@gmb/bitmark-parser 6.0.1 → 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.
@@ -1,4 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
1
7
  // wasm-web/bitmark_wasm.js
8
+ var bitmark_wasm_exports = {};
9
+ __export(bitmark_wasm_exports, {
10
+ breakscape_text: () => breakscape_text,
11
+ canonicalize: () => canonicalize,
12
+ convert: () => convert,
13
+ count_bits: () => count_bits,
14
+ default: () => bitmark_wasm_default,
15
+ fullize: () => fullize,
16
+ info: () => info,
17
+ initSync: () => initSync,
18
+ is_bitmark: () => is_bitmark,
19
+ lex: () => lex,
20
+ optimize: () => optimize,
21
+ parse: () => parse,
22
+ prettify: () => prettify,
23
+ split_bits: () => split_bits,
24
+ split_json_bits: () => split_json_bits,
25
+ transform: () => transform,
26
+ unbreakscape_text: () => unbreakscape_text
27
+ });
2
28
  var wasm;
3
29
  var WASM_VECTOR_LEN = 0;
4
30
  var cachedUint8ArrayMemory0 = null;
@@ -68,6 +94,44 @@ function getStringFromWasm0(ptr, len) {
68
94
  ptr = ptr >>> 0;
69
95
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
70
96
  }
97
+ function lex(input, stage) {
98
+ let deferred3_0;
99
+ let deferred3_1;
100
+ try {
101
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
102
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
103
+ const len0 = WASM_VECTOR_LEN;
104
+ const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
105
+ const len1 = WASM_VECTOR_LEN;
106
+ wasm.lex(retptr, ptr0, len0, ptr1, len1);
107
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
108
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
109
+ deferred3_0 = r0;
110
+ deferred3_1 = r1;
111
+ return getStringFromWasm0(r0, r1);
112
+ } finally {
113
+ wasm.__wbindgen_add_to_stack_pointer(16);
114
+ wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
115
+ }
116
+ }
117
+ function prettify(json, indent) {
118
+ let deferred2_0;
119
+ let deferred2_1;
120
+ try {
121
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
122
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
123
+ const len0 = WASM_VECTOR_LEN;
124
+ wasm.prettify(retptr, ptr0, len0, indent);
125
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
126
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
127
+ deferred2_0 = r0;
128
+ deferred2_1 = r1;
129
+ return getStringFromWasm0(r0, r1);
130
+ } finally {
131
+ wasm.__wbindgen_add_to_stack_pointer(16);
132
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
133
+ }
134
+ }
71
135
  function unbreakscape_text(input, format, location) {
72
136
  let deferred4_0;
73
137
  let deferred4_1;
@@ -90,36 +154,64 @@ function unbreakscape_text(input, format, location) {
90
154
  wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
91
155
  }
92
156
  }
93
- function convert(input, mode, warnings, plain_text, pretty, indent) {
94
- let deferred3_0;
95
- let deferred3_1;
157
+ function info(info_type, format, bit, pretty, indent) {
158
+ let deferred4_0;
159
+ let deferred4_1;
160
+ try {
161
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
162
+ const ptr0 = passStringToWasm0(info_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
163
+ const len0 = WASM_VECTOR_LEN;
164
+ const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
165
+ const len1 = WASM_VECTOR_LEN;
166
+ const ptr2 = passStringToWasm0(bit, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
167
+ const len2 = WASM_VECTOR_LEN;
168
+ wasm.info(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent);
169
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
170
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
171
+ deferred4_0 = r0;
172
+ deferred4_1 = r1;
173
+ return getStringFromWasm0(r0, r1);
174
+ } finally {
175
+ wasm.__wbindgen_add_to_stack_pointer(16);
176
+ wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
177
+ }
178
+ }
179
+ function transform(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {
180
+ let deferred6_0;
181
+ let deferred6_1;
96
182
  try {
97
183
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
98
184
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
99
185
  const len0 = WASM_VECTOR_LEN;
100
- const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
186
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
101
187
  const len1 = WASM_VECTOR_LEN;
102
- wasm.convert(retptr, ptr0, len0, ptr1, len1, warnings, plain_text, pretty, indent);
188
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
189
+ const len2 = WASM_VECTOR_LEN;
190
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
191
+ const len3 = WASM_VECTOR_LEN;
192
+ const ptr4 = passStringToWasm0(patch_json, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
193
+ const len4 = WASM_VECTOR_LEN;
194
+ wasm.transform(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, pretty, indent, spaces_around_values);
103
195
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
104
196
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
105
- deferred3_0 = r0;
106
- deferred3_1 = r1;
197
+ deferred6_0 = r0;
198
+ deferred6_1 = r1;
107
199
  return getStringFromWasm0(r0, r1);
108
200
  } finally {
109
201
  wasm.__wbindgen_add_to_stack_pointer(16);
110
- wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
202
+ wasm.__wbindgen_export_2(deferred6_0, deferred6_1, 1);
111
203
  }
112
204
  }
113
- function lex(input, stage) {
205
+ function canonicalize(input, mode, pretty, indent, spaces_around_values) {
114
206
  let deferred3_0;
115
207
  let deferred3_1;
116
208
  try {
117
209
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
118
210
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
119
211
  const len0 = WASM_VECTOR_LEN;
120
- const ptr1 = passStringToWasm0(stage, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
212
+ const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
121
213
  const len1 = WASM_VECTOR_LEN;
122
- wasm.lex(retptr, ptr0, len0, ptr1, len1);
214
+ wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, pretty, indent, spaces_around_values);
123
215
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
124
216
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
125
217
  deferred3_0 = r0;
@@ -130,40 +222,84 @@ function lex(input, stage) {
130
222
  wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
131
223
  }
132
224
  }
133
- function breakscape_text(input, format, location) {
134
- let deferred4_0;
135
- let deferred4_1;
225
+ function split_json_bits(input) {
226
+ let deferred2_0;
227
+ let deferred2_1;
136
228
  try {
137
229
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
138
230
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
139
231
  const len0 = WASM_VECTOR_LEN;
140
- const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
232
+ wasm.split_json_bits(retptr, ptr0, len0);
233
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
234
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
235
+ deferred2_0 = r0;
236
+ deferred2_1 = r1;
237
+ return getStringFromWasm0(r0, r1);
238
+ } finally {
239
+ wasm.__wbindgen_add_to_stack_pointer(16);
240
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
241
+ }
242
+ }
243
+ function fullize(input, pretty, indent) {
244
+ let deferred2_0;
245
+ let deferred2_1;
246
+ try {
247
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
248
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
249
+ const len0 = WASM_VECTOR_LEN;
250
+ wasm.fullize(retptr, ptr0, len0, pretty, indent);
251
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
252
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
253
+ deferred2_0 = r0;
254
+ deferred2_1 = r1;
255
+ return getStringFromWasm0(r0, r1);
256
+ } finally {
257
+ wasm.__wbindgen_add_to_stack_pointer(16);
258
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
259
+ }
260
+ }
261
+ function convert(input, input_format_sel, output_format_sel, mode, pretty, indent, spaces_around_values) {
262
+ let deferred5_0;
263
+ let deferred5_1;
264
+ try {
265
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
266
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
267
+ const len0 = WASM_VECTOR_LEN;
268
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
141
269
  const len1 = WASM_VECTOR_LEN;
142
- const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
270
+ const ptr2 = passStringToWasm0(output_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
143
271
  const len2 = WASM_VECTOR_LEN;
144
- wasm.breakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
272
+ const ptr3 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
273
+ const len3 = WASM_VECTOR_LEN;
274
+ wasm.convert(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, pretty, indent, spaces_around_values);
145
275
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
146
276
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
147
- deferred4_0 = r0;
148
- deferred4_1 = r1;
277
+ deferred5_0 = r0;
278
+ deferred5_1 = r1;
149
279
  return getStringFromWasm0(r0, r1);
150
280
  } finally {
151
281
  wasm.__wbindgen_add_to_stack_pointer(16);
152
- wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
282
+ wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);
153
283
  }
154
284
  }
155
- function info(info_type, format, bit, pretty, indent) {
285
+ function is_bitmark(input) {
286
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
287
+ const len0 = WASM_VECTOR_LEN;
288
+ const ret = wasm.is_bitmark(ptr0, len0);
289
+ return ret !== 0;
290
+ }
291
+ function breakscape_text(input, format, location) {
156
292
  let deferred4_0;
157
293
  let deferred4_1;
158
294
  try {
159
295
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
160
- const ptr0 = passStringToWasm0(info_type, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
296
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
161
297
  const len0 = WASM_VECTOR_LEN;
162
298
  const ptr1 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
163
299
  const len1 = WASM_VECTOR_LEN;
164
- const ptr2 = passStringToWasm0(bit, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
300
+ const ptr2 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
165
301
  const len2 = WASM_VECTOR_LEN;
166
- wasm.info(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent);
302
+ wasm.breakscape_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2);
167
303
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
168
304
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
169
305
  deferred4_0 = r0;
@@ -194,6 +330,60 @@ function parse(input, mode) {
194
330
  wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
195
331
  }
196
332
  }
333
+ function optimize(input, pretty, indent) {
334
+ let deferred2_0;
335
+ let deferred2_1;
336
+ try {
337
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
338
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
339
+ const len0 = WASM_VECTOR_LEN;
340
+ wasm.optimize(retptr, ptr0, len0, pretty, indent);
341
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
342
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
343
+ deferred2_0 = r0;
344
+ deferred2_1 = r1;
345
+ return getStringFromWasm0(r0, r1);
346
+ } finally {
347
+ wasm.__wbindgen_add_to_stack_pointer(16);
348
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
349
+ }
350
+ }
351
+ function count_bits(input) {
352
+ let deferred2_0;
353
+ let deferred2_1;
354
+ try {
355
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
356
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
357
+ const len0 = WASM_VECTOR_LEN;
358
+ wasm.count_bits(retptr, ptr0, len0);
359
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
360
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
361
+ deferred2_0 = r0;
362
+ deferred2_1 = r1;
363
+ return getStringFromWasm0(r0, r1);
364
+ } finally {
365
+ wasm.__wbindgen_add_to_stack_pointer(16);
366
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
367
+ }
368
+ }
369
+ function split_bits(input) {
370
+ let deferred2_0;
371
+ let deferred2_1;
372
+ try {
373
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
374
+ const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
375
+ const len0 = WASM_VECTOR_LEN;
376
+ wasm.split_bits(retptr, ptr0, len0);
377
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
378
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
379
+ deferred2_0 = r0;
380
+ deferred2_1 = r1;
381
+ return getStringFromWasm0(r0, r1);
382
+ } finally {
383
+ wasm.__wbindgen_add_to_stack_pointer(16);
384
+ wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
385
+ }
386
+ }
197
387
  async function __wbg_load(module, imports) {
198
388
  if (typeof Response === "function" && module instanceof Response) {
199
389
  if (typeof WebAssembly.instantiateStreaming === "function") {
@@ -274,12 +464,193 @@ var bitmark_wasm_default = __wbg_init;
274
464
  // src/generated/package_info.ts
275
465
  var PACKAGE_INFO = {
276
466
  "name": "@gmb/bitmark-parser",
277
- "version": "6.0.1",
467
+ "version": "6.1.0",
278
468
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
279
469
  "license": "ISC",
280
470
  "description": "A parser for bitmark text, powered by WebAssembly."
281
471
  };
282
472
 
473
+ // src/core/hooked-transform.ts
474
+ function isError(s) {
475
+ return s.startsWith("error:");
476
+ }
477
+ function errorString(e) {
478
+ const m = e instanceof Error ? e.message : String(e);
479
+ return m.startsWith("error:") ? m : `error: ${m}`;
480
+ }
481
+ function stripArray(doc) {
482
+ const t = doc.trim();
483
+ return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
484
+ }
485
+ function normalisePatch(patch) {
486
+ if (patch === void 0) return [];
487
+ if (typeof patch === "string") {
488
+ const trimmed = patch.trim();
489
+ return trimmed === "" ? [] : JSON.parse(trimmed);
490
+ }
491
+ return patch;
492
+ }
493
+ function buildUnits(wasm2, input, inputIsBitmark) {
494
+ if (inputIsBitmark) {
495
+ const out2 = wasm2.split_bits(input);
496
+ if (isError(out2)) throw new Error(out2);
497
+ const slices = JSON.parse(out2);
498
+ return slices.map((s) => ({
499
+ view: { format: "bitmark", index: s.index, total: slices.length, source: s.source },
500
+ source: s.source
501
+ }));
502
+ }
503
+ const out = wasm2.split_json_bits(input);
504
+ if (isError(out)) throw new Error(out);
505
+ const envelopes = JSON.parse(out);
506
+ return envelopes.map((env, index) => ({
507
+ view: { format: "json", index, total: envelopes.length, bit: env.bit },
508
+ // Per-bit transform consumes a one-bit JSON document.
509
+ source: JSON.stringify([env])
510
+ }));
511
+ }
512
+ function planTransform(wasm2, input, options) {
513
+ const mode = options.mode ?? "optimized";
514
+ const output = options.outputFormat ?? "json";
515
+ const spacesAroundValues = options.spacesAroundValues ?? 1;
516
+ const indent = options.indent ?? 2;
517
+ const pretty = options.pretty ?? false;
518
+ const sel = options.inputFormat ?? "auto";
519
+ const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm2.is_bitmark(input);
520
+ const inputFormat = inputIsBitmark ? "bitmark" : "json";
521
+ const staticPatch = normalisePatch(options.patch);
522
+ const units = buildUnits(wasm2, input, inputIsBitmark);
523
+ const total = units.length;
524
+ const jobs = [];
525
+ const views = [];
526
+ for (let index = 0; index < total; index++) {
527
+ const { view, source } = units[index];
528
+ view.index = index;
529
+ view.total = total;
530
+ const result = options.preHook ? options.preHook(view) || {} : {};
531
+ if (result.drop) continue;
532
+ const patches = result.patches ? [...staticPatch, ...result.patches] : staticPatch;
533
+ jobs.push({
534
+ index,
535
+ source,
536
+ inputFormat,
537
+ outputFormat: result.outputFormat ?? output,
538
+ mode,
539
+ patchJson: JSON.stringify(patches),
540
+ spacesAroundValues
541
+ });
542
+ views.push(view);
543
+ }
544
+ return { jobs, views, output, pretty, indent };
545
+ }
546
+ function computeBit(wasm2, job) {
547
+ const out = wasm2.transform(
548
+ job.source,
549
+ job.inputFormat,
550
+ job.outputFormat,
551
+ job.mode,
552
+ job.patchJson,
553
+ false,
554
+ 2,
555
+ job.spacesAroundValues
556
+ );
557
+ if (isError(out)) return out;
558
+ return job.outputFormat === "json" ? stripArray(out) : out;
559
+ }
560
+ function recombine(wasm2, elements, output, pretty, indent) {
561
+ if (output === "bitmark") return elements.join("\n");
562
+ const arr = `[${elements.join(",")}]`;
563
+ return pretty ? wasm2.prettify(arr, indent) : arr;
564
+ }
565
+ function runHookedTransform(wasm2, input, options) {
566
+ let plan;
567
+ try {
568
+ plan = planTransform(wasm2, input, options);
569
+ } catch (e) {
570
+ return errorString(e);
571
+ }
572
+ const rendered = [];
573
+ for (let i = 0; i < plan.jobs.length; i++) {
574
+ const element = computeBit(wasm2, plan.jobs[i]);
575
+ if (isError(element)) return element;
576
+ options.postHook?.(plan.views[i], element);
577
+ rendered.push(element);
578
+ }
579
+ return recombine(wasm2, rendered, plan.output, plan.pretty, plan.indent);
580
+ }
581
+
582
+ // src/core/parallel.ts
583
+ async function orchestrateParallel(wasm2, input, options, runJobs) {
584
+ let plan;
585
+ try {
586
+ plan = planTransform(wasm2, input, options);
587
+ } catch (e) {
588
+ return errorString(e);
589
+ }
590
+ let elements;
591
+ try {
592
+ elements = await runJobs(plan.jobs, options.workers ?? 4);
593
+ } catch (e) {
594
+ return errorString(e);
595
+ }
596
+ for (let i = 0; i < elements.length; i++) {
597
+ if (isError(elements[i])) return elements[i];
598
+ options.postHook?.(plan.views[i], elements[i]);
599
+ }
600
+ return recombine(wasm2, elements, plan.output, plan.pretty, plan.indent);
601
+ }
602
+
603
+ // src/browser/pool.ts
604
+ function runJobsParallel(jobs, workers) {
605
+ if (jobs.length === 0) return Promise.resolve([]);
606
+ const poolSize = Math.max(1, Math.min(workers, jobs.length));
607
+ const workerUrl = new URL("./worker-entry.js", import.meta.url);
608
+ return new Promise((resolve, reject) => {
609
+ const results = new Array(jobs.length);
610
+ let next = 0;
611
+ let settled = 0;
612
+ let done = false;
613
+ const pool = [];
614
+ const shutdown = () => {
615
+ for (const w of pool) w.terminate();
616
+ };
617
+ const fail = (err) => {
618
+ if (done) return;
619
+ done = true;
620
+ shutdown();
621
+ reject(err);
622
+ };
623
+ const dispatch = (w) => {
624
+ if (done || next >= jobs.length) return;
625
+ const id = next++;
626
+ w.postMessage({ id, job: jobs[id] });
627
+ };
628
+ for (let i = 0; i < poolSize; i++) {
629
+ const w = new Worker(workerUrl, { type: "module" });
630
+ pool.push(w);
631
+ w.onmessage = (ev) => {
632
+ const res = ev.data;
633
+ if (done) return;
634
+ if (!res.ok) {
635
+ fail(new Error(res.error ?? "worker job failed"));
636
+ return;
637
+ }
638
+ results[res.id] = res.element;
639
+ settled++;
640
+ if (settled === jobs.length) {
641
+ done = true;
642
+ shutdown();
643
+ resolve(results);
644
+ return;
645
+ }
646
+ dispatch(w);
647
+ };
648
+ w.onerror = (e) => fail(new Error(e.message || "worker error"));
649
+ }
650
+ for (const w of pool) dispatch(w);
651
+ });
652
+ }
653
+
283
654
  // src/browser/index.ts
284
655
  async function init(module_or_path) {
285
656
  if (typeof module_or_path === "undefined") {
@@ -297,7 +668,58 @@ function parse2(input, options = {}) {
297
668
  return parse(input, options.mode ?? "optimized");
298
669
  }
299
670
  function convert2(input, options = {}) {
300
- return convert(input, options.mode ?? "optimized", options.warnings ?? false, options.plainText ?? false, options.pretty ?? false, options.indent ?? 2);
671
+ return convert(
672
+ input,
673
+ options.inputFormat ?? "auto",
674
+ options.outputFormat ?? "auto",
675
+ options.mode ?? "optimized",
676
+ options.pretty ?? false,
677
+ options.indent ?? 2,
678
+ options.spacesAroundValues ?? 1
679
+ );
680
+ }
681
+ function optimize2(input, options = {}) {
682
+ return optimize(input, options.pretty ?? false, options.indent ?? 2);
683
+ }
684
+ function fullize2(input, options = {}) {
685
+ return fullize(input, options.pretty ?? false, options.indent ?? 2);
686
+ }
687
+ var expand = fullize2;
688
+ function canonicalize2(input, options = {}) {
689
+ return canonicalize(
690
+ input,
691
+ options.mode ?? "optimized",
692
+ options.pretty ?? false,
693
+ options.indent ?? 2,
694
+ options.spacesAroundValues ?? 1
695
+ );
696
+ }
697
+ function countBits(input) {
698
+ const out = count_bits(input);
699
+ if (out.startsWith("error:")) throw new Error(out);
700
+ return Number.parseInt(out, 10);
701
+ }
702
+ function splitBits(input) {
703
+ return JSON.parse(split_bits(input));
704
+ }
705
+ function transform2(input, options = {}) {
706
+ if (options.preHook || options.postHook) {
707
+ return runHookedTransform(bitmark_wasm_exports, input, options);
708
+ }
709
+ const patchJson = options.patch === void 0 ? "" : typeof options.patch === "string" ? options.patch : JSON.stringify(options.patch);
710
+ return transform(
711
+ input,
712
+ options.inputFormat ?? "auto",
713
+ options.outputFormat ?? "json",
714
+ options.mode ?? "optimized",
715
+ patchJson,
716
+ options.pretty ?? false,
717
+ options.indent ?? 2,
718
+ options.spacesAroundValues ?? 1
719
+ );
720
+ }
721
+ function transformParallel(input, options = {}) {
722
+ return orchestrateParallel(bitmark_wasm_exports, input, options, runJobsParallel);
301
723
  }
302
724
  function breakscapeText(input, options = {}) {
303
725
  const format = options.format ?? "bitmark++";
@@ -319,12 +741,20 @@ function info2(options = {}) {
319
741
  }
320
742
  export {
321
743
  breakscapeText,
744
+ canonicalize2 as canonicalize,
322
745
  convert2 as convert,
746
+ countBits,
747
+ expand,
748
+ fullize2 as fullize,
323
749
  info2 as info,
324
750
  init,
325
751
  initSync,
326
752
  lex2 as lex,
753
+ optimize2 as optimize,
327
754
  parse2 as parse,
755
+ splitBits,
756
+ transform2 as transform,
757
+ transformParallel,
328
758
  unbreakscapeText,
329
759
  version
330
760
  };