@gmb/bitmark-parser 6.1.3 → 6.2.0

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