vzcode 1.39.0 → 1.40.0

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.
@@ -144,10 +144,10 @@ a=extmap-allow-mixed`)!==-1){const o=i.sdp.split(`
144
144
  `;)o--;this.fragmentEnd=o?o-1:0}let r=this.cursor;r||(r=this.cursor=this.fragment.tree.cursor(),r.firstChild());let i=e+this.fragment.offset;for(;r.to<=i;)if(!r.parent())return!1;for(;;){if(r.from>=i)return this.fragment.from<=t;if(!r.childAfter(i))return!1}}matches(e){let t=this.cursor.tree;return t&&t.prop(On.contextHash)==e}takeNodes(e){let t=this.cursor,r=this.fragment.offset,i=this.fragmentEnd-(this.fragment.openEnd?1:0),o=e.absoluteLineStart,s=o,a=e.block.children.length,l=s,u=a;for(;;){if(t.to-r>i){if(t.type.isAnonymous&&t.firstChild())continue;break}let c=qB(t.from-r,e.ranges);if(t.to-r<=e.ranges[e.rangeI].to)e.addNode(t.tree,c);else{let f=new nr(e.parser.nodeSet.types[yt.Paragraph],[],[],0,e.block.hashProp);e.reusePlaceholders.set(f,t.tree),e.addNode(f,c)}if(t.type.is("Block")&&(wle.indexOf(t.type.id)<0?(s=t.to-r,a=e.block.children.length):(s=l,a=u,l=t.to-r,u=e.block.children.length)),!t.nextSibling())break}for(;e.block.children.length>a;)e.block.children.pop(),e.block.positions.pop();return s-o}}function qB(n,e){let t=n;for(let r=1;r<e.length;r++){let i=e[r-1].to,o=e[r].from;i<n&&(t-=o-i)}return t}const xle=$u({"Blockquote/...":E.quote,HorizontalRule:E.contentSeparator,"ATXHeading1/... SetextHeading1/...":E.heading1,"ATXHeading2/... SetextHeading2/...":E.heading2,"ATXHeading3/...":E.heading3,"ATXHeading4/...":E.heading4,"ATXHeading5/...":E.heading5,"ATXHeading6/...":E.heading6,"Comment CommentBlock":E.comment,Escape:E.escape,Entity:E.character,"Emphasis/...":E.emphasis,"StrongEmphasis/...":E.strong,"Link/... Image/...":E.link,"OrderedList/... BulletList/...":E.list,"BlockQuote/...":E.quote,"InlineCode CodeText":E.monospace,"URL Autolink":E.url,"HeaderMark HardBreak QuoteMark ListMark LinkMark EmphasisMark CodeMark":E.processingInstruction,"CodeInfo LinkLabel":E.labelName,LinkTitle:E.string,Paragraph:E.content}),Ple=new X0(new hm($B).extend(xle),Object.keys(ey).map(n=>ey[n]),Object.keys(ey).map(n=>AB[n]),Object.keys(ey),yle,wB,Object.keys(i1).map(n=>i1[n]),Object.keys(i1),[]);function Cle(n,e,t){let r=[];for(let i=n.firstChild,o=e;;i=i.nextSibling){let s=i?i.from:t;if(s>o&&r.push({from:o,to:s}),!i)break;o=i.to}return r}function Tle(n){let{codeParser:e,htmlParser:t}=n;return{wrap:OT((i,o)=>{let s=i.type.id;if(e&&(s==yt.CodeBlock||s==yt.FencedCode)){let a="";if(s==yt.FencedCode){let u=i.node.getChild(yt.CodeInfo);u&&(a=o.read(u.from,u.to))}let l=e(a);if(l)return{parser:l,overlay:u=>u.type.id==yt.CodeText}}else if(t&&(s==yt.HTMLBlock||s==yt.HTMLTag))return{parser:t,overlay:Cle(i.node,i.from,i.to)};return null})}}const _le={resolve:"Strikethrough",mark:"StrikethroughMark"},Ele={defineNodes:[{name:"Strikethrough",style:{"Strikethrough/...":E.strikethrough}},{name:"StrikethroughMark",style:E.processingInstruction}],parseInline:[{name:"Strikethrough",parse(n,e,t){if(e!=126||n.char(t+1)!=126||n.char(t+2)==126)return-1;let r=n.slice(t-1,t),i=n.slice(t+2,t+3),o=/\s|^$/.test(r),s=/\s|^$/.test(i),a=Hp.test(r),l=Hp.test(i);return n.addDelimiter(_le,t,t+2,!s&&(!l||o||a),!o&&(!a||s||l))},after:"Emphasis"}]};function bp(n,e,t=0,r,i=0){let o=0,s=!0,a=-1,l=-1,u=!1,c=()=>{r.push(n.elt("TableCell",i+a,i+l,n.parser.parseInline(e.slice(a,l),i+a)))};for(let f=t;f<e.length;f++){let d=e.charCodeAt(f);d==124&&!u?((!s||a>-1)&&o++,s=!1,r&&(a>-1&&c(),r.push(n.elt("TableDelimiter",f+i,f+i+1))),a=l=-1):(u||d!=32&&d!=9)&&(a<0&&(a=f),l=f+1),u=!u&&d==92}return a>-1&&(o++,r&&c()),o}function nI(n,e){for(let t=e;t<n.length;t++){let r=n.charCodeAt(t);if(r==124)return!0;r==92&&t++}return!1}const UB=/^\|?(\s*:?-+:?\s*\|)+(\s*:?-+:?\s*)?$/;class rI{constructor(){this.rows=null}nextLine(e,t,r){if(this.rows==null){this.rows=!1;let i;if((t.next==45||t.next==58||t.next==124)&&UB.test(i=t.text.slice(t.pos))){let o=[];bp(e,r.content,0,o,r.start)==bp(e,i,t.pos)&&(this.rows=[e.elt("TableHeader",r.start,r.start+r.content.length,o),e.elt("TableDelimiter",e.lineStart+t.pos,e.lineStart+t.text.length)])}}else if(this.rows){let i=[];bp(e,t.text,t.pos,i,e.lineStart),this.rows.push(e.elt("TableRow",e.lineStart+t.pos,e.lineStart+t.text.length,i))}return!1}finish(e,t){return this.rows?(e.addLeafElement(t,e.elt("Table",t.start,t.start+t.content.length,this.rows)),!0):!1}}const Rle={defineNodes:[{name:"Table",block:!0},{name:"TableHeader",style:{"TableHeader/...":E.heading}},"TableRow",{name:"TableCell",style:E.content},{name:"TableDelimiter",style:E.processingInstruction}],parseBlock:[{name:"Table",leaf(n,e){return nI(e.content,0)?new rI:null},endLeaf(n,e,t){if(t.parsers.some(i=>i instanceof rI)||!nI(e.text,e.basePos))return!1;let r=n.peekLine();return UB.test(r)&&bp(n,e.text,e.basePos)==bp(n,r,e.basePos)},before:"SetextHeading"}]};class Ale{nextLine(){return!1}finish(e,t){return e.addLeafElement(t,e.elt("Task",t.start,t.start+t.content.length,[e.elt("TaskMarker",t.start,t.start+3),...e.parser.parseInline(t.content.slice(3),t.start+3)])),!0}}const Mle={defineNodes:[{name:"Task",block:!0,style:E.list},{name:"TaskMarker",style:E.atom}],parseBlock:[{name:"TaskList",leaf(n,e){return/^\[[ xX]\][ \t]/.test(e.content)&&n.parentType().name=="ListItem"?new Ale:null},after:"SetextHeading"}]},iI=/(www\.)|(https?:\/\/)|([\w.+-]{1,100}@)|(mailto:|xmpp:)/gy,oI=/[\w-]+(\.[\w-]+)+(\/[^\s<]*)?/gy,$le=/[\w-]+\.[\w-]+($|\/)/,sI=/[\w.+-]+@[\w-]+(\.[\w.-]+)+/gy,aI=/\/[a-zA-Z\d@.]+/gy;function lI(n,e,t,r){let i=0;for(let o=e;o<t;o++)n[o]==r&&i++;return i}function Dle(n,e){oI.lastIndex=e;let t=oI.exec(n);if(!t||$le.exec(t[0])[0].indexOf("_")>-1)return-1;let r=e+t[0].length;for(;;){let i=n[r-1],o;if(/[?!.,:*_~]/.test(i)||i==")"&&lI(n,e,r,")")>lI(n,e,r,"("))r--;else if(i==";"&&(o=/&(?:#\d+|#x[a-f\d]+|\w+);$/.exec(n.slice(e,r))))r=e+o.index;else break}return r}function uI(n,e){sI.lastIndex=e;let t=sI.exec(n);if(!t)return-1;let r=t[0][t[0].length-1];return r=="_"||r=="-"?-1:e+t[0].length-(r=="."?1:0)}const Ile={parseInline:[{name:"Autolink",parse(n,e,t){let r=t-n.offset;if(r&&/\w/.test(n.text[r-1]))return-1;iI.lastIndex=r;let i=iI.exec(n.text),o=-1;if(!i)return-1;if(i[1]||i[2]){if(o=Dle(n.text,r+i[0].length),o>-1&&n.hasOpenLink){let s=/([^\[\]]|\[[^\]]*\])*/.exec(n.text.slice(r,o));o=r+s[0].length}}else i[3]?o=uI(n.text,r):(o=uI(n.text,r+i[0].length),o>-1&&i[0]=="xmpp:"&&(aI.lastIndex=o,i=aI.exec(n.text),i&&(o=i.index+i[0].length)));return o<0?-1:(n.addElement(n.elt("URL",t,o+n.offset)),o+n.offset)}}]},Qle=[Rle,Mle,Ele,Ile];function BB(n,e,t){return(r,i,o)=>{if(i!=n||r.char(o+1)==n)return-1;let s=[r.elt(t,o,o+1)];for(let a=o+1;a<r.end;a++){let l=r.char(a);if(l==n)return r.addElement(r.elt(e,o,a+1,s.concat(r.elt(t,a,a+1))));if(l==92&&s.push(r.elt("Escape",a,a+++2)),Cs(l))break}return-1}}const Lle={defineNodes:[{name:"Superscript",style:E.special(E.content)},{name:"SuperscriptMark",style:E.processingInstruction}],parseInline:[{name:"Superscript",parse:BB(94,"Superscript","SuperscriptMark")}]},jle={defineNodes:[{name:"Subscript",style:E.special(E.content)},{name:"SubscriptMark",style:E.processingInstruction}],parseInline:[{name:"Subscript",parse:BB(126,"Subscript","SubscriptMark")}]},Nle={defineNodes:[{name:"Emoji",style:E.character}],parseInline:[{name:"Emoji",parse(n,e,t){let r;return e!=58||!(r=/^[a-zA-Z_0-9]+:/.exec(n.slice(t+1,n.end)))?-1:n.addElement(n.elt("Emoji",t,t+1+r[0].length))}}]},VB=bT({commentTokens:{block:{open:"<!--",close:"-->"}}}),WB=new On,ZB=Ple.configure({props:[Du.add(n=>!n.is("Block")||n.is("Document")||JP(n)!=null||Fle(n)?void 0:(e,t)=>({from:t.doc.lineAt(e.from).to,to:e.to})),WB.add(JP),jc.add({Document:()=>null}),Sc.add({Document:VB})]});function JP(n){let e=/^(?:ATX|Setext)Heading(\d)$/.exec(n.name);return e?+e[1]:void 0}function Fle(n){return n.name=="OrderedList"||n.name=="BulletList"}function qle(n,e){let t=n;for(;;){let r=t.nextSibling,i;if(!r||(i=JP(r.type))!=null&&i<=e)break;t=r}return t.to}const Ule=l4.of((n,e,t)=>{for(let r=Ar(n).resolveInner(t,-1);r&&!(r.from<e);r=r.parent){let i=r.type.prop(WB);if(i==null)continue;let o=qle(r,i);if(o>t)return{from:t,to:o}}return null});function JT(n){return new Os(VB,n,[Ule],"markdown")}const Ble=JT(ZB),Vle=ZB.configure([Qle,jle,Lle,Nle,{props:[Du.add({Table:(n,e)=>({from:e.doc.lineAt(n.from).to,to:n.to})})]}]),eC=JT(Vle);function Wle(n,e){return t=>{if(t&&n){let r=null;if(t=/\S*/.exec(t)[0],typeof n=="function"?r=n(t):r=$O.matchLanguageName(n,t,!0),r instanceof $O)return r.support?r.support.language.parser:Fp.getSkippingParser(r.load());if(r)return r.parser}return e?e.parser:null}}class o1{constructor(e,t,r,i,o,s,a){this.node=e,this.from=t,this.to=r,this.spaceBefore=i,this.spaceAfter=o,this.type=s,this.item=a}blank(e,t=!0){let r=this.spaceBefore+(this.node.name=="Blockquote"?">":"");if(e!=null){for(;r.length<e;)r+=" ";return r}else{for(let i=this.to-this.from-r.length-this.spaceAfter.length;i>0;i--)r+=" ";return r+(t?this.spaceAfter:"")}}marker(e,t){let r=this.node.name=="OrderedList"?String(+XB(this.item,e)[2]+t):"";return this.spaceBefore+r+this.type+this.spaceAfter}}function zB(n,e){let t=[],r=[];for(let i=n;i;i=i.parent){if(i.name=="FencedCode")return r;(i.name=="ListItem"||i.name=="Blockquote")&&t.push(i)}for(let i=t.length-1;i>=0;i--){let o=t[i],s,a=e.lineAt(o.from),l=o.from-a.from;if(o.name=="Blockquote"&&(s=/^ *>( ?)/.exec(a.text.slice(l))))r.push(new o1(o,l,l+s[0].length,"",s[1],">",null));else if(o.name=="ListItem"&&o.parent.name=="OrderedList"&&(s=/^( *)\d+([.)])( *)/.exec(a.text.slice(l)))){let u=s[3],c=s[0].length;u.length>=4&&(u=u.slice(0,u.length-4),c-=4),r.push(new o1(o.parent,l,l+c,s[1],u,s[2],o))}else if(o.name=="ListItem"&&o.parent.name=="BulletList"&&(s=/^( *)([-+*])( {1,4}\[[ xX]\])?( +)/.exec(a.text.slice(l)))){let u=s[4],c=s[0].length;u.length>4&&(u=u.slice(0,u.length-4),c-=4);let f=s[2];s[3]&&(f+=s[3].replace(/[xX]/," ")),r.push(new o1(o.parent,l,l+c,s[1],u,f,o))}}return r}function XB(n,e){return/^(\s*)(\d+)(?=[.)])/.exec(e.sliceString(n.from,n.from+10))}function s1(n,e,t,r=0){for(let i=-1,o=n;;){if(o.name=="ListItem"){let a=XB(o,e),l=+a[2];if(i>=0){if(l!=i+1)return;t.push({from:o.from+a[1].length,to:o.from+a[0].length,insert:String(i+2+r)})}i=l}let s=o.nextSibling;if(!s)break;o=s}}function e_(n,e){let t=/^[ \t]*/.exec(n)[0].length;if(!t||e.facet(pm)!=" ")return n;let r=Gs(n,4,t),i="";for(let o=r;o>0;)o>=4?(i+=" ",o-=4):(i+=" ",o--);return i+n.slice(t)}const Zle=({state:n,dispatch:e})=>{let t=Ar(n),{doc:r}=n,i=null,o=n.changeByRange(s=>{if(!s.empty||!eC.isActiveAt(n,s.from,-1)&&!eC.isActiveAt(n,s.from,1))return i={range:s};let a=s.from,l=r.lineAt(a),u=zB(t.resolveInner(a,-1),r);for(;u.length&&u[u.length-1].from>a-l.from;)u.pop();if(!u.length)return i={range:s};let c=u[u.length-1];if(c.to-c.spaceAfter.length>a-l.from)return i={range:s};let f=a>=c.to-c.spaceAfter.length&&!/\S/.test(l.text.slice(c.to));if(c.item&&f){let v=c.node.firstChild,O=c.node.getChild("ListItem","ListItem");if(v.to>=a||O&&O.to<a||l.from>0&&!/[^\s>]/.test(r.lineAt(l.from-1).text)){let S=u.length>1?u[u.length-2]:null,w,k="";S&&S.item?(w=l.from+S.from,k=S.marker(r,1)):w=l.from+(S?S.to:0);let x=[{from:w,to:a,insert:k}];return c.node.name=="OrderedList"&&s1(c.item,r,x,-2),S&&S.node.name=="OrderedList"&&s1(S.item,r,x),{range:Ue.cursor(w+k.length),changes:x}}else{let S=fI(u,n,l);return{range:Ue.cursor(a+S.length+1),changes:{from:l.from,insert:S+n.lineBreak}}}}if(c.node.name=="Blockquote"&&f&&l.from){let v=r.lineAt(l.from-1),O=/>\s*$/.exec(v.text);if(O&&O.index==c.from){let S=n.changes([{from:v.from+O.index,to:v.to},{from:l.from+c.from,to:l.to}]);return{range:s.map(S),changes:S}}}let d=[];c.node.name=="OrderedList"&&s1(c.item,r,d);let p=c.item&&c.item.from<l.from,m="";if(!p||/^[\s\d.)\-+*>]*/.exec(l.text)[0].length>=c.to)for(let v=0,O=u.length-1;v<=O;v++)m+=v==O&&!p?u[v].marker(r,1):u[v].blank(v<O?Gs(l.text,4,u[v+1].from)-m.length:null);let y=a;for(;y>l.from&&/\s/.test(l.text.charAt(y-l.from-1));)y--;return m=e_(m,n),zle(c.node,n.doc)&&(m=fI(u,n,l)+n.lineBreak+m),d.push({from:y,to:a,insert:n.lineBreak+m}),{range:Ue.cursor(y+m.length+1),changes:d}});return i?!1:(e(n.update(o,{scrollIntoView:!0,userEvent:"input"})),!0)};function cI(n){return n.name=="QuoteMark"||n.name=="ListMark"}function zle(n,e){if(n.name!="OrderedList"&&n.name!="BulletList")return!1;let t=n.firstChild,r=n.getChild("ListItem","ListItem");if(!r)return!1;let i=e.lineAt(t.to),o=e.lineAt(r.from),s=/^[\s>]*$/.test(i.text);return i.number+(s?0:1)<o.number}function fI(n,e,t){let r="";for(let i=0,o=n.length-2;i<=o;i++)r+=n[i].blank(i<o?Gs(t.text,4,n[i+1].from)-r.length:null,i<o);return e_(r,e)}function Xle(n,e){let t=n.resolveInner(e,-1),r=e;cI(t)&&(r=t.from,t=t.parent);for(let i;i=t.childBefore(r);)if(cI(i))r=i.from;else if(i.name=="OrderedList"||i.name=="BulletList")t=i.lastChild,r=t.to;else break;return t}const Yle=({state:n,dispatch:e})=>{let t=Ar(n),r=null,i=n.changeByRange(o=>{let s=o.from,{doc:a}=n;if(o.empty&&eC.isActiveAt(n,o.from)){let l=a.lineAt(s),u=zB(Xle(t,s),a);if(u.length){let c=u[u.length-1],f=c.to-c.spaceAfter.length+(c.spaceAfter?1:0);if(s-l.from>f&&!/\S/.test(l.text.slice(f,s-l.from)))return{range:Ue.cursor(l.from+f),changes:{from:l.from+f,to:s}};if(s-l.from==f&&(!c.item||l.from<=c.item.from||!/\S/.test(l.text.slice(0,c.to)))){let d=l.from+c.from;if(c.item&&c.node.from<c.item.from&&/\S/.test(l.text.slice(c.from,c.to))){let p=c.blank(Gs(l.text,4,c.to)-Gs(l.text,4,c.from));return d==l.from&&(p=e_(p,n)),{range:Ue.cursor(d+p.length),changes:{from:d,to:l.from+c.to,insert:p}}}if(d<s)return{range:Ue.cursor(d),changes:{from:d,to:s}}}}}return r={range:o}});return r?!1:(e(n.update(i,{scrollIntoView:!0,userEvent:"delete"})),!0)},Hle=[{key:"Enter",run:Zle},{key:"Backspace",run:Yle}],YB=aB({matchClosingTags:!1});function Gle(n={}){let{codeLanguages:e,defaultCodeLanguage:t,addKeymap:r=!0,base:{parser:i}=Ble,completeHTMLTags:o=!0,htmlTagLanguage:s=YB}=n;if(!(i instanceof X0))throw new RangeError("Base parser provided to `markdown` should be a Markdown parser");let a=n.extensions?[n.extensions]:[],l=[s.support],u;t instanceof Dc?(l.push(t.support),u=t.language):t&&(u=t);let c=e||u?Wle(e,u):void 0;a.push(Tle({codeParser:c,htmlParser:s.language.parser})),r&&l.push(Na.high(Md.of(Hle)));let f=JT(i.configure(a));return o&&l.push(f.data.of({autocomplete:Kle})),new Dc(f,l)}function Kle(n){let{state:e,pos:t}=n,r=/<[:\-\.\w\u00b7-\uffff]*$/.exec(e.sliceDoc(t-25,t));if(!r)return null;let i=Ar(e).resolveInner(t,-1);for(;i&&!i.type.isTop;){if(i.name=="CodeBlock"||i.name=="FencedCode"||i.name=="ProcessingInstructionBlock"||i.name=="CommentBlock"||i.name=="Link"||i.name=="Image")return null;i=i.parent}return{from:t-r[0].length,to:t,options:Jle(),validFor:/^<[:\-\.\w\u00b7-\uffff]*$/}}let a1=null;function Jle(){if(a1)return a1;let n=rB(new DT(Xn.create({extensions:YB}),0,!0));return a1=n?n.options:[]}const dI=(n,e,t,r,i)=>{let o=[],s=0;return e.iterChanges((a,l,u,c,f)=>{const d=t.sliceString(a,l,`
145
145
  `),p=f.sliceString(0,f.length,`
146
146
  `);d&&o.push(i.remove(a+s,d)),p&&o.push(i.insert(a+s,p)),s+=p.length,s-=d.length}),o.length===0?null:(o=o.reduce(i.type.compose),r.editOp(n,"text-unicode",o))},hI=n=>{if(!n)return[];const e=[];for(const t of n){const{es:r}=t;if(r!==void 0){let i=0;for(let o=0;o<r.length;o++){const s=r[o];if(typeof s=="number")i+=s;else if(typeof s=="string")if(r[o+1]&&typeof r[o+1]=="object"&&r[o+1].d!==void 0){let a=typeof r[o+1].d=="number"?r[o+1].d:r[o+1].d.length;e.push({from:i,to:i+a,insert:s}),i+=a,o++}else e.push({from:i,to:i,insert:s});else s&&s.d!==void 0&&(typeof s.d=="number"?(e.push({from:i,to:i+s.d}),i+=s.d):typeof s.d=="string"&&(e.push({from:i,to:i+s.d.length}),i+=s.d.length))}}}return e},eue=(n,e)=>{if(!n||!e)return!1;for(let t=0;t<e.length;t++)if(e[t]!==n[t])return!1;return!0},tue=({shareDBDoc:n,path:e=[],json1:t,textUnicode:r,debug:i=!1})=>ir.fromClass(class{constructor(o){this.view=o,this.handleOp=s=>{if(this.lock||!Array.isArray(s))return;this.lock=!0;const a=Array.isArray(s[0])?s:[s];for(const l of a)eue(l,e)&&(i&&(console.log("Received op from ShareDB"),console.log(" op: "+JSON.stringify(l)),console.log(" generated changes: "+JSON.stringify(hI(l)))),o.dispatch({changes:hI(l)}));this.lock=!1},n.on("op",this.handleOp)}update(o){!this.lock&&o.docChanged&&(this.lock=!0,i&&(console.log("Received change from CodeMirror"),console.log(" changes:"+JSON.stringify(o.changes.toJSON())),console.log(" iterChanges:"),o.changes.iterChanges((s,a,l,u,c)=>{console.log(" "+JSON.stringify({fromA:s,toA:a,fromB:l,toB:u,inserted:c.sliceString(0,c.length,`
147
- `)}))}),console.log(" generated json1 op: "+JSON.stringify(dI(e,o.changes,o.startState.doc,t,r)))),n.submitOp(dI(e,o.changes,o.startState.doc,t,r)),this.lock=!1)}destroy(){n.off("op",this.handleOp)}});function nue(n,e=n.state){const t=new Set;for(const{from:r,to:i}of n.visibleRanges){let o=r;for(;o<=i;){const s=e.doc.lineAt(o);t.has(s)||t.add(s),o=s.to+1}}return t}function tC(n){const e=n.selection.main.head;return n.doc.lineAt(e)}function pI(n,e){let t=0;e:for(let r=0;r<n.length;r++)switch(n[r]){case" ":case" ":{t+=1;continue e}case" ":{t+=e-t%e;continue e}case"\r":continue e;default:break e}return t}const KO=Tt.define({combine(n){return is(n,{highlightActiveBlock:!0,hideFirstIndent:!1,markerType:"fullScope",thickness:1})}});class rue{constructor(e,t,r,i){this.lines=e,this.state=t,this.map=new Map,this.unitWidth=r,this.markerType=i;for(const o of this.lines)this.add(o);this.state.facet(KO).highlightActiveBlock&&this.findAndSetActiveLines()}has(e){return this.map.has(typeof e=="number"?e:e.number)}get(e){const t=this.map.get(typeof e=="number"?e:e.number);if(!t)throw new Error("Line not found in indentation map");return t}set(e,t,r){const i=!e.text.trim().length,o={line:e,col:t,level:r,empty:i};return this.map.set(o.line.number,o),o}add(e){if(this.has(e))return this.get(e);if(!e.length||!e.text.trim().length){if(e.number===1)return this.set(e,0,0);if(e.number===this.state.doc.lines){const s=this.closestNonEmpty(e,-1);return this.set(e,0,s.level)}const i=this.closestNonEmpty(e,-1),o=this.closestNonEmpty(e,1);return i.level>=o.level&&this.markerType!=="codeOnly"?this.set(e,0,i.level):i.empty&&i.level===0&&o.level!==0?this.set(e,0,0):o.level>i.level?this.set(e,0,i.level+1):this.set(e,0,o.level)}const t=pI(e.text,this.state.tabSize),r=Math.floor(t/this.unitWidth);return this.set(e,t,r)}closestNonEmpty(e,t){let r=e.number+t;for(;t===-1?r>=1:r<=this.state.doc.lines;){if(this.has(r)){const s=this.get(r);if(!s.empty)return s}const o=this.state.doc.line(r);if(o.text.trim().length){const s=pI(o.text,this.state.tabSize),a=Math.floor(s/this.unitWidth);return this.set(o,s,a)}r+=t}const i=this.state.doc.line(t===-1?1:this.state.doc.lines);return this.set(i,0,0)}findAndSetActiveLines(){const e=tC(this.state);if(!this.has(e))return;let t=this.get(e);if(this.has(t.line.number+1)){const o=this.get(t.line.number+1);o.level>t.level&&(t=o)}if(this.has(t.line.number-1)){const o=this.get(t.line.number-1);o.level>t.level&&(t=o)}if(t.level===0)return;t.active=t.level;let r,i;for(r=t.line.number;r>1;r--){if(!this.has(r-1))continue;const o=this.get(r-1);if(o.level<t.level)break;o.active=t.level}for(i=t.line.number;i<this.state.doc.lines;i++){if(!this.has(i+1))continue;const o=this.get(i+1);if(o.level<t.level)break;o.active=t.level}}}function iue(n){const e={light:"#F0F1F2",dark:"#2B3245",activeLight:"#E4E5E6",activeDark:"#3C445C"};let t=e;return n&&(t=Object.assign(Object.assign({},e),n)),ht.baseTheme({"&light":{"--indent-marker-bg-color":t.light,"--indent-marker-active-bg-color":t.activeLight},"&dark":{"--indent-marker-bg-color":t.dark,"--indent-marker-active-bg-color":t.activeDark},".cm-line":{position:"relative"},".cm-indent-markers::before":{content:'""',position:"absolute",top:0,left:"2px",right:0,bottom:0,background:"var(--indent-markers)",pointerEvents:"none",zIndex:"-1"}})}function ny(n,e,t,r,i){return`${`repeating-linear-gradient(to right, var(${n}) 0 ${e}px, transparent ${e}px ${t}ch)`} ${r*t}.5ch/calc(${t*i}ch - 1px) no-repeat`}function oue(n,e,t,r,i){const{level:o,active:s}=n;if(i=i??r,t&&o===0)return[];const a=t?1:0,l=[];if(s!==void 0){const u=s-a-1;u>0&&l.push(ny("--indent-marker-bg-color",r,e,a,u)),l.push(ny("--indent-marker-active-bg-color",i,e,s-1,1)),s!==o&&l.push(ny("--indent-marker-bg-color",r,e,s,o-s))}else l.push(ny("--indent-marker-bg-color",r,e,a,o-a));return l.join(",")}class sue{constructor(e){this.view=e,this.unitWidth=wd(e.state),this.currentLineNumber=tC(e.state).number,this.generate(e.state)}update(e){const t=wd(e.state),r=t!==this.unitWidth;r&&(this.unitWidth=t);const i=tC(e.state).number,o=i!==this.currentLineNumber;this.currentLineNumber=i;const s=e.state.facet(KO).highlightActiveBlock&&o;(e.docChanged||e.viewportChanged||r||s)&&this.generate(e.state)}generate(e){const t=new yl,r=nue(this.view,e),{hideFirstIndent:i,markerType:o,thickness:s,activeThickness:a}=e.facet(KO),l=new rue(r,e,this.unitWidth,o);for(const u of r){const c=l.get(u.number);if(!c?.level)continue;const f=oue(c,this.unitWidth,i,s,a);t.add(u.from,u.from,Rt.line({class:"cm-indent-markers",attributes:{style:`--indent-markers: ${f}`}}))}this.decorations=t.finish()}}function aue(n={}){return[KO.of(n),iue(n.colors),ir.fromClass(sue,{decorations:e=>e.decorations})]}const HB=n=>e=>{const t=n==="down";let r=e.state.selection;for(const i of r.ranges)r=r.addRange(e.moveVertically(i,t));return e.dispatch({selection:r}),!0},lue=HB("up"),uue=HB("down"),cue=n=>{let e=null;for(const t of n.state.selection.ranges)if(!t.empty)for(let r=t.from;r<=t.to;){const i=n.state.doc.lineAt(r),o=Math.min(i.to,t.to);e?e=e.addRange(Ue.range(o,o)):e=Ue.single(o),r=i.to+1}return e?(n.dispatch({selection:e}),!0):!1},fue=[{key:"Ctrl-Space",run:LP},{key:"Escape",run:iU},{key:"ArrowDown",run:pu(!0)},{key:"ArrowUp",run:pu(!1)},{key:"PageDown",run:pu(!0,"page")},{key:"PageUp",run:pu(!1,"page")},{key:"Enter",run:QP},{key:"Tab",run:QP},{key:"Mod-f",run:K4,scope:"editor search-panel"},{key:"Escape",run:J4,scope:"editor search-panel"},{key:"Alt-Enter",run:X4,scope:"editor search-panel"},{key:"Mod-Alt-Enter",run:Y4,scope:"editor search-panel"},{key:"Ctrl-g",run:Rne},{key:"Mod-d",run:Une,preventDefault:!0},{key:"Shift-Mod-l",run:Hne},{key:"Enter",run:WD,shift:WD},{key:"ArrowLeft",run:xD,shift:RD,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:sne,shift:dne},{key:"ArrowRight",run:PD,shift:AD,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:ane,shift:hne},{key:"ArrowUp",run:CD,shift:MD,preventDefault:!0},{key:"ArrowDown",run:TD,shift:$D,preventDefault:!0},{key:"Home",run:ED,shift:LD},{mac:"Cmd-ArrowLeft",run:ED,shift:LD},{key:"Mod-Home",run:jD,shift:FD},{mac:"Cmd-ArrowUp",run:jD,shift:FD},{key:"PageUp",run:jw,shift:DD},{mac:"Ctrl-ArrowUp",run:jw,shift:DD},{key:"PageDown",run:Nw,shift:ID},{mac:"Ctrl-ArrowDown",run:Nw,shift:ID},{key:"End",run:_D,shift:QD},{mac:"Cmd-ArrowRight",run:_D,shift:QD},{key:"Mod-Alt-ArrowUp",linux:"Shift-Alt-ArrowUp",run:lue,preventDefault:!0},{key:"Mod-Alt-ArrowDown",linux:"Shift-Alt-ArrowDown",run:uue,preventDefault:!0},{key:"Shift-Alt-i",run:cue},{key:"Mod-End",run:ND,shift:qD},{mac:"Cmd-ArrowDown",run:ND,shift:qD},{key:"Mod-a",run:gne},{key:"Backspace",run:jre},{key:"Backspace",run:Fw,shift:Fw},{key:"Delete",run:UD},{key:"Mod-Backspace",mac:"Alt-Backspace",run:BD},{key:"Mod-Delete",mac:"Alt-Delete",run:vne},{mac:"Mod-Backspace",run:One},{mac:"Mod-Delete",run:VD},{mac:"Ctrl-b",run:xD,shift:RD,preventDefault:!0},{mac:"Ctrl-f",run:PD,shift:AD},{mac:"Ctrl-p",run:CD,shift:MD},{mac:"Ctrl-n",run:TD,shift:$D},{mac:"Ctrl-a",run:lne,shift:pne},{mac:"Ctrl-e",run:une,shift:mne},{mac:"Ctrl-d",run:UD},{mac:"Ctrl-h",run:Fw},{mac:"Ctrl-k",run:VD},{mac:"Ctrl-Alt-h",run:BD},{mac:"Ctrl-o",run:bne},{mac:"Ctrl-t",run:Sne},{mac:"Ctrl-v",run:Nw},{mac:"Alt-v",run:jw},{key:"Shift-Mod-k",run:Cne},{key:"Alt-ArrowDown",run:kne},{key:"Alt-ArrowUp",run:wne},{win:"Shift-Alt-ArrowDown",mac:"Shift-Alt-ArrowDown",run:Pne},{win:"Shift-Alt-ArrowUp",mac:"Shift-Alt-ArrowUp",run:xne},{key:"Mod-l",run:yne,preventDefault:!0},{key:"Shift-Mod-\\",run:fne},{key:"Tab",run:ZD,shift:zD,preventDefault:!0},{key:"Mod-[",run:zD},{key:"Mod-]",run:ZD},{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:Kee},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:Jee},{key:"Mod-k Mod-0",run:ete},{key:"Mod-k Mod-j",run:tte},{key:"Mod-k Mod-c",run:Vte},{key:"Mod-k Mod-u",run:Wte},{key:"Mod-/",run:Ute},{key:"Shift-Alt-a",run:Zte},{key:"Mod-z",run:C4,preventDefault:!0},{key:"Mod-y",run:$P,preventDefault:!0},{key:"Mod-Shift-z",run:$P,preventDefault:!0},{key:"Mod-u",run:Jte,preventDefault:!0},{key:"Mod-Shift-m",run:Hre},{key:"F8",run:Gre}],due=({path:n,localPresence:e,usernameRef:t})=>ht.updateListener.of(r=>{if(r.selectionSet){const i=r.state.selection.ranges[0],{from:o,to:s}=i,a={start:[...n,o],end:[...n,s],username:t.current};e.submit(a,l=>{if(l)throw l})}});var pn=function(n,e,t){if(!e.has(n))throw new TypeError("attempted to set private field on non-instance");return e.set(n,t),t},It=function(n,e){if(!e.has(n))throw new TypeError("attempted to get private field on non-instance");return e.get(n)},Gl,hc,Us,If,up,pa,ma,ga,ya,va,Oa,ba,Sa,pc,Qf,Kl,eO,Jl;const hue=function(n){var e=131,t=137,r=0;n+="x";var i=Math.floor(9007199254740991/t);for(let o=0;o<n.length;o++)r>i&&(r=Math.floor(r/t)),r=r*e+n.charCodeAt(o);return r},jt="0123456789abcdef".split(""),pue=[-2147483648,8388608,32768,128],Ns=[24,16,8,0],ry=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],wi=[];class mue{constructor(e=!1,t=!1){Gl.set(this,void 0),hc.set(this,void 0),Us.set(this,void 0),If.set(this,void 0),up.set(this,void 0),pa.set(this,void 0),ma.set(this,void 0),ga.set(this,void 0),ya.set(this,void 0),va.set(this,void 0),Oa.set(this,void 0),ba.set(this,void 0),Sa.set(this,void 0),pc.set(this,void 0),Qf.set(this,void 0),Kl.set(this,void 0),eO.set(this,0),Jl.set(this,void 0),this.init(e,t)}init(e,t){t?(wi[0]=wi[16]=wi[1]=wi[2]=wi[3]=wi[4]=wi[5]=wi[6]=wi[7]=wi[8]=wi[9]=wi[10]=wi[11]=wi[12]=wi[13]=wi[14]=wi[15]=0,pn(this,hc,wi)):pn(this,hc,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),e?(pn(this,pa,3238371032),pn(this,ma,914150663),pn(this,ga,812702999),pn(this,ya,4144912697),pn(this,va,4290775857),pn(this,Oa,1750603025),pn(this,ba,1694076839),pn(this,Sa,3204075428)):(pn(this,pa,1779033703),pn(this,ma,3144134277),pn(this,ga,1013904242),pn(this,ya,2773480762),pn(this,va,1359893119),pn(this,Oa,2600822924),pn(this,ba,528734635),pn(this,Sa,1541459225)),pn(this,Gl,pn(this,Jl,pn(this,Us,pn(this,Qf,0)))),pn(this,If,pn(this,pc,!1)),pn(this,up,!0),pn(this,Kl,e)}update(e){if(It(this,If))return this;let t;e instanceof ArrayBuffer?t=new Uint8Array(e):t=e;let r=0;const i=t.length,o=It(this,hc);for(;r<i;){let s;if(It(this,pc)&&(pn(this,pc,!1),o[0]=It(this,Gl),o[16]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0),typeof t!="string")for(s=It(this,Jl);r<i&&s<64;++r)o[s>>2]|=t[r]<<Ns[s++&3];else for(s=It(this,Jl);r<i&&s<64;++r){let a=t.charCodeAt(r);a<128?o[s>>2]|=a<<Ns[s++&3]:a<2048?(o[s>>2]|=(192|a>>6)<<Ns[s++&3],o[s>>2]|=(128|a&63)<<Ns[s++&3]):a<55296||a>=57344?(o[s>>2]|=(224|a>>12)<<Ns[s++&3],o[s>>2]|=(128|a>>6&63)<<Ns[s++&3],o[s>>2]|=(128|a&63)<<Ns[s++&3]):(a=65536+((a&1023)<<10|t.charCodeAt(++r)&1023),o[s>>2]|=(240|a>>18)<<Ns[s++&3],o[s>>2]|=(128|a>>12&63)<<Ns[s++&3],o[s>>2]|=(128|a>>6&63)<<Ns[s++&3],o[s>>2]|=(128|a&63)<<Ns[s++&3])}pn(this,eO,s),pn(this,Us,It(this,Us)+(s-It(this,Jl))),s>=64?(pn(this,Gl,o[16]),pn(this,Jl,s-64),this.hash(),pn(this,pc,!0)):pn(this,Jl,s)}return It(this,Us)>4294967295&&(pn(this,Qf,It(this,Qf)+(It(this,Us)/4294967296<<0)),pn(this,Us,It(this,Us)%4294967296)),this}finalize(){if(It(this,If))return;pn(this,If,!0);const e=It(this,hc),t=It(this,eO);e[16]=It(this,Gl),e[t>>2]|=pue[t&3],pn(this,Gl,e[16]),t>=56&&(It(this,pc)||this.hash(),e[0]=It(this,Gl),e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=It(this,Qf)<<3|It(this,Us)>>>29,e[15]=It(this,Us)<<3,this.hash()}hash(){let e=It(this,pa),t=It(this,ma),r=It(this,ga),i=It(this,ya),o=It(this,va),s=It(this,Oa),a=It(this,ba),l=It(this,Sa);const u=It(this,hc);let c,f,d,p,m,y,v,O,S,w;for(let k=16;k<64;++k)p=u[k-15],c=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,p=u[k-2],f=(p>>>17|p<<15)^(p>>>19|p<<13)^p>>>10,u[k]=u[k-16]+c+u[k-7]+f<<0;w=t&r;for(let k=0;k<64;k+=4)It(this,up)?(It(this,Kl)?(v=300032,p=u[0]-1413257819,l=p-150054599<<0,i=p+24177077<<0):(v=704751109,p=u[0]-210244248,l=p-1521486534<<0,i=p+143694565<<0),pn(this,up,!1)):(c=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),f=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7),v=e&t,d=v^e&r^w,y=o&s^~o&a,p=l+f+y+ry[k]+u[k],m=c+d,l=i+p<<0,i=p+m<<0),c=(i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10),f=(l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7),O=i&e,d=O^i&t^v,y=l&o^~l&s,p=a+f+y+ry[k+1]+u[k+1],m=c+d,a=r+p<<0,r=p+m<<0,c=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),f=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),S=r&i,d=S^r&e^O,y=a&l^~a&o,p=s+f+y+ry[k+2]+u[k+2],m=c+d,s=t+p<<0,t=p+m<<0,c=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),f=(s>>>6|s<<26)^(s>>>11|s<<21)^(s>>>25|s<<7),w=t&r,d=w^t&i^S,y=s&a^~s&l,p=o+f+y+ry[k+3]+u[k+3],m=c+d,o=e+p<<0,e=p+m<<0;pn(this,pa,It(this,pa)+e<<0),pn(this,ma,It(this,ma)+t<<0),pn(this,ga,It(this,ga)+r<<0),pn(this,ya,It(this,ya)+i<<0),pn(this,va,It(this,va)+o<<0),pn(this,Oa,It(this,Oa)+s<<0),pn(this,ba,It(this,ba)+a<<0),pn(this,Sa,It(this,Sa)+l<<0)}hex(){this.finalize();const e=It(this,pa),t=It(this,ma),r=It(this,ga),i=It(this,ya),o=It(this,va),s=It(this,Oa),a=It(this,ba),l=It(this,Sa);let u=jt[e>>28&15]+jt[e>>24&15]+jt[e>>20&15]+jt[e>>16&15]+jt[e>>12&15]+jt[e>>8&15]+jt[e>>4&15]+jt[e&15]+jt[t>>28&15]+jt[t>>24&15]+jt[t>>20&15]+jt[t>>16&15]+jt[t>>12&15]+jt[t>>8&15]+jt[t>>4&15]+jt[t&15]+jt[r>>28&15]+jt[r>>24&15]+jt[r>>20&15]+jt[r>>16&15]+jt[r>>12&15]+jt[r>>8&15]+jt[r>>4&15]+jt[r&15]+jt[i>>28&15]+jt[i>>24&15]+jt[i>>20&15]+jt[i>>16&15]+jt[i>>12&15]+jt[i>>8&15]+jt[i>>4&15]+jt[i&15]+jt[o>>28&15]+jt[o>>24&15]+jt[o>>20&15]+jt[o>>16&15]+jt[o>>12&15]+jt[o>>8&15]+jt[o>>4&15]+jt[o&15]+jt[s>>28&15]+jt[s>>24&15]+jt[s>>20&15]+jt[s>>16&15]+jt[s>>12&15]+jt[s>>8&15]+jt[s>>4&15]+jt[s&15]+jt[a>>28&15]+jt[a>>24&15]+jt[a>>20&15]+jt[a>>16&15]+jt[a>>12&15]+jt[a>>8&15]+jt[a>>4&15]+jt[a&15];return It(this,Kl)||(u+=jt[l>>28&15]+jt[l>>24&15]+jt[l>>20&15]+jt[l>>16&15]+jt[l>>12&15]+jt[l>>8&15]+jt[l>>4&15]+jt[l&15]),u}toString(){return this.hex()}digest(){this.finalize();const e=It(this,pa),t=It(this,ma),r=It(this,ga),i=It(this,ya),o=It(this,va),s=It(this,Oa),a=It(this,ba),l=It(this,Sa),u=[e>>24&255,e>>16&255,e>>8&255,e&255,t>>24&255,t>>16&255,t>>8&255,t&255,r>>24&255,r>>16&255,r>>8&255,r&255,i>>24&255,i>>16&255,i>>8&255,i&255,o>>24&255,o>>16&255,o>>8&255,o&255,s>>24&255,s>>16&255,s>>8&255,s&255,a>>24&255,a>>16&255,a>>8&255,a&255];return It(this,Kl)||u.push(l>>24&255,l>>16&255,l>>8&255,l&255),u}array(){return this.digest()}arrayBuffer(){this.finalize();const e=new ArrayBuffer(It(this,Kl)?28:32),t=new DataView(e);return t.setUint32(0,It(this,pa)),t.setUint32(4,It(this,ma)),t.setUint32(8,It(this,ga)),t.setUint32(12,It(this,ya)),t.setUint32(16,It(this,va)),t.setUint32(20,It(this,Oa)),t.setUint32(24,It(this,ba)),It(this,Kl)||t.setUint32(28,It(this,Sa)),e}}Gl=new WeakMap,hc=new WeakMap,Us=new WeakMap,If=new WeakMap,up=new WeakMap,pa=new WeakMap,ma=new WeakMap,ga=new WeakMap,ya=new WeakMap,va=new WeakMap,Oa=new WeakMap,ba=new WeakMap,Sa=new WeakMap,pc=new WeakMap,Qf=new WeakMap,Kl=new WeakMap,eO=new WeakMap,Jl=new WeakMap;function gue(n){const e=new mue;return e.update(n),parseInt(e.hex().substring(0,8),16)}const yue=function(n){var e="#";return n.forEach(function(t){t<16&&(e+=0),e+=t.toString(16)}),e},vue=function(n,e,t){n/=360;var r=t<.5?t*(1+e):t+e-t*e,i=2*t-r;return[n+1/3,n,n-1/3].map(function(o){return o<0&&o++,o>1&&o--,o<1/6?o=i+(r-i)*6*o:o<.5?o=r:o<2/3?o=i+(r-i)*6*(2/3-o):o=i,Math.round(o*255)})};class Oue{constructor(e={}){const[t,r]=[e.lightness,e.saturation].map(function(i){return i=i!==void 0?i:[.35,.5,.65],Array.isArray(i)?i.concat():[i]});this.L=t,this.S=r,typeof e.hue=="number"&&(e.hue={min:e.hue,max:e.hue}),typeof e.hue=="object"&&!Array.isArray(e.hue)&&(e.hue=[e.hue]),typeof e.hue>"u"&&(e.hue=[]),this.hueRanges=e.hue.map(function(i){return{min:typeof i.min>"u"?0:i.min,max:typeof i.max>"u"?360:i.max}}),this.hash=gue,typeof e.hash=="function"&&(this.hash=e.hash),e.hash==="bkdr"&&(this.hash=hue)}hsl(e){var t,r,i,o=this.hash(e),s=727;if(this.hueRanges.length){const a=this.hueRanges[o%this.hueRanges.length];t=o/this.hueRanges.length%s*(a.max-a.min)/s+a.min}else t=o%359;return o=Math.ceil(o/360),r=this.S[o%this.S.length],o=Math.ceil(o/this.S.length),i=this.L[o%this.L.length],[t,r,i]}rgb(e){var t=this.hsl(e);return vue.apply(this,t)}hex(e){var t=this.rgb(e);return yue(t)}}const GB=n=>new Oue({lightness:.75}).rgb(n).join(","),bue=({path:n,docPresence:e,enableAutoFollowRef:t})=>[ir.fromClass(class{decorations;cursorPosition={};constructor(r){this.decorations=Vn.of([]);const i={};e.on("receive",(o,s)=>{if(console.log(`Received presence for id ${o}`,s),!s){delete i[o];return}wue(n,s)?i[o]=s:s&&delete i[o];const l=[];for(const u of Object.keys(i)){const c=i[u],{start:f,end:d}=c,p=+f[f.length-1],m=+d[d.length-1],y=GB(c.username),{username:v}=c;l.push({from:p,to:p,value:Rt.widget({side:-1,block:!1,widget:new kue(""+Math.random(),y,v)})}),p!==m&&l.push({from:p,to:m,value:Rt.mark({class:"cm-json1-presence",attributes:{style:`
148
- background-color: rgba(${y}, 0.75);
147
+ `)}))}),console.log(" generated json1 op: "+JSON.stringify(dI(e,o.changes,o.startState.doc,t,r)))),n.submitOp(dI(e,o.changes,o.startState.doc,t,r)),this.lock=!1)}destroy(){n.off("op",this.handleOp)}});function nue(n,e=n.state){const t=new Set;for(const{from:r,to:i}of n.visibleRanges){let o=r;for(;o<=i;){const s=e.doc.lineAt(o);t.has(s)||t.add(s),o=s.to+1}}return t}function tC(n){const e=n.selection.main.head;return n.doc.lineAt(e)}function pI(n,e){let t=0;e:for(let r=0;r<n.length;r++)switch(n[r]){case" ":case" ":{t+=1;continue e}case" ":{t+=e-t%e;continue e}case"\r":continue e;default:break e}return t}const KO=Tt.define({combine(n){return is(n,{highlightActiveBlock:!0,hideFirstIndent:!1,markerType:"fullScope",thickness:1})}});class rue{constructor(e,t,r,i){this.lines=e,this.state=t,this.map=new Map,this.unitWidth=r,this.markerType=i;for(const o of this.lines)this.add(o);this.state.facet(KO).highlightActiveBlock&&this.findAndSetActiveLines()}has(e){return this.map.has(typeof e=="number"?e:e.number)}get(e){const t=this.map.get(typeof e=="number"?e:e.number);if(!t)throw new Error("Line not found in indentation map");return t}set(e,t,r){const i=!e.text.trim().length,o={line:e,col:t,level:r,empty:i};return this.map.set(o.line.number,o),o}add(e){if(this.has(e))return this.get(e);if(!e.length||!e.text.trim().length){if(e.number===1)return this.set(e,0,0);if(e.number===this.state.doc.lines){const s=this.closestNonEmpty(e,-1);return this.set(e,0,s.level)}const i=this.closestNonEmpty(e,-1),o=this.closestNonEmpty(e,1);return i.level>=o.level&&this.markerType!=="codeOnly"?this.set(e,0,i.level):i.empty&&i.level===0&&o.level!==0?this.set(e,0,0):o.level>i.level?this.set(e,0,i.level+1):this.set(e,0,o.level)}const t=pI(e.text,this.state.tabSize),r=Math.floor(t/this.unitWidth);return this.set(e,t,r)}closestNonEmpty(e,t){let r=e.number+t;for(;t===-1?r>=1:r<=this.state.doc.lines;){if(this.has(r)){const s=this.get(r);if(!s.empty)return s}const o=this.state.doc.line(r);if(o.text.trim().length){const s=pI(o.text,this.state.tabSize),a=Math.floor(s/this.unitWidth);return this.set(o,s,a)}r+=t}const i=this.state.doc.line(t===-1?1:this.state.doc.lines);return this.set(i,0,0)}findAndSetActiveLines(){const e=tC(this.state);if(!this.has(e))return;let t=this.get(e);if(this.has(t.line.number+1)){const o=this.get(t.line.number+1);o.level>t.level&&(t=o)}if(this.has(t.line.number-1)){const o=this.get(t.line.number-1);o.level>t.level&&(t=o)}if(t.level===0)return;t.active=t.level;let r,i;for(r=t.line.number;r>1;r--){if(!this.has(r-1))continue;const o=this.get(r-1);if(o.level<t.level)break;o.active=t.level}for(i=t.line.number;i<this.state.doc.lines;i++){if(!this.has(i+1))continue;const o=this.get(i+1);if(o.level<t.level)break;o.active=t.level}}}function iue(n){const e={light:"#F0F1F2",dark:"#2B3245",activeLight:"#E4E5E6",activeDark:"#3C445C"};let t=e;return n&&(t=Object.assign(Object.assign({},e),n)),ht.baseTheme({"&light":{"--indent-marker-bg-color":t.light,"--indent-marker-active-bg-color":t.activeLight},"&dark":{"--indent-marker-bg-color":t.dark,"--indent-marker-active-bg-color":t.activeDark},".cm-line":{position:"relative"},".cm-indent-markers::before":{content:'""',position:"absolute",top:0,left:"2px",right:0,bottom:0,background:"var(--indent-markers)",pointerEvents:"none",zIndex:"-1"}})}function ny(n,e,t,r,i){return`${`repeating-linear-gradient(to right, var(${n}) 0 ${e}px, transparent ${e}px ${t}ch)`} ${r*t}.5ch/calc(${t*i}ch - 1px) no-repeat`}function oue(n,e,t,r,i){const{level:o,active:s}=n;if(i=i??r,t&&o===0)return[];const a=t?1:0,l=[];if(s!==void 0){const u=s-a-1;u>0&&l.push(ny("--indent-marker-bg-color",r,e,a,u)),l.push(ny("--indent-marker-active-bg-color",i,e,s-1,1)),s!==o&&l.push(ny("--indent-marker-bg-color",r,e,s,o-s))}else l.push(ny("--indent-marker-bg-color",r,e,a,o-a));return l.join(",")}class sue{constructor(e){this.view=e,this.unitWidth=wd(e.state),this.currentLineNumber=tC(e.state).number,this.generate(e.state)}update(e){const t=wd(e.state),r=t!==this.unitWidth;r&&(this.unitWidth=t);const i=tC(e.state).number,o=i!==this.currentLineNumber;this.currentLineNumber=i;const s=e.state.facet(KO).highlightActiveBlock&&o;(e.docChanged||e.viewportChanged||r||s)&&this.generate(e.state)}generate(e){const t=new yl,r=nue(this.view,e),{hideFirstIndent:i,markerType:o,thickness:s,activeThickness:a}=e.facet(KO),l=new rue(r,e,this.unitWidth,o);for(const u of r){const c=l.get(u.number);if(!c?.level)continue;const f=oue(c,this.unitWidth,i,s,a);t.add(u.from,u.from,Rt.line({class:"cm-indent-markers",attributes:{style:`--indent-markers: ${f}`}}))}this.decorations=t.finish()}}function aue(n={}){return[KO.of(n),iue(n.colors),ir.fromClass(sue,{decorations:e=>e.decorations})]}const HB=n=>e=>{const t=n==="down";let r=e.state.selection;for(const i of r.ranges)r=r.addRange(e.moveVertically(i,t));return e.dispatch({selection:r}),!0},lue=HB("up"),uue=HB("down"),cue=n=>{let e=null;for(const t of n.state.selection.ranges)if(!t.empty)for(let r=t.from;r<=t.to;){const i=n.state.doc.lineAt(r),o=Math.min(i.to,t.to);e?e=e.addRange(Ue.range(o,o)):e=Ue.single(o),r=i.to+1}return e?(n.dispatch({selection:e}),!0):!1},fue=[{key:"Ctrl-Space",run:LP},{key:"Escape",run:iU},{key:"ArrowDown",run:pu(!0)},{key:"ArrowUp",run:pu(!1)},{key:"PageDown",run:pu(!0,"page")},{key:"PageUp",run:pu(!1,"page")},{key:"Enter",run:QP},{key:"Tab",run:QP},{key:"Mod-f",run:K4,scope:"editor search-panel"},{key:"Escape",run:J4,scope:"editor search-panel"},{key:"Alt-Enter",run:X4,scope:"editor search-panel"},{key:"Mod-Alt-Enter",run:Y4,scope:"editor search-panel"},{key:"Ctrl-g",run:Rne},{key:"Mod-d",run:Une,preventDefault:!0},{key:"Shift-Mod-l",run:Hne},{key:"Enter",run:WD,shift:WD},{key:"ArrowLeft",run:xD,shift:RD,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:sne,shift:dne},{key:"ArrowRight",run:PD,shift:AD,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:ane,shift:hne},{key:"ArrowUp",run:CD,shift:MD,preventDefault:!0},{key:"ArrowDown",run:TD,shift:$D,preventDefault:!0},{key:"Home",run:ED,shift:LD},{mac:"Cmd-ArrowLeft",run:ED,shift:LD},{key:"Mod-Home",run:jD,shift:FD},{mac:"Cmd-ArrowUp",run:jD,shift:FD},{key:"PageUp",run:jw,shift:DD},{mac:"Ctrl-ArrowUp",run:jw,shift:DD},{key:"PageDown",run:Nw,shift:ID},{mac:"Ctrl-ArrowDown",run:Nw,shift:ID},{key:"End",run:_D,shift:QD},{mac:"Cmd-ArrowRight",run:_D,shift:QD},{key:"Mod-Alt-ArrowUp",linux:"Shift-Alt-ArrowUp",run:lue,preventDefault:!0},{key:"Mod-Alt-ArrowDown",linux:"Shift-Alt-ArrowDown",run:uue,preventDefault:!0},{key:"Shift-Alt-i",run:cue},{key:"Mod-End",run:ND,shift:qD},{mac:"Cmd-ArrowDown",run:ND,shift:qD},{key:"Mod-a",run:gne},{key:"Backspace",run:jre},{key:"Backspace",run:Fw,shift:Fw},{key:"Delete",run:UD},{key:"Mod-Backspace",mac:"Alt-Backspace",run:BD},{key:"Mod-Delete",mac:"Alt-Delete",run:vne},{mac:"Mod-Backspace",run:One},{mac:"Mod-Delete",run:VD},{mac:"Ctrl-b",run:xD,shift:RD,preventDefault:!0},{mac:"Ctrl-f",run:PD,shift:AD},{mac:"Ctrl-p",run:CD,shift:MD},{mac:"Ctrl-n",run:TD,shift:$D},{mac:"Ctrl-a",run:lne,shift:pne},{mac:"Ctrl-e",run:une,shift:mne},{mac:"Ctrl-d",run:UD},{mac:"Ctrl-h",run:Fw},{mac:"Ctrl-k",run:VD},{mac:"Ctrl-Alt-h",run:BD},{mac:"Ctrl-o",run:bne},{mac:"Ctrl-t",run:Sne},{mac:"Ctrl-v",run:Nw},{mac:"Alt-v",run:jw},{key:"Shift-Mod-k",run:Cne},{key:"Alt-ArrowDown",run:kne},{key:"Alt-ArrowUp",run:wne},{win:"Shift-Alt-ArrowDown",mac:"Shift-Alt-ArrowDown",run:Pne},{win:"Shift-Alt-ArrowUp",mac:"Shift-Alt-ArrowUp",run:xne},{key:"Mod-l",run:yne,preventDefault:!0},{key:"Shift-Mod-\\",run:fne},{key:"Tab",run:ZD,shift:zD,preventDefault:!0},{key:"Mod-[",run:zD},{key:"Mod-]",run:ZD},{key:"Ctrl-Shift-[",mac:"Cmd-Alt-[",run:Kee},{key:"Ctrl-Shift-]",mac:"Cmd-Alt-]",run:Jee},{key:"Mod-k Mod-0",run:ete},{key:"Mod-k Mod-j",run:tte},{key:"Mod-k Mod-c",run:Vte},{key:"Mod-k Mod-u",run:Wte},{key:"Mod-/",run:Ute},{key:"Shift-Alt-a",run:Zte},{key:"Mod-z",run:C4,preventDefault:!0},{key:"Mod-y",run:$P,preventDefault:!0},{key:"Mod-Shift-z",run:$P,preventDefault:!0},{key:"Mod-u",run:Jte,preventDefault:!0},{key:"Mod-Shift-m",run:Hre},{key:"F8",run:Gre}],due=({path:n,localPresence:e,usernameRef:t})=>ht.updateListener.of(r=>{if(r.selectionSet){const i=r.state.selection.ranges[0],{from:o,to:s}=i,a={start:[...n,o],end:[...n,s],username:t.current};e.submit(a,l=>{if(l)throw l})}});var pn=function(n,e,t){if(!e.has(n))throw new TypeError("attempted to set private field on non-instance");return e.set(n,t),t},It=function(n,e){if(!e.has(n))throw new TypeError("attempted to get private field on non-instance");return e.get(n)},Gl,hc,Us,If,up,pa,ma,ga,ya,va,Oa,ba,Sa,pc,Qf,Kl,eO,Jl;const hue=function(n){var e=131,t=137,r=0;n+="x";var i=Math.floor(9007199254740991/t);for(let o=0;o<n.length;o++)r>i&&(r=Math.floor(r/t)),r=r*e+n.charCodeAt(o);return r},jt="0123456789abcdef".split(""),pue=[-2147483648,8388608,32768,128],Ns=[24,16,8,0],ry=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],wi=[];class mue{constructor(e=!1,t=!1){Gl.set(this,void 0),hc.set(this,void 0),Us.set(this,void 0),If.set(this,void 0),up.set(this,void 0),pa.set(this,void 0),ma.set(this,void 0),ga.set(this,void 0),ya.set(this,void 0),va.set(this,void 0),Oa.set(this,void 0),ba.set(this,void 0),Sa.set(this,void 0),pc.set(this,void 0),Qf.set(this,void 0),Kl.set(this,void 0),eO.set(this,0),Jl.set(this,void 0),this.init(e,t)}init(e,t){t?(wi[0]=wi[16]=wi[1]=wi[2]=wi[3]=wi[4]=wi[5]=wi[6]=wi[7]=wi[8]=wi[9]=wi[10]=wi[11]=wi[12]=wi[13]=wi[14]=wi[15]=0,pn(this,hc,wi)):pn(this,hc,[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),e?(pn(this,pa,3238371032),pn(this,ma,914150663),pn(this,ga,812702999),pn(this,ya,4144912697),pn(this,va,4290775857),pn(this,Oa,1750603025),pn(this,ba,1694076839),pn(this,Sa,3204075428)):(pn(this,pa,1779033703),pn(this,ma,3144134277),pn(this,ga,1013904242),pn(this,ya,2773480762),pn(this,va,1359893119),pn(this,Oa,2600822924),pn(this,ba,528734635),pn(this,Sa,1541459225)),pn(this,Gl,pn(this,Jl,pn(this,Us,pn(this,Qf,0)))),pn(this,If,pn(this,pc,!1)),pn(this,up,!0),pn(this,Kl,e)}update(e){if(It(this,If))return this;let t;e instanceof ArrayBuffer?t=new Uint8Array(e):t=e;let r=0;const i=t.length,o=It(this,hc);for(;r<i;){let s;if(It(this,pc)&&(pn(this,pc,!1),o[0]=It(this,Gl),o[16]=o[1]=o[2]=o[3]=o[4]=o[5]=o[6]=o[7]=o[8]=o[9]=o[10]=o[11]=o[12]=o[13]=o[14]=o[15]=0),typeof t!="string")for(s=It(this,Jl);r<i&&s<64;++r)o[s>>2]|=t[r]<<Ns[s++&3];else for(s=It(this,Jl);r<i&&s<64;++r){let a=t.charCodeAt(r);a<128?o[s>>2]|=a<<Ns[s++&3]:a<2048?(o[s>>2]|=(192|a>>6)<<Ns[s++&3],o[s>>2]|=(128|a&63)<<Ns[s++&3]):a<55296||a>=57344?(o[s>>2]|=(224|a>>12)<<Ns[s++&3],o[s>>2]|=(128|a>>6&63)<<Ns[s++&3],o[s>>2]|=(128|a&63)<<Ns[s++&3]):(a=65536+((a&1023)<<10|t.charCodeAt(++r)&1023),o[s>>2]|=(240|a>>18)<<Ns[s++&3],o[s>>2]|=(128|a>>12&63)<<Ns[s++&3],o[s>>2]|=(128|a>>6&63)<<Ns[s++&3],o[s>>2]|=(128|a&63)<<Ns[s++&3])}pn(this,eO,s),pn(this,Us,It(this,Us)+(s-It(this,Jl))),s>=64?(pn(this,Gl,o[16]),pn(this,Jl,s-64),this.hash(),pn(this,pc,!0)):pn(this,Jl,s)}return It(this,Us)>4294967295&&(pn(this,Qf,It(this,Qf)+(It(this,Us)/4294967296<<0)),pn(this,Us,It(this,Us)%4294967296)),this}finalize(){if(It(this,If))return;pn(this,If,!0);const e=It(this,hc),t=It(this,eO);e[16]=It(this,Gl),e[t>>2]|=pue[t&3],pn(this,Gl,e[16]),t>=56&&(It(this,pc)||this.hash(),e[0]=It(this,Gl),e[16]=e[1]=e[2]=e[3]=e[4]=e[5]=e[6]=e[7]=e[8]=e[9]=e[10]=e[11]=e[12]=e[13]=e[14]=e[15]=0),e[14]=It(this,Qf)<<3|It(this,Us)>>>29,e[15]=It(this,Us)<<3,this.hash()}hash(){let e=It(this,pa),t=It(this,ma),r=It(this,ga),i=It(this,ya),o=It(this,va),s=It(this,Oa),a=It(this,ba),l=It(this,Sa);const u=It(this,hc);let c,f,d,p,m,y,v,O,S,w;for(let k=16;k<64;++k)p=u[k-15],c=(p>>>7|p<<25)^(p>>>18|p<<14)^p>>>3,p=u[k-2],f=(p>>>17|p<<15)^(p>>>19|p<<13)^p>>>10,u[k]=u[k-16]+c+u[k-7]+f<<0;w=t&r;for(let k=0;k<64;k+=4)It(this,up)?(It(this,Kl)?(v=300032,p=u[0]-1413257819,l=p-150054599<<0,i=p+24177077<<0):(v=704751109,p=u[0]-210244248,l=p-1521486534<<0,i=p+143694565<<0),pn(this,up,!1)):(c=(e>>>2|e<<30)^(e>>>13|e<<19)^(e>>>22|e<<10),f=(o>>>6|o<<26)^(o>>>11|o<<21)^(o>>>25|o<<7),v=e&t,d=v^e&r^w,y=o&s^~o&a,p=l+f+y+ry[k]+u[k],m=c+d,l=i+p<<0,i=p+m<<0),c=(i>>>2|i<<30)^(i>>>13|i<<19)^(i>>>22|i<<10),f=(l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7),O=i&e,d=O^i&t^v,y=l&o^~l&s,p=a+f+y+ry[k+1]+u[k+1],m=c+d,a=r+p<<0,r=p+m<<0,c=(r>>>2|r<<30)^(r>>>13|r<<19)^(r>>>22|r<<10),f=(a>>>6|a<<26)^(a>>>11|a<<21)^(a>>>25|a<<7),S=r&i,d=S^r&e^O,y=a&l^~a&o,p=s+f+y+ry[k+2]+u[k+2],m=c+d,s=t+p<<0,t=p+m<<0,c=(t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10),f=(s>>>6|s<<26)^(s>>>11|s<<21)^(s>>>25|s<<7),w=t&r,d=w^t&i^S,y=s&a^~s&l,p=o+f+y+ry[k+3]+u[k+3],m=c+d,o=e+p<<0,e=p+m<<0;pn(this,pa,It(this,pa)+e<<0),pn(this,ma,It(this,ma)+t<<0),pn(this,ga,It(this,ga)+r<<0),pn(this,ya,It(this,ya)+i<<0),pn(this,va,It(this,va)+o<<0),pn(this,Oa,It(this,Oa)+s<<0),pn(this,ba,It(this,ba)+a<<0),pn(this,Sa,It(this,Sa)+l<<0)}hex(){this.finalize();const e=It(this,pa),t=It(this,ma),r=It(this,ga),i=It(this,ya),o=It(this,va),s=It(this,Oa),a=It(this,ba),l=It(this,Sa);let u=jt[e>>28&15]+jt[e>>24&15]+jt[e>>20&15]+jt[e>>16&15]+jt[e>>12&15]+jt[e>>8&15]+jt[e>>4&15]+jt[e&15]+jt[t>>28&15]+jt[t>>24&15]+jt[t>>20&15]+jt[t>>16&15]+jt[t>>12&15]+jt[t>>8&15]+jt[t>>4&15]+jt[t&15]+jt[r>>28&15]+jt[r>>24&15]+jt[r>>20&15]+jt[r>>16&15]+jt[r>>12&15]+jt[r>>8&15]+jt[r>>4&15]+jt[r&15]+jt[i>>28&15]+jt[i>>24&15]+jt[i>>20&15]+jt[i>>16&15]+jt[i>>12&15]+jt[i>>8&15]+jt[i>>4&15]+jt[i&15]+jt[o>>28&15]+jt[o>>24&15]+jt[o>>20&15]+jt[o>>16&15]+jt[o>>12&15]+jt[o>>8&15]+jt[o>>4&15]+jt[o&15]+jt[s>>28&15]+jt[s>>24&15]+jt[s>>20&15]+jt[s>>16&15]+jt[s>>12&15]+jt[s>>8&15]+jt[s>>4&15]+jt[s&15]+jt[a>>28&15]+jt[a>>24&15]+jt[a>>20&15]+jt[a>>16&15]+jt[a>>12&15]+jt[a>>8&15]+jt[a>>4&15]+jt[a&15];return It(this,Kl)||(u+=jt[l>>28&15]+jt[l>>24&15]+jt[l>>20&15]+jt[l>>16&15]+jt[l>>12&15]+jt[l>>8&15]+jt[l>>4&15]+jt[l&15]),u}toString(){return this.hex()}digest(){this.finalize();const e=It(this,pa),t=It(this,ma),r=It(this,ga),i=It(this,ya),o=It(this,va),s=It(this,Oa),a=It(this,ba),l=It(this,Sa),u=[e>>24&255,e>>16&255,e>>8&255,e&255,t>>24&255,t>>16&255,t>>8&255,t&255,r>>24&255,r>>16&255,r>>8&255,r&255,i>>24&255,i>>16&255,i>>8&255,i&255,o>>24&255,o>>16&255,o>>8&255,o&255,s>>24&255,s>>16&255,s>>8&255,s&255,a>>24&255,a>>16&255,a>>8&255,a&255];return It(this,Kl)||u.push(l>>24&255,l>>16&255,l>>8&255,l&255),u}array(){return this.digest()}arrayBuffer(){this.finalize();const e=new ArrayBuffer(It(this,Kl)?28:32),t=new DataView(e);return t.setUint32(0,It(this,pa)),t.setUint32(4,It(this,ma)),t.setUint32(8,It(this,ga)),t.setUint32(12,It(this,ya)),t.setUint32(16,It(this,va)),t.setUint32(20,It(this,Oa)),t.setUint32(24,It(this,ba)),It(this,Kl)||t.setUint32(28,It(this,Sa)),e}}Gl=new WeakMap,hc=new WeakMap,Us=new WeakMap,If=new WeakMap,up=new WeakMap,pa=new WeakMap,ma=new WeakMap,ga=new WeakMap,ya=new WeakMap,va=new WeakMap,Oa=new WeakMap,ba=new WeakMap,Sa=new WeakMap,pc=new WeakMap,Qf=new WeakMap,Kl=new WeakMap,eO=new WeakMap,Jl=new WeakMap;function gue(n){const e=new mue;return e.update(n),parseInt(e.hex().substring(0,8),16)}const yue=function(n){var e="#";return n.forEach(function(t){t<16&&(e+=0),e+=t.toString(16)}),e},vue=function(n,e,t){n/=360;var r=t<.5?t*(1+e):t+e-t*e,i=2*t-r;return[n+1/3,n,n-1/3].map(function(o){return o<0&&o++,o>1&&o--,o<1/6?o=i+(r-i)*6*o:o<.5?o=r:o<2/3?o=i+(r-i)*6*(2/3-o):o=i,Math.round(o*255)})};class Oue{constructor(e={}){const[t,r]=[e.lightness,e.saturation].map(function(i){return i=i!==void 0?i:[.35,.5,.65],Array.isArray(i)?i.concat():[i]});this.L=t,this.S=r,typeof e.hue=="number"&&(e.hue={min:e.hue,max:e.hue}),typeof e.hue=="object"&&!Array.isArray(e.hue)&&(e.hue=[e.hue]),typeof e.hue>"u"&&(e.hue=[]),this.hueRanges=e.hue.map(function(i){return{min:typeof i.min>"u"?0:i.min,max:typeof i.max>"u"?360:i.max}}),this.hash=gue,typeof e.hash=="function"&&(this.hash=e.hash),e.hash==="bkdr"&&(this.hash=hue)}hsl(e){var t,r,i,o=this.hash(e),s=727;if(this.hueRanges.length){const a=this.hueRanges[o%this.hueRanges.length];t=o/this.hueRanges.length%s*(a.max-a.min)/s+a.min}else t=o%359;return o=Math.ceil(o/360),r=this.S[o%this.S.length],o=Math.ceil(o/this.S.length),i=this.L[o%this.L.length],[t,r,i]}rgb(e){var t=this.hsl(e);return vue.apply(this,t)}hex(e){var t=this.rgb(e);return yue(t)}}const GB=n=>new Oue({lightness:.75}).rgb(n).join(","),bue=({path:n,docPresence:e,enableAutoFollowRef:t})=>[ir.fromClass(class{decorations;cursorPosition={};constructor(r){this.decorations=Vn.of([]);const i={};e.on("receive",(o,s)=>{s?wue(n,s)?i[o]=s:(delete i[o],delete this.cursorPosition[o]):(delete i[o],delete this.cursorPosition[o]);const a=[];for(const l of Object.keys(i)){const u=i[l],{start:c,end:f}=u,d=+c[c.length-1],p=+f[f.length-1],m=GB(u.username),{username:y}=u;a.push({from:d,to:d,value:Rt.widget({side:-1,block:!1,widget:new kue(""+Math.random(),m,y)})}),d!==p&&a.push({from:d,to:p,value:Rt.mark({class:"cm-json1-presence",attributes:{style:`
148
+ background-color: rgba(${m}, 0.75);
149
149
  mix-blend-mode: luminosity;
150
- `}})}),r.state.doc.length>=p&&(this.cursorPosition[u]=p)}this.decorations=Rt.set(l,!0),setTimeout(()=>{r.dispatch({annotations:[Sue.of(!0)]})},0),t.current&&this.scrollToCursor(r)})}scrollToCursor(r){for(const i in this.cursorPosition){const o=this.cursorPosition[i];r.dispatch({effects:ht.scrollIntoView(o)})}}},{decorations:r=>r.decorations}),xue],Sue=Fa.define(),wue=(n,e)=>{for(let t=0;t<n.length;t++)if(n[t]!==e.start[t])return!1;return!0};class kue extends os{id;color;username;timeout;constructor(e,t,r){super(),this.id=e,this.color=t,this.username=r}eq(e){return e.id===this.id}toDOM(){const e=document.createElement("span");e.setAttribute("aria-hidden","true"),e.className="cm-json1-presence";const t=document.createElement("div");e.appendChild(t),t.style.borderLeft=`1px solid rgba(${this.color})`;const r=document.createElement("div");return r.className="remote-cursor-username",r.style.top="-20px",r.style.height="20px",r.style.width=`${this.username.length*12}px`,r.style.backgroundColor=`rgba(${this.color})`,r.style.color="black",r.appendChild(document.createTextNode(this.username)),e.appendChild(r),this.timeout=window.setTimeout(()=>{r.style.opacity="0.3"},2e3),e}ignoreEvent(){return!1}}const xue=ht.baseTheme({".cm-json1-presence":{position:"relative"},".cm-json1-presence > div":{position:"absolute",top:"0",bottom:"0",left:"0",right:"0"}}),KB=qr.define({create:()=>null,update:(n,e)=>{for(const t of e.effects)if(t.is(nC))return t.value;if(!n)return null;if(!e.changes.empty){const t=e.changes.mapPos(n.pos,-1,mi.TrackDel),r=e.changes.mapPos(n.pos+n.text.length,-1,mi.TrackDel);return t===null||r===null||e.newDoc.sliceString(t,r)!==n.text?null:Object.assign(Object.assign({},n),{pos:t})}return n},provide:n=>[ht.decorations.from(n,e=>{if(!e)return Rt.none;const t=e.pos,r=e.pos+e.text.length,i=e.rule.className;return Rt.set(Pue({className:i}).range(t,r))}),ht.contentAttributes.from(n,e=>!e||!e.rule.cursor?{style:""}:{style:`cursor: ${e.rule.cursor}`})]}),nC=hn.define(),Pue=n=>{var e;return Rt.mark({class:`cm-interact ${(e=n?.className)!==null&&e!==void 0?e:""}`})},Cue=ht.theme({".cm-interact":{background:"rgba(128, 128, 255, 0.2)",borderRadius:"4px"}}),JB=Tt.define(),eV=Tt.define({combine:n=>n[n.length-1]}),Tue=ir.define(n=>({target:null,dragging:!1,mouseX:0,mouseY:0,getMatch(){const e=n.state.facet(JB),t=n.posAtCoords({x:this.mouseX,y:this.mouseY});if(!t)return null;const r=n.state.doc.lineAt(t),i=t-r.from;let o=null;for(const s of e)for(const a of r.text.matchAll(s.regexp)){if(a.index===void 0)continue;const l=a[0];if(!l)continue;const u=a.index,c=a.index+l.length;i<u||i>c||(!o||l.length<o.text.length)&&(o={rule:s,pos:r.from+u,text:l})}return o},updateText(e){return t=>{n.dispatch({effects:nC.of(Object.assign(Object.assign({},e),{text:t})),changes:{from:e.pos,to:e.pos+e.text.length,insert:t}})}},setTarget(e){this.target=e,n.dispatch({effects:nC.of(e)})},isModKeyDown(e){const t=n.state.facet(eV),r=!!window.navigator&&window.navigator.userAgent.includes("Macintosh");switch(t){case"alt":return e.altKey;case"shift":return e.shiftKey;case"ctrl":return e.ctrlKey;case"meta":return e.metaKey;case"mod":return r?e.metaKey:e.ctrlKey}throw new Error(`Invalid mod key: ${t}`)},update(e){const t=e.state.field(KB,!1);t!==void 0&&this.target!==t&&(this.target=t,t===null&&this.endDrag())},startDrag(e){this.dragging||this.target&&(this.dragging=!0,this.target.rule.onDragStart&&this.target.rule.onDragStart(this.target.text,this.updateText(this.target),e))},endDrag(){var e;this.dragging&&(this.dragging=!1,!((e=this.target)===null||e===void 0)&&e.rule.onDragEnd&&this.target.rule.onDragEnd(this.target.text,this.updateText(this.target)))}}),{eventHandlers:{mousedown(n,e){this.isModKeyDown(n)&&this.target&&(n.preventDefault(),this.target.rule.onClick&&this.target.rule.onClick(this.target.text,t=>{this.target&&this.updateText(this.target)(t)},n),this.target.rule.onDrag&&this.startDrag(n))},mousemove(n,e){if(this.mouseX=n.clientX,this.mouseY=n.clientY,!this.isModKeyDown(n)){this.target&&this.setTarget(null);return}this.target&&this.dragging?this.target.rule.onDrag&&this.target.rule.onDrag(this.target.text,this.updateText(this.target),n):this.setTarget(this.getMatch())},mouseup(n,e){this.endDrag(),this.target&&!this.isModKeyDown(n)&&this.setTarget(null),this.isModKeyDown(n)&&this.setTarget(this.getMatch())},mouseleave(n,e){this.endDrag(),this.target&&this.setTarget(null)},keydown(n,e){!this.target&&this.isModKeyDown(n)&&this.setTarget(this.getMatch())},keyup(n,e){this.target&&!this.isModKeyDown(n)&&(this.endDrag(),this.setTarget(null))}}}),_ue=(n={})=>{var e,t;return[KB,Cue,Tue,eV.of((e=n.key)!==null&&e!==void 0?e:"alt"),((t=n.rules)!==null&&t!==void 0?t:[]).map(r=>JB.of(r))]},Eue=/https?:\/\/[^\s'")]*([^\s'",;.]|\([^\s'")]*\)|\b)/g,Rue={regexp:Eue,cursor:"pointer",onClick:n=>{window.open(n)}},tV=/#[0-9A-Fa-f]{6}/g,Aue=n=>({regexp:tV,cursor:"pointer",onClick(e,t,r){const i=e,o=document.createElement("input");o.type="color",o.value=i.toLowerCase();const s=i.toUpperCase()===i,a=l=>{const u=l.target;u.value&&t(s?u.value.toUpperCase():u.value),n&&n()};o.addEventListener("input",a),o.style.position="absolute",o.style.left=`${r.clientX}px`,o.style.top=`${r.clientY}px`,o.style.opacity="0",o.style.height="0",o.style.width="0",o.style.border="none",o.style.padding="0",o.style.margin="0",document.body.appendChild(o),setTimeout(()=>{o.click()},10),o.addEventListener("blur",()=>{document.body.removeChild(o)})}}),Mue=new RegExp("(?<!\\#)-?\\b\\d+\\.?\\d*\\b","g"),$ue=n=>({regexp:Mue,cursor:"ew-resize",onDrag:(e,t,r)=>{const i=Number(e)+r.movementX;isNaN(i)||(t(i.toString()),n&&n())}}),Due=/true|false/g,Iue=n=>({regexp:Due,cursor:"pointer",onClick:(e,t)=>{t(e==="true"?"false":"true"),n&&n()}}),Que=n=>({regexp:/vec2\(-?\b\d+\.?\d*\b\s*(,\s*-?\b\d+\.?\d*\b)?\)/g,cursor:"move",onDrag:(e,t,r)=>{const i=/vec2\((?<x>-?\b\d+\.?\d*\b)\s*(,\s*(?<y>-?\b\d+\.?\d*\b))?\)/.exec(e),o=Number(i?.groups?.x);let s=Number(i?.groups?.y);isNaN(o)||(isNaN(s)&&(s=o),t(`vec2(${o+r.movementX}, ${s-r.movementY})`),n&&n())}});let yc=null;const Lue=n=>({regexp:/rotate\(-?\d*\.?\d*\)/g,cursor:"move",onDragStart(e,t,r){yc={x:r.clientX,y:r.clientY}},onDrag(e,t,r){if(yc==null)return;const i=Math.round(Math.atan2(yc.y-r.clientY,r.clientX-yc.x)*180/Math.PI);t(`rotate(${i})`);const o=new CustomEvent("updateRotateDrag",{detail:i});document.dispatchEvent(o),n&&n()},onDragEnd(){yc=null}}),jue=ir.fromClass(class{view;textPosition;rotation;constructor(n){this.view=n,this.textPosition=null,this.rotation=0,document.addEventListener("updateRotateDrag",e=>{this.textPosition=this.view.posAtCoords(yc,!1),this.rotation=e.detail})}},{decorations:n=>yc===null?Rt.none:Rt.set([{from:n.textPosition,to:n.textPosition,value:Rt.widget({side:-1,widget:new Nue(n.rotation)})}])});class Nue extends os{angle;constructor(e){super(),this.angle=e}toDOM(e){const t=document.createElement("div");t.setAttribute("style","width:20px;height:20px"),t.className="color-circle-parent";const r=document.createElementNS("http://www.w3.org/2000/svg","svg"),i=document.createElementNS("http://www.w3.org/2000/svg","circle");i.setAttributeNS(null,"fill","#808080"),i.setAttributeNS(null,"r","5"),i.setAttributeNS(null,"cx","5"),i.setAttributeNS(null,"cy","5");const o=document.createElementNS("http://www.w3.org/2000/svg","line");return o.setAttributeNS(null,"x1","10"),o.setAttributeNS(null,"x2","5"),o.setAttributeNS(null,"y1","5"),o.setAttributeNS(null,"y2","5"),o.setAttributeNS(null,"stroke","black"),o.setAttributeNS(null,"transform",`rotate(${360-this.angle},5,5)`),r.setAttributeNS(null,"viewBox","0 0 10 10"),r.setAttributeNS(null,"width","20"),r.setAttributeNS(null,"height","20"),r.appendChild(i),r.appendChild(o),t.appendChild(r),t}ignoreEvent(){return!1}}const Fue=n=>({regexp:/\[[ x]\]/g,cursor:"pointer",onClick:(e,t)=>{t(e==="[ ]"?"[x]":"[ ]"),n&&n()}}),que=ht.baseTheme({".color-circle-parent":{display:"inline-block",cursor:"inherit"}});class Uue extends os{color;constructor(e){super(),this.color=e}eq(e){return e.color===this.color}toDOM(){const e=document.createElement("div"),t=20,r=14;e.setAttribute("style",`width:${t}px;height:${t}px;position:relative;`),e.className="color-circle-parent";const i=document.createElementNS("http://www.w3.org/2000/svg","svg"),o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttributeNS(null,"fill",this.color.replace(/["']/g,"")),o.setAttributeNS(null,"stroke","white"),o.setAttributeNS(null,"stroke-width","0.75"),o.setAttributeNS(null,"r",""+r/2),o.setAttributeNS(null,"cx",""+t/2),o.setAttributeNS(null,"cy",""+(t/2-1)),i.setAttributeNS(null,"width",""+t),i.setAttributeNS(null,"height",""+t),i.appendChild(o),e.appendChild(i);const s=document.createElement("div");s.className="tooltip_hover_circle",s.innerHTML=`<strong>Alt + Click on a hex color</strong><br />
150
+ `}})}),r.state.doc.length>=d?this.cursorPosition[l]=d:delete this.cursorPosition[l]}this.decorations=Rt.set(a,!0),setTimeout(()=>{r.dispatch({annotations:[Sue.of(!0)]})},0),t.current&&this.scrollToCursor(r)})}scrollToCursor(r){for(const i in this.cursorPosition){const o=this.cursorPosition[i];r.dispatch({effects:ht.scrollIntoView(o)})}}},{decorations:r=>r.decorations}),xue],Sue=Fa.define(),wue=(n,e)=>{for(let t=0;t<n.length;t++)if(n[t]!==e.start[t])return!1;return!0};class kue extends os{id;color;username;timeout;constructor(e,t,r){super(),this.id=e,this.color=t,this.username=r}eq(e){return e.id===this.id}toDOM(){const e=document.createElement("span");e.setAttribute("aria-hidden","true"),e.className="cm-json1-presence";const t=document.createElement("div");e.appendChild(t),t.style.borderLeft=`1px solid rgba(${this.color})`;const r=document.createElement("div");return r.className="remote-cursor-username",r.style.top="-20px",r.style.height="20px",r.style.width=`${this.username.length*12}px`,r.style.backgroundColor=`rgba(${this.color})`,r.style.color="black",r.appendChild(document.createTextNode(this.username)),e.appendChild(r),this.timeout=window.setTimeout(()=>{r.style.opacity="0.3"},2e3),e}ignoreEvent(){return!1}}const xue=ht.baseTheme({".cm-json1-presence":{position:"relative"},".cm-json1-presence > div":{position:"absolute",top:"0",bottom:"0",left:"0",right:"0"}}),KB=qr.define({create:()=>null,update:(n,e)=>{for(const t of e.effects)if(t.is(nC))return t.value;if(!n)return null;if(!e.changes.empty){const t=e.changes.mapPos(n.pos,-1,mi.TrackDel),r=e.changes.mapPos(n.pos+n.text.length,-1,mi.TrackDel);return t===null||r===null||e.newDoc.sliceString(t,r)!==n.text?null:Object.assign(Object.assign({},n),{pos:t})}return n},provide:n=>[ht.decorations.from(n,e=>{if(!e)return Rt.none;const t=e.pos,r=e.pos+e.text.length,i=e.rule.className;return Rt.set(Pue({className:i}).range(t,r))}),ht.contentAttributes.from(n,e=>!e||!e.rule.cursor?{style:""}:{style:`cursor: ${e.rule.cursor}`})]}),nC=hn.define(),Pue=n=>{var e;return Rt.mark({class:`cm-interact ${(e=n?.className)!==null&&e!==void 0?e:""}`})},Cue=ht.theme({".cm-interact":{background:"rgba(128, 128, 255, 0.2)",borderRadius:"4px"}}),JB=Tt.define(),eV=Tt.define({combine:n=>n[n.length-1]}),Tue=ir.define(n=>({target:null,dragging:!1,mouseX:0,mouseY:0,getMatch(){const e=n.state.facet(JB),t=n.posAtCoords({x:this.mouseX,y:this.mouseY});if(!t)return null;const r=n.state.doc.lineAt(t),i=t-r.from;let o=null;for(const s of e)for(const a of r.text.matchAll(s.regexp)){if(a.index===void 0)continue;const l=a[0];if(!l)continue;const u=a.index,c=a.index+l.length;i<u||i>c||(!o||l.length<o.text.length)&&(o={rule:s,pos:r.from+u,text:l})}return o},updateText(e){return t=>{n.dispatch({effects:nC.of(Object.assign(Object.assign({},e),{text:t})),changes:{from:e.pos,to:e.pos+e.text.length,insert:t}})}},setTarget(e){this.target=e,n.dispatch({effects:nC.of(e)})},isModKeyDown(e){const t=n.state.facet(eV),r=!!window.navigator&&window.navigator.userAgent.includes("Macintosh");switch(t){case"alt":return e.altKey;case"shift":return e.shiftKey;case"ctrl":return e.ctrlKey;case"meta":return e.metaKey;case"mod":return r?e.metaKey:e.ctrlKey}throw new Error(`Invalid mod key: ${t}`)},update(e){const t=e.state.field(KB,!1);t!==void 0&&this.target!==t&&(this.target=t,t===null&&this.endDrag())},startDrag(e){this.dragging||this.target&&(this.dragging=!0,this.target.rule.onDragStart&&this.target.rule.onDragStart(this.target.text,this.updateText(this.target),e))},endDrag(){var e;this.dragging&&(this.dragging=!1,!((e=this.target)===null||e===void 0)&&e.rule.onDragEnd&&this.target.rule.onDragEnd(this.target.text,this.updateText(this.target)))}}),{eventHandlers:{mousedown(n,e){this.isModKeyDown(n)&&this.target&&(n.preventDefault(),this.target.rule.onClick&&this.target.rule.onClick(this.target.text,t=>{this.target&&this.updateText(this.target)(t)},n),this.target.rule.onDrag&&this.startDrag(n))},mousemove(n,e){if(this.mouseX=n.clientX,this.mouseY=n.clientY,!this.isModKeyDown(n)){this.target&&this.setTarget(null);return}this.target&&this.dragging?this.target.rule.onDrag&&this.target.rule.onDrag(this.target.text,this.updateText(this.target),n):this.setTarget(this.getMatch())},mouseup(n,e){this.endDrag(),this.target&&!this.isModKeyDown(n)&&this.setTarget(null),this.isModKeyDown(n)&&this.setTarget(this.getMatch())},mouseleave(n,e){this.endDrag(),this.target&&this.setTarget(null)},keydown(n,e){!this.target&&this.isModKeyDown(n)&&this.setTarget(this.getMatch())},keyup(n,e){this.target&&!this.isModKeyDown(n)&&(this.endDrag(),this.setTarget(null))}}}),_ue=(n={})=>{var e,t;return[KB,Cue,Tue,eV.of((e=n.key)!==null&&e!==void 0?e:"alt"),((t=n.rules)!==null&&t!==void 0?t:[]).map(r=>JB.of(r))]},Eue=/https?:\/\/[^\s'")]*([^\s'",;.]|\([^\s'")]*\)|\b)/g,Rue={regexp:Eue,cursor:"pointer",onClick:n=>{window.open(n)}},tV=/#[0-9A-Fa-f]{6}/g,Aue=n=>({regexp:tV,cursor:"pointer",onClick(e,t,r){const i=e,o=document.createElement("input");o.type="color",o.value=i.toLowerCase();const s=i.toUpperCase()===i,a=l=>{const u=l.target;u.value&&t(s?u.value.toUpperCase():u.value),n&&n()};o.addEventListener("input",a),o.style.position="absolute",o.style.left=`${r.clientX}px`,o.style.top=`${r.clientY}px`,o.style.opacity="0",o.style.height="0",o.style.width="0",o.style.border="none",o.style.padding="0",o.style.margin="0",document.body.appendChild(o),setTimeout(()=>{o.click()},10),o.addEventListener("blur",()=>{document.body.removeChild(o)})}}),Mue=new RegExp("(?<!\\#)-?\\b\\d+\\.?\\d*\\b","g"),$ue=n=>({regexp:Mue,cursor:"ew-resize",onDrag:(e,t,r)=>{const i=Number(e)+r.movementX;isNaN(i)||(t(i.toString()),n&&n())}}),Due=/true|false/g,Iue=n=>({regexp:Due,cursor:"pointer",onClick:(e,t)=>{t(e==="true"?"false":"true"),n&&n()}}),Que=n=>({regexp:/vec2\(-?\b\d+\.?\d*\b\s*(,\s*-?\b\d+\.?\d*\b)?\)/g,cursor:"move",onDrag:(e,t,r)=>{const i=/vec2\((?<x>-?\b\d+\.?\d*\b)\s*(,\s*(?<y>-?\b\d+\.?\d*\b))?\)/.exec(e),o=Number(i?.groups?.x);let s=Number(i?.groups?.y);isNaN(o)||(isNaN(s)&&(s=o),t(`vec2(${o+r.movementX}, ${s-r.movementY})`),n&&n())}});let yc=null;const Lue=n=>({regexp:/rotate\(-?\d*\.?\d*\)/g,cursor:"move",onDragStart(e,t,r){yc={x:r.clientX,y:r.clientY}},onDrag(e,t,r){if(yc==null)return;const i=Math.round(Math.atan2(yc.y-r.clientY,r.clientX-yc.x)*180/Math.PI);t(`rotate(${i})`);const o=new CustomEvent("updateRotateDrag",{detail:i});document.dispatchEvent(o),n&&n()},onDragEnd(){yc=null}}),jue=ir.fromClass(class{view;textPosition;rotation;constructor(n){this.view=n,this.textPosition=null,this.rotation=0,document.addEventListener("updateRotateDrag",e=>{this.textPosition=this.view.posAtCoords(yc,!1),this.rotation=e.detail})}},{decorations:n=>yc===null?Rt.none:Rt.set([{from:n.textPosition,to:n.textPosition,value:Rt.widget({side:-1,widget:new Nue(n.rotation)})}])});class Nue extends os{angle;constructor(e){super(),this.angle=e}toDOM(e){const t=document.createElement("div");t.setAttribute("style","width:20px;height:20px"),t.className="color-circle-parent";const r=document.createElementNS("http://www.w3.org/2000/svg","svg"),i=document.createElementNS("http://www.w3.org/2000/svg","circle");i.setAttributeNS(null,"fill","#808080"),i.setAttributeNS(null,"r","5"),i.setAttributeNS(null,"cx","5"),i.setAttributeNS(null,"cy","5");const o=document.createElementNS("http://www.w3.org/2000/svg","line");return o.setAttributeNS(null,"x1","10"),o.setAttributeNS(null,"x2","5"),o.setAttributeNS(null,"y1","5"),o.setAttributeNS(null,"y2","5"),o.setAttributeNS(null,"stroke","black"),o.setAttributeNS(null,"transform",`rotate(${360-this.angle},5,5)`),r.setAttributeNS(null,"viewBox","0 0 10 10"),r.setAttributeNS(null,"width","20"),r.setAttributeNS(null,"height","20"),r.appendChild(i),r.appendChild(o),t.appendChild(r),t}ignoreEvent(){return!1}}const Fue=n=>({regexp:/\[[ x]\]/g,cursor:"pointer",onClick:(e,t)=>{t(e==="[ ]"?"[x]":"[ ]"),n&&n()}}),que=ht.baseTheme({".color-circle-parent":{display:"inline-block",cursor:"inherit"}});class Uue extends os{color;constructor(e){super(),this.color=e}eq(e){return e.color===this.color}toDOM(){const e=document.createElement("div"),t=20,r=14;e.setAttribute("style",`width:${t}px;height:${t}px;position:relative;`),e.className="color-circle-parent";const i=document.createElementNS("http://www.w3.org/2000/svg","svg"),o=document.createElementNS("http://www.w3.org/2000/svg","circle");o.setAttributeNS(null,"fill",this.color.replace(/["']/g,"")),o.setAttributeNS(null,"stroke","white"),o.setAttributeNS(null,"stroke-width","0.75"),o.setAttributeNS(null,"r",""+r/2),o.setAttributeNS(null,"cx",""+t/2),o.setAttributeNS(null,"cy",""+(t/2-1)),i.setAttributeNS(null,"width",""+t),i.setAttributeNS(null,"height",""+t),i.appendChild(o),e.appendChild(i);const s=document.createElement("div");s.className="tooltip_hover_circle",s.innerHTML=`<strong>Alt + Click on a hex color</strong><br />
151
151
  <div>Open a color picker to modify the color</div>`,e.appendChild(s);let a;return e.addEventListener("mouseenter",l=>{a=window.setTimeout(()=>{s.style.top=`${l.clientY-60}px`,s.style.left=`${l.clientX}px`,s.style.opacity="1"},700)}),e.addEventListener("mouseleave",()=>{clearTimeout(a),s.style.opacity="0"}),e}ignoreEvent(){return!1}}const Bue=[ir.fromClass(class{decorations;view;constructor(n){this.decorations=Vn.of([]),this.view=n}},{decorations:n=>{const e=[],t=n.view.state.doc.iter();let r=t.next(),i=0;for(;!r.done;){if(r.value===`
152
152
  `){i++,r=t.next();continue}const o=r.value.matchAll(tV);let s=o.next();for(;!s.done;){const a=s.value;a.index+=i,e.push(a),s=o.next()}i+=r.value.length,r=t.next()}return Rt.set(e.map(o=>({from:o.index+7,to:o.index+7,value:Rt.widget({side:-1,widget:new Uue(o[0])})})))}}),que],Vue=({onInteract:n,customInteractRules:e})=>{const t=[Aue(n),$ue(n),Fue(n),Iue(n),Que(n),Lue(n),Rue];return e&&t.push(...e),_ue({rules:t})},Wue=[fee(),pee(),MJ(),Kte(),SJ(),CJ(),Xn.allowMultipleSelections.of(!0),Xee(),CT(lte,{fallback:!0}),mte(),Ire(),fU({defaultKeymap:!1}),VJ(),zJ(),jJ(),Dne()];function Zue(){return["red","orange","yellow","green"]}const zue=ir.fromClass(class{decorations;constructor(n){this.decorations=this.getBracketDecorations(n)}update(n){(n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.getBracketDecorations(n.view))}getBracketDecorations(n){const{doc:e}=n.state,t=[],r=[],i=Zue();for(let o=0;o<e.length;o+=1){const s=e.sliceString(o,o+1);if(s==="("||s==="["||s==="{")r.push({type:s,from:o});else if(s===")"||s==="]"||s==="}"){const a=r.pop();if(a&&a.type===this.getMatchingBracket(s)){const u=`rainbow-bracket-${i[r.length%i.length]}`;t.push(Rt.mark({class:u}).range(a.from,a.from+1),Rt.mark({class:u}).range(o,o+1))}}}return t.sort((o,s)=>o.from-s.from||o.startSide-s.startSide),Rt.set(t)}getMatchingBracket(n){switch(n){case")":return"(";case"]":return"[";case"}":return"{";default:return null}}},{decorations:n=>n.decorations});function mI(){return[zue,ht.baseTheme({".rainbow-bracket-red":{color:"white"},".rainbow-bracket-red > span":{color:"white"},".rainbow-bracket-orange":{color:"#FFFFB2"},".rainbow-bracket-orange > span":{color:"#FFFFB2"},".rainbow-bracket-yellow":{color:"#FFB2DA"},".rainbow-bracket-yellow > span":{color:"#FFB2DA"},".rainbow-bracket-green":{color:"#B2FFB2"},".rainbow-bracket-green > span":{color:"#B2FFB2"},".default-bracket":{color:"currentColor"},".default-bracket > span":{color:"currentColor"}})]}function Xue(n,e,t=void 0){let r=()=>{};return(...i)=>(r(),new Promise((o,s)=>{const a=setTimeout(()=>o(n(...i)),e);r=()=>{clearTimeout(a),t!==void 0&&s(t)}}))}var Yue=Object.defineProperty,Hue=(n,e,t)=>e in n?Yue(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,nV=(n,e,t)=>(Hue(n,typeof e!="symbol"?e+"":e,t),t);const Y0=qr.define({create(){return{suggestion:null}},update(n,e){const t=e.effects.find(r=>r.is(rV));if(e.state.doc){if(t&&e.state.doc==t.value.doc)return{suggestion:t.value.text};if(!e.docChanged&&!e.selection)return n}return{suggestion:null}}}),rV=hn.define();function Gue(n,e){const t=n.state.selection.main.head,r=[],i=Rt.widget({widget:new Kue(e),side:1});return r.push(i.range(t)),Rt.set(r)}const t_=Tt.define({combine(n){var e,t;return{acceptOnClick:!!((e=n.at(-1))!=null&&e.acceptOnClick),fetchFn:(t=n.at(-1))==null?void 0:t.fetchFn}}});class Kue extends os{constructor(e){super(),nV(this,"suggestion"),this.suggestion=e}toDOM(e){const t=document.createElement("span");return t.style.opacity="0.4",t.className="cm-inline-suggestion",t.textContent=this.suggestion,t.onclick=r=>this.accept(r,e),t}accept(e,t){var r;if(!t.state.facet(t_).acceptOnClick)return;e.stopPropagation(),e.preventDefault();const i=(r=t.state.field(Y0))==null?void 0:r.suggestion;return i?(t.dispatch({...iV(t.state,i,t.state.selection.main.head,t.state.selection.main.head)}),!0):!1}}const Jue=ir.fromClass(class{async update(n){const e=n.state.doc;if(!n.docChanged||n.transactions.some(i=>i.isUserEvent("input.complete")))return;const t=n.view.state.facet(t_);if(!t.fetchFn){console.error("Unexpected issue in codemirror-copilot: fetchFn was not configured");return}const r=await t.fetchFn(n.state);n.view.dispatch({effects:rV.of({text:r,doc:e})})}}),ece=ir.fromClass(class{constructor(){nV(this,"decorations"),this.decorations=Rt.none}update(n){var e;const t=(e=n.state.field(Y0))==null?void 0:e.suggestion;if(!t){this.decorations=Rt.none;return}this.decorations=Gue(n.view,t)}},{decorations:n=>n.decorations}),tce=Na.highest(Md.of([{key:"Tab",run:n=>{var e;const t=(e=n.state.field(Y0))==null?void 0:e.suggestion;return t?(n.dispatch({...iV(n.state,t,n.state.selection.main.head,n.state.selection.main.head)}),!0):!1}}]));function iV(n,e,t,r){return{...n.changeByRange(i=>{if(i==n.selection.main)return{changes:{from:t,to:r,insert:e},range:Ue.cursor(t+e.length)};const o=r-t;return!i.empty||o&&n.sliceDoc(i.from-o,i.from)!=n.sliceDoc(t,r)?{range:i}:{changes:{from:i.from-o,to:i.from,insert:e},range:Ue.cursor(i.from-o+e.length)}}),userEvent:"input.complete"}}function nce(n){const{delay:e=500,acceptOnClick:t=!0}=n,r=Xue(n.fetchFn,e);return[t_.of({acceptOnClick:t,fetchFn:r}),Y0,Jue,ece,tce]}const gI={};function rce(n){return async function(e){const{from:t,to:r}=e.selection.ranges[0],i=e.doc.toString(),o=i.slice(0,r),s=i.slice(t),a=`${o}<:|:>${s}`,l=gI[a];if(l)return l;const u=await n(o,s);return gI[a]=u,u}}const ice=(n,e=1e3,t=!0)=>nce({fetchFn:rce(n),delay:e,acceptOnClick:t}),oce="/ai-copilot";let l1=!1;const sce=({aiCopilotEndpoint:n=oce})=>ice(async(e,t)=>{if(l1)return"";const r=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prefix:e,suffix:t})});if(!r.ok)return l1=!0,"";const i=await r.json();return i.error?(l1=!0,""):i.text});/**
153
153
  * @license
@@ -217,7 +217,7 @@ ${String(n)}`),new Response(t,{status:500,headers:{"Content-Type":"text/plain"}}
217
217
  *
218
218
  * @license MIT
219
219
  */const hme=Object.freeze(Object.defineProperty({__proto__:null,Await:Nde,BrowserRouter:y7,Form:E_,HashRouter:Whe,HydratedRouter:dme,IDLE_BLOCKER:au,IDLE_FETCHER:J0,IDLE_NAVIGATION:Sp,Link:__,Links:Ihe,MemoryRouter:Qde,Meta:jhe,NavLink:b7,Navigate:Lde,NavigationType:QV,Outlet:C6,PrefetchPageLinks:C_,Route:T6,Router:qu,RouterProvider:Z7,Routes:jde,Scripts:h7,ScrollRestoration:S7,ServerRouter:dpe,StaticRouter:epe,StaticRouterProvider:M_,UNSAFE_DataRouterContext:wl,UNSAFE_DataRouterStateContext:ju,UNSAFE_ErrorResponseImpl:fo,UNSAFE_FetchersContext:Cm,UNSAFE_FrameworkContext:qa,UNSAFE_LocationContext:Fc,UNSAFE_NavigationContext:Io,UNSAFE_RSCDefaultRootErrorBoundary:Wpe,UNSAFE_RemixErrorBoundary:T_,UNSAFE_RouteContext:Qo,UNSAFE_ServerMode:M7,UNSAFE_SingleFetchRedirectSymbol:ea,UNSAFE_ViewTransitionContext:Pm,UNSAFE_WithComponentProps:Vde,UNSAFE_WithErrorBoundaryProps:Zde,UNSAFE_WithHydrateFallbackProps:Wde,UNSAFE_createBrowserHistory:km,UNSAFE_createClientRoutes:Rm,UNSAFE_createClientRoutesWithHMRRevalidationOptOut:a7,UNSAFE_createRouter:Nd,UNSAFE_decodeViaTurboStream:lb,UNSAFE_deserializeErrors:W7,UNSAFE_getHydrationData:F_,UNSAFE_getPatchRoutesOnNavigationFunction:u7,UNSAFE_getTurboStreamSingleFetchDataStrategy:G6,UNSAFE_hydrationRouteProperties:Em,UNSAFE_invariant:qt,UNSAFE_mapRouteProperties:qc,UNSAFE_shouldHydrateRouteLoader:qd,UNSAFE_useFogOFWarDiscovery:c7,UNSAFE_useScrollRestoration:P7,UNSAFE_withComponentProps:E6,UNSAFE_withErrorBoundaryProps:$6,UNSAFE_withHydrateFallbackProps:A6,createBrowserRouter:Uhe,createCookie:Q_,createCookieSessionStorage:Upe,createHashRouter:Bhe,createMemoryRouter:P6,createMemorySessionStorage:Bpe,createPath:co,createRequestHandler:Dpe,createRoutesFromChildren:em,createRoutesFromElements:Ude,createRoutesStub:hpe,createSearchParams:s0,createSession:N_,createSessionStorage:F7,createStaticHandler:rpe,createStaticRouter:$_,data:YV,generatePath:Wfe,href:Vpe,isCookie:L_,isRouteErrorResponse:li,isSession:qpe,matchPath:Ed,matchRoutes:Ro,parsePath:ss,redirect:xm,redirectDocument:HV,renderMatches:Bde,replace:GV,resolvePath:zV,unstable_HistoryRouter:v7,unstable_RSCHydratedRouter:Hpe,unstable_RSCStaticRouter:sme,unstable_RouterContextProvider:Aa,unstable_createCallServer:Zpe,unstable_createContext:qV,unstable_getRSCStream:ume,unstable_routeRSCServerRequest:ome,unstable_setDevServerHooks:Tpe,unstable_usePrompt:Jhe,useActionData:sb,useAsyncError:Rde,useAsyncValue:w6,useBeforeUnload:Ghe,useBlocker:k6,useFetcher:Yhe,useFetchers:Hhe,useFormAction:x7,useHref:p6,useInRouterContext:Nu,useLinkClickHandler:k7,useLoaderData:ob,useLocation:Lo,useMatch:Ode,useMatches:ib,useNavigate:nb,useNavigation:S6,useNavigationType:vde,useOutlet:v6,useOutletContext:Sde,useParams:rb,useResolvedPath:Fd,useRevalidator:_de,useRouteError:_m,useRouteLoaderData:Ede,useRoutes:O6,useSearchParams:Zhe,useSubmit:A_,useViewTransitionState:C7},Symbol.toStringTag,{value:"Module"})),{useSearchParams:pme}=hme,mme=({content:n,openTab:e,setActiveFileId:t,tabList:r,activeFileId:i})=>{const[o,s]=pme(),a=M.useMemo(()=>({file:o.get("file"),tabs:o.get("tabs")}),[o]),l=M.useRef(!1);M.useEffect(()=>{if(l.current||!n)return;const{tabList:f,activeFileId:d}=Pfe({tabStateParams:a,content:n});l.current=!0,f.forEach(e),t(d)},[n,o,t,e,l]);const u=M.useRef(n);M.useEffect(()=>{u.current=n},[n]);const c=M.useRef(s);M.useEffect(()=>{c.current=s},[s]),M.useEffect(()=>{if(!u.current)return;const f=Cfe({tabList:r,activeFileId:i,content:u.current});c.current(d=>{const p=new URLSearchParams(d);return f.file?p.set("file",f.file):p.delete("file"),f.tabs?p.set("tabs",f.tabs):p.delete("tabs"),p})},[r,i])},Uc=(n,e)=>{if(n.id===e)return n;if(n.type==="splitPane")for(const t of n.children){const r=Uc(t,e);if(r)return r}},Eu=({pane:n,activePaneId:e,newTabList:t,newActiveFileId:r})=>n.type==="splitPane"?{...n,children:n.children.map(i=>Eu({pane:i,activePaneId:e,newTabList:t,newActiveFileId:r}))}:n.id===e?{...n,tabList:t!==void 0?t:n.tabList,activeFileId:r!==void 0?r:n.activeFileId}:n,gme=(n,e)=>{if(e.type!=="close_tabs")return n;const{pane:t,activePaneId:r}=n,i=Uc(t,r);if(i.type!=="leafPane")throw new Error("closeTabsReducer: activePane is not a leafPane");const o=i.tabList.filter(l=>!e.fileIdsToClose.includes(l.fileId));if(!e.fileIdsToClose.includes(i.activeFileId))return{...n,pane:Eu({pane:t,activePaneId:r,newTabList:o})};let s=null;const a=i.tabList.findIndex(l=>l.fileId===i.activeFileId);for(let l=a-1;l>=0;l--)if(!e.fileIdsToClose.includes(i.tabList[l].fileId)){s=i.tabList[l].fileId;break}if(!s){for(let l=a+1;l<i.tabList.length;l++)if(!e.fileIdsToClose.includes(i.tabList[l].fileId)){s=i.tabList[l].fileId;break}}return{...n,pane:Eu({pane:t,activePaneId:r,newTabList:o,newActiveFileId:s})}},yme=(n,e)=>{if(e.type!=="open_tab")return n;const{pane:t,activePaneId:r}=n,i=Uc(t,r);if(i.type!=="leafPane")throw new Error("closeTabsReducer: activePane is not a leafPane");const o=i.tabList.findIndex(d=>d.fileId===e.fileId),s=o!==-1,a=s&&i.tabList[o].isTransient,l=i.tabList.findIndex(d=>d.isTransient&&d.fileId!==e.fileId),u={fileId:e.fileId,isTransient:e.isTransient};let c;s?a?c=i.tabList.map(d=>d.fileId===e.fileId?u:d):c=[...i.tabList]:l!==-1?(c=[...i.tabList],c[l]=u):c=[...i.tabList,u];const f=!e.isTransient;return{...n,pane:Eu({pane:t,activePaneId:r,newTabList:c,newActiveFileId:e.fileId}),editorWantsFocus:f}},vme=(n,e)=>{if(e.type!=="set_active_file_id")return n;const{pane:t,activePaneId:r}=n;if(Uc(t,r).type!=="leafPane")throw new Error("closeTabsReducer: activePane is not a leafPane");return{...n,pane:Eu({pane:t,activePaneId:r,newActiveFileId:e.activeFileId})}},Ome=(n,e)=>{if(e.type!=="set_active_file_left")return n;const{pane:t,activePaneId:r}=n,i=Uc(t,r);if(i.type!=="leafPane")throw new Error("closeTabsReducer: activePane is not a leafPane");let o=i.tabList.findIndex(s=>s.fileId===i.activeFileId);return o-=1,o<0&&(o=i.tabList.length-1),{...n,pane:Eu({pane:t,activePaneId:r,newActiveFileId:i.tabList[o].fileId})}},bme=(n,e)=>{if(e.type!=="set_active_file_right")return n;const{pane:t,activePaneId:r}=n,i=Uc(t,r);if(i.type!=="leafPane")throw new Error("closeTabsReducer: activePane is not a leafPane");let o=i.tabList.findIndex(s=>s.fileId===i.activeFileId);return o+=1,o>i.tabList.length-1&&(o=0),{...n,pane:Eu({pane:t,activePaneId:r,newActiveFileId:i.tabList[o].fileId})}},Sme=(n,e)=>e.type==="set_is_settings_open"?{...n,isSettingsOpen:e.value}:n,wme=(n,e)=>e.type==="set_is_doc_open"?{...n,isDocOpen:e.value}:n,kme=(n,e)=>e.type==="set_theme"?{...n,theme:e.themeLabel}:n,xme=(n,e)=>e.type==="editor_no_longer_wants_focus"?{...n,editorWantsFocus:!1}:n,Pme=(n,e)=>e.type==="set_username"?{...n,username:e.username}:n;function Cme(n,e){const t=n.data.files,r=Object.keys(n.data.files);let i={};for(let o=0;o<r.length;o++){const s=t[r[o]];if(t[r[o]].text){const a=s.name,l=s.text.split(`
220
- `),u=[];for(let c=0;c<l.length;c++){const f=l[c].indexOf(e);f!==-1&&u.push({line:c+1,index:f,text:l[c],isClosed:!1})}u.length>0&&(i[r[o]]={name:a,matches:u,visibility:"open"})}}return i}function Tme(n,e,t){return{...n,[e]:{...n[e],visibility:t}}}const _me=(n,e)=>e.type==="set_is_search_open"?{...n,isSearchOpen:e.value}:n,Eme=(n,e)=>e.type==="set_search"?{...n,search:{...n.search,pattern:e.value,results:{},focusedIndex:0,focusedChildIndex:null,focused:!0}}:n,Rme=(n,e)=>e.type==="set_search_results"?{...n,search:{...n.search,pattern:n.search.pattern,results:Cme(e.files,n.search.pattern),focused:n.search.focused}}:n,Ame=(n,e)=>e.type==="set_search_file_visibility"?{...n,search:{...n.search,pattern:n.search.pattern,results:Tme(n.search.results,e.id,e.visibility)}}:n,Mme=(n,e)=>e.type==="hide_search_results_line"?{...n,search:{...n.search,results:{...n.search.results,[e.id]:{...n.search.results[e.id],matches:n.search.results[e.id].matches.filter((t,r)=>t.line!==e.line)}}}}:n,$me=(n,e)=>e.type==="set_active_search_index"?{...n,search:{...n.search,focusedIndex:e.focusedIndex,focusedChildIndex:e.childIndex}}:n,Dme=(n,e)=>e.type==="toggle_search_focused"?{...n,search:{...n.search,focused:!n.search.focused}}:n,Ime=(n,e)=>e.type==="set_is_ai_chat_open"?{...n,isAIChatOpen:e.value,isSearchOpen:e.value?!1:n.isSearchOpen}:n,Qme=(n,e)=>e.type==="toggle_ai_chat_focused"?{...n,aiChatFocused:!n.aiChatFocused}:n,Lme=(n,e)=>e.type==="toggle_auto_follow"?{...n,enableAutoFollow:!n.enableAutoFollow}:n,jme=(n,e)=>{if(e.type==="update_presence_indicator"){const t=n.sidebarPresenceIndicators.find(r=>r.username===e.presenceIndicator.username);return{...n,sidebarPresenceIndicators:t?n.sidebarPresenceIndicators.map(r=>r.username===e.presenceIndicator.username?e.presenceIndicator:r):[...n.sidebarPresenceIndicators,e.presenceIndicator]}}return n},Nme=(n,e)=>{if(e.type!=="split_current_pane")return n;const t=n.activePaneId,r={id:`${t}-1`,type:"leafPane",tabList:[],activeFileId:null},i={id:`${t}-2`,type:"leafPane",tabList:[],activeFileId:null},o={id:t,type:"splitPane",orientation:"horizontal",children:[r,i]},s=Eu({pane:n.pane,activePaneId:t,newTabList:void 0,newActiveFileId:void 0}),a=(u,c)=>u.id===c?o:u.type==="splitPane"?{...u,children:u.children.map(f=>a(f,c))}:u,l=a(s,t);return{...n,pane:l,activePaneId:r.id}},Fme=({defaultTheme:n,initialUsername:e="Anonymous"})=>({pane:{id:"root",type:"leafPane",tabList:[],activeFileId:null},activePaneId:"root",theme:n,search:{pattern:"",results:{},focused:!1,focusedIndex:null,focusedChildIndex:null},isSearchOpen:!1,isAIChatOpen:!1,aiChatFocused:!1,isSettingsOpen:!1,isDocOpen:!1,editorWantsFocus:!1,username:e,enableAutoFollow:!0,sidebarPresenceIndicators:[]}),qme=[vme,Ome,bme,yme,gme,kme,Eme,Rme,Ame,Mme,$me,Dme,_me,Ime,Qme,Sme,wme,xme,Pme,Lme,jme,Nme],Ume=(n,e)=>qme.reduce((t,r)=>r(t,e),n),Bme=({docPresence:n,enableAutoFollow:e,openTab:t,activePane:r})=>{const i=M.useRef(e);M.useEffect(()=>{i.current=e},[e]);const o=M.useRef(r?.activeFileId);M.useEffect(()=>{o.current=r?.activeFileId},[r?.activeFileId]),M.useEffect(()=>{if(!n)return;const s=(a,l)=>{if(console.log(`[usePresenceAutoFollow] Received presence for id ${a}`,l),!l||!i.current)return;const u=l.start[1];u!==o.current&&(console.log(`[usePresenceAutoFollow] Auto-opening tab for ${l.username} in file ${u}`),t({fileId:u,isTransient:!0}))};return n.on("receive",s),()=>{n.off("receive",s)}},[n,t])},ui=M.createContext(null),Vme=({content:n,shareDBDoc:e,submitOperation:t,localPresence:r,docPresence:i,prettierWorker:o,initialUsername:s,children:a,codeError:l=null,connected:u,pending:c,liveKitToken:f,setLiveKitToken:d,liveKitRoomName:p,setLiveKitRoom:m,liveKitConnection:y,setLiveKitConnection:v,aiChatEndpoint:O,aiChatOptions:S})=>{const{prettierError:w,runPrettierRef:k}=Nce({shareDBDoc:e,submitOperation:t,prettierWorker:o}),x=xfe(t),C=M.useRef(null),D=M.useRef(null),I=w||l,[T,_]=M.useReducer(Ume,{defaultTheme:Kie,initialUsername:s},Fme),{pane:A,activePaneId:Q,theme:F,search:U,isSearchOpen:ne,isAIChatOpen:B,aiChatFocused:X,isSettingsOpen:Y,isDocOpen:te,editorWantsFocus:j,username:G,enableAutoFollow:ae,sidebarPresenceIndicators:L}=T,se=Uc(A,Q);if(se.type!=="leafPane")throw new Error("Expected leafPane");const{setActiveFileId:ye,setActiveFileLeft:_e,setActiveFileRight:V,openTab:z,closeTabs:J,setTheme:he,setIsSearchOpen:Ee,setSearch:je,setSearchResults:Ie,setSearchFileVisibility:$e,setSearchLineVisibility:lt,setSearchFocusedIndex:wt,toggleSearchFocused:Nt,setIsAIChatOpen:En,toggleAIChatFocused:ln,setIsSettingsOpen:fn,setIsDocOpen:Fn,closeSettings:wn,closeDoc:N,editorNoLongerWantsFocus:Se,setUsername:Ye,toggleAutoFollow:ce,updatePresenceIndicator:me,splitCurrentPane:Ae}=eoe(_);mme({content:n,openTab:z,setActiveFileId:ye,tabList:se.tabList,activeFileId:se.activeFileId});const{isDirectoryOpen:rt,toggleDirectory:ct}=Lce({activePane:se,content:n}),Re=toe();Jie(Re,F);const{createFile:st,renameFile:Ke,deleteFile:at,createDirectory:Ot,renameDirectory:pt,deleteDirectory:$t}=Ace({submitOperation:t,closeTabs:J,openTab:z,editorCache:Re,content:n}),[ze,kt]=M.useState(!1),rn=M.useCallback(()=>{kt(!0)},[]),_t=M.useCallback(()=>{kt(!1)},[]),Zt=M.useCallback(De=>{st(De),kt(!1)},[st,kt]),[kn,xn]=M.useState(!1),Tn=M.useCallback(()=>{xn(!0)},[]),$n=M.useCallback(()=>{xn(!1)},[]),or=M.useCallback(De=>{Ot(De),xn(!1)},[Ot,xn]),oe=n?n.files:null;Ice({closeTabs:J,activeFileId:se.activeFileId,activePaneId:Q,handleOpenCreateFileModal:rn,setActiveFileLeft:_e,setActiveFileRight:V,toggleSearchFocused:Nt,runPrettierRef:k,runCodeRef:x,sidebarRef:C,editorCache:Re,codeEditorRef:D});const[ge,be]=M.useState(null);Bme({docPresence:i,enableAutoFollow:ae,openTab:z,activePane:se});const[Ze,Je]=M.useState(!1),it={content:n,shareDBDoc:e,submitOperation:t,localPresence:r,docPresence:i,files:oe,createFile:st,renameFile:Ke,deleteFile:at,createDirectory:Ot,renameDirectory:pt,deleteDirectory:$t,setActiveFileId:ye,setActiveFileLeft:_e,setActiveFileRight:V,activePaneId:Q,pane:A,activePane:se,openTab:z,closeTabs:J,search:U,isSearchOpen:ne,setIsSearchOpen:Ee,setSearch:je,setSearchResults:Ie,setSearchFileVisibility:$e,setSearchLineVisibility:lt,setSearchFocusedIndex:wt,toggleSearchFocused:Nt,isAIChatOpen:B,setIsAIChatOpen:En,aiChatFocused:X,toggleAIChatFocused:ln,aiChatEndpoint:O,aiChatOptions:S,isSettingsOpen:Y,setIsSettingsOpen:fn,closeSettings:wn,isDocOpen:te,setIsDocOpen:Fn,closeDoc:N,theme:F,setTheme:he,username:G,setUsername:Ye,isDirectoryOpen:rt,toggleDirectory:ct,editorCache:Re,editorWantsFocus:j,editorNoLongerWantsFocus:Se,errorMessage:I,isCreateFileModalOpen:ze,handleOpenCreateFileModal:rn,handleCloseCreateFileModal:_t,handleCreateFileClick:Zt,isCreateDirModalOpen:kn,handleOpenCreateDirModal:Tn,handleCloseCreateDirModal:$n,handleCreateDirClick:or,runPrettierRef:k,runCodeRef:x,sidebarRef:C,codeEditorRef:D,connected:u,pending:c,hoveredItemId:ge,setHoveredItemId:be,enableAutoFollow:ae,toggleAutoFollow:ce,updatePresenceIndicator:me,sidebarPresenceIndicators:L,splitCurrentPane:Ae,liveKitRoomName:p,setLiveKitRoom:m,liveKitToken:f,setLiveKitToken:d,liveKitConnection:y,setLiveKitConnection:v,voiceChatModalOpen:Ze,setVoiceChatModalOpen:Je};return q.jsx(ui.Provider,{value:it,children:a})},z7=!1;var my={exports:{}},Ck={exports:{}},dL;function Nn(){return dL||(dL=1,function(n){function e(t){return t&&t.__esModule?t:{default:t}}n.exports=e,n.exports.__esModule=!0,n.exports.default=n.exports}(Ck)),Ck.exports}var Tk={exports:{}};/*!
220
+ `),u=[];for(let c=0;c<l.length;c++){const f=l[c].indexOf(e);f!==-1&&u.push({line:c+1,index:f,text:l[c],isClosed:!1})}u.length>0&&(i[r[o]]={name:a,matches:u,visibility:"open"})}}return i}function Tme(n,e,t){return{...n,[e]:{...n[e],visibility:t}}}const _me=(n,e)=>e.type==="set_is_search_open"?{...n,isSearchOpen:e.value}:n,Eme=(n,e)=>e.type==="set_search"?{...n,search:{...n.search,pattern:e.value,results:{},focusedIndex:0,focusedChildIndex:null,focused:!0}}:n,Rme=(n,e)=>e.type==="set_search_results"?{...n,search:{...n.search,pattern:n.search.pattern,results:Cme(e.files,n.search.pattern),focused:n.search.focused}}:n,Ame=(n,e)=>e.type==="set_search_file_visibility"?{...n,search:{...n.search,pattern:n.search.pattern,results:Tme(n.search.results,e.id,e.visibility)}}:n,Mme=(n,e)=>e.type==="hide_search_results_line"?{...n,search:{...n.search,results:{...n.search.results,[e.id]:{...n.search.results[e.id],matches:n.search.results[e.id].matches.filter((t,r)=>t.line!==e.line)}}}}:n,$me=(n,e)=>e.type==="set_active_search_index"?{...n,search:{...n.search,focusedIndex:e.focusedIndex,focusedChildIndex:e.childIndex}}:n,Dme=(n,e)=>e.type==="toggle_search_focused"?{...n,search:{...n.search,focused:!n.search.focused}}:n,Ime=(n,e)=>e.type==="set_is_ai_chat_open"?{...n,isAIChatOpen:e.value,isSearchOpen:e.value?!1:n.isSearchOpen}:n,Qme=(n,e)=>e.type==="toggle_ai_chat_focused"?{...n,aiChatFocused:!n.aiChatFocused}:n,Lme=(n,e)=>e.type==="toggle_auto_follow"?{...n,enableAutoFollow:!n.enableAutoFollow}:n,jme=(n,e)=>{if(e.type==="update_presence_indicator"){const t=n.sidebarPresenceIndicators.find(r=>r.username===e.presenceIndicator.username);return{...n,sidebarPresenceIndicators:t?n.sidebarPresenceIndicators.map(r=>r.username===e.presenceIndicator.username?e.presenceIndicator:r):[...n.sidebarPresenceIndicators,e.presenceIndicator]}}return n},Nme=(n,e)=>{if(e.type!=="split_current_pane")return n;const t=n.activePaneId,r={id:`${t}-1`,type:"leafPane",tabList:[],activeFileId:null},i={id:`${t}-2`,type:"leafPane",tabList:[],activeFileId:null},o={id:t,type:"splitPane",orientation:"horizontal",children:[r,i]},s=Eu({pane:n.pane,activePaneId:t,newTabList:void 0,newActiveFileId:void 0}),a=(u,c)=>u.id===c?o:u.type==="splitPane"?{...u,children:u.children.map(f=>a(f,c))}:u,l=a(s,t);return{...n,pane:l,activePaneId:r.id}},Fme=({defaultTheme:n,initialUsername:e="Anonymous"})=>({pane:{id:"root",type:"leafPane",tabList:[],activeFileId:null},activePaneId:"root",theme:n,search:{pattern:"",results:{},focused:!1,focusedIndex:null,focusedChildIndex:null},isSearchOpen:!1,isAIChatOpen:!1,aiChatFocused:!1,isSettingsOpen:!1,isDocOpen:!1,editorWantsFocus:!1,username:e,enableAutoFollow:!0,sidebarPresenceIndicators:[]}),qme=[vme,Ome,bme,yme,gme,kme,Eme,Rme,Ame,Mme,$me,Dme,_me,Ime,Qme,Sme,wme,xme,Pme,Lme,jme,Nme],Ume=(n,e)=>qme.reduce((t,r)=>r(t,e),n),Bme=({docPresence:n,enableAutoFollow:e,openTab:t,activePane:r})=>{const i=M.useRef(e);M.useEffect(()=>{i.current=e},[e]);const o=M.useRef(r?.activeFileId);M.useEffect(()=>{o.current=r?.activeFileId},[r?.activeFileId]),M.useEffect(()=>{if(!n)return;const s=(a,l)=>{if(!l||!i.current)return;const u=l.start[1];u!==o.current&&t({fileId:u,isTransient:!0})};return n.on("receive",s),()=>{n.off("receive",s)}},[n,t])},ui=M.createContext(null),Vme=({content:n,shareDBDoc:e,submitOperation:t,localPresence:r,docPresence:i,prettierWorker:o,initialUsername:s,children:a,codeError:l=null,connected:u,pending:c,liveKitToken:f,setLiveKitToken:d,liveKitRoomName:p,setLiveKitRoom:m,liveKitConnection:y,setLiveKitConnection:v,aiChatEndpoint:O,aiChatOptions:S})=>{const{prettierError:w,runPrettierRef:k}=Nce({shareDBDoc:e,submitOperation:t,prettierWorker:o}),x=xfe(t),C=M.useRef(null),D=M.useRef(null),I=w||l,[T,_]=M.useReducer(Ume,{defaultTheme:Kie,initialUsername:s},Fme),{pane:A,activePaneId:Q,theme:F,search:U,isSearchOpen:ne,isAIChatOpen:B,aiChatFocused:X,isSettingsOpen:Y,isDocOpen:te,editorWantsFocus:j,username:G,enableAutoFollow:ae,sidebarPresenceIndicators:L}=T,se=Uc(A,Q);if(se.type!=="leafPane")throw new Error("Expected leafPane");const{setActiveFileId:ye,setActiveFileLeft:_e,setActiveFileRight:V,openTab:z,closeTabs:J,setTheme:he,setIsSearchOpen:Ee,setSearch:je,setSearchResults:Ie,setSearchFileVisibility:$e,setSearchLineVisibility:lt,setSearchFocusedIndex:wt,toggleSearchFocused:Nt,setIsAIChatOpen:En,toggleAIChatFocused:ln,setIsSettingsOpen:fn,setIsDocOpen:Fn,closeSettings:wn,closeDoc:N,editorNoLongerWantsFocus:Se,setUsername:Ye,toggleAutoFollow:ce,updatePresenceIndicator:me,splitCurrentPane:Ae}=eoe(_);mme({content:n,openTab:z,setActiveFileId:ye,tabList:se.tabList,activeFileId:se.activeFileId});const{isDirectoryOpen:rt,toggleDirectory:ct}=Lce({activePane:se,content:n}),Re=toe();Jie(Re,F);const{createFile:st,renameFile:Ke,deleteFile:at,createDirectory:Ot,renameDirectory:pt,deleteDirectory:$t}=Ace({submitOperation:t,closeTabs:J,openTab:z,editorCache:Re,content:n}),[ze,kt]=M.useState(!1),rn=M.useCallback(()=>{kt(!0)},[]),_t=M.useCallback(()=>{kt(!1)},[]),Zt=M.useCallback(De=>{st(De),kt(!1)},[st,kt]),[kn,xn]=M.useState(!1),Tn=M.useCallback(()=>{xn(!0)},[]),$n=M.useCallback(()=>{xn(!1)},[]),or=M.useCallback(De=>{Ot(De),xn(!1)},[Ot,xn]),oe=n?n.files:null;Ice({closeTabs:J,activeFileId:se.activeFileId,activePaneId:Q,handleOpenCreateFileModal:rn,setActiveFileLeft:_e,setActiveFileRight:V,toggleSearchFocused:Nt,runPrettierRef:k,runCodeRef:x,sidebarRef:C,editorCache:Re,codeEditorRef:D});const[ge,be]=M.useState(null);Bme({docPresence:i,enableAutoFollow:ae,openTab:z,activePane:se});const[Ze,Je]=M.useState(!1),it={content:n,shareDBDoc:e,submitOperation:t,localPresence:r,docPresence:i,files:oe,createFile:st,renameFile:Ke,deleteFile:at,createDirectory:Ot,renameDirectory:pt,deleteDirectory:$t,setActiveFileId:ye,setActiveFileLeft:_e,setActiveFileRight:V,activePaneId:Q,pane:A,activePane:se,openTab:z,closeTabs:J,search:U,isSearchOpen:ne,setIsSearchOpen:Ee,setSearch:je,setSearchResults:Ie,setSearchFileVisibility:$e,setSearchLineVisibility:lt,setSearchFocusedIndex:wt,toggleSearchFocused:Nt,isAIChatOpen:B,setIsAIChatOpen:En,aiChatFocused:X,toggleAIChatFocused:ln,aiChatEndpoint:O,aiChatOptions:S,isSettingsOpen:Y,setIsSettingsOpen:fn,closeSettings:wn,isDocOpen:te,setIsDocOpen:Fn,closeDoc:N,theme:F,setTheme:he,username:G,setUsername:Ye,isDirectoryOpen:rt,toggleDirectory:ct,editorCache:Re,editorWantsFocus:j,editorNoLongerWantsFocus:Se,errorMessage:I,isCreateFileModalOpen:ze,handleOpenCreateFileModal:rn,handleCloseCreateFileModal:_t,handleCreateFileClick:Zt,isCreateDirModalOpen:kn,handleOpenCreateDirModal:Tn,handleCloseCreateDirModal:$n,handleCreateDirClick:or,runPrettierRef:k,runCodeRef:x,sidebarRef:C,codeEditorRef:D,connected:u,pending:c,hoveredItemId:ge,setHoveredItemId:be,enableAutoFollow:ae,toggleAutoFollow:ce,updatePresenceIndicator:me,sidebarPresenceIndicators:L,splitCurrentPane:Ae,liveKitRoomName:p,setLiveKitRoom:m,liveKitToken:f,setLiveKitToken:d,liveKitConnection:y,setLiveKitConnection:v,voiceChatModalOpen:Ze,setVoiceChatModalOpen:Je};return q.jsx(ui.Provider,{value:it,children:a})},z7=!1;var my={exports:{}},Ck={exports:{}},dL;function Nn(){return dL||(dL=1,function(n){function e(t){return t&&t.__esModule?t:{default:t}}n.exports=e,n.exports.__esModule=!0,n.exports.default=n.exports}(Ck)),Ck.exports}var Tk={exports:{}};/*!
221
221
  Copyright (c) 2018 Jed Watson.
222
222
  Licensed under the MIT License (MIT), see
223
223
  http://jedwatson.github.io/classnames
package/dist/index.html CHANGED
@@ -20,7 +20,7 @@
20
20
  href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap"
21
21
  rel="stylesheet"
22
22
  />
23
- <script type="module" crossorigin src="/assets/index-0y6ZxgSv.js"></script>
23
+ <script type="module" crossorigin src="/assets/index-ubSLcdJf.js"></script>
24
24
  <link rel="stylesheet" crossorigin href="/assets/index-DKLiE98a.css">
25
25
  </head>
26
26
  <body>
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "vzcode",
3
- "version": "1.39.0",
3
+ "version": "1.40.0",
4
4
  "description": "Multiplayer code editor system",
5
5
  "main": "src/index.ts",
6
6
  "type": "module",
7
- "bin": "src/server/index.js",
7
+ "bin": "src/server/index.ts",
8
8
  "files": [
9
9
  "dist/**",
10
10
  "src/**"
11
11
  ],
12
12
  "scripts": {
13
13
  "test": "vitest run",
14
- "test-interactive": "cd test/sampleDirectories/kitchenSink && node ../../../src/server/index.js",
14
+ "test-interactive": "cd test/sampleDirectories/kitchenSink && node --import 'data:text/javascript,import { register } from \"node:module\"; import { pathToFileURL } from \"node:url\"; register(\"ts-node/esm\", pathToFileURL(\"./\"));' ../../../src/server/index.ts",
15
15
  "prettier": "prettier {*.*,**/*.*} --write",
16
16
  "typecheck": "tsc --noEmit",
17
17
  "dev": "cross-env EDITOR_PORT=5173 concurrently \"npm run test-interactive\" \"vite\"",
@@ -180,6 +180,7 @@
180
180
  "npm-check-updates": "^18.0.1",
181
181
  "prettier": "^3.6.2",
182
182
  "sass": "^1.89.2",
183
+ "ts-node": "^10.9.2",
183
184
  "typescript": "^5.8.3",
184
185
  "vite": "^7.0.5",
185
186
  "vitest": "^3.2.4"
@@ -12,7 +12,7 @@ import {
12
12
  Username,
13
13
  } from '../../types';
14
14
 
15
- const DEBUG = true;
15
+ const DEBUG = false;
16
16
 
17
17
  // Deals with receiving the broadcasted presence cursor locations
18
18
  // from other clients and displaying them.
@@ -57,6 +57,7 @@ export const json1PresenceDisplay = ({
57
57
  // this.scrollToCursor(view);
58
58
  // });
59
59
  // Receive remote presence changes.
60
+ // Receive remote presence changes.
60
61
  docPresence.on(
61
62
  'receive',
62
63
  (id: PresenceId, presence: Presence) => {
@@ -64,37 +65,35 @@ export const json1PresenceDisplay = ({
64
65
  console.log(
65
66
  `Received presence for id ${id}`,
66
67
  presence,
67
- ); // Debug statement
68
+ );
68
69
  }
69
70
 
70
- // If presence === null, the user has disconnected / exited
71
+ // If presence is null, the user has disconnected.
72
+ // We must remove them from our local state.
71
73
  if (!presence) {
72
74
  delete presenceState[id];
73
- return;
74
- }
75
-
76
- // Check if the presence is for the current file or not.
77
- const isPresenceInCurrentFile = pathMatches(
78
- path,
79
- presence,
80
- );
81
-
82
- // If the presence is in the current file, update the presence state.
83
- if (isPresenceInCurrentFile) {
84
- presenceState[id] = presence;
85
- } else if (presence) {
86
- // Otherwise, delete the presence state.
87
- delete presenceState[id];
75
+ // Also remove their cursor position to prevent errors.
76
+ delete this.cursorPosition[id];
77
+ } else {
78
+ // Otherwise, the user is active. Check if the presence
79
+ // is for the current file.
80
+ const isPresenceInCurrentFile = pathMatches(
81
+ path,
82
+ presence,
83
+ );
88
84
 
89
- // Note: Auto-follow tab opening is now handled by usePresenceAutoFollow hook
90
- // in VZCodeContext, which works independently of CodeMirror extensions
85
+ // If it's the current file, add/update their state.
86
+ if (isPresenceInCurrentFile) {
87
+ presenceState[id] = presence;
88
+ } else {
89
+ // If it's for another file, remove them from this view's state.
90
+ delete presenceState[id];
91
+ delete this.cursorPosition[id];
92
+ }
91
93
  }
92
- // Update decorations to reflect new presence state.
93
- // TODO consider mutating this rather than recomputing it on each change.
94
94
 
95
95
  const presenceDecorations = [];
96
96
 
97
- // Object.keys(presenceState).map((id) => {
98
97
  for (const id of Object.keys(presenceState)) {
99
98
  const presence: Presence = presenceState[id];
100
99
  const { start, end } = presence;
@@ -104,7 +103,7 @@ export const json1PresenceDisplay = ({
104
103
  presence.username,
105
104
  );
106
105
  const { username } = presence;
107
- //console.log("File User Color:" + assignUserColor(presence.username));
106
+
108
107
  presenceDecorations.push({
109
108
  from,
110
109
  to: from,
@@ -112,10 +111,6 @@ export const json1PresenceDisplay = ({
112
111
  side: -1,
113
112
  block: false,
114
113
  widget: new PresenceWidget(
115
- // TODO see if we can figure out why
116
- // updateDOM was not being called when passing
117
- // the presence id as the id
118
- // id,
119
114
  '' + Math.random(),
120
115
  userColor,
121
116
  username,
@@ -123,10 +118,7 @@ export const json1PresenceDisplay = ({
123
118
  }),
124
119
  });
125
120
 
126
- // This is `true` when the presence is a cursor,
127
- // with no selection.
128
121
  if (from !== to) {
129
- // This is the case when the presence is a selection.
130
122
  presenceDecorations.push({
131
123
  from,
132
124
  to,
@@ -142,34 +134,26 @@ export const json1PresenceDisplay = ({
142
134
  });
143
135
  }
144
136
  if (view.state.doc.length >= from) {
145
- // Ensure position is valid
146
- this.cursorPosition[id] = from; // Store the cursor position, important to run if we cant get the regular scroll to work
147
- // console.log(`Stored cursor position for id ${id}: ${from}`); // Debug statement
137
+ this.cursorPosition[id] = from;
148
138
  } else {
149
- // console.warn(`Invalid cursor position for id ${id}: ${from}`); // Debug statement
139
+ // The cursor position is invalid, so remove it.
140
+ delete this.cursorPosition[id];
150
141
  }
151
142
  }
152
143
 
153
144
  this.decorations = Decoration.set(
154
145
  presenceDecorations,
155
- // Without this argument, we get the following error:
156
- // Uncaught Error: Ranges must be added sorted by `from` position and `startSide`
157
146
  true,
158
147
  );
159
148
 
160
- // Somehow this triggers re-rendering of the Decorations.
161
- // Not sure if this is the correct usage of the API.
162
- // Inspired by https://github.com/yjs/y-codemirror.next/blob/main/src/y-remote-selections.js
163
- // Set timeout so that the current CodeMirror update finishes
164
- // before the next ones that render presence begin.
149
+ // This dispatch triggers the re-rendering of decorations.
150
+ // It now correctly runs after a deletion.
165
151
  setTimeout(() => {
166
152
  view.dispatch({
167
153
  annotations: [presenceAnnotation.of(true)],
168
154
  });
169
155
  }, 0);
170
156
 
171
- // Auto-follow all users when their presence is broadcast
172
- // by scrolling them into view.
173
157
  if (enableAutoFollowRef.current) {
174
158
  this.scrollToCursor(view);
175
159
  }
@@ -1,9 +1,8 @@
1
- import { useContext, useEffect, useRef } from 'react';
2
- import { VZCodeContext } from './VZCodeContext';
3
- import { Presence, PresenceId, TabState } from '../types';
1
+ import { useEffect, useRef } from 'react';
2
+ import { Presence, PresenceId } from '../types';
4
3
  import { VizFileId } from '@vizhub/viz-types';
5
4
 
6
- const DEBUG = true;
5
+ const DEBUG = false;
7
6
 
8
7
  /**
9
8
  * Custom hook that handles auto-following users by opening tabs when presence
@@ -213,12 +213,15 @@ export const setIsInteracting = (
213
213
  /**
214
214
  * Finds a file ID by searching for a matching file name
215
215
  */
216
- export const resolveFileId = (fileName, shareDBDoc) => {
216
+ export const resolveFileId = (
217
+ fileName: string,
218
+ shareDBDoc: any,
219
+ ) => {
217
220
  const files = shareDBDoc.data.files;
218
221
 
219
222
  // Search through all files to find matching name
220
223
  for (const [fileId, file] of Object.entries(files)) {
221
- if (file.name === fileName) {
224
+ if ((file as any).name === fileName) {
222
225
  return fileId;
223
226
  }
224
227
  }
@@ -8,12 +8,22 @@ import { createLLMFunction } from './llmStreaming.js';
8
8
  import { performAIEditing } from './aiEditing.js';
9
9
  import { handleError } from './errorHandling.js';
10
10
  import { createRunCodeFunction } from '../../runCode.js';
11
+ import { ShareDBDoc } from '../../types.js';
12
+ import { VizContent } from '@vizhub/viz-types';
11
13
 
12
14
  const DEBUG = false;
13
15
 
14
16
  export const handleAIChatMessage =
15
- ({ shareDBDoc, localPresence, onCreditDeduction }) =>
16
- async (req, res) => {
17
+ ({
18
+ shareDBDoc,
19
+ createVizBotLocalPresence,
20
+ onCreditDeduction,
21
+ }: {
22
+ shareDBDoc: ShareDBDoc<VizContent>;
23
+ createVizBotLocalPresence: () => any;
24
+ onCreditDeduction?: any;
25
+ }) =>
26
+ async (req: any, res: any) => {
17
27
  const { content, chatId } = req.body;
18
28
 
19
29
  if (DEBUG) {
@@ -41,7 +51,7 @@ export const handleAIChatMessage =
41
51
  // Create LLM function for streaming
42
52
  const llmFunction = createLLMFunction({
43
53
  shareDBDoc,
44
- localPresence,
54
+ createVizBotLocalPresence,
45
55
  chatId,
46
56
  });
47
57
 
@@ -52,7 +62,6 @@ export const handleAIChatMessage =
52
62
  const editResult = await performAIEditing({
53
63
  prompt: content,
54
64
  shareDBDoc,
55
- chatId,
56
65
  llmFunction,
57
66
  runCode,
58
67
  });
@@ -60,14 +69,15 @@ export const handleAIChatMessage =
60
69
  // Handle credit deduction if callback is provided
61
70
  if (
62
71
  onCreditDeduction &&
63
- editResult.upstreamCostCents
72
+ (editResult as any).upstreamCostCents
64
73
  ) {
65
74
  try {
66
75
  await onCreditDeduction({
67
- upstreamCostCents: editResult.upstreamCostCents,
68
- provider: editResult.provider,
69
- inputTokens: editResult.inputTokens,
70
- outputTokens: editResult.outputTokens,
76
+ upstreamCostCents: (editResult as any)
77
+ .upstreamCostCents,
78
+ provider: (editResult as any).provider,
79
+ inputTokens: (editResult as any).inputTokens,
80
+ outputTokens: (editResult as any).outputTokens,
71
81
  });
72
82
  } catch (creditError) {
73
83
  console.error(
@@ -16,10 +16,11 @@ const DEBUG = false;
16
16
  */
17
17
  export const createLLMFunction = ({
18
18
  shareDBDoc,
19
- localPresence,
19
+ createVizBotLocalPresence,
20
20
  chatId,
21
21
  }) => {
22
22
  return async (fullPrompt) => {
23
+ const localPresence = createVizBotLocalPresence();
23
24
  // Submit initial presence for VizBot
24
25
  const vizBotPresence = {
25
26
  username: 'VizBot',
@@ -188,7 +189,12 @@ export const createLLMFunction = ({
188
189
  updateAIScratchpad(shareDBDoc, chatId, fullContent);
189
190
 
190
191
  // Clear VizBot presence when done
191
- localPresence.destroy((error) => {
192
+ DEBUG &&
193
+ console.log(
194
+ 'AI editing done, clearing VizBot presence',
195
+ );
196
+ localPresence.submit(null, (error) => {
197
+ DEBUG && console.log('VizBot presence cleared');
192
198
  if (error) {
193
199
  console.warn(
194
200
  'VizBot presence cleanup error:',
@@ -28,7 +28,8 @@ const slowdown = false;
28
28
 
29
29
  // The options passed into the OpenAI client
30
30
  // new OpenAI(openAIOptions)
31
- const openAIOptions = {};
31
+ const openAIOptions: { apiKey?: string; baseURL?: string } =
32
+ {};
32
33
 
33
34
  // Support specifying the API key via an environment variable
34
35
  // If VZCODE_AI_API_KEY is not set, note that the OpenAI client
@@ -71,7 +72,7 @@ const opComesFromAIAssist = (ops, source) =>
71
72
 
72
73
  // Keeps track of the currently ongoing AI streams.
73
74
  // There could be many streams at the same time.
74
- const streams = {};
75
+ export const streams: Record<string, any> = {};
75
76
 
76
77
  export const generateAIResponse = async ({
77
78
  inputText,
@@ -1,9 +1,12 @@
1
- import { generateAIResponse } from './generateAIResponse.js';
1
+ import {
2
+ generateAIResponse,
3
+ streams,
4
+ } from './generateAIResponse.js';
2
5
 
3
6
  const debug = false;
4
7
 
5
8
  export const handleAIAssist =
6
- (shareDBDoc) => async (req, res) => {
9
+ (shareDBDoc: any) => async (req: any, res: any) => {
7
10
  const { inputText, insertionCursor, fileId } = req.body;
8
11
 
9
12
  if (debug) {
@@ -16,17 +19,21 @@ export const handleAIAssist =
16
19
  }
17
20
 
18
21
  try {
22
+ // Generate a unique streamId for this request
23
+ const streamId = `stream_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
24
+
19
25
  await generateAIResponse({
20
26
  inputText,
21
27
  insertionCursor,
22
28
  fileId,
29
+ streamId,
23
30
  shareDBDoc,
24
31
  });
25
32
 
26
33
  res
27
34
  .status(200)
28
35
  .send({ message: 'Operation successful!' });
29
- } catch (error) {
36
+ } catch (error: any) {
30
37
  console.error('handleAIAssist error:', error);
31
38
  res.status(500).send({
32
39
  message: 'Internal Server Error',
@@ -35,7 +42,7 @@ export const handleAIAssist =
35
42
  }
36
43
  };
37
44
 
38
- export function haltGeneration(streamId) {
45
+ export function haltGeneration(streamId: string) {
39
46
  const stream = streams[streamId];
40
47
 
41
48
  // Stream can be undefined here if the user
@@ -4,7 +4,6 @@ import bodyParser from 'body-parser';
4
4
  import express from 'express';
5
5
  import fs from 'fs';
6
6
  import http from 'http';
7
- import ngrok from 'ngrok';
8
7
  import open from 'open';
9
8
  import path from 'path';
10
9
  import ShareDB from 'sharedb';
@@ -103,9 +102,8 @@ const generateVizBotId = () => {
103
102
  return `vizbot-${timestamp}`;
104
103
  };
105
104
 
106
- const localPresence = docPresence.create(
107
- generateVizBotId(),
108
- );
105
+ const createVizBotLocalPresence = () =>
106
+ docPresence.create(generateVizBotId());
109
107
 
110
108
  shareDBDoc.create(initialDocument, json1Presence.type.uri);
111
109
 
@@ -127,7 +125,11 @@ app.post(
127
125
  app.post(
128
126
  '/ai-chat-message',
129
127
  bodyParser.json(),
130
- handleAIChatMessage({ shareDBDoc, localPresence }),
128
+ handleAIChatMessage({
129
+ shareDBDoc,
130
+ createVizBotLocalPresence,
131
+ onCreditDeduction: undefined,
132
+ }),
131
133
  );
132
134
 
133
135
  // Livekit Token Generator
@@ -335,21 +337,13 @@ shareDBDoc.subscribe(() => {
335
337
  });
336
338
 
337
339
  server.listen(port, async () => {
338
- if (process.env.NGROK_TOKEN) {
339
- (async function () {
340
- await ngrok.authtoken(process.env.NGROK_TOKEN);
341
- const url = await ngrok.connect(port);
342
- console.log(`Editor is live at ${url}`);
343
- open(url);
344
- })();
345
- } else {
346
- // Sets the port to the one specified in the environment
347
- // variable (for development) or the default port.
348
- let livePort = process.env.EDITOR_PORT || port;
349
- console.log(`EDITOR_PORT: ${process.env.EDITOR_PORT}`);
350
- console.log(
351
- `Editor is live at http://localhost:${livePort}`,
352
- );
353
- open(`http://localhost:${livePort}`);
354
- }
340
+ // Note: ngrok support can be added when the package is properly installed
341
+ // Sets the port to the one specified in the environment
342
+ // variable (for development) or the default port.
343
+ let livePort = process.env.EDITOR_PORT || port;
344
+ console.log(`EDITOR_PORT: ${process.env.EDITOR_PORT}`);
345
+ console.log(
346
+ `Editor is live at http://localhost:${livePort}`,
347
+ );
348
+ open(`http://localhost:${livePort}`);
355
349
  });
File without changes
File without changes
File without changes
File without changes
File without changes