@gmb/bitmark-parser 6.9.0 → 6.10.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 +55 -3
- package/dist/browser/bitmark-parser.min.js +4 -4
- package/dist/browser/bitmark-parser.min.js.map +1 -1
- 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/cjs/index.cjs +619 -114
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +2432 -3280
- package/dist/browser/esm/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/esm/index.d.ts +2432 -3280
- package/dist/browser/esm/index.js +616 -114
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +704 -7
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/index.cjs +154 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -968
- package/dist/index.d.ts +81 -968
- package/dist/index.js +149 -85
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +9 -9
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.js +9 -9
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs +6 -1
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +8 -7
- package/schema/bitmark.schema.json +823 -4064
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +99 -0
- package/wasm-bitmark-json/bitmark_json_wasm.js +491 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +19 -0
- package/wasm-bitmark-json/package.json +20 -0
package/dist/index.js
CHANGED
|
@@ -10,12 +10,46 @@ 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.10.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."
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
// src/core/facade.ts
|
|
20
|
+
var NotInitializedError = class extends Error {
|
|
21
|
+
constructor() {
|
|
22
|
+
super("wasm not initialised: call init() (or init({ feature: \u2026 })) first");
|
|
23
|
+
this.name = "NotInitializedError";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var UnsupportedFeatureError = class extends Error {
|
|
27
|
+
constructor(what, active2) {
|
|
28
|
+
super(
|
|
29
|
+
`${what} is not available in the loaded wasm module${active2 ? ` (feature: "${active2}")` : ""}; init({ feature: "full" }) to load it`
|
|
30
|
+
);
|
|
31
|
+
this.name = "UnsupportedFeatureError";
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var active;
|
|
35
|
+
var activeFeature;
|
|
36
|
+
var lazyLoader;
|
|
37
|
+
function getActive() {
|
|
38
|
+
if (!active && lazyLoader) lazyLoader();
|
|
39
|
+
if (!active) throw new NotInitializedError();
|
|
40
|
+
return active;
|
|
41
|
+
}
|
|
42
|
+
function setActive(feature, module) {
|
|
43
|
+
active = module;
|
|
44
|
+
activeFeature = feature;
|
|
45
|
+
}
|
|
46
|
+
function setLazyLoader(loader) {
|
|
47
|
+
lazyLoader = loader;
|
|
48
|
+
}
|
|
49
|
+
function variant() {
|
|
50
|
+
return activeFeature;
|
|
51
|
+
}
|
|
52
|
+
|
|
19
53
|
// src/core/hooked-transform.ts
|
|
20
54
|
function isError(s) {
|
|
21
55
|
return s.startsWith("error:");
|
|
@@ -36,9 +70,9 @@ function normalisePatch(patch) {
|
|
|
36
70
|
}
|
|
37
71
|
return patch;
|
|
38
72
|
}
|
|
39
|
-
function buildUnits(
|
|
73
|
+
function buildUnits(wasm, input, inputIsBitmark) {
|
|
40
74
|
if (inputIsBitmark) {
|
|
41
|
-
const out2 =
|
|
75
|
+
const out2 = wasm.split_bits(input);
|
|
42
76
|
if (isError(out2)) throw new Error(out2);
|
|
43
77
|
const slices = JSON.parse(out2);
|
|
44
78
|
return slices.map((s) => ({
|
|
@@ -46,7 +80,7 @@ function buildUnits(wasm2, input, inputIsBitmark) {
|
|
|
46
80
|
source: s.source
|
|
47
81
|
}));
|
|
48
82
|
}
|
|
49
|
-
const out =
|
|
83
|
+
const out = wasm.split_json_bits(input);
|
|
50
84
|
if (isError(out)) throw new Error(out);
|
|
51
85
|
const envelopes = JSON.parse(out);
|
|
52
86
|
return envelopes.map((env, index) => ({
|
|
@@ -55,17 +89,17 @@ function buildUnits(wasm2, input, inputIsBitmark) {
|
|
|
55
89
|
source: JSON.stringify([env])
|
|
56
90
|
}));
|
|
57
91
|
}
|
|
58
|
-
function planTransform(
|
|
92
|
+
function planTransform(wasm, input, options) {
|
|
59
93
|
const mode = options.mode ?? "optimized";
|
|
60
94
|
const output = options.outputFormat ?? "json";
|
|
61
95
|
const spacesAroundValues = options.spacesAroundValues ?? 1;
|
|
62
96
|
const indent = options.indent ?? 2;
|
|
63
97
|
const pretty = options.pretty ?? false;
|
|
64
98
|
const sel = options.inputFormat ?? "auto";
|
|
65
|
-
const inputIsBitmark = sel === "bitmark" || sel !== "json" &&
|
|
99
|
+
const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
|
|
66
100
|
const inputFormat = inputIsBitmark ? "bitmark" : "json";
|
|
67
101
|
const staticPatch = normalisePatch(options.patch);
|
|
68
|
-
const units = buildUnits(
|
|
102
|
+
const units = buildUnits(wasm, input, inputIsBitmark);
|
|
69
103
|
const total = units.length;
|
|
70
104
|
const jobs = [];
|
|
71
105
|
const views = [];
|
|
@@ -89,8 +123,8 @@ function planTransform(wasm2, input, options) {
|
|
|
89
123
|
}
|
|
90
124
|
return { jobs, views, output, pretty, indent };
|
|
91
125
|
}
|
|
92
|
-
function computeBit(
|
|
93
|
-
const out =
|
|
126
|
+
function computeBit(wasm, job) {
|
|
127
|
+
const out = wasm.transform(
|
|
94
128
|
job.source,
|
|
95
129
|
job.inputFormat,
|
|
96
130
|
job.outputFormat,
|
|
@@ -103,33 +137,33 @@ function computeBit(wasm2, job) {
|
|
|
103
137
|
if (isError(out)) return out;
|
|
104
138
|
return job.outputFormat === "json" ? stripArray(out) : out;
|
|
105
139
|
}
|
|
106
|
-
function recombine(
|
|
140
|
+
function recombine(wasm, elements, output, pretty, indent) {
|
|
107
141
|
if (output === "bitmark" || output === "text") return elements.join("\n");
|
|
108
142
|
const arr = `[${elements.join(",")}]`;
|
|
109
|
-
return pretty ?
|
|
143
|
+
return pretty ? wasm.prettify(arr, indent) : arr;
|
|
110
144
|
}
|
|
111
|
-
function runHookedTransform(
|
|
145
|
+
function runHookedTransform(wasm, input, options) {
|
|
112
146
|
let plan;
|
|
113
147
|
try {
|
|
114
|
-
plan = planTransform(
|
|
148
|
+
plan = planTransform(wasm, input, options);
|
|
115
149
|
} catch (e) {
|
|
116
150
|
return errorString(e);
|
|
117
151
|
}
|
|
118
152
|
const rendered = [];
|
|
119
153
|
for (let i = 0; i < plan.jobs.length; i++) {
|
|
120
|
-
const element = computeBit(
|
|
154
|
+
const element = computeBit(wasm, plan.jobs[i]);
|
|
121
155
|
if (isError(element)) return element;
|
|
122
156
|
options.postHook?.(plan.views[i], element);
|
|
123
157
|
rendered.push(element);
|
|
124
158
|
}
|
|
125
|
-
return recombine(
|
|
159
|
+
return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);
|
|
126
160
|
}
|
|
127
161
|
|
|
128
162
|
// src/core/parallel.ts
|
|
129
|
-
async function orchestrateParallel(
|
|
163
|
+
async function orchestrateParallel(wasm, input, options, runJobs) {
|
|
130
164
|
let plan;
|
|
131
165
|
try {
|
|
132
|
-
plan = planTransform(
|
|
166
|
+
plan = planTransform(wasm, input, options);
|
|
133
167
|
} catch (e) {
|
|
134
168
|
return errorString(e);
|
|
135
169
|
}
|
|
@@ -143,7 +177,7 @@ async function orchestrateParallel(wasm2, input, options, runJobs) {
|
|
|
143
177
|
if (isError(elements[i])) return elements[i];
|
|
144
178
|
options.postHook?.(plan.views[i], elements[i]);
|
|
145
179
|
}
|
|
146
|
-
return recombine(
|
|
180
|
+
return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
|
|
147
181
|
}
|
|
148
182
|
|
|
149
183
|
// src/node/pool.ts
|
|
@@ -152,7 +186,7 @@ import { Worker } from "worker_threads";
|
|
|
152
186
|
function workerPath() {
|
|
153
187
|
return fileURLToPath(new URL("./worker-entry.cjs", import.meta.url));
|
|
154
188
|
}
|
|
155
|
-
function runJobsParallel(jobs, workers) {
|
|
189
|
+
function runJobsParallel(jobs, workers, feature) {
|
|
156
190
|
if (jobs.length === 0) return Promise.resolve([]);
|
|
157
191
|
const poolSize = Math.max(1, Math.min(workers, jobs.length));
|
|
158
192
|
const path2 = workerPath();
|
|
@@ -178,7 +212,7 @@ function runJobsParallel(jobs, workers) {
|
|
|
178
212
|
w.postMessage({ id, job: jobs[id] });
|
|
179
213
|
};
|
|
180
214
|
for (let i = 0; i < poolSize; i++) {
|
|
181
|
-
const w = new Worker(path2);
|
|
215
|
+
const w = new Worker(path2, { workerData: { feature } });
|
|
182
216
|
pool.push(w);
|
|
183
217
|
w.on("message", (res) => {
|
|
184
218
|
if (done) return;
|
|
@@ -206,8 +240,14 @@ function runJobsParallel(jobs, workers) {
|
|
|
206
240
|
}
|
|
207
241
|
|
|
208
242
|
// src/node/transform-parallel.ts
|
|
209
|
-
function runParallelTransform(
|
|
210
|
-
|
|
243
|
+
function runParallelTransform(wasm, input, options) {
|
|
244
|
+
const feature = variant() ?? "full";
|
|
245
|
+
return orchestrateParallel(
|
|
246
|
+
wasm,
|
|
247
|
+
input,
|
|
248
|
+
options,
|
|
249
|
+
(jobs, workers) => runJobsParallel(jobs, workers, feature)
|
|
250
|
+
);
|
|
211
251
|
}
|
|
212
252
|
|
|
213
253
|
// src/node/legacy-init.ts
|
|
@@ -215,17 +255,17 @@ import * as fs from "fs";
|
|
|
215
255
|
import * as path from "path";
|
|
216
256
|
|
|
217
257
|
// src/legacy/runtime.ts
|
|
218
|
-
var
|
|
219
|
-
function
|
|
220
|
-
|
|
258
|
+
var wasmProvider;
|
|
259
|
+
function setLegacyWasmProvider(provider) {
|
|
260
|
+
wasmProvider = provider;
|
|
221
261
|
}
|
|
222
262
|
function getLegacyWasm() {
|
|
223
|
-
if (!
|
|
263
|
+
if (!wasmProvider) {
|
|
224
264
|
throw new Error(
|
|
225
265
|
"legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)"
|
|
226
266
|
);
|
|
227
267
|
}
|
|
228
|
-
return
|
|
268
|
+
return wasmProvider();
|
|
229
269
|
}
|
|
230
270
|
var fileIo;
|
|
231
271
|
function setLegacyFileIo(io) {
|
|
@@ -236,8 +276,8 @@ function getLegacyFileIo() {
|
|
|
236
276
|
}
|
|
237
277
|
|
|
238
278
|
// src/node/legacy-init.ts
|
|
239
|
-
function initLegacyNode(
|
|
240
|
-
|
|
279
|
+
function initLegacyNode(provider) {
|
|
280
|
+
setLegacyWasmProvider(provider);
|
|
241
281
|
setLegacyFileIo({
|
|
242
282
|
existsSync: (p) => fs.existsSync(p),
|
|
243
283
|
readFileSync: (p, encoding) => fs.readFileSync(p, { encoding }),
|
|
@@ -428,7 +468,7 @@ var Builder = class {
|
|
|
428
468
|
* more than one resource, use the first one").
|
|
429
469
|
*/
|
|
430
470
|
buildBit(data, _options) {
|
|
431
|
-
const
|
|
471
|
+
const wasm = getLegacyWasm();
|
|
432
472
|
const src = { ...data };
|
|
433
473
|
const bitType = src.bitType;
|
|
434
474
|
const bitConfig = this.getBitConfig(bitType);
|
|
@@ -489,7 +529,7 @@ var Builder = class {
|
|
|
489
529
|
}
|
|
490
530
|
}
|
|
491
531
|
this.parseStringTexts(bit);
|
|
492
|
-
const out =
|
|
532
|
+
const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false);
|
|
493
533
|
if (out.startsWith("error:")) {
|
|
494
534
|
throw new Error(out.slice("error:".length).trim());
|
|
495
535
|
}
|
|
@@ -545,10 +585,10 @@ var Builder = class {
|
|
|
545
585
|
* (bpg TextParser.toAst ignores format; only location matters).
|
|
546
586
|
*/
|
|
547
587
|
parseStringTexts(bit) {
|
|
548
|
-
const
|
|
588
|
+
const wasm = getLegacyWasm();
|
|
549
589
|
const toAst = (s, location) => {
|
|
550
590
|
if (s === "") return s;
|
|
551
|
-
const out =
|
|
591
|
+
const out = wasm.convert_text(s, "textToAst", "bitmark++", location);
|
|
552
592
|
try {
|
|
553
593
|
return JSON.parse(out);
|
|
554
594
|
} catch {
|
|
@@ -578,10 +618,10 @@ var Builder = class {
|
|
|
578
618
|
* unknown-bit-type error (`Config.getBitConfig` parity).
|
|
579
619
|
*/
|
|
580
620
|
getBitConfig(bitType) {
|
|
581
|
-
const
|
|
621
|
+
const wasm = getLegacyWasm();
|
|
582
622
|
if (bitType !== void 0) {
|
|
583
623
|
try {
|
|
584
|
-
const info2 = JSON.parse(
|
|
624
|
+
const info2 = JSON.parse(wasm.info("bit", "json", bitType, false, 2, false, false, true));
|
|
585
625
|
if (info2.error === void 0) return { bodyFormat: info2.body?.format };
|
|
586
626
|
} catch {
|
|
587
627
|
}
|
|
@@ -621,7 +661,7 @@ var BitmarkParserGenerator = class {
|
|
|
621
661
|
validateBitmarkOptions(bitmarkOptions);
|
|
622
662
|
validateJsonOptions(jsonOptions);
|
|
623
663
|
this.checkBrowserFileWrite(opts.outputFile);
|
|
624
|
-
const
|
|
664
|
+
const wasm = getLegacyWasm();
|
|
625
665
|
const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
|
|
626
666
|
const outputFormat = opts.outputFormat ?? (isBitmark ? "json" : "bitmark");
|
|
627
667
|
const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
|
|
@@ -629,7 +669,7 @@ var BitmarkParserGenerator = class {
|
|
|
629
669
|
const emit = coreFormat === "bitmark" ? prettyIndent(bitmarkOptions.prettifyJson) : { pretty, indent };
|
|
630
670
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
631
671
|
const includeUnknown = !jsonOptions.excludeUnknownProperties;
|
|
632
|
-
const out =
|
|
672
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false);
|
|
633
673
|
this.throwOnError(out);
|
|
634
674
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
635
675
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
@@ -657,13 +697,13 @@ var BitmarkParserGenerator = class {
|
|
|
657
697
|
validateBitmarkOptions(bitmarkOptions);
|
|
658
698
|
validateJsonOptions(jsonOptions);
|
|
659
699
|
this.checkBrowserFileWrite(opts.outputFile);
|
|
660
|
-
const
|
|
700
|
+
const wasm = getLegacyWasm();
|
|
661
701
|
const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
|
|
662
702
|
const { pretty, indent } = prettyIndent(
|
|
663
703
|
isBitmark ? bitmarkOptions.prettifyJson : jsonOptions.prettify
|
|
664
704
|
);
|
|
665
705
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
666
|
-
const out =
|
|
706
|
+
const out = wasm.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
|
|
667
707
|
this.throwOnError(out);
|
|
668
708
|
if (isBitmark) return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
669
709
|
if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
@@ -675,12 +715,12 @@ var BitmarkParserGenerator = class {
|
|
|
675
715
|
*/
|
|
676
716
|
info(options) {
|
|
677
717
|
const opts = Object.assign({}, options);
|
|
678
|
-
const
|
|
718
|
+
const wasm = getLegacyWasm();
|
|
679
719
|
const type = opts.type ?? "list";
|
|
680
720
|
const format = opts.outputFormat ?? "text";
|
|
681
721
|
const { pretty, indent } = prettyIndent(opts.prettify);
|
|
682
722
|
const coreFormat = format === "pojo" ? "json" : format;
|
|
683
|
-
const out =
|
|
723
|
+
const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true);
|
|
684
724
|
this.throwOnError(out);
|
|
685
725
|
if (format === "pojo") return JSON.parse(out);
|
|
686
726
|
return out;
|
|
@@ -708,12 +748,12 @@ var BitmarkParserGenerator = class {
|
|
|
708
748
|
if (opts.keepUnknownTags) unsupportedOption("keepUnknownTags");
|
|
709
749
|
if (opts.noBreakscaping) unsupportedOption("noBreakscaping");
|
|
710
750
|
this.checkBrowserFileWrite(opts.outputFile);
|
|
711
|
-
const
|
|
751
|
+
const wasm = getLegacyWasm();
|
|
712
752
|
const inStr = typeof input === "string" ? this.maybeReadFile(input, void 0) : "";
|
|
713
753
|
const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
|
|
714
754
|
if (!isHtmlInput) {
|
|
715
755
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
716
|
-
const out2 =
|
|
756
|
+
const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false);
|
|
717
757
|
this.throwOnError(out2);
|
|
718
758
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
719
759
|
}
|
|
@@ -723,12 +763,12 @@ var BitmarkParserGenerator = class {
|
|
|
723
763
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
724
764
|
const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
|
|
725
765
|
if (outputFormat === "html") {
|
|
726
|
-
const out2 =
|
|
766
|
+
const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false);
|
|
727
767
|
this.throwOnError(out2);
|
|
728
768
|
return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
|
|
729
769
|
}
|
|
730
770
|
const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
|
|
731
|
-
const out =
|
|
771
|
+
const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false);
|
|
732
772
|
this.throwOnError(out);
|
|
733
773
|
if (outputFormat === "bitmark" || outputFormat === "text") {
|
|
734
774
|
return this.deliver(out, opts.outputFile, opts.fileOptions);
|
|
@@ -751,9 +791,9 @@ var BitmarkParserGenerator = class {
|
|
|
751
791
|
*/
|
|
752
792
|
createAst(input, options) {
|
|
753
793
|
const opts = Object.assign({}, options);
|
|
754
|
-
const
|
|
794
|
+
const wasm = getLegacyWasm();
|
|
755
795
|
const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
|
|
756
|
-
const out =
|
|
796
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false);
|
|
757
797
|
this.throwOnError(out);
|
|
758
798
|
return makePseudoAst(JSON.parse(out));
|
|
759
799
|
}
|
|
@@ -764,9 +804,9 @@ var BitmarkParserGenerator = class {
|
|
|
764
804
|
if (!input) return input;
|
|
765
805
|
const opts = Object.assign({}, options);
|
|
766
806
|
this.checkBrowserFileWrite(opts.outputFile);
|
|
767
|
-
const
|
|
807
|
+
const wasm = getLegacyWasm();
|
|
768
808
|
const inStr = this.maybeReadFile(input, opts.inputFormat);
|
|
769
|
-
const res =
|
|
809
|
+
const res = wasm.breakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
|
|
770
810
|
return this.deliver(res, opts.outputFile, opts.fileOptions);
|
|
771
811
|
}
|
|
772
812
|
/**
|
|
@@ -776,9 +816,9 @@ var BitmarkParserGenerator = class {
|
|
|
776
816
|
if (!input) return input;
|
|
777
817
|
const opts = Object.assign({}, options);
|
|
778
818
|
this.checkBrowserFileWrite(opts.outputFile);
|
|
779
|
-
const
|
|
819
|
+
const wasm = getLegacyWasm();
|
|
780
820
|
const inStr = this.maybeReadFile(input, opts.inputFormat);
|
|
781
|
-
const res =
|
|
821
|
+
const res = wasm.unbreakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
|
|
782
822
|
return this.deliver(res, opts.outputFile, opts.fileOptions);
|
|
783
823
|
}
|
|
784
824
|
/**
|
|
@@ -792,7 +832,7 @@ var BitmarkParserGenerator = class {
|
|
|
792
832
|
const opts = Object.assign({}, options);
|
|
793
833
|
const jsonOptions = Object.assign({}, opts.jsonOptions);
|
|
794
834
|
this.checkBrowserFileWrite(opts.outputFile);
|
|
795
|
-
const
|
|
835
|
+
const wasm = getLegacyWasm();
|
|
796
836
|
const isBitmarkText = opts.textFormat === void 0 || mapTextFormat(opts.textFormat) === "bitmark++";
|
|
797
837
|
const textLocation = opts.textLocation ?? "body";
|
|
798
838
|
let inStr;
|
|
@@ -805,14 +845,14 @@ var BitmarkParserGenerator = class {
|
|
|
805
845
|
ast = Array.isArray(input) ? input : void 0;
|
|
806
846
|
}
|
|
807
847
|
if (ast !== void 0) {
|
|
808
|
-
const out2 = isBitmarkText ?
|
|
848
|
+
const out2 = isBitmarkText ? wasm.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
|
|
809
849
|
this.throwOnError(out2);
|
|
810
850
|
return this.deliver(out2, opts.outputFile, opts.fileOptions);
|
|
811
851
|
}
|
|
812
|
-
const out =
|
|
852
|
+
const out = wasm.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
|
|
813
853
|
this.throwOnError(out);
|
|
814
854
|
const { pretty, indent } = prettyIndent(jsonOptions.prettify);
|
|
815
|
-
const outStr = pretty ?
|
|
855
|
+
const outStr = pretty ? wasm.prettify(out, indent) : out;
|
|
816
856
|
if (opts.outputFile) return this.deliver(outStr, opts.outputFile, opts.fileOptions);
|
|
817
857
|
if (pretty) return outStr;
|
|
818
858
|
return JSON.parse(out);
|
|
@@ -821,8 +861,8 @@ var BitmarkParserGenerator = class {
|
|
|
821
861
|
* Convert a text AST to plain text (bpg-compatible `textAstToPlainText`).
|
|
822
862
|
*/
|
|
823
863
|
textAstToPlainText(textAst, _options) {
|
|
824
|
-
const
|
|
825
|
-
const out =
|
|
864
|
+
const wasm = getLegacyWasm();
|
|
865
|
+
const out = wasm.convert_text(
|
|
826
866
|
typeof textAst === "string" ? textAst : JSON.stringify(textAst),
|
|
827
867
|
"astToPlainText",
|
|
828
868
|
"bitmark++",
|
|
@@ -836,17 +876,17 @@ var BitmarkParserGenerator = class {
|
|
|
836
876
|
*/
|
|
837
877
|
extractPlainText(input, options) {
|
|
838
878
|
const inputFormat = options?.inputFormat;
|
|
839
|
-
const
|
|
879
|
+
const wasm = getLegacyWasm();
|
|
840
880
|
if (inputFormat === "plainText") {
|
|
841
881
|
return typeof input === "string" ? String(input) : "";
|
|
842
882
|
}
|
|
843
883
|
if (inputFormat === "bitmarkText") {
|
|
844
|
-
const ast =
|
|
845
|
-
const out2 =
|
|
884
|
+
const ast = wasm.convert_text(String(input), "textToAst", "bitmark++", "body");
|
|
885
|
+
const out2 = wasm.convert_text(ast, "astToPlainText", "bitmark++", "body");
|
|
846
886
|
this.throwOnError(out2);
|
|
847
887
|
return out2;
|
|
848
888
|
}
|
|
849
|
-
if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !
|
|
889
|
+
if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm.is_bitmark(input)) {
|
|
850
890
|
const looksJson = (() => {
|
|
851
891
|
try {
|
|
852
892
|
JSON.parse(input);
|
|
@@ -860,7 +900,7 @@ var BitmarkParserGenerator = class {
|
|
|
860
900
|
}
|
|
861
901
|
}
|
|
862
902
|
const { source, isBitmark } = this.resolveInput(input, void 0);
|
|
863
|
-
const out =
|
|
903
|
+
const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false);
|
|
864
904
|
this.throwOnError(out);
|
|
865
905
|
return out;
|
|
866
906
|
}
|
|
@@ -894,8 +934,8 @@ var BitmarkParserGenerator = class {
|
|
|
894
934
|
};
|
|
895
935
|
}
|
|
896
936
|
const inStr = this.maybeReadFile(input, inputFormat);
|
|
897
|
-
const
|
|
898
|
-
if (
|
|
937
|
+
const wasm = getLegacyWasm();
|
|
938
|
+
if (wasm.is_bitmark(inStr)) return { source: inStr, isBitmark: true };
|
|
899
939
|
try {
|
|
900
940
|
const parsed = JSON.parse(inStr);
|
|
901
941
|
const entries = this.jsonEntries(parsed);
|
|
@@ -1262,8 +1302,8 @@ function bitNameToKey(name) {
|
|
|
1262
1302
|
var bitTypeCache;
|
|
1263
1303
|
function loadBitTypes() {
|
|
1264
1304
|
if (!bitTypeCache) {
|
|
1265
|
-
const
|
|
1266
|
-
const all = JSON.parse(
|
|
1305
|
+
const wasm = getLegacyWasm();
|
|
1306
|
+
const all = JSON.parse(wasm.info("all", "json", "", false, 2, true, false, false));
|
|
1267
1307
|
const map = { _standard: "_standard" };
|
|
1268
1308
|
for (const { name } of all) {
|
|
1269
1309
|
map[bitNameToKey(name)] = name;
|
|
@@ -1335,18 +1375,14 @@ function patchEntry(path2, op, value) {
|
|
|
1335
1375
|
return value === void 0 ? { path: path2, op } : { path: path2, op, value };
|
|
1336
1376
|
}
|
|
1337
1377
|
|
|
1338
|
-
// src/
|
|
1339
|
-
var require2 = createRequire(import.meta.url);
|
|
1340
|
-
var wasm = require2("../wasm/bitmark_wasm.js");
|
|
1341
|
-
initLegacyNode(wasm);
|
|
1342
|
-
function version() {
|
|
1343
|
-
return PACKAGE_INFO.version;
|
|
1344
|
-
}
|
|
1378
|
+
// src/core/api.ts
|
|
1345
1379
|
function lex(input, options = {}) {
|
|
1380
|
+
const wasm = getActive();
|
|
1381
|
+
if (typeof wasm.lex !== "function") throw new UnsupportedFeatureError("lex", variant());
|
|
1346
1382
|
return wasm.lex(input, options.stage ?? "lex");
|
|
1347
1383
|
}
|
|
1348
1384
|
function bitmarkToObjects(input, options = {}) {
|
|
1349
|
-
const out =
|
|
1385
|
+
const out = getActive().convert(
|
|
1350
1386
|
input,
|
|
1351
1387
|
"bitmark",
|
|
1352
1388
|
"json",
|
|
@@ -1364,7 +1400,7 @@ function objectsToBitmark(bits, options = {}) {
|
|
|
1364
1400
|
const entries = bits.map(
|
|
1365
1401
|
(b) => b !== null && typeof b === "object" && "bit" in b && typeof b.bit === "object" ? b : { bit: b }
|
|
1366
1402
|
);
|
|
1367
|
-
const out =
|
|
1403
|
+
const out = getActive().convert(
|
|
1368
1404
|
JSON.stringify(entries),
|
|
1369
1405
|
"json",
|
|
1370
1406
|
"bitmark",
|
|
@@ -1379,7 +1415,7 @@ function objectsToBitmark(bits, options = {}) {
|
|
|
1379
1415
|
return out;
|
|
1380
1416
|
}
|
|
1381
1417
|
function convert(input, options = {}) {
|
|
1382
|
-
return
|
|
1418
|
+
return getActive().convert(
|
|
1383
1419
|
input,
|
|
1384
1420
|
options.inputFormat ?? "auto",
|
|
1385
1421
|
options.outputFormat ?? "auto",
|
|
@@ -1392,7 +1428,7 @@ function convert(input, options = {}) {
|
|
|
1392
1428
|
);
|
|
1393
1429
|
}
|
|
1394
1430
|
function canonicalize(input, options = {}) {
|
|
1395
|
-
return
|
|
1431
|
+
return getActive().canonicalize(
|
|
1396
1432
|
input,
|
|
1397
1433
|
options.inputFormat ?? "auto",
|
|
1398
1434
|
options.mode ?? "optimized",
|
|
@@ -1402,14 +1438,15 @@ function canonicalize(input, options = {}) {
|
|
|
1402
1438
|
);
|
|
1403
1439
|
}
|
|
1404
1440
|
function countBits(input) {
|
|
1405
|
-
const out =
|
|
1441
|
+
const out = getActive().count_bits(input);
|
|
1406
1442
|
if (out.startsWith("error:")) throw new Error(out);
|
|
1407
1443
|
return Number.parseInt(out, 10);
|
|
1408
1444
|
}
|
|
1409
1445
|
function splitBits(input) {
|
|
1410
|
-
return JSON.parse(
|
|
1446
|
+
return JSON.parse(getActive().split_bits(input));
|
|
1411
1447
|
}
|
|
1412
1448
|
function transform(input, options = {}) {
|
|
1449
|
+
const wasm = getActive();
|
|
1413
1450
|
if (options.preHook || options.postHook) {
|
|
1414
1451
|
return runHookedTransform(wasm, input, options);
|
|
1415
1452
|
}
|
|
@@ -1425,18 +1462,15 @@ function transform(input, options = {}) {
|
|
|
1425
1462
|
options.spacesAroundValues ?? 1
|
|
1426
1463
|
);
|
|
1427
1464
|
}
|
|
1428
|
-
function transformParallel(input, options = {}) {
|
|
1429
|
-
return runParallelTransform(wasm, input, options);
|
|
1430
|
-
}
|
|
1431
1465
|
function breakscapeText(input, options = {}) {
|
|
1432
1466
|
const format = options.format ?? "bitmark++";
|
|
1433
1467
|
const location = options.location ?? "body";
|
|
1434
|
-
return
|
|
1468
|
+
return getActive().breakscape_text(input, format, location);
|
|
1435
1469
|
}
|
|
1436
1470
|
function unbreakscapeText(input, options = {}) {
|
|
1437
1471
|
const format = options.format ?? "bitmark++";
|
|
1438
1472
|
const location = options.location ?? "body";
|
|
1439
|
-
return
|
|
1473
|
+
return getActive().unbreakscape_text(input, format, location);
|
|
1440
1474
|
}
|
|
1441
1475
|
function info(options = {}) {
|
|
1442
1476
|
const infoType = options.infoType ?? "list";
|
|
@@ -1447,15 +1481,44 @@ function info(options = {}) {
|
|
|
1447
1481
|
const includeDeprecated = options.includeDeprecated ?? false;
|
|
1448
1482
|
const onlyDeprecated = options.onlyDeprecated ?? false;
|
|
1449
1483
|
const full = options.full ?? false;
|
|
1450
|
-
return
|
|
1484
|
+
return getActive().info(infoType, format, bit, pretty, indent, includeDeprecated, onlyDeprecated, full);
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
// src/index.ts
|
|
1488
|
+
var require2 = createRequire(import.meta.url);
|
|
1489
|
+
var VARIANT_GLUE = {
|
|
1490
|
+
full: "../wasm/bitmark_wasm.js",
|
|
1491
|
+
"bitmark-json": "../wasm-bitmark-json/bitmark_json_wasm.js"
|
|
1492
|
+
};
|
|
1493
|
+
function loadVariant(feature) {
|
|
1494
|
+
const module = require2(VARIANT_GLUE[feature]);
|
|
1495
|
+
setActive(feature, module);
|
|
1496
|
+
}
|
|
1497
|
+
setLazyLoader(() => loadVariant("full"));
|
|
1498
|
+
async function init(options = {}) {
|
|
1499
|
+
loadVariant(options.feature ?? "full");
|
|
1500
|
+
}
|
|
1501
|
+
function initSync(options = {}) {
|
|
1502
|
+
loadVariant(options.feature ?? "full");
|
|
1503
|
+
}
|
|
1504
|
+
initLegacyNode(() => getActive());
|
|
1505
|
+
function version() {
|
|
1506
|
+
return PACKAGE_INFO.version;
|
|
1507
|
+
}
|
|
1508
|
+
function transformParallel(input, options = {}) {
|
|
1509
|
+
return runParallelTransform(getActive(), input, options);
|
|
1451
1510
|
}
|
|
1452
1511
|
export {
|
|
1512
|
+
NotInitializedError,
|
|
1513
|
+
UnsupportedFeatureError,
|
|
1453
1514
|
bitmarkToObjects,
|
|
1454
1515
|
breakscapeText,
|
|
1455
1516
|
canonicalize,
|
|
1456
1517
|
convert,
|
|
1457
1518
|
countBits,
|
|
1458
1519
|
info,
|
|
1520
|
+
init,
|
|
1521
|
+
initSync,
|
|
1459
1522
|
legacy_exports as legacy,
|
|
1460
1523
|
lex,
|
|
1461
1524
|
objectsToBitmark,
|
|
@@ -1464,6 +1527,7 @@ export {
|
|
|
1464
1527
|
transform,
|
|
1465
1528
|
transformParallel,
|
|
1466
1529
|
unbreakscapeText,
|
|
1530
|
+
variant,
|
|
1467
1531
|
version
|
|
1468
1532
|
};
|
|
1469
1533
|
//# sourceMappingURL=index.js.map
|