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