@gmb/bitmark-parser 7.2.0 → 7.4.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 +163 -23
- package/config/bitmark-json.tsp +439 -0
- package/config/bitmark.json +85074 -0
- package/dist/browser/bitmark-parser.min.js +6 -4
- package/dist/browser/bitmark-parser.min.js.map +1 -1
- package/dist/browser/cjs/index.cjs +140 -72
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +6299 -6806
- package/dist/browser/esm/index.d.ts +6299 -6806
- package/dist/browser/esm/index.js +139 -72
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +86 -57
- 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 +76 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6299 -6806
- package/dist/index.d.ts +6299 -6806
- package/dist/index.js +75 -29
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +4 -3
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.d.cts +9 -1
- package/dist/legacy.d.ts +9 -1
- package/dist/legacy.js +4 -3
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs +23 -15
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +11 -7
- package/schema/bitmark.schema.json +10459 -14050
- package/wasm/bitmark_wasm.d.ts +12 -3
- package/wasm/bitmark_wasm.js +34 -15
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +2 -2
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +12 -3
- package/wasm-bitmark-json/bitmark_json_wasm.js +34 -15
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +2 -2
- package/wasm-bitmark-json/package.json +1 -1
- package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +12 -3
- package/wasm-browser-full/bitmark_browser_full_wasm.js +34 -15
- 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 -2
- package/wasm-browser-full/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": "7.
|
|
13
|
+
"version": "7.4.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."
|
|
@@ -30,6 +30,18 @@ var RegisterError = class extends Error {
|
|
|
30
30
|
this.name = "RegisterError";
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
+
var PatchError = class extends Error {
|
|
34
|
+
diagnostics;
|
|
35
|
+
constructor(diagnostics2) {
|
|
36
|
+
const lines = diagnostics2.map((d) => `${d.kind} at ${d.path}: ${d.message}`);
|
|
37
|
+
super(
|
|
38
|
+
`${diagnostics2.length} patch ${diagnostics2.length === 1 ? "entry was" : "entries were"} skipped:
|
|
39
|
+
` + lines.join("\n")
|
|
40
|
+
);
|
|
41
|
+
this.name = "PatchError";
|
|
42
|
+
this.diagnostics = diagnostics2;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
33
45
|
var UnsupportedFeatureError = class extends Error {
|
|
34
46
|
constructor(what, active2) {
|
|
35
47
|
super(
|
|
@@ -139,6 +151,18 @@ function planTransform(wasm, input, options) {
|
|
|
139
151
|
spacesAroundValues
|
|
140
152
|
});
|
|
141
153
|
views.push(units[item.source].view);
|
|
154
|
+
} else if (typeof item.bit === "string") {
|
|
155
|
+
const index = jobs.length;
|
|
156
|
+
jobs.push({
|
|
157
|
+
index,
|
|
158
|
+
source: item.bit,
|
|
159
|
+
inputFormat: "bitmark",
|
|
160
|
+
outputFormat: output,
|
|
161
|
+
mode,
|
|
162
|
+
patchJson: JSON.stringify(item.patch),
|
|
163
|
+
spacesAroundValues
|
|
164
|
+
});
|
|
165
|
+
views.push({ format: "bitmark", index, total, source: item.bit });
|
|
142
166
|
} else {
|
|
143
167
|
const bit = item.bit ?? {};
|
|
144
168
|
const index = jobs.length;
|
|
@@ -156,18 +180,24 @@ function planTransform(wasm, input, options) {
|
|
|
156
180
|
}
|
|
157
181
|
return { jobs, views, output, pretty, indent };
|
|
158
182
|
}
|
|
183
|
+
function bitOutput(envelopeJson, outputFormat) {
|
|
184
|
+
const { data, diagnostics: diagnostics2 } = JSON.parse(envelopeJson);
|
|
185
|
+
return { element: outputFormat === "json" ? stripArray(data) : data, diagnostics: diagnostics2 };
|
|
186
|
+
}
|
|
159
187
|
function computeBit(wasm, job) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
188
|
+
return bitOutput(
|
|
189
|
+
wasm.transform(
|
|
190
|
+
job.source,
|
|
191
|
+
job.inputFormat,
|
|
192
|
+
job.outputFormat,
|
|
193
|
+
job.mode,
|
|
194
|
+
job.patchJson,
|
|
195
|
+
false,
|
|
196
|
+
2,
|
|
197
|
+
job.spacesAroundValues
|
|
198
|
+
),
|
|
199
|
+
job.outputFormat
|
|
169
200
|
);
|
|
170
|
-
return job.outputFormat === "json" ? stripArray(out) : out;
|
|
171
201
|
}
|
|
172
202
|
function recombine(wasm, elements, output, pretty, indent) {
|
|
173
203
|
if (output !== "json") return elements.join("\n");
|
|
@@ -177,21 +207,29 @@ function recombine(wasm, elements, output, pretty, indent) {
|
|
|
177
207
|
function runHookedTransform(wasm, input, options) {
|
|
178
208
|
const plan = planTransform(wasm, input, options);
|
|
179
209
|
const rendered = [];
|
|
210
|
+
const skipped = [];
|
|
180
211
|
for (let i = 0; i < plan.jobs.length; i++) {
|
|
181
|
-
const element = computeBit(wasm, plan.jobs[i]);
|
|
212
|
+
const { element, diagnostics: diagnostics2 } = computeBit(wasm, plan.jobs[i]);
|
|
213
|
+
skipped.push(...diagnostics2);
|
|
182
214
|
options.postHook?.(plan.views[i], element);
|
|
183
215
|
rendered.push(element);
|
|
184
216
|
}
|
|
217
|
+
if (skipped.length > 0) throw new PatchError(skipped);
|
|
185
218
|
return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);
|
|
186
219
|
}
|
|
187
220
|
|
|
188
221
|
// src/core/parallel.ts
|
|
189
222
|
async function orchestrateParallel(wasm, input, options, runJobs) {
|
|
190
223
|
const plan = planTransform(wasm, input, options);
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
|
|
224
|
+
const outputs = await runJobs(plan.jobs, options.workers ?? 4);
|
|
225
|
+
const elements = [];
|
|
226
|
+
const skipped = [];
|
|
227
|
+
for (let i = 0; i < outputs.length; i++) {
|
|
228
|
+
elements.push(outputs[i].element);
|
|
229
|
+
skipped.push(...outputs[i].diagnostics);
|
|
230
|
+
options.postHook?.(plan.views[i], outputs[i].element);
|
|
194
231
|
}
|
|
232
|
+
if (skipped.length > 0) throw new PatchError(skipped);
|
|
195
233
|
return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
|
|
196
234
|
}
|
|
197
235
|
|
|
@@ -225,7 +263,7 @@ function runJobsWithPool(jobs, workers, spawn) {
|
|
|
225
263
|
const w = spawn((res) => {
|
|
226
264
|
if (done) return;
|
|
227
265
|
if (!res.ok) return finish(new Error(res.error ?? "worker job failed"));
|
|
228
|
-
results[res.id] = res.element;
|
|
266
|
+
results[res.id] = { element: res.element, diagnostics: res.diagnostics ?? [] };
|
|
229
267
|
if (++settled === jobs.length) finish();
|
|
230
268
|
else dispatch(w);
|
|
231
269
|
}, finish);
|
|
@@ -622,7 +660,7 @@ var Builder = class {
|
|
|
622
660
|
}
|
|
623
661
|
/**
|
|
624
662
|
* Look up the bit's config (`wasm.info`); throws bpg's exact
|
|
625
|
-
*
|
|
663
|
+
* bit-type-invalid error (`Config.getBitConfig` parity).
|
|
626
664
|
*/
|
|
627
665
|
getBitConfig(bitType) {
|
|
628
666
|
const wasm = getLegacyWasm();
|
|
@@ -1199,7 +1237,8 @@ var BodyTextFormat = {
|
|
|
1199
1237
|
};
|
|
1200
1238
|
var TextLocation = {
|
|
1201
1239
|
tag: "tag",
|
|
1202
|
-
body: "body"
|
|
1240
|
+
body: "body",
|
|
1241
|
+
cardBody: "cardBody"
|
|
1203
1242
|
};
|
|
1204
1243
|
|
|
1205
1244
|
// src/legacy/enums-extra.ts
|
|
@@ -1511,16 +1550,20 @@ function transform(input, options = {}) {
|
|
|
1511
1550
|
return runHookedTransform(wasm, input, options);
|
|
1512
1551
|
}
|
|
1513
1552
|
const patchJson = options.patch === void 0 ? "" : typeof options.patch === "string" ? options.patch : JSON.stringify(options.patch);
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1553
|
+
const { data, diagnostics: diagnostics2 } = JSON.parse(
|
|
1554
|
+
wasm.transform(
|
|
1555
|
+
input,
|
|
1556
|
+
options.inputFormat ?? "auto",
|
|
1557
|
+
options.outputFormat ?? "json",
|
|
1558
|
+
options.mode ?? "optimized",
|
|
1559
|
+
patchJson,
|
|
1560
|
+
options.pretty ?? false,
|
|
1561
|
+
options.indent ?? 2,
|
|
1562
|
+
options.spacesAroundValues ?? 1
|
|
1563
|
+
)
|
|
1523
1564
|
);
|
|
1565
|
+
if (diagnostics2.length > 0) throw new PatchError(diagnostics2);
|
|
1566
|
+
return data;
|
|
1524
1567
|
}
|
|
1525
1568
|
function diff(a, b, options = {}) {
|
|
1526
1569
|
const wasm = getActive();
|
|
@@ -1544,12 +1587,14 @@ function diffBits(a, b, options = {}) {
|
|
|
1544
1587
|
function breakscapeText(input, options = {}) {
|
|
1545
1588
|
const format = options.format ?? "bitmark++";
|
|
1546
1589
|
const location = options.location ?? "body";
|
|
1547
|
-
|
|
1590
|
+
const subLocation = options.subLocation ?? "text";
|
|
1591
|
+
return getActive().breakscape_text(input, format, location, subLocation);
|
|
1548
1592
|
}
|
|
1549
1593
|
function unbreakscapeText(input, options = {}) {
|
|
1550
1594
|
const format = options.format ?? "bitmark++";
|
|
1551
1595
|
const location = options.location ?? "body";
|
|
1552
|
-
|
|
1596
|
+
const subLocation = options.subLocation ?? "text";
|
|
1597
|
+
return getActive().unbreakscape_text(input, format, location, subLocation);
|
|
1553
1598
|
}
|
|
1554
1599
|
function info(options = {}) {
|
|
1555
1600
|
const infoType = options.infoType ?? "list";
|
|
@@ -1621,6 +1666,7 @@ export {
|
|
|
1621
1666
|
CompletionItemTag,
|
|
1622
1667
|
DiagnosticSeverity,
|
|
1623
1668
|
NotInitializedError,
|
|
1669
|
+
PatchError,
|
|
1624
1670
|
RegisterError,
|
|
1625
1671
|
UnsupportedFeatureError,
|
|
1626
1672
|
bitmarkToObjects,
|