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Ae,EAAmB,GACzC,MAAM,EAAa,OAAO,yBAAyB,EAAW,GAC9D,IAAK,GAA0C,mBAArB,EAAW,MACnC,OAGF,MAAM,EAAW,EAAW,MAC5B,GAAK,EAAiB,6BACpB,OAGF,MAAM,EAAU,YAA4B,GAC1C,IAAI,EACJ,IAEE,OADA,EAAS,EAAS,MAAM,KAAM,GACvB,C,SAEH,GAAuD,mBAArC,EAA4B,KAC/C,EAA4B,QAAQ,KACnC,sBAGF,mB,CAGN,EAEC,EAAgB,8BAA+B,EAEhD,OAAO,eAAe,EAAW,EAAQ,IACpC,EACH,MAAO,GAEX,CAEA,SAAS,gBAAgB,EAAmB,GAC1C,IAAK,MAAM,KAAU,EACnB,eAAe,EAAW,EAE9B,CA8BA,gBAAgB,QAAQ,UAAW,CACjC,qBACA,SACA,SACA,OACA,SACA,mBACA,WACA,SACA,eACA,WACA,SACA,oBACA,qBACA,oBACA,SACA,oBACA,cACA,wBACA,yBACA,OACA,YACA,cAGF,gBAAgB,mBAAmB,UAAW,CAC5C,MACA,SACA,QACA,mBAGF,gBAAgB,YAAY,UAAW,CAAC,OAAQ,gB","file":"/npm/loro-crdt@1.16.4/browser/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.48.0.\n * Original file: /npm/loro-crdt@1.16.4/browser/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","export * from \"loro-wasm\";\nexport type * from \"loro-wasm\";\nimport {\n  AwarenessWasm,\n  EphemeralStoreWasm,\n  PeerID,\n  Container,\n  ContainerID,\n  ContainerType,\n  LoroCounter,\n  LoroDoc,\n  LoroList,\n  LoroMap,\n  LoroMovableList,\n  LoroText,\n  LoroTree,\n  LoroTreeNode,\n  OpId,\n  Value,\n  AwarenessListener,\n  EphemeralListener,\n  EphemeralLocalListener,\n  UndoManager,\n  callPendingEvents,\n  isValidContainerId,\n} from \"loro-wasm\";\n\n/**\n * @deprecated Please use LoroDoc\n */\nexport class Loro extends LoroDoc {}\n\nconst CONTAINER_TYPES = [\n  \"Map\",\n  \"Text\",\n  \"List\",\n  \"Tree\",\n  \"MovableList\",\n  \"Counter\",\n];\n\nexport function isContainerId(s: string): s is ContainerID {\n  return isValidContainerId(s);\n}\n\n/**  Whether the value is a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new LoroDoc();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * isContainer(map); // true\n * isContainer(list); // true\n * isContainer(text); // true\n * isContainer(123); // false\n * isContainer(\"123\"); // false\n * isContainer({}); // false\n * ```\n */\nexport function isContainer(value: any): value is Container {\n  if (typeof value !== \"object\" || value == null) {\n    return false;\n  }\n\n  const p = Object.getPrototypeOf(value);\n  if (p == null || typeof p !== \"object\" || typeof p[\"kind\"] !== \"function\") {\n    return false;\n  }\n\n  return CONTAINER_TYPES.includes(value.kind());\n}\n\n/**  Get the type of a value that may be a container.\n *\n * # Example\n *\n * ```ts\n * const doc = new LoroDoc();\n * const map = doc.getMap(\"map\");\n * const list = doc.getList(\"list\");\n * const text = doc.getText(\"text\");\n * getType(map); // \"Map\"\n * getType(list); // \"List\"\n * getType(text); // \"Text\"\n * getType(123); // \"Json\"\n * getType(\"123\"); // \"Json\"\n * getType({}); // \"Json\"\n * ```\n */\nexport function getType<T>(\n  value: T,\n): T extends LoroText\n  ? \"Text\"\n  : T extends LoroMap<any>\n    ? \"Map\"\n    : T extends LoroTree<any>\n      ? \"Tree\"\n      : T extends LoroList<any>\n        ? \"List\"\n        : T extends LoroCounter\n          ? \"Counter\"\n          : \"Json\" {\n  if (isContainer(value)) {\n    return value.kind() as unknown as any;\n  }\n\n  return \"Json\" as any;\n}\n\nexport function newContainerID(id: OpId, type: ContainerType): ContainerID {\n  return `cid:${id.counter}@${id.peer}:${type}`;\n}\n\nexport function newRootContainerID(\n  name: string,\n  type: ContainerType,\n): ContainerID {\n  return `cid:root-${name}:${type}`;\n}\n\n/**\n * @deprecated Please use `EphemeralStore` instead.\n *\n * Awareness is a structure that allows to track the ephemeral state of the peers.\n *\n * If we don't receive a state update from a peer within the timeout, we will remove their state.\n * The timeout is in milliseconds. This can be used to handle the offline state of a peer.\n */\nexport class Awareness<T extends Value = Value> {\n  inner: AwarenessWasm<T>;\n  private peer: PeerID;\n  private timer: number | undefined;\n  private timeout: number;\n  private listeners: Set<AwarenessListener> = new Set();\n  constructor(peer: PeerID, timeout: number = 30000) {\n    this.inner = new AwarenessWasm(peer, timeout);\n    this.peer = peer;\n    this.timeout = timeout;\n  }\n\n  apply(bytes: Uint8Array, origin = \"remote\") {\n    const { updated, added } = this.inner.apply(bytes);\n    this.listeners.forEach((listener) => {\n      listener({ updated, added, removed: [] }, origin);\n    });\n\n    this.startTimerIfNotEmpty();\n  }\n\n  setLocalState(state: T) {\n    const wasEmpty = this.inner.getState(this.peer) == null;\n    this.inner.setLocalState(state);\n    if (wasEmpty) {\n      this.listeners.forEach((listener) => {\n        listener(\n          { updated: [], added: [this.inner.peer()], removed: [] },\n          \"local\",\n        );\n      });\n    } else {\n      this.listeners.forEach((listener) => {\n        listener(\n          { updated: [this.inner.peer()], added: [], removed: [] },\n          \"local\",\n        );\n      });\n    }\n\n    this.startTimerIfNotEmpty();\n  }\n\n  getLocalState(): T | undefined {\n    return this.inner.getState(this.peer);\n  }\n\n  getAllStates(): Record<PeerID, T> {\n    return this.inner.getAllStates();\n  }\n\n  encode(peers: PeerID[]): Uint8Array {\n    return this.inner.encode(peers);\n  }\n\n  encodeAll(): Uint8Array {\n    return this.inner.encodeAll();\n  }\n\n  addListener(listener: AwarenessListener) {\n    this.listeners.add(listener);\n  }\n\n  removeListener(listener: AwarenessListener) {\n    this.listeners.delete(listener);\n  }\n\n  peers(): PeerID[] {\n    return this.inner.peers();\n  }\n\n  destroy() {\n    clearInterval(this.timer);\n    this.listeners.clear();\n  }\n\n  private startTimerIfNotEmpty() {\n    if (this.inner.isEmpty() || this.timer != null) {\n      return;\n    }\n\n    this.timer = setInterval(() => {\n      const removed = this.inner.removeOutdated();\n      if (removed.length > 0) {\n        this.listeners.forEach((listener) => {\n          listener({ updated: [], added: [], removed }, \"timeout\");\n        });\n      }\n      if (this.inner.isEmpty()) {\n        clearInterval(this.timer);\n        this.timer = undefined;\n      }\n    }, this.timeout / 2) as unknown as number;\n  }\n}\n\n/**\n * EphemeralStore tracks ephemeral key-value state across peers.\n *\n * - Use it for lightweight presence/state like cursors, selections, and UI hints.\n * - Conflict resolution is timestamp-based LWW (Last-Write-Wins) per key.\n * - Timeout unit: milliseconds.\n * - After timeout: keys are considered expired. They are omitted from\n *   `encode(key)`, `encodeAll()` and `getAllStates()`. A periodic cleanup runs\n *   while the store is non-empty and removes expired keys; when removals happen\n *   subscribers receive an event with `by: \"timeout\"` and the `removed` keys.\n *\n * See: https://loro.dev/docs/tutorial/ephemeral\n *\n * @param timeout Inactivity timeout in milliseconds (default: 30000). If a key\n * doesn't receive updates within this duration, it will expire and be removed\n * on the next cleanup tick.\n *\n * @example\n * ```ts\n * const store = new EphemeralStore();\n * const store2 = new EphemeralStore();\n * // Subscribe to local updates and forward over the wire\n * store.subscribeLocalUpdates((data) => {\n *   store2.apply(data);\n * });\n * // Subscribe to all updates (including removals by timeout)\n * store2.subscribe((event) => {\n *   console.log(\"event:\", event);\n * });\n * // Set a value\n * store.set(\"key\", \"value\");\n * // Encode the value\n * const encoded = store.encode(\"key\");\n * // Apply the encoded value\n * store2.apply(encoded);\n * ```\n */\nexport class EphemeralStore<\n  T extends Record<string, Value> = Record<string, Value>,\n> {\n  inner: EphemeralStoreWasm;\n  private timer: number | undefined;\n  private timeout: number;\n  constructor(timeout: number = 30000) {\n    this.inner = new EphemeralStoreWasm(timeout);\n    this.timeout = timeout;\n  }\n\n  apply(bytes: Uint8Array) {\n    this.inner.apply(bytes);\n    this.startTimerIfNotEmpty();\n  }\n\n  set<K extends keyof T>(key: K, value: T[K]) {\n    this.inner.set(key as string, value);\n    this.startTimerIfNotEmpty();\n  }\n\n  delete<K extends keyof T>(key: K) {\n    this.inner.delete(key as string);\n  }\n\n  get<K extends keyof T>(key: K): T[K] | undefined {\n    return this.inner.get(key as string);\n  }\n\n  getAllStates(): Partial<T> {\n    return this.inner.getAllStates();\n  }\n\n  encode<K extends keyof T>(key: K): Uint8Array {\n    return this.inner.encode(key as string);\n  }\n\n  encodeAll(): Uint8Array {\n    return this.inner.encodeAll();\n  }\n\n  keys(): string[] {\n    return this.inner.keys();\n  }\n\n  destroy() {\n    clearInterval(this.timer);\n  }\n\n  subscribe(listener: EphemeralListener) {\n    return this.inner.subscribe(listener);\n  }\n\n  subscribeLocalUpdates(listener: EphemeralLocalListener) {\n    return this.inner.subscribeLocalUpdates(listener);\n  }\n\n  private startTimerIfNotEmpty() {\n    if (this.inner.isEmpty() || this.timer != null) {\n      return;\n    }\n\n    this.timer = setInterval(() => {\n      this.inner.removeOutdated();\n      if (this.inner.isEmpty()) {\n        clearInterval(this.timer);\n        this.timer = undefined;\n      }\n    }, this.timeout / 2) as unknown as number;\n  }\n}\n\nLoroDoc.prototype.toJsonWithReplacer = function (\n  replacer: (\n    key: string | number,\n    value: Value | Container,\n  ) => Value | Container | undefined,\n) {\n  const processed = new Set<string>();\n  const doc = this;\n  const m = (key: string | number, value: Value): Value | undefined => {\n    if (typeof value === \"string\") {\n      if (isContainerId(value) && !processed.has(value)) {\n        processed.add(value);\n        const container = doc.getContainerById(value);\n        if (container == null) {\n          throw new Error(`ContainerID not found: ${value}`);\n        }\n\n        const ans = replacer(key, container);\n        if (ans === container) {\n          const ans = container.getShallowValue();\n          if (typeof ans === \"object\") {\n            return run(ans as any);\n          }\n\n          return ans;\n        }\n\n        if (isContainer(ans)) {\n          throw new Error(\n            \"Using new container is not allowed in toJsonWithReplacer\",\n          );\n        }\n\n        if (typeof ans === \"object\" && ans != null) {\n          return run(ans as any);\n        }\n\n        return ans;\n      }\n    }\n\n    if (typeof value === \"object\" && value != null) {\n      return run(value as Record<string, Value>);\n    }\n\n    const ans = replacer(key, value);\n    if (isContainer(ans)) {\n      throw new Error(\n        \"Using new container is not allowed in toJsonWithReplacer\",\n      );\n    }\n\n    return ans;\n  };\n\n  const run = (layer: Record<string, Value> | Value[]): Value => {\n    if (Array.isArray(layer)) {\n      return layer\n        .map((item, index) => {\n          return m(index, item);\n        })\n        .filter((item): item is NonNullable<typeof item> => item !== undefined);\n    }\n\n    const result: Record<string, Value> = {};\n    for (const [key, value] of Object.entries(layer)) {\n      const ans = m(key, value);\n      if (ans !== undefined) {\n        result[key] = ans;\n      }\n    }\n\n    return result;\n  };\n\n  const layer = doc.getShallowValue();\n  return run(layer);\n};\n\nexport function idStrToId(idStr: `${number}@${PeerID}`): OpId {\n  const [counter, peer] = idStr.split(\"@\");\n  return {\n    counter: parseInt(counter),\n    peer: peer as PeerID,\n  };\n}\n\nconst CALL_PENDING_EVENTS_WRAPPED = Symbol(\"loro.callPendingEventsWrapped\");\n\nfunction decorateMethod(prototype: object, method: PropertyKey) {\n  const descriptor = Object.getOwnPropertyDescriptor(prototype, method);\n  if (!descriptor || typeof descriptor.value !== \"function\") {\n    return;\n  }\n\n  const original = descriptor.value as (...args: unknown[]) => unknown;\n  if ((original as any)[CALL_PENDING_EVENTS_WRAPPED]) {\n    return;\n  }\n\n  const wrapped = function (this: unknown, ...args: unknown[]) {\n    let result;\n    try {\n      result = original.apply(this, args);\n      return result;\n    } finally {\n      if (result && typeof (result as Promise<unknown>).then === \"function\") {\n        (result as Promise<unknown>).finally(() => {\n          callPendingEvents();\n        });\n      } else {\n        callPendingEvents();\n      }\n    }\n  };\n\n  (wrapped as any)[CALL_PENDING_EVENTS_WRAPPED] = true;\n\n  Object.defineProperty(prototype, method, {\n    ...descriptor,\n    value: wrapped,\n  });\n}\n\nfunction decorateMethods(prototype: object, methods: PropertyKey[]) {\n  for (const method of methods) {\n    decorateMethod(prototype, method);\n  }\n}\n\nfunction decorateAllPrototypeMethods(prototype: object) {\n  const visited = new Set<PropertyKey>();\n  let current: object | null = prototype;\n  while (\n    current &&\n    current !== Object.prototype &&\n    current !== Function.prototype\n  ) {\n    for (const property of Object.getOwnPropertyNames(current)) {\n      if (property === \"constructor\" || visited.has(property)) {\n        continue;\n      }\n      visited.add(property);\n      decorateMethod(current, property);\n    }\n\n    for (const symbol of Object.getOwnPropertySymbols(current)) {\n      if (visited.has(symbol)) {\n        continue;\n      }\n      visited.add(symbol);\n      decorateMethod(current, symbol);\n    }\n\n    current = Object.getPrototypeOf(current) as object | null;\n  }\n}\n\ndecorateMethods(LoroDoc.prototype, [\n  \"setDetachedEditing\",\n  \"attach\",\n  \"detach\",\n  \"fork\",\n  \"forkAt\",\n  \"checkoutToLatest\",\n  \"checkout\",\n  \"commit\",\n  \"getCursorPos\",\n  \"revertTo\",\n  \"export\",\n  \"exportJsonUpdates\",\n  \"exportJsonInIdSpan\",\n  \"importJsonUpdates\",\n  \"import\",\n  \"importUpdateBatch\",\n  \"importBatch\",\n  \"travelChangeAncestors\",\n  \"getChangedContainersIn\",\n  \"diff\",\n  \"applyDiff\",\n  \"setPeerId\",\n]);\n\ndecorateMethods(EphemeralStoreWasm.prototype, [\n  \"set\",\n  \"delete\",\n  \"apply\",\n  \"removeOutdated\",\n]);\n\ndecorateMethods(UndoManager.prototype, [\"undo\", \"redo\"]);\n"]}