@gmb/bitmark-parser 6.1.4 → 6.3.0

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../wasm-web/bitmark_wasm.js","../../../src/browser/worker-entry.ts"],"sourcesContent":["let wasm;\n\nlet WASM_VECTOR_LEN = 0;\n\nlet cachedUint8ArrayMemory0 = null;\n\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nconst cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );\n\nconst encodeString = (typeof cachedTextEncoder.encodeInto === 'function'\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n}\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n});\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nlet cachedDataViewMemory0 = null;\n\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nconst cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );\n\nif (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n/**\n * Lex bitmark input text, returning one line per token in the same format as\n * the Rust CLI: `{kind:?} {span:?} \"{text}\"`.\n *\n * `stage` selects the lexer pipeline:\n * - `\"lex\"` — combined (default)\n * - `\"lex-json\"` — combined, JSON array output\n * @param {string} input\n * @param {string} stage\n * @returns {string}\n */\nexport function lex(input, stage) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n wasm.lex(retptr, ptr0, len0, ptr1, len1);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred3_0 = r0;\n deferred3_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Parse bitmark input text and return the reference JSON format.\n *\n * Uses the full pipeline: parse → validate → serialize.\n *\n * `mode`: `\"optimized\"` (default) or `\"full\"`\n * @param {string} input\n * @param {string} mode\n * @returns {string}\n */\nexport function parse(input, mode) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n wasm.parse(retptr, ptr0, len0, ptr1, len1);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred3_0 = r0;\n deferred3_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Breakscape text (escape bitmark special characters).\n *\n * `format`: `\"bitmark++\"` (default) or `\"plainText\"`\n * `location`: `\"body\"` (default) or `\"tag\"`\n * @param {string} input\n * @param {string} format\n * @param {string} location\n * @returns {string}\n */\nexport function breakscape_text(input, format, location) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.breakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Unbreakscape text (unescape bitmark special characters).\n *\n * `format`: `\"bitmark++\"` (default) or `\"plainText\"`\n * `location`: `\"body\"` (default) or `\"tag\"`\n * @param {string} input\n * @param {string} format\n * @param {string} location\n * @returns {string}\n */\nexport function unbreakscape_text(input, format, location) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Split a JSON document (a top-level array of bit envelopes) into its per-bit\n * envelope objects, returned as a JSON array string. Lets a JS caller iterate\n * JSON-input bits for per-bit hooks (the JSON counterpart of [`split_bits`]).\n * Returns `error: …` if the input is not a JSON array of bits.\n * @param {string} input\n * @returns {string}\n */\nexport function split_json_bits(input) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.split_json_bits(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Pretty-print a compact JSON string with the given indent. Used to format a\n * document recombined on the JS side (the per-bit hook path) so its output\n * matches the in-Rust recombination byte-for-byte.\n * @param {string} json\n * @param {number} indent\n * @returns {string}\n */\nexport function prettify(json, indent) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.prettify(retptr, ptr0, len0, indent);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Convert a standalone bitmark text fragment ↔ TextAst (ProseMirror JSON).\n *\n * `direction`: `\"textToAst\"` | `\"astToText\"` | `\"astToPlainText\"`.\n * `format`: a bitmark text format (`\"bitmark++\"`, `\"bitmark+\"`) parses\n * inline marks; anything else is treated as plain text (textToAst only).\n * `location`: `\"body\"` (default) or `\"tag\"`.\n * Returns the converted fragment, or `error: …`.\n * @param {string} input\n * @param {string} direction\n * @param {string} format\n * @param {string} location\n * @returns {string}\n */\nexport function convert_text(input, direction, format, location) {\n let deferred5_0;\n let deferred5_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(direction, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n const ptr3 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len3 = WASM_VECTOR_LEN;\n wasm.convert_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred5_0 = r0;\n deferred5_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);\n }\n}\n\n/**\n * Apply a patch (a JSON array of patch entries) to every bit and re-emit.\n *\n * `input_format_sel`: `\"auto\"` | `\"bitmark\"` | `\"json\"`.\n * `output_format_sel`: `\"bitmark\"` | `\"json\"` (default json).\n * `patch_json`: the patch entry array (empty string = no patches, i.e. a\n * canonicalizing pass). Parallelism is a JS-side concern (web workers); this\n * runs sequentially. Returns the document text/JSON, or `error: …`.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {string} output_format_sel\n * @param {string} mode\n * @param {string} patch_json\n * @param {boolean} pretty\n * @param {number} indent\n * @param {number} spaces_around_values\n * @returns {string}\n */\nexport function transform(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {\n let deferred6_0;\n let deferred6_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len3 = WASM_VECTOR_LEN;\n const ptr4 = passStringToWasm0(patch_json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len4 = WASM_VECTOR_LEN;\n wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, pretty, indent, spaces_around_values);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred6_0 = r0;\n deferred6_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred6_0, deferred6_1, 1);\n }\n}\n\n/**\n * Query information about supported bit types.\n *\n * `info_type`: `\"list\"`, `\"bit\"`, `\"all\"`, or `\"deprecated\"`\n * `format`: `\"text\"` or `\"json\"`\n * `bit`: bit name (required when `info_type` is `\"bit\"`)\n * `pretty`: whether to pretty-print JSON output\n * `indent`: indent size for pretty-printing (default: 2)\n * @param {string} info_type\n * @param {string} format\n * @param {string} bit\n * @param {boolean} pretty\n * @param {number} indent\n * @returns {string}\n */\nexport function info(info_type, format, bit, pretty, indent) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(info_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(bit, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.info(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Convert between bitmark and JSON with explicit input/output formats + mode.\n *\n * `input_format`: `\"auto\"` (default) | `\"bitmark\"` | `\"json\"`.\n * `output_format`: `\"auto\"` (opposite of input) | `\"bitmark\"` | `\"json\"`.\n * `mode`: `\"optimized\"` (default) | `\"full\"`.\n * Returns the converted text/JSON, or a string prefixed `error:` on failure.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {string} output_format_sel\n * @param {string} mode\n * @param {boolean} pretty\n * @param {number} indent\n * @param {number} spaces_around_values\n * @returns {string}\n */\nexport function convert(input, input_format_sel, output_format_sel, mode, pretty, indent, spaces_around_values) {\n let deferred5_0;\n let deferred5_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len3 = WASM_VECTOR_LEN;\n wasm.convert(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pretty, indent, spaces_around_values);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred5_0 = r0;\n deferred5_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);\n }\n}\n\n/**\n * Re-emit input in its own format at optimized mode (omit natural defaults).\n *\n * `input_format`: `\"auto\"` (default) | `\"bitmark\"` | `\"json\"` | any config\n * mapping id (`html`, `xml`, …). The output is re-emitted in this same format.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {boolean} pretty\n * @param {number} indent\n * @returns {string}\n */\nexport function optimize(input, input_format_sel, pretty, indent) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n wasm.optimize(retptr, ptr0, len0, ptr1, len1, pretty, indent);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred3_0 = r0;\n deferred3_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Re-emit input in its own format at full mode (all keys).\n *\n * `input_format`: `\"auto\"` (default) | `\"bitmark\"` | `\"json\"` | any config\n * mapping id (`html`, `xml`, …). The output is re-emitted in this same format.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {boolean} pretty\n * @param {number} indent\n * @returns {string}\n */\nexport function fullize(input, input_format_sel, pretty, indent) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n wasm.fullize(retptr, ptr0, len0, ptr1, len1, pretty, indent);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred3_0 = r0;\n deferred3_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Re-emit input in its own format in canonical form at `mode`.\n *\n * `input_format`: `\"auto\"` (default) | `\"bitmark\"` | `\"json\"` | any config\n * mapping id (`html`, `xml`, …). The output is re-emitted in this same format.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {string} mode\n * @param {boolean} pretty\n * @param {number} indent\n * @param {number} spaces_around_values\n * @returns {string}\n */\nexport function canonicalize(input, input_format_sel, mode, pretty, indent, spaces_around_values) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent, spaces_around_values);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Count the bits in `input` (auto-detecting bitmark vs JSON).\n * Returns the count as a decimal string, or `error: …`.\n * @param {string} input\n * @returns {string}\n */\nexport function count_bits(input) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.count_bits(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Split a bitmark document into per-bit source slices.\n *\n * Returns a JSON array of `{ index, byteStart, byteEnd, source }`. Lets a JS\n * caller chunk a document at bit boundaries (e.g. to feed a worker pool).\n * @param {string} input\n * @returns {string}\n */\nexport function split_bits(input) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.split_bits(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Whether `input` looks like bitmark (vs JSON). Mirrors the auto-detection\n * used across the API so a JS caller can resolve `\"auto\"` consistently.\n * @param {string} input\n * @returns {boolean}\n */\nexport function is_bitmark(input) {\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.is_bitmark(ptr0, len0);\n return ret !== 0;\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n\n } catch (e) {\n if (module.headers.get('Content-Type') != 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n\n } else {\n return instance;\n }\n }\n}\n\nfunction __wbg_get_imports() {\n const imports = {};\n imports.wbg = {};\n\n return imports;\n}\n\nfunction __wbg_init_memory(imports, memory) {\n\n}\n\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n __wbg_init.__wbindgen_wasm_module = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n\n\n\n return wasm;\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (typeof module !== 'undefined') {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n\n __wbg_init_memory(imports);\n\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n\n const instance = new WebAssembly.Instance(module, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (typeof module_or_path !== 'undefined') {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (typeof module_or_path === 'undefined') {\n module_or_path = new URL('bitmark_wasm_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n __wbg_init_memory(imports);\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync };\nexport default __wbg_init;\n","// @zen-component: TS-BrowserWorkerEntry\n//\n// Browser Worker entry for the parallel transform pool. Each module worker\n// loads its own WASM instance (lazily, on the first job) and computes one bit\n// at a time from a data-only job. Hooks (JS closures) never reach here — they\n// run on the main thread.\n\nimport wasmInit, * as wasm from \"../../wasm-web/bitmark_wasm.js\";\nimport type { BitJob } from \"../core/hooked-transform.js\";\n\n// Minimal dedicated-worker scope (avoids needing the WebWorker tsconfig lib).\nconst ctx = self as unknown as {\n postMessage(message: unknown): void;\n addEventListener(type: \"message\", listener: (ev: { data: unknown }) => void): void;\n};\n\nlet ready: Promise<unknown> | null = null;\nfunction ensureReady(): Promise<unknown> {\n // The .wasm is copied beside this bundle (see tsup config).\n if (!ready) ready = wasmInit(new URL(\"bitmark_wasm_bg.wasm\", import.meta.url));\n return ready;\n}\n\nfunction stripArray(doc: string): string {\n const t = doc.trim();\n return t.startsWith(\"[\") && t.endsWith(\"]\") ? t.slice(1, -1) : doc;\n}\n\nctx.addEventListener(\"message\", (ev) => {\n const { id, job } = ev.data as { id: number; job: BitJob };\n ensureReady()\n .then(() => {\n const out = wasm.transform(\n job.source,\n job.inputFormat,\n job.outputFormat,\n job.mode,\n job.patchJson,\n false,\n 2,\n job.spacesAroundValues,\n );\n if (out.startsWith(\"error:\")) {\n ctx.postMessage({ id, ok: false, error: out });\n return;\n }\n const element = job.outputFormat === \"json\" ? stripArray(out) : out;\n ctx.postMessage({ id, ok: true, element });\n })\n .catch((e: unknown) => {\n ctx.postMessage({ id, ok: false, error: `error: ${String(e)}` });\n });\n});\n"],"mappings":";AAAA,IAAI;AAEJ,IAAI,kBAAkB;AAEtB,IAAI,0BAA0B;AAE9B,SAAS,uBAAuB;AAC5B,MAAI,4BAA4B,QAAQ,wBAAwB,eAAe,GAAG;AAC9E,8BAA0B,IAAI,WAAW,KAAK,OAAO,MAAM;AAAA,EAC/D;AACA,SAAO;AACX;AAEA,IAAM,oBAAqB,OAAO,gBAAgB,cAAc,IAAI,YAAY,OAAO,IAAI,EAAE,QAAQ,MAAM;AAAE,QAAM,MAAM,2BAA2B;AAAE,EAAE;AAExJ,IAAM,eAAgB,OAAO,kBAAkB,eAAe,aACxD,SAAU,KAAK,MAAM;AACvB,SAAO,kBAAkB,WAAW,KAAK,IAAI;AACjD,IACM,SAAU,KAAK,MAAM;AACvB,QAAM,MAAM,kBAAkB,OAAO,GAAG;AACxC,OAAK,IAAI,GAAG;AACZ,SAAO;AAAA,IACH,MAAM,IAAI;AAAA,IACV,SAAS,IAAI;AAAA,EACjB;AACJ;AAEA,SAAS,kBAAkB,KAAK,QAAQ,SAAS;AAE7C,MAAI,YAAY,QAAW;AACvB,UAAM,MAAM,kBAAkB,OAAO,GAAG;AACxC,UAAMA,OAAM,OAAO,IAAI,QAAQ,CAAC,MAAM;AACtC,yBAAqB,EAAE,SAASA,MAAKA,OAAM,IAAI,MAAM,EAAE,IAAI,GAAG;AAC9D,sBAAkB,IAAI;AACtB,WAAOA;AAAA,EACX;AAEA,MAAI,MAAM,IAAI;AACd,MAAI,MAAM,OAAO,KAAK,CAAC,MAAM;AAE7B,QAAM,MAAM,qB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Y,GAAG,CAAC;AAC7E,SAAO;AACT;AAEA,SAAS,WAAW,KAAqB;AACvC,QAAM,IAAI,IAAI,KAAK;AACnB,SAAO,EAAE,WAAW,GAAG,KAAK,EAAE,SAAS,GAAG,IAAI,EAAE,MAAM,GAAG,EAAE,IAAI;AACjE;AAEA,IAAI,iBAAiB,WAAW,CAAC,OAAO;AACtC,QAAM,EAAE,IAAI,IAAI,IAAI,GAAG;AACvB,cAAY,EACT,KAAK,MAAM;AACV,UAAM,MAAW;AAAA,MACf,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ;AAAA,MACA;AAAA,MACA,IAAI;AAAA,IACN;AACA,QAAI,IAAI,WAAW,QAAQ,GAAG;AAC5B,UAAI,YAAY,EAAE,IAAI,IAAI,OAAO,OAAO,IAAI,CAAC;AAC7C;AAAA,IACF;AACA,UAAM,UAAU,IAAI,iBAAiB,SAAS,WAAW,GAAG,IAAI;AAChE,QAAI,YAAY,EAAE,IAAI,IAAI,MAAM,QAAQ,CAAC;AAAA,EAC3C,CAAC,EACA,MAAM,CAAC,MAAe;AACrB,QAAI,YAAY,EAAE,IAAI,IAAI,OAAO,OAAO,UAAU,OAAO,CAAC,CAAC,GAAG,CAAC;AAAA,EACjE,CAAC;AACL,CAAC;","names":["ptr"]}
1
+ {"version":3,"sources":["../../../wasm-web/bitmark_wasm.js","../../../src/browser/worker-entry.ts"],"sourcesContent":["let wasm;\n\nlet WASM_VECTOR_LEN = 0;\n\nlet cachedUint8ArrayMemory0 = null;\n\nfunction getUint8ArrayMemory0() {\n if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {\n cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);\n }\n return cachedUint8ArrayMemory0;\n}\n\nconst cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );\n\nconst encodeString = (typeof cachedTextEncoder.encodeInto === 'function'\n ? function (arg, view) {\n return cachedTextEncoder.encodeInto(arg, view);\n}\n : function (arg, view) {\n const buf = cachedTextEncoder.encode(arg);\n view.set(buf);\n return {\n read: arg.length,\n written: buf.length\n };\n});\n\nfunction passStringToWasm0(arg, malloc, realloc) {\n\n if (realloc === undefined) {\n const buf = cachedTextEncoder.encode(arg);\n const ptr = malloc(buf.length, 1) >>> 0;\n getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);\n WASM_VECTOR_LEN = buf.length;\n return ptr;\n }\n\n let len = arg.length;\n let ptr = malloc(len, 1) >>> 0;\n\n const mem = getUint8ArrayMemory0();\n\n let offset = 0;\n\n for (; offset < len; offset++) {\n const code = arg.charCodeAt(offset);\n if (code > 0x7F) break;\n mem[ptr + offset] = code;\n }\n\n if (offset !== len) {\n if (offset !== 0) {\n arg = arg.slice(offset);\n }\n ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;\n const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);\n const ret = encodeString(arg, view);\n\n offset += ret.written;\n ptr = realloc(ptr, len, offset, 1) >>> 0;\n }\n\n WASM_VECTOR_LEN = offset;\n return ptr;\n}\n\nlet cachedDataViewMemory0 = null;\n\nfunction getDataViewMemory0() {\n if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {\n cachedDataViewMemory0 = new DataView(wasm.memory.buffer);\n }\n return cachedDataViewMemory0;\n}\n\nconst cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );\n\nif (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };\n\nfunction getStringFromWasm0(ptr, len) {\n ptr = ptr >>> 0;\n return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));\n}\n/**\n * Lex bitmark input text, returning one line per token in the same format as\n * the Rust CLI: `{kind:?} {span:?} \"{text}\"`.\n *\n * `stage` selects the lexer pipeline:\n * - `\"lex\"` — combined (default)\n * - `\"lex-json\"` — combined, JSON array output\n * @param {string} input\n * @param {string} stage\n * @returns {string}\n */\nexport function lex(input, stage) {\n let deferred3_0;\n let deferred3_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n wasm.lex(retptr, ptr0, len0, ptr1, len1);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred3_0 = r0;\n deferred3_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);\n }\n}\n\n/**\n * Breakscape text (escape bitmark special characters).\n *\n * `format`: `\"bitmark++\"` (default) or `\"plainText\"`\n * `location`: `\"body\"` (default) or `\"tag\"`\n * @param {string} input\n * @param {string} format\n * @param {string} location\n * @returns {string}\n */\nexport function breakscape_text(input, format, location) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.breakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Unbreakscape text (unescape bitmark special characters).\n *\n * `format`: `\"bitmark++\"` (default) or `\"plainText\"`\n * `location`: `\"body\"` (default) or `\"tag\"`\n * @param {string} input\n * @param {string} format\n * @param {string} location\n * @returns {string}\n */\nexport function unbreakscape_text(input, format, location) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Query information about supported bit types.\n *\n * `info_type`: `\"list\"`, `\"bit\"`, `\"all\"`, or `\"deprecated\"`\n * `format`: `\"text\"` or `\"json\"`\n * `bit`: bit name (required when `info_type` is `\"bit\"`)\n * `pretty`: whether to pretty-print JSON output\n * `indent`: indent size for pretty-printing (default: 2)\n * @param {string} info_type\n * @param {string} format\n * @param {string} bit\n * @param {boolean} pretty\n * @param {number} indent\n * @returns {string}\n */\nexport function info(info_type, format, bit, pretty, indent) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(info_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(bit, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.info(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Apply a patch (a JSON array of patch entries) to every bit and re-emit.\n *\n * `input_format_sel`: `\"auto\"` | `\"bitmark\"` | `\"json\"`.\n * `output_format_sel`: `\"bitmark\"` | `\"json\"` (default json).\n * `patch_json`: the patch entry array (empty string = no patches, i.e. a\n * canonicalizing pass). Parallelism is a JS-side concern (web workers); this\n * runs sequentially. Returns the document text/JSON, or `error: …`.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {string} output_format_sel\n * @param {string} mode\n * @param {string} patch_json\n * @param {boolean} pretty\n * @param {number} indent\n * @param {number} spaces_around_values\n * @returns {string}\n */\nexport function transform(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {\n let deferred6_0;\n let deferred6_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len3 = WASM_VECTOR_LEN;\n const ptr4 = passStringToWasm0(patch_json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len4 = WASM_VECTOR_LEN;\n wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, pretty, indent, spaces_around_values);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred6_0 = r0;\n deferred6_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred6_0, deferred6_1, 1);\n }\n}\n\n/**\n * Convert between bitmark and JSON with explicit input/output formats + mode.\n *\n * `input_format`: `\"auto\"` (default) | `\"bitmark\"` | `\"json\"`.\n * `output_format`: `\"auto\"` (opposite of input) | `\"bitmark\"` | `\"json\"`.\n * `mode`: `\"optimized\"` (default) | `\"full\"`.\n * Returns the converted text/JSON, or a string prefixed `error:` on failure.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {string} output_format_sel\n * @param {string} mode\n * @param {boolean} pretty\n * @param {number} indent\n * @param {number} spaces_around_values\n * @param {boolean} include_unknown_properties\n * @returns {string}\n */\nexport function convert(input, input_format_sel, output_format_sel, mode, pretty, indent, spaces_around_values, include_unknown_properties) {\n let deferred5_0;\n let deferred5_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len3 = WASM_VECTOR_LEN;\n wasm.convert(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pretty, indent, spaces_around_values, include_unknown_properties);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred5_0 = r0;\n deferred5_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);\n }\n}\n\n/**\n * Re-emit input in its own format in canonical form at `mode`.\n *\n * `input_format`: `\"auto\"` (default) | `\"bitmark\"` | `\"json\"` | any config\n * mapping id (`html`, `xml`, …). The output is re-emitted in this same format.\n * @param {string} input\n * @param {string} input_format_sel\n * @param {string} mode\n * @param {boolean} pretty\n * @param {number} indent\n * @param {number} spaces_around_values\n * @returns {string}\n */\nexport function canonicalize(input, input_format_sel, mode, pretty, indent, spaces_around_values) {\n let deferred4_0;\n let deferred4_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent, spaces_around_values);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred4_0 = r0;\n deferred4_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);\n }\n}\n\n/**\n * Count the bits in `input` (auto-detecting bitmark vs JSON).\n * Returns the count as a decimal string, or `error: …`.\n * @param {string} input\n * @returns {string}\n */\nexport function count_bits(input) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.count_bits(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Split a bitmark document into per-bit source slices.\n *\n * Returns a JSON array of `{ index, byteStart, byteEnd, source }`. Lets a JS\n * caller chunk a document at bit boundaries (e.g. to feed a worker pool).\n * @param {string} input\n * @returns {string}\n */\nexport function split_bits(input) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.split_bits(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Whether `input` looks like bitmark (vs JSON). Mirrors the auto-detection\n * used across the API so a JS caller can resolve `\"auto\"` consistently.\n * @param {string} input\n * @returns {boolean}\n */\nexport function is_bitmark(input) {\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ret = wasm.is_bitmark(ptr0, len0);\n return ret !== 0;\n}\n\n/**\n * Split a JSON document (a top-level array of bit envelopes) into its per-bit\n * envelope objects, returned as a JSON array string. Lets a JS caller iterate\n * JSON-input bits for per-bit hooks (the JSON counterpart of [`split_bits`]).\n * Returns `error: …` if the input is not a JSON array of bits.\n * @param {string} input\n * @returns {string}\n */\nexport function split_json_bits(input) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.split_json_bits(retptr, ptr0, len0);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Pretty-print a compact JSON string with the given indent. Used to format a\n * document recombined on the JS side (the per-bit hook path) so its output\n * matches the in-Rust recombination byte-for-byte.\n * @param {string} json\n * @param {number} indent\n * @returns {string}\n */\nexport function prettify(json, indent) {\n let deferred2_0;\n let deferred2_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n wasm.prettify(retptr, ptr0, len0, indent);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred2_0 = r0;\n deferred2_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);\n }\n}\n\n/**\n * Convert a standalone bitmark text fragment ↔ TextAst (ProseMirror JSON).\n *\n * `direction`: `\"textToAst\"` | `\"astToText\"` | `\"astToPlainText\"`.\n * `format`: a bitmark text format (`\"bitmark++\"`, `\"bitmark+\"`) parses\n * inline marks; anything else is treated as plain text (textToAst only).\n * `location`: `\"body\"` (default) or `\"tag\"`.\n * Returns the converted fragment, or `error: …`.\n * @param {string} input\n * @param {string} direction\n * @param {string} format\n * @param {string} location\n * @returns {string}\n */\nexport function convert_text(input, direction, format, location) {\n let deferred5_0;\n let deferred5_1;\n try {\n const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);\n const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len0 = WASM_VECTOR_LEN;\n const ptr1 = passStringToWasm0(direction, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len1 = WASM_VECTOR_LEN;\n const ptr2 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len2 = WASM_VECTOR_LEN;\n const ptr3 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);\n const len3 = WASM_VECTOR_LEN;\n wasm.convert_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);\n var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);\n var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);\n deferred5_0 = r0;\n deferred5_1 = r1;\n return getStringFromWasm0(r0, r1);\n } finally {\n wasm.__wbindgen_add_to_stack_pointer(16);\n wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);\n }\n}\n\nasync function __wbg_load(module, imports) {\n if (typeof Response === 'function' && module instanceof Response) {\n if (typeof WebAssembly.instantiateStreaming === 'function') {\n try {\n return await WebAssembly.instantiateStreaming(module, imports);\n\n } catch (e) {\n if (module.headers.get('Content-Type') != 'application/wasm') {\n console.warn(\"`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\\n\", e);\n\n } else {\n throw e;\n }\n }\n }\n\n const bytes = await module.arrayBuffer();\n return await WebAssembly.instantiate(bytes, imports);\n\n } else {\n const instance = await WebAssembly.instantiate(module, imports);\n\n if (instance instanceof WebAssembly.Instance) {\n return { instance, module };\n\n } else {\n return instance;\n }\n }\n}\n\nfunction __wbg_get_imports() {\n const imports = {};\n imports.wbg = {};\n\n return imports;\n}\n\nfunction __wbg_init_memory(imports, memory) {\n\n}\n\nfunction __wbg_finalize_init(instance, module) {\n wasm = instance.exports;\n __wbg_init.__wbindgen_wasm_module = module;\n cachedDataViewMemory0 = null;\n cachedUint8ArrayMemory0 = null;\n\n\n\n return wasm;\n}\n\nfunction initSync(module) {\n if (wasm !== undefined) return wasm;\n\n\n if (typeof module !== 'undefined') {\n if (Object.getPrototypeOf(module) === Object.prototype) {\n ({module} = module)\n } else {\n console.warn('using deprecated parameters for `initSync()`; pass a single object instead')\n }\n }\n\n const imports = __wbg_get_imports();\n\n __wbg_init_memory(imports);\n\n if (!(module instanceof WebAssembly.Module)) {\n module = new WebAssembly.Module(module);\n }\n\n const instance = new WebAssembly.Instance(module, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nasync function __wbg_init(module_or_path) {\n if (wasm !== undefined) return wasm;\n\n\n if (typeof module_or_path !== 'undefined') {\n if (Object.getPrototypeOf(module_or_path) === Object.prototype) {\n ({module_or_path} = module_or_path)\n } else {\n console.warn('using deprecated parameters for the initialization function; pass a single object instead')\n }\n }\n\n if (typeof module_or_path === 'undefined') {\n module_or_path = new URL('bitmark_wasm_bg.wasm', import.meta.url);\n }\n const imports = __wbg_get_imports();\n\n if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {\n module_or_path = fetch(module_or_path);\n }\n\n __wbg_init_memory(imports);\n\n const { instance, module } = await __wbg_load(await module_or_path, imports);\n\n return __wbg_finalize_init(instance, module);\n}\n\nexport { initSync };\nexport default __wbg_init;\n","// @zen-component: TS-BrowserWorkerEntry\n//\n// Browser Worker entry for the parallel transform pool. Each module worker\n// loads its own WASM instance (lazily, on the first job) and computes one bit\n// at a time from a data-only job. Hooks (JS closures) never reach here — they\n// run on the main thread.\n\nimport wasmInit, * as wasm from \"../../wasm-web/bitmark_wasm.js\";\nimport type { BitJob } from \"../core/hooked-transform.js\";\n\n// Minimal dedicated-worker scope (avoids needing the WebWorker tsconfig lib).\nconst ctx = self as unknown as {\n postMessage(message: unknown): void;\n addEventListener(type: \"message\", listener: (ev: { data: unknown }) => void): void;\n};\n\nlet ready: Promise<unknown> | null = null;\nfunction ensureReady(): Promise<unknown> {\n // The .wasm is copied beside this bundle (see tsup config).\n if (!ready) ready = wasmInit(new URL(\"bitmark_wasm_bg.wasm\", import.meta.url));\n return ready;\n}\n\nfunction stripArray(doc: string): string {\n const t = doc.trim();\n return t.startsWith(\"[\") && t.endsWith(\"]\") ? t.slice(1, -1) : doc;\n}\n\nctx.addEventListener(\"message\", (ev) => {\n const { id, job } = ev.data as { id: number; job: BitJob };\n ensureReady()\n .then(() => {\n const out = wasm.transform(\n job.source,\n job.inputFormat,\n job.outputFormat,\n job.mode,\n job.patchJson,\n false,\n 2,\n job.spacesAroundValues,\n );\n if (out.startsWith(\"error:\")) {\n ctx.postMessage({ id, ok: false, error: out });\n return;\n }\n const element = job.outputFormat === \"json\" ? stripArray(out) : out;\n ctx.postMessage({ id, ok: true, element });\n })\n .catch((e: unknown) => {\n ctx.postMessage({ id, ok: false, error: `error: ${String(e)}` });\n });\n});\n"],"mappings":";AAAA,IAAI;AAEJ,IAAI,kBAAkB;AAEtB,IAAI,0BAA0B;AAE9B,SAAS,uBAAuB;AAC5B,MAAI,4BAA4B,QAAQ,wBAAwB,eAAe,GAAG;AAC9E,8BAA0B,IAAI,WAAW,KAAK,OAAO,MAAM;AAAA,EAC/D;AACA,SAAO;AACX;AAEA,IAAM,oBAAqB,OAAO,gBAAgB,cAAc,IAAI,YAAY,OAAO,IAAI,EAAE,QAAQ,MAAM;AAAE,QAAM,MAAM,2BAA2B;AAAE,EAAE;AAExJ,IAAM,eAAgB,OAAO,kBAAkB,eAAe,aACxD,SAAU,KAAK,MAAM;AACvB,SAAO,kBAAkB,WAAW,KAAK,IAAI;AACjD,IACM,SAAU,KAAK,MAAM;AACvB,QAAM,MAAM,kBAAkB,OAAO,GAAG;AACxC,OAAK,IAAI,GAAG;AACZ,SAAO;AAAA,IACH,MAAM,IAAI;AAAA,IACV,SAAS,IAAI;AAAA,EACjB;AACJ;AAEA,SAAS,kBAAkB,KAAK,QAAQ,SAAS;AAE7C,MAAI,YAAY,QAAW;AACvB,UAAM,MAAM,kBAAkB,OAAO,GAAG;AACxC,UAAMA,OAAM,OAAO,IAAI,QAAQ,CAAC,MAAM;AACtC,yBAAqB,EAAE,SAASA,MAAKA,OAAM,IAAI,MAAM,EAAE,IAAI,GAAG;AAC9D,sBAAkB,IAAI;AACtB,WAAOA;AAAA,EACX;AAEA,MAAI,MAAM,IAAI;AACd,MAAI,MAAM,OAAO,KAAK,CAAC,MAAM;AAE7B,QAAM,MAAM,qBAAqB;AAEjC,MAAI,SAAS;AAEb,SAAO,SAAS,KAAK,UAAU;AAC3B,UAAM,OAAO,IAAI,WAAW,MAAM;AAClC,QAAI,OAAO,IAAM;AACjB,QAAI,MAAM,MAAM,IAAI;AAAA,E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MAAM,GAAG,EAAE,IAAI;AACjE;AAEA,IAAI,iBAAiB,WAAW,CAAC,OAAO;AACtC,QAAM,EAAE,IAAI,IAAI,IAAI,GAAG;AACvB,cAAY,EACT,KAAK,MAAM;AACV,UAAM,MAAW;AAAA,MACf,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ,IAAI;AAAA,MACJ;AAAA,MACA;AAAA,MACA,IAAI;AAAA,IACN;AACA,QAAI,IAAI,WAAW,QAAQ,GAAG;AAC5B,UAAI,YAAY,EAAE,IAAI,IAAI,OAAO,OAAO,IAAI,CAAC;AAC7C;AAAA,IACF;AACA,UAAM,UAAU,IAAI,iBAAiB,SAAS,WAAW,GAAG,IAAI;AAChE,QAAI,YAAY,EAAE,IAAI,IAAI,MAAM,QAAQ,CAAC;AAAA,EAC3C,CAAC,EACA,MAAM,CAAC,MAAe;AACrB,QAAI,YAAY,EAAE,IAAI,IAAI,OAAO,OAAO,UAAU,OAAO,CAAC,CAAC,GAAG,CAAC;AAAA,EACjE,CAAC;AACL,CAAC;","names":["ptr"]}
package/dist/index.cjs CHANGED
@@ -30,18 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ bitmarkToObjects: () => bitmarkToObjects,
33
34
  breakscapeText: () => breakscapeText,
34
35
  canonicalize: () => canonicalize,
35
36
  convert: () => convert,
36
37
  countBits: () => countBits,
37
- expand: () => expand,
38
- fullize: () => fullize,
39
- generate: () => generate,
40
38
  info: () => info,
41
39
  legacy: () => legacy_exports,
42
40
  lex: () => lex,
43
- optimize: () => optimize,
44
- parse: () => parse,
41
+ objectsToBitmark: () => objectsToBitmark,
42
+ patchEntry: () => patchEntry,
45
43
  splitBits: () => splitBits,
46
44
  transform: () => transform,
47
45
  transformParallel: () => transformParallel,
@@ -60,7 +58,7 @@ var import_node_module = require("module");
60
58
  // src/generated/package_info.ts
61
59
  var PACKAGE_INFO = {
62
60
  "name": "@gmb/bitmark-parser",
63
- "version": "6.1.4",
61
+ "version": "6.3.0",
64
62
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
65
63
  "license": "ISC",
66
64
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -100,7 +98,7 @@ function buildUnits(wasm2, input, inputIsBitmark) {
100
98
  if (isError(out)) throw new Error(out);
101
99
  const envelopes = JSON.parse(out);
102
100
  return envelopes.map((env, index) => ({
103
- view: { format: "json", index, total: envelopes.length, bit: env.bit },
101
+ view: { format: "json", index, total: envelopes.length, bit: env.bit ?? {} },
104
102
  // Per-bit transform consumes a one-bit JSON document.
105
103
  source: JSON.stringify([env])
106
104
  }));
@@ -366,16 +364,14 @@ function validateVersionOptions(opts) {
366
364
  }
367
365
  function validateBitmarkOptions(o) {
368
366
  if (o.explicitTextFormat) unsupportedOption("bitmarkOptions.explicitTextFormat");
369
- if (o.prettifyJson !== void 0 && o.prettifyJson !== false) {
370
- unsupportedOption("bitmarkOptions.prettifyJson", "embedded-JSON body prettification is not supported");
367
+ if (o.cardSetVersion === 1) {
368
+ unsupportedOption("bitmarkOptions.cardSetVersion: 1", V3_ONLY);
371
369
  }
372
- if (o.cardSetVersion === 1) unsupportedOption("bitmarkOptions.cardSetVersion: 1", V3_ONLY);
373
370
  if (o.debugGenerationInline) unsupportedOption("bitmarkOptions.debugGenerationInline");
374
371
  if (o.noBreakscaping) unsupportedOption("bitmarkOptions.noBreakscaping");
375
372
  }
376
373
  function validateJsonOptions(o) {
377
374
  if (o.textAsPlainText) unsupportedOption("jsonOptions.textAsPlainText", V3_ONLY);
378
- if (o.excludeUnknownProperties) unsupportedOption("jsonOptions.excludeUnknownProperties");
379
375
  if (o.debugGenerationInline) unsupportedOption("jsonOptions.debugGenerationInline");
380
376
  }
381
377
  function prettyIndent(prettify) {
@@ -411,6 +407,14 @@ function isPseudoAst(v) {
411
407
  return v !== null && typeof v === "object" && (PSEUDO_AST_MARKER in v || Array.isArray(v.bits));
412
408
  }
413
409
 
410
+ // src/legacy/generated/resource-collection-keys.ts
411
+ var RESOURCE_COLLECTION_KEYS = {
412
+ "extractor-image": { key: "images", resourceType: "image" },
413
+ "extractor-image-collapsible": { key: "images", resourceType: "image" },
414
+ "images-logo-grave": { key: "logos", resourceType: "image" },
415
+ "prototype-images": { key: "images", resourceType: "image" }
416
+ };
417
+
414
418
  // src/legacy/builder.ts
415
419
  var BUILT_BIT_PARSER = /* @__PURE__ */ Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser");
416
420
  var DATA_KEY_TO_JSON_KEY = {
@@ -455,10 +459,14 @@ var Builder = class {
455
459
  * NOTE (documented divergences from bpg):
456
460
  * - the return value is bit JSON, not bpg's internal AST node model;
457
461
  * - `resourceType` (an inference hint in bpg) is not carried into the
458
- * JSON — the attached `resource` object is authoritative;
459
- * - more than one entry in `resources` passes through under a
460
- * `resources` key (kept visible, not silently dropped) — the canonical
461
- * single attachment is `resource`.
462
+ * JSON — the attached `resource` object is authoritative.
463
+ *
464
+ * `resources` follows bpg's JsonGenerator routing: on a bit whose config
465
+ * maps a repeatable resource tag group onto a collection key (e.g.
466
+ * `images` / `logos` — see the generated RESOURCE_COLLECTION_KEYS), the
467
+ * matching-type entries land under that key; on every other bit the first
468
+ * entry becomes the canonical single `resource` (as bpg: "if there is
469
+ * more than one resource, use the first one").
462
470
  */
463
471
  buildBit(data, _options) {
464
472
  const wasm2 = getLegacyWasm();
@@ -494,12 +502,15 @@ var Builder = class {
494
502
  delete src.__isDefaultExample;
495
503
  }
496
504
  const resources = src.resources;
497
- if (resources !== void 0) {
498
- if (Array.isArray(resources)) {
499
- if (resources.length === 1) bit.resource = resources[0];
500
- else if (resources.length > 1) bit.resources = resources;
501
- } else {
502
- bit.resource = resources;
505
+ if (resources !== void 0 && bitType !== void 0) {
506
+ const list = Array.isArray(resources) ? resources : [resources];
507
+ const collection = RESOURCE_COLLECTION_KEYS[bitType];
508
+ if (collection) {
509
+ bit[collection.key] = list.filter(
510
+ (r) => r !== null && typeof r === "object" && r.type === collection.resourceType
511
+ );
512
+ } else if (list.length >= 1) {
513
+ bit.resource = list[0];
503
514
  }
504
515
  delete src.resources;
505
516
  }
@@ -517,7 +528,7 @@ var Builder = class {
517
528
  }
518
529
  }
519
530
  this.parseStringTexts(bit);
520
- const out = wasm2.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1);
531
+ const out = wasm2.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false);
521
532
  if (out.startsWith("error:")) {
522
533
  throw new Error(out.slice("error:".length).trim());
523
534
  }
@@ -641,8 +652,10 @@ var BitmarkParserGenerator = class {
641
652
  const outputFormat = opts.outputFormat ?? (isBitmark ? "json" : "bitmark");
642
653
  const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
643
654
  const { pretty, indent } = prettyIndent(jsonOptions.prettify);
655
+ const emit = coreFormat === "bitmark" ? prettyIndent(bitmarkOptions.prettifyJson) : { pretty, indent };
644
656
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
645
- const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", pretty, indent, spaces);
657
+ const includeUnknown = !jsonOptions.excludeUnknownProperties;
658
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown);
646
659
  this.throwOnError(out);
647
660
  if (outputFormat === "bitmark" || outputFormat === "text") {
648
661
  return this.deliver(out, opts.outputFile, opts.fileOptions);
@@ -672,7 +685,9 @@ var BitmarkParserGenerator = class {
672
685
  this.checkBrowserFileWrite(opts.outputFile);
673
686
  const wasm2 = getLegacyWasm();
674
687
  const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
675
- const { pretty, indent } = prettyIndent(jsonOptions.prettify);
688
+ const { pretty, indent } = prettyIndent(
689
+ isBitmark ? bitmarkOptions.prettifyJson : jsonOptions.prettify
690
+ );
676
691
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
677
692
  const out = wasm2.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
678
693
  this.throwOnError(out);
@@ -724,7 +739,7 @@ var BitmarkParserGenerator = class {
724
739
  const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
725
740
  if (!isHtmlInput) {
726
741
  const { source, isBitmark } = this.resolveInput(input, void 0);
727
- const out2 = wasm2.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1);
742
+ const out2 = wasm2.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false);
728
743
  this.throwOnError(out2);
729
744
  return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
730
745
  }
@@ -734,12 +749,12 @@ var BitmarkParserGenerator = class {
734
749
  const { pretty, indent } = prettyIndent(jsonOptions.prettify);
735
750
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
736
751
  if (outputFormat === "html") {
737
- const out2 = wasm2.convert(wrapped, "html", "html", "optimized", false, 2, 1);
752
+ const out2 = wasm2.convert(wrapped, "html", "html", "optimized", false, 2, 1, false);
738
753
  this.throwOnError(out2);
739
754
  return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
740
755
  }
741
756
  const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
742
- const out = wasm2.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces);
757
+ const out = wasm2.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false);
743
758
  this.throwOnError(out);
744
759
  if (outputFormat === "bitmark" || outputFormat === "text") {
745
760
  return this.deliver(out, opts.outputFile, opts.fileOptions);
@@ -764,7 +779,7 @@ var BitmarkParserGenerator = class {
764
779
  const opts = Object.assign({}, options);
765
780
  const wasm2 = getLegacyWasm();
766
781
  const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
767
- const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1);
782
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true);
768
783
  this.throwOnError(out);
769
784
  return makePseudoAst(JSON.parse(out));
770
785
  }
@@ -871,7 +886,7 @@ var BitmarkParserGenerator = class {
871
886
  }
872
887
  }
873
888
  const { source, isBitmark } = this.resolveInput(input, void 0);
874
- const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1);
889
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false);
875
890
  this.throwOnError(out);
876
891
  return out;
877
892
  }
@@ -1341,6 +1356,11 @@ var StringWriter = stubClass("StringWriter", INTERNAL_REASON);
1341
1356
  var FileWriter = stubClass("FileWriter", INTERNAL_REASON);
1342
1357
  var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
1343
1358
 
1359
+ // src/types.ts
1360
+ function patchEntry(path2, op, value) {
1361
+ return value === void 0 ? { path: path2, op } : { path: path2, op, value };
1362
+ }
1363
+
1344
1364
  // src/index.ts
1345
1365
  var require2 = (0, import_node_module.createRequire)(importMetaUrl);
1346
1366
  var wasm = require2("../wasm/bitmark_wasm.js");
@@ -1351,8 +1371,27 @@ function version() {
1351
1371
  function lex(input, options = {}) {
1352
1372
  return wasm.lex(input, options.stage ?? "lex");
1353
1373
  }
1354
- function parse(input, options = {}) {
1355
- return wasm.parse(input, options.mode ?? "optimized");
1374
+ function bitmarkToObjects(input, options = {}) {
1375
+ const out = wasm.convert(
1376
+ input,
1377
+ "bitmark",
1378
+ "json",
1379
+ options.mode ?? "optimized",
1380
+ false,
1381
+ 2,
1382
+ 1,
1383
+ options.includeUnknownProperties ?? false
1384
+ );
1385
+ if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1386
+ return JSON.parse(out);
1387
+ }
1388
+ function objectsToBitmark(bits, options = {}) {
1389
+ const entries = bits.map(
1390
+ (b) => b !== null && typeof b === "object" && "bit" in b && typeof b.bit === "object" ? b : { bit: b }
1391
+ );
1392
+ const out = wasm.convert(JSON.stringify(entries), "json", "bitmark", options.mode ?? "optimized", false, 2, 1, false);
1393
+ if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1394
+ return out;
1356
1395
  }
1357
1396
  function convert(input, options = {}) {
1358
1397
  return wasm.convert(
@@ -1362,16 +1401,10 @@ function convert(input, options = {}) {
1362
1401
  options.mode ?? "optimized",
1363
1402
  options.pretty ?? false,
1364
1403
  options.indent ?? 2,
1365
- options.spacesAroundValues ?? 1
1404
+ options.spacesAroundValues ?? 1,
1405
+ options.includeUnknownProperties ?? false
1366
1406
  );
1367
1407
  }
1368
- function optimize(input, options = {}) {
1369
- return wasm.optimize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
1370
- }
1371
- function fullize(input, options = {}) {
1372
- return wasm.fullize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
1373
- }
1374
- var expand = fullize;
1375
1408
  function canonicalize(input, options = {}) {
1376
1409
  return wasm.canonicalize(
1377
1410
  input,
@@ -1427,23 +1460,18 @@ function info(options = {}) {
1427
1460
  const indent = options.indent ?? 2;
1428
1461
  return wasm.info(infoType, format, bit, pretty, indent);
1429
1462
  }
1430
- function generate(input, options = {}) {
1431
- return wasm.convert(input, "json", "bitmark", options.mode ?? "optimized", false, 2, 1);
1432
- }
1433
1463
  // Annotate the CommonJS export names for ESM import in node:
1434
1464
  0 && (module.exports = {
1465
+ bitmarkToObjects,
1435
1466
  breakscapeText,
1436
1467
  canonicalize,
1437
1468
  convert,
1438
1469
  countBits,
1439
- expand,
1440
- fullize,
1441
- generate,
1442
1470
  info,
1443
1471
  legacy,
1444
1472
  lex,
1445
- optimize,
1446
- parse,
1473
+ objectsToBitmark,
1474
+ patchEntry,
1447
1475
  splitBits,
1448
1476
  transform,
1449
1477
  transformParallel,