@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.cjs
CHANGED
|
@@ -30,13 +30,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
+
ALL_LANGUAGES: () => ALL_LANGUAGES,
|
|
33
34
|
NotInitializedError: () => NotInitializedError,
|
|
35
|
+
RegisterError: () => RegisterError,
|
|
34
36
|
UnsupportedFeatureError: () => UnsupportedFeatureError,
|
|
35
37
|
bitmarkToObjects: () => bitmarkToObjects,
|
|
36
38
|
breakscapeText: () => breakscapeText,
|
|
37
39
|
canonicalize: () => canonicalize,
|
|
38
40
|
convert: () => convert,
|
|
39
41
|
countBits: () => countBits,
|
|
42
|
+
diff: () => diff,
|
|
43
|
+
diffBits: () => diffBits,
|
|
40
44
|
info: () => info,
|
|
41
45
|
init: () => init,
|
|
42
46
|
initSync: () => initSync,
|
|
@@ -44,6 +48,7 @@ __export(src_exports, {
|
|
|
44
48
|
lex: () => lex,
|
|
45
49
|
objectsToBitmark: () => objectsToBitmark,
|
|
46
50
|
patchEntry: () => patchEntry,
|
|
51
|
+
register: () => register,
|
|
47
52
|
splitBits: () => splitBits,
|
|
48
53
|
transform: () => transform,
|
|
49
54
|
transformParallel: () => transformParallel,
|
|
@@ -63,19 +68,26 @@ var import_node_module = require("module");
|
|
|
63
68
|
// src/generated/package_info.ts
|
|
64
69
|
var PACKAGE_INFO = {
|
|
65
70
|
"name": "@gmb/bitmark-parser",
|
|
66
|
-
"version": "6.
|
|
71
|
+
"version": "6.11.1",
|
|
67
72
|
"author": "Get More Brain Ltd <info@getmorebrain.com>",
|
|
68
73
|
"license": "ISC",
|
|
69
74
|
"description": "A parser for bitmark text, powered by WebAssembly."
|
|
70
75
|
};
|
|
71
76
|
|
|
72
77
|
// src/core/facade.ts
|
|
78
|
+
var NODE_DEFAULT_FEATURE = "full";
|
|
73
79
|
var NotInitializedError = class extends Error {
|
|
74
80
|
constructor() {
|
|
75
81
|
super("wasm not initialised: call init() (or init({ feature: \u2026 })) first");
|
|
76
82
|
this.name = "NotInitializedError";
|
|
77
83
|
}
|
|
78
84
|
};
|
|
85
|
+
var RegisterError = class extends Error {
|
|
86
|
+
constructor(message) {
|
|
87
|
+
super(message);
|
|
88
|
+
this.name = "RegisterError";
|
|
89
|
+
}
|
|
90
|
+
};
|
|
79
91
|
var UnsupportedFeatureError = class extends Error {
|
|
80
92
|
constructor(what, active2) {
|
|
81
93
|
super(
|
|
@@ -87,15 +99,23 @@ var UnsupportedFeatureError = class extends Error {
|
|
|
87
99
|
var active;
|
|
88
100
|
var activeFeature;
|
|
89
101
|
var lazyLoader;
|
|
102
|
+
var registrations = /* @__PURE__ */ new Map();
|
|
90
103
|
function getActive() {
|
|
91
104
|
if (!active && lazyLoader) lazyLoader();
|
|
92
105
|
if (!active) throw new NotInitializedError();
|
|
93
106
|
return active;
|
|
94
107
|
}
|
|
95
108
|
function setActive(feature, module2) {
|
|
109
|
+
for (const [type, data] of registrations) {
|
|
110
|
+
const error = module2.register(type, data);
|
|
111
|
+
if (error) throw new RegisterError(error.replace(/^error:\s*/, ""));
|
|
112
|
+
}
|
|
96
113
|
active = module2;
|
|
97
114
|
activeFeature = feature;
|
|
98
115
|
}
|
|
116
|
+
function rememberRegistration(type, data) {
|
|
117
|
+
registrations.set(type, data);
|
|
118
|
+
}
|
|
99
119
|
function setLazyLoader(loader) {
|
|
100
120
|
lazyLoader = loader;
|
|
101
121
|
}
|
|
@@ -115,13 +135,10 @@ function stripArray(doc) {
|
|
|
115
135
|
const t = doc.trim();
|
|
116
136
|
return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
|
|
117
137
|
}
|
|
118
|
-
function
|
|
119
|
-
if (patch === void 0) return
|
|
120
|
-
if (typeof patch === "string")
|
|
121
|
-
|
|
122
|
-
return trimmed === "" ? [] : JSON.parse(trimmed);
|
|
123
|
-
}
|
|
124
|
-
return patch;
|
|
138
|
+
function patchJsonOf(patch) {
|
|
139
|
+
if (patch === void 0) return "";
|
|
140
|
+
if (typeof patch === "string") return patch.trim();
|
|
141
|
+
return JSON.stringify(patch);
|
|
125
142
|
}
|
|
126
143
|
function buildUnits(wasm, input, inputIsBitmark) {
|
|
127
144
|
if (inputIsBitmark) {
|
|
@@ -151,28 +168,56 @@ function planTransform(wasm, input, options) {
|
|
|
151
168
|
const sel = options.inputFormat ?? "auto";
|
|
152
169
|
const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
|
|
153
170
|
const inputFormat = inputIsBitmark ? "bitmark" : "json";
|
|
154
|
-
const staticPatch = normalisePatch(options.patch);
|
|
155
171
|
const units = buildUnits(wasm, input, inputIsBitmark);
|
|
156
172
|
const total = units.length;
|
|
157
|
-
const
|
|
158
|
-
const views = [];
|
|
173
|
+
const hooked = [];
|
|
159
174
|
for (let index = 0; index < total; index++) {
|
|
160
|
-
const { view
|
|
175
|
+
const { view } = units[index];
|
|
161
176
|
view.index = index;
|
|
162
177
|
view.total = total;
|
|
163
178
|
const result = options.preHook ? options.preHook(view) || {} : {};
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
hooked.push(result.drop ? null : { patches: result.patches ?? [], outputFormat: result.outputFormat ?? output });
|
|
180
|
+
}
|
|
181
|
+
const patchJson = patchJsonOf(options.patch);
|
|
182
|
+
let resolved;
|
|
183
|
+
if (patchJson === "") {
|
|
184
|
+
resolved = units.map((_, index) => ({ source: index, bit: null, patch: [] }));
|
|
185
|
+
} else {
|
|
186
|
+
const out = wasm.resolve_patch_document(input, patchJson);
|
|
187
|
+
if (isError(out)) throw new Error(out);
|
|
188
|
+
resolved = JSON.parse(out);
|
|
189
|
+
}
|
|
190
|
+
const jobs = [];
|
|
191
|
+
const views = [];
|
|
192
|
+
for (const item of resolved) {
|
|
193
|
+
if (item.source !== null) {
|
|
194
|
+
const hook = hooked[item.source];
|
|
195
|
+
if (!hook) continue;
|
|
196
|
+
jobs.push({
|
|
197
|
+
index: item.source,
|
|
198
|
+
source: units[item.source].source,
|
|
199
|
+
inputFormat,
|
|
200
|
+
outputFormat: hook.outputFormat,
|
|
201
|
+
mode,
|
|
202
|
+
// The document's patches first, the hook's after (the hook contract).
|
|
203
|
+
patchJson: JSON.stringify([...item.patch, ...hook.patches]),
|
|
204
|
+
spacesAroundValues
|
|
205
|
+
});
|
|
206
|
+
views.push(units[item.source].view);
|
|
207
|
+
} else {
|
|
208
|
+
const bit = item.bit ?? {};
|
|
209
|
+
const index = jobs.length;
|
|
210
|
+
jobs.push({
|
|
211
|
+
index,
|
|
212
|
+
source: JSON.stringify([{ bit }]),
|
|
213
|
+
inputFormat: "json",
|
|
214
|
+
outputFormat: output,
|
|
215
|
+
mode,
|
|
216
|
+
patchJson: JSON.stringify(item.patch),
|
|
217
|
+
spacesAroundValues
|
|
218
|
+
});
|
|
219
|
+
views.push({ format: "json", index, total, bit });
|
|
220
|
+
}
|
|
176
221
|
}
|
|
177
222
|
return { jobs, views, output, pretty, indent };
|
|
178
223
|
}
|
|
@@ -674,7 +719,7 @@ var Builder = class {
|
|
|
674
719
|
const wasm = getLegacyWasm();
|
|
675
720
|
if (bitType !== void 0) {
|
|
676
721
|
try {
|
|
677
|
-
const info2 = JSON.parse(wasm.info("bit", "json", bitType, false, 2, false, false, true));
|
|
722
|
+
const info2 = JSON.parse(wasm.info("bit", "json", bitType, false, 2, false, false, true, ""));
|
|
678
723
|
if (info2.error === void 0) return { bodyFormat: info2.body?.format };
|
|
679
724
|
} catch {
|
|
680
725
|
}
|
|
@@ -773,7 +818,7 @@ var BitmarkParserGenerator = class {
|
|
|
773
818
|
const format = opts.outputFormat ?? "text";
|
|
774
819
|
const { pretty, indent } = prettyIndent(opts.prettify);
|
|
775
820
|
const coreFormat = format === "pojo" ? "json" : format;
|
|
776
|
-
const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true);
|
|
821
|
+
const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true, "");
|
|
777
822
|
this.throwOnError(out);
|
|
778
823
|
if (format === "pojo") return JSON.parse(out);
|
|
779
824
|
return out;
|
|
@@ -1356,7 +1401,7 @@ var bitTypeCache;
|
|
|
1356
1401
|
function loadBitTypes() {
|
|
1357
1402
|
if (!bitTypeCache) {
|
|
1358
1403
|
const wasm = getLegacyWasm();
|
|
1359
|
-
const all = JSON.parse(wasm.info("all", "json", "", false, 2, true, false, false));
|
|
1404
|
+
const all = JSON.parse(wasm.info("all", "json", "", false, 2, true, false, false, ""));
|
|
1360
1405
|
const map = { _standard: "_standard" };
|
|
1361
1406
|
for (const { name } of all) {
|
|
1362
1407
|
map[bitNameToKey(name)] = name;
|
|
@@ -1427,6 +1472,7 @@ var StreamWriter = stubClass("StreamWriter", INTERNAL_REASON);
|
|
|
1427
1472
|
function patchEntry(path2, op, value) {
|
|
1428
1473
|
return value === void 0 ? { path: path2, op } : { path: path2, op, value };
|
|
1429
1474
|
}
|
|
1475
|
+
var ALL_LANGUAGES = "all";
|
|
1430
1476
|
|
|
1431
1477
|
// src/core/api.ts
|
|
1432
1478
|
function lex(input, options = {}) {
|
|
@@ -1515,6 +1561,26 @@ function transform(input, options = {}) {
|
|
|
1515
1561
|
options.spacesAroundValues ?? 1
|
|
1516
1562
|
);
|
|
1517
1563
|
}
|
|
1564
|
+
function diff(a, b, options = {}) {
|
|
1565
|
+
const wasm = getActive();
|
|
1566
|
+
if (typeof wasm.diff !== "function") throw new UnsupportedFeatureError("diff", variant());
|
|
1567
|
+
const out = wasm.diff(
|
|
1568
|
+
a,
|
|
1569
|
+
b,
|
|
1570
|
+
options.inputFormat ?? "auto",
|
|
1571
|
+
options.outputFormat ?? "bitmark",
|
|
1572
|
+
options.context ?? 3,
|
|
1573
|
+
options.locate ?? false,
|
|
1574
|
+
options.similarity ?? 0.6,
|
|
1575
|
+
options.bboxTolerance ?? 8,
|
|
1576
|
+
options.spacesAroundValues ?? 0
|
|
1577
|
+
);
|
|
1578
|
+
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1579
|
+
return out;
|
|
1580
|
+
}
|
|
1581
|
+
function diffBits(a, b, options = {}) {
|
|
1582
|
+
return JSON.parse(diff(a, b, { ...options, outputFormat: "json" }));
|
|
1583
|
+
}
|
|
1518
1584
|
function breakscapeText(input, options = {}) {
|
|
1519
1585
|
const format = options.format ?? "bitmark++";
|
|
1520
1586
|
const location = options.location ?? "body";
|
|
@@ -1534,42 +1600,67 @@ function info(options = {}) {
|
|
|
1534
1600
|
const includeDeprecated = options.includeDeprecated ?? false;
|
|
1535
1601
|
const onlyDeprecated = options.onlyDeprecated ?? false;
|
|
1536
1602
|
const full = options.full ?? false;
|
|
1537
|
-
|
|
1603
|
+
const language = typeof options.language === "string" ? options.language : options.language?.join(",") ?? "";
|
|
1604
|
+
return getActive().info(
|
|
1605
|
+
infoType,
|
|
1606
|
+
format,
|
|
1607
|
+
bit,
|
|
1608
|
+
pretty,
|
|
1609
|
+
indent,
|
|
1610
|
+
includeDeprecated,
|
|
1611
|
+
onlyDeprecated,
|
|
1612
|
+
full,
|
|
1613
|
+
language
|
|
1614
|
+
);
|
|
1615
|
+
}
|
|
1616
|
+
function register(options) {
|
|
1617
|
+
const result = getActive().register(options.type, options.data);
|
|
1618
|
+
if (result) throw new RegisterError(result.replace(/^error:\s*/, ""));
|
|
1619
|
+
rememberRegistration(options.type, options.data);
|
|
1538
1620
|
}
|
|
1539
1621
|
|
|
1540
1622
|
// src/index.ts
|
|
1541
1623
|
var require2 = (0, import_node_module.createRequire)(importMetaUrl);
|
|
1542
1624
|
var VARIANT_GLUE = {
|
|
1543
1625
|
full: "../wasm/bitmark_wasm.js",
|
|
1626
|
+
"browser-full": "../wasm-browser-full/bitmark_browser_full_wasm.js",
|
|
1544
1627
|
"bitmark-json": "../wasm-bitmark-json/bitmark_json_wasm.js"
|
|
1545
1628
|
};
|
|
1546
1629
|
function loadVariant(feature) {
|
|
1547
1630
|
const module2 = require2(VARIANT_GLUE[feature]);
|
|
1548
1631
|
setActive(feature, module2);
|
|
1549
1632
|
}
|
|
1550
|
-
setLazyLoader(() => loadVariant(
|
|
1633
|
+
setLazyLoader(() => loadVariant(NODE_DEFAULT_FEATURE));
|
|
1551
1634
|
async function init(options = {}) {
|
|
1552
|
-
loadVariant(options.feature ??
|
|
1635
|
+
loadVariant(options.feature ?? NODE_DEFAULT_FEATURE);
|
|
1553
1636
|
}
|
|
1554
1637
|
function initSync(options = {}) {
|
|
1555
|
-
loadVariant(options.feature ??
|
|
1638
|
+
loadVariant(options.feature ?? NODE_DEFAULT_FEATURE);
|
|
1556
1639
|
}
|
|
1557
1640
|
initLegacyNode(() => getActive());
|
|
1558
1641
|
function version() {
|
|
1559
1642
|
return PACKAGE_INFO.version;
|
|
1560
1643
|
}
|
|
1561
1644
|
function transformParallel(input, options = {}) {
|
|
1562
|
-
return runParallelTransform(
|
|
1645
|
+
return runParallelTransform(
|
|
1646
|
+
getActive(),
|
|
1647
|
+
input,
|
|
1648
|
+
options
|
|
1649
|
+
);
|
|
1563
1650
|
}
|
|
1564
1651
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1565
1652
|
0 && (module.exports = {
|
|
1653
|
+
ALL_LANGUAGES,
|
|
1566
1654
|
NotInitializedError,
|
|
1655
|
+
RegisterError,
|
|
1567
1656
|
UnsupportedFeatureError,
|
|
1568
1657
|
bitmarkToObjects,
|
|
1569
1658
|
breakscapeText,
|
|
1570
1659
|
canonicalize,
|
|
1571
1660
|
convert,
|
|
1572
1661
|
countBits,
|
|
1662
|
+
diff,
|
|
1663
|
+
diffBits,
|
|
1573
1664
|
info,
|
|
1574
1665
|
init,
|
|
1575
1666
|
initSync,
|
|
@@ -1577,6 +1668,7 @@ function transformParallel(input, options = {}) {
|
|
|
1577
1668
|
lex,
|
|
1578
1669
|
objectsToBitmark,
|
|
1579
1670
|
patchEntry,
|
|
1671
|
+
register,
|
|
1580
1672
|
splitBits,
|
|
1581
1673
|
transform,
|
|
1582
1674
|
transformParallel,
|