@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/README.md CHANGED
@@ -71,7 +71,7 @@ runtime — the API surface never changes:
71
71
  | -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------- |
72
72
  | `full` (Node default) | everything: rich `info` metadata + built-in translations + the semantic `diff` | ~1044 KB (~410 KB gzip) |
73
73
  | `browser-full` (browser default) | the same conversions and `diff`, without either | ~855 KB (~353 KB gzip) |
74
- | `bitmark-json` | bitmark ↔ JSON only: `convert`/`canonicalize`/`transform` (formats `auto`/`bitmark`/`json`, plus the `text`, `semantic-tokens` and `diagnostics` outputs), the editor services, `info` (JSON only), breakscape, text fragments — no `diff` | ~629 KB (~256 KB gzip) |
74
+ | `bitmark-json` | bitmark ↔ JSON only: `convert`/`canonicalize`/`transform` (formats `auto`/`bitmark`/`json`, plus the `text`, `semantic-tokens` and `diagnostics` outputs), the editor services, bit templates, `info` (JSON only), breakscape, text fragments — no `diff` | ~629 KB (~256 KB gzip) |
75
75
 
76
76
  **The rule.** _Every build includes every feature, except the two
77
77
  browser-targeted variants, which each carry an explicit exclusion list._ That
@@ -294,8 +294,8 @@ with each extra asked for by a flag in the options. `output` is exactly what
294
294
  one more flag and one more field each.
295
295
 
296
296
  - `bitSpans` — `true` adds `result.bitSpans`, where each top-level bit's text
297
- landed in the output, for linking a source pane to an output pane bit by
298
- bit:
297
+ is in the input and in the output, for linking the panes that show them
298
+ bit by bit — whichever side of the conversion a pane is on:
299
299
 
300
300
  ```ts
301
301
  const { output, bitSpans } = convertWithDetails(source, {
@@ -303,24 +303,32 @@ const { output, bitSpans } = convertWithDetails(source, {
303
303
  outputFormat: "html",
304
304
  bitSpans: true,
305
305
  });
306
- // bitSpans = { positionEncoding: "utf-16", spans: [{ index, start, end }, …] }
307
- for (const { index, start, end } of bitSpans!.spans) {
308
- console.log(index, output.slice(start, end));
306
+ // bitSpans = { positionEncoding: "utf-16",
307
+ // spans: [{ index, inputStart, inputEnd, outputStart, outputEnd }, …] }
308
+ for (const { index, inputStart, inputEnd, outputStart, outputEnd } of bitSpans!.spans) {
309
+ console.log(index, source.slice(inputStart, inputEnd), output.slice(outputStart, outputEnd));
309
310
  }
310
311
  ```
311
312
 
312
313
  - `index` is the bit's position in the **input**: its `splitBits` index for
313
- bitmark input, its entry index in the top-level array for JSON input. An
314
- entry that is not a bit gets no span, so the indexes can have gaps.
315
- - `start` / `end` are **the bit's text**, tight: never the separators
316
- between bits (`\n`, blank lines, `,`) nor the JSON array's `[` / `]`. They
317
- are counted in `positionEncoding` — `"utf-16"` by default, so
318
- `output.slice(start, end)` is the bit — or `"utf-8"` bytes.
319
- - Spans are reported for the document outputs: `bitmark`, `json` (compact or
320
- pretty), `text`, and the markup formats (`html`, `xml`, …). In `bitmark`
321
- output they equal `splitBits(output)`'s `start` / `end`.
314
+ bitmark input, its entry index in the top-level array for JSON input, its
315
+ position among the bits the import finds for markup input. An entry that
316
+ is not a bit gets no span, so the indexes can have gaps.
317
+ - Each side is **the bit's text**, tight: never the separators between bits
318
+ (`\n`, blank lines, `,`) nor the JSON array's `[` / `]`. Both are counted
319
+ in `positionEncoding` — `"utf-16"` by default, so
320
+ `output.slice(outputStart, outputEnd)` is the bit — or `"utf-8"` bytes.
321
+ - `inputStart` / `inputEnd`: for bitmark input, the bit's `splitBits`
322
+ `start` / `end`; for JSON, its top-level entry; for markup, the element it
323
+ was read from — one that holds the next bit's element (a NISO section
324
+ around its paragraphs) ends where that element starts. Converting an
325
+ output back gives input spans equal to the output spans it was written
326
+ with.
327
+ - Output spans are reported for the document outputs: `bitmark`, `json`
328
+ (compact or pretty), `text`, and the markup formats (`html`, `xml`, …). In
329
+ `bitmark` output they equal `splitBits(output)`'s `start` / `end`.
322
330
  - A bit that writes nothing (an empty or `_error` bit in `text`) gets a
323
- zero-width span where its text would start.
331
+ zero-width output span where its text would start.
324
332
  - Only top-level bits get spans. For any other output (`lex`, `ast`,
325
333
  `semantic-tokens`, `diagnostics`, a mapping report) `bitSpans` is present
326
334
  with `spans: []`; without the flag it is absent.
@@ -744,6 +752,56 @@ Unbreakscape text (unescape bitmark special characters).
744
752
  For `bitmark++` the rule is "remove one caret from each run" whatever the
745
753
  context, so a single inverse undoes every breakscape mode.
746
754
 
755
+ #### template(options: TemplateOptions): string
756
+
757
+ The template of a bit (PLAN-225): an empty, config-filtered skeleton — the
758
+ header, the tags an author usually writes (required ones, and those the config
759
+ flags `template`) with their chains, the body, and the card structure (one
760
+ card, every side, the first variant). Every value is the tag's default, so the
761
+ plain rendering parses and canonicalizes cleanly.
762
+
763
+ - `bit` — the bit name; required unless `all` is set
764
+ - `format` — `"text"` (default; plain bitmark), `"snippet"` (an LSP snippet,
765
+ `insertTextFormat: 2`: `${n:default}` per value, a choice for enums and
766
+ booleans with the default first, labelled body placeholders, `$0` last), or
767
+ `"json"` (the slot model — `bit`, `attachment`, `tags[]` with `name`,
768
+ `format`, `default`, `values`, `required`, `chain`; `body`; `card` with its
769
+ `sides` — plus the `text` and `snippet` renderings)
770
+ - `full` — every tag in the bit's set plus the head chain of every resource
771
+ type the bit may attach: a diagnostic dump, expected to validate with
772
+ warnings (default `false`)
773
+ - `includeDeprecated` — keep deprecated tags (and, with `all`, deprecated bits)
774
+ - `all` — every bit as one JSON object `{ [bit]: { normal, full } }`, whatever
775
+ `format` says (`"snippet"` throws)
776
+ - `pretty` / `indent` — JSON formatting
777
+
778
+ ```ts
779
+ template({ bit: "multiple-choice" });
780
+ // [.multiple-choice]
781
+ // [@revealSolutions:false]
782
+ // [@additionalSolutions:]
783
+ //
784
+ // ====
785
+ // [+]
786
+ // [-]
787
+ // ====
788
+ template({ bit: "quote", format: "snippet" });
789
+ // [.quote]\n[@quotedPerson:${1}]\n${2:body}\n$0
790
+ JSON.parse(template({ bit: "image", format: "json" })).tags[0].name; // "&image"
791
+ ```
792
+
793
+ Which tags are "usual" is configuration: a `template` member on a tag entry
794
+ (`true`, `false`, or `{ "only": { "bits": [...], "bitGroups": [...] } }` /
795
+ `{ "except": … }`), resolved by `bitmark-confgen` into a per-bit flag the
796
+ `info` views show as `template: true`. Required tags are always in the
797
+ template. A resource head flagged for a bit that can only reach it through a
798
+ header attachment puts the attachment in the header (`[.article&image]`).
799
+
800
+ `complete(input, position, { bitTemplate: true })` makes a bit-type item
801
+ insert the bit's normal snippet from the name onward (`article]⏎…`) — the
802
+ editor must then replace a `]` it auto-closed after the cursor. Available in
803
+ every wasm variant.
804
+
747
805
  #### info(options?: InfoOptions): string
748
806
 
749
807
  Query information about supported bit types. `"bit"`/`"all"` default to a
@@ -919,7 +977,9 @@ The normative definition of the JSON is
919
977
 
920
978
  #### version(): string
921
979
 
922
- Return the library version string.
980
+ Return the library version string: the version the loaded wasm reports, so
981
+ it is the parser actually running. Before a wasm is loaded (in the browser,
982
+ before `init()`), the package's own version. Never throws.
923
983
 
924
984
  ### Typed API (generated types)
925
985
 
@@ -1081,7 +1141,8 @@ Differences (all loud, never silent):
1081
1141
  at the boundary). The markup produced _inside_ `<table>` follows this
1082
1142
  parser's html mapping and may differ from bpg's in detail.
1083
1143
  `keepUnknownTags` / `noBreakscaping` throw.
1084
- - `version()` reports this package's version (6.x), not a bpg version.
1144
+ - `version()` reports this package's version (the loaded wasm's), not a bpg
1145
+ version.
1085
1146
 
1086
1147
  ## CLI
1087
1148
 
@@ -1135,8 +1196,9 @@ bitmark convert input.bitmark --output-format semantic-tokens --tokens-layout ab
1135
1196
  # Dump the lexer token stream as JSON (debug tooling; bitmark input only)
1136
1197
  bitmark convert input.bitmark --input-format bitmark --output-format lex --pretty
1137
1198
 
1138
- # Also write where each bit landed in the output, {positionEncoding, spans},
1139
- # to its own file (offsets into this run's output; --position-encoding applies)
1199
+ # Also write where each bit is in the input and in the output,
1200
+ # {positionEncoding, spans}, to its own file (output offsets into this run's
1201
+ # output; --position-encoding applies)
1140
1202
  bitmark convert input.bitmark --output-format html -o out.html --bit-spans spans.json
1141
1203
 
1142
1204
  # Breakscape / unbreakscape text
@@ -1154,8 +1216,16 @@ bitmark info all -f json --pretty
1154
1216
  bitmark info --bit article # compact: one line per tag (format, count, default)
1155
1217
  bitmark info --bit article --full # full detail: defaults, provenance, keys, card set
1156
1218
  bitmark info deprecated # deprecated bits + migration targets
1157
- bitmark info list --all # include deprecated bits in the listing
1219
+ bitmark info list --include-deprecated # include deprecated bits in the listing
1158
1220
  bitmark info list --deprecated # only deprecated bits
1221
+
1222
+ # A bit's template: the tags an author usually writes, the body and the card
1223
+ # structure (PLAN-225) — plain bitmark, an LSP snippet, or JSON
1224
+ bitmark template --bit multiple-choice
1225
+ bitmark template --bit flashcard -f snippet
1226
+ bitmark template --bit article --full # every tag + every attachable resource chain
1227
+ bitmark template --all --pretty # every bit, both modes, keyed by name (JSON)
1228
+ bitmark editor complete input.bitmark --line 0 --character 2 --bit-template # bit items insert their template
1159
1229
  ```
1160
1230
 
1161
1231
  All commands support `-o, --output <file>` and `-a, --append` flags. Commands that accept input support file paths, literal strings, or stdin (when no arguments are given).
@@ -1187,6 +1257,14 @@ selected variant's `.wasm` (from `dist/browser/wasm/`). A bare `init()` loads
1187
1257
  build, and a later `init({ feature: "full" })` upgrades in place (see _WASM
1188
1258
  variants_).
1189
1259
 
1260
+ The script and the `.wasm` are one release. Loaded through a version alias
1261
+ such as `@latest`, the script fetches the `.wasm` from the path pinned to its
1262
+ own version (`…/@gmb/bitmark-parser@<version>/…`), so a script served from a
1263
+ CDN cache after a release never drives the new release's wasm. `init()`
1264
+ rejects a `.wasm` of another version (`version-mismatch: …`) rather than
1265
+ running it; the glue can be instantiated once per page, so a reload is the
1266
+ remedy.
1267
+
1190
1268
  ### Bundler (webpack / vite)
1191
1269
 
1192
1270
  ```js