@gmb/bitmark-parser 6.0.0 → 6.1.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.
@@ -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;
@@ -126,18 +154,36 @@ function lex(input, stage) {
126
154
  wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
127
155
  }
128
156
  }
129
- function info(info_type, format, bit, pretty, indent) {
157
+ function prettify(json, 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(json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
163
+ const len0 = WASM_VECTOR_LEN;
164
+ wasm.prettify(retptr, ptr0, len0, 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 unbreakscape_text(input, format, location) {
130
176
  let deferred4_0;
131
177
  let deferred4_1;
132
178
  try {
133
179
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
134
- const ptr0 = passStringToWasm0(info_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
180
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
135
181
  const len0 = WASM_VECTOR_LEN;
136
182
  const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
137
183
  const len1 = WASM_VECTOR_LEN;
138
- const ptr2 = passStringToWasm0(bit, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
184
+ const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
139
185
  const len2 = WASM_VECTOR_LEN;
140
- wasm.info(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent);
186
+ wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
141
187
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
142
188
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
143
189
  deferred4_0 = r0;
@@ -148,18 +194,18 @@ function info(info_type, format, bit, pretty, indent) {
148
194
  wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
149
195
  }
150
196
  }
151
- function unbreakscape_text(input, format, location) {
197
+ function info(info_type, format, bit, pretty, indent) {
152
198
  let deferred4_0;
153
199
  let deferred4_1;
154
200
  try {
155
201
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
156
- const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
202
+ const ptr0 = passStringToWasm0(info_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
157
203
  const len0 = WASM_VECTOR_LEN;
158
204
  const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
159
205
  const len1 = WASM_VECTOR_LEN;
160
- const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
206
+ const ptr2 = passStringToWasm0(bit, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
161
207
  const len2 = WASM_VECTOR_LEN;
162
- wasm.unbreakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
208
+ wasm.info(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent);
163
209
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
164
210
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
165
211
  deferred4_0 = r0;
@@ -170,27 +216,33 @@ function unbreakscape_text(input, format, location) {
170
216
  wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
171
217
  }
172
218
  }
173
- function parse(input, mode) {
174
- let deferred3_0;
175
- let deferred3_1;
219
+ function transform(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {
220
+ let deferred6_0;
221
+ let deferred6_1;
176
222
  try {
177
223
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
178
224
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
179
225
  const len0 = WASM_VECTOR_LEN;
180
- const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
226
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
181
227
  const len1 = WASM_VECTOR_LEN;
182
- wasm.parse(retptr, ptr0, len0, ptr1, len1);
228
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
229
+ const len2 = WASM_VECTOR_LEN;
230
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
231
+ const len3 = WASM_VECTOR_LEN;
232
+ const ptr4 = passStringToWasm0(patch_json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
233
+ const len4 = WASM_VECTOR_LEN;
234
+ wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, pretty, indent, spaces_around_values);
183
235
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
184
236
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
185
- deferred3_0 = r0;
186
- deferred3_1 = r1;
237
+ deferred6_0 = r0;
238
+ deferred6_1 = r1;
187
239
  return getStringFromWasm0(r0, r1);
188
240
  } finally {
189
241
  wasm.__wbindgen_add_to_stack_pointer(16);
190
- wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
242
+ wasm.__wbindgen_export_2(deferred6_0, deferred6_1, 1);
191
243
  }
192
244
  }
193
- function convert(input, mode, warnings, plain_text, pretty, indent) {
245
+ function canonicalize(input, mode, pretty, indent, spaces_around_values) {
194
246
  let deferred3_0;
195
247
  let deferred3_1;
196
248
  try {
@@ -199,7 +251,7 @@ function convert(input, mode, warnings, plain_text, pretty, indent) {
199
251
  const len0 = WASM_VECTOR_LEN;
200
252
  const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
201
253
  const len1 = WASM_VECTOR_LEN;
202
- wasm.convert(retptr, ptr0, len0, ptr1, len1, warnings, plain_text, pretty, indent);
254
+ wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, pretty, indent, spaces_around_values);
203
255
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
204
256
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
205
257
  deferred3_0 = r0;
@@ -210,6 +262,72 @@ function convert(input, mode, warnings, plain_text, pretty, indent) {
210
262
  wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
211
263
  }
212
264
  }
265
+ function split_json_bits(input) {
266
+ let deferred2_0;
267
+ let deferred2_1;
268
+ try {
269
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
270
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
271
+ const len0 = WASM_VECTOR_LEN;
272
+ wasm.split_json_bits(retptr, ptr0, len0);
273
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
274
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
275
+ deferred2_0 = r0;
276
+ deferred2_1 = r1;
277
+ return getStringFromWasm0(r0, r1);
278
+ } finally {
279
+ wasm.__wbindgen_add_to_stack_pointer(16);
280
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
281
+ }
282
+ }
283
+ function fullize(input, pretty, indent) {
284
+ let deferred2_0;
285
+ let deferred2_1;
286
+ try {
287
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
288
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
289
+ const len0 = WASM_VECTOR_LEN;
290
+ wasm.fullize(retptr, ptr0, len0, pretty, indent);
291
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
292
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
293
+ deferred2_0 = r0;
294
+ deferred2_1 = r1;
295
+ return getStringFromWasm0(r0, r1);
296
+ } finally {
297
+ wasm.__wbindgen_add_to_stack_pointer(16);
298
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
299
+ }
300
+ }
301
+ function convert(input, input_format_sel, output_format_sel, mode, pretty, indent, spaces_around_values) {
302
+ let deferred5_0;
303
+ let deferred5_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
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
309
+ const len1 = WASM_VECTOR_LEN;
310
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
311
+ const len2 = WASM_VECTOR_LEN;
312
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
313
+ const len3 = WASM_VECTOR_LEN;
314
+ wasm.convert(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pretty, indent, spaces_around_values);
315
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
316
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
317
+ deferred5_0 = r0;
318
+ deferred5_1 = r1;
319
+ return getStringFromWasm0(r0, r1);
320
+ } finally {
321
+ wasm.__wbindgen_add_to_stack_pointer(16);
322
+ wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);
323
+ }
324
+ }
325
+ function is_bitmark(input) {
326
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
327
+ const len0 = WASM_VECTOR_LEN;
328
+ const ret = wasm.is_bitmark(ptr0, len0);
329
+ return ret !== 0;
330
+ }
213
331
  function breakscape_text(input, format, location) {
214
332
  let deferred4_0;
215
333
  let deferred4_1;
@@ -232,6 +350,80 @@ function breakscape_text(input, format, location) {
232
350
  wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
233
351
  }
234
352
  }
353
+ function parse(input, mode) {
354
+ let deferred3_0;
355
+ let deferred3_1;
356
+ try {
357
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
358
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
359
+ const len0 = WASM_VECTOR_LEN;
360
+ const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
361
+ const len1 = WASM_VECTOR_LEN;
362
+ wasm.parse(retptr, ptr0, len0, ptr1, len1);
363
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
364
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
365
+ deferred3_0 = r0;
366
+ deferred3_1 = r1;
367
+ return getStringFromWasm0(r0, r1);
368
+ } finally {
369
+ wasm.__wbindgen_add_to_stack_pointer(16);
370
+ wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
371
+ }
372
+ }
373
+ function optimize(input, pretty, indent) {
374
+ let deferred2_0;
375
+ let deferred2_1;
376
+ try {
377
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
378
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
379
+ const len0 = WASM_VECTOR_LEN;
380
+ wasm.optimize(retptr, ptr0, len0, pretty, indent);
381
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
382
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
383
+ deferred2_0 = r0;
384
+ deferred2_1 = r1;
385
+ return getStringFromWasm0(r0, r1);
386
+ } finally {
387
+ wasm.__wbindgen_add_to_stack_pointer(16);
388
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
389
+ }
390
+ }
391
+ function count_bits(input) {
392
+ let deferred2_0;
393
+ let deferred2_1;
394
+ try {
395
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
396
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
397
+ const len0 = WASM_VECTOR_LEN;
398
+ wasm.count_bits(retptr, ptr0, len0);
399
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
400
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
401
+ deferred2_0 = r0;
402
+ deferred2_1 = r1;
403
+ return getStringFromWasm0(r0, r1);
404
+ } finally {
405
+ wasm.__wbindgen_add_to_stack_pointer(16);
406
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
407
+ }
408
+ }
409
+ function split_bits(input) {
410
+ let deferred2_0;
411
+ let deferred2_1;
412
+ try {
413
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
414
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
415
+ const len0 = WASM_VECTOR_LEN;
416
+ wasm.split_bits(retptr, ptr0, len0);
417
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
418
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
419
+ deferred2_0 = r0;
420
+ deferred2_1 = r1;
421
+ return getStringFromWasm0(r0, r1);
422
+ } finally {
423
+ wasm.__wbindgen_add_to_stack_pointer(16);
424
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_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.0",
507
+ "version": "6.1.0",
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") 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
  });