@luminocity/lemonate-engine 26.3.12 → 26.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lemonate.es.js +1 -1
- package/dist/lemonate.js +2 -2
- package/dist/lemonate.min.js +2 -2
- package/dist/lemonate.umd.js +1 -1
- package/dist/player.zip +0 -0
- package/package.json +2 -2
package/dist/lemonate.js
CHANGED
|
@@ -6597,7 +6597,7 @@ var Lemonate = (function (exports) {
|
|
|
6597
6597
|
Version 1.10.0
|
|
6598
6598
|
https://localforage.github.io/localForage
|
|
6599
6599
|
(c) 2013-2017 Mozilla, Apache License 2.0
|
|
6600
|
-
*/var Xi=(Ji||(Ji=1,Ki.exports=function e(t,a,i){function n(s,o){if(!a[s]){if(!t[s]){if(!o&&R$a)return R$a(s);if(r)return r(s,true);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=a[s]={exports:{}};t[s][0].call(u.exports,(function(e){var a=t[s][1][e];return n(a||e)}),u,u.exports,e,t,a,i);}return a[s].exports}for(var r=R$a,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(e,t,a){(function(e){var a,i,n=e.MutationObserver||e.WebKitMutationObserver;if(n){var r=0,s=new n(c),o=e.document.createTextNode("");s.observe(o,{characterData:true}),a=function(){o.data=r=++r%2;};}else if(e.setImmediate||void 0===e.MessageChannel)a="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){c(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null;},e.document.documentElement.appendChild(t);}:function(){setTimeout(c,0);};else {var l=new e.MessageChannel;l.port1.onmessage=c,a=function(){l.port2.postMessage(0);};}var u=[];function c(){var e,t;i=true;for(var a=u.length;a;){for(t=u,u=[],e=-1;++e<a;)t[e]();a=u.length;}i=false;}function d(e){1!==u.push(e)||i||a();}t.exports=d;}).call(this,void 0!==D?D:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});},{}],2:[function(e,t,a){var i=e(1);function n(){}var r={},s=["REJECTED"],o=["FULFILLED"],l=["PENDING"];function u(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,e!==n&&h(this,e);}function c(e,t,a){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof a&&(this.onRejected=a,this.callRejected=this.otherCallRejected);}function d(e,t,a){i((function(){var i;try{i=t(a);}catch(t){return r.reject(e,t)}i===e?r.reject(e,new TypeError("Cannot resolve promise with itself")):r.resolve(e,i);}));}function p(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments);}}function h(e,t){var a=false;function i(t){a||(a=true,r.reject(e,t));}function n(t){a||(a=true,r.resolve(e,t));}function s(){t(n,i);}var o=f(s);"error"===o.status&&i(o.value);}function f(e,t){var a={};try{a.value=e(t),a.status="success";}catch(e){a.status="error",a.value=e;}return a}function m(e){return e instanceof this?e:r.resolve(new this(n),e)}function y(e){var t=new this(n);return r.reject(t,e)}function g(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var a=e.length,i=false;if(!a)return this.resolve([]);for(var s=new Array(a),o=0,l=-1,u=new this(n);++l<a;)c(e[l],l);return u;function c(e,n){function l(e){s[n]=e,++o!==a||i||(i=true,r.resolve(u,s));}t.resolve(e).then(l,(function(e){i||(i=true,r.reject(u,e));}));}}function b(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var a=e.length,i=false;if(!a)return this.resolve([]);for(var s=-1,o=new this(n);++s<a;)l(e[s]);return o;function l(e){t.resolve(e).then((function(e){i||(i=true,r.resolve(o,e));}),(function(e){i||(i=true,r.reject(o,e));}));}}t.exports=u,u.prototype.catch=function(e){return this.then(null,e)},u.prototype.then=function(e,t){if("function"!=typeof e&&this.state===o||"function"!=typeof t&&this.state===s)return this;var a=new this.constructor(n);return this.state!==l?d(a,this.state===o?e:t,this.outcome):this.queue.push(new c(a,e,t)),a},c.prototype.callFulfilled=function(e){r.resolve(this.promise,e);},c.prototype.otherCallFulfilled=function(e){d(this.promise,this.onFulfilled,e);},c.prototype.callRejected=function(e){r.reject(this.promise,e);},c.prototype.otherCallRejected=function(e){d(this.promise,this.onRejected,e);},r.resolve=function(e,t){var a=f(p,t);if("error"===a.status)return r.reject(e,a.value);var i=a.value;if(i)h(e,i);else {e.state=o,e.outcome=t;for(var n=-1,s=e.queue.length;++n<s;)e.queue[n].callFulfilled(t);}return e},r.reject=function(e,t){e.state=s,e.outcome=t;for(var a=-1,i=e.queue.length;++a<i;)e.queue[a].callRejected(t);return e},u.resolve=m,u.reject=y,u.all=g,u.race=b;},{1:1}],3:[function(e,t,a){(function(t){"function"!=typeof t.Promise&&(t.Promise=e(2));}).call(this,void 0!==D?D:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});},{2:2}],4:[function(e,t,a){var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(){try{if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof webkitIndexedDB)return webkitIndexedDB;if("undefined"!=typeof mozIndexedDB)return mozIndexedDB;if("undefined"!=typeof OIndexedDB)return OIndexedDB;if("undefined"!=typeof msIndexedDB)return msIndexedDB}catch(e){return}}var s=r();function o(){try{if(!s||!s.open)return !1;var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),t="function"==typeof fetch&&-1!==fetch.toString().indexOf("[native code");return (!e||t)&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return false}}function l(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(n){if("TypeError"!==n.name)throw n;for(var a=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),i=0;i<e.length;i+=1)a.append(e[i]);return a.getBlob(t.type)}}"undefined"==typeof Promise&&e(3);var u=Promise;function c(e,t){t&&e.then((function(e){t(null,e);}),(function(e){t(e);}));}function d(e,t,a){"function"==typeof t&&e.then(t),"function"==typeof a&&e.catch(a);}function p(e){return "string"!=typeof e&&(console.warn(e+" used as a key, but it is not a string."),e=String(e)),e}function h(){if(arguments.length&&"function"==typeof arguments[arguments.length-1])return arguments[arguments.length-1]}var f="local-forage-detect-blob-support",m=void 0,y={},g=Object.prototype.toString,b="readonly",v="readwrite";function _(e){for(var t=e.length,a=new ArrayBuffer(t),i=new Uint8Array(a),n=0;n<t;n++)i[n]=e.charCodeAt(n);return a}function w(e){return new u((function(t){var a=e.transaction(f,v),i=l([""]);a.objectStore(f).put(i,"key"),a.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(false);},a.oncomplete=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),a=navigator.userAgent.match(/Edge\//);t(a||!e||parseInt(e[1],10)>=43);};})).catch((function(){return false}))}function A(e){return "boolean"==typeof m?u.resolve(m):w(e).then((function(e){return m=e}))}function k(e){var t=y[e.name],a={};a.promise=new u((function(e,t){a.resolve=e,a.reject=t;})),t.deferredOperations.push(a),t.dbReady?t.dbReady=t.dbReady.then((function(){return a.promise})):t.dbReady=a.promise;}function S(e){var t=y[e.name].deferredOperations.pop();if(t)return t.resolve(),t.promise}function N(e,t){var a=y[e.name].deferredOperations.pop();if(a)return a.reject(t),a.promise}function T(e,t){return new u((function(a,i){if(y[e.name]=y[e.name]||R(),e.db){if(!t)return a(e.db);k(e),e.db.close();}var n=[e.name];t&&n.push(e.version);var r=s.open.apply(s,n);t&&(r.onupgradeneeded=function(t){var a=r.result;try{a.createObjectStore(e.storeName),t.oldVersion<=1&&a.createObjectStore(f);}catch(a){if("ConstraintError"!==a.name)throw a;console.warn('The database "'+e.name+'" has been upgraded from version '+t.oldVersion+" to version "+t.newVersion+', but the storage "'+e.storeName+'" already exists.');}}),r.onerror=function(e){e.preventDefault(),i(r.error);},r.onsuccess=function(){var t=r.result;t.onversionchange=function(e){e.target.close();},a(t),S(e);};}))}function M(e){return T(e,false)}function x(e){return T(e,true)}function V(e,t){if(!e.db)return true;var a=!e.db.objectStoreNames.contains(e.storeName),i=e.version<e.db.version,n=e.version>e.db.version;if(i&&(e.version!==t&&console.warn('The database "'+e.name+"\" can't be downgraded from version "+e.db.version+" to version "+e.version+"."),e.version=e.db.version),n||a){if(a){var r=e.db.version+1;r>e.version&&(e.version=r);}return true}return false}function C(e){return new u((function(t,a){var i=new FileReader;i.onerror=a,i.onloadend=function(a){var i=btoa(a.target.result||"");t({__local_forage_encoded_blob:true,data:i,type:e.type});},i.readAsBinaryString(e);}))}function I(e){return l([_(atob(e.data))],{type:e.type})}function F(e){return e&&e.__local_forage_encoded_blob}function E(e){var t=this,a=t._initReady().then((function(){var e=y[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady}));return d(a,e,e),a}function D(e){k(e);for(var t=y[e.name],a=t.forages,i=0;i<a.length;i++){var n=a[i];n._dbInfo.db&&(n._dbInfo.db.close(),n._dbInfo.db=null);}return e.db=null,M(e).then((function(t){return e.db=t,V(e)?x(e):t})).then((function(i){e.db=t.db=i;for(var n=0;n<a.length;n++)a[n]._dbInfo.db=i;})).catch((function(t){throw N(e,t),t}))}function L(e,t,a,i){ void 0===i&&(i=1);try{var n=e.db.transaction(e.storeName,t);a(null,n);}catch(n){if(i>0&&(!e.db||"InvalidStateError"===n.name||"NotFoundError"===n.name))return u.resolve().then((function(){if(!e.db||"NotFoundError"===n.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),x(e)})).then((function(){return D(e).then((function(){L(e,t,a,i-1);}))})).catch(a);a(n);}}function R(){return {forages:[],db:null,dbReady:null,deferredOperations:[]}}function P(e){var t=this,a={db:null};if(e)for(var i in e)a[i]=e[i];var n=y[a.name];n||(n=R(),y[a.name]=n),n.forages.push(t),t._initReady||(t._initReady=t.ready,t.ready=E);var r=[];function s(){return u.resolve()}for(var o=0;o<n.forages.length;o++){var l=n.forages[o];l!==t&&r.push(l._initReady().catch(s));}var c=n.forages.slice(0);return u.all(r).then((function(){return a.db=n.db,M(a)})).then((function(e){return a.db=e,V(a,t._defaultConfig.version)?x(a):e})).then((function(e){a.db=n.db=e,t._dbInfo=a;for(var i=0;i<c.length;i++){var r=c[i];r!==t&&(r._dbInfo.db=a.db,r._dbInfo.version=a.version);}}))}function O(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){L(a._dbInfo,b,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName).get(e);s.onsuccess=function(){var e=s.result;void 0===e&&(e=null),F(e)&&(e=I(e)),t(e);},s.onerror=function(){i(s.error);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function B(e,t){var a=this,i=new u((function(t,i){a.ready().then((function(){L(a._dbInfo,b,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName).openCursor(),o=1;s.onsuccess=function(){var a=s.result;if(a){var i=a.value;F(i)&&(i=I(i));var n=e(i,a.key,o++);void 0!==n?t(n):a.continue();}else t();},s.onerror=function(){i(s.error);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function $(e,t,a){var i=this;e=p(e);var n=new u((function(a,n){var r;i.ready().then((function(){return r=i._dbInfo,"[object Blob]"===g.call(t)?A(r.db).then((function(e){return e?t:C(t)})):t})).then((function(t){L(i._dbInfo,v,(function(r,s){if(r)return n(r);try{var o=s.objectStore(i._dbInfo.storeName);null===t&&(t=void 0);var l=o.put(t,e);s.oncomplete=function(){void 0===t&&(t=null),a(t);},s.onabort=s.onerror=function(){var e=l.error?l.error:l.transaction.error;n(e);};}catch(e){n(e);}}));})).catch(n);}));return c(n,a),n}function j(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){L(a._dbInfo,v,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName).delete(e);r.oncomplete=function(){t();},r.onerror=function(){i(s.error);},r.onabort=function(){var e=s.error?s.error:s.transaction.error;i(e);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function U(e){var t=this,a=new u((function(e,a){t.ready().then((function(){L(t._dbInfo,v,(function(i,n){if(i)return a(i);try{var r=n.objectStore(t._dbInfo.storeName).clear();n.oncomplete=function(){e();},n.onabort=n.onerror=function(){var e=r.error?r.error:r.transaction.error;a(e);};}catch(e){a(e);}}));})).catch(a);}));return c(a,e),a}function z(e){var t=this,a=new u((function(e,a){t.ready().then((function(){L(t._dbInfo,b,(function(i,n){if(i)return a(i);try{var r=n.objectStore(t._dbInfo.storeName).count();r.onsuccess=function(){e(r.result);},r.onerror=function(){a(r.error);};}catch(e){a(e);}}));})).catch(a);}));return c(a,e),a}function W(e,t){var a=this,i=new u((function(t,i){e<0?t(null):a.ready().then((function(){L(a._dbInfo,b,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName),o=!1,l=s.openKeyCursor();l.onsuccess=function(){var a=l.result;a?0===e||o?t(a.key):(o=!0,a.advance(e)):t(null);},l.onerror=function(){i(l.error);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function Y(e){var t=this,a=new u((function(e,a){t.ready().then((function(){L(t._dbInfo,b,(function(i,n){if(i)return a(i);try{var r=n.objectStore(t._dbInfo.storeName).openKeyCursor(),s=[];r.onsuccess=function(){var t=r.result;t?(s.push(t.key),t.continue()):e(s);},r.onerror=function(){a(r.error);};}catch(e){a(e);}}));})).catch(a);}));return c(a,e),a}function H(e,t){t=h.apply(this,arguments);var a=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||a.name,e.storeName=e.storeName||a.storeName);var i,n=this;if(e.name){var r=e.name===a.name&&n._dbInfo.db?u.resolve(n._dbInfo.db):M(e).then((function(t){var a=y[e.name],i=a.forages;a.db=t;for(var n=0;n<i.length;n++)i[n]._dbInfo.db=t;return t}));i=e.storeName?r.then((function(t){if(t.objectStoreNames.contains(e.storeName)){var a=t.version+1;k(e);var i=y[e.name],n=i.forages;t.close();for(var r=0;r<n.length;r++){var o=n[r];o._dbInfo.db=null,o._dbInfo.version=a;}var l=new u((function(t,i){var n=s.open(e.name,a);n.onerror=function(e){n.result.close(),i(e);},n.onupgradeneeded=function(){n.result.deleteObjectStore(e.storeName);},n.onsuccess=function(){var e=n.result;e.close(),t(e);};}));return l.then((function(e){i.db=e;for(var t=0;t<n.length;t++){var a=n[t];a._dbInfo.db=e,S(a._dbInfo);}})).catch((function(t){throw (N(e,t)||u.resolve()).catch((function(){})),t}))}})):r.then((function(t){k(e);var a=y[e.name],i=a.forages;t.close();for(var n=0;n<i.length;n++)i[n]._dbInfo.db=null;var r=new u((function(t,a){var i=s.deleteDatabase(e.name);i.onerror=function(){var e=i.result;e&&e.close(),a(i.error);},i.onblocked=function(){console.warn('dropInstance blocked for database "'+e.name+'" until all open connections are closed');},i.onsuccess=function(){var e=i.result;e&&e.close(),t(e);};}));return r.then((function(e){a.db=e;for(var t=0;t<i.length;t++)S(i[t]._dbInfo);})).catch((function(t){throw (N(e,t)||u.resolve()).catch((function(){})),t}))}));}else i=u.reject("Invalid arguments");return c(i,t),i}var G={_driver:"asyncStorage",_initStorage:P,_support:o(),iterate:B,getItem:O,setItem:$,removeItem:j,clear:U,length:z,key:W,keys:Y,dropInstance:H};function q(){return "function"==typeof openDatabase}var Z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",J="~~local_forage_type~",K=/^~~local_forage_type~([^~]+)~/,X="__lfsc__:",Q=X.length,ee="arbf",te="blob",ae="si08",ie="ui08",ne="uic8",re="si16",se="si32",oe="ur16",le="ui32",ue="fl32",ce="fl64",de=Q+ee.length,pe=Object.prototype.toString;function he(e){var t,a,i,n,r,s=.75*e.length,o=e.length,l=0;"="===e[e.length-1]&&(s--,"="===e[e.length-2]&&s--);var u=new ArrayBuffer(s),c=new Uint8Array(u);for(t=0;t<o;t+=4)a=Z.indexOf(e[t]),i=Z.indexOf(e[t+1]),n=Z.indexOf(e[t+2]),r=Z.indexOf(e[t+3]),c[l++]=a<<2|i>>4,c[l++]=(15&i)<<4|n>>2,c[l++]=(3&n)<<6|63&r;return u}function fe(e){var t,a=new Uint8Array(e),i="";for(t=0;t<a.length;t+=3)i+=Z[a[t]>>2],i+=Z[(3&a[t])<<4|a[t+1]>>4],i+=Z[(15&a[t+1])<<2|a[t+2]>>6],i+=Z[63&a[t+2]];return a.length%3==2?i=i.substring(0,i.length-1)+"=":a.length%3==1&&(i=i.substring(0,i.length-2)+"=="),i}function me(e,t){var a="";if(e&&(a=pe.call(e)),e&&("[object ArrayBuffer]"===a||e.buffer&&"[object ArrayBuffer]"===pe.call(e.buffer))){var i,n=X;e instanceof ArrayBuffer?(i=e,n+=ee):(i=e.buffer,"[object Int8Array]"===a?n+=ae:"[object Uint8Array]"===a?n+=ie:"[object Uint8ClampedArray]"===a?n+=ne:"[object Int16Array]"===a?n+=re:"[object Uint16Array]"===a?n+=oe:"[object Int32Array]"===a?n+=se:"[object Uint32Array]"===a?n+=le:"[object Float32Array]"===a?n+=ue:"[object Float64Array]"===a?n+=ce:t(new Error("Failed to get type for BinaryArray"))),t(n+fe(i));}else if("[object Blob]"===a){var r=new FileReader;r.onload=function(){var a=J+e.type+"~"+fe(this.result);t(X+te+a);},r.readAsArrayBuffer(e);}else try{t(JSON.stringify(e));}catch(a){console.error("Couldn't convert value into a JSON string: ",e),t(null,a);}}function ye(e){if(e.substring(0,Q)!==X)return JSON.parse(e);var t,a=e.substring(de),i=e.substring(Q,de);if(i===te&&K.test(a)){var n=a.match(K);t=n[1],a=a.substring(n[0].length);}var r=he(a);switch(i){case ee:return r;case te:return l([r],{type:t});case ae:return new Int8Array(r);case ie:return new Uint8Array(r);case ne:return new Uint8ClampedArray(r);case re:return new Int16Array(r);case oe:return new Uint16Array(r);case se:return new Int32Array(r);case le:return new Uint32Array(r);case ue:return new Float32Array(r);case ce:return new Float64Array(r);default:throw new Error("Unkown type: "+i)}}var ge={serialize:me,deserialize:ye,stringToBuffer:he,bufferToString:fe};function be(e,t,a,i){e.executeSql("CREATE TABLE IF NOT EXISTS "+t.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],a,i);}function ve(e){var t=this,a={db:null};if(e)for(var i in e)a[i]="string"!=typeof e[i]?e[i].toString():e[i];var n=new u((function(e,i){try{a.db=openDatabase(a.name,String(a.version),a.description,a.size);}catch(e){return i(e)}a.db.transaction((function(n){be(n,a,(function(){t._dbInfo=a,e();}),(function(e,t){i(t);}));}),i);}));return a.serializer=ge,n}function _e(e,t,a,i,n,r){e.executeSql(a,i,n,(function(e,s){s.code===s.SYNTAX_ERR?e.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[t.storeName],(function(e,o){o.rows.length?r(e,s):be(e,t,(function(){e.executeSql(a,i,n,r);}),r);}),r):r(e,s);}),r);}function we(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"SELECT * FROM "+n.storeName+" WHERE key = ? LIMIT 1",[e],(function(e,a){var i=a.rows.length?a.rows.item(0).value:null;i&&(i=n.serializer.deserialize(i)),t(i);}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function Ae(e,t){var a=this,i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"SELECT * FROM "+n.storeName,[],(function(a,i){for(var r=i.rows,s=r.length,o=0;o<s;o++){var l=r.item(o),u=l.value;if(u&&(u=n.serializer.deserialize(u)),void 0!==(u=e(u,l.key,o+1)))return void t(u)}t();}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function ke(e,t,a,i){var n=this;e=p(e);var r=new u((function(r,s){n.ready().then((function(){ void 0===t&&(t=null);var o=t,l=n._dbInfo;l.serializer.serialize(t,(function(t,u){u?s(u):l.db.transaction((function(a){_e(a,l,"INSERT OR REPLACE INTO "+l.storeName+" (key, value) VALUES (?, ?)",[e,t],(function(){r(o);}),(function(e,t){s(t);}));}),(function(t){if(t.code===t.QUOTA_ERR){if(i>0)return void r(ke.apply(n,[e,o,a,i-1]));s(t);}}));}));})).catch(s);}));return c(r,a),r}function Se(e,t,a){return ke.apply(this,[e,t,a,1])}function Ne(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"DELETE FROM "+n.storeName+" WHERE key = ?",[e],(function(){t();}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function Te(e){var t=this,a=new u((function(e,a){t.ready().then((function(){var i=t._dbInfo;i.db.transaction((function(t){_e(t,i,"DELETE FROM "+i.storeName,[],(function(){e();}),(function(e,t){a(t);}));}));})).catch(a);}));return c(a,e),a}function Me(e){var t=this,a=new u((function(e,a){t.ready().then((function(){var i=t._dbInfo;i.db.transaction((function(t){_e(t,i,"SELECT COUNT(key) as c FROM "+i.storeName,[],(function(t,a){var i=a.rows.item(0).c;e(i);}),(function(e,t){a(t);}));}));})).catch(a);}));return c(a,e),a}function xe(e,t){var a=this,i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"SELECT key FROM "+n.storeName+" WHERE id = ? LIMIT 1",[e+1],(function(e,a){var i=a.rows.length?a.rows.item(0).key:null;t(i);}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function Ve(e){var t=this,a=new u((function(e,a){t.ready().then((function(){var i=t._dbInfo;i.db.transaction((function(t){_e(t,i,"SELECT key FROM "+i.storeName,[],(function(t,a){for(var i=[],n=0;n<a.rows.length;n++)i.push(a.rows.item(n).key);e(i);}),(function(e,t){a(t);}));}));})).catch(a);}));return c(a,e),a}function Ce(e){return new u((function(t,a){e.transaction((function(i){i.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'",[],(function(a,i){for(var n=[],r=0;r<i.rows.length;r++)n.push(i.rows.item(r).name);t({db:e,storeNames:n});}),(function(e,t){a(t);}));}),(function(e){a(e);}));}))}function Ie(e,t){t=h.apply(this,arguments);var a=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||a.name,e.storeName=e.storeName||a.storeName);var i,n=this;return c(i=e.name?new u((function(t){var i;i=e.name===a.name?n._dbInfo.db:openDatabase(e.name,"","",0),e.storeName?t({db:i,storeNames:[e.storeName]}):t(Ce(i));})).then((function(e){return new u((function(t,a){e.db.transaction((function(i){function n(e){return new u((function(t,a){i.executeSql("DROP TABLE IF EXISTS "+e,[],(function(){t();}),(function(e,t){a(t);}));}))}for(var r=[],s=0,o=e.storeNames.length;s<o;s++)r.push(n(e.storeNames[s]));u.all(r).then((function(){t();})).catch((function(e){a(e);}));}),(function(e){a(e);}));}))})):u.reject("Invalid arguments"),t),i}var Fe={_driver:"webSQLStorage",_initStorage:ve,_support:q(),iterate:Ae,getItem:we,setItem:Se,removeItem:Ne,clear:Te,length:Me,key:xe,keys:Ve,dropInstance:Ie};function Ee(){try{return "undefined"!=typeof localStorage&&"setItem"in localStorage&&!!localStorage.setItem}catch(e){return false}}function De(e,t){var a=e.name+"/";return e.storeName!==t.storeName&&(a+=e.storeName+"/"),a}function Le(){var e="_localforage_support_test";try{return localStorage.setItem(e,!0),localStorage.removeItem(e),!1}catch(e){return true}}function Re(){return !Le()||localStorage.length>0}function Pe(e){var t=this,a={};if(e)for(var i in e)a[i]=e[i];return a.keyPrefix=De(e,t._defaultConfig),Re()?(t._dbInfo=a,a.serializer=ge,u.resolve()):u.reject()}function Oe(e){var t=this,a=t.ready().then((function(){for(var e=t._dbInfo.keyPrefix,a=localStorage.length-1;a>=0;a--){var i=localStorage.key(a);0===i.indexOf(e)&&localStorage.removeItem(i);}}));return c(a,e),a}function Be(e,t){var a=this;e=p(e);var i=a.ready().then((function(){var t=a._dbInfo,i=localStorage.getItem(t.keyPrefix+e);return i&&(i=t.serializer.deserialize(i)),i}));return c(i,t),i}function $e(e,t){var a=this,i=a.ready().then((function(){for(var t=a._dbInfo,i=t.keyPrefix,n=i.length,r=localStorage.length,s=1,o=0;o<r;o++){var l=localStorage.key(o);if(0===l.indexOf(i)){var u=localStorage.getItem(l);if(u&&(u=t.serializer.deserialize(u)),void 0!==(u=e(u,l.substring(n),s++)))return u}}}));return c(i,t),i}function je(e,t){var a=this,i=a.ready().then((function(){var t,i=a._dbInfo;try{t=localStorage.key(e);}catch(e){t=null;}return t&&(t=t.substring(i.keyPrefix.length)),t}));return c(i,t),i}function Ue(e){var t=this,a=t.ready().then((function(){for(var e=t._dbInfo,a=localStorage.length,i=[],n=0;n<a;n++){var r=localStorage.key(n);0===r.indexOf(e.keyPrefix)&&i.push(r.substring(e.keyPrefix.length));}return i}));return c(a,e),a}function ze(e){var t=this.keys().then((function(e){return e.length}));return c(t,e),t}function We(e,t){var a=this;e=p(e);var i=a.ready().then((function(){var t=a._dbInfo;localStorage.removeItem(t.keyPrefix+e);}));return c(i,t),i}function Ye(e,t,a){var i=this;e=p(e);var n=i.ready().then((function(){ void 0===t&&(t=null);var a=t;return new u((function(n,r){var s=i._dbInfo;s.serializer.serialize(t,(function(t,i){if(i)r(i);else try{localStorage.setItem(s.keyPrefix+e,t),n(a);}catch(e){"QuotaExceededError"!==e.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==e.name||r(e),r(e);}}));}))}));return c(n,a),n}function He(e,t){if(t=h.apply(this,arguments),!(e="function"!=typeof e&&e||{}).name){var a=this.config();e.name=e.name||a.name,e.storeName=e.storeName||a.storeName;}var i,n=this;return i=e.name?new u((function(t){e.storeName?t(De(e,n._defaultConfig)):t(e.name+"/");})).then((function(e){for(var t=localStorage.length-1;t>=0;t--){var a=localStorage.key(t);0===a.indexOf(e)&&localStorage.removeItem(a);}})):u.reject("Invalid arguments"),c(i,t),i}var Ge={_driver:"localStorageWrapper",_initStorage:Pe,_support:Ee(),iterate:$e,getItem:Be,setItem:Ye,removeItem:We,clear:Oe,length:ze,key:je,keys:Ue,dropInstance:He},qe=function(e,t){return e===t||"number"==typeof e&&"number"==typeof t&&isNaN(e)&&isNaN(t)},Ze=function(e,t){for(var a=e.length,i=0;i<a;){if(qe(e[i],t))return true;i++;}return false},Je=Array.isArray||function(e){return "[object Array]"===Object.prototype.toString.call(e)},Ke={},Xe={},Qe={INDEXEDDB:G,WEBSQL:Fe,LOCALSTORAGE:Ge},et=[Qe.INDEXEDDB._driver,Qe.WEBSQL._driver,Qe.LOCALSTORAGE._driver],tt=["dropInstance"],at=["clear","getItem","iterate","key","keys","length","removeItem","setItem"].concat(tt),it={description:"",driver:et.slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1};function nt(e,t){e[t]=function(){var a=arguments;return e.ready().then((function(){return e[t].apply(e,a)}))};}function rt(){for(var e=1;e<arguments.length;e++){var t=arguments[e];if(t)for(var a in t)t.hasOwnProperty(a)&&(Je(t[a])?arguments[0][a]=t[a].slice():arguments[0][a]=t[a]);}return arguments[0]}var st=function(){function e(t){for(var a in n(this,e),Qe)if(Qe.hasOwnProperty(a)){var i=Qe[a],r=i._driver;this[a]=r,Ke[r]||this.defineDriver(i);}this._defaultConfig=rt({},it),this._config=rt({},this._defaultConfig,t),this._driverSet=null,this._initDriver=null,this._ready=false,this._dbInfo=null,this._wrapLibraryMethodsWithReady(),this.setDriver(this._config.driver).catch((function(){}));}return e.prototype.config=function(e){if("object"===(void 0===e?"undefined":i(e))){if(this._ready)return new Error("Can't call config() after localforage has been used.");for(var t in e){if("storeName"===t&&(e[t]=e[t].replace(/\W/g,"_")),"version"===t&&"number"!=typeof e[t])return new Error("Database version must be a number.");this._config[t]=e[t];}return !("driver"in e)||!e.driver||this.setDriver(this._config.driver)}return "string"==typeof e?this._config[e]:this._config},e.prototype.defineDriver=function(e,t,a){var i=new u((function(t,a){try{var i=e._driver,n=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!e._driver)return void a(n);for(var r=at.concat("_initStorage"),s=0,o=r.length;s<o;s++){var l=r[s];if((!Ze(tt,l)||e[l])&&"function"!=typeof e[l])return void a(n)}var d=function(){for(var t=function(e){return function(){var t=new Error("Method "+e+" is not implemented by the current driver"),a=u.reject(t);return c(a,arguments[arguments.length-1]),a}},a=0,i=tt.length;a<i;a++){var n=tt[a];e[n]||(e[n]=t(n));}};d();var p=function(a){Ke[i]&&console.info("Redefining LocalForage driver: "+i),Ke[i]=e,Xe[i]=a,t();};"_support"in e?e._support&&"function"==typeof e._support?e._support().then(p,a):p(!!e._support):p(!0);}catch(e){a(e);}}));return d(i,t,a),i},e.prototype.driver=function(){return this._driver||null},e.prototype.getDriver=function(e,t,a){var i=Ke[e]?u.resolve(Ke[e]):u.reject(new Error("Driver not found."));return d(i,t,a),i},e.prototype.getSerializer=function(e){var t=u.resolve(ge);return d(t,e),t},e.prototype.ready=function(e){var t=this,a=t._driverSet.then((function(){return null===t._ready&&(t._ready=t._initDriver()),t._ready}));return d(a,e,e),a},e.prototype.setDriver=function(e,t,a){var i=this;Je(e)||(e=[e]);var n=this._getSupportedDrivers(e);function r(){i._config.driver=i.driver();}function s(e){return i._extend(e),r(),i._ready=i._initStorage(i._config),i._ready}function o(e){return function(){var t=0;function a(){for(;t<e.length;){var n=e[t];return t++,i._dbInfo=null,i._ready=null,i.getDriver(n).then(s).catch(a)}r();var o=new Error("No available storage method found.");return i._driverSet=u.reject(o),i._driverSet}return a()}}var l=null!==this._driverSet?this._driverSet.catch((function(){return u.resolve()})):u.resolve();return this._driverSet=l.then((function(){var e=n[0];return i._dbInfo=null,i._ready=null,i.getDriver(e).then((function(e){i._driver=e._driver,r(),i._wrapLibraryMethodsWithReady(),i._initDriver=o(n);}))})).catch((function(){r();var e=new Error("No available storage method found.");return i._driverSet=u.reject(e),i._driverSet})),d(this._driverSet,t,a),this._driverSet},e.prototype.supports=function(e){return !!Xe[e]},e.prototype._extend=function(e){rt(this,e);},e.prototype._getSupportedDrivers=function(e){for(var t=[],a=0,i=e.length;a<i;a++){var n=e[a];this.supports(n)&&t.push(n);}return t},e.prototype._wrapLibraryMethodsWithReady=function(){for(var e=0,t=at.length;e<t;e++)nt(this,at[e]);},e.prototype.createInstance=function(t){return new e(t)},e}(),ot=new st;t.exports=ot;},{3:3}]},{},[4])(4)),Ki.exports),Qi=L$1(Xi);let en$1 = class en{databaseName;collectionName;size;_store;constructor(e,t,a){Qi.config({driver:Qi.INDEXEDDB}),this.databaseName=e||"lumino-cache",this.collectionName=t||"data",this.size=a,this._store=Qi.createInstance({name:this.databaseName,storeName:this.collectionName});}async init(){}async _keys(){return this._store.keys()}async _set(e,t){return this._store.setItem(e,t)}async _clear(){return this._store.clear()}async _get(e){return this._store.getItem(e)}async _remove(e){return this._store.removeItem(e)}};function tn(e){let t,a,i,n;e.onmessage=async r=>{const s=r.data;try{switch(s.type){case "init":{i=s.databaseName,n=s.collectionName,t=await navigator.storage.getDirectory();const r=await t.getDirectoryHandle(i,{create:!0});a=await r.getDirectoryHandle(n,{create:!0}),e.postMessage({type:s.type,database:i,collection:n,success:!0});break}case "write":{if(!a)throw new Error("OPFS Worker: not initialized yet!");const t=await a.getFileHandle(s.filename,{create:!0}),r=await t.createSyncAccessHandle();let o;if("string"==typeof s.content){o=(new TextEncoder).encode(s.content).buffer;}else if(s.content instanceof ArrayBuffer)o=s.content;else {if(!(s.content instanceof Blob))throw new Error("OPFS Worker: Unsupported content type: "+typeof s.content);o=await s.content.arrayBuffer();}r.truncate(o.byteLength),r.write(o,{at:0}),await r.flush(),r.close(),e.postMessage({type:s.type,database:i,collection:n,success:!0});break}}}catch(t){e.postMessage({type:s.type,success:false,database:i,collection:n,error:t.message});}};}let an$1 = class an{databaseName;collectionName;size;_worker;_storage;_root;constructor(e,t,a){this.databaseName=e||"lumino-cache",this.collectionName=t||"data",this.size=a;}async init(){if("object"==typeof globalThis.navigator&&"storage"in globalThis.navigator&&"function"==typeof globalThis.navigator.storage.getDirectory){this._storage=await navigator.storage.getDirectory();const e=await this._storage.getDirectoryHandle(this.databaseName,{create:true});let t,a;this._root=await e.getDirectoryHandle(this.collectionName,{create:true}),this._worker=new Worker(URL.createObjectURL(new Blob(["(",tn.toString(),")(self)"],{type:"application/javascript"})),{type:"module"});let i=new Promise(((e,i)=>{t=e,a=i;}));return this._worker.onmessage=e=>{const i=e.data;i.success||console.error("OPFS Worker failed:",i),"init"===i.type&&(i.success?t():a(i.error));},this._worker.postMessage({type:"init",databaseName:this.databaseName,collectionName:this.collectionName}),i}}async _keys(){if(!this._root)return [];const e=[];for await(const t of this._root.values())e.push(t.name);return e}async _set(e,t){if(!this._root)return;let a;if(t instanceof Blob)a=t;else if("object"==typeof t){const e=JSON.stringify(t,null,2);a=new Blob([e],{type:"application/json"});}else a=new Blob([t],{type:"text/plain"});const i=await this._root.getFileHandle(e,{create:true});if("function"==typeof i.createWritable){const e=await i.createWritable();await e.write(a),await e.close();}else this._worker.postMessage({type:"write",filename:e,content:a});}async _clear(){if(!this._root)return;const e=[];for await(const t of this._root.values())e.push(this._root.removeEntry(t.name));return Promise.all(e)}async _get(e,t){if(!this._root)return null;let a;try{const t=await this._root.getFileHandle(e);a=await t.getFile();}catch(e){return null}switch(t=t||a.type){case "text/plain":return a.text();case "application/json":{const e=await a.text();try{return JSON.parse(e)}catch(t){return console.error("Content was loaded from cache but could not be json parsed: ",e),null}}default:return a}}async _remove(e){if(this._root)return this._root.removeEntry(e)}};let nn$1 = class nn{databaseName;collectionName;size;type;_impl;constructor(e,t,a=0,i=1){switch(this.databaseName=e||"lumino",this.collectionName=t||"data",this.size=1048576*(i||1),this.type=a,this.type){case 0:this._impl=new en$1(this.databaseName,this.collectionName,this.size);break;case 1:this._impl=new an$1(this.databaseName,this.collectionName,this.size);break;default:throw "Invalid storage type: "+a}}async init(){return this._impl.init()}async _keys(){return this._impl._keys()}fixKey(e){return e.replaceAll("/","_")}async _set(e,t){return this._impl._set(this.fixKey(e),t)}async _clear(){return this._impl._clear()}async _get(e,t){return this._impl._get(this.fixKey(e),t)}async _remove(e){return this._impl._remove(this.fixKey(e))}};var rn$1,sn$1,on$2,ln,un,cn$1,dn$1,pn$1,hn,fn,mn$1,yn$1,gn,bn$1,vn,_n,wn$1,An,kn,Sn,Nn,Tn,Mn,xn$1,Vn$1,Cn$1,In,Fn;function En(){if(sn$1)return rn$1;return sn$1=1,rn$1=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}}function Dn$1(){if(cn$1)return un;cn$1=1;var e=function(){if(ln)return on$2;ln=1;var e="object"==typeof D&&D&&D.Object===Object&&D;return on$2=e}(),t="object"==typeof self&&self&&self.Object===Object&&self,a=e||t||Function("return this")();return un=a}function Ln(){if(yn$1)return mn$1;yn$1=1;var e=function(){if(fn)return hn;fn=1;var e=/\s/;return hn=function(t){for(var a=t.length;a--&&e.test(t.charAt(a)););return a}}(),t=/^\s+/;return mn$1=function(a){return a?a.slice(0,e(a)+1).replace(t,""):a}}function Rn(){if(bn$1)return gn;bn$1=1;var e=Dn$1().Symbol;return gn=e}function Pn(){if(Sn)return kn;Sn=1;var e=Rn(),t=function(){if(_n)return vn;_n=1;var e=Rn(),t=Object.prototype,a=t.hasOwnProperty,i=t.toString,n=e?e.toStringTag:void 0;return vn=function(e){var t=a.call(e,n),r=e[n];try{e[n]=void 0;var s=!0;}catch(e){}var o=i.call(e);return s&&(t?e[n]=r:delete e[n]),o}}(),a=function(){if(An)return wn$1;An=1;var e=Object.prototype.toString;return wn$1=function(t){return e.call(t)}}(),i=e?e.toStringTag:void 0;return kn=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":i&&i in Object(e)?t(e):a(e)}}function On(){if(xn$1)return Mn;xn$1=1;var e=Pn(),t=Tn?Nn:(Tn=1,Nn=function(e){return null!=e&&"object"==typeof e});return Mn=function(a){return "symbol"==typeof a||t(a)&&"[object Symbol]"==e(a)}}var Bn=function(){if(Fn)return In;Fn=1;var e=En(),t=function(){if(pn$1)return dn$1;pn$1=1;var e=Dn$1();return dn$1=function(){return e.Date.now()}}(),a=function(){if(Cn$1)return Vn$1;Cn$1=1;var e=Ln(),t=En(),a=On(),i=/^[-+]0x[0-9a-f]+$/i,n=/^0b[01]+$/i,r=/^0o[0-7]+$/i,s=parseInt;return Vn$1=function(o){if("number"==typeof o)return o;if(a(o))return NaN;if(t(o)){var l="function"==typeof o.valueOf?o.valueOf():o;o=t(l)?l+"":l;}if("string"!=typeof o)return 0===o?o:+o;o=e(o);var u=n.test(o);return u||r.test(o)?s(o.slice(2),u?2:8):i.test(o)?NaN:+o}}(),i=Math.max,n=Math.min;return In=function(r,s,o){var l,u,c,d,p,h,f=0,m=false,y=false,g=true;if("function"!=typeof r)throw new TypeError("Expected a function");function b(e){var t=l,a=u;return l=u=void 0,f=e,d=r.apply(a,t)}function v(e){var t=e-h;return void 0===h||t>=s||t<0||y&&e-f>=c}function _(){var e=t();if(v(e))return w(e);p=setTimeout(_,function(e){var t=s-(e-h);return y?n(t,c-(e-f)):t}(e));}function w(e){return p=void 0,g&&l?b(e):(l=u=void 0,d)}function A(){var e=t(),a=v(e);if(l=arguments,u=this,h=e,a){if(void 0===p)return function(e){return f=e,p=setTimeout(_,s),m?b(e):d}(h);if(y)return clearTimeout(p),p=setTimeout(_,s),b(h)}return void 0===p&&(p=setTimeout(_,s)),d}return s=a(s)||0,e(o)&&(m=!!o.leading,c=(y="maxWait"in o)?i(a(o.maxWait)||0,s):c,g="trailing"in o?!!o.trailing:g),A.cancel=function(){ void 0!==p&&clearTimeout(p),f=0,l=h=u=p=void 0;},A.flush=function(){return void 0===p?d:w(t())},A}}(),$n=L$1(Bn);class jn extends nn$1{apiClient;cache=new Map;urlToIdMap=new Map;logging=false;ready=false;usePublicApi=false;quota=0;size=0;usePersistentStorage=false;saveIndex;constructor(e,t,a,i){if(super("lumino","items",1),!a)throw "A lumino client needs to be passed.";this.apiClient=a,this.usePublicApi=e,this.quota=1048576*(i||1024),this.usePersistentStorage=t;this.saveIndex=$n((()=>{const e=[];for(const t of this.cache.values())e.push({id:t.id,time:t.time.valueOf(),size:t.size,hash:t.hash,itemType:t.itemType,mimeType:t.mimeType,itemName:t.itemName});this._set("index",e).then((function(){})).catch((function(e){console.error("Error saving cache index: "+e);}));}),1e3);}async init(){return await super.init(),this.initFromStorage()}getQuota(){return this.quota}setQuota(e){this.quota=e,this.checkQuota();}getCount(){return this.cache.size}getSize(){return this.size}async initFromStorage(){if(this.usePersistentStorage){const e=await this._get("index","application/json");if(e&&Array.isArray(e))for(const t of e)t.time=j(t.time),this.cache.set(t.id,t),this.size+=t.size;else await this._clear(),this.saveIndex();}this.ready=true,u$3.$emit("itemCache:cacheReady"),u$3.$emit("itemCache:cacheChange"),u$3.$on("item:rename",(e=>this.handleRename(e)));}async addToStorage(e,t){if(this.usePersistentStorage){const a={id:e.id,time:j(e.time.toDate()),size:e.size,hash:e.hash,itemType:e.itemType,mimeType:e.mimeType,itemName:e.itemName};await this._set(`blob_${e.id}`,t),this.cache.set(e.id,a),this.saveIndex();}this.size+=e.size;}waitUntilReady(){const e=this;return new Promise(((t,a)=>{try{e.ready?t():u$3.$on("itemCache:cacheReady",(()=>{t();}));}catch(e){a(e);}}))}findObject(e){return this.cache.get(e)}getEntries(){return this.cache.values()}clear(){for(const e of this.cache.values())e.objectUrl&&URL.revokeObjectURL(e.objectUrl);this.cache.clear(),u$3.$emit("itemCache:cacheChange"),this.usePersistentStorage&&this._clear().then((function(){console.log("Cache storage cleared.");})).catch((function(e){console.error(e);}));}clearMemory(){for(let e of this.cache.values())e.objectUrl&&(URL.revokeObjectURL(e.objectUrl),delete e.objectUrl);u$3.$emit("itemCache:cacheChange");}checkQuota(e=0){let t=this.size+e;if(t>this.quota){const e=[...this.cache.entries()].sort((function(e,t){return e[1].time.valueOf()-t[1].time.valueOf()}));let a=0;for(;t>this.quota&&a<e.length;){const i=e[a][1];i.objectUrl||(t-=i.size,this.removeObjectFromCache(i.id)),a++;}}}removeObjectFromCache(e){const t=this.cache.get(e);t&&(t.objectUrl&&URL.revokeObjectURL(t.objectUrl),this.cache.delete(e),this.size-=t.size,this.usePersistentStorage&&(this._remove(`blob_${t.id}`).then((function(){console.log(`Removed blob for ${e} from cache`);})).catch((function(t){console.error(`Error removing blob for ${e} from cache: ${t}`);})),this.saveIndex()));}getIdFromUrl(e){return this.urlToIdMap.has(e)?this.urlToIdMap.get(e):null}getById(e){const t=this.findObject(e);return t?(this.logging&&console.log("Retrieving from cache: "+e),t.time=j(),t):(this.logging&&console.error("Object not in cache: "+e),null)}getObjectUrl(e){const t=this.getIdFromUrl(e);if(!t)return console.error("Could not find URL in cache: "+e),"";const a=this.getById(t);return a?a.objectUrl:(console.error("Could not find Id in cache: "+t),"")}async getBufferById(e){const t=await this.getBlobById(e);return t?await new Response(t).arrayBuffer():null}async getBlobById(e){const t=this.getById(e);return t?await fetch(t.objectUrl).then((e=>e.blob())):null}async loadFromStorage(e){if(e.objectUrl)return true;let t=null;return !!this.usePersistentStorage&&(t=await this._get(`blob_${e.id}`),!!t&&(e.objectUrl=URL.createObjectURL(t),e.time=j(),this.saveIndex(),u$3.$emit("itemCache:cacheChange"),true))}getCacheKey(e,t){return t&&"item"!==t.type?e+"_lod"+t.index:e}_getLodLevelUrl(e,t){let a;return a=t&&"item"!==t.type?this.apiClient.getAttachmentDownloadUrl(e,"lod",t.index):this.apiClient.getDownloadUrl(e),a}async loadItem(e,t,a){let i=0;for(;;)try{let i;if(this.usePublicApi)i=t&&"item"!==t.type?await this.apiClient.downloadPublicAttachment(e,"lod",t.index,void 0,a):await this.apiClient.publicDownloadItem(e,a);else try{i=t&&"item"!==t.type?await this.apiClient.downloadAttachment(e,"lod",t.index,void 0,a):await this.apiClient.downloadItem(e,a);}catch{i=t&&"item"!==t.type?await this.apiClient.downloadPublicAttachment(e,"lod",t.index,void 0,a):await this.apiClient.publicDownloadItem(e,a);}return i}catch(t){if(console.log(t),i++,!(i<3))return u$3.$emit("client:fatalError",`Failed to download item ${e}`),null;console.debug(`Failed attempts to download item ${e}: ${i}. Trying again...`);}}async addItemToCache(e,t,a,i){try{const n=this.getCacheKey(e,t),r=this.findObject(n);if(r&&(a||!this.apiClient.getItemHash||this.usePublicApi||(a=await this.apiClient.getItemHash(e)),a&&r.hash===a&&(this.logging&&console.log("Item already in cache: "+e),await this.loadFromStorage(r))))return r.url||(r.url=this._getLodLevelUrl(e,t)),this.urlToIdMap.set(r.url,n),this.cache.set(n,r),r;i&&i(0);let s=await this.loadItem(e,t,i);if(!s)return console.error("Was not able to load object into cache: "+n),null;i&&i(100);const o=this._getLodLevelUrl(e,t),l=URL.createObjectURL(s.blob),c={id:n,url:o,time:j(),objectUrl:l,size:s.blob.size,hash:s.hash,itemType:s.itemType,mimeType:s.mimeType,itemName:s.itemName};return this.checkQuota(c.size),await this.addToStorage(c,s.blob),this.cache.set(n,c),this.urlToIdMap.set(o,n),this.saveIndex(),u$3.$emit("itemCache:cacheChange"),this.logging&&console.log("Added item to cache: ",c),c}catch(e){return console.error(e),null}}getObjectCount(){return this.cache.size}getObjectSize(){let e=0;for(const t of this.cache.values())e+=t.size;return e}handleRename({id:e,newName:t}){const a=this.cache.get(e);a&&(a.itemName=t,this.saveIndex(),u$3.$emit("itemCache:cacheChange"));}}let Un$1 = class Un extends nn$1{apiClient;ready=false;maxNumItems=1e4;constructor(e){if(super("lumino","folders",1),!e)throw "A lumino client needs to be passed.";this.apiClient=e;}async init(){await super.init(),await this.checkStorage(),this.ready=true;}clear(){return this._clear()}async checkStorage(){const e=await this._keys();let t=e.length-this.maxNumItems;if(t>0){t=Math.floor(this.maxNumItems/2);const a=[];for(let i=0;i<t;i++)a.push(this._remove(e[i]));await Promise.all(a);}}async getFolderListing(e){return this.ready?this._get(e,"application/json"):null}async getItemListing(e){if(!this.ready)return null;const t=await this._get("items_"+e,"application/json");if(!t)return null;const a=await this.getFolderListing(e);return a&&a.parent&&new Date(t.cachedAt).getTime()>new Date(a.parent.updatedAt).getTime()?t.data:null}async getFolderACLs(e,t){if(!this.ready)return null;const a=await this._get("acl_"+e,"application/json");return a&&Date.now()-a.cachedAt<t?(delete a.cachedAt,a):null}async refreshCacheForFolder(e){const t=await this.getFolderListing(e);await this.addFolderListing(e,t);}async addFolderListing(e,t){this.ready&&(await this._set(e,{...t,cachedAt:new Date}),await this.checkStorage());}async addItemListing(e,t){this.ready&&(await this._set("items_"+e,{data:t,cachedAt:new Date}),await this.checkStorage());}async addACL(e,t){this.ready&&(await this._set("acl_"+e,{...t,cachedAt:new Date}),await this.checkStorage());}};class zn extends nn$1{apiClient;constructor(e){if(super("lumino","thumbs",1),!e)throw "A lumino client needs to be passed.";this.apiClient=e;}clear(){this._clear();}async _loadThumbnail(e,t){try{return await this.apiClient.getThumbnail(e,t)}catch{try{return await this.apiClient.getPublicThumbnail(e,t)}catch{return null}}}async get(e,t,a,i){if(!t)throw "Cannot retrieve item thumbnail from cache without knowing size!";let n=await this._get(e,"application/json");if(n&&n.hash===a&&n.timestamp===i){for(const e of n.thumbnails)if(e.size===t){if(e.data)return e.data;n.thumbnails.removeObject(e);break}let a=await this._loadThumbnail(t,e);return a&&(n.thumbnails.push({size:t,data:a}),await this._set(e,n)),a}let r=await this._loadThumbnail(t,e);if(a||i){let s=[];r&&s.push({size:t,data:r}),n={id:e,hash:a,timestamp:i,thumbnails:s},await this._set(e,n);}return r}}class Wn{apiClient;cache=new Map;constructor(e){this.apiClient=e,this.cache=new Map;}async resolve(e){let t=this.cache.get(e);if(!t)try{t=this.apiClient.getUserPublicInfo(e,this.apiClient.requestClientId,32),this.cache.set(e,t);}catch(e){console.error(e);}return t}}class Yn{apiClient;cache=new Map;constructor(e){this.apiClient=e;}async resolve(e){let t=this.cache.get(e);if(!t)try{t=this.apiClient.getGroupPublicInfo(e,this.apiClient.requestClientId,32),this.cache.set(e,t);}catch(e){console.error(e);}return t}}class Hn{apiClient;cache=new Map;constructor(e){this.apiClient=e;}async get(e,t,a,i,n=false){const r=`${e}_${t}_${a}${ void 0===i?"":`_${i}`}`,s=this.cache.get(r);if(s)return s;try{const s=new Promise((async r=>{try{let s;s=n?await this.apiClient.downloadPublicAttachment(e,t,a,i,void 0):await this.apiClient.downloadAttachmentPOP(e,t,a,i,void 0);r(URL.createObjectURL(s.blob));}catch(e){r(null);}}));return this.cache.set(r,s),s}catch(e){return console.warn(`Attachment ${r} not available.`),null}}invalidateAttachment(e,t,a,i){let n=`${e}_${t}`;null!=a&&(n+=`_${a}`);for(const e of this.cache.keys()){const t=null==i||e.endsWith(`_${i}`);e.startsWith(n)&&t&&this.cache.delete(e);}}}class Gn{apiClient;itemRepo;jobManager;items=[];hasExternalResources=false;totalSize=0;affectedFolderIds=new Set;constructor(e){this.apiClient=e,this.itemRepo=e.getItemRepo(),this.jobManager=e.getJobManager();}_updateQuota(){this.apiClient.eventBus.$emit("quota:update");}async getPreviousVersions(e,t){const a=[];t=t||"published";const i=await this.apiClient.createFolder({name:t,parent:e,returnIfExists:true}),n=await this.apiClient.getFoldersInFolderList(i,{folderAsItemType:"Package"});for(const e of n.children)e.item&&a.push({itemId:e.item._id,folderId:e._id,version:e.name,name:e.item.name,filesize:0|e.item.filesize,visibility:e.item.visibility});return a}async verify(e){const t=this,a=new Map,i=new Map;e=e?await this.itemRepo.loadItem(e._id,{recursive:true}):this.itemRepo.activeItem;const n=await r(e.folder);async function r(e){try{if(e){const a=e._id?e._id:e;if(i.has(a))return i.get(a);{const e=(await t.apiClient.getFolderPath(a)).path;return i.set(a,e),e}}return "/"}catch{return ""}}await this.itemRepo.traverseItems((async function(e){const t={_id:e._id,name:e.name,type:e.type,size:e.totalSize,path:await r(e.folder),item:e,external:false};t.path.startsWith(n)?t.path=t.path.slice(n.length):t.external=true,a.set(e._id,t);})),this.items=Array.from(a.values()),this.hasExternalResources=false,this.totalSize=0;for(const e of this.items)e.external&&(this.hasExternalResources=true),this.totalSize+=e.size;return !this.hasExternalResources}getItems(){return this.items}async unpackToProject(e,t,a,i){a&&(t=await this.apiClient.createFolder({name:a,parent:t,returnIfExists:true}));const n=await this.apiClient.getItem(e);n.folder===t&&await this.apiClient.renameItem(e,n.name+" (Unpackaged)");const r=await this.apiClient.createFolder({name:n.name,parent:t,fixNameCollisions:true}),s=await this.jobManager.execute("JS:Unpackage",[{_id:e,isFolder:false}],[{name:"Destination Folder",value:r},{name:"Make Destination Visible",value:false}],i);if(this._updateQuota(),3===s.state){const t=s.log.trim().split(";");if(2!==t.length||"UNPACKAGED"!==t[0])throw new N$1("Unpacking failed. Did not get unpackaged item id!");const a=t[1].trim();return await this.apiClient.renameItem(a,n.name),await this.itemRepo.replaceLink(e,a),a}if(2===s.state)throw new N$1("Unpacking failed: "+s.error)}async copyItemToProject(e,t,a,i){return (await this.copyItemsToProject([{_id:e,isFolder:false}],t,a,i))[0].newId}async copyItemsToProject(e,t,a,i){a=a||"packages",t=await this.apiClient.createFolder({name:a,parent:t,returnIfExists:true}),this.affectedFolderIds.add(t);const n=[];if(e.length){const a=await this.jobManager.execute("JS:CloneItem",e,[{name:"Deep Clone",value:false},{name:"Destination Folder",value:t},{name:"Exclude Types",value:""},{name:"Make Private",value:true}],i);if(this._updateQuota(),3===a.state){if(!a.log.trim().length)throw new N$1("Copy job returned no results.");{const e=a.log.split("\n").reverse();for(const t of e){const e=t.trim().split(";");if(3===e.length){const t=e[1],a=e[2];await this.itemRepo.replaceLink(t,a),n.push({oldId:t,newId:a});}}}}else if(2===a.state)throw new N$1("Copying of items failed: "+a.error)}return n}async copyToProject(e,t,a){const i=[];for(const e of this.items)e.external&&i.push({_id:e._id,isFolder:false});return this.copyItemsToProject(i,e,t,a)}async unpublish(e){await this.apiClient.makeItemPrivate(e,false,false);}async publish(e,t,a,i,n,r,s,o){const l=e.version;i=i||`published/${l.major}.${l.minor}.${l.revision}`,n=void 0===n||n,r=void 0===r||r,this.affectedFolderIds.add(a);let u,c=a;if(i){const e=i.split("/");for(const t of e)c=await this.apiClient.createFolder({name:t,parent:c,returnIfExists:true}),this.affectedFolderIds.add(c),u||(u=c);}const d=(await this.apiClient.getFoldersInFolderList(a)).children.map((e=>e._id)).filter((e=>e!==u)).join(","),p=await this.jobManager.execute("JS:CreatePackage",[{_id:e._id,isFolder:false}],[{name:"Folders To Include",value:d},{name:"Destination Folder",value:c},{name:"Item Name",value:t},{name:"Make Public",value:!!n},{name:"Copy External",value:!!r},{name:"Always Create New Package",value:!!s},{name:"Make Cloneable",value:!!o}]);if(this._updateQuota(),2===p.state)throw new N$1("Packaging failed: "+p.error);this.apiClient.eventBus.$emit("folder:changed",Array.from(this.affectedFolderIds.values()));}}class qn{id;job;nextCheckMs;constructor(e,t,a){this.id=e,this.job=a,this.nextCheckMs=t;}}class Zn{apiClient;jobs=new Map;constructor(e){this.apiClient=e;}getJobs(){return Array.from(this.jobs.values())}async execute(e,t,a,i=void 0,n){const r=this;return new Promise((async(s,o)=>{try{const o=async()=>{try{u.job=await r.apiClient.getJobState(l);let e=!1;switch(u.job.state){case 0:case 1:try{i&&i(u.job);}catch(e){console.error("Error calling progress callback: ",e);}break;case 2:case 3:console.log("Job is done."),e=!0,s(u.job);}e?r.jobs.delete(l):(u.nextCheckMs=Math.min(2*u.nextCheckMs,8e3),setTimeout(o,u.nextCheckMs));}catch(e){console.error("Error fetching job state: "+e);}},l=await r.apiClient.createJob({type:e,elements:t,parameters:a,requiredParameters:n}),u=new qn(l,1e3);r.jobs.set(l,u),setTimeout(o,u.nextCheckMs);}catch(e){o(e);}}))}}const Jn={mp3:{name:"Mpeg Audio Layer 3",itemType:"Audio",itemTypeCollection:"Audio Collection",collectionEntryName:"AudioItems",folderName:"audio",defaultAction:"Use",actions:["Skip","Use"]},hdr:{name:"HDR Image",itemType:"HDR Image",folderName:"envmaps",defaultAction:"Use",actions:["Skip","Use"]},glb:{name:"Gltf Binary",itemType:"Mesh",itemTypeCollection:"Mesh Collection",collectionEntryName:"MeshItems",folderName:"meshes",defaultAction:"Use",actions:["Skip","Use"]},png:{name:"Portable Network Graphics",itemType:"Image",folderName:"textures",defaultAction:"Use",actions:["Skip","Use"]},jpg:{name:"JPEG",itemType:"Image",folderName:"textures",defaultAction:"Use",actions:["Skip","Use"]},jpeg:{name:"JPEG",itemType:"Image",folderName:"textures",defaultAction:"Use",actions:["Skip","Use"]},lua:{name:"Lua",itemType:"Script",folderName:"scripts",defaultAction:"Use",actions:["Skip","Use"]},ttf:{name:"True Type Font",itemType:"Font",folderName:"fonts",defaultAction:"Use",actions:["Skip","Use"]},otf:{name:"Open Type Font",itemType:"Font",folderName:"fonts",defaultAction:"Use",actions:["Skip","Use"]},unknown:{name:"Unsupported",itemType:"Unknown",defaultAction:"Skip",actions:["Skip"],invisible:true}},Kn={Audio:"audio","Audio Collection":"audio","HDR Image":"envmaps",Mesh:"meshes","Mesh Collection":"",Script:"scripts",Material:"materials","Background Shader":"background shaders","Pixel Shader":"pixel shaders","Vertex Shader":"vertex shaders",Image:"textures",Scene:"prefabs",Font:"fonts"};function Xn(e,t){let a=Jn[t];a||(a=Jn.unknown),e.size=e.blob?e.blob.size:0,e.type=a.name,e.collectionType=a.itemTypeCollection,e.collectionEntryName=a.collectionEntryName,e.action=a.defaultAction,e.actions=a.actions,e.folderName=a.folderName,e.itemType=a.itemType,e.name=function(e,t){let a=e.lastIndexOf(".");return e.substring(0,a<0?e.length:a)+"."+t}(e.name,t);}class Qn{name;blob;processing=false;progress=0;size=0;type;collectionType;collectionEntryName;action;actions;folderName;itemType;constructor(e,t,a){this.name=e,this.blob=t,Xn(this,a);}}class er{apiClient;itemRepo;jobManager;items=[];mainItem;totalSize=0;oldMainItemId;originalItemIds=[];affectedFolderIds=new Set;packageId;converter;supportedExtensions;hasExternalResources=false;constructor(e){this.apiClient=e,this.itemRepo=e.getItemRepo(),this.jobManager=e.getJobManager();const t=[];for(const e in Jn)Jn[e].invisible||t.push(`.${e.toUpperCase()}`);this.supportedExtensions=t.sort(((e,t)=>e.localeCompare(t)));}_updateQuota(){this.apiClient.eventBus.$emit("quota:update");}_addAffectedFolder(e){"object"==typeof e&&e._id?this.affectedFolderIds.add(e._id):"string"==typeof e?this.affectedFolderIds.add(e):console.error("Invalid affected folder to add: ",e);}getAffectedFolderIds(){return Array.from(this.affectedFolderIds.values())}getSupportedExtensions(){return this.supportedExtensions}setConverter(e){this.converter=e;}setItems(e){this.items=e;}async scan(e){const t=this,a=new Map,i=new Map;this.mainItem=await this.itemRepo.loadItem(e,{recursive:true}),this.oldMainItemId=this.mainItem._id;const n=await r(this.mainItem.folder);async function r(e){try{if(e){const a=e._id?e._id:e;if(i.has(a))return i.get(a);{const e=(await t.apiClient.getFolderPath(a)).path;return i.set(a,e),e}}return "/"}catch(e){return console.error(e),""}}await this.itemRepo.traverseItems((async function(e){const i={_id:e._id,name:e.name,type:e.type,size:e.totalSize,path:await r(e.folder),item:e,external:false};i.path.startsWith(n)?i.path=i.path.slice(n.length):i.external=true,t._addAffectedFolder(e.folder),a.set(e._id,i);}),this.mainItem),this.items=Array.from(a.values()),this.originalItemIds=this.items.map((e=>e._id)),this.hasExternalResources=false,this.totalSize=0;for(const e of this.items)e.external&&(this.hasExternalResources=true),this.totalSize+=e.size;return this.items}getItems(){return this.items}async saveMainItemChanges(){const e=this.mainItem;await this.apiClient.updateItem({_id:e._id,name:e.name,shortDescription:e.shortDescription,description:e.description,tags:e.tags,categories:e.categories,visibility:e.visibility,contributors:e.contributors,version:e.version});}async createAssetFolder(e,t){let a=e;const i=t.split("/");this._addAffectedFolder(e);for(const e of i)a=await this.apiClient.createFolder({name:e,parent:a,returnIfExists:true}),this._addAffectedFolder(a);const n=await this.apiClient.getItemsInFolderList(a,true);if(n&&n.length)throw new Error("Asset folder already exists and is not empty!");return a}createStandardAssetFolderPath(e){let t=Kn[e.type];return t||(t=e.type.toLowerCase()+"s"),`assets/${t}/${e.name}`}async executeActions(){if(!this.converter)throw new Error("No converter is configured. Cannot execute actions on items.");return this.converter(this.items,Xn)}async createAsset(e,t=false,a){const i=[];for(const e of this.items)i.push(e._id);if(this._addAffectedFolder(e),i.length)if(t){await this.apiClient.moveItems({items:i,dest:e})!==i.length&&console.warn("Not all items could be moved. Most likely due to permissions."),this.mainItem.folder=e;}else {const t=await this.jobManager.execute("JS:CloneItem",[{_id:this.mainItem._id,isFolder:false}],[{name:"Deep Clone",value:true},{name:"Destination Folder",value:e},{name:"Exclude Types",value:""}],a);if(3===t.state){const a=t.log.split("\n").reverse()[0].split(";");this.mainItem={...this.mainItem,_id:a[2],folder:e};}else if(2===t.state)throw new N$1("Copying of items failed: "+t.error)}"Main"!==this.mainItem.name&&(this.mainItem.originalName=this.mainItem.name,this.mainItem.name="Main",await this.apiClient.renameItem(this.mainItem._id,this.mainItem.name));const n=await this.apiClient.getItem(this.mainItem._id);return n.flags||(n.flags=[]),n.flags.includes("original")||n.flags.push("original"),await this.apiClient.updateItem(n),this._updateQuota(),this.mainItem._id}async createPackage(e,t=false,a=false){let i,n=this.mainItem.folder;if(this._addAffectedFolder(n),void 0===e){const t=this.mainItem.version||{major:1,minor:0,revision:0};e=`published/${t.major}.${t.minor}.${t.revision}`;}if(void 0===t&&(t=true),e){const t=e.split("/");for(const e of t)n=await this.apiClient.createFolder({name:e,parent:n,returnIfExists:true}),this._addAffectedFolder(n),i||(i=n);}const r=(await this.apiClient.getFoldersInFolderList(this.mainItem.folder)).children.map((e=>e._id)).filter((e=>e!==i)).join(","),s=await this.jobManager.execute("JS:CreatePackage",[{_id:this.mainItem._id,isFolder:false}],[{name:"Folders To Include",value:r},{name:"Destination Folder",value:n},{name:"Item Name",value:this.mainItem.originalName||this.mainItem.name},{name:"Make Public",value:!!t},{name:"Copy External",value:!!a}]);if(this._updateQuota(),2===s.state)throw new N$1("Packaging failed: "+s.error);const o=s.log.split("\n").reverse()[0].split(";");this.packageId=o[2];}async replaceReferences(){await this.itemRepo.replaceLink(this.oldMainItemId,this.packageId);}async deleteOriginalItems(){await this.apiClient.deleteItem(this.originalItemIds);}sendFolderRefreshEvent(){this.apiClient.eventBus.$emit("folder:changed",this.getAffectedFolderIds());}async processUploads(e){const t=[];for(const a of e)if("application/zip"===a.type||"application/x-zip-compressed"===a.type){const e=new s$2;try{const i=[];(await e.loadAsync(a)).forEach(((e,a)=>{const n=a.name.split("/").pop();if(!n.startsWith(".")){const e=n.split(".").pop(),r=a.async("blob");i.push(r),r.then((function(i){const n=new Qn(a.name,i,e);t.push(n);}));}})),await Promise.all(i);}catch(e){console.error("Error reading the ZIP file:",e);}}else {const e=a.name.split(".").pop(),i=new Qn(a.name,a,e);t.push(i);}return t}detectAssets(e){let t,a,i,n=0;for(const r of e)if("Use"===r.action)if(void 0===t)t=r.itemType,a=r.collectionType,i=r.folderName,n++;else {if(t!==r.itemType)return {valid:false,reason:"Mixed item types found. To create an asset, upload a single type of file for example only meshes."};n++;}return 0===n?{valid:false,reason:"There are no files we can use to create an asset."}:n>1&&!a?{valid:false,reason:"Cannot create collections of this type."}:{valid:true,assetType:n>1?a:t,itemCount:n,folderName:i}}_filterUploadFiles(e){let t=[];for(const a of e)"Use"===a.action&&t.push(a);return t}createNewItem(){return {name:"New asset",type:"",description:"",shortDescription:"",tags:[],flags:["original"],categories:[],license:"CC0",allowConversation:true,version:{major:1,minor:0,revision:0}}}async createAssetFromFiles(e,t,a,i=false,n=false){const r=this.detectAssets(e);if(r.assetType!==a.type)throw new Error("Asset type not valid for these items.");if(!r.valid)throw new Error(r.reason||"No valid asset detected.");let s=await this.apiClient.createFolder({name:r.folderName,parent:t,returnIfExists:true}),o=await this.apiClient.createFolder({name:a.name,parent:s,returnIfExists:true}),l=false;if(0===(await this.apiClient.getItemsInFolderList(o)).length){(await this.apiClient.getFoldersInFolderList(o)).children.length&&(l=true);}else l=true;if(l){if(!i)throw new Error("Cannot create asset, target folder is not empty!");await this.apiClient.deleteFolder(o),o=await this.apiClient.createFolder({name:a.name,parent:s});}let u,c=this._filterUploadFiles(e);if(1===c.length){const e=c[0];e.processing=true,e.progress=0,u=await this.apiClient.uploadAndCreate(o,e.blob,e.name,{nameOverride:"Main",flags:"original"},(function(t){e.progress=t;})),this._updateQuota(),e.action="Skip";}else {let e=await this.apiClient.createFolder({name:"resources",parent:o}),t={},a=[],i=0;for(const n of c){n.processing=true,n.progress=0;const r=await this.apiClient.uploadAndCreate(e,n.blob,n.name,void 0,(function(e){n.progress=e;}));this._updateQuota(),n.action="Skip",t[`${n.collectionEntryName}[${i}]->Name`]="",a.push({usage:`MeshItems[${i}]->Mesh`,to:r}),i++;}u=await this.apiClient.createItem({type:r.assetType,name:"Main",flags:["original"],folder:o,fixNameCollisions:true,attributes:t,links:a});}return a._id=u,a.folder=o,this.mainItem=a,n?{assetItemId:u,assetTypeFolderId:s,assetFolderId:o}:u}}class tr{apiClient;itemRepo;constructor(e){this.apiClient=e,this.itemRepo=e.getItemRepo();}grab(e,t,a,i){i=i||{};const n=[];for(const r of a){const a=this._serializeBlockFields(r),s=this._serializeScripts(r),o={type:"block",item:e._id,field:t.name,path:"",block:{id:r.id,type:r.type||"Group",fields:a,scripts:s,children:[]}};i.omitPath||(o.path=this._getBlockPath(r)),i.withChildren&&(o.block.children=this.grab(e,t,r.blocks||[],{withChildren:true,returnArray:true})),n.push(o);}if(i.returnArray)return n;const r={type:"serializedBlocks",data:n};return i.noStringify?r:JSON.stringify(r,null,2)}async put(e,t,a,i={}){e=this.validateMessage(e);const n=[];for(const r of e.data){const e=await this._putBlock(r,t,a,i);e&&n.push(e);}return n}validateMessage(e){if("string"==typeof e&&(e=JSON.parse(e)),"serializedBlocks"!==e.type)throw new Error("Data must be a serialized block message. Format is wrong.");if(!Array.isArray(e.data))throw new Error("The contained data is not an array.");return e}async clone(e,t,a,i,n={}){const r=this.grab(i,t,[e],{withChildren:true,noStringify:true});return this.put(r,t,a,n)}_updateScriptFieldReferences(e,t){const a=new Map,i=(e,t)=>{a.set(e.block.id,t.id);const n=e.block.children||[],r=t.blocks||[];for(let e=0;e<n.length;e++)i(n[e],r[e]);};i(e,t),this.itemRepo.updateScriptFieldReferencesFromMap(a,t);}async _putBlock(e,t,a,i={},n=false){if(!e.block||!e.block.type||!e.block.fields)return null;const r=e.block,s=this._findItemById(e.item)??this.itemRepo.activeItem;let o=a;o||(o=this._findParentBlock(s,e.field,e.path));const l={};if(Array.isArray(r.fields))for(const e of r.fields){const{name:t,type:a,value:n,linkto:r}=e;if("Separator"!==a)if(i.fieldOverrides&&t in i.fieldOverrides)l[t]=i.fieldOverrides[t];else if(r){const e=this.itemRepo.getLoadedItem(r);l[t]=e||await this.itemRepo.loadItem(r);}else l[t]=n;}const u=i.dontCopyScripts?[]:[...r.scripts],c=await this._createUnproxifiedBlock(r.type,l,u,t,s),d={...i,parentPosition:void 0,fieldOverrides:void 0};if(!c)return console.warn(`Could not create block of type ${r.type}. Skipping.`),null;if(Array.isArray(r.children))for(const e of r.children)await this._putBlock(e,t,c,d,true);if(n&&o)return "number"==typeof i.parentPosition?o.blocks.splice(i.parentPosition,0,c):o.blocks.push(c),c.parent=o,c;i.dontCopyScripts||this._updateScriptFieldReferences(e,c);return this._proxifyAndAttachTree(c,o,s,i.parentPosition)}async _createUnproxifiedBlock(e,t,a,i,n){let r=se.instance.getTemplate(n.packageType||n.type,i.name,e);if(!r)return null;if(t){const e=r.template.clone().specialize(t);r={displayName:r.displayName,typeName:r.typeName,template:e,inputs:r.inputs,outputs:r.outputs};}const s=new le(void 0,void 0,r.typeName,void 0,r.displayName,n),o=await this.itemRepo.createFieldsForItem(s,r.template,n,true);return s.setFields(o),s.blocks=[],await this.itemRepo.createScriptsForItem(s,a,n,false),s}_proxifyAndAttachTree(e,t,a,i){const n=e=>{if(Array.isArray(e.blocks)&&e.blocks.length)for(const t of e.blocks)n(t);const t=e.blocks.map((e=>g$1.instance.proxyBlock(e,a)));e.blocks=g$1.instance.proxyBlockArray(t,e,a),e.scripts=g$1.instance.proxyScriptArray(e.scripts,e,a);};n(e),e.parent=t;const r=g$1.instance.proxyBlock(e,a);return "number"==typeof i?t.blocks.splice(i,0,r):t.blocks.push(r),r}_findItemById(e){return this.itemRepo.findLoadedItem(e)}_findItemField(e,t){if(!e.fieldInstances)return null;for(const a of e.fieldInstances)if(a.name===t)return a;return null}_findParentBlock(e,t,a){const i=this._findItemField(e,t);if(!i)return null;const n=a.split("/");let r=i.blocks,s=null;for(const e of n)s=r[e],r=s.blocks;return s}_getBlockIndex(e){if(!e.parent)return 0;let t=0;for(const a of e.parent.blocks){if(e.id===a.id)return t;t++;}throw new Error("Could not find block in parent block array!")}_getBlockPath(e){const t=[];let a=e;for(;a;)t.push(this._getBlockIndex(a)),a=a.parent;return "/"+t.reverse().join("/")}_serializeBlockFields(e){const t=[];if(!Array.isArray(e.fields))return t;for(const a of e.fields)switch(a.type){case "Link":t.push({name:a.name,linkto:a.value?._id});break;case "Attribute":t.push({name:a.name,value:a.value});break;case "Separator":t.push({name:a.name,type:"Separator"});}return t}_serializeScripts(e){const t=[];if(!Array.isArray(e.scripts))return t;for(const a of e.scripts){const e=[],i={item:a.item?.value?._id,fields:e};for(const t of a.fields)e.push({name:t.name,value:t.value});t.push(i);}return t}}Array.prototype.pushAll||(Array.prototype.pushAll=function(e){for(const t of e)this.push(t);}),Array.prototype.removeObject||(Array.prototype.removeObject=function(e){const t=this.indexOf(e);return t>-1&&(this.splice(t,1),true)}),Array.prototype.moveObjectToArray||(Array.prototype.moveObjectToArray=function(e,t,a){const i=this.indexOf(e);if(i>-1){return (0, this.moveToArray)(i,t,a)}return false}),Array.prototype.removeByFilterFunc||(Array.prototype.removeByFilterFunc=function(e){let t=0;for(let a=0;a<this.length;a++)e(this[a])&&(this.splice(a,1),a--,t++);return t}),Array.prototype.clone||(Array.prototype.clone=function(){const e=[];for(const t of this)e.push(t);return e});const ar=()=>new Map,ir=e=>{const t=ar();return e.forEach(((e,a)=>{t.set(a,e);})),t},nr=(e,t,a)=>{let i=e.get(t);return void 0===i&&e.set(t,i=a()),i},rr=()=>new Set,sr=e=>e[e.length-1],or=(e,t)=>{for(let a=0;a<t.length;a++)e.push(t[a]);},lr=Array.from,ur=Array.isArray;class cr{constructor(){this._observers=ar();}on(e,t){return nr(this._observers,e,rr).add(t),t}once(e,t){const a=(...i)=>{this.off(e,a),t(...i);};this.on(e,a);}off(e,t){const a=this._observers.get(e);void 0!==a&&(a.delete(t),0===a.size&&this._observers.delete(e));}emit(e,t){return lr((this._observers.get(e)||ar()).values()).forEach((e=>e(...t)))}destroy(){this._observers=ar();}}class dr{constructor(){this._observers=ar();}on(e,t){nr(this._observers,e,rr).add(t);}once(e,t){const a=(...i)=>{this.off(e,a),t(...i);};this.on(e,a);}off(e,t){const a=this._observers.get(e);void 0!==a&&(a.delete(t),0===a.size&&this._observers.delete(e));}emit(e,t){return lr((this._observers.get(e)||ar()).values()).forEach((e=>e(...t)))}destroy(){this._observers=ar();}}const pr=Math.floor,hr=Math.abs,fr=(e,t)=>e<t?e:t,mr=(e,t)=>e>t?e:t,yr=Math.pow,gr=e=>0!==e?e<0:1/e<0,br=64,vr=128,_r=127,wr=Number.MAX_SAFE_INTEGER,Ar=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&pr(e)===e),kr=String.fromCharCode,Sr=/^\s*/g,Nr=/([A-Z])/g,Tr=(e,t)=>(e=>e.replace(Sr,""))(e.replace(Nr,(e=>`${t}${(e=>e.toLowerCase())(e)}`))),Mr="undefined"!=typeof TextEncoder?new TextEncoder:null,xr=Mr?e=>Mr.encode(e):e=>{const t=unescape(encodeURIComponent(e)),a=t.length,i=new Uint8Array(a);for(let e=0;e<a;e++)i[e]=t.codePointAt(e);return i};let Vr="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});Vr&&1===Vr.decode(new Uint8Array).length&&(Vr=null);class Cr{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[];}}const Ir=()=>new Cr,Fr=e=>{let t=e.cpos;for(let a=0;a<e.bufs.length;a++)t+=e.bufs[a].length;return t},Er=e=>{const t=new Uint8Array(Fr(e));let a=0;for(let i=0;i<e.bufs.length;i++){const n=e.bufs[i];t.set(n,a),a+=n.length;}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),a),t},Dr=(e,t)=>{const a=e.cbuf.length;e.cpos===a&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*a),e.cpos=0),e.cbuf[e.cpos++]=t;},Lr=Dr,Rr=(e,t)=>{for(;t>_r;)Dr(e,vr|_r&t),t=pr(t/128);Dr(e,_r&t);},Pr=(e,t)=>{const a=gr(t);for(a&&(t=-t),Dr(e,(t>63?vr:0)|(a?br:0)|63&t),t=pr(t/64);t>0;)Dr(e,(t>_r?vr:0)|_r&t),t=pr(t/128);},Or=new Uint8Array(3e4),Br=Or.length/3,$r=Mr&&Mr.encodeInto?(e,t)=>{if(t.length<Br){const a=Mr.encodeInto(t,Or).written||0;Rr(e,a);for(let t=0;t<a;t++)Dr(e,Or[t]);}else Ur(e,xr(t));}:(e,t)=>{const a=unescape(encodeURIComponent(t)),i=a.length;Rr(e,i);for(let t=0;t<i;t++)Dr(e,a.codePointAt(t));},jr=(e,t)=>{const a=e.cbuf.length,i=e.cpos,n=fr(a-i,t.length),r=t.length-n;e.cbuf.set(t.subarray(0,n),i),e.cpos+=n,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(mr(2*a,r)),e.cbuf.set(t.subarray(n)),e.cpos=r);},Ur=(e,t)=>{Rr(e,t.byteLength),jr(e,t);},zr=(e,t)=>{((e,t)=>{const a=e.cbuf.length;a-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*mr(a,t)),e.cpos=0);})(e,t);const a=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,a},Wr=new DataView(new ArrayBuffer(4)),Yr=(e,t)=>{switch(typeof t){case "string":Dr(e,119),$r(e,t);break;case "number":Ar(t)&&hr(t)<=2147483647?(Dr(e,125),Pr(e,t)):(a=t,Wr.setFloat32(0,a),Wr.getFloat32(0)===a?(Dr(e,124),((e,t)=>{zr(e,4).setFloat32(0,t,false);})(e,t)):(Dr(e,123),((e,t)=>{zr(e,8).setFloat64(0,t,false);})(e,t)));break;case "bigint":Dr(e,122),((e,t)=>{zr(e,8).setBigInt64(0,t,false);})(e,t);break;case "object":if(null===t)Dr(e,126);else if(ur(t)){Dr(e,117),Rr(e,t.length);for(let a=0;a<t.length;a++)Yr(e,t[a]);}else if(t instanceof Uint8Array)Dr(e,116),Ur(e,t);else {Dr(e,118);const a=Object.keys(t);Rr(e,a.length);for(let i=0;i<a.length;i++){const n=a[i];$r(e,n),Yr(e,t[n]);}}break;case "boolean":Dr(e,t?120:121);break;default:Dr(e,127);}var a;};class Hr extends Cr{constructor(e){super(),this.w=e,this.s=null,this.count=0;}write(e){this.s===e?this.count++:(this.count>0&&Rr(this,this.count-1),this.count=1,this.w(this,e),this.s=e);}}const Gr=e=>{e.count>0&&(Pr(e.encoder,1===e.count?e.s:-e.s),e.count>1&&Rr(e.encoder,e.count-2));};class qr{constructor(){this.encoder=new Cr,this.s=0,this.count=0;}write(e){this.s===e?this.count++:(Gr(this),this.count=1,this.s=e);}toUint8Array(){return Gr(this),Er(this.encoder)}}const Zr=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);Pr(e.encoder,t),e.count>1&&Rr(e.encoder,e.count-2);}};class Jr{constructor(){this.encoder=new Cr,this.s=0,this.count=0,this.diff=0;}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Zr(this),this.count=1,this.diff=e-this.s,this.s=e);}toUint8Array(){return Zr(this),Er(this.encoder)}}class Kr{constructor(){this.sarr=[],this.s="",this.lensE=new qr;}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length);}toUint8Array(){const e=new Cr;return this.sarr.push(this.s),this.s="",$r(e,this.sarr.join("")),jr(e,this.lensE.toUint8Array()),Er(e)}}const Xr=e=>new Error(e),Qr=()=>{throw Xr("Method unimplemented")},es=()=>{throw Xr("Unexpected case")},ts=Xr("Unexpected end of array"),as=Xr("Integer out of Range");class is{constructor(e){this.arr=e,this.pos=0;}}const ns=e=>new is(e),rs=e=>((e,t)=>{const a=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,a})(e,os(e)),ss=e=>e.arr[e.pos++],os=e=>{let t=0,a=1;const i=e.arr.length;for(;e.pos<i;){const i=e.arr[e.pos++];if(t+=(i&_r)*a,a*=128,i<vr)return t;if(t>wr)throw as}throw ts},ls=e=>{let t=e.arr[e.pos++],a=63&t,i=64;const n=(t&br)>0?-1:1;if(!(t&vr))return n*a;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],a+=(t&_r)*i,i*=128,t<vr)return n*a;if(a>wr)throw as}throw ts},us=Vr?e=>Vr.decode(rs(e)):e=>{let t=os(e);if(0===t)return "";{let a=String.fromCodePoint(ss(e));if(--t<100)for(;t--;)a+=String.fromCodePoint(ss(e));else for(;t>0;){const i=t<1e4?t:1e4,n=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,a+=String.fromCodePoint.apply(null,n),t-=i;}return decodeURIComponent(escape(a))}},cs=(e,t)=>{const a=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,a},ds=[e=>{},e=>null,ls,e=>cs(e,4).getFloat32(0,false),e=>cs(e,8).getFloat64(0,false),e=>cs(e,8).getBigInt64(0,false),e=>false,e=>true,us,e=>{const t=os(e),a={};for(let i=0;i<t;i++){a[us(e)]=ps(e);}return a},e=>{const t=os(e),a=[];for(let i=0;i<t;i++)a.push(ps(e));return a},rs],ps=e=>ds[127-ss(e)](e);class hs extends is{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0;}read(){var e;return 0===this.count&&(this.s=this.reader(this),(e=this).pos!==e.arr.length?this.count=os(this)+1:this.count=-1),this.count--,this.s}}class fs extends is{constructor(e){super(e),this.s=0,this.count=0;}read(){if(0===this.count){this.s=ls(this);const e=gr(this.s);this.count=1,e&&(this.s=-this.s,this.count=os(this)+2);}return this.count--,this.s}}class ms extends is{constructor(e){super(e),this.s=0,this.count=0,this.diff=0;}read(){if(0===this.count){const e=ls(this),t=1&e;this.diff=pr(e/2),this.count=1,t&&(this.count=os(this)+2);}return this.s+=this.diff,this.count--,this.s}}class ys{constructor(e){this.decoder=new fs(e),this.str=us(this.decoder),this.spos=0;}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const gs=crypto.getRandomValues.bind(crypto),bs=()=>gs(new Uint32Array(1))[0],vs=[1e7]+-1e3+-4e3+-8e3+-1e11,_s=()=>vs.replace(/[018]/g,(e=>(e^bs()&15>>e/4).toString(16))),ws=Date.now,As=e=>new Promise(e);Promise.all.bind(Promise);const ks=e=>void 0===e?null:e;let Ss=new class{constructor(){this.map=new Map;}setItem(e,t){this.map.set(e,t);}getItem(e){return this.map.get(e)}},Ns=true;try{"undefined"!=typeof localStorage&&localStorage&&(Ss=localStorage,Ns=!1);}catch(e){}const Ts=Ss,Ms=Object.assign,xs=Object.keys,Vs=e=>xs(e).length,Cs=e=>xs(e).length,Is=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Fs=Object.freeze,Es=e=>{for(const t in e){const a=e[t];"object"!=typeof a&&"function"!=typeof a||Es(e[t]);}return Fs(e)},Ds=Symbol("Equality"),Ls=(e,t,a=0)=>{try{for(;a<e.length;a++)e[a](...t);}finally{a<e.length&&Ls(e,t,a+1);}},Rs=e=>e,Ps=(e,t)=>{if(e===t)return true;if(null==e||null==t||e.constructor!==t.constructor)return false;if(null!=e[Ds])return e[Ds](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return false;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return false;break;case Set:if(e.size!==t.size)return false;for(const a of e)if(!t.has(a))return false;break;case Map:if(e.size!==t.size)return false;for(const a of e.keys())if(!t.has(a)||!Ps(e.get(a),t.get(a)))return false;break;case Object:if(Vs(e)!==Vs(t))return false;for(const a in e)if(!Is(e,a)||!Ps(e[a],t[a]))return false;break;case Array:if(e.length!==t.length)return false;for(let a=0;a<e.length;a++)if(!Ps(e[a],t[a]))return false;break;default:return false}return true},Os="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),Bs="undefined"!=typeof window&&"undefined"!=typeof document&&!Os;let $s;const js=e=>(()=>{if(void 0===$s)if(Os){$s=ar();const e=process.argv;let t=null;for(let a=0;a<e.length;a++){const i=e[a];"-"===i[0]?(null!==t&&$s.set(t,""),t=i):null!==t&&($s.set(t,i),t=null);}null!==t&&$s.set(t,"");}else "object"==typeof location?($s=ar(),(location.search||"?").slice(1).split("&").forEach((e=>{if(0!==e.length){const[t,a]=e.split("=");$s.set(`--${Tr(t,"-")}`,a),$s.set(`-${Tr(t,"-")}`,a);}}))):$s=ar();return $s})().has(e),Us=e=>ks(Os?process.env[e.toUpperCase().replaceAll("-","_")]:Ts.getItem(e)),zs=e=>js("--"+e)||null!==Us(e);zs("production");var Ws;const Ys=Os&&(Ws=process.env.FORCE_COLOR,["true","1","2"].includes(Ws))||!js("--no-colors")&&!zs("no-color")&&(!Os||process.stdout.isTTY)&&(!Os||js("--color")||null!==Us("COLORTERM")||(Us("TERM")||"").includes("color")),Hs=e=>new Uint8Array(e),Gs=Bs?e=>{let t="";for(let a=0;a<e.byteLength;a++)t+=kr(e[a]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),qs=Bs?e=>{const t=atob(e),a=Hs(t.length);for(let e=0;e<t.length;e++)a[e]=t.charCodeAt(e);return a}:e=>{const t=Buffer.from(e,"base64");return ((e,t,a)=>new Uint8Array(e,t,a))(t.buffer,t.byteOffset,t.byteLength)};class Zs{constructor(e,t){this.left=e,this.right=t;}}const Js=(e,t)=>new Zs(e,t);"undefined"!=typeof DOMParser&&new DOMParser;const Ks=Symbol,Xs=Ks(),Qs=Ks(),eo=Ks(),to$2=Ks(),ao=Ks(),io=Ks(),no=Ks(),ro=Ks(),so=Ks(),oo={[Xs]:Js("font-weight","bold"),[Qs]:Js("font-weight","normal"),[eo]:Js("color","blue"),[ao]:Js("color","green"),[to$2]:Js("color","grey"),[io]:Js("color","red"),[no]:Js("color","purple"),[ro]:Js("color","orange"),[so]:Js("color","black")},lo=Ys?e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],a=[],i=ar();let n=[],r=0;for(;r<e.length;r++){const n=e[r],s=oo[n];if(void 0!==s)i.set(s.left,s.right);else {if(void 0===n)break;if(n.constructor!==String&&n.constructor!==Number)break;{const e=((e,t)=>{const a=[];for(const[i,n]of e)a.push(t(n,i));return a})(i,((e,t)=>`${t}:${e};`)).join("");r>0||e.length>0?(t.push("%c"+n),a.push(e)):t.push(n);}}}for(r>0&&(n=a,n.unshift(t.join("")));r<e.length;r++){const t=e[r];t instanceof Symbol||n.push(t);}return n}:e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],a=[];let i=0;for(;i<e.length;i++){const a=e[i];if(void 0===a)break;if(a.constructor===String||a.constructor===Number)t.push(a);else if(a.constructor===Object)break}for(i>0&&a.push(t.join(""));i<e.length;i++){const t=e[i];t instanceof Symbol||a.push(t);}return a},uo=rr(),co=e=>({[Symbol.iterator](){return this},next:e}),po=(e,t)=>co((()=>{const{done:a,value:i}=e.next();return {done:a,value:a?void 0:t(i)}}));class ho{constructor(e,t){this.clock=e,this.len=t;}}class fo{constructor(){this.clients=new Map;}}const mo=(e,t,a)=>t.clients.forEach(((t,i)=>{const n=e.doc.store.clients.get(i);if(null!=n){const i=n[n.length-1],r=i.id.clock+i.length;for(let i=0,s=t[i];i<t.length&&s.clock<r;s=t[++i])rl(e,n,s.clock,s.len,a);}})),yo=(e,t)=>{const a=e.clients.get(t.client);return void 0!==a&&null!==((e,t)=>{let a=0,i=e.length-1;for(;a<=i;){const n=pr((a+i)/2),r=e[n],s=r.clock;if(s<=t){if(t<s+r.len)return n;a=n+1;}else i=n-1;}return null})(a,t.clock)},go=e=>{e.clients.forEach((e=>{let t,a;for(e.sort(((e,t)=>e.clock-t.clock)),t=1,a=1;t<e.length;t++){const i=e[a-1],n=e[t];i.clock+i.len>=n.clock?i.len=mr(i.len,n.clock+n.len-i.clock):(a<t&&(e[a]=n),a++);}e.length=a;}));},bo=(e,t,a,i)=>{nr(e.clients,t,(()=>[])).push(new ho(a,i));},vo=e=>{const t=new fo;return e.clients.forEach(((e,a)=>{const i=[];for(let t=0;t<e.length;t++){const a=e[t];if(a.deleted){const n=a.id.clock;let r=a.length;if(t+1<e.length)for(let a=e[t+1];t+1<e.length&&a.deleted;a=e[1+ ++t])r+=a.length;i.push(new ho(n,r));}}i.length>0&&t.clients.set(a,i);})),t},_o=(e,t)=>{Rr(e.restEncoder,t.clients.size),lr(t.clients.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,a])=>{e.resetDsCurVal(),Rr(e.restEncoder,t);const i=a.length;Rr(e.restEncoder,i);for(let t=0;t<i;t++){const i=a[t];e.writeDsClock(i.clock),e.writeDsLen(i.len);}}));},wo=e=>{const t=new fo,a=os(e.restDecoder);for(let i=0;i<a;i++){e.resetDsCurVal();const a=os(e.restDecoder),i=os(e.restDecoder);if(i>0){const n=nr(t.clients,a,(()=>[]));for(let t=0;t<i;t++)n.push(new ho(e.readDsClock(),e.readDsLen()));}}return t},Ao=(e,t,a)=>{const i=new fo,n=os(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const n=os(e.restDecoder),r=os(e.restDecoder),s=a.clients.get(n)||[],o=Xo(a,n);for(let a=0;a<r;a++){const a=e.readDsClock(),r=a+e.readDsLen();if(a<o){o<r&&bo(i,n,o,r-o);let e=el(s,a),l=s[e];for(!l.deleted&&l.id.clock<a&&(s.splice(e+1,0,Uu(t,l,a-l.id.clock)),e++);e<s.length&&(l=s[e++],l.id.clock<r);)l.deleted||(r<l.id.clock+l.length&&s.splice(e,0,Uu(t,l,r-l.id.clock)),l.delete(t));}else bo(i,n,a,r-a);}}if(i.clients.size>0){const e=new Fo;return Rr(e.restEncoder,0),_o(e,i),e.toUint8Array()}return null},ko=bs;class So extends cr{constructor({guid:e=_s(),collectionid:t=null,gc:a=true,gcFilter:i=()=>true,meta:n=null,autoLoad:r=false,shouldLoad:s=true}={}){super(),this.gc=a,this.gcFilter=i,this.clientID=ko(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Jo,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=s,this.autoLoad=r,this.meta=n,this.isLoaded=false,this.isSynced=false,this.isDestroyed=false,this.whenLoaded=As((e=>{this.on("load",(()=>{this.isLoaded=true,e(this);}));}));const o=()=>As((e=>{const t=a=>{ void 0!==a&&true!==a||(this.off("sync",t),e());};this.on("sync",t);}));this.on("sync",(e=>{ false===e&&this.isSynced&&(this.whenSynced=o()),this.isSynced=void 0===e||true===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this]);})),this.whenSynced=o();}load(){const e=this._item;null===e||this.shouldLoad||dl(e.parent.doc,(e=>{e.subdocsLoaded.add(this);}),null,true),this.shouldLoad=true;}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(lr(this.subdocs).map((e=>e.guid)))}transact(e,t=null){return dl(this,e,t)}get(e,t=Fl){const a=nr(this.share,e,(()=>{const e=new t;return e._integrate(this,null),e})),i=a.constructor;if(t!==Fl&&i!==t){if(i===Fl){const i=new t;i._map=a._map,a._map.forEach((e=>{for(;null!==e;e=e.left)e.parent=i;})),i._start=a._start;for(let e=i._start;null!==e;e=e.right)e.parent=i;return i._length=a._length,this.share.set(e,i),i._integrate(this,null),i}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return a}getArray(e=""){return this.get(e,Jl)}getText(e=""){return this.get(e,fu)}getMap(e=""){return this.get(e,Xl)}getXmlElement(e=""){return this.get(e,gu)}getXmlFragment(e=""){return this.get(e,yu)}toJSON(){const e={};return this.share.forEach(((t,a)=>{e[a]=t.toJSON();})),e}destroy(){this.isDestroyed=true,lr(this.subdocs).forEach((e=>e.destroy()));const e=this._item;if(null!==e){this._item=null;const t=e.content;t.doc=new So({guid:this.guid,...t.opts,shouldLoad:false}),t.doc._item=e,dl(e.parent.doc,(a=>{const i=t.doc;e.deleted||a.subdocsAdded.add(i),a.subdocsRemoved.add(this);}),null,true);}this.emit("destroyed",[true]),this.emit("destroy",[this]),super.destroy();}}class No{constructor(e){this.restDecoder=e;}resetDsCurVal(){}readDsClock(){return os(this.restDecoder)}readDsLen(){return os(this.restDecoder)}}class To extends No{readLeftID(){return Go(os(this.restDecoder),os(this.restDecoder))}readRightID(){return Go(os(this.restDecoder),os(this.restDecoder))}readClient(){return os(this.restDecoder)}readInfo(){return ss(this.restDecoder)}readString(){return us(this.restDecoder)}readParentInfo(){return 1===os(this.restDecoder)}readTypeRef(){return os(this.restDecoder)}readLen(){return os(this.restDecoder)}readAny(){return ps(this.restDecoder)}readBuf(){return (e=>{const t=Hs(e.byteLength);return t.set(e),t})(rs(this.restDecoder))}readJSON(){return JSON.parse(us(this.restDecoder))}readKey(){return us(this.restDecoder)}}class Mo{constructor(e){this.dsCurrVal=0,this.restDecoder=e;}resetDsCurVal(){this.dsCurrVal=0;}readDsClock(){return this.dsCurrVal+=os(this.restDecoder),this.dsCurrVal}readDsLen(){const e=os(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class xo extends Mo{constructor(e){super(e),this.keys=[],os(e),this.keyClockDecoder=new ms(rs(e)),this.clientDecoder=new fs(rs(e)),this.leftClockDecoder=new ms(rs(e)),this.rightClockDecoder=new ms(rs(e)),this.infoDecoder=new hs(rs(e),ss),this.stringDecoder=new ys(rs(e)),this.parentInfoDecoder=new hs(rs(e),ss),this.typeRefDecoder=new fs(rs(e)),this.lenDecoder=new fs(rs(e));}readLeftID(){return new Yo(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Yo(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return ps(this.restDecoder)}readBuf(){return rs(this.restDecoder)}readJSON(){return ps(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class Vo{constructor(){this.restEncoder=Ir();}toUint8Array(){return Er(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){Rr(this.restEncoder,e);}writeDsLen(e){Rr(this.restEncoder,e);}}class Co extends Vo{writeLeftID(e){Rr(this.restEncoder,e.client),Rr(this.restEncoder,e.clock);}writeRightID(e){Rr(this.restEncoder,e.client),Rr(this.restEncoder,e.clock);}writeClient(e){Rr(this.restEncoder,e);}writeInfo(e){Lr(this.restEncoder,e);}writeString(e){$r(this.restEncoder,e);}writeParentInfo(e){Rr(this.restEncoder,e?1:0);}writeTypeRef(e){Rr(this.restEncoder,e);}writeLen(e){Rr(this.restEncoder,e);}writeAny(e){Yr(this.restEncoder,e);}writeBuf(e){Ur(this.restEncoder,e);}writeJSON(e){$r(this.restEncoder,JSON.stringify(e));}writeKey(e){$r(this.restEncoder,e);}}class Io{constructor(){this.restEncoder=Ir(),this.dsCurrVal=0;}toUint8Array(){return Er(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0;}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,Rr(this.restEncoder,t);}writeDsLen(e){0===e&&es(),Rr(this.restEncoder,e-1),this.dsCurrVal+=e;}}class Fo extends Io{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Jr,this.clientEncoder=new qr,this.leftClockEncoder=new Jr,this.rightClockEncoder=new Jr,this.infoEncoder=new Hr(Lr),this.stringEncoder=new Kr,this.parentInfoEncoder=new Hr(Lr),this.typeRefEncoder=new qr,this.lenEncoder=new qr;}toUint8Array(){const e=Ir();return Rr(e,0),Ur(e,this.keyClockEncoder.toUint8Array()),Ur(e,this.clientEncoder.toUint8Array()),Ur(e,this.leftClockEncoder.toUint8Array()),Ur(e,this.rightClockEncoder.toUint8Array()),Ur(e,Er(this.infoEncoder)),Ur(e,this.stringEncoder.toUint8Array()),Ur(e,Er(this.parentInfoEncoder)),Ur(e,this.typeRefEncoder.toUint8Array()),Ur(e,this.lenEncoder.toUint8Array()),jr(e,Er(this.restEncoder)),Er(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock);}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock);}writeClient(e){this.clientEncoder.write(e);}writeInfo(e){this.infoEncoder.write(e);}writeString(e){this.stringEncoder.write(e);}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0);}writeTypeRef(e){this.typeRefEncoder.write(e);}writeLen(e){this.lenEncoder.write(e);}writeAny(e){Yr(this.restEncoder,e);}writeBuf(e){Ur(this.restEncoder,e);}writeJSON(e){Yr(this.restEncoder,e);}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t);}}const Eo=(e,t,a)=>{const i=new Map;a.forEach(((e,a)=>{Xo(t,a)>e&&i.set(a,e);})),Ko(t).forEach(((e,t)=>{a.has(t)||i.set(t,0);})),Rr(e.restEncoder,i.size),lr(i.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([a,i])=>{((e,t,a,i)=>{i=mr(i,t[0].id.clock);const n=el(t,i);Rr(e.restEncoder,t.length-n),e.writeClient(a),Rr(e.restEncoder,i);const r=t[n];r.write(e,i-r.id.clock);for(let a=n+1;a<t.length;a++)t[a].write(e,0);})(e,t.clients.get(a),a,i);}));},Do=(e,t,a,i=new xo(e))=>dl(t,(e=>{e.local=!1;let t=!1;const a=e.doc,n=a.store,r=((e,t)=>{const a=ar(),i=os(e.restDecoder);for(let n=0;n<i;n++){const i=os(e.restDecoder),n=new Array(i),r=e.readClient();let s=os(e.restDecoder);a.set(r,{i:0,refs:n});for(let a=0;a<i;a++){const i=e.readInfo();switch(31&i){case 0:{const t=e.readLen();n[a]=new Au(Go(r,s),t),s+=t;break}case 10:{const t=os(e.restDecoder);n[a]=new Hu(Go(r,s),t),s+=t;break}default:{const o=!(192&i),l=new zu(Go(r,s),null,(i&vr)===vr?e.readLeftID():null,null,(i&br)===br?e.readRightID():null,o?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,!o||32&~i?null:e.readString(),Wu(e,i));n[a]=l,s+=l.length;}}}}return a})(i,a),s=((e,t,a)=>{const i=[];let n=lr(a.keys()).sort(((e,t)=>e-t));if(0===n.length)return null;const r=()=>{if(0===n.length)return null;let e=a.get(n[n.length-1]);for(;e.refs.length===e.i;){if(n.pop(),!(n.length>0))return null;e=a.get(n[n.length-1]);}return e};let s=r();if(null===s)return null;const o=new Jo,l=new Map,u=(e,t)=>{const a=l.get(e);(null==a||a>t)&&l.set(e,t);};let c=s.refs[s.i++];const d=new Map,p=()=>{for(const e of i){const t=e.id.client,i=a.get(t);i?(i.i--,o.clients.set(t,i.refs.slice(i.i)),a.delete(t),i.i=0,i.refs=[]):o.clients.set(t,[e]),n=n.filter((e=>e!==t));}i.length=0;};for(;;){if(c.constructor!==Hu){const n=nr(d,c.id.client,(()=>Xo(t,c.id.client)))-c.id.clock;if(n<0)i.push(c),u(c.id.client,c.id.clock-1),p();else {const r=c.getMissing(e,t);if(null!==r){i.push(c);const e=a.get(r)||{refs:[],i:0};if(e.refs.length!==e.i){c=e.refs[e.i++];continue}u(r,Xo(t,r)),p();}else (0===n||n<c.length)&&(c.integrate(e,n),d.set(c.id.client,c.id.clock+c.length));}}if(i.length>0)c=i.pop();else if(null!==s&&s.i<s.refs.length)c=s.refs[s.i++];else {if(s=r(),null===s)break;c=s.refs[s.i++];}}if(o.clients.size>0){const e=new Fo;return Eo(e,o,new Map),Rr(e.restEncoder,0),{missing:l,update:e.toUint8Array()}}return null})(e,n,r),o=n.pendingStructs;if(o){for(const[e,a]of o.missing)if(a<Xo(n,e)){t=!0;break}if(s){for(const[e,t]of s.missing){const a=o.missing.get(e);(null==a||a>t)&&o.missing.set(e,t);}o.update=yl([o.update,s.update]);}}else n.pendingStructs=s;const l=Ao(i,e,n);if(n.pendingDs){const t=new xo(ns(n.pendingDs));os(t.restDecoder);const a=Ao(t,e,n);n.pendingDs=l&&a?yl([l,a]):l||a;}else n.pendingDs=l;if(t){const t=n.pendingStructs.update;n.pendingStructs=null,Lo(e.doc,t);}}),a,false),Lo=(e,t,a,i=xo)=>{const n=ns(t);Do(n,e,a,new i(n));},Ro=(e,t=new Uint8Array([0]),a=new Fo)=>{((e,t,a=new Map)=>{Eo(e,t.store,a),_o(e,vo(t.store));})(a,e,Po(t));const i=[a.toUint8Array()];if(e.store.pendingDs&&i.push(e.store.pendingDs),e.store.pendingStructs&&i.push(gl(e.store.pendingStructs.update,t)),i.length>1){if(a.constructor===Co)return fl$2(i.map(((e,t)=>0===t?e:wl(e))));if(a.constructor===Fo)return yl(i)}return i[0]},Po=e=>(e=>{const t=new Map,a=os(e.restDecoder);for(let i=0;i<a;i++){const a=os(e.restDecoder),i=os(e.restDecoder);t.set(a,i);}return t})(new No(ns(e))),Oo=(e,t)=>(Rr(e.restEncoder,t.size),lr(t.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,a])=>{Rr(e.restEncoder,t),Rr(e.restEncoder,a);})),e),Bo=(e,t=new Io)=>(e instanceof Map?Oo(t,e):((e,t)=>{Oo(e,Ko(t.store));})(t,e),t.toUint8Array());class $o{constructor(){this.l=[];}}const jo=()=>new $o,Uo=(e,t)=>e.l.push(t),zo=(e,t)=>{const a=e.l,i=a.length;e.l=a.filter((e=>t!==e)),i===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.");},Wo=(e,t,a)=>Ls(e.l,[t,a]);class Yo{constructor(e,t){this.client=e,this.clock=t;}}const Ho=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,Go=(e,t)=>new Yo(e,t),qo=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!yo(t.ds,e.id),Zo=(e,t)=>{const a=nr(e.meta,Zo,rr),i=e.doc.store;a.has(t)||(t.sv.forEach(((t,a)=>{t<Xo(i,a)&&il(e,Go(a,t));})),mo(e,t.ds,(e=>{})),a.add(t));};class Jo{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null;}}const Ko=e=>{const t=new Map;return e.clients.forEach(((e,a)=>{const i=e[e.length-1];t.set(a,i.id.clock+i.length);})),t},Xo=(e,t)=>{const a=e.clients.get(t);if(void 0===a)return 0;const i=a[a.length-1];return i.id.clock+i.length},Qo=(e,t)=>{let a=e.clients.get(t.id.client);if(void 0===a)a=[],e.clients.set(t.id.client,a);else {const e=a[a.length-1];if(e.id.clock+e.length!==t.id.clock)throw es()}a.push(t);},el=(e,t)=>{let a=0,i=e.length-1,n=e[i],r=n.id.clock;if(r===t)return i;let s=pr(t/(r+n.length-1)*i);for(;a<=i;){if(n=e[s],r=n.id.clock,r<=t){if(t<r+n.length)return s;a=s+1;}else i=s-1;s=pr((a+i)/2);}throw es()},tl=(e,t)=>{const a=e.clients.get(t.client);return a[el(a,t.clock)]},al=(e,t,a)=>{const i=el(t,a),n=t[i];return n.id.clock<a&&n instanceof zu?(t.splice(i+1,0,Uu(e,n,a-n.id.clock)),i+1):i},il=(e,t)=>{const a=e.doc.store.clients.get(t.client);return a[al(e,a,t.clock)]},nl=(e,t,a)=>{const i=t.clients.get(a.client),n=el(i,a.clock),r=i[n];return a.clock!==r.id.clock+r.length-1&&r.constructor!==Au&&i.splice(n+1,0,Uu(e,r,a.clock-r.id.clock+1)),r},rl=(e,t,a,i,n)=>{if(0===i)return;const r=a+i;let s,o=al(e,t,a);do{s=t[o++],r<s.id.clock+s.length&&al(e,t,r),n(s);}while(o<t.length&&t[o].id.clock<r)};class sl{constructor(e,t,a){this.doc=e,this.deleteSet=new fo,this.beforeState=Ko(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=a,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=false;}}const ol=(e,t)=>!(0===t.deleteSet.clients.size&&!((e,t)=>{for(const[a,i]of e)if(t(i,a))return true;return false})(t.afterState,((e,a)=>t.beforeState.get(a)!==e)))&&(go(t.deleteSet),((e,t)=>{Eo(e,t.doc.store,t.beforeState);})(e,t),_o(e,t.deleteSet),true),ll=(e,t,a)=>{const i=t._item;(null===i||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&nr(e.changed,t,rr).add(a);},ul=(e,t)=>{let a=e[t],i=e[t-1],n=t;for(;n>0&&(i.deleted===a.deleted&&i.constructor===a.constructor&&i.mergeWith(a));a=i,i=e[--n-1])a instanceof zu&&null!==a.parentSub&&a.parent._map.get(a.parentSub)===a&&a.parent._map.set(a.parentSub,i);const r=t-n;return r&&e.splice(t+1-r,r),r},cl=(e,t)=>{if(t<e.length){const a=e[t],i=a.doc,n=i.store,r=a.deleteSet,s=a._mergeStructs;try{go(r),a.afterState=Ko(a.doc.store),i.emit("beforeObserverCalls",[a,i]);const e=[];a.changed.forEach(((t,i)=>e.push((()=>{null!==i._item&&i._item.deleted||i._callObserver(a,t);})))),e.push((()=>{a.changedParentTypes.forEach(((e,t)=>{t._dEH.l.length>0&&(null===t._item||!t._item.deleted)&&((e=e.filter((e=>null===e.target._item||!e.target._item.deleted))).forEach((e=>{e.currentTarget=t,e._path=null;})),e.sort(((e,t)=>e.path.length-t.path.length)),Wo(t._dEH,e,a));}));})),e.push((()=>i.emit("afterTransaction",[a,i]))),Ls(e,[]),a._needFormattingCleanup&&du(a);}finally{i.gc&&((e,t,a)=>{for(const[i,n]of e.clients.entries()){const e=t.clients.get(i);for(let i=n.length-1;i>=0;i--){const r=n[i],s=r.clock+r.len;for(let i=el(e,r.clock),n=e[i];i<e.length&&n.id.clock<s;n=e[++i]){const n=e[i];if(r.clock+r.len<=n.id.clock)break;n instanceof zu&&n.deleted&&!n.keep&&a(n)&&n.gc(t,false);}}}})(r,n,i.gcFilter),((e,t)=>{e.clients.forEach(((e,a)=>{const i=t.clients.get(a);for(let t=e.length-1;t>=0;t--){const a=e[t];for(let e=fr(i.length-1,1+el(i,a.clock+a.len-1)),t=i[e];e>0&&t.id.clock>=a.clock;t=i[e])e-=1+ul(i,e);}}));})(r,n),a.afterState.forEach(((e,t)=>{const i=a.beforeState.get(t)||0;if(i!==e){const e=n.clients.get(t),a=mr(el(e,i),1);for(let t=e.length-1;t>=a;)t-=1+ul(e,t);}}));for(let e=s.length-1;e>=0;e--){const{client:t,clock:a}=s[e].id,i=n.clients.get(t),r=el(i,a);r+1<i.length&&ul(i,r+1)>1||r>0&&ul(i,r);}if(a.local||a.afterState.get(i.clientID)===a.beforeState.get(i.clientID)||(((...e)=>{console.log(...lo(e)),uo.forEach((t=>t.print(e)));})(ro,Xs,"[yjs] ",Qs,io,"Changed the client-id because another client seems to be using it."),i.clientID=ko()),i.emit("afterTransactionCleanup",[a,i]),i._observers.has("update")){const e=new Co;ol(e,a)&&i.emit("update",[e.toUint8Array(),a.origin,i,a]);}if(i._observers.has("updateV2")){const e=new Fo;ol(e,a)&&i.emit("updateV2",[e.toUint8Array(),a.origin,i,a]);}const{subdocsAdded:o,subdocsLoaded:l,subdocsRemoved:u}=a;(o.size>0||u.size>0||l.size>0)&&(o.forEach((e=>{e.clientID=i.clientID,null==e.collectionid&&(e.collectionid=i.collectionid),i.subdocs.add(e);})),u.forEach((e=>i.subdocs.delete(e))),i.emit("subdocs",[{loaded:l,added:o,removed:u},i,a]),u.forEach((e=>e.destroy()))),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):cl(e,t+1);}}},dl=(e,t,a=null,i=true)=>{const n=e._transactionCleanups;let r=false,s=null;null===e._transaction&&(r=true,e._transaction=new sl(e,a,i),n.push(e._transaction),1===n.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{s=t(e._transaction);}finally{if(r){const t=e._transaction===n[0];e._transaction=null,t&&cl(n,0);}}return s};class pl{constructor(e,t){this.gen=function*(e){const t=os(e.restDecoder);for(let a=0;a<t;a++){const t=os(e.restDecoder),a=e.readClient();let i=os(e.restDecoder);for(let n=0;n<t;n++){const t=e.readInfo();if(10===t){const t=os(e.restDecoder);yield new Hu(Go(a,i),t),i+=t;}else if(31&t){const n=!(192&t),r=new zu(Go(a,i),null,(t&vr)===vr?e.readLeftID():null,null,(t&br)===br?e.readRightID():null,n?e.readParentInfo()?e.readString():e.readLeftID():null,!n||32&~t?null:e.readString(),Wu(e,t));yield r,i+=r.length;}else {const t=e.readLen();yield new Au(Go(a,i),t),i+=t;}}}}(e),this.curr=null,this.done=false,this.filterSkips=t,this.next();}next(){do{this.curr=this.gen.next().value||null;}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Hu);return this.curr}}class hl{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[];}}const fl$2=e=>yl(e,To,Co),ml=(e,t)=>{if(e.constructor===Au){const{client:a,clock:i}=e.id;return new Au(Go(a,i+t),e.length-t)}if(e.constructor===Hu){const{client:a,clock:i}=e.id;return new Hu(Go(a,i+t),e.length-t)}{const a=e,{client:i,clock:n}=a.id;return new zu(Go(i,n+t),null,Go(i,n+t-1),null,a.rightOrigin,a.parent,a.parentSub,a.content.splice(t))}},yl=(e,t=xo,a=Fo)=>{if(1===e.length)return e[0];const i=e.map((e=>new t(ns(e))));let n=i.map((e=>new pl(e,true))),r=null;const s=new a,o=new hl(s);for(;n=n.filter((e=>null!==e.curr)),n.sort(((e,t)=>{if(e.curr.id.client===t.curr.id.client){const a=e.curr.id.clock-t.curr.id.clock;return 0===a?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Hu?1:-1:a}return t.curr.id.client-e.curr.id.client})),0!==n.length;){const e=n[0],t=e.curr.id.client;if(null!==r){let a=e.curr,i=false;for(;null!==a&&a.id.clock+a.length<=r.struct.id.clock+r.struct.length&&a.id.client>=r.struct.id.client;)a=e.next(),i=true;if(null===a||a.id.client!==t||i&&a.id.clock>r.struct.id.clock+r.struct.length)continue;if(t!==r.struct.id.client)vl(o,r.struct,r.offset),r={struct:a,offset:0},e.next();else if(r.struct.id.clock+r.struct.length<a.id.clock)if(r.struct.constructor===Hu)r.struct.length=a.id.clock+a.length-r.struct.id.clock;else {vl(o,r.struct,r.offset);const e=a.id.clock-r.struct.id.clock-r.struct.length;r={struct:new Hu(Go(t,r.struct.id.clock+r.struct.length),e),offset:0};}else {const t=r.struct.id.clock+r.struct.length-a.id.clock;t>0&&(r.struct.constructor===Hu?r.struct.length-=t:a=ml(a,t)),r.struct.mergeWith(a)||(vl(o,r.struct,r.offset),r={struct:a,offset:0},e.next());}}else r={struct:e.curr,offset:0},e.next();for(let a=e.curr;null!==a&&a.id.client===t&&a.id.clock===r.struct.id.clock+r.struct.length&&a.constructor!==Hu;a=e.next())vl(o,r.struct,r.offset),r={struct:a,offset:0};}null!==r&&(vl(o,r.struct,r.offset),r=null),_l(o);const l=(e=>{const t=new fo;for(let a=0;a<e.length;a++)e[a].clients.forEach(((i,n)=>{if(!t.clients.has(n)){const r=i.slice();for(let t=a+1;t<e.length;t++)or(r,e[t].clients.get(n)||[]);t.clients.set(n,r);}}));return go(t),t})(i.map((e=>wo(e))));return _o(s,l),s.toUint8Array()},gl=(e,t,a=xo,i=Fo)=>{const n=Po(t),r=new i,s=new hl(r),o=new a(ns(e)),l=new pl(o,false);for(;l.curr;){const e=l.curr,t=e.id.client,a=n.get(t)||0;if(l.curr.constructor!==Hu)if(e.id.clock+e.length>a)for(vl(s,e,mr(a-e.id.clock,0)),l.next();l.curr&&l.curr.id.client===t;)vl(s,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===t&&l.curr.id.clock+l.curr.length<=a;)l.next();else l.next();}_l(s);const u=wo(o);return _o(r,u),r.toUint8Array()},bl=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Er(e.encoder.restEncoder)}),e.encoder.restEncoder=Ir(),e.written=0);},vl=(e,t,a)=>{e.written>0&&e.currClient!==t.id.client&&bl(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),Rr(e.encoder.restEncoder,t.id.clock+a)),t.write(e.encoder,a),e.written++;},_l=e=>{bl(e);const t=e.encoder.restEncoder;Rr(t,e.clientStructs.length);for(let a=0;a<e.clientStructs.length;a++){const i=e.clientStructs[a];Rr(t,i.written),jr(t,i.restEncoder);}},wl=e=>((e,t,a,i)=>{const n=new a(ns(e)),r=new pl(n,false),s=new i,o=new hl(s);for(let e=r.curr;null!==e;e=r.next())vl(o,t(e),0);_l(o);const l=wo(n);return _o(s,l),s.toUint8Array()})(e,Rs,xo,Co),Al="You must not compute changes after the event-handler fired.";class kl{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null;}get path(){return this._path||(this._path=Sl(this.currentTarget,this.target))}deletes(e){return yo(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Xr(Al);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach((a=>{if(null!==a){const i=t._map.get(a);let n,r;if(this.adds(i)){let e=i.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(i)){if(null===e||!this.deletes(e))return;n="delete",r=sr(e.content.getContent());}else null!==e&&this.deletes(e)?(n="update",r=sr(e.content.getContent())):(n="add",r=void 0);}else {if(!this.deletes(i))return;n="delete",r=sr(i.content.getContent());}e.set(a,{action:n,oldValue:r});}})),this._keys=e;}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw Xr(Al);const t=this.target,a=rr(),i=rr(),n=[];e={added:a,deleted:i,delta:n,keys:this.keys};if(this.transaction.changed.get(t).has(null)){let e=null;const r=()=>{e&&n.push(e);};for(let n=t._start;null!==n;n=n.right)n.deleted?this.deletes(n)&&!this.adds(n)&&(null!==e&&void 0!==e.delete||(r(),e={delete:0}),e.delete+=n.length,i.add(n)):this.adds(n)?(null!==e&&void 0!==e.insert||(r(),e={insert:[]}),e.insert=e.insert.concat(n.content.getContent()),a.add(n)):(null!==e&&void 0!==e.retain||(r(),e={retain:0}),e.retain+=n.length);null!==e&&void 0===e.retain&&r();}this._changes=e;}return e}}const Sl=(e,t)=>{const a=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)a.unshift(t._item.parentSub);else {let e=0,i=t._item.parent._start;for(;i!==t._item&&null!==i;)!i.deleted&&i.countable&&(e+=i.length),i=i.right;a.unshift(e);}t=t._item.parent;}return a},Nl=()=>{((...e)=>{console.warn(...lo(e)),e.unshift(ro),uo.forEach((t=>t.print(e)));})("Invalid access: Add Yjs type to a document before reading data.");};let Tl=0;class Ml{constructor(e,t){e.marker=true,this.p=e,this.index=t,this.timestamp=Tl++;}}const xl=(e,t,a)=>{e.p.marker=false,e.p=t,t.marker=true,e.index=a,e.timestamp=Tl++;},Vl=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const a=0===e._searchMarker.length?null:e._searchMarker.reduce(((e,a)=>hr(t-e.index)<hr(t-a.index)?e:a));let i=e._start,n=0;for(null!==a&&(i=a.p,n=a.index,(e=>{e.timestamp=Tl++;})(a));null!==i.right&&n<t;){if(!i.deleted&&i.countable){if(t<n+i.length)break;n+=i.length;}i=i.right;}for(;null!==i.left&&n>t;)i=i.left,!i.deleted&&i.countable&&(n-=i.length);for(;null!==i.left&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(n-=i.length);return null!==a&&hr(a.index-n)<i.parent.length/80?(xl(a,i,n),a):((e,t,a)=>{if(e.length>=80){const i=e.reduce(((e,t)=>e.timestamp<t.timestamp?e:t));return xl(i,t,a),i}{const i=new Ml(t,a);return e.push(i),i}})(e._searchMarker,i,n)},Cl=(e,t,a)=>{for(let i=e.length-1;i>=0;i--){const n=e[i];if(a>0){let t=n.p;for(t.marker=false;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(n.index-=t.length);if(null===t||true===t.marker){e.splice(i,1);continue}n.p=t,t.marker=true;}(t<n.index||a>0&&t===n.index)&&(n.index=mr(t,n.index+a));}},Il=(e,t,a)=>{const i=e,n=t.changedParentTypes;for(;nr(n,e,(()=>[])).push(a),null!==e._item;)e=e._item.parent;Wo(i._eH,a,t);};class Fl{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=jo(),this._dEH=jo(),this._searchMarker=null;}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t;}_copy(){throw Qr()}clone(){throw Qr()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0);}observe(e){Uo(this._eH,e);}observeDeep(e){Uo(this._dEH,e);}unobserve(e){zo(this._eH,e);}unobserveDeep(e){zo(this._dEH,e);}toJSON(){}}const El=(e,t,a)=>{e.doc??Nl(),t<0&&(t=e._length+t),a<0&&(a=e._length+a);let i=a-t;const n=[];let r=e._start;for(;null!==r&&i>0;){if(r.countable&&!r.deleted){const e=r.content.getContent();if(e.length<=t)t-=e.length;else {for(let a=t;a<e.length&&i>0;a++)n.push(e[a]),i--;t=0;}}r=r.right;}return n},Dl=e=>{e.doc??Nl();const t=[];let a=e._start;for(;null!==a;){if(a.countable&&!a.deleted){const e=a.content.getContent();for(let a=0;a<e.length;a++)t.push(e[a]);}a=a.right;}return t},Ll=(e,t)=>{let a=0,i=e._start;for(e.doc??Nl();null!==i;){if(i.countable&&!i.deleted){const n=i.content.getContent();for(let i=0;i<n.length;i++)t(n[i],a++,e);}i=i.right;}},Rl=(e,t)=>{const a=[];return Ll(e,((i,n)=>{a.push(t(i,n,e));})),a},Pl=e=>{let t=e._start,a=null,i=0;return {[Symbol.iterator](){return this},next:()=>{if(null===a){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return {done:true,value:void 0};a=t.content.getContent(),i=0,t=t.right;}const e=a[i++];return a.length<=i&&(a=null),{done:false,value:e}}}},Ol=(e,t)=>{e.doc??Nl();const a=Vl(e,t);let i=e._start;for(null!==a&&(i=a.p,t-=a.index);null!==i;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length;}},Bl=(e,t,a,i)=>{let n=a;const r=e.doc,s=r.clientID,o=r.store,l=null===a?t._start:a.right;let u=[];const c=()=>{u.length>0&&(n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new Iu(u)),n.integrate(e,0),u=[]);};i.forEach((a=>{if(null===a)u.push(a);else switch(a.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(a);break;default:switch(c(),a.constructor){case Uint8Array:case ArrayBuffer:n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new ku(new Uint8Array(a))),n.integrate(e,0);break;case So:n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new Tu(a)),n.integrate(e,0);break;default:if(!(a instanceof Fl))throw new Error("Unexpected content type in insert operation");n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new ju(a)),n.integrate(e,0);}}})),c();},$l=()=>Xr("Length exceeded!"),jl=(e,t,a,i)=>{if(a>t._length)throw $l();if(0===a)return t._searchMarker&&Cl(t._searchMarker,a,i.length),Bl(e,t,null,i);const n=a,r=Vl(t,a);let s=t._start;for(null!==r&&(s=r.p,0===(a-=r.index)&&(s=s.prev,a+=s&&s.countable&&!s.deleted?s.length:0));null!==s;s=s.right)if(!s.deleted&&s.countable){if(a<=s.length){a<s.length&&il(e,Go(s.id.client,s.id.clock+a));break}a-=s.length;}return t._searchMarker&&Cl(t._searchMarker,n,i.length),Bl(e,t,s,i)},Ul=(e,t,a,i)=>{if(0===i)return;const n=a,r=i,s=Vl(t,a);let o=t._start;for(null!==s&&(o=s.p,a-=s.index);null!==o&&a>0;o=o.right)!o.deleted&&o.countable&&(a<o.length&&il(e,Go(o.id.client,o.id.clock+a)),a-=o.length);for(;i>0&&null!==o;)o.deleted||(i<o.length&&il(e,Go(o.id.client,o.id.clock+i)),o.delete(e),i-=o.length),o=o.right;if(i>0)throw $l();t._searchMarker&&Cl(t._searchMarker,n,-r+i);},zl=(e,t,a)=>{const i=t._map.get(a);void 0!==i&&i.delete(e);},Wl=(e,t,a,i)=>{const n=t._map.get(a)||null,r=e.doc,s=r.clientID;let o;if(null==i)o=new Iu([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new Iu([i]);break;case Uint8Array:o=new ku(i);break;case So:o=new Tu(i);break;default:if(!(i instanceof Fl))throw new Error("Unexpected content type");o=new ju(i);}new zu(Go(s,Xo(r.store,s)),n,n&&n.lastId,null,null,t,a,o).integrate(e,0);},Yl=(e,t)=>{e.doc??Nl();const a=e._map.get(t);return void 0===a||a.deleted?void 0:a.content.getContent()[a.length-1]},Hl=e=>{const t={};return e.doc??Nl(),e._map.forEach(((e,a)=>{e.deleted||(t[a]=e.content.getContent()[e.length-1]);})),t},Gl=(e,t)=>{e.doc??Nl();const a=e._map.get(t);return void 0!==a&&!a.deleted},ql=e=>{return e.doc??Nl(),t=e._map.entries(),a=e=>!e[1].deleted,co((()=>{let e;do{e=t.next();}while(!e.done&&!a(e.value));return e}));var t,a;};class Zl extends kl{}class Jl extends Fl{constructor(){super(),this._prelimContent=[],this._searchMarker=[];}static from(e){const t=new Jl;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null;}_copy(){return new Jl}clone(){const e=new Jl;return e.insert(0,this.toArray().map((e=>e instanceof Fl?e.clone():e))),e}get length(){return this.doc??Nl(),this._length}_callObserver(e,t){super._callObserver(e,t),Il(this,e,new Zl(this,e));}insert(e,t){null!==this.doc?dl(this.doc,(a=>{jl(a,this,e,t);})):this._prelimContent.splice(e,0,...t);}push(e){null!==this.doc?dl(this.doc,(t=>{((e,t,a)=>{let i=(t._searchMarker||[]).reduce(((e,t)=>t.index>e.index?t:e),{index:0,p:t._start}).p;if(i)for(;i.right;)i=i.right;Bl(e,t,i,a);})(t,this,e);})):this._prelimContent.push(...e);}unshift(e){this.insert(0,e);}delete(e,t=1){null!==this.doc?dl(this.doc,(a=>{Ul(a,this,e,t);})):this._prelimContent.splice(e,t);}get(e){return Ol(this,e)}toArray(){return Dl(this)}slice(e=0,t=this.length){return El(this,e,t)}toJSON(){return this.map((e=>e instanceof Fl?e.toJSON():e))}map(e){return Rl(this,e)}forEach(e){Ll(this,e);}[Symbol.iterator](){return Pl(this)}_write(e){e.writeTypeRef(Du);}}class Kl extends kl{constructor(e,t,a){super(e,t),this.keysChanged=a;}}class Xl extends Fl{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?new Map:new Map(e);}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach(((e,t)=>{this.set(t,e);})),this._prelimContent=null;}_copy(){return new Xl}clone(){const e=new Xl;return this.forEach(((t,a)=>{e.set(a,t instanceof Fl?t.clone():t);})),e}_callObserver(e,t){Il(this,e,new Kl(this,e,t));}toJSON(){this.doc??Nl();const e={};return this._map.forEach(((t,a)=>{if(!t.deleted){const i=t.content.getContent()[t.length-1];e[a]=i instanceof Fl?i.toJSON():i;}})),e}get size(){return [...ql(this)].length}keys(){return po(ql(this),(e=>e[0]))}values(){return po(ql(this),(e=>e[1].content.getContent()[e[1].length-1]))}entries(){return po(ql(this),(e=>[e[0],e[1].content.getContent()[e[1].length-1]]))}forEach(e){this.doc??Nl(),this._map.forEach(((t,a)=>{t.deleted||e(t.content.getContent()[t.length-1],a,this);}));}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?dl(this.doc,(t=>{zl(t,this,e);})):this._prelimContent.delete(e);}set(e,t){return null!==this.doc?dl(this.doc,(a=>{Wl(a,this,e,t);})):this._prelimContent.set(e,t),t}get(e){return Yl(this,e)}has(e){return Gl(this,e)}clear(){null!==this.doc?dl(this.doc,(e=>{this.forEach((function(t,a,i){zl(e,i,a);}));})):this._prelimContent.clear();}_write(e){e.writeTypeRef(Lu);}}const Ql=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&((e,t)=>e===t||Cs(e)===Cs(t)&&((e,t)=>{for(const a in e)if(!t(e[a],a))return false;return true})(e,((e,a)=>(void 0!==e||Is(t,a))&&t[a]===e)))(e,t);class eu{constructor(e,t,a,i){this.left=e,this.right=t,this.index=a,this.currentAttributes=i;}forward(){if(null===this.right&&es(),this.right.content.constructor===xu)this.right.deleted||nu(this.currentAttributes,this.right.content);else this.right.deleted||(this.index+=this.right.length);this.left=this.right,this.right=this.right.right;}}const tu=(e,t,a)=>{for(;null!==t.right&&a>0;){if(t.right.content.constructor===xu)t.right.deleted||nu(t.currentAttributes,t.right.content);else t.right.deleted||(a<t.right.length&&il(e,Go(t.right.id.client,t.right.id.clock+a)),t.index+=t.right.length,a-=t.right.length);t.left=t.right,t.right=t.right.right;}return t},au=(e,t,a,i)=>{const n=new Map,r=i?Vl(t,a):null;if(r){const t=new eu(r.p.left,r.p,r.index,n);return tu(e,t,a-r.index)}{const i=new eu(null,t._start,0,n);return tu(e,i,a)}},iu=(e,t,a,i)=>{for(;null!==a.right&&(true===a.right.deleted||a.right.content.constructor===xu&&Ql(i.get(a.right.content.key),a.right.content.value));)a.right.deleted||i.delete(a.right.content.key),a.forward();const n=e.doc,r=n.clientID;i.forEach(((i,s)=>{const o=a.left,l=a.right,u=new zu(Go(r,Xo(n.store,r)),o,o&&o.lastId,l,l&&l.id,t,null,new xu(s,i));u.integrate(e,0),a.right=u,a.forward();}));},nu=(e,t)=>{const{key:a,value:i}=t;null===i?e.delete(a):e.set(a,i);},ru=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===xu&&Ql(t[e.right.content.key]??null,e.right.content.value));)e.forward();},su=(e,t,a,i)=>{const n=e.doc,r=n.clientID,s=new Map;for(const o in i){const l=i[o],u=a.currentAttributes.get(o)??null;if(!Ql(u,l)){s.set(o,u);const{left:i,right:c}=a;a.right=new zu(Go(r,Xo(n.store,r)),i,i&&i.lastId,c,c&&c.id,t,null,new xu(o,l)),a.right.integrate(e,0),a.forward();}}return s},ou=(e,t,a,i,n)=>{a.currentAttributes.forEach(((e,t)=>{ void 0===n[t]&&(n[t]=null);}));const r=e.doc,s=r.clientID;ru(a,n);const o=su(e,t,a,n),l=i.constructor===String?new Fu(i):i instanceof Fl?new ju(i):new Mu(i);let{left:u,right:c,index:d}=a;t._searchMarker&&Cl(t._searchMarker,a.index,l.getLength()),c=new zu(Go(s,Xo(r.store,s)),u,u&&u.lastId,c,c&&c.id,t,null,l),c.integrate(e,0),a.right=c,a.index=d,a.forward(),iu(e,t,a,o);},lu=(e,t,a,i,n)=>{const r=e.doc,s=r.clientID;ru(a,n);const o=su(e,t,a,n);e:for(;null!==a.right&&(i>0||o.size>0&&(a.right.deleted||a.right.content.constructor===xu));){if(!a.right.deleted)switch(a.right.content.constructor){case xu:{const{key:t,value:r}=a.right.content,s=n[t];if(void 0!==s){if(Ql(s,r))o.delete(t);else {if(0===i)break e;o.set(t,r);}a.right.delete(e);}else a.currentAttributes.set(t,r);break}default:i<a.right.length&&il(e,Go(a.right.id.client,a.right.id.clock+i)),i-=a.right.length;}a.forward();}if(i>0){let n="";for(;i>0;i--)n+="\n";a.right=new zu(Go(s,Xo(r.store,s)),a.left,a.left&&a.left.lastId,a.right,a.right&&a.right.id,t,null,new Fu(n)),a.right.integrate(e,0),a.forward();}iu(e,t,a,o);},uu=(e,t,a,i,n)=>{let r=t;const s=ar();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===xu){const e=r.content;s.set(e.key,e);}r=r.right;}let o=0,l=false;for(;t!==r;){if(a===t&&(l=true),!t.deleted){const a=t.content;switch(a.constructor){case xu:{const{key:r,value:u}=a,c=i.get(r)??null;s.get(r)===a&&c!==u||(t.delete(e),o++,l||(n.get(r)??null)!==u||c===u||(null===c?n.delete(r):n.set(r,c))),l||t.deleted||nu(n,a);break}}}t=t.right;}return o},cu=e=>{let t=0;return dl(e.doc,(a=>{let i=e._start,n=e._start,r=ar();const s=ir(r);for(;n;){if(!1===n.deleted)if(n.content.constructor===xu)nu(s,n.content);else t+=uu(a,i,n,r,s),r=ir(s),i=n;n=n.right;}})),t},du=e=>{const t=new Set,a=e.doc;for(const[i,n]of e.afterState.entries()){const r=e.beforeState.get(i)||0;n!==r&&rl(e,a.store.clients.get(i),r,n,(e=>{e.deleted||e.content.constructor!==xu||e.constructor===Au||t.add(e.parent);}));}dl(a,(a=>{mo(e,e.deleteSet,(e=>{if(e instanceof Au||!e.parent._hasFormatting||t.has(e.parent))return;const i=e.parent;e.content.constructor===xu?t.add(i):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const a=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===xu){const i=t.content.key;a.has(i)?t.delete(e):a.add(i);}t=t.left;}})(a,e);}));for(const e of t)cu(e);}));},pu=(e,t,a)=>{const i=a,n=ir(t.currentAttributes),r=t.right;for(;a>0&&null!==t.right;){if(false===t.right.deleted)switch(t.right.content.constructor){case ju:case Mu:case Fu:a<t.right.length&&il(e,Go(t.right.id.client,t.right.id.clock+a)),a-=t.right.length,t.right.delete(e);}t.forward();}r&&uu(e,r,t.right,n,t.currentAttributes);const s=(t.left||t.right).parent;return s._searchMarker&&Cl(s._searchMarker,t.index,-i+a),t};class hu extends kl{constructor(e,t,a){super(e,t),this.childListChanged=false,this.keysChanged=new Set,a.forEach((e=>{null===e?this.childListChanged=true:this.keysChanged.add(e);}));}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e;}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];dl(e,(e=>{const a=new Map,i=new Map;let n=this.target._start,r=null;const s={};let o="",l=0,u=0;const c=()=>{if(null!==r){let e=null;switch(r){case "delete":u>0&&(e={delete:u}),u=0;break;case "insert":("object"==typeof o||o.length>0)&&(e={insert:o},a.size>0&&(e.attributes={},a.forEach(((t,a)=>{null!==t&&(e.attributes[a]=t);})))),o="";break;case "retain":l>0&&(e={retain:l},(e=>{for(const t in e)return !1;return !0})(s)||(e.attributes=Ms({},s))),l=0;}e&&t.push(e),r=null;}};for(;null!==n;){switch(n.content.constructor){case ju:case Mu:this.adds(n)?this.deletes(n)||(c(),r="insert",o=n.content.getContent()[0],c()):this.deletes(n)?("delete"!==r&&(c(),r="delete"),u+=1):n.deleted||("retain"!==r&&(c(),r="retain"),l+=1);break;case Fu:this.adds(n)?this.deletes(n)||("insert"!==r&&(c(),r="insert"),o+=n.content.str):this.deletes(n)?("delete"!==r&&(c(),r="delete"),u+=n.length):n.deleted||("retain"!==r&&(c(),r="retain"),l+=n.length);break;case xu:{const{key:t,value:o}=n.content;if(this.adds(n)){if(!this.deletes(n)){const l=a.get(t)??null;Ql(l,o)?null!==o&&n.delete(e):("retain"===r&&c(),Ql(o,i.get(t)??null)?delete s[t]:s[t]=o);}}else if(this.deletes(n)){i.set(t,o);const e=a.get(t)??null;Ql(e,o)||("retain"===r&&c(),s[t]=e);}else if(!n.deleted){i.set(t,o);const a=s[t];void 0!==a&&(Ql(a,o)?null!==a&&n.delete(e):("retain"===r&&c(),null===o?delete s[t]:s[t]=o));}n.deleted||("insert"===r&&c(),nu(a,n.content));break}}n=n.right;}for(c();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop();}})),this._delta=t;}return this._delta}}class fu extends Fl{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=false;}get length(){return this.doc??Nl(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach((e=>e()));}catch(e){console.error(e);}this._pending=null;}_copy(){return new fu}clone(){const e=new fu;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const a=new hu(this,e,t);Il(this,e,a),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=true);}toString(){this.doc??Nl();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===Fu&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=true}={}){null!==this.doc?dl(this.doc,(a=>{const i=new eu(null,this._start,0,new Map);for(let n=0;n<e.length;n++){const r=e[n];if(void 0!==r.insert){const s=t||"string"!=typeof r.insert||n!==e.length-1||null!==i.right||"\n"!==r.insert.slice(-1)?r.insert:r.insert.slice(0,-1);("string"!=typeof s||s.length>0)&&ou(a,this,i,s,r.attributes||{});}else void 0!==r.retain?lu(a,this,i,r.retain,r.attributes||{}):void 0!==r.delete&&pu(a,i,r.delete);}})):this._pending.push((()=>this.applyDelta(e)));}toDelta(e,t,a){this.doc??Nl();const i=[],n=new Map,r=this.doc;let s="",o=this._start;function l(){if(s.length>0){const e={};let t=false;n.forEach(((a,i)=>{t=true,e[i]=a;}));const a={insert:s};t&&(a.attributes=e),i.push(a),s="";}}const u=()=>{for(;null!==o;){if(qo(o,e)||void 0!==t&&qo(o,t))switch(o.content.constructor){case Fu:{const i=n.get("ychange");void 0===e||qo(o,e)?void 0===t||qo(o,t)?void 0!==i&&(l(),n.delete("ychange")):void 0!==i&&i.user===o.id.client&&"added"===i.type||(l(),n.set("ychange",a?a("added",o.id):{type:"added"})):void 0!==i&&i.user===o.id.client&&"removed"===i.type||(l(),n.set("ychange",a?a("removed",o.id):{type:"removed"})),s+=o.content.str;break}case ju:case Mu:{l();const e={insert:o.content.getContent()[0]};if(n.size>0){const t={};e.attributes=t,n.forEach(((e,a)=>{t[a]=e;}));}i.push(e);break}case xu:qo(o,e)&&(l(),nu(n,o.content));}o=o.right;}l();};return e||t?dl(r,(a=>{e&&Zo(a,e),t&&Zo(a,t),u();}),"cleanup"):u(),i}insert(e,t,a){if(t.length<=0)return;const i=this.doc;null!==i?dl(i,(i=>{const n=au(i,this,e,!a);a||(a={},n.currentAttributes.forEach(((e,t)=>{a[t]=e;}))),ou(i,this,n,t,a);})):this._pending.push((()=>this.insert(e,t,a)));}insertEmbed(e,t,a){const i=this.doc;null!==i?dl(i,(i=>{const n=au(i,this,e,!a);ou(i,this,n,t,a||{});})):this._pending.push((()=>this.insertEmbed(e,t,a||{})));}delete(e,t){if(0===t)return;const a=this.doc;null!==a?dl(a,(a=>{pu(a,au(a,this,e,!0),t);})):this._pending.push((()=>this.delete(e,t)));}format(e,t,a){if(0===t)return;const i=this.doc;null!==i?dl(i,(i=>{const n=au(i,this,e,!1);null!==n.right&&lu(i,this,n,t,a);})):this._pending.push((()=>this.format(e,t,a)));}removeAttribute(e){null!==this.doc?dl(this.doc,(t=>{zl(t,this,e);})):this._pending.push((()=>this.removeAttribute(e)));}setAttribute(e,t){null!==this.doc?dl(this.doc,(a=>{Wl(a,this,e,t);})):this._pending.push((()=>this.setAttribute(e,t)));}getAttribute(e){return Yl(this,e)}getAttributes(){return Hl(this)}_write(e){e.writeTypeRef(Ru);}}class mu{constructor(e,t=()=>true){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=true,e.doc??Nl();}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==gu&&t.constructor!==yu||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item;}else e=t._start;}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=false,null===e?{value:void 0,done:true}:(this._currentNode=e,{value:e.content.type,done:false})}}class yu extends Fl{constructor(){super(),this._prelimContent=[];}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null;}_copy(){return new yu}clone(){const e=new yu;return e.insert(0,this.toArray().map((e=>e instanceof Fl?e.clone():e))),e}get length(){return this.doc??Nl(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new mu(this,e)}querySelector(e){e=e.toUpperCase();const t=new mu(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),lr(new mu(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)))}_callObserver(e,t){Il(this,e,new bu(this,t,e));}toString(){return Rl(this,(e=>e.toString())).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},a){const i=e.createDocumentFragment();return void 0!==a&&a._createAssociation(i,this),Ll(this,(n=>{i.insertBefore(n.toDOM(e,t,a),null);})),i}insert(e,t){null!==this.doc?dl(this.doc,(a=>{jl(a,this,e,t);})):this._prelimContent.splice(e,0,...t);}insertAfter(e,t){if(null!==this.doc)dl(this.doc,(a=>{const i=e&&e instanceof Fl?e._item:e;Bl(a,this,i,t);}));else {const a=this._prelimContent,i=null===e?0:a.findIndex((t=>t===e))+1;if(0===i&&null!==e)throw Xr("Reference item not found");a.splice(i,0,...t);}}delete(e,t=1){null!==this.doc?dl(this.doc,(a=>{Ul(a,this,e,t);})):this._prelimContent.splice(e,t);}toArray(){return Dl(this)}push(e){this.insert(this.length,e);}unshift(e){this.insert(0,e);}get(e){return Ol(this,e)}slice(e=0,t=this.length){return El(this,e,t)}forEach(e){Ll(this,e);}_write(e){e.writeTypeRef(Ou);}}class gu extends yu{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map;}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach(((e,t)=>{this.setAttribute(t,e);})),this._prelimAttrs=null;}_copy(){return new gu(this.nodeName)}clone(){const e=new gu(this.nodeName);return ((e,t)=>{for(const a in e)t(e[a],a);})(this.getAttributes(),((t,a)=>{"string"==typeof t&&e.setAttribute(a,t);})),e.insert(0,this.toArray().map((e=>e instanceof Fl?e.clone():e))),e}toString(){const e=this.getAttributes(),t=[],a=[];for(const t in e)a.push(t);a.sort();const i=a.length;for(let n=0;n<i;n++){const i=a[n];t.push(i+'="'+e[i]+'"');}const n=this.nodeName.toLocaleLowerCase();return `<${n}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${n}>`}removeAttribute(e){null!==this.doc?dl(this.doc,(t=>{zl(t,this,e);})):this._prelimAttrs.delete(e);}setAttribute(e,t){null!==this.doc?dl(this.doc,(a=>{Wl(a,this,e,t);})):this._prelimAttrs.set(e,t);}getAttribute(e){return Yl(this,e)}hasAttribute(e){return Gl(this,e)}getAttributes(e){return e?((e,t)=>{const a={};return e._map.forEach(((e,i)=>{let n=e;for(;null!==n&&(!t.sv.has(n.id.client)||n.id.clock>=(t.sv.get(n.id.client)||0));)n=n.left;null!==n&&qo(n,t)&&(a[i]=n.content.getContent()[n.length-1]);})),a})(this,e):Hl(this)}toDOM(e=document,t={},a){const i=e.createElement(this.nodeName),n=this.getAttributes();for(const e in n){const t=n[e];"string"==typeof t&&i.setAttribute(e,t);}return Ll(this,(n=>{i.appendChild(n.toDOM(e,t,a));})),void 0!==a&&a._createAssociation(i,this),i}_write(e){e.writeTypeRef(Pu),e.writeKey(this.nodeName);}}class bu extends kl{constructor(e,t,a){super(e,a),this.childListChanged=false,this.attributesChanged=new Set,t.forEach((e=>{null===e?this.childListChanged=true:this.attributesChanged.add(e);}));}}class vu extends Xl{constructor(e){super(),this.hookName=e;}_copy(){return new vu(this.hookName)}clone(){const e=new vu(this.hookName);return this.forEach(((t,a)=>{e.set(a,t);})),e}toDOM(e=document,t={},a){const i=t[this.hookName];let n;return n=void 0!==i?i.createDom(this):document.createElement(this.hookName),n.setAttribute("data-yjs-hook",this.hookName),void 0!==a&&a._createAssociation(n,this),n}_write(e){e.writeTypeRef(Bu),e.writeKey(this.hookName);}}class _u extends fu{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new _u}clone(){const e=new _u;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,a){const i=e.createTextNode(this.toString());return void 0!==a&&a._createAssociation(i,this),i}toString(){return this.toDelta().map((e=>{const t=[];for(const a in e.attributes){const i=[];for(const t in e.attributes[a])i.push({key:t,value:e.attributes[a][t]});i.sort(((e,t)=>e.key<t.key?-1:1)),t.push({nodeName:a,attrs:i});}t.sort(((e,t)=>e.nodeName<t.nodeName?-1:1));let a="";for(let e=0;e<t.length;e++){const i=t[e];a+=`<${i.nodeName}`;for(let e=0;e<i.attrs.length;e++){const t=i.attrs[e];a+=` ${t.key}="${t.value}"`;}a+=">";}a+=e.insert;for(let e=t.length-1;e>=0;e--)a+=`</${t[e].nodeName}>`;return a})).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef($u);}}class wu{constructor(e,t){this.id=e,this.length=t;}get deleted(){throw Qr()}mergeWith(e){return false}write(e,t,a){throw Qr()}integrate(e,t){throw Qr()}}class Au extends wu{get deleted(){return true}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,true)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Qo(e.doc.store,this);}write(e,t){e.writeInfo(0),e.writeLen(this.length-t);}getMissing(e,t){return null}}class ku{constructor(e){this.content=e;}getLength(){return 1}getContent(){return [this.content]}isCountable(){return true}copy(){return new ku(this.content)}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content);}getRef(){return 3}}class Su{constructor(e){this.len=e;}getLength(){return this.len}getContent(){return []}isCountable(){return false}copy(){return new Su(this.len)}splice(e){const t=new Su(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,true}integrate(e,t){bo(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted();}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t);}getRef(){return 1}}const Nu=(e,t)=>new So({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||false});class Tu{constructor(e){e._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=e;const t={};this.opts=t,e.gc||(t.gc=false),e.autoLoad&&(t.autoLoad=true),null!==e.meta&&(t.meta=e.meta);}getLength(){return 1}getContent(){return [this.doc]}isCountable(){return true}copy(){return new Tu(Nu(this.doc.guid,this.opts))}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc);}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc);}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts);}getRef(){return 9}}class Mu{constructor(e){this.embed=e;}getLength(){return 1}getContent(){return [this.embed]}isCountable(){return true}copy(){return new Mu(this.embed)}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed);}getRef(){return 5}}class xu{constructor(e,t){this.key=e,this.value=t;}getLength(){return 1}getContent(){return []}isCountable(){return false}copy(){return new xu(this.key,this.value)}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){const a=t.parent;a._searchMarker=null,a._hasFormatting=true;}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value);}getRef(){return 6}}class Vu{constructor(e){this.arr=e;}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return true}copy(){return new Vu(this.arr)}splice(e){const t=new Vu(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),true}integrate(e,t){}delete(e){}gc(e){}write(e,t){const a=this.arr.length;e.writeLen(a-t);for(let i=t;i<a;i++){const t=this.arr[i];e.writeString(void 0===t?"undefined":JSON.stringify(t));}}getRef(){return 2}}const Cu="development"===Us("node_env");class Iu{constructor(e){this.arr=e,Cu&&Es(e);}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return true}copy(){return new Iu(this.arr)}splice(e){const t=new Iu(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),true}integrate(e,t){}delete(e){}gc(e){}write(e,t){const a=this.arr.length;e.writeLen(a-t);for(let i=t;i<a;i++){const t=this.arr[i];e.writeAny(t);}}getRef(){return 8}}class Fu{constructor(e){this.str=e;}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return true}copy(){return new Fu(this.str)}splice(e){const t=new Fu(this.str.slice(e));this.str=this.str.slice(0,e);const a=this.str.charCodeAt(e-1);return a>=55296&&a<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,true}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(0===t?this.str:this.str.slice(t));}getRef(){return 4}}const Eu=[e=>new Jl,e=>new Xl,e=>new fu,e=>new gu(e.readKey()),e=>new yu,e=>new vu(e.readKey()),e=>new _u],Du=0,Lu=1,Ru=2,Pu=3,Ou=4,Bu=5,$u=6;class ju{constructor(e){this.type=e;}getLength(){return 1}getContent(){return [this.type]}isCountable(){return true}copy(){return new ju(this.type._copy())}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){this.type._integrate(e.doc,t);}delete(e){let t=this.type._start;for(;null!==t;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach((t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e);})),e.changed.delete(this.type);}gc(e){let t=this.type._start;for(;null!==t;)t.gc(e,true),t=t.right;this.type._start=null,this.type._map.forEach((t=>{for(;null!==t;)t.gc(e,true),t=t.left;})),this.type._map=new Map;}write(e,t){this.type._write(e);}getRef(){return 7}}const Uu=(e,t,a)=>{const{client:i,clock:n}=t.id,r=new zu(Go(i,n+a),t,Go(i,n+a-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(a));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=true),null!==t.redone&&(r.redone=Go(t.redone.client,t.redone.clock+a)),t.right=r,null!==r.right&&(r.right.left=r),e._mergeStructs.push(r),null!==r.parentSub&&null===r.right&&r.parent._map.set(r.parentSub,r),t.length=a,r};class zu extends wu{constructor(e,t,a,i,n,r,s,o){super(e,o.getLength()),this.origin=a,this.left=t,this.right=i,this.rightOrigin=n,this.parent=r,this.parentSub=s,this.redone=null,this.content=o,this.info=this.content.isCountable()?2:0;}set marker(e){(8&this.info)>0!==e&&(this.info^=8);}get marker(){return (8&this.info)>0}get keep(){return (1&this.info)>0}set keep(e){this.keep!==e&&(this.info^=1);}get countable(){return (2&this.info)>0}get deleted(){return (4&this.info)>0}set deleted(e){this.deleted!==e&&(this.info^=4);}markDeleted(){this.info|=4;}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Xo(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Xo(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Yo&&this.id.client!==this.parent.client&&this.parent.clock>=Xo(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=nl(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=il(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Au||this.right&&this.right.constructor===Au)this.parent=null;else if(this.parent){if(this.parent.constructor===Yo){const e=tl(t,this.parent);e.constructor===Au?this.parent=null:this.parent=e.content.type;}}else this.left&&this.left.constructor===zu?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===zu&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=nl(e,e.doc.store,Go(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,a=this.left;if(null!==a)t=a.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const i=new Set,n=new Set;for(;null!==t&&t!==this.right;){if(n.add(t),i.add(t),Ho(this.origin,t.origin)){if(t.id.client<this.id.client)a=t,i.clear();else if(Ho(this.rightOrigin,t.rightOrigin))break}else {if(null===t.origin||!n.has(tl(e.doc.store,t.origin)))break;i.has(tl(e.doc.store,t.origin))||(a=t,i.clear());}t=t.right;}this.left=a;}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this;}else {let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e;}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Qo(e.doc.store,this),this.content.integrate(e,this),ll(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e);}else new Au(this.id,this.length).integrate(e,0);}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:Go(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Ho(e.origin,this.lastId)&&this.right===e&&Ho(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach((t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length));})),e.keep&&(this.keep=true),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,true}return false}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),bo(e.deleteSet,this.id.client,this.id.clock,this.length),ll(e,t,this.parentSub),this.content.delete(e);}}gc(e,t){if(!this.deleted)throw es();this.content.gc(e),t?((e,t,a)=>{const i=e.clients.get(t.id.client);i[el(i,t.id.clock)]=a;})(e,this,new Au(this.id,this.length)):this.content=new Su(this.length);}write(e,t){const a=t>0?Go(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,n=this.parentSub,r=31&this.content.getRef()|(null===a?0:vr)|(null===i?0:br)|(null===n?0:32);if(e.writeInfo(r),null!==a&&e.writeLeftID(a),null!==i&&e.writeRightID(i),null===a&&null===i){const t=this.parent;if(void 0!==t._item){const a=t._item;if(null===a){const a=(e=>{for(const[t,a]of e.doc.share.entries())if(a===e)return t;throw es()})(t);e.writeParentInfo(true),e.writeString(a);}else e.writeParentInfo(false),e.writeLeftID(a.id);}else t.constructor===String?(e.writeParentInfo(true),e.writeString(t)):t.constructor===Yo?(e.writeParentInfo(false),e.writeLeftID(t)):es();null!==n&&e.writeString(n);}this.content.write(e,t);}}const Wu=(e,t)=>Yu[31&t](e),Yu=[()=>{es();},e=>new Su(e.readLen()),e=>{const t=e.readLen(),a=[];for(let i=0;i<t;i++){const t=e.readString();"undefined"===t?a.push(void 0):a.push(JSON.parse(t));}return new Vu(a)},e=>new ku(e.readBuf()),e=>new Fu(e.readString()),e=>new Mu(e.readJSON()),e=>new xu(e.readKey(),e.readJSON()),e=>new ju(Eu[e.readTypeRef()](e)),e=>{const t=e.readLen(),a=[];for(let i=0;i<t;i++)a.push(e.readAny());return new Iu(a)},e=>new Tu(Nu(e.readString(),e.readAny())),()=>{es();}];class Hu extends wu{get deleted(){return true}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,true)}integrate(e,t){es();}write(e,t){e.writeInfo(10),Rr(e.restEncoder,this.length-t);}getMissing(e,t){return null}}const Gu="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},qu="__ $YJS$ __";true===Gu[qu]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Gu[qu]=true;const Zu=new Map;const Ju="undefined"==typeof BroadcastChannel?class{constructor(e){var t;this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&null!==this.onmessage&&this.onmessage({data:qs(t.newValue||"")}),t=this._onChange,Ns||addEventListener("storage",t);}postMessage(e){Ts.setItem(this.room,Gs(new Uint8Array(e)));}close(){var e;e=this._onChange,Ns||removeEventListener("storage",e);}}:BroadcastChannel,Ku=e=>nr(Zu,e,(()=>{const t=rr(),a=new Ju(e);return a.onmessage=e=>t.forEach((t=>t(e.data,"broadcastchannel"))),{bc:a,subs:t}})),Xu=(e,t,a=null)=>{const i=Ku(e);i.bc.postMessage(t),i.subs.forEach((e=>e(t,a)));},Qu=(e,t)=>{Rr(e,0);const a=(e=>Bo(e,new Vo))(t);Ur(e,a);},ec$2=(e,t,a)=>{Rr(e,1),Ur(e,((e,t)=>Ro(e,t,new Co))(t,a));},tc=(e,t,a)=>{try{((e,t,a)=>{Lo(e,t,a,To);})(t,rs(e),a);}catch(e){console.error("Caught error while handling a Yjs update",e);}},ac=tc,ic=(e,t,a,i)=>{const n=os(e);switch(n){case 0:((e,t,a)=>{ec$2(t,a,rs(e));})(e,t,a);break;case 1:tc(e,a,i);break;case 2:ac(e,a,i);break;default:throw new Error("Unknown message type")}return n},nc=3e4;class rc extends dr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const e=ws();null!==this.getLocalState()&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const t=[];this.meta.forEach(((a,i)=>{i!==this.clientID&&nc<=e-a.lastUpdated&&this.states.has(i)&&t.push(i);})),t.length>0&&sc(this,t,"timeout");}),pr(3e3)),e.on("destroy",(()=>{this.destroy();})),this.setLocalState({});}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval);}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const t=this.clientID,a=this.meta.get(t),i=void 0===a?0:a.clock+1,n=this.states.get(t);null===e?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:ws()});const r=[],s=[],o=[],l=[];null===e?l.push(t):null==n?null!=e&&r.push(t):(s.push(t),Ps(n,e)||o.push(t)),(r.length>0||o.length>0||l.length>0)&&this.emit("change",[{added:r,updated:o,removed:l},"local"]),this.emit("update",[{added:r,updated:s,removed:l},"local"]);}setLocalStateField(e,t){const a=this.getLocalState();null!==a&&this.setLocalState({...a,[e]:t});}getStates(){return this.states}}const sc=(e,t,a)=>{const i=[];for(let a=0;a<t.length;a++){const n=t[a];if(e.states.has(n)){if(e.states.delete(n),n===e.clientID){const t=e.meta.get(n);e.meta.set(n,{clock:t.clock+1,lastUpdated:ws()});}i.push(n);}}i.length>0&&(e.emit("change",[{added:[],updated:[],removed:i},a]),e.emit("update",[{added:[],updated:[],removed:i},a]));},oc=(e,t,a=e.states)=>{const i=t.length,n=Ir();Rr(n,i);for(let r=0;r<i;r++){const i=t[r],s=a.get(i)||null,o=e.meta.get(i).clock;Rr(n,i),Rr(n,o),$r(n,JSON.stringify(s));}return Er(n)},lc=[];lc[0]=(e,t,a,i,n)=>{Rr(e,0);const r=ic(t,e,a.doc,a);i&&1===r&&!a.synced&&(a.synced=true);},lc[3]=(e,t,a,i,n)=>{Rr(e,1),Ur(e,oc(a.awareness,Array.from(a.awareness.getStates().keys())));},lc[1]=(e,t,a,i,n)=>{((e,t,a)=>{const i=ns(t),n=ws(),r=[],s=[],o=[],l=[],u=os(i);for(let t=0;t<u;t++){const t=os(i);let a=os(i);const u=JSON.parse(us(i)),c=e.meta.get(t),d=e.states.get(t),p=void 0===c?0:c.clock;(p<a||p===a&&null===u&&e.states.has(t))&&(null===u?t===e.clientID&&null!=e.getLocalState()?a++:e.states.delete(t):e.states.set(t,u),e.meta.set(t,{clock:a,lastUpdated:n}),void 0===c&&null!==u?r.push(t):void 0!==c&&null===u?l.push(t):null!==u&&(Ps(u,d)||o.push(t),s.push(t)));}(r.length>0||o.length>0||l.length>0)&&e.emit("change",[{added:r,updated:o,removed:l},a]),(r.length>0||s.length>0||l.length>0)&&e.emit("update",[{added:r,updated:s,removed:l},a]);})(a.awareness,rs(t),a);},lc[2]=(e,t,a,i,n)=>{((e,t,a)=>{0===os(e)&&a(t,us(e));})(t,a.doc,((e,t)=>uc(a,t)));};const uc=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),cc=(e,t,a)=>{const i=ns(t),n=Ir(),r=os(i),s=e.messageHandlers[r];return s?s(n,i,e,a,r):console.error("Unable to compute message"),n},dc=(e,t,a)=>{t===e.ws&&(e.emit("connection-close",[a,e]),e.ws=null,t.close(),e.wsconnecting=false,e.wsconnected?(e.wsconnected=false,e.synced=false,sc(e.awareness,Array.from(e.awareness.getStates().keys()).filter((t=>t!==e.doc.clientID)),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(pc,fr(100*yr(2,e.wsUnsuccessfulReconnects),e.maxBackoffTime),e));},pc=e=>{if(e.shouldConnect&&null===e.ws){const t=new e._WS(e.url,e.protocols);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=true,e.wsconnected=false,e.synced=false,t.onmessage=a=>{e.wsLastMessageReceived=ws();const i=cc(e,new Uint8Array(a.data),true);Fr(i)>1&&t.send(Er(i));},t.onerror=t=>{e.emit("connection-error",[t,e]);},t.onclose=a=>{dc(e,t,a);},t.onopen=()=>{e.wsLastMessageReceived=ws(),e.wsconnecting=false,e.wsconnected=true,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const a=Ir();if(Rr(a,0),Qu(a,e.doc),t.send(Er(a)),null!==e.awareness.getLocalState()){const a=Ir();Rr(a,1),Ur(a,oc(e.awareness,[e.doc.clientID])),t.send(Er(a));}},e.emit("status",[{status:"connecting"}]);}},hc=(e,t)=>{const a=e.ws;e.wsconnected&&a&&a.readyState===a.OPEN&&a.send(t),e.bcconnected&&Xu(e.bcChannel,t,e);};class fc extends cr{constructor(e,t,a,{connect:i=true,awareness:n=new rc(a),params:r={},protocols:s=[],WebSocketPolyfill:o=WebSocket,resyncInterval:l=-1,maxBackoffTime:u=2500,disableBc:c=false}={}){for(super();"/"===e[e.length-1];)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=u,this.params=r,this.protocols=s,this.roomname=t,this.doc=a,this._WS=o,this.awareness=n,this.wsconnected=false,this.wsconnecting=false,this.bcconnected=false,this.disableBc=c,this.wsUnsuccessfulReconnects=0,this.messageHandlers=lc.slice(),this._synced=false,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,l>0&&(this._resyncInterval=setInterval((()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const e=Ir();Rr(e,0),Qu(e,a),this.ws.send(Er(e));}}),l)),this._bcSubscriber=(e,t)=>{if(t!==this){const t=cc(this,new Uint8Array(e),false);Fr(t)>1&&Xu(this.bcChannel,Er(t),this);}},this._updateHandler=(e,t)=>{if(t!==this){const t=Ir();Rr(t,0),((e,t)=>{Rr(e,2),Ur(e,t);})(t,e),hc(this,Er(t));}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:a},i)=>{const r=e.concat(t).concat(a),s=Ir();Rr(s,1),Ur(s,oc(n,r)),hc(this,Er(s));},this._exitHandler=()=>{sc(this.awareness,[a.clientID],"app closed");},Os&&"undefined"!=typeof process&&process.on("exit",this._exitHandler),n.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval((()=>{this.wsconnected&&3e4<ws()-this.wsLastMessageReceived&&dc(this,this.ws,null);}),3e3),i&&this.connect();}get url(){const e=(e=>((e,t)=>{const a=[];for(const i in e)a.push(t(e[i],i));return a})(e,((e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`)).join("&"))(this.params);return this.serverUrl+"/"+this.roomname+(0===e.length?"":"?"+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]));}destroy(){0!==this._resyncInterval&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),Os&&"undefined"!=typeof process&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy();}connectBc(){if(this.disableBc)return;var e,t;this.bcconnected||(e=this.bcChannel,t=this._bcSubscriber,Ku(e).subs.add(t),this.bcconnected=true);const a=Ir();Rr(a,0),Qu(a,this.doc),Xu(this.bcChannel,Er(a),this);const i=Ir();Rr(i,0),ec$2(i,this.doc),Xu(this.bcChannel,Er(i),this);const n=Ir();Rr(n,3),Xu(this.bcChannel,Er(n),this);const r=Ir();Rr(r,1),Ur(r,oc(this.awareness,[this.doc.clientID])),Xu(this.bcChannel,Er(r),this);}disconnectBc(){const e=Ir();Rr(e,1),Ur(e,oc(this.awareness,[this.doc.clientID],new Map)),hc(this,Er(e)),this.bcconnected&&(((e,t)=>{const a=Ku(e),i=a.subs.delete(t);i&&0===a.subs.size&&(a.bc.close(),Zu.delete(e));})(this.bcChannel,this._bcSubscriber),this.bcconnected=false);}disconnect(){this.shouldConnect=false,this.disconnectBc(),null!==this.ws&&dc(this,this.ws,null);}connect(){this.shouldConnect=true,this.wsconnected||null!==this.ws||(pc(this),this.connectBc());}}class mc extends So{}class yc{apiClient;collabDocument;yWebsocketProvider;item;awareness;users=[];avatars=new Map;constructor(e){this.apiClient=e,this.collabDocument=new mc;}isActive(){return void 0!==this.yWebsocketProvider}getAwarenessStates(){return this.awareness?this.awareness.getStates():new Map}getUsersList(){return this.users}_getUser(e){for(const t of this.users)if(e===t.key)return t;return null}getLocalState(){if(!this.awareness)throw new Error("No awareness available. Cannot get state field.");return this.awareness.getLocalState()}setLocalStateField(e,t){if(!this.awareness)throw new Error("No awareness available. Cannot set state field.");this.awareness.setLocalStateField(e,t);}async _updateUsersList(){const e=this.getAwarenessStates(),t=await this.apiClient.me(true);for(const[a,i]of e.entries()){if(!this._getUser(a)){let e=this.avatars.get(i.user.id);if(!e){e=(await this.apiClient.getAvatar(i.user.id,32)).avatar,this.avatars.set(i.user.id,e);}this.users.push({key:a,id:i.user.id,name:i.user.name,color:i.user.color,avatar:e,itsMe:i.user.id===t._id});}}const a=[];for(const t of this.users)e.has(t.key)&&a.push(t);this.users=a;}async startCollaboration(e){try{if(!this.apiClient.isDevOrLocalhost())return !1;this.endCollaboration(),this.item=e;const t=this.apiClient.getCollabUrl(),a=`${this.item.type}.${this.item._id}`;let i=1e3;this.yWebsocketProvider=new fc(t,a,this.collabDocument,{connect:!1}),this.yWebsocketProvider.on("status",(e=>{console.log(`[Collab] ${e.status}`),"disconnected"===e.status&&this.yWebsocketProvider&&(this.yWebsocketProvider.disconnect(),setTimeout(r,i));})),this.yWebsocketProvider.on("sync",(e=>{console.log(`[Collab] synced: ${e}`);})),this.awareness=this.yWebsocketProvider.awareness,this.awareness.on("change",(async e=>{await this._updateUsersList(),u$3.$emit("collab:awareness:changed",{users:this.users,states:this.getAwarenessStates(),changes:e});}));const n=await this.apiClient.me(!0);this.awareness.setLocalStateField("user",{id:n._id,name:n.name,color:h$2.colorFromString(n.name)});const r=async()=>{if(!this.yWebsocketProvider)return void console.warn("[Collab] Cannot connect without websocket provider!");console.log("[Collab] reconnecting...");const e=await this.apiClient.getCollabToken();this.yWebsocketProvider.params.token=e,this.yWebsocketProvider.connect();};return await r(),u$3.$emit("collab:started"),!0}catch(e){return console.error("Error starting collaboration: ",e),false}}endCollaboration(){this.yWebsocketProvider&&(console.log("Ending collaboration."),u$3.$emit("collab:ended"),this.yWebsocketProvider.destroy(),this.yWebsocketProvider=void 0,this.awareness=void 0),this.collabDocument=new mc,this.item=void 0;}}class gc{apiClient;constructor(e){this.apiClient=e;}async testCopyItems(e,t){const a=await this.apiClient.getItemsInFolderList(t,true),i=await this.apiClient.getFoldersInFolderList(t),n=new Map;for(const e of i.children)n.set(e.name,null);for(const e of a)n.set(e.name,e._id);const r=this.apiClient.getItemRepo(),s=[];for(const t of e){let e,a,i=false;t.isFolder?a=await this.apiClient.getFolder(t._id):(a=r.getLoadedItem(t._id),a||(a=await this.apiClient.getItem(t._id))),e=a?.name,i=n.has(e),s.push({_id:t._id,isFolder:t.isFolder,data:a,name:e,conflicted:i,conflictedItemId:n.get(e)});}return s}async copyItems(e,t,a=false,i=false){const n=e.filter((e=>!e.isFolder)).map((e=>e._id)),r=await this.apiClient.copyItems(n,t,a,i),s=this.apiClient.getItemRepo();for(let t of r){const a=e.filter((e=>e._id===t.original));a.length>0&&(t.replaced=a[0].conflictedItemId),await s.replaceLink(t.original,t.clone);}return await this.apiClient.eventBus.$emit("folder:changed",t),await this.apiClient.eventBus.$emit("items:copied",r),r}}class bc{apiClient;jobManager;constructor(e){this.apiClient=e,this.jobManager=e.getJobManager();}async executeExport(e,t,a,i){const n=await this.jobManager.execute("EXPORT:ExportGame",[{_id:e,isFolder:false}],[{name:"Destination Folder",value:a},{name:"EngineVersion",value:i}],void 0,{os:t});if(await this.apiClient.eventBus.$emit("quota:update"),2===n.state)throw new N$1("Export failed: "+n.error);await this.apiClient.eventBus.$emit("folder:changed",[a]);}}(axiosRetry.default?axiosRetry.default:axiosRetry)(axios,{retries:3,retryCondition:e=>e.message.includes("net::ERR_NETWORK_CHANGED")});const vc={Draft:0,Private:1,NotListed:2,Public:3},_c=[{id:"prod",name:"Production",ssl:true,apiHost:"api.lumino.cloud",viewerHost:"viewer.lumino.cloud",collabHost:"collab.lumino.cloud"},{id:"dev",name:"Development",ssl:true,apiHost:"api-dev.lumino.cloud",viewerHost:"viewer-dev.lumino.cloud",collabHost:"collab-dev.lumino.cloud"},{id:"local",name:"Local",ssl:false,apiHost:"localhost:8081",viewerHost:"localhost:8090",collabHost:"localhost:8200"}];class wc extends l$2{accessToken;apiToken;options;forcePublicApi;usePublicApi;usePersistentStorage;storageSizeMib;requestClientId;apiUrl;wsUrl;viewerUrl;collabUrl;itemRepo;itemCache;folderCache;thumbCache;userCache;groupCache;attachmentCache;jobManager;serializer;collab;itemCopier;executableExporter;eventBus;env;api;ws=null;cachedMe;profiler;wsLastPing=null;last2faCode="";constructor(e={}){super(),e=e||{},this.options=Object.assign({environment:"auto",wsAutoReconnect:true,wsAutoConnect:false,forcePublicApi:false,debug:false,accessToken:null,apiToken:null,usePersistentStorage:true,storageSizeMib:10240,requestClientId:null},e),this.accessToken=this.options.accessToken,this.apiToken=this.options.apiToken,this.forcePublicApi=this.options.forcePublicApi,this.usePublicApi=!this.accessToken&&!this.apiToken,this.usePersistentStorage=this.options.usePersistentStorage,this.storageSizeMib=this.options.storageSizeMib,this.requestClientId=this.options.requestClientId,this.cachedMe=null,this.itemRepo=new Zi(this.usePublicApi,this),this.itemCache=new jn(this.usePublicApi,this.usePersistentStorage,this,this.storageSizeMib),this.folderCache=new Un$1(this),this.thumbCache=new zn(this),this.userCache=new Wn(this),this.groupCache=new Yn(this),this.attachmentCache=new Hn(this),this.jobManager=new Zn(this),this.serializer=new tr(this),this.collab=new yc(this),this.itemCopier=new gc(this),this.executableExporter=new bc(this),this.eventBus=u$3,this.profiler=null,this.switchEnvironment(this.options.environment),this.setDebugMode(this.options.debug);}detectEnvironment(){const e=this.isOnLocalhost(),t=this.isDevPlatform();return e?this.getEnvironmentById("local"):t?this.getEnvironmentById("dev"):this.getEnvironmentById("prod")}getEnvironmentById(e){return "auto"===e?this.detectEnvironment():_c.find((t=>t.id===e))}getEnvironments(){return _c}switchEnvironment(e){let a=this.getEnvironmentById(e);if(!a)throw new Error(`Unknown environment: ${e}`);console.log(`ApiClient switched to env: ${a.name}`);const i=a.ssl?"https":"http",n=a.ssl?"wss":"ws";this.apiUrl=`${i}://${a.apiHost}`,this.wsUrl=`${n}://${a.apiHost}/api/ws`,this.viewerUrl=`${i}://${a.viewerHost}`,this.collabUrl=`${i}://${a.collabHost}`,this.api=axios.create({baseURL:this.apiUrl}),this.ws=null,this.wsLastPing=null;}async initCaches(){return Promise.all([this.itemCache.init(),this.folderCache.init(),this.thumbCache.init()])}clearCaches(){this.itemCache.clear(),this.folderCache.clear(),this.thumbCache.clear();}isDevPlatform(){return "object"==typeof window&&"location"in window&&window.location.href.includes("dev.lumino.cloud")}isOnLocalhost(){return "object"==typeof window&&"location"in window&&window.location.href.includes("localhost")}isDevOrLocalhost(){return this.isOnLocalhost()||this.isDevPlatform()}async clearIndexedDb(e){return new Promise(((t,a)=>{const i=indexedDB.deleteDatabase(e);i.onsuccess=()=>{t();},i.onerror=e=>{a("An error occured while deleting a IndexedDB database.");},i.onblocked=()=>{a(`Database deletion is blocked. Please close all connections to "${e}".`);};}))}async logout(){return this.clearCaches(),this.clearIndexedDb("lumino")}setDebugMode(e){this.options.debug=!!e,this.eventBus.setDebugMode(this.options.debug);}websocketConnect(e){const t=this;if(this.ws){if(!e)return void console.warn("Websocket is already connected!");this.websocketDisconnect();}this.ws=new i$4(this.wsUrl),this.ws.onerror=function(e){console.error("Websocket error",e),t.$emit("client:websocketError",e);},this.ws.onopen=function(){t.$emit("client:websocketOpen"),t.accessToken&&t.websocketSend(JSON.stringify({type:"auth",subscriptions:["item","folder","job","user","notification"],token:t.accessToken}));},this.ws.onclose=function(){t.$emit("client:websocketClosed"),t.options.wsAutoReconnect&&t.websocketConnect(true);},this.ws.onmessage=function(e){try{const a=JSON.parse(e.data);switch(a.type){case "ping":t.wsLastPing=new Date,t.ws&&t.ws.send(JSON.stringify({type:"ping"}));break;case "authenticated":t.$emit("client:websocketAuthenticated");break;case "Item":case "Folder":case "Notification":case "Job":case "User":u$3.$emit("client:elementUpdate",a);break;default:console.warn("Unknown websocket message: ",a);}}catch(e){console.error("Websocket error:",e);}};}websocketDisconnect(){this.ws&&(this.ws.close(),this.ws=null);}websocketSend(e){this.ws?1===this.ws.readyState?this.ws.send(e):console.error("Websocket is not in READY state. Currently in state "+this.ws.readyState):console.error("Websocket is not created");}getItemCopier(){return this.itemCopier}getExecutableExporter(){return this.executableExporter}getCollab(){return this.collab}getCollabUrl(){return this.collabUrl}getPublisher(){return new Gn(this)}getAssetCreator(){return new er(this)}getJobManager(){return this.jobManager}getThumbCache(){return this.thumbCache}getItemCache(){return this.itemCache}getItemRepo(){return this.itemRepo}getRootVisibility(){return this.itemRepo.activeItem?this.itemRepo.activeItem.visibility:vc.Private}getEventBus(){return this.eventBus}getSerializer(){return this.serializer}setForcePublicApi(e){this.forcePublicApi=e,this._updateUsePublicApi();}_updateUsePublicApi(){this.usePublicApi=this.forcePublicApi||!this.apiToken&&!this.accessToken,this.itemRepo.usePublicApi=this.usePublicApi,this.itemCache.usePublicApi=this.usePublicApi;}setApiToken(e){this.apiToken=e,this._updateUsePublicApi();}setAccessToken(e){this.accessToken=e,this._updateUsePublicApi(),this.accessToken&&this.options.wsAutoConnect&&this.websocketConnect();}getApiToken(){return this.apiToken}getAccessToken(){return this.accessToken}setApiBaseUrl(e){this.apiUrl=e,this.api=axios.create({baseURL:this.apiUrl});}setWsBaseUrl(e){this.wsUrl=e,this.accessToken&&this.options.wsAutoConnect&&(this.websocketDisconnect(),this.websocketConnect());}setRequestClientId(e){this.requestClientId=e;}getApiBaseUrl(){return this.apiUrl}getWsBaseUrl(){return this.wsUrl}getViewerBaseUrl(){return this.viewerUrl}setProfiler(e){if(!e||"function"!=typeof e.start)throw new Error("Profiler needs to be an object providing a start function.");this.profiler=e;}async login2FA(e,t,a){return console.log("Running Login..."),this.execute("post","/api/auth/login2fa",{account:e,password:t,client:a}).then((e=>{this.last2faCode=e,this.eventBus.$emit("login.2facode",e);}))}async confirm2FA(e,t){return this.execute("post","/api/auth/confirm2fa",{account:e,code:t})}isAuthenticated(){return !!this.accessToken||!!this.apiToken}isFeatureEnabled(e){return !!this.cachedMe&&this.cachedMe.features.includes(e)}async resolveUserOrGroupInfoForItem(e){return e.quotaUser?this.userCache.resolve(e.quotaUser):e.quotaGroup?this.groupCache.resolve(e.quotaGroup):e.createdBy?this.userCache.resolve(e.createdBy):{name:"?",initials:"?",avatar:null}}_startOp(e){const t=this,a={id:h$2.createGUID(),name:e,startTimeMs:performance.now(),runningMs:0,percent:0,reportProgress:function(e){a.percent=e;},interval:null,finish:function(){if(a.interval&&clearInterval(a.interval),a.runningMs>1e3)try{t.$emit("client:longRunningOpFinished",a.id);}catch(e){console.error(e);}}};return a.interval=setInterval((function(){if(a.runningMs=performance.now()-a.startTimeMs,a.runningMs>1e3)try{t.$emit("client:longRunningOp",a.id,a.name,a.percent);}catch(e){console.error(e);}}),100),a}_createOpName(e,t){try{const a=t.split("/");switch(e.toLowerCase()){case "get":e="Fetching";break;case "post":e="Creating";break;case "put":e="Updating";break;case "delete":e="Deleting";}a.shift(),a.shift();const i=a.shift();let n=a.join("/");return n.length&&(n=` [${n}]`),`${e} ${i} data ${n}`}catch{return `${e} ${t}`}}addAuthenticationHeaders(e){this.accessToken&&(e["x-access-token"]=this.accessToken),this.apiToken&&(e["x-api-token"]=this.apiToken),this.requestClientId&&(e["x-request-client"]=this.requestClientId);}async execute(e,t,a,i){let n=this,r={};(i=i||{}).headers?r=i.headers:a&&"object"==typeof a&&"getHeaders"in a&&"function"==typeof a.getHeaders&&(r=a.getHeaders()),this.addAuthenticationHeaders(r);const s=this.profiler?this.profiler.start("ApiClient",`${e} ${t}`):null,o=this._startOp(i.opName||n._createOpName(e,t));return this.api({method:e,url:t,data:a,responseType:i.responseType,headers:r,signal:i.controller?i.controller.signal:void 0,onUploadProgress:function(e){if(e.total){const t=Math.min(100,Math.round(100*e.loaded/e.total));o.reportProgress(t),n.$emit("client:progress",{type:"upload",percent:t}),"function"==typeof i.progressCallback&&i.progressCallback(t,e.loaded,e.total);}},onDownloadProgress:function(e){if(e.total){const t=Math.min(100,Math.round(100*e.loaded/e.total));o.reportProgress(t),n.$emit("client:progress",{type:"download",percent:t}),"function"==typeof i.progressCallback&&i.progressCallback(t,e.loaded,e.total);}}}).then((e=>{if(s&&s.done(),o.finish(),n.$emit("client:progress",{type:"done"}),e.headers["content-type"].startsWith("application/json")){if("success"===e.data.result){let t;return t=i.withNext?{data:e.data.data,next:e.data.next}:e.data.data,i.emitOnSuccess&&this.eventBus.$emit(i.emitOnSuccess,t),t}throw e.data.redirect&&this.$emit("client:redirect",e.data.redirect),e.data.error?e.data.error:"API response seems to be json but does not contain result type!"}return i.emitOnSuccess&&this.eventBus.$emit(i.emitOnSuccess),{blob:new Blob([e.data],{type:e.headers["content-type"]}),hash:e.headers["sha256-hash"],itemName:e.headers["lumino-itemname"],itemType:e.headers["lumino-itemtype"],mimeType:e.headers["content-type"]}})).catch((e=>{if(s&&s.done(),o.finish(),n.$emit("client:progress",{type:"done"}),e.response){if(401===e.response.status)throw this.$emit("client:unauthorized"),new x$4("Access denied. Please login again.");if(413===e.response.status)throw new M$1;if(e.response.data&&e.response.data.error)throw new Error(e.response.data.error)}throw e}))}_createFormData(e,t){let a=new n$3;if("function"==typeof File&&e instanceof Blob)a.append("file",e,t);else {const i=new Blob([e]);try{a.append("file",i,t);}catch{a=new n$3,a.append("file",e,t);}}return a}async me(e){return e&&this.cachedMe||(this.cachedMe=await this.execute("get","/api/auth/me")),this.cachedMe}async getHomeFolder(){return this.execute("get","/api/auth/homefolder")}async myClients(){return this.execute("get","/api/auth/myclients")}async getCollabToken(){return this.execute("get","/api/auth/collabtoken")}async checkCollabToken(e){return this.execute("post","/api/auth/collabtoken",{token:e})}async register(e){return this.execute("post","/api/auth/register",e)}async deleteMyAccount(e){return this.execute("post","/api/auth/deletemyaccount",{password:e})}async confirmEmail(e){return this.execute("get","/api/auth/confirmemail/"+e)}async confirmEmailChange(e){return this.execute("get","/api/auth/confirmchangedemail/"+e)}async forgotPassword(e,t){return this.execute("post","/api/auth/forgotpassword",{account:e,client:t})}async setNewPassword(e,t){return this.execute("post","/api/auth/setnewpassword",{token:e,password:t})}async accountExists(e){return this.execute("post","/api/auth/accountExists",e)}async getItemsInFolderList(e,t=false){if(e&&!t){const t=await this.folderCache.getItemListing(e);if(t)return t}const a=await this.execute("get","/api/item/infolder/"+(e||"0"));return await this.folderCache.addItemListing(e,a),a}async getItem(e,t){const a=[];t&&(t.returnClonedFrom&&a.push("returnClonedFrom=true"),t.withThumbnails&&a.push("withThumbnails=true"));let i="";return a.length&&(i=`?${a.join("&")}`),this.execute("get",`/api/item/${e}${i}`)}getItemAggregatedPOP(e,t){return this.usePublicApi?this.getItemPublicAggregated(e,t):this.getItemAggregated(e,t)}async getItemPublicAggregated(e,t){const a=Bi(e);if(a)return a;const i=[];t&&(t.withFieldInstances&&i.push("withFieldInstances"),t.withAttachmentInfo&&i.push("withAttachmentInfo"),t.noAttributes&&i.push("noAttributes"),t.noUserAttributes&&i.push("noUserAttributes"),t.noFields&&i.push("noFields"),t.noThumbnails&&i.push("noThumbnails"),t.noLinks&&i.push("noLinks"));let n="";return i.length&&(n=`?${i.join("&")}`),Bi(e)?Bi(e):this.execute("get","/api/item/publicaggregate/"+e+n)}async getItemAggregated(e,t){const a=Bi(e);if(a)return a;const i=[];t&&(t.withFieldInstances&&i.push("withFieldInstances"),t.withAttachmentInfo&&i.push("withAttachmentInfo"),t.noAttributes&&i.push("noAttributes"),t.noUserAttributes&&i.push("noUserAttributes"),t.noFields&&i.push("noFields"),t.noThumbnails&&i.push("noThumbnails"),t.noLinks&&i.push("noLinks"));let n="";return i.length&&(n=`?${i.join("&")}`),Bi(e)?Bi(e):this.execute("get",`/api/item/aggregate/${e}${n}`)}async getItemAggregatedRecursive(e,t){const a=[];t&&(t.withFieldInstances&&a.push("withFieldInstances"),t.withAttachmentInfo&&a.push("withAttachmentInfo"),t.noAttributes&&a.push("noAttributes"),t.noUserAttributes&&a.push("noUserAttributes"),t.noFields&&a.push("noFields"),t.noThumbnails&&a.push("noThumbnails"));let i="";return a.length&&(i=`?${a.join("&")}`),this.execute("get",`/api/item/aggregaterecursive/${e}${i}`)}async getItemPublicRecursive(e,t){return this.execute("get","/api/item/publicrecursive/"+e+(t?"?withFeatures":""))}async getItemPublic(e,t){return this.execute("get","/api/item/public/"+e+(t?"?returnClonedFrom=true":""))}async getItemHistory(e){return this.execute("get","/api/item/history/"+e)}async copyItems(e,t,a,i){return this.execute("post","/api/item/copy",{sourceItemIds:e,destFolderId:t,deepCopy:a,overwrite:i})}async createItem(e){return this.execute("post","/api/item",e)}async updateItem(e){return this.execute("put","/api/item",e)}async deleteItem(e){return this.execute("delete","/api/item",{id:e})}async renameItem(e,t){return this.updateItem({_id:e,name:t})}async queryPublicItemsList(e){return this.execute("post","/api/item/publicquery",e)}async queryItemsListPOP(e){return this.usePublicApi?this.queryPublicItemsList(e):this.queryItemsList(e)}async queryItemsList(e){return this.execute("post","/api/item/query",e)}async queryItemsListAsExcel(e){e.exportAsExcel=true;const t=await this.execute("post","/api/item/query",e,{responseType:"arraybuffer"}),a=window.URL.createObjectURL(t.blob),i=document.createElement("a");i.href=a,i.setAttribute("download","export.xlsx"),i.click();}async moveItems(e){return this.execute("post","/api/item/move",e)}async downloadItem(e,t){const a=Ei(e);return a||this.execute("get",`/api/item/download/${e}`,null,{responseType:"arraybuffer",progressCallback:t,opName:`Downloading item ${e}`})}async publicDownloadItem(e,t){const a=Ei(e);return a||this.execute("get",`/api/item/publicdownload/${e}`,null,{responseType:"arraybuffer",progressCallback:t})}async getItemHash(e){const t=Bi(e);return t?t.hash:this.execute("get",`/api/item/hash/${e}`)}async requestSecureDownload(e){return this.execute("get","/api/item/requestsecuredownload/"+e)}async getThumbnail(e,t){return this.execute("get",`/api/item/thumbnail/${e}/${t}`)}async uploadThumbnail(e,t,a,i,n,r){const s=this._createFormData(a,i);return this.execute("post",`/api/item/thumbnail/${t}/${e}`,s,{progressCallback:n,controller:r})}async getPublicThumbnail(e,t){return this.execute("get",`/api/item/publicthumbnail/${e}/${t}`)}async makeItemPublic(e,t,a){return this.execute("put","/api/item/makepublic",{id:e,recursive:t,inSubfolders:a})}async setVisibility(e,t,a,i){return this.execute("put","/api/item/setvisibility",{id:e,visibility:t,recursive:a,inSubfolders:i})}async makeItemPrivate(e,t,a){return this.execute("put","/api/item/makeprivate",{id:e,recursive:t,inSubfolders:a})}async setOmitLodGeneration(e,t){return this.execute("get",`/api/item/setOmitLodGeneration/${e}/${t}`)}async setOmitThumbnailGeneration(e,t){return this.execute("get",`/api/item/setOmitThumbnailGeneration/${e}/${t}`)}async setOmitPreviewGeneration(e,t){return this.execute("get",`/api/item/setOmitPreviewGeneration/${e}/${t}`)}async uploadAndCreate(e,t,a,i,n,r){const s=this._createFormData(t,a);let o=`/api/item/uploadAndCreate/${e}`,l={};return i&&("object"==typeof i?(i.autoDestructIn&&(o+="?autoDestructIn="+i.autoDestructIn),i.visibility&&(o+="?visibility="+i.visibility),i.flags&&(o+="?flags="+i.flags),i.overwrite&&(o+="?overwrite="+(i.overwrite?"true":"false")),i.nameOverride&&(l["x-override-name"]=i.nameOverride)):o+="?autoDestructIn="+i),this.execute("post",o,s,{progressCallback:n,controller:r,headers:l})}async upload(e,t,a,i,n,r){const s=[];r&&(r.omitHandleDependencyChange&&s.push("omitHandleDependencyChange=true"),r.keepThumbnails&&s.push("keepThumbnails=true"));let o="";s.length&&(o=`?${s.join("&")}`);const l=this._createFormData(t,a);return this.execute("post",`/api/item/upload/${e}${o}`,l,{progressCallback:i,controller:n})}resetPreview(e){const t=this.execute("delete",`/api/item/attachment/${e}/preview`),a=this.execute("get",`/api/item/setOmitPreviewGeneration/${e}/false`);return Promise.all([t,a])}clearPreview(e){const t=this.execute("delete",`/api/item/attachment/${e}/preview`),a=this.execute("get",`/api/item/setOmitPreviewGeneration/${e}/true`);return Promise.all([t,a])}async clearThumbnail(e){return this.execute("get",`/api/item/clearThumbnail/${e}`)}async resetThumbnail(e){return this.execute("get",`/api/item/resetThumbnail/${e}`)}async downloadAttachmentPOP(e,t,a,i,n){return this.usePublicApi?this.downloadPublicAttachment(e,t,a,i,n):this.downloadAttachment(e,t,a,i,n)}_getAttachmentUrlPath(e,t,a,i,n){return `/api/item/${n?"public":""}attachment/${e}/${t}${null!=a?`/${a}`:"/undefined"}${null!=i?`/${i}`:""}`}async downloadAttachment(e,t,a,i=0,n){const r=Wi(e,t,a,i);return r||this.execute("get",this._getAttachmentUrlPath(e,t,a,i),null,{responseType:"arraybuffer",progressCallback:n})}async downloadPublicAttachment(e,t,a,i,n){const r=Wi(e,t,a,i);return r||this.execute("get",this._getAttachmentUrlPath(e,t,a,i,true),null,{responseType:"arraybuffer",progressCallback:n})}async uploadAttachment(e,t,a,i,n,r,s,o){const l=this._createFormData(n,r);return this.execute("post",this._getAttachmentUrlPath(e,t,a,i),l,{progressCallback:s,controller:o})}async deleteAttachment(e,t,a,i){return this.attachmentCache.invalidateAttachment(e,t,a,i),this.execute("delete",this._getAttachmentUrlPath(e,t,a,i))}setPerceptiveHashOnAttachment(e,t,a){return this.execute("get",`/api/item/setPerceptiveHashAttachment/${e}/${t}/${a}`)}setPerceptiveHash(e,t){return this.execute("get",`/api/item/setPerceptiveHash/${e}/${t}`)}async getItemClient(e){return this.execute("get",`/api/item/getClient/${e}`)}async getItemAcl(e){return this.execute("get",`/api/item/acl/${e}`)}async getItemsLinking(e){return this.execute("get",`/api/item/linking/${e}`)}async setAttributes(e,t){return this.execute("put","/api/item/setAttributes",{id:e,attributes:t})}async getItemSyncList(e){const t=j(e).format("YYYYMMDDHHmmss");return this.execute("get",`/api/item/synclist/${t}`)}async increaseViews(e){return this.execute("get",`/api/item/increaseViews/${e}`)}async getViews(e){return this.execute("get",`/api/item/views/${e}`)}async getPublicItemCounts(e){return this.execute("get",`/api/item/publiccounts/${e}`)}async getItemCounts(e){return this.execute("get",`/api/item/counts/${e}`)}async likeItem(e){return this.execute("get",`/api/item/like/${e}`)}async unlikeItem(e){return this.execute("get",`/api/item/unlike/${e}`)}async doILike(e){return this.execute("get",`/api/item/doILike/${e}`)}async setItemAutoDestruct(e,t){const a=j(t).format("YYYYMMDDHHmmss");return this.execute("get",`/api/item/setAutoDestruct/${e}/${a}`)}async clearItemAutoDestruct(e){return this.execute("get",`/api/item/clearAutoDestruct/${e}`)}async resolveRelativeItem(e,t){const a=Bi(e);if(!a)return this.execute("post","/api/item/resolve/"+e,{path:t});t.startsWith("/")&&(t=t.substring(1));const i=t.split("/"),n=i.pop();let r=a.folder._id;for(const e of i){let t=false;for(const[a,i]of Object.entries(Di()))if(i.parent===r&&i.name===e){r=a,t=true;break}if(!t)break}for(const e of Object.values(Oi$1()))if(e.folder._id===r&&e.name===n)return e._id;return console.error(`Could not resolve path ${t} for item ${e}`),null}async publicResolveRelativeItem(e,t){const a=Bi(e);if(!a)return this.execute("post","/api/item/publicResolve/"+e,{path:t});t.startsWith("/")&&(t=t.substring(1));const i=t.split("/"),n=i.pop();let r=Li(a.folder._id);for(const e of i)if(".."===e)r=Li(r.parent);else {const t=Ri(e,r._id);if(!t)throw new Error("Can't find folder while loading folder from package");r=t;}const s=Pi(n,r._id);if(s)return s._id;throw new Error("Can't load item from package.")}async rewireItems(e){return this.execute("post","/api/item/rewire",{items:e})}async getFolder(e){return this.execute("get","/api/folder/"+e)}async getFullFolderTree(e){return this.execute("get",`/api/folder/fulltree/${e||"0"}`)}async getFoldersInFolderList(e,t){e=e||"0";const a=[];let i="";if(t){if(t.resolveNames&&!t.folderAsItemType&&"0"!==e){if(i=await this.folderCache.getFolderListing(e),i&&Date.now()-new Date(i.cachedAt).getTime()<1e4)return i;i&&i.parent&&a.push(`lastUpdatedAt=${i.parent.updatedAt}`);}t.resolveNames&&a.push("resolve"),t.folderAsItemType&&a.push(`folderAsItemType=${t.folderAsItemType}`),t.folderAsItemName&&a.push(`folderAsItemName=${t.folderAsItemName}`),t.folderAsItemFlag&&a.push(`folderAsItemFlag=${t.folderAsItemFlag}`),t.withStats&&a.push("withStats=true"),t.returnLatestPackage&&a.push("returnLatestPackage=true");}let n="";a.length&&(n="?"+a.join("&"));const r=await this.execute("get",`/api/folder/infolder/${e}${n}`);if(true===r.notModified)return i;if(!t||t.resolveNames&&!t.folderAsItemType){const t=await this.getFolderAclList([e,...r.children.map((e=>e._id))]);for(const e of t)await this.folderCache.addACL(e.id,e.acl);return await this.folderCache.addFolderListing(e,r),r}return r}async updateFolderCache(e){const t=[];for(const a of e){if(!a)continue;const e=await this.folderCache.getFolderListing(a);e&&e.parent?t.push({id:a,lastUpdatedAt:e.parent.updatedAt}):t.push({id:a});}const a=await this.execute("post","/api/folder/infolderquery",{folders:t});for(const e of a) true===e.data.notModified?await this.folderCache.refreshCacheForFolder(e.id):await this.folderCache.addFolderListing(e.id,e.data);}async createFolder(e){return this.execute("post","/api/folder",e)}async updateFolder(e){return this.execute("put","/api/folder",e)}async deleteFolder(e){return this.execute("delete","/api/folder",{id:e})}async renameFolder(e,t){return this.updateFolder({_id:e,name:t})}async moveFolders(e){return this.execute("post","/api/folder/move",e)}async getFolderPath(e){return e?("object"==typeof e&&(e=e._id),this.execute("get","/api/folder/path/"+e)):{path:"/",elements:[]}}async resolveFolderPath(e){return "/"===(e=e.trim())?null:this.execute("post","/api/folder/resolve",{path:e})}async getFolderClient(e){return this.execute("get",`/api/folder/getClient/${e}`)}async getFolderAcl(e){const t=await this.folderCache.getFolderACLs(e||"0",1e4);if(t&&e)return t;{const t=await this.execute("get",`/api/folder/acl/${e||"0"}`);return await this.folderCache.addACL(e||"0",t),t}}async getFolderAclList(e){return this.execute("post","/api/folder/aclquery",{ids:e})}async getUser(e){return this.execute("get","/api/user/"+e)}async getUsersList(){return this.execute("get","/api/user")}async createUser(e){return this.execute("post","/api/user",e)}async queryUser(e,t,a){return this.execute("post","/api/user/query",{searchQuery:e,groupID:t,cursor:a},{withNext:true})}async updateUser(e){return this.execute("put","/api/user",e)}async deleteUser(e){return this.execute("delete","/api/user",{id:e})}async updateMyProfile(e){return this.execute("put","/api/user/myprofile",e)}async switchClient(e){return this.execute("get",`/api/user/switchclient/${e}`)}async activateUser(e,t){return this.execute("post","/api/user/activate",{token:t,password:e})}async getUsersToApprove(){return this.execute("get","/api/user/approvals")}async approveUserRegistration(e){return this.execute("get",`/api/user/approveuserregistration/${e}`)}async rejectUserRegistration(e){return this.execute("get",`/api/user/rejectuserregistration/${e}`)}async uploadAvatar(e){const t=new n$3;if(e instanceof Blob)t.append("file",e);else {const a=new Blob([new Uint8Array(e)]);t.append("file",a,"avatar.jpg");}return this.execute("post","/api/user/uploadAvatar",t)}async clearAvatar(){return this.execute("get","/api/user/clearAvatar")}async getAvatar(e,t){return this.execute("get",`/api/user/avatar/${t}/${e}`)}async getUserPublicInfo(e,t,a){return this.execute("get",`/api/user/publicinfo/${e}/${t}/${a}`)}async getUserAttribute(e){return this.execute("get",`/api/user/attribute/${e}`)}async clearUserAttribute(e){return this.execute("delete",`/api/user/attribute/${e}`)}async setUserAttribute(e,t){return this.execute("post",`/api/user/attribute/${e}`,t)}async getGroup(e){return this.execute("get","/api/group/"+e)}async getGroupFolder(e){return this.execute("get","/api/group/folder/"+e)}async getGroupsList(){return this.execute("get","/api/group")}async createGroup(e){return this.execute("post","/api/group",e)}async queryGroup(e,t){return this.execute("post","/api/group/query",{searchQuery:e,cursor:t},{withNext:true})}async updateGroup(e){return this.execute("put","/api/group",e)}async deleteGroup(e){return this.execute("delete","/api/group",{id:e})}async getGroupQuotaInfo(e){return this.execute("get","/api/group/quota/"+e)}async getGroupPublicInfo(e,t,a){return this.execute("get",`/api/group/publicinfo/${e}/${t}/${a}`)}async getGroupUsers(e){return this.execute("get","/api/group/users/"+e)}async uploadGroupAvatar(e,t){const a=new n$3;if(t instanceof Blob)a.append("file",t);else {const e=new Blob([new Uint8Array(t)]);a.append("file",e,"avatar.jpg");}return this.execute("post","/api/group/"+e+"/uploadAvatar",a)}async getClientsList(){return this.execute("get","/api/client")}async getClient(e){return this.execute("get",`/api/client/${e}`)}async createClient(e){return this.execute("post","/api/client",e)}async queryClient(e,t){return this.execute("post","/api/client/query",{searchQuery:e,cursor:t},{withNext:true})}async updateClient(e){return this.execute("put","/api/client",e)}async deleteClient(e){return this.execute("delete","/api/client",{id:e})}async getClientMetrics(e,t,a){return this.execute("get",`/api/client/metrics/${t}/${a}/${e}`)}async joinClient(e){return this.execute("get",`/api/client/join/${e}`)}async leaveClient(e){return this.execute("get",`/api/client/leave/${e}`)}async myClient(){return this.execute("get","/api/client/my")}async saveMyClient(e){return this.execute("put","/api/client/my",e)}async getPublicCategories(e){return this.execute("get",`/api/client/publiccategories/${e}`)}async getCategories(){return this.execute("get","/api/client/categories")}async getCategoriesInClient(e){return this.execute("get",`/api/client/categories/${e}`)}async updateCategoriesInClient(e,t){return this.execute("post",`/api/client/categories/${e}`,t)}async getLicenses(){return this.execute("get","/api/license")}async getLicensesInClient(e){return this.execute("get",`/api/license/inclient/${e}`)}async getLicense(e){return this.execute("get",`/api/license/${e}`)}async createLicense(e){return this.execute("post","/api/license",e)}async updateLicense(e){return this.execute("put","/api/license",e)}async deleteLicense(e,t){return this.execute("delete","/api/license",{_id:e,client:t})}async getPublicLicenses(e){return this.execute("get",`/api/license/publiclist/${e}`)}async getPublicLicense(e){return this.execute("get",`/api/license/public/${e}`)}async getDatatypesList(){return this.execute("get","/api/datatype")}async getPublicDatatypesList(e){return this.execute("get",`/api/datatype/public/${e}`)}async getDatatypesListOnClient(){return this.execute("get","/api/datatype/onclient")}async getDatatypesListOnClientForAll(){return this.execute("get","/api/datatype/onclientforall")}async getAllDatatypesList(){return this.execute("get","/api/datatype/all")}async getDatatype(e){return this.execute("get",`/api/datatype/${e}`)}async createDatatype(e){return this.execute("post","/api/datatype",e)}async updateDatatype(e){return this.execute("put","/api/datatype",e)}async deleteDatatype(e){return this.execute("delete","/api/datatype",{id:e})}async getMyNotifications(e){return this.execute("get","/api/notification"+(e?`?maxCount=${e}`:""))}async markNotificationAsRead(e){return this.execute("get",`/api/notification/markasread/${e}`)}async markAllNotificationsAsRead(){return this.execute("get","/api/notification/markallasread")}async createJob(e){return this.execute("post","/api/job",e,{emitOnSuccess:"job:created"})}async getManualJobTypes(){return this.execute("get","/api/job/manualtypes")}async getManualJobTypesOnClient(){return this.execute("get","/api/job/manualtypes/onclient")}async getManualJobTypesOnClientForAll(){return this.execute("get","/api/job/manualtypes/onclientforall")}async getAllManualJobTypes(){return this.execute("get","/api/job/manualtypes/all")}async getAllManualJobTypesForClient(e){return this.execute("get",`/api/job/manualtypes/all/${e}`)}async getClientJobTypes(){return this.execute("get","/api/job/clientTypes")}async getMyJobs(){return this.execute("get","/api/job/mine")}async getJobs(){return this.execute("get","/api/job")}async getJobsAggregated(){return this.execute("get","/api/job/aggregated")}async getJobsTimeframe(e,t){return this.execute("get",`/api/job/all/${e}/${t}`)}async getJob(e){return this.execute("get",`/api/job/${e}`)}async getJobState(e){return this.execute("get",`/api/job/state/${e}`)}async getAgents(){return this.execute("get","/api/jobagent")}async getAgentsAggregated(){return this.execute("get","/api/jobagent/aggregated")}async enableJobAgent(e){return this.execute("get",`/api/jobagent/enable/${e}`)}async disableJobAgent(e){return this.execute("get",`/api/jobagent/disable/${e}`)}async restartJobAgent(e){return this.execute("get",`/api/jobagent/restart/${e}`)}async getPermissionsList(){return this.execute("get","/api/permission")}async getPlugins(){return this.execute("get","/api/plugin")}async getPlans(){return this.execute("get","/api/plan")}async getPlan(e){return this.execute("get",`/api/plan/${e}`)}async createPlan(e){return this.execute("post","/api/plan",e)}async updatePlan(e){return this.execute("put","/api/plan",e)}async deletePlan(e){return this.execute("delete","/api/plan",{id:e})}async getWorkflows(){return this.execute("get","/api/workflow")}async getWorkflow(e){return this.execute("get",`/api/workflow/${e}`)}async createWorkflow(e){return this.execute("post","/api/workflow",e)}async updateWorkflow(e){return this.execute("put","/api/workflow",e)}async deleteWorkflow(e){return this.execute("delete","/api/workflow",{id:e})}async startWorkflow(e){return this.execute("post","/api/workflow/start",e)}async getAccessTokens(){return this.execute("get","/api/accesstoken")}async getClientAccessTokens(){return this.execute("get","/api/accesstoken/client")}async createAccessToken(e){return this.execute("post","/api/accesstoken",e)}async createClientAccessToken(e){return this.execute("post","/api/accesstoken/client",e)}async deleteAccessToken(e){return this.execute("delete","/api/accesstoken",{id:e})}async deleteClientAccessToken(e){return this.execute("delete","/api/accesstoken/client",{id:e})}async enableAccessToken(e){return this.execute("get",`/api/accesstoken/enable/${e}`)}async disableAccessToken(e){return this.execute("get",`/api/accesstoken/disable/${e}`)}async getApiTokens(){return this.execute("get","/api/apitoken")}async createApiToken(e){return this.execute("post","/api/apitoken",e)}async deleteApiToken(e){return this.execute("delete","/api/apitoken",{id:e})}async getMyClientInvoices(){return this.execute("get","/api/invoice")}async getMyUserInvoices(){return this.execute("get","/api/invoice/my")}async getClientInvoices(e){return this.execute("get",`/api/invoice/client/${e}`)}async downloadInvoice(e,t){const a=await this.execute("get",`/api/invoice/download/${e}`,null,{responseType:"arraybuffer"}),i=window.URL.createObjectURL(a.blob),n=document.createElement("a");n.href=i,n.setAttribute("download",t||"invoice.pdf"),document.body.appendChild(n),n.click();}async regenerateInvoice(e){return this.execute("get",`/api/invoice/regenerate/${e}`)}async getInvoicesForMonth(e,t){return this.execute("get",`/api/invoice/month/${t}/${e}`)}async refundInvoice(e,t,a){return this.execute("post","/api/invoice/refund",{invoice:e,amount:t,reason:a})}async paymentStartCheckout(e,t){return this.execute("post","/api/payment/checkout",{successUrl:e,cancelUrl:t})}async paymentStartUserCheckout(e,t){return this.execute("post","/api/payment/usercheckout",{successUrl:e,cancelUrl:t})}async getSupportedCurrencies(){return this.execute("get","/api/payment/supportedCurrencies")}async getPurchasables(){return this.execute("get","/api/purchasable")}async getPurchasable(e){return this.execute("get",`/api/purchasable/${e}`)}async createPurchasable(e){return this.execute("post","/api/purchasable",e)}async updatePurchasable(e){return this.execute("put","/api/purchasable",e)}async deletePurchasable(e){return this.execute("delete","/api/purchasable",{id:e})}async getPublicPurchasables(e){return this.execute("get",`/api/purchasable/public/${e}`)}async getPurchases(){return this.execute("get","/api/purchase")}async getMyActivePurchases(){return this.execute("get","/api/purchase/active")}async purchase(e){return this.execute("post","/api/purchase",e)}async changePurchaseProduct(e,t,a){return this.execute("post","/api/purchase/change",{purchaseID:e,purchasableID:t,optionID:a})}async cancelPurchase(e){return this.execute("delete","/api/purchase",{id:e})}async uncancelPurchase(e){return this.execute("post","/api/purchase/uncancel",{id:e})}async getSecureSessionPayload(e,t){return this.execute("get","/api/payment/secureSessionPayload?purchasableID="+e+"&optionID="+t)}async queryPurchases(e,t,a,i,n,r){return this.execute("post","/api/purchase/query",{startDate:e,endDate:t,email:a,invoice:i,cursor:n,limit:r})}async getAttributeTemplates(){return this.execute("get","/api/attributetemplate")}async getAttributeTemplate(e){return this.execute("get",`/api/attributetemplate/${e}`)}async createAttributeTemplate(e){return this.execute("post","/api/attributetemplate",e)}async updateAttributeTemplate(e){return this.execute("put","/api/attributetemplate",e)}async deleteAttributeTemplate(e){return this.execute("delete","/api/attributetemplate",{id:e})}async getStorages(){return this.execute("get","/api/storage")}async getConversation(e){return this.execute("get",`/api/conversation/${e}`)}async getPublicConversation(e){return this.execute("get",`/api/conversation/public/${e}`)}async createConversation(e,t){return this.execute("post","/api/conversation",{parentId:e,parentType:t})}async postConversationMessage(e,t,a){return this.execute("post","/api/conversation/post",{id:e,text:t,replyTo:a})}async editConversationMessage(e,t){return this.execute("put","/api/conversation/post",{id:e,text:t})}async deleteConversationMessage(e){return this.execute("delete","/api/conversation/post",{id:e})}async subscribeToConversation(e){return this.execute("post","/api/conversation/subscribe",{id:e})}async unsubscribeFromConversation(e){return this.execute("post","/api/conversation/unsubscribe",{id:e})}async likeConversationEntry(e){return this.execute("post","/api/conversation/like",{id:e})}async unlikeConversationEntry(e){return this.execute("post","/api/conversation/unlike",{id:e})}async command(e){return this.execute("post","/api/command",e)}async getMailTemplates(){return this.execute("get","/api/mailtemplate")}async getMailTemplate(e){return this.execute("get",`/api/mailtemplate/${e}`)}async createMailTemplate(e){return this.execute("post","/api/mailtemplate",e)}async updateMailTemplate(e){return this.execute("put","/api/mailtemplate",e)}async deleteMailTemplate(e){return this.execute("delete","/api/mailtemplate",{id:e})}async addMailTemplateImage(e,t,a){const i=this._createFormData(a,"image.jpg");return this.execute("post",`/api/mailtemplate/image/${e}/${t}`,i)}async deleteMailTemplateImage(e,t){return this.execute("delete",`/api/mailtemplate/image/${e}/${t}`)}async getMailTemplateNames(){return this.execute("get","/api/mailtemplate/names")}async getMailQuery(e,t,a,i){return this.execute("post","/api/email/query",{templateName:e,dateStart:t,dateEnd:a,success:i},{withNext:true})}async getMail(e){return this.execute("get","/api/email/get?token="+e)}async getInvoiceTemplates(){return this.execute("get","/api/invoicetemplate")}async getInvoiceTemplate(e){return this.execute("get",`/api/invoicetemplate/${e}`)}async createInvoiceTemplate(e){return this.execute("post","/api/invoicetemplate",e)}async updateInvoiceTemplate(e){return this.execute("put","/api/invoicetemplate",e)}async deleteInvoiceTemplate(e){return this.execute("delete","/api/invoicetemplate",{id:e})}async addInvoiceTemplateImage(e,t,a){const i=this._createFormData(a,"image.jpg");return this.execute("post",`/api/invoicetemplate/image/${e}/${t}`,i)}async deleteInvoiceTemplateImage(e,t){return this.execute("delete",`/api/invoicetemplate/image/${e}/${t}`)}async getItemTemplatesList(){return this.execute("get","/api/itemtemplate/list")}async getItemTemplates(){return this.execute("get","/api/itemtemplate")}async createItemTemplate(e){return this.execute("post","/api/itemtemplate",e)}async updateItemTemplate(e){return this.execute("put","/api/itemtemplate",e)}async deleteItemTemplate(e){return this.execute("delete","/api/itemtemplate",{id:e})}async getFeatures(){return this.execute("get","/api/feature")}async getFeaturesOnClient(){return this.execute("get","/api/feature/onclient")}async getFeaturesOnClientForAll(){return this.execute("get","/api/feature/onclientforall")}async getAllFeatures(){return this.execute("get","/api/feature/all")}async getBlogs(){return this.execute("get","/api/blog")}async getBlog(e){return this.execute("get","/api/blog/"+e)}async getPublicBlog(e){return this.execute("get","/api/blog/"+e+"/public")}async createBlog(e,t,a,i){return this.execute("post","/api/blog",{name:e,public:t,commentsEnabled:a,editors:i})}async saveBlog(e,t,a,i,n){return this.execute("put","/api/blog",{_id:e,name:t,public:a,commentsEnabled:i,editors:n})}async deleteBlog(e){return this.execute("delete","/api/blog",{_id:e})}async getBlogOverview(e){return this.execute("get","/api/blog/"+e+"/overview")}async queryBlog(e,t,a,i,n,r,s){return this.execute("post","/api/blog/"+e+"/query",{tag:t,text:a,limit:i,previousArticle:n,searchTag:r,sortBy:s})}async getArticles(e){return this.execute("get","/api/blog/"+e+"/article")}async getArticle(e,t){return this.execute("get","/api/blog/"+e+"/article/"+t)}async getArticleBySlug(e,t){return this.execute("get","/api/blog/article/"+e+"/"+t)}async createArticle(e,t,a){return this.execute("post","/api/blog/"+e+"/article",{title:t,slug:a})}async saveArticle(e,t,a,i,n,r,s,o){return this.execute("put","/api/blog/"+e+"/article",{_id:t,title:a,slug:i,content:o,tags:r,public:n,author:s})}async deleteArticle(e,t){return this.execute("delete","/api/blog/"+e+"/article",{_id:t})}async getNewsletters(){return this.execute("get","/api/newsletter")}async createNewsletter(e,t){return this.execute("post","/api/newsletter",{name:e,editors:t})}async getNewsletter(e){return this.execute("get","/api/newsletter/"+e)}async updateNewsletter(e,t,a,i){return this.execute("put","/api/newsletter/"+e,{name:t,sender:a,editors:i})}async deleteNewsletter(e){return this.execute("delete","/api/newsletter/"+e)}async joinNewsletter(e,t){return this.execute("post","/api/newsletter/join",{id:e,email:t})}async confirmNewsletter(e){return this.execute("post","/api/newsletter/confirm",{token:e})}async unsubscribeFromNewsletter(e){return this.execute("post","/api/newsletter/unsubscribe",{token:e})}async getNewsletterBlocks(){return this.execute("get","/api/newsletterblock")}async getNewsletterBlock(e){return this.execute("get","/api/newsletterblock/"+e)}async createNewsletterBlock(e){return this.execute("post","/api/newsletterblock",{name:e})}async updateNewsletterBlock(e,t,a,i,n,r){return this.execute("put","/api/newsletterblock/"+e,{name:t,inputs:a,html:i,css:n,acceptsChildren:r})}async deleteNewsletterBlock(e){return this.execute("delete","/api/newsletterblock/"+e)}async getNewsletterMails(e){return this.execute("get","/api/newslettermail/"+e)}async getNewsletterMail(e,t){return this.execute("get","/api/newslettermail/"+e+"/"+t)}async createNewsletterMail(e,t){return this.execute("post","/api/newslettermail/"+e,{title:t})}async updateNewsletterMail(e,t,a,i,n){return this.execute("put","/api/newslettermail/"+e+"/"+t,{title:a,blocks:i,parentBlock:n})}async generatePreviewNewsletterMail(e,t){return this.execute("post","/api/newslettermail/render",{blocks:e,parentBlock:t})}async sendTestNewsletter(e,t,a){return this.execute("post","/api/newslettermail/"+e+"/"+t+"/sendTest",{email:a})}async sendOutNewsletter(e,t){return this.execute("post","/api/newslettermail/"+e+"/"+t+"/send",{})}async getPages(){return this.execute("get","/api/page")}async createPage(e,t){return this.execute("post","/api/page",{title:e,slug:t})}async getPage(e){return this.execute("get","/api/page/"+e)}async updatePage(e,t,a,i,n){return this.execute("put","/api/page",{_id:e,title:t,slug:a,public:i,content:n})}async deletePage(e){return this.execute("delete","/api/page",{_id:e})}async getPublicPage(e,t){return this.execute("get","/api/page/public/"+e+"/"+t)}async setItemFlag(e,t,a,i,n,r){return this.execute("post","/api/itemflag",{item:e,isStaffPick:t,featureWeight:a,isGame:i,replaceIndex:n,internalRating:r})}getDownloadUrl(e){return `${this.getApiBaseUrl()}/api/item/download/${e}`}getAttachmentDownloadUrl(e,t,a,i){return `${this.getApiBaseUrl()}${this._getAttachmentUrlPath(e,t,a,i)}`}getPublicAttachmentDownloadUrl(e,t,a,i){return `${this.getApiBaseUrl()}${this._getAttachmentUrlPath(e,t,a,i,true)}`}getPublicDownloadUrl(e){return `${this.getApiBaseUrl()}/api/item/publicdownload/${e}`}async postFeedback(e){return this.execute("post","/api/feedback",{text:e})}}class Ac{linkableItemsCache;apiGateway;itemCache;usePublicApi;constructor(e,t,a=false){this.linkableItemsCache=new Map,this.apiGateway=e,this.itemCache=t,this.usePublicApi=a;}clear(){this.linkableItemsCache.clear();}resolveItem(e,t){for(const a of t)if(a._id===e)return a;return null}async loadLinkableItems(e,t){if(!e)throw "loadLinkableItems(): Item cannot be null!";let a=[];if(t.linkableTypes&&t.linkableTypes.length){if(!this.usePublicApi){const i=t.linkableTypes.join("#")+(e.folder?e.folder._id:"");if(this.linkableItemsCache.has(i))return this.linkableItemsCache.get(i);const n=[...t.linkableTypes];n.includes("Package")||n.push("Package");const r={types:n,folder:e.folder?e.folder._id:null};a=(await this.apiGateway.call("LinkableItemsCache::loadLinkableItems","queryItemsList",r)).filter((e=>"Package"!==e.type||t.linkableTypes.includes(e.packageType)));for(const i of e.links)if(null==this.resolveItem(i.to,a))try{const e=await this.itemCache.getItem(i.to);t.linkableTypes.includes(e.type)&&a.push(e);}catch(e){console.error(`Link item ${i.to} not found. Dead link? (${e})`);}this.linkableItemsCache.set(i,a);}}else {for(const t of e.links){const e=await this.itemCache.getItem(t.to);a.push(e);}const i=t.name+"#CurrentLinks";this.linkableItemsCache.set(i,a);}return a}}
|
|
6600
|
+
*/var Xi=(Ji||(Ji=1,Ki.exports=function e(t,a,i){function n(s,o){if(!a[s]){if(!t[s]){if(!o&&R$a)return R$a(s);if(r)return r(s,true);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var u=a[s]={exports:{}};t[s][0].call(u.exports,(function(e){var a=t[s][1][e];return n(a||e)}),u,u.exports,e,t,a,i);}return a[s].exports}for(var r=R$a,s=0;s<i.length;s++)n(i[s]);return n}({1:[function(e,t,a){(function(e){var a,i,n=e.MutationObserver||e.WebKitMutationObserver;if(n){var r=0,s=new n(c),o=e.document.createTextNode("");s.observe(o,{characterData:true}),a=function(){o.data=r=++r%2;};}else if(e.setImmediate||void 0===e.MessageChannel)a="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){c(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null;},e.document.documentElement.appendChild(t);}:function(){setTimeout(c,0);};else {var l=new e.MessageChannel;l.port1.onmessage=c,a=function(){l.port2.postMessage(0);};}var u=[];function c(){var e,t;i=true;for(var a=u.length;a;){for(t=u,u=[],e=-1;++e<a;)t[e]();a=u.length;}i=false;}function d(e){1!==u.push(e)||i||a();}t.exports=d;}).call(this,void 0!==D?D:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});},{}],2:[function(e,t,a){var i=e(1);function n(){}var r={},s=["REJECTED"],o=["FULFILLED"],l=["PENDING"];function u(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=l,this.queue=[],this.outcome=void 0,e!==n&&h(this,e);}function c(e,t,a){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof a&&(this.onRejected=a,this.callRejected=this.otherCallRejected);}function d(e,t,a){i((function(){var i;try{i=t(a);}catch(t){return r.reject(e,t)}i===e?r.reject(e,new TypeError("Cannot resolve promise with itself")):r.resolve(e,i);}));}function p(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments);}}function h(e,t){var a=false;function i(t){a||(a=true,r.reject(e,t));}function n(t){a||(a=true,r.resolve(e,t));}function s(){t(n,i);}var o=f(s);"error"===o.status&&i(o.value);}function f(e,t){var a={};try{a.value=e(t),a.status="success";}catch(e){a.status="error",a.value=e;}return a}function m(e){return e instanceof this?e:r.resolve(new this(n),e)}function y(e){var t=new this(n);return r.reject(t,e)}function g(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var a=e.length,i=false;if(!a)return this.resolve([]);for(var s=new Array(a),o=0,l=-1,u=new this(n);++l<a;)c(e[l],l);return u;function c(e,n){function l(e){s[n]=e,++o!==a||i||(i=true,r.resolve(u,s));}t.resolve(e).then(l,(function(e){i||(i=true,r.reject(u,e));}));}}function b(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var a=e.length,i=false;if(!a)return this.resolve([]);for(var s=-1,o=new this(n);++s<a;)l(e[s]);return o;function l(e){t.resolve(e).then((function(e){i||(i=true,r.resolve(o,e));}),(function(e){i||(i=true,r.reject(o,e));}));}}t.exports=u,u.prototype.catch=function(e){return this.then(null,e)},u.prototype.then=function(e,t){if("function"!=typeof e&&this.state===o||"function"!=typeof t&&this.state===s)return this;var a=new this.constructor(n);return this.state!==l?d(a,this.state===o?e:t,this.outcome):this.queue.push(new c(a,e,t)),a},c.prototype.callFulfilled=function(e){r.resolve(this.promise,e);},c.prototype.otherCallFulfilled=function(e){d(this.promise,this.onFulfilled,e);},c.prototype.callRejected=function(e){r.reject(this.promise,e);},c.prototype.otherCallRejected=function(e){d(this.promise,this.onRejected,e);},r.resolve=function(e,t){var a=f(p,t);if("error"===a.status)return r.reject(e,a.value);var i=a.value;if(i)h(e,i);else {e.state=o,e.outcome=t;for(var n=-1,s=e.queue.length;++n<s;)e.queue[n].callFulfilled(t);}return e},r.reject=function(e,t){e.state=s,e.outcome=t;for(var a=-1,i=e.queue.length;++a<i;)e.queue[a].callRejected(t);return e},u.resolve=m,u.reject=y,u.all=g,u.race=b;},{1:1}],3:[function(e,t,a){(function(t){"function"!=typeof t.Promise&&(t.Promise=e(2));}).call(this,void 0!==D?D:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{});},{2:2}],4:[function(e,t,a){var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(){try{if("undefined"!=typeof indexedDB)return indexedDB;if("undefined"!=typeof webkitIndexedDB)return webkitIndexedDB;if("undefined"!=typeof mozIndexedDB)return mozIndexedDB;if("undefined"!=typeof OIndexedDB)return OIndexedDB;if("undefined"!=typeof msIndexedDB)return msIndexedDB}catch(e){return}}var s=r();function o(){try{if(!s||!s.open)return !1;var e="undefined"!=typeof openDatabase&&/(Safari|iPhone|iPad|iPod)/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)&&!/BlackBerry/.test(navigator.platform),t="function"==typeof fetch&&-1!==fetch.toString().indexOf("[native code");return (!e||t)&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return false}}function l(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(n){if("TypeError"!==n.name)throw n;for(var a=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),i=0;i<e.length;i+=1)a.append(e[i]);return a.getBlob(t.type)}}"undefined"==typeof Promise&&e(3);var u=Promise;function c(e,t){t&&e.then((function(e){t(null,e);}),(function(e){t(e);}));}function d(e,t,a){"function"==typeof t&&e.then(t),"function"==typeof a&&e.catch(a);}function p(e){return "string"!=typeof e&&(console.warn(e+" used as a key, but it is not a string."),e=String(e)),e}function h(){if(arguments.length&&"function"==typeof arguments[arguments.length-1])return arguments[arguments.length-1]}var f="local-forage-detect-blob-support",m=void 0,y={},g=Object.prototype.toString,b="readonly",v="readwrite";function _(e){for(var t=e.length,a=new ArrayBuffer(t),i=new Uint8Array(a),n=0;n<t;n++)i[n]=e.charCodeAt(n);return a}function w(e){return new u((function(t){var a=e.transaction(f,v),i=l([""]);a.objectStore(f).put(i,"key"),a.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(false);},a.oncomplete=function(){var e=navigator.userAgent.match(/Chrome\/(\d+)/),a=navigator.userAgent.match(/Edge\//);t(a||!e||parseInt(e[1],10)>=43);};})).catch((function(){return false}))}function A(e){return "boolean"==typeof m?u.resolve(m):w(e).then((function(e){return m=e}))}function k(e){var t=y[e.name],a={};a.promise=new u((function(e,t){a.resolve=e,a.reject=t;})),t.deferredOperations.push(a),t.dbReady?t.dbReady=t.dbReady.then((function(){return a.promise})):t.dbReady=a.promise;}function S(e){var t=y[e.name].deferredOperations.pop();if(t)return t.resolve(),t.promise}function N(e,t){var a=y[e.name].deferredOperations.pop();if(a)return a.reject(t),a.promise}function T(e,t){return new u((function(a,i){if(y[e.name]=y[e.name]||R(),e.db){if(!t)return a(e.db);k(e),e.db.close();}var n=[e.name];t&&n.push(e.version);var r=s.open.apply(s,n);t&&(r.onupgradeneeded=function(t){var a=r.result;try{a.createObjectStore(e.storeName),t.oldVersion<=1&&a.createObjectStore(f);}catch(a){if("ConstraintError"!==a.name)throw a;console.warn('The database "'+e.name+'" has been upgraded from version '+t.oldVersion+" to version "+t.newVersion+', but the storage "'+e.storeName+'" already exists.');}}),r.onerror=function(e){e.preventDefault(),i(r.error);},r.onsuccess=function(){var t=r.result;t.onversionchange=function(e){e.target.close();},a(t),S(e);};}))}function M(e){return T(e,false)}function x(e){return T(e,true)}function V(e,t){if(!e.db)return true;var a=!e.db.objectStoreNames.contains(e.storeName),i=e.version<e.db.version,n=e.version>e.db.version;if(i&&(e.version!==t&&console.warn('The database "'+e.name+"\" can't be downgraded from version "+e.db.version+" to version "+e.version+"."),e.version=e.db.version),n||a){if(a){var r=e.db.version+1;r>e.version&&(e.version=r);}return true}return false}function C(e){return new u((function(t,a){var i=new FileReader;i.onerror=a,i.onloadend=function(a){var i=btoa(a.target.result||"");t({__local_forage_encoded_blob:true,data:i,type:e.type});},i.readAsBinaryString(e);}))}function I(e){return l([_(atob(e.data))],{type:e.type})}function F(e){return e&&e.__local_forage_encoded_blob}function E(e){var t=this,a=t._initReady().then((function(){var e=y[t._dbInfo.name];if(e&&e.dbReady)return e.dbReady}));return d(a,e,e),a}function D(e){k(e);for(var t=y[e.name],a=t.forages,i=0;i<a.length;i++){var n=a[i];n._dbInfo.db&&(n._dbInfo.db.close(),n._dbInfo.db=null);}return e.db=null,M(e).then((function(t){return e.db=t,V(e)?x(e):t})).then((function(i){e.db=t.db=i;for(var n=0;n<a.length;n++)a[n]._dbInfo.db=i;})).catch((function(t){throw N(e,t),t}))}function L(e,t,a,i){ void 0===i&&(i=1);try{var n=e.db.transaction(e.storeName,t);a(null,n);}catch(n){if(i>0&&(!e.db||"InvalidStateError"===n.name||"NotFoundError"===n.name))return u.resolve().then((function(){if(!e.db||"NotFoundError"===n.name&&!e.db.objectStoreNames.contains(e.storeName)&&e.version<=e.db.version)return e.db&&(e.version=e.db.version+1),x(e)})).then((function(){return D(e).then((function(){L(e,t,a,i-1);}))})).catch(a);a(n);}}function R(){return {forages:[],db:null,dbReady:null,deferredOperations:[]}}function P(e){var t=this,a={db:null};if(e)for(var i in e)a[i]=e[i];var n=y[a.name];n||(n=R(),y[a.name]=n),n.forages.push(t),t._initReady||(t._initReady=t.ready,t.ready=E);var r=[];function s(){return u.resolve()}for(var o=0;o<n.forages.length;o++){var l=n.forages[o];l!==t&&r.push(l._initReady().catch(s));}var c=n.forages.slice(0);return u.all(r).then((function(){return a.db=n.db,M(a)})).then((function(e){return a.db=e,V(a,t._defaultConfig.version)?x(a):e})).then((function(e){a.db=n.db=e,t._dbInfo=a;for(var i=0;i<c.length;i++){var r=c[i];r!==t&&(r._dbInfo.db=a.db,r._dbInfo.version=a.version);}}))}function O(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){L(a._dbInfo,b,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName).get(e);s.onsuccess=function(){var e=s.result;void 0===e&&(e=null),F(e)&&(e=I(e)),t(e);},s.onerror=function(){i(s.error);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function B(e,t){var a=this,i=new u((function(t,i){a.ready().then((function(){L(a._dbInfo,b,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName).openCursor(),o=1;s.onsuccess=function(){var a=s.result;if(a){var i=a.value;F(i)&&(i=I(i));var n=e(i,a.key,o++);void 0!==n?t(n):a.continue();}else t();},s.onerror=function(){i(s.error);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function $(e,t,a){var i=this;e=p(e);var n=new u((function(a,n){var r;i.ready().then((function(){return r=i._dbInfo,"[object Blob]"===g.call(t)?A(r.db).then((function(e){return e?t:C(t)})):t})).then((function(t){L(i._dbInfo,v,(function(r,s){if(r)return n(r);try{var o=s.objectStore(i._dbInfo.storeName);null===t&&(t=void 0);var l=o.put(t,e);s.oncomplete=function(){void 0===t&&(t=null),a(t);},s.onabort=s.onerror=function(){var e=l.error?l.error:l.transaction.error;n(e);};}catch(e){n(e);}}));})).catch(n);}));return c(n,a),n}function j(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){L(a._dbInfo,v,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName).delete(e);r.oncomplete=function(){t();},r.onerror=function(){i(s.error);},r.onabort=function(){var e=s.error?s.error:s.transaction.error;i(e);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function U(e){var t=this,a=new u((function(e,a){t.ready().then((function(){L(t._dbInfo,v,(function(i,n){if(i)return a(i);try{var r=n.objectStore(t._dbInfo.storeName).clear();n.oncomplete=function(){e();},n.onabort=n.onerror=function(){var e=r.error?r.error:r.transaction.error;a(e);};}catch(e){a(e);}}));})).catch(a);}));return c(a,e),a}function z(e){var t=this,a=new u((function(e,a){t.ready().then((function(){L(t._dbInfo,b,(function(i,n){if(i)return a(i);try{var r=n.objectStore(t._dbInfo.storeName).count();r.onsuccess=function(){e(r.result);},r.onerror=function(){a(r.error);};}catch(e){a(e);}}));})).catch(a);}));return c(a,e),a}function W(e,t){var a=this,i=new u((function(t,i){e<0?t(null):a.ready().then((function(){L(a._dbInfo,b,(function(n,r){if(n)return i(n);try{var s=r.objectStore(a._dbInfo.storeName),o=!1,l=s.openKeyCursor();l.onsuccess=function(){var a=l.result;a?0===e||o?t(a.key):(o=!0,a.advance(e)):t(null);},l.onerror=function(){i(l.error);};}catch(e){i(e);}}));})).catch(i);}));return c(i,t),i}function Y(e){var t=this,a=new u((function(e,a){t.ready().then((function(){L(t._dbInfo,b,(function(i,n){if(i)return a(i);try{var r=n.objectStore(t._dbInfo.storeName).openKeyCursor(),s=[];r.onsuccess=function(){var t=r.result;t?(s.push(t.key),t.continue()):e(s);},r.onerror=function(){a(r.error);};}catch(e){a(e);}}));})).catch(a);}));return c(a,e),a}function H(e,t){t=h.apply(this,arguments);var a=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||a.name,e.storeName=e.storeName||a.storeName);var i,n=this;if(e.name){var r=e.name===a.name&&n._dbInfo.db?u.resolve(n._dbInfo.db):M(e).then((function(t){var a=y[e.name],i=a.forages;a.db=t;for(var n=0;n<i.length;n++)i[n]._dbInfo.db=t;return t}));i=e.storeName?r.then((function(t){if(t.objectStoreNames.contains(e.storeName)){var a=t.version+1;k(e);var i=y[e.name],n=i.forages;t.close();for(var r=0;r<n.length;r++){var o=n[r];o._dbInfo.db=null,o._dbInfo.version=a;}var l=new u((function(t,i){var n=s.open(e.name,a);n.onerror=function(e){n.result.close(),i(e);},n.onupgradeneeded=function(){n.result.deleteObjectStore(e.storeName);},n.onsuccess=function(){var e=n.result;e.close(),t(e);};}));return l.then((function(e){i.db=e;for(var t=0;t<n.length;t++){var a=n[t];a._dbInfo.db=e,S(a._dbInfo);}})).catch((function(t){throw (N(e,t)||u.resolve()).catch((function(){})),t}))}})):r.then((function(t){k(e);var a=y[e.name],i=a.forages;t.close();for(var n=0;n<i.length;n++)i[n]._dbInfo.db=null;var r=new u((function(t,a){var i=s.deleteDatabase(e.name);i.onerror=function(){var e=i.result;e&&e.close(),a(i.error);},i.onblocked=function(){console.warn('dropInstance blocked for database "'+e.name+'" until all open connections are closed');},i.onsuccess=function(){var e=i.result;e&&e.close(),t(e);};}));return r.then((function(e){a.db=e;for(var t=0;t<i.length;t++)S(i[t]._dbInfo);})).catch((function(t){throw (N(e,t)||u.resolve()).catch((function(){})),t}))}));}else i=u.reject("Invalid arguments");return c(i,t),i}var G={_driver:"asyncStorage",_initStorage:P,_support:o(),iterate:B,getItem:O,setItem:$,removeItem:j,clear:U,length:z,key:W,keys:Y,dropInstance:H};function q(){return "function"==typeof openDatabase}var Z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",J="~~local_forage_type~",K=/^~~local_forage_type~([^~]+)~/,X="__lfsc__:",Q=X.length,ee="arbf",te="blob",ae="si08",ie="ui08",ne="uic8",re="si16",se="si32",oe="ur16",le="ui32",ue="fl32",ce="fl64",de=Q+ee.length,pe=Object.prototype.toString;function he(e){var t,a,i,n,r,s=.75*e.length,o=e.length,l=0;"="===e[e.length-1]&&(s--,"="===e[e.length-2]&&s--);var u=new ArrayBuffer(s),c=new Uint8Array(u);for(t=0;t<o;t+=4)a=Z.indexOf(e[t]),i=Z.indexOf(e[t+1]),n=Z.indexOf(e[t+2]),r=Z.indexOf(e[t+3]),c[l++]=a<<2|i>>4,c[l++]=(15&i)<<4|n>>2,c[l++]=(3&n)<<6|63&r;return u}function fe(e){var t,a=new Uint8Array(e),i="";for(t=0;t<a.length;t+=3)i+=Z[a[t]>>2],i+=Z[(3&a[t])<<4|a[t+1]>>4],i+=Z[(15&a[t+1])<<2|a[t+2]>>6],i+=Z[63&a[t+2]];return a.length%3==2?i=i.substring(0,i.length-1)+"=":a.length%3==1&&(i=i.substring(0,i.length-2)+"=="),i}function me(e,t){var a="";if(e&&(a=pe.call(e)),e&&("[object ArrayBuffer]"===a||e.buffer&&"[object ArrayBuffer]"===pe.call(e.buffer))){var i,n=X;e instanceof ArrayBuffer?(i=e,n+=ee):(i=e.buffer,"[object Int8Array]"===a?n+=ae:"[object Uint8Array]"===a?n+=ie:"[object Uint8ClampedArray]"===a?n+=ne:"[object Int16Array]"===a?n+=re:"[object Uint16Array]"===a?n+=oe:"[object Int32Array]"===a?n+=se:"[object Uint32Array]"===a?n+=le:"[object Float32Array]"===a?n+=ue:"[object Float64Array]"===a?n+=ce:t(new Error("Failed to get type for BinaryArray"))),t(n+fe(i));}else if("[object Blob]"===a){var r=new FileReader;r.onload=function(){var a=J+e.type+"~"+fe(this.result);t(X+te+a);},r.readAsArrayBuffer(e);}else try{t(JSON.stringify(e));}catch(a){console.error("Couldn't convert value into a JSON string: ",e),t(null,a);}}function ye(e){if(e.substring(0,Q)!==X)return JSON.parse(e);var t,a=e.substring(de),i=e.substring(Q,de);if(i===te&&K.test(a)){var n=a.match(K);t=n[1],a=a.substring(n[0].length);}var r=he(a);switch(i){case ee:return r;case te:return l([r],{type:t});case ae:return new Int8Array(r);case ie:return new Uint8Array(r);case ne:return new Uint8ClampedArray(r);case re:return new Int16Array(r);case oe:return new Uint16Array(r);case se:return new Int32Array(r);case le:return new Uint32Array(r);case ue:return new Float32Array(r);case ce:return new Float64Array(r);default:throw new Error("Unkown type: "+i)}}var ge={serialize:me,deserialize:ye,stringToBuffer:he,bufferToString:fe};function be(e,t,a,i){e.executeSql("CREATE TABLE IF NOT EXISTS "+t.storeName+" (id INTEGER PRIMARY KEY, key unique, value)",[],a,i);}function ve(e){var t=this,a={db:null};if(e)for(var i in e)a[i]="string"!=typeof e[i]?e[i].toString():e[i];var n=new u((function(e,i){try{a.db=openDatabase(a.name,String(a.version),a.description,a.size);}catch(e){return i(e)}a.db.transaction((function(n){be(n,a,(function(){t._dbInfo=a,e();}),(function(e,t){i(t);}));}),i);}));return a.serializer=ge,n}function _e(e,t,a,i,n,r){e.executeSql(a,i,n,(function(e,s){s.code===s.SYNTAX_ERR?e.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name = ?",[t.storeName],(function(e,o){o.rows.length?r(e,s):be(e,t,(function(){e.executeSql(a,i,n,r);}),r);}),r):r(e,s);}),r);}function we(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"SELECT * FROM "+n.storeName+" WHERE key = ? LIMIT 1",[e],(function(e,a){var i=a.rows.length?a.rows.item(0).value:null;i&&(i=n.serializer.deserialize(i)),t(i);}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function Ae(e,t){var a=this,i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"SELECT * FROM "+n.storeName,[],(function(a,i){for(var r=i.rows,s=r.length,o=0;o<s;o++){var l=r.item(o),u=l.value;if(u&&(u=n.serializer.deserialize(u)),void 0!==(u=e(u,l.key,o+1)))return void t(u)}t();}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function ke(e,t,a,i){var n=this;e=p(e);var r=new u((function(r,s){n.ready().then((function(){ void 0===t&&(t=null);var o=t,l=n._dbInfo;l.serializer.serialize(t,(function(t,u){u?s(u):l.db.transaction((function(a){_e(a,l,"INSERT OR REPLACE INTO "+l.storeName+" (key, value) VALUES (?, ?)",[e,t],(function(){r(o);}),(function(e,t){s(t);}));}),(function(t){if(t.code===t.QUOTA_ERR){if(i>0)return void r(ke.apply(n,[e,o,a,i-1]));s(t);}}));}));})).catch(s);}));return c(r,a),r}function Se(e,t,a){return ke.apply(this,[e,t,a,1])}function Ne(e,t){var a=this;e=p(e);var i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"DELETE FROM "+n.storeName+" WHERE key = ?",[e],(function(){t();}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function Te(e){var t=this,a=new u((function(e,a){t.ready().then((function(){var i=t._dbInfo;i.db.transaction((function(t){_e(t,i,"DELETE FROM "+i.storeName,[],(function(){e();}),(function(e,t){a(t);}));}));})).catch(a);}));return c(a,e),a}function Me(e){var t=this,a=new u((function(e,a){t.ready().then((function(){var i=t._dbInfo;i.db.transaction((function(t){_e(t,i,"SELECT COUNT(key) as c FROM "+i.storeName,[],(function(t,a){var i=a.rows.item(0).c;e(i);}),(function(e,t){a(t);}));}));})).catch(a);}));return c(a,e),a}function xe(e,t){var a=this,i=new u((function(t,i){a.ready().then((function(){var n=a._dbInfo;n.db.transaction((function(a){_e(a,n,"SELECT key FROM "+n.storeName+" WHERE id = ? LIMIT 1",[e+1],(function(e,a){var i=a.rows.length?a.rows.item(0).key:null;t(i);}),(function(e,t){i(t);}));}));})).catch(i);}));return c(i,t),i}function Ve(e){var t=this,a=new u((function(e,a){t.ready().then((function(){var i=t._dbInfo;i.db.transaction((function(t){_e(t,i,"SELECT key FROM "+i.storeName,[],(function(t,a){for(var i=[],n=0;n<a.rows.length;n++)i.push(a.rows.item(n).key);e(i);}),(function(e,t){a(t);}));}));})).catch(a);}));return c(a,e),a}function Ce(e){return new u((function(t,a){e.transaction((function(i){i.executeSql("SELECT name FROM sqlite_master WHERE type='table' AND name <> '__WebKitDatabaseInfoTable__'",[],(function(a,i){for(var n=[],r=0;r<i.rows.length;r++)n.push(i.rows.item(r).name);t({db:e,storeNames:n});}),(function(e,t){a(t);}));}),(function(e){a(e);}));}))}function Ie(e,t){t=h.apply(this,arguments);var a=this.config();(e="function"!=typeof e&&e||{}).name||(e.name=e.name||a.name,e.storeName=e.storeName||a.storeName);var i,n=this;return c(i=e.name?new u((function(t){var i;i=e.name===a.name?n._dbInfo.db:openDatabase(e.name,"","",0),e.storeName?t({db:i,storeNames:[e.storeName]}):t(Ce(i));})).then((function(e){return new u((function(t,a){e.db.transaction((function(i){function n(e){return new u((function(t,a){i.executeSql("DROP TABLE IF EXISTS "+e,[],(function(){t();}),(function(e,t){a(t);}));}))}for(var r=[],s=0,o=e.storeNames.length;s<o;s++)r.push(n(e.storeNames[s]));u.all(r).then((function(){t();})).catch((function(e){a(e);}));}),(function(e){a(e);}));}))})):u.reject("Invalid arguments"),t),i}var Fe={_driver:"webSQLStorage",_initStorage:ve,_support:q(),iterate:Ae,getItem:we,setItem:Se,removeItem:Ne,clear:Te,length:Me,key:xe,keys:Ve,dropInstance:Ie};function Ee(){try{return "undefined"!=typeof localStorage&&"setItem"in localStorage&&!!localStorage.setItem}catch(e){return false}}function De(e,t){var a=e.name+"/";return e.storeName!==t.storeName&&(a+=e.storeName+"/"),a}function Le(){var e="_localforage_support_test";try{return localStorage.setItem(e,!0),localStorage.removeItem(e),!1}catch(e){return true}}function Re(){return !Le()||localStorage.length>0}function Pe(e){var t=this,a={};if(e)for(var i in e)a[i]=e[i];return a.keyPrefix=De(e,t._defaultConfig),Re()?(t._dbInfo=a,a.serializer=ge,u.resolve()):u.reject()}function Oe(e){var t=this,a=t.ready().then((function(){for(var e=t._dbInfo.keyPrefix,a=localStorage.length-1;a>=0;a--){var i=localStorage.key(a);0===i.indexOf(e)&&localStorage.removeItem(i);}}));return c(a,e),a}function Be(e,t){var a=this;e=p(e);var i=a.ready().then((function(){var t=a._dbInfo,i=localStorage.getItem(t.keyPrefix+e);return i&&(i=t.serializer.deserialize(i)),i}));return c(i,t),i}function $e(e,t){var a=this,i=a.ready().then((function(){for(var t=a._dbInfo,i=t.keyPrefix,n=i.length,r=localStorage.length,s=1,o=0;o<r;o++){var l=localStorage.key(o);if(0===l.indexOf(i)){var u=localStorage.getItem(l);if(u&&(u=t.serializer.deserialize(u)),void 0!==(u=e(u,l.substring(n),s++)))return u}}}));return c(i,t),i}function je(e,t){var a=this,i=a.ready().then((function(){var t,i=a._dbInfo;try{t=localStorage.key(e);}catch(e){t=null;}return t&&(t=t.substring(i.keyPrefix.length)),t}));return c(i,t),i}function Ue(e){var t=this,a=t.ready().then((function(){for(var e=t._dbInfo,a=localStorage.length,i=[],n=0;n<a;n++){var r=localStorage.key(n);0===r.indexOf(e.keyPrefix)&&i.push(r.substring(e.keyPrefix.length));}return i}));return c(a,e),a}function ze(e){var t=this.keys().then((function(e){return e.length}));return c(t,e),t}function We(e,t){var a=this;e=p(e);var i=a.ready().then((function(){var t=a._dbInfo;localStorage.removeItem(t.keyPrefix+e);}));return c(i,t),i}function Ye(e,t,a){var i=this;e=p(e);var n=i.ready().then((function(){ void 0===t&&(t=null);var a=t;return new u((function(n,r){var s=i._dbInfo;s.serializer.serialize(t,(function(t,i){if(i)r(i);else try{localStorage.setItem(s.keyPrefix+e,t),n(a);}catch(e){"QuotaExceededError"!==e.name&&"NS_ERROR_DOM_QUOTA_REACHED"!==e.name||r(e),r(e);}}));}))}));return c(n,a),n}function He(e,t){if(t=h.apply(this,arguments),!(e="function"!=typeof e&&e||{}).name){var a=this.config();e.name=e.name||a.name,e.storeName=e.storeName||a.storeName;}var i,n=this;return i=e.name?new u((function(t){e.storeName?t(De(e,n._defaultConfig)):t(e.name+"/");})).then((function(e){for(var t=localStorage.length-1;t>=0;t--){var a=localStorage.key(t);0===a.indexOf(e)&&localStorage.removeItem(a);}})):u.reject("Invalid arguments"),c(i,t),i}var Ge={_driver:"localStorageWrapper",_initStorage:Pe,_support:Ee(),iterate:$e,getItem:Be,setItem:Ye,removeItem:We,clear:Oe,length:ze,key:je,keys:Ue,dropInstance:He},qe=function(e,t){return e===t||"number"==typeof e&&"number"==typeof t&&isNaN(e)&&isNaN(t)},Ze=function(e,t){for(var a=e.length,i=0;i<a;){if(qe(e[i],t))return true;i++;}return false},Je=Array.isArray||function(e){return "[object Array]"===Object.prototype.toString.call(e)},Ke={},Xe={},Qe={INDEXEDDB:G,WEBSQL:Fe,LOCALSTORAGE:Ge},et=[Qe.INDEXEDDB._driver,Qe.WEBSQL._driver,Qe.LOCALSTORAGE._driver],tt=["dropInstance"],at=["clear","getItem","iterate","key","keys","length","removeItem","setItem"].concat(tt),it={description:"",driver:et.slice(),name:"localforage",size:4980736,storeName:"keyvaluepairs",version:1};function nt(e,t){e[t]=function(){var a=arguments;return e.ready().then((function(){return e[t].apply(e,a)}))};}function rt(){for(var e=1;e<arguments.length;e++){var t=arguments[e];if(t)for(var a in t)t.hasOwnProperty(a)&&(Je(t[a])?arguments[0][a]=t[a].slice():arguments[0][a]=t[a]);}return arguments[0]}var st=function(){function e(t){for(var a in n(this,e),Qe)if(Qe.hasOwnProperty(a)){var i=Qe[a],r=i._driver;this[a]=r,Ke[r]||this.defineDriver(i);}this._defaultConfig=rt({},it),this._config=rt({},this._defaultConfig,t),this._driverSet=null,this._initDriver=null,this._ready=false,this._dbInfo=null,this._wrapLibraryMethodsWithReady(),this.setDriver(this._config.driver).catch((function(){}));}return e.prototype.config=function(e){if("object"===(void 0===e?"undefined":i(e))){if(this._ready)return new Error("Can't call config() after localforage has been used.");for(var t in e){if("storeName"===t&&(e[t]=e[t].replace(/\W/g,"_")),"version"===t&&"number"!=typeof e[t])return new Error("Database version must be a number.");this._config[t]=e[t];}return !("driver"in e)||!e.driver||this.setDriver(this._config.driver)}return "string"==typeof e?this._config[e]:this._config},e.prototype.defineDriver=function(e,t,a){var i=new u((function(t,a){try{var i=e._driver,n=new Error("Custom driver not compliant; see https://mozilla.github.io/localForage/#definedriver");if(!e._driver)return void a(n);for(var r=at.concat("_initStorage"),s=0,o=r.length;s<o;s++){var l=r[s];if((!Ze(tt,l)||e[l])&&"function"!=typeof e[l])return void a(n)}var d=function(){for(var t=function(e){return function(){var t=new Error("Method "+e+" is not implemented by the current driver"),a=u.reject(t);return c(a,arguments[arguments.length-1]),a}},a=0,i=tt.length;a<i;a++){var n=tt[a];e[n]||(e[n]=t(n));}};d();var p=function(a){Ke[i]&&console.info("Redefining LocalForage driver: "+i),Ke[i]=e,Xe[i]=a,t();};"_support"in e?e._support&&"function"==typeof e._support?e._support().then(p,a):p(!!e._support):p(!0);}catch(e){a(e);}}));return d(i,t,a),i},e.prototype.driver=function(){return this._driver||null},e.prototype.getDriver=function(e,t,a){var i=Ke[e]?u.resolve(Ke[e]):u.reject(new Error("Driver not found."));return d(i,t,a),i},e.prototype.getSerializer=function(e){var t=u.resolve(ge);return d(t,e),t},e.prototype.ready=function(e){var t=this,a=t._driverSet.then((function(){return null===t._ready&&(t._ready=t._initDriver()),t._ready}));return d(a,e,e),a},e.prototype.setDriver=function(e,t,a){var i=this;Je(e)||(e=[e]);var n=this._getSupportedDrivers(e);function r(){i._config.driver=i.driver();}function s(e){return i._extend(e),r(),i._ready=i._initStorage(i._config),i._ready}function o(e){return function(){var t=0;function a(){for(;t<e.length;){var n=e[t];return t++,i._dbInfo=null,i._ready=null,i.getDriver(n).then(s).catch(a)}r();var o=new Error("No available storage method found.");return i._driverSet=u.reject(o),i._driverSet}return a()}}var l=null!==this._driverSet?this._driverSet.catch((function(){return u.resolve()})):u.resolve();return this._driverSet=l.then((function(){var e=n[0];return i._dbInfo=null,i._ready=null,i.getDriver(e).then((function(e){i._driver=e._driver,r(),i._wrapLibraryMethodsWithReady(),i._initDriver=o(n);}))})).catch((function(){r();var e=new Error("No available storage method found.");return i._driverSet=u.reject(e),i._driverSet})),d(this._driverSet,t,a),this._driverSet},e.prototype.supports=function(e){return !!Xe[e]},e.prototype._extend=function(e){rt(this,e);},e.prototype._getSupportedDrivers=function(e){for(var t=[],a=0,i=e.length;a<i;a++){var n=e[a];this.supports(n)&&t.push(n);}return t},e.prototype._wrapLibraryMethodsWithReady=function(){for(var e=0,t=at.length;e<t;e++)nt(this,at[e]);},e.prototype.createInstance=function(t){return new e(t)},e}(),ot=new st;t.exports=ot;},{3:3}]},{},[4])(4)),Ki.exports),Qi=L$1(Xi);let en$1 = class en{databaseName;collectionName;size;_store;constructor(e,t,a){Qi.config({driver:Qi.INDEXEDDB}),this.databaseName=e||"lumino-cache",this.collectionName=t||"data",this.size=a,this._store=Qi.createInstance({name:this.databaseName,storeName:this.collectionName});}async init(){}async _keys(){return this._store.keys()}async _set(e,t){return this._store.setItem(e,t)}async _clear(){return this._store.clear()}async _get(e){return this._store.getItem(e)}async _remove(e){return this._store.removeItem(e)}};function tn(e){let t,a,i,n;e.onmessage=async r=>{const s=r.data;try{switch(s.type){case "init":{i=s.databaseName,n=s.collectionName,t=await navigator.storage.getDirectory();const r=await t.getDirectoryHandle(i,{create:!0});a=await r.getDirectoryHandle(n,{create:!0}),e.postMessage({type:s.type,database:i,collection:n,success:!0});break}case "write":{if(!a)throw new Error("OPFS Worker: not initialized yet!");const t=await a.getFileHandle(s.filename,{create:!0}),r=await t.createSyncAccessHandle();let o;if("string"==typeof s.content){o=(new TextEncoder).encode(s.content).buffer;}else if(s.content instanceof ArrayBuffer)o=s.content;else {if(!(s.content instanceof Blob))throw new Error("OPFS Worker: Unsupported content type: "+typeof s.content);o=await s.content.arrayBuffer();}r.truncate(o.byteLength),r.write(o,{at:0}),await r.flush(),r.close(),e.postMessage({type:s.type,database:i,collection:n,success:!0});break}}}catch(t){e.postMessage({type:s.type,success:false,database:i,collection:n,error:t.message});}};}let an$1 = class an{databaseName;collectionName;size;_worker;_storage;_root;constructor(e,t,a){this.databaseName=e||"lumino-cache",this.collectionName=t||"data",this.size=a;}async init(){if("object"==typeof globalThis.navigator&&"storage"in globalThis.navigator&&"function"==typeof globalThis.navigator.storage.getDirectory){this._storage=await navigator.storage.getDirectory();const e=await this._storage.getDirectoryHandle(this.databaseName,{create:true});let t,a;this._root=await e.getDirectoryHandle(this.collectionName,{create:true}),this._worker=new Worker(URL.createObjectURL(new Blob(["(",tn.toString(),")(self)"],{type:"application/javascript"})),{type:"module"});let i=new Promise(((e,i)=>{t=e,a=i;}));return this._worker.onmessage=e=>{const i=e.data;i.success||console.error("OPFS Worker failed:",i),"init"===i.type&&(i.success?t():a(i.error));},this._worker.postMessage({type:"init",databaseName:this.databaseName,collectionName:this.collectionName}),i}}async _keys(){if(!this._root)return [];const e=[];for await(const t of this._root.values())e.push(t.name);return e}async _set(e,t){if(!this._root)return;let a;if(t instanceof Blob)a=t;else if("object"==typeof t){const e=JSON.stringify(t,null,2);a=new Blob([e],{type:"application/json"});}else a=new Blob([t],{type:"text/plain"});const i=await this._root.getFileHandle(e,{create:true});if("function"==typeof i.createWritable){const e=await i.createWritable();await e.write(a),await e.close();}else this._worker.postMessage({type:"write",filename:e,content:a});}async _clear(){if(!this._root)return;const e=[];for await(const t of this._root.values())e.push(this._root.removeEntry(t.name));return Promise.all(e)}async _get(e,t){if(!this._root)return null;let a;try{const t=await this._root.getFileHandle(e);a=await t.getFile();}catch(e){return null}switch(t=t||a.type){case "text/plain":return a.text();case "application/json":{const e=await a.text();try{return JSON.parse(e)}catch(t){return console.error("Content was loaded from cache but could not be json parsed: ",e),null}}default:return a}}async _remove(e){if(this._root)return this._root.removeEntry(e)}};let nn$1 = class nn{databaseName;collectionName;size;type;_impl;constructor(e,t,a=0,i=1){switch(this.databaseName=e||"lumino",this.collectionName=t||"data",this.size=1048576*(i||1),this.type=a,this.type){case 0:this._impl=new en$1(this.databaseName,this.collectionName,this.size);break;case 1:this._impl=new an$1(this.databaseName,this.collectionName,this.size);break;default:throw "Invalid storage type: "+a}}async init(){return this._impl.init()}async _keys(){return this._impl._keys()}fixKey(e){return e.replaceAll("/","_")}async _set(e,t){return this._impl._set(this.fixKey(e),t)}async _clear(){return this._impl._clear()}async _get(e,t){return this._impl._get(this.fixKey(e),t)}async _remove(e){return this._impl._remove(this.fixKey(e))}};var rn$1,sn$1,on$2,ln,un,cn$1,dn$1,pn$1,hn,fn,mn$1,yn$1,gn,bn$1,vn,_n,wn$1,An,kn,Sn,Nn,Tn,Mn,xn$1,Vn$1,Cn$1,In,Fn;function En(){if(sn$1)return rn$1;return sn$1=1,rn$1=function(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}}function Dn$1(){if(cn$1)return un;cn$1=1;var e=function(){if(ln)return on$2;ln=1;var e="object"==typeof D&&D&&D.Object===Object&&D;return on$2=e}(),t="object"==typeof self&&self&&self.Object===Object&&self,a=e||t||Function("return this")();return un=a}function Ln(){if(yn$1)return mn$1;yn$1=1;var e=function(){if(fn)return hn;fn=1;var e=/\s/;return hn=function(t){for(var a=t.length;a--&&e.test(t.charAt(a)););return a}}(),t=/^\s+/;return mn$1=function(a){return a?a.slice(0,e(a)+1).replace(t,""):a}}function Rn(){if(bn$1)return gn;bn$1=1;var e=Dn$1().Symbol;return gn=e}function Pn(){if(Sn)return kn;Sn=1;var e=Rn(),t=function(){if(_n)return vn;_n=1;var e=Rn(),t=Object.prototype,a=t.hasOwnProperty,i=t.toString,n=e?e.toStringTag:void 0;return vn=function(e){var t=a.call(e,n),r=e[n];try{e[n]=void 0;var s=!0;}catch(e){}var o=i.call(e);return s&&(t?e[n]=r:delete e[n]),o}}(),a=function(){if(An)return wn$1;An=1;var e=Object.prototype.toString;return wn$1=function(t){return e.call(t)}}(),i=e?e.toStringTag:void 0;return kn=function(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":i&&i in Object(e)?t(e):a(e)}}function On(){if(xn$1)return Mn;xn$1=1;var e=Pn(),t=Tn?Nn:(Tn=1,Nn=function(e){return null!=e&&"object"==typeof e});return Mn=function(a){return "symbol"==typeof a||t(a)&&"[object Symbol]"==e(a)}}var Bn=function(){if(Fn)return In;Fn=1;var e=En(),t=function(){if(pn$1)return dn$1;pn$1=1;var e=Dn$1();return dn$1=function(){return e.Date.now()}}(),a=function(){if(Cn$1)return Vn$1;Cn$1=1;var e=Ln(),t=En(),a=On(),i=/^[-+]0x[0-9a-f]+$/i,n=/^0b[01]+$/i,r=/^0o[0-7]+$/i,s=parseInt;return Vn$1=function(o){if("number"==typeof o)return o;if(a(o))return NaN;if(t(o)){var l="function"==typeof o.valueOf?o.valueOf():o;o=t(l)?l+"":l;}if("string"!=typeof o)return 0===o?o:+o;o=e(o);var u=n.test(o);return u||r.test(o)?s(o.slice(2),u?2:8):i.test(o)?NaN:+o}}(),i=Math.max,n=Math.min;return In=function(r,s,o){var l,u,c,d,p,h,f=0,m=false,y=false,g=true;if("function"!=typeof r)throw new TypeError("Expected a function");function b(e){var t=l,a=u;return l=u=void 0,f=e,d=r.apply(a,t)}function v(e){var t=e-h;return void 0===h||t>=s||t<0||y&&e-f>=c}function _(){var e=t();if(v(e))return w(e);p=setTimeout(_,function(e){var t=s-(e-h);return y?n(t,c-(e-f)):t}(e));}function w(e){return p=void 0,g&&l?b(e):(l=u=void 0,d)}function A(){var e=t(),a=v(e);if(l=arguments,u=this,h=e,a){if(void 0===p)return function(e){return f=e,p=setTimeout(_,s),m?b(e):d}(h);if(y)return clearTimeout(p),p=setTimeout(_,s),b(h)}return void 0===p&&(p=setTimeout(_,s)),d}return s=a(s)||0,e(o)&&(m=!!o.leading,c=(y="maxWait"in o)?i(a(o.maxWait)||0,s):c,g="trailing"in o?!!o.trailing:g),A.cancel=function(){ void 0!==p&&clearTimeout(p),f=0,l=h=u=p=void 0;},A.flush=function(){return void 0===p?d:w(t())},A}}(),$n=L$1(Bn);class jn extends nn$1{apiClient;cache=new Map;urlToIdMap=new Map;logging=false;ready=false;usePublicApi=false;quota=0;size=0;usePersistentStorage=false;saveIndex;constructor(e,t,a,i){if(super("lumino","items",1),!a)throw "A lumino client needs to be passed.";this.apiClient=a,this.usePublicApi=e,this.quota=1048576*(i||1024),this.usePersistentStorage=t;this.saveIndex=$n((()=>{const e=[];for(const t of this.cache.values())e.push({id:t.id,time:t.time.valueOf(),size:t.size,hash:t.hash,itemType:t.itemType,mimeType:t.mimeType,itemName:t.itemName});this._set("index",e).then((function(){})).catch((function(e){console.error("Error saving cache index: "+e);}));}),1e3);}async init(){return await super.init(),this.initFromStorage()}getQuota(){return this.quota}setQuota(e){this.quota=e,this.checkQuota();}getCount(){return this.cache.size}getSize(){return this.size}async initFromStorage(){if(this.usePersistentStorage){const e=await this._get("index","application/json");if(e&&Array.isArray(e))for(const t of e)t.time=j(t.time),this.cache.set(t.id,t),this.size+=t.size;else await this._clear(),this.saveIndex();}this.ready=true,u$3.$emit("itemCache:cacheReady"),u$3.$emit("itemCache:cacheChange"),u$3.$on("item:rename",(e=>this.handleRename(e)));}async addToStorage(e,t){if(this.usePersistentStorage){const a={id:e.id,time:j(e.time.toDate()),size:e.size,hash:e.hash,itemType:e.itemType,mimeType:e.mimeType,itemName:e.itemName};await this._set(`blob_${e.id}`,t),this.cache.set(e.id,a),this.saveIndex();}this.size+=e.size;}waitUntilReady(){const e=this;return new Promise(((t,a)=>{try{e.ready?t():u$3.$on("itemCache:cacheReady",(()=>{t();}));}catch(e){a(e);}}))}findObject(e){return this.cache.get(e)}getEntries(){return this.cache.values()}clear(){for(const e of this.cache.values())e.objectUrl&&URL.revokeObjectURL(e.objectUrl);this.cache.clear(),u$3.$emit("itemCache:cacheChange"),this.usePersistentStorage&&this._clear().then((function(){console.log("Cache storage cleared.");})).catch((function(e){console.error(e);}));}clearMemory(){for(let e of this.cache.values())e.objectUrl&&(URL.revokeObjectURL(e.objectUrl),delete e.objectUrl);u$3.$emit("itemCache:cacheChange");}checkQuota(e=0){let t=this.size+e;if(t>this.quota){const e=[...this.cache.entries()].sort((function(e,t){return e[1].time.valueOf()-t[1].time.valueOf()}));let a=0;for(;t>this.quota&&a<e.length;){const i=e[a][1];i.objectUrl||(t-=i.size,this.removeObjectFromCache(i.id)),a++;}}}removeObjectFromCache(e){const t=this.cache.get(e);t&&(t.objectUrl&&URL.revokeObjectURL(t.objectUrl),this.cache.delete(e),this.size-=t.size,this.usePersistentStorage&&(this._remove(`blob_${t.id}`).then((function(){console.log(`Removed blob for ${e} from cache`);})).catch((function(t){console.error(`Error removing blob for ${e} from cache: ${t}`);})),this.saveIndex()));}getIdFromUrl(e){return this.urlToIdMap.has(e)?this.urlToIdMap.get(e):null}getById(e){const t=this.findObject(e);return t?(this.logging&&console.log("Retrieving from cache: "+e),t.time=j(),t):(this.logging&&console.error("Object not in cache: "+e),null)}getObjectUrl(e){const t=this.getIdFromUrl(e);if(!t)return console.error("Could not find URL in cache: "+e),"";const a=this.getById(t);return a?a.objectUrl:(console.error("Could not find Id in cache: "+t),"")}async getBufferById(e){const t=await this.getBlobById(e);return t?await new Response(t).arrayBuffer():null}async getBlobById(e){const t=this.getById(e);return t?await fetch(t.objectUrl).then((e=>e.blob())):null}async loadFromStorage(e){if(e.objectUrl)return true;let t=null;return !!this.usePersistentStorage&&(t=await this._get(`blob_${e.id}`),!!t&&(e.objectUrl=URL.createObjectURL(t),e.time=j(),this.saveIndex(),u$3.$emit("itemCache:cacheChange"),true))}getCacheKey(e,t){return t&&"item"!==t.type?e+"_lod"+t.index:e}_getLodLevelUrl(e,t){let a;return a=t&&"item"!==t.type?this.apiClient.getAttachmentDownloadUrl(e,"lod",t.index):this.apiClient.getDownloadUrl(e),a}async loadItem(e,t,a){let i=0;for(;;)try{let i;if(this.usePublicApi)i=t&&"item"!==t.type?await this.apiClient.downloadPublicAttachment(e,"lod",t.index,void 0,a):await this.apiClient.publicDownloadItem(e,a);else try{i=t&&"item"!==t.type?await this.apiClient.downloadAttachment(e,"lod",t.index,void 0,a):await this.apiClient.downloadItem(e,a);}catch{i=t&&"item"!==t.type?await this.apiClient.downloadPublicAttachment(e,"lod",t.index,void 0,a):await this.apiClient.publicDownloadItem(e,a);}return i}catch(t){if(console.log(t),i++,!(i<3))return u$3.$emit("client:fatalError",`Failed to download item ${e}`),null;console.debug(`Failed attempts to download item ${e}: ${i}. Trying again...`);}}async addItemToCache(e,t,a,i){try{const n=this.getCacheKey(e,t),r=this.findObject(n);if(r&&(a||!this.apiClient.getItemHash||this.usePublicApi||(a=await this.apiClient.getItemHash(e)),a&&r.hash===a&&(this.logging&&console.log("Item already in cache: "+e),await this.loadFromStorage(r))))return r.url||(r.url=this._getLodLevelUrl(e,t)),this.urlToIdMap.set(r.url,n),this.cache.set(n,r),r;i&&i(0);let s=await this.loadItem(e,t,i);if(!s)return console.error("Was not able to load object into cache: "+n),null;i&&i(100);const o=this._getLodLevelUrl(e,t),l=URL.createObjectURL(s.blob),c={id:n,url:o,time:j(),objectUrl:l,size:s.blob.size,hash:s.hash,itemType:s.itemType,mimeType:s.mimeType,itemName:s.itemName};return this.checkQuota(c.size),await this.addToStorage(c,s.blob),this.cache.set(n,c),this.urlToIdMap.set(o,n),this.saveIndex(),u$3.$emit("itemCache:cacheChange"),this.logging&&console.log("Added item to cache: ",c),c}catch(e){return console.error(e),null}}getObjectCount(){return this.cache.size}getObjectSize(){let e=0;for(const t of this.cache.values())e+=t.size;return e}handleRename({id:e,newName:t}){const a=this.cache.get(e);a&&(a.itemName=t,this.saveIndex(),u$3.$emit("itemCache:cacheChange"));}}let Un$1 = class Un extends nn$1{apiClient;ready=false;maxNumItems=1e4;constructor(e){if(super("lumino","folders",1),!e)throw "A lumino client needs to be passed.";this.apiClient=e;}async init(){await super.init(),await this.checkStorage(),this.ready=true;}clear(){return this._clear()}async checkStorage(){const e=await this._keys();let t=e.length-this.maxNumItems;if(t>0){t=Math.floor(this.maxNumItems/2);const a=[];for(let i=0;i<t;i++)a.push(this._remove(e[i]));await Promise.all(a);}}async getFolderListing(e){return this.ready?this._get(e,"application/json"):null}async getItemListing(e){if(!this.ready)return null;const t=await this._get("items_"+e,"application/json");if(!t)return null;const a=await this.getFolderListing(e);return a&&a.parent&&new Date(t.cachedAt).getTime()>new Date(a.parent.updatedAt).getTime()?t.data:null}async getFolderACLs(e,t){if(!this.ready)return null;const a=await this._get("acl_"+e,"application/json");return a&&Date.now()-a.cachedAt<t?(delete a.cachedAt,a):null}async refreshCacheForFolder(e){const t=await this.getFolderListing(e);await this.addFolderListing(e,t);}async addFolderListing(e,t){this.ready&&(await this._set(e,{...t,cachedAt:new Date}),await this.checkStorage());}async addItemListing(e,t){this.ready&&(await this._set("items_"+e,{data:t,cachedAt:new Date}),await this.checkStorage());}async addACL(e,t){this.ready&&(await this._set("acl_"+e,{...t,cachedAt:new Date}),await this.checkStorage());}};class zn extends nn$1{apiClient;constructor(e){if(super("lumino","thumbs",1),!e)throw "A lumino client needs to be passed.";this.apiClient=e;}clear(){this._clear();}async _loadThumbnail(e,t){try{return await this.apiClient.getThumbnail(e,t)}catch{try{return await this.apiClient.getPublicThumbnail(e,t)}catch{return null}}}async get(e,t,a,i){if(!t)throw "Cannot retrieve item thumbnail from cache without knowing size!";let n=await this._get(e,"application/json");if(n&&n.hash===a&&n.timestamp===i){for(const e of n.thumbnails)if(e.size===t){if(e.data)return e.data;n.thumbnails.removeObject(e);break}let a=await this._loadThumbnail(t,e);return a&&(n.thumbnails.push({size:t,data:a}),await this._set(e,n)),a}let r=await this._loadThumbnail(t,e);if(a||i){let s=[];r&&s.push({size:t,data:r}),n={id:e,hash:a,timestamp:i,thumbnails:s},await this._set(e,n);}return r}}class Wn{apiClient;cache=new Map;constructor(e){this.apiClient=e,this.cache=new Map;}async resolve(e){let t=this.cache.get(e);if(!t)try{t=this.apiClient.getUserPublicInfo(e,this.apiClient.requestClientId,32),this.cache.set(e,t);}catch(e){console.error(e);}return t}}class Yn{apiClient;cache=new Map;constructor(e){this.apiClient=e;}async resolve(e){let t=this.cache.get(e);if(!t)try{t=this.apiClient.getGroupPublicInfo(e,this.apiClient.requestClientId,32),this.cache.set(e,t);}catch(e){console.error(e);}return t}}class Hn{apiClient;cache=new Map;constructor(e){this.apiClient=e;}async get(e,t,a,i,n=false){const r=`${e}_${t}_${a}${ void 0===i?"":`_${i}`}`,s=this.cache.get(r);if(s)return s;try{const s=new Promise((async r=>{try{let s;s=n?await this.apiClient.downloadPublicAttachment(e,t,a,i,void 0):await this.apiClient.downloadAttachmentPOP(e,t,a,i,void 0);r(URL.createObjectURL(s.blob));}catch(e){r(null);}}));return this.cache.set(r,s),s}catch(e){return console.warn(`Attachment ${r} not available.`),null}}invalidateAttachment(e,t,a,i){let n=`${e}_${t}`;null!=a&&(n+=`_${a}`);for(const e of this.cache.keys()){const t=null==i||e.endsWith(`_${i}`);e.startsWith(n)&&t&&this.cache.delete(e);}}}class Gn{apiClient;itemRepo;jobManager;items=[];hasExternalResources=false;totalSize=0;affectedFolderIds=new Set;constructor(e){this.apiClient=e,this.itemRepo=e.getItemRepo(),this.jobManager=e.getJobManager();}_updateQuota(){this.apiClient.eventBus.$emit("quota:update");}async getPreviousVersions(e,t){const a=[];t=t||"published";const i=await this.apiClient.createFolder({name:t,parent:e,returnIfExists:true}),n=await this.apiClient.getFoldersInFolderList(i,{folderAsItemType:"Package"});for(const e of n.children)e.item&&a.push({itemId:e.item._id,folderId:e._id,version:e.name,name:e.item.name,filesize:0|e.item.filesize,visibility:e.item.visibility});return a}async verify(e){const t=this,a=new Map,i=new Map;e=e?await this.itemRepo.loadItem(e._id,{recursive:true}):this.itemRepo.activeItem;const n=await r(e.folder);async function r(e){try{if(e){const a=e._id?e._id:e;if(i.has(a))return i.get(a);{const e=(await t.apiClient.getFolderPath(a)).path;return i.set(a,e),e}}return "/"}catch{return ""}}await this.itemRepo.traverseItems((async function(e){const t={_id:e._id,name:e.name,type:e.type,size:e.totalSize,path:await r(e.folder),item:e,external:false};t.path.startsWith(n)?t.path=t.path.slice(n.length):t.external=true,a.set(e._id,t);})),this.items=Array.from(a.values()),this.hasExternalResources=false,this.totalSize=0;for(const e of this.items)e.external&&(this.hasExternalResources=true),this.totalSize+=e.size;return !this.hasExternalResources}getItems(){return this.items}async unpackToProject(e,t,a,i){a&&(t=await this.apiClient.createFolder({name:a,parent:t,returnIfExists:true}));const n=await this.apiClient.getItem(e);n.folder===t&&await this.apiClient.renameItem(e,n.name+" (Unpackaged)");const r=await this.apiClient.createFolder({name:n.name,parent:t,fixNameCollisions:true}),s=await this.jobManager.execute("JS:Unpackage",[{_id:e,isFolder:false}],[{name:"Destination Folder",value:r},{name:"Make Destination Visible",value:false}],i);if(this._updateQuota(),3===s.state){const t=s.log.trim().split(";");if(2!==t.length||"UNPACKAGED"!==t[0])throw new N$1("Unpacking failed. Did not get unpackaged item id!");const a=t[1].trim();return await this.apiClient.renameItem(a,n.name),await this.itemRepo.replaceLink(e,a),a}if(2===s.state)throw new N$1("Unpacking failed: "+s.error)}async copyItemToProject(e,t,a,i){return (await this.copyItemsToProject([{_id:e,isFolder:false}],t,a,i))[0].newId}async copyItemsToProject(e,t,a,i){a=a||"packages",t=await this.apiClient.createFolder({name:a,parent:t,returnIfExists:true}),this.affectedFolderIds.add(t);const n=[];if(e.length){const a=await this.jobManager.execute("JS:CloneItem",e,[{name:"Deep Clone",value:false},{name:"Destination Folder",value:t},{name:"Exclude Types",value:""},{name:"Make Private",value:true}],i);if(this._updateQuota(),3===a.state){if(!a.log.trim().length)throw new N$1("Copy job returned no results.");{const e=a.log.split("\n").reverse();for(const t of e){const e=t.trim().split(";");if(3===e.length){const t=e[1],a=e[2];await this.itemRepo.replaceLink(t,a),n.push({oldId:t,newId:a});}}}}else if(2===a.state)throw new N$1("Copying of items failed: "+a.error)}return n}async copyToProject(e,t,a){const i=[];for(const e of this.items)e.external&&i.push({_id:e._id,isFolder:false});return this.copyItemsToProject(i,e,t,a)}async unpublish(e){await this.apiClient.makeItemPrivate(e,false,false);}async publish(e,t,a,i,n,r,s,o){const l=e.version;i=i||`published/${l.major}.${l.minor}.${l.revision}`,n=void 0===n||n,r=void 0===r||r,this.affectedFolderIds.add(a);let u,c=a;if(i){const e=i.split("/");for(const t of e)c=await this.apiClient.createFolder({name:t,parent:c,returnIfExists:true}),this.affectedFolderIds.add(c),u||(u=c);}const d=(await this.apiClient.getFoldersInFolderList(a)).children.map((e=>e._id)).filter((e=>e!==u)).join(","),p=await this.jobManager.execute("JS:CreatePackage",[{_id:e._id,isFolder:false}],[{name:"Folders To Include",value:d},{name:"Destination Folder",value:c},{name:"Item Name",value:t},{name:"Make Public",value:!!n},{name:"Copy External",value:!!r},{name:"Always Create New Package",value:!!s},{name:"Make Cloneable",value:!!o}]);if(this._updateQuota(),2===p.state)throw new N$1("Packaging failed: "+p.error);this.apiClient.eventBus.$emit("folder:changed",Array.from(this.affectedFolderIds.values()));}}class qn{id;job;nextCheckMs;constructor(e,t,a){this.id=e,this.job=a,this.nextCheckMs=t;}}class Zn{apiClient;jobs=new Map;constructor(e){this.apiClient=e;}getJobs(){return Array.from(this.jobs.values())}async execute(e,t,a,i=void 0,n){const r=this;return new Promise((async(s,o)=>{try{const o=async()=>{try{u.job=await r.apiClient.getJobState(l);let e=!1;switch(u.job.state){case 0:case 1:try{i&&i(u.job);}catch(e){console.error("Error calling progress callback: ",e);}break;case 2:case 3:console.log("Job is done."),e=!0,s(u.job);}e?r.jobs.delete(l):(u.nextCheckMs=Math.min(2*u.nextCheckMs,8e3),setTimeout(o,u.nextCheckMs));}catch(e){console.error("Error fetching job state: "+e);}},l=await r.apiClient.createJob({type:e,elements:t,parameters:a,requiredParameters:n}),u=new qn(l,1e3);r.jobs.set(l,u),setTimeout(o,u.nextCheckMs);}catch(e){o(e);}}))}}const Jn={mp3:{name:"Mpeg Audio Layer 3",itemType:"Audio",itemTypeCollection:"Audio Collection",collectionEntryName:"AudioItems",folderName:"audio",defaultAction:"Use",actions:["Skip","Use"]},hdr:{name:"HDR Image",itemType:"HDR Image",folderName:"envmaps",defaultAction:"Use",actions:["Skip","Use"]},glb:{name:"Gltf Binary",itemType:"Mesh",itemTypeCollection:"Mesh Collection",collectionEntryName:"MeshItems",folderName:"meshes",defaultAction:"Use",actions:["Skip","Use"]},png:{name:"Portable Network Graphics",itemType:"Image",folderName:"textures",defaultAction:"Use",actions:["Skip","Use"]},jpg:{name:"JPEG",itemType:"Image",folderName:"textures",defaultAction:"Use",actions:["Skip","Use"]},jpeg:{name:"JPEG",itemType:"Image",folderName:"textures",defaultAction:"Use",actions:["Skip","Use"]},lua:{name:"Lua",itemType:"Script",folderName:"scripts",defaultAction:"Use",actions:["Skip","Use"]},ttf:{name:"True Type Font",itemType:"Font",folderName:"fonts",defaultAction:"Use",actions:["Skip","Use"]},otf:{name:"Open Type Font",itemType:"Font",folderName:"fonts",defaultAction:"Use",actions:["Skip","Use"]},unknown:{name:"Unsupported",itemType:"Unknown",defaultAction:"Skip",actions:["Skip"],invisible:true}},Kn={Audio:"audio","Audio Collection":"audio","HDR Image":"envmaps",Mesh:"meshes","Mesh Collection":"",Script:"scripts",Material:"materials","Background Shader":"background shaders","Pixel Shader":"pixel shaders","Vertex Shader":"vertex shaders",Image:"textures",Scene:"prefabs",Font:"fonts"};function Xn(e,t){let a=Jn[t];a||(a=Jn.unknown),e.size=e.blob?e.blob.size:0,e.type=a.name,e.collectionType=a.itemTypeCollection,e.collectionEntryName=a.collectionEntryName,e.action=a.defaultAction,e.actions=a.actions,e.folderName=a.folderName,e.itemType=a.itemType,e.name=function(e,t){let a=e.lastIndexOf(".");return e.substring(0,a<0?e.length:a)+"."+t}(e.name,t);}class Qn{name;blob;processing=false;progress=0;size=0;type;collectionType;collectionEntryName;action;actions;folderName;itemType;constructor(e,t,a){this.name=e,this.blob=t,Xn(this,a);}}class er{apiClient;itemRepo;jobManager;items=[];mainItem;totalSize=0;oldMainItemId;originalItemIds=[];affectedFolderIds=new Set;packageId;converter;supportedExtensions;hasExternalResources=false;constructor(e){this.apiClient=e,this.itemRepo=e.getItemRepo(),this.jobManager=e.getJobManager();const t=[];for(const e in Jn)Jn[e].invisible||t.push(`.${e.toUpperCase()}`);this.supportedExtensions=t.sort(((e,t)=>e.localeCompare(t)));}_updateQuota(){this.apiClient.eventBus.$emit("quota:update");}_addAffectedFolder(e){"object"==typeof e&&e._id?this.affectedFolderIds.add(e._id):"string"==typeof e?this.affectedFolderIds.add(e):console.error("Invalid affected folder to add: ",e);}getAffectedFolderIds(){return Array.from(this.affectedFolderIds.values())}getSupportedExtensions(){return this.supportedExtensions}setConverter(e){this.converter=e;}setItems(e){this.items=e;}async scan(e){const t=this,a=new Map,i=new Map;this.mainItem=await this.itemRepo.loadItem(e,{recursive:true}),this.oldMainItemId=this.mainItem._id;const n=await r(this.mainItem.folder);async function r(e){try{if(e){const a=e._id?e._id:e;if(i.has(a))return i.get(a);{const e=(await t.apiClient.getFolderPath(a)).path;return i.set(a,e),e}}return "/"}catch(e){return console.error(e),""}}await this.itemRepo.traverseItems((async function(e){const i={_id:e._id,name:e.name,type:e.type,size:e.totalSize,path:await r(e.folder),item:e,external:false};i.path.startsWith(n)?i.path=i.path.slice(n.length):i.external=true,t._addAffectedFolder(e.folder),a.set(e._id,i);}),this.mainItem),this.items=Array.from(a.values()),this.originalItemIds=this.items.map((e=>e._id)),this.hasExternalResources=false,this.totalSize=0;for(const e of this.items)e.external&&(this.hasExternalResources=true),this.totalSize+=e.size;return this.items}getItems(){return this.items}async saveMainItemChanges(){const e=this.mainItem;await this.apiClient.updateItem({_id:e._id,name:e.name,shortDescription:e.shortDescription,description:e.description,tags:e.tags,categories:e.categories,visibility:e.visibility,contributors:e.contributors,version:e.version});}async createAssetFolder(e,t){let a=e;const i=t.split("/");this._addAffectedFolder(e);for(const e of i)a=await this.apiClient.createFolder({name:e,parent:a,returnIfExists:true}),this._addAffectedFolder(a);const n=await this.apiClient.getItemsInFolderList(a,true);if(n&&n.length)throw new Error("Asset folder already exists and is not empty!");return a}createStandardAssetFolderPath(e){let t=Kn[e.type];return t||(t=e.type.toLowerCase()+"s"),`assets/${t}/${e.name}`}async executeActions(){if(!this.converter)throw new Error("No converter is configured. Cannot execute actions on items.");return this.converter(this.items,Xn)}async createAsset(e,t=false,a){const i=[];for(const e of this.items)i.push(e._id);if(this._addAffectedFolder(e),i.length)if(t){await this.apiClient.moveItems({items:i,dest:e})!==i.length&&console.warn("Not all items could be moved. Most likely due to permissions."),this.mainItem.folder=e;}else {const t=await this.jobManager.execute("JS:CloneItem",[{_id:this.mainItem._id,isFolder:false}],[{name:"Deep Clone",value:true},{name:"Destination Folder",value:e},{name:"Exclude Types",value:""}],a);if(3===t.state){const a=t.log.split("\n").reverse()[0].split(";");this.mainItem={...this.mainItem,_id:a[2],folder:e};}else if(2===t.state)throw new N$1("Copying of items failed: "+t.error)}"Main"!==this.mainItem.name&&(this.mainItem.originalName=this.mainItem.name,this.mainItem.name="Main",await this.apiClient.renameItem(this.mainItem._id,this.mainItem.name));const n=await this.apiClient.getItem(this.mainItem._id);return n.flags||(n.flags=[]),n.flags.includes("original")||n.flags.push("original"),await this.apiClient.updateItem(n),this._updateQuota(),this.mainItem._id}async createPackage(e,t=false,a=false){let i,n=this.mainItem.folder;if(this._addAffectedFolder(n),void 0===e){const t=this.mainItem.version||{major:1,minor:0,revision:0};e=`published/${t.major}.${t.minor}.${t.revision}`;}if(void 0===t&&(t=true),e){const t=e.split("/");for(const e of t)n=await this.apiClient.createFolder({name:e,parent:n,returnIfExists:true}),this._addAffectedFolder(n),i||(i=n);}const r=(await this.apiClient.getFoldersInFolderList(this.mainItem.folder)).children.map((e=>e._id)).filter((e=>e!==i)).join(","),s=await this.jobManager.execute("JS:CreatePackage",[{_id:this.mainItem._id,isFolder:false}],[{name:"Folders To Include",value:r},{name:"Destination Folder",value:n},{name:"Item Name",value:this.mainItem.originalName||this.mainItem.name},{name:"Make Public",value:!!t},{name:"Copy External",value:!!a}]);if(this._updateQuota(),2===s.state)throw new N$1("Packaging failed: "+s.error);const o=s.log.split("\n").reverse()[0].split(";");this.packageId=o[2];}async replaceReferences(){await this.itemRepo.replaceLink(this.oldMainItemId,this.packageId);}async deleteOriginalItems(){await this.apiClient.deleteItem(this.originalItemIds);}sendFolderRefreshEvent(){this.apiClient.eventBus.$emit("folder:changed",this.getAffectedFolderIds());}async processUploads(e){const t=[];for(const a of e)if("application/zip"===a.type||"application/x-zip-compressed"===a.type){const e=new s$2;try{const i=[];(await e.loadAsync(a)).forEach(((e,a)=>{const n=a.name.split("/").pop();if(!n.startsWith(".")){const e=n.split(".").pop(),r=a.async("blob");i.push(r),r.then((function(i){const n=new Qn(a.name,i,e);t.push(n);}));}})),await Promise.all(i);}catch(e){console.error("Error reading the ZIP file:",e);}}else {const e=a.name.split(".").pop(),i=new Qn(a.name,a,e);t.push(i);}return t}detectAssets(e){let t,a,i,n=0;for(const r of e)if("Use"===r.action)if(void 0===t)t=r.itemType,a=r.collectionType,i=r.folderName,n++;else {if(t!==r.itemType)return {valid:false,reason:"Mixed item types found. To create an asset, upload a single type of file for example only meshes."};n++;}return 0===n?{valid:false,reason:"There are no files we can use to create an asset."}:n>1&&!a?{valid:false,reason:"Cannot create collections of this type."}:{valid:true,assetType:n>1?a:t,itemCount:n,folderName:i}}_filterUploadFiles(e){let t=[];for(const a of e)"Use"===a.action&&t.push(a);return t}createNewItem(){return {name:"New asset",type:"",description:"",shortDescription:"",tags:[],flags:["original"],categories:[],license:"CC0",allowConversation:true,version:{major:1,minor:0,revision:0}}}async createAssetFromFiles(e,t,a,i=false,n=false){const r=this.detectAssets(e);if(r.assetType!==a.type)throw new Error("Asset type not valid for these items.");if(!r.valid)throw new Error(r.reason||"No valid asset detected.");let s=await this.apiClient.createFolder({name:r.folderName,parent:t,returnIfExists:true}),o=await this.apiClient.createFolder({name:a.name,parent:s,returnIfExists:true}),l=false;if(0===(await this.apiClient.getItemsInFolderList(o)).length){(await this.apiClient.getFoldersInFolderList(o)).children.length&&(l=true);}else l=true;if(l){if(!i)throw new Error("Cannot create asset, target folder is not empty!");await this.apiClient.deleteFolder(o),o=await this.apiClient.createFolder({name:a.name,parent:s});}let u,c=this._filterUploadFiles(e);if(1===c.length){const e=c[0];e.processing=true,e.progress=0,u=await this.apiClient.uploadAndCreate(o,e.blob,e.name,{nameOverride:"Main",flags:"original"},(function(t){e.progress=t;})),this._updateQuota(),e.action="Skip";}else {let e=await this.apiClient.createFolder({name:"resources",parent:o}),t={},a=[],i=0;for(const n of c){n.processing=true,n.progress=0;const r=await this.apiClient.uploadAndCreate(e,n.blob,n.name,void 0,(function(e){n.progress=e;}));this._updateQuota(),n.action="Skip",t[`${n.collectionEntryName}[${i}]->Name`]="",a.push({usage:`MeshItems[${i}]->Mesh`,to:r}),i++;}u=await this.apiClient.createItem({type:r.assetType,name:"Main",flags:["original"],folder:o,fixNameCollisions:true,attributes:t,links:a});}return a._id=u,a.folder=o,this.mainItem=a,n?{assetItemId:u,assetTypeFolderId:s,assetFolderId:o}:u}}class tr{apiClient;itemRepo;constructor(e){this.apiClient=e,this.itemRepo=e.getItemRepo();}grab(e,t,a,i){i=i||{};const n=[];for(const r of a){const a=this._serializeBlockFields(r),s=this._serializeScripts(r),o={type:"block",item:e._id,field:t.name,path:"",block:{id:r.id,type:r.type||"Group",fields:a,scripts:s,children:[]}};i.omitPath||(o.path=this._getBlockPath(r)),i.withChildren&&(o.block.children=this.grab(e,t,r.blocks||[],{withChildren:true,returnArray:true})),n.push(o);}if(i.returnArray)return n;const r={type:"serializedBlocks",data:n};return i.noStringify?r:JSON.stringify(r,null,2)}async put(e,t,a,i={}){e=this.validateMessage(e);const n=[];for(const r of e.data){const e=await this._putBlock(r,t,a,i);e&&n.push(e);}return n}validateMessage(e){if("string"==typeof e&&(e=JSON.parse(e)),"serializedBlocks"!==e.type)throw new Error("Data must be a serialized block message. Format is wrong.");if(!Array.isArray(e.data))throw new Error("The contained data is not an array.");return e}async clone(e,t,a,i,n={}){const r=this.grab(i,t,[e],{withChildren:true,noStringify:true});return this.put(r,t,a,n)}_updateScriptFieldReferences(e,t){const a=new Map,i=(e,t)=>{a.set(e.block.id,t.id);const n=e.block.children||[],r=t.blocks||[];for(let e=0;e<n.length;e++)i(n[e],r[e]);};i(e,t),this.itemRepo.updateScriptFieldReferencesFromMap(a,t);}async _putBlock(e,t,a,i={},n=false){if(!e.block||!e.block.type||!e.block.fields)return null;const r=e.block,s=this._findItemById(e.item)??this.itemRepo.activeItem;let o=a;o||(o=this._findParentBlock(s,e.field,e.path));const l={};if(Array.isArray(r.fields))for(const e of r.fields){const{name:t,type:a,value:n,linkto:r}=e;if("Separator"!==a)if(i.fieldOverrides&&t in i.fieldOverrides)l[t]=i.fieldOverrides[t];else if(r){const e=this.itemRepo.getLoadedItem(r);l[t]=e||await this.itemRepo.loadItem(r);}else l[t]=n;}const u=i.dontCopyScripts?[]:[...r.scripts],c=await this._createUnproxifiedBlock(r.type,l,u,t,s),d={...i,parentPosition:void 0,fieldOverrides:void 0};if(!c)return console.warn(`Could not create block of type ${r.type}. Skipping.`),null;if(Array.isArray(r.children))for(const e of r.children)await this._putBlock(e,t,c,d,true);if(n&&o)return "number"==typeof i.parentPosition?o.blocks.splice(i.parentPosition,0,c):o.blocks.push(c),c.parent=o,c;i.dontCopyScripts||this._updateScriptFieldReferences(e,c);return this._proxifyAndAttachTree(c,o,s,i.parentPosition)}async _createUnproxifiedBlock(e,t,a,i,n){let r=se.instance.getTemplate(n.packageType||n.type,i.name,e);if(!r)return null;if(t){const e=r.template.clone().specialize(t);r={displayName:r.displayName,typeName:r.typeName,template:e,inputs:r.inputs,outputs:r.outputs};}const s=new le(void 0,void 0,r.typeName,void 0,r.displayName,n),o=await this.itemRepo.createFieldsForItem(s,r.template,n,true);return s.setFields(o),s.blocks=[],await this.itemRepo.createScriptsForItem(s,a,n,false),s}_proxifyAndAttachTree(e,t,a,i){const n=e=>{if(Array.isArray(e.blocks)&&e.blocks.length)for(const t of e.blocks)n(t);const t=e.blocks.map((e=>g$1.instance.proxyBlock(e,a)));e.blocks=g$1.instance.proxyBlockArray(t,e,a),e.scripts=g$1.instance.proxyScriptArray(e.scripts,e,a);};n(e),e.parent=t;const r=g$1.instance.proxyBlock(e,a);return "number"==typeof i?t.blocks.splice(i,0,r):t.blocks.push(r),r}_findItemById(e){return this.itemRepo.findLoadedItem(e)}_findItemField(e,t){if(!e.fieldInstances)return null;for(const a of e.fieldInstances)if(a.name===t)return a;return null}_findParentBlock(e,t,a){const i=this._findItemField(e,t);if(!i)return null;const n=a.split("/");let r=i.blocks,s=null;for(const e of n)s=r[e],r=s.blocks;return s}_getBlockIndex(e){if(!e.parent)return 0;let t=0;for(const a of e.parent.blocks){if(e.id===a.id)return t;t++;}throw new Error("Could not find block in parent block array!")}_getBlockPath(e){const t=[];let a=e;for(;a;)t.push(this._getBlockIndex(a)),a=a.parent;return "/"+t.reverse().join("/")}_serializeBlockFields(e){const t=[];if(!Array.isArray(e.fields))return t;for(const a of e.fields)switch(a.type){case "Link":t.push({name:a.name,linkto:a.value?._id});break;case "Attribute":t.push({name:a.name,value:a.value});break;case "Separator":t.push({name:a.name,type:"Separator"});}return t}_serializeScripts(e){const t=[];if(!Array.isArray(e.scripts))return t;for(const a of e.scripts){const e=[],i={item:a.item?.value?._id,fields:e};for(const t of a.fields)e.push({name:t.name,value:t.value});t.push(i);}return t}}Array.prototype.pushAll||(Array.prototype.pushAll=function(e){for(const t of e)this.push(t);}),Array.prototype.removeObject||(Array.prototype.removeObject=function(e){const t=this.indexOf(e);return t>-1&&(this.splice(t,1),true)}),Array.prototype.moveObjectToArray||(Array.prototype.moveObjectToArray=function(e,t,a){const i=this.indexOf(e);if(i>-1){return (0, this.moveToArray)(i,t,a)}return false}),Array.prototype.removeByFilterFunc||(Array.prototype.removeByFilterFunc=function(e){let t=0;for(let a=0;a<this.length;a++)e(this[a])&&(this.splice(a,1),a--,t++);return t}),Array.prototype.clone||(Array.prototype.clone=function(){const e=[];for(const t of this)e.push(t);return e});const ar=()=>new Map,ir=e=>{const t=ar();return e.forEach(((e,a)=>{t.set(a,e);})),t},nr=(e,t,a)=>{let i=e.get(t);return void 0===i&&e.set(t,i=a()),i},rr=()=>new Set,sr=e=>e[e.length-1],or=(e,t)=>{for(let a=0;a<t.length;a++)e.push(t[a]);},lr=Array.from,ur=Array.isArray;class cr{constructor(){this._observers=ar();}on(e,t){return nr(this._observers,e,rr).add(t),t}once(e,t){const a=(...i)=>{this.off(e,a),t(...i);};this.on(e,a);}off(e,t){const a=this._observers.get(e);void 0!==a&&(a.delete(t),0===a.size&&this._observers.delete(e));}emit(e,t){return lr((this._observers.get(e)||ar()).values()).forEach((e=>e(...t)))}destroy(){this._observers=ar();}}class dr{constructor(){this._observers=ar();}on(e,t){nr(this._observers,e,rr).add(t);}once(e,t){const a=(...i)=>{this.off(e,a),t(...i);};this.on(e,a);}off(e,t){const a=this._observers.get(e);void 0!==a&&(a.delete(t),0===a.size&&this._observers.delete(e));}emit(e,t){return lr((this._observers.get(e)||ar()).values()).forEach((e=>e(...t)))}destroy(){this._observers=ar();}}const pr=Math.floor,hr=Math.abs,fr=(e,t)=>e<t?e:t,mr=(e,t)=>e>t?e:t,yr=Math.pow,gr=e=>0!==e?e<0:1/e<0,br=64,vr=128,_r=127,wr=Number.MAX_SAFE_INTEGER,Ar=Number.isInteger||(e=>"number"==typeof e&&isFinite(e)&&pr(e)===e),kr=String.fromCharCode,Sr=/^\s*/g,Nr=/([A-Z])/g,Tr=(e,t)=>(e=>e.replace(Sr,""))(e.replace(Nr,(e=>`${t}${(e=>e.toLowerCase())(e)}`))),Mr="undefined"!=typeof TextEncoder?new TextEncoder:null,xr=Mr?e=>Mr.encode(e):e=>{const t=unescape(encodeURIComponent(e)),a=t.length,i=new Uint8Array(a);for(let e=0;e<a;e++)i[e]=t.codePointAt(e);return i};let Vr="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8",{fatal:true,ignoreBOM:true});Vr&&1===Vr.decode(new Uint8Array).length&&(Vr=null);class Cr{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[];}}const Ir=()=>new Cr,Fr=e=>{let t=e.cpos;for(let a=0;a<e.bufs.length;a++)t+=e.bufs[a].length;return t},Er=e=>{const t=new Uint8Array(Fr(e));let a=0;for(let i=0;i<e.bufs.length;i++){const n=e.bufs[i];t.set(n,a),a+=n.length;}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),a),t},Dr=(e,t)=>{const a=e.cbuf.length;e.cpos===a&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(2*a),e.cpos=0),e.cbuf[e.cpos++]=t;},Lr=Dr,Rr=(e,t)=>{for(;t>_r;)Dr(e,vr|_r&t),t=pr(t/128);Dr(e,_r&t);},Pr=(e,t)=>{const a=gr(t);for(a&&(t=-t),Dr(e,(t>63?vr:0)|(a?br:0)|63&t),t=pr(t/64);t>0;)Dr(e,(t>_r?vr:0)|_r&t),t=pr(t/128);},Or=new Uint8Array(3e4),Br=Or.length/3,$r=Mr&&Mr.encodeInto?(e,t)=>{if(t.length<Br){const a=Mr.encodeInto(t,Or).written||0;Rr(e,a);for(let t=0;t<a;t++)Dr(e,Or[t]);}else Ur(e,xr(t));}:(e,t)=>{const a=unescape(encodeURIComponent(t)),i=a.length;Rr(e,i);for(let t=0;t<i;t++)Dr(e,a.codePointAt(t));},jr=(e,t)=>{const a=e.cbuf.length,i=e.cpos,n=fr(a-i,t.length),r=t.length-n;e.cbuf.set(t.subarray(0,n),i),e.cpos+=n,r>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(mr(2*a,r)),e.cbuf.set(t.subarray(n)),e.cpos=r);},Ur=(e,t)=>{Rr(e,t.byteLength),jr(e,t);},zr=(e,t)=>{((e,t)=>{const a=e.cbuf.length;a-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(2*mr(a,t)),e.cpos=0);})(e,t);const a=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,a},Wr=new DataView(new ArrayBuffer(4)),Yr=(e,t)=>{switch(typeof t){case "string":Dr(e,119),$r(e,t);break;case "number":Ar(t)&&hr(t)<=2147483647?(Dr(e,125),Pr(e,t)):(a=t,Wr.setFloat32(0,a),Wr.getFloat32(0)===a?(Dr(e,124),((e,t)=>{zr(e,4).setFloat32(0,t,false);})(e,t)):(Dr(e,123),((e,t)=>{zr(e,8).setFloat64(0,t,false);})(e,t)));break;case "bigint":Dr(e,122),((e,t)=>{zr(e,8).setBigInt64(0,t,false);})(e,t);break;case "object":if(null===t)Dr(e,126);else if(ur(t)){Dr(e,117),Rr(e,t.length);for(let a=0;a<t.length;a++)Yr(e,t[a]);}else if(t instanceof Uint8Array)Dr(e,116),Ur(e,t);else {Dr(e,118);const a=Object.keys(t);Rr(e,a.length);for(let i=0;i<a.length;i++){const n=a[i];$r(e,n),Yr(e,t[n]);}}break;case "boolean":Dr(e,t?120:121);break;default:Dr(e,127);}var a;};class Hr extends Cr{constructor(e){super(),this.w=e,this.s=null,this.count=0;}write(e){this.s===e?this.count++:(this.count>0&&Rr(this,this.count-1),this.count=1,this.w(this,e),this.s=e);}}const Gr=e=>{e.count>0&&(Pr(e.encoder,1===e.count?e.s:-e.s),e.count>1&&Rr(e.encoder,e.count-2));};class qr{constructor(){this.encoder=new Cr,this.s=0,this.count=0;}write(e){this.s===e?this.count++:(Gr(this),this.count=1,this.s=e);}toUint8Array(){return Gr(this),Er(this.encoder)}}const Zr=e=>{if(e.count>0){const t=2*e.diff+(1===e.count?0:1);Pr(e.encoder,t),e.count>1&&Rr(e.encoder,e.count-2);}};class Jr{constructor(){this.encoder=new Cr,this.s=0,this.count=0,this.diff=0;}write(e){this.diff===e-this.s?(this.s=e,this.count++):(Zr(this),this.count=1,this.diff=e-this.s,this.s=e);}toUint8Array(){return Zr(this),Er(this.encoder)}}class Kr{constructor(){this.sarr=[],this.s="",this.lensE=new qr;}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=""),this.lensE.write(e.length);}toUint8Array(){const e=new Cr;return this.sarr.push(this.s),this.s="",$r(e,this.sarr.join("")),jr(e,this.lensE.toUint8Array()),Er(e)}}const Xr=e=>new Error(e),Qr=()=>{throw Xr("Method unimplemented")},es=()=>{throw Xr("Unexpected case")},ts=Xr("Unexpected end of array"),as=Xr("Integer out of Range");class is{constructor(e){this.arr=e,this.pos=0;}}const ns=e=>new is(e),rs=e=>((e,t)=>{const a=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,a})(e,os(e)),ss=e=>e.arr[e.pos++],os=e=>{let t=0,a=1;const i=e.arr.length;for(;e.pos<i;){const i=e.arr[e.pos++];if(t+=(i&_r)*a,a*=128,i<vr)return t;if(t>wr)throw as}throw ts},ls=e=>{let t=e.arr[e.pos++],a=63&t,i=64;const n=(t&br)>0?-1:1;if(!(t&vr))return n*a;const r=e.arr.length;for(;e.pos<r;){if(t=e.arr[e.pos++],a+=(t&_r)*i,i*=128,t<vr)return n*a;if(a>wr)throw as}throw ts},us=Vr?e=>Vr.decode(rs(e)):e=>{let t=os(e);if(0===t)return "";{let a=String.fromCodePoint(ss(e));if(--t<100)for(;t--;)a+=String.fromCodePoint(ss(e));else for(;t>0;){const i=t<1e4?t:1e4,n=e.arr.subarray(e.pos,e.pos+i);e.pos+=i,a+=String.fromCodePoint.apply(null,n),t-=i;}return decodeURIComponent(escape(a))}},cs=(e,t)=>{const a=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,a},ds=[e=>{},e=>null,ls,e=>cs(e,4).getFloat32(0,false),e=>cs(e,8).getFloat64(0,false),e=>cs(e,8).getBigInt64(0,false),e=>false,e=>true,us,e=>{const t=os(e),a={};for(let i=0;i<t;i++){a[us(e)]=ps(e);}return a},e=>{const t=os(e),a=[];for(let i=0;i<t;i++)a.push(ps(e));return a},rs],ps=e=>ds[127-ss(e)](e);class hs extends is{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0;}read(){var e;return 0===this.count&&(this.s=this.reader(this),(e=this).pos!==e.arr.length?this.count=os(this)+1:this.count=-1),this.count--,this.s}}class fs extends is{constructor(e){super(e),this.s=0,this.count=0;}read(){if(0===this.count){this.s=ls(this);const e=gr(this.s);this.count=1,e&&(this.s=-this.s,this.count=os(this)+2);}return this.count--,this.s}}class ms extends is{constructor(e){super(e),this.s=0,this.count=0,this.diff=0;}read(){if(0===this.count){const e=ls(this),t=1&e;this.diff=pr(e/2),this.count=1,t&&(this.count=os(this)+2);}return this.s+=this.diff,this.count--,this.s}}class ys{constructor(e){this.decoder=new fs(e),this.str=us(this.decoder),this.spos=0;}read(){const e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}}const gs=crypto.getRandomValues.bind(crypto),bs=()=>gs(new Uint32Array(1))[0],vs=[1e7]+-1e3+-4e3+-8e3+-1e11,_s=()=>vs.replace(/[018]/g,(e=>(e^bs()&15>>e/4).toString(16))),ws=Date.now,As=e=>new Promise(e);Promise.all.bind(Promise);const ks=e=>void 0===e?null:e;let Ss=new class{constructor(){this.map=new Map;}setItem(e,t){this.map.set(e,t);}getItem(e){return this.map.get(e)}},Ns=true;try{"undefined"!=typeof localStorage&&localStorage&&(Ss=localStorage,Ns=!1);}catch(e){}const Ts=Ss,Ms=Object.assign,xs=Object.keys,Vs=e=>xs(e).length,Cs=e=>xs(e).length,Is=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),Fs=Object.freeze,Es=e=>{for(const t in e){const a=e[t];"object"!=typeof a&&"function"!=typeof a||Es(e[t]);}return Fs(e)},Ds=Symbol("Equality"),Ls=(e,t,a=0)=>{try{for(;a<e.length;a++)e[a](...t);}finally{a<e.length&&Ls(e,t,a+1);}},Rs=e=>e,Ps=(e,t)=>{if(e===t)return true;if(null==e||null==t||e.constructor!==t.constructor)return false;if(null!=e[Ds])return e[Ds](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return false;for(let a=0;a<e.length;a++)if(e[a]!==t[a])return false;break;case Set:if(e.size!==t.size)return false;for(const a of e)if(!t.has(a))return false;break;case Map:if(e.size!==t.size)return false;for(const a of e.keys())if(!t.has(a)||!Ps(e.get(a),t.get(a)))return false;break;case Object:if(Vs(e)!==Vs(t))return false;for(const a in e)if(!Is(e,a)||!Ps(e[a],t[a]))return false;break;case Array:if(e.length!==t.length)return false;for(let a=0;a<e.length;a++)if(!Ps(e[a],t[a]))return false;break;default:return false}return true},Os="undefined"!=typeof process&&process.release&&/node|io\.js/.test(process.release.name)&&"[object process]"===Object.prototype.toString.call("undefined"!=typeof process?process:0),Bs="undefined"!=typeof window&&"undefined"!=typeof document&&!Os;let $s;const js=e=>(()=>{if(void 0===$s)if(Os){$s=ar();const e=process.argv;let t=null;for(let a=0;a<e.length;a++){const i=e[a];"-"===i[0]?(null!==t&&$s.set(t,""),t=i):null!==t&&($s.set(t,i),t=null);}null!==t&&$s.set(t,"");}else "object"==typeof location?($s=ar(),(location.search||"?").slice(1).split("&").forEach((e=>{if(0!==e.length){const[t,a]=e.split("=");$s.set(`--${Tr(t,"-")}`,a),$s.set(`-${Tr(t,"-")}`,a);}}))):$s=ar();return $s})().has(e),Us=e=>ks(Os?process.env[e.toUpperCase().replaceAll("-","_")]:Ts.getItem(e)),zs=e=>js("--"+e)||null!==Us(e);zs("production");var Ws;const Ys=Os&&(Ws=process.env.FORCE_COLOR,["true","1","2"].includes(Ws))||!js("--no-colors")&&!zs("no-color")&&(!Os||process.stdout.isTTY)&&(!Os||js("--color")||null!==Us("COLORTERM")||(Us("TERM")||"").includes("color")),Hs=e=>new Uint8Array(e),Gs=Bs?e=>{let t="";for(let a=0;a<e.byteLength;a++)t+=kr(e[a]);return btoa(t)}:e=>Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64"),qs=Bs?e=>{const t=atob(e),a=Hs(t.length);for(let e=0;e<t.length;e++)a[e]=t.charCodeAt(e);return a}:e=>{const t=Buffer.from(e,"base64");return ((e,t,a)=>new Uint8Array(e,t,a))(t.buffer,t.byteOffset,t.byteLength)};class Zs{constructor(e,t){this.left=e,this.right=t;}}const Js=(e,t)=>new Zs(e,t);"undefined"!=typeof DOMParser&&new DOMParser;const Ks=Symbol,Xs=Ks(),Qs=Ks(),eo=Ks(),to$2=Ks(),ao=Ks(),io=Ks(),no=Ks(),ro=Ks(),so=Ks(),oo={[Xs]:Js("font-weight","bold"),[Qs]:Js("font-weight","normal"),[eo]:Js("color","blue"),[ao]:Js("color","green"),[to$2]:Js("color","grey"),[io]:Js("color","red"),[no]:Js("color","purple"),[ro]:Js("color","orange"),[so]:Js("color","black")},lo=Ys?e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],a=[],i=ar();let n=[],r=0;for(;r<e.length;r++){const n=e[r],s=oo[n];if(void 0!==s)i.set(s.left,s.right);else {if(void 0===n)break;if(n.constructor!==String&&n.constructor!==Number)break;{const e=((e,t)=>{const a=[];for(const[i,n]of e)a.push(t(n,i));return a})(i,((e,t)=>`${t}:${e};`)).join("");r>0||e.length>0?(t.push("%c"+n),a.push(e)):t.push(n);}}}for(r>0&&(n=a,n.unshift(t.join("")));r<e.length;r++){const t=e[r];t instanceof Symbol||n.push(t);}return n}:e=>{1===e.length&&e[0]?.constructor===Function&&(e=e[0]());const t=[],a=[];let i=0;for(;i<e.length;i++){const a=e[i];if(void 0===a)break;if(a.constructor===String||a.constructor===Number)t.push(a);else if(a.constructor===Object)break}for(i>0&&a.push(t.join(""));i<e.length;i++){const t=e[i];t instanceof Symbol||a.push(t);}return a},uo=rr(),co=e=>({[Symbol.iterator](){return this},next:e}),po=(e,t)=>co((()=>{const{done:a,value:i}=e.next();return {done:a,value:a?void 0:t(i)}}));class ho{constructor(e,t){this.clock=e,this.len=t;}}class fo{constructor(){this.clients=new Map;}}const mo=(e,t,a)=>t.clients.forEach(((t,i)=>{const n=e.doc.store.clients.get(i);if(null!=n){const i=n[n.length-1],r=i.id.clock+i.length;for(let i=0,s=t[i];i<t.length&&s.clock<r;s=t[++i])rl(e,n,s.clock,s.len,a);}})),yo=(e,t)=>{const a=e.clients.get(t.client);return void 0!==a&&null!==((e,t)=>{let a=0,i=e.length-1;for(;a<=i;){const n=pr((a+i)/2),r=e[n],s=r.clock;if(s<=t){if(t<s+r.len)return n;a=n+1;}else i=n-1;}return null})(a,t.clock)},go=e=>{e.clients.forEach((e=>{let t,a;for(e.sort(((e,t)=>e.clock-t.clock)),t=1,a=1;t<e.length;t++){const i=e[a-1],n=e[t];i.clock+i.len>=n.clock?i.len=mr(i.len,n.clock+n.len-i.clock):(a<t&&(e[a]=n),a++);}e.length=a;}));},bo=(e,t,a,i)=>{nr(e.clients,t,(()=>[])).push(new ho(a,i));},vo=e=>{const t=new fo;return e.clients.forEach(((e,a)=>{const i=[];for(let t=0;t<e.length;t++){const a=e[t];if(a.deleted){const n=a.id.clock;let r=a.length;if(t+1<e.length)for(let a=e[t+1];t+1<e.length&&a.deleted;a=e[1+ ++t])r+=a.length;i.push(new ho(n,r));}}i.length>0&&t.clients.set(a,i);})),t},_o=(e,t)=>{Rr(e.restEncoder,t.clients.size),lr(t.clients.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,a])=>{e.resetDsCurVal(),Rr(e.restEncoder,t);const i=a.length;Rr(e.restEncoder,i);for(let t=0;t<i;t++){const i=a[t];e.writeDsClock(i.clock),e.writeDsLen(i.len);}}));},wo=e=>{const t=new fo,a=os(e.restDecoder);for(let i=0;i<a;i++){e.resetDsCurVal();const a=os(e.restDecoder),i=os(e.restDecoder);if(i>0){const n=nr(t.clients,a,(()=>[]));for(let t=0;t<i;t++)n.push(new ho(e.readDsClock(),e.readDsLen()));}}return t},Ao=(e,t,a)=>{const i=new fo,n=os(e.restDecoder);for(let r=0;r<n;r++){e.resetDsCurVal();const n=os(e.restDecoder),r=os(e.restDecoder),s=a.clients.get(n)||[],o=Xo(a,n);for(let a=0;a<r;a++){const a=e.readDsClock(),r=a+e.readDsLen();if(a<o){o<r&&bo(i,n,o,r-o);let e=el(s,a),l=s[e];for(!l.deleted&&l.id.clock<a&&(s.splice(e+1,0,Uu(t,l,a-l.id.clock)),e++);e<s.length&&(l=s[e++],l.id.clock<r);)l.deleted||(r<l.id.clock+l.length&&s.splice(e,0,Uu(t,l,r-l.id.clock)),l.delete(t));}else bo(i,n,a,r-a);}}if(i.clients.size>0){const e=new Fo;return Rr(e.restEncoder,0),_o(e,i),e.toUint8Array()}return null},ko=bs;class So extends cr{constructor({guid:e=_s(),collectionid:t=null,gc:a=true,gcFilter:i=()=>true,meta:n=null,autoLoad:r=false,shouldLoad:s=true}={}){super(),this.gc=a,this.gcFilter=i,this.clientID=ko(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new Jo,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=s,this.autoLoad=r,this.meta=n,this.isLoaded=false,this.isSynced=false,this.isDestroyed=false,this.whenLoaded=As((e=>{this.on("load",(()=>{this.isLoaded=true,e(this);}));}));const o=()=>As((e=>{const t=a=>{ void 0!==a&&true!==a||(this.off("sync",t),e());};this.on("sync",t);}));this.on("sync",(e=>{ false===e&&this.isSynced&&(this.whenSynced=o()),this.isSynced=void 0===e||true===e,this.isSynced&&!this.isLoaded&&this.emit("load",[this]);})),this.whenSynced=o();}load(){const e=this._item;null===e||this.shouldLoad||dl(e.parent.doc,(e=>{e.subdocsLoaded.add(this);}),null,true),this.shouldLoad=true;}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(lr(this.subdocs).map((e=>e.guid)))}transact(e,t=null){return dl(this,e,t)}get(e,t=Fl){const a=nr(this.share,e,(()=>{const e=new t;return e._integrate(this,null),e})),i=a.constructor;if(t!==Fl&&i!==t){if(i===Fl){const i=new t;i._map=a._map,a._map.forEach((e=>{for(;null!==e;e=e.left)e.parent=i;})),i._start=a._start;for(let e=i._start;null!==e;e=e.right)e.parent=i;return i._length=a._length,this.share.set(e,i),i._integrate(this,null),i}throw new Error(`Type with the name ${e} has already been defined with a different constructor`)}return a}getArray(e=""){return this.get(e,Jl)}getText(e=""){return this.get(e,fu)}getMap(e=""){return this.get(e,Xl)}getXmlElement(e=""){return this.get(e,gu)}getXmlFragment(e=""){return this.get(e,yu)}toJSON(){const e={};return this.share.forEach(((t,a)=>{e[a]=t.toJSON();})),e}destroy(){this.isDestroyed=true,lr(this.subdocs).forEach((e=>e.destroy()));const e=this._item;if(null!==e){this._item=null;const t=e.content;t.doc=new So({guid:this.guid,...t.opts,shouldLoad:false}),t.doc._item=e,dl(e.parent.doc,(a=>{const i=t.doc;e.deleted||a.subdocsAdded.add(i),a.subdocsRemoved.add(this);}),null,true);}this.emit("destroyed",[true]),this.emit("destroy",[this]),super.destroy();}}class No{constructor(e){this.restDecoder=e;}resetDsCurVal(){}readDsClock(){return os(this.restDecoder)}readDsLen(){return os(this.restDecoder)}}class To extends No{readLeftID(){return Go(os(this.restDecoder),os(this.restDecoder))}readRightID(){return Go(os(this.restDecoder),os(this.restDecoder))}readClient(){return os(this.restDecoder)}readInfo(){return ss(this.restDecoder)}readString(){return us(this.restDecoder)}readParentInfo(){return 1===os(this.restDecoder)}readTypeRef(){return os(this.restDecoder)}readLen(){return os(this.restDecoder)}readAny(){return ps(this.restDecoder)}readBuf(){return (e=>{const t=Hs(e.byteLength);return t.set(e),t})(rs(this.restDecoder))}readJSON(){return JSON.parse(us(this.restDecoder))}readKey(){return us(this.restDecoder)}}class Mo{constructor(e){this.dsCurrVal=0,this.restDecoder=e;}resetDsCurVal(){this.dsCurrVal=0;}readDsClock(){return this.dsCurrVal+=os(this.restDecoder),this.dsCurrVal}readDsLen(){const e=os(this.restDecoder)+1;return this.dsCurrVal+=e,e}}class xo extends Mo{constructor(e){super(e),this.keys=[],os(e),this.keyClockDecoder=new ms(rs(e)),this.clientDecoder=new fs(rs(e)),this.leftClockDecoder=new ms(rs(e)),this.rightClockDecoder=new ms(rs(e)),this.infoDecoder=new hs(rs(e),ss),this.stringDecoder=new ys(rs(e)),this.parentInfoDecoder=new hs(rs(e),ss),this.typeRefDecoder=new fs(rs(e)),this.lenDecoder=new fs(rs(e));}readLeftID(){return new Yo(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Yo(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return 1===this.parentInfoDecoder.read()}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return ps(this.restDecoder)}readBuf(){return rs(this.restDecoder)}readJSON(){return ps(this.restDecoder)}readKey(){const e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{const e=this.stringDecoder.read();return this.keys.push(e),e}}}class Vo{constructor(){this.restEncoder=Ir();}toUint8Array(){return Er(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){Rr(this.restEncoder,e);}writeDsLen(e){Rr(this.restEncoder,e);}}class Co extends Vo{writeLeftID(e){Rr(this.restEncoder,e.client),Rr(this.restEncoder,e.clock);}writeRightID(e){Rr(this.restEncoder,e.client),Rr(this.restEncoder,e.clock);}writeClient(e){Rr(this.restEncoder,e);}writeInfo(e){Lr(this.restEncoder,e);}writeString(e){$r(this.restEncoder,e);}writeParentInfo(e){Rr(this.restEncoder,e?1:0);}writeTypeRef(e){Rr(this.restEncoder,e);}writeLen(e){Rr(this.restEncoder,e);}writeAny(e){Yr(this.restEncoder,e);}writeBuf(e){Ur(this.restEncoder,e);}writeJSON(e){$r(this.restEncoder,JSON.stringify(e));}writeKey(e){$r(this.restEncoder,e);}}class Io{constructor(){this.restEncoder=Ir(),this.dsCurrVal=0;}toUint8Array(){return Er(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0;}writeDsClock(e){const t=e-this.dsCurrVal;this.dsCurrVal=e,Rr(this.restEncoder,t);}writeDsLen(e){0===e&&es(),Rr(this.restEncoder,e-1),this.dsCurrVal+=e;}}class Fo extends Io{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new Jr,this.clientEncoder=new qr,this.leftClockEncoder=new Jr,this.rightClockEncoder=new Jr,this.infoEncoder=new Hr(Lr),this.stringEncoder=new Kr,this.parentInfoEncoder=new Hr(Lr),this.typeRefEncoder=new qr,this.lenEncoder=new qr;}toUint8Array(){const e=Ir();return Rr(e,0),Ur(e,this.keyClockEncoder.toUint8Array()),Ur(e,this.clientEncoder.toUint8Array()),Ur(e,this.leftClockEncoder.toUint8Array()),Ur(e,this.rightClockEncoder.toUint8Array()),Ur(e,Er(this.infoEncoder)),Ur(e,this.stringEncoder.toUint8Array()),Ur(e,Er(this.parentInfoEncoder)),Ur(e,this.typeRefEncoder.toUint8Array()),Ur(e,this.lenEncoder.toUint8Array()),jr(e,Er(this.restEncoder)),Er(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock);}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock);}writeClient(e){this.clientEncoder.write(e);}writeInfo(e){this.infoEncoder.write(e);}writeString(e){this.stringEncoder.write(e);}writeParentInfo(e){this.parentInfoEncoder.write(e?1:0);}writeTypeRef(e){this.typeRefEncoder.write(e);}writeLen(e){this.lenEncoder.write(e);}writeAny(e){Yr(this.restEncoder,e);}writeBuf(e){Ur(this.restEncoder,e);}writeJSON(e){Yr(this.restEncoder,e);}writeKey(e){const t=this.keyMap.get(e);void 0===t?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t);}}const Eo=(e,t,a)=>{const i=new Map;a.forEach(((e,a)=>{Xo(t,a)>e&&i.set(a,e);})),Ko(t).forEach(((e,t)=>{a.has(t)||i.set(t,0);})),Rr(e.restEncoder,i.size),lr(i.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([a,i])=>{((e,t,a,i)=>{i=mr(i,t[0].id.clock);const n=el(t,i);Rr(e.restEncoder,t.length-n),e.writeClient(a),Rr(e.restEncoder,i);const r=t[n];r.write(e,i-r.id.clock);for(let a=n+1;a<t.length;a++)t[a].write(e,0);})(e,t.clients.get(a),a,i);}));},Do=(e,t,a,i=new xo(e))=>dl(t,(e=>{e.local=!1;let t=!1;const a=e.doc,n=a.store,r=((e,t)=>{const a=ar(),i=os(e.restDecoder);for(let n=0;n<i;n++){const i=os(e.restDecoder),n=new Array(i),r=e.readClient();let s=os(e.restDecoder);a.set(r,{i:0,refs:n});for(let a=0;a<i;a++){const i=e.readInfo();switch(31&i){case 0:{const t=e.readLen();n[a]=new Au(Go(r,s),t),s+=t;break}case 10:{const t=os(e.restDecoder);n[a]=new Hu(Go(r,s),t),s+=t;break}default:{const o=!(192&i),l=new zu(Go(r,s),null,(i&vr)===vr?e.readLeftID():null,null,(i&br)===br?e.readRightID():null,o?e.readParentInfo()?t.get(e.readString()):e.readLeftID():null,!o||32&~i?null:e.readString(),Wu(e,i));n[a]=l,s+=l.length;}}}}return a})(i,a),s=((e,t,a)=>{const i=[];let n=lr(a.keys()).sort(((e,t)=>e-t));if(0===n.length)return null;const r=()=>{if(0===n.length)return null;let e=a.get(n[n.length-1]);for(;e.refs.length===e.i;){if(n.pop(),!(n.length>0))return null;e=a.get(n[n.length-1]);}return e};let s=r();if(null===s)return null;const o=new Jo,l=new Map,u=(e,t)=>{const a=l.get(e);(null==a||a>t)&&l.set(e,t);};let c=s.refs[s.i++];const d=new Map,p=()=>{for(const e of i){const t=e.id.client,i=a.get(t);i?(i.i--,o.clients.set(t,i.refs.slice(i.i)),a.delete(t),i.i=0,i.refs=[]):o.clients.set(t,[e]),n=n.filter((e=>e!==t));}i.length=0;};for(;;){if(c.constructor!==Hu){const n=nr(d,c.id.client,(()=>Xo(t,c.id.client)))-c.id.clock;if(n<0)i.push(c),u(c.id.client,c.id.clock-1),p();else {const r=c.getMissing(e,t);if(null!==r){i.push(c);const e=a.get(r)||{refs:[],i:0};if(e.refs.length!==e.i){c=e.refs[e.i++];continue}u(r,Xo(t,r)),p();}else (0===n||n<c.length)&&(c.integrate(e,n),d.set(c.id.client,c.id.clock+c.length));}}if(i.length>0)c=i.pop();else if(null!==s&&s.i<s.refs.length)c=s.refs[s.i++];else {if(s=r(),null===s)break;c=s.refs[s.i++];}}if(o.clients.size>0){const e=new Fo;return Eo(e,o,new Map),Rr(e.restEncoder,0),{missing:l,update:e.toUint8Array()}}return null})(e,n,r),o=n.pendingStructs;if(o){for(const[e,a]of o.missing)if(a<Xo(n,e)){t=!0;break}if(s){for(const[e,t]of s.missing){const a=o.missing.get(e);(null==a||a>t)&&o.missing.set(e,t);}o.update=yl([o.update,s.update]);}}else n.pendingStructs=s;const l=Ao(i,e,n);if(n.pendingDs){const t=new xo(ns(n.pendingDs));os(t.restDecoder);const a=Ao(t,e,n);n.pendingDs=l&&a?yl([l,a]):l||a;}else n.pendingDs=l;if(t){const t=n.pendingStructs.update;n.pendingStructs=null,Lo(e.doc,t);}}),a,false),Lo=(e,t,a,i=xo)=>{const n=ns(t);Do(n,e,a,new i(n));},Ro=(e,t=new Uint8Array([0]),a=new Fo)=>{((e,t,a=new Map)=>{Eo(e,t.store,a),_o(e,vo(t.store));})(a,e,Po(t));const i=[a.toUint8Array()];if(e.store.pendingDs&&i.push(e.store.pendingDs),e.store.pendingStructs&&i.push(gl(e.store.pendingStructs.update,t)),i.length>1){if(a.constructor===Co)return fl$2(i.map(((e,t)=>0===t?e:wl(e))));if(a.constructor===Fo)return yl(i)}return i[0]},Po=e=>(e=>{const t=new Map,a=os(e.restDecoder);for(let i=0;i<a;i++){const a=os(e.restDecoder),i=os(e.restDecoder);t.set(a,i);}return t})(new No(ns(e))),Oo=(e,t)=>(Rr(e.restEncoder,t.size),lr(t.entries()).sort(((e,t)=>t[0]-e[0])).forEach((([t,a])=>{Rr(e.restEncoder,t),Rr(e.restEncoder,a);})),e),Bo=(e,t=new Io)=>(e instanceof Map?Oo(t,e):((e,t)=>{Oo(e,Ko(t.store));})(t,e),t.toUint8Array());class $o{constructor(){this.l=[];}}const jo=()=>new $o,Uo=(e,t)=>e.l.push(t),zo=(e,t)=>{const a=e.l,i=a.length;e.l=a.filter((e=>t!==e)),i===e.l.length&&console.error("[yjs] Tried to remove event handler that doesn't exist.");},Wo=(e,t,a)=>Ls(e.l,[t,a]);class Yo{constructor(e,t){this.client=e,this.clock=t;}}const Ho=(e,t)=>e===t||null!==e&&null!==t&&e.client===t.client&&e.clock===t.clock,Go=(e,t)=>new Yo(e,t),qo=(e,t)=>void 0===t?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!yo(t.ds,e.id),Zo=(e,t)=>{const a=nr(e.meta,Zo,rr),i=e.doc.store;a.has(t)||(t.sv.forEach(((t,a)=>{t<Xo(i,a)&&il(e,Go(a,t));})),mo(e,t.ds,(e=>{})),a.add(t));};class Jo{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null;}}const Ko=e=>{const t=new Map;return e.clients.forEach(((e,a)=>{const i=e[e.length-1];t.set(a,i.id.clock+i.length);})),t},Xo=(e,t)=>{const a=e.clients.get(t);if(void 0===a)return 0;const i=a[a.length-1];return i.id.clock+i.length},Qo=(e,t)=>{let a=e.clients.get(t.id.client);if(void 0===a)a=[],e.clients.set(t.id.client,a);else {const e=a[a.length-1];if(e.id.clock+e.length!==t.id.clock)throw es()}a.push(t);},el=(e,t)=>{let a=0,i=e.length-1,n=e[i],r=n.id.clock;if(r===t)return i;let s=pr(t/(r+n.length-1)*i);for(;a<=i;){if(n=e[s],r=n.id.clock,r<=t){if(t<r+n.length)return s;a=s+1;}else i=s-1;s=pr((a+i)/2);}throw es()},tl=(e,t)=>{const a=e.clients.get(t.client);return a[el(a,t.clock)]},al=(e,t,a)=>{const i=el(t,a),n=t[i];return n.id.clock<a&&n instanceof zu?(t.splice(i+1,0,Uu(e,n,a-n.id.clock)),i+1):i},il=(e,t)=>{const a=e.doc.store.clients.get(t.client);return a[al(e,a,t.clock)]},nl=(e,t,a)=>{const i=t.clients.get(a.client),n=el(i,a.clock),r=i[n];return a.clock!==r.id.clock+r.length-1&&r.constructor!==Au&&i.splice(n+1,0,Uu(e,r,a.clock-r.id.clock+1)),r},rl=(e,t,a,i,n)=>{if(0===i)return;const r=a+i;let s,o=al(e,t,a);do{s=t[o++],r<s.id.clock+s.length&&al(e,t,r),n(s);}while(o<t.length&&t[o].id.clock<r)};class sl{constructor(e,t,a){this.doc=e,this.deleteSet=new fo,this.beforeState=Ko(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=a,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=false;}}const ol=(e,t)=>!(0===t.deleteSet.clients.size&&!((e,t)=>{for(const[a,i]of e)if(t(i,a))return true;return false})(t.afterState,((e,a)=>t.beforeState.get(a)!==e)))&&(go(t.deleteSet),((e,t)=>{Eo(e,t.doc.store,t.beforeState);})(e,t),_o(e,t.deleteSet),true),ll=(e,t,a)=>{const i=t._item;(null===i||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&nr(e.changed,t,rr).add(a);},ul=(e,t)=>{let a=e[t],i=e[t-1],n=t;for(;n>0&&(i.deleted===a.deleted&&i.constructor===a.constructor&&i.mergeWith(a));a=i,i=e[--n-1])a instanceof zu&&null!==a.parentSub&&a.parent._map.get(a.parentSub)===a&&a.parent._map.set(a.parentSub,i);const r=t-n;return r&&e.splice(t+1-r,r),r},cl=(e,t)=>{if(t<e.length){const a=e[t],i=a.doc,n=i.store,r=a.deleteSet,s=a._mergeStructs;try{go(r),a.afterState=Ko(a.doc.store),i.emit("beforeObserverCalls",[a,i]);const e=[];a.changed.forEach(((t,i)=>e.push((()=>{null!==i._item&&i._item.deleted||i._callObserver(a,t);})))),e.push((()=>{a.changedParentTypes.forEach(((e,t)=>{t._dEH.l.length>0&&(null===t._item||!t._item.deleted)&&((e=e.filter((e=>null===e.target._item||!e.target._item.deleted))).forEach((e=>{e.currentTarget=t,e._path=null;})),e.sort(((e,t)=>e.path.length-t.path.length)),Wo(t._dEH,e,a));}));})),e.push((()=>i.emit("afterTransaction",[a,i]))),Ls(e,[]),a._needFormattingCleanup&&du(a);}finally{i.gc&&((e,t,a)=>{for(const[i,n]of e.clients.entries()){const e=t.clients.get(i);for(let i=n.length-1;i>=0;i--){const r=n[i],s=r.clock+r.len;for(let i=el(e,r.clock),n=e[i];i<e.length&&n.id.clock<s;n=e[++i]){const n=e[i];if(r.clock+r.len<=n.id.clock)break;n instanceof zu&&n.deleted&&!n.keep&&a(n)&&n.gc(t,false);}}}})(r,n,i.gcFilter),((e,t)=>{e.clients.forEach(((e,a)=>{const i=t.clients.get(a);for(let t=e.length-1;t>=0;t--){const a=e[t];for(let e=fr(i.length-1,1+el(i,a.clock+a.len-1)),t=i[e];e>0&&t.id.clock>=a.clock;t=i[e])e-=1+ul(i,e);}}));})(r,n),a.afterState.forEach(((e,t)=>{const i=a.beforeState.get(t)||0;if(i!==e){const e=n.clients.get(t),a=mr(el(e,i),1);for(let t=e.length-1;t>=a;)t-=1+ul(e,t);}}));for(let e=s.length-1;e>=0;e--){const{client:t,clock:a}=s[e].id,i=n.clients.get(t),r=el(i,a);r+1<i.length&&ul(i,r+1)>1||r>0&&ul(i,r);}if(a.local||a.afterState.get(i.clientID)===a.beforeState.get(i.clientID)||(((...e)=>{console.log(...lo(e)),uo.forEach((t=>t.print(e)));})(ro,Xs,"[yjs] ",Qs,io,"Changed the client-id because another client seems to be using it."),i.clientID=ko()),i.emit("afterTransactionCleanup",[a,i]),i._observers.has("update")){const e=new Co;ol(e,a)&&i.emit("update",[e.toUint8Array(),a.origin,i,a]);}if(i._observers.has("updateV2")){const e=new Fo;ol(e,a)&&i.emit("updateV2",[e.toUint8Array(),a.origin,i,a]);}const{subdocsAdded:o,subdocsLoaded:l,subdocsRemoved:u}=a;(o.size>0||u.size>0||l.size>0)&&(o.forEach((e=>{e.clientID=i.clientID,null==e.collectionid&&(e.collectionid=i.collectionid),i.subdocs.add(e);})),u.forEach((e=>i.subdocs.delete(e))),i.emit("subdocs",[{loaded:l,added:o,removed:u},i,a]),u.forEach((e=>e.destroy()))),e.length<=t+1?(i._transactionCleanups=[],i.emit("afterAllTransactions",[i,e])):cl(e,t+1);}}},dl=(e,t,a=null,i=true)=>{const n=e._transactionCleanups;let r=false,s=null;null===e._transaction&&(r=true,e._transaction=new sl(e,a,i),n.push(e._transaction),1===n.length&&e.emit("beforeAllTransactions",[e]),e.emit("beforeTransaction",[e._transaction,e]));try{s=t(e._transaction);}finally{if(r){const t=e._transaction===n[0];e._transaction=null,t&&cl(n,0);}}return s};class pl{constructor(e,t){this.gen=function*(e){const t=os(e.restDecoder);for(let a=0;a<t;a++){const t=os(e.restDecoder),a=e.readClient();let i=os(e.restDecoder);for(let n=0;n<t;n++){const t=e.readInfo();if(10===t){const t=os(e.restDecoder);yield new Hu(Go(a,i),t),i+=t;}else if(31&t){const n=!(192&t),r=new zu(Go(a,i),null,(t&vr)===vr?e.readLeftID():null,null,(t&br)===br?e.readRightID():null,n?e.readParentInfo()?e.readString():e.readLeftID():null,!n||32&~t?null:e.readString(),Wu(e,t));yield r,i+=r.length;}else {const t=e.readLen();yield new Au(Go(a,i),t),i+=t;}}}}(e),this.curr=null,this.done=false,this.filterSkips=t,this.next();}next(){do{this.curr=this.gen.next().value||null;}while(this.filterSkips&&null!==this.curr&&this.curr.constructor===Hu);return this.curr}}class hl{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[];}}const fl$2=e=>yl(e,To,Co),ml=(e,t)=>{if(e.constructor===Au){const{client:a,clock:i}=e.id;return new Au(Go(a,i+t),e.length-t)}if(e.constructor===Hu){const{client:a,clock:i}=e.id;return new Hu(Go(a,i+t),e.length-t)}{const a=e,{client:i,clock:n}=a.id;return new zu(Go(i,n+t),null,Go(i,n+t-1),null,a.rightOrigin,a.parent,a.parentSub,a.content.splice(t))}},yl=(e,t=xo,a=Fo)=>{if(1===e.length)return e[0];const i=e.map((e=>new t(ns(e))));let n=i.map((e=>new pl(e,true))),r=null;const s=new a,o=new hl(s);for(;n=n.filter((e=>null!==e.curr)),n.sort(((e,t)=>{if(e.curr.id.client===t.curr.id.client){const a=e.curr.id.clock-t.curr.id.clock;return 0===a?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Hu?1:-1:a}return t.curr.id.client-e.curr.id.client})),0!==n.length;){const e=n[0],t=e.curr.id.client;if(null!==r){let a=e.curr,i=false;for(;null!==a&&a.id.clock+a.length<=r.struct.id.clock+r.struct.length&&a.id.client>=r.struct.id.client;)a=e.next(),i=true;if(null===a||a.id.client!==t||i&&a.id.clock>r.struct.id.clock+r.struct.length)continue;if(t!==r.struct.id.client)vl(o,r.struct,r.offset),r={struct:a,offset:0},e.next();else if(r.struct.id.clock+r.struct.length<a.id.clock)if(r.struct.constructor===Hu)r.struct.length=a.id.clock+a.length-r.struct.id.clock;else {vl(o,r.struct,r.offset);const e=a.id.clock-r.struct.id.clock-r.struct.length;r={struct:new Hu(Go(t,r.struct.id.clock+r.struct.length),e),offset:0};}else {const t=r.struct.id.clock+r.struct.length-a.id.clock;t>0&&(r.struct.constructor===Hu?r.struct.length-=t:a=ml(a,t)),r.struct.mergeWith(a)||(vl(o,r.struct,r.offset),r={struct:a,offset:0},e.next());}}else r={struct:e.curr,offset:0},e.next();for(let a=e.curr;null!==a&&a.id.client===t&&a.id.clock===r.struct.id.clock+r.struct.length&&a.constructor!==Hu;a=e.next())vl(o,r.struct,r.offset),r={struct:a,offset:0};}null!==r&&(vl(o,r.struct,r.offset),r=null),_l(o);const l=(e=>{const t=new fo;for(let a=0;a<e.length;a++)e[a].clients.forEach(((i,n)=>{if(!t.clients.has(n)){const r=i.slice();for(let t=a+1;t<e.length;t++)or(r,e[t].clients.get(n)||[]);t.clients.set(n,r);}}));return go(t),t})(i.map((e=>wo(e))));return _o(s,l),s.toUint8Array()},gl=(e,t,a=xo,i=Fo)=>{const n=Po(t),r=new i,s=new hl(r),o=new a(ns(e)),l=new pl(o,false);for(;l.curr;){const e=l.curr,t=e.id.client,a=n.get(t)||0;if(l.curr.constructor!==Hu)if(e.id.clock+e.length>a)for(vl(s,e,mr(a-e.id.clock,0)),l.next();l.curr&&l.curr.id.client===t;)vl(s,l.curr,0),l.next();else for(;l.curr&&l.curr.id.client===t&&l.curr.id.clock+l.curr.length<=a;)l.next();else l.next();}_l(s);const u=wo(o);return _o(r,u),r.toUint8Array()},bl=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:Er(e.encoder.restEncoder)}),e.encoder.restEncoder=Ir(),e.written=0);},vl=(e,t,a)=>{e.written>0&&e.currClient!==t.id.client&&bl(e),0===e.written&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),Rr(e.encoder.restEncoder,t.id.clock+a)),t.write(e.encoder,a),e.written++;},_l=e=>{bl(e);const t=e.encoder.restEncoder;Rr(t,e.clientStructs.length);for(let a=0;a<e.clientStructs.length;a++){const i=e.clientStructs[a];Rr(t,i.written),jr(t,i.restEncoder);}},wl=e=>((e,t,a,i)=>{const n=new a(ns(e)),r=new pl(n,false),s=new i,o=new hl(s);for(let e=r.curr;null!==e;e=r.next())vl(o,t(e),0);_l(o);const l=wo(n);return _o(s,l),s.toUint8Array()})(e,Rs,xo,Co),Al="You must not compute changes after the event-handler fired.";class kl{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null;}get path(){return this._path||(this._path=Sl(this.currentTarget,this.target))}deletes(e){return yo(this.transaction.deleteSet,e.id)}get keys(){if(null===this._keys){if(0===this.transaction.doc._transactionCleanups.length)throw Xr(Al);const e=new Map,t=this.target;this.transaction.changed.get(t).forEach((a=>{if(null!==a){const i=t._map.get(a);let n,r;if(this.adds(i)){let e=i.left;for(;null!==e&&this.adds(e);)e=e.left;if(this.deletes(i)){if(null===e||!this.deletes(e))return;n="delete",r=sr(e.content.getContent());}else null!==e&&this.deletes(e)?(n="update",r=sr(e.content.getContent())):(n="add",r=void 0);}else {if(!this.deletes(i))return;n="delete",r=sr(i.content.getContent());}e.set(a,{action:n,oldValue:r});}})),this._keys=e;}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(null===e){if(0===this.transaction.doc._transactionCleanups.length)throw Xr(Al);const t=this.target,a=rr(),i=rr(),n=[];e={added:a,deleted:i,delta:n,keys:this.keys};if(this.transaction.changed.get(t).has(null)){let e=null;const r=()=>{e&&n.push(e);};for(let n=t._start;null!==n;n=n.right)n.deleted?this.deletes(n)&&!this.adds(n)&&(null!==e&&void 0!==e.delete||(r(),e={delete:0}),e.delete+=n.length,i.add(n)):this.adds(n)?(null!==e&&void 0!==e.insert||(r(),e={insert:[]}),e.insert=e.insert.concat(n.content.getContent()),a.add(n)):(null!==e&&void 0!==e.retain||(r(),e={retain:0}),e.retain+=n.length);null!==e&&void 0===e.retain&&r();}this._changes=e;}return e}}const Sl=(e,t)=>{const a=[];for(;null!==t._item&&t!==e;){if(null!==t._item.parentSub)a.unshift(t._item.parentSub);else {let e=0,i=t._item.parent._start;for(;i!==t._item&&null!==i;)!i.deleted&&i.countable&&(e+=i.length),i=i.right;a.unshift(e);}t=t._item.parent;}return a},Nl=()=>{((...e)=>{console.warn(...lo(e)),e.unshift(ro),uo.forEach((t=>t.print(e)));})("Invalid access: Add Yjs type to a document before reading data.");};let Tl=0;class Ml{constructor(e,t){e.marker=true,this.p=e,this.index=t,this.timestamp=Tl++;}}const xl=(e,t,a)=>{e.p.marker=false,e.p=t,t.marker=true,e.index=a,e.timestamp=Tl++;},Vl=(e,t)=>{if(null===e._start||0===t||null===e._searchMarker)return null;const a=0===e._searchMarker.length?null:e._searchMarker.reduce(((e,a)=>hr(t-e.index)<hr(t-a.index)?e:a));let i=e._start,n=0;for(null!==a&&(i=a.p,n=a.index,(e=>{e.timestamp=Tl++;})(a));null!==i.right&&n<t;){if(!i.deleted&&i.countable){if(t<n+i.length)break;n+=i.length;}i=i.right;}for(;null!==i.left&&n>t;)i=i.left,!i.deleted&&i.countable&&(n-=i.length);for(;null!==i.left&&i.left.id.client===i.id.client&&i.left.id.clock+i.left.length===i.id.clock;)i=i.left,!i.deleted&&i.countable&&(n-=i.length);return null!==a&&hr(a.index-n)<i.parent.length/80?(xl(a,i,n),a):((e,t,a)=>{if(e.length>=80){const i=e.reduce(((e,t)=>e.timestamp<t.timestamp?e:t));return xl(i,t,a),i}{const i=new Ml(t,a);return e.push(i),i}})(e._searchMarker,i,n)},Cl=(e,t,a)=>{for(let i=e.length-1;i>=0;i--){const n=e[i];if(a>0){let t=n.p;for(t.marker=false;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(n.index-=t.length);if(null===t||true===t.marker){e.splice(i,1);continue}n.p=t,t.marker=true;}(t<n.index||a>0&&t===n.index)&&(n.index=mr(t,n.index+a));}},Il=(e,t,a)=>{const i=e,n=t.changedParentTypes;for(;nr(n,e,(()=>[])).push(a),null!==e._item;)e=e._item.parent;Wo(i._eH,a,t);};class Fl{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=jo(),this._dEH=jo(),this._searchMarker=null;}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t;}_copy(){throw Qr()}clone(){throw Qr()}_write(e){}get _first(){let e=this._start;for(;null!==e&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0);}observe(e){Uo(this._eH,e);}observeDeep(e){Uo(this._dEH,e);}unobserve(e){zo(this._eH,e);}unobserveDeep(e){zo(this._dEH,e);}toJSON(){}}const El=(e,t,a)=>{e.doc??Nl(),t<0&&(t=e._length+t),a<0&&(a=e._length+a);let i=a-t;const n=[];let r=e._start;for(;null!==r&&i>0;){if(r.countable&&!r.deleted){const e=r.content.getContent();if(e.length<=t)t-=e.length;else {for(let a=t;a<e.length&&i>0;a++)n.push(e[a]),i--;t=0;}}r=r.right;}return n},Dl=e=>{e.doc??Nl();const t=[];let a=e._start;for(;null!==a;){if(a.countable&&!a.deleted){const e=a.content.getContent();for(let a=0;a<e.length;a++)t.push(e[a]);}a=a.right;}return t},Ll=(e,t)=>{let a=0,i=e._start;for(e.doc??Nl();null!==i;){if(i.countable&&!i.deleted){const n=i.content.getContent();for(let i=0;i<n.length;i++)t(n[i],a++,e);}i=i.right;}},Rl=(e,t)=>{const a=[];return Ll(e,((i,n)=>{a.push(t(i,n,e));})),a},Pl=e=>{let t=e._start,a=null,i=0;return {[Symbol.iterator](){return this},next:()=>{if(null===a){for(;null!==t&&t.deleted;)t=t.right;if(null===t)return {done:true,value:void 0};a=t.content.getContent(),i=0,t=t.right;}const e=a[i++];return a.length<=i&&(a=null),{done:false,value:e}}}},Ol=(e,t)=>{e.doc??Nl();const a=Vl(e,t);let i=e._start;for(null!==a&&(i=a.p,t-=a.index);null!==i;i=i.right)if(!i.deleted&&i.countable){if(t<i.length)return i.content.getContent()[t];t-=i.length;}},Bl=(e,t,a,i)=>{let n=a;const r=e.doc,s=r.clientID,o=r.store,l=null===a?t._start:a.right;let u=[];const c=()=>{u.length>0&&(n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new Iu(u)),n.integrate(e,0),u=[]);};i.forEach((a=>{if(null===a)u.push(a);else switch(a.constructor){case Number:case Object:case Boolean:case Array:case String:u.push(a);break;default:switch(c(),a.constructor){case Uint8Array:case ArrayBuffer:n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new ku(new Uint8Array(a))),n.integrate(e,0);break;case So:n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new Tu(a)),n.integrate(e,0);break;default:if(!(a instanceof Fl))throw new Error("Unexpected content type in insert operation");n=new zu(Go(s,Xo(o,s)),n,n&&n.lastId,l,l&&l.id,t,null,new ju(a)),n.integrate(e,0);}}})),c();},$l=()=>Xr("Length exceeded!"),jl=(e,t,a,i)=>{if(a>t._length)throw $l();if(0===a)return t._searchMarker&&Cl(t._searchMarker,a,i.length),Bl(e,t,null,i);const n=a,r=Vl(t,a);let s=t._start;for(null!==r&&(s=r.p,0===(a-=r.index)&&(s=s.prev,a+=s&&s.countable&&!s.deleted?s.length:0));null!==s;s=s.right)if(!s.deleted&&s.countable){if(a<=s.length){a<s.length&&il(e,Go(s.id.client,s.id.clock+a));break}a-=s.length;}return t._searchMarker&&Cl(t._searchMarker,n,i.length),Bl(e,t,s,i)},Ul=(e,t,a,i)=>{if(0===i)return;const n=a,r=i,s=Vl(t,a);let o=t._start;for(null!==s&&(o=s.p,a-=s.index);null!==o&&a>0;o=o.right)!o.deleted&&o.countable&&(a<o.length&&il(e,Go(o.id.client,o.id.clock+a)),a-=o.length);for(;i>0&&null!==o;)o.deleted||(i<o.length&&il(e,Go(o.id.client,o.id.clock+i)),o.delete(e),i-=o.length),o=o.right;if(i>0)throw $l();t._searchMarker&&Cl(t._searchMarker,n,-r+i);},zl=(e,t,a)=>{const i=t._map.get(a);void 0!==i&&i.delete(e);},Wl=(e,t,a,i)=>{const n=t._map.get(a)||null,r=e.doc,s=r.clientID;let o;if(null==i)o=new Iu([i]);else switch(i.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:o=new Iu([i]);break;case Uint8Array:o=new ku(i);break;case So:o=new Tu(i);break;default:if(!(i instanceof Fl))throw new Error("Unexpected content type");o=new ju(i);}new zu(Go(s,Xo(r.store,s)),n,n&&n.lastId,null,null,t,a,o).integrate(e,0);},Yl=(e,t)=>{e.doc??Nl();const a=e._map.get(t);return void 0===a||a.deleted?void 0:a.content.getContent()[a.length-1]},Hl=e=>{const t={};return e.doc??Nl(),e._map.forEach(((e,a)=>{e.deleted||(t[a]=e.content.getContent()[e.length-1]);})),t},Gl=(e,t)=>{e.doc??Nl();const a=e._map.get(t);return void 0!==a&&!a.deleted},ql=e=>{return e.doc??Nl(),t=e._map.entries(),a=e=>!e[1].deleted,co((()=>{let e;do{e=t.next();}while(!e.done&&!a(e.value));return e}));var t,a;};class Zl extends kl{}class Jl extends Fl{constructor(){super(),this._prelimContent=[],this._searchMarker=[];}static from(e){const t=new Jl;return t.push(e),t}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null;}_copy(){return new Jl}clone(){const e=new Jl;return e.insert(0,this.toArray().map((e=>e instanceof Fl?e.clone():e))),e}get length(){return this.doc??Nl(),this._length}_callObserver(e,t){super._callObserver(e,t),Il(this,e,new Zl(this,e));}insert(e,t){null!==this.doc?dl(this.doc,(a=>{jl(a,this,e,t);})):this._prelimContent.splice(e,0,...t);}push(e){null!==this.doc?dl(this.doc,(t=>{((e,t,a)=>{let i=(t._searchMarker||[]).reduce(((e,t)=>t.index>e.index?t:e),{index:0,p:t._start}).p;if(i)for(;i.right;)i=i.right;Bl(e,t,i,a);})(t,this,e);})):this._prelimContent.push(...e);}unshift(e){this.insert(0,e);}delete(e,t=1){null!==this.doc?dl(this.doc,(a=>{Ul(a,this,e,t);})):this._prelimContent.splice(e,t);}get(e){return Ol(this,e)}toArray(){return Dl(this)}slice(e=0,t=this.length){return El(this,e,t)}toJSON(){return this.map((e=>e instanceof Fl?e.toJSON():e))}map(e){return Rl(this,e)}forEach(e){Ll(this,e);}[Symbol.iterator](){return Pl(this)}_write(e){e.writeTypeRef(Du);}}class Kl extends kl{constructor(e,t,a){super(e,t),this.keysChanged=a;}}class Xl extends Fl{constructor(e){super(),this._prelimContent=null,this._prelimContent=void 0===e?new Map:new Map(e);}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach(((e,t)=>{this.set(t,e);})),this._prelimContent=null;}_copy(){return new Xl}clone(){const e=new Xl;return this.forEach(((t,a)=>{e.set(a,t instanceof Fl?t.clone():t);})),e}_callObserver(e,t){Il(this,e,new Kl(this,e,t));}toJSON(){this.doc??Nl();const e={};return this._map.forEach(((t,a)=>{if(!t.deleted){const i=t.content.getContent()[t.length-1];e[a]=i instanceof Fl?i.toJSON():i;}})),e}get size(){return [...ql(this)].length}keys(){return po(ql(this),(e=>e[0]))}values(){return po(ql(this),(e=>e[1].content.getContent()[e[1].length-1]))}entries(){return po(ql(this),(e=>[e[0],e[1].content.getContent()[e[1].length-1]]))}forEach(e){this.doc??Nl(),this._map.forEach(((t,a)=>{t.deleted||e(t.content.getContent()[t.length-1],a,this);}));}[Symbol.iterator](){return this.entries()}delete(e){null!==this.doc?dl(this.doc,(t=>{zl(t,this,e);})):this._prelimContent.delete(e);}set(e,t){return null!==this.doc?dl(this.doc,(a=>{Wl(a,this,e,t);})):this._prelimContent.set(e,t),t}get(e){return Yl(this,e)}has(e){return Gl(this,e)}clear(){null!==this.doc?dl(this.doc,(e=>{this.forEach((function(t,a,i){zl(e,i,a);}));})):this._prelimContent.clear();}_write(e){e.writeTypeRef(Lu);}}const Ql=(e,t)=>e===t||"object"==typeof e&&"object"==typeof t&&e&&t&&((e,t)=>e===t||Cs(e)===Cs(t)&&((e,t)=>{for(const a in e)if(!t(e[a],a))return false;return true})(e,((e,a)=>(void 0!==e||Is(t,a))&&t[a]===e)))(e,t);class eu{constructor(e,t,a,i){this.left=e,this.right=t,this.index=a,this.currentAttributes=i;}forward(){if(null===this.right&&es(),this.right.content.constructor===xu)this.right.deleted||nu(this.currentAttributes,this.right.content);else this.right.deleted||(this.index+=this.right.length);this.left=this.right,this.right=this.right.right;}}const tu=(e,t,a)=>{for(;null!==t.right&&a>0;){if(t.right.content.constructor===xu)t.right.deleted||nu(t.currentAttributes,t.right.content);else t.right.deleted||(a<t.right.length&&il(e,Go(t.right.id.client,t.right.id.clock+a)),t.index+=t.right.length,a-=t.right.length);t.left=t.right,t.right=t.right.right;}return t},au=(e,t,a,i)=>{const n=new Map,r=i?Vl(t,a):null;if(r){const t=new eu(r.p.left,r.p,r.index,n);return tu(e,t,a-r.index)}{const i=new eu(null,t._start,0,n);return tu(e,i,a)}},iu=(e,t,a,i)=>{for(;null!==a.right&&(true===a.right.deleted||a.right.content.constructor===xu&&Ql(i.get(a.right.content.key),a.right.content.value));)a.right.deleted||i.delete(a.right.content.key),a.forward();const n=e.doc,r=n.clientID;i.forEach(((i,s)=>{const o=a.left,l=a.right,u=new zu(Go(r,Xo(n.store,r)),o,o&&o.lastId,l,l&&l.id,t,null,new xu(s,i));u.integrate(e,0),a.right=u,a.forward();}));},nu=(e,t)=>{const{key:a,value:i}=t;null===i?e.delete(a):e.set(a,i);},ru=(e,t)=>{for(;null!==e.right&&(e.right.deleted||e.right.content.constructor===xu&&Ql(t[e.right.content.key]??null,e.right.content.value));)e.forward();},su=(e,t,a,i)=>{const n=e.doc,r=n.clientID,s=new Map;for(const o in i){const l=i[o],u=a.currentAttributes.get(o)??null;if(!Ql(u,l)){s.set(o,u);const{left:i,right:c}=a;a.right=new zu(Go(r,Xo(n.store,r)),i,i&&i.lastId,c,c&&c.id,t,null,new xu(o,l)),a.right.integrate(e,0),a.forward();}}return s},ou=(e,t,a,i,n)=>{a.currentAttributes.forEach(((e,t)=>{ void 0===n[t]&&(n[t]=null);}));const r=e.doc,s=r.clientID;ru(a,n);const o=su(e,t,a,n),l=i.constructor===String?new Fu(i):i instanceof Fl?new ju(i):new Mu(i);let{left:u,right:c,index:d}=a;t._searchMarker&&Cl(t._searchMarker,a.index,l.getLength()),c=new zu(Go(s,Xo(r.store,s)),u,u&&u.lastId,c,c&&c.id,t,null,l),c.integrate(e,0),a.right=c,a.index=d,a.forward(),iu(e,t,a,o);},lu=(e,t,a,i,n)=>{const r=e.doc,s=r.clientID;ru(a,n);const o=su(e,t,a,n);e:for(;null!==a.right&&(i>0||o.size>0&&(a.right.deleted||a.right.content.constructor===xu));){if(!a.right.deleted)switch(a.right.content.constructor){case xu:{const{key:t,value:r}=a.right.content,s=n[t];if(void 0!==s){if(Ql(s,r))o.delete(t);else {if(0===i)break e;o.set(t,r);}a.right.delete(e);}else a.currentAttributes.set(t,r);break}default:i<a.right.length&&il(e,Go(a.right.id.client,a.right.id.clock+i)),i-=a.right.length;}a.forward();}if(i>0){let n="";for(;i>0;i--)n+="\n";a.right=new zu(Go(s,Xo(r.store,s)),a.left,a.left&&a.left.lastId,a.right,a.right&&a.right.id,t,null,new Fu(n)),a.right.integrate(e,0),a.forward();}iu(e,t,a,o);},uu=(e,t,a,i,n)=>{let r=t;const s=ar();for(;r&&(!r.countable||r.deleted);){if(!r.deleted&&r.content.constructor===xu){const e=r.content;s.set(e.key,e);}r=r.right;}let o=0,l=false;for(;t!==r;){if(a===t&&(l=true),!t.deleted){const a=t.content;switch(a.constructor){case xu:{const{key:r,value:u}=a,c=i.get(r)??null;s.get(r)===a&&c!==u||(t.delete(e),o++,l||(n.get(r)??null)!==u||c===u||(null===c?n.delete(r):n.set(r,c))),l||t.deleted||nu(n,a);break}}}t=t.right;}return o},cu=e=>{let t=0;return dl(e.doc,(a=>{let i=e._start,n=e._start,r=ar();const s=ir(r);for(;n;){if(!1===n.deleted)if(n.content.constructor===xu)nu(s,n.content);else t+=uu(a,i,n,r,s),r=ir(s),i=n;n=n.right;}})),t},du=e=>{const t=new Set,a=e.doc;for(const[i,n]of e.afterState.entries()){const r=e.beforeState.get(i)||0;n!==r&&rl(e,a.store.clients.get(i),r,n,(e=>{e.deleted||e.content.constructor!==xu||e.constructor===Au||t.add(e.parent);}));}dl(a,(a=>{mo(e,e.deleteSet,(e=>{if(e instanceof Au||!e.parent._hasFormatting||t.has(e.parent))return;const i=e.parent;e.content.constructor===xu?t.add(i):((e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;const a=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===xu){const i=t.content.key;a.has(i)?t.delete(e):a.add(i);}t=t.left;}})(a,e);}));for(const e of t)cu(e);}));},pu=(e,t,a)=>{const i=a,n=ir(t.currentAttributes),r=t.right;for(;a>0&&null!==t.right;){if(false===t.right.deleted)switch(t.right.content.constructor){case ju:case Mu:case Fu:a<t.right.length&&il(e,Go(t.right.id.client,t.right.id.clock+a)),a-=t.right.length,t.right.delete(e);}t.forward();}r&&uu(e,r,t.right,n,t.currentAttributes);const s=(t.left||t.right).parent;return s._searchMarker&&Cl(s._searchMarker,t.index,-i+a),t};class hu extends kl{constructor(e,t,a){super(e,t),this.childListChanged=false,this.keysChanged=new Set,a.forEach((e=>{null===e?this.childListChanged=true:this.keysChanged.add(e);}));}get changes(){if(null===this._changes){const e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e;}return this._changes}get delta(){if(null===this._delta){const e=this.target.doc,t=[];dl(e,(e=>{const a=new Map,i=new Map;let n=this.target._start,r=null;const s={};let o="",l=0,u=0;const c=()=>{if(null!==r){let e=null;switch(r){case "delete":u>0&&(e={delete:u}),u=0;break;case "insert":("object"==typeof o||o.length>0)&&(e={insert:o},a.size>0&&(e.attributes={},a.forEach(((t,a)=>{null!==t&&(e.attributes[a]=t);})))),o="";break;case "retain":l>0&&(e={retain:l},(e=>{for(const t in e)return !1;return !0})(s)||(e.attributes=Ms({},s))),l=0;}e&&t.push(e),r=null;}};for(;null!==n;){switch(n.content.constructor){case ju:case Mu:this.adds(n)?this.deletes(n)||(c(),r="insert",o=n.content.getContent()[0],c()):this.deletes(n)?("delete"!==r&&(c(),r="delete"),u+=1):n.deleted||("retain"!==r&&(c(),r="retain"),l+=1);break;case Fu:this.adds(n)?this.deletes(n)||("insert"!==r&&(c(),r="insert"),o+=n.content.str):this.deletes(n)?("delete"!==r&&(c(),r="delete"),u+=n.length):n.deleted||("retain"!==r&&(c(),r="retain"),l+=n.length);break;case xu:{const{key:t,value:o}=n.content;if(this.adds(n)){if(!this.deletes(n)){const l=a.get(t)??null;Ql(l,o)?null!==o&&n.delete(e):("retain"===r&&c(),Ql(o,i.get(t)??null)?delete s[t]:s[t]=o);}}else if(this.deletes(n)){i.set(t,o);const e=a.get(t)??null;Ql(e,o)||("retain"===r&&c(),s[t]=e);}else if(!n.deleted){i.set(t,o);const a=s[t];void 0!==a&&(Ql(a,o)?null!==a&&n.delete(e):("retain"===r&&c(),null===o?delete s[t]:s[t]=o));}n.deleted||("insert"===r&&c(),nu(a,n.content));break}}n=n.right;}for(c();t.length>0;){const e=t[t.length-1];if(void 0===e.retain||void 0!==e.attributes)break;t.pop();}})),this._delta=t;}return this._delta}}class fu extends Fl{constructor(e){super(),this._pending=void 0!==e?[()=>this.insert(0,e)]:[],this._searchMarker=[],this._hasFormatting=false;}get length(){return this.doc??Nl(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach((e=>e()));}catch(e){console.error(e);}this._pending=null;}_copy(){return new fu}clone(){const e=new fu;return e.applyDelta(this.toDelta()),e}_callObserver(e,t){super._callObserver(e,t);const a=new hu(this,e,t);Il(this,e,a),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=true);}toString(){this.doc??Nl();let e="",t=this._start;for(;null!==t;)!t.deleted&&t.countable&&t.content.constructor===Fu&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=true}={}){null!==this.doc?dl(this.doc,(a=>{const i=new eu(null,this._start,0,new Map);for(let n=0;n<e.length;n++){const r=e[n];if(void 0!==r.insert){const s=t||"string"!=typeof r.insert||n!==e.length-1||null!==i.right||"\n"!==r.insert.slice(-1)?r.insert:r.insert.slice(0,-1);("string"!=typeof s||s.length>0)&&ou(a,this,i,s,r.attributes||{});}else void 0!==r.retain?lu(a,this,i,r.retain,r.attributes||{}):void 0!==r.delete&&pu(a,i,r.delete);}})):this._pending.push((()=>this.applyDelta(e)));}toDelta(e,t,a){this.doc??Nl();const i=[],n=new Map,r=this.doc;let s="",o=this._start;function l(){if(s.length>0){const e={};let t=false;n.forEach(((a,i)=>{t=true,e[i]=a;}));const a={insert:s};t&&(a.attributes=e),i.push(a),s="";}}const u=()=>{for(;null!==o;){if(qo(o,e)||void 0!==t&&qo(o,t))switch(o.content.constructor){case Fu:{const i=n.get("ychange");void 0===e||qo(o,e)?void 0===t||qo(o,t)?void 0!==i&&(l(),n.delete("ychange")):void 0!==i&&i.user===o.id.client&&"added"===i.type||(l(),n.set("ychange",a?a("added",o.id):{type:"added"})):void 0!==i&&i.user===o.id.client&&"removed"===i.type||(l(),n.set("ychange",a?a("removed",o.id):{type:"removed"})),s+=o.content.str;break}case ju:case Mu:{l();const e={insert:o.content.getContent()[0]};if(n.size>0){const t={};e.attributes=t,n.forEach(((e,a)=>{t[a]=e;}));}i.push(e);break}case xu:qo(o,e)&&(l(),nu(n,o.content));}o=o.right;}l();};return e||t?dl(r,(a=>{e&&Zo(a,e),t&&Zo(a,t),u();}),"cleanup"):u(),i}insert(e,t,a){if(t.length<=0)return;const i=this.doc;null!==i?dl(i,(i=>{const n=au(i,this,e,!a);a||(a={},n.currentAttributes.forEach(((e,t)=>{a[t]=e;}))),ou(i,this,n,t,a);})):this._pending.push((()=>this.insert(e,t,a)));}insertEmbed(e,t,a){const i=this.doc;null!==i?dl(i,(i=>{const n=au(i,this,e,!a);ou(i,this,n,t,a||{});})):this._pending.push((()=>this.insertEmbed(e,t,a||{})));}delete(e,t){if(0===t)return;const a=this.doc;null!==a?dl(a,(a=>{pu(a,au(a,this,e,!0),t);})):this._pending.push((()=>this.delete(e,t)));}format(e,t,a){if(0===t)return;const i=this.doc;null!==i?dl(i,(i=>{const n=au(i,this,e,!1);null!==n.right&&lu(i,this,n,t,a);})):this._pending.push((()=>this.format(e,t,a)));}removeAttribute(e){null!==this.doc?dl(this.doc,(t=>{zl(t,this,e);})):this._pending.push((()=>this.removeAttribute(e)));}setAttribute(e,t){null!==this.doc?dl(this.doc,(a=>{Wl(a,this,e,t);})):this._pending.push((()=>this.setAttribute(e,t)));}getAttribute(e){return Yl(this,e)}getAttributes(){return Hl(this)}_write(e){e.writeTypeRef(Ru);}}class mu{constructor(e,t=()=>true){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=true,e.doc??Nl();}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(null!==e&&(!this._firstCall||e.deleted||!this._filter(t)))do{if(t=e.content.type,e.deleted||t.constructor!==gu&&t.constructor!==yu||null===t._start)for(;null!==e;){const t=e.next;if(null!==t){e=t;break}e=e.parent===this._root?null:e.parent._item;}else e=t._start;}while(null!==e&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=false,null===e?{value:void 0,done:true}:(this._currentNode=e,{value:e.content.type,done:false})}}class yu extends Fl{constructor(){super(),this._prelimContent=[];}get firstChild(){const e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null;}_copy(){return new yu}clone(){const e=new yu;return e.insert(0,this.toArray().map((e=>e instanceof Fl?e.clone():e))),e}get length(){return this.doc??Nl(),null===this._prelimContent?this._length:this._prelimContent.length}createTreeWalker(e){return new mu(this,e)}querySelector(e){e=e.toUpperCase();const t=new mu(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),lr(new mu(this,(t=>t.nodeName&&t.nodeName.toUpperCase()===e)))}_callObserver(e,t){Il(this,e,new bu(this,t,e));}toString(){return Rl(this,(e=>e.toString())).join("")}toJSON(){return this.toString()}toDOM(e=document,t={},a){const i=e.createDocumentFragment();return void 0!==a&&a._createAssociation(i,this),Ll(this,(n=>{i.insertBefore(n.toDOM(e,t,a),null);})),i}insert(e,t){null!==this.doc?dl(this.doc,(a=>{jl(a,this,e,t);})):this._prelimContent.splice(e,0,...t);}insertAfter(e,t){if(null!==this.doc)dl(this.doc,(a=>{const i=e&&e instanceof Fl?e._item:e;Bl(a,this,i,t);}));else {const a=this._prelimContent,i=null===e?0:a.findIndex((t=>t===e))+1;if(0===i&&null!==e)throw Xr("Reference item not found");a.splice(i,0,...t);}}delete(e,t=1){null!==this.doc?dl(this.doc,(a=>{Ul(a,this,e,t);})):this._prelimContent.splice(e,t);}toArray(){return Dl(this)}push(e){this.insert(this.length,e);}unshift(e){this.insert(0,e);}get(e){return Ol(this,e)}slice(e=0,t=this.length){return El(this,e,t)}forEach(e){Ll(this,e);}_write(e){e.writeTypeRef(Ou);}}class gu extends yu{constructor(e="UNDEFINED"){super(),this.nodeName=e,this._prelimAttrs=new Map;}get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach(((e,t)=>{this.setAttribute(t,e);})),this._prelimAttrs=null;}_copy(){return new gu(this.nodeName)}clone(){const e=new gu(this.nodeName);return ((e,t)=>{for(const a in e)t(e[a],a);})(this.getAttributes(),((t,a)=>{"string"==typeof t&&e.setAttribute(a,t);})),e.insert(0,this.toArray().map((e=>e instanceof Fl?e.clone():e))),e}toString(){const e=this.getAttributes(),t=[],a=[];for(const t in e)a.push(t);a.sort();const i=a.length;for(let n=0;n<i;n++){const i=a[n];t.push(i+'="'+e[i]+'"');}const n=this.nodeName.toLocaleLowerCase();return `<${n}${t.length>0?" "+t.join(" "):""}>${super.toString()}</${n}>`}removeAttribute(e){null!==this.doc?dl(this.doc,(t=>{zl(t,this,e);})):this._prelimAttrs.delete(e);}setAttribute(e,t){null!==this.doc?dl(this.doc,(a=>{Wl(a,this,e,t);})):this._prelimAttrs.set(e,t);}getAttribute(e){return Yl(this,e)}hasAttribute(e){return Gl(this,e)}getAttributes(e){return e?((e,t)=>{const a={};return e._map.forEach(((e,i)=>{let n=e;for(;null!==n&&(!t.sv.has(n.id.client)||n.id.clock>=(t.sv.get(n.id.client)||0));)n=n.left;null!==n&&qo(n,t)&&(a[i]=n.content.getContent()[n.length-1]);})),a})(this,e):Hl(this)}toDOM(e=document,t={},a){const i=e.createElement(this.nodeName),n=this.getAttributes();for(const e in n){const t=n[e];"string"==typeof t&&i.setAttribute(e,t);}return Ll(this,(n=>{i.appendChild(n.toDOM(e,t,a));})),void 0!==a&&a._createAssociation(i,this),i}_write(e){e.writeTypeRef(Pu),e.writeKey(this.nodeName);}}class bu extends kl{constructor(e,t,a){super(e,a),this.childListChanged=false,this.attributesChanged=new Set,t.forEach((e=>{null===e?this.childListChanged=true:this.attributesChanged.add(e);}));}}class vu extends Xl{constructor(e){super(),this.hookName=e;}_copy(){return new vu(this.hookName)}clone(){const e=new vu(this.hookName);return this.forEach(((t,a)=>{e.set(a,t);})),e}toDOM(e=document,t={},a){const i=t[this.hookName];let n;return n=void 0!==i?i.createDom(this):document.createElement(this.hookName),n.setAttribute("data-yjs-hook",this.hookName),void 0!==a&&a._createAssociation(n,this),n}_write(e){e.writeTypeRef(Bu),e.writeKey(this.hookName);}}class _u extends fu{get nextSibling(){const e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){const e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new _u}clone(){const e=new _u;return e.applyDelta(this.toDelta()),e}toDOM(e=document,t,a){const i=e.createTextNode(this.toString());return void 0!==a&&a._createAssociation(i,this),i}toString(){return this.toDelta().map((e=>{const t=[];for(const a in e.attributes){const i=[];for(const t in e.attributes[a])i.push({key:t,value:e.attributes[a][t]});i.sort(((e,t)=>e.key<t.key?-1:1)),t.push({nodeName:a,attrs:i});}t.sort(((e,t)=>e.nodeName<t.nodeName?-1:1));let a="";for(let e=0;e<t.length;e++){const i=t[e];a+=`<${i.nodeName}`;for(let e=0;e<i.attrs.length;e++){const t=i.attrs[e];a+=` ${t.key}="${t.value}"`;}a+=">";}a+=e.insert;for(let e=t.length-1;e>=0;e--)a+=`</${t[e].nodeName}>`;return a})).join("")}toJSON(){return this.toString()}_write(e){e.writeTypeRef($u);}}class wu{constructor(e,t){this.id=e,this.length=t;}get deleted(){throw Qr()}mergeWith(e){return false}write(e,t,a){throw Qr()}integrate(e,t){throw Qr()}}class Au extends wu{get deleted(){return true}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,true)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),Qo(e.doc.store,this);}write(e,t){e.writeInfo(0),e.writeLen(this.length-t);}getMissing(e,t){return null}}class ku{constructor(e){this.content=e;}getLength(){return 1}getContent(){return [this.content]}isCountable(){return true}copy(){return new ku(this.content)}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content);}getRef(){return 3}}class Su{constructor(e){this.len=e;}getLength(){return this.len}getContent(){return []}isCountable(){return false}copy(){return new Su(this.len)}splice(e){const t=new Su(this.len-e);return this.len=e,t}mergeWith(e){return this.len+=e.len,true}integrate(e,t){bo(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted();}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t);}getRef(){return 1}}const Nu=(e,t)=>new So({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||false});class Tu{constructor(e){e._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=e;const t={};this.opts=t,e.gc||(t.gc=false),e.autoLoad&&(t.autoLoad=true),null!==e.meta&&(t.meta=e.meta);}getLength(){return 1}getContent(){return [this.doc]}isCountable(){return true}copy(){return new Tu(Nu(this.doc.guid,this.opts))}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc);}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc);}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts);}getRef(){return 9}}class Mu{constructor(e){this.embed=e;}getLength(){return 1}getContent(){return [this.embed]}isCountable(){return true}copy(){return new Mu(this.embed)}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed);}getRef(){return 5}}class xu{constructor(e,t){this.key=e,this.value=t;}getLength(){return 1}getContent(){return []}isCountable(){return false}copy(){return new xu(this.key,this.value)}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){const a=t.parent;a._searchMarker=null,a._hasFormatting=true;}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value);}getRef(){return 6}}class Vu{constructor(e){this.arr=e;}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return true}copy(){return new Vu(this.arr)}splice(e){const t=new Vu(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),true}integrate(e,t){}delete(e){}gc(e){}write(e,t){const a=this.arr.length;e.writeLen(a-t);for(let i=t;i<a;i++){const t=this.arr[i];e.writeString(void 0===t?"undefined":JSON.stringify(t));}}getRef(){return 2}}const Cu="development"===Us("node_env");class Iu{constructor(e){this.arr=e,Cu&&Es(e);}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return true}copy(){return new Iu(this.arr)}splice(e){const t=new Iu(this.arr.slice(e));return this.arr=this.arr.slice(0,e),t}mergeWith(e){return this.arr=this.arr.concat(e.arr),true}integrate(e,t){}delete(e){}gc(e){}write(e,t){const a=this.arr.length;e.writeLen(a-t);for(let i=t;i<a;i++){const t=this.arr[i];e.writeAny(t);}}getRef(){return 8}}class Fu{constructor(e){this.str=e;}getLength(){return this.str.length}getContent(){return this.str.split("")}isCountable(){return true}copy(){return new Fu(this.str)}splice(e){const t=new Fu(this.str.slice(e));this.str=this.str.slice(0,e);const a=this.str.charCodeAt(e-1);return a>=55296&&a<=56319&&(this.str=this.str.slice(0,e-1)+"�",t.str="�"+t.str.slice(1)),t}mergeWith(e){return this.str+=e.str,true}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(0===t?this.str:this.str.slice(t));}getRef(){return 4}}const Eu=[e=>new Jl,e=>new Xl,e=>new fu,e=>new gu(e.readKey()),e=>new yu,e=>new vu(e.readKey()),e=>new _u],Du=0,Lu=1,Ru=2,Pu=3,Ou=4,Bu=5,$u=6;class ju{constructor(e){this.type=e;}getLength(){return 1}getContent(){return [this.type]}isCountable(){return true}copy(){return new ju(this.type._copy())}splice(e){throw Qr()}mergeWith(e){return false}integrate(e,t){this.type._integrate(e.doc,t);}delete(e){let t=this.type._start;for(;null!==t;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach((t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e);})),e.changed.delete(this.type);}gc(e){let t=this.type._start;for(;null!==t;)t.gc(e,true),t=t.right;this.type._start=null,this.type._map.forEach((t=>{for(;null!==t;)t.gc(e,true),t=t.left;})),this.type._map=new Map;}write(e,t){this.type._write(e);}getRef(){return 7}}const Uu=(e,t,a)=>{const{client:i,clock:n}=t.id,r=new zu(Go(i,n+a),t,Go(i,n+a-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(a));return t.deleted&&r.markDeleted(),t.keep&&(r.keep=true),null!==t.redone&&(r.redone=Go(t.redone.client,t.redone.clock+a)),t.right=r,null!==r.right&&(r.right.left=r),e._mergeStructs.push(r),null!==r.parentSub&&null===r.right&&r.parent._map.set(r.parentSub,r),t.length=a,r};class zu extends wu{constructor(e,t,a,i,n,r,s,o){super(e,o.getLength()),this.origin=a,this.left=t,this.right=i,this.rightOrigin=n,this.parent=r,this.parentSub=s,this.redone=null,this.content=o,this.info=this.content.isCountable()?2:0;}set marker(e){(8&this.info)>0!==e&&(this.info^=8);}get marker(){return (8&this.info)>0}get keep(){return (1&this.info)>0}set keep(e){this.keep!==e&&(this.info^=1);}get countable(){return (2&this.info)>0}get deleted(){return (4&this.info)>0}set deleted(e){this.deleted!==e&&(this.info^=4);}markDeleted(){this.info|=4;}getMissing(e,t){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=Xo(t,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=Xo(t,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Yo&&this.id.client!==this.parent.client&&this.parent.clock>=Xo(t,this.parent.client))return this.parent.client;if(this.origin&&(this.left=nl(e,t,this.origin),this.origin=this.left.lastId),this.rightOrigin&&(this.right=il(e,this.rightOrigin),this.rightOrigin=this.right.id),this.left&&this.left.constructor===Au||this.right&&this.right.constructor===Au)this.parent=null;else if(this.parent){if(this.parent.constructor===Yo){const e=tl(t,this.parent);e.constructor===Au?this.parent=null:this.parent=e.content.type;}}else this.left&&this.left.constructor===zu?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===zu&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=nl(e,e.doc.store,Go(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||null!==this.right.left)||this.left&&this.left.right!==this.right){let t,a=this.left;if(null!==a)t=a.right;else if(null!==this.parentSub)for(t=this.parent._map.get(this.parentSub)||null;null!==t&&null!==t.left;)t=t.left;else t=this.parent._start;const i=new Set,n=new Set;for(;null!==t&&t!==this.right;){if(n.add(t),i.add(t),Ho(this.origin,t.origin)){if(t.id.client<this.id.client)a=t,i.clear();else if(Ho(this.rightOrigin,t.rightOrigin))break}else {if(null===t.origin||!n.has(tl(e.doc.store,t.origin)))break;i.has(tl(e.doc.store,t.origin))||(a=t,i.clear());}t=t.right;}this.left=a;}if(null!==this.left){const e=this.left.right;this.right=e,this.left.right=this;}else {let e;if(null!==this.parentSub)for(e=this.parent._map.get(this.parentSub)||null;null!==e&&null!==e.left;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e;}null!==this.right?this.right.left=this:null!==this.parentSub&&(this.parent._map.set(this.parentSub,this),null!==this.left&&this.left.delete(e)),null===this.parentSub&&this.countable&&!this.deleted&&(this.parent._length+=this.length),Qo(e.doc.store,this),this.content.integrate(e,this),ll(e,this.parent,this.parentSub),(null!==this.parent._item&&this.parent._item.deleted||null!==this.parentSub&&null!==this.right)&&this.delete(e);}else new Au(this.id,this.length).integrate(e,0);}get next(){let e=this.right;for(;null!==e&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;null!==e&&e.deleted;)e=e.left;return e}get lastId(){return 1===this.length?this.id:Go(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&Ho(e.origin,this.lastId)&&this.right===e&&Ho(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&null===this.redone&&null===e.redone&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){const t=this.parent._searchMarker;return t&&t.forEach((t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length));})),e.keep&&(this.keep=true),this.right=e.right,null!==this.right&&(this.right.left=this),this.length+=e.length,true}return false}delete(e){if(!this.deleted){const t=this.parent;this.countable&&null===this.parentSub&&(t._length-=this.length),this.markDeleted(),bo(e.deleteSet,this.id.client,this.id.clock,this.length),ll(e,t,this.parentSub),this.content.delete(e);}}gc(e,t){if(!this.deleted)throw es();this.content.gc(e),t?((e,t,a)=>{const i=e.clients.get(t.id.client);i[el(i,t.id.clock)]=a;})(e,this,new Au(this.id,this.length)):this.content=new Su(this.length);}write(e,t){const a=t>0?Go(this.id.client,this.id.clock+t-1):this.origin,i=this.rightOrigin,n=this.parentSub,r=31&this.content.getRef()|(null===a?0:vr)|(null===i?0:br)|(null===n?0:32);if(e.writeInfo(r),null!==a&&e.writeLeftID(a),null!==i&&e.writeRightID(i),null===a&&null===i){const t=this.parent;if(void 0!==t._item){const a=t._item;if(null===a){const a=(e=>{for(const[t,a]of e.doc.share.entries())if(a===e)return t;throw es()})(t);e.writeParentInfo(true),e.writeString(a);}else e.writeParentInfo(false),e.writeLeftID(a.id);}else t.constructor===String?(e.writeParentInfo(true),e.writeString(t)):t.constructor===Yo?(e.writeParentInfo(false),e.writeLeftID(t)):es();null!==n&&e.writeString(n);}this.content.write(e,t);}}const Wu=(e,t)=>Yu[31&t](e),Yu=[()=>{es();},e=>new Su(e.readLen()),e=>{const t=e.readLen(),a=[];for(let i=0;i<t;i++){const t=e.readString();"undefined"===t?a.push(void 0):a.push(JSON.parse(t));}return new Vu(a)},e=>new ku(e.readBuf()),e=>new Fu(e.readString()),e=>new Mu(e.readJSON()),e=>new xu(e.readKey(),e.readJSON()),e=>new ju(Eu[e.readTypeRef()](e)),e=>{const t=e.readLen(),a=[];for(let i=0;i<t;i++)a.push(e.readAny());return new Iu(a)},e=>new Tu(Nu(e.readString(),e.readAny())),()=>{es();}];class Hu extends wu{get deleted(){return true}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,true)}integrate(e,t){es();}write(e,t){e.writeInfo(10),Rr(e.restEncoder,this.length-t);}getMissing(e,t){return null}}const Gu="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},qu="__ $YJS$ __";true===Gu[qu]&&console.error("Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438"),Gu[qu]=true;const Zu=new Map;const Ju="undefined"==typeof BroadcastChannel?class{constructor(e){var t;this.room=e,this.onmessage=null,this._onChange=t=>t.key===e&&null!==this.onmessage&&this.onmessage({data:qs(t.newValue||"")}),t=this._onChange,Ns||addEventListener("storage",t);}postMessage(e){Ts.setItem(this.room,Gs(new Uint8Array(e)));}close(){var e;e=this._onChange,Ns||removeEventListener("storage",e);}}:BroadcastChannel,Ku=e=>nr(Zu,e,(()=>{const t=rr(),a=new Ju(e);return a.onmessage=e=>t.forEach((t=>t(e.data,"broadcastchannel"))),{bc:a,subs:t}})),Xu=(e,t,a=null)=>{const i=Ku(e);i.bc.postMessage(t),i.subs.forEach((e=>e(t,a)));},Qu=(e,t)=>{Rr(e,0);const a=(e=>Bo(e,new Vo))(t);Ur(e,a);},ec$2=(e,t,a)=>{Rr(e,1),Ur(e,((e,t)=>Ro(e,t,new Co))(t,a));},tc=(e,t,a)=>{try{((e,t,a)=>{Lo(e,t,a,To);})(t,rs(e),a);}catch(e){console.error("Caught error while handling a Yjs update",e);}},ac=tc,ic=(e,t,a,i)=>{const n=os(e);switch(n){case 0:((e,t,a)=>{ec$2(t,a,rs(e));})(e,t,a);break;case 1:tc(e,a,i);break;case 2:ac(e,a,i);break;default:throw new Error("Unknown message type")}return n},nc=3e4;class rc extends dr{constructor(e){super(),this.doc=e,this.clientID=e.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval((()=>{const e=ws();null!==this.getLocalState()&&15e3<=e-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());const t=[];this.meta.forEach(((a,i)=>{i!==this.clientID&&nc<=e-a.lastUpdated&&this.states.has(i)&&t.push(i);})),t.length>0&&sc(this,t,"timeout");}),pr(3e3)),e.on("destroy",(()=>{this.destroy();})),this.setLocalState({});}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval);}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(e){const t=this.clientID,a=this.meta.get(t),i=void 0===a?0:a.clock+1,n=this.states.get(t);null===e?this.states.delete(t):this.states.set(t,e),this.meta.set(t,{clock:i,lastUpdated:ws()});const r=[],s=[],o=[],l=[];null===e?l.push(t):null==n?null!=e&&r.push(t):(s.push(t),Ps(n,e)||o.push(t)),(r.length>0||o.length>0||l.length>0)&&this.emit("change",[{added:r,updated:o,removed:l},"local"]),this.emit("update",[{added:r,updated:s,removed:l},"local"]);}setLocalStateField(e,t){const a=this.getLocalState();null!==a&&this.setLocalState({...a,[e]:t});}getStates(){return this.states}}const sc=(e,t,a)=>{const i=[];for(let a=0;a<t.length;a++){const n=t[a];if(e.states.has(n)){if(e.states.delete(n),n===e.clientID){const t=e.meta.get(n);e.meta.set(n,{clock:t.clock+1,lastUpdated:ws()});}i.push(n);}}i.length>0&&(e.emit("change",[{added:[],updated:[],removed:i},a]),e.emit("update",[{added:[],updated:[],removed:i},a]));},oc=(e,t,a=e.states)=>{const i=t.length,n=Ir();Rr(n,i);for(let r=0;r<i;r++){const i=t[r],s=a.get(i)||null,o=e.meta.get(i).clock;Rr(n,i),Rr(n,o),$r(n,JSON.stringify(s));}return Er(n)},lc=[];lc[0]=(e,t,a,i,n)=>{Rr(e,0);const r=ic(t,e,a.doc,a);i&&1===r&&!a.synced&&(a.synced=true);},lc[3]=(e,t,a,i,n)=>{Rr(e,1),Ur(e,oc(a.awareness,Array.from(a.awareness.getStates().keys())));},lc[1]=(e,t,a,i,n)=>{((e,t,a)=>{const i=ns(t),n=ws(),r=[],s=[],o=[],l=[],u=os(i);for(let t=0;t<u;t++){const t=os(i);let a=os(i);const u=JSON.parse(us(i)),c=e.meta.get(t),d=e.states.get(t),p=void 0===c?0:c.clock;(p<a||p===a&&null===u&&e.states.has(t))&&(null===u?t===e.clientID&&null!=e.getLocalState()?a++:e.states.delete(t):e.states.set(t,u),e.meta.set(t,{clock:a,lastUpdated:n}),void 0===c&&null!==u?r.push(t):void 0!==c&&null===u?l.push(t):null!==u&&(Ps(u,d)||o.push(t),s.push(t)));}(r.length>0||o.length>0||l.length>0)&&e.emit("change",[{added:r,updated:o,removed:l},a]),(r.length>0||s.length>0||l.length>0)&&e.emit("update",[{added:r,updated:s,removed:l},a]);})(a.awareness,rs(t),a);},lc[2]=(e,t,a,i,n)=>{((e,t,a)=>{0===os(e)&&a(t,us(e));})(t,a.doc,((e,t)=>uc(a,t)));};const uc=(e,t)=>console.warn(`Permission denied to access ${e.url}.\n${t}`),cc=(e,t,a)=>{const i=ns(t),n=Ir(),r=os(i),s=e.messageHandlers[r];return s?s(n,i,e,a,r):console.error("Unable to compute message"),n},dc=(e,t,a)=>{t===e.ws&&(e.emit("connection-close",[a,e]),e.ws=null,t.close(),e.wsconnecting=false,e.wsconnected?(e.wsconnected=false,e.synced=false,sc(e.awareness,Array.from(e.awareness.getStates().keys()).filter((t=>t!==e.doc.clientID)),e),e.emit("status",[{status:"disconnected"}])):e.wsUnsuccessfulReconnects++,setTimeout(pc,fr(100*yr(2,e.wsUnsuccessfulReconnects),e.maxBackoffTime),e));},pc=e=>{if(e.shouldConnect&&null===e.ws){const t=new e._WS(e.url,e.protocols);t.binaryType="arraybuffer",e.ws=t,e.wsconnecting=true,e.wsconnected=false,e.synced=false,t.onmessage=a=>{e.wsLastMessageReceived=ws();const i=cc(e,new Uint8Array(a.data),true);Fr(i)>1&&t.send(Er(i));},t.onerror=t=>{e.emit("connection-error",[t,e]);},t.onclose=a=>{dc(e,t,a);},t.onopen=()=>{e.wsLastMessageReceived=ws(),e.wsconnecting=false,e.wsconnected=true,e.wsUnsuccessfulReconnects=0,e.emit("status",[{status:"connected"}]);const a=Ir();if(Rr(a,0),Qu(a,e.doc),t.send(Er(a)),null!==e.awareness.getLocalState()){const a=Ir();Rr(a,1),Ur(a,oc(e.awareness,[e.doc.clientID])),t.send(Er(a));}},e.emit("status",[{status:"connecting"}]);}},hc=(e,t)=>{const a=e.ws;e.wsconnected&&a&&a.readyState===a.OPEN&&a.send(t),e.bcconnected&&Xu(e.bcChannel,t,e);};class fc extends cr{constructor(e,t,a,{connect:i=true,awareness:n=new rc(a),params:r={},protocols:s=[],WebSocketPolyfill:o=WebSocket,resyncInterval:l=-1,maxBackoffTime:u=2500,disableBc:c=false}={}){for(super();"/"===e[e.length-1];)e=e.slice(0,e.length-1);this.serverUrl=e,this.bcChannel=e+"/"+t,this.maxBackoffTime=u,this.params=r,this.protocols=s,this.roomname=t,this.doc=a,this._WS=o,this.awareness=n,this.wsconnected=false,this.wsconnecting=false,this.bcconnected=false,this.disableBc=c,this.wsUnsuccessfulReconnects=0,this.messageHandlers=lc.slice(),this._synced=false,this.ws=null,this.wsLastMessageReceived=0,this.shouldConnect=i,this._resyncInterval=0,l>0&&(this._resyncInterval=setInterval((()=>{if(this.ws&&this.ws.readyState===WebSocket.OPEN){const e=Ir();Rr(e,0),Qu(e,a),this.ws.send(Er(e));}}),l)),this._bcSubscriber=(e,t)=>{if(t!==this){const t=cc(this,new Uint8Array(e),false);Fr(t)>1&&Xu(this.bcChannel,Er(t),this);}},this._updateHandler=(e,t)=>{if(t!==this){const t=Ir();Rr(t,0),((e,t)=>{Rr(e,2),Ur(e,t);})(t,e),hc(this,Er(t));}},this.doc.on("update",this._updateHandler),this._awarenessUpdateHandler=({added:e,updated:t,removed:a},i)=>{const r=e.concat(t).concat(a),s=Ir();Rr(s,1),Ur(s,oc(n,r)),hc(this,Er(s));},this._exitHandler=()=>{sc(this.awareness,[a.clientID],"app closed");},Os&&"undefined"!=typeof process&&process.on("exit",this._exitHandler),n.on("update",this._awarenessUpdateHandler),this._checkInterval=setInterval((()=>{this.wsconnected&&3e4<ws()-this.wsLastMessageReceived&&dc(this,this.ws,null);}),3e3),i&&this.connect();}get url(){const e=(e=>((e,t)=>{const a=[];for(const i in e)a.push(t(e[i],i));return a})(e,((e,t)=>`${encodeURIComponent(t)}=${encodeURIComponent(e)}`)).join("&"))(this.params);return this.serverUrl+"/"+this.roomname+(0===e.length?"":"?"+e)}get synced(){return this._synced}set synced(e){this._synced!==e&&(this._synced=e,this.emit("synced",[e]),this.emit("sync",[e]));}destroy(){0!==this._resyncInterval&&clearInterval(this._resyncInterval),clearInterval(this._checkInterval),this.disconnect(),Os&&"undefined"!=typeof process&&process.off("exit",this._exitHandler),this.awareness.off("update",this._awarenessUpdateHandler),this.doc.off("update",this._updateHandler),super.destroy();}connectBc(){if(this.disableBc)return;var e,t;this.bcconnected||(e=this.bcChannel,t=this._bcSubscriber,Ku(e).subs.add(t),this.bcconnected=true);const a=Ir();Rr(a,0),Qu(a,this.doc),Xu(this.bcChannel,Er(a),this);const i=Ir();Rr(i,0),ec$2(i,this.doc),Xu(this.bcChannel,Er(i),this);const n=Ir();Rr(n,3),Xu(this.bcChannel,Er(n),this);const r=Ir();Rr(r,1),Ur(r,oc(this.awareness,[this.doc.clientID])),Xu(this.bcChannel,Er(r),this);}disconnectBc(){const e=Ir();Rr(e,1),Ur(e,oc(this.awareness,[this.doc.clientID],new Map)),hc(this,Er(e)),this.bcconnected&&(((e,t)=>{const a=Ku(e),i=a.subs.delete(t);i&&0===a.subs.size&&(a.bc.close(),Zu.delete(e));})(this.bcChannel,this._bcSubscriber),this.bcconnected=false);}disconnect(){this.shouldConnect=false,this.disconnectBc(),null!==this.ws&&dc(this,this.ws,null);}connect(){this.shouldConnect=true,this.wsconnected||null!==this.ws||(pc(this),this.connectBc());}}class mc extends So{}class yc{apiClient;collabDocument;yWebsocketProvider;item;awareness;users=[];avatars=new Map;constructor(e){this.apiClient=e,this.collabDocument=new mc;}isActive(){return void 0!==this.yWebsocketProvider}getAwarenessStates(){return this.awareness?this.awareness.getStates():new Map}getUsersList(){return this.users}_getUser(e){for(const t of this.users)if(e===t.key)return t;return null}getLocalState(){if(!this.awareness)throw new Error("No awareness available. Cannot get state field.");return this.awareness.getLocalState()}setLocalStateField(e,t){if(!this.awareness)throw new Error("No awareness available. Cannot set state field.");this.awareness.setLocalStateField(e,t);}async _updateUsersList(){const e=this.getAwarenessStates(),t=await this.apiClient.me(true);for(const[a,i]of e.entries()){if(!this._getUser(a)){let e=this.avatars.get(i.user.id);if(!e){e=(await this.apiClient.getAvatar(i.user.id,32)).avatar,this.avatars.set(i.user.id,e);}this.users.push({key:a,id:i.user.id,name:i.user.name,color:i.user.color,avatar:e,itsMe:i.user.id===t._id});}}const a=[];for(const t of this.users)e.has(t.key)&&a.push(t);this.users=a;}async startCollaboration(e){try{if(!this.apiClient.isDevOrLocalhost())return !1;this.endCollaboration(),this.item=e;const t=this.apiClient.getCollabUrl(),a=`${this.item.type}.${this.item._id}`;let i=1e3;this.yWebsocketProvider=new fc(t,a,this.collabDocument,{connect:!1}),this.yWebsocketProvider.on("status",(e=>{console.log(`[Collab] ${e.status}`),"disconnected"===e.status&&this.yWebsocketProvider&&(this.yWebsocketProvider.disconnect(),setTimeout(r,i));})),this.yWebsocketProvider.on("sync",(e=>{console.log(`[Collab] synced: ${e}`);})),this.awareness=this.yWebsocketProvider.awareness,this.awareness.on("change",(async e=>{await this._updateUsersList(),u$3.$emit("collab:awareness:changed",{users:this.users,states:this.getAwarenessStates(),changes:e});}));const n=await this.apiClient.me(!0);this.awareness.setLocalStateField("user",{id:n._id,name:n.name,color:h$2.colorFromString(n.name)});const r=async()=>{if(!this.yWebsocketProvider)return void console.warn("[Collab] Cannot connect without websocket provider!");console.log("[Collab] reconnecting...");const e=await this.apiClient.getCollabToken();this.yWebsocketProvider.params.token=e,this.yWebsocketProvider.connect();};return await r(),u$3.$emit("collab:started"),!0}catch(e){return console.error("Error starting collaboration: ",e),false}}endCollaboration(){this.yWebsocketProvider&&(console.log("Ending collaboration."),u$3.$emit("collab:ended"),this.yWebsocketProvider.destroy(),this.yWebsocketProvider=void 0,this.awareness=void 0),this.collabDocument=new mc,this.item=void 0;}}class gc{apiClient;constructor(e){this.apiClient=e;}async testCopyItems(e,t){const a=await this.apiClient.getItemsInFolderList(t,true),i=await this.apiClient.getFoldersInFolderList(t),n=new Map;for(const e of i.children)n.set(e.name,null);for(const e of a)n.set(e.name,e._id);const r=this.apiClient.getItemRepo(),s=[];for(const t of e){let e,a,i=false;t.isFolder?a=await this.apiClient.getFolder(t._id):(a=r.getLoadedItem(t._id),a||(a=await this.apiClient.getItem(t._id))),e=a?.name,i=n.has(e),s.push({_id:t._id,isFolder:t.isFolder,data:a,name:e,conflicted:i,conflictedItemId:n.get(e)});}return s}async copyItems(e,t,a=false,i=false){const n=e.filter((e=>!e.isFolder)).map((e=>e._id)),r=await this.apiClient.copyItems(n,t,a,i),s=this.apiClient.getItemRepo();for(let t of r){const a=e.filter((e=>e._id===t.original));a.length>0&&(t.replaced=a[0].conflictedItemId),await s.replaceLink(t.original,t.clone);}return await this.apiClient.eventBus.$emit("folder:changed",t),await this.apiClient.eventBus.$emit("items:copied",r),r}}class bc{apiClient;jobManager;constructor(e){this.apiClient=e,this.jobManager=e.getJobManager();}async executeExport(e,t,a,i){const n=await this.jobManager.execute("EXPORT:ExportGame",[{_id:e,isFolder:false}],[{name:"Destination Folder",value:a},{name:"EngineVersion",value:i}],void 0,{os:t});if(await this.apiClient.eventBus.$emit("quota:update"),2===n.state)throw new N$1("Export failed: "+n.error);await this.apiClient.eventBus.$emit("folder:changed",[a]);}}(axiosRetry.default?axiosRetry.default:axiosRetry)(axios,{retries:3,retryCondition:e=>e.message.includes("net::ERR_NETWORK_CHANGED")});const vc={Draft:0,Private:1,NotListed:2,Public:3},_c=[{id:"prod",name:"Production",ssl:true,apiHost:"api.lumino.cloud",viewerHost:"viewer.lumino.cloud",collabHost:"collab.lumino.cloud"},{id:"dev",name:"Development",ssl:true,apiHost:"api-dev.lumino.cloud",viewerHost:"viewer-dev.lumino.cloud",collabHost:"collab-dev.lumino.cloud"},{id:"local",name:"Local",ssl:false,apiHost:"localhost:8081",viewerHost:"localhost:8090",collabHost:"localhost:8200"}];class wc extends l$2{accessToken;apiToken;options;forcePublicApi;usePublicApi;usePersistentStorage;storageSizeMib;requestClientId;apiUrl;wsUrl;viewerUrl;collabUrl;itemRepo;itemCache;folderCache;thumbCache;userCache;groupCache;attachmentCache;jobManager;serializer;collab;itemCopier;executableExporter;eventBus;env;api;ws=null;cachedMe;profiler;wsLastPing=null;last2faCode="";constructor(e={}){super(),e=e||{},this.options=Object.assign({environment:"auto",wsAutoReconnect:true,wsAutoConnect:false,forcePublicApi:false,debug:false,accessToken:null,apiToken:null,usePersistentStorage:true,storageSizeMib:10240,requestClientId:null},e),this.accessToken=this.options.accessToken,this.apiToken=this.options.apiToken,this.forcePublicApi=this.options.forcePublicApi,this.usePublicApi=!this.accessToken&&!this.apiToken,this.usePersistentStorage=this.options.usePersistentStorage,this.storageSizeMib=this.options.storageSizeMib,this.requestClientId=this.options.requestClientId,this.cachedMe=null,this.itemRepo=new Zi(this.usePublicApi,this),this.itemCache=new jn(this.usePublicApi,this.usePersistentStorage,this,this.storageSizeMib),this.folderCache=new Un$1(this),this.thumbCache=new zn(this),this.userCache=new Wn(this),this.groupCache=new Yn(this),this.attachmentCache=new Hn(this),this.jobManager=new Zn(this),this.serializer=new tr(this),this.collab=new yc(this),this.itemCopier=new gc(this),this.executableExporter=new bc(this),this.eventBus=u$3,this.profiler=null,this.switchEnvironment(this.options.environment),this.setDebugMode(this.options.debug);}detectEnvironment(){const e=this.isOnLocalhost(),t=this.isDevPlatform();return e?this.getEnvironmentById("local"):t?this.getEnvironmentById("dev"):this.getEnvironmentById("prod")}getEnvironmentById(e){return "auto"===e?this.detectEnvironment():_c.find((t=>t.id===e))}getEnvironments(){return _c}switchEnvironment(e){let a=this.getEnvironmentById(e);if(!a)throw new Error(`Unknown environment: ${e}`);console.log(`ApiClient switched to env: ${a.name}`);const i=a.ssl?"https":"http",n=a.ssl?"wss":"ws";this.apiUrl=`${i}://${a.apiHost}`,this.wsUrl=`${n}://${a.apiHost}/api/ws`,this.viewerUrl=`${i}://${a.viewerHost}`,this.collabUrl=`${i}://${a.collabHost}`,this.api=axios.create({baseURL:this.apiUrl}),this.ws=null,this.wsLastPing=null;}async initCaches(){return Promise.all([this.itemCache.init(),this.folderCache.init(),this.thumbCache.init()])}clearCaches(){this.itemCache.clear(),this.folderCache.clear(),this.thumbCache.clear();}isDevPlatform(){return "object"==typeof window&&"location"in window&&(window.location.href.includes("dev.lumino.cloud")||window.location.href.includes("taste.lemonate.io"))}isOnLocalhost(){return "object"==typeof window&&"location"in window&&window.location.href.includes("localhost")}isDevOrLocalhost(){return this.isOnLocalhost()||this.isDevPlatform()}async clearIndexedDb(e){return new Promise(((t,a)=>{const i=indexedDB.deleteDatabase(e);i.onsuccess=()=>{t();},i.onerror=e=>{a("An error occured while deleting a IndexedDB database.");},i.onblocked=()=>{a(`Database deletion is blocked. Please close all connections to "${e}".`);};}))}async logout(){return this.clearCaches(),this.clearIndexedDb("lumino")}setDebugMode(e){this.options.debug=!!e,this.eventBus.setDebugMode(this.options.debug);}websocketConnect(e){const t=this;if(this.ws){if(!e)return void console.warn("Websocket is already connected!");this.websocketDisconnect();}this.ws=new i$4(this.wsUrl),this.ws.onerror=function(e){console.error("Websocket error",e),t.$emit("client:websocketError",e);},this.ws.onopen=function(){t.$emit("client:websocketOpen"),t.accessToken&&t.websocketSend(JSON.stringify({type:"auth",subscriptions:["item","folder","job","user","notification"],token:t.accessToken}));},this.ws.onclose=function(){t.$emit("client:websocketClosed"),t.options.wsAutoReconnect&&t.websocketConnect(true);},this.ws.onmessage=function(e){try{const a=JSON.parse(e.data);switch(a.type){case "ping":t.wsLastPing=new Date,t.ws&&t.ws.send(JSON.stringify({type:"ping"}));break;case "authenticated":t.$emit("client:websocketAuthenticated");break;case "Item":case "Folder":case "Notification":case "Job":case "User":u$3.$emit("client:elementUpdate",a);break;default:console.warn("Unknown websocket message: ",a);}}catch(e){console.error("Websocket error:",e);}};}websocketDisconnect(){this.ws&&(this.ws.close(),this.ws=null);}websocketSend(e){this.ws?1===this.ws.readyState?this.ws.send(e):console.error("Websocket is not in READY state. Currently in state "+this.ws.readyState):console.error("Websocket is not created");}getItemCopier(){return this.itemCopier}getExecutableExporter(){return this.executableExporter}getCollab(){return this.collab}getCollabUrl(){return this.collabUrl}getPublisher(){return new Gn(this)}getAssetCreator(){return new er(this)}getJobManager(){return this.jobManager}getThumbCache(){return this.thumbCache}getItemCache(){return this.itemCache}getItemRepo(){return this.itemRepo}getRootVisibility(){return this.itemRepo.activeItem?this.itemRepo.activeItem.visibility:vc.Private}getEventBus(){return this.eventBus}getSerializer(){return this.serializer}setForcePublicApi(e){this.forcePublicApi=e,this._updateUsePublicApi();}_updateUsePublicApi(){this.usePublicApi=this.forcePublicApi||!this.apiToken&&!this.accessToken,this.itemRepo.usePublicApi=this.usePublicApi,this.itemCache.usePublicApi=this.usePublicApi;}setApiToken(e){this.apiToken=e,this._updateUsePublicApi();}setAccessToken(e){this.accessToken=e,this._updateUsePublicApi(),this.accessToken&&this.options.wsAutoConnect&&this.websocketConnect();}getApiToken(){return this.apiToken}getAccessToken(){return this.accessToken}setApiBaseUrl(e){this.apiUrl=e,this.api=axios.create({baseURL:this.apiUrl});}setWsBaseUrl(e){this.wsUrl=e,this.accessToken&&this.options.wsAutoConnect&&(this.websocketDisconnect(),this.websocketConnect());}setRequestClientId(e){this.requestClientId=e;}getApiBaseUrl(){return this.apiUrl}getWsBaseUrl(){return this.wsUrl}getViewerBaseUrl(){return this.viewerUrl}setProfiler(e){if(!e||"function"!=typeof e.start)throw new Error("Profiler needs to be an object providing a start function.");this.profiler=e;}async login2FA(e,t,a){return console.log("Running Login..."),this.execute("post","/api/auth/login2fa",{account:e,password:t,client:a}).then((e=>{this.last2faCode=e,this.eventBus.$emit("login.2facode",e);}))}async confirm2FA(e,t){return this.execute("post","/api/auth/confirm2fa",{account:e,code:t})}isAuthenticated(){return !!this.accessToken||!!this.apiToken}isFeatureEnabled(e){return !!this.cachedMe&&this.cachedMe.features.includes(e)}async resolveUserOrGroupInfoForItem(e){return e.quotaUser?this.userCache.resolve(e.quotaUser):e.quotaGroup?this.groupCache.resolve(e.quotaGroup):e.createdBy?this.userCache.resolve(e.createdBy):{name:"?",initials:"?",avatar:null}}_startOp(e){const t=this,a={id:h$2.createGUID(),name:e,startTimeMs:performance.now(),runningMs:0,percent:0,reportProgress:function(e){a.percent=e;},interval:null,finish:function(){if(a.interval&&clearInterval(a.interval),a.runningMs>1e3)try{t.$emit("client:longRunningOpFinished",a.id);}catch(e){console.error(e);}}};return a.interval=setInterval((function(){if(a.runningMs=performance.now()-a.startTimeMs,a.runningMs>1e3)try{t.$emit("client:longRunningOp",a.id,a.name,a.percent);}catch(e){console.error(e);}}),100),a}_createOpName(e,t){try{const a=t.split("/");switch(e.toLowerCase()){case "get":e="Fetching";break;case "post":e="Creating";break;case "put":e="Updating";break;case "delete":e="Deleting";}a.shift(),a.shift();const i=a.shift();let n=a.join("/");return n.length&&(n=` [${n}]`),`${e} ${i} data ${n}`}catch{return `${e} ${t}`}}addAuthenticationHeaders(e){this.accessToken&&(e["x-access-token"]=this.accessToken),this.apiToken&&(e["x-api-token"]=this.apiToken),this.requestClientId&&(e["x-request-client"]=this.requestClientId);}async execute(e,t,a,i){let n=this,r={};(i=i||{}).headers?r=i.headers:a&&"object"==typeof a&&"getHeaders"in a&&"function"==typeof a.getHeaders&&(r=a.getHeaders()),this.addAuthenticationHeaders(r);const s=this.profiler?this.profiler.start("ApiClient",`${e} ${t}`):null,o=this._startOp(i.opName||n._createOpName(e,t));return this.api({method:e,url:t,data:a,responseType:i.responseType,headers:r,signal:i.controller?i.controller.signal:void 0,onUploadProgress:function(e){if(e.total){const t=Math.min(100,Math.round(100*e.loaded/e.total));o.reportProgress(t),n.$emit("client:progress",{type:"upload",percent:t}),"function"==typeof i.progressCallback&&i.progressCallback(t,e.loaded,e.total);}},onDownloadProgress:function(e){if(e.total){const t=Math.min(100,Math.round(100*e.loaded/e.total));o.reportProgress(t),n.$emit("client:progress",{type:"download",percent:t}),"function"==typeof i.progressCallback&&i.progressCallback(t,e.loaded,e.total);}}}).then((e=>{if(s&&s.done(),o.finish(),n.$emit("client:progress",{type:"done"}),e.headers["content-type"].startsWith("application/json")){if("success"===e.data.result){let t;return t=i.withNext?{data:e.data.data,next:e.data.next}:e.data.data,i.emitOnSuccess&&this.eventBus.$emit(i.emitOnSuccess,t),t}throw e.data.redirect&&this.$emit("client:redirect",e.data.redirect),e.data.error?e.data.error:"API response seems to be json but does not contain result type!"}return i.emitOnSuccess&&this.eventBus.$emit(i.emitOnSuccess),{blob:new Blob([e.data],{type:e.headers["content-type"]}),hash:e.headers["sha256-hash"],itemName:e.headers["lumino-itemname"],itemType:e.headers["lumino-itemtype"],mimeType:e.headers["content-type"]}})).catch((e=>{if(s&&s.done(),o.finish(),n.$emit("client:progress",{type:"done"}),e.response){if(401===e.response.status)throw this.$emit("client:unauthorized"),new x$4("Access denied. Please login again.");if(413===e.response.status)throw new M$1;if(e.response.data&&e.response.data.error)throw new Error(e.response.data.error)}throw e}))}_createFormData(e,t){let a=new n$3;if("function"==typeof File&&e instanceof Blob)a.append("file",e,t);else {const i=new Blob([e]);try{a.append("file",i,t);}catch{a=new n$3,a.append("file",e,t);}}return a}async me(e){return e&&this.cachedMe||(this.cachedMe=await this.execute("get","/api/auth/me")),this.cachedMe}async getHomeFolder(){return this.execute("get","/api/auth/homefolder")}async myClients(){return this.execute("get","/api/auth/myclients")}async getCollabToken(){return this.execute("get","/api/auth/collabtoken")}async checkCollabToken(e){return this.execute("post","/api/auth/collabtoken",{token:e})}async register(e){return this.execute("post","/api/auth/register",e)}async deleteMyAccount(e){return this.execute("post","/api/auth/deletemyaccount",{password:e})}async confirmEmail(e){return this.execute("get","/api/auth/confirmemail/"+e)}async confirmEmailChange(e){return this.execute("get","/api/auth/confirmchangedemail/"+e)}async forgotPassword(e,t){return this.execute("post","/api/auth/forgotpassword",{account:e,client:t})}async setNewPassword(e,t){return this.execute("post","/api/auth/setnewpassword",{token:e,password:t})}async accountExists(e){return this.execute("post","/api/auth/accountExists",e)}async getItemsInFolderList(e,t=false){if(e&&!t){const t=await this.folderCache.getItemListing(e);if(t)return t}const a=await this.execute("get","/api/item/infolder/"+(e||"0"));return await this.folderCache.addItemListing(e,a),a}async getItem(e,t){const a=[];t&&(t.returnClonedFrom&&a.push("returnClonedFrom=true"),t.withThumbnails&&a.push("withThumbnails=true"));let i="";return a.length&&(i=`?${a.join("&")}`),this.execute("get",`/api/item/${e}${i}`)}getItemAggregatedPOP(e,t){return this.usePublicApi?this.getItemPublicAggregated(e,t):this.getItemAggregated(e,t)}async getItemPublicAggregated(e,t){const a=Bi(e);if(a)return a;const i=[];t&&(t.withFieldInstances&&i.push("withFieldInstances"),t.withAttachmentInfo&&i.push("withAttachmentInfo"),t.noAttributes&&i.push("noAttributes"),t.noUserAttributes&&i.push("noUserAttributes"),t.noFields&&i.push("noFields"),t.noThumbnails&&i.push("noThumbnails"),t.noLinks&&i.push("noLinks"));let n="";return i.length&&(n=`?${i.join("&")}`),Bi(e)?Bi(e):this.execute("get","/api/item/publicaggregate/"+e+n)}async getItemAggregated(e,t){const a=Bi(e);if(a)return a;const i=[];t&&(t.withFieldInstances&&i.push("withFieldInstances"),t.withAttachmentInfo&&i.push("withAttachmentInfo"),t.noAttributes&&i.push("noAttributes"),t.noUserAttributes&&i.push("noUserAttributes"),t.noFields&&i.push("noFields"),t.noThumbnails&&i.push("noThumbnails"),t.noLinks&&i.push("noLinks"));let n="";return i.length&&(n=`?${i.join("&")}`),Bi(e)?Bi(e):this.execute("get",`/api/item/aggregate/${e}${n}`)}async getItemAggregatedRecursive(e,t){const a=[];t&&(t.withFieldInstances&&a.push("withFieldInstances"),t.withAttachmentInfo&&a.push("withAttachmentInfo"),t.noAttributes&&a.push("noAttributes"),t.noUserAttributes&&a.push("noUserAttributes"),t.noFields&&a.push("noFields"),t.noThumbnails&&a.push("noThumbnails"));let i="";return a.length&&(i=`?${a.join("&")}`),this.execute("get",`/api/item/aggregaterecursive/${e}${i}`)}async getItemPublicRecursive(e,t){return this.execute("get","/api/item/publicrecursive/"+e+(t?"?withFeatures":""))}async getItemPublic(e,t){return this.execute("get","/api/item/public/"+e+(t?"?returnClonedFrom=true":""))}async getItemHistory(e){return this.execute("get","/api/item/history/"+e)}async copyItems(e,t,a,i){return this.execute("post","/api/item/copy",{sourceItemIds:e,destFolderId:t,deepCopy:a,overwrite:i})}async createItem(e){return this.execute("post","/api/item",e)}async updateItem(e){return this.execute("put","/api/item",e)}async deleteItem(e){return this.execute("delete","/api/item",{id:e})}async renameItem(e,t){return this.updateItem({_id:e,name:t})}async queryPublicItemsList(e){return this.execute("post","/api/item/publicquery",e)}async queryItemsListPOP(e){return this.usePublicApi?this.queryPublicItemsList(e):this.queryItemsList(e)}async queryItemsList(e){return this.execute("post","/api/item/query",e)}async queryItemsListAsExcel(e){e.exportAsExcel=true;const t=await this.execute("post","/api/item/query",e,{responseType:"arraybuffer"}),a=window.URL.createObjectURL(t.blob),i=document.createElement("a");i.href=a,i.setAttribute("download","export.xlsx"),i.click();}async moveItems(e){return this.execute("post","/api/item/move",e)}async downloadItem(e,t){const a=Ei(e);return a||this.execute("get",`/api/item/download/${e}`,null,{responseType:"arraybuffer",progressCallback:t,opName:`Downloading item ${e}`})}async publicDownloadItem(e,t){const a=Ei(e);return a||this.execute("get",`/api/item/publicdownload/${e}`,null,{responseType:"arraybuffer",progressCallback:t})}async getItemHash(e){const t=Bi(e);return t?t.hash:this.execute("get",`/api/item/hash/${e}`)}async requestSecureDownload(e){return this.execute("get","/api/item/requestsecuredownload/"+e)}async getThumbnail(e,t){return this.execute("get",`/api/item/thumbnail/${e}/${t}`)}async uploadThumbnail(e,t,a,i,n,r){const s=this._createFormData(a,i);return this.execute("post",`/api/item/thumbnail/${t}/${e}`,s,{progressCallback:n,controller:r})}async getPublicThumbnail(e,t){return this.execute("get",`/api/item/publicthumbnail/${e}/${t}`)}async makeItemPublic(e,t,a){return this.execute("put","/api/item/makepublic",{id:e,recursive:t,inSubfolders:a})}async setVisibility(e,t,a,i){return this.execute("put","/api/item/setvisibility",{id:e,visibility:t,recursive:a,inSubfolders:i})}async makeItemPrivate(e,t,a){return this.execute("put","/api/item/makeprivate",{id:e,recursive:t,inSubfolders:a})}async setOmitLodGeneration(e,t){return this.execute("get",`/api/item/setOmitLodGeneration/${e}/${t}`)}async setOmitThumbnailGeneration(e,t){return this.execute("get",`/api/item/setOmitThumbnailGeneration/${e}/${t}`)}async setOmitPreviewGeneration(e,t){return this.execute("get",`/api/item/setOmitPreviewGeneration/${e}/${t}`)}async uploadAndCreate(e,t,a,i,n,r){const s=this._createFormData(t,a);let o=`/api/item/uploadAndCreate/${e}`,l={};return i&&("object"==typeof i?(i.autoDestructIn&&(o+="?autoDestructIn="+i.autoDestructIn),i.visibility&&(o+="?visibility="+i.visibility),i.flags&&(o+="?flags="+i.flags),i.overwrite&&(o+="?overwrite="+(i.overwrite?"true":"false")),i.nameOverride&&(l["x-override-name"]=i.nameOverride)):o+="?autoDestructIn="+i),this.execute("post",o,s,{progressCallback:n,controller:r,headers:l})}async upload(e,t,a,i,n,r){const s=[];r&&(r.omitHandleDependencyChange&&s.push("omitHandleDependencyChange=true"),r.keepThumbnails&&s.push("keepThumbnails=true"));let o="";s.length&&(o=`?${s.join("&")}`);const l=this._createFormData(t,a);return this.execute("post",`/api/item/upload/${e}${o}`,l,{progressCallback:i,controller:n})}resetPreview(e){const t=this.execute("delete",`/api/item/attachment/${e}/preview`),a=this.execute("get",`/api/item/setOmitPreviewGeneration/${e}/false`);return Promise.all([t,a])}clearPreview(e){const t=this.execute("delete",`/api/item/attachment/${e}/preview`),a=this.execute("get",`/api/item/setOmitPreviewGeneration/${e}/true`);return Promise.all([t,a])}async clearThumbnail(e){return this.execute("get",`/api/item/clearThumbnail/${e}`)}async resetThumbnail(e){return this.execute("get",`/api/item/resetThumbnail/${e}`)}async downloadAttachmentPOP(e,t,a,i,n){return this.usePublicApi?this.downloadPublicAttachment(e,t,a,i,n):this.downloadAttachment(e,t,a,i,n)}_getAttachmentUrlPath(e,t,a,i,n){return `/api/item/${n?"public":""}attachment/${e}/${t}${null!=a?`/${a}`:"/undefined"}${null!=i?`/${i}`:""}`}async downloadAttachment(e,t,a,i=0,n){const r=Wi(e,t,a,i);return r||this.execute("get",this._getAttachmentUrlPath(e,t,a,i),null,{responseType:"arraybuffer",progressCallback:n})}async downloadPublicAttachment(e,t,a,i,n){const r=Wi(e,t,a,i);return r||this.execute("get",this._getAttachmentUrlPath(e,t,a,i,true),null,{responseType:"arraybuffer",progressCallback:n})}async uploadAttachment(e,t,a,i,n,r,s,o){const l=this._createFormData(n,r);return this.execute("post",this._getAttachmentUrlPath(e,t,a,i),l,{progressCallback:s,controller:o})}async deleteAttachment(e,t,a,i){return this.attachmentCache.invalidateAttachment(e,t,a,i),this.execute("delete",this._getAttachmentUrlPath(e,t,a,i))}setPerceptiveHashOnAttachment(e,t,a){return this.execute("get",`/api/item/setPerceptiveHashAttachment/${e}/${t}/${a}`)}setPerceptiveHash(e,t){return this.execute("get",`/api/item/setPerceptiveHash/${e}/${t}`)}async getItemClient(e){return this.execute("get",`/api/item/getClient/${e}`)}async getItemAcl(e){return this.execute("get",`/api/item/acl/${e}`)}async getItemsLinking(e){return this.execute("get",`/api/item/linking/${e}`)}async setAttributes(e,t){return this.execute("put","/api/item/setAttributes",{id:e,attributes:t})}async getItemSyncList(e){const t=j(e).format("YYYYMMDDHHmmss");return this.execute("get",`/api/item/synclist/${t}`)}async increaseViews(e){return this.execute("get",`/api/item/increaseViews/${e}`)}async getViews(e){return this.execute("get",`/api/item/views/${e}`)}async getPublicItemCounts(e){return this.execute("get",`/api/item/publiccounts/${e}`)}async getItemCounts(e){return this.execute("get",`/api/item/counts/${e}`)}async likeItem(e){return this.execute("get",`/api/item/like/${e}`)}async unlikeItem(e){return this.execute("get",`/api/item/unlike/${e}`)}async doILike(e){return this.execute("get",`/api/item/doILike/${e}`)}async setItemAutoDestruct(e,t){const a=j(t).format("YYYYMMDDHHmmss");return this.execute("get",`/api/item/setAutoDestruct/${e}/${a}`)}async clearItemAutoDestruct(e){return this.execute("get",`/api/item/clearAutoDestruct/${e}`)}async resolveRelativeItem(e,t){const a=Bi(e);if(!a)return this.execute("post","/api/item/resolve/"+e,{path:t});t.startsWith("/")&&(t=t.substring(1));const i=t.split("/"),n=i.pop();let r=a.folder._id;for(const e of i){let t=false;for(const[a,i]of Object.entries(Di()))if(i.parent===r&&i.name===e){r=a,t=true;break}if(!t)break}for(const e of Object.values(Oi$1()))if(e.folder._id===r&&e.name===n)return e._id;return console.error(`Could not resolve path ${t} for item ${e}`),null}async publicResolveRelativeItem(e,t){const a=Bi(e);if(!a)return this.execute("post","/api/item/publicResolve/"+e,{path:t});t.startsWith("/")&&(t=t.substring(1));const i=t.split("/"),n=i.pop();let r=Li(a.folder._id);for(const e of i)if(".."===e)r=Li(r.parent);else {const t=Ri(e,r._id);if(!t)throw new Error("Can't find folder while loading folder from package");r=t;}const s=Pi(n,r._id);if(s)return s._id;throw new Error("Can't load item from package.")}async rewireItems(e){return this.execute("post","/api/item/rewire",{items:e})}async getFolder(e){return this.execute("get","/api/folder/"+e)}async getFullFolderTree(e){return this.execute("get",`/api/folder/fulltree/${e||"0"}`)}async getFoldersInFolderList(e,t){e=e||"0";const a=[];let i="";if(t){if(t.resolveNames&&!t.folderAsItemType&&"0"!==e){if(i=await this.folderCache.getFolderListing(e),i&&Date.now()-new Date(i.cachedAt).getTime()<1e4)return i;i&&i.parent&&a.push(`lastUpdatedAt=${i.parent.updatedAt}`);}t.resolveNames&&a.push("resolve"),t.folderAsItemType&&a.push(`folderAsItemType=${t.folderAsItemType}`),t.folderAsItemName&&a.push(`folderAsItemName=${t.folderAsItemName}`),t.folderAsItemFlag&&a.push(`folderAsItemFlag=${t.folderAsItemFlag}`),t.withStats&&a.push("withStats=true"),t.returnLatestPackage&&a.push("returnLatestPackage=true");}let n="";a.length&&(n="?"+a.join("&"));const r=await this.execute("get",`/api/folder/infolder/${e}${n}`);if(true===r.notModified)return i;if(!t||t.resolveNames&&!t.folderAsItemType){const t=await this.getFolderAclList([e,...r.children.map((e=>e._id))]);for(const e of t)await this.folderCache.addACL(e.id,e.acl);return await this.folderCache.addFolderListing(e,r),r}return r}async updateFolderCache(e){const t=[];for(const a of e){if(!a)continue;const e=await this.folderCache.getFolderListing(a);e&&e.parent?t.push({id:a,lastUpdatedAt:e.parent.updatedAt}):t.push({id:a});}const a=await this.execute("post","/api/folder/infolderquery",{folders:t});for(const e of a) true===e.data.notModified?await this.folderCache.refreshCacheForFolder(e.id):await this.folderCache.addFolderListing(e.id,e.data);}async createFolder(e){return this.execute("post","/api/folder",e)}async updateFolder(e){return this.execute("put","/api/folder",e)}async deleteFolder(e){return this.execute("delete","/api/folder",{id:e})}async renameFolder(e,t){return this.updateFolder({_id:e,name:t})}async moveFolders(e){return this.execute("post","/api/folder/move",e)}async getFolderPath(e){return e?("object"==typeof e&&(e=e._id),this.execute("get","/api/folder/path/"+e)):{path:"/",elements:[]}}async resolveFolderPath(e){return "/"===(e=e.trim())?null:this.execute("post","/api/folder/resolve",{path:e})}async getFolderClient(e){return this.execute("get",`/api/folder/getClient/${e}`)}async getFolderAcl(e){const t=await this.folderCache.getFolderACLs(e||"0",1e4);if(t&&e)return t;{const t=await this.execute("get",`/api/folder/acl/${e||"0"}`);return await this.folderCache.addACL(e||"0",t),t}}async getFolderAclList(e){return this.execute("post","/api/folder/aclquery",{ids:e})}async getUser(e){return this.execute("get","/api/user/"+e)}async getUsersList(){return this.execute("get","/api/user")}async createUser(e){return this.execute("post","/api/user",e)}async queryUser(e,t,a){return this.execute("post","/api/user/query",{searchQuery:e,groupID:t,cursor:a},{withNext:true})}async updateUser(e){return this.execute("put","/api/user",e)}async deleteUser(e){return this.execute("delete","/api/user",{id:e})}async updateMyProfile(e){return this.execute("put","/api/user/myprofile",e)}async switchClient(e){return this.execute("get",`/api/user/switchclient/${e}`)}async activateUser(e,t){return this.execute("post","/api/user/activate",{token:t,password:e})}async getUsersToApprove(){return this.execute("get","/api/user/approvals")}async approveUserRegistration(e){return this.execute("get",`/api/user/approveuserregistration/${e}`)}async rejectUserRegistration(e){return this.execute("get",`/api/user/rejectuserregistration/${e}`)}async uploadAvatar(e){const t=new n$3;if(e instanceof Blob)t.append("file",e);else {const a=new Blob([new Uint8Array(e)]);t.append("file",a,"avatar.jpg");}return this.execute("post","/api/user/uploadAvatar",t)}async clearAvatar(){return this.execute("get","/api/user/clearAvatar")}async getAvatar(e,t){return this.execute("get",`/api/user/avatar/${t}/${e}`)}async getUserPublicInfo(e,t,a){return this.execute("get",`/api/user/publicinfo/${e}/${t}/${a}`)}async getUserAttribute(e){return this.execute("get",`/api/user/attribute/${e}`)}async clearUserAttribute(e){return this.execute("delete",`/api/user/attribute/${e}`)}async setUserAttribute(e,t){return this.execute("post",`/api/user/attribute/${e}`,t)}async getGroup(e){return this.execute("get","/api/group/"+e)}async getGroupFolder(e){return this.execute("get","/api/group/folder/"+e)}async getGroupsList(){return this.execute("get","/api/group")}async createGroup(e){return this.execute("post","/api/group",e)}async queryGroup(e,t){return this.execute("post","/api/group/query",{searchQuery:e,cursor:t},{withNext:true})}async updateGroup(e){return this.execute("put","/api/group",e)}async deleteGroup(e){return this.execute("delete","/api/group",{id:e})}async getGroupQuotaInfo(e){return this.execute("get","/api/group/quota/"+e)}async getGroupPublicInfo(e,t,a){return this.execute("get",`/api/group/publicinfo/${e}/${t}/${a}`)}async getGroupUsers(e){return this.execute("get","/api/group/users/"+e)}async uploadGroupAvatar(e,t){const a=new n$3;if(t instanceof Blob)a.append("file",t);else {const e=new Blob([new Uint8Array(t)]);a.append("file",e,"avatar.jpg");}return this.execute("post","/api/group/"+e+"/uploadAvatar",a)}async getClientsList(){return this.execute("get","/api/client")}async getClient(e){return this.execute("get",`/api/client/${e}`)}async createClient(e){return this.execute("post","/api/client",e)}async queryClient(e,t){return this.execute("post","/api/client/query",{searchQuery:e,cursor:t},{withNext:true})}async updateClient(e){return this.execute("put","/api/client",e)}async deleteClient(e){return this.execute("delete","/api/client",{id:e})}async getClientMetrics(e,t,a){return this.execute("get",`/api/client/metrics/${t}/${a}/${e}`)}async joinClient(e){return this.execute("get",`/api/client/join/${e}`)}async leaveClient(e){return this.execute("get",`/api/client/leave/${e}`)}async myClient(){return this.execute("get","/api/client/my")}async saveMyClient(e){return this.execute("put","/api/client/my",e)}async getPublicCategories(e){return this.execute("get",`/api/client/publiccategories/${e}`)}async getCategories(){return this.execute("get","/api/client/categories")}async getCategoriesInClient(e){return this.execute("get",`/api/client/categories/${e}`)}async updateCategoriesInClient(e,t){return this.execute("post",`/api/client/categories/${e}`,t)}async getLicenses(){return this.execute("get","/api/license")}async getLicensesInClient(e){return this.execute("get",`/api/license/inclient/${e}`)}async getLicense(e){return this.execute("get",`/api/license/${e}`)}async createLicense(e){return this.execute("post","/api/license",e)}async updateLicense(e){return this.execute("put","/api/license",e)}async deleteLicense(e,t){return this.execute("delete","/api/license",{_id:e,client:t})}async getPublicLicenses(e){return this.execute("get",`/api/license/publiclist/${e}`)}async getPublicLicense(e){return this.execute("get",`/api/license/public/${e}`)}async getDatatypesList(){return this.execute("get","/api/datatype")}async getPublicDatatypesList(e){return this.execute("get",`/api/datatype/public/${e}`)}async getDatatypesListOnClient(){return this.execute("get","/api/datatype/onclient")}async getDatatypesListOnClientForAll(){return this.execute("get","/api/datatype/onclientforall")}async getAllDatatypesList(){return this.execute("get","/api/datatype/all")}async getDatatype(e){return this.execute("get",`/api/datatype/${e}`)}async createDatatype(e){return this.execute("post","/api/datatype",e)}async updateDatatype(e){return this.execute("put","/api/datatype",e)}async deleteDatatype(e){return this.execute("delete","/api/datatype",{id:e})}async getMyNotifications(e){return this.execute("get","/api/notification"+(e?`?maxCount=${e}`:""))}async markNotificationAsRead(e){return this.execute("get",`/api/notification/markasread/${e}`)}async markAllNotificationsAsRead(){return this.execute("get","/api/notification/markallasread")}async createJob(e){return this.execute("post","/api/job",e,{emitOnSuccess:"job:created"})}async getManualJobTypes(){return this.execute("get","/api/job/manualtypes")}async getManualJobTypesOnClient(){return this.execute("get","/api/job/manualtypes/onclient")}async getManualJobTypesOnClientForAll(){return this.execute("get","/api/job/manualtypes/onclientforall")}async getAllManualJobTypes(){return this.execute("get","/api/job/manualtypes/all")}async getAllManualJobTypesForClient(e){return this.execute("get",`/api/job/manualtypes/all/${e}`)}async getClientJobTypes(){return this.execute("get","/api/job/clientTypes")}async getMyJobs(){return this.execute("get","/api/job/mine")}async getJobs(){return this.execute("get","/api/job")}async getJobsAggregated(){return this.execute("get","/api/job/aggregated")}async getJobsTimeframe(e,t){return this.execute("get",`/api/job/all/${e}/${t}`)}async getJob(e){return this.execute("get",`/api/job/${e}`)}async getJobState(e){return this.execute("get",`/api/job/state/${e}`)}async getAgents(){return this.execute("get","/api/jobagent")}async getAgentsAggregated(){return this.execute("get","/api/jobagent/aggregated")}async enableJobAgent(e){return this.execute("get",`/api/jobagent/enable/${e}`)}async disableJobAgent(e){return this.execute("get",`/api/jobagent/disable/${e}`)}async restartJobAgent(e){return this.execute("get",`/api/jobagent/restart/${e}`)}async getPermissionsList(){return this.execute("get","/api/permission")}async getPlugins(){return this.execute("get","/api/plugin")}async getPlans(){return this.execute("get","/api/plan")}async getPlan(e){return this.execute("get",`/api/plan/${e}`)}async createPlan(e){return this.execute("post","/api/plan",e)}async updatePlan(e){return this.execute("put","/api/plan",e)}async deletePlan(e){return this.execute("delete","/api/plan",{id:e})}async getWorkflows(){return this.execute("get","/api/workflow")}async getWorkflow(e){return this.execute("get",`/api/workflow/${e}`)}async createWorkflow(e){return this.execute("post","/api/workflow",e)}async updateWorkflow(e){return this.execute("put","/api/workflow",e)}async deleteWorkflow(e){return this.execute("delete","/api/workflow",{id:e})}async startWorkflow(e){return this.execute("post","/api/workflow/start",e)}async getAccessTokens(){return this.execute("get","/api/accesstoken")}async getClientAccessTokens(){return this.execute("get","/api/accesstoken/client")}async createAccessToken(e){return this.execute("post","/api/accesstoken",e)}async createClientAccessToken(e){return this.execute("post","/api/accesstoken/client",e)}async deleteAccessToken(e){return this.execute("delete","/api/accesstoken",{id:e})}async deleteClientAccessToken(e){return this.execute("delete","/api/accesstoken/client",{id:e})}async enableAccessToken(e){return this.execute("get",`/api/accesstoken/enable/${e}`)}async disableAccessToken(e){return this.execute("get",`/api/accesstoken/disable/${e}`)}async getApiTokens(){return this.execute("get","/api/apitoken")}async createApiToken(e){return this.execute("post","/api/apitoken",e)}async deleteApiToken(e){return this.execute("delete","/api/apitoken",{id:e})}async getMyClientInvoices(){return this.execute("get","/api/invoice")}async getMyUserInvoices(){return this.execute("get","/api/invoice/my")}async getClientInvoices(e){return this.execute("get",`/api/invoice/client/${e}`)}async downloadInvoice(e,t){const a=await this.execute("get",`/api/invoice/download/${e}`,null,{responseType:"arraybuffer"}),i=window.URL.createObjectURL(a.blob),n=document.createElement("a");n.href=i,n.setAttribute("download",t||"invoice.pdf"),document.body.appendChild(n),n.click();}async regenerateInvoice(e){return this.execute("get",`/api/invoice/regenerate/${e}`)}async getInvoicesForMonth(e,t){return this.execute("get",`/api/invoice/month/${t}/${e}`)}async refundInvoice(e,t,a){return this.execute("post","/api/invoice/refund",{invoice:e,amount:t,reason:a})}async paymentStartCheckout(e,t){return this.execute("post","/api/payment/checkout",{successUrl:e,cancelUrl:t})}async paymentStartUserCheckout(e,t){return this.execute("post","/api/payment/usercheckout",{successUrl:e,cancelUrl:t})}async getSupportedCurrencies(){return this.execute("get","/api/payment/supportedCurrencies")}async getPurchasables(){return this.execute("get","/api/purchasable")}async getPurchasable(e){return this.execute("get",`/api/purchasable/${e}`)}async createPurchasable(e){return this.execute("post","/api/purchasable",e)}async updatePurchasable(e){return this.execute("put","/api/purchasable",e)}async deletePurchasable(e){return this.execute("delete","/api/purchasable",{id:e})}async getPublicPurchasables(e){return this.execute("get",`/api/purchasable/public/${e}`)}async getPurchases(){return this.execute("get","/api/purchase")}async getMyActivePurchases(){return this.execute("get","/api/purchase/active")}async purchase(e){return this.execute("post","/api/purchase",e)}async changePurchaseProduct(e,t,a){return this.execute("post","/api/purchase/change",{purchaseID:e,purchasableID:t,optionID:a})}async cancelPurchase(e){return this.execute("delete","/api/purchase",{id:e})}async uncancelPurchase(e){return this.execute("post","/api/purchase/uncancel",{id:e})}async getSecureSessionPayload(e,t){return this.execute("get","/api/payment/secureSessionPayload?purchasableID="+e+"&optionID="+t)}async queryPurchases(e,t,a,i,n,r){return this.execute("post","/api/purchase/query",{startDate:e,endDate:t,email:a,invoice:i,cursor:n,limit:r})}async getAttributeTemplates(){return this.execute("get","/api/attributetemplate")}async getAttributeTemplate(e){return this.execute("get",`/api/attributetemplate/${e}`)}async createAttributeTemplate(e){return this.execute("post","/api/attributetemplate",e)}async updateAttributeTemplate(e){return this.execute("put","/api/attributetemplate",e)}async deleteAttributeTemplate(e){return this.execute("delete","/api/attributetemplate",{id:e})}async getStorages(){return this.execute("get","/api/storage")}async getConversation(e){return this.execute("get",`/api/conversation/${e}`)}async getPublicConversation(e){return this.execute("get",`/api/conversation/public/${e}`)}async createConversation(e,t){return this.execute("post","/api/conversation",{parentId:e,parentType:t})}async postConversationMessage(e,t,a){return this.execute("post","/api/conversation/post",{id:e,text:t,replyTo:a})}async editConversationMessage(e,t){return this.execute("put","/api/conversation/post",{id:e,text:t})}async deleteConversationMessage(e){return this.execute("delete","/api/conversation/post",{id:e})}async subscribeToConversation(e){return this.execute("post","/api/conversation/subscribe",{id:e})}async unsubscribeFromConversation(e){return this.execute("post","/api/conversation/unsubscribe",{id:e})}async likeConversationEntry(e){return this.execute("post","/api/conversation/like",{id:e})}async unlikeConversationEntry(e){return this.execute("post","/api/conversation/unlike",{id:e})}async command(e){return this.execute("post","/api/command",e)}async getMailTemplates(){return this.execute("get","/api/mailtemplate")}async getMailTemplate(e){return this.execute("get",`/api/mailtemplate/${e}`)}async createMailTemplate(e){return this.execute("post","/api/mailtemplate",e)}async updateMailTemplate(e){return this.execute("put","/api/mailtemplate",e)}async deleteMailTemplate(e){return this.execute("delete","/api/mailtemplate",{id:e})}async addMailTemplateImage(e,t,a){const i=this._createFormData(a,"image.jpg");return this.execute("post",`/api/mailtemplate/image/${e}/${t}`,i)}async deleteMailTemplateImage(e,t){return this.execute("delete",`/api/mailtemplate/image/${e}/${t}`)}async getMailTemplateNames(){return this.execute("get","/api/mailtemplate/names")}async getMailQuery(e,t,a,i){return this.execute("post","/api/email/query",{templateName:e,dateStart:t,dateEnd:a,success:i},{withNext:true})}async getMail(e){return this.execute("get","/api/email/get?token="+e)}async getInvoiceTemplates(){return this.execute("get","/api/invoicetemplate")}async getInvoiceTemplate(e){return this.execute("get",`/api/invoicetemplate/${e}`)}async createInvoiceTemplate(e){return this.execute("post","/api/invoicetemplate",e)}async updateInvoiceTemplate(e){return this.execute("put","/api/invoicetemplate",e)}async deleteInvoiceTemplate(e){return this.execute("delete","/api/invoicetemplate",{id:e})}async addInvoiceTemplateImage(e,t,a){const i=this._createFormData(a,"image.jpg");return this.execute("post",`/api/invoicetemplate/image/${e}/${t}`,i)}async deleteInvoiceTemplateImage(e,t){return this.execute("delete",`/api/invoicetemplate/image/${e}/${t}`)}async getItemTemplatesList(){return this.execute("get","/api/itemtemplate/list")}async getItemTemplates(){return this.execute("get","/api/itemtemplate")}async createItemTemplate(e){return this.execute("post","/api/itemtemplate",e)}async updateItemTemplate(e){return this.execute("put","/api/itemtemplate",e)}async deleteItemTemplate(e){return this.execute("delete","/api/itemtemplate",{id:e})}async getFeatures(){return this.execute("get","/api/feature")}async getFeaturesOnClient(){return this.execute("get","/api/feature/onclient")}async getFeaturesOnClientForAll(){return this.execute("get","/api/feature/onclientforall")}async getAllFeatures(){return this.execute("get","/api/feature/all")}async getBlogs(){return this.execute("get","/api/blog")}async getBlog(e){return this.execute("get","/api/blog/"+e)}async getPublicBlog(e){return this.execute("get","/api/blog/"+e+"/public")}async createBlog(e,t,a,i){return this.execute("post","/api/blog",{name:e,public:t,commentsEnabled:a,editors:i})}async saveBlog(e,t,a,i,n){return this.execute("put","/api/blog",{_id:e,name:t,public:a,commentsEnabled:i,editors:n})}async deleteBlog(e){return this.execute("delete","/api/blog",{_id:e})}async getBlogOverview(e){return this.execute("get","/api/blog/"+e+"/overview")}async queryBlog(e,t,a,i,n,r,s){return this.execute("post","/api/blog/"+e+"/query",{tag:t,text:a,limit:i,previousArticle:n,searchTag:r,sortBy:s})}async getArticles(e){return this.execute("get","/api/blog/"+e+"/article")}async getArticle(e,t){return this.execute("get","/api/blog/"+e+"/article/"+t)}async getArticleBySlug(e,t){return this.execute("get","/api/blog/article/"+e+"/"+t)}async createArticle(e,t,a){return this.execute("post","/api/blog/"+e+"/article",{title:t,slug:a})}async saveArticle(e,t,a,i,n,r,s,o){return this.execute("put","/api/blog/"+e+"/article",{_id:t,title:a,slug:i,content:o,tags:r,public:n,author:s})}async deleteArticle(e,t){return this.execute("delete","/api/blog/"+e+"/article",{_id:t})}async getNewsletters(){return this.execute("get","/api/newsletter")}async createNewsletter(e,t){return this.execute("post","/api/newsletter",{name:e,editors:t})}async getNewsletter(e){return this.execute("get","/api/newsletter/"+e)}async updateNewsletter(e,t,a,i){return this.execute("put","/api/newsletter/"+e,{name:t,sender:a,editors:i})}async deleteNewsletter(e){return this.execute("delete","/api/newsletter/"+e)}async joinNewsletter(e,t){return this.execute("post","/api/newsletter/join",{id:e,email:t})}async confirmNewsletter(e){return this.execute("post","/api/newsletter/confirm",{token:e})}async unsubscribeFromNewsletter(e){return this.execute("post","/api/newsletter/unsubscribe",{token:e})}async getNewsletterBlocks(){return this.execute("get","/api/newsletterblock")}async getNewsletterBlock(e){return this.execute("get","/api/newsletterblock/"+e)}async createNewsletterBlock(e){return this.execute("post","/api/newsletterblock",{name:e})}async updateNewsletterBlock(e,t,a,i,n,r){return this.execute("put","/api/newsletterblock/"+e,{name:t,inputs:a,html:i,css:n,acceptsChildren:r})}async deleteNewsletterBlock(e){return this.execute("delete","/api/newsletterblock/"+e)}async getNewsletterMails(e){return this.execute("get","/api/newslettermail/"+e)}async getNewsletterMail(e,t){return this.execute("get","/api/newslettermail/"+e+"/"+t)}async createNewsletterMail(e,t){return this.execute("post","/api/newslettermail/"+e,{title:t})}async updateNewsletterMail(e,t,a,i,n){return this.execute("put","/api/newslettermail/"+e+"/"+t,{title:a,blocks:i,parentBlock:n})}async generatePreviewNewsletterMail(e,t){return this.execute("post","/api/newslettermail/render",{blocks:e,parentBlock:t})}async sendTestNewsletter(e,t,a){return this.execute("post","/api/newslettermail/"+e+"/"+t+"/sendTest",{email:a})}async sendOutNewsletter(e,t){return this.execute("post","/api/newslettermail/"+e+"/"+t+"/send",{})}async getPages(){return this.execute("get","/api/page")}async createPage(e,t){return this.execute("post","/api/page",{title:e,slug:t})}async getPage(e){return this.execute("get","/api/page/"+e)}async updatePage(e,t,a,i,n){return this.execute("put","/api/page",{_id:e,title:t,slug:a,public:i,content:n})}async deletePage(e){return this.execute("delete","/api/page",{_id:e})}async getPublicPage(e,t){return this.execute("get","/api/page/public/"+e+"/"+t)}async setItemFlag(e,t,a,i,n,r){return this.execute("post","/api/itemflag",{item:e,isStaffPick:t,featureWeight:a,isGame:i,replaceIndex:n,internalRating:r})}getDownloadUrl(e){return `${this.getApiBaseUrl()}/api/item/download/${e}`}getAttachmentDownloadUrl(e,t,a,i){return `${this.getApiBaseUrl()}${this._getAttachmentUrlPath(e,t,a,i)}`}getPublicAttachmentDownloadUrl(e,t,a,i){return `${this.getApiBaseUrl()}${this._getAttachmentUrlPath(e,t,a,i,true)}`}getPublicDownloadUrl(e){return `${this.getApiBaseUrl()}/api/item/publicdownload/${e}`}async postFeedback(e){return this.execute("post","/api/feedback",{text:e})}}class Ac{linkableItemsCache;apiGateway;itemCache;usePublicApi;constructor(e,t,a=false){this.linkableItemsCache=new Map,this.apiGateway=e,this.itemCache=t,this.usePublicApi=a;}clear(){this.linkableItemsCache.clear();}resolveItem(e,t){for(const a of t)if(a._id===e)return a;return null}async loadLinkableItems(e,t){if(!e)throw "loadLinkableItems(): Item cannot be null!";let a=[];if(t.linkableTypes&&t.linkableTypes.length){if(!this.usePublicApi){const i=t.linkableTypes.join("#")+(e.folder?e.folder._id:"");if(this.linkableItemsCache.has(i))return this.linkableItemsCache.get(i);const n=[...t.linkableTypes];n.includes("Package")||n.push("Package");const r={types:n,folder:e.folder?e.folder._id:null};a=(await this.apiGateway.call("LinkableItemsCache::loadLinkableItems","queryItemsList",r)).filter((e=>"Package"!==e.type||t.linkableTypes.includes(e.packageType)));for(const i of e.links)if(null==this.resolveItem(i.to,a))try{const e=await this.itemCache.getItem(i.to);t.linkableTypes.includes(e.type)&&a.push(e);}catch(e){console.error(`Link item ${i.to} not found. Dead link? (${e})`);}this.linkableItemsCache.set(i,a);}}else {for(const t of e.links){const e=await this.itemCache.getItem(t.to);a.push(e);}const i=t.name+"#CurrentLinks";this.linkableItemsCache.set(i,a);}return a}}
|
|
6601
6601
|
|
|
6602
6602
|
/**
|
|
6603
6603
|
* @license
|
|
@@ -114104,7 +114104,7 @@ void main() {
|
|
|
114104
114104
|
}
|
|
114105
114105
|
}
|
|
114106
114106
|
|
|
114107
|
-
var engine$1 = "26.3.
|
|
114107
|
+
var engine$1 = "26.3.13";
|
|
114108
114108
|
var bullet = "3.26";
|
|
114109
114109
|
var lua = "5.4.3";
|
|
114110
114110
|
var packageVersionInfo = {
|