UNPKG

@liascript/exporter

Version:
1 lines 131 kB
!function(){function t(t,e,n,r){Object.defineProperty(t,e,{get:n,set:r,enumerable:!0,configurable:!0})}var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},n=e.parcelRequire55a5;n.register("auvHb",(function(e,r){t(e.exports,"Sync",(function(){return s}));var i=n("9Klpk"),o=n("3bWnf"),u=n("eT7f3"),a=n("7OeKL"),c=n("edmAk");n("ie2ZQ");function l(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:16,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n="",r=0;r<t;r++)n+=e.charAt(Math.floor(62*Math.random()));return n}var s=function(){"use strict";function t(e,n,r,o){var a,s=arguments.length>4&&void 0!==arguments[4]&&arguments[4],f=!(arguments.length>5&&void 0!==arguments[5])||arguments[5],d=this;(0,i.default)(this,t),(0,u.default)(this,"isConnected",!1),(0,u.default)(this,"replyOnReceive",!1);try{(a=window.localStorage.getItem("lia-token"))||(a=l(),window.localStorage.setItem("lia-token",a))}catch(t){console.warn("cannot write to localStorage"),a=l()}this.token=a,this.urlCounter=0,this.cbConnection=e,this.cbRelay=n,this.onConnect=r,this.onReceive=o,this.replyOnReceive=s;var h=this;this.db=new(0,c.CRDT)(a,f?function(t,e){if(h.db)switch(e){case"cursor":d.sync("update",{cmd:"cursor",param:t});break;case"peer":d.sync("update",{cmd:"peer",param:t});break;case"code":d.sync("update",{cmd:"code",param:t});break;case"quiz":d.sync("update",{cmd:"quiz",param:t});break;case"survey":d.sync("update",{cmd:"survey",param:t});break;case"chat":d.sync("update",{cmd:"chat",param:t});break;default:console.warn("Sync unknown origin",e)}}:void 0)}return(0,o.default)(t,[{key:"connect",value:function(t){this.room=t.room,this.course=t.course,this.password=t.password,this.isConnected=!0}},{key:"destroy",value:function(){this.db.destroy(),this.cbConnection("disconnect",this.token),this.isConnected=!1}},{key:"disconnect",value:function(){this.db.removePeer(),this.destroy()}},{key:"uniqueID",value:function(t){var e=null;return"string"==typeof this.room&&(this.room.startsWith('"')&&this.room.endsWith('"')||this.room.startsWith("'")&&this.room.endsWith("'"))&&(e=this.room),this.course&&this.room&&(e=JSON.stringify({course:this.course,room:this.room,pw:a.getHashCode(this.password||"")})),t&&e&&(e=a.getHashCode(e+t).toString()),e||console.warn("Sync: no uniqueID"),e}},{key:"sendToLia",value:function(t){this.cbRelay(t)}},{key:"sync",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;this.cbConnection(t,e)}},{key:"sendDisconnectError",value:function(t){this.sync("error",t)}},{key:"sendConnect",value:function(){this.sync("connect",this.token),this.onConnect&&this.onConnect()}},{key:"pubsubSend",value:function(t,e){var n;JSON.stringify({topic:t,message:e}),new TextEncoder;this.replyOnReceive&&(null===(n=this.onReceive)||void 0===n||n.call(this,t,e))}},{key:"pubsubReceive",value:function(t){try{var e,n=(new TextDecoder).decode(t),r=JSON.parse(n);null===(e=this.onReceive)||void 0===e||e.call(this,r.topic,r.message)}catch(t){console.warn("Sync: pubsubReceive",t.message)}}},{key:"load",value:function(t,e){try{for(var n=this,r=function(r){var i=document.createElement("script");i.async=!1,i.defer=!0,i.src=t[r],n.urlCounter++;var o=n;i.onload=function(){console.log("successfully loaded =>",t),o.urlCounter--,0==o.urlCounter&&e.init(!0)},i.onerror=function(n){console.warn("could not load =>",t,n),o.urlCounter=0,e.init(!1,"could not load => ".concat(t))},document.head.appendChild(i)},i=0;i<t.length;i++)r(i)}catch(t){console.error("load: ",t),e.init(!1,t.message)}}},{key:"publish",value:function(t){switch(console.warn("publish needs to be implemented",t),t.message.cmd){case"update":break;case"join":this.db.init(t.message.param);break;case"chat":this.db.addChatMessage(t.message.param);break;case"quiz":var e,n;"quiz"===(null===(e=t.track)||void 0===e?void 0:e[0][0])&&"id"===(null===(n=t.track)||void 0===n?void 0:n[1][0])?this.db.addQuiz(t.track[0][1],t.track[1][1],t.message.param):console.warn("SyncTX wrong event ->",t);break;case"survey":var r,i;"survey"===(null===(r=t.track)||void 0===r?void 0:r[0][0])&&"id"===(null===(i=t.track)||void 0===i?void 0:i[1][0])?this.db.addSurvey(t.track[0][1],t.track[1][1],t.message.param):console.warn("SyncTX wrong event ->",t);break;case"code":var o,u;"code"===(null===(o=t.track)||void 0===o?void 0:o[0][0])&&"id"===(null===(u=t.track)||void 0===u?void 0:u[1][0])?this.db.updateCode(t.track[0][1],t.track[1][1],t.message.param.j,t.message.param.msg):console.warn("SyncTX wrong event ->",t);break;case"codes":var a;if("code"===(null===(a=t.track)||void 0===a?void 0:a[0][0])&&1===t.track.length)for(var c=0;c<t.message.param.length;c++)for(var l=0;l<t.message.param[c].length;l++)this.db.initCode(t.track[0][1],c,l,t.message.param[c][l]);else console.warn("SyncTX wrong event ->",t);break;case"cursor":var s;"code"==(null===(s=t.track)||void 0===s?void 0:s[0][0])&&this.db.setCursor(t.track[0][1],t.message.param);break;default:console.warn("SyncTX unknown command:",t.message)}}}]),t}()})),n.register("edmAk",(function(e,r){t(e.exports,"CRDT",(function(){return v}));var i=n("9Klpk"),o=n("3bWnf"),u=n("eT7f3"),a=n("bgoEC"),c=n("7j4mF"),l=n("5ENmm"),s=n("6Wo7Q"),f=n("bymyA"),d=n("7OeKL"),h=n("17n8H"),v=function(){"use strict";function t(e,n){(0,i.default)(this,t),(0,u.default)(this,"timestamp",Date.now()),this.doc=new f.Doc,this.callback=n||function(t,e){console.warn("SyncDB: no callback provided")},this.length=0,this.peerID=e,this.codes=this.doc.getMap("c"),this.quizzes=this.doc.getMap("q"),this.surveys=this.doc.getMap("s"),this.chat=new(0,h.YKeyValue)(this.doc.getArray("chat"))}return(0,o.default)(t,[{key:"init",value:function(t){var e=this;this.length=Math.max(this.length,t.length),this.doc.transact((function(){for(var n=0;n<t.length;n++)e.initMap(e.quizzes,n,t[n].q),e.initMap(e.surveys,n,t[n].s),e.initText(n,t[n].c)}),this.peerID),this.registerCallbacks(),this.fireInitialState()}},{key:"fireInitialState",value:function(){var t=this,e=this.getPeers();e.length>0&&this.callback(e,"peer");var n=this.getCursors();n.length>0&&this.callback(n,"cursor");var r=new Set,i=!0,o=!1,u=void 0;try{for(var f,d=this.quizzes.keys()[Symbol.iterator]();!(i=(f=d.next()).done);i=!0){var h=f.value;try{var v=(0,l.default)(JSON.parse(h),1)[0];r.add(v)}catch(t){}}}catch(t){o=!0,u=t}finally{try{i||null==d.return||d.return()}finally{if(o)throw u}}r.size>0&&this.callback((0,s.default)(r).map((function(e){return{id:e,data:t.getMaps(e,t.quizzes)}})),"quiz");var g=new Set,y=!0,p=!1,k=void 0;try{for(var w,m=this.surveys.keys()[Symbol.iterator]();!(y=(w=m.next()).done);y=!0){var b=w.value;try{var _=(0,l.default)(JSON.parse(b),1)[0];g.add(_)}catch(t){}}}catch(t){p=!0,k=t}finally{try{y||null==m.return||m.return()}finally{if(p)throw k}}g.size>0&&this.callback((0,s.default)(g).map((function(e){return{id:e,data:t.getMaps(e,t.surveys)}})),"survey");var S=new Set,x=!0,E=!1,C=void 0;try{for(var D,U=this.codes.keys()[Symbol.iterator]();!(x=(D=U.next()).done);x=!0){var A=D.value;try{var I=(0,l.default)(JSON.parse(A),1)[0];S.add(I)}catch(t){}}}catch(t){E=!0,C=t}finally{try{x||null==U.return||U.return()}finally{if(E)throw C}}S.size>0&&this.callback(this.getCode(S),"code");var T=[],O=!0,V=!1,N=void 0;try{for(var M,R=this.chat.map[Symbol.iterator]();!(O=(M=R.next()).done);O=!0){var B=(0,l.default)(M.value,2),L=B[0],F=B[1],j=(0,c.default)((0,a.default)({},F.val),{id:parseInt(L)});T.push(j)}}catch(t){V=!0,N=t}finally{try{O||null==R.return||R.return()}finally{if(V)throw N}}T.length>0&&(T.sort((function(t,e){return t.id-e.id})),this.callback(T,"chat"))}},{key:"setAwareness",value:function(t){var e=this;this.awareness=t,t.setLocalState({peerID:this.peerID,color:this.getColor()}),t.on("change",(function(t){var n=e.getPeers();e.callback(n,"peer");var r=e.getCursors();r.length>0&&e.callback(r,"cursor")}))}},{key:"registerCallbacks",value:function(){var t=this;this.quizzes.observe((function(e){var n=new Set;e.keysChanged.forEach((function(t){try{var e=(0,l.default)(JSON.parse(t),1)[0];n.add(e)}catch(t){}})),n.size>0&&t.callback((0,s.default)(n).map((function(e){return{id:e,data:t.getMaps(e,t.quizzes)}})),"quiz")})),this.surveys.observe((function(e){var n=new Set;e.keysChanged.forEach((function(t){try{var e=(0,l.default)(JSON.parse(t),1)[0];n.add(e)}catch(t){}})),n.size>0&&t.callback((0,s.default)(n).map((function(e){return{id:e,data:t.getMaps(e,t.surveys)}})),"survey")})),this.chat.on("change",(function(e){var n,r=[],i=!0,o=!1,u=void 0;try{for(var a,c=e[Symbol.iterator]();!(i=(a=c.next()).done);i=!0){var s=(0,l.default)(a.value,2),f=s[0],d=s[1];"add"===d.action&&((n=d.newValue).id=parseInt(f),r.push(n))}}catch(t){o=!0,u=t}finally{try{i||null==c.return||c.return()}finally{if(o)throw u}}r.length>0&&t.callback(r,"chat")})),this.codes.observeDeep((function(e){var n=new Set,r=!0,i=!1,o=void 0;try{for(var u,a=e[Symbol.iterator]();!(r=(u=a.next()).done);r=!0){var c=u.value;if(c.target===t.codes)c.keysChanged.forEach((function(t){try{var e=(0,l.default)(JSON.parse(t),1)[0];n.add(e)}catch(t){}}));else try{var s=(0,l.default)(JSON.parse(c.path[0]),1)[0];n.add(s)}catch(t){}}}catch(t){i=!0,o=t}finally{try{r||null==a.return||a.return()}finally{if(i)throw o}}n.size>0&&t.callback(t.getCode(n),"code")}))}},{key:"encode",value:function(){return f.encodeStateAsUpdate(this.doc)}},{key:"destroy",value:function(){this.doc.destroy()}},{key:"log",value:function(){console.warn("*********** PEERS ***********"),console.warn(this.getPeers()),console.warn("*********** CURSORS ***********"),console.warn(this.getCursors()),console.warn("*********** STATE ***********"),console.warn(this.doc.toJSON())}},{key:"initMap",value:function(t,e,n){if(0!==n.length)for(var r=0;r<n.length;r++){var i=n[r][this.peerID];if(void 0!==i){var o=JSON.stringify([e,r,this.peerID]);t.has(o)||t.set(o,i)}}}},{key:"initText",value:function(t,e){if(0!==e.length)for(var n=0;n<e.length;n++)for(var r=0;r<e[n].length;r++)this.initCode(t,n,r,e[n][r])}},{key:"getCode",value:function(t){var e=[],n=!0,r=!1,i=void 0;try{for(var o,u=t[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var a=o.value;e.push({id:a,data:this.getAllTexts(a)})}}catch(t){r=!0,i=t}finally{try{n||null==u.return||u.return()}finally{if(r)throw i}}return e}},{key:"getCursors",value:function(){if(!this.awareness)return[];var t=[],e=!0,n=!1,r=void 0;try{for(var i,o=this.awareness.getStates()[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){var u=(0,l.default)(i.value,2)[1];(null==u?void 0:u.cursor)&&(null==u?void 0:u.peerID)&&u.peerID!==this.peerID&&t.push(u.cursor)}}catch(t){n=!0,r=t}finally{try{e||null==o.return||o.return()}finally{if(n)throw r}}return t}},{key:"getPeers",value:function(){if(!this.awareness)return[];var t=[],e=!0,n=!1,r=void 0;try{for(var i,o=this.awareness.getStates()[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){var u=(0,l.default)(i.value,2)[1];(null==u?void 0:u.peerID)&&t.push(u.peerID)}}catch(t){n=!0,r=t}finally{try{e||null==o.return||o.return()}finally{if(n)throw r}}return t}},{key:"removePeer",value:function(){var t;null===(t=this.awareness)||void 0===t||t.setLocalState(null)}},{key:"id",value:function(t,e,n){return void 0===n?JSON.stringify([t,e]):JSON.stringify([t,e,n])}},{key:"getMaps",value:function(t,e){var n="[".concat(t,","),r=[],i=!0,o=!1,u=void 0;try{for(var a,c=e[Symbol.iterator]();!(i=(a=c.next()).done);i=!0){var s=(0,l.default)(a.value,2),f=s[0],d=s[1];if(f.startsWith(n))try{var h=JSON.parse(f);if(3!==h.length)continue;var v=h[1],g=h[2];r[v]||(r[v]={}),r[v][g]=d}catch(t){}}}catch(t){o=!0,u=t}finally{try{i||null==c.return||c.return()}finally{if(o)throw u}}for(var y=0;y<r.length;y++)r[y]||(r[y]={});return r}},{key:"getAllTexts",value:function(t){for(var e,n=[],r=0;this.codes.has(this.id(t,r,0));r++){for(var i=[],o=0;this.codes.has(this.id(t,r,o));o++)e=this.codes.get(this.id(t,r,o)),i.push((null==e?void 0:e.toString())||"");n.push(i)}return n}},{key:"addQuiz",value:function(t,e,n){this.addRecord(this.quizzes,t,e,n)}},{key:"addSurvey",value:function(t,e,n){this.addRecord(this.surveys,t,e,n)}},{key:"addRecord",value:function(t,e,n,r){t.set(JSON.stringify([e,n,this.peerID]),r)}},{key:"initCode",value:function(t,e,n,r){if(!this.codes.has(this.id(t,e,n))){var i=this.doc.clientID;this.doc.clientID=0;var o=new f.Text;o.insert(0,r),this.codes.set(this.id(t,e,n),o),this.doc.clientID=i}}},{key:"addChatMessage",value:function(t){this.chat.set(""+Date.now(),{color:this.getColor(),message:t,user:this.peerID})}},{key:"updateCode",value:function(t,e,n,r){var i=this;this.codes.has(this.id(t,e,n))&&this.doc.transact((function(){var o=i.codes.get(i.id(t,e,n));if(void 0!==o){var u=!0,a=!1,c=void 0;try{for(var l,s=r[Symbol.iterator]();!(u=(l=s.next()).done);u=!0){var f=l.value;switch(f.action){case"insert":o.insert(f.index,f.content);break;case"remove":o.delete(f.index,f.content.length);break;default:console.warn("Sync code, unknown action ->",f)}}}catch(t){a=!0,c=t}finally{try{u||null==s.return||s.return()}finally{if(a)throw c}}}}),"code")}},{key:"getColor",value:function(){return this.color||(this.color=d.getColorFor(this.peerID)),this.color}},{key:"setCursor",value:function(t,e){var n;null===(n=this.awareness)||void 0===n||n.setLocalStateField("cursor",{id:this.peerID,section:t,project:e.project,file:e.file,state:e.state,color:this.getColor()})}},{key:"removeCursor",value:function(){var t;null===(t=this.awareness)||void 0===t||t.setLocalStateField("cursor",null)}}]),t}()})),n.register("bymyA",(function(r,i){t(r.exports,"Doc",(function(){return G})),t(r.exports,"Text",(function(){return Ze})),t(r.exports,"applyUpdate",(function(){return ct})),t(r.exports,"mergeUpdates",(function(){return $t})),t(r.exports,"encodeStateAsUpdate",(function(){return st})),t(r.exports,"encodeStateVector",(function(){return gt}));var o=n("f1evb"),u=n("9Klpk"),a=n("3bWnf"),c=n("eT7f3"),l=n("9WzNc"),s=n("div3d"),f=n("kb0qF"),d=n("bgoEC"),h=n("7j4mF"),v=n("5ENmm"),g=n("6Wo7Q"),y=n("bWNdT"),p=n("32Euv"),k=n("l6jCY"),w=n("7qPwo"),m=n("3db39"),b=n("lOVDE"),_=n("iwMp2"),S=n("i9WxE"),x=n("8C35u"),E=n("3bx5p"),C=n("jKUB9"),D=n("9eXpO"),U=n("hrH1s"),A=n("dNOud"),I=(A=n("dNOud"),n("iitZb")),T=n("b0TDd"),O=n("byQoJ"),V=n("c01oj"),N=(n("ktjib"),n("2EkIU")),M=n("7ke8k"),R=n("eYuQa"),B=(k.ObservableV2,function t(e,n){"use strict";(0,u.default)(this,t),this.clock=e,this.len=n}),L=function t(){"use strict";(0,u.default)(this,t),this.clients=new Map},F=function(t,e,n){return e.clients.forEach((function(e,r){var i=t.doc.store.clients.get(r);if(null!=i)for(var o=i[i.length-1],u=o.id.clock+o.length,a=0,c=e[a];a<e.length&&c.clock<u;c=e[++a])Ft(t,i,c.clock,c.len,n)}))},j=function(t,e){var n=t.clients.get(e.client);return void 0!==n&&null!==function(t,e){for(var n=0,r=t.length-1;n<=r;){var i=m.floor((n+r)/2),o=t[i],u=o.clock;if(u<=e){if(e<u+o.len)return i;n=i+1}else r=i-1}return null}(n,e.clock)},z=function(t){t.clients.forEach((function(t){var e,n;for(t.sort((function(t,e){return t.clock-e.clock})),e=1,n=1;e<t.length;e++){var r=t[n-1],i=t[e];r.clock+r.len>=i.clock?r.len=m.max(r.len,i.clock+i.len-r.clock):(n<e&&(t[n]=i),n++)}t.length=n}))},P=function(t){for(var e=function(e){t[e].clients.forEach((function(r,i){if(!n.clients.has(i)){for(var o=r.slice(),u=e+1;u<t.length;u++)w.appendTo(o,t[u].clients.get(i)||[]);n.clients.set(i,o)}}))},n=new L,r=0;r<t.length;r++)e(r);return z(n),n},J=function(t,e,n,r){b.setIfUndefined(t.clients,e,(function(){return[]})).push(new B(n,r))},W=function(){return new L},q=function(t){var e=W();return t.clients.forEach((function(t,n){for(var r=[],i=0;i<t.length;i++){var o=t[i];if(o.deleted){var u=o.id.clock,a=o.length;if(i+1<t.length)for(var c=t[i+1];i+1<t.length&&c.deleted;c=t[1+ ++i])a+=c.length;r.push(new B(u,a))}}r.length>0&&e.clients.set(n,r)})),e},K=function(t,e){_.writeVarUint(t.restEncoder,e.clients.size),w.from(e.clients.entries()).sort((function(t,e){return e[0]-t[0]})).forEach((function(e){var n=(0,v.default)(e,2),r=n[0],i=n[1];t.resetDsCurVal(),_.writeVarUint(t.restEncoder,r);var o=i.length;_.writeVarUint(t.restEncoder,o);for(var u=0;u<o;u++){var a=i[u];t.writeDsClock(a.clock),t.writeDsLen(a.len)}}))},Q=function(t){for(var e=function(e){t.resetDsCurVal();var r=S.readVarUint(t.restDecoder),i=S.readVarUint(t.restDecoder);if(i>0)for(var o=b.setIfUndefined(n.clients,r,(function(){return[]})),u=0;u<i;u++)o.push(new B(t.readDsClock(),t.readDsLen()))},n=new L,r=S.readVarUint(t.restDecoder),i=0;i<r;i++)e();return n},H=function(t,e,n){for(var r=new L,i=S.readVarUint(t.restDecoder),o=0;o<i;o++){t.resetDsCurVal();for(var u=S.readVarUint(t.restDecoder),a=S.readVarUint(t.restDecoder),c=n.clients.get(u)||[],l=Ot(n,u),s=0;s<a;s++){var f=t.readDsClock(),d=f+t.readDsLen();if(f<l){l<d&&J(r,u,l,d-l);var h=Nt(c,f),v=c[h];for(!v.deleted&&v.id.clock<f&&(c.splice(h+1,0,An(e,v,f-v.id.clock)),h++);h<c.length&&(v=c[h++]).id.clock<d;)v.deleted||(d<v.id.clock+v.length&&c.splice(h,0,An(e,v,d-v.id.clock)),v.delete(e))}else J(r,u,f,d-f)}}if(r.clients.size>0){var g=new it;return _.writeVarUint(g.restEncoder,0),K(g,r),g.toUint8Array()}return null},Y=x.uint32,G=function(t){"use strict";(0,f.default)(n,t);var e=(0,y.default)(n);function n(){var t,r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},i=r.guid,a=void 0===i?x.uuidv4():i,c=r.collectionid,l=void 0===c?null:c,s=r.gc,f=void 0===s||s,d=r.gcFilter,h=void 0===d?function(){return!0}:d,v=r.meta,g=void 0===v?null:v,y=r.autoLoad,p=void 0!==y&&y,k=r.shouldLoad,w=void 0===k||k;(0,u.default)(this,n),(t=e.call(this)).gc=f,t.gcFilter=h,t.clientID=Y(),t.guid=a,t.collectionid=l,t.share=new Map,t.store=new It,t._transaction=null,t._transactionCleanups=[],t.subdocs=new Set,t._item=null,t.shouldLoad=w,t.autoLoad=p,t.meta=g,t.isLoaded=!1,t.isSynced=!1,t.isDestroyed=!1,t.whenLoaded=E.create((function(e){t.on("load",(function(){t.isLoaded=!0,e((0,o.default)(t))}))}));var m=function(){return E.create((function(e){var n=function(r){void 0!==r&&!0!==r||(t.off("sync",n),e())};t.on("sync",n)}))};return t.on("sync",(function(e){!1===e&&t.isSynced&&(t.whenSynced=m()),t.isSynced=void 0===e||!0===e,t.isSynced&&!t.isLoaded&&t.emit("load",[(0,o.default)(t)])})),t.whenSynced=m(),t}return(0,a.default)(n,[{key:"load",value:function(){var t=this,e=this._item;null===e||this.shouldLoad||Qt(e.parent.doc,(function(e){e.subdocsLoaded.add(t)}),null,!0),this.shouldLoad=!0}},{key:"getSubdocs",value:function(){return this.subdocs}},{key:"getSubdocGuids",value:function(){return new Set(w.from(this.subdocs).map((function(t){return t.guid})))}},{key:"transact",value:function(t){return Qt(this,t,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null)}},{key:"get",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:pe,n=this,r=b.setIfUndefined(this.share,t,(function(){var t=new e;return t._integrate(n,null),t})),i=r.constructor;if(e!==pe&&i!==e){if(i===pe){var o=new e;o._map=r._map,r._map.forEach((function(t){for(;null!==t;t=t.left)t.parent=o})),o._start=r._start;for(var u=o._start;null!==u;u=u.right)u.parent=o;return o._length=r._length,this.share.set(t,o),o._integrate(this,null),o}throw new Error("Type with the name ".concat(t," has already been defined with a different constructor"))}return r}},{key:"getArray",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.get(t,Ne)}},{key:"getText",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.get(t,Ze)}},{key:"getMap",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.get(t,Re)}},{key:"getXmlElement",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.get(t,en)}},{key:"getXmlFragment",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"";return this.get(t,tn)}},{key:"toJSON",value:function(){var t={};return this.share.forEach((function(e,n){t[n]=e.toJSON()})),t}},{key:"destroy",value:function(){var t=this;this.isDestroyed=!0,w.from(this.subdocs).forEach((function(t){return t.destroy()}));var e=this._item;if(null!==e){this._item=null;var r=e.content;r.doc=new n((0,h.default)((0,d.default)({guid:this.guid},r.opts),{shouldLoad:!1})),r.doc._item=e,Qt(e.parent.doc,(function(n){var i=r.doc;e.deleted||n.subdocsAdded.add(i),n.subdocsRemoved.add(t)}),null,!0)}this.emit("destroyed",[!0]),this.emit("destroy",[this]),(0,l.default)((0,s.default)(n.prototype),"destroy",this).call(this)}}]),n}(k.ObservableV2),X=function(){"use strict";function t(e){(0,u.default)(this,t),this.restDecoder=e}return(0,a.default)(t,[{key:"resetDsCurVal",value:function(){}},{key:"readDsClock",value:function(){return S.readVarUint(this.restDecoder)}},{key:"readDsLen",value:function(){return S.readVarUint(this.restDecoder)}}]),t}(),Z=function(t){"use strict";(0,f.default)(n,t);var e=(0,y.default)(n);function n(){return(0,u.default)(this,n),e.apply(this,arguments)}return(0,a.default)(n,[{key:"readLeftID",value:function(){return St(S.readVarUint(this.restDecoder),S.readVarUint(this.restDecoder))}},{key:"readRightID",value:function(){return St(S.readVarUint(this.restDecoder),S.readVarUint(this.restDecoder))}},{key:"readClient",value:function(){return S.readVarUint(this.restDecoder)}},{key:"readInfo",value:function(){return S.readUint8(this.restDecoder)}},{key:"readString",value:function(){return S.readVarString(this.restDecoder)}},{key:"readParentInfo",value:function(){return 1===S.readVarUint(this.restDecoder)}},{key:"readTypeRef",value:function(){return S.readVarUint(this.restDecoder)}},{key:"readLen",value:function(){return S.readVarUint(this.restDecoder)}},{key:"readAny",value:function(){return S.readAny(this.restDecoder)}},{key:"readBuf",value:function(){return C.copyUint8Array(S.readVarUint8Array(this.restDecoder))}},{key:"readJSON",value:function(){return JSON.parse(S.readVarString(this.restDecoder))}},{key:"readKey",value:function(){return S.readVarString(this.restDecoder)}}]),n}(X),$=function(){"use strict";function t(e){(0,u.default)(this,t),this.dsCurrVal=0,this.restDecoder=e}return(0,a.default)(t,[{key:"resetDsCurVal",value:function(){this.dsCurrVal=0}},{key:"readDsClock",value:function(){return this.dsCurrVal+=S.readVarUint(this.restDecoder),this.dsCurrVal}},{key:"readDsLen",value:function(){var t=S.readVarUint(this.restDecoder)+1;return this.dsCurrVal+=t,t}}]),t}(),tt=function(t){"use strict";(0,f.default)(n,t);var e=(0,y.default)(n);function n(t){var r;return(0,u.default)(this,n),(r=e.call(this,t)).keys=[],S.readVarUint(t),r.keyClockDecoder=new S.IntDiffOptRleDecoder(S.readVarUint8Array(t)),r.clientDecoder=new S.UintOptRleDecoder(S.readVarUint8Array(t)),r.leftClockDecoder=new S.IntDiffOptRleDecoder(S.readVarUint8Array(t)),r.rightClockDecoder=new S.IntDiffOptRleDecoder(S.readVarUint8Array(t)),r.infoDecoder=new S.RleDecoder(S.readVarUint8Array(t),S.readUint8),r.stringDecoder=new S.StringDecoder(S.readVarUint8Array(t)),r.parentInfoDecoder=new S.RleDecoder(S.readVarUint8Array(t),S.readUint8),r.typeRefDecoder=new S.UintOptRleDecoder(S.readVarUint8Array(t)),r.lenDecoder=new S.UintOptRleDecoder(S.readVarUint8Array(t)),r}return(0,a.default)(n,[{key:"readLeftID",value:function(){return new bt(this.clientDecoder.read(),this.leftClockDecoder.read())}},{key:"readRightID",value:function(){return new bt(this.clientDecoder.read(),this.rightClockDecoder.read())}},{key:"readClient",value:function(){return this.clientDecoder.read()}},{key:"readInfo",value:function(){return this.infoDecoder.read()}},{key:"readString",value:function(){return this.stringDecoder.read()}},{key:"readParentInfo",value:function(){return 1===this.parentInfoDecoder.read()}},{key:"readTypeRef",value:function(){return this.typeRefDecoder.read()}},{key:"readLen",value:function(){return this.lenDecoder.read()}},{key:"readAny",value:function(){return S.readAny(this.restDecoder)}},{key:"readBuf",value:function(){return S.readVarUint8Array(this.restDecoder)}},{key:"readJSON",value:function(){return S.readAny(this.restDecoder)}},{key:"readKey",value:function(){var t=this.keyClockDecoder.read();if(t<this.keys.length)return this.keys[t];var e=this.stringDecoder.read();return this.keys.push(e),e}}]),n}($),et=function(){"use strict";function t(){(0,u.default)(this,t),this.restEncoder=_.createEncoder()}return(0,a.default)(t,[{key:"toUint8Array",value:function(){return _.toUint8Array(this.restEncoder)}},{key:"resetDsCurVal",value:function(){}},{key:"writeDsClock",value:function(t){_.writeVarUint(this.restEncoder,t)}},{key:"writeDsLen",value:function(t){_.writeVarUint(this.restEncoder,t)}}]),t}(),nt=function(t){"use strict";(0,f.default)(n,t);var e=(0,y.default)(n);function n(){return(0,u.default)(this,n),e.apply(this,arguments)}return(0,a.default)(n,[{key:"writeLeftID",value:function(t){_.writeVarUint(this.restEncoder,t.client),_.writeVarUint(this.restEncoder,t.clock)}},{key:"writeRightID",value:function(t){_.writeVarUint(this.restEncoder,t.client),_.writeVarUint(this.restEncoder,t.clock)}},{key:"writeClient",value:function(t){_.writeVarUint(this.restEncoder,t)}},{key:"writeInfo",value:function(t){_.writeUint8(this.restEncoder,t)}},{key:"writeString",value:function(t){_.writeVarString(this.restEncoder,t)}},{key:"writeParentInfo",value:function(t){_.writeVarUint(this.restEncoder,t?1:0)}},{key:"writeTypeRef",value:function(t){_.writeVarUint(this.restEncoder,t)}},{key:"writeLen",value:function(t){_.writeVarUint(this.restEncoder,t)}},{key:"writeAny",value:function(t){_.writeAny(this.restEncoder,t)}},{key:"writeBuf",value:function(t){_.writeVarUint8Array(this.restEncoder,t)}},{key:"writeJSON",value:function(t){_.writeVarString(this.restEncoder,JSON.stringify(t))}},{key:"writeKey",value:function(t){_.writeVarString(this.restEncoder,t)}}]),n}(et),rt=function(){"use strict";function t(){(0,u.default)(this,t),this.restEncoder=_.createEncoder(),this.dsCurrVal=0}return(0,a.default)(t,[{key:"toUint8Array",value:function(){return _.toUint8Array(this.restEncoder)}},{key:"resetDsCurVal",value:function(){this.dsCurrVal=0}},{key:"writeDsClock",value:function(t){var e=t-this.dsCurrVal;this.dsCurrVal=t,_.writeVarUint(this.restEncoder,e)}},{key:"writeDsLen",value:function(t){0===t&&D.unexpectedCase(),_.writeVarUint(this.restEncoder,t-1),this.dsCurrVal+=t}}]),t}(),it=function(t){"use strict";(0,f.default)(n,t);var e=(0,y.default)(n);function n(){var t;return(0,u.default)(this,n),(t=e.call(this)).keyMap=new Map,t.keyClock=0,t.keyClockEncoder=new _.IntDiffOptRleEncoder,t.clientEncoder=new _.UintOptRleEncoder,t.leftClockEncoder=new _.IntDiffOptRleEncoder,t.rightClockEncoder=new _.IntDiffOptRleEncoder,t.infoEncoder=new _.RleEncoder(_.writeUint8),t.stringEncoder=new _.StringEncoder,t.parentInfoEncoder=new _.RleEncoder(_.writeUint8),t.typeRefEncoder=new _.UintOptRleEncoder,t.lenEncoder=new _.UintOptRleEncoder,t}return(0,a.default)(n,[{key:"toUint8Array",value:function(){var t=_.createEncoder();return _.writeVarUint(t,0),_.writeVarUint8Array(t,this.keyClockEncoder.toUint8Array()),_.writeVarUint8Array(t,this.clientEncoder.toUint8Array()),_.writeVarUint8Array(t,this.leftClockEncoder.toUint8Array()),_.writeVarUint8Array(t,this.rightClockEncoder.toUint8Array()),_.writeVarUint8Array(t,_.toUint8Array(this.infoEncoder)),_.writeVarUint8Array(t,this.stringEncoder.toUint8Array()),_.writeVarUint8Array(t,_.toUint8Array(this.parentInfoEncoder)),_.writeVarUint8Array(t,this.typeRefEncoder.toUint8Array()),_.writeVarUint8Array(t,this.lenEncoder.toUint8Array()),_.writeUint8Array(t,_.toUint8Array(this.restEncoder)),_.toUint8Array(t)}},{key:"writeLeftID",value:function(t){this.clientEncoder.write(t.client),this.leftClockEncoder.write(t.clock)}},{key:"writeRightID",value:function(t){this.clientEncoder.write(t.client),this.rightClockEncoder.write(t.clock)}},{key:"writeClient",value:function(t){this.clientEncoder.write(t)}},{key:"writeInfo",value:function(t){this.infoEncoder.write(t)}},{key:"writeString",value:function(t){this.stringEncoder.write(t)}},{key:"writeParentInfo",value:function(t){this.parentInfoEncoder.write(t?1:0)}},{key:"writeTypeRef",value:function(t){this.typeRefEncoder.write(t)}},{key:"writeLen",value:function(t){this.lenEncoder.write(t)}},{key:"writeAny",value:function(t){_.writeAny(this.restEncoder,t)}},{key:"writeBuf",value:function(t){_.writeVarUint8Array(this.restEncoder,t)}},{key:"writeJSON",value:function(t){_.writeAny(this.restEncoder,t)}},{key:"writeKey",value:function(t){var e=this.keyMap.get(t);void 0===e?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(t)):this.keyClockEncoder.write(e)}}]),n}(rt),ot=function(t,e,n){var r=new Map;n.forEach((function(t,n){Ot(e,n)>t&&r.set(n,t)})),Tt(e).forEach((function(t,e){n.has(e)||r.set(e,0)})),_.writeVarUint(t.restEncoder,r.size),w.from(r.entries()).sort((function(t,e){return e[0]-t[0]})).forEach((function(n){var r=(0,v.default)(n,2),i=r[0],o=r[1];!function(t,e,n,r){r=m.max(r,e[0].id.clock);var i=Nt(e,r);_.writeVarUint(t.restEncoder,e.length-i),t.writeClient(n),_.writeVarUint(t.restEncoder,r);var o=e[i];o.write(t,r-o.id.clock);for(var u=i+1;u<e.length;u++)e[u].write(t,0)}(t,e.clients.get(i),i,o)}))},ut=function(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:new tt(t);return Qt(e,(function(t){t.local=!1;var e=!1,n=t.doc,i=n.store,o=function(t,e){for(var n=b.create(),r=S.readVarUint(t.restDecoder),i=0;i<r;i++){var o=S.readVarUint(t.restDecoder),u=new Array(o),a=t.readClient(),c=S.readVarUint(t.restDecoder);n.set(a,{i:0,refs:u});for(var l=0;l<o;l++){var s=t.readInfo();switch(U.BITS5&s){case 0:var f=t.readLen();u[l]=new an(St(a,c),f),c+=f;break;case 10:var d=S.readVarUint(t.restDecoder);u[l]=new Mn(St(a,c),d),c+=d;break;default:var h=!(s&(U.BIT7|U.BIT8)),v=new On(St(a,c),null,(s&U.BIT8)===U.BIT8?t.readLeftID():null,null,(s&U.BIT7)===U.BIT7?t.readRightID():null,h?t.readParentInfo()?e.get(t.readString()):t.readLeftID():null,h&&(s&U.BIT6)===U.BIT6?t.readString():null,Vn(t,s));u[l]=v,c+=v.length}}}return n}(r,n),u=function(t,e,n){var r=[],i=w.from(n.keys()).sort((function(t,e){return t-e}));if(0===i.length)return null;var o=function(){if(0===i.length)return null;for(var t=n.get(i[i.length-1]);t.refs.length===t.i;){if(i.pop(),!(i.length>0))return null;t=n.get(i[i.length-1])}return t},u=o();if(null===u)return null;for(var a=new It,c=new Map,l=function(t,e){var n=c.get(t);(null==n||n>e)&&c.set(t,e)},s=u.refs[u.i++],f=new Map,d=function(){var t=!0,e=!1,o=void 0;try{for(var u,c=function(){var t=u.value,e=t.id.client,r=n.get(e);r?(r.i--,a.clients.set(e,r.refs.slice(r.i)),n.delete(e),r.i=0,r.refs=[]):a.clients.set(e,[t]),i=i.filter((function(t){return t!==e}))},l=r[Symbol.iterator]();!(t=(u=l.next()).done);t=!0)c()}catch(t){e=!0,o=t}finally{try{t||null==l.return||l.return()}finally{if(e)throw o}}r.length=0};;){if(s.constructor!==Mn){var h=b.setIfUndefined(f,s.id.client,(function(){return Ot(e,s.id.client)}))-s.id.clock;if(h<0)r.push(s),l(s.id.client,s.id.clock-1),d();else{var v=s.getMissing(t,e);if(null!==v){r.push(s);var g=n.get(v)||{refs:[],i:0};if(g.refs.length!==g.i){s=g.refs[g.i++];continue}l(v,Ot(e,v)),d()}else(0===h||h<s.length)&&(s.integrate(t,h),f.set(s.id.client,s.id.clock+s.length))}}if(r.length>0)s=r.pop();else if(null!==u&&u.i<u.refs.length)s=u.refs[u.i++];else{if(null===(u=o()))break;s=u.refs[u.i++]}}if(a.clients.size>0){var y=new it;return ot(y,a,new Map),_.writeVarUint(y.restEncoder,0),{missing:c,update:y.toUint8Array()}}return null}(t,i,o),a=i.pendingStructs;if(a){var c=!0,l=!1,s=void 0;try{for(var f,d=a.missing[Symbol.iterator]();!(c=(f=d.next()).done);c=!0){var h=(0,v.default)(f.value,2),g=h[0];if(h[1]<Ot(i,g)){e=!0;break}}}catch(t){l=!0,s=t}finally{try{c||null==d.return||d.return()}finally{if(l)throw s}}if(u){var y=!0,p=!1,k=void 0;try{for(var m,x=u.missing[Symbol.iterator]();!(y=(m=x.next()).done);y=!0){var E=(0,v.default)(m.value,2),C=E[0],D=E[1],A=a.missing.get(C);(null==A||A>D)&&a.missing.set(C,D)}}catch(t){p=!0,k=t}finally{try{y||null==x.return||x.return()}finally{if(p)throw k}}a.update=te([a.update,u.update])}}else i.pendingStructs=u;var I=H(r,t,i);if(i.pendingDs){var T=new tt(S.createDecoder(i.pendingDs));S.readVarUint(T.restDecoder);var O=H(T,t,i);i.pendingDs=I&&O?te([I,O]):I||O}else i.pendingDs=I;if(e){var V=i.pendingStructs.update;i.pendingStructs=null,at(t.doc,V)}}),n,!1)},at=function(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:tt,i=S.createDecoder(e);ut(i,t,n,new r(i))},ct=function(t,e,n){return at(t,e,n,Z)},lt=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new Uint8Array([0]),n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new it;!function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new Map;ot(t,e.store,n),K(t,q(e.store))}(n,t,dt(e));var r=[n.toUint8Array()];if(t.store.pendingDs&&r.push(t.store.pendingDs),t.store.pendingStructs&&r.push(ee(t.store.pendingStructs.update,e)),r.length>1){if(n.constructor===nt)return $t(r.map((function(t,e){return 0===e?t:ue(t)})));if(n.constructor===it)return te(r)}return r[0]},st=function(t,e){return lt(t,e,new nt)},ft=function(t){for(var e=new Map,n=S.readVarUint(t.restDecoder),r=0;r<n;r++){var i=S.readVarUint(t.restDecoder),o=S.readVarUint(t.restDecoder);e.set(i,o)}return e},dt=function(t){return ft(new X(S.createDecoder(t)))},ht=function(t,e){return _.writeVarUint(t.restEncoder,e.size),w.from(e.entries()).sort((function(t,e){return e[0]-t[0]})).forEach((function(e){var n=(0,v.default)(e,2),r=n[0],i=n[1];_.writeVarUint(t.restEncoder,r),_.writeVarUint(t.restEncoder,i)})),t},vt=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:new rt;return t instanceof Map?ht(e,t):function(t,e){ht(t,Tt(e.store))}(e,t),e.toUint8Array()},gt=function(t){return vt(t,new et)},yt=function t(){"use strict";(0,u.default)(this,t),this.l=[]},pt=function(){return new yt},kt=function(t,e){return t.l.push(e)},wt=function(t,e){var n=t.l,r=n.length;t.l=n.filter((function(t){return e!==t})),r===t.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.")},mt=function(t,e,n){return A.callAll(t.l,[e,n])},bt=function t(e,n){"use strict";(0,u.default)(this,t),this.client=e,this.clock=n},_t=function(t,e){return t===e||null!==t&&null!==e&&t.client===e.client&&t.clock===e.clock},St=function(t,e){return new bt(t,e)},xt=function(t){var e=!0,n=!1,r=void 0;try{for(var i,o=t.doc.share.entries()[Symbol.iterator]();!(e=(i=o.next()).done);e=!0){var u=(0,v.default)(i.value,2),a=u[0];if(u[1]===t)return a}}catch(t){n=!0,r=t}finally{try{e||null==o.return||o.return()}finally{if(n)throw r}}throw D.unexpectedCase()},Et=function(t,e){for(;null!==e;){if(e.parent===t)return!0;e=e.parent._item}return!1},Ct=function t(e,n){"use strict";(0,u.default)(this,t),this.ds=e,this.sv=n},Dt=function(t,e){return new Ct(t,e)},Ut=(Dt(W(),new Map),function(t,e){return void 0===e?!t.deleted:e.sv.has(t.id.client)&&(e.sv.get(t.id.client)||0)>t.id.clock&&!j(e.ds,t.id)}),At=function(t,e){var n=b.setIfUndefined(t.meta,At,I.create),r=t.doc.store;n.has(e)||(e.sv.forEach((function(e,n){e<Ot(r,n)&&Bt(t,St(n,e))})),F(t,e.ds,(function(t){})),n.add(e))},It=function t(){"use strict";(0,u.default)(this,t),this.clients=new Map,this.pendingStructs=null,this.pendingDs=null},Tt=function(t){var e=new Map;return t.clients.forEach((function(t,n){var r=t[t.length-1];e.set(n,r.id.clock+r.length)})),e},Ot=function(t,e){var n=t.clients.get(e);if(void 0===n)return 0;var r=n[n.length-1];return r.id.clock+r.length},Vt=function(t,e){var n=t.clients.get(e.id.client);if(void 0===n)n=[],t.clients.set(e.id.client,n);else{var r=n[n.length-1];if(r.id.clock+r.length!==e.id.clock)throw D.unexpectedCase()}n.push(e)},Nt=function(t,e){var n=0,r=t.length-1,i=t[r],o=i.id.clock;if(o===e)return r;for(var u=m.floor(e/(o+i.length-1)*r);n<=r;){if((o=(i=t[u]).id.clock)<=e){if(e<o+i.length)return u;n=u+1}else r=u-1;u=m.floor((n+r)/2)}throw D.unexpectedCase()},Mt=function(t,e){var n=t.clients.get(e.client);return n[Nt(n,e.clock)]},Rt=function(t,e,n){var r=Nt(e,n),i=e[r];return i.id.clock<n&&i instanceof On?(e.splice(r+1,0,An(t,i,n-i.id.clock)),r+1):r},Bt=function(t,e){var n=t.doc.store.clients.get(e.client);return n[Rt(t,n,e.clock)]},Lt=function(t,e,n){var r=e.clients.get(n.client),i=Nt(r,n.clock),o=r[i];return n.clock!==o.id.clock+o.length-1&&o.constructor!==an&&r.splice(i+1,0,An(t,o,n.clock-o.id.clock+1)),o},Ft=function(t,e,n,r,i){if(0!==r){var o,u=n+r,a=Rt(t,e,n);do{u<(o=e[a++]).id.clock+o.length&&Rt(t,e,u),i(o)}while(a<e.length&&e[a].id.clock<u)}},jt=function t(e,n,r){"use strict";(0,u.default)(this,t),this.doc=e,this.deleteSet=new L,this.beforeState=Tt(e.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,this._needFormattingCleanup=!1},zt=function(t,e){return!(0===e.deleteSet.clients.size&&!b.any(e.afterState,(function(t,n){return e.beforeState.get(n)!==t})))&&(z(e.deleteSet),function(t,e){ot(t,e.doc.store,e.beforeState)}(t,e),K(t,e.deleteSet),!0)},Pt=function(t,e,n){var r=e._item;(null===r||r.id.clock<(t.beforeState.get(r.id.client)||0)&&!r.deleted)&&b.setIfUndefined(t.changed,e,I.create).add(n)},Jt=function(t,e){for(var n=t[e],r=t[e-1],i=e;i>0&&(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n));n=r,r=t[--i-1])n instanceof On&&null!==n.parentSub&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);var o=e-i;return o&&t.splice(e+1-o,o),o},Wt=function(t,e,n){var r=!0,i=!1,o=void 0;try{for(var u,a=t.clients.entries()[Symbol.iterator]();!(r=(u=a.next()).done);r=!0)for(var c=(0,v.default)(u.value,2),l=c[0],s=c[1],f=e.clients.get(l),d=s.length-1;d>=0;d--)for(var h=s[d],g=h.clock+h.len,y=Nt(f,h.clock),p=f[y];y<f.length&&p.id.clock<g;p=f[++y]){var k=f[y];if(h.clock+h.len<=k.id.clock)break;k instanceof On&&k.deleted&&!k.keep&&n(k)&&k.gc(e,!1)}}catch(t){i=!0,o=t}finally{try{r||null==a.return||a.return()}finally{if(i)throw o}}},qt=function(t,e){t.clients.forEach((function(t,n){for(var r=e.clients.get(n),i=t.length-1;i>=0;i--)for(var o=t[i],u=m.min(r.length-1,1+Nt(r,o.clock+o.len-1)),a=r[u];u>0&&a.id.clock>=o.clock;a=r[u])u-=1+Jt(r,u)}))},Kt=function(t,e){if(e<t.length){var n=t[e],r=n.doc,i=r.store,o=n.deleteSet,u=n._mergeStructs;try{z(o),n.afterState=Tt(n.doc.store),r.emit("beforeObserverCalls",[n,r]);var a=[];n.changed.forEach((function(t,e){return a.push((function(){null!==e._item&&e._item.deleted||e._callObserver(n,t)}))})),a.push((function(){n.changedParentTypes.forEach((function(t,e){e._dEH.l.length>0&&(null===e._item||!e._item.deleted)&&((t=t.filter((function(t){return null===t.target._item||!t.target._item.deleted}))).forEach((function(t){t.currentTarget=e,t._path=null})),t.sort((function(t,e){return t.path.length-e.path.length})),a.push((function(){mt(e._dEH,t,n)})))})),a.push((function(){return r.emit("afterTransaction",[n,r])})),a.push((function(){n._needFormattingCleanup&&Ye(n)}))})),(0,A.callAll)(a,[])}finally{r.gc&&Wt(o,i,r.gcFilter),qt(o,i),n.afterState.forEach((function(t,e){var r=n.beforeState.get(e)||0;if(r!==t)for(var o=i.clients.get(e),u=m.max(Nt(o,r),1),a=o.length-1;a>=u;)a-=1+Jt(o,a)}));for(var c=u.length-1;c>=0;c--){var l=u[c].id,s=l.client,f=l.clock,d=i.clients.get(s),h=Nt(d,f);h+1<d.length&&Jt(d,h+1)>1||h>0&&Jt(d,h)}if(n.local||n.afterState.get(r.clientID)===n.beforeState.get(r.clientID)||(T.print(O.ORANGE,O.BOLD,"[yjs] ",O.UNBOLD,O.RED,"Changed the client-id because another client seems to be using it."),r.clientID=Y()),r.emit("afterTransactionCleanup",[n,r]),r._observers.has("update")){var v=new nt;zt(v,n)&&r.emit("update",[v.toUint8Array(),n.origin,r,n])}if(r._observers.has("updateV2")){var g=new it;zt(g,n)&&r.emit("updateV2",[g.toUint8Array(),n.origin,r,n])}var y=n.subdocsAdded,p=n.subdocsLoaded,k=n.subdocsRemoved;(y.size>0||k.size>0||p.size>0)&&(y.forEach((function(t){t.clientID=r.clientID,null==t.collectionid&&(t.collectionid=r.collectionid),r.subdocs.add(t)})),k.forEach((function(t){return r.subdocs.delete(t)})),r.emit("subdocs",[{loaded:p,added:y,removed:k},r,n]),k.forEach((function(t){return t.destroy()}))),t.length<=e+1?(r._transactionCleanups=[],r.emit("afterAllTransactions",[r,t])):Kt(t,e+1)}}},Qt=function(t,e){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,r=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],i=t._transactionCleanups,o=!1,u=null;null===t._transaction&&(o=!0,t._transaction=new jt(t,n,r),i.push(t._transaction),1===i.length&&t.emit("beforeAllTransactions",[t]),t.emit("beforeTransaction",[t._transaction,t]));try{u=e(t._transaction)}finally{if(o){var a=t._transaction===i[0];t._transaction=null,a&&Kt(i,0)}}return u},Ht=function t(e,n){"use strict";(0,u.default)(this,t),this.insertions=n,this.deletions=e,this.meta=new Map},Yt=function(t,e,n){F(t,n.deletions,(function(n){n instanceof On&&e.scope.some((function(e){return e===t.doc||Et(e,n)}))&&Un(n,!1)}))},Gt=function(t,e,n){var r=null,i=t.doc,o=t.scope;Qt(i,(function(n){for(var u=function(){var r=i.store,u=e.pop(),a=new Set,c=[],l=!1;F(n,u.insertions,(function(t){if(t instanceof On){if(null!==t.redone){var e=Dn(r,t.id),i=e.item,u=e.diff;u>0&&(i=Bt(n,St(i.id.client,i.id.clock+u))),t=i}!t.deleted&&o.some((function(e){return e===n.doc||Et(e,t)}))&&c.push(t)}})),F(n,u.deletions,(function(t){t instanceof On&&o.some((function(e){return e===n.doc||Et(e,t)}))&&!j(u.insertions,t.id)&&a.add(t)})),a.forEach((function(e){l=null!==Tn(n,e,a,u.insertions,t.ignoreRemoteMapChanges,t)||l}));for(var s=c.length-1;s>=0;s--){var f=c[s];t.deleteFilter(f)&&(f.delete(n),l=!0)}t.currStackItem=l?u:null};e.length>0&&null===t.currStackItem;)u();n.changed.forEach((function(t,e){t.has(null)&&e._searchMarker&&(e._searchMarker.length=0)})),r=n}),t);var u=t.currStackItem;if(null!=u){var a=r.changedParentTypes;t.emit("stack-item-popped",[{stackItem:u,type:n,changedParentTypes:a,origin:t},t]),t.currStackItem=null}return u};k.ObservableV2;var Xt=function(){"use strict";function t(e,n){(0,u.default)(this,t),this.gen=function(t){var e,n,r,i,o,u,a,c,l,s,f;return(0,p.__generator)(this,(function(d){switch(d.label){case 0:e=S.readVarUint(t.restDecoder),n=0,d.label=1;case 1:if(!(n<e))return[3,10];r=S.readVarUint(t.restDecoder),i=t.readClient(),o=S.readVarUint(t.restDecoder),u=0,d.label=2;case 2:return u<r?10!==(a=t.readInfo())?[3,4]:(c=S.readVarUint(t.restDecoder),[4,new Mn(St(i,o),c)]):[3,9];case 3:return d.sent(),o+=c,[3,8];case 4:return U.BITS5&a?(l=!(a&(U.BIT7|U.BIT8)),[4,s=new On(St(i,o),null,(a&U.BIT8)===U.BIT8?t.readLeftID():null,null,(a&U.BIT7)===U.BIT7?t.readRightID():null,l?t.readParentInfo()?t.readString():t.readLeftID():null,l&&(a&U.BIT6)===U.BIT6?t.readString():null,Vn(t,a))]):[3,6];case 5:return d.sent(),o+=s.length,[3,8];case 6:return f=t.readLen(),[4,new an(St(i,o),f)];case 7:d.sent(),o+=f,d.label=8;case 8:return u++,[3,2];case 9:return n++,[3,1];case 10:return[2]}}))}(e),this.curr=null,this.done=!1,this.filterSkips=n,this.next()}return(0,a.default)(t,[{key:"next",value:function(){do{this.curr=this.gen.next().value||null}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Mn);return this.curr}}]),t}(),Zt=function t(e){"use strict";(0,u.default)(this,t),this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]},$t=function(t){return te(t,Z,nt)},te=function(t){var e=function(){if((o=o.filter((function(t){return null!==t.curr}))).sort((function(t,e){if(t.curr.id.client===e.curr.id.client){var n=t.curr.id.clock-e.curr.id.clock;return 0===n?t.curr.constructor===e.curr.constructor?0:t.curr.constructor===Mn?1:-1:n}return e.curr.id.client-t.curr.id.client})),0===o.length)return"break";var t=o[0],e=t.curr.id.client;if(null!==u){for(var n=t.curr,r=!1;null!==n&&n.id.clock+n.length<=u.struct.id.clock+u.struct.length&&n.id.client>=u.struct.id.client;)n=t.next(),r=!0;if(null===n||n.id.client!==e||r&&n.id.clock>u.struct.id.clock+u.struct.length)return"continue";if(e!==u.struct.id.client)re(c,u.struct,u.offset),u={struct:n,offset:0},t.next();else if(u.struct.id.clock+u.struct.length<n.id.clock)if(u.struct.constructor===Mn)u.struct.length=n.id.clock+n.length-u.struct.id.clock;else{re(c,u.struct,u.offset);var i=n.id.clock-u.struct.id.clock-u.struct.length,a=new Mn(St(e,u.struct.id.clock+u.struct.length),i);u={struct:a,offset:0}}else{var l=u.struct.id.clock+u.struct.length-n.id.clock;l>0&&(u.struct.constructor===Mn?u.struct.length-=l:n=function(t,e){if(t.constructor===an){var n=t.id,r=n.client,i=n.clock;return new an(St(r,i+e),t.length-e)}if(t.constructor===Mn){var o=t.id,u=o.client,a=o.clock;return new Mn(St(u,a+e),t.length-e)}var c=t,l=c.id,s=l.client,f=l.clock;return new On(St(s,f+e),null,St(s,f+e-1),null,c.rightOrigin,c.parent,c.parentSub,c.content.splice(e))}(n,l)),u.struct.mergeWith(n)||(re(c,u.struct,u.offset),u={struct:n,offset:0},t.next())}}else u={struct:t.curr,offset:0},t.next();for(var s=t.curr;null!==s&&s.id.client===e&&s.id.clock===u.struct.id.clock+u.struct.length&&s.constructor!==Mn;s=t.next())re(c,u.struct,u.offset),u={struct:s,offset:0}},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:tt,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:it;if(1===t.length)return t[0];for(var i=t.map((function(t){return new n(S.createDecoder(t))})),o=i.map((function(t){return new Xt(t,!0)})),u=null,a=new r,c=new Zt(a);;){if("break"===e())break}null!==u&&(re(c,u.struct,u.offset),u=null),ie(c);var l=i.map((function(t){return Q(t)})),s=P(l);return K(a,s),a.toUint8Array()},ee=function(t,e){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:tt,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:it,i=dt(e),o=new r,u=new Zt(o),a=new n(S.createDecoder(t)),c=new Xt(a,!1);c.curr;){var l=c.curr,s=l.id.client,f=i.get(s)||0;if(c.curr.constructor!==Mn)if(l.id.clock+l.length>f)for(re(u,l,m.max(f-l.id.clock,0)),c.next();c.curr&&c.curr.id.client===s;)re(u,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===s&&c.curr.id.clock+c.curr.length<=f;)c.next();else c.next()}ie(u);var d=Q(a);return K(o,d),o.toUint8Array()},ne=function(t){t.written>0&&(t.clientStructs.push({written:t.written,restEncoder:_.toUint8Array(t.encoder.restEncoder)}),t.encoder.restEncoder=_.createEncoder(),t.written=0)},re=function(t,e,n){t.written>0&&t.currClient!==e.id.client&&ne(t),0===t.written&&(t.currClient=e.id.client,t.encoder.writeClient(e.id.client),_.writeVarUint(t.encoder.restEncoder,e.id.clock+n)),e.write(t.encoder,n),t.written++},ie=function(t){ne(t);var e=t.encoder.restEncoder;_.writeVarUint(e,t.clientStructs.length);for(var n=0;n<t.clientStructs.length;n++){var r=t.clientStructs[n];_.writeVarUint(e,r.written),_.writeUint8Array(e,r.restEncoder)}},oe=function(t,e,n,r){for(var i=new n(S.createDecoder(t)),o=new Xt(i,!1),u=new r,a=new Zt(u),c=o.curr;null!==c;c=o.next())re(a,e(c),0);ie(a);var l=Q(i);return K(u,l),u.toUint8Array()},ue=function(t){return oe(t,A.id,tt,nt)},ae="You must not compute changes after the event-handler fired.",ce=function(){"use strict";function t(e,n){(0,u.default)(this,t),this.target=e,this.currentTarget=e,this.transaction=n,this._changes=null,this._keys=null,this._delta=null,this._path=null}return(0,a.default)(t,[{key:"path",get:function(){return this._path||(this._path=le(this.currentTarget,this.target))}},{key:"deletes",value:function(t){return j(this.transaction.deleteSet,t.id)}},{key:"keys",get:function(){var t=this;if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw D.create(ae);var e=new Map,n=this.target;this.transaction.changed.get(n).forEach((function(r){if(null!==r){var i,o,u=n._map.get(r);if(t.adds(u)){for(var a=u.left;null!==a&&t.adds(a);)a=a.left;if(t.deletes(u)){if(null===a||!t.deletes(a))return;i="delete",o=w.last(a.content.getContent())}else null!==a&&t.deletes(a)?(i="update",o=w.last(a.content.getContent())):(i="add",o=void 0)}else{if(!t.deletes(u))return;i="delete",o=w.last(u.content.getContent())}e.set(r,{action:i,oldValue:o})}})),this._keys=e}return this._keys}},{key:"delta",get:function(){return this.changes.delta}},{key:"adds",value:function(t){return t.id.clock>=(this.transaction.beforeState.get(t.id.client)||0)}},{key:"changes",get:function(){var t=this._changes;if(null===t){if(0===this.transaction.doc._transactionCleanups.length)throw D.create(ae);var e=this.target,n=I.create(),r=I.create(),i=[];if(t={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(e).has(null)){for(var o=null,u=function(){o&&i.push(o)},a=e._start;null!==a;a=a.right)a.deleted?this.deletes(a)&&!this.adds(a)&&(null!==o&&void 0!==o.delete||(u(),o={delete:0}),o.delete+=a.length,r.add(a)):this.adds(a)?(null!==o&&void 0!==o.insert||(u(),o={insert:[]}),o.insert=o.insert.concat(a.content.getContent()),n.add(a)):(null!==o&&void 0!==o.retain||(u(),o={retain:0}),o.retain+=a.length);null!==o&&void 0===o.retain&&u()}this._changes=t}return t}}]),t}(),le=function(t,e){for(var n=[];null!==e._item&&e!==t;){if(null!==e._item.parentSub)n.unshift(e._item.parentSub);else{for(var r=0,i=e._item.parent._start;i!==e._item&&null!==i;)!i.deleted&&i.countable&&(r+=i.length),i=i.right;n.unshift(r)}e=e._item.parent}return n},se=function(){T.warn("Invalid access: Add Yjs type to a document before reading data.")},fe=0,de=function t(e,n){"use strict";(0,u.default)(this,t),e.marker=!0,this.p=e,this.index=n,this.timestamp=fe++},he=function(t,e,n){t.p.marker=!1,t.p=e,e.marker=!0,t.index=n,t.timestamp=fe++},ve=function(t,e){if(null===t._start||0===e||null===t._searchMarker)return null;var n=0===t._searchMarker.length?null:t._searchMarker.reduce((function(t,n){return m.abs(e-t.index)<m.abs(e-n.index)?t:n})),r=t._start,i=0;for(null!==n&&(r=n.p,i=n.index,function(t){t.timestamp=fe++}(n));null!==r.right&&i<e;){if(!r.deleted&&r.countable){if(e<i+r.length)break;i+=r.length}r=r.right}for(;null!==r.left&&i>e;)!(r=r.left).deleted&&r.countable&&(i-=r.length);for(;null!==r.left&&r.left.id.client===r.id.client&&r.left.id.clock+r