import{_ as o,N as i}from"./bootstrap-DlNJH-GE.js";class n{constructor(t){this.replicaId=t}doc;map;policy={kind:"lww"};listeners=new Set;docUnsub;async connect(){let t;try{t=await o(()=>import("./index-DrVhnRju.js"),[])}catch(r){throw new i("LoroCRDTAdapter","install `loro-crdt` (npm i loro-crdt)",r)}this.doc=new t.LoroDoc,this.doc.setPeerId(s(this.replicaId)),this.map=this.doc.getMap("kv"),this.docUnsub=this.doc.subscribe(()=>this.fire())}async close(){this.docUnsub?.(),this.listeners.clear(),this.doc=void 0,this.map=void 0}async set(t,r){this.requireMap().set(t,r),this.requireDoc().commit()}async get(t){return this.requireMap().get(t)}async snapshot(){return this.requireMap().toJSON()}async export(){return this.requireDoc().export({mode:"snapshot"})}async apply(t){this.requireDoc().import(t)}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}setConflictPolicy(t){this.policy=t,this.policy}requireDoc(){if(!this.doc)throw new i("LoroCRDTAdapter","connect() first");return this.doc}requireMap(){if(!this.map)throw new i("LoroCRDTAdapter","connect() first");return this.map}fire(){for(const t of this.listeners)t()}}function s(e){let t=2166136261;for(let r=0;r<e.length;r++)t^=e.charCodeAt(r),t=Math.imul(t,16777619)>>>0;return BigInt(t)}export{n as LoroCRDTAdapter};
//# sourceMappingURL=loro_crdt-2XPYnAqy.js.map
