@gmb/bitmark-parser 6.0.1 → 6.1.1

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.
@@ -21,12 +21,20 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  breakscapeText: () => breakscapeText,
24
+ canonicalize: () => canonicalize2,
24
25
  convert: () => convert2,
26
+ countBits: () => countBits,
27
+ expand: () => expand,
28
+ fullize: () => fullize2,
25
29
  info: () => info2,
26
30
  init: () => init,
27
31
  initSync: () => initSync,
28
32
  lex: () => lex2,
33
+ optimize: () => optimize2,
29
34
  parse: () => parse2,
35
+ splitBits: () => splitBits,
36
+ transform: () => transform2,
37
+ transformParallel: () => transformParallel,
30
38
  unbreakscapeText: () => unbreakscapeText,
31
39
  version: () => version
32
40
  });
@@ -37,6 +45,26 @@ var getImportMetaUrl = () => typeof document === "undefined" ? new URL(`file:${_
37
45
  var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
38
46
 
39
47
  // wasm-web/bitmark_wasm.js
48
+ var bitmark_wasm_exports = {};
49
+ __export(bitmark_wasm_exports, {
50
+ breakscape_text: () => breakscape_text,
51
+ canonicalize: () => canonicalize,
52
+ convert: () => convert,
53
+ count_bits: () => count_bits,
54
+ default: () => bitmark_wasm_default,
55
+ fullize: () => fullize,
56
+ info: () => info,
57
+ initSync: () => initSync,
58
+ is_bitmark: () => is_bitmark,
59
+ lex: () => lex,
60
+ optimize: () => optimize,
61
+ parse: () => parse,
62
+ prettify: () => prettify,
63
+ split_bits: () => split_bits,
64
+ split_json_bits: () => split_json_bits,
65
+ transform: () => transform,
66
+ unbreakscape_text: () => unbreakscape_text
67
+ });
40
68
  var wasm;
41
69
  var WASM_VECTOR_LEN = 0;
42
70
  var cachedUint8ArrayMemory0 = null;
@@ -106,7 +134,89 @@ function getStringFromWasm0(ptr, len) {
106
134
  ptr = ptr >>> 0;
107
135
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
108
136
  }
109
- function unbreakscape_text(input, format, location) {
137
+ function canonicalize(input, mode, pretty, indent, spaces_around_values) {
138
+ let deferred3_0;
139
+ let deferred3_1;
140
+ try {
141
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
142
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
143
+ const len0 = WASM_VECTOR_LEN;
144
+ const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
145
+ const len1 = WASM_VECTOR_LEN;
146
+ wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, pretty, indent, spaces_around_values);
147
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
148
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
149
+ deferred3_0 = r0;
150
+ deferred3_1 = r1;
151
+ return getStringFromWasm0(r0, r1);
152
+ } finally {
153
+ wasm.__wbindgen_add_to_stack_pointer(16);
154
+ wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
155
+ }
156
+ }
157
+ function fullize(input, pretty, indent) {
158
+ let deferred2_0;
159
+ let deferred2_1;
160
+ try {
161
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
162
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
163
+ const len0 = WASM_VECTOR_LEN;
164
+ wasm.fullize(retptr, ptr0, len0, pretty, indent);
165
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
166
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
167
+ deferred2_0 = r0;
168
+ deferred2_1 = r1;
169
+ return getStringFromWasm0(r0, r1);
170
+ } finally {
171
+ wasm.__wbindgen_add_to_stack_pointer(16);
172
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
173
+ }
174
+ }
175
+ function transform(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {
176
+ let deferred6_0;
177
+ let deferred6_1;
178
+ try {
179
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
180
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
181
+ const len0 = WASM_VECTOR_LEN;
182
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
183
+ const len1 = WASM_VECTOR_LEN;
184
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
185
+ const len2 = WASM_VECTOR_LEN;
186
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
187
+ const len3 = WASM_VECTOR_LEN;
188
+ const ptr4 = passStringToWasm0(patch_json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
189
+ const len4 = WASM_VECTOR_LEN;
190
+ wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, pretty, indent, spaces_around_values);
191
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
192
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
193
+ deferred6_0 = r0;
194
+ deferred6_1 = r1;
195
+ return getStringFromWasm0(r0, r1);
196
+ } finally {
197
+ wasm.__wbindgen_add_to_stack_pointer(16);
198
+ wasm.__wbindgen_export_2(deferred6_0, deferred6_1, 1);
199
+ }
200
+ }
201
+ function split_bits(input) {
202
+ let deferred2_0;
203
+ let deferred2_1;
204
+ try {
205
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
206
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
207
+ const len0 = WASM_VECTOR_LEN;
208
+ wasm.split_bits(retptr, ptr0, len0);
209
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
210
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
211
+ deferred2_0 = r0;
212
+ deferred2_1 = r1;
213
+ return getStringFromWasm0(r0, r1);
214
+ } finally {
215
+ wasm.__wbindgen_add_to_stack_pointer(16);
216
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
217
+ }
218
+ }
219
+ function breakscape_text(input, format, location) {
110
220
  let deferred4_0;
111
221
  let deferred4_1;
112
222
  try {
@@ -117,7 +227,7 @@ function unbreakscape_text(input, format, location) {
117
227
  const len1 = WASM_VECTOR_LEN;
118
228
  const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
119
229
  const len2 = WASM_VECTOR_LEN;
120
- wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
230
+ wasm.breakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
121
231
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
122
232
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
123
233
  deferred4_0 = r0;
@@ -128,16 +238,16 @@ function unbreakscape_text(input, format, location) {
128
238
  wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
129
239
  }
130
240
  }
131
- function convert(input, mode, warnings, plain_text, pretty, indent) {
241
+ function lex(input, stage) {
132
242
  let deferred3_0;
133
243
  let deferred3_1;
134
244
  try {
135
245
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
136
246
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
137
247
  const len0 = WASM_VECTOR_LEN;
138
- const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
248
+ const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
139
249
  const len1 = WASM_VECTOR_LEN;
140
- wasm.convert(retptr, ptr0, len0, ptr1, len1, warnings, plain_text, pretty, indent);
250
+ wasm.lex(retptr, ptr0, len0, ptr1, len1);
141
251
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
142
252
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
143
253
  deferred3_0 = r0;
@@ -148,27 +258,25 @@ function convert(input, mode, warnings, plain_text, pretty, indent) {
148
258
  wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
149
259
  }
150
260
  }
151
- function lex(input, stage) {
152
- let deferred3_0;
153
- let deferred3_1;
261
+ function split_json_bits(input) {
262
+ let deferred2_0;
263
+ let deferred2_1;
154
264
  try {
155
265
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
156
266
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
157
267
  const len0 = WASM_VECTOR_LEN;
158
- const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
159
- const len1 = WASM_VECTOR_LEN;
160
- wasm.lex(retptr, ptr0, len0, ptr1, len1);
268
+ wasm.split_json_bits(retptr, ptr0, len0);
161
269
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
162
270
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
163
- deferred3_0 = r0;
164
- deferred3_1 = r1;
271
+ deferred2_0 = r0;
272
+ deferred2_1 = r1;
165
273
  return getStringFromWasm0(r0, r1);
166
274
  } finally {
167
275
  wasm.__wbindgen_add_to_stack_pointer(16);
168
- wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
276
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
169
277
  }
170
278
  }
171
- function breakscape_text(input, format, location) {
279
+ function unbreakscape_text(input, format, location) {
172
280
  let deferred4_0;
173
281
  let deferred4_1;
174
282
  try {
@@ -179,7 +287,7 @@ function breakscape_text(input, format, location) {
179
287
  const len1 = WASM_VECTOR_LEN;
180
288
  const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
181
289
  const len2 = WASM_VECTOR_LEN;
182
- wasm.breakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
290
+ wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
183
291
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
184
292
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
185
293
  deferred4_0 = r0;
@@ -190,6 +298,42 @@ function breakscape_text(input, format, location) {
190
298
  wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
191
299
  }
192
300
  }
301
+ function count_bits(input) {
302
+ let deferred2_0;
303
+ let deferred2_1;
304
+ try {
305
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
306
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
307
+ const len0 = WASM_VECTOR_LEN;
308
+ wasm.count_bits(retptr, ptr0, len0);
309
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
310
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
311
+ deferred2_0 = r0;
312
+ deferred2_1 = r1;
313
+ return getStringFromWasm0(r0, r1);
314
+ } finally {
315
+ wasm.__wbindgen_add_to_stack_pointer(16);
316
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
317
+ }
318
+ }
319
+ function optimize(input, pretty, indent) {
320
+ let deferred2_0;
321
+ let deferred2_1;
322
+ try {
323
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
324
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
325
+ const len0 = WASM_VECTOR_LEN;
326
+ wasm.optimize(retptr, ptr0, len0, pretty, indent);
327
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
328
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
329
+ deferred2_0 = r0;
330
+ deferred2_1 = r1;
331
+ return getStringFromWasm0(r0, r1);
332
+ } finally {
333
+ wasm.__wbindgen_add_to_stack_pointer(16);
334
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
335
+ }
336
+ }
193
337
  function info(info_type, format, bit, pretty, indent) {
194
338
  let deferred4_0;
195
339
  let deferred4_1;
@@ -232,6 +376,54 @@ function parse(input, mode) {
232
376
  wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
233
377
  }
234
378
  }
379
+ function is_bitmark(input) {
380
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
381
+ const len0 = WASM_VECTOR_LEN;
382
+ const ret = wasm.is_bitmark(ptr0, len0);
383
+ return ret !== 0;
384
+ }
385
+ function prettify(json, indent) {
386
+ let deferred2_0;
387
+ let deferred2_1;
388
+ try {
389
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
390
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
391
+ const len0 = WASM_VECTOR_LEN;
392
+ wasm.prettify(retptr, ptr0, len0, indent);
393
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
394
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
395
+ deferred2_0 = r0;
396
+ deferred2_1 = r1;
397
+ return getStringFromWasm0(r0, r1);
398
+ } finally {
399
+ wasm.__wbindgen_add_to_stack_pointer(16);
400
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
401
+ }
402
+ }
403
+ function convert(input, input_format_sel, output_format_sel, mode, pretty, indent, spaces_around_values) {
404
+ let deferred5_0;
405
+ let deferred5_1;
406
+ try {
407
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
408
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
409
+ const len0 = WASM_VECTOR_LEN;
410
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
411
+ const len1 = WASM_VECTOR_LEN;
412
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
413
+ const len2 = WASM_VECTOR_LEN;
414
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
415
+ const len3 = WASM_VECTOR_LEN;
416
+ wasm.convert(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pretty, indent, spaces_around_values);
417
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
418
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
419
+ deferred5_0 = r0;
420
+ deferred5_1 = r1;
421
+ return getStringFromWasm0(r0, r1);
422
+ } finally {
423
+ wasm.__wbindgen_add_to_stack_pointer(16);
424
+ wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);
425
+ }
426
+ }
235
427
  async function __wbg_load(module2, imports) {
236
428
  if (typeof Response === "function" && module2 instanceof Response) {
237
429
  if (typeof WebAssembly.instantiateStreaming === "function") {
@@ -312,12 +504,193 @@ var bitmark_wasm_default = __wbg_init;
312
504
  // src/generated/package_info.ts
313
505
  var PACKAGE_INFO = {
314
506
  "name": "@gmb/bitmark-parser",
315
- "version": "6.0.1",
507
+ "version": "6.1.1",
316
508
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
317
509
  "license": "ISC",
318
510
  "description": "A parser for bitmark text, powered by WebAssembly."
319
511
  };
320
512
 
513
+ // src/core/hooked-transform.ts
514
+ function isError(s) {
515
+ return s.startsWith("error:");
516
+ }
517
+ function errorString(e) {
518
+ const m = e instanceof Error ? e.message : String(e);
519
+ return m.startsWith("error:") ? m : `error: ${m}`;
520
+ }
521
+ function stripArray(doc) {
522
+ const t = doc.trim();
523
+ return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
524
+ }
525
+ function normalisePatch(patch) {
526
+ if (patch === void 0) return [];
527
+ if (typeof patch === "string") {
528
+ const trimmed = patch.trim();
529
+ return trimmed === "" ? [] : JSON.parse(trimmed);
530
+ }
531
+ return patch;
532
+ }
533
+ function buildUnits(wasm2, input, inputIsBitmark) {
534
+ if (inputIsBitmark) {
535
+ const out2 = wasm2.split_bits(input);
536
+ if (isError(out2)) throw new Error(out2);
537
+ const slices = JSON.parse(out2);
538
+ return slices.map((s) => ({
539
+ view: { format: "bitmark", index: s.index, total: slices.length, source: s.source },
540
+ source: s.source
541
+ }));
542
+ }
543
+ const out = wasm2.split_json_bits(input);
544
+ if (isError(out)) throw new Error(out);
545
+ const envelopes = JSON.parse(out);
546
+ return envelopes.map((env, index) => ({
547
+ view: { format: "json", index, total: envelopes.length, bit: env.bit },
548
+ // Per-bit transform consumes a one-bit JSON document.
549
+ source: JSON.stringify([env])
550
+ }));
551
+ }
552
+ function planTransform(wasm2, input, options) {
553
+ const mode = options.mode ?? "optimized";
554
+ const output = options.outputFormat ?? "json";
555
+ const spacesAroundValues = options.spacesAroundValues ?? 1;
556
+ const indent = options.indent ?? 2;
557
+ const pretty = options.pretty ?? false;
558
+ const sel = options.inputFormat ?? "auto";
559
+ const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm2.is_bitmark(input);
560
+ const inputFormat = inputIsBitmark ? "bitmark" : "json";
561
+ const staticPatch = normalisePatch(options.patch);
562
+ const units = buildUnits(wasm2, input, inputIsBitmark);
563
+ const total = units.length;
564
+ const jobs = [];
565
+ const views = [];
566
+ for (let index = 0; index < total; index++) {
567
+ const { view, source } = units[index];
568
+ view.index = index;
569
+ view.total = total;
570
+ const result = options.preHook ? options.preHook(view) || {} : {};
571
+ if (result.drop) continue;
572
+ const patches = result.patches ? [...staticPatch, ...result.patches] : staticPatch;
573
+ jobs.push({
574
+ index,
575
+ source,
576
+ inputFormat,
577
+ outputFormat: result.outputFormat ?? output,
578
+ mode,
579
+ patchJson: JSON.stringify(patches),
580
+ spacesAroundValues
581
+ });
582
+ views.push(view);
583
+ }
584
+ return { jobs, views, output, pretty, indent };
585
+ }
586
+ function computeBit(wasm2, job) {
587
+ const out = wasm2.transform(
588
+ job.source,
589
+ job.inputFormat,
590
+ job.outputFormat,
591
+ job.mode,
592
+ job.patchJson,
593
+ false,
594
+ 2,
595
+ job.spacesAroundValues
596
+ );
597
+ if (isError(out)) return out;
598
+ return job.outputFormat === "json" ? stripArray(out) : out;
599
+ }
600
+ function recombine(wasm2, elements, output, pretty, indent) {
601
+ if (output === "bitmark" || output === "text") return elements.join("\n");
602
+ const arr = `[${elements.join(",")}]`;
603
+ return pretty ? wasm2.prettify(arr, indent) : arr;
604
+ }
605
+ function runHookedTransform(wasm2, input, options) {
606
+ let plan;
607
+ try {
608
+ plan = planTransform(wasm2, input, options);
609
+ } catch (e) {
610
+ return errorString(e);
611
+ }
612
+ const rendered = [];
613
+ for (let i = 0; i < plan.jobs.length; i++) {
614
+ const element = computeBit(wasm2, plan.jobs[i]);
615
+ if (isError(element)) return element;
616
+ options.postHook?.(plan.views[i], element);
617
+ rendered.push(element);
618
+ }
619
+ return recombine(wasm2, rendered, plan.output, plan.pretty, plan.indent);
620
+ }
621
+
622
+ // src/core/parallel.ts
623
+ async function orchestrateParallel(wasm2, input, options, runJobs) {
624
+ let plan;
625
+ try {
626
+ plan = planTransform(wasm2, input, options);
627
+ } catch (e) {
628
+ return errorString(e);
629
+ }
630
+ let elements;
631
+ try {
632
+ elements = await runJobs(plan.jobs, options.workers ?? 4);
633
+ } catch (e) {
634
+ return errorString(e);
635
+ }
636
+ for (let i = 0; i < elements.length; i++) {
637
+ if (isError(elements[i])) return elements[i];
638
+ options.postHook?.(plan.views[i], elements[i]);
639
+ }
640
+ return recombine(wasm2, elements, plan.output, plan.pretty, plan.indent);
641
+ }
642
+
643
+ // src/browser/pool.ts
644
+ function runJobsParallel(jobs, workers) {
645
+ if (jobs.length === 0) return Promise.resolve([]);
646
+ const poolSize = Math.max(1, Math.min(workers, jobs.length));
647
+ const workerUrl = new URL("./worker-entry.js", importMetaUrl);
648
+ return new Promise((resolve, reject) => {
649
+ const results = new Array(jobs.length);
650
+ let next = 0;
651
+ let settled = 0;
652
+ let done = false;
653
+ const pool = [];
654
+ const shutdown = () => {
655
+ for (const w of pool) w.terminate();
656
+ };
657
+ const fail = (err) => {
658
+ if (done) return;
659
+ done = true;
660
+ shutdown();
661
+ reject(err);
662
+ };
663
+ const dispatch = (w) => {
664
+ if (done || next >= jobs.length) return;
665
+ const id = next++;
666
+ w.postMessage({ id, job: jobs[id] });
667
+ };
668
+ for (let i = 0; i < poolSize; i++) {
669
+ const w = new Worker(workerUrl, { type: "module" });
670
+ pool.push(w);
671
+ w.onmessage = (ev) => {
672
+ const res = ev.data;
673
+ if (done) return;
674
+ if (!res.ok) {
675
+ fail(new Error(res.error ?? "worker job failed"));
676
+ return;
677
+ }
678
+ results[res.id] = res.element;
679
+ settled++;
680
+ if (settled === jobs.length) {
681
+ done = true;
682
+ shutdown();
683
+ resolve(results);
684
+ return;
685
+ }
686
+ dispatch(w);
687
+ };
688
+ w.onerror = (e) => fail(new Error(e.message || "worker error"));
689
+ }
690
+ for (const w of pool) dispatch(w);
691
+ });
692
+ }
693
+
321
694
  // src/browser/index.ts
322
695
  async function init(module_or_path) {
323
696
  if (typeof module_or_path === "undefined") {
@@ -335,7 +708,58 @@ function parse2(input, options = {}) {
335
708
  return parse(input, options.mode ?? "optimized");
336
709
  }
337
710
  function convert2(input, options = {}) {
338
- return convert(input, options.mode ?? "optimized", options.warnings ?? false, options.plainText ?? false, options.pretty ?? false, options.indent ?? 2);
711
+ return convert(
712
+ input,
713
+ options.inputFormat ?? "auto",
714
+ options.outputFormat ?? "auto",
715
+ options.mode ?? "optimized",
716
+ options.pretty ?? false,
717
+ options.indent ?? 2,
718
+ options.spacesAroundValues ?? 1
719
+ );
720
+ }
721
+ function optimize2(input, options = {}) {
722
+ return optimize(input, options.pretty ?? false, options.indent ?? 2);
723
+ }
724
+ function fullize2(input, options = {}) {
725
+ return fullize(input, options.pretty ?? false, options.indent ?? 2);
726
+ }
727
+ var expand = fullize2;
728
+ function canonicalize2(input, options = {}) {
729
+ return canonicalize(
730
+ input,
731
+ options.mode ?? "optimized",
732
+ options.pretty ?? false,
733
+ options.indent ?? 2,
734
+ options.spacesAroundValues ?? 1
735
+ );
736
+ }
737
+ function countBits(input) {
738
+ const out = count_bits(input);
739
+ if (out.startsWith("error:")) throw new Error(out);
740
+ return Number.parseInt(out, 10);
741
+ }
742
+ function splitBits(input) {
743
+ return JSON.parse(split_bits(input));
744
+ }
745
+ function transform2(input, options = {}) {
746
+ if (options.preHook || options.postHook) {
747
+ return runHookedTransform(bitmark_wasm_exports, input, options);
748
+ }
749
+ const patchJson = options.patch === void 0 ? "" : typeof options.patch === "string" ? options.patch : JSON.stringify(options.patch);
750
+ return transform(
751
+ input,
752
+ options.inputFormat ?? "auto",
753
+ options.outputFormat ?? "json",
754
+ options.mode ?? "optimized",
755
+ patchJson,
756
+ options.pretty ?? false,
757
+ options.indent ?? 2,
758
+ options.spacesAroundValues ?? 1
759
+ );
760
+ }
761
+ function transformParallel(input, options = {}) {
762
+ return orchestrateParallel(bitmark_wasm_exports, input, options, runJobsParallel);
339
763
  }
340
764
  function breakscapeText(input, options = {}) {
341
765
  const format = options.format ?? "bitmark++";
@@ -358,12 +782,20 @@ function info2(options = {}) {
358
782
  // Annotate the CommonJS export names for ESM import in node:
359
783
  0 && (module.exports = {
360
784
  breakscapeText,
785
+ canonicalize,
361
786
  convert,
787
+ countBits,
788
+ expand,
789
+ fullize,
362
790
  info,
363
791
  init,
364
792
  initSync,
365
793
  lex,
794
+ optimize,
366
795
  parse,
796
+ splitBits,
797
+ transform,
798
+ transformParallel,
367
799
  unbreakscapeText,
368
800
  version
369
801
  });