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