@gmb/bitmark-parser 6.2.0 → 6.3.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.
- package/README.md +105 -54
- package/dist/browser/bitmark-parser.min.js +4 -4
- 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 +128 -182
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +146 -117
- package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/esm/index.d.ts +146 -117
- package/dist/browser/esm/index.js +126 -176
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/index.cjs +59 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1912 -300
- package/dist/index.d.ts +1912 -300
- package/dist/index.js +57 -48
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +40 -23
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.d.cts +32 -14
- package/dist/legacy.d.ts +32 -14
- package/dist/legacy.js +40 -23
- package/dist/legacy.js.map +1 -1
- package/package.json +8 -7
- package/wasm/bitmark_wasm.d.ts +31 -53
- package/wasm/bitmark_wasm.js +115 -209
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +1 -4
- package/wasm/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createRequire } from "module";
|
|
|
10
10
|
// src/generated/package_info.ts
|
|
11
11
|
var PACKAGE_INFO = {
|
|
12
12
|
"name": "@gmb/bitmark-parser",
|
|
13
|
-
"version": "6.
|
|
13
|
+
"version": "6.3.0",
|
|
14
14
|
"author": "Get More Brain Ltd <info@getmorebrain.com>",
|
|
15
15
|
"license": "ISC",
|
|
16
16
|
"description": "A parser for bitmark text, powered by WebAssembly."
|
|
@@ -316,16 +316,14 @@ function validateVersionOptions(opts) {
|
|
|
316
316
|
}
|
|
317
317
|
function validateBitmarkOptions(o) {
|
|
318
318
|
if (o.explicitTextFormat) unsupportedOption("bitmarkOptions.explicitTextFormat");
|
|
319
|
-
if (o.
|
|
320
|
-
unsupportedOption("bitmarkOptions.
|
|
319
|
+
if (o.cardSetVersion === 1) {
|
|
320
|
+
unsupportedOption("bitmarkOptions.cardSetVersion: 1", V3_ONLY);
|
|
321
321
|
}
|
|
322
|
-
if (o.cardSetVersion === 1) unsupportedOption("bitmarkOptions.cardSetVersion: 1", V3_ONLY);
|
|
323
322
|
if (o.debugGenerationInline) unsupportedOption("bitmarkOptions.debugGenerationInline");
|
|
324
323
|
if (o.noBreakscaping) unsupportedOption("bitmarkOptions.noBreakscaping");
|
|
325
324
|
}
|
|
326
325
|
function validateJsonOptions(o) {
|
|
327
326
|
if (o.textAsPlainText) unsupportedOption("jsonOptions.textAsPlainText", V3_ONLY);
|
|
328
|
-
if (o.excludeUnknownProperties) unsupportedOption("jsonOptions.excludeUnknownProperties");
|
|
329
327
|
if (o.debugGenerationInline) unsupportedOption("jsonOptions.debugGenerationInline");
|
|
330
328
|
}
|
|
331
329
|
function prettyIndent(prettify) {
|
|
@@ -361,6 +359,14 @@ function isPseudoAst(v) {
|
|
|
361
359
|
return v !== null && typeof v === "object" && (PSEUDO_AST_MARKER in v || Array.isArray(v.bits));
|
|
362
360
|
}
|
|
363
361
|
|
|
362
|
+
// src/legacy/generated/resource-collection-keys.ts
|
|
363
|
+
var RESOURCE_COLLECTION_KEYS = {
|
|
364
|
+
"extractor-image": { key: "images", resourceType: "image" },
|
|
365
|
+
"extractor-image-collapsible": { key: "images", resourceType: "image" },
|
|
366
|
+
"images-logo-grave": { key: "logos", resourceType: "image" },
|
|
367
|
+
"prototype-images": { key: "images", resourceType: "image" }
|
|
368
|
+
};
|
|
369
|
+
|
|
364
370
|
// src/legacy/builder.ts
|
|
365
371
|
var BUILT_BIT_PARSER = /* @__PURE__ */ Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser");
|
|
366
372
|
var DATA_KEY_TO_JSON_KEY = {
|
|
@@ -405,10 +411,14 @@ var Builder = class {
|
|
|
405
411
|
* NOTE (documented divergences from bpg):
|
|
406
412
|
* - the return value is bit JSON, not bpg's internal AST node model;
|
|
407
413
|
* - `resourceType` (an inference hint in bpg) is not carried into the
|
|
408
|
-
* JSON — the attached `resource` object is authoritative
|
|
409
|
-
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
414
|
+
* JSON — the attached `resource` object is authoritative.
|
|
415
|
+
*
|
|
416
|
+
* `resources` follows bpg's JsonGenerator routing: on a bit whose config
|
|
417
|
+
* maps a repeatable resource tag group onto a collection key (e.g.
|
|
418
|
+
* `images` / `logos` — see the generated RESOURCE_COLLECTION_KEYS), the
|
|
419
|
+
* matching-type entries land under that key; on every other bit the first
|
|
420
|
+
* entry becomes the canonical single `resource` (as bpg: "if there is
|
|
421
|
+
* more than one resource, use the first one").
|
|
412
422
|
*/
|
|
413
423
|
buildBit(data, _options) {
|
|
414
424
|
const wasm2 = getLegacyWasm();
|
|
@@ -444,12 +454,15 @@ var Builder = class {
|
|
|
444
454
|
delete src.__isDefaultExample;
|
|
445
455
|
}
|
|
446
456
|
const resources = src.resources;
|
|
447
|
-
if (resources !== void 0) {
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
457
|
+
if (resources !== void 0 && bitType !== void 0) {
|
|
458
|
+
const list = Array.isArray(resources) ? resources : [resources];
|
|
459
|
+
const collection = RESOURCE_COLLECTION_KEYS[bitType];
|
|
460
|
+
if (collection) {
|
|
461
|
+
bit[collection.key] = list.filter(
|
|
462
|
+
(r) => r !== null && typeof r === "object" && r.type === collection.resourceType
|
|
463
|
+
);
|
|
464
|
+
} else if (list.length >= 1) {
|
|
465
|
+
bit.resource = list[0];
|
|
453
466
|
}
|
|
454
467
|
delete src.resources;
|
|
455
468
|
}
|
|
@@ -467,7 +480,7 @@ var Builder = class {
|
|
|
467
480
|
}
|
|
468
481
|
}
|
|
469
482
|
this.parseStringTexts(bit);
|
|
470
|
-
const out = wasm2.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1);
|
|
483
|
+
const out = wasm2.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false);
|
|
471
484
|
if (out.startsWith("error:")) {
|
|
472
485
|
throw new Error(out.slice("error:".length).trim());
|
|
473
486
|
}
|
|
@@ -591,8 +604,10 @@ var BitmarkParserGenerator = class {
|
|
|
591
604
|
const outputFormat = opts.outputFormat ?? (isBitmark ? "json" : "bitmark");
|
|
592
605
|
const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
|
|
593
606
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
607
|
+
const emit = coreFormat === "bitmark" ? prettyIndent(bitmarkOptions.prettifyJson) : { pretty, indent };
|
|
594
608
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
595
|
-
const
|
|
609
|
+
const includeUnknown = !jsonOptions.excludeUnknownProperties;
|
|
610
|
+
const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown);
|
|
596
611
|
this.throwOnError(out);
|
|
597
612
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
598
613
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
@@ -622,7 +637,9 @@ var BitmarkParserGenerator = class {
|
|
|
622
637
|
this.checkBrowserFileWrite(opts.outputFile);
|
|
623
638
|
const wasm2 = getLegacyWasm();
|
|
624
639
|
const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
|
|
625
|
-
const { pretty, indent } = prettyIndent(
|
|
640
|
+
const { pretty, indent } = prettyIndent(
|
|
641
|
+
isBitmark ? bitmarkOptions.prettifyJson : jsonOptions.prettify
|
|
642
|
+
);
|
|
626
643
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
627
644
|
const out = wasm2.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
|
|
628
645
|
this.throwOnError(out);
|
|
@@ -674,7 +691,7 @@ var BitmarkParserGenerator = class {
|
|
|
674
691
|
const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
|
|
675
692
|
if (!isHtmlInput) {
|
|
676
693
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
677
|
-
const out2 = wasm2.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1);
|
|
694
|
+
const out2 = wasm2.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false);
|
|
678
695
|
this.throwOnError(out2);
|
|
679
696
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
680
697
|
}
|
|
@@ -684,12 +701,12 @@ var BitmarkParserGenerator = class {
|
|
|
684
701
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
685
702
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
686
703
|
if (outputFormat === "html") {
|
|
687
|
-
const out2 = wasm2.convert(wrapped, "html", "html", "optimized", false, 2, 1);
|
|
704
|
+
const out2 = wasm2.convert(wrapped, "html", "html", "optimized", false, 2, 1, false);
|
|
688
705
|
this.throwOnError(out2);
|
|
689
706
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
690
707
|
}
|
|
691
708
|
const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
|
|
692
|
-
const out = wasm2.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces);
|
|
709
|
+
const out = wasm2.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false);
|
|
693
710
|
this.throwOnError(out);
|
|
694
711
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
695
712
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
@@ -714,7 +731,7 @@ var BitmarkParserGenerator = class {
|
|
|
714
731
|
const opts = Object.assign({}, options);
|
|
715
732
|
const wasm2 = getLegacyWasm();
|
|
716
733
|
const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
|
|
717
|
-
const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1);
|
|
734
|
+
const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true);
|
|
718
735
|
this.throwOnError(out);
|
|
719
736
|
return makePseudoAst(JSON.parse(out));
|
|
720
737
|
}
|
|
@@ -821,7 +838,7 @@ var BitmarkParserGenerator = class {
|
|
|
821
838
|
}
|
|
822
839
|
}
|
|
823
840
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
824
|
-
const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1);
|
|
841
|
+
const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false);
|
|
825
842
|
this.throwOnError(out);
|
|
826
843
|
return out;
|
|
827
844
|
}
|
|
@@ -1306,19 +1323,25 @@ function version() {
|
|
|
1306
1323
|
function lex(input, options = {}) {
|
|
1307
1324
|
return wasm.lex(input, options.stage ?? "lex");
|
|
1308
1325
|
}
|
|
1309
|
-
function
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1326
|
+
function bitmarkToObjects(input, options = {}) {
|
|
1327
|
+
const out = wasm.convert(
|
|
1328
|
+
input,
|
|
1329
|
+
"bitmark",
|
|
1330
|
+
"json",
|
|
1331
|
+
options.mode ?? "optimized",
|
|
1332
|
+
false,
|
|
1333
|
+
2,
|
|
1334
|
+
1,
|
|
1335
|
+
options.includeUnknownProperties ?? false
|
|
1336
|
+
);
|
|
1314
1337
|
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1315
1338
|
return JSON.parse(out);
|
|
1316
1339
|
}
|
|
1317
|
-
function
|
|
1340
|
+
function objectsToBitmark(bits, options = {}) {
|
|
1318
1341
|
const entries = bits.map(
|
|
1319
1342
|
(b) => b !== null && typeof b === "object" && "bit" in b && typeof b.bit === "object" ? b : { bit: b }
|
|
1320
1343
|
);
|
|
1321
|
-
const out = wasm.convert(JSON.stringify(entries), "json", "bitmark", options.mode ?? "optimized", false, 2, 1);
|
|
1344
|
+
const out = wasm.convert(JSON.stringify(entries), "json", "bitmark", options.mode ?? "optimized", false, 2, 1, false);
|
|
1322
1345
|
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1323
1346
|
return out;
|
|
1324
1347
|
}
|
|
@@ -1330,16 +1353,10 @@ function convert(input, options = {}) {
|
|
|
1330
1353
|
options.mode ?? "optimized",
|
|
1331
1354
|
options.pretty ?? false,
|
|
1332
1355
|
options.indent ?? 2,
|
|
1333
|
-
options.spacesAroundValues ?? 1
|
|
1356
|
+
options.spacesAroundValues ?? 1,
|
|
1357
|
+
options.includeUnknownProperties ?? false
|
|
1334
1358
|
);
|
|
1335
1359
|
}
|
|
1336
|
-
function optimize(input, options = {}) {
|
|
1337
|
-
return wasm.optimize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
|
|
1338
|
-
}
|
|
1339
|
-
function fullize(input, options = {}) {
|
|
1340
|
-
return wasm.fullize(input, options.inputFormat ?? "auto", options.pretty ?? false, options.indent ?? 2);
|
|
1341
|
-
}
|
|
1342
|
-
var expand = fullize;
|
|
1343
1360
|
function canonicalize(input, options = {}) {
|
|
1344
1361
|
return wasm.canonicalize(
|
|
1345
1362
|
input,
|
|
@@ -1395,24 +1412,16 @@ function info(options = {}) {
|
|
|
1395
1412
|
const indent = options.indent ?? 2;
|
|
1396
1413
|
return wasm.info(infoType, format, bit, pretty, indent);
|
|
1397
1414
|
}
|
|
1398
|
-
function generate(input, options = {}) {
|
|
1399
|
-
return wasm.convert(input, "json", "bitmark", options.mode ?? "optimized", false, 2, 1);
|
|
1400
|
-
}
|
|
1401
1415
|
export {
|
|
1416
|
+
bitmarkToObjects,
|
|
1402
1417
|
breakscapeText,
|
|
1403
1418
|
canonicalize,
|
|
1404
1419
|
convert,
|
|
1405
1420
|
countBits,
|
|
1406
|
-
expand,
|
|
1407
|
-
fullize,
|
|
1408
|
-
generate,
|
|
1409
|
-
generateBits,
|
|
1410
1421
|
info,
|
|
1411
1422
|
legacy_exports as legacy,
|
|
1412
1423
|
lex,
|
|
1413
|
-
|
|
1414
|
-
parse,
|
|
1415
|
-
parseBits,
|
|
1424
|
+
objectsToBitmark,
|
|
1416
1425
|
patchEntry,
|
|
1417
1426
|
splitBits,
|
|
1418
1427
|
transform,
|