vzcode 0.33.0 → 0.35.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.
|
@@ -108,8 +108,8 @@ Source:
|
|
|
108
108
|
mix-blend-mode: luminosity;
|
|
109
109
|
`}})}}),!0),setTimeout(()=>{n.dispatch({annotations:[q4.of(!0)]})},0)})}},{decorations:n=>n.decorations}),H4],q4=di.define(),V4=(t,e)=>{for(let n=0;n<t.length;n++)if(t[n]!==e.start[n])return!1;return!0};class G4 extends qr{constructor(e,n,r){super(),this.id=e,this.color=n,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 n=document.createElement("div");e.appendChild(n),n.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*11}px`,r.style.backgroundColor=`rgba(${this.color})`,r.style.color="black",r.style.textAlign="center",r.appendChild(document.createTextNode(this.username)),e.appendChild(r),e}ignoreEvent(){return!1}}const H4=Le.baseTheme({".cm-json1-presence":{position:"relative"},".cm-json1-presence > div":{position:"absolute",top:"0",bottom:"0",left:"0",right:"0"}}),jQ=En.define({create:()=>null,update:(t,e)=>{for(const n of e.effects)if(n.is(ry))return n.value;if(!t)return null;if(!e.changes.empty){const n=e.changes.mapPos(t.pos,-1,xn.TrackDel),r=e.changes.mapPos(t.pos+t.text.length,-1,xn.TrackDel);return n===null||r===null||e.newDoc.sliceString(n,r)!==t.text?null:Object.assign(Object.assign({},t),{pos:n})}return t},provide:t=>[Le.decorations.from(t,e=>{if(!e)return He.none;const n=e.pos,r=e.pos+e.text.length,i=e.rule.className;return He.set(K4({className:i}).range(n,r))}),Le.contentAttributes.from(t,e=>!e||!e.rule.cursor?{style:""}:{style:`cursor: ${e.rule.cursor}`})]}),ry=kt.define(),K4=t=>{var e;return He.mark({class:`cm-interact ${(e=t==null?void 0:t.className)!==null&&e!==void 0?e:""}`})},J4=Le.theme({".cm-interact":{background:"rgba(128, 128, 255, 0.2)",borderRadius:"4px"}}),XQ=Ue.define(),YQ=Ue.define({combine:t=>t[t.length-1]}),eF=qt.define(t=>({target:null,dragging:!1,mouseX:0,mouseY:0,getMatch(){const e=t.state.facet(XQ),n=t.posAtCoords({x:this.mouseX,y:this.mouseY});if(!n)return null;const r=t.state.doc.lineAt(n),i=n-r.from;let s=null;for(const o of e)for(const l of r.text.matchAll(o.regexp)){if(l.index===void 0)continue;const a=l[0];if(!a)continue;const u=l.index,c=l.index+a.length;i<u||i>c||(!s||a.length<s.text.length)&&(s={rule:o,pos:r.from+u,text:a})}return s},updateText(e){return n=>{t.dispatch({effects:ry.of(Object.assign(Object.assign({},e),{text:n})),changes:{from:e.pos,to:e.pos+e.text.length,insert:n}})}},setTarget(e){this.target=e,t.dispatch({effects:ry.of(e)})},isModKeyDown(e){const n=t.state.facet(YQ),r=!!window.navigator&&window.navigator.userAgent.includes("Macintosh");switch(n){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: ${n}`)},update(e){const n=e.state.field(jQ,!1);n!==void 0&&this.target!==n&&(this.target=n,n===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(t,e){this.isModKeyDown(t)&&this.target&&(t.preventDefault(),this.target.rule.onClick&&this.target.rule.onClick(this.target.text,this.updateText(this.target),t),this.target.rule.onDrag&&this.startDrag(t))},mousemove(t,e){if(this.mouseX=t.clientX,this.mouseY=t.clientY,!this.isModKeyDown(t)){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),t):this.setTarget(this.getMatch())},mouseup(t,e){this.endDrag(),this.target&&!this.isModKeyDown(t)&&this.setTarget(null),this.isModKeyDown(t)&&this.setTarget(this.getMatch())},mouseleave(t,e){this.endDrag(),this.target&&this.setTarget(null)},keydown(t,e){!this.target&&this.isModKeyDown(t)&&this.setTarget(this.getMatch())},keyup(t,e){this.target&&!this.isModKeyDown(t)&&(this.endDrag(),this.setTarget(null))}}}),tF=(t={})=>{var e,n;return[jQ,J4,eF,YQ.of((e=t.key)!==null&&e!==void 0?e:"alt"),((n=t.rules)!==null&&n!==void 0?n:[]).map(r=>XQ.of(r))]},nF=({onInteract:t})=>tF({rules:[{regexp:/\"\#([0-9]|[A-F]|[a-f]){6}\"/g,cursor:"pointer",onClick(e,n,r){var u;const s=(u=/\"(?<hex>\#([0-9]|[A-F]|[a-f]){6})\"/.exec(e).groups)==null?void 0:u.hex,o=document.createElement("input");o.type="color",o.value=s.toLowerCase();const l=s.toUpperCase()===s,a=c=>{const h=c.target;h.value&&n(`"${l?h.value.toUpperCase():h.value}"`)};o.addEventListener("input",a),o.click()}},{regexp:new RegExp("(?<!\\#)-?\\b\\d+\\.?\\d*\\b","g"),cursor:"ew-resize",onDrag:(e,n,r)=>{t&&t();const i=Number(e)+r.movementX;isNaN(i)||n(i.toString())}},{regexp:/true|false/g,cursor:"pointer",onClick:(e,n)=>{switch(t&&t(),e){case"true":return n("false");case"false":return n("true")}}},{regexp:/vec2\(-?\b\d+\.?\d*\b\s*(,\s*-?\b\d+\.?\d*\b)?\)/g,cursor:"move",onDrag:(e,n,r)=>{var l,a;const i=/vec2\((?<x>-?\b\d+\.?\d*\b)\s*(,\s*(?<y>-?\b\d+\.?\d*\b))?\)/.exec(e),s=Number((l=i==null?void 0:i.groups)==null?void 0:l.x);let o=Number((a=i==null?void 0:i.groups)==null?void 0:a.y);isNaN(s)||(isNaN(o)&&(o=s),n(`vec2(${s+r.movementX}, ${o-r.movementY})`))}},{regexp:/rgb\(.*\)/g,cursor:"pointer",onClick:(e,n,r)=>{var c,h,f;const i=/rgb\((?<r>\d+)\s*,\s*(?<g>\d+)\s*,\s*(?<b>\d+)\)/.exec(e),s=Number((c=i==null?void 0:i.groups)==null?void 0:c.r),o=Number((h=i==null?void 0:i.groups)==null?void 0:h.g),l=Number((f=i==null?void 0:i.groups)==null?void 0:f.b),a=document.createElement("input");a.type="color",isNaN(s+o+l)||(a.value=iF(s,o,l));const u=d=>{const p=d.target;if(p.value){const[g,O,y]=rF(p.value);n(`rgb(${g}, ${O}, ${y})`)}a.removeEventListener("change",u)};a.addEventListener("change",u),a.click()}},{regexp:/https?:\/\/[^ "]+/g,cursor:"pointer",onClick:e=>{window.open(e)}},{regexp:/rotate\(-?\d*\.?\d*\)/g,cursor:"move",onDragStart(e,n,r){vo={x:r.clientX,y:r.clientY}},onDrag(e,n,r){if(vo==null)return;const i=Math.round(Math.atan2(vo.y-r.clientY,r.clientX-vo.x)*180/Math.PI);n(`rotate(${i})`);const s=new CustomEvent("updateRotateDrag",{detail:i});document.dispatchEvent(s)},onDragEnd(e,n){vo=null}}]});let vo=null;const rF=t=>{const e=parseInt(t.substring(1),16);return[e>>16&255,e>>8&255,e&255]},iF=(t,e,n)=>"#"+t.toString(16)+e.toString(16)+n.toString(16),sF=Le.baseTheme({".color-circle-parent":{display:"inline-block"}});di.define();const oF=[qt.fromClass(class{constructor(t){this.decorations=Bt.of([]),this.view=t}},{decorations:t=>{const e=[],n=t.view.state.doc.iter();let r=n.next(),i=0;for(;!r.done;){if(r.value===`
|
|
110
110
|
`){i++,r=n.next();continue}const s=r.value.matchAll(/\"\#([0-9]|[A-F]|[a-f]){6}\"/g);let o=s.next();for(;!o.done;){const l=o.value;l.index+=i,e.push(l),o=s.next()}i+=r.value.length,r=n.next()}return He.set(e.map(s=>({from:s.index+9,to:s.index+9,value:He.widget({side:-1,widget:new lF(s[0])})})))}}),sF];class lF extends qr{constructor(e){super(),this.color=e}eq(e){return e.color===this.color}toDOM(e){const n=document.createElement("div");n.setAttribute("style","width:10px;height:10px"),n.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");return i.setAttributeNS(null,"fill",this.color.replace(/\"/g,"")),i.setAttributeNS(null,"r","5"),i.setAttributeNS(null,"cx","5"),i.setAttributeNS(null,"cy","5"),r.setAttributeNS(null,"viewBox","0 0 10 10"),r.setAttributeNS(null,"width","10"),r.setAttributeNS(null,"height","10"),r.appendChild(i),n.appendChild(r),n}ignoreEvent(){return!1}}const aF=qt.fromClass(class{constructor(t){this.showHighlight=!1,this.view=t}},{decorations:t=>{if(!t.showHighlight)return He.none;const e=[],n=t.view.state.doc.iter();let r=n.next(),i=0;for(;!r.done;){if(r.value===`
|
|
111
|
-
`){i++,r=n.next();continue}const s=r.value.matchAll(new RegExp('\\"\\#([0-9]|[A-F]|[a-f]){6}\\"|rotate\\(-?\\d*\\.?\\d*\\)|https?:\\/\\/[^ "]+|vec2\\(-?\\b\\d+\\.?\\d*\\b\\s*(,\\s*-?\\b\\d+\\.?\\d*\\b)?\\)|true|false|(?<!\\#)-?\\b\\d+\\.?\\d*\\b|rgb\\(.*\\)',"dg"));let o=s.next();for(;!o.done;){const l=o.value;l.indices[0][0]+=i,l.indices[0][1]+=i,e.push(l),o=s.next()}i+=r.value.length,r=n.next()}return He.set(e.map(s=>({from:s.indices[0][0],to:s.indices[0][1],value:He.mark({class:"cm-interact "})})))},eventHandlers:{keydown(t,e){t.key=="Alt"&&(this.showHighlight=!0)},keyup(t,e){t.key=="Alt"&&(this.showHighlight=!1)}}}),uF=qt.fromClass(class{constructor(t){this.view=t,this.textPosition=null,this.rotation=0,document.addEventListener("updateRotateDrag",e=>{this.textPosition=this.view.posAtCoords(vo,!1),this.rotation=e.detail})}},{decorations:t=>vo===null?He.none:He.set([{from:t.textPosition,to:t.textPosition,value:He.widget({side:-1,widget:new cF(t.rotation)})}])});class cF extends qr{constructor(e){super(),this.angle=e}toDOM(e){const n=document.createElement("div");n.setAttribute("style","width:20px;height:20px"),n.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 s=document.createElementNS("http://www.w3.org/2000/svg","line");return s.setAttributeNS(null,"x1","10"),s.setAttributeNS(null,"x2","5"),s.setAttributeNS(null,"y1","5"),s.setAttributeNS(null,"y2","5"),s.setAttributeNS(null,"stroke","black"),s.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(s),n.appendChild(r),n}ignoreEvent(){return!1}}const e0=()=>(Math.random()+"").slice(2),fF=({typeScriptWorker:t,fileName:e})=>async r=>{const i=e0(),s=r.state.doc.toString(),o={event:"autocomplete-request",fileName:e,fileContent:s,position:r.pos,requestId:i};t.postMessage(o);const l=await new Promise(c=>{t.onmessage=h=>{const f=h.data,{event:d,requestId:p,completions:g}=f;d==="post-completions"&&p===p&&c(g)}});if(!l)return{from:r.pos,options:[]};const a=r.matchBefore(/\w*/).from,u=r.matchBefore(/\w*/).text;return u&&(l.entries=l.entries.filter(c=>c.name.startsWith(u))),{from:r.pos,options:l.entries.map(c=>({label:c.name,apply:h=>{h.dispatch({changes:{from:a,to:r.pos,insert:c.name}})}}))}};var Ld={},UQ={},t0={};Object.defineProperty(t0,"__esModule",{value:!0});function hF(t,e){if(Array.isArray(e))return!1;for(let n in t)if(!n0(t[n],e[n]))return!1;for(let n in e)if(t[n]===void 0)return!1;return!0}function dF(t,e){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!n0(t[n],e[n]))return!1;return!0}function n0(t,e){return t===e?!0:t===null||e===null||typeof t!="object"||typeof e!="object"?!1:Array.isArray(t)?dF(t,e):hF(t,e)}t0.default=n0;var r0={};Object.defineProperty(r0,"__esModule",{value:!0});function iy(t){if(t===null)return null;if(Array.isArray(t))return t.map(iy);if(typeof t=="object"){const e={};for(let n in t)e[n]=iy(t[n]);return e}else return t}r0.default=iy;var i0={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.eachChildOf=t.advancer=t.readCursor=t.writeCursor=t.WriteCursor=t.ReadCursor=t.isValidPathItem=void 0;function e(c,h){if(!c)throw new Error(h)}const n=c=>c!=null&&typeof c=="object"&&!Array.isArray(c),r=(c,h)=>typeof c==typeof h?c>h:typeof c=="string"&&typeof h=="number";function i(c,h){for(let f in c){const d=f;h.write(d,c[d])}}t.isValidPathItem=c=>typeof c=="number"||typeof c=="string"&&c!=="__proto__";class s{constructor(h=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=h}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){const h=[];let f=this.container,d=this.parents.length-1,p=this.idx;for(;p>=0;)h.unshift(f[p]),p===0?(p=this.indexes[d*2],f=this.parents[d--]):p-=n(f[p-1])?2:1;return h}}class o extends s{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let h;return this.container&&this.container.length>this.idx+1&&n(h=this.container[this.idx+1])?h:null}descendFirst(){let h=this.idx+1;if(!this.container||h>=this.container.length||n(this.container[h])&&h+1>=this.container.length)return!1;n(this.container[h])&&h++;const f=this.container[h];return Array.isArray(f)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(h),this.idx=0,this.container=f):this.idx=h,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const h=this.indexes[this.indexes.length-1]+1,f=this.parents[this.parents.length-1];return h>=f.length?!1:(e(!isNaN(h)),this.indexes[this.indexes.length-1]=h,this.container=f[h],!0)}_init(h,f,d,p){this.container=h,this.idx=f,this.parents=d.slice(),this.indexes=p.slice()}clone(){const h=new o;return h._init(this.container,this.idx,this.parents,this.indexes),h}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(h,f){const d=this.getComponent();d&&f(d,h);for(const p of this)h&&h.descend(p),this.traverse(h,f),h&&h.ascend()}eachPick(h,f){this.traverse(h,(d,p)=>{d.p!=null&&f(d.p,p)})}eachDrop(h,f){this.traverse(h,(d,p)=>{d.d!=null&&f(d.d,p)})}}t.ReadCursor=o;class l extends s{constructor(h=null){super(h),this.pendingDescent=[],this._op=h}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let h=0;h<this.pendingDescent.length;h++){const f=this.pendingDescent[h];let d=this.idx+1;if(d<this.container.length&&n(this.container[d])&&d++,e(d===this.container.length||!n(this.container[d])),d===this.container.length)this.container.push(f),this.idx=d;else if(this.container[d]===f)this.idx=d;else{if(!Array.isArray(this.container[d])){const p=this.container.splice(d,this.container.length-d);this.container.push(p),this.lcIdx>-1&&(this.lcIdx=d)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(r(f,this.container[this.lcIdx][0])),d=this.lcIdx+1,this.lcIdx=-1);d<this.container.length&&r(f,this.container[d][0]);)d++;if(this.indexes.push(d),this.idx=0,d<this.container.length&&this.container[d][0]===f)this.container=this.container[d];else{const p=[f];this.container.splice(d,0,p),this.container=p}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const h=this.idx+1;if(h<this.container.length&&n(this.container[h]))return this.container[h];{const f={};return this.container.splice(h,0,f),f}}write(h,f){const d=this.getComponent();e(d[h]==null||d[h]===f,"Internal consistency error: Overwritten component. File a bug"),d[h]=f}get(){return this._op}descend(h){if(!t.isValidPathItem(h))throw Error("Invalid JSON key");this.pendingDescent.push(h)}descendPath(h){return this.pendingDescent.push(...h),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(h,f=i){if(h===null)return;if(e(Array.isArray(h)),h===this._op)throw Error("Cannot merge into my own tree");const d=this.lcIdx,p=this.parents.length;let g=0;for(let O=0;O<h.length;O++){const y=h[O];typeof y=="string"||typeof y=="number"?(g++,this.descend(y)):Array.isArray(y)?this.mergeTree(y,f):typeof y=="object"&&f(y,this)}for(;g--;)this.ascend();this.lcIdx=this.parents.length===p?d:-1}at(h,f){this.descendPath(h),f(this);for(let d=0;d<h.length;d++)this.ascend();return this}writeAtPath(h,f,d){return this.at(h,()=>this.write(f,d)),this.reset(),this}writeMove(h,f,d=0){return this.writeAtPath(h,"p",d).writeAtPath(f,"d",d)}getPath(){const h=super.getPath();return h.push(...this.pendingDescent),h}}t.WriteCursor=l,t.writeCursor=()=>new l,t.readCursor=c=>new o(c);function a(c,h,f){let d,p;p=d=c?c.descendFirst():!1;function g(O){let y;for(;p;){const m=y=c.getKey();if(O!=null){let v=!1;if(h&&typeof m=="number"&&(y=h(m,c.getComponent()),y<0&&(y=~y,v=!0)),r(y,O))return null;if(y===O&&!v)return c}f&&typeof y=="number"&&f(y,c.getComponent()),p=c.nextSibling()}return null}return g.end=()=>{d&&c.ascend()},g}t.advancer=a;function u(c,h,f){let d,p,g,O;for(d=p=c&&c.descendFirst(),g=O=h&&h.descendFirst();d||g;){let y=d?c.getKey():null,m=g?h.getKey():null;y!==null&&m!==null&&(r(m,y)?m=null:y!==m&&(y=null)),f(y??m,y!=null?c:null,m!=null?h:null),y!=null&&d&&(d=c.nextSibling()),m!=null&&g&&(g=h.nextSibling())}p&&c.ascend(),O&&h.ascend()}t.eachChildOf=u})(i0);var s0={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(t.ConflictType||(t.ConflictType={}))})(s0);var zg={},co={},sx;function o0(){return sx||(sx=1,Object.defineProperty(co,"__esModule",{value:!0}),co.uniToStrPos=co.strPosToUni=void 0,co.strPosToUni=(t,e=t.length)=>{let n=0,r=0;for(;r<e;r++){const i=t.charCodeAt(r);i>=55296&&i<=57343&&(n++,r++)}if(r!==e)throw Error("Invalid offset - splits unicode bytes");return r-n},co.uniToStrPos=(t,e)=>{let n=0;for(;e>0;e--){const r=t.charCodeAt(n);n+=r>=55296&&r<=57343?2:1}return n}),co}var qg={},ox;function sy(){return ox||(ox=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.uniSlice=t.dlen=t.eachOp=void 0;const e=o0(),n=b=>{if(!Array.isArray(b))throw Error("Op must be an array of components");let P=null;for(let C=0;C<b.length;C++){const k=b[C];switch(typeof k){case"object":if(typeof k.d!="number"&&typeof k.d!="string")throw Error("Delete must be number or string");if(t.dlen(k.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(k.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(k>0))throw Error("Skip components must be >0");if(typeof P=="number")throw Error("Adjacent skip components should be combined");break}P=k}if(typeof P=="number")throw Error("Op has a trailing skip")};function r(b,P){let C=0,k=0;for(let x=0;x<b.length;x++){const _=b[x];switch(P(_,C,k),typeof _){case"object":C+=t.dlen(_.d);break;case"string":k+=e.strPosToUni(_);break;case"number":C+=_,k+=_;break}}}t.eachOp=r;function i(b,P){const C=[],k=l(C);return r(b,(x,_,E)=>{k(P(x,_,E))}),h(C)}const s=b=>b,o=b=>i(b,s);t.dlen=b=>typeof b=="number"?b:e.strPosToUni(b);const l=b=>P=>{if(!(!P||P.d===0||P.d===""))if(b.length===0)b.push(P);else if(typeof P==typeof b[b.length-1])if(typeof P=="object"){const C=b[b.length-1];C.d=typeof C.d=="string"&&typeof P.d=="string"?C.d+P.d:t.dlen(C.d)+t.dlen(P.d)}else b[b.length-1]+=P;else b.push(P)},a=b=>typeof b=="number"?b:typeof b=="string"?e.strPosToUni(b):typeof b.d=="number"?b.d:e.strPosToUni(b.d);t.uniSlice=(b,P,C)=>{const k=e.uniToStrPos(b,P),x=C==null?1/0:e.uniToStrPos(b,C);return b.slice(k,x)};const u=(b,P,C)=>typeof b=="number"?C==null?b-P:Math.min(b,C)-P:t.uniSlice(b,P,C),c=b=>{let P=0,C=0;return{take:(_,E)=>{if(P===b.length)return _===-1?null:_;const A=b[P];let I;if(typeof A=="number")return _===-1||A-C<=_?(I=A-C,++P,C=0,I):(C+=_,_);if(typeof A=="string"){if(_===-1||E==="i"||e.strPosToUni(A.slice(C))<=_)return I=A.slice(C),++P,C=0,I;{const Y=C+e.uniToStrPos(A.slice(C),_);return I=A.slice(C,Y),C=Y,I}}else{if(_===-1||E==="d"||t.dlen(A.d)-C<=_)return I={d:u(A.d,C)},++P,C=0,I;{let Y=u(A.d,C,C+_);return C+=_,{d:Y}}}},peek:()=>b[P]}},h=b=>(b.length>0&&typeof b[b.length-1]=="number"&&b.pop(),b);function f(b,P,C){if(C!=="left"&&C!=="right")throw Error("side ("+C+") must be 'left' or 'right'");n(b),n(P);const k=[],x=l(k),{take:_,peek:E}=c(b);for(let I=0;I<P.length;I++){const Y=P[I];let te,M;switch(typeof Y){case"number":for(te=Y;te>0;)M=_(te,"i"),x(M),typeof M!="string"&&(te-=a(M));break;case"string":C==="left"&&typeof E()=="string"&&x(_(-1)),x(e.strPosToUni(Y));break;case"object":for(te=t.dlen(Y.d);te>0;)switch(M=_(te,"i"),typeof M){case"number":te-=M;break;case"string":x(M);break;case"object":te-=t.dlen(M.d)}break}}let A;for(;A=_(-1);)x(A);return h(k)}function d(b,P){n(b),n(P);const C=[],k=l(C),{take:x}=c(b);for(let E=0;E<P.length;E++){const A=P[E];let I,Y;switch(typeof A){case"number":for(I=A;I>0;)Y=x(I,"d"),k(Y),typeof Y!="object"&&(I-=a(Y));break;case"string":k(A);break;case"object":I=t.dlen(A.d);let te=0;for(;te<I;)switch(Y=x(I-te,"d"),typeof Y){case"number":k({d:u(A.d,te,te+Y)}),te+=Y;break;case"string":te+=e.strPosToUni(Y);break;case"object":k(Y)}break}}let _;for(;_=x(-1);)k(_);return h(C)}const p=(b,P)=>{let C=0;for(let k=0;k<P.length&&b>C;k++){const x=P[k];switch(typeof x){case"number":{C+=x;break}case"string":const _=e.strPosToUni(x);C+=_,b+=_;break;case"object":b-=Math.min(t.dlen(x.d),b-C);break}}return b},g=(b,P)=>typeof b=="number"?p(b,P):b.map(C=>p(C,P));function O(b,P,C){return i(b,(k,x)=>typeof k=="object"&&typeof k.d=="number"?{d:C.slice(P,x,x+k.d)}:k)}function y(b){return i(b,P=>{switch(typeof P){case"object":if(typeof P.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return P.d;case"string":return{d:P};case"number":return P}})}function m(b){return i(b,P=>typeof P=="object"&&typeof P.d=="string"?{d:e.strPosToUni(P.d)}:P)}function v(b){let P=!0;return r(b,C=>{typeof C=="object"&&typeof C.d=="number"&&(P=!1)}),P}function w(b){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:h,normalize:o,checkOp:n,create(P=""){if(typeof P!="string")throw Error("Initial data must be a string");return b.create(P)},apply(P,C){n(C);const k=b.builder(P);for(let x=0;x<C.length;x++){const _=C[x];switch(typeof _){case"number":k.skip(_);break;case"string":k.append(_);break;case"object":k.del(t.dlen(_.d));break}}return k.build()},transform:f,compose:d,transformPosition:p,transformSelection:g,isInvertible:v,makeInvertible(P,C){return O(P,C,b)},stripInvertible:m,invert:y,invertWithDoc(P,C){return y(O(P,C,b))},isNoop:P=>P.length===0}}t.default=w}(qg)),qg}var sh={},lx;function pF(){if(lx)return sh;lx=1,Object.defineProperty(sh,"__esModule",{value:!0});const t=sy(),e=o0();function n(r,i){return{get:r,getLength(){return r().length},insert(s,o,l){const a=e.strPosToUni(r(),s);return i([a,o],l)},remove(s,o,l){const a=e.strPosToUni(r(),s);return i([a,{d:o}],l)},_onOp(s){t.eachOp(s,(o,l,a)=>{switch(typeof o){case"string":this.onInsert&&this.onInsert(a,o);break;case"object":const u=t.dlen(o.d);this.onRemove&&this.onRemove(a,u)}})},onInsert:null,onRemove:null}}return sh.default=n,n.provides={text:!0},sh}var ax;function gF(){return ax||(ax=1,function(t){var e=Ft&&Ft.__createBinding||(Object.create?function(f,d,p,g){g===void 0&&(g=p),Object.defineProperty(f,g,{enumerable:!0,get:function(){return d[p]}})}:function(f,d,p,g){g===void 0&&(g=p),f[g]=d[p]}),n=Ft&&Ft.__setModuleDefault||(Object.create?function(f,d){Object.defineProperty(f,"default",{enumerable:!0,value:d})}:function(f,d){f.default=d}),r=Ft&&Ft.__importStar||function(f){if(f&&f.__esModule)return f;var d={};if(f!=null)for(var p in f)Object.hasOwnProperty.call(f,p)&&e(d,f,p);return n(d,f),d},i=Ft&&Ft.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(t,"__esModule",{value:!0}),t.type=t.remove=t.insert=void 0;const s=o0(),o=r(sy()),l=i(pF()),a={create(f){return f},toString(f){return f},builder(f){if(typeof f!="string")throw Error("Invalid document snapshot: "+f);const d=[];return{skip(p){let g=s.uniToStrPos(f,p);if(g>f.length)throw Error("The op is too long for this document");d.push(f.slice(0,g)),f=f.slice(g)},append(p){d.push(p)},del(p){f=f.slice(s.uniToStrPos(f,p))},build(){return d.join("")+f}}},slice:o.uniSlice},u=o.default(a),c=Object.assign(Object.assign({},u),{api:l.default});t.type=c,t.insert=(f,d)=>d.length===0?[]:f===0?[d]:[f,d],t.remove=(f,d)=>o.dlen(d)===0?[]:f===0?[{d}]:[f,{d}];var h=sy();Object.defineProperty(t,"makeType",{enumerable:!0,get:function(){return h.default}})}(zg)),zg}(function(t){var e=Ft&&Ft.__importDefault||function(N){return N&&N.__esModule?N:{default:N}};Object.defineProperty(t,"__esModule",{value:!0}),t.editOp=t.replaceOp=t.insertOp=t.moveOp=t.removeOp=t.type=void 0;const n=e(t0),r=e(r0),i=i0,s=s0;function o(N,q){if(!N)throw new Error(q)}t.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:i.readCursor,writeCursor:i.writeCursor,create:N=>N,isNoop:N=>N==null,setDebug(N){},registerSubtype:y,checkValidOp:x,normalize:_,apply:E,transformPosition:A,compose:I,tryTransform:X,transform:Qe,makeInvertible:M,invert:Y,invertWithDoc:W,RM_UNEXPECTED_CONTENT:s.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:s.ConflictType.DROP_COLLISION,BLACKHOLE:s.ConflictType.BLACKHOLE,transformNoConflict:(N,q,D)=>re(()=>!0,N,q,D),typeAllowingConflictsPred:N=>Object.assign(Object.assign({},t.type),{transform:(q,D,L)=>re(N,q,D,L)})};const l=N=>N?N.getComponent():null;function a(N){return N&&typeof N=="object"&&!Array.isArray(N)}const u=N=>Array.isArray(N)?N.slice():N!==null&&typeof N=="object"?Object.assign({},N):N,c=N=>N&&(N.p!=null||N.r!==void 0),h=N=>N&&(N.d!=null||N.i!==void 0);function f(N,q){return o(N!=null),typeof q=="number"?(o(Array.isArray(N),"Invalid key - child is not an array"),(N=N.slice()).splice(q,1)):(o(a(N),"Invalid key - child is not an object"),delete(N=Object.assign({},N))[q]),N}function d(N,q,D){return typeof q=="number"?(o(N!=null,"Container is missing for key"),o(Array.isArray(N),"Cannot use numerical key for object container"),o(N.length>=q,"Cannot insert into out of bounds index"),N.splice(q,0,D)):(o(a(N),"Cannot insert into missing item"),o(N[q]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),N[q]=D),D}t.removeOp=(N,q=!0)=>i.writeCursor().writeAtPath(N,"r",q).get(),t.moveOp=(N,q)=>i.writeCursor().writeMove(N,q).get(),t.insertOp=(N,q)=>i.writeCursor().writeAtPath(N,"i",q).get(),t.replaceOp=(N,q,D)=>i.writeCursor().at(N,L=>{L.write("r",q),L.write("i",D)}).get(),t.editOp=(N,q,D,L=!1)=>i.writeCursor().at(N,B=>P(B,q,D,L)).get();const p=(N,q)=>N!=null&&(typeof q=="number"?Array.isArray(N):typeof N=="object"),g=(N,q)=>p(N,q)?N[q]:void 0,O={};function y(N){let q=N.type?N.type:N;q.name&&(O[q.name]=q),q.uri&&(O[q.uri]=q)}const m=N=>{const q=O[N];if(q)return q;throw Error("Missing type: "+N)};y(gF());const v=(N,q)=>N+q;y({name:"number",apply:v,compose:v,invert:N=>-N,transform:N=>N});const w=N=>N==null?null:N.et?m(N.et):N.es?O["text-unicode"]:N.ena!=null?O.number:null,b=N=>N.es?N.es:N.ena!=null?N.ena:N.e,P=(N,q,D,L=!1)=>{const[B,J]=typeof q=="string"?[m(q),q]:[q,q.name];!L&&B.isNoop&&B.isNoop(D)||(J==="number"?N.write("ena",D):J==="text-unicode"?N.write("es",D):(N.write("et",J),N.write("e",D)))};function C(N){o(typeof N=="number"),o(N>=0),o(N===(0|N))}function k(N){typeof N=="number"?C(N):o(typeof N=="string")}function x(N){if(N===null)return;const q=new Set,D=new Set,L=J=>{let he=!0,de=!1;for(let K in J){const se=J[K];if(he=!1,o(K==="p"||K==="r"||K==="d"||K==="i"||K==="e"||K==="es"||K==="ena"||K==="et","Invalid component item '"+K+"'"),K==="p")C(se),o(!q.has(se)),q.add(se),o(J.r===void 0);else if(K==="d")C(se),o(!D.has(se)),D.add(se),o(J.i===void 0);else if(K==="e"||K==="es"||K==="ena"){o(!de),de=!0;const ue=w(J);o(ue,"Missing type in edit"),ue.checkValidOp&&ue.checkValidOp(b(J))}}o(!he)},B=(J,he,de)=>{if(!Array.isArray(J))throw Error("Op must be null or a list");if(J.length===0)throw Error("Empty descent");he||k(J[0]);let K=1,se=0,ue=0;for(let Oe=0;Oe<J.length;Oe++){const Be=J[Oe];if(o(Be!=null),Array.isArray(Be)){const Je=B(Be,!1);if(se){const ge=typeof ue,Ze=typeof Je;ge===Ze?o(ue<Je,"descent keys are not in order"):o(ge==="number"&&Ze==="string")}ue=Je,se++,K=3}else typeof Be=="object"?(o(K===1,`Prev not scalar - instead ${K}`),L(Be),K=2):(o(K!==3),k(Be),o(i.isValidPathItem(Be),"Invalid path key"),K=1)}return o(se!==1,"Operation makes multiple descents. Remove some []"),o(K===2||K===3),J[0]};B(N,!0),o(q.size===D.size,"Mismatched picks and drops in op");for(let J=0;J<q.size;J++)o(q.has(J)),o(D.has(J))}function _(N){let q=0,D=[];const L=i.writeCursor();return L.mergeTree(N,(B,J)=>{const he=w(B);if(he){const K=b(B);P(J,he,he.normalize?he.normalize(K):K)}for(const K of["r","p","i","d"])if(B[K]!==void 0){const se=K==="p"||K==="d"?(de=B[K],D[de]==null&&(D[de]=q++),D[de]):B[K];J.write(K,se)}var de}),L.get()}function E(N,q){if(x(q),q===null)return N;const D=[];return function L(B,J){let he=B,de=0,K={root:B},se=0,ue=K,Oe="root";function Be(){for(;se<de;se++){let Je=J[se];typeof Je!="object"&&(o(p(ue,Oe)),ue=ue[Oe]=u(ue[Oe]),Oe=Je)}}for(;de<J.length;de++){const Je=J[de];if(Array.isArray(Je)){const ge=L(he,Je);ge!==he&&ge!==void 0&&(Be(),he=ue[Oe]=ge)}else if(typeof Je=="object"){Je.d!=null?(Be(),he=d(ue,Oe,D[Je.d])):Je.i!==void 0&&(Be(),he=d(ue,Oe,Je.i));const ge=w(Je);if(ge)Be(),he=ue[Oe]=ge.apply(he,b(Je));else if(Je.e!==void 0)throw Error("Subtype "+Je.et+" undefined")}else he=g(he,Je)}return K.root}(N=function L(B,J){const he=[];let de=0;for(;de<J.length;de++){const Oe=J[de];if(Array.isArray(Oe))break;typeof Oe!="object"&&(he.push(B),B=g(B,Oe))}for(let Oe=J.length-1;Oe>=de;Oe--)B=L(B,J[Oe]);for(--de;de>=0;de--){const Oe=J[de];if(typeof Oe!="object"){const Be=he.pop();B=B===g(Be,Oe)?Be:B===void 0?f(Be,Oe):(se=Oe,ue=B,(K=u(K=Be))[se]=ue,K)}else c(Oe)&&(o(B!==void 0,"Cannot pick up or remove undefined"),Oe.p!=null&&(D[Oe.p]=B),B=void 0)}var K,se,ue;return B}(N,q),q)}function A(N,q){N=N.slice(),x(q);const D=i.readCursor(q);let L,B,J=!1;const he=[];for(let K=0;;K++){const se=N[K],ue=D.getComponent();if(ue&&(ue.r!==void 0?J=!0:ue.p!=null&&(J=!1,L=ue.p,B=K)),K>=N.length)break;let Oe=0;const Be=i.advancer(D,void 0,(ge,Ze)=>{c(Ze)&&Oe++});he.unshift(Be);const Je=Be(se);if(typeof se=="number"&&(N[K]-=Oe),!Je)break}if(he.forEach(K=>K.end()),J)return null;const de=()=>{let K=0;if(L!=null){const se=D.getPath();K=se.length,N=se.concat(N.slice(B))}for(;K<N.length;K++){const se=N[K],ue=l(D),Oe=w(ue);if(Oe){const ge=b(ue);Oe.transformPosition&&(N[K]=Oe.transformPosition(N[K],ge));break}let Be=0;const Je=i.advancer(D,(ge,Ze)=>h(Ze)?~(ge-Be):ge-Be,(ge,Ze)=>{h(Ze)&&Be++})(se);if(typeof se=="number"&&(N[K]+=Be),!Je)break}};return L!=null?D.eachDrop(null,K=>{K===L&&de()}):de(),N}function I(N,q){if(x(N),x(q),N==null)return q;if(q==null)return N;let D=0;const L=i.readCursor(N),B=i.readCursor(q),J=i.writeCursor(),he=[],de=[],K=[],se=[],ue=[],Oe=[],Be=new Set;L.traverse(null,ge=>{ge.p!=null&&(K[ge.p]=L.clone())}),B.traverse(null,ge=>{ge.d!=null&&(se[ge.d]=B.clone())});const Je=i.writeCursor();return function ge(Ze,_t,mt,T,z,me,be,ye){o(_t||mt);const ve=l(_t),Fe=l(mt),ze=!!Fe&&Fe.r!==void 0,fe=!!ve&&ve.i!==void 0,Te=ve?ve.d:null,xe=Fe?Fe.p:null,_e=(me||ze)&&xe==null;if(xe!=null)T=se[xe],be=de[xe]=new i.WriteCursor;else if(Fe&&Fe.r!==void 0)T=null;else{const Ne=l(T);Ne&&Ne.d!=null&&(T=null)}const Se=l(T);if(Te!=null)if(Ze=K[Te],ye=he[Te]=new i.WriteCursor,_e)me&&!ze&&ye.write("r",!0);else{const Ne=ue[Te]=D++;be.write("d",Ne)}else if(ve&&ve.i!==void 0)Ze=null;else{const Ne=l(Ze);Ne&&Ne.p!=null&&(Ze=null)}let ce;fe?(o(z===void 0),ce=ve.i):ce=z;const $e=(xe==null?!fe||me||ze:ce===void 0)?null:be.getComponent();if(xe!=null){if(!(z!==void 0||fe)){const Ne=Te!=null?ue[Te]:D++;Oe[xe]=Ne,ye.write("p",Ne)}}else ze&&(fe||z!==void 0||(Fe.r,ye.write("r",Fe.r)));const H=_e?null:w(ve),oe=w(Se);if((H||oe)&&(H&&H.name,oe&&oe.name),H&&oe){o(H===oe);const Ne=b(ve),tt=b(Se),Pt=H.compose(Ne,tt);P(be,H,Pt),Be.add(Se)}else H?P(be,H,b(ve)):oe&&(P(be,oe,b(Se)),Be.add(Se));const Pe=typeof ce=="object"&&ce!=null;let ke=!1,Ae=0,qe=0,yt=0,dt=0,lt=0;const Ct=i.advancer(T,(Ne,tt)=>h(tt)?dt-Ne-1:Ne-dt,(Ne,tt)=>{h(tt)&&dt++}),et=i.advancer(Ze,(Ne,tt)=>c(tt)?Ae-Ne-1:Ne-Ae,(Ne,tt)=>{c(tt)&&Ae++});if(i.eachChildOf(_t,mt,(Ne,tt,Pt)=>{let Qt,pt,je=Ne,We=Ne,Ke=Ne;if(typeof Ne=="number"){let Ot=Ne+yt;pt=Ct(Ot),We=Ot+dt;let gt=Ne+qe;Qt=et(gt),h(l(pt))&&(Qt=null),je=gt+Ae,Ke=Ne+lt,o(je>=0,"p1PickKey is negative"),o(We>=0,"p2DropKey is negative");const xt=h(l(tt)),Nt=c(l(Pt));(xt||Nt&&!_e)&<--,xt&&qe--,Nt&&yt--}else Qt=et(Ne),pt=Ct(Ne);ye.descend(je),be.descend(We);const pe=Pe&&!h(l(tt))?ce[Ke]:void 0,De=ge(Qt,tt,Pt,pt,pe,_e,be,ye);var ut,Ce,nt;Pe&&!_e?pe!==De&&(ke||(ce=Array.isArray(ce)?ce.slice():Object.assign({},ce),ke=!0),ut=ce,nt=De,typeof(Ce=Ke)=="number"?(o(Array.isArray(ut)),o(Ce<ut.length)):(o(!Array.isArray(ut)),o(ut[Ce]!==void 0)),nt===void 0?typeof Ce=="number"?ut.splice(Ce,1):delete ut[Ce]:ut[Ce]=nt):o(De===void 0),be.ascend(),ye.ascend()}),et.end(),Ct.end(),$e!=null)$e.i=ce;else if(!me&&!ze&&xe==null)return ce}(L,L.clone(),B,B.clone(),void 0,!1,J,Je),J.reset(),J.mergeTree(Je.get()),J.reset(),J.get(),he.map(ge=>ge.get()),de.map(ge=>ge.get()),L.traverse(J,(ge,Ze)=>{const _t=ge.p;if(_t!=null){const mt=ue[_t];mt!=null&&Ze.write("p",mt);const T=he[_t];T&&T.get(),T&&Ze.mergeTree(T.get())}else ge.r!==void 0&&Ze.write("r",ge.r)}),J.reset(),J.get(),B.traverse(J,(ge,Ze)=>{const _t=ge.d;if(_t!=null){const T=Oe[_t];T!=null&&Ze.write("d",T);const z=de[_t];z&&Ze.mergeTree(z.get())}else ge.i!==void 0&&Ze.write("i",ge.i);const mt=w(ge);mt&&!Be.has(ge)&&P(Ze,mt,b(ge))}),J.get()}function Y(N){if(N==null)return null;const q=new i.ReadCursor(N),D=new i.WriteCursor;let L;const B=[],J=[];return function he(de,K,se){const ue=de.getComponent();let Oe,Be=!1;if(ue){ue.p!=null&&(K.write("d",ue.p),B[ue.p]=de.clone()),ue.r!==void 0&&K.write("i",ue.r),ue.d!=null&&(K.write("p",ue.d),se=void 0),ue.i!==void 0&&(se=Oe=ue.i);const ge=w(ue);ge&&(se===void 0?(L||(L=new Set),L.add(ue)):(b(ue),se=ge.apply(se,b(ue)),Be=!0))}let Je=0;for(const ge of de){K.descend(ge);const Ze=typeof ge=="number"?ge-Je:ge,_t=g(se,Ze);h(de.getComponent())&&Je++;const mt=he(de,K,_t);if(se!==void 0&&mt!==void 0){if(Be||(Be=!0,se=u(se)),!p(se,Ze))throw Error("Cannot modify child - invalid operation");se[Ze]=mt}K.ascend()}if(Oe===void 0)return Be?se:void 0;K.write("r",se)}(q,D,void 0),L&&(D.reset(),function he(de,K,se){const ue=K.getComponent();if(ue){const ge=ue.d;if(ge!=null&&(de=B[ge],se=J[ge]=i.writeCursor()),L.has(ue)){const Ze=w(ue);if(!Ze.invert)throw Error(`Cannot invert subtype ${Ze.name}`);P(se,Ze,Ze.invert(b(ue)))}}let Oe=0,Be=0;const Je=i.advancer(de,(ge,Ze)=>c(Ze)?Oe-ge-1:ge-Oe,(ge,Ze)=>{c(Ze)&&Oe++});for(const ge of K)if(typeof ge=="number"){const Ze=ge-Be,_t=Je(Ze),mt=Ze+Oe;se.descend(mt),he(_t,K,se),h(K.getComponent())&&Be++,se.ascend()}else se.descend(ge),he(Je(ge),K,se),se.ascend();Je.end()}(q.clone(),q,D),J.length&&(D.reset(),q.traverse(D,(he,de)=>{const K=he.p;if(K!=null){const se=J[K];se&&se.get(),se&&de.mergeTree(se.get())}}))),D.get()}const te=(N,q)=>N.some(D=>typeof D=="object"&&(Array.isArray(D)?te(D,q):q(D)));function M(N,q){if(N==null||!te(N,K=>{var se;return K.r!==void 0||((se=w(K))===null||se===void 0?void 0:se.makeInvertible)!=null}))return N;const D=new i.ReadCursor(N),L=new i.WriteCursor;let B=!1;const J=[],he=[],de=(K,se,ue)=>{const Oe=K.getComponent();let Be=!1;if(Oe){Oe.d!=null&&se.write("d",Oe.d),Oe.i!==void 0&&se.write("i",Oe.i);const ge=Oe.p;if(ge!=null&&(J[ge]=K.clone(),o(ue!==void 0,"Operation picks up at an invalid key"),he[ge]=ue,se.write("p",Oe.p)),Oe.r!==void 0&&ue===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const Ze=w(Oe);Ze&&(Ze.makeInvertible?B=!0:P(se,Ze,b(Oe),!0))}let Je=0;for(const ge of K){se.descend(ge);const Ze=typeof ge=="number"?ge-Je:ge,_t=g(ue,Ze),mt=de(K,se,_t);_t!==mt&&(Be||(Be=!0,ue=u(ue)),mt===void 0?(ue=f(ue,Ze),typeof ge=="number"&&Je++):ue[Ze]=mt),se.ascend()}return Oe&&(Oe.r!==void 0?(se.write("r",r.default(ue)),ue=void 0):Oe.p!=null&&(ue=void 0)),ue};return de(D,L,q),L.get(),B&&(L.reset(),function K(se,ue,Oe,Be,Je){const ge=ue.getComponent();if(ge){ge.i!==void 0?(Be=ge.i,Je=!0):ge.d!=null&&(Be=he[ge.d],se=J[ge.d],Je=!1,ge.d);let T=w(ge);if(T&&T.makeInvertible){const z=b(ge);P(Oe,T,T.makeInvertible(z,Be),!0)}}let Ze=0,_t=0;const mt=i.advancer(se,(T,z)=>c(z)?Ze-T-1:T-Ze,(T,z)=>{c(z)&&Ze++});for(const T of ue)if(typeof T=="number"){const z=T-_t,me=mt(z),be=z+Ze,ye=g(Be,Je?z:be);Oe.descend(T),K(me,ue,Oe,ye,Je),h(ue.getComponent())&&_t++,Oe.ascend()}else{const z=g(Be,T);Oe.descend(T),K(mt(T),ue,Oe,z,Je),Oe.ascend()}mt.end()}(D.clone(),D,L,q,!1)),L.get()}function W(N,q){return Y(M(N,q))}const Z=N=>{if(N==null)return null;const q=N.slice();for(let D=0;D<N.length;D++){const L=q[D];Array.isArray(L)&&(q[D]=Z(L))}return q};function X(N,q,D){o(D==="left"||D==="right","Direction must be left or right");const L=D==="left"?0:1;if(q==null)return{ok:!0,result:N};x(N),x(q);let B=null;const J=[],he=[],de=[],K=[],se=[],ue=[],Oe=[],Be=[],Je=[],ge=[],Ze=[],_t=[],mt=[],T=[],z=[];let me=0;const be=i.readCursor(N),ye=i.readCursor(q),ve=i.writeCursor();if(function Se(ce,$e=null,H){const oe=l($e);oe&&(oe.r!==void 0?H=$e.clone():oe.p!=null&&(H=null,ue[oe.p]=ce.clone()));const Pe=ce.getComponent();let ke;Pe&&(ke=Pe.p)!=null&&(se[ke]=$e?$e.clone():null,de[ke]=ce.clone(),H&&(ge[ke]=!0,Je[ke]=H),oe&&oe.p!=null&&(T[ke]=oe.p));const Ae=i.advancer($e);for(const qe of ce)Se(ce,Ae(qe),H);Ae.end()}(ye,be,null),function Se(ce,$e,H,oe,Pe){const ke=H.getComponent();let Ae,qe=!1;ke&&((Ae=ke.d)!=null?(K[Ae]=H.clone(),oe!=null&&(z[oe]==null&&(z[oe]=[]),z[oe].push(Ae)),ce=se[Ae]||null,$e=de[Ae]||null,ge[Ae]?(Pe&&(Ze[Ae]=!0),Pe=Je[Ae]||null):!Pe||L!==1&&T[Ae]!=null||B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(Pe.getPath()),op2:t.moveOp($e.getPath(),H.getPath())}),qe=!0):ke.i!==void 0&&(ce=$e=null,qe=!0,Pe&&B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(Pe.getPath()),op2:t.insertOp(H.getPath(),ke.i)})));const yt=l(ce);yt&&(yt.r!==void 0?Pe=ce.clone():yt.p!=null&&(yt.p,oe=yt.p,Pe=null));const dt=w(ke);dt&&Pe&&B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(Pe.getPath()),op2:t.editOp(H.getPath(),dt,b(ke),!0)});let lt=0,Ct=0;const et=i.advancer($e,(tt,Pt)=>c(Pt)?lt-tt-1:tt-lt,(tt,Pt)=>{c(Pt)&<++}),Ne=i.advancer(ce);for(const tt of H)if(typeof tt=="number"){const Pt=tt-Ct,Qt=et(Pt);Ct+=+Se(Ne(Pt+lt),Qt,H,oe,Pe)}else{const Pt=et(tt);Se(Ne(tt),Pt,H,oe,Pe)}return et.end(),Ne.end(),qe}(be,ye,ye.clone(),null,null),K.map(Se=>Se&&Se.get()),B)return{ok:!1,conflict:B};Ze.map(Se=>!!Se);const Fe=[];let ze=null;(function Se(ce,$e,H,oe,Pe){let ke=!1;const Ae=l($e);if(c(Ae)){const et=Ae.p;et!=null?(H=K[et],oe=_t[et]=i.writeCursor(),ke=!0,Pe=null):(H=null,Pe=$e.clone())}else h(l(H))&&(H=null);const qe=ce.getComponent();if(qe){const et=qe.p;et!=null?(Pe&&(Be[et]=Pe),Fe[et]=Pe||L===1&&ke?null:oe.getComponent(),J[et]=ce.clone(),H&&(Oe[et]=H.clone())):qe.r!==void 0&&(Pe||oe.write("r",!0),(Pe||ke)&&(ze==null&&(ze=new Set),ze.add(qe)))}let yt=0,dt=0;const lt=i.advancer($e,void 0,(et,Ne)=>{c(Ne)&&yt++}),Ct=i.advancer(H,(et,Ne)=>h(Ne)?~(et-dt):et-dt,(et,Ne)=>{h(Ne)&&dt++});if(ce)for(const et of ce)if(typeof et=="string"){const Ne=lt(et),tt=Ct(et);oe.descend(et),Se(ce,Ne,tt,oe,Pe),oe.ascend()}else{const Ne=lt(et),tt=et-yt,Pt=c(l(Ne))?null:Ct(tt),Qt=tt+dt;o(Qt>=0),oe.descend(Qt),Se(ce,Ne,Pt,oe,Pe),oe.ascend()}lt.end(),Ct.end()})(be,ye,ye.clone(),ve,null),ve.reset();let fe=[];if(function Se(ce,$e,H,oe,Pe,ke){o($e);const Ae=$e.getComponent();let qe=l(oe),yt=!1;const dt=(Ce,nt,Ot)=>Ce?t.moveOp(Ce.getPath(),nt.getPath()):t.insertOp(nt.getPath(),Ot.i);if(h(Ae)){const Ce=Ae.d;Ce!=null&&(he[Ce]=$e.clone());const nt=Ce!=null?Fe[Ce]:null;let Ot=!1;if(Ae.i!==void 0||Ce!=null&&nt){let gt;qe&&(qe.i!==void 0||(gt=qe.d)!=null&&!ge[gt])&&(Ot=gt!=null?Ce!=null&&Ce===T[gt]:n.default(qe.i,Ae.i),Ot||gt!=null&&L!==1&&T[gt]!=null||B==null&&(B={type:s.ConflictType.DROP_COLLISION,op1:dt(Ce!=null?J[Ce]:null,$e,Ae),op2:dt(gt!=null?de[gt]:null,oe,qe)})),Ot||(ke?B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:dt(Ce!=null?J[Ce]:null,$e,Ae),op2:t.removeOp(ke.getPath())}):(Ce!=null?(fe[me]=Ce,Pe.write("d",nt.p=me++)):Pe.write("i",r.default(Ae.i)),yt=!0))}else if(Ce!=null&&!nt){const gt=Be[Ce];gt&&(ke=gt.clone())}Ce!=null?(ce=J[Ce],H=ue[Ce],oe=Oe[Ce]):Ae.i!==void 0&&(ce=H=null,Ot||(oe=null))}else c(l(ce))&&(ce=H=oe=null);const lt=l(ce),Ct=l(H);if(c(Ct)){const Ce=Ct.p;Ct.r!==void 0&&(!lt||lt.r===void 0)||ge[Ce]?(oe=null,ke=H.clone()):Ce!=null&&(oe=K[Ce],L!==1&&T[Ce]!=null||((Pe=mt[Ce])||(Pe=mt[Ce]=i.writeCursor()),Pe.reset(),ke=null))}else!h(Ae)&&h(qe)&&(oe=null);qe=oe!=null?oe.getComponent():null;const et=w(Ae);if(et){const Ce=b(Ae);if(ke)B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.editOp($e.getPath(),et,Ce,!0),op2:t.removeOp(ke.getPath())});else{const nt=w(qe);let Ot;if(nt){if(et!==nt)throw Error("Transforming incompatible types");const gt=b(qe);Ot=et.transform(Ce,gt,D)}else Ot=r.default(Ce);P(Pe,et,Ot)}}let Ne=0,tt=0,Pt=0,Qt=0,pt=0,je=0,We=ce!=null&&ce.descendFirst(),Ke=We;const pe=i.advancer(H,void 0,(Ce,nt)=>{c(nt)&&Pt++});let De=oe!=null&&oe.descendFirst(),ut=De;for(const Ce of $e)if(typeof Ce=="number"){let nt;const Ot=h($e.getComponent()),gt=Ce-tt;{let wt;for(;We&&typeof(wt=ce.getKey())=="number";){wt+=Ne;const jt=ce.getComponent(),Tn=c(jt);if(wt>gt||wt===gt&&(!Tn||L===0&&Ot))break;if(Tn){Ne--;const mn=jt.p;T.includes(mn),jt.d,l(mt[jt.d]),c(l(mt[jt.d])),(jt.r===void 0||ze&&ze.has(jt))&&(mn==null||!Fe[mn]||L!==1&&T.includes(mn))||pt--}We=ce.nextSibling()}nt=We&&wt===gt?ce:null}const xt=gt-Ne;let Nt=pe(xt);const St=xt-Pt;let ct=null;{let wt,jt;for(;De&&typeof(wt=oe.getKey())=="number";){jt=wt-Qt;const Tn=oe.getComponent(),mn=h(Tn);if(jt>St)break;if(jt===St){if(!mn){ct=oe;break}{if(L===0&&Ot){ct=oe;break}const On=Nt&&c(Nt.getComponent());if(L===0&&On)break}}if(mn){const On=Tn.d;T[On],Tn.i===void 0&&(ge[On]||T[On]!=null&&L!==1)?(ge[On]||T[On]!=null&&L===0)&&(Qt++,je--):Qt++}De=oe.nextSibling()}}const Ve=St+Qt+pt+je;o(Ve>=0,"trying to descend to a negative index"),Pe.descend(Ve),Ot&&(nt=Nt=ct=null,tt++),Se(nt,$e,Nt,ct,Pe,ke)&&je++,Pe.ascend()}else{let nt;for(;We&&(nt=ce.getKey(),typeof nt!="string"||!(nt>Ce||nt===Ce));)We=ce.nextSibling();const Ot=We&&nt===Ce?ce:null,gt=pe(Ce);let xt;for(;De&&(xt=oe.getKey(),typeof xt!="string"||!(xt>Ce||xt===Ce));)De=oe.nextSibling();const Nt=De&&xt===Ce?oe:null;Pe.descend(Ce),Se(Ot,$e,gt,Nt,Pe,ke),Pe.ascend()}return pe.end(),Ke&&ce.ascend(),ut&&oe.ascend(),yt}(be,be.clone(),ye,ye.clone(),ve,null),B)return{ok:!1,conflict:B};ve.reset();const Te=(Se,ce,$e)=>Se.traverse(ce,(H,oe)=>{H.d!=null&&$e(H.d,Se,oe)});(ge.length||_t.length)&&(Te(ye,ve,(Se,ce,$e)=>{ge[Se]&&!Ze[Se]&&$e.write("r",!0),_t[Se]&&$e.mergeTree(_t[Se].get())}),ve.reset());const xe=[],_e=[];if((mt.length||ge.length)&&!B){const Se=i.readCursor(Z(ve.get()));if(Te(Se,null,(ce,$e)=>{xe[ce]=$e.clone()}),mt.forEach(ce=>{ce&&Te(i.readCursor(ce.get()),null,($e,H)=>{xe[$e]=H.clone()})}),function ce($e,H,oe,Pe,ke,Ae){const qe=l(H);if(qe&&c(qe))if(qe.p!=null){const Ne=qe.p;xe[Ne].getPath(),oe=xe[Ne],Pe=_e[Ne]=i.writeCursor()}else qe.r!==void 0&&(oe=null);else h(l(oe))&&(oe=null);const yt=$e.getComponent();if(yt){let Ne;if((Ne=yt.d)!=null){const tt=mt[Ne];tt&&(tt.get(),Pe.mergeTree(tt.get()),oe=i.readCursor(tt.get()))}}let dt=0,lt=0;const Ct=i.advancer(H,void 0,(Ne,tt)=>{c(tt)&&dt--}),et=i.advancer(oe,(Ne,tt)=>h(tt)?-(Ne-lt)-1:Ne-lt,(Ne,tt)=>{h(tt)&<++});for(const Ne of $e)if(typeof Ne=="number"){const tt=Ct(Ne),Pt=Ne+dt,Qt=et(Pt),pt=Pt+lt;Pe.descend(pt),ce($e,tt,Qt,Pe),Pe.ascend()}else Pe.descend(Ne),ce($e,Ct(Ne),et(Ne),Pe),Pe.ascend();Ct.end(),et.end()}(ye,Se,Se.clone(),ve),ve.reset(),B)return{ok:!1,conflict:B};if(ve.get(),_e.length){const ce=_e.map(H=>H?H.get():null),$e=i.readCursor(Z(ve.get()));if(Te($e,ve,(H,oe,Pe)=>{const ke=ce[H];ke&&(Pe.mergeTree(ke),ce[H]=null)}),ce.find(H=>H)){const H=i.writeCursor(),oe=i.writeCursor();let Pe=0,ke=0;ce.forEach(Ae=>{Ae!=null&&Te(i.readCursor(Ae),null,qe=>{const yt=fe[qe];H.writeMove(J[yt].getPath(),he[yt].getPath(),Pe++);const dt=z[yt];dt&&dt.forEach(lt=>{ge[lt]||L!==1&&T[lt]!=null||oe.writeMove(de[lt].getPath(),K[lt].getPath(),ke++)})})}),B={type:s.ConflictType.BLACKHOLE,op1:H.get(),op2:oe.get()}}}}return B?{ok:!1,conflict:B}:{ok:!0,result:ve.get()}}const G=N=>{const q=new Error("Transform detected write conflict");throw q.conflict=N,q.type=q.name="writeConflict",q};function Qe(N,q,D){const L=X(N,q,D);if(L.ok)return L.result;G(L.conflict)}const Me=N=>{const q=i.writeCursor();return i.readCursor(N).traverse(q,(D,L)=>{(h(D)||w(D))&&L.write("r",!0)}),q.get()},U=(N,q)=>{const{type:D,op1:L,op2:B}=N;switch(D){case s.ConflictType.DROP_COLLISION:return q==="left"?[null,Me(B)]:[Me(L),null];case s.ConflictType.RM_UNEXPECTED_CONTENT:let J=!1;return i.readCursor(L).traverse(null,he=>{he.r!==void 0&&(J=!0)}),J?[null,Me(B)]:[Me(L),null];case s.ConflictType.BLACKHOLE:return[Me(L),Me(B)];default:throw Error("Unrecognised conflict: "+D)}};function re(N,q,D,L){let B=null;for(;;){const J=X(q,D,L);if(J.ok)return I(B,J.result);{const{conflict:he}=J;N(he)||G(he);const[de,K]=U(he,L);q=I(_(q),de),D=I(_(D),K),B=I(B,K)}}}})(UQ);(function(t){var e=Ft&&Ft.__createBinding||(Object.create?function(s,o,l,a){a===void 0&&(a=l),Object.defineProperty(s,a,{enumerable:!0,get:function(){return o[l]}})}:function(s,o,l,a){a===void 0&&(a=l),s[a]=o[l]}),n=Ft&&Ft.__exportStar||function(s,o){for(var l in s)l!=="default"&&!o.hasOwnProperty(l)&&e(o,s,l)};Object.defineProperty(t,"__esModule",{value:!0}),n(UQ,t);var r=i0;Object.defineProperty(t,"ReadCursor",{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(t,"WriteCursor",{enumerable:!0,get:function(){return r.WriteCursor}});var i=s0;Object.defineProperty(t,"ConflictType",{enumerable:!0,get:function(){return i.ConflictType}})})(Ld);const mF=({shareDBDoc:t,fileId:e,tabList:n,aiAssistEndpoint:r="/AIAssist",aiAssistOptions:i={}})=>aa.of([{key:"control-m",run:s=>{var o;return t.data.aiStreams===void 0||t.data.aiStreams[ia]===null||((o=t.data.aiStreams[ia])==null?void 0:o.AIStreamStatus.serverIsRunning)!==!0?FQ(s,t,e,n):zQ(t),!0}}]);let ia=null;const FQ=async(t,e,n,r)=>{const i=await OF(r.map(s=>e.data.files[s.fileId]))+`Current File:
|
|
112
|
-
`+t.state.sliceDoc(0,t.state.selection.main.to);console.log(i),ia=
|
|
111
|
+
`){i++,r=n.next();continue}const s=r.value.matchAll(new RegExp('\\"\\#([0-9]|[A-F]|[a-f]){6}\\"|rotate\\(-?\\d*\\.?\\d*\\)|https?:\\/\\/[^ "]+|vec2\\(-?\\b\\d+\\.?\\d*\\b\\s*(,\\s*-?\\b\\d+\\.?\\d*\\b)?\\)|true|false|(?<!\\#)-?\\b\\d+\\.?\\d*\\b|rgb\\(.*\\)',"dg"));let o=s.next();for(;!o.done;){const l=o.value;l.indices[0][0]+=i,l.indices[0][1]+=i,e.push(l),o=s.next()}i+=r.value.length,r=n.next()}return He.set(e.map(s=>({from:s.indices[0][0],to:s.indices[0][1],value:He.mark({class:"cm-interact "})})))},eventHandlers:{keydown(t,e){t.key=="Alt"&&(this.showHighlight=!0)},keyup(t,e){t.key=="Alt"&&(this.showHighlight=!1)}}}),uF=qt.fromClass(class{constructor(t){this.view=t,this.textPosition=null,this.rotation=0,document.addEventListener("updateRotateDrag",e=>{this.textPosition=this.view.posAtCoords(vo,!1),this.rotation=e.detail})}},{decorations:t=>vo===null?He.none:He.set([{from:t.textPosition,to:t.textPosition,value:He.widget({side:-1,widget:new cF(t.rotation)})}])});class cF extends qr{constructor(e){super(),this.angle=e}toDOM(e){const n=document.createElement("div");n.setAttribute("style","width:20px;height:20px"),n.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 s=document.createElementNS("http://www.w3.org/2000/svg","line");return s.setAttributeNS(null,"x1","10"),s.setAttributeNS(null,"x2","5"),s.setAttributeNS(null,"y1","5"),s.setAttributeNS(null,"y2","5"),s.setAttributeNS(null,"stroke","black"),s.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(s),n.appendChild(r),n}ignoreEvent(){return!1}}var Ld={},UQ={},e0={};Object.defineProperty(e0,"__esModule",{value:!0});function fF(t,e){if(Array.isArray(e))return!1;for(let n in t)if(!t0(t[n],e[n]))return!1;for(let n in e)if(t[n]===void 0)return!1;return!0}function hF(t,e){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(!t0(t[n],e[n]))return!1;return!0}function t0(t,e){return t===e?!0:t===null||e===null||typeof t!="object"||typeof e!="object"?!1:Array.isArray(t)?hF(t,e):fF(t,e)}e0.default=t0;var n0={};Object.defineProperty(n0,"__esModule",{value:!0});function iy(t){if(t===null)return null;if(Array.isArray(t))return t.map(iy);if(typeof t=="object"){const e={};for(let n in t)e[n]=iy(t[n]);return e}else return t}n0.default=iy;var r0={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.eachChildOf=t.advancer=t.readCursor=t.writeCursor=t.WriteCursor=t.ReadCursor=t.isValidPathItem=void 0;function e(c,h){if(!c)throw new Error(h)}const n=c=>c!=null&&typeof c=="object"&&!Array.isArray(c),r=(c,h)=>typeof c==typeof h?c>h:typeof c=="string"&&typeof h=="number";function i(c,h){for(let f in c){const d=f;h.write(d,c[d])}}t.isValidPathItem=c=>typeof c=="number"||typeof c=="string"&&c!=="__proto__";class s{constructor(h=null){this.parents=[],this.indexes=[],this.lcIdx=-1,this.idx=-1,this.container=h}ascend(){e(this.parents.length===this.indexes.length/2),this.idx===0?this.parents.length?(this.lcIdx=this.indexes.pop(),this.container=this.parents.pop(),this.idx=this.indexes.pop()):(this.lcIdx=0,this.idx=-1):(e(this.idx>0),this.idx--,n(this.container[this.idx])&&this.idx--)}getPath(){const h=[];let f=this.container,d=this.parents.length-1,p=this.idx;for(;p>=0;)h.unshift(f[p]),p===0?(p=this.indexes[d*2],f=this.parents[d--]):p-=n(f[p-1])?2:1;return h}}class o extends s{get(){return this.container?this.container.slice(this.idx+1):null}getKey(){return e(this.container!=null,"Invalid call to getKey before cursor descended"),this.container[this.idx]}getComponent(){let h;return this.container&&this.container.length>this.idx+1&&n(h=this.container[this.idx+1])?h:null}descendFirst(){let h=this.idx+1;if(!this.container||h>=this.container.length||n(this.container[h])&&h+1>=this.container.length)return!1;n(this.container[h])&&h++;const f=this.container[h];return Array.isArray(f)?(this.indexes.push(this.idx),this.parents.push(this.container),this.indexes.push(h),this.idx=0,this.container=f):this.idx=h,!0}nextSibling(){if(e(this.parents.length===this.indexes.length/2),this.idx>0||this.parents.length===0)return!1;const h=this.indexes[this.indexes.length-1]+1,f=this.parents[this.parents.length-1];return h>=f.length?!1:(e(!isNaN(h)),this.indexes[this.indexes.length-1]=h,this.container=f[h],!0)}_init(h,f,d,p){this.container=h,this.idx=f,this.parents=d.slice(),this.indexes=p.slice()}clone(){const h=new o;return h._init(this.container,this.idx,this.parents,this.indexes),h}*[Symbol.iterator](){if(this.descendFirst()){do yield this.getKey();while(this.nextSibling());this.ascend()}}traverse(h,f){const d=this.getComponent();d&&f(d,h);for(const p of this)h&&h.descend(p),this.traverse(h,f),h&&h.ascend()}eachPick(h,f){this.traverse(h,(d,p)=>{d.p!=null&&f(d.p,p)})}eachDrop(h,f){this.traverse(h,(d,p)=>{d.d!=null&&f(d.d,p)})}}t.ReadCursor=o;class l extends s{constructor(h=null){super(h),this.pendingDescent=[],this._op=h}flushDescent(){e(this.parents.length===this.indexes.length/2),this.container===null&&(this._op=this.container=[]);for(let h=0;h<this.pendingDescent.length;h++){const f=this.pendingDescent[h];let d=this.idx+1;if(d<this.container.length&&n(this.container[d])&&d++,e(d===this.container.length||!n(this.container[d])),d===this.container.length)this.container.push(f),this.idx=d;else if(this.container[d]===f)this.idx=d;else{if(!Array.isArray(this.container[d])){const p=this.container.splice(d,this.container.length-d);this.container.push(p),this.lcIdx>-1&&(this.lcIdx=d)}for(this.indexes.push(this.idx),this.parents.push(this.container),this.lcIdx!==-1&&(e(r(f,this.container[this.lcIdx][0])),d=this.lcIdx+1,this.lcIdx=-1);d<this.container.length&&r(f,this.container[d][0]);)d++;if(this.indexes.push(d),this.idx=0,d<this.container.length&&this.container[d][0]===f)this.container=this.container[d];else{const p=[f];this.container.splice(d,0,p),this.container=p}}}this.pendingDescent.length=0}reset(){this.lcIdx=-1}getComponent(){this.flushDescent();const h=this.idx+1;if(h<this.container.length&&n(this.container[h]))return this.container[h];{const f={};return this.container.splice(h,0,f),f}}write(h,f){const d=this.getComponent();e(d[h]==null||d[h]===f,"Internal consistency error: Overwritten component. File a bug"),d[h]=f}get(){return this._op}descend(h){if(!t.isValidPathItem(h))throw Error("Invalid JSON key");this.pendingDescent.push(h)}descendPath(h){return this.pendingDescent.push(...h),this}ascend(){this.pendingDescent.length?this.pendingDescent.pop():super.ascend()}mergeTree(h,f=i){if(h===null)return;if(e(Array.isArray(h)),h===this._op)throw Error("Cannot merge into my own tree");const d=this.lcIdx,p=this.parents.length;let g=0;for(let O=0;O<h.length;O++){const y=h[O];typeof y=="string"||typeof y=="number"?(g++,this.descend(y)):Array.isArray(y)?this.mergeTree(y,f):typeof y=="object"&&f(y,this)}for(;g--;)this.ascend();this.lcIdx=this.parents.length===p?d:-1}at(h,f){this.descendPath(h),f(this);for(let d=0;d<h.length;d++)this.ascend();return this}writeAtPath(h,f,d){return this.at(h,()=>this.write(f,d)),this.reset(),this}writeMove(h,f,d=0){return this.writeAtPath(h,"p",d).writeAtPath(f,"d",d)}getPath(){const h=super.getPath();return h.push(...this.pendingDescent),h}}t.WriteCursor=l,t.writeCursor=()=>new l,t.readCursor=c=>new o(c);function a(c,h,f){let d,p;p=d=c?c.descendFirst():!1;function g(O){let y;for(;p;){const m=y=c.getKey();if(O!=null){let v=!1;if(h&&typeof m=="number"&&(y=h(m,c.getComponent()),y<0&&(y=~y,v=!0)),r(y,O))return null;if(y===O&&!v)return c}f&&typeof y=="number"&&f(y,c.getComponent()),p=c.nextSibling()}return null}return g.end=()=>{d&&c.ascend()},g}t.advancer=a;function u(c,h,f){let d,p,g,O;for(d=p=c&&c.descendFirst(),g=O=h&&h.descendFirst();d||g;){let y=d?c.getKey():null,m=g?h.getKey():null;y!==null&&m!==null&&(r(m,y)?m=null:y!==m&&(y=null)),f(y??m,y!=null?c:null,m!=null?h:null),y!=null&&d&&(d=c.nextSibling()),m!=null&&g&&(g=h.nextSibling())}p&&c.ascend(),O&&h.ascend()}t.eachChildOf=u})(r0);var i0={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ConflictType=void 0,function(e){e[e.RM_UNEXPECTED_CONTENT=1]="RM_UNEXPECTED_CONTENT",e[e.DROP_COLLISION=2]="DROP_COLLISION",e[e.BLACKHOLE=3]="BLACKHOLE"}(t.ConflictType||(t.ConflictType={}))})(i0);var zg={},co={},sx;function s0(){return sx||(sx=1,Object.defineProperty(co,"__esModule",{value:!0}),co.uniToStrPos=co.strPosToUni=void 0,co.strPosToUni=(t,e=t.length)=>{let n=0,r=0;for(;r<e;r++){const i=t.charCodeAt(r);i>=55296&&i<=57343&&(n++,r++)}if(r!==e)throw Error("Invalid offset - splits unicode bytes");return r-n},co.uniToStrPos=(t,e)=>{let n=0;for(;e>0;e--){const r=t.charCodeAt(n);n+=r>=55296&&r<=57343?2:1}return n}),co}var qg={},ox;function sy(){return ox||(ox=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.uniSlice=t.dlen=t.eachOp=void 0;const e=s0(),n=b=>{if(!Array.isArray(b))throw Error("Op must be an array of components");let P=null;for(let C=0;C<b.length;C++){const k=b[C];switch(typeof k){case"object":if(typeof k.d!="number"&&typeof k.d!="string")throw Error("Delete must be number or string");if(t.dlen(k.d)<=0)throw Error("Deletes must not be empty");break;case"string":if(!(k.length>0))throw Error("Inserts cannot be empty");break;case"number":if(!(k>0))throw Error("Skip components must be >0");if(typeof P=="number")throw Error("Adjacent skip components should be combined");break}P=k}if(typeof P=="number")throw Error("Op has a trailing skip")};function r(b,P){let C=0,k=0;for(let x=0;x<b.length;x++){const _=b[x];switch(P(_,C,k),typeof _){case"object":C+=t.dlen(_.d);break;case"string":k+=e.strPosToUni(_);break;case"number":C+=_,k+=_;break}}}t.eachOp=r;function i(b,P){const C=[],k=l(C);return r(b,(x,_,E)=>{k(P(x,_,E))}),h(C)}const s=b=>b,o=b=>i(b,s);t.dlen=b=>typeof b=="number"?b:e.strPosToUni(b);const l=b=>P=>{if(!(!P||P.d===0||P.d===""))if(b.length===0)b.push(P);else if(typeof P==typeof b[b.length-1])if(typeof P=="object"){const C=b[b.length-1];C.d=typeof C.d=="string"&&typeof P.d=="string"?C.d+P.d:t.dlen(C.d)+t.dlen(P.d)}else b[b.length-1]+=P;else b.push(P)},a=b=>typeof b=="number"?b:typeof b=="string"?e.strPosToUni(b):typeof b.d=="number"?b.d:e.strPosToUni(b.d);t.uniSlice=(b,P,C)=>{const k=e.uniToStrPos(b,P),x=C==null?1/0:e.uniToStrPos(b,C);return b.slice(k,x)};const u=(b,P,C)=>typeof b=="number"?C==null?b-P:Math.min(b,C)-P:t.uniSlice(b,P,C),c=b=>{let P=0,C=0;return{take:(_,E)=>{if(P===b.length)return _===-1?null:_;const A=b[P];let I;if(typeof A=="number")return _===-1||A-C<=_?(I=A-C,++P,C=0,I):(C+=_,_);if(typeof A=="string"){if(_===-1||E==="i"||e.strPosToUni(A.slice(C))<=_)return I=A.slice(C),++P,C=0,I;{const Y=C+e.uniToStrPos(A.slice(C),_);return I=A.slice(C,Y),C=Y,I}}else{if(_===-1||E==="d"||t.dlen(A.d)-C<=_)return I={d:u(A.d,C)},++P,C=0,I;{let Y=u(A.d,C,C+_);return C+=_,{d:Y}}}},peek:()=>b[P]}},h=b=>(b.length>0&&typeof b[b.length-1]=="number"&&b.pop(),b);function f(b,P,C){if(C!=="left"&&C!=="right")throw Error("side ("+C+") must be 'left' or 'right'");n(b),n(P);const k=[],x=l(k),{take:_,peek:E}=c(b);for(let I=0;I<P.length;I++){const Y=P[I];let te,M;switch(typeof Y){case"number":for(te=Y;te>0;)M=_(te,"i"),x(M),typeof M!="string"&&(te-=a(M));break;case"string":C==="left"&&typeof E()=="string"&&x(_(-1)),x(e.strPosToUni(Y));break;case"object":for(te=t.dlen(Y.d);te>0;)switch(M=_(te,"i"),typeof M){case"number":te-=M;break;case"string":x(M);break;case"object":te-=t.dlen(M.d)}break}}let A;for(;A=_(-1);)x(A);return h(k)}function d(b,P){n(b),n(P);const C=[],k=l(C),{take:x}=c(b);for(let E=0;E<P.length;E++){const A=P[E];let I,Y;switch(typeof A){case"number":for(I=A;I>0;)Y=x(I,"d"),k(Y),typeof Y!="object"&&(I-=a(Y));break;case"string":k(A);break;case"object":I=t.dlen(A.d);let te=0;for(;te<I;)switch(Y=x(I-te,"d"),typeof Y){case"number":k({d:u(A.d,te,te+Y)}),te+=Y;break;case"string":te+=e.strPosToUni(Y);break;case"object":k(Y)}break}}let _;for(;_=x(-1);)k(_);return h(C)}const p=(b,P)=>{let C=0;for(let k=0;k<P.length&&b>C;k++){const x=P[k];switch(typeof x){case"number":{C+=x;break}case"string":const _=e.strPosToUni(x);C+=_,b+=_;break;case"object":b-=Math.min(t.dlen(x.d),b-C);break}}return b},g=(b,P)=>typeof b=="number"?p(b,P):b.map(C=>p(C,P));function O(b,P,C){return i(b,(k,x)=>typeof k=="object"&&typeof k.d=="number"?{d:C.slice(P,x,x+k.d)}:k)}function y(b){return i(b,P=>{switch(typeof P){case"object":if(typeof P.d=="number")throw Error("Cannot invert text op: Deleted characters missing from operation. makeInvertible must be called first.");return P.d;case"string":return{d:P};case"number":return P}})}function m(b){return i(b,P=>typeof P=="object"&&typeof P.d=="string"?{d:e.strPosToUni(P.d)}:P)}function v(b){let P=!0;return r(b,C=>{typeof C=="object"&&typeof C.d=="number"&&(P=!1)}),P}function w(b){return{name:"text-unicode",uri:"http://sharejs.org/types/text-unicode",trim:h,normalize:o,checkOp:n,create(P=""){if(typeof P!="string")throw Error("Initial data must be a string");return b.create(P)},apply(P,C){n(C);const k=b.builder(P);for(let x=0;x<C.length;x++){const _=C[x];switch(typeof _){case"number":k.skip(_);break;case"string":k.append(_);break;case"object":k.del(t.dlen(_.d));break}}return k.build()},transform:f,compose:d,transformPosition:p,transformSelection:g,isInvertible:v,makeInvertible(P,C){return O(P,C,b)},stripInvertible:m,invert:y,invertWithDoc(P,C){return y(O(P,C,b))},isNoop:P=>P.length===0}}t.default=w}(qg)),qg}var sh={},lx;function dF(){if(lx)return sh;lx=1,Object.defineProperty(sh,"__esModule",{value:!0});const t=sy(),e=s0();function n(r,i){return{get:r,getLength(){return r().length},insert(s,o,l){const a=e.strPosToUni(r(),s);return i([a,o],l)},remove(s,o,l){const a=e.strPosToUni(r(),s);return i([a,{d:o}],l)},_onOp(s){t.eachOp(s,(o,l,a)=>{switch(typeof o){case"string":this.onInsert&&this.onInsert(a,o);break;case"object":const u=t.dlen(o.d);this.onRemove&&this.onRemove(a,u)}})},onInsert:null,onRemove:null}}return sh.default=n,n.provides={text:!0},sh}var ax;function pF(){return ax||(ax=1,function(t){var e=Ft&&Ft.__createBinding||(Object.create?function(f,d,p,g){g===void 0&&(g=p),Object.defineProperty(f,g,{enumerable:!0,get:function(){return d[p]}})}:function(f,d,p,g){g===void 0&&(g=p),f[g]=d[p]}),n=Ft&&Ft.__setModuleDefault||(Object.create?function(f,d){Object.defineProperty(f,"default",{enumerable:!0,value:d})}:function(f,d){f.default=d}),r=Ft&&Ft.__importStar||function(f){if(f&&f.__esModule)return f;var d={};if(f!=null)for(var p in f)Object.hasOwnProperty.call(f,p)&&e(d,f,p);return n(d,f),d},i=Ft&&Ft.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(t,"__esModule",{value:!0}),t.type=t.remove=t.insert=void 0;const s=s0(),o=r(sy()),l=i(dF()),a={create(f){return f},toString(f){return f},builder(f){if(typeof f!="string")throw Error("Invalid document snapshot: "+f);const d=[];return{skip(p){let g=s.uniToStrPos(f,p);if(g>f.length)throw Error("The op is too long for this document");d.push(f.slice(0,g)),f=f.slice(g)},append(p){d.push(p)},del(p){f=f.slice(s.uniToStrPos(f,p))},build(){return d.join("")+f}}},slice:o.uniSlice},u=o.default(a),c=Object.assign(Object.assign({},u),{api:l.default});t.type=c,t.insert=(f,d)=>d.length===0?[]:f===0?[d]:[f,d],t.remove=(f,d)=>o.dlen(d)===0?[]:f===0?[{d}]:[f,{d}];var h=sy();Object.defineProperty(t,"makeType",{enumerable:!0,get:function(){return h.default}})}(zg)),zg}(function(t){var e=Ft&&Ft.__importDefault||function(N){return N&&N.__esModule?N:{default:N}};Object.defineProperty(t,"__esModule",{value:!0}),t.editOp=t.replaceOp=t.insertOp=t.moveOp=t.removeOp=t.type=void 0;const n=e(e0),r=e(n0),i=r0,s=i0;function o(N,q){if(!N)throw new Error(q)}t.type={name:"json1",uri:"http://sharejs.org/types/JSONv1",readCursor:i.readCursor,writeCursor:i.writeCursor,create:N=>N,isNoop:N=>N==null,setDebug(N){},registerSubtype:y,checkValidOp:x,normalize:_,apply:E,transformPosition:A,compose:I,tryTransform:X,transform:Qe,makeInvertible:M,invert:Y,invertWithDoc:W,RM_UNEXPECTED_CONTENT:s.ConflictType.RM_UNEXPECTED_CONTENT,DROP_COLLISION:s.ConflictType.DROP_COLLISION,BLACKHOLE:s.ConflictType.BLACKHOLE,transformNoConflict:(N,q,D)=>re(()=>!0,N,q,D),typeAllowingConflictsPred:N=>Object.assign(Object.assign({},t.type),{transform:(q,D,L)=>re(N,q,D,L)})};const l=N=>N?N.getComponent():null;function a(N){return N&&typeof N=="object"&&!Array.isArray(N)}const u=N=>Array.isArray(N)?N.slice():N!==null&&typeof N=="object"?Object.assign({},N):N,c=N=>N&&(N.p!=null||N.r!==void 0),h=N=>N&&(N.d!=null||N.i!==void 0);function f(N,q){return o(N!=null),typeof q=="number"?(o(Array.isArray(N),"Invalid key - child is not an array"),(N=N.slice()).splice(q,1)):(o(a(N),"Invalid key - child is not an object"),delete(N=Object.assign({},N))[q]),N}function d(N,q,D){return typeof q=="number"?(o(N!=null,"Container is missing for key"),o(Array.isArray(N),"Cannot use numerical key for object container"),o(N.length>=q,"Cannot insert into out of bounds index"),N.splice(q,0,D)):(o(a(N),"Cannot insert into missing item"),o(N[q]===void 0,"Trying to overwrite value at key. Your op needs to remove it first"),N[q]=D),D}t.removeOp=(N,q=!0)=>i.writeCursor().writeAtPath(N,"r",q).get(),t.moveOp=(N,q)=>i.writeCursor().writeMove(N,q).get(),t.insertOp=(N,q)=>i.writeCursor().writeAtPath(N,"i",q).get(),t.replaceOp=(N,q,D)=>i.writeCursor().at(N,L=>{L.write("r",q),L.write("i",D)}).get(),t.editOp=(N,q,D,L=!1)=>i.writeCursor().at(N,B=>P(B,q,D,L)).get();const p=(N,q)=>N!=null&&(typeof q=="number"?Array.isArray(N):typeof N=="object"),g=(N,q)=>p(N,q)?N[q]:void 0,O={};function y(N){let q=N.type?N.type:N;q.name&&(O[q.name]=q),q.uri&&(O[q.uri]=q)}const m=N=>{const q=O[N];if(q)return q;throw Error("Missing type: "+N)};y(pF());const v=(N,q)=>N+q;y({name:"number",apply:v,compose:v,invert:N=>-N,transform:N=>N});const w=N=>N==null?null:N.et?m(N.et):N.es?O["text-unicode"]:N.ena!=null?O.number:null,b=N=>N.es?N.es:N.ena!=null?N.ena:N.e,P=(N,q,D,L=!1)=>{const[B,J]=typeof q=="string"?[m(q),q]:[q,q.name];!L&&B.isNoop&&B.isNoop(D)||(J==="number"?N.write("ena",D):J==="text-unicode"?N.write("es",D):(N.write("et",J),N.write("e",D)))};function C(N){o(typeof N=="number"),o(N>=0),o(N===(0|N))}function k(N){typeof N=="number"?C(N):o(typeof N=="string")}function x(N){if(N===null)return;const q=new Set,D=new Set,L=J=>{let he=!0,de=!1;for(let K in J){const se=J[K];if(he=!1,o(K==="p"||K==="r"||K==="d"||K==="i"||K==="e"||K==="es"||K==="ena"||K==="et","Invalid component item '"+K+"'"),K==="p")C(se),o(!q.has(se)),q.add(se),o(J.r===void 0);else if(K==="d")C(se),o(!D.has(se)),D.add(se),o(J.i===void 0);else if(K==="e"||K==="es"||K==="ena"){o(!de),de=!0;const ue=w(J);o(ue,"Missing type in edit"),ue.checkValidOp&&ue.checkValidOp(b(J))}}o(!he)},B=(J,he,de)=>{if(!Array.isArray(J))throw Error("Op must be null or a list");if(J.length===0)throw Error("Empty descent");he||k(J[0]);let K=1,se=0,ue=0;for(let Oe=0;Oe<J.length;Oe++){const Be=J[Oe];if(o(Be!=null),Array.isArray(Be)){const Je=B(Be,!1);if(se){const ge=typeof ue,Ze=typeof Je;ge===Ze?o(ue<Je,"descent keys are not in order"):o(ge==="number"&&Ze==="string")}ue=Je,se++,K=3}else typeof Be=="object"?(o(K===1,`Prev not scalar - instead ${K}`),L(Be),K=2):(o(K!==3),k(Be),o(i.isValidPathItem(Be),"Invalid path key"),K=1)}return o(se!==1,"Operation makes multiple descents. Remove some []"),o(K===2||K===3),J[0]};B(N,!0),o(q.size===D.size,"Mismatched picks and drops in op");for(let J=0;J<q.size;J++)o(q.has(J)),o(D.has(J))}function _(N){let q=0,D=[];const L=i.writeCursor();return L.mergeTree(N,(B,J)=>{const he=w(B);if(he){const K=b(B);P(J,he,he.normalize?he.normalize(K):K)}for(const K of["r","p","i","d"])if(B[K]!==void 0){const se=K==="p"||K==="d"?(de=B[K],D[de]==null&&(D[de]=q++),D[de]):B[K];J.write(K,se)}var de}),L.get()}function E(N,q){if(x(q),q===null)return N;const D=[];return function L(B,J){let he=B,de=0,K={root:B},se=0,ue=K,Oe="root";function Be(){for(;se<de;se++){let Je=J[se];typeof Je!="object"&&(o(p(ue,Oe)),ue=ue[Oe]=u(ue[Oe]),Oe=Je)}}for(;de<J.length;de++){const Je=J[de];if(Array.isArray(Je)){const ge=L(he,Je);ge!==he&&ge!==void 0&&(Be(),he=ue[Oe]=ge)}else if(typeof Je=="object"){Je.d!=null?(Be(),he=d(ue,Oe,D[Je.d])):Je.i!==void 0&&(Be(),he=d(ue,Oe,Je.i));const ge=w(Je);if(ge)Be(),he=ue[Oe]=ge.apply(he,b(Je));else if(Je.e!==void 0)throw Error("Subtype "+Je.et+" undefined")}else he=g(he,Je)}return K.root}(N=function L(B,J){const he=[];let de=0;for(;de<J.length;de++){const Oe=J[de];if(Array.isArray(Oe))break;typeof Oe!="object"&&(he.push(B),B=g(B,Oe))}for(let Oe=J.length-1;Oe>=de;Oe--)B=L(B,J[Oe]);for(--de;de>=0;de--){const Oe=J[de];if(typeof Oe!="object"){const Be=he.pop();B=B===g(Be,Oe)?Be:B===void 0?f(Be,Oe):(se=Oe,ue=B,(K=u(K=Be))[se]=ue,K)}else c(Oe)&&(o(B!==void 0,"Cannot pick up or remove undefined"),Oe.p!=null&&(D[Oe.p]=B),B=void 0)}var K,se,ue;return B}(N,q),q)}function A(N,q){N=N.slice(),x(q);const D=i.readCursor(q);let L,B,J=!1;const he=[];for(let K=0;;K++){const se=N[K],ue=D.getComponent();if(ue&&(ue.r!==void 0?J=!0:ue.p!=null&&(J=!1,L=ue.p,B=K)),K>=N.length)break;let Oe=0;const Be=i.advancer(D,void 0,(ge,Ze)=>{c(Ze)&&Oe++});he.unshift(Be);const Je=Be(se);if(typeof se=="number"&&(N[K]-=Oe),!Je)break}if(he.forEach(K=>K.end()),J)return null;const de=()=>{let K=0;if(L!=null){const se=D.getPath();K=se.length,N=se.concat(N.slice(B))}for(;K<N.length;K++){const se=N[K],ue=l(D),Oe=w(ue);if(Oe){const ge=b(ue);Oe.transformPosition&&(N[K]=Oe.transformPosition(N[K],ge));break}let Be=0;const Je=i.advancer(D,(ge,Ze)=>h(Ze)?~(ge-Be):ge-Be,(ge,Ze)=>{h(Ze)&&Be++})(se);if(typeof se=="number"&&(N[K]+=Be),!Je)break}};return L!=null?D.eachDrop(null,K=>{K===L&&de()}):de(),N}function I(N,q){if(x(N),x(q),N==null)return q;if(q==null)return N;let D=0;const L=i.readCursor(N),B=i.readCursor(q),J=i.writeCursor(),he=[],de=[],K=[],se=[],ue=[],Oe=[],Be=new Set;L.traverse(null,ge=>{ge.p!=null&&(K[ge.p]=L.clone())}),B.traverse(null,ge=>{ge.d!=null&&(se[ge.d]=B.clone())});const Je=i.writeCursor();return function ge(Ze,_t,mt,T,z,me,be,ye){o(_t||mt);const ve=l(_t),Fe=l(mt),ze=!!Fe&&Fe.r!==void 0,fe=!!ve&&ve.i!==void 0,Te=ve?ve.d:null,xe=Fe?Fe.p:null,_e=(me||ze)&&xe==null;if(xe!=null)T=se[xe],be=de[xe]=new i.WriteCursor;else if(Fe&&Fe.r!==void 0)T=null;else{const Ne=l(T);Ne&&Ne.d!=null&&(T=null)}const Se=l(T);if(Te!=null)if(Ze=K[Te],ye=he[Te]=new i.WriteCursor,_e)me&&!ze&&ye.write("r",!0);else{const Ne=ue[Te]=D++;be.write("d",Ne)}else if(ve&&ve.i!==void 0)Ze=null;else{const Ne=l(Ze);Ne&&Ne.p!=null&&(Ze=null)}let ce;fe?(o(z===void 0),ce=ve.i):ce=z;const $e=(xe==null?!fe||me||ze:ce===void 0)?null:be.getComponent();if(xe!=null){if(!(z!==void 0||fe)){const Ne=Te!=null?ue[Te]:D++;Oe[xe]=Ne,ye.write("p",Ne)}}else ze&&(fe||z!==void 0||(Fe.r,ye.write("r",Fe.r)));const H=_e?null:w(ve),oe=w(Se);if((H||oe)&&(H&&H.name,oe&&oe.name),H&&oe){o(H===oe);const Ne=b(ve),tt=b(Se),Pt=H.compose(Ne,tt);P(be,H,Pt),Be.add(Se)}else H?P(be,H,b(ve)):oe&&(P(be,oe,b(Se)),Be.add(Se));const Pe=typeof ce=="object"&&ce!=null;let ke=!1,Ae=0,qe=0,yt=0,dt=0,lt=0;const Ct=i.advancer(T,(Ne,tt)=>h(tt)?dt-Ne-1:Ne-dt,(Ne,tt)=>{h(tt)&&dt++}),et=i.advancer(Ze,(Ne,tt)=>c(tt)?Ae-Ne-1:Ne-Ae,(Ne,tt)=>{c(tt)&&Ae++});if(i.eachChildOf(_t,mt,(Ne,tt,Pt)=>{let Qt,pt,je=Ne,We=Ne,Ke=Ne;if(typeof Ne=="number"){let Ot=Ne+yt;pt=Ct(Ot),We=Ot+dt;let gt=Ne+qe;Qt=et(gt),h(l(pt))&&(Qt=null),je=gt+Ae,Ke=Ne+lt,o(je>=0,"p1PickKey is negative"),o(We>=0,"p2DropKey is negative");const xt=h(l(tt)),Nt=c(l(Pt));(xt||Nt&&!_e)&<--,xt&&qe--,Nt&&yt--}else Qt=et(Ne),pt=Ct(Ne);ye.descend(je),be.descend(We);const pe=Pe&&!h(l(tt))?ce[Ke]:void 0,De=ge(Qt,tt,Pt,pt,pe,_e,be,ye);var ut,Ce,nt;Pe&&!_e?pe!==De&&(ke||(ce=Array.isArray(ce)?ce.slice():Object.assign({},ce),ke=!0),ut=ce,nt=De,typeof(Ce=Ke)=="number"?(o(Array.isArray(ut)),o(Ce<ut.length)):(o(!Array.isArray(ut)),o(ut[Ce]!==void 0)),nt===void 0?typeof Ce=="number"?ut.splice(Ce,1):delete ut[Ce]:ut[Ce]=nt):o(De===void 0),be.ascend(),ye.ascend()}),et.end(),Ct.end(),$e!=null)$e.i=ce;else if(!me&&!ze&&xe==null)return ce}(L,L.clone(),B,B.clone(),void 0,!1,J,Je),J.reset(),J.mergeTree(Je.get()),J.reset(),J.get(),he.map(ge=>ge.get()),de.map(ge=>ge.get()),L.traverse(J,(ge,Ze)=>{const _t=ge.p;if(_t!=null){const mt=ue[_t];mt!=null&&Ze.write("p",mt);const T=he[_t];T&&T.get(),T&&Ze.mergeTree(T.get())}else ge.r!==void 0&&Ze.write("r",ge.r)}),J.reset(),J.get(),B.traverse(J,(ge,Ze)=>{const _t=ge.d;if(_t!=null){const T=Oe[_t];T!=null&&Ze.write("d",T);const z=de[_t];z&&Ze.mergeTree(z.get())}else ge.i!==void 0&&Ze.write("i",ge.i);const mt=w(ge);mt&&!Be.has(ge)&&P(Ze,mt,b(ge))}),J.get()}function Y(N){if(N==null)return null;const q=new i.ReadCursor(N),D=new i.WriteCursor;let L;const B=[],J=[];return function he(de,K,se){const ue=de.getComponent();let Oe,Be=!1;if(ue){ue.p!=null&&(K.write("d",ue.p),B[ue.p]=de.clone()),ue.r!==void 0&&K.write("i",ue.r),ue.d!=null&&(K.write("p",ue.d),se=void 0),ue.i!==void 0&&(se=Oe=ue.i);const ge=w(ue);ge&&(se===void 0?(L||(L=new Set),L.add(ue)):(b(ue),se=ge.apply(se,b(ue)),Be=!0))}let Je=0;for(const ge of de){K.descend(ge);const Ze=typeof ge=="number"?ge-Je:ge,_t=g(se,Ze);h(de.getComponent())&&Je++;const mt=he(de,K,_t);if(se!==void 0&&mt!==void 0){if(Be||(Be=!0,se=u(se)),!p(se,Ze))throw Error("Cannot modify child - invalid operation");se[Ze]=mt}K.ascend()}if(Oe===void 0)return Be?se:void 0;K.write("r",se)}(q,D,void 0),L&&(D.reset(),function he(de,K,se){const ue=K.getComponent();if(ue){const ge=ue.d;if(ge!=null&&(de=B[ge],se=J[ge]=i.writeCursor()),L.has(ue)){const Ze=w(ue);if(!Ze.invert)throw Error(`Cannot invert subtype ${Ze.name}`);P(se,Ze,Ze.invert(b(ue)))}}let Oe=0,Be=0;const Je=i.advancer(de,(ge,Ze)=>c(Ze)?Oe-ge-1:ge-Oe,(ge,Ze)=>{c(Ze)&&Oe++});for(const ge of K)if(typeof ge=="number"){const Ze=ge-Be,_t=Je(Ze),mt=Ze+Oe;se.descend(mt),he(_t,K,se),h(K.getComponent())&&Be++,se.ascend()}else se.descend(ge),he(Je(ge),K,se),se.ascend();Je.end()}(q.clone(),q,D),J.length&&(D.reset(),q.traverse(D,(he,de)=>{const K=he.p;if(K!=null){const se=J[K];se&&se.get(),se&&de.mergeTree(se.get())}}))),D.get()}const te=(N,q)=>N.some(D=>typeof D=="object"&&(Array.isArray(D)?te(D,q):q(D)));function M(N,q){if(N==null||!te(N,K=>{var se;return K.r!==void 0||((se=w(K))===null||se===void 0?void 0:se.makeInvertible)!=null}))return N;const D=new i.ReadCursor(N),L=new i.WriteCursor;let B=!1;const J=[],he=[],de=(K,se,ue)=>{const Oe=K.getComponent();let Be=!1;if(Oe){Oe.d!=null&&se.write("d",Oe.d),Oe.i!==void 0&&se.write("i",Oe.i);const ge=Oe.p;if(ge!=null&&(J[ge]=K.clone(),o(ue!==void 0,"Operation picks up at an invalid key"),he[ge]=ue,se.write("p",Oe.p)),Oe.r!==void 0&&ue===void 0)throw Error("Invalid doc / op in makeInvertible: removed item missing from doc");const Ze=w(Oe);Ze&&(Ze.makeInvertible?B=!0:P(se,Ze,b(Oe),!0))}let Je=0;for(const ge of K){se.descend(ge);const Ze=typeof ge=="number"?ge-Je:ge,_t=g(ue,Ze),mt=de(K,se,_t);_t!==mt&&(Be||(Be=!0,ue=u(ue)),mt===void 0?(ue=f(ue,Ze),typeof ge=="number"&&Je++):ue[Ze]=mt),se.ascend()}return Oe&&(Oe.r!==void 0?(se.write("r",r.default(ue)),ue=void 0):Oe.p!=null&&(ue=void 0)),ue};return de(D,L,q),L.get(),B&&(L.reset(),function K(se,ue,Oe,Be,Je){const ge=ue.getComponent();if(ge){ge.i!==void 0?(Be=ge.i,Je=!0):ge.d!=null&&(Be=he[ge.d],se=J[ge.d],Je=!1,ge.d);let T=w(ge);if(T&&T.makeInvertible){const z=b(ge);P(Oe,T,T.makeInvertible(z,Be),!0)}}let Ze=0,_t=0;const mt=i.advancer(se,(T,z)=>c(z)?Ze-T-1:T-Ze,(T,z)=>{c(z)&&Ze++});for(const T of ue)if(typeof T=="number"){const z=T-_t,me=mt(z),be=z+Ze,ye=g(Be,Je?z:be);Oe.descend(T),K(me,ue,Oe,ye,Je),h(ue.getComponent())&&_t++,Oe.ascend()}else{const z=g(Be,T);Oe.descend(T),K(mt(T),ue,Oe,z,Je),Oe.ascend()}mt.end()}(D.clone(),D,L,q,!1)),L.get()}function W(N,q){return Y(M(N,q))}const Z=N=>{if(N==null)return null;const q=N.slice();for(let D=0;D<N.length;D++){const L=q[D];Array.isArray(L)&&(q[D]=Z(L))}return q};function X(N,q,D){o(D==="left"||D==="right","Direction must be left or right");const L=D==="left"?0:1;if(q==null)return{ok:!0,result:N};x(N),x(q);let B=null;const J=[],he=[],de=[],K=[],se=[],ue=[],Oe=[],Be=[],Je=[],ge=[],Ze=[],_t=[],mt=[],T=[],z=[];let me=0;const be=i.readCursor(N),ye=i.readCursor(q),ve=i.writeCursor();if(function Se(ce,$e=null,H){const oe=l($e);oe&&(oe.r!==void 0?H=$e.clone():oe.p!=null&&(H=null,ue[oe.p]=ce.clone()));const Pe=ce.getComponent();let ke;Pe&&(ke=Pe.p)!=null&&(se[ke]=$e?$e.clone():null,de[ke]=ce.clone(),H&&(ge[ke]=!0,Je[ke]=H),oe&&oe.p!=null&&(T[ke]=oe.p));const Ae=i.advancer($e);for(const qe of ce)Se(ce,Ae(qe),H);Ae.end()}(ye,be,null),function Se(ce,$e,H,oe,Pe){const ke=H.getComponent();let Ae,qe=!1;ke&&((Ae=ke.d)!=null?(K[Ae]=H.clone(),oe!=null&&(z[oe]==null&&(z[oe]=[]),z[oe].push(Ae)),ce=se[Ae]||null,$e=de[Ae]||null,ge[Ae]?(Pe&&(Ze[Ae]=!0),Pe=Je[Ae]||null):!Pe||L!==1&&T[Ae]!=null||B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(Pe.getPath()),op2:t.moveOp($e.getPath(),H.getPath())}),qe=!0):ke.i!==void 0&&(ce=$e=null,qe=!0,Pe&&B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(Pe.getPath()),op2:t.insertOp(H.getPath(),ke.i)})));const yt=l(ce);yt&&(yt.r!==void 0?Pe=ce.clone():yt.p!=null&&(yt.p,oe=yt.p,Pe=null));const dt=w(ke);dt&&Pe&&B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.removeOp(Pe.getPath()),op2:t.editOp(H.getPath(),dt,b(ke),!0)});let lt=0,Ct=0;const et=i.advancer($e,(tt,Pt)=>c(Pt)?lt-tt-1:tt-lt,(tt,Pt)=>{c(Pt)&<++}),Ne=i.advancer(ce);for(const tt of H)if(typeof tt=="number"){const Pt=tt-Ct,Qt=et(Pt);Ct+=+Se(Ne(Pt+lt),Qt,H,oe,Pe)}else{const Pt=et(tt);Se(Ne(tt),Pt,H,oe,Pe)}return et.end(),Ne.end(),qe}(be,ye,ye.clone(),null,null),K.map(Se=>Se&&Se.get()),B)return{ok:!1,conflict:B};Ze.map(Se=>!!Se);const Fe=[];let ze=null;(function Se(ce,$e,H,oe,Pe){let ke=!1;const Ae=l($e);if(c(Ae)){const et=Ae.p;et!=null?(H=K[et],oe=_t[et]=i.writeCursor(),ke=!0,Pe=null):(H=null,Pe=$e.clone())}else h(l(H))&&(H=null);const qe=ce.getComponent();if(qe){const et=qe.p;et!=null?(Pe&&(Be[et]=Pe),Fe[et]=Pe||L===1&&ke?null:oe.getComponent(),J[et]=ce.clone(),H&&(Oe[et]=H.clone())):qe.r!==void 0&&(Pe||oe.write("r",!0),(Pe||ke)&&(ze==null&&(ze=new Set),ze.add(qe)))}let yt=0,dt=0;const lt=i.advancer($e,void 0,(et,Ne)=>{c(Ne)&&yt++}),Ct=i.advancer(H,(et,Ne)=>h(Ne)?~(et-dt):et-dt,(et,Ne)=>{h(Ne)&&dt++});if(ce)for(const et of ce)if(typeof et=="string"){const Ne=lt(et),tt=Ct(et);oe.descend(et),Se(ce,Ne,tt,oe,Pe),oe.ascend()}else{const Ne=lt(et),tt=et-yt,Pt=c(l(Ne))?null:Ct(tt),Qt=tt+dt;o(Qt>=0),oe.descend(Qt),Se(ce,Ne,Pt,oe,Pe),oe.ascend()}lt.end(),Ct.end()})(be,ye,ye.clone(),ve,null),ve.reset();let fe=[];if(function Se(ce,$e,H,oe,Pe,ke){o($e);const Ae=$e.getComponent();let qe=l(oe),yt=!1;const dt=(Ce,nt,Ot)=>Ce?t.moveOp(Ce.getPath(),nt.getPath()):t.insertOp(nt.getPath(),Ot.i);if(h(Ae)){const Ce=Ae.d;Ce!=null&&(he[Ce]=$e.clone());const nt=Ce!=null?Fe[Ce]:null;let Ot=!1;if(Ae.i!==void 0||Ce!=null&&nt){let gt;qe&&(qe.i!==void 0||(gt=qe.d)!=null&&!ge[gt])&&(Ot=gt!=null?Ce!=null&&Ce===T[gt]:n.default(qe.i,Ae.i),Ot||gt!=null&&L!==1&&T[gt]!=null||B==null&&(B={type:s.ConflictType.DROP_COLLISION,op1:dt(Ce!=null?J[Ce]:null,$e,Ae),op2:dt(gt!=null?de[gt]:null,oe,qe)})),Ot||(ke?B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:dt(Ce!=null?J[Ce]:null,$e,Ae),op2:t.removeOp(ke.getPath())}):(Ce!=null?(fe[me]=Ce,Pe.write("d",nt.p=me++)):Pe.write("i",r.default(Ae.i)),yt=!0))}else if(Ce!=null&&!nt){const gt=Be[Ce];gt&&(ke=gt.clone())}Ce!=null?(ce=J[Ce],H=ue[Ce],oe=Oe[Ce]):Ae.i!==void 0&&(ce=H=null,Ot||(oe=null))}else c(l(ce))&&(ce=H=oe=null);const lt=l(ce),Ct=l(H);if(c(Ct)){const Ce=Ct.p;Ct.r!==void 0&&(!lt||lt.r===void 0)||ge[Ce]?(oe=null,ke=H.clone()):Ce!=null&&(oe=K[Ce],L!==1&&T[Ce]!=null||((Pe=mt[Ce])||(Pe=mt[Ce]=i.writeCursor()),Pe.reset(),ke=null))}else!h(Ae)&&h(qe)&&(oe=null);qe=oe!=null?oe.getComponent():null;const et=w(Ae);if(et){const Ce=b(Ae);if(ke)B==null&&(B={type:s.ConflictType.RM_UNEXPECTED_CONTENT,op1:t.editOp($e.getPath(),et,Ce,!0),op2:t.removeOp(ke.getPath())});else{const nt=w(qe);let Ot;if(nt){if(et!==nt)throw Error("Transforming incompatible types");const gt=b(qe);Ot=et.transform(Ce,gt,D)}else Ot=r.default(Ce);P(Pe,et,Ot)}}let Ne=0,tt=0,Pt=0,Qt=0,pt=0,je=0,We=ce!=null&&ce.descendFirst(),Ke=We;const pe=i.advancer(H,void 0,(Ce,nt)=>{c(nt)&&Pt++});let De=oe!=null&&oe.descendFirst(),ut=De;for(const Ce of $e)if(typeof Ce=="number"){let nt;const Ot=h($e.getComponent()),gt=Ce-tt;{let wt;for(;We&&typeof(wt=ce.getKey())=="number";){wt+=Ne;const jt=ce.getComponent(),Tn=c(jt);if(wt>gt||wt===gt&&(!Tn||L===0&&Ot))break;if(Tn){Ne--;const mn=jt.p;T.includes(mn),jt.d,l(mt[jt.d]),c(l(mt[jt.d])),(jt.r===void 0||ze&&ze.has(jt))&&(mn==null||!Fe[mn]||L!==1&&T.includes(mn))||pt--}We=ce.nextSibling()}nt=We&&wt===gt?ce:null}const xt=gt-Ne;let Nt=pe(xt);const St=xt-Pt;let ct=null;{let wt,jt;for(;De&&typeof(wt=oe.getKey())=="number";){jt=wt-Qt;const Tn=oe.getComponent(),mn=h(Tn);if(jt>St)break;if(jt===St){if(!mn){ct=oe;break}{if(L===0&&Ot){ct=oe;break}const On=Nt&&c(Nt.getComponent());if(L===0&&On)break}}if(mn){const On=Tn.d;T[On],Tn.i===void 0&&(ge[On]||T[On]!=null&&L!==1)?(ge[On]||T[On]!=null&&L===0)&&(Qt++,je--):Qt++}De=oe.nextSibling()}}const Ve=St+Qt+pt+je;o(Ve>=0,"trying to descend to a negative index"),Pe.descend(Ve),Ot&&(nt=Nt=ct=null,tt++),Se(nt,$e,Nt,ct,Pe,ke)&&je++,Pe.ascend()}else{let nt;for(;We&&(nt=ce.getKey(),typeof nt!="string"||!(nt>Ce||nt===Ce));)We=ce.nextSibling();const Ot=We&&nt===Ce?ce:null,gt=pe(Ce);let xt;for(;De&&(xt=oe.getKey(),typeof xt!="string"||!(xt>Ce||xt===Ce));)De=oe.nextSibling();const Nt=De&&xt===Ce?oe:null;Pe.descend(Ce),Se(Ot,$e,gt,Nt,Pe,ke),Pe.ascend()}return pe.end(),Ke&&ce.ascend(),ut&&oe.ascend(),yt}(be,be.clone(),ye,ye.clone(),ve,null),B)return{ok:!1,conflict:B};ve.reset();const Te=(Se,ce,$e)=>Se.traverse(ce,(H,oe)=>{H.d!=null&&$e(H.d,Se,oe)});(ge.length||_t.length)&&(Te(ye,ve,(Se,ce,$e)=>{ge[Se]&&!Ze[Se]&&$e.write("r",!0),_t[Se]&&$e.mergeTree(_t[Se].get())}),ve.reset());const xe=[],_e=[];if((mt.length||ge.length)&&!B){const Se=i.readCursor(Z(ve.get()));if(Te(Se,null,(ce,$e)=>{xe[ce]=$e.clone()}),mt.forEach(ce=>{ce&&Te(i.readCursor(ce.get()),null,($e,H)=>{xe[$e]=H.clone()})}),function ce($e,H,oe,Pe,ke,Ae){const qe=l(H);if(qe&&c(qe))if(qe.p!=null){const Ne=qe.p;xe[Ne].getPath(),oe=xe[Ne],Pe=_e[Ne]=i.writeCursor()}else qe.r!==void 0&&(oe=null);else h(l(oe))&&(oe=null);const yt=$e.getComponent();if(yt){let Ne;if((Ne=yt.d)!=null){const tt=mt[Ne];tt&&(tt.get(),Pe.mergeTree(tt.get()),oe=i.readCursor(tt.get()))}}let dt=0,lt=0;const Ct=i.advancer(H,void 0,(Ne,tt)=>{c(tt)&&dt--}),et=i.advancer(oe,(Ne,tt)=>h(tt)?-(Ne-lt)-1:Ne-lt,(Ne,tt)=>{h(tt)&<++});for(const Ne of $e)if(typeof Ne=="number"){const tt=Ct(Ne),Pt=Ne+dt,Qt=et(Pt),pt=Pt+lt;Pe.descend(pt),ce($e,tt,Qt,Pe),Pe.ascend()}else Pe.descend(Ne),ce($e,Ct(Ne),et(Ne),Pe),Pe.ascend();Ct.end(),et.end()}(ye,Se,Se.clone(),ve),ve.reset(),B)return{ok:!1,conflict:B};if(ve.get(),_e.length){const ce=_e.map(H=>H?H.get():null),$e=i.readCursor(Z(ve.get()));if(Te($e,ve,(H,oe,Pe)=>{const ke=ce[H];ke&&(Pe.mergeTree(ke),ce[H]=null)}),ce.find(H=>H)){const H=i.writeCursor(),oe=i.writeCursor();let Pe=0,ke=0;ce.forEach(Ae=>{Ae!=null&&Te(i.readCursor(Ae),null,qe=>{const yt=fe[qe];H.writeMove(J[yt].getPath(),he[yt].getPath(),Pe++);const dt=z[yt];dt&&dt.forEach(lt=>{ge[lt]||L!==1&&T[lt]!=null||oe.writeMove(de[lt].getPath(),K[lt].getPath(),ke++)})})}),B={type:s.ConflictType.BLACKHOLE,op1:H.get(),op2:oe.get()}}}}return B?{ok:!1,conflict:B}:{ok:!0,result:ve.get()}}const G=N=>{const q=new Error("Transform detected write conflict");throw q.conflict=N,q.type=q.name="writeConflict",q};function Qe(N,q,D){const L=X(N,q,D);if(L.ok)return L.result;G(L.conflict)}const Me=N=>{const q=i.writeCursor();return i.readCursor(N).traverse(q,(D,L)=>{(h(D)||w(D))&&L.write("r",!0)}),q.get()},U=(N,q)=>{const{type:D,op1:L,op2:B}=N;switch(D){case s.ConflictType.DROP_COLLISION:return q==="left"?[null,Me(B)]:[Me(L),null];case s.ConflictType.RM_UNEXPECTED_CONTENT:let J=!1;return i.readCursor(L).traverse(null,he=>{he.r!==void 0&&(J=!0)}),J?[null,Me(B)]:[Me(L),null];case s.ConflictType.BLACKHOLE:return[Me(L),Me(B)];default:throw Error("Unrecognised conflict: "+D)}};function re(N,q,D,L){let B=null;for(;;){const J=X(q,D,L);if(J.ok)return I(B,J.result);{const{conflict:he}=J;N(he)||G(he);const[de,K]=U(he,L);q=I(_(q),de),D=I(_(D),K),B=I(B,K)}}}})(UQ);(function(t){var e=Ft&&Ft.__createBinding||(Object.create?function(s,o,l,a){a===void 0&&(a=l),Object.defineProperty(s,a,{enumerable:!0,get:function(){return o[l]}})}:function(s,o,l,a){a===void 0&&(a=l),s[a]=o[l]}),n=Ft&&Ft.__exportStar||function(s,o){for(var l in s)l!=="default"&&!o.hasOwnProperty(l)&&e(o,s,l)};Object.defineProperty(t,"__esModule",{value:!0}),n(UQ,t);var r=r0;Object.defineProperty(t,"ReadCursor",{enumerable:!0,get:function(){return r.ReadCursor}}),Object.defineProperty(t,"WriteCursor",{enumerable:!0,get:function(){return r.WriteCursor}});var i=i0;Object.defineProperty(t,"ConflictType",{enumerable:!0,get:function(){return i.ConflictType}})})(Ld);const o0=()=>(Math.random()+"").slice(2),gF=({typeScriptWorker:t,fileName:e})=>async r=>{const i=o0(),s=r.state.doc.toString(),o={event:"autocomplete-request",fileName:e,fileContent:s,position:r.pos,requestId:i};t.postMessage(o);const l=await new Promise(c=>{t.onmessage=h=>{const f=h.data,{event:d,requestId:p,completions:g}=f;d==="post-completions"&&p===p&&c(g)}});if(!l)return{from:r.pos,options:[]};const a=r.matchBefore(/\w*/).from,u=r.matchBefore(/\w*/).text;return u&&(l.entries=l.entries.filter(c=>c.name.startsWith(u))),{from:r.pos,options:l.entries.map(c=>({label:c.name,apply:h=>{h.dispatch({changes:{from:a,to:r.pos,insert:c.name}})}}))}},mF=({shareDBDoc:t,fileId:e,tabList:n})=>aa.of([{key:"control-m",run:r=>{var i;return t.data.aiStreams===void 0||t.data.aiStreams[ia]===null||((i=t.data.aiStreams[ia])==null?void 0:i.AIStreamStatus.serverIsRunning)!==!0?FQ(r,t,e,n):zQ(t),!0}}]);let ia=null;const FQ=async(t,e,n,r)=>{const i=await OF(r.map(s=>e.data.files[s.fileId]))+`Current File:
|
|
112
|
+
`+t.state.sliceDoc(0,t.state.selection.main.to);console.log(i),ia=o0(),e.data.aiStreams===void 0&&e.submitOp(Ld.insertOp(["aiStreams"],{}),{source:"AIClient"}),e.submitOp(Ld.insertOp(["aiStreams",ia],{AIStreamStatus:{clientWantsToStart:!0,serverIsRunning:!1,text:i,insertionCursor:t.state.selection.main.to,fileId:n}}),{source:"AIClient"})},zQ=t=>{const e=Ld.replaceOp(["aiStreams",ia,"AIStreamStatus","clientWantsToStart"],!0,!1);t.submitOp(e,{source:"AIClient"})},OF=async t=>t.map(n=>{const r=n.name.trim(),i=n.text.trim();return`File \`${r}\`:
|
|
113
113
|
\`\`\`${i}\`\`\``}).join(`
|
|
114
114
|
|
|
115
|
-
`),yF=({typeScriptWorker:t,fileName:e,shareDBDoc:n,fileId:r})=>async()=>{const i=
|
|
115
|
+
`),yF=({typeScriptWorker:t,fileName:e,shareDBDoc:n,fileId:r})=>async()=>{const i=o0(),s=n.data.files[r].text,o={event:"lint-request",fileName:e,fileContent:s,requestId:i};return t.postMessage(o),await new Promise(a=>{t.onmessage=u=>{const c=u.data,{event:h,requestId:f,tsErrors:d}=c;h==="post-error-linter"&&f===f&&a(d)}})},oh=()=>Y$({jsx:!0,typescript:!0}),vF={json:D3,tsx:oh,js:oh,jsx:oh,ts:oh,html:DQ,css:_Q,md:M4},ux=(t,e)=>{let n=t;for(const r of e){if(!n)return;n=n[r]}return n},SF=({fileId:t,shareDBDoc:e,filesPath:n,localPresence:r,docPresence:i,theme:s,onInteract:o,editorCache:l,usernameRef:a,aiAssistEndpoint:u,aiAssistOptions:c,typeScriptWorker:h,tabList:f})=>{if(l.has(t))return l.get(t);const d=e.data,p=[...n,t,"text"],g=[...n,t,"name"],O=ux(d,p),y=ux(d,g),m=y.split(".").pop();let v=new ql;const w=[];w.push(Z4({shareDBDoc:e,path:p,json1:ev,textUnicode:E_})),r&&w.push(L4({path:p,localPresence:r,usernameRef:a})),i&&w.push(z4({path:p,docPresence:i})),w.push(oF),w.push(qY),w.push(v.of(QE[s].value));const b=new ql,C=(_=>{const E=vF[_];return E?E():void 0})(m);C?w.push(b.of(C)):(console.warn(`No language extension for file extension: ${m}`),w.push(b.of([]))),w.push(nF({onInteract:o})),w.push(aF),w.push(uF),w.push(mF({shareDBDoc:e,fileId:t,tabList:f,aiAssistEndpoint:u,aiAssistOptions:c})),w.push(x$({override:[gF({typeScriptWorker:h,fileName:y})]})),w.push(YY(yF({typeScriptWorker:h,fileName:y,shareDBDoc:e,fileId:t})));const x={editor:new Le({state:Mt.create({doc:O,extensions:w})}),themeCompartment:v};return l.set(t,x),x},wF=({activeFileId:t,shareDBDoc:e,submitOperation:n,localPresence:r,docPresence:i,theme:s=RE,filesPath:o=["files"],editorCache:l,editorWantsFocus:a,editorNoLongerWantsFocus:u,username:c,aiAssistEndpoint:h,aiAssistOptions:f,typeScriptWorker:d,tabList:p})=>{const g=F.useRef(null),O=F.useRef(null),y=F.useCallback(()=>{O.current?clearTimeout(O.current):n(w=>({...w,isInteracting:!0})),O.current=setTimeout(()=>{O.current=null,n(w=>({...w,isInteracting:!1}))},800)},[n]),m=F.useRef(c);m.current=c;const v=F.useMemo(()=>SF({fileId:t,shareDBDoc:e,filesPath:o,localPresence:r,docPresence:i,theme:s,onInteract:y,editorCache:l,usernameRef:m,aiAssistEndpoint:h,aiAssistOptions:f,typeScriptWorker:d,tabList:p}),[t,e,o,r,i,s,y,l,m,h,f,d]);return F.useLayoutEffect(()=>{if(g.current&&e)return g.current.appendChild(v.editor.dom),()=>{g.current.removeChild(v.editor.dom)}},[e,v]),F.useLayoutEffect(()=>{a&&(v.editor.focus(),u())},[a,v,u]),ne.jsx("div",{className:"vz-code-editor",ref:g})},bF=({errorMessage:t})=>{const[e,n]=F.useState(!0);F.useEffect(()=>{t!==null&&n(!0)},[t]),F.useEffect(()=>(document.addEventListener("keydown",i,!0),()=>{document.removeEventListener("keydown",i,!0)}),[]);const r=F.useCallback(()=>{n(!1)},[]),i=F.useCallback(s=>{s.key==="Escape"&&r()},[r]);return e&&t!==null?ne.jsxs("div",{className:"vz-code-error-overlay",children:[ne.jsx("pre",{children:t}),ne.jsx("div",{className:"bx bx-x error-dismiss-button",onClick:r})]}):null},cx=t=>{const[e]=t.split("-");return parseInt(e,36)},kF=(t,e)=>{const n=cx(t),r=cx(e);return n>r},xF=(t,e,n,r)=>{n.current.has(t)?n.current.set(t,e):(n.current.set(t,e),r(i=>[...i,{user:e,join:!0,presenceId:t}]))},PF=(t,e,n)=>{const r=e.current.get(t);r&&(e.current.delete(t),n(i=>[...i,{user:r,join:!1,presenceId:t}]))},_F=({docPresence:t,localPresence:e})=>{const[n,r]=F.useState([]),i=F.useRef(new Map);return F.useEffect(()=>{if(t){const s=(o,l)=>{var u;const a=l!==null;if(kF(o,e.presenceId)){if(a){const h=(u=t.remotePresences[o])==null?void 0:u.username;xF(o,h,i,r)}else PF(o,i,r);const c=setTimeout(()=>{r(h=>h.slice(1))},5e3);return()=>{clearTimeout(c)}}};return t.on("receive",s),()=>{t.off("receive",s)}}},[t,e]),n.length>0?ne.jsx("div",{className:"vz-notification",children:n.map(({user:s,join:o,presenceId:l})=>ne.jsx("div",{className:"vz-notification-item",children:o?`${s} has joined the session.`:`${s} has left the session.`},l))}):null},CF=()=>ne.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",width:"24",height:"24",children:ne.jsx("path",{d:"M15.716 1.329a1.341 1.341 0 0 1 2.109 1.55L15.147 9h4.161c1.623 0 2.372 2.016 1.143 3.075L8.102 22.721a1.148 1.148 0 0 1-1.81-1.317L8.996 15H4.674c-1.619 0-2.37-2.008-1.148-3.07l12.19-10.6Zm.452 1.595L4.51 13.061a.25.25 0 0 0 .164.439h5.45a.749.749 0 0 1 .692 1.041l-2.559 6.066 11.215-9.668a.25.25 0 0 0-.164-.439H14a.75.75 0 0 1-.687-1.05Z"})}),EF=()=>ne.jsx("svg",{width:"15pt",height:"15pt",version:"1.1",viewBox:"0 0 15 15",xmlns:"http://www.w3.org/2000/svg",children:ne.jsx("g",{transform:"scale(.75)",fill:"#fff",stroke:"#000",children:ne.jsx("path",{d:"m17.5 0.5c1.1055 0 2 0.89453 2 2v15c0 1.1055-0.89453 2-2 2h-15c-1.1055 0-2-0.89453-2-2v-15c0-1.1055 0.89453-2 2-2z"})})}),TF=({activeFileId:t,shareDBDoc:e,editorCache:n,tabList:r})=>{const[i,s]=F.useState(!1);F.useEffect(()=>{const l=(a,u)=>{var c;a!==null&&a[0]==="aiStreams"&&s(((c=e.data.aiStreams[ia])==null?void 0:c.AIStreamStatus.serverIsRunning)===!0)};return e.on("op",l),()=>{e.off("op",l)}},[e]);const o=F.useCallback(()=>{i?zQ(e):FQ(n.get(t).editor,e,t,r)},[t,i]);return ne.jsx("div",{className:"vz-code-ai-assist-widget",children:ne.jsx(Gu,{variant:"light",title:"Start AI Assist",onClick:o,children:i?ne.jsx(EF,{}):ne.jsx(CF,{})})})},$F=()=>{const{codeEditorWidth:t}=F.useContext(sp),{content:e,shareDBDoc:n,submitOperation:r,localPresence:i,docPresence:s,files:o,createFile:l,activeFileId:a,setActiveFileId:u,tabList:c,openTab:h,closeTabs:f,theme:d,username:p,editorCache:g,editorWantsFocus:O,editorNoLongerWantsFocus:y,errorMessage:m,typeScriptWorker:v}=F.useContext(gc);return a!==null?ne.jsxs("div",{className:"middle",style:{width:t+"px"},children:[ne.jsx(tj,{files:o,tabList:c,activeFileId:a,setActiveFileId:u,openTab:h,closeTabs:f,createFile:l}),e&&a?ne.jsx(wF,{shareDBDoc:n,submitOperation:r,localPresence:i,docPresence:s,activeFileId:a,theme:d,editorCache:g,editorWantsFocus:O,editorNoLongerWantsFocus:y,username:p,typeScriptWorker:v,tabList:c}):null,ne.jsx(bF,{errorMessage:m}),ne.jsx(_F,{docPresence:s,localPresence:i}),e&&a?ne.jsx(TF,{activeFileId:a,shareDBDoc:n,editorCache:g,tabList:c}):null]}):null},QF=()=>ne.jsx("div",{className:"right",children:null}),RF=new I2,AF=new Z2;__.types.register(ev.type);const{Connection:MF}=__,DF=window.location.protocol==="https:"?"wss://":"ws://",NF=new WebSocket(DF+window.location.host+"/ws"),IF=new MF(NF),ZF=()=>{const{username:t}=F.useContext(gc);return g5(t),null};function LF(){const{shareDBDoc:t,content:e,localPresence:n,docPresence:r,submitOperation:i}=oW({connection:IF}),s=p5();return ne.jsx(X2,{children:ne.jsxs(u5,{content:e,shareDBDoc:t,submitOperation:i,localPresence:n,docPresence:r,prettierWorker:RF,typeScriptWorker:AF,initialUsername:s,children:[ne.jsxs("div",{className:"app",children:[ne.jsx(KB,{}),ne.jsx($F,{}),ne.jsx(QF,{}),ne.jsx(gw,{side:"left"}),ne.jsx(gw,{side:"right"})]}),ne.jsx(ZF,{})]})})}x_(document.getElementById("root")).render(ne.jsx(LF,{}));
|
package/dist/index.html
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
href="https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css"
|
|
25
25
|
rel="stylesheet"
|
|
26
26
|
/>
|
|
27
|
-
<script type="module" crossorigin src="/assets/index-
|
|
27
|
+
<script type="module" crossorigin src="/assets/index-OHcEizsk.js"></script>
|
|
28
28
|
<link rel="stylesheet" crossorigin href="/assets/index-esdlTXtH.css">
|
|
29
29
|
</head>
|
|
30
30
|
<body>
|
package/package.json
CHANGED
package/src/client/AIAssist.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EditorView, keymap } from '@codemirror/view';
|
|
2
|
+
import { insertOp, replaceOp } from 'ot-json1';
|
|
2
3
|
import {
|
|
3
4
|
FileId,
|
|
4
5
|
File,
|
|
@@ -6,7 +7,6 @@ import {
|
|
|
6
7
|
VZCodeContent,
|
|
7
8
|
} from '../types';
|
|
8
9
|
import { generateRequestId } from './CodeEditor/typeScriptCompletions';
|
|
9
|
-
import { insertOp, replaceOp } from 'ot-json1';
|
|
10
10
|
|
|
11
11
|
import { TabState } from './vzReducer';
|
|
12
12
|
|
|
@@ -15,12 +15,6 @@ export const AIAssist = ({
|
|
|
15
15
|
// The file id of the file the AI should assist with.
|
|
16
16
|
fileId,
|
|
17
17
|
tabList,
|
|
18
|
-
|
|
19
|
-
// Optional endpoint override.
|
|
20
|
-
aiAssistEndpoint = '/AIAssist',
|
|
21
|
-
|
|
22
|
-
// Optional additional options to pass to the endpoint.
|
|
23
|
-
aiAssistOptions = {},
|
|
24
18
|
}: {
|
|
25
19
|
shareDBDoc: ShareDBDoc<VZCodeContent>;
|
|
26
20
|
fileId: string;
|