@gmb/bitmark-parser 6.10.1 → 6.11.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 (50) hide show
  1. package/README.md +194 -20
  2. package/dist/browser/bitmark-parser.min.js +4 -4
  3. package/dist/browser/bitmark-parser.min.js.map +1 -1
  4. package/dist/browser/cjs/index.cjs +726 -180
  5. package/dist/browser/cjs/index.cjs.map +1 -1
  6. package/dist/browser/cjs/index.d.cts +1031 -29
  7. package/dist/browser/esm/index.d.ts +1031 -29
  8. package/dist/browser/esm/index.js +723 -180
  9. package/dist/browser/esm/index.js.map +1 -1
  10. package/dist/browser/esm/worker-entry.js +599 -96
  11. package/dist/browser/esm/worker-entry.js.map +1 -1
  12. package/dist/browser/wasm/bitmark_browser_full_wasm_bg.wasm +0 -0
  13. package/dist/browser/wasm/bitmark_json_wasm_bg.wasm +0 -0
  14. package/dist/browser/wasm/bitmark_wasm_bg.wasm +0 -0
  15. package/dist/index.cjs +52 -9
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +1031 -29
  18. package/dist/index.d.ts +1031 -29
  19. package/dist/index.js +49 -9
  20. package/dist/index.js.map +1 -1
  21. package/dist/legacy.cjs +4 -4
  22. package/dist/legacy.cjs.map +1 -1
  23. package/dist/legacy.js +4 -4
  24. package/dist/legacy.js.map +1 -1
  25. package/dist/worker-entry.cjs +7 -1
  26. package/dist/worker-entry.cjs.map +1 -1
  27. package/package.json +14 -8
  28. package/schema/bitmark.schema.json +2746 -573
  29. package/translations/translations.json +2940 -0
  30. package/wasm/bitmark_wasm.d.ts +30 -12
  31. package/wasm/bitmark_wasm.js +91 -47
  32. package/wasm/bitmark_wasm_bg.wasm +0 -0
  33. package/wasm/bitmark_wasm_bg.wasm.d.ts +2 -1
  34. package/wasm/package.json +1 -1
  35. package/wasm-bitmark-json/bitmark_json_wasm.d.ts +30 -12
  36. package/wasm-bitmark-json/bitmark_json_wasm.js +97 -53
  37. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
  38. package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +2 -1
  39. package/wasm-bitmark-json/package.json +1 -1
  40. package/wasm-browser-full/bitmark_browser_full_wasm.d.ts +126 -0
  41. package/wasm-browser-full/bitmark_browser_full_wasm.js +567 -0
  42. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm +0 -0
  43. package/wasm-browser-full/bitmark_browser_full_wasm_bg.wasm.d.ts +21 -0
  44. package/wasm-browser-full/package.json +20 -0
  45. package/dist/browser/bitmark_json_wasm_bg.wasm +0 -0
  46. package/dist/browser/bitmark_wasm_bg.wasm +0 -0
  47. package/dist/browser/cjs/bitmark_json_wasm_bg.wasm +0 -0
  48. package/dist/browser/cjs/bitmark_wasm_bg.wasm +0 -0
  49. package/dist/browser/esm/bitmark_json_wasm_bg.wasm +0 -0
  50. package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
package/README.md CHANGED
@@ -55,21 +55,43 @@ const bitInfo = info({ infoType: "list", format: "text" });
55
55
  console.log(version());
56
56
  ```
57
57
 
58
- ### WASM feature modules (`full` / `bitmark-json`)
58
+ ### WASM variants (`full` / `browser-full` / `bitmark-json`)
59
59
 
60
- The package ships **two wasm builds of the same engine** and selects one at
60
+ The package ships **three wasm builds of the same engine** and selects one at
61
61
  runtime — the API surface never changes:
62
62
 
63
63
  | Feature | Contents | Size (approx.) |
64
64
  | --- | --- | --- |
65
- | `full` (default) | everything | ~749 KB (~310 KB gzip) |
66
- | `bitmark-json` | bitmark ↔ JSON only: `convert`/`canonicalize`/`transform` (formats `auto`/`bitmark`/`json`, plus the `text` output), `info`, breakscape, text fragments | ~560 KB (~231 KB gzip) |
65
+ | `full` (Node default) | everything: rich `info` metadata + built-in translations | ~1003 KB (~390 KB gzip) |
66
+ | `browser-full` (browser default) | the same conversions, without either | ~857 KB (~341 KB gzip) |
67
+ | `bitmark-json` | bitmark ↔ JSON only: `convert`/`canonicalize`/`transform` (formats `auto`/`bitmark`/`json`, plus the `text` output), `info`, breakscape, text fragments | ~667 KB (~262 KB gzip) |
67
68
 
68
69
  Not in `bitmark-json`: the markup formats (`html`, `xml`, `xml-niso-iec`, …)
69
70
  as input or output (they return an `error: … not supported in this build`
70
71
  string), the `mappingReport` option (same error), and `lex` (throws
71
72
  `UnsupportedFeatureError`).
72
73
 
74
+ `full` and `browser-full` convert **identically** — they differ only in what
75
+ `info` can report: the META fields (tag descriptions, group provenance and raw
76
+ mapping patterns) and the built-in translations table. Bit titles, bit
77
+ descriptions and the bit-group / resource-group catalogs are in every variant,
78
+ in English; `register` supplies translations to the lean ones (see *Display
79
+ names and languages*).
80
+
81
+ Why the defaults differ: only the browser pays a download-latency cost for
82
+ those strings, and a Node backend loading wasm from disk has the same
83
+ requirements as the native CLI. But which channel an artifact ends up in is
84
+ not knowable from the artifact — browser code is routinely package-managed and
85
+ webpack-built — so both variants are available on both platforms and the
86
+ defaults are conveniences only. **If you bundle the Node entry for the
87
+ browser, select `browser-full` explicitly.**
88
+
89
+ > **Migrating from ≤ 6.10:** `full` used to mean what `browser-full` means now.
90
+ > Browser code that explicitly selected `"full"` should move to
91
+ > `"browser-full"` to keep its download size close to what it was; leave it on
92
+ > `"full"` to gain the metadata and built-in translations for ~49 KB gzip.
93
+ > Nothing else changes — the capabilities that were in `full` are in both.
94
+
73
95
  ```js
74
96
  import { init, convert, variant } from "@gmb/bitmark-parser";
75
97
 
@@ -88,12 +110,16 @@ Notes:
88
110
  - **Node**: with no explicit `init`, the first call lazily loads `full`
89
111
  synchronously — existing zero-init usage is unchanged. `initSync({ feature })`
90
112
  selects a variant synchronously.
91
- - **Browser**: `init()` is required as before; only the selected variant's
92
- `.wasm` is fetched (both small JS glue modules are in the bundle). Overlapping
93
- `init` calls: same-feature calls coalesce; a different-feature call supersedes
94
- an unfinished one (last call wins); every promise resolves once the
95
- finally-active module is live. In the browser, `initSync(bytes, { feature })`
96
- instantiates from bytes you supply.
113
+ - **Browser**: `init()` is required as before, and loads `browser-full`; only
114
+ the selected variant's `.wasm` is fetched (all three small JS glue modules
115
+ are in the bundle). Overlapping `init` calls: same-feature calls coalesce; a
116
+ different-feature call supersedes an unfinished one (last call wins); every
117
+ promise resolves once the finally-active module is live. In the browser,
118
+ `initSync(bytes, { feature })` instantiates from bytes you supply.
119
+ - **Supplying your own `.wasm`**: glue and module are a pair, so name the
120
+ feature the bytes belong to — `init({ feature, module_or_path })`. The
121
+ back-compat positional form `init(module_or_path)` stays on `full`, since
122
+ those bytes are `bitmark_wasm_bg.wasm`.
97
123
  - **Workers**: `transformParallel` workers load the active variant.
98
124
  - **Legacy API**: works on `bitmark-json` (it follows the active module) except
99
125
  its HTML-dependent members (e.g. `convertHtmlTable`), which throw.
@@ -124,8 +150,12 @@ Options:
124
150
  bit's config cannot resolve, at the bit body/footer — never inside cards or
125
151
  consumed by a chain) is appended after all real keys as an array of strings
126
152
  (a valueless `[@key]` → `true`); a key colliding with a configured key of
127
- the bit is `_`-prefixed. Unknown properties are never converted back to
128
- bitmark, and each occurrence warns whether or not it is included.
153
+ the bit is `_`-prefixed. A bare tag the bit does not declare (`[!…]`,
154
+ `[?…]`, `[#…]`, … on a bit whose config has no such tag) is an unknown
155
+ too, under the key a declaring bit would use (`[!x]` → `"instruction":
156
+ ["x"]`); a rejected resource attachment is not — it is still emitted, with
157
+ a warning. Unknown properties are never converted back to bitmark, and
158
+ each occurrence warns whether or not it is included.
129
159
  Also available on `bitmarkToObjects` and as the CLI's
130
160
  `--include-unknown-properties`
131
161
  - `mappingReport` — replace the converted output with a human-readable
@@ -153,7 +183,7 @@ Options:
153
183
  For bitmark input, output is a JSON array of entries with:
154
184
 
155
185
  - `bit` — serialized bit payload
156
- - `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)
186
+ - `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). Each issue carries a stable machine-readable `code` (`"unknown-property"`, `"missing-required-tag"`, …) beside its human-readable `message`, plus `text` and `location`. **Branch on `code`** — a shipped code never changes meaning, whereas the message text is not contractual and may be reworded in any release
157
187
  - `bitmark` — source bitmark text
158
188
 
159
189
  #### canonicalize(input: string, options?: CanonicalizeOptions): string
@@ -201,7 +231,8 @@ format-natural), nullability (absence as a distinct state — orthogonal to
201
231
  defaults), JSON keys, per-context overrides, and the card set structure. `"deprecated"` lists deprecated bits with their deprecation
202
232
  version and (separately) any migration target.
203
233
 
204
- - `infoType` — `"list"` (default), `"bit"`, `"all"`, or `"deprecated"`
234
+ - `infoType` — `"list"` (default), `"bit"`, `"all"`, `"deprecated"`,
235
+ `"bit-groups"`, `"resource-groups"`, or `"languages"`
205
236
  - `format` — `"text"` (default) or `"json"`
206
237
  - `bit` — filter to a specific bit type (when `infoType` is `"bit"`)
207
238
  - `pretty` — prettify JSON output (default: `false`)
@@ -209,10 +240,151 @@ version and (separately) any migration target.
209
240
  - `includeDeprecated` — include deprecated bits in `"list"`/`"all"` (default: `false`)
210
241
  - `onlyDeprecated` — restrict `"list"`/`"all"` to deprecated bits (default: `false`)
211
242
  - `full` — complete detail for `"bit"`/`"all"` (default: `false` = compact view)
243
+ - `language` — BCP-47 tag(s) for display names: one (`"de"`), several
244
+ (`["de", "fr"]` or `"de,fr"`), or `"all"` — exported as `ALL_LANGUAGES`
245
+ (default: English). More than one adds a `titles` map. See *Display names
246
+ and languages* below
247
+
248
+ `"bit-groups"` / `"resource-groups"` return the search/filter catalogs —
249
+ each group's key, translated title, description, optional aliases and
250
+ `subgroupOf`, and its members. They are available in EVERY build: the group
251
+ catalog and per-bit titles/descriptions are "descriptive" data, which the
252
+ lean wasm variants carry too. Deprecated members are excluded by default and
253
+ MARKED when included with `includeDeprecated: true`; a search index matching
254
+ already-published content needs them, because a migrating bit is re-emitted
255
+ under its target's name.
256
+
257
+ To derive quiz categories, intersect a bit's `bitGroups` with the groups
258
+ carrying `subgroupOf: "quizzes"` — `subgroupOf` is metadata and never implies
259
+ membership, so every member of a subgroup also declares the parent.
260
+
261
+ Only the META fields — TAG descriptions, group-inheritance provenance and raw
262
+ mapping patterns (the `info-meta` cargo feature) — depend on the build. They
263
+ are reported by the native CLI and the wasm `full` variant; `browser-full` and
264
+ `bitmark-json` omit them to stay small. Those are absent structurally: the key
265
+ is missing, never `null` or empty. Everything else `info` returns — including
266
+ bit titles, bit descriptions and the group catalogs — is identical in every
267
+ variant.
268
+
269
+ #### Display names and languages
270
+
271
+ `title` — on bits, bit groups and resource groups — is a DISPLAY name, meant
272
+ to be shown. Pass `language` to get it in another language:
273
+
274
+ ```js
275
+ info({ infoType: "bit-groups", format: "json", language: "de" });
276
+ ```
277
+
278
+ Resolution narrows one subtag at a time (`de-CH` → `de`), then falls back to
279
+ the English title, then to the technical key. A partially translated language
280
+ is therefore safe: untranslated entries stay English rather than blank.
281
+ **Technical identity is never translated** — `name`, `key`, tag names and
282
+ member lists are the same in every language, so you can key off them freely.
283
+
284
+ **Several languages at once.** Building a multilingual index should not mean
285
+ walking every bit once per language, so `language` also takes a list, or
286
+ `"all"` — exported as the `ALL_LANGUAGES` constant, so you can name it rather
287
+ than retype the literal:
288
+
289
+ ```js
290
+ import { info, ALL_LANGUAGES } from "@gmb/bitmark-parser";
291
+
292
+ const groups = JSON.parse(
293
+ info({ infoType: "bit-groups", format: "json", language: ALL_LANGUAGES }),
294
+ );
295
+ groups[0].titles; // { en: "Cloze", de: "Lückentext", … }
296
+
297
+ // equivalent, and the idiomatic JS spelling of a list
298
+ info({ infoType: "bit-groups", format: "json", language: ["de", "fr"] });
299
+
300
+ // what "all" expands to
301
+ JSON.parse(info({ infoType: "languages", format: "json" })); // ["de","en",…]
302
+ ```
303
+
304
+ **Getting every name in one call.** `bit-groups` carries each member's
305
+ display name, so one request answers "every bit type, what it is called, and
306
+ which categories it is in":
307
+
308
+ ```js
309
+ const groups = JSON.parse(
310
+ info({ infoType: "bit-groups", format: "json", includeDeprecated: true, language: "all" }),
311
+ );
312
+ groups[0].bitTypes[0]; // { name: "assignment", title: "Assignment", titles: {…} }
313
+ ```
314
+
315
+ That is ~132 KB. Do not reach for `infoType: "all"` to get names — it carries
316
+ the full per-tag detail for every bit (~5 MB) and is the wrong tool for this.
317
+
318
+ More than one language adds a **`titles`** map, and nothing else. It carries `en` when an English title exists, and is otherwise sparse: a requested language with no translation is absent rather than filled with English, so a gap stays visible.
319
+ It is keyed by the tag you ASKED for — request `de-CH` where only `de` exists
320
+ and you read `titles["de-CH"]`.
321
+
322
+ A single tag (or none) renders exactly as it always has, with no `titles`. The
323
+ shape follows your REQUEST rather than which language you picked: `"all"` adds
324
+ `titles` even on a build that resolves nothing but English.
325
+
326
+ `title` is the name in your PRIMARY language — the first one you named. Name
327
+ none and it is English; ask for `"all"` and it is English too, because with
328
+ everything already in `titles` there is no non-arbitrary "first". So `title`
329
+ tracks how you asked: consistent for any consumer that asks the same way every
330
+ time, which in practice is all of them — a UI names one language, an index
331
+ asks for `"all"`.
332
+
333
+ `title` stays optional, as its type says — it is the name in the language you
334
+ asked for, and a few bits have one in some languages but not in English (the
335
+ internal `_comment` and `_error`). Every other key is the same in every
336
+ language.
337
+
338
+ Which languages resolve depends on the build. The native CLI and the wasm
339
+ `full` variant bake the table in; `browser-full` and `bitmark-json` do not,
340
+ because ~76 KB of names is not something a browser should download without
341
+ asking. Those variants — and any build whose translations you want to
342
+ override — take the file at runtime:
343
+
344
+ ```js
345
+ import { init, register, info } from "@gmb/bitmark-parser";
346
+ import translations from "@gmb/bitmark-parser/translations" with { type: "json" };
347
+
348
+ await init({ feature: "browser-full" });
349
+ register({ type: "translations", data: JSON.stringify(translations) });
350
+ info({ infoType: "bit", bit: "cloze", format: "json", language: "de" });
351
+ ```
352
+
353
+ `register` REPLACES rather than merges: a second call supersedes the first
354
+ entirely, and the built-in table (where there is one) stays underneath, so a
355
+ key your file omits still resolves. It applies process-wide and survives an
356
+ `init` variant swap. The `language` option stays per-call, because that is
357
+ the axis that actually varies — one process may serve many.
358
+
359
+ The same file backs all three routes: `@gmb/bitmark-parser/translations`
360
+ (an opt-in subpath, so nothing pays for it unasked), the CLI's
361
+ `--translations <file>` flag, and what the `full` builds bake in. It holds
362
+ non-English names only — English lives in the config `title`, which every
363
+ build carries.
364
+
365
+ **The JSON shape is a stable contract**; a change to it is a semver-major
366
+ release. Language changes VALUES only — the key set is identical for every
367
+ language. Parse it and assert the matching exported type:
368
+
369
+ ```ts
370
+ import { info, type DeprecatedInfo } from "@gmb/bitmark-parser";
371
+
372
+ const deprecated = JSON.parse(
373
+ info({ infoType: "deprecated", format: "json" }),
374
+ ) as DeprecatedInfo;
375
+ ```
376
+
377
+ Result types: `BitListInfo`, `BitInfo` (`CompactBitInfo | FullBitInfo`),
378
+ `AllBitsInfo`, `DeprecatedInfo`, `BitGroupsInfo`, `ResourceGroupsInfo`, and
379
+ `InfoErrorResult` — returned in place of
380
+ a result when `infoType` is `"bit"` and the name is unknown. `info` itself
381
+ returns a `string` because it renders a document (`format: "text"`, `pretty`
382
+ and `indent` only mean anything for one).
212
383
 
213
- The WASM build omits bit/tag descriptions, group-inheritance provenance and
214
- raw mapping patterns (native-CLI-only, via the `info-meta` cargo feature) to
215
- keep the binary small.
384
+ **The text output is NOT a contract** — it is for humans and may change in
385
+ any release. Never parse it; every field it shows exists in the JSON form.
386
+ The normative definition of the JSON is
387
+ `.zen/specs/API-INF-info-output.tsp`.
216
388
 
217
389
  #### version(): string
218
390
 
@@ -420,9 +592,11 @@ The package includes pre-built browser bundles with the WASM module.
420
592
  </script>
421
593
  ```
422
594
 
423
- The CDN bundle carries both feature modules' JS glue; `init({ feature:
424
- "bitmark-json" })` fetches only the smaller `.wasm`, and a later
425
- `init({ feature: "full" })` upgrades in place (see *WASM feature modules*).
595
+ The CDN bundle carries all three variants' JS glue and fetches only the
596
+ selected variant's `.wasm` (from `dist/browser/wasm/`). A bare `init()` loads
597
+ `browser-full`; `init({ feature: "bitmark-json" })` fetches the smallest
598
+ build, and a later `init({ feature: "full" })` upgrades in place (see *WASM
599
+ variants*).
426
600
 
427
601
  ### Bundler (webpack / vite)
428
602
 
@@ -1,5 +1,5 @@
1
- var Le=Object.defineProperty;var vt=(t,e,r)=>e in t?Le(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var xe=(t,e)=>{for(var r in e)Le(t,r,{get:e[r],enumerable:true});};var B=(t,e,r)=>vt(t,typeof e!="symbol"?e+"":e,r);var he={};xe(he,{breakscape_text:()=>Et,canonicalize:()=>jt,convert:()=>St,convert_text:()=>Nt,count_bits:()=>At,default:()=>ke,info:()=>Pt,initSync:()=>we,is_bitmark:()=>Wt,lex:()=>Rt,prettify:()=>Mt,split_bits:()=>Lt,split_json_bits:()=>Jt,transform:()=>Bt,unbreakscape_text:()=>It});var p,x=0,X=null;function ne(){return (X===null||X.byteLength===0)&&(X=new Uint8Array(p.memory.buffer)),X}var re=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},Ft=typeof re.encodeInto=="function"?function(t,e){return re.encodeInto(t,e)}:function(t,e){let r=re.encode(t);return e.set(r),{read:t.length,written:r.length}};function k(t,e,r){if(r===void 0){let a=re.encode(t),u=e(a.length,1)>>>0;return ne().subarray(u,u+a.length).set(a),x=a.length,u}let n=t.length,o=e(n,1)>>>0,s=ne(),i=0;for(;i<n;i++){let a=t.charCodeAt(i);if(a>127)break;s[o+i]=a;}if(i!==n){i!==0&&(t=t.slice(i)),o=r(o,n,n=i+t.length*3,1)>>>0;let a=ne().subarray(o+i,o+n),u=Ft(t,a);i+=u.written,o=r(o,n,i,1)>>>0;}return x=i,o}var D=null;function v(){return (D===null||D.buffer.detached===true||D.buffer.detached===void 0&&D.buffer!==p.memory.buffer)&&(D=new DataView(p.memory.buffer)),D}var We=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&We.decode();function M(t,e){return t=t>>>0,We.decode(ne().subarray(t,t+e))}function Rt(t,e){let r,n;try{let i=p.__wbindgen_add_to_stack_pointer(-16),a=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),u=x,d=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),l=x;p.lex(i,a,u,d,l);var o=v().getInt32(i+0,!0),s=v().getInt32(i+4,!0);return r=o,n=s,M(o,s)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(r,n,1);}}function Et(t,e,r){let n,o;try{let a=p.__wbindgen_add_to_stack_pointer(-16),u=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),d=x,l=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),_=x,g=k(r,p.__wbindgen_export_0,p.__wbindgen_export_1),m=x;p.breakscape_text(a,u,d,l,_,g,m);var s=v().getInt32(a+0,!0),i=v().getInt32(a+4,!0);return n=s,o=i,M(s,i)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(n,o,1);}}function It(t,e,r){let n,o;try{let a=p.__wbindgen_add_to_stack_pointer(-16),u=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),d=x,l=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),_=x,g=k(r,p.__wbindgen_export_0,p.__wbindgen_export_1),m=x;p.unbreakscape_text(a,u,d,l,_,g,m);var s=v().getInt32(a+0,!0),i=v().getInt32(a+4,!0);return n=s,o=i,M(s,i)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(n,o,1);}}function Pt(t,e,r,n,o,s,i,a){let u,d;try{let g=p.__wbindgen_add_to_stack_pointer(-16),m=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),w=x,b=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),f=x,y=k(r,p.__wbindgen_export_0,p.__wbindgen_export_1),T=x;p.info(g,m,w,b,f,y,T,n,o,s,i,a);var l=v().getInt32(g+0,!0),_=v().getInt32(g+4,!0);return u=l,d=_,M(l,_)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(u,d,1);}}function Bt(t,e,r,n,o,s,i,a){let u,d;try{let g=p.__wbindgen_add_to_stack_pointer(-16),m=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),w=x,b=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),f=x,y=k(r,p.__wbindgen_export_0,p.__wbindgen_export_1),T=x,A=k(n,p.__wbindgen_export_0,p.__wbindgen_export_1),J=x,H=k(o,p.__wbindgen_export_0,p.__wbindgen_export_1),ye=x;p.transform(g,m,w,b,f,y,T,A,J,H,ye,s,i,a);var l=v().getInt32(g+0,!0),_=v().getInt32(g+4,!0);return u=l,d=_,M(l,_)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(u,d,1);}}function St(t,e,r,n,o,s,i,a,u){let d,l;try{let m=p.__wbindgen_add_to_stack_pointer(-16),w=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),b=x,f=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),y=x,T=k(r,p.__wbindgen_export_0,p.__wbindgen_export_1),A=x,J=k(n,p.__wbindgen_export_0,p.__wbindgen_export_1),H=x;p.convert(m,w,b,f,y,T,A,J,H,o,s,i,a,u);var _=v().getInt32(m+0,!0),g=v().getInt32(m+4,!0);return d=_,l=g,M(_,g)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(d,l,1);}}function jt(t,e,r,n,o,s){let i,a;try{let l=p.__wbindgen_add_to_stack_pointer(-16),_=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),g=x,m=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),w=x,b=k(r,p.__wbindgen_export_0,p.__wbindgen_export_1),f=x;p.canonicalize(l,_,g,m,w,b,f,n,o,s);var u=v().getInt32(l+0,!0),d=v().getInt32(l+4,!0);return i=u,a=d,M(u,d)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(i,a,1);}}function At(t){let e,r;try{let s=p.__wbindgen_add_to_stack_pointer(-16),i=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),a=x;p.count_bits(s,i,a);var n=v().getInt32(s+0,!0),o=v().getInt32(s+4,!0);return e=n,r=o,M(n,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(e,r,1);}}function Lt(t){let e,r;try{let s=p.__wbindgen_add_to_stack_pointer(-16),i=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),a=x;p.split_bits(s,i,a);var n=v().getInt32(s+0,!0),o=v().getInt32(s+4,!0);return e=n,r=o,M(n,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(e,r,1);}}function Wt(t){let e=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),r=x;return p.is_bitmark(e,r)!==0}function Jt(t){let e,r;try{let s=p.__wbindgen_add_to_stack_pointer(-16),i=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),a=x;p.split_json_bits(s,i,a);var n=v().getInt32(s+0,!0),o=v().getInt32(s+4,!0);return e=n,r=o,M(n,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(e,r,1);}}function Mt(t,e){let r,n;try{let i=p.__wbindgen_add_to_stack_pointer(-16),a=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),u=x;p.prettify(i,a,u,e);var o=v().getInt32(i+0,!0),s=v().getInt32(i+4,!0);return r=o,n=s,M(o,s)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(r,n,1);}}function Nt(t,e,r,n){let o,s;try{let u=p.__wbindgen_add_to_stack_pointer(-16),d=k(t,p.__wbindgen_export_0,p.__wbindgen_export_1),l=x,_=k(e,p.__wbindgen_export_0,p.__wbindgen_export_1),g=x,m=k(r,p.__wbindgen_export_0,p.__wbindgen_export_1),w=x,b=k(n,p.__wbindgen_export_0,p.__wbindgen_export_1),f=x;p.convert_text(u,d,l,_,g,m,w,b,f);var i=v().getInt32(u+0,!0),a=v().getInt32(u+4,!0);return o=i,s=a,M(i,a)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(o,s,1);}}async function Ct(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 Je(){let t={};return t.wbg={},t}function Me(t,e){return p=t.exports,Ne.__wbindgen_wasm_module=e,D=null,X=null,p}function we(t){if(p!==void 0)return p;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=Je();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));let r=new WebAssembly.Instance(t,e);return Me(r,t)}async function Ne(t){if(p!==void 0)return p;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=Je();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await Ct(await t,e);return Me(r,n)}var ke=Ne;var ve={};xe(ve,{breakscape_text:()=>Ut,canonicalize:()=>zt,convert:()=>Gt,convert_text:()=>Qt,count_bits:()=>$t,default:()=>Te,info:()=>Dt,initSync:()=>Oe,is_bitmark:()=>Yt,prettify:()=>Xt,split_bits:()=>Kt,split_json_bits:()=>qt,transform:()=>Zt,unbreakscape_text:()=>Ht});var c,h=0,Q=null;function oe(){return (Q===null||Q.byteLength===0)&&(Q=new Uint8Array(c.memory.buffer)),Q}var ie=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},Vt=typeof ie.encodeInto=="function"?function(t,e){return ie.encodeInto(t,e)}:function(t,e){let r=ie.encode(t);return e.set(r),{read:t.length,written:r.length}};function O(t,e,r){if(r===void 0){let a=ie.encode(t),u=e(a.length,1)>>>0;return oe().subarray(u,u+a.length).set(a),h=a.length,u}let n=t.length,o=e(n,1)>>>0,s=oe(),i=0;for(;i<n;i++){let a=t.charCodeAt(i);if(a>127)break;s[o+i]=a;}if(i!==n){i!==0&&(t=t.slice(i)),o=r(o,n,n=i+t.length*3,1)>>>0;let a=oe().subarray(o+i,o+n),u=Vt(t,a);i+=u.written,o=r(o,n,i,1)>>>0;}return h=i,o}var G=null;function F(){return (G===null||G.buffer.detached===true||G.buffer.detached===void 0&&G.buffer!==c.memory.buffer)&&(G=new DataView(c.memory.buffer)),G}var Ce=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&Ce.decode();function N(t,e){return t=t>>>0,Ce.decode(oe().subarray(t,t+e))}function Ut(t,e,r){let n,o;try{let a=c.__wbindgen_add_to_stack_pointer(-16),u=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),d=h,l=O(e,c.__wbindgen_export_0,c.__wbindgen_export_1),_=h,g=O(r,c.__wbindgen_export_0,c.__wbindgen_export_1),m=h;c.breakscape_text(a,u,d,l,_,g,m);var s=F().getInt32(a+0,!0),i=F().getInt32(a+4,!0);return n=s,o=i,N(s,i)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(n,o,1);}}function Ht(t,e,r){let n,o;try{let a=c.__wbindgen_add_to_stack_pointer(-16),u=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),d=h,l=O(e,c.__wbindgen_export_0,c.__wbindgen_export_1),_=h,g=O(r,c.__wbindgen_export_0,c.__wbindgen_export_1),m=h;c.unbreakscape_text(a,u,d,l,_,g,m);var s=F().getInt32(a+0,!0),i=F().getInt32(a+4,!0);return n=s,o=i,N(s,i)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(n,o,1);}}function Dt(t,e,r,n,o,s,i,a){let u,d;try{let g=c.__wbindgen_add_to_stack_pointer(-16),m=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),w=h,b=O(e,c.__wbindgen_export_0,c.__wbindgen_export_1),f=h,y=O(r,c.__wbindgen_export_0,c.__wbindgen_export_1),T=h;c.info(g,m,w,b,f,y,T,n,o,s,i,a);var l=F().getInt32(g+0,!0),_=F().getInt32(g+4,!0);return u=l,d=_,N(l,_)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(u,d,1);}}function Gt(t,e,r,n,o,s,i,a,u){let d,l;try{let m=c.__wbindgen_add_to_stack_pointer(-16),w=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),b=h,f=O(e,c.__wbindgen_export_0,c.__wbindgen_export_1),y=h,T=O(r,c.__wbindgen_export_0,c.__wbindgen_export_1),A=h,J=O(n,c.__wbindgen_export_0,c.__wbindgen_export_1),H=h;c.convert(m,w,b,f,y,T,A,J,H,o,s,i,a,u);var _=F().getInt32(m+0,!0),g=F().getInt32(m+4,!0);return d=_,l=g,N(_,g)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(d,l,1);}}function zt(t,e,r,n,o,s){let i,a;try{let l=c.__wbindgen_add_to_stack_pointer(-16),_=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),g=h,m=O(e,c.__wbindgen_export_0,c.__wbindgen_export_1),w=h,b=O(r,c.__wbindgen_export_0,c.__wbindgen_export_1),f=h;c.canonicalize(l,_,g,m,w,b,f,n,o,s);var u=F().getInt32(l+0,!0),d=F().getInt32(l+4,!0);return i=u,a=d,N(u,d)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(i,a,1);}}function $t(t){let e,r;try{let s=c.__wbindgen_add_to_stack_pointer(-16),i=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),a=h;c.count_bits(s,i,a);var n=F().getInt32(s+0,!0),o=F().getInt32(s+4,!0);return e=n,r=o,N(n,o)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(e,r,1);}}function Kt(t){let e,r;try{let s=c.__wbindgen_add_to_stack_pointer(-16),i=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),a=h;c.split_bits(s,i,a);var n=F().getInt32(s+0,!0),o=F().getInt32(s+4,!0);return e=n,r=o,N(n,o)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(e,r,1);}}function Yt(t){let e=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),r=h;return c.is_bitmark(e,r)!==0}function qt(t){let e,r;try{let s=c.__wbindgen_add_to_stack_pointer(-16),i=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),a=h;c.split_json_bits(s,i,a);var n=F().getInt32(s+0,!0),o=F().getInt32(s+4,!0);return e=n,r=o,N(n,o)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(e,r,1);}}function Xt(t,e){let r,n;try{let i=c.__wbindgen_add_to_stack_pointer(-16),a=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),u=h;c.prettify(i,a,u,e);var o=F().getInt32(i+0,!0),s=F().getInt32(i+4,!0);return r=o,n=s,N(o,s)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(r,n,1);}}function Qt(t,e,r,n){let o,s;try{let u=c.__wbindgen_add_to_stack_pointer(-16),d=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),l=h,_=O(e,c.__wbindgen_export_0,c.__wbindgen_export_1),g=h,m=O(r,c.__wbindgen_export_0,c.__wbindgen_export_1),w=h,b=O(n,c.__wbindgen_export_0,c.__wbindgen_export_1),f=h;c.convert_text(u,d,l,_,g,m,w,b,f);var i=F().getInt32(u+0,!0),a=F().getInt32(u+4,!0);return o=i,s=a,N(i,a)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(o,s,1);}}function Zt(t,e,r,n,o,s,i,a){let u,d;try{let g=c.__wbindgen_add_to_stack_pointer(-16),m=O(t,c.__wbindgen_export_0,c.__wbindgen_export_1),w=h,b=O(e,c.__wbindgen_export_0,c.__wbindgen_export_1),f=h,y=O(r,c.__wbindgen_export_0,c.__wbindgen_export_1),T=h,A=O(n,c.__wbindgen_export_0,c.__wbindgen_export_1),J=h,H=O(o,c.__wbindgen_export_0,c.__wbindgen_export_1),ye=h;c.transform(g,m,w,b,f,y,T,A,J,H,ye,s,i,a);var l=F().getInt32(g+0,!0),_=F().getInt32(g+4,!0);return u=l,d=_,N(l,_)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(u,d,1);}}async function en(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 Ve(){let t={};return t.wbg={},t}function Ue(t,e){return c=t.exports,He.__wbindgen_wasm_module=e,G=null,Q=null,c}function Oe(t){if(c!==void 0)return c;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=Ve();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));let r=new WebAssembly.Instance(t,e);return Ue(r,t)}async function He(t){if(c!==void 0)return c;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_json_wasm_bg.wasm",import.meta.url));let e=Ve();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await en(await t,e);return Ue(r,n)}var Te=He;var Z={version:"6.10.1"};var ae=class extends Error{constructor(){super("wasm not initialised: call init() (or init({ feature: \u2026 })) first"),this.name="NotInitializedError";}},ee=class extends Error{constructor(e,r){super(`${e} is not available in the loaded wasm module${r?` (feature: "${r}")`:""}; init({ feature: "full" }) to load it`),this.name="UnsupportedFeatureError";}},se,Ge,De;function j(){if(!se&&De&&De(),!se)throw new ae;return se}function Fe(t,e){se=e,Ge=t;}function $(){return Ge}function K(t){return t.startsWith("error:")}function pe(t){let e=t instanceof Error?t.message:String(t);return e.startsWith("error:")?e:`error: ${e}`}function tn(t){let e=t.trim();return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):t}function nn(t){if(t===void 0)return [];if(typeof t=="string"){let e=t.trim();return e===""?[]:JSON.parse(e)}return t}function rn(t,e,r){if(r){let s=t.split_bits(e);if(K(s))throw new Error(s);let i=JSON.parse(s);return i.map(a=>({view:{format:"bitmark",index:a.index,total:i.length,source:a.source},source:a.source}))}let n=t.split_json_bits(e);if(K(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 Re(t,e,r){let n=r.mode??"optimized",o=r.outputFormat??"json",s=r.spacesAroundValues??1,i=r.indent??2,a=r.pretty??false,u=r.inputFormat??"auto",d=u==="bitmark"||u!=="json"&&t.is_bitmark(e),l=d?"bitmark":"json",_=nn(r.patch),g=rn(t,e,d),m=g.length,w=[],b=[];for(let f=0;f<m;f++){let{view:y,source:T}=g[f];y.index=f,y.total=m;let A=r.preHook?r.preHook(y)||{}:{};if(A.drop)continue;let J=A.patches?[..._,...A.patches]:_;w.push({index:f,source:T,inputFormat:l,outputFormat:A.outputFormat??o,mode:n,patchJson:JSON.stringify(J),spacesAroundValues:s}),b.push(y);}return {jobs:w,views:b,output:o,pretty:a,indent:i}}function on(t,e){let r=t.transform(e.source,e.inputFormat,e.outputFormat,e.mode,e.patchJson,false,2,e.spacesAroundValues);return K(r)?r:e.outputFormat==="json"?tn(r):r}function Ee(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 ze(t,e,r){let n;try{n=Re(t,e,r);}catch(s){return pe(s)}let o=[];for(let s=0;s<n.jobs.length;s++){let i=on(t,n.jobs[s]);if(K(i))return i;r.postHook?.(n.views[s],i),o.push(i);}return Ee(t,o,n.output,n.pretty,n.indent)}async function $e(t,e,r,n){let o;try{o=Re(t,e,r);}catch(i){return pe(i)}let s;try{s=await n(o.jobs,r.workers??4);}catch(i){return pe(i)}for(let i=0;i<s.length;i++){if(K(s[i]))return s[i];r.postHook?.(o.views[i],s[i]);}return Ee(t,s,o.output,o.pretty,o.indent)}var Ie;function Ke(t){Ie=t;}function I(){if(!Ie)throw new Error("legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)");return Ie()}function Ye(t,e,r){if(t.length===0)return Promise.resolve([]);let n=Math.max(1,Math.min(e,t.length)),o=new URL("./worker-entry.js",import.meta.url);return new Promise((s,i)=>{let a=new Array(t.length),u=0,d=0,l=false,_=[],g=()=>{for(let b of _)b.terminate();},m=b=>{l||(l=true,g(),i(b));},w=b=>{if(l||u>=t.length)return;let f=u++;b.postMessage({id:f,job:t[f],feature:r});};for(let b=0;b<n;b++){let f=new Worker(o,{type:"module"});_.push(f),f.onmessage=y=>{let T=y.data;if(!l){if(!T.ok){m(new Error(T.error??"worker job failed"));return}if(a[T.id]=T.element,d++,d===t.length){l=true,g(),s(a);return}w(f);}},f.onerror=y=>m(new Error(y.message||"worker error"));}for(let b of _)w(b);})}var ht={};xe(ht,{Ast:()=>pt,BitType:()=>ot,BitmarkFileGenerator:()=>dt,BitmarkGenerator:()=>ct,BitmarkParser:()=>bt,BitmarkParserGenerator:()=>ge,BitmarkParserType:()=>mn,BitmarkStringGenerator:()=>ut,BitmarkVersion:()=>fn,BodyTextFormat:()=>xn,BoundingBoxIndex:()=>at,Builder:()=>fe,CardSetVersion:()=>gn,FileWriter:()=>wt,HtmlTableGenerator:()=>gt,HtmlTableParser:()=>mt,InfoFormat:()=>yn,InfoType:()=>bn,Input:()=>dn,InputFormat:()=>_n,JsonFileGenerator:()=>ft,JsonGenerator:()=>lt,JsonParser:()=>yt,JsonStringGenerator:()=>_t,LegacyUnsupportedError:()=>Y,NodeType:()=>st,Output:()=>ln,ResourceBuilder:()=>me,StreamWriter:()=>kt,StringWriter:()=>xt,TextLocation:()=>wn,TextMarkType:()=>nt,TextNodeType:()=>rt,bitmarkTextParse:()=>et,isPseudoAst:()=>Xe});var Y=class extends Error{constructor(e){super(e),this.name="LegacyUnsupportedError";}};function V(t,e){throw new Y(`'${t}' is not supported by the @gmb/bitmark-parser legacy API`+(e?`: ${e}`:""))}function C(t,e){throw new Y(`Option '${t}' is not supported by the @gmb/bitmark-parser legacy API`+(e?`: ${e}`:""))}var Pe="bitmark v2 output is not supported (this parser is bitmark v3 only)";function Be(t){t.bitmarkVersion===2&&C("bitmarkVersion: 2",Pe);}function ue(t){t.explicitTextFormat&&C("bitmarkOptions.explicitTextFormat"),t.cardSetVersion===1&&C("bitmarkOptions.cardSetVersion: 1",Pe),t.debugGenerationInline&&C("bitmarkOptions.debugGenerationInline"),t.noBreakscaping&&C("bitmarkOptions.noBreakscaping");}function de(t){t.textAsPlainText&&C("jsonOptions.textAsPlainText",Pe),t.debugGenerationInline&&C("jsonOptions.debugGenerationInline");}function z(t){return t===true?{pretty:true,indent:2}:typeof t=="number"&&t>0?{pretty:true,indent:t}:{pretty:false,indent:2}}function le(t){return t===void 0||t===true?1:t===false?0:Math.max(0,Math.min(10,t))}function _e(t){switch(t){case "text":case "latex":case "json":case "xml":return "plainText";default:return "bitmark++"}}var qe=Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");function q(t){let e={bits:t};return Object.defineProperty(e,qe,{value:true,enumerable:false}),e}function Xe(t){return t!==null&&typeof t=="object"&&(qe in t||Array.isArray(t.bits))}var Qe={"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 Se=Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser"),an={bitType:"type",textFormat:"format",flashcards:"cards",markConfig:"marks"},pn={"bitmark--":"bitmark++","bitmark+":"bitmark++"},cn={bitmark:"bitmark++",text:"text",json:"json",latex:"latex",xml:"xml"},un=["title","subtitle","item","lead","pageNumber","marginNumber","hint","instruction","caption"],fe=class{buildBitmark(e){let r=q(e.bits??[]);return e.errors!==void 0&&(r.errors=e.errors),r}buildBit(e,r){let n=I(),o={...e},s=o.bitType,i=this.getBitConfig(s),a={};a.type=s,o.isCommented&&(a.type="_comment",a.originalType=s),delete o.bitType,delete o.isCommented;let u=o.textFormat;u!==void 0?(a.format=pn[u]??u,delete o.textFormat):a.format=cn[i.bodyFormat??""]??"bitmark++",delete o.resourceType;let d=o.body;d!=null&&typeof d=="object"&&"body"in d&&(a.body=d.body,delete o.body),o.example!==void 0?(a.isExample=true,a.example=o.example,delete o.example,delete o.__isDefaultExample):o.__isDefaultExample&&(a.isExample=true,delete o.__isDefaultExample);let l=o.resources;if(l!==void 0&&s!==void 0){let f=Array.isArray(l)?l:[l],y=Qe[s];y?a[y.key]=f.filter(T=>T!==null&&typeof T=="object"&&T.type===y.resourceType):f.length>=1&&(a.resource=f[0]),delete o.resources;}let _=o.parser;delete o.parser;let g=o.extraProperties;delete o.extraProperties;for(let[f,y]of Object.entries(o))y!==void 0&&(a[an[f]??f]=y);if(g)for(let[f,y]of Object.entries(g))f in a||(a[f]=y);this.parseStringTexts(a);let m=n.convert(JSON.stringify([{bit:a}]),"json","json","optimized",false,2,1,false,false);if(m.startsWith("error:"))throw new Error(m.slice(6).trim());let b=JSON.parse(m)[0]?.bit??a;for(let[f,y]of Object.entries(a))f in b||y===false||y===""||y===null||Array.isArray(y)&&y.length===0||(b[f]=y);return _!==void 0&&Object.defineProperty(b,Se,{value:_,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(a=>a!=null).map(a=>({text:a.text??"",isCorrect:a.isCorrect??false,isHighlighted:a.isHighlighted??false,...Ze(a,["text","isCorrect","isHighlighted"])})):[],prefix:n.prefix??"",postfix:n.postfix??"",...Ze(n,["type","texts","prefix","postfix","attrs"]),attrs:{}}}parseStringTexts(e){let r=I(),n=(i,a)=>{if(i==="")return i;let u=r.convert_text(i,"textToAst","bitmark++",a);try{return JSON.parse(u)}catch{return i}},o=e.format,s=o===void 0||o==="bitmark++"||o==="bitmark+";if(typeof e.body=="string")if(o==="json")try{e.body=JSON.parse(e.body);}catch{e.body=null;}else s&&(e.body=n(e.body,"body"));for(let i of un){let a=e[i];typeof a=="string"&&(e[i]=n(a,"tag"));}}getBitConfig(e){let r=I();if(e!==void 0)try{let n=JSON.parse(r.info("bit","json",e,!1,2,!1,!1,!0));if(n.error===void 0)return {bodyFormat:n.body?.format}}catch{}throw new Error(`No config found for bit: ${e}`)}};function Ze(t,e){let r={};for(let[n,o]of Object.entries(t))o!==void 0&&!e.includes(n)&&(r[n]=o);return r}var ge=class{version(){return Z.version}convert(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);Be(n),ue(s),de(o),this.checkBrowserFileWrite(n.outputFile);let i=I(),{source:a,isBitmark:u}=this.resolveInput(e,n.inputFormat),d=n.outputFormat??(u?"json":"bitmark"),l=d==="ast"?"json":d,{pretty:_,indent:g}=z(o.prettify),m=l==="bitmark"?z(s.prettifyJson):{pretty:_,indent:g},w=le(s.spacesAroundValues),b=!o.excludeUnknownProperties,f=i.convert(a,u?"bitmark":"json",l,"optimized",m.pretty,m.indent,w,b,false);if(this.throwOnError(f),d==="bitmark"||d==="text")return this.deliver(f,n.outputFile,n.fileOptions);if(d==="json")return n.outputFile?this.deliver(f,n.outputFile,n.fileOptions):_||o.stringify?f:JSON.parse(f);let y=q(JSON.parse(f));return n.outputFile?this.deliver(JSON.stringify(y),n.outputFile,n.fileOptions):y}upgrade(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);Be(n),ue(s),de(o),this.checkBrowserFileWrite(n.outputFile);let i=I(),{source:a,isBitmark:u}=this.resolveInput(e,n.inputFormat),{pretty:d,indent:l}=z(u?s.prettifyJson:o.prettify),_=le(s.spacesAroundValues),g=i.canonicalize(a,u?"bitmark":"json","optimized",d,l,_);return this.throwOnError(g),u?this.deliver(g,n.outputFile,n.fileOptions):n.outputFile?this.deliver(g,n.outputFile,n.fileOptions):d||o.stringify?g:JSON.parse(g)}info(e){let r=Object.assign({},e),n=I(),o=r.type??"list",s=r.outputFormat??"text",{pretty:i,indent:a}=z(r.prettify),u=s==="pojo"?"json":s,d=n.info(o,u,r.bit??"",i,a,false,false,true);return this.throwOnError(d),s==="pojo"?JSON.parse(d):d}generateConfig(e){V("BitmarkParserGenerator.generateConfig","bpg-internal development tool");}convertHtmlTable(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);ue(s),de(o),n.keepUnknownTags&&C("keepUnknownTags"),n.noBreakscaping&&C("noBreakscaping"),this.checkBrowserFileWrite(n.outputFile);let i=I(),a=typeof e=="string"?this.maybeReadFile(e,void 0):"";if(!(n.inputFormat==="html"||n.inputFormat===void 0&&typeof e=="string"&&/<table[\s>]/iu.test(a))){let{source:T,isBitmark:A}=this.resolveInput(e,void 0),J=i.convert(T,A?"bitmark":"json","html","optimized",false,2,1,false,false);return this.throwOnError(J),this.deliver(je(J).join(`
3
- `),n.outputFile,n.fileOptions)}let d=n.tableFormat==="table"?"table":"table-extended",l=je(a).map(T=>`<bitmark-bit data-type="${d}" data-format="bitmark++">${T}</bitmark-bit>`).join(""),_=n.outputFormat??"bitmark",{pretty:g,indent:m}=z(o.prettify),w=le(s.spacesAroundValues);if(_==="html"){let T=i.convert(l,"html","html","optimized",false,2,1,false,false);return this.throwOnError(T),this.deliver(je(T).join(`
4
- `),n.outputFile,n.fileOptions)}let b=_==="ast"?"json":_,f=i.convert(l,"html",b,"optimized",g,m,w,false,false);if(this.throwOnError(f),_==="bitmark"||_==="text")return this.deliver(f,n.outputFile,n.fileOptions);if(_==="json")return n.outputFile?this.deliver(f,n.outputFile,n.fileOptions):g||o.stringify?f:JSON.parse(f);let y=q(JSON.parse(f));return n.outputFile?this.deliver(JSON.stringify(y),n.outputFile,n.fileOptions):y}createAst(e,r){let n=Object.assign({},r),o=I(),{source:s,isBitmark:i}=this.resolveInput(e,n.inputFormat),a=o.convert(s,i?"bitmark":"json","json","optimized",false,2,1,true,false);return this.throwOnError(a),q(JSON.parse(a))}breakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=I(),s=this.maybeReadFile(e,n.inputFormat),i=o.breakscape_text(s,_e(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=I(),s=this.maybeReadFile(e,n.inputFormat),i=o.unbreakscape_text(s,_e(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=I(),i=n.textFormat===void 0||_e(n.textFormat)==="bitmark++",a=n.textLocation??"body",u,d;if(typeof e=="string"?(u=this.maybeReadFile(e,n.inputFormat),d=this.parseTextAstString(u)):(u=JSON.stringify(e),d=Array.isArray(e)?e:void 0),d!==void 0){let w=i?s.convert_text(JSON.stringify(d),"astToText","bitmark++",a):s.convert_text(JSON.stringify(d),"astToPlainText","plainText",a);return this.throwOnError(w),this.deliver(w,n.outputFile,n.fileOptions)}let l=s.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(l);let{pretty:_,indent:g}=z(o.prettify),m=_?s.prettify(l,g):l;return n.outputFile?this.deliver(m,n.outputFile,n.fileOptions):_?m:JSON.parse(l)}textAstToPlainText(e,r){let o=I().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=I();if(n==="plainText")return typeof e=="string"?String(e):"";if(n==="bitmarkText"){let u=o.convert_text(String(e),"textToAst","bitmark++","body"),d=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(d),d}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),a=o.convert(s,i?"bitmark":"json","text","optimized",false,2,1,false,false);return this.throwOnError(a),a}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(I().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(a=>this.toWrapperEntry(a))),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?.[Se];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 je(t){let e=[],r=t.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let s=0,i=o,a=-1;for(;i<t.length;){let u=r.indexOf("<table",i),d=r.indexOf("</table",i);if(d===-1)break;if(u!==-1&&u<d)s++,i=u+6;else {s--;let l=r.indexOf(">",d);if(i=l===-1?t.length:l+1,s===0){a=i;break}}}if(a===-1)break;e.push(t.slice(o,a)),n=a;}return e}function et(t){let e=I().convert_text(t,"textToAst","bitmark++","body");if(e.startsWith("error:"))throw new Error(e.slice(6).trim());return JSON.parse(e)}var S={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 P(t){return (e,r,n)=>{if(!r)return;let{value:o,...s}=r,i={[t.valueField]:o??""};for(let[a,u]of Object.entries(s))u!==void 0&&(i[a]=u);return {type:t.type,[t.key]:i}}}var tt=Object.fromEntries(Object.values(S).map(t=>[t.type,t])),me=class{constructor(){B(this,"imageResource",P(S.imageResource));B(this,"imageLinkResource",P(S.imageLinkResource));B(this,"audioResource",P(S.audioResource));B(this,"audioEmbedResource",P(S.audioEmbedResource));B(this,"audioLinkResource",P(S.audioLinkResource));B(this,"videoResource",P(S.videoResource));B(this,"videoEmbedResource",P(S.videoEmbedResource));B(this,"videoLinkResource",P(S.videoLinkResource));B(this,"stillImageFilmEmbedResource",P(S.stillImageFilmEmbedResource));B(this,"stillImageFilmLinkResource",P(S.stillImageFilmLinkResource));B(this,"articleResource",P(S.articleResource));B(this,"documentResource",P(S.documentResource));B(this,"documentEmbedResource",P(S.documentEmbedResource));B(this,"documentLinkResource",P(S.documentLinkResource));B(this,"documentDownloadResource",P(S.documentDownloadResource));B(this,"appLinkResource",P(S.appLinkResource));B(this,"websiteLinkResource",P(S.websiteLinkResource));}resourceFromResourceJson(e,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,s=[];for(let i of o){let a=tt[i.type];if(!a)continue;let u=i[a.key]??{},{[a.valueField]:d,...l}=u,_=P(a)(void 0,{value:d,...l});_&&s.push(_);}if(s.length!==0)return n?s[0]:s}resourceFromResourceDataJson(e,r,n){if(!n)return;let o=tt[r];if(!o)return;let s=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:a,src:u,body:d,...l}=i,_=a??u??d??s;return P(o)(e,{value:_,...l})}};var dn={string:"string",file:"file"},ln={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},_n={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},fn={v2:2,v3:3},gn={v1:1,v2:2},mn={peggy:"peggy"},bn={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},yn={text:"text",json:"json",pojo:"pojo"},xn={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},wn={tag:"tag",body:"body"};var nt={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"},rt={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 kn(t){return t.replace(/-([a-z0-9])/gu,(e,r)=>r.toUpperCase())}var Ae;function te(){if(!Ae){let t=I(),e=JSON.parse(t.info("all","json","",false,2,true,false,false)),r={_standard:"_standard"};for(let{name:n}of e)r[kn(n)]=n;Ae=r;}return Ae}var ot=new Proxy({},{get:(t,e)=>typeof e=="string"?te()[e]:void 0,has:(t,e)=>typeof e=="string"&&e in te(),ownKeys:()=>Reflect.ownKeys(te()),getOwnPropertyDescriptor:(t,e)=>typeof e=="string"&&e in te()?{value:te()[e],enumerable:true,configurable:true,writable:false}:void 0});function it(t,e){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${t}]`:V(t,e),has:()=>V(t,e),ownKeys:()=>V(t,e)})}var st=it("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),at=it("BoundingBoxIndex","bpg-internal bounding-box utility");function L(t,e){return class{constructor(){V(t,e);}}}var hn="the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave",W="internal class of bpg's TS implementation",pt=L("Ast",hn),ct=L("BitmarkGenerator",W),ut=L("BitmarkStringGenerator",W),dt=L("BitmarkFileGenerator",W),lt=L("JsonGenerator",W),_t=L("JsonStringGenerator",W),ft=L("JsonFileGenerator",W),gt=L("HtmlTableGenerator",W),mt=L("HtmlTableParser",W),bt=L("BitmarkParser",W),yt=L("JsonParser",W),xt=L("StringWriter",W),wt=L("FileWriter",W),kt=L("StreamWriter",W);function On(t,e,r){return r===void 0?{path:t,op:e}:{path:t,op:e,value:r}}function Tn(t,e={}){let r=j();if(typeof r.lex!="function")throw new ee("lex",$());return r.lex(t,e.stage??"lex")}function vn(t,e={}){let r=j().convert(t,"bitmark","json",e.mode??"optimized",false,2,1,e.includeUnknownProperties??false,false);if(r.startsWith("error:"))throw new Error(r.slice(6).trim());return JSON.parse(r)}function Fn(t,e={}){let r=t.map(o=>o!==null&&typeof o=="object"&&"bit"in o&&typeof o.bit=="object"?o:{bit:o}),n=j().convert(JSON.stringify(r),"json","bitmark",e.mode??"optimized",false,2,1,false,false);if(n.startsWith("error:"))throw new Error(n.slice(6).trim());return n}function Rn(t,e={}){return j().convert(t,e.inputFormat??"auto",e.outputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1,e.includeUnknownProperties??false,e.mappingReport??false)}function En(t,e={}){return j().canonicalize(t,e.inputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function In(t){let e=j().count_bits(t);if(e.startsWith("error:"))throw new Error(e);return Number.parseInt(e,10)}function Pn(t){return JSON.parse(j().split_bits(t))}function Bn(t,e={}){let r=j();if(e.preHook||e.postHook)return ze(r,t,e);let n=e.patch===void 0?"":typeof e.patch=="string"?e.patch:JSON.stringify(e.patch);return r.transform(t,e.inputFormat??"auto",e.outputFormat??"json",e.mode??"optimized",n,e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function Sn(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return j().breakscape_text(t,r,n)}function jn(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return j().unbreakscape_text(t,r,n)}function An(t={}){let e=t.infoType??"list",r=t.format??"text",n=t.bit??"",o=t.pretty??false,s=t.indent??2,i=t.includeDeprecated??false,a=t.onlyDeprecated??false,u=t.full??false;return j().info(e,r,n,o,s,i,a,u)}var Tt={full:{init:ke,initSync:we,ns:he,wasmFile:"bitmark_wasm_bg.wasm"},"bitmark-json":{init:Te,initSync:Oe,ns:ve,wasmFile:"bitmark_json_wasm_bg.wasm"}};Ke(()=>j());function Ln(t){if(t!==null&&typeof t=="object"&&!(t instanceof URL)&&("feature"in t||"module_or_path"in t)){let e=t;return {feature:e.feature??"full",module_or_path:e.module_or_path}}return {feature:"full",module_or_path:t??void 0}}var Ot=0,be,U;async function to(t){let{feature:e,module_or_path:r}=Ln(t);if(r===void 0){if(!U&&$()===e)return be;if(U?.feature===e)return U.promise}let n=++Ot,o=Tt[e],s=r??new URL(`${o.wasmFile}?v=${Z.version}`,import.meta.url),i=(async()=>{try{let a=await o.init(s);n===Ot&&(Fe(e,o.ns),be=a);}finally{U?.seq===n&&(U=void 0);}for(;U;)await U.promise.catch(()=>{});return be})();return U={feature:e,seq:n,promise:i},i}function no(t,e={}){let r=e.feature??"full",n=Tt[r],o=n.initSync(t);return Fe(r,n.ns),be=o,o}function ro(){return Z.version}function oo(t,e={}){let r=j(),n=$()??"full";return $e(r,t,e,(o,s)=>Ye(o,s,n))}export{ae as NotInitializedError,ee as UnsupportedFeatureError,vn as bitmarkToObjects,Sn as breakscapeText,En as canonicalize,Rn as convert,In as countBits,An as info,to as init,no as initSync,ht as legacy,Tn as lex,Fn as objectsToBitmark,On as patchEntry,Pn as splitBits,Bn as transform,oo as transformParallel,jn as unbreakscapeText,$ as variant,ro as version};//# sourceMappingURL=bitmark-parser.min.js.map
1
+ var Ye=Object.defineProperty;var zt=(e,t,r)=>t in e?Ye(e,t,{enumerable:true,configurable:true,writable:true,value:r}):e[t]=r;var _e=(e,t)=>{for(var r in t)Ye(e,r,{get:t[r],enumerable:true});};var C=(e,t,r)=>zt(e,typeof t!="symbol"?t+"":t,r);var Ae={};_e(Ae,{breakscape_text:()=>qt,canonicalize:()=>nn,convert:()=>tn,convert_text:()=>Qt,count_bits:()=>rn,default:()=>Se,info:()=>Xt,initSync:()=>Be,is_bitmark:()=>sn,lex:()=>Kt,prettify:()=>pn,register:()=>en,split_bits:()=>on,split_json_bits:()=>an,transform:()=>Zt,unbreakscape_text:()=>Yt});var p,k=0,ie=null;function de(){return (ie===null||ie.byteLength===0)&&(ie=new Uint8Array(p.memory.buffer)),ie}var le=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},$t=typeof le.encodeInto=="function"?function(e,t){return le.encodeInto(e,t)}:function(e,t){let r=le.encode(e);return t.set(r),{read:e.length,written:r.length}};function T(e,t,r){if(r===void 0){let a=le.encode(e),u=t(a.length,1)>>>0;return de().subarray(u,u+a.length).set(a),k=a.length,u}let n=e.length,o=t(n,1)>>>0,s=de(),i=0;for(;i<n;i++){let a=e.charCodeAt(i);if(a>127)break;s[o+i]=a;}if(i!==n){i!==0&&(e=e.slice(i)),o=r(o,n,n=i+e.length*3,1)>>>0;let a=de().subarray(o+i,o+n),u=$t(e,a);i+=u.written,o=r(o,n,i,1)>>>0;}return k=i,o}var q=null;function R(){return (q===null||q.buffer.detached===true||q.buffer.detached===void 0&&q.buffer!==p.memory.buffer)&&(q=new DataView(p.memory.buffer)),q}var Xe=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&Xe.decode();function U(e,t){return e=e>>>0,Xe.decode(de().subarray(e,e+t))}function Kt(e,t){let r,n;try{let i=p.__wbindgen_add_to_stack_pointer(-16),a=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),u=k,d=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),l=k;p.lex(i,a,u,d,l);var o=R().getInt32(i+0,!0),s=R().getInt32(i+4,!0);return r=o,n=s,U(o,s)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(r,n,1);}}function qt(e,t,r){let n,o;try{let a=p.__wbindgen_add_to_stack_pointer(-16),u=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),d=k,l=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),g=k,f=T(r,p.__wbindgen_export_0,p.__wbindgen_export_1),m=k;p.breakscape_text(a,u,d,l,g,f,m);var s=R().getInt32(a+0,!0),i=R().getInt32(a+4,!0);return n=s,o=i,U(s,i)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(n,o,1);}}function Yt(e,t,r){let n,o;try{let a=p.__wbindgen_add_to_stack_pointer(-16),u=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),d=k,l=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),g=k,f=T(r,p.__wbindgen_export_0,p.__wbindgen_export_1),m=k;p.unbreakscape_text(a,u,d,l,g,f,m);var s=R().getInt32(a+0,!0),i=R().getInt32(a+4,!0);return n=s,o=i,U(s,i)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(n,o,1);}}function Xt(e,t,r,n,o,s,i,a,u){let d,l;try{let m=p.__wbindgen_add_to_stack_pointer(-16),w=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),y=k,b=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),x=k,O=T(r,p.__wbindgen_export_0,p.__wbindgen_export_1),B=k,A=T(u,p.__wbindgen_export_0,p.__wbindgen_export_1),M=k;p.info(m,w,y,b,x,O,B,n,o,s,i,a,A,M);var g=R().getInt32(m+0,!0),f=R().getInt32(m+4,!0);return d=g,l=f,U(g,f)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(d,l,1);}}function Qt(e,t,r,n){let o,s;try{let u=p.__wbindgen_add_to_stack_pointer(-16),d=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),l=k,g=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),f=k,m=T(r,p.__wbindgen_export_0,p.__wbindgen_export_1),w=k,y=T(n,p.__wbindgen_export_0,p.__wbindgen_export_1),b=k;p.convert_text(u,d,l,g,f,m,w,y,b);var i=R().getInt32(u+0,!0),a=R().getInt32(u+4,!0);return o=i,s=a,U(i,a)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(o,s,1);}}function Zt(e,t,r,n,o,s,i,a){let u,d;try{let f=p.__wbindgen_add_to_stack_pointer(-16),m=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),w=k,y=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),b=k,x=T(r,p.__wbindgen_export_0,p.__wbindgen_export_1),O=k,B=T(n,p.__wbindgen_export_0,p.__wbindgen_export_1),A=k,M=T(o,p.__wbindgen_export_0,p.__wbindgen_export_1),oe=k;p.transform(f,m,w,y,b,x,O,B,A,M,oe,s,i,a);var l=R().getInt32(f+0,!0),g=R().getInt32(f+4,!0);return u=l,d=g,U(l,g)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(u,d,1);}}function en(e,t){let r,n;try{let i=p.__wbindgen_add_to_stack_pointer(-16),a=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),u=k,d=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),l=k;p.register(i,a,u,d,l);var o=R().getInt32(i+0,!0),s=R().getInt32(i+4,!0);return r=o,n=s,U(o,s)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(r,n,1);}}function tn(e,t,r,n,o,s,i,a,u){let d,l;try{let m=p.__wbindgen_add_to_stack_pointer(-16),w=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),y=k,b=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),x=k,O=T(r,p.__wbindgen_export_0,p.__wbindgen_export_1),B=k,A=T(n,p.__wbindgen_export_0,p.__wbindgen_export_1),M=k;p.convert(m,w,y,b,x,O,B,A,M,o,s,i,a,u);var g=R().getInt32(m+0,!0),f=R().getInt32(m+4,!0);return d=g,l=f,U(g,f)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(d,l,1);}}function nn(e,t,r,n,o,s){let i,a;try{let l=p.__wbindgen_add_to_stack_pointer(-16),g=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),f=k,m=T(t,p.__wbindgen_export_0,p.__wbindgen_export_1),w=k,y=T(r,p.__wbindgen_export_0,p.__wbindgen_export_1),b=k;p.canonicalize(l,g,f,m,w,y,b,n,o,s);var u=R().getInt32(l+0,!0),d=R().getInt32(l+4,!0);return i=u,a=d,U(u,d)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(i,a,1);}}function rn(e){let t,r;try{let s=p.__wbindgen_add_to_stack_pointer(-16),i=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),a=k;p.count_bits(s,i,a);var n=R().getInt32(s+0,!0),o=R().getInt32(s+4,!0);return t=n,r=o,U(n,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(t,r,1);}}function on(e){let t,r;try{let s=p.__wbindgen_add_to_stack_pointer(-16),i=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),a=k;p.split_bits(s,i,a);var n=R().getInt32(s+0,!0),o=R().getInt32(s+4,!0);return t=n,r=o,U(n,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(t,r,1);}}function sn(e){let t=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),r=k;return p.is_bitmark(t,r)!==0}function an(e){let t,r;try{let s=p.__wbindgen_add_to_stack_pointer(-16),i=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),a=k;p.split_json_bits(s,i,a);var n=R().getInt32(s+0,!0),o=R().getInt32(s+4,!0);return t=n,r=o,U(n,o)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(t,r,1);}}function pn(e,t){let r,n;try{let i=p.__wbindgen_add_to_stack_pointer(-16),a=T(e,p.__wbindgen_export_0,p.__wbindgen_export_1),u=k;p.prettify(i,a,u,t);var o=R().getInt32(i+0,!0),s=R().getInt32(i+4,!0);return r=o,n=s,U(o,s)}finally{p.__wbindgen_add_to_stack_pointer(16),p.__wbindgen_export_2(r,n,1);}}async function cn(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 Qe(){let e={};return e.wbg={},e}function Ze(e,t){return p=e.exports,et.__wbindgen_wasm_module=t,q=null,ie=null,p}function Be(e){if(p!==void 0)return p;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=Qe();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));let r=new WebAssembly.Instance(e,t);return Ze(r,e)}async function et(e){if(p!==void 0)return p;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=Qe();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:n}=await cn(await e,t);return Ze(r,n)}var Se=et;var Le={};_e(Le,{breakscape_text:()=>dn,canonicalize:()=>xn,convert:()=>yn,convert_text:()=>fn,count_bits:()=>wn,default:()=>je,info:()=>gn,initSync:()=>Pe,is_bitmark:()=>hn,lex:()=>_n,prettify:()=>Tn,register:()=>bn,split_bits:()=>kn,split_json_bits:()=>On,transform:()=>mn,unbreakscape_text:()=>ln});var c,h=0,se=null;function ge(){return (se===null||se.byteLength===0)&&(se=new Uint8Array(c.memory.buffer)),se}var fe=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},un=typeof fe.encodeInto=="function"?function(e,t){return fe.encodeInto(e,t)}:function(e,t){let r=fe.encode(e);return t.set(r),{read:e.length,written:r.length}};function v(e,t,r){if(r===void 0){let a=fe.encode(e),u=t(a.length,1)>>>0;return ge().subarray(u,u+a.length).set(a),h=a.length,u}let n=e.length,o=t(n,1)>>>0,s=ge(),i=0;for(;i<n;i++){let a=e.charCodeAt(i);if(a>127)break;s[o+i]=a;}if(i!==n){i!==0&&(e=e.slice(i)),o=r(o,n,n=i+e.length*3,1)>>>0;let a=ge().subarray(o+i,o+n),u=un(e,a);i+=u.written,o=r(o,n,i,1)>>>0;}return h=i,o}var Y=null;function E(){return (Y===null||Y.buffer.detached===true||Y.buffer.detached===void 0&&Y.buffer!==c.memory.buffer)&&(Y=new DataView(c.memory.buffer)),Y}var tt=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&tt.decode();function D(e,t){return e=e>>>0,tt.decode(ge().subarray(e,e+t))}function _n(e,t){let r,n;try{let i=c.__wbindgen_add_to_stack_pointer(-16),a=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),u=h,d=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),l=h;c.lex(i,a,u,d,l);var o=E().getInt32(i+0,!0),s=E().getInt32(i+4,!0);return r=o,n=s,D(o,s)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(r,n,1);}}function dn(e,t,r){let n,o;try{let a=c.__wbindgen_add_to_stack_pointer(-16),u=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),d=h,l=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),g=h,f=v(r,c.__wbindgen_export_0,c.__wbindgen_export_1),m=h;c.breakscape_text(a,u,d,l,g,f,m);var s=E().getInt32(a+0,!0),i=E().getInt32(a+4,!0);return n=s,o=i,D(s,i)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(n,o,1);}}function ln(e,t,r){let n,o;try{let a=c.__wbindgen_add_to_stack_pointer(-16),u=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),d=h,l=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),g=h,f=v(r,c.__wbindgen_export_0,c.__wbindgen_export_1),m=h;c.unbreakscape_text(a,u,d,l,g,f,m);var s=E().getInt32(a+0,!0),i=E().getInt32(a+4,!0);return n=s,o=i,D(s,i)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(n,o,1);}}function gn(e,t,r,n,o,s,i,a,u){let d,l;try{let m=c.__wbindgen_add_to_stack_pointer(-16),w=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),y=h,b=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),x=h,O=v(r,c.__wbindgen_export_0,c.__wbindgen_export_1),B=h,A=v(u,c.__wbindgen_export_0,c.__wbindgen_export_1),M=h;c.info(m,w,y,b,x,O,B,n,o,s,i,a,A,M);var g=E().getInt32(m+0,!0),f=E().getInt32(m+4,!0);return d=g,l=f,D(g,f)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(d,l,1);}}function fn(e,t,r,n){let o,s;try{let u=c.__wbindgen_add_to_stack_pointer(-16),d=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),l=h,g=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),f=h,m=v(r,c.__wbindgen_export_0,c.__wbindgen_export_1),w=h,y=v(n,c.__wbindgen_export_0,c.__wbindgen_export_1),b=h;c.convert_text(u,d,l,g,f,m,w,y,b);var i=E().getInt32(u+0,!0),a=E().getInt32(u+4,!0);return o=i,s=a,D(i,a)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(o,s,1);}}function mn(e,t,r,n,o,s,i,a){let u,d;try{let f=c.__wbindgen_add_to_stack_pointer(-16),m=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),w=h,y=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),b=h,x=v(r,c.__wbindgen_export_0,c.__wbindgen_export_1),O=h,B=v(n,c.__wbindgen_export_0,c.__wbindgen_export_1),A=h,M=v(o,c.__wbindgen_export_0,c.__wbindgen_export_1),oe=h;c.transform(f,m,w,y,b,x,O,B,A,M,oe,s,i,a);var l=E().getInt32(f+0,!0),g=E().getInt32(f+4,!0);return u=l,d=g,D(l,g)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(u,d,1);}}function bn(e,t){let r,n;try{let i=c.__wbindgen_add_to_stack_pointer(-16),a=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),u=h,d=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),l=h;c.register(i,a,u,d,l);var o=E().getInt32(i+0,!0),s=E().getInt32(i+4,!0);return r=o,n=s,D(o,s)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(r,n,1);}}function yn(e,t,r,n,o,s,i,a,u){let d,l;try{let m=c.__wbindgen_add_to_stack_pointer(-16),w=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),y=h,b=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),x=h,O=v(r,c.__wbindgen_export_0,c.__wbindgen_export_1),B=h,A=v(n,c.__wbindgen_export_0,c.__wbindgen_export_1),M=h;c.convert(m,w,y,b,x,O,B,A,M,o,s,i,a,u);var g=E().getInt32(m+0,!0),f=E().getInt32(m+4,!0);return d=g,l=f,D(g,f)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(d,l,1);}}function xn(e,t,r,n,o,s){let i,a;try{let l=c.__wbindgen_add_to_stack_pointer(-16),g=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),f=h,m=v(t,c.__wbindgen_export_0,c.__wbindgen_export_1),w=h,y=v(r,c.__wbindgen_export_0,c.__wbindgen_export_1),b=h;c.canonicalize(l,g,f,m,w,y,b,n,o,s);var u=E().getInt32(l+0,!0),d=E().getInt32(l+4,!0);return i=u,a=d,D(u,d)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(i,a,1);}}function wn(e){let t,r;try{let s=c.__wbindgen_add_to_stack_pointer(-16),i=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),a=h;c.count_bits(s,i,a);var n=E().getInt32(s+0,!0),o=E().getInt32(s+4,!0);return t=n,r=o,D(n,o)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(t,r,1);}}function kn(e){let t,r;try{let s=c.__wbindgen_add_to_stack_pointer(-16),i=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),a=h;c.split_bits(s,i,a);var n=E().getInt32(s+0,!0),o=E().getInt32(s+4,!0);return t=n,r=o,D(n,o)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(t,r,1);}}function hn(e){let t=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),r=h;return c.is_bitmark(t,r)!==0}function On(e){let t,r;try{let s=c.__wbindgen_add_to_stack_pointer(-16),i=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),a=h;c.split_json_bits(s,i,a);var n=E().getInt32(s+0,!0),o=E().getInt32(s+4,!0);return t=n,r=o,D(n,o)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(t,r,1);}}function Tn(e,t){let r,n;try{let i=c.__wbindgen_add_to_stack_pointer(-16),a=v(e,c.__wbindgen_export_0,c.__wbindgen_export_1),u=h;c.prettify(i,a,u,t);var o=E().getInt32(i+0,!0),s=E().getInt32(i+4,!0);return r=o,n=s,D(o,s)}finally{c.__wbindgen_add_to_stack_pointer(16),c.__wbindgen_export_2(r,n,1);}}async function vn(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 nt(){let e={};return e.wbg={},e}function rt(e,t){return c=e.exports,ot.__wbindgen_wasm_module=t,Y=null,se=null,c}function Pe(e){if(c!==void 0)return c;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=nt();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));let r=new WebAssembly.Instance(e,t);return rt(r,e)}async function ot(e){if(c!==void 0)return c;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_browser_full_wasm_bg.wasm",import.meta.url));let t=nt();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:n}=await vn(await e,t);return rt(r,n)}var je=ot;var Je={};_e(Je,{breakscape_text:()=>In,canonicalize:()=>Pn,convert:()=>An,convert_text:()=>Mn,count_bits:()=>jn,default:()=>Ce,info:()=>En,initSync:()=>We,is_bitmark:()=>Wn,prettify:()=>Jn,register:()=>Bn,split_bits:()=>Ln,split_json_bits:()=>Cn,transform:()=>Sn,unbreakscape_text:()=>Rn});var _,F=0,ae=null;function me(){return (ae===null||ae.byteLength===0)&&(ae=new Uint8Array(_.memory.buffer)),ae}var be=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},Fn=typeof be.encodeInto=="function"?function(e,t){return be.encodeInto(e,t)}:function(e,t){let r=be.encode(e);return t.set(r),{read:e.length,written:r.length}};function I(e,t,r){if(r===void 0){let a=be.encode(e),u=t(a.length,1)>>>0;return me().subarray(u,u+a.length).set(a),F=a.length,u}let n=e.length,o=t(n,1)>>>0,s=me(),i=0;for(;i<n;i++){let a=e.charCodeAt(i);if(a>127)break;s[o+i]=a;}if(i!==n){i!==0&&(e=e.slice(i)),o=r(o,n,n=i+e.length*3,1)>>>0;let a=me().subarray(o+i,o+n),u=Fn(e,a);i+=u.written,o=r(o,n,i,1)>>>0;}return F=i,o}var X=null;function S(){return (X===null||X.buffer.detached===true||X.buffer.detached===void 0&&X.buffer!==_.memory.buffer)&&(X=new DataView(_.memory.buffer)),X}var it=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&it.decode();function H(e,t){return e=e>>>0,it.decode(me().subarray(e,e+t))}function In(e,t,r){let n,o;try{let a=_.__wbindgen_add_to_stack_pointer(-16),u=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),d=F,l=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),g=F,f=I(r,_.__wbindgen_export_0,_.__wbindgen_export_1),m=F;_.breakscape_text(a,u,d,l,g,f,m);var s=S().getInt32(a+0,!0),i=S().getInt32(a+4,!0);return n=s,o=i,H(s,i)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(n,o,1);}}function Rn(e,t,r){let n,o;try{let a=_.__wbindgen_add_to_stack_pointer(-16),u=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),d=F,l=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),g=F,f=I(r,_.__wbindgen_export_0,_.__wbindgen_export_1),m=F;_.unbreakscape_text(a,u,d,l,g,f,m);var s=S().getInt32(a+0,!0),i=S().getInt32(a+4,!0);return n=s,o=i,H(s,i)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(n,o,1);}}function En(e,t,r,n,o,s,i,a,u){let d,l;try{let m=_.__wbindgen_add_to_stack_pointer(-16),w=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),y=F,b=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),x=F,O=I(r,_.__wbindgen_export_0,_.__wbindgen_export_1),B=F,A=I(u,_.__wbindgen_export_0,_.__wbindgen_export_1),M=F;_.info(m,w,y,b,x,O,B,n,o,s,i,a,A,M);var g=S().getInt32(m+0,!0),f=S().getInt32(m+4,!0);return d=g,l=f,H(g,f)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(d,l,1);}}function Bn(e,t){let r,n;try{let i=_.__wbindgen_add_to_stack_pointer(-16),a=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),u=F,d=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),l=F;_.register(i,a,u,d,l);var o=S().getInt32(i+0,!0),s=S().getInt32(i+4,!0);return r=o,n=s,H(o,s)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(r,n,1);}}function Sn(e,t,r,n,o,s,i,a){let u,d;try{let f=_.__wbindgen_add_to_stack_pointer(-16),m=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),w=F,y=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),b=F,x=I(r,_.__wbindgen_export_0,_.__wbindgen_export_1),O=F,B=I(n,_.__wbindgen_export_0,_.__wbindgen_export_1),A=F,M=I(o,_.__wbindgen_export_0,_.__wbindgen_export_1),oe=F;_.transform(f,m,w,y,b,x,O,B,A,M,oe,s,i,a);var l=S().getInt32(f+0,!0),g=S().getInt32(f+4,!0);return u=l,d=g,H(l,g)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(u,d,1);}}function An(e,t,r,n,o,s,i,a,u){let d,l;try{let m=_.__wbindgen_add_to_stack_pointer(-16),w=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),y=F,b=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),x=F,O=I(r,_.__wbindgen_export_0,_.__wbindgen_export_1),B=F,A=I(n,_.__wbindgen_export_0,_.__wbindgen_export_1),M=F;_.convert(m,w,y,b,x,O,B,A,M,o,s,i,a,u);var g=S().getInt32(m+0,!0),f=S().getInt32(m+4,!0);return d=g,l=f,H(g,f)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(d,l,1);}}function Pn(e,t,r,n,o,s){let i,a;try{let l=_.__wbindgen_add_to_stack_pointer(-16),g=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),f=F,m=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),w=F,y=I(r,_.__wbindgen_export_0,_.__wbindgen_export_1),b=F;_.canonicalize(l,g,f,m,w,y,b,n,o,s);var u=S().getInt32(l+0,!0),d=S().getInt32(l+4,!0);return i=u,a=d,H(u,d)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(i,a,1);}}function jn(e){let t,r;try{let s=_.__wbindgen_add_to_stack_pointer(-16),i=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),a=F;_.count_bits(s,i,a);var n=S().getInt32(s+0,!0),o=S().getInt32(s+4,!0);return t=n,r=o,H(n,o)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(t,r,1);}}function Ln(e){let t,r;try{let s=_.__wbindgen_add_to_stack_pointer(-16),i=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),a=F;_.split_bits(s,i,a);var n=S().getInt32(s+0,!0),o=S().getInt32(s+4,!0);return t=n,r=o,H(n,o)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(t,r,1);}}function Wn(e){let t=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),r=F;return _.is_bitmark(t,r)!==0}function Cn(e){let t,r;try{let s=_.__wbindgen_add_to_stack_pointer(-16),i=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),a=F;_.split_json_bits(s,i,a);var n=S().getInt32(s+0,!0),o=S().getInt32(s+4,!0);return t=n,r=o,H(n,o)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(t,r,1);}}function Jn(e,t){let r,n;try{let i=_.__wbindgen_add_to_stack_pointer(-16),a=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),u=F;_.prettify(i,a,u,t);var o=S().getInt32(i+0,!0),s=S().getInt32(i+4,!0);return r=o,n=s,H(o,s)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(r,n,1);}}function Mn(e,t,r,n){let o,s;try{let u=_.__wbindgen_add_to_stack_pointer(-16),d=I(e,_.__wbindgen_export_0,_.__wbindgen_export_1),l=F,g=I(t,_.__wbindgen_export_0,_.__wbindgen_export_1),f=F,m=I(r,_.__wbindgen_export_0,_.__wbindgen_export_1),w=F,y=I(n,_.__wbindgen_export_0,_.__wbindgen_export_1),b=F;_.convert_text(u,d,l,g,f,m,w,y,b);var i=S().getInt32(u+0,!0),a=S().getInt32(u+4,!0);return o=i,s=a,H(i,a)}finally{_.__wbindgen_add_to_stack_pointer(16),_.__wbindgen_export_2(o,s,1);}}async function Vn(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 st(){let e={};return e.wbg={},e}function at(e,t){return _=e.exports,pt.__wbindgen_wasm_module=t,X=null,ae=null,_}function We(e){if(_!==void 0)return _;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=st();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));let r=new WebAssembly.Instance(e,t);return at(r,e)}async function pt(e){if(_!==void 0)return _;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_json_wasm_bg.wasm",import.meta.url));let t=st();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:n}=await Vn(await e,t);return at(r,n)}var Ce=pt;var pe={version:"6.11.0"};var Me="browser-full",xe=class extends Error{constructor(){super("wasm not initialised: call init() (or init({ feature: \u2026 })) first"),this.name="NotInitializedError";}},Z=class extends Error{constructor(t){super(t),this.name="RegisterError";}},ce=class extends Error{constructor(t,r){super(`${t} is not available in the loaded wasm module${r?` (feature: "${r}")`:""}; init({ feature: "full" }) to load it`),this.name="UnsupportedFeatureError";}},ye,ut,ct,_t=new Map;function V(){if(!ye&&ct&&ct(),!ye)throw new xe;return ye}function Ve(e,t){for(let[r,n]of _t){let o=t.register(r,n);if(o)throw new Z(o.replace(/^error:\s*/,""))}ye=t,ut=e;}function dt(e,t){_t.set(e,t);}function ee(){return ut}function te(e){return e.startsWith("error:")}function we(e){let t=e instanceof Error?e.message:String(e);return t.startsWith("error:")?t:`error: ${t}`}function Nn(e){let t=e.trim();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):e}function Un(e){if(e===void 0)return [];if(typeof e=="string"){let t=e.trim();return t===""?[]:JSON.parse(t)}return e}function Dn(e,t,r){if(r){let s=e.split_bits(t);if(te(s))throw new Error(s);let i=JSON.parse(s);return i.map(a=>({view:{format:"bitmark",index:a.index,total:i.length,source:a.source},source:a.source}))}let n=e.split_json_bits(t);if(te(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 Ne(e,t,r){let n=r.mode??"optimized",o=r.outputFormat??"json",s=r.spacesAroundValues??1,i=r.indent??2,a=r.pretty??false,u=r.inputFormat??"auto",d=u==="bitmark"||u!=="json"&&e.is_bitmark(t),l=d?"bitmark":"json",g=Un(r.patch),f=Dn(e,t,d),m=f.length,w=[],y=[];for(let b=0;b<m;b++){let{view:x,source:O}=f[b];x.index=b,x.total=m;let B=r.preHook?r.preHook(x)||{}:{};if(B.drop)continue;let A=B.patches?[...g,...B.patches]:g;w.push({index:b,source:O,inputFormat:l,outputFormat:B.outputFormat??o,mode:n,patchJson:JSON.stringify(A),spacesAroundValues:s}),y.push(x);}return {jobs:w,views:y,output:o,pretty:a,indent:i}}function Gn(e,t){let r=e.transform(t.source,t.inputFormat,t.outputFormat,t.mode,t.patchJson,false,2,t.spacesAroundValues);return te(r)?r:t.outputFormat==="json"?Nn(r):r}function Ue(e,t,r,n,o){if(r==="bitmark"||r==="text")return t.join(`
2
+ `);let s=`[${t.join(",")}]`;return n?e.prettify(s,o):s}function lt(e,t,r){let n;try{n=Ne(e,t,r);}catch(s){return we(s)}let o=[];for(let s=0;s<n.jobs.length;s++){let i=Gn(e,n.jobs[s]);if(te(i))return i;r.postHook?.(n.views[s],i),o.push(i);}return Ue(e,o,n.output,n.pretty,n.indent)}async function gt(e,t,r,n){let o;try{o=Ne(e,t,r);}catch(i){return we(i)}let s;try{s=await n(o.jobs,r.workers??4);}catch(i){return we(i)}for(let i=0;i<s.length;i++){if(te(s[i]))return s[i];r.postHook?.(o.views[i],s[i]);}return Ue(e,s,o.output,o.pretty,o.indent)}var De;function ft(e){De=e;}function L(){if(!De)throw new Error("legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)");return De()}function mt(e,t,r){if(e.length===0)return Promise.resolve([]);let n=Math.max(1,Math.min(t,e.length)),o=new URL("./worker-entry.js",import.meta.url);return new Promise((s,i)=>{let a=new Array(e.length),u=0,d=0,l=false,g=[],f=()=>{for(let y of g)y.terminate();},m=y=>{l||(l=true,f(),i(y));},w=y=>{if(l||u>=e.length)return;let b=u++;y.postMessage({id:b,job:e[b],feature:r});};for(let y=0;y<n;y++){let b=new Worker(o,{type:"module"});g.push(b),b.onmessage=x=>{let O=x.data;if(!l){if(!O.ok){m(new Error(O.error??"worker job failed"));return}if(a[O.id]=O.element,d++,d===e.length){l=true,f(),s(a);return}w(b);}},b.onerror=x=>m(new Error(x.message||"worker error"));}for(let y of g)w(y);})}var Dt={};_e(Dt,{Ast:()=>Et,BitType:()=>vt,BitmarkFileGenerator:()=>At,BitmarkGenerator:()=>Bt,BitmarkParser:()=>Jt,BitmarkParserGenerator:()=>Ie,BitmarkParserType:()=>tr,BitmarkStringGenerator:()=>St,BitmarkVersion:()=>Zn,BodyTextFormat:()=>or,BoundingBoxIndex:()=>Rt,Builder:()=>Fe,CardSetVersion:()=>er,FileWriter:()=>Nt,HtmlTableGenerator:()=>Wt,HtmlTableParser:()=>Ct,InfoFormat:()=>rr,InfoType:()=>nr,Input:()=>Yn,InputFormat:()=>Qn,JsonFileGenerator:()=>Lt,JsonGenerator:()=>Pt,JsonParser:()=>Mt,JsonStringGenerator:()=>jt,LegacyUnsupportedError:()=>ne,NodeType:()=>It,Output:()=>Xn,ResourceBuilder:()=>Re,StreamWriter:()=>Ut,StringWriter:()=>Vt,TextLocation:()=>ir,TextMarkType:()=>Ot,TextNodeType:()=>Tt,bitmarkTextParse:()=>kt,isPseudoAst:()=>yt});var ne=class extends Error{constructor(t){super(t),this.name="LegacyUnsupportedError";}};function $(e,t){throw new ne(`'${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}function z(e,t){throw new ne(`Option '${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}var Ge="bitmark v2 output is not supported (this parser is bitmark v3 only)";function He(e){e.bitmarkVersion===2&&z("bitmarkVersion: 2",Ge);}function he(e){e.explicitTextFormat&&z("bitmarkOptions.explicitTextFormat"),e.cardSetVersion===1&&z("bitmarkOptions.cardSetVersion: 1",Ge),e.debugGenerationInline&&z("bitmarkOptions.debugGenerationInline"),e.noBreakscaping&&z("bitmarkOptions.noBreakscaping");}function Oe(e){e.textAsPlainText&&z("jsonOptions.textAsPlainText",Ge),e.debugGenerationInline&&z("jsonOptions.debugGenerationInline");}function Q(e){return e===true?{pretty:true,indent:2}:typeof e=="number"&&e>0?{pretty:true,indent:e}:{pretty:false,indent:2}}function Te(e){return e===void 0||e===true?1:e===false?0:Math.max(0,Math.min(10,e))}function ve(e){switch(e){case "text":case "latex":case "json":case "xml":return "plainText";default:return "bitmark++"}}var bt=Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");function re(e){let t={bits:e};return Object.defineProperty(t,bt,{value:true,enumerable:false}),t}function yt(e){return e!==null&&typeof e=="object"&&(bt in e||Array.isArray(e.bits))}var xt={"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 ze=Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser"),zn={bitType:"type",textFormat:"format",flashcards:"cards",markConfig:"marks"},$n={"bitmark--":"bitmark++","bitmark+":"bitmark++"},Kn={bitmark:"bitmark++",text:"text",json:"json",latex:"latex",xml:"xml"},qn=["title","subtitle","item","lead","pageNumber","marginNumber","hint","instruction","caption"],Fe=class{buildBitmark(t){let r=re(t.bits??[]);return t.errors!==void 0&&(r.errors=t.errors),r}buildBit(t,r){let n=L(),o={...t},s=o.bitType,i=this.getBitConfig(s),a={};a.type=s,o.isCommented&&(a.type="_comment",a.originalType=s),delete o.bitType,delete o.isCommented;let u=o.textFormat;u!==void 0?(a.format=$n[u]??u,delete o.textFormat):a.format=Kn[i.bodyFormat??""]??"bitmark++",delete o.resourceType;let d=o.body;d!=null&&typeof d=="object"&&"body"in d&&(a.body=d.body,delete o.body),o.example!==void 0?(a.isExample=true,a.example=o.example,delete o.example,delete o.__isDefaultExample):o.__isDefaultExample&&(a.isExample=true,delete o.__isDefaultExample);let l=o.resources;if(l!==void 0&&s!==void 0){let b=Array.isArray(l)?l:[l],x=xt[s];x?a[x.key]=b.filter(O=>O!==null&&typeof O=="object"&&O.type===x.resourceType):b.length>=1&&(a.resource=b[0]),delete o.resources;}let g=o.parser;delete o.parser;let f=o.extraProperties;delete o.extraProperties;for(let[b,x]of Object.entries(o))x!==void 0&&(a[zn[b]??b]=x);if(f)for(let[b,x]of Object.entries(f))b in a||(a[b]=x);this.parseStringTexts(a);let m=n.convert(JSON.stringify([{bit:a}]),"json","json","optimized",false,2,1,false,false);if(m.startsWith("error:"))throw new Error(m.slice(6).trim());let y=JSON.parse(m)[0]?.bit??a;for(let[b,x]of Object.entries(a))b in y||x===false||x===""||x===null||Array.isArray(x)&&x.length===0||(y[b]=x);return g!==void 0&&Object.defineProperty(y,ze,{value:g,enumerable:false}),y}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(a=>a!=null).map(a=>({text:a.text??"",isCorrect:a.isCorrect??false,isHighlighted:a.isHighlighted??false,...wt(a,["text","isCorrect","isHighlighted"])})):[],prefix:n.prefix??"",postfix:n.postfix??"",...wt(n,["type","texts","prefix","postfix","attrs"]),attrs:{}}}parseStringTexts(t){let r=L(),n=(i,a)=>{if(i==="")return i;let u=r.convert_text(i,"textToAst","bitmark++",a);try{return JSON.parse(u)}catch{return i}},o=t.format,s=o===void 0||o==="bitmark++"||o==="bitmark+";if(typeof t.body=="string")if(o==="json")try{t.body=JSON.parse(t.body);}catch{t.body=null;}else s&&(t.body=n(t.body,"body"));for(let i of qn){let a=t[i];typeof a=="string"&&(t[i]=n(a,"tag"));}}getBitConfig(t){let r=L();if(t!==void 0)try{let n=JSON.parse(r.info("bit","json",t,!1,2,!1,!1,!0,""));if(n.error===void 0)return {bodyFormat:n.body?.format}}catch{}throw new Error(`No config found for bit: ${t}`)}};function wt(e,t){let r={};for(let[n,o]of Object.entries(e))o!==void 0&&!t.includes(n)&&(r[n]=o);return r}var Ie=class{version(){return pe.version}convert(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);He(n),he(s),Oe(o),this.checkBrowserFileWrite(n.outputFile);let i=L(),{source:a,isBitmark:u}=this.resolveInput(t,n.inputFormat),d=n.outputFormat??(u?"json":"bitmark"),l=d==="ast"?"json":d,{pretty:g,indent:f}=Q(o.prettify),m=l==="bitmark"?Q(s.prettifyJson):{pretty:g,indent:f},w=Te(s.spacesAroundValues),y=!o.excludeUnknownProperties,b=i.convert(a,u?"bitmark":"json",l,"optimized",m.pretty,m.indent,w,y,false);if(this.throwOnError(b),d==="bitmark"||d==="text")return this.deliver(b,n.outputFile,n.fileOptions);if(d==="json")return n.outputFile?this.deliver(b,n.outputFile,n.fileOptions):g||o.stringify?b:JSON.parse(b);let x=re(JSON.parse(b));return n.outputFile?this.deliver(JSON.stringify(x),n.outputFile,n.fileOptions):x}upgrade(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);He(n),he(s),Oe(o),this.checkBrowserFileWrite(n.outputFile);let i=L(),{source:a,isBitmark:u}=this.resolveInput(t,n.inputFormat),{pretty:d,indent:l}=Q(u?s.prettifyJson:o.prettify),g=Te(s.spacesAroundValues),f=i.canonicalize(a,u?"bitmark":"json","optimized",d,l,g);return this.throwOnError(f),u?this.deliver(f,n.outputFile,n.fileOptions):n.outputFile?this.deliver(f,n.outputFile,n.fileOptions):d||o.stringify?f:JSON.parse(f)}info(t){let r=Object.assign({},t),n=L(),o=r.type??"list",s=r.outputFormat??"text",{pretty:i,indent:a}=Q(r.prettify),u=s==="pojo"?"json":s,d=n.info(o,u,r.bit??"",i,a,false,false,true,"");return this.throwOnError(d),s==="pojo"?JSON.parse(d):d}generateConfig(t){$("BitmarkParserGenerator.generateConfig","bpg-internal development tool");}convertHtmlTable(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),s=Object.assign({},n.bitmarkOptions);he(s),Oe(o),n.keepUnknownTags&&z("keepUnknownTags"),n.noBreakscaping&&z("noBreakscaping"),this.checkBrowserFileWrite(n.outputFile);let i=L(),a=typeof t=="string"?this.maybeReadFile(t,void 0):"";if(!(n.inputFormat==="html"||n.inputFormat===void 0&&typeof t=="string"&&/<table[\s>]/iu.test(a))){let{source:O,isBitmark:B}=this.resolveInput(t,void 0),A=i.convert(O,B?"bitmark":"json","html","optimized",false,2,1,false,false);return this.throwOnError(A),this.deliver($e(A).join(`
3
+ `),n.outputFile,n.fileOptions)}let d=n.tableFormat==="table"?"table":"table-extended",l=$e(a).map(O=>`<bitmark-bit data-type="${d}" data-format="bitmark++">${O}</bitmark-bit>`).join(""),g=n.outputFormat??"bitmark",{pretty:f,indent:m}=Q(o.prettify),w=Te(s.spacesAroundValues);if(g==="html"){let O=i.convert(l,"html","html","optimized",false,2,1,false,false);return this.throwOnError(O),this.deliver($e(O).join(`
4
+ `),n.outputFile,n.fileOptions)}let y=g==="ast"?"json":g,b=i.convert(l,"html",y,"optimized",f,m,w,false,false);if(this.throwOnError(b),g==="bitmark"||g==="text")return this.deliver(b,n.outputFile,n.fileOptions);if(g==="json")return n.outputFile?this.deliver(b,n.outputFile,n.fileOptions):f||o.stringify?b:JSON.parse(b);let x=re(JSON.parse(b));return n.outputFile?this.deliver(JSON.stringify(x),n.outputFile,n.fileOptions):x}createAst(t,r){let n=Object.assign({},r),o=L(),{source:s,isBitmark:i}=this.resolveInput(t,n.inputFormat),a=o.convert(s,i?"bitmark":"json","json","optimized",false,2,1,true,false);return this.throwOnError(a),re(JSON.parse(a))}breakscapeText(t,r){if(!t)return t;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=L(),s=this.maybeReadFile(t,n.inputFormat),i=o.breakscape_text(s,ve(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=L(),s=this.maybeReadFile(t,n.inputFormat),i=o.unbreakscape_text(s,ve(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 s=L(),i=n.textFormat===void 0||ve(n.textFormat)==="bitmark++",a=n.textLocation??"body",u,d;if(typeof t=="string"?(u=this.maybeReadFile(t,n.inputFormat),d=this.parseTextAstString(u)):(u=JSON.stringify(t),d=Array.isArray(t)?t:void 0),d!==void 0){let w=i?s.convert_text(JSON.stringify(d),"astToText","bitmark++",a):s.convert_text(JSON.stringify(d),"astToPlainText","plainText",a);return this.throwOnError(w),this.deliver(w,n.outputFile,n.fileOptions)}let l=s.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(l);let{pretty:g,indent:f}=Q(o.prettify),m=g?s.prettify(l,f):l;return n.outputFile?this.deliver(m,n.outputFile,n.fileOptions):g?m:JSON.parse(l)}textAstToPlainText(t,r){let o=L().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=L();if(n==="plainText")return typeof t=="string"?String(t):"";if(n==="bitmarkText"){let u=o.convert_text(String(t),"textToAst","bitmark++","body"),d=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(d),d}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:s,isBitmark:i}=this.resolveInput(t,void 0),a=o.convert(s,i?"bitmark":"json","text","optimized",false,2,1,false,false);return this.throwOnError(a),a}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 s=this.jsonEntries(t);return {source:JSON.stringify(s?s.map(i=>this.toWrapperEntry(i)):t),isBitmark:false}}let n=this.maybeReadFile(t,r);if(L().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(a=>this.toWrapperEntry(a))),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?.[ze];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 $e(e){let t=[],r=e.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let s=0,i=o,a=-1;for(;i<e.length;){let u=r.indexOf("<table",i),d=r.indexOf("</table",i);if(d===-1)break;if(u!==-1&&u<d)s++,i=u+6;else {s--;let l=r.indexOf(">",d);if(i=l===-1?e.length:l+1,s===0){a=i;break}}}if(a===-1)break;t.push(e.slice(o,a)),n=a;}return t}function kt(e){let t=L().convert_text(e,"textToAst","bitmark++","body");if(t.startsWith("error:"))throw new Error(t.slice(6).trim());return JSON.parse(t)}var J={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 W(e){return (t,r,n)=>{if(!r)return;let{value:o,...s}=r,i={[e.valueField]:o??""};for(let[a,u]of Object.entries(s))u!==void 0&&(i[a]=u);return {type:e.type,[e.key]:i}}}var ht=Object.fromEntries(Object.values(J).map(e=>[e.type,e])),Re=class{constructor(){C(this,"imageResource",W(J.imageResource));C(this,"imageLinkResource",W(J.imageLinkResource));C(this,"audioResource",W(J.audioResource));C(this,"audioEmbedResource",W(J.audioEmbedResource));C(this,"audioLinkResource",W(J.audioLinkResource));C(this,"videoResource",W(J.videoResource));C(this,"videoEmbedResource",W(J.videoEmbedResource));C(this,"videoLinkResource",W(J.videoLinkResource));C(this,"stillImageFilmEmbedResource",W(J.stillImageFilmEmbedResource));C(this,"stillImageFilmLinkResource",W(J.stillImageFilmLinkResource));C(this,"articleResource",W(J.articleResource));C(this,"documentResource",W(J.documentResource));C(this,"documentEmbedResource",W(J.documentEmbedResource));C(this,"documentLinkResource",W(J.documentLinkResource));C(this,"documentDownloadResource",W(J.documentDownloadResource));C(this,"appLinkResource",W(J.appLinkResource));C(this,"websiteLinkResource",W(J.websiteLinkResource));}resourceFromResourceJson(t,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,s=[];for(let i of o){let a=ht[i.type];if(!a)continue;let u=i[a.key]??{},{[a.valueField]:d,...l}=u,g=W(a)(void 0,{value:d,...l});g&&s.push(g);}if(s.length!==0)return n?s[0]:s}resourceFromResourceDataJson(t,r,n){if(!n)return;let o=ht[r];if(!o)return;let s=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:a,src:u,body:d,...l}=i,g=a??u??d??s;return W(o)(t,{value:g,...l})}};var Yn={string:"string",file:"file"},Xn={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},Qn={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},Zn={v2:2,v3:3},er={v1:1,v2:2},tr={peggy:"peggy"},nr={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},rr={text:"text",json:"json",pojo:"pojo"},or={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},ir={tag:"tag",body:"body"};var Ot={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"},Tt={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 sr(e){return e.replace(/-([a-z0-9])/gu,(t,r)=>r.toUpperCase())}var Ke;function ue(){if(!Ke){let e=L(),t=JSON.parse(e.info("all","json","",false,2,true,false,false,"")),r={_standard:"_standard"};for(let{name:n}of t)r[sr(n)]=n;Ke=r;}return Ke}var vt=new Proxy({},{get:(e,t)=>typeof t=="string"?ue()[t]:void 0,has:(e,t)=>typeof t=="string"&&t in ue(),ownKeys:()=>Reflect.ownKeys(ue()),getOwnPropertyDescriptor:(e,t)=>typeof t=="string"&&t in ue()?{value:ue()[t],enumerable:true,configurable:true,writable:false}:void 0});function Ft(e,t){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${e}]`:$(e,t),has:()=>$(e,t),ownKeys:()=>$(e,t)})}var It=Ft("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),Rt=Ft("BoundingBoxIndex","bpg-internal bounding-box utility");function N(e,t){return class{constructor(){$(e,t);}}}var ar="the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave",G="internal class of bpg's TS implementation",Et=N("Ast",ar),Bt=N("BitmarkGenerator",G),St=N("BitmarkStringGenerator",G),At=N("BitmarkFileGenerator",G),Pt=N("JsonGenerator",G),jt=N("JsonStringGenerator",G),Lt=N("JsonFileGenerator",G),Wt=N("HtmlTableGenerator",G),Ct=N("HtmlTableParser",G),Jt=N("BitmarkParser",G),Mt=N("JsonParser",G),Vt=N("StringWriter",G),Nt=N("FileWriter",G),Ut=N("StreamWriter",G);function pr(e,t,r){return r===void 0?{path:e,op:t}:{path:e,op:t,value:r}}var cr="all";function ur(e,t={}){let r=V();if(typeof r.lex!="function")throw new ce("lex",ee());return r.lex(e,t.stage??"lex")}function _r(e,t={}){let r=V().convert(e,"bitmark","json",t.mode??"optimized",false,2,1,t.includeUnknownProperties??false,false);if(r.startsWith("error:"))throw new Error(r.slice(6).trim());return JSON.parse(r)}function dr(e,t={}){let r=e.map(o=>o!==null&&typeof o=="object"&&"bit"in o&&typeof o.bit=="object"?o:{bit:o}),n=V().convert(JSON.stringify(r),"json","bitmark",t.mode??"optimized",false,2,1,false,false);if(n.startsWith("error:"))throw new Error(n.slice(6).trim());return n}function lr(e,t={}){return V().convert(e,t.inputFormat??"auto",t.outputFormat??"auto",t.mode??"optimized",t.pretty??false,t.indent??2,t.spacesAroundValues??1,t.includeUnknownProperties??false,t.mappingReport??false)}function gr(e,t={}){return V().canonicalize(e,t.inputFormat??"auto",t.mode??"optimized",t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function fr(e){let t=V().count_bits(e);if(t.startsWith("error:"))throw new Error(t);return Number.parseInt(t,10)}function mr(e){return JSON.parse(V().split_bits(e))}function br(e,t={}){let r=V();if(t.preHook||t.postHook)return lt(r,e,t);let n=t.patch===void 0?"":typeof t.patch=="string"?t.patch:JSON.stringify(t.patch);return r.transform(e,t.inputFormat??"auto",t.outputFormat??"json",t.mode??"optimized",n,t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function yr(e,t={}){let r=t.format??"bitmark++",n=t.location??"body";return V().breakscape_text(e,r,n)}function xr(e,t={}){let r=t.format??"bitmark++",n=t.location??"body";return V().unbreakscape_text(e,r,n)}function wr(e={}){let t=e.infoType??"list",r=e.format??"text",n=e.bit??"",o=e.pretty??false,s=e.indent??2,i=e.includeDeprecated??false,a=e.onlyDeprecated??false,u=e.full??false,d=typeof e.language=="string"?e.language:e.language?.join(",")??"";return V().info(t,r,n,o,s,i,a,u,d)}function kr(e){let t=V().register(e.type,e.data);if(t)throw new Z(t.replace(/^error:\s*/,""));dt(e.type,e.data);}var hr="./wasm/",Ht={full:{init:Se,initSync:Be,ns:Ae,wasmFile:"bitmark_wasm_bg.wasm"},"browser-full":{init:je,initSync:Pe,ns:Le,wasmFile:"bitmark_browser_full_wasm_bg.wasm"},"bitmark-json":{init:Ce,initSync:We,ns:Je,wasmFile:"bitmark_json_wasm_bg.wasm"}};ft(()=>V());function qe(e){return e===void 0?Me:"full"}function Or(e){if(e!==null&&typeof e=="object"&&!(e instanceof URL)&&("feature"in e||"module_or_path"in e)){let r=e;return {feature:r.feature??qe(r.module_or_path),module_or_path:r.module_or_path}}let t=e??void 0;return {feature:qe(t),module_or_path:t}}var Gt=0,Ee,K;async function zo(e){let{feature:t,module_or_path:r}=Or(e);if(r===void 0){if(!K&&ee()===t)return Ee;if(K?.feature===t)return K.promise}let n=++Gt,o=Ht[t],s=r??new URL(`${hr}${o.wasmFile}?v=${pe.version}`,import.meta.url),i=(async()=>{try{let a=await o.init(s);n===Gt&&(Ve(t,o.ns),Ee=a);}finally{K?.seq===n&&(K=void 0);}for(;K;)await K.promise.catch(()=>{});return Ee})();return K={feature:t,seq:n,promise:i},i}function $o(e,t={}){let r=t.feature??qe(e),n=Ht[r],o=n.initSync(e);return Ve(r,n.ns),Ee=o,o}function Ko(){return pe.version}function qo(e,t={}){let r=V(),n=ee()??Me;return gt(r,e,t,(o,s)=>mt(o,s,n))}export{cr as ALL_LANGUAGES,xe as NotInitializedError,Z as RegisterError,ce as UnsupportedFeatureError,_r as bitmarkToObjects,yr as breakscapeText,gr as canonicalize,lr as convert,fr as countBits,wr as info,zo as init,$o as initSync,Dt as legacy,ur as lex,dr as objectsToBitmark,pr as patchEntry,kr as register,mr as splitBits,br as transform,qo as transformParallel,xr as unbreakscapeText,ee as variant,Ko as version};//# sourceMappingURL=bitmark-parser.min.js.map
5
5
  //# sourceMappingURL=bitmark-parser.min.js.map