6 lines
104 KiB
JavaScript
6 lines
104 KiB
JavaScript
(function(){var qo=Object.create;var $n=Object.defineProperty;var zo=Object.getOwnPropertyDescriptor;var Ho=Object.getOwnPropertyNames;var Jo=Object.getPrototypeOf,Go=Object.prototype.hasOwnProperty;var Wo=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Ko=(e,t)=>{for(var n in t)$n(e,n,{get:t[n],enumerable:!0})},Zo=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Ho(t))!Go.call(e,s)&&s!==n&&$n(e,s,{get:()=>t[s],enumerable:!(r=zo(t,s))||r.enumerable});return e};var Yo=(e,t,n)=>(n=e!=null?qo(Jo(e)):{},Zo(t||!e||!e.__esModule?$n(n,"default",{value:e,enumerable:!0}):n,e));var is=Wo((Xn,os)=>{(function(e,t){var n=t(e);if(typeof Xn=="object"||typeof navigator=="object"&&navigator.product.match(/ReactNative/i))os.exports=n;else{var r=e.DeepDiff;n.noConflict=function(){return e.DeepDiff===n&&(e.DeepDiff=r),n},e.DeepDiff=n}})(Xn,function(e){var t=["N","E","A","D"];function n(g,m){g.super_=m,g.prototype=Object.create(m.prototype,{constructor:{value:g,enumerable:!1,writable:!0,configurable:!0}})}function r(g,m){Object.defineProperty(this,"kind",{value:g,enumerable:!0}),m&&m.length&&Object.defineProperty(this,"path",{value:m,enumerable:!0})}function s(g,m,p){s.super_.call(this,"E",g),Object.defineProperty(this,"lhs",{value:m,enumerable:!0}),Object.defineProperty(this,"rhs",{value:p,enumerable:!0})}n(s,r);function o(g,m){o.super_.call(this,"N",g),Object.defineProperty(this,"rhs",{value:m,enumerable:!0})}n(o,r);function i(g,m){i.super_.call(this,"D",g),Object.defineProperty(this,"lhs",{value:m,enumerable:!0})}n(i,r);function c(g,m,p){c.super_.call(this,"A",g),Object.defineProperty(this,"index",{value:m,enumerable:!0}),Object.defineProperty(this,"item",{value:p,enumerable:!0})}n(c,r);function a(g,m,p){var b=g.slice((p||m)+1||g.length);return g.length=m<0?g.length+m:m,g.push.apply(g,b),g}function l(g){var m=typeof g;return m!=="object"?m:g===Math?"math":g===null?"null":Array.isArray(g)?"array":Object.prototype.toString.call(g)==="[object Date]"?"date":typeof g.toString=="function"&&/^\/.*\//.test(g.toString())?"regexp":"object"}function d(g){var m=0;if(g.length===0)return m;for(var p=0;p<g.length;p++){var b=g.charCodeAt(p);m=(m<<5)-m+b,m=m&m}return m}function u(g){var m=0,p=l(g);if(p==="array"){g.forEach(function(Dt){m+=u(Dt)});var b="[type: array, hash: "+m+"]";return m+d(b)}if(p==="object"){for(var w in g)if(g.hasOwnProperty(w)){var _="[ type: object, key: "+w+", value hash: "+u(g[w])+"]";m+=d(_)}return m}var E="[ type: "+p+" ; value: "+g+"]";return m+d(E)}function h(g,m,p,b,w,_,E,Dt){p=p||[],w=w||[],E=E||[];var N=w.slice(0);if(typeof _<"u"&&_!==null){if(b){if(typeof b=="function"&&b(N,_))return;if(typeof b=="object"){if(b.prefilter&&b.prefilter(N,_))return;if(b.normalize){var Nn=b.normalize(N,_,g,m);Nn&&(g=Nn[0],m=Nn[1])}}}N.push(_)}l(g)==="regexp"&&l(m)==="regexp"&&(g=g.toString(),m=m.toString());var Vn=typeof g,Po=typeof m,j,fe,tt,pe,Vr=Vn!=="undefined"||E&&E.length>0&&E[E.length-1].lhs&&Object.getOwnPropertyDescriptor(E[E.length-1].lhs,_),Rr=Po!=="undefined"||E&&E.length>0&&E[E.length-1].rhs&&Object.getOwnPropertyDescriptor(E[E.length-1].rhs,_);if(!Vr&&Rr)p.push(new o(N,m));else if(!Rr&&Vr)p.push(new i(N,g));else if(l(g)!==l(m))p.push(new s(N,g,m));else if(l(g)==="date"&&g-m!==0)p.push(new s(N,g,m));else if(Vn==="object"&&g!==null&&m!==null){for(j=E.length-1;j>-1;--j)if(E[j].lhs===g){pe=!0;break}if(pe)g!==m&&p.push(new s(N,g,m));else{if(E.push({lhs:g,rhs:m}),Array.isArray(g)){for(Dt&&(g.sort(function(Rn,Fn){return u(Rn)-u(Fn)}),m.sort(function(Rn,Fn){return u(Rn)-u(Fn)})),j=m.length-1,fe=g.length-1;j>fe;)p.push(new c(N,j,new o(void 0,m[j--])));for(;fe>j;)p.push(new c(N,fe,new i(void 0,g[fe--])));for(;j>=0;--j)h(g[j],m[j],p,b,N,j,E,Dt)}else{var Fr=Object.keys(g),ze=Object.keys(m);for(j=0;j<Fr.length;++j)tt=Fr[j],pe=ze.indexOf(tt),pe>=0?(h(g[tt],m[tt],p,b,N,tt,E,Dt),ze[pe]=null):h(g[tt],void 0,p,b,N,tt,E,Dt);for(j=0;j<ze.length;++j)tt=ze[j],tt&&h(void 0,m[tt],p,b,N,tt,E,Dt)}E.length=E.length-1}}else g!==m&&(Vn==="number"&&isNaN(g)&&isNaN(m)||p.push(new s(N,g,m)))}function f(g,m,p,b,w){var _=[];if(h(g,m,_,b,null,null,null,w),p)for(var E=0;E<_.length;++E)p(_[E]);return _}function y(g,m,p,b,w,_,E){return h(g,m,p,b,w,_,E,!0)}function x(g,m,p,b){var w=b?function(E){E&&b.push(E)}:void 0,_=f(g,m,w,p);return b||(_.length?_:void 0)}function k(g,m,p,b){var w=b?function(E){E&&b.push(E)}:void 0,_=f(g,m,w,p,!0);return b||(_.length?_:void 0)}function C(g,m,p){if(p.path&&p.path.length){var b=g[m],w,_=p.path.length-1;for(w=0;w<_;w++)b=b[p.path[w]];switch(p.kind){case"A":C(b[p.path[w]],p.index,p.item);break;case"D":delete b[p.path[w]];break;case"E":case"N":b[p.path[w]]=p.rhs;break}}else switch(p.kind){case"A":C(g[m],p.index,p.item);break;case"D":g=a(g,m);break;case"E":case"N":g[m]=p.rhs;break}return g}function A(g,m,p){if(typeof p>"u"&&m&&~t.indexOf(m.kind)&&(p=m),g&&p&&p.kind){for(var b=g,w=-1,_=p.path?p.path.length-1:0;++w<_;)typeof b[p.path[w]]>"u"&&(b[p.path[w]]=typeof p.path[w+1]<"u"&&typeof p.path[w+1]=="number"?[]:{}),b=b[p.path[w]];switch(p.kind){case"A":p.path&&typeof b[p.path[w]]>"u"&&(b[p.path[w]]=[]),C(p.path?b[p.path[w]]:b,p.index,p.item);break;case"D":delete b[p.path[w]];break;case"E":case"N":b[p.path[w]]=p.rhs;break}}}function O(g,m,p){if(p.path&&p.path.length){var b=g[m],w,_=p.path.length-1;for(w=0;w<_;w++)b=b[p.path[w]];switch(p.kind){case"A":O(b[p.path[w]],p.index,p.item);break;case"D":b[p.path[w]]=p.lhs;break;case"E":b[p.path[w]]=p.lhs;break;case"N":delete b[p.path[w]];break}}else switch(p.kind){case"A":O(g[m],p.index,p.item);break;case"D":g[m]=p.lhs;break;case"E":g[m]=p.lhs;break;case"N":g=a(g,m);break}return g}function Nr(g,m,p){if(g&&m&&p&&p.kind){var b=g,w,_;for(_=p.path.length-1,w=0;w<_;w++)typeof b[p.path[w]]>"u"&&(b[p.path[w]]={}),b=b[p.path[w]];switch(p.kind){case"A":O(b[p.path[w]],p.index,p.item);break;case"D":b[p.path[w]]=p.lhs;break;case"E":b[p.path[w]]=p.lhs;break;case"N":delete b[p.path[w]];break}}}function Jt(g,m,p){if(g&&m){var b=function(w){(!p||p(g,m,w))&&A(g,m,w)};f(g,m,b)}}return Object.defineProperties(x,{diff:{value:x,enumerable:!0},orderIndependentDiff:{value:k,enumerable:!0},observableDiff:{value:f,enumerable:!0},orderIndependentObservableDiff:{value:y,enumerable:!0},orderIndepHash:{value:u,enumerable:!0},applyDiff:{value:Jt,enumerable:!0},applyChange:{value:A,enumerable:!0},revertChange:{value:Nr,enumerable:!0},isConflict:{value:function(){return typeof $conflict<"u"},enumerable:!0}}),x.DeepDiff=x,e&&(e.DeepDiff=x),x})});var Xo=typeof btoa=="function",Pn=typeof Buffer=="function",Pa=typeof TextDecoder=="function"?new TextDecoder:void 0,$r=typeof TextEncoder=="function"?new TextEncoder:void 0,Qo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",ge=Array.prototype.slice.call(Qo),qa=(e=>{let t={};return e.forEach((n,r)=>t[n]=r),t})(ge);var ot=String.fromCharCode.bind(String),za=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),ti=e=>e.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_");var ei=e=>{let t,n,r,s,o="",i=e.length%3;for(let c=0;c<e.length;){if((n=e.charCodeAt(c++))>255||(r=e.charCodeAt(c++))>255||(s=e.charCodeAt(c++))>255)throw new TypeError("invalid character found");t=n<<16|r<<8|s,o+=ge[t>>18&63]+ge[t>>12&63]+ge[t>>6&63]+ge[t&63]}return i?o.slice(0,i-3)+"===".substring(i):o},qr=Xo?e=>btoa(e):Pn?e=>Buffer.from(e,"binary").toString("base64"):ei,ni=Pn?e=>Buffer.from(e).toString("base64"):e=>{let n=[];for(let r=0,s=e.length;r<s;r+=4096)n.push(ot.apply(null,e.subarray(r,r+4096)));return qr(n.join(""))};var ri=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?ot(192|t>>>6)+ot(128|t&63):ot(224|t>>>12&15)+ot(128|t>>>6&63)+ot(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return ot(240|t>>>18&7)+ot(128|t>>>12&63)+ot(128|t>>>6&63)+ot(128|t&63)}},si=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,oi=e=>e.replace(si,ri),Pr=Pn?e=>Buffer.from(e,"utf8").toString("base64"):$r?e=>ni($r.encode(e)):e=>qr(oi(e)),qn=(e,t=!1)=>t?ti(Pr(e)):Pr(e);var zr=(e,t="_")=>e.replace(/[\W]+/g,t);var Hr=e=>(globalThis.structuredClone||(t=>JSON.parse(JSON.stringify(t,(n,r)=>r===void 0?null:r))))(e);var ii=()=>String(Math.random())+"-"+Date.now().toFixed();var me=(e,t)=>new Promise((n,r)=>{if(t&&globalThis[t])return n(globalThis[t]);if(typeof globalThis.importScripts=="function")return globalThis.importScripts(e),t&&globalThis[t]?n(globalThis[t]):n(globalThis);let s=document.createElement("script");s.src=e,s.async=!0;let o=()=>{s.removeEventListener("load",i),s.removeEventListener("error",c)},i=()=>{if(o(),!t)return n("loaded: "+e);let a=setInterval(()=>{if(window[t])return clearInterval(a),n(window[t])},5)},c=()=>{o(),r("failed to load: "+e)};s.addEventListener("load",i),s.addEventListener("error",c),document.head.appendChild(s)});var Jr=e=>{let n=[];for(let r=0;r<e.length;r+=32768)n.push(String.fromCharCode.apply(null,e.subarray(r,r+32768)));return btoa(n.join(""))};var zn=(e,t)=>{if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.byteLength;n++)if(e[n]!==t[n])return!1;return!0};var Hn=async(e,t)=>new Promise(n=>{let r=ii(),s=o=>{let i=o.data;i.method===t.method&&i.messageId===r&&(e.removeEventListener("message",s),n(i.data))};e.addEventListener("message",s),e.postMessage({...t,messageId:r})});var Gt=(e,t)=>({Accept:`application/vnd.github.v3${t?"."+t:""}+json`,"Content-Type":"application/json",Authorization:"token "+e.token}),ci=async(e,t)=>{try{return(await fetch(`https://api.github.com/repos/${e.username}/${t}`,{method:"GET",cache:"no-store",headers:Gt(e)})).ok}catch{return!1}},ai=async(e,t,n=!1,r)=>{let s=await fetch("https://api.github.com/user/repos",{method:"POST",cache:"no-store",headers:Gt(e),body:JSON.stringify({name:t,private:n,...n?{}:{homepage:`https://${e.username}.github.io/${t}/`},...r?{description:r}:{}})});if(!s.ok)throw await s.json().then(i=>i.errors[0]?.message)==="name already exists on this account"?new Error("Repo name already exists"):new Error("Error creating repo");return s.json().then(o=>o.name)},Gr=async({user:e,repo:t,branch:n,file:r,message:s,initialize:o=!1,encoded:i=!1})=>{let c=`https://api.github.com/repos/${e.username}/${t}/contents/`,a=r.path.split("/").slice(0,-1).join("/"),l;if(!o){let u=await fetch(c+a,{method:"GET",cache:"no-store",headers:Gt(e)});u.ok&&(l=(await u.json()).find(f=>f.path===r.path)?.sha)}let d=await fetch(c+r.path,{method:"PUT",cache:"no-store",headers:Gt(e),body:JSON.stringify({message:s||"deploy",content:i?r.content:qn(r.content),branch:n,...l?{sha:l}:{}})});if(!d.ok)throw new Error("Error creating file");return d.json()},ye=async({user:e,repo:t,branch:n,path:r})=>{let s=`https://api.github.com/repos/${e.username}/${t}/contents/${r}`+(n?`?ref=${n}`:""),o=await fetch(s,{method:"GET",cache:"no-store",headers:Gt(e,"object")});if(!o.ok)throw new Error("Error getting file");let i=await o.json();if(i.content===""&&i.encoding==="none"){let c=await fetch(s,{method:"GET",cache:"no-store",headers:Gt(e,"raw")});if(!c.ok)throw new Error("Error getting file");r.endsWith(".b64.zip")?(i.content=await c.arrayBuffer(),i.encoding="arrayBuffer"):(i.content=qn(await c.text()),i.encoding="base64")}return i},li=async(e,t,n="main",r)=>(await Gr({user:e,repo:t,branch:n,file:{path:"README.md",content:`${r||"# "+t+`
|
|
`}`},message:"initial commit",initialize:!0,encoded:!1}))?.commit.sha;var Jn=async({file:e,user:t,repo:n,branch:r,message:s,newRepo:o,privateRepo:i,description:c,readmeContent:a})=>{try{(o||!await ci(t,n))&&(o=!0,n=zr(n,"-").toLowerCase(),await ai(t,n,i,c),await li(t,n,r,a));let l=await Gr({user:t,repo:n,branch:r,file:e,message:s,initialize:o||!1,encoded:!0});return{tree:l?.commit?.tree?.sha,commit:l?.commit?.sha}}catch{return null}};var He=()=>{let e=[];return{subscribe:o=>(e.push(o),{unsubscribe:()=>{e.splice(e.indexOf(o),1)}}),notify:o=>{e.forEach(i=>{i(o)})},hasSubscribers:()=>e.length>0,unsubscribeAll:()=>{e.length=0}}};var Kr=["esm.sh","skypack","esm.run","jsdelivr.esm","fastly.jsdelivr.esm","gcore.jsdelivr.esm","testingcf.jsdelivr.esm","jsdelivr.b-cdn.esm","jspm"],Zr=["jsdelivr","fastly.jsdelivr","unpkg","gcore.jsdelivr","testingcf.jsdelivr","jsdelivr.b-cdn","npmcdn"],Yr=["jsdelivr.gh","fastly.jsdelivr.gh","statically","gcore.jsdelivr.gh","testingcf.jsdelivr.gh","jsdelivr.b-cdn.gh"],Tt={getModuleUrl:(e,{isModule:t=!0,defaultCDN:n="esm.sh",external:r}={})=>{e=e.replace(/#nobundle/g,"");let s=i=>!r||!i.includes("https://esm.sh")?i:i.includes("?")?`${i}&external=${r}`:`${i}?external=${r}`,o=Wr(e,t,n);return o?s(o):t?s("https://esm.sh/"+e):"https://cdn.jsdelivr.net/npm/"+e},getUrl:(e,t)=>e.startsWith("http")||e.startsWith("data:")?e:Wr(e,!1,t||di())||e,cdnLists:{npm:Zr,module:Kr,gh:Yr},checkCDNs:async(e,t)=>{let n=[t,...Tt.cdnLists.npm].filter(Boolean);for(let r of n)try{if((await fetch(Tt.getUrl(e,r),{method:"HEAD"})).ok)return r}catch{}return Tt.cdnLists.npm[0]}},di=()=>{if(globalThis.appCDN)return globalThis.appCDN;try{return new URL(location.href).searchParams.get("appCDN")||Tt.cdnLists.npm[0]}catch{return Tt.cdnLists.npm[0]}},Wr=(e,t,n)=>{let r=t&&e.startsWith("unpkg:")?"?module":"";e.startsWith("gh:")?e=e.replace("gh",Yr[0]):e.includes(":")||(e=(n||(t?Kr[0]:Zr[0]))+":"+e);for(let s of ui){let[o,i]=s;if(o.test(e))return e.replace(o,i)+r}return null},ui=[[/^(esm\.sh:)(.+)/i,"https://esm.sh/$2"],[/^(npm:)(.+)/i,"https://esm.sh/$2"],[/^(node:)(.+)/i,"https://esm.sh/$2"],[/^(jsr:)(.+)/i,"https://esm.sh/jsr/$2"],[/^(skypack:)(.+)/i,"https://cdn.skypack.dev/$2"],[/^(jsdelivr:)(.+)/i,"https://cdn.jsdelivr.net/npm/$2"],[/^(fastly\.jsdelivr:)(.+)/i,"https://fastly.jsdelivr.net/npm/$2"],[/^(gcore\.jsdelivr:)(.+)/i,"https://gcore.jsdelivr.net/npm/$2"],[/^(testingcf\.jsdelivr:)(.+)/i,"https://testingcf.jsdelivr.net/npm/$2"],[/^(jsdelivr\.b-cdn:)(.+)/i,"https://jsdelivr.b-cdn.net/npm/$2"],[/^(jsdelivr\.gh:)(.+)/i,"https://cdn.jsdelivr.net/gh/$2"],[/^(fastly\.jsdelivr\.gh:)(.+)/i,"https://fastly.jsdelivr.net/gh/$2"],[/^(gcore\.jsdelivr\.gh:)(.+)/i,"https://gcore.jsdelivr.net/gh/$2"],[/^(testingcf\.jsdelivr\.gh:)(.+)/i,"https://testingcf.jsdelivr.net/gh/$2"],[/^(jsdelivr\.b-cdn\.gh:)(.+)/i,"https://jsdelivr.b-cdn.net/gh/$2"],[/^(statically:)(.+)/i,"https://cdn.statically.io/gh/$2"],[/^(esm\.run:)(.+)/i,"https://esm.run/$2"],[/^(jsdelivr\.esm:)(.+)/i,"https://cdn.jsdelivr.net/npm/$2/+esm"],[/^(fastly\.jsdelivr\.esm:)(.+)/i,"https://fastly.jsdelivr.net/npm/$2/+esm"],[/^(gcore\.jsdelivr\.esm:)(.+)/i,"https://gcore.jsdelivr.net/npm/$2/+esm"],[/^(testingcf\.jsdelivr\.esm:)(.+)/i,"https://testingcf.jsdelivr.net/npm/$2/+esm"],[/^(jsdelivr\.b-cdn\.esm:)(.+)/i,"https://jsdelivr.b-cdn.net/npm/$2/+esm"],[/^(jspm:)(.+)/i,"https://jspm.dev/$2"],[/^(esbuild:)(.+)/i,"https://esbuild.vercel.app/$2"],[/^(bundle\.run:)(.+)/i,"https://bundle.run/$2"],[/^(unpkg:)(.+)/i,"https://unpkg.com/$2"],[/^(npmcdn:)(.+)/i,"https://npmcdn.com/$2"],[/^(bundlejs:)(.+)/i,"https://deno.bundlejs.com/?file&q=$2"],[/^(bundle:)(.+)/i,"https://deno.bundlejs.com/?file&q=$2"],[/^(deno:)(.+)/i,"https://deno.bundlejs.com/?file&q=https://deno.land/x/$2/mod.ts"],[/^(https:\/\/deno\.land\/.+)/i,"https://deno.bundlejs.com/?file&q=$1"],[/^(github:|https:\/\/github\.com\/)(.[^\/]+?)\/(.[^\/]+?)\/(?!releases\/)(?:(?:blob|raw)\/)?(.+?\/.+)/i,"https://deno.bundlejs.com/?file&q=https://cdn.jsdelivr.net/gh/$2/$3@$4"],[/^(gist\.github:)(.+?\/[0-9a-f]+\/raw\/(?:[0-9a-f]+\/)?.+)$/i,"https://gist.githack.com/$2"],[/^(gitlab:|https:\/\/gitlab\.com\/)([^\/]+.*\/[^\/]+)\/(?:raw|blob)\/(.+?)(?:\?.*)?$/i,"https://deno.bundlejs.com/?file&q=https://gl.githack.com/$2/raw/$3"],[/^(bitbucket:|https:\/\/bitbucket\.org\/)([^\/]+\/[^\/]+)\/(?:raw|src)\/(.+?)(?:\?.*)?$/i,"https://deno.bundlejs.com/?file&q=https://bb.githack.com/$2/raw/$3"],[/^(bitbucket:)snippets\/([^\/]+\/[^\/]+)\/revisions\/([^\/\#\?]+)(?:\?[^#]*)?(?:\#file-(.+?))$/i,"https://bb.githack.com/!api/2.0/snippets/$2/$3/files/$4"],[/^(bitbucket:)snippets\/([^\/]+\/[^\/\#\?]+)(?:\?[^#]*)?(?:\#file-(.+?))$/i,"https://bb.githack.com/!api/2.0/snippets/$2/HEAD/files/$3"],[/^(bitbucket:)\!api\/2.0\/snippets\/([^\/]+\/[^\/]+\/[^\/]+)\/files\/(.+?)(?:\?.*)?$/i,"https://bb.githack.com/!api/2.0/snippets/$2/files/$3"],[/^(api\.bitbucket:)2.0\/snippets\/([^\/]+\/[^\/]+\/[^\/]+)\/files\/(.+?)(?:\?.*)?$/i,"https://bb.githack.com/!api/2.0/snippets/$2/files/$3"],[/^(rawgit:)(.+?\/[0-9a-f]+\/raw\/(?:[0-9a-f]+\/)?.+)$/i,"https://gist.githack.com/$2"],[/^(rawgit:|https:\/\/raw\.githubusercontent\.com)(\/[^\/]+\/[^\/]+|[0-9A-Za-z-]+\/[0-9a-f]+\/raw)\/(.+)/i,"https://deno.bundlejs.com/?file&q=https://raw.githack.com/$2/$3"]];var{getUrl:Xr,getModuleUrl:ol}=Tt;var Gn=Xr("jszip@3.10.1/dist/jszip.js");var Qr=Xr("localforage@1.10.0/dist/localforage.min.js");var ts={getList:async()=>[],getAllData:async()=>[],getItem:async()=>null,addItem:async()=>"",updateItem:async()=>"",deleteItem:async()=>{},bulkInsert:async()=>{},restore:async()=>{},clear:async()=>{},subscribe:()=>({unsubscribe:()=>{}}),unsubscribeAll:()=>{}},es={getValue:()=>null,setValue:()=>{},clear:()=>{},subscribe:()=>({unsubscribe:()=>{}}),unsubscribeAll:()=>{}};var Je,ns="livecodes",Wn={},Kn=()=>(Date.now()+""+Math.floor(Math.floor(Math.random()*Date.now()))).substring(0,24),hi=async e=>{Je||(Je=await me(Qr,"localforage"),Je.config({name:ns})),Wn[e]||(Wn[e]=Je.createInstance({name:ns,storeName:e}))},It=async(e,t)=>{if(t)return ts;let n,r=He(),s=C=>r.subscribe(C),o=()=>{r.unsubscribeAll()},i=()=>{r.hasSubscribers()&&l().then(C=>{r.notify(C)})},c=async()=>{await hi(e),n=Wn[e]},a=async()=>(await c(),n.keys()),l=async()=>{await c();let C=[];return await n.iterate(A=>{C.push(A)}),C.sort((A,O)=>O.lastModified&&A.lastModified?O.lastModified-A.lastModified:0)},d=async C=>(await c(),n.getItem(C)),u=async(C,A,O=!0)=>(await c(),await n.setItem(C,A),O&&i(),C),h=async(C,A=!0)=>{let O=Kn();return await u(O,C,A),O};return{getList:a,getAllData:l,getItem:d,addItem:C=>h(C),updateItem:(C,A)=>u(C,A),deleteItem:async C=>{await c(),await n.removeItem(C),i()},bulkInsert:async C=>{for(let A of C)await h(A,!1);i()},restore:async C=>{for(let A of C)A.id?await u(A.id,A,!1):await h(A,!1);i()},clear:async()=>{await c(),await n.clear(),i()},subscribe:s,unsubscribeAll:o}};var Zn=async(e,t)=>{let n=await It(e,t),r=async()=>(await n.getAllData()).map(c=>({id:c.id,title:c.config?.title||"",description:c.config?.description||"",tags:c.config?.tags||[],languages:c.config?[c.config.markup.language,c.config.style.language,c.config.script.language]:[],lastModified:c.lastModified})).sort((c,a)=>a.lastModified-c.lastModified),s=(c,a)=>{let l={id:c,config:a,lastModified:Date.now()};return n.updateItem(c,l)},o=async c=>{let a=Kn();return s(a,c)};return{...n,getList:r,addItem:o,updateItem:s,bulkInsert:async c=>{for(let a of c)await o(a)}}};var Ge=(e,t)=>{if(t)return es;let n=He(),r=l=>n.subscribe(l),s=()=>{n.unsubscribeAll()},o=()=>{n.notify(c())},i=l=>{window.localStorage.setItem(e,JSON.stringify(l)),o()},c=()=>{let l=window.localStorage.getItem(e);if(!l)return null;try{return JSON.parse(l)}catch{return null}};return{getValue:c,setValue:i,clear:()=>{i(null),o()},subscribe:r,unsubscribeAll:s}};var rs=()=>Hr({projects:null,templates:null,assets:null,snippets:null,recover:null,userConfig:null,userData:null,appData:null,sync:null}),ss=async(e,t)=>{t||(e.projects=await Zn("__livecodes_data__",t),e.templates=await Zn("__livecodes_templates__",t),e.assets=await It("__livecodes_assets__",t),e.snippets=await It("__livecodes_snippets__",t),e.recover=Ge("__livecodes_project_recover__",t),e.userConfig=Ge("__livecodes_user_config__",t),e.userData=await It("__livecodes_user_data__",t),e.appData=Ge("__livecodes_app_data__",t),e.sync=await It("__livecodes_sync_data__",t))};var Yn=(e,t)=>{for(let n of Object.keys(t))if(t[n]===e)return n;return null};var Bn=Yo(is());var R={};Ko(R,{AbsolutePosition:()=>yn,AbstractConnector:()=>hr,AbstractStruct:()=>ae,AbstractType:()=>L,Array:()=>W,ContentAny:()=>Ht,ContentBinary:()=>le,ContentDeleted:()=>Fe,ContentEmbed:()=>_t,ContentFormat:()=>B,ContentJSON:()=>An,ContentString:()=>ut,ContentType:()=>st,Doc:()=>$t,GC:()=>$,ID:()=>pt,Item:()=>T,Map:()=>Q,PermanentUserData:()=>pr,RelativePosition:()=>ie,Snapshot:()=>Le,Text:()=>ce,Transaction:()=>bn,UndoManager:()=>yr,UpdateEncoderV1:()=>gt,XmlElement:()=>Re,XmlFragment:()=>zt,XmlHook:()=>En,XmlText:()=>_n,YArrayEvent:()=>Un,YEvent:()=>qt,YMapEvent:()=>kn,YTextEvent:()=>vn,YXmlEvent:()=>Cn,applyUpdate:()=>mc,applyUpdateV2:()=>In,cleanupYTextFormatting:()=>Lo,compareIDs:()=>Ft,compareRelativePositions:()=>jc,convertUpdateFormatV1ToV2:()=>Kc,convertUpdateFormatV2ToV1:()=>yo,createAbsolutePositionFromRelativePosition:()=>Ic,createDeleteSet:()=>Tn,createDeleteSetFromStructStore:()=>Ur,createDocFromSnapshot:()=>Vc,createID:()=>U,createRelativePositionFromJSON:()=>vc,createRelativePositionFromTypeIndex:()=>Ec,createSnapshot:()=>Ar,decodeRelativePosition:()=>Tc,decodeSnapshot:()=>Oc,decodeSnapshotV2:()=>ro,decodeStateVector:()=>Cr,decodeUpdate:()=>zc,decodeUpdateV2:()=>uo,diffUpdate:()=>Wc,diffUpdateV2:()=>Dr,emptySnapshot:()=>Mc,encodeRelativePosition:()=>Ac,encodeSnapshot:()=>Bc,encodeSnapshotV2:()=>no,encodeStateAsUpdate:()=>wc,encodeStateAsUpdateV2:()=>Qs,encodeStateVector:()=>Sc,encodeStateVectorFromUpdate:()=>Hc,encodeStateVectorFromUpdateV2:()=>fo,equalSnapshots:()=>Lc,findIndexSS:()=>X,findRootTypeKey:()=>_r,getItem:()=>_e,getState:()=>I,getTypeChildren:()=>Qc,isDeleted:()=>de,isParentOf:()=>je,iterateDeletedStructs:()=>vt,logType:()=>Uc,logUpdate:()=>qc,logUpdateV2:()=>lo,mergeUpdates:()=>ho,mergeUpdatesV2:()=>Oe,parseUpdateMeta:()=>Jc,parseUpdateMetaV2:()=>po,readUpdate:()=>gc,readUpdateV2:()=>vr,relativePositionToJSON:()=>kc,snapshot:()=>Nc,transact:()=>D,tryGc:()=>$c,typeListToArraySnapshot:()=>ta,typeMapGetSnapshot:()=>ra});var q=()=>new Map,we=e=>{let t=q();return e.forEach((n,r)=>{t.set(r,n)}),t},it=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},cs=(e,t)=>{let n=[];for(let[r,s]of e)n.push(t(s,r));return n},as=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1};var jt=()=>new Set;var We=e=>e[e.length-1];var ds=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},Ke=Array.from;var Qn=Array.isArray;var Wt=class{constructor(){this._observers=q()}on(t,n){it(this._observers,t,jt).add(n)}once(t,n){let r=(...s)=>{this.off(t,r),n(...s)};this.on(t,r)}off(t,n){let r=this._observers.get(t);r!==void 0&&(r.delete(n),r.size===0&&this._observers.delete(t))}emit(t,n){return Ke((this._observers.get(t)||q()).values()).forEach(r=>r(...n))}destroy(){this._observers=q()}};var Kt=Math.floor;var Zt=Math.abs;var Ze=(e,t)=>e<t?e:t,ft=(e,t)=>e>t?e:t,vl=Number.isNaN;var Ye=e=>e!==0?e<0:1/e<0;var Cl=String.fromCharCode,El=String.fromCodePoint,fi=e=>e.toLowerCase(),pi=/^\s*/g,gi=e=>e.replace(pi,""),mi=/([A-Z])/g,er=(e,t)=>gi(e.replace(mi,n=>`${t}${fi(n)}`));var _l=typeof TextEncoder<"u"?new TextEncoder:null;var tr=typeof TextDecoder>"u"?null:new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0});tr&&tr.decode(new Uint8Array).length===1&&(tr=null);var nr=e=>e===void 0?null:e;var rr=class{constructor(){this.map=new Map}setItem(t,n){this.map.set(t,n)}getItem(t){return this.map.get(t)}},hs=new rr,bi=!0;try{typeof localStorage<"u"&&(hs=localStorage,bi=!1)}catch{}var fs=hs;var Qe=typeof process<"u"&&process.release&&/node|io\.js/.test(process.release.name);var Al=typeof navigator<"u"?/Mac/.test(navigator.platform):!1,ct,Si=[],Ui=()=>{if(ct===void 0)if(Qe){ct=q();let e=process.argv,t=null;for(let n=0;n<e.length;n++){let r=e[n];r[0]==="-"?(t!==null&&ct.set(t,""),t=r):t!==null?(ct.set(t,r),t=null):Si.push(r)}t!==null&&ct.set(t,"")}else typeof location=="object"?(ct=q(),(location.search||"?").slice(1).split("&").forEach(e=>{if(e.length!==0){let[t,n]=e.split("=");ct.set(`--${er(t,"-")}`,n),ct.set(`-${er(t,"-")}`,n)}})):ct=q();return ct},ki=e=>Ui().has(e);var ps=e=>Qe?nr(process.env[e.toUpperCase()]):nr(fs.getItem(e));var vi=e=>ki("--"+e)||ps(e)!==null,Dl=vi("production");var Yt=class{constructor(t){this.arr=t,this.pos=0}},V=e=>new Yt(e),sr=e=>e.pos!==e.arr.length;var Ei=(e,t)=>{let n=Ue(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},z=e=>Ei(e,v(e));var Lt=e=>e.arr[e.pos++];var v=e=>{let t=0,n=0;for(;;){let r=e.arr[e.pos++];if(t=t|(r&127)<<n,n+=7,r<128)return t>>>0;if(n>53)throw new Error("Integer out of range!")}},Se=e=>{let t=e.arr[e.pos++],n=t&63,r=6,s=(t&64)>0?-1:1;if(!(t&128))return s*n;for(;;){if(t=e.arr[e.pos++],n=n|(t&127)<<r,r+=7,t<128)return s*(n>>>0);if(r>53)throw new Error("Integer out of range!")}};var wt=e=>{let t=v(e);if(t===0)return"";{let n=String.fromCodePoint(Lt(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Lt(e));else for(;t>0;){let r=t<1e4?t:1e4,s=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,s),t-=r}return decodeURIComponent(escape(n))}};var or=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},_i=e=>or(e,4).getFloat32(0,!1),Ai=e=>or(e,8).getFloat64(0,!1),Di=e=>or(e,8).getBigInt64(0,!1);var Ti=[e=>{},e=>null,Se,_i,Ai,Di,e=>!1,e=>!0,wt,e=>{let t=v(e),n={};for(let r=0;r<t;r++){let s=wt(e);n[s]=Xt(e)}return n},e=>{let t=v(e),n=[];for(let r=0;r<t;r++)n.push(Xt(e));return n},z],Xt=e=>Ti[127-Lt(e)](e),xe=class extends Yt{constructor(t,n){super(t),this.reader=n,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),sr(this)?this.count=v(this)+1:this.count=-1),this.count--,this.s}};var Bt=class extends Yt{constructor(t){super(t),this.s=0,this.count=0}read(){if(this.count===0){this.s=Se(this);let t=Ye(this.s);this.count=1,t&&(this.s=-this.s,this.count=v(this)+2)}return this.count--,this.s}};var Qt=class extends Yt{constructor(t){super(t),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let t=Se(this),n=t&1;this.diff=t>>1,this.count=1,n&&(this.count=v(this)+2)}return this.s+=this.diff,this.count--,this.s}},tn=class{constructor(t){this.decoder=new Bt(t),this.str=wt(this.decoder),this.spos=0}read(){let t=this.spos+this.decoder.read(),n=this.str.slice(this.spos,t);return this.spos=t,n}};var ji=e=>new Uint8Array(e),Ue=(e,t,n)=>new Uint8Array(e,t,n);var ms=e=>{let t=ji(e.byteLength);return t.set(e),t};var Tl=Number.MAX_SAFE_INTEGER,Il=Number.MIN_SAFE_INTEGER,jl=1<<31;var ys=Number.isInteger||(e=>typeof e=="number"&&isFinite(e)&&Kt(e)===e),Ll=Number.isNaN,Bl=Number.parseInt;var Ot=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}},Nt=()=>new Ot,Bi=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},H=e=>{let t=new Uint8Array(Bi(e)),n=0;for(let r=0;r<e.bufs.length;r++){let s=e.bufs[r];t.set(s,n),n+=s.length}return t.set(Ue(e.cbuf.buffer,0,e.cpos),n),t},Oi=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(Ue(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(ft(n,t)*2),e.cpos=0)},M=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t};var re=M;var S=(e,t)=>{for(;t>127;)M(e,128|127&t),t>>>=7;M(e,127&t)},ve=(e,t)=>{let n=Ye(t);for(n&&(t=-t),M(e,(t>63?128:0)|(n?64:0)|63&t),t>>>=6;t>0;)M(e,(t>127?128:0)|127&t),t>>>=7},xt=(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;S(e,r);for(let s=0;s<r;s++)M(e,n.codePointAt(s))},Ss=(e,t)=>se(e,H(t)),se=(e,t)=>{let n=e.cbuf.length,r=e.cpos,s=Ze(n-r,t.length),o=t.length-s;e.cbuf.set(t.subarray(0,s),r),e.cpos+=s,o>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(ft(n*2,o)),e.cbuf.set(t.subarray(s)),e.cpos=o)},J=(e,t)=>{S(e,t.byteLength),se(e,t)},cr=(e,t)=>{Oi(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},Mi=(e,t)=>cr(e,4).setFloat32(0,t,!1),Ni=(e,t)=>cr(e,8).setFloat64(0,t,!1),Vi=(e,t)=>cr(e,8).setBigInt64(0,t,!1);var ws=new DataView(new ArrayBuffer(4)),Ri=e=>(ws.setFloat32(0,e),ws.getFloat32(0)===e),ee=(e,t)=>{switch(typeof t){case"string":M(e,119),xt(e,t);break;case"number":ys(t)&&Zt(t)<=2147483647?(M(e,125),ve(e,t)):Ri(t)?(M(e,124),Mi(e,t)):(M(e,123),Ni(e,t));break;case"bigint":M(e,122),Vi(e,t);break;case"object":if(t===null)M(e,126);else if(t instanceof Array){M(e,117),S(e,t.length);for(let n=0;n<t.length;n++)ee(e,t[n])}else if(t instanceof Uint8Array)M(e,116),J(e,t);else{M(e,118);let n=Object.keys(t);S(e,n.length);for(let r=0;r<n.length;r++){let s=n[r];xt(e,s),ee(e,t[s])}}break;case"boolean":M(e,t?120:121);break;default:M(e,127)}},ke=class extends Ot{constructor(t){super(),this.w=t,this.s=null,this.count=0}write(t){this.s===t?this.count++:(this.count>0&&S(this,this.count-1),this.count=1,this.w(this,t),this.s=t)}};var bs=e=>{e.count>0&&(ve(e.encoder,e.count===1?e.s:-e.s),e.count>1&&S(e.encoder,e.count-2))},Mt=class{constructor(){this.encoder=new Ot,this.s=0,this.count=0}write(t){this.s===t?this.count++:(bs(this),this.count=1,this.s=t)}toUint8Array(){return bs(this),H(this.encoder)}};var xs=e=>{if(e.count>0){let t=e.diff<<1|(e.count===1?0:1);ve(e.encoder,t),e.count>1&&S(e.encoder,e.count-2)}},ne=class{constructor(){this.encoder=new Ot,this.s=0,this.count=0,this.diff=0}write(t){this.diff===t-this.s?(this.s=t,this.count++):(xs(this),this.count=1,this.diff=t-this.s,this.s=t)}toUint8Array(){return xs(this),H(this.encoder)}},en=class{constructor(){this.sarr=[],this.s="",this.lensE=new Mt}write(t){this.s+=t,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(t.length)}toUint8Array(){let t=new Ot;return this.sarr.push(this.s),this.s="",xt(t,this.sarr.join("")),se(t,this.lensE.toUint8Array()),H(t)}};var $i=typeof window>"u"?null:typeof window.performance<"u"&&window.performance||null,Us=typeof crypto>"u"?null:crypto,ar=Us!==null?e=>{let t=new ArrayBuffer(e),n=new Uint8Array(t);return Us.getRandomValues(n),t}:e=>{let t=new ArrayBuffer(e),n=new Uint8Array(t);for(let r=0;r<e;r++)n[r]=Math.ceil(Math.random()*4294967295>>>0);return t};var lr=()=>new Uint32Array(ar(4))[0];var Pi="10000000-1000-4000-8000"+-1e11,ks=()=>Pi.replace(/[018]/g,e=>(e^lr()&15>>e/4).toString(16));var nn=Date.now;var Cs=e=>new Promise(e);var Ce=e=>new Error(e),et=()=>{throw Ce("Method unimplemented")},G=()=>{throw Ce("Unexpected case")};var Ji=Object.keys;var Es=e=>Ji(e).length;var Gi=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},Wi=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),_s=(e,t)=>e===t||Es(e)===Es(t)&&Gi(e,(n,r)=>(n!==void 0||Wi(t,r))&&t[r]===n);var Ee=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&&Ee(e,t,n+1)}};var at=Symbol;var dr=class{constructor(t,n){this.left=t,this.right=n}},lt=(e,t)=>new dr(e,t);var Vt=typeof document<"u"?document:{};var Fl=typeof DOMParser<"u"?new DOMParser:null;var As=e=>cs(e,(t,n)=>`${n}:${t};`).join("");var $l=Vt.ELEMENT_NODE,Pl=Vt.TEXT_NODE,ql=Vt.CDATA_SECTION_NODE,zl=Vt.COMMENT_NODE,Hl=Vt.DOCUMENT_NODE,Jl=Vt.DOCUMENT_TYPE_NODE,Gl=Vt.DOCUMENT_FRAGMENT_NODE;var rn=at(),sn=at(),Ds=at(),Ts=at(),Is=at(),on=at(),js=at(),cn=at(),Ls=at(),tc={[rn]:lt("font-weight","bold"),[sn]:lt("font-weight","normal"),[Ds]:lt("color","blue"),[Is]:lt("color","green"),[Ts]:lt("color","grey"),[on]:lt("color","red"),[js]:lt("color","purple"),[cn]:lt("color","orange"),[Ls]:lt("color","black")},ec={[rn]:"\x1B[1m",[sn]:"\x1B[2m",[Ds]:"\x1B[34m",[Is]:"\x1B[32m",[Ts]:"\x1B[37m",[on]:"\x1B[31m",[js]:"\x1B[35m",[cn]:"\x1B[38;5;208m",[Ls]:"\x1B[0m"},nc=e=>{let t=[],n=[],r=q(),s=[],o=0;for(;o<e.length;o++){let i=e[o],c=tc[i];if(c!==void 0)r.set(c.left,c.right);else if(i.constructor===String||i.constructor===Number){let a=As(r);o>0||a.length>0?(t.push("%c"+i),n.push(a)):t.push(i)}else break}for(o>0&&(s=n,s.unshift(t.join("")));o<e.length;o++){let i=e[o];i instanceof Symbol||s.push(i)}return s},rc=e=>{let t=[],n=[],r=0;for(;r<e.length;r++){let s=e[r],o=ec[s];if(o!==void 0)t.push(o);else if(s.constructor===String||s.constructor===Number)t.push(s);else break}for(r>0&&(t.push("\x1B[0m"),n.push(t.join("")));r<e.length;r++){let s=e[r];s instanceof Symbol||n.push(s)}return n},sc=Qe?rc:nc,an=(...e)=>{console.log(...sc(e)),oc.forEach(t=>t.print(e))};var oc=new Set;var Ql=nn();var Bs=e=>({[Symbol.iterator](){return this},next:e}),Os=(e,t)=>Bs(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),ln=(e,t)=>Bs(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var hr=class extends Wt{constructor(t,n){super(),this.doc=t,this.awareness=n}},De=class{constructor(t,n){this.clock=t,this.len=n}},kt=class{constructor(){this.clients=new Map}},vt=(e,t,n)=>t.clients.forEach((r,s)=>{let o=e.doc.store.clients.get(s);for(let i=0;i<r.length;i++){let c=r[i];oo(e,o,c.clock,c.len,n)}}),dc=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let s=Kt((n+r)/2),o=e[s],i=o.clock;if(i<=t){if(t<i+o.len)return s;n=s+1}else r=s-1}return null},de=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&dc(n,t.clock)!==null},Sr=e=>{e.clients.forEach(t=>{t.sort((s,o)=>s.clock-o.clock);let n,r;for(n=1,r=1;n<t.length;n++){let s=t[r-1],o=t[n];s.clock+s.len>=o.clock?s.len=ft(s.len,o.clock+o.len-s.clock):(r<n&&(t[r]=o),r++)}t.length=r})},Te=e=>{let t=new kt;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,s)=>{if(!t.clients.has(s)){let o=r.slice();for(let i=n+1;i<e.length;i++)ds(o,e[i].clients.get(s)||[]);t.clients.set(s,o)}});return Sr(t),t},Ie=(e,t,n,r)=>{it(e.clients,t,()=>[]).push(new De(n,r))},Tn=()=>new kt,Ur=e=>{let t=Tn();return e.clients.forEach((n,r)=>{let s=[];for(let o=0;o<n.length;o++){let i=n[o];if(i.deleted){let c=i.id.clock,a=i.length;if(o+1<n.length)for(let l=n[o+1];o+1<n.length&&l.deleted;l=n[++o+1])a+=l.length;s.push(new De(c,a))}}s.length>0&&t.clients.set(r,s)}),t},dt=(e,t)=>{S(e.restEncoder,t.clients.size),t.clients.forEach((n,r)=>{e.resetDsCurVal(),S(e.restEncoder,r);let s=n.length;S(e.restEncoder,s);for(let o=0;o<s;o++){let i=n[o];e.writeDsClock(i.clock),e.writeDsLen(i.len)}})},Ct=e=>{let t=new kt,n=v(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();let s=v(e.restDecoder),o=v(e.restDecoder);if(o>0){let i=it(t.clients,s,()=>[]);for(let c=0;c<o;c++)i.push(new De(e.readDsClock(),e.readDsLen()))}}return t},Vs=(e,t,n)=>{let r=new kt,s=v(e.restDecoder);for(let o=0;o<s;o++){e.resetDsCurVal();let i=v(e.restDecoder),c=v(e.restDecoder),a=n.clients.get(i)||[],l=I(n,i);for(let d=0;d<c;d++){let u=e.readDsClock(),h=u+e.readDsLen();if(u<l){l<h&&Ie(r,i,l,h-l);let f=X(a,u),y=a[f];for(!y.deleted&&y.id.clock<u&&(a.splice(f+1,0,Dn(t,y,u-y.id.clock)),f++);f<a.length&&(y=a[f++],y.id.clock<h);)y.deleted||(h<y.id.clock+y.length&&a.splice(f,0,Dn(t,y,h-y.id.clock)),y.delete(t))}else Ie(r,i,u,h-u)}}if(r.clients.size>0){let o=new rt;return S(o.restEncoder,0),dt(o,r),o.toUint8Array()}return null},Xs=lr,$t=class e extends Wt{constructor({guid:t=ks(),collectionid:n=null,gc:r=!0,gcFilter:s=()=>!0,meta:o=null,autoLoad:i=!1,shouldLoad:c=!0}={}){super(),this.gc=r,this.gcFilter=s,this.clientID=Xs(),this.guid=t,this.collectionid=n,this.share=new Map,this.store=new wn,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=c,this.autoLoad=i,this.meta=o,this.isLoaded=!1,this.whenLoaded=Cs(a=>{this.on("load",()=>{this.isLoaded=!0,a(this)})})}load(){let t=this._item;t!==null&&!this.shouldLoad&&D(t.parent.doc,n=>{n.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(Array.from(this.subdocs).map(t=>t.guid))}transact(t,n=null){D(this,t,n)}get(t,n=L){let r=it(this.share,t,()=>{let o=new n;return o._integrate(this,null),o}),s=r.constructor;if(n!==L&&s!==n)if(s===L){let o=new n;o._map=r._map,r._map.forEach(i=>{for(;i!==null;i=i.left)i.parent=o}),o._start=r._start;for(let i=o._start;i!==null;i=i.right)i.parent=o;return o._length=r._length,this.share.set(t,o),o._integrate(this,null),o}else throw new Error(`Type with the name ${t} has already been defined with a different constructor`);return r}getArray(t=""){return this.get(t,W)}getText(t=""){return this.get(t,ce)}getMap(t=""){return this.get(t,Q)}getXmlFragment(t=""){return this.get(t,zt)}toJSON(){let t={};return this.share.forEach((n,r)=>{t[r]=n.toJSON()}),t}destroy(){Ke(this.subdocs).forEach(n=>n.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,D(t.parent.doc,r=>{let s=n.doc;t.deleted||r.subdocsAdded.add(s),r.subdocsRemoved.add(this)},null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),super.destroy()}on(t,n){super.on(t,n)}off(t,n){super.off(t,n)}},Pt=class{constructor(t){this.restDecoder=t}resetDsCurVal(){}readDsClock(){return v(this.restDecoder)}readDsLen(){return v(this.restDecoder)}},nt=class extends Pt{readLeftID(){return U(v(this.restDecoder),v(this.restDecoder))}readRightID(){return U(v(this.restDecoder),v(this.restDecoder))}readClient(){return v(this.restDecoder)}readInfo(){return Lt(this.restDecoder)}readString(){return wt(this.restDecoder)}readParentInfo(){return v(this.restDecoder)===1}readTypeRef(){return v(this.restDecoder)}readLen(){return v(this.restDecoder)}readAny(){return Xt(this.restDecoder)}readBuf(){return ms(z(this.restDecoder))}readJSON(){return JSON.parse(wt(this.restDecoder))}readKey(){return wt(this.restDecoder)}},mn=class{constructor(t){this.dsCurrVal=0,this.restDecoder=t}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=v(this.restDecoder),this.dsCurrVal}readDsLen(){let t=v(this.restDecoder)+1;return this.dsCurrVal+=t,t}},Y=class extends mn{constructor(t){super(t),this.keys=[],v(t),this.keyClockDecoder=new Qt(z(t)),this.clientDecoder=new Bt(z(t)),this.leftClockDecoder=new Qt(z(t)),this.rightClockDecoder=new Qt(z(t)),this.infoDecoder=new xe(z(t),Lt),this.stringDecoder=new tn(z(t)),this.parentInfoDecoder=new xe(z(t),Lt),this.typeRefDecoder=new Bt(z(t)),this.lenDecoder=new Bt(z(t))}readLeftID(){return new pt(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new pt(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Xt(this.restDecoder)}readBuf(){return z(this.restDecoder)}readJSON(){return Xt(this.restDecoder)}readKey(){let t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];{let n=this.stringDecoder.read();return this.keys.push(n),n}}},Et=class{constructor(){this.restEncoder=Nt()}toUint8Array(){return H(this.restEncoder)}resetDsCurVal(){}writeDsClock(t){S(this.restEncoder,t)}writeDsLen(t){S(this.restEncoder,t)}},gt=class extends Et{writeLeftID(t){S(this.restEncoder,t.client),S(this.restEncoder,t.clock)}writeRightID(t){S(this.restEncoder,t.client),S(this.restEncoder,t.clock)}writeClient(t){S(this.restEncoder,t)}writeInfo(t){re(this.restEncoder,t)}writeString(t){xt(this.restEncoder,t)}writeParentInfo(t){S(this.restEncoder,t?1:0)}writeTypeRef(t){S(this.restEncoder,t)}writeLen(t){S(this.restEncoder,t)}writeAny(t){ee(this.restEncoder,t)}writeBuf(t){J(this.restEncoder,t)}writeJSON(t){xt(this.restEncoder,JSON.stringify(t))}writeKey(t){xt(this.restEncoder,t)}},oe=class{constructor(){this.restEncoder=Nt(),this.dsCurrVal=0}toUint8Array(){return H(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(t){let n=t-this.dsCurrVal;this.dsCurrVal=t,S(this.restEncoder,n)}writeDsLen(t){t===0&&G(),S(this.restEncoder,t-1),this.dsCurrVal+=t}},rt=class extends oe{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new ne,this.clientEncoder=new Mt,this.leftClockEncoder=new ne,this.rightClockEncoder=new ne,this.infoEncoder=new ke(re),this.stringEncoder=new en,this.parentInfoEncoder=new ke(re),this.typeRefEncoder=new Mt,this.lenEncoder=new Mt}toUint8Array(){let t=Nt();return S(t,0),J(t,this.keyClockEncoder.toUint8Array()),J(t,this.clientEncoder.toUint8Array()),J(t,this.leftClockEncoder.toUint8Array()),J(t,this.rightClockEncoder.toUint8Array()),J(t,H(this.infoEncoder)),J(t,this.stringEncoder.toUint8Array()),J(t,H(this.parentInfoEncoder)),J(t,this.typeRefEncoder.toUint8Array()),J(t,this.lenEncoder.toUint8Array()),se(t,H(this.restEncoder)),H(t)}writeLeftID(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}writeRightID(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}writeClient(t){this.clientEncoder.write(t)}writeInfo(t){this.infoEncoder.write(t)}writeString(t){this.stringEncoder.write(t)}writeParentInfo(t){this.parentInfoEncoder.write(t?1:0)}writeTypeRef(t){this.typeRefEncoder.write(t)}writeLen(t){this.lenEncoder.write(t)}writeAny(t){ee(this.restEncoder,t)}writeBuf(t){J(this.restEncoder,t)}writeJSON(t){ee(this.restEncoder,t)}writeKey(t){let n=this.keyMap.get(t);n===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(n)}},uc=(e,t,n,r)=>{r=ft(r,t[0].id.clock);let s=X(t,r);S(e.restEncoder,t.length-s),e.writeClient(n),S(e.restEncoder,r);let o=t[s];o.write(e,r-o.id.clock);for(let i=s+1;i<t.length;i++)t[i].write(e,0)},kr=(e,t,n)=>{let r=new Map;n.forEach((s,o)=>{I(t,o)>s&&r.set(o,s)}),Pe(t).forEach((s,o)=>{n.has(o)||r.set(o,0)}),S(e.restEncoder,r.size),Array.from(r.entries()).sort((s,o)=>o[0]-s[0]).forEach(([s,o])=>{uc(e,t.clients.get(s),s,o)})},hc=(e,t)=>{let n=q(),r=v(e.restDecoder);for(let s=0;s<r;s++){let o=v(e.restDecoder),i=new Array(o),c=e.readClient(),a=v(e.restDecoder);n.set(c,{i:0,refs:i});for(let l=0;l<o;l++){let d=e.readInfo();switch(31&d){case 0:{let u=e.readLen();i[l]=new $(U(c,a),u),a+=u;break}case 10:{let u=v(e.restDecoder);i[l]=new P(U(c,a),u),a+=u;break}default:{let u=(d&192)===0,h=new T(U(c,a),null,(d&128)===128?e.readLeftID():null,null,(d&64)===64?e.readRightID():null,u?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,u&&(d&32)===32?e.readString():null,Mo(e,d));i[l]=h,a+=h.length}}}}return n},fc=(e,t,n)=>{let r=[],s=Array.from(n.keys()).sort((f,y)=>f-y);if(s.length===0)return null;let o=()=>{if(s.length===0)return null;let f=n.get(s[s.length-1]);for(;f.refs.length===f.i;)if(s.pop(),s.length>0)f=n.get(s[s.length-1]);else return null;return f},i=o();if(i===null&&r.length===0)return null;let c=new wn,a=new Map,l=(f,y)=>{let x=a.get(f);(x==null||x>y)&&a.set(f,y)},d=i.refs[i.i++],u=new Map,h=()=>{for(let f of r){let y=f.id.client,x=n.get(y);x?(x.i--,c.clients.set(y,x.refs.slice(x.i)),n.delete(y),x.i=0,x.refs=[]):c.clients.set(y,[f]),s=s.filter(k=>k!==y)}r.length=0};for(;;){if(d.constructor!==P){let y=it(u,d.id.client,()=>I(t,d.id.client))-d.id.clock;if(y<0)r.push(d),l(d.id.client,d.id.clock-1),h();else{let x=d.getMissing(e,t);if(x!==null){r.push(d);let k=n.get(x)||{refs:[],i:0};if(k.refs.length===k.i)l(x,I(t,x)),h();else{d=k.refs[k.i++];continue}}else(y===0||y<d.length)&&(d.integrate(e,y),u.set(d.id.client,d.id.clock+d.length))}}if(r.length>0)d=r.pop();else if(i!==null&&i.i<i.refs.length)d=i.refs[i.i++];else{if(i=o(),i===null)break;d=i.refs[i.i++]}}if(c.clients.size>0){let f=new rt;return kr(f,c,new Map),S(f.restEncoder,0),{missing:a,update:f.toUint8Array()}}return null},pc=(e,t)=>kr(e,t.doc.store,t.beforeState),vr=(e,t,n,r=new Y(e))=>D(t,s=>{s.local=!1;let o=!1,i=s.doc,c=i.store,a=hc(r,i),l=fc(s,c,a),d=c.pendingStructs;if(d){for(let[h,f]of d.missing)if(f<I(c,h)){o=!0;break}if(l){for(let[h,f]of l.missing){let y=d.missing.get(h);(y==null||y>f)&&d.missing.set(h,f)}d.update=Oe([d.update,l.update])}}else c.pendingStructs=l;let u=Vs(r,s,c);if(c.pendingDs){let h=new Y(V(c.pendingDs));v(h.restDecoder);let f=Vs(h,s,c);u&&f?c.pendingDs=Oe([u,f]):c.pendingDs=u||f}else c.pendingDs=u;if(o){let h=c.pendingStructs.update;c.pendingStructs=null,In(s.doc,h)}},n,!1),gc=(e,t,n)=>vr(e,t,n,new nt(e)),In=(e,t,n,r=Y)=>{let s=V(t);vr(s,e,n,new r(s))},mc=(e,t,n)=>In(e,t,n,nt),yc=(e,t,n=new Map)=>{kr(e,t.store,n),dt(e,Ur(t.store))},Qs=(e,t=new Uint8Array([0]),n=new rt)=>{let r=Cr(t);yc(n,e,r);let s=[n.toUint8Array()];if(e.store.pendingDs&&s.push(e.store.pendingDs),e.store.pendingStructs&&s.push(Dr(e.store.pendingStructs.update,t)),s.length>1){if(n.constructor===gt)return ho(s.map((o,i)=>i===0?o:yo(o)));if(n.constructor===rt)return Oe(s)}return s[0]},wc=(e,t)=>Qs(e,t,new gt),to=e=>{let t=new Map,n=v(e.restDecoder);for(let r=0;r<n;r++){let s=v(e.restDecoder),o=v(e.restDecoder);t.set(s,o)}return t},Cr=e=>to(new Pt(V(e))),Er=(e,t)=>(S(e.restEncoder,t.size),Array.from(t.entries()).sort((n,r)=>r[0]-n[0]).forEach(([n,r])=>{S(e.restEncoder,n),S(e.restEncoder,r)}),e),bc=(e,t)=>Er(e,Pe(t.store)),xc=(e,t=new oe)=>(e instanceof Map?Er(t,e):bc(t,e),t.toUint8Array()),Sc=e=>xc(e,new Et),fr=class{constructor(){this.l=[]}},Rs=()=>new fr,Fs=(e,t)=>e.l.push(t),$s=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(s=>t!==s),r===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},eo=(e,t,n)=>Ee(e.l,[t,n]),pt=class{constructor(t,n){this.client=t,this.clock=n}},Ft=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,U=(e,t)=>new pt(e,t),Ps=(e,t)=>{S(e,t.client),S(e,t.clock)},qs=e=>U(v(e),v(e)),_r=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw G()},je=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1},Uc=e=>{let t=[],n=e._start;for(;n;)t.push(n),n=n.right;console.log("Children: ",t),console.log("Children content: ",t.filter(r=>!r.deleted).map(r=>r.content))},pr=class{constructor(t,n=t.getMap("users")){let r=new Map;this.yusers=n,this.doc=t,this.clients=new Map,this.dss=r;let s=(o,i)=>{let c=o.get("ds"),a=o.get("ids"),l=d=>this.clients.set(d,i);c.observe(d=>{d.changes.added.forEach(u=>{u.content.getContent().forEach(h=>{h instanceof Uint8Array&&this.dss.set(i,Te([this.dss.get(i)||Tn(),Ct(new Pt(V(h)))]))})})}),this.dss.set(i,Te(c.map(d=>Ct(new Pt(V(d)))))),a.observe(d=>d.changes.added.forEach(u=>u.content.getContent().forEach(l))),a.forEach(l)};n.observe(o=>{o.keysChanged.forEach(i=>s(n.get(i),i))}),n.forEach(s)}setUserMapping(t,n,r,{filter:s=()=>!0}={}){let o=this.yusers,i=o.get(r);i||(i=new Q,i.set("ids",new W),i.set("ds",new W),o.set(r,i)),i.get("ids").push([n]),o.observe(c=>{setTimeout(()=>{let a=o.get(r);if(a!==i){i=a,this.clients.forEach((u,h)=>{r===u&&i.get("ids").push([h])});let l=new Et,d=this.dss.get(r);d&&(dt(l,d),i.get("ds").push([l.toUint8Array()]))}},0)}),t.on("afterTransaction",c=>{setTimeout(()=>{let a=i.get("ds"),l=c.deleteSet;if(c.local&&l.clients.size>0&&s(c,l)){let d=new Et;dt(d,l),a.push([d.toUint8Array()])}})})}getUserByClientId(t){return this.clients.get(t)||null}getUserByDeletedId(t){for(let[n,r]of this.dss.entries())if(de(r,t))return n;return null}},ie=class{constructor(t,n,r,s=0){this.type=t,this.tname=n,this.item=r,this.assoc=s}},kc=e=>{let t={};return e.type&&(t.type=e.type),e.tname&&(t.tname=e.tname),e.item&&(t.item=e.item),e.assoc!=null&&(t.assoc=e.assoc),t},vc=e=>new ie(e.type==null?null:U(e.type.client,e.type.clock),e.tname||null,e.item==null?null:U(e.item.client,e.item.clock),e.assoc==null?0:e.assoc),yn=class{constructor(t,n,r=0){this.type=t,this.index=n,this.assoc=r}},Cc=(e,t,n=0)=>new yn(e,t,n),dn=(e,t,n)=>{let r=null,s=null;return e._item===null?s=_r(e):r=U(e._item.id.client,e._item.id.clock),new ie(r,s,t,n)},Ec=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return dn(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return dn(e,U(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return dn(e,r.lastId,n);r=r.right}return dn(e,null,n)},_c=(e,t)=>{let{type:n,tname:r,item:s,assoc:o}=t;if(s!==null)S(e,0),Ps(e,s);else if(r!==null)re(e,1),xt(e,r);else if(n!==null)re(e,2),Ps(e,n);else throw G();return ve(e,o),e},Ac=e=>{let t=Nt();return _c(t,e),H(t)},Dc=e=>{let t=null,n=null,r=null;switch(v(e)){case 0:r=qs(e);break;case 1:n=wt(e);break;case 2:t=qs(e)}let s=sr(e)?Se(e):0;return new ie(t,n,r,s)},Tc=e=>Dc(V(e)),Ic=(e,t)=>{let n=t.store,r=e.item,s=e.type,o=e.tname,i=e.assoc,c=null,a=0;if(r!==null){if(I(n,r.client)<=r.clock)return null;let l=br(n,r),d=l.item;if(!(d instanceof T))return null;if(c=d.parent,c._item===null||!c._item.deleted){a=d.deleted||!d.countable?0:l.diff+(i>=0?0:1);let u=d.left;for(;u!==null;)!u.deleted&&u.countable&&(a+=u.length),u=u.left}}else{if(o!==null)c=t.get(o);else if(s!==null){if(I(n,s.client)<=s.clock)return null;let{item:l}=br(n,s);if(l instanceof T&&l.content instanceof st)c=l.content.type;else return null}else throw G();i>=0?a=c._length:a=0}return Cc(c,a,e.assoc)},jc=(e,t)=>e===t||e!==null&&t!==null&&e.tname===t.tname&&Ft(e.item,t.item)&&Ft(e.type,t.type)&&e.assoc===t.assoc,Le=class{constructor(t,n){this.ds=t,this.sv=n}},Lc=(e,t)=>{let n=e.ds.clients,r=t.ds.clients,s=e.sv,o=t.sv;if(s.size!==o.size||n.size!==r.size)return!1;for(let[i,c]of s.entries())if(o.get(i)!==c)return!1;for(let[i,c]of n.entries()){let a=r.get(i)||[];if(c.length!==a.length)return!1;for(let l=0;l<c.length;l++){let d=c[l],u=a[l];if(d.clock!==u.clock||d.len!==u.len)return!1}}return!0},no=(e,t=new oe)=>(dt(t,e.ds),Er(t,e.sv),t.toUint8Array()),Bc=e=>no(e,new Et),ro=(e,t=new mn(V(e)))=>new Le(Ct(t),to(t)),Oc=e=>ro(e,new Pt(V(e))),Ar=(e,t)=>new Le(e,t),Mc=Ar(Tn(),new Map),Nc=e=>Ar(Ur(e.store),Pe(e.store)),Rt=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!de(t.ds,e.id),fn=(e,t)=>{let n=it(e.meta,fn,jt),r=e.doc.store;n.has(t)||(t.sv.forEach((s,o)=>{s<I(r,o)&&F(e,U(o,s))}),vt(e,t.ds,s=>{}),n.add(t))},Vc=(e,t,n=new $t)=>{if(e.gc)throw new Error("originDoc must not be garbage collected");let{sv:r,ds:s}=t,o=new rt;return e.transact(i=>{let c=0;r.forEach(a=>{a>0&&c++}),S(o.restEncoder,c);for(let[a,l]of r){if(l===0)continue;l<I(e.store,a)&&F(i,U(a,l));let d=e.store.clients.get(a)||[],u=X(d,l-1);S(o.restEncoder,u+1),o.writeClient(a),S(o.restEncoder,0);for(let h=0;h<=u;h++)d[h].write(o,0)}dt(o,s)}),In(n,o.toUint8Array(),"snapshot"),n},wn=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}},Pe=e=>{let t=new Map;return e.clients.forEach((n,r)=>{let s=n[n.length-1];t.set(r,s.id.clock+s.length)}),t},I=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},so=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let r=n[n.length-1];if(r.id.clock+r.length!==t.id.clock)throw G()}n.push(t)},X=(e,t)=>{let n=0,r=e.length-1,s=e[r],o=s.id.clock;if(o===t)return r;let i=Kt(t/(o+s.length-1)*r);for(;n<=r;){if(s=e[i],o=s.id.clock,o<=t){if(t<o+s.length)return i;n=i+1}else r=i-1;i=Kt((n+r)/2)}throw G()},Rc=(e,t)=>{let n=e.clients.get(t.client);return n[X(n,t.clock)]},_e=Rc,gr=(e,t,n)=>{let r=X(t,n),s=t[r];return s.id.clock<n&&s instanceof T?(t.splice(r+1,0,Dn(e,s,n-s.id.clock)),r+1):r},F=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[gr(e,n,t.clock)]},zs=(e,t,n)=>{let r=t.clients.get(n.client),s=X(r,n.clock),o=r[s];return n.clock!==o.id.clock+o.length-1&&o.constructor!==$&&r.splice(s+1,0,Dn(e,o,n.clock-o.id.clock+1)),o},Fc=(e,t,n)=>{let r=e.clients.get(t.id.client);r[X(r,t.id.clock)]=n},oo=(e,t,n,r,s)=>{if(r===0)return;let o=n+r,i=gr(e,t,n),c;do c=t[i++],o<c.id.clock+c.length&&gr(e,t,o),s(c);while(i<t.length&&t[i].id.clock<o)},bn=class{constructor(t,n,r){this.doc=t,this.deleteSet=new kt,this.beforeState=Pe(t.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=n,this.meta=new Map,this.local=r,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set}},Hs=(e,t)=>t.deleteSet.clients.size===0&&!as(t.afterState,(n,r)=>t.beforeState.get(r)!==n)?!1:(Sr(t.deleteSet),pc(e,t),dt(e,t.deleteSet),!0),Js=(e,t,n)=>{let r=t._item;(r===null||r.id.clock<(e.beforeState.get(r.id.client)||0)&&!r.deleted)&&it(e.changed,t,jt).add(n)},pn=(e,t)=>{let n=e[t-1],r=e[t];n.deleted===r.deleted&&n.constructor===r.constructor&&n.mergeWith(r)&&(e.splice(t,1),r instanceof T&&r.parentSub!==null&&r.parent._map.get(r.parentSub)===r&&r.parent._map.set(r.parentSub,n))},io=(e,t,n)=>{for(let[r,s]of e.clients.entries()){let o=t.clients.get(r);for(let i=s.length-1;i>=0;i--){let c=s[i],a=c.clock+c.len;for(let l=X(o,c.clock),d=o[l];l<o.length&&d.id.clock<a;d=o[++l]){let u=o[l];if(c.clock+c.len<=u.id.clock)break;u instanceof T&&u.deleted&&!u.keep&&n(u)&&u.gc(t,!1)}}}},co=(e,t)=>{e.clients.forEach((n,r)=>{let s=t.clients.get(r);for(let o=n.length-1;o>=0;o--){let i=n[o],c=Ze(s.length-1,1+X(s,i.clock+i.len-1));for(let a=c,l=s[a];a>0&&l.id.clock>=i.clock;l=s[--a])pn(s,a)}})},$c=(e,t,n)=>{io(e,t,n),co(e,t)},ao=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,s=r.store,o=n.deleteSet,i=n._mergeStructs;try{Sr(o),n.afterState=Pe(n.doc.store),r._transaction=null,r.emit("beforeObserverCalls",[n,r]);let c=[];n.changed.forEach((a,l)=>c.push(()=>{(l._item===null||!l._item.deleted)&&l._callObserver(n,a)})),c.push(()=>{n.changedParentTypes.forEach((a,l)=>c.push(()=>{(l._item===null||!l._item.deleted)&&(a=a.filter(d=>d.target._item===null||!d.target._item.deleted),a.forEach(d=>{d.currentTarget=l}),a.sort((d,u)=>d.path.length-u.path.length),eo(l._dEH,a,n))})),c.push(()=>r.emit("afterTransaction",[n,r]))}),Ee(c,[])}finally{r.gc&&io(o,s,r.gcFilter),co(o,s),n.afterState.forEach((d,u)=>{let h=n.beforeState.get(u)||0;if(h!==d){let f=s.clients.get(u),y=ft(X(f,h),1);for(let x=f.length-1;x>=y;x--)pn(f,x)}});for(let d=0;d<i.length;d++){let{client:u,clock:h}=i[d].id,f=s.clients.get(u),y=X(f,h);y+1<f.length&&pn(f,y+1),y>0&&pn(f,y)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(an(cn,rn,"[yjs] ",sn,on,"Changed the client-id because another client seems to be using it."),r.clientID=Xs()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){let d=new gt;Hs(d,n)&&r.emit("update",[d.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){let d=new rt;Hs(d,n)&&r.emit("updateV2",[d.toUint8Array(),n.origin,r,n])}let{subdocsAdded:c,subdocsLoaded:a,subdocsRemoved:l}=n;(c.size>0||l.size>0||a.size>0)&&(c.forEach(d=>{d.clientID=r.clientID,d.collectionid==null&&(d.collectionid=r.collectionid),r.subdocs.add(d)}),l.forEach(d=>r.subdocs.delete(d)),r.emit("subdocs",[{loaded:a,added:c,removed:l},r,n]),l.forEach(d=>d.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,e])):ao(e,t+1)}}},D=(e,t,n=null,r=!0)=>{let s=e._transactionCleanups,o=!1;e._transaction===null&&(o=!0,e._transaction=new bn(e,n,r),s.push(e._transaction),s.length===1&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{t(e._transaction)}finally{o&&s[0]===e._transaction&&ao(s,0)}},mr=class{constructor(t,n){this.insertions=n,this.deletions=t,this.meta=new Map}},Gs=(e,t,n)=>{vt(e,n.deletions,r=>{r instanceof T&&t.scope.some(s=>je(s,r))&&Br(r,!1)})},Ws=(e,t,n)=>{let r=null,s=null,o=e.doc,i=e.scope;if(D(o,c=>{for(;t.length>0&&r===null;){let a=o.store,l=t.pop(),d=new Set,u=[],h=!1;vt(c,l.insertions,f=>{if(f instanceof T){if(f.redone!==null){let{item:y,diff:x}=br(a,f.id);x>0&&(y=F(c,U(y.id.client,y.id.clock+x))),f=y}!f.deleted&&i.some(y=>je(y,f))&&u.push(f)}}),vt(c,l.deletions,f=>{f instanceof T&&i.some(y=>je(y,f))&&!de(l.insertions,f.id)&&d.add(f)}),d.forEach(f=>{h=Oo(c,f,d,l.insertions,e.ignoreRemoteMapChanges)!==null||h});for(let f=u.length-1;f>=0;f--){let y=u[f];e.deleteFilter(y)&&(y.delete(c),h=!0)}r=h?l:null}c.changed.forEach((a,l)=>{a.has(null)&&l._searchMarker&&(l._searchMarker.length=0)}),s=c},e),r!=null){let c=s.changedParentTypes;e.emit("stack-item-popped",[{stackItem:r,type:n,changedParentTypes:c},e])}return r},yr=class extends Wt{constructor(t,{captureTimeout:n=500,captureTransaction:r=a=>!0,deleteFilter:s=()=>!0,trackedOrigins:o=new Set([null]),ignoreRemoteMapChanges:i=!1,doc:c=Qn(t)?t[0].doc:t.doc}={}){super(),this.scope=[],this.addToScope(t),this.deleteFilter=s,o.add(this),this.trackedOrigins=o,this.captureTransaction=r,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.doc=c,this.lastChange=0,this.ignoreRemoteMapChanges=i,this.afterTransactionHandler=a=>{if(!this.captureTransaction(a)||!this.scope.some(k=>a.changedParentTypes.has(k))||!this.trackedOrigins.has(a.origin)&&(!a.origin||!this.trackedOrigins.has(a.origin.constructor)))return;let l=this.undoing,d=this.redoing,u=l?this.redoStack:this.undoStack;l?this.stopCapturing():d||this.clear(!1,!0);let h=new kt;a.afterState.forEach((k,C)=>{let A=a.beforeState.get(C)||0,O=k-A;O>0&&Ie(h,C,A,O)});let f=nn(),y=!1;if(f-this.lastChange<n&&u.length>0&&!l&&!d){let k=u[u.length-1];k.deletions=Te([k.deletions,a.deleteSet]),k.insertions=Te([k.insertions,h])}else u.push(new mr(a.deleteSet,h)),y=!0;!l&&!d&&(this.lastChange=f),vt(a,a.deleteSet,k=>{k instanceof T&&this.scope.some(C=>je(C,k))&&Br(k,!0)});let x=[{stackItem:u[u.length-1],origin:a.origin,type:l?"redo":"undo",changedParentTypes:a.changedParentTypes},this];y?this.emit("stack-item-added",x):this.emit("stack-item-updated",x)},this.doc.on("afterTransaction",this.afterTransactionHandler),this.doc.on("destroy",()=>{this.destroy()})}addToScope(t){t=Qn(t)?t:[t],t.forEach(n=>{this.scope.every(r=>r!==n)&&this.scope.push(n)})}addTrackedOrigin(t){this.trackedOrigins.add(t)}removeTrackedOrigin(t){this.trackedOrigins.delete(t)}clear(t=!0,n=!0){(t&&this.canUndo()||n&&this.canRedo())&&this.doc.transact(r=>{t&&(this.undoStack.forEach(s=>Gs(r,this,s)),this.undoStack=[]),n&&(this.redoStack.forEach(s=>Gs(r,this,s)),this.redoStack=[]),this.emit("stack-cleared",[{undoStackCleared:t,redoStackCleared:n}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let t;try{t=Ws(this,this.undoStack,"undo")}finally{this.undoing=!1}return t}redo(){this.redoing=!0;let t;try{t=Ws(this,this.redoStack,"redo")}finally{this.redoing=!1}return t}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off("afterTransaction",this.afterTransactionHandler),super.destroy()}};function*Pc(e){let t=v(e.restDecoder);for(let n=0;n<t;n++){let r=v(e.restDecoder),s=e.readClient(),o=v(e.restDecoder);for(let i=0;i<r;i++){let c=e.readInfo();if(c===10){let a=v(e.restDecoder);yield new P(U(s,o),a),o+=a}else if(31&c){let a=(c&192)===0,l=new T(U(s,o),null,(c&128)===128?e.readLeftID():null,null,(c&64)===64?e.readRightID():null,a?e.readParentInfo()?e.readString():e.readLeftID():null,a&&(c&32)===32?e.readString():null,Mo(e,c));yield l,o+=l.length}else{let a=e.readLen();yield new $(U(s,o),a),o+=a}}}}var mt=class{constructor(t,n){this.gen=Pc(t),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===P);return this.curr}},qc=e=>lo(e,nt),lo=(e,t=Y)=>{let n=[],r=new t(V(e)),s=new mt(r,!1);for(let i=s.curr;i!==null;i=s.next())n.push(i);an("Structs: ",n);let o=Ct(r);an("DeleteSet: ",o)},zc=e=>uo(e,nt),uo=(e,t=Y)=>{let n=[],r=new t(V(e)),s=new mt(r,!1);for(let o=s.curr;o!==null;o=s.next())n.push(o);return{structs:n,ds:Ct(r)}},Be=class{constructor(t){this.currClient=0,this.startClock=0,this.written=0,this.encoder=t,this.clientStructs=[]}},ho=e=>Oe(e,nt,gt),fo=(e,t=oe,n=Y)=>{let r=new t,s=new mt(new n(V(e)),!1),o=s.curr;if(o!==null){let i=0,c=o.id.client,a=o.id.clock!==0,l=a?0:o.id.clock+o.length;for(;o!==null;o=s.next())c!==o.id.client&&(l!==0&&(i++,S(r.restEncoder,c),S(r.restEncoder,l)),c=o.id.client,l=0,a=o.id.clock!==0),o.constructor===P&&(a=!0),a||(l=o.id.clock+o.length);l!==0&&(i++,S(r.restEncoder,c),S(r.restEncoder,l));let d=Nt();return S(d,i),Ss(d,r.restEncoder),r.restEncoder=d,r.toUint8Array()}else return S(r.restEncoder,0),r.toUint8Array()},Hc=e=>fo(e,Et,nt),po=(e,t=Y)=>{let n=new Map,r=new Map,s=new mt(new t(V(e)),!1),o=s.curr;if(o!==null){let i=o.id.client,c=o.id.clock;for(n.set(i,c);o!==null;o=s.next())i!==o.id.client&&(r.set(i,c),n.set(o.id.client,o.id.clock),i=o.id.client),c=o.id.clock+o.length;r.set(i,c)}return{from:n,to:r}},Jc=e=>po(e,nt),Gc=(e,t)=>{if(e.constructor===$){let{client:n,clock:r}=e.id;return new $(U(n,r+t),e.length-t)}else if(e.constructor===P){let{client:n,clock:r}=e.id;return new P(U(n,r+t),e.length-t)}else{let n=e,{client:r,clock:s}=n.id;return new T(U(r,s+t),null,U(r,s+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},Oe=(e,t=Y,n=rt)=>{if(e.length===1)return e[0];let r=e.map(d=>new t(V(d))),s=r.map(d=>new mt(d,!0)),o=null,i=new n,c=new Be(i);for(;s=s.filter(h=>h.curr!==null),s.sort((h,f)=>{if(h.curr.id.client===f.curr.id.client){let y=h.curr.id.clock-f.curr.id.clock;return y===0?h.curr.constructor===f.curr.constructor?0:h.curr.constructor===P?1:-1:y}else return f.curr.id.client-h.curr.id.client}),s.length!==0;){let d=s[0],u=d.curr.id.client;if(o!==null){let h=d.curr,f=!1;for(;h!==null&&h.id.clock+h.length<=o.struct.id.clock+o.struct.length&&h.id.client>=o.struct.id.client;)h=d.next(),f=!0;if(h===null||h.id.client!==u||f&&h.id.clock>o.struct.id.clock+o.struct.length)continue;if(u!==o.struct.id.client)St(c,o.struct,o.offset),o={struct:h,offset:0},d.next();else if(o.struct.id.clock+o.struct.length<h.id.clock)if(o.struct.constructor===P)o.struct.length=h.id.clock+h.length-o.struct.id.clock;else{St(c,o.struct,o.offset);let y=h.id.clock-o.struct.id.clock-o.struct.length;o={struct:new P(U(u,o.struct.id.clock+o.struct.length),y),offset:0}}else{let y=o.struct.id.clock+o.struct.length-h.id.clock;y>0&&(o.struct.constructor===P?o.struct.length-=y:h=Gc(h,y)),o.struct.mergeWith(h)||(St(c,o.struct,o.offset),o={struct:h,offset:0},d.next())}}else o={struct:d.curr,offset:0},d.next();for(let h=d.curr;h!==null&&h.id.client===u&&h.id.clock===o.struct.id.clock+o.struct.length&&h.constructor!==P;h=d.next())St(c,o.struct,o.offset),o={struct:h,offset:0}}o!==null&&(St(c,o.struct,o.offset),o=null),Tr(c);let a=r.map(d=>Ct(d)),l=Te(a);return dt(i,l),i.toUint8Array()},Dr=(e,t,n=Y,r=rt)=>{let s=Cr(t),o=new r,i=new Be(o),c=new n(V(e)),a=new mt(c,!1);for(;a.curr;){let d=a.curr,u=d.id.client,h=s.get(u)||0;if(a.curr.constructor===P){a.next();continue}if(d.id.clock+d.length>h)for(St(i,d,ft(h-d.id.clock,0)),a.next();a.curr&&a.curr.id.client===u;)St(i,a.curr,0),a.next();else for(;a.curr&&a.curr.id.client===u&&a.curr.id.clock+a.curr.length<=h;)a.next()}Tr(i);let l=Ct(c);return dt(o,l),o.toUint8Array()},Wc=(e,t)=>Dr(e,t,nt,gt),go=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:H(e.encoder.restEncoder)}),e.encoder.restEncoder=Nt(),e.written=0)},St=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&go(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),S(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Tr=e=>{go(e);let t=e.encoder.restEncoder;S(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];S(t,r.written),se(t,r.restEncoder)}},mo=(e,t,n)=>{let r=new t(V(e)),s=new mt(r,!1),o=new n,i=new Be(o);for(let a=s.curr;a!==null;a=s.next())St(i,a,0);Tr(i);let c=Ct(r);return dt(o,c),o.toUint8Array()},Kc=e=>mo(e,nt,rt),yo=e=>mo(e,Y,gt),qt=class{constructor(t,n){this.target=t,this.currentTarget=t,this.transaction=n,this._changes=null,this._keys=null,this._delta=null}get path(){return Zc(this.currentTarget,this.target)}deletes(t){return de(this.transaction.deleteSet,t.id)}get keys(){if(this._keys===null){let t=new Map,n=this.target;this.transaction.changed.get(n).forEach(s=>{if(s!==null){let o=n._map.get(s),i,c;if(this.adds(o)){let a=o.left;for(;a!==null&&this.adds(a);)a=a.left;if(this.deletes(o))if(a!==null&&this.deletes(a))i="delete",c=We(a.content.getContent());else return;else a!==null&&this.deletes(a)?(i="update",c=We(a.content.getContent())):(i="add",c=void 0)}else if(this.deletes(o))i="delete",c=We(o.content.getContent());else return;t.set(s,{action:i,oldValue:c})}}),this._keys=t}return this._keys}get delta(){return this.changes.delta}adds(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}get changes(){let t=this._changes;if(t===null){let n=this.target,r=jt(),s=jt(),o=[];if(t={added:r,deleted:s,delta:o,keys:this.keys},this.transaction.changed.get(n).has(null)){let c=null,a=()=>{c&&o.push(c)};for(let l=n._start;l!==null;l=l.right)l.deleted?this.deletes(l)&&!this.adds(l)&&((c===null||c.delete===void 0)&&(a(),c={delete:0}),c.delete+=l.length,s.add(l)):this.adds(l)?((c===null||c.insert===void 0)&&(a(),c={insert:[]}),c.insert=c.insert.concat(l.content.getContent()),r.add(l)):((c===null||c.retain===void 0)&&(a(),c={retain:0}),c.retain+=l.length);c!==null&&c.retain===void 0&&a()}this._changes=t}return t}},Zc=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let r=0,s=t._item.parent._start;for(;s!==t._item&&s!==null;)s.deleted||r++,s=s.right;n.unshift(r)}t=t._item.parent}return n},wo=80,Ir=0,wr=class{constructor(t,n){t.marker=!0,this.p=t,this.index=n,this.timestamp=Ir++}},Yc=e=>{e.timestamp=Ir++},bo=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Ir++},Xc=(e,t,n)=>{if(e.length>=wo){let r=e.reduce((s,o)=>s.timestamp<o.timestamp?s:o);return bo(r,t,n),r}else{let r=new wr(t,n);return e.push(r),r}},jn=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((o,i)=>Zt(t-o.index)<Zt(t-i.index)?o:i),r=e._start,s=0;for(n!==null&&(r=n.p,s=n.index,Yc(n));r.right!==null&&s<t;){if(!r.deleted&&r.countable){if(t<s+r.length)break;s+=r.length}r=r.right}for(;r.left!==null&&s>t;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(s-=r.length);return n!==null&&Zt(n.index-s)<r.parent.length/wo?(bo(n,r,s),n):Xc(e._searchMarker,r,s)},Me=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let s=e[r];if(n>0){let o=s.p;for(o.marker=!1;o&&(o.deleted||!o.countable);)o=o.left,o&&!o.deleted&&o.countable&&(s.index-=o.length);if(o===null||o.marker===!0){e.splice(r,1);continue}s.p=o,o.marker=!0}(t<s.index||n>0&&t===s.index)&&(s.index=ft(t,s.index+n))}},Qc=e=>{let t=e._start,n=[];for(;t;)n.push(t),t=t.right;return n},Ln=(e,t,n)=>{let r=e,s=t.changedParentTypes;for(;it(s,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;eo(r._eH,n,t)},L=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Rs(),this._dEH=Rs(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(t,n){this.doc=t,this._item=n}_copy(){throw et()}clone(){throw et()}_write(t){}get _first(){let t=this._start;for(;t!==null&&t.deleted;)t=t.right;return t}_callObserver(t,n){!t.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(t){Fs(this._eH,t)}observeDeep(t){Fs(this._dEH,t)}unobserve(t){$s(this._eH,t)}unobserveDeep(t){$s(this._dEH,t)}toJSON(){}},xo=(e,t,n)=>{t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,s=[],o=e._start;for(;o!==null&&r>0;){if(o.countable&&!o.deleted){let i=o.content.getContent();if(i.length<=t)t-=i.length;else{for(let c=t;c<i.length&&r>0;c++)s.push(i[c]),r--;t=0}}o=o.right}return s},So=e=>{let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let r=n.content.getContent();for(let s=0;s<r.length;s++)t.push(r[s])}n=n.right}return t},ta=(e,t)=>{let n=[],r=e._start;for(;r!==null;){if(r.countable&&Rt(r,t)){let s=r.content.getContent();for(let o=0;o<s.length;o++)n.push(s[o])}r=r.right}return n},Ne=(e,t)=>{let n=0,r=e._start;for(;r!==null;){if(r.countable&&!r.deleted){let s=r.content.getContent();for(let o=0;o<s.length;o++)t(s[o],n++,e)}r=r.right}},Uo=(e,t)=>{let n=[];return Ne(e,(r,s)=>{n.push(t(r,s,e))}),n},ea=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let s=n[r++];return n.length<=r&&(n=null),{done:!1,value:s}}}},ko=(e,t)=>{let n=jn(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},xn=(e,t,n,r)=>{let s=n,o=e.doc,i=o.clientID,c=o.store,a=n===null?t._start:n.right,l=[],d=()=>{l.length>0&&(s=new T(U(i,I(c,i)),s,s&&s.lastId,a,a&&a.id,t,null,new Ht(l)),s.integrate(e,0),l=[])};r.forEach(u=>{if(u===null)l.push(u);else switch(u.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(u);break;default:switch(d(),u.constructor){case Uint8Array:case ArrayBuffer:s=new T(U(i,I(c,i)),s,s&&s.lastId,a,a&&a.id,t,null,new le(new Uint8Array(u))),s.integrate(e,0);break;case $t:s=new T(U(i,I(c,i)),s,s&&s.lastId,a,a&&a.id,t,null,new $e(u)),s.integrate(e,0);break;default:if(u instanceof L)s=new T(U(i,I(c,i)),s,s&&s.lastId,a,a&&a.id,t,null,new st(u)),s.integrate(e,0);else throw new Error("Unexpected content type in insert operation")}}}),d()},vo=Ce("Length exceeded!"),Co=(e,t,n,r)=>{if(n>t._length)throw vo;if(n===0)return t._searchMarker&&Me(t._searchMarker,n,r.length),xn(e,t,null,r);let s=n,o=jn(t,n),i=t._start;for(o!==null&&(i=o.p,n-=o.index,n===0&&(i=i.prev,n+=i&&i.countable&&!i.deleted?i.length:0));i!==null;i=i.right)if(!i.deleted&&i.countable){if(n<=i.length){n<i.length&&F(e,U(i.id.client,i.id.clock+n));break}n-=i.length}return t._searchMarker&&Me(t._searchMarker,s,r.length),xn(e,t,i,r)},na=(e,t,n)=>{let s=(t._searchMarker||[]).reduce((o,i)=>i.index>o.index?i:o,{index:0,p:t._start}).p;if(s)for(;s.right;)s=s.right;return xn(e,t,s,n)},Eo=(e,t,n,r)=>{if(r===0)return;let s=n,o=r,i=jn(t,n),c=t._start;for(i!==null&&(c=i.p,n-=i.index);c!==null&&n>0;c=c.right)!c.deleted&&c.countable&&(n<c.length&&F(e,U(c.id.client,c.id.clock+n)),n-=c.length);for(;r>0&&c!==null;)c.deleted||(r<c.length&&F(e,U(c.id.client,c.id.clock+r)),c.delete(e),r-=c.length),c=c.right;if(r>0)throw vo;t._searchMarker&&Me(t._searchMarker,s,-o+r)},Sn=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},jr=(e,t,n,r)=>{let s=t._map.get(n)||null,o=e.doc,i=o.clientID,c;if(r==null)c=new Ht([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:c=new Ht([r]);break;case Uint8Array:c=new le(r);break;case $t:c=new $e(r);break;default:if(r instanceof L)c=new st(r);else throw new Error("Unexpected content type")}new T(U(i,I(o.store,i)),s,s&&s.lastId,null,null,t,n,c).integrate(e,0)},Lr=(e,t)=>{let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},_o=e=>{let t={};return e._map.forEach((n,r)=>{n.deleted||(t[r]=n.content.getContent()[n.length-1])}),t},Ao=(e,t)=>{let n=e._map.get(t);return n!==void 0&&!n.deleted},ra=(e,t,n)=>{let r=e._map.get(t)||null;for(;r!==null&&(!n.sv.has(r.id.client)||r.id.clock>=(n.sv.get(r.id.client)||0));)r=r.left;return r!==null&&Rt(r,n)?r.content.getContent()[r.length-1]:void 0},un=e=>Os(e.entries(),t=>!t[1].deleted),Un=class extends qt{constructor(t,n){super(t,n),this._transaction=n}},W=class e extends L{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof L?n.clone():n)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}_callObserver(t,n){super._callObserver(t,n),Ln(this,t,new Un(this,t))}insert(t,n){this.doc!==null?D(this.doc,r=>{Co(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}push(t){this.doc!==null?D(this.doc,n=>{na(n,this,t)}):this._prelimContent.push(...t)}unshift(t){this.insert(0,t)}delete(t,n=1){this.doc!==null?D(this.doc,r=>{Eo(r,this,t,n)}):this._prelimContent.splice(t,n)}get(t){return ko(this,t)}toArray(){return So(this)}slice(t=0,n=this.length){return xo(this,t,n)}toJSON(){return this.map(t=>t instanceof L?t.toJSON():t)}map(t){return Uo(this,t)}forEach(t){Ne(this,t)}[Symbol.iterator](){return ea(this)}_write(t){t.writeTypeRef(Ua)}},sa=e=>new W,kn=class extends qt{constructor(t,n,r){super(t,n),this.keysChanged=r}},Q=class e extends L{constructor(t){super(),this._prelimContent=null,t===void 0?this._prelimContent=new Map:this._prelimContent=new Map(t)}_integrate(t,n){super._integrate(t,n),this._prelimContent.forEach((r,s)=>{this.set(s,r)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((n,r)=>{t.set(r,n instanceof L?n.clone():n)}),t}_callObserver(t,n){Ln(this,t,new kn(this,t,n))}toJSON(){let t={};return this._map.forEach((n,r)=>{if(!n.deleted){let s=n.content.getContent()[n.length-1];t[r]=s instanceof L?s.toJSON():s}}),t}get size(){return[...un(this._map)].length}keys(){return ln(un(this._map),t=>t[0])}values(){return ln(un(this._map),t=>t[1].content.getContent()[t[1].length-1])}entries(){return ln(un(this._map),t=>[t[0],t[1].content.getContent()[t[1].length-1]])}forEach(t){let n={};return this._map.forEach((r,s)=>{r.deleted||t(r.content.getContent()[r.length-1],s,this)}),n}[Symbol.iterator](){return this.entries()}delete(t){this.doc!==null?D(this.doc,n=>{Sn(n,this,t)}):this._prelimContent.delete(t)}set(t,n){return this.doc!==null?D(this.doc,r=>{jr(r,this,t,n)}):this._prelimContent.set(t,n),n}get(t){return Lr(this,t)}has(t){return Ao(this,t)}clear(){this.doc!==null?D(this.doc,t=>{this.forEach(function(n,r,s){Sn(t,s,r)})}):this._prelimContent.clear()}_write(t){t.writeTypeRef(ka)}},oa=e=>new Q,Ut=(e,t)=>e===t||typeof e=="object"&&typeof t=="object"&&e&&t&&_s(e,t),Ve=class{constructor(t,n,r,s){this.left=t,this.right=n,this.index=r,this.currentAttributes=s}forward(){switch(this.right===null&&G(),this.right.content.constructor){case B:this.right.deleted||ue(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length);break}this.left=this.right,this.right=this.right.right}},Ks=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case B:t.right.deleted||ue(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&F(e,U(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length);break}t.left=t.right,t.right=t.right.right}return t},hn=(e,t,n)=>{let r=new Map,s=jn(t,n);if(s){let o=new Ve(s.p.left,s.p,s.index,r);return Ks(e,o,n-s.index)}else{let o=new Ve(null,t._start,0,r);return Ks(e,o,n)}},Do=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===B&&Ut(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let s=e.doc,o=s.clientID;r.forEach((i,c)=>{let a=n.left,l=n.right,d=new T(U(o,I(s.store,o)),a,a&&a.lastId,l,l&&l.id,t,null,new B(c,i));d.integrate(e,0),n.right=d,n.forward()})},ue=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},To=(e,t)=>{for(;e.right!==null;){if(!(e.right.deleted||e.right.content.constructor===B&&Ut(t[e.right.content.key]||null,e.right.content.value)))break;e.forward()}},Io=(e,t,n,r)=>{let s=e.doc,o=s.clientID,i=new Map;for(let c in r){let a=r[c],l=n.currentAttributes.get(c)||null;if(!Ut(l,a)){i.set(c,l);let{left:d,right:u}=n;n.right=new T(U(o,I(s.store,o)),d,d&&d.lastId,u,u&&u.id,t,null,new B(c,a)),n.right.integrate(e,0),n.forward()}}return i},ur=(e,t,n,r,s)=>{n.currentAttributes.forEach((h,f)=>{s[f]===void 0&&(s[f]=null)});let o=e.doc,i=o.clientID;To(n,s);let c=Io(e,t,n,s),a=r.constructor===String?new ut(r):r instanceof L?new st(r):new _t(r),{left:l,right:d,index:u}=n;t._searchMarker&&Me(t._searchMarker,n.index,a.getLength()),d=new T(U(i,I(o.store,i)),l,l&&l.lastId,d,d&&d.id,t,null,a),d.integrate(e,0),n.right=d,n.index=u,n.forward(),Do(e,t,n,c)},Zs=(e,t,n,r,s)=>{let o=e.doc,i=o.clientID;To(n,s);let c=Io(e,t,n,s);t:for(;n.right!==null&&(r>0||c.size>0&&(n.right.deleted||n.right.content.constructor===B));){if(!n.right.deleted)switch(n.right.content.constructor){case B:{let{key:a,value:l}=n.right.content,d=s[a];if(d!==void 0){if(Ut(d,l))c.delete(a);else{if(r===0)break t;c.set(a,l)}n.right.delete(e)}else n.currentAttributes.set(a,l);break}default:r<n.right.length&&F(e,U(n.right.id.client,n.right.id.clock+r)),r-=n.right.length;break}n.forward()}if(r>0){let a="";for(;r>0;r--)a+=`
|
|
`;n.right=new T(U(i,I(o.store,i)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new ut(a)),n.right.integrate(e,0),n.forward()}Do(e,t,n,c)},jo=(e,t,n,r,s)=>{let o=n,i=we(s);for(;o&&(!o.countable||o.deleted);)!o.deleted&&o.content.constructor===B&&ue(i,o.content),o=o.right;let c=0,a=!1;for(;t!==o;){if(n===t&&(a=!0),!t.deleted){let l=t.content;switch(l.constructor){case B:{let{key:d,value:u}=l;((i.get(d)||null)!==u||(r.get(d)||null)===u)&&(t.delete(e),c++,!a&&(s.get(d)||null)===u&&(r.get(d)||null)!==u&&s.delete(d));break}}}t=t.right}return c},ia=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===B){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},Lo=e=>{let t=0;return D(e.doc,n=>{let r=e._start,s=e._start,o=q(),i=we(o);for(;s;){if(s.deleted===!1)switch(s.content.constructor){case B:ue(i,s.content);break;default:t+=jo(n,r,s,o,i),o=we(i),r=s;break}s=s.right}}),t},Ys=(e,t,n)=>{let r=n,s=we(t.currentAttributes),o=t.right;for(;n>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case st:case _t:case ut:n<t.right.length&&F(e,U(t.right.id.client,t.right.id.clock+n)),n-=t.right.length,t.right.delete(e);break}t.forward()}o&&jo(e,o,t.right,s,t.currentAttributes);let i=(t.left||t.right).parent;return i._searchMarker&&Me(i._searchMarker,t.index,-r+n),t},vn=class extends qt{constructor(t,n,r){super(t,n),this.childListChanged=!1,this.keysChanged=new Set,r.forEach(s=>{s===null?this.childListChanged=!0:this.keysChanged.add(s)})}get changes(){if(this._changes===null){let t={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=t}return this._changes}get delta(){if(this._delta===null){let t=this.target.doc,n=[];D(t,r=>{let s=new Map,o=new Map,i=this.target._start,c=null,a={},l="",d=0,u=0,h=()=>{if(c!==null){let f;switch(c){case"delete":f={delete:u},u=0;break;case"insert":f={insert:l},s.size>0&&(f.attributes={},s.forEach((y,x)=>{y!==null&&(f.attributes[x]=y)})),l="";break;case"retain":if(f={retain:d},Object.keys(a).length>0){f.attributes={};for(let y in a)f.attributes[y]=a[y]}d=0;break}n.push(f),c=null}};for(;i!==null;){switch(i.content.constructor){case st:case _t:this.adds(i)?this.deletes(i)||(h(),c="insert",l=i.content.getContent()[0],h()):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),u+=1):i.deleted||(c!=="retain"&&(h(),c="retain"),d+=1);break;case ut:this.adds(i)?this.deletes(i)||(c!=="insert"&&(h(),c="insert"),l+=i.content.str):this.deletes(i)?(c!=="delete"&&(h(),c="delete"),u+=i.length):i.deleted||(c!=="retain"&&(h(),c="retain"),d+=i.length);break;case B:{let{key:f,value:y}=i.content;if(this.adds(i)){if(!this.deletes(i)){let x=s.get(f)||null;Ut(x,y)?y!==null&&i.delete(r):(c==="retain"&&h(),Ut(y,o.get(f)||null)?delete a[f]:a[f]=y)}}else if(this.deletes(i)){o.set(f,y);let x=s.get(f)||null;Ut(x,y)||(c==="retain"&&h(),a[f]=x)}else if(!i.deleted){o.set(f,y);let x=a[f];x!==void 0&&(Ut(x,y)?x!==null&&i.delete(r):(c==="retain"&&h(),y===null?delete a[f]:a[f]=y))}i.deleted||(c==="insert"&&h(),ue(s,i.content));break}}i=i.right}for(h();n.length>0;){let f=n[n.length-1];if(f.retain!==void 0&&f.attributes===void 0)n.pop();else break}}),this._delta=n}return this._delta}},ce=class e extends L{constructor(t){super(),this._pending=t!==void 0?[()=>this.insert(0,t)]:[],this._searchMarker=[]}get length(){return this._length}_integrate(t,n){super._integrate(t,n);try{this._pending.forEach(r=>r())}catch(r){console.error(r)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(t,n){super._callObserver(t,n);let r=new vn(this,t,n),s=t.doc;if(Ln(this,t,r),!t.local){let o=!1;for(let[i,c]of t.afterState.entries()){let a=t.beforeState.get(i)||0;if(c!==a&&(oo(t,s.store.clients.get(i),a,c,l=>{!l.deleted&&l.content.constructor===B&&(o=!0)}),o))break}o||vt(t,t.deleteSet,i=>{i instanceof $||o||i.parent===this&&i.content.constructor===B&&(o=!0)}),D(s,i=>{o?Lo(this):vt(i,i.deleteSet,c=>{c instanceof $||c.parent===this&&ia(i,c)})})}}toString(){let t="",n=this._start;for(;n!==null;)!n.deleted&&n.countable&&n.content.constructor===ut&&(t+=n.content.str),n=n.right;return t}toJSON(){return this.toString()}applyDelta(t,{sanitize:n=!0}={}){this.doc!==null?D(this.doc,r=>{let s=new Ve(null,this._start,0,new Map);for(let o=0;o<t.length;o++){let i=t[o];if(i.insert!==void 0){let c=!n&&typeof i.insert=="string"&&o===t.length-1&&s.right===null&&i.insert.slice(-1)===`
|
|
`?i.insert.slice(0,-1):i.insert;(typeof c!="string"||c.length>0)&&ur(r,this,s,c,i.attributes||{})}else i.retain!==void 0?Zs(r,this,s,i.retain,i.attributes||{}):i.delete!==void 0&&Ys(r,s,i.delete)}}):this._pending.push(()=>this.applyDelta(t))}toDelta(t,n,r){let s=[],o=new Map,i=this.doc,c="",a=this._start;function l(){if(c.length>0){let d={},u=!1;o.forEach((f,y)=>{u=!0,d[y]=f});let h={insert:c};u&&(h.attributes=d),s.push(h),c=""}}return D(i,d=>{for(t&&fn(d,t),n&&fn(d,n);a!==null;){if(Rt(a,t)||n!==void 0&&Rt(a,n))switch(a.content.constructor){case ut:{let u=o.get("ychange");t!==void 0&&!Rt(a,t)?(u===void 0||u.user!==a.id.client||u.state!=="removed")&&(l(),o.set("ychange",r?r("removed",a.id):{type:"removed"})):n!==void 0&&!Rt(a,n)?(u===void 0||u.user!==a.id.client||u.state!=="added")&&(l(),o.set("ychange",r?r("added",a.id):{type:"added"})):u!==void 0&&(l(),o.delete("ychange")),c+=a.content.str;break}case st:case _t:{l();let u={insert:a.content.getContent()[0]};if(o.size>0){let h={};u.attributes=h,o.forEach((f,y)=>{h[y]=f})}s.push(u);break}case B:Rt(a,t)&&(l(),ue(o,a.content));break}a=a.right}l()},fn),s}insert(t,n,r){if(n.length<=0)return;let s=this.doc;s!==null?D(s,o=>{let i=hn(o,this,t);r||(r={},i.currentAttributes.forEach((c,a)=>{r[a]=c})),ur(o,this,i,n,r)}):this._pending.push(()=>this.insert(t,n,r))}insertEmbed(t,n,r={}){let s=this.doc;s!==null?D(s,o=>{let i=hn(o,this,t);ur(o,this,i,n,r)}):this._pending.push(()=>this.insertEmbed(t,n,r))}delete(t,n){if(n===0)return;let r=this.doc;r!==null?D(r,s=>{Ys(s,hn(s,this,t),n)}):this._pending.push(()=>this.delete(t,n))}format(t,n,r){if(n===0)return;let s=this.doc;s!==null?D(s,o=>{let i=hn(o,this,t);i.right!==null&&Zs(o,this,i,n,r)}):this._pending.push(()=>this.format(t,n,r))}removeAttribute(t){this.doc!==null?D(this.doc,n=>{Sn(n,this,t)}):this._pending.push(()=>this.removeAttribute(t))}setAttribute(t,n){this.doc!==null?D(this.doc,r=>{jr(r,this,t,n)}):this._pending.push(()=>this.setAttribute(t,n))}getAttribute(t){return Lr(this,t)}getAttributes(t){return _o(this)}_write(t){t.writeTypeRef(va)}},ca=e=>new ce,Ae=class{constructor(t,n=()=>!0){this._filter=n,this._root=t,this._currentNode=t._start,this._firstCall=!0}[Symbol.iterator](){return this}next(){let t=this._currentNode,n=t&&t.content&&t.content.type;if(t!==null&&(!this._firstCall||t.deleted||!this._filter(n)))do if(n=t.content.type,!t.deleted&&(n.constructor===Re||n.constructor===zt)&&n._start!==null)t=n._start;else for(;t!==null;)if(t.right!==null){t=t.right;break}else t.parent===this._root?t=null:t=t.parent._item;while(t!==null&&(t.deleted||!this._filter(t.content.type)));return this._firstCall=!1,t===null?{value:void 0,done:!0}:(this._currentNode=t,{value:t.content.type,done:!1})}},zt=class e extends L{constructor(){super(),this._prelimContent=[]}get firstChild(){let t=this._first;return t?t.content.getContent()[0]:null}_integrate(t,n){super._integrate(t,n),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(n=>n instanceof L?n.clone():n)),t}get length(){return this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(t){return new Ae(this,t)}querySelector(t){t=t.toUpperCase();let r=new Ae(this,s=>s.nodeName&&s.nodeName.toUpperCase()===t).next();return r.done?null:r.value}querySelectorAll(t){return t=t.toUpperCase(),Array.from(new Ae(this,n=>n.nodeName&&n.nodeName.toUpperCase()===t))}_callObserver(t,n){Ln(this,t,new Cn(this,n,t))}toString(){return Uo(this,t=>t.toString()).join("")}toJSON(){return this.toString()}toDOM(t=document,n={},r){let s=t.createDocumentFragment();return r!==void 0&&r._createAssociation(s,this),Ne(this,o=>{s.insertBefore(o.toDOM(t,n,r),null)}),s}insert(t,n){this.doc!==null?D(this.doc,r=>{Co(r,this,t,n)}):this._prelimContent.splice(t,0,...n)}insertAfter(t,n){if(this.doc!==null)D(this.doc,r=>{let s=t&&t instanceof L?t._item:t;xn(r,this,s,n)});else{let r=this._prelimContent,s=t===null?0:r.findIndex(o=>o===t)+1;if(s===0&&t!==null)throw Ce("Reference item not found");r.splice(s,0,...n)}}delete(t,n=1){this.doc!==null?D(this.doc,r=>{Eo(r,this,t,n)}):this._prelimContent.splice(t,n)}toArray(){return So(this)}push(t){this.insert(this.length,t)}unshift(t){this.insert(0,t)}get(t){return ko(this,t)}slice(t=0,n=this.length){return xo(this,t,n)}forEach(t){Ne(this,t)}_write(t){t.writeTypeRef(Ea)}},aa=e=>new zt,Re=class e extends zt{constructor(t="UNDEFINED"){super(),this.nodeName=t,this._prelimAttrs=new Map}get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_integrate(t,n){super._integrate(t,n),this._prelimAttrs.forEach((r,s)=>{this.setAttribute(s,r)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();for(let r in n)t.setAttribute(r,n[r]);return t.insert(0,this.toArray().map(r=>r instanceof L?r.clone():r)),t}toString(){let t=this.getAttributes(),n=[],r=[];for(let c in t)r.push(c);r.sort();let s=r.length;for(let c=0;c<s;c++){let a=r[c];n.push(a+'="'+t[a]+'"')}let o=this.nodeName.toLocaleLowerCase(),i=n.length>0?" "+n.join(" "):"";return`<${o}${i}>${super.toString()}</${o}>`}removeAttribute(t){this.doc!==null?D(this.doc,n=>{Sn(n,this,t)}):this._prelimAttrs.delete(t)}setAttribute(t,n){this.doc!==null?D(this.doc,r=>{jr(r,this,t,n)}):this._prelimAttrs.set(t,n)}getAttribute(t){return Lr(this,t)}hasAttribute(t){return Ao(this,t)}getAttributes(t){return _o(this)}toDOM(t=document,n={},r){let s=t.createElement(this.nodeName),o=this.getAttributes();for(let i in o)s.setAttribute(i,o[i]);return Ne(this,i=>{s.appendChild(i.toDOM(t,n,r))}),r!==void 0&&r._createAssociation(s,this),s}_write(t){t.writeTypeRef(Ca),t.writeKey(this.nodeName)}},la=e=>new Re(e.readKey()),Cn=class extends qt{constructor(t,n,r){super(t,r),this.childListChanged=!1,this.attributesChanged=new Set,n.forEach(s=>{s===null?this.childListChanged=!0:this.attributesChanged.add(s)})}},En=class e extends Q{constructor(t){super(),this.hookName=t}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((n,r)=>{t.set(r,n)}),t}toDOM(t=document,n={},r){let s=n[this.hookName],o;return s!==void 0?o=s.createDom(this):o=document.createElement(this.hookName),o.setAttribute("data-yjs-hook",this.hookName),r!==void 0&&r._createAssociation(o,this),o}_write(t){t.writeTypeRef(_a),t.writeKey(this.hookName)}},da=e=>new En(e.readKey()),_n=class e extends ce{get nextSibling(){let t=this._item?this._item.next:null;return t?t.content.type:null}get prevSibling(){let t=this._item?this._item.prev:null;return t?t.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(t=document,n,r){let s=t.createTextNode(this.toString());return r!==void 0&&r._createAssociation(s,this),s}toString(){return this.toDelta().map(t=>{let n=[];for(let s in t.attributes){let o=[];for(let i in t.attributes[s])o.push({key:i,value:t.attributes[s][i]});o.sort((i,c)=>i.key<c.key?-1:1),n.push({nodeName:s,attrs:o})}n.sort((s,o)=>s.nodeName<o.nodeName?-1:1);let r="";for(let s=0;s<n.length;s++){let o=n[s];r+=`<${o.nodeName}`;for(let i=0;i<o.attrs.length;i++){let c=o.attrs[i];r+=` ${c.key}="${c.value}"`}r+=">"}r+=t.insert;for(let s=n.length-1;s>=0;s--)r+=`</${n[s].nodeName}>`;return r}).join("")}toJSON(){return this.toString()}_write(t){t.writeTypeRef(Aa)}},ua=e=>new _n,ae=class{constructor(t,n){this.id=t,this.length=n}get deleted(){throw et()}mergeWith(t){return!1}write(t,n,r){throw et()}integrate(t,n){throw et()}},ha=0,$=class extends ae{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){n>0&&(this.id.clock+=n,this.length-=n),so(t.doc.store,this)}write(t,n){t.writeInfo(ha),t.writeLen(this.length-n)}getMissing(t,n){return null}},le=class e{constructor(t){this.content=t}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(t){throw et()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeBuf(this.content)}getRef(){return 3}},fa=e=>new le(e.readBuf()),Fe=class e{constructor(t){this.len=t}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(t){return this.len+=t.len,!0}integrate(t,n){Ie(t.deleteSet,n.id.client,n.id.clock,this.len),n.markDeleted()}delete(t){}gc(t){}write(t,n){t.writeLen(this.len-n)}getRef(){return 1}},pa=e=>new Fe(e.readLen()),Bo=(e,t)=>new $t({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1}),$e=class e{constructor(t){t._item&&console.error("This document was already integrated as a sub-document. You should create a second instance instead with the same guid."),this.doc=t;let n={};this.opts=n,t.gc||(n.gc=!1),t.autoLoad&&(n.autoLoad=!0),t.meta!==null&&(n.meta=t.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(Bo(this.doc.guid,this.opts))}splice(t){throw et()}mergeWith(t){return!1}integrate(t,n){this.doc._item=n,t.subdocsAdded.add(this.doc),this.doc.shouldLoad&&t.subdocsLoaded.add(this.doc)}delete(t){t.subdocsAdded.has(this.doc)?t.subdocsAdded.delete(this.doc):t.subdocsRemoved.add(this.doc)}gc(t){}write(t,n){t.writeString(this.doc.guid),t.writeAny(this.opts)}getRef(){return 9}},ga=e=>new $e(Bo(e.readString(),e.readAny())),_t=class e{constructor(t){this.embed=t}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(t){throw et()}mergeWith(t){return!1}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeJSON(this.embed)}getRef(){return 5}},ma=e=>new _t(e.readJSON()),B=class e{constructor(t,n){this.key=t,this.value=n}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(t){throw et()}mergeWith(t){return!1}integrate(t,n){n.parent._searchMarker=null}delete(t){}gc(t){}write(t,n){t.writeKey(this.key),t.writeJSON(this.value)}getRef(){return 6}},ya=e=>new B(e.readKey(),e.readJSON()),An=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeString(o===void 0?"undefined":JSON.stringify(o))}}getRef(){return 2}},wa=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let s=e.readString();s==="undefined"?n.push(void 0):n.push(JSON.parse(s))}return new An(n)},Ht=class e{constructor(t){this.arr=t}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(t){return this.arr=this.arr.concat(t.arr),!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){let r=this.arr.length;t.writeLen(r-n);for(let s=n;s<r;s++){let o=this.arr[s];t.writeAny(o)}}getRef(){return 8}},ba=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new Ht(n)},ut=class e{constructor(t){this.str=t}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+"\uFFFD",n.str="\uFFFD"+n.str.slice(1)),n}mergeWith(t){return this.str+=t.str,!0}integrate(t,n){}delete(t){}gc(t){}write(t,n){t.writeString(n===0?this.str:this.str.slice(n))}getRef(){return 4}},xa=e=>new ut(e.readString()),Sa=[sa,oa,ca,la,aa,da,ua],Ua=0,ka=1,va=2,Ca=3,Ea=4,_a=5,Aa=6,st=class e{constructor(t){this.type=t}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(t){throw et()}mergeWith(t){return!1}integrate(t,n){this.type._integrate(t.doc,n)}delete(t){let n=this.type._start;for(;n!==null;)n.deleted?t._mergeStructs.push(n):n.delete(t),n=n.right;this.type._map.forEach(r=>{r.deleted?t._mergeStructs.push(r):r.delete(t)}),t.changed.delete(this.type)}gc(t){let n=this.type._start;for(;n!==null;)n.gc(t,!0),n=n.right;this.type._start=null,this.type._map.forEach(r=>{for(;r!==null;)r.gc(t,!0),r=r.left}),this.type._map=new Map}write(t,n){this.type._write(t)}getRef(){return 7}},Da=e=>new st(Sa[e.readTypeRef()](e)),br=(e,t)=>{let n=t,r=0,s;do r>0&&(n=U(n.client,n.clock+r)),s=_e(e,n),r=n.clock-s.id.clock,n=s.redone;while(n!==null&&s instanceof T);return{item:s,diff:r}},Br=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Dn=(e,t,n)=>{let{client:r,clock:s}=t.id,o=new T(U(r,s+n),t,U(r,s+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&o.markDeleted(),t.keep&&(o.keep=!0),t.redone!==null&&(o.redone=U(t.redone.client,t.redone.clock+n)),t.right=o,o.right!==null&&(o.right.left=o),e._mergeStructs.push(o),o.parentSub!==null&&o.right===null&&o.parent._map.set(o.parentSub,o),t.length=n,o},Oo=(e,t,n,r,s)=>{let o=e.doc,i=o.store,c=o.clientID,a=t.redone;if(a!==null)return F(e,a);let l=t.parent._item,d=null,u;if(l!==null&&l.deleted===!0){if(l.redone===null&&(!n.has(l)||Oo(e,l,n,r,s)===null))return null;for(;l.redone!==null;)l=F(e,l.redone)}let h=l===null?t.parent:l.content.type;if(t.parentSub===null){for(d=t.left,u=t;d!==null;){let k=d;for(;k!==null&&k.parent._item!==l;)k=k.redone===null?null:F(e,k.redone);if(k!==null&&k.parent._item===l){d=k;break}d=d.left}for(;u!==null;){let k=u;for(;k!==null&&k.parent._item!==l;)k=k.redone===null?null:F(e,k.redone);if(k!==null&&k.parent._item===l){u=k;break}u=u.right}}else if(u=null,t.right&&!s){for(d=t;d!==null&&d.right!==null&&de(r,d.right.id);)d=d.right;for(;d!==null&&d.redone!==null;)d=F(e,d.redone);if(d===null||d.parent._item!==l||d&&d.right!==null)return null}else d=h._map.get(t.parentSub)||null;let f=I(i,c),y=U(c,f),x=new T(y,d,d&&d.lastId,u,u&&u.id,h,t.parentSub,t.content.copy());return t.redone=y,Br(x,!0),x.integrate(e,0),x},T=class e extends ae{constructor(t,n,r,s,o,i,c,a){super(t,a.getLength()),this.origin=r,this.left=n,this.right=s,this.rightOrigin=o,this.parent=i,this.parentSub=c,this.redone=null,this.content=a,this.info=this.content.isCountable()?2:0}set marker(t){(this.info&8)>0!==t&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(t){this.keep!==t&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(t){this.deleted!==t&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=I(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=I(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===pt&&this.id.client!==this.parent.client&&this.parent.clock>=I(n,this.parent.client))return this.parent.client;if(this.origin&&(this.left=zs(t,n,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=F(t,this.rightOrigin),this.rightOrigin=this.right.id),(this.left&&this.left.constructor===$||this.right&&this.right.constructor===$)&&(this.parent=null),!this.parent)this.left&&this.left.constructor===e&&(this.parent=this.left.parent,this.parentSub=this.left.parentSub),this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===pt){let r=_e(n,this.parent);r.constructor===$?this.parent=null:this.parent=r.content.type}return null}integrate(t,n){if(n>0&&(this.id.clock+=n,this.left=zs(t,t.doc.store,U(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(n),this.length-=n),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let r=this.left,s;if(r!==null)s=r.right;else if(this.parentSub!==null)for(s=this.parent._map.get(this.parentSub)||null;s!==null&&s.left!==null;)s=s.left;else s=this.parent._start;let o=new Set,i=new Set;for(;s!==null&&s!==this.right;){if(i.add(s),o.add(s),Ft(this.origin,s.origin)){if(s.id.client<this.id.client)r=s,o.clear();else if(Ft(this.rightOrigin,s.rightOrigin))break}else if(s.origin!==null&&i.has(_e(t.doc.store,s.origin)))o.has(_e(t.doc.store,s.origin))||(r=s,o.clear());else break;s=s.right}this.left=r}if(this.left!==null){let r=this.left.right;this.right=r,this.left.right=this}else{let r;if(this.parentSub!==null)for(r=this.parent._map.get(this.parentSub)||null;r!==null&&r.left!==null;)r=r.left;else r=this.parent._start,this.parent._start=this;this.right=r}this.right!==null?this.right.left=this:this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(t)),this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),so(t.doc.store,this),this.content.integrate(t,this),Js(t,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(t)}else new $(this.id,this.length).integrate(t,0)}get next(){let t=this.right;for(;t!==null&&t.deleted;)t=t.right;return t}get prev(){let t=this.left;for(;t!==null&&t.deleted;)t=t.left;return t}get lastId(){return this.length===1?this.id:U(this.id.client,this.id.clock+this.length-1)}mergeWith(t){if(this.constructor===t.constructor&&Ft(t.origin,this.lastId)&&this.right===t&&Ft(this.rightOrigin,t.rightOrigin)&&this.id.client===t.id.client&&this.id.clock+this.length===t.id.clock&&this.deleted===t.deleted&&this.redone===null&&t.redone===null&&this.content.constructor===t.content.constructor&&this.content.mergeWith(t.content)){let n=this.parent._searchMarker;return n&&n.forEach(r=>{r.p===t&&(r.p=this,!this.deleted&&this.countable&&(r.index-=this.length))}),t.keep&&(this.keep=!0),this.right=t.right,this.right!==null&&(this.right.left=this),this.length+=t.length,!0}return!1}delete(t){if(!this.deleted){let n=this.parent;this.countable&&this.parentSub===null&&(n._length-=this.length),this.markDeleted(),Ie(t.deleteSet,this.id.client,this.id.clock,this.length),Js(t,n,this.parentSub),this.content.delete(t)}}gc(t,n){if(!this.deleted)throw G();this.content.gc(t),n?Fc(t,this,new $(this.id,this.length)):this.content=new Fe(this.length)}write(t,n){let r=n>0?U(this.id.client,this.id.clock+n-1):this.origin,s=this.rightOrigin,o=this.parentSub,i=this.content.getRef()&31|(r===null?0:128)|(s===null?0:64)|(o===null?0:32);if(t.writeInfo(i),r!==null&&t.writeLeftID(r),s!==null&&t.writeRightID(s),r===null&&s===null){let c=this.parent;if(c._item!==void 0){let a=c._item;if(a===null){let l=_r(c);t.writeParentInfo(!0),t.writeString(l)}else t.writeParentInfo(!1),t.writeLeftID(a.id)}else c.constructor===String?(t.writeParentInfo(!0),t.writeString(c)):c.constructor===pt?(t.writeParentInfo(!1),t.writeLeftID(c)):G();o!==null&&t.writeString(o)}this.content.write(t,n)}},Mo=(e,t)=>Ta[t&31](e),Ta=[()=>{G()},pa,wa,fa,xa,ma,ya,Da,ba,ga,()=>{G()}],Ia=10,P=class extends ae{get deleted(){return!0}delete(){}mergeWith(t){return this.constructor!==t.constructor?!1:(this.length+=t.length,!0)}integrate(t,n){G()}write(t,n){t.writeInfo(Ia),S(t.restEncoder,this.length-n)}getMissing(t,n){return null}},No=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:{},Vo="__ $YJS$ __";No[Vo]===!0&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438");No[Vo]=!0;function yt(e){if(e instanceof L){e=e.toJSON();for(let[t,n]of Or(e))At(e,t,n,yt)}if(Array.isArray(e))return e.map(yt);if(typeof e=="object"&&e!==null){let t={};for(let[n,r]of Object.entries(e))t[n]=yt(r);return t}return e}function ja(e){return Array.isArray(e)?new W:typeof e=="object"&&e!==null?new Q:e}function Or(e){return Array.isArray(e)?[...e.entries()]:typeof e=="object"&&e!==null?Object.entries(e):e instanceof W?e.map((t,n)=>[n,t]):e instanceof Q?[...e.entries()]:[]}function At(e,t,n,r=ja){let s=r(n);if(e instanceof Q){e.set(String(t),s),Or(n).forEach(([o,i])=>{At(e.get(String(t)),o,i)});return}if(e instanceof W&&typeof t=="number"){e.length>t&&e.delete(t,1);let o=t-e.length;o>0&&e.push(Array(o).fill(null)),e.insert(t,[s]),Or(n).forEach(([i,c])=>{At(e.get(t),i,c)});return}e[t]=s}function Mr(e,t,n){if(n.path&&n.path.length){let r=e.get(t),s,o=n.path.length-1;for(s=0;s<o;s++)switch(r=r.get(n.path[s]),n.kind){case"A":Mr(r.get(n.path[s]),n.index,n.item);break;case"D":r.delete(n.path[s],1);break;case"E":case"N":At(r,n.path[s],n.rhs);break}}else switch(n.kind){case"A":Mr(e.get(t),n.index,n.item);break;case"D":e.delete(t,1);break;case"E":case"N":At(e,t,n.rhs);break}return e}function Ro(e,t){if(e&&t&&t.kind){let n=e,r=-1,s=t.path?t.path.length-1:0;for(;++r<s;)typeof n.get(t.path?.[r])>"u"&&At(n,t.path?.[r],typeof t.path?.[r+1]=="number"?new W:new Q),n=n.get(t.path?.[r]);switch(t.kind){case"A":t.path&&typeof n.get(t.path[r])>"u"&&At(n,t.path[r],new W),Mr(t.path?n.get(t.path[r]):n,t.index,t.item);break;case"D":n.delete(t.path?.[r],1);break;case"E":case"N":At(n,t.path?.[r],t.rhs);break}}}var La=["projects","templates","assets","snippets"],qe="livecodes-data",ht="data",On=self,K=rs(),Mn=async e=>{if(!e)return[];if("getValue"in e){let t=Yn(e,K),n=await Hn(On,{method:"getValue",args:{storeKey:t}});return n!=null?[n]:[]}return e.getAllData()},Fo=async(e,t)=>{if(e){if("setValue"in e){let n=Yn(e,K);await Hn(On,{method:"setValue",args:{storeKey:n,value:t[0]}});return}await e.clear(),await e.restore(t)}},he=(e,t=[])=>{let n=Bn.diff(yt(e),t)||[];e.doc?.transact(()=>{for(let r of n)Ro(e,r)})},Ba=async({user:e,repo:t,branch:n,stores:r,storeKey:s,remoteContent:o})=>{let i=`${e.username}_${s}`,c=(await r.sync?.getItem(i))?.lastSyncSha,a=`${s}.b64.zip`,l=`${qe}/${a}`,d=r[s];if(!d||"getValue"in d)return!0;let h=new R.Doc;try{let f,y=o.find(w=>w.name===a)!=null,x=o.find(w=>w.sha===c)!=null,k=!y||x?void 0:await ye({user:e,repo:t,branch:n,path:l});if(k?.content){let w=k.encoding==="arrayBuffer"?"binary":"base64";f=await Fa(k.content,w)}let C=(await r.sync?.getItem(i))?.data,A=await Mn(d);if(C&&(R.applyUpdate(h,C),he(h.getArray(ht),A),f&&R.applyUpdate(h,f)),!C&&!f&&he(h.getArray(ht),A),!C&&f){let w=new R.Doc;R.applyUpdate(w,f);let _=yt(w.getArray(ht));w.destroy();let E=[..._,...A];he(h.getArray(ht),E)}let O=yt(h.getArray(ht));Bn.diff(O,A)!=null&&await Fo(d,O);let Jt=R.encodeStateAsUpdate(h),g=!y||f&&!zn(f,Jt)||x&&C&&!zn(C,Jt);if(g){let w={path:l,content:await Ra([{filename:a.replace(".zip",""),content:Jt}])};if(!await Jn({file:w,user:e,repo:t,branch:n,message:"sync "+s}))return!1}let p=(g?(await ye({user:e,repo:t,branch:n,path:qe}))?.entries:o)?.find?.(w=>w.name===a)?.sha,b={lastModified:Date.now(),data:Jt,lastSyncSha:p||""};await r.sync?.updateItem(i,b)}catch{return!1}finally{h.destroy()}return!0},Oa=async({user:e,repo:t,branch:n="main",newRepo:r})=>{let s=[];try{r?await Jn({file:{path:qe+"/.gitkeep",content:""},user:e,repo:t,branch:n,message:"create data dir",description:"LiveCodes Sync",newRepo:r,privateRepo:!0,readmeContent:"# LiveCodes Sync"}):(await ye({user:e,repo:t,branch:n,path:""}))?.entries?.find?.(a=>a.type==="dir"&&a.name===qe)&&(s=(await ye({user:e,repo:t,branch:n,path:qe}))?.entries)}catch{return!1}let o=!0,i=Object.keys(K).filter(c=>La.includes(c));for(let c of i)await Ba({user:e,repo:t,branch:n,stores:K,storeKey:c,remoteContent:s})||(o=!1);return o},Ma=async({user:e,storeKey:t})=>{let n=`${e.username}_${t}`,r=K[t];if(!r)return;let{data:s,lastSyncSha:o=""}=await K.sync?.getItem(n)||{},i=await Mn(r),c=new R.Doc;try{s&&R.applyUpdate(c,s),he(c.getArray(ht),i);let a=R.encodeStateAsUpdate(c),l={lastModified:Date.now(),data:a,lastSyncSha:o};await K.sync?.updateItem(n,l)}finally{c.destroy()}},Na=async({storeKey:e})=>{let t=K[e];if(!t)return;let n=await Mn(t),r=new R.Doc;he(r.getArray(ht),n);let s=R.encodeStateAsUpdate(r),o=Jr(s);return r.destroy(),o},$o=async({update:e,storeKey:t,mergeCurrent:n=!0})=>{let r=K[t];if(!r)return;let s="getValue"in r,o=await Mn(r),i=new R.Doc;try{if(R.applyUpdate(i,e),n){let l=yt(i.getArray(ht)),d=s?l:[...l,...o];he(i.getArray(ht),d)}let c=yt(i.getArray(ht));Bn.diff(c,o)!=null&&await Fo(r,c)}finally{i.destroy()}},Va=async({user:e,storeKey:t,mergeCurrent:n=!0})=>{let r=`${e.username}_${t}`;if(!K[t])return;let o=(await K.sync?.getItem(r))?.data;if(o)return $o({update:o,storeKey:t,mergeCurrent:n})},Ra=async e=>{let t=await me(Gn,"JSZip"),n=new t;return e.forEach(({filename:r,content:s})=>{n.file(r,s)}),n.generateAsync({type:"base64",compression:"DEFLATE",compressionOptions:{level:6}})},Fa=async(e,t)=>{let s=(await(await me(Gn,"JSZip")).loadAsync(e,{base64:t==="base64"})).file(/.*\.b64/);if(s.length>0)return s[0].async("uint8array")};On.addEventListener("message",async e=>{K.projects||await ss(K,!1);let t=e.data,n;t.method==="sync"&&(n=await Oa(...t.args)),t.method==="exportToLocalSync"&&(n=await Ma(...t.args)),t.method==="exportStoreAsBase64Update"&&(n=await Na(...t.args)),t.method==="restoreFromUpdate"&&(n=await $o(...t.args)),t.method==="restoreFromLocalSync"&&(n=await Va(...t.args)),On.postMessage({messageId:t.messageId,method:t.method,data:n})});
|
|
})();
|