@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.
@@ -3,6 +3,7 @@ var __defProp = Object.defineProperty;
3
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
7
  var __export = (target, all) => {
7
8
  for (var name in all)
8
9
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -16,6 +17,7 @@ var __copyProps = (to, from, except, desc) => {
16
17
  return to;
17
18
  };
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
19
21
 
20
22
  // src/browser/index.ts
21
23
  var index_exports = {};
@@ -29,6 +31,7 @@ __export(index_exports, {
29
31
  info: () => info2,
30
32
  init: () => init,
31
33
  initSync: () => initSync,
34
+ legacy: () => legacy_exports,
32
35
  lex: () => lex2,
33
36
  optimize: () => optimize2,
34
37
  parse: () => parse2,
@@ -50,6 +53,7 @@ __export(bitmark_wasm_exports, {
50
53
  breakscape_text: () => breakscape_text,
51
54
  canonicalize: () => canonicalize,
52
55
  convert: () => convert,
56
+ convert_text: () => convert_text,
53
57
  count_bits: () => count_bits,
54
58
  default: () => bitmark_wasm_default,
55
59
  fullize: () => fullize,
@@ -254,6 +258,30 @@ function prettify(json, indent) {
254
258
  wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
255
259
  }
256
260
  }
261
+ function convert_text(input, direction, format, location) {
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(direction, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
269
+ const len1 = WASM_VECTOR_LEN;
270
+ const ptr2 = passStringToWasm0(format, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
271
+ const len2 = WASM_VECTOR_LEN;
272
+ const ptr3 = passStringToWasm0(location, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
273
+ const len3 = WASM_VECTOR_LEN;
274
+ wasm.convert_text(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
275
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
276
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
277
+ deferred5_0 = r0;
278
+ deferred5_1 = r1;
279
+ return getStringFromWasm0(r0, r1);
280
+ } finally {
281
+ wasm.__wbindgen_add_to_stack_pointer(16);
282
+ wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);
283
+ }
284
+ }
257
285
  function transform(input, input_format_sel, output_format_sel, mode, patch_json, pretty, indent, spaces_around_values) {
258
286
  let deferred6_0;
259
287
  let deferred6_1;
@@ -326,60 +354,66 @@ function convert(input, input_format_sel, output_format_sel, mode, pretty, inden
326
354
  wasm.__wbindgen_export_2(deferred5_0, deferred5_1, 1);
327
355
  }
328
356
  }
329
- function optimize(input, pretty, indent) {
330
- let deferred2_0;
331
- let deferred2_1;
357
+ function optimize(input, input_format_sel, pretty, indent) {
358
+ let deferred3_0;
359
+ let deferred3_1;
332
360
  try {
333
361
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
334
362
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
335
363
  const len0 = WASM_VECTOR_LEN;
336
- wasm.optimize(retptr, ptr0, len0, pretty, indent);
364
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
365
+ const len1 = WASM_VECTOR_LEN;
366
+ wasm.optimize(retptr, ptr0, len0, ptr1, len1, pretty, indent);
337
367
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
338
368
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
339
- deferred2_0 = r0;
340
- deferred2_1 = r1;
369
+ deferred3_0 = r0;
370
+ deferred3_1 = r1;
341
371
  return getStringFromWasm0(r0, r1);
342
372
  } finally {
343
373
  wasm.__wbindgen_add_to_stack_pointer(16);
344
- wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
374
+ wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
345
375
  }
346
376
  }
347
- function fullize(input, pretty, indent) {
348
- let deferred2_0;
349
- let deferred2_1;
377
+ function fullize(input, input_format_sel, pretty, indent) {
378
+ let deferred3_0;
379
+ let deferred3_1;
350
380
  try {
351
381
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
352
382
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
353
383
  const len0 = WASM_VECTOR_LEN;
354
- wasm.fullize(retptr, ptr0, len0, pretty, indent);
384
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
385
+ const len1 = WASM_VECTOR_LEN;
386
+ wasm.fullize(retptr, ptr0, len0, ptr1, len1, pretty, indent);
355
387
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
356
388
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
357
- deferred2_0 = r0;
358
- deferred2_1 = r1;
389
+ deferred3_0 = r0;
390
+ deferred3_1 = r1;
359
391
  return getStringFromWasm0(r0, r1);
360
392
  } finally {
361
393
  wasm.__wbindgen_add_to_stack_pointer(16);
362
- wasm.__wbindgen_export_2(deferred2_0, deferred2_1, 1);
394
+ wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
363
395
  }
364
396
  }
365
- function canonicalize(input, mode, pretty, indent, spaces_around_values) {
366
- let deferred3_0;
367
- let deferred3_1;
397
+ function canonicalize(input, input_format_sel, mode, pretty, indent, spaces_around_values) {
398
+ let deferred4_0;
399
+ let deferred4_1;
368
400
  try {
369
401
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
370
402
  const ptr0 = passStringToWasm0(input, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
371
403
  const len0 = WASM_VECTOR_LEN;
372
- const ptr1 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
404
+ const ptr1 = passStringToWasm0(input_format_sel, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
373
405
  const len1 = WASM_VECTOR_LEN;
374
- wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, pretty, indent, spaces_around_values);
406
+ const ptr2 = passStringToWasm0(mode, wasm.__wbindgen_export_0, wasm.__wbindgen_export_1);
407
+ const len2 = WASM_VECTOR_LEN;
408
+ wasm.canonicalize(retptr, ptr0, len0, ptr1, len1, ptr2, len2, pretty, indent, spaces_around_values);
375
409
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
376
410
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
377
- deferred3_0 = r0;
378
- deferred3_1 = r1;
411
+ deferred4_0 = r0;
412
+ deferred4_1 = r1;
379
413
  return getStringFromWasm0(r0, r1);
380
414
  } finally {
381
415
  wasm.__wbindgen_add_to_stack_pointer(16);
382
- wasm.__wbindgen_export_2(deferred3_0, deferred3_1, 1);
416
+ wasm.__wbindgen_export_2(deferred4_0, deferred4_1, 1);
383
417
  }
384
418
  }
385
419
  function count_bits(input) {
@@ -504,7 +538,7 @@ var bitmark_wasm_default = __wbg_init;
504
538
  // src/generated/package_info.ts
505
539
  var PACKAGE_INFO = {
506
540
  "name": "@gmb/bitmark-parser",
507
- "version": "6.1.2",
541
+ "version": "6.1.4",
508
542
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
509
543
  "license": "ISC",
510
544
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -691,7 +725,1068 @@ function runJobsParallel(jobs, workers) {
691
725
  });
692
726
  }
693
727
 
728
+ // src/legacy/runtime.ts
729
+ var wasmModule;
730
+ function setLegacyWasm(wasm2) {
731
+ wasmModule = wasm2;
732
+ }
733
+ function getLegacyWasm() {
734
+ if (!wasmModule) {
735
+ throw new Error(
736
+ "legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)"
737
+ );
738
+ }
739
+ return wasmModule;
740
+ }
741
+ var fileIo;
742
+ function getLegacyFileIo() {
743
+ return fileIo;
744
+ }
745
+
746
+ // src/legacy/index.ts
747
+ var legacy_exports = {};
748
+ __export(legacy_exports, {
749
+ Ast: () => Ast,
750
+ BitType: () => BitType,
751
+ BitmarkFileGenerator: () => BitmarkFileGenerator,
752
+ BitmarkGenerator: () => BitmarkGenerator,
753
+ BitmarkParser: () => BitmarkParser,
754
+ BitmarkParserGenerator: () => BitmarkParserGenerator,
755
+ BitmarkParserType: () => BitmarkParserType,
756
+ BitmarkStringGenerator: () => BitmarkStringGenerator,
757
+ BitmarkVersion: () => BitmarkVersion,
758
+ BodyTextFormat: () => BodyTextFormat,
759
+ BoundingBoxIndex: () => BoundingBoxIndex,
760
+ Builder: () => Builder,
761
+ CardSetVersion: () => CardSetVersion,
762
+ FileWriter: () => FileWriter,
763
+ HtmlTableGenerator: () => HtmlTableGenerator,
764
+ HtmlTableParser: () => HtmlTableParser,
765
+ InfoFormat: () => InfoFormat,
766
+ InfoType: () => InfoType,
767
+ Input: () => Input,
768
+ InputFormat: () => InputFormat,
769
+ JsonFileGenerator: () => JsonFileGenerator,
770
+ JsonGenerator: () => JsonGenerator,
771
+ JsonParser: () => JsonParser,
772
+ JsonStringGenerator: () => JsonStringGenerator,
773
+ LegacyUnsupportedError: () => LegacyUnsupportedError,
774
+ NodeType: () => NodeType,
775
+ Output: () => Output,
776
+ ResourceBuilder: () => ResourceBuilder,
777
+ StreamWriter: () => StreamWriter,
778
+ StringWriter: () => StringWriter,
779
+ TextLocation: () => TextLocation,
780
+ TextMarkType: () => TextMarkType,
781
+ TextNodeType: () => TextNodeType,
782
+ bitmarkTextParse: () => bitmarkTextParse,
783
+ isPseudoAst: () => isPseudoAst
784
+ });
785
+
786
+ // src/legacy/errors.ts
787
+ var LegacyUnsupportedError = class extends Error {
788
+ constructor(message) {
789
+ super(message);
790
+ this.name = "LegacyUnsupportedError";
791
+ }
792
+ };
793
+ function unsupportedMember(member, reason) {
794
+ throw new LegacyUnsupportedError(
795
+ `'${member}' is not supported by the @gmb/bitmark-parser legacy API` + (reason ? `: ${reason}` : "")
796
+ );
797
+ }
798
+ function unsupportedOption(option, reason) {
799
+ throw new LegacyUnsupportedError(
800
+ `Option '${option}' is not supported by the @gmb/bitmark-parser legacy API` + (reason ? `: ${reason}` : "")
801
+ );
802
+ }
803
+
804
+ // src/legacy/translate.ts
805
+ var V3_ONLY = "bitmark v2 output is not supported (this parser is bitmark v3 only)";
806
+ function validateVersionOptions(opts) {
807
+ if (opts.bitmarkVersion === 2) unsupportedOption("bitmarkVersion: 2", V3_ONLY);
808
+ }
809
+ function validateBitmarkOptions(o) {
810
+ if (o.explicitTextFormat) unsupportedOption("bitmarkOptions.explicitTextFormat");
811
+ if (o.prettifyJson !== void 0 && o.prettifyJson !== false) {
812
+ unsupportedOption("bitmarkOptions.prettifyJson", "embedded-JSON body prettification is not supported");
813
+ }
814
+ if (o.cardSetVersion === 1) unsupportedOption("bitmarkOptions.cardSetVersion: 1", V3_ONLY);
815
+ if (o.debugGenerationInline) unsupportedOption("bitmarkOptions.debugGenerationInline");
816
+ if (o.noBreakscaping) unsupportedOption("bitmarkOptions.noBreakscaping");
817
+ }
818
+ function validateJsonOptions(o) {
819
+ if (o.textAsPlainText) unsupportedOption("jsonOptions.textAsPlainText", V3_ONLY);
820
+ if (o.excludeUnknownProperties) unsupportedOption("jsonOptions.excludeUnknownProperties");
821
+ if (o.debugGenerationInline) unsupportedOption("jsonOptions.debugGenerationInline");
822
+ }
823
+ function prettyIndent(prettify2) {
824
+ if (prettify2 === true) return { pretty: true, indent: 2 };
825
+ if (typeof prettify2 === "number" && prettify2 > 0) return { pretty: true, indent: prettify2 };
826
+ return { pretty: false, indent: 2 };
827
+ }
828
+ function spacesAround(v) {
829
+ if (v === void 0 || v === true) return 1;
830
+ if (v === false) return 0;
831
+ return Math.max(0, Math.min(10, v));
832
+ }
833
+ function mapTextFormat(f) {
834
+ switch (f) {
835
+ case "text":
836
+ case "latex":
837
+ case "json":
838
+ case "xml":
839
+ return "plainText";
840
+ default:
841
+ return "bitmark++";
842
+ }
843
+ }
844
+
845
+ // src/legacy/pseudo-ast.ts
846
+ var PSEUDO_AST_MARKER = /* @__PURE__ */ Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");
847
+ function makePseudoAst(bits) {
848
+ const ast = { bits };
849
+ Object.defineProperty(ast, PSEUDO_AST_MARKER, { value: true, enumerable: false });
850
+ return ast;
851
+ }
852
+ function isPseudoAst(v) {
853
+ return v !== null && typeof v === "object" && (PSEUDO_AST_MARKER in v || Array.isArray(v.bits));
854
+ }
855
+
856
+ // src/legacy/builder.ts
857
+ var BUILT_BIT_PARSER = /* @__PURE__ */ Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser");
858
+ var DATA_KEY_TO_JSON_KEY = {
859
+ bitType: "type",
860
+ textFormat: "format",
861
+ flashcards: "cards",
862
+ markConfig: "marks"
863
+ };
864
+ var DEPRECATED_TEXT_FORMATS = {
865
+ "bitmark--": "bitmark++",
866
+ "bitmark+": "bitmark++"
867
+ };
868
+ var TAG_TEXT_KEYS = [
869
+ "title",
870
+ "subtitle",
871
+ "item",
872
+ "lead",
873
+ "pageNumber",
874
+ "marginNumber",
875
+ "hint",
876
+ "instruction",
877
+ "caption"
878
+ ];
879
+ var Builder = class {
880
+ /**
881
+ * Build bitmark AST envelope (bpg-compatible `buildBitmark`).
882
+ */
883
+ buildBitmark(data) {
884
+ const ast = makePseudoAst(data.bits ?? []);
885
+ if (data.errors !== void 0) {
886
+ ast.errors = data.errors;
887
+ }
888
+ return ast;
889
+ }
890
+ /**
891
+ * Build a bit (bpg-compatible `buildBit`).
892
+ *
893
+ * Accepts the full bpg data shape (flat, ~250 optional fields, values in
894
+ * the JSON model types). Returns the normalized bit JSON. Throws
895
+ * `No config found for bit: X` for unknown bit types, as bpg does.
896
+ *
897
+ * NOTE (documented divergences from bpg):
898
+ * - the return value is bit JSON, not bpg's internal AST node model;
899
+ * - `resourceType` (an inference hint in bpg) is not carried into the
900
+ * JSON — the attached `resource` object is authoritative;
901
+ * - more than one entry in `resources` passes through under a
902
+ * `resources` key (kept visible, not silently dropped) — the canonical
903
+ * single attachment is `resource`.
904
+ */
905
+ buildBit(data, _options) {
906
+ const wasm2 = getLegacyWasm();
907
+ const src = { ...data };
908
+ const bitType = src.bitType;
909
+ this.assertKnownBitType(bitType);
910
+ const bit = {};
911
+ bit.type = bitType;
912
+ if (src.isCommented) {
913
+ bit.type = "_comment";
914
+ bit.originalType = bitType;
915
+ }
916
+ delete src.bitType;
917
+ delete src.isCommented;
918
+ const textFormat = src.textFormat;
919
+ if (textFormat !== void 0) {
920
+ bit.format = DEPRECATED_TEXT_FORMATS[textFormat] ?? textFormat;
921
+ delete src.textFormat;
922
+ }
923
+ delete src.resourceType;
924
+ const body = src.body;
925
+ if (body !== void 0 && body !== null && typeof body === "object" && "body" in body) {
926
+ bit.body = body.body;
927
+ delete src.body;
928
+ }
929
+ if (src.example !== void 0) {
930
+ bit.isExample = true;
931
+ bit.example = src.example;
932
+ delete src.example;
933
+ delete src.__isDefaultExample;
934
+ } else if (src.__isDefaultExample) {
935
+ bit.isExample = true;
936
+ delete src.__isDefaultExample;
937
+ }
938
+ const resources = src.resources;
939
+ if (resources !== void 0) {
940
+ if (Array.isArray(resources)) {
941
+ if (resources.length === 1) bit.resource = resources[0];
942
+ else if (resources.length > 1) bit.resources = resources;
943
+ } else {
944
+ bit.resource = resources;
945
+ }
946
+ delete src.resources;
947
+ }
948
+ const parser = src.parser;
949
+ delete src.parser;
950
+ const extraProperties = src.extraProperties;
951
+ delete src.extraProperties;
952
+ for (const [key, value] of Object.entries(src)) {
953
+ if (value === void 0) continue;
954
+ bit[DATA_KEY_TO_JSON_KEY[key] ?? key] = value;
955
+ }
956
+ if (extraProperties) {
957
+ for (const [key, value] of Object.entries(extraProperties)) {
958
+ if (!(key in bit)) bit[key] = value;
959
+ }
960
+ }
961
+ this.parseStringTexts(bit);
962
+ const out = wasm2.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1);
963
+ if (out.startsWith("error:")) {
964
+ throw new Error(out.slice("error:".length).trim());
965
+ }
966
+ const entries = JSON.parse(out);
967
+ const built = entries[0]?.bit ?? bit;
968
+ for (const [key, value] of Object.entries(bit)) {
969
+ if (key in built) continue;
970
+ if (value === false || value === "" || value === null || Array.isArray(value) && value.length === 0) {
971
+ continue;
972
+ }
973
+ built[key] = value;
974
+ }
975
+ if (parser !== void 0) {
976
+ Object.defineProperty(built, BUILT_BIT_PARSER, { value: parser, enumerable: false });
977
+ }
978
+ return built;
979
+ }
980
+ /**
981
+ * Build a highlight body bit (bpg-compatible `buildHighlight`).
982
+ * Shapes the HighlightJson body-bit; unset optionals are omitted.
983
+ */
984
+ buildHighlight(_context, data) {
985
+ if (!data) return void 0;
986
+ const src = { ...data };
987
+ const attrs = src.attrs;
988
+ if (attrs) Object.assign(src, attrs);
989
+ const texts = Array.isArray(src.texts) ? src.texts.filter((t) => t != null).map((t) => ({
990
+ text: t.text ?? "",
991
+ isCorrect: t.isCorrect ?? false,
992
+ isHighlighted: t.isHighlighted ?? false,
993
+ ...stripUndefined(t, ["text", "isCorrect", "isHighlighted"])
994
+ })) : [];
995
+ const node = {
996
+ type: "highlight",
997
+ texts,
998
+ prefix: src.prefix ?? "",
999
+ postfix: src.postfix ?? "",
1000
+ ...stripUndefined(src, ["type", "texts", "prefix", "postfix", "attrs"]),
1001
+ attrs: {}
1002
+ };
1003
+ return node;
1004
+ }
1005
+ /**
1006
+ * bpg's builder parses string-valued JsonText fields as bitmark text
1007
+ * (inline marks become TextAst marks); the composer would otherwise treat
1008
+ * them as literal text. Converts top-level JsonText fields in place.
1009
+ * Nested (card-content) strings are left literal — documented divergence.
1010
+ */
1011
+ parseStringTexts(bit) {
1012
+ const wasm2 = getLegacyWasm();
1013
+ const toAst = (s, location) => {
1014
+ if (s === "") return s;
1015
+ const out = wasm2.convert_text(s, "textToAst", "bitmark++", location);
1016
+ try {
1017
+ return JSON.parse(out);
1018
+ } catch {
1019
+ return s;
1020
+ }
1021
+ };
1022
+ const format = bit.format;
1023
+ const bitmarkBody = format === void 0 || format === "bitmark++" || format === "bitmark+";
1024
+ if (typeof bit.body === "string" && bitmarkBody) {
1025
+ bit.body = toAst(bit.body, "body");
1026
+ }
1027
+ for (const key of TAG_TEXT_KEYS) {
1028
+ const v = bit[key];
1029
+ if (typeof v === "string") bit[key] = toAst(v, "tag");
1030
+ }
1031
+ }
1032
+ /** Throw bpg's exact unknown-bit-type error (`Config.getBitConfig` parity). */
1033
+ assertKnownBitType(bitType) {
1034
+ const wasm2 = getLegacyWasm();
1035
+ let known = false;
1036
+ if (bitType !== void 0) {
1037
+ try {
1038
+ const info3 = JSON.parse(wasm2.info("bit", "json", bitType, false, 2));
1039
+ known = info3.error === void 0;
1040
+ } catch {
1041
+ known = false;
1042
+ }
1043
+ }
1044
+ if (!known) {
1045
+ throw new Error(`No config found for bit: ${bitType}`);
1046
+ }
1047
+ }
1048
+ };
1049
+ function stripUndefined(src, exclude) {
1050
+ const out = {};
1051
+ for (const [k, v] of Object.entries(src)) {
1052
+ if (v !== void 0 && !exclude.includes(k)) out[k] = v;
1053
+ }
1054
+ return out;
1055
+ }
1056
+
1057
+ // src/legacy/bpg-class.ts
1058
+ var BitmarkParserGenerator = class {
1059
+ /**
1060
+ * Get the version of the library.
1061
+ *
1062
+ * Reports the @gmb/bitmark-parser version (not a bpg version string).
1063
+ */
1064
+ version() {
1065
+ return PACKAGE_INFO.version;
1066
+ }
1067
+ /**
1068
+ * Convert bitmark from bitmark to JSON, or JSON to bitmark (bpg-compatible).
1069
+ *
1070
+ * Input detection order matches bpg: AST → JSON → assume bitmark.
1071
+ * Default output: bitmark input → json; json/ast input → bitmark.
1072
+ */
1073
+ convert(input, options) {
1074
+ const opts = Object.assign({}, options);
1075
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
1076
+ const bitmarkOptions = Object.assign({}, opts.bitmarkOptions);
1077
+ validateVersionOptions(opts);
1078
+ validateBitmarkOptions(bitmarkOptions);
1079
+ validateJsonOptions(jsonOptions);
1080
+ this.checkBrowserFileWrite(opts.outputFile);
1081
+ const wasm2 = getLegacyWasm();
1082
+ const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
1083
+ const outputFormat = opts.outputFormat ?? (isBitmark ? "json" : "bitmark");
1084
+ const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
1085
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
1086
+ const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
1087
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", pretty, indent, spaces);
1088
+ this.throwOnError(out);
1089
+ if (outputFormat === "bitmark" || outputFormat === "text") {
1090
+ return this.deliver(out, opts.outputFile, opts.fileOptions);
1091
+ }
1092
+ if (outputFormat === "json") {
1093
+ if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
1094
+ if (pretty || jsonOptions.stringify) return out;
1095
+ return JSON.parse(out);
1096
+ }
1097
+ const ast = makePseudoAst(JSON.parse(out));
1098
+ if (opts.outputFile) {
1099
+ return this.deliver(JSON.stringify(ast), opts.outputFile, opts.fileOptions);
1100
+ }
1101
+ return ast;
1102
+ }
1103
+ /**
1104
+ * Upgrade (prettify / canonicalize) bitmark or JSON to the latest version
1105
+ * of itself (bpg-compatible `upgrade`).
1106
+ */
1107
+ upgrade(input, options) {
1108
+ const opts = Object.assign({}, options);
1109
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
1110
+ const bitmarkOptions = Object.assign({}, opts.bitmarkOptions);
1111
+ validateVersionOptions(opts);
1112
+ validateBitmarkOptions(bitmarkOptions);
1113
+ validateJsonOptions(jsonOptions);
1114
+ this.checkBrowserFileWrite(opts.outputFile);
1115
+ const wasm2 = getLegacyWasm();
1116
+ const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
1117
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
1118
+ const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
1119
+ const out = wasm2.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
1120
+ this.throwOnError(out);
1121
+ if (isBitmark) return this.deliver(out, opts.outputFile, opts.fileOptions);
1122
+ if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
1123
+ if (pretty || jsonOptions.stringify) return out;
1124
+ return JSON.parse(out);
1125
+ }
1126
+ /**
1127
+ * Get information about the bitmark language (bpg-compatible `info`).
1128
+ */
1129
+ info(options) {
1130
+ const opts = Object.assign({}, options);
1131
+ const wasm2 = getLegacyWasm();
1132
+ const type = opts.type ?? "list";
1133
+ const format = opts.outputFormat ?? "text";
1134
+ const { pretty, indent } = prettyIndent(opts.prettify);
1135
+ const coreFormat = format === "pojo" ? "json" : format;
1136
+ const out = wasm2.info(type, coreFormat, opts.bit ?? "", pretty, indent);
1137
+ this.throwOnError(out);
1138
+ if (format === "pojo") return JSON.parse(out);
1139
+ return out;
1140
+ }
1141
+ /** Not supported: bpg-internal development tool. */
1142
+ generateConfig(_options) {
1143
+ unsupportedMember("BitmarkParserGenerator.generateConfig", "bpg-internal development tool");
1144
+ }
1145
+ /**
1146
+ * Convert between HTML tables and bitmark tables (bpg-compatible
1147
+ * `convertHtmlTable`).
1148
+ *
1149
+ * Backed by the core's schema-driven html mapping: HTML input has each
1150
+ * `<table>` wrapped in the core's `<bitmark-bit>` envelope and parsed;
1151
+ * bits input is emitted as html and the `<table>` fragments extracted
1152
+ * (the envelope stripped). The markup *inside* `<table>` follows this
1153
+ * parser's html mapping, which may differ from bpg's in detail.
1154
+ */
1155
+ convertHtmlTable(input, options) {
1156
+ const opts = Object.assign({}, options);
1157
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
1158
+ const bitmarkOptions = Object.assign({}, opts.bitmarkOptions);
1159
+ validateBitmarkOptions(bitmarkOptions);
1160
+ validateJsonOptions(jsonOptions);
1161
+ if (opts.keepUnknownTags) unsupportedOption("keepUnknownTags");
1162
+ if (opts.noBreakscaping) unsupportedOption("noBreakscaping");
1163
+ this.checkBrowserFileWrite(opts.outputFile);
1164
+ const wasm2 = getLegacyWasm();
1165
+ const inStr = typeof input === "string" ? this.maybeReadFile(input, void 0) : "";
1166
+ const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
1167
+ if (!isHtmlInput) {
1168
+ const { source, isBitmark } = this.resolveInput(input, void 0);
1169
+ const out2 = wasm2.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1);
1170
+ this.throwOnError(out2);
1171
+ return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
1172
+ }
1173
+ const bitType = opts.tableFormat === "table" ? "table" : "table-extended";
1174
+ const wrapped = extractHtmlTables(inStr).map((t) => `<bitmark-bit data-type="${bitType}" data-format="bitmark++">${t}</bitmark-bit>`).join("");
1175
+ const outputFormat = opts.outputFormat ?? "bitmark";
1176
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
1177
+ const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
1178
+ if (outputFormat === "html") {
1179
+ const out2 = wasm2.convert(wrapped, "html", "html", "optimized", false, 2, 1);
1180
+ this.throwOnError(out2);
1181
+ return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
1182
+ }
1183
+ const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
1184
+ const out = wasm2.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces);
1185
+ this.throwOnError(out);
1186
+ if (outputFormat === "bitmark" || outputFormat === "text") {
1187
+ return this.deliver(out, opts.outputFile, opts.fileOptions);
1188
+ }
1189
+ if (outputFormat === "json") {
1190
+ if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
1191
+ if (pretty || jsonOptions.stringify) return out;
1192
+ return JSON.parse(out);
1193
+ }
1194
+ const ast = makePseudoAst(JSON.parse(out));
1195
+ if (opts.outputFile) return this.deliver(JSON.stringify(ast), opts.outputFile, opts.fileOptions);
1196
+ return ast;
1197
+ }
1198
+ /**
1199
+ * Create a bit-JSON pseudo-AST from bitmark or JSON input (PLAN-126 §3.1).
1200
+ *
1201
+ * NOTE: the returned structure is the bit JSON (wrapper entries), not
1202
+ * bpg's internal TS AST node model. It round-trips through `convert` but
1203
+ * is not walkable with bpg's `Ast`/`NodeType`.
1204
+ */
1205
+ createAst(input, options) {
1206
+ const opts = Object.assign({}, options);
1207
+ const wasm2 = getLegacyWasm();
1208
+ const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
1209
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1);
1210
+ this.throwOnError(out);
1211
+ return makePseudoAst(JSON.parse(out));
1212
+ }
1213
+ /**
1214
+ * Breakscape text (bpg-compatible `breakscapeText`).
1215
+ */
1216
+ breakscapeText(input, options) {
1217
+ if (!input) return input;
1218
+ const opts = Object.assign({}, options);
1219
+ this.checkBrowserFileWrite(opts.outputFile);
1220
+ const wasm2 = getLegacyWasm();
1221
+ const inStr = this.maybeReadFile(input, opts.inputFormat);
1222
+ const res = wasm2.breakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
1223
+ return this.deliver(res, opts.outputFile, opts.fileOptions);
1224
+ }
1225
+ /**
1226
+ * Unbreakscape text (bpg-compatible `unbreakscapeText`).
1227
+ */
1228
+ unbreakscapeText(input, options) {
1229
+ if (!input) return input;
1230
+ const opts = Object.assign({}, options);
1231
+ this.checkBrowserFileWrite(opts.outputFile);
1232
+ const wasm2 = getLegacyWasm();
1233
+ const inStr = this.maybeReadFile(input, opts.inputFormat);
1234
+ const res = wasm2.unbreakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
1235
+ return this.deliver(res, opts.outputFile, opts.fileOptions);
1236
+ }
1237
+ /**
1238
+ * Convert bitmark text ↔ text AST (bpg-compatible `convertText`).
1239
+ *
1240
+ * Direction is auto-detected: TextAst (JSON) input generates bitmark
1241
+ * text; anything else parses as bitmark text and returns the TextAst
1242
+ * (plain JS object; a string when `jsonOptions.prettify` is set).
1243
+ */
1244
+ convertText(input, options) {
1245
+ const opts = Object.assign({}, options);
1246
+ const jsonOptions = Object.assign({}, opts.jsonOptions);
1247
+ this.checkBrowserFileWrite(opts.outputFile);
1248
+ const wasm2 = getLegacyWasm();
1249
+ const isBitmarkText = opts.textFormat === void 0 || mapTextFormat(opts.textFormat) === "bitmark++";
1250
+ const textLocation = opts.textLocation ?? "body";
1251
+ let inStr;
1252
+ let ast;
1253
+ if (typeof input === "string") {
1254
+ inStr = this.maybeReadFile(input, opts.inputFormat);
1255
+ ast = this.parseTextAstString(inStr);
1256
+ } else {
1257
+ inStr = JSON.stringify(input);
1258
+ ast = Array.isArray(input) ? input : void 0;
1259
+ }
1260
+ if (ast !== void 0) {
1261
+ const out2 = isBitmarkText ? wasm2.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm2.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
1262
+ this.throwOnError(out2);
1263
+ return this.deliver(out2, opts.outputFile, opts.fileOptions);
1264
+ }
1265
+ const out = wasm2.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
1266
+ this.throwOnError(out);
1267
+ const { pretty, indent } = prettyIndent(jsonOptions.prettify);
1268
+ const outStr = pretty ? wasm2.prettify(out, indent) : out;
1269
+ if (opts.outputFile) return this.deliver(outStr, opts.outputFile, opts.fileOptions);
1270
+ if (pretty) return outStr;
1271
+ return JSON.parse(out);
1272
+ }
1273
+ /**
1274
+ * Convert a text AST to plain text (bpg-compatible `textAstToPlainText`).
1275
+ */
1276
+ textAstToPlainText(textAst, _options) {
1277
+ const wasm2 = getLegacyWasm();
1278
+ const out = wasm2.convert_text(
1279
+ typeof textAst === "string" ? textAst : JSON.stringify(textAst),
1280
+ "astToPlainText",
1281
+ "bitmark++",
1282
+ "body"
1283
+ );
1284
+ this.throwOnError(out);
1285
+ return out;
1286
+ }
1287
+ /**
1288
+ * Extract plain text from bitmark or bitmark JSON (bpg-compatible).
1289
+ */
1290
+ extractPlainText(input, options) {
1291
+ const inputFormat = options?.inputFormat;
1292
+ const wasm2 = getLegacyWasm();
1293
+ if (inputFormat === "plainText") {
1294
+ return typeof input === "string" ? String(input) : "";
1295
+ }
1296
+ if (inputFormat === "bitmarkText") {
1297
+ const ast = wasm2.convert_text(String(input), "textToAst", "bitmark++", "body");
1298
+ const out2 = wasm2.convert_text(ast, "astToPlainText", "bitmark++", "body");
1299
+ this.throwOnError(out2);
1300
+ return out2;
1301
+ }
1302
+ if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm2.is_bitmark(input)) {
1303
+ const looksJson = (() => {
1304
+ try {
1305
+ JSON.parse(input);
1306
+ return true;
1307
+ } catch {
1308
+ return false;
1309
+ }
1310
+ })();
1311
+ if (!looksJson) {
1312
+ return this.extractPlainText(input, { inputFormat: "bitmarkText" });
1313
+ }
1314
+ }
1315
+ const { source, isBitmark } = this.resolveInput(input, void 0);
1316
+ const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1);
1317
+ this.throwOnError(out);
1318
+ return out;
1319
+ }
1320
+ /** If `s` parses as a TextAst JSON array, return it. */
1321
+ parseTextAstString(s) {
1322
+ const t = s.trim();
1323
+ if (!t.startsWith("[")) return void 0;
1324
+ try {
1325
+ const v = JSON.parse(t);
1326
+ if (Array.isArray(v) && v.every((n) => n !== null && typeof n === "object" && "type" in n)) {
1327
+ return v;
1328
+ }
1329
+ } catch {
1330
+ }
1331
+ return void 0;
1332
+ }
1333
+ // ------------------------------------------------------------------
1334
+ // Internal helpers
1335
+ // ------------------------------------------------------------------
1336
+ /**
1337
+ * Resolve bpg input (string | file path | JSON value | pseudo-AST) to a
1338
+ * source string for the WASM core, classified per bpg's detection order:
1339
+ * AST → JSON → assume bitmark (PLAN-126 F-10).
1340
+ */
1341
+ resolveInput(input, inputFormat) {
1342
+ if (typeof input !== "string") {
1343
+ const entries = this.jsonEntries(input);
1344
+ return {
1345
+ source: JSON.stringify(entries ? entries.map((b) => this.toWrapperEntry(b)) : input),
1346
+ isBitmark: false
1347
+ };
1348
+ }
1349
+ const inStr = this.maybeReadFile(input, inputFormat);
1350
+ const wasm2 = getLegacyWasm();
1351
+ if (wasm2.is_bitmark(inStr)) return { source: inStr, isBitmark: true };
1352
+ try {
1353
+ const parsed = JSON.parse(inStr);
1354
+ const entries = this.jsonEntries(parsed);
1355
+ if (entries) {
1356
+ return {
1357
+ source: JSON.stringify(entries.map((b) => this.toWrapperEntry(b))),
1358
+ isBitmark: false
1359
+ };
1360
+ }
1361
+ } catch {
1362
+ return { source: inStr, isBitmark: true };
1363
+ }
1364
+ return { source: inStr, isBitmark: false };
1365
+ }
1366
+ /**
1367
+ * Normalise the JSON shapes bpg accepts to a bits/entries array:
1368
+ * wrapper array, `{ bits: [...] }` AST envelope, single `{ bit: ... }`
1369
+ * wrapper, or a bare bit object (`{ type: ... }`).
1370
+ */
1371
+ jsonEntries(v) {
1372
+ if (Array.isArray(v)) return v;
1373
+ if (v !== null && typeof v === "object") {
1374
+ const o = v;
1375
+ if (Array.isArray(o.bits)) return o.bits;
1376
+ if ("bit" in o) return [o];
1377
+ if (typeof o.type === "string") return [{ bit: o }];
1378
+ }
1379
+ return void 0;
1380
+ }
1381
+ /**
1382
+ * Normalise a pseudo-AST bits entry to a `{ bit, parser? }` wrapper.
1383
+ * `Builder.buildBit` returns bare bit JSON (with any parser metadata
1384
+ * attached under a non-enumerable symbol); parsed forward output is
1385
+ * already wrapper-shaped.
1386
+ */
1387
+ toWrapperEntry(entry) {
1388
+ if (entry !== null && typeof entry === "object" && "bit" in entry) return entry;
1389
+ const wrapper = { bit: entry };
1390
+ const parser = entry?.[BUILT_BIT_PARSER];
1391
+ if (parser !== void 0) wrapper.parser = parser;
1392
+ return wrapper;
1393
+ }
1394
+ /** bpg parity: read `input` as a file when it names one (Node only). */
1395
+ maybeReadFile(input, inputFormat) {
1396
+ if (inputFormat === "string") return input;
1397
+ const io = getLegacyFileIo();
1398
+ if (!io) return input;
1399
+ try {
1400
+ if (io.existsSync(input)) return io.readFileSync(input, "utf8");
1401
+ } catch {
1402
+ }
1403
+ return input;
1404
+ }
1405
+ /** bpg parity: writing a file is impossible in the browser. */
1406
+ checkBrowserFileWrite(outputFile) {
1407
+ if (outputFile && !getLegacyFileIo()) {
1408
+ throw new Error("Cannot write to file in browser environment");
1409
+ }
1410
+ }
1411
+ /** Return `data`, or write it to `outputFile` (returning void), as bpg does. */
1412
+ deliver(data, outputFile, fileOptions) {
1413
+ if (!outputFile) return data;
1414
+ const io = getLegacyFileIo();
1415
+ if (!io) throw new Error("Cannot write to file in browser environment");
1416
+ io.writeFile(outputFile, data, {
1417
+ append: fileOptions?.append,
1418
+ encoding: fileOptions?.encoding ?? "utf8"
1419
+ });
1420
+ }
1421
+ /** The core reports failures as `error:`-prefixed strings; bpg throws. */
1422
+ throwOnError(out) {
1423
+ if (out.startsWith("error:")) {
1424
+ throw new Error(out.slice("error:".length).trim());
1425
+ }
1426
+ }
1427
+ };
1428
+ function extractHtmlTables(html) {
1429
+ const tables = [];
1430
+ const lower = html.toLowerCase();
1431
+ let i = 0;
1432
+ for (; ; ) {
1433
+ const start = lower.indexOf("<table", i);
1434
+ if (start === -1) break;
1435
+ let depth = 0;
1436
+ let j = start;
1437
+ let end = -1;
1438
+ while (j < html.length) {
1439
+ const open = lower.indexOf("<table", j);
1440
+ const close = lower.indexOf("</table", j);
1441
+ if (close === -1) break;
1442
+ if (open !== -1 && open < close) {
1443
+ depth++;
1444
+ j = open + "<table".length;
1445
+ } else {
1446
+ depth--;
1447
+ const closeEnd = lower.indexOf(">", close);
1448
+ j = closeEnd === -1 ? html.length : closeEnd + 1;
1449
+ if (depth === 0) {
1450
+ end = j;
1451
+ break;
1452
+ }
1453
+ }
1454
+ }
1455
+ if (end === -1) break;
1456
+ tables.push(html.slice(start, end));
1457
+ i = end;
1458
+ }
1459
+ return tables;
1460
+ }
1461
+ function bitmarkTextParse(text) {
1462
+ const out = getLegacyWasm().convert_text(text, "textToAst", "bitmark++", "body");
1463
+ if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
1464
+ return JSON.parse(out);
1465
+ }
1466
+
1467
+ // src/legacy/resource-builder.ts
1468
+ var RESOURCE_SPECS = {
1469
+ imageResource: { type: "image", key: "image", valueField: "src" },
1470
+ imageLinkResource: { type: "image-link", key: "imageLink", valueField: "url" },
1471
+ audioResource: { type: "audio", key: "audio", valueField: "src" },
1472
+ audioEmbedResource: { type: "audio-embed", key: "audioEmbed", valueField: "src" },
1473
+ audioLinkResource: { type: "audio-link", key: "audioLink", valueField: "url" },
1474
+ videoResource: { type: "video", key: "video", valueField: "src" },
1475
+ videoEmbedResource: { type: "video-embed", key: "videoEmbed", valueField: "url" },
1476
+ videoLinkResource: { type: "video-link", key: "videoLink", valueField: "url" },
1477
+ stillImageFilmEmbedResource: {
1478
+ type: "still-image-film-embed",
1479
+ key: "stillImageFilmEmbed",
1480
+ valueField: "url"
1481
+ },
1482
+ stillImageFilmLinkResource: {
1483
+ type: "still-image-film-link",
1484
+ key: "stillImageFilmLink",
1485
+ valueField: "url"
1486
+ },
1487
+ articleResource: { type: "article", key: "article", valueField: "body" },
1488
+ documentResource: { type: "document", key: "document", valueField: "url" },
1489
+ documentEmbedResource: { type: "document-embed", key: "documentEmbed", valueField: "url" },
1490
+ documentLinkResource: { type: "document-link", key: "documentLink", valueField: "url" },
1491
+ documentDownloadResource: {
1492
+ type: "document-download",
1493
+ key: "documentDownload",
1494
+ valueField: "url"
1495
+ },
1496
+ appLinkResource: { type: "app-link", key: "appLink", valueField: "url" },
1497
+ websiteLinkResource: { type: "website-link", key: "websiteLink", valueField: "url" }
1498
+ };
1499
+ function buildResource(spec) {
1500
+ return (_context, data, _typeAlias) => {
1501
+ if (!data) return void 0;
1502
+ const { value, ...rest } = data;
1503
+ const inner = { [spec.valueField]: value ?? "" };
1504
+ for (const [k, v] of Object.entries(rest)) {
1505
+ if (v !== void 0) inner[k] = v;
1506
+ }
1507
+ return { type: spec.type, [spec.key]: inner };
1508
+ };
1509
+ }
1510
+ var SPEC_BY_TYPE = Object.fromEntries(
1511
+ Object.values(RESOURCE_SPECS).map((s) => [s.type, s])
1512
+ );
1513
+ var ResourceBuilder = class {
1514
+ constructor() {
1515
+ __publicField(this, "imageResource", buildResource(RESOURCE_SPECS.imageResource));
1516
+ __publicField(this, "imageLinkResource", buildResource(RESOURCE_SPECS.imageLinkResource));
1517
+ __publicField(this, "audioResource", buildResource(RESOURCE_SPECS.audioResource));
1518
+ __publicField(this, "audioEmbedResource", buildResource(RESOURCE_SPECS.audioEmbedResource));
1519
+ __publicField(this, "audioLinkResource", buildResource(RESOURCE_SPECS.audioLinkResource));
1520
+ __publicField(this, "videoResource", buildResource(RESOURCE_SPECS.videoResource));
1521
+ __publicField(this, "videoEmbedResource", buildResource(RESOURCE_SPECS.videoEmbedResource));
1522
+ __publicField(this, "videoLinkResource", buildResource(RESOURCE_SPECS.videoLinkResource));
1523
+ __publicField(this, "stillImageFilmEmbedResource", buildResource(
1524
+ RESOURCE_SPECS.stillImageFilmEmbedResource
1525
+ ));
1526
+ __publicField(this, "stillImageFilmLinkResource", buildResource(
1527
+ RESOURCE_SPECS.stillImageFilmLinkResource
1528
+ ));
1529
+ __publicField(this, "articleResource", buildResource(RESOURCE_SPECS.articleResource));
1530
+ __publicField(this, "documentResource", buildResource(RESOURCE_SPECS.documentResource));
1531
+ __publicField(this, "documentEmbedResource", buildResource(RESOURCE_SPECS.documentEmbedResource));
1532
+ __publicField(this, "documentLinkResource", buildResource(RESOURCE_SPECS.documentLinkResource));
1533
+ __publicField(this, "documentDownloadResource", buildResource(
1534
+ RESOURCE_SPECS.documentDownloadResource
1535
+ ));
1536
+ __publicField(this, "appLinkResource", buildResource(RESOURCE_SPECS.appLinkResource));
1537
+ __publicField(this, "websiteLinkResource", buildResource(RESOURCE_SPECS.websiteLinkResource));
1538
+ }
1539
+ /**
1540
+ * Normalise existing ResourceJson wrapper(s) (bpg-compatible).
1541
+ * Unknown resource types are dropped (bpg parity: it skips invalid types).
1542
+ */
1543
+ resourceFromResourceJson(_context, resource) {
1544
+ if (!resource) return void 0;
1545
+ const single = !Array.isArray(resource);
1546
+ const list = single ? [resource] : resource;
1547
+ const nodes = [];
1548
+ for (const wrapper of list) {
1549
+ const spec = SPEC_BY_TYPE[wrapper.type];
1550
+ if (!spec) continue;
1551
+ const inner = wrapper[spec.key] ?? {};
1552
+ const { [spec.valueField]: value, ...rest } = inner;
1553
+ const built = buildResource(spec)(void 0, { value, ...rest });
1554
+ if (built) nodes.push(built);
1555
+ }
1556
+ if (nodes.length === 0) return void 0;
1557
+ return single ? nodes[0] : nodes;
1558
+ }
1559
+ /**
1560
+ * Build a resource wrapper from a bare ResourceDataJson (bpg-compatible).
1561
+ * `data` may also be a plain string (used as the url/src/body value).
1562
+ */
1563
+ resourceFromResourceDataJson(context, type, data) {
1564
+ if (!data) return void 0;
1565
+ const spec = SPEC_BY_TYPE[type];
1566
+ if (!spec) return void 0;
1567
+ const asString = typeof data === "string" ? data : void 0;
1568
+ const obj = typeof data === "object" ? data : {};
1569
+ const { url, src, body, ...rest } = obj;
1570
+ const value = url ?? src ?? body ?? asString;
1571
+ return buildResource(spec)(context, { value, ...rest });
1572
+ }
1573
+ };
1574
+
1575
+ // src/legacy/options.ts
1576
+ var Input = {
1577
+ /** Input is as a string */
1578
+ string: "string",
1579
+ /** Input is as a file path */
1580
+ file: "file"
1581
+ };
1582
+ var Output = {
1583
+ /** Output bitmark string */
1584
+ bitmark: "bitmark",
1585
+ /** Output JSON as a plain JS object, or a file */
1586
+ json: "json",
1587
+ /** Output AST as a plain JS object, or a file */
1588
+ ast: "ast",
1589
+ /** Output plain text as a string, or a file */
1590
+ text: "text"
1591
+ };
1592
+ var InputFormat = {
1593
+ bitmark: "bitmark",
1594
+ bitmarkText: "bitmarkText",
1595
+ plainText: "plainText",
1596
+ html: "html"
1597
+ };
1598
+ var BitmarkVersion = {
1599
+ v2: 2,
1600
+ v3: 3
1601
+ };
1602
+ var CardSetVersion = {
1603
+ v1: 1,
1604
+ v2: 2
1605
+ };
1606
+ var BitmarkParserType = {
1607
+ peggy: "peggy"
1608
+ };
1609
+ var InfoType = {
1610
+ list: "list",
1611
+ deprecated: "deprecated",
1612
+ all: "all",
1613
+ bit: "bit"
1614
+ };
1615
+ var InfoFormat = {
1616
+ text: "text",
1617
+ json: "json",
1618
+ pojo: "pojo"
1619
+ };
1620
+ var BodyTextFormat = {
1621
+ plainText: "text",
1622
+ latex: "latex",
1623
+ json: "json",
1624
+ xml: "xml",
1625
+ bitmarkPlusPlus: "bitmark++"
1626
+ };
1627
+ var TextLocation = {
1628
+ tag: "tag",
1629
+ body: "body"
1630
+ };
1631
+
1632
+ // src/legacy/enums-extra.ts
1633
+ var TextMarkType = {
1634
+ bold: "bold",
1635
+ light: "light",
1636
+ italic: "italic",
1637
+ highlight: "highlight",
1638
+ highlightOrange: "highlightOrange",
1639
+ highlightYellow: "highlightYellow",
1640
+ highlightGreen: "highlightGreen",
1641
+ highlightBlue: "highlightBlue",
1642
+ highlightPurple: "highlightPurple",
1643
+ highlightPink: "highlightPink",
1644
+ highlightBrown: "highlightBrown",
1645
+ highlightBlack: "highlightBlack",
1646
+ highlightWhite: "highlightWhite",
1647
+ highlightGray: "highlightGray",
1648
+ strike: "strike",
1649
+ subscript: "subscript",
1650
+ superscript: "superscript",
1651
+ ins: "ins",
1652
+ del: "del",
1653
+ underline: "underline",
1654
+ doubleUnderline: "doubleUnderline",
1655
+ circle: "circle",
1656
+ languageEmRed: "languageEmRed",
1657
+ languageEmOrange: "languageEmOrange",
1658
+ languageEmYellow: "languageEmYellow",
1659
+ languageEmGreen: "languageEmGreen",
1660
+ languageEmBlue: "languageEmBlue",
1661
+ languageEmPurple: "languageEmPurple",
1662
+ languageEmPink: "languageEmPink",
1663
+ languageEmBrown: "languageEmBrown",
1664
+ languageEmBlack: "languageEmBlack",
1665
+ languageEmWhite: "languageEmWhite",
1666
+ languageEmGray: "languageEmGray",
1667
+ languageEm: "languageEm",
1668
+ userUnderline: "userUnderline",
1669
+ userDoubleUnderline: "userDoubleUnderline",
1670
+ userStrike: "userStrike",
1671
+ userCircle: "userCircle",
1672
+ userHighlight: "userHighlight",
1673
+ notranslate: "notranslate",
1674
+ link: "link",
1675
+ ref: "ref",
1676
+ xref: "xref",
1677
+ extref: "extref",
1678
+ footnote: "footnote",
1679
+ footnoteStar: "footnote*",
1680
+ symbol: "symbol",
1681
+ var: "var",
1682
+ code: "code",
1683
+ timer: "timer",
1684
+ duration: "duration",
1685
+ color: "color",
1686
+ colorPicker: "colorPicker",
1687
+ comment: "comment"
1688
+ };
1689
+ var TextNodeType = {
1690
+ text: "text",
1691
+ hardBreak: "hardBreak",
1692
+ paragraph: "paragraph",
1693
+ heading: "heading",
1694
+ section: "section",
1695
+ noBulletList: "noBulletList",
1696
+ bulletList: "bulletList",
1697
+ orderedList: "orderedList",
1698
+ orderedListRoman: "orderedListRoman",
1699
+ orderedListRomanLower: "orderedListRomanLower",
1700
+ letteredList: "letteredList",
1701
+ letteredListLower: "letteredListLower",
1702
+ taskList: "taskList",
1703
+ listItem: "listItem",
1704
+ taskItem: "taskItem",
1705
+ image: "image",
1706
+ imageInline: "imageInline",
1707
+ codeBlock: "codeBlock",
1708
+ latex: "latex",
1709
+ gap: "gap",
1710
+ select: "select",
1711
+ highlight: "highlight",
1712
+ mark: "mark"
1713
+ };
1714
+ function bitNameToKey(name) {
1715
+ return name.replace(/-([a-z0-9])/gu, (_, c) => c.toUpperCase());
1716
+ }
1717
+ var bitTypeCache;
1718
+ function loadBitTypes() {
1719
+ if (!bitTypeCache) {
1720
+ const wasm2 = getLegacyWasm();
1721
+ const all = JSON.parse(wasm2.info("all", "json", "", false, 2));
1722
+ const map = { _standard: "_standard" };
1723
+ for (const { name } of all) {
1724
+ map[bitNameToKey(name)] = name;
1725
+ }
1726
+ bitTypeCache = map;
1727
+ }
1728
+ return bitTypeCache;
1729
+ }
1730
+ var BitType = new Proxy(
1731
+ {},
1732
+ {
1733
+ get: (_t, prop) => typeof prop === "string" ? loadBitTypes()[prop] : void 0,
1734
+ has: (_t, prop) => typeof prop === "string" && prop in loadBitTypes(),
1735
+ ownKeys: () => Reflect.ownKeys(loadBitTypes()),
1736
+ getOwnPropertyDescriptor: (_t, prop) => typeof prop === "string" && prop in loadBitTypes() ? { value: loadBitTypes()[prop], enumerable: true, configurable: true, writable: false } : void 0
1737
+ }
1738
+ );
1739
+ function unsupportedEnum(name, reason) {
1740
+ return new Proxy(
1741
+ {},
1742
+ {
1743
+ get: (_t, prop) => {
1744
+ if (prop === Symbol.toPrimitive || prop === "toString" || prop === Symbol.toStringTag) {
1745
+ return () => `[unsupported ${name}]`;
1746
+ }
1747
+ return unsupportedMember(name, reason);
1748
+ },
1749
+ has: () => unsupportedMember(name, reason),
1750
+ ownKeys: () => unsupportedMember(name, reason)
1751
+ }
1752
+ );
1753
+ }
1754
+ var NodeType = unsupportedEnum(
1755
+ "NodeType",
1756
+ "it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"
1757
+ );
1758
+ var BoundingBoxIndex = unsupportedEnum(
1759
+ "BoundingBoxIndex",
1760
+ "bpg-internal bounding-box utility"
1761
+ );
1762
+
1763
+ // src/legacy/stubs.ts
1764
+ function stubClass(name, reason) {
1765
+ return class {
1766
+ constructor() {
1767
+ unsupportedMember(name, reason);
1768
+ }
1769
+ };
1770
+ }
1771
+ var WALKER_REASON = "the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave";
1772
+ var INTERNAL_REASON = "internal class of bpg's TS implementation";
1773
+ var Ast = stubClass("Ast", WALKER_REASON);
1774
+ var BitmarkGenerator = stubClass("BitmarkGenerator", INTERNAL_REASON);
1775
+ var BitmarkStringGenerator = stubClass("BitmarkStringGenerator", INTERNAL_REASON);
1776
+ var BitmarkFileGenerator = stubClass("BitmarkFileGenerator", INTERNAL_REASON);
1777
+ var JsonGenerator = stubClass("JsonGenerator", INTERNAL_REASON);
1778
+ var JsonStringGenerator = stubClass("JsonStringGenerator", INTERNAL_REASON);
1779
+ var JsonFileGenerator = stubClass("JsonFileGenerator", INTERNAL_REASON);
1780
+ var HtmlTableGenerator = stubClass("HtmlTableGenerator", INTERNAL_REASON);
1781
+ var HtmlTableParser = stubClass("HtmlTableParser", INTERNAL_REASON);
1782
+ var BitmarkParser = stubClass("BitmarkParser", INTERNAL_REASON);
1783
+ var JsonParser = stubClass("JsonParser", INTERNAL_REASON);
1784
+ var StringWriter = stubClass("StringWriter", INTERNAL_REASON);
1785
+ var FileWriter = stubClass("FileWriter", INTERNAL_REASON);
1786
+ var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
1787
+
694
1788
  // src/browser/index.ts
1789
+ setLegacyWasm(bitmark_wasm_exports);
695
1790
  async function init(module_or_path) {
696
1791
  if (typeof module_or_path === "undefined") {
697
1792
  module_or_path = new URL(`bitmark_wasm_bg.wasm?v=${PACKAGE_INFO.version}`, importMetaUrl);
@@ -719,15 +1814,16 @@ function convert2(input, options = {}) {
719
1814
  );
720
1815
  }
721
1816
  function optimize2(input, options = {}) {
722
- return optimize(input, options.pretty ?? false, options.indent ?? 2);
1817
+ return optimize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
723
1818
  }
724
1819
  function fullize2(input, options = {}) {
725
- return fullize(input, options.pretty ?? false, options.indent ?? 2);
1820
+ return fullize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
726
1821
  }
727
1822
  var expand = fullize2;
728
1823
  function canonicalize2(input, options = {}) {
729
1824
  return canonicalize(
730
1825
  input,
1826
+ options.inputFormat ?? "auto",
731
1827
  options.mode ?? "optimized",
732
1828
  options.pretty ?? false,
733
1829
  options.indent ?? 2,
@@ -790,6 +1886,7 @@ function info2(options = {}) {
790
1886
  info,
791
1887
  init,
792
1888
  initSync,
1889
+ legacy,
793
1890
  lex,
794
1891
  optimize,
795
1892
  parse,