collabmd 0.1.20 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +4 -2
  2. package/package.json +1 -1
  3. package/public/assets/css/style.css +1 -1
  4. package/public/assets/js/chunks/chunk-GFDM7YCF.js +1 -0
  5. package/public/assets/js/chunks/editor-session-EAUBJCHH.js +22 -0
  6. package/public/assets/js/chunks/{preview-render-compiler-UZ4SZDQQ.js → preview-render-compiler-6Y7TKXFJ.js} +1 -1
  7. package/public/assets/js/chunks/{quick-switcher-controller-J7I3CUET.js → quick-switcher-controller-A6SKH5HI.js} +1 -1
  8. package/public/assets/js/{excalidraw-editor-ZDYKMZOL.js → excalidraw-editor-TCIH6GJL.js} +1 -1
  9. package/public/assets/js/excalidraw-editor.js +1 -1
  10. package/public/assets/js/main.js +68 -68
  11. package/public/assets/js/preview-render-worker.js +15 -15
  12. package/src/client/application/app-shell/git-feature.js +57 -18
  13. package/src/client/application/app-shell/ui-feature.js +4 -0
  14. package/src/client/bootstrap/collabmd-app-shell.js +12 -0
  15. package/src/client/domain/vault-utils.js +2 -2
  16. package/src/client/excalidraw-editor.js +2 -1
  17. package/src/client/infrastructure/editor-session.js +4 -0
  18. package/src/client/infrastructure/editor-view-adapter.js +181 -1
  19. package/src/client/infrastructure/workspace-sync-client.js +324 -0
  20. package/src/client/presentation/comment-ui-controller.js +192 -5
  21. package/src/client/presentation/file-explorer-controller.js +15 -3
  22. package/src/client/presentation/file-explorer-view.js +152 -11
  23. package/src/client/styles/style.css +46 -2
  24. package/src/domain/wiki-link-resolver.js +16 -5
  25. package/src/domain/workspace-change.js +68 -0
  26. package/src/domain/workspace-room.js +3 -0
  27. package/src/server/create-app-server.js +41 -10
  28. package/src/server/domain/backlink-index.js +94 -1
  29. package/src/server/domain/collaboration/collaboration-room.js +191 -22
  30. package/src/server/domain/collaboration/room-registry.js +64 -10
  31. package/src/server/infrastructure/git/responses.js +12 -19
  32. package/src/server/infrastructure/http/create-git-api-command-handler.js +53 -43
  33. package/src/server/infrastructure/http/create-git-api-handler.js +2 -0
  34. package/src/server/infrastructure/http/create-request-handler.js +7 -0
  35. package/src/server/infrastructure/http/create-vault-api-command-handler.js +58 -14
  36. package/src/server/infrastructure/http/create-vault-api-handler.js +3 -0
  37. package/src/server/infrastructure/http/create-vault-api-query-handler.js +3 -1
  38. package/src/server/infrastructure/http/http-response.js +65 -28
  39. package/src/server/infrastructure/persistence/vault-file-store.js +163 -52
  40. package/src/server/infrastructure/workspace/file-system-sync-service.js +488 -0
  41. package/src/server/infrastructure/workspace/workspace-mutation-coordinator.js +551 -0
  42. package/public/assets/js/chunks/chunk-R3DDMJHH.js +0 -1
  43. package/public/assets/js/chunks/editor-session-TAV2VXTA.js +0 -22
@@ -1,22 +0,0 @@
1
- import{b as Pn,g as Vn}from"./chunk-X6EEYWV4.js";import"./chunk-OOT2HALX.js";import"./chunk-NO7UPWTU.js";import"./chunk-CGVY4PKT.js";import{e as En,f as In,g as Rn}from"./chunk-OQLLZFFN.js";import{A as mn,Aa as ve,Ba as Bn,C as O,Ca as Dn,D as y,E as dn,Ea as q,F as fn,Fa as we,G as pn,H as gn,I as xn,J as yn,K as Cn,N as ut,O as Sn,P as kn,Q as bn,R as Ln,S as Se,a as ht,aa as f,b as V,c as on,d as rn,e as sn,g as an,ga as ke,h as ln,i as p,ia as be,j as P,ja as c,k as pe,ka as vn,l as ge,la as Le,m as xe,ma as ae,n as F,na as mt,o as j,oa as dt,p as ye,q as v,r as ie,s as se,ta as wn,u as cn,v as hn,w as Ce,x as w,xa as Mn,y as un,ya as An,z as S,za as Tn}from"./chunk-G7NUGGE7.js";import{A as lt,B as re,D as Zt,E as ct,F as en,G as tn,H as nn,c as qt,d as Ht,e as Yt,f as Gt,g as Jt,h as te,i as fe,j as ne,k as Kt,l as G,m as I,n as U,o as R,p as st,q as J,r as at,s as oe,t as Qt,y as Xt}from"./chunk-HEWVH67U.js";import"./chunk-775E65SU.js";function Fn({body:e,user:t}){return{body:e,createdAt:Date.now(),id:ct("comment"),peerId:t?.peerId??"",reactions:[],userColor:t?.color??"",userName:t?.name??"Anonymous"}}function gr(e,t){return e instanceof oe?e.get(t):e?.[t]}function xr(e=[]){return Array.isArray(e)?e.map(t=>({emoji:typeof t?.emoji=="string"?t.emoji:"",users:Array.isArray(t?.users)?t.users.map(n=>({reactedAt:Number.isFinite(n?.reactedAt)?n.reactedAt:Date.now(),userColor:typeof n?.userColor=="string"?n.userColor:"",userId:typeof n?.userId=="string"?n.userId:"",userName:typeof n?.userName=="string"&&n.userName?n.userName:"Anonymous"})).filter(n=>n.userId):[]})).filter(t=>t.emoji&&t.users.length>0):[]}function yr(e,t){let n=t?.doc;if(!n)return null;let o=e?.anchor??e,r=o?.anchorKind==="text"?"text":"line",i=n.lines,s=Math.min(Math.max(Math.round(o?.startLine??1),1),i),a=Math.min(Math.max(Math.round(o?.endLine??s),s),i),l=n.line(s).from,h=n.line(a).to,m=Math.min(Math.max(Math.round(o?.startIndex??l),0),n.length),d=Math.min(Math.max(Math.round(o?.endIndex??h),m),n.length);return{anchorEndLine:a,anchorKind:r,anchorQuote:re(o?.anchorQuote||n.sliceString(m,d)),anchorStartLine:s,endIndex:d,startIndex:m}}var Me=class{constructor({getDoc:t,getEditorState:n,getLocalUser:o,onCommentsChange:r=null}){this.getDoc=t,this.getEditorState=n,this.getLocalUser=o,this.onCommentsChange=r,this.commentThreads=null,this.ydoc=null,this.ytext=null,this.handleCommentThreadsChange=null,this.handleTextChange=null}bind({commentThreads:t,ydoc:n,ytext:o}){this.unbind(),this.commentThreads=t,this.ydoc=n,this.ytext=o,this.handleCommentThreadsChange=()=>{this.emitCommentsChange()},this.handleTextChange=()=>{this.emitCommentsChange()},this.commentThreads.observeDeep(this.handleCommentThreadsChange),this.ytext?.observe?.(this.handleTextChange),this.emitCommentsChange()}unbind(){this.commentThreads&&this.handleCommentThreadsChange&&this.commentThreads.unobserveDeep(this.handleCommentThreadsChange),this.ytext&&this.handleTextChange&&this.ytext.unobserve(this.handleTextChange),this.commentThreads=null,this.ydoc=null,this.ytext=null,this.handleCommentThreadsChange=null,this.handleTextChange=null}emitCommentsChange(){this.onCommentsChange?.(this.getCommentThreads())}getCommentThreads(){return this.commentThreads?nn(this.commentThreads).map(t=>this.resolveCommentThread(t)).filter(Boolean):[]}createCommentThread({anchor:t,body:n}){let o=this.getEditorState();if(!o||!this.commentThreads||!this.ytext||!this.ydoc)return null;let r=lt(n),i=yr(t,o);if(!r||!i)return null;let s=tn({anchorEnd:G(U(this.ytext,i.endIndex)),anchorEndLine:i.anchorEndLine,anchorKind:i.anchorKind,anchorQuote:i.anchorQuote,anchorStart:G(U(this.ytext,i.startIndex)),anchorStartLine:i.anchorStartLine,createdAt:Date.now(),createdByColor:this.getLocalUser()?.color??"",createdByName:this.getLocalUser()?.name??"Anonymous",createdByPeerId:this.getLocalUser()?.peerId??"",id:ct("thread"),messages:[Fn({body:r,user:this.getLocalUser()})]});return s?(this.ydoc.transact(()=>{this.commentThreads.push([s])},"comment-thread-create"),s.get("id")):null}replyToCommentThread(t,n){let o=lt(n);if(!o||!this.ydoc)return null;let i=this.findSharedCommentThread(t)?.get("messages");if(!(i instanceof at))return null;let s=Fn({body:o,user:this.getLocalUser()});return this.ydoc.transact(()=>{i.push([s])},"comment-thread-reply"),s.id}toggleCommentReaction(t,n,o){if(!this.ydoc||!t||!n||typeof o!="string"||!o.trim())return!1;let r=this.getLocalUser?.(),i=typeof r?.userId=="string"?r.userId:"";if(!i)return!1;let a=this.findSharedCommentThread(t)?.get("messages");if(!(a instanceof at))return!1;let l=a.toArray(),h=l.findIndex(x=>gr(x,"id")===n);if(h<0)return!1;let m=l[h]instanceof oe?l[h].toJSON():{...l[h]},d=xr(m.reactions),g=d.findIndex(x=>x.emoji===o);if(g>=0){let x=d[g].users.filter(k=>k.userId!==i);x.length===d[g].users.length&&x.push({reactedAt:Date.now(),userColor:r?.color??"",userId:i,userName:r?.name??"Anonymous"}),x.length===0?d.splice(g,1):d[g]={...d[g],users:x}}else d.push({emoji:o,users:[{reactedAt:Date.now(),userColor:r?.color??"",userId:i,userName:r?.name??"Anonymous"}]});let C={...m,reactions:d};return this.ydoc.transact(()=>{a.delete(h,1),a.insert(h,[C])},"comment-reaction-toggle"),!0}deleteCommentThread(t){if(!this.commentThreads||!this.ydoc)return!1;let n=this.findSharedCommentThreadIndex(t);return n<0?!1:(this.ydoc.transact(()=>{this.commentThreads.delete(n,1)},"comment-thread-resolve"),!0)}findSharedCommentThread(t){return this.commentThreads?this.commentThreads.toArray().find(n=>n instanceof oe&&n.get("id")===t)??null:null}findSharedCommentThreadIndex(t){return this.commentThreads?this.commentThreads.toArray().findIndex(n=>n instanceof oe&&n.get("id")===t):-1}resolveCommentThread(t){let n=this.getEditorState();if(!t||!n||!this.ydoc)return null;let o=en(t);if(!o)return null;let r=this.resolveCommentPosition(o.anchorStart),i=this.resolveCommentPosition(o.anchorEnd),s=r?.index??n.doc.line(o.anchorStartLine).from,a=Math.min(Math.max(o.anchorEndLine??o.anchorStartLine,o.anchorStartLine),n.doc.lines),l=i?.index??n.doc.line(a).to,h=n.doc.lineAt(s).number,m=Math.min(Math.max(l,s),n.doc.length),d=n.doc.lineAt(m).number,g=n.doc.sliceString(s,o.anchorKind==="text"?Math.max(l,s):n.doc.line(d).to),C=Zt(g)||o.anchorQuote;return{...t,anchor:{endIndex:l,endLine:d,excerpt:C,quote:o.anchorQuote,startIndex:s,startLine:h,kind:o.anchorKind},anchorEnd:o.anchorEnd,anchorEndLine:o.anchorEndLine,anchorKind:o.anchorKind,anchorQuote:o.anchorQuote,anchorStart:o.anchorStart,anchorStartLine:o.anchorStartLine}}resolveCommentPosition(t){if(!t||!this.ydoc||!this.ytext)return null;try{let n=I(t),o=R(n,this.ydoc);return!o||o.type!==this.ytext?null:o}catch{return null}}};var Ae=class{constructor({localUser:t=null,onAwarenessChange:n=null,onConnectionChange:o=null,onInitialSync:r=null,preferredUserName:i,resolveAwarenessCursor:s=null}){this.onAwarenessChange=n,this.onConnectionChange=o,this.onInitialSync=r,this.preferredUserName=i,this.providedLocalUser=t,this.resolveAwarenessCursor=s??(()=>null),this.provider=null,this.awareness=null,this.localUser=null,this.ydoc=null,this.ytext=null,this.commentThreads=null,this.wsBaseUrl="",this.initialSyncComplete=!1,this.initialSyncPromise=Promise.resolve(),this.resolveInitialSync=null}normalizeViewport(t){if(!t||typeof t!="object")return null;let n=Number(t.topLine),o=Number(t.viewportRatio);return!Number.isFinite(n)||n<1?null:{topLine:Math.max(1,Math.round(n)),viewportRatio:Number.isFinite(o)?Math.min(Math.max(o,0),1):.35}}async initialize(t){this.wsBaseUrl=qt(),this.ydoc=new Kt,this.ytext=this.ydoc.getText("codemirror"),this.commentThreads=this.ydoc.getArray("comments");let n=new J(this.ytext),o=new Qt(this.wsBaseUrl,t,this.ydoc,{disableBc:!0,maxBackoffTime:5e3});Xt(o);let r=o.awareness,i=this.providedLocalUser??Yt(this.preferredUserName);this.provider=o,this.awareness=r,this.localUser=i,this.initialSyncComplete=!1,this.initialSyncPromise=new Promise(a=>{this.resolveInitialSync=a}),r.setLocalStateField("user",i),r.on("change",()=>{this.onAwarenessChange?.(this.collectUsers(this.resolveAwarenessCursor))}),this.trackConnectionStatus();let s=!1;return o.on("sync",a=>{!a||s||(s=!0,this.initialSyncComplete=!0,this.resolveInitialSync?.(),this.resolveInitialSync=null,this.onInitialSync?.())}),{awareness:r,commentThreads:this.commentThreads,localUser:this.localUser,undoManager:n,ydoc:this.ydoc,ytext:this.ytext}}destroy(){this.resolveInitialSync?.(),this.resolveInitialSync=null,this.initialSyncComplete=!1,this.initialSyncPromise=Promise.resolve(),this.provider?.disconnect(),this.provider?.destroy(),this.provider=null,this.awareness=null,this.localUser=null,this.ydoc?.destroy(),this.ydoc=null,this.ytext=null,this.commentThreads=null}waitForInitialSync(t=1500){return this.initialSyncComplete?Promise.resolve():Promise.race([this.initialSyncPromise,new Promise(n=>{window.setTimeout(n,t)})])}getText(){return this.ytext?.toString()??""}getLocalUser(){return this.localUser}setUserName(t){let n=Ht(t);return!n||!this.awareness||!this.localUser?null:(this.localUser={...this.localUser,name:n},this.awareness.setLocalStateField("user",this.localUser),n)}getUserCursor(t,n){if(!this.awareness)return null;let o=this.awareness.getStates().get(t);return n(o?.cursor)}getUserViewport(t){if(!this.awareness)return null;let n=this.awareness.getStates().get(t);return this.normalizeViewport(n?.viewport)}setLocalViewport(t){if(!this.awareness)return null;let n=this.normalizeViewport(t);return this.awareness.setLocalStateField("viewport",n),n}collectUsers(t=()=>null){if(!this.awareness)return[];let n=[];return this.awareness.getStates().forEach((o,r)=>{if(!o.user)return;let i=t(o.cursor);n.push({...i??{},...o.user,clientId:r,hasCursor:!!i,isLocal:r===this.awareness.clientID,viewport:this.normalizeViewport(o.viewport)})}),n}trackConnectionStatus(){if(!this.provider)return;let t=0,n=!1;this.provider.on("status",({status:o})=>{o==="connecting"&&(t+=1);let r=o==="connected"&&!n;o==="connected"&&(t=0,n=!0),this.onConnectionChange?.({attempts:t,firstConnection:r,hasEverConnected:n,status:o,unreachable:!n&&t>=3,wsBaseUrl:this.wsBaseUrl})})}};var Cr=e=>{let{state:t}=e,n=t.doc.lineAt(t.selection.main.from),o=St(e.state,n.from);return o.line?Sr(e):o.block?br(e):!1};function Ct(e,t){return({state:n,dispatch:o})=>{if(n.readOnly)return!1;let r=e(t,n);return r?(o(n.update(r)),!0):!1}}var Sr=Ct(wr,0);var kr=Ct(qn,0);var br=Ct((e,t)=>qn(e,t,vr(t)),0);function St(e,t){let n=e.languageDataAt("commentTokens",t,1);return n.length?n[0]:{}}var le=50;function Lr(e,{open:t,close:n},o,r){let i=e.sliceDoc(o-le,o),s=e.sliceDoc(r,r+le),a=/\s*$/.exec(i)[0].length,l=/^\s*/.exec(s)[0].length,h=i.length-a;if(i.slice(h-t.length,h)==t&&s.slice(l,l+n.length)==n)return{open:{pos:o-a,margin:a&&1},close:{pos:r+l,margin:l&&1}};let m,d;r-o<=2*le?m=d=e.sliceDoc(o,r):(m=e.sliceDoc(o,o+le),d=e.sliceDoc(r-le,r));let g=/^\s*/.exec(m)[0].length,C=/\s*$/.exec(d)[0].length,x=d.length-C-n.length;return m.slice(g,g+t.length)==t&&d.slice(x,x+n.length)==n?{open:{pos:o+g+t.length,margin:/\s/.test(m.charAt(g+t.length))?1:0},close:{pos:r-C-n.length,margin:/\s/.test(d.charAt(x-1))?1:0}}:null}function vr(e){let t=[];for(let n of e.selection.ranges){let o=e.doc.lineAt(n.from),r=n.to<=o.to?o:e.doc.lineAt(n.to);r.from>o.from&&r.from==n.to&&(r=n.to==o.to+1?o:e.doc.lineAt(n.to-1));let i=t.length-1;i>=0&&t[i].to>o.from?t[i].to=r.to:t.push({from:o.from+/^\s*/.exec(o.text)[0].length,to:r.to})}return t}function qn(e,t,n=t.selection.ranges){let o=n.map(i=>St(t,i.from).block);if(!o.every(i=>i))return null;let r=n.map((i,s)=>Lr(t,o[s],i.from,i.to));if(e!=2&&!r.every(i=>i))return{changes:t.changes(n.map((i,s)=>r[s]?[]:[{from:i.from,insert:o[s].open+" "},{from:i.to,insert:" "+o[s].close}]))};if(e!=1&&r.some(i=>i)){let i=[];for(let s=0,a;s<r.length;s++)if(a=r[s]){let l=o[s],{open:h,close:m}=a;i.push({from:h.pos-l.open.length,to:h.pos+h.margin},{from:m.pos-m.margin,to:m.pos+l.close.length})}return{changes:i}}return null}function wr(e,t,n=t.selection.ranges){let o=[],r=-1;e:for(let{from:i,to:s}of n){let a=o.length,l=1e9,h;for(let m=i;m<=s;){let d=t.doc.lineAt(m);if(h==null&&(h=St(t,d.from).line,!h))continue e;if(d.from>r&&(i==s||s>d.from)){r=d.from;let g=/^\s*/.exec(d.text)[0].length,C=g==d.length,x=d.text.slice(g,g+h.length)==h?g:-1;g<d.text.length&&g<l&&(l=g),o.push({line:d,comment:x,token:h,indent:g,empty:C,single:!1})}m=d.to+1}if(l<1e9)for(let m=a;m<o.length;m++)o[m].indent<o[m].line.text.length&&(o[m].indent=l);o.length==a+1&&(o[a].single=!0)}if(e!=2&&o.some(i=>i.comment<0&&(!i.empty||i.single))){let i=[];for(let{line:a,token:l,indent:h,empty:m,single:d}of o)(d||!m)&&i.push({from:a.from+h,insert:l+" "});let s=t.changes(i);return{changes:s,selection:t.selection.map(s,1)}}else if(e!=1&&o.some(i=>i.comment>=0)){let i=[];for(let{line:s,comment:a,token:l}of o)if(a>=0){let h=s.from+a,m=h+l.length;s.text[m-s.from]==" "&&m++,i.push({from:h,to:m})}return{changes:i}}return null}var pt=F.define(),Mr=F.define(),Ar=P.define(),Hn=P.define({combine(e){return se(e,{minDepth:100,newGroupDelay:500,joinToEvent:(t,n)=>n},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(t,n)=>(o,r)=>t(o,r)||n(o,r)})}}),Yn=pe.define({create(){return H.empty},update(e,t){let n=t.state.facet(Hn),o=t.annotation(pt);if(o){let l=B.fromTransaction(t,o.selection),h=o.side,m=h==0?e.undone:e.done;return l?m=Be(m,m.length,n.minDepth,l):m=Qn(m,t.startState.selection),new H(h==0?o.rest:m,h==0?m:o.rest)}let r=t.annotation(Mr);if((r=="full"||r=="before")&&(e=e.isolate()),t.annotation(ye.addToHistory)===!1)return t.changes.empty?e:e.addMapping(t.changes.desc);let i=B.fromTransaction(t),s=t.annotation(ye.time),a=t.annotation(ye.userEvent);return i?e=e.addChanges(i,s,a,n,t):t.selection&&(e=e.addSelection(t.startState.selection,s,a,n.newGroupDelay)),(r=="full"||r=="after")&&(e=e.isolate()),e},toJSON(e){return{done:e.done.map(t=>t.toJSON()),undone:e.undone.map(t=>t.toJSON())}},fromJSON(e){return new H(e.done.map(B.fromJSON),e.undone.map(B.fromJSON))}});function Gn(e={}){return[Yn,Hn.of(e),y.domEventHandlers({beforeinput(t,n){let o=t.inputType=="historyUndo"?Jn:t.inputType=="historyRedo"?gt:null;return o?(t.preventDefault(),o(n)):!1}})]}function De(e,t){return function({state:n,dispatch:o}){if(!t&&n.readOnly)return!1;let r=n.field(Yn,!1);if(!r)return!1;let i=r.pop(e,n,t);return i?(o(i),!0):!1}}var Jn=De(0,!1),gt=De(1,!1),Tr=De(0,!0),Br=De(1,!0);var B=class e{constructor(t,n,o,r,i){this.changes=t,this.effects=n,this.mapped=o,this.startSelection=r,this.selectionsAfter=i}setSelAfter(t){return new e(this.changes,this.effects,this.mapped,this.startSelection,t)}toJSON(){var t,n,o;return{changes:(t=this.changes)===null||t===void 0?void 0:t.toJSON(),mapped:(n=this.mapped)===null||n===void 0?void 0:n.toJSON(),startSelection:(o=this.startSelection)===null||o===void 0?void 0:o.toJSON(),selectionsAfter:this.selectionsAfter.map(r=>r.toJSON())}}static fromJSON(t){return new e(t.changes&&ln.fromJSON(t.changes),[],t.mapped&&an.fromJSON(t.mapped),t.startSelection&&p.fromJSON(t.startSelection),t.selectionsAfter.map(p.fromJSON))}static fromTransaction(t,n){let o=A;for(let r of t.startState.facet(Ar)){let i=r(t);i.length&&(o=o.concat(i))}return!o.length&&t.changes.empty?null:new e(t.changes.invert(t.startState.doc),o,void 0,n||t.startState.selection,A)}static selection(t){return new e(void 0,A,void 0,void 0,t)}};function Be(e,t,n,o){let r=t+1>n+20?t-n-1:0,i=e.slice(r,t);return i.push(o),i}function Dr(e,t){let n=[],o=!1;return e.iterChangedRanges((r,i)=>n.push(r,i)),t.iterChangedRanges((r,i,s,a)=>{for(let l=0;l<n.length;){let h=n[l++],m=n[l++];a>=h&&s<=m&&(o=!0)}}),o}function Er(e,t){return e.ranges.length==t.ranges.length&&e.ranges.filter((n,o)=>n.empty!=t.ranges[o].empty).length===0}function Kn(e,t){return e.length?t.length?e.concat(t):e:t}var A=[],Ir=200;function Qn(e,t){if(e.length){let n=e[e.length-1],o=n.selectionsAfter.slice(Math.max(0,n.selectionsAfter.length-Ir));return o.length&&o[o.length-1].eq(t)?e:(o.push(t),Be(e,e.length-1,1e9,n.setSelAfter(o)))}else return[B.selection([t])]}function Rr(e){let t=e[e.length-1],n=e.slice();return n[e.length-1]=t.setSelAfter(t.selectionsAfter.slice(0,t.selectionsAfter.length-1)),n}function ft(e,t){if(!e.length)return e;let n=e.length,o=A;for(;n;){let r=Pr(e[n-1],t,o);if(r.changes&&!r.changes.empty||r.effects.length){let i=e.slice(0,n);return i[n-1]=r,i}else t=r.mapped,n--,o=r.selectionsAfter}return o.length?[B.selection(o)]:A}function Pr(e,t,n){let o=Kn(e.selectionsAfter.length?e.selectionsAfter.map(a=>a.map(t)):A,n);if(!e.changes)return B.selection(o);let r=e.changes.map(t),i=t.mapDesc(e.changes,!0),s=e.mapped?e.mapped.composeDesc(i):i;return new B(r,j.mapEffects(e.effects,t),s,e.startSelection.map(i),o)}var Vr=/^(input\.type|delete)($|\.)/,H=class e{constructor(t,n,o=0,r=void 0){this.done=t,this.undone=n,this.prevTime=o,this.prevUserEvent=r}isolate(){return this.prevTime?new e(this.done,this.undone):this}addChanges(t,n,o,r,i){let s=this.done,a=s[s.length-1];return a&&a.changes&&!a.changes.empty&&t.changes&&(!o||Vr.test(o))&&(!a.selectionsAfter.length&&n-this.prevTime<r.newGroupDelay&&r.joinToEvent(i,Dr(a.changes,t.changes))||o=="input.type.compose")?s=Be(s,s.length-1,r.minDepth,new B(t.changes.compose(a.changes),Kn(j.mapEffects(t.effects,a.changes),a.effects),a.mapped,a.startSelection,A)):s=Be(s,s.length,r.minDepth,t),new e(s,A,n,o)}addSelection(t,n,o,r){let i=this.done.length?this.done[this.done.length-1].selectionsAfter:A;return i.length>0&&n-this.prevTime<r&&o==this.prevUserEvent&&o&&/^select($|\.)/.test(o)&&Er(i[i.length-1],t)?this:new e(Qn(this.done,t),this.undone,n,o)}addMapping(t){return new e(ft(this.done,t),ft(this.undone,t),this.prevTime,this.prevUserEvent)}pop(t,n,o){let r=t==0?this.done:this.undone;if(r.length==0)return null;let i=r[r.length-1],s=i.selectionsAfter[0]||(i.startSelection?i.startSelection.map(i.changes.invertedDesc,1):n.selection);if(o&&i.selectionsAfter.length)return n.update({selection:i.selectionsAfter[i.selectionsAfter.length-1],annotations:pt.of({side:t,rest:Rr(r),selection:s}),userEvent:t==0?"select.undo":"select.redo",scrollIntoView:!0});if(i.changes){let a=r.length==1?A:r.slice(0,r.length-1);return i.mapped&&(a=ft(a,i.mapped)),n.update({changes:i.changes,selection:i.startSelection,effects:i.effects,annotations:pt.of({side:t,rest:a,selection:s}),filter:!1,userEvent:t==0?"undo":"redo",scrollIntoView:!0})}else return null}};H.empty=new H(A,A);var Xn=[{key:"Mod-z",run:Jn,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:gt,preventDefault:!0},{linux:"Ctrl-Shift-z",run:gt,preventDefault:!0},{key:"Mod-u",run:Tr,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:Br,preventDefault:!0}];function Q(e,t){return p.create(e.ranges.map(t),e.mainIndex)}function D(e,t){return e.update({selection:t,scrollIntoView:!0,userEvent:"select"})}function E({state:e,dispatch:t},n){let o=Q(e.selection,n);return o.eq(e.selection,!0)?!1:(t(D(e,o)),!0)}function Ee(e,t){return p.cursor(t?e.to:e.from)}function Zn(e,t){return E(e,n=>n.empty?e.moveByChar(n,t):Ee(n,t))}function L(e){return e.textDirectionAt(e.state.selection.main.head)==mn.LTR}var eo=e=>Zn(e,!L(e)),to=e=>Zn(e,L(e));function no(e,t){return E(e,n=>n.empty?e.moveByGroup(n,t):Ee(n,t))}var Fr=e=>no(e,!L(e)),Or=e=>no(e,L(e));var qs=typeof Intl<"u"&&Intl.Segmenter?new Intl.Segmenter(void 0,{granularity:"word"}):null;function Ur(e,t,n){if(t.type.prop(n))return!0;let o=t.to-t.from;return o&&(o>2||/[^\s,.;:]/.test(e.sliceDoc(t.from,t.to)))||t.firstChild}function Ie(e,t,n){let o=ke(e).resolveInner(t.head),r=n?Se.closedBy:Se.openedBy;for(let l=t.head;;){let h=n?o.childAfter(l):o.childBefore(l);if(!h)break;Ur(e,h,r)?o=h:l=n?h.to:h.from}let i=o.type.prop(r),s,a;return i&&(s=n?q(e,o.from,1):q(e,o.to,-1))&&s.matched?a=n?s.end.to:s.end.from:a=n?o.to:o.from,p.cursor(a,n?-1:1)}var Nr=e=>E(e,t=>Ie(e.state,t,!L(e))),Wr=e=>E(e,t=>Ie(e.state,t,L(e)));function oo(e,t){return E(e,n=>{if(!n.empty)return Ee(n,t);let o=e.moveVertically(n,t);return o.head!=n.head?o:e.moveToLineBoundary(n,t)})}var ro=e=>oo(e,!1),io=e=>oo(e,!0);function so(e){let t=e.scrollDOM.clientHeight<e.scrollDOM.scrollHeight-2,n=0,o=0,r;if(t){for(let i of e.state.facet(y.scrollMargins)){let s=i(e);s?.top&&(n=Math.max(s?.top,n)),s?.bottom&&(o=Math.max(s?.bottom,o))}r=e.scrollDOM.clientHeight-n-o}else r=(e.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:n,marginBottom:o,selfScroll:t,height:Math.max(e.defaultLineHeight,r-5)}}function ao(e,t){let n=so(e),{state:o}=e,r=Q(o.selection,s=>s.empty?e.moveVertically(s,t,n.height):Ee(s,t));if(r.eq(o.selection))return!1;let i;if(n.selfScroll){let s=e.coordsAtPos(o.selection.main.head),a=e.scrollDOM.getBoundingClientRect(),l=a.top+n.marginTop,h=a.bottom-n.marginBottom;s&&s.top>l&&s.bottom<h&&(i=y.scrollIntoView(r.main.head,{y:"start",yMargin:s.top-l}))}return e.dispatch(D(o,r),{effects:i}),!0}var On=e=>ao(e,!1),xt=e=>ao(e,!0);function N(e,t,n){let o=e.lineBlockAt(t.head),r=e.moveToLineBoundary(t,n);if(r.head==t.head&&r.head!=(n?o.to:o.from)&&(r=e.moveToLineBoundary(t,n,!1)),!n&&r.head==o.from&&o.length){let i=/^\s*/.exec(e.state.sliceDoc(o.from,Math.min(o.from+100,o.to)))[0].length;i&&t.head!=o.from+i&&(r=p.cursor(o.from+i))}return r}var $r=e=>E(e,t=>N(e,t,!0)),zr=e=>E(e,t=>N(e,t,!1)),_r=e=>E(e,t=>N(e,t,!L(e))),jr=e=>E(e,t=>N(e,t,L(e))),qr=e=>E(e,t=>p.cursor(e.lineBlockAt(t.head).from,1)),Hr=e=>E(e,t=>p.cursor(e.lineBlockAt(t.head).to,-1));function Yr(e,t,n){let o=!1,r=Q(e.selection,i=>{let s=q(e,i.head,-1)||q(e,i.head,1)||i.head>0&&q(e,i.head-1,1)||i.head<e.doc.length&&q(e,i.head+1,-1);if(!s||!s.end)return i;o=!0;let a=s.start.from==i.head?s.end.to:s.end.from;return n?p.range(i.anchor,a):p.cursor(a)});return o?(t(D(e,r)),!0):!1}var Gr=({state:e,dispatch:t})=>Yr(e,t,!1);function T(e,t){let n=Q(e.state.selection,o=>{let r=t(o);return p.range(o.anchor,r.head,r.goalColumn,r.bidiLevel||void 0)});return n.eq(e.state.selection)?!1:(e.dispatch(D(e.state,n)),!0)}function lo(e,t){return T(e,n=>e.moveByChar(n,t))}var co=e=>lo(e,!L(e)),ho=e=>lo(e,L(e));function uo(e,t){return T(e,n=>e.moveByGroup(n,t))}var Jr=e=>uo(e,!L(e)),Kr=e=>uo(e,L(e));var Qr=e=>T(e,t=>Ie(e.state,t,!L(e))),Xr=e=>T(e,t=>Ie(e.state,t,L(e)));function mo(e,t){return T(e,n=>e.moveVertically(n,t))}var fo=e=>mo(e,!1),po=e=>mo(e,!0);function go(e,t){return T(e,n=>e.moveVertically(n,t,so(e).height))}var Un=e=>go(e,!1),Nn=e=>go(e,!0),Zr=e=>T(e,t=>N(e,t,!0)),ei=e=>T(e,t=>N(e,t,!1)),ti=e=>T(e,t=>N(e,t,!L(e))),ni=e=>T(e,t=>N(e,t,L(e))),oi=e=>T(e,t=>p.cursor(e.lineBlockAt(t.head).from)),ri=e=>T(e,t=>p.cursor(e.lineBlockAt(t.head).to)),Wn=({state:e,dispatch:t})=>(t(D(e,{anchor:0})),!0),$n=({state:e,dispatch:t})=>(t(D(e,{anchor:e.doc.length})),!0),zn=({state:e,dispatch:t})=>(t(D(e,{anchor:e.selection.main.anchor,head:0})),!0),_n=({state:e,dispatch:t})=>(t(D(e,{anchor:e.selection.main.anchor,head:e.doc.length})),!0),ii=({state:e,dispatch:t})=>(t(e.update({selection:{anchor:0,head:e.doc.length},userEvent:"select"})),!0),si=({state:e,dispatch:t})=>{let n=Re(e).map(({from:o,to:r})=>p.range(o,Math.min(r+1,e.doc.length)));return t(e.update({selection:p.create(n),userEvent:"select"})),!0},ai=({state:e,dispatch:t})=>{let n=Q(e.selection,o=>{let r=ke(e),i=r.resolveStack(o.from,1);if(o.empty){let s=r.resolveStack(o.from,-1);s.node.from>=i.node.from&&s.node.to<=i.node.to&&(i=s)}for(let s=i;s;s=s.next){let{node:a}=s;if((a.from<o.from&&a.to>=o.to||a.to>o.to&&a.from<=o.from)&&s.next)return p.range(a.to,a.from)}return o});return n.eq(e.selection)?!1:(t(D(e,n)),!0)};function xo(e,t){let{state:n}=e,o=n.selection,r=n.selection.ranges.slice();for(let i of n.selection.ranges){let s=n.doc.lineAt(i.head);if(t?s.to<e.state.doc.length:s.from>0)for(let a=i;;){let l=e.moveVertically(a,t);if(l.head<s.from||l.head>s.to){r.some(h=>h.head==l.head)||r.push(l);break}else{if(l.head==a.head)break;a=l}}}return r.length==o.ranges.length?!1:(e.dispatch(D(n,p.create(r,r.length-1))),!0)}var li=e=>xo(e,!1),ci=e=>xo(e,!0),hi=({state:e,dispatch:t})=>{let n=e.selection,o=null;return n.ranges.length>1?o=p.create([n.main]):n.main.empty||(o=p.create([p.cursor(n.main.head)])),o?(t(D(e,o)),!0):!1};function ce(e,t){if(e.state.readOnly)return!1;let n="delete.selection",{state:o}=e,r=o.changeByRange(i=>{let{from:s,to:a}=i;if(s==a){let l=t(i);l<s?(n="delete.backward",l=Te(e,l,!1)):l>s&&(n="delete.forward",l=Te(e,l,!0)),s=Math.min(s,l),a=Math.max(a,l)}else s=Te(e,s,!1),a=Te(e,a,!0);return s==a?{range:i}:{changes:{from:s,to:a},range:p.cursor(s,s<i.head?-1:1)}});return r.changes.empty?!1:(e.dispatch(o.update(r,{scrollIntoView:!0,userEvent:n,effects:n=="delete.selection"?y.announce.of(o.phrase("Selection deleted")):void 0})),!0)}function Te(e,t,n){if(e instanceof y)for(let o of e.state.facet(y.atomicRanges).map(r=>r(e)))o.between(t,t,(r,i)=>{r<t&&i>t&&(t=n?i:r)});return t}var yo=(e,t,n)=>ce(e,o=>{let r=o.from,{state:i}=e,s=i.doc.lineAt(r),a,l;if(n&&!t&&r>s.from&&r<s.from+200&&!/[^ \t]/.test(a=s.text.slice(0,r-s.from))){if(a[a.length-1]==" ")return r-1;let h=Ce(a,i.tabSize),m=h%Le(i)||Le(i);for(let d=0;d<m&&a[a.length-1-d]==" ";d++)r--;l=r}else l=V(s.text,r-s.from,t,t)+s.from,l==r&&s.number!=(t?i.doc.lines:1)?l+=t?1:-1:!t&&/[\ufe00-\ufe0f]/.test(s.text.slice(l-s.from,r-s.from))&&(l=V(s.text,l-s.from,!1,!1)+s.from);return l}),yt=e=>yo(e,!1,!0);var Co=e=>yo(e,!0,!1),So=(e,t)=>ce(e,n=>{let o=n.head,{state:r}=e,i=r.doc.lineAt(o),s=r.charCategorizer(o);for(let a=null;;){if(o==(t?i.to:i.from)){o==n.head&&i.number!=(t?r.doc.lines:1)&&(o+=t?1:-1);break}let l=V(i.text,o-i.from,t)+i.from,h=i.text.slice(Math.min(o,l)-i.from,Math.max(o,l)-i.from),m=s(h);if(a!=null&&m!=a)break;(h!=" "||o!=n.head)&&(a=m),o=l}return o}),ko=e=>So(e,!1),ui=e=>So(e,!0);var mi=e=>ce(e,t=>{let n=e.lineBlockAt(t.head).to;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)});var di=e=>ce(e,t=>{let n=e.moveToLineBoundary(t,!1).head;return t.head>n?n:Math.max(0,t.head-1)}),fi=e=>ce(e,t=>{let n=e.moveToLineBoundary(t,!0).head;return t.head<n?n:Math.min(e.state.doc.length,t.head+1)});var pi=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(o=>({changes:{from:o.from,to:o.to,insert:ht.of(["",""])},range:p.cursor(o.from)}));return t(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0},gi=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=e.changeByRange(o=>{if(!o.empty||o.from==0||o.from==e.doc.length)return{range:o};let r=o.from,i=e.doc.lineAt(r),s=r==i.from?r-1:V(i.text,r-i.from,!1)+i.from,a=r==i.to?r+1:V(i.text,r-i.from,!0)+i.from;return{changes:{from:s,to:a,insert:e.doc.slice(r,a).append(e.doc.slice(s,r))},range:p.cursor(a)}});return n.changes.empty?!1:(t(e.update(n,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Re(e){let t=[],n=-1;for(let o of e.selection.ranges){let r=e.doc.lineAt(o.from),i=e.doc.lineAt(o.to);if(!o.empty&&o.to==i.from&&(i=e.doc.lineAt(o.to-1)),n>=r.number){let s=t[t.length-1];s.to=i.to,s.ranges.push(o)}else t.push({from:r.from,to:i.to,ranges:[o]});n=i.number+1}return t}function bo(e,t,n){if(e.readOnly)return!1;let o=[],r=[];for(let i of Re(e)){if(n?i.to==e.doc.length:i.from==0)continue;let s=e.doc.lineAt(n?i.to+1:i.from-1),a=s.length+1;if(n){o.push({from:i.to,to:s.to},{from:i.from,insert:s.text+e.lineBreak});for(let l of i.ranges)r.push(p.range(Math.min(e.doc.length,l.anchor+a),Math.min(e.doc.length,l.head+a)))}else{o.push({from:s.from,to:i.from},{from:i.to,insert:e.lineBreak+s.text});for(let l of i.ranges)r.push(p.range(l.anchor-a,l.head-a))}}return o.length?(t(e.update({changes:o,scrollIntoView:!0,selection:p.create(r,e.selection.mainIndex),userEvent:"move.line"})),!0):!1}var xi=({state:e,dispatch:t})=>bo(e,t,!1),yi=({state:e,dispatch:t})=>bo(e,t,!0);function Lo(e,t,n){if(e.readOnly)return!1;let o=[];for(let i of Re(e))n?o.push({from:i.from,insert:e.doc.slice(i.from,i.to)+e.lineBreak}):o.push({from:i.to,insert:e.lineBreak+e.doc.slice(i.from,i.to)});let r=e.changes(o);return t(e.update({changes:r,selection:e.selection.map(r,n?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}var Ci=({state:e,dispatch:t})=>Lo(e,t,!1),Si=({state:e,dispatch:t})=>Lo(e,t,!0),ki=e=>{if(e.state.readOnly)return!1;let{state:t}=e,n=t.changes(Re(t).map(({from:r,to:i})=>(r>0?r--:i<t.doc.length&&i++,{from:r,to:i}))),o=Q(t.selection,r=>{let i;if(e.lineWrapping){let s=e.lineBlockAt(r.head),a=e.coordsAtPos(r.head,r.assoc||1);a&&(i=s.bottom+e.documentTop-a.bottom+e.defaultLineHeight/2)}return e.moveVertically(r,!0,i)}).map(n);return e.dispatch({changes:n,selection:o,scrollIntoView:!0,userEvent:"delete.line"}),!0};function bi(e,t){if(/\(\)|\[\]|\{\}/.test(e.sliceDoc(t-1,t+1)))return{from:t,to:t};let n=ke(e).resolveInner(t),o=n.childBefore(t),r=n.childAfter(t),i;return o&&r&&o.to<=t&&r.from>=t&&(i=o.type.prop(Se.closedBy))&&i.indexOf(r.name)>-1&&e.doc.lineAt(o.to).from==e.doc.lineAt(r.from).from&&!/\S/.test(e.sliceDoc(o.to,r.from))?{from:o.to,to:r.from}:null}var jn=vo(!1),Li=vo(!0);function vo(e){return({state:t,dispatch:n})=>{if(t.readOnly)return!1;let o=t.changeByRange(r=>{let{from:i,to:s}=r,a=t.doc.lineAt(i),l=!e&&i==s&&bi(t,i);e&&(i=s=(s<=a.to?a:t.doc.lineAt(s)).to);let h=new dt(t,{simulateBreak:i,simulateDoubleBreak:!!l}),m=mt(h,i);for(m==null&&(m=Ce(/^\s*/.exec(t.doc.lineAt(i).text)[0],t.tabSize));s<a.to&&/\s/.test(a.text[s-a.from]);)s++;l?{from:i,to:s}=l:i>a.from&&i<a.from+100&&!/\S/.test(a.text.slice(0,i))&&(i=a.from);let d=["",ae(t,m)];return l&&d.push(ae(t,h.lineIndent(a.from,-1))),{changes:{from:i,to:s,insert:ht.of(d)},range:p.cursor(i+1+d[1].length)}});return n(t.update(o,{scrollIntoView:!0,userEvent:"input"})),!0}}function kt(e,t){let n=-1;return e.changeByRange(o=>{let r=[];for(let s=o.from;s<=o.to;){let a=e.doc.lineAt(s);a.number>n&&(o.empty||o.to>a.from)&&(t(a,r,o),n=a.number),s=a.to+1}let i=e.changes(r);return{changes:r,range:p.range(i.mapPos(o.anchor,1),i.mapPos(o.head,1))}})}var vi=({state:e,dispatch:t})=>{if(e.readOnly)return!1;let n=Object.create(null),o=new dt(e,{overrideIndentation:i=>{let s=n[i];return s??-1}}),r=kt(e,(i,s,a)=>{let l=mt(o,i.from);if(l==null)return;/\S/.test(i.text)||(l=0);let h=/^\s*/.exec(i.text)[0],m=ae(e,l);(h!=m||a.from<i.from+h.length)&&(n[i.from]=l,s.push({from:i.from,to:i.from+h.length,insert:m}))});return r.changes.empty||t(e.update(r,{userEvent:"indent"})),!0},wo=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(kt(e,(n,o)=>{o.push({from:n.from,insert:e.facet(vn)})}),{userEvent:"input.indent"})),!0),Mo=({state:e,dispatch:t})=>e.readOnly?!1:(t(e.update(kt(e,(n,o)=>{let r=/^\s*/.exec(n.text)[0];if(!r)return;let i=Ce(r,e.tabSize),s=0,a=ae(e,Math.max(0,i-Le(e)));for(;s<r.length&&s<a.length&&r.charCodeAt(s)==a.charCodeAt(s);)s++;o.push({from:n.from+s,to:n.from+r.length,insert:a.slice(s)})}),{userEvent:"delete.dedent"})),!0),wi=e=>(e.setTabFocusMode(),!0);var Mi=[{key:"Ctrl-b",run:eo,shift:co,preventDefault:!0},{key:"Ctrl-f",run:to,shift:ho},{key:"Ctrl-p",run:ro,shift:fo},{key:"Ctrl-n",run:io,shift:po},{key:"Ctrl-a",run:qr,shift:oi},{key:"Ctrl-e",run:Hr,shift:ri},{key:"Ctrl-d",run:Co},{key:"Ctrl-h",run:yt},{key:"Ctrl-k",run:mi},{key:"Ctrl-Alt-h",run:ko},{key:"Ctrl-o",run:pi},{key:"Ctrl-t",run:gi},{key:"Ctrl-v",run:xt}],Ai=[{key:"ArrowLeft",run:eo,shift:co,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Fr,shift:Jr,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:_r,shift:ti,preventDefault:!0},{key:"ArrowRight",run:to,shift:ho,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Or,shift:Kr,preventDefault:!0},{mac:"Cmd-ArrowRight",run:jr,shift:ni,preventDefault:!0},{key:"ArrowUp",run:ro,shift:fo,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Wn,shift:zn},{mac:"Ctrl-ArrowUp",run:On,shift:Un},{key:"ArrowDown",run:io,shift:po,preventDefault:!0},{mac:"Cmd-ArrowDown",run:$n,shift:_n},{mac:"Ctrl-ArrowDown",run:xt,shift:Nn},{key:"PageUp",run:On,shift:Un},{key:"PageDown",run:xt,shift:Nn},{key:"Home",run:zr,shift:ei,preventDefault:!0},{key:"Mod-Home",run:Wn,shift:zn},{key:"End",run:$r,shift:Zr,preventDefault:!0},{key:"Mod-End",run:$n,shift:_n},{key:"Enter",run:jn,shift:jn},{key:"Mod-a",run:ii},{key:"Backspace",run:yt,shift:yt,preventDefault:!0},{key:"Delete",run:Co,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:ko,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:ui,preventDefault:!0},{mac:"Mod-Backspace",run:di,preventDefault:!0},{mac:"Mod-Delete",run:fi,preventDefault:!0}].concat(Mi.map(e=>({mac:e.key,run:e.run,shift:e.shift}))),Ao=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Nr,shift:Qr},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Wr,shift:Xr},{key:"Alt-ArrowUp",run:xi},{key:"Shift-Alt-ArrowUp",run:Ci},{key:"Alt-ArrowDown",run:yi},{key:"Shift-Alt-ArrowDown",run:Si},{key:"Mod-Alt-ArrowUp",run:li},{key:"Mod-Alt-ArrowDown",run:ci},{key:"Escape",run:hi},{key:"Mod-Enter",run:Li},{key:"Alt-l",mac:"Ctrl-l",run:si},{key:"Mod-i",run:ai,preventDefault:!0},{key:"Mod-[",run:Mo},{key:"Mod-]",run:wo},{key:"Mod-Alt-\\",run:vi},{key:"Shift-Mod-k",run:ki},{key:"Shift-Mod-\\",run:Gr},{key:"Mod-/",run:Cr},{key:"Alt-A",run:kr},{key:"Ctrl-m",mac:"Shift-Alt-m",run:wi}].concat(Ai),To={key:"Tab",run:wo,shift:Mo};function u(e){return new be(we.define(e))}function W(e){return import("./dist-DPBSGC3Y.js").then(t=>t.sql({dialect:t[e]}))}var Bo=[c.of({name:"C",extensions:["c","h","ino"],load(){return import("./dist-IQA4KVJK.js").then(e=>e.cpp())}}),c.of({name:"C++",alias:["cpp"],extensions:["cpp","c++","cc","cxx","hpp","h++","hh","hxx"],load(){return import("./dist-IQA4KVJK.js").then(e=>e.cpp())}}),c.of({name:"CQL",alias:["cassandra"],extensions:["cql"],load(){return W("Cassandra")}}),c.of({name:"CSS",extensions:["css"],load(){return import("./dist-HAB5NIXI.js").then(e=>e.css())}}),c.of({name:"Go",extensions:["go"],load(){return import("./dist-7RQKSOUX.js").then(e=>e.go())}}),c.of({name:"HTML",alias:["xhtml"],extensions:["html","htm","handlebars","hbs"],load(){return import("./dist-XOODBV4L.js").then(e=>e.html())}}),c.of({name:"Java",extensions:["java"],load(){return import("./dist-RCQFQRLD.js").then(e=>e.java())}}),c.of({name:"JavaScript",alias:["ecmascript","js","node"],extensions:["js","mjs","cjs"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript())}}),c.of({name:"Jinja",extensions:["j2","jinja","jinja2"],load(){return import("./dist-E5NM7OBW.js").then(e=>e.jinja())}}),c.of({name:"JSON",alias:["json5"],extensions:["json","map"],load(){return import("./dist-F43RIHBZ.js").then(e=>e.json())}}),c.of({name:"JSX",extensions:["jsx"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript({jsx:!0}))}}),c.of({name:"LESS",extensions:["less"],load(){return import("./dist-ZFZNCRZY.js").then(e=>e.less())}}),c.of({name:"Liquid",extensions:["liquid"],load(){return import("./dist-RSJGLSKC.js").then(e=>e.liquid())}}),c.of({name:"MariaDB SQL",load(){return W("MariaSQL")}}),c.of({name:"Markdown",extensions:["md","markdown","mkd"],load(){return import("./dist-RQLC4GVI.js").then(e=>e.markdown())}}),c.of({name:"MS SQL",load(){return W("MSSQL")}}),c.of({name:"MySQL",load(){return W("MySQL")}}),c.of({name:"PHP",extensions:["php","php3","php4","php5","php7","phtml"],load(){return import("./dist-HG23OLRA.js").then(e=>e.php())}}),c.of({name:"PLSQL",extensions:["pls"],load(){return W("PLSQL")}}),c.of({name:"PostgreSQL",load(){return W("PostgreSQL")}}),c.of({name:"Python",extensions:["BUILD","bzl","py","pyw"],filename:/^(BUCK|BUILD)$/,load(){return import("./dist-OIQTNVT2.js").then(e=>e.python())}}),c.of({name:"Rust",extensions:["rs"],load(){return import("./dist-VCFTF7Z6.js").then(e=>e.rust())}}),c.of({name:"Sass",extensions:["sass"],load(){return import("./dist-ARWGZ6MN.js").then(e=>e.sass({indented:!0}))}}),c.of({name:"SCSS",extensions:["scss"],load(){return import("./dist-ARWGZ6MN.js").then(e=>e.sass())}}),c.of({name:"SQL",extensions:["sql"],load(){return W("StandardSQL")}}),c.of({name:"SQLite",load(){return W("SQLite")}}),c.of({name:"TSX",extensions:["tsx"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript({jsx:!0,typescript:!0}))}}),c.of({name:"TypeScript",alias:["ts"],extensions:["ts","mts","cts"],load(){return import("./dist-ERADYPEK.js").then(e=>e.javascript({typescript:!0}))}}),c.of({name:"WebAssembly",extensions:["wat","wast"],load(){return import("./dist-PMZJ734S.js").then(e=>e.wast())}}),c.of({name:"XML",alias:["rss","wsdl","xsd"],extensions:["xml","xsl","xsd","svg"],load(){return import("./dist-IEJXBSDJ.js").then(e=>e.xml())}}),c.of({name:"YAML",alias:["yml"],extensions:["yaml","yml"],load(){return import("./dist-VTO23SHH.js").then(e=>e.yaml())}}),c.of({name:"APL",extensions:["dyalog","apl"],load(){return import("./apl-C5P5JBDI.js").then(e=>u(e.apl))}}),c.of({name:"PGP",alias:["asciiarmor"],extensions:["asc","pgp","sig"],load(){return import("./asciiarmor-3NCLLELT.js").then(e=>u(e.asciiArmor))}}),c.of({name:"ASN.1",extensions:["asn","asn1"],load(){return import("./asn1-KF4WXU3M.js").then(e=>u(e.asn1({})))}}),c.of({name:"Asterisk",filename:/^extensions\.conf$/i,load(){return import("./asterisk-EA3VIN65.js").then(e=>u(e.asterisk))}}),c.of({name:"Brainfuck",extensions:["b","bf"],load(){return import("./brainfuck-A3CTQVFD.js").then(e=>u(e.brainfuck))}}),c.of({name:"Cobol",extensions:["cob","cpy"],load(){return import("./cobol-V6EIK6DN.js").then(e=>u(e.cobol))}}),c.of({name:"C#",alias:["csharp","cs"],extensions:["cs"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.csharp))}}),c.of({name:"Clojure",extensions:["clj","cljc","cljx"],load(){return import("./clojure-BR2VJ2JI.js").then(e=>u(e.clojure))}}),c.of({name:"ClojureScript",extensions:["cljs"],load(){return import("./clojure-BR2VJ2JI.js").then(e=>u(e.clojure))}}),c.of({name:"Closure Stylesheets (GSS)",extensions:["gss"],load(){return import("./css-C5DVWGB4.js").then(e=>u(e.gss))}}),c.of({name:"CMake",extensions:["cmake","cmake.in"],filename:/^CMakeLists\.txt$/,load(){return import("./cmake-2HEWVFEE.js").then(e=>u(e.cmake))}}),c.of({name:"CoffeeScript",alias:["coffee","coffee-script"],extensions:["coffee"],load(){return import("./coffeescript-JW3ZOGMD.js").then(e=>u(e.coffeeScript))}}),c.of({name:"Common Lisp",alias:["lisp"],extensions:["cl","lisp","el"],load(){return import("./commonlisp-UCWSIHYK.js").then(e=>u(e.commonLisp))}}),c.of({name:"Cypher",extensions:["cyp","cypher"],load(){return import("./cypher-K7FZM5GC.js").then(e=>u(e.cypher))}}),c.of({name:"Cython",extensions:["pyx","pxd","pxi"],load(){return import("./python-6YGH4S47.js").then(e=>u(e.cython))}}),c.of({name:"Crystal",extensions:["cr"],load(){return import("./crystal-GR4VLC3M.js").then(e=>u(e.crystal))}}),c.of({name:"D",extensions:["d"],load(){return import("./d-CF3QNNH5.js").then(e=>u(e.d))}}),c.of({name:"Dart",extensions:["dart"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.dart))}}),c.of({name:"diff",extensions:["diff","patch"],load(){return import("./diff-KOMSZU7O.js").then(e=>u(e.diff))}}),c.of({name:"Dockerfile",filename:/^Dockerfile$/,load(){return import("./dockerfile-XCIKYOSI.js").then(e=>u(e.dockerFile))}}),c.of({name:"DTD",extensions:["dtd"],load(){return import("./dtd-3XFH7W6Z.js").then(e=>u(e.dtd))}}),c.of({name:"Dylan",extensions:["dylan","dyl","intr"],load(){return import("./dylan-3UWPKVOR.js").then(e=>u(e.dylan))}}),c.of({name:"EBNF",load(){return import("./ebnf-OLHTL3VN.js").then(e=>u(e.ebnf))}}),c.of({name:"ECL",extensions:["ecl"],load(){return import("./ecl-43LZ3ZRM.js").then(e=>u(e.ecl))}}),c.of({name:"edn",extensions:["edn"],load(){return import("./clojure-BR2VJ2JI.js").then(e=>u(e.clojure))}}),c.of({name:"Eiffel",extensions:["e"],load(){return import("./eiffel-ISPO2UJF.js").then(e=>u(e.eiffel))}}),c.of({name:"Elm",extensions:["elm"],load(){return import("./elm-CLK576PK.js").then(e=>u(e.elm))}}),c.of({name:"Erlang",extensions:["erl"],load(){return import("./erlang-AVQXQFOT.js").then(e=>u(e.erlang))}}),c.of({name:"Esper",load(){return import("./sql-BPLIIUYC.js").then(e=>u(e.esper))}}),c.of({name:"Factor",extensions:["factor"],load(){return import("./factor-CRTVBD6Q.js").then(e=>u(e.factor))}}),c.of({name:"FCL",load(){return import("./fcl-FX24LKTH.js").then(e=>u(e.fcl))}}),c.of({name:"Forth",extensions:["forth","fth","4th"],load(){return import("./forth-YKDKCTVS.js").then(e=>u(e.forth))}}),c.of({name:"Fortran",extensions:["f","for","f77","f90","f95"],load(){return import("./fortran-UJWC6SLU.js").then(e=>u(e.fortran))}}),c.of({name:"F#",alias:["fsharp"],extensions:["fs"],load(){return import("./mllike-VV3KS46B.js").then(e=>u(e.fSharp))}}),c.of({name:"Gas",extensions:["s"],load(){return import("./gas-MYEMWGRE.js").then(e=>u(e.gas))}}),c.of({name:"Gherkin",extensions:["feature"],load(){return import("./gherkin-JWHAU2YG.js").then(e=>u(e.gherkin))}}),c.of({name:"Groovy",extensions:["groovy","gradle"],filename:/^Jenkinsfile$/,load(){return import("./groovy-QZIZQIAK.js").then(e=>u(e.groovy))}}),c.of({name:"Haskell",extensions:["hs"],load(){return import("./haskell-JR3G7YNW.js").then(e=>u(e.haskell))}}),c.of({name:"Haxe",extensions:["hx"],load(){return import("./haxe-TVLAIYEN.js").then(e=>u(e.haxe))}}),c.of({name:"HXML",extensions:["hxml"],load(){return import("./haxe-TVLAIYEN.js").then(e=>u(e.hxml))}}),c.of({name:"HTTP",load(){return import("./http-YXQRE77G.js").then(e=>u(e.http))}}),c.of({name:"IDL",extensions:["pro"],load(){return import("./idl-RAQGJ6LJ.js").then(e=>u(e.idl))}}),c.of({name:"JSON-LD",alias:["jsonld"],extensions:["jsonld"],load(){return import("./javascript-NM7KDJUE.js").then(e=>u(e.jsonld))}}),c.of({name:"Julia",extensions:["jl"],load(){return import("./julia-LG3BH25B.js").then(e=>u(e.julia))}}),c.of({name:"Kotlin",extensions:["kt","kts"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.kotlin))}}),c.of({name:"LiveScript",alias:["ls"],extensions:["ls"],load(){return import("./livescript-4CVWVI4M.js").then(e=>u(e.liveScript))}}),c.of({name:"Lua",extensions:["lua"],load(){return import("./lua-VWGE7DQ7.js").then(e=>u(e.lua))}}),c.of({name:"mIRC",extensions:["mrc"],load(){return import("./mirc-565WBI76.js").then(e=>u(e.mirc))}}),c.of({name:"Mathematica",extensions:["m","nb","wl","wls"],load(){return import("./mathematica-D7APQSEU.js").then(e=>u(e.mathematica))}}),c.of({name:"Modelica",extensions:["mo"],load(){return import("./modelica-EGX44FZV.js").then(e=>u(e.modelica))}}),c.of({name:"MUMPS",extensions:["mps"],load(){return import("./mumps-POZYWSMI.js").then(e=>u(e.mumps))}}),c.of({name:"Mbox",extensions:["mbox"],load(){return import("./mbox-BN3XQBYX.js").then(e=>u(e.mbox))}}),c.of({name:"Nginx",filename:/nginx.*\.conf$/i,load(){return import("./nginx-JUBX55EU.js").then(e=>u(e.nginx))}}),c.of({name:"NSIS",extensions:["nsh","nsi"],load(){return import("./nsis-RC4CREGM.js").then(e=>u(e.nsis))}}),c.of({name:"NTriples",extensions:["nt","nq"],load(){return import("./ntriples-4WK6CNVE.js").then(e=>u(e.ntriples))}}),c.of({name:"Objective-C",alias:["objective-c","objc"],extensions:["m"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.objectiveC))}}),c.of({name:"Objective-C++",alias:["objective-c++","objc++"],extensions:["mm"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.objectiveCpp))}}),c.of({name:"OCaml",extensions:["ml","mli","mll","mly"],load(){return import("./mllike-VV3KS46B.js").then(e=>u(e.oCaml))}}),c.of({name:"Octave",extensions:["m"],load(){return import("./octave-GOKFN2V7.js").then(e=>u(e.octave))}}),c.of({name:"Oz",extensions:["oz"],load(){return import("./oz-OQUMNC63.js").then(e=>u(e.oz))}}),c.of({name:"Pascal",extensions:["p","pas"],load(){return import("./pascal-BBWQWWWD.js").then(e=>u(e.pascal))}}),c.of({name:"Perl",extensions:["pl","pm"],load(){return import("./perl-KTPJTTAM.js").then(e=>u(e.perl))}}),c.of({name:"Pig",extensions:["pig"],load(){return import("./pig-IJMBS4FZ.js").then(e=>u(e.pig))}}),c.of({name:"PowerShell",extensions:["ps1","psd1","psm1"],load(){return import("./powershell-6YGCBHDP.js").then(e=>u(e.powerShell))}}),c.of({name:"Properties files",alias:["ini","properties"],extensions:["properties","ini","in"],load(){return import("./properties-5QTD3364.js").then(e=>u(e.properties))}}),c.of({name:"ProtoBuf",extensions:["proto"],load(){return import("./protobuf-LTRWBIK3.js").then(e=>u(e.protobuf))}}),c.of({name:"Pug",alias:["jade"],extensions:["pug","jade"],load(){return import("./pug-U4PV3WLG.js").then(e=>u(e.pug))}}),c.of({name:"Puppet",extensions:["pp"],load(){return import("./puppet-WGYJPR3Y.js").then(e=>u(e.puppet))}}),c.of({name:"Q",extensions:["q"],load(){return import("./q-VIG4IJLI.js").then(e=>u(e.q))}}),c.of({name:"R",alias:["rscript"],extensions:["r","R"],load(){return import("./r-NVPCXGTR.js").then(e=>u(e.r))}}),c.of({name:"RPM Changes",load(){return import("./rpm-UEA257HD.js").then(e=>u(e.rpmChanges))}}),c.of({name:"RPM Spec",extensions:["spec"],load(){return import("./rpm-UEA257HD.js").then(e=>u(e.rpmSpec))}}),c.of({name:"Ruby",alias:["jruby","macruby","rake","rb","rbx"],extensions:["rb"],filename:/^(Gemfile|Rakefile)$/,load(){return import("./ruby-KPQRAJGE.js").then(e=>u(e.ruby))}}),c.of({name:"SAS",extensions:["sas"],load(){return import("./sas-L7VATVH5.js").then(e=>u(e.sas))}}),c.of({name:"Scala",extensions:["scala"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.scala))}}),c.of({name:"Scheme",extensions:["scm","ss"],load(){return import("./scheme-T2NOWR3P.js").then(e=>u(e.scheme))}}),c.of({name:"Shell",alias:["bash","sh","zsh"],extensions:["sh","ksh","bash"],filename:/^PKGBUILD$/,load(){return import("./shell-DLVDUNFA.js").then(e=>u(e.shell))}}),c.of({name:"Sieve",extensions:["siv","sieve"],load(){return import("./sieve-BKBZYDBU.js").then(e=>u(e.sieve))}}),c.of({name:"Smalltalk",extensions:["st"],load(){return import("./smalltalk-WRJQKJSD.js").then(e=>u(e.smalltalk))}}),c.of({name:"Solr",load(){return import("./solr-66B3BIDL.js").then(e=>u(e.solr))}}),c.of({name:"SML",extensions:["sml","sig","fun","smackspec"],load(){return import("./mllike-VV3KS46B.js").then(e=>u(e.sml))}}),c.of({name:"SPARQL",alias:["sparul"],extensions:["rq","sparql"],load(){return import("./sparql-S25Z47JG.js").then(e=>u(e.sparql))}}),c.of({name:"Spreadsheet",alias:["excel","formula"],load(){return import("./spreadsheet-B272EF7Y.js").then(e=>u(e.spreadsheet))}}),c.of({name:"Squirrel",extensions:["nut"],load(){return import("./clike-RTBH33GE.js").then(e=>u(e.squirrel))}}),c.of({name:"Stylus",extensions:["styl"],load(){return import("./stylus-PJUHLGPT.js").then(e=>u(e.stylus))}}),c.of({name:"Swift",extensions:["swift"],load(){return import("./swift-UYHTO4SX.js").then(e=>u(e.swift))}}),c.of({name:"sTeX",load(){return import("./stex-4IJY64QX.js").then(e=>u(e.stex))}}),c.of({name:"LaTeX",alias:["tex"],extensions:["text","ltx","tex"],load(){return import("./stex-4IJY64QX.js").then(e=>u(e.stex))}}),c.of({name:"SystemVerilog",extensions:["v","sv","svh"],load(){return import("./verilog-EWWQPMNN.js").then(e=>u(e.verilog))}}),c.of({name:"Tcl",extensions:["tcl"],load(){return import("./tcl-OQ5J3VO2.js").then(e=>u(e.tcl))}}),c.of({name:"Textile",extensions:["textile"],load(){return import("./textile-NOGVBEYF.js").then(e=>u(e.textile))}}),c.of({name:"TiddlyWiki",load(){return import("./tiddlywiki-SYTK4QUE.js").then(e=>u(e.tiddlyWiki))}}),c.of({name:"Tiki wiki",load(){return import("./tiki-P7K4ZLOM.js").then(e=>u(e.tiki))}}),c.of({name:"TOML",extensions:["toml"],load(){return import("./toml-AUZYRP36.js").then(e=>u(e.toml))}}),c.of({name:"Troff",extensions:["1","2","3","4","5","6","7","8","9"],load(){return import("./troff-XFYJNQOJ.js").then(e=>u(e.troff))}}),c.of({name:"TTCN",extensions:["ttcn","ttcn3","ttcnpp"],load(){return import("./ttcn-AK2IXWU6.js").then(e=>u(e.ttcn))}}),c.of({name:"TTCN_CFG",extensions:["cfg"],load(){return import("./ttcn-cfg-3IDPIYPU.js").then(e=>u(e.ttcnCfg))}}),c.of({name:"Turtle",extensions:["ttl"],load(){return import("./turtle-OIDMF46P.js").then(e=>u(e.turtle))}}),c.of({name:"Web IDL",extensions:["webidl"],load(){return import("./webidl-XVBHXCRV.js").then(e=>u(e.webIDL))}}),c.of({name:"VB.NET",extensions:["vb"],load(){return import("./vb-J6K4XVA2.js").then(e=>u(e.vb))}}),c.of({name:"VBScript",extensions:["vbs"],load(){return import("./vbscript-FM7DDZZE.js").then(e=>u(e.vbScript))}}),c.of({name:"Velocity",extensions:["vtl"],load(){return import("./velocity-6KZFEOFD.js").then(e=>u(e.velocity))}}),c.of({name:"Verilog",extensions:["v"],load(){return import("./verilog-EWWQPMNN.js").then(e=>u(e.verilog))}}),c.of({name:"VHDL",extensions:["vhd","vhdl"],load(){return import("./vhdl-CJ3M4IHI.js").then(e=>u(e.vhdl))}}),c.of({name:"XQuery",extensions:["xy","xquery","xq","xqm","xqy"],load(){return import("./xquery-7WZOZ4UK.js").then(e=>u(e.xQuery))}}),c.of({name:"Yacas",extensions:["ys"],load(){return import("./yacas-MZ2ZZPF3.js").then(e=>u(e.yacas))}}),c.of({name:"Z80",extensions:["z80"],load(){return import("./z80-I447CBF7.js").then(e=>u(e.z80))}}),c.of({name:"MscGen",extensions:["mscgen","mscin","msc"],load(){return import("./mscgen-GFGTHENT.js").then(e=>u(e.mscgen))}}),c.of({name:"X\xF9",extensions:["xu"],load(){return import("./mscgen-GFGTHENT.js").then(e=>u(e.xu))}}),c.of({name:"MsGenny",extensions:["msgenny"],load(){return import("./mscgen-GFGTHENT.js").then(e=>u(e.msgenny))}}),c.of({name:"Vue",extensions:["vue"],load(){return import("./dist-E36PJE5M.js").then(e=>e.vue())}}),c.of({name:"Angular Template",load(){return import("./dist-SGNQZVVX.js").then(e=>e.angular())}})];var Do=typeof String.prototype.normalize=="function"?e=>e.normalize("NFKD"):e=>e,z=class{constructor(t,n,o=0,r=t.length,i,s){this.test=s,this.value={from:0,to:0},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=t.iterRange(o,r),this.bufferStart=o,this.normalize=i?a=>i(Do(a)):Do,this.query=this.normalize(n)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return on(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let t=this.peek();if(t<0)return this.done=!0,this;let n=rn(t),o=this.bufferStart+this.bufferPos;this.bufferPos+=sn(t);let r=this.normalize(n);if(r.length)for(let i=0,s=o;;i++){let a=r.charCodeAt(i),l=this.match(a,s,this.bufferPos+this.bufferStart);if(i==r.length-1){if(l)return this.value=l,this;break}s==o&&i<n.length&&n.charCodeAt(i)==a&&s++}}}match(t,n,o){let r=null;for(let i=0;i<this.matches.length;i+=2){let s=this.matches[i],a=!1;this.query.charCodeAt(s)==t&&(s==this.query.length-1?r={from:this.matches[i+1],to:o}:(this.matches[i]++,a=!0)),a||(this.matches.splice(i,2),i-=2)}return this.query.charCodeAt(0)==t&&(this.query.length==1?r={from:n,to:o}:this.matches.push(1,n)),r&&this.test&&!this.test(r.from,r.to,this.buffer,this.bufferStart)&&(r=null),r}};typeof Symbol<"u"&&(z.prototype[Symbol.iterator]=function(){return this});var Ro={from:-1,to:-1,match:/.*/.exec("")},At="gm"+(/x/.unicode==null?"":"u"),Fe=class{constructor(t,n,o,r=0,i=t.length){if(this.text=t,this.to=i,this.curLine="",this.done=!1,this.value=Ro,/\\[sWDnr]|\n|\r|\[\^/.test(n))return new Ue(t,n,o,r,i);this.re=new RegExp(n,At+(o?.ignoreCase?"i":"")),this.test=o?.test,this.iter=t.iter();let s=t.lineAt(r);this.curLineStart=s.from,this.matchPos=Ne(t,r),this.getLine(this.curLineStart)}getLine(t){this.iter.next(t),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let t=this.matchPos-this.curLineStart;;){this.re.lastIndex=t;let n=this.matchPos<=this.to&&this.re.exec(this.curLine);if(n){let o=this.curLineStart+n.index,r=o+n[0].length;if(this.matchPos=Ne(this.text,r+(o==r?1:0)),o==this.curLineStart+this.curLine.length&&this.nextLine(),(o<r||o>this.value.to)&&(!this.test||this.test(o,r,n)))return this.value={from:o,to:r,match:n},this;t=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),t=0;else return this.done=!0,this}}},bt=new WeakMap,Oe=class e{constructor(t,n){this.from=t,this.text=n}get to(){return this.from+this.text.length}static get(t,n,o){let r=bt.get(t);if(!r||r.from>=o||r.to<=n){let a=new e(n,t.sliceString(n,o));return bt.set(t,a),a}if(r.from==n&&r.to==o)return r;let{text:i,from:s}=r;return s>n&&(i=t.sliceString(n,s)+i,s=n),r.to<o&&(i+=t.sliceString(r.to,o)),bt.set(t,new e(s,i)),new e(n,i.slice(n-s,o-s))}},Ue=class{constructor(t,n,o,r,i){this.text=t,this.to=i,this.done=!1,this.value=Ro,this.matchPos=Ne(t,r),this.re=new RegExp(n,At+(o?.ignoreCase?"i":"")),this.test=o?.test,this.flat=Oe.get(t,r,this.chunkEnd(r+5e3))}chunkEnd(t){return t>=this.to?this.to:this.text.lineAt(t).to}next(){for(;;){let t=this.re.lastIndex=this.matchPos-this.flat.from,n=this.re.exec(this.flat.text);if(n&&!n[0]&&n.index==t&&(this.re.lastIndex=t+1,n=this.re.exec(this.flat.text)),n){let o=this.flat.from+n.index,r=o+n[0].length;if((this.flat.to>=this.to||n.index+n[0].length<=this.flat.text.length-10)&&(!this.test||this.test(o,r,n)))return this.value={from:o,to:r,match:n},this.matchPos=Ne(this.text,r+(o==r?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=Oe.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}};typeof Symbol<"u"&&(Fe.prototype[Symbol.iterator]=Ue.prototype[Symbol.iterator]=function(){return this});function Ti(e){try{return new RegExp(e,At),!0}catch{return!1}}function Ne(e,t){if(t>=e.length)return t;let n=e.lineAt(t),o;for(;t<n.to&&(o=n.text.charCodeAt(t-n.from))>=56320&&o<57344;)t++;return t}var Bi=e=>{let{state:t}=e,n=String(t.doc.lineAt(e.state.selection.main.head).number),{close:o,result:r}=kn(e,{label:t.phrase("Go to line"),input:{type:"text",name:"line",value:n},focus:!0,submitLabel:t.phrase("go")});return r.then(i=>{let s=i&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(i.elements.line.value);if(!s){e.dispatch({effects:o});return}let a=t.doc.lineAt(t.selection.main.head),[,l,h,m,d]=s,g=m?+m.slice(1):0,C=h?+h:a.number;if(h&&d){let b=C/100;l&&(b=b*(l=="-"?-1:1)+a.number/t.doc.lines),C=Math.round(t.doc.lines*b)}else h&&l&&(C=C*(l=="-"?-1:1)+a.number);let x=t.doc.line(Math.max(1,Math.min(t.doc.lines,C))),k=p.cursor(x.from+Math.max(0,Math.min(g,x.length)));e.dispatch({effects:[o,y.scrollIntoView(k.from,{y:"center"})],selection:k})}),!0},Di={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Po=P.define({combine(e){return se(e,Di,{highlightWordAroundCursor:(t,n)=>t||n,minSelectionLength:Math.min,maxMatches:Math.min})}});function Vo(e){let t=[Vi,Pi];return e&&t.push(Po.of(e)),t}var Ei=S.mark({class:"cm-selectionMatch"}),Ii=S.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function Eo(e,t,n,o){return(n==0||e(t.sliceDoc(n-1,n))!=v.Word)&&(o==t.doc.length||e(t.sliceDoc(o,o+1))!=v.Word)}function Ri(e,t,n,o){return e(t.sliceDoc(n,n+1))==v.Word&&e(t.sliceDoc(o-1,o))==v.Word}var Pi=O.fromClass(class{constructor(e){this.decorations=this.getDeco(e)}update(e){(e.selectionSet||e.docChanged||e.viewportChanged)&&(this.decorations=this.getDeco(e.view))}getDeco(e){let t=e.state.facet(Po),{state:n}=e,o=n.selection;if(o.ranges.length>1)return S.none;let r=o.main,i,s=null;if(r.empty){if(!t.highlightWordAroundCursor)return S.none;let l=n.wordAt(r.head);if(!l)return S.none;s=n.charCategorizer(r.head),i=n.sliceDoc(l.from,l.to)}else{let l=r.to-r.from;if(l<t.minSelectionLength||l>200)return S.none;if(t.wholeWords){if(i=n.sliceDoc(r.from,r.to),s=n.charCategorizer(r.head),!(Eo(s,n,r.from,r.to)&&Ri(s,n,r.from,r.to)))return S.none}else if(i=n.sliceDoc(r.from,r.to),!i)return S.none}let a=[];for(let l of e.visibleRanges){let h=new z(n.doc,i,l.from,l.to);for(;!h.next().done;){let{from:m,to:d}=h.value;if((!s||Eo(s,n,m,d))&&(r.empty&&m<=r.from&&d>=r.to?a.push(Ii.range(m,d)):(m>=r.to||d<=r.from)&&a.push(Ei.range(m,d)),a.length>t.maxMatches))return S.none}}return S.set(a)}},{decorations:e=>e.decorations}),Vi=y.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Fi=({state:e,dispatch:t})=>{let{selection:n}=e,o=p.create(n.ranges.map(r=>e.wordAt(r.head)||p.cursor(r.head)),n.mainIndex);return o.eq(n)?!1:(t(e.update({selection:o})),!0)};function Oi(e,t){let{main:n,ranges:o}=e.selection,r=e.wordAt(n.head),i=r&&r.from==n.from&&r.to==n.to;for(let s=!1,a=new z(e.doc,t,o[o.length-1].to);;)if(a.next(),a.done){if(s)return null;a=new z(e.doc,t,0,Math.max(0,o[o.length-1].from-1)),s=!0}else{if(s&&o.some(l=>l.from==a.value.from))continue;if(i){let l=e.wordAt(a.value.from);if(!l||l.from!=a.value.from||l.to!=a.value.to)continue}return a.value}}var Ui=({state:e,dispatch:t})=>{let{ranges:n}=e.selection;if(n.some(i=>i.from===i.to))return Fi({state:e,dispatch:t});let o=e.sliceDoc(n[0].from,n[0].to);if(e.selection.ranges.some(i=>e.sliceDoc(i.from,i.to)!=o))return!1;let r=Oi(e,o);return r?(t(e.update({selection:e.selection.addRange(p.range(r.from,r.to),!1),effects:y.scrollIntoView(r.to)})),!0):!1},ee=P.define({combine(e){return se(e,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:t=>new Mt(t),scrollToMatch:t=>y.scrollIntoView(t)})}});var We=class{constructor(t){this.search=t.search,this.caseSensitive=!!t.caseSensitive,this.literal=!!t.literal,this.regexp=!!t.regexp,this.replace=t.replace||"",this.valid=!!this.search&&(!this.regexp||Ti(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!t.wholeWord,this.test=t.test}unquote(t){return this.literal?t:t.replace(/\\([nrt\\])/g,(n,o)=>o=="n"?`
2
- `:o=="r"?"\r":o=="t"?" ":"\\")}eq(t){return this.search==t.search&&this.replace==t.replace&&this.caseSensitive==t.caseSensitive&&this.regexp==t.regexp&&this.wholeWord==t.wholeWord&&this.test==t.test}create(){return this.regexp?new vt(this):new Lt(this)}getCursor(t,n=0,o){let r=t.doc?t:ie.create({doc:t});return o==null&&(o=r.doc.length),this.regexp?Z(this,r,n,o):X(this,r,n,o)}},$e=class{constructor(t){this.spec=t}};function Ni(e,t,n){return(o,r,i,s)=>{if(n&&!n(o,r,i,s))return!1;let a=o>=s&&r<=s+i.length?i.slice(o-s,r-s):t.doc.sliceString(o,r);return e(a,t,o,r)}}function X(e,t,n,o){let r;return e.wholeWord&&(r=Wi(t.doc,t.charCategorizer(t.selection.main.head))),e.test&&(r=Ni(e.test,t,r)),new z(t.doc,e.unquoted,n,o,e.caseSensitive?void 0:i=>i.toLowerCase(),r)}function Wi(e,t){return(n,o,r,i)=>((i>n||i+r.length<o)&&(i=Math.max(0,n-2),r=e.sliceString(i,Math.min(e.length,o+2))),(t(ze(r,n-i))!=v.Word||t(_e(r,n-i))!=v.Word)&&(t(_e(r,o-i))!=v.Word||t(ze(r,o-i))!=v.Word))}var Lt=class extends $e{constructor(t){super(t)}nextMatch(t,n,o){let r=X(this.spec,t,o,t.doc.length).nextOverlapping();if(r.done){let i=Math.min(t.doc.length,n+this.spec.unquoted.length);r=X(this.spec,t,0,i).nextOverlapping()}return r.done||r.value.from==n&&r.value.to==o?null:r.value}prevMatchInRange(t,n,o){for(let r=o;;){let i=Math.max(n,r-1e4-this.spec.unquoted.length),s=X(this.spec,t,i,r),a=null;for(;!s.nextOverlapping().done;)a=s.value;if(a)return a;if(i==n)return null;r-=1e4}}prevMatch(t,n,o){let r=this.prevMatchInRange(t,0,n);return r||(r=this.prevMatchInRange(t,Math.max(0,o-this.spec.unquoted.length),t.doc.length)),r&&(r.from!=n||r.to!=o)?r:null}getReplacement(t){return this.spec.unquote(this.spec.replace)}matchAll(t,n){let o=X(this.spec,t,0,t.doc.length),r=[];for(;!o.next().done;){if(r.length>=n)return null;r.push(o.value)}return r}highlight(t,n,o,r){let i=X(this.spec,t,Math.max(0,n-this.spec.unquoted.length),Math.min(o+this.spec.unquoted.length,t.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}};function $i(e,t,n){return(o,r,i)=>(!n||n(o,r,i))&&e(i[0],t,o,r)}function Z(e,t,n,o){let r;return e.wholeWord&&(r=zi(t.charCategorizer(t.selection.main.head))),e.test&&(r=$i(e.test,t,r)),new Fe(t.doc,e.search,{ignoreCase:!e.caseSensitive,test:r},n,o)}function ze(e,t){return e.slice(V(e,t,!1),t)}function _e(e,t){return e.slice(t,V(e,t))}function zi(e){return(t,n,o)=>!o[0].length||(e(ze(o.input,o.index))!=v.Word||e(_e(o.input,o.index))!=v.Word)&&(e(_e(o.input,o.index+o[0].length))!=v.Word||e(ze(o.input,o.index+o[0].length))!=v.Word)}var vt=class extends $e{nextMatch(t,n,o){let r=Z(this.spec,t,o,t.doc.length).next();return r.done&&(r=Z(this.spec,t,0,n).next()),r.done?null:r.value}prevMatchInRange(t,n,o){for(let r=1;;r++){let i=Math.max(n,o-r*1e4),s=Z(this.spec,t,i,o),a=null;for(;!s.next().done;)a=s.value;if(a&&(i==n||a.from>i+10))return a;if(i==n)return null}}prevMatch(t,n,o){return this.prevMatchInRange(t,0,n)||this.prevMatchInRange(t,o,t.doc.length)}getReplacement(t){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(n,o)=>{if(o=="&")return t.match[0];if(o=="$")return"$";for(let r=o.length;r>0;r--){let i=+o.slice(0,r);if(i>0&&i<t.match.length)return t.match[i]+o.slice(r)}return n})}matchAll(t,n){let o=Z(this.spec,t,0,t.doc.length),r=[];for(;!o.next().done;){if(r.length>=n)return null;r.push(o.value)}return r}highlight(t,n,o,r){let i=Z(this.spec,t,Math.max(0,n-250),Math.min(o+250,t.doc.length));for(;!i.next().done;)r(i.value.from,i.value.to)}},ue=j.define(),Tt=j.define(),$=pe.define({create(e){return new he(wt(e).create(),null)},update(e,t){for(let n of t.effects)n.is(ue)?e=new he(n.value.create(),e.panel):n.is(Tt)&&(e=new he(e.query,n.value?Bt:null));return e},provide:e=>Sn.from(e,t=>t.panel)});var he=class{constructor(t,n){this.query=t,this.panel=n}},_i=S.mark({class:"cm-searchMatch"}),ji=S.mark({class:"cm-searchMatch cm-searchMatch-selected"}),qi=O.fromClass(class{constructor(e){this.view=e,this.decorations=this.highlight(e.state.field($))}update(e){let t=e.state.field($);(t!=e.startState.field($)||e.docChanged||e.selectionSet||e.viewportChanged)&&(this.decorations=this.highlight(t))}highlight({query:e,panel:t}){if(!t||!e.spec.valid)return S.none;let{view:n}=this,o=new hn;for(let r=0,i=n.visibleRanges,s=i.length;r<s;r++){let{from:a,to:l}=i[r];for(;r<s-1&&l>i[r+1].from-500;)l=i[++r].to;e.highlight(n.state,a,l,(h,m)=>{let d=n.state.selection.ranges.some(g=>g.from==h&&g.to==m);o.add(h,m,d?ji:_i)})}return o.finish()}},{decorations:e=>e.decorations});function me(e){return t=>{let n=t.state.field($,!1);return n&&n.query.spec.valid?e(t,n):Uo(t)}}var je=me((e,{query:t})=>{let{to:n}=e.state.selection.main,o=t.nextMatch(e.state,n,n);if(!o)return!1;let r=p.single(o.from,o.to),i=e.state.facet(ee);return e.dispatch({selection:r,effects:[Dt(e,o),i.scrollToMatch(r.main,e)],userEvent:"select.search"}),Oo(e),!0}),qe=me((e,{query:t})=>{let{state:n}=e,{from:o}=n.selection.main,r=t.prevMatch(n,o,o);if(!r)return!1;let i=p.single(r.from,r.to),s=e.state.facet(ee);return e.dispatch({selection:i,effects:[Dt(e,r),s.scrollToMatch(i.main,e)],userEvent:"select.search"}),Oo(e),!0}),Hi=me((e,{query:t})=>{let n=t.matchAll(e.state,1e3);return!n||!n.length?!1:(e.dispatch({selection:p.create(n.map(o=>p.range(o.from,o.to))),userEvent:"select.search.matches"}),!0)}),Yi=({state:e,dispatch:t})=>{let n=e.selection;if(n.ranges.length>1||n.main.empty)return!1;let{from:o,to:r}=n.main,i=[],s=0;for(let a=new z(e.doc,e.sliceDoc(o,r));!a.next().done;){if(i.length>1e3)return!1;a.value.from==o&&(s=i.length),i.push(p.range(a.value.from,a.value.to))}return t(e.update({selection:p.create(i,s),userEvent:"select.search.matches"})),!0},Io=me((e,{query:t})=>{let{state:n}=e,{from:o,to:r}=n.selection.main;if(n.readOnly)return!1;let i=t.nextMatch(n,o,o);if(!i)return!1;let s=i,a=[],l,h,m=[];s.from==o&&s.to==r&&(h=n.toText(t.getReplacement(s)),a.push({from:s.from,to:s.to,insert:h}),s=t.nextMatch(n,s.from,s.to),m.push(y.announce.of(n.phrase("replaced match on line $",n.doc.lineAt(o).number)+".")));let d=e.state.changes(a);return s&&(l=p.single(s.from,s.to).map(d),m.push(Dt(e,s)),m.push(n.facet(ee).scrollToMatch(l.main,e))),e.dispatch({changes:d,selection:l,effects:m,userEvent:"input.replace"}),!0}),Gi=me((e,{query:t})=>{if(e.state.readOnly)return!1;let n=t.matchAll(e.state,1e9).map(r=>{let{from:i,to:s}=r;return{from:i,to:s,insert:t.getReplacement(r)}});if(!n.length)return!1;let o=e.state.phrase("replaced $ matches",n.length)+".";return e.dispatch({changes:n,effects:y.announce.of(o),userEvent:"input.replace.all"}),!0});function Bt(e){return e.state.facet(ee).createPanel(e)}function wt(e,t){var n,o,r,i,s;let a=e.selection.main,l=a.empty||a.to>a.from+100?"":e.sliceDoc(a.from,a.to);if(t&&!l)return t;let h=e.facet(ee);return new We({search:((n=t?.literal)!==null&&n!==void 0?n:h.literal)?l:l.replace(/\n/g,"\\n"),caseSensitive:(o=t?.caseSensitive)!==null&&o!==void 0?o:h.caseSensitive,literal:(r=t?.literal)!==null&&r!==void 0?r:h.literal,regexp:(i=t?.regexp)!==null&&i!==void 0?i:h.regexp,wholeWord:(s=t?.wholeWord)!==null&&s!==void 0?s:h.wholeWord})}function Fo(e){let t=ut(e,Bt);return t&&t.dom.querySelector("[main-field]")}function Oo(e){let t=Fo(e);t&&t==e.root.activeElement&&t.select()}var Uo=e=>{let t=e.state.field($,!1);if(t&&t.panel){let n=Fo(e);if(n&&n!=e.root.activeElement){let o=wt(e.state,t.query.spec);o.valid&&e.dispatch({effects:ue.of(o)}),n.focus(),n.select()}}else e.dispatch({effects:[Tt.of(!0),t?ue.of(wt(e.state,t.query.spec)):j.appendConfig.of(Ki)]});return!0},No=e=>{let t=e.state.field($,!1);if(!t||!t.panel)return!1;let n=ut(e,Bt);return n&&n.dom.contains(e.root.activeElement)&&e.focus(),e.dispatch({effects:Tt.of(!1)}),!0},Wo=[{key:"Mod-f",run:Uo,scope:"editor search-panel"},{key:"F3",run:je,shift:qe,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:je,shift:qe,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:No,scope:"editor search-panel"},{key:"Mod-Shift-l",run:Yi},{key:"Mod-Alt-g",run:Bi},{key:"Mod-d",run:Ui,preventDefault:!0}],Mt=class{constructor(t){this.view=t;let n=this.query=t.state.field($).query.spec;this.commit=this.commit.bind(this),this.searchField=w("input",{value:n.search,placeholder:M(t,"Find"),"aria-label":M(t,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=w("input",{value:n.replace,placeholder:M(t,"Replace"),"aria-label":M(t,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=w("input",{type:"checkbox",name:"case",form:"",checked:n.caseSensitive,onchange:this.commit}),this.reField=w("input",{type:"checkbox",name:"re",form:"",checked:n.regexp,onchange:this.commit}),this.wordField=w("input",{type:"checkbox",name:"word",form:"",checked:n.wholeWord,onchange:this.commit});function o(r,i,s){return w("button",{class:"cm-button",name:r,onclick:i,type:"button"},s)}this.dom=w("div",{onkeydown:r=>this.keydown(r),class:"cm-search"},[this.searchField,o("next",()=>je(t),[M(t,"next")]),o("prev",()=>qe(t),[M(t,"previous")]),o("select",()=>Hi(t),[M(t,"all")]),w("label",null,[this.caseField,M(t,"match case")]),w("label",null,[this.reField,M(t,"regexp")]),w("label",null,[this.wordField,M(t,"by word")]),...t.state.readOnly?[]:[w("br"),this.replaceField,o("replace",()=>Io(t),[M(t,"replace")]),o("replaceAll",()=>Gi(t),[M(t,"replace all")])],w("button",{name:"close",onclick:()=>No(t),"aria-label":M(t,"close"),type:"button"},["\xD7"])])}commit(){let t=new We({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});t.eq(this.query)||(this.query=t,this.view.dispatch({effects:ue.of(t)}))}keydown(t){fn(this.view,t,"search-panel")?t.preventDefault():t.keyCode==13&&t.target==this.searchField?(t.preventDefault(),(t.shiftKey?qe:je)(this.view)):t.keyCode==13&&t.target==this.replaceField&&(t.preventDefault(),Io(this.view))}update(t){for(let n of t.transactions)for(let o of n.effects)o.is(ue)&&!o.value.eq(this.query)&&this.setQuery(o.value)}setQuery(t){this.query=t,this.searchField.value=t.search,this.replaceField.value=t.replace,this.caseField.checked=t.caseSensitive,this.reField.checked=t.regexp,this.wordField.checked=t.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(ee).top}};function M(e,t){return e.state.phrase(t)}var Pe=30,Ve=/[\s\.,:;?!]/;function Dt(e,{from:t,to:n}){let o=e.state.doc.lineAt(t),r=e.state.doc.lineAt(n).to,i=Math.max(o.from,t-Pe),s=Math.min(r,n+Pe),a=e.state.sliceDoc(i,s);if(i!=o.from){for(let l=0;l<Pe;l++)if(!Ve.test(a[l+1])&&Ve.test(a[l])){a=a.slice(l);break}}if(s!=r){for(let l=a.length-1;l>a.length-Pe;l--)if(!Ve.test(a[l-1])&&Ve.test(a[l])){a=a.slice(0,l);break}}return y.announce.of(`${e.state.phrase("current match")}. ${a} ${e.state.phrase("on line")} ${o.number}.`)}var Ji=y.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),Ki=[$,ge.low(qi),Ji];var Qi="#e5c07b",$o="#e06c75",Xi="#56b6c2",Zi="#ffffff",He="#abb2bf",It="#7d8799",es="#61afef",ts="#98c379",zo="#d19a66",ns="#c678dd",os="#21252b",_o="#2c313a",jo="#282c34",Et="#353a42",rs="#3E4451",qo="#528bff";var is=y.theme({"&":{color:He,backgroundColor:jo},".cm-content":{caretColor:qo},".cm-cursor, .cm-dropCursor":{borderLeftColor:qo},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:rs},".cm-panels":{backgroundColor:os,color:He},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:jo,color:It,border:"none"},".cm-activeLineGutter":{backgroundColor:_o},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Et},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Et,borderBottomColor:Et},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:_o,color:He}}},{dark:!0}),ss=Tn.define([{tag:f.keyword,color:ns},{tag:[f.name,f.deleted,f.character,f.propertyName,f.macroName],color:$o},{tag:[f.function(f.variableName),f.labelName],color:es},{tag:[f.color,f.constant(f.name),f.standard(f.name)],color:zo},{tag:[f.definition(f.name),f.separator],color:He},{tag:[f.typeName,f.className,f.number,f.changed,f.annotation,f.modifier,f.self,f.namespace],color:Qi},{tag:[f.operator,f.operatorKeyword,f.url,f.escape,f.regexp,f.link,f.special(f.string)],color:Xi},{tag:[f.meta,f.comment],color:It},{tag:f.strong,fontWeight:"bold"},{tag:f.emphasis,fontStyle:"italic"},{tag:f.strikethrough,textDecoration:"line-through"},{tag:f.link,color:It,textDecoration:"underline"},{tag:f.heading,fontWeight:"bold",color:$o},{tag:[f.atom,f.bool,f.special(f.variableName)],color:zo},{tag:[f.processingInstruction,f.string,f.inserted],color:ts},{tag:f.invalid,color:Zi}]),Rt=[is,ve(ss)];var Ye=class e{constructor(t,n){this.yanchor=t,this.yhead=n}toJSON(){return{yanchor:G(this.yanchor),yhead:G(this.yhead)}}static fromJSON(t){return new e(I(t.yanchor),I(t.yhead))}};var Ge=class{constructor(t,n){this.ytext=t,this.awareness=n,this.undoManager=new J(t)}toYPos(t,n=0){return U(this.ytext,t,n)}fromYPos(t){let n=R(I(t),this.ytext.doc);if(n==null||n.type!==this.ytext)throw new Error("[y-codemirror] The position you want to retrieve was created by a different document");return{pos:n.index,assoc:n.assoc}}toYRange(t){let n=t.assoc,o=this.toYPos(t.anchor,n),r=this.toYPos(t.head,n);return new Ye(o,r)}fromYRange(t){let n=this.fromYPos(t.yanchor),o=this.fromYPos(t.yhead);return n.pos===o.pos?p.cursor(o.pos,o.assoc):p.range(n.pos,o.pos)}},Y=P.define({combine(e){return e[e.length-1]}}),Je=F.define(),Pt=class{constructor(t){this.view=t,this.conf=t.state.facet(Y),this._observer=(n,o)=>{if(o.origin!==this.conf){let r=n.delta,i=[],s=0;for(let a=0;a<r.length;a++){let l=r[a];l.insert!=null?i.push({from:s,to:s,insert:l.insert}):l.delete!=null?(i.push({from:s,to:s+l.delete,insert:""}),s+=l.delete):s+=l.retain}t.dispatch({changes:i,annotations:[Je.of(this.conf)]})}},this._ytext=this.conf.ytext,this._ytext.observe(this._observer)}update(t){if(!t.docChanged||t.transactions.length>0&&t.transactions[0].annotation(Je)===this.conf)return;let n=this.conf.ytext;n.doc.transact(()=>{let o=0;t.changes.iterChanges((r,i,s,a,l)=>{let h=l.sliceString(0,l.length,`
3
- `);r!==i&&n.delete(r+o,i-r),h.length>0&&n.insert(r+o,h),o+=h.length-(i-r)})},this.conf)}destroy(){this._ytext.unobserve(this._observer)}},Yo=O.fromClass(Pt);var Go=y.baseTheme({".cm-ySelection":{},".cm-yLineSelection":{padding:0,margin:"0px 2px 0px 4px"},".cm-ySelectionCaret":{position:"relative",borderLeft:"1px solid black",borderRight:"1px solid black",marginLeft:"-1px",marginRight:"-1px",boxSizing:"border-box",display:"inline"},".cm-ySelectionCaretDot":{borderRadius:"50%",position:"absolute",width:".4em",height:".4em",top:"-.2em",left:"-.2em",backgroundColor:"inherit",transition:"transform .3s ease-in-out",boxSizing:"border-box"},".cm-ySelectionCaret:hover > .cm-ySelectionCaretDot":{transformOrigin:"bottom center",transform:"scale(0)"},".cm-ySelectionInfo":{position:"absolute",top:"-1.05em",left:"-1px",fontSize:".75em",fontFamily:"serif",fontStyle:"normal",fontWeight:"normal",lineHeight:"normal",userSelect:"none",color:"white",paddingLeft:"2px",paddingRight:"2px",zIndex:101,transition:"opacity .3s ease-in-out",backgroundColor:"inherit",opacity:0,transitionDelay:"0s",whiteSpace:"nowrap"},".cm-ySelectionCaret:hover > .cm-ySelectionInfo":{opacity:1,transitionDelay:"0s"}}),as=F.define(),Ft=class extends un{constructor(t,n){super(),this.color=t,this.name=n}toDOM(){return fe("span",[te("class","cm-ySelectionCaret"),te("style",`background-color: ${this.color}; border-color: ${this.color}`)],[ne("\u2060"),fe("div",[te("class","cm-ySelectionCaretDot")]),ne("\u2060"),fe("div",[te("class","cm-ySelectionInfo")],[ne(this.name)]),ne("\u2060")])}eq(t){return t.color===this.color}compare(t){return t.color===this.color}updateDOM(){return!1}get estimatedHeight(){return-1}ignoreEvent(){return!0}},Ot=class{constructor(t){this.conf=t.state.facet(Y),this._listener=({added:n,updated:o,removed:r},i,s)=>{n.concat(o).concat(r).findIndex(l=>l!==this.conf.awareness.doc.clientID)>=0&&t.dispatch({annotations:[as.of([])]})},this._awareness=this.conf.awareness,this._awareness.on("change",this._listener),this.decorations=cn.of([])}destroy(){this._awareness.off("change",this._listener)}update(t){let n=this.conf.ytext,o=n.doc,r=this.conf.awareness,i=[],s=this.conf.awareness.getLocalState();if(s!=null){let a=t.view.hasFocus&&t.view.dom.ownerDocument.hasFocus(),l=a?t.state.selection.main:null,h=s.cursor==null?null:I(s.cursor.anchor),m=s.cursor==null?null:I(s.cursor.head);if(l!=null){let d=U(n,l.anchor),g=U(n,l.head);(s.cursor==null||!st(h,d)||!st(m,g))&&r.setLocalStateField("cursor",{anchor:d,head:g})}else s.cursor!=null&&a&&r.setLocalStateField("cursor",null)}r.getStates().forEach((a,l)=>{if(l===r.doc.clientID)return;let h=a.cursor;if(h==null||h.anchor==null||h.head==null)return;let m=R(h.anchor,o),d=R(h.head,o);if(m==null||d==null||m.type!==n||d.type!==n)return;let{color:g="#30bced",name:C="Anonymous"}=a.user||{},x=a.user&&a.user.colorLight||g+"33",k=Gt(m.index,d.index),b=Jt(m.index,d.index),_=t.view.state.doc.lineAt(k),rt=t.view.state.doc.lineAt(b);if(_.number===rt.number)i.push({from:k,to:b,value:S.mark({attributes:{style:`background-color: ${x}`},class:"cm-ySelection"})});else{i.push({from:k,to:_.from+_.length,value:S.mark({attributes:{style:`background-color: ${x}`},class:"cm-ySelection"})}),i.push({from:rt.from,to:b,value:S.mark({attributes:{style:`background-color: ${x}`},class:"cm-ySelection"})});for(let it=_.number+1;it<rt.number;it++){let jt=t.view.state.doc.line(it).from;i.push({from:jt,to:jt,value:S.line({attributes:{style:`background-color: ${x}`,class:"cm-yLineSelection"}})})}}i.push({from:d.index,to:d.index,value:S.widget({side:d.index-m.index>0?-1:1,block:!1,widget:new Ft(g,C)})})}),this.decorations=S.set(i,!0)}},Jo=O.fromClass(Ot,{decorations:e=>e.decorations});var Ko=()=>{let e=!0;return(t,n)=>{if(e){e=!1;try{t()}finally{e=!0}}else n!==void 0&&n()}};var Ke=class{constructor(t){this.undoManager=t}addTrackedOrigin(t){this.undoManager.addTrackedOrigin(t)}removeTrackedOrigin(t){this.undoManager.removeTrackedOrigin(t)}undo(){return this.undoManager.undo()!=null}redo(){return this.undoManager.redo()!=null}},de=P.define({combine(e){return e[e.length-1]}}),ga=F.define(),Ut=class{constructor(t){this.view=t,this.conf=t.state.facet(de),this._undoManager=this.conf.undoManager,this.syncConf=t.state.facet(Y),this._beforeChangeSelection=null,this._mux=Ko(),this._onStackItemAdded=({stackItem:n,changedParentTypes:o})=>{o.has(this.syncConf.ytext)&&this._beforeChangeSelection&&!n.meta.has(this)&&n.meta.set(this,this._beforeChangeSelection)},this._onStackItemPopped=({stackItem:n})=>{let o=n.meta.get(this);if(o){let r=this.syncConf.fromYRange(o);t.dispatch(t.state.update({selection:r,effects:[y.scrollIntoView(r)]})),this._storeSelection()}},this._storeSelection=()=>{this._beforeChangeSelection=this.syncConf.toYRange(this.view.state.selection.main)},this._undoManager.on("stack-item-added",this._onStackItemAdded),this._undoManager.on("stack-item-popped",this._onStackItemPopped),this._undoManager.addTrackedOrigin(this.syncConf)}update(t){t.selectionSet&&(t.transactions.length===0||t.transactions[0].annotation(Je)!==this.syncConf)&&this._storeSelection()}destroy(){this._undoManager.off("stack-item-added",this._onStackItemAdded),this._undoManager.off("stack-item-popped",this._onStackItemPopped),this._undoManager.removeTrackedOrigin(this.syncConf)}},Qo=O.fromClass(Ut),Xo=({state:e,dispatch:t})=>e.facet(de).undo()||!0,Zo=({state:e,dispatch:t})=>e.facet(de).redo()||!0;var er=(e,t,{undoManager:n=new J(e)}={})=>{let o=new Ge(e,t),r=[Y.of(o),Yo];return t&&r.push(Go,Jo),n!==!1&&r.push(de.of(new Ke(n)),Qo,y.domEventHandlers({beforeinput(i,s){return i.inputType==="historyUndo"?Xo(s):i.inputType==="historyRedo"?Zo(s):!1}})),r};var Qe=Object.freeze({bold:"bold text",code:"code",italic:"emphasis",strikethrough:"struck text"}),Xe="link text",Nt="https://",Ze="alt text",Wt="https://",et="Video",$t="https://",tr="code",or=Object.freeze(["Column 1","Column 2"]),nr="Value";function ls(e,t){let n=Math.max(0,Math.min(e.from,e.to,t)),o=Math.max(0,Math.min(Math.max(e.from,e.to),t));return{from:n,to:o}}function cs(e,t){return t===0||e[t-1]===`
4
- `}function hs(e,t){if(t<=0)return 0;let n=e.lastIndexOf(`
5
- `,t-1);return n<0?0:n+1}function us(e,t){let n=e.indexOf(`
6
- `,t);return n<0?e.length:n}function rr(e,t){let{from:n}=t,{to:o}=t;return o>n&&cs(e,o)&&(o-=1),{from:hs(e,n),to:us(e,Math.max(n,o))}}function tt(e,t,n,o){let r=e.slice(t.from,t.to);return r.length>0?{anchor:t.from+n.length,from:t.from,head:t.from+n.length+r.length,insert:`${n}${r}${n}`,to:t.to}:{anchor:t.from+n.length,from:t.from,head:t.from+n.length+o.length,insert:`${n}${o}${n}`,to:t.to}}function zt(e){return/^https?:\/\//i.test(e.trim())}function ms(e,t){let n=e.slice(t.from,t.to);if(n.length>0&&zt(n))return{anchor:t.from+1,from:t.from,head:t.from+1+Xe.length,insert:`[${Xe}](${n})`,to:t.to};if(n.length>0){let o=`[${n}](`;return{anchor:t.from+o.length,from:t.from,head:t.from+o.length+Nt.length,insert:`${o}${Nt})`,to:t.to}}return{anchor:t.from+1,from:t.from,head:t.from+1+Xe.length,insert:`[${Xe}](${Nt})`,to:t.to}}function ds(e,t){let n=e.slice(t.from,t.to);if(n.length>0&&zt(n))return{anchor:t.from+2,from:t.from,head:t.from+2+Ze.length,insert:`![${Ze}](${n})`,to:t.to};if(n.length>0){let o=`![${n}](`;return{anchor:t.from+o.length,from:t.from,head:t.from+o.length+Wt.length,insert:`${o}${Wt})`,to:t.to}}return{anchor:t.from+2,from:t.from,head:t.from+2+Ze.length,insert:`![${Ze}](${Wt})`,to:t.to}}function fs(e,t){let n=e.slice(t.from,t.to);if(n.length>0&&zt(n))return{anchor:t.from+2,from:t.from,head:t.from+2+et.length,insert:`![${et}](${n})`,to:t.to};if(n.length>0){let o=`![${n}](`;return{anchor:t.from+o.length,from:t.from,head:t.from+o.length+$t.length,insert:`${o}${$t})`,to:t.to}}return{anchor:t.from+2,from:t.from,head:t.from+2+et.length,insert:`![${et}](${$t})`,to:t.to}}function nt(e,t,n,o){let r=rr(e,t),s=e.slice(r.from,r.to).split(`
7
- `),a=d=>o.test(d),l=s.every(d=>d.trim().length===0||a(d)),h=0,m=s.map(d=>{if(d.trim().length===0)return d;if(l)return a(d)?d.replace(o,""):d;let g=n(h);return h+=1,`${g}${d}`});return{anchor:r.from,from:r.from,head:r.from+m.join(`
8
- `).length,insert:m.join(`
9
- `),to:r.to}}function ps(e,t){return nt(e,t,()=>"## ",/^#{1,6}\s+/)}function gs(e,t){return nt(e,t,()=>"- ",/^[-*+]\s+/)}function xs(e,t){return nt(e,t,()=>"> ",/^>\s+/)}function ys(e,t){return nt(e,t,()=>"- [ ] ",/^-\s\[(?: |x|X)\]\s+/)}function Cs(e,t){let n=rr(e,t),r=e.slice(n.from,n.to).split(`
10
- `),i=r.every(l=>l.trim().length===0||/^\d+\.\s+/.test(l)),s=1,a=r.map(l=>{if(l.trim().length===0)return l;if(i)return l.replace(/^\d+\.\s+/,"");let h=`${s}. ${l}`;return s+=1,h});return{anchor:n.from,from:n.from,head:n.from+a.join(`
11
- `).length,insert:a.join(`
12
- `),to:n.to}}function Ss(e){let n=e.replace(/\r\n/g,`
13
- `).match(/^```[^\n]*\n([\s\S]*?)\n```$/);return n?n[1]:null}function ks(e,t){let n=e.slice(t.from,t.to);if(n.length>0){let o=Ss(n);return o!==null?{anchor:t.from,from:t.from,head:t.from+o.length,insert:o,to:t.to}:{anchor:t.from+4,from:t.from,head:t.from+4+n.length,insert:`\`\`\`
14
- ${n}
15
- \`\`\``,to:t.to}}return{anchor:t.from+4,from:t.from,head:t.from+4+tr.length,insert:`\`\`\`
16
- ${tr}
17
- \`\`\``,to:t.to}}function ir(e,t,n,o,r=0){let i=t.from>0&&e[t.from-1]!==`
18
- `,s=t.to<e.length&&e[t.to]!==`
19
- `,a=i?`
20
- `:"",h=`${a}${n}${s?`
21
- `:""}`,m=t.from+a.length+o;return{anchor:m,from:t.from,head:m+r,insert:h,to:t.to}}function bs(e=""){let t=e.trim()||nr;return[`| ${or.join(" | ")} |`,"| --- | --- |",`| ${t} | ${nr} |`].join(`
22
- `)}function Ls(e,t){let n=e.slice(t.from,t.to),o=bs(n);return ir(e,t,o,2,or[0].length)}function vs(e,t){return ir(e,t,"---",4,0)}function sr(e,t,n){let o=String(e??""),r=ls(t,o.length);switch(n){case"bold":return tt(o,r,"**",Qe.bold);case"italic":return tt(o,r,"_",Qe.italic);case"strikethrough":return tt(o,r,"~~",Qe.strikethrough);case"code":return tt(o,r,"`",Qe.code);case"link":return ms(o,r);case"image":return ds(o,r);case"video":return fs(o,r);case"heading":return ps(o,r);case"quote":return xs(o,r);case"bullet-list":return gs(o,r);case"numbered-list":return Cs(o,r);case"task-list":return ys(o,r);case"code-block":return ks(o,r);case"table":return Ls(o,r);case"horizontal-rule":return vs(o,r);default:return null}}function ar(e){return t=>{let n=t.state.doc.lineAt(t.pos),o=n.text.slice(0,t.pos-n.from),r=o.lastIndexOf("[[");if(r===-1)return null;let i=o.slice(r+2);if(i.includes("]]"))return null;let s=i.toLowerCase(),a=n.from+r+2,h=e().map(m=>{let d=m.replace(/\.md$/i,""),g=d.split("/").pop();return{filePath:m,label:d,fileName:g}}).filter(({label:m,fileName:d})=>m.toLowerCase().includes(s)||d.toLowerCase().includes(s)).map(({label:m,fileName:d})=>({label:m,detail:m.includes("/")?` ${d}`:void 0,apply:(g,C,x,k)=>{let b=g.state.doc.toString(),_=k;b.slice(k,k+2)==="]]"&&(_=k+2),g.dispatch({changes:{from:x,to:_,insert:`${C.label}]]`},selection:{anchor:x+C.label.length+2}})},type:"text",boost:m.toLowerCase().startsWith(s)?1:0}));return h.length===0?null:{from:a,options:h,filter:!1}}}var ws=new Set(["@startuml","@enduml","@startmindmap","@endmindmap","@startwbs","@endwbs","@startgantt","@endgantt","@startjson","@endjson","@startyaml","@endyaml","@startsalt","@endsalt"]),Ms=new Set(["activate","actor","agent","allowmixing","alt","annotation","artifact","as","autonumber","boundary","box","break","caption","card","case","circle","class","cloud","collections","component","control","create","critical","database","deactivate","destroy","detach","else","elseif","end","endlegend","endif","endwhile","entity","enum","exception","file","folder","footer","fork","frame","group","header","hide","hnote","if","interface","json","kill","label","legend","loop","map","namespace","newpage","node","note","object","of","opt","order","over","package","page","par","participant","partition","person","port","protocol","queue","rectangle","ref","repeat","return","rnote","show","skinparam","split","stack","start","state","stop","storage","struct","switch","then","title","usecase","while"]),As=new Set(["false","no","off","on","true","yes"]);function Ts(e){let t=e.match(/[@!A-Za-z_][\w.-]*/u,!1);return t?(e.match(/[@!A-Za-z_][\w.-]*/u),t[0]):""}var Bs=we.define({languageData:{commentTokens:{block:{close:"'/",open:"/'"},line:"'"}},startState(){return{inBlockComment:!1}},token(e,t){if(t.inBlockComment)return e.skipTo("'/")?(e.match("'/"),t.inBlockComment=!1):e.skipToEnd(),"comment";if(e.eatSpace())return null;if(e.match("/'"))return t.inBlockComment=!0,"comment";let n=e.pos===0?" ":e.string.charAt(e.pos-1);if(e.peek()==="'"&&(e.sol()||/\s/u.test(n)))return e.skipToEnd(),"comment";if(e.match(/"(?:[^"\\]|\\.)*"?/u))return"string";if(e.match(/#[0-9a-f]{3,8}\b/iu)||e.match(/#[A-Za-z][\w-]*/u))return"atom";if(e.match(/\b\d+(?:\.\d+)?\b/u))return"number";if(e.match(/[<>{}[\]():,]/u))return"punctuation";if(e.match(/[ox*+<#]?[-=.\\/]+(?:left|right|up|down)?[-=.\\/]*[ox*+>#]?/iu))return"operator";let o=Ts(e);if(o){let r=o.toLowerCase();return r.startsWith("!")||ws.has(r)?"meta":Ms.has(r)?"keyword":As.has(r)?"bool":/^[A-Z][A-Z0-9_]*$/u.test(o)?"typeName":"variableName"}return e.next(),null}}),_t=new be(Bs),lr=c.of({alias:["plantuml","puml"],extensions:["plantuml","puml"],name:"PlantUML",support:_t});function Ds(e){let t=Array.from(e?.clipboardData?.files??[]);for(let o of t)if(o?.type?.startsWith?.("image/"))return o;let n=Array.from(e?.clipboardData?.items??[]);for(let o of n){if(o.kind!=="file"||!o.type?.startsWith?.("image/"))continue;let r=o.getAsFile?.();if(r)return r}return null}function cr(e,t){let n=Ds(e);return n?typeof t!="function"?(console.warn("[editor] Ignoring pasted image because no image paste handler is registered."),!1):(console.debug("[editor] Detected pasted image.",{name:n.name??"",size:n.size??null,type:n.type??""}),e.preventDefault?.(),Promise.resolve(t(n)).catch(o=>{console.error("[editor] Failed to process pasted image:",o)}),!0):!1}var Es=[...Bo,lr],hr=S.mark({class:"cm-matchingBracket cm-matchingBracket-paired"}),ur=S.mark({class:"cm-nonmatchingBracket"});function mr(e,t){return t.selection.ranges.some(n=>n.empty&&e.to===n.head)}function Is(e,t){let n=[];if(!e.matched)return n.push(ur.range(e.start.from,e.start.to)),e.end&&n.push(ur.range(e.end.from,e.end.to)),n;let o=mr(e.start,t),r=e.end?mr(e.end,t):!1;return o||n.push(hr.range(e.start.from,e.start.to)),e.end&&!r&&n.push(hr.range(e.end.from,e.end.to)),n}function dr(e){let t=e==="dark"?"oklch(from var(--color-surface-offset) l c h / 0.55)":"oklch(from var(--color-surface-offset) l c h / 0.75)",n=e==="dark"?"oklch(from var(--color-primary) l c h / 0.28)":"oklch(from var(--color-primary) l c h / 0.18)",o=e==="dark"?"oklch(from var(--color-primary) l c h / 0.4)":"oklch(from var(--color-primary) l c h / 0.26)",r=e==="dark"?"oklch(from var(--color-primary) l c h / 0.65)":"oklch(from var(--color-primary) l c h / 0.5)",i=e==="dark"?"color-mix(in oklab, var(--color-primary) 78%, white)":"color-mix(in oklab, var(--color-primary) 84%, black)",s=e==="dark"?"oklch(from var(--color-primary) l c h / 0.2)":"oklch(from var(--color-primary) l c h / 0.12)",a=e==="dark"?"oklch(from var(--color-primary) calc(l + 0.08) c h / 0.85)":"oklch(from var(--color-primary) calc(l - 0.04) c h / 0.7)",l=e==="dark"?"oklch(from var(--color-error) l c h / 0.12)":"oklch(from var(--color-error) l c h / 0.1)",h=e==="dark"?"oklch(from var(--color-error) calc(l + 0.08) c h / 0.8)":"oklch(from var(--color-error) calc(l - 0.04) c h / 0.7)";return y.theme({"&":{backgroundColor:"var(--color-bg)",color:"var(--color-text)"},".cm-content":{caretColor:i,fontFamily:"var(--font-mono)",padding:"16px 0"},".cm-cursor, .cm-dropCursor":{borderLeftColor:i,borderLeftWidth:"3px",marginLeft:"-1px"},".cm-foldPlaceholder":{backgroundColor:"var(--color-surface-dynamic)",border:"none",color:"var(--color-text-muted)"},".cm-gutters":{backgroundColor:"var(--color-surface)",borderRight:"1px solid var(--color-divider)",color:"var(--color-text-muted)",minWidth:"44px"},".cm-line":{padding:"0 16px"},".cm-activeLine":{backgroundColor:t,boxShadow:`inset 3px 0 0 ${n}`},".cm-activeLineGutter":{backgroundColor:t,boxShadow:`inset 3px 0 0 ${n}`,color:"var(--color-text-muted)"},".cm-matchingBracket":{borderRadius:"2px",color:"inherit"},".cm-matchingBracket.cm-matchingBracket-paired":{backgroundColor:s,outline:`1px solid ${a}`},".cm-nonmatchingBracket":{backgroundColor:l,outline:`1px solid ${h}`,borderRadius:"2px"},".cm-selectionMatch":{backgroundColor:"var(--color-primary-highlight)"},"&.cm-focused .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:o},"&.cm-focused .cm-selectionLayer .cm-selectionBackground":{border:`1px solid ${r}`,borderRadius:"2px"}},{dark:e==="dark"})}function Rs(e){return typeof e=="string"&&(e.toLowerCase().endsWith(".puml")||e.toLowerCase().endsWith(".plantuml"))?_t:Vn({base:Pn,codeLanguages:Es})}function fr(e){return{from:Math.min(...e.ranges.map(t=>Math.min(t.from,t.to))),to:Math.max(...e.ranges.map(t=>Math.max(t.from,t.to)))}}var ot=class{constructor({editorContainer:t,getFileList:n,initialTheme:o,lineInfoElement:r,lineWrappingEnabled:i=!0,onDocChanged:s=null,onImagePaste:a=null,onSelectionChanged:l=null,onViewportChanged:h=null}){this.editorContainer=t,this.getFileList=n??(()=>[]),this.initialTheme=o,this.lineInfoElement=r,this.lineWrappingEnabled=i,this.onDocChanged=s,this.onImagePaste=a,this.onSelectionChanged=l,this.onViewportChanged=h,this.editorView=null,this.themeCompartment=new xe,this.syntaxThemeCompartment=new xe,this.lineWrappingCompartment=new xe,this.viewportFrame=0,this.handleScroll=()=>{this.viewportFrame||(this.viewportFrame=requestAnimationFrame(()=>{this.viewportFrame=0,this.emitViewportChange()}))}}initialize({awareness:t,filePath:n,undoManager:o,ytext:r}){let i=y.updateListener.of(a=>{a.docChanged&&this.onDocChanged?.(),(a.selectionSet||a.docChanged)&&(this.updateCursorInfo(a.state),this.onSelectionChanged?.(a.state))}),s=this.editorContainer.querySelector("#editorLoading");Array.from(this.editorContainer.children).forEach(a=>{a!==s&&a.remove()}),this.editorView=new y({parent:this.editorContainer,state:ie.create({doc:r.toString(),extensions:[bn(),Ln(),gn(),Gn(),An(),pn(),ie.allowMultipleSelections.of(!0),wn(),ve(Bn,{fallback:!0}),Dn({renderMatch:Is}),En(),Rn({override:[ar(this.getFileList)]}),yn(),Cn(),xn(),Vo(),dn.of([...In,...Ao,...Xn,...Wo,...Mn,To]),y.contentAttributes.of({"aria-label":"Markdown editor"}),ge.highest(y.domEventHandlers({paste:a=>cr(a,this.onImagePaste)})),Rs(n),this.themeCompartment.of(dr(this.initialTheme)),this.syntaxThemeCompartment.of(this.initialTheme==="dark"?Rt:[]),this.lineWrappingCompartment.of(this.lineWrappingEnabled?y.lineWrapping:[]),er(r,t,{undoManager:o}),i]})}),this.editorView.scrollDOM.addEventListener("scroll",this.handleScroll,{passive:!0}),this.updateCursorInfo(this.editorView.state),this.onSelectionChanged?.(this.editorView.state),this.emitViewportChange()}destroy(){this.viewportFrame&&(cancelAnimationFrame(this.viewportFrame),this.viewportFrame=0),this.editorView?.scrollDOM?.removeEventListener("scroll",this.handleScroll),this.editorView?.destroy(),this.editorView=null,this.editorContainer&&(this.editorContainer.innerHTML="")}getText(){return this.editorView?.state.doc.toString()??""}getDoc(){return this.editorView?.state.doc??null}getState(){return this.editorView?.state??null}getScrollContainer(){return this.editorView?.scrollDOM??null}applyTheme(t){this.editorView&&this.editorView.dispatch({effects:[this.themeCompartment.reconfigure(dr(t)),this.syntaxThemeCompartment.reconfigure(t==="dark"?Rt:[])]})}isLineWrappingEnabled(){return this.lineWrappingEnabled}setLineWrapping(t){return this.lineWrappingEnabled=!!t,this.editorView?(this.editorView.dispatch({effects:this.lineWrappingCompartment.reconfigure(this.lineWrappingEnabled?y.lineWrapping:[])}),this.lineWrappingEnabled):this.lineWrappingEnabled}requestMeasure(){this.editorView?.requestMeasure()}getViewportState(t=.35){return{topLine:this.getTopVisibleLineNumber(t),viewportRatio:t}}getTopVisibleLineNumber(t=0){if(!this.editorView)return 1;let n=this.editorView.scrollDOM.getBoundingClientRect(),o=Math.max(n.height*t,8),r=this.editorView.lineBlockAtHeight(n.top+o-this.editorView.documentTop);return r?this.editorView.state.doc.lineAt(r.from).number:1}getCurrentSelectionLineRange(){let t=this.editorView?.state;if(!t)return null;let{doc:n,selection:o}=t,{from:r,to:i}=fr(o),s=n.lineAt(r).number,a=Math.min(Math.max(i,r),n.length);return a>r&&n.lineAt(a).from===a&&(a-=1),{endLine:n.lineAt(a).number,startLine:s}}getCurrentSelectionCommentAnchor(){let t=this.editorView?.state;if(!t)return null;let{doc:n,selection:o}=t,{from:r,to:i}=fr(o);if(r===i){let l=n.lineAt(r);return{anchorKind:"line",anchorQuote:re(l.text),endIndex:l.to,endLine:l.number,startIndex:l.from,startLine:l.number}}let a=Math.min(Math.max(i,r),n.length);return a>r&&n.lineAt(a).from===a&&(a-=1),{anchorKind:"text",anchorQuote:re(n.sliceString(r,i)),endIndex:i,endLine:n.lineAt(a).number,startIndex:r,startLine:n.lineAt(r).number}}normalizeLineRange({endLine:t,startLine:n}){let o=this.editorView?.state;if(!o)return{endLine:1,startLine:1};let r=o.doc.lines,i=Math.min(Math.max(Math.round(n??1),1),r);return{endLine:Math.min(Math.max(Math.round(t??i),i),r),startLine:i}}getLineInfoAt(t){let n=this.editorView?.state;if(!n)return null;let o=Math.min(Math.max(t,0),n.doc.length),r=n.doc.lineAt(o);return{line:r,lineNumber:r.number}}getAnchorClientRect(t){let n=this.editorView?.state,o=this.editorView;if(!n||!o||!t)return null;let r=t.anchorKind||t.kind||"line",i=Math.min(Math.max(Math.round(t.startIndex??0),0),n.doc.length),s=Math.min(Math.max(Math.round(t.endIndex??i),i),n.doc.length);if(r==="text"&&s>i){let k=o.coordsAtPos(i),b=o.coordsAtPos(Math.max(s-1,i));if(k&&b)return{bottom:Math.max(k.bottom,b.bottom),height:Math.max(k.bottom,b.bottom)-Math.min(k.top,b.top),left:Math.min(k.left,b.left),right:Math.max(k.right,b.right),top:Math.min(k.top,b.top),width:Math.max(k.right,b.right)-Math.min(k.left,b.left)}}let a=n.doc.line(Math.min(Math.max(Math.round(t.startLine??1),1),n.doc.lines)),l=o.lineBlockAt(a.from),h=o.scrollDOM.getBoundingClientRect(),m=o.scrollDOM.scrollTop,d=o.contentDOM.getBoundingClientRect(),g=d.left,C=Math.max(d.right,h.right-8),x=h.top+l.top-m;return{bottom:x+l.height,height:l.height,left:g,right:C,top:x,width:Math.max(C-g,0)}}getSelectionChipClientRect(t){let n=this.editorView?.state,o=this.editorView;if(!n||!o||!t)return null;let r=Math.min(Math.max(Math.round(t.startIndex??0),0),n.doc.length),i=n.doc.lineAt(r),s=o.lineBlockAt(i.from),a=o.scrollDOM.getBoundingClientRect(),l=o.scrollDOM.scrollTop,h=o.contentDOM.getBoundingClientRect(),m=Math.max(h.right,a.right-8),d=a.top+s.top-l;return{bottom:d+s.height,height:s.height,left:h.left,right:m,top:d,width:Math.max(m-h.left,0)}}scrollToLine(t,n=0){let o=this.editorView?.state,r=this.editorView?.scrollDOM;if(!o||!r||!this.editorView)return!1;let i=Math.min(Math.max(Math.round(t),1),o.doc.lines),s=o.doc.line(i),a=this.editorView.lineBlockAt(s.from),l=Math.max(r.scrollHeight-r.clientHeight,0),h=n>0?r.clientHeight*n:8,m=Math.min(Math.max(a.top-h,0),l);return r.scrollTo({top:m}),!0}scrollToPosition(t,n="center"){let o=this.editorView?.state,r=this.editorView?.scrollDOM;if(!o||!r||!this.editorView)return!1;let i=Math.min(Math.max(Math.round(t),0),o.doc.length),s=this.editorView.lineBlockAt(i),a=Math.max(r.scrollHeight-r.clientHeight,0),l=s.top;return n==="center"&&(l=s.top-(r.clientHeight-s.height)/2),r.scrollTo({top:Math.min(Math.max(l,0),a)}),!0}applyMarkdownToolbarAction(t){if(!this.editorView)return!1;let{state:n}=this.editorView,o=n.doc.toString(),r=!1,i=n.changeByRange(s=>{let a=sr(o,s,t);return a?(r=!0,{changes:{from:a.from,insert:a.insert,to:a.to},range:p.range(a.anchor,a.head)}):{range:s}});return r?(this.editorView.dispatch(n.update(i,{scrollIntoView:!0,userEvent:"input"})),this.editorView.focus(),!0):!1}insertText(t){if(!this.editorView)return!1;let n=String(t??""),{state:o}=this.editorView,r=o.selection.main,i=r.from+n.length;return this.editorView.dispatch({changes:{from:r.from,insert:n,to:r.to},scrollIntoView:!0,selection:{anchor:i,head:i},userEvent:"input"}),this.editorView.focus(),!0}updateCursorInfo(t){if(!this.lineInfoElement)return;let n=t.selection.main.head,o=t.doc.lineAt(n),r=n-o.from+1;this.lineInfoElement.textContent=`Ln ${o.number}, Col ${r}`}emitViewportChange(){this.onViewportChanged?.(this.getViewportState())}};var pr=class{constructor({editorContainer:t,lineWrappingEnabled:n=!0,initialTheme:o,lineInfoElement:r,onAwarenessChange:i,onConnectionChange:s,onCommentsChange:a,onContentChange:l,onImagePaste:h,onSelectionChange:m,preferredUserName:d,localUser:g,getFileList:C}){this.onAwarenessChange=i,this.onCommentsChange=a,this.onContentChange=l,this.onSelectionChange=m,this.hasDeliveredContent=!1,this.lastDeliveredContent=null,this.collaborationClient=new Ae({localUser:g,onAwarenessChange:x=>this.onAwarenessChange?.(x),onConnectionChange:s,onInitialSync:()=>this.emitContentChange(),preferredUserName:d,resolveAwarenessCursor:x=>this.resolveAwarenessCursor(x)}),this.viewAdapter=new ot({editorContainer:t,getFileList:C||(()=>[]),initialTheme:o,lineInfoElement:r,lineWrappingEnabled:n,onDocChanged:()=>{this.emitContentChange()},onImagePaste:h,onViewportChanged:x=>{this.collaborationClient.setLocalViewport(x)},onSelectionChanged:()=>{this.onSelectionChange?.(this.getCurrentSelectionCommentAnchor())}}),this.commentThreadStore=new Me({getDoc:()=>this.collaborationClient.ydoc,getEditorState:()=>this.viewAdapter.getState(),getLocalUser:()=>this.collaborationClient.getLocalUser(),onCommentsChange:x=>this.onCommentsChange?.(x)})}async initialize(t){this.hasDeliveredContent=!1,this.lastDeliveredContent=null;let n=await this.collaborationClient.initialize(t);this.viewAdapter.initialize({awareness:n.awareness,filePath:t,undoManager:n.undoManager,ytext:n.ytext}),this.commentThreadStore.bind({commentThreads:n.commentThreads,ydoc:n.ydoc,ytext:n.ytext}),this.onAwarenessChange?.(this.collaborationClient.collectUsers(o=>this.resolveAwarenessCursor(o)))}emitContentChange({force:t=!1}={}){let n=this.getText();return!t&&this.hasDeliveredContent&&n===this.lastDeliveredContent?!1:(this.hasDeliveredContent=!0,this.lastDeliveredContent=n,this.onContentChange?.(),!0)}ensureInitialContent(){return this.emitContentChange()}applyTheme(t){this.viewAdapter.applyTheme(t)}getText(){return this.collaborationClient.getText()||this.viewAdapter.getText()}getScrollContainer(){return this.viewAdapter.getScrollContainer()}getTopVisibleLineNumber(t=0){return this.viewAdapter.getTopVisibleLineNumber(t)}getLocalUser(){return this.collaborationClient.getLocalUser()}get awareness(){return this.collaborationClient.awareness}get provider(){return this.collaborationClient.provider}get ydoc(){return this.collaborationClient.ydoc}get ytext(){return this.collaborationClient.ytext}getCurrentSelectionLineRange(){return this.viewAdapter.getCurrentSelectionLineRange()}getCurrentSelectionCommentAnchor(){return this.viewAdapter.getCurrentSelectionCommentAnchor()}getCommentAnchorClientRect(t){return this.viewAdapter.getAnchorClientRect(t)}getSelectionChipClientRect(t){return this.viewAdapter.getSelectionChipClientRect(t)}getCommentThreads(){return this.commentThreadStore.getCommentThreads()}createCommentThread(t){return this.commentThreadStore.createCommentThread(t)}replyToCommentThread(t,n){return this.commentThreadStore.replyToCommentThread(t,n)}toggleCommentReaction(t,n,o){return this.commentThreadStore.toggleCommentReaction(t,n,o)}deleteCommentThread(t){return this.commentThreadStore.deleteCommentThread(t)}isLineWrappingEnabled(){return this.viewAdapter.isLineWrappingEnabled()}setLineWrapping(t){return this.viewAdapter.setLineWrapping(t)}scrollToLine(t,n=0){return this.viewAdapter.scrollToLine(t,n)}getUserCursor(t){return this.collaborationClient.getUserCursor(t,n=>this.resolveAwarenessCursor(n))}getUserViewport(t){return this.collaborationClient.getUserViewport(t)}scrollToPosition(t,n="center"){return this.viewAdapter.scrollToPosition(t,n)}scrollToUserViewport(t){let n=this.getUserViewport(t);return n?this.scrollToLine(n.topLine,n.viewportRatio):!1}scrollToUserCursor(t,n="center"){let o=this.getUserCursor(t);return o?this.scrollToPosition(o.cursorHead,n)||this.scrollToLine(o.cursorLine):!1}setUserName(t){return this.collaborationClient.setUserName(t)}requestMeasure(){this.viewAdapter.requestMeasure()}applyMarkdownToolbarAction(t){return this.viewAdapter.applyMarkdownToolbarAction(t)}insertText(t){return this.viewAdapter.insertText(t)}waitForInitialSync(t=1500){return this.collaborationClient.waitForInitialSync(t)}destroy(){this.commentThreadStore.unbind(),this.hasDeliveredContent=!1,this.lastDeliveredContent=null,this.collaborationClient.destroy(),this.viewAdapter.destroy()}resolveAwarenessCursor(t){let n=this.collaborationClient.ydoc,o=this.collaborationClient.ytext,r=this.viewAdapter.getState();if(!t?.anchor||!t?.head||!n||!r||!o)return null;let i=R(t.anchor,n),s=R(t.head,n);if(!i||!s||i.type!==o||s.type!==o)return null;let a=r.doc.lineAt(s.index);return{cursorAnchor:i.index,cursorHead:s.index,cursorLine:a.number}}};export{pr as EditorSession};