@gmb/bitmark-parser 6.1.2 → 6.1.4

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.
package/dist/index.js CHANGED
@@ -1,10 +1,16 @@
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
  // src/index.ts
2
8
  import { createRequire } from "module";
3
9
 
4
10
  // src/generated/package_info.ts
5
11
  var PACKAGE_INFO = {
6
12
  "name": "@gmb/bitmark-parser",
7
- "version": "6.1.2",
13
+ "version": "6.1.4",
8
14
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
9
15
  "license": "ISC",
10
16
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -149,7 +155,7 @@ function workerPath() {
149
155
  function runJobsParallel(jobs, workers) {
150
156
  if (jobs.length === 0) return Promise.resolve([]);
151
157
  const poolSize = Math.max(1, Math.min(workers, jobs.length));
152
- const path = workerPath();
158
+ const path2 = workerPath();
153
159
  return new Promise((resolve, reject) => {
154
160
  const results = new Array(jobs.length);
155
161
  let next = 0;
@@ -172,7 +178,7 @@ function runJobsParallel(jobs, workers) {
172
178
  w.postMessage({ id, job: jobs[id] });
173
179
  };
174
180
  for (let i = 0; i < poolSize; i++) {
175
- const w = new Worker(path);
181
+ const w = new Worker(path2);
176
182
  pool.push(w);
177
183
  w.on("message", (res) => {
178
184
  if (done) return;
@@ -204,9 +210,1091 @@ function runParallelTransform(wasm2, input, options) {
204
210
  return orchestrateParallel(wasm2, input, options, runJobsParallel);
205
211
  }
206
212
 
213
+ // src/node/legacy-init.ts
214
+ import * as fs from "fs";
215
+ import * as path from "path";
216
+
217
+ // src/legacy/runtime.ts
218
+ var wasmModule;
219
+ function setLegacyWasm(wasm2) {
220
+ wasmModule = wasm2;
221
+ }
222
+ function getLegacyWasm() {
223
+ if (!wasmModule) {
224
+ throw new Error(
225
+ "legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)"
226
+ );
227
+ }
228
+ return wasmModule;
229
+ }
230
+ var fileIo;
231
+ function setLegacyFileIo(io) {
232
+ fileIo = io;
233
+ }
234
+ function getLegacyFileIo() {
235
+ return fileIo;
236
+ }
237
+
238
+ // src/node/legacy-init.ts
239
+ function initLegacyNode(wasm2) {
240
+ setLegacyWasm(wasm2);
241
+ setLegacyFileIo({
242
+ existsSync: (p) => fs.existsSync(p),
243
+ readFileSync: (p, encoding) => fs.readFileSync(p, { encoding }),
244
+ writeFile: (p, data, opts) => {
245
+ fs.mkdirSync(path.dirname(p), { recursive: true });
246
+ fs.writeFileSync(p, data, {
247
+ encoding: opts.encoding ?? "utf8",
248
+ flag: opts.append ? "a" : "w"
249
+ });
250
+ }
251
+ });
252
+ }
253
+
254
+ // src/legacy/index.ts
255
+ var legacy_exports = {};
256
+ __export(legacy_exports, {
257
+ Ast: () => Ast,
258
+ BitType: () => BitType,
259
+ BitmarkFileGenerator: () => BitmarkFileGenerator,
260
+ BitmarkGenerator: () => BitmarkGenerator,
261
+ BitmarkParser: () => BitmarkParser,
262
+ BitmarkParserGenerator: () => BitmarkParserGenerator,
263
+ BitmarkParserType: () => BitmarkParserType,
264
+ BitmarkStringGenerator: () => BitmarkStringGenerator,
265
+ BitmarkVersion: () => BitmarkVersion,
266
+ BodyTextFormat: () => BodyTextFormat,
267
+ BoundingBoxIndex: () => BoundingBoxIndex,
268
+ Builder: () => Builder,
269
+ CardSetVersion: () => CardSetVersion,
270
+ FileWriter: () => FileWriter,
271
+ HtmlTableGenerator: () => HtmlTableGenerator,
272
+ HtmlTableParser: () => HtmlTableParser,
273
+ InfoFormat: () => InfoFormat,
274
+ InfoType: () => InfoType,
275
+ Input: () => Input,
276
+ InputFormat: () => InputFormat,
277
+ JsonFileGenerator: () => JsonFileGenerator,
278
+ JsonGenerator: () => JsonGenerator,
279
+ JsonParser: () => JsonParser,
280
+ JsonStringGenerator: () => JsonStringGenerator,
281
+ LegacyUnsupportedError: () => LegacyUnsupportedError,
282
+ NodeType: () => NodeType,
283
+ Output: () => Output,
284
+ ResourceBuilder: () => ResourceBuilder,
285
+ StreamWriter: () => StreamWriter,
286
+ StringWriter: () => StringWriter,
287
+ TextLocation: () => TextLocation,
288
+ TextMarkType: () => TextMarkType,
289
+ TextNodeType: () => TextNodeType,
290
+ bitmarkTextParse: () => bitmarkTextParse,
291
+ isPseudoAst: () => isPseudoAst
292
+ });
293
+
294
+ // src/legacy/errors.ts
295
+ var LegacyUnsupportedError = class extends Error {
296
+ constructor(message) {
297
+ super(message);
298
+ this.name = "LegacyUnsupportedError";
299
+ }
300
+ };
301
+ function unsupportedMember(member, reason) {
302
+ throw new LegacyUnsupportedError(
303
+ `'${member}' is not supported by the @gmb/bitmark-parser legacy API` + (reason ? `: ${reason}` : "")
304
+ );
305
+ }
306
+ function unsupportedOption(option, reason) {
307
+ throw new LegacyUnsupportedError(
308
+ `Option '${option}' is not supported by the @gmb/bitmark-parser legacy API` + (reason ? `: ${reason}` : "")
309
+ );
310
+ }
311
+
312
+ // src/legacy/translate.ts
313
+ var V3_ONLY = "bitmark v2 output is not supported (this parser is bitmark v3 only)";
314
+ function validateVersionOptions(opts) {
315
+ if (opts.bitmarkVersion === 2) unsupportedOption("bitmarkVersion: 2", V3_ONLY);
316
+ }
317
+ function validateBitmarkOptions(o) {
318
+ if (o.explicitTextFormat) unsupportedOption("bitmarkOptions.explicitTextFormat");
319
+ if (o.prettifyJson !== void 0 && o.prettifyJson !== false) {
320
+ unsupportedOption("bitmarkOptions.prettifyJson", "embedded-JSON body prettification is not supported");
321
+ }
322
+ if (o.cardSetVersion === 1) unsupportedOption("bitmarkOptions.cardSetVersion: 1", V3_ONLY);
323
+ if (o.debugGenerationInline) unsupportedOption("bitmarkOptions.debugGenerationInline");
324
+ if (o.noBreakscaping) unsupportedOption("bitmarkOptions.noBreakscaping");
325
+ }
326
+ function validateJsonOptions(o) {
327
+ if (o.textAsPlainText) unsupportedOption("jsonOptions.textAsPlainText", V3_ONLY);
328
+ if (o.excludeUnknownProperties) unsupportedOption("jsonOptions.excludeUnknownProperties");
329
+ if (o.debugGenerationInline) unsupportedOption("jsonOptions.debugGenerationInline");
330
+ }
331
+ function prettyIndent(prettify) {
332
+ if (prettify === true) return { pretty: true, indent: 2 };
333
+ if (typeof prettify === "number" && prettify > 0) return { pretty: true, indent: prettify };
334
+ return { pretty: false, indent: 2 };
335
+ }
336
+ function spacesAround(v) {
337
+ if (v === void 0 || v === true) return 1;
338
+ if (v === false) return 0;
339
+ return Math.max(0, Math.min(10, v));
340
+ }
341
+ function mapTextFormat(f) {
342
+ switch (f) {
343
+ case "text":
344
+ case "latex":
345
+ case "json":
346
+ case "xml":
347
+ return "plainText";
348
+ default:
349
+ return "bitmark++";
350
+ }
351
+ }
352
+
353
+ // src/legacy/pseudo-ast.ts
354
+ var PSEUDO_AST_MARKER = /* @__PURE__ */ Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");
355
+ function makePseudoAst(bits) {
356
+ const ast = { bits };
357
+ Object.defineProperty(ast, PSEUDO_AST_MARKER, { value: true, enumerable: false });
358
+ return ast;
359
+ }
360
+ function isPseudoAst(v) {
361
+ return v !== null && typeof v === "object" && (PSEUDO_AST_MARKER in v || Array.isArray(v.bits));
362
+ }
363
+
364
+ // src/legacy/builder.ts
365
+ var BUILT_BIT_PARSER = /* @__PURE__ */ Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser");
366
+ var DATA_KEY_TO_JSON_KEY = {
367
+ bitType: "type",
368
+ textFormat: "format",
369
+ flashcards: "cards",
370
+ markConfig: "marks"
371
+ };
372
+ var DEPRECATED_TEXT_FORMATS = {
373
+ "bitmark--": "bitmark++",
374
+ "bitmark+": "bitmark++"
375
+ };
376
+ var TAG_TEXT_KEYS = [
377
+ "title",
378
+ "subtitle",
379
+ "item",
380
+ "lead",
381
+ "pageNumber",
382
+ "marginNumber",
383
+ "hint",
384
+ "instruction",
385
+ "caption"
386
+ ];
387
+ var Builder = class {
388
+ /**
389
+ * Build bitmark AST envelope (bpg-compatible `buildBitmark`).
390
+ */
391
+ buildBitmark(data) {
392
+ const ast = makePseudoAst(data.bits ?? []);
393
+ if (data.errors !== void 0) {
394
+ ast.errors = data.errors;
395
+ }
396
+ return ast;
397
+ }
398
+ /**
399
+ * Build a bit (bpg-compatible `buildBit`).
400
+ *
401
+ * Accepts the full bpg data shape (flat, ~250 optional fields, values in
402
+ * the JSON model types). Returns the normalized bit JSON. Throws
403
+ * `No config found for bit: X` for unknown bit types, as bpg does.
404
+ *
405
+ * NOTE (documented divergences from bpg):
406
+ * - the return value is bit JSON, not bpg's internal AST node model;
407
+ * - `resourceType` (an inference hint in bpg) is not carried into the
408
+ * JSON — the attached `resource` object is authoritative;
409
+ * - more than one entry in `resources` passes through under a
410
+ * `resources` key (kept visible, not silently dropped) — the canonical
411
+ * single attachment is `resource`.
412
+ */
413
+ buildBit(data, _options) {
414
+ const wasm2 = getLegacyWasm();
415
+ const src = { ...data };
416
+ const bitType = src.bitType;
417
+ this.assertKnownBitType(bitType);
418
+ const bit = {};
419
+ bit.type = bitType;
420
+ if (src.isCommented) {
421
+ bit.type = "_comment";
422
+ bit.originalType = bitType;
423
+ }
424
+ delete src.bitType;
425
+ delete src.isCommented;
426
+ const textFormat = src.textFormat;
427
+ if (textFormat !== void 0) {
428
+ bit.format = DEPRECATED_TEXT_FORMATS[textFormat] ?? textFormat;
429
+ delete src.textFormat;
430
+ }
431
+ delete src.resourceType;
432
+ const body = src.body;
433
+ if (body !== void 0 && body !== null && typeof body === "object" && "body" in body) {
434
+ bit.body = body.body;
435
+ delete src.body;
436
+ }
437
+ if (src.example !== void 0) {
438
+ bit.isExample = true;
439
+ bit.example = src.example;
440
+ delete src.example;
441
+ delete src.__isDefaultExample;
442
+ } else if (src.__isDefaultExample) {
443
+ bit.isExample = true;
444
+ delete src.__isDefaultExample;
445
+ }
446
+ const resources = src.resources;
447
+ if (resources !== void 0) {
448
+ if (Array.isArray(resources)) {
449
+ if (resources.length === 1) bit.resource = resources[0];
450
+ else if (resources.length > 1) bit.resources = resources;
451
+ } else {
452
+ bit.resource = resources;
453
+ }
454
+ delete src.resources;
455
+ }
456
+ const parser = src.parser;
457
+ delete src.parser;
458
+ const extraProperties = src.extraProperties;
459
+ delete src.extraProperties;
460
+ for (const [key, value] of Object.entries(src)) {
461
+ if (value === void 0) continue;
462
+ bit[DATA_KEY_TO_JSON_KEY[key] ?? key] = value;
463
+ }
464
+ if (extraProperties) {
465
+ for (const [key, value] of Object.entries(extraProperties)) {
466
+ if (!(key in bit)) bit[key] = value;
467
+ }
468
+ }
469
+ this.parseStringTexts(bit);
470
+ const out = wasm2.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1);
471
+ if (out.startsWith("error:")) {
472
+ throw new Error(out.slice("error:".length).trim());
473
+ }
474
+ const entries = JSON.parse(out);
475
+ const built = entries[0]?.bit ?? bit;
476
+ for (const [key, value] of Object.entries(bit)) {
477
+ if (key in built) continue;
478
+ if (value === false || value === "" || value === null || Array.isArray(value) && value.length === 0) {
479
+ continue;
480
+ }
481
+ built[key] = value;
482
+ }
483
+ if (parser !== void 0) {
484
+ Object.defineProperty(built, BUILT_BIT_PARSER, { value: parser, enumerable: false });
485
+ }
486
+ return built;
487
+ }
488
+ /**
489
+ * Build a highlight body bit (bpg-compatible `buildHighlight`).
490
+ * Shapes the HighlightJson body-bit; unset optionals are omitted.
491
+ */
492
+ buildHighlight(_context, data) {
493
+ if (!data) return void 0;
494
+ const src = { ...data };
495
+ const attrs = src.attrs;
496
+ if (attrs) Object.assign(src, attrs);
497
+ const texts = Array.isArray(src.texts) ? src.texts.filter((t) => t != null).map((t) => ({
498
+ text: t.text ?? "",
499
+ isCorrect: t.isCorrect ?? false,
500
+ isHighlighted: t.isHighlighted ?? false,
501
+ ...stripUndefined(t, ["text", "isCorrect", "isHighlighted"])
502
+ })) : [];
503
+ const node = {
504
+ type: "highlight",
505
+ texts,
506
+ prefix: src.prefix ?? "",
507
+ postfix: src.postfix ?? "",
508
+ ...stripUndefined(src, ["type", "texts", "prefix", "postfix", "attrs"]),
509
+ attrs: {}
510
+ };
511
+ return node;
512
+ }
513
+ /**
514
+ * bpg's builder parses string-valued JsonText fields as bitmark text
515
+ * (inline marks become TextAst marks); the composer would otherwise treat
516
+ * them as literal text. Converts top-level JsonText fields in place.
517
+ * Nested (card-content) strings are left literal — documented divergence.
518
+ */
519
+ parseStringTexts(bit) {
520
+ const wasm2 = getLegacyWasm();
521
+ const toAst = (s, location) => {
522
+ if (s === "") return s;
523
+ const out = wasm2.convert_text(s, "textToAst", "bitmark++", location);
524
+ try {
525
+ return JSON.parse(out);
526
+ } catch {
527
+ return s;
528
+ }
529
+ };
530
+ const format = bit.format;
531
+ const bitmarkBody = format === void 0 || format === "bitmark++" || format === "bitmark+";
532
+ if (typeof bit.body === "string" && bitmarkBody) {
533
+ bit.body = toAst(bit.body, "body");
534
+ }
535
+ for (const key of TAG_TEXT_KEYS) {
536
+ const v = bit[key];
537
+ if (typeof v === "string") bit[key] = toAst(v, "tag");
538
+ }
539
+ }
540
+ /** Throw bpg's exact unknown-bit-type error (`Config.getBitConfig` parity). */
541
+ assertKnownBitType(bitType) {
542
+ const wasm2 = getLegacyWasm();
543
+ let known = false;
544
+ if (bitType !== void 0) {
545
+ try {
546
+ const info2 = JSON.parse(wasm2.info("bit", "json", bitType, false, 2));
547
+ known = info2.error === void 0;
548
+ } catch {
549
+ known = false;
550
+ }
551
+ }
552
+ if (!known) {
553
+ throw new Error(`No config found for bit: ${bitType}`);
554
+ }
555
+ }
556
+ };
557
+ function stripUndefined(src, exclude) {
558
+ const out = {};
559
+ for (const [k, v] of Object.entries(src)) {
560
+ if (v !== void 0 && !exclude.includes(k)) out[k] = v;
561
+ }
562
+ return out;
563
+ }
564
+
565
+ // src/legacy/bpg-class.ts
566
+ var BitmarkParserGenerator = class {
567
+ /**
568
+ * Get the version of the library.
569
+ *
570
+ * Reports the @gmb/bitmark-parser version (not a bpg version string).
571
+ */
572
+ version() {
573
+ return PACKAGE_INFO.version;
574
+ }
575
+ /**
576
+ * Convert bitmark from bitmark to JSON, or JSON to bitmark (bpg-compatible).
577
+ *
578
+ * Input detection order matches bpg: AST → JSON → assume bitmark.
579
+ * Default output: bitmark input → json; json/ast input → bitmark.
580
+ */
581
+ convert(input, options) {
582
+ const opts = Object.assign({}, options);
583
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
584
+ const bitmarkOptions = Object.assign({}, opts.bitmarkOptions);
585
+ validateVersionOptions(opts);
586
+ validateBitmarkOptions(bitmarkOptions);
587
+ validateJsonOptions(jsonOptions);
588
+ this.checkBrowserFileWrite(opts.outputFile);
589
+ const wasm2 = getLegacyWasm();
590
+ const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
591
+ const outputFormat = opts.outputFormat ?? (isBitmark ? "json" : "bitmark");
592
+ const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
593
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
594
+ const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
595
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", pretty, indent, spaces);
596
+ this.throwOnError(out);
597
+ if (outputFormat === "bitmark" || outputFormat === "text") {
598
+ return this.deliver(out, opts.outputFile, opts.fileOptions);
599
+ }
600
+ if (outputFormat === "json") {
601
+ if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
602
+ if (pretty || jsonOptions.stringify) return out;
603
+ return JSON.parse(out);
604
+ }
605
+ const ast = makePseudoAst(JSON.parse(out));
606
+ if (opts.outputFile) {
607
+ return this.deliver(JSON.stringify(ast), opts.outputFile, opts.fileOptions);
608
+ }
609
+ return ast;
610
+ }
611
+ /**
612
+ * Upgrade (prettify / canonicalize) bitmark or JSON to the latest version
613
+ * of itself (bpg-compatible `upgrade`).
614
+ */
615
+ upgrade(input, options) {
616
+ const opts = Object.assign({}, options);
617
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
618
+ const bitmarkOptions = Object.assign({}, opts.bitmarkOptions);
619
+ validateVersionOptions(opts);
620
+ validateBitmarkOptions(bitmarkOptions);
621
+ validateJsonOptions(jsonOptions);
622
+ this.checkBrowserFileWrite(opts.outputFile);
623
+ const wasm2 = getLegacyWasm();
624
+ const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
625
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
626
+ const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
627
+ const out = wasm2.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
628
+ this.throwOnError(out);
629
+ if (isBitmark) return this.deliver(out, opts.outputFile, opts.fileOptions);
630
+ if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
631
+ if (pretty || jsonOptions.stringify) return out;
632
+ return JSON.parse(out);
633
+ }
634
+ /**
635
+ * Get information about the bitmark language (bpg-compatible `info`).
636
+ */
637
+ info(options) {
638
+ const opts = Object.assign({}, options);
639
+ const wasm2 = getLegacyWasm();
640
+ const type = opts.type ?? "list";
641
+ const format = opts.outputFormat ?? "text";
642
+ const { pretty, indent } = prettyIndent(opts.prettify);
643
+ const coreFormat = format === "pojo" ? "json" : format;
644
+ const out = wasm2.info(type, coreFormat, opts.bit ?? "", pretty, indent);
645
+ this.throwOnError(out);
646
+ if (format === "pojo") return JSON.parse(out);
647
+ return out;
648
+ }
649
+ /** Not supported: bpg-internal development tool. */
650
+ generateConfig(_options) {
651
+ unsupportedMember("BitmarkParserGenerator.generateConfig", "bpg-internal development tool");
652
+ }
653
+ /**
654
+ * Convert between HTML tables and bitmark tables (bpg-compatible
655
+ * `convertHtmlTable`).
656
+ *
657
+ * Backed by the core's schema-driven html mapping: HTML input has each
658
+ * `<table>` wrapped in the core's `<bitmark-bit>` envelope and parsed;
659
+ * bits input is emitted as html and the `<table>` fragments extracted
660
+ * (the envelope stripped). The markup *inside* `<table>` follows this
661
+ * parser's html mapping, which may differ from bpg's in detail.
662
+ */
663
+ convertHtmlTable(input, options) {
664
+ const opts = Object.assign({}, options);
665
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
666
+ const bitmarkOptions = Object.assign({}, opts.bitmarkOptions);
667
+ validateBitmarkOptions(bitmarkOptions);
668
+ validateJsonOptions(jsonOptions);
669
+ if (opts.keepUnknownTags) unsupportedOption("keepUnknownTags");
670
+ if (opts.noBreakscaping) unsupportedOption("noBreakscaping");
671
+ this.checkBrowserFileWrite(opts.outputFile);
672
+ const wasm2 = getLegacyWasm();
673
+ const inStr = typeof input === "string" ? this.maybeReadFile(input, void 0) : "";
674
+ const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
675
+ if (!isHtmlInput) {
676
+ const { source, isBitmark } = this.resolveInput(input, void 0);
677
+ const out2 = wasm2.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1);
678
+ this.throwOnError(out2);
679
+ return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
680
+ }
681
+ const bitType = opts.tableFormat === "table" ? "table" : "table-extended";
682
+ const wrapped = extractHtmlTables(inStr).map((t) => `<bitmark-bit data-type="${bitType}" data-format="bitmark++">${t}</bitmark-bit>`).join("");
683
+ const outputFormat = opts.outputFormat ?? "bitmark";
684
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
685
+ const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
686
+ if (outputFormat === "html") {
687
+ const out2 = wasm2.convert(wrapped, "html", "html", "optimized", false, 2, 1);
688
+ this.throwOnError(out2);
689
+ return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
690
+ }
691
+ const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
692
+ const out = wasm2.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces);
693
+ this.throwOnError(out);
694
+ if (outputFormat === "bitmark" || outputFormat === "text") {
695
+ return this.deliver(out, opts.outputFile, opts.fileOptions);
696
+ }
697
+ if (outputFormat === "json") {
698
+ if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
699
+ if (pretty || jsonOptions.stringify) return out;
700
+ return JSON.parse(out);
701
+ }
702
+ const ast = makePseudoAst(JSON.parse(out));
703
+ if (opts.outputFile) return this.deliver(JSON.stringify(ast), opts.outputFile, opts.fileOptions);
704
+ return ast;
705
+ }
706
+ /**
707
+ * Create a bit-JSON pseudo-AST from bitmark or JSON input (PLAN-126 §3.1).
708
+ *
709
+ * NOTE: the returned structure is the bit JSON (wrapper entries), not
710
+ * bpg's internal TS AST node model. It round-trips through `convert` but
711
+ * is not walkable with bpg's `Ast`/`NodeType`.
712
+ */
713
+ createAst(input, options) {
714
+ const opts = Object.assign({}, options);
715
+ const wasm2 = getLegacyWasm();
716
+ const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
717
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1);
718
+ this.throwOnError(out);
719
+ return makePseudoAst(JSON.parse(out));
720
+ }
721
+ /**
722
+ * Breakscape text (bpg-compatible `breakscapeText`).
723
+ */
724
+ breakscapeText(input, options) {
725
+ if (!input) return input;
726
+ const opts = Object.assign({}, options);
727
+ this.checkBrowserFileWrite(opts.outputFile);
728
+ const wasm2 = getLegacyWasm();
729
+ const inStr = this.maybeReadFile(input, opts.inputFormat);
730
+ const res = wasm2.breakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
731
+ return this.deliver(res, opts.outputFile, opts.fileOptions);
732
+ }
733
+ /**
734
+ * Unbreakscape text (bpg-compatible `unbreakscapeText`).
735
+ */
736
+ unbreakscapeText(input, options) {
737
+ if (!input) return input;
738
+ const opts = Object.assign({}, options);
739
+ this.checkBrowserFileWrite(opts.outputFile);
740
+ const wasm2 = getLegacyWasm();
741
+ const inStr = this.maybeReadFile(input, opts.inputFormat);
742
+ const res = wasm2.unbreakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
743
+ return this.deliver(res, opts.outputFile, opts.fileOptions);
744
+ }
745
+ /**
746
+ * Convert bitmark text ↔ text AST (bpg-compatible `convertText`).
747
+ *
748
+ * Direction is auto-detected: TextAst (JSON) input generates bitmark
749
+ * text; anything else parses as bitmark text and returns the TextAst
750
+ * (plain JS object; a string when `jsonOptions.prettify` is set).
751
+ */
752
+ convertText(input, options) {
753
+ const opts = Object.assign({}, options);
754
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
755
+ this.checkBrowserFileWrite(opts.outputFile);
756
+ const wasm2 = getLegacyWasm();
757
+ const isBitmarkText = opts.textFormat === void 0 || mapTextFormat(opts.textFormat) === "bitmark++";
758
+ const textLocation = opts.textLocation ?? "body";
759
+ let inStr;
760
+ let ast;
761
+ if (typeof input === "string") {
762
+ inStr = this.maybeReadFile(input, opts.inputFormat);
763
+ ast = this.parseTextAstString(inStr);
764
+ } else {
765
+ inStr = JSON.stringify(input);
766
+ ast = Array.isArray(input) ? input : void 0;
767
+ }
768
+ if (ast !== void 0) {
769
+ const out2 = isBitmarkText ? wasm2.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm2.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
770
+ this.throwOnError(out2);
771
+ return this.deliver(out2, opts.outputFile, opts.fileOptions);
772
+ }
773
+ const out = wasm2.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
774
+ this.throwOnError(out);
775
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
776
+ const outStr = pretty ? wasm2.prettify(out, indent) : out;
777
+ if (opts.outputFile) return this.deliver(outStr, opts.outputFile, opts.fileOptions);
778
+ if (pretty) return outStr;
779
+ return JSON.parse(out);
780
+ }
781
+ /**
782
+ * Convert a text AST to plain text (bpg-compatible `textAstToPlainText`).
783
+ */
784
+ textAstToPlainText(textAst, _options) {
785
+ const wasm2 = getLegacyWasm();
786
+ const out = wasm2.convert_text(
787
+ typeof textAst === "string" ? textAst : JSON.stringify(textAst),
788
+ "astToPlainText",
789
+ "bitmark++",
790
+ "body"
791
+ );
792
+ this.throwOnError(out);
793
+ return out;
794
+ }
795
+ /**
796
+ * Extract plain text from bitmark or bitmark JSON (bpg-compatible).
797
+ */
798
+ extractPlainText(input, options) {
799
+ const inputFormat = options?.inputFormat;
800
+ const wasm2 = getLegacyWasm();
801
+ if (inputFormat === "plainText") {
802
+ return typeof input === "string" ? String(input) : "";
803
+ }
804
+ if (inputFormat === "bitmarkText") {
805
+ const ast = wasm2.convert_text(String(input), "textToAst", "bitmark++", "body");
806
+ const out2 = wasm2.convert_text(ast, "astToPlainText", "bitmark++", "body");
807
+ this.throwOnError(out2);
808
+ return out2;
809
+ }
810
+ if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm2.is_bitmark(input)) {
811
+ const looksJson = (() => {
812
+ try {
813
+ JSON.parse(input);
814
+ return true;
815
+ } catch {
816
+ return false;
817
+ }
818
+ })();
819
+ if (!looksJson) {
820
+ return this.extractPlainText(input, { inputFormat: "bitmarkText" });
821
+ }
822
+ }
823
+ const { source, isBitmark } = this.resolveInput(input, void 0);
824
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1);
825
+ this.throwOnError(out);
826
+ return out;
827
+ }
828
+ /** If `s` parses as a TextAst JSON array, return it. */
829
+ parseTextAstString(s) {
830
+ const t = s.trim();
831
+ if (!t.startsWith("[")) return void 0;
832
+ try {
833
+ const v = JSON.parse(t);
834
+ if (Array.isArray(v) && v.every((n) => n !== null && typeof n === "object" && "type" in n)) {
835
+ return v;
836
+ }
837
+ } catch {
838
+ }
839
+ return void 0;
840
+ }
841
+ // ------------------------------------------------------------------
842
+ // Internal helpers
843
+ // ------------------------------------------------------------------
844
+ /**
845
+ * Resolve bpg input (string | file path | JSON value | pseudo-AST) to a
846
+ * source string for the WASM core, classified per bpg's detection order:
847
+ * AST → JSON → assume bitmark (PLAN-126 F-10).
848
+ */
849
+ resolveInput(input, inputFormat) {
850
+ if (typeof input !== "string") {
851
+ const entries = this.jsonEntries(input);
852
+ return {
853
+ source: JSON.stringify(entries ? entries.map((b) => this.toWrapperEntry(b)) : input),
854
+ isBitmark: false
855
+ };
856
+ }
857
+ const inStr = this.maybeReadFile(input, inputFormat);
858
+ const wasm2 = getLegacyWasm();
859
+ if (wasm2.is_bitmark(inStr)) return { source: inStr, isBitmark: true };
860
+ try {
861
+ const parsed = JSON.parse(inStr);
862
+ const entries = this.jsonEntries(parsed);
863
+ if (entries) {
864
+ return {
865
+ source: JSON.stringify(entries.map((b) => this.toWrapperEntry(b))),
866
+ isBitmark: false
867
+ };
868
+ }
869
+ } catch {
870
+ return { source: inStr, isBitmark: true };
871
+ }
872
+ return { source: inStr, isBitmark: false };
873
+ }
874
+ /**
875
+ * Normalise the JSON shapes bpg accepts to a bits/entries array:
876
+ * wrapper array, `{ bits: [...] }` AST envelope, single `{ bit: ... }`
877
+ * wrapper, or a bare bit object (`{ type: ... }`).
878
+ */
879
+ jsonEntries(v) {
880
+ if (Array.isArray(v)) return v;
881
+ if (v !== null && typeof v === "object") {
882
+ const o = v;
883
+ if (Array.isArray(o.bits)) return o.bits;
884
+ if ("bit" in o) return [o];
885
+ if (typeof o.type === "string") return [{ bit: o }];
886
+ }
887
+ return void 0;
888
+ }
889
+ /**
890
+ * Normalise a pseudo-AST bits entry to a `{ bit, parser? }` wrapper.
891
+ * `Builder.buildBit` returns bare bit JSON (with any parser metadata
892
+ * attached under a non-enumerable symbol); parsed forward output is
893
+ * already wrapper-shaped.
894
+ */
895
+ toWrapperEntry(entry) {
896
+ if (entry !== null && typeof entry === "object" && "bit" in entry) return entry;
897
+ const wrapper = { bit: entry };
898
+ const parser = entry?.[BUILT_BIT_PARSER];
899
+ if (parser !== void 0) wrapper.parser = parser;
900
+ return wrapper;
901
+ }
902
+ /** bpg parity: read `input` as a file when it names one (Node only). */
903
+ maybeReadFile(input, inputFormat) {
904
+ if (inputFormat === "string") return input;
905
+ const io = getLegacyFileIo();
906
+ if (!io) return input;
907
+ try {
908
+ if (io.existsSync(input)) return io.readFileSync(input, "utf8");
909
+ } catch {
910
+ }
911
+ return input;
912
+ }
913
+ /** bpg parity: writing a file is impossible in the browser. */
914
+ checkBrowserFileWrite(outputFile) {
915
+ if (outputFile && !getLegacyFileIo()) {
916
+ throw new Error("Cannot write to file in browser environment");
917
+ }
918
+ }
919
+ /** Return `data`, or write it to `outputFile` (returning void), as bpg does. */
920
+ deliver(data, outputFile, fileOptions) {
921
+ if (!outputFile) return data;
922
+ const io = getLegacyFileIo();
923
+ if (!io) throw new Error("Cannot write to file in browser environment");
924
+ io.writeFile(outputFile, data, {
925
+ append: fileOptions?.append,
926
+ encoding: fileOptions?.encoding ?? "utf8"
927
+ });
928
+ }
929
+ /** The core reports failures as `error:`-prefixed strings; bpg throws. */
930
+ throwOnError(out) {
931
+ if (out.startsWith("error:")) {
932
+ throw new Error(out.slice("error:".length).trim());
933
+ }
934
+ }
935
+ };
936
+ function extractHtmlTables(html) {
937
+ const tables = [];
938
+ const lower = html.toLowerCase();
939
+ let i = 0;
940
+ for (; ; ) {
941
+ const start = lower.indexOf("<table", i);
942
+ if (start === -1) break;
943
+ let depth = 0;
944
+ let j = start;
945
+ let end = -1;
946
+ while (j < html.length) {
947
+ const open = lower.indexOf("<table", j);
948
+ const close = lower.indexOf("</table", j);
949
+ if (close === -1) break;
950
+ if (open !== -1 && open < close) {
951
+ depth++;
952
+ j = open + "<table".length;
953
+ } else {
954
+ depth--;
955
+ const closeEnd = lower.indexOf(">", close);
956
+ j = closeEnd === -1 ? html.length : closeEnd + 1;
957
+ if (depth === 0) {
958
+ end = j;
959
+ break;
960
+ }
961
+ }
962
+ }
963
+ if (end === -1) break;
964
+ tables.push(html.slice(start, end));
965
+ i = end;
966
+ }
967
+ return tables;
968
+ }
969
+ function bitmarkTextParse(text) {
970
+ const out = getLegacyWasm().convert_text(text, "textToAst", "bitmark++", "body");
971
+ if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
972
+ return JSON.parse(out);
973
+ }
974
+
975
+ // src/legacy/resource-builder.ts
976
+ var RESOURCE_SPECS = {
977
+ imageResource: { type: "image", key: "image", valueField: "src" },
978
+ imageLinkResource: { type: "image-link", key: "imageLink", valueField: "url" },
979
+ audioResource: { type: "audio", key: "audio", valueField: "src" },
980
+ audioEmbedResource: { type: "audio-embed", key: "audioEmbed", valueField: "src" },
981
+ audioLinkResource: { type: "audio-link", key: "audioLink", valueField: "url" },
982
+ videoResource: { type: "video", key: "video", valueField: "src" },
983
+ videoEmbedResource: { type: "video-embed", key: "videoEmbed", valueField: "url" },
984
+ videoLinkResource: { type: "video-link", key: "videoLink", valueField: "url" },
985
+ stillImageFilmEmbedResource: {
986
+ type: "still-image-film-embed",
987
+ key: "stillImageFilmEmbed",
988
+ valueField: "url"
989
+ },
990
+ stillImageFilmLinkResource: {
991
+ type: "still-image-film-link",
992
+ key: "stillImageFilmLink",
993
+ valueField: "url"
994
+ },
995
+ articleResource: { type: "article", key: "article", valueField: "body" },
996
+ documentResource: { type: "document", key: "document", valueField: "url" },
997
+ documentEmbedResource: { type: "document-embed", key: "documentEmbed", valueField: "url" },
998
+ documentLinkResource: { type: "document-link", key: "documentLink", valueField: "url" },
999
+ documentDownloadResource: {
1000
+ type: "document-download",
1001
+ key: "documentDownload",
1002
+ valueField: "url"
1003
+ },
1004
+ appLinkResource: { type: "app-link", key: "appLink", valueField: "url" },
1005
+ websiteLinkResource: { type: "website-link", key: "websiteLink", valueField: "url" }
1006
+ };
1007
+ function buildResource(spec) {
1008
+ return (_context, data, _typeAlias) => {
1009
+ if (!data) return void 0;
1010
+ const { value, ...rest } = data;
1011
+ const inner = { [spec.valueField]: value ?? "" };
1012
+ for (const [k, v] of Object.entries(rest)) {
1013
+ if (v !== void 0) inner[k] = v;
1014
+ }
1015
+ return { type: spec.type, [spec.key]: inner };
1016
+ };
1017
+ }
1018
+ var SPEC_BY_TYPE = Object.fromEntries(
1019
+ Object.values(RESOURCE_SPECS).map((s) => [s.type, s])
1020
+ );
1021
+ var ResourceBuilder = class {
1022
+ /**
1023
+ * Normalise existing ResourceJson wrapper(s) (bpg-compatible).
1024
+ * Unknown resource types are dropped (bpg parity: it skips invalid types).
1025
+ */
1026
+ resourceFromResourceJson(_context, resource) {
1027
+ if (!resource) return void 0;
1028
+ const single = !Array.isArray(resource);
1029
+ const list = single ? [resource] : resource;
1030
+ const nodes = [];
1031
+ for (const wrapper of list) {
1032
+ const spec = SPEC_BY_TYPE[wrapper.type];
1033
+ if (!spec) continue;
1034
+ const inner = wrapper[spec.key] ?? {};
1035
+ const { [spec.valueField]: value, ...rest } = inner;
1036
+ const built = buildResource(spec)(void 0, { value, ...rest });
1037
+ if (built) nodes.push(built);
1038
+ }
1039
+ if (nodes.length === 0) return void 0;
1040
+ return single ? nodes[0] : nodes;
1041
+ }
1042
+ /**
1043
+ * Build a resource wrapper from a bare ResourceDataJson (bpg-compatible).
1044
+ * `data` may also be a plain string (used as the url/src/body value).
1045
+ */
1046
+ resourceFromResourceDataJson(context, type, data) {
1047
+ if (!data) return void 0;
1048
+ const spec = SPEC_BY_TYPE[type];
1049
+ if (!spec) return void 0;
1050
+ const asString = typeof data === "string" ? data : void 0;
1051
+ const obj = typeof data === "object" ? data : {};
1052
+ const { url, src, body, ...rest } = obj;
1053
+ const value = url ?? src ?? body ?? asString;
1054
+ return buildResource(spec)(context, { value, ...rest });
1055
+ }
1056
+ imageResource = buildResource(RESOURCE_SPECS.imageResource);
1057
+ imageLinkResource = buildResource(RESOURCE_SPECS.imageLinkResource);
1058
+ audioResource = buildResource(RESOURCE_SPECS.audioResource);
1059
+ audioEmbedResource = buildResource(RESOURCE_SPECS.audioEmbedResource);
1060
+ audioLinkResource = buildResource(RESOURCE_SPECS.audioLinkResource);
1061
+ videoResource = buildResource(RESOURCE_SPECS.videoResource);
1062
+ videoEmbedResource = buildResource(RESOURCE_SPECS.videoEmbedResource);
1063
+ videoLinkResource = buildResource(RESOURCE_SPECS.videoLinkResource);
1064
+ stillImageFilmEmbedResource = buildResource(
1065
+ RESOURCE_SPECS.stillImageFilmEmbedResource
1066
+ );
1067
+ stillImageFilmLinkResource = buildResource(
1068
+ RESOURCE_SPECS.stillImageFilmLinkResource
1069
+ );
1070
+ articleResource = buildResource(RESOURCE_SPECS.articleResource);
1071
+ documentResource = buildResource(RESOURCE_SPECS.documentResource);
1072
+ documentEmbedResource = buildResource(RESOURCE_SPECS.documentEmbedResource);
1073
+ documentLinkResource = buildResource(RESOURCE_SPECS.documentLinkResource);
1074
+ documentDownloadResource = buildResource(
1075
+ RESOURCE_SPECS.documentDownloadResource
1076
+ );
1077
+ appLinkResource = buildResource(RESOURCE_SPECS.appLinkResource);
1078
+ websiteLinkResource = buildResource(RESOURCE_SPECS.websiteLinkResource);
1079
+ };
1080
+
1081
+ // src/legacy/options.ts
1082
+ var Input = {
1083
+ /** Input is as a string */
1084
+ string: "string",
1085
+ /** Input is as a file path */
1086
+ file: "file"
1087
+ };
1088
+ var Output = {
1089
+ /** Output bitmark string */
1090
+ bitmark: "bitmark",
1091
+ /** Output JSON as a plain JS object, or a file */
1092
+ json: "json",
1093
+ /** Output AST as a plain JS object, or a file */
1094
+ ast: "ast",
1095
+ /** Output plain text as a string, or a file */
1096
+ text: "text"
1097
+ };
1098
+ var InputFormat = {
1099
+ bitmark: "bitmark",
1100
+ bitmarkText: "bitmarkText",
1101
+ plainText: "plainText",
1102
+ html: "html"
1103
+ };
1104
+ var BitmarkVersion = {
1105
+ v2: 2,
1106
+ v3: 3
1107
+ };
1108
+ var CardSetVersion = {
1109
+ v1: 1,
1110
+ v2: 2
1111
+ };
1112
+ var BitmarkParserType = {
1113
+ peggy: "peggy"
1114
+ };
1115
+ var InfoType = {
1116
+ list: "list",
1117
+ deprecated: "deprecated",
1118
+ all: "all",
1119
+ bit: "bit"
1120
+ };
1121
+ var InfoFormat = {
1122
+ text: "text",
1123
+ json: "json",
1124
+ pojo: "pojo"
1125
+ };
1126
+ var BodyTextFormat = {
1127
+ plainText: "text",
1128
+ latex: "latex",
1129
+ json: "json",
1130
+ xml: "xml",
1131
+ bitmarkPlusPlus: "bitmark++"
1132
+ };
1133
+ var TextLocation = {
1134
+ tag: "tag",
1135
+ body: "body"
1136
+ };
1137
+
1138
+ // src/legacy/enums-extra.ts
1139
+ var TextMarkType = {
1140
+ bold: "bold",
1141
+ light: "light",
1142
+ italic: "italic",
1143
+ highlight: "highlight",
1144
+ highlightOrange: "highlightOrange",
1145
+ highlightYellow: "highlightYellow",
1146
+ highlightGreen: "highlightGreen",
1147
+ highlightBlue: "highlightBlue",
1148
+ highlightPurple: "highlightPurple",
1149
+ highlightPink: "highlightPink",
1150
+ highlightBrown: "highlightBrown",
1151
+ highlightBlack: "highlightBlack",
1152
+ highlightWhite: "highlightWhite",
1153
+ highlightGray: "highlightGray",
1154
+ strike: "strike",
1155
+ subscript: "subscript",
1156
+ superscript: "superscript",
1157
+ ins: "ins",
1158
+ del: "del",
1159
+ underline: "underline",
1160
+ doubleUnderline: "doubleUnderline",
1161
+ circle: "circle",
1162
+ languageEmRed: "languageEmRed",
1163
+ languageEmOrange: "languageEmOrange",
1164
+ languageEmYellow: "languageEmYellow",
1165
+ languageEmGreen: "languageEmGreen",
1166
+ languageEmBlue: "languageEmBlue",
1167
+ languageEmPurple: "languageEmPurple",
1168
+ languageEmPink: "languageEmPink",
1169
+ languageEmBrown: "languageEmBrown",
1170
+ languageEmBlack: "languageEmBlack",
1171
+ languageEmWhite: "languageEmWhite",
1172
+ languageEmGray: "languageEmGray",
1173
+ languageEm: "languageEm",
1174
+ userUnderline: "userUnderline",
1175
+ userDoubleUnderline: "userDoubleUnderline",
1176
+ userStrike: "userStrike",
1177
+ userCircle: "userCircle",
1178
+ userHighlight: "userHighlight",
1179
+ notranslate: "notranslate",
1180
+ link: "link",
1181
+ ref: "ref",
1182
+ xref: "xref",
1183
+ extref: "extref",
1184
+ footnote: "footnote",
1185
+ footnoteStar: "footnote*",
1186
+ symbol: "symbol",
1187
+ var: "var",
1188
+ code: "code",
1189
+ timer: "timer",
1190
+ duration: "duration",
1191
+ color: "color",
1192
+ colorPicker: "colorPicker",
1193
+ comment: "comment"
1194
+ };
1195
+ var TextNodeType = {
1196
+ text: "text",
1197
+ hardBreak: "hardBreak",
1198
+ paragraph: "paragraph",
1199
+ heading: "heading",
1200
+ section: "section",
1201
+ noBulletList: "noBulletList",
1202
+ bulletList: "bulletList",
1203
+ orderedList: "orderedList",
1204
+ orderedListRoman: "orderedListRoman",
1205
+ orderedListRomanLower: "orderedListRomanLower",
1206
+ letteredList: "letteredList",
1207
+ letteredListLower: "letteredListLower",
1208
+ taskList: "taskList",
1209
+ listItem: "listItem",
1210
+ taskItem: "taskItem",
1211
+ image: "image",
1212
+ imageInline: "imageInline",
1213
+ codeBlock: "codeBlock",
1214
+ latex: "latex",
1215
+ gap: "gap",
1216
+ select: "select",
1217
+ highlight: "highlight",
1218
+ mark: "mark"
1219
+ };
1220
+ function bitNameToKey(name) {
1221
+ return name.replace(/-([a-z0-9])/gu, (_, c) => c.toUpperCase());
1222
+ }
1223
+ var bitTypeCache;
1224
+ function loadBitTypes() {
1225
+ if (!bitTypeCache) {
1226
+ const wasm2 = getLegacyWasm();
1227
+ const all = JSON.parse(wasm2.info("all", "json", "", false, 2));
1228
+ const map = { _standard: "_standard" };
1229
+ for (const { name } of all) {
1230
+ map[bitNameToKey(name)] = name;
1231
+ }
1232
+ bitTypeCache = map;
1233
+ }
1234
+ return bitTypeCache;
1235
+ }
1236
+ var BitType = new Proxy(
1237
+ {},
1238
+ {
1239
+ get: (_t, prop) => typeof prop === "string" ? loadBitTypes()[prop] : void 0,
1240
+ has: (_t, prop) => typeof prop === "string" && prop in loadBitTypes(),
1241
+ ownKeys: () => Reflect.ownKeys(loadBitTypes()),
1242
+ getOwnPropertyDescriptor: (_t, prop) => typeof prop === "string" && prop in loadBitTypes() ? { value: loadBitTypes()[prop], enumerable: true, configurable: true, writable: false } : void 0
1243
+ }
1244
+ );
1245
+ function unsupportedEnum(name, reason) {
1246
+ return new Proxy(
1247
+ {},
1248
+ {
1249
+ get: (_t, prop) => {
1250
+ if (prop === Symbol.toPrimitive || prop === "toString" || prop === Symbol.toStringTag) {
1251
+ return () => `[unsupported ${name}]`;
1252
+ }
1253
+ return unsupportedMember(name, reason);
1254
+ },
1255
+ has: () => unsupportedMember(name, reason),
1256
+ ownKeys: () => unsupportedMember(name, reason)
1257
+ }
1258
+ );
1259
+ }
1260
+ var NodeType = unsupportedEnum(
1261
+ "NodeType",
1262
+ "it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"
1263
+ );
1264
+ var BoundingBoxIndex = unsupportedEnum(
1265
+ "BoundingBoxIndex",
1266
+ "bpg-internal bounding-box utility"
1267
+ );
1268
+
1269
+ // src/legacy/stubs.ts
1270
+ function stubClass(name, reason) {
1271
+ return class {
1272
+ constructor() {
1273
+ unsupportedMember(name, reason);
1274
+ }
1275
+ };
1276
+ }
1277
+ var WALKER_REASON = "the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave";
1278
+ var INTERNAL_REASON = "internal class of bpg's TS implementation";
1279
+ var Ast = stubClass("Ast", WALKER_REASON);
1280
+ var BitmarkGenerator = stubClass("BitmarkGenerator", INTERNAL_REASON);
1281
+ var BitmarkStringGenerator = stubClass("BitmarkStringGenerator", INTERNAL_REASON);
1282
+ var BitmarkFileGenerator = stubClass("BitmarkFileGenerator", INTERNAL_REASON);
1283
+ var JsonGenerator = stubClass("JsonGenerator", INTERNAL_REASON);
1284
+ var JsonStringGenerator = stubClass("JsonStringGenerator", INTERNAL_REASON);
1285
+ var JsonFileGenerator = stubClass("JsonFileGenerator", INTERNAL_REASON);
1286
+ var HtmlTableGenerator = stubClass("HtmlTableGenerator", INTERNAL_REASON);
1287
+ var HtmlTableParser = stubClass("HtmlTableParser", INTERNAL_REASON);
1288
+ var BitmarkParser = stubClass("BitmarkParser", INTERNAL_REASON);
1289
+ var JsonParser = stubClass("JsonParser", INTERNAL_REASON);
1290
+ var StringWriter = stubClass("StringWriter", INTERNAL_REASON);
1291
+ var FileWriter = stubClass("FileWriter", INTERNAL_REASON);
1292
+ var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
1293
+
207
1294
  // src/index.ts
208
1295
  var require2 = createRequire(import.meta.url);
209
1296
  var wasm = require2("../wasm/bitmark_wasm.js");
1297
+ initLegacyNode(wasm);
210
1298
  function version() {
211
1299
  return PACKAGE_INFO.version;
212
1300
  }
@@ -228,15 +1316,16 @@ function convert(input, options = {}) {
228
1316
  );
229
1317
  }
230
1318
  function optimize(input, options = {}) {
231
- return wasm.optimize(input, options.pretty ?? false, options.indent ?? 2);
1319
+ return wasm.optimize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
232
1320
  }
233
1321
  function fullize(input, options = {}) {
234
- return wasm.fullize(input, options.pretty ?? false, options.indent ?? 2);
1322
+ return wasm.fullize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
235
1323
  }
236
1324
  var expand = fullize;
237
1325
  function canonicalize(input, options = {}) {
238
1326
  return wasm.canonicalize(
239
1327
  input,
1328
+ options.inputFormat ?? "auto",
240
1329
  options.mode ?? "optimized",
241
1330
  options.pretty ?? false,
242
1331
  options.indent ?? 2,
@@ -300,6 +1389,7 @@ export {
300
1389
  fullize,
301
1390
  generate,
302
1391
  info,
1392
+ legacy_exports as legacy,
303
1393
  lex,
304
1394
  optimize,
305
1395
  parse,