/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/loro-crdt@1.17.1/browser/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{LoroDoc,EphemeralStoreWasm,UndoManager,isValidContainerId,AwarenessWasm,callPendingEvents}from"./loro_wasm";export*from"./loro_wasm";class Loro extends LoroDoc{}const CONTAINER_TYPES=["Map","Text","List","Tree","MovableList","Counter"];function isContainerId(e){return isValidContainerId(e)}function isContainer(e){if("object"!=typeof e||null==e)return!1;const t=Object.getPrototypeOf(e);return null!=t&&"object"==typeof t&&"function"==typeof t.kind&&CONTAINER_TYPES.includes(e.kind())}function getType(e){return isContainer(e)?e.kind():"Json"}function newContainerID(e,t){return`cid:${e.counter}@${e.peer}:${t}`}function newRootContainerID(e,t){return`cid:root-${e}:${t}`}class Awareness{constructor(e,t=3e4){this.listeners=new Set,this.inner=new AwarenessWasm(e,t),this.peer=e,this.timeout=t}apply(e,t="remote"){const{updated:_,added:n}=this.inner.apply(e);this.listeners.forEach(e=>{e({updated:_,added:n,removed:[]},t)}),this.startTimerIfNotEmpty()}setLocalState(e){const t=null==this.inner.getState(this.peer);this.inner.setLocalState(e),t?this.listeners.forEach(e=>{e({updated:[],added:[this.inner.peer()],removed:[]},"local")}):this.listeners.forEach(e=>{e({updated:[this.inner.peer()],added:[],removed:[]},"local")}),this.startTimerIfNotEmpty()}getLocalState(){return this.inner.getState(this.peer)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}addListener(e){this.listeners.add(e)}removeListener(e){this.listeners.delete(e)}peers(){return this.inner.peers()}destroy(){clearInterval(this.timer),this.listeners.clear()}startTimerIfNotEmpty(){this.inner.isEmpty()||null!=this.timer||(this.timer=setInterval(()=>{const e=this.inner.removeOutdated();e.length>0&&this.listeners.forEach(t=>{t({updated:[],added:[],removed:e},"timeout")}),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}}class EphemeralStore{constructor(e=3e4){this.inner=new EphemeralStoreWasm(e),this.timeout=e}apply(e){this.inner.apply(e),this.startTimerIfNotEmpty()}set(e,t){this.inner.set(e,t),this.startTimerIfNotEmpty()}delete(e){this.inner.delete(e)}get(e){return this.inner.get(e)}getAllStates(){return this.inner.getAllStates()}encode(e){return this.inner.encode(e)}encodeAll(){return this.inner.encodeAll()}keys(){return this.inner.keys()}destroy(){clearInterval(this.timer)}subscribe(e){return this.inner.subscribe(e)}subscribeLocalUpdates(e){return this.inner.subscribeLocalUpdates(e)}startTimerIfNotEmpty(){this.inner.isEmpty()||null!=this.timer||(this.timer=setInterval(()=>{this.inner.removeOutdated(),this.inner.isEmpty()&&(clearInterval(this.timer),this.timer=void 0)},this.timeout/2))}}function idStrToId(e){const[t,_]=e.split("@");return{counter:parseInt(t),peer:_}}LoroDoc.prototype.toJsonWithReplacer=function(e){const t=new Set,_=this,n=(n,o)=>{if("string"==typeof o&&isContainerId(o)&&!t.has(o)){t.add(o);const i=_.getContainerById(o);if(null==i)throw new Error(`ContainerID not found: ${o}`);const a=e(n,i);if(a===i){const e=i.getShallowValue();return"object"==typeof e?r(e):e}if(isContainer(a))throw new Error("Using new container is not allowed in toJsonWithReplacer");return"object"==typeof a&&null!=a?r(a):a}if("object"==typeof o&&null!=o)return r(o);const i=e(n,o);if(isContainer(i))throw new Error("Using new container is not allowed in toJsonWithReplacer");return i},r=e=>{if(Array.isArray(e))return e.map((e,t)=>n(t,e)).filter(e=>void 0!==e);const t={};for(const[_,r]of Object.entries(e)){const e=n(_,r);void 0!==e&&(t[_]=e)}return t},o=_.getShallowValue();return r(o)};const CALL_PENDING_EVENTS_WRAPPED=Symbol("loro.callPendingEventsWrapped");function decorateMethod(e,t){const _=Object.getOwnPropertyDescriptor(e,t);if(!_||"function"!=typeof _.value)return;const n=_.value;if(n[CALL_PENDING_EVENTS_WRAPPED])return;const r=function(...e){let t;try{return t=n.apply(this,e),t}finally{t&&"function"==typeof t.then?t.finally(()=>{callPendingEvents()}):callPendingEvents()}};r[CALL_PENDING_EVENTS_WRAPPED]=!0,Object.defineProperty(e,t,{..._,value:r})}function decorateMethods(e,t){for(const _ of t)decorateMethod(e,_)}decorateMethods(LoroDoc.prototype,["setDetachedEditing","attach","detach","fork","forkAt","checkoutToLatest","checkout","commit","getCursorPos","revertTo","export","exportJsonUpdates","exportJsonInIdSpan","importJsonUpdates","import","importUpdateBatch","importBatch","travelChangeAncestors","getChangedContainersIn","diff","applyDiff","setPeerId"]),decorateMethods(EphemeralStoreWasm.prototype,["set","delete","apply","removeOutdated"]),decorateMethods(UndoManager.prototype,["undo","redo"]);export{Awareness,EphemeralStore,Loro,getType,idStrToId,isContainer,isContainerId,newContainerID,newRootContainerID};export{AwarenessWasm,ChangeModifier,Cursor,EphemeralStoreWasm,LORO_VERSION,LoroCounter,LoroDoc,LoroList,LoroMap,LoroMovableList,LoroText,LoroTree,LoroTreeNode,UndoManager,VersionVector,__wbg_String_8f0eb39a4a4c2f66,__wbg_apply_36be6a55257c99bf,__wbg_apply_eb9e9b97497f91e4,__wbg_buffer_609cc3eee51ed158,__wbg_call_672a4d21634d4a24,__wbg_call_7cccdd69e0791ae2,__wbg_call_833bed5770ea2041,__wbg_call_b8adc8b1d0a0d8eb,__wbg_changemodifier_new,__wbg_crypto_574e78ad8b13b65f,__wbg_cursor_new,__wbg_done_769e5ede4b31c67b,__wbg_entries_3265d4158b33e5dc,__wbg_entries_c8a90a7ed73e84ce,__wbg_error_428bae4e36b351e3,__wbg_from_2a5d3e218e67aa85,__wbg_getOwnPropertySymbols_97eebed6fe6e08be,__wbg_getRandomValues_b8f5dbd5f3995a9e,__wbg_get_67b2ba62fc30de12,__wbg_get_b9b93047fe3cf45b,__wbg_getindex_5b00c274b05714aa,__wbg_getwithrefkey_1dc361bd10053bfe,__wbg_instanceof_ArrayBuffer_e14585432e3737fc,__wbg_instanceof_Map_f3469ce2244d2430,__wbg_instanceof_Object_7f2dcef8f78644a4,__wbg_instanceof_Uint8Array_17156bcf118086a9,__wbg_isArray_a1eab7e0d067391b,__wbg_isSafeInteger_343e2beeeece1bb0,__wbg_iterator_9a24c88df860dc65,__wbg_length_a446193dc22c12f8,__wbg_length_e2d2a49132c1b256,__wbg_log_0cc1b7768397bcfe,__wbg_log_882f657276590a29,__wbg_log_cb9e190acc5753fb,__wbg_lorocounter_new,__wbg_lorolist_new,__wbg_loromap_new,__wbg_loromovablelist_new,__wbg_lorotext_new,__wbg_lorotree_new,__wbg_lorotreenode_new,__wbg_mark_7438147ce31e9d4b,__wbg_measure_fb7825c11612c823,__wbg_msCrypto_a61aeb35a24c1329,__wbg_new_405e22f390576ce2,__wbg_new_5e0be73521bc8c17,__wbg_new_78feb108b6472713,__wbg_new_a12002a7f91c75be,__wbg_new_c68d7209be747379,__wbg_newnoargs_105ed471475aaf50,__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a,__wbg_newwithlength_a381634e90c276d4,__wbg_newwithlength_c4c419ef0bc8a1f8,__wbg_next_25feadfc0913fea9,__wbg_next_6574e1a8a62d1055,__wbg_node_905d3e251edff8a2,__wbg_now_2b509d5c9d429404,__wbg_ownKeys_3930041068756f1f,__wbg_process_dc0fbacc7c1c06f7,__wbg_push_737cfc8c1432c2c6,__wbg_randomFillSync_ac0988aba3254290,__wbg_require_60cc747a6bc5215a,__wbg_resolve_4851785c9c5f573d,__wbg_set_37837023f3d740e8,__wbg_set_3f1d0b984ed272ed,__wbg_set_65595bdd868b3009,__wbg_set_8fc6bf8a5b1071d1,__wbg_set_bb8cecf6a62b9f46,__wbg_set_wasm,__wbg_stateBinary_bcc49261f5205b9f,__wbg_stateCid_ddf7fe40691e2c8f,__wbg_stateContainer_8b73508686ecac7f,__wbg_stateIndex_985e23155ddc5679,__wbg_stateOptions_234376ac96321e68,__wbg_stateRootCid_92a320b321ddff0a,__wbg_stateSet_9c75457bd566f749,__wbg_stateSlice_4573448d6dfd609f,__wbg_stateValue_32a9721f28b53795,__wbg_static_accessor_GLOBAL_88a902d13a557d07,__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0,__wbg_static_accessor_SELF_37c5d418e4bf5819,__wbg_static_accessor_WINDOW_5de37043a91a9c40,__wbg_subarray_aa9065fa9dc5df96,__wbg_then_44b73946d2fb3e7d,__wbg_value_cd1ffa7b1ab794f1,__wbg_versions_c01dfd4722a88165,__wbg_versionvector_new,__wbg_warn_5d1fd3858772ca54,__wbindgen_as_number,__wbindgen_bigint_from_i64,__wbindgen_bigint_from_u64,__wbindgen_bigint_get_as_i64,__wbindgen_boolean_get,__wbindgen_cb_drop,__wbindgen_closure_wrapper295,__wbindgen_closure_wrapper551,__wbindgen_debug_string,__wbindgen_error_new,__wbindgen_in,__wbindgen_is_array,__wbindgen_is_bigint,__wbindgen_is_function,__wbindgen_is_null,__wbindgen_is_object,__wbindgen_is_string,__wbindgen_is_undefined,__wbindgen_jsval_eq,__wbindgen_jsval_loose_eq,__wbindgen_memory,__wbindgen_number_get,__wbindgen_number_new,__wbindgen_object_clone_ref,__wbindgen_object_drop_ref,__wbindgen_rethrow,__wbindgen_string_get,__wbindgen_string_new,__wbindgen_throw,__wbindgen_typeof,callPendingEvents,decodeFrontiers,decodeImportBlobMeta,encodeFrontiers,isValidContainerId,redactJsonUpdates,run,setDebug}from"./loro_wasm";
//# sourceMappingURL=/sm/9267d2ef3844039112dbbc9c31c177dbd1bbbd4d3574dd4412c4305771040377.map