@gmb/bitmark-parser 6.11.0 → 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 +97 -5
- 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 +186 -24
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +146 -7
- package/dist/browser/esm/index.d.ts +146 -7
- package/dist/browser/esm/index.js +184 -24
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +113 -0
- 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 +73 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +146 -7
- package/dist/index.d.ts +146 -7
- package/dist/index.js +71 -24
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +1 -1
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.js +1 -1
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +7 -7
- package/schema/bitmark.schema.json +1 -1
- package/wasm/bitmark_wasm.d.ts +23 -0
- package/wasm/bitmark_wasm.js +80 -0
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +2 -0
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +9 -0
- package/wasm-bitmark-json/bitmark_json_wasm.js +32 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +1 -0
- package/wasm-bitmark-json/package.json +1 -1
- package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +23 -0
- package/wasm-browser-full/bitmark_browser_full_wasm.js +80 -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 +2 -0
- package/wasm-browser-full/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -39,6 +39,8 @@ __export(src_exports, {
|
|
|
39
39
|
canonicalize: () => canonicalize,
|
|
40
40
|
convert: () => convert,
|
|
41
41
|
countBits: () => countBits,
|
|
42
|
+
diff: () => diff,
|
|
43
|
+
diffBits: () => diffBits,
|
|
42
44
|
info: () => info,
|
|
43
45
|
init: () => init,
|
|
44
46
|
initSync: () => initSync,
|
|
@@ -66,7 +68,7 @@ var import_node_module = require("module");
|
|
|
66
68
|
// src/generated/package_info.ts
|
|
67
69
|
var PACKAGE_INFO = {
|
|
68
70
|
"name": "@gmb/bitmark-parser",
|
|
69
|
-
"version": "6.11.
|
|
71
|
+
"version": "6.11.1",
|
|
70
72
|
"author": "Get More Brain Ltd <info@getmorebrain.com>",
|
|
71
73
|
"license": "ISC",
|
|
72
74
|
"description": "A parser for bitmark text, powered by WebAssembly."
|
|
@@ -133,13 +135,10 @@ function stripArray(doc) {
|
|
|
133
135
|
const t = doc.trim();
|
|
134
136
|
return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
|
|
135
137
|
}
|
|
136
|
-
function
|
|
137
|
-
if (patch === void 0) return
|
|
138
|
-
if (typeof patch === "string")
|
|
139
|
-
|
|
140
|
-
return trimmed === "" ? [] : JSON.parse(trimmed);
|
|
141
|
-
}
|
|
142
|
-
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);
|
|
143
142
|
}
|
|
144
143
|
function buildUnits(wasm, input, inputIsBitmark) {
|
|
145
144
|
if (inputIsBitmark) {
|
|
@@ -169,28 +168,56 @@ function planTransform(wasm, input, options) {
|
|
|
169
168
|
const sel = options.inputFormat ?? "auto";
|
|
170
169
|
const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
|
|
171
170
|
const inputFormat = inputIsBitmark ? "bitmark" : "json";
|
|
172
|
-
const staticPatch = normalisePatch(options.patch);
|
|
173
171
|
const units = buildUnits(wasm, input, inputIsBitmark);
|
|
174
172
|
const total = units.length;
|
|
175
|
-
const
|
|
176
|
-
const views = [];
|
|
173
|
+
const hooked = [];
|
|
177
174
|
for (let index = 0; index < total; index++) {
|
|
178
|
-
const { view
|
|
175
|
+
const { view } = units[index];
|
|
179
176
|
view.index = index;
|
|
180
177
|
view.total = total;
|
|
181
178
|
const result = options.preHook ? options.preHook(view) || {} : {};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
+
}
|
|
194
221
|
}
|
|
195
222
|
return { jobs, views, output, pretty, indent };
|
|
196
223
|
}
|
|
@@ -1534,6 +1561,26 @@ function transform(input, options = {}) {
|
|
|
1534
1561
|
options.spacesAroundValues ?? 1
|
|
1535
1562
|
);
|
|
1536
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
|
+
}
|
|
1537
1584
|
function breakscapeText(input, options = {}) {
|
|
1538
1585
|
const format = options.format ?? "bitmark++";
|
|
1539
1586
|
const location = options.location ?? "body";
|
|
@@ -1612,6 +1659,8 @@ function transformParallel(input, options = {}) {
|
|
|
1612
1659
|
canonicalize,
|
|
1613
1660
|
convert,
|
|
1614
1661
|
countBits,
|
|
1662
|
+
diff,
|
|
1663
|
+
diffBits,
|
|
1615
1664
|
info,
|
|
1616
1665
|
init,
|
|
1617
1666
|
initSync,
|