@gmb/bitmark-parser 7.7.0 → 7.9.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.
Files changed (45) hide show
  1. package/README.md +99 -21
  2. package/config/bitmark.json +532 -209
  3. package/dist/browser/bitmark-parser.min.js +6 -6
  4. package/dist/browser/bitmark-parser.min.js.map +1 -1
  5. package/dist/browser/cjs/index.cjs +533 -275
  6. package/dist/browser/cjs/index.cjs.map +1 -1
  7. package/dist/browser/cjs/index.d.cts +103 -22
  8. package/dist/browser/esm/index.d.ts +103 -22
  9. package/dist/browser/esm/index.js +532 -275
  10. package/dist/browser/esm/index.js.map +1 -1
  11. package/dist/browser/esm/worker-entry.js +494 -264
  12. package/dist/browser/esm/worker-entry.js.map +1 -1
  13. package/dist/browser/wasm/bitmark_browser_full_wasm_bg.wasm +0 -0
  14. package/dist/browser/wasm/bitmark_json_wasm_bg.wasm +0 -0
  15. package/dist/browser/wasm/bitmark_wasm_bg.wasm +0 -0
  16. package/dist/index.cjs +43 -8
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +92 -20
  19. package/dist/index.d.ts +92 -20
  20. package/dist/index.js +42 -8
  21. package/dist/index.js.map +1 -1
  22. package/dist/legacy.cjs +19 -11
  23. package/dist/legacy.cjs.map +1 -1
  24. package/dist/legacy.d.cts +3 -1
  25. package/dist/legacy.d.ts +3 -1
  26. package/dist/legacy.js +19 -11
  27. package/dist/legacy.js.map +1 -1
  28. package/dist/worker-entry.cjs.map +1 -1
  29. package/package.json +7 -7
  30. package/schema/bitmark.schema.json +1 -1
  31. package/wasm/bitmark_wasm.d.ts +52 -30
  32. package/wasm/bitmark_wasm.js +209 -113
  33. package/wasm/bitmark_wasm_bg.wasm +0 -0
  34. package/wasm/bitmark_wasm_bg.wasm.d.ts +5 -2
  35. package/wasm/package.json +1 -1
  36. package/wasm-bitmark-json/bitmark_json_wasm.d.ts +73 -51
  37. package/wasm-bitmark-json/bitmark_json_wasm.js +257 -161
  38. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
  39. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +5 -2
  40. package/wasm-bitmark-json/package.json +1 -1
  41. package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +52 -30
  42. package/wasm-browser-full/bitmark_browser_full_wasm.js +209 -113
  43. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
  44. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +5 -2
  45. package/wasm-browser-full/package.json +1 -1
package/dist/index.cjs CHANGED
@@ -59,6 +59,7 @@ __export(src_exports, {
59
59
  resolve: () => resolve,
60
60
  semanticTokens: () => semanticTokens,
61
61
  splitBits: () => splitBits,
62
+ template: () => template,
62
63
  transform: () => transform,
63
64
  transformParallel: () => transformParallel,
64
65
  unbreakscapeText: () => unbreakscapeText,
@@ -77,7 +78,7 @@ var import_node_module = require("module");
77
78
  // src/generated/package_info.ts
78
79
  var PACKAGE_INFO = {
79
80
  "name": "@gmb/bitmark-parser",
80
- "version": "7.7.0",
81
+ "version": "7.9.0",
81
82
  "author": "Get More Brain Ltd <info@getmorebrain.com>",
82
83
  "license": "ISC",
83
84
  "description": "A parser for bitmark text, powered by WebAssembly."
@@ -146,6 +147,9 @@ function setLazyLoader(loader) {
146
147
  function variant() {
147
148
  return activeFeature;
148
149
  }
150
+ function engineVersion(fallback) {
151
+ return active ? active.version() : fallback;
152
+ }
149
153
 
150
154
  // src/core/hooked-transform.ts
151
155
  function stripArray(doc) {
@@ -754,10 +758,12 @@ var BitmarkParserGenerator = class {
754
758
  /**
755
759
  * Get the version of the library.
756
760
  *
757
- * Reports the @gmb/bitmark-parser version (not a bpg version string).
761
+ * Reports the @gmb/bitmark-parser version (not a bpg version string): the
762
+ * one the loaded wasm reports, else the package's own (PLAN-224). Never
763
+ * throws.
758
764
  */
759
765
  version() {
760
- return PACKAGE_INFO.version;
766
+ return engineVersion(PACKAGE_INFO.version);
761
767
  }
762
768
  /**
763
769
  * Convert bitmark from bitmark to JSON, or JSON to bitmark (bpg-compatible).
@@ -1558,9 +1564,15 @@ function convertWithDetails(input, options = {}) {
1558
1564
  const result = { output: details.take_data() };
1559
1565
  const flat = details.bit_spans();
1560
1566
  if (flat !== void 0) {
1561
- const spans = new Array(flat.length / 3);
1562
- for (let i = 0, j = 0; j < flat.length; i++, j += 3) {
1563
- spans[i] = { index: flat[j], start: flat[j + 1], end: flat[j + 2] };
1567
+ const spans = new Array(flat.length / 5);
1568
+ for (let i = 0, j = 0; j < flat.length; i++, j += 5) {
1569
+ spans[i] = {
1570
+ index: flat[j],
1571
+ inputStart: flat[j + 1],
1572
+ inputEnd: flat[j + 2],
1573
+ outputStart: flat[j + 3],
1574
+ outputEnd: flat[j + 4]
1575
+ };
1564
1576
  }
1565
1577
  result.bitSpans = {
1566
1578
  positionEncoding: details.bit_spans_encoding(),
@@ -1601,7 +1613,8 @@ function complete(input, position, options = {}) {
1601
1613
  position.character,
1602
1614
  options.positionEncoding ?? "",
1603
1615
  options.includeDeprecated ?? false,
1604
- options.triggerCharacter ?? ""
1616
+ options.triggerCharacter ?? "",
1617
+ options.bitTemplate ?? false
1605
1618
  )
1606
1619
  );
1607
1620
  }
@@ -1615,6 +1628,7 @@ function resolve(input, position, item, options = {}) {
1615
1628
  position.character,
1616
1629
  options.positionEncoding ?? "",
1617
1630
  options.includeDeprecated ?? false,
1631
+ options.bitTemplate ?? false,
1618
1632
  item.label,
1619
1633
  item.kind
1620
1634
  )
@@ -1722,6 +1736,26 @@ function info(options = {}) {
1722
1736
  language
1723
1737
  );
1724
1738
  }
1739
+ function template(options) {
1740
+ const format = options.format ?? "text";
1741
+ const pretty = options.pretty ?? false;
1742
+ const indent = options.indent ?? 2;
1743
+ const includeDeprecated = options.includeDeprecated ?? false;
1744
+ const wasm = getActive();
1745
+ if (typeof wasm.template !== "function" || typeof wasm.template_all !== "function") {
1746
+ throw new UnsupportedFeatureError("template", variant());
1747
+ }
1748
+ if (options.all) {
1749
+ if (format === "snippet") {
1750
+ throw new Error("template({ all: true }) renders every bit as JSON; there is no snippet form");
1751
+ }
1752
+ return wasm.template_all(includeDeprecated, pretty, indent);
1753
+ }
1754
+ if (!options.bit) {
1755
+ throw new Error("template() needs a bit name, or all: true");
1756
+ }
1757
+ return wasm.template(options.bit, format, options.full ?? false, includeDeprecated, pretty, indent);
1758
+ }
1725
1759
  function register(options) {
1726
1760
  try {
1727
1761
  getActive().register(options.type, options.data);
@@ -1751,7 +1785,7 @@ function initSync(options = {}) {
1751
1785
  }
1752
1786
  initLegacyNode(() => getActive());
1753
1787
  function version() {
1754
- return PACKAGE_INFO.version;
1788
+ return engineVersion(PACKAGE_INFO.version);
1755
1789
  }
1756
1790
  function transformParallel(input, options = {}) {
1757
1791
  return runParallelTransform(
@@ -1791,6 +1825,7 @@ function transformParallel(input, options = {}) {
1791
1825
  resolve,
1792
1826
  semanticTokens,
1793
1827
  splitBits,
1828
+ template,
1794
1829
  transform,
1795
1830
  transformParallel,
1796
1831
  unbreakscapeText,