@gmb/bitmark-parser 6.10.1 → 6.11.1
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 +288 -22
- package/dist/browser/bitmark-parser.min.js +4 -4
- package/dist/browser/bitmark-parser.min.js.map +1 -1
- package/dist/browser/cjs/index.cjs +1053 -345
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +1175 -34
- package/dist/browser/esm/index.d.ts +1175 -34
- package/dist/browser/esm/index.js +1048 -345
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +712 -96
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/browser/wasm/bitmark_browser_full_wasm_bg.wasm +0 -0
- package/dist/browser/wasm/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/wasm/bitmark_wasm_bg.wasm +0 -0
- package/dist/index.cjs +124 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1175 -34
- package/dist/index.d.ts +1175 -34
- package/dist/index.js +119 -32
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +4 -4
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.js +4 -4
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs +7 -1
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +14 -8
- package/schema/bitmark.schema.json +2746 -573
- package/translations/translations.json +2940 -0
- package/wasm/bitmark_wasm.d.ts +53 -12
- package/wasm/bitmark_wasm.js +171 -47
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +4 -1
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +39 -12
- package/wasm-bitmark-json/bitmark_json_wasm.js +129 -53
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +3 -1
- package/wasm-bitmark-json/package.json +1 -1
- package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +149 -0
- package/wasm-browser-full/bitmark_browser_full_wasm.js +647 -0
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +23 -0
- package/wasm-browser-full/package.json +20 -0
- package/dist/browser/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/cjs/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/cjs/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/esm/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
package/dist/index.js
CHANGED
|
@@ -10,19 +10,26 @@ 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.11.1",
|
|
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."
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// src/core/facade.ts
|
|
20
|
+
var NODE_DEFAULT_FEATURE = "full";
|
|
20
21
|
var NotInitializedError = class extends Error {
|
|
21
22
|
constructor() {
|
|
22
23
|
super("wasm not initialised: call init() (or init({ feature: \u2026 })) first");
|
|
23
24
|
this.name = "NotInitializedError";
|
|
24
25
|
}
|
|
25
26
|
};
|
|
27
|
+
var RegisterError = class extends Error {
|
|
28
|
+
constructor(message) {
|
|
29
|
+
super(message);
|
|
30
|
+
this.name = "RegisterError";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
26
33
|
var UnsupportedFeatureError = class extends Error {
|
|
27
34
|
constructor(what, active2) {
|
|
28
35
|
super(
|
|
@@ -34,15 +41,23 @@ var UnsupportedFeatureError = class extends Error {
|
|
|
34
41
|
var active;
|
|
35
42
|
var activeFeature;
|
|
36
43
|
var lazyLoader;
|
|
44
|
+
var registrations = /* @__PURE__ */ new Map();
|
|
37
45
|
function getActive() {
|
|
38
46
|
if (!active && lazyLoader) lazyLoader();
|
|
39
47
|
if (!active) throw new NotInitializedError();
|
|
40
48
|
return active;
|
|
41
49
|
}
|
|
42
50
|
function setActive(feature, module) {
|
|
51
|
+
for (const [type, data] of registrations) {
|
|
52
|
+
const error = module.register(type, data);
|
|
53
|
+
if (error) throw new RegisterError(error.replace(/^error:\s*/, ""));
|
|
54
|
+
}
|
|
43
55
|
active = module;
|
|
44
56
|
activeFeature = feature;
|
|
45
57
|
}
|
|
58
|
+
function rememberRegistration(type, data) {
|
|
59
|
+
registrations.set(type, data);
|
|
60
|
+
}
|
|
46
61
|
function setLazyLoader(loader) {
|
|
47
62
|
lazyLoader = loader;
|
|
48
63
|
}
|
|
@@ -62,13 +77,10 @@ function stripArray(doc) {
|
|
|
62
77
|
const t = doc.trim();
|
|
63
78
|
return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
|
|
64
79
|
}
|
|
65
|
-
function
|
|
66
|
-
if (patch === void 0) return
|
|
67
|
-
if (typeof patch === "string")
|
|
68
|
-
|
|
69
|
-
return trimmed === "" ? [] : JSON.parse(trimmed);
|
|
70
|
-
}
|
|
71
|
-
return patch;
|
|
80
|
+
function patchJsonOf(patch) {
|
|
81
|
+
if (patch === void 0) return "";
|
|
82
|
+
if (typeof patch === "string") return patch.trim();
|
|
83
|
+
return JSON.stringify(patch);
|
|
72
84
|
}
|
|
73
85
|
function buildUnits(wasm, input, inputIsBitmark) {
|
|
74
86
|
if (inputIsBitmark) {
|
|
@@ -98,28 +110,56 @@ function planTransform(wasm, input, options) {
|
|
|
98
110
|
const sel = options.inputFormat ?? "auto";
|
|
99
111
|
const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
|
|
100
112
|
const inputFormat = inputIsBitmark ? "bitmark" : "json";
|
|
101
|
-
const staticPatch = normalisePatch(options.patch);
|
|
102
113
|
const units = buildUnits(wasm, input, inputIsBitmark);
|
|
103
114
|
const total = units.length;
|
|
104
|
-
const
|
|
105
|
-
const views = [];
|
|
115
|
+
const hooked = [];
|
|
106
116
|
for (let index = 0; index < total; index++) {
|
|
107
|
-
const { view
|
|
117
|
+
const { view } = units[index];
|
|
108
118
|
view.index = index;
|
|
109
119
|
view.total = total;
|
|
110
120
|
const result = options.preHook ? options.preHook(view) || {} : {};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
hooked.push(result.drop ? null : { patches: result.patches ?? [], outputFormat: result.outputFormat ?? output });
|
|
122
|
+
}
|
|
123
|
+
const patchJson = patchJsonOf(options.patch);
|
|
124
|
+
let resolved;
|
|
125
|
+
if (patchJson === "") {
|
|
126
|
+
resolved = units.map((_, index) => ({ source: index, bit: null, patch: [] }));
|
|
127
|
+
} else {
|
|
128
|
+
const out = wasm.resolve_patch_document(input, patchJson);
|
|
129
|
+
if (isError(out)) throw new Error(out);
|
|
130
|
+
resolved = JSON.parse(out);
|
|
131
|
+
}
|
|
132
|
+
const jobs = [];
|
|
133
|
+
const views = [];
|
|
134
|
+
for (const item of resolved) {
|
|
135
|
+
if (item.source !== null) {
|
|
136
|
+
const hook = hooked[item.source];
|
|
137
|
+
if (!hook) continue;
|
|
138
|
+
jobs.push({
|
|
139
|
+
index: item.source,
|
|
140
|
+
source: units[item.source].source,
|
|
141
|
+
inputFormat,
|
|
142
|
+
outputFormat: hook.outputFormat,
|
|
143
|
+
mode,
|
|
144
|
+
// The document's patches first, the hook's after (the hook contract).
|
|
145
|
+
patchJson: JSON.stringify([...item.patch, ...hook.patches]),
|
|
146
|
+
spacesAroundValues
|
|
147
|
+
});
|
|
148
|
+
views.push(units[item.source].view);
|
|
149
|
+
} else {
|
|
150
|
+
const bit = item.bit ?? {};
|
|
151
|
+
const index = jobs.length;
|
|
152
|
+
jobs.push({
|
|
153
|
+
index,
|
|
154
|
+
source: JSON.stringify([{ bit }]),
|
|
155
|
+
inputFormat: "json",
|
|
156
|
+
outputFormat: output,
|
|
157
|
+
mode,
|
|
158
|
+
patchJson: JSON.stringify(item.patch),
|
|
159
|
+
spacesAroundValues
|
|
160
|
+
});
|
|
161
|
+
views.push({ format: "json", index, total, bit });
|
|
162
|
+
}
|
|
123
163
|
}
|
|
124
164
|
return { jobs, views, output, pretty, indent };
|
|
125
165
|
}
|
|
@@ -621,7 +661,7 @@ var Builder = class {
|
|
|
621
661
|
const wasm = getLegacyWasm();
|
|
622
662
|
if (bitType !== void 0) {
|
|
623
663
|
try {
|
|
624
|
-
const info2 = JSON.parse(wasm.info("bit", "json", bitType, false, 2, false, false, true));
|
|
664
|
+
const info2 = JSON.parse(wasm.info("bit", "json", bitType, false, 2, false, false, true, ""));
|
|
625
665
|
if (info2.error === void 0) return { bodyFormat: info2.body?.format };
|
|
626
666
|
} catch {
|
|
627
667
|
}
|
|
@@ -720,7 +760,7 @@ var BitmarkParserGenerator = class {
|
|
|
720
760
|
const format = opts.outputFormat ?? "text";
|
|
721
761
|
const { pretty, indent } = prettyIndent(opts.prettify);
|
|
722
762
|
const coreFormat = format === "pojo" ? "json" : format;
|
|
723
|
-
const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true);
|
|
763
|
+
const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true, "");
|
|
724
764
|
this.throwOnError(out);
|
|
725
765
|
if (format === "pojo") return JSON.parse(out);
|
|
726
766
|
return out;
|
|
@@ -1303,7 +1343,7 @@ var bitTypeCache;
|
|
|
1303
1343
|
function loadBitTypes() {
|
|
1304
1344
|
if (!bitTypeCache) {
|
|
1305
1345
|
const wasm = getLegacyWasm();
|
|
1306
|
-
const all = JSON.parse(wasm.info("all", "json", "", false, 2, true, false, false));
|
|
1346
|
+
const all = JSON.parse(wasm.info("all", "json", "", false, 2, true, false, false, ""));
|
|
1307
1347
|
const map = { _standard: "_standard" };
|
|
1308
1348
|
for (const { name } of all) {
|
|
1309
1349
|
map[bitNameToKey(name)] = name;
|
|
@@ -1374,6 +1414,7 @@ var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
|
|
|
1374
1414
|
function patchEntry(path2, op, value) {
|
|
1375
1415
|
return value === void 0 ? { path: path2, op } : { path: path2, op, value };
|
|
1376
1416
|
}
|
|
1417
|
+
var ALL_LANGUAGES = "all";
|
|
1377
1418
|
|
|
1378
1419
|
// src/core/api.ts
|
|
1379
1420
|
function lex(input, options = {}) {
|
|
@@ -1462,6 +1503,26 @@ function transform(input, options = {}) {
|
|
|
1462
1503
|
options.spacesAroundValues ?? 1
|
|
1463
1504
|
);
|
|
1464
1505
|
}
|
|
1506
|
+
function diff(a, b, options = {}) {
|
|
1507
|
+
const wasm = getActive();
|
|
1508
|
+
if (typeof wasm.diff !== "function") throw new UnsupportedFeatureError("diff", variant());
|
|
1509
|
+
const out = wasm.diff(
|
|
1510
|
+
a,
|
|
1511
|
+
b,
|
|
1512
|
+
options.inputFormat ?? "auto",
|
|
1513
|
+
options.outputFormat ?? "bitmark",
|
|
1514
|
+
options.context ?? 3,
|
|
1515
|
+
options.locate ?? false,
|
|
1516
|
+
options.similarity ?? 0.6,
|
|
1517
|
+
options.bboxTolerance ?? 8,
|
|
1518
|
+
options.spacesAroundValues ?? 0
|
|
1519
|
+
);
|
|
1520
|
+
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1521
|
+
return out;
|
|
1522
|
+
}
|
|
1523
|
+
function diffBits(a, b, options = {}) {
|
|
1524
|
+
return JSON.parse(diff(a, b, { ...options, outputFormat: "json" }));
|
|
1525
|
+
}
|
|
1465
1526
|
function breakscapeText(input, options = {}) {
|
|
1466
1527
|
const format = options.format ?? "bitmark++";
|
|
1467
1528
|
const location = options.location ?? "body";
|
|
@@ -1481,41 +1542,66 @@ function info(options = {}) {
|
|
|
1481
1542
|
const includeDeprecated = options.includeDeprecated ?? false;
|
|
1482
1543
|
const onlyDeprecated = options.onlyDeprecated ?? false;
|
|
1483
1544
|
const full = options.full ?? false;
|
|
1484
|
-
|
|
1545
|
+
const language = typeof options.language === "string" ? options.language : options.language?.join(",") ?? "";
|
|
1546
|
+
return getActive().info(
|
|
1547
|
+
infoType,
|
|
1548
|
+
format,
|
|
1549
|
+
bit,
|
|
1550
|
+
pretty,
|
|
1551
|
+
indent,
|
|
1552
|
+
includeDeprecated,
|
|
1553
|
+
onlyDeprecated,
|
|
1554
|
+
full,
|
|
1555
|
+
language
|
|
1556
|
+
);
|
|
1557
|
+
}
|
|
1558
|
+
function register(options) {
|
|
1559
|
+
const result = getActive().register(options.type, options.data);
|
|
1560
|
+
if (result) throw new RegisterError(result.replace(/^error:\s*/, ""));
|
|
1561
|
+
rememberRegistration(options.type, options.data);
|
|
1485
1562
|
}
|
|
1486
1563
|
|
|
1487
1564
|
// src/index.ts
|
|
1488
1565
|
var require2 = createRequire(import.meta.url);
|
|
1489
1566
|
var VARIANT_GLUE = {
|
|
1490
1567
|
full: "../wasm/bitmark_wasm.js",
|
|
1568
|
+
"browser-full": "../wasm-browser-full/bitmark_browser_full_wasm.js",
|
|
1491
1569
|
"bitmark-json": "../wasm-bitmark-json/bitmark_json_wasm.js"
|
|
1492
1570
|
};
|
|
1493
1571
|
function loadVariant(feature) {
|
|
1494
1572
|
const module = require2(VARIANT_GLUE[feature]);
|
|
1495
1573
|
setActive(feature, module);
|
|
1496
1574
|
}
|
|
1497
|
-
setLazyLoader(() => loadVariant(
|
|
1575
|
+
setLazyLoader(() => loadVariant(NODE_DEFAULT_FEATURE));
|
|
1498
1576
|
async function init(options = {}) {
|
|
1499
|
-
loadVariant(options.feature ??
|
|
1577
|
+
loadVariant(options.feature ?? NODE_DEFAULT_FEATURE);
|
|
1500
1578
|
}
|
|
1501
1579
|
function initSync(options = {}) {
|
|
1502
|
-
loadVariant(options.feature ??
|
|
1580
|
+
loadVariant(options.feature ?? NODE_DEFAULT_FEATURE);
|
|
1503
1581
|
}
|
|
1504
1582
|
initLegacyNode(() => getActive());
|
|
1505
1583
|
function version() {
|
|
1506
1584
|
return PACKAGE_INFO.version;
|
|
1507
1585
|
}
|
|
1508
1586
|
function transformParallel(input, options = {}) {
|
|
1509
|
-
return runParallelTransform(
|
|
1587
|
+
return runParallelTransform(
|
|
1588
|
+
getActive(),
|
|
1589
|
+
input,
|
|
1590
|
+
options
|
|
1591
|
+
);
|
|
1510
1592
|
}
|
|
1511
1593
|
export {
|
|
1594
|
+
ALL_LANGUAGES,
|
|
1512
1595
|
NotInitializedError,
|
|
1596
|
+
RegisterError,
|
|
1513
1597
|
UnsupportedFeatureError,
|
|
1514
1598
|
bitmarkToObjects,
|
|
1515
1599
|
breakscapeText,
|
|
1516
1600
|
canonicalize,
|
|
1517
1601
|
convert,
|
|
1518
1602
|
countBits,
|
|
1603
|
+
diff,
|
|
1604
|
+
diffBits,
|
|
1519
1605
|
info,
|
|
1520
1606
|
init,
|
|
1521
1607
|
initSync,
|
|
@@ -1523,6 +1609,7 @@ export {
|
|
|
1523
1609
|
lex,
|
|
1524
1610
|
objectsToBitmark,
|
|
1525
1611
|
patchEntry,
|
|
1612
|
+
register,
|
|
1526
1613
|
splitBits,
|
|
1527
1614
|
transform,
|
|
1528
1615
|
transformParallel,
|