botnote 0.1.51 → 0.1.52

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.
@@ -46,7 +46,7 @@ Error generating stack: `+v.message+`
46
46
  * LICENSE.md file in the root directory of this source tree.
47
47
  *
48
48
  * @license MIT
49
- */function Uu(){return Uu=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},Uu.apply(null,arguments)}var _s;(function(n){n.Pop="POP",n.Push="PUSH",n.Replace="REPLACE"})(_s||(_s={}));const ib="popstate";function FR(n){n===void 0&&(n={});function e(r,i){let{pathname:s,search:l,hash:o}=r.location;return VO("",{pathname:s,search:l,hash:o},i.state&&i.state.usr||null,i.state&&i.state.key||"default")}function t(r,i){return typeof i=="string"?i:nd(i)}return UR(e,t,null,n)}function bt(n,e){if(n===!1||n===null||typeof n>"u")throw new Error(e)}function Cy(n,e){if(!n){typeof console<"u"&&console.warn(e);try{throw new Error(e)}catch{}}}function YR(){return Math.random().toString(36).substr(2,8)}function sb(n,e){return{usr:n.state,key:n.key,idx:e}}function VO(n,e,t,r){return t===void 0&&(t=null),Uu({pathname:typeof n=="string"?n:n.pathname,search:"",hash:""},typeof e=="string"?ya(e):e,{state:t,key:e&&e.key||r||YR()})}function nd(n){let{pathname:e="/",search:t="",hash:r=""}=n;return t&&t!=="?"&&(e+=t.charAt(0)==="?"?t:"?"+t),r&&r!=="#"&&(e+=r.charAt(0)==="#"?r:"#"+r),e}function ya(n){let e={};if(n){let t=n.indexOf("#");t>=0&&(e.hash=n.substr(t),n=n.substr(0,t));let r=n.indexOf("?");r>=0&&(e.search=n.substr(r),n=n.substr(0,r)),n&&(e.pathname=n)}return e}function UR(n,e,t,r){r===void 0&&(r={});let{window:i=document.defaultView,v5Compat:s=!1}=r,l=i.history,o=_s.Pop,u=null,h=f();h==null&&(h=0,l.replaceState(Uu({},l.state,{idx:h}),""));function f(){return(l.state||{idx:null}).idx}function p(){o=_s.Pop;let w=f(),S=w==null?null:w-h;h=w,u&&u({action:o,location:b.location,delta:S})}function g(w,S){o=_s.Push;let Q=VO(b.location,w,S);h=f()+1;let $=sb(Q,h),R=b.createHref(Q);try{l.pushState($,"",R)}catch(I){if(I instanceof DOMException&&I.name==="DataCloneError")throw I;i.location.assign(R)}s&&u&&u({action:o,location:b.location,delta:1})}function x(w,S){o=_s.Replace;let Q=VO(b.location,w,S);h=f();let $=sb(Q,h),R=b.createHref(Q);l.replaceState($,"",R),s&&u&&u({action:o,location:b.location,delta:0})}function k(w){let S=i.location.origin!=="null"?i.location.origin:i.location.href,Q=typeof w=="string"?w:nd(w);return Q=Q.replace(/ $/,"%20"),bt(S,"No window.location.(origin|href) available to create URL for href: "+Q),new URL(Q,S)}let b={get action(){return o},get location(){return n(i,l)},listen(w){if(u)throw new Error("A history only accepts one active listener");return i.addEventListener(ib,p),u=w,()=>{i.removeEventListener(ib,p),u=null}},createHref(w){return e(i,w)},createURL:k,encodeLocation(w){let S=k(w);return{pathname:S.pathname,search:S.search,hash:S.hash}},push:g,replace:x,go(w){return l.go(w)}};return b}var lb;(function(n){n.data="data",n.deferred="deferred",n.redirect="redirect",n.error="error"})(lb||(lb={}));function GR(n,e,t){return t===void 0&&(t="/"),HR(n,e,t)}function HR(n,e,t,r){let i=typeof e=="string"?ya(e):e,s=na(i.pathname||"/",t);if(s==null)return null;let l=RC(n);KR(l);let o=null,u=u5(s);for(let h=0;o==null&&h<l.length;++h)o=o5(l[h],u);return o}function RC(n,e,t,r){e===void 0&&(e=[]),t===void 0&&(t=[]),r===void 0&&(r="");let i=(s,l,o)=>{let u={relativePath:o===void 0?s.path||"":o,caseSensitive:s.caseSensitive===!0,childrenIndex:l,route:s};u.relativePath.startsWith("/")&&(bt(u.relativePath.startsWith(r),'Absolute route path "'+u.relativePath+'" nested under path '+('"'+r+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),u.relativePath=u.relativePath.slice(r.length));let h=zs([r,u.relativePath]),f=t.concat(u);s.children&&s.children.length>0&&(bt(s.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+h+'".')),RC(s.children,e,f,h)),!(s.path==null&&!s.index)&&e.push({path:h,score:s5(h,s.index),routesMeta:f})};return n.forEach((s,l)=>{var o;if(s.path===""||!((o=s.path)!=null&&o.includes("?")))i(s,l);else for(let u of NC(s.path))i(s,l,u)}),e}function NC(n){let e=n.split("/");if(e.length===0)return[];let[t,...r]=e,i=t.endsWith("?"),s=t.replace(/\?$/,"");if(r.length===0)return i?[s,""]:[s];let l=NC(r.join("/")),o=[];return o.push(...l.map(u=>u===""?s:[s,u].join("/"))),i&&o.push(...l),o.map(u=>n.startsWith("/")&&u===""?"/":u)}function KR(n){n.sort((e,t)=>e.score!==t.score?t.score-e.score:l5(e.routesMeta.map(r=>r.childrenIndex),t.routesMeta.map(r=>r.childrenIndex)))}const JR=/^:[\w-]+$/,e5=3,t5=2,n5=1,r5=10,i5=-2,ob=n=>n==="*";function s5(n,e){let t=n.split("/"),r=t.length;return t.some(ob)&&(r+=i5),e&&(r+=t5),t.filter(i=>!ob(i)).reduce((i,s)=>i+(JR.test(s)?e5:s===""?n5:r5),r)}function l5(n,e){return n.length===e.length&&n.slice(0,-1).every((r,i)=>r===e[i])?n[n.length-1]-e[e.length-1]:0}function o5(n,e,t){let{routesMeta:r}=n,i={},s="/",l=[];for(let o=0;o<r.length;++o){let u=r[o],h=o===r.length-1,f=s==="/"?e:e.slice(s.length)||"/",p=FO({path:u.relativePath,caseSensitive:u.caseSensitive,end:h},f),g=u.route;if(!p)return null;Object.assign(i,p.params),l.push({params:i,pathname:zs([s,p.pathname]),pathnameBase:p5(zs([s,p.pathnameBase])),route:g}),p.pathnameBase!=="/"&&(s=zs([s,p.pathnameBase]))}return l}function FO(n,e){typeof n=="string"&&(n={path:n,caseSensitive:!1,end:!0});let[t,r]=a5(n.path,n.caseSensitive,n.end),i=e.match(t);if(!i)return null;let s=i[0],l=s.replace(/(.)\/+$/,"$1"),o=i.slice(1);return{params:r.reduce((h,f,p)=>{let{paramName:g,isOptional:x}=f;if(g==="*"){let b=o[p]||"";l=s.slice(0,s.length-b.length).replace(/(.)\/+$/,"$1")}const k=o[p];return x&&!k?h[g]=void 0:h[g]=(k||"").replace(/%2F/g,"/"),h},{}),pathname:s,pathnameBase:l,pattern:n}}function a5(n,e,t){e===void 0&&(e=!1),t===void 0&&(t=!0),Cy(n==="*"||!n.endsWith("*")||n.endsWith("/*"),'Route path "'+n+'" will be treated as if it were '+('"'+n.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+n.replace(/\*$/,"/*")+'".'));let r=[],i="^"+n.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(l,o,u)=>(r.push({paramName:o,isOptional:u!=null}),u?"/?([^\\/]+)?":"/([^\\/]+)"));return n.endsWith("*")?(r.push({paramName:"*"}),i+=n==="*"||n==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):t?i+="\\/*$":n!==""&&n!=="/"&&(i+="(?:(?=\\/|$))"),[new RegExp(i,e?void 0:"i"),r]}function u5(n){try{return n.split("/").map(e=>decodeURIComponent(e).replace(/\//g,"%2F")).join("/")}catch(e){return Cy(!1,'The URL path "'+n+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+e+").")),n}}function na(n,e){if(e==="/")return n;if(!n.toLowerCase().startsWith(e.toLowerCase()))return null;let t=e.endsWith("/")?e.length-1:e.length,r=n.charAt(t);return r&&r!=="/"?null:n.slice(t)||"/"}const c5=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,h5=n=>c5.test(n);function f5(n,e){e===void 0&&(e="/");let{pathname:t,search:r="",hash:i=""}=typeof n=="string"?ya(n):n,s;if(t)if(h5(t))s=t;else{if(t.includes("//")){let l=t;t=LC(t),Cy(!1,"Pathnames cannot have embedded double slashes - normalizing "+(l+" -> "+t))}t.startsWith("/")?s=ab(t.substring(1),"/"):s=ab(t,e)}else s=e;return{pathname:s,search:m5(r),hash:g5(i)}}function ab(n,e){let t=e.replace(/\/+$/,"").split("/");return n.split("/").forEach(i=>{i===".."?t.length>1&&t.pop():i!=="."&&t.push(i)}),t.length>1?t.join("/"):"/"}function mg(n,e,t,r){return"Cannot include a '"+n+"' character in a manually specified "+("`to."+e+"` field ["+JSON.stringify(r)+"]. Please separate it out to the ")+("`to."+t+"` field. Alternatively you may provide the full path as ")+'a string in <Link to="..."> and the router will parse it for you.'}function d5(n){return n.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function Qy(n,e){let t=d5(n);return e?t.map((r,i)=>i===t.length-1?r.pathname:r.pathnameBase):t.map(r=>r.pathnameBase)}function $y(n,e,t,r){r===void 0&&(r=!1);let i;typeof n=="string"?i=ya(n):(i=Uu({},n),bt(!i.pathname||!i.pathname.includes("?"),mg("?","pathname","search",i)),bt(!i.pathname||!i.pathname.includes("#"),mg("#","pathname","hash",i)),bt(!i.search||!i.search.includes("#"),mg("#","search","hash",i)));let s=n===""||i.pathname==="",l=s?"/":i.pathname,o;if(l==null)o=t;else{let p=e.length-1;if(!r&&l.startsWith("..")){let g=l.split("/");for(;g[0]==="..";)g.shift(),p-=1;i.pathname=g.join("/")}o=p>=0?e[p]:"/"}let u=f5(i,o),h=l&&l!=="/"&&l.endsWith("/"),f=(s||l===".")&&t.endsWith("/");return!u.pathname.endsWith("/")&&(h||f)&&(u.pathname+="/"),u}const LC=n=>n.replace(/\/\/+/g,"/"),zs=n=>LC(n.join("/")),p5=n=>n.replace(/\/+$/,"").replace(/^\/*/,"/"),m5=n=>!n||n==="?"?"":n.startsWith("?")?n:"?"+n,g5=n=>!n||n==="#"?"":n.startsWith("#")?n:"#"+n;function O5(n){return n!=null&&typeof n.status=="number"&&typeof n.statusText=="string"&&typeof n.internal=="boolean"&&"data"in n}const _C=["post","put","patch","delete"];new Set(_C);const x5=["get",..._C];new Set(x5);/**
49
+ */function Uu(){return Uu=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},Uu.apply(null,arguments)}var _s;(function(n){n.Pop="POP",n.Push="PUSH",n.Replace="REPLACE"})(_s||(_s={}));const ib="popstate";function FR(n){n===void 0&&(n={});function e(r,i){let{pathname:s,search:l,hash:o}=r.location;return VO("",{pathname:s,search:l,hash:o},i.state&&i.state.usr||null,i.state&&i.state.key||"default")}function t(r,i){return typeof i=="string"?i:nd(i)}return UR(e,t,null,n)}function bt(n,e){if(n===!1||n===null||typeof n>"u")throw new Error(e)}function Cy(n,e){if(!n){typeof console<"u"&&console.warn(e);try{throw new Error(e)}catch{}}}function YR(){return Math.random().toString(36).substr(2,8)}function sb(n,e){return{usr:n.state,key:n.key,idx:e}}function VO(n,e,t,r){return t===void 0&&(t=null),Uu({pathname:typeof n=="string"?n:n.pathname,search:"",hash:""},typeof e=="string"?ya(e):e,{state:t,key:e&&e.key||r||YR()})}function nd(n){let{pathname:e="/",search:t="",hash:r=""}=n;return t&&t!=="?"&&(e+=t.charAt(0)==="?"?t:"?"+t),r&&r!=="#"&&(e+=r.charAt(0)==="#"?r:"#"+r),e}function ya(n){let e={};if(n){let t=n.indexOf("#");t>=0&&(e.hash=n.substr(t),n=n.substr(0,t));let r=n.indexOf("?");r>=0&&(e.search=n.substr(r),n=n.substr(0,r)),n&&(e.pathname=n)}return e}function UR(n,e,t,r){r===void 0&&(r={});let{window:i=document.defaultView,v5Compat:s=!1}=r,l=i.history,o=_s.Pop,u=null,h=f();h==null&&(h=0,l.replaceState(Uu({},l.state,{idx:h}),""));function f(){return(l.state||{idx:null}).idx}function p(){o=_s.Pop;let w=f(),S=w==null?null:w-h;h=w,u&&u({action:o,location:b.location,delta:S})}function g(w,S){o=_s.Push;let Q=VO(b.location,w,S);h=f()+1;let $=sb(Q,h),R=b.createHref(Q);try{l.pushState($,"",R)}catch(I){if(I instanceof DOMException&&I.name==="DataCloneError")throw I;i.location.assign(R)}s&&u&&u({action:o,location:b.location,delta:1})}function x(w,S){o=_s.Replace;let Q=VO(b.location,w,S);h=f();let $=sb(Q,h),R=b.createHref(Q);l.replaceState($,"",R),s&&u&&u({action:o,location:b.location,delta:0})}function k(w){let S=i.location.origin!=="null"?i.location.origin:i.location.href,Q=typeof w=="string"?w:nd(w);return Q=Q.replace(/ $/,"%20"),bt(S,"No window.location.(origin|href) available to create URL for href: "+Q),new URL(Q,S)}let b={get action(){return o},get location(){return n(i,l)},listen(w){if(u)throw new Error("A history only accepts one active listener");return i.addEventListener(ib,p),u=w,()=>{i.removeEventListener(ib,p),u=null}},createHref(w){return e(i,w)},createURL:k,encodeLocation(w){let S=k(w);return{pathname:S.pathname,search:S.search,hash:S.hash}},push:g,replace:x,go(w){return l.go(w)}};return b}var lb;(function(n){n.data="data",n.deferred="deferred",n.redirect="redirect",n.error="error"})(lb||(lb={}));function GR(n,e,t){return t===void 0&&(t="/"),HR(n,e,t)}function HR(n,e,t,r){let i=typeof e=="string"?ya(e):e,s=na(i.pathname||"/",t);if(s==null)return null;let l=RC(n);KR(l);let o=null,u=uN(s);for(let h=0;o==null&&h<l.length;++h)o=oN(l[h],u);return o}function RC(n,e,t,r){e===void 0&&(e=[]),t===void 0&&(t=[]),r===void 0&&(r="");let i=(s,l,o)=>{let u={relativePath:o===void 0?s.path||"":o,caseSensitive:s.caseSensitive===!0,childrenIndex:l,route:s};u.relativePath.startsWith("/")&&(bt(u.relativePath.startsWith(r),'Absolute route path "'+u.relativePath+'" nested under path '+('"'+r+'" is not valid. An absolute child route path ')+"must start with the combined path of all its parent routes."),u.relativePath=u.relativePath.slice(r.length));let h=zs([r,u.relativePath]),f=t.concat(u);s.children&&s.children.length>0&&(bt(s.index!==!0,"Index routes must not have child routes. Please remove "+('all child routes from route path "'+h+'".')),RC(s.children,e,f,h)),!(s.path==null&&!s.index)&&e.push({path:h,score:sN(h,s.index),routesMeta:f})};return n.forEach((s,l)=>{var o;if(s.path===""||!((o=s.path)!=null&&o.includes("?")))i(s,l);else for(let u of NC(s.path))i(s,l,u)}),e}function NC(n){let e=n.split("/");if(e.length===0)return[];let[t,...r]=e,i=t.endsWith("?"),s=t.replace(/\?$/,"");if(r.length===0)return i?[s,""]:[s];let l=NC(r.join("/")),o=[];return o.push(...l.map(u=>u===""?s:[s,u].join("/"))),i&&o.push(...l),o.map(u=>n.startsWith("/")&&u===""?"/":u)}function KR(n){n.sort((e,t)=>e.score!==t.score?t.score-e.score:lN(e.routesMeta.map(r=>r.childrenIndex),t.routesMeta.map(r=>r.childrenIndex)))}const JR=/^:[\w-]+$/,eN=3,tN=2,nN=1,rN=10,iN=-2,ob=n=>n==="*";function sN(n,e){let t=n.split("/"),r=t.length;return t.some(ob)&&(r+=iN),e&&(r+=tN),t.filter(i=>!ob(i)).reduce((i,s)=>i+(JR.test(s)?eN:s===""?nN:rN),r)}function lN(n,e){return n.length===e.length&&n.slice(0,-1).every((r,i)=>r===e[i])?n[n.length-1]-e[e.length-1]:0}function oN(n,e,t){let{routesMeta:r}=n,i={},s="/",l=[];for(let o=0;o<r.length;++o){let u=r[o],h=o===r.length-1,f=s==="/"?e:e.slice(s.length)||"/",p=FO({path:u.relativePath,caseSensitive:u.caseSensitive,end:h},f),g=u.route;if(!p)return null;Object.assign(i,p.params),l.push({params:i,pathname:zs([s,p.pathname]),pathnameBase:pN(zs([s,p.pathnameBase])),route:g}),p.pathnameBase!=="/"&&(s=zs([s,p.pathnameBase]))}return l}function FO(n,e){typeof n=="string"&&(n={path:n,caseSensitive:!1,end:!0});let[t,r]=aN(n.path,n.caseSensitive,n.end),i=e.match(t);if(!i)return null;let s=i[0],l=s.replace(/(.)\/+$/,"$1"),o=i.slice(1);return{params:r.reduce((h,f,p)=>{let{paramName:g,isOptional:x}=f;if(g==="*"){let b=o[p]||"";l=s.slice(0,s.length-b.length).replace(/(.)\/+$/,"$1")}const k=o[p];return x&&!k?h[g]=void 0:h[g]=(k||"").replace(/%2F/g,"/"),h},{}),pathname:s,pathnameBase:l,pattern:n}}function aN(n,e,t){e===void 0&&(e=!1),t===void 0&&(t=!0),Cy(n==="*"||!n.endsWith("*")||n.endsWith("/*"),'Route path "'+n+'" will be treated as if it were '+('"'+n.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+n.replace(/\*$/,"/*")+'".'));let r=[],i="^"+n.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(l,o,u)=>(r.push({paramName:o,isOptional:u!=null}),u?"/?([^\\/]+)?":"/([^\\/]+)"));return n.endsWith("*")?(r.push({paramName:"*"}),i+=n==="*"||n==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):t?i+="\\/*$":n!==""&&n!=="/"&&(i+="(?:(?=\\/|$))"),[new RegExp(i,e?void 0:"i"),r]}function uN(n){try{return n.split("/").map(e=>decodeURIComponent(e).replace(/\//g,"%2F")).join("/")}catch(e){return Cy(!1,'The URL path "'+n+'" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent '+("encoding ("+e+").")),n}}function na(n,e){if(e==="/")return n;if(!n.toLowerCase().startsWith(e.toLowerCase()))return null;let t=e.endsWith("/")?e.length-1:e.length,r=n.charAt(t);return r&&r!=="/"?null:n.slice(t)||"/"}const cN=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,hN=n=>cN.test(n);function fN(n,e){e===void 0&&(e="/");let{pathname:t,search:r="",hash:i=""}=typeof n=="string"?ya(n):n,s;if(t)if(hN(t))s=t;else{if(t.includes("//")){let l=t;t=LC(t),Cy(!1,"Pathnames cannot have embedded double slashes - normalizing "+(l+" -> "+t))}t.startsWith("/")?s=ab(t.substring(1),"/"):s=ab(t,e)}else s=e;return{pathname:s,search:mN(r),hash:gN(i)}}function ab(n,e){let t=e.replace(/\/+$/,"").split("/");return n.split("/").forEach(i=>{i===".."?t.length>1&&t.pop():i!=="."&&t.push(i)}),t.length>1?t.join("/"):"/"}function mg(n,e,t,r){return"Cannot include a '"+n+"' character in a manually specified "+("`to."+e+"` field ["+JSON.stringify(r)+"]. Please separate it out to the ")+("`to."+t+"` field. Alternatively you may provide the full path as ")+'a string in <Link to="..."> and the router will parse it for you.'}function dN(n){return n.filter((e,t)=>t===0||e.route.path&&e.route.path.length>0)}function Qy(n,e){let t=dN(n);return e?t.map((r,i)=>i===t.length-1?r.pathname:r.pathnameBase):t.map(r=>r.pathnameBase)}function $y(n,e,t,r){r===void 0&&(r=!1);let i;typeof n=="string"?i=ya(n):(i=Uu({},n),bt(!i.pathname||!i.pathname.includes("?"),mg("?","pathname","search",i)),bt(!i.pathname||!i.pathname.includes("#"),mg("#","pathname","hash",i)),bt(!i.search||!i.search.includes("#"),mg("#","search","hash",i)));let s=n===""||i.pathname==="",l=s?"/":i.pathname,o;if(l==null)o=t;else{let p=e.length-1;if(!r&&l.startsWith("..")){let g=l.split("/");for(;g[0]==="..";)g.shift(),p-=1;i.pathname=g.join("/")}o=p>=0?e[p]:"/"}let u=fN(i,o),h=l&&l!=="/"&&l.endsWith("/"),f=(s||l===".")&&t.endsWith("/");return!u.pathname.endsWith("/")&&(h||f)&&(u.pathname+="/"),u}const LC=n=>n.replace(/\/\/+/g,"/"),zs=n=>LC(n.join("/")),pN=n=>n.replace(/\/+$/,"").replace(/^\/*/,"/"),mN=n=>!n||n==="?"?"":n.startsWith("?")?n:"?"+n,gN=n=>!n||n==="#"?"":n.startsWith("#")?n:"#"+n;function ON(n){return n!=null&&typeof n.status=="number"&&typeof n.statusText=="string"&&typeof n.internal=="boolean"&&"data"in n}const _C=["post","put","patch","delete"];new Set(_C);const xN=["get",..._C];new Set(xN);/**
50
50
  * React Router v6.30.4
51
51
  *
52
52
  * Copyright (c) Remix Software Inc.
@@ -55,7 +55,7 @@ Error generating stack: `+v.message+`
55
55
  * LICENSE.md file in the root directory of this source tree.
56
56
  *
57
57
  * @license MIT
58
- */function Gu(){return Gu=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},Gu.apply(null,arguments)}const Yd=M.createContext(null),DC=M.createContext(null),Yi=M.createContext(null),Ud=M.createContext(null),ki=M.createContext({outlet:null,matches:[],isDataRoute:!1}),IC=M.createContext(null);function y5(n,e){let{relative:t}=e===void 0?{}:e;ka()||bt(!1);let{basename:r,navigator:i}=M.useContext(Yi),{hash:s,pathname:l,search:o}=Hd(n,{relative:t}),u=l;return r!=="/"&&(u=l==="/"?r:zs([r,l])),i.createHref({pathname:u,search:o,hash:s})}function ka(){return M.useContext(Ud)!=null}function Us(){return ka()||bt(!1),M.useContext(Ud).location}function zC(n){M.useContext(Yi).static||M.useLayoutEffect(n)}function Gs(){let{isDataRoute:n}=M.useContext(ki);return n?R5():k5()}function k5(){ka()||bt(!1);let n=M.useContext(Yd),{basename:e,future:t,navigator:r}=M.useContext(Yi),{matches:i}=M.useContext(ki),{pathname:s}=Us(),l=JSON.stringify(Qy(i,t.v7_relativeSplatPath)),o=M.useRef(!1);return zC(()=>{o.current=!0}),M.useCallback(function(h,f){if(f===void 0&&(f={}),!o.current)return;if(typeof h=="number"){r.go(h);return}let p=$y(h,JSON.parse(l),s,f.relative==="path");n==null&&e!=="/"&&(p.pathname=p.pathname==="/"?e:zs([e,p.pathname])),(f.replace?r.replace:r.push)(p,f.state,f)},[e,r,l,s,n])}const v5=M.createContext(null);function b5(n){let e=M.useContext(ki).outlet;return e&&M.createElement(v5.Provider,{value:n},e)}function Gd(){let{matches:n}=M.useContext(ki),e=n[n.length-1];return e?e.params:{}}function Hd(n,e){let{relative:t}=e===void 0?{}:e,{future:r}=M.useContext(Yi),{matches:i}=M.useContext(ki),{pathname:s}=Us(),l=JSON.stringify(Qy(i,r.v7_relativeSplatPath));return M.useMemo(()=>$y(n,JSON.parse(l),s,t==="path"),[n,l,s,t])}function w5(n,e){return S5(n,e)}function S5(n,e,t,r){ka()||bt(!1);let{navigator:i}=M.useContext(Yi),{matches:s}=M.useContext(ki),l=s[s.length-1],o=l?l.params:{};l&&l.pathname;let u=l?l.pathnameBase:"/";l&&l.route;let h=Us(),f;if(e){var p;let w=typeof e=="string"?ya(e):e;u==="/"||(p=w.pathname)!=null&&p.startsWith(u)||bt(!1),f=w}else f=h;let g=f.pathname||"/",x=g;if(u!=="/"){let w=u.replace(/^\//,"").split("/");x="/"+g.replace(/^\//,"").split("/").slice(w.length).join("/")}let k=GR(n,{pathname:x}),b=T5(k&&k.map(w=>Object.assign({},w,{params:Object.assign({},o,w.params),pathname:zs([u,i.encodeLocation?i.encodeLocation(w.pathname).pathname:w.pathname]),pathnameBase:w.pathnameBase==="/"?u:zs([u,i.encodeLocation?i.encodeLocation(w.pathnameBase).pathname:w.pathnameBase])})),s,t,r);return e&&b?M.createElement(Ud.Provider,{value:{location:Gu({pathname:"/",search:"",hash:"",state:null,key:"default"},f),navigationType:_s.Pop}},b):b}function P5(){let n=A5(),e=O5(n)?n.status+" "+n.statusText:n instanceof Error?n.message:JSON.stringify(n),t=n instanceof Error?n.stack:null,i={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return M.createElement(M.Fragment,null,M.createElement("h2",null,"Unexpected Application Error!"),M.createElement("h3",{style:{fontStyle:"italic"}},e),t?M.createElement("pre",{style:i},t):null,null)}const C5=M.createElement(P5,null);class Q5 extends M.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:t.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){console.error("React Router caught the following error during render",e,t)}render(){return this.state.error!==void 0?M.createElement(ki.Provider,{value:this.props.routeContext},M.createElement(IC.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function $5(n){let{routeContext:e,match:t,children:r}=n,i=M.useContext(Yd);return i&&i.static&&i.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(i.staticContext._deepestRenderedBoundaryId=t.route.id),M.createElement(ki.Provider,{value:e},r)}function T5(n,e,t,r){var i;if(e===void 0&&(e=[]),t===void 0&&(t=null),r===void 0&&(r=null),n==null){var s;if(!t)return null;if(t.errors)n=t.matches;else if((s=r)!=null&&s.v7_partialHydration&&e.length===0&&!t.initialized&&t.matches.length>0)n=t.matches;else return null}let l=n,o=(i=t)==null?void 0:i.errors;if(o!=null){let f=l.findIndex(p=>p.route.id&&(o==null?void 0:o[p.route.id])!==void 0);f>=0||bt(!1),l=l.slice(0,Math.min(l.length,f+1))}let u=!1,h=-1;if(t&&r&&r.v7_partialHydration)for(let f=0;f<l.length;f++){let p=l[f];if((p.route.HydrateFallback||p.route.hydrateFallbackElement)&&(h=f),p.route.id){let{loaderData:g,errors:x}=t,k=p.route.loader&&g[p.route.id]===void 0&&(!x||x[p.route.id]===void 0);if(p.route.lazy||k){u=!0,h>=0?l=l.slice(0,h+1):l=[l[0]];break}}}return l.reduceRight((f,p,g)=>{let x,k=!1,b=null,w=null;t&&(x=o&&p.route.id?o[p.route.id]:void 0,b=p.route.errorElement||C5,u&&(h<0&&g===0?(N5("route-fallback"),k=!0,w=null):h===g&&(k=!0,w=p.route.hydrateFallbackElement||null)));let S=e.concat(l.slice(0,g+1)),Q=()=>{let $;return x?$=b:k?$=w:p.route.Component?$=M.createElement(p.route.Component,null):p.route.element?$=p.route.element:$=f,M.createElement($5,{match:p,routeContext:{outlet:f,matches:S,isDataRoute:t!=null},children:$})};return t&&(p.route.ErrorBoundary||p.route.errorElement||g===0)?M.createElement(Q5,{location:t.location,revalidation:t.revalidation,component:b,error:x,children:Q(),routeContext:{outlet:null,matches:S,isDataRoute:!0}}):Q()},null)}var ZC=(function(n){return n.UseBlocker="useBlocker",n.UseRevalidator="useRevalidator",n.UseNavigateStable="useNavigate",n})(ZC||{}),XC=(function(n){return n.UseBlocker="useBlocker",n.UseLoaderData="useLoaderData",n.UseActionData="useActionData",n.UseRouteError="useRouteError",n.UseNavigation="useNavigation",n.UseRouteLoaderData="useRouteLoaderData",n.UseMatches="useMatches",n.UseRevalidator="useRevalidator",n.UseNavigateStable="useNavigate",n.UseRouteId="useRouteId",n})(XC||{});function j5(n){let e=M.useContext(Yd);return e||bt(!1),e}function E5(n){let e=M.useContext(DC);return e||bt(!1),e}function M5(n){let e=M.useContext(ki);return e||bt(!1),e}function BC(n){let e=M5(),t=e.matches[e.matches.length-1];return t.route.id||bt(!1),t.route.id}function A5(){var n;let e=M.useContext(IC),t=E5(),r=BC();return e!==void 0?e:(n=t.errors)==null?void 0:n[r]}function R5(){let{router:n}=j5(ZC.UseNavigateStable),e=BC(XC.UseNavigateStable),t=M.useRef(!1);return zC(()=>{t.current=!0}),M.useCallback(function(i,s){s===void 0&&(s={}),t.current&&(typeof i=="number"?n.navigate(i):n.navigate(i,Gu({fromRouteId:e},s)))},[n,e])}const ub={};function N5(n,e,t){ub[n]||(ub[n]=!0)}function L5(n,e){n==null||n.v7_startTransition,n==null||n.v7_relativeSplatPath}function cb(n){let{to:e,replace:t,state:r,relative:i}=n;ka()||bt(!1);let{future:s,static:l}=M.useContext(Yi),{matches:o}=M.useContext(ki),{pathname:u}=Us(),h=Gs(),f=$y(e,Qy(o,s.v7_relativeSplatPath),u,i==="path"),p=JSON.stringify(f);return M.useEffect(()=>h(JSON.parse(p),{replace:t,state:r,relative:i}),[h,p,i,t,r]),null}function _5(n){return b5(n.context)}function ir(n){bt(!1)}function D5(n){let{basename:e="/",children:t=null,location:r,navigationType:i=_s.Pop,navigator:s,static:l=!1,future:o}=n;ka()&&bt(!1);let u=e.replace(/^\/*/,"/"),h=M.useMemo(()=>({basename:u,navigator:s,static:l,future:Gu({v7_relativeSplatPath:!1},o)}),[u,o,s,l]);typeof r=="string"&&(r=ya(r));let{pathname:f="/",search:p="",hash:g="",state:x=null,key:k="default"}=r,b=M.useMemo(()=>{let w=na(f,u);return w==null?null:{location:{pathname:w,search:p,hash:g,state:x,key:k},navigationType:i}},[u,f,p,g,x,k,i]);return b==null?null:M.createElement(Yi.Provider,{value:h},M.createElement(Ud.Provider,{children:t,value:b}))}function I5(n){let{children:e,location:t}=n;return w5(YO(e),t)}new Promise(()=>{});function YO(n,e){e===void 0&&(e=[]);let t=[];return M.Children.forEach(n,(r,i)=>{if(!M.isValidElement(r))return;let s=[...e,i];if(r.type===M.Fragment){t.push.apply(t,YO(r.props.children,s));return}r.type!==ir&&bt(!1),!r.props.index||!r.props.children||bt(!1);let l={id:r.props.id||s.join("-"),caseSensitive:r.props.caseSensitive,element:r.props.element,Component:r.props.Component,index:r.props.index,path:r.props.path,loader:r.props.loader,action:r.props.action,errorElement:r.props.errorElement,ErrorBoundary:r.props.ErrorBoundary,hasErrorBoundary:r.props.ErrorBoundary!=null||r.props.errorElement!=null,shouldRevalidate:r.props.shouldRevalidate,handle:r.props.handle,lazy:r.props.lazy};r.props.children&&(l.children=YO(r.props.children,s)),t.push(l)}),t}/**
58
+ */function Gu(){return Gu=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},Gu.apply(null,arguments)}const Yd=M.createContext(null),DC=M.createContext(null),Yi=M.createContext(null),Ud=M.createContext(null),ki=M.createContext({outlet:null,matches:[],isDataRoute:!1}),IC=M.createContext(null);function yN(n,e){let{relative:t}=e===void 0?{}:e;ka()||bt(!1);let{basename:r,navigator:i}=M.useContext(Yi),{hash:s,pathname:l,search:o}=Hd(n,{relative:t}),u=l;return r!=="/"&&(u=l==="/"?r:zs([r,l])),i.createHref({pathname:u,search:o,hash:s})}function ka(){return M.useContext(Ud)!=null}function Us(){return ka()||bt(!1),M.useContext(Ud).location}function zC(n){M.useContext(Yi).static||M.useLayoutEffect(n)}function Gs(){let{isDataRoute:n}=M.useContext(ki);return n?RN():kN()}function kN(){ka()||bt(!1);let n=M.useContext(Yd),{basename:e,future:t,navigator:r}=M.useContext(Yi),{matches:i}=M.useContext(ki),{pathname:s}=Us(),l=JSON.stringify(Qy(i,t.v7_relativeSplatPath)),o=M.useRef(!1);return zC(()=>{o.current=!0}),M.useCallback(function(h,f){if(f===void 0&&(f={}),!o.current)return;if(typeof h=="number"){r.go(h);return}let p=$y(h,JSON.parse(l),s,f.relative==="path");n==null&&e!=="/"&&(p.pathname=p.pathname==="/"?e:zs([e,p.pathname])),(f.replace?r.replace:r.push)(p,f.state,f)},[e,r,l,s,n])}const vN=M.createContext(null);function bN(n){let e=M.useContext(ki).outlet;return e&&M.createElement(vN.Provider,{value:n},e)}function Gd(){let{matches:n}=M.useContext(ki),e=n[n.length-1];return e?e.params:{}}function Hd(n,e){let{relative:t}=e===void 0?{}:e,{future:r}=M.useContext(Yi),{matches:i}=M.useContext(ki),{pathname:s}=Us(),l=JSON.stringify(Qy(i,r.v7_relativeSplatPath));return M.useMemo(()=>$y(n,JSON.parse(l),s,t==="path"),[n,l,s,t])}function wN(n,e){return SN(n,e)}function SN(n,e,t,r){ka()||bt(!1);let{navigator:i}=M.useContext(Yi),{matches:s}=M.useContext(ki),l=s[s.length-1],o=l?l.params:{};l&&l.pathname;let u=l?l.pathnameBase:"/";l&&l.route;let h=Us(),f;if(e){var p;let w=typeof e=="string"?ya(e):e;u==="/"||(p=w.pathname)!=null&&p.startsWith(u)||bt(!1),f=w}else f=h;let g=f.pathname||"/",x=g;if(u!=="/"){let w=u.replace(/^\//,"").split("/");x="/"+g.replace(/^\//,"").split("/").slice(w.length).join("/")}let k=GR(n,{pathname:x}),b=TN(k&&k.map(w=>Object.assign({},w,{params:Object.assign({},o,w.params),pathname:zs([u,i.encodeLocation?i.encodeLocation(w.pathname).pathname:w.pathname]),pathnameBase:w.pathnameBase==="/"?u:zs([u,i.encodeLocation?i.encodeLocation(w.pathnameBase).pathname:w.pathnameBase])})),s,t,r);return e&&b?M.createElement(Ud.Provider,{value:{location:Gu({pathname:"/",search:"",hash:"",state:null,key:"default"},f),navigationType:_s.Pop}},b):b}function PN(){let n=AN(),e=ON(n)?n.status+" "+n.statusText:n instanceof Error?n.message:JSON.stringify(n),t=n instanceof Error?n.stack:null,i={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return M.createElement(M.Fragment,null,M.createElement("h2",null,"Unexpected Application Error!"),M.createElement("h3",{style:{fontStyle:"italic"}},e),t?M.createElement("pre",{style:i},t):null,null)}const CN=M.createElement(PN,null);class QN extends M.Component{constructor(e){super(e),this.state={location:e.location,revalidation:e.revalidation,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location||t.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:t.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){console.error("React Router caught the following error during render",e,t)}render(){return this.state.error!==void 0?M.createElement(ki.Provider,{value:this.props.routeContext},M.createElement(IC.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function $N(n){let{routeContext:e,match:t,children:r}=n,i=M.useContext(Yd);return i&&i.static&&i.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(i.staticContext._deepestRenderedBoundaryId=t.route.id),M.createElement(ki.Provider,{value:e},r)}function TN(n,e,t,r){var i;if(e===void 0&&(e=[]),t===void 0&&(t=null),r===void 0&&(r=null),n==null){var s;if(!t)return null;if(t.errors)n=t.matches;else if((s=r)!=null&&s.v7_partialHydration&&e.length===0&&!t.initialized&&t.matches.length>0)n=t.matches;else return null}let l=n,o=(i=t)==null?void 0:i.errors;if(o!=null){let f=l.findIndex(p=>p.route.id&&(o==null?void 0:o[p.route.id])!==void 0);f>=0||bt(!1),l=l.slice(0,Math.min(l.length,f+1))}let u=!1,h=-1;if(t&&r&&r.v7_partialHydration)for(let f=0;f<l.length;f++){let p=l[f];if((p.route.HydrateFallback||p.route.hydrateFallbackElement)&&(h=f),p.route.id){let{loaderData:g,errors:x}=t,k=p.route.loader&&g[p.route.id]===void 0&&(!x||x[p.route.id]===void 0);if(p.route.lazy||k){u=!0,h>=0?l=l.slice(0,h+1):l=[l[0]];break}}}return l.reduceRight((f,p,g)=>{let x,k=!1,b=null,w=null;t&&(x=o&&p.route.id?o[p.route.id]:void 0,b=p.route.errorElement||CN,u&&(h<0&&g===0?(NN("route-fallback"),k=!0,w=null):h===g&&(k=!0,w=p.route.hydrateFallbackElement||null)));let S=e.concat(l.slice(0,g+1)),Q=()=>{let $;return x?$=b:k?$=w:p.route.Component?$=M.createElement(p.route.Component,null):p.route.element?$=p.route.element:$=f,M.createElement($N,{match:p,routeContext:{outlet:f,matches:S,isDataRoute:t!=null},children:$})};return t&&(p.route.ErrorBoundary||p.route.errorElement||g===0)?M.createElement(QN,{location:t.location,revalidation:t.revalidation,component:b,error:x,children:Q(),routeContext:{outlet:null,matches:S,isDataRoute:!0}}):Q()},null)}var ZC=(function(n){return n.UseBlocker="useBlocker",n.UseRevalidator="useRevalidator",n.UseNavigateStable="useNavigate",n})(ZC||{}),XC=(function(n){return n.UseBlocker="useBlocker",n.UseLoaderData="useLoaderData",n.UseActionData="useActionData",n.UseRouteError="useRouteError",n.UseNavigation="useNavigation",n.UseRouteLoaderData="useRouteLoaderData",n.UseMatches="useMatches",n.UseRevalidator="useRevalidator",n.UseNavigateStable="useNavigate",n.UseRouteId="useRouteId",n})(XC||{});function jN(n){let e=M.useContext(Yd);return e||bt(!1),e}function EN(n){let e=M.useContext(DC);return e||bt(!1),e}function MN(n){let e=M.useContext(ki);return e||bt(!1),e}function BC(n){let e=MN(),t=e.matches[e.matches.length-1];return t.route.id||bt(!1),t.route.id}function AN(){var n;let e=M.useContext(IC),t=EN(),r=BC();return e!==void 0?e:(n=t.errors)==null?void 0:n[r]}function RN(){let{router:n}=jN(ZC.UseNavigateStable),e=BC(XC.UseNavigateStable),t=M.useRef(!1);return zC(()=>{t.current=!0}),M.useCallback(function(i,s){s===void 0&&(s={}),t.current&&(typeof i=="number"?n.navigate(i):n.navigate(i,Gu({fromRouteId:e},s)))},[n,e])}const ub={};function NN(n,e,t){ub[n]||(ub[n]=!0)}function LN(n,e){n==null||n.v7_startTransition,n==null||n.v7_relativeSplatPath}function cb(n){let{to:e,replace:t,state:r,relative:i}=n;ka()||bt(!1);let{future:s,static:l}=M.useContext(Yi),{matches:o}=M.useContext(ki),{pathname:u}=Us(),h=Gs(),f=$y(e,Qy(o,s.v7_relativeSplatPath),u,i==="path"),p=JSON.stringify(f);return M.useEffect(()=>h(JSON.parse(p),{replace:t,state:r,relative:i}),[h,p,i,t,r]),null}function _N(n){return bN(n.context)}function ir(n){bt(!1)}function DN(n){let{basename:e="/",children:t=null,location:r,navigationType:i=_s.Pop,navigator:s,static:l=!1,future:o}=n;ka()&&bt(!1);let u=e.replace(/^\/*/,"/"),h=M.useMemo(()=>({basename:u,navigator:s,static:l,future:Gu({v7_relativeSplatPath:!1},o)}),[u,o,s,l]);typeof r=="string"&&(r=ya(r));let{pathname:f="/",search:p="",hash:g="",state:x=null,key:k="default"}=r,b=M.useMemo(()=>{let w=na(f,u);return w==null?null:{location:{pathname:w,search:p,hash:g,state:x,key:k},navigationType:i}},[u,f,p,g,x,k,i]);return b==null?null:M.createElement(Yi.Provider,{value:h},M.createElement(Ud.Provider,{children:t,value:b}))}function IN(n){let{children:e,location:t}=n;return wN(YO(e),t)}new Promise(()=>{});function YO(n,e){e===void 0&&(e=[]);let t=[];return M.Children.forEach(n,(r,i)=>{if(!M.isValidElement(r))return;let s=[...e,i];if(r.type===M.Fragment){t.push.apply(t,YO(r.props.children,s));return}r.type!==ir&&bt(!1),!r.props.index||!r.props.children||bt(!1);let l={id:r.props.id||s.join("-"),caseSensitive:r.props.caseSensitive,element:r.props.element,Component:r.props.Component,index:r.props.index,path:r.props.path,loader:r.props.loader,action:r.props.action,errorElement:r.props.errorElement,ErrorBoundary:r.props.ErrorBoundary,hasErrorBoundary:r.props.ErrorBoundary!=null||r.props.errorElement!=null,shouldRevalidate:r.props.shouldRevalidate,handle:r.props.handle,lazy:r.props.lazy};r.props.children&&(l.children=YO(r.props.children,s)),t.push(l)}),t}/**
59
59
  * React Router DOM v6.30.4
60
60
  *
61
61
  * Copyright (c) Remix Software Inc.
@@ -64,16 +64,16 @@ Error generating stack: `+v.message+`
64
64
  * LICENSE.md file in the root directory of this source tree.
65
65
  *
66
66
  * @license MIT
67
- */function rd(){return rd=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},rd.apply(null,arguments)}function WC(n,e){if(n==null)return{};var t={};for(var r in n)if({}.hasOwnProperty.call(n,r)){if(e.indexOf(r)!==-1)continue;t[r]=n[r]}return t}function z5(n){return!!(n.metaKey||n.altKey||n.ctrlKey||n.shiftKey)}function Z5(n,e){return n.button===0&&(!e||e==="_self")&&!z5(n)}function UO(n){return n===void 0&&(n=""),new URLSearchParams(typeof n=="string"||Array.isArray(n)||n instanceof URLSearchParams?n:Object.keys(n).reduce((e,t)=>{let r=n[t];return e.concat(Array.isArray(r)?r.map(i=>[t,i]):[[t,r]])},[]))}function X5(n,e){let t=UO(n);return e&&e.forEach((r,i)=>{t.has(i)||e.getAll(i).forEach(s=>{t.append(i,s)})}),t}const B5=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],W5=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],q5="6";try{window.__reactRouterVersion=q5}catch{}const V5=M.createContext({isTransitioning:!1}),F5="startTransition",hb=QR[F5];function Y5(n){let{basename:e,children:t,future:r,window:i}=n,s=M.useRef();s.current==null&&(s.current=FR({window:i,v5Compat:!0}));let l=s.current,[o,u]=M.useState({action:l.action,location:l.location}),{v7_startTransition:h}=r||{},f=M.useCallback(p=>{h&&hb?hb(()=>u(p)):u(p)},[u,h]);return M.useLayoutEffect(()=>l.listen(f),[l,f]),M.useEffect(()=>L5(r),[r]),M.createElement(D5,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:l,future:r})}const U5=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",G5=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,va=M.forwardRef(function(e,t){let{onClick:r,relative:i,reloadDocument:s,replace:l,state:o,target:u,to:h,preventScrollReset:f,viewTransition:p}=e,g=WC(e,B5),{basename:x}=M.useContext(Yi),k,b=!1;if(typeof h=="string"&&G5.test(h)&&(k=h,U5))try{let $=new URL(window.location.href),R=h.startsWith("//")?new URL($.protocol+h):new URL(h),I=na(R.pathname,x);R.origin===$.origin&&I!=null?h=I+R.search+R.hash:b=!0}catch{}let w=y5(h,{relative:i}),S=K5(h,{replace:l,state:o,target:u,preventScrollReset:f,relative:i,viewTransition:p});function Q($){r&&r($),$.defaultPrevented||S($)}return M.createElement("a",rd({},g,{href:k||w,onClick:b||s?r:Q,ref:t,target:u}))}),qC=M.forwardRef(function(e,t){let{"aria-current":r="page",caseSensitive:i=!1,className:s="",end:l=!1,style:o,to:u,viewTransition:h,children:f}=e,p=WC(e,W5),g=Hd(u,{relative:p.relative}),x=Us(),k=M.useContext(DC),{navigator:b,basename:w}=M.useContext(Yi),S=k!=null&&J5(g)&&h===!0,Q=b.encodeLocation?b.encodeLocation(g).pathname:g.pathname,$=x.pathname,R=k&&k.navigation&&k.navigation.location?k.navigation.location.pathname:null;i||($=$.toLowerCase(),R=R?R.toLowerCase():null,Q=Q.toLowerCase()),R&&w&&(R=na(R,w)||R);const I=Q!=="/"&&Q.endsWith("/")?Q.length-1:Q.length;let T=$===Q||!l&&$.startsWith(Q)&&$.charAt(I)==="/",X=R!=null&&(R===Q||!l&&R.startsWith(Q)&&R.charAt(Q.length)==="/"),Z={isActive:T,isPending:X,isTransitioning:S},H=T?r:void 0,N;typeof s=="function"?N=s(Z):N=[s,T?"active":null,X?"pending":null,S?"transitioning":null].filter(Boolean).join(" ");let U=typeof o=="function"?o(Z):o;return M.createElement(va,rd({},p,{"aria-current":H,className:N,ref:t,style:U,to:u,viewTransition:h}),typeof f=="function"?f(Z):f)});var GO;(function(n){n.UseScrollRestoration="useScrollRestoration",n.UseSubmit="useSubmit",n.UseSubmitFetcher="useSubmitFetcher",n.UseFetcher="useFetcher",n.useViewTransitionState="useViewTransitionState"})(GO||(GO={}));var fb;(function(n){n.UseFetcher="useFetcher",n.UseFetchers="useFetchers",n.UseScrollRestoration="useScrollRestoration"})(fb||(fb={}));function H5(n){let e=M.useContext(Yd);return e||bt(!1),e}function K5(n,e){let{target:t,replace:r,state:i,preventScrollReset:s,relative:l,viewTransition:o}=e===void 0?{}:e,u=Gs(),h=Us(),f=Hd(n,{relative:l});return M.useCallback(p=>{if(Z5(p,t)){p.preventDefault();let g=r!==void 0?r:nd(h)===nd(f);u(n,{replace:g,state:i,preventScrollReset:s,relative:l,viewTransition:o})}},[h,u,f,r,i,t,n,s,l,o])}function Mc(n){let e=M.useRef(UO(n)),t=M.useRef(!1),r=Us(),i=M.useMemo(()=>X5(r.search,t.current?null:e.current),[r.search]),s=Gs(),l=M.useCallback((o,u)=>{const h=UO(typeof o=="function"?o(i):o);t.current=!0,s("?"+h,u)},[s,i]);return[i,l]}function J5(n,e){e===void 0&&(e={});let t=M.useContext(V5);t==null&&bt(!1);let{basename:r}=H5(GO.useViewTransitionState),i=Hd(n,{relative:e.relative});if(!t.isTransitioning)return!1;let s=na(t.currentLocation.pathname,r)||t.currentLocation.pathname,l=na(t.nextLocation.pathname,r)||t.nextLocation.pathname;return FO(i.pathname,l)!=null||FO(i.pathname,s)!=null}const VC=M.createContext(null);function eN({children:n}){const[e,t]=M.useState(null),r=M.useCallback(l=>t(l),[]),i=M.useCallback(()=>t(null),[]),s=M.useMemo(()=>({active:e,open:r,close:i}),[e,r,i]);return m.jsx(VC.Provider,{value:s,children:n})}function zt(){const n=M.useContext(VC);if(!n)throw new Error("useModals must be used inside ModalsProvider");return n}function db(n){const e=n.target;if(!e)return!1;const t=e.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable||e.closest(".cm-editor"))}function tN(){const{active:n,open:e,close:t}=zt(),r=Gs();M.useEffect(()=>{const i=s=>{const l=s.metaKey||s.ctrlKey;if(l&&s.key.toLowerCase()==="k"){s.preventDefault(),e({kind:"search"});return}if(s.key==="Escape"){n&&(s.preventDefault(),t());return}if(!db(s)&&!(s.altKey||l)){if(s.key==="c"){s.preventDefault(),e({kind:"quick-create"});return}if(s.key==="n"){s.preventDefault(),e({kind:"new-project"});return}if(s.key==="g"){const o=u=>{if(window.removeEventListener("keydown",o),db(u))return;const f={d:"/",t:"/today",i:"/inbox",w:"/dashboard"}[u.key];f&&(u.preventDefault(),r(f))};window.addEventListener("keydown",o,{once:!0});return}}};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[n,e,t,r])}let HO=[],FC=[];(()=>{let n="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(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?FC:HO).push(t=t+n[e])})();function nN(n){if(n<768)return!1;for(let e=0,t=HO.length;;){let r=e+t>>1;if(n<HO[r])t=r;else if(n>=FC[r])e=r+1;else return!0;if(e==t)return!1}}function pb(n){return n>=127462&&n<=127487}const mb=8205;function rN(n,e,t=!0,r=!0){return(t?YC:iN)(n,e,r)}function YC(n,e,t){if(e==n.length)return e;e&&UC(n.charCodeAt(e))&&GC(n.charCodeAt(e-1))&&e--;let r=gg(n,e);for(e+=gb(r);e<n.length;){let i=gg(n,e);if(r==mb||i==mb||t&&nN(i))e+=gb(i),r=i;else if(pb(i)){let s=0,l=e-2;for(;l>=0&&pb(gg(n,l));)s++,l-=2;if(s%2==0)break;e+=2}else break}return e}function iN(n,e,t){for(;e>0;){let r=YC(n,e-2,t);if(r<e)return r;e--}return 0}function gg(n,e){let t=n.charCodeAt(e);if(!GC(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return UC(r)?(t-55296<<10)+(r-56320)+65536:t}function UC(n){return n>=56320&&n<57344}function GC(n){return n>=55296&&n<56320}function gb(n){return n<65536?1:2}class Ge{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,r){[e,t]=ra(this,e,t);let i=[];return this.decompose(0,e,i,2),r.length&&r.decompose(0,r.length,i,3),this.decompose(t,this.length,i,1),ci.from(i,this.length-(t-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=ra(this,e,t);let r=[];return this.decompose(e,t,r,0),ci.from(r,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),r=this.length-this.scanIdentical(e,-1),i=new Nu(this),s=new Nu(e);for(let l=t,o=t;;){if(i.next(l),s.next(l),l=0,i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return!1;if(o+=i.value.length,i.done||o>=r)return!0}}iter(e=1){return new Nu(this,e)}iterRange(e,t=this.length){return new HC(this,e,t)}iterLines(e,t){let r;if(e==null)r=this.iter();else{t==null&&(t=this.lines+1);let i=this.line(e).from;r=this.iterRange(i,Math.max(i,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new KC(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?Ge.empty:e.length<=32?new jt(e):ci.from(jt.split(e,[]))}}class jt extends Ge{constructor(e,t=sN(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,r,i){for(let s=0;;s++){let l=this.text[s],o=i+l.length;if((t?r:o)>=e)return new lN(i,o,r,l);i=o+1,r++}}decompose(e,t,r,i){let s=e<=0&&t>=this.length?this:new jt(Ob(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(i&1){let l=r.pop(),o=If(s.text,l.text.slice(),0,s.length);if(o.length<=32)r.push(new jt(o,l.length+s.length));else{let u=o.length>>1;r.push(new jt(o.slice(0,u)),new jt(o.slice(u)))}}else r.push(s)}replace(e,t,r){if(!(r instanceof jt))return super.replace(e,t,r);[e,t]=ra(this,e,t);let i=If(this.text,If(r.text,Ob(this.text,0,e)),t),s=this.length+r.length-(t-e);return i.length<=32?new jt(i,s):ci.from(jt.split(i,[]),s)}sliceString(e,t=this.length,r=`
67
+ */function rd(){return rd=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},rd.apply(null,arguments)}function WC(n,e){if(n==null)return{};var t={};for(var r in n)if({}.hasOwnProperty.call(n,r)){if(e.indexOf(r)!==-1)continue;t[r]=n[r]}return t}function zN(n){return!!(n.metaKey||n.altKey||n.ctrlKey||n.shiftKey)}function ZN(n,e){return n.button===0&&(!e||e==="_self")&&!zN(n)}function UO(n){return n===void 0&&(n=""),new URLSearchParams(typeof n=="string"||Array.isArray(n)||n instanceof URLSearchParams?n:Object.keys(n).reduce((e,t)=>{let r=n[t];return e.concat(Array.isArray(r)?r.map(i=>[t,i]):[[t,r]])},[]))}function XN(n,e){let t=UO(n);return e&&e.forEach((r,i)=>{t.has(i)||e.getAll(i).forEach(s=>{t.append(i,s)})}),t}const BN=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],WN=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],qN="6";try{window.__reactRouterVersion=qN}catch{}const VN=M.createContext({isTransitioning:!1}),FN="startTransition",hb=QR[FN];function YN(n){let{basename:e,children:t,future:r,window:i}=n,s=M.useRef();s.current==null&&(s.current=FR({window:i,v5Compat:!0}));let l=s.current,[o,u]=M.useState({action:l.action,location:l.location}),{v7_startTransition:h}=r||{},f=M.useCallback(p=>{h&&hb?hb(()=>u(p)):u(p)},[u,h]);return M.useLayoutEffect(()=>l.listen(f),[l,f]),M.useEffect(()=>LN(r),[r]),M.createElement(DN,{basename:e,children:t,location:o.location,navigationType:o.action,navigator:l,future:r})}const UN=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",GN=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,va=M.forwardRef(function(e,t){let{onClick:r,relative:i,reloadDocument:s,replace:l,state:o,target:u,to:h,preventScrollReset:f,viewTransition:p}=e,g=WC(e,BN),{basename:x}=M.useContext(Yi),k,b=!1;if(typeof h=="string"&&GN.test(h)&&(k=h,UN))try{let $=new URL(window.location.href),R=h.startsWith("//")?new URL($.protocol+h):new URL(h),I=na(R.pathname,x);R.origin===$.origin&&I!=null?h=I+R.search+R.hash:b=!0}catch{}let w=yN(h,{relative:i}),S=KN(h,{replace:l,state:o,target:u,preventScrollReset:f,relative:i,viewTransition:p});function Q($){r&&r($),$.defaultPrevented||S($)}return M.createElement("a",rd({},g,{href:k||w,onClick:b||s?r:Q,ref:t,target:u}))}),qC=M.forwardRef(function(e,t){let{"aria-current":r="page",caseSensitive:i=!1,className:s="",end:l=!1,style:o,to:u,viewTransition:h,children:f}=e,p=WC(e,WN),g=Hd(u,{relative:p.relative}),x=Us(),k=M.useContext(DC),{navigator:b,basename:w}=M.useContext(Yi),S=k!=null&&JN(g)&&h===!0,Q=b.encodeLocation?b.encodeLocation(g).pathname:g.pathname,$=x.pathname,R=k&&k.navigation&&k.navigation.location?k.navigation.location.pathname:null;i||($=$.toLowerCase(),R=R?R.toLowerCase():null,Q=Q.toLowerCase()),R&&w&&(R=na(R,w)||R);const I=Q!=="/"&&Q.endsWith("/")?Q.length-1:Q.length;let T=$===Q||!l&&$.startsWith(Q)&&$.charAt(I)==="/",X=R!=null&&(R===Q||!l&&R.startsWith(Q)&&R.charAt(Q.length)==="/"),Z={isActive:T,isPending:X,isTransitioning:S},H=T?r:void 0,N;typeof s=="function"?N=s(Z):N=[s,T?"active":null,X?"pending":null,S?"transitioning":null].filter(Boolean).join(" ");let U=typeof o=="function"?o(Z):o;return M.createElement(va,rd({},p,{"aria-current":H,className:N,ref:t,style:U,to:u,viewTransition:h}),typeof f=="function"?f(Z):f)});var GO;(function(n){n.UseScrollRestoration="useScrollRestoration",n.UseSubmit="useSubmit",n.UseSubmitFetcher="useSubmitFetcher",n.UseFetcher="useFetcher",n.useViewTransitionState="useViewTransitionState"})(GO||(GO={}));var fb;(function(n){n.UseFetcher="useFetcher",n.UseFetchers="useFetchers",n.UseScrollRestoration="useScrollRestoration"})(fb||(fb={}));function HN(n){let e=M.useContext(Yd);return e||bt(!1),e}function KN(n,e){let{target:t,replace:r,state:i,preventScrollReset:s,relative:l,viewTransition:o}=e===void 0?{}:e,u=Gs(),h=Us(),f=Hd(n,{relative:l});return M.useCallback(p=>{if(ZN(p,t)){p.preventDefault();let g=r!==void 0?r:nd(h)===nd(f);u(n,{replace:g,state:i,preventScrollReset:s,relative:l,viewTransition:o})}},[h,u,f,r,i,t,n,s,l,o])}function Mc(n){let e=M.useRef(UO(n)),t=M.useRef(!1),r=Us(),i=M.useMemo(()=>XN(r.search,t.current?null:e.current),[r.search]),s=Gs(),l=M.useCallback((o,u)=>{const h=UO(typeof o=="function"?o(i):o);t.current=!0,s("?"+h,u)},[s,i]);return[i,l]}function JN(n,e){e===void 0&&(e={});let t=M.useContext(VN);t==null&&bt(!1);let{basename:r}=HN(GO.useViewTransitionState),i=Hd(n,{relative:e.relative});if(!t.isTransitioning)return!1;let s=na(t.currentLocation.pathname,r)||t.currentLocation.pathname,l=na(t.nextLocation.pathname,r)||t.nextLocation.pathname;return FO(i.pathname,l)!=null||FO(i.pathname,s)!=null}const VC=M.createContext(null);function e5({children:n}){const[e,t]=M.useState(null),r=M.useCallback(l=>t(l),[]),i=M.useCallback(()=>t(null),[]),s=M.useMemo(()=>({active:e,open:r,close:i}),[e,r,i]);return m.jsx(VC.Provider,{value:s,children:n})}function zt(){const n=M.useContext(VC);if(!n)throw new Error("useModals must be used inside ModalsProvider");return n}function db(n){const e=n.target;if(!e)return!1;const t=e.tagName;return!!(t==="INPUT"||t==="TEXTAREA"||t==="SELECT"||e.isContentEditable||e.closest(".cm-editor"))}function t5(){const{active:n,open:e,close:t}=zt(),r=Gs();M.useEffect(()=>{const i=s=>{const l=s.metaKey||s.ctrlKey;if(l&&s.key.toLowerCase()==="k"){s.preventDefault(),e({kind:"search"});return}if(s.key==="Escape"){n&&(s.preventDefault(),t());return}if(!db(s)&&!(s.altKey||l)){if(s.key==="c"){s.preventDefault(),e({kind:"quick-create"});return}if(s.key==="n"){s.preventDefault(),e({kind:"new-project"});return}if(s.key==="g"){const o=u=>{if(window.removeEventListener("keydown",o),db(u))return;const f={d:"/",t:"/today",i:"/inbox",w:"/dashboard"}[u.key];f&&(u.preventDefault(),r(f))};window.addEventListener("keydown",o,{once:!0});return}}};return window.addEventListener("keydown",i),()=>window.removeEventListener("keydown",i)},[n,e,t,r])}let HO=[],FC=[];(()=>{let n="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(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?FC:HO).push(t=t+n[e])})();function n5(n){if(n<768)return!1;for(let e=0,t=HO.length;;){let r=e+t>>1;if(n<HO[r])t=r;else if(n>=FC[r])e=r+1;else return!0;if(e==t)return!1}}function pb(n){return n>=127462&&n<=127487}const mb=8205;function r5(n,e,t=!0,r=!0){return(t?YC:i5)(n,e,r)}function YC(n,e,t){if(e==n.length)return e;e&&UC(n.charCodeAt(e))&&GC(n.charCodeAt(e-1))&&e--;let r=gg(n,e);for(e+=gb(r);e<n.length;){let i=gg(n,e);if(r==mb||i==mb||t&&n5(i))e+=gb(i),r=i;else if(pb(i)){let s=0,l=e-2;for(;l>=0&&pb(gg(n,l));)s++,l-=2;if(s%2==0)break;e+=2}else break}return e}function i5(n,e,t){for(;e>0;){let r=YC(n,e-2,t);if(r<e)return r;e--}return 0}function gg(n,e){let t=n.charCodeAt(e);if(!GC(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return UC(r)?(t-55296<<10)+(r-56320)+65536:t}function UC(n){return n>=56320&&n<57344}function GC(n){return n>=55296&&n<56320}function gb(n){return n<65536?1:2}class Ge{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,r){[e,t]=ra(this,e,t);let i=[];return this.decompose(0,e,i,2),r.length&&r.decompose(0,r.length,i,3),this.decompose(t,this.length,i,1),ci.from(i,this.length-(t-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=ra(this,e,t);let r=[];return this.decompose(e,t,r,0),ci.from(r,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),r=this.length-this.scanIdentical(e,-1),i=new Nu(this),s=new Nu(e);for(let l=t,o=t;;){if(i.next(l),s.next(l),l=0,i.lineBreak!=s.lineBreak||i.done!=s.done||i.value!=s.value)return!1;if(o+=i.value.length,i.done||o>=r)return!0}}iter(e=1){return new Nu(this,e)}iterRange(e,t=this.length){return new HC(this,e,t)}iterLines(e,t){let r;if(e==null)r=this.iter();else{t==null&&(t=this.lines+1);let i=this.line(e).from;r=this.iterRange(i,Math.max(i,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new KC(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?Ge.empty:e.length<=32?new jt(e):ci.from(jt.split(e,[]))}}class jt extends Ge{constructor(e,t=s5(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,r,i){for(let s=0;;s++){let l=this.text[s],o=i+l.length;if((t?r:o)>=e)return new l5(i,o,r,l);i=o+1,r++}}decompose(e,t,r,i){let s=e<=0&&t>=this.length?this:new jt(Ob(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(i&1){let l=r.pop(),o=If(s.text,l.text.slice(),0,s.length);if(o.length<=32)r.push(new jt(o,l.length+s.length));else{let u=o.length>>1;r.push(new jt(o.slice(0,u)),new jt(o.slice(u)))}}else r.push(s)}replace(e,t,r){if(!(r instanceof jt))return super.replace(e,t,r);[e,t]=ra(this,e,t);let i=If(this.text,If(r.text,Ob(this.text,0,e)),t),s=this.length+r.length-(t-e);return i.length<=32?new jt(i,s):ci.from(jt.split(i,[]),s)}sliceString(e,t=this.length,r=`
68
68
  `){[e,t]=ra(this,e,t);let i="";for(let s=0,l=0;s<=t&&l<this.text.length;l++){let o=this.text[l],u=s+o.length;s>e&&l&&(i+=r),e<u&&t>s&&(i+=o.slice(Math.max(0,e-s),t-s)),s=u+1}return i}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let r=[],i=-1;for(let s of e)r.push(s),i+=s.length+1,r.length==32&&(t.push(new jt(r,i)),r=[],i=-1);return i>-1&&t.push(new jt(r,i)),t}}class ci extends Ge{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let r of e)this.lines+=r.lines}lineInner(e,t,r,i){for(let s=0;;s++){let l=this.children[s],o=i+l.length,u=r+l.lines-1;if((t?u:o)>=e)return l.lineInner(e,t,r,i);i=o+1,r=u+1}}decompose(e,t,r,i){for(let s=0,l=0;l<=t&&s<this.children.length;s++){let o=this.children[s],u=l+o.length;if(e<=u&&t>=l){let h=i&((l<=e?1:0)|(u>=t?2:0));l>=e&&u<=t&&!h?r.push(o):o.decompose(e-l,t-l,r,h)}l=u+1}}replace(e,t,r){if([e,t]=ra(this,e,t),r.lines<this.lines)for(let i=0,s=0;i<this.children.length;i++){let l=this.children[i],o=s+l.length;if(e>=s&&t<=o){let u=l.replace(e-s,t-s,r),h=this.lines-l.lines+u.lines;if(u.lines<h>>4&&u.lines>h>>6){let f=this.children.slice();return f[i]=u,new ci(f,this.length-(t-e)+r.length)}return super.replace(s,o,u)}s=o+1}return super.replace(e,t,r)}sliceString(e,t=this.length,r=`
69
- `){[e,t]=ra(this,e,t);let i="";for(let s=0,l=0;s<this.children.length&&l<=t;s++){let o=this.children[s],u=l+o.length;l>e&&s&&(i+=r),e<u&&t>l&&(i+=o.sliceString(e-l,t-l,r)),l=u+1}return i}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof ci))return 0;let r=0,[i,s,l,o]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;i+=t,s+=t){if(i==l||s==o)return r;let u=this.children[i],h=e.children[s];if(u!=h)return r+u.scanIdentical(h,t);r+=u.length+1}}static from(e,t=e.reduce((r,i)=>r+i.length+1,-1)){let r=0;for(let x of e)r+=x.lines;if(r<32){let x=[];for(let k of e)k.flatten(x);return new jt(x,t)}let i=Math.max(32,r>>5),s=i<<1,l=i>>1,o=[],u=0,h=-1,f=[];function p(x){let k;if(x.lines>s&&x instanceof ci)for(let b of x.children)p(b);else x.lines>l&&(u>l||!u)?(g(),o.push(x)):x instanceof jt&&u&&(k=f[f.length-1])instanceof jt&&x.lines+k.lines<=32?(u+=x.lines,h+=x.length+1,f[f.length-1]=new jt(k.text.concat(x.text),k.length+1+x.length)):(u+x.lines>i&&g(),u+=x.lines,h+=x.length+1,f.push(x))}function g(){u!=0&&(o.push(f.length==1?f[0]:ci.from(f,h)),h=-1,u=f.length=0)}for(let x of e)p(x);return g(),o.length==1?o[0]:new ci(o,t)}}Ge.empty=new jt([""],0);function sN(n){let e=-1;for(let t of n)e+=t.length+1;return e}function If(n,e,t=0,r=1e9){for(let i=0,s=0,l=!0;s<n.length&&i<=r;s++){let o=n[s],u=i+o.length;u>=t&&(u>r&&(o=o.slice(0,r-i)),i<t&&(o=o.slice(t-i)),l?(e[e.length-1]+=o,l=!1):e.push(o)),i=u+1}return e}function Ob(n,e,t){return If(n,[""],e,t)}class Nu{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 jt?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,i=this.nodes[r],s=this.offsets[r],l=s>>1,o=i instanceof jt?i.text.length:i.children.length;if(l==(t>0?o:0)){if(r==0)return this.done=!0,this.value="",this;t>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[r]+=t,e==0)return this.lineBreak=!0,this.value=`
70
- `,this;e--}else if(i instanceof jt){let u=i.text[l+(t<0?-1:0)];if(this.offsets[r]+=t,u.length>Math.max(0,e))return this.value=e==0?u:t>0?u.slice(e):u.slice(0,u.length-e),this;e-=u.length}else{let u=i.children[l+(t<0?-1:0)];e>u.length?(e-=u.length,this.offsets[r]+=t):(t<0&&this.offsets[r]--,this.nodes.push(u),this.offsets.push(t>0?1:(u instanceof jt?u.text.length:u.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class HC{constructor(e,t,r){this.value="",this.done=!1,this.cursor=new Nu(e,t>r?-1:1),this.pos=t>r?e.length:0,this.from=Math.min(t,r),this.to=Math.max(t,r)}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 r=t<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:i}=this.cursor.next(e);return this.pos+=(i.length+e)*t,this.value=i.length<=r?i:t<0?i.slice(i.length-r):i.slice(0,r),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!=""}}class KC{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:r,value:i}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=i,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(Ge.prototype[Symbol.iterator]=function(){return this.iter()},Nu.prototype[Symbol.iterator]=HC.prototype[Symbol.iterator]=KC.prototype[Symbol.iterator]=function(){return this});let lN=class{constructor(e,t,r,i){this.from=e,this.to=t,this.number=r,this.text=i}get length(){return this.to-this.from}};function ra(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function Ut(n,e,t=!0,r=!0){return rN(n,e,t,r)}function oN(n){return n>=56320&&n<57344}function aN(n){return n>=55296&&n<56320}function In(n,e){let t=n.charCodeAt(e);if(!aN(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return oN(r)?(t-55296<<10)+(r-56320)+65536:t}function Ty(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function hi(n){return n<65536?1:2}const KO=/\r\n?|\n/;var sn=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(sn||(sn={}));class Oi{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 r=this.sections[t+1];e+=r<0?this.sections[t]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,r=0,i=0;t<this.sections.length;){let s=this.sections[t++],l=this.sections[t++];l<0?(e(r,i,s),i+=s):i+=l,r+=s}}iterChangedRanges(e,t=!1){JO(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let r=this.sections[t++],i=this.sections[t++];i<0?e.push(r,i):e.push(i,r)}return new Oi(e)}composeDesc(e){return this.empty?e:e.empty?this:JC(this,e)}mapDesc(e,t=!1){return e.empty?this:ex(this,e,t)}mapPos(e,t=-1,r=sn.Simple){let i=0,s=0;for(let l=0;l<this.sections.length;){let o=this.sections[l++],u=this.sections[l++],h=i+o;if(u<0){if(h>e)return s+(e-i);s+=o}else{if(r!=sn.Simple&&h>=e&&(r==sn.TrackDel&&i<e&&h>e||r==sn.TrackBefore&&i<e||r==sn.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!o)return e==i||t<0?s:s+u;s+=u}i=h}if(e>i)throw new RangeError(`Position ${e} is out of range for changeset of length ${i}`);return s}touchesRange(e,t=e){for(let r=0,i=0;r<this.sections.length&&i<=t;){let s=this.sections[r++],l=this.sections[r++],o=i+s;if(l>=0&&i<=t&&o>=e)return i<e&&o>t?"cover":!0;i=o}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let r=this.sections[t++],i=this.sections[t++];e+=(e?" ":"")+r+(i>=0?":"+i:"")}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 Oi(e)}static create(e){return new Oi(e)}}class Lt extends Oi{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 JO(this,(t,r,i,s,l)=>e=e.replace(i,i+(r-t),l),!1),e}mapDesc(e,t=!1){return ex(this,e,t,!0)}invert(e){let t=this.sections.slice(),r=[];for(let i=0,s=0;i<t.length;i+=2){let l=t[i],o=t[i+1];if(o>=0){t[i]=o,t[i+1]=l;let u=i>>1;for(;r.length<u;)r.push(Ge.empty);r.push(l?e.slice(s,s+l):Ge.empty)}s+=l}return new Lt(t,r)}compose(e){return this.empty?e:e.empty?this:JC(this,e,!0)}map(e,t=!1){return e.empty?this:ex(this,e,t,!0)}iterChanges(e,t=!1){JO(this,e,t)}get desc(){return Oi.create(this.sections)}filter(e){let t=[],r=[],i=[],s=new Hu(this);e:for(let l=0,o=0;;){let u=l==e.length?1e9:e[l++];for(;o<u||o==u&&s.len==0;){if(s.done)break e;let f=Math.min(s.len,u-o);pn(i,f,-1);let p=s.ins==-1?-1:s.off==0?s.ins:0;pn(t,f,p),p>0&&Ds(r,t,s.text),s.forward(f),o+=f}let h=e[l++];for(;o<h;){if(s.done)break e;let f=Math.min(s.len,h-o);pn(t,f,-1),pn(i,f,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(f),o+=f}}return{changes:new Lt(t,r),filtered:Oi.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t],i=this.sections[t+1];i<0?e.push(r):i==0?e.push([r]):e.push([r].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,r){let i=[],s=[],l=0,o=null;function u(f=!1){if(!f&&!i.length)return;l<t&&pn(i,t-l,-1);let p=new Lt(i,s);o=o?o.compose(p.map(o)):p,i=[],s=[],l=0}function h(f){if(Array.isArray(f))for(let p of f)h(p);else if(f instanceof Lt){if(f.length!=t)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${t})`);u(),o=o?o.compose(f.map(o)):f}else{let{from:p,to:g=p,insert:x}=f;if(p>g||p<0||g>t)throw new RangeError(`Invalid change range ${p} to ${g} (in doc of length ${t})`);let k=x?typeof x=="string"?Ge.of(x.split(r||KO)):x:Ge.empty,b=k.length;if(p==g&&b==0)return;p<l&&u(),p>l&&pn(i,p-l,-1),pn(i,g-p,b),Ds(s,i,k),l=g}}return h(e),u(!o),o}static empty(e){return new Lt(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],r=[];for(let i=0;i<e.length;i++){let s=e[i];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((l,o)=>o&&typeof l!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;r.length<i;)r.push(Ge.empty);r[i]=Ge.of(s.slice(1)),t.push(s[0],r[i].length)}}}return new Lt(t,r)}static createSet(e,t){return new Lt(e,t)}}function pn(n,e,t,r=!1){if(e==0&&t<=0)return;let i=n.length-2;i>=0&&t<=0&&t==n[i+1]?n[i]+=e:i>=0&&e==0&&n[i]==0?n[i+1]+=t:r?(n[i]+=e,n[i+1]+=t):n.push(e,t)}function Ds(n,e,t){if(t.length==0)return;let r=e.length-2>>1;if(r<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<r;)n.push(Ge.empty);n.push(t)}}function JO(n,e,t){let r=n.inserted;for(let i=0,s=0,l=0;l<n.sections.length;){let o=n.sections[l++],u=n.sections[l++];if(u<0)i+=o,s+=o;else{let h=i,f=s,p=Ge.empty;for(;h+=o,f+=u,u&&r&&(p=p.append(r[l-2>>1])),!(t||l==n.sections.length||n.sections[l+1]<0);)o=n.sections[l++],u=n.sections[l++];e(i,h,s,f,p),i=h,s=f}}}function ex(n,e,t,r=!1){let i=[],s=r?[]:null,l=new Hu(n),o=new Hu(e);for(let u=-1;;){if(l.done&&o.len||o.done&&l.len)throw new Error("Mismatched change set lengths");if(l.ins==-1&&o.ins==-1){let h=Math.min(l.len,o.len);pn(i,h,-1),l.forward(h),o.forward(h)}else if(o.ins>=0&&(l.ins<0||u==l.i||l.off==0&&(o.len<l.len||o.len==l.len&&!t))){let h=o.len;for(pn(i,o.ins,-1);h;){let f=Math.min(l.len,h);l.ins>=0&&u<l.i&&l.len<=f&&(pn(i,0,l.ins),s&&Ds(s,i,l.text),u=l.i),l.forward(f),h-=f}o.next()}else if(l.ins>=0){let h=0,f=l.len;for(;f;)if(o.ins==-1){let p=Math.min(f,o.len);h+=p,f-=p,o.forward(p)}else if(o.ins==0&&o.len<f)f-=o.len,o.next();else break;pn(i,h,u<l.i?l.ins:0),s&&u<l.i&&Ds(s,i,l.text),u=l.i,l.forward(l.len-f)}else{if(l.done&&o.done)return s?Lt.createSet(i,s):Oi.create(i);throw new Error("Mismatched change set lengths")}}}function JC(n,e,t=!1){let r=[],i=t?[]:null,s=new Hu(n),l=new Hu(e);for(let o=!1;;){if(s.done&&l.done)return i?Lt.createSet(r,i):Oi.create(r);if(s.ins==0)pn(r,s.len,0,o),s.next();else if(l.len==0&&!l.done)pn(r,0,l.ins,o),i&&Ds(i,r,l.text),l.next();else{if(s.done||l.done)throw new Error("Mismatched change set lengths");{let u=Math.min(s.len2,l.len),h=r.length;if(s.ins==-1){let f=l.ins==-1?-1:l.off?0:l.ins;pn(r,u,f,o),i&&f&&Ds(i,r,l.text)}else l.ins==-1?(pn(r,s.off?0:s.len,u,o),i&&Ds(i,r,s.textBit(u))):(pn(r,s.off?0:s.len,l.off?0:l.ins,o),i&&!l.off&&Ds(i,r,l.text));o=(s.ins>u||l.ins>=0&&l.len>u)&&(o||r.length>h),s.forward2(u),l.forward(u)}}}}class Hu{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?Ge.empty:e[t]}textBit(e){let{inserted:t}=this.set,r=this.i-2>>1;return r>=t.length&&!e?Ge.empty:t[r].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)}}class wl{constructor(e,t,r){this.from=e,this.to=t,this.flags=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let r,i;return this.empty?r=i=e.mapPos(this.from,t):(r=e.mapPos(this.from,1),i=e.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new wl(r,i,this.flags)}extend(e,t=e,r=0){if(e<=this.anchor&&t>=this.anchor)return Y.range(e,t,void 0,void 0,r);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return Y.range(this.anchor,i,void 0,void 0,r)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}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 Y.range(e.anchor,e.head)}static create(e,t,r){return new wl(e,t,r)}}class Y{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:Y.create(this.ranges.map(r=>r.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new Y([this.main],0)}addRange(e,t=!0){return Y.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let r=this.ranges.slice();return r[t]=e,Y.create(r,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 Y(e.ranges.map(t=>wl.fromJSON(t)),e.main)}static single(e,t=e){return new Y([Y.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 r=0,i=0;i<e.length;i++){let s=e[i];if(s.empty?s.from<=r:s.from<r)return Y.normalized(e.slice(),t);r=s.to}return new Y(e,t)}static cursor(e,t=0,r,i){return wl.create(e,e,(t==0?0:t<0?8:16)|(r==null?7:Math.min(6,r))|(i??16777215)<<6)}static range(e,t,r,i,s){let l=(r??16777215)<<6|(i==null?7:Math.min(6,i));return!s&&e!=t&&(s=t<e?1:-1),t<e?wl.create(t,e,48|l):wl.create(e,t,(s?s<0?8:16:0)|l)}static normalized(e,t=0){let r=e[t];e.sort((i,s)=>i.from-s.from),t=e.indexOf(r);for(let i=1;i<e.length;i++){let s=e[i],l=e[i-1];if(s.empty?s.from<=l.to:s.from<l.to){let o=l.from,u=Math.max(s.to,l.to);i<=t&&t--,e.splice(--i,2,s.anchor>s.head?Y.range(u,o):Y.range(o,u))}}return new Y(e,t)}}function e2(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let jy=0;class ge{constructor(e,t,r,i,s){this.combine=e,this.compareInput=t,this.compare=r,this.isStatic=i,this.id=jy++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new ge(e.combine||(t=>t),e.compareInput||((t,r)=>t===r),e.compare||(e.combine?(t,r)=>t===r:Ey),!!e.static,e.enables)}of(e){return new zf([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new zf(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new zf(e,this,2,t)}from(e,t){return t||(t=r=>r),this.compute([e],r=>t(r.field(e)))}}function Ey(n,e){return n==e||n.length==e.length&&n.every((t,r)=>t===e[r])}class zf{constructor(e,t,r,i){this.dependencies=e,this.facet=t,this.type=r,this.value=i,this.id=jy++}dynamicSlot(e){var t;let r=this.value,i=this.facet.compareInput,s=this.id,l=e[s]>>1,o=this.type==2,u=!1,h=!1,f=[];for(let p of this.dependencies)p=="doc"?u=!0:p=="selection"?h=!0:(((t=e[p.id])!==null&&t!==void 0?t:1)&1)==0&&f.push(e[p.id]);return{create(p){return p.values[l]=r(p),1},update(p,g){if(u&&g.docChanged||h&&(g.docChanged||g.selection)||tx(p,f)){let x=r(p);if(o?!xb(x,p.values[l],i):!i(x,p.values[l]))return p.values[l]=x,1}return 0},reconfigure:(p,g)=>{let x,k=g.config.address[s];if(k!=null){let b=sd(g,k);if(this.dependencies.every(w=>w instanceof ge?g.facet(w)===p.facet(w):w instanceof an?g.field(w,!1)==p.field(w,!1):!0)||(o?xb(x=r(p),b,i):i(x=r(p),b)))return p.values[l]=b,0}else x=r(p);return p.values[l]=x,1}}}}function xb(n,e,t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!t(n[r],e[r]))return!1;return!0}function tx(n,e){let t=!1;for(let r of e)Lu(n,r)&1&&(t=!0);return t}function uN(n,e,t){let r=t.map(u=>n[u.id]),i=t.map(u=>u.type),s=r.filter(u=>!(u&1)),l=n[e.id]>>1;function o(u){let h=[];for(let f=0;f<r.length;f++){let p=sd(u,r[f]);if(i[f]==2)for(let g of p)h.push(g);else h.push(p)}return e.combine(h)}return{create(u){for(let h of r)Lu(u,h);return u.values[l]=o(u),1},update(u,h){if(!tx(u,s))return 0;let f=o(u);return e.compare(f,u.values[l])?0:(u.values[l]=f,1)},reconfigure(u,h){let f=tx(u,r),p=h.config.facets[e.id],g=h.facet(e);if(p&&!f&&Ey(t,p))return u.values[l]=g,0;let x=o(u);return e.compare(x,g)?(u.values[l]=g,0):(u.values[l]=x,1)}}}const of=ge.define({static:!0});class an{constructor(e,t,r,i,s){this.id=e,this.createF=t,this.updateF=r,this.compareF=i,this.spec=s,this.provides=void 0}static define(e){let t=new an(jy++,e.create,e.update,e.compare||((r,i)=>r===i),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(of).find(r=>r.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:r=>(r.values[t]=this.create(r),1),update:(r,i)=>{let s=r.values[t],l=this.updateF(s,i);return this.compareF(s,l)?0:(r.values[t]=l,1)},reconfigure:(r,i)=>{let s=r.facet(of),l=i.facet(of),o;return(o=s.find(u=>u.field==this))&&o!=l.find(u=>u.field==this)?(r.values[t]=o.create(r),1):i.config.address[this.id]!=null?(r.values[t]=i.field(this),0):(r.values[t]=this.create(r),1)}}}init(e){return[this,of.of({field:this,create:e})]}get extension(){return this}}const yl={lowest:4,low:3,default:2,high:1,highest:0};function gu(n){return e=>new t2(e,n)}const Ui={highest:gu(yl.highest),high:gu(yl.high),default:gu(yl.default),low:gu(yl.low),lowest:gu(yl.lowest)};class t2{constructor(e,t){this.inner=e,this.prec=t}}class Kd{of(e){return new nx(this,e)}reconfigure(e){return Kd.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class nx{constructor(e,t){this.compartment=e,this.inner=t}}class id{constructor(e,t,r,i,s,l){for(this.base=e,this.compartments=t,this.dynamicSlots=r,this.address=i,this.staticValues=s,this.facets=l,this.statusTemplate=[];this.statusTemplate.length<r.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,r){let i=[],s=Object.create(null),l=new Map;for(let g of cN(e,t,l))g instanceof an?i.push(g):(s[g.facet.id]||(s[g.facet.id]=[])).push(g);let o=Object.create(null),u=[],h=[];for(let g of i)o[g.id]=h.length<<1,h.push(x=>g.slot(x));let f=r==null?void 0:r.config.facets;for(let g in s){let x=s[g],k=x[0].facet,b=f&&f[g]||[];if(x.every(w=>w.type==0))if(o[k.id]=u.length<<1|1,Ey(b,x))u.push(r.facet(k));else{let w=k.combine(x.map(S=>S.value));u.push(r&&k.compare(w,r.facet(k))?r.facet(k):w)}else{for(let w of x)w.type==0?(o[w.id]=u.length<<1|1,u.push(w.value)):(o[w.id]=h.length<<1,h.push(S=>w.dynamicSlot(S)));o[k.id]=h.length<<1,h.push(w=>uN(w,k,x))}}let p=h.map(g=>g(o));return new id(e,l,p,o,u,s)}}function cN(n,e,t){let r=[[],[],[],[],[]],i=new Map;function s(l,o){let u=i.get(l);if(u!=null){if(u<=o)return;let h=r[u].indexOf(l);h>-1&&r[u].splice(h,1),l instanceof nx&&t.delete(l.compartment)}if(i.set(l,o),Array.isArray(l))for(let h of l)s(h,o);else if(l instanceof nx){if(t.has(l.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(l.compartment)||l.inner;t.set(l.compartment,h),s(h,o)}else if(l instanceof t2)s(l.inner,l.prec);else if(l instanceof an)r[o].push(l),l.provides&&s(l.provides,o);else if(l instanceof zf)r[o].push(l),l.facet.extensions&&s(l.facet.extensions,yl.default);else{let h=l.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${l}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,o)}}return s(n,yl.default),r.reduce((l,o)=>l.concat(o))}function Lu(n,e){if(e&1)return 2;let t=e>>1,r=n.status[t];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;n.status[t]=4;let i=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|i}function sd(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const n2=ge.define(),rx=ge.define({combine:n=>n.some(e=>e),static:!0}),r2=ge.define({combine:n=>n.length?n[0]:void 0,static:!0}),i2=ge.define(),s2=ge.define(),l2=ge.define(),o2=ge.define({combine:n=>n.length?n[0]:!1});class vi{constructor(e,t){this.type=e,this.value=t}static define(){return new hN}}class hN{of(e){return new vi(this,e)}}class fN{constructor(e){this.map=e}of(e){return new Ne(this,e)}}class Ne{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 Ne(this.type,t)}is(e){return this.type==e}static define(e={}){return new fN(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let r=[];for(let i of e){let s=i.map(t);s&&r.push(s)}return r}}Ne.reconfigure=Ne.define();Ne.appendConfig=Ne.define();class At{constructor(e,t,r,i,s,l){this.startState=e,this.changes=t,this.selection=r,this.effects=i,this.annotations=s,this.scrollIntoView=l,this._doc=null,this._state=null,r&&e2(r,t.newLength),s.some(o=>o.type==At.time)||(this.annotations=s.concat(At.time.of(Date.now())))}static create(e,t,r,i,s,l){return new At(e,t,r,i,s,l)}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(At.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}At.time=vi.define();At.userEvent=vi.define();At.addToHistory=vi.define();At.remote=vi.define();function dN(n,e){let t=[];for(let r=0,i=0;;){let s,l;if(r<n.length&&(i==e.length||e[i]>=n[r]))s=n[r++],l=n[r++];else if(i<e.length)s=e[i++],l=e[i++];else return t;!t.length||t[t.length-1]<s?t.push(s,l):t[t.length-1]<l&&(t[t.length-1]=l)}}function a2(n,e,t){var r;let i,s,l;return t?(i=e.changes,s=Lt.empty(e.changes.length),l=n.changes.compose(e.changes)):(i=e.changes.map(n.changes),s=n.changes.mapDesc(e.changes,!0),l=n.changes.compose(i)),{changes:l,selection:e.selection?e.selection.map(s):(r=n.selection)===null||r===void 0?void 0:r.map(i),effects:Ne.mapEffects(n.effects,i).concat(Ne.mapEffects(e.effects,s)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function ix(n,e,t){let r=e.selection,i=No(e.annotations);return e.userEvent&&(i=i.concat(At.userEvent.of(e.userEvent))),{changes:e.changes instanceof Lt?e.changes:Lt.of(e.changes||[],t,n.facet(r2)),selection:r&&(r instanceof Y?r:Y.single(r.anchor,r.head)),effects:No(e.effects),annotations:i,scrollIntoView:!!e.scrollIntoView}}function u2(n,e,t){let r=ix(n,e.length?e[0]:{},n.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 l=!!e[s].sequential;r=a2(r,ix(n,e[s],l?r.changes.newLength:n.doc.length),l)}let i=At.create(n,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return mN(t?pN(i):i)}function pN(n){let e=n.startState,t=!0;for(let i of e.facet(i2)){let s=i(n);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:dN(t,s))}if(t!==!0){let i,s;if(t===!1)s=n.changes.invertedDesc,i=Lt.empty(e.doc.length);else{let l=n.changes.filter(t);i=l.changes,s=l.filtered.mapDesc(l.changes).invertedDesc}n=At.create(e,i,n.selection&&n.selection.map(s),Ne.mapEffects(n.effects,s),n.annotations,n.scrollIntoView)}let r=e.facet(s2);for(let i=r.length-1;i>=0;i--){let s=r[i](n);s instanceof At?n=s:Array.isArray(s)&&s.length==1&&s[0]instanceof At?n=s[0]:n=u2(e,No(s),!1)}return n}function mN(n){let e=n.startState,t=e.facet(l2),r=n;for(let i=t.length-1;i>=0;i--){let s=t[i](n);s&&Object.keys(s).length&&(r=a2(r,ix(e,s,n.changes.newLength),!0))}return r==n?n:At.create(e,n.changes,n.selection,r.effects,r.annotations,r.scrollIntoView)}const gN=[];function No(n){return n==null?gN:Array.isArray(n)?n:[n]}var yt=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(yt||(yt={}));const ON=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let sx;try{sx=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function xN(n){if(sx)return sx.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"€"&&(t.toUpperCase()!=t.toLowerCase()||ON.test(t)))return!0}return!1}function yN(n){return e=>{if(!/\S/.test(e))return yt.Space;if(xN(e))return yt.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return yt.Word;return yt.Other}}class Fe{constructor(e,t,r,i,s,l){this.config=e,this.doc=t,this.selection=r,this.values=i,this.status=e.statusTemplate.slice(),this.computeSlot=s,l&&(l._state=this);for(let o=0;o<this.config.dynamicSlots.length;o++)Lu(this,o<<1);this.computeSlot=null}field(e,t=!0){let r=this.config.address[e.id];if(r==null){if(t)throw new RangeError("Field is not present in this state");return}return Lu(this,r),sd(this,r)}update(...e){return u2(this,e,!0)}applyTransaction(e){let t=this.config,{base:r,compartments:i}=t;for(let o of e.effects)o.is(Kd.reconfigure)?(t&&(i=new Map,t.compartments.forEach((u,h)=>i.set(h,u)),t=null),i.set(o.value.compartment,o.value.extension)):o.is(Ne.reconfigure)?(t=null,r=o.value):o.is(Ne.appendConfig)&&(t=null,r=No(r).concat(o.value));let s;t?s=e.startState.values.slice():(t=id.resolve(r,i,this),s=new Fe(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(u,h)=>h.reconfigure(u,this),null).values);let l=e.startState.facet(rx)?e.newSelection:e.newSelection.asSingle();new Fe(t,e.newDoc,l,s,(o,u)=>u.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:Y.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,r=e(t.ranges[0]),i=this.changes(r.changes),s=[r.range],l=No(r.effects);for(let o=1;o<t.ranges.length;o++){let u=e(t.ranges[o]),h=this.changes(u.changes),f=h.map(i);for(let g=0;g<o;g++)s[g]=s[g].map(f);let p=i.mapDesc(h,!0);s.push(u.range.map(p)),i=i.compose(f),l=Ne.mapEffects(l,f).concat(Ne.mapEffects(No(u.effects),p))}return{changes:i,selection:Y.create(s,t.mainIndex),effects:l}}changes(e=[]){return e instanceof Lt?e:Lt.of(e,this.doc.length,this.facet(Fe.lineSeparator))}toText(e){return Ge.of(e.split(this.facet(Fe.lineSeparator)||KO))}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:(Lu(this,t),sd(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let i=e[r];i instanceof an&&this.config.address[i.id]!=null&&(t[r]=i.spec.toJSON(this.field(e[r]),this))}return t}static fromJSON(e,t={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let i=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let l=r[s],o=e[s];i.push(l.init(u=>l.spec.fromJSON(o,u)))}}return Fe.create({doc:e.doc,selection:Y.fromJSON(e.selection),extensions:t.extensions?i.concat([t.extensions]):i})}static create(e={}){let t=id.resolve(e.extensions||[],new Map),r=e.doc instanceof Ge?e.doc:Ge.of((e.doc||"").split(t.staticFacet(Fe.lineSeparator)||KO)),i=e.selection?e.selection instanceof Y?e.selection:Y.single(e.selection.anchor,e.selection.head):Y.single(0);return e2(i,r.length),t.staticFacet(rx)||(i=i.asSingle()),new Fe(t,r,i,t.dynamicSlots.map(()=>null),(s,l)=>l.create(s),null)}get tabSize(){return this.facet(Fe.tabSize)}get lineBreak(){return this.facet(Fe.lineSeparator)||`
71
- `}get readOnly(){return this.facet(o2)}phrase(e,...t){for(let r of this.facet(Fe.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(r,i)=>{if(i=="$")return"$";let s=+(i||1);return!s||s>t.length?r:t[s-1]})),e}languageDataAt(e,t,r=-1){let i=[];for(let s of this.facet(n2))for(let l of s(this,t,r))Object.prototype.hasOwnProperty.call(l,e)&&i.push(l[e]);return i}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return yN(t.length?t[0]:"")}wordAt(e){let{text:t,from:r,length:i}=this.doc.lineAt(e),s=this.charCategorizer(e),l=e-r,o=e-r;for(;l>0;){let u=Ut(t,l,!1);if(s(t.slice(u,l))!=yt.Word)break;l=u}for(;o<i;){let u=Ut(t,o);if(s(t.slice(o,u))!=yt.Word)break;o=u}return l==o?null:Y.range(l+r,o+r)}}Fe.allowMultipleSelections=rx;Fe.tabSize=ge.define({combine:n=>n.length?n[0]:4});Fe.lineSeparator=r2;Fe.readOnly=o2;Fe.phrases=ge.define({compare(n,e){let t=Object.keys(n),r=Object.keys(e);return t.length==r.length&&t.every(i=>n[i]==e[i])}});Fe.languageData=n2;Fe.changeFilter=i2;Fe.transactionFilter=s2;Fe.transactionExtender=l2;Kd.reconfigure=Ne.define();function bi(n,e,t={}){let r={};for(let i of n)for(let s of Object.keys(i)){let l=i[s],o=r[s];if(o===void 0)r[s]=l;else if(!(o===l||l===void 0))if(Object.hasOwnProperty.call(t,s))r[s]=t[s](o,l);else throw new Error("Config merge conflict for field "+s)}for(let i in e)r[i]===void 0&&(r[i]=e[i]);return r}class Xs{eq(e){return this==e}range(e,t=e){return lx.create(e,t,this)}}Xs.prototype.startSide=Xs.prototype.endSide=0;Xs.prototype.point=!1;Xs.prototype.mapMode=sn.TrackDel;function My(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}let lx=class c2{constructor(e,t,r){this.from=e,this.to=t,this.value=r}static create(e,t,r){return new c2(e,t,r)}};function ox(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class Ay{constructor(e,t,r,i){this.from=e,this.to=t,this.value=r,this.maxPoint=i}get length(){return this.to[this.to.length-1]}findIndex(e,t,r,i=0){let s=r?this.to:this.from;for(let l=i,o=s.length;;){if(l==o)return l;let u=l+o>>1,h=s[u]-e||(r?this.value[u].endSide:this.value[u].startSide)-t;if(u==l)return h>=0?l:o;h>=0?o=u:l=u+1}}between(e,t,r,i){for(let s=this.findIndex(t,-1e9,!0),l=this.findIndex(r,1e9,!1,s);s<l;s++)if(i(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t){let r=[],i=[],s=[],l=-1,o=-1;for(let u=0;u<this.value.length;u++){let h=this.value[u],f=this.from[u]+e,p=this.to[u]+e,g,x;if(f==p){let k=t.mapPos(f,h.startSide,h.mapMode);if(k==null||(g=x=k,h.startSide!=h.endSide&&(x=t.mapPos(f,h.endSide),x<g)))continue}else if(g=t.mapPos(f,h.startSide),x=t.mapPos(p,h.endSide),g>x||g==x&&h.startSide>0&&h.endSide<=0)continue;(x-g||h.endSide-h.startSide)<0||(l<0&&(l=g),h.point&&(o=Math.max(o,x-g)),r.push(h),i.push(g-l),s.push(x-l))}return{mapped:r.length?new Ay(i,s,r,o):null,pos:l}}}class We{constructor(e,t,r,i){this.chunkPos=e,this.chunk=t,this.nextLayer=r,this.maxPoint=i}static create(e,t,r,i){return new We(e,t,r,i)}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:r=!1,filterFrom:i=0,filterTo:s=this.length}=e,l=e.filter;if(t.length==0&&!l)return this;if(r&&(t=t.slice().sort(ox)),this.isEmpty)return t.length?We.of(t):this;let o=new h2(this,null,-1).goto(0),u=0,h=[],f=new qi;for(;o.value||u<t.length;)if(u<t.length&&(o.from-t[u].from||o.startSide-t[u].value.startSide)>=0){let p=t[u++];f.addInner(p.from,p.to,p.value)||h.push(p)}else o.rangeIndex==1&&o.chunkIndex<this.chunk.length&&(u==t.length||this.chunkEnd(o.chunkIndex)<t[u].from)&&(!l||i>this.chunkEnd(o.chunkIndex)||s<this.chunkPos[o.chunkIndex])&&f.addChunk(this.chunkPos[o.chunkIndex],this.chunk[o.chunkIndex])?o.nextChunk():((!l||i>o.to||s<o.from||l(o.from,o.to,o.value))&&(f.addInner(o.from,o.to,o.value)||h.push(lx.create(o.from,o.to,o.value))),o.next());return f.finishInner(this.nextLayer.isEmpty&&!h.length?We.empty:this.nextLayer.update({add:h,filter:l,filterFrom:i,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],r=[],i=-1;for(let l=0;l<this.chunk.length;l++){let o=this.chunkPos[l],u=this.chunk[l],h=e.touchesRange(o,o+u.length);if(h===!1)i=Math.max(i,u.maxPoint),t.push(u),r.push(e.mapPos(o));else if(h===!0){let{mapped:f,pos:p}=u.map(o,e);f&&(i=Math.max(i,f.maxPoint),t.push(f),r.push(p))}}let s=this.nextLayer.map(e);return t.length==0?s:new We(r,t,s||We.empty,i)}between(e,t,r){if(!this.isEmpty){for(let i=0;i<this.chunk.length;i++){let s=this.chunkPos[i],l=this.chunk[i];if(t>=s&&e<=s+l.length&&l.between(s,e-s,t-s,r)===!1)return}this.nextLayer.between(e,t,r)}}iter(e=0){return Ku.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ku.from(e).goto(t)}static compare(e,t,r,i,s=-1){let l=e.filter(p=>p.maxPoint>0||!p.isEmpty&&p.maxPoint>=s),o=t.filter(p=>p.maxPoint>0||!p.isEmpty&&p.maxPoint>=s),u=yb(l,o,r),h=new Ou(l,u,s),f=new Ou(o,u,s);r.iterGaps((p,g,x)=>kb(h,p,f,g,x,i)),r.empty&&r.length==0&&kb(h,0,f,0,0,i)}static eq(e,t,r=0,i){i==null&&(i=999999999);let s=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0),l=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0);if(s.length!=l.length)return!1;if(!s.length)return!0;let o=yb(s,l),u=new Ou(s,o,0).goto(r),h=new Ou(l,o,0).goto(r);for(;;){if(u.to!=h.to||!ax(u.active,h.active)||u.point&&(!h.point||!My(u.point,h.point)))return!1;if(u.to>i)return!0;u.next(),h.next()}}static spans(e,t,r,i,s=-1){let l=new Ou(e,null,s).goto(t),o=t,u=l.openStart;for(;;){let h=Math.min(l.to,r);if(l.point){let f=l.activeForPoint(l.to),p=l.pointFrom<t?f.length+1:l.point.startSide<0?f.length:Math.min(f.length,u);i.point(o,h,l.point,f,p,l.pointRank),u=Math.min(l.openEnd(h),f.length)}else h>o&&(i.span(o,h,l.active,u),u=l.openEnd(h));if(l.to>r)return u+(l.point&&l.to>r?1:0);o=l.to,l.next()}}static of(e,t=!1){let r=new qi;for(let i of e instanceof lx?[e]:t?kN(e):e)r.add(i.from,i.to,i.value);return r.finish()}static join(e){if(!e.length)return We.empty;let t=e[e.length-1];for(let r=e.length-2;r>=0;r--)for(let i=e[r];i!=We.empty;i=i.nextLayer)t=new We(i.chunkPos,i.chunk,t,Math.max(i.maxPoint,t.maxPoint));return t}}We.empty=new We([],[],null,-1);function kN(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let r=n[t];if(ox(e,r)>0)return n.slice().sort(ox);e=r}return n}We.empty.nextLayer=We.empty;class qi{finishChunk(e){this.chunks.push(new Ay(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=[])}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}add(e,t,r){this.addInner(e,t,r)||(this.nextLayer||(this.nextLayer=new qi)).add(e,t,r)}addInner(e,t,r){let i=e-this.lastTo||r.startSide-this.last.endSide;if(i<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return i<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=r,this.lastFrom=e,this.lastTo=t,this.value.push(r),r.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 r=t.value.length-1;return this.last=t.value[r],this.lastFrom=t.from[r]+e,this.lastTo=t.to[r]+e,!0}finish(){return this.finishInner(We.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=We.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function yb(n,e,t){let r=new Map;for(let s of n)for(let l=0;l<s.chunk.length;l++)s.chunk[l].maxPoint<=0&&r.set(s.chunk[l],s.chunkPos[l]);let i=new Set;for(let s of e)for(let l=0;l<s.chunk.length;l++){let o=r.get(s.chunk[l]);o!=null&&(t?t.mapPos(o):o)==s.chunkPos[l]&&!(t!=null&&t.touchesRange(o,o+s.chunk[l].length))&&i.add(s.chunk[l])}return i}class h2{constructor(e,t,r,i=0){this.layer=e,this.skip=t,this.minPoint=r,this.rank=i}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,r){for(;this.chunkIndex<this.layer.chunk.length;){let i=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(i)||this.layer.chunkEnd(this.chunkIndex)<e||i.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let i=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!r||this.rangeIndex<i)&&this.setRangeIndex(i)}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],r=e+t.from[this.rangeIndex];if(this.from=r,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}}class Ku{constructor(e){this.heap=e}static from(e,t=null,r=-1){let i=[];for(let s=0;s<e.length;s++)for(let l=e[s];!l.isEmpty;l=l.nextLayer)l.maxPoint>=r&&i.push(new h2(l,t,r,s));return i.length==1?i[0]:new Ku(i)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let r of this.heap)r.goto(e,t);for(let r=this.heap.length>>1;r>=0;r--)Og(this.heap,r);return this.next(),this}forward(e,t){for(let r of this.heap)r.forward(e,t);for(let r=this.heap.length>>1;r>=0;r--)Og(this.heap,r);(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(),Og(this.heap,0)}}}function Og(n,e){for(let t=n[e];;){let r=(e<<1)+1;if(r>=n.length)break;let i=n[r];if(r+1<n.length&&i.compare(n[r+1])>=0&&(i=n[r+1],r++),t.compare(i)<0)break;n[r]=t,n[e]=i,e=r}}class Ou{constructor(e,t,r){this.minPoint=r,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=Ku.from(e,t,r)}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){af(this.active,e),af(this.activeTo,e),af(this.activeRank,e),this.minActive=vb(this.active,this.activeTo)}addActive(e){let t=0,{value:r,to:i,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||i-this.activeTo[t])>0;)t++;uf(this.active,t,r),uf(this.activeTo,t,i),uf(this.activeRank,t,s),e&&uf(e,t,this.cursor.from),this.minActive=vb(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let i=this.minActive;if(i>-1&&(this.activeTo[i]-this.cursor.from||this.active[i].endSide-this.cursor.startSide)<0){if(this.activeTo[i]>e){this.to=this.activeTo[i],this.endSide=this.active[i].endSide;break}this.removeActive(i),r&&af(r,i)}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(r),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(r){this.openStart=0;for(let i=r.length-1;i>=0&&r[i]<e;i--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&t.push(this.active[r]);return t.reverse()}openEnd(e){let t=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)t++;return t}}function kb(n,e,t,r,i,s){n.goto(e),t.goto(r);let l=r+i,o=r,u=r-e,h=!!s.boundChange;for(let f=!1;;){let p=n.to+u-t.to,g=p||n.endSide-t.endSide,x=g<0?n.to+u:t.to,k=Math.min(x,l);if(n.point||t.point?(n.point&&t.point&&My(n.point,t.point)&&ax(n.activeForPoint(n.to),t.activeForPoint(t.to))||s.comparePoint(o,k,n.point,t.point),f=!1):(f&&s.boundChange(o),k>o&&!ax(n.active,t.active)&&s.compareRange(o,k,n.active,t.active),h&&k<l&&(p||n.openEnd(x)!=t.openEnd(x))&&(f=!0)),x>l)break;o=x,g<=0&&n.next(),g>=0&&t.next()}}function ax(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!My(n[t],e[t]))return!1;return!0}function af(n,e){for(let t=e,r=n.length-1;t<r;t++)n[t]=n[t+1];n.pop()}function uf(n,e,t){for(let r=n.length-1;r>=e;r--)n[r+1]=n[r];n[e]=t}function vb(n,e){let t=-1,r=1e9;for(let i=0;i<e.length;i++)(e[i]-r||n[i].endSide-n[t].endSide)<0&&(t=i,r=e[i]);return t}function Wr(n,e,t=n.length){let r=0;for(let i=0;i<t&&i<n.length;)n.charCodeAt(i)==9?(r+=e-r%e,i++):(r++,i=Ut(n,i));return r}function ux(n,e,t,r){for(let i=0,s=0;;){if(s>=e)return i;if(i==n.length)break;s+=n.charCodeAt(i)==9?t-s%t:1,i=Ut(n,i)}return r===!0?-1:n.length}const cx="ͼ",bb=typeof Symbol>"u"?"__"+cx:Symbol.for(cx),hx=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),wb=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Bs{constructor(e,t){this.rules=[];let{finish:r}=t||{};function i(l){return/^@/.test(l)?[l]:l.split(/,\s*/)}function s(l,o,u,h){let f=[],p=/^@(\w+)\b/.exec(l[0]),g=p&&p[1]=="keyframes";if(p&&o==null)return u.push(l[0]+";");for(let x in o){let k=o[x];if(/&/.test(x))s(x.split(/,\s*/).map(b=>l.map(w=>b.replace(/&/,w))).reduce((b,w)=>b.concat(w)),k,u);else if(k&&typeof k=="object"){if(!p)throw new RangeError("The value of a property ("+x+") should be a primitive value.");s(i(x),k,f,g)}else k!=null&&f.push(x.replace(/_.*/,"").replace(/[A-Z]/g,b=>"-"+b.toLowerCase())+": "+k+";")}(f.length||g)&&u.push((r&&!p&&!h?l.map(r):l).join(", ")+" {"+f.join(" ")+"}")}for(let l in e)s(i(l),e[l],this.rules)}getRules(){return this.rules.join(`
72
- `)}static newName(){let e=wb[bb]||1;return wb[bb]=e+1,cx+e.toString(36)}static mount(e,t,r){let i=e[hx],s=r&&r.nonce;i?s&&i.setNonce(s):i=new vN(e,s),i.mount(Array.isArray(t)?t:[t],e)}}let Sb=new Map;class vN{constructor(e,t){let r=e.ownerDocument||e,i=r.defaultView;if(!e.head&&e.adoptedStyleSheets&&i.CSSStyleSheet){let s=Sb.get(r);if(s)return e[hx]=s;this.sheet=new i.CSSStyleSheet,Sb.set(r,this)}else this.styleTag=r.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[hx]=this}mount(e,t){let r=this.sheet,i=0,s=0;for(let l=0;l<e.length;l++){let o=e[l],u=this.modules.indexOf(o);if(u<s&&u>-1&&(this.modules.splice(u,1),s--,u=-1),u==-1){if(this.modules.splice(s++,0,o),r)for(let h=0;h<o.rules.length;h++)r.insertRule(o.rules[h],i++)}else{for(;s<u;)i+=this.modules[s++].rules.length;i+=o.rules.length,s++}}if(r)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let l="";for(let u=0;u<this.modules.length;u++)l+=this.modules[u].getRules()+`
73
- `;this.styleTag.textContent=l;let o=t.head||t;this.styleTag.parentNode!=o&&o.insertBefore(this.styleTag,o.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var Ws={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:"'"},Ju={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},bN=typeof navigator<"u"&&/Mac/.test(navigator.platform),wN=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var rn=0;rn<10;rn++)Ws[48+rn]=Ws[96+rn]=String(rn);for(var rn=1;rn<=24;rn++)Ws[rn+111]="F"+rn;for(var rn=65;rn<=90;rn++)Ws[rn]=String.fromCharCode(rn+32),Ju[rn]=String.fromCharCode(rn);for(var xg in Ws)Ju.hasOwnProperty(xg)||(Ju[xg]=Ws[xg]);function SN(n){var e=bN&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||wN&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Ju:Ws)[n.keyCode]||n.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 lt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e<arguments.length;e++)f2(n,arguments[e]);return n}function f2(n,e){if(typeof e=="string")n.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)n.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)f2(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}let Cn=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},fx=typeof document<"u"?document:{documentElement:{style:{}}};const dx=/Edge\/(\d+)/.exec(Cn.userAgent),d2=/MSIE \d/.test(Cn.userAgent),px=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Cn.userAgent),Jd=!!(d2||px||dx),Pb=!Jd&&/gecko\/(\d+)/i.test(Cn.userAgent),yg=!Jd&&/Chrome\/(\d+)/.exec(Cn.userAgent),Cb="webkitFontSmoothing"in fx.documentElement.style,mx=!Jd&&/Apple Computer/.test(Cn.vendor),Qb=mx&&(/Mobile\/\w+/.test(Cn.userAgent)||Cn.maxTouchPoints>2);var xe={mac:Qb||/Mac/.test(Cn.platform),windows:/Win/.test(Cn.platform),linux:/Linux|X11/.test(Cn.platform),ie:Jd,ie_version:d2?fx.documentMode||6:px?+px[1]:dx?+dx[1]:0,gecko:Pb,gecko_version:Pb?+(/Firefox\/(\d+)/.exec(Cn.userAgent)||[0,0])[1]:0,chrome:!!yg,chrome_version:yg?+yg[1]:0,ios:Qb,android:/Android\b/.test(Cn.userAgent),webkit:Cb,webkit_version:Cb?+(/\bAppleWebKit\/(\d+)/.exec(Cn.userAgent)||[0,0])[1]:0,safari:mx,safari_version:mx?+(/\bVersion\/(\d+(\.\d+)?)/.exec(Cn.userAgent)||[0,0])[1]:0,tabSize:fx.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Ry(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const ld=Object.create(null);function Ny(n,e,t){if(n==e)return!0;n||(n=ld),e||(e=ld);let r=Object.keys(n),i=Object.keys(e);if(r.length-0!=i.length-0)return!1;for(let s of r)if(s!=t&&(i.indexOf(s)==-1||n[s]!==e[s]))return!1;return!0}function PN(n,e){for(let t=n.attributes.length-1;t>=0;t--){let r=n.attributes[t].name;e[r]==null&&n.removeAttribute(r)}for(let t in e){let r=e[t];t=="style"?n.style.cssText=r:n.getAttribute(t)!=r&&n.setAttribute(t,r)}}function $b(n,e,t){let r=!1;if(e)for(let i in e)t&&i in t||(r=!0,i=="style"?n.style.cssText="":n.removeAttribute(i));if(t)for(let i in t)e&&e[i]==t[i]||(r=!0,i=="style"?n.style.cssText=t[i]:n.setAttribute(i,t[i]));return r}function CN(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let r=n.attributes[t];e[r.name]=r.value}return e}class Vr{eq(e){return!1}updateDOM(e,t,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var ln=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(ln||(ln={}));class $e extends Xs{constructor(e,t,r,i){super(),this.startSide=e,this.endSide=t,this.widget=r,this.spec=i}get heightRelevant(){return!1}static mark(e){return new Ac(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return t+=r&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new zl(e,t,t,r,e.widget||null,!1)}static replace(e){let t=!!e.block,r,i;if(e.isBlockGap)r=-5e8,i=4e8;else{let{start:s,end:l}=p2(e,t);r=(s?t?-3e8:-1:5e8)-1,i=(l?t?2e8:1:-6e8)+1}return new zl(e,r,i,t,e.widget||null,!0)}static line(e){return new Rc(e)}static set(e,t=!1){return We.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}$e.none=We.empty;class Ac extends $e{constructor(e){let{start:t,end:r}=p2(e);super(t?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Ry(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||ld}eq(e){return this==e||e instanceof Ac&&this.tagName==e.tagName&&Ny(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)}}Ac.prototype.point=!1;class Rc extends $e{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Rc&&this.spec.class==e.spec.class&&Ny(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)}}Rc.prototype.mapMode=sn.TrackBefore;Rc.prototype.point=!0;class zl extends $e{constructor(e,t,r,i,s,l){super(t,r,s,e),this.block=i,this.isReplace=l,this.mapMode=i?t<=0?sn.TrackBefore:sn.TrackAfter:sn.TrackDel}get type(){return this.startSide!=this.endSide?ln.WidgetRange:this.startSide<=0?ln.WidgetBefore:ln.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof zl&&QN(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)}}zl.prototype.point=!0;function p2(n,e=!1){let{inclusiveStart:t,inclusiveEnd:r}=n;return t==null&&(t=n.inclusive),r==null&&(r=n.inclusive),{start:t??e,end:r??e}}function QN(n,e){return n==e||!!(n&&e&&n.compare(e))}function Lo(n,e,t,r=0){let i=t.length-1;i>=0&&t[i]+r>=n?t[i]=Math.max(t[i],e):t.push(n,e)}class ec extends Xs{constructor(e,t,r){super(),this.tagName=e,this.attributes=t,this.rank=r}eq(e){return e==this||e instanceof ec&&this.tagName==e.tagName&&Ny(this.attributes,e.attributes)}static create(e){return new ec(e.tagName,e.attributes||ld,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return We.of(e,t)}}ec.prototype.startSide=ec.prototype.endSide=-1;function tc(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function gx(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function _u(n,e){if(!e.anchorNode)return!1;try{return gx(n,e.anchorNode)}catch{return!1}}function Du(n){return n.nodeType==3?rc(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Iu(n,e,t,r){return t?Tb(n,e,t,r,-1)||Tb(n,e,t,r,1):!1}function qs(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function od(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Tb(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Vi(n))){if(n.nodeName=="DIV")return!1;let s=n.parentNode;if(!s||s.nodeType!=1)return!1;e=qs(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=i<0?Vi(n):0}else return!1}}function Vi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function nc(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function $N(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function m2(n,e){let t=e.width/n.offsetWidth,r=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-n.offsetHeight)<1)&&(r=1),{scaleX:t,scaleY:r}}function TN(n,e,t,r,i,s,l,o){let u=n.ownerDocument,h=u.defaultView||window;for(let f=n,p=!1;f&&!p;)if(f.nodeType==1){let g,x=f==u.body,k=1,b=1;if(x)g=$N(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(p=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let Q=f.getBoundingClientRect();({scaleX:k,scaleY:b}=m2(f,Q)),g={left:Q.left,right:Q.left+f.clientWidth*k,top:Q.top,bottom:Q.top+f.clientHeight*b}}let w=0,S=0;if(i=="nearest")e.top<g.top+l?(S=e.top-(g.top+l),t>0&&e.bottom>g.bottom+S&&(S=e.bottom-g.bottom+l)):e.bottom>g.bottom-l&&(S=e.bottom-g.bottom+l,t<0&&e.top-S<g.top&&(S=e.top-(g.top+l)));else{let Q=e.bottom-e.top,$=g.bottom-g.top;S=(i=="center"&&Q<=$?e.top+Q/2-$/2:i=="start"||i=="center"&&t<0?e.top-l:e.bottom-$+l)-g.top}if(r=="nearest"?e.left<g.left+s?(w=e.left-(g.left+s),t>0&&e.right>g.right+w&&(w=e.right-g.right+s)):e.right>g.right-s&&(w=e.right-g.right+s,t<0&&e.left<g.left+w&&(w=e.left-(g.left+s))):w=(r=="center"?e.left+(e.right-e.left)/2-(g.right-g.left)/2:r=="start"==o?e.left-s:e.right-(g.right-g.left)+s)-g.left,w||S)if(x)h.scrollBy(w,S);else{let Q=0,$=0;if(S){let R=f.scrollTop;f.scrollTop+=S/b,$=(f.scrollTop-R)*b}if(w){let R=f.scrollLeft;f.scrollLeft+=w/k,Q=(f.scrollLeft-R)*k}e={left:e.left-Q,top:e.top-$,right:e.right-Q,bottom:e.bottom-$},Q&&Math.abs(Q-w)<1&&(r="nearest"),$&&Math.abs($-S)<1&&(i="nearest")}if(x)break;(e.top<g.top||e.bottom>g.bottom||e.left<g.left||e.right>g.right)&&(e={left:Math.max(e.left,g.left),right:Math.min(e.right,g.right),top:Math.max(e.top,g.top),bottom:Math.min(e.bottom,g.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function g2(n,e=!0){let t=n.ownerDocument,r=null,i=null;for(let s=n.parentNode;s&&!(s==t.body||(!e||r)&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:i}}class jN{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){let{anchorNode:t,focusNode:r}=e;this.set(t,Math.min(e.anchorOffset,t?Vi(t):0),r,Math.min(e.focusOffset,r?Vi(r):0))}set(e,t,r,i){this.anchorNode=e,this.anchorOffset=t,this.focusNode=r,this.focusOffset=i}}let Ol=null;xe.safari&&xe.safari_version>=26&&(Ol=!1);function O2(n){if(n.setActive)return n.setActive();if(Ol)return n.focus(Ol);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(Ol==null?{get preventScroll(){return Ol={preventScroll:!0},!0}}:void 0),!Ol){Ol=!1;for(let t=0;t<e.length;){let r=e[t++],i=e[t++],s=e[t++];r.scrollTop!=i&&(r.scrollTop=i),r.scrollLeft!=s&&(r.scrollLeft=s)}}}let jb;function rc(n,e,t=e){let r=jb||(jb=document.createRange());return r.setEnd(n,t),r.setStart(n,e),r}function _o(n,e,t,r){let i={key:e,code:e,keyCode:t,which:t,cancelable:!0};r&&({altKey:i.altKey,ctrlKey:i.ctrlKey,shiftKey:i.shiftKey,metaKey:i.metaKey}=r);let s=new KeyboardEvent("keydown",i);s.synthetic=!0,n.dispatchEvent(s);let l=new KeyboardEvent("keyup",i);return l.synthetic=!0,n.dispatchEvent(l),s.defaultPrevented||l.defaultPrevented}function EN(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function MN(n,e){let t=e.focusNode,r=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=r)return!1;for(r=Math.min(r,Vi(t));;)if(r){if(t.nodeType!=1)return!1;let i=t.childNodes[r-1];i.contentEditable=="false"?r--:(t=i,r=Vi(t))}else{if(t==n)return!0;r=qs(t),t=t.parentNode}}function x2(n){return n instanceof Window?n.pageYOffset>Math.max(0,n.document.documentElement.scrollHeight-n.innerHeight-4):n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function y2(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r>0)return{node:t,offset:r};if(t.nodeType==1&&r>0){if(t.contentEditable=="false")return null;t=t.childNodes[r-1],r=Vi(t)}else if(t.parentNode&&!od(t))r=qs(t),t=t.parentNode;else return null}}function k2(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r<t.nodeValue.length)return{node:t,offset:r};if(t.nodeType==1&&r<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[r],r=0}else if(t.parentNode&&!od(t))r=qs(t)+1,t=t.parentNode;else return null}}class Xr{constructor(e,t,r=!0){this.node=e,this.offset=t,this.precise=r}static before(e,t){return new Xr(e.parentNode,qs(e),t)}static after(e,t){return new Xr(e.parentNode,qs(e)+1,t)}}var ht=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(ht||(ht={}));const Zl=ht.LTR,Ly=ht.RTL;function v2(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const AN=v2("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),RN=v2("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ox=Object.create(null),ni=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);Ox[e]=t,Ox[t]=-e}function b2(n){return n<=247?AN[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?RN[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const NN=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class di{get dir(){return this.level%2?Ly:Zl}constructor(e,t,r){this.from=e,this.to=t,this.level=r}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,r,i){let s=-1;for(let l=0;l<e.length;l++){let o=e[l];if(o.from<=t&&o.to>=t){if(o.level==r)return l;(s<0||(i!=0?i<0?o.from<t:o.to>t:e[s].level>o.level))&&(s=l)}}if(s<0)throw new RangeError("Index out of range");return s}}function w2(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],i=e[t];if(r.from!=i.from||r.to!=i.to||r.direction!=i.direction||!w2(r.inner,i.inner))return!1}return!0}const ct=[];function LN(n,e,t,r,i){for(let s=0;s<=r.length;s++){let l=s?r[s-1].to:e,o=s<r.length?r[s].from:t,u=s?256:i;for(let h=l,f=u,p=u;h<o;h++){let g=b2(n.charCodeAt(h));g==512?g=f:g==8&&p==4&&(g=16),ct[h]=g==4?2:g,g&7&&(p=g),f=g}for(let h=l,f=u,p=u;h<o;h++){let g=ct[h];if(g==128)h<o-1&&f==ct[h+1]&&f&24?g=ct[h]=f:ct[h]=256;else if(g==64){let x=h+1;for(;x<o&&ct[x]==64;)x++;let k=h&&f==8||x<t&&ct[x]==8?p==1?1:8:256;for(let b=h;b<x;b++)ct[b]=k;h=x-1}else g==8&&p==1&&(ct[h]=1);f=g,g&7&&(p=g)}}}function _N(n,e,t,r,i){let s=i==1?2:1;for(let l=0,o=0,u=0;l<=r.length;l++){let h=l?r[l-1].to:e,f=l<r.length?r[l].from:t;for(let p=h,g,x,k;p<f;p++)if(x=Ox[g=n.charCodeAt(p)])if(x<0){for(let b=o-3;b>=0;b-=3)if(ni[b+1]==-x){let w=ni[b+2],S=w&2?i:w&4?w&1?s:i:0;S&&(ct[p]=ct[ni[b]]=S),o=b;break}}else{if(ni.length==189)break;ni[o++]=p,ni[o++]=g,ni[o++]=u}else if((k=ct[p])==2||k==1){let b=k==i;u=b?0:1;for(let w=o-3;w>=0;w-=3){let S=ni[w+2];if(S&2)break;if(b)ni[w+2]|=2;else{if(S&4)break;ni[w+2]|=4}}}}}function DN(n,e,t,r){for(let i=0,s=r;i<=t.length;i++){let l=i?t[i-1].to:n,o=i<t.length?t[i].from:e;for(let u=l;u<o;){let h=ct[u];if(h==256){let f=u+1;for(;;)if(f==o){if(i==t.length)break;f=t[i++].to,o=i<t.length?t[i].from:e}else if(ct[f]==256)f++;else break;let p=s==1,g=(f<e?ct[f]:r)==1,x=p==g?p?1:2:r;for(let k=f,b=i,w=b?t[b-1].to:n;k>u;)k==w&&(k=t[--b].from,w=b?t[b-1].to:n),ct[--k]=x;u=f}else s=h,u++}}}function xx(n,e,t,r,i,s,l){let o=r%2?2:1;if(r%2==i%2)for(let u=e,h=0;u<t;){let f=!0,p=!1;if(h==s.length||u<s[h].from){let b=ct[u];b!=o&&(f=!1,p=b==16)}let g=!f&&o==1?[]:null,x=f?r:r+1,k=u;e:for(;;)if(h<s.length&&k==s[h].from){if(p)break e;let b=s[h];if(!f)for(let w=b.to,S=h+1;;){if(w==t)break e;if(S<s.length&&s[S].from==w)w=s[S++].to;else{if(ct[w]==o)break e;break}}if(h++,g)g.push(b);else{b.from>u&&l.push(new di(u,b.from,x));let w=b.direction==Zl!=!(x%2);yx(n,w?r+1:r,i,b.inner,b.from,b.to,l),u=b.to}k=b.to}else{if(k==t||(f?ct[k]!=o:ct[k]==o))break;k++}g?xx(n,u,k,r+1,i,g,l):u<k&&l.push(new di(u,k,x)),u=k}else for(let u=t,h=s.length;u>e;){let f=!0,p=!1;if(!h||u>s[h-1].to){let b=ct[u-1];b!=o&&(f=!1,p=b==16)}let g=!f&&o==1?[]:null,x=f?r:r+1,k=u;e:for(;;)if(h&&k==s[h-1].to){if(p)break e;let b=s[--h];if(!f)for(let w=b.from,S=h;;){if(w==e)break e;if(S&&s[S-1].to==w)w=s[--S].from;else{if(ct[w-1]==o)break e;break}}if(g)g.push(b);else{b.to<u&&l.push(new di(b.to,u,x));let w=b.direction==Zl!=!(x%2);yx(n,w?r+1:r,i,b.inner,b.from,b.to,l),u=b.from}k=b.from}else{if(k==e||(f?ct[k-1]!=o:ct[k-1]==o))break;k--}g?xx(n,k,u,r+1,i,g,l):k<u&&l.push(new di(k,u,x)),u=k}}function yx(n,e,t,r,i,s,l){let o=e%2?2:1;LN(n,i,s,r,o),_N(n,i,s,r,o),DN(i,s,r,o),xx(n,i,s,e,t,r,l)}function IN(n,e,t){if(!n)return[new di(0,0,e==Ly?1:0)];if(e==Zl&&!t.length&&!NN.test(n))return S2(n.length);if(t.length)for(;n.length>ct.length;)ct[ct.length]=256;let r=[],i=e==Zl?0:1;return yx(n,i,i,t,0,n.length,r),r}function S2(n){return[new di(0,n,0)]}let P2="";function zN(n,e,t,r,i){var s;let l=r.head-n.from,o=di.find(e,l,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc),u=e[o],h=u.side(i,t);if(l==h){let g=o+=i?1:-1;if(g<0||g>=e.length)return null;u=e[o=g],l=u.side(!i,t),h=u.side(i,t)}let f=Ut(n.text,l,u.forward(i,t));(f<u.from||f>u.to)&&(f=h),P2=n.text.slice(Math.min(l,f),Math.max(l,f));let p=o==(i?e.length-1:0)?null:e[o+(i?1:-1)];return p&&f==h&&p.level+(i?0:1)<u.level?Y.cursor(p.side(!i,t)+n.from,p.forward(i,t)?1:-1,p.level):Y.cursor(f+n.from,u.forward(i,t)?-1:1,u.level)}function ZN(n,e,t){for(let r=e;r<t;r++){let i=b2(n.charCodeAt(r));if(i==1)return Zl;if(i==2||i==4)return Ly}return Zl}const C2=ge.define(),Q2=ge.define(),$2=ge.define(),T2=ge.define(),kx=ge.define(),j2=ge.define(),E2=ge.define(),_y=ge.define(),Dy=ge.define(),M2=ge.define({combine:n=>n.some(e=>e)}),A2=ge.define({combine:n=>n.some(e=>e)}),R2=ge.define();class Do{constructor(e,t,r,i,s,l=!1){this.range=e,this.y=t,this.x=r,this.yMargin=i,this.xMargin=s,this.isSnapshot=l}map(e){return e.empty?this:new Do(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Do(Y.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const cf=Ne.define({map:(n,e)=>n.map(e)}),N2=Ne.define();function Xn(n,e,t){let r=n.facet(T2);r.length?r[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const Zi=ge.define({combine:n=>n.length?n[0]:!0});let XN=0;const Mo=ge.define({combine(n){return n.filter((e,t)=>{for(let r=0;r<t;r++)if(n[r].plugin==e.plugin)return!1;return!0})}});class Ct{constructor(e,t,r,i,s){this.id=e,this.create=t,this.domEventHandlers=r,this.domEventObservers=i,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(Mo.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Mo.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:r,eventObservers:i,provide:s,decorations:l}=t||{};return new Ct(XN++,e,r,i,o=>{let u=[];return l&&u.push(ep.of(h=>{let f=h.plugin(o);return f?l(f):$e.none})),s&&u.push(s(o)),u})}static fromClass(e,t){return Ct.define((r,i)=>new e(r,i),t)}}class kg{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}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(r){if(Xn(t.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Xn(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(r){Xn(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const L2=ge.define(),Iy=ge.define(),ep=ge.define(),_2=ge.define(),zy=ge.define(),Nc=ge.define(),D2=ge.define();function Eb(n,e){let t=n.state.facet(D2);if(!t.length)return t;let r=t.map(s=>s instanceof Function?s(n):s),i=[];return We.spans(r,e.from,e.to,{point(){},span(s,l,o,u){let h=s-e.from,f=l-e.from,p=i;for(let g=o.length-1;g>=0;g--,u--){let x=o[g].spec.bidiIsolate,k;if(x==null&&(x=ZN(e.text,h,f)),u>0&&p.length&&(k=p[p.length-1]).to==h&&k.direction==x)k.to=f,p=k.inner;else{let b={from:h,to:f,direction:x,inner:[]};p.push(b),p=b.inner}}}}),i}const I2=ge.define();function Zy(n){let e=0,t=0,r=0,i=0;for(let s of n.state.facet(I2)){let l=s(n);l&&(l.left!=null&&(e=Math.max(e,l.left)),l.right!=null&&(t=Math.max(t,l.right)),l.top!=null&&(r=Math.max(r,l.top)),l.bottom!=null&&(i=Math.max(i,l.bottom)))}return{left:e,right:t,top:r,bottom:i}}const Eu=ge.define();class Sr{constructor(e,t,r,i){this.fromA=e,this.toA=t,this.fromB=r,this.toB=i}join(e){return new Sr(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,r=this;for(;t>0;t--){let i=e[t-1];if(!(i.fromA>r.toA)){if(i.toA<r.fromA)break;r=r.join(i),e.splice(t-1,1)}}return e.splice(t,0,r),e}static extendWithRanges(e,t){if(t.length==0)return e;let r=[];for(let i=0,s=0,l=0;;){let o=i<e.length?e[i].fromB:1e9,u=s<t.length?t[s]:1e9,h=Math.min(o,u);if(h==1e9)break;let f=h+l,p=h,g=f;for(;;)if(s<t.length&&t[s]<=p){let x=t[s+1];s+=2,p=Math.max(p,x);for(let k=i;k<e.length&&e[k].fromB<=p;k++)l=e[k].toA-e[k].toB;g=Math.max(g,x+l)}else if(i<e.length&&e[i].fromB<=p){let x=e[i++];p=Math.max(p,x.toB),g=Math.max(g,x.toA),l=x.toA-x.toB}else break;r.push(new Sr(f,g,h,p))}return r}}class ad{constructor(e,t,r){this.view=e,this.state=t,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=Lt.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let i=[];this.changes.iterChangedRanges((s,l,o,u)=>i.push(new Sr(s,l,o,u))),this.changedRanges=i}static create(e,t,r){return new ad(e,t,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>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}}const BN=[];class Pt{constructor(e,t,r=0){this.dom=e,this.length=t,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return BN}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&PN(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let r=t;for(let i of this.children){if(i==e)return r;r+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let r=qs(this.dom),i=this.length?e>0:t>0;return new Xr(this.parent.dom,r+(i?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof np)return e;return null}static get(e){return e.cmTile}}class tp extends Pt{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,r=null,i,s=(e==null?void 0:e.node)==t?e:null,l=0;for(let o of this.children){if(o.sync(e),l+=o.length+o.breakAfter,i=r?r.nextSibling:t.firstChild,s&&i!=o.dom&&(s.written=!0),o.dom.parentNode==t)for(;i&&i!=o.dom;)i=Mb(i);else t.insertBefore(o.dom,i);r=o.dom}for(i=r?r.nextSibling:t.firstChild,s&&i&&(s.written=!0);i;)i=Mb(i);this.length=l}}function Mb(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class np extends tp{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=Pt.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],r=this,i=0,s=0;;)if(i==r.children.length){if(!t.length)return;r=r.parent,r.breakAfter&&s++,i=t.pop()}else{let l=r.children[i++];if(l instanceof Xi)t.push(i),r=l,i=0;else{let o=s+l.length,u=e(l,s);if(u!==void 0)return u;s=o+l.breakAfter}}}resolveBlock(e,t){let r,i=-1,s,l=-1;if(this.blockTiles((o,u)=>{let h=u+o.length;if(e>=u&&e<=h){if(o.isWidget()&&t>=-1&&t<=1){if(o.flags&32)return!0;o.flags&16&&(r=void 0)}(u<e||e==h&&(t<-1?o.length:o.covers(1)))&&(!r||!o.isWidget()&&r.isWidget())&&(r=o,i=e-u),(h>e||e==u&&(t>1?o.length:o.covers(-1)))&&(!s||!o.isWidget()&&s.isWidget())&&(s=o,l=e-u)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&t<0||!s?{tile:r,offset:i}:{tile:s,offset:l}}}class Xi extends tp{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let r=new Xi(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}}class ia extends tp{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,r){let i=new ia(t||document.createElement("div"),e);return(!t||!r)&&(i.flags|=4),i}get domAttrs(){return this.attrs}resolveInline(e,t,r){let i=null,s=-1,l=null,o=-1;function u(f,p){for(let g=0,x=0;g<f.children.length&&x<=p;g++){let k=f.children[g],b=x+k.length;b>=p&&(k.isComposite()?u(k,p-x):(!l||l.isHidden&&(t>0||r&&qN(l,k)))&&(b>p||k.flags&32)?(l=k,o=p-x):(x<p||k.flags&16&&!k.isHidden)&&(i=k,s=p-x)),x=b}}u(this,e);let h=(t<0?i:l)||i||l;return h?{tile:h,offset:h==i?s:o}:null}coordsIn(e,t){let r=this.resolveInline(e,t,!0);return r?r.tile.coordsIn(Math.max(0,r.offset),t):WN(this)}domIn(e,t){let r=this.resolveInline(e,t);if(r){let{tile:i,offset:s}=r;if(this.dom.contains(i.dom))return i.isText()?new Xr(i.dom,Math.min(i.dom.nodeValue.length,s)):i.domPosFor(s,i.flags&16?1:i.flags&32?-1:t);let l=r.tile.parent,o=!1;for(let u of l.children){if(o)return new Xr(u.dom,0);u==r.tile&&(o=!0)}}return new Xr(this.dom,0)}}function WN(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=Du(e);return t[t.length-1]||null}function qN(n,e){let t=n.coordsIn(0,1),r=e.coordsIn(0,1);return t&&r&&r.top<t.bottom}class Zn extends tp{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let r=new Zn(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}}class Sl extends Pt{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let r=this.dom.nodeValue.length;e>r&&(e=r);let i=e,s=e,l=0;e==0&&t<0||e==r&&t>=0?xe.chrome||xe.gecko||(e?(i--,l=1):s<r&&(s++,l=-1)):t<0?i--:s<r&&s++;let o=rc(this.dom,i,s).getClientRects();if(!o.length)return null;let u=o[(l?l<0:t>=0)?0:o.length-1];return xe.safari&&!l&&u.width==0&&(u=Array.prototype.find.call(o,h=>h.width)||u),l?nc(u,l<0):u||null}static of(e,t){let r=new Sl(t||document.createTextNode(e),e);return t||(r.flags|=2),r}}class Xl extends Pt{constructor(e,t,r,i){super(e,t,i),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,r){let i=this.widget.coordsAt(this.dom,e,t);if(i)return i;if(r)return nc(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),l=null;if(!s.length)return null;let o=this.flags&16?!0:this.flags&32?!1:e>0;for(let u=o?s.length-1:0;l=s[u],!(e>0?u==0:u==s.length-1||l.top<l.bottom);u+=o?-1:1);return nc(l,!o)}}get overrideDOMText(){if(!this.length)return Ge.empty;let{root:e}=this;if(!e)return Ge.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,r,i,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new Xl(s,r,e,i)}}class ud extends Pt{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return Ge.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class VN{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,r){let{tile:i,index:s,beforeBreak:l,parents:o}=this;for(;e||t>0;)if(i.isComposite())if(l){if(!e)break;r&&r.break(),e--,l=!1}else if(s==i.children.length){if(!e&&!o.length)break;r&&r.leave(i),l=!!i.breakAfter,{tile:i,index:s}=o.pop(),s++}else{let u=i.children[s],h=u.breakAfter;(t>0?u.length<=e:u.length<e)&&(!r||r.skip(u,0,u.length)!==!1||!u.isComposite)?(l=!!h,s++,e-=u.length):(o.push({tile:i,index:s}),i=u,s=0,r&&u.isComposite()&&r.enter(u))}else if(s==i.length)l=!!i.breakAfter,{tile:i,index:s}=o.pop(),s++;else if(e){let u=Math.min(e,i.length-s);r&&r.skip(i,s,s+u),e-=u,s+=u}else break;return this.tile=i,this.index=s,this.beforeBreak=l,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class FN{constructor(e,t,r,i){this.from=e,this.to=t,this.wrapper=r,this.rank=i}}class YN{constructor(e,t,r){this.cache=e,this.root=t,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,r,i){var s;this.flushBuffer();let l=this.ensureMarks(t,r),o=l.lastChild;if(o&&o.isText()&&!(o.flags&8)&&o.length+e.length<512){this.cache.reused.set(o,2);let u=l.children[l.children.length-1]=new Sl(o.dom,o.text+e);u.parent=l}else l.append(i||Sl.of(e,(s=this.cache.find(Sl))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let r=this.curLine;r.dom!=t.line.dom&&(r.setDOM(this.cache.reused.has(t.line)?vg(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let i=r;for(let o=t.marks.length-1;o>=0;o--){let u=t.marks[o],h=i.lastChild;if(h instanceof Zn&&h.mark.eq(u.mark))h.dom!=u.dom&&h.setDOM(vg(u.dom)),i=h;else{if(this.cache.reused.get(u)){let p=Pt.get(u.dom);p&&p.setDOM(vg(u.dom))}let f=Zn.of(u.mark,u.dom);i.append(f),i=f}this.cache.reused.set(u,2)}let s=Pt.get(e.text);s&&this.cache.reused.set(s,2);let l=new Sl(e.text,e.text.nodeValue);l.flags|=8,this.pos=e.range.toB,i.append(l)}addInlineWidget(e,t,r){let i=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);i||this.flushBuffer();let s=this.ensureMarks(t,r);!i&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,r){this.flushBuffer(),this.ensureMarks(t,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var r;e||(e=z2);let i=ia.start(e,t||((r=this.cache.find(ia))===null||r===void 0?void 0:r.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=i)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var r;let i=this.curLine;for(let s=e.length-1;s>=0;s--){let l=e[s],o;if(t>0&&(o=i.lastChild)&&o instanceof Zn&&o.mark.eq(l))i=o,t--;else{let u=Zn.of(l,(r=this.cache.find(Zn,h=>h.mark.eq(l)))===null||r===void 0?void 0:r.dom);i.append(u),i=u,t=0}}return i}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Ab(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(xe.ios&&Ab(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(bg,0,32)||new Xl(bg.toDOM(),0,bg,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,r=new FN(e.from,e.to,e.value,t),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-r.rank||this.wrappers[i-1].to-r.to)<0;)i--;this.wrappers.splice(i,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let r of this.wrappers){let i=t.lastChild;if(r.from<this.pos&&i instanceof Xi&&i.wrapper.eq(r.wrapper))t=i;else{let s=Xi.of(r.wrapper,(e=this.cache.find(Xi,l=>l.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),r=this.cache.find(ud,void 0,1);return r&&(r.flags=t),r||new ud(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class UN{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:i,lineBreak:s,done:l}=this.cursor.next(this.skipCount);if(this.skipCount=0,l)throw new Error("Ran out of text content when drawing inline views");this.text=i;let o=this.textOff=Math.min(e,i.length);return s?null:i.slice(0,o)}let t=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,t);return this.textOff=t,r}}const cd=[Xl,ia,Sl,Zn,ud,Xi,np];for(let n=0;n<cd.length;n++)cd[n].bucket=n;class GN{constructor(e){this.view=e,this.buckets=cd.map(()=>[]),this.index=cd.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,r=this.buckets[t];r.length<6?r.push(e):r[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,r=2){let i=e.bucket,s=this.buckets[i],l=this.index[i];for(let o=s.length-1;o>=0;o--){let u=(o+l)%s.length,h=s[u];if((!t||t(h))&&!this.reused.has(h))return s.splice(u,1),u<l&&this.index[i]--,this.reused.set(h,r),h}return null}findWidget(e,t,r){let i=this.buckets[0];if(i.length)for(let s=0,l=0;;s++){if(s==i.length){if(l)return null;l=1,s=0}let o=i[s];if(!this.reused.has(o)&&(l==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return i.splice(s,1),s<this.index[0]&&this.index[0]--,o.widget==e&&o.length==t&&(o.flags&497)==r?(this.reused.set(o,1),o):(this.reused.set(o,2),new Xl(o.dom,t,e,o.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class HN{constructor(e,t,r,i,s){this.view=e,this.decorations=i,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new GN(e),this.text=new UN(e.state.doc),this.builder=new YN(this.cache,new np(e,e.contentDOM),We.iter(r)),this.cache.reused.set(t,2),this.old=new VN(t),this.reuseWalker={skip:(l,o,u)=>{if(this.cache.add(l),l.isComposite())return!1},enter:l=>this.cache.add(l),leave:()=>{},break:()=>{}}}run(e,t){let r=t&&this.getCompositionContext(t.text);for(let i=0,s=0,l=0;;){let o=l<e.length?e[l++]:null,u=o?o.fromA:this.old.root.length;if(u>i){let h=u-i;this.preserve(h,!l,!o),i=u,s+=h}if(!o)break;t&&o.fromA<=t.range.fromA&&o.toA>=t.range.toA?(this.forward(o.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,r),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,o.toA),this.emit(t.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(s,o.toB)),s=o.toB,i=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,r){let i=eL(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(l,o,u)=>{if(l.isWidget())if(this.openWidget)this.builder.continueWidget(u-o);else{let h=u>0||o<l.length?Xl.of(l.widget,this.view,u-o,l.flags&496,this.cache.maybeReuse(l)):this.cache.reuse(l);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,i,s),s=i.length)}else if(l.isText())this.builder.ensureLine(null),!o&&u==l.length&&!this.cache.reused.has(l)?this.builder.addText(l.text,i,s,this.cache.reuse(l)):(this.cache.add(l),this.builder.addText(l.text.slice(o,u),i,s)),s=i.length;else if(l.isLine())l.flags&=-2,this.cache.reused.set(l,1),this.builder.addLine(l);else if(l instanceof ud)this.cache.add(l);else if(l instanceof Zn)this.builder.ensureLine(null),this.builder.addMark(l,i,s),this.cache.reused.set(l,1),s=i.length;else return!1;this.openWidget=!1},enter:l=>{l.isLine()?this.builder.addLineStart(l.attrs,this.cache.maybeReuse(l)):(this.cache.add(l),l instanceof Zn&&i.unshift(l.mark)),this.openWidget=!1},leave:l=>{l.isLine()?i.length&&(i.length=s=0):l instanceof Zn&&(i.shift(),s=Math.min(s,i.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let r=null,i=this.builder,s=0,l=We.spans(this.decorations,e,t,{point:(o,u,h,f,p,g)=>{if(h instanceof zl){if(this.disallowBlockEffectsFor[g]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(u>this.view.state.doc.lineAt(o).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=f.length,p>f.length)i.continueWidget(u-o);else{let x=h.widget||(h.block?sa.block:sa.inline),k=KN(h),b=this.cache.findWidget(x,u-o,k)||Xl.of(x,this.view,u-o,k);h.block?(h.startSide>0&&i.addLineStartIfNotCovered(r),i.addBlockWidget(b)):(i.ensureLine(r),i.addInlineWidget(b,f,p))}r=null}else r=JN(r,h);u>o&&this.text.skip(u-o)},span:(o,u,h,f)=>{for(let p=o;p<u;){let g=this.text.next(Math.min(512,u-p));g==null?(i.addLineStartIfNotCovered(r),i.addBreak(),p++):(i.ensureLine(r),i.addText(g,h,p==o?f:h.length),p+=g.length),r=null}}});i.addLineStartIfNotCovered(r),this.openWidget=l>s,this.openMarks=l}forward(e,t,r=1){t-e<=10?this.old.advance(t-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let t=[],r=null;for(let i=e.parentNode;;i=i.parentNode){let s=Pt.get(i);if(i==this.view.contentDOM)break;s instanceof Zn?t.push(s):s!=null&&s.isLine()?r=s:s instanceof Xi||(i.nodeName=="DIV"&&!r&&i!=this.view.contentDOM?r=new ia(i,z2):r||t.push(Zn.of(new Ac({tagName:i.nodeName.toLowerCase(),attributes:CN(i)}),i)))}return{line:r,marks:t}}}function Ab(n,e){let t=r=>{for(let i of r.children)if((e?i.isText():i.length)||t(i))return!0;return!1};return t(n)}function KN(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}const z2={class:"cm-line"};function JN(n,e){let t=e.spec.attributes,r=e.spec.class;return!t&&!r||(n||(n={class:"cm-line"}),t&&Ry(t,n),r&&(n.class+=" "+r)),n}function eL(n){let e=[];for(let t=n.parents.length;t>1;t--){let r=t==n.parents.length?n.tile:n.parents[t].tile;r instanceof Zn&&e.push(r.mark)}return e}function vg(n){let e=Pt.get(n);return e&&e.setDOM(n.cloneNode()),n}class sa extends Vr{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}get isHidden(){return!0}}sa.inline=new sa("span");sa.block=new sa("div");const bg=new class extends Vr{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Rb{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=$e.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new np(e,e.contentDOM),this.updateInner([new Sr(0,0,0,e.state.doc.length)],null)}update(e){var t;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:f,toA:p})=>p<this.minWidthFrom||f>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.updateEditContextFormatting(e);let i=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?i=this.domChanged.newSel.head:!uL(e.changes,this.hasComposition)&&!e.selectionSet&&(i=e.state.selection.main.head));let s=i>-1?nL(this.view,e.changes,i):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:p}=this.hasComposition;r=new Sr(f,p,e.changes.mapPos(f,-1),e.changes.mapPos(p,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(xe.ie||xe.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let l=this.decorations,o=this.blockWrappers;this.updateDeco();let u=sL(l,this.decorations,e.changes);u.length&&(r=Sr.extendWithRanges(r,u));let h=oL(o,this.blockWrappers,e.changes);return h.length&&(r=Sr.extendWithRanges(r,h)),s&&!r.some(f=>f.fromA<=s.range.fromA&&f.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(t||e.length){let l=this.tile,o=new HN(this.view,l,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&Pt.get(t.text)&&o.cache.reused.set(Pt.get(t.text),2),this.tile=o.run(e,t),vx(l,o.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=xe.chrome||xe.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let i=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof wg&&i.push(s.dom);r.updateGaps(i)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let r of t.effects)r.is(N2)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,i=this.view.root.activeElement,s=i==r,l=!s&&!(this.view.state.facet(Zi)||r.tabIndex>-1)&&_u(r,this.view.observer.selectionRange)&&!(i&&r.contains(i));if(!(s||t||l))return;let o=this.forceSelection;this.forceSelection=!1;let u=this.view.state.selection.main,h,f;if(u.empty?f=h=this.inlineDOMNearPos(u.anchor,u.assoc||1):(f=this.inlineDOMNearPos(u.head,u.head==u.from?1:-1),h=this.inlineDOMNearPos(u.anchor,u.anchor==u.from?1:-1)),xe.gecko&&u.empty&&!this.hasComposition&&tL(h)){let g=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(g,h.node.childNodes[h.offset]||null)),h=f=new Xr(g,0),o=!0}let p=this.view.observer.selectionRange;(o||!p.focusNode||(!Iu(h.node,h.offset,p.anchorNode,p.anchorOffset)||!Iu(f.node,f.offset,p.focusNode,p.focusOffset))&&!this.suppressWidgetCursorChange(p,u))&&(this.view.observer.ignore(()=>{xe.android&&xe.chrome&&r.contains(p.focusNode)&&aL(p.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let g=tc(this.view.root);if(g)if(u.empty){if(xe.gecko){let x=rL(h.node,h.offset);if(x&&x!=3){let k=(x==1?y2:k2)(h.node,h.offset);k&&(h=new Xr(k.node,k.offset))}}g.collapse(h.node,h.offset),u.bidiLevel!=null&&g.caretBidiLevel!==void 0&&(g.caretBidiLevel=u.bidiLevel)}else if(g.extend){g.collapse(h.node,h.offset);try{g.extend(f.node,f.offset)}catch{}}else{let x=document.createRange();u.anchor>u.head&&([h,f]=[f,h]),x.setEnd(f.node,f.offset),x.setStart(h.node,h.offset),g.removeAllRanges(),g.addRange(x)}l&&this.view.root.activeElement==r&&(r.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(h,f)),this.impreciseAnchor=h.precise?null:new Xr(p.anchorNode,p.anchorOffset),this.impreciseHead=f.precise?null:new Xr(p.focusNode,p.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Iu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,r=tc(e.root),{anchorNode:i,anchorOffset:s}=e.observer.selectionRange;if(!r||!t.empty||!t.assoc||!r.modify)return;let l=this.lineAt(t.head,t.assoc);if(!l)return;let o=l.posAtStart;if(t.head==o||t.head==o+l.length)return;let u=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!u||!h||u.bottom>h.top)return;let f=this.domAtPos(t.head+t.assoc,t.assoc);r.collapse(f.node,f.offset),r.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let p=e.observer.selectionRange;e.docView.posFromDOM(p.anchorNode,p.anchorOffset)!=t.from&&r.collapse(i,s)}posFromDOM(e,t){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let i=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[t];else{let l=Vi(e)==0?0:t==0?-1:1;for(;;){let o=e.parentNode;if(o==r.dom)break;l==0&&o.firstChild!=o.lastChild&&(e==o.firstChild?l=-1:l=1),e=o}l<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return i;for(;s&&!Pt.get(s);)s=s.nextSibling;if(!s)return i+r.length;for(let l=0,o=i;;l++){let u=r.children[l];if(u.dom==s)return o;o+=u.length+u.breakAfter}}else return r.isText()?e==r.dom?i+t:i+(t?r.length:0):i}domAtPos(e,t){let{tile:r,offset:i}=this.tile.resolveBlock(e,t);return r.isWidget()?r.domPosFor(e,t):r.domIn(i,t)}inlineDOMNearPos(e,t){let r,i=-1,s=!1,l,o=-1,u=!1;return this.tile.blockTiles((h,f)=>{if(h.isWidget()){if(h.flags&32&&f>=e)return!0;h.flags&16&&(s=!0)}else{let p=f+h.length;if(f<=e&&(r=h,i=e-f,s=p<e),p>=e&&!l&&(l=h,o=e-f,u=f>e),f>e&&l)return!0}}),!r&&!l?this.domAtPos(e,t):(s&&l?r=null:u&&r&&(l=null),r&&t<0||!l?r.domIn(i,t):l.domIn(o,t))}coordsAt(e,t){let{tile:r,offset:i}=this.tile.resolveBlock(e,t);return r.isWidget()?r.widget instanceof wg?null:r.coordsInWidget(i,t,!0):r.coordsIn(i,t)}lineAt(e,t){let{tile:r}=this.tile.resolveBlock(e,t);return r.isLine()?r:null}coordsForChar(e){let{tile:t,offset:r}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function i(s,l){if(s.isComposite())for(let o of s.children){if(o.length>=l){let u=i(o,l);if(u)return u}if(l-=o.length,l<0)break}else if(s.isText()&&l<s.length){let o=Ut(s.text,l);if(o==l)return null;let u=rc(s.dom,l,o).getClientRects();for(let h=0;h<u.length;h++){let f=u[h];if(h==u.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return i(t,r)}measureVisibleLineHeights(e){let t=[],{from:r,to:i}=e,s=this.view.contentDOM.clientWidth,l=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,u=this.view.textDirection==ht.LTR,h=0,f=(p,g,x)=>{for(let k=0;k<p.children.length&&!(g>i);k++){let b=p.children[k],w=g+b.length,S=b.dom.getBoundingClientRect(),{height:Q}=S;if(x&&!k&&(h+=S.top-x.top),b instanceof Xi)w>r&&f(b,g,S);else if(g>=r&&(h>0&&t.push(-h),t.push(Q+h),h=0,l)){let $=b.dom.lastChild,R=$?Du($):[];if(R.length){let I=R[R.length-1],T=u?I.right-S.left:S.right-I.left;T>o&&(o=T,this.minWidth=s,this.minWidthFrom=g,this.minWidthTo=w)}}x&&k==p.children.length-1&&(h+=x.bottom-S.bottom),g=w+b.breakAfter}};return f(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?ht.RTL:ht.LTR}measureTextSize(){let e=this.tile.blockTiles(l=>{if(l.isLine()&&l.children.length&&l.length<=20){let o=0,u;for(let h of l.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let f=Du(h.dom);if(f.length!=1)return;o+=f[0].width,u=f[0].height}if(o)return{lineHeight:l.dom.getBoundingClientRect().height,charWidth:o/l.length,textHeight:u}}});if(e)return e;let t=document.createElement("div"),r,i,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let l=Du(t.firstChild)[0];r=t.getBoundingClientRect().height,i=l&&l.width?l.width/27:7,s=l&&l.height?l.height:r,t.remove()}),{lineHeight:r,charWidth:i,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let r=0,i=0;;i++){let s=i==t.viewports.length?null:t.viewports[i],l=s?s.from-1:this.view.state.doc.length;if(l>r){let o=(t.lineBlockAt(l).bottom-t.lineBlockAt(r).top)/this.view.scaleY;e.push($e.replace({widget:new wg(o),block:!0,inclusive:!0,isBlockGap:!0}).range(r,l))}if(!s)break;r=s.to+1}return $e.set(e)}updateDeco(){let e=1,t=this.view.state.facet(ep).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,i=this.view.state.facet(zy).map((s,l)=>{let o=typeof s=="function";return o&&(r=!0),o?s(this.view):s});for(i.length&&(this.dynamicDecorationMap[e++]=r,t.push(We.join(i))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(_2).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){var t;if(e.isSnapshot){let f=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=f.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let f of this.view.state.facet(R2))try{if(f(this.view,e.range,e))return!0}catch(p){Xn(this.view.state,p,"scroll handler")}let{range:r}=e,i=this.coordsAt(r.head,(t=r.assoc)!==null&&t!==void 0?t:r.empty?0:r.head>r.anchor?-1:1),s;if(!i)return;!r.empty&&(s=this.coordsAt(r.anchor,r.anchor>r.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let l=Zy(this.view),o={left:i.left-l.left,top:i.top-l.top,right:i.right+l.right,bottom:i.bottom+l.bottom},{offsetWidth:u,offsetHeight:h}=this.view.scrollDOM;if(TN(this.view.scrollDOM,o,r.head<r.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,u),-u),Math.max(Math.min(e.yMargin,h),-h),this.view.textDirection==ht.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(i.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||i.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let f=this.view.docView.lineAt(r.head,1);f&&f.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=r=>r.isWidget()||r.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){vx(this.tile)}}function vx(n,e){let t=e==null?void 0:e.get(n);if(t!=1){t==null&&n.destroy();for(let r of n.children)vx(r,e)}}function tL(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function Z2(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let r=y2(t.focusNode,t.focusOffset),i=k2(t.focusNode,t.focusOffset),s=r||i;if(i&&r&&i.node!=r.node){let o=Pt.get(i.node);if(!o||o.isText()&&o.text!=i.node.nodeValue)s=i;else if(n.docView.lastCompositionAfterCursor){let u=Pt.get(r.node);!u||u.isText()&&u.text!=r.node.nodeValue||(s=i)}}if(n.docView.lastCompositionAfterCursor=s!=r,!s)return null;let l=e-s.offset;return{from:l,to:l+s.node.nodeValue.length,node:s.node}}function nL(n,e,t){let r=Z2(n,t);if(!r)return null;let{node:i,from:s,to:l}=r,o=i.nodeValue;if(/[\n\r]/.test(o)||n.state.doc.sliceString(r.from,r.to)!=o)return null;let u=e.invertedDesc;return{range:new Sr(u.mapPos(s),u.mapPos(l),s,l),text:i}}function rL(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let iL=class{constructor(){this.changes=[]}compareRange(e,t){Lo(e,t,this.changes)}comparePoint(e,t){Lo(e,t,this.changes)}boundChange(e){Lo(e,e,this.changes)}};function sL(n,e,t){let r=new iL;return We.compare(n,e,t,r),r.changes}class lL{constructor(){this.changes=[]}compareRange(e,t){Lo(e,t,this.changes)}comparePoint(){}boundChange(e){Lo(e,e,this.changes)}}function oL(n,e,t){let r=new lL;return We.compare(n,e,t,r),r.changes}function aL(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function uL(n,e){let t=!1;return e&&n.iterChangedRanges((r,i)=>{r<e.to&&i>e.from&&(t=!0)}),t}class wg extends Vr{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function cL(n,e,t=1){let r=n.charCategorizer(e),i=n.doc.lineAt(e),s=e-i.from;if(i.length==0)return Y.cursor(e);s==0?t=1:s==i.length&&(t=-1);let l=s,o=s;t<0?l=Ut(i.text,s,!1):o=Ut(i.text,s);let u=r(i.text.slice(l,o));for(;l>0;){let h=Ut(i.text,l,!1);if(r(i.text.slice(h,l))!=u)break;l=h}for(;o<i.length;){let h=Ut(i.text,o);if(r(i.text.slice(o,h))!=u)break;o=h}return Y.range(l+i.from,o+i.from)}function hL(n,e,t,r,i){let s=Math.round((r-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let o=n.viewState.heightOracle.textHeight,u=Math.floor((i-t.top-(n.defaultLineHeight-o)*.5)/o);s+=u*n.viewState.heightOracle.lineLength}let l=n.state.sliceDoc(t.from,t.to);return t.from+ux(l,s,n.state.tabSize)}function bx(n,e,t){let r=n.lineBlockAt(e);if(Array.isArray(r.type)){let i;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!i||s.type==ln.Text&&(i.type!=s.type||(t<0?s.from<e:s.to>e)))&&(i=s)}}return i||r}return r}function fL(n,e,t,r){let i=bx(n,e.head,e.assoc||-1),s=!r||i.type!=ln.Text||!(n.lineWrapping||i.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>i.from?e.head-1:e.head);if(s){let l=n.dom.getBoundingClientRect(),o=n.textDirectionAt(i.from),u=n.posAtCoords({x:t==(o==ht.LTR)?l.right-1:l.left+1,y:(s.top+s.bottom)/2});if(u!=null)return Y.cursor(u,t?-1:1)}return Y.cursor(t?i.to:i.from,t?-1:1)}function Nb(n,e,t,r){let i=n.state.doc.lineAt(e.head),s=n.bidiSpans(i),l=n.textDirectionAt(i.from);for(let o=e,u=null;;){let h=zN(i,s,l,o,t),f=P2;if(!h){if(i.number==(t?n.state.doc.lines:1))return o;f=`
69
+ `){[e,t]=ra(this,e,t);let i="";for(let s=0,l=0;s<this.children.length&&l<=t;s++){let o=this.children[s],u=l+o.length;l>e&&s&&(i+=r),e<u&&t>l&&(i+=o.sliceString(e-l,t-l,r)),l=u+1}return i}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof ci))return 0;let r=0,[i,s,l,o]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;i+=t,s+=t){if(i==l||s==o)return r;let u=this.children[i],h=e.children[s];if(u!=h)return r+u.scanIdentical(h,t);r+=u.length+1}}static from(e,t=e.reduce((r,i)=>r+i.length+1,-1)){let r=0;for(let x of e)r+=x.lines;if(r<32){let x=[];for(let k of e)k.flatten(x);return new jt(x,t)}let i=Math.max(32,r>>5),s=i<<1,l=i>>1,o=[],u=0,h=-1,f=[];function p(x){let k;if(x.lines>s&&x instanceof ci)for(let b of x.children)p(b);else x.lines>l&&(u>l||!u)?(g(),o.push(x)):x instanceof jt&&u&&(k=f[f.length-1])instanceof jt&&x.lines+k.lines<=32?(u+=x.lines,h+=x.length+1,f[f.length-1]=new jt(k.text.concat(x.text),k.length+1+x.length)):(u+x.lines>i&&g(),u+=x.lines,h+=x.length+1,f.push(x))}function g(){u!=0&&(o.push(f.length==1?f[0]:ci.from(f,h)),h=-1,u=f.length=0)}for(let x of e)p(x);return g(),o.length==1?o[0]:new ci(o,t)}}Ge.empty=new jt([""],0);function s5(n){let e=-1;for(let t of n)e+=t.length+1;return e}function If(n,e,t=0,r=1e9){for(let i=0,s=0,l=!0;s<n.length&&i<=r;s++){let o=n[s],u=i+o.length;u>=t&&(u>r&&(o=o.slice(0,r-i)),i<t&&(o=o.slice(t-i)),l?(e[e.length-1]+=o,l=!1):e.push(o)),i=u+1}return e}function Ob(n,e,t){return If(n,[""],e,t)}class Nu{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 jt?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let r=this.nodes.length-1,i=this.nodes[r],s=this.offsets[r],l=s>>1,o=i instanceof jt?i.text.length:i.children.length;if(l==(t>0?o:0)){if(r==0)return this.done=!0,this.value="",this;t>0&&this.offsets[r-1]++,this.nodes.pop(),this.offsets.pop()}else if((s&1)==(t>0?0:1)){if(this.offsets[r]+=t,e==0)return this.lineBreak=!0,this.value=`
70
+ `,this;e--}else if(i instanceof jt){let u=i.text[l+(t<0?-1:0)];if(this.offsets[r]+=t,u.length>Math.max(0,e))return this.value=e==0?u:t>0?u.slice(e):u.slice(0,u.length-e),this;e-=u.length}else{let u=i.children[l+(t<0?-1:0)];e>u.length?(e-=u.length,this.offsets[r]+=t):(t<0&&this.offsets[r]--,this.nodes.push(u),this.offsets.push(t>0?1:(u instanceof jt?u.text.length:u.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class HC{constructor(e,t,r){this.value="",this.done=!1,this.cursor=new Nu(e,t>r?-1:1),this.pos=t>r?e.length:0,this.from=Math.min(t,r),this.to=Math.max(t,r)}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 r=t<0?this.pos-this.from:this.to-this.pos;e>r&&(e=r),r-=e;let{value:i}=this.cursor.next(e);return this.pos+=(i.length+e)*t,this.value=i.length<=r?i:t<0?i.slice(i.length-r):i.slice(0,r),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!=""}}class KC{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:r,value:i}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):r?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=i,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(Ge.prototype[Symbol.iterator]=function(){return this.iter()},Nu.prototype[Symbol.iterator]=HC.prototype[Symbol.iterator]=KC.prototype[Symbol.iterator]=function(){return this});let l5=class{constructor(e,t,r,i){this.from=e,this.to=t,this.number=r,this.text=i}get length(){return this.to-this.from}};function ra(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function Ut(n,e,t=!0,r=!0){return r5(n,e,t,r)}function o5(n){return n>=56320&&n<57344}function a5(n){return n>=55296&&n<56320}function In(n,e){let t=n.charCodeAt(e);if(!a5(t)||e+1==n.length)return t;let r=n.charCodeAt(e+1);return o5(r)?(t-55296<<10)+(r-56320)+65536:t}function Ty(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function hi(n){return n<65536?1:2}const KO=/\r\n?|\n/;var sn=(function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n})(sn||(sn={}));class Oi{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 r=this.sections[t+1];e+=r<0?this.sections[t]:r}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,r=0,i=0;t<this.sections.length;){let s=this.sections[t++],l=this.sections[t++];l<0?(e(r,i,s),i+=s):i+=l,r+=s}}iterChangedRanges(e,t=!1){JO(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let r=this.sections[t++],i=this.sections[t++];i<0?e.push(r,i):e.push(i,r)}return new Oi(e)}composeDesc(e){return this.empty?e:e.empty?this:JC(this,e)}mapDesc(e,t=!1){return e.empty?this:ex(this,e,t)}mapPos(e,t=-1,r=sn.Simple){let i=0,s=0;for(let l=0;l<this.sections.length;){let o=this.sections[l++],u=this.sections[l++],h=i+o;if(u<0){if(h>e)return s+(e-i);s+=o}else{if(r!=sn.Simple&&h>=e&&(r==sn.TrackDel&&i<e&&h>e||r==sn.TrackBefore&&i<e||r==sn.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!o)return e==i||t<0?s:s+u;s+=u}i=h}if(e>i)throw new RangeError(`Position ${e} is out of range for changeset of length ${i}`);return s}touchesRange(e,t=e){for(let r=0,i=0;r<this.sections.length&&i<=t;){let s=this.sections[r++],l=this.sections[r++],o=i+s;if(l>=0&&i<=t&&o>=e)return i<e&&o>t?"cover":!0;i=o}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let r=this.sections[t++],i=this.sections[t++];e+=(e?" ":"")+r+(i>=0?":"+i:"")}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 Oi(e)}static create(e){return new Oi(e)}}class Lt extends Oi{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 JO(this,(t,r,i,s,l)=>e=e.replace(i,i+(r-t),l),!1),e}mapDesc(e,t=!1){return ex(this,e,t,!0)}invert(e){let t=this.sections.slice(),r=[];for(let i=0,s=0;i<t.length;i+=2){let l=t[i],o=t[i+1];if(o>=0){t[i]=o,t[i+1]=l;let u=i>>1;for(;r.length<u;)r.push(Ge.empty);r.push(l?e.slice(s,s+l):Ge.empty)}s+=l}return new Lt(t,r)}compose(e){return this.empty?e:e.empty?this:JC(this,e,!0)}map(e,t=!1){return e.empty?this:ex(this,e,t,!0)}iterChanges(e,t=!1){JO(this,e,t)}get desc(){return Oi.create(this.sections)}filter(e){let t=[],r=[],i=[],s=new Hu(this);e:for(let l=0,o=0;;){let u=l==e.length?1e9:e[l++];for(;o<u||o==u&&s.len==0;){if(s.done)break e;let f=Math.min(s.len,u-o);pn(i,f,-1);let p=s.ins==-1?-1:s.off==0?s.ins:0;pn(t,f,p),p>0&&Ds(r,t,s.text),s.forward(f),o+=f}let h=e[l++];for(;o<h;){if(s.done)break e;let f=Math.min(s.len,h-o);pn(t,f,-1),pn(i,f,s.ins==-1?-1:s.off==0?s.ins:0),s.forward(f),o+=f}}return{changes:new Lt(t,r),filtered:Oi.create(i)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let r=this.sections[t],i=this.sections[t+1];i<0?e.push(r):i==0?e.push([r]):e.push([r].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,r){let i=[],s=[],l=0,o=null;function u(f=!1){if(!f&&!i.length)return;l<t&&pn(i,t-l,-1);let p=new Lt(i,s);o=o?o.compose(p.map(o)):p,i=[],s=[],l=0}function h(f){if(Array.isArray(f))for(let p of f)h(p);else if(f instanceof Lt){if(f.length!=t)throw new RangeError(`Mismatched change set length (got ${f.length}, expected ${t})`);u(),o=o?o.compose(f.map(o)):f}else{let{from:p,to:g=p,insert:x}=f;if(p>g||p<0||g>t)throw new RangeError(`Invalid change range ${p} to ${g} (in doc of length ${t})`);let k=x?typeof x=="string"?Ge.of(x.split(r||KO)):x:Ge.empty,b=k.length;if(p==g&&b==0)return;p<l&&u(),p>l&&pn(i,p-l,-1),pn(i,g-p,b),Ds(s,i,k),l=g}}return h(e),u(!o),o}static empty(e){return new Lt(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],r=[];for(let i=0;i<e.length;i++){let s=e[i];if(typeof s=="number")t.push(s,-1);else{if(!Array.isArray(s)||typeof s[0]!="number"||s.some((l,o)=>o&&typeof l!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(s.length==1)t.push(s[0],0);else{for(;r.length<i;)r.push(Ge.empty);r[i]=Ge.of(s.slice(1)),t.push(s[0],r[i].length)}}}return new Lt(t,r)}static createSet(e,t){return new Lt(e,t)}}function pn(n,e,t,r=!1){if(e==0&&t<=0)return;let i=n.length-2;i>=0&&t<=0&&t==n[i+1]?n[i]+=e:i>=0&&e==0&&n[i]==0?n[i+1]+=t:r?(n[i]+=e,n[i+1]+=t):n.push(e,t)}function Ds(n,e,t){if(t.length==0)return;let r=e.length-2>>1;if(r<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<r;)n.push(Ge.empty);n.push(t)}}function JO(n,e,t){let r=n.inserted;for(let i=0,s=0,l=0;l<n.sections.length;){let o=n.sections[l++],u=n.sections[l++];if(u<0)i+=o,s+=o;else{let h=i,f=s,p=Ge.empty;for(;h+=o,f+=u,u&&r&&(p=p.append(r[l-2>>1])),!(t||l==n.sections.length||n.sections[l+1]<0);)o=n.sections[l++],u=n.sections[l++];e(i,h,s,f,p),i=h,s=f}}}function ex(n,e,t,r=!1){let i=[],s=r?[]:null,l=new Hu(n),o=new Hu(e);for(let u=-1;;){if(l.done&&o.len||o.done&&l.len)throw new Error("Mismatched change set lengths");if(l.ins==-1&&o.ins==-1){let h=Math.min(l.len,o.len);pn(i,h,-1),l.forward(h),o.forward(h)}else if(o.ins>=0&&(l.ins<0||u==l.i||l.off==0&&(o.len<l.len||o.len==l.len&&!t))){let h=o.len;for(pn(i,o.ins,-1);h;){let f=Math.min(l.len,h);l.ins>=0&&u<l.i&&l.len<=f&&(pn(i,0,l.ins),s&&Ds(s,i,l.text),u=l.i),l.forward(f),h-=f}o.next()}else if(l.ins>=0){let h=0,f=l.len;for(;f;)if(o.ins==-1){let p=Math.min(f,o.len);h+=p,f-=p,o.forward(p)}else if(o.ins==0&&o.len<f)f-=o.len,o.next();else break;pn(i,h,u<l.i?l.ins:0),s&&u<l.i&&Ds(s,i,l.text),u=l.i,l.forward(l.len-f)}else{if(l.done&&o.done)return s?Lt.createSet(i,s):Oi.create(i);throw new Error("Mismatched change set lengths")}}}function JC(n,e,t=!1){let r=[],i=t?[]:null,s=new Hu(n),l=new Hu(e);for(let o=!1;;){if(s.done&&l.done)return i?Lt.createSet(r,i):Oi.create(r);if(s.ins==0)pn(r,s.len,0,o),s.next();else if(l.len==0&&!l.done)pn(r,0,l.ins,o),i&&Ds(i,r,l.text),l.next();else{if(s.done||l.done)throw new Error("Mismatched change set lengths");{let u=Math.min(s.len2,l.len),h=r.length;if(s.ins==-1){let f=l.ins==-1?-1:l.off?0:l.ins;pn(r,u,f,o),i&&f&&Ds(i,r,l.text)}else l.ins==-1?(pn(r,s.off?0:s.len,u,o),i&&Ds(i,r,s.textBit(u))):(pn(r,s.off?0:s.len,l.off?0:l.ins,o),i&&!l.off&&Ds(i,r,l.text));o=(s.ins>u||l.ins>=0&&l.len>u)&&(o||r.length>h),s.forward2(u),l.forward(u)}}}}class Hu{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?Ge.empty:e[t]}textBit(e){let{inserted:t}=this.set,r=this.i-2>>1;return r>=t.length&&!e?Ge.empty:t[r].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)}}class wl{constructor(e,t,r){this.from=e,this.to=t,this.flags=r}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let r,i;return this.empty?r=i=e.mapPos(this.from,t):(r=e.mapPos(this.from,1),i=e.mapPos(this.to,-1)),r==this.from&&i==this.to?this:new wl(r,i,this.flags)}extend(e,t=e,r=0){if(e<=this.anchor&&t>=this.anchor)return Y.range(e,t,void 0,void 0,r);let i=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return Y.range(this.anchor,i,void 0,void 0,r)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}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 Y.range(e.anchor,e.head)}static create(e,t,r){return new wl(e,t,r)}}class Y{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:Y.create(this.ranges.map(r=>r.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let r=0;r<this.ranges.length;r++)if(!this.ranges[r].eq(e.ranges[r],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new Y([this.main],0)}addRange(e,t=!0){return Y.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let r=this.ranges.slice();return r[t]=e,Y.create(r,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 Y(e.ranges.map(t=>wl.fromJSON(t)),e.main)}static single(e,t=e){return new Y([Y.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 r=0,i=0;i<e.length;i++){let s=e[i];if(s.empty?s.from<=r:s.from<r)return Y.normalized(e.slice(),t);r=s.to}return new Y(e,t)}static cursor(e,t=0,r,i){return wl.create(e,e,(t==0?0:t<0?8:16)|(r==null?7:Math.min(6,r))|(i??16777215)<<6)}static range(e,t,r,i,s){let l=(r??16777215)<<6|(i==null?7:Math.min(6,i));return!s&&e!=t&&(s=t<e?1:-1),t<e?wl.create(t,e,48|l):wl.create(e,t,(s?s<0?8:16:0)|l)}static normalized(e,t=0){let r=e[t];e.sort((i,s)=>i.from-s.from),t=e.indexOf(r);for(let i=1;i<e.length;i++){let s=e[i],l=e[i-1];if(s.empty?s.from<=l.to:s.from<l.to){let o=l.from,u=Math.max(s.to,l.to);i<=t&&t--,e.splice(--i,2,s.anchor>s.head?Y.range(u,o):Y.range(o,u))}}return new Y(e,t)}}function e2(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let jy=0;class ge{constructor(e,t,r,i,s){this.combine=e,this.compareInput=t,this.compare=r,this.isStatic=i,this.id=jy++,this.default=e([]),this.extensions=typeof s=="function"?s(this):s}get reader(){return this}static define(e={}){return new ge(e.combine||(t=>t),e.compareInput||((t,r)=>t===r),e.compare||(e.combine?(t,r)=>t===r:Ey),!!e.static,e.enables)}of(e){return new zf([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new zf(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new zf(e,this,2,t)}from(e,t){return t||(t=r=>r),this.compute([e],r=>t(r.field(e)))}}function Ey(n,e){return n==e||n.length==e.length&&n.every((t,r)=>t===e[r])}class zf{constructor(e,t,r,i){this.dependencies=e,this.facet=t,this.type=r,this.value=i,this.id=jy++}dynamicSlot(e){var t;let r=this.value,i=this.facet.compareInput,s=this.id,l=e[s]>>1,o=this.type==2,u=!1,h=!1,f=[];for(let p of this.dependencies)p=="doc"?u=!0:p=="selection"?h=!0:(((t=e[p.id])!==null&&t!==void 0?t:1)&1)==0&&f.push(e[p.id]);return{create(p){return p.values[l]=r(p),1},update(p,g){if(u&&g.docChanged||h&&(g.docChanged||g.selection)||tx(p,f)){let x=r(p);if(o?!xb(x,p.values[l],i):!i(x,p.values[l]))return p.values[l]=x,1}return 0},reconfigure:(p,g)=>{let x,k=g.config.address[s];if(k!=null){let b=sd(g,k);if(this.dependencies.every(w=>w instanceof ge?g.facet(w)===p.facet(w):w instanceof an?g.field(w,!1)==p.field(w,!1):!0)||(o?xb(x=r(p),b,i):i(x=r(p),b)))return p.values[l]=b,0}else x=r(p);return p.values[l]=x,1}}}}function xb(n,e,t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!t(n[r],e[r]))return!1;return!0}function tx(n,e){let t=!1;for(let r of e)Lu(n,r)&1&&(t=!0);return t}function u5(n,e,t){let r=t.map(u=>n[u.id]),i=t.map(u=>u.type),s=r.filter(u=>!(u&1)),l=n[e.id]>>1;function o(u){let h=[];for(let f=0;f<r.length;f++){let p=sd(u,r[f]);if(i[f]==2)for(let g of p)h.push(g);else h.push(p)}return e.combine(h)}return{create(u){for(let h of r)Lu(u,h);return u.values[l]=o(u),1},update(u,h){if(!tx(u,s))return 0;let f=o(u);return e.compare(f,u.values[l])?0:(u.values[l]=f,1)},reconfigure(u,h){let f=tx(u,r),p=h.config.facets[e.id],g=h.facet(e);if(p&&!f&&Ey(t,p))return u.values[l]=g,0;let x=o(u);return e.compare(x,g)?(u.values[l]=g,0):(u.values[l]=x,1)}}}const of=ge.define({static:!0});class an{constructor(e,t,r,i,s){this.id=e,this.createF=t,this.updateF=r,this.compareF=i,this.spec=s,this.provides=void 0}static define(e){let t=new an(jy++,e.create,e.update,e.compare||((r,i)=>r===i),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(of).find(r=>r.field==this);return((t==null?void 0:t.create)||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:r=>(r.values[t]=this.create(r),1),update:(r,i)=>{let s=r.values[t],l=this.updateF(s,i);return this.compareF(s,l)?0:(r.values[t]=l,1)},reconfigure:(r,i)=>{let s=r.facet(of),l=i.facet(of),o;return(o=s.find(u=>u.field==this))&&o!=l.find(u=>u.field==this)?(r.values[t]=o.create(r),1):i.config.address[this.id]!=null?(r.values[t]=i.field(this),0):(r.values[t]=this.create(r),1)}}}init(e){return[this,of.of({field:this,create:e})]}get extension(){return this}}const yl={lowest:4,low:3,default:2,high:1,highest:0};function gu(n){return e=>new t2(e,n)}const Ui={highest:gu(yl.highest),high:gu(yl.high),default:gu(yl.default),low:gu(yl.low),lowest:gu(yl.lowest)};class t2{constructor(e,t){this.inner=e,this.prec=t}}class Kd{of(e){return new nx(this,e)}reconfigure(e){return Kd.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class nx{constructor(e,t){this.compartment=e,this.inner=t}}class id{constructor(e,t,r,i,s,l){for(this.base=e,this.compartments=t,this.dynamicSlots=r,this.address=i,this.staticValues=s,this.facets=l,this.statusTemplate=[];this.statusTemplate.length<r.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,r){let i=[],s=Object.create(null),l=new Map;for(let g of c5(e,t,l))g instanceof an?i.push(g):(s[g.facet.id]||(s[g.facet.id]=[])).push(g);let o=Object.create(null),u=[],h=[];for(let g of i)o[g.id]=h.length<<1,h.push(x=>g.slot(x));let f=r==null?void 0:r.config.facets;for(let g in s){let x=s[g],k=x[0].facet,b=f&&f[g]||[];if(x.every(w=>w.type==0))if(o[k.id]=u.length<<1|1,Ey(b,x))u.push(r.facet(k));else{let w=k.combine(x.map(S=>S.value));u.push(r&&k.compare(w,r.facet(k))?r.facet(k):w)}else{for(let w of x)w.type==0?(o[w.id]=u.length<<1|1,u.push(w.value)):(o[w.id]=h.length<<1,h.push(S=>w.dynamicSlot(S)));o[k.id]=h.length<<1,h.push(w=>u5(w,k,x))}}let p=h.map(g=>g(o));return new id(e,l,p,o,u,s)}}function c5(n,e,t){let r=[[],[],[],[],[]],i=new Map;function s(l,o){let u=i.get(l);if(u!=null){if(u<=o)return;let h=r[u].indexOf(l);h>-1&&r[u].splice(h,1),l instanceof nx&&t.delete(l.compartment)}if(i.set(l,o),Array.isArray(l))for(let h of l)s(h,o);else if(l instanceof nx){if(t.has(l.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(l.compartment)||l.inner;t.set(l.compartment,h),s(h,o)}else if(l instanceof t2)s(l.inner,l.prec);else if(l instanceof an)r[o].push(l),l.provides&&s(l.provides,o);else if(l instanceof zf)r[o].push(l),l.facet.extensions&&s(l.facet.extensions,yl.default);else{let h=l.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${l}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);s(h,o)}}return s(n,yl.default),r.reduce((l,o)=>l.concat(o))}function Lu(n,e){if(e&1)return 2;let t=e>>1,r=n.status[t];if(r==4)throw new Error("Cyclic dependency between fields and/or facets");if(r&2)return r;n.status[t]=4;let i=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|i}function sd(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const n2=ge.define(),rx=ge.define({combine:n=>n.some(e=>e),static:!0}),r2=ge.define({combine:n=>n.length?n[0]:void 0,static:!0}),i2=ge.define(),s2=ge.define(),l2=ge.define(),o2=ge.define({combine:n=>n.length?n[0]:!1});class vi{constructor(e,t){this.type=e,this.value=t}static define(){return new h5}}class h5{of(e){return new vi(this,e)}}class f5{constructor(e){this.map=e}of(e){return new Ne(this,e)}}class Ne{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 Ne(this.type,t)}is(e){return this.type==e}static define(e={}){return new f5(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let r=[];for(let i of e){let s=i.map(t);s&&r.push(s)}return r}}Ne.reconfigure=Ne.define();Ne.appendConfig=Ne.define();class At{constructor(e,t,r,i,s,l){this.startState=e,this.changes=t,this.selection=r,this.effects=i,this.annotations=s,this.scrollIntoView=l,this._doc=null,this._state=null,r&&e2(r,t.newLength),s.some(o=>o.type==At.time)||(this.annotations=s.concat(At.time.of(Date.now())))}static create(e,t,r,i,s,l){return new At(e,t,r,i,s,l)}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(At.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}At.time=vi.define();At.userEvent=vi.define();At.addToHistory=vi.define();At.remote=vi.define();function d5(n,e){let t=[];for(let r=0,i=0;;){let s,l;if(r<n.length&&(i==e.length||e[i]>=n[r]))s=n[r++],l=n[r++];else if(i<e.length)s=e[i++],l=e[i++];else return t;!t.length||t[t.length-1]<s?t.push(s,l):t[t.length-1]<l&&(t[t.length-1]=l)}}function a2(n,e,t){var r;let i,s,l;return t?(i=e.changes,s=Lt.empty(e.changes.length),l=n.changes.compose(e.changes)):(i=e.changes.map(n.changes),s=n.changes.mapDesc(e.changes,!0),l=n.changes.compose(i)),{changes:l,selection:e.selection?e.selection.map(s):(r=n.selection)===null||r===void 0?void 0:r.map(i),effects:Ne.mapEffects(n.effects,i).concat(Ne.mapEffects(e.effects,s)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function ix(n,e,t){let r=e.selection,i=No(e.annotations);return e.userEvent&&(i=i.concat(At.userEvent.of(e.userEvent))),{changes:e.changes instanceof Lt?e.changes:Lt.of(e.changes||[],t,n.facet(r2)),selection:r&&(r instanceof Y?r:Y.single(r.anchor,r.head)),effects:No(e.effects),annotations:i,scrollIntoView:!!e.scrollIntoView}}function u2(n,e,t){let r=ix(n,e.length?e[0]:{},n.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 l=!!e[s].sequential;r=a2(r,ix(n,e[s],l?r.changes.newLength:n.doc.length),l)}let i=At.create(n,r.changes,r.selection,r.effects,r.annotations,r.scrollIntoView);return m5(t?p5(i):i)}function p5(n){let e=n.startState,t=!0;for(let i of e.facet(i2)){let s=i(n);if(s===!1){t=!1;break}Array.isArray(s)&&(t=t===!0?s:d5(t,s))}if(t!==!0){let i,s;if(t===!1)s=n.changes.invertedDesc,i=Lt.empty(e.doc.length);else{let l=n.changes.filter(t);i=l.changes,s=l.filtered.mapDesc(l.changes).invertedDesc}n=At.create(e,i,n.selection&&n.selection.map(s),Ne.mapEffects(n.effects,s),n.annotations,n.scrollIntoView)}let r=e.facet(s2);for(let i=r.length-1;i>=0;i--){let s=r[i](n);s instanceof At?n=s:Array.isArray(s)&&s.length==1&&s[0]instanceof At?n=s[0]:n=u2(e,No(s),!1)}return n}function m5(n){let e=n.startState,t=e.facet(l2),r=n;for(let i=t.length-1;i>=0;i--){let s=t[i](n);s&&Object.keys(s).length&&(r=a2(r,ix(e,s,n.changes.newLength),!0))}return r==n?n:At.create(e,n.changes,n.selection,r.effects,r.annotations,r.scrollIntoView)}const g5=[];function No(n){return n==null?g5:Array.isArray(n)?n:[n]}var yt=(function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n})(yt||(yt={}));const O5=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let sx;try{sx=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function x5(n){if(sx)return sx.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"€"&&(t.toUpperCase()!=t.toLowerCase()||O5.test(t)))return!0}return!1}function y5(n){return e=>{if(!/\S/.test(e))return yt.Space;if(x5(e))return yt.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return yt.Word;return yt.Other}}class Fe{constructor(e,t,r,i,s,l){this.config=e,this.doc=t,this.selection=r,this.values=i,this.status=e.statusTemplate.slice(),this.computeSlot=s,l&&(l._state=this);for(let o=0;o<this.config.dynamicSlots.length;o++)Lu(this,o<<1);this.computeSlot=null}field(e,t=!0){let r=this.config.address[e.id];if(r==null){if(t)throw new RangeError("Field is not present in this state");return}return Lu(this,r),sd(this,r)}update(...e){return u2(this,e,!0)}applyTransaction(e){let t=this.config,{base:r,compartments:i}=t;for(let o of e.effects)o.is(Kd.reconfigure)?(t&&(i=new Map,t.compartments.forEach((u,h)=>i.set(h,u)),t=null),i.set(o.value.compartment,o.value.extension)):o.is(Ne.reconfigure)?(t=null,r=o.value):o.is(Ne.appendConfig)&&(t=null,r=No(r).concat(o.value));let s;t?s=e.startState.values.slice():(t=id.resolve(r,i,this),s=new Fe(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(u,h)=>h.reconfigure(u,this),null).values);let l=e.startState.facet(rx)?e.newSelection:e.newSelection.asSingle();new Fe(t,e.newDoc,l,s,(o,u)=>u.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:Y.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,r=e(t.ranges[0]),i=this.changes(r.changes),s=[r.range],l=No(r.effects);for(let o=1;o<t.ranges.length;o++){let u=e(t.ranges[o]),h=this.changes(u.changes),f=h.map(i);for(let g=0;g<o;g++)s[g]=s[g].map(f);let p=i.mapDesc(h,!0);s.push(u.range.map(p)),i=i.compose(f),l=Ne.mapEffects(l,f).concat(Ne.mapEffects(No(u.effects),p))}return{changes:i,selection:Y.create(s,t.mainIndex),effects:l}}changes(e=[]){return e instanceof Lt?e:Lt.of(e,this.doc.length,this.facet(Fe.lineSeparator))}toText(e){return Ge.of(e.split(this.facet(Fe.lineSeparator)||KO))}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:(Lu(this,t),sd(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let r in e){let i=e[r];i instanceof an&&this.config.address[i.id]!=null&&(t[r]=i.spec.toJSON(this.field(e[r]),this))}return t}static fromJSON(e,t={},r){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let i=[];if(r){for(let s in r)if(Object.prototype.hasOwnProperty.call(e,s)){let l=r[s],o=e[s];i.push(l.init(u=>l.spec.fromJSON(o,u)))}}return Fe.create({doc:e.doc,selection:Y.fromJSON(e.selection),extensions:t.extensions?i.concat([t.extensions]):i})}static create(e={}){let t=id.resolve(e.extensions||[],new Map),r=e.doc instanceof Ge?e.doc:Ge.of((e.doc||"").split(t.staticFacet(Fe.lineSeparator)||KO)),i=e.selection?e.selection instanceof Y?e.selection:Y.single(e.selection.anchor,e.selection.head):Y.single(0);return e2(i,r.length),t.staticFacet(rx)||(i=i.asSingle()),new Fe(t,r,i,t.dynamicSlots.map(()=>null),(s,l)=>l.create(s),null)}get tabSize(){return this.facet(Fe.tabSize)}get lineBreak(){return this.facet(Fe.lineSeparator)||`
71
+ `}get readOnly(){return this.facet(o2)}phrase(e,...t){for(let r of this.facet(Fe.phrases))if(Object.prototype.hasOwnProperty.call(r,e)){e=r[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(r,i)=>{if(i=="$")return"$";let s=+(i||1);return!s||s>t.length?r:t[s-1]})),e}languageDataAt(e,t,r=-1){let i=[];for(let s of this.facet(n2))for(let l of s(this,t,r))Object.prototype.hasOwnProperty.call(l,e)&&i.push(l[e]);return i}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return y5(t.length?t[0]:"")}wordAt(e){let{text:t,from:r,length:i}=this.doc.lineAt(e),s=this.charCategorizer(e),l=e-r,o=e-r;for(;l>0;){let u=Ut(t,l,!1);if(s(t.slice(u,l))!=yt.Word)break;l=u}for(;o<i;){let u=Ut(t,o);if(s(t.slice(o,u))!=yt.Word)break;o=u}return l==o?null:Y.range(l+r,o+r)}}Fe.allowMultipleSelections=rx;Fe.tabSize=ge.define({combine:n=>n.length?n[0]:4});Fe.lineSeparator=r2;Fe.readOnly=o2;Fe.phrases=ge.define({compare(n,e){let t=Object.keys(n),r=Object.keys(e);return t.length==r.length&&t.every(i=>n[i]==e[i])}});Fe.languageData=n2;Fe.changeFilter=i2;Fe.transactionFilter=s2;Fe.transactionExtender=l2;Kd.reconfigure=Ne.define();function bi(n,e,t={}){let r={};for(let i of n)for(let s of Object.keys(i)){let l=i[s],o=r[s];if(o===void 0)r[s]=l;else if(!(o===l||l===void 0))if(Object.hasOwnProperty.call(t,s))r[s]=t[s](o,l);else throw new Error("Config merge conflict for field "+s)}for(let i in e)r[i]===void 0&&(r[i]=e[i]);return r}class Xs{eq(e){return this==e}range(e,t=e){return lx.create(e,t,this)}}Xs.prototype.startSide=Xs.prototype.endSide=0;Xs.prototype.point=!1;Xs.prototype.mapMode=sn.TrackDel;function My(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}let lx=class c2{constructor(e,t,r){this.from=e,this.to=t,this.value=r}static create(e,t,r){return new c2(e,t,r)}};function ox(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class Ay{constructor(e,t,r,i){this.from=e,this.to=t,this.value=r,this.maxPoint=i}get length(){return this.to[this.to.length-1]}findIndex(e,t,r,i=0){let s=r?this.to:this.from;for(let l=i,o=s.length;;){if(l==o)return l;let u=l+o>>1,h=s[u]-e||(r?this.value[u].endSide:this.value[u].startSide)-t;if(u==l)return h>=0?l:o;h>=0?o=u:l=u+1}}between(e,t,r,i){for(let s=this.findIndex(t,-1e9,!0),l=this.findIndex(r,1e9,!1,s);s<l;s++)if(i(this.from[s]+e,this.to[s]+e,this.value[s])===!1)return!1}map(e,t){let r=[],i=[],s=[],l=-1,o=-1;for(let u=0;u<this.value.length;u++){let h=this.value[u],f=this.from[u]+e,p=this.to[u]+e,g,x;if(f==p){let k=t.mapPos(f,h.startSide,h.mapMode);if(k==null||(g=x=k,h.startSide!=h.endSide&&(x=t.mapPos(f,h.endSide),x<g)))continue}else if(g=t.mapPos(f,h.startSide),x=t.mapPos(p,h.endSide),g>x||g==x&&h.startSide>0&&h.endSide<=0)continue;(x-g||h.endSide-h.startSide)<0||(l<0&&(l=g),h.point&&(o=Math.max(o,x-g)),r.push(h),i.push(g-l),s.push(x-l))}return{mapped:r.length?new Ay(i,s,r,o):null,pos:l}}}class We{constructor(e,t,r,i){this.chunkPos=e,this.chunk=t,this.nextLayer=r,this.maxPoint=i}static create(e,t,r,i){return new We(e,t,r,i)}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:r=!1,filterFrom:i=0,filterTo:s=this.length}=e,l=e.filter;if(t.length==0&&!l)return this;if(r&&(t=t.slice().sort(ox)),this.isEmpty)return t.length?We.of(t):this;let o=new h2(this,null,-1).goto(0),u=0,h=[],f=new qi;for(;o.value||u<t.length;)if(u<t.length&&(o.from-t[u].from||o.startSide-t[u].value.startSide)>=0){let p=t[u++];f.addInner(p.from,p.to,p.value)||h.push(p)}else o.rangeIndex==1&&o.chunkIndex<this.chunk.length&&(u==t.length||this.chunkEnd(o.chunkIndex)<t[u].from)&&(!l||i>this.chunkEnd(o.chunkIndex)||s<this.chunkPos[o.chunkIndex])&&f.addChunk(this.chunkPos[o.chunkIndex],this.chunk[o.chunkIndex])?o.nextChunk():((!l||i>o.to||s<o.from||l(o.from,o.to,o.value))&&(f.addInner(o.from,o.to,o.value)||h.push(lx.create(o.from,o.to,o.value))),o.next());return f.finishInner(this.nextLayer.isEmpty&&!h.length?We.empty:this.nextLayer.update({add:h,filter:l,filterFrom:i,filterTo:s}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],r=[],i=-1;for(let l=0;l<this.chunk.length;l++){let o=this.chunkPos[l],u=this.chunk[l],h=e.touchesRange(o,o+u.length);if(h===!1)i=Math.max(i,u.maxPoint),t.push(u),r.push(e.mapPos(o));else if(h===!0){let{mapped:f,pos:p}=u.map(o,e);f&&(i=Math.max(i,f.maxPoint),t.push(f),r.push(p))}}let s=this.nextLayer.map(e);return t.length==0?s:new We(r,t,s||We.empty,i)}between(e,t,r){if(!this.isEmpty){for(let i=0;i<this.chunk.length;i++){let s=this.chunkPos[i],l=this.chunk[i];if(t>=s&&e<=s+l.length&&l.between(s,e-s,t-s,r)===!1)return}this.nextLayer.between(e,t,r)}}iter(e=0){return Ku.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ku.from(e).goto(t)}static compare(e,t,r,i,s=-1){let l=e.filter(p=>p.maxPoint>0||!p.isEmpty&&p.maxPoint>=s),o=t.filter(p=>p.maxPoint>0||!p.isEmpty&&p.maxPoint>=s),u=yb(l,o,r),h=new Ou(l,u,s),f=new Ou(o,u,s);r.iterGaps((p,g,x)=>kb(h,p,f,g,x,i)),r.empty&&r.length==0&&kb(h,0,f,0,0,i)}static eq(e,t,r=0,i){i==null&&(i=999999999);let s=e.filter(f=>!f.isEmpty&&t.indexOf(f)<0),l=t.filter(f=>!f.isEmpty&&e.indexOf(f)<0);if(s.length!=l.length)return!1;if(!s.length)return!0;let o=yb(s,l),u=new Ou(s,o,0).goto(r),h=new Ou(l,o,0).goto(r);for(;;){if(u.to!=h.to||!ax(u.active,h.active)||u.point&&(!h.point||!My(u.point,h.point)))return!1;if(u.to>i)return!0;u.next(),h.next()}}static spans(e,t,r,i,s=-1){let l=new Ou(e,null,s).goto(t),o=t,u=l.openStart;for(;;){let h=Math.min(l.to,r);if(l.point){let f=l.activeForPoint(l.to),p=l.pointFrom<t?f.length+1:l.point.startSide<0?f.length:Math.min(f.length,u);i.point(o,h,l.point,f,p,l.pointRank),u=Math.min(l.openEnd(h),f.length)}else h>o&&(i.span(o,h,l.active,u),u=l.openEnd(h));if(l.to>r)return u+(l.point&&l.to>r?1:0);o=l.to,l.next()}}static of(e,t=!1){let r=new qi;for(let i of e instanceof lx?[e]:t?k5(e):e)r.add(i.from,i.to,i.value);return r.finish()}static join(e){if(!e.length)return We.empty;let t=e[e.length-1];for(let r=e.length-2;r>=0;r--)for(let i=e[r];i!=We.empty;i=i.nextLayer)t=new We(i.chunkPos,i.chunk,t,Math.max(i.maxPoint,t.maxPoint));return t}}We.empty=new We([],[],null,-1);function k5(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let r=n[t];if(ox(e,r)>0)return n.slice().sort(ox);e=r}return n}We.empty.nextLayer=We.empty;class qi{finishChunk(e){this.chunks.push(new Ay(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=[])}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}add(e,t,r){this.addInner(e,t,r)||(this.nextLayer||(this.nextLayer=new qi)).add(e,t,r)}addInner(e,t,r){let i=e-this.lastTo||r.startSide-this.last.endSide;if(i<=0&&(e-this.lastFrom||r.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return i<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=r,this.lastFrom=e,this.lastTo=t,this.value.push(r),r.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 r=t.value.length-1;return this.last=t.value[r],this.lastFrom=t.from[r]+e,this.lastTo=t.to[r]+e,!0}finish(){return this.finishInner(We.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=We.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function yb(n,e,t){let r=new Map;for(let s of n)for(let l=0;l<s.chunk.length;l++)s.chunk[l].maxPoint<=0&&r.set(s.chunk[l],s.chunkPos[l]);let i=new Set;for(let s of e)for(let l=0;l<s.chunk.length;l++){let o=r.get(s.chunk[l]);o!=null&&(t?t.mapPos(o):o)==s.chunkPos[l]&&!(t!=null&&t.touchesRange(o,o+s.chunk[l].length))&&i.add(s.chunk[l])}return i}class h2{constructor(e,t,r,i=0){this.layer=e,this.skip=t,this.minPoint=r,this.rank=i}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,r){for(;this.chunkIndex<this.layer.chunk.length;){let i=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(i)||this.layer.chunkEnd(this.chunkIndex)<e||i.maxPoint<this.minPoint))break;this.chunkIndex++,r=!1}if(this.chunkIndex<this.layer.chunk.length){let i=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!r||this.rangeIndex<i)&&this.setRangeIndex(i)}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],r=e+t.from[this.rangeIndex];if(this.from=r,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}}class Ku{constructor(e){this.heap=e}static from(e,t=null,r=-1){let i=[];for(let s=0;s<e.length;s++)for(let l=e[s];!l.isEmpty;l=l.nextLayer)l.maxPoint>=r&&i.push(new h2(l,t,r,s));return i.length==1?i[0]:new Ku(i)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let r of this.heap)r.goto(e,t);for(let r=this.heap.length>>1;r>=0;r--)Og(this.heap,r);return this.next(),this}forward(e,t){for(let r of this.heap)r.forward(e,t);for(let r=this.heap.length>>1;r>=0;r--)Og(this.heap,r);(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(),Og(this.heap,0)}}}function Og(n,e){for(let t=n[e];;){let r=(e<<1)+1;if(r>=n.length)break;let i=n[r];if(r+1<n.length&&i.compare(n[r+1])>=0&&(i=n[r+1],r++),t.compare(i)<0)break;n[r]=t,n[e]=i,e=r}}class Ou{constructor(e,t,r){this.minPoint=r,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=Ku.from(e,t,r)}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){af(this.active,e),af(this.activeTo,e),af(this.activeRank,e),this.minActive=vb(this.active,this.activeTo)}addActive(e){let t=0,{value:r,to:i,rank:s}=this.cursor;for(;t<this.activeRank.length&&(s-this.activeRank[t]||i-this.activeTo[t])>0;)t++;uf(this.active,t,r),uf(this.activeTo,t,i),uf(this.activeRank,t,s),e&&uf(e,t,this.cursor.from),this.minActive=vb(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let r=this.openStart<0?[]:null;for(;;){let i=this.minActive;if(i>-1&&(this.activeTo[i]-this.cursor.from||this.active[i].endSide-this.cursor.startSide)<0){if(this.activeTo[i]>e){this.to=this.activeTo[i],this.endSide=this.active[i].endSide;break}this.removeActive(i),r&&af(r,i)}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(r),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(r){this.openStart=0;for(let i=r.length-1;i>=0&&r[i]<e;i--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let r=this.active.length-1;r>=0&&!(this.activeRank[r]<this.pointRank);r--)(this.activeTo[r]>e||this.activeTo[r]==e&&this.active[r].endSide>=this.point.endSide)&&t.push(this.active[r]);return t.reverse()}openEnd(e){let t=0;for(let r=this.activeTo.length-1;r>=0&&this.activeTo[r]>e;r--)t++;return t}}function kb(n,e,t,r,i,s){n.goto(e),t.goto(r);let l=r+i,o=r,u=r-e,h=!!s.boundChange;for(let f=!1;;){let p=n.to+u-t.to,g=p||n.endSide-t.endSide,x=g<0?n.to+u:t.to,k=Math.min(x,l);if(n.point||t.point?(n.point&&t.point&&My(n.point,t.point)&&ax(n.activeForPoint(n.to),t.activeForPoint(t.to))||s.comparePoint(o,k,n.point,t.point),f=!1):(f&&s.boundChange(o),k>o&&!ax(n.active,t.active)&&s.compareRange(o,k,n.active,t.active),h&&k<l&&(p||n.openEnd(x)!=t.openEnd(x))&&(f=!0)),x>l)break;o=x,g<=0&&n.next(),g>=0&&t.next()}}function ax(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!My(n[t],e[t]))return!1;return!0}function af(n,e){for(let t=e,r=n.length-1;t<r;t++)n[t]=n[t+1];n.pop()}function uf(n,e,t){for(let r=n.length-1;r>=e;r--)n[r+1]=n[r];n[e]=t}function vb(n,e){let t=-1,r=1e9;for(let i=0;i<e.length;i++)(e[i]-r||n[i].endSide-n[t].endSide)<0&&(t=i,r=e[i]);return t}function Wr(n,e,t=n.length){let r=0;for(let i=0;i<t&&i<n.length;)n.charCodeAt(i)==9?(r+=e-r%e,i++):(r++,i=Ut(n,i));return r}function ux(n,e,t,r){for(let i=0,s=0;;){if(s>=e)return i;if(i==n.length)break;s+=n.charCodeAt(i)==9?t-s%t:1,i=Ut(n,i)}return r===!0?-1:n.length}const cx="ͼ",bb=typeof Symbol>"u"?"__"+cx:Symbol.for(cx),hx=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),wb=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class Bs{constructor(e,t){this.rules=[];let{finish:r}=t||{};function i(l){return/^@/.test(l)?[l]:l.split(/,\s*/)}function s(l,o,u,h){let f=[],p=/^@(\w+)\b/.exec(l[0]),g=p&&p[1]=="keyframes";if(p&&o==null)return u.push(l[0]+";");for(let x in o){let k=o[x];if(/&/.test(x))s(x.split(/,\s*/).map(b=>l.map(w=>b.replace(/&/,w))).reduce((b,w)=>b.concat(w)),k,u);else if(k&&typeof k=="object"){if(!p)throw new RangeError("The value of a property ("+x+") should be a primitive value.");s(i(x),k,f,g)}else k!=null&&f.push(x.replace(/_.*/,"").replace(/[A-Z]/g,b=>"-"+b.toLowerCase())+": "+k+";")}(f.length||g)&&u.push((r&&!p&&!h?l.map(r):l).join(", ")+" {"+f.join(" ")+"}")}for(let l in e)s(i(l),e[l],this.rules)}getRules(){return this.rules.join(`
72
+ `)}static newName(){let e=wb[bb]||1;return wb[bb]=e+1,cx+e.toString(36)}static mount(e,t,r){let i=e[hx],s=r&&r.nonce;i?s&&i.setNonce(s):i=new v5(e,s),i.mount(Array.isArray(t)?t:[t],e)}}let Sb=new Map;class v5{constructor(e,t){let r=e.ownerDocument||e,i=r.defaultView;if(!e.head&&e.adoptedStyleSheets&&i.CSSStyleSheet){let s=Sb.get(r);if(s)return e[hx]=s;this.sheet=new i.CSSStyleSheet,Sb.set(r,this)}else this.styleTag=r.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[hx]=this}mount(e,t){let r=this.sheet,i=0,s=0;for(let l=0;l<e.length;l++){let o=e[l],u=this.modules.indexOf(o);if(u<s&&u>-1&&(this.modules.splice(u,1),s--,u=-1),u==-1){if(this.modules.splice(s++,0,o),r)for(let h=0;h<o.rules.length;h++)r.insertRule(o.rules[h],i++)}else{for(;s<u;)i+=this.modules[s++].rules.length;i+=o.rules.length,s++}}if(r)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let l="";for(let u=0;u<this.modules.length;u++)l+=this.modules[u].getRules()+`
73
+ `;this.styleTag.textContent=l;let o=t.head||t;this.styleTag.parentNode!=o&&o.insertBefore(this.styleTag,o.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var Ws={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:"'"},Ju={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},b5=typeof navigator<"u"&&/Mac/.test(navigator.platform),w5=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var rn=0;rn<10;rn++)Ws[48+rn]=Ws[96+rn]=String(rn);for(var rn=1;rn<=24;rn++)Ws[rn+111]="F"+rn;for(var rn=65;rn<=90;rn++)Ws[rn]=String.fromCharCode(rn+32),Ju[rn]=String.fromCharCode(rn);for(var xg in Ws)Ju.hasOwnProperty(xg)||(Ju[xg]=Ws[xg]);function S5(n){var e=b5&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||w5&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Ju:Ws)[n.keyCode]||n.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 lt(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var r in t)if(Object.prototype.hasOwnProperty.call(t,r)){var i=t[r];typeof i=="string"?n.setAttribute(r,i):i!=null&&(n[r]=i)}e++}for(;e<arguments.length;e++)f2(n,arguments[e]);return n}function f2(n,e){if(typeof e=="string")n.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)n.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)f2(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}let Cn=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},fx=typeof document<"u"?document:{documentElement:{style:{}}};const dx=/Edge\/(\d+)/.exec(Cn.userAgent),d2=/MSIE \d/.test(Cn.userAgent),px=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Cn.userAgent),Jd=!!(d2||px||dx),Pb=!Jd&&/gecko\/(\d+)/i.test(Cn.userAgent),yg=!Jd&&/Chrome\/(\d+)/.exec(Cn.userAgent),Cb="webkitFontSmoothing"in fx.documentElement.style,mx=!Jd&&/Apple Computer/.test(Cn.vendor),Qb=mx&&(/Mobile\/\w+/.test(Cn.userAgent)||Cn.maxTouchPoints>2);var xe={mac:Qb||/Mac/.test(Cn.platform),windows:/Win/.test(Cn.platform),linux:/Linux|X11/.test(Cn.platform),ie:Jd,ie_version:d2?fx.documentMode||6:px?+px[1]:dx?+dx[1]:0,gecko:Pb,gecko_version:Pb?+(/Firefox\/(\d+)/.exec(Cn.userAgent)||[0,0])[1]:0,chrome:!!yg,chrome_version:yg?+yg[1]:0,ios:Qb,android:/Android\b/.test(Cn.userAgent),webkit:Cb,webkit_version:Cb?+(/\bAppleWebKit\/(\d+)/.exec(Cn.userAgent)||[0,0])[1]:0,safari:mx,safari_version:mx?+(/\bVersion\/(\d+(\.\d+)?)/.exec(Cn.userAgent)||[0,0])[1]:0,tabSize:fx.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function Ry(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const ld=Object.create(null);function Ny(n,e,t){if(n==e)return!0;n||(n=ld),e||(e=ld);let r=Object.keys(n),i=Object.keys(e);if(r.length-0!=i.length-0)return!1;for(let s of r)if(s!=t&&(i.indexOf(s)==-1||n[s]!==e[s]))return!1;return!0}function P5(n,e){for(let t=n.attributes.length-1;t>=0;t--){let r=n.attributes[t].name;e[r]==null&&n.removeAttribute(r)}for(let t in e){let r=e[t];t=="style"?n.style.cssText=r:n.getAttribute(t)!=r&&n.setAttribute(t,r)}}function $b(n,e,t){let r=!1;if(e)for(let i in e)t&&i in t||(r=!0,i=="style"?n.style.cssText="":n.removeAttribute(i));if(t)for(let i in t)e&&e[i]==t[i]||(r=!0,i=="style"?n.style.cssText=t[i]:n.setAttribute(i,t[i]));return r}function C5(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let r=n.attributes[t];e[r.name]=r.value}return e}class Vr{eq(e){return!1}updateDOM(e,t,r){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,r){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var ln=(function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n})(ln||(ln={}));class $e extends Xs{constructor(e,t,r,i){super(),this.startSide=e,this.endSide=t,this.widget=r,this.spec=i}get heightRelevant(){return!1}static mark(e){return new Ac(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),r=!!e.block;return t+=r&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new zl(e,t,t,r,e.widget||null,!1)}static replace(e){let t=!!e.block,r,i;if(e.isBlockGap)r=-5e8,i=4e8;else{let{start:s,end:l}=p2(e,t);r=(s?t?-3e8:-1:5e8)-1,i=(l?t?2e8:1:-6e8)+1}return new zl(e,r,i,t,e.widget||null,!0)}static line(e){return new Rc(e)}static set(e,t=!1){return We.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}$e.none=We.empty;class Ac extends $e{constructor(e){let{start:t,end:r}=p2(e);super(t?-1:5e8,r?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?Ry(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||ld}eq(e){return this==e||e instanceof Ac&&this.tagName==e.tagName&&Ny(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)}}Ac.prototype.point=!1;class Rc extends $e{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof Rc&&this.spec.class==e.spec.class&&Ny(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)}}Rc.prototype.mapMode=sn.TrackBefore;Rc.prototype.point=!0;class zl extends $e{constructor(e,t,r,i,s,l){super(t,r,s,e),this.block=i,this.isReplace=l,this.mapMode=i?t<=0?sn.TrackBefore:sn.TrackAfter:sn.TrackDel}get type(){return this.startSide!=this.endSide?ln.WidgetRange:this.startSide<=0?ln.WidgetBefore:ln.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof zl&&Q5(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)}}zl.prototype.point=!0;function p2(n,e=!1){let{inclusiveStart:t,inclusiveEnd:r}=n;return t==null&&(t=n.inclusive),r==null&&(r=n.inclusive),{start:t??e,end:r??e}}function Q5(n,e){return n==e||!!(n&&e&&n.compare(e))}function Lo(n,e,t,r=0){let i=t.length-1;i>=0&&t[i]+r>=n?t[i]=Math.max(t[i],e):t.push(n,e)}class ec extends Xs{constructor(e,t,r){super(),this.tagName=e,this.attributes=t,this.rank=r}eq(e){return e==this||e instanceof ec&&this.tagName==e.tagName&&Ny(this.attributes,e.attributes)}static create(e){return new ec(e.tagName,e.attributes||ld,e.rank==null?50:Math.max(0,Math.min(e.rank,100)))}static set(e,t=!1){return We.of(e,t)}}ec.prototype.startSide=ec.prototype.endSide=-1;function tc(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function gx(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function _u(n,e){if(!e.anchorNode)return!1;try{return gx(n,e.anchorNode)}catch{return!1}}function Du(n){return n.nodeType==3?rc(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Iu(n,e,t,r){return t?Tb(n,e,t,r,-1)||Tb(n,e,t,r,1):!1}function qs(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function od(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Tb(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:Vi(n))){if(n.nodeName=="DIV")return!1;let s=n.parentNode;if(!s||s.nodeType!=1)return!1;e=qs(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=i<0?Vi(n):0}else return!1}}function Vi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function nc(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function $5(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function m2(n,e){let t=e.width/n.offsetWidth,r=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(r>.995&&r<1.005||!isFinite(r)||Math.abs(e.height-n.offsetHeight)<1)&&(r=1),{scaleX:t,scaleY:r}}function T5(n,e,t,r,i,s,l,o){let u=n.ownerDocument,h=u.defaultView||window;for(let f=n,p=!1;f&&!p;)if(f.nodeType==1){let g,x=f==u.body,k=1,b=1;if(x)g=$5(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(f).position)&&(p=!0),f.scrollHeight<=f.clientHeight&&f.scrollWidth<=f.clientWidth){f=f.assignedSlot||f.parentNode;continue}let Q=f.getBoundingClientRect();({scaleX:k,scaleY:b}=m2(f,Q)),g={left:Q.left,right:Q.left+f.clientWidth*k,top:Q.top,bottom:Q.top+f.clientHeight*b}}let w=0,S=0;if(i=="nearest")e.top<g.top+l?(S=e.top-(g.top+l),t>0&&e.bottom>g.bottom+S&&(S=e.bottom-g.bottom+l)):e.bottom>g.bottom-l&&(S=e.bottom-g.bottom+l,t<0&&e.top-S<g.top&&(S=e.top-(g.top+l)));else{let Q=e.bottom-e.top,$=g.bottom-g.top;S=(i=="center"&&Q<=$?e.top+Q/2-$/2:i=="start"||i=="center"&&t<0?e.top-l:e.bottom-$+l)-g.top}if(r=="nearest"?e.left<g.left+s?(w=e.left-(g.left+s),t>0&&e.right>g.right+w&&(w=e.right-g.right+s)):e.right>g.right-s&&(w=e.right-g.right+s,t<0&&e.left<g.left+w&&(w=e.left-(g.left+s))):w=(r=="center"?e.left+(e.right-e.left)/2-(g.right-g.left)/2:r=="start"==o?e.left-s:e.right-(g.right-g.left)+s)-g.left,w||S)if(x)h.scrollBy(w,S);else{let Q=0,$=0;if(S){let R=f.scrollTop;f.scrollTop+=S/b,$=(f.scrollTop-R)*b}if(w){let R=f.scrollLeft;f.scrollLeft+=w/k,Q=(f.scrollLeft-R)*k}e={left:e.left-Q,top:e.top-$,right:e.right-Q,bottom:e.bottom-$},Q&&Math.abs(Q-w)<1&&(r="nearest"),$&&Math.abs($-S)<1&&(i="nearest")}if(x)break;(e.top<g.top||e.bottom>g.bottom||e.left<g.left||e.right>g.right)&&(e={left:Math.max(e.left,g.left),right:Math.min(e.right,g.right),top:Math.max(e.top,g.top),bottom:Math.min(e.bottom,g.bottom)}),f=f.assignedSlot||f.parentNode}else if(f.nodeType==11)f=f.host;else break}function g2(n,e=!0){let t=n.ownerDocument,r=null,i=null;for(let s=n.parentNode;s&&!(s==t.body||(!e||r)&&i);)if(s.nodeType==1)!i&&s.scrollHeight>s.clientHeight&&(i=s),e&&!r&&s.scrollWidth>s.clientWidth&&(r=s),s=s.assignedSlot||s.parentNode;else if(s.nodeType==11)s=s.host;else break;return{x:r,y:i}}class j5{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){let{anchorNode:t,focusNode:r}=e;this.set(t,Math.min(e.anchorOffset,t?Vi(t):0),r,Math.min(e.focusOffset,r?Vi(r):0))}set(e,t,r,i){this.anchorNode=e,this.anchorOffset=t,this.focusNode=r,this.focusOffset=i}}let Ol=null;xe.safari&&xe.safari_version>=26&&(Ol=!1);function O2(n){if(n.setActive)return n.setActive();if(Ol)return n.focus(Ol);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(Ol==null?{get preventScroll(){return Ol={preventScroll:!0},!0}}:void 0),!Ol){Ol=!1;for(let t=0;t<e.length;){let r=e[t++],i=e[t++],s=e[t++];r.scrollTop!=i&&(r.scrollTop=i),r.scrollLeft!=s&&(r.scrollLeft=s)}}}let jb;function rc(n,e,t=e){let r=jb||(jb=document.createRange());return r.setEnd(n,t),r.setStart(n,e),r}function _o(n,e,t,r){let i={key:e,code:e,keyCode:t,which:t,cancelable:!0};r&&({altKey:i.altKey,ctrlKey:i.ctrlKey,shiftKey:i.shiftKey,metaKey:i.metaKey}=r);let s=new KeyboardEvent("keydown",i);s.synthetic=!0,n.dispatchEvent(s);let l=new KeyboardEvent("keyup",i);return l.synthetic=!0,n.dispatchEvent(l),s.defaultPrevented||l.defaultPrevented}function E5(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function M5(n,e){let t=e.focusNode,r=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=r)return!1;for(r=Math.min(r,Vi(t));;)if(r){if(t.nodeType!=1)return!1;let i=t.childNodes[r-1];i.contentEditable=="false"?r--:(t=i,r=Vi(t))}else{if(t==n)return!0;r=qs(t),t=t.parentNode}}function x2(n){return n instanceof Window?n.pageYOffset>Math.max(0,n.document.documentElement.scrollHeight-n.innerHeight-4):n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function y2(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r>0)return{node:t,offset:r};if(t.nodeType==1&&r>0){if(t.contentEditable=="false")return null;t=t.childNodes[r-1],r=Vi(t)}else if(t.parentNode&&!od(t))r=qs(t),t=t.parentNode;else return null}}function k2(n,e){for(let t=n,r=e;;){if(t.nodeType==3&&r<t.nodeValue.length)return{node:t,offset:r};if(t.nodeType==1&&r<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[r],r=0}else if(t.parentNode&&!od(t))r=qs(t)+1,t=t.parentNode;else return null}}class Xr{constructor(e,t,r=!0){this.node=e,this.offset=t,this.precise=r}static before(e,t){return new Xr(e.parentNode,qs(e),t)}static after(e,t){return new Xr(e.parentNode,qs(e)+1,t)}}var ht=(function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n})(ht||(ht={}));const Zl=ht.LTR,Ly=ht.RTL;function v2(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const A5=v2("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),R5=v2("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Ox=Object.create(null),ni=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);Ox[e]=t,Ox[t]=-e}function b2(n){return n<=247?A5[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?R5[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const N5=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class di{get dir(){return this.level%2?Ly:Zl}constructor(e,t,r){this.from=e,this.to=t,this.level=r}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,r,i){let s=-1;for(let l=0;l<e.length;l++){let o=e[l];if(o.from<=t&&o.to>=t){if(o.level==r)return l;(s<0||(i!=0?i<0?o.from<t:o.to>t:e[s].level>o.level))&&(s=l)}}if(s<0)throw new RangeError("Index out of range");return s}}function w2(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let r=n[t],i=e[t];if(r.from!=i.from||r.to!=i.to||r.direction!=i.direction||!w2(r.inner,i.inner))return!1}return!0}const ct=[];function L5(n,e,t,r,i){for(let s=0;s<=r.length;s++){let l=s?r[s-1].to:e,o=s<r.length?r[s].from:t,u=s?256:i;for(let h=l,f=u,p=u;h<o;h++){let g=b2(n.charCodeAt(h));g==512?g=f:g==8&&p==4&&(g=16),ct[h]=g==4?2:g,g&7&&(p=g),f=g}for(let h=l,f=u,p=u;h<o;h++){let g=ct[h];if(g==128)h<o-1&&f==ct[h+1]&&f&24?g=ct[h]=f:ct[h]=256;else if(g==64){let x=h+1;for(;x<o&&ct[x]==64;)x++;let k=h&&f==8||x<t&&ct[x]==8?p==1?1:8:256;for(let b=h;b<x;b++)ct[b]=k;h=x-1}else g==8&&p==1&&(ct[h]=1);f=g,g&7&&(p=g)}}}function _5(n,e,t,r,i){let s=i==1?2:1;for(let l=0,o=0,u=0;l<=r.length;l++){let h=l?r[l-1].to:e,f=l<r.length?r[l].from:t;for(let p=h,g,x,k;p<f;p++)if(x=Ox[g=n.charCodeAt(p)])if(x<0){for(let b=o-3;b>=0;b-=3)if(ni[b+1]==-x){let w=ni[b+2],S=w&2?i:w&4?w&1?s:i:0;S&&(ct[p]=ct[ni[b]]=S),o=b;break}}else{if(ni.length==189)break;ni[o++]=p,ni[o++]=g,ni[o++]=u}else if((k=ct[p])==2||k==1){let b=k==i;u=b?0:1;for(let w=o-3;w>=0;w-=3){let S=ni[w+2];if(S&2)break;if(b)ni[w+2]|=2;else{if(S&4)break;ni[w+2]|=4}}}}}function D5(n,e,t,r){for(let i=0,s=r;i<=t.length;i++){let l=i?t[i-1].to:n,o=i<t.length?t[i].from:e;for(let u=l;u<o;){let h=ct[u];if(h==256){let f=u+1;for(;;)if(f==o){if(i==t.length)break;f=t[i++].to,o=i<t.length?t[i].from:e}else if(ct[f]==256)f++;else break;let p=s==1,g=(f<e?ct[f]:r)==1,x=p==g?p?1:2:r;for(let k=f,b=i,w=b?t[b-1].to:n;k>u;)k==w&&(k=t[--b].from,w=b?t[b-1].to:n),ct[--k]=x;u=f}else s=h,u++}}}function xx(n,e,t,r,i,s,l){let o=r%2?2:1;if(r%2==i%2)for(let u=e,h=0;u<t;){let f=!0,p=!1;if(h==s.length||u<s[h].from){let b=ct[u];b!=o&&(f=!1,p=b==16)}let g=!f&&o==1?[]:null,x=f?r:r+1,k=u;e:for(;;)if(h<s.length&&k==s[h].from){if(p)break e;let b=s[h];if(!f)for(let w=b.to,S=h+1;;){if(w==t)break e;if(S<s.length&&s[S].from==w)w=s[S++].to;else{if(ct[w]==o)break e;break}}if(h++,g)g.push(b);else{b.from>u&&l.push(new di(u,b.from,x));let w=b.direction==Zl!=!(x%2);yx(n,w?r+1:r,i,b.inner,b.from,b.to,l),u=b.to}k=b.to}else{if(k==t||(f?ct[k]!=o:ct[k]==o))break;k++}g?xx(n,u,k,r+1,i,g,l):u<k&&l.push(new di(u,k,x)),u=k}else for(let u=t,h=s.length;u>e;){let f=!0,p=!1;if(!h||u>s[h-1].to){let b=ct[u-1];b!=o&&(f=!1,p=b==16)}let g=!f&&o==1?[]:null,x=f?r:r+1,k=u;e:for(;;)if(h&&k==s[h-1].to){if(p)break e;let b=s[--h];if(!f)for(let w=b.from,S=h;;){if(w==e)break e;if(S&&s[S-1].to==w)w=s[--S].from;else{if(ct[w-1]==o)break e;break}}if(g)g.push(b);else{b.to<u&&l.push(new di(b.to,u,x));let w=b.direction==Zl!=!(x%2);yx(n,w?r+1:r,i,b.inner,b.from,b.to,l),u=b.from}k=b.from}else{if(k==e||(f?ct[k-1]!=o:ct[k-1]==o))break;k--}g?xx(n,k,u,r+1,i,g,l):k<u&&l.push(new di(k,u,x)),u=k}}function yx(n,e,t,r,i,s,l){let o=e%2?2:1;L5(n,i,s,r,o),_5(n,i,s,r,o),D5(i,s,r,o),xx(n,i,s,e,t,r,l)}function I5(n,e,t){if(!n)return[new di(0,0,e==Ly?1:0)];if(e==Zl&&!t.length&&!N5.test(n))return S2(n.length);if(t.length)for(;n.length>ct.length;)ct[ct.length]=256;let r=[],i=e==Zl?0:1;return yx(n,i,i,t,0,n.length,r),r}function S2(n){return[new di(0,n,0)]}let P2="";function z5(n,e,t,r,i){var s;let l=r.head-n.from,o=di.find(e,l,(s=r.bidiLevel)!==null&&s!==void 0?s:-1,r.assoc),u=e[o],h=u.side(i,t);if(l==h){let g=o+=i?1:-1;if(g<0||g>=e.length)return null;u=e[o=g],l=u.side(!i,t),h=u.side(i,t)}let f=Ut(n.text,l,u.forward(i,t));(f<u.from||f>u.to)&&(f=h),P2=n.text.slice(Math.min(l,f),Math.max(l,f));let p=o==(i?e.length-1:0)?null:e[o+(i?1:-1)];return p&&f==h&&p.level+(i?0:1)<u.level?Y.cursor(p.side(!i,t)+n.from,p.forward(i,t)?1:-1,p.level):Y.cursor(f+n.from,u.forward(i,t)?-1:1,u.level)}function Z5(n,e,t){for(let r=e;r<t;r++){let i=b2(n.charCodeAt(r));if(i==1)return Zl;if(i==2||i==4)return Ly}return Zl}const C2=ge.define(),Q2=ge.define(),$2=ge.define(),T2=ge.define(),kx=ge.define(),j2=ge.define(),E2=ge.define(),_y=ge.define(),Dy=ge.define(),M2=ge.define({combine:n=>n.some(e=>e)}),A2=ge.define({combine:n=>n.some(e=>e)}),R2=ge.define();class Do{constructor(e,t,r,i,s,l=!1){this.range=e,this.y=t,this.x=r,this.yMargin=i,this.xMargin=s,this.isSnapshot=l}map(e){return e.empty?this:new Do(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new Do(Y.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const cf=Ne.define({map:(n,e)=>n.map(e)}),N2=Ne.define();function Xn(n,e,t){let r=n.facet(T2);r.length?r[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const Zi=ge.define({combine:n=>n.length?n[0]:!0});let X5=0;const Mo=ge.define({combine(n){return n.filter((e,t)=>{for(let r=0;r<t;r++)if(n[r].plugin==e.plugin)return!1;return!0})}});class Ct{constructor(e,t,r,i,s){this.id=e,this.create=t,this.domEventHandlers=r,this.domEventObservers=i,this.baseExtensions=s(this),this.extension=this.baseExtensions.concat(Mo.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Mo.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:r,eventObservers:i,provide:s,decorations:l}=t||{};return new Ct(X5++,e,r,i,o=>{let u=[];return l&&u.push(ep.of(h=>{let f=h.plugin(o);return f?l(f):$e.none})),s&&u.push(s(o)),u})}static fromClass(e,t){return Ct.define((r,i)=>new e(r,i),t)}}class kg{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}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(r){if(Xn(t.state,r,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){Xn(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(r){Xn(e.state,r,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const L2=ge.define(),Iy=ge.define(),ep=ge.define(),_2=ge.define(),zy=ge.define(),Nc=ge.define(),D2=ge.define();function Eb(n,e){let t=n.state.facet(D2);if(!t.length)return t;let r=t.map(s=>s instanceof Function?s(n):s),i=[];return We.spans(r,e.from,e.to,{point(){},span(s,l,o,u){let h=s-e.from,f=l-e.from,p=i;for(let g=o.length-1;g>=0;g--,u--){let x=o[g].spec.bidiIsolate,k;if(x==null&&(x=Z5(e.text,h,f)),u>0&&p.length&&(k=p[p.length-1]).to==h&&k.direction==x)k.to=f,p=k.inner;else{let b={from:h,to:f,direction:x,inner:[]};p.push(b),p=b.inner}}}}),i}const I2=ge.define();function Zy(n){let e=0,t=0,r=0,i=0;for(let s of n.state.facet(I2)){let l=s(n);l&&(l.left!=null&&(e=Math.max(e,l.left)),l.right!=null&&(t=Math.max(t,l.right)),l.top!=null&&(r=Math.max(r,l.top)),l.bottom!=null&&(i=Math.max(i,l.bottom)))}return{left:e,right:t,top:r,bottom:i}}const Eu=ge.define();class Sr{constructor(e,t,r,i){this.fromA=e,this.toA=t,this.fromB=r,this.toB=i}join(e){return new Sr(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,r=this;for(;t>0;t--){let i=e[t-1];if(!(i.fromA>r.toA)){if(i.toA<r.fromA)break;r=r.join(i),e.splice(t-1,1)}}return e.splice(t,0,r),e}static extendWithRanges(e,t){if(t.length==0)return e;let r=[];for(let i=0,s=0,l=0;;){let o=i<e.length?e[i].fromB:1e9,u=s<t.length?t[s]:1e9,h=Math.min(o,u);if(h==1e9)break;let f=h+l,p=h,g=f;for(;;)if(s<t.length&&t[s]<=p){let x=t[s+1];s+=2,p=Math.max(p,x);for(let k=i;k<e.length&&e[k].fromB<=p;k++)l=e[k].toA-e[k].toB;g=Math.max(g,x+l)}else if(i<e.length&&e[i].fromB<=p){let x=e[i++];p=Math.max(p,x.toB),g=Math.max(g,x.toA),l=x.toA-x.toB}else break;r.push(new Sr(f,g,h,p))}return r}}class ad{constructor(e,t,r){this.view=e,this.state=t,this.transactions=r,this.flags=0,this.startState=e.state,this.changes=Lt.empty(this.startState.doc.length);for(let s of r)this.changes=this.changes.compose(s.changes);let i=[];this.changes.iterChangedRanges((s,l,o,u)=>i.push(new Sr(s,l,o,u))),this.changedRanges=i}static create(e,t,r){return new ad(e,t,r)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>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}}const B5=[];class Pt{constructor(e,t,r=0){this.dom=e,this.length=t,this.flags=r,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return B5}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&P5(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let r=t;for(let i of this.children){if(i==e)return r;r+=i.length+i.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let r=qs(this.dom),i=this.length?e>0:t>0;return new Xr(this.parent.dom,r+(i?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof np)return e;return null}static get(e){return e.cmTile}}class tp extends Pt{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,r=null,i,s=(e==null?void 0:e.node)==t?e:null,l=0;for(let o of this.children){if(o.sync(e),l+=o.length+o.breakAfter,i=r?r.nextSibling:t.firstChild,s&&i!=o.dom&&(s.written=!0),o.dom.parentNode==t)for(;i&&i!=o.dom;)i=Mb(i);else t.insertBefore(o.dom,i);r=o.dom}for(i=r?r.nextSibling:t.firstChild,s&&i&&(s.written=!0);i;)i=Mb(i);this.length=l}}function Mb(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class np extends tp{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=Pt.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],r=this,i=0,s=0;;)if(i==r.children.length){if(!t.length)return;r=r.parent,r.breakAfter&&s++,i=t.pop()}else{let l=r.children[i++];if(l instanceof Xi)t.push(i),r=l,i=0;else{let o=s+l.length,u=e(l,s);if(u!==void 0)return u;s=o+l.breakAfter}}}resolveBlock(e,t){let r,i=-1,s,l=-1;if(this.blockTiles((o,u)=>{let h=u+o.length;if(e>=u&&e<=h){if(o.isWidget()&&t>=-1&&t<=1){if(o.flags&32)return!0;o.flags&16&&(r=void 0)}(u<e||e==h&&(t<-1?o.length:o.covers(1)))&&(!r||!o.isWidget()&&r.isWidget())&&(r=o,i=e-u),(h>e||e==u&&(t>1?o.length:o.covers(-1)))&&(!s||!o.isWidget()&&s.isWidget())&&(s=o,l=e-u)}}),!r&&!s)throw new Error("No tile at position "+e);return r&&t<0||!s?{tile:r,offset:i}:{tile:s,offset:l}}}class Xi extends tp{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let r=new Xi(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}}class ia extends tp{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,r){let i=new ia(t||document.createElement("div"),e);return(!t||!r)&&(i.flags|=4),i}get domAttrs(){return this.attrs}resolveInline(e,t,r){let i=null,s=-1,l=null,o=-1;function u(f,p){for(let g=0,x=0;g<f.children.length&&x<=p;g++){let k=f.children[g],b=x+k.length;b>=p&&(k.isComposite()?u(k,p-x):(!l||l.isHidden&&(t>0||r&&q5(l,k)))&&(b>p||k.flags&32)?(l=k,o=p-x):(x<p||k.flags&16&&!k.isHidden)&&(i=k,s=p-x)),x=b}}u(this,e);let h=(t<0?i:l)||i||l;return h?{tile:h,offset:h==i?s:o}:null}coordsIn(e,t){let r=this.resolveInline(e,t,!0);return r?r.tile.coordsIn(Math.max(0,r.offset),t):W5(this)}domIn(e,t){let r=this.resolveInline(e,t);if(r){let{tile:i,offset:s}=r;if(this.dom.contains(i.dom))return i.isText()?new Xr(i.dom,Math.min(i.dom.nodeValue.length,s)):i.domPosFor(s,i.flags&16?1:i.flags&32?-1:t);let l=r.tile.parent,o=!1;for(let u of l.children){if(o)return new Xr(u.dom,0);u==r.tile&&(o=!0)}}return new Xr(this.dom,0)}}function W5(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=Du(e);return t[t.length-1]||null}function q5(n,e){let t=n.coordsIn(0,1),r=e.coordsIn(0,1);return t&&r&&r.top<t.bottom}class Zn extends tp{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let r=new Zn(t||document.createElement(e.tagName),e);return t||(r.flags|=4),r}}class Sl extends Pt{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let r=this.dom.nodeValue.length;e>r&&(e=r);let i=e,s=e,l=0;e==0&&t<0||e==r&&t>=0?xe.chrome||xe.gecko||(e?(i--,l=1):s<r&&(s++,l=-1)):t<0?i--:s<r&&s++;let o=rc(this.dom,i,s).getClientRects();if(!o.length)return null;let u=o[(l?l<0:t>=0)?0:o.length-1];return xe.safari&&!l&&u.width==0&&(u=Array.prototype.find.call(o,h=>h.width)||u),l?nc(u,l<0):u||null}static of(e,t){let r=new Sl(t||document.createTextNode(e),e);return t||(r.flags|=2),r}}class Xl extends Pt{constructor(e,t,r,i){super(e,t,i),this.widget=r}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,r){let i=this.widget.coordsAt(this.dom,e,t);if(i)return i;if(r)return nc(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let s=this.dom.getClientRects(),l=null;if(!s.length)return null;let o=this.flags&16?!0:this.flags&32?!1:e>0;for(let u=o?s.length-1:0;l=s[u],!(e>0?u==0:u==s.length-1||l.top<l.bottom);u+=o?-1:1);return nc(l,!o)}}get overrideDOMText(){if(!this.length)return Ge.empty;let{root:e}=this;if(!e)return Ge.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,r,i,s){return s||(s=e.toDOM(t),e.editable||(s.contentEditable="false")),new Xl(s,r,e,i)}}class ud extends Pt{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return Ge.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class V5{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,r){let{tile:i,index:s,beforeBreak:l,parents:o}=this;for(;e||t>0;)if(i.isComposite())if(l){if(!e)break;r&&r.break(),e--,l=!1}else if(s==i.children.length){if(!e&&!o.length)break;r&&r.leave(i),l=!!i.breakAfter,{tile:i,index:s}=o.pop(),s++}else{let u=i.children[s],h=u.breakAfter;(t>0?u.length<=e:u.length<e)&&(!r||r.skip(u,0,u.length)!==!1||!u.isComposite)?(l=!!h,s++,e-=u.length):(o.push({tile:i,index:s}),i=u,s=0,r&&u.isComposite()&&r.enter(u))}else if(s==i.length)l=!!i.breakAfter,{tile:i,index:s}=o.pop(),s++;else if(e){let u=Math.min(e,i.length-s);r&&r.skip(i,s,s+u),e-=u,s+=u}else break;return this.tile=i,this.index=s,this.beforeBreak=l,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class F5{constructor(e,t,r,i){this.from=e,this.to=t,this.wrapper=r,this.rank=i}}class Y5{constructor(e,t,r){this.cache=e,this.root=t,this.blockWrappers=r,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,r,i){var s;this.flushBuffer();let l=this.ensureMarks(t,r),o=l.lastChild;if(o&&o.isText()&&!(o.flags&8)&&o.length+e.length<512){this.cache.reused.set(o,2);let u=l.children[l.children.length-1]=new Sl(o.dom,o.text+e);u.parent=l}else l.append(i||Sl.of(e,(s=this.cache.find(Sl))===null||s===void 0?void 0:s.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let r=this.curLine;r.dom!=t.line.dom&&(r.setDOM(this.cache.reused.has(t.line)?vg(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let i=r;for(let o=t.marks.length-1;o>=0;o--){let u=t.marks[o],h=i.lastChild;if(h instanceof Zn&&h.mark.eq(u.mark))h.dom!=u.dom&&h.setDOM(vg(u.dom)),i=h;else{if(this.cache.reused.get(u)){let p=Pt.get(u.dom);p&&p.setDOM(vg(u.dom))}let f=Zn.of(u.mark,u.dom);i.append(f),i=f}this.cache.reused.set(u,2)}let s=Pt.get(e.text);s&&this.cache.reused.set(s,2);let l=new Sl(e.text,e.text.nodeValue);l.flags|=8,this.pos=e.range.toB,i.append(l)}addInlineWidget(e,t,r){let i=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);i||this.flushBuffer();let s=this.ensureMarks(t,r);!i&&!(e.flags&16)&&s.append(this.getBuffer(1)),s.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,r){this.flushBuffer(),this.ensureMarks(t,r).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var r;e||(e=z2);let i=ia.start(e,t||((r=this.cache.find(ia))===null||r===void 0?void 0:r.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=i)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var r;let i=this.curLine;for(let s=e.length-1;s>=0;s--){let l=e[s],o;if(t>0&&(o=i.lastChild)&&o instanceof Zn&&o.mark.eq(l))i=o,t--;else{let u=Zn.of(l,(r=this.cache.find(Zn,h=>h.mark.eq(l)))===null||r===void 0?void 0:r.dom);i.append(u),i=u,t=0}}return i}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Ab(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(xe.ios&&Ab(this.curLine,!0)))&&this.curLine.append(this.cache.findWidget(bg,0,32)||new Xl(bg.toDOM(),0,bg,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=e.rank*102+e.value.rank,r=new F5(e.from,e.to,e.value,t),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-r.rank||this.wrappers[i-1].to-r.to)<0;)i--;this.wrappers.splice(i,0,r)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let r of this.wrappers){let i=t.lastChild;if(r.from<this.pos&&i instanceof Xi&&i.wrapper.eq(r.wrapper))t=i;else{let s=Xi.of(r.wrapper,(e=this.cache.find(Xi,l=>l.wrapper.eq(r.wrapper)))===null||e===void 0?void 0:e.dom);t.append(s),t=s}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),r=this.cache.find(ud,void 0,1);return r&&(r.flags=t),r||new ud(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class U5{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:i,lineBreak:s,done:l}=this.cursor.next(this.skipCount);if(this.skipCount=0,l)throw new Error("Ran out of text content when drawing inline views");this.text=i;let o=this.textOff=Math.min(e,i.length);return s?null:i.slice(0,o)}let t=Math.min(this.text.length,this.textOff+e),r=this.text.slice(this.textOff,t);return this.textOff=t,r}}const cd=[Xl,ia,Sl,Zn,ud,Xi,np];for(let n=0;n<cd.length;n++)cd[n].bucket=n;class G5{constructor(e){this.view=e,this.buckets=cd.map(()=>[]),this.index=cd.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,r=this.buckets[t];r.length<6?r.push(e):r[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,r=2){let i=e.bucket,s=this.buckets[i],l=this.index[i];for(let o=s.length-1;o>=0;o--){let u=(o+l)%s.length,h=s[u];if((!t||t(h))&&!this.reused.has(h))return s.splice(u,1),u<l&&this.index[i]--,this.reused.set(h,r),h}return null}findWidget(e,t,r){let i=this.buckets[0];if(i.length)for(let s=0,l=0;;s++){if(s==i.length){if(l)return null;l=1,s=0}let o=i[s];if(!this.reused.has(o)&&(l==0?o.widget.compare(e):o.widget.constructor==e.constructor&&e.updateDOM(o.dom,this.view,o.widget)))return i.splice(s,1),s<this.index[0]&&this.index[0]--,o.widget==e&&o.length==t&&(o.flags&497)==r?(this.reused.set(o,1),o):(this.reused.set(o,2),new Xl(o.dom,t,e,o.flags&-498|r))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class H5{constructor(e,t,r,i,s){this.view=e,this.decorations=i,this.disallowBlockEffectsFor=s,this.openWidget=!1,this.openMarks=0,this.cache=new G5(e),this.text=new U5(e.state.doc),this.builder=new Y5(this.cache,new np(e,e.contentDOM),We.iter(r)),this.cache.reused.set(t,2),this.old=new V5(t),this.reuseWalker={skip:(l,o,u)=>{if(this.cache.add(l),l.isComposite())return!1},enter:l=>this.cache.add(l),leave:()=>{},break:()=>{}}}run(e,t){let r=t&&this.getCompositionContext(t.text);for(let i=0,s=0,l=0;;){let o=l<e.length?e[l++]:null,u=o?o.fromA:this.old.root.length;if(u>i){let h=u-i;this.preserve(h,!l,!o),i=u,s+=h}if(!o)break;t&&o.fromA<=t.range.fromA&&o.toA>=t.range.toA?(this.forward(o.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(s,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,r),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,o.toA),this.emit(t.range.toB,o.toB)):(this.forward(o.fromA,o.toA),this.emit(s,o.toB)),s=o.toB,i=o.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,r){let i=eL(this.old),s=this.openMarks;this.old.advance(e,r?1:-1,{skip:(l,o,u)=>{if(l.isWidget())if(this.openWidget)this.builder.continueWidget(u-o);else{let h=u>0||o<l.length?Xl.of(l.widget,this.view,u-o,l.flags&496,this.cache.maybeReuse(l)):this.cache.reuse(l);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,i,s),s=i.length)}else if(l.isText())this.builder.ensureLine(null),!o&&u==l.length&&!this.cache.reused.has(l)?this.builder.addText(l.text,i,s,this.cache.reuse(l)):(this.cache.add(l),this.builder.addText(l.text.slice(o,u),i,s)),s=i.length;else if(l.isLine())l.flags&=-2,this.cache.reused.set(l,1),this.builder.addLine(l);else if(l instanceof ud)this.cache.add(l);else if(l instanceof Zn)this.builder.ensureLine(null),this.builder.addMark(l,i,s),this.cache.reused.set(l,1),s=i.length;else return!1;this.openWidget=!1},enter:l=>{l.isLine()?this.builder.addLineStart(l.attrs,this.cache.maybeReuse(l)):(this.cache.add(l),l instanceof Zn&&i.unshift(l.mark)),this.openWidget=!1},leave:l=>{l.isLine()?i.length&&(i.length=s=0):l instanceof Zn&&(i.shift(),s=Math.min(s,i.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let r=null,i=this.builder,s=0,l=We.spans(this.decorations,e,t,{point:(o,u,h,f,p,g)=>{if(h instanceof zl){if(this.disallowBlockEffectsFor[g]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");if(u>this.view.state.doc.lineAt(o).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(s=f.length,p>f.length)i.continueWidget(u-o);else{let x=h.widget||(h.block?sa.block:sa.inline),k=K5(h),b=this.cache.findWidget(x,u-o,k)||Xl.of(x,this.view,u-o,k);h.block?(h.startSide>0&&i.addLineStartIfNotCovered(r),i.addBlockWidget(b)):(i.ensureLine(r),i.addInlineWidget(b,f,p))}r=null}else r=J5(r,h);u>o&&this.text.skip(u-o)},span:(o,u,h,f)=>{for(let p=o;p<u;){let g=this.text.next(Math.min(512,u-p));g==null?(i.addLineStartIfNotCovered(r),i.addBreak(),p++):(i.ensureLine(r),i.addText(g,h,p==o?f:h.length),p+=g.length),r=null}}});i.addLineStartIfNotCovered(r),this.openWidget=l>s,this.openMarks=l}forward(e,t,r=1){t-e<=10?this.old.advance(t-e,r,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,r,this.reuseWalker))}getCompositionContext(e){let t=[],r=null;for(let i=e.parentNode;;i=i.parentNode){let s=Pt.get(i);if(i==this.view.contentDOM)break;s instanceof Zn?t.push(s):s!=null&&s.isLine()?r=s:s instanceof Xi||(i.nodeName=="DIV"&&!r&&i!=this.view.contentDOM?r=new ia(i,z2):r||t.push(Zn.of(new Ac({tagName:i.nodeName.toLowerCase(),attributes:C5(i)}),i)))}return{line:r,marks:t}}}function Ab(n,e){let t=r=>{for(let i of r.children)if((e?i.isText():i.length)||t(i))return!0;return!1};return t(n)}function K5(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}const z2={class:"cm-line"};function J5(n,e){let t=e.spec.attributes,r=e.spec.class;return!t&&!r||(n||(n={class:"cm-line"}),t&&Ry(t,n),r&&(n.class+=" "+r)),n}function eL(n){let e=[];for(let t=n.parents.length;t>1;t--){let r=t==n.parents.length?n.tile:n.parents[t].tile;r instanceof Zn&&e.push(r.mark)}return e}function vg(n){let e=Pt.get(n);return e&&e.setDOM(n.cloneNode()),n}class sa extends Vr{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}get isHidden(){return!0}}sa.inline=new sa("span");sa.block=new sa("div");const bg=new class extends Vr{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Rb{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=$e.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new np(e,e.contentDOM),this.updateInner([new Sr(0,0,0,e.state.doc.length)],null)}update(e){var t;let r=e.changedRanges;this.minWidth>0&&r.length&&(r.every(({fromA:f,toA:p})=>p<this.minWidthFrom||f>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.updateEditContextFormatting(e);let i=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?i=this.domChanged.newSel.head:!uL(e.changes,this.hasComposition)&&!e.selectionSet&&(i=e.state.selection.main.head));let s=i>-1?nL(this.view,e.changes,i):null;if(this.domChanged=null,this.hasComposition){let{from:f,to:p}=this.hasComposition;r=new Sr(f,p,e.changes.mapPos(f,-1),e.changes.mapPos(p,1)).addToSet(r.slice())}this.hasComposition=s?{from:s.range.fromB,to:s.range.toB}:null,(xe.ie||xe.chrome)&&!s&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let l=this.decorations,o=this.blockWrappers;this.updateDeco();let u=sL(l,this.decorations,e.changes);u.length&&(r=Sr.extendWithRanges(r,u));let h=oL(o,this.blockWrappers,e.changes);return h.length&&(r=Sr.extendWithRanges(r,h)),s&&!r.some(f=>f.fromA<=s.range.fromA&&f.toA>=s.range.toA)&&(r=s.range.addToSet(r.slice())),this.tile.flags&2&&r.length==0?!1:(this.updateInner(r,s),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:r}=this.view;r.ignore(()=>{if(t||e.length){let l=this.tile,o=new H5(this.view,l,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&Pt.get(t.text)&&o.cache.reused.set(Pt.get(t.text),2),this.tile=o.run(e,t),vx(l,o.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let s=xe.chrome||xe.ios?{node:r.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(s),s&&(s.written||r.selectionRange.focusNode!=s.node||!this.tile.dom.contains(s.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let i=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let s of this.tile.children)s.isWidget()&&s.widget instanceof wg&&i.push(s.dom);r.updateGaps(i)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let r of t.effects)r.is(N2)&&(this.editContextFormatting=r.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:r}=this.tile,i=this.view.root.activeElement,s=i==r,l=!s&&!(this.view.state.facet(Zi)||r.tabIndex>-1)&&_u(r,this.view.observer.selectionRange)&&!(i&&r.contains(i));if(!(s||t||l))return;let o=this.forceSelection;this.forceSelection=!1;let u=this.view.state.selection.main,h,f;if(u.empty?f=h=this.inlineDOMNearPos(u.anchor,u.assoc||1):(f=this.inlineDOMNearPos(u.head,u.head==u.from?1:-1),h=this.inlineDOMNearPos(u.anchor,u.anchor==u.from?1:-1)),xe.gecko&&u.empty&&!this.hasComposition&&tL(h)){let g=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(g,h.node.childNodes[h.offset]||null)),h=f=new Xr(g,0),o=!0}let p=this.view.observer.selectionRange;(o||!p.focusNode||(!Iu(h.node,h.offset,p.anchorNode,p.anchorOffset)||!Iu(f.node,f.offset,p.focusNode,p.focusOffset))&&!this.suppressWidgetCursorChange(p,u))&&(this.view.observer.ignore(()=>{xe.android&&xe.chrome&&r.contains(p.focusNode)&&aL(p.focusNode,r)&&(r.blur(),r.focus({preventScroll:!0}));let g=tc(this.view.root);if(g)if(u.empty){if(xe.gecko){let x=rL(h.node,h.offset);if(x&&x!=3){let k=(x==1?y2:k2)(h.node,h.offset);k&&(h=new Xr(k.node,k.offset))}}g.collapse(h.node,h.offset),u.bidiLevel!=null&&g.caretBidiLevel!==void 0&&(g.caretBidiLevel=u.bidiLevel)}else if(g.extend){g.collapse(h.node,h.offset);try{g.extend(f.node,f.offset)}catch{}}else{let x=document.createRange();u.anchor>u.head&&([h,f]=[f,h]),x.setEnd(f.node,f.offset),x.setStart(h.node,h.offset),g.removeAllRanges(),g.addRange(x)}l&&this.view.root.activeElement==r&&(r.blur(),i&&i.focus())}),this.view.observer.setSelectionRange(h,f)),this.impreciseAnchor=h.precise?null:new Xr(p.anchorNode,p.anchorOffset),this.impreciseHead=f.precise?null:new Xr(p.focusNode,p.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Iu(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,r=tc(e.root),{anchorNode:i,anchorOffset:s}=e.observer.selectionRange;if(!r||!t.empty||!t.assoc||!r.modify)return;let l=this.lineAt(t.head,t.assoc);if(!l)return;let o=l.posAtStart;if(t.head==o||t.head==o+l.length)return;let u=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!u||!h||u.bottom>h.top)return;let f=this.domAtPos(t.head+t.assoc,t.assoc);r.collapse(f.node,f.offset),r.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let p=e.observer.selectionRange;e.docView.posFromDOM(p.anchorNode,p.anchorOffset)!=t.from&&r.collapse(i,s)}posFromDOM(e,t){let r=this.tile.nearest(e);if(!r)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let i=r.posAtStart;if(r.isComposite()){let s;if(e==r.dom)s=r.dom.childNodes[t];else{let l=Vi(e)==0?0:t==0?-1:1;for(;;){let o=e.parentNode;if(o==r.dom)break;l==0&&o.firstChild!=o.lastChild&&(e==o.firstChild?l=-1:l=1),e=o}l<0?s=e:s=e.nextSibling}if(s==r.dom.firstChild)return i;for(;s&&!Pt.get(s);)s=s.nextSibling;if(!s)return i+r.length;for(let l=0,o=i;;l++){let u=r.children[l];if(u.dom==s)return o;o+=u.length+u.breakAfter}}else return r.isText()?e==r.dom?i+t:i+(t?r.length:0):i}domAtPos(e,t){let{tile:r,offset:i}=this.tile.resolveBlock(e,t);return r.isWidget()?r.domPosFor(e,t):r.domIn(i,t)}inlineDOMNearPos(e,t){let r,i=-1,s=!1,l,o=-1,u=!1;return this.tile.blockTiles((h,f)=>{if(h.isWidget()){if(h.flags&32&&f>=e)return!0;h.flags&16&&(s=!0)}else{let p=f+h.length;if(f<=e&&(r=h,i=e-f,s=p<e),p>=e&&!l&&(l=h,o=e-f,u=f>e),f>e&&l)return!0}}),!r&&!l?this.domAtPos(e,t):(s&&l?r=null:u&&r&&(l=null),r&&t<0||!l?r.domIn(i,t):l.domIn(o,t))}coordsAt(e,t){let{tile:r,offset:i}=this.tile.resolveBlock(e,t);return r.isWidget()?r.widget instanceof wg?null:r.coordsInWidget(i,t,!0):r.coordsIn(i,t)}lineAt(e,t){let{tile:r}=this.tile.resolveBlock(e,t);return r.isLine()?r:null}coordsForChar(e){let{tile:t,offset:r}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function i(s,l){if(s.isComposite())for(let o of s.children){if(o.length>=l){let u=i(o,l);if(u)return u}if(l-=o.length,l<0)break}else if(s.isText()&&l<s.length){let o=Ut(s.text,l);if(o==l)return null;let u=rc(s.dom,l,o).getClientRects();for(let h=0;h<u.length;h++){let f=u[h];if(h==u.length-1||f.top<f.bottom&&f.left<f.right)return f}}return null}return i(t,r)}measureVisibleLineHeights(e){let t=[],{from:r,to:i}=e,s=this.view.contentDOM.clientWidth,l=s>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,o=-1,u=this.view.textDirection==ht.LTR,h=0,f=(p,g,x)=>{for(let k=0;k<p.children.length&&!(g>i);k++){let b=p.children[k],w=g+b.length,S=b.dom.getBoundingClientRect(),{height:Q}=S;if(x&&!k&&(h+=S.top-x.top),b instanceof Xi)w>r&&f(b,g,S);else if(g>=r&&(h>0&&t.push(-h),t.push(Q+h),h=0,l)){let $=b.dom.lastChild,R=$?Du($):[];if(R.length){let I=R[R.length-1],T=u?I.right-S.left:S.right-I.left;T>o&&(o=T,this.minWidth=s,this.minWidthFrom=g,this.minWidthTo=w)}}x&&k==p.children.length-1&&(h+=x.bottom-S.bottom),g=w+b.breakAfter}};return f(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?ht.RTL:ht.LTR}measureTextSize(){let e=this.tile.blockTiles(l=>{if(l.isLine()&&l.children.length&&l.length<=20){let o=0,u;for(let h of l.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let f=Du(h.dom);if(f.length!=1)return;o+=f[0].width,u=f[0].height}if(o)return{lineHeight:l.dom.getBoundingClientRect().height,charWidth:o/l.length,textHeight:u}}});if(e)return e;let t=document.createElement("div"),r,i,s;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let l=Du(t.firstChild)[0];r=t.getBoundingClientRect().height,i=l&&l.width?l.width/27:7,s=l&&l.height?l.height:r,t.remove()}),{lineHeight:r,charWidth:i,textHeight:s}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let r=0,i=0;;i++){let s=i==t.viewports.length?null:t.viewports[i],l=s?s.from-1:this.view.state.doc.length;if(l>r){let o=(t.lineBlockAt(l).bottom-t.lineBlockAt(r).top)/this.view.scaleY;e.push($e.replace({widget:new wg(o),block:!0,inclusive:!0,isBlockGap:!0}).range(r,l))}if(!s)break;r=s.to+1}return $e.set(e)}updateDeco(){let e=1,t=this.view.state.facet(ep).map(s=>(this.dynamicDecorationMap[e++]=typeof s=="function")?s(this.view):s),r=!1,i=this.view.state.facet(zy).map((s,l)=>{let o=typeof s=="function";return o&&(r=!0),o?s(this.view):s});for(i.length&&(this.dynamicDecorationMap[e++]=r,t.push(We.join(i))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(_2).map(s=>typeof s=="function"?s(this.view):s)}scrollIntoView(e){var t;if(e.isSnapshot){let f=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=f.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let f of this.view.state.facet(R2))try{if(f(this.view,e.range,e))return!0}catch(p){Xn(this.view.state,p,"scroll handler")}let{range:r}=e,i=this.coordsAt(r.head,(t=r.assoc)!==null&&t!==void 0?t:r.empty?0:r.head>r.anchor?-1:1),s;if(!i)return;!r.empty&&(s=this.coordsAt(r.anchor,r.anchor>r.head?-1:1))&&(i={left:Math.min(i.left,s.left),top:Math.min(i.top,s.top),right:Math.max(i.right,s.right),bottom:Math.max(i.bottom,s.bottom)});let l=Zy(this.view),o={left:i.left-l.left,top:i.top-l.top,right:i.right+l.right,bottom:i.bottom+l.bottom},{offsetWidth:u,offsetHeight:h}=this.view.scrollDOM;if(T5(this.view.scrollDOM,o,r.head<r.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,u),-u),Math.max(Math.min(e.yMargin,h),-h),this.view.textDirection==ht.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(i.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||i.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let f=this.view.docView.lineAt(r.head,1);f&&f.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=r=>r.isWidget()||r.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){vx(this.tile)}}function vx(n,e){let t=e==null?void 0:e.get(n);if(t!=1){t==null&&n.destroy();for(let r of n.children)vx(r,e)}}function tL(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function Z2(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let r=y2(t.focusNode,t.focusOffset),i=k2(t.focusNode,t.focusOffset),s=r||i;if(i&&r&&i.node!=r.node){let o=Pt.get(i.node);if(!o||o.isText()&&o.text!=i.node.nodeValue)s=i;else if(n.docView.lastCompositionAfterCursor){let u=Pt.get(r.node);!u||u.isText()&&u.text!=r.node.nodeValue||(s=i)}}if(n.docView.lastCompositionAfterCursor=s!=r,!s)return null;let l=e-s.offset;return{from:l,to:l+s.node.nodeValue.length,node:s.node}}function nL(n,e,t){let r=Z2(n,t);if(!r)return null;let{node:i,from:s,to:l}=r,o=i.nodeValue;if(/[\n\r]/.test(o)||n.state.doc.sliceString(r.from,r.to)!=o)return null;let u=e.invertedDesc;return{range:new Sr(u.mapPos(s),u.mapPos(l),s,l),text:i}}function rL(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let iL=class{constructor(){this.changes=[]}compareRange(e,t){Lo(e,t,this.changes)}comparePoint(e,t){Lo(e,t,this.changes)}boundChange(e){Lo(e,e,this.changes)}};function sL(n,e,t){let r=new iL;return We.compare(n,e,t,r),r.changes}class lL{constructor(){this.changes=[]}compareRange(e,t){Lo(e,t,this.changes)}comparePoint(){}boundChange(e){Lo(e,e,this.changes)}}function oL(n,e,t){let r=new lL;return We.compare(n,e,t,r),r.changes}function aL(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function uL(n,e){let t=!1;return e&&n.iterChangedRanges((r,i)=>{r<e.to&&i>e.from&&(t=!0)}),t}class wg extends Vr{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function cL(n,e,t=1){let r=n.charCategorizer(e),i=n.doc.lineAt(e),s=e-i.from;if(i.length==0)return Y.cursor(e);s==0?t=1:s==i.length&&(t=-1);let l=s,o=s;t<0?l=Ut(i.text,s,!1):o=Ut(i.text,s);let u=r(i.text.slice(l,o));for(;l>0;){let h=Ut(i.text,l,!1);if(r(i.text.slice(h,l))!=u)break;l=h}for(;o<i.length;){let h=Ut(i.text,o);if(r(i.text.slice(o,h))!=u)break;o=h}return Y.range(l+i.from,o+i.from)}function hL(n,e,t,r,i){let s=Math.round((r-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let o=n.viewState.heightOracle.textHeight,u=Math.floor((i-t.top-(n.defaultLineHeight-o)*.5)/o);s+=u*n.viewState.heightOracle.lineLength}let l=n.state.sliceDoc(t.from,t.to);return t.from+ux(l,s,n.state.tabSize)}function bx(n,e,t){let r=n.lineBlockAt(e);if(Array.isArray(r.type)){let i;for(let s of r.type){if(s.from>e)break;if(!(s.to<e)){if(s.from<e&&s.to>e)return s;(!i||s.type==ln.Text&&(i.type!=s.type||(t<0?s.from<e:s.to>e)))&&(i=s)}}return i||r}return r}function fL(n,e,t,r){let i=bx(n,e.head,e.assoc||-1),s=!r||i.type!=ln.Text||!(n.lineWrapping||i.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>i.from?e.head-1:e.head);if(s){let l=n.dom.getBoundingClientRect(),o=n.textDirectionAt(i.from),u=n.posAtCoords({x:t==(o==ht.LTR)?l.right-1:l.left+1,y:(s.top+s.bottom)/2});if(u!=null)return Y.cursor(u,t?-1:1)}return Y.cursor(t?i.to:i.from,t?-1:1)}function Nb(n,e,t,r){let i=n.state.doc.lineAt(e.head),s=n.bidiSpans(i),l=n.textDirectionAt(i.from);for(let o=e,u=null;;){let h=z5(i,s,l,o,t),f=P2;if(!h){if(i.number==(t?n.state.doc.lines:1))return o;f=`
74
74
  `,i=n.state.doc.line(i.number+(t?1:-1)),s=n.bidiSpans(i),h=n.visualLineSide(i,!t)}if(u){if(!u(f))return o}else{if(!r)return h;u=r(f)}o=h}}function dL(n,e,t){let r=n.state.charCategorizer(e),i=r(t);return s=>{let l=r(s);return i==yt.Space&&(i=l),i==l}}function pL(n,e,t,r){let i=e.head,s=t?1:-1;if(i==(t?n.state.doc.length:0))return Y.cursor(i,e.assoc);let l=e.goalColumn,o,u=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(i,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),f=n.documentTop;if(h)l==null&&(l=h.left-u.left),o=s<0?h.top:h.bottom;else{let k=n.viewState.lineBlockAt(i);l==null&&(l=Math.min(u.right-u.left,n.defaultCharacterWidth*(i-k.from))),o=(s<0?k.top:k.bottom)+f}let p=u.left+l,g=n.viewState.heightOracle.textHeight>>1,x=r??g;for(let k=0;;k+=g){let b=o+(x+k)*s,w=wx(n,{x:p,y:b},!1,s);if(t?b>u.bottom:b<u.top)return Y.cursor(w.pos,w.assoc);let S=n.coordsAtPos(w.pos,w.assoc),Q=S?(S.top+S.bottom)/2:0;if(!S||(t?Q>o:Q<o))return Y.cursor(w.pos,w.assoc,void 0,l)}}function zu(n,e,t){for(;;){let r=0;for(let i of n)i.between(e-1,e+1,(s,l,o)=>{if(e>s&&e<l){let u=r||t||(e-s<l-e?-1:1);e=u<0?s:l,r=u}});if(!r)return e}}function X2(n,e){let t=null;for(let r=0;r<e.ranges.length;r++){let i=e.ranges[r],s=null;if(i.empty){let l=zu(n,i.from,0);l!=i.from&&(s=Y.cursor(l,-1))}else{let l=zu(n,i.from,-1),o=zu(n,i.to,1);(l!=i.from||o!=i.to)&&(s=Y.range(i.from==i.anchor?l:o,i.from==i.head?l:o))}s&&(t||(t=e.ranges.slice()),t[r]=s)}return t?Y.create(t,e.mainIndex):e}function Sg(n,e,t){let r=zu(n.state.facet(Nc).map(i=>i(n)),t.from,e.head>t.from?-1:1);return r==t.from?t:Y.cursor(r,r<t.from?1:-1)}class fi{constructor(e,t){this.pos=e,this.assoc=t}}function wx(n,e,t,r){let i=n.contentDOM.getBoundingClientRect(),s=i.top+n.viewState.paddingTop,{x:l,y:o}=e,u=o-s,h;for(;;){if(u<0)return new fi(0,1);if(u>n.viewState.docHeight)return new fi(n.state.doc.length,-1);if(h=n.elementAtHeight(u),r==null)break;if(h.type==ln.Text){if(r<0?h.to<n.viewport.from:h.from>n.viewport.to)break;let g=n.docView.coordsAt(r<0?h.from:h.to,r>0?-1:1);if(g&&(r<0?g.top<=u+s:g.bottom>=u+s))break}let p=n.viewState.heightOracle.textHeight/2;u=r>0?h.bottom+p:h.top-p}if(n.viewport.from>=h.to||n.viewport.to<=h.from){if(t)return null;if(h.type==ln.Text){let p=hL(n,i,h,l,o);return new fi(p,p==h.from?1:-1)}}if(h.type!=ln.Text)return u<(h.top+h.bottom)/2?new fi(h.from,1):new fi(h.to,-1);let f=n.docView.lineAt(h.from,2);return(!f||f.length!=h.length)&&(f=n.docView.lineAt(h.from,-2)),new mL(n,l,o,n.textDirectionAt(h.from)).scanTile(f,h.from)}class mL{constructor(e,t,r,i){this.view=e,this.x=t,this.y=r,this.baseDir=i,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:r,spans:i}=this.bidiSpansAt(e);return i[di.find(i,e-r.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:r,spans:i}=this.bidiSpansAt(e);return i[di.find(i,e-r.from,-1,t)].dir}bidiIn(e,t){let{spans:r,line:i}=this.bidiSpansAt(e);return r.length>1||r.length&&(r[0].level!=this.baseDir||r[0].to+i.from<t)}scan(e,t,r=!1){let i=0,s=e.length-1,l=new Set,o=this.bidiIn(e[0],e[s]),u,h,f=-1,p=1e9,g;e:for(;i<s;){let k=s-i,b=i+s>>1;t:if(l.has(b)){let S=i+Math.floor(Math.random()*k);for(let Q=0;Q<k;Q++){if(!l.has(S)){b=S;break t}S++,S==s&&(S=i)}break e}l.add(b);let w=t(b);if(w)for(let S=0;S<w.length;S++){let Q=w[S],$=0;if(!(Q.width==0&&w.length>1)){if(Q.bottom<this.y)(!u||u.bottom<Q.bottom)&&(u=Q),$=1;else if(Q.top>this.y)(!h||h.top>Q.top)&&(h=Q),$=-1;else{let R=Q.left>this.x?this.x-Q.left:Q.right<this.x?this.x-Q.right:0,I=Math.abs(R);I<p&&(f=b,p=I,g=Q),R&&($=R<0==(this.baseDir==ht.LTR)?-1:1)}$==-1&&(!o||this.baseDirAt(e[b],1))?s=b:$==1&&(!o||this.baseDirAt(e[b+1],-1))&&(i=b+1)}}}if(!g){let k=u&&(!h||this.y-u.bottom<h.top-this.y)?u:h;return this.y=(k.top+k.bottom)/2,this.scan(e,t,!0)}if(p&&!r){let{top:k,bottom:b}=g;if(u&&u.bottom>(k+k+b)/3)return this.y=u.bottom-1,this.scan(e,t,!0);if(h&&h.top<(k+b+b)/3)return this.y=h.top+1,this.scan(e,t,!0)}let x=(o?this.dirAt(e[f],1):this.baseDir)==ht.LTR;return{i:f,after:this.x>(g.left+g.right)/2==x}}scanText(e,t){let r=[];for(let s=0;s<e.length;s=Ut(e.text,s))r.push(t+s);r.push(t+e.length);let i=this.scan(r,s=>{let l=r[s]-t,o=r[s+1]-t;return rc(e.dom,l,o).getClientRects()});return i.after?new fi(r[i.i+1],-1):new fi(r[i.i],1)}scanTile(e,t){if(!e.length)return new fi(t,1);if(e.children.length==1){let o=e.children[0];if(o.isText())return this.scanText(o,t);if(o.isComposite())return this.scanTile(o,t)}let r=[t];for(let o=0,u=t;o<e.children.length;o++)r.push(u+=e.children[o].length);let i=this.scan(r,o=>{let u=e.children[o];return u.flags&48?null:(u.dom.nodeType==1?u.dom:rc(u.dom,0,u.length)).getClientRects()}),s=e.children[i.i],l=r[i.i];return s.isText()?this.scanText(s,l):s.isComposite()?this.scanTile(s,l):i.after?new fi(r[i.i+1],-1):new fi(l,1)}}const $o="￿";class gL{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(Fe.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=$o}readRange(e,t){if(!e)return this;let r=e.parentNode;for(let i=e;;){this.findPointBefore(r,i);let s=this.text.length;this.readNode(i);let l=Pt.get(i),o=i.nextSibling;if(o==t){l!=null&&l.breakAfter&&!o&&r!=this.view.contentDOM&&this.lineBreak();break}let u=Pt.get(o);(l&&u?l.breakAfter:(l?l.breakAfter:od(i))||od(o)&&(i.nodeName!="BR"||l!=null&&l.isWidget())&&this.text.length>s)&&!xL(o,t)&&this.lineBreak(),i=o}return this.findPointBefore(r,t),this}readTextNode(e){let t=e.nodeValue;for(let r of this.points)r.node==e&&(r.pos=this.text.length+Math.min(r.offset,t.length));for(let r=0,i=this.lineSeparator?null:/\r\n?|\n/g;;){let s=-1,l=1,o;if(this.lineSeparator?(s=t.indexOf(this.lineSeparator,r),l=this.lineSeparator.length):(o=i.exec(t))&&(s=o.index,l=o[0].length),this.append(t.slice(r,s<0?t.length:s)),s<0)break;if(this.lineBreak(),l>1)for(let u of this.points)u.node==e&&u.pos>this.text.length&&(u.pos-=l-1);r=s+l}}readNode(e){let t=Pt.get(e),r=t&&t.overrideDOMText;if(r!=null){this.findPointInside(e,r.length);for(let i=r.iter();!i.next().done;)i.lineBreak?this.lineBreak():this.append(i.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 r of this.points)r.node==e&&e.childNodes[r.offset]==t&&(r.pos=this.text.length)}findPointInside(e,t){for(let r of this.points)(e.nodeType==3?r.node==e:e.contains(r.node))&&(r.pos=this.text.length+(OL(e,r.node,r.offset)?t:0))}}function OL(n,e,t){for(;;){if(!e||t<Vi(e))return!1;if(e==n)return!0;t=qs(e)+1,e=e.parentNode}}function xL(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let r=Pt.get(n);if(!(r!=null&&r.isWidget()))return!1;r&&(t||(t=[])).push(r)}if(t)for(let r of t){let i=r.overrideDOMText;if(i!=null&&i.length)return!1}return!0}class Lb{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class yL{constructor(e,t,r,i){this.typeOver=i,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:s,impreciseAnchor:l}=e.docView,o=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=B2(e.docView.tile,t,r,0))){let u=s||l?[]:vL(e),h=new gL(u,e);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=bL(u,this.bounds.from)}else{let u=e.observer.selectionRange,h=s&&s.node==u.focusNode&&s.offset==u.focusOffset||!gx(e.contentDOM,u.focusNode)?o.main.head:e.docView.posFromDOM(u.focusNode,u.focusOffset),f=l&&l.node==u.anchorNode&&l.offset==u.anchorOffset||!gx(e.contentDOM,u.anchorNode)?o.main.anchor:e.docView.posFromDOM(u.anchorNode,u.anchorOffset),p=e.viewport;if((xe.ios||xe.chrome)&&o.main.empty&&h!=f&&(p.from>0||p.to<e.state.doc.length)){let g=Math.min(h,f),x=Math.max(h,f),k=p.from-g,b=p.to-x;(k==0||k==1||g==0)&&(b==0||b==-1||x==e.state.doc.length)&&(h=0,f=e.state.doc.length)}if(e.inputState.composing>-1&&o.ranges.length>1)this.newSel=o.replaceRange(Y.range(f,h));else if(e.lineWrapping&&f==h&&!(o.main.empty&&o.main.head==h)&&e.inputState.lastTouchTime>Date.now()-100){let g=e.coordsAtPos(h,-1),x=0;g&&(x=e.inputState.lastTouchY<=g.bottom?-1:1),this.newSel=Y.create([Y.cursor(h,x)])}else this.newSel=Y.single(f,h)}}}function B2(n,e,t,r){if(n.isComposite()){let i=-1,s=-1,l=-1,o=-1;for(let u=0,h=r,f=r;u<n.children.length;u++){let p=n.children[u],g=h+p.length;if(h<e&&g>t)return B2(p,e,t,h);if(g>=e&&i==-1&&(i=u,s=h),h>t&&p.dom.parentNode==n.dom){l=u,o=f;break}f=g,h=g+p.breakAfter}return{from:s,to:o<0?r+n.length:o,startDOM:(i?n.children[i-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:l<n.children.length&&l>=0?n.children[l].dom:null}}else return n.isText()?{from:r,to:r+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function W2(n,e){let t,{newSel:r}=e,{state:i}=n,s=i.selection.main,l=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:o,to:u}=e.bounds,h=s.from,f=null;(l===8||xe.android&&e.text.length<u-o)&&(h=s.to,f="end");let p=i.doc.sliceString(o,u,$o),g,x;!s.empty&&s.from>=o&&s.to<=u&&(e.typeOver||p!=e.text)&&p.slice(0,s.from-o)==e.text.slice(0,s.from-o)&&p.slice(s.to-o)==e.text.slice(g=e.text.length-(p.length-(s.to-o)))?t={from:s.from,to:s.to,insert:Ge.of(e.text.slice(s.from-o,g).split($o))}:(x=q2(p,e.text,h-o,f))&&(xe.chrome&&l==13&&x.toB==x.from+2&&e.text.slice(x.from,x.toB)==$o+$o&&x.toB--,t={from:o+x.from,to:o+x.toA,insert:Ge.of(e.text.slice(x.from,x.toB).split($o))})}else r&&(!n.hasFocus&&i.facet(Zi)||hd(r,s))&&(r=null);if(!t&&!r)return!1;if((xe.mac||xe.android)&&t&&t.from==t.to&&t.from==s.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(r&&t.insert.length==2&&(r=Y.single(r.main.anchor-1,r.main.head-1)),t={from:t.from,to:t.to,insert:Ge.of([t.insert.toString().replace("."," ")])}):i.doc.lineAt(s.from).to<s.to&&n.docView.lineHasWidget(s.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:s.from,to:s.to,insert:i.toText(n.inputState.insertingText)}:xe.chrome&&t&&t.from==t.to&&t.from==s.head&&t.insert.toString()==`
75
- `&&n.lineWrapping&&(r&&(r=Y.single(r.main.anchor-1,r.main.head-1)),t={from:s.from,to:s.to,insert:Ge.of([" "])}),t)return Xy(n,t,r,l);if(r&&!hd(r,s)){let o=!1,u="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),u=n.inputState.lastSelectionOrigin,u=="select.pointer"&&(r=X2(i.facet(Nc).map(h=>h(n)),r))),n.dispatch({selection:r,scrollIntoView:o,userEvent:u}),!0}else return!1}function Xy(n,e,t,r=-1){if(xe.ios&&n.inputState.flushIOSKey(e))return!0;let i=n.state.selection.main;if(xe.android&&(e.to==i.to&&(e.from==i.from||e.from==i.from-1&&n.state.sliceDoc(e.from,i.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&_o(n.contentDOM,"Enter",13)||(e.from==i.from-1&&e.to==i.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>i.head)&&_o(n.contentDOM,"Backspace",8)||e.from==i.from&&e.to==i.to+1&&e.insert.length==0&&_o(n.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let l,o=()=>l||(l=kL(n,e,t));return n.state.facet(j2).some(u=>u(n,e.from,e.to,s,o))||n.dispatch(o()),!0}function kL(n,e,t){let r,i=n.state,s=i.selection.main,l=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let u=e.from<s.from?-1:1,h=u<0?s.from:s.to,f=zu(i.facet(Nc).map(p=>p(n)),h,u);e.from==f&&(l=f)}if(l>-1)r={changes:e,selection:Y.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let u=s.from<e.from?i.sliceDoc(s.from,e.from):"",h=s.to>e.to?i.sliceDoc(e.to,s.to):"";r=i.replaceSelection(n.state.toText(u+e.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let u=i.changes(e),h=t&&t.main.to<=u.newLength?t.main:void 0;if(i.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let f=n.state.sliceDoc(e.from,e.to),p,g=t&&Z2(n,t.main.head);if(g){let k=e.insert.length-(e.to-e.from);p={from:g.from,to:g.to-k}}else p=n.state.doc.lineAt(s.head);let x=s.to-e.to;r=i.changeByRange(k=>{if(k.from==s.from&&k.to==s.to)return{changes:u,range:h||k.map(u)};let b=k.to-x,w=b-f.length;if(n.state.sliceDoc(w,b)!=f||b>=p.from&&w<=p.to)return{range:k};let S=i.changes({from:w,to:b,insert:e.insert}),Q=k.to-s.to;return{changes:S,range:h?Y.range(Math.max(0,h.anchor+Q),Math.max(0,h.head+Q)):k.map(S)}})}else r={changes:u,selection:h&&i.selection.replaceRange(h)}}let o="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,o+=".compose",n.inputState.compositionFirstChange&&(o+=".start",n.inputState.compositionFirstChange=!1)),i.update(r,{userEvent:o,scrollIntoView:!0})}function q2(n,e,t,r){let i=Math.min(n.length,e.length),s=0;for(;s<i&&n.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==i&&n.length==e.length)return null;let l=n.length,o=e.length;for(;l>0&&o>0&&n.charCodeAt(l-1)==e.charCodeAt(o-1);)l--,o--;if(r=="end"){let u=Math.max(0,s-Math.min(l,o));t-=l+u-s}if(l<s&&n.length<e.length){let u=t<=s&&t>=l?s-t:0;s-=u,o=s+(o-l),l=s}else if(o<s){let u=t<=s&&t>=o?s-t:0;s-=u,l=s+(l-o),o=s}return{from:s,toA:l,toB:o}}function vL(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}=n.observer.selectionRange;return t&&(e.push(new Lb(t,r)),(i!=t||s!=r)&&e.push(new Lb(i,s))),e}function bL(n,e){if(n.length==0)return null;let t=n[0].pos,r=n.length==2?n[1].pos:t;return t>-1&&r>-1?Y.single(t+e,r+e):null}function hd(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}class wL{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,xe.safari&&e.contentDOM.addEventListener("input",()=>null),xe.gecko&&DL(e.contentDOM.ownerDocument)}handleEvent(e){!EL(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let r=this.handlers[e];if(r){for(let i of r.observers)i(this.view,t);for(let i of r.handlers){if(t.defaultPrevented)break;if(i(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=SL(e),r=this.handlers,i=this.view.contentDOM;for(let s in t)if(s!="scroll"){let l=!t[s].handlers.length,o=r[s];o&&l!=!o.handlers.length&&(i.removeEventListener(s,this.handleEvent),o=null),o||i.addEventListener(s,this.handleEvent,{passive:l})}for(let s in r)s!="scroll"&&!t[s]&&i.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&F2.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),xe.android&&xe.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return xe.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=V2.find(r=>r.keyCode==e.keyCode))&&!e.ctrlKey||PL.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,_o(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:xe.safari&&!xe.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function _b(n,e){return(t,r)=>{try{return e.call(n,r,t)}catch(i){Xn(t.state,i)}}}function SL(n){let e=Object.create(null);function t(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of n){let i=r.spec,s=i&&i.plugin.domEventHandlers,l=i&&i.plugin.domEventObservers;if(s)for(let o in s){let u=s[o];u&&t(o).handlers.push(_b(r.value,u))}if(l)for(let o in l){let u=l[o];u&&t(o).observers.push(_b(r.value,u))}}for(let r in qr)t(r).handlers.push(qr[r]);for(let r in Wn)t(r).observers.push(Wn[r]);return e}const V2=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],PL="dthko",F2=[16,17,18,20,91,92,224,225],hf=6;function ff(n){return Math.max(0,n)*.7+8}function CL(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class QL{constructor(e,t,r,i){this.view=e,this.startEvent=t,this.style=r,this.mustSelect=i,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=g2(e.contentDOM),this.atoms=e.state.facet(Nc).map(l=>l(e));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(Fe.allowMultipleSelections)&&$L(e,t),this.dragging=jL(e,t)&&G2(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&CL(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,r=0,i=0,s=0,l=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:i,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:o}=this.scrollParents.y.getBoundingClientRect());let u=Zy(this.view);e.clientX-u.left<=i+hf?t=-ff(i-e.clientX):e.clientX+u.right>=l-hf&&(t=ff(e.clientX-l)),e.clientY-u.top<=s+hf?r=-ff(s-e.clientY):e.clientY+u.bottom>=o-hf&&(r=ff(e.clientY-o)),this.setScrollSpeed(t,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=this.view.inputState.draggedContent=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(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,r=X2(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function $L(n,e){let t=n.state.facet(C2);return t.length?t[0](e):xe.mac?e.metaKey:e.ctrlKey}function TL(n,e){let t=n.state.facet(Q2);return t.length?t[0](e):xe.mac?!e.altKey:!e.ctrlKey}function jL(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let r=tc(n.root);if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let s=0;s<i.length;s++){let l=i[s];if(l.left<=e.clientX&&l.right>=e.clientX&&l.top<=e.clientY&&l.bottom>=e.clientY)return!0}return!1}function EL(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,r;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(r=Pt.get(t))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}const qr=Object.create(null),Wn=Object.create(null),Y2=xe.ie&&xe.ie_version<15||xe.ios&&xe.webkit_version<604;function ML(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),U2(n,t.value)},50)}function rp(n,e,t){for(let r of n.facet(e))t=r(t,n);return t}function U2(n,e){e=rp(n.state,_y,e);let{state:t}=n,r,i=1,s=t.toText(e),l=s.lines==t.selection.ranges.length;if(Sx!=null&&t.selection.ranges.every(u=>u.empty)&&Sx==s.toString()){let u=-1;r=t.changeByRange(h=>{let f=t.doc.lineAt(h.from);if(f.from==u)return{range:h};u=f.from;let p=t.toText((l?s.line(i++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:p},range:Y.cursor(h.from+p.length)}})}else l?r=t.changeByRange(u=>{let h=s.line(i++);return{changes:{from:u.from,to:u.to,insert:h.text},range:Y.cursor(u.from+h.length)}}):r=t.replaceSelection(s);n.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}Wn.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Wn.wheel=Wn.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};qr.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);Wn.touchstart=(n,e)=>{let t=n.inputState,r=e.targetTouches[0];t.lastTouchTime=Date.now(),r&&(t.lastTouchX=r.clientX,t.lastTouchY=r.clientY),t.setSelectionOrigin("select.pointer")};Wn.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};qr.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let r of n.state.facet($2))if(t=r(n,e),t)break;if(!t&&e.button==0&&(t=RL(n,e)),t){let r=!n.hasFocus;n.inputState.startMouseSelection(new QL(n,e,t,r)),r&&n.observer.ignore(()=>{O2(n.contentDOM);let s=n.root.activeElement;s&&!s.contains(n.contentDOM)&&s.blur()});let i=n.inputState.mouseSelection;if(i)return i.start(e),i.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Db(n,e,t,r){if(r==1)return Y.cursor(e,t);if(r==2)return cL(n.state,e,t);{let i=n.docView.lineAt(e,t),s=n.state.doc.lineAt(i?i.posAtEnd:e),l=i?i.posAtStart:s.from,o=i?i.posAtEnd:s.to;return o<n.state.doc.length&&o==s.to&&o++,Y.range(l,o)}}const AL=xe.ie&&xe.ie_version<=11;let Ib=null,zb=0,Zb=0;function G2(n){if(!AL)return n.detail;let e=Ib,t=Zb;return Ib=n,Zb=Date.now(),zb=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(zb+1)%3:1}function RL(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=G2(e),i=n.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),i=i.map(s.changes))},get(s,l,o){let u=n.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),h,f=Db(n,u.pos,u.assoc,r);if(t.pos!=u.pos&&!l){let p=Db(n,t.pos,t.assoc,r),g=Math.min(p.from,f.from),x=Math.max(p.to,f.to);f=g<f.from?Y.range(g,x,f.assoc):Y.range(x,g,f.assoc)}return l?i.replaceRange(i.main.extend(f.from,f.to,f.assoc)):o&&r==1&&i.ranges.length>1&&(h=NL(i,u.pos))?h:o?i.addRange(f):Y.create([f])}}}function NL(n,e){for(let t=0;t<n.ranges.length;t++){let{from:r,to:i}=n.ranges[t];if(r<=e&&i>=e)return Y.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}qr.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let i=n.docView.tile.nearest(e.target);if(i&&i.isWidget()){let s=i.posAtStart,l=s+i.length;(s>=t.to||l<=t.from)&&(t=Y.range(s,l))}}let{inputState:r}=n;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",rp(n.state,Dy,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};qr.dragend=n=>(n.inputState.draggedContent=null,!1);function Xb(n,e,t,r){if(t=rp(n.state,_y,t),!t)return;let i=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=n.inputState,l=r&&s&&TL(n,e)?{from:s.from,to:s.to}:null,o={from:i,insert:t},u=n.state.changes(l?[l,o]:o);n.focus(),n.dispatch({changes:u,selection:{anchor:u.mapPos(i,-1),head:u.mapPos(i,1)},userEvent:l?"move.drop":"input.drop"}),n.inputState.draggedContent=null}qr.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let r=Array(t.length),i=0,s=()=>{++i==t.length&&Xb(n,e,r.filter(l=>l!=null).join(n.state.lineBreak),!1)};for(let l=0;l<t.length;l++){let o=new FileReader;o.onerror=s,o.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(o.result)||(r[l]=o.result),s()},o.readAsText(t[l])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Xb(n,e,r,!0),!0}return!1};qr.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=Y2?null:e.clipboardData;return t?(U2(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(ML(n),!1)};function LL(n,e){let t=n.dom.parentNode;if(!t)return;let r=t.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),n.focus()},50)}function _L(n){let e=[],t=[],r=!1;for(let i of n.selection.ranges)i.empty||(e.push(n.sliceDoc(i.from,i.to)),t.push(i));if(!e.length){let i=-1;for(let{from:s}of n.selection.ranges){let l=n.doc.lineAt(s);l.number>i&&(e.push(l.text),t.push({from:l.from,to:Math.min(n.doc.length,l.to+1)})),i=l.number}r=!0}return{text:rp(n,Dy,e.join(n.lineBreak)),ranges:t,linewise:r}}let Sx=null;qr.copy=qr.cut=(n,e)=>{if(!_u(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:r,linewise:i}=_L(n.state);if(!t&&!i)return!1;Sx=i?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=Y2?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(LL(n,t),!1)};const H2=vi.define();function K2(n,e){let t=[];for(let r of n.facet(E2)){let i=r(n,e);i&&t.push(i)}return t.length?n.update({effects:t,annotations:H2.of(!0)}):null}function J2(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=K2(n.state,e);t?n.dispatch(t):n.update([])}},10)}Wn.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),J2(n)};Wn.blur=n=>{n.observer.clearSelectionRange(),J2(n)};Wn.compositionstart=Wn.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};Wn.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,xe.chrome&&xe.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};Wn.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};qr.beforeinput=(n,e)=>{var t,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),l=e.getTargetRanges();if(s&&l.length){let o=l[0],u=n.posAtDOM(o.startContainer,o.startOffset),h=n.posAtDOM(o.endContainer,o.endOffset);return Xy(n,{from:u,to:h,insert:n.state.toText(s)},null),!0}}let i;if(xe.chrome&&xe.android&&(i=V2.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var l;(((l=window.visualViewport)===null||l===void 0?void 0:l.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return xe.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),xe.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>Wn.compositionend(n,e),20),!1};const Bb=new Set;function DL(n){Bb.has(n)||(Bb.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Wb=["pre-wrap","normal","pre-line","break-spaces"];let la=!1;function qb(){la=!1}class IL{constructor(e){this.lineWrapping=e,this.doc=Ge.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let r=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((t-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Wb.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let r=0;r<e.length;r++){let i=e[r];i<0?r++:this.heightSamples[Math.floor(i*10)]||(t=!0,this.heightSamples[Math.floor(i*10)]=!0)}return t}refresh(e,t,r,i,s,l){let o=Wb.indexOf(e)>-1,u=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=r,this.textHeight=i,this.lineLength=s,u){this.heightSamples={};for(let h=0;h<l.length;h++){let f=l[h];f<0?h++:this.heightSamples[Math.floor(f*10)]=!0}}return u}}class zL{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Zr{constructor(e,t,r,i,s){this.from=e,this.length=t,this.top=r,this.height=i,this._content=s}get type(){return typeof this._content=="number"?ln.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof zl?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Zr(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var mt=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(mt||(mt={}));const Zf=.001;class $n{constructor(e,t,r=2){this.length=e,this.height=t,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Zf&&(la=!0),this.height=e)}replace(e,t,r){return $n.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,r,i){let s=this,l=r.doc;for(let o=i.length-1;o>=0;o--){let{fromA:u,toA:h,fromB:f,toB:p}=i[o],g=s.lineAt(u,mt.ByPosNoHeight,r.setDoc(t),0,0),x=g.to>=h?g:s.lineAt(h,mt.ByPosNoHeight,r,0,0);for(p+=x.to-h,h=x.to;o>0&&g.from<=i[o-1].toA;)u=i[o-1].fromA,f=i[o-1].fromB,o--,u<g.from&&(g=s.lineAt(u,mt.ByPosNoHeight,r,0,0));f+=g.from-u,u=g.from;let k=By.build(r.setDoc(l),e,f,p);s=fd(s,s.replace(u,h,k))}return s.updateHeight(r,0)}static empty(){return new lr(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,r=e.length,i=0,s=0;for(;;)if(t==r)if(i>s*2){let o=e[t-1];o.break?e.splice(--t,1,o.left,null,o.right):e.splice(--t,1,o.left,o.right),r+=1+o.break,i-=o.size}else if(s>i*2){let o=e[r];o.break?e.splice(r,1,o.left,null,o.right):e.splice(r,1,o.left,o.right),r+=2+o.break,s-=o.size}else break;else if(i<s){let o=e[t++];o&&(i+=o.size)}else{let o=e[--r];o&&(s+=o.size)}let l=0;return e[t-1]==null?(l=1,t--):e[t]==null&&(l=1,r++),new XL($n.of(e.slice(0,t)),l,$n.of(e.slice(r)))}}function fd(n,e){return n==e?n:(n.constructor!=e.constructor&&(la=!0),e)}$n.prototype.size=1;const ZL=$e.replace({});class eQ extends $n{constructor(e,t,r){super(e,t),this.deco=r,this.spaceAbove=0}mainBlock(e,t){return new Zr(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,r,i){return this.spaceAbove&&e<r+this.spaceAbove?new Zr(i,0,r,this.spaceAbove,ZL):this.mainBlock(r,i)}lineAt(e,t,r,i,s){let l=this.mainBlock(i,s);return this.spaceAbove?this.blockAt(0,r,i,s).join(l):l}forEachLine(e,t,r,i,s,l){e<=s+this.length&&t>=s&&l(this.lineAt(0,mt.ByPos,r,i,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,r=!1,i){return i&&i.from<=t&&i.more&&this.setMeasuredHeight(i),this.outdated=!1,this}toString(){return`block(${this.length})`}}class lr extends eQ{constructor(e,t,r){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,t){return new Zr(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,r){let i=r[0];return r.length==1&&(i instanceof lr||i instanceof nn&&i.flags&4)&&Math.abs(this.length-i.length)<10?(i instanceof nn?i=new lr(i.length,this.height,this.spaceAbove):i.height=this.height,this.outdated||(i.outdated=!1),i):$n.of(r)}updateHeight(e,t=0,r=!1,i){return i&&i.from<=t&&i.more?this.setMeasuredHeight(i):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class nn extends $n{constructor(e){super(e,0)}heightMetrics(e,t){let r=e.doc.lineAt(t).number,i=e.doc.lineAt(t+this.length).number,s=i-r+1,l,o=0;if(e.lineWrapping){let u=Math.min(this.height,e.lineHeight*s);l=u/s,this.length>s+1&&(o=(this.height-u)/(this.length-s-1))}else l=this.height/s;return{firstLine:r,lastLine:i,perLine:l,perChar:o}}blockAt(e,t,r,i){let{firstLine:s,lastLine:l,perLine:o,perChar:u}=this.heightMetrics(t,i);if(t.lineWrapping){let h=i+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),f=t.doc.lineAt(h),p=o+f.length*u,g=Math.max(r,e-p/2);return new Zr(f.from,f.length,g,p,0)}else{let h=Math.max(0,Math.min(l-s,Math.floor((e-r)/o))),{from:f,length:p}=t.doc.line(s+h);return new Zr(f,p,r+o*h,o,0)}}lineAt(e,t,r,i,s){if(t==mt.ByHeight)return this.blockAt(e,r,i,s);if(t==mt.ByPosNoHeight){let{from:x,to:k}=r.doc.lineAt(e);return new Zr(x,k-x,0,0,0)}let{firstLine:l,perLine:o,perChar:u}=this.heightMetrics(r,s),h=r.doc.lineAt(e),f=o+h.length*u,p=h.number-l,g=i+o*p+u*(h.from-s-p);return new Zr(h.from,h.length,Math.max(i,Math.min(g,i+this.height-f)),f,0)}forEachLine(e,t,r,i,s,l){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:o,perLine:u,perChar:h}=this.heightMetrics(r,s);for(let f=e,p=i;f<=t;){let g=r.doc.lineAt(f);if(f==e){let k=g.number-o;p+=u*k+h*(e-s-k)}let x=u+h*g.length;l(new Zr(g.from,g.length,p,x,0)),p+=x,f=g.to+1}}replace(e,t,r){let i=this.length-t;if(i>0){let s=r[r.length-1];s instanceof nn?r[r.length-1]=new nn(s.length+i):r.push(null,new nn(i-1))}if(e>0){let s=r[0];s instanceof nn?r[0]=new nn(e+s.length):r.unshift(new nn(e-1),null)}return $n.of(r)}decomposeLeft(e,t){t.push(new nn(e-1),null)}decomposeRight(e,t){t.push(null,new nn(this.length-e-1))}updateHeight(e,t=0,r=!1,i){let s=t+this.length;if(i&&i.from<=t+this.length&&i.more){let l=[],o=Math.max(t,i.from),u=-1;for(i.from>t&&l.push(new nn(i.from-t-1).updateHeight(e,t));o<=s&&i.more;){let f=e.doc.lineAt(o).length;l.length&&l.push(null);let p=i.heights[i.index++],g=0;p<0&&(g=-p,p=i.heights[i.index++]),u==-1?u=p:Math.abs(p-u)>=Zf&&(u=-2);let x=new lr(f,p,g);x.outdated=!1,l.push(x),o+=f+1}o<=s&&l.push(null,new nn(s-o).updateHeight(e,o));let h=$n.of(l);return(u<0||Math.abs(h.height-this.height)>=Zf||Math.abs(u-this.heightMetrics(e,t).perLine)>=Zf)&&(la=!0),fd(this,h)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class XL extends $n{constructor(e,t,r){super(e.length+t+r.length,e.height+r.height,t|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,t,r,i){let s=r+this.left.height;return e<s?this.left.blockAt(e,t,r,i):this.right.blockAt(e,t,s,i+this.left.length+this.break)}lineAt(e,t,r,i,s){let l=i+this.left.height,o=s+this.left.length+this.break,u=t==mt.ByHeight?e<l:e<o,h=u?this.left.lineAt(e,t,r,i,s):this.right.lineAt(e,t,r,l,o);if(this.break||(u?h.to<o:h.from>o))return h;let f=t==mt.ByPosNoHeight?mt.ByPosNoHeight:mt.ByPos;return u?h.join(this.right.lineAt(o,f,r,l,o)):this.left.lineAt(o,f,r,i,s).join(h)}forEachLine(e,t,r,i,s,l){let o=i+this.left.height,u=s+this.left.length+this.break;if(this.break)e<u&&this.left.forEachLine(e,t,r,i,s,l),t>=u&&this.right.forEachLine(e,t,r,o,u,l);else{let h=this.lineAt(u,mt.ByPos,r,i,s);e<h.from&&this.left.forEachLine(e,h.from-1,r,i,s,l),h.to>=e&&h.from<=t&&l(h),t>h.to&&this.right.forEachLine(h.to+1,t,r,o,u,l)}}replace(e,t,r){let i=this.left.length+this.break;if(t<i)return this.balanced(this.left.replace(e,t,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-i,t-i,r));let s=[];e>0&&this.decomposeLeft(e,s);let l=s.length;for(let o of r)s.push(o);if(e>0&&Vb(s,l-1),t<this.length){let o=s.length;this.decomposeRight(t,s),Vb(s,o)}return $n.of(s)}decomposeLeft(e,t){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(r++,e>=r&&t.push(null)),e>r&&this.right.decomposeLeft(e-r,t)}decomposeRight(e,t){let r=this.left.length,i=r+this.break;if(e>=i)return this.right.decomposeRight(e-i,t);e<r&&this.left.decomposeRight(e,t),this.break&&e<i&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?$n.of(this.break?[e,null,t]:[e,t]):(this.left=fd(this.left,e),this.right=fd(this.right,t),this.setHeight(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,r=!1,i){let{left:s,right:l}=this,o=t+s.length+this.break,u=null;return i&&i.from<=t+s.length&&i.more?u=s=s.updateHeight(e,t,r,i):s.updateHeight(e,t,r),i&&i.from<=o+l.length&&i.more?u=l=l.updateHeight(e,o,r,i):l.updateHeight(e,o,r),u?this.balanced(s,l):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Vb(n,e){let t,r;n[e]==null&&(t=n[e-1])instanceof nn&&(r=n[e+1])instanceof nn&&n.splice(e-1,3,new nn(t.length+1+r.length))}const BL=5;class By{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 r=Math.min(t,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof lr?i.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new lr(r-this.pos,-1,0)),this.writtenTo=r,t>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,r){if(e<t||r.heightRelevant){let i=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;i<0&&(i=this.oracle.lineHeight);let l=t-e;r.block?this.addBlock(new eQ(l,i,r)):(l||s||i>=BL)&&this.addLineDeco(i,s,l)}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 lr(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let r=new nn(t-e);return this.oracle.doc.lineAt(e).to==t&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof lr)return e;let t=new lr(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,r){let i=this.ensureLine();i.length+=r,i.collapsed+=r,i.widgetHeight=Math.max(i.widgetHeight,e),i.breaks+=t,this.writtenTo=this.pos=this.pos+r}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof lr)&&!this.isCovered?this.nodes.push(new lr(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let i of this.nodes)i instanceof lr&&i.updateHeight(this.oracle,r),r+=i?i.length:1;return this.nodes}static build(e,t,r,i){let s=new By(r,e);return We.spans(t,r,i,s,0),s.finish(r)}}function WL(n,e,t){let r=new qL;return We.compare(n,e,t,r,0),r.changes}class qL{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,r,i){(e<t||r&&r.heightRelevant||i&&i.heightRelevant)&&Lo(e,t,this.changes,5)}}function VL(n,e){let t=n.getBoundingClientRect(),r=n.ownerDocument,i=r.defaultView||window,s=Math.max(0,t.left),l=Math.min(i.innerWidth,t.right),o=Math.max(0,t.top),u=Math.min(i.innerHeight,t.bottom);for(let h=n.parentNode;h&&h!=r.body;)if(h.nodeType==1){let f=h,p=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&p.overflow!="visible"){let g=f.getBoundingClientRect();s=Math.max(s,g.left),l=Math.min(l,g.right),o=Math.max(o,g.top),u=Math.min(h==n.parentNode?i.innerHeight:u,g.bottom)}h=p.position=="absolute"||p.position=="fixed"?f.offsetParent:f.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,l)-t.left,top:o-(t.top+e),bottom:Math.max(o,u)-(t.top+e)}}function FL(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function YL(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Pg{constructor(e,t,r,i){this.from=e,this.to=t,this.size=r,this.displaySize=i}static same(e,t){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++){let i=e[r],s=t[r];if(i.from!=s.from||i.to!=s.to||i.size!=s.size)return!1}return!0}draw(e,t){return $e.replace({widget:new UL(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class UL extends Vr{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}}class Fb{constructor(e,t){this.view=e,this.state=t,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.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Yb,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=ht.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=t.facet(Iy).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new IL(r),this.stateDeco=Ub(t),this.heightMap=$n.empty().applyChanges(this.stateDeco,Ge.empty,this.heightOracle.setDoc(t.doc),[new Sr(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=$e.set(this.lineGaps.map(i=>i.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let r=0;r<=1;r++){let i=r?t.head:t.anchor;if(!e.some(({from:s,to:l})=>i>=s&&i<=l)){let{from:s,to:l}=this.lineBlockAt(i);e.push(new df(s,l))}}return this.viewports=e.sort((r,i)=>r.from-i.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Yb:new Wy(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Mu(e,this.scaler))})}update(e,t=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=Ub(this.state);let i=e.changedRanges,s=Sr.extendWithRanges(i,WL(r,this.stateDeco,e?e.changes:Lt.empty(this.state.doc.length))),l=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);qb(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=l||la)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=l);let u=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<u.from||t.range.head>u.to)||!this.viewportIsAppropriate(u))&&(u=this.getViewport(0,t));let h=u.from!=this.viewport.from||u.to!=this.viewport.to;this.viewport=u,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(A2)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,r=window.getComputedStyle(t),i=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?ht.RTL:ht.LTR;let l=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",o=t.getBoundingClientRect(),u=l||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let h=0,f=0;if(o.width&&o.height){let{scaleX:I,scaleY:T}=m2(t,o);(I>.005&&Math.abs(this.scaleX-I)>.005||T>.005&&Math.abs(this.scaleY-T)>.005)&&(this.scaleX=I,this.scaleY=T,h|=16,l=u=!0)}let p=(parseInt(r.paddingTop)||0)*this.scaleY,g=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=p||this.paddingBottom!=g)&&(this.paddingTop=p,this.paddingBottom=g,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(i.lineWrapping&&(u=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let x=g2(this.view.contentDOM,!1).y;x!=this.scrollParent&&(this.scrollParent=x,this.scrollAnchorHeight=-1,this.scrollOffset=0);let k=this.getScrollOffset();this.scrollOffset!=k&&(this.scrollAnchorHeight=-1,this.scrollOffset=k),this.scrolledToBottom=x2(this.scrollParent||e.win);let b=(this.printing?YL:VL)(t,this.paddingTop),w=b.top-this.pixelViewport.top,S=b.bottom-this.pixelViewport.bottom;this.pixelViewport=b;let Q=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(Q!=this.inView&&(this.inView=Q,Q&&(u=!0)),!this.inView&&!this.scrollTarget&&!FL(e.dom))return 0;let $=o.width;if((this.contentDOMWidth!=$||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),u){let I=e.docView.measureVisibleLineHeights(this.viewport);if(i.mustRefreshForHeights(I)&&(l=!0),l||i.lineWrapping&&Math.abs($-this.contentDOMWidth)>i.charWidth){let{lineHeight:T,charWidth:X,textHeight:Z}=e.docView.measureTextSize();l=T>0&&i.refresh(s,T,X,Z,Math.max(5,$/X),I),l&&(e.docView.minWidth=0,h|=16)}w>0&&S>0?f=Math.max(w,S):w<0&&S<0&&(f=Math.min(w,S)),qb();for(let T of this.viewports){let X=T.from==this.viewport.from?I:e.docView.measureVisibleLineHeights(T);this.heightMap=(l?$n.empty().applyChanges(this.stateDeco,Ge.empty,this.heightOracle,[new Sr(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(i,0,l,new zL(T.from,X))}la&&(h|=2)}let R=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return R&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),h|=this.updateForViewport()),(h&2||R)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(l?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),i=this.heightMap,s=this.heightOracle,{visibleTop:l,visibleBottom:o}=this,u=new df(i.lineAt(l-r*1e3,mt.ByHeight,s,0,0).from,i.lineAt(o+(1-r)*1e3,mt.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(h<u.from||h>u.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),p=i.lineAt(h,mt.ByPos,s,0,0),g;t.y=="center"?g=(p.top+p.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&h<u.from?g=p.top:g=p.bottom-f,u=new df(i.lineAt(g-1e3/2,mt.ByHeight,s,0,0).from,i.lineAt(g+f+1e3/2,mt.ByHeight,s,0,0).to)}}return u}mapViewport(e,t){let r=t.mapPos(e.from,-1),i=t.mapPos(e.to,1);return new df(this.heightMap.lineAt(r,mt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(i,mt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},r=0){if(!this.inView)return!0;let{top:i}=this.heightMap.lineAt(e,mt.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,mt.ByPos,this.heightOracle,0,0),{visibleTop:l,visibleBottom:o}=this;return(e==0||i<=l-Math.max(10,Math.min(-r,250)))&&(t==this.state.doc.length||s>=o+Math.max(10,Math.min(r,250)))&&i>l-2*1e3&&s<o+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let r=[];for(let i of e)t.touchesRange(i.from,i.to)||r.push(new Pg(t.mapPos(i.from),t.mapPos(i.to),i.size,i.displaySize));return r}ensureLineGaps(e,t){let r=this.heightOracle.lineWrapping,i=r?1e4:2e3,s=i>>1,l=i<<1;if(this.defaultTextDirection!=ht.LTR&&!r)return[];let o=[],u=(f,p,g,x)=>{if(p-f<s)return;let k=this.state.selection.main,b=[k.from];k.empty||b.push(k.to);for(let S of b)if(S>f&&S<p){u(f,S-10,g,x),u(S+10,p,g,x);return}let w=HL(e,S=>S.from>=g.from&&S.to<=g.to&&Math.abs(S.from-f)<s&&Math.abs(S.to-p)<s&&!b.some(Q=>S.from<Q&&S.to>Q));if(!w){if(p<g.to&&t&&r&&t.visibleRanges.some($=>$.from<=p&&$.to>=p)){let $=t.moveToLineBoundary(Y.cursor(p),!1,!0).head;$>f&&(p=$)}let S=this.gapSize(g,f,p,x),Q=r||S<2e6?S:2e6;w=new Pg(f,p,S,Q)}o.push(w)},h=f=>{if(f.length<l||f.type!=ln.Text)return;let p=GL(f.from,f.to,this.stateDeco);if(p.total<l)return;let g=this.scrollTarget?this.scrollTarget.range.head:null,x,k;if(r){let b=i/this.heightOracle.lineLength*this.heightOracle.lineHeight,w,S;if(g!=null){let Q=mf(p,g),$=((this.visibleBottom-this.visibleTop)/2+b)/f.height;w=Q-$,S=Q+$}else w=(this.visibleTop-f.top-b)/f.height,S=(this.visibleBottom-f.top+b)/f.height;x=pf(p,w),k=pf(p,S)}else{let b=p.total*this.heightOracle.charWidth,w=i*this.heightOracle.charWidth,S=0;if(b>2e6)for(let T of e)T.from>=f.from&&T.from<f.to&&T.size!=T.displaySize&&T.from*this.heightOracle.charWidth+S<this.pixelViewport.left&&(S=T.size-T.displaySize);let Q=this.pixelViewport.left+S,$=this.pixelViewport.right+S,R,I;if(g!=null){let T=mf(p,g),X=(($-Q)/2+w)/b;R=T-X,I=T+X}else R=(Q-w)/b,I=($+w)/b;x=pf(p,R),k=pf(p,I)}x>f.from&&u(f.from,x,f,p),k<f.to&&u(k,f.to,f,p)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(h):h(f);return o}gapSize(e,t,r,i){let s=mf(i,r)-mf(i,t);return this.heightOracle.lineWrapping?e.height*s:i.total*this.heightOracle.charWidth*s}updateLineGaps(e){Pg.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=$e.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let r=[];We.spans(t,this.viewport.from,this.viewport.to,{span(s,l){r.push({from:s,to:l})},point(){}},20);let i=0;if(r.length!=this.visibleRanges.length)i=12;else for(let s=0;s<r.length&&!(i&8);s++){let l=this.visibleRanges[s],o=r[s];(l.from!=o.from||l.to!=o.to)&&(i|=4,e&&e.mapPos(l.from,-1)==o.from&&e.mapPos(l.to,1)==o.to||(i|=8))}return this.visibleRanges=r,i}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Mu(this.heightMap.lineAt(e,mt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Mu(this.heightMap.lineAt(this.scaler.fromDOM(e),mt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Mu(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}}class df{constructor(e,t){this.from=e,this.to=t}}function GL(n,e,t){let r=[],i=n,s=0;return We.spans(t,n,e,{span(){},point(l,o){l>i&&(r.push({from:i,to:l}),s+=l-i),i=o}},20),i<e&&(r.push({from:i,to:e}),s+=e-i),{total:s,ranges:r}}function pf({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let r=Math.floor(n*t);for(let i=0;;i++){let{from:s,to:l}=e[i],o=l-s;if(r<=o)return s+r;r-=o}}function mf(n,e){let t=0;for(let{from:r,to:i}of n.ranges){if(e<=i){t+=e-r;break}t+=i-r}return t/n.total}function HL(n,e){for(let t of n)if(e(t))return t}const Yb={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function Ub(n){let e=n.facet(ep).filter(r=>typeof r!="function"),t=n.facet(zy).filter(r=>typeof r!="function");return t.length&&e.push(We.join(t)),e}class Wy{constructor(e,t,r){let i=0,s=0,l=0;this.viewports=r.map(({from:o,to:u})=>{let h=t.lineAt(o,mt.ByPos,e,0,0).top,f=t.lineAt(u,mt.ByPos,e,0,0).bottom;return i+=f-h,{from:o,to:u,top:h,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-i)/(t.height-i);for(let o of this.viewports)o.domTop=l+(o.top-s)*this.scale,l=o.domBottom=o.domTop+(o.bottom-o.top),s=o.bottom}toDOM(e){for(let t=0,r=0,i=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return i+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,i=s.domBottom}}fromDOM(e){for(let t=0,r=0,i=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return r+(e-i)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,i=s.domBottom}}eq(e){return e instanceof Wy?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,r)=>t.from==e.viewports[r].from&&t.to==e.viewports[r].to):!1}}function Mu(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),r=e.toDOM(n.bottom);return new Zr(n.from,n.length,t,r-t,Array.isArray(n._content)?n._content.map(i=>Mu(i,e)):n._content)}const gf=ge.define({combine:n=>n.join(" ")}),Px=ge.define({combine:n=>n.indexOf(!0)>-1}),Cx=Bs.newName(),tQ=Bs.newName(),nQ=Bs.newName(),rQ={"&light":"."+tQ,"&dark":"."+nQ};function Qx(n,e,t){return new Bs(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,i=>{if(i=="&")return n;if(!t||!t[i])throw new RangeError(`Unsupported selector: ${i}`);return t[i]}):n+" "+r}})}const KL=Qx("."+Cx,{"&":{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,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",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":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .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:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&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",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&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,zIndex:300},"&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-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".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",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".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"}},rQ),JL={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Cg=xe.ie&&xe.ie_version<=11;class e3{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new jN,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.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let r of t)this.queue.push(r);(xe.ie&&xe.ie_version<=11||xe.ios&&e.composing)&&t.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&xe.android&&e.constructor.EDIT_CONTEXT!==!1&&!(xe.chrome&&xe.chrome_version<126)&&(this.editContext=new n3(e),e.state.facet(Zi)&&(e.contentDOM.editContext=this.editContext.editContext)),Cg&&(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),window.matchMedia&&(this.printQuery=window.matchMedia("print")),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.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")))},{threshold:[0,.001]}),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.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(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,r)=>t!=e[r]))){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:r}=this,i=this.selectionRange;if(r.state.facet(Zi)?r.root.activeElement!=this.dom:!_u(this.dom,i))return;let s=i.anchorNode&&r.docView.tile.nearest(i.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(xe.ie&&xe.ie_version<=11||xe.android&&xe.chrome)&&!r.state.selection.main.empty&&i.focusNode&&Iu(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=tc(e.root);if(!t)return!1;let r=xe.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&t3(this.view,t)||t;if(!r||this.selectionRange.eq(r))return!1;let i=_u(this.dom,r);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&MN(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),i&&(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 r=this.dom;r;)if(r.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=t)r.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,JL),Cg&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Cg&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var r;if(!this.delayedAndroidKey){let i=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&_o(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(i)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.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()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,r=-1,i=!1;for(let s of e){let l=this.readMutation(s);l&&(l.typeOver&&(i=!0),t==-1?{from:t,to:r}=l:(t=Math.min(l.from,t),r=Math.max(l.to,r)))}return{from:t,to:r,typeOver:i}}readChange(){let{from:e,to:t,typeOver:r}=this.processRecords(),i=this.selectionChanged&&_u(this.dom,this.selectionRange);if(e<0&&!i)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new yL(this.view,e,t,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let r=this.view.state,i=W2(this.view,t);return this.view.state==r&&(t.domChanged||t.newSel&&!hd(this.view.state.selection,t.newSel.main))&&this.view.update([]),i}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let r=Gb(t,e.previousSibling||e.target.previousSibling,-1),i=Gb(t,e.nextSibling||e.target.nextSibling,1);return{from:r?t.posAfter(r):t.posAtStart,to:i?t.posBefore(i):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),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):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),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Zi)!=e.state.facet(Zi)&&(e.view.contentDOM.editContext=e.state.facet(Zi)?this.editContext.editContext:null))}destroy(){var e,t,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Gb(n,e,t){for(;e;){let r=Pt.get(e);if(r&&r.parent==n)return r;let i=e.parentNode;e=i!=n.dom?i:t>0?e.nextSibling:e.previousSibling}return null}function Hb(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,s=e.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor,1);return Iu(l.node,l.offset,i,s)&&([t,r,i,s]=[i,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}}function t3(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return Hb(n,i)}let t=null;function r(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",r,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",r,!0),t?Hb(n,t):null}class n3{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let i=e.state.selection.main,{anchor:s,head:l}=i,o=this.toEditorPos(r.updateRangeStart),u=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:o,drifted:!1});let h=u-o>r.text.length;o==this.from&&s<this.from?o=s:u==this.to&&s>this.to&&(u=s);let f=q2(e.state.sliceDoc(o,u),r.text,(h?i.from:i.to)-o,h?"end":null);if(!f){let g=Y.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));hd(g,i)||e.dispatch({selection:g,userEvent:"select"});return}let p={from:f.from+o,to:f.toA+o,insert:Ge.of(r.text.slice(f.from,f.toB).split(`
76
- `))};if((xe.mac||xe.android)&&p.from==l-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(p={from:o,to:u,insert:Ge.of([r.text.replace("."," ")])}),this.pendingContextChange=p,!e.state.readOnly){let g=this.to-this.from+(p.to-p.from+p.insert.length);Xy(e,p,Y.single(this.toEditorPos(r.selectionStart,g),this.toEditorPos(r.selectionEnd,g)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),p.from<p.to&&!p.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(t.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let i=[],s=null;for(let l=this.toEditorPos(r.rangeStart),o=this.toEditorPos(r.rangeEnd);l<o;l++){let u=e.coordsForChar(l);s=u&&new DOMRect(u.left,u.top,u.right-u.left,u.bottom-u.top)||s||new DOMRect,i.push(s)}t.updateCharacterBounds(r.rangeStart,i)},this.handlers.textformatupdate=r=>{let i=[];for(let s of r.getTextFormats()){let l=s.underlineStyle,o=s.underlineThickness;if(!/none/i.test(l)&&!/none/i.test(o)){let u=this.toEditorPos(s.rangeStart),h=this.toEditorPos(s.rangeEnd);if(u<h){let f=`text-decoration: underline ${/^[a-z]/.test(l)?l+" ":l=="Dashed"?"dashed ":l=="Squiggle"?"wavy ":""}${/thin/i.test(o)?1:2}px`;i.push($e.mark({attributes:{style:f}}).range(u,h))}}}e.dispatch({effects:N2.of($e.set(i))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)t.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{this.editContext.updateControlBounds(r.contentDOM.getBoundingClientRect());let i=tc(r.root);i&&i.rangeCount&&this.editContext.updateSelectionBounds(i.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,r=!1,i=this.pendingContextChange;return e.changes.iterChanges((s,l,o,u,h)=>{if(r)return;let f=h.length-(l-s);if(i&&l>=i.to)if(i.from==s&&i.to==l&&i.insert.eq(h)){i=this.pendingContextChange=null,t+=f,this.to+=f;return}else i=null,this.revertPending(e.state);if(s+=t,l+=t,l<=this.from)this.from+=f,this.to+=f;else if(s<this.to){if(s<this.from||l>this.to||this.to-this.from+h.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(l),h.toString()),this.to+=f}t+=f}),i&&!r&&this.revertPending(e.state),!r}update(e){let t=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(i=>!i.isUserEvent("input.type")&&i.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),i=this.toContextPos(t.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=i)&&this.editContext.updateSelection(r,i)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class he{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&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;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.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(i=>i.forEach(s=>r(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=e.root||EN(e.parent)||document,this.viewState=new Fb(this,e.state||Fe.create(e)),e.scrollTo&&e.scrollTo.is(cf)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Mo).map(i=>new kg(i));for(let i of this.plugins)i.update(this);this.observer=new e3(this),this.inputState=new wL(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Rb(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof At?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}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,r=!1,i,s=this.state;for(let g of e){if(g.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=g.state}if(this.destroyed){this.viewState.state=s;return}let l=this.hasFocus,o=0,u=null;e.some(g=>g.annotation(H2))?(this.inputState.notifiedFocused=l,o=1):l!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=l,u=K2(s,l),u||(o=1));let h=this.observer.delayedAndroidKey,f=null;if(h?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(f=null)):this.observer.clear(),s.facet(Fe.phrases)!=this.state.facet(Fe.phrases))return this.setState(s);i=ad.create(this,s,e),i.flags|=o;let p=this.viewState.scrollTarget;try{this.updateState=2;for(let g of e){if(p&&(p=p.map(g.changes)),g.scrollIntoView){let{main:x}=g.state.selection,{x:k,y:b}=this.state.facet(he.cursorScrollMargin);p=new Do(x.empty?x:Y.cursor(x.head,x.head>x.anchor?-1:1),"nearest","nearest",b,k)}for(let x of g.effects)x.is(cf)&&(p=x.value.clip(this.state))}this.viewState.update(i,p),this.bidiCache=dd.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),t=this.docView.update(i),this.state.facet(Eu)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(g=>g.isUserEvent("select.pointer")))}finally{this.updateState=0}if(i.startState.facet(gf)!=i.state.facet(gf)&&(this.viewState.mustMeasureContent=!0),(t||r||p||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!i.empty)for(let g of this.state.facet(kx))try{g(i)}catch(x){Xn(this.state,x,"update listener")}(u||f)&&Promise.resolve().then(()=>{u&&this.state==u.startState&&this.dispatch(u),f&&!W2(this,f)&&h.force&&_o(this.contentDOM,h.key,h.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 r of this.plugins)r.destroy(this);this.viewState=new Fb(this,e),this.plugins=e.facet(Mo).map(r=>new kg(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Rb(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Mo),r=e.state.facet(Mo);if(t!=r){let i=[];for(let s of r){let l=t.indexOf(s);if(l<0)i.push(new kg(s));else{let o=this.plugins[l];o.mustUpdate=e,i.push(o)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=i,this.pluginMap.clear()}else for(let i of this.plugins)i.mustUpdate=e;for(let i=0;i<this.plugins.length;i++)this.plugins[i].update(this);t!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(r){Xn(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,r=this.viewState.scrollParent,i=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:l}=this.viewState;Math.abs(i-this.viewState.scrollOffset)>1&&(l=-1),this.viewState.scrollAnchorHeight=-1;try{for(let o=0;;o++){if(l<0)if(x2(r||this.win))s=-1,l=this.viewState.heightMap.height;else{let x=this.viewState.scrollAnchorAt(i);s=x.from,l=x.top}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(o>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];u&4||([this.measureRequests,h]=[h,this.measureRequests]);let f=h.map(x=>{try{return x.read(this)}catch(k){return Xn(this.state,k),Kb}}),p=ad.create(this,this.state,[]),g=!1;p.flags|=u,t?t.flags|=u:t=p,this.updateState=2,p.empty||(this.updatePlugins(p),this.inputState.update(p),this.updateAttrs(),g=this.docView.update(p),g&&this.docViewUpdate());for(let x=0;x<h.length;x++)if(f[x]!=Kb)try{let k=h[x];k.write&&k.write(f[x],this)}catch(k){Xn(this.state,k)}if(g&&this.docView.updateSelection(!0),!p.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,l=-1;continue}else{let k=((s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)-l)/this.scaleY;if((k>1||k<-1)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){i=i+k,r?r.scrollTop+=k:this.win.scrollBy(0,k),l=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let o of this.state.facet(kx))o(t)}get themeClasses(){return Cx+" "+(this.state.facet(Px)?nQ:tQ)+" "+this.state.facet(gf)}updateAttrs(){let e=Jb(this,L2,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Zi)?"true":"false",class:"cm-content",style:`${xe.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Jb(this,Iy,t);let r=this.observer.ignore(()=>{let i=$b(this.contentDOM,this.contentAttrs,t),s=$b(this.dom,this.editorAttrs,e);return i||s});return this.editorAttrs=e,this.contentAttrs=t,r}showAnnouncements(e){let t=!0;for(let r of e)for(let i of r.effects)if(i.is(he.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=i.value}}mountStyles(){this.styleModules=this.state.facet(Eu);let e=this.state.facet(he.cspNonce);Bs.mount(this.root,this.styleModules.concat(KL).reverse(),e?{nonce:e}:void 0)}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.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(r=>r.plugin==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}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}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,r){return Sg(this,e,Nb(this,e,t,r))}moveByGroup(e,t){return Sg(this,e,Nb(this,e,t,r=>dL(this,e.head,r)))}visualLineSide(e,t){let r=this.bidiSpans(e),i=this.textDirectionAt(e.from),s=r[t?r.length-1:0];return Y.cursor(s.side(t,i)+e.from,s.forward(!t,i)?1:-1)}moveToLineBoundary(e,t,r=!0){return fL(this,e,t,r)}moveVertically(e,t,r){return Sg(this,e,pL(this,e,t,r))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let r=wx(this,e,t);return r&&r.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),wx(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let r=this.docView.coordsAt(e,t);if(!r||r.left==r.right)return r;let i=this.state.doc.lineAt(e),s=this.bidiSpans(i),l=s[di.find(s,e-i.from,-1,t)];return nc(r,l.dir==ht.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}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(M2)||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>r3)return S2(e.length);let t=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||w2(s.isolates,r=Eb(this,e))))return s.order;r||(r=Eb(this,e));let i=IN(e.text,t,r);return this.bidiCache.push(new dd(e.from,e.to,t,r,!0,i)),i}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||xe.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{O2(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(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var r,i,s,l;return cf.of(new Do(typeof e=="number"?Y.cursor(e):e,(r=t.y)!==null&&r!==void 0?r:"nearest",(i=t.x)!==null&&i!==void 0?i:"nearest",(s=t.yMargin)!==null&&s!==void 0?s:5,(l=t.xMargin)!==null&&l!==void 0?l:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return cf.of(new Do(Y.cursor(r.from),"start","start",r.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Ct.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Ct.define(()=>({}),{eventObservers:e})}static theme(e,t){let r=Bs.newName(),i=[gf.of(r),Eu.of(Qx(`.${r}`,e))];return t&&t.dark&&i.push(Px.of(!0)),i}static baseTheme(e){return Ui.lowest(Eu.of(Qx("."+Cx,e,rQ)))}static findFromDOM(e){var t;let r=e.querySelector(".cm-content"),i=r&&Pt.get(r)||Pt.get(e);return((t=i==null?void 0:i.root)===null||t===void 0?void 0:t.view)||null}}he.styleModule=Eu;he.inputHandler=j2;he.clipboardInputFilter=_y;he.clipboardOutputFilter=Dy;he.scrollHandler=R2;he.focusChangeEffect=E2;he.perLineTextDirection=M2;he.exceptionSink=T2;he.updateListener=kx;he.editable=Zi;he.mouseSelectionStyle=$2;he.dragMovesSelection=Q2;he.clickAddsSelectionRange=C2;he.decorations=ep;he.blockWrappers=_2;he.outerDecorations=zy;he.atomicRanges=Nc;he.bidiIsolatedRanges=D2;he.cursorScrollMargin=ge.define({combine:n=>{let e=5,t=5;for(let r of n)typeof r=="number"?e=t=r:{x:e,y:t}=r;return{x:e,y:t}}});he.scrollMargins=I2;he.darkTheme=Px;he.cspNonce=ge.define({combine:n=>n.length?n[0]:""});he.contentAttributes=Iy;he.editorAttributes=L2;he.lineWrapping=he.contentAttributes.of({class:"cm-lineWrapping"});he.announce=Ne.define();const r3=4096,Kb={};class dd{constructor(e,t,r,i,s,l){this.from=e,this.to=t,this.dir=r,this.isolates=i,this.fresh=s,this.order=l}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let r=[],i=e.length?e[e.length-1].dir:ht.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let l=e[s];l.dir==i&&!t.touchesRange(l.from,l.to)&&r.push(new dd(t.mapPos(l.from,1),t.mapPos(l.to,-1),l.dir,l.isolates,!1,l.order))}return r}}function Jb(n,e,t){for(let r=n.state.facet(e),i=r.length-1;i>=0;i--){let s=r[i],l=typeof s=="function"?s(n):s;l&&Ry(l,t)}return t}const i3=xe.mac?"mac":xe.windows?"win":xe.linux?"linux":"key";function s3(n,e){const t=n.split(/-(?!$)/);let r=t[t.length-1];r=="Space"&&(r=" ");let i,s,l,o;for(let u=0;u<t.length-1;++u){const h=t[u];if(/^(cmd|meta|m)$/i.test(h))o=!0;else if(/^a(lt)?$/i.test(h))i=!0;else if(/^(c|ctrl|control)$/i.test(h))s=!0;else if(/^s(hift)?$/i.test(h))l=!0;else if(/^mod$/i.test(h))e=="mac"?o=!0:s=!0;else throw new Error("Unrecognized modifier name: "+h)}return i&&(r="Alt-"+r),s&&(r="Ctrl-"+r),o&&(r="Meta-"+r),l&&(r="Shift-"+r),r}function Of(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const l3=Ui.default(he.domEventHandlers({keydown(n,e){return sQ(iQ(e.state),n,e,"editor")}})),ba=ge.define({enables:l3}),ew=new WeakMap;function iQ(n){let e=n.facet(ba),t=ew.get(e);return t||ew.set(e,t=u3(e.reduce((r,i)=>r.concat(i),[]))),t}function o3(n,e,t){return sQ(iQ(n.state),e,n,t)}let Qs=null;const a3=4e3;function u3(n,e=i3){let t=Object.create(null),r=Object.create(null),i=(l,o)=>{let u=r[l];if(u==null)r[l]=o;else if(u!=o)throw new Error("Key binding "+l+" is used both as a regular binding and as a multi-stroke prefix")},s=(l,o,u,h,f)=>{var p,g;let x=t[l]||(t[l]=Object.create(null)),k=o.split(/ (?!$)/).map(S=>s3(S,e));for(let S=1;S<k.length;S++){let Q=k.slice(0,S).join(" ");i(Q,!0),x[Q]||(x[Q]={preventDefault:!0,stopPropagation:!1,run:[$=>{let R=Qs={view:$,prefix:Q,scope:l};return setTimeout(()=>{Qs==R&&(Qs=null)},a3),!0}]})}let b=k.join(" ");i(b,!1);let w=x[b]||(x[b]={preventDefault:!1,stopPropagation:!1,run:((g=(p=x._any)===null||p===void 0?void 0:p.run)===null||g===void 0?void 0:g.slice())||[]});u&&w.run.push(u),h&&(w.preventDefault=!0),f&&(w.stopPropagation=!0)};for(let l of n){let o=l.scope?l.scope.split(" "):["editor"];if(l.any)for(let h of o){let f=t[h]||(t[h]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:p}=l;for(let g in f)f[g].run.push(x=>p(x,$x))}let u=l[e]||l.key;if(u)for(let h of o)s(h,u,l.run,l.preventDefault,l.stopPropagation),l.shift&&s(h,"Shift-"+u,l.shift,l.preventDefault,l.stopPropagation)}return t}let $x=null;function sQ(n,e,t,r){$x=e;let i=SN(e),s=In(i,0),l=hi(s)==i.length&&i!=" ",o="",u=!1,h=!1,f=!1;Qs&&Qs.view==t&&Qs.scope==r&&(o=Qs.prefix+" ",F2.indexOf(e.keyCode)<0&&(h=!0,Qs=null));let p=new Set,g=w=>{if(w){for(let S of w.run)if(!p.has(S)&&(p.add(S),S(t)))return w.stopPropagation&&(f=!0),!0;w.preventDefault&&(w.stopPropagation&&(f=!0),h=!0)}return!1},x=n[r],k,b;return x&&(g(x[o+Of(i,e,!l)])?u=!0:l&&(e.altKey||e.metaKey||e.ctrlKey)&&!(xe.windows&&e.ctrlKey&&e.altKey)&&!(xe.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(k=Ws[e.keyCode])&&k!=i?(g(x[o+Of(k,e,!0)])||e.shiftKey&&(b=Ju[e.keyCode])!=i&&b!=k&&g(x[o+Of(b,e,!1)]))&&(u=!0):l&&e.shiftKey&&g(x[o+Of(i,e,!0)])&&(u=!0),!u&&g(x._any)&&(u=!0)),h&&(u=!0),u&&f&&e.stopPropagation(),$x=null,u}class Ll{constructor(e,t,r,i,s){this.className=e,this.left=t,this.top=r,this.width=i,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,r){if(r.empty){let i=e.coordsAtPos(r.head,r.assoc||1);if(!i)return[];let s=lQ(e);return[new Ll(t,i.left-s.left,i.top-s.top,null,i.bottom-i.top)]}else return c3(e,t,r)}}function lQ(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==ht.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function tw(n,e,t,r){let i=n.coordsAtPos(e,t*2);if(!i)return r;let s=n.dom.getBoundingClientRect(),l=(i.top+i.bottom)/2,o=n.posAtCoords({x:s.left+1,y:l}),u=n.posAtCoords({x:s.right-1,y:l});return o==null||u==null?r:{from:Math.max(r.from,Math.min(o,u)),to:Math.min(r.to,Math.max(o,u))}}function c3(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let r=Math.max(t.from,n.viewport.from),i=Math.min(t.to,n.viewport.to),s=n.textDirection==ht.LTR,l=n.contentDOM,o=l.getBoundingClientRect(),u=lQ(n),h=l.querySelector(".cm-line"),f=h&&window.getComputedStyle(h),p=o.left+(f?parseInt(f.paddingLeft)+Math.min(0,parseInt(f.textIndent)):0),g=o.right-(f?parseInt(f.paddingRight):0),x=bx(n,r,1),k=bx(n,i,-1),b=x.type==ln.Text?x:null,w=k.type==ln.Text?k:null;if(b&&(n.lineWrapping||x.widgetLineBreaks)&&(b=tw(n,r,1,b)),w&&(n.lineWrapping||k.widgetLineBreaks)&&(w=tw(n,i,-1,w)),b&&w&&b.from==w.from&&b.to==w.to)return Q($(t.from,t.to,b));{let I=b?$(t.from,null,b):R(x,!1),T=w?$(null,t.to,w):R(k,!0),X=[];return(b||x).to<(w||k).from-(b&&w?1:0)||x.widgetLineBreaks>1&&I.bottom+n.defaultLineHeight/2<T.top?X.push(S(p,I.bottom,g,T.top)):I.bottom<T.top&&n.elementAtHeight((I.bottom+T.top)/2).type==ln.Text&&(I.bottom=T.top=(I.bottom+T.top)/2),Q(I).concat(X).concat(Q(T))}function S(I,T,X,Z){return new Ll(e,I-u.left,T-u.top,Math.max(0,X-I),Z-T)}function Q({top:I,bottom:T,horizontal:X}){let Z=[];for(let H=0;H<X.length;H+=2)Z.push(S(X[H],I,X[H+1],T));return Z}function $(I,T,X){let Z=1e9,H=-1e9,N=[];function U(K,G,Oe,de,ee){let le=n.coordsAtPos(K,K==X.to?-2:2),C=n.coordsAtPos(Oe,Oe==X.from?2:-2);!le||!C||(Z=Math.min(le.top,C.top,Z),H=Math.max(le.bottom,C.bottom,H),ee==ht.LTR?N.push(s&&G?p:le.left,s&&de?g:C.right):N.push(!s&&de?p:C.left,!s&&G?g:le.right))}let V=I??X.from,se=T??X.to;for(let K of n.visibleRanges)if(K.to>V&&K.from<se)for(let G=Math.max(K.from,V),Oe=Math.min(K.to,se);;){let de=n.state.doc.lineAt(G);for(let ee of n.bidiSpans(de)){let le=ee.from+de.from,C=ee.to+de.from;if(le>=Oe)break;C>G&&U(Math.max(le,G),I==null&&le<=V,Math.min(C,Oe),T==null&&C>=se,ee.dir)}if(G=de.to+1,G>=Oe)break}return N.length==0&&U(V,I==null,se,T==null,n.textDirection),{top:Z,bottom:H,horizontal:N}}function R(I,T){let X=o.top+(T?I.top:I.bottom);return{top:X,bottom:X,horizontal:[]}}}function h3(n,e){return n.constructor==e.constructor&&n.eq(e)}class f3{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,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.scale(),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(Xf)!=e.state.facet(Xf)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,r=e.facet(Xf);for(;t<r.length&&r[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,r)=>!h3(t,this.drawn[r]))){let t=this.dom.firstChild,r=0;for(let i of e)i.update&&t&&i.constructor&&this.drawn[r].constructor&&i.update(t,this.drawn[r])?(t=t.nextSibling,r++):this.dom.insertBefore(i.draw(),t);for(;t;){let i=t.nextSibling;t.remove(),t=i}this.drawn=e,xe.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Xf=ge.define();function oQ(n){return[Ct.define(e=>new f3(e,n)),Xf.of(n)]}const oa=ge.define({combine(n){return bi(n,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function d3(n={}){return[oa.of(n),p3,m3,g3,A2.of(!0)]}function aQ(n){return n.startState.facet(oa)!=n.state.facet(oa)}const p3=oQ({above:!0,markers(n){let{state:e}=n,t=e.facet(oa),r=[];for(let i of e.selection.ranges){let s=i==e.selection.main;if(i.empty||t.drawRangeCursor&&!(s&&xe.ios&&t.iosSelectionHandles)){let l=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",o=i.empty?i:Y.cursor(i.head,i.assoc);for(let u of Ll.forRange(n,l,o))r.push(u)}}return r},update(n,e){n.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=aQ(n);return t&&nw(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){nw(e.state,n)},class:"cm-cursorLayer"});function nw(n,e){e.style.animationDuration=n.facet(oa).cursorBlinkRate+"ms"}const m3=oQ({above:!1,markers(n){let e=[],{main:t,ranges:r}=n.state.selection;for(let i of r)if(!i.empty)for(let s of Ll.forRange(n,"cm-selectionBackground",i))e.push(s);if(xe.ios&&!t.empty&&n.state.facet(oa).iosSelectionHandles){for(let i of Ll.forRange(n,"cm-selectionHandle cm-selectionHandle-start",Y.cursor(t.from,1)))e.push(i);for(let i of Ll.forRange(n,"cm-selectionHandle cm-selectionHandle-end",Y.cursor(t.to,1)))e.push(i)}return e},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||aQ(n)},class:"cm-selectionLayer"}),g3=Ui.highest(he.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),uQ=Ne.define({map(n,e){return n==null?null:e.mapPos(n)}}),Au=an.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,r)=>r.is(uQ)?r.value:t,n)}}),O3=Ct.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var e;let t=n.state.field(Au);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(Au)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,e=n.state.field(Au),t=e!=null&&n.coordsAtPos(e);if(!t)return null;let r=n.scrollDOM.getBoundingClientRect();return{left:t.left-r.left+n.scrollDOM.scrollLeft*n.scaleX,top:t.top-r.top+n.scrollDOM.scrollTop*n.scaleY,height:t.bottom-t.top}}drawCursor(n){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;n?(this.cursor.style.left=n.left/e+"px",this.cursor.style.top=n.top/t+"px",this.cursor.style.height=n.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(Au)!=n&&this.view.dispatch({effects:uQ.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function x3(){return[Au,O3]}function rw(n,e,t,r,i){e.lastIndex=0;for(let s=n.iterRange(t,r),l=t,o;!s.next().done;l+=s.value.length)if(!s.lineBreak)for(;o=e.exec(s.value);)i(l+o.index,o)}function y3(n,e){let t=n.visibleRanges;if(t.length==1&&t[0].from==n.viewport.from&&t[0].to==n.viewport.to)return t;let r=[];for(let{from:i,to:s}of t)i=Math.max(n.state.doc.lineAt(i).from,i-e),s=Math.min(n.state.doc.lineAt(s).to,s+e),r.length&&r[r.length-1].to>=i?r[r.length-1].to=s:r.push({from:i,to:s});return r}class k3{constructor(e){const{regexp:t,decoration:r,decorate:i,boundary:s,maxLength:l=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,i)this.addMatch=(o,u,h,f)=>i(f,h,h+o[0].length,o,u);else if(typeof r=="function")this.addMatch=(o,u,h,f)=>{let p=r(o,u,h);p&&f(h,h+o[0].length,p)};else if(r)this.addMatch=(o,u,h,f)=>f(h,h+o[0].length,r);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=s,this.maxLength=l}createDeco(e){let t=new qi,r=t.add.bind(t);for(let{from:i,to:s}of y3(e,this.maxLength))rw(e.state.doc,this.regexp,i,s,(l,o)=>this.addMatch(o,e,l,r));return t.finish()}updateDeco(e,t){let r=1e9,i=-1;return e.docChanged&&e.changes.iterChanges((s,l,o,u)=>{u>=e.view.viewport.from&&o<=e.view.viewport.to&&(r=Math.min(o,r),i=Math.max(u,i))}),e.viewportMoved||i-r>1e3?this.createDeco(e.view):i>-1?this.updateRange(e.view,t.map(e.changes),r,i):t}updateRange(e,t,r,i){for(let s of e.visibleRanges){let l=Math.max(s.from,r),o=Math.min(s.to,i);if(o>=l){let u=e.state.doc.lineAt(l),h=u.to<o?e.state.doc.lineAt(o):u,f=Math.max(s.from,u.from),p=Math.min(s.to,h.to);if(this.boundary){for(;l>u.from;l--)if(this.boundary.test(u.text[l-1-u.from])){f=l;break}for(;o<h.to;o++)if(this.boundary.test(h.text[o-h.from])){p=o;break}}let g=[],x,k=(b,w,S)=>g.push(S.range(b,w));if(u==h)for(this.regexp.lastIndex=f-u.from;(x=this.regexp.exec(u.text))&&x.index<p-u.from;)this.addMatch(x,e,x.index+u.from,k);else rw(e.state.doc,this.regexp,f,p,(b,w)=>this.addMatch(w,e,b,k));t=t.update({filterFrom:f,filterTo:p,filter:(b,w)=>b<f||w>p,add:g})}}return t}}const Tx=/x/.unicode!=null?"gu":"g",v3=new RegExp(`[\0-\b
75
+ `&&n.lineWrapping&&(r&&(r=Y.single(r.main.anchor-1,r.main.head-1)),t={from:s.from,to:s.to,insert:Ge.of([" "])}),t)return Xy(n,t,r,l);if(r&&!hd(r,s)){let o=!1,u="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(o=!0),u=n.inputState.lastSelectionOrigin,u=="select.pointer"&&(r=X2(i.facet(Nc).map(h=>h(n)),r))),n.dispatch({selection:r,scrollIntoView:o,userEvent:u}),!0}else return!1}function Xy(n,e,t,r=-1){if(xe.ios&&n.inputState.flushIOSKey(e))return!0;let i=n.state.selection.main;if(xe.android&&(e.to==i.to&&(e.from==i.from||e.from==i.from-1&&n.state.sliceDoc(e.from,i.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&_o(n.contentDOM,"Enter",13)||(e.from==i.from-1&&e.to==i.to&&e.insert.length==0||r==8&&e.insert.length<e.to-e.from&&e.to>i.head)&&_o(n.contentDOM,"Backspace",8)||e.from==i.from&&e.to==i.to+1&&e.insert.length==0&&_o(n.contentDOM,"Delete",46)))return!0;let s=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let l,o=()=>l||(l=kL(n,e,t));return n.state.facet(j2).some(u=>u(n,e.from,e.to,s,o))||n.dispatch(o()),!0}function kL(n,e,t){let r,i=n.state,s=i.selection.main,l=-1;if(e.from==e.to&&e.from<s.from||e.from>s.to){let u=e.from<s.from?-1:1,h=u<0?s.from:s.to,f=zu(i.facet(Nc).map(p=>p(n)),h,u);e.from==f&&(l=f)}if(l>-1)r={changes:e,selection:Y.cursor(e.from+e.insert.length,-1)};else if(e.from>=s.from&&e.to<=s.to&&e.to-e.from>=(s.to-s.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let u=s.from<e.from?i.sliceDoc(s.from,e.from):"",h=s.to>e.to?i.sliceDoc(e.to,s.to):"";r=i.replaceSelection(n.state.toText(u+e.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let u=i.changes(e),h=t&&t.main.to<=u.newLength?t.main:void 0;if(i.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=s.to+10&&e.to>=s.to-10){let f=n.state.sliceDoc(e.from,e.to),p,g=t&&Z2(n,t.main.head);if(g){let k=e.insert.length-(e.to-e.from);p={from:g.from,to:g.to-k}}else p=n.state.doc.lineAt(s.head);let x=s.to-e.to;r=i.changeByRange(k=>{if(k.from==s.from&&k.to==s.to)return{changes:u,range:h||k.map(u)};let b=k.to-x,w=b-f.length;if(n.state.sliceDoc(w,b)!=f||b>=p.from&&w<=p.to)return{range:k};let S=i.changes({from:w,to:b,insert:e.insert}),Q=k.to-s.to;return{changes:S,range:h?Y.range(Math.max(0,h.anchor+Q),Math.max(0,h.head+Q)):k.map(S)}})}else r={changes:u,selection:h&&i.selection.replaceRange(h)}}let o="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,o+=".compose",n.inputState.compositionFirstChange&&(o+=".start",n.inputState.compositionFirstChange=!1)),i.update(r,{userEvent:o,scrollIntoView:!0})}function q2(n,e,t,r){let i=Math.min(n.length,e.length),s=0;for(;s<i&&n.charCodeAt(s)==e.charCodeAt(s);)s++;if(s==i&&n.length==e.length)return null;let l=n.length,o=e.length;for(;l>0&&o>0&&n.charCodeAt(l-1)==e.charCodeAt(o-1);)l--,o--;if(r=="end"){let u=Math.max(0,s-Math.min(l,o));t-=l+u-s}if(l<s&&n.length<e.length){let u=t<=s&&t>=l?s-t:0;s-=u,o=s+(o-l),l=s}else if(o<s){let u=t<=s&&t>=o?s-t:0;s-=u,l=s+(l-o),o=s}return{from:s,toA:l,toB:o}}function vL(n){let e=[];if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}=n.observer.selectionRange;return t&&(e.push(new Lb(t,r)),(i!=t||s!=r)&&e.push(new Lb(i,s))),e}function bL(n,e){if(n.length==0)return null;let t=n[0].pos,r=n.length==2?n[1].pos:t;return t>-1&&r>-1?Y.single(t+e,r+e):null}function hd(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}class wL{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,xe.safari&&e.contentDOM.addEventListener("input",()=>null),xe.gecko&&DL(e.contentDOM.ownerDocument)}handleEvent(e){!EL(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let r=this.handlers[e];if(r){for(let i of r.observers)i(this.view,t);for(let i of r.handlers){if(t.defaultPrevented)break;if(i(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=SL(e),r=this.handlers,i=this.view.contentDOM;for(let s in t)if(s!="scroll"){let l=!t[s].handlers.length,o=r[s];o&&l!=!o.handlers.length&&(i.removeEventListener(s,this.handleEvent),o=null),o||i.addEventListener(s,this.handleEvent,{passive:l})}for(let s in r)s!="scroll"&&!t[s]&&i.removeEventListener(s,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&F2.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),xe.android&&xe.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return xe.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=V2.find(r=>r.keyCode==e.keyCode))&&!e.ctrlKey||PL.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,_o(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:xe.safari&&!xe.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function _b(n,e){return(t,r)=>{try{return e.call(n,r,t)}catch(i){Xn(t.state,i)}}}function SL(n){let e=Object.create(null);function t(r){return e[r]||(e[r]={observers:[],handlers:[]})}for(let r of n){let i=r.spec,s=i&&i.plugin.domEventHandlers,l=i&&i.plugin.domEventObservers;if(s)for(let o in s){let u=s[o];u&&t(o).handlers.push(_b(r.value,u))}if(l)for(let o in l){let u=l[o];u&&t(o).observers.push(_b(r.value,u))}}for(let r in qr)t(r).handlers.push(qr[r]);for(let r in Wn)t(r).observers.push(Wn[r]);return e}const V2=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],PL="dthko",F2=[16,17,18,20,91,92,224,225],hf=6;function ff(n){return Math.max(0,n)*.7+8}function CL(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class QL{constructor(e,t,r,i){this.view=e,this.startEvent=t,this.style=r,this.mustSelect=i,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=g2(e.contentDOM),this.atoms=e.state.facet(Nc).map(l=>l(e));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(Fe.allowMultipleSelections)&&$L(e,t),this.dragging=jL(e,t)&&G2(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&CL(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,r=0,i=0,s=0,l=this.view.win.innerWidth,o=this.view.win.innerHeight;this.scrollParents.x&&({left:i,right:l}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:s,bottom:o}=this.scrollParents.y.getBoundingClientRect());let u=Zy(this.view);e.clientX-u.left<=i+hf?t=-ff(i-e.clientX):e.clientX+u.right>=l-hf&&(t=ff(e.clientX-l)),e.clientY-u.top<=s+hf?r=-ff(s-e.clientY):e.clientY+u.bottom>=o-hf&&(r=ff(e.clientY-o)),this.setScrollSpeed(t,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=this.view.inputState.draggedContent=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(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,r=X2(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!r.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:r,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function $L(n,e){let t=n.state.facet(C2);return t.length?t[0](e):xe.mac?e.metaKey:e.ctrlKey}function TL(n,e){let t=n.state.facet(Q2);return t.length?t[0](e):xe.mac?!e.altKey:!e.ctrlKey}function jL(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let r=tc(n.root);if(!r||r.rangeCount==0)return!0;let i=r.getRangeAt(0).getClientRects();for(let s=0;s<i.length;s++){let l=i[s];if(l.left<=e.clientX&&l.right>=e.clientX&&l.top<=e.clientY&&l.bottom>=e.clientY)return!0}return!1}function EL(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,r;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(r=Pt.get(t))&&r.isWidget()&&!r.isHidden&&r.widget.ignoreEvent(e))return!1;return!0}const qr=Object.create(null),Wn=Object.create(null),Y2=xe.ie&&xe.ie_version<15||xe.ios&&xe.webkit_version<604;function ML(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),U2(n,t.value)},50)}function rp(n,e,t){for(let r of n.facet(e))t=r(t,n);return t}function U2(n,e){e=rp(n.state,_y,e);let{state:t}=n,r,i=1,s=t.toText(e),l=s.lines==t.selection.ranges.length;if(Sx!=null&&t.selection.ranges.every(u=>u.empty)&&Sx==s.toString()){let u=-1;r=t.changeByRange(h=>{let f=t.doc.lineAt(h.from);if(f.from==u)return{range:h};u=f.from;let p=t.toText((l?s.line(i++).text:e)+t.lineBreak);return{changes:{from:f.from,insert:p},range:Y.cursor(h.from+p.length)}})}else l?r=t.changeByRange(u=>{let h=s.line(i++);return{changes:{from:u.from,to:u.to,insert:h.text},range:Y.cursor(u.from+h.length)}}):r=t.replaceSelection(s);n.dispatch(r,{userEvent:"input.paste",scrollIntoView:!0})}Wn.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};Wn.wheel=Wn.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};qr.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);Wn.touchstart=(n,e)=>{let t=n.inputState,r=e.targetTouches[0];t.lastTouchTime=Date.now(),r&&(t.lastTouchX=r.clientX,t.lastTouchY=r.clientY),t.setSelectionOrigin("select.pointer")};Wn.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};qr.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let r of n.state.facet($2))if(t=r(n,e),t)break;if(!t&&e.button==0&&(t=RL(n,e)),t){let r=!n.hasFocus;n.inputState.startMouseSelection(new QL(n,e,t,r)),r&&n.observer.ignore(()=>{O2(n.contentDOM);let s=n.root.activeElement;s&&!s.contains(n.contentDOM)&&s.blur()});let i=n.inputState.mouseSelection;if(i)return i.start(e),i.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Db(n,e,t,r){if(r==1)return Y.cursor(e,t);if(r==2)return cL(n.state,e,t);{let i=n.docView.lineAt(e,t),s=n.state.doc.lineAt(i?i.posAtEnd:e),l=i?i.posAtStart:s.from,o=i?i.posAtEnd:s.to;return o<n.state.doc.length&&o==s.to&&o++,Y.range(l,o)}}const AL=xe.ie&&xe.ie_version<=11;let Ib=null,zb=0,Zb=0;function G2(n){if(!AL)return n.detail;let e=Ib,t=Zb;return Ib=n,Zb=Date.now(),zb=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(zb+1)%3:1}function RL(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),r=G2(e),i=n.state.selection;return{update(s){s.docChanged&&(t.pos=s.changes.mapPos(t.pos),i=i.map(s.changes))},get(s,l,o){let u=n.posAndSideAtCoords({x:s.clientX,y:s.clientY},!1),h,f=Db(n,u.pos,u.assoc,r);if(t.pos!=u.pos&&!l){let p=Db(n,t.pos,t.assoc,r),g=Math.min(p.from,f.from),x=Math.max(p.to,f.to);f=g<f.from?Y.range(g,x,f.assoc):Y.range(x,g,f.assoc)}return l?i.replaceRange(i.main.extend(f.from,f.to,f.assoc)):o&&r==1&&i.ranges.length>1&&(h=NL(i,u.pos))?h:o?i.addRange(f):Y.create([f])}}}function NL(n,e){for(let t=0;t<n.ranges.length;t++){let{from:r,to:i}=n.ranges[t];if(r<=e&&i>=e)return Y.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}qr.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let i=n.docView.tile.nearest(e.target);if(i&&i.isWidget()){let s=i.posAtStart,l=s+i.length;(s>=t.to||l<=t.from)&&(t=Y.range(s,l))}}let{inputState:r}=n;return r.mouseSelection&&(r.mouseSelection.dragging=!0),r.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",rp(n.state,Dy,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};qr.dragend=n=>(n.inputState.draggedContent=null,!1);function Xb(n,e,t,r){if(t=rp(n.state,_y,t),!t)return;let i=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:s}=n.inputState,l=r&&s&&TL(n,e)?{from:s.from,to:s.to}:null,o={from:i,insert:t},u=n.state.changes(l?[l,o]:o);n.focus(),n.dispatch({changes:u,selection:{anchor:u.mapPos(i,-1),head:u.mapPos(i,1)},userEvent:l?"move.drop":"input.drop"}),n.inputState.draggedContent=null}qr.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let r=Array(t.length),i=0,s=()=>{++i==t.length&&Xb(n,e,r.filter(l=>l!=null).join(n.state.lineBreak),!1)};for(let l=0;l<t.length;l++){let o=new FileReader;o.onerror=s,o.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(o.result)||(r[l]=o.result),s()},o.readAsText(t[l])}return!0}else{let r=e.dataTransfer.getData("Text");if(r)return Xb(n,e,r,!0),!0}return!1};qr.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=Y2?null:e.clipboardData;return t?(U2(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(ML(n),!1)};function LL(n,e){let t=n.dom.parentNode;if(!t)return;let r=t.appendChild(document.createElement("textarea"));r.style.cssText="position: fixed; left: -10000px; top: 10px",r.value=e,r.focus(),r.selectionEnd=e.length,r.selectionStart=0,setTimeout(()=>{r.remove(),n.focus()},50)}function _L(n){let e=[],t=[],r=!1;for(let i of n.selection.ranges)i.empty||(e.push(n.sliceDoc(i.from,i.to)),t.push(i));if(!e.length){let i=-1;for(let{from:s}of n.selection.ranges){let l=n.doc.lineAt(s);l.number>i&&(e.push(l.text),t.push({from:l.from,to:Math.min(n.doc.length,l.to+1)})),i=l.number}r=!0}return{text:rp(n,Dy,e.join(n.lineBreak)),ranges:t,linewise:r}}let Sx=null;qr.copy=qr.cut=(n,e)=>{if(!_u(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:r,linewise:i}=_L(n.state);if(!t&&!i)return!1;Sx=i?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:r,scrollIntoView:!0,userEvent:"delete.cut"});let s=Y2?null:e.clipboardData;return s?(s.clearData(),s.setData("text/plain",t),!0):(LL(n,t),!1)};const H2=vi.define();function K2(n,e){let t=[];for(let r of n.facet(E2)){let i=r(n,e);i&&t.push(i)}return t.length?n.update({effects:t,annotations:H2.of(!0)}):null}function J2(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=K2(n.state,e);t?n.dispatch(t):n.update([])}},10)}Wn.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),J2(n)};Wn.blur=n=>{n.observer.clearSelectionRange(),J2(n)};Wn.compositionstart=Wn.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};Wn.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,xe.chrome&&xe.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};Wn.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};qr.beforeinput=(n,e)=>{var t,r;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let s=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),l=e.getTargetRanges();if(s&&l.length){let o=l[0],u=n.posAtDOM(o.startContainer,o.startOffset),h=n.posAtDOM(o.endContainer,o.endOffset);return Xy(n,{from:u,to:h,insert:n.state.toText(s)},null),!0}}let i;if(xe.chrome&&xe.android&&(i=V2.find(s=>s.inputType==e.inputType))&&(n.observer.delayAndroidKey(i.key,i.keyCode),i.key=="Backspace"||i.key=="Delete")){let s=((r=window.visualViewport)===null||r===void 0?void 0:r.height)||0;setTimeout(()=>{var l;(((l=window.visualViewport)===null||l===void 0?void 0:l.height)||0)>s+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return xe.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),xe.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>Wn.compositionend(n,e),20),!1};const Bb=new Set;function DL(n){Bb.has(n)||(Bb.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Wb=["pre-wrap","normal","pre-line","break-spaces"];let la=!1;function qb(){la=!1}class IL{constructor(e){this.lineWrapping=e,this.doc=Ge.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let r=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(r+=Math.max(0,Math.ceil((t-e-r*this.lineLength*.5)/this.lineLength))),this.lineHeight*r}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Wb.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let r=0;r<e.length;r++){let i=e[r];i<0?r++:this.heightSamples[Math.floor(i*10)]||(t=!0,this.heightSamples[Math.floor(i*10)]=!0)}return t}refresh(e,t,r,i,s,l){let o=Wb.indexOf(e)>-1,u=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=o;if(this.lineWrapping=o,this.lineHeight=t,this.charWidth=r,this.textHeight=i,this.lineLength=s,u){this.heightSamples={};for(let h=0;h<l.length;h++){let f=l[h];f<0?h++:this.heightSamples[Math.floor(f*10)]=!0}}return u}}class zL{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class Zr{constructor(e,t,r,i,s){this.from=e,this.length=t,this.top=r,this.height=i,this._content=s}get type(){return typeof this._content=="number"?ln.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof zl?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new Zr(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var mt=(function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n})(mt||(mt={}));const Zf=.001;class $n{constructor(e,t,r=2){this.length=e,this.height=t,this.flags=r}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Zf&&(la=!0),this.height=e)}replace(e,t,r){return $n.of(r)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,r,i){let s=this,l=r.doc;for(let o=i.length-1;o>=0;o--){let{fromA:u,toA:h,fromB:f,toB:p}=i[o],g=s.lineAt(u,mt.ByPosNoHeight,r.setDoc(t),0,0),x=g.to>=h?g:s.lineAt(h,mt.ByPosNoHeight,r,0,0);for(p+=x.to-h,h=x.to;o>0&&g.from<=i[o-1].toA;)u=i[o-1].fromA,f=i[o-1].fromB,o--,u<g.from&&(g=s.lineAt(u,mt.ByPosNoHeight,r,0,0));f+=g.from-u,u=g.from;let k=By.build(r.setDoc(l),e,f,p);s=fd(s,s.replace(u,h,k))}return s.updateHeight(r,0)}static empty(){return new lr(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,r=e.length,i=0,s=0;for(;;)if(t==r)if(i>s*2){let o=e[t-1];o.break?e.splice(--t,1,o.left,null,o.right):e.splice(--t,1,o.left,o.right),r+=1+o.break,i-=o.size}else if(s>i*2){let o=e[r];o.break?e.splice(r,1,o.left,null,o.right):e.splice(r,1,o.left,o.right),r+=2+o.break,s-=o.size}else break;else if(i<s){let o=e[t++];o&&(i+=o.size)}else{let o=e[--r];o&&(s+=o.size)}let l=0;return e[t-1]==null?(l=1,t--):e[t]==null&&(l=1,r++),new XL($n.of(e.slice(0,t)),l,$n.of(e.slice(r)))}}function fd(n,e){return n==e?n:(n.constructor!=e.constructor&&(la=!0),e)}$n.prototype.size=1;const ZL=$e.replace({});class eQ extends $n{constructor(e,t,r){super(e,t),this.deco=r,this.spaceAbove=0}mainBlock(e,t){return new Zr(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,r,i){return this.spaceAbove&&e<r+this.spaceAbove?new Zr(i,0,r,this.spaceAbove,ZL):this.mainBlock(r,i)}lineAt(e,t,r,i,s){let l=this.mainBlock(i,s);return this.spaceAbove?this.blockAt(0,r,i,s).join(l):l}forEachLine(e,t,r,i,s,l){e<=s+this.length&&t>=s&&l(this.lineAt(0,mt.ByPos,r,i,s))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,r=!1,i){return i&&i.from<=t&&i.more&&this.setMeasuredHeight(i),this.outdated=!1,this}toString(){return`block(${this.length})`}}class lr extends eQ{constructor(e,t,r){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=r}mainBlock(e,t){return new Zr(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,r){let i=r[0];return r.length==1&&(i instanceof lr||i instanceof nn&&i.flags&4)&&Math.abs(this.length-i.length)<10?(i instanceof nn?i=new lr(i.length,this.height,this.spaceAbove):i.height=this.height,this.outdated||(i.outdated=!1),i):$n.of(r)}updateHeight(e,t=0,r=!1,i){return i&&i.from<=t&&i.more?this.setMeasuredHeight(i):(r||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class nn extends $n{constructor(e){super(e,0)}heightMetrics(e,t){let r=e.doc.lineAt(t).number,i=e.doc.lineAt(t+this.length).number,s=i-r+1,l,o=0;if(e.lineWrapping){let u=Math.min(this.height,e.lineHeight*s);l=u/s,this.length>s+1&&(o=(this.height-u)/(this.length-s-1))}else l=this.height/s;return{firstLine:r,lastLine:i,perLine:l,perChar:o}}blockAt(e,t,r,i){let{firstLine:s,lastLine:l,perLine:o,perChar:u}=this.heightMetrics(t,i);if(t.lineWrapping){let h=i+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-r)/this.height))*this.length)),f=t.doc.lineAt(h),p=o+f.length*u,g=Math.max(r,e-p/2);return new Zr(f.from,f.length,g,p,0)}else{let h=Math.max(0,Math.min(l-s,Math.floor((e-r)/o))),{from:f,length:p}=t.doc.line(s+h);return new Zr(f,p,r+o*h,o,0)}}lineAt(e,t,r,i,s){if(t==mt.ByHeight)return this.blockAt(e,r,i,s);if(t==mt.ByPosNoHeight){let{from:x,to:k}=r.doc.lineAt(e);return new Zr(x,k-x,0,0,0)}let{firstLine:l,perLine:o,perChar:u}=this.heightMetrics(r,s),h=r.doc.lineAt(e),f=o+h.length*u,p=h.number-l,g=i+o*p+u*(h.from-s-p);return new Zr(h.from,h.length,Math.max(i,Math.min(g,i+this.height-f)),f,0)}forEachLine(e,t,r,i,s,l){e=Math.max(e,s),t=Math.min(t,s+this.length);let{firstLine:o,perLine:u,perChar:h}=this.heightMetrics(r,s);for(let f=e,p=i;f<=t;){let g=r.doc.lineAt(f);if(f==e){let k=g.number-o;p+=u*k+h*(e-s-k)}let x=u+h*g.length;l(new Zr(g.from,g.length,p,x,0)),p+=x,f=g.to+1}}replace(e,t,r){let i=this.length-t;if(i>0){let s=r[r.length-1];s instanceof nn?r[r.length-1]=new nn(s.length+i):r.push(null,new nn(i-1))}if(e>0){let s=r[0];s instanceof nn?r[0]=new nn(e+s.length):r.unshift(new nn(e-1),null)}return $n.of(r)}decomposeLeft(e,t){t.push(new nn(e-1),null)}decomposeRight(e,t){t.push(null,new nn(this.length-e-1))}updateHeight(e,t=0,r=!1,i){let s=t+this.length;if(i&&i.from<=t+this.length&&i.more){let l=[],o=Math.max(t,i.from),u=-1;for(i.from>t&&l.push(new nn(i.from-t-1).updateHeight(e,t));o<=s&&i.more;){let f=e.doc.lineAt(o).length;l.length&&l.push(null);let p=i.heights[i.index++],g=0;p<0&&(g=-p,p=i.heights[i.index++]),u==-1?u=p:Math.abs(p-u)>=Zf&&(u=-2);let x=new lr(f,p,g);x.outdated=!1,l.push(x),o+=f+1}o<=s&&l.push(null,new nn(s-o).updateHeight(e,o));let h=$n.of(l);return(u<0||Math.abs(h.height-this.height)>=Zf||Math.abs(u-this.heightMetrics(e,t).perLine)>=Zf)&&(la=!0),fd(this,h)}else(r||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class XL extends $n{constructor(e,t,r){super(e.length+t+r.length,e.height+r.height,t|(e.outdated||r.outdated?2:0)),this.left=e,this.right=r,this.size=e.size+r.size}get break(){return this.flags&1}blockAt(e,t,r,i){let s=r+this.left.height;return e<s?this.left.blockAt(e,t,r,i):this.right.blockAt(e,t,s,i+this.left.length+this.break)}lineAt(e,t,r,i,s){let l=i+this.left.height,o=s+this.left.length+this.break,u=t==mt.ByHeight?e<l:e<o,h=u?this.left.lineAt(e,t,r,i,s):this.right.lineAt(e,t,r,l,o);if(this.break||(u?h.to<o:h.from>o))return h;let f=t==mt.ByPosNoHeight?mt.ByPosNoHeight:mt.ByPos;return u?h.join(this.right.lineAt(o,f,r,l,o)):this.left.lineAt(o,f,r,i,s).join(h)}forEachLine(e,t,r,i,s,l){let o=i+this.left.height,u=s+this.left.length+this.break;if(this.break)e<u&&this.left.forEachLine(e,t,r,i,s,l),t>=u&&this.right.forEachLine(e,t,r,o,u,l);else{let h=this.lineAt(u,mt.ByPos,r,i,s);e<h.from&&this.left.forEachLine(e,h.from-1,r,i,s,l),h.to>=e&&h.from<=t&&l(h),t>h.to&&this.right.forEachLine(h.to+1,t,r,o,u,l)}}replace(e,t,r){let i=this.left.length+this.break;if(t<i)return this.balanced(this.left.replace(e,t,r),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-i,t-i,r));let s=[];e>0&&this.decomposeLeft(e,s);let l=s.length;for(let o of r)s.push(o);if(e>0&&Vb(s,l-1),t<this.length){let o=s.length;this.decomposeRight(t,s),Vb(s,o)}return $n.of(s)}decomposeLeft(e,t){let r=this.left.length;if(e<=r)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(r++,e>=r&&t.push(null)),e>r&&this.right.decomposeLeft(e-r,t)}decomposeRight(e,t){let r=this.left.length,i=r+this.break;if(e>=i)return this.right.decomposeRight(e-i,t);e<r&&this.left.decomposeRight(e,t),this.break&&e<i&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?$n.of(this.break?[e,null,t]:[e,t]):(this.left=fd(this.left,e),this.right=fd(this.right,t),this.setHeight(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,r=!1,i){let{left:s,right:l}=this,o=t+s.length+this.break,u=null;return i&&i.from<=t+s.length&&i.more?u=s=s.updateHeight(e,t,r,i):s.updateHeight(e,t,r),i&&i.from<=o+l.length&&i.more?u=l=l.updateHeight(e,o,r,i):l.updateHeight(e,o,r),u?this.balanced(s,l):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Vb(n,e){let t,r;n[e]==null&&(t=n[e-1])instanceof nn&&(r=n[e+1])instanceof nn&&n.splice(e-1,3,new nn(t.length+1+r.length))}const BL=5;class By{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 r=Math.min(t,this.lineEnd),i=this.nodes[this.nodes.length-1];i instanceof lr?i.length+=r-this.pos:(r>this.pos||!this.isCovered)&&this.nodes.push(new lr(r-this.pos,-1,0)),this.writtenTo=r,t>r&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,r){if(e<t||r.heightRelevant){let i=r.widget?r.widget.estimatedHeight:0,s=r.widget?r.widget.lineBreaks:0;i<0&&(i=this.oracle.lineHeight);let l=t-e;r.block?this.addBlock(new eQ(l,i,r)):(l||s||i>=BL)&&this.addLineDeco(i,s,l)}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 lr(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let r=new nn(t-e);return this.oracle.doc.lineAt(e).to==t&&(r.flags|=4),r}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof lr)return e;let t=new lr(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,r){let i=this.ensureLine();i.length+=r,i.collapsed+=r,i.widgetHeight=Math.max(i.widgetHeight,e),i.breaks+=t,this.writtenTo=this.pos=this.pos+r}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof lr)&&!this.isCovered?this.nodes.push(new lr(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let r=e;for(let i of this.nodes)i instanceof lr&&i.updateHeight(this.oracle,r),r+=i?i.length:1;return this.nodes}static build(e,t,r,i){let s=new By(r,e);return We.spans(t,r,i,s,0),s.finish(r)}}function WL(n,e,t){let r=new qL;return We.compare(n,e,t,r,0),r.changes}class qL{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,r,i){(e<t||r&&r.heightRelevant||i&&i.heightRelevant)&&Lo(e,t,this.changes,5)}}function VL(n,e){let t=n.getBoundingClientRect(),r=n.ownerDocument,i=r.defaultView||window,s=Math.max(0,t.left),l=Math.min(i.innerWidth,t.right),o=Math.max(0,t.top),u=Math.min(i.innerHeight,t.bottom);for(let h=n.parentNode;h&&h!=r.body;)if(h.nodeType==1){let f=h,p=window.getComputedStyle(f);if((f.scrollHeight>f.clientHeight||f.scrollWidth>f.clientWidth)&&p.overflow!="visible"){let g=f.getBoundingClientRect();s=Math.max(s,g.left),l=Math.min(l,g.right),o=Math.max(o,g.top),u=Math.min(h==n.parentNode?i.innerHeight:u,g.bottom)}h=p.position=="absolute"||p.position=="fixed"?f.offsetParent:f.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:s-t.left,right:Math.max(s,l)-t.left,top:o-(t.top+e),bottom:Math.max(o,u)-(t.top+e)}}function FL(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>0&&e.top<t.innerHeight&&e.bottom>0}function YL(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class Pg{constructor(e,t,r,i){this.from=e,this.to=t,this.size=r,this.displaySize=i}static same(e,t){if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++){let i=e[r],s=t[r];if(i.from!=s.from||i.to!=s.to||i.size!=s.size)return!1}return!0}draw(e,t){return $e.replace({widget:new UL(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class UL extends Vr{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}}class Fb{constructor(e,t){this.view=e,this.state=t,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.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Yb,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=ht.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let r=t.facet(Iy).some(i=>typeof i!="function"&&i.class=="cm-lineWrapping");this.heightOracle=new IL(r),this.stateDeco=Ub(t),this.heightMap=$n.empty().applyChanges(this.stateDeco,Ge.empty,this.heightOracle.setDoc(t.doc),[new Sr(0,0,0,t.doc.length)]);for(let i=0;i<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());i++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=$e.set(this.lineGaps.map(i=>i.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let r=0;r<=1;r++){let i=r?t.head:t.anchor;if(!e.some(({from:s,to:l})=>i>=s&&i<=l)){let{from:s,to:l}=this.lineBlockAt(i);e.push(new df(s,l))}}return this.viewports=e.sort((r,i)=>r.from-i.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Yb:new Wy(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Mu(e,this.scaler))})}update(e,t=null){this.state=e.state;let r=this.stateDeco;this.stateDeco=Ub(this.state);let i=e.changedRanges,s=Sr.extendWithRanges(i,WL(r,this.stateDeco,e?e.changes:Lt.empty(this.state.doc.length))),l=this.heightMap.height,o=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);qb(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),s),(this.heightMap.height!=l||la)&&(e.flags|=2),o?(this.scrollAnchorPos=e.changes.mapPos(o.from,-1),this.scrollAnchorHeight=o.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=l);let u=s.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<u.from||t.range.head>u.to)||!this.viewportIsAppropriate(u))&&(u=this.getViewport(0,t));let h=u.from!=this.viewport.from||u.to!=this.viewport.to;this.viewport=u,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(A2)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,r=window.getComputedStyle(t),i=this.heightOracle,s=r.whiteSpace;this.defaultTextDirection=r.direction=="rtl"?ht.RTL:ht.LTR;let l=this.heightOracle.mustRefreshForWrapping(s)||this.mustMeasureContent==="refresh",o=t.getBoundingClientRect(),u=l||this.mustMeasureContent||this.contentDOMHeight!=o.height;this.contentDOMHeight=o.height,this.mustMeasureContent=!1;let h=0,f=0;if(o.width&&o.height){let{scaleX:I,scaleY:T}=m2(t,o);(I>.005&&Math.abs(this.scaleX-I)>.005||T>.005&&Math.abs(this.scaleY-T)>.005)&&(this.scaleX=I,this.scaleY=T,h|=16,l=u=!0)}let p=(parseInt(r.paddingTop)||0)*this.scaleY,g=(parseInt(r.paddingBottom)||0)*this.scaleY;(this.paddingTop!=p||this.paddingBottom!=g)&&(this.paddingTop=p,this.paddingBottom=g,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(i.lineWrapping&&(u=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let x=g2(this.view.contentDOM,!1).y;x!=this.scrollParent&&(this.scrollParent=x,this.scrollAnchorHeight=-1,this.scrollOffset=0);let k=this.getScrollOffset();this.scrollOffset!=k&&(this.scrollAnchorHeight=-1,this.scrollOffset=k),this.scrolledToBottom=x2(this.scrollParent||e.win);let b=(this.printing?YL:VL)(t,this.paddingTop),w=b.top-this.pixelViewport.top,S=b.bottom-this.pixelViewport.bottom;this.pixelViewport=b;let Q=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(Q!=this.inView&&(this.inView=Q,Q&&(u=!0)),!this.inView&&!this.scrollTarget&&!FL(e.dom))return 0;let $=o.width;if((this.contentDOMWidth!=$||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=o.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),u){let I=e.docView.measureVisibleLineHeights(this.viewport);if(i.mustRefreshForHeights(I)&&(l=!0),l||i.lineWrapping&&Math.abs($-this.contentDOMWidth)>i.charWidth){let{lineHeight:T,charWidth:X,textHeight:Z}=e.docView.measureTextSize();l=T>0&&i.refresh(s,T,X,Z,Math.max(5,$/X),I),l&&(e.docView.minWidth=0,h|=16)}w>0&&S>0?f=Math.max(w,S):w<0&&S<0&&(f=Math.min(w,S)),qb();for(let T of this.viewports){let X=T.from==this.viewport.from?I:e.docView.measureVisibleLineHeights(T);this.heightMap=(l?$n.empty().applyChanges(this.stateDeco,Ge.empty,this.heightOracle,[new Sr(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(i,0,l,new zL(T.from,X))}la&&(h|=2)}let R=!this.viewportIsAppropriate(this.viewport,f)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return R&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(f,this.scrollTarget),h|=this.updateForViewport()),(h&2||R)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(l?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let r=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),i=this.heightMap,s=this.heightOracle,{visibleTop:l,visibleBottom:o}=this,u=new df(i.lineAt(l-r*1e3,mt.ByHeight,s,0,0).from,i.lineAt(o+(1-r)*1e3,mt.ByHeight,s,0,0).to);if(t){let{head:h}=t.range;if(h<u.from||h>u.to){let f=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),p=i.lineAt(h,mt.ByPos,s,0,0),g;t.y=="center"?g=(p.top+p.bottom)/2-f/2:t.y=="start"||t.y=="nearest"&&h<u.from?g=p.top:g=p.bottom-f,u=new df(i.lineAt(g-1e3/2,mt.ByHeight,s,0,0).from,i.lineAt(g+f+1e3/2,mt.ByHeight,s,0,0).to)}}return u}mapViewport(e,t){let r=t.mapPos(e.from,-1),i=t.mapPos(e.to,1);return new df(this.heightMap.lineAt(r,mt.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(i,mt.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},r=0){if(!this.inView)return!0;let{top:i}=this.heightMap.lineAt(e,mt.ByPos,this.heightOracle,0,0),{bottom:s}=this.heightMap.lineAt(t,mt.ByPos,this.heightOracle,0,0),{visibleTop:l,visibleBottom:o}=this;return(e==0||i<=l-Math.max(10,Math.min(-r,250)))&&(t==this.state.doc.length||s>=o+Math.max(10,Math.min(r,250)))&&i>l-2*1e3&&s<o+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let r=[];for(let i of e)t.touchesRange(i.from,i.to)||r.push(new Pg(t.mapPos(i.from),t.mapPos(i.to),i.size,i.displaySize));return r}ensureLineGaps(e,t){let r=this.heightOracle.lineWrapping,i=r?1e4:2e3,s=i>>1,l=i<<1;if(this.defaultTextDirection!=ht.LTR&&!r)return[];let o=[],u=(f,p,g,x)=>{if(p-f<s)return;let k=this.state.selection.main,b=[k.from];k.empty||b.push(k.to);for(let S of b)if(S>f&&S<p){u(f,S-10,g,x),u(S+10,p,g,x);return}let w=HL(e,S=>S.from>=g.from&&S.to<=g.to&&Math.abs(S.from-f)<s&&Math.abs(S.to-p)<s&&!b.some(Q=>S.from<Q&&S.to>Q));if(!w){if(p<g.to&&t&&r&&t.visibleRanges.some($=>$.from<=p&&$.to>=p)){let $=t.moveToLineBoundary(Y.cursor(p),!1,!0).head;$>f&&(p=$)}let S=this.gapSize(g,f,p,x),Q=r||S<2e6?S:2e6;w=new Pg(f,p,S,Q)}o.push(w)},h=f=>{if(f.length<l||f.type!=ln.Text)return;let p=GL(f.from,f.to,this.stateDeco);if(p.total<l)return;let g=this.scrollTarget?this.scrollTarget.range.head:null,x,k;if(r){let b=i/this.heightOracle.lineLength*this.heightOracle.lineHeight,w,S;if(g!=null){let Q=mf(p,g),$=((this.visibleBottom-this.visibleTop)/2+b)/f.height;w=Q-$,S=Q+$}else w=(this.visibleTop-f.top-b)/f.height,S=(this.visibleBottom-f.top+b)/f.height;x=pf(p,w),k=pf(p,S)}else{let b=p.total*this.heightOracle.charWidth,w=i*this.heightOracle.charWidth,S=0;if(b>2e6)for(let T of e)T.from>=f.from&&T.from<f.to&&T.size!=T.displaySize&&T.from*this.heightOracle.charWidth+S<this.pixelViewport.left&&(S=T.size-T.displaySize);let Q=this.pixelViewport.left+S,$=this.pixelViewport.right+S,R,I;if(g!=null){let T=mf(p,g),X=(($-Q)/2+w)/b;R=T-X,I=T+X}else R=(Q-w)/b,I=($+w)/b;x=pf(p,R),k=pf(p,I)}x>f.from&&u(f.from,x,f,p),k<f.to&&u(k,f.to,f,p)};for(let f of this.viewportLines)Array.isArray(f.type)?f.type.forEach(h):h(f);return o}gapSize(e,t,r,i){let s=mf(i,r)-mf(i,t);return this.heightOracle.lineWrapping?e.height*s:i.total*this.heightOracle.charWidth*s}updateLineGaps(e){Pg.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=$e.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let r=[];We.spans(t,this.viewport.from,this.viewport.to,{span(s,l){r.push({from:s,to:l})},point(){}},20);let i=0;if(r.length!=this.visibleRanges.length)i=12;else for(let s=0;s<r.length&&!(i&8);s++){let l=this.visibleRanges[s],o=r[s];(l.from!=o.from||l.to!=o.to)&&(i|=4,e&&e.mapPos(l.from,-1)==o.from&&e.mapPos(l.to,1)==o.to||(i|=8))}return this.visibleRanges=r,i}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Mu(this.heightMap.lineAt(e,mt.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Mu(this.heightMap.lineAt(this.scaler.fromDOM(e),mt.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Mu(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}}class df{constructor(e,t){this.from=e,this.to=t}}function GL(n,e,t){let r=[],i=n,s=0;return We.spans(t,n,e,{span(){},point(l,o){l>i&&(r.push({from:i,to:l}),s+=l-i),i=o}},20),i<e&&(r.push({from:i,to:e}),s+=e-i),{total:s,ranges:r}}function pf({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let r=Math.floor(n*t);for(let i=0;;i++){let{from:s,to:l}=e[i],o=l-s;if(r<=o)return s+r;r-=o}}function mf(n,e){let t=0;for(let{from:r,to:i}of n.ranges){if(e<=i){t+=e-r;break}t+=i-r}return t/n.total}function HL(n,e){for(let t of n)if(e(t))return t}const Yb={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function Ub(n){let e=n.facet(ep).filter(r=>typeof r!="function"),t=n.facet(zy).filter(r=>typeof r!="function");return t.length&&e.push(We.join(t)),e}class Wy{constructor(e,t,r){let i=0,s=0,l=0;this.viewports=r.map(({from:o,to:u})=>{let h=t.lineAt(o,mt.ByPos,e,0,0).top,f=t.lineAt(u,mt.ByPos,e,0,0).bottom;return i+=f-h,{from:o,to:u,top:h,bottom:f,domTop:0,domBottom:0}}),this.scale=(7e6-i)/(t.height-i);for(let o of this.viewports)o.domTop=l+(o.top-s)*this.scale,l=o.domBottom=o.domTop+(o.bottom-o.top),s=o.bottom}toDOM(e){for(let t=0,r=0,i=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.top)return i+(e-r)*this.scale;if(e<=s.bottom)return s.domTop+(e-s.top);r=s.bottom,i=s.domBottom}}fromDOM(e){for(let t=0,r=0,i=0;;t++){let s=t<this.viewports.length?this.viewports[t]:null;if(!s||e<s.domTop)return r+(e-i)/this.scale;if(e<=s.domBottom)return s.top+(e-s.domTop);r=s.bottom,i=s.domBottom}}eq(e){return e instanceof Wy?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,r)=>t.from==e.viewports[r].from&&t.to==e.viewports[r].to):!1}}function Mu(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),r=e.toDOM(n.bottom);return new Zr(n.from,n.length,t,r-t,Array.isArray(n._content)?n._content.map(i=>Mu(i,e)):n._content)}const gf=ge.define({combine:n=>n.join(" ")}),Px=ge.define({combine:n=>n.indexOf(!0)>-1}),Cx=Bs.newName(),tQ=Bs.newName(),nQ=Bs.newName(),rQ={"&light":"."+tQ,"&dark":"."+nQ};function Qx(n,e,t){return new Bs(e,{finish(r){return/&/.test(r)?r.replace(/&\w*/,i=>{if(i=="&")return n;if(!t||!t[i])throw new RangeError(`Unsupported selector: ${i}`);return t[i]}):n+" "+r}})}const KL=Qx("."+Cx,{"&":{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,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",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":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .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:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&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",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&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,zIndex:300},"&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-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".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",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".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"}},rQ),JL={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Cg=xe.ie&&xe.ie_version<=11;class e3{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new j5,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.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let r of t)this.queue.push(r);(xe.ie&&xe.ie_version<=11||xe.ios&&e.composing)&&t.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&xe.android&&e.constructor.EDIT_CONTEXT!==!1&&!(xe.chrome&&xe.chrome_version<126)&&(this.editContext=new n3(e),e.state.facet(Zi)&&(e.contentDOM.editContext=this.editContext.editContext)),Cg&&(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),window.matchMedia&&(this.printQuery=window.matchMedia("print")),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.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")))},{threshold:[0,.001]}),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.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(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,r)=>t!=e[r]))){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:r}=this,i=this.selectionRange;if(r.state.facet(Zi)?r.root.activeElement!=this.dom:!_u(this.dom,i))return;let s=i.anchorNode&&r.docView.tile.nearest(i.anchorNode);if(s&&s.isWidget()&&s.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(xe.ie&&xe.ie_version<=11||xe.android&&xe.chrome)&&!r.state.selection.main.empty&&i.focusNode&&Iu(i.focusNode,i.focusOffset,i.anchorNode,i.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=tc(e.root);if(!t)return!1;let r=xe.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&t3(this.view,t)||t;if(!r||this.selectionRange.eq(r))return!1;let i=_u(this.dom,r);return i&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&M5(this.dom,r)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(r),i&&(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 r=this.dom;r;)if(r.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==r?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let r of this.scrollTargets)r.removeEventListener("scroll",this.onScroll);for(let r of this.scrollTargets=t)r.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,JL),Cg&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Cg&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var r;if(!this.delayedAndroidKey){let i=()=>{let s=this.delayedAndroidKey;s&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=s.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&s.force&&_o(this.dom,s.key,s.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(i)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((r=this.delayedAndroidKey)===null||r===void 0)&&r.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()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,r=-1,i=!1;for(let s of e){let l=this.readMutation(s);l&&(l.typeOver&&(i=!0),t==-1?{from:t,to:r}=l:(t=Math.min(l.from,t),r=Math.max(l.to,r)))}return{from:t,to:r,typeOver:i}}readChange(){let{from:e,to:t,typeOver:r}=this.processRecords(),i=this.selectionChanged&&_u(this.dom,this.selectionRange);if(e<0&&!i)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let s=new yL(this.view,e,t,r);return this.view.docView.domChanged={newSel:s.newSel?s.newSel.main:null},s}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let r=this.view.state,i=W2(this.view,t);return this.view.state==r&&(t.domChanged||t.newSel&&!hd(this.view.state.selection,t.newSel.main))&&this.view.update([]),i}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let r=Gb(t,e.previousSibling||e.target.previousSibling,-1),i=Gb(t,e.nextSibling||e.target.nextSibling,1);return{from:r?t.posAfter(r):t.posAtStart,to:i?t.posBefore(i):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),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):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),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(Zi)!=e.state.facet(Zi)&&(e.view.contentDOM.editContext=e.state.facet(Zi)?this.editContext.editContext:null))}destroy(){var e,t,r;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(r=this.resizeScroll)===null||r===void 0||r.disconnect();for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Gb(n,e,t){for(;e;){let r=Pt.get(e);if(r&&r.parent==n)return r;let i=e.parentNode;e=i!=n.dom?i:t>0?e.nextSibling:e.previousSibling}return null}function Hb(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,s=e.endOffset,l=n.docView.domAtPos(n.state.selection.main.anchor,1);return Iu(l.node,l.offset,i,s)&&([t,r,i,s]=[i,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}}function t3(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return Hb(n,i)}let t=null;function r(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",r,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",r,!0),t?Hb(n,t):null}class n3{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=r=>{let i=e.state.selection.main,{anchor:s,head:l}=i,o=this.toEditorPos(r.updateRangeStart),u=this.toEditorPos(r.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:r.updateRangeStart,editorBase:o,drifted:!1});let h=u-o>r.text.length;o==this.from&&s<this.from?o=s:u==this.to&&s>this.to&&(u=s);let f=q2(e.state.sliceDoc(o,u),r.text,(h?i.from:i.to)-o,h?"end":null);if(!f){let g=Y.single(this.toEditorPos(r.selectionStart),this.toEditorPos(r.selectionEnd));hd(g,i)||e.dispatch({selection:g,userEvent:"select"});return}let p={from:f.from+o,to:f.toA+o,insert:Ge.of(r.text.slice(f.from,f.toB).split(`
76
+ `))};if((xe.mac||xe.android)&&p.from==l-1&&/^\. ?$/.test(r.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(p={from:o,to:u,insert:Ge.of([r.text.replace("."," ")])}),this.pendingContextChange=p,!e.state.readOnly){let g=this.to-this.from+(p.to-p.from+p.insert.length);Xy(e,p,Y.single(this.toEditorPos(r.selectionStart,g),this.toEditorPos(r.selectionEnd,g)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),p.from<p.to&&!p.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,r.updateRangeStart-1),Math.min(t.text.length,r.updateRangeStart+1)))&&this.handlers.compositionend(r)},this.handlers.characterboundsupdate=r=>{let i=[],s=null;for(let l=this.toEditorPos(r.rangeStart),o=this.toEditorPos(r.rangeEnd);l<o;l++){let u=e.coordsForChar(l);s=u&&new DOMRect(u.left,u.top,u.right-u.left,u.bottom-u.top)||s||new DOMRect,i.push(s)}t.updateCharacterBounds(r.rangeStart,i)},this.handlers.textformatupdate=r=>{let i=[];for(let s of r.getTextFormats()){let l=s.underlineStyle,o=s.underlineThickness;if(!/none/i.test(l)&&!/none/i.test(o)){let u=this.toEditorPos(s.rangeStart),h=this.toEditorPos(s.rangeEnd);if(u<h){let f=`text-decoration: underline ${/^[a-z]/.test(l)?l+" ":l=="Dashed"?"dashed ":l=="Squiggle"?"wavy ":""}${/thin/i.test(o)?1:2}px`;i.push($e.mark({attributes:{style:f}}).range(u,h))}}}e.dispatch({effects:N2.of($e.set(i))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:r}=this.composing;this.composing=null,r&&this.reset(e.state)}};for(let r in this.handlers)t.addEventListener(r,this.handlers[r]);this.measureReq={read:r=>{this.editContext.updateControlBounds(r.contentDOM.getBoundingClientRect());let i=tc(r.root);i&&i.rangeCount&&this.editContext.updateSelectionBounds(i.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,r=!1,i=this.pendingContextChange;return e.changes.iterChanges((s,l,o,u,h)=>{if(r)return;let f=h.length-(l-s);if(i&&l>=i.to)if(i.from==s&&i.to==l&&i.insert.eq(h)){i=this.pendingContextChange=null,t+=f,this.to+=f;return}else i=null,this.revertPending(e.state);if(s+=t,l+=t,l<=this.from)this.from+=f,this.to+=f;else if(s<this.to){if(s<this.from||l>this.to||this.to-this.from+h.length>3e4){r=!0;return}this.editContext.updateText(this.toContextPos(s),this.toContextPos(l),h.toString()),this.to+=f}t+=f}),i&&!r&&this.revertPending(e.state),!r}update(e){let t=this.pendingContextChange,r=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(r.from,r.to)&&e.transactions.some(i=>!i.isUserEvent("input.type")&&i.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,r=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),i=this.toContextPos(t.head);(this.editContext.selectionStart!=r||this.editContext.selectionEnd!=i)&&this.editContext.updateSelection(r,i)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let r=this.composing;return r&&r.drifted?r.editorBase+(e-r.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class he{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&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;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.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:r}=e;this.dispatchTransactions=e.dispatchTransactions||r&&(i=>i.forEach(s=>r(s,this)))||(i=>this.update(i)),this.dispatch=this.dispatch.bind(this),this._root=e.root||E5(e.parent)||document,this.viewState=new Fb(this,e.state||Fe.create(e)),e.scrollTo&&e.scrollTo.is(cf)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Mo).map(i=>new kg(i));for(let i of this.plugins)i.update(this);this.observer=new e3(this),this.inputState=new wL(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Rb(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof At?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}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,r=!1,i,s=this.state;for(let g of e){if(g.startState!=s)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");s=g.state}if(this.destroyed){this.viewState.state=s;return}let l=this.hasFocus,o=0,u=null;e.some(g=>g.annotation(H2))?(this.inputState.notifiedFocused=l,o=1):l!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=l,u=K2(s,l),u||(o=1));let h=this.observer.delayedAndroidKey,f=null;if(h?(this.observer.clearDelayedAndroidKey(),f=this.observer.readChange(),(f&&!this.state.doc.eq(s.doc)||!this.state.selection.eq(s.selection))&&(f=null)):this.observer.clear(),s.facet(Fe.phrases)!=this.state.facet(Fe.phrases))return this.setState(s);i=ad.create(this,s,e),i.flags|=o;let p=this.viewState.scrollTarget;try{this.updateState=2;for(let g of e){if(p&&(p=p.map(g.changes)),g.scrollIntoView){let{main:x}=g.state.selection,{x:k,y:b}=this.state.facet(he.cursorScrollMargin);p=new Do(x.empty?x:Y.cursor(x.head,x.head>x.anchor?-1:1),"nearest","nearest",b,k)}for(let x of g.effects)x.is(cf)&&(p=x.value.clip(this.state))}this.viewState.update(i,p),this.bidiCache=dd.update(this.bidiCache,i.changes),i.empty||(this.updatePlugins(i),this.inputState.update(i)),t=this.docView.update(i),this.state.facet(Eu)!=this.styleModules&&this.mountStyles(),r=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(g=>g.isUserEvent("select.pointer")))}finally{this.updateState=0}if(i.startState.facet(gf)!=i.state.facet(gf)&&(this.viewState.mustMeasureContent=!0),(t||r||p||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!i.empty)for(let g of this.state.facet(kx))try{g(i)}catch(x){Xn(this.state,x,"update listener")}(u||f)&&Promise.resolve().then(()=>{u&&this.state==u.startState&&this.dispatch(u),f&&!W2(this,f)&&h.force&&_o(this.contentDOM,h.key,h.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 r of this.plugins)r.destroy(this);this.viewState=new Fb(this,e),this.plugins=e.facet(Mo).map(r=>new kg(r)),this.pluginMap.clear();for(let r of this.plugins)r.update(this);this.docView.destroy(),this.docView=new Rb(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Mo),r=e.state.facet(Mo);if(t!=r){let i=[];for(let s of r){let l=t.indexOf(s);if(l<0)i.push(new kg(s));else{let o=this.plugins[l];o.mustUpdate=e,i.push(o)}}for(let s of this.plugins)s.mustUpdate!=e&&s.destroy(this);this.plugins=i,this.pluginMap.clear()}else for(let i of this.plugins)i.mustUpdate=e;for(let i=0;i<this.plugins.length;i++)this.plugins[i].update(this);t!=r&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(r){Xn(this.state,r,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,r=this.viewState.scrollParent,i=this.viewState.getScrollOffset(),{scrollAnchorPos:s,scrollAnchorHeight:l}=this.viewState;Math.abs(i-this.viewState.scrollOffset)>1&&(l=-1),this.viewState.scrollAnchorHeight=-1;try{for(let o=0;;o++){if(l<0)if(x2(r||this.win))s=-1,l=this.viewState.heightMap.height;else{let x=this.viewState.scrollAnchorAt(i);s=x.from,l=x.top}this.updateState=1;let u=this.viewState.measure();if(!u&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(o>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];u&4||([this.measureRequests,h]=[h,this.measureRequests]);let f=h.map(x=>{try{return x.read(this)}catch(k){return Xn(this.state,k),Kb}}),p=ad.create(this,this.state,[]),g=!1;p.flags|=u,t?t.flags|=u:t=p,this.updateState=2,p.empty||(this.updatePlugins(p),this.inputState.update(p),this.updateAttrs(),g=this.docView.update(p),g&&this.docViewUpdate());for(let x=0;x<h.length;x++)if(f[x]!=Kb)try{let k=h[x];k.write&&k.write(f[x],this)}catch(k){Xn(this.state,k)}if(g&&this.docView.updateSelection(!0),!p.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,l=-1;continue}else{let k=((s<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(s).top)-l)/this.scaleY;if((k>1||k<-1)&&(r==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){i=i+k,r?r.scrollTop+=k:this.win.scrollBy(0,k),l=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let o of this.state.facet(kx))o(t)}get themeClasses(){return Cx+" "+(this.state.facet(Px)?nQ:tQ)+" "+this.state.facet(gf)}updateAttrs(){let e=Jb(this,L2,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(Zi)?"true":"false",class:"cm-content",style:`${xe.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Jb(this,Iy,t);let r=this.observer.ignore(()=>{let i=$b(this.contentDOM,this.contentAttrs,t),s=$b(this.dom,this.editorAttrs,e);return i||s});return this.editorAttrs=e,this.contentAttrs=t,r}showAnnouncements(e){let t=!0;for(let r of e)for(let i of r.effects)if(i.is(he.announce)){t&&(this.announceDOM.textContent=""),t=!1;let s=this.announceDOM.appendChild(document.createElement("div"));s.textContent=i.value}}mountStyles(){this.styleModules=this.state.facet(Eu);let e=this.state.facet(he.cspNonce);Bs.mount(this.root,this.styleModules.concat(KL).reverse(),e?{nonce:e}:void 0)}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.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(r=>r.plugin==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}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}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,r){return Sg(this,e,Nb(this,e,t,r))}moveByGroup(e,t){return Sg(this,e,Nb(this,e,t,r=>dL(this,e.head,r)))}visualLineSide(e,t){let r=this.bidiSpans(e),i=this.textDirectionAt(e.from),s=r[t?r.length-1:0];return Y.cursor(s.side(t,i)+e.from,s.forward(!t,i)?1:-1)}moveToLineBoundary(e,t,r=!0){return fL(this,e,t,r)}moveVertically(e,t,r){return Sg(this,e,pL(this,e,t,r))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let r=wx(this,e,t);return r&&r.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),wx(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let r=this.docView.coordsAt(e,t);if(!r||r.left==r.right)return r;let i=this.state.doc.lineAt(e),s=this.bidiSpans(i),l=s[di.find(s,e-i.from,-1,t)];return nc(r,l.dir==ht.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}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(M2)||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>r3)return S2(e.length);let t=this.textDirectionAt(e.from),r;for(let s of this.bidiCache)if(s.from==e.from&&s.dir==t&&(s.fresh||w2(s.isolates,r=Eb(this,e))))return s.order;r||(r=Eb(this,e));let i=I5(e.text,t,r);return this.bidiCache.push(new dd(e.from,e.to,t,r,!0,i)),i}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||xe.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{O2(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(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var r,i,s,l;return cf.of(new Do(typeof e=="number"?Y.cursor(e):e,(r=t.y)!==null&&r!==void 0?r:"nearest",(i=t.x)!==null&&i!==void 0?i:"nearest",(s=t.yMargin)!==null&&s!==void 0?s:5,(l=t.xMargin)!==null&&l!==void 0?l:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,r=this.viewState.scrollAnchorAt(e);return cf.of(new Do(Y.cursor(r.from),"start","start",r.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Ct.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Ct.define(()=>({}),{eventObservers:e})}static theme(e,t){let r=Bs.newName(),i=[gf.of(r),Eu.of(Qx(`.${r}`,e))];return t&&t.dark&&i.push(Px.of(!0)),i}static baseTheme(e){return Ui.lowest(Eu.of(Qx("."+Cx,e,rQ)))}static findFromDOM(e){var t;let r=e.querySelector(".cm-content"),i=r&&Pt.get(r)||Pt.get(e);return((t=i==null?void 0:i.root)===null||t===void 0?void 0:t.view)||null}}he.styleModule=Eu;he.inputHandler=j2;he.clipboardInputFilter=_y;he.clipboardOutputFilter=Dy;he.scrollHandler=R2;he.focusChangeEffect=E2;he.perLineTextDirection=M2;he.exceptionSink=T2;he.updateListener=kx;he.editable=Zi;he.mouseSelectionStyle=$2;he.dragMovesSelection=Q2;he.clickAddsSelectionRange=C2;he.decorations=ep;he.blockWrappers=_2;he.outerDecorations=zy;he.atomicRanges=Nc;he.bidiIsolatedRanges=D2;he.cursorScrollMargin=ge.define({combine:n=>{let e=5,t=5;for(let r of n)typeof r=="number"?e=t=r:{x:e,y:t}=r;return{x:e,y:t}}});he.scrollMargins=I2;he.darkTheme=Px;he.cspNonce=ge.define({combine:n=>n.length?n[0]:""});he.contentAttributes=Iy;he.editorAttributes=L2;he.lineWrapping=he.contentAttributes.of({class:"cm-lineWrapping"});he.announce=Ne.define();const r3=4096,Kb={};class dd{constructor(e,t,r,i,s,l){this.from=e,this.to=t,this.dir=r,this.isolates=i,this.fresh=s,this.order=l}static update(e,t){if(t.empty&&!e.some(s=>s.fresh))return e;let r=[],i=e.length?e[e.length-1].dir:ht.LTR;for(let s=Math.max(0,e.length-10);s<e.length;s++){let l=e[s];l.dir==i&&!t.touchesRange(l.from,l.to)&&r.push(new dd(t.mapPos(l.from,1),t.mapPos(l.to,-1),l.dir,l.isolates,!1,l.order))}return r}}function Jb(n,e,t){for(let r=n.state.facet(e),i=r.length-1;i>=0;i--){let s=r[i],l=typeof s=="function"?s(n):s;l&&Ry(l,t)}return t}const i3=xe.mac?"mac":xe.windows?"win":xe.linux?"linux":"key";function s3(n,e){const t=n.split(/-(?!$)/);let r=t[t.length-1];r=="Space"&&(r=" ");let i,s,l,o;for(let u=0;u<t.length-1;++u){const h=t[u];if(/^(cmd|meta|m)$/i.test(h))o=!0;else if(/^a(lt)?$/i.test(h))i=!0;else if(/^(c|ctrl|control)$/i.test(h))s=!0;else if(/^s(hift)?$/i.test(h))l=!0;else if(/^mod$/i.test(h))e=="mac"?o=!0:s=!0;else throw new Error("Unrecognized modifier name: "+h)}return i&&(r="Alt-"+r),s&&(r="Ctrl-"+r),o&&(r="Meta-"+r),l&&(r="Shift-"+r),r}function Of(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const l3=Ui.default(he.domEventHandlers({keydown(n,e){return sQ(iQ(e.state),n,e,"editor")}})),ba=ge.define({enables:l3}),ew=new WeakMap;function iQ(n){let e=n.facet(ba),t=ew.get(e);return t||ew.set(e,t=u3(e.reduce((r,i)=>r.concat(i),[]))),t}function o3(n,e,t){return sQ(iQ(n.state),e,n,t)}let Qs=null;const a3=4e3;function u3(n,e=i3){let t=Object.create(null),r=Object.create(null),i=(l,o)=>{let u=r[l];if(u==null)r[l]=o;else if(u!=o)throw new Error("Key binding "+l+" is used both as a regular binding and as a multi-stroke prefix")},s=(l,o,u,h,f)=>{var p,g;let x=t[l]||(t[l]=Object.create(null)),k=o.split(/ (?!$)/).map(S=>s3(S,e));for(let S=1;S<k.length;S++){let Q=k.slice(0,S).join(" ");i(Q,!0),x[Q]||(x[Q]={preventDefault:!0,stopPropagation:!1,run:[$=>{let R=Qs={view:$,prefix:Q,scope:l};return setTimeout(()=>{Qs==R&&(Qs=null)},a3),!0}]})}let b=k.join(" ");i(b,!1);let w=x[b]||(x[b]={preventDefault:!1,stopPropagation:!1,run:((g=(p=x._any)===null||p===void 0?void 0:p.run)===null||g===void 0?void 0:g.slice())||[]});u&&w.run.push(u),h&&(w.preventDefault=!0),f&&(w.stopPropagation=!0)};for(let l of n){let o=l.scope?l.scope.split(" "):["editor"];if(l.any)for(let h of o){let f=t[h]||(t[h]=Object.create(null));f._any||(f._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:p}=l;for(let g in f)f[g].run.push(x=>p(x,$x))}let u=l[e]||l.key;if(u)for(let h of o)s(h,u,l.run,l.preventDefault,l.stopPropagation),l.shift&&s(h,"Shift-"+u,l.shift,l.preventDefault,l.stopPropagation)}return t}let $x=null;function sQ(n,e,t,r){$x=e;let i=S5(e),s=In(i,0),l=hi(s)==i.length&&i!=" ",o="",u=!1,h=!1,f=!1;Qs&&Qs.view==t&&Qs.scope==r&&(o=Qs.prefix+" ",F2.indexOf(e.keyCode)<0&&(h=!0,Qs=null));let p=new Set,g=w=>{if(w){for(let S of w.run)if(!p.has(S)&&(p.add(S),S(t)))return w.stopPropagation&&(f=!0),!0;w.preventDefault&&(w.stopPropagation&&(f=!0),h=!0)}return!1},x=n[r],k,b;return x&&(g(x[o+Of(i,e,!l)])?u=!0:l&&(e.altKey||e.metaKey||e.ctrlKey)&&!(xe.windows&&e.ctrlKey&&e.altKey)&&!(xe.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(k=Ws[e.keyCode])&&k!=i?(g(x[o+Of(k,e,!0)])||e.shiftKey&&(b=Ju[e.keyCode])!=i&&b!=k&&g(x[o+Of(b,e,!1)]))&&(u=!0):l&&e.shiftKey&&g(x[o+Of(i,e,!0)])&&(u=!0),!u&&g(x._any)&&(u=!0)),h&&(u=!0),u&&f&&e.stopPropagation(),$x=null,u}class Ll{constructor(e,t,r,i,s){this.className=e,this.left=t,this.top=r,this.width=i,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,r){if(r.empty){let i=e.coordsAtPos(r.head,r.assoc||1);if(!i)return[];let s=lQ(e);return[new Ll(t,i.left-s.left,i.top-s.top,null,i.bottom-i.top)]}else return c3(e,t,r)}}function lQ(n){let e=n.scrollDOM.getBoundingClientRect();return{left:(n.textDirection==ht.LTR?e.left:e.right-n.scrollDOM.clientWidth*n.scaleX)-n.scrollDOM.scrollLeft*n.scaleX,top:e.top-n.scrollDOM.scrollTop*n.scaleY}}function tw(n,e,t,r){let i=n.coordsAtPos(e,t*2);if(!i)return r;let s=n.dom.getBoundingClientRect(),l=(i.top+i.bottom)/2,o=n.posAtCoords({x:s.left+1,y:l}),u=n.posAtCoords({x:s.right-1,y:l});return o==null||u==null?r:{from:Math.max(r.from,Math.min(o,u)),to:Math.min(r.to,Math.max(o,u))}}function c3(n,e,t){if(t.to<=n.viewport.from||t.from>=n.viewport.to)return[];let r=Math.max(t.from,n.viewport.from),i=Math.min(t.to,n.viewport.to),s=n.textDirection==ht.LTR,l=n.contentDOM,o=l.getBoundingClientRect(),u=lQ(n),h=l.querySelector(".cm-line"),f=h&&window.getComputedStyle(h),p=o.left+(f?parseInt(f.paddingLeft)+Math.min(0,parseInt(f.textIndent)):0),g=o.right-(f?parseInt(f.paddingRight):0),x=bx(n,r,1),k=bx(n,i,-1),b=x.type==ln.Text?x:null,w=k.type==ln.Text?k:null;if(b&&(n.lineWrapping||x.widgetLineBreaks)&&(b=tw(n,r,1,b)),w&&(n.lineWrapping||k.widgetLineBreaks)&&(w=tw(n,i,-1,w)),b&&w&&b.from==w.from&&b.to==w.to)return Q($(t.from,t.to,b));{let I=b?$(t.from,null,b):R(x,!1),T=w?$(null,t.to,w):R(k,!0),X=[];return(b||x).to<(w||k).from-(b&&w?1:0)||x.widgetLineBreaks>1&&I.bottom+n.defaultLineHeight/2<T.top?X.push(S(p,I.bottom,g,T.top)):I.bottom<T.top&&n.elementAtHeight((I.bottom+T.top)/2).type==ln.Text&&(I.bottom=T.top=(I.bottom+T.top)/2),Q(I).concat(X).concat(Q(T))}function S(I,T,X,Z){return new Ll(e,I-u.left,T-u.top,Math.max(0,X-I),Z-T)}function Q({top:I,bottom:T,horizontal:X}){let Z=[];for(let H=0;H<X.length;H+=2)Z.push(S(X[H],I,X[H+1],T));return Z}function $(I,T,X){let Z=1e9,H=-1e9,N=[];function U(K,G,Oe,de,ee){let le=n.coordsAtPos(K,K==X.to?-2:2),C=n.coordsAtPos(Oe,Oe==X.from?2:-2);!le||!C||(Z=Math.min(le.top,C.top,Z),H=Math.max(le.bottom,C.bottom,H),ee==ht.LTR?N.push(s&&G?p:le.left,s&&de?g:C.right):N.push(!s&&de?p:C.left,!s&&G?g:le.right))}let V=I??X.from,se=T??X.to;for(let K of n.visibleRanges)if(K.to>V&&K.from<se)for(let G=Math.max(K.from,V),Oe=Math.min(K.to,se);;){let de=n.state.doc.lineAt(G);for(let ee of n.bidiSpans(de)){let le=ee.from+de.from,C=ee.to+de.from;if(le>=Oe)break;C>G&&U(Math.max(le,G),I==null&&le<=V,Math.min(C,Oe),T==null&&C>=se,ee.dir)}if(G=de.to+1,G>=Oe)break}return N.length==0&&U(V,I==null,se,T==null,n.textDirection),{top:Z,bottom:H,horizontal:N}}function R(I,T){let X=o.top+(T?I.top:I.bottom);return{top:X,bottom:X,horizontal:[]}}}function h3(n,e){return n.constructor==e.constructor&&n.eq(e)}class f3{constructor(e,t){this.view=e,this.layer=t,this.drawn=[],this.scaleX=1,this.scaleY=1,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.scale(),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(Xf)!=e.state.facet(Xf)&&this.setOrder(e.state),(this.layer.update(e,this.dom)||e.geometryChanged)&&(this.scale(),e.view.requestMeasure(this.measureReq))}docViewUpdate(e){this.layer.updateOnDocViewUpdate!==!1&&e.requestMeasure(this.measureReq)}setOrder(e){let t=0,r=e.facet(Xf);for(;t<r.length&&r[t]!=this.layer;)t++;this.dom.style.zIndex=String((this.layer.above?150:-1)-t)}measure(){return this.layer.markers(this.view)}scale(){let{scaleX:e,scaleY:t}=this.view;(e!=this.scaleX||t!=this.scaleY)&&(this.scaleX=e,this.scaleY=t,this.dom.style.transform=`scale(${1/e}, ${1/t})`)}draw(e){if(e.length!=this.drawn.length||e.some((t,r)=>!h3(t,this.drawn[r]))){let t=this.dom.firstChild,r=0;for(let i of e)i.update&&t&&i.constructor&&this.drawn[r].constructor&&i.update(t,this.drawn[r])?(t=t.nextSibling,r++):this.dom.insertBefore(i.draw(),t);for(;t;){let i=t.nextSibling;t.remove(),t=i}this.drawn=e,xe.webkit&&(this.dom.style.display=this.dom.firstChild?"":"none")}}destroy(){this.layer.destroy&&this.layer.destroy(this.dom,this.view),this.dom.remove()}}const Xf=ge.define();function oQ(n){return[Ct.define(e=>new f3(e,n)),Xf.of(n)]}const oa=ge.define({combine(n){return bi(n,{cursorBlinkRate:1200,drawRangeCursor:!0,iosSelectionHandles:!0},{cursorBlinkRate:(e,t)=>Math.min(e,t),drawRangeCursor:(e,t)=>e||t})}});function d3(n={}){return[oa.of(n),p3,m3,g3,A2.of(!0)]}function aQ(n){return n.startState.facet(oa)!=n.state.facet(oa)}const p3=oQ({above:!0,markers(n){let{state:e}=n,t=e.facet(oa),r=[];for(let i of e.selection.ranges){let s=i==e.selection.main;if(i.empty||t.drawRangeCursor&&!(s&&xe.ios&&t.iosSelectionHandles)){let l=s?"cm-cursor cm-cursor-primary":"cm-cursor cm-cursor-secondary",o=i.empty?i:Y.cursor(i.head,i.assoc);for(let u of Ll.forRange(n,l,o))r.push(u)}}return r},update(n,e){n.transactions.some(r=>r.selection)&&(e.style.animationName=e.style.animationName=="cm-blink"?"cm-blink2":"cm-blink");let t=aQ(n);return t&&nw(n.state,e),n.docChanged||n.selectionSet||t},mount(n,e){nw(e.state,n)},class:"cm-cursorLayer"});function nw(n,e){e.style.animationDuration=n.facet(oa).cursorBlinkRate+"ms"}const m3=oQ({above:!1,markers(n){let e=[],{main:t,ranges:r}=n.state.selection;for(let i of r)if(!i.empty)for(let s of Ll.forRange(n,"cm-selectionBackground",i))e.push(s);if(xe.ios&&!t.empty&&n.state.facet(oa).iosSelectionHandles){for(let i of Ll.forRange(n,"cm-selectionHandle cm-selectionHandle-start",Y.cursor(t.from,1)))e.push(i);for(let i of Ll.forRange(n,"cm-selectionHandle cm-selectionHandle-end",Y.cursor(t.to,1)))e.push(i)}return e},update(n,e){return n.docChanged||n.selectionSet||n.viewportChanged||aQ(n)},class:"cm-selectionLayer"}),g3=Ui.highest(he.theme({".cm-line":{"& ::selection, &::selection":{backgroundColor:"transparent !important"},caretColor:"transparent !important"},".cm-content":{caretColor:"transparent !important","& :focus":{caretColor:"initial !important","&::selection, & ::selection":{backgroundColor:"Highlight !important"}}}})),uQ=Ne.define({map(n,e){return n==null?null:e.mapPos(n)}}),Au=an.define({create(){return null},update(n,e){return n!=null&&(n=e.changes.mapPos(n)),e.effects.reduce((t,r)=>r.is(uQ)?r.value:t,n)}}),O3=Ct.fromClass(class{constructor(n){this.view=n,this.cursor=null,this.measureReq={read:this.readPos.bind(this),write:this.drawCursor.bind(this)}}update(n){var e;let t=n.state.field(Au);t==null?this.cursor!=null&&((e=this.cursor)===null||e===void 0||e.remove(),this.cursor=null):(this.cursor||(this.cursor=this.view.scrollDOM.appendChild(document.createElement("div")),this.cursor.className="cm-dropCursor"),(n.startState.field(Au)!=t||n.docChanged||n.geometryChanged)&&this.view.requestMeasure(this.measureReq))}readPos(){let{view:n}=this,e=n.state.field(Au),t=e!=null&&n.coordsAtPos(e);if(!t)return null;let r=n.scrollDOM.getBoundingClientRect();return{left:t.left-r.left+n.scrollDOM.scrollLeft*n.scaleX,top:t.top-r.top+n.scrollDOM.scrollTop*n.scaleY,height:t.bottom-t.top}}drawCursor(n){if(this.cursor){let{scaleX:e,scaleY:t}=this.view;n?(this.cursor.style.left=n.left/e+"px",this.cursor.style.top=n.top/t+"px",this.cursor.style.height=n.height/t+"px"):this.cursor.style.left="-100000px"}}destroy(){this.cursor&&this.cursor.remove()}setDropPos(n){this.view.state.field(Au)!=n&&this.view.dispatch({effects:uQ.of(n)})}},{eventObservers:{dragover(n){this.setDropPos(this.view.posAtCoords({x:n.clientX,y:n.clientY}))},dragleave(n){(n.target==this.view.contentDOM||!this.view.contentDOM.contains(n.relatedTarget))&&this.setDropPos(null)},dragend(){this.setDropPos(null)},drop(){this.setDropPos(null)}}});function x3(){return[Au,O3]}function rw(n,e,t,r,i){e.lastIndex=0;for(let s=n.iterRange(t,r),l=t,o;!s.next().done;l+=s.value.length)if(!s.lineBreak)for(;o=e.exec(s.value);)i(l+o.index,o)}function y3(n,e){let t=n.visibleRanges;if(t.length==1&&t[0].from==n.viewport.from&&t[0].to==n.viewport.to)return t;let r=[];for(let{from:i,to:s}of t)i=Math.max(n.state.doc.lineAt(i).from,i-e),s=Math.min(n.state.doc.lineAt(s).to,s+e),r.length&&r[r.length-1].to>=i?r[r.length-1].to=s:r.push({from:i,to:s});return r}class k3{constructor(e){const{regexp:t,decoration:r,decorate:i,boundary:s,maxLength:l=1e3}=e;if(!t.global)throw new RangeError("The regular expression given to MatchDecorator should have its 'g' flag set");if(this.regexp=t,i)this.addMatch=(o,u,h,f)=>i(f,h,h+o[0].length,o,u);else if(typeof r=="function")this.addMatch=(o,u,h,f)=>{let p=r(o,u,h);p&&f(h,h+o[0].length,p)};else if(r)this.addMatch=(o,u,h,f)=>f(h,h+o[0].length,r);else throw new RangeError("Either 'decorate' or 'decoration' should be provided to MatchDecorator");this.boundary=s,this.maxLength=l}createDeco(e){let t=new qi,r=t.add.bind(t);for(let{from:i,to:s}of y3(e,this.maxLength))rw(e.state.doc,this.regexp,i,s,(l,o)=>this.addMatch(o,e,l,r));return t.finish()}updateDeco(e,t){let r=1e9,i=-1;return e.docChanged&&e.changes.iterChanges((s,l,o,u)=>{u>=e.view.viewport.from&&o<=e.view.viewport.to&&(r=Math.min(o,r),i=Math.max(u,i))}),e.viewportMoved||i-r>1e3?this.createDeco(e.view):i>-1?this.updateRange(e.view,t.map(e.changes),r,i):t}updateRange(e,t,r,i){for(let s of e.visibleRanges){let l=Math.max(s.from,r),o=Math.min(s.to,i);if(o>=l){let u=e.state.doc.lineAt(l),h=u.to<o?e.state.doc.lineAt(o):u,f=Math.max(s.from,u.from),p=Math.min(s.to,h.to);if(this.boundary){for(;l>u.from;l--)if(this.boundary.test(u.text[l-1-u.from])){f=l;break}for(;o<h.to;o++)if(this.boundary.test(h.text[o-h.from])){p=o;break}}let g=[],x,k=(b,w,S)=>g.push(S.range(b,w));if(u==h)for(this.regexp.lastIndex=f-u.from;(x=this.regexp.exec(u.text))&&x.index<p-u.from;)this.addMatch(x,e,x.index+u.from,k);else rw(e.state.doc,this.regexp,f,p,(b,w)=>this.addMatch(w,e,b,k));t=t.update({filterFrom:f,filterTo:p,filter:(b,w)=>b<f||w>p,add:g})}}return t}}const Tx=/x/.unicode!=null?"gu":"g",v3=new RegExp(`[\0-\b
77
77
  --Ÿ­؜​‎‏\u2028\u2029‭‮⁦⁧⁩\uFEFF-]`,Tx),b3={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"};let Qg=null;function w3(){var n;if(Qg==null&&typeof document<"u"&&document.body){let e=document.body.style;Qg=((n=e.tabSize)!==null&&n!==void 0?n:e.MozTabSize)!=null}return Qg||!1}const Bf=ge.define({combine(n){let e=bi(n,{render:null,specialChars:v3,addSpecialChars:null});return(e.replaceTabs=!w3())&&(e.specialChars=new RegExp(" |"+e.specialChars.source,Tx)),e.addSpecialChars&&(e.specialChars=new RegExp(e.specialChars.source+"|"+e.addSpecialChars.source,Tx)),e}});function S3(n={}){return[Bf.of(n),P3()]}let iw=null;function P3(){return iw||(iw=Ct.fromClass(class{constructor(n){this.view=n,this.decorations=$e.none,this.decorationCache=Object.create(null),this.decorator=this.makeDecorator(n.state.facet(Bf)),this.decorations=this.decorator.createDeco(n)}makeDecorator(n){return new k3({regexp:n.specialChars,decoration:(e,t,r)=>{let{doc:i}=t.state,s=In(e[0],0);if(s==9){let l=i.lineAt(r),o=t.state.tabSize,u=Wr(l.text,o,r-l.from);return $e.replace({widget:new T3((o-u%o)*this.view.defaultCharacterWidth/this.view.scaleX)})}return this.decorationCache[s]||(this.decorationCache[s]=$e.replace({widget:new $3(n,s)}))},boundary:n.replaceTabs?void 0:/[^]/})}update(n){let e=n.state.facet(Bf);n.startState.facet(Bf)!=e?(this.decorator=this.makeDecorator(e),this.decorations=this.decorator.createDeco(n.view)):this.decorations=this.decorator.updateDeco(n,this.decorations)}},{decorations:n=>n.decorations}))}const C3="•";function Q3(n){return n>=32?C3:n==10?"␤":String.fromCharCode(9216+n)}class $3 extends Vr{constructor(e,t){super(),this.options=e,this.code=t}eq(e){return e.code==this.code}toDOM(e){let t=Q3(this.code),r=e.state.phrase("Control character")+" "+(b3[this.code]||"0x"+this.code.toString(16)),i=this.options.render&&this.options.render(this.code,r,t);if(i)return i;let s=document.createElement("span");return s.textContent=t,s.title=r,s.setAttribute("aria-label",r),s.className="cm-specialChar",s}ignoreEvent(){return!1}}class T3 extends Vr{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}}function j3(){return M3}const E3=$e.line({class:"cm-activeLine"}),M3=Ct.fromClass(class{constructor(n){this.decorations=this.getDeco(n)}update(n){(n.docChanged||n.selectionSet)&&(this.decorations=this.getDeco(n.view))}getDeco(n){let e=-1,t=[];for(let r of n.state.selection.ranges){let i=n.lineBlockAt(r.head);i.from>e&&(t.push(E3.range(i.from)),e=i.from)}return $e.set(t)}},{decorations:n=>n.decorations});class A3 extends Vr{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?Du(e.firstChild):[];if(!t.length)return null;let r=window.getComputedStyle(e.parentNode),i=nc(t[0],r.direction!="rtl"),s=parseInt(r.lineHeight);return i.bottom-i.top>s*1.5?{left:i.left,right:i.right,top:i.top,bottom:i.top+s}:i}ignoreEvent(){return!1}}function R3(n){let e=Ct.fromClass(class{constructor(t){this.view=t,this.placeholder=n?$e.set([$e.widget({widget:new A3(n),side:1}).range(0)]):$e.none}get decorations(){return this.view.state.doc.length?$e.none:this.placeholder}},{decorations:t=>t.decorations});return typeof n=="string"?[e,he.contentAttributes.of({"aria-placeholder":n})]:e}const jx=2e3;function N3(n,e,t){let r=Math.min(e.line,t.line),i=Math.max(e.line,t.line),s=[];if(e.off>jx||t.off>jx||e.col<0||t.col<0){let l=Math.min(e.off,t.off),o=Math.max(e.off,t.off);for(let u=r;u<=i;u++){let h=n.doc.line(u);h.length<=o&&s.push(Y.range(h.from+l,h.to+o))}}else{let l=Math.min(e.col,t.col),o=Math.max(e.col,t.col);for(let u=r;u<=i;u++){let h=n.doc.line(u),f=ux(h.text,l,n.tabSize,!0);if(f<0)s.push(Y.cursor(h.to));else{let p=ux(h.text,o,n.tabSize);s.push(Y.range(h.from+f,h.from+p))}}}return s}function L3(n,e){let t=n.coordsAtPos(n.viewport.from);return t?Math.round(Math.abs((t.left-e)/n.defaultCharacterWidth)):-1}function sw(n,e){let t=n.posAtCoords({x:e.clientX,y:e.clientY},!1),r=n.state.doc.lineAt(t),i=t-r.from,s=i>jx?-1:i==r.length?L3(n,e.clientX):Wr(r.text,n.state.tabSize,t-r.from);return{line:r.number,col:s,off:i}}function _3(n,e){let t=sw(n,e),r=n.state.selection;return t?{update(i){if(i.docChanged){let s=i.changes.mapPos(i.startState.doc.line(t.line).from),l=i.state.doc.lineAt(s);t={line:l.number,col:t.col,off:Math.min(t.off,l.length)},r=r.map(i.changes)}},get(i,s,l){let o=sw(n,i);if(!o)return r;let u=N3(n.state,t,o);return u.length?l?Y.create(u.concat(r.ranges)):Y.create(u):r}}:null}function D3(n){let e=(t=>t.altKey&&t.button==0);return he.mouseSelectionStyle.of((t,r)=>e(r)?_3(t,r):null)}const I3={Alt:[18,n=>!!n.altKey],Control:[17,n=>!!n.ctrlKey],Shift:[16,n=>!!n.shiftKey],Meta:[91,n=>!!n.metaKey]},z3={style:"cursor: crosshair"};function Z3(n={}){let[e,t]=I3[n.key||"Alt"],r=Ct.fromClass(class{constructor(i){this.view=i,this.isDown=!1}set(i){this.isDown!=i&&(this.isDown=i,this.view.update([]))}},{eventObservers:{keydown(i){this.set(i.keyCode==e||t(i))},keyup(i){(i.keyCode==e||!t(i))&&this.set(!1)},mousemove(i){this.set(t(i))}}});return[r,he.contentAttributes.of(i=>{var s;return!((s=i.plugin(r))===null||s===void 0)&&s.isDown?z3:null})]}const xf="-10000px";class cQ{constructor(e,t,r,i){this.facet=t,this.createTooltipView=r,this.removeTooltipView=i,this.input=e.state.facet(t),this.tooltips=this.input.filter(l=>l);let s=null;this.tooltipViews=this.tooltips.map(l=>s=r(l,s))}update(e,t){var r;let i=e.state.facet(this.facet),s=i.filter(u=>u);if(i===this.input){for(let u of this.tooltipViews)u.update&&u.update(e);return!1}let l=[],o=t?[]:null;for(let u=0;u<s.length;u++){let h=s[u],f=-1;if(h){for(let p=0;p<this.tooltips.length;p++){let g=this.tooltips[p];g&&g.create==h.create&&(f=p)}if(f<0)l[u]=this.createTooltipView(h,u?l[u-1]:null),o&&(o[u]=!!h.above);else{let p=l[u]=this.tooltipViews[f];o&&(o[u]=t[f]),p.update&&p.update(e)}}}for(let u of this.tooltipViews)l.indexOf(u)<0&&(this.removeTooltipView(u),(r=u.destroy)===null||r===void 0||r.call(u));return t&&(o.forEach((u,h)=>t[h]=u),t.length=o.length),this.input=i,this.tooltips=s,this.tooltipViews=l,!0}}function X3(n){let e=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const $g=ge.define({combine:n=>{var e,t,r;return{position:xe.ios?"absolute":((e=n.find(i=>i.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(i=>i.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((r=n.find(i=>i.tooltipSpace))===null||r===void 0?void 0:r.tooltipSpace)||X3}}}),lw=new WeakMap,qy=Ct.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet($g);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new cQ(n,Vy,(t,r)=>this.createTooltip(t,r),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,r=n.state.facet($g);if(r.position!=this.position&&!this.madeAbsolute){this.position=r.position;for(let i of this.manager.tooltipViews)i.dom.style.position=this.position;t=!0}if(r.parent!=this.parent){this.parent&&this.container.remove(),this.parent=r.parent,this.createContainer();for(let i of this.manager.tooltipViews)this.container.appendChild(i.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n,e){let t=n.create(this.view),r=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let i=document.createElement("div");i.className="cm-tooltip-arrow",t.dom.appendChild(i)}return t.dom.style.position=this.position,t.dom.style.top=xf,t.dom.style.left="0px",this.container.insertBefore(t.dom,r),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let r of this.manager.tooltipViews)r.dom.remove(),(n=r.destroy)===null||n===void 0||n.call(r);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:s}=this.manager.tooltipViews[0];if(xe.safari){let l=s.getBoundingClientRect();t=Math.abs(l.top+1e4)>1||Math.abs(l.left)>1}else t=!!s.offsetParent&&s.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let s=this.parent.getBoundingClientRect();s.width&&s.height&&(n=s.width/this.parent.offsetWidth,e=s.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:e}=this.view.viewState);let r=this.view.scrollDOM.getBoundingClientRect(),i=Zy(this.view);return{visible:{left:r.left+i.left,top:r.top+i.top,right:r.right-i.right,bottom:r.bottom-i.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((s,l)=>{let o=this.manager.tooltipViews[l];return o.getCoords?o.getCoords(s.pos):this.view.coordsAtPos(s.pos)}),size:this.manager.tooltipViews.map(({dom:s})=>s.getBoundingClientRect()),space:this.view.state.facet($g).tooltipSpace(this.view),scaleX:n,scaleY:e,makeAbsolute:t}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let o of this.manager.tooltipViews)o.dom.style.position="absolute"}let{visible:t,space:r,scaleX:i,scaleY:s}=n,l=[];for(let o=0;o<this.manager.tooltips.length;o++){let u=this.manager.tooltips[o],h=this.manager.tooltipViews[o],{dom:f}=h,p=n.pos[o],g=n.size[o];if(!p||u.clip!==!1&&(p.bottom<=Math.max(t.top,r.top)||p.top>=Math.min(t.bottom,r.bottom)||p.right<Math.max(t.left,r.left)-.1||p.left>Math.min(t.right,r.right)+.1)){f.style.top=xf;continue}let x=u.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,k=x?7:0,b=g.right-g.left,w=(e=lw.get(h))!==null&&e!==void 0?e:g.bottom-g.top,S=h.offset||W3,Q=this.view.textDirection==ht.LTR,$=g.width>r.right-r.left?Q?r.left:r.right-g.width:Q?Math.max(r.left,Math.min(p.left-(x?14:0)+S.x,r.right-b)):Math.min(Math.max(r.left,p.left-b+(x?14:0)-S.x),r.right-b),R=this.above[o];!u.strictSide&&(R?p.top-w-k-S.y<r.top:p.bottom+w+k+S.y>r.bottom)&&R==r.bottom-p.bottom>p.top-r.top&&(R=this.above[o]=!R);let I=(R?p.top-r.top:r.bottom-p.bottom)-k;if(I<w&&h.resize!==!1){if(I<this.view.defaultLineHeight){f.style.top=xf;continue}lw.set(h,w),f.style.height=(w=I)/s+"px"}else f.style.height&&(f.style.height="");let T=R?p.top-w-k-S.y:p.bottom+k+S.y,X=$+b;if(h.overlap!==!0)for(let Z of l)Z.left<X&&Z.right>$&&Z.top<T+w&&Z.bottom>T&&(T=R?Z.top-w-2-k:Z.bottom+k+2);if(this.position=="absolute"?(f.style.top=(T-n.parent.top)/s+"px",ow(f,($-n.parent.left)/i)):(f.style.top=T/s+"px",ow(f,$/i)),x){let Z=p.left+(Q?S.x:-S.x)-($+14-7);x.style.left=Z/i+"px"}h.overlap!==!0&&l.push({left:$,top:T,right:X,bottom:T+w}),f.classList.toggle("cm-tooltip-above",R),f.classList.toggle("cm-tooltip-below",!R),h.positioned&&h.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=xf}},{eventObservers:{scroll(){this.maybeMeasure()}}});function ow(n,e){let t=parseInt(n.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(n.style.left=e+"px")}const B3=he.baseTheme({".cm-tooltip":{zIndex:500,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:"14px",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"}}}),W3={x:0,y:0},Vy=ge.define({enables:[qy,B3]}),pd=ge.define({combine:n=>n.reduce((e,t)=>e.concat(t),[])});class ip{static create(e){return new ip(e)}constructor(e){this.view=e,this.mounted=!1,this.dom=document.createElement("div"),this.dom.classList.add("cm-tooltip-hover"),this.manager=new cQ(e,pd,(t,r)=>this.createHostedView(t,r),t=>t.dom.remove())}createHostedView(e,t){let r=e.create(this.view);return r.dom.classList.add("cm-tooltip-section"),this.dom.insertBefore(r.dom,t?t.dom.nextSibling:this.dom.firstChild),this.mounted&&r.mount&&r.mount(this.view),r}mount(e){for(let t of this.manager.tooltipViews)t.mount&&t.mount(e);this.mounted=!0}positioned(e){for(let t of this.manager.tooltipViews)t.positioned&&t.positioned(e)}update(e){this.manager.update(e)}destroy(){var e;for(let t of this.manager.tooltipViews)(e=t.destroy)===null||e===void 0||e.call(t)}passProp(e){let t;for(let r of this.manager.tooltipViews){let i=r[e];if(i!==void 0){if(t===void 0)t=i;else if(t!==i)return}}return t}get offset(){return this.passProp("offset")}get getCoords(){return this.passProp("getCoords")}get overlap(){return this.passProp("overlap")}get resize(){return this.passProp("resize")}}const q3=Vy.compute([pd],n=>{let e=n.facet(pd);return e.length===0?null:{pos:Math.min(...e.map(t=>t.pos)),end:Math.max(...e.map(t=>{var r;return(r=t.end)!==null&&r!==void 0?r:t.pos})),create:ip.create,above:e[0].above,arrow:e.some(t=>t.arrow)}}),hQ=ge.define();class V3{constructor(e,t,r,i,s,l){this.view=e,this.source=t,this.field=r,this.locked=i,this.setHover=s,this.hoverTime=l,this.hoverTimeout=-1,this.restartTimeout=-1,this.pending=null,this.lastMove={x:0,y:0,target:e.dom,time:0},this.checkHover=this.checkHover.bind(this),e.dom.addEventListener("mouseleave",this.mouseleave=this.mouseleave.bind(this)),e.dom.addEventListener("mousemove",this.mousemove=this.mousemove.bind(this))}update(e){this.pending&&(this.pending=null,clearTimeout(this.restartTimeout),this.restartTimeout=setTimeout(()=>this.startHover(),20))}get active(){return this.view.state.field(this.field)}checkHover(){if(this.hoverTimeout=-1,this.active.length)return;let e=Date.now()-this.lastMove.time;e<this.hoverTime?this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime-e):this.startHover()}startHover(){clearTimeout(this.restartTimeout);let{view:e,lastMove:t}=this,r=e.docView.tile.nearest(t.target);if(!r)return;let i,s=1;if(r.isWidget())i=r.posAtStart;else{if(i=e.posAtCoords(t),i==null)return;let l=e.coordsAtPos(i);if(!l||t.y<l.top||t.y>l.bottom||t.x<l.left-e.defaultCharacterWidth||t.x>l.right+e.defaultCharacterWidth)return;let o=e.bidiSpans(e.state.doc.lineAt(i)).find(h=>h.from<=i&&h.to>=i),u=o&&o.dir==ht.RTL?-1:1;s=t.x<l.left?-u:u}this.activateHover(e,i,s)}activateHover(e,t,r,i){let s=this.source(e,t,r),l=o=>{if(o&&!(Array.isArray(o)&&!o.length)){let u=Array.isArray(o)?o:[o];i&&this.locked.set(u,i),e.dispatch({effects:this.setHover.of(u)})}};if(s&&"then"in s){let o=this.pending={pos:t};s.then(u=>{this.pending==o&&(this.pending=null,l(u))},u=>Xn(e.state,u,"hover tooltip"))}else l(s)}get tooltip(){let e=this.view.plugin(qy),t=e?e.manager.tooltips.findIndex(r=>r.create==ip.create):-1;return t>-1?e.manager.tooltipViews[t]:null}mousemove(e){var t,r;this.lastMove={x:e.clientX,y:e.clientY,target:e.target,time:Date.now()},this.hoverTimeout<0&&(this.hoverTimeout=setTimeout(this.checkHover,this.hoverTime));let{active:i,tooltip:s}=this;if(i.length&&!this.locked.has(i)&&s&&!F3(s.dom,e)||this.pending){let{pos:l}=i[0]||this.pending,o=(r=(t=i[0])===null||t===void 0?void 0:t.end)!==null&&r!==void 0?r:l;(l==o?this.view.posAtCoords(this.lastMove)!=l:!Y3(this.view,l,o,e.clientX,e.clientY))&&(this.view.dispatch({effects:this.setHover.of([])}),this.pending=null)}}mouseleave(e){clearTimeout(this.hoverTimeout),this.hoverTimeout=-1;let{active:t}=this;if(t.length&&!this.locked.has(t)){let{tooltip:r}=this;r&&r.dom.contains(e.relatedTarget)?this.watchTooltipLeave(r.dom):this.view.dispatch({effects:this.setHover.of([])})}}watchTooltipLeave(e){let t=r=>{e.removeEventListener("mouseleave",t);let{active:i}=this;i.length&&!this.locked.has(i)&&!this.view.dom.contains(r.relatedTarget)&&this.view.dispatch({effects:this.setHover.of([])})};e.addEventListener("mouseleave",t)}destroy(){clearTimeout(this.hoverTimeout),clearTimeout(this.restartTimeout),this.view.dom.removeEventListener("mouseleave",this.mouseleave),this.view.dom.removeEventListener("mousemove",this.mousemove)}}const yf=4;function F3(n,e){let{left:t,right:r,top:i,bottom:s}=n.getBoundingClientRect(),l;if(l=n.querySelector(".cm-tooltip-arrow")){let o=l.getBoundingClientRect();i=Math.min(o.top,i),s=Math.max(o.bottom,s)}return e.clientX>=t-yf&&e.clientX<=r+yf&&e.clientY>=i-yf&&e.clientY<=s+yf}function Y3(n,e,t,r,i,s){let l=n.scrollDOM.getBoundingClientRect(),o=n.documentTop+n.documentPadding.top+n.contentHeight;if(l.left>r||l.right<r||l.top>i||Math.min(l.bottom,o)<i)return!1;let u=n.posAtCoords({x:r,y:i},!1);return u>=e&&u<=t}function U3(n,e={}){let t=Ne.define(),r=new WeakMap,i=an.define({create(){return[]},update(l,o){let u=r.get(l);if(l.length&&(e.hideOnChange&&(o.docChanged||o.selection)?l=[]:u&&u(o)?l=[]:e.hideOn&&(l=l.filter(h=>!e.hideOn(o,h)))),o.docChanged&&l.length){let h=[];for(let f of l){let p=o.changes.mapPos(f.pos,-1,sn.TrackDel);if(p!=null){let g=Object.assign(Object.create(null),f);g.pos=p,g.end!=null&&(g.end=o.changes.mapPos(g.end)),h.push(g)}}l=h}for(let h of o.effects)h.is(t)&&(l=h.value,u=void 0),(h.is(H3)&&!h.value||h.value==i)&&(l=[]);return l.length&&u&&r.set(l,u),l},provide:l=>pd.from(l)});const s=Ct.define(l=>new V3(l,n,i,r,t,e.hoverTime||300));return{active:i,extension:[i,s,hQ.of(s),q3]}}function G3(n,e,t,r={}){var i;let s=n.state.facet(hQ).map(l=>n.plugin(l)).filter(l=>!!l);if(r.tooltip&&r.tooltip.active){let l=s.find(o=>o.field==r.tooltip.active);l&&(s=[l])}for(let l of s)l.activateHover(n,e,t,(i=r.until)!==null&&i!==void 0?i:(()=>!1))}function fQ(n,e){let t=n.plugin(qy);if(!t)return null;let r=t.manager.tooltips.indexOf(e);return r<0?null:t.manager.tooltipViews[r]}const H3=Ne.define(),aw=ge.define({combine(n){let e,t;for(let r of n)e=e||r.topContainer,t=t||r.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Fy(n,e){let t=n.plugin(dQ),r=t?t.specs.indexOf(e):-1;return r>-1?t.panels[r]:null}const dQ=Ct.fromClass(class{constructor(n){this.input=n.state.facet(ic),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(aw);this.top=new kf(n,!0,e.topContainer),this.bottom=new kf(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(aw);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new kf(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new kf(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(ic);if(t!=this.input){let r=t.filter(u=>u),i=[],s=[],l=[],o=[];for(let u of r){let h=this.specs.indexOf(u),f;h<0?(f=u(n.view),o.push(f)):(f=this.panels[h],f.update&&f.update(n)),i.push(f),(f.top?s:l).push(f)}this.specs=r,this.panels=i,this.top.sync(s),this.bottom.sync(l);for(let u of o)u.dom.classList.add("cm-panel"),u.mount&&u.mount()}else for(let r of this.panels)r.update&&r.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>he.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class kf{constructor(e,t,r){this.view=e,this.top=t,this.container=r,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=uw(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=uw(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function uw(n){let e=n.nextSibling;return n.remove(),e}const ic=ge.define({enables:dQ});function K3(n,e){let t,r=new Promise(l=>t=l),i=l=>J3(l,e,t);n.state.field(Tg,!1)?n.dispatch({effects:pQ.of(i)}):n.dispatch({effects:Ne.appendConfig.of(Tg.init(()=>[i]))});let s=mQ.of(i);return{close:s,result:r.then(l=>((n.win.queueMicrotask||(u=>n.win.setTimeout(u,10)))(()=>{n.state.field(Tg).indexOf(i)>-1&&n.dispatch({effects:s})}),l))}}const Tg=an.define({create(){return[]},update(n,e){for(let t of e.effects)t.is(pQ)?n=[t.value].concat(n):t.is(mQ)&&(n=n.filter(r=>r!=t.value));return n},provide:n=>ic.computeN([n],e=>e.field(n))}),pQ=Ne.define(),mQ=Ne.define();function J3(n,e,t){let r=e.content?e.content(n,()=>l(null)):null;if(!r){if(r=lt("form"),e.input){let o=lt("input",e.input);/^(text|password|number|email|tel|url)$/.test(o.type)&&o.classList.add("cm-textfield"),o.name||(o.name="input"),r.appendChild(lt("label",(e.label||"")+": ",o))}else r.appendChild(document.createTextNode(e.label||""));r.appendChild(document.createTextNode(" ")),r.appendChild(lt("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let i=r.nodeName=="FORM"?[r]:r.querySelectorAll("form");for(let o=0;o<i.length;o++){let u=i[o];u.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),l(null)):h.keyCode==13&&(h.preventDefault(),l(u))}),u.addEventListener("submit",h=>{h.preventDefault(),l(u)})}let s=lt("div",r,lt("button",{onclick:()=>l(null),"aria-label":n.state.phrase("close"),class:"cm-dialog-close",type:"button"},["×"]));e.class&&(s.className=e.class),s.classList.add("cm-dialog");function l(o){s.contains(s.ownerDocument.activeElement)&&n.focus(),t(o)}return{dom:s,top:e.top,mount:()=>{if(e.focus){let o;typeof e.focus=="string"?o=r.querySelector(e.focus):o=r.querySelector("input")||r.querySelector("button"),o&&"select"in o?o.select():o&&"focus"in o&&o.focus()}}}}class Fi extends Xs{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}Fi.prototype.elementClass="";Fi.prototype.toDOM=void 0;Fi.prototype.mapMode=sn.TrackBefore;Fi.prototype.startSide=Fi.prototype.endSide=-1;Fi.prototype.point=!0;const Wf=ge.define(),e_=ge.define(),t_={class:"",renderEmptyElements:!1,elementStyle:"",markers:()=>We.empty,lineMarker:()=>null,widgetMarker:()=>null,lineMarkerChange:null,initialSpacer:null,updateSpacer:null,domEventHandlers:{},side:"before"},Zu=ge.define();function n_(n){return[gQ(),Zu.of({...t_,...n})]}const cw=ge.define({combine:n=>n.some(e=>e)});function gQ(n){return[r_]}const r_=Ct.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(Zu).map(e=>new fw(n,e)),this.fixed=!n.state.facet(cw);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,r=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(r<(t.to-t.from)*.8)}if(n.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(cw)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=We.iter(this.view.state.facet(Wf),this.view.viewport.from),r=[],i=this.gutters.map(s=>new i_(s,this.view.viewport,-this.view.documentPadding.top));for(let s of this.view.viewportLineBlocks)if(r.length&&(r=[]),Array.isArray(s.type)){let l=!0;for(let o of s.type)if(o.type==ln.Text&&l){Ex(t,r,o.from);for(let u of i)u.line(this.view,o,r);l=!1}else if(o.widget)for(let u of i)u.widget(this.view,o)}else if(s.type==ln.Text){Ex(t,r,s.from);for(let l of i)l.line(this.view,s,r)}else if(s.widget)for(let l of i)l.widget(this.view,s);for(let s of i)s.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(Zu),t=n.state.facet(Zu),r=n.docChanged||n.heightChanged||n.viewportChanged||!We.eq(n.startState.facet(Wf),n.state.facet(Wf),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let i of this.gutters)i.update(n)&&(r=!0);else{r=!0;let i=[];for(let s of t){let l=e.indexOf(s);l<0?i.push(new fw(this.view,s)):(this.gutters[l].update(n),i.push(this.gutters[l]))}for(let s of this.gutters)s.dom.remove(),i.indexOf(s)<0&&s.destroy();for(let s of i)s.config.side=="after"?this.getDOMAfter().appendChild(s.dom):this.dom.appendChild(s.dom);this.gutters=i}return r}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>he.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let r=t.dom.offsetWidth*e.scaleX,i=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==ht.LTR?{left:r,right:i}:{right:r,left:i}})});function hw(n){return Array.isArray(n)?n:[n]}function Ex(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}class i_{constructor(e,t,r){this.gutter=e,this.height=r,this.i=0,this.cursor=We.iter(e.markers,t.from)}addElement(e,t,r){let{gutter:i}=this,s=(t.top-this.height)/e.scaleY,l=t.height/e.scaleY;if(this.i==i.elements.length){let o=new OQ(e,l,s,r);i.elements.push(o),i.dom.appendChild(o.dom)}else i.elements[this.i].update(e,l,s,r);this.height=t.bottom,this.i++}line(e,t,r){let i=[];Ex(this.cursor,i,t.from),r.length&&(i=i.concat(r));let s=this.gutter.config.lineMarker(e,t,i);s&&i.unshift(s);let l=this.gutter;i.length==0&&!l.config.renderEmptyElements||this.addElement(e,t,i)}widget(e,t){let r=this.gutter.config.widgetMarker(e,t.widget,t),i=r?[r]:null;for(let s of e.state.facet(e_)){let l=s(e,t.widget,t);l&&(i||(i=[])).push(l)}i&&this.addElement(e,t,i)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class fw{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let r in t.domEventHandlers)this.dom.addEventListener(r,i=>{let s=i.target,l;if(s!=this.dom&&this.dom.contains(s)){for(;s.parentNode!=this.dom;)s=s.parentNode;let u=s.getBoundingClientRect();l=(u.top+u.bottom)/2}else l=i.clientY;let o=e.lineBlockAtHeight(l-e.documentTop);t.domEventHandlers[r](e,o,i)&&i.preventDefault()});this.markers=hw(t.markers(e)),t.initialSpacer&&(this.spacer=new OQ(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=hw(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let i=this.config.updateSpacer(this.spacer.markers[0],e);i!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[i])}let r=e.view.viewport;return!We.eq(this.markers,t,r.from,r.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class OQ{constructor(e,t,r,i){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,r,i)}update(e,t,r,i){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=r&&(this.dom.style.marginTop=(this.above=r)?r+"px":""),s_(this.markers,i)||this.setMarkers(e,i)}setMarkers(e,t){let r="cm-gutterElement",i=this.dom.firstChild;for(let s=0,l=0;;){let o=l,u=s<t.length?t[s++]:null,h=!1;if(u){let f=u.elementClass;f&&(r+=" "+f);for(let p=l;p<this.markers.length;p++)if(this.markers[p].compare(u)){o=p,h=!0;break}}else o=this.markers.length;for(;l<o;){let f=this.markers[l++];if(f.toDOM){f.destroy(i);let p=i.nextSibling;i.remove(),i=p}}if(!u)break;u.toDOM&&(h?i=i.nextSibling:this.dom.insertBefore(u.toDOM(e),i)),h&&l++}this.dom.className=r,this.markers=t}destroy(){this.setMarkers(null,[])}}function s_(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}const l_=ge.define(),o_=ge.define(),Ao=ge.define({combine(n){return bi(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let r=Object.assign({},e);for(let i in t){let s=r[i],l=t[i];r[i]=s?(o,u,h)=>s(o,u,h)||l(o,u,h):l}return r}})}});class jg extends Fi{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Eg(n,e){return n.state.facet(Ao).formatNumber(e,n.state)}const a_=Zu.compute([Ao],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(l_)},lineMarker(e,t,r){return r.some(i=>i.toDOM)?null:new jg(Eg(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,r)=>{for(let i of e.state.facet(o_)){let s=i(e,t,r);if(s)return s}return null},lineMarkerChange:e=>e.startState.facet(Ao)!=e.state.facet(Ao),initialSpacer(e){return new jg(Eg(e,dw(e.state.doc.lines)))},updateSpacer(e,t){let r=Eg(t.view,dw(t.view.state.doc.lines));return r==e.number?e:new jg(r)},domEventHandlers:n.facet(Ao).domEventHandlers,side:"before"}));function u_(n={}){return[Ao.of(n),gQ(),a_]}function dw(n){let e=9;for(;e<n;)e=e*10+9;return e}const c_=new class extends Fi{constructor(){super(...arguments),this.elementClass="cm-activeLineGutter"}},h_=Wf.compute(["selection"],n=>{let e=[],t=-1;for(let r of n.selection.ranges){let i=n.doc.lineAt(r.head).from;i>t&&(t=i,e.push(c_.range(i)))}return We.of(e)});function f_(){return h_}const xQ=1024;let d_=0;class Pr{constructor(e,t){this.from=e,this.to=t}}class Le{constructor(e={}){this.id=d_++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Dt.match(e)),t=>{let r=e(t);return r===void 0?null:[this,r]}}}Le.closedBy=new Le({deserialize:n=>n.split(" ")});Le.openedBy=new Le({deserialize:n=>n.split(" ")});Le.group=new Le({deserialize:n=>n.split(" ")});Le.isolate=new Le({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});Le.contextHash=new Le({perNode:!0});Le.lookAhead=new Le({perNode:!0});Le.mounted=new Le({perNode:!0});class Io{constructor(e,t,r,i=!1){this.tree=e,this.overlay=t,this.parser=r,this.bracketed=i}static get(e){return e&&e.props&&e.props[Le.mounted.id]}}const p_=Object.create(null);class Dt{constructor(e,t,r,i=0){this.name=e,this.props=t,this.id=r,this.flags=i}static define(e){let t=e.props&&e.props.length?Object.create(null):p_,r=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),i=new Dt(e.name||"",t,e.id,r);if(e.props){for(let s of e.props)if(Array.isArray(s)||(s=s(i)),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 i}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(Le.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let r in e)for(let i of r.split(" "))t[i]=e[r];return r=>{for(let i=r.prop(Le.group),s=-1;s<(i?i.length:0);s++){let l=t[s<0?r.name:i[s]];if(l)return l}}}}Dt.none=new Dt("",Object.create(null),0,8);class Lc{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 r of this.types){let i=null;for(let s of e){let l=s(r);if(l){i||(i=Object.assign({},r.props));let o=l[1],u=l[0];u.combine&&u.id in i&&(o=u.combine(i[u.id],o)),i[u.id]=o}}t.push(i?new Dt(r.name,i,r.id,r.flags):r)}return new Lc(t)}}const vf=new WeakMap,pw=new WeakMap;var nt;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(nt||(nt={}));class tt{constructor(e,t,r,i,s){if(this.type=e,this.children=t,this.positions=r,this.length=i,this.props=null,s&&s.length){this.props=Object.create(null);for(let[l,o]of s)this.props[typeof l=="number"?l:l.id]=o}}toString(){let e=Io.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let r of this.children){let i=r.toString();i&&(t&&(t+=","),t+=i)}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 md(this.topNode,e)}cursorAt(e,t=0,r=0){let i=vf.get(this)||this.topNode,s=new md(i);return s.moveTo(e,t),vf.set(this,s._tree),s}get topNode(){return new gn(this,0,0,null)}resolve(e,t=0){let r=sc(vf.get(this)||this.topNode,e,t,!1);return vf.set(this,r),r}resolveInner(e,t=0){let r=sc(pw.get(this)||this.topNode,e,t,!0);return pw.set(this,r),r}resolveStack(e,t=0){return O_(this,e,t)}iterate(e){let{enter:t,leave:r,from:i=0,to:s=this.length}=e,l=e.mode||0,o=(l&nt.IncludeAnonymous)>0;for(let u=this.cursor(l|nt.IncludeAnonymous);;){let h=!1;if(u.from<=s&&u.to>=i&&(!o&&u.type.isAnonymous||t(u)!==!1)){if(u.firstChild())continue;h=!0}for(;h&&r&&(o||!u.type.isAnonymous)&&r(u),!u.nextSibling();){if(!u.parent())return;h=!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:Gy(Dt.none,this.children,this.positions,0,this.children.length,0,this.length,(t,r,i)=>new tt(this.type,t,r,i,this.propValues),e.makeTree||((t,r,i)=>new tt(Dt.none,t,r,i)))}static build(e){return x_(e)}}tt.empty=new tt(Dt.none,[],[],0);class Yy{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 Yy(this.buffer,this.index)}}class Vs{constructor(e,t,r){this.buffer=e,this.length=t,this.set=r}get type(){return Dt.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],r=this.buffer[e+3],i=this.set.types[t],s=i.name;if(/\W/.test(s)&&!i.isError&&(s=JSON.stringify(s)),e+=4,r==e)return s;let l=[];for(;e<r;)l.push(this.childString(e)),e=this.buffer[e+3];return s+"("+l.join(",")+")"}findChild(e,t,r,i,s){let{buffer:l}=this,o=-1;for(let u=e;u!=t&&!(yQ(s,i,l[u+1],l[u+2])&&(o=u,r>0));u=l[u+3]);return o}slice(e,t,r){let i=this.buffer,s=new Uint16Array(t-e),l=0;for(let o=e,u=0;o<t;){s[u++]=i[o++],s[u++]=i[o++]-r;let h=s[u++]=i[o++]-r;s[u++]=i[o++]-e,l=Math.max(l,h)}return new Vs(s,l,this.set)}}function yQ(n,e,t,r){switch(n){case-2:return t<e;case-1:return r>=e&&t<e;case 0:return t<e&&r>e;case 1:return t<=e&&r>e;case 2:return r>e;case 4:return!0}}function sc(n,e,t,r){for(var i;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let l=!r&&n instanceof gn&&n.index<0?null:n.parent;if(!l)return n;n=l}let s=r?0:nt.IgnoreOverlays;if(r)for(let l=n,o=l.parent;o;l=o,o=l.parent)l instanceof gn&&l.index<0&&((i=o.enter(e,t,s))===null||i===void 0?void 0:i.from)!=l.from&&(n=o);for(;;){let l=n.enter(e,t,s);if(!l)return n;n=l}}class kQ{cursor(e=0){return new md(this,e)}getChild(e,t=null,r=null){let i=mw(this,e,t,r);return i.length?i[0]:null}getChildren(e,t=null,r=null){return mw(this,e,t,r)}resolve(e,t=0){return sc(this,e,t,!1)}resolveInner(e,t=0){return sc(this,e,t,!0)}matchContext(e){return Mx(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),r=this;for(;t;){let i=t.lastChild;if(!i||i.to!=t.to)break;i.type.isError&&i.from==i.to?(r=t,t=i.prevSibling):t=i}return r}get node(){return this}get next(){return this.parent}}class gn extends kQ{constructor(e,t,r,i){super(),this._tree=e,this.from=t,this.index=r,this._parent=i}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,r,i,s=0){for(let l=this;;){for(let{children:o,positions:u}=l._tree,h=t>0?o.length:-1;e!=h;e+=t){let f=o[e],p=u[e]+l.from,g;if(!(!(s&nt.EnterBracketed&&f instanceof tt&&(g=Io.get(f))&&!g.overlay&&g.bracketed&&r>=p&&r<=p+f.length)&&!yQ(i,r,p,p+f.length))){if(f instanceof Vs){if(s&nt.ExcludeBuffers)continue;let x=f.findChild(0,f.buffer.length,t,r-p,i);if(x>-1)return new pi(new m_(l,f,e,p),null,x)}else if(s&nt.IncludeAnonymous||!f.type.isAnonymous||Uy(f)){let x;if(!(s&nt.IgnoreMounts)&&(x=Io.get(f))&&!x.overlay)return new gn(x.tree,p,e,l);let k=new gn(f,p,e,l);return s&nt.IncludeAnonymous||!k.type.isAnonymous?k:k.nextChild(t<0?f.children.length-1:0,t,r,i,s)}}}if(s&nt.IncludeAnonymous||!l.type.isAnonymous||(l.index>=0?e=l.index+t:e=t<0?-1:l._parent._tree.children.length,l=l._parent,!l))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)}prop(e){return this._tree.prop(e)}enter(e,t,r=0){let i;if(!(r&nt.IgnoreOverlays)&&(i=Io.get(this._tree))&&i.overlay){let s=e-this.from,l=r&nt.EnterBracketed&&i.bracketed;for(let{from:o,to:u}of i.overlay)if((t>0||l?o<=s:o<s)&&(t<0||l?u>=s:u>s))return new gn(i.tree,i.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,r)}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}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function mw(n,e,t,r){let i=n.cursor(),s=[];if(!i.firstChild())return s;if(t!=null){for(let l=!1;!l;)if(l=i.type.is(t),!i.nextSibling())return s}for(;;){if(r!=null&&i.type.is(r))return s;if(i.type.is(e)&&s.push(i.node),!i.nextSibling())return r==null?s:[]}}function Mx(n,e,t=e.length-1){for(let r=n;t>=0;r=r.parent){if(!r)return!1;if(!r.type.isAnonymous){if(e[t]&&e[t]!=r.name)return!1;t--}}return!0}class m_{constructor(e,t,r,i){this.parent=e,this.buffer=t,this.index=r,this.start=i}}class pi extends kQ{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,r){super(),this.context=e,this._parent=t,this.index=r,this.type=e.buffer.set.types[e.buffer.buffer[r]]}child(e,t,r){let{buffer:i}=this.context,s=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.context.start,r);return s<0?null:new pi(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)}prop(e){return this.type.prop(e)}enter(e,t,r=0){if(r&nt.ExcludeBuffers)return null;let{buffer:i}=this.context,s=i.findChild(this.index+4,i.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return s<0?null:new pi(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 pi(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 pi(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:r}=this.context,i=this.index+4,s=r.buffer[this.index+3];if(s>i){let l=r.buffer[this.index+1];e.push(r.slice(i,s,l)),t.push(0)}return new tt(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function vQ(n){if(!n.length)return null;let e=0,t=n[0];for(let s=1;s<n.length;s++){let l=n[s];(l.from>t.from||l.to<t.to)&&(t=l,e=s)}let r=t instanceof gn&&t.index<0?null:t.parent,i=n.slice();return r?i[e]=r:i.splice(e,1),new g_(i,t)}class g_{constructor(e,t){this.heads=e,this.node=t}get next(){return vQ(this.heads)}}function O_(n,e,t){let r=n.resolveInner(e,t),i=null;for(let s=r instanceof gn?r:r.context.parent;s;s=s.parent)if(s.index<0){let l=s.parent;(i||(i=[r])).push(l.resolve(e,t)),s=l}else{let l=Io.get(s.tree);if(l&&l.overlay&&l.overlay[0].from<=e&&l.overlay[l.overlay.length-1].to>=e){let o=new gn(l.tree,l.overlay[0].from+s.from,-1,s);(i||(i=[r])).push(sc(o,e,t,!1))}}return i?vQ(i):r}class md{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~nt.EnterBracketed,e instanceof gn)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;for(let r=e._parent;r;r=r._parent)this.stack.unshift(r.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:r,buffer:i}=this.buffer;return this.type=t||i.set.types[i.buffer[e]],this.from=r+i.buffer[e+1],this.to=r+i.buffer[e+2],!0}yield(e){return e?e instanceof gn?(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,r){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,r,this.mode));let{buffer:i}=this.buffer,s=i.findChild(this.index+4,i.buffer[this.index+3],e,t-this.buffer.start,r);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,r=this.mode){return this.buffer?r&nt.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,r))}parent(){if(!this.buffer)return this.yieldNode(this.mode&nt.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&nt.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,r=this.stack.length-1;if(e<0){let i=r<0?0:this.stack[r]+4;if(this.index!=i)return this.yieldBuf(t.findChild(i,this.index,-1,0,4))}else{let i=t.buffer[this.index+3];if(i<(r<0?t.buffer.length:t.buffer[this.stack[r]+3]))return this.yieldBuf(i)}return r<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,r,{buffer:i}=this;if(i){if(e>0){if(this.index<i.buffer.buffer.length)return!1}else for(let s=0;s<this.index;s++)if(i.buffer.buffer[s+3]<this.index)return!1;({index:t,parent:r}=i)}else({index:t,_parent:r}=this._tree);for(;r;{index:t,_parent:r}=r)if(t>-1)for(let s=t+e,l=e<0?-1:r._tree.children.length;s!=l;s+=e){let o=r._tree.children[s];if(this.mode&nt.IncludeAnonymous||o instanceof Vs||!o.type.isAnonymous||Uy(o))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,r=0;if(e&&e.context==this.buffer)e:for(let i=this.index,s=this.stack.length;s>=0;){for(let l=e;l;l=l._parent)if(l.index==i){if(i==this.index)return l;t=l,r=s+1;break e}i=this.stack[--s]}for(let i=r;i<this.stack.length;i++)t=new pi(this.buffer,t,this.stack[i]);return this.bufferNode=new pi(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let r=0;;){let i=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){r++;continue}this.type.isAnonymous||(i=!0)}for(;;){if(i&&t&&t(this),i=this.type.isAnonymous,!r)return;if(this.nextSibling())break;this.parent(),r--,i=!0}}}matchContext(e){if(!this.buffer)return Mx(this.node.parent,e);let{buffer:t}=this.buffer,{types:r}=t.set;for(let i=e.length-1,s=this.stack.length-1;i>=0;s--){if(s<0)return Mx(this._tree,e,i);let l=r[t.buffer[this.stack[s]]];if(!l.isAnonymous){if(e[i]&&e[i]!=l.name)return!1;i--}}return!0}}function Uy(n){return n.children.some(e=>e instanceof Vs||!e.type.isAnonymous||Uy(e))}function x_(n){var e;let{buffer:t,nodeSet:r,maxBufferLength:i=xQ,reused:s=[],minRepeatType:l=r.types.length}=n,o=Array.isArray(t)?new Yy(t,t.length):t,u=r.types,h=0,f=0;function p(I,T,X,Z,H,N){let{id:U,start:V,end:se,size:K}=o,G=f,Oe=h;if(K<0)if(o.next(),K==-1){let D=s[U];X.push(D),Z.push(V-I);return}else if(K==-3){h=U;return}else if(K==-4){f=U;return}else throw new RangeError(`Unrecognized record size: ${K}`);let de=u[U],ee,le,C=V-I;if(se-V<=i&&(le=w(o.pos-T,H))){let D=new Uint16Array(le.size-le.skip),F=o.pos-le.size,E=D.length;for(;o.pos>F;)E=S(le.start,D,E);ee=new Vs(D,se-le.start,r),C=le.start-I}else{let D=o.pos-K;o.next();let F=[],E=[],ce=U>=l?U:-1,ye=0,me=se;for(;o.pos>D;)ce>=0&&o.id==ce&&o.size>=0?(o.end<=me-i&&(k(F,E,V,ye,o.end,me,ce,G,Oe),ye=F.length,me=o.end),o.next()):N>2500?g(V,D,F,E):p(V,D,F,E,ce,N+1);if(ce>=0&&ye>0&&ye<F.length&&k(F,E,V,ye,V,me,ce,G,Oe),F.reverse(),E.reverse(),ce>-1&&ye>0){let Ie=x(de,Oe);ee=Gy(de,F,E,0,F.length,0,se-V,Ie,Ie)}else ee=b(de,F,E,se-V,G-se,Oe)}X.push(ee),Z.push(C)}function g(I,T,X,Z){let H=[],N=0,U=-1;for(;o.pos>T;){let{id:V,start:se,end:K,size:G}=o;if(G>4)o.next();else{if(U>-1&&se<U)break;U<0&&(U=K-i),H.push(V,se,K),N++,o.next()}}if(N){let V=new Uint16Array(N*4),se=H[H.length-2];for(let K=H.length-3,G=0;K>=0;K-=3)V[G++]=H[K],V[G++]=H[K+1]-se,V[G++]=H[K+2]-se,V[G++]=G;X.push(new Vs(V,H[2]-se,r)),Z.push(se-I)}}function x(I,T){return(X,Z,H)=>{let N=0,U=X.length-1,V,se;if(U>=0&&(V=X[U])instanceof tt){if(!U&&V.type==I&&V.length==H)return V;(se=V.prop(Le.lookAhead))&&(N=Z[U]+V.length+se)}return b(I,X,Z,H,N,T)}}function k(I,T,X,Z,H,N,U,V,se){let K=[],G=[];for(;I.length>Z;)K.push(I.pop()),G.push(T.pop()+X-H);I.push(b(r.types[U],K,G,N-H,V-N,se)),T.push(H-X)}function b(I,T,X,Z,H,N,U){if(N){let V=[Le.contextHash,N];U=U?[V].concat(U):[V]}if(H>25){let V=[Le.lookAhead,H];U=U?[V].concat(U):[V]}return new tt(I,T,X,Z,U)}function w(I,T){let X=o.fork(),Z=0,H=0,N=0,U=X.end-i,V={size:0,start:0,skip:0};e:for(let se=X.pos-I;X.pos>se;){let K=X.size;if(X.id==T&&K>=0){V.size=Z,V.start=H,V.skip=N,N+=4,Z+=4,X.next();continue}let G=X.pos-K;if(K<0||G<se||X.start<U)break;let Oe=X.id>=l?4:0,de=X.start;for(X.next();X.pos>G;){if(X.size<0)if(X.size==-3||X.size==-4)Oe+=4;else break e;else X.id>=l&&(Oe+=4);X.next()}H=de,Z+=K,N+=Oe}return(T<0||Z==I)&&(V.size=Z,V.start=H,V.skip=N),V.size>4?V:void 0}function S(I,T,X){let{id:Z,start:H,end:N,size:U}=o;if(o.next(),U>=0&&Z<l){let V=X;if(U>4){let se=o.pos-(U-4);for(;o.pos>se;)X=S(I,T,X)}T[--X]=V,T[--X]=N-I,T[--X]=H-I,T[--X]=Z}else U==-3?h=Z:U==-4&&(f=Z);return X}let Q=[],$=[];for(;o.pos>0;)p(n.start||0,n.bufferStart||0,Q,$,-1,0);let R=(e=n.length)!==null&&e!==void 0?e:Q.length?$[0]+Q[0].length:0;return new tt(u[n.topID],Q.reverse(),$.reverse(),R)}const gw=new WeakMap;function qf(n,e){if(!n.isAnonymous||e instanceof Vs||e.type!=n)return 1;let t=gw.get(e);if(t==null){t=1;for(let r of e.children){if(r.type!=n||!(r instanceof tt)){t=1;break}t+=qf(n,r)}gw.set(e,t)}return t}function Gy(n,e,t,r,i,s,l,o,u){let h=0;for(let k=r;k<i;k++)h+=qf(n,e[k]);let f=Math.ceil(h*1.5/8),p=[],g=[];function x(k,b,w,S,Q){for(let $=w;$<S;){let R=$,I=b[$],T=qf(n,k[$]);for($++;$<S;$++){let X=qf(n,k[$]);if(T+X>=f)break;T+=X}if($==R+1){if(T>f){let X=k[R];x(X.children,X.positions,0,X.children.length,b[R]+Q);continue}p.push(k[R])}else{let X=b[$-1]+k[$-1].length-I;p.push(Gy(n,k,b,R,$,I,X,null,u))}g.push(I+Q-s)}}return x(e,t,r,i,0),(o||u)(p,g,l)}class bQ{constructor(){this.map=new WeakMap}setBuffer(e,t,r){let i=this.map.get(e);i||this.map.set(e,i=new Map),i.set(t,r)}getBuffer(e,t){let r=this.map.get(e);return r&&r.get(t)}set(e,t){e instanceof pi?this.setBuffer(e.context.buffer,e.index,t):e instanceof gn&&this.map.set(e.tree,t)}get(e){return e instanceof pi?this.getBuffer(e.context.buffer,e.index):e instanceof gn?this.map.get(e.tree):void 0}cursorSet(e,t){e.buffer?this.setBuffer(e.buffer.buffer,e.index,t):this.map.set(e.tree,t)}cursorGet(e){return e.buffer?this.getBuffer(e.buffer.buffer,e.index):this.map.get(e.tree)}}class Bi{constructor(e,t,r,i,s=!1,l=!1){this.from=e,this.to=t,this.tree=r,this.offset=i,this.open=(s?1:0)|(l?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],r=!1){let i=[new Bi(0,e.length,e,0,!1,r)];for(let s of t)s.to>e.length&&i.push(s);return i}static applyChanges(e,t,r=128){if(!t.length)return e;let i=[],s=1,l=e.length?e[0]:null;for(let o=0,u=0,h=0;;o++){let f=o<t.length?t[o]:null,p=f?f.fromA:1e9;if(p-u>=r)for(;l&&l.from<p;){let g=l;if(u>=g.from||p<=g.to||h){let x=Math.max(g.from,u)-h,k=Math.min(g.to,p)-h;g=x>=k?null:new Bi(x,k,g.tree,g.offset+h,o>0,!!f)}if(g&&i.push(g),l.to>p)break;l=s<e.length?e[s++]:null}if(!f)break;u=f.toA,h=f.toA-f.toB}return i}}class Hy{startParse(e,t,r){return typeof e=="string"&&(e=new y_(e)),r=r?r.length?r.map(i=>new Pr(i.from,i.to)):[new Pr(0,0)]:[new Pr(0,e.length)],this.createParse(e,t||[],r)}parse(e,t,r){let i=this.startParse(e,t,r);for(;;){let s=i.advance();if(s)return s}}}class y_{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)}}function wQ(n){return(e,t,r,i)=>new v_(e,n,t,r,i)}class Ow{constructor(e,t,r,i,s,l){this.parser=e,this.parse=t,this.overlay=r,this.bracketed=i,this.target=s,this.from=l}}function xw(n){if(!n.length||n.some(e=>e.from>=e.to))throw new RangeError("Invalid inner parse ranges given: "+JSON.stringify(n))}class k_{constructor(e,t,r,i,s,l,o,u){this.parser=e,this.predicate=t,this.mounts=r,this.index=i,this.start=s,this.bracketed=l,this.target=o,this.prev=u,this.depth=0,this.ranges=[]}}const Ax=new Le({perNode:!0});class v_{constructor(e,t,r,i,s){this.nest=t,this.input=r,this.fragments=i,this.ranges=s,this.inner=[],this.innerDone=0,this.baseTree=null,this.stoppedAt=null,this.baseParse=e}advance(){if(this.baseParse){let r=this.baseParse.advance();if(!r)return null;if(this.baseParse=null,this.baseTree=r,this.startInner(),this.stoppedAt!=null)for(let i of this.inner)i.parse.stopAt(this.stoppedAt)}if(this.innerDone==this.inner.length){let r=this.baseTree;return this.stoppedAt!=null&&(r=new tt(r.type,r.children,r.positions,r.length,r.propValues.concat([[Ax,this.stoppedAt]]))),r}let e=this.inner[this.innerDone],t=e.parse.advance();if(t){this.innerDone++;let r=Object.assign(Object.create(null),e.target.props);r[Le.mounted.id]=new Io(t,e.overlay,e.parser,e.bracketed),e.target.props=r}return null}get parsedPos(){if(this.baseParse)return 0;let e=this.input.length;for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].from<e&&(e=Math.min(e,this.inner[t].parse.parsedPos));return e}stopAt(e){if(this.stoppedAt=e,this.baseParse)this.baseParse.stopAt(e);else for(let t=this.innerDone;t<this.inner.length;t++)this.inner[t].parse.stopAt(e)}startInner(){let e=new S_(this.fragments),t=null,r=null,i=new md(new gn(this.baseTree,this.ranges[0].from,0,null),nt.IncludeAnonymous|nt.IgnoreMounts);e:for(let s,l;;){let o=!0,u;if(this.stoppedAt!=null&&i.from>=this.stoppedAt)o=!1;else if(e.hasNode(i)){if(t){let h=t.mounts.find(f=>f.frag.from<=i.from&&f.frag.to>=i.to&&f.mount.overlay);if(h)for(let f of h.mount.overlay){let p=f.from+h.pos,g=f.to+h.pos;p>=i.from&&g<=i.to&&!t.ranges.some(x=>x.from<g&&x.to>p)&&t.ranges.push({from:p,to:g})}}o=!1}else if(r&&(l=b_(r.ranges,i.from,i.to)))o=l!=2;else if(!i.type.isAnonymous&&(s=this.nest(i,this.input))&&(i.from<i.to||!s.overlay)){i.tree||(w_(i),t&&t.depth++,r&&r.depth++);let h=e.findMounts(i.from,s.parser);if(typeof s.overlay=="function")t=new k_(s.parser,s.overlay,h,this.inner.length,i.from,!!s.bracketed,i.tree,t);else{let f=vw(this.ranges,s.overlay||(i.from<i.to?[new Pr(i.from,i.to)]:[]));f.length&&xw(f),(f.length||!s.overlay)&&this.inner.push(new Ow(s.parser,f.length?s.parser.startParse(this.input,bw(h,f),f):s.parser.startParse(""),s.overlay?s.overlay.map(p=>new Pr(p.from-i.from,p.to-i.from)):null,!!s.bracketed,i.tree,f.length?f[0].from:i.from)),s.overlay?f.length&&(r={ranges:f,depth:0,prev:r}):o=!1}}else if(t&&(u=t.predicate(i))&&(u===!0&&(u=new Pr(i.from,i.to)),u.from<u.to)){let h=t.ranges.length-1;h>=0&&t.ranges[h].to==u.from?t.ranges[h]={from:t.ranges[h].from,to:u.to}:t.ranges.push(u)}if(o&&i.firstChild())t&&t.depth++,r&&r.depth++;else for(;!i.nextSibling();){if(!i.parent())break e;if(t&&!--t.depth){let h=vw(this.ranges,t.ranges);h.length&&(xw(h),this.inner.splice(t.index,0,new Ow(t.parser,t.parser.startParse(this.input,bw(t.mounts,h),h),t.ranges.map(f=>new Pr(f.from-t.start,f.to-t.start)),t.bracketed,t.target,h[0].from))),t=t.prev}r&&!--r.depth&&(r=r.prev)}}}}function b_(n,e,t){for(let r of n){if(r.from>=t)break;if(r.to>e)return r.from<=e&&r.to>=t?2:1}return 0}function yw(n,e,t,r,i,s){if(e<t){let l=n.buffer[e+1];r.push(n.slice(e,t,l)),i.push(l-s)}}function w_(n){let{node:e}=n,t=[],r=e.context.buffer;do t.push(n.index),n.parent();while(!n.tree);let i=n.tree,s=i.children.indexOf(r),l=i.children[s],o=l.buffer,u=[s];function h(f,p,g,x,k,b){let w=t[b],S=[],Q=[];yw(l,f,w,S,Q,x);let $=o[w+1],R=o[w+2];u.push(S.length);let I=b?h(w+4,o[w+3],l.set.types[o[w]],$,R-$,b-1):e.toTree();return S.push(I),Q.push($-x),yw(l,o[w+3],p,S,Q,x),new tt(g,S,Q,k)}i.children[s]=h(0,o.length,Dt.none,0,l.length,t.length-1);for(let f of u){let p=n.tree.children[f],g=n.tree.positions[f];n.yield(new gn(p,g+n.from,f,n._tree))}}class kw{constructor(e,t){this.offset=t,this.done=!1,this.cursor=e.cursor(nt.IncludeAnonymous|nt.IgnoreMounts)}moveTo(e){let{cursor:t}=this,r=e-this.offset;for(;!this.done&&t.from<r;)if(!(t.to>=e&&t.enter(r,1,nt.IgnoreOverlays|nt.ExcludeBuffers)))if(t.to<=e)t.next(!1)||(this.done=!0);else break}hasNode(e){if(this.moveTo(e.from),!this.done&&this.cursor.from+this.offset==e.from&&this.cursor.tree)for(let t=this.cursor.tree;;){if(t==e.tree)return!0;if(t.children.length&&t.positions[0]==0&&t.children[0]instanceof tt)t=t.children[0];else break}return!1}}let S_=class{constructor(e){var t;if(this.fragments=e,this.curTo=0,this.fragI=0,e.length){let r=this.curFrag=e[0];this.curTo=(t=r.tree.prop(Ax))!==null&&t!==void 0?t:r.to,this.inner=new kw(r.tree,-r.offset)}else this.curFrag=this.inner=null}hasNode(e){for(;this.curFrag&&e.from>=this.curTo;)this.nextFrag();return this.curFrag&&this.curFrag.from<=e.from&&this.curTo>=e.to&&this.inner.hasNode(e)}nextFrag(){var e;if(this.fragI++,this.fragI==this.fragments.length)this.curFrag=this.inner=null;else{let t=this.curFrag=this.fragments[this.fragI];this.curTo=(e=t.tree.prop(Ax))!==null&&e!==void 0?e:t.to,this.inner=new kw(t.tree,-t.offset)}}findMounts(e,t){var r;let i=[];if(this.inner){this.inner.cursor.moveTo(e,1);for(let s=this.inner.cursor.node;s;s=s.parent){let l=(r=s.tree)===null||r===void 0?void 0:r.prop(Le.mounted);if(l&&l.parser==t)for(let o=this.fragI;o<this.fragments.length;o++){let u=this.fragments[o];if(u.from>=s.to)break;u.tree==this.curFrag.tree&&i.push({frag:u,pos:s.from-u.offset,mount:l})}}}return i}};function vw(n,e){let t=null,r=e;for(let i=1,s=0;i<n.length;i++){let l=n[i-1].to,o=n[i].from;for(;s<r.length;s++){let u=r[s];if(u.from>=o)break;u.to<=l||(t||(r=t=e.slice()),u.from<l?(t[s]=new Pr(u.from,l),u.to>o&&t.splice(s+1,0,new Pr(o,u.to))):u.to>o?t[s--]=new Pr(o,u.to):t.splice(s--,1))}}return r}function P_(n,e,t,r){let i=0,s=0,l=!1,o=!1,u=-1e9,h=[];for(;;){let f=i==n.length?1e9:l?n[i].to:n[i].from,p=s==e.length?1e9:o?e[s].to:e[s].from;if(l!=o){let g=Math.max(u,t),x=Math.min(f,p,r);g<x&&h.push(new Pr(g,x))}if(u=Math.min(f,p),u==1e9)break;f==u&&(l?(l=!1,i++):l=!0),p==u&&(o?(o=!1,s++):o=!0)}return h}function bw(n,e){let t=[];for(let{pos:r,mount:i,frag:s}of n){let l=r+(i.overlay?i.overlay[0].from:0),o=l+i.tree.length,u=Math.max(s.from,l),h=Math.min(s.to,o);if(i.overlay){let f=i.overlay.map(g=>new Pr(g.from+r,g.to+r)),p=P_(e,f,u,h);for(let g=0,x=u;;g++){let k=g==p.length,b=k?h:p[g].from;if(b>x&&t.push(new Bi(x,b,i.tree,-l,s.from>=x||s.openStart,s.to<=b||s.openEnd)),k)break;x=p[g].to}}else t.push(new Bi(u,h,i.tree,-l,s.from>=l||s.openStart,s.to<=o||s.openEnd))}return t}let C_=0;class cr{constructor(e,t,r,i){this.name=e,this.set=t,this.base=r,this.modified=i,this.id=C_++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let r=typeof e=="string"?e:"?";if(e instanceof cr&&(t=e),t!=null&&t.base)throw new Error("Can not derive from a modified tag");let i=new cr(r,[],null,[]);if(i.set.push(i),t)for(let s of t.set)i.set.push(s);return i}static defineModifier(e){let t=new gd(e);return r=>r.modified.indexOf(t)>-1?r:gd.get(r.base||r,r.modified.concat(t).sort((i,s)=>i.id-s.id))}}let Q_=0;class gd{constructor(e){this.name=e,this.instances=[],this.id=Q_++}static get(e,t){if(!t.length)return e;let r=t[0].instances.find(o=>o.base==e&&$_(t,o.modified));if(r)return r;let i=[],s=new cr(e.name,i,e,t);for(let o of t)o.instances.push(s);let l=T_(t);for(let o of e.set)if(!o.modified.length)for(let u of l)i.push(gd.get(o,u));return s}}function $_(n,e){return n.length==e.length&&n.every((t,r)=>t==e[r])}function T_(n){let e=[[]];for(let t=0;t<n.length;t++)for(let r=0,i=e.length;r<i;r++)e.push(e[r].concat(n[t]));return e.sort((t,r)=>r.length-t.length)}function wa(n){let e=Object.create(null);for(let t in n){let r=n[t];Array.isArray(r)||(r=[r]);for(let i of t.split(" "))if(i){let s=[],l=2,o=i;for(let p=0;;){if(o=="..."&&p>0&&p+3==i.length){l=1;break}let g=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(o);if(!g)throw new RangeError("Invalid path: "+i);if(s.push(g[0]=="*"?"":g[0][0]=='"'?JSON.parse(g[0]):g[0]),p+=g[0].length,p==i.length)break;let x=i[p++];if(p==i.length&&x=="!"){l=0;break}if(x!="/")throw new RangeError("Invalid path: "+i);o=i.slice(p)}let u=s.length-1,h=s[u];if(!h)throw new RangeError("Invalid path: "+i);let f=new lc(r,l,u>0?s.slice(0,u):null);e[h]=f.sort(e[h])}}return SQ.add(e)}const SQ=new Le({combine(n,e){let t,r,i;for(;n||e;){if(!n||e&&n.depth>=e.depth?(i=e,e=e.next):(i=n,n=n.next),t&&t.mode==i.mode&&!i.context&&!t.context)continue;let s=new lc(i.tags,i.mode,i.context);t?t.next=s:r=s,t=s}return r}});class lc{constructor(e,t,r,i){this.tags=e,this.mode=t,this.context=r,this.next=i}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}}lc.empty=new lc([],2,null);function PQ(n,e){let t=Object.create(null);for(let s of n)if(!Array.isArray(s.tag))t[s.tag.id]=s.class;else for(let l of s.tag)t[l.id]=s.class;let{scope:r,all:i=null}=e||{};return{style:s=>{let l=i;for(let o of s)for(let u of o.set){let h=t[u.id];if(h){l=l?l+" "+h:h;break}}return l},scope:r}}function j_(n,e){let t=null;for(let r of n){let i=r.style(e);i&&(t=t?t+" "+i:i)}return t}function E_(n,e,t,r=0,i=n.length){let s=new M_(r,Array.isArray(e)?e:[e],t);s.highlightRange(n.cursor(),r,i,"",s.highlighters),s.flush(i)}class M_{constructor(e,t,r){this.at=e,this.highlighters=t,this.span=r,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,r,i,s){let{type:l,from:o,to:u}=e;if(o>=r||u<=t)return;l.isTop&&(s=this.highlighters.filter(x=>!x.scope||x.scope(l)));let h=i,f=A_(e)||lc.empty,p=j_(s,f.tags);if(p&&(h&&(h+=" "),h+=p,f.mode==1&&(i+=(i?" ":"")+p)),this.startSpan(Math.max(t,o),h),f.opaque)return;let g=e.tree&&e.tree.prop(Le.mounted);if(g&&g.overlay){let x=e.node.enter(g.overlay[0].from+o,1),k=this.highlighters.filter(w=>!w.scope||w.scope(g.tree.type)),b=e.firstChild();for(let w=0,S=o;;w++){let Q=w<g.overlay.length?g.overlay[w]:null,$=Q?Q.from+o:u,R=Math.max(t,S),I=Math.min(r,$);if(R<I&&b)for(;e.from<I&&(this.highlightRange(e,R,I,i,s),this.startSpan(Math.min(I,e.to),h),!(e.to>=$||!e.nextSibling())););if(!Q||$>r)break;S=Q.to+o,S>t&&(this.highlightRange(x.cursor(),Math.max(t,Q.from+o),Math.min(r,S),"",k),this.startSpan(Math.min(r,S),h))}b&&e.parent()}else if(e.firstChild()){g&&(i="");do if(!(e.to<=t)){if(e.from>=r)break;this.highlightRange(e,t,r,i,s),this.startSpan(Math.min(r,e.to),h)}while(e.nextSibling());e.parent()}}}function A_(n){let e=n.type.prop(SQ);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}const fe=cr.define,bf=fe(),Ps=fe(),ww=fe(Ps),Sw=fe(Ps),Cs=fe(),wf=fe(Cs),Mg=fe(Cs),si=fe(),ml=fe(si),ri=fe(),ii=fe(),Rx=fe(),xu=fe(Rx),Sf=fe(),j={comment:bf,lineComment:fe(bf),blockComment:fe(bf),docComment:fe(bf),name:Ps,variableName:fe(Ps),typeName:ww,tagName:fe(ww),propertyName:Sw,attributeName:fe(Sw),className:fe(Ps),labelName:fe(Ps),namespace:fe(Ps),macroName:fe(Ps),literal:Cs,string:wf,docString:fe(wf),character:fe(wf),attributeValue:fe(wf),number:Mg,integer:fe(Mg),float:fe(Mg),bool:fe(Cs),regexp:fe(Cs),escape:fe(Cs),color:fe(Cs),url:fe(Cs),keyword:ri,self:fe(ri),null:fe(ri),atom:fe(ri),unit:fe(ri),modifier:fe(ri),operatorKeyword:fe(ri),controlKeyword:fe(ri),definitionKeyword:fe(ri),moduleKeyword:fe(ri),operator:ii,derefOperator:fe(ii),arithmeticOperator:fe(ii),logicOperator:fe(ii),bitwiseOperator:fe(ii),compareOperator:fe(ii),updateOperator:fe(ii),definitionOperator:fe(ii),typeOperator:fe(ii),controlOperator:fe(ii),punctuation:Rx,separator:fe(Rx),bracket:xu,angleBracket:fe(xu),squareBracket:fe(xu),paren:fe(xu),brace:fe(xu),content:si,heading:ml,heading1:fe(ml),heading2:fe(ml),heading3:fe(ml),heading4:fe(ml),heading5:fe(ml),heading6:fe(ml),contentSeparator:fe(si),list:fe(si),quote:fe(si),emphasis:fe(si),strong:fe(si),link:fe(si),monospace:fe(si),strikethrough:fe(si),inserted:fe(),deleted:fe(),changed:fe(),invalid:fe(),meta:Sf,documentMeta:fe(Sf),annotation:fe(Sf),processingInstruction:fe(Sf),definition:cr.defineModifier("definition"),constant:cr.defineModifier("constant"),function:cr.defineModifier("function"),standard:cr.defineModifier("standard"),local:cr.defineModifier("local"),special:cr.defineModifier("special")};for(let n in j){let e=j[n];e instanceof cr&&(e.name=n)}PQ([{tag:j.link,class:"tok-link"},{tag:j.heading,class:"tok-heading"},{tag:j.emphasis,class:"tok-emphasis"},{tag:j.strong,class:"tok-strong"},{tag:j.keyword,class:"tok-keyword"},{tag:j.atom,class:"tok-atom"},{tag:j.bool,class:"tok-bool"},{tag:j.url,class:"tok-url"},{tag:j.labelName,class:"tok-labelName"},{tag:j.inserted,class:"tok-inserted"},{tag:j.deleted,class:"tok-deleted"},{tag:j.literal,class:"tok-literal"},{tag:j.string,class:"tok-string"},{tag:j.number,class:"tok-number"},{tag:[j.regexp,j.escape,j.special(j.string)],class:"tok-string2"},{tag:j.variableName,class:"tok-variableName"},{tag:j.local(j.variableName),class:"tok-variableName tok-local"},{tag:j.definition(j.variableName),class:"tok-variableName tok-definition"},{tag:j.special(j.variableName),class:"tok-variableName2"},{tag:j.definition(j.propertyName),class:"tok-propertyName tok-definition"},{tag:j.typeName,class:"tok-typeName"},{tag:j.namespace,class:"tok-namespace"},{tag:j.className,class:"tok-className"},{tag:j.macroName,class:"tok-macroName"},{tag:j.propertyName,class:"tok-propertyName"},{tag:j.operator,class:"tok-operator"},{tag:j.comment,class:"tok-comment"},{tag:j.meta,class:"tok-meta"},{tag:j.invalid,class:"tok-invalid"},{tag:j.punctuation,class:"tok-punctuation"}]);var Ag;const Pl=new Le;function Ky(n){return ge.define({combine:n?e=>e.concat(n):void 0})}const Jy=new Le;class Cr{constructor(e,t,r=[],i=""){this.data=e,this.name=i,Fe.prototype.hasOwnProperty("tree")||Object.defineProperty(Fe.prototype,"tree",{get(){return dt(this)}}),this.parser=t,this.extension=[Fs.of(this),Fe.languageData.of((s,l,o)=>{let u=Pw(s,l,o),h=u.type.prop(Pl);if(!h)return[];let f=s.facet(h),p=u.type.prop(Jy);if(p){let g=u.resolve(l-u.from,o);for(let x of p)if(x.test(g,s)){let k=s.facet(x.facet);return x.type=="replace"?k:k.concat(f)}}return f})].concat(r)}isActiveAt(e,t,r=-1){return Pw(e,t,r).type.prop(Pl)==this.data}findRegions(e){let t=e.facet(Fs);if((t==null?void 0:t.data)==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let r=[],i=(s,l)=>{if(s.prop(Pl)==this.data){r.push({from:l,to:l+s.length});return}let o=s.prop(Le.mounted);if(o){if(o.tree.prop(Pl)==this.data){if(o.overlay)for(let u of o.overlay)r.push({from:u.from+l,to:u.to+l});else r.push({from:l,to:l+s.length});return}else if(o.overlay){let u=r.length;if(i(o.tree,o.overlay[0].from+l),r.length>u)return}}for(let u=0;u<s.children.length;u++){let h=s.children[u];h instanceof tt&&i(h,s.positions[u]+l)}};return i(dt(e),0),r}get allowsNesting(){return!0}}Cr.setState=Ne.define();function Pw(n,e,t){let r=n.facet(Fs),i=dt(n).topNode;if(!r||r.allowsNesting)for(let s=i;s;s=s.enter(e,t,nt.ExcludeBuffers|nt.EnterBracketed))s.type.isTop&&(i=s);return i}class aa extends Cr{constructor(e,t,r){super(e,t,[],r),this.parser=t}static define(e){let t=Ky(e.languageData);return new aa(t,e.parser.configure({props:[Pl.add(r=>r.isTop?t:void 0)]}),e.name)}configure(e,t){return new aa(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function dt(n){let e=n.field(Cr.state,!1);return e?e.tree:tt.empty}class R_{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 r=this.cursorPos-this.string.length;return e<r||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-r,t-r)}}let yu=null;class oc{constructor(e,t,r=[],i,s,l,o,u){this.parser=e,this.state=t,this.fragments=r,this.tree=i,this.treeLen=s,this.viewport=l,this.skipped=o,this.scheduleOn=u,this.parse=null,this.tempSkipped=[]}static create(e,t,r){return new oc(e,t,[],tt.empty,0,r,[],null)}startParse(){return this.parser.startParse(new R_(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=tt.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var r;if(typeof e=="number"){let i=Date.now()+e;e=()=>Date.now()>i}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 i=this.parse.advance();if(i)if(this.fragments=this.withoutTempSkipped(Bi.addTree(i,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(r=this.parse.stoppedAt)!==null&&r!==void 0?r:this.state.doc.length,this.tree=i,this.parse=null,this.treeLen<(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(Bi.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=yu;yu=this;try{return e()}finally{yu=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=Cw(e,t.from,t.to);return e}changes(e,t){let{fragments:r,tree:i,treeLen:s,viewport:l,skipped:o}=this;if(this.takeTree(),!e.empty){let u=[];if(e.iterChangedRanges((h,f,p,g)=>u.push({fromA:h,toA:f,fromB:p,toB:g})),r=Bi.applyChanges(r,u),i=tt.empty,s=0,l={from:e.mapPos(l.from,-1),to:e.mapPos(l.to,1)},this.skipped.length){o=[];for(let h of this.skipped){let f=e.mapPos(h.from,1),p=e.mapPos(h.to,-1);f<p&&o.push({from:f,to:p})}}}return new oc(this.parser,t,r,i,s,l,o,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 r=0;r<this.skipped.length;r++){let{from:i,to:s}=this.skipped[r];i<e.to&&s>e.from&&(this.fragments=Cw(this.fragments,i,s),this.skipped.splice(r--,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 Hy{createParse(t,r,i){let s=i[0].from,l=i[i.length-1].to;return{parsedPos:s,advance(){let u=yu;if(u){for(let h of i)u.tempSkipped.push(h);e&&(u.scheduleOn=u.scheduleOn?Promise.all([u.scheduleOn,e]):e)}return this.parsedPos=l,new tt(Dt.none,[],[],l-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 yu}}function Cw(n,e,t){return Bi.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class ua{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),r=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,r)||t.takeTree(),new ua(t)}static init(e){let t=Math.min(3e3,e.doc.length),r=oc.create(e.facet(Fs).parser,e,{from:0,to:t});return r.work(20,t)||r.takeTree(),new ua(r)}}Cr.state=an.define({create:ua.init,update(n,e){for(let t of e.effects)if(t.is(Cr.setState))return t.value;return e.startState.facet(Fs)!=e.state.facet(Fs)?ua.init(e.state):n.apply(e)}});let CQ=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(CQ=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const Rg=typeof navigator<"u"&&(!((Ag=navigator.scheduling)===null||Ag===void 0)&&Ag.isInputPending)?()=>navigator.scheduling.isInputPending():null,N_=Ct.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(Cr.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(Cr.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=CQ(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:r,viewport:{to:i}}=this.view,s=r.field(Cr.state);if(s.tree==s.context.tree&&s.context.isDone(i+1e5))return;let l=Date.now()+Math.min(this.chunkBudget,100,e&&!Rg?Math.max(25,e.timeRemaining()-5):1e9),o=s.context.treeLen<i&&r.doc.length>i+1e3,u=s.context.work(()=>Rg&&Rg()||Date.now()>l,i+(o?0:1e5));this.chunkBudget-=Date.now()-t,(u||this.chunkBudget<=0)&&(s.context.takeTree(),this.view.dispatch({effects:Cr.setState.of(new ua(s.context))})),this.chunkBudget>0&&!(u&&!o)&&this.scheduleWork(),this.checkAsyncSchedule(s.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>Xn(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()}}}),Fs=ge.define({combine(n){return n.length?n[0]:null},enables:n=>[Cr.state,N_,he.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class ac{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}class Od{constructor(e,t,r,i,s,l=void 0){this.name=e,this.alias=t,this.extensions=r,this.filename=i,this.loadFunc=s,this.support=l,this.loading=null}load(){return this.loading||(this.loading=this.loadFunc().then(e=>this.support=e,e=>{throw this.loading=null,e}))}static of(e){let{load:t,support:r}=e;if(!t){if(!r)throw new RangeError("Must pass either 'load' or 'support' to LanguageDescription.of");t=()=>Promise.resolve(r)}return new Od(e.name,(e.alias||[]).concat(e.name).map(i=>i.toLowerCase()),e.extensions||[],e.filename,t,r)}static matchFilename(e,t){for(let i of e)if(i.filename&&i.filename.test(t))return i;let r=/\.([^.]+)$/.exec(t);if(r){for(let i of e)if(i.extensions.indexOf(r[1])>-1)return i}return null}static matchLanguageName(e,t,r=!0){t=t.toLowerCase();for(let i of e)if(i.alias.some(s=>s==t))return i;if(r)for(let i of e)for(let s of i.alias){let l=t.indexOf(s);if(l>-1&&(s.length>2||!/\w/.test(t[l-1])&&!/\w/.test(t[l+s.length])))return i}return null}}const L_=ge.define(),Sa=ge.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function xd(n){let e=n.facet(Sa);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function uc(n,e){let t="",r=n.tabSize,i=n.facet(Sa)[0];if(i==" "){for(;e>=r;)t+=" ",e-=r;i=" "}for(let s=0;s<e;s++)t+=i;return t}function e0(n,e){n instanceof Fe&&(n=new sp(n));for(let r of n.state.facet(L_)){let i=r(n,e);if(i!==void 0)return i}let t=dt(n.state);return t.length>=e?__(n,t,e):null}class sp{constructor(e,t={}){this.state=e,this.options=t,this.unit=xd(e)}lineAt(e,t=1){let r=this.state.doc.lineAt(e),{simulateBreak:i,simulateDoubleBreak:s}=this.options;return i!=null&&i>=r.from&&i<=r.to?s&&i==e?{text:"",from:e}:(t<0?i<e:i<=e)?{text:r.text.slice(i-r.from),from:i}:{text:r.text.slice(0,i-r.from),from:r.from}:r}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:r,from:i}=this.lineAt(e,t);return r.slice(e-i,Math.min(r.length,e+100-i))}column(e,t=1){let{text:r,from:i}=this.lineAt(e,t),s=this.countColumn(r,e-i),l=this.options.overrideIndentation?this.options.overrideIndentation(i):-1;return l>-1&&(s+=l-this.countColumn(r,r.search(/\S|$/))),s}countColumn(e,t=e.length){return Wr(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:r,from:i}=this.lineAt(e,t),s=this.options.overrideIndentation;if(s){let l=s(i);if(l>-1)return l}return this.countColumn(r,r.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const _c=new Le;function __(n,e,t){let r=e.resolveStack(t),i=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(i!=r.node){let s=[];for(let l=i;l&&!(l.from<r.node.from||l.to>r.node.to||l.from==r.node.from&&l.type==r.node.type);l=l.parent)s.push(l);for(let l=s.length-1;l>=0;l--)r={node:s[l],next:r}}return QQ(r,n,t)}function QQ(n,e,t){for(let r=n;r;r=r.next){let i=I_(r.node);if(i)return i(t0.create(e,t,r))}return 0}function D_(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function I_(n){let e=n.type.prop(_c);if(e)return e;let t=n.firstChild,r;if(t&&(r=t.type.prop(Le.closedBy))){let i=n.lastChild,s=i&&r.indexOf(i.name)>-1;return l=>$Q(l,!0,1,void 0,s&&!D_(l)?i.from:void 0)}return n.parent==null?z_:null}function z_(){return 0}class t0 extends sp{constructor(e,t,r){super(e.state,e.options),this.base=e,this.pos=t,this.context=r}get node(){return this.context.node}static create(e,t,r){return new t0(e,t,r)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let r=e.resolve(t.from);for(;r.parent&&r.parent.from==r.from;)r=r.parent;if(Z_(r,e))break;t=this.state.doc.lineAt(r.from)}return this.lineIndent(t.from)}continue(){return QQ(this.context.next,this.base,this.pos)}}function Z_(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function X_(n){let e=n.node,t=e.childAfter(e.from),r=e.lastChild;if(!t)return null;let i=n.options.simulateBreak,s=n.state.doc.lineAt(t.from),l=i==null||i<=s.from?s.to:Math.min(s.to,i);for(let o=t.to;;){let u=e.childAfter(o);if(!u||u==r)return null;if(!u.type.isSkipped){if(u.from>=l)return null;let h=/^ */.exec(s.text.slice(t.to-s.from))[0].length;return{from:t.from,to:t.to+h}}o=u.to}}function B_({closing:n,align:e=!0,units:t=1}){return r=>$Q(r,e,t,n)}function $Q(n,e,t,r,i){let s=n.textAfter,l=s.match(/^\s*/)[0].length,o=r&&s.slice(l,l+r.length)==r||i==n.pos+l,u=e?X_(n):null;return u?o?n.column(u.from):n.column(u.to):n.baseIndent+(o?0:n.unit*t)}const W_=n=>n.baseIndent;function Vf({except:n,units:e=1}={}){return t=>{let r=n&&n.test(t.textAfter);return t.baseIndent+(r?0:e*t.unit)}}const q_=200;function V_(){return Fe.transactionFilter.of(n=>{if(!n.docChanged||!n.isUserEvent("input.type")&&!n.isUserEvent("input.complete"))return n;let e=n.startState.languageDataAt("indentOnInput",n.startState.selection.main.head);if(!e.length)return n;let t=n.newDoc,{head:r}=n.newSelection.main,i=t.lineAt(r);if(r>i.from+q_)return n;let s=t.sliceString(i.from,r);if(!e.some(h=>h.test(s)))return n;let{state:l}=n,o=-1,u=[];for(let{head:h}of l.selection.ranges){let f=l.doc.lineAt(h);if(f.from==o)continue;o=f.from;let p=e0(l,f.from);if(p==null)continue;let g=/^\s*/.exec(f.text)[0],x=uc(l,p);g!=x&&u.push({from:f.from,to:f.from+g.length,insert:x})}return u.length?[n,{changes:u,sequential:!0}]:n})}const TQ=ge.define(),Pa=new Le;function jQ(n){let e=n.firstChild,t=n.lastChild;return e&&e.to<t.from?{from:e.to,to:t.type.isError?n.to:t.from}:null}function F_(n,e,t){let r=dt(n);if(r.length<t)return null;let i=r.resolveStack(t,1),s=null;for(let l=i;l;l=l.next){let o=l.node;if(o.to<=t||o.from>t)continue;if(s&&o.from<e)break;let u=o.type.prop(Pa);if(u&&(o.to<r.length-50||r.length==n.doc.length||!Y_(o))){let h=u(o,n);h&&h.from<=t&&h.from>=e&&h.to>t&&(s=h)}}return s}function Y_(n){let e=n.lastChild;return e&&e.to==n.to&&e.type.isError}function yd(n,e,t){for(let r of n.facet(TQ)){let i=r(n,e,t);if(i)return i}return F_(n,e,t)}function EQ(n,e){let t=e.mapPos(n.from,1),r=e.mapPos(n.to,-1);return t>=r?void 0:{from:t,to:r}}const lp=Ne.define({map:EQ}),Dc=Ne.define({map:EQ});function MQ(n){let e=[];for(let{head:t}of n.state.selection.ranges)e.some(r=>r.from<=t&&r.to>=t)||e.push(n.lineBlockAt(t));return e}const Bl=an.define({create(){return $e.none},update(n,e){e.isUserEvent("delete")&&e.changes.iterChangedRanges((t,r)=>n=Qw(n,t,r)),n=n.map(e.changes);for(let t of e.effects)if(t.is(lp)&&!U_(n,t.value.from,t.value.to)){let{preparePlaceholder:r}=e.state.facet(NQ),i=r?$e.replace({widget:new n4(r(e.state,t.value))}):$w;n=n.update({add:[i.range(t.value.from,t.value.to)]})}else t.is(Dc)&&(n=n.update({filter:(r,i)=>t.value.from!=r||t.value.to!=i,filterFrom:t.value.from,filterTo:t.value.to}));return e.selection&&(n=Qw(n,e.selection.main.head)),n},provide:n=>he.decorations.from(n),toJSON(n,e){let t=[];return n.between(0,e.doc.length,(r,i)=>{t.push(r,i)}),t},fromJSON(n){if(!Array.isArray(n)||n.length%2)throw new RangeError("Invalid JSON for fold state");let e=[];for(let t=0;t<n.length;){let r=n[t++],i=n[t++];if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid JSON for fold state");e.push($w.range(r,i))}return $e.set(e,!0)}});function Qw(n,e,t=e){let r=!1;return n.between(e,t,(i,s)=>{i<t&&s>e&&(r=!0)}),r?n.update({filterFrom:e,filterTo:t,filter:(i,s)=>i>=t||s<=e}):n}function kd(n,e,t){var r;let i=null;return(r=n.field(Bl,!1))===null||r===void 0||r.between(e,t,(s,l)=>{(!i||i.from>s)&&(i={from:s,to:l})}),i}function U_(n,e,t){let r=!1;return n.between(e,e,(i,s)=>{i==e&&s==t&&(r=!0)}),r}function AQ(n,e){return n.field(Bl,!1)?e:e.concat(Ne.appendConfig.of(LQ()))}const G_=n=>{for(let e of MQ(n)){let t=yd(n.state,e.from,e.to);if(t)return n.dispatch({effects:AQ(n.state,[lp.of(t),RQ(n,t)])}),!0}return!1},H_=n=>{if(!n.state.field(Bl,!1))return!1;let e=[];for(let t of MQ(n)){let r=kd(n.state,t.from,t.to);r&&e.push(Dc.of(r),RQ(n,r,!1))}return e.length&&n.dispatch({effects:e}),e.length>0};function RQ(n,e,t=!0){let r=n.state.doc.lineAt(e.from).number,i=n.state.doc.lineAt(e.to).number;return he.announce.of(`${n.state.phrase(t?"Folded lines":"Unfolded lines")} ${r} ${n.state.phrase("to")} ${i}.`)}const K_=n=>{let{state:e}=n,t=[];for(let r=0;r<e.doc.length;){let i=n.lineBlockAt(r),s=yd(e,i.from,i.to);s&&t.push(lp.of(s)),r=(s?n.lineBlockAt(s.to):i).to+1}return t.length&&n.dispatch({effects:AQ(n.state,t)}),!!t.length},J_=n=>{let e=n.state.field(Bl,!1);if(!e||!e.size)return!1;let t=[];return e.between(0,n.state.doc.length,(r,i)=>{t.push(Dc.of({from:r,to:i}))}),n.dispatch({effects:t}),!0},e4=[{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:G_},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:H_},{key:"Ctrl-Alt-[",run:K_},{key:"Ctrl-Alt-]",run:J_}],t4={placeholderDOM:null,preparePlaceholder:null,placeholderText:"…"},NQ=ge.define({combine(n){return bi(n,t4)}});function LQ(n){return[Bl,s4]}function _Q(n,e){let{state:t}=n,r=t.facet(NQ),i=l=>{let o=n.lineBlockAt(n.posAtDOM(l.target)),u=kd(n.state,o.from,o.to);u&&n.dispatch({effects:Dc.of(u)}),l.preventDefault()};if(r.placeholderDOM)return r.placeholderDOM(n,i,e);let s=document.createElement("span");return s.textContent=r.placeholderText,s.setAttribute("aria-label",t.phrase("folded code")),s.title=t.phrase("unfold"),s.className="cm-foldPlaceholder",s.onclick=i,s}const $w=$e.replace({widget:new class extends Vr{toDOM(n){return _Q(n,null)}}});class n4 extends Vr{constructor(e){super(),this.value=e}eq(e){return this.value==e.value}toDOM(e){return _Q(e,this.value)}}const r4={openText:"⌄",closedText:"›",markerDOM:null,domEventHandlers:{},foldingChanged:()=>!1};class Ng extends Fi{constructor(e,t){super(),this.config=e,this.open=t}eq(e){return this.config==e.config&&this.open==e.open}toDOM(e){if(this.config.markerDOM)return this.config.markerDOM(this.open);let t=document.createElement("span");return t.textContent=this.open?this.config.openText:this.config.closedText,t.title=e.state.phrase(this.open?"Fold line":"Unfold line"),t}}function i4(n={}){let e={...r4,...n},t=new Ng(e,!0),r=new Ng(e,!1),i=Ct.fromClass(class{constructor(l){this.from=l.viewport.from,this.markers=this.buildMarkers(l)}update(l){(l.docChanged||l.viewportChanged||l.startState.facet(Fs)!=l.state.facet(Fs)||l.startState.field(Bl,!1)!=l.state.field(Bl,!1)||dt(l.startState)!=dt(l.state)||e.foldingChanged(l))&&(this.markers=this.buildMarkers(l.view))}buildMarkers(l){let o=new qi;for(let u of l.viewportLineBlocks){let h=kd(l.state,u.from,u.to)?r:yd(l.state,u.from,u.to)?t:null;h&&o.add(u.from,u.from,h)}return o.finish()}}),{domEventHandlers:s}=e;return[i,n_({class:"cm-foldGutter",markers(l){var o;return((o=l.plugin(i))===null||o===void 0?void 0:o.markers)||We.empty},initialSpacer(){return new Ng(e,!1)},domEventHandlers:{...s,click:(l,o,u)=>{if(s.click&&s.click(l,o,u))return!0;let h=kd(l.state,o.from,o.to);if(h)return l.dispatch({effects:Dc.of(h)}),!0;let f=yd(l.state,o.from,o.to);return f?(l.dispatch({effects:lp.of(f)}),!0):!1}}}),LQ()]}const s4=he.baseTheme({".cm-foldPlaceholder":{backgroundColor:"#eee",border:"1px solid #ddd",color:"#888",borderRadius:".2em",margin:"0 1px",padding:"0 1px",cursor:"pointer"},".cm-foldGutter span":{padding:"0 1px",cursor:"pointer"}});class Ic{constructor(e,t){this.specs=e;let r;function i(o){let u=Bs.newName();return(r||(r=Object.create(null)))["."+u]=o,u}const s=typeof t.all=="string"?t.all:t.all?i(t.all):void 0,l=t.scope;this.scope=l instanceof Cr?o=>o.prop(Pl)==l.data:l?o=>o==l:void 0,this.style=PQ(e.map(o=>({tag:o.tag,class:o.class||i(Object.assign({},o,{tag:null}))})),{all:s}).style,this.module=r?new Bs(r):null,this.themeType=t.themeType}static define(e,t){return new Ic(e,t||{})}}const Nx=ge.define(),DQ=ge.define({combine(n){return n.length?[n[0]]:null}});function Lg(n){let e=n.facet(Nx);return e.length?e:n.facet(DQ)}function IQ(n,e){let t=[o4],r;return n instanceof Ic&&(n.module&&t.push(he.styleModule.of(n.module)),r=n.themeType),e!=null&&e.fallback?t.push(DQ.of(n)):r?t.push(Nx.computeN([he.darkTheme],i=>i.facet(he.darkTheme)==(r=="dark")?[n]:[])):t.push(Nx.of(n)),t}class l4{constructor(e){this.markCache=Object.create(null),this.tree=dt(e.state),this.decorations=this.buildDeco(e,Lg(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=dt(e.state),r=Lg(e.state),i=r!=Lg(e.startState),{viewport:s}=e.view,l=e.changes.mapPos(this.decoratedTo,1);t.length<s.to&&!i&&t.type==this.tree.type&&l>=s.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=l):(t!=this.tree||e.viewportChanged||i)&&(this.tree=t,this.decorations=this.buildDeco(e.view,r),this.decoratedTo=s.to)}buildDeco(e,t){if(!t||!this.tree.length)return $e.none;let r=new qi;for(let{from:i,to:s}of e.visibleRanges)E_(this.tree,t,(l,o,u)=>{r.add(l,o,this.markCache[u]||(this.markCache[u]=$e.mark({class:u})))},i,s);return r.finish()}}const o4=Ui.high(Ct.fromClass(l4,{decorations:n=>n.decorations})),a4=Ic.define([{tag:j.meta,color:"#404740"},{tag:j.link,textDecoration:"underline"},{tag:j.heading,textDecoration:"underline",fontWeight:"bold"},{tag:j.emphasis,fontStyle:"italic"},{tag:j.strong,fontWeight:"bold"},{tag:j.strikethrough,textDecoration:"line-through"},{tag:j.keyword,color:"#708"},{tag:[j.atom,j.bool,j.url,j.contentSeparator,j.labelName],color:"#219"},{tag:[j.literal,j.inserted],color:"#164"},{tag:[j.string,j.deleted],color:"#a11"},{tag:[j.regexp,j.escape,j.special(j.string)],color:"#e40"},{tag:j.definition(j.variableName),color:"#00f"},{tag:j.local(j.variableName),color:"#30a"},{tag:[j.typeName,j.namespace],color:"#085"},{tag:j.className,color:"#167"},{tag:[j.special(j.variableName),j.macroName],color:"#256"},{tag:j.definition(j.propertyName),color:"#00c"},{tag:j.comment,color:"#940"},{tag:j.invalid,color:"#f00"}]),u4=he.baseTheme({"&.cm-focused .cm-matchingBracket":{backgroundColor:"#328c8252"},"&.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bb555544"}}),zQ=1e4,ZQ="()[]{}",XQ=ge.define({combine(n){return bi(n,{afterCursor:!0,brackets:ZQ,maxScanDistance:zQ,renderMatch:f4})}}),c4=$e.mark({class:"cm-matchingBracket"}),h4=$e.mark({class:"cm-nonmatchingBracket"});function f4(n){let e=[],t=n.matched?c4:h4;return e.push(t.range(n.start.from,n.start.to)),n.end&&e.push(t.range(n.end.from,n.end.to)),e}function Tw(n){let e=[],t=n.facet(XQ);for(let r of n.selection.ranges){if(!r.empty)continue;let i=mi(n,r.head,-1,t)||r.head>0&&mi(n,r.head-1,1,t)||t.afterCursor&&(mi(n,r.head,1,t)||r.head<n.doc.length&&mi(n,r.head+1,-1,t));i&&(e=e.concat(t.renderMatch(i,n)))}return $e.set(e,!0)}const d4=Ct.fromClass(class{constructor(n){this.paused=!1,this.decorations=Tw(n.state)}update(n){(n.docChanged||n.selectionSet||this.paused)&&(n.view.composing?(this.decorations=this.decorations.map(n.changes),this.paused=!0):(this.decorations=Tw(n.state),this.paused=!1))}},{decorations:n=>n.decorations}),p4=[d4,u4];function m4(n={}){return[XQ.of(n),p4]}const BQ=new Le;function Lx(n,e,t){let r=n.prop(e<0?Le.openedBy:Le.closedBy);if(r)return r;if(n.name.length==1){let i=t.indexOf(n.name);if(i>-1&&i%2==(e<0?1:0))return[t[i+e]]}return null}function _x(n){let e=n.type.prop(BQ);return e?e(n.node):n}function mi(n,e,t,r={}){let i=r.maxScanDistance||zQ,s=r.brackets||ZQ,l=dt(n),o=l.resolveInner(e,t);for(let u=o;u;u=u.parent){let h=Lx(u.type,t,s);if(h&&u.from<u.to){let f=_x(u);if(f&&(t>0?e>=f.from&&e<f.to:e>f.from&&e<=f.to))return g4(n,e,t,u,f,h,s)}}return O4(n,e,t,l,o.type,i,s)}function g4(n,e,t,r,i,s,l){let o=r.parent,u={from:i.from,to:i.to},h=0,f=o==null?void 0:o.cursor();if(f&&(t<0?f.childBefore(r.from):f.childAfter(r.to)))do if(t<0?f.to<=r.from:f.from>=r.to){if(h==0&&s.indexOf(f.type.name)>-1&&f.from<f.to){let p=_x(f);return{start:u,end:p?{from:p.from,to:p.to}:void 0,matched:!0}}else if(Lx(f.type,t,l))h++;else if(Lx(f.type,-t,l)){if(h==0){let p=_x(f);return{start:u,end:p&&p.from<p.to?{from:p.from,to:p.to}:void 0,matched:!1}}h--}}while(t<0?f.prevSibling():f.nextSibling());return{start:u,matched:!1}}function O4(n,e,t,r,i,s,l){if(t<0?!e:e==n.doc.length)return null;let o=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),u=l.indexOf(o);if(u<0||u%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},f=n.doc.iterRange(e,t>0?n.doc.length:0),p=0;for(let g=0;!f.next().done&&g<=s;){let x=f.value;t<0&&(g+=x.length);let k=e+g*t;for(let b=t>0?0:x.length-1,w=t>0?x.length:-1;b!=w;b+=t){let S=l.indexOf(x[b]);if(!(S<0||r.resolveInner(k+b,1).type!=i))if(S%2==0==t>0)p++;else{if(p==1)return{start:h,end:{from:k+b,to:k+b+1},matched:S>>1==u>>1};p--}}t>0&&(g+=x.length)}return f.done?{start:h,matched:!1}:null}const x4=Object.create(null),jw=[Dt.none],Ew=[],Mw=Object.create(null),y4=Object.create(null);for(let[n,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"]])y4[n]=k4(x4,e);function _g(n,e){Ew.indexOf(n)>-1||(Ew.push(n),console.warn(e))}function k4(n,e){let t=[];for(let o of e.split(" ")){let u=[];for(let h of o.split(".")){let f=n[h]||j[h];f?typeof f=="function"?u.length?u=u.map(f):_g(h,`Modifier ${h} used at start of tag`):u.length?_g(h,`Tag ${h} used as modifier`):u=Array.isArray(f)?f:[f]:_g(h,`Unknown highlighting tag ${h}`)}for(let h of u)t.push(h)}if(!t.length)return 0;let r=e.replace(/ /g,"_"),i=r+" "+t.map(o=>o.id),s=Mw[i];if(s)return s.id;let l=Mw[i]=Dt.define({id:jw.length,name:r,props:[wa({[r]:t})]});return jw.push(l),l.id}ht.RTL,ht.LTR;class n0{constructor(e,t,r,i){this.state=e,this.pos=t,this.explicit=r,this.view=i,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=dt(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),r=Math.max(t.from,this.pos-250),i=t.text.slice(r-t.from,this.pos-t.from),s=i.search(qQ(e,!1));return s<0?null:{from:r+s,to:this.pos,text:i.slice(s)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,r){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),r&&r.onDocChange&&(this.abortOnDocChange=!0))}}function Aw(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function v4(n){let e=Object.create(null),t=Object.create(null);for(let{label:i}of n){e[i[0]]=!0;for(let s=1;s<i.length;s++)t[i[s]]=!0}let r=Aw(e)+Aw(t)+"*$";return[new RegExp("^"+r),new RegExp(r)]}function WQ(n){let e=n.map(i=>typeof i=="string"?{label:i}:i),[t,r]=e.every(i=>/^\w+$/.test(i.label))?[/\w*$/,/\w+$/]:v4(e);return i=>{let s=i.matchBefore(r);return s||i.explicit?{from:s?s.from:i.pos,options:e,validFor:t}:null}}function b4(n,e){return t=>{for(let r=dt(t.state).resolveInner(t.pos,-1);r;r=r.parent){if(n.indexOf(r.name)>-1)return null;if(r.type.isTop)break}return e(t)}}class Rw{constructor(e,t,r,i){this.completion=e,this.source=t,this.match=r,this.score=i}}function _l(n){return n.selection.main.from}function qQ(n,e){var t;let{source:r}=n,i=e&&r[0]!="^",s=r[r.length-1]!="$";return!i&&!s?n:new RegExp(`${i?"^":""}(?:${r})${s?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const r0=vi.define();function w4(n,e,t,r){let{main:i}=n.selection,s=t-i.from,l=r-i.from;return{...n.changeByRange(o=>{if(o!=i&&t!=r&&n.sliceDoc(o.from+s,o.from+l)!=n.sliceDoc(t,r))return{range:o};let u=n.toText(e);return{changes:{from:o.from+s,to:r==i.from?o.to:o.from+l,insert:u},range:Y.cursor(o.from+s+u.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const Nw=new WeakMap;function S4(n){if(!Array.isArray(n))return n;let e=Nw.get(n);return e||Nw.set(n,e=WQ(n)),e}const vd=Ne.define(),cc=Ne.define();class P4{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let r=In(e,t),i=hi(r);this.chars.push(r);let s=e.slice(t,t+i),l=s.toUpperCase();this.folded.push(In(l==s?s.toLowerCase():l,0)),t+=i}this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:r,any:i,precise:s,byWord:l}=this;if(t.length==1){let Q=In(e,0),$=hi(Q),R=$==e.length?0:-100;if(Q!=t[0])if(Q==r[0])R+=-200;else return null;return this.ret(R,[0,$])}let o=e.indexOf(this.pattern);if(o==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let u=t.length,h=0;if(o<0){for(let Q=0,$=Math.min(e.length,200);Q<$&&h<u;){let R=In(e,Q);(R==t[h]||R==r[h])&&(i[h++]=Q),Q+=hi(R)}if(h<u)return null}let f=0,p=0,g=!1,x=0,k=-1,b=-1,w=/[a-z]/.test(e),S=!0;for(let Q=0,$=Math.min(e.length,200),R=0;Q<$&&p<u;){let I=In(e,Q);o<0&&(f<u&&I==t[f]&&(s[f++]=Q),x<u&&(I==t[x]||I==r[x]?(x==0&&(k=Q),b=Q+1,x++):x=0));let T,X=I<255?I>=48&&I<=57||I>=97&&I<=122?2:I>=65&&I<=90?1:0:(T=Ty(I))!=T.toLowerCase()?1:T!=T.toUpperCase()?2:0;(!Q||X==1&&w||R==0&&X!=0)&&(t[p]==I||r[p]==I&&(g=!0)?l[p++]=Q:l.length&&(S=!1)),R=X,Q+=hi(I)}return p==u&&l[0]==0&&S?this.result(-100+(g?-200:0),l,e):x==u&&k==0?this.ret(-200-e.length+(b==e.length?0:-100),[0,b]):o>-1?this.ret(-700-e.length,[o,o+this.pattern.length]):x==u?this.ret(-900-e.length,[k,b]):p==u?this.result(-100+(g?-200:0)+-700+(S?0:-1100),l,e):t.length==2?null:this.result((i[0]?-700:0)+-200+-1100,i,e)}result(e,t,r){let i=[],s=0;for(let l of t){let o=l+(this.astral?hi(In(r,l)):1);s&&i[s-1]==l?i[s-1]=o:(i[s++]=l,i[s++]=o)}return this.ret(e-r.length,i)}}class C4{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),r=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return r==null?null:(this.matched=[0,t.length],this.score=r+(e.length==this.pattern.length?0:-100),this)}}const Yt=ge.define({combine(n){return bi(n,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Q4,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>r=>Lw(e(r),t(r)),optionClass:(e,t)=>r=>Lw(e(r),t(r)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function Lw(n,e){return n?e?n+" "+e:n:e}function Q4(n,e,t,r,i,s){let l=n.textDirection==ht.RTL,o=l,u=!1,h="top",f,p,g=e.left-i.left,x=i.right-e.right,k=r.right-r.left,b=r.bottom-r.top;if(o&&g<Math.min(k,x)?o=!1:!o&&x<Math.min(k,g)&&(o=!0),k<=(o?g:x))f=Math.max(i.top,Math.min(t.top,i.bottom-b))-e.top,p=Math.min(400,o?g:x);else{u=!0,p=Math.min(400,(l?e.right:i.right-e.left)-30);let Q=i.bottom-e.bottom;Q>=b||Q>e.top?f=t.bottom-e.top:(h="bottom",f=e.bottom-t.top)}let w=(e.bottom-e.top)/s.offsetHeight,S=(e.right-e.left)/s.offsetWidth;return{style:`${h}: ${f/w}px; max-width: ${p/S}px`,class:"cm-completionInfo-"+(u?l?"left-narrow":"right-narrow":o?"left":"right")}}const i0=Ne.define();function $4(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let r=document.createElement("div");return r.classList.add("cm-completionIcon"),t.type&&r.classList.add(...t.type.split(/\s+/g).map(i=>"cm-completionIcon-"+i)),r.setAttribute("aria-hidden","true"),r},position:20}),e.push({render(t,r,i,s){let l=document.createElement("span");l.className="cm-completionLabel";let o=t.displayLabel||t.label,u=0;for(let h=0;h<s.length;){let f=s[h++],p=s[h++];f>u&&l.appendChild(document.createTextNode(o.slice(u,f)));let g=l.appendChild(document.createElement("span"));g.appendChild(document.createTextNode(o.slice(f,p))),g.className="cm-completionMatchedText",u=p}return u<o.length&&l.appendChild(document.createTextNode(o.slice(u))),l},position:50},{render(t){if(!t.detail)return null;let r=document.createElement("span");return r.className="cm-completionDetail",r.textContent=t.detail,r},position:80}),e.sort((t,r)=>t.position-r.position).map(t=>t.render)}function Dg(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let i=Math.floor(e/t);return{from:i*t,to:(i+1)*t}}let r=Math.ceil((n-e)/t);return{from:n-r*t,to:n-(r-1)*t}}class T4{constructor(e,t,r){this.view=e,this.stateField=t,this.applyCompletion=r,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:u=>this.placeInfo(u),key:this},this.space=null,this.currentClass="";let i=e.state.field(t),{options:s,selected:l}=i.open,o=e.state.facet(Yt);this.optionContent=$4(o),this.optionClass=o.optionClass,this.tooltipClass=o.tooltipClass,this.range=Dg(s.length,l,o.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",u=>{let{options:h}=e.state.field(t).open;for(let f=u.target,p;f&&f!=this.dom;f=f.parentNode)if(f.nodeName=="LI"&&(p=/-(\d+)$/.exec(f.id))&&+p[1]<h.length){this.applyCompletion(e,h[+p[1]]),u.preventDefault();return}if(u.target==this.list){let f=this.list.classList.contains("cm-completionListIncompleteTop")&&u.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&u.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;f!=null&&(e.dispatch({effects:i0.of(f)}),u.preventDefault())}}),this.dom.addEventListener("focusout",u=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(Yt).closeOnBlur&&u.relatedTarget!=e.contentDOM&&e.dispatch({effects:cc.of(null)})}),this.showOptions(s,i.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let r=e.state.field(this.stateField),i=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),r!=i){let{options:s,selected:l,disabled:o}=r.open;(!i.open||i.open.options!=s)&&(this.range=Dg(s.length,l,e.state.facet(Yt).maxRenderedOptions),this.showOptions(s,r.id)),this.updateSel(),o!=((t=i.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!o)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let r of this.currentClass.split(" "))r&&this.dom.classList.remove(r);for(let r of t.split(" "))r&&this.dom.classList.add(r);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=Dg(t.options.length,t.selected,this.view.state.facet(Yt).maxRenderedOptions),this.showOptions(t.options,e.id));let r=this.updateSelectedOption(t.selected);if(r){this.destroyInfo();let{completion:i}=t.options[t.selected],{info:s}=i;if(!s)return;let l=typeof s=="string"?document.createTextNode(s):s(i);if(!l)return;"then"in l?l.then(o=>{o&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(o,i)}).catch(o=>Xn(this.view.state,o,"completion info")):(this.addInfoPane(l,i),r.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let r=this.info=document.createElement("div");if(r.className="cm-tooltip cm-completionInfo",r.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)r.appendChild(e),this.infoDestroy=null;else{let{dom:i,destroy:s}=e;r.appendChild(i),this.infoDestroy=s||null}this.dom.appendChild(r),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let r=this.list.firstChild,i=this.range.from;r;r=r.nextSibling,i++)r.nodeName!="LI"||!r.id?i--:i==e?r.hasAttribute("aria-selected")||(r.setAttribute("aria-selected","true"),t=r):r.hasAttribute("aria-selected")&&(r.removeAttribute("aria-selected"),r.removeAttribute("aria-describedby"));return t&&E4(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),r=this.info.getBoundingClientRect(),i=e.getBoundingClientRect(),s=this.space;if(!s){let l=this.dom.ownerDocument.documentElement;s={left:0,top:0,right:l.clientWidth,bottom:l.clientHeight}}return i.top>Math.min(s.bottom,t.bottom)-10||i.bottom<Math.max(s.top,t.top)+10?null:this.view.state.facet(Yt).positionInfo(this.view,t,i,r,s,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,r){const i=document.createElement("ul");i.id=t,i.setAttribute("role","listbox"),i.setAttribute("aria-expanded","true"),i.setAttribute("aria-label",this.view.state.phrase("Completions")),i.addEventListener("mousedown",l=>{l.target==i&&l.preventDefault()});let s=null;for(let l=r.from;l<r.to;l++){let{completion:o,match:u}=e[l],{section:h}=o;if(h){let g=typeof h=="string"?h:h.name;if(g!=s&&(l>r.from||r.from==0))if(s=g,typeof h!="string"&&h.header)i.appendChild(h.header(h));else{let x=i.appendChild(document.createElement("completion-section"));x.textContent=g}}const f=i.appendChild(document.createElement("li"));f.id=t+"-"+l,f.setAttribute("role","option");let p=this.optionClass(o);p&&(f.className=p);for(let g of this.optionContent){let x=g(o,this.view.state,this.view,u);x&&f.appendChild(x)}}return r.from&&i.classList.add("cm-completionListIncompleteTop"),r.to<e.length&&i.classList.add("cm-completionListIncompleteBottom"),i}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function j4(n,e){return t=>new T4(t,n,e)}function E4(n,e){let t=n.getBoundingClientRect(),r=e.getBoundingClientRect(),i=t.height/n.offsetHeight;r.top<t.top?n.scrollTop-=(t.top-r.top)/i:r.bottom>t.bottom&&(n.scrollTop+=(r.bottom-t.bottom)/i)}function _w(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function M4(n,e){let t=[],r=null,i=null,s=f=>{t.push(f);let{section:p}=f.completion;if(p){r||(r=[]);let g=typeof p=="string"?p:p.name;r.some(x=>x.name==g)||r.push(typeof p=="string"?{name:g}:p)}},l=e.facet(Yt);for(let f of n)if(f.hasResult()){let p=f.result.getMatch;if(f.result.filter===!1)for(let g of f.result.options)s(new Rw(g,f.source,p?p(g):[],1e9-t.length));else{let g=e.sliceDoc(f.from,f.to),x,k=l.filterStrict?new C4(g):new P4(g);for(let b of f.result.options)if(x=k.match(b.label)){let w=b.displayLabel?p?p(b,x.matched):[]:x.matched,S=x.score+(b.boost||0);if(s(new Rw(b,f.source,w,S)),typeof b.section=="object"&&b.section.rank==="dynamic"){let{name:Q}=b.section;i||(i=Object.create(null)),i[Q]=Math.max(S,i[Q]||-1e9)}}}}if(r){let f=Object.create(null),p=0,g=(x,k)=>(x.rank==="dynamic"&&k.rank==="dynamic"?i[k.name]-i[x.name]:0)||(typeof x.rank=="number"?x.rank:1e9)-(typeof k.rank=="number"?k.rank:1e9)||(x.name<k.name?-1:1);for(let x of r.sort(g))p-=1e5,f[x.name]=p;for(let x of t){let{section:k}=x.completion;k&&(x.score+=f[typeof k=="string"?k:k.name])}}let o=[],u=null,h=l.compareCompletions;for(let f of t.sort((p,g)=>g.score-p.score||h(p.completion,g.completion))){let p=f.completion;!u||u.label!=p.label||u.detail!=p.detail||u.type!=null&&p.type!=null&&u.type!=p.type||u.apply!=p.apply||u.boost!=p.boost?o.push(f):_w(f.completion)>_w(u)&&(o[o.length-1]=f),u=f.completion}return o}class Ro{constructor(e,t,r,i,s,l){this.options=e,this.attrs=t,this.tooltip=r,this.timestamp=i,this.selected=s,this.disabled=l}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new Ro(this.options,Dw(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,r,i,s,l){if(i&&!l&&e.some(h=>h.isPending))return i.setDisabled();let o=M4(e,t);if(!o.length)return i&&e.some(h=>h.isPending)?i.setDisabled():null;let u=t.facet(Yt).selectOnOpen?0:-1;if(i&&i.selected!=u&&i.selected!=-1){let h=i.options[i.selected].completion;for(let f=0;f<o.length;f++)if(o[f].completion==h){u=f;break}}return new Ro(o,Dw(r,u),{pos:e.reduce((h,f)=>f.hasResult()?Math.min(h,f.from):h,1e8),create:D4,above:s.aboveCursor},i?i.timestamp:Date.now(),u,!1)}map(e){return new Ro(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new Ro(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class bd{constructor(e,t,r){this.active=e,this.id=t,this.open=r}static start(){return new bd(L4,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,r=t.facet(Yt),s=(r.override||t.languageDataAt("autocomplete",_l(t)).map(S4)).map(u=>(this.active.find(f=>f.source==u)||new Qr(u,this.active.some(f=>f.state!=0)?1:0)).update(e,r));s.length==this.active.length&&s.every((u,h)=>u==this.active[h])&&(s=this.active);let l=this.open,o=e.effects.some(u=>u.is(s0));l&&e.docChanged&&(l=l.map(e.changes)),e.selection||s.some(u=>u.hasResult()&&e.changes.touchesRange(u.from,u.to))||!A4(s,this.active)||o?l=Ro.build(s,t,this.id,l,r,o):l&&l.disabled&&!s.some(u=>u.isPending)&&(l=null),!l&&s.every(u=>!u.isPending)&&s.some(u=>u.hasResult())&&(s=s.map(u=>u.hasResult()?new Qr(u.source,0):u));for(let u of e.effects)u.is(i0)&&(l=l&&l.setSelected(u.value,this.id));return s==this.active&&l==this.open?this:new bd(s,this.id,l)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?R4:N4}}function A4(n,e){if(n==e)return!0;for(let t=0,r=0;;){for(;t<n.length&&!n[t].hasResult();)t++;for(;r<e.length&&!e[r].hasResult();)r++;let i=t==n.length,s=r==e.length;if(i||s)return i==s;if(n[t++].result!=e[r++].result)return!1}}const R4={"aria-autocomplete":"list"},N4={};function Dw(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const L4=[];function VQ(n,e){if(n.isUserEvent("input.complete")){let r=n.annotation(r0);if(r&&e.activateOnCompletion(r))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}class Qr{constructor(e,t,r=!1){this.source=e,this.state=t,this.explicit=r}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let r=VQ(e,t),i=this;(r&8||r&16&&this.touches(e))&&(i=new Qr(i.source,0)),r&4&&i.state==0&&(i=new Qr(this.source,1)),i=i.updateFor(e,r);for(let s of e.effects)if(s.is(vd))i=new Qr(i.source,1,s.value);else if(s.is(cc))i=new Qr(i.source,0);else if(s.is(s0))for(let l of s.value)l.source==i.source&&(i=l);return i}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(_l(e.state))}}class zo extends Qr{constructor(e,t,r,i,s,l){super(e,3,t),this.limit=r,this.result=i,this.from=s,this.to=l}hasResult(){return!0}updateFor(e,t){var r;if(!(t&3))return this.map(e.changes);let i=this.result;i.map&&!e.changes.empty&&(i=i.map(i,e.changes));let s=e.changes.mapPos(this.from),l=e.changes.mapPos(this.to,1),o=_l(e.state);if(o>l||!i||t&2&&(_l(e.startState)==this.from||o<this.limit))return new Qr(this.source,t&4?1:0);let u=e.changes.mapPos(this.limit);return _4(i.validFor,e.state,s,l)?new zo(this.source,this.explicit,u,i,s,l):i.update&&(i=i.update(i,s,l,new n0(e.state,o,!1)))?new zo(this.source,this.explicit,u,i,i.from,(r=i.to)!==null&&r!==void 0?r:_l(e.state)):new Qr(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new zo(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Qr(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function _4(n,e,t,r){if(!n)return!1;let i=e.sliceDoc(t,r);return typeof n=="function"?n(i,t,r,e):qQ(n,!0).test(i)}const s0=Ne.define({map(n,e){return n.map(t=>t.map(e))}}),zn=an.define({create(){return bd.start()},update(n,e){return n.update(e)},provide:n=>[Vy.from(n,e=>e.tooltip),he.contentAttributes.from(n,e=>e.attrs)]});function l0(n,e){const t=e.completion.apply||e.completion.label;let r=n.state.field(zn).active.find(i=>i.source==e.source);return r instanceof zo?(typeof t=="string"?n.dispatch({...w4(n.state,t,r.from,r.to),annotations:r0.of(e.completion)}):t(n,e.completion,r.from,r.to),!0):!1}const D4=j4(zn,l0);function Pf(n,e="option"){return t=>{let r=t.state.field(zn,!1);if(!r||!r.open||r.open.disabled||Date.now()-r.open.timestamp<t.state.facet(Yt).interactionDelay)return!1;let i=1,s;e=="page"&&(s=fQ(t,r.open.tooltip))&&(i=Math.max(2,Math.floor(s.dom.offsetHeight/s.dom.querySelector("li").offsetHeight)-1));let{length:l}=r.open.options,o=r.open.selected>-1?r.open.selected+i*(n?1:-1):n?0:l-1;return o<0?o=e=="page"?0:l-1:o>=l&&(o=e=="page"?l-1:0),t.dispatch({effects:i0.of(o)}),!0}}const I4=n=>{let e=n.state.field(zn,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(Yt).interactionDelay?!1:l0(n,e.open.options[e.open.selected])},Ig=n=>n.state.field(zn,!1)?(n.dispatch({effects:vd.of(!0)}),!0):!1,z4=n=>{let e=n.state.field(zn,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:cc.of(null)}),!0)};class Z4{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const X4=50,B4=1e3,W4=Ct.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(zn).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(zn),t=n.state.facet(Yt);if(!n.selectionSet&&!n.docChanged&&n.startState.field(zn)==e)return;let r=n.transactions.some(s=>{let l=VQ(s,t);return l&8||(s.selection||s.docChanged)&&!(l&3)});for(let s=0;s<this.running.length;s++){let l=this.running[s];if(r||l.context.abortOnDocChange&&n.docChanged||l.updates.length+n.transactions.length>X4&&Date.now()-l.time>B4){for(let o of l.context.abortListeners)try{o()}catch(u){Xn(this.view.state,u)}l.context.abortListeners=null,this.running.splice(s--,1)}else l.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(s=>s.effects.some(l=>l.is(vd)))&&(this.pendingStart=!0);let i=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(s=>s.isPending&&!this.running.some(l=>l.active.source==s.source))?setTimeout(()=>this.startUpdate(),i):-1,this.composing!=0)for(let s of n.transactions)s.isUserEvent("input.type")?this.composing=2:this.composing==2&&s.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,e=n.field(zn);for(let t of e.active)t.isPending&&!this.running.some(r=>r.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Yt).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=_l(e),r=new n0(e,t,n.explicit,this.view),i=new Z4(n,r);this.running.push(i),Promise.resolve(n.source(r)).then(s=>{i.context.aborted||(i.done=s||null,this.scheduleAccept())},s=>{this.view.dispatch({effects:cc.of(null)}),Xn(this.view.state,s)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(Yt).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(Yt),r=this.view.state.field(zn);for(let i=0;i<this.running.length;i++){let s=this.running[i];if(s.done===void 0)continue;if(this.running.splice(i--,1),s.done){let o=_l(s.updates.length?s.updates[0].startState:this.view.state),u=Math.min(o,s.done.from+(s.active.explicit?0:1)),h=new zo(s.active.source,s.active.explicit,u,s.done,s.done.from,(n=s.done.to)!==null&&n!==void 0?n:o);for(let f of s.updates)h=h.update(f,t);if(h.hasResult()){e.push(h);continue}}let l=r.active.find(o=>o.source==s.active.source);if(l&&l.isPending)if(s.done==null){let o=new Qr(s.active.source,0);for(let u of s.updates)o=o.update(u,t);o.isPending||e.push(o)}else this.startQuery(l)}(e.length||r.open&&r.open.disabled)&&this.view.dispatch({effects:s0.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(zn,!1);if(e&&e.tooltip&&this.view.state.facet(Yt).closeOnBlur){let t=e.open&&fQ(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:cc.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:vd.of(!1)}),20),this.composing=0}}}),q4=typeof navigator=="object"&&/Win/.test(navigator.platform),V4=Ui.highest(he.domEventHandlers({keydown(n,e){let t=e.state.field(zn,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(q4&&n.altKey)||n.metaKey)return!1;let r=t.open.options[t.open.selected],i=t.active.find(l=>l.source==r.source),s=r.completion.commitCharacters||i.result.commitCharacters;return s&&s.indexOf(n.key)>-1&&l0(e,r),!1}})),FQ=he.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center",cursor:"pointer"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'ƒ'"}},".cm-completionIcon-class":{"&:after":{content:"'○'"}},".cm-completionIcon-interface":{"&:after":{content:"'◌'"}},".cm-completionIcon-variable":{"&:after":{content:"'𝑥'"}},".cm-completionIcon-constant":{"&:after":{content:"'𝐶'"}},".cm-completionIcon-type":{"&:after":{content:"'𝑡'"}},".cm-completionIcon-enum":{"&:after":{content:"'∪'"}},".cm-completionIcon-property":{"&:after":{content:"'□'"}},".cm-completionIcon-keyword":{"&:after":{content:"'🔑︎'"}},".cm-completionIcon-namespace":{"&:after":{content:"'▢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}});class F4{constructor(e,t,r,i){this.field=e,this.line=t,this.from=r,this.to=i}}class o0{constructor(e,t,r){this.field=e,this.from=t,this.to=r}map(e){let t=e.mapPos(this.from,-1,sn.TrackDel),r=e.mapPos(this.to,1,sn.TrackDel);return t==null||r==null?null:new o0(this.field,t,r)}}let Y4=class YQ{constructor(e,t){this.lines=e,this.fieldPositions=t}instantiate(e,t){let r=[],i=[t],s=e.doc.lineAt(t),l=/^\s*/.exec(s.text)[0];for(let u of this.lines){if(r.length){let h=l,f=/^\t*/.exec(u)[0].length;for(let p=0;p<f;p++)h+=e.facet(Sa);i.push(t+h.length-f),u=h+u.slice(f)}r.push(u),t+=u.length+1}let o=this.fieldPositions.map(u=>new o0(u.field,i[u.line]+u.from,i[u.line]+u.to));return{text:r,ranges:o}}static parse(e){let t=[],r=[],i=[],s;for(let l of e.split(/\r\n?|\n/)){for(;s=/[#$]\{(?:(\d+)(?::([^{}]*))?|((?:\\[{}]|[^{}])*))\}/.exec(l);){let o=s[1]?+s[1]:null,u=s[2]||s[3]||"",h=-1,f=u.replace(/\\[{}]/g,p=>p[1]);for(let p=0;p<t.length;p++)(o!=null?t[p].seq==o:f&&t[p].name==f)&&(h=p);if(h<0){let p=0;for(;p<t.length&&(o==null||t[p].seq!=null&&t[p].seq<o);)p++;t.splice(p,0,{seq:o,name:f}),h=p;for(let g of i)g.field>=h&&g.field++}for(let p of i)if(p.line==r.length&&p.from>s.index){let g=s[2]?3+(s[1]||"").length:2;p.from-=g,p.to-=g}i.push(new F4(h,r.length,s.index,s.index+f.length)),l=l.slice(0,s.index)+u+l.slice(s.index+s[0].length)}l=l.replace(/\\([{}])/g,(o,u,h)=>{for(let f of i)f.line==r.length&&f.from>h&&(f.from--,f.to--);return u}),r.push(l)}return new YQ(r,i)}},U4=$e.widget({widget:new class extends Vr{toDOM(){let n=document.createElement("span");return n.className="cm-snippetFieldPosition",n}ignoreEvent(){return!1}}}),G4=$e.mark({class:"cm-snippetField"});class Ca{constructor(e,t){this.ranges=e,this.active=t,this.deco=$e.set(e.map(r=>(r.from==r.to?U4:G4).range(r.from,r.to)),!0)}map(e){let t=[];for(let r of this.ranges){let i=r.map(e);if(!i)return null;t.push(i)}return new Ca(t,this.active)}selectionInsideField(e){return e.ranges.every(t=>this.ranges.some(r=>r.field==this.active&&r.from<=t.from&&r.to>=t.to))}}const zc=Ne.define({map(n,e){return n&&n.map(e)}}),H4=Ne.define(),hc=an.define({create(){return null},update(n,e){for(let t of e.effects){if(t.is(zc))return t.value;if(t.is(H4)&&n)return new Ca(n.ranges,t.value)}return n&&e.docChanged&&(n=n.map(e.changes)),n&&e.selection&&!n.selectionInsideField(e.selection)&&(n=null),n},provide:n=>he.decorations.from(n,e=>e?e.deco:$e.none)});function a0(n,e){return Y.create(n.filter(t=>t.field==e).map(t=>Y.range(t.from,t.to)))}function K4(n){let e=Y4.parse(n);return(t,r,i,s)=>{let{text:l,ranges:o}=e.instantiate(t.state,i),{main:u}=t.state.selection,h={changes:{from:i,to:s==u.from?u.to:s,insert:Ge.of(l)},scrollIntoView:!0,annotations:r?[r0.of(r),At.userEvent.of("input.complete")]:void 0};if(o.length&&(h.selection=a0(o,0)),o.some(f=>f.field>0)){let f=new Ca(o,0),p=h.effects=[zc.of(f)];t.state.field(hc,!1)===void 0&&p.push(Ne.appendConfig.of([hc,rD,iD,FQ]))}t.dispatch(t.state.update(h))}}function UQ(n){return({state:e,dispatch:t})=>{let r=e.field(hc,!1);if(!r||n<0&&r.active==0)return!1;let i=r.active+n,s=n>0&&!r.ranges.some(l=>l.field==i+n);return t(e.update({selection:a0(r.ranges,i),effects:zc.of(s?null:new Ca(r.ranges,i)),scrollIntoView:!0})),!0}}const J4=({state:n,dispatch:e})=>n.field(hc,!1)?(e(n.update({effects:zc.of(null)})),!0):!1,eD=UQ(1),tD=UQ(-1),nD=[{key:"Tab",run:eD,shift:tD},{key:"Escape",run:J4}],Iw=ge.define({combine(n){return n.length?n[0]:nD}}),rD=Ui.highest(ba.compute([Iw],n=>n.facet(Iw)));function Ln(n,e){return{...e,apply:K4(n)}}const iD=he.domEventHandlers({mousedown(n,e){let t=e.state.field(hc,!1),r;if(!t||(r=e.posAtCoords({x:n.clientX,y:n.clientY}))==null)return!1;let i=t.ranges.find(s=>s.from<=r&&s.to>=r);return!i||i.field==t.active?!1:(e.dispatch({selection:a0(t.ranges,i.field),effects:zc.of(t.ranges.some(s=>s.field>i.field)?new Ca(t.ranges,i.field):null),scrollIntoView:!0}),!0)}}),fc={brackets:["(","[","{","'",'"'],before:")]}:;>",stringPrefixes:[]},Cl=Ne.define({map(n,e){let t=e.mapPos(n,-1,sn.TrackAfter);return t??void 0}}),u0=new class extends Xs{};u0.startSide=1;u0.endSide=-1;const GQ=an.define({create(){return We.empty},update(n,e){if(n=n.map(e.changes),e.selection){let t=e.state.doc.lineAt(e.selection.main.head);n=n.update({filter:r=>r>=t.from&&r<=t.to})}for(let t of e.effects)t.is(Cl)&&(n=n.update({add:[u0.range(t.value,t.value+1)]}));return n}});function sD(){return[oD,GQ]}const zg="()[]{}<>«»»«[]{}";function HQ(n){for(let e=0;e<zg.length;e+=2)if(zg.charCodeAt(e)==n)return zg.charAt(e+1);return Ty(n<128?n:n+1)}function KQ(n,e){return n.languageDataAt("closeBrackets",e)[0]||fc}const lD=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),oD=he.inputHandler.of((n,e,t,r)=>{if((lD?n.composing:n.compositionStarted)||n.state.readOnly)return!1;let i=n.state.selection.main;if(r.length>2||r.length==2&&hi(In(r,0))==1||e!=i.from||t!=i.to)return!1;let s=cD(n.state,r);return s?(n.dispatch(s),!0):!1}),aD=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let r=KQ(n,n.selection.main.head).brackets||fc.brackets,i=null,s=n.changeByRange(l=>{if(l.empty){let o=hD(n.doc,l.head);for(let u of r)if(u==o&&op(n.doc,l.head)==HQ(In(u,0)))return{changes:{from:l.head-u.length,to:l.head+u.length},range:Y.cursor(l.head-u.length)}}return{range:i=l}});return i||e(n.update(s,{scrollIntoView:!0,userEvent:"delete.backward"})),!i},uD=[{key:"Backspace",run:aD}];function cD(n,e){let t=KQ(n,n.selection.main.head),r=t.brackets||fc.brackets;for(let i of r){let s=HQ(In(i,0));if(e==i)return s==i?pD(n,i,r.indexOf(i+i+i)>-1,t):fD(n,i,s,t.before||fc.before);if(e==s&&JQ(n,n.selection.main.from))return dD(n,i,s)}return null}function JQ(n,e){let t=!1;return n.field(GQ).between(0,n.doc.length,r=>{r==e&&(t=!0)}),t}function op(n,e){let t=n.sliceString(e,e+2);return t.slice(0,hi(In(t,0)))}function hD(n,e){let t=n.sliceString(e-2,e);return hi(In(t,0))==t.length?t:t.slice(1)}function fD(n,e,t,r){let i=null,s=n.changeByRange(l=>{if(!l.empty)return{changes:[{insert:e,from:l.from},{insert:t,from:l.to}],effects:Cl.of(l.to+e.length),range:Y.range(l.anchor+e.length,l.head+e.length)};let o=op(n.doc,l.head);return!o||/\s/.test(o)||r.indexOf(o)>-1?{changes:{insert:e+t,from:l.head},effects:Cl.of(l.head+e.length),range:Y.cursor(l.head+e.length)}:{range:i=l}});return i?null:n.update(s,{scrollIntoView:!0,userEvent:"input.type"})}function dD(n,e,t){let r=null,i=n.changeByRange(s=>s.empty&&op(n.doc,s.head)==t?{changes:{from:s.head,to:s.head+t.length,insert:t},range:Y.cursor(s.head+t.length)}:r={range:s});return r?null:n.update(i,{scrollIntoView:!0,userEvent:"input.type"})}function pD(n,e,t,r){let i=r.stringPrefixes||fc.stringPrefixes,s=null,l=n.changeByRange(o=>{if(!o.empty)return{changes:[{insert:e,from:o.from},{insert:e,from:o.to}],effects:Cl.of(o.to+e.length),range:Y.range(o.anchor+e.length,o.head+e.length)};let u=o.head,h=op(n.doc,u),f;if(h==e){if(zw(n,u))return{changes:{insert:e+e,from:u},effects:Cl.of(u+e.length),range:Y.cursor(u+e.length)};if(JQ(n,u)){let g=t&&n.sliceDoc(u,u+e.length*3)==e+e+e?e+e+e:e;return{changes:{from:u,to:u+g.length,insert:g},range:Y.cursor(u+g.length)}}}else{if(t&&n.sliceDoc(u-2*e.length,u)==e+e&&(f=Zw(n,u-2*e.length,i))>-1&&zw(n,f))return{changes:{insert:e+e+e+e,from:u},effects:Cl.of(u+e.length),range:Y.cursor(u+e.length)};if(n.charCategorizer(u)(h)!=yt.Word&&Zw(n,u,i)>-1&&!mD(n,u,e,i))return{changes:{insert:e+e,from:u},effects:Cl.of(u+e.length),range:Y.cursor(u+e.length)}}return{range:s=o}});return s?null:n.update(l,{scrollIntoView:!0,userEvent:"input.type"})}function zw(n,e){let t=dt(n).resolveInner(e+1);return t.parent&&t.from==e}function mD(n,e,t,r){let i=dt(n).resolveInner(e,-1),s=r.reduce((l,o)=>Math.max(l,o.length),0);for(let l=0;l<5;l++){let o=n.sliceDoc(i.from,Math.min(i.to,i.from+t.length+s)),u=o.indexOf(t);if(!u||u>-1&&r.indexOf(o.slice(0,u))>-1){let f=i.firstChild;for(;f&&f.from==i.from&&f.to-f.from>t.length+u;){if(n.sliceDoc(f.to-t.length,f.to)==t)return!1;f=f.firstChild}return!0}let h=i.to==e&&i.parent;if(!h)break;i=h}return!1}function Zw(n,e,t){let r=n.charCategorizer(e);if(r(n.sliceDoc(e-1,e))!=yt.Word)return e;for(let i of t){let s=e-i.length;if(n.sliceDoc(s,e)==i&&r(n.sliceDoc(s-1,s))!=yt.Word)return s}return-1}function gD(n={}){return[V4,zn,Yt.of(n),W4,OD,FQ]}const e$=[{key:"Ctrl-Space",run:Ig},{mac:"Alt-`",run:Ig},{mac:"Alt-i",run:Ig},{key:"Escape",run:z4},{key:"ArrowDown",run:Pf(!0)},{key:"ArrowUp",run:Pf(!1)},{key:"PageDown",run:Pf(!0,"page")},{key:"PageUp",run:Pf(!1,"page")},{key:"Enter",run:I4}],OD=Ui.highest(ba.computeN([Yt],n=>n.facet(Yt).defaultKeymap?[e$]:[]));class wd{static create(e,t,r,i,s){let l=i+(i<<8)+e+(t<<4)|0;return new wd(e,t,r,l,s,[],[])}constructor(e,t,r,i,s,l,o){this.type=e,this.value=t,this.from=r,this.hash=i,this.end=s,this.children=l,this.positions=o,this.hashProp=[[Le.contextHash,i]]}addChild(e,t){e.prop(Le.contextHash)!=this.hash&&(e=new tt(e.type,e.children,e.positions,e.length,this.hashProp)),this.children.push(e),this.positions.push(t)}toTree(e,t=this.end){let r=this.children.length-1;return r>=0&&(t=Math.max(t,this.positions[r]+this.children[r].length+this.from)),new tt(e.types[this.type],this.children,this.positions,t-this.from).balance({makeTree:(i,s,l)=>new tt(Dt.none,i,s,l,this.hashProp)})}}var ae;(function(n){n[n.Document=1]="Document",n[n.CodeBlock=2]="CodeBlock",n[n.FencedCode=3]="FencedCode",n[n.Blockquote=4]="Blockquote",n[n.HorizontalRule=5]="HorizontalRule",n[n.BulletList=6]="BulletList",n[n.OrderedList=7]="OrderedList",n[n.ListItem=8]="ListItem",n[n.ATXHeading1=9]="ATXHeading1",n[n.ATXHeading2=10]="ATXHeading2",n[n.ATXHeading3=11]="ATXHeading3",n[n.ATXHeading4=12]="ATXHeading4",n[n.ATXHeading5=13]="ATXHeading5",n[n.ATXHeading6=14]="ATXHeading6",n[n.SetextHeading1=15]="SetextHeading1",n[n.SetextHeading2=16]="SetextHeading2",n[n.HTMLBlock=17]="HTMLBlock",n[n.LinkReference=18]="LinkReference",n[n.Paragraph=19]="Paragraph",n[n.CommentBlock=20]="CommentBlock",n[n.ProcessingInstructionBlock=21]="ProcessingInstructionBlock",n[n.Escape=22]="Escape",n[n.Entity=23]="Entity",n[n.HardBreak=24]="HardBreak",n[n.Emphasis=25]="Emphasis",n[n.StrongEmphasis=26]="StrongEmphasis",n[n.Link=27]="Link",n[n.Image=28]="Image",n[n.InlineCode=29]="InlineCode",n[n.HTMLTag=30]="HTMLTag",n[n.Comment=31]="Comment",n[n.ProcessingInstruction=32]="ProcessingInstruction",n[n.Autolink=33]="Autolink",n[n.HeaderMark=34]="HeaderMark",n[n.QuoteMark=35]="QuoteMark",n[n.ListMark=36]="ListMark",n[n.LinkMark=37]="LinkMark",n[n.EmphasisMark=38]="EmphasisMark",n[n.CodeMark=39]="CodeMark",n[n.CodeText=40]="CodeText",n[n.CodeInfo=41]="CodeInfo",n[n.LinkTitle=42]="LinkTitle",n[n.LinkLabel=43]="LinkLabel",n[n.URL=44]="URL"})(ae||(ae={}));class xD{constructor(e,t){this.start=e,this.content=t,this.marks=[],this.parsers=[]}}class yD{constructor(){this.text="",this.baseIndent=0,this.basePos=0,this.depth=0,this.markers=[],this.pos=0,this.indent=0,this.next=-1}forward(){this.basePos>this.pos&&this.forwardInner()}forwardInner(){let e=this.skipSpace(this.basePos);this.indent=this.countIndent(e,this.pos,this.indent),this.pos=e,this.next=e==this.text.length?-1:this.text.charCodeAt(e)}skipSpace(e){return Xu(this.text,e)}reset(e){for(this.text=e,this.baseIndent=this.basePos=this.pos=this.indent=0,this.forwardInner(),this.depth=1;this.markers.length;)this.markers.pop()}moveBase(e){this.basePos=e,this.baseIndent=this.countIndent(e,this.pos,this.indent)}moveBaseColumn(e){this.baseIndent=e,this.basePos=this.findColumn(e)}addMarker(e){this.markers.push(e)}countIndent(e,t=0,r=0){for(let i=t;i<e;i++)r+=this.text.charCodeAt(i)==9?4-r%4:1;return r}findColumn(e){let t=0;for(let r=0;t<this.text.length&&r<e;t++)r+=this.text.charCodeAt(t)==9?4-r%4:1;return t}scrub(){if(!this.baseIndent)return this.text;let e="";for(let t=0;t<this.basePos;t++)e+=" ";return e+this.text.slice(this.basePos)}}function Xw(n,e,t){if(t.pos==t.text.length||n!=e.block&&t.indent>=e.stack[t.depth+1].value+t.baseIndent)return!0;if(t.indent>=t.baseIndent+4)return!1;let r=(n.type==ae.OrderedList?f0:h0)(t,e,!1);return r>0&&(n.type!=ae.BulletList||c0(t,e,!1)<0)&&t.text.charCodeAt(t.pos+r-1)==n.value}const t$={[ae.Blockquote](n,e,t){return t.next!=62?!1:(t.markers.push(Ue(ae.QuoteMark,e.lineStart+t.pos,e.lineStart+t.pos+1)),t.moveBase(t.pos+(jr(t.text.charCodeAt(t.pos+1))?2:1)),n.end=e.lineStart+t.text.length,!0)},[ae.ListItem](n,e,t){return t.indent<t.baseIndent+n.value&&t.next>-1?!1:(t.moveBaseColumn(t.baseIndent+n.value),!0)},[ae.OrderedList]:Xw,[ae.BulletList]:Xw,[ae.Document](){return!0}};function jr(n){return n==32||n==9||n==10||n==13}function Xu(n,e=0){for(;e<n.length&&jr(n.charCodeAt(e));)e++;return e}function Bw(n,e,t){for(;e>t&&jr(n.charCodeAt(e-1));)e--;return e}function n$(n){if(n.next!=96&&n.next!=126)return-1;let e=n.pos+1;for(;e<n.text.length&&n.text.charCodeAt(e)==n.next;)e++;if(e<n.pos+3)return-1;if(n.next==96){for(let t=e;t<n.text.length;t++)if(n.text.charCodeAt(t)==96)return-1}return e}function r$(n){return n.next!=62?-1:n.text.charCodeAt(n.pos+1)==32?2:1}function c0(n,e,t){if(n.next!=42&&n.next!=45&&n.next!=95)return-1;let r=1;for(let i=n.pos+1;i<n.text.length;i++){let s=n.text.charCodeAt(i);if(s==n.next)r++;else if(!jr(s))return-1}return t&&n.next==45&&l$(n)>-1&&n.depth==e.stack.length&&e.parser.leafBlockParsers.indexOf(c$.SetextHeading)>-1||r<3?-1:1}function i$(n,e){for(let t=n.stack.length-1;t>=0;t--)if(n.stack[t].type==e)return!0;return!1}function h0(n,e,t){return(n.next==45||n.next==43||n.next==42)&&(n.pos==n.text.length-1||jr(n.text.charCodeAt(n.pos+1)))&&(!t||i$(e,ae.BulletList)||n.skipSpace(n.pos+2)<n.text.length)?1:-1}function f0(n,e,t){let r=n.pos,i=n.next;for(;i>=48&&i<=57;){r++;if(r==n.text.length)return-1;i=n.text.charCodeAt(r)}return r==n.pos||r>n.pos+9||i!=46&&i!=41||r<n.text.length-1&&!jr(n.text.charCodeAt(r+1))||t&&!i$(e,ae.OrderedList)&&(n.skipSpace(r+1)==n.text.length||r>n.pos+1||n.next!=49)?-1:r+1-n.pos}function s$(n){if(n.next!=35)return-1;let e=n.pos+1;for(;e<n.text.length&&n.text.charCodeAt(e)==35;)e++;if(e<n.text.length&&n.text.charCodeAt(e)!=32)return-1;let t=e-n.pos;return t>6?-1:t}function l$(n){if(n.next!=45&&n.next!=61||n.indent>=n.baseIndent+4)return-1;let e=n.pos+1;for(;e<n.text.length&&n.text.charCodeAt(e)==n.next;)e++;let t=e;for(;e<n.text.length&&jr(n.text.charCodeAt(e));)e++;return e==n.text.length?t:-1}const Dx=/^[ \t]*$/,o$=/-->/,a$=/\?>/,Ix=[[/^<(?:script|pre|style)(?:\s|>|$)/i,/<\/(?:script|pre|style)>/i],[/^\s*<!--/,o$],[/^\s*<\?/,a$],[/^\s*<![A-Z]/,/>/],[/^\s*<!\[CDATA\[/,/\]\]>/],[/^\s*<\/?(?:address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h1|h2|h3|h4|h5|h6|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|nav|noframes|ol|optgroup|option|p|param|section|source|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul)(?:\s|\/?>|$)/i,Dx],[/^\s*(?:<\/[a-z][\w-]*\s*>|<[a-z][\w-]*(\s+[a-z:_][\w-.]*(?:\s*=\s*(?:[^\s"'=<>`]+|'[^']*'|"[^"]*"))?)*\s*>)\s*$/i,Dx]];function u$(n,e,t){if(n.next!=60)return-1;let r=n.text.slice(n.pos);for(let i=0,s=Ix.length-(t?1:0);i<s;i++)if(Ix[i][0].test(r))return i;return-1}function Ww(n,e){let t=n.countIndent(e,n.pos,n.indent),r=n.countIndent(n.skipSpace(e),e,t);return r>=t+5?t+1:r}function vs(n,e,t){let r=n.length-1;r>=0&&n[r].to==e&&n[r].type==ae.CodeText?n[r].to=t:n.push(Ue(ae.CodeText,e,t))}const Cf={LinkReference:void 0,IndentedCode(n,e){let t=e.baseIndent+4;if(e.indent<t)return!1;let r=e.findColumn(t),i=n.lineStart+r,s=n.lineStart+e.text.length,l=[],o=[];for(vs(l,i,s);n.nextLine()&&e.depth>=n.stack.length;)if(e.pos==e.text.length){vs(o,n.lineStart-1,n.lineStart);for(let u of e.markers)o.push(u)}else{if(e.indent<t)break;{if(o.length){for(let h of o)h.type==ae.CodeText?vs(l,h.from,h.to):l.push(h);o=[]}vs(l,n.lineStart-1,n.lineStart);for(let h of e.markers)l.push(h);s=n.lineStart+e.text.length;let u=n.lineStart+e.findColumn(e.baseIndent+4);u<s&&vs(l,u,s)}}return o.length&&(o=o.filter(u=>u.type!=ae.CodeText),o.length&&(e.markers=o.concat(e.markers))),n.addNode(n.buffer.writeElements(l,-i).finish(ae.CodeBlock,s-i),i),!0},FencedCode(n,e){let t=n$(e);if(t<0)return!1;let r=n.lineStart+e.pos,i=e.next,s=t-e.pos,l=e.skipSpace(t),o=Bw(e.text,e.text.length,l),u=[Ue(ae.CodeMark,r,r+s)];l<o&&u.push(Ue(ae.CodeInfo,n.lineStart+l,n.lineStart+o));for(let h=!0,f=!0,p=!1;n.nextLine()&&e.depth>=n.stack.length;h=!1){let g=e.pos;if(e.indent-e.baseIndent<4)for(;g<e.text.length&&e.text.charCodeAt(g)==i;)g++;if(g-e.pos>=s&&e.skipSpace(g)==e.text.length){for(let x of e.markers)u.push(x);f&&p&&vs(u,n.lineStart-1,n.lineStart),u.push(Ue(ae.CodeMark,n.lineStart+e.pos,n.lineStart+g)),n.nextLine();break}else{p=!0,h||(vs(u,n.lineStart-1,n.lineStart),f=!1);for(let b of e.markers)u.push(b);let x=n.lineStart+e.basePos,k=n.lineStart+e.text.length;x<k&&(vs(u,x,k),f=!1)}}return n.addNode(n.buffer.writeElements(u,-r).finish(ae.FencedCode,n.prevLineEnd()-r),r),!0},Blockquote(n,e){let t=r$(e);return t<0?!1:(n.startContext(ae.Blockquote,e.pos),n.addNode(ae.QuoteMark,n.lineStart+e.pos,n.lineStart+e.pos+1),e.moveBase(e.pos+t),null)},HorizontalRule(n,e){if(c0(e,n,!1)<0)return!1;let t=n.lineStart+e.pos;return n.nextLine(),n.addNode(ae.HorizontalRule,t),!0},BulletList(n,e){let t=h0(e,n,!1);if(t<0)return!1;n.block.type!=ae.BulletList&&n.startContext(ae.BulletList,e.basePos,e.next);let r=Ww(e,e.pos+1);return n.startContext(ae.ListItem,e.basePos,r-e.baseIndent),n.addNode(ae.ListMark,n.lineStart+e.pos,n.lineStart+e.pos+t),e.moveBaseColumn(r),null},OrderedList(n,e){let t=f0(e,n,!1);if(t<0)return!1;n.block.type!=ae.OrderedList&&n.startContext(ae.OrderedList,e.basePos,e.text.charCodeAt(e.pos+t-1));let r=Ww(e,e.pos+t);return n.startContext(ae.ListItem,e.basePos,r-e.baseIndent),n.addNode(ae.ListMark,n.lineStart+e.pos,n.lineStart+e.pos+t),e.moveBaseColumn(r),null},ATXHeading(n,e){let t=s$(e);if(t<0)return!1;let r=e.pos,i=n.lineStart+r,s=Bw(e.text,e.text.length,r),l=s;for(;l>r&&e.text.charCodeAt(l-1)==e.next;)l--;(l==s||l==r||!jr(e.text.charCodeAt(l-1)))&&(l=e.text.length);let o=n.buffer.write(ae.HeaderMark,0,t).writeElements(n.parser.parseInline(e.text.slice(r+t+1,l),i+t+1),-i);l<e.text.length&&o.write(ae.HeaderMark,l-r,s-r);let u=o.finish(ae.ATXHeading1-1+t,e.text.length-r);return n.nextLine(),n.addNode(u,i),!0},HTMLBlock(n,e){let t=u$(e,n,!1);if(t<0)return!1;let r=n.lineStart+e.pos,i=Ix[t][1],s=[],l=i!=Dx;for(;!i.test(e.text)&&n.nextLine();){if(e.depth<n.stack.length){l=!1;break}for(let h of e.markers)s.push(h)}l&&n.nextLine();let o=i==o$?ae.CommentBlock:i==a$?ae.ProcessingInstructionBlock:ae.HTMLBlock,u=n.prevLineEnd();return n.addNode(n.buffer.writeElements(s,-r).finish(o,u-r),r),!0},SetextHeading:void 0};class kD{constructor(e){this.stage=0,this.elts=[],this.pos=0,this.start=e.start,this.advance(e.content)}nextLine(e,t,r){if(this.stage==-1)return!1;let i=r.content+`
78
78
  `+t.scrub(),s=this.advance(i);return s>-1&&s<i.length?this.complete(e,r,s):!1}finish(e,t){return(this.stage==2||this.stage==3)&&Xu(t.content,this.pos)==t.content.length?this.complete(e,t,t.content.length):!1}complete(e,t,r){return e.addLeafElement(t,Ue(ae.LinkReference,this.start,this.start+r,this.elts)),!0}nextStage(e){return e?(this.pos=e.to-this.start,this.elts.push(e),this.stage++,!0):(e===!1&&(this.stage=-1),!1)}advance(e){for(;;){if(this.stage==-1)return-1;if(this.stage==0){if(!this.nextStage(y$(e,this.pos,this.start,!0)))return-1;if(e.charCodeAt(this.pos)!=58)return this.stage=-1;this.elts.push(Ue(ae.LinkMark,this.pos+this.start,this.pos+this.start+1)),this.pos++}else if(this.stage==1){if(!this.nextStage(O$(e,Xu(e,this.pos),this.start)))return-1}else if(this.stage==2){let t=Xu(e,this.pos),r=0;if(t>this.pos){let i=x$(e,t,this.start);if(i){let s=Zg(e,i.to-this.start);s>0&&(this.nextStage(i),r=s)}}return r||(r=Zg(e,this.pos)),r>0&&r<e.length?r:-1}else return Zg(e,this.pos)}}}function Zg(n,e){for(;e<n.length;e++){let t=n.charCodeAt(e);if(t==10)break;if(!jr(t))return-1}return e}class vD{nextLine(e,t,r){let i=t.depth<e.stack.length?-1:l$(t),s=t.next;if(i<0)return!1;let l=Ue(ae.HeaderMark,e.lineStart+t.pos,e.lineStart+i);return e.nextLine(),e.addLeafElement(r,Ue(s==61?ae.SetextHeading1:ae.SetextHeading2,r.start,e.prevLineEnd(),[...e.parser.parseInline(r.content,r.start),l])),!0}finish(){return!1}}const c$={LinkReference(n,e){return e.content.charCodeAt(0)==91?new kD(e):null},SetextHeading(){return new vD}},bD=[(n,e)=>s$(e)>=0,(n,e)=>n$(e)>=0,(n,e)=>r$(e)>=0,(n,e)=>h0(e,n,!0)>=0,(n,e)=>f0(e,n,!0)>=0,(n,e)=>c0(e,n,!0)>=0,(n,e)=>u$(e,n,!0)>=0],wD={text:"",end:0};class SD{constructor(e,t,r,i){this.parser=e,this.input=t,this.ranges=i,this.line=new yD,this.atEnd=!1,this.reusePlaceholders=new Map,this.stoppedAt=null,this.rangeI=0,this.to=i[i.length-1].to,this.lineStart=this.absoluteLineStart=this.absoluteLineEnd=i[0].from,this.block=wd.create(ae.Document,0,this.lineStart,0,0),this.stack=[this.block],this.fragments=r.length?new QD(r,t):null,this.readLine()}get parsedPos(){return this.absoluteLineStart}advance(){if(this.stoppedAt!=null&&this.absoluteLineStart>this.stoppedAt)return this.finish();let{line:e}=this;for(;;){for(let r=0;;){let i=e.depth<this.stack.length?this.stack[this.stack.length-1]:null;for(;r<e.markers.length&&(!i||e.markers[r].from<i.end);){let s=e.markers[r++];this.addNode(s.type,s.from,s.to)}if(!i)break;this.finishContext()}if(e.pos<e.text.length)break;if(!this.nextLine())return this.finish()}if(this.fragments&&this.reuseFragment(e.basePos))return null;e:for(;;){for(let r of this.parser.blockParsers)if(r){let i=r(this,e);if(i!=!1){if(i==!0)return null;e.forward();continue e}}break}let t=new xD(this.lineStart+e.pos,e.text.slice(e.pos));for(let r of this.parser.leafBlockParsers)if(r){let i=r(this,t);i&&t.parsers.push(i)}e:for(;this.nextLine()&&e.pos!=e.text.length;){if(e.indent<e.baseIndent+4){for(let r of this.parser.endLeafBlock)if(r(this,e,t))break e}for(let r of t.parsers)if(r.nextLine(this,e,t))return null;t.content+=`
79
79
  `+e.scrub();for(let r of e.markers)t.marks.push(r)}return this.finishLeaf(t),null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}reuseFragment(e){if(!this.fragments.moveTo(this.absoluteLineStart+e,this.absoluteLineStart)||!this.fragments.matches(this.block.hash))return!1;let t=this.fragments.takeNodes(this);return t?(this.absoluteLineStart+=t,this.lineStart=k$(this.absoluteLineStart,this.ranges),this.moveRangeI(),this.absoluteLineStart<this.to?(this.lineStart++,this.absoluteLineStart++,this.readLine()):(this.atEnd=!0,this.readLine()),!0):!1}get depth(){return this.stack.length}parentType(e=this.depth-1){return this.parser.nodeSet.types[this.stack[e].type]}nextLine(){return this.lineStart+=this.line.text.length,this.absoluteLineEnd>=this.to?(this.absoluteLineStart=this.absoluteLineEnd,this.atEnd=!0,this.readLine(),!1):(this.lineStart++,this.absoluteLineStart=this.absoluteLineEnd+1,this.moveRangeI(),this.readLine(),!0)}peekLine(){return this.scanLine(this.absoluteLineEnd+1).text}moveRangeI(){for(;this.rangeI<this.ranges.length-1&&this.absoluteLineStart>=this.ranges[this.rangeI].to;)this.rangeI++,this.absoluteLineStart=Math.max(this.absoluteLineStart,this.ranges[this.rangeI].from)}scanLine(e){let t=wD;if(t.end=e,e>=this.to)t.text="";else if(t.text=this.lineChunkAt(e),t.end+=t.text.length,this.ranges.length>1){let r=this.absoluteLineStart,i=this.rangeI;for(;this.ranges[i].to<t.end;){i++;let s=this.ranges[i].from,l=this.lineChunkAt(s);t.end=s+l.length,t.text=t.text.slice(0,this.ranges[i-1].to-r)+l,r=t.end-t.text.length}}return t}readLine(){let{line:e}=this,{text:t,end:r}=this.scanLine(this.absoluteLineStart);for(this.absoluteLineEnd=r,e.reset(t);e.depth<this.stack.length;e.depth++){let i=this.stack[e.depth],s=this.parser.skipContextMarkup[i.type];if(!s)throw new Error("Unhandled block context "+ae[i.type]);let l=this.line.markers.length;if(!s(i,this,e)){this.line.markers.length>l&&(i.end=this.line.markers[this.line.markers.length-1].to),e.forward();break}e.forward()}}lineChunkAt(e){let t=this.input.chunk(e),r;if(this.input.lineChunks)r=t==`
@@ -476,7 +476,7 @@ Error generating stack: `+v.message+`
476
476
  `,...s.current()});return/^[\t ]/.test(h)&&(h=Sc(h.charCodeAt(0))+h.slice(1)),h=h?l+" "+h:l,t.options.closeAtx&&(h+=" "+l),u(),o(),h}rE.peek=sV;function rE(n){return n.value||""}function sV(){return"<"}iE.peek=lV;function iE(n,e,t,r){const i=V0(t),s=i==='"'?"Quote":"Apostrophe",l=t.enter("image");let o=t.enter("label");const u=t.createTracker(r);let h=u.move("![");return h+=u.move(t.safe(n.alt,{before:h,after:"]",...u.current()})),h+=u.move("]("),o(),!n.url&&n.title||/[\0- \u007F]/.test(n.url)?(o=t.enter("destinationLiteral"),h+=u.move("<"),h+=u.move(t.safe(n.url,{before:h,after:">",...u.current()})),h+=u.move(">")):(o=t.enter("destinationRaw"),h+=u.move(t.safe(n.url,{before:h,after:n.title?" ":")",...u.current()}))),o(),n.title&&(o=t.enter(`title${s}`),h+=u.move(" "+i),h+=u.move(t.safe(n.title,{before:h,after:i,...u.current()})),h+=u.move(i),o()),h+=u.move(")"),l(),h}function lV(){return"!"}sE.peek=oV;function sE(n,e,t,r){const i=n.referenceType,s=t.enter("imageReference");let l=t.enter("label");const o=t.createTracker(r);let u=o.move("![");const h=t.safe(n.alt,{before:u,after:"]",...o.current()});u+=o.move(h+"]["),l();const f=t.stack;t.stack=[],l=t.enter("reference");const p=t.safe(t.associationId(n),{before:u,after:"]",...o.current()});return l(),t.stack=f,s(),i==="full"||!h||h!==p?u+=o.move(p+"]"):i==="shortcut"?u=u.slice(0,-1):u+=o.move("]"),u}function oV(){return"!"}lE.peek=aV;function lE(n,e,t){let r=n.value||"",i="`",s=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<t.unsafe.length;){const l=t.unsafe[s],o=t.compilePattern(l);let u;if(l.atBreak)for(;u=o.exec(r);){let h=u.index;r.charCodeAt(h)===10&&r.charCodeAt(h-1)===13&&h--,r=r.slice(0,h)+" "+r.slice(u.index+1)}}return i+r+i}function aV(){return"`"}function oE(n,e){const t=_0(n);return!!(!e.options.resourceLink&&n.url&&!n.title&&n.children&&n.children.length===1&&n.children[0].type==="text"&&(t===n.url||"mailto:"+t===n.url)&&/^[a-z][a-z+.-]+:/i.test(n.url)&&!/[\0- <>\u007F]/.test(n.url))}aE.peek=uV;function aE(n,e,t,r){const i=V0(t),s=i==='"'?"Quote":"Apostrophe",l=t.createTracker(r);let o,u;if(oE(n,t)){const f=t.stack;t.stack=[],o=t.enter("autolink");let p=l.move("<");return p+=l.move(t.containerPhrasing(n,{before:p,after:">",...l.current()})),p+=l.move(">"),o(),t.stack=f,p}o=t.enter("link"),u=t.enter("label");let h=l.move("[");return h+=l.move(t.containerPhrasing(n,{before:h,after:"](",...l.current()})),h+=l.move("]("),u(),!n.url&&n.title||/[\0- \u007F]/.test(n.url)?(u=t.enter("destinationLiteral"),h+=l.move("<"),h+=l.move(t.safe(n.url,{before:h,after:">",...l.current()})),h+=l.move(">")):(u=t.enter("destinationRaw"),h+=l.move(t.safe(n.url,{before:h,after:n.title?" ":")",...l.current()}))),u(),n.title&&(u=t.enter(`title${s}`),h+=l.move(" "+i),h+=l.move(t.safe(n.title,{before:h,after:i,...l.current()})),h+=l.move(i),u()),h+=l.move(")"),o(),h}function uV(n,e,t){return oE(n,t)?"<":"["}uE.peek=cV;function uE(n,e,t,r){const i=n.referenceType,s=t.enter("linkReference");let l=t.enter("label");const o=t.createTracker(r);let u=o.move("[");const h=t.containerPhrasing(n,{before:u,after:"]",...o.current()});u+=o.move(h+"]["),l();const f=t.stack;t.stack=[],l=t.enter("reference");const p=t.safe(t.associationId(n),{before:u,after:"]",...o.current()});return l(),t.stack=f,s(),i==="full"||!h||h!==p?u+=o.move(p+"]"):i==="shortcut"?u=u.slice(0,-1):u+=o.move("]"),u}function cV(){return"["}function F0(n){const e=n.options.bullet||"*";if(e!=="*"&&e!=="+"&&e!=="-")throw new Error("Cannot serialize items with `"+e+"` for `options.bullet`, expected `*`, `+`, or `-`");return e}function hV(n){const e=F0(n),t=n.options.bulletOther;if(!t)return e==="*"?"-":"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(t===e)throw new Error("Expected `bullet` (`"+e+"`) and `bulletOther` (`"+t+"`) to be different");return t}function fV(n){const e=n.options.bulletOrdered||".";if(e!=="."&&e!==")")throw new Error("Cannot serialize items with `"+e+"` for `options.bulletOrdered`, expected `.` or `)`");return e}function cE(n){const e=n.options.rule||"*";if(e!=="*"&&e!=="-"&&e!=="_")throw new Error("Cannot serialize rules with `"+e+"` for `options.rule`, expected `*`, `-`, or `_`");return e}function dV(n,e,t,r){const i=t.enter("list"),s=t.bulletCurrent;let l=n.ordered?fV(t):F0(t);const o=n.ordered?l==="."?")":".":hV(t);let u=e&&t.bulletLastUsed?l===t.bulletLastUsed:!1;if(!n.ordered){const f=n.children?n.children[0]:void 0;if((l==="*"||l==="-")&&f&&(!f.children||!f.children[0])&&t.stack[t.stack.length-1]==="list"&&t.stack[t.stack.length-2]==="listItem"&&t.stack[t.stack.length-3]==="list"&&t.stack[t.stack.length-4]==="listItem"&&t.indexStack[t.indexStack.length-1]===0&&t.indexStack[t.indexStack.length-2]===0&&t.indexStack[t.indexStack.length-3]===0&&(u=!0),cE(t)===l&&f){let p=-1;for(;++p<n.children.length;){const g=n.children[p];if(g&&g.type==="listItem"&&g.children&&g.children[0]&&g.children[0].type==="thematicBreak"){u=!0;break}}}}u&&(l=o),t.bulletCurrent=l;const h=t.containerFlow(n,r);return t.bulletLastUsed=l,t.bulletCurrent=s,i(),h}function pV(n){const e=n.options.listItemIndent||"one";if(e!=="tab"&&e!=="one"&&e!=="mixed")throw new Error("Cannot serialize items with `"+e+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return e}function mV(n,e,t,r){const i=pV(t);let s=t.bulletCurrent||F0(t);e&&e.type==="list"&&e.ordered&&(s=(typeof e.start=="number"&&e.start>-1?e.start:1)+(t.options.incrementListMarker===!1?0:e.children.indexOf(n))+s);let l=s.length+1;(i==="tab"||i==="mixed"&&(e&&e.type==="list"&&e.spread||n.spread))&&(l=Math.ceil(l/4)*4);const o=t.createTracker(r);o.move(s+" ".repeat(l-s.length)),o.shift(l);const u=t.enter("listItem"),h=t.indentLines(t.containerFlow(n,o.current()),f);return u(),h;function f(p,g,x){return g?(x?"":" ".repeat(l))+p:(x?s:s+" ".repeat(l-s.length))+p}}function gV(n,e,t,r){const i=t.enter("paragraph"),s=t.enter("phrasing"),l=t.containerPhrasing(n,r);return s(),i(),l}const OV=gp(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function xV(n,e,t,r){return(n.children.some(function(l){return OV(l)})?t.containerPhrasing:t.containerFlow).call(t,n,r)}function yV(n){const e=n.options.strong||"*";if(e!=="*"&&e!=="_")throw new Error("Cannot serialize strong with `"+e+"` for `options.strong`, expected `*`, or `_`");return e}hE.peek=kV;function hE(n,e,t,r){const i=yV(t),s=t.enter("strong"),l=t.createTracker(r),o=l.move(i+i);let u=l.move(t.containerPhrasing(n,{after:i,before:o,...l.current()}));const h=u.charCodeAt(0),f=Xd(r.before.charCodeAt(r.before.length-1),h,i);f.inside&&(u=Sc(h)+u.slice(1));const p=u.charCodeAt(u.length-1),g=Xd(r.after.charCodeAt(0),p,i);g.inside&&(u=u.slice(0,-1)+Sc(p));const x=l.move(i+i);return s(),t.attentionEncodeSurroundingInfo={after:g.outside,before:f.outside},o+u+x}function kV(n,e,t){return t.options.strong||"*"}function vV(n,e,t,r){return t.safe(n.value,r)}function bV(n){const e=n.options.ruleRepetition||3;if(e<3)throw new Error("Cannot serialize rules with repetition `"+e+"` for `options.ruleRepetition`, expected `3` or more");return e}function wV(n,e,t){const r=(cE(t)+(t.options.ruleSpaces?" ":"")).repeat(bV(t));return t.options.ruleSpaces?r.slice(0,-1):r}const fE={blockquote:V8,break:_P,code:K8,definition:eV,emphasis:nE,hardBreak:_P,heading:iV,html:rE,image:iE,imageReference:sE,inlineCode:lE,link:aE,linkReference:uE,list:dV,listItem:mV,paragraph:gV,root:xV,strong:hE,text:vV,thematicBreak:wV};function SV(){return{enter:{table:PV,tableData:DP,tableHeader:DP,tableRow:QV},exit:{codeText:$V,table:CV,tableData:wO,tableHeader:wO,tableRow:wO}}}function PV(n){const e=n._align;this.enter({type:"table",align:e.map(function(t){return t==="none"?null:t}),children:[]},n),this.data.inTable=!0}function CV(n){this.exit(n),this.data.inTable=void 0}function QV(n){this.enter({type:"tableRow",children:[]},n)}function wO(n){this.exit(n)}function DP(n){this.enter({type:"tableCell",children:[]},n)}function $V(n){let e=this.resume();this.data.inTable&&(e=e.replace(/\\([\\|])/g,TV));const t=this.stack[this.stack.length-1];t.type,t.value=e,this.exit(n)}function TV(n,e){return e==="|"?e:n}function jV(n){const e=n||{},t=e.tableCellPadding,r=e.tablePipeAlign,i=e.stringLength,s=t?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
477
477
  `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:g,table:l,tableCell:u,tableRow:o}};function l(x,k,b,w){return h(f(x,b,w),x.align)}function o(x,k,b,w){const S=p(x,b,w),Q=h([S]);return Q.slice(0,Q.indexOf(`
478
478
  `))}function u(x,k,b,w){const S=b.enter("tableCell"),Q=b.enter("phrasing"),$=b.containerPhrasing(x,{...w,before:s,after:s});return Q(),S(),$}function h(x,k){return W8(x,{align:k,alignDelimiters:r,padding:t,stringLength:i})}function f(x,k,b){const w=x.children;let S=-1;const Q=[],$=k.enter("table");for(;++S<w.length;)Q[S]=p(w[S],k,b);return $(),Q}function p(x,k,b){const w=x.children;let S=-1;const Q=[],$=k.enter("tableRow");for(;++S<w.length;)Q[S]=u(w[S],x,k,b);return $(),Q}function g(x,k,b){let w=fE.inlineCode(x,k,b);return b.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function EV(){return{exit:{taskListCheckValueChecked:IP,taskListCheckValueUnchecked:IP,paragraph:AV}}}function MV(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:RV}}}function IP(n){const e=this.stack[this.stack.length-2];e.type,e.checked=n.type==="taskListCheckValueChecked"}function AV(n){const e=this.stack[this.stack.length-2];if(e&&e.type==="listItem"&&typeof e.checked=="boolean"){const t=this.stack[this.stack.length-1];t.type;const r=t.children[0];if(r&&r.type==="text"){const i=e.children;let s=-1,l;for(;++s<i.length;){const o=i[s];if(o.type==="paragraph"){l=o;break}}l===t&&(r.value=r.value.slice(1),r.value.length===0?t.children.shift():t.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,t.position.start=Object.assign({},r.position.start)))}}this.exit(n)}function RV(n,e,t,r){const i=n.children[0],s=typeof n.checked=="boolean"&&i&&i.type==="paragraph",l="["+(n.checked?"x":" ")+"] ",o=t.createTracker(r);s&&o.move(l);let u=fE.listItem(n,e,t,{...r,...o.current()});return s&&(u=u.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,h)),u;function h(f){return f+l}}function NV(){return[d8(),R8(),D8(),SV(),EV()]}function LV(n){return{extensions:[p8(),N8(n),I8(),jV(n),MV()]}}const _V={tokenize:BV,partial:!0},dE={tokenize:WV,partial:!0},pE={tokenize:qV,partial:!0},mE={tokenize:VV,partial:!0},DV={tokenize:FV,partial:!0},gE={name:"wwwAutolink",tokenize:ZV,previous:xE},OE={name:"protocolAutolink",tokenize:XV,previous:yE},Hi={name:"emailAutolink",tokenize:zV,previous:kE},wi={};function IV(){return{text:wi}}let gl=48;for(;gl<123;)wi[gl]=Hi,gl++,gl===58?gl=65:gl===91&&(gl=97);wi[43]=Hi;wi[45]=Hi;wi[46]=Hi;wi[95]=Hi;wi[72]=[Hi,OE];wi[104]=[Hi,OE];wi[87]=[Hi,gE];wi[119]=[Hi,gE];function zV(n,e,t){const r=this;let i,s;return l;function l(p){return!fy(p)||!kE.call(r,r.previous)||Y0(r.events)?t(p):(n.enter("literalAutolink"),n.enter("literalAutolinkEmail"),o(p))}function o(p){return fy(p)?(n.consume(p),o):p===64?(n.consume(p),u):t(p)}function u(p){return p===46?n.check(DV,f,h)(p):p===45||p===95||mn(p)?(s=!0,n.consume(p),u):f(p)}function h(p){return n.consume(p),i=!0,u}function f(p){return s&&i&&Qn(r.previous)?(n.exit("literalAutolinkEmail"),n.exit("literalAutolink"),e(p)):t(p)}}function ZV(n,e,t){const r=this;return i;function i(l){return l!==87&&l!==119||!xE.call(r,r.previous)||Y0(r.events)?t(l):(n.enter("literalAutolink"),n.enter("literalAutolinkWww"),n.check(_V,n.attempt(dE,n.attempt(pE,s),t),t)(l))}function s(l){return n.exit("literalAutolinkWww"),n.exit("literalAutolink"),e(l)}}function XV(n,e,t){const r=this;let i="",s=!1;return l;function l(p){return(p===72||p===104)&&yE.call(r,r.previous)&&!Y0(r.events)?(n.enter("literalAutolink"),n.enter("literalAutolinkHttp"),i+=String.fromCodePoint(p),n.consume(p),o):t(p)}function o(p){if(Qn(p)&&i.length<5)return i+=String.fromCodePoint(p),n.consume(p),o;if(p===58){const g=i.toLowerCase();if(g==="http"||g==="https")return n.consume(p),u}return t(p)}function u(p){return p===47?(n.consume(p),s?h:(s=!0,u)):t(p)}function h(p){return p===null||Id(p)||ft(p)||Wl(p)||dp(p)?t(p):n.attempt(dE,n.attempt(pE,f),t)(p)}function f(p){return n.exit("literalAutolinkHttp"),n.exit("literalAutolink"),e(p)}}function BV(n,e,t){let r=0;return i;function i(l){return(l===87||l===119)&&r<3?(r++,n.consume(l),i):l===46&&r===3?(n.consume(l),s):t(l)}function s(l){return l===null?t(l):e(l)}}function WV(n,e,t){let r,i,s;return l;function l(h){return h===46||h===95?n.check(mE,u,o)(h):h===null||ft(h)||Wl(h)||h!==45&&dp(h)?u(h):(s=!0,n.consume(h),l)}function o(h){return h===95?r=!0:(i=r,r=void 0),n.consume(h),l}function u(h){return i||r||!s?t(h):e(h)}}function qV(n,e){let t=0,r=0;return i;function i(l){return l===40?(t++,n.consume(l),i):l===41&&r<t?s(l):l===33||l===34||l===38||l===39||l===41||l===42||l===44||l===46||l===58||l===59||l===60||l===63||l===93||l===95||l===126?n.check(mE,e,s)(l):l===null||ft(l)||Wl(l)?e(l):(n.consume(l),i)}function s(l){return l===41&&r++,n.consume(l),i}}function VV(n,e,t){return r;function r(o){return o===33||o===34||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===63||o===95||o===126?(n.consume(o),r):o===38?(n.consume(o),s):o===93?(n.consume(o),i):o===60||o===null||ft(o)||Wl(o)?e(o):t(o)}function i(o){return o===null||o===40||o===91||ft(o)||Wl(o)?e(o):r(o)}function s(o){return Qn(o)?l(o):t(o)}function l(o){return o===59?(n.consume(o),r):Qn(o)?(n.consume(o),l):t(o)}}function FV(n,e,t){return r;function r(s){return n.consume(s),i}function i(s){return mn(s)?t(s):e(s)}}function xE(n){return n===null||n===40||n===42||n===95||n===91||n===93||n===126||ft(n)}function yE(n){return!Qn(n)}function kE(n){return!(n===47||fy(n))}function fy(n){return n===43||n===45||n===46||n===95||mn(n)}function Y0(n){let e=n.length,t=!1;for(;e--;){const r=n[e][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){t=!0;break}if(r._gfmAutolinkLiteralWalkedInto){t=!1;break}}return n.length>0&&!t&&(n[n.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),t}const YV={tokenize:nF,partial:!0};function UV(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:JV,continuation:{tokenize:eF},exit:tF}},text:{91:{name:"gfmFootnoteCall",tokenize:KV},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:GV,resolveTo:HV}}}}function GV(n,e,t){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let l;for(;i--;){const u=r.events[i][1];if(u.type==="labelImage"){l=u;break}if(u.type==="gfmFootnoteCall"||u.type==="labelLink"||u.type==="label"||u.type==="image"||u.type==="link")break}return o;function o(u){if(!l||!l._balanced)return t(u);const h=Br(r.sliceSerialize({start:l.end,end:r.now()}));return h.codePointAt(0)!==94||!s.includes(h.slice(1))?t(u):(n.enter("gfmFootnoteCallLabelMarker"),n.consume(u),n.exit("gfmFootnoteCallLabelMarker"),e(u))}}function HV(n,e){let t=n.length;for(;t--;)if(n[t][1].type==="labelImage"&&n[t][0]==="enter"){n[t][1];break}n[t+1][1].type="data",n[t+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},n[t+3][1].start),end:Object.assign({},n[n.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},n[t+3][1].end),end:Object.assign({},n[t+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},n[n.length-1][1].start)},l={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},o=[n[t+1],n[t+2],["enter",r,e],n[t+3],n[t+4],["enter",i,e],["exit",i,e],["enter",s,e],["enter",l,e],["exit",l,e],["exit",s,e],n[n.length-2],n[n.length-1],["exit",r,e]];return n.splice(t,n.length-t+1,...o),n}function KV(n,e,t){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,l;return o;function o(p){return n.enter("gfmFootnoteCall"),n.enter("gfmFootnoteCallLabelMarker"),n.consume(p),n.exit("gfmFootnoteCallLabelMarker"),u}function u(p){return p!==94?t(p):(n.enter("gfmFootnoteCallMarker"),n.consume(p),n.exit("gfmFootnoteCallMarker"),n.enter("gfmFootnoteCallString"),n.enter("chunkString").contentType="string",h)}function h(p){if(s>999||p===93&&!l||p===null||p===91||ft(p))return t(p);if(p===93){n.exit("chunkString");const g=n.exit("gfmFootnoteCallString");return i.includes(Br(r.sliceSerialize(g)))?(n.enter("gfmFootnoteCallLabelMarker"),n.consume(p),n.exit("gfmFootnoteCallLabelMarker"),n.exit("gfmFootnoteCall"),e):t(p)}return ft(p)||(l=!0),s++,n.consume(p),p===92?f:h}function f(p){return p===91||p===92||p===93?(n.consume(p),s++,h):h(p)}}function JV(n,e,t){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,l=0,o;return u;function u(k){return n.enter("gfmFootnoteDefinition")._container=!0,n.enter("gfmFootnoteDefinitionLabel"),n.enter("gfmFootnoteDefinitionLabelMarker"),n.consume(k),n.exit("gfmFootnoteDefinitionLabelMarker"),h}function h(k){return k===94?(n.enter("gfmFootnoteDefinitionMarker"),n.consume(k),n.exit("gfmFootnoteDefinitionMarker"),n.enter("gfmFootnoteDefinitionLabelString"),n.enter("chunkString").contentType="string",f):t(k)}function f(k){if(l>999||k===93&&!o||k===null||k===91||ft(k))return t(k);if(k===93){n.exit("chunkString");const b=n.exit("gfmFootnoteDefinitionLabelString");return s=Br(r.sliceSerialize(b)),n.enter("gfmFootnoteDefinitionLabelMarker"),n.consume(k),n.exit("gfmFootnoteDefinitionLabelMarker"),n.exit("gfmFootnoteDefinitionLabel"),g}return ft(k)||(o=!0),l++,n.consume(k),k===92?p:f}function p(k){return k===91||k===92||k===93?(n.consume(k),l++,f):f(k)}function g(k){return k===58?(n.enter("definitionMarker"),n.consume(k),n.exit("definitionMarker"),i.includes(s)||i.push(s),He(n,x,"gfmFootnoteDefinitionWhitespace")):t(k)}function x(k){return e(k)}}function eF(n,e,t){return n.check(Vc,e,n.attempt(YV,e,t))}function tF(n){n.exit("gfmFootnoteDefinition")}function nF(n,e,t){const r=this;return He(n,i,"gfmFootnoteDefinitionIndent",5);function i(s){const l=r.events[r.events.length-1];return l&&l[1].type==="gfmFootnoteDefinitionIndent"&&l[2].sliceSerialize(l[1],!0).length===4?e(s):t(s)}}function rF(n){let t=(n||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return t==null&&(t=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(l,o){let u=-1;for(;++u<l.length;)if(l[u][0]==="enter"&&l[u][1].type==="strikethroughSequenceTemporary"&&l[u][1]._close){let h=u;for(;h--;)if(l[h][0]==="exit"&&l[h][1].type==="strikethroughSequenceTemporary"&&l[h][1]._open&&l[u][1].end.offset-l[u][1].start.offset===l[h][1].end.offset-l[h][1].start.offset){l[u][1].type="strikethroughSequence",l[h][1].type="strikethroughSequence";const f={type:"strikethrough",start:Object.assign({},l[h][1].start),end:Object.assign({},l[u][1].end)},p={type:"strikethroughText",start:Object.assign({},l[h][1].end),end:Object.assign({},l[u][1].start)},g=[["enter",f,o],["enter",l[h][1],o],["exit",l[h][1],o],["enter",p,o]],x=o.parser.constructs.insideSpan.null;x&&fr(g,g.length,0,pp(x,l.slice(h+1,u),o)),fr(g,g.length,0,[["exit",p,o],["enter",l[u][1],o],["exit",l[u][1],o],["exit",f,o]]),fr(l,h-1,u-h+3,g),u=h+g.length-2;break}}for(u=-1;++u<l.length;)l[u][1].type==="strikethroughSequenceTemporary"&&(l[u][1].type="data");return l}function s(l,o,u){const h=this.previous,f=this.events;let p=0;return g;function g(k){return h===126&&f[f.length-1][1].type!=="characterEscape"?u(k):(l.enter("strikethroughSequenceTemporary"),x(k))}function x(k){const b=ma(h);if(k===126)return p>1?u(k):(l.consume(k),p++,x);if(p<2&&!t)return u(k);const w=l.exit("strikethroughSequenceTemporary"),S=ma(k);return w._open=!S||S===2&&!!b,w._close=!b||b===2&&!!S,o(k)}}}class iF{constructor(){this.map=[]}add(e,t,r){sF(this,e,t,r)}consume(e){if(this.map.sort(function(s,l){return s[0]-l[0]}),this.map.length===0)return;let t=this.map.length;const r=[];for(;t>0;)t-=1,r.push(e.slice(this.map[t][0]+this.map[t][1]),this.map[t][2]),e.length=this.map[t][0];r.push(e.slice()),e.length=0;let i=r.pop();for(;i;){for(const s of i)e.push(s);i=r.pop()}this.map.length=0}}function sF(n,e,t,r){let i=0;if(!(t===0&&r.length===0)){for(;i<n.map.length;){if(n.map[i][0]===e){n.map[i][1]+=t,n.map[i][2].push(...r);return}i+=1}n.map.push([e,t,r])}}function lF(n,e){let t=!1;const r=[];for(;e<n.length;){const i=n[e];if(t){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(n[e+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(n[e-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(t=!0);e+=1}return r}function oF(){return{flow:{null:{name:"table",tokenize:aF,resolveAll:uF}}}}function aF(n,e,t){const r=this;let i=0,s=0,l;return o;function o(N){let U=r.events.length-1;for(;U>-1;){const K=r.events[U][1].type;if(K==="lineEnding"||K==="linePrefix")U--;else break}const V=U>-1?r.events[U][1].type:null,se=V==="tableHead"||V==="tableRow"?T:u;return se===T&&r.parser.lazy[r.now().line]?t(N):se(N)}function u(N){return n.enter("tableHead"),n.enter("tableRow"),h(N)}function h(N){return N===124||(l=!0,s+=1),f(N)}function f(N){return N===null?t(N):Ee(N)?s>1?(s=0,r.interrupt=!0,n.exit("tableRow"),n.enter("lineEnding"),n.consume(N),n.exit("lineEnding"),x):t(N):qe(N)?He(n,f,"whitespace")(N):(s+=1,l&&(l=!1,i+=1),N===124?(n.enter("tableCellDivider"),n.consume(N),n.exit("tableCellDivider"),l=!0,f):(n.enter("data"),p(N)))}function p(N){return N===null||N===124||ft(N)?(n.exit("data"),f(N)):(n.consume(N),N===92?g:p)}function g(N){return N===92||N===124?(n.consume(N),p):p(N)}function x(N){return r.interrupt=!1,r.parser.lazy[r.now().line]?t(N):(n.enter("tableDelimiterRow"),l=!1,qe(N)?He(n,k,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(N):k(N))}function k(N){return N===45||N===58?w(N):N===124?(l=!0,n.enter("tableCellDivider"),n.consume(N),n.exit("tableCellDivider"),b):I(N)}function b(N){return qe(N)?He(n,w,"whitespace")(N):w(N)}function w(N){return N===58?(s+=1,l=!0,n.enter("tableDelimiterMarker"),n.consume(N),n.exit("tableDelimiterMarker"),S):N===45?(s+=1,S(N)):N===null||Ee(N)?R(N):I(N)}function S(N){return N===45?(n.enter("tableDelimiterFiller"),Q(N)):I(N)}function Q(N){return N===45?(n.consume(N),Q):N===58?(l=!0,n.exit("tableDelimiterFiller"),n.enter("tableDelimiterMarker"),n.consume(N),n.exit("tableDelimiterMarker"),$):(n.exit("tableDelimiterFiller"),$(N))}function $(N){return qe(N)?He(n,R,"whitespace")(N):R(N)}function R(N){return N===124?k(N):N===null||Ee(N)?!l||i!==s?I(N):(n.exit("tableDelimiterRow"),n.exit("tableHead"),e(N)):I(N)}function I(N){return t(N)}function T(N){return n.enter("tableRow"),X(N)}function X(N){return N===124?(n.enter("tableCellDivider"),n.consume(N),n.exit("tableCellDivider"),X):N===null||Ee(N)?(n.exit("tableRow"),e(N)):qe(N)?He(n,X,"whitespace")(N):(n.enter("data"),Z(N))}function Z(N){return N===null||N===124||ft(N)?(n.exit("data"),X(N)):(n.consume(N),N===92?H:Z)}function H(N){return N===92||N===124?(n.consume(N),Z):Z(N)}}function uF(n,e){let t=-1,r=!0,i=0,s=[0,0,0,0],l=[0,0,0,0],o=!1,u=0,h,f,p;const g=new iF;for(;++t<n.length;){const x=n[t],k=x[1];x[0]==="enter"?k.type==="tableHead"?(o=!1,u!==0&&(zP(g,e,u,h,f),f=void 0,u=0),h={type:"table",start:Object.assign({},k.start),end:Object.assign({},k.end)},g.add(t,0,[["enter",h,e]])):k.type==="tableRow"||k.type==="tableDelimiterRow"?(r=!0,p=void 0,s=[0,0,0,0],l=[0,t+1,0,0],o&&(o=!1,f={type:"tableBody",start:Object.assign({},k.start),end:Object.assign({},k.end)},g.add(t,0,[["enter",f,e]])),i=k.type==="tableDelimiterRow"?2:f?3:1):i&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")?(r=!1,l[2]===0&&(s[1]!==0&&(l[0]=l[1],p=Nf(g,e,s,i,void 0,p),s=[0,0,0,0]),l[2]=t)):k.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(l[0]=l[1],p=Nf(g,e,s,i,void 0,p)),s=l,l=[s[1],t,0,0])):k.type==="tableHead"?(o=!0,u=t):k.type==="tableRow"||k.type==="tableDelimiterRow"?(u=t,s[1]!==0?(l[0]=l[1],p=Nf(g,e,s,i,t,p)):l[1]!==0&&(p=Nf(g,e,l,i,t,p)),i=0):i&&(k.type==="data"||k.type==="tableDelimiterMarker"||k.type==="tableDelimiterFiller")&&(l[3]=t)}for(u!==0&&zP(g,e,u,h,f),g.consume(e.events),t=-1;++t<e.events.length;){const x=e.events[t];x[0]==="enter"&&x[1].type==="table"&&(x[1]._align=lF(e.events,t))}return n}function Nf(n,e,t,r,i,s){const l=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",o="tableContent";t[0]!==0&&(s.end=Object.assign({},Eo(e.events,t[0])),n.add(t[0],0,[["exit",s,e]]));const u=Eo(e.events,t[1]);if(s={type:l,start:Object.assign({},u),end:Object.assign({},u)},n.add(t[1],0,[["enter",s,e]]),t[2]!==0){const h=Eo(e.events,t[2]),f=Eo(e.events,t[3]),p={type:o,start:Object.assign({},h),end:Object.assign({},f)};if(n.add(t[2],0,[["enter",p,e]]),r!==2){const g=e.events[t[2]],x=e.events[t[3]];if(g[1].end=Object.assign({},x[1].end),g[1].type="chunkText",g[1].contentType="text",t[3]>t[2]+1){const k=t[2]+1,b=t[3]-t[2]-1;n.add(k,b,[])}}n.add(t[3]+1,0,[["exit",p,e]])}return i!==void 0&&(s.end=Object.assign({},Eo(e.events,i)),n.add(i,0,[["exit",s,e]]),s=void 0),s}function zP(n,e,t,r,i){const s=[],l=Eo(e.events,t);i&&(i.end=Object.assign({},l),s.push(["exit",i,e])),r.end=Object.assign({},l),s.push(["exit",r,e]),n.add(t+1,0,s)}function Eo(n,e){const t=n[e],r=t[0]==="enter"?"start":"end";return t[1][r]}const cF={name:"tasklistCheck",tokenize:fF};function hF(){return{text:{91:cF}}}function fF(n,e,t){const r=this;return i;function i(u){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?t(u):(n.enter("taskListCheck"),n.enter("taskListCheckMarker"),n.consume(u),n.exit("taskListCheckMarker"),s)}function s(u){return ft(u)?(n.enter("taskListCheckValueUnchecked"),n.consume(u),n.exit("taskListCheckValueUnchecked"),l):u===88||u===120?(n.enter("taskListCheckValueChecked"),n.consume(u),n.exit("taskListCheckValueChecked"),l):t(u)}function l(u){return u===93?(n.enter("taskListCheckMarker"),n.consume(u),n.exit("taskListCheckMarker"),n.exit("taskListCheck"),o):t(u)}function o(u){return Ee(u)?e(u):qe(u)?n.check({tokenize:dF},e,t)(u):t(u)}}function dF(n,e,t){return He(n,r,"whitespace");function r(i){return i===null?t(i):e(i)}}function pF(n){return jj([IV(),UV(),rF(n),oF(),hF()])}const mF={};function vE(n){const e=this,t=n||mF,r=e.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),l=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(pF(t)),s.push(NV()),l.push(LV(t))}const gF="",bE="/login",OF=new Set(["/v1/auth/login","/v1/auth/logout","/v1/auth/whoami","/health"]);function xF(n){if(typeof window>"u"||window.location.pathname===bE)return!1;for(const e of OF)if(n.startsWith(e))return!1;return!0}async function Ze(n,e){const t=new Headers(e==null?void 0:e.headers);(e==null?void 0:e.body)!==void 0&&(e==null?void 0:e.body)!==null&&!t.has("content-type")&&t.set("content-type","application/json");const r=await fetch(`${gF}${n}`,{...e,credentials:"include",headers:t});if(r.status===401&&xF(n)){const i=window.location.pathname+window.location.search;throw window.location.href=`${bE}?next=${encodeURIComponent(i)}`,new Error("unauthenticated")}if(!r.ok){let i="";try{i=await r.text()}catch{}throw new Error(`${(e==null?void 0:e.method)??"GET"} ${n} -> ${r.status} ${i}`)}if(r.status!==204)return await r.json()}const Ve={health:()=>Ze("/health"),listProjects:(n={})=>{const e=new URLSearchParams;n.includeArchived&&e.set("includeArchived","true");const t=e.size?`?${e.toString()}`:"";return Ze(`/v1/projects${t}`)},getProject:n=>Ze(`/v1/projects/${n}`),getProjectByKey:n=>Ze(`/v1/projects/by-key/${encodeURIComponent(n)}`),createProject:n=>Ze("/v1/projects",{method:"POST",body:JSON.stringify(n)}),updateProject:(n,e)=>Ze(`/v1/projects/${n}`,{method:"PATCH",body:JSON.stringify(e)}),openingBrief:(n,e=10)=>Ze(`/v1/projects/${n}/opening-brief`,{method:"POST",body:JSON.stringify({recentLimit:e})}),getEntity:n=>Ze(`/v1/entities/${n}`),getEntityByKey:(n,e)=>Ze(`/v1/projects/by-key/${encodeURIComponent(n)}/entities/by-seq/${e}`),createTask:n=>Ze("/v1/tasks",{method:"POST",body:JSON.stringify(n)}),createNote:n=>Ze("/v1/notes",{method:"POST",body:JSON.stringify(n)}),writeEntity:n=>{if(n.kind==="task"){const{kind:r,...i}=n;return Ze("/v1/tasks",{method:"POST",body:JSON.stringify(i)})}const{kind:e,...t}=n;return Ze("/v1/notes",{method:"POST",body:JSON.stringify(t)})},updateEntity:(n,e)=>Ze(`/v1/entities/${n}`,{method:"PATCH",body:JSON.stringify(e)}),deleteEntity:n=>Ze(`/v1/entities/${n}`,{method:"DELETE"}),purgeEntity:n=>Ze(`/v1/entities/${n}?purge=true`,{method:"DELETE"}),restoreEntity:n=>Ze(`/v1/entities/${n}/restore`,{method:"POST"}),listTrash:(n=100)=>Ze(`/v1/trash?limit=${n}`),relatedEntities:n=>Ze(`/v1/entities/${n}/related`),recent:(n={})=>Ze("/v1/recent",{method:"POST",body:JSON.stringify(n)}),search:n=>Ze("/v1/search",{method:"POST",body:JSON.stringify(n)}),listFeedback:(n={})=>{const e=new URLSearchParams;n.category&&e.set("category",n.category),n.status&&e.set("status",n.status),n.limit&&e.set("limit",String(n.limit));const t=e.size?`?${e.toString()}`:"";return Ze(`/v1/feedback${t}`)},getEmbeddingSettings:()=>Ze("/v1/settings/embedding"),updateEmbeddingSettings:n=>Ze("/v1/settings/embedding",{method:"PATCH",body:JSON.stringify(n)}),backfillEmbeddings:n=>Ze("/v1/settings/embedding/backfill",{method:"POST",body:JSON.stringify(n==null?{}:{limit:n})}),getWorkspaceSettings:()=>Ze("/v1/settings/workspace"),updateWorkspaceSettings:n=>Ze("/v1/settings/workspace",{method:"PATCH",body:JSON.stringify(n)}),tasksRange:n=>Ze("/v1/tasks/range",{method:"POST",body:JSON.stringify(n)}),configureRecurrence:(n,e)=>Ze(`/v1/tasks/${n}/recurrence`,{method:"POST",body:JSON.stringify(e)}),getRecurrence:n=>Ze(`/v1/tasks/${n}/recurrence`),skipOccurrence:(n,e)=>Ze(`/v1/tasks/${n}/skip-occurrence`,{method:"POST",body:JSON.stringify(e?{reason:e,actorKind:"human"}:{actorKind:"human"})}),stopRecurrence:(n,e)=>Ze(`/v1/recurrences/${n}/stop`,{method:"POST",body:JSON.stringify(e?{reason:e}:{})}),splitRecurrence:(n,e)=>Ze(`/v1/recurrences/${n}/split`,{method:"POST",body:JSON.stringify(e)}),listTokens:()=>Ze("/v1/tokens"),createToken:n=>Ze("/v1/tokens",{method:"POST",body:JSON.stringify({name:n})}),revokeToken:n=>Ze(`/v1/tokens/${n}`,{method:"DELETE"}),login:n=>Ze("/v1/auth/login",{method:"POST",body:JSON.stringify({password:n})}),logout:()=>Ze("/v1/auth/logout",{method:"POST"}),whoami:()=>Ze("/v1/auth/whoami")},Yc=3e4;function yF(){return On({queryKey:["health"],queryFn:Ve.health,staleTime:5*6e4})}function Vn(n={}){const e=!!n.includeArchived;return On({queryKey:["projects",e],queryFn:()=>Ve.listProjects({includeArchived:e})})}function kF(n){return On({queryKey:["project",n],queryFn:()=>Ve.getProject(n),enabled:!!n})}function wE(n){return On({queryKey:["project","by-key",n],queryFn:()=>Ve.getProjectByKey(n),enabled:!!n})}function ZP(n){return On({queryKey:["entity",n],queryFn:()=>Ve.getEntity(n),enabled:!!n})}function vF(n){return On({queryKey:["related",n],queryFn:()=>Ve.relatedEntities(n),enabled:!!n})}function bF(n,e={}){return On({queryKey:["recent",n],queryFn:()=>Ve.recent(n),refetchInterval:e.poll===!1?!1:Yc})}function U0(n,e,t={}){return On({queryKey:["entity-list",n,e],queryFn:()=>Ve.recent({projectId:n??null,kinds:e??null,limit:100}),enabled:!!n,refetchInterval:t.poll===!1?!1:Yc})}function SE(n){return On({queryKey:["search",n],queryFn:()=>Ve.search(n),enabled:!!(n&&n.query.length>0)})}function wF(n={},e={}){return On({queryKey:["feedback",n],queryFn:()=>Ve.listFeedback(n),refetchInterval:e.poll===!1?!1:Yc})}function PE(n=100){return On({queryKey:["trash",n],queryFn:()=>Ve.listTrash(n)})}const SF=[["trash"],["tasks-range"],["recent"],["entity-list"],["feedback"]];function PF(){const n=It();return xn({mutationFn:e=>Ve.restoreEntity(e),onSuccess:()=>{for(const e of SF)n.invalidateQueries({queryKey:e})}})}function CF(){const n=It();return xn({mutationFn:e=>Ve.purgeEntity(e),onSuccess:()=>{n.invalidateQueries({queryKey:["trash"]})}})}function QF(){return On({queryKey:["settings","embedding"],queryFn:Ve.getEmbeddingSettings,refetchInterval:Yc})}function $F(){const n=It();return xn({mutationFn:e=>Ve.updateEmbeddingSettings(e),onSuccess:e=>{n.setQueryData(["settings","embedding"],e),n.invalidateQueries({queryKey:["health"]})}})}function TF(){const n=It();return xn({mutationFn:e=>Ve.backfillEmbeddings(e),onSuccess:e=>{n.setQueryData(["settings","embedding"],e.settings)}})}function jF(){return On({queryKey:["settings","workspace"],queryFn:Ve.getWorkspaceSettings})}function EF(){const n=It();return xn({mutationFn:e=>Ve.updateWorkspaceSettings(e),onSuccess:e=>{n.setQueryData(["settings","workspace"],e)}})}function Yl(n,e={}){return On({queryKey:["tasks-range",n],queryFn:()=>Ve.tasksRange(n),refetchInterval:e.poll===!1?!1:Yc})}function MF(n){return On({queryKey:["recurrence",n],queryFn:()=>Ve.getRecurrence(n),enabled:!!n,retry:!1})}function CE(){const n=It();return xn({mutationFn:({taskId:e,input:t})=>Ve.configureRecurrence(e,t),onSuccess:e=>{n.invalidateQueries({queryKey:["entity",e.currentOccurrenceId??void 0]}),n.invalidateQueries({queryKey:["recurrence"]}),n.invalidateQueries({queryKey:["tasks-range"]}),n.invalidateQueries({queryKey:["recent"]}),n.invalidateQueries({queryKey:["entity-list"]})}})}function AF(){const n=It();return xn({mutationFn:({taskId:e,reason:t})=>Ve.skipOccurrence(e,t),onSuccess:e=>{n.invalidateQueries({queryKey:["entity",e.skipped.id]}),e.next&&n.invalidateQueries({queryKey:["entity",e.next.id]}),n.invalidateQueries({queryKey:["recurrence"]}),n.invalidateQueries({queryKey:["tasks-range"]}),n.invalidateQueries({queryKey:["recent"]}),n.invalidateQueries({queryKey:["entity-list"]})}})}function RF(){const n=It();return xn({mutationFn:({ruleId:e,reason:t})=>Ve.stopRecurrence(e,t),onSuccess:()=>{n.invalidateQueries({queryKey:["recurrence"]}),n.invalidateQueries({queryKey:["tasks-range"]}),n.invalidateQueries({queryKey:["recent"]}),n.invalidateQueries({queryKey:["entity-list"]})}})}function NF(){const n=It();return xn({mutationFn:({ruleId:e,input:t})=>Ve.splitRecurrence(e,t),onSuccess:e=>{n.invalidateQueries({queryKey:["entity",e.currentOccurrenceId??void 0]}),n.invalidateQueries({queryKey:["recurrence"]}),n.invalidateQueries({queryKey:["tasks-range"]}),n.invalidateQueries({queryKey:["recent"]}),n.invalidateQueries({queryKey:["entity-list"]})}})}function LF(){const n=It();return xn({mutationFn:e=>Ve.createProject(e),onSuccess:()=>{n.invalidateQueries({queryKey:["projects"]})}})}function _F(){const n=It();return xn({mutationFn:({id:e,fields:t})=>Ve.updateProject(e,t),onSuccess:e=>{n.invalidateQueries({queryKey:["projects"]}),n.setQueryData(["project",e.id],e),n.invalidateQueries({queryKey:["project","by-key",e.key]}),n.invalidateQueries({queryKey:["opening-brief",e.id]})}})}function QE(){const n=It();return xn({mutationFn:e=>Ve.writeEntity(e),onSuccess:e=>{n.invalidateQueries({queryKey:["entity-list",e.projectId??void 0]}),n.invalidateQueries({queryKey:["opening-brief",e.projectId??void 0]}),n.invalidateQueries({queryKey:["recent"]}),n.invalidateQueries({queryKey:["tasks-range"]}),e.parentId&&n.invalidateQueries({queryKey:["related",e.parentId]})}})}function Js(){const n=It();return xn({mutationFn:({id:e,fields:t})=>Ve.updateEntity(e,t),onSuccess:e=>{n.invalidateQueries({queryKey:["entity",e.id]}),n.invalidateQueries({queryKey:["entity-list",e.projectId??void 0]}),n.invalidateQueries({queryKey:["opening-brief",e.projectId??void 0]}),n.invalidateQueries({queryKey:["tasks-range"]}),n.invalidateQueries({queryKey:["related"]}),e.kind==="feedback"&&n.invalidateQueries({queryKey:["feedback"]})}})}function DF(){const n=It();return xn({mutationFn:({id:e,agentsMd:t})=>Ve.updateProject(e,{agentsMd:t}),onSuccess:e=>{n.invalidateQueries({queryKey:["project","by-key",e.key]}),n.invalidateQueries({queryKey:["opening-brief",e.id]}),n.invalidateQueries({queryKey:["projects"]})}})}function IF(){return On({queryKey:["tokens"],queryFn:Ve.listTokens})}function zF(){const n=It();return xn({mutationFn:e=>Ve.createToken(e),onSuccess:()=>{n.invalidateQueries({queryKey:["tokens"]})}})}function ZF(){const n=It();return xn({mutationFn:e=>Ve.revokeToken(e),onSuccess:(e,t)=>{n.setQueryData(["tokens"],r=>(r==null?void 0:r.filter(i=>i.id!==t))??r),n.invalidateQueries({queryKey:["tokens"],refetchType:"active"})}})}const XF=["task","note","comment","feedback"],BF=["bug","feature","friction","idea"],WF=["task","note"],$E=["planned","active","watching","paused","archived"],TE=["urgent","high","medium","low","none"];function Si(){const[n,e]=Mc(),t=n.get("d"),r=M.useCallback(s=>{e(l=>{const o=new URLSearchParams(l);return o.set("d",s),o})},[e]),i=M.useCallback(()=>{e(s=>{const l=new URLSearchParams(s);return l.delete("d"),l})},[e]);return{openId:t,open:r,close:i}}function on(n){var t;if(n.title&&n.title.trim())return n.title;const e=((t=n.body.split(`
479
- `).find(r=>r.trim()))==null?void 0:t.trim())??"";return e?e.length>60?`${e.slice(0,60)}…`:e:"Untitled"}function Tr(n){return!n.title||!n.title.trim()}const jE=M.createContext(null),qF=6e3;function VF({children:n}){const[e,t]=M.useState([]),r=M.useRef(1),i=M.useRef(new Map),s=M.useCallback(u=>{const h=i.current.get(u);h&&(clearTimeout(h),i.current.delete(u)),t(f=>f.filter(p=>p.id!==u))},[]),l=M.useCallback(({duration:u=qF,...h})=>{const f=r.current++;t(p=>[...p,{...h,id:f}]),i.current.set(f,setTimeout(()=>{var p;i.current.delete(f),t(g=>g.filter(x=>x.id!==f)),(p=h.onExpire)==null||p.call(h)},u))},[]),o=M.useMemo(()=>({toasts:e,show:l,dismiss:s}),[e,l,s]);return m.jsxs(jE.Provider,{value:o,children:[n,m.jsx(FF,{})]})}function EE(){const n=M.useContext(jE);if(!n)throw new Error("useToasts must be used inside ToastsProvider");return n}function FF(){const{toasts:n,dismiss:e}=EE();return n.length===0?null:m.jsx("div",{className:"fixed bottom-4 left-1/2 -translate-x-1/2 z-[60] flex flex-col items-center gap-2",children:n.map(t=>m.jsxs("div",{className:"flex items-center gap-3 pl-3 pr-2 py-2 rounded-md bg-ink text-white text-xs shadow-modal",role:"status",children:[m.jsx("span",{className:"max-w-[60vw] truncate",children:t.message}),t.action&&m.jsx("button",{className:"shrink-0 px-2 py-0.5 rounded font-medium text-white/90 hover:text-white hover:bg-white/10",onClick:()=>{t.action.onClick(),e(t.id)},children:t.action.label}),m.jsx("button",{className:"shrink-0 px-1.5 text-white/50 hover:text-white",onClick:()=>{var r;(r=t.onExpire)==null||r.call(t),e(t.id)},"aria-label":"Dismiss",children:"×"})]},t.id))})}const XP=[["tasks-range"],["recent"],["entity-list"],["feedback"],["trash"]];function YF(n,e){if(Array.isArray(n))return n.filter(t=>t.id!==e);if(n&&typeof n=="object"&&"scheduled"in n){const t=n;return{...t,scheduled:t.scheduled.filter(r=>r.id!==e),overdue:t.overdue.filter(r=>r.id!==e),backlog:t.backlog.filter(r=>r.id!==e)}}return n}function ME(){const n=It(),{show:e}=EE(),t=M.useCallback(()=>{for(const r of XP)n.invalidateQueries({queryKey:r})},[n]);return M.useCallback(r=>{const i=[];for(const s of XP)for(const[l,o]of n.getQueriesData({queryKey:s}))o!==void 0&&(i.push([l,o]),n.setQueryData(l,YF(o,r.id)));Ve.deleteEntity(r.id).catch(()=>{for(const[s,l]of i)n.setQueryData(s,l)}),e({message:`Moved “${on(r)}” to trash`,action:{label:"Undo",onClick:()=>{Ve.restoreEntity(r.id).then(t).catch(t)}},onExpire:t})},[n,e,t])}const AE=["hourly","daily","weekly","monthly","yearly"],dy=["MO","TU","WE","TH","FR","SA","SU"];function UF(n){if(!n)return;const e=n.match(/^(\d{4})(\d{2})(\d{2})/);if(e)return`${e[1]}-${e[2]}-${e[3]}`;const t=new Date(n);return Number.isNaN(t.getTime())?void 0:t.toISOString().slice(0,10)}function RE(n){var o;const e=new Map(n.replace(/^RRULE:/i,"").split(";").map(u=>u.split("=")).filter(u=>u.length===2).map(([u,h])=>[u.toUpperCase(),h])),t=(o=e.get("FREQ"))==null?void 0:o.toLowerCase(),r=AE.includes(t)?t:void 0,i=Number(e.get("INTERVAL")??1),s=Number(e.get("COUNT")),l=(e.get("BYDAY")??"").split(",").filter(u=>dy.includes(u));return{preset:r,interval:Number.isFinite(i)&&i>0?i:1,byWeekday:l,count:Number.isFinite(s)&&s>0?s:void 0,until:UF(e.get("UNTIL"))}}const GF=["title","body","tags","priority"];function HF(n,e,t){return!e||!GF.some(i=>i in n)?n:{...n,recurrenceScope:t}}const KF={task:{glyph:"☑",color:"text-blue-600 bg-blue-50 border-blue-100"},note:{glyph:"✎",color:"text-slate-700 bg-slate-50 border-slate-200"},comment:{glyph:"💬",color:"text-amber-700 bg-amber-50 border-amber-100"},feedback:{glyph:"📣",color:"text-purple-700 bg-purple-50 border-purple-100"}};function xp({kind:n,compact:e=!1}){const t=KF[n];return m.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 h-5 text-xxs rounded border ${t.color}`,title:n,children:[m.jsx("span",{children:t.glyph}),!e&&m.jsx("span",{className:"uppercase tracking-wider",children:n})]})}const NE=[{name:"circle",Icon:ty},{name:"square",Icon:Z6},{name:"triangle",Icon:q6},{name:"hexagon",Icon:v6},{name:"folder",Icon:x6},{name:"briefcase",Icon:l6},{name:"rocket",Icon:N6},{name:"sparkles",Icon:I6},{name:"target",Icon:B6},{name:"layers",Icon:S6},{name:"code",Icon:c6},{name:"book",Icon:r6},{name:"flame",Icon:g6},{name:"zap",Icon:mj},{name:"star",Icon:X6},{name:"heart",Icon:k6},{name:"box",Icon:i6},{name:"lightbulb",Icon:C6},{name:"pencil",Icon:cj},{name:"hash",Icon:y6}],JF=new Map(NE.map(n=>[n.name,n.Icon]));function eY(n){return n?JF.get(n)??ty:ty}const tY=[{name:"gray",value:"#6f6f76"},{name:"red",value:"#ef4444"},{name:"orange",value:"#f59e0b"},{name:"yellow",value:"#eab308"},{name:"green",value:"#10b981"},{name:"teal",value:"#14b8a6"},{name:"cyan",value:"#06b6d4"},{name:"blue",value:"#3b82f6"},{name:"indigo",value:"#5e6ad2"},{name:"purple",value:"#8b5cf6"},{name:"pink",value:"#ec4899"}],LE="#5e6ad2",_E="circle";function nY(n){return n==="circle"||n==="square"||n==="triangle"}function el({color:n,icon:e,size:t=12,className:r=""}){const i=eY(e),s=nY(e);return m.jsx(i,{size:t,className:`shrink-0 ${r}`,color:n,fill:s?n:"none",strokeWidth:s?1.2:1.8})}function py({status:n,size:e=14}){const t="currentColor";return n==="done"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusDone shrink-0",children:[m.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor"}),m.jsx("path",{d:"M4 7.4L6.2 9.5L10 5.5",stroke:"white",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):n==="in_progress"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusInProgress shrink-0",children:[m.jsx("circle",{cx:"7",cy:"7",r:"6",stroke:t,strokeWidth:"1.4",fill:"none"}),m.jsx("path",{d:"M7 1 a6 6 0 0 1 0 12 z",fill:"currentColor"})]}):n==="rejected"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusRejected shrink-0",children:[m.jsx("circle",{cx:"7",cy:"7",r:"6",stroke:t,strokeWidth:"1.4",fill:"none"}),m.jsx("path",{d:"M4 4l6 6M10 4l-6 6",stroke:t,strokeWidth:"1.4",strokeLinecap:"round"})]}):m.jsx("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusOpen shrink-0",children:m.jsx("circle",{cx:"7",cy:"7",r:"6",stroke:t,strokeWidth:"1.4",fill:"none"})})}function ga({priority:n,size:e=14}){return n==="urgent"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioUrgent shrink-0",children:[m.jsx("rect",{x:"2",y:"2",width:"10",height:"10",rx:"2",fill:"currentColor"}),m.jsx("path",{d:"M7 4v3.5M7 9.5h.01",stroke:"white",strokeWidth:"1.6",strokeLinecap:"round"})]}):n==="high"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioHigh shrink-0",children:[m.jsx("rect",{x:"2",y:"8",width:"2.5",height:"4",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"5.75",y:"5",width:"2.5",height:"7",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"9.5",y:"2",width:"2.5",height:"10",rx:"0.5",fill:"currentColor"})]}):n==="medium"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioMedium shrink-0",children:[m.jsx("rect",{x:"2",y:"8",width:"2.5",height:"4",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"5.75",y:"5",width:"2.5",height:"7",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"9.5",y:"2",width:"2.5",height:"10",rx:"0.5",opacity:"0.3",fill:"currentColor"})]}):n==="low"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioLow shrink-0",children:[m.jsx("rect",{x:"2",y:"8",width:"2.5",height:"4",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"5.75",y:"5",width:"2.5",height:"7",rx:"0.5",opacity:"0.3",fill:"currentColor"}),m.jsx("rect",{x:"9.5",y:"2",width:"2.5",height:"10",rx:"0.5",opacity:"0.3",fill:"currentColor"})]}):m.jsx("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-faint shrink-0",children:m.jsx("line",{x1:"3",y1:"7",x2:"11",y2:"7",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeDasharray:"1.5 1.5"})})}function Uc({size:n=12,className:e=""}){return m.jsxs("svg",{width:n,height:n,viewBox:"0 0 14 14",fill:"none",className:`shrink-0 ${e}`,"aria-hidden":"true",children:[m.jsx("path",{d:"M2.5 7a4.5 4.5 0 0 1 7.7-3.2L11.5 5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),m.jsx("path",{d:"M11.5 2v3h-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),m.jsx("path",{d:"M11.5 7a4.5 4.5 0 0 1-7.7 3.2L2.5 9",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),m.jsx("path",{d:"M2.5 12V9h3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]})}const Oa={urgent:"Urgent",high:"High",medium:"Medium",low:"Low",none:"No priority"},Bd={open:"Todo",in_progress:"In progress",done:"Done",rejected:"Cancelled"},DE=["open","in_progress","done","rejected"];function G0({trigger:n,children:e,align:t="start"}){const[r,i]=M.useState(!1),[s,l]=M.useState(null),o=M.useRef(null),u=M.useRef(null),h=M.useCallback(()=>{const f=o.current,p=u.current;if(!f||!p)return;const g=8,x=4,k=f.getBoundingClientRect(),b=p.offsetWidth,w=p.offsetHeight,S=window.innerWidth-b-g,Q=k.bottom+x,$=k.top-w-x,R=Q+w<=window.innerHeight-g,I=$>=g,T=t==="end"?k.right-b:k.left,X=R||!I?Q:$,Z=window.innerHeight-w-g;l({top:Math.min(Math.max(g,X),Math.max(g,Z)),left:Math.min(Math.max(g,T),Math.max(g,S))})},[t]);return M.useEffect(()=>{if(!r)return;const f=g=>{var k,b;const x=g.target;!((k=o.current)!=null&&k.contains(x))&&!((b=u.current)!=null&&b.contains(x))&&i(!1)},p=g=>{g.key==="Escape"&&i(!1)};return window.addEventListener("mousedown",f),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",p)}},[r]),M.useLayoutEffect(()=>{if(!r){l(null);return}h();const f=window.requestAnimationFrame(h);return window.addEventListener("resize",h),window.addEventListener("scroll",h,!0),()=>{window.cancelAnimationFrame(f),window.removeEventListener("resize",h),window.removeEventListener("scroll",h,!0)}},[r,h]),m.jsxs(m.Fragment,{children:[m.jsx("span",{ref:o,onClick:f=>{f.stopPropagation(),i(p=>!p)},children:n}),r&&VR.createPortal(m.jsx("div",{ref:u,className:"popover",style:{position:"fixed",top:(s==null?void 0:s.top)??-9999,left:(s==null?void 0:s.left)??-9999,visibility:s?"visible":"hidden"},onClick:f=>f.stopPropagation(),children:e(()=>i(!1))}),document.body)]})}function yp({task:n,size:e=14,className:t="",align:r="start",onStatusChange:i}){const s=Js();return m.jsx(G0,{align:r,trigger:m.jsx("button",{type:"button",draggable:!1,className:`inline-flex shrink-0 items-center justify-center rounded p-0.5 -m-0.5 hover:bg-line/40 disabled:opacity-60 ${t}`,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),onKeyUp:l=>l.stopPropagation(),onDragStart:l=>{l.preventDefault(),l.stopPropagation()},disabled:s.isPending,title:`Change status (${Bd[n.status]??n.status})`,"aria-label":"Change status","aria-haspopup":"menu",children:m.jsx(py,{status:n.status,size:e})}),children:l=>m.jsx(m.Fragment,{children:DE.map(o=>m.jsxs("button",{className:"popover-item",role:"menuitemradio","aria-checked":n.status===o,onClick:u=>{if(u.stopPropagation(),l(),n.status===o)return;const h=n.status;i==null||i(o),s.mutate({id:n.id,fields:{status:o}},{onError:()=>i==null?void 0:i(h)})},children:[m.jsx(py,{status:o,size:12}),m.jsx("span",{children:Bd[o]??o}),n.status===o&&m.jsx("span",{className:"ml-auto text-faint",children:"✓"})]},o))})})}const rY=600,IE={hourly:"Hourly",daily:"Daily",weekly:"Weekly",monthly:"Monthly",yearly:"Yearly"},iY={hourly:"hour",daily:"day",weekly:"week",monthly:"month",yearly:"year"};function sY(){const{openId:n,close:e}=Si();return M.useEffect(()=>{if(!n)return;const t=r=>{if(r.key!=="Escape")return;const i=r.target;if(i&&(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.closest(".cm-editor"))){i.blur();return}e()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[n,e]),n?m.jsxs("div",{className:"fixed inset-0 z-30 flex",children:[m.jsx("div",{className:"flex-1 bg-ink/10 backdrop-blur-[1px] cursor-pointer",onClick:e}),m.jsx("aside",{className:"w-[min(680px,92vw)] bg-surface border-l border-line shadow-modal flex flex-col",children:m.jsx(lY,{id:n,onClose:e})})]}):null}function SO(n){if(!n)return"";const e=new Date(n),t=r=>String(r).padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}`}function lY({id:n,onClose:e}){var Gt,Mr;const{data:t,isLoading:r}=ZP(n),{data:i}=Vn(),{data:s}=vF(n),{data:l}=ZP((t==null?void 0:t.parentId)??void 0),{data:o}=MF((t==null?void 0:t.kind)==="task"?n:void 0),u=Js(),h=ME(),f=CE(),p=AF(),g=RF(),x=NF(),{open:k}=zt(),{open:b}=Si(),[w,S]=M.useState(""),[Q,$]=M.useState(""),[R,I]=M.useState(""),[T,X]=M.useState("open"),[Z,H]=M.useState(""),[N,U]=M.useState(""),[V,se]=M.useState("none"),[K,G]=M.useState(!1),[Oe,de]=M.useState("idle"),[ee,le]=M.useState("future"),C=M.useRef(null),D=M.useRef(!1);M.useEffect(()=>{t&&C.current!==t.id&&(S(t.title??""),$(t.body),I(t.tags.join(", ")),X(t.status),H(t.dueAt?t.dueAt.slice(0,10):""),U(SO(t.completedAt)),D.current=!1,se(t.priority),G(!1),de("idle"),C.current=t.id)},[t==null?void 0:t.id,t]),M.useEffect(()=>{!t||D.current||U(SO(t.completedAt))},[t,t==null?void 0:t.completedAt]);const F=M.useMemo(()=>{if(!K||!t||C.current!==t.id)return null;const at=t.kind==="note",Ht=w.trim(),Xt=Ht||(at?null:Ht),Ji=R.split(",").map(es=>es.trim()).filter(Boolean),Un={};Xt!==(t.title??"")&&!(Xt===null&&t.title===null)&&Xt!==t.title&&(Un.title=Xt===""?null:Xt),Q!==t.body&&(Un.body=Q),JSON.stringify(Ji)!==JSON.stringify(t.tags)&&(Un.tags=Ji),T!==t.status&&(Un.status=T),V!==t.priority&&(Un.priority=V);const Kl=t.dueAt?t.dueAt.slice(0,10):"";if(Z!==Kl&&(Un.dueAt=Z?new Date(Z).toISOString():null),t.kind==="task"&&T==="done"&&D.current){const es=SO(t.completedAt);N!==es&&(Un.completedAt=N?new Date(N).toISOString():null)}return Un},[K,t,w,Q,R,T,V,Z,N]),E=t!=null&&((Mr=(Gt=t.metadata)==null?void 0:Gt.recurrence)==null?void 0:Mr.role)==="occurrence";function ce(at){return HF(at,E,ee)}if(M.useEffect(()=>{if(!K||!t||!F||Object.keys(F).length===0)return;de("idle");const at=setTimeout(async()=>{de("saving");try{await u.mutateAsync({id:t.id,fields:ce(F)}),de("saved")}catch{de("error")}},rY);return()=>clearTimeout(at)},[K,F]),r||!t)return m.jsxs("div",{className:"p-6 text-sm text-muted flex items-center justify-between",children:[m.jsx("span",{children:"Loading…"}),m.jsx("button",{onClick:e,className:"text-faint hover:text-ink",children:m.jsx(bc,{size:14})})]});const ye=t,me=i==null?void 0:i.find(at=>at.id===ye.projectId),Ie=me?`/p/${me.key}`:"",Re=ye.kind==="note",_e=F?Object.keys(F).length>0:!1;function ot(){S(ye.title??""),$(ye.body),I(ye.tags.join(", ")),X(ye.status),H(ye.dueAt?ye.dueAt.slice(0,10):""),se(ye.priority),de("idle"),le("future"),G(!0)}async function Fn(){if(!_e||!F){G(!1);return}de("saving");try{await u.mutateAsync({id:ye.id,fields:ce(F)}),de("saved"),G(!1)}catch{de("error")}}async function Ki(){h(t),e()}async function Ur(){if(!o||!confirm("Skip this recurring occurrence?"))return;const at=await p.mutateAsync({taskId:ye.id});at.next&&b(at.next.id)}async function Yn(){!o||!confirm("Stop this recurrence series?")||await g.mutateAsync({ruleId:o.rule.id})}async function Zt(at,Ht){if(!Ht)throw new Error("First due date is required");const Xt=ye.dueAt?ye.dueAt.slice(0,10):"";Ht!==Xt&&await u.mutateAsync({id:ye.id,fields:{dueAt:new Date(`${Ht}T12:00:00Z`).toISOString()}}),await f.mutateAsync({taskId:ye.id,input:at})}async function vn(at){if(!o)return;const{dtstart:Ht,...Xt}=at;await x.mutateAsync({ruleId:o.rule.id,input:Xt})}return m.jsxs(m.Fragment,{children:[m.jsxs("header",{className:"h-12 px-3 border-b border-line flex items-center gap-2 shrink-0",children:[m.jsx("button",{onClick:e,className:"p-1 -m-1 text-faint hover:text-ink rounded hover:bg-sidebar",title:"Close (Esc)",children:m.jsx(bc,{size:16})}),m.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted min-w-0",children:[me&&m.jsxs(m.Fragment,{children:[m.jsxs(va,{to:Ie,className:"flex items-center gap-1 hover:opacity-80",children:[m.jsx(el,{color:me.color,icon:me.icon,size:12}),m.jsx("span",{className:"font-mono tabular-nums",style:{color:me.color},children:me.key})]}),m.jsx(Bc,{size:11,className:"text-faint shrink-0"})]}),m.jsx(xp,{kind:t.kind,compact:!0}),t.sequenceId&&me&&m.jsxs("span",{className:"font-mono text-faint tabular-nums",children:[me.key,"-",t.sequenceId]})]}),m.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[K&&m.jsx(cY,{state:Oe,dirty:_e}),Re&&m.jsx("button",{className:`p-1 -m-1 rounded hover:bg-sidebar ${t.pinned?"text-accent":"text-faint hover:text-ink"}`,onClick:()=>u.mutate({id:t.id,fields:{pinned:!t.pinned}}),title:t.pinned?"Unpin from opening brief":"Pin to opening brief",children:m.jsx(j0,{size:13,fill:t.pinned?"currentColor":"none"})}),K?m.jsx("button",{className:"p-1 -m-1 text-faint hover:text-ink rounded hover:bg-sidebar",onClick:Fn,title:"Finish editing",children:m.jsx(Gi,{size:13})}):m.jsx("button",{className:"p-1 -m-1 text-faint hover:text-ink rounded hover:bg-sidebar",onClick:ot,title:"Edit",children:m.jsx(cj,{size:13})}),m.jsx("button",{className:"p-1 -m-1 text-faint hover:text-danger rounded hover:bg-danger/10",onClick:Ki,title:"Delete",children:m.jsx(vc,{size:13})})]})]}),m.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"px-6 py-5 space-y-4",children:[K?m.jsx("input",{className:`w-full text-lg font-semibold bg-transparent border-none outline-none focus:outline-none px-0 py-1 ${w?"":"placeholder:text-muted/60 placeholder:italic"}`,value:w,placeholder:Re?"Untitled":"Title",onChange:at=>S(at.target.value),autoFocus:!0}):m.jsx("h2",{className:`text-lg font-semibold py-1 ${Tr(t)?"italic text-muted":"text-ink"}`,children:on(t)}),m.jsx(uY,{isEditing:K,isTask:t.kind==="task",status:T,setStatus:X,dueDate:Z,setDueDate:H,priority:V,setPriority:se,tagsStr:R,setTagsStr:I,completedAt:t.completedAt,completedAtStr:N,setCompletedAtStr:at=>{D.current=!0,U(at)},createdAt:t.createdAt,actorKind:t.actorKind,task:ye.kind==="task"?{...ye,status:T}:void 0,onStatusChange:X,recurrence:o,recurrenceBusy:u.isPending||f.isPending||p.isPending||g.isPending||x.isPending,onSaveRecurrence:Zt,onSkipOccurrence:Ur,onStopRecurrence:Yn,onSplitRecurrence:vn,isRecurringOccurrence:E,occurrenceScope:ee,setOccurrenceScope:le}),Re&&l&&m.jsxs("button",{className:"w-full text-left flex items-center gap-2 text-xs px-3 py-2 rounded border border-line bg-sidebar/50 hover:border-accent hover:bg-accentSoft/40 transition-colors",onClick:()=>b(l.id),title:"Open linked task",children:[m.jsx(Q6,{size:12,className:"text-faint"}),m.jsx("span",{className:"text-faint",children:"Linked to task:"}),l.sequenceId&&me&&m.jsxs("span",{className:"font-mono text-faint tabular-nums",children:[me.key,"-",l.sequenceId]}),m.jsx("span",{className:"text-ink truncate",children:on(l)})]}),m.jsx("div",{className:"border border-line rounded-md overflow-hidden bg-surface",children:K?m.jsx(T0,{value:Q,onChange:at=>$(at),extensions:[hT()],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1,highlightActiveLineGutter:!1},theme:"light",minHeight:"220px",placeholder:"Write in Markdown…"}):Q?m.jsx("div",{className:"min-h-[120px] p-3",children:m.jsx(WP,{body:Q})}):m.jsx("div",{className:"min-h-[120px] p-3 text-xs text-faint",children:"No description."})}),K&&Q&&m.jsxs("details",{className:"text-xxs text-muted",children:[m.jsx("summary",{className:"cursor-pointer hover:text-ink",children:"Preview rendered Markdown"}),m.jsx("div",{className:"mt-2 p-3 border border-line rounded bg-sidebar/30",children:m.jsx(WP,{body:Q})})]}),t.kind==="task"&&m.jsx(hY,{related:s??[],onOpen:b,onAdd:()=>{me&&k({kind:"quick-create",projectId:me.id,initialKind:"note",parentId:t.id})},project:me})]})})]})}function oY(n){const e=n.rule,t=RE(e.rrule),r=t.preset??"daily",i=t.interval??1,s=i>1?`Every ${i} ${iY[r]}s`:IE[r],l=t.byWeekday.length?` · ${t.byWeekday.join(", ")}`:"",o=e.anchor==="completion"?"after completion":"scheduled",u=e.enabled?"":" · stopped",h=e.nextOccurrenceAt?` · next ${new Date(e.nextOccurrenceAt).toLocaleDateString()}`:"";return`${s}${l} · ${o}${h}${u}`}function BP(n){const e=n?RE(n.rule.rrule):void 0;return{preset:n?(e==null?void 0:e.preset)??"weekly":"none",interval:(e==null?void 0:e.interval)??1,anchor:(n==null?void 0:n.rule.anchor)??"scheduled",byWeekday:(e==null?void 0:e.byWeekday)??[],count:e!=null&&e.count?String(e.count):"",until:(e==null?void 0:e.until)??""}}function aY({isEditing:n,task:e,dueDate:t,recurrence:r,onSave:i,onSkip:s,onStop:l,onSplit:o,busy:u}){const[h,f]=M.useState(()=>BP(r)),[p,g]=M.useState(null);if(M.useEffect(()=>{f(BP(r)),g(null)},[n,e==null?void 0:e.id,e==null?void 0:e.dueAt,r==null?void 0:r.rule.id,r==null?void 0:r.rule.rrule,r==null?void 0:r.rule.anchor]),!e)return null;const x=["done","rejected"].includes(e.status),k=!!(r!=null&&r.rule.enabled)&&(r==null?void 0:r.rule.currentOccurrenceId)===e.id,b=!!(r!=null&&r.rule.enabled),w=h.preset!=="none",S=!!i&&t.length>0&&w&&h.interval>=1,Q=!!o&&!!(r!=null&&r.rule.enabled)&&w&&h.interval>=1;function $(Z){f(H=>({...H,...Z})),g(null)}function R(Z){const H=new Set(h.byWeekday);H.has(Z)?H.delete(Z):H.add(Z),$({byWeekday:dy.filter(N=>H.has(N))})}function I(){const Z={preset:h.preset,interval:h.interval,anchor:h.anchor,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,allDay:!0};return h.preset==="weekly"&&h.byWeekday.length>0&&(Z.byWeekday=h.byWeekday),h.count&&(Z.count=Number(h.count)),h.until&&(Z.until=new Date(`${h.until}T23:59:59Z`).toISOString()),Z}async function T(){if(h.preset==="none"){g(null);return}if(!t){g("Set due date first");return}if(h.count&&h.until){g("Use count or until");return}try{await(i==null?void 0:i(I(),t)),g(null)}catch(Z){g(Z instanceof Error?Z.message:"Could not save repeat")}}async function X(){if(h.preset!=="none"){if(h.count&&h.until){g("Use count or until");return}try{await(o==null?void 0:o(I())),g(null)}catch(Z){g(Z instanceof Error?Z.message:"Could not split series")}}}return!n||x?m.jsxs("span",{className:"min-w-0 flex items-center gap-2",children:[m.jsx("span",{className:r?"text-muted truncate":"text-faint",children:r?oY(r):"None"}),k&&s&&m.jsx("button",{className:"text-faint hover:text-ink disabled:opacity-40 shrink-0",onClick:s,disabled:u,title:"Skip occurrence",children:"Skip"})]}):m.jsxs("span",{className:"min-w-0 flex flex-col gap-1",children:[m.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[m.jsxs("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.preset,onChange:Z=>$({preset:Z.target.value}),title:"Repeat",children:[m.jsx("option",{value:"none",children:"None"}),AE.map(Z=>m.jsx("option",{value:Z,children:IE[Z]},Z))]}),w&&m.jsxs(m.Fragment,{children:[m.jsx("input",{type:"number",min:1,max:999,className:"w-14 bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.interval,onChange:Z=>$({interval:Math.max(1,Number(Z.target.value)||1)}),title:"Interval"}),m.jsxs("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.anchor,onChange:Z=>$({anchor:Z.target.value}),title:"Anchor",children:[m.jsx("option",{value:"scheduled",children:"Scheduled"}),m.jsx("option",{value:"completion",children:"Completion"})]}),m.jsx("button",{className:"text-accent hover:underline disabled:opacity-40",onClick:T,disabled:u||!S,children:"Save"}),Q&&m.jsx("button",{className:"text-faint hover:text-ink disabled:opacity-40",onClick:X,disabled:u,title:"Keep past occurrences on the old cadence; apply this cadence going forward",children:"Split"})]}),b&&l&&m.jsx("button",{className:"text-faint hover:text-danger disabled:opacity-40",onClick:l,disabled:u,title:"Stop series",children:"Stop"})]}),w&&h.preset==="weekly"&&m.jsx("span",{className:"flex flex-wrap gap-1",children:dy.map(Z=>m.jsx("button",{type:"button",className:`px-1.5 py-0.5 rounded border text-[10px] ${h.byWeekday.includes(Z)?"border-accent bg-accentSoft text-accent":"border-line bg-surface text-muted hover:text-ink"}`,onClick:()=>R(Z),children:Z},Z))}),w&&m.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[m.jsx("input",{type:"number",min:1,max:1e4,className:"w-20 bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.count,onChange:Z=>$({count:Z.target.value,until:Z.target.value?"":h.until}),placeholder:"Count",title:"Count"}),m.jsx("input",{type:"date",className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.until,onChange:Z=>$({until:Z.target.value,count:Z.target.value?"":h.count}),title:"Until"}),!t&&m.jsx("span",{className:"text-faint text-xxs",children:"Set due date first"}),p&&m.jsx("span",{className:"text-danger text-xxs truncate",children:p})]})]})}function uY({isEditing:n,isTask:e,status:t,setStatus:r,dueDate:i,setDueDate:s,priority:l,setPriority:o,tagsStr:u,setTagsStr:h,completedAt:f,completedAtStr:p,setCompletedAtStr:g,createdAt:x,actorKind:k,task:b,onStatusChange:w,recurrence:S,recurrenceBusy:Q,onSaveRecurrence:$,onSkipOccurrence:R,onStopRecurrence:I,onSplitRecurrence:T,isRecurringOccurrence:X,occurrenceScope:Z,setOccurrenceScope:H}){return m.jsxs("div",{className:"grid grid-cols-[80px_1fr] gap-x-3 gap-y-1.5 items-center text-xs",children:[e&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Status"}),m.jsxs("span",{className:"flex items-center gap-1.5",children:[n||!b?m.jsx(py,{status:t,size:12}):m.jsx(yp,{task:b,size:12,onStatusChange:w}),n?m.jsx("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:t,onChange:N=>r(N.target.value),children:DE.map(N=>m.jsx("option",{value:N,children:Bd[N]??N},N))}):m.jsx("span",{className:"text-ink",children:Bd[t]??t})]}),m.jsx("span",{className:"text-faint",children:"Due"}),m.jsx("span",{className:"flex items-center gap-1.5",children:n?m.jsxs(m.Fragment,{children:[m.jsx("input",{type:"date",className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:i,onChange:N=>s(N.target.value)}),!i&&m.jsx("span",{className:"text-faint text-xxs",children:"inbox"}),i&&m.jsx("button",{className:"text-faint hover:text-danger text-xxs",onClick:()=>s(""),title:"Clear",children:"✕"})]}):m.jsx("span",{className:i?"text-ink":"text-faint text-xxs",children:i||"inbox"})}),(S||n&&b&&!["done","rejected"].includes(t))&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Repeat"}),m.jsx(aY,{isEditing:n,task:b,dueDate:i,recurrence:S,busy:!!Q,onSave:$,onSkip:R,onStop:I,onSplit:T})]}),n&&X&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Apply to"}),m.jsx("span",{className:"flex items-center gap-1.5",children:m.jsxs("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:Z??"future",onChange:N=>H==null?void 0:H(N.target.value),title:"Recurrence edit scope",children:[m.jsx("option",{value:"future",children:"This and future"}),m.jsx("option",{value:"this",children:"This occurrence only"})]})})]}),m.jsx("span",{className:"text-faint",children:"Priority"}),m.jsxs("span",{className:"flex items-center gap-1.5",children:[m.jsx(ga,{priority:l,size:12}),n?m.jsx("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:l,onChange:N=>o(N.target.value),children:TE.map(N=>m.jsx("option",{value:N,children:Oa[N]},N))}):m.jsx("span",{className:"text-ink",children:Oa[l]})]}),t==="done"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Completed"}),n?m.jsxs("span",{className:"flex items-center gap-1.5",children:[m.jsx("input",{type:"datetime-local",className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:p,onChange:N=>g(N.target.value)}),!p&&m.jsx("span",{className:"text-faint text-xxs",children:"auto"}),p&&m.jsx("button",{className:"text-faint hover:text-danger text-xxs",onClick:()=>g(""),title:"Clear",children:"✕"})]}):m.jsx("span",{className:"text-muted",children:f?new Date(f).toLocaleString():"Not recorded"})]})]}),m.jsx("span",{className:"text-faint",children:"Tags"}),n?m.jsx("input",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:u,onChange:N=>h(N.target.value),placeholder:"comma, separated"}):m.jsx("span",{className:u?"text-muted":"text-faint",children:u||"none"}),m.jsx("span",{className:"text-faint",children:"Created"}),m.jsxs("span",{className:"text-muted",children:[new Date(x).toLocaleString()," · ",m.jsx("span",{className:"text-ink",children:k})]})]})}function cY({state:n,dirty:e}){return n==="saving"?m.jsxs("span",{className:"flex items-center gap-1 text-xxs text-muted",children:[m.jsx(aj,{size:11,className:"animate-spin"}),"Saving…"]}):n==="saved"&&!e?m.jsxs("span",{className:"flex items-center gap-1 text-xxs text-faint",children:[m.jsx(u6,{size:11}),"Saved"]}):n==="error"?m.jsx("span",{className:"text-xxs text-danger",children:"Save failed"}):e?m.jsxs("span",{className:"flex items-center gap-1 text-xxs text-faint",children:[m.jsx(a6,{size:11}),"Unsaved"]}):null}function hY({related:n,onOpen:e,onAdd:t,project:r}){const i=n.filter(s=>s.kind==="note");return m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-baseline justify-between mb-1.5",children:[m.jsxs("h3",{className:"text-xxs uppercase tracking-wider text-muted font-semibold",children:["Related notes ",m.jsx("span",{className:"text-faint",children:i.length})]}),m.jsx("button",{onClick:t,className:"text-xs text-accent hover:underline",children:"+ Add note"})]}),i.length===0?m.jsx("div",{className:"text-xs text-faint border border-dashed border-line rounded p-3 text-center",children:"No linked notes yet."}):m.jsx("div",{className:"border border-line rounded-md divide-y divide-lineSoft overflow-hidden",children:i.map(s=>m.jsxs("button",{className:"w-full text-left px-3 py-2 hover:bg-sidebar flex items-start gap-2",onClick:()=>e(s.id),children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:`text-sm truncate ${Tr(s)?"italic text-muted":"text-ink"}`,children:on(s)}),!Tr(s)&&s.body&&m.jsx("div",{className:"text-xxs text-muted truncate mt-0.5",children:s.body.replace(/\n/g," ").slice(0,140)})]}),s.pinned&&m.jsx(j0,{size:11,className:"text-accent shrink-0 mt-1",fill:"currentColor"})]},s.id))}),!r&&m.jsx("div",{className:"text-xxs text-faint mt-1",children:"No project context — link picker unavailable."})]})}function WP({body:n}){return m.jsx("div",{className:"text-sm leading-relaxed text-ink space-y-2 [&_h1]:text-lg [&_h1]:font-semibold [&_h1]:mt-3 [&_h1]:mb-1.5 [&_h2]:text-base [&_h2]:font-semibold [&_h2]:mt-3 [&_h2]:mb-1 [&_h3]:font-semibold [&_h3]:mt-2 [&_p]:my-1 [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:my-0.5 [&_code]:bg-sidebar [&_code]:px-1 [&_code]:py-0.5 [&_code]:rounded [&_code]:text-xs [&_pre]:bg-sidebar [&_pre]:p-2 [&_pre]:rounded [&_pre]:overflow-x-auto [&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_a]:text-accent [&_a]:underline [&_blockquote]:border-l-2 [&_blockquote]:border-line [&_blockquote]:pl-3 [&_blockquote]:text-muted [&_table]:border-collapse [&_th]:border [&_th]:border-line [&_th]:px-2 [&_th]:py-1 [&_td]:border [&_td]:border-line [&_td]:px-2 [&_td]:py-1",children:m.jsx(Hj,{remarkPlugins:[vE],children:n})})}function my(n,e){const[t,r]=M.useState(()=>{if(typeof window>"u")return e;try{const s=window.localStorage.getItem(n);return s===null?e:JSON.parse(s)}catch{return e}});M.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(n,JSON.stringify(t))}catch{}},[n,t]);const i=M.useCallback(s=>r(s),[]);return[t,i]}const ql={planned:"Planned",active:"Active",watching:"Watching",paused:"Paused",archived:"Archived"},zE={planned:"Committed, not started",active:"Currently being built",watching:"Built, in maintenance",paused:"Intentionally on hold",archived:"Hidden from active work"},gy=["planned","active","watching","paused","archived"],PO={key:"Key (A→Z)",name:"Name (A→Z)",recent:"Recently active"},qP={archived:!0};function fY(n,e){const t=[...n];return e==="key"?t.sort((r,i)=>r.key.localeCompare(i.key)):e==="name"?t.sort((r,i)=>r.name.localeCompare(i.name)):t.sort((r,i)=>+new Date(i.updatedAt)-+new Date(r.updatedAt))}function VP(){const{open:n}=zt(),{key:e}=Gd(),[t,r]=my("botnote.projectSort","key"),[i,s]=my("botnote.sidebar.projectGroups.collapsed",qP),{data:l,isLoading:o}=Vn({includeArchived:!0}),{data:u}=PE(200),h=(u==null?void 0:u.length)??0,f=M.useMemo(()=>{const k=l??[];return new Map(gy.map(b=>[b,fY(k.filter(w=>w.status===b),t)]))},[l,t]),p=(l==null?void 0:l.length)??0,g=k=>i[k]??qP[k]??!1,x=k=>{const b=g(k);s({...i,[k]:!b})};return m.jsxs("aside",{className:"w-52 shrink-0 border-r border-line bg-sidebar flex flex-col scrollbar-thin overflow-y-auto text-sm",children:[m.jsxs("nav",{className:"px-1.5 pt-2 space-y-px",children:[m.jsx(Co,{to:"/",end:!0,icon:m.jsx(o6,{size:12,className:"opacity-70"}),label:"Tasks",shortcut:"g d"}),m.jsx(Co,{to:"/today",icon:m.jsx(dj,{size:12,className:"opacity-70"}),label:"Today",shortcut:"g t"}),m.jsx(Co,{to:"/inbox",icon:m.jsx(_d,{size:12,className:"opacity-70"}),label:"Inbox",shortcut:"g i"}),m.jsx(Co,{to:"/dashboard",icon:m.jsx(P6,{size:12,className:"opacity-70"}),label:"Workspace",shortcut:"g w"})]}),m.jsxs("div",{className:"mt-3 px-3 py-1.5 flex items-center justify-between",children:[m.jsx("div",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:"Projects"}),m.jsxs("div",{className:"flex items-center gap-0.5",children:[m.jsx(G0,{trigger:m.jsx("button",{className:"text-muted hover:text-ink p-0.5 rounded hover:bg-sidebarHover flex items-center gap-0.5",title:`Sort: ${PO[t]}`,children:m.jsx(ey,{size:11})}),align:"end",children:k=>m.jsx(m.Fragment,{children:Object.keys(PO).map(b=>m.jsxs("button",{className:"popover-item",onClick:()=>{r(b),k()},children:[m.jsx("span",{children:PO[b]}),t===b&&m.jsx("span",{className:"ml-auto text-faint",children:"✓"})]},b))})}),m.jsx("button",{className:"text-muted hover:text-ink p-0.5 rounded hover:bg-sidebarHover",title:"New project (n)",onClick:()=>n({kind:"new-project"}),children:m.jsx(Wc,{size:11})})]})]}),m.jsxs("nav",{className:"px-1.5 space-y-px flex-1",children:[o&&m.jsx("div",{className:"px-2 py-1 text-xs text-faint",children:"Loading…"}),!o&&p===0&&m.jsxs("button",{className:"w-full text-left px-2 py-1 text-xs text-muted hover:bg-sidebarHover rounded",onClick:()=>n({kind:"new-project"}),children:["No projects yet. ",m.jsx("span",{className:"text-accent",children:"Create →"})]}),gy.map(k=>{const b=f.get(k)??[];if(o||b.length===0)return null;const w=g(k);return m.jsxs("div",{className:"pt-2 first:pt-0",children:[m.jsxs("button",{type:"button",className:"w-full px-1.5 pb-1 flex items-center gap-1 text-xxs uppercase tracking-wider text-muted font-medium hover:text-ink",onClick:()=>x(k),title:`${w?"Expand":"Collapse"} ${ql[k]}`,children:[w?m.jsx(Bc,{size:10}):m.jsx(ey,{size:10}),m.jsx("span",{children:ql[k]}),m.jsx("span",{className:"ml-auto text-faint tabular-nums",children:b.length})]}),!w&&b.map(S=>m.jsx(dY,{project:S,activeKey:e},S.id))]},k)})]}),m.jsxs("div",{className:"border-t border-line/60 px-1.5 py-1.5 space-y-px",children:[m.jsx(Co,{to:"/trash",icon:m.jsx(vc,{size:12,className:"opacity-70"}),label:"Trash",badge:h>0?h:void 0}),m.jsx(Co,{to:"/settings",icon:m.jsx(oj,{size:12,className:"opacity-70"}),label:"Settings"})]})]})}function dY({project:n,activeKey:e}){return m.jsxs(qC,{to:`/p/${n.key}`,title:n.status==="archived"?`${n.name} (archived)`:n.name,className:({isActive:t})=>`flex items-center gap-2 px-2 py-1 text-xs rounded ${t||e===n.key?"bg-accentSoft text-accentText":"text-ink2 hover:bg-sidebarHover"} ${n.status==="archived"?"opacity-60":""}`,children:[m.jsx(el,{color:n.color,icon:n.icon,size:11}),m.jsx("span",{className:"font-mono text-xxs tabular-nums opacity-90 shrink-0",style:{color:n.color},children:n.key}),m.jsx("span",{className:"truncate text-muted",children:n.name})]})}function Co({to:n,end:e,icon:t,label:r,shortcut:i,badge:s}){return m.jsxs(qC,{to:n,end:e,className:({isActive:l})=>`group flex items-center gap-2 px-2 py-1 rounded text-xs ${l?"bg-accentSoft text-accentText":"text-ink2 hover:bg-sidebarHover"}`,title:i?`${r} (${i})`:r,children:[t,m.jsx("span",{children:r}),s!=null&&m.jsx("span",{className:"ml-auto text-xxs text-faint tabular-nums",children:s}),i&&m.jsx("kbd",{className:"ml-auto opacity-0 group-hover:opacity-100 transition-opacity",children:i})]})}function pY({onMenuClick:n}){const{open:e}=zt(),t=Gs(),r=typeof navigator<"u"&&navigator.platform.includes("Mac")?"⌘":"Ctrl";async function i(){try{await Ve.logout()}catch{}t("/login",{replace:!0})}return m.jsxs("header",{className:"h-11 flex items-center justify-between px-3 border-b border-line bg-surface",children:[m.jsxs("div",{className:"flex items-center gap-1",children:[m.jsx("button",{className:"btn btn-ghost !h-7 !w-7 !p-0 md:hidden",onClick:n,title:"Menu","aria-label":"Toggle sidebar",children:m.jsx(j6,{size:14})}),m.jsxs(va,{to:"/",className:"flex items-center gap-1.5 text-ink hover:opacity-90",children:[m.jsx("img",{src:"/favicon.svg",alt:"","aria-hidden":"true",className:"w-[18px] h-[18px]"}),m.jsx("span",{className:"text-xs font-semibold tracking-tight",children:"botnote"})]})]}),m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsxs("button",{className:"btn !pl-2 !pr-1.5 gap-2 md:min-w-[220px] !justify-between text-muted",onClick:()=>e({kind:"search"}),title:"Search (⌘K)",children:[m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsx(Dd,{size:12}),m.jsx("span",{className:"text-xs hidden sm:inline",children:"Search…"})]}),m.jsxs("kbd",{className:"hidden md:inline-block",children:[r,"K"]})]}),m.jsxs("button",{className:"btn btn-primary",onClick:()=>e({kind:"quick-create"}),title:"Quick create (c)",children:[m.jsx(Wc,{size:12}),m.jsx("span",{className:"text-xs hidden sm:inline",children:"New"}),m.jsx("kbd",{className:"!bg-white/15 !border-white/25 !text-white hidden md:inline-block",children:"c"})]}),m.jsx("button",{className:"btn !px-1.5 !py-1 text-muted hover:!text-red-500",onClick:i,title:"Log out","aria-label":"Log out",children:m.jsx(uj,{size:12})})]})]})}function mY(){tN();const[n,e]=M.useState(!1),t=Us();return M.useEffect(()=>{e(!1)},[t.pathname,t.search]),m.jsxs("div",{className:"h-full w-full flex flex-col",children:[m.jsx(pY,{onMenuClick:()=>e(r=>!r)}),m.jsxs("div",{className:"flex-1 min-h-0 flex",children:[m.jsx("div",{className:"hidden md:flex shrink-0",children:m.jsx(VP,{})}),m.jsx("main",{className:"flex-1 min-w-0 min-h-0 overflow-hidden bg-bg",children:m.jsx(_5,{})})]}),n&&m.jsxs("div",{className:"fixed inset-0 z-40 md:hidden",children:[m.jsx("div",{className:"absolute inset-0 bg-black/30",onClick:()=>e(!1)}),m.jsx("div",{className:"absolute inset-y-0 left-0 flex shadow-modal",children:m.jsx(VP,{})})]}),m.jsx(sY,{})]})}function ZE({icon:n,color:e,onIconChange:t,onColorChange:r}){return m.jsxs("div",{className:"space-y-2",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-xxs text-muted uppercase tracking-wider mb-1",children:"Color"}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:tY.map(i=>m.jsx("button",{type:"button",onClick:()=>r(i.value),className:"relative w-6 h-6 rounded-full border border-line/80 hover:scale-110 transition-transform",style:{backgroundColor:i.value},title:i.name,children:e===i.value&&m.jsx(Gi,{size:12,className:"absolute inset-0 m-auto text-white",strokeWidth:3})},i.value))})]}),m.jsxs("div",{children:[m.jsx("div",{className:"text-xxs text-muted uppercase tracking-wider mb-1",children:"Icon"}),m.jsx("div",{className:"flex flex-wrap gap-1",children:NE.map(i=>m.jsx("button",{type:"button",onClick:()=>t(i.name),className:`w-7 h-7 rounded flex items-center justify-center border transition-colors ${n===i.name?"border-accent bg-accentSoft":"border-line bg-surface hover:bg-sidebar"}`,title:i.name,children:m.jsx(el,{color:e,icon:i.name,size:14})},i.name))})]})]})}function Pc({title:n,children:e,width:t="max-w-2xl"}){const{close:r}=zt();return M.useEffect(()=>{const i=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=i}},[]),m.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-20 px-4 bg-ink/20",onClick:r,children:m.jsxs("div",{className:`w-full ${t} bg-surface border border-line rounded-lg shadow-2xl overflow-hidden`,onClick:i=>i.stopPropagation(),children:[m.jsxs("div",{className:"h-9 px-3 flex items-center justify-between border-b border-line",children:[m.jsx("div",{className:"text-xs font-semibold text-ink",children:n}),m.jsx("button",{onClick:r,className:"text-muted hover:text-ink p-0.5 rounded hover:bg-line/60",title:"Close (Esc)",children:m.jsx(bc,{size:14})})]}),e]})})}function gY({projectId:n}){const{data:e}=kF(n),t=_F(),{close:r}=zt(),[i,s]=M.useState(""),[l,o]=M.useState("active"),[u,h]=M.useState(LE),[f,p]=M.useState(_E);if(M.useEffect(()=>{e&&(s(e.name),o(e.status),h(e.color),p(e.icon))},[e==null?void 0:e.id,e==null?void 0:e.name,e==null?void 0:e.status,e==null?void 0:e.color,e==null?void 0:e.icon]),!e)return m.jsx(Pc,{title:"Project settings",width:"max-w-md",children:m.jsx("div",{className:"p-4 text-sm text-muted",children:"Loading…"})});const g=e,x=i!==g.name||l!==g.status||u!==g.color||f!==g.icon,k=i.trim().length>0;return m.jsx(Pc,{title:`Settings · ${g.key}`,width:"max-w-md",children:m.jsxs("form",{onSubmit:async b=>{b.preventDefault(),!(!x||!k)&&(await t.mutateAsync({id:g.id,fields:{name:i.trim(),status:l,color:u,icon:f}}),r())},className:"p-3 space-y-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Name"}),m.jsx("input",{autoFocus:!0,className:"input",value:i,onChange:b=>s(b.target.value)})]}),m.jsx(ZE,{icon:f,color:u,onIconChange:p,onColorChange:h}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Status"}),m.jsx("select",{className:"input",value:l,onChange:b=>o(b.target.value),children:$E.map(b=>m.jsxs("option",{value:b,children:[ql[b]," · ",zE[b]]},b))})]}),m.jsx("div",{className:"flex justify-end items-center pt-1",children:m.jsxs("div",{className:"flex gap-2",children:[m.jsx("button",{type:"button",className:"btn",onClick:r,children:"Cancel"}),m.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!x||!k||t.isPending,children:t.isPending?"Saving…":"Save"})]})}),t.error&&m.jsx("div",{className:"text-xs text-danger",children:t.error.message})]})})}function OY(){const[n,e]=M.useState(""),[t,r]=M.useState(""),[i,s]=M.useState("active"),[l,o]=M.useState(""),[u,h]=M.useState(LE),[f,p]=M.useState(_E),g=LF(),{close:x}=zt(),k=Gs(),b=/^[A-Z][A-Z0-9_]{0,19}$/.test(n)&&t.trim().length>0;return m.jsx(Pc,{title:"New project",width:"max-w-md",children:m.jsxs("form",{onSubmit:async w=>{if(w.preventDefault(),!b)return;const S=await g.mutateAsync({key:n.trim(),name:t.trim(),status:i,color:u,icon:f,agentsMd:l.trim()});x(),k(`/p/${S.key}`)},className:"p-3 space-y-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Key (uppercase, e.g. BOT)"}),m.jsx("input",{autoFocus:!0,className:"input font-mono uppercase",value:n,onChange:w=>e(w.target.value.toUpperCase()),placeholder:"BOT",maxLength:20})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Name"}),m.jsx("input",{className:"input",value:t,onChange:w=>r(w.target.value),placeholder:"botnote"})]}),m.jsx(ZE,{icon:f,color:u,onIconChange:p,onColorChange:h}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Status"}),m.jsx("select",{className:"input",value:i,onChange:w=>s(w.target.value),children:$E.map(w=>m.jsxs("option",{value:w,children:[ql[w]," · ",zE[w]]},w))})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"AGENTS.md (optional)"}),m.jsx("textarea",{className:"input !h-24 py-1.5 font-mono text-xs leading-snug resize-y",value:l,onChange:w=>o(w.target.value),placeholder:`## Critical
479
+ `).find(r=>r.trim()))==null?void 0:t.trim())??"";return e?e.length>60?`${e.slice(0,60)}…`:e:"Untitled"}function Tr(n){return!n.title||!n.title.trim()}const jE=M.createContext(null),qF=6e3;function VF({children:n}){const[e,t]=M.useState([]),r=M.useRef(1),i=M.useRef(new Map),s=M.useCallback(u=>{const h=i.current.get(u);h&&(clearTimeout(h),i.current.delete(u)),t(f=>f.filter(p=>p.id!==u))},[]),l=M.useCallback(({duration:u=qF,...h})=>{const f=r.current++;t(p=>[...p,{...h,id:f}]),i.current.set(f,setTimeout(()=>{var p;i.current.delete(f),t(g=>g.filter(x=>x.id!==f)),(p=h.onExpire)==null||p.call(h)},u))},[]),o=M.useMemo(()=>({toasts:e,show:l,dismiss:s}),[e,l,s]);return m.jsxs(jE.Provider,{value:o,children:[n,m.jsx(FF,{})]})}function EE(){const n=M.useContext(jE);if(!n)throw new Error("useToasts must be used inside ToastsProvider");return n}function FF(){const{toasts:n,dismiss:e}=EE();return n.length===0?null:m.jsx("div",{className:"fixed bottom-4 left-1/2 -translate-x-1/2 z-[60] flex flex-col items-center gap-2",children:n.map(t=>m.jsxs("div",{className:"flex items-center gap-3 pl-3 pr-2 py-2 rounded-md bg-ink text-white text-xs shadow-modal",role:"status",children:[m.jsx("span",{className:"max-w-[60vw] truncate",children:t.message}),t.action&&m.jsx("button",{className:"shrink-0 px-2 py-0.5 rounded font-medium text-white/90 hover:text-white hover:bg-white/10",onClick:()=>{t.action.onClick(),e(t.id)},children:t.action.label}),m.jsx("button",{className:"shrink-0 px-1.5 text-white/50 hover:text-white",onClick:()=>{var r;(r=t.onExpire)==null||r.call(t),e(t.id)},"aria-label":"Dismiss",children:"×"})]},t.id))})}const XP=[["tasks-range"],["recent"],["entity-list"],["feedback"],["trash"]];function YF(n,e){if(Array.isArray(n))return n.filter(t=>t.id!==e);if(n&&typeof n=="object"&&"scheduled"in n){const t=n;return{...t,scheduled:t.scheduled.filter(r=>r.id!==e),overdue:t.overdue.filter(r=>r.id!==e),backlog:t.backlog.filter(r=>r.id!==e)}}return n}function ME(){const n=It(),{show:e}=EE(),t=M.useCallback(()=>{for(const r of XP)n.invalidateQueries({queryKey:r})},[n]);return M.useCallback(r=>{const i=[];for(const s of XP)for(const[l,o]of n.getQueriesData({queryKey:s}))o!==void 0&&(i.push([l,o]),n.setQueryData(l,YF(o,r.id)));Ve.deleteEntity(r.id).catch(()=>{for(const[s,l]of i)n.setQueryData(s,l)}),e({message:`Moved “${on(r)}” to trash`,action:{label:"Undo",onClick:()=>{Ve.restoreEntity(r.id).then(t).catch(t)}},onExpire:t})},[n,e,t])}const AE=["hourly","daily","weekly","monthly","yearly"],dy=["MO","TU","WE","TH","FR","SA","SU"];function UF(n){if(!n)return;const e=n.match(/^(\d{4})(\d{2})(\d{2})/);if(e)return`${e[1]}-${e[2]}-${e[3]}`;const t=new Date(n);return Number.isNaN(t.getTime())?void 0:t.toISOString().slice(0,10)}function RE(n){var o;const e=new Map(n.replace(/^RRULE:/i,"").split(";").map(u=>u.split("=")).filter(u=>u.length===2).map(([u,h])=>[u.toUpperCase(),h])),t=(o=e.get("FREQ"))==null?void 0:o.toLowerCase(),r=AE.includes(t)?t:void 0,i=Number(e.get("INTERVAL")??1),s=Number(e.get("COUNT")),l=(e.get("BYDAY")??"").split(",").filter(u=>dy.includes(u));return{preset:r,interval:Number.isFinite(i)&&i>0?i:1,byWeekday:l,count:Number.isFinite(s)&&s>0?s:void 0,until:UF(e.get("UNTIL"))}}const GF=["title","body","tags","priority"];function HF(n,e,t){return!e||!GF.some(i=>i in n)?n:{...n,recurrenceScope:t}}const KF={task:{glyph:"☑",color:"text-blue-600 bg-blue-50 border-blue-100"},note:{glyph:"✎",color:"text-slate-700 bg-slate-50 border-slate-200"},comment:{glyph:"💬",color:"text-amber-700 bg-amber-50 border-amber-100"},feedback:{glyph:"📣",color:"text-purple-700 bg-purple-50 border-purple-100"}};function xp({kind:n,compact:e=!1}){const t=KF[n];return m.jsxs("span",{className:`inline-flex items-center gap-1 px-1.5 h-5 text-xxs rounded border ${t.color}`,title:n,children:[m.jsx("span",{children:t.glyph}),!e&&m.jsx("span",{className:"uppercase tracking-wider",children:n})]})}const NE=[{name:"circle",Icon:ty},{name:"square",Icon:Z6},{name:"triangle",Icon:q6},{name:"hexagon",Icon:v6},{name:"folder",Icon:x6},{name:"briefcase",Icon:l6},{name:"rocket",Icon:N6},{name:"sparkles",Icon:I6},{name:"target",Icon:B6},{name:"layers",Icon:S6},{name:"code",Icon:c6},{name:"book",Icon:r6},{name:"flame",Icon:g6},{name:"zap",Icon:mj},{name:"star",Icon:X6},{name:"heart",Icon:k6},{name:"box",Icon:i6},{name:"lightbulb",Icon:C6},{name:"pencil",Icon:cj},{name:"hash",Icon:y6}],JF=new Map(NE.map(n=>[n.name,n.Icon]));function eY(n){return n?JF.get(n)??ty:ty}const tY=[{name:"gray",value:"#6f6f76"},{name:"red",value:"#ef4444"},{name:"orange",value:"#f59e0b"},{name:"yellow",value:"#eab308"},{name:"green",value:"#10b981"},{name:"teal",value:"#14b8a6"},{name:"cyan",value:"#06b6d4"},{name:"blue",value:"#3b82f6"},{name:"indigo",value:"#5e6ad2"},{name:"purple",value:"#8b5cf6"},{name:"pink",value:"#ec4899"}],LE="#5e6ad2",_E="circle";function nY(n){return n==="circle"||n==="square"||n==="triangle"}function el({color:n,icon:e,size:t=12,className:r=""}){const i=eY(e),s=nY(e);return m.jsx(i,{size:t,className:`shrink-0 ${r}`,color:n,fill:s?n:"none",strokeWidth:s?1.2:1.8})}function py({status:n,size:e=14}){const t="currentColor";return n==="done"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusDone shrink-0",children:[m.jsx("circle",{cx:"7",cy:"7",r:"6",fill:"currentColor"}),m.jsx("path",{d:"M4 7.4L6.2 9.5L10 5.5",stroke:"white",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]}):n==="in_progress"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusInProgress shrink-0",children:[m.jsx("circle",{cx:"7",cy:"7",r:"6",stroke:t,strokeWidth:"1.4",fill:"none"}),m.jsx("path",{d:"M7 1 a6 6 0 0 1 0 12 z",fill:"currentColor"})]}):n==="rejected"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusRejected shrink-0",children:[m.jsx("circle",{cx:"7",cy:"7",r:"6",stroke:t,strokeWidth:"1.4",fill:"none"}),m.jsx("path",{d:"M4 4l6 6M10 4l-6 6",stroke:t,strokeWidth:"1.4",strokeLinecap:"round"})]}):m.jsx("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-statusOpen shrink-0",children:m.jsx("circle",{cx:"7",cy:"7",r:"6",stroke:t,strokeWidth:"1.4",fill:"none"})})}function ga({priority:n,size:e=14}){return n==="urgent"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioUrgent shrink-0",children:[m.jsx("rect",{x:"2",y:"2",width:"10",height:"10",rx:"2",fill:"currentColor"}),m.jsx("path",{d:"M7 4v3.5M7 9.5h.01",stroke:"white",strokeWidth:"1.6",strokeLinecap:"round"})]}):n==="high"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioHigh shrink-0",children:[m.jsx("rect",{x:"2",y:"8",width:"2.5",height:"4",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"5.75",y:"5",width:"2.5",height:"7",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"9.5",y:"2",width:"2.5",height:"10",rx:"0.5",fill:"currentColor"})]}):n==="medium"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioMedium shrink-0",children:[m.jsx("rect",{x:"2",y:"8",width:"2.5",height:"4",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"5.75",y:"5",width:"2.5",height:"7",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"9.5",y:"2",width:"2.5",height:"10",rx:"0.5",opacity:"0.3",fill:"currentColor"})]}):n==="low"?m.jsxs("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-prioLow shrink-0",children:[m.jsx("rect",{x:"2",y:"8",width:"2.5",height:"4",rx:"0.5",fill:"currentColor"}),m.jsx("rect",{x:"5.75",y:"5",width:"2.5",height:"7",rx:"0.5",opacity:"0.3",fill:"currentColor"}),m.jsx("rect",{x:"9.5",y:"2",width:"2.5",height:"10",rx:"0.5",opacity:"0.3",fill:"currentColor"})]}):m.jsx("svg",{width:e,height:e,viewBox:"0 0 14 14",className:"text-faint shrink-0",children:m.jsx("line",{x1:"3",y1:"7",x2:"11",y2:"7",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeDasharray:"1.5 1.5"})})}function Uc({size:n=12,className:e=""}){return m.jsxs("svg",{width:n,height:n,viewBox:"0 0 14 14",fill:"none",className:`shrink-0 ${e}`,"aria-hidden":"true",children:[m.jsx("path",{d:"M2.5 7a4.5 4.5 0 0 1 7.7-3.2L11.5 5",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),m.jsx("path",{d:"M11.5 2v3h-3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),m.jsx("path",{d:"M11.5 7a4.5 4.5 0 0 1-7.7 3.2L2.5 9",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"}),m.jsx("path",{d:"M2.5 12V9h3",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})]})}const Oa={urgent:"Urgent",high:"High",medium:"Medium",low:"Low",none:"No priority"},Bd={open:"Todo",in_progress:"In progress",done:"Done",rejected:"Cancelled"},DE=["open","in_progress","done","rejected"];function G0({trigger:n,children:e,align:t="start"}){const[r,i]=M.useState(!1),[s,l]=M.useState(null),o=M.useRef(null),u=M.useRef(null),h=M.useCallback(()=>{const f=o.current,p=u.current;if(!f||!p)return;const g=8,x=4,k=f.getBoundingClientRect(),b=p.offsetWidth,w=p.offsetHeight,S=window.innerWidth-b-g,Q=k.bottom+x,$=k.top-w-x,R=Q+w<=window.innerHeight-g,I=$>=g,T=t==="end"?k.right-b:k.left,X=R||!I?Q:$,Z=window.innerHeight-w-g;l({top:Math.min(Math.max(g,X),Math.max(g,Z)),left:Math.min(Math.max(g,T),Math.max(g,S))})},[t]);return M.useEffect(()=>{if(!r)return;const f=g=>{var k,b;const x=g.target;!((k=o.current)!=null&&k.contains(x))&&!((b=u.current)!=null&&b.contains(x))&&i(!1)},p=g=>{g.key==="Escape"&&i(!1)};return window.addEventListener("mousedown",f),window.addEventListener("keydown",p),()=>{window.removeEventListener("mousedown",f),window.removeEventListener("keydown",p)}},[r]),M.useLayoutEffect(()=>{if(!r){l(null);return}h();const f=window.requestAnimationFrame(h);return window.addEventListener("resize",h),window.addEventListener("scroll",h,!0),()=>{window.cancelAnimationFrame(f),window.removeEventListener("resize",h),window.removeEventListener("scroll",h,!0)}},[r,h]),m.jsxs(m.Fragment,{children:[m.jsx("span",{ref:o,onClick:f=>{f.stopPropagation(),i(p=>!p)},children:n}),r&&VR.createPortal(m.jsx("div",{ref:u,className:"popover",style:{position:"fixed",top:(s==null?void 0:s.top)??-9999,left:(s==null?void 0:s.left)??-9999,visibility:s?"visible":"hidden"},onClick:f=>f.stopPropagation(),children:e(()=>i(!1))}),document.body)]})}function yp({task:n,size:e=14,className:t="",align:r="start",onStatusChange:i}){const s=Js();return m.jsx(G0,{align:r,trigger:m.jsx("button",{type:"button",draggable:!1,className:`inline-flex shrink-0 items-center justify-center rounded p-0.5 -m-0.5 hover:bg-line/40 disabled:opacity-60 ${t}`,onPointerDown:l=>l.stopPropagation(),onMouseDown:l=>l.stopPropagation(),onKeyDown:l=>l.stopPropagation(),onKeyUp:l=>l.stopPropagation(),onDragStart:l=>{l.preventDefault(),l.stopPropagation()},disabled:s.isPending,title:`Change status (${Bd[n.status]??n.status})`,"aria-label":"Change status","aria-haspopup":"menu",children:m.jsx(py,{status:n.status,size:e})}),children:l=>m.jsx(m.Fragment,{children:DE.map(o=>m.jsxs("button",{className:"popover-item",role:"menuitemradio","aria-checked":n.status===o,onClick:u=>{if(u.stopPropagation(),l(),n.status===o)return;const h=n.status;i==null||i(o),s.mutate({id:n.id,fields:{status:o}},{onError:()=>i==null?void 0:i(h)})},children:[m.jsx(py,{status:o,size:12}),m.jsx("span",{children:Bd[o]??o}),n.status===o&&m.jsx("span",{className:"ml-auto text-faint",children:"✓"})]},o))})})}const rY=600,IE={hourly:"Hourly",daily:"Daily",weekly:"Weekly",monthly:"Monthly",yearly:"Yearly"},iY={hourly:"hour",daily:"day",weekly:"week",monthly:"month",yearly:"year"};function sY(){const{openId:n,close:e}=Si();return M.useEffect(()=>{if(!n)return;const t=r=>{if(r.key!=="Escape")return;const i=r.target;if(i&&(i.tagName==="INPUT"||i.tagName==="TEXTAREA"||i.closest(".cm-editor"))){i.blur();return}e()};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[n,e]),n?m.jsxs("div",{className:"fixed inset-0 z-30 flex",children:[m.jsx("div",{className:"flex-1 bg-ink/10 backdrop-blur-[1px] cursor-pointer",onClick:e}),m.jsx("aside",{className:"w-[min(680px,92vw)] bg-surface border-l border-line shadow-modal flex flex-col",children:m.jsx(lY,{id:n,onClose:e})})]}):null}function SO(n){if(!n)return"";const e=new Date(n),t=r=>String(r).padStart(2,"0");return`${e.getFullYear()}-${t(e.getMonth()+1)}-${t(e.getDate())}T${t(e.getHours())}:${t(e.getMinutes())}`}function lY({id:n,onClose:e}){var Gt,Mr;const{data:t,isLoading:r}=ZP(n),{data:i}=Vn(),{data:s}=vF(n),{data:l}=ZP((t==null?void 0:t.parentId)??void 0),{data:o}=MF((t==null?void 0:t.kind)==="task"?n:void 0),u=Js(),h=ME(),f=CE(),p=AF(),g=RF(),x=NF(),{open:k}=zt(),{open:b}=Si(),[w,S]=M.useState(""),[Q,$]=M.useState(""),[R,I]=M.useState(""),[T,X]=M.useState("open"),[Z,H]=M.useState(""),[N,U]=M.useState(""),[V,se]=M.useState("none"),[K,G]=M.useState(!1),[Oe,de]=M.useState("idle"),[ee,le]=M.useState("future"),C=M.useRef(null),D=M.useRef(!1);M.useEffect(()=>{t&&C.current!==t.id&&(S(t.title??""),$(t.body),I(t.tags.join(", ")),X(t.status),H(t.dueAt?t.dueAt.slice(0,10):""),U(SO(t.completedAt)),D.current=!1,se(t.priority),G(!1),de("idle"),C.current=t.id)},[t==null?void 0:t.id,t]),M.useEffect(()=>{!t||D.current||U(SO(t.completedAt))},[t,t==null?void 0:t.completedAt]);const F=M.useMemo(()=>{if(!K||!t||C.current!==t.id)return null;const at=t.kind==="note",Ht=w.trim(),Xt=Ht||(at?null:Ht),Ji=R.split(",").map(es=>es.trim()).filter(Boolean),Un={};Xt!==(t.title??"")&&!(Xt===null&&t.title===null)&&Xt!==t.title&&(Un.title=Xt===""?null:Xt),Q!==t.body&&(Un.body=Q),JSON.stringify(Ji)!==JSON.stringify(t.tags)&&(Un.tags=Ji),T!==t.status&&(Un.status=T),V!==t.priority&&(Un.priority=V);const Kl=t.dueAt?t.dueAt.slice(0,10):"";if(Z!==Kl&&(Un.dueAt=Z?new Date(Z).toISOString():null),t.kind==="task"&&T==="done"&&D.current){const es=SO(t.completedAt);N!==es&&(Un.completedAt=N?new Date(N).toISOString():null)}return Un},[K,t,w,Q,R,T,V,Z,N]),E=t!=null&&((Mr=(Gt=t.metadata)==null?void 0:Gt.recurrence)==null?void 0:Mr.role)==="occurrence";function ce(at){return HF(at,E,ee)}if(M.useEffect(()=>{if(!K||!t||!F||Object.keys(F).length===0)return;de("idle");const at=setTimeout(async()=>{de("saving");try{await u.mutateAsync({id:t.id,fields:ce(F)}),de("saved")}catch{de("error")}},rY);return()=>clearTimeout(at)},[K,F]),r||!t)return m.jsxs("div",{className:"p-6 text-sm text-muted flex items-center justify-between",children:[m.jsx("span",{children:"Loading…"}),m.jsx("button",{onClick:e,className:"text-faint hover:text-ink",children:m.jsx(bc,{size:14})})]});const ye=t,me=i==null?void 0:i.find(at=>at.id===ye.projectId),Ie=me?`/p/${me.key}`:"",Re=ye.kind==="note",_e=F?Object.keys(F).length>0:!1;function ot(){S(ye.title??""),$(ye.body),I(ye.tags.join(", ")),X(ye.status),H(ye.dueAt?ye.dueAt.slice(0,10):""),se(ye.priority),de("idle"),le("future"),G(!0)}async function Fn(){if(!_e||!F){G(!1);return}de("saving");try{await u.mutateAsync({id:ye.id,fields:ce(F)}),de("saved"),G(!1)}catch{de("error")}}async function Ki(){h(t),e()}async function Ur(){if(!o||!confirm("Skip this recurring occurrence?"))return;const at=await p.mutateAsync({taskId:ye.id});at.next&&b(at.next.id)}async function Yn(){!o||!confirm("Stop this recurrence series?")||await g.mutateAsync({ruleId:o.rule.id})}async function Zt(at,Ht){if(!Ht)throw new Error("First due date is required");const Xt=ye.dueAt?ye.dueAt.slice(0,10):"";Ht!==Xt&&await u.mutateAsync({id:ye.id,fields:{dueAt:new Date(`${Ht}T12:00:00Z`).toISOString()}}),await f.mutateAsync({taskId:ye.id,input:at})}async function vn(at){if(!o)return;const{dtstart:Ht,...Xt}=at;await x.mutateAsync({ruleId:o.rule.id,input:Xt})}return m.jsxs(m.Fragment,{children:[m.jsxs("header",{className:"h-12 px-3 border-b border-line flex items-center gap-2 shrink-0",children:[m.jsx("button",{onClick:e,className:"p-1 -m-1 text-faint hover:text-ink rounded hover:bg-sidebar",title:"Close (Esc)",children:m.jsx(bc,{size:16})}),m.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted min-w-0",children:[me&&m.jsxs(m.Fragment,{children:[m.jsxs(va,{to:Ie,className:"flex items-center gap-1 hover:opacity-80",children:[m.jsx(el,{color:me.color,icon:me.icon,size:12}),m.jsx("span",{className:"font-mono tabular-nums",style:{color:me.color},children:me.key})]}),m.jsx(Bc,{size:11,className:"text-faint shrink-0"})]}),m.jsx(xp,{kind:t.kind,compact:!0}),t.sequenceId&&me&&m.jsxs("span",{className:"font-mono text-faint tabular-nums",children:[me.key,"-",t.sequenceId]})]}),m.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[K&&m.jsx(cY,{state:Oe,dirty:_e}),Re&&m.jsx("button",{className:`p-1 -m-1 rounded hover:bg-sidebar ${t.pinned?"text-accent":"text-faint hover:text-ink"}`,onClick:()=>u.mutate({id:t.id,fields:{pinned:!t.pinned}}),title:t.pinned?"Unpin from opening brief":"Pin to opening brief",children:m.jsx(j0,{size:13,fill:t.pinned?"currentColor":"none"})}),K?m.jsx("button",{className:"p-1 -m-1 text-faint hover:text-ink rounded hover:bg-sidebar",onClick:Fn,title:"Finish editing",children:m.jsx(Gi,{size:13})}):m.jsx("button",{className:"p-1 -m-1 text-faint hover:text-ink rounded hover:bg-sidebar",onClick:ot,title:"Edit",children:m.jsx(cj,{size:13})}),m.jsx("button",{className:"p-1 -m-1 text-faint hover:text-danger rounded hover:bg-danger/10",onClick:Ki,title:"Delete",children:m.jsx(vc,{size:13})})]})]}),m.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"px-6 py-5 space-y-4",children:[K?m.jsx("input",{className:`w-full text-lg font-semibold bg-transparent border-none outline-none focus:outline-none px-0 py-1 ${w?"":"placeholder:text-muted/60 placeholder:italic"}`,value:w,placeholder:Re?"Untitled":"Title",onChange:at=>S(at.target.value),autoFocus:!0}):m.jsx("h2",{className:`text-lg font-semibold py-1 ${Tr(t)?"italic text-muted":"text-ink"}`,children:on(t)}),m.jsx(uY,{isEditing:K,isTask:t.kind==="task",status:T,setStatus:X,dueDate:Z,setDueDate:H,priority:V,setPriority:se,tagsStr:R,setTagsStr:I,completedAt:t.completedAt,completedAtStr:N,setCompletedAtStr:at=>{D.current=!0,U(at)},createdAt:t.createdAt,actorKind:t.actorKind,task:ye.kind==="task"?{...ye,status:T}:void 0,onStatusChange:X,recurrence:o,recurrenceBusy:u.isPending||f.isPending||p.isPending||g.isPending||x.isPending,onSaveRecurrence:Zt,onSkipOccurrence:Ur,onStopRecurrence:Yn,onSplitRecurrence:vn,isRecurringOccurrence:E,occurrenceScope:ee,setOccurrenceScope:le}),Re&&l&&m.jsxs("button",{className:"w-full text-left flex items-center gap-2 text-xs px-3 py-2 rounded border border-line bg-sidebar/50 hover:border-accent hover:bg-accentSoft/40 transition-colors",onClick:()=>b(l.id),title:"Open linked task",children:[m.jsx(Q6,{size:12,className:"text-faint"}),m.jsx("span",{className:"text-faint",children:"Linked to task:"}),l.sequenceId&&me&&m.jsxs("span",{className:"font-mono text-faint tabular-nums",children:[me.key,"-",l.sequenceId]}),m.jsx("span",{className:"text-ink truncate",children:on(l)})]}),m.jsx("div",{className:"border border-line rounded-md overflow-hidden bg-surface",children:K?m.jsx(T0,{value:Q,onChange:at=>$(at),extensions:[hT()],basicSetup:{lineNumbers:!1,foldGutter:!1,highlightActiveLine:!1,highlightActiveLineGutter:!1},theme:"light",minHeight:"220px",placeholder:"Write in Markdown…"}):Q?m.jsx("div",{className:"min-h-[120px] p-3",children:m.jsx(WP,{body:Q})}):m.jsx("div",{className:"min-h-[120px] p-3 text-xs text-faint",children:"No description."})}),K&&Q&&m.jsxs("details",{className:"text-xxs text-muted",children:[m.jsx("summary",{className:"cursor-pointer hover:text-ink",children:"Preview rendered Markdown"}),m.jsx("div",{className:"mt-2 p-3 border border-line rounded bg-sidebar/30",children:m.jsx(WP,{body:Q})})]}),t.kind==="task"&&m.jsx(hY,{related:s??[],onOpen:b,onAdd:()=>{me&&k({kind:"quick-create",projectId:me.id,initialKind:"note",parentId:t.id})},project:me})]})})]})}function oY(n){const e=n.rule,t=RE(e.rrule),r=t.preset??"daily",i=t.interval??1,s=i>1?`Every ${i} ${iY[r]}s`:IE[r],l=t.byWeekday.length?` · ${t.byWeekday.join(", ")}`:"",o=e.anchor==="completion"?"after completion":"scheduled",u=e.enabled?"":" · stopped",h=e.nextOccurrenceAt?` · next ${new Date(e.nextOccurrenceAt).toLocaleDateString()}`:"";return`${s}${l} · ${o}${h}${u}`}function BP(n){const e=n?RE(n.rule.rrule):void 0;return{preset:n?(e==null?void 0:e.preset)??"weekly":"none",interval:(e==null?void 0:e.interval)??1,anchor:(n==null?void 0:n.rule.anchor)??"scheduled",byWeekday:(e==null?void 0:e.byWeekday)??[],count:e!=null&&e.count?String(e.count):"",until:(e==null?void 0:e.until)??""}}function aY({isEditing:n,task:e,dueDate:t,recurrence:r,onSave:i,onSkip:s,onStop:l,onSplit:o,busy:u}){const[h,f]=M.useState(()=>BP(r)),[p,g]=M.useState(null);if(M.useEffect(()=>{f(BP(r)),g(null)},[n,e==null?void 0:e.id,e==null?void 0:e.dueAt,r==null?void 0:r.rule.id,r==null?void 0:r.rule.rrule,r==null?void 0:r.rule.anchor]),!e)return null;const x=["done","rejected"].includes(e.status),k=!!(r!=null&&r.rule.enabled)&&(r==null?void 0:r.rule.currentOccurrenceId)===e.id,b=!!(r!=null&&r.rule.enabled),w=h.preset!=="none",S=!!i&&t.length>0&&w&&h.interval>=1,Q=!!o&&!!(r!=null&&r.rule.enabled)&&w&&h.interval>=1;function $(Z){f(H=>({...H,...Z})),g(null)}function R(Z){const H=new Set(h.byWeekday);H.has(Z)?H.delete(Z):H.add(Z),$({byWeekday:dy.filter(N=>H.has(N))})}function I(){const Z={preset:h.preset,interval:h.interval,anchor:h.anchor,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,allDay:!0};return h.preset==="weekly"&&h.byWeekday.length>0&&(Z.byWeekday=h.byWeekday),h.count&&(Z.count=Number(h.count)),h.until&&(Z.until=new Date(`${h.until}T23:59:59Z`).toISOString()),Z}async function T(){if(h.preset==="none"){g(null);return}if(!t){g("Set due date first");return}if(h.count&&h.until){g("Use count or until");return}try{await(i==null?void 0:i(I(),t)),g(null)}catch(Z){g(Z instanceof Error?Z.message:"Could not save repeat")}}async function X(){if(h.preset!=="none"){if(h.count&&h.until){g("Use count or until");return}try{await(o==null?void 0:o(I())),g(null)}catch(Z){g(Z instanceof Error?Z.message:"Could not split series")}}}return!n||x?m.jsxs("span",{className:"min-w-0 flex items-center gap-2",children:[m.jsx("span",{className:r?"text-muted truncate":"text-faint",children:r?oY(r):"None"}),k&&s&&m.jsx("button",{className:"text-faint hover:text-ink disabled:opacity-40 shrink-0",onClick:s,disabled:u,title:"Skip occurrence",children:"Skip"})]}):m.jsxs("span",{className:"min-w-0 flex flex-col gap-1",children:[m.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[m.jsxs("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.preset,onChange:Z=>$({preset:Z.target.value}),title:"Repeat",children:[m.jsx("option",{value:"none",children:"None"}),AE.map(Z=>m.jsx("option",{value:Z,children:IE[Z]},Z))]}),w&&m.jsxs(m.Fragment,{children:[m.jsx("input",{type:"number",min:1,max:999,className:"w-14 bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.interval,onChange:Z=>$({interval:Math.max(1,Number(Z.target.value)||1)}),title:"Interval"}),m.jsxs("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.anchor,onChange:Z=>$({anchor:Z.target.value}),title:"Anchor",children:[m.jsx("option",{value:"scheduled",children:"Scheduled"}),m.jsx("option",{value:"completion",children:"Completion"})]}),m.jsx("button",{className:"text-accent hover:underline disabled:opacity-40",onClick:T,disabled:u||!S,children:"Save"}),Q&&m.jsx("button",{className:"text-faint hover:text-ink disabled:opacity-40",onClick:X,disabled:u,title:"Keep past occurrences on the old cadence; apply this cadence going forward",children:"Split"})]}),b&&l&&m.jsx("button",{className:"text-faint hover:text-danger disabled:opacity-40",onClick:l,disabled:u,title:"Stop series",children:"Stop"})]}),w&&h.preset==="weekly"&&m.jsx("span",{className:"flex flex-wrap gap-1",children:dy.map(Z=>m.jsx("button",{type:"button",className:`px-1.5 py-0.5 rounded border text-[10px] ${h.byWeekday.includes(Z)?"border-accent bg-accentSoft text-accent":"border-line bg-surface text-muted hover:text-ink"}`,onClick:()=>R(Z),children:Z},Z))}),w&&m.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[m.jsx("input",{type:"number",min:1,max:1e4,className:"w-20 bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.count,onChange:Z=>$({count:Z.target.value,until:Z.target.value?"":h.until}),placeholder:"Count",title:"Count"}),m.jsx("input",{type:"date",className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:h.until,onChange:Z=>$({until:Z.target.value,count:Z.target.value?"":h.count}),title:"Until"}),!t&&m.jsx("span",{className:"text-faint text-xxs",children:"Set due date first"}),p&&m.jsx("span",{className:"text-danger text-xxs truncate",children:p})]})]})}function uY({isEditing:n,isTask:e,status:t,setStatus:r,dueDate:i,setDueDate:s,priority:l,setPriority:o,tagsStr:u,setTagsStr:h,completedAt:f,completedAtStr:p,setCompletedAtStr:g,createdAt:x,actorKind:k,task:b,onStatusChange:w,recurrence:S,recurrenceBusy:Q,onSaveRecurrence:$,onSkipOccurrence:R,onStopRecurrence:I,onSplitRecurrence:T,isRecurringOccurrence:X,occurrenceScope:Z,setOccurrenceScope:H}){return m.jsxs("div",{className:"grid grid-cols-[80px_1fr] gap-x-3 gap-y-1.5 items-center text-xs",children:[e&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Status"}),m.jsxs("span",{className:"flex items-center gap-1.5",children:[n||!b?m.jsx(py,{status:t,size:12}):m.jsx(yp,{task:b,size:12,onStatusChange:w}),n?m.jsx("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:t,onChange:N=>r(N.target.value),children:DE.map(N=>m.jsx("option",{value:N,children:Bd[N]??N},N))}):m.jsx("span",{className:"text-ink",children:Bd[t]??t})]}),m.jsx("span",{className:"text-faint",children:"Due"}),m.jsx("span",{className:"flex items-center gap-1.5",children:n?m.jsxs(m.Fragment,{children:[m.jsx("input",{type:"date",className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:i,onChange:N=>s(N.target.value)}),!i&&m.jsx("span",{className:"text-faint text-xxs",children:"inbox"}),i&&m.jsx("button",{className:"text-faint hover:text-danger text-xxs",onClick:()=>s(""),title:"Clear",children:"✕"})]}):m.jsx("span",{className:i?"text-ink":"text-faint text-xxs",children:i||"inbox"})}),(S||n&&b&&!["done","rejected"].includes(t))&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Repeat"}),m.jsx(aY,{isEditing:n,task:b,dueDate:i,recurrence:S,busy:!!Q,onSave:$,onSkip:R,onStop:I,onSplit:T})]}),n&&X&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Apply to"}),m.jsx("span",{className:"flex items-center gap-1.5",children:m.jsxs("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:Z??"future",onChange:N=>H==null?void 0:H(N.target.value),title:"Recurrence edit scope",children:[m.jsx("option",{value:"future",children:"This and future"}),m.jsx("option",{value:"this",children:"This occurrence only"})]})})]}),m.jsx("span",{className:"text-faint",children:"Priority"}),m.jsxs("span",{className:"flex items-center gap-1.5",children:[m.jsx(ga,{priority:l,size:12}),n?m.jsx("select",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:l,onChange:N=>o(N.target.value),children:TE.map(N=>m.jsx("option",{value:N,children:Oa[N]},N))}):m.jsx("span",{className:"text-ink",children:Oa[l]})]}),t==="done"&&m.jsxs(m.Fragment,{children:[m.jsx("span",{className:"text-faint",children:"Completed"}),n?m.jsxs("span",{className:"flex items-center gap-1.5",children:[m.jsx("input",{type:"datetime-local",className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:p,onChange:N=>g(N.target.value)}),!p&&m.jsx("span",{className:"text-faint text-xxs",children:"auto"}),p&&m.jsx("button",{className:"text-faint hover:text-danger text-xxs",onClick:()=>g(""),title:"Clear",children:"✕"})]}):m.jsx("span",{className:"text-muted",children:f?new Date(f).toLocaleString():"Not recorded"})]})]}),m.jsx("span",{className:"text-faint",children:"Tags"}),n?m.jsx("input",{className:"bg-transparent border-none text-xs text-ink hover:bg-sidebar rounded px-1 -mx-1 focus:outline-none focus:ring-1 focus:ring-accent",value:u,onChange:N=>h(N.target.value),placeholder:"comma, separated"}):m.jsx("span",{className:u?"text-muted":"text-faint",children:u||"none"}),m.jsx("span",{className:"text-faint",children:"Created"}),m.jsxs("span",{className:"text-muted",children:[new Date(x).toLocaleString()," · ",m.jsx("span",{className:"text-ink",children:k})]})]})}function cY({state:n,dirty:e}){return n==="saving"?m.jsxs("span",{className:"flex items-center gap-1 text-xxs text-muted",children:[m.jsx(aj,{size:11,className:"animate-spin"}),"Saving…"]}):n==="saved"&&!e?m.jsxs("span",{className:"flex items-center gap-1 text-xxs text-faint",children:[m.jsx(u6,{size:11}),"Saved"]}):n==="error"?m.jsx("span",{className:"text-xxs text-danger",children:"Save failed"}):e?m.jsxs("span",{className:"flex items-center gap-1 text-xxs text-faint",children:[m.jsx(a6,{size:11}),"Unsaved"]}):null}function hY({related:n,onOpen:e,onAdd:t,project:r}){const i=n.filter(s=>s.kind==="note");return m.jsxs("div",{children:[m.jsxs("div",{className:"flex items-baseline justify-between mb-1.5",children:[m.jsxs("h3",{className:"text-xxs uppercase tracking-wider text-muted font-semibold",children:["Related notes ",m.jsx("span",{className:"text-faint",children:i.length})]}),m.jsx("button",{onClick:t,className:"text-xs text-accent hover:underline",children:"+ Add note"})]}),i.length===0?m.jsx("div",{className:"text-xs text-faint border border-dashed border-line rounded p-3 text-center",children:"No linked notes yet."}):m.jsx("div",{className:"border border-line rounded-md divide-y divide-lineSoft overflow-hidden",children:i.map(s=>m.jsxs("button",{className:"w-full text-left px-3 py-2 hover:bg-sidebar flex items-start gap-2",onClick:()=>e(s.id),children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:`text-sm truncate ${Tr(s)?"italic text-muted":"text-ink"}`,children:on(s)}),!Tr(s)&&s.body&&m.jsx("div",{className:"text-xxs text-muted truncate mt-0.5",children:s.body.replace(/\n/g," ").slice(0,140)})]}),s.pinned&&m.jsx(j0,{size:11,className:"text-accent shrink-0 mt-1",fill:"currentColor"})]},s.id))}),!r&&m.jsx("div",{className:"text-xxs text-faint mt-1",children:"No project context — link picker unavailable."})]})}function WP({body:n}){return m.jsx("div",{className:"text-sm leading-relaxed text-ink space-y-2 [&_h1]:text-lg [&_h1]:font-semibold [&_h1]:mt-3 [&_h1]:mb-1.5 [&_h2]:text-base [&_h2]:font-semibold [&_h2]:mt-3 [&_h2]:mb-1 [&_h3]:font-semibold [&_h3]:mt-2 [&_p]:my-1 [&_ul]:list-disc [&_ul]:pl-5 [&_ol]:list-decimal [&_ol]:pl-5 [&_li]:my-0.5 [&_code]:bg-sidebar [&_code]:px-1 [&_code]:py-0.5 [&_code]:rounded [&_code]:text-xs [&_pre]:bg-sidebar [&_pre]:p-2 [&_pre]:rounded [&_pre]:overflow-x-auto [&_pre_code]:bg-transparent [&_pre_code]:p-0 [&_a]:text-accent [&_a]:underline [&_blockquote]:border-l-2 [&_blockquote]:border-line [&_blockquote]:pl-3 [&_blockquote]:text-muted [&_table]:border-collapse [&_th]:border [&_th]:border-line [&_th]:px-2 [&_th]:py-1 [&_td]:border [&_td]:border-line [&_td]:px-2 [&_td]:py-1",children:m.jsx(Hj,{remarkPlugins:[vE],children:n})})}function my(n,e){const[t,r]=M.useState(()=>{if(typeof window>"u")return e;try{const s=window.localStorage.getItem(n);return s===null?e:JSON.parse(s)}catch{return e}});M.useEffect(()=>{if(!(typeof window>"u"))try{window.localStorage.setItem(n,JSON.stringify(t))}catch{}},[n,t]);const i=M.useCallback(s=>r(s),[]);return[t,i]}const ql={planned:"Planned",active:"Active",watching:"Watching",paused:"Paused",archived:"Archived"},zE={planned:"Committed, not started",active:"Currently being built",watching:"Built, in maintenance",paused:"Intentionally on hold",archived:"Hidden from active work"},gy=["planned","active","watching","paused","archived"],PO={key:"Key (A→Z)",name:"Name (A→Z)",recent:"Recently active"},qP={archived:!0};function fY(n,e){const t=[...n];return e==="key"?t.sort((r,i)=>r.key.localeCompare(i.key)):e==="name"?t.sort((r,i)=>r.name.localeCompare(i.name)):t.sort((r,i)=>+new Date(i.updatedAt)-+new Date(r.updatedAt))}function VP(){const{open:n}=zt(),{key:e}=Gd(),[t,r]=my("botnote.projectSort","key"),[i,s]=my("botnote.sidebar.projectGroups.collapsed",qP),{data:l,isLoading:o}=Vn({includeArchived:!0}),{data:u}=PE(200),h=(u==null?void 0:u.length)??0,f=M.useMemo(()=>{const k=l??[];return new Map(gy.map(b=>[b,fY(k.filter(w=>w.status===b),t)]))},[l,t]),p=(l==null?void 0:l.length)??0,g=k=>i[k]??qP[k]??!1,x=k=>{const b=g(k);s({...i,[k]:!b})};return m.jsxs("aside",{className:"w-52 shrink-0 border-r border-line bg-sidebar flex flex-col scrollbar-thin overflow-y-auto text-sm",children:[m.jsxs("nav",{className:"px-1.5 pt-2 space-y-px",children:[m.jsx(Co,{to:"/",end:!0,icon:m.jsx(o6,{size:12,className:"opacity-70"}),label:"Tasks",shortcut:"g d"}),m.jsx(Co,{to:"/today",icon:m.jsx(dj,{size:12,className:"opacity-70"}),label:"Today",shortcut:"g t"}),m.jsx(Co,{to:"/inbox",icon:m.jsx(_d,{size:12,className:"opacity-70"}),label:"Inbox",shortcut:"g i"}),m.jsx(Co,{to:"/dashboard",icon:m.jsx(P6,{size:12,className:"opacity-70"}),label:"Workspace",shortcut:"g w"})]}),m.jsxs("div",{className:"mt-3 px-3 py-1.5 flex items-center justify-between",children:[m.jsx("div",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:"Projects"}),m.jsxs("div",{className:"flex items-center gap-0.5",children:[m.jsx(G0,{trigger:m.jsx("button",{className:"text-muted hover:text-ink p-0.5 rounded hover:bg-sidebarHover flex items-center gap-0.5",title:`Sort: ${PO[t]}`,children:m.jsx(ey,{size:11})}),align:"end",children:k=>m.jsx(m.Fragment,{children:Object.keys(PO).map(b=>m.jsxs("button",{className:"popover-item",onClick:()=>{r(b),k()},children:[m.jsx("span",{children:PO[b]}),t===b&&m.jsx("span",{className:"ml-auto text-faint",children:"✓"})]},b))})}),m.jsx("button",{className:"text-muted hover:text-ink p-0.5 rounded hover:bg-sidebarHover",title:"New project (n)",onClick:()=>n({kind:"new-project"}),children:m.jsx(Wc,{size:11})})]})]}),m.jsxs("nav",{className:"px-1.5 space-y-px flex-1",children:[o&&m.jsx("div",{className:"px-2 py-1 text-xs text-faint",children:"Loading…"}),!o&&p===0&&m.jsxs("button",{className:"w-full text-left px-2 py-1 text-xs text-muted hover:bg-sidebarHover rounded",onClick:()=>n({kind:"new-project"}),children:["No projects yet. ",m.jsx("span",{className:"text-accent",children:"Create →"})]}),gy.map(k=>{const b=f.get(k)??[];if(o||b.length===0)return null;const w=g(k);return m.jsxs("div",{className:"pt-2 first:pt-0",children:[m.jsxs("button",{type:"button",className:"w-full px-1.5 pb-1 flex items-center gap-1 text-xxs uppercase tracking-wider text-muted font-medium hover:text-ink",onClick:()=>x(k),title:`${w?"Expand":"Collapse"} ${ql[k]}`,children:[w?m.jsx(Bc,{size:10}):m.jsx(ey,{size:10}),m.jsx("span",{children:ql[k]}),m.jsx("span",{className:"ml-auto text-faint tabular-nums",children:b.length})]}),!w&&b.map(S=>m.jsx(dY,{project:S,activeKey:e},S.id))]},k)})]}),m.jsxs("div",{className:"border-t border-line/60 px-1.5 py-1.5 space-y-px",children:[m.jsx(Co,{to:"/trash",icon:m.jsx(vc,{size:12,className:"opacity-70"}),label:"Trash",badge:h>0?h:void 0}),m.jsx(Co,{to:"/settings",icon:m.jsx(oj,{size:12,className:"opacity-70"}),label:"Settings"})]})]})}function dY({project:n,activeKey:e}){return m.jsxs(qC,{to:`/p/${n.key}`,title:n.status==="archived"?`${n.name} (archived)`:n.name,className:({isActive:t})=>`flex items-center gap-2 px-2 py-1 text-xs rounded ${t||e===n.key?"bg-accentSoft text-accentText":"text-ink2 hover:bg-sidebarHover"} ${n.status==="archived"?"opacity-60":""}`,children:[m.jsx(el,{color:n.color,icon:n.icon,size:11}),m.jsx("span",{className:"font-mono text-xxs tabular-nums opacity-90 shrink-0",style:{color:n.color},children:n.key}),m.jsx("span",{className:"truncate text-muted",children:n.name})]})}function Co({to:n,end:e,icon:t,label:r,shortcut:i,badge:s}){return m.jsxs(qC,{to:n,end:e,className:({isActive:l})=>`group flex items-center gap-2 px-2 py-1 rounded text-xs ${l?"bg-accentSoft text-accentText":"text-ink2 hover:bg-sidebarHover"}`,title:i?`${r} (${i})`:r,children:[t,m.jsx("span",{children:r}),s!=null&&m.jsx("span",{className:"ml-auto text-xxs text-faint tabular-nums",children:s}),i&&m.jsx("kbd",{className:"ml-auto opacity-0 group-hover:opacity-100 transition-opacity",children:i})]})}function pY({onMenuClick:n}){const{open:e}=zt(),t=Gs(),r=typeof navigator<"u"&&navigator.platform.includes("Mac")?"⌘":"Ctrl";async function i(){try{await Ve.logout()}catch{}t("/login",{replace:!0})}return m.jsxs("header",{className:"h-11 flex items-center justify-between px-3 border-b border-line bg-surface",children:[m.jsxs("div",{className:"flex items-center gap-1",children:[m.jsx("button",{className:"btn btn-ghost !h-7 !w-7 !p-0 md:hidden",onClick:n,title:"Menu","aria-label":"Toggle sidebar",children:m.jsx(j6,{size:14})}),m.jsxs(va,{to:"/",className:"flex items-center gap-1.5 text-ink hover:opacity-90",children:[m.jsx("img",{src:"/favicon.svg",alt:"","aria-hidden":"true",className:"w-[18px] h-[18px]"}),m.jsx("span",{className:"text-xs font-semibold tracking-tight",children:"botnote"})]})]}),m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsxs("button",{className:"btn !pl-2 !pr-1.5 gap-2 md:min-w-[220px] !justify-between text-muted",onClick:()=>e({kind:"search"}),title:"Search (⌘K)",children:[m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsx(Dd,{size:12}),m.jsx("span",{className:"text-xs hidden sm:inline",children:"Search…"})]}),m.jsxs("kbd",{className:"hidden md:inline-block",children:[r,"K"]})]}),m.jsxs("button",{className:"btn btn-primary",onClick:()=>e({kind:"quick-create"}),title:"Quick create (c)",children:[m.jsx(Wc,{size:12}),m.jsx("span",{className:"text-xs hidden sm:inline",children:"New"}),m.jsx("kbd",{className:"!bg-white/15 !border-white/25 !text-white hidden md:inline-block",children:"c"})]}),m.jsx("button",{className:"btn !px-1.5 !py-1 text-muted hover:!text-red-500",onClick:i,title:"Log out","aria-label":"Log out",children:m.jsx(uj,{size:12})})]})]})}function mY(){t5();const[n,e]=M.useState(!1),t=Us();return M.useEffect(()=>{e(!1)},[t.pathname,t.search]),m.jsxs("div",{className:"h-full w-full flex flex-col",children:[m.jsx(pY,{onMenuClick:()=>e(r=>!r)}),m.jsxs("div",{className:"flex-1 min-h-0 flex",children:[m.jsx("div",{className:"hidden md:flex shrink-0",children:m.jsx(VP,{})}),m.jsx("main",{className:"flex-1 min-w-0 min-h-0 overflow-hidden bg-bg",children:m.jsx(_N,{})})]}),n&&m.jsxs("div",{className:"fixed inset-0 z-40 md:hidden",children:[m.jsx("div",{className:"absolute inset-0 bg-black/30",onClick:()=>e(!1)}),m.jsx("div",{className:"absolute inset-y-0 left-0 flex shadow-modal",children:m.jsx(VP,{})})]}),m.jsx(sY,{})]})}function ZE({icon:n,color:e,onIconChange:t,onColorChange:r}){return m.jsxs("div",{className:"space-y-2",children:[m.jsxs("div",{children:[m.jsx("div",{className:"text-xxs text-muted uppercase tracking-wider mb-1",children:"Color"}),m.jsx("div",{className:"flex flex-wrap gap-1.5",children:tY.map(i=>m.jsx("button",{type:"button",onClick:()=>r(i.value),className:"relative w-6 h-6 rounded-full border border-line/80 hover:scale-110 transition-transform",style:{backgroundColor:i.value},title:i.name,children:e===i.value&&m.jsx(Gi,{size:12,className:"absolute inset-0 m-auto text-white",strokeWidth:3})},i.value))})]}),m.jsxs("div",{children:[m.jsx("div",{className:"text-xxs text-muted uppercase tracking-wider mb-1",children:"Icon"}),m.jsx("div",{className:"flex flex-wrap gap-1",children:NE.map(i=>m.jsx("button",{type:"button",onClick:()=>t(i.name),className:`w-7 h-7 rounded flex items-center justify-center border transition-colors ${n===i.name?"border-accent bg-accentSoft":"border-line bg-surface hover:bg-sidebar"}`,title:i.name,children:m.jsx(el,{color:e,icon:i.name,size:14})},i.name))})]})]})}function Pc({title:n,children:e,width:t="max-w-2xl"}){const{close:r}=zt();return M.useEffect(()=>{const i=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=i}},[]),m.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-20 px-4 bg-ink/20",onClick:r,children:m.jsxs("div",{className:`w-full ${t} bg-surface border border-line rounded-lg shadow-2xl overflow-hidden`,onClick:i=>i.stopPropagation(),children:[m.jsxs("div",{className:"h-9 px-3 flex items-center justify-between border-b border-line",children:[m.jsx("div",{className:"text-xs font-semibold text-ink",children:n}),m.jsx("button",{onClick:r,className:"text-muted hover:text-ink p-0.5 rounded hover:bg-line/60",title:"Close (Esc)",children:m.jsx(bc,{size:14})})]}),e]})})}function gY({projectId:n}){const{data:e}=kF(n),t=_F(),{close:r}=zt(),[i,s]=M.useState(""),[l,o]=M.useState("active"),[u,h]=M.useState(LE),[f,p]=M.useState(_E);if(M.useEffect(()=>{e&&(s(e.name),o(e.status),h(e.color),p(e.icon))},[e==null?void 0:e.id,e==null?void 0:e.name,e==null?void 0:e.status,e==null?void 0:e.color,e==null?void 0:e.icon]),!e)return m.jsx(Pc,{title:"Project settings",width:"max-w-md",children:m.jsx("div",{className:"p-4 text-sm text-muted",children:"Loading…"})});const g=e,x=i!==g.name||l!==g.status||u!==g.color||f!==g.icon,k=i.trim().length>0;return m.jsx(Pc,{title:`Settings · ${g.key}`,width:"max-w-md",children:m.jsxs("form",{onSubmit:async b=>{b.preventDefault(),!(!x||!k)&&(await t.mutateAsync({id:g.id,fields:{name:i.trim(),status:l,color:u,icon:f}}),r())},className:"p-3 space-y-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Name"}),m.jsx("input",{autoFocus:!0,className:"input",value:i,onChange:b=>s(b.target.value)})]}),m.jsx(ZE,{icon:f,color:u,onIconChange:p,onColorChange:h}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Status"}),m.jsx("select",{className:"input",value:l,onChange:b=>o(b.target.value),children:$E.map(b=>m.jsxs("option",{value:b,children:[ql[b]," · ",zE[b]]},b))})]}),m.jsx("div",{className:"flex justify-end items-center pt-1",children:m.jsxs("div",{className:"flex gap-2",children:[m.jsx("button",{type:"button",className:"btn",onClick:r,children:"Cancel"}),m.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!x||!k||t.isPending,children:t.isPending?"Saving…":"Save"})]})}),t.error&&m.jsx("div",{className:"text-xs text-danger",children:t.error.message})]})})}function OY(){const[n,e]=M.useState(""),[t,r]=M.useState(""),[i,s]=M.useState("active"),[l,o]=M.useState(""),[u,h]=M.useState(LE),[f,p]=M.useState(_E),g=LF(),{close:x}=zt(),k=Gs(),b=/^[A-Z][A-Z0-9_]{0,19}$/.test(n)&&t.trim().length>0;return m.jsx(Pc,{title:"New project",width:"max-w-md",children:m.jsxs("form",{onSubmit:async w=>{if(w.preventDefault(),!b)return;const S=await g.mutateAsync({key:n.trim(),name:t.trim(),status:i,color:u,icon:f,agentsMd:l.trim()});x(),k(`/p/${S.key}`)},className:"p-3 space-y-3",children:[m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Key (uppercase, e.g. BOT)"}),m.jsx("input",{autoFocus:!0,className:"input font-mono uppercase",value:n,onChange:w=>e(w.target.value.toUpperCase()),placeholder:"BOT",maxLength:20})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Name"}),m.jsx("input",{className:"input",value:t,onChange:w=>r(w.target.value),placeholder:"botnote"})]}),m.jsx(ZE,{icon:f,color:u,onIconChange:p,onColorChange:h}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"Status"}),m.jsx("select",{className:"input",value:i,onChange:w=>s(w.target.value),children:$E.map(w=>m.jsxs("option",{value:w,children:[ql[w]," · ",zE[w]]},w))})]}),m.jsxs("div",{children:[m.jsx("label",{className:"block text-xxs text-muted uppercase tracking-wider mb-1",children:"AGENTS.md (optional)"}),m.jsx("textarea",{className:"input !h-24 py-1.5 font-mono text-xs leading-snug resize-y",value:l,onChange:w=>o(w.target.value),placeholder:`## Critical
480
480
  - ALWAYS run pnpm typecheck before commit.`})]}),m.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[m.jsx("button",{type:"button",className:"btn",onClick:x,children:"Cancel"}),m.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!b||g.isPending,children:g.isPending?"Creating…":"Create project"})]}),g.error&&m.jsx("div",{className:"text-xs text-danger",children:g.error.message})]})})}function xY({initialProjectId:n,initialKind:e,initialParentId:t}){const{data:r}=Vn(),[i,s]=M.useState(e??"task"),[l,o]=M.useState(n??""),[u,h]=M.useState(""),[f,p]=M.useState(""),[g,x]=M.useState(""),[k,b]=M.useState(""),[w,S]=M.useState("none"),[Q,$]=M.useState("none"),[R,I]=M.useState(1),[T,X]=M.useState("scheduled"),[Z,H]=M.useState(!1),[N,U]=M.useState(t??""),V=QE(),se=CE(),{close:K}=zt(),{open:G}=Si(),Oe=r==null?void 0:r.find(C=>C.id===l),de=i==="note",{data:ee}=U0(de&&l?l:void 0,["task"]),le=l.length>0&&(de?u.trim().length>0||f.trim().length>0:u.trim().length>0&&(Q==="none"||k.length>0));return m.jsx(Pc,{title:"Quick create",width:"max-w-xl",children:m.jsxs("form",{onSubmit:async C=>{if(C.preventDefault(),!le)return;const D=u.trim(),F=g.split(",").map(ce=>ce.trim()).filter(Boolean),E=i==="task"?await V.mutateAsync({kind:"task",projectId:l,title:D,body:f.trim(),tags:F,actorKind:"human",dueAt:k?new Date(k).toISOString():null,priority:w}):await V.mutateAsync({kind:"note",projectId:l,title:D||null,body:f.trim(),tags:F,actorKind:"human",pinned:Z,parentId:N||null});i==="task"&&Q!=="none"&&await se.mutateAsync({taskId:E.id,input:{preset:Q,interval:R,anchor:T,timezone:Intl.DateTimeFormat().resolvedOptions().timeZone,allDay:!0}}),K(),G(E.id)},className:"p-3 space-y-3",children:[m.jsxs("div",{className:"flex gap-2",children:[m.jsx("div",{className:"seg w-32",children:WF.map(C=>m.jsx("button",{type:"button","data-active":i===C,onClick:()=>s(C),className:"flex-1 justify-center capitalize",children:C},C))}),m.jsxs("select",{className:"input flex-1",value:l,onChange:C=>o(C.target.value),children:[m.jsx("option",{value:"",children:"— pick a project —"}),r==null?void 0:r.map(C=>m.jsxs("option",{value:C.id,children:[C.key," · ",C.name]},C.id))]})]}),m.jsx("input",{autoFocus:!0,className:"input",placeholder:de?"Title (optional)":"Title",value:u,onChange:C=>h(C.target.value)}),m.jsx("textarea",{className:"input !h-32 py-1.5 font-mono text-xs leading-snug resize-y",placeholder:"Body (Markdown, optional)",value:f,onChange:C=>p(C.target.value)}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx("input",{className:"input flex-1",placeholder:"Tags (comma-separated, optional)",value:g,onChange:C=>x(C.target.value)}),i==="task"&&m.jsxs(m.Fragment,{children:[m.jsx("input",{type:"date",className:"input w-36",value:k,onChange:C=>b(C.target.value),title:"Due date"}),m.jsx("select",{className:"input w-36",value:w,onChange:C=>S(C.target.value),title:"Priority",children:TE.map(C=>m.jsx("option",{value:C,children:Oa[C]},C))})]})]}),i==="task"&&m.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_84px_132px] gap-2",children:[m.jsxs("select",{className:"input",value:Q,onChange:C=>$(C.target.value),title:"Repeat",children:[m.jsx("option",{value:"none",children:"Repeat: none"}),m.jsx("option",{value:"hourly",children:"Hourly"}),m.jsx("option",{value:"daily",children:"Daily"}),m.jsx("option",{value:"weekly",children:"Weekly"}),m.jsx("option",{value:"monthly",children:"Monthly"}),m.jsx("option",{value:"yearly",children:"Yearly"})]}),m.jsx("input",{type:"number",min:1,max:999,className:"input",value:R,disabled:Q==="none",onChange:C=>I(Math.max(1,Number(C.target.value)||1)),title:"Repeat interval"}),m.jsxs("select",{className:"input",value:T,disabled:Q==="none",onChange:C=>X(C.target.value),title:"Repeat anchor",children:[m.jsx("option",{value:"scheduled",children:"Scheduled"}),m.jsx("option",{value:"completion",children:"Completion"})]})]}),i==="task"&&w!=="none"&&m.jsxs("div",{className:"flex items-center gap-1.5 text-xxs text-muted",children:[m.jsx(ga,{priority:w,size:11}),m.jsxs("span",{children:[Oa[w]," priority"]})]}),de&&m.jsxs(m.Fragment,{children:[m.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted cursor-pointer",children:[m.jsx("input",{type:"checkbox",checked:Z,onChange:C=>H(C.target.checked)}),m.jsx("span",{children:"📌 Pin to project — auto-include in agent opening brief"})]}),ee&&ee.length>0&&m.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted",children:[m.jsx("span",{className:"shrink-0",children:"Link to task:"}),m.jsxs("select",{className:"input flex-1 !h-7 text-xs",value:N,onChange:C=>U(C.target.value),children:[m.jsx("option",{value:"",children:"— none —"}),ee.map(C=>m.jsxs("option",{value:C.id,children:[Oe!=null&&Oe.key&&C.sequenceId?`${Oe.key}-${C.sequenceId} · `:"",on(C)]},C.id))]})]})]}),m.jsxs("div",{className:"flex justify-between items-center pt-1",children:[m.jsxs("div",{className:"text-xxs text-muted",children:[m.jsx("kbd",{children:"⌘"}),"+",m.jsx("kbd",{children:"Enter"})," to submit · ",m.jsx("kbd",{children:"Esc"})," to close"]}),m.jsxs("div",{className:"flex gap-2",children:[m.jsx("button",{type:"button",className:"btn",onClick:K,children:"Cancel"}),m.jsx("button",{type:"submit",className:"btn btn-primary",disabled:!le||V.isPending,children:V.isPending?"Creating…":`Create ${i}`})]})]}),V.error&&m.jsx("div",{className:"text-xs text-danger",children:V.error.message})]})})}const yY={task:"task",note:"note",comment:"comment",feedback:"feedback"};function kY(){const[n,e]=M.useState(""),[t,r]=M.useState(""),{close:i}=zt(),{open:s}=Si(),{data:l}=Vn();M.useEffect(()=>{const f=setTimeout(()=>r(n.trim()),200);return()=>clearTimeout(f)},[n]);const{data:o,isFetching:u}=SE(t?{query:t,limit:20}:null),h=M.useMemo(()=>{const f=new Map;return l==null||l.forEach(p=>f.set(p.id,p.key)),f},[l]);return m.jsxs(Pc,{title:"Search",children:[m.jsx("div",{className:"p-3 pb-1",children:m.jsxs("div",{className:"flex items-center gap-2 px-2 h-9 border border-line rounded bg-surface focus-within:border-accent focus-within:ring-1 focus-within:ring-accentSoft",children:[m.jsx(Dd,{size:14,className:"text-muted"}),m.jsx("input",{autoFocus:!0,placeholder:"Hybrid search (BM25 + vector + time decay)",className:"flex-1 bg-transparent border-none outline-none text-sm",value:n,onChange:f=>e(f.target.value)}),u&&m.jsx("span",{className:"text-xxs text-muted",children:"searching…"})]})}),m.jsxs("div",{className:"max-h-[60vh] overflow-y-auto scrollbar-thin",children:[t&&!u&&(!o||o.hits.length===0)&&m.jsx("div",{className:"px-4 py-6 text-center text-sm text-muted",children:"No matches."}),o==null?void 0:o.hits.map(f=>{const p=f.entity.projectId?h.get(f.entity.projectId):null;return m.jsxs("button",{onClick:()=>{i(),s(f.entity.id)},className:"w-full px-3 py-2 row-hover text-left flex items-start gap-3 border-t border-line/60",children:[m.jsx("span",{className:"chip mt-0.5",children:yY[f.entity.kind]}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:"text-sm text-ink truncate",children:on(f.entity)}),m.jsx("div",{className:"text-xs text-muted truncate mt-0.5",children:f.entity.body.replace(/\n/g," ").slice(0,140)||"—"}),m.jsxs("div",{className:"text-xxs text-faint mt-0.5 flex gap-2",children:[p&&m.jsxs("span",{children:["· ",p]}),m.jsxs("span",{children:["· score ",f.score.toFixed(3)]}),f.components.bm25&&m.jsx("span",{children:"· bm25"}),f.components.cosine&&m.jsx("span",{children:"· vec"})]})]}),m.jsx(n6,{size:13,className:"text-faint mt-1"})]},f.entity.id)}),o&&m.jsxs("div",{className:"px-3 py-2 text-xxs text-muted border-t border-line/60",children:[o.hits.length," result(s) · embedding ",o.embeddingUsed?"ON":"OFF (BM25-only)"]})]})]})}function vY(){const{active:n}=zt();if(!n)return null;switch(n.kind){case"search":return m.jsx(kY,{});case"quick-create":return m.jsx(xY,{initialProjectId:n.projectId,initialKind:n.initialKind,initialParentId:n.parentId});case"new-project":return m.jsx(OY,{});case"edit-project":return m.jsx(gY,{projectId:n.projectId})}}const bY=`## Critical
481
481
  - NEVER commit credentials.
482
482
  - ALWAYS run tests before commit.
@@ -544,5 +544,5 @@ BOTNOTE_TOKEN = "bn_..."`}],r=[{note:"Create a task:",code:`curl -X POST '${Jf}/
544
544
  -d '{ "body": "Quick capture", "pinned": false }'`},{note:"Hybrid search:",code:`curl -X POST '${Jf}/v1/search' \\
545
545
  -H 'authorization: Bearer bn_...' \\
546
546
  -H 'content-type: application/json' \\
547
- -d '{ "query": "deployment", "limit": 10 }'`}];return m.jsxs(m.Fragment,{children:[m.jsx(Hl,{title:"MCP (raw integration)",blurb:"Skip the Claude Code plugin and wire the MCP server in by hand — for Codex, custom agents, or any MCP-aware client. The botnote binary doubles as the MCP stdio server."}),m.jsx(kG,{title:"Claude Code (~/.claude.json or project-local .mcp.json)",code:n}),m.jsx(Cc,{title:"Codex (~/.codex/config.toml)",steps:t}),m.jsx(Cc,{title:"REST · curl",steps:r}),m.jsxs("div",{className:"border border-line rounded-md bg-surface px-4 py-3 text-xs text-muted leading-relaxed",children:["Raw MCP configuration requires the ",m.jsx("code",{className:"text-ink",children:"botnote"})," binary in",m.jsx("code",{className:"text-ink",children:" PATH"})," ","(",m.jsx("code",{className:"text-ink",children:"npm i -g botnote"}),"). The Claude Code and Codex plugins do not require a global CLI install; they run the matching npm package version automatically. The MCP server has no DB connection of its own; it speaks HTTP to whichever"," ",m.jsx("code",{className:"text-ink",children:"BOTNOTE_URL"})," you set."]})]})}function xG(){const{data:n,isLoading:e}=yF(),t=n!=null&&n.version?`v${n.version}`:e?"loading...":"unknown";return m.jsxs(m.Fragment,{children:[m.jsx(Hl,{title:"About",blurb:"Build + runtime info for this daemon."}),m.jsxs("div",{className:"border border-line rounded-md bg-surface px-4 py-3 text-xs text-muted space-y-2",children:[m.jsxs("div",{children:[m.jsxs("span",{className:"text-ink",children:["botnote ",t]})," — Postgres 16 + pgvector + Fastify 5 + MCP SDK"]}),m.jsxs("div",{children:["REST: ",m.jsx("code",{className:"text-ink",children:Jf})," · docs:"," ",m.jsx("a",{className:"text-accent hover:underline",href:"/docs",target:"_blank",rel:"noreferrer",children:"/docs"})]}),m.jsxs("div",{className:"pt-1 border-t border-lineSoft",children:["Auth is enforced when ",m.jsx("code",{className:"text-ink",children:"BOTNOTE_REQUIRE_AUTH=1"})," on the daemon. Direct connections from loopback or private networks are trusted; requests via Cloudflare Tunnel (or any proxy that sets ",m.jsx("code",{children:"cf-connecting-ip"})," /"," ",m.jsx("code",{children:"x-forwarded-for"}),") require a bearer token or a browser session cookie."]})]})]})}function Cc({title:n,steps:e}){return m.jsxs("div",{className:"border border-line rounded-md bg-surface overflow-hidden",children:[m.jsx("div",{className:"px-3 py-1.5 border-b border-lineSoft bg-sidebar/40",children:m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:n})}),m.jsx("div",{className:"px-3 py-3 space-y-3",children:e.map((t,r)=>m.jsxs("div",{className:"space-y-1.5",children:[t.note&&m.jsx("p",{className:"text-xs text-muted leading-relaxed",children:t.note}),t.code&&m.jsx(JE,{code:t.code})]},r))})]})}function JE({code:n}){const[e,t]=M.useState(!1);function r(){navigator.clipboard.writeText(n).then(()=>{t(!0),setTimeout(()=>t(!1),1400)})}return m.jsxs("div",{className:"relative border border-lineSoft rounded-md bg-sidebar/30",children:[m.jsx("pre",{className:"px-3 py-2 pr-9 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre text-ink2",children:n}),m.jsx("button",{onClick:r,className:"absolute top-1.5 right-1.5 p-1 rounded text-faint hover:text-ink hover:bg-sidebarHover transition-colors",title:"Copy command",children:e?m.jsx(Gi,{size:12,className:"text-success"}):m.jsx(kc,{size:12})})]})}function eM({title:n,items:e}){return m.jsxs("div",{className:"border border-line rounded-md bg-surface overflow-hidden",children:[m.jsx("div",{className:"px-3 py-1.5 border-b border-lineSoft bg-sidebar/40",children:m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:n})}),m.jsx("ul",{className:"divide-y divide-lineSoft",children:e.map(t=>m.jsx(yG,{code:t.code,desc:t.desc},t.code))})]})}function yG({code:n,desc:e}){const[t,r]=M.useState(!1);function i(){navigator.clipboard.writeText(n).then(()=>{r(!0),setTimeout(()=>r(!1),1400)})}return m.jsxs("li",{className:"group flex items-center gap-3 px-3 py-1.5",children:[m.jsx("code",{className:"font-mono text-xs text-ink whitespace-nowrap overflow-x-auto scrollbar-thin",children:n}),m.jsx("span",{className:"flex-1 text-xs text-muted text-right truncate",children:e}),m.jsx("button",{onClick:i,className:`p-1 rounded transition-colors ${t?"text-success":"text-faint hover:text-ink opacity-0 group-hover:opacity-100 focus:opacity-100"}`,title:"Copy command",children:t?m.jsx(Gi,{size:12}):m.jsx(kc,{size:12})})]})}function kG({title:n,code:e}){const[t,r]=M.useState(!1);function i(){navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1400)})}return m.jsxs("div",{className:"border border-line rounded-md bg-surface overflow-hidden",children:[m.jsxs("div",{className:"px-3 py-1.5 border-b border-lineSoft flex items-center justify-between bg-sidebar/40",children:[m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:n}),m.jsxs("button",{onClick:i,className:"text-xxs text-muted hover:text-ink flex items-center gap-1",children:[t?m.jsx(Gi,{size:11}):m.jsx(kc,{size:11}),t?"Copied":"Copy"]})]}),m.jsx("pre",{className:"px-3 py-2 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre bg-sidebar/20 text-ink2",children:e})]})}function vG(){const{data:n,isLoading:e}=IF(),t=zF(),r=ZF(),[i,s]=M.useState(""),[l,o]=M.useState(null),[u,h]=M.useState(null),[f,p]=M.useState(null),[g,x]=M.useState(null);function k(S){navigator.clipboard.writeText(S.plaintext).then(()=>{x(S.id),setTimeout(()=>x(Q=>Q===S.id?null:Q),1400)})}async function b(S){if(S.preventDefault(),!i.trim())return;const Q=await t.mutateAsync(i.trim());o(Q),s("")}async function w(S,Q){if(!u&&confirm(`Revoke token "${Q}"? Any client using it stops working.`)){h(S),p(null);try{await r.mutateAsync(S),(l==null?void 0:l.id)===S&&o(null)}catch($){const R=$ instanceof Error?$.message:String($);p(`Could not revoke "${Q}": ${R}`)}finally{h($=>$===S?null:$)}}}return m.jsxs(m.Fragment,{children:[m.jsx(Hl,{title:"API tokens",blurb:"Bearer tokens for the CLI, MCP server, and direct REST calls. New tokens keep their full value available for copying here; older tokens created before this change only have a prefix and must be regenerated if the full value was lost."}),l&&m.jsxs("div",{className:"border border-warn rounded-md bg-warn/10 p-3 space-y-2",children:[m.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-warn",children:[m.jsx(W6,{size:13}),"Copy this token now, or later from the token list."]}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-xs font-mono bg-surface border border-line rounded px-2 py-1 overflow-x-auto whitespace-nowrap",children:l.plaintext}),m.jsxs("button",{className:"btn",onClick:()=>navigator.clipboard.writeText(l.plaintext),children:[m.jsx(kc,{size:11})," Copy"]}),m.jsx("button",{className:"btn",onClick:()=>o(null),children:"Done"})]})]}),f&&m.jsx("div",{className:"border border-danger/30 rounded-md bg-danger/10 px-3 py-2 text-xs text-danger",children:f}),m.jsxs("form",{onSubmit:b,className:"flex gap-2",children:[m.jsx("input",{className:"input flex-1",placeholder:"Token name (e.g. claude-code-laptop)",value:i,onChange:S=>s(S.target.value)}),m.jsxs("button",{type:"submit",className:"btn btn-primary",disabled:!i.trim()||t.isPending,children:[m.jsx(Wc,{size:11})," ",t.isPending?"Generating…":"Generate"]})]}),m.jsxs("div",{className:"border border-line rounded-md bg-surface divide-y divide-lineSoft overflow-hidden",children:[e&&m.jsx("div",{className:"p-3 text-xs text-muted",children:"Loading…"}),!e&&(!n||n.length===0)&&m.jsx("div",{className:"p-4 text-xs text-faint text-center",children:"No tokens yet."}),n==null?void 0:n.map(S=>{const Q=g===S.id;return m.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:"text-sm text-ink truncate",children:S.name}),m.jsxs("div",{className:"text-xxs text-muted flex items-center gap-3 mt-0.5",children:[m.jsxs("code",{className:"font-mono text-faint",children:[S.prefix,"…"]}),m.jsxs("span",{children:["created ",xy(new Date(S.createdAt),{addSuffix:!0})]}),m.jsx("span",{children:S.lastUsedAt?`used ${xy(new Date(S.lastUsedAt),{addSuffix:!0})}`:"never used"})]})]}),S.plaintext?m.jsxs("button",{type:"button",onClick:()=>k({id:S.id,plaintext:S.plaintext}),className:`btn gap-1.5 ${Q?"!border-emerald-500/30 !text-emerald-600":""}`,title:"Copy full token",children:[Q?m.jsx(Gi,{size:11}):m.jsx(kc,{size:11}),Q?"Copied":"Copy token"]}):m.jsx("span",{className:"text-xxs text-faint border border-line rounded px-2 py-1",title:"Full token is unavailable for tokens created before recoverable storage was enabled.",children:"Unavailable"}),m.jsx("button",{type:"button",className:"text-faint hover:text-danger p-1 -m-1",disabled:u!==null,onClick:()=>w(S.id,S.name),title:u===S.id?"Revoking":"Revoke",children:u===S.id?m.jsx("span",{className:"text-xxs text-muted",children:"Revoking…"}):m.jsx(vc,{size:12})})]},S.id)})]})]})}function bG({anchor:n,projectIds:e}){const t=K0("day",n),{data:r}=Yl({from:t.from.toISOString(),to:t.to.toISOString(),projectIds:e??null,includeBacklog:!1,includeDone:!0}),{data:i}=Vn(),s=M.useMemo(()=>Gl(i),[i]),{open:l}=zt(),o=((r==null?void 0:r.overdue)??[]).filter(f=>Ma(f,n)),u=((r==null?void 0:r.scheduled)??[]).slice().sort(bp),h=vp(n);return m.jsx("div",{className:"h-full overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"max-w-4xl mx-auto py-4",children:[h&&o.length>0&&m.jsx(sC,{title:"Overdue",count:o.length,accent:"text-danger",tasks:o,projectMap:s}),m.jsx(sC,{title:h?"Today":Ft(n,"EEEE"),count:u.length,accent:"text-ink",tasks:u,projectMap:s,emptyAction:m.jsx("button",{className:"text-accent text-xs hover:underline",onClick:()=>l({kind:"quick-create"}),children:"+ add a task for this day"})})]})})}function sC({title:n,count:e,accent:t,tasks:r,projectMap:i,emptyAction:s}){return m.jsxs("section",{className:"mb-6",children:[m.jsxs("div",{className:"px-4 py-1.5 flex items-baseline gap-2 sticky top-0 bg-bg z-10",children:[m.jsx("h2",{className:`text-xs font-semibold ${t}`,children:n}),m.jsx("span",{className:"text-xxs text-faint tabular-nums",children:e})]}),r.length===0?m.jsx("div",{className:"px-4 py-2 text-xs text-muted",children:s??"Nothing here."}):m.jsx("div",{className:"bg-surface border-y border-lineSoft",children:r.map(l=>m.jsx(wp,{task:l,project:l.projectId?i.get(l.projectId):void 0},l.id))})]})}function wG({projectIds:n,collapsed:e,onToggle:t}){const{data:r}=Yl({projectIds:n??null,includeBacklog:!0,includeDone:!1}),{data:i}=Vn(),s=M.useMemo(()=>Gl(i),[i]),l=((r==null?void 0:r.backlog)??[]).filter(u=>u.status!=="rejected"),o=M.useMemo(()=>{const u=new Map;for(const f of l){const p=f.projectId??null,g=u.get(p);g?g.push(f):u.set(p,[f])}const h=[];for(const[f,p]of u)h.push({project:f?s.get(f):void 0,tasks:p});return h.sort((f,p)=>f.project?p.project?f.project.key.localeCompare(p.project.key):-1:1),h},[l,s]);return e?m.jsxs("button",{className:"shrink-0 w-8 border-l border-line bg-sidebar/50 hover:bg-sidebar flex flex-col items-center pt-2 gap-2 group",onClick:t,title:"Expand Inbox",children:[m.jsx(_d,{size:14,className:"text-muted group-hover:text-ink"}),l.length>0&&m.jsx("div",{className:"text-xxs text-muted bg-surface border border-line rounded-full w-5 h-5 flex items-center justify-center",children:l.length})]}):m.jsxs("aside",{className:"shrink-0 w-72 border-l border-line bg-surface flex flex-col",children:[m.jsxs("div",{className:"px-3 h-9 flex items-center justify-between border-b border-lineSoft",children:[m.jsxs("div",{className:"flex items-center gap-2 text-muted",children:[m.jsx(_d,{size:12}),m.jsx("h2",{className:"text-xs font-medium text-ink2",children:"Inbox"}),m.jsx("span",{className:"text-xxs text-faint tabular-nums",children:l.length})]}),m.jsx("button",{onClick:t,className:"btn-ghost btn !h-6 !w-6 !p-0",title:"Collapse",children:"→"})]}),m.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-thin",children:l.length===0?m.jsxs("div",{className:"text-xs text-muted text-center py-8 px-4",children:["No tasks without due date.",m.jsx("div",{className:"text-faint mt-1",children:"Tasks without due date appear here."})]}):o.map(({project:u,tasks:h})=>m.jsxs("div",{children:[m.jsxs("div",{className:"sticky top-0 z-10 flex items-center gap-1.5 px-3 py-1 bg-surface border-b border-lineSoft",children:[m.jsx("span",{className:"font-mono text-xxs text-faint tabular-nums",children:(u==null?void 0:u.key)??"—"}),m.jsx("span",{className:"text-xxs text-muted truncate",children:(u==null?void 0:u.name)??"No project"}),m.jsx("span",{className:"ml-auto text-xxs text-faint tabular-nums",children:h.length})]}),h.map(f=>m.jsx(wp,{task:f,project:u,showProject:!1,compact:!0},f.id))]},(u==null?void 0:u.id)??"none"))})]})}function SG({virtual:n,project:e}){const t=n.title&&n.title.trim()?n.title:"Untitled";return m.jsxs("div",{"aria-label":`Upcoming — will be created automatically: ${t}`,className:"pointer-events-none w-full text-left flex items-center gap-1.5 pl-1 pr-1.5 py-1 rounded text-xs opacity-40 border border-dashed border-current",children:[m.jsx("span",{className:"w-[2px] self-stretch rounded-sm shrink-0",style:{backgroundColor:(e==null?void 0:e.color)??"#a8a8af"}}),m.jsx("span",{className:"truncate flex-1 min-w-0 text-ink2 italic",children:t}),m.jsx(Uc,{size:11,className:"text-faint"})]})}function tM({virtuals:n,projectMap:e}){if(n.length===0)return null;if(n.length===1){const r=n[0];return m.jsx(SG,{virtual:r,project:r.projectId?e.get(r.projectId):void 0})}const t=n.map(r=>r.title&&r.title.trim()?r.title:"Untitled").join(`
548
- `);return m.jsxs("div",{title:t,"aria-label":`${n.length} upcoming recurring tasks: ${t}`,className:"w-full flex items-center gap-1.5 pl-1 pr-1.5 py-1 rounded text-xs opacity-40 border border-dashed border-current",children:[m.jsx(Uc,{size:11,className:"text-faint shrink-0"}),m.jsxs("span",{className:"truncate flex-1 min-w-0 text-ink2 italic",children:["+",n.length," recurring"]})]})}function nM({task:n,project:e}){const t=Si(),r=Ma(n);return m.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:i=>{i.dataTransfer.setData("text/task-id",n.id),i.dataTransfer.effectAllowed="move",i.stopPropagation()},onClick:()=>t.open(n.id),onKeyDown:i=>{i.key!=="Enter"&&i.key!==" "||(i.preventDefault(),t.open(n.id))},className:`group w-full text-left flex items-center gap-1.5 pl-1 pr-1.5 py-1 rounded text-xs hover:bg-sidebarHover transition-colors cursor-grab active:cursor-grabbing ${r?"bg-danger/5":""}`,title:e?`${e.key} · ${on(n)}`:on(n),children:[m.jsx("span",{className:"w-[2px] self-stretch rounded-sm shrink-0",style:{backgroundColor:(e==null?void 0:e.color)??"#a8a8af"}}),m.jsx(yp,{task:n,size:11}),m.jsx("span",{className:`truncate flex-1 min-w-0 ${n.status==="done"?"line-through text-muted":n.status==="rejected"?"text-muted":Tr(n)?"italic text-muted":"text-ink2"}`,children:on(n)}),J0(n)&&m.jsx(Uc,{size:11,className:"text-faint"}),n.priority!=="none"&&m.jsx(ga,{priority:n.priority,size:11})]})}const PG=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];function CG({anchor:n,projectIds:e}){const t=K0("month",n),r=HE(t.from,t.to),{data:i}=Yl({from:t.from.toISOString(),to:t.to.toISOString(),projectIds:e??null,includeBacklog:!1,includeDone:!0,includeVirtualRecurrences:!0}),{data:s}=Vn(),l=M.useMemo(()=>Gl(s),[s]),o=M.useMemo(()=>UE((i==null?void 0:i.scheduled)??[]),[i]),u=M.useMemo(()=>GE((i==null?void 0:i.virtualOccurrences)??[]),[i]);return m.jsxs("div",{className:"h-full flex flex-col",children:[m.jsx("div",{className:"grid grid-cols-7 border-b border-lineSoft bg-sidebar/50",children:PG.map(h=>m.jsx("div",{className:"px-2 py-1 text-xxs uppercase tracking-wider text-muted text-center",children:h},h))}),m.jsx("div",{className:"flex-1 grid grid-cols-7 grid-rows-6 bg-line/30 gap-px overflow-y-auto scrollbar-thin",children:r.map(h=>{const f=o.get(Vd(h))??[],p=u.get(Vd(h))??[],g=!zU(h,n),x=vp(h);return m.jsx(QG,{day:h,tasks:f,virtuals:p,projectMap:l,outOfMonth:g,today:x},h.toISOString())})})]})}function QG({day:n,tasks:e,virtuals:t,projectMap:r,outOfMonth:i,today:s}){const{open:l}=zt(),o=Js(),[u,h]=M.useState(!1),f=e.slice().sort(bp),p=f.filter(b=>b.status==="done").length,g=f.length,x=g>0&&p===g;function k(b){b.preventDefault(),h(!1);const w=b.dataTransfer.getData("text/task-id");if(!w)return;const S=new Date(n);S.setHours(12,0,0,0),o.mutate({id:w,fields:{dueAt:S.toISOString()}})}return m.jsxs("div",{className:`group bg-surface p-1 min-h-[112px] flex flex-col transition-colors ${i?"opacity-50":""} ${u?"ring-2 ring-accent ring-inset bg-accentSoft/40":s?"ring-1 ring-accent ring-inset bg-accentSoft/30":""}`,onDragOver:b=>{b.preventDefault(),u||h(!0)},onDragLeave:()=>h(!1),onDrop:k,children:[m.jsxs("div",{className:"flex items-center justify-between mb-1 px-1",children:[m.jsxs("div",{className:"flex items-baseline gap-1.5 min-w-0",children:[m.jsx("span",{className:`text-xs tabular-nums ${s?"font-semibold text-accent":"text-muted"}`,children:Ft(n,"d")}),g>0&&m.jsxs("span",{className:`text-xxs tabular-nums ${x?"text-statusDone font-medium":"text-faint"}`,title:`${p} done · ${g} total`,children:[p,"/",g]})]}),m.jsx("button",{className:"text-xs text-faint hover:text-accent opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>l({kind:"quick-create"}),title:"Add task",children:"+"})]}),m.jsxs("div",{className:"flex-1 space-y-0.5 min-h-0 overflow-hidden",children:[f.slice(0,4).map(b=>m.jsx(nM,{task:b,project:b.projectId?r.get(b.projectId):void 0},b.id)),f.length>4&&m.jsxs("div",{className:"text-xxs text-muted pl-1",children:["+",f.length-4]}),m.jsx(tM,{virtuals:t,projectMap:r})]})]})}function $G({view:n,setView:e,anchor:t,setAnchor:r,projectIds:i,setProjectIds:s}){var h;const{data:l}=Vn(),{open:o}=zt(),u=i?i.length===1?((h=l==null?void 0:l.find(f=>f.id===i[0]))==null?void 0:h.key)??"1 project":`${i.length} projects`:"All projects";return m.jsx("div",{className:"border-b border-line bg-surface",children:m.jsxs("div",{className:"flex items-center justify-between h-11 px-3",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[m.jsx("h1",{className:"text-xs font-semibold text-ink hidden sm:block",children:"Tasks"}),m.jsx("div",{className:"seg hidden md:flex",children:["day","week","month"].map(f=>m.jsx("button",{onClick:()=>e(f),"data-active":n===f,className:"capitalize",children:f},f))}),m.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[m.jsx("button",{onClick:()=>r(QO(n,t,-1)),className:"btn btn-ghost !h-6 !w-6 !p-0",title:"Previous",children:m.jsx(lj,{size:12})}),m.jsx("button",{onClick:()=>r(QO(n,t,0)),className:"btn !h-6 px-2 text-xxs",title:"Today",children:"Today"}),m.jsx("button",{onClick:()=>r(QO(n,t,1)),className:"btn btn-ghost !h-6 !w-6 !p-0",title:"Next",children:m.jsx(Bc,{size:12})}),m.jsx("div",{className:"ml-2 text-xs font-medium text-ink2 tabular-nums",children:ZU(n,t)})]})]}),m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsx(TG,{projects:l??[],projectIds:i,setProjectIds:s,label:u}),m.jsxs("button",{className:"btn btn-primary",onClick:()=>o({kind:"quick-create"}),title:"New task (c)",children:[m.jsx(Wc,{size:11}),m.jsx("span",{className:"text-xs hidden sm:inline",children:"Task"}),m.jsx("kbd",{className:"!bg-white/15 !border-white/25 !text-white hidden md:inline-block",children:"c"})]})]})]})})}function TG({projects:n,projectIds:e,setProjectIds:t,label:r}){return m.jsxs("details",{className:"relative",children:[m.jsxs("summary",{className:"btn list-none cursor-pointer",children:[m.jsx(m6,{size:11}),m.jsx("span",{className:"text-xs",children:r})]}),m.jsxs("div",{className:"popover top-9 right-0 w-56 px-1 py-1.5",children:[m.jsxs("button",{className:`popover-item ${e?"":"bg-accentSoft text-accentText"}`,onClick:()=>t(null),children:[m.jsx("span",{children:"All projects"}),!e&&m.jsx("span",{className:"ml-auto text-faint",children:"✓"})]}),m.jsx("div",{className:"divider my-1"}),n.map(i=>{const s=(e==null?void 0:e.includes(i.id))??!1;return m.jsxs("label",{className:"popover-item gap-2 cursor-pointer",children:[m.jsx("input",{type:"checkbox",className:"cursor-pointer",checked:s,onChange:()=>{if(!e)t([i.id]);else if(s){const l=e.filter(o=>o!==i.id);t(l.length?l:null)}else t([...e,i.id])}}),m.jsx("span",{className:"font-mono text-xxs text-faint tabular-nums",children:i.key}),m.jsx("span",{className:"text-ink2 truncate",children:i.name})]},i.id)})]})]})}function jG({anchor:n,projectIds:e}){const t=K0("week",n),r=HE(t.from,t.to),i=kp(r[r.length-1],1),s=[...r,i],l=new Date(i);l.setHours(23,59,59,999);const{data:o}=Yl({from:t.from.toISOString(),to:l.toISOString(),projectIds:e??null,includeBacklog:!1,includeDone:!0,includeVirtualRecurrences:!0}),{data:u}=Vn(),h=M.useMemo(()=>Gl(u),[u]),f=M.useMemo(()=>UE((o==null?void 0:o.scheduled)??[]),[o]),p=M.useMemo(()=>GE((o==null?void 0:o.virtualOccurrences)??[]),[o]),g=s.slice(0,4),x=s.slice(4);return m.jsxs("div",{className:"h-full flex flex-col bg-bg",children:[m.jsx(lC,{days:g,byDay:f,virtualsByDay:p,projectMap:h,anchor:n}),m.jsx(lC,{days:x,byDay:f,virtualsByDay:p,projectMap:h,anchor:n})]})}function lC({days:n,byDay:e,virtualsByDay:t,projectMap:r,anchor:i}){return m.jsx("div",{className:"flex-1 min-h-0 flex border-b border-line last:border-b-0",children:n.map(s=>{const l=e.get(Vd(s))??[],o=t.get(Vd(s))??[],u=!IU(s,i,{weekStartsOn:1});return m.jsx(EG,{day:s,tasks:l,virtuals:o,projectMap:r,outOfWeek:u},s.toISOString())})})}function EG({day:n,tasks:e,virtuals:t,projectMap:r,outOfWeek:i}){const s=vp(n),{open:l}=zt(),o=Js(),u=e.slice().sort(bp),h=u.filter(x=>x.status==="done").length,f=u.length,p=f>0&&h===f;function g(x){x.preventDefault();const k=x.dataTransfer.getData("text/task-id");if(!k)return;const b=new Date(n);b.setHours(12,0,0,0),o.mutate({id:k,fields:{dueAt:b.toISOString()}})}return m.jsxs("div",{className:`flex-1 min-w-0 border-r border-lineSoft last:border-r-0 flex flex-col group/col ${s?"bg-accentSoft/30":i?"bg-sidebar/40":"bg-surface"}`,onDragOver:x=>x.preventDefault(),onDrop:g,children:[m.jsxs("div",{className:"px-3 py-1.5 flex items-baseline justify-between border-b border-lineSoft",children:[m.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted",children:Ft(n,"EEE")}),m.jsx("span",{className:`text-sm tabular-nums font-semibold ${s?"text-accent":i?"text-muted":"text-ink2"}`,children:Ft(n,"d")}),f>0&&m.jsxs("span",{className:`text-xxs tabular-nums ${p?"text-statusDone font-medium":"text-faint"}`,title:`${h} done · ${f} total`,children:[h,"/",f]}),i&&m.jsx("span",{className:"text-xxs text-faint italic",children:"next"})]}),m.jsx("button",{className:"text-faint hover:text-accent text-xs opacity-0 group-hover/col:opacity-100",title:"Add task",onClick:()=>l({kind:"quick-create"}),children:"+"})]}),m.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-thin p-1.5 space-y-1",children:u.length===0&&t.length===0?m.jsx("div",{className:"text-xxs text-faint px-1 py-0.5",children:"—"}):m.jsxs(m.Fragment,{children:[u.map(x=>m.jsx(nM,{task:x,project:x.projectId?r.get(x.projectId):void 0},x.id)),m.jsx(tM,{virtuals:t,projectMap:r})]})})]})}const oC="(max-width: 767px)";function MG(){const[n,e]=M.useState(()=>typeof window<"u"&&window.matchMedia(oC).matches);return M.useEffect(()=>{const t=window.matchMedia(oC),r=()=>e(t.matches);return t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[]),n}function AG(){const n=MG(),[e,t]=M.useState("week"),[r,i]=M.useState(()=>new Date),[s,l]=M.useState(null),[o,u]=M.useState(n),h=n?"day":e;return m.jsxs("div",{className:"h-full flex flex-col",children:[m.jsx($G,{view:h,setView:t,anchor:r,setAnchor:i,projectIds:s,setProjectIds:l}),m.jsxs("div",{className:"flex-1 min-h-0 flex",children:[m.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden bg-bg",children:[h==="day"&&m.jsx(bG,{anchor:r,projectIds:s}),h==="week"&&m.jsx(jG,{anchor:r,projectIds:s}),h==="month"&&m.jsx(CG,{anchor:r,projectIds:s})]}),m.jsx(wG,{projectIds:s,collapsed:o,onToggle:()=>u(f=>!f)})]})]})}function RG(){const n=new Date,{data:e}=Vn(),t=M.useMemo(()=>Gl(e),[e]),r=M.useMemo(()=>{const h=new Date(n);h.setHours(0,0,0,0);const f=new Date(n);return f.setHours(23,59,59,999),{from:h.toISOString(),to:f.toISOString()}},[]),{data:i,isLoading:s}=Yl({from:r.from,to:r.to,includeBacklog:!1,includeDone:!0}),{open:l}=zt(),o=((i==null?void 0:i.overdue)??[]).filter(h=>Ma(h,n)),u=((i==null?void 0:i.scheduled)??[]).slice().sort(bp);return m.jsx("div",{className:"h-full overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-6 space-y-6",children:[m.jsxs("header",{className:"flex items-baseline gap-3",children:[m.jsx(dj,{size:18,className:"text-accent"}),m.jsx("h1",{className:"text-lg font-semibold",children:"Today"}),m.jsx("span",{className:"text-xs text-muted",children:Ft(n,"EEEE, MMM d")})]}),s&&m.jsx("div",{className:"text-sm text-muted",children:"Loading…"}),!s&&m.jsxs(m.Fragment,{children:[m.jsx(aC,{title:"Overdue",count:o.length,accent:"text-danger",tasks:o,projectMap:t}),m.jsx(aC,{title:vp(n)?"Today":Ft(n,"EEEE"),count:u.length,accent:"text-ink",tasks:u,projectMap:t,emptyAction:m.jsx("button",{className:"text-accent text-xs hover:underline",onClick:()=>l({kind:"quick-create"}),children:"+ add a task"})}),m.jsx(NG,{})]})]})})}function NG(){const[n,e]=M.useState(""),t=QE();function r(){const i=n.trim();if(!i||t.isPending)return;const s=new Date;s.setHours(12,0,0,0),t.mutate({kind:"task",title:i,dueAt:s.toISOString()},{onSuccess:()=>e("")})}return m.jsxs("div",{className:"flex items-center gap-2 border border-dashed border-line rounded-md px-3 py-1.5 focus-within:border-accent transition-colors",children:[m.jsx(Wc,{size:12,className:"text-faint shrink-0"}),m.jsx("input",{value:n,onChange:i=>e(i.target.value),onKeyDown:i=>{i.key==="Enter"&&r()},placeholder:"Add a task for today…",className:"flex-1 bg-transparent text-xs outline-none placeholder:text-faint",disabled:t.isPending}),t.isPending&&m.jsx("span",{className:"text-xxs text-faint",children:"Adding…"})]})}function aC({title:n,count:e,accent:t,tasks:r,projectMap:i,emptyAction:s}){if(r.length===0&&!s)return null;const l=new Map;for(const o of r){const u=o.projectId??null;l.has(u)||l.set(u,[]),l.get(u).push(o)}return m.jsxs("section",{className:"space-y-1.5",children:[m.jsxs("div",{className:"flex items-baseline gap-2",children:[m.jsx("h2",{className:`text-xs font-semibold ${t}`,children:n}),m.jsx("span",{className:"text-xxs text-faint tabular-nums",children:e})]}),r.length===0?m.jsx("div",{className:"text-xs text-muted py-1",children:s??"Nothing here."}):m.jsx("div",{className:"border border-line rounded-md overflow-hidden bg-surface",children:Array.from(l.entries()).map(([o,u])=>{const h=o?i.get(o):void 0;return m.jsxs("div",{children:[m.jsxs("div",{className:"px-3 py-1 border-b border-lineSoft bg-sidebar/40 flex items-center gap-1.5 text-xxs",children:[h?m.jsxs(m.Fragment,{children:[m.jsx(el,{color:h.color,icon:h.icon,size:10}),m.jsx("span",{className:"font-mono tabular-nums",style:{color:h.color},children:h.key}),m.jsx("span",{className:"text-muted truncate",children:h.name})]}):m.jsx("span",{className:"text-faint",children:"no project"}),m.jsx("span",{className:"text-faint ml-auto tabular-nums",children:u.length})]}),u.map(f=>m.jsx(wp,{task:f,project:h},f.id))]},o??"_none")})})]})}function LG(){const{data:n}=PE(200),{data:e}=Vn({includeArchived:!0}),t=PF(),r=CF(),i=()=>{if(!(!n||n.length===0)&&window.confirm(`Permanently delete all ${n.length} item(s) in the trash? This cannot be undone.`))for(const s of n)r.mutate(s.id)};return m.jsx("div",{className:"h-full overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-8 space-y-5",children:[m.jsxs("header",{className:"flex items-start justify-between gap-4",children:[m.jsxs("div",{children:[m.jsxs("h1",{className:"text-xl font-semibold text-ink flex items-center gap-2",children:[m.jsx(vc,{size:18,className:"text-muted"})," Trash"]}),m.jsx("p",{className:"text-sm text-muted mt-1",children:"Deleted items land here and are purged automatically after 30 days."})]}),n&&n.length>0&&m.jsxs("button",{className:"btn btn-ghost !h-7 !px-2.5 text-xs gap-1 shrink-0 hover:!text-red-600",onClick:i,children:[m.jsx(bc,{size:12})," Empty trash"]})]}),n&&n.length===0?m.jsx("div",{className:"border border-dashed border-line rounded-lg p-8 text-center text-sm text-muted",children:"Trash is empty."}):m.jsx("div",{className:"bg-surface border border-line rounded-md divide-y divide-line/60",children:n==null?void 0:n.map(s=>{const l=e==null?void 0:e.find(o=>o.id===s.projectId);return m.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 row-hover group",children:[m.jsx(xp,{kind:s.kind}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:`text-sm truncate ${Tr(s)?"text-muted italic":"text-ink"}`,children:on(s)}),m.jsxs("div",{className:"text-xxs text-muted mt-0.5",children:[l?l.key:"—"," · deleted"," ",s.deletedAt?_G(s.deletedAt):"—"," ·"," ",m.jsx("span",{className:"opacity-70",children:s.actorKind})]})]}),m.jsxs("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",children:[m.jsxs("button",{className:"btn btn-ghost !h-6 !px-2 text-xxs gap-1",title:"Restore",onClick:()=>t.mutate(s.id),children:[m.jsx(L6,{size:11})," Restore"]}),m.jsxs("button",{className:"btn btn-ghost !h-6 !px-2 text-xxs gap-1 hover:!text-red-600",title:"Delete forever",onClick:()=>{window.confirm(`Permanently delete "${on(s)}"? This cannot be undone.`)&&r.mutate(s.id)},children:[m.jsx(vc,{size:11})," Delete forever"]})]})]},s.id)})})]})})}function _G(n){const e=Date.now()-new Date(n).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:e<7*864e5?`${Math.floor(e/864e5)}d ago`:new Date(n).toLocaleDateString()}function DG(){return m.jsx(VF,{children:m.jsxs(eN,{children:[m.jsxs(I5,{children:[m.jsx(ir,{path:"/login",element:m.jsx(JU,{})}),m.jsxs(ir,{element:m.jsx(mY,{}),children:[m.jsx(ir,{path:"/",element:m.jsx(AG,{})}),m.jsx(ir,{path:"/today",element:m.jsx(RG,{})}),m.jsx(ir,{path:"/inbox",element:m.jsx(GU,{})}),m.jsx(ir,{path:"/dashboard",element:m.jsx(BU,{})}),m.jsx(ir,{path:"/trash",element:m.jsx(LG,{})}),m.jsx(ir,{path:"/settings",element:m.jsx(aG,{})}),m.jsx(ir,{path:"/p/:key",element:m.jsx(iG,{})}),m.jsx(ir,{path:"/p/:key/e/:id",element:m.jsx(YU,{})}),m.jsx(ir,{path:"/p/:key/agents-md",element:m.jsx(wY,{})}),m.jsx(ir,{path:"/search",element:m.jsx(lG,{})})]})]}),m.jsx(vY,{})]})})}const IG=new CR({defaultOptions:{queries:{staleTime:1e4,gcTime:5*6e4,retry:1,refetchOnWindowFocus:!0}}});qR.createRoot(document.getElementById("root")).render(m.jsx(jC.StrictMode,{children:m.jsx($R,{client:IG,children:m.jsx(Y5,{children:m.jsx(DG,{})})})}));
547
+ -d '{ "query": "deployment", "limit": 10 }'`}];return m.jsxs(m.Fragment,{children:[m.jsx(Hl,{title:"MCP (raw integration)",blurb:"Skip the Claude Code plugin and wire the MCP server in by hand — for Codex, custom agents, or any MCP-aware client. The botnote binary doubles as the MCP stdio server."}),m.jsx(kG,{title:"Claude Code (~/.claude.json or project-local .mcp.json)",code:n}),m.jsx(Cc,{title:"Codex (~/.codex/config.toml)",steps:t}),m.jsx(Cc,{title:"REST · curl",steps:r}),m.jsxs("div",{className:"border border-line rounded-md bg-surface px-4 py-3 text-xs text-muted leading-relaxed",children:["Raw MCP configuration requires the ",m.jsx("code",{className:"text-ink",children:"botnote"})," binary in",m.jsx("code",{className:"text-ink",children:" PATH"})," ","(",m.jsx("code",{className:"text-ink",children:"npm i -g botnote"}),"). The Claude Code and Codex plugins do not require a global CLI install; they run the matching npm package version automatically. The MCP server has no DB connection of its own; it speaks HTTP to whichever"," ",m.jsx("code",{className:"text-ink",children:"BOTNOTE_URL"})," you set."]})]})}function xG(){const{data:n,isLoading:e}=yF(),t=n!=null&&n.version?`v${n.version}`:e?"loading...":"unknown";return m.jsxs(m.Fragment,{children:[m.jsx(Hl,{title:"About",blurb:"Build + runtime info for this daemon."}),m.jsxs("div",{className:"border border-line rounded-md bg-surface px-4 py-3 text-xs text-muted space-y-2",children:[m.jsxs("div",{children:[m.jsxs("span",{className:"text-ink",children:["botnote ",t]})," — Postgres 16 + pgvector + Fastify 5 + MCP SDK"]}),m.jsxs("div",{children:["REST: ",m.jsx("code",{className:"text-ink",children:Jf})," · docs:"," ",m.jsx("a",{className:"text-accent hover:underline",href:"/docs",target:"_blank",rel:"noreferrer",children:"/docs"})]}),m.jsxs("div",{className:"pt-1 border-t border-lineSoft",children:["Auth is enforced when ",m.jsx("code",{className:"text-ink",children:"BOTNOTE_REQUIRE_AUTH=1"})," (or a"," ",m.jsx("code",{children:"BOTNOTE_PASSWORD"})," is set) on the daemon. Every request then needs a bearer token or a browser session cookie, except direct connections from the daemon host itself (",m.jsx("code",{children:"BOTNOTE_TRUST_LOCALHOST=0"})," closes that too). Forwarded headers are honoured only from proxies listed in ",m.jsx("code",{children:"BOTNOTE_TRUST_PROXY"})," (default: loopback)."]})]})]})}function Cc({title:n,steps:e}){return m.jsxs("div",{className:"border border-line rounded-md bg-surface overflow-hidden",children:[m.jsx("div",{className:"px-3 py-1.5 border-b border-lineSoft bg-sidebar/40",children:m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:n})}),m.jsx("div",{className:"px-3 py-3 space-y-3",children:e.map((t,r)=>m.jsxs("div",{className:"space-y-1.5",children:[t.note&&m.jsx("p",{className:"text-xs text-muted leading-relaxed",children:t.note}),t.code&&m.jsx(JE,{code:t.code})]},r))})]})}function JE({code:n}){const[e,t]=M.useState(!1);function r(){navigator.clipboard.writeText(n).then(()=>{t(!0),setTimeout(()=>t(!1),1400)})}return m.jsxs("div",{className:"relative border border-lineSoft rounded-md bg-sidebar/30",children:[m.jsx("pre",{className:"px-3 py-2 pr-9 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre text-ink2",children:n}),m.jsx("button",{onClick:r,className:"absolute top-1.5 right-1.5 p-1 rounded text-faint hover:text-ink hover:bg-sidebarHover transition-colors",title:"Copy command",children:e?m.jsx(Gi,{size:12,className:"text-success"}):m.jsx(kc,{size:12})})]})}function eM({title:n,items:e}){return m.jsxs("div",{className:"border border-line rounded-md bg-surface overflow-hidden",children:[m.jsx("div",{className:"px-3 py-1.5 border-b border-lineSoft bg-sidebar/40",children:m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:n})}),m.jsx("ul",{className:"divide-y divide-lineSoft",children:e.map(t=>m.jsx(yG,{code:t.code,desc:t.desc},t.code))})]})}function yG({code:n,desc:e}){const[t,r]=M.useState(!1);function i(){navigator.clipboard.writeText(n).then(()=>{r(!0),setTimeout(()=>r(!1),1400)})}return m.jsxs("li",{className:"group flex items-center gap-3 px-3 py-1.5",children:[m.jsx("code",{className:"font-mono text-xs text-ink whitespace-nowrap overflow-x-auto scrollbar-thin",children:n}),m.jsx("span",{className:"flex-1 text-xs text-muted text-right truncate",children:e}),m.jsx("button",{onClick:i,className:`p-1 rounded transition-colors ${t?"text-success":"text-faint hover:text-ink opacity-0 group-hover:opacity-100 focus:opacity-100"}`,title:"Copy command",children:t?m.jsx(Gi,{size:12}):m.jsx(kc,{size:12})})]})}function kG({title:n,code:e}){const[t,r]=M.useState(!1);function i(){navigator.clipboard.writeText(e).then(()=>{r(!0),setTimeout(()=>r(!1),1400)})}return m.jsxs("div",{className:"border border-line rounded-md bg-surface overflow-hidden",children:[m.jsxs("div",{className:"px-3 py-1.5 border-b border-lineSoft flex items-center justify-between bg-sidebar/40",children:[m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted font-medium",children:n}),m.jsxs("button",{onClick:i,className:"text-xxs text-muted hover:text-ink flex items-center gap-1",children:[t?m.jsx(Gi,{size:11}):m.jsx(kc,{size:11}),t?"Copied":"Copy"]})]}),m.jsx("pre",{className:"px-3 py-2 text-xs font-mono leading-relaxed overflow-x-auto whitespace-pre bg-sidebar/20 text-ink2",children:e})]})}function vG(){const{data:n,isLoading:e}=IF(),t=zF(),r=ZF(),[i,s]=M.useState(""),[l,o]=M.useState(null),[u,h]=M.useState(null),[f,p]=M.useState(null),[g,x]=M.useState(null);function k(S){navigator.clipboard.writeText(S.plaintext).then(()=>{x(S.id),setTimeout(()=>x(Q=>Q===S.id?null:Q),1400)})}async function b(S){if(S.preventDefault(),!i.trim())return;const Q=await t.mutateAsync(i.trim());o(Q),s("")}async function w(S,Q){if(!u&&confirm(`Revoke token "${Q}"? Any client using it stops working.`)){h(S),p(null);try{await r.mutateAsync(S),(l==null?void 0:l.id)===S&&o(null)}catch($){const R=$ instanceof Error?$.message:String($);p(`Could not revoke "${Q}": ${R}`)}finally{h($=>$===S?null:$)}}}return m.jsxs(m.Fragment,{children:[m.jsx(Hl,{title:"API tokens",blurb:"Bearer tokens for the CLI, MCP server, and direct REST calls. New tokens keep their full value available for copying here; older tokens created before this change only have a prefix and must be regenerated if the full value was lost."}),l&&m.jsxs("div",{className:"border border-warn rounded-md bg-warn/10 p-3 space-y-2",children:[m.jsxs("div",{className:"flex items-center gap-2 text-xs font-medium text-warn",children:[m.jsx(W6,{size:13}),"Copy this token now, or later from the token list."]}),m.jsxs("div",{className:"flex items-center gap-2",children:[m.jsx("code",{className:"flex-1 text-xs font-mono bg-surface border border-line rounded px-2 py-1 overflow-x-auto whitespace-nowrap",children:l.plaintext}),m.jsxs("button",{className:"btn",onClick:()=>navigator.clipboard.writeText(l.plaintext),children:[m.jsx(kc,{size:11})," Copy"]}),m.jsx("button",{className:"btn",onClick:()=>o(null),children:"Done"})]})]}),f&&m.jsx("div",{className:"border border-danger/30 rounded-md bg-danger/10 px-3 py-2 text-xs text-danger",children:f}),m.jsxs("form",{onSubmit:b,className:"flex gap-2",children:[m.jsx("input",{className:"input flex-1",placeholder:"Token name (e.g. claude-code-laptop)",value:i,onChange:S=>s(S.target.value)}),m.jsxs("button",{type:"submit",className:"btn btn-primary",disabled:!i.trim()||t.isPending,children:[m.jsx(Wc,{size:11})," ",t.isPending?"Generating…":"Generate"]})]}),m.jsxs("div",{className:"border border-line rounded-md bg-surface divide-y divide-lineSoft overflow-hidden",children:[e&&m.jsx("div",{className:"p-3 text-xs text-muted",children:"Loading…"}),!e&&(!n||n.length===0)&&m.jsx("div",{className:"p-4 text-xs text-faint text-center",children:"No tokens yet."}),n==null?void 0:n.map(S=>{const Q=g===S.id;return m.jsxs("div",{className:"flex items-center gap-3 px-3 py-2",children:[m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:"text-sm text-ink truncate",children:S.name}),m.jsxs("div",{className:"text-xxs text-muted flex items-center gap-3 mt-0.5",children:[m.jsxs("code",{className:"font-mono text-faint",children:[S.prefix,"…"]}),m.jsxs("span",{children:["created ",xy(new Date(S.createdAt),{addSuffix:!0})]}),m.jsx("span",{children:S.lastUsedAt?`used ${xy(new Date(S.lastUsedAt),{addSuffix:!0})}`:"never used"})]})]}),S.plaintext?m.jsxs("button",{type:"button",onClick:()=>k({id:S.id,plaintext:S.plaintext}),className:`btn gap-1.5 ${Q?"!border-emerald-500/30 !text-emerald-600":""}`,title:"Copy full token",children:[Q?m.jsx(Gi,{size:11}):m.jsx(kc,{size:11}),Q?"Copied":"Copy token"]}):m.jsx("span",{className:"text-xxs text-faint border border-line rounded px-2 py-1",title:"Full token is unavailable for tokens created before recoverable storage was enabled.",children:"Unavailable"}),m.jsx("button",{type:"button",className:"text-faint hover:text-danger p-1 -m-1",disabled:u!==null,onClick:()=>w(S.id,S.name),title:u===S.id?"Revoking":"Revoke",children:u===S.id?m.jsx("span",{className:"text-xxs text-muted",children:"Revoking…"}):m.jsx(vc,{size:12})})]},S.id)})]})]})}function bG({anchor:n,projectIds:e}){const t=K0("day",n),{data:r}=Yl({from:t.from.toISOString(),to:t.to.toISOString(),projectIds:e??null,includeBacklog:!1,includeDone:!0}),{data:i}=Vn(),s=M.useMemo(()=>Gl(i),[i]),{open:l}=zt(),o=((r==null?void 0:r.overdue)??[]).filter(f=>Ma(f,n)),u=((r==null?void 0:r.scheduled)??[]).slice().sort(bp),h=vp(n);return m.jsx("div",{className:"h-full overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"max-w-4xl mx-auto py-4",children:[h&&o.length>0&&m.jsx(sC,{title:"Overdue",count:o.length,accent:"text-danger",tasks:o,projectMap:s}),m.jsx(sC,{title:h?"Today":Ft(n,"EEEE"),count:u.length,accent:"text-ink",tasks:u,projectMap:s,emptyAction:m.jsx("button",{className:"text-accent text-xs hover:underline",onClick:()=>l({kind:"quick-create"}),children:"+ add a task for this day"})})]})})}function sC({title:n,count:e,accent:t,tasks:r,projectMap:i,emptyAction:s}){return m.jsxs("section",{className:"mb-6",children:[m.jsxs("div",{className:"px-4 py-1.5 flex items-baseline gap-2 sticky top-0 bg-bg z-10",children:[m.jsx("h2",{className:`text-xs font-semibold ${t}`,children:n}),m.jsx("span",{className:"text-xxs text-faint tabular-nums",children:e})]}),r.length===0?m.jsx("div",{className:"px-4 py-2 text-xs text-muted",children:s??"Nothing here."}):m.jsx("div",{className:"bg-surface border-y border-lineSoft",children:r.map(l=>m.jsx(wp,{task:l,project:l.projectId?i.get(l.projectId):void 0},l.id))})]})}function wG({projectIds:n,collapsed:e,onToggle:t}){const{data:r}=Yl({projectIds:n??null,includeBacklog:!0,includeDone:!1}),{data:i}=Vn(),s=M.useMemo(()=>Gl(i),[i]),l=((r==null?void 0:r.backlog)??[]).filter(u=>u.status!=="rejected"),o=M.useMemo(()=>{const u=new Map;for(const f of l){const p=f.projectId??null,g=u.get(p);g?g.push(f):u.set(p,[f])}const h=[];for(const[f,p]of u)h.push({project:f?s.get(f):void 0,tasks:p});return h.sort((f,p)=>f.project?p.project?f.project.key.localeCompare(p.project.key):-1:1),h},[l,s]);return e?m.jsxs("button",{className:"shrink-0 w-8 border-l border-line bg-sidebar/50 hover:bg-sidebar flex flex-col items-center pt-2 gap-2 group",onClick:t,title:"Expand Inbox",children:[m.jsx(_d,{size:14,className:"text-muted group-hover:text-ink"}),l.length>0&&m.jsx("div",{className:"text-xxs text-muted bg-surface border border-line rounded-full w-5 h-5 flex items-center justify-center",children:l.length})]}):m.jsxs("aside",{className:"shrink-0 w-72 border-l border-line bg-surface flex flex-col",children:[m.jsxs("div",{className:"px-3 h-9 flex items-center justify-between border-b border-lineSoft",children:[m.jsxs("div",{className:"flex items-center gap-2 text-muted",children:[m.jsx(_d,{size:12}),m.jsx("h2",{className:"text-xs font-medium text-ink2",children:"Inbox"}),m.jsx("span",{className:"text-xxs text-faint tabular-nums",children:l.length})]}),m.jsx("button",{onClick:t,className:"btn-ghost btn !h-6 !w-6 !p-0",title:"Collapse",children:"→"})]}),m.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-thin",children:l.length===0?m.jsxs("div",{className:"text-xs text-muted text-center py-8 px-4",children:["No tasks without due date.",m.jsx("div",{className:"text-faint mt-1",children:"Tasks without due date appear here."})]}):o.map(({project:u,tasks:h})=>m.jsxs("div",{children:[m.jsxs("div",{className:"sticky top-0 z-10 flex items-center gap-1.5 px-3 py-1 bg-surface border-b border-lineSoft",children:[m.jsx("span",{className:"font-mono text-xxs text-faint tabular-nums",children:(u==null?void 0:u.key)??"—"}),m.jsx("span",{className:"text-xxs text-muted truncate",children:(u==null?void 0:u.name)??"No project"}),m.jsx("span",{className:"ml-auto text-xxs text-faint tabular-nums",children:h.length})]}),h.map(f=>m.jsx(wp,{task:f,project:u,showProject:!1,compact:!0},f.id))]},(u==null?void 0:u.id)??"none"))})]})}function SG({virtual:n,project:e}){const t=n.title&&n.title.trim()?n.title:"Untitled";return m.jsxs("div",{"aria-label":`Upcoming — will be created automatically: ${t}`,className:"pointer-events-none w-full text-left flex items-center gap-1.5 pl-1 pr-1.5 py-1 rounded text-xs opacity-40 border border-dashed border-current",children:[m.jsx("span",{className:"w-[2px] self-stretch rounded-sm shrink-0",style:{backgroundColor:(e==null?void 0:e.color)??"#a8a8af"}}),m.jsx("span",{className:"truncate flex-1 min-w-0 text-ink2 italic",children:t}),m.jsx(Uc,{size:11,className:"text-faint"})]})}function tM({virtuals:n,projectMap:e}){if(n.length===0)return null;if(n.length===1){const r=n[0];return m.jsx(SG,{virtual:r,project:r.projectId?e.get(r.projectId):void 0})}const t=n.map(r=>r.title&&r.title.trim()?r.title:"Untitled").join(`
548
+ `);return m.jsxs("div",{title:t,"aria-label":`${n.length} upcoming recurring tasks: ${t}`,className:"w-full flex items-center gap-1.5 pl-1 pr-1.5 py-1 rounded text-xs opacity-40 border border-dashed border-current",children:[m.jsx(Uc,{size:11,className:"text-faint shrink-0"}),m.jsxs("span",{className:"truncate flex-1 min-w-0 text-ink2 italic",children:["+",n.length," recurring"]})]})}function nM({task:n,project:e}){const t=Si(),r=Ma(n);return m.jsxs("div",{role:"button",tabIndex:0,draggable:!0,onDragStart:i=>{i.dataTransfer.setData("text/task-id",n.id),i.dataTransfer.effectAllowed="move",i.stopPropagation()},onClick:()=>t.open(n.id),onKeyDown:i=>{i.key!=="Enter"&&i.key!==" "||(i.preventDefault(),t.open(n.id))},className:`group w-full text-left flex items-center gap-1.5 pl-1 pr-1.5 py-1 rounded text-xs hover:bg-sidebarHover transition-colors cursor-grab active:cursor-grabbing ${r?"bg-danger/5":""}`,title:e?`${e.key} · ${on(n)}`:on(n),children:[m.jsx("span",{className:"w-[2px] self-stretch rounded-sm shrink-0",style:{backgroundColor:(e==null?void 0:e.color)??"#a8a8af"}}),m.jsx(yp,{task:n,size:11}),m.jsx("span",{className:`truncate flex-1 min-w-0 ${n.status==="done"?"line-through text-muted":n.status==="rejected"?"text-muted":Tr(n)?"italic text-muted":"text-ink2"}`,children:on(n)}),J0(n)&&m.jsx(Uc,{size:11,className:"text-faint"}),n.priority!=="none"&&m.jsx(ga,{priority:n.priority,size:11})]})}const PG=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];function CG({anchor:n,projectIds:e}){const t=K0("month",n),r=HE(t.from,t.to),{data:i}=Yl({from:t.from.toISOString(),to:t.to.toISOString(),projectIds:e??null,includeBacklog:!1,includeDone:!0,includeVirtualRecurrences:!0}),{data:s}=Vn(),l=M.useMemo(()=>Gl(s),[s]),o=M.useMemo(()=>UE((i==null?void 0:i.scheduled)??[]),[i]),u=M.useMemo(()=>GE((i==null?void 0:i.virtualOccurrences)??[]),[i]);return m.jsxs("div",{className:"h-full flex flex-col",children:[m.jsx("div",{className:"grid grid-cols-7 border-b border-lineSoft bg-sidebar/50",children:PG.map(h=>m.jsx("div",{className:"px-2 py-1 text-xxs uppercase tracking-wider text-muted text-center",children:h},h))}),m.jsx("div",{className:"flex-1 grid grid-cols-7 grid-rows-6 bg-line/30 gap-px overflow-y-auto scrollbar-thin",children:r.map(h=>{const f=o.get(Vd(h))??[],p=u.get(Vd(h))??[],g=!zU(h,n),x=vp(h);return m.jsx(QG,{day:h,tasks:f,virtuals:p,projectMap:l,outOfMonth:g,today:x},h.toISOString())})})]})}function QG({day:n,tasks:e,virtuals:t,projectMap:r,outOfMonth:i,today:s}){const{open:l}=zt(),o=Js(),[u,h]=M.useState(!1),f=e.slice().sort(bp),p=f.filter(b=>b.status==="done").length,g=f.length,x=g>0&&p===g;function k(b){b.preventDefault(),h(!1);const w=b.dataTransfer.getData("text/task-id");if(!w)return;const S=new Date(n);S.setHours(12,0,0,0),o.mutate({id:w,fields:{dueAt:S.toISOString()}})}return m.jsxs("div",{className:`group bg-surface p-1 min-h-[112px] flex flex-col transition-colors ${i?"opacity-50":""} ${u?"ring-2 ring-accent ring-inset bg-accentSoft/40":s?"ring-1 ring-accent ring-inset bg-accentSoft/30":""}`,onDragOver:b=>{b.preventDefault(),u||h(!0)},onDragLeave:()=>h(!1),onDrop:k,children:[m.jsxs("div",{className:"flex items-center justify-between mb-1 px-1",children:[m.jsxs("div",{className:"flex items-baseline gap-1.5 min-w-0",children:[m.jsx("span",{className:`text-xs tabular-nums ${s?"font-semibold text-accent":"text-muted"}`,children:Ft(n,"d")}),g>0&&m.jsxs("span",{className:`text-xxs tabular-nums ${x?"text-statusDone font-medium":"text-faint"}`,title:`${p} done · ${g} total`,children:[p,"/",g]})]}),m.jsx("button",{className:"text-xs text-faint hover:text-accent opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>l({kind:"quick-create"}),title:"Add task",children:"+"})]}),m.jsxs("div",{className:"flex-1 space-y-0.5 min-h-0 overflow-hidden",children:[f.slice(0,4).map(b=>m.jsx(nM,{task:b,project:b.projectId?r.get(b.projectId):void 0},b.id)),f.length>4&&m.jsxs("div",{className:"text-xxs text-muted pl-1",children:["+",f.length-4]}),m.jsx(tM,{virtuals:t,projectMap:r})]})]})}function $G({view:n,setView:e,anchor:t,setAnchor:r,projectIds:i,setProjectIds:s}){var h;const{data:l}=Vn(),{open:o}=zt(),u=i?i.length===1?((h=l==null?void 0:l.find(f=>f.id===i[0]))==null?void 0:h.key)??"1 project":`${i.length} projects`:"All projects";return m.jsx("div",{className:"border-b border-line bg-surface",children:m.jsxs("div",{className:"flex items-center justify-between h-11 px-3",children:[m.jsxs("div",{className:"flex items-center gap-3",children:[m.jsx("h1",{className:"text-xs font-semibold text-ink hidden sm:block",children:"Tasks"}),m.jsx("div",{className:"seg hidden md:flex",children:["day","week","month"].map(f=>m.jsx("button",{onClick:()=>e(f),"data-active":n===f,className:"capitalize",children:f},f))}),m.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[m.jsx("button",{onClick:()=>r(QO(n,t,-1)),className:"btn btn-ghost !h-6 !w-6 !p-0",title:"Previous",children:m.jsx(lj,{size:12})}),m.jsx("button",{onClick:()=>r(QO(n,t,0)),className:"btn !h-6 px-2 text-xxs",title:"Today",children:"Today"}),m.jsx("button",{onClick:()=>r(QO(n,t,1)),className:"btn btn-ghost !h-6 !w-6 !p-0",title:"Next",children:m.jsx(Bc,{size:12})}),m.jsx("div",{className:"ml-2 text-xs font-medium text-ink2 tabular-nums",children:ZU(n,t)})]})]}),m.jsxs("div",{className:"flex items-center gap-1.5",children:[m.jsx(TG,{projects:l??[],projectIds:i,setProjectIds:s,label:u}),m.jsxs("button",{className:"btn btn-primary",onClick:()=>o({kind:"quick-create"}),title:"New task (c)",children:[m.jsx(Wc,{size:11}),m.jsx("span",{className:"text-xs hidden sm:inline",children:"Task"}),m.jsx("kbd",{className:"!bg-white/15 !border-white/25 !text-white hidden md:inline-block",children:"c"})]})]})]})})}function TG({projects:n,projectIds:e,setProjectIds:t,label:r}){return m.jsxs("details",{className:"relative",children:[m.jsxs("summary",{className:"btn list-none cursor-pointer",children:[m.jsx(m6,{size:11}),m.jsx("span",{className:"text-xs",children:r})]}),m.jsxs("div",{className:"popover top-9 right-0 w-56 px-1 py-1.5",children:[m.jsxs("button",{className:`popover-item ${e?"":"bg-accentSoft text-accentText"}`,onClick:()=>t(null),children:[m.jsx("span",{children:"All projects"}),!e&&m.jsx("span",{className:"ml-auto text-faint",children:"✓"})]}),m.jsx("div",{className:"divider my-1"}),n.map(i=>{const s=(e==null?void 0:e.includes(i.id))??!1;return m.jsxs("label",{className:"popover-item gap-2 cursor-pointer",children:[m.jsx("input",{type:"checkbox",className:"cursor-pointer",checked:s,onChange:()=>{if(!e)t([i.id]);else if(s){const l=e.filter(o=>o!==i.id);t(l.length?l:null)}else t([...e,i.id])}}),m.jsx("span",{className:"font-mono text-xxs text-faint tabular-nums",children:i.key}),m.jsx("span",{className:"text-ink2 truncate",children:i.name})]},i.id)})]})]})}function jG({anchor:n,projectIds:e}){const t=K0("week",n),r=HE(t.from,t.to),i=kp(r[r.length-1],1),s=[...r,i],l=new Date(i);l.setHours(23,59,59,999);const{data:o}=Yl({from:t.from.toISOString(),to:l.toISOString(),projectIds:e??null,includeBacklog:!1,includeDone:!0,includeVirtualRecurrences:!0}),{data:u}=Vn(),h=M.useMemo(()=>Gl(u),[u]),f=M.useMemo(()=>UE((o==null?void 0:o.scheduled)??[]),[o]),p=M.useMemo(()=>GE((o==null?void 0:o.virtualOccurrences)??[]),[o]),g=s.slice(0,4),x=s.slice(4);return m.jsxs("div",{className:"h-full flex flex-col bg-bg",children:[m.jsx(lC,{days:g,byDay:f,virtualsByDay:p,projectMap:h,anchor:n}),m.jsx(lC,{days:x,byDay:f,virtualsByDay:p,projectMap:h,anchor:n})]})}function lC({days:n,byDay:e,virtualsByDay:t,projectMap:r,anchor:i}){return m.jsx("div",{className:"flex-1 min-h-0 flex border-b border-line last:border-b-0",children:n.map(s=>{const l=e.get(Vd(s))??[],o=t.get(Vd(s))??[],u=!IU(s,i,{weekStartsOn:1});return m.jsx(EG,{day:s,tasks:l,virtuals:o,projectMap:r,outOfWeek:u},s.toISOString())})})}function EG({day:n,tasks:e,virtuals:t,projectMap:r,outOfWeek:i}){const s=vp(n),{open:l}=zt(),o=Js(),u=e.slice().sort(bp),h=u.filter(x=>x.status==="done").length,f=u.length,p=f>0&&h===f;function g(x){x.preventDefault();const k=x.dataTransfer.getData("text/task-id");if(!k)return;const b=new Date(n);b.setHours(12,0,0,0),o.mutate({id:k,fields:{dueAt:b.toISOString()}})}return m.jsxs("div",{className:`flex-1 min-w-0 border-r border-lineSoft last:border-r-0 flex flex-col group/col ${s?"bg-accentSoft/30":i?"bg-sidebar/40":"bg-surface"}`,onDragOver:x=>x.preventDefault(),onDrop:g,children:[m.jsxs("div",{className:"px-3 py-1.5 flex items-baseline justify-between border-b border-lineSoft",children:[m.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[m.jsx("span",{className:"text-xxs uppercase tracking-wider text-muted",children:Ft(n,"EEE")}),m.jsx("span",{className:`text-sm tabular-nums font-semibold ${s?"text-accent":i?"text-muted":"text-ink2"}`,children:Ft(n,"d")}),f>0&&m.jsxs("span",{className:`text-xxs tabular-nums ${p?"text-statusDone font-medium":"text-faint"}`,title:`${h} done · ${f} total`,children:[h,"/",f]}),i&&m.jsx("span",{className:"text-xxs text-faint italic",children:"next"})]}),m.jsx("button",{className:"text-faint hover:text-accent text-xs opacity-0 group-hover/col:opacity-100",title:"Add task",onClick:()=>l({kind:"quick-create"}),children:"+"})]}),m.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-thin p-1.5 space-y-1",children:u.length===0&&t.length===0?m.jsx("div",{className:"text-xxs text-faint px-1 py-0.5",children:"—"}):m.jsxs(m.Fragment,{children:[u.map(x=>m.jsx(nM,{task:x,project:x.projectId?r.get(x.projectId):void 0},x.id)),m.jsx(tM,{virtuals:t,projectMap:r})]})})]})}const oC="(max-width: 767px)";function MG(){const[n,e]=M.useState(()=>typeof window<"u"&&window.matchMedia(oC).matches);return M.useEffect(()=>{const t=window.matchMedia(oC),r=()=>e(t.matches);return t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[]),n}function AG(){const n=MG(),[e,t]=M.useState("week"),[r,i]=M.useState(()=>new Date),[s,l]=M.useState(null),[o,u]=M.useState(n),h=n?"day":e;return m.jsxs("div",{className:"h-full flex flex-col",children:[m.jsx($G,{view:h,setView:t,anchor:r,setAnchor:i,projectIds:s,setProjectIds:l}),m.jsxs("div",{className:"flex-1 min-h-0 flex",children:[m.jsxs("div",{className:"flex-1 min-w-0 overflow-hidden bg-bg",children:[h==="day"&&m.jsx(bG,{anchor:r,projectIds:s}),h==="week"&&m.jsx(jG,{anchor:r,projectIds:s}),h==="month"&&m.jsx(CG,{anchor:r,projectIds:s})]}),m.jsx(wG,{projectIds:s,collapsed:o,onToggle:()=>u(f=>!f)})]})]})}function RG(){const n=new Date,{data:e}=Vn(),t=M.useMemo(()=>Gl(e),[e]),r=M.useMemo(()=>{const h=new Date(n);h.setHours(0,0,0,0);const f=new Date(n);return f.setHours(23,59,59,999),{from:h.toISOString(),to:f.toISOString()}},[]),{data:i,isLoading:s}=Yl({from:r.from,to:r.to,includeBacklog:!1,includeDone:!0}),{open:l}=zt(),o=((i==null?void 0:i.overdue)??[]).filter(h=>Ma(h,n)),u=((i==null?void 0:i.scheduled)??[]).slice().sort(bp);return m.jsx("div",{className:"h-full overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-6 space-y-6",children:[m.jsxs("header",{className:"flex items-baseline gap-3",children:[m.jsx(dj,{size:18,className:"text-accent"}),m.jsx("h1",{className:"text-lg font-semibold",children:"Today"}),m.jsx("span",{className:"text-xs text-muted",children:Ft(n,"EEEE, MMM d")})]}),s&&m.jsx("div",{className:"text-sm text-muted",children:"Loading…"}),!s&&m.jsxs(m.Fragment,{children:[m.jsx(aC,{title:"Overdue",count:o.length,accent:"text-danger",tasks:o,projectMap:t}),m.jsx(aC,{title:vp(n)?"Today":Ft(n,"EEEE"),count:u.length,accent:"text-ink",tasks:u,projectMap:t,emptyAction:m.jsx("button",{className:"text-accent text-xs hover:underline",onClick:()=>l({kind:"quick-create"}),children:"+ add a task"})}),m.jsx(NG,{})]})]})})}function NG(){const[n,e]=M.useState(""),t=QE();function r(){const i=n.trim();if(!i||t.isPending)return;const s=new Date;s.setHours(12,0,0,0),t.mutate({kind:"task",title:i,dueAt:s.toISOString()},{onSuccess:()=>e("")})}return m.jsxs("div",{className:"flex items-center gap-2 border border-dashed border-line rounded-md px-3 py-1.5 focus-within:border-accent transition-colors",children:[m.jsx(Wc,{size:12,className:"text-faint shrink-0"}),m.jsx("input",{value:n,onChange:i=>e(i.target.value),onKeyDown:i=>{i.key==="Enter"&&r()},placeholder:"Add a task for today…",className:"flex-1 bg-transparent text-xs outline-none placeholder:text-faint",disabled:t.isPending}),t.isPending&&m.jsx("span",{className:"text-xxs text-faint",children:"Adding…"})]})}function aC({title:n,count:e,accent:t,tasks:r,projectMap:i,emptyAction:s}){if(r.length===0&&!s)return null;const l=new Map;for(const o of r){const u=o.projectId??null;l.has(u)||l.set(u,[]),l.get(u).push(o)}return m.jsxs("section",{className:"space-y-1.5",children:[m.jsxs("div",{className:"flex items-baseline gap-2",children:[m.jsx("h2",{className:`text-xs font-semibold ${t}`,children:n}),m.jsx("span",{className:"text-xxs text-faint tabular-nums",children:e})]}),r.length===0?m.jsx("div",{className:"text-xs text-muted py-1",children:s??"Nothing here."}):m.jsx("div",{className:"border border-line rounded-md overflow-hidden bg-surface",children:Array.from(l.entries()).map(([o,u])=>{const h=o?i.get(o):void 0;return m.jsxs("div",{children:[m.jsxs("div",{className:"px-3 py-1 border-b border-lineSoft bg-sidebar/40 flex items-center gap-1.5 text-xxs",children:[h?m.jsxs(m.Fragment,{children:[m.jsx(el,{color:h.color,icon:h.icon,size:10}),m.jsx("span",{className:"font-mono tabular-nums",style:{color:h.color},children:h.key}),m.jsx("span",{className:"text-muted truncate",children:h.name})]}):m.jsx("span",{className:"text-faint",children:"no project"}),m.jsx("span",{className:"text-faint ml-auto tabular-nums",children:u.length})]}),u.map(f=>m.jsx(wp,{task:f,project:h},f.id))]},o??"_none")})})]})}function LG(){const{data:n}=PE(200),{data:e}=Vn({includeArchived:!0}),t=PF(),r=CF(),i=()=>{if(!(!n||n.length===0)&&window.confirm(`Permanently delete all ${n.length} item(s) in the trash? This cannot be undone.`))for(const s of n)r.mutate(s.id)};return m.jsx("div",{className:"h-full overflow-y-auto scrollbar-thin",children:m.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-8 space-y-5",children:[m.jsxs("header",{className:"flex items-start justify-between gap-4",children:[m.jsxs("div",{children:[m.jsxs("h1",{className:"text-xl font-semibold text-ink flex items-center gap-2",children:[m.jsx(vc,{size:18,className:"text-muted"})," Trash"]}),m.jsx("p",{className:"text-sm text-muted mt-1",children:"Deleted items land here and are purged automatically after 30 days."})]}),n&&n.length>0&&m.jsxs("button",{className:"btn btn-ghost !h-7 !px-2.5 text-xs gap-1 shrink-0 hover:!text-red-600",onClick:i,children:[m.jsx(bc,{size:12})," Empty trash"]})]}),n&&n.length===0?m.jsx("div",{className:"border border-dashed border-line rounded-lg p-8 text-center text-sm text-muted",children:"Trash is empty."}):m.jsx("div",{className:"bg-surface border border-line rounded-md divide-y divide-line/60",children:n==null?void 0:n.map(s=>{const l=e==null?void 0:e.find(o=>o.id===s.projectId);return m.jsxs("div",{className:"flex items-center gap-3 px-3 py-2 row-hover group",children:[m.jsx(xp,{kind:s.kind}),m.jsxs("div",{className:"flex-1 min-w-0",children:[m.jsx("div",{className:`text-sm truncate ${Tr(s)?"text-muted italic":"text-ink"}`,children:on(s)}),m.jsxs("div",{className:"text-xxs text-muted mt-0.5",children:[l?l.key:"—"," · deleted"," ",s.deletedAt?_G(s.deletedAt):"—"," ·"," ",m.jsx("span",{className:"opacity-70",children:s.actorKind})]})]}),m.jsxs("div",{className:"flex items-center gap-1 shrink-0 opacity-0 group-hover:opacity-100 transition-opacity",children:[m.jsxs("button",{className:"btn btn-ghost !h-6 !px-2 text-xxs gap-1",title:"Restore",onClick:()=>t.mutate(s.id),children:[m.jsx(L6,{size:11})," Restore"]}),m.jsxs("button",{className:"btn btn-ghost !h-6 !px-2 text-xxs gap-1 hover:!text-red-600",title:"Delete forever",onClick:()=>{window.confirm(`Permanently delete "${on(s)}"? This cannot be undone.`)&&r.mutate(s.id)},children:[m.jsx(vc,{size:11})," Delete forever"]})]})]},s.id)})})]})})}function _G(n){const e=Date.now()-new Date(n).getTime();return e<6e4?"just now":e<36e5?`${Math.floor(e/6e4)}m ago`:e<864e5?`${Math.floor(e/36e5)}h ago`:e<7*864e5?`${Math.floor(e/864e5)}d ago`:new Date(n).toLocaleDateString()}function DG(){return m.jsx(VF,{children:m.jsxs(e5,{children:[m.jsxs(IN,{children:[m.jsx(ir,{path:"/login",element:m.jsx(JU,{})}),m.jsxs(ir,{element:m.jsx(mY,{}),children:[m.jsx(ir,{path:"/",element:m.jsx(AG,{})}),m.jsx(ir,{path:"/today",element:m.jsx(RG,{})}),m.jsx(ir,{path:"/inbox",element:m.jsx(GU,{})}),m.jsx(ir,{path:"/dashboard",element:m.jsx(BU,{})}),m.jsx(ir,{path:"/trash",element:m.jsx(LG,{})}),m.jsx(ir,{path:"/settings",element:m.jsx(aG,{})}),m.jsx(ir,{path:"/p/:key",element:m.jsx(iG,{})}),m.jsx(ir,{path:"/p/:key/e/:id",element:m.jsx(YU,{})}),m.jsx(ir,{path:"/p/:key/agents-md",element:m.jsx(wY,{})}),m.jsx(ir,{path:"/search",element:m.jsx(lG,{})})]})]}),m.jsx(vY,{})]})})}const IG=new CR({defaultOptions:{queries:{staleTime:1e4,gcTime:5*6e4,retry:1,refetchOnWindowFocus:!0}}});qR.createRoot(document.getElementById("root")).render(m.jsx(jC.StrictMode,{children:m.jsx($R,{client:IG,children:m.jsx(YN,{children:m.jsx(DG,{})})})}));