@gmb/bitmark-parser 6.1.1 → 6.1.3

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.
@@ -86,24 +86,26 @@ function getStringFromWasm0(ptr, len) {
86
86
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
87
87
  }
88
88
  /**
89
- * Re-emit input in its own format in canonical form at `mode`.
89
+ * Lex bitmark input text, returning one line per token in the same format as
90
+ * the Rust CLI: `{kind:?} {span:?} "{text}"`.
91
+ *
92
+ * `stage` selects the lexer pipeline:
93
+ * - `"lex"` — combined (default)
94
+ * - `"lex-json"` — combined, JSON array output
90
95
  * @param {string} input
91
- * @param {string} mode
92
- * @param {boolean} pretty
93
- * @param {number} indent
94
- * @param {number} spaces_around_values
96
+ * @param {string} stage
95
97
  * @returns {string}
96
98
  */
97
- module.exports.canonicalize = function(input, mode, pretty, indent, spaces_around_values) {
99
+ module.exports.lex = function(input, stage) {
98
100
  let deferred3_0;
99
101
  let deferred3_1;
100
102
  try {
101
103
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
102
104
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
103
105
  const len0 = WASM_VECTOR_LEN;
104
- const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
106
+ const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
105
107
  const len1 = WASM_VECTOR_LEN;
106
- wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, pretty, indent, spaces_around_values);
108
+ wasm.lex(retptr, ptr0, len0, ptr1, len1);
107
109
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
108
110
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
109
111
  deferred3_0 = r0;
@@ -116,100 +118,33 @@ module.exports.canonicalize = function(input, mode, pretty, indent, spaces_aroun
116
118
  };
117
119
 
118
120
  /**
119
- * Re-emit input in its own format at full mode (all keys).
120
- * @param {string} input
121
- * @param {boolean} pretty
122
- * @param {number} indent
123
- * @returns {string}
124
- */
125
- module.exports.fullize = function(input, pretty, indent) {
126
- let deferred2_0;
127
- let deferred2_1;
128
- try {
129
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
130
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
131
- const len0 = WASM_VECTOR_LEN;
132
- wasm.fullize(retptr, ptr0, len0, pretty, indent);
133
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
134
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
135
- deferred2_0 = r0;
136
- deferred2_1 = r1;
137
- return getStringFromWasm0(r0, r1);
138
- } finally {
139
- wasm.__wbindgen_add_to_stack_pointer(16);
140
- wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
141
- }
142
- };
143
-
144
- /**
145
- * Apply a patch (a JSON array of patch entries) to every bit and re-emit.
121
+ * Parse bitmark input text and return the reference JSON format.
146
122
  *
147
- * `input_format_sel`: `"auto"` | `"bitmark"` | `"json"`.
148
- * `output_format_sel`: `"bitmark"` | `"json"` (default json).
149
- * `patch_json`: the patch entry array (empty string = no patches, i.e. a
150
- * canonicalizing pass). Parallelism is a JS-side concern (web workers); this
151
- * runs sequentially. Returns the document text/JSON, or `error: …`.
123
+ * Uses the full pipeline: parse → validate → serialize.
124
+ *
125
+ * `mode`: `"optimized"` (default) or `"full"`
152
126
  * @param {string} input
153
- * @param {string} input_format_sel
154
- * @param {string} output_format_sel
155
127
  * @param {string} mode
156
- * @param {string} patch_json
157
- * @param {boolean} pretty
158
- * @param {number} indent
159
- * @param {number} spaces_around_values
160
128
  * @returns {string}
161
129
  */
162
- module.exports.transform = function(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {
163
- let deferred6_0;
164
- let deferred6_1;
130
+ module.exports.parse = function(input, mode) {
131
+ let deferred3_0;
132
+ let deferred3_1;
165
133
  try {
166
134
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
167
135
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
168
136
  const len0 = WASM_VECTOR_LEN;
169
- const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
137
+ const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
170
138
  const len1 = WASM_VECTOR_LEN;
171
- const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
172
- const len2 = WASM_VECTOR_LEN;
173
- const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
174
- const len3 = WASM_VECTOR_LEN;
175
- const ptr4 = passStringToWasm0(patch_json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
176
- const len4 = WASM_VECTOR_LEN;
177
- wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, pretty, indent, spaces_around_values);
178
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
179
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
180
- deferred6_0 = r0;
181
- deferred6_1 = r1;
182
- return getStringFromWasm0(r0, r1);
183
- } finally {
184
- wasm.__wbindgen_add_to_stack_pointer(16);
185
- wasm.__wbindgen_export_2(deferred6_0, deferred6_1, 1);
186
- }
187
- };
188
-
189
- /**
190
- * Split a bitmark document into per-bit source slices.
191
- *
192
- * Returns a JSON array of `{ index, byteStart, byteEnd, source }`. Lets a JS
193
- * caller chunk a document at bit boundaries (e.g. to feed a worker pool).
194
- * @param {string} input
195
- * @returns {string}
196
- */
197
- module.exports.split_bits = function(input) {
198
- let deferred2_0;
199
- let deferred2_1;
200
- try {
201
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
202
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
203
- const len0 = WASM_VECTOR_LEN;
204
- wasm.split_bits(retptr, ptr0, len0);
139
+ wasm.parse(retptr, ptr0, len0, ptr1, len1);
205
140
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
206
141
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
207
- deferred2_0 = r0;
208
- deferred2_1 = r1;
142
+ deferred3_0 = r0;
143
+ deferred3_1 = r1;
209
144
  return getStringFromWasm0(r0, r1);
210
145
  } finally {
211
146
  wasm.__wbindgen_add_to_stack_pointer(16);
212
- wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
147
+ wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
213
148
  }
214
149
  };
215
150
 
@@ -247,34 +182,35 @@ module.exports.breakscape_text = function(input, format, location) {
247
182
  };
248
183
 
249
184
  /**
250
- * Lex bitmark input text, returning one line per token in the same format as
251
- * the Rust CLI: `{kind:?} {span:?} "{text}"`.
185
+ * Unbreakscape text (unescape bitmark special characters).
252
186
  *
253
- * `stage` selects the lexer pipeline:
254
- * - `"lex"` — combined (default)
255
- * - `"lex-json"` — combined, JSON array output
187
+ * `format`: `"bitmark++"` (default) or `"plainText"`
188
+ * `location`: `"body"` (default) or `"tag"`
256
189
  * @param {string} input
257
- * @param {string} stage
190
+ * @param {string} format
191
+ * @param {string} location
258
192
  * @returns {string}
259
193
  */
260
- module.exports.lex = function(input, stage) {
261
- let deferred3_0;
262
- let deferred3_1;
194
+ module.exports.unbreakscape_text = function(input, format, location) {
195
+ let deferred4_0;
196
+ let deferred4_1;
263
197
  try {
264
198
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
265
199
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
266
200
  const len0 = WASM_VECTOR_LEN;
267
- const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
201
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
268
202
  const len1 = WASM_VECTOR_LEN;
269
- wasm.lex(retptr, ptr0, len0, ptr1, len1);
203
+ const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
204
+ const len2 = WASM_VECTOR_LEN;
205
+ wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
270
206
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
271
207
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
272
- deferred3_0 = r0;
273
- deferred3_1 = r1;
208
+ deferred4_0 = r0;
209
+ deferred4_1 = r1;
274
210
  return getStringFromWasm0(r0, r1);
275
211
  } finally {
276
212
  wasm.__wbindgen_add_to_stack_pointer(16);
277
- wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
213
+ wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
278
214
  }
279
215
  };
280
216
 
@@ -306,52 +242,21 @@ module.exports.split_json_bits = function(input) {
306
242
  };
307
243
 
308
244
  /**
309
- * Unbreakscape text (unescape bitmark special characters).
310
- *
311
- * `format`: `"bitmark++"` (default) or `"plainText"`
312
- * `location`: `"body"` (default) or `"tag"`
313
- * @param {string} input
314
- * @param {string} format
315
- * @param {string} location
316
- * @returns {string}
317
- */
318
- module.exports.unbreakscape_text = function(input, format, location) {
319
- let deferred4_0;
320
- let deferred4_1;
321
- try {
322
- const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
323
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
324
- const len0 = WASM_VECTOR_LEN;
325
- const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
326
- const len1 = WASM_VECTOR_LEN;
327
- const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
328
- const len2 = WASM_VECTOR_LEN;
329
- wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
330
- var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
331
- var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
332
- deferred4_0 = r0;
333
- deferred4_1 = r1;
334
- return getStringFromWasm0(r0, r1);
335
- } finally {
336
- wasm.__wbindgen_add_to_stack_pointer(16);
337
- wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
338
- }
339
- };
340
-
341
- /**
342
- * Count the bits in `input` (auto-detecting bitmark vs JSON).
343
- * Returns the count as a decimal string, or `error: …`.
344
- * @param {string} input
245
+ * Pretty-print a compact JSON string with the given indent. Used to format a
246
+ * document recombined on the JS side (the per-bit hook path) so its output
247
+ * matches the in-Rust recombination byte-for-byte.
248
+ * @param {string} json
249
+ * @param {number} indent
345
250
  * @returns {string}
346
251
  */
347
- module.exports.count_bits = function(input) {
252
+ module.exports.prettify = function(json, indent) {
348
253
  let deferred2_0;
349
254
  let deferred2_1;
350
255
  try {
351
256
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
352
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
257
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
353
258
  const len0 = WASM_VECTOR_LEN;
354
- wasm.count_bits(retptr, ptr0, len0);
259
+ wasm.prettify(retptr, ptr0, len0, indent);
355
260
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
356
261
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
357
262
  deferred2_0 = r0;
@@ -364,28 +269,47 @@ module.exports.count_bits = function(input) {
364
269
  };
365
270
 
366
271
  /**
367
- * Re-emit input in its own format at optimized mode (omit natural defaults).
272
+ * Apply a patch (a JSON array of patch entries) to every bit and re-emit.
273
+ *
274
+ * `input_format_sel`: `"auto"` | `"bitmark"` | `"json"`.
275
+ * `output_format_sel`: `"bitmark"` | `"json"` (default json).
276
+ * `patch_json`: the patch entry array (empty string = no patches, i.e. a
277
+ * canonicalizing pass). Parallelism is a JS-side concern (web workers); this
278
+ * runs sequentially. Returns the document text/JSON, or `error: …`.
368
279
  * @param {string} input
280
+ * @param {string} input_format_sel
281
+ * @param {string} output_format_sel
282
+ * @param {string} mode
283
+ * @param {string} patch_json
369
284
  * @param {boolean} pretty
370
285
  * @param {number} indent
286
+ * @param {number} spaces_around_values
371
287
  * @returns {string}
372
288
  */
373
- module.exports.optimize = function(input, pretty, indent) {
374
- let deferred2_0;
375
- let deferred2_1;
289
+ module.exports.transform = function(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {
290
+ let deferred6_0;
291
+ let deferred6_1;
376
292
  try {
377
293
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
378
294
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
379
295
  const len0 = WASM_VECTOR_LEN;
380
- wasm.optimize(retptr, ptr0, len0, pretty, indent);
296
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
297
+ const len1 = WASM_VECTOR_LEN;
298
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
299
+ const len2 = WASM_VECTOR_LEN;
300
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
301
+ const len3 = WASM_VECTOR_LEN;
302
+ const ptr4 = passStringToWasm0(patch_json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
303
+ const len4 = WASM_VECTOR_LEN;
304
+ wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, pretty, indent, spaces_around_values);
381
305
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
382
306
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
383
- deferred2_0 = r0;
384
- deferred2_1 = r1;
307
+ deferred6_0 = r0;
308
+ deferred6_1 = r1;
385
309
  return getStringFromWasm0(r0, r1);
386
310
  } finally {
387
311
  wasm.__wbindgen_add_to_stack_pointer(16);
388
- wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
312
+ wasm.__wbindgen_export_2(deferred6_0, deferred6_1, 1);
389
313
  }
390
314
  };
391
315
 
@@ -428,25 +352,67 @@ module.exports.info = function(info_type, format, bit, pretty, indent) {
428
352
  };
429
353
 
430
354
  /**
431
- * Parse bitmark input text and return the reference JSON format.
432
- *
433
- * Uses the full pipeline: parse → validate → serialize.
355
+ * Convert between bitmark and JSON with explicit input/output formats + mode.
434
356
  *
435
- * `mode`: `"optimized"` (default) or `"full"`
357
+ * `input_format`: `"auto"` (default) | `"bitmark"` | `"json"`.
358
+ * `output_format`: `"auto"` (opposite of input) | `"bitmark"` | `"json"`.
359
+ * `mode`: `"optimized"` (default) | `"full"`.
360
+ * Returns the converted text/JSON, or a string prefixed `error:` on failure.
436
361
  * @param {string} input
362
+ * @param {string} input_format_sel
363
+ * @param {string} output_format_sel
437
364
  * @param {string} mode
365
+ * @param {boolean} pretty
366
+ * @param {number} indent
367
+ * @param {number} spaces_around_values
438
368
  * @returns {string}
439
369
  */
440
- module.exports.parse = function(input, mode) {
370
+ module.exports.convert = function(input, input_format_sel, output_format_sel, mode, pretty, indent, spaces_around_values) {
371
+ let deferred5_0;
372
+ let deferred5_1;
373
+ try {
374
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
375
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
376
+ const len0 = WASM_VECTOR_LEN;
377
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
378
+ const len1 = WASM_VECTOR_LEN;
379
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
380
+ const len2 = WASM_VECTOR_LEN;
381
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
382
+ const len3 = WASM_VECTOR_LEN;
383
+ wasm.convert(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pretty, indent, spaces_around_values);
384
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
385
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
386
+ deferred5_0 = r0;
387
+ deferred5_1 = r1;
388
+ return getStringFromWasm0(r0, r1);
389
+ } finally {
390
+ wasm.__wbindgen_add_to_stack_pointer(16);
391
+ wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);
392
+ }
393
+ };
394
+
395
+ /**
396
+ * Re-emit input in its own format at optimized mode (omit natural defaults).
397
+ *
398
+ * `input_format`: `"auto"` (default) | `"bitmark"` | `"json"` | any config
399
+ * mapping id (`html`, `xml`, …). The output is re-emitted in this same format.
400
+ * @param {string} input
401
+ * @param {string} input_format_sel
402
+ * @param {boolean} pretty
403
+ * @param {number} indent
404
+ * @returns {string}
405
+ */
406
+ module.exports.optimize = function(input, input_format_sel, pretty, indent) {
441
407
  let deferred3_0;
442
408
  let deferred3_1;
443
409
  try {
444
410
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
445
411
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
446
412
  const len0 = WASM_VECTOR_LEN;
447
- const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
413
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
448
414
  const len1 = WASM_VECTOR_LEN;
449
- wasm.parse(retptr, ptr0, len0, ptr1, len1);
415
+ wasm.optimize(retptr, ptr0, len0, ptr1, len1, pretty, indent);
450
416
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
451
417
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
452
418
  deferred3_0 = r0;
@@ -459,34 +425,87 @@ module.exports.parse = function(input, mode) {
459
425
  };
460
426
 
461
427
  /**
462
- * Whether `input` looks like bitmark (vs JSON). Mirrors the auto-detection
463
- * used across the API so a JS caller can resolve `"auto"` consistently.
428
+ * Re-emit input in its own format at full mode (all keys).
429
+ *
430
+ * `input_format`: `"auto"` (default) | `"bitmark"` | `"json"` | any config
431
+ * mapping id (`html`, `xml`, …). The output is re-emitted in this same format.
464
432
  * @param {string} input
465
- * @returns {boolean}
433
+ * @param {string} input_format_sel
434
+ * @param {boolean} pretty
435
+ * @param {number} indent
436
+ * @returns {string}
466
437
  */
467
- module.exports.is_bitmark = function(input) {
468
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
469
- const len0 = WASM_VECTOR_LEN;
470
- const ret = wasm.is_bitmark(ptr0, len0);
471
- return ret !== 0;
438
+ module.exports.fullize = function(input, input_format_sel, pretty, indent) {
439
+ let deferred3_0;
440
+ let deferred3_1;
441
+ try {
442
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
443
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
444
+ const len0 = WASM_VECTOR_LEN;
445
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
446
+ const len1 = WASM_VECTOR_LEN;
447
+ wasm.fullize(retptr, ptr0, len0, ptr1, len1, pretty, indent);
448
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
449
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
450
+ deferred3_0 = r0;
451
+ deferred3_1 = r1;
452
+ return getStringFromWasm0(r0, r1);
453
+ } finally {
454
+ wasm.__wbindgen_add_to_stack_pointer(16);
455
+ wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
456
+ }
472
457
  };
473
458
 
474
459
  /**
475
- * Pretty-print a compact JSON string with the given indent. Used to format a
476
- * document recombined on the JS side (the per-bit hook path) so its output
477
- * matches the in-Rust recombination byte-for-byte.
478
- * @param {string} json
460
+ * Re-emit input in its own format in canonical form at `mode`.
461
+ *
462
+ * `input_format`: `"auto"` (default) | `"bitmark"` | `"json"` | any config
463
+ * mapping id (`html`, `xml`, …). The output is re-emitted in this same format.
464
+ * @param {string} input
465
+ * @param {string} input_format_sel
466
+ * @param {string} mode
467
+ * @param {boolean} pretty
479
468
  * @param {number} indent
469
+ * @param {number} spaces_around_values
480
470
  * @returns {string}
481
471
  */
482
- module.exports.prettify = function(json, indent) {
472
+ module.exports.canonicalize = function(input, input_format_sel, mode, pretty, indent, spaces_around_values) {
473
+ let deferred4_0;
474
+ let deferred4_1;
475
+ try {
476
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
477
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
478
+ const len0 = WASM_VECTOR_LEN;
479
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
480
+ const len1 = WASM_VECTOR_LEN;
481
+ const ptr2 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
482
+ const len2 = WASM_VECTOR_LEN;
483
+ wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent, spaces_around_values);
484
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
485
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
486
+ deferred4_0 = r0;
487
+ deferred4_1 = r1;
488
+ return getStringFromWasm0(r0, r1);
489
+ } finally {
490
+ wasm.__wbindgen_add_to_stack_pointer(16);
491
+ wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
492
+ }
493
+ };
494
+
495
+ /**
496
+ * Count the bits in `input` (auto-detecting bitmark vs JSON).
497
+ * Returns the count as a decimal string, or `error: …`.
498
+ * @param {string} input
499
+ * @returns {string}
500
+ */
501
+ module.exports.count_bits = function(input) {
483
502
  let deferred2_0;
484
503
  let deferred2_1;
485
504
  try {
486
505
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
487
- const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
506
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
488
507
  const len0 = WASM_VECTOR_LEN;
489
- wasm.prettify(retptr, ptr0, len0, indent);
508
+ wasm.count_bits(retptr, ptr0, len0);
490
509
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
491
510
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
492
511
  deferred2_0 = r0;
@@ -499,46 +518,45 @@ module.exports.prettify = function(json, indent) {
499
518
  };
500
519
 
501
520
  /**
502
- * Convert between bitmark and JSON with explicit input/output formats + mode.
521
+ * Split a bitmark document into per-bit source slices.
503
522
  *
504
- * `input_format`: `"auto"` (default) | `"bitmark"` | `"json"`.
505
- * `output_format`: `"auto"` (opposite of input) | `"bitmark"` | `"json"`.
506
- * `mode`: `"optimized"` (default) | `"full"`.
507
- * Returns the converted text/JSON, or a string prefixed `error:` on failure.
523
+ * Returns a JSON array of `{ index, byteStart, byteEnd, source }`. Lets a JS
524
+ * caller chunk a document at bit boundaries (e.g. to feed a worker pool).
508
525
  * @param {string} input
509
- * @param {string} input_format_sel
510
- * @param {string} output_format_sel
511
- * @param {string} mode
512
- * @param {boolean} pretty
513
- * @param {number} indent
514
- * @param {number} spaces_around_values
515
526
  * @returns {string}
516
527
  */
517
- module.exports.convert = function(input, input_format_sel, output_format_sel, mode, pretty, indent, spaces_around_values) {
518
- let deferred5_0;
519
- let deferred5_1;
528
+ module.exports.split_bits = function(input) {
529
+ let deferred2_0;
530
+ let deferred2_1;
520
531
  try {
521
532
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
522
533
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
523
534
  const len0 = WASM_VECTOR_LEN;
524
- const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
525
- const len1 = WASM_VECTOR_LEN;
526
- const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
527
- const len2 = WASM_VECTOR_LEN;
528
- const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
529
- const len3 = WASM_VECTOR_LEN;
530
- wasm.convert(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pretty, indent, spaces_around_values);
535
+ wasm.split_bits(retptr, ptr0, len0);
531
536
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
532
537
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
533
- deferred5_0 = r0;
534
- deferred5_1 = r1;
538
+ deferred2_0 = r0;
539
+ deferred2_1 = r1;
535
540
  return getStringFromWasm0(r0, r1);
536
541
  } finally {
537
542
  wasm.__wbindgen_add_to_stack_pointer(16);
538
- wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);
543
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
539
544
  }
540
545
  };
541
546
 
547
+ /**
548
+ * Whether `input` looks like bitmark (vs JSON). Mirrors the auto-detection
549
+ * used across the API so a JS caller can resolve `"auto"` consistently.
550
+ * @param {string} input
551
+ * @returns {boolean}
552
+ */
553
+ module.exports.is_bitmark = function(input) {
554
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
555
+ const len0 = WASM_VECTOR_LEN;
556
+ const ret = wasm.is_bitmark(ptr0, len0);
557
+ return ret !== 0;
558
+ };
559
+
542
560
  const path = require('path').join(__dirname, 'bitmark_wasm_bg.wasm');
543
561
  const bytes = require('fs').readFileSync(path);
544
562
 
Binary file
@@ -2,14 +2,14 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const breakscape_text: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
5
- export const canonicalize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => void;
5
+ export const canonicalize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void;
6
6
  export const convert: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => void;
7
7
  export const count_bits: (a: number, b: number, c: number) => void;
8
- export const fullize: (a: number, b: number, c: number, d: number, e: number) => void;
8
+ export const fullize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
9
9
  export const info: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
10
10
  export const is_bitmark: (a: number, b: number) => number;
11
11
  export const lex: (a: number, b: number, c: number, d: number, e: number) => void;
12
- export const optimize: (a: number, b: number, c: number, d: number, e: number) => void;
12
+ export const optimize: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => void;
13
13
  export const parse: (a: number, b: number, c: number, d: number, e: number) => void;
14
14
  export const prettify: (a: number, b: number, c: number, d: number) => void;
15
15
  export const split_bits: (a: number, b: number, c: number) => void;
package/wasm/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "Get More Brain Ltd <info@getmorebrain.com>"
5
5
  ],
6
6
  "description": "WebAssembly bindings for the bitmark parser",
7
- "version": "6.1.1",
7
+ "version": "6.1.3",
8
8
  "license": "ISC",
9
9
  "repository": {
10
10
  "type": "git",