@gmb/bitmark-parser 6.11.0 → 7.0.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 +311 -51
- 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 +696 -312
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +487 -74
- package/dist/browser/esm/index.d.ts +487 -74
- package/dist/browser/esm/index.js +693 -311
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +578 -210
- 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 +119 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +487 -74
- package/dist/index.d.ts +487 -74
- package/dist/index.js +116 -106
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +8 -30
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.d.cts +0 -2
- package/dist/legacy.d.ts +0 -2
- package/dist/legacy.js +8 -30
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs +1 -5
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +7 -7
- package/schema/bitmark.schema.json +496 -139
- package/wasm/bitmark_wasm.d.ts +47 -20
- package/wasm/bitmark_wasm.js +262 -96
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +4 -2
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +26 -11
- package/wasm-bitmark-json/bitmark_json_wasm.js +195 -65
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +2 -1
- package/wasm-bitmark-json/package.json +1 -1
- package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +47 -20
- package/wasm-browser-full/bitmark_browser_full_wasm.js +262 -96
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
- package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +4 -2
- package/wasm-browser-full/package.json +1 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/dist/index.cjs
CHANGED
|
@@ -39,14 +39,16 @@ __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,
|
|
45
47
|
legacy: () => legacy_exports,
|
|
46
|
-
lex: () => lex,
|
|
47
48
|
objectsToBitmark: () => objectsToBitmark,
|
|
48
49
|
patchEntry: () => patchEntry,
|
|
49
50
|
register: () => register,
|
|
51
|
+
semanticTokens: () => semanticTokens,
|
|
50
52
|
splitBits: () => splitBits,
|
|
51
53
|
transform: () => transform,
|
|
52
54
|
transformParallel: () => transformParallel,
|
|
@@ -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": "
|
|
71
|
+
"version": "7.0.0",
|
|
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."
|
|
@@ -105,8 +107,11 @@ function getActive() {
|
|
|
105
107
|
}
|
|
106
108
|
function setActive(feature, module2) {
|
|
107
109
|
for (const [type, data] of registrations) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
try {
|
|
111
|
+
module2.register(type, data);
|
|
112
|
+
} catch (e) {
|
|
113
|
+
throw new RegisterError(e instanceof Error ? e.message : String(e));
|
|
114
|
+
}
|
|
110
115
|
}
|
|
111
116
|
active = module2;
|
|
112
117
|
activeFeature = feature;
|
|
@@ -122,38 +127,24 @@ function variant() {
|
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
// src/core/hooked-transform.ts
|
|
125
|
-
function isError(s) {
|
|
126
|
-
return s.startsWith("error:");
|
|
127
|
-
}
|
|
128
|
-
function errorString(e) {
|
|
129
|
-
const m = e instanceof Error ? e.message : String(e);
|
|
130
|
-
return m.startsWith("error:") ? m : `error: ${m}`;
|
|
131
|
-
}
|
|
132
130
|
function stripArray(doc) {
|
|
133
131
|
const t = doc.trim();
|
|
134
132
|
return t.startsWith("[") && t.endsWith("]") ? t.slice(1, -1) : doc;
|
|
135
133
|
}
|
|
136
|
-
function
|
|
137
|
-
if (patch === void 0) return
|
|
138
|
-
if (typeof patch === "string")
|
|
139
|
-
|
|
140
|
-
return trimmed === "" ? [] : JSON.parse(trimmed);
|
|
141
|
-
}
|
|
142
|
-
return patch;
|
|
134
|
+
function patchJsonOf(patch) {
|
|
135
|
+
if (patch === void 0) return "";
|
|
136
|
+
if (typeof patch === "string") return patch.trim();
|
|
137
|
+
return JSON.stringify(patch);
|
|
143
138
|
}
|
|
144
139
|
function buildUnits(wasm, input, inputIsBitmark) {
|
|
145
140
|
if (inputIsBitmark) {
|
|
146
|
-
const
|
|
147
|
-
if (isError(out2)) throw new Error(out2);
|
|
148
|
-
const slices = JSON.parse(out2);
|
|
141
|
+
const slices = JSON.parse(wasm.split_bits(input));
|
|
149
142
|
return slices.map((s) => ({
|
|
150
143
|
view: { format: "bitmark", index: s.index, total: slices.length, source: s.source },
|
|
151
144
|
source: s.source
|
|
152
145
|
}));
|
|
153
146
|
}
|
|
154
|
-
const
|
|
155
|
-
if (isError(out)) throw new Error(out);
|
|
156
|
-
const envelopes = JSON.parse(out);
|
|
147
|
+
const envelopes = JSON.parse(wasm.split_json_bits(input));
|
|
157
148
|
return envelopes.map((env, index) => ({
|
|
158
149
|
view: { format: "json", index, total: envelopes.length, bit: env.bit ?? {} },
|
|
159
150
|
// Per-bit transform consumes a one-bit JSON document.
|
|
@@ -169,28 +160,54 @@ function planTransform(wasm, input, options) {
|
|
|
169
160
|
const sel = options.inputFormat ?? "auto";
|
|
170
161
|
const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
|
|
171
162
|
const inputFormat = inputIsBitmark ? "bitmark" : "json";
|
|
172
|
-
const staticPatch = normalisePatch(options.patch);
|
|
173
163
|
const units = buildUnits(wasm, input, inputIsBitmark);
|
|
174
164
|
const total = units.length;
|
|
175
|
-
const
|
|
176
|
-
const views = [];
|
|
165
|
+
const hooked = [];
|
|
177
166
|
for (let index = 0; index < total; index++) {
|
|
178
|
-
const { view
|
|
167
|
+
const { view } = units[index];
|
|
179
168
|
view.index = index;
|
|
180
169
|
view.total = total;
|
|
181
170
|
const result = options.preHook ? options.preHook(view) || {} : {};
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
171
|
+
hooked.push(result.drop ? null : { patches: result.patches ?? [], outputFormat: result.outputFormat ?? output });
|
|
172
|
+
}
|
|
173
|
+
const patchJson = patchJsonOf(options.patch);
|
|
174
|
+
let resolved;
|
|
175
|
+
if (patchJson === "") {
|
|
176
|
+
resolved = units.map((_, index) => ({ source: index, bit: null, patch: [] }));
|
|
177
|
+
} else {
|
|
178
|
+
resolved = JSON.parse(wasm.resolve_patch_document(input, patchJson));
|
|
179
|
+
}
|
|
180
|
+
const jobs = [];
|
|
181
|
+
const views = [];
|
|
182
|
+
for (const item of resolved) {
|
|
183
|
+
if (item.source !== null) {
|
|
184
|
+
const hook = hooked[item.source];
|
|
185
|
+
if (!hook) continue;
|
|
186
|
+
jobs.push({
|
|
187
|
+
index: item.source,
|
|
188
|
+
source: units[item.source].source,
|
|
189
|
+
inputFormat,
|
|
190
|
+
outputFormat: hook.outputFormat,
|
|
191
|
+
mode,
|
|
192
|
+
// The document's patches first, the hook's after (the hook contract).
|
|
193
|
+
patchJson: JSON.stringify([...item.patch, ...hook.patches]),
|
|
194
|
+
spacesAroundValues
|
|
195
|
+
});
|
|
196
|
+
views.push(units[item.source].view);
|
|
197
|
+
} else {
|
|
198
|
+
const bit = item.bit ?? {};
|
|
199
|
+
const index = jobs.length;
|
|
200
|
+
jobs.push({
|
|
201
|
+
index,
|
|
202
|
+
source: JSON.stringify([{ bit }]),
|
|
203
|
+
inputFormat: "json",
|
|
204
|
+
outputFormat: output,
|
|
205
|
+
mode,
|
|
206
|
+
patchJson: JSON.stringify(item.patch),
|
|
207
|
+
spacesAroundValues
|
|
208
|
+
});
|
|
209
|
+
views.push({ format: "json", index, total, bit });
|
|
210
|
+
}
|
|
194
211
|
}
|
|
195
212
|
return { jobs, views, output, pretty, indent };
|
|
196
213
|
}
|
|
@@ -205,7 +222,6 @@ function computeBit(wasm, job) {
|
|
|
205
222
|
2,
|
|
206
223
|
job.spacesAroundValues
|
|
207
224
|
);
|
|
208
|
-
if (isError(out)) return out;
|
|
209
225
|
return job.outputFormat === "json" ? stripArray(out) : out;
|
|
210
226
|
}
|
|
211
227
|
function recombine(wasm, elements, output, pretty, indent) {
|
|
@@ -214,16 +230,10 @@ function recombine(wasm, elements, output, pretty, indent) {
|
|
|
214
230
|
return pretty ? wasm.prettify(arr, indent) : arr;
|
|
215
231
|
}
|
|
216
232
|
function runHookedTransform(wasm, input, options) {
|
|
217
|
-
|
|
218
|
-
try {
|
|
219
|
-
plan = planTransform(wasm, input, options);
|
|
220
|
-
} catch (e) {
|
|
221
|
-
return errorString(e);
|
|
222
|
-
}
|
|
233
|
+
const plan = planTransform(wasm, input, options);
|
|
223
234
|
const rendered = [];
|
|
224
235
|
for (let i = 0; i < plan.jobs.length; i++) {
|
|
225
236
|
const element = computeBit(wasm, plan.jobs[i]);
|
|
226
|
-
if (isError(element)) return element;
|
|
227
237
|
options.postHook?.(plan.views[i], element);
|
|
228
238
|
rendered.push(element);
|
|
229
239
|
}
|
|
@@ -232,20 +242,9 @@ function runHookedTransform(wasm, input, options) {
|
|
|
232
242
|
|
|
233
243
|
// src/core/parallel.ts
|
|
234
244
|
async function orchestrateParallel(wasm, input, options, runJobs) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
plan = planTransform(wasm, input, options);
|
|
238
|
-
} catch (e) {
|
|
239
|
-
return errorString(e);
|
|
240
|
-
}
|
|
241
|
-
let elements;
|
|
242
|
-
try {
|
|
243
|
-
elements = await runJobs(plan.jobs, options.workers ?? 4);
|
|
244
|
-
} catch (e) {
|
|
245
|
-
return errorString(e);
|
|
246
|
-
}
|
|
245
|
+
const plan = planTransform(wasm, input, options);
|
|
246
|
+
const elements = await runJobs(plan.jobs, options.workers ?? 4);
|
|
247
247
|
for (let i = 0; i < elements.length; i++) {
|
|
248
|
-
if (isError(elements[i])) return elements[i];
|
|
249
248
|
options.postHook?.(plan.views[i], elements[i]);
|
|
250
249
|
}
|
|
251
250
|
return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
|
|
@@ -600,10 +599,7 @@ var Builder = class {
|
|
|
600
599
|
}
|
|
601
600
|
}
|
|
602
601
|
this.parseStringTexts(bit);
|
|
603
|
-
const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false);
|
|
604
|
-
if (out.startsWith("error:")) {
|
|
605
|
-
throw new Error(out.slice("error:".length).trim());
|
|
606
|
-
}
|
|
602
|
+
const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false, "", "");
|
|
607
603
|
const entries = JSON.parse(out);
|
|
608
604
|
const built = entries[0]?.bit ?? bit;
|
|
609
605
|
for (const [key, value] of Object.entries(bit)) {
|
|
@@ -740,8 +736,7 @@ var BitmarkParserGenerator = class {
|
|
|
740
736
|
const emit = coreFormat === "bitmark" ? prettyIndent(bitmarkOptions.prettifyJson) : { pretty, indent };
|
|
741
737
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
742
738
|
const includeUnknown = !jsonOptions.excludeUnknownProperties;
|
|
743
|
-
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false);
|
|
744
|
-
this.throwOnError(out);
|
|
739
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false, "", "");
|
|
745
740
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
746
741
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
747
742
|
}
|
|
@@ -775,7 +770,6 @@ var BitmarkParserGenerator = class {
|
|
|
775
770
|
);
|
|
776
771
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
777
772
|
const out = wasm.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
|
|
778
|
-
this.throwOnError(out);
|
|
779
773
|
if (isBitmark) return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
780
774
|
if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
781
775
|
if (pretty || jsonOptions.stringify) return out;
|
|
@@ -792,7 +786,6 @@ var BitmarkParserGenerator = class {
|
|
|
792
786
|
const { pretty, indent } = prettyIndent(opts.prettify);
|
|
793
787
|
const coreFormat = format === "pojo" ? "json" : format;
|
|
794
788
|
const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true, "");
|
|
795
|
-
this.throwOnError(out);
|
|
796
789
|
if (format === "pojo") return JSON.parse(out);
|
|
797
790
|
return out;
|
|
798
791
|
}
|
|
@@ -824,8 +817,7 @@ var BitmarkParserGenerator = class {
|
|
|
824
817
|
const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
|
|
825
818
|
if (!isHtmlInput) {
|
|
826
819
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
827
|
-
const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false);
|
|
828
|
-
this.throwOnError(out2);
|
|
820
|
+
const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false, "", "");
|
|
829
821
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
830
822
|
}
|
|
831
823
|
const bitType = opts.tableFormat === "table" ? "table" : "table-extended";
|
|
@@ -834,13 +826,11 @@ var BitmarkParserGenerator = class {
|
|
|
834
826
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
835
827
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
836
828
|
if (outputFormat === "html") {
|
|
837
|
-
const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false);
|
|
838
|
-
this.throwOnError(out2);
|
|
829
|
+
const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false, "", "");
|
|
839
830
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
840
831
|
}
|
|
841
832
|
const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
|
|
842
|
-
const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false);
|
|
843
|
-
this.throwOnError(out);
|
|
833
|
+
const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false, "", "");
|
|
844
834
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
845
835
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
846
836
|
}
|
|
@@ -864,8 +854,7 @@ var BitmarkParserGenerator = class {
|
|
|
864
854
|
const opts = Object.assign({}, options);
|
|
865
855
|
const wasm = getLegacyWasm();
|
|
866
856
|
const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
|
|
867
|
-
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false);
|
|
868
|
-
this.throwOnError(out);
|
|
857
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false, "", "");
|
|
869
858
|
return makePseudoAst(JSON.parse(out));
|
|
870
859
|
}
|
|
871
860
|
/**
|
|
@@ -917,11 +906,9 @@ var BitmarkParserGenerator = class {
|
|
|
917
906
|
}
|
|
918
907
|
if (ast !== void 0) {
|
|
919
908
|
const out2 = isBitmarkText ? wasm.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
|
|
920
|
-
this.throwOnError(out2);
|
|
921
909
|
return this.deliver(out2, opts.outputFile, opts.fileOptions);
|
|
922
910
|
}
|
|
923
911
|
const out = wasm.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
|
|
924
|
-
this.throwOnError(out);
|
|
925
912
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
926
913
|
const outStr = pretty ? wasm.prettify(out, indent) : out;
|
|
927
914
|
if (opts.outputFile) return this.deliver(outStr, opts.outputFile, opts.fileOptions);
|
|
@@ -939,7 +926,6 @@ var BitmarkParserGenerator = class {
|
|
|
939
926
|
"bitmark++",
|
|
940
927
|
"body"
|
|
941
928
|
);
|
|
942
|
-
this.throwOnError(out);
|
|
943
929
|
return out;
|
|
944
930
|
}
|
|
945
931
|
/**
|
|
@@ -954,7 +940,6 @@ var BitmarkParserGenerator = class {
|
|
|
954
940
|
if (inputFormat === "bitmarkText") {
|
|
955
941
|
const ast = wasm.convert_text(String(input), "textToAst", "bitmark++", "body");
|
|
956
942
|
const out2 = wasm.convert_text(ast, "astToPlainText", "bitmark++", "body");
|
|
957
|
-
this.throwOnError(out2);
|
|
958
943
|
return out2;
|
|
959
944
|
}
|
|
960
945
|
if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm.is_bitmark(input)) {
|
|
@@ -971,8 +956,7 @@ var BitmarkParserGenerator = class {
|
|
|
971
956
|
}
|
|
972
957
|
}
|
|
973
958
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
974
|
-
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false);
|
|
975
|
-
this.throwOnError(out);
|
|
959
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false, "", "");
|
|
976
960
|
return out;
|
|
977
961
|
}
|
|
978
962
|
/** If `s` parses as a TextAst JSON array, return it. */
|
|
@@ -1076,12 +1060,6 @@ var BitmarkParserGenerator = class {
|
|
|
1076
1060
|
encoding: fileOptions?.encoding ?? "utf8"
|
|
1077
1061
|
});
|
|
1078
1062
|
}
|
|
1079
|
-
/** The core reports failures as `error:`-prefixed strings; bpg throws. */
|
|
1080
|
-
throwOnError(out) {
|
|
1081
|
-
if (out.startsWith("error:")) {
|
|
1082
|
-
throw new Error(out.slice("error:".length).trim());
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
1063
|
};
|
|
1086
1064
|
function extractHtmlTables(html) {
|
|
1087
1065
|
const tables = [];
|
|
@@ -1118,7 +1096,6 @@ function extractHtmlTables(html) {
|
|
|
1118
1096
|
}
|
|
1119
1097
|
function bitmarkTextParse(text) {
|
|
1120
1098
|
const out = getLegacyWasm().convert_text(text, "textToAst", "bitmark++", "body");
|
|
1121
|
-
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1122
1099
|
return JSON.parse(out);
|
|
1123
1100
|
}
|
|
1124
1101
|
|
|
@@ -1448,11 +1425,6 @@ function patchEntry(path2, op, value) {
|
|
|
1448
1425
|
var ALL_LANGUAGES = "all";
|
|
1449
1426
|
|
|
1450
1427
|
// src/core/api.ts
|
|
1451
|
-
function lex(input, options = {}) {
|
|
1452
|
-
const wasm = getActive();
|
|
1453
|
-
if (typeof wasm.lex !== "function") throw new UnsupportedFeatureError("lex", variant());
|
|
1454
|
-
return wasm.lex(input, options.stage ?? "lex");
|
|
1455
|
-
}
|
|
1456
1428
|
function bitmarkToObjects(input, options = {}) {
|
|
1457
1429
|
const out = getActive().convert(
|
|
1458
1430
|
input,
|
|
@@ -1463,9 +1435,10 @@ function bitmarkToObjects(input, options = {}) {
|
|
|
1463
1435
|
2,
|
|
1464
1436
|
1,
|
|
1465
1437
|
options.includeUnknownProperties ?? false,
|
|
1466
|
-
false
|
|
1438
|
+
false,
|
|
1439
|
+
"",
|
|
1440
|
+
""
|
|
1467
1441
|
);
|
|
1468
|
-
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1469
1442
|
return JSON.parse(out);
|
|
1470
1443
|
}
|
|
1471
1444
|
function objectsToBitmark(bits, options = {}) {
|
|
@@ -1481,9 +1454,10 @@ function objectsToBitmark(bits, options = {}) {
|
|
|
1481
1454
|
2,
|
|
1482
1455
|
1,
|
|
1483
1456
|
false,
|
|
1484
|
-
false
|
|
1457
|
+
false,
|
|
1458
|
+
"",
|
|
1459
|
+
""
|
|
1485
1460
|
);
|
|
1486
|
-
if (out.startsWith("error:")) throw new Error(out.slice("error:".length).trim());
|
|
1487
1461
|
return out;
|
|
1488
1462
|
}
|
|
1489
1463
|
function convert(input, options = {}) {
|
|
@@ -1496,7 +1470,19 @@ function convert(input, options = {}) {
|
|
|
1496
1470
|
options.indent ?? 2,
|
|
1497
1471
|
options.spacesAroundValues ?? 1,
|
|
1498
1472
|
options.includeUnknownProperties ?? false,
|
|
1499
|
-
options.mappingReport ?? false
|
|
1473
|
+
options.mappingReport ?? false,
|
|
1474
|
+
options.positionEncoding ?? "",
|
|
1475
|
+
options.tokensLayout ?? ""
|
|
1476
|
+
);
|
|
1477
|
+
}
|
|
1478
|
+
function semanticTokens(input, options = {}) {
|
|
1479
|
+
return JSON.parse(
|
|
1480
|
+
convert(input, {
|
|
1481
|
+
inputFormat: "bitmark",
|
|
1482
|
+
outputFormat: "semantic-tokens",
|
|
1483
|
+
positionEncoding: options.positionEncoding,
|
|
1484
|
+
tokensLayout: options.tokensLayout
|
|
1485
|
+
})
|
|
1500
1486
|
);
|
|
1501
1487
|
}
|
|
1502
1488
|
function canonicalize(input, options = {}) {
|
|
@@ -1510,9 +1496,7 @@ function canonicalize(input, options = {}) {
|
|
|
1510
1496
|
);
|
|
1511
1497
|
}
|
|
1512
1498
|
function countBits(input) {
|
|
1513
|
-
|
|
1514
|
-
if (out.startsWith("error:")) throw new Error(out);
|
|
1515
|
-
return Number.parseInt(out, 10);
|
|
1499
|
+
return Number.parseInt(getActive().count_bits(input), 10);
|
|
1516
1500
|
}
|
|
1517
1501
|
function splitBits(input) {
|
|
1518
1502
|
return JSON.parse(getActive().split_bits(input));
|
|
@@ -1534,6 +1518,25 @@ function transform(input, options = {}) {
|
|
|
1534
1518
|
options.spacesAroundValues ?? 1
|
|
1535
1519
|
);
|
|
1536
1520
|
}
|
|
1521
|
+
function diff(a, b, options = {}) {
|
|
1522
|
+
const wasm = getActive();
|
|
1523
|
+
if (typeof wasm.diff !== "function") throw new UnsupportedFeatureError("diff", variant());
|
|
1524
|
+
const out = wasm.diff(
|
|
1525
|
+
a,
|
|
1526
|
+
b,
|
|
1527
|
+
options.inputFormat ?? "auto",
|
|
1528
|
+
options.outputFormat ?? "bitmark",
|
|
1529
|
+
options.context ?? 3,
|
|
1530
|
+
options.locate ?? false,
|
|
1531
|
+
options.similarity ?? 0.6,
|
|
1532
|
+
options.bboxTolerance ?? 8,
|
|
1533
|
+
options.spacesAroundValues ?? 0
|
|
1534
|
+
);
|
|
1535
|
+
return out;
|
|
1536
|
+
}
|
|
1537
|
+
function diffBits(a, b, options = {}) {
|
|
1538
|
+
return JSON.parse(diff(a, b, { ...options, outputFormat: "json" }));
|
|
1539
|
+
}
|
|
1537
1540
|
function breakscapeText(input, options = {}) {
|
|
1538
1541
|
const format = options.format ?? "bitmark++";
|
|
1539
1542
|
const location = options.location ?? "body";
|
|
@@ -1554,7 +1557,11 @@ function info(options = {}) {
|
|
|
1554
1557
|
const onlyDeprecated = options.onlyDeprecated ?? false;
|
|
1555
1558
|
const full = options.full ?? false;
|
|
1556
1559
|
const language = typeof options.language === "string" ? options.language : options.language?.join(",") ?? "";
|
|
1557
|
-
|
|
1560
|
+
const wasm = getActive();
|
|
1561
|
+
if (format !== "json" && typeof wasm.info_text_supported !== "function") {
|
|
1562
|
+
throw new UnsupportedFeatureError('info (format: "text")', variant());
|
|
1563
|
+
}
|
|
1564
|
+
return wasm.info(
|
|
1558
1565
|
infoType,
|
|
1559
1566
|
format,
|
|
1560
1567
|
bit,
|
|
@@ -1567,8 +1574,11 @@ function info(options = {}) {
|
|
|
1567
1574
|
);
|
|
1568
1575
|
}
|
|
1569
1576
|
function register(options) {
|
|
1570
|
-
|
|
1571
|
-
|
|
1577
|
+
try {
|
|
1578
|
+
getActive().register(options.type, options.data);
|
|
1579
|
+
} catch (e) {
|
|
1580
|
+
throw new RegisterError(e instanceof Error ? e.message : String(e));
|
|
1581
|
+
}
|
|
1572
1582
|
rememberRegistration(options.type, options.data);
|
|
1573
1583
|
}
|
|
1574
1584
|
|
|
@@ -1612,14 +1622,16 @@ function transformParallel(input, options = {}) {
|
|
|
1612
1622
|
canonicalize,
|
|
1613
1623
|
convert,
|
|
1614
1624
|
countBits,
|
|
1625
|
+
diff,
|
|
1626
|
+
diffBits,
|
|
1615
1627
|
info,
|
|
1616
1628
|
init,
|
|
1617
1629
|
initSync,
|
|
1618
1630
|
legacy,
|
|
1619
|
-
lex,
|
|
1620
1631
|
objectsToBitmark,
|
|
1621
1632
|
patchEntry,
|
|
1622
1633
|
register,
|
|
1634
|
+
semanticTokens,
|
|
1623
1635
|
splitBits,
|
|
1624
1636
|
transform,
|
|
1625
1637
|
transformParallel,
|