@gmb/bitmark-parser 6.1.4 → 6.3.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 CHANGED
@@ -1,6 +1,4 @@
1
- # @gmb/bitmark-parser
2
-
3
- A high-performance parser for [bitmark](https://docs.bitmark.cloud/), powered by WebAssembly. Provides both a programmatic API and a CLI for converting between bitmark markup and JSON.
1
+ A high-performance parser and generator for [bitmark](https://docs.bitmark.cloud/). Provides a programmatic API (powered by WebAssembly) and a CLI (prebuilt native binary per platform) for converting between bitmark markup and JSON.
4
2
 
5
3
  ## Installation
6
4
 
@@ -11,17 +9,18 @@ npm install @gmb/bitmark-parser
11
9
  ## Programmatic API (Node.js)
12
10
 
13
11
  ```js
14
- import { convert, parse, lex, breakscapeText, unbreakscapeText, info, version } from "@gmb/bitmark-parser";
12
+ import { convert, lex, breakscapeText, unbreakscapeText, info, version } from "@gmb/bitmark-parser";
15
13
 
16
- // Convert bitmark to JSON (auto-detects input format)
17
- const json = convert("[.article]\nHello **bold**", { warnings: true });
14
+ // Convert bitmark to JSON — set inputFormat explicitly when known (skips
15
+ // auto-detection); "auto" also works but costs an extra scan
16
+ const json = convert("[.article]\nHello **bold**", { inputFormat: "bitmark", warnings: true });
18
17
  const parsedJson = JSON.parse(json);
19
18
  console.log(parsedJson[0].bit.type);
20
19
  console.log(parsedJson[0].parser.warnings);
21
20
  console.log(parsedJson[0].bitmark);
22
21
 
23
- // Parse bitmark to JSON (same as convert for bitmark input)
24
- const parsed = parse("[.article]\nHello **bold**", { mode: "full" });
22
+ // Generate bitmark from JSON
23
+ const bitmark = convert(json, { inputFormat: "json", outputFormat: "bitmark" });
25
24
 
26
25
  // Lex bitmark to token dump
27
26
  const tokens = lex("[.article]\nHello **bold**");
@@ -30,8 +29,8 @@ const tokens = lex("[.article]\nHello **bold**");
30
29
  const tokenJson = lex("[.article]\nHello **bold**", { stage: "lex-json" });
31
30
 
32
31
  // Breakscape / unbreakscape text
33
- const escaped = breakscapeText("[!example]", "bitmark++", "body");
34
- const unescaped = unbreakscapeText(escaped, "bitmark++", "body");
32
+ const escaped = breakscapeText("[!example]", { format: "bitmark++", location: "body" });
33
+ const unescaped = unbreakscapeText(escaped, { format: "bitmark++", location: "body" });
35
34
 
36
35
  // Query supported bit types
37
36
  const bitInfo = info({ infoType: "list", format: "text" });
@@ -42,49 +41,82 @@ console.log(version());
42
41
 
43
42
  ### API
44
43
 
45
- #### `convert(input: string, options?: ConvertOptions): string`
44
+ #### convert(input: string, options?: ConvertOptions): string
46
45
 
47
- Auto-detect input format and convert between bitmark and JSON.
46
+ Convert between bitmark, JSON, and the mapped markup formats (html/xml/…).
48
47
 
49
- Options (passed as a JSON string):
48
+ Options:
49
+ - `inputFormat` — `"auto"` (default), `"bitmark"`, `"json"`, or a mapping id (`"html"`, `"xml"`, …)
50
+ - `outputFormat` — `"auto"` (default: the opposite direction), `"text"` (lossy plain-text extraction; output-only), or as above
50
51
  - `mode` — `"optimized"` (default) or `"full"`
51
52
  - `warnings` — include validation warnings (default: `false`)
52
53
  - `plainText` — output text as plain text (default: `false`)
53
- - `pretty` — prettify JSON output (default: `false`)
54
+ - `pretty` — prettify the emitted JSON (default: `false`). For JSON output this
55
+ is the whole document; for bitmark output it pretty-prints the embedded JSON
56
+ bodies of `json`-format bits (cosmetic — they re-parse to the same value)
54
57
  - `indent` — indent size for pretty JSON (default: `2`)
58
+ - `includeUnknownProperties` — bitmark → JSON only (default: `false`): include
59
+ unknown properties in the bit JSON. An unknown property (`[@key:value]` the
60
+ bit's config cannot resolve, at the bit body/footer — never inside cards or
61
+ consumed by a chain) is appended after all real keys as an array of strings
62
+ (a valueless `[@key]` → `true`); a key colliding with a configured key of
63
+ the bit is `_`-prefixed. Unknown properties are never converted back to
64
+ bitmark, and each occurrence warns whether or not it is included.
65
+ Also available on `bitmarkToObjects` and as the CLI's
66
+ `--include-unknown-properties`
67
+
68
+ > **Performance:** `inputFormat: "auto"` detects the format by scanning the
69
+ > input for a bitmark bit header — for non-bitmark input that is a full pass
70
+ > over the whole input before parsing starts, and the detection is a
71
+ > heuristic (markup formats are never auto-detected). If you know the input
72
+ > format, set `inputFormat` explicitly. The same applies to `canonicalize`
73
+ > and `transform`, whose `inputFormat` also defaults to `"auto"`.
74
+
75
+ `convert` is the single string-based conversion surface — parsing is
76
+ `{ inputFormat: "bitmark", outputFormat: "json" }`, generating is
77
+ `{ inputFormat: "json", outputFormat: "bitmark" }`. For typed objects use
78
+ `bitmarkToObjects` / `objectsToBitmark` (below), which pin their formats.
55
79
 
56
80
  For bitmark input, output is a JSON array of entries with:
57
81
  - `bit` — serialized bit payload
58
- - `parser` — parser metadata and `warnings`
82
+ - `parser` — parser metadata, `errors` / `warnings`, and `infos` (informational notices for recoveries that are not necessarily wrong, e.g. text kept as text because it only looks like an unclosed tag)
59
83
  - `bitmark` — source bitmark text
60
84
 
61
- #### `parse(input: string, options?: ParseOptions): string`
85
+ #### canonicalize(input: string, options?: CanonicalizeOptions): string
86
+
87
+ Re-emit input in its own format in canonical form — the single same-format surface. `mode`: `"optimized"` (default, omit natural defaults) or `"full"` (all keys).
88
+
89
+ #### transform(input: string, options?: TransformOptions): string
90
+
91
+ Apply path patches to each bit (per-bit transform pipeline; build patches with `patchEntry`). `transformParallel` is the worker-thread variant returning a `Promise<string>`.
62
92
 
63
- Parse bitmark text and return structured JSON entries (`bit`, `parser`, `bitmark`).
93
+ #### countBits(input: string): number / splitBits(input: string): BitSlice[]
64
94
 
65
- #### `lex(input: string, stage?: string): string`
95
+ Count or split the bits of a bitmark/JSON input without full parsing.
66
96
 
67
- Lex bitmark text and return one token per line.
97
+ #### lex(input: string, options?: LexOptions): string
68
98
 
69
- Stages:
70
- - `"lex"` — Unified lexer token stream (default)
99
+ Lex bitmark text.
100
+
101
+ Stages (`options.stage`):
102
+ - `"lex"` — Unified lexer token stream, one token per line (default)
71
103
  - `"lex-json"` — Unified lexer token stream as JSON
72
104
 
73
- #### `breakscapeText(input: string, options?: BreakscapeOptions): string`
105
+ #### breakscapeText(input: string, options?: BreakscapeOptions): string
74
106
 
75
107
  Breakscape text (escape bitmark special characters).
76
108
 
77
109
  - `format` — `"bitmark++"` (default) or `"plainText"`
78
110
  - `location` — `"body"` (default) or `"tag"`
79
111
 
80
- #### `unbreakscapeText(input: string, options?: BreakscapeOptions): string`
112
+ #### unbreakscapeText(input: string, options?: BreakscapeOptions): string
81
113
 
82
114
  Unbreakscape text (unescape bitmark special characters).
83
115
 
84
116
  - `format` — `"bitmark++"` (default) or `"plainText"`
85
117
  - `location` — `"body"` (default) or `"tag"`
86
118
 
87
- #### `info(options?: InfoOptions): string`
119
+ #### info(options?: InfoOptions): string
88
120
 
89
121
  Query information about supported bit types.
90
122
 
@@ -94,13 +126,43 @@ Query information about supported bit types.
94
126
  - `pretty` — prettify JSON output (default: `false`)
95
127
  - `indent` — indent size for pretty JSON (default: `2`)
96
128
 
97
- #### `version(): string`
129
+ #### version(): string
98
130
 
99
131
  Return the library version string.
100
132
 
101
- #### `generate(json: string): string`
133
+ ### Typed API (generated types)
134
+
135
+ TypeScript types for the parser's JSON are **generated from `bitmark.json`**
136
+ (`npm run schema:ts`, automatic in the build): per-bit types (`ArticleBit`,
137
+ `ClozeBit`, …) form the `Bit` discriminated union (narrow on `bit.type`),
138
+ `AnyBit` is the loose merged view, `BitEntry` is the `{bit, parser?, bitmark?}`
139
+ envelope, and resource/card content have named types (`ImageResource`,
140
+ `FlashcardBitCard`, …).
141
+
142
+ ```ts
143
+ import { bitmarkToObjects, objectsToBitmark, patchEntry, type ArticleBit } from "@gmb/bitmark-parser";
144
+
145
+ // bitmark → typed entries
146
+ const entries = bitmarkToObjects("[.article]\nHello **world**");
147
+ if (entries[0].bit.type === "article") console.log(entries[0].bit.body);
148
+
149
+ // author bits as typed literals (no builder needed) → bitmark
150
+ const article: ArticleBit = { type: "article", body: "Hello" };
151
+ const bitmark = objectsToBitmark([article]);
152
+
153
+ // typed round-trip editing
154
+ entries[0].bit.id = ["42"];
155
+ const edited = objectsToBitmark(entries);
156
+
157
+ // patch values typed from the literal path
158
+ const patch = patchEntry("id", "append", "1234");
159
+ ```
102
160
 
103
- Generate bitmark text from JSON. **Not yet implemented** — throws an error.
161
+ See `examples/` for runnable scripts covering the whole API (executed by
162
+ `npm test`, so they stay correct). Generated API documentation (TypeDoc) is
163
+ published at <https://getmorebrain.github.io/bitmark-parser-rust/> with each
164
+ release, or build it locally with `npm run docs` (→ `docs/api/`) and preview
165
+ it with `npm run docs:serve` (http://localhost:8080, `--port` to change).
104
166
 
105
167
  ## Legacy API (bpg-compatible)
106
168
 
@@ -132,15 +194,29 @@ Differences (all loud, never silent):
132
194
  `jsonOptions.textAsPlainText: true` throw.
133
195
  - **Strict option policy** — options with no equivalent here throw a
134
196
  `LegacyUnsupportedError` naming the option (`explicitTextFormat`,
135
- `prettifyJson`, `noBreakscaping`, `excludeUnknownProperties`,
136
- `debugGenerationInline`). Exception: `bitmarkParserType` is accepted and
137
- ignored — bpg itself ignores it. `jsonOptions.enableWarnings` is accepted
138
- (parser warnings are always carried in the output envelope).
197
+ `noBreakscaping`, `debugGenerationInline`).
198
+ The option **types** are narrowed to the supported values too (e.g.
199
+ `bitmarkVersion?: 3`, `noBreakscaping?: false`), so TypeScript consumers
200
+ get a build-time error rather than only the runtime throw — JS callers
201
+ still get the loud runtime error. Exception: `bitmarkParserType` is
202
+ accepted and ignored — bpg itself ignores it. `jsonOptions.enableWarnings`
203
+ is accepted (parser warnings are always carried in the output envelope).
204
+ `bitmarkOptions.prettifyJson` is honoured (pretty-prints the embedded JSON
205
+ bodies of `json`-format bits in bitmark output, as bpg did).
206
+ - **Unknown properties** — included in JSON output by default and excludable
207
+ via `jsonOptions.excludeUnknownProperties`, exactly as bpg (arrays, last
208
+ keys, `_`-prefix on collision with a real key, never converted back to
209
+ bitmark). One deliberate divergence: the per-occurrence warning text names
210
+ the new API's inverse flag (`includeUnknownProperties`), not bpg's
211
+ `excludeUnknownProperties`.
139
212
  - **The AST is bit JSON** — `createAst` / `Output.ast` /
140
213
  `Builder.buildBit` produce the bit JSON ("pseudo-AST"), not bpg's
141
214
  internal TS node model. It round-trips through `convert`, but bpg's
142
215
  `Ast` walker (and the generator/parser/writer internals) throw as
143
- unsupported.
216
+ unsupported. `buildBit`'s `resources` input follows bpg's routing:
217
+ on bits whose config maps a repeatable resource group onto a collection
218
+ key (e.g. `images` / `logos`), the entries land under that key; on other
219
+ bits the first entry becomes the single `resource` (as bpg).
144
220
  - **`convertHtmlTable`** converts HTML `<table>` markup ↔ table bits via
145
221
  the core's html mapping (the `<bitmark-bit>` envelope is added/stripped
146
222
  at the boundary). The markup produced *inside* `<table>` follows this
@@ -163,16 +239,26 @@ bitmark convert input.json -o output.bitmark
163
239
  # Convert with options
164
240
  bitmark convert input.bitmark --mode full --pretty --warnings
165
241
 
242
+ # Include unknown properties in the bit JSON (bitmark → JSON only)
243
+ bitmark convert input.bitmark --include-unknown-properties
244
+
166
245
  # Parse a bitmark file to JSON
167
- bitmark parse input.bitmark
168
- bitmark parse input.bitmark -o output.json
169
- bitmark parse input.bitmark --mode full
246
+ bitmark convert input.bitmark --input-format bitmark --output-format json
247
+ bitmark convert input.bitmark --input-format bitmark -o output.json
248
+ bitmark convert input.bitmark --input-format bitmark --output-format json --mode full
249
+
250
+ # Generate bitmark from JSON
251
+ bitmark convert input.json --input-format json --output-format bitmark -o output.bitmark
170
252
 
171
- # Lex instead of parse
172
- bitmark parse --stage=lex input.bitmark
253
+ # Re-emit in the same format at optimized / full mode (canonical form)
254
+ bitmark canonicalize input.bitmark
255
+ bitmark canonicalize input.json --mode full
173
256
 
174
- # Available stages: all (default), lex
175
- bitmark parse --stage=lex input.bitmark
257
+ # Apply path patches to each bit
258
+ bitmark transform input.json --patch patches.json # alias: patch
259
+
260
+ # Dump the lexer token stream
261
+ bitmark lex input.bitmark
176
262
 
177
263
  # Breakscape / unbreakscape text
178
264
  bitmark breakscape input.txt
@@ -183,9 +269,6 @@ bitmark unbreakscape input.txt
183
269
  bitmark info
184
270
  bitmark info all -f json --pretty
185
271
  bitmark info bit --bit article
186
-
187
- # Generate bitmark from JSON (not yet implemented)
188
- bitmark generate input.json output.bitmark
189
272
  ```
190
273
 
191
274
  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).
@@ -198,11 +281,11 @@ The package includes pre-built browser bundles with the WASM module.
198
281
 
199
282
  ```html
200
283
  <script type="module">
201
- import init, { parse } from "https://cdn.jsdelivr.net/npm/@gmb/bitmark-parser@latest/dist/browser/bitmark-parser.min.js";
284
+ import init, { convert } from "https://cdn.jsdelivr.net/npm/@gmb/bitmark-parser@latest/dist/browser/bitmark-parser.min.js";
202
285
 
203
286
  await init();
204
287
 
205
- const json = parse("[.article]\nHello **bold**");
288
+ const json = convert("[.article]\nHello **bold**", { inputFormat: "bitmark" });
206
289
  console.log(json);
207
290
  </script>
208
291
  ```
@@ -210,10 +293,10 @@ The package includes pre-built browser bundles with the WASM module.
210
293
  ### Bundler (webpack / vite)
211
294
 
212
295
  ```js
213
- import init, { parse, lex } from "@gmb/bitmark-parser/browser";
296
+ import init, { convert, lex } from "@gmb/bitmark-parser/browser";
214
297
 
215
298
  await init();
216
- const json = parse("[.article]\nHello");
299
+ const json = convert("[.article]\nHello", { inputFormat: "bitmark" });
217
300
  ```
218
301
 
219
302
  ## License
@@ -1,5 +1,5 @@
1
- var Ot=Object.defineProperty;var pe=(e,t,r)=>t in e?Ot(e,t,{enumerable:true,configurable:true,writable:true,value:r}):e[t]=r;var Tt=(e,t)=>{for(var r in t)Ot(e,r,{get:t[r],enumerable:true});};var O=(e,t,r)=>pe(e,typeof t!="symbol"?t+"":t,r);var H={};Tt(H,{breakscape_text:()=>ot,canonicalize:()=>dt,convert:()=>pt,convert_text:()=>le,count_bits:()=>lt,default:()=>mt,fullize:()=>ct,info:()=>at,initSync:()=>Et,is_bitmark:()=>ge,lex:()=>nt,optimize:()=>ut,parse:()=>rt,prettify:()=>de,split_bits:()=>gt,split_json_bits:()=>ce,transform:()=>st,unbreakscape_text:()=>it});var s,f=0,V=null;function z(){return (V===null||V.byteLength===0)&&(V=new Uint8Array(s.memory.buffer)),V}var D=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},ue=typeof D.encodeInto=="function"?function(e,t){return D.encodeInto(e,t)}:function(e,t){let r=D.encode(e);return t.set(r),{read:e.length,written:r.length}};function _(e,t,r){if(r===void 0){let p=D.encode(e),u=t(p.length,1)>>>0;return z().subarray(u,u+p.length).set(p),f=p.length,u}let n=e.length,o=t(n,1)>>>0,a=z(),i=0;for(;i<n;i++){let p=e.charCodeAt(i);if(p>127)break;a[o+i]=p;}if(i!==n){i!==0&&(e=e.slice(i)),o=r(o,n,n=i+e.length*3,1)>>>0;let p=z().subarray(o+i,o+n),u=ue(e,p);i+=u.written,o=r(o,n,i,1)>>>0;}return f=i,o}var L=null;function x(){return (L===null||L.buffer.detached===true||L.buffer.detached===void 0&&L.buffer!==s.memory.buffer)&&(L=new DataView(s.memory.buffer)),L}var vt=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&vt.decode();function E(e,t){return e=e>>>0,vt.decode(z().subarray(e,e+t))}function nt(e,t){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),u=f,c=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f;s.lex(i,p,u,c,d);var o=x().getInt32(i+0,!0),a=x().getInt32(i+4,!0);return r=o,n=a,E(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function rt(e,t){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),u=f,c=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f;s.parse(i,p,u,c,d);var o=x().getInt32(i+0,!0),a=x().getInt32(i+4,!0);return r=o,n=a,E(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function ot(e,t,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),c=f,d=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),l=f,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f;s.breakscape_text(p,u,c,d,l,g,k);var a=x().getInt32(p+0,!0),i=x().getInt32(p+4,!0);return n=a,o=i,E(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function it(e,t,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),c=f,d=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),l=f,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f;s.unbreakscape_text(p,u,c,d,l,g,k);var a=x().getInt32(p+0,!0),i=x().getInt32(p+4,!0);return n=a,o=i,E(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function ce(e){let t,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),p=f;s.split_json_bits(a,i,p);var n=x().getInt32(a+0,!0),o=x().getInt32(a+4,!0);return t=n,r=o,E(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(t,r,1);}}function de(e,t){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),u=f;s.prettify(i,p,u,t);var o=x().getInt32(i+0,!0),a=x().getInt32(i+4,!0);return r=o,n=a,E(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function le(e,t,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f,l=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f,k=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),m=f,y=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),b=f;s.convert_text(u,c,d,l,g,k,m,y,b);var i=x().getInt32(u+0,!0),p=x().getInt32(u+4,!0);return o=i,a=p,E(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}function st(e,t,r,n,o,a,i,p){let u,c;try{let g=s.__wbindgen_add_to_stack_pointer(-16),k=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),m=f,y=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),b=f,v=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),S=f,j=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),J=f,se=_(o,s.__wbindgen_export_0,s.__wbindgen_export_1),ae=f;s.transform(g,k,m,y,b,v,S,j,J,se,ae,a,i,p);var d=x().getInt32(g+0,!0),l=x().getInt32(g+4,!0);return u=d,c=l,E(d,l)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(u,c,1);}}function at(e,t,r,n,o){let a,i;try{let c=s.__wbindgen_add_to_stack_pointer(-16),d=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),l=f,g=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f,m=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),y=f;s.info(c,d,l,g,k,m,y,n,o);var p=x().getInt32(c+0,!0),u=x().getInt32(c+4,!0);return a=p,i=u,E(p,u)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(a,i,1);}}function pt(e,t,r,n,o,a,i){let p,u;try{let l=s.__wbindgen_add_to_stack_pointer(-16),g=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f,m=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),y=f,b=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),v=f,S=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),j=f;s.convert(l,g,k,m,y,b,v,S,j,o,a,i);var c=x().getInt32(l+0,!0),d=x().getInt32(l+4,!0);return p=c,u=d,E(c,d)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(p,u,1);}}function ut(e,t,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f,l=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f;s.optimize(u,c,d,l,g,r,n);var i=x().getInt32(u+0,!0),p=x().getInt32(u+4,!0);return o=i,a=p,E(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}function ct(e,t,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f,l=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f;s.fullize(u,c,d,l,g,r,n);var i=x().getInt32(u+0,!0),p=x().getInt32(u+4,!0);return o=i,a=p,E(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}function dt(e,t,r,n,o,a){let i,p;try{let d=s.__wbindgen_add_to_stack_pointer(-16),l=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f,k=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),m=f,y=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),b=f;s.canonicalize(d,l,g,k,m,y,b,n,o,a);var u=x().getInt32(d+0,!0),c=x().getInt32(d+4,!0);return i=u,p=c,E(u,c)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(i,p,1);}}function lt(e){let t,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),p=f;s.count_bits(a,i,p);var n=x().getInt32(a+0,!0),o=x().getInt32(a+4,!0);return t=n,r=o,E(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(t,r,1);}}function gt(e){let t,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),p=f;s.split_bits(a,i,p);var n=x().getInt32(a+0,!0),o=x().getInt32(a+4,!0);return t=n,r=o,E(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(t,r,1);}}function ge(e){let t=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),r=f;return s.is_bitmark(t,r)!==0}async function me(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(n){if(e.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n);else throw n}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else {let r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}}function Ft(){let e={};return e.wbg={},e}function Rt(e,t){return s=e.exports,Bt.__wbindgen_wasm_module=t,L=null,V=null,s}function Et(e){if(s!==void 0)return s;typeof e<"u"&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=Ft();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));let r=new WebAssembly.Instance(e,t);return Rt(r,e)}async function Bt(e){if(s!==void 0)return s;typeof e<"u"&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof e>"u"&&(e=new URL("bitmark_wasm_bg.wasm",import.meta.url));let t=Ft();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:n}=await me(await e,t);return Rt(r,n)}var mt=Bt;var G={version:"6.1.4"};function W(e){return e.startsWith("error:")}function K(e){let t=e instanceof Error?e.message:String(e);return t.startsWith("error:")?t:`error: ${t}`}function fe(e){let t=e.trim();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):e}function _e(e){if(e===void 0)return [];if(typeof e=="string"){let t=e.trim();return t===""?[]:JSON.parse(t)}return e}function be(e,t,r){if(r){let a=e.split_bits(t);if(W(a))throw new Error(a);let i=JSON.parse(a);return i.map(p=>({view:{format:"bitmark",index:p.index,total:i.length,source:p.source},source:p.source}))}let n=e.split_json_bits(t);if(W(n))throw new Error(n);let o=JSON.parse(n);return o.map((a,i)=>({view:{format:"json",index:i,total:o.length,bit:a.bit},source:JSON.stringify([a])}))}function ft(e,t,r){let n=r.mode??"optimized",o=r.outputFormat??"json",a=r.spacesAroundValues??1,i=r.indent??2,p=r.pretty??false,u=r.inputFormat??"auto",c=u==="bitmark"||u!=="json"&&e.is_bitmark(t),d=c?"bitmark":"json",l=_e(r.patch),g=be(e,t,c),k=g.length,m=[],y=[];for(let b=0;b<k;b++){let{view:v,source:S}=g[b];v.index=b,v.total=k;let j=r.preHook?r.preHook(v)||{}:{};if(j.drop)continue;let J=j.patches?[...l,...j.patches]:l;m.push({index:b,source:S,inputFormat:d,outputFormat:j.outputFormat??o,mode:n,patchJson:JSON.stringify(J),spacesAroundValues:a}),y.push(v);}return {jobs:m,views:y,output:o,pretty:p,indent:i}}function ye(e,t){let r=e.transform(t.source,t.inputFormat,t.outputFormat,t.mode,t.patchJson,false,2,t.spacesAroundValues);return W(r)?r:t.outputFormat==="json"?fe(r):r}function _t(e,t,r,n,o){if(r==="bitmark"||r==="text")return t.join(`
2
- `);let a=`[${t.join(",")}]`;return n?e.prettify(a,o):a}function It(e,t,r){let n;try{n=ft(e,t,r);}catch(a){return K(a)}let o=[];for(let a=0;a<n.jobs.length;a++){let i=ye(e,n.jobs[a]);if(W(i))return i;r.postHook?.(n.views[a],i),o.push(i);}return _t(e,o,n.output,n.pretty,n.indent)}async function Pt(e,t,r,n){let o;try{o=ft(e,t,r);}catch(i){return K(i)}let a;try{a=await n(o.jobs,r.workers??4);}catch(i){return K(i)}for(let i=0;i<a.length;i++){if(W(a[i]))return a[i];r.postHook?.(o.views[i],a[i]);}return _t(e,a,o.output,o.pretty,o.indent)}function St(e,t){if(e.length===0)return Promise.resolve([]);let r=Math.max(1,Math.min(t,e.length)),n=new URL("./worker-entry.js",import.meta.url);return new Promise((o,a)=>{let i=new Array(e.length),p=0,u=0,c=false,d=[],l=()=>{for(let m of d)m.terminate();},g=m=>{c||(c=true,l(),a(m));},k=m=>{if(c||p>=e.length)return;let y=p++;m.postMessage({id:y,job:e[y]});};for(let m=0;m<r;m++){let y=new Worker(n,{type:"module"});d.push(y),y.onmessage=b=>{let v=b.data;if(!c){if(!v.ok){g(new Error(v.error??"worker job failed"));return}if(i[v.id]=v.element,u++,u===e.length){c=true,l(),o(i);return}k(y);}},y.onerror=b=>g(new Error(b.message||"worker error"));}for(let m of d)k(m);})}var bt;function jt(e){bt=e;}function w(){if(!bt)throw new Error("legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)");return bt}var ie={};Tt(ie,{Ast:()=>zt,BitType:()=>Vt,BitmarkFileGenerator:()=>$t,BitmarkGenerator:()=>Dt,BitmarkParser:()=>te,BitmarkParserGenerator:()=>tt,BitmarkParserType:()=>Ee,BitmarkStringGenerator:()=>Kt,BitmarkVersion:()=>Fe,BodyTextFormat:()=>Pe,BoundingBoxIndex:()=>Ut,Builder:()=>Z,CardSetVersion:()=>Re,FileWriter:()=>re,HtmlTableGenerator:()=>Qt,HtmlTableParser:()=>Zt,InfoFormat:()=>Ie,InfoType:()=>Be,Input:()=>Oe,InputFormat:()=>ve,JsonFileGenerator:()=>Xt,JsonGenerator:()=>Yt,JsonParser:()=>ee,JsonStringGenerator:()=>qt,LegacyUnsupportedError:()=>N,NodeType:()=>Gt,Output:()=>Te,ResourceBuilder:()=>et,StreamWriter:()=>oe,StringWriter:()=>ne,TextLocation:()=>Se,TextMarkType:()=>Ct,TextNodeType:()=>Mt,bitmarkTextParse:()=>Wt,isPseudoAst:()=>Lt});var N=class extends Error{constructor(t){super(t),this.name="LegacyUnsupportedError";}};function A(e,t){throw new N(`'${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}function I(e,t){throw new N(`Option '${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}var yt="bitmark v2 output is not supported (this parser is bitmark v3 only)";function xt(e){e.bitmarkVersion===2&&I("bitmarkVersion: 2",yt);}function Y(e){e.explicitTextFormat&&I("bitmarkOptions.explicitTextFormat"),e.prettifyJson!==void 0&&e.prettifyJson!==false&&I("bitmarkOptions.prettifyJson","embedded-JSON body prettification is not supported"),e.cardSetVersion===1&&I("bitmarkOptions.cardSetVersion: 1",yt),e.debugGenerationInline&&I("bitmarkOptions.debugGenerationInline"),e.noBreakscaping&&I("bitmarkOptions.noBreakscaping");}function q(e){e.textAsPlainText&&I("jsonOptions.textAsPlainText",yt),e.excludeUnknownProperties&&I("jsonOptions.excludeUnknownProperties"),e.debugGenerationInline&&I("jsonOptions.debugGenerationInline");}function C(e){return e===true?{pretty:true,indent:2}:typeof e=="number"&&e>0?{pretty:true,indent:e}:{pretty:false,indent:2}}function X(e){return e===void 0||e===true?1:e===false?0:Math.max(0,Math.min(10,e))}function Q(e){switch(e){case "text":case "latex":case "json":case "xml":return "plainText";default:return "bitmark++"}}var At=Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");function M(e){let t={bits:e};return Object.defineProperty(t,At,{value:true,enumerable:false}),t}function Lt(e){return e!==null&&typeof e=="object"&&(At in e||Array.isArray(e.bits))}var kt=Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser"),ke={bitType:"type",textFormat:"format",flashcards:"cards",markConfig:"marks"},we={"bitmark--":"bitmark++","bitmark+":"bitmark++"},he=["title","subtitle","item","lead","pageNumber","marginNumber","hint","instruction","caption"],Z=class{buildBitmark(t){let r=M(t.bits??[]);return t.errors!==void 0&&(r.errors=t.errors),r}buildBit(t,r){let n=w(),o={...t},a=o.bitType;this.assertKnownBitType(a);let i={};i.type=a,o.isCommented&&(i.type="_comment",i.originalType=a),delete o.bitType,delete o.isCommented;let p=o.textFormat;p!==void 0&&(i.format=we[p]??p,delete o.textFormat),delete o.resourceType;let u=o.body;u!=null&&typeof u=="object"&&"body"in u&&(i.body=u.body,delete o.body),o.example!==void 0?(i.isExample=true,i.example=o.example,delete o.example,delete o.__isDefaultExample):o.__isDefaultExample&&(i.isExample=true,delete o.__isDefaultExample);let c=o.resources;c!==void 0&&(Array.isArray(c)?c.length===1?i.resource=c[0]:c.length>1&&(i.resources=c):i.resource=c,delete o.resources);let d=o.parser;delete o.parser;let l=o.extraProperties;delete o.extraProperties;for(let[y,b]of Object.entries(o))b!==void 0&&(i[ke[y]??y]=b);if(l)for(let[y,b]of Object.entries(l))y in i||(i[y]=b);this.parseStringTexts(i);let g=n.convert(JSON.stringify([{bit:i}]),"json","json","optimized",false,2,1);if(g.startsWith("error:"))throw new Error(g.slice(6).trim());let m=JSON.parse(g)[0]?.bit??i;for(let[y,b]of Object.entries(i))y in m||b===false||b===""||b===null||Array.isArray(b)&&b.length===0||(m[y]=b);return d!==void 0&&Object.defineProperty(m,kt,{value:d,enumerable:false}),m}buildHighlight(t,r){if(!r)return;let n={...r},o=n.attrs;return o&&Object.assign(n,o),{type:"highlight",texts:Array.isArray(n.texts)?n.texts.filter(p=>p!=null).map(p=>({text:p.text??"",isCorrect:p.isCorrect??false,isHighlighted:p.isHighlighted??false,...Jt(p,["text","isCorrect","isHighlighted"])})):[],prefix:n.prefix??"",postfix:n.postfix??"",...Jt(n,["type","texts","prefix","postfix","attrs"]),attrs:{}}}parseStringTexts(t){let r=w(),n=(i,p)=>{if(i==="")return i;let u=r.convert_text(i,"textToAst","bitmark++",p);try{return JSON.parse(u)}catch{return i}},o=t.format,a=o===void 0||o==="bitmark++"||o==="bitmark+";typeof t.body=="string"&&a&&(t.body=n(t.body,"body"));for(let i of he){let p=t[i];typeof p=="string"&&(t[i]=n(p,"tag"));}}assertKnownBitType(t){let r=w(),n=false;if(t!==void 0)try{n=JSON.parse(r.info("bit","json",t,!1,2)).error===void 0;}catch{n=false;}if(!n)throw new Error(`No config found for bit: ${t}`)}};function Jt(e,t){let r={};for(let[n,o]of Object.entries(e))o!==void 0&&!t.includes(n)&&(r[n]=o);return r}var tt=class{version(){return G.version}convert(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);xt(n),Y(a),q(o),this.checkBrowserFileWrite(n.outputFile);let i=w(),{source:p,isBitmark:u}=this.resolveInput(t,n.inputFormat),c=n.outputFormat??(u?"json":"bitmark"),d=c==="ast"?"json":c,{pretty:l,indent:g}=C(o.prettify),k=X(a.spacesAroundValues),m=i.convert(p,u?"bitmark":"json",d,"optimized",l,g,k);if(this.throwOnError(m),c==="bitmark"||c==="text")return this.deliver(m,n.outputFile,n.fileOptions);if(c==="json")return n.outputFile?this.deliver(m,n.outputFile,n.fileOptions):l||o.stringify?m:JSON.parse(m);let y=M(JSON.parse(m));return n.outputFile?this.deliver(JSON.stringify(y),n.outputFile,n.fileOptions):y}upgrade(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);xt(n),Y(a),q(o),this.checkBrowserFileWrite(n.outputFile);let i=w(),{source:p,isBitmark:u}=this.resolveInput(t,n.inputFormat),{pretty:c,indent:d}=C(o.prettify),l=X(a.spacesAroundValues),g=i.canonicalize(p,u?"bitmark":"json","optimized",c,d,l);return this.throwOnError(g),u?this.deliver(g,n.outputFile,n.fileOptions):n.outputFile?this.deliver(g,n.outputFile,n.fileOptions):c||o.stringify?g:JSON.parse(g)}info(t){let r=Object.assign({},t),n=w(),o=r.type??"list",a=r.outputFormat??"text",{pretty:i,indent:p}=C(r.prettify),u=a==="pojo"?"json":a,c=n.info(o,u,r.bit??"",i,p);return this.throwOnError(c),a==="pojo"?JSON.parse(c):c}generateConfig(t){A("BitmarkParserGenerator.generateConfig","bpg-internal development tool");}convertHtmlTable(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);Y(a),q(o),n.keepUnknownTags&&I("keepUnknownTags"),n.noBreakscaping&&I("noBreakscaping"),this.checkBrowserFileWrite(n.outputFile);let i=w(),p=typeof t=="string"?this.maybeReadFile(t,void 0):"";if(!(n.inputFormat==="html"||n.inputFormat===void 0&&typeof t=="string"&&/<table[\s>]/iu.test(p))){let{source:S,isBitmark:j}=this.resolveInput(t,void 0),J=i.convert(S,j?"bitmark":"json","html","optimized",false,2,1);return this.throwOnError(J),this.deliver(wt(J).join(`
3
- `),n.outputFile,n.fileOptions)}let c=n.tableFormat==="table"?"table":"table-extended",d=wt(p).map(S=>`<bitmark-bit data-type="${c}" data-format="bitmark++">${S}</bitmark-bit>`).join(""),l=n.outputFormat??"bitmark",{pretty:g,indent:k}=C(o.prettify),m=X(a.spacesAroundValues);if(l==="html"){let S=i.convert(d,"html","html","optimized",false,2,1);return this.throwOnError(S),this.deliver(wt(S).join(`
4
- `),n.outputFile,n.fileOptions)}let y=l==="ast"?"json":l,b=i.convert(d,"html",y,"optimized",g,k,m);if(this.throwOnError(b),l==="bitmark"||l==="text")return this.deliver(b,n.outputFile,n.fileOptions);if(l==="json")return n.outputFile?this.deliver(b,n.outputFile,n.fileOptions):g||o.stringify?b:JSON.parse(b);let v=M(JSON.parse(b));return n.outputFile?this.deliver(JSON.stringify(v),n.outputFile,n.fileOptions):v}createAst(t,r){let n=Object.assign({},r),o=w(),{source:a,isBitmark:i}=this.resolveInput(t,n.inputFormat),p=o.convert(a,i?"bitmark":"json","json","optimized",false,2,1);return this.throwOnError(p),M(JSON.parse(p))}breakscapeText(t,r){if(!t)return t;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=w(),a=this.maybeReadFile(t,n.inputFormat),i=o.breakscape_text(a,Q(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}unbreakscapeText(t,r){if(!t)return t;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=w(),a=this.maybeReadFile(t,n.inputFormat),i=o.unbreakscape_text(a,Q(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}convertText(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions);this.checkBrowserFileWrite(n.outputFile);let a=w(),i=n.textFormat===void 0||Q(n.textFormat)==="bitmark++",p=n.textLocation??"body",u,c;if(typeof t=="string"?(u=this.maybeReadFile(t,n.inputFormat),c=this.parseTextAstString(u)):(u=JSON.stringify(t),c=Array.isArray(t)?t:void 0),c!==void 0){let m=i?a.convert_text(JSON.stringify(c),"astToText","bitmark++",p):a.convert_text(JSON.stringify(c),"astToPlainText","plainText",p);return this.throwOnError(m),this.deliver(m,n.outputFile,n.fileOptions)}let d=a.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(d);let{pretty:l,indent:g}=C(o.prettify),k=l?a.prettify(d,g):d;return n.outputFile?this.deliver(k,n.outputFile,n.fileOptions):l?k:JSON.parse(d)}textAstToPlainText(t,r){let o=w().convert_text(typeof t=="string"?t:JSON.stringify(t),"astToPlainText","bitmark++","body");return this.throwOnError(o),o}extractPlainText(t,r){let n=r?.inputFormat,o=w();if(n==="plainText")return typeof t=="string"?String(t):"";if(n==="bitmarkText"){let u=o.convert_text(String(t),"textToAst","bitmark++","body"),c=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(c),c}if(typeof t=="string"&&this.parseTextAstString(t)===void 0&&!o.is_bitmark(t)&&!(()=>{try{return JSON.parse(t),!0}catch{return false}})())return this.extractPlainText(t,{inputFormat:"bitmarkText"});let{source:a,isBitmark:i}=this.resolveInput(t,void 0),p=o.convert(a,i?"bitmark":"json","text","optimized",false,2,1);return this.throwOnError(p),p}parseTextAstString(t){let r=t.trim();if(r.startsWith("["))try{let n=JSON.parse(r);if(Array.isArray(n)&&n.every(o=>o!==null&&typeof o=="object"&&"type"in o))return n}catch{}}resolveInput(t,r){if(typeof t!="string"){let a=this.jsonEntries(t);return {source:JSON.stringify(a?a.map(i=>this.toWrapperEntry(i)):t),isBitmark:false}}let n=this.maybeReadFile(t,r);if(w().is_bitmark(n))return {source:n,isBitmark:true};try{let a=JSON.parse(n),i=this.jsonEntries(a);if(i)return {source:JSON.stringify(i.map(p=>this.toWrapperEntry(p))),isBitmark:!1}}catch{return {source:n,isBitmark:true}}return {source:n,isBitmark:false}}jsonEntries(t){if(Array.isArray(t))return t;if(t!==null&&typeof t=="object"){let r=t;if(Array.isArray(r.bits))return r.bits;if("bit"in r)return [r];if(typeof r.type=="string")return [{bit:r}]}}toWrapperEntry(t){if(t!==null&&typeof t=="object"&&"bit"in t)return t;let r={bit:t},n=t?.[kt];return n!==void 0&&(r.parser=n),r}maybeReadFile(t,r){if(r==="string")return t;return t;}checkBrowserFileWrite(t){if(t&&true)throw new Error("Cannot write to file in browser environment")}deliver(t,r,n){if(!r)return t;throw new Error("Cannot write to file in browser environment");}throwOnError(t){if(t.startsWith("error:"))throw new Error(t.slice(6).trim())}};function wt(e){let t=[],r=e.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let a=0,i=o,p=-1;for(;i<e.length;){let u=r.indexOf("<table",i),c=r.indexOf("</table",i);if(c===-1)break;if(u!==-1&&u<c)a++,i=u+6;else {a--;let d=r.indexOf(">",c);if(i=d===-1?e.length:d+1,a===0){p=i;break}}}if(p===-1)break;t.push(e.slice(o,p)),n=p;}return t}function Wt(e){let t=w().convert_text(e,"textToAst","bitmark++","body");if(t.startsWith("error:"))throw new Error(t.slice(6).trim());return JSON.parse(t)}var T={imageResource:{type:"image",key:"image",valueField:"src"},imageLinkResource:{type:"image-link",key:"imageLink",valueField:"url"},audioResource:{type:"audio",key:"audio",valueField:"src"},audioEmbedResource:{type:"audio-embed",key:"audioEmbed",valueField:"src"},audioLinkResource:{type:"audio-link",key:"audioLink",valueField:"url"},videoResource:{type:"video",key:"video",valueField:"src"},videoEmbedResource:{type:"video-embed",key:"videoEmbed",valueField:"url"},videoLinkResource:{type:"video-link",key:"videoLink",valueField:"url"},stillImageFilmEmbedResource:{type:"still-image-film-embed",key:"stillImageFilmEmbed",valueField:"url"},stillImageFilmLinkResource:{type:"still-image-film-link",key:"stillImageFilmLink",valueField:"url"},articleResource:{type:"article",key:"article",valueField:"body"},documentResource:{type:"document",key:"document",valueField:"url"},documentEmbedResource:{type:"document-embed",key:"documentEmbed",valueField:"url"},documentLinkResource:{type:"document-link",key:"documentLink",valueField:"url"},documentDownloadResource:{type:"document-download",key:"documentDownload",valueField:"url"},appLinkResource:{type:"app-link",key:"appLink",valueField:"url"},websiteLinkResource:{type:"website-link",key:"websiteLink",valueField:"url"}};function h(e){return (t,r,n)=>{if(!r)return;let{value:o,...a}=r,i={[e.valueField]:o??""};for(let[p,u]of Object.entries(a))u!==void 0&&(i[p]=u);return {type:e.type,[e.key]:i}}}var Nt=Object.fromEntries(Object.values(T).map(e=>[e.type,e])),et=class{constructor(){O(this,"imageResource",h(T.imageResource));O(this,"imageLinkResource",h(T.imageLinkResource));O(this,"audioResource",h(T.audioResource));O(this,"audioEmbedResource",h(T.audioEmbedResource));O(this,"audioLinkResource",h(T.audioLinkResource));O(this,"videoResource",h(T.videoResource));O(this,"videoEmbedResource",h(T.videoEmbedResource));O(this,"videoLinkResource",h(T.videoLinkResource));O(this,"stillImageFilmEmbedResource",h(T.stillImageFilmEmbedResource));O(this,"stillImageFilmLinkResource",h(T.stillImageFilmLinkResource));O(this,"articleResource",h(T.articleResource));O(this,"documentResource",h(T.documentResource));O(this,"documentEmbedResource",h(T.documentEmbedResource));O(this,"documentLinkResource",h(T.documentLinkResource));O(this,"documentDownloadResource",h(T.documentDownloadResource));O(this,"appLinkResource",h(T.appLinkResource));O(this,"websiteLinkResource",h(T.websiteLinkResource));}resourceFromResourceJson(t,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,a=[];for(let i of o){let p=Nt[i.type];if(!p)continue;let u=i[p.key]??{},{[p.valueField]:c,...d}=u,l=h(p)(void 0,{value:c,...d});l&&a.push(l);}if(a.length!==0)return n?a[0]:a}resourceFromResourceDataJson(t,r,n){if(!n)return;let o=Nt[r];if(!o)return;let a=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:p,src:u,body:c,...d}=i,l=p??u??c??a;return h(o)(t,{value:l,...d})}};var Oe={string:"string",file:"file"},Te={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},ve={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},Fe={v2:2,v3:3},Re={v1:1,v2:2},Ee={peggy:"peggy"},Be={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},Ie={text:"text",json:"json",pojo:"pojo"},Pe={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},Se={tag:"tag",body:"body"};var Ct={bold:"bold",light:"light",italic:"italic",highlight:"highlight",highlightOrange:"highlightOrange",highlightYellow:"highlightYellow",highlightGreen:"highlightGreen",highlightBlue:"highlightBlue",highlightPurple:"highlightPurple",highlightPink:"highlightPink",highlightBrown:"highlightBrown",highlightBlack:"highlightBlack",highlightWhite:"highlightWhite",highlightGray:"highlightGray",strike:"strike",subscript:"subscript",superscript:"superscript",ins:"ins",del:"del",underline:"underline",doubleUnderline:"doubleUnderline",circle:"circle",languageEmRed:"languageEmRed",languageEmOrange:"languageEmOrange",languageEmYellow:"languageEmYellow",languageEmGreen:"languageEmGreen",languageEmBlue:"languageEmBlue",languageEmPurple:"languageEmPurple",languageEmPink:"languageEmPink",languageEmBrown:"languageEmBrown",languageEmBlack:"languageEmBlack",languageEmWhite:"languageEmWhite",languageEmGray:"languageEmGray",languageEm:"languageEm",userUnderline:"userUnderline",userDoubleUnderline:"userDoubleUnderline",userStrike:"userStrike",userCircle:"userCircle",userHighlight:"userHighlight",notranslate:"notranslate",link:"link",ref:"ref",xref:"xref",extref:"extref",footnote:"footnote",footnoteStar:"footnote*",symbol:"symbol",var:"var",code:"code",timer:"timer",duration:"duration",color:"color",colorPicker:"colorPicker",comment:"comment"},Mt={text:"text",hardBreak:"hardBreak",paragraph:"paragraph",heading:"heading",section:"section",noBulletList:"noBulletList",bulletList:"bulletList",orderedList:"orderedList",orderedListRoman:"orderedListRoman",orderedListRomanLower:"orderedListRomanLower",letteredList:"letteredList",letteredListLower:"letteredListLower",taskList:"taskList",listItem:"listItem",taskItem:"taskItem",image:"image",imageInline:"imageInline",codeBlock:"codeBlock",latex:"latex",gap:"gap",select:"select",highlight:"highlight",mark:"mark"};function je(e){return e.replace(/-([a-z0-9])/gu,(t,r)=>r.toUpperCase())}var ht;function U(){if(!ht){let e=w(),t=JSON.parse(e.info("all","json","",false,2)),r={_standard:"_standard"};for(let{name:n}of t)r[je(n)]=n;ht=r;}return ht}var Vt=new Proxy({},{get:(e,t)=>typeof t=="string"?U()[t]:void 0,has:(e,t)=>typeof t=="string"&&t in U(),ownKeys:()=>Reflect.ownKeys(U()),getOwnPropertyDescriptor:(e,t)=>typeof t=="string"&&t in U()?{value:U()[t],enumerable:true,configurable:true,writable:false}:void 0});function Ht(e,t){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${e}]`:A(e,t),has:()=>A(e,t),ownKeys:()=>A(e,t)})}var Gt=Ht("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),Ut=Ht("BoundingBoxIndex","bpg-internal bounding-box utility");function B(e,t){return class{constructor(){A(e,t);}}}var Ae="the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave",P="internal class of bpg's TS implementation",zt=B("Ast",Ae),Dt=B("BitmarkGenerator",P),Kt=B("BitmarkStringGenerator",P),$t=B("BitmarkFileGenerator",P),Yt=B("JsonGenerator",P),qt=B("JsonStringGenerator",P),Xt=B("JsonFileGenerator",P),Qt=B("HtmlTableGenerator",P),Zt=B("HtmlTableParser",P),te=B("BitmarkParser",P),ee=B("JsonParser",P),ne=B("StringWriter",P),re=B("FileWriter",P),oe=B("StreamWriter",P);jt(H);async function Gn(e){return typeof e>"u"&&(e=new URL(`bitmark_wasm_bg.wasm?v=${G.version}`,import.meta.url)),mt(e)}function Un(){return G.version}function zn(e,t={}){return nt(e,t.stage??"lex")}function Dn(e,t={}){return rt(e,t.mode??"optimized")}function Kn(e,t={}){return pt(e,t.inputFormat??"auto",t.outputFormat??"auto",t.mode??"optimized",t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function $n(e,t={}){return ut(e,t.inputFormat??"auto",t.pretty??false,t.indent??2)}function Le(e,t={}){return ct(e,t.inputFormat??"auto",t.pretty??false,t.indent??2)}var Yn=Le;function qn(e,t={}){return dt(e,t.inputFormat??"auto",t.mode??"optimized",t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function Xn(e){let t=lt(e);if(t.startsWith("error:"))throw new Error(t);return Number.parseInt(t,10)}function Qn(e){return JSON.parse(gt(e))}function Zn(e,t={}){if(t.preHook||t.postHook)return It(H,e,t);let r=t.patch===void 0?"":typeof t.patch=="string"?t.patch:JSON.stringify(t.patch);return st(e,t.inputFormat??"auto",t.outputFormat??"json",t.mode??"optimized",r,t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function tr(e,t={}){return Pt(H,e,t,St)}function er(e,t={}){let r=t.format??"bitmark++",n=t.location??"body";return ot(e,r,n)}function nr(e,t={}){let r=t.format??"bitmark++",n=t.location??"body";return it(e,r,n)}function rr(e={}){let t=e.infoType??"list",r=e.format??"text",n=e.bit??"",o=e.pretty??false,a=e.indent??2;return at(t,r,n,o,a)}export{er as breakscapeText,qn as canonicalize,Kn as convert,Xn as countBits,Yn as expand,Le as fullize,rr as info,Gn as init,Et as initSync,ie as legacy,zn as lex,$n as optimize,Dn as parse,Qn as splitBits,Zn as transform,tr as transformParallel,nr as unbreakscapeText,Un as version};//# sourceMappingURL=bitmark-parser.min.js.map
1
+ var ke=Object.defineProperty;var st=(t,e,r)=>e in t?ke(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var we=(t,e)=>{for(var r in e)ke(t,r,{get:e[r],enumerable:true});};var T=(t,e,r)=>st(t,typeof e!="symbol"?e+"":e,r);var U={};we(U,{breakscape_text:()=>oe,canonicalize:()=>pe,convert:()=>H,convert_text:()=>lt,count_bits:()=>ue,default:()=>le,info:()=>se,initSync:()=>Fe,is_bitmark:()=>pt,lex:()=>re,prettify:()=>ct,split_bits:()=>ce,split_json_bits:()=>ut,transform:()=>ae,unbreakscape_text:()=>ie});var a,y=0,M=null;function D(){return (M===null||M.byteLength===0)&&(M=new Uint8Array(a.memory.buffer)),M}var K=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},at=typeof K.encodeInto=="function"?function(t,e){return K.encodeInto(t,e)}:function(t,e){let r=K.encode(t);return e.set(r),{read:t.length,written:r.length}};function _(t,e,r){if(r===void 0){let p=K.encode(t),u=e(p.length,1)>>>0;return D().subarray(u,u+p.length).set(p),y=p.length,u}let n=t.length,o=e(n,1)>>>0,s=D(),i=0;for(;i<n;i++){let p=t.charCodeAt(i);if(p>127)break;s[o+i]=p;}if(i!==n){i!==0&&(t=t.slice(i)),o=r(o,n,n=i+t.length*3,1)>>>0;let p=D().subarray(o+i,o+n),u=at(t,p);i+=u.written,o=r(o,n,i,1)>>>0;}return y=i,o}var J=null;function k(){return (J===null||J.buffer.detached===true||J.buffer.detached===void 0&&J.buffer!==a.memory.buffer)&&(J=new DataView(a.memory.buffer)),J}var he=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&he.decode();function S(t,e){return t=t>>>0,he.decode(D().subarray(t,t+e))}function re(t,e){let r,n;try{let i=a.__wbindgen_add_to_stack_pointer(-16),p=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),u=y,c=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),l=y;a.lex(i,p,u,c,l);var o=k().getInt32(i+0,!0),s=k().getInt32(i+4,!0);return r=o,n=s,S(o,s)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(r,n,1);}}function oe(t,e,r){let n,o;try{let p=a.__wbindgen_add_to_stack_pointer(-16),u=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),c=y,l=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),m=y,f=_(r,a.__wbindgen_export_0,a.__wbindgen_export_1),x=y;a.breakscape_text(p,u,c,l,m,f,x);var s=k().getInt32(p+0,!0),i=k().getInt32(p+4,!0);return n=s,o=i,S(s,i)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(n,o,1);}}function ie(t,e,r){let n,o;try{let p=a.__wbindgen_add_to_stack_pointer(-16),u=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),c=y,l=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),m=y,f=_(r,a.__wbindgen_export_0,a.__wbindgen_export_1),x=y;a.unbreakscape_text(p,u,c,l,m,f,x);var s=k().getInt32(p+0,!0),i=k().getInt32(p+4,!0);return n=s,o=i,S(s,i)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(n,o,1);}}function se(t,e,r,n,o){let s,i;try{let c=a.__wbindgen_add_to_stack_pointer(-16),l=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),m=y,f=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),x=y,b=_(r,a.__wbindgen_export_0,a.__wbindgen_export_1),g=y;a.info(c,l,m,f,x,b,g,n,o);var p=k().getInt32(c+0,!0),u=k().getInt32(c+4,!0);return s=p,i=u,S(p,u)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(s,i,1);}}function ae(t,e,r,n,o,s,i,p){let u,c;try{let f=a.__wbindgen_add_to_stack_pointer(-16),x=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),b=y,g=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),d=y,w=_(r,a.__wbindgen_export_0,a.__wbindgen_export_1),B=y,j=_(n,a.__wbindgen_export_0,a.__wbindgen_export_1),A=y,ot=_(o,a.__wbindgen_export_0,a.__wbindgen_export_1),it=y;a.transform(f,x,b,g,d,w,B,j,A,ot,it,s,i,p);var l=k().getInt32(f+0,!0),m=k().getInt32(f+4,!0);return u=l,c=m,S(l,m)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(u,c,1);}}function H(t,e,r,n,o,s,i,p){let u,c;try{let f=a.__wbindgen_add_to_stack_pointer(-16),x=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),b=y,g=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),d=y,w=_(r,a.__wbindgen_export_0,a.__wbindgen_export_1),B=y,j=_(n,a.__wbindgen_export_0,a.__wbindgen_export_1),A=y;a.convert(f,x,b,g,d,w,B,j,A,o,s,i,p);var l=k().getInt32(f+0,!0),m=k().getInt32(f+4,!0);return u=l,c=m,S(l,m)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(u,c,1);}}function pe(t,e,r,n,o,s){let i,p;try{let l=a.__wbindgen_add_to_stack_pointer(-16),m=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),f=y,x=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),b=y,g=_(r,a.__wbindgen_export_0,a.__wbindgen_export_1),d=y;a.canonicalize(l,m,f,x,b,g,d,n,o,s);var u=k().getInt32(l+0,!0),c=k().getInt32(l+4,!0);return i=u,p=c,S(u,c)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(i,p,1);}}function ue(t){let e,r;try{let s=a.__wbindgen_add_to_stack_pointer(-16),i=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),p=y;a.count_bits(s,i,p);var n=k().getInt32(s+0,!0),o=k().getInt32(s+4,!0);return e=n,r=o,S(n,o)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(e,r,1);}}function ce(t){let e,r;try{let s=a.__wbindgen_add_to_stack_pointer(-16),i=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),p=y;a.split_bits(s,i,p);var n=k().getInt32(s+0,!0),o=k().getInt32(s+4,!0);return e=n,r=o,S(n,o)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(e,r,1);}}function pt(t){let e=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),r=y;return a.is_bitmark(e,r)!==0}function ut(t){let e,r;try{let s=a.__wbindgen_add_to_stack_pointer(-16),i=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),p=y;a.split_json_bits(s,i,p);var n=k().getInt32(s+0,!0),o=k().getInt32(s+4,!0);return e=n,r=o,S(n,o)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(e,r,1);}}function ct(t,e){let r,n;try{let i=a.__wbindgen_add_to_stack_pointer(-16),p=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),u=y;a.prettify(i,p,u,e);var o=k().getInt32(i+0,!0),s=k().getInt32(i+4,!0);return r=o,n=s,S(o,s)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(r,n,1);}}function lt(t,e,r,n){let o,s;try{let u=a.__wbindgen_add_to_stack_pointer(-16),c=_(t,a.__wbindgen_export_0,a.__wbindgen_export_1),l=y,m=_(e,a.__wbindgen_export_0,a.__wbindgen_export_1),f=y,x=_(r,a.__wbindgen_export_0,a.__wbindgen_export_1),b=y,g=_(n,a.__wbindgen_export_0,a.__wbindgen_export_1),d=y;a.convert_text(u,c,l,m,f,x,b,g,d);var i=k().getInt32(u+0,!0),p=k().getInt32(u+4,!0);return o=i,s=p,S(i,p)}finally{a.__wbindgen_add_to_stack_pointer(16),a.__wbindgen_export_2(o,s,1);}}async function dt(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(n){if(t.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n);else throw n}let r=await t.arrayBuffer();return await WebAssembly.instantiate(r,e)}else {let r=await WebAssembly.instantiate(t,e);return r instanceof WebAssembly.Instance?{instance:r,module:t}:r}}function Oe(){let t={};return t.wbg={},t}function Te(t,e){return a=t.exports,ve.__wbindgen_wasm_module=e,J=null,M=null,a}function Fe(t){if(a!==void 0)return a;typeof t<"u"&&(Object.getPrototypeOf(t)===Object.prototype?{module:t}=t:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let e=Oe();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));let r=new WebAssembly.Instance(t,e);return Te(r,t)}async function ve(t){if(a!==void 0)return a;typeof t<"u"&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof t>"u"&&(t=new URL("bitmark_wasm_bg.wasm",import.meta.url));let e=Oe();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await dt(await t,e);return Te(r,n)}var le=ve;var G={version:"6.3.0"};function N(t){return t.startsWith("error:")}function $(t){let e=t instanceof Error?t.message:String(t);return e.startsWith("error:")?e:`error: ${e}`}function mt(t){let e=t.trim();return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):t}function ft(t){if(t===void 0)return [];if(typeof t=="string"){let e=t.trim();return e===""?[]:JSON.parse(e)}return t}function gt(t,e,r){if(r){let s=t.split_bits(e);if(N(s))throw new Error(s);let i=JSON.parse(s);return i.map(p=>({view:{format:"bitmark",index:p.index,total:i.length,source:p.source},source:p.source}))}let n=t.split_json_bits(e);if(N(n))throw new Error(n);let o=JSON.parse(n);return o.map((s,i)=>({view:{format:"json",index:i,total:o.length,bit:s.bit??{}},source:JSON.stringify([s])}))}function de(t,e,r){let n=r.mode??"optimized",o=r.outputFormat??"json",s=r.spacesAroundValues??1,i=r.indent??2,p=r.pretty??false,u=r.inputFormat??"auto",c=u==="bitmark"||u!=="json"&&t.is_bitmark(e),l=c?"bitmark":"json",m=ft(r.patch),f=gt(t,e,c),x=f.length,b=[],g=[];for(let d=0;d<x;d++){let{view:w,source:B}=f[d];w.index=d,w.total=x;let j=r.preHook?r.preHook(w)||{}:{};if(j.drop)continue;let A=j.patches?[...m,...j.patches]:m;b.push({index:d,source:B,inputFormat:l,outputFormat:j.outputFormat??o,mode:n,patchJson:JSON.stringify(A),spacesAroundValues:s}),g.push(w);}return {jobs:b,views:g,output:o,pretty:p,indent:i}}function bt(t,e){let r=t.transform(e.source,e.inputFormat,e.outputFormat,e.mode,e.patchJson,false,2,e.spacesAroundValues);return N(r)?r:e.outputFormat==="json"?mt(r):r}function me(t,e,r,n,o){if(r==="bitmark"||r==="text")return e.join(`
2
+ `);let s=`[${e.join(",")}]`;return n?t.prettify(s,o):s}function Re(t,e,r){let n;try{n=de(t,e,r);}catch(s){return $(s)}let o=[];for(let s=0;s<n.jobs.length;s++){let i=bt(t,n.jobs[s]);if(N(i))return i;r.postHook?.(n.views[s],i),o.push(i);}return me(t,o,n.output,n.pretty,n.indent)}async function Ee(t,e,r,n){let o;try{o=de(t,e,r);}catch(i){return $(i)}let s;try{s=await n(o.jobs,r.workers??4);}catch(i){return $(i)}for(let i=0;i<s.length;i++){if(N(s[i]))return s[i];r.postHook?.(o.views[i],s[i]);}return me(t,s,o.output,o.pretty,o.indent)}function Pe(t,e){if(t.length===0)return Promise.resolve([]);let r=Math.max(1,Math.min(e,t.length)),n=new URL("./worker-entry.js",import.meta.url);return new Promise((o,s)=>{let i=new Array(t.length),p=0,u=0,c=false,l=[],m=()=>{for(let b of l)b.terminate();},f=b=>{c||(c=true,m(),s(b));},x=b=>{if(c||p>=t.length)return;let g=p++;b.postMessage({id:g,job:t[g]});};for(let b=0;b<r;b++){let g=new Worker(n,{type:"module"});l.push(g),g.onmessage=d=>{let w=d.data;if(!c){if(!w.ok){f(new Error(w.error??"worker job failed"));return}if(i[w.id]=w.element,u++,u===t.length){c=true,m(),o(i);return}x(g);}},g.onerror=d=>f(new Error(d.message||"worker error"));}for(let b of l)x(b);})}var fe;function Be(t){fe=t;}function h(){if(!fe)throw new Error("legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)");return fe}var rt={};we(rt,{Ast:()=>Ue,BitType:()=>Ce,BitmarkFileGenerator:()=>De,BitmarkGenerator:()=>Ge,BitmarkParser:()=>Qe,BitmarkParserGenerator:()=>te,BitmarkParserType:()=>vt,BitmarkStringGenerator:()=>ze,BitmarkVersion:()=>Tt,BodyTextFormat:()=>Pt,BoundingBoxIndex:()=>He,Builder:()=>ee,CardSetVersion:()=>Ft,FileWriter:()=>tt,HtmlTableGenerator:()=>qe,HtmlTableParser:()=>Xe,InfoFormat:()=>Et,InfoType:()=>Rt,Input:()=>wt,InputFormat:()=>Ot,JsonFileGenerator:()=>Ye,JsonGenerator:()=>Ke,JsonParser:()=>Ze,JsonStringGenerator:()=>$e,LegacyUnsupportedError:()=>C,NodeType:()=>Me,Output:()=>ht,ResourceBuilder:()=>ne,StreamWriter:()=>nt,StringWriter:()=>et,TextLocation:()=>Bt,TextMarkType:()=>We,TextNodeType:()=>Ne,bitmarkTextParse:()=>Le,isPseudoAst:()=>Ie});var C=class extends Error{constructor(e){super(e),this.name="LegacyUnsupportedError";}};function L(t,e){throw new C(`'${t}' is not supported by the @gmb/bitmark-parser legacy API`+(e?`: ${e}`:""))}function I(t,e){throw new C(`Option '${t}' is not supported by the @gmb/bitmark-parser legacy API`+(e?`: ${e}`:""))}var ge="bitmark v2 output is not supported (this parser is bitmark v3 only)";function be(t){t.bitmarkVersion===2&&I("bitmarkVersion: 2",ge);}function q(t){t.explicitTextFormat&&I("bitmarkOptions.explicitTextFormat"),t.cardSetVersion===1&&I("bitmarkOptions.cardSetVersion: 1",ge),t.debugGenerationInline&&I("bitmarkOptions.debugGenerationInline"),t.noBreakscaping&&I("bitmarkOptions.noBreakscaping");}function X(t){t.textAsPlainText&&I("jsonOptions.textAsPlainText",ge),t.debugGenerationInline&&I("jsonOptions.debugGenerationInline");}function W(t){return t===true?{pretty:true,indent:2}:typeof t=="number"&&t>0?{pretty:true,indent:t}:{pretty:false,indent:2}}function Q(t){return t===void 0||t===true?1:t===false?0:Math.max(0,Math.min(10,t))}function Z(t){switch(t){case "text":case "latex":case "json":case "xml":return "plainText";default:return "bitmark++"}}var Se=Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");function V(t){let e={bits:t};return Object.defineProperty(e,Se,{value:true,enumerable:false}),e}function Ie(t){return t!==null&&typeof t=="object"&&(Se in t||Array.isArray(t.bits))}var je={"extractor-image":{key:"images",resourceType:"image"},"extractor-image-collapsible":{key:"images",resourceType:"image"},"images-logo-grave":{key:"logos",resourceType:"image"},"prototype-images":{key:"images",resourceType:"image"}};var ye=Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser"),_t={bitType:"type",textFormat:"format",flashcards:"cards",markConfig:"marks"},xt={"bitmark--":"bitmark++","bitmark+":"bitmark++"},kt=["title","subtitle","item","lead","pageNumber","marginNumber","hint","instruction","caption"],ee=class{buildBitmark(e){let r=V(e.bits??[]);return e.errors!==void 0&&(r.errors=e.errors),r}buildBit(e,r){let n=h(),o={...e},s=o.bitType;this.assertKnownBitType(s);let i={};i.type=s,o.isCommented&&(i.type="_comment",i.originalType=s),delete o.bitType,delete o.isCommented;let p=o.textFormat;p!==void 0&&(i.format=xt[p]??p,delete o.textFormat),delete o.resourceType;let u=o.body;u!=null&&typeof u=="object"&&"body"in u&&(i.body=u.body,delete o.body),o.example!==void 0?(i.isExample=true,i.example=o.example,delete o.example,delete o.__isDefaultExample):o.__isDefaultExample&&(i.isExample=true,delete o.__isDefaultExample);let c=o.resources;if(c!==void 0&&s!==void 0){let g=Array.isArray(c)?c:[c],d=je[s];d?i[d.key]=g.filter(w=>w!==null&&typeof w=="object"&&w.type===d.resourceType):g.length>=1&&(i.resource=g[0]),delete o.resources;}let l=o.parser;delete o.parser;let m=o.extraProperties;delete o.extraProperties;for(let[g,d]of Object.entries(o))d!==void 0&&(i[_t[g]??g]=d);if(m)for(let[g,d]of Object.entries(m))g in i||(i[g]=d);this.parseStringTexts(i);let f=n.convert(JSON.stringify([{bit:i}]),"json","json","optimized",false,2,1,false);if(f.startsWith("error:"))throw new Error(f.slice(6).trim());let b=JSON.parse(f)[0]?.bit??i;for(let[g,d]of Object.entries(i))g in b||d===false||d===""||d===null||Array.isArray(d)&&d.length===0||(b[g]=d);return l!==void 0&&Object.defineProperty(b,ye,{value:l,enumerable:false}),b}buildHighlight(e,r){if(!r)return;let n={...r},o=n.attrs;return o&&Object.assign(n,o),{type:"highlight",texts:Array.isArray(n.texts)?n.texts.filter(p=>p!=null).map(p=>({text:p.text??"",isCorrect:p.isCorrect??false,isHighlighted:p.isHighlighted??false,...Ae(p,["text","isCorrect","isHighlighted"])})):[],prefix:n.prefix??"",postfix:n.postfix??"",...Ae(n,["type","texts","prefix","postfix","attrs"]),attrs:{}}}parseStringTexts(e){let r=h(),n=(i,p)=>{if(i==="")return i;let u=r.convert_text(i,"textToAst","bitmark++",p);try{return JSON.parse(u)}catch{return i}},o=e.format,s=o===void 0||o==="bitmark++"||o==="bitmark+";typeof e.body=="string"&&s&&(e.body=n(e.body,"body"));for(let i of kt){let p=e[i];typeof p=="string"&&(e[i]=n(p,"tag"));}}assertKnownBitType(e){let r=h(),n=false;if(e!==void 0)try{n=JSON.parse(r.info("bit","json",e,!1,2)).error===void 0;}catch{n=false;}if(!n)throw new Error(`No config found for bit: ${e}`)}};function Ae(t,e){let r={};for(let[n,o]of Object.entries(t))o!==void 0&&!e.includes(n)&&(r[n]=o);return r}var te=class{version(){return G.version}convert(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);be(n),q(s),X(o),this.checkBrowserFileWrite(n.outputFile);let i=h(),{source:p,isBitmark:u}=this.resolveInput(e,n.inputFormat),c=n.outputFormat??(u?"json":"bitmark"),l=c==="ast"?"json":c,{pretty:m,indent:f}=W(o.prettify),x=l==="bitmark"?W(s.prettifyJson):{pretty:m,indent:f},b=Q(s.spacesAroundValues),g=!o.excludeUnknownProperties,d=i.convert(p,u?"bitmark":"json",l,"optimized",x.pretty,x.indent,b,g);if(this.throwOnError(d),c==="bitmark"||c==="text")return this.deliver(d,n.outputFile,n.fileOptions);if(c==="json")return n.outputFile?this.deliver(d,n.outputFile,n.fileOptions):m||o.stringify?d:JSON.parse(d);let w=V(JSON.parse(d));return n.outputFile?this.deliver(JSON.stringify(w),n.outputFile,n.fileOptions):w}upgrade(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);be(n),q(s),X(o),this.checkBrowserFileWrite(n.outputFile);let i=h(),{source:p,isBitmark:u}=this.resolveInput(e,n.inputFormat),{pretty:c,indent:l}=W(u?s.prettifyJson:o.prettify),m=Q(s.spacesAroundValues),f=i.canonicalize(p,u?"bitmark":"json","optimized",c,l,m);return this.throwOnError(f),u?this.deliver(f,n.outputFile,n.fileOptions):n.outputFile?this.deliver(f,n.outputFile,n.fileOptions):c||o.stringify?f:JSON.parse(f)}info(e){let r=Object.assign({},e),n=h(),o=r.type??"list",s=r.outputFormat??"text",{pretty:i,indent:p}=W(r.prettify),u=s==="pojo"?"json":s,c=n.info(o,u,r.bit??"",i,p);return this.throwOnError(c),s==="pojo"?JSON.parse(c):c}generateConfig(e){L("BitmarkParserGenerator.generateConfig","bpg-internal development tool");}convertHtmlTable(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);q(s),X(o),n.keepUnknownTags&&I("keepUnknownTags"),n.noBreakscaping&&I("noBreakscaping"),this.checkBrowserFileWrite(n.outputFile);let i=h(),p=typeof e=="string"?this.maybeReadFile(e,void 0):"";if(!(n.inputFormat==="html"||n.inputFormat===void 0&&typeof e=="string"&&/<table[\s>]/iu.test(p))){let{source:B,isBitmark:j}=this.resolveInput(e,void 0),A=i.convert(B,j?"bitmark":"json","html","optimized",false,2,1,false);return this.throwOnError(A),this.deliver(_e(A).join(`
3
+ `),n.outputFile,n.fileOptions)}let c=n.tableFormat==="table"?"table":"table-extended",l=_e(p).map(B=>`<bitmark-bit data-type="${c}" data-format="bitmark++">${B}</bitmark-bit>`).join(""),m=n.outputFormat??"bitmark",{pretty:f,indent:x}=W(o.prettify),b=Q(s.spacesAroundValues);if(m==="html"){let B=i.convert(l,"html","html","optimized",false,2,1,false);return this.throwOnError(B),this.deliver(_e(B).join(`
4
+ `),n.outputFile,n.fileOptions)}let g=m==="ast"?"json":m,d=i.convert(l,"html",g,"optimized",f,x,b,false);if(this.throwOnError(d),m==="bitmark"||m==="text")return this.deliver(d,n.outputFile,n.fileOptions);if(m==="json")return n.outputFile?this.deliver(d,n.outputFile,n.fileOptions):f||o.stringify?d:JSON.parse(d);let w=V(JSON.parse(d));return n.outputFile?this.deliver(JSON.stringify(w),n.outputFile,n.fileOptions):w}createAst(e,r){let n=Object.assign({},r),o=h(),{source:s,isBitmark:i}=this.resolveInput(e,n.inputFormat),p=o.convert(s,i?"bitmark":"json","json","optimized",false,2,1,true);return this.throwOnError(p),V(JSON.parse(p))}breakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),s=this.maybeReadFile(e,n.inputFormat),i=o.breakscape_text(s,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}unbreakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),s=this.maybeReadFile(e,n.inputFormat),i=o.unbreakscape_text(s,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}convertText(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions);this.checkBrowserFileWrite(n.outputFile);let s=h(),i=n.textFormat===void 0||Z(n.textFormat)==="bitmark++",p=n.textLocation??"body",u,c;if(typeof e=="string"?(u=this.maybeReadFile(e,n.inputFormat),c=this.parseTextAstString(u)):(u=JSON.stringify(e),c=Array.isArray(e)?e:void 0),c!==void 0){let b=i?s.convert_text(JSON.stringify(c),"astToText","bitmark++",p):s.convert_text(JSON.stringify(c),"astToPlainText","plainText",p);return this.throwOnError(b),this.deliver(b,n.outputFile,n.fileOptions)}let l=s.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(l);let{pretty:m,indent:f}=W(o.prettify),x=m?s.prettify(l,f):l;return n.outputFile?this.deliver(x,n.outputFile,n.fileOptions):m?x:JSON.parse(l)}textAstToPlainText(e,r){let o=h().convert_text(typeof e=="string"?e:JSON.stringify(e),"astToPlainText","bitmark++","body");return this.throwOnError(o),o}extractPlainText(e,r){let n=r?.inputFormat,o=h();if(n==="plainText")return typeof e=="string"?String(e):"";if(n==="bitmarkText"){let u=o.convert_text(String(e),"textToAst","bitmark++","body"),c=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(c),c}if(typeof e=="string"&&this.parseTextAstString(e)===void 0&&!o.is_bitmark(e)&&!(()=>{try{return JSON.parse(e),!0}catch{return false}})())return this.extractPlainText(e,{inputFormat:"bitmarkText"});let{source:s,isBitmark:i}=this.resolveInput(e,void 0),p=o.convert(s,i?"bitmark":"json","text","optimized",false,2,1,false);return this.throwOnError(p),p}parseTextAstString(e){let r=e.trim();if(r.startsWith("["))try{let n=JSON.parse(r);if(Array.isArray(n)&&n.every(o=>o!==null&&typeof o=="object"&&"type"in o))return n}catch{}}resolveInput(e,r){if(typeof e!="string"){let s=this.jsonEntries(e);return {source:JSON.stringify(s?s.map(i=>this.toWrapperEntry(i)):e),isBitmark:false}}let n=this.maybeReadFile(e,r);if(h().is_bitmark(n))return {source:n,isBitmark:true};try{let s=JSON.parse(n),i=this.jsonEntries(s);if(i)return {source:JSON.stringify(i.map(p=>this.toWrapperEntry(p))),isBitmark:!1}}catch{return {source:n,isBitmark:true}}return {source:n,isBitmark:false}}jsonEntries(e){if(Array.isArray(e))return e;if(e!==null&&typeof e=="object"){let r=e;if(Array.isArray(r.bits))return r.bits;if("bit"in r)return [r];if(typeof r.type=="string")return [{bit:r}]}}toWrapperEntry(e){if(e!==null&&typeof e=="object"&&"bit"in e)return e;let r={bit:e},n=e?.[ye];return n!==void 0&&(r.parser=n),r}maybeReadFile(e,r){if(r==="string")return e;return e;}checkBrowserFileWrite(e){if(e&&true)throw new Error("Cannot write to file in browser environment")}deliver(e,r,n){if(!r)return e;throw new Error("Cannot write to file in browser environment");}throwOnError(e){if(e.startsWith("error:"))throw new Error(e.slice(6).trim())}};function _e(t){let e=[],r=t.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let s=0,i=o,p=-1;for(;i<t.length;){let u=r.indexOf("<table",i),c=r.indexOf("</table",i);if(c===-1)break;if(u!==-1&&u<c)s++,i=u+6;else {s--;let l=r.indexOf(">",c);if(i=l===-1?t.length:l+1,s===0){p=i;break}}}if(p===-1)break;e.push(t.slice(o,p)),n=p;}return e}function Le(t){let e=h().convert_text(t,"textToAst","bitmark++","body");if(e.startsWith("error:"))throw new Error(e.slice(6).trim());return JSON.parse(e)}var R={imageResource:{type:"image",key:"image",valueField:"src"},imageLinkResource:{type:"image-link",key:"imageLink",valueField:"url"},audioResource:{type:"audio",key:"audio",valueField:"src"},audioEmbedResource:{type:"audio-embed",key:"audioEmbed",valueField:"src"},audioLinkResource:{type:"audio-link",key:"audioLink",valueField:"url"},videoResource:{type:"video",key:"video",valueField:"src"},videoEmbedResource:{type:"video-embed",key:"videoEmbed",valueField:"url"},videoLinkResource:{type:"video-link",key:"videoLink",valueField:"url"},stillImageFilmEmbedResource:{type:"still-image-film-embed",key:"stillImageFilmEmbed",valueField:"url"},stillImageFilmLinkResource:{type:"still-image-film-link",key:"stillImageFilmLink",valueField:"url"},articleResource:{type:"article",key:"article",valueField:"body"},documentResource:{type:"document",key:"document",valueField:"url"},documentEmbedResource:{type:"document-embed",key:"documentEmbed",valueField:"url"},documentLinkResource:{type:"document-link",key:"documentLink",valueField:"url"},documentDownloadResource:{type:"document-download",key:"documentDownload",valueField:"url"},appLinkResource:{type:"app-link",key:"appLink",valueField:"url"},websiteLinkResource:{type:"website-link",key:"websiteLink",valueField:"url"}};function O(t){return (e,r,n)=>{if(!r)return;let{value:o,...s}=r,i={[t.valueField]:o??""};for(let[p,u]of Object.entries(s))u!==void 0&&(i[p]=u);return {type:t.type,[t.key]:i}}}var Je=Object.fromEntries(Object.values(R).map(t=>[t.type,t])),ne=class{constructor(){T(this,"imageResource",O(R.imageResource));T(this,"imageLinkResource",O(R.imageLinkResource));T(this,"audioResource",O(R.audioResource));T(this,"audioEmbedResource",O(R.audioEmbedResource));T(this,"audioLinkResource",O(R.audioLinkResource));T(this,"videoResource",O(R.videoResource));T(this,"videoEmbedResource",O(R.videoEmbedResource));T(this,"videoLinkResource",O(R.videoLinkResource));T(this,"stillImageFilmEmbedResource",O(R.stillImageFilmEmbedResource));T(this,"stillImageFilmLinkResource",O(R.stillImageFilmLinkResource));T(this,"articleResource",O(R.articleResource));T(this,"documentResource",O(R.documentResource));T(this,"documentEmbedResource",O(R.documentEmbedResource));T(this,"documentLinkResource",O(R.documentLinkResource));T(this,"documentDownloadResource",O(R.documentDownloadResource));T(this,"appLinkResource",O(R.appLinkResource));T(this,"websiteLinkResource",O(R.websiteLinkResource));}resourceFromResourceJson(e,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,s=[];for(let i of o){let p=Je[i.type];if(!p)continue;let u=i[p.key]??{},{[p.valueField]:c,...l}=u,m=O(p)(void 0,{value:c,...l});m&&s.push(m);}if(s.length!==0)return n?s[0]:s}resourceFromResourceDataJson(e,r,n){if(!n)return;let o=Je[r];if(!o)return;let s=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:p,src:u,body:c,...l}=i,m=p??u??c??s;return O(o)(e,{value:m,...l})}};var wt={string:"string",file:"file"},ht={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},Ot={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},Tt={v2:2,v3:3},Ft={v1:1,v2:2},vt={peggy:"peggy"},Rt={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},Et={text:"text",json:"json",pojo:"pojo"},Pt={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},Bt={tag:"tag",body:"body"};var We={bold:"bold",light:"light",italic:"italic",highlight:"highlight",highlightOrange:"highlightOrange",highlightYellow:"highlightYellow",highlightGreen:"highlightGreen",highlightBlue:"highlightBlue",highlightPurple:"highlightPurple",highlightPink:"highlightPink",highlightBrown:"highlightBrown",highlightBlack:"highlightBlack",highlightWhite:"highlightWhite",highlightGray:"highlightGray",strike:"strike",subscript:"subscript",superscript:"superscript",ins:"ins",del:"del",underline:"underline",doubleUnderline:"doubleUnderline",circle:"circle",languageEmRed:"languageEmRed",languageEmOrange:"languageEmOrange",languageEmYellow:"languageEmYellow",languageEmGreen:"languageEmGreen",languageEmBlue:"languageEmBlue",languageEmPurple:"languageEmPurple",languageEmPink:"languageEmPink",languageEmBrown:"languageEmBrown",languageEmBlack:"languageEmBlack",languageEmWhite:"languageEmWhite",languageEmGray:"languageEmGray",languageEm:"languageEm",userUnderline:"userUnderline",userDoubleUnderline:"userDoubleUnderline",userStrike:"userStrike",userCircle:"userCircle",userHighlight:"userHighlight",notranslate:"notranslate",link:"link",ref:"ref",xref:"xref",extref:"extref",footnote:"footnote",footnoteStar:"footnote*",symbol:"symbol",var:"var",code:"code",timer:"timer",duration:"duration",color:"color",colorPicker:"colorPicker",comment:"comment"},Ne={text:"text",hardBreak:"hardBreak",paragraph:"paragraph",heading:"heading",section:"section",noBulletList:"noBulletList",bulletList:"bulletList",orderedList:"orderedList",orderedListRoman:"orderedListRoman",orderedListRomanLower:"orderedListRomanLower",letteredList:"letteredList",letteredListLower:"letteredListLower",taskList:"taskList",listItem:"listItem",taskItem:"taskItem",image:"image",imageInline:"imageInline",codeBlock:"codeBlock",latex:"latex",gap:"gap",select:"select",highlight:"highlight",mark:"mark"};function St(t){return t.replace(/-([a-z0-9])/gu,(e,r)=>r.toUpperCase())}var xe;function z(){if(!xe){let t=h(),e=JSON.parse(t.info("all","json","",false,2)),r={_standard:"_standard"};for(let{name:n}of e)r[St(n)]=n;xe=r;}return xe}var Ce=new Proxy({},{get:(t,e)=>typeof e=="string"?z()[e]:void 0,has:(t,e)=>typeof e=="string"&&e in z(),ownKeys:()=>Reflect.ownKeys(z()),getOwnPropertyDescriptor:(t,e)=>typeof e=="string"&&e in z()?{value:z()[e],enumerable:true,configurable:true,writable:false}:void 0});function Ve(t,e){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${t}]`:L(t,e),has:()=>L(t,e),ownKeys:()=>L(t,e)})}var Me=Ve("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),He=Ve("BoundingBoxIndex","bpg-internal bounding-box utility");function E(t,e){return class{constructor(){L(t,e);}}}var It="the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave",P="internal class of bpg's TS implementation",Ue=E("Ast",It),Ge=E("BitmarkGenerator",P),ze=E("BitmarkStringGenerator",P),De=E("BitmarkFileGenerator",P),Ke=E("JsonGenerator",P),$e=E("JsonStringGenerator",P),Ye=E("JsonFileGenerator",P),qe=E("HtmlTableGenerator",P),Xe=E("HtmlTableParser",P),Qe=E("BitmarkParser",P),Ze=E("JsonParser",P),et=E("StringWriter",P),tt=E("FileWriter",P),nt=E("StreamWriter",P);function jt(t,e,r){return r===void 0?{path:t,op:e}:{path:t,op:e,value:r}}Be(U);async function Dn(t){return typeof t>"u"&&(t=new URL(`bitmark_wasm_bg.wasm?v=${G.version}`,import.meta.url)),le(t)}function Kn(){return G.version}function $n(t,e={}){return re(t,e.stage??"lex")}function Yn(t,e={}){let r=H(t,"bitmark","json",e.mode??"optimized",false,2,1,e.includeUnknownProperties??false);if(r.startsWith("error:"))throw new Error(r.slice(6).trim());return JSON.parse(r)}function qn(t,e={}){let r=t.map(o=>o!==null&&typeof o=="object"&&"bit"in o&&typeof o.bit=="object"?o:{bit:o}),n=H(JSON.stringify(r),"json","bitmark",e.mode??"optimized",false,2,1,false);if(n.startsWith("error:"))throw new Error(n.slice(6).trim());return n}function Xn(t,e={}){return H(t,e.inputFormat??"auto",e.outputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1,e.includeUnknownProperties??false)}function Qn(t,e={}){return pe(t,e.inputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function Zn(t){let e=ue(t);if(e.startsWith("error:"))throw new Error(e);return Number.parseInt(e,10)}function er(t){return JSON.parse(ce(t))}function tr(t,e={}){if(e.preHook||e.postHook)return Re(U,t,e);let r=e.patch===void 0?"":typeof e.patch=="string"?e.patch:JSON.stringify(e.patch);return ae(t,e.inputFormat??"auto",e.outputFormat??"json",e.mode??"optimized",r,e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function nr(t,e={}){return Ee(U,t,e,Pe)}function rr(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return oe(t,r,n)}function or(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return ie(t,r,n)}function ir(t={}){let e=t.infoType??"list",r=t.format??"text",n=t.bit??"",o=t.pretty??false,s=t.indent??2;return se(e,r,n,o,s)}export{Yn as bitmarkToObjects,rr as breakscapeText,Qn as canonicalize,Xn as convert,Zn as countBits,ir as info,Dn as init,Fe as initSync,rt as legacy,$n as lex,qn as objectsToBitmark,jt as patchEntry,er as splitBits,tr as transform,nr as transformParallel,or as unbreakscapeText,Kn as version};//# sourceMappingURL=bitmark-parser.min.js.map
5
5
  //# sourceMappingURL=bitmark-parser.min.js.map