@gmb/bitmark-parser 6.9.0 → 6.10.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.
Files changed (38) hide show
  1. package/README.md +55 -3
  2. package/dist/browser/bitmark-parser.min.js +4 -4
  3. package/dist/browser/bitmark-parser.min.js.map +1 -1
  4. package/dist/browser/bitmark_json_wasm_bg.wasm +0 -0
  5. package/dist/browser/bitmark_wasm_bg.wasm +0 -0
  6. package/dist/browser/cjs/bitmark_json_wasm_bg.wasm +0 -0
  7. package/dist/browser/cjs/bitmark_wasm_bg.wasm +0 -0
  8. package/dist/browser/cjs/index.cjs +619 -114
  9. package/dist/browser/cjs/index.cjs.map +1 -1
  10. package/dist/browser/cjs/index.d.cts +2432 -3280
  11. package/dist/browser/esm/bitmark_json_wasm_bg.wasm +0 -0
  12. package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
  13. package/dist/browser/esm/index.d.ts +2432 -3280
  14. package/dist/browser/esm/index.js +616 -114
  15. package/dist/browser/esm/index.js.map +1 -1
  16. package/dist/browser/esm/worker-entry.js +704 -7
  17. package/dist/browser/esm/worker-entry.js.map +1 -1
  18. package/dist/index.cjs +154 -85
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +81 -968
  21. package/dist/index.d.ts +81 -968
  22. package/dist/index.js +149 -85
  23. package/dist/index.js.map +1 -1
  24. package/dist/legacy.cjs +9 -9
  25. package/dist/legacy.cjs.map +1 -1
  26. package/dist/legacy.js +9 -9
  27. package/dist/legacy.js.map +1 -1
  28. package/dist/worker-entry.cjs +6 -1
  29. package/dist/worker-entry.cjs.map +1 -1
  30. package/package.json +8 -7
  31. package/schema/bitmark.schema.json +823 -4064
  32. package/wasm/bitmark_wasm_bg.wasm +0 -0
  33. package/wasm/package.json +1 -1
  34. package/wasm-bitmark-json/bitmark_json_wasm.d.ts +99 -0
  35. package/wasm-bitmark-json/bitmark_json_wasm.js +491 -0
  36. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
  37. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +19 -0
  38. package/wasm-bitmark-json/package.json +20 -0
package/dist/index.cjs CHANGED
@@ -30,12 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
+ NotInitializedError: () => NotInitializedError,
34
+ UnsupportedFeatureError: () => UnsupportedFeatureError,
33
35
  bitmarkToObjects: () => bitmarkToObjects,
34
36
  breakscapeText: () => breakscapeText,
35
37
  canonicalize: () => canonicalize,
36
38
  convert: () => convert,
37
39
  countBits: () => countBits,
38
40
  info: () => info,
41
+ init: () => init,
42
+ initSync: () => initSync,
39
43
  legacy: () => legacy_exports,
40
44
  lex: () => lex,
41
45
  objectsToBitmark: () => objectsToBitmark,
@@ -44,6 +48,7 @@ __export(src_exports, {
44
48
  transform: () => transform,
45
49
  transformParallel: () => transformParallel,
46
50
  unbreakscapeText: () => unbreakscapeText,
51
+ variant: () => variant,
47
52
  version: () => version
48
53
  });
49
54
  module.exports = __toCommonJS(src_exports);
@@ -58,12 +63,46 @@ var import_node_module = require("module");
58
63
  // src/generated/package_info.ts
59
64
  var PACKAGE_INFO = {
60
65
  "name": "@gmb/bitmark-parser",
61
- "version": "6.9.0",
66
+ "version": "6.10.1",
62
67
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
63
68
  "license": "ISC",
64
69
  "description": "A parser for bitmark text, powered by WebAssembly."
65
70
  };
66
71
 
72
+ // src/core/facade.ts
73
+ var NotInitializedError = class extends Error {
74
+ constructor() {
75
+ super("wasm not initialised: call init() (or init({ feature: \u2026 })) first");
76
+ this.name = "NotInitializedError";
77
+ }
78
+ };
79
+ var UnsupportedFeatureError = class extends Error {
80
+ constructor(what, active2) {
81
+ super(
82
+ `${what} is not available in the loaded wasm module${active2 ? ` (feature: "${active2}")` : ""}; init({ feature: "full" }) to load it`
83
+ );
84
+ this.name = "UnsupportedFeatureError";
85
+ }
86
+ };
87
+ var active;
88
+ var activeFeature;
89
+ var lazyLoader;
90
+ function getActive() {
91
+ if (!active && lazyLoader) lazyLoader();
92
+ if (!active) throw new NotInitializedError();
93
+ return active;
94
+ }
95
+ function setActive(feature, module2) {
96
+ active = module2;
97
+ activeFeature = feature;
98
+ }
99
+ function setLazyLoader(loader) {
100
+ lazyLoader = loader;
101
+ }
102
+ function variant() {
103
+ return activeFeature;
104
+ }
105
+
67
106
  // src/core/hooked-transform.ts
68
107
  function isError(s) {
69
108
  return s.startsWith("error:");
@@ -84,9 +123,9 @@ function normalisePatch(patch) {
84
123
  }
85
124
  return patch;
86
125
  }
87
- function buildUnits(wasm2, input, inputIsBitmark) {
126
+ function buildUnits(wasm, input, inputIsBitmark) {
88
127
  if (inputIsBitmark) {
89
- const out2 = wasm2.split_bits(input);
128
+ const out2 = wasm.split_bits(input);
90
129
  if (isError(out2)) throw new Error(out2);
91
130
  const slices = JSON.parse(out2);
92
131
  return slices.map((s) => ({
@@ -94,7 +133,7 @@ function buildUnits(wasm2, input, inputIsBitmark) {
94
133
  source: s.source
95
134
  }));
96
135
  }
97
- const out = wasm2.split_json_bits(input);
136
+ const out = wasm.split_json_bits(input);
98
137
  if (isError(out)) throw new Error(out);
99
138
  const envelopes = JSON.parse(out);
100
139
  return envelopes.map((env, index) => ({
@@ -103,17 +142,17 @@ function buildUnits(wasm2, input, inputIsBitmark) {
103
142
  source: JSON.stringify([env])
104
143
  }));
105
144
  }
106
- function planTransform(wasm2, input, options) {
145
+ function planTransform(wasm, input, options) {
107
146
  const mode = options.mode ?? "optimized";
108
147
  const output = options.outputFormat ?? "json";
109
148
  const spacesAroundValues = options.spacesAroundValues ?? 1;
110
149
  const indent = options.indent ?? 2;
111
150
  const pretty = options.pretty ?? false;
112
151
  const sel = options.inputFormat ?? "auto";
113
- const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm2.is_bitmark(input);
152
+ const inputIsBitmark = sel === "bitmark" || sel !== "json" && wasm.is_bitmark(input);
114
153
  const inputFormat = inputIsBitmark ? "bitmark" : "json";
115
154
  const staticPatch = normalisePatch(options.patch);
116
- const units = buildUnits(wasm2, input, inputIsBitmark);
155
+ const units = buildUnits(wasm, input, inputIsBitmark);
117
156
  const total = units.length;
118
157
  const jobs = [];
119
158
  const views = [];
@@ -137,8 +176,8 @@ function planTransform(wasm2, input, options) {
137
176
  }
138
177
  return { jobs, views, output, pretty, indent };
139
178
  }
140
- function computeBit(wasm2, job) {
141
- const out = wasm2.transform(
179
+ function computeBit(wasm, job) {
180
+ const out = wasm.transform(
142
181
  job.source,
143
182
  job.inputFormat,
144
183
  job.outputFormat,
@@ -151,33 +190,33 @@ function computeBit(wasm2, job) {
151
190
  if (isError(out)) return out;
152
191
  return job.outputFormat === "json" ? stripArray(out) : out;
153
192
  }
154
- function recombine(wasm2, elements, output, pretty, indent) {
193
+ function recombine(wasm, elements, output, pretty, indent) {
155
194
  if (output === "bitmark" || output === "text") return elements.join("\n");
156
195
  const arr = `[${elements.join(",")}]`;
157
- return pretty ? wasm2.prettify(arr, indent) : arr;
196
+ return pretty ? wasm.prettify(arr, indent) : arr;
158
197
  }
159
- function runHookedTransform(wasm2, input, options) {
198
+ function runHookedTransform(wasm, input, options) {
160
199
  let plan;
161
200
  try {
162
- plan = planTransform(wasm2, input, options);
201
+ plan = planTransform(wasm, input, options);
163
202
  } catch (e) {
164
203
  return errorString(e);
165
204
  }
166
205
  const rendered = [];
167
206
  for (let i = 0; i < plan.jobs.length; i++) {
168
- const element = computeBit(wasm2, plan.jobs[i]);
207
+ const element = computeBit(wasm, plan.jobs[i]);
169
208
  if (isError(element)) return element;
170
209
  options.postHook?.(plan.views[i], element);
171
210
  rendered.push(element);
172
211
  }
173
- return recombine(wasm2, rendered, plan.output, plan.pretty, plan.indent);
212
+ return recombine(wasm, rendered, plan.output, plan.pretty, plan.indent);
174
213
  }
175
214
 
176
215
  // src/core/parallel.ts
177
- async function orchestrateParallel(wasm2, input, options, runJobs) {
216
+ async function orchestrateParallel(wasm, input, options, runJobs) {
178
217
  let plan;
179
218
  try {
180
- plan = planTransform(wasm2, input, options);
219
+ plan = planTransform(wasm, input, options);
181
220
  } catch (e) {
182
221
  return errorString(e);
183
222
  }
@@ -191,7 +230,7 @@ async function orchestrateParallel(wasm2, input, options, runJobs) {
191
230
  if (isError(elements[i])) return elements[i];
192
231
  options.postHook?.(plan.views[i], elements[i]);
193
232
  }
194
- return recombine(wasm2, elements, plan.output, plan.pretty, plan.indent);
233
+ return recombine(wasm, elements, plan.output, plan.pretty, plan.indent);
195
234
  }
196
235
 
197
236
  // src/node/pool.ts
@@ -200,7 +239,7 @@ var import_node_worker_threads = require("worker_threads");
200
239
  function workerPath() {
201
240
  return (0, import_node_url.fileURLToPath)(new URL("./worker-entry.cjs", importMetaUrl));
202
241
  }
203
- function runJobsParallel(jobs, workers) {
242
+ function runJobsParallel(jobs, workers, feature) {
204
243
  if (jobs.length === 0) return Promise.resolve([]);
205
244
  const poolSize = Math.max(1, Math.min(workers, jobs.length));
206
245
  const path2 = workerPath();
@@ -226,7 +265,7 @@ function runJobsParallel(jobs, workers) {
226
265
  w.postMessage({ id, job: jobs[id] });
227
266
  };
228
267
  for (let i = 0; i < poolSize; i++) {
229
- const w = new import_node_worker_threads.Worker(path2);
268
+ const w = new import_node_worker_threads.Worker(path2, { workerData: { feature } });
230
269
  pool.push(w);
231
270
  w.on("message", (res) => {
232
271
  if (done) return;
@@ -254,8 +293,14 @@ function runJobsParallel(jobs, workers) {
254
293
  }
255
294
 
256
295
  // src/node/transform-parallel.ts
257
- function runParallelTransform(wasm2, input, options) {
258
- return orchestrateParallel(wasm2, input, options, runJobsParallel);
296
+ function runParallelTransform(wasm, input, options) {
297
+ const feature = variant() ?? "full";
298
+ return orchestrateParallel(
299
+ wasm,
300
+ input,
301
+ options,
302
+ (jobs, workers) => runJobsParallel(jobs, workers, feature)
303
+ );
259
304
  }
260
305
 
261
306
  // src/node/legacy-init.ts
@@ -263,17 +308,17 @@ var fs = __toESM(require("fs"), 1);
263
308
  var path = __toESM(require("path"), 1);
264
309
 
265
310
  // src/legacy/runtime.ts
266
- var wasmModule;
267
- function setLegacyWasm(wasm2) {
268
- wasmModule = wasm2;
311
+ var wasmProvider;
312
+ function setLegacyWasmProvider(provider) {
313
+ wasmProvider = provider;
269
314
  }
270
315
  function getLegacyWasm() {
271
- if (!wasmModule) {
316
+ if (!wasmProvider) {
272
317
  throw new Error(
273
318
  "legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)"
274
319
  );
275
320
  }
276
- return wasmModule;
321
+ return wasmProvider();
277
322
  }
278
323
  var fileIo;
279
324
  function setLegacyFileIo(io) {
@@ -284,8 +329,8 @@ function getLegacyFileIo() {
284
329
  }
285
330
 
286
331
  // src/node/legacy-init.ts
287
- function initLegacyNode(wasm2) {
288
- setLegacyWasm(wasm2);
332
+ function initLegacyNode(provider) {
333
+ setLegacyWasmProvider(provider);
289
334
  setLegacyFileIo({
290
335
  existsSync: (p) => fs.existsSync(p),
291
336
  readFileSync: (p, encoding) => fs.readFileSync(p, { encoding }),
@@ -476,7 +521,7 @@ var Builder = class {
476
521
  * more than one resource, use the first one").
477
522
  */
478
523
  buildBit(data, _options) {
479
- const wasm2 = getLegacyWasm();
524
+ const wasm = getLegacyWasm();
480
525
  const src = { ...data };
481
526
  const bitType = src.bitType;
482
527
  const bitConfig = this.getBitConfig(bitType);
@@ -537,7 +582,7 @@ var Builder = class {
537
582
  }
538
583
  }
539
584
  this.parseStringTexts(bit);
540
- const out = wasm2.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false);
585
+ const out = wasm.convert(JSON.stringify([{ bit }]), "json", "json", "optimized", false, 2, 1, false, false);
541
586
  if (out.startsWith("error:")) {
542
587
  throw new Error(out.slice("error:".length).trim());
543
588
  }
@@ -593,10 +638,10 @@ var Builder = class {
593
638
  * (bpg TextParser.toAst ignores format; only location matters).
594
639
  */
595
640
  parseStringTexts(bit) {
596
- const wasm2 = getLegacyWasm();
641
+ const wasm = getLegacyWasm();
597
642
  const toAst = (s, location) => {
598
643
  if (s === "") return s;
599
- const out = wasm2.convert_text(s, "textToAst", "bitmark++", location);
644
+ const out = wasm.convert_text(s, "textToAst", "bitmark++", location);
600
645
  try {
601
646
  return JSON.parse(out);
602
647
  } catch {
@@ -626,10 +671,10 @@ var Builder = class {
626
671
  * unknown-bit-type error (`Config.getBitConfig` parity).
627
672
  */
628
673
  getBitConfig(bitType) {
629
- const wasm2 = getLegacyWasm();
674
+ const wasm = getLegacyWasm();
630
675
  if (bitType !== void 0) {
631
676
  try {
632
- const info2 = JSON.parse(wasm2.info("bit", "json", bitType, false, 2, false, false, true));
677
+ const info2 = JSON.parse(wasm.info("bit", "json", bitType, false, 2, false, false, true));
633
678
  if (info2.error === void 0) return { bodyFormat: info2.body?.format };
634
679
  } catch {
635
680
  }
@@ -669,7 +714,7 @@ var BitmarkParserGenerator = class {
669
714
  validateBitmarkOptions(bitmarkOptions);
670
715
  validateJsonOptions(jsonOptions);
671
716
  this.checkBrowserFileWrite(opts.outputFile);
672
- const wasm2 = getLegacyWasm();
717
+ const wasm = getLegacyWasm();
673
718
  const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
674
719
  const outputFormat = opts.outputFormat ?? (isBitmark ? "json" : "bitmark");
675
720
  const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
@@ -677,7 +722,7 @@ var BitmarkParserGenerator = class {
677
722
  const emit = coreFormat === "bitmark" ? prettyIndent(bitmarkOptions.prettifyJson) : { pretty, indent };
678
723
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
679
724
  const includeUnknown = !jsonOptions.excludeUnknownProperties;
680
- const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false);
725
+ const out = wasm.convert(source, isBitmark ? "bitmark" : "json", coreFormat, "optimized", emit.pretty, emit.indent, spaces, includeUnknown, false);
681
726
  this.throwOnError(out);
682
727
  if (outputFormat === "bitmark" || outputFormat === "text") {
683
728
  return this.deliver(out, opts.outputFile, opts.fileOptions);
@@ -705,13 +750,13 @@ var BitmarkParserGenerator = class {
705
750
  validateBitmarkOptions(bitmarkOptions);
706
751
  validateJsonOptions(jsonOptions);
707
752
  this.checkBrowserFileWrite(opts.outputFile);
708
- const wasm2 = getLegacyWasm();
753
+ const wasm = getLegacyWasm();
709
754
  const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
710
755
  const { pretty, indent } = prettyIndent(
711
756
  isBitmark ? bitmarkOptions.prettifyJson : jsonOptions.prettify
712
757
  );
713
758
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
714
- const out = wasm2.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
759
+ const out = wasm.canonicalize(source, isBitmark ? "bitmark" : "json", "optimized", pretty, indent, spaces);
715
760
  this.throwOnError(out);
716
761
  if (isBitmark) return this.deliver(out, opts.outputFile, opts.fileOptions);
717
762
  if (opts.outputFile) return this.deliver(out, opts.outputFile, opts.fileOptions);
@@ -723,12 +768,12 @@ var BitmarkParserGenerator = class {
723
768
  */
724
769
  info(options) {
725
770
  const opts = Object.assign({}, options);
726
- const wasm2 = getLegacyWasm();
771
+ const wasm = getLegacyWasm();
727
772
  const type = opts.type ?? "list";
728
773
  const format = opts.outputFormat ?? "text";
729
774
  const { pretty, indent } = prettyIndent(opts.prettify);
730
775
  const coreFormat = format === "pojo" ? "json" : format;
731
- const out = wasm2.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true);
776
+ const out = wasm.info(type, coreFormat, opts.bit ?? "", pretty, indent, false, false, true);
732
777
  this.throwOnError(out);
733
778
  if (format === "pojo") return JSON.parse(out);
734
779
  return out;
@@ -756,12 +801,12 @@ var BitmarkParserGenerator = class {
756
801
  if (opts.keepUnknownTags) unsupportedOption("keepUnknownTags");
757
802
  if (opts.noBreakscaping) unsupportedOption("noBreakscaping");
758
803
  this.checkBrowserFileWrite(opts.outputFile);
759
- const wasm2 = getLegacyWasm();
804
+ const wasm = getLegacyWasm();
760
805
  const inStr = typeof input === "string" ? this.maybeReadFile(input, void 0) : "";
761
806
  const isHtmlInput = opts.inputFormat === "html" || opts.inputFormat === void 0 && typeof input === "string" && /<table[\s>]/iu.test(inStr);
762
807
  if (!isHtmlInput) {
763
808
  const { source, isBitmark } = this.resolveInput(input, void 0);
764
- const out2 = wasm2.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false);
809
+ const out2 = wasm.convert(source, isBitmark ? "bitmark" : "json", "html", "optimized", false, 2, 1, false, false);
765
810
  this.throwOnError(out2);
766
811
  return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
767
812
  }
@@ -771,12 +816,12 @@ var BitmarkParserGenerator = class {
771
816
  const { pretty, indent } = prettyIndent(jsonOptions.prettify);
772
817
  const spaces = spacesAround(bitmarkOptions.spacesAroundValues);
773
818
  if (outputFormat === "html") {
774
- const out2 = wasm2.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false);
819
+ const out2 = wasm.convert(wrapped, "html", "html", "optimized", false, 2, 1, false, false);
775
820
  this.throwOnError(out2);
776
821
  return this.deliver(extractHtmlTables(out2).join("\n"), opts.outputFile, opts.fileOptions);
777
822
  }
778
823
  const coreFormat = outputFormat === "ast" ? "json" : outputFormat;
779
- const out = wasm2.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false);
824
+ const out = wasm.convert(wrapped, "html", coreFormat, "optimized", pretty, indent, spaces, false, false);
780
825
  this.throwOnError(out);
781
826
  if (outputFormat === "bitmark" || outputFormat === "text") {
782
827
  return this.deliver(out, opts.outputFile, opts.fileOptions);
@@ -799,9 +844,9 @@ var BitmarkParserGenerator = class {
799
844
  */
800
845
  createAst(input, options) {
801
846
  const opts = Object.assign({}, options);
802
- const wasm2 = getLegacyWasm();
847
+ const wasm = getLegacyWasm();
803
848
  const { source, isBitmark } = this.resolveInput(input, opts.inputFormat);
804
- const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false);
849
+ const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "json", "optimized", false, 2, 1, true, false);
805
850
  this.throwOnError(out);
806
851
  return makePseudoAst(JSON.parse(out));
807
852
  }
@@ -812,9 +857,9 @@ var BitmarkParserGenerator = class {
812
857
  if (!input) return input;
813
858
  const opts = Object.assign({}, options);
814
859
  this.checkBrowserFileWrite(opts.outputFile);
815
- const wasm2 = getLegacyWasm();
860
+ const wasm = getLegacyWasm();
816
861
  const inStr = this.maybeReadFile(input, opts.inputFormat);
817
- const res = wasm2.breakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
862
+ const res = wasm.breakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
818
863
  return this.deliver(res, opts.outputFile, opts.fileOptions);
819
864
  }
820
865
  /**
@@ -824,9 +869,9 @@ var BitmarkParserGenerator = class {
824
869
  if (!input) return input;
825
870
  const opts = Object.assign({}, options);
826
871
  this.checkBrowserFileWrite(opts.outputFile);
827
- const wasm2 = getLegacyWasm();
872
+ const wasm = getLegacyWasm();
828
873
  const inStr = this.maybeReadFile(input, opts.inputFormat);
829
- const res = wasm2.unbreakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
874
+ const res = wasm.unbreakscape_text(inStr, mapTextFormat(opts.textFormat), opts.textLocation ?? "body");
830
875
  return this.deliver(res, opts.outputFile, opts.fileOptions);
831
876
  }
832
877
  /**
@@ -840,7 +885,7 @@ var BitmarkParserGenerator = class {
840
885
  const opts = Object.assign({}, options);
841
886
  const jsonOptions = Object.assign({}, opts.jsonOptions);
842
887
  this.checkBrowserFileWrite(opts.outputFile);
843
- const wasm2 = getLegacyWasm();
888
+ const wasm = getLegacyWasm();
844
889
  const isBitmarkText = opts.textFormat === void 0 || mapTextFormat(opts.textFormat) === "bitmark++";
845
890
  const textLocation = opts.textLocation ?? "body";
846
891
  let inStr;
@@ -853,14 +898,14 @@ var BitmarkParserGenerator = class {
853
898
  ast = Array.isArray(input) ? input : void 0;
854
899
  }
855
900
  if (ast !== void 0) {
856
- const out2 = isBitmarkText ? wasm2.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm2.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
901
+ const out2 = isBitmarkText ? wasm.convert_text(JSON.stringify(ast), "astToText", "bitmark++", textLocation) : wasm.convert_text(JSON.stringify(ast), "astToPlainText", "plainText", textLocation);
857
902
  this.throwOnError(out2);
858
903
  return this.deliver(out2, opts.outputFile, opts.fileOptions);
859
904
  }
860
- const out = wasm2.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
905
+ const out = wasm.convert_text(inStr, "textToAst", isBitmarkText ? "bitmark++" : "plainText", "body");
861
906
  this.throwOnError(out);
862
907
  const { pretty, indent } = prettyIndent(jsonOptions.prettify);
863
- const outStr = pretty ? wasm2.prettify(out, indent) : out;
908
+ const outStr = pretty ? wasm.prettify(out, indent) : out;
864
909
  if (opts.outputFile) return this.deliver(outStr, opts.outputFile, opts.fileOptions);
865
910
  if (pretty) return outStr;
866
911
  return JSON.parse(out);
@@ -869,8 +914,8 @@ var BitmarkParserGenerator = class {
869
914
  * Convert a text AST to plain text (bpg-compatible `textAstToPlainText`).
870
915
  */
871
916
  textAstToPlainText(textAst, _options) {
872
- const wasm2 = getLegacyWasm();
873
- const out = wasm2.convert_text(
917
+ const wasm = getLegacyWasm();
918
+ const out = wasm.convert_text(
874
919
  typeof textAst === "string" ? textAst : JSON.stringify(textAst),
875
920
  "astToPlainText",
876
921
  "bitmark++",
@@ -884,17 +929,17 @@ var BitmarkParserGenerator = class {
884
929
  */
885
930
  extractPlainText(input, options) {
886
931
  const inputFormat = options?.inputFormat;
887
- const wasm2 = getLegacyWasm();
932
+ const wasm = getLegacyWasm();
888
933
  if (inputFormat === "plainText") {
889
934
  return typeof input === "string" ? String(input) : "";
890
935
  }
891
936
  if (inputFormat === "bitmarkText") {
892
- const ast = wasm2.convert_text(String(input), "textToAst", "bitmark++", "body");
893
- const out2 = wasm2.convert_text(ast, "astToPlainText", "bitmark++", "body");
937
+ const ast = wasm.convert_text(String(input), "textToAst", "bitmark++", "body");
938
+ const out2 = wasm.convert_text(ast, "astToPlainText", "bitmark++", "body");
894
939
  this.throwOnError(out2);
895
940
  return out2;
896
941
  }
897
- if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm2.is_bitmark(input)) {
942
+ if (typeof input === "string" && this.parseTextAstString(input) === void 0 && !wasm.is_bitmark(input)) {
898
943
  const looksJson = (() => {
899
944
  try {
900
945
  JSON.parse(input);
@@ -908,7 +953,7 @@ var BitmarkParserGenerator = class {
908
953
  }
909
954
  }
910
955
  const { source, isBitmark } = this.resolveInput(input, void 0);
911
- const out = wasm2.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false);
956
+ const out = wasm.convert(source, isBitmark ? "bitmark" : "json", "text", "optimized", false, 2, 1, false, false);
912
957
  this.throwOnError(out);
913
958
  return out;
914
959
  }
@@ -942,8 +987,8 @@ var BitmarkParserGenerator = class {
942
987
  };
943
988
  }
944
989
  const inStr = this.maybeReadFile(input, inputFormat);
945
- const wasm2 = getLegacyWasm();
946
- if (wasm2.is_bitmark(inStr)) return { source: inStr, isBitmark: true };
990
+ const wasm = getLegacyWasm();
991
+ if (wasm.is_bitmark(inStr)) return { source: inStr, isBitmark: true };
947
992
  try {
948
993
  const parsed = JSON.parse(inStr);
949
994
  const entries = this.jsonEntries(parsed);
@@ -1310,8 +1355,8 @@ function bitNameToKey(name) {
1310
1355
  var bitTypeCache;
1311
1356
  function loadBitTypes() {
1312
1357
  if (!bitTypeCache) {
1313
- const wasm2 = getLegacyWasm();
1314
- const all = JSON.parse(wasm2.info("all", "json", "", false, 2, true, false, false));
1358
+ const wasm = getLegacyWasm();
1359
+ const all = JSON.parse(wasm.info("all", "json", "", false, 2, true, false, false));
1315
1360
  const map = { _standard: "_standard" };
1316
1361
  for (const { name } of all) {
1317
1362
  map[bitNameToKey(name)] = name;
@@ -1383,18 +1428,14 @@ function patchEntry(path2, op, value) {
1383
1428
  return value === void 0 ? { path: path2, op } : { path: path2, op, value };
1384
1429
  }
1385
1430
 
1386
- // src/index.ts
1387
- var require2 = (0, import_node_module.createRequire)(importMetaUrl);
1388
- var wasm = require2("../wasm/bitmark_wasm.js");
1389
- initLegacyNode(wasm);
1390
- function version() {
1391
- return PACKAGE_INFO.version;
1392
- }
1431
+ // src/core/api.ts
1393
1432
  function lex(input, options = {}) {
1433
+ const wasm = getActive();
1434
+ if (typeof wasm.lex !== "function") throw new UnsupportedFeatureError("lex", variant());
1394
1435
  return wasm.lex(input, options.stage ?? "lex");
1395
1436
  }
1396
1437
  function bitmarkToObjects(input, options = {}) {
1397
- const out = wasm.convert(
1438
+ const out = getActive().convert(
1398
1439
  input,
1399
1440
  "bitmark",
1400
1441
  "json",
@@ -1412,7 +1453,7 @@ function objectsToBitmark(bits, options = {}) {
1412
1453
  const entries = bits.map(
1413
1454
  (b) => b !== null && typeof b === "object" && "bit" in b && typeof b.bit === "object" ? b : { bit: b }
1414
1455
  );
1415
- const out = wasm.convert(
1456
+ const out = getActive().convert(
1416
1457
  JSON.stringify(entries),
1417
1458
  "json",
1418
1459
  "bitmark",
@@ -1427,7 +1468,7 @@ function objectsToBitmark(bits, options = {}) {
1427
1468
  return out;
1428
1469
  }
1429
1470
  function convert(input, options = {}) {
1430
- return wasm.convert(
1471
+ return getActive().convert(
1431
1472
  input,
1432
1473
  options.inputFormat ?? "auto",
1433
1474
  options.outputFormat ?? "auto",
@@ -1440,7 +1481,7 @@ function convert(input, options = {}) {
1440
1481
  );
1441
1482
  }
1442
1483
  function canonicalize(input, options = {}) {
1443
- return wasm.canonicalize(
1484
+ return getActive().canonicalize(
1444
1485
  input,
1445
1486
  options.inputFormat ?? "auto",
1446
1487
  options.mode ?? "optimized",
@@ -1450,14 +1491,15 @@ function canonicalize(input, options = {}) {
1450
1491
  );
1451
1492
  }
1452
1493
  function countBits(input) {
1453
- const out = wasm.count_bits(input);
1494
+ const out = getActive().count_bits(input);
1454
1495
  if (out.startsWith("error:")) throw new Error(out);
1455
1496
  return Number.parseInt(out, 10);
1456
1497
  }
1457
1498
  function splitBits(input) {
1458
- return JSON.parse(wasm.split_bits(input));
1499
+ return JSON.parse(getActive().split_bits(input));
1459
1500
  }
1460
1501
  function transform(input, options = {}) {
1502
+ const wasm = getActive();
1461
1503
  if (options.preHook || options.postHook) {
1462
1504
  return runHookedTransform(wasm, input, options);
1463
1505
  }
@@ -1473,18 +1515,15 @@ function transform(input, options = {}) {
1473
1515
  options.spacesAroundValues ?? 1
1474
1516
  );
1475
1517
  }
1476
- function transformParallel(input, options = {}) {
1477
- return runParallelTransform(wasm, input, options);
1478
- }
1479
1518
  function breakscapeText(input, options = {}) {
1480
1519
  const format = options.format ?? "bitmark++";
1481
1520
  const location = options.location ?? "body";
1482
- return wasm.breakscape_text(input, format, location);
1521
+ return getActive().breakscape_text(input, format, location);
1483
1522
  }
1484
1523
  function unbreakscapeText(input, options = {}) {
1485
1524
  const format = options.format ?? "bitmark++";
1486
1525
  const location = options.location ?? "body";
1487
- return wasm.unbreakscape_text(input, format, location);
1526
+ return getActive().unbreakscape_text(input, format, location);
1488
1527
  }
1489
1528
  function info(options = {}) {
1490
1529
  const infoType = options.infoType ?? "list";
@@ -1495,16 +1534,45 @@ function info(options = {}) {
1495
1534
  const includeDeprecated = options.includeDeprecated ?? false;
1496
1535
  const onlyDeprecated = options.onlyDeprecated ?? false;
1497
1536
  const full = options.full ?? false;
1498
- return wasm.info(infoType, format, bit, pretty, indent, includeDeprecated, onlyDeprecated, full);
1537
+ return getActive().info(infoType, format, bit, pretty, indent, includeDeprecated, onlyDeprecated, full);
1538
+ }
1539
+
1540
+ // src/index.ts
1541
+ var require2 = (0, import_node_module.createRequire)(importMetaUrl);
1542
+ var VARIANT_GLUE = {
1543
+ full: "../wasm/bitmark_wasm.js",
1544
+ "bitmark-json": "../wasm-bitmark-json/bitmark_json_wasm.js"
1545
+ };
1546
+ function loadVariant(feature) {
1547
+ const module2 = require2(VARIANT_GLUE[feature]);
1548
+ setActive(feature, module2);
1549
+ }
1550
+ setLazyLoader(() => loadVariant("full"));
1551
+ async function init(options = {}) {
1552
+ loadVariant(options.feature ?? "full");
1553
+ }
1554
+ function initSync(options = {}) {
1555
+ loadVariant(options.feature ?? "full");
1556
+ }
1557
+ initLegacyNode(() => getActive());
1558
+ function version() {
1559
+ return PACKAGE_INFO.version;
1560
+ }
1561
+ function transformParallel(input, options = {}) {
1562
+ return runParallelTransform(getActive(), input, options);
1499
1563
  }
1500
1564
  // Annotate the CommonJS export names for ESM import in node:
1501
1565
  0 && (module.exports = {
1566
+ NotInitializedError,
1567
+ UnsupportedFeatureError,
1502
1568
  bitmarkToObjects,
1503
1569
  breakscapeText,
1504
1570
  canonicalize,
1505
1571
  convert,
1506
1572
  countBits,
1507
1573
  info,
1574
+ init,
1575
+ initSync,
1508
1576
  legacy,
1509
1577
  lex,
1510
1578
  objectsToBitmark,
@@ -1513,6 +1581,7 @@ function info(options = {}) {
1513
1581
  transform,
1514
1582
  transformParallel,
1515
1583
  unbreakscapeText,
1584
+ variant,
1516
1585
  version
1517
1586
  });
1518
1587
  //# sourceMappingURL=index.cjs.map