{"version":3,"sources":["jsdelivr-header.js","/npm/@thi.ng/wasm-api@2.4.13/api.js","/npm/@thi.ng/wasm-api@2.4.13/bridge.js","/npm/@thi.ng/wasm-api@2.4.13/memory.js","/npm/@thi.ng/wasm-api@2.4.13/deftype.js","/npm/@thi.ng/wasm-api@2.4.13/object-index.js","/npm/@thi.ng/wasm-api@2.4.13/pointer.js","/npm/@thi.ng/wasm-api@2.4.13/string.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,goBCNK,MAAC,EAAuB,iBACvB,EAAc,QCDpB,IAAI,EAAY,OAAO,eACnB,EAAmB,OAAO,yBAmBzB,MAAC,EAAQ,GAAS,IAAM,UACvB,EAAmB,GAAS,IAAM,kBACrC,IAAC,EAAa,MACf,WAAA,CAAY,EAAU,GAAI,EAAS,IAAI,EAAc,SACnD,KAAK,OAAS,EACd,MAAM,EAAQ,GAAM,KAAK,OAAO,MAAM,GAChC,EAAQ,GAAW,CAAC,EAAM,IAAQ,KAAK,OAAO,OAAM,IAAM,EAAO,EAAM,GAAK,KAAK,QACvF,KAAK,IAAM,CACT,QAAS,EACT,QAAS,EACT,SAAU,EACV,SAAU,EACV,SAAU,EACV,SAAW,GAAM,KAAK,OAAO,MAAM,IAAM,GACzC,SAAW,GAAM,KAAK,OAAO,MAAM,GACnC,SAAW,GAAM,KAAK,OAAO,MAAM,GACnC,SAAU,EACV,SAAU,EACV,WAAa,GAAM,KAAK,OAAO,OAAM,IAAM,KAAK,EAAG,OACnD,YAAc,GAAM,KAAK,OAAO,OAAM,IAAM,KAAK,EAAI,OACrD,YAAc,GAAM,KAAK,OAAO,OAAM,IAAM,KAAK,EAAI,OACrD,YAAc,GAAM,KAAK,OAAO,OAAM,IAAM,KAAK,EAAO,OACxD,aAAc,CAAC,EAAM,KACnB,KAAK,eACL,IAAK,MAAM,KAAQ,EAAa,KAAK,GAAI,EAAM,GAC7C,KAAK,OAAO,MAAM,EAC5B,EAEM,cAAe,EAAK,KAAK,WA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AI,IAAI,KAAK,OAAS,EACtC,CACE,QAAI,CAAK,GACP,KAAK,IAAI,eACT,KAAK,IAAI,IAAI,KAAK,OAAS,GAAK,CACpC,CACE,UAAI,GACF,OAAqB,IAAd,KAAK,IAChB,CAQE,UAAI,GACF,MAAM,EAAO,KAAK,KAClB,IAAK,EAAM,OAAO,EAClB,MAAM,EAAM,KAAK,IAAI,GAAG,QAAQ,EAAG,GACnC,OAAO,GAAO,EAAI,EAAM,EAAO,CACnC,CAME,KAAA,GACE,MAAM,EAAO,KAAK,KAClB,OAAO,EAAO,KAAK,IAAI,UAAU,EAAM,KAAK,QAAU,EAC1D,CAqBE,GAAA,CAAI,GACF,MAAM,EAAO,KAAK,KACb,GAAM,EAAY,6BACJ,iBAAR,GACL,KAAK,SAAS,EAAY,6BAC9B,KAAK,IAAI,eACT,KAAK,IAAI,UAAU,EAAK,EAAM,KAAK,IAAI,GAAG,WAAa,GAAM,KAE7D,KAAK,KAAO,EAAI,KAChB,KAAK,QAAU,EAAI,QAEzB,CAWE,QAAA,CAAS,GACP,MAAM,EAAQ,EAAQ,KAAK,IAAK,GAAK,GAErC,OADA,KAAK,IAAI,IAAI,KAAK,OAAS,GAAK,EAAM,GAC/B,CACX,CACE,MAAA,GACE,OAAO,KAAK,OAChB,CACE,QAAA,GACE,OAAO,KAAK,OAChB,CACE,OAAA,GACE,OAAO,KAAK,OAChB,EAEA,MAAM,EAAU,CAAC,EAAK,EAAK,KACzB,MAAM,GAAM,IAAI,aAAc,OAAO,GAC/B,EAAQ,EAAI,SAAS,EAAI,SAAW,GAK1C,OAJI,EAAM,GAAK,IACb,EAAI,GAAG,IAAI,EAAK,EAAM,IACtB,IAAc,EAAI,GAAG,EAAM,GAAK,EAAI,QAAU,IAEzC,CAAK,S","file":"/npm/@thi.ng/wasm-api@2.4.13/index.js/+esm","sourceRoot":"","sourcesContent":["/**\n * Bundled by jsDelivr using Rollup v2.79.2 and Terser v5.39.0.\n * Original file: /npm/@thi.ng/wasm-api@2.4.13/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","const EVENT_MEMORY_CHANGED = \"memory-changed\";\nconst EVENT_PANIC = \"panic\";\nexport {\n  EVENT_MEMORY_CHANGED,\n  EVENT_PANIC\n};\n","var __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __decorateClass = (decorators, target, key, kind) => {\n  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;\n  for (var i = decorators.length - 1, decorator; i >= 0; i--)\n    if (decorator = decorators[i])\n      result = (kind ? decorator(target, key, result) : decorator(result)) || result;\n  if (kind && result) __defProp(target, key, result);\n  return result;\n};\nimport { INotifyMixin } from \"@thi.ng/api/mixins/inotify\";\nimport { topoSort } from \"@thi.ng/arrays/topo-sort\";\nimport { assert } from \"@thi.ng/errors/assert\";\nimport { defError } from \"@thi.ng/errors/deferror\";\nimport { U16, U32, U64BIG, U8, hexdumpLines } from \"@thi.ng/hex\";\nimport { ConsoleLogger } from \"@thi.ng/logger/console\";\nimport {\n  EVENT_MEMORY_CHANGED,\n  EVENT_PANIC\n} from \"./api.js\";\nconst Panic = defError(() => \"Panic\");\nconst OutOfMemoryError = defError(() => \"Out of memory\");\nlet WasmBridge = class {\n  constructor(modules = [], logger = new ConsoleLogger(\"wasm\")) {\n    this.logger = logger;\n    const logN = (x) => this.logger.debug(x);\n    const logA = (method) => (addr, len) => this.logger.debug(() => method(addr, len).join(\", \"));\n    this.api = {\n      printI8: logN,\n      printU8: logN,\n      printI16: logN,\n      printU16: logN,\n      printI32: logN,\n      printU32: (x) => this.logger.debug(x >>> 0),\n      printI64: (x) => this.logger.debug(x),\n      printU64: (x) => this.logger.debug(x),\n      printF32: logN,\n      printF64: logN,\n      printU8Hex: (x) => this.logger.debug(() => `0x${U8(x)}`),\n      printU16Hex: (x) => this.logger.debug(() => `0x${U16(x)}`),\n      printU32Hex: (x) => this.logger.debug(() => `0x${U32(x)}`),\n      printU64Hex: (x) => this.logger.debug(() => `0x${U64BIG(x)}`),\n      printHexdump: (addr, len) => {\n        this.ensureMemory();\n        for (const line of hexdumpLines(this.u8, addr, len)) {\n          this.logger.debug(line);\n        }\n      },\n      _printI8Array: logA(this.getI8Array.bind(this)),\n      _printU8Array: logA(this.getU8Array.bind(this)),\n      _printI16Array: logA(this.getI16Array.bind(this)),\n      _printU16Array: logA(this.getU16Array.bind(this)),\n      _printI32Array: logA(this.getI32Array.bind(this)),\n      _printU32Array: logA(this.getU32Array.bind(this)),\n      _printI64Array: logA(this.getI64Array.bind(this)),\n      _printU64Array: logA(this.getU64Array.bind(this)),\n      _printF32Array: logA(this.getF32Array.bind(this)),\n      _printF64Array: logA(this.getF64Array.bind(this)),\n      printStrZ: (addr) => this.logger.debug(() => this.getString(addr, 0)),\n      _printStr: (addr, len) => this.logger.debug(() => this.getString(addr, len)),\n      debug: () => {\n        debugger;\n      },\n      _panic: (addr, len) => {\n        const msg = this.getString(addr, len);\n        if (!this.notify({ id: EVENT_PANIC, value: msg })) {\n          throw new Panic(msg);\n        }\n      },\n      timer: () => performance.now(),\n      epoch: () => BigInt(Date.now())\n    };\n    this._buildModuleGraph(modules);\n  }\n  id = \"wasmapi\";\n  i8;\n  u8;\n  i16;\n  u16;\n  i32;\n  u32;\n  i64;\n  u64;\n  f32;\n  f64;\n  utf8Decoder = new TextDecoder();\n  utf8Encoder = new TextEncoder();\n  imports;\n  exports;\n  api;\n  modules;\n  order;\n  /**\n   * Takes array of root module specs, extracts all transitive dependencies,\n   * pre-computes their topological order, then calls\n   * {@link WasmModuleSpec.factory} for each module and stores all modules for\n   * future reference.\n   *\n   * @remarks\n   * Note: The pre-instantiated modules will only be fully initialized later\n   * via {@link WasmBridge.instantiate} or {@link WasmBridge.init}.\n   *\n   * @param specs\n   */\n  _buildModuleGraph(specs) {\n    const unique = /* @__PURE__ */ new Set();\n    const queue = [...specs];\n    while (queue.length) {\n      const mod = queue.shift();\n      unique.add(mod);\n      if (!mod.deps) continue;\n      for (const d of mod.deps) {\n        if (!unique.has(d)) queue.push(d);\n      }\n    }\n    const graph = [...unique].reduce((acc, mod) => {\n      assert(\n        (acc[mod.id] === void 0 || acc[mod.id] === mod) && mod.id !== this.id,\n        `duplicate API module ID: ${mod.id}`\n      );\n      acc[mod.id] = mod;\n      return acc;\n    }, {});\n    this.order = topoSort(graph, (mod) => mod.deps?.map((x) => x.id));\n    this.modules = this.order.reduce((acc, id) => {\n      acc[id] = graph[id].factory(this);\n      return acc;\n    }, {});\n  }\n  /**\n   * Instantiates WASM module from given `src` (and optional provided extra\n   * imports), then automatically calls {@link WasmBridge.init} with the\n   * modules exports.\n   *\n   * @remarks\n   * If the given `src` is a `Response` or `Promise<Response>`, the module\n   * will be instantiated via `WebAssembly.instantiateStreaming()`, otherwise\n   * the non-streaming version will be used.\n   *\n   * @param src\n   * @param imports\n   */\n  async instantiate(src, imports) {\n    const $src = await src;\n    const $imports = { ...this.getImports(), ...imports };\n    const wasm = await ($src instanceof Response ? WebAssembly.instantiateStreaming($src, $imports) : WebAssembly.instantiate($src, $imports));\n    return this.init(wasm.instance.exports);\n  }\n  /**\n   * Receives the WASM module's combined exports, stores them for future\n   * reference and then initializes all declared bridge child API modules in\n   * their stated dependency order. Returns false if any of the module\n   * initializations failed.\n   *\n   * @remarks\n   * Emits the {@link EVENT_MEMORY_CHANGED} event just before returning (and\n   * AFTER all child API modules have been initialized).\n   *\n   * @param exports\n   */\n  async init(exports) {\n    this.exports = exports;\n    this.ensureMemory(false);\n    for (const id of this.order) {\n      this.logger.debug(`initializing API module: ${id}`);\n      const status = await this.modules[id].init(this);\n      if (!status) return false;\n    }\n    this.notify({ id: EVENT_MEMORY_CHANGED, value: this.exports.memory });\n    return true;\n  }\n  /**\n   * Called automatically during initialization and from other memory\n   * accessors. Initializes and/or updates the various typed WASM memory views\n   * (e.g. after growing the WASM memory and the previous buffer becoming\n   * detached). Unless `notify` is false, the {@link EVENT_MEMORY_CHANGED}\n   * event will be emitted if the memory views had to be updated.\n   *\n   * @param notify\n   */\n  ensureMemory(notify = true) {\n    const buf = this.exports.memory.buffer;\n    if (this.u8?.buffer === buf) return;\n    this.i8 = new Int8Array(buf);\n    this.u8 = new Uint8Array(buf);\n    this.i16 = new Int16Array(buf);\n    this.u16 = new Uint16Array(buf);\n    this.i32 = new Int32Array(buf);\n    this.u32 = new Uint32Array(buf);\n    this.i64 = new BigInt64Array(buf);\n    this.u64 = new BigUint64Array(buf);\n    this.f32 = new Float32Array(buf);\n    this.f64 = new Float64Array(buf);\n    notify && this.notify({\n      id: EVENT_MEMORY_CHANGED,\n      value: this.exports.memory\n    });\n  }\n  /**\n   * Required use for WASM module instantiation to provide JS imports to the\n   * module. Returns an object of all WASM imports declared by the bridge core\n   * API and any provided bridge API modules.\n   *\n   * @remarks\n   * Each API module's imports will be in their own WASM import object/table,\n   * named using the same key which is defined by the JS side of the module\n   * via {@link WasmModuleSpec.id}. The bridge's core API is named `wasmapi`\n   * and is reserved.\n   *\n   * @example\n   * The following creates a bridge with a fictional `custom` API module:\n   *\n   * ```ts\n   * import { WasmBridge } from \"@thi.ng/wasm-api\";\n   *\n   * const bridge = new WasmBridge([new CustomAPI()]);\n   *\n   * // get combined imports object\n   * bridge.getImports();\n   * {\n   *   // imports defined by the core API of the bridge itself\n   *   wasmapi: { ... },\n   *   // imports defined by the CustomAPI module\n   *   custom: { ... }\n   * }\n   * ```\n   *\n   * Any related API bindings on the WASM (Zig) side then also need to refer\n   * to these custom import sections (also see `/zig/core.zig`):\n   *\n   * ```zig\n   * pub export \"custom\" fn foo(x: u32) void;\n   * ```\n   */\n  getImports() {\n    if (!this.imports) {\n      this.imports = { [this.id]: this.api };\n      for (const id in this.modules) {\n        this.imports[id] = this.modules[id].getImports();\n      }\n    }\n    return this.imports;\n  }\n  growMemory(numPages) {\n    this.exports.memory.grow(numPages);\n    this.ensureMemory();\n  }\n  allocate(numBytes, clear = false) {\n    const addr = this.exports._wasm_allocate(numBytes);\n    if (!addr)\n      throw new OutOfMemoryError(`unable to allocate: ${numBytes}`);\n    this.logger.fine(\n      () => `allocated ${numBytes} bytes @ 0x${U32(addr)} .. 0x${U32(\n        addr + numBytes - 1\n      )}`\n    );\n    this.ensureMemory();\n    clear && this.u8.fill(0, addr, addr + numBytes);\n    return [addr, numBytes];\n  }\n  free([addr, numBytes]) {\n    this.logger.fine(\n      () => `freeing memory @ 0x${U32(addr)} .. 0x${U32(\n        addr + numBytes - 1\n      )}`\n    );\n    this.exports._wasm_free(addr, numBytes);\n  }\n  getI8(addr) {\n    return this.i8[addr];\n  }\n  getU8(addr) {\n    return this.u8[addr];\n  }\n  getI16(addr) {\n    return this.i16[addr >> 1];\n  }\n  getU16(addr) {\n    return this.u16[addr >> 1];\n  }\n  getI32(addr) {\n    return this.i32[addr >> 2];\n  }\n  getU32(addr) {\n    return this.u32[addr >> 2];\n  }\n  getI64(addr) {\n    return this.i64[addr >> 3];\n  }\n  getU64(addr) {\n    return this.u64[addr >> 3];\n  }\n  getF32(addr) {\n    return this.f32[addr >> 2];\n  }\n  getF64(addr) {\n    return this.f64[addr >> 3];\n  }\n  setI8(addr, x) {\n    this.i8[addr] = x;\n    return this;\n  }\n  setU8(addr, x) {\n    this.u8[addr] = x;\n    return this;\n  }\n  setI16(addr, x) {\n    this.i16[addr >> 1] = x;\n    return this;\n  }\n  setU16(addr, x) {\n    this.u16[addr >> 1] = x;\n    return this;\n  }\n  setI32(addr, x) {\n    this.i32[addr >> 2] = x;\n    return this;\n  }\n  setU32(addr, x) {\n    this.u32[addr >> 2] = x;\n    return this;\n  }\n  setI64(addr, x) {\n    this.i64[addr >> 3] = x;\n    return this;\n  }\n  setU64(addr, x) {\n    this.u64[addr >> 3] = x;\n    return this;\n  }\n  setF32(addr, x) {\n    this.f32[addr >> 2] = x;\n    return this;\n  }\n  setF64(addr, x) {\n    this.f64[addr >> 3] = x;\n    return this;\n  }\n  getI8Array(addr, len) {\n    return this.i8.subarray(addr, addr + len);\n  }\n  getU8Array(addr, len) {\n    return this.u8.subarray(addr, addr + len);\n  }\n  getI16Array(addr, len) {\n    addr >>= 1;\n    return this.i16.subarray(addr, addr + len);\n  }\n  getU16Array(addr, len) {\n    addr >>= 1;\n    return this.u16.subarray(addr, addr + len);\n  }\n  getI32Array(addr, len) {\n    addr >>= 2;\n    return this.i32.subarray(addr, addr + len);\n  }\n  getU32Array(addr, len) {\n    addr >>= 2;\n    return this.u32.subarray(addr, addr + len);\n  }\n  getI64Array(addr, len) {\n    addr >>= 3;\n    return this.i64.subarray(addr, addr + len);\n  }\n  getU64Array(addr, len) {\n    addr >>= 3;\n    return this.u64.subarray(addr, addr + len);\n  }\n  getF32Array(addr, len) {\n    addr >>= 2;\n    return this.f32.subarray(addr, addr + len);\n  }\n  getF64Array(addr, len) {\n    addr >>= 3;\n    return this.f64.subarray(addr, addr + len);\n  }\n  setI8Array(addr, buf) {\n    this.i8.set(buf, addr);\n    return this;\n  }\n  setU8Array(addr, buf) {\n    this.u8.set(buf, addr);\n    return this;\n  }\n  setI16Array(addr, buf) {\n    this.i16.set(buf, addr >> 1);\n    return this;\n  }\n  setU16Array(addr, buf) {\n    this.u16.set(buf, addr >> 1);\n    return this;\n  }\n  setI32Array(addr, buf) {\n    this.i32.set(buf, addr >> 2);\n    return this;\n  }\n  setU32Array(addr, buf) {\n    this.u32.set(buf, addr >> 2);\n    return this;\n  }\n  setI64Array(addr, buf) {\n    this.i64.set(buf, addr >> 3);\n    return this;\n  }\n  setU64Array(addr, buf) {\n    this.u64.set(buf, addr >> 3);\n    return this;\n  }\n  setF32Array(addr, buf) {\n    this.f32.set(buf, addr >> 2);\n    return this;\n  }\n  setF64Array(addr, buf) {\n    this.f64.set(buf, addr >> 3);\n    return this;\n  }\n  getString(addr, len = 0) {\n    this.ensureMemory();\n    return this.utf8Decoder.decode(\n      this.u8.subarray(\n        addr,\n        len > 0 ? addr + len : this.u8.indexOf(0, addr)\n      )\n    );\n  }\n  setString(str, addr, maxBytes, terminate = true) {\n    this.ensureMemory();\n    maxBytes = Math.min(maxBytes, this.u8.length - addr);\n    const len = this.utf8Encoder.encodeInto(\n      str,\n      this.u8.subarray(addr, addr + maxBytes)\n    ).written;\n    assert(\n      len != null && len < maxBytes + (terminate ? 0 : 1),\n      `error writing string to 0x${U32(\n        addr\n      )} (max. ${maxBytes} bytes, got at least ${str.length})`\n    );\n    if (terminate) {\n      this.u8[addr + len] = 0;\n    }\n    return len;\n  }\n  getElementById(addr, len = 0) {\n    const id = this.getString(addr, len);\n    const el = document.getElementById(id);\n    assert(!!el, `missing DOM element #${id}`);\n    return el;\n  }\n  // @ts-ignore: mixin\n  // prettier-ignore\n  addListener(id, fn, scope) {\n  }\n  // @ts-ignore: mixin\n  // prettier-ignore\n  removeListener(id, fn, scope) {\n  }\n  // @ts-ignore: mixin\n  notify(event) {\n  }\n};\nWasmBridge = __decorateClass([\n  INotifyMixin\n], WasmBridge);\nexport {\n  OutOfMemoryError,\n  Panic,\n  WasmBridge\n};\n","const __instanceArray = (type, addr, num, size = type.size) => {\n  const items = [];\n  for (; num-- > 0; addr += size) items.push(type.instance(addr));\n  return items;\n};\nconst __array = (mem, ctor, addr, len) => __instanceArray(ctor(mem), addr, len);\nconst __slice32 = (mem, ctor, offset) => {\n  return __array(\n    mem,\n    ctor,\n    mem.u32[offset >>> 2],\n    mem.u32[offset + 4 >>> 2]\n  );\n};\nconst __slice64 = (mem, ctor, offset) => {\n  return __array(\n    mem,\n    ctor,\n    Number(mem.u64[offset >>> 3]),\n    Number(mem.u64[offset + 8 >>> 3])\n  );\n};\nconst __primslice32 = (mem, view, offset, shift) => {\n  const addr = mem.u32[offset >>> 2] >>> shift;\n  const len = mem.u32[offset + 4 >>> 2];\n  return view.subarray(addr, addr + len);\n};\nconst __primslice64 = (mem, view, offset, shift) => {\n  const addr = Number(mem.u64[offset >>> 3]) >>> shift;\n  const len = Number(mem.u64[offset + 8 >>> 3]);\n  return view.subarray(addr, addr + len);\n};\nexport {\n  __array,\n  __instanceArray,\n  __primslice32,\n  __primslice64,\n  __slice32,\n  __slice64\n};\n","import { __instanceArray } from \"./memory.js\";\nconst defType = (align, size, instance) => (mem) => ({\n  get align() {\n    return align;\n  },\n  get size() {\n    return size;\n  },\n  instanceArray(base, num) {\n    return __instanceArray(this, base, num);\n  },\n  instance: (base) => {\n    const inst = instance(mem, base);\n    Object.defineProperties(inst, {\n      __base: { value: base },\n      __bytes: {\n        get() {\n          return mem.u8.subarray(base, base + size);\n        }\n      }\n    });\n    return inst;\n  }\n});\nexport {\n  defType\n};\n","import { assert } from \"@thi.ng/errors/assert\";\nimport { IDGen } from \"@thi.ng/idgen\";\nlet __nextID = 0;\nclass ObjectIndex {\n  name;\n  logger;\n  idgen;\n  items = [];\n  constructor(opts) {\n    this.name = opts?.name ?? `idx-${__nextID++}`;\n    this.logger = opts?.logger;\n    this.idgen = new IDGen(opts?.bits ?? 32, 0);\n  }\n  keys() {\n    return this.idgen[Symbol.iterator]();\n  }\n  *values() {\n    for (const id of this.idgen) {\n      yield this.items[id];\n    }\n  }\n  /**\n   * Indexes given `item` and assigns it to the next available ID (which might\n   * be a previously freed ID) and returns it.\n   *\n   * @param item\n   */\n  add(item) {\n    const id = this.idgen.next();\n    this.logger?.debug(`adding ${this.name} ID: ${id}`);\n    this.items[id] = item;\n    return id;\n  }\n  /**\n   * Similar to {@link ObjectIndex.add}, but first checks if `item` has\n   * already been indexed and if so returns the ID of already indexed item\n   * without adding `item` to the index again. Uses `equiv` for checking item\n   * equality (by default: `===`).\n   *\n   * @remarks\n   * Currently an O(n) implementation.\n   *\n   * @param item\n   * @param equiv\n   */\n  addUnique(item, equiv = (x) => x === item) {\n    const id = this.find(equiv, false);\n    return id === void 0 ? this.add(item) : id;\n  }\n  /**\n   * Returns true if the given `id` is valid/active.\n   *\n   * @param id\n   */\n  has(id) {\n    return this.idgen.has(id);\n  }\n  /**\n   * First checks if given `id` is valid and if so frees it (for recycling)\n   * and deletes its corresponding item. If `ensure` is true (default), throws\n   * an error if the ID is invalid (otherwise returns false for invalid IDs).\n   *\n   * @param id\n   * @param ensure\n   */\n  delete(id, ensure = true) {\n    if (this.idgen.has(id)) {\n      this.logger?.debug(`deleting ${this.name} ID: ${id}`);\n      this.idgen.free(id);\n      delete this.items[id];\n      return true;\n    }\n    assert(!ensure, `can't delete missing ${this.name} ID: ${id}`);\n    return false;\n  }\n  get(id, ensure = true) {\n    ensure && assert(this.idgen.has(id), `missing ${this.name} for ID: ${id}`);\n    return this.items[id];\n  }\n  /**\n   * Applies given predicate to all active items and returns ID of first\n   * matching. If `ensure` is true (default), throws an error if the `pred`\n   * didn't match anything (otherwise returns undefined).\n   *\n   * @param pred\n   * @param ensure\n   */\n  find(pred, ensure = true) {\n    for (const id of this.idgen) {\n      if (pred(this.items[id])) return id;\n    }\n    assert(!ensure, `given predicate matched no ${this.name}`);\n  }\n}\nexport {\n  ObjectIndex\n};\n","class Pointer {\n  constructor(mem, base, fn) {\n    this.mem = mem;\n    this.base = base;\n    this.fn = fn;\n  }\n  get addr() {\n    this.mem.ensureMemory();\n    return this.mem.u32[this.base >>> 2];\n  }\n  set addr(addr) {\n    this.mem.ensureMemory();\n    this.mem.u32[this.base >>> 2] = addr;\n  }\n  get isNull() {\n    return this.addr === 0;\n  }\n  deref() {\n    const addr = this.addr;\n    return addr ? this.fn(addr) : void 0;\n  }\n}\nclass Pointer64 {\n  constructor(mem, base, fn) {\n    this.mem = mem;\n    this.base = base;\n    this.fn = fn;\n  }\n  get addr() {\n    this.mem.ensureMemory();\n    return this.mem.u64[Number(this.base >> BigInt(3))];\n  }\n  set addr(addr) {\n    this.mem.ensureMemory();\n    this.mem.u64[Number(this.base >> BigInt(3))] = addr;\n  }\n  get isNull() {\n    return this.addr === 0n;\n  }\n  deref() {\n    const addr = this.addr;\n    return addr ? this.fn(addr) : void 0;\n  }\n}\nexport {\n  Pointer,\n  Pointer64\n};\n","import { isNumber } from \"@thi.ng/checks/is-number\";\nimport { unsupported } from \"@thi.ng/errors/unsupported\";\nclass WasmStringSlice {\n  constructor(mem, base, isConst = true, terminated = true) {\n    this.mem = mem;\n    this.base = base;\n    this.isConst = isConst;\n    this.terminated = terminated;\n    this.maxLen = this.length;\n  }\n  maxLen;\n  /**\n   * Returns string start address (deref'd pointer).\n   */\n  get addr() {\n    this.mem.ensureMemory();\n    return this.mem.u32[this.base >>> 2];\n  }\n  /**\n   * Returns string length (read from memory)\n   */\n  get length() {\n    this.mem.ensureMemory();\n    return this.mem.u32[this.base + 4 >>> 2];\n  }\n  /**\n   * Returns memory as JS string (aka wrapper for\n   * {@link WasmBridge.getString}).\n   */\n  deref() {\n    return this.mem.getString(this.addr, this.length);\n  }\n  /**\n   * If given a JS string as arg (and if **not** a const slice), attempts to\n   * overwrite this wrapped string's memory with bytes from given string. If\n   * given another {@link WasmStringSlice} as arg, only the slice pointer &\n   * new length will be updated (always succeeds).\n   *\n   * @remarks\n   * When copying bytes from a JS string, an error will be thrown if the new\n   * string is longer than the _original_ length of the slice (i.e. from when\n   * this `WasmStringSlice` wrapper instance was created). Also updates the\n   * slice's length field to new string length.\n   *\n   * Passing a `WasmString` instance as arg is faster than JS string since\n   * only the slice definition itself will be updated.\n   *\n   * @param str\n   */\n  set(str) {\n    this.mem.ensureMemory();\n    if (typeof str === \"string\") {\n      if (this.isConst) unsupported(\"can't mutate const string\");\n      this.mem.u32[this.base + 4 >>> 2] = this.mem.setString(\n        str,\n        this.addr,\n        this.maxLen + ~~this.terminated,\n        this.terminated\n      );\n    } else {\n      this.mem.u32[this.base >>> 2] = str.addr;\n      this.mem.u32[this.base + 4 >>> 2] = str.length;\n    }\n  }\n  setSlice(...args) {\n    this.mem.ensureMemory();\n    const [slice, terminated] = isNumber(args[0]) ? [[args[0], args[1]], args[2]] : [args[0], args[1]];\n    this.mem.u32[this.base >>> 2] = slice[0];\n    this.mem.u32[this.base + 4 >>> 2] = slice[1];\n    this.terminated = terminated;\n    return slice;\n  }\n  /**\n   * Encodes given string to UTF-8 (by default zero terminated), allocates\n   * memory for it, updates this slice and returns a {@link MemorySlice} of\n   * the allocated region.\n   *\n   * @remarks\n   * If `terminated` is true, the stored slice length will **NOT** include the\n   * sentinel! E.g. the slice length of zero-terminated string `\"abc\"` is 3,\n   * but the number of allocated bytes is 4. This is done for compatibility\n   * with Zig's sentinel-terminated slice handling (e.g. `[:0]u8` slices).\n   *\n   * Regardless of `terminated` setting, the returned `MemorySlice` **always**\n   * covers the entire allocated region!\n   *\n   * @param str\n   * @param terminate\n   */\n  setAlloc(str, terminate = true) {\n    const slice = __alloc(this.mem, str, terminate);\n    this.setSlice(terminate ? [slice[0], slice[1] - 1] : slice, terminate);\n    return slice;\n  }\n  toJSON() {\n    return this.deref();\n  }\n  toString() {\n    return this.deref();\n  }\n  valueOf() {\n    return this.deref();\n  }\n}\nclass WasmStringPtr {\n  constructor(mem, base, isConst = true) {\n    this.mem = mem;\n    this.base = base;\n    this.isConst = isConst;\n  }\n  /**\n   * Returns string start address (deref'd pointer).\n   */\n  get addr() {\n    this.mem.ensureMemory();\n    return this.mem.u32[this.base >>> 2];\n  }\n  set addr(addr) {\n    this.mem.ensureMemory();\n    this.mem.u32[this.base >>> 2] = addr;\n  }\n  get isNull() {\n    return this.addr === 0;\n  }\n  /**\n   * Returns computed string length (scanning memory for zero sentinel)\n   *\n   * @remarks\n   * Always returns 0 if null pointer (i.e. if {@link WasmStringPtr.addr} is\n   * zero).\n   */\n  get length() {\n    const addr = this.addr;\n    if (!addr) return 0;\n    const idx = this.mem.u8.indexOf(0, addr);\n    return idx >= 0 ? idx - addr : 0;\n  }\n  /**\n   * Returns memory as JS string (via {@link WasmBridge.getString}). Returns\n   * empty string if null pointer (i.e. if {@link WasmStringPtr.addr} is\n   * zero).\n   */\n  deref() {\n    const addr = this.addr;\n    return addr ? this.mem.getString(addr, this.length) : \"\";\n  }\n  /**\n   * If given a JS string as arg (and if this `WasmStringPtr` instance itself\n   * is not a `const` pointer), attempts to overwrite this wrapped string's\n   * memory with bytes from given string. If given another\n   * {@link WasmStringPtr}, it merely overrides the pointer to the new one\n   * (always succeeds).\n   *\n   * @remarks\n   * Unlike with {@link WasmStringSlice.set} this implementation which\n   * performs bounds checking when copying bytes from a JS string, this method\n   * only throws an error if the new string is longer than the available\n   * memory (from the start address until the end of the WASM memory).\n   * **Therefore, this is as (un)safe as a C pointer and should be used with\n   * caution!**\n   *\n   * Passing a `WasmStringPtr` instance as arg is faster than JS string since\n   * only the pointer itself will be updated.\n   *\n   * @param str\n   */\n  set(str) {\n    const addr = this.addr;\n    if (!addr) unsupported(\"can't mutate null pointer\");\n    if (typeof str === \"string\") {\n      if (this.isConst) unsupported(\"can't mutate const string\");\n      this.mem.ensureMemory();\n      this.mem.setString(str, addr, this.mem.u8.byteLength - addr, true);\n    } else {\n      this.addr = str.addr;\n      this.isConst = str.isConst;\n    }\n  }\n  /**\n   * Encodes given string to UTF-8 (by default zero terminated), allocates\n   * memory for it, updates this pointer to new address and returns allocated\n   * {@link MemorySlice}.\n   *\n   * @remarks\n   * See {@link WasmStringSlice.setAlloc} for important details.\n   *\n   * @param str\n   */\n  setAlloc(str) {\n    const slice = __alloc(this.mem, str, true);\n    this.mem.u32[this.base >>> 2] = slice[0];\n    return slice;\n  }\n  toJSON() {\n    return this.deref();\n  }\n  toString() {\n    return this.deref();\n  }\n  valueOf() {\n    return this.deref();\n  }\n}\nconst __alloc = (mem, str, terminate) => {\n  const buf = new TextEncoder().encode(str);\n  const slice = mem.allocate(buf.length + ~~terminate);\n  if (slice[1] > 0) {\n    mem.u8.set(buf, slice[0]);\n    terminate && (mem.u8[slice[0] + buf.length] = 0);\n  }\n  return slice;\n};\nexport {\n  WasmStringPtr,\n  WasmStringSlice\n};\n"]}