@gmb/bitmark-parser 6.9.0 → 6.10.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 +55 -3
- package/dist/browser/bitmark-parser.min.js +4 -4
- package/dist/browser/bitmark-parser.min.js.map +1 -1
- package/dist/browser/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/cjs/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/cjs/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/cjs/index.cjs +619 -114
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +2432 -3280
- package/dist/browser/esm/bitmark_json_wasm_bg.wasm +0 -0
- package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/esm/index.d.ts +2432 -3280
- package/dist/browser/esm/index.js +616 -114
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js +704 -7
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/index.cjs +154 -85
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -968
- package/dist/index.d.ts +81 -968
- package/dist/index.js +149 -85
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +9 -9
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.js +9 -9
- package/dist/legacy.js.map +1 -1
- package/dist/worker-entry.cjs +6 -1
- package/dist/worker-entry.cjs.map +1 -1
- package/package.json +8 -7
- package/schema/bitmark.schema.json +823 -4064
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/package.json +1 -1
- package/wasm-bitmark-json/bitmark_json_wasm.d.ts +99 -0
- package/wasm-bitmark-json/bitmark_json_wasm.js +491 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm +0 -0
- package/wasm-bitmark-json/bitmark_json_wasm_bg.wasm.d.ts +19 -0
- package/wasm-bitmark-json/package.json +20 -0
package/README.md
CHANGED
|
@@ -55,6 +55,53 @@ const bitInfo = info({ infoType: "list", format: "text" });
|
|
|
55
55
|
console.log(version());
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
### WASM feature modules (`full` / `bitmark-json`)
|
|
59
|
+
|
|
60
|
+
The package ships **two wasm builds of the same engine** and selects one at
|
|
61
|
+
runtime — the API surface never changes:
|
|
62
|
+
|
|
63
|
+
| Feature | Contents | Size (approx.) |
|
|
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) |
|
|
67
|
+
|
|
68
|
+
Not in `bitmark-json`: the markup formats (`html`, `xml`, `xml-niso-iec`, …)
|
|
69
|
+
as input or output (they return an `error: … not supported in this build`
|
|
70
|
+
string), the `mappingReport` option (same error), and `lex` (throws
|
|
71
|
+
`UnsupportedFeatureError`).
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
import { init, convert, variant } from "@gmb/bitmark-parser";
|
|
75
|
+
|
|
76
|
+
await init({ feature: "bitmark-json" }); // load the minimal wasm
|
|
77
|
+
convert("[.article]\nHello"); // works
|
|
78
|
+
variant(); // "bitmark-json"
|
|
79
|
+
|
|
80
|
+
// Upgrade in place: the interface stays valid while the full wasm loads —
|
|
81
|
+
// calls keep being served by the active module, then swap atomically.
|
|
82
|
+
await init({ feature: "full" });
|
|
83
|
+
convert("[.article]\nHi", { outputFormat: "html" }); // now works
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Notes:
|
|
87
|
+
|
|
88
|
+
- **Node**: with no explicit `init`, the first call lazily loads `full`
|
|
89
|
+
synchronously — existing zero-init usage is unchanged. `initSync({ feature })`
|
|
90
|
+
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.
|
|
97
|
+
- **Workers**: `transformParallel` workers load the active variant.
|
|
98
|
+
- **Legacy API**: works on `bitmark-json` (it follows the active module) except
|
|
99
|
+
its HTML-dependent members (e.g. `convertHtmlTable`), which throw.
|
|
100
|
+
- A previously active module's reference is dropped on swap; wasm-bindgen's
|
|
101
|
+
glue retains the instance until that variant is re-initialised, so switching
|
|
102
|
+
back is cheap but the memory of an abandoned variant is only reclaimed on
|
|
103
|
+
page/process end or its re-init.
|
|
104
|
+
|
|
58
105
|
### API
|
|
59
106
|
|
|
60
107
|
#### convert(input: string, options?: ConvertOptions): string
|
|
@@ -206,9 +253,10 @@ const patch = patchEntry("id", "append", "1234");
|
|
|
206
253
|
|
|
207
254
|
See `examples/` for runnable scripts covering the whole API (executed by
|
|
208
255
|
`npm test`, so they stay correct). Generated API documentation (TypeDoc) is
|
|
209
|
-
published at <https://getmorebrain.github.io/bitmark-parser-rust/>
|
|
210
|
-
|
|
211
|
-
it with `npm run docs
|
|
256
|
+
published at <https://getmorebrain.github.io/bitmark-parser-rust/docs/api/>
|
|
257
|
+
with each release (the site root hosts the bitmark language docs), or build
|
|
258
|
+
it locally with `npm run docs` (→ `docs/api/`) and preview it with
|
|
259
|
+
`npm run docs:serve` (http://localhost:8080, `--port` to change).
|
|
212
260
|
|
|
213
261
|
### JSON Schema
|
|
214
262
|
|
|
@@ -372,6 +420,10 @@ The package includes pre-built browser bundles with the WASM module.
|
|
|
372
420
|
</script>
|
|
373
421
|
```
|
|
374
422
|
|
|
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*).
|
|
426
|
+
|
|
375
427
|
### Bundler (webpack / vite)
|
|
376
428
|
|
|
377
429
|
```js
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var we=Object.defineProperty;var st=(t,e,r)=>e in t?we(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var he=(t,e)=>{for(var r in e)we(t,r,{get:e[r],enumerable:true});};var F=(t,e,r)=>st(t,typeof e!="symbol"?e+"":e,r);var U={};he(U,{breakscape_text:()=>ie,canonicalize:()=>ue,convert:()=>H,convert_text:()=>lt,count_bits:()=>ce,default:()=>de,info:()=>ae,initSync:()=>ve,is_bitmark:()=>pt,lex:()=>oe,prettify:()=>ct,split_bits:()=>le,split_json_bits:()=>ut,transform:()=>pe,unbreakscape_text:()=>se});var s,b=0,M=null;function z(){return (M===null||M.byteLength===0)&&(M=new Uint8Array(s.memory.buffer)),M}var $=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},at=typeof $.encodeInto=="function"?function(t,e){return $.encodeInto(t,e)}:function(t,e){let r=$.encode(t);return e.set(r),{read:t.length,written:r.length}};function _(t,e,r){if(r===void 0){let p=$.encode(t),u=e(p.length,1)>>>0;return z().subarray(u,u+p.length).set(p),b=p.length,u}let n=t.length,o=e(n,1)>>>0,a=z(),i=0;for(;i<n;i++){let p=t.charCodeAt(i);if(p>127)break;a[o+i]=p;}if(i!==n){i!==0&&(t=t.slice(i)),o=r(o,n,n=i+t.length*3,1)>>>0;let p=z().subarray(o+i,o+n),u=at(t,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!==s.memory.buffer)&&(J=new DataView(s.memory.buffer)),J}var Oe=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&Oe.decode();function S(t,e){return t=t>>>0,Oe.decode(z().subarray(t,t+e))}function oe(t,e){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),u=b,c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),l=b;s.lex(i,p,u,c,l);var o=w().getInt32(i+0,!0),a=w().getInt32(i+4,!0);return r=o,n=a,S(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function ie(t,e,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),c=b,l=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),m=b,f=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),y=b;s.breakscape_text(p,u,c,l,m,f,y);var a=w().getInt32(p+0,!0),i=w().getInt32(p+4,!0);return n=a,o=i,S(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function se(t,e,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),c=b,l=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),m=b,f=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),y=b;s.unbreakscape_text(p,u,c,l,m,f,y);var a=w().getInt32(p+0,!0),i=w().getInt32(p+4,!0);return n=a,o=i,S(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function ae(t,e,r,n,o,a,i,p){let u,c;try{let f=s.__wbindgen_add_to_stack_pointer(-16),y=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),T=b;s.info(f,y,x,k,d,g,T,n,o,a,i,p);var l=w().getInt32(f+0,!0),m=w().getInt32(f+4,!0);return u=l,c=m,S(l,m)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(u,c,1);}}function pe(t,e,r,n,o,a,i,p){let u,c;try{let f=s.__wbindgen_add_to_stack_pointer(-16),y=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),T=b,j=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),A=b,re=_(o,s.__wbindgen_export_0,s.__wbindgen_export_1),it=b;s.transform(f,y,x,k,d,g,T,j,A,re,it,a,i,p);var l=w().getInt32(f+0,!0),m=w().getInt32(f+4,!0);return u=l,c=m,S(l,m)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(u,c,1);}}function H(t,e,r,n,o,a,i,p,u){let c,l;try{let y=s.__wbindgen_add_to_stack_pointer(-16),x=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),k=b,d=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),g=b,T=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),j=b,A=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),re=b;s.convert(y,x,k,d,g,T,j,A,re,o,a,i,p,u);var m=w().getInt32(y+0,!0),f=w().getInt32(y+4,!0);return c=m,l=f,S(m,f)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(c,l,1);}}function ue(t,e,r,n,o,a){let i,p;try{let l=s.__wbindgen_add_to_stack_pointer(-16),m=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),f=b,y=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b;s.canonicalize(l,m,f,y,x,k,d,n,o,a);var u=w().getInt32(l+0,!0),c=w().getInt32(l+4,!0);return i=u,p=c,S(u,c)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(i,p,1);}}function ce(t){let e,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),p=b;s.count_bits(a,i,p);var n=w().getInt32(a+0,!0),o=w().getInt32(a+4,!0);return e=n,r=o,S(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(e,r,1);}}function le(t){let e,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),p=b;s.split_bits(a,i,p);var n=w().getInt32(a+0,!0),o=w().getInt32(a+4,!0);return e=n,r=o,S(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(e,r,1);}}function pt(t){let e=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),r=b;return s.is_bitmark(e,r)!==0}function ut(t){let e,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),p=b;s.split_json_bits(a,i,p);var n=w().getInt32(a+0,!0),o=w().getInt32(a+4,!0);return e=n,r=o,S(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(e,r,1);}}function ct(t,e){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),u=b;s.prettify(i,p,u,e);var o=w().getInt32(i+0,!0),a=w().getInt32(i+4,!0);return r=o,n=a,S(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function lt(t,e,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),l=b,m=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),f=b,y=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b;s.convert_text(u,c,l,m,f,y,x,k,d);var i=w().getInt32(u+0,!0),p=w().getInt32(u+4,!0);return o=i,a=p,S(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}async function dt(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(n){if(t.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n);else throw n}let r=await t.arrayBuffer();return await WebAssembly.instantiate(r,e)}else {let r=await WebAssembly.instantiate(t,e);return r instanceof WebAssembly.Instance?{instance:r,module:t}:r}}function Te(){let t={};return t.wbg={},t}function Fe(t,e){return s=t.exports,Re.__wbindgen_wasm_module=e,J=null,M=null,s}function ve(t){if(s!==void 0)return s;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=Te();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));let r=new WebAssembly.Instance(t,e);return Fe(r,t)}async function Re(t){if(s!==void 0)return s;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=Te();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await dt(await t,e);return Fe(r,n)}var de=Re;var G={version:"6.9.0"};function N(t){return t.startsWith("error:")}function K(t){let e=t instanceof Error?t.message:String(t);return e.startsWith("error:")?e:`error: ${e}`}function mt(t){let e=t.trim();return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):t}function ft(t){if(t===void 0)return [];if(typeof t=="string"){let e=t.trim();return e===""?[]:JSON.parse(e)}return t}function gt(t,e,r){if(r){let a=t.split_bits(e);if(N(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=t.split_json_bits(e);if(N(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 me(t,e,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"&&t.is_bitmark(e),l=c?"bitmark":"json",m=ft(r.patch),f=gt(t,e,c),y=f.length,x=[],k=[];for(let d=0;d<y;d++){let{view:g,source:T}=f[d];g.index=d,g.total=y;let j=r.preHook?r.preHook(g)||{}:{};if(j.drop)continue;let A=j.patches?[...m,...j.patches]:m;x.push({index:d,source:T,inputFormat:l,outputFormat:j.outputFormat??o,mode:n,patchJson:JSON.stringify(A),spacesAroundValues:a}),k.push(g);}return {jobs:x,views:k,output:o,pretty:p,indent:i}}function bt(t,e){let r=t.transform(e.source,e.inputFormat,e.outputFormat,e.mode,e.patchJson,false,2,e.spacesAroundValues);return N(r)?r:e.outputFormat==="json"?mt(r):r}function fe(t,e,r,n,o){if(r==="bitmark"||r==="text")return e.join(`
|
|
2
|
-
`);let
|
|
3
|
-
`),n.outputFile,n.fileOptions)}let
|
|
4
|
-
`),n.outputFile,n.fileOptions)}let k=m==="ast"?"json":m,d=i.convert(l,"html",k,"optimized",f,y,x,false,false);if(this.throwOnError(d),m==="bitmark"||m==="text")return this.deliver(d,n.outputFile,n.fileOptions);if(m==="json")return n.outputFile?this.deliver(d,n.outputFile,n.fileOptions):f||o.stringify?d:JSON.parse(d);let g=V(JSON.parse(d));return n.outputFile?this.deliver(JSON.stringify(g),n.outputFile,n.fileOptions):g}createAst(e,r){let n=Object.assign({},r),o=h(),{source:a,isBitmark:i}=this.resolveInput(e,n.inputFormat),p=o.convert(a,i?"bitmark":"json","json","optimized",false,2,1,true,false);return this.throwOnError(p),V(JSON.parse(p))}breakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),a=this.maybeReadFile(e,n.inputFormat),i=o.breakscape_text(a,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}unbreakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),a=this.maybeReadFile(e,n.inputFormat),i=o.unbreakscape_text(a,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}convertText(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions);this.checkBrowserFileWrite(n.outputFile);let a=h(),i=n.textFormat===void 0||Z(n.textFormat)==="bitmark++",p=n.textLocation??"body",u,c;if(typeof e=="string"?(u=this.maybeReadFile(e,n.inputFormat),c=this.parseTextAstString(u)):(u=JSON.stringify(e),c=Array.isArray(e)?e:void 0),c!==void 0){let x=i?a.convert_text(JSON.stringify(c),"astToText","bitmark++",p):a.convert_text(JSON.stringify(c),"astToPlainText","plainText",p);return this.throwOnError(x),this.deliver(x,n.outputFile,n.fileOptions)}let l=a.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(l);let{pretty:m,indent:f}=W(o.prettify),y=m?a.prettify(l,f):l;return n.outputFile?this.deliver(y,n.outputFile,n.fileOptions):m?y:JSON.parse(l)}textAstToPlainText(e,r){let o=h().convert_text(typeof e=="string"?e:JSON.stringify(e),"astToPlainText","bitmark++","body");return this.throwOnError(o),o}extractPlainText(e,r){let n=r?.inputFormat,o=h();if(n==="plainText")return typeof e=="string"?String(e):"";if(n==="bitmarkText"){let u=o.convert_text(String(e),"textToAst","bitmark++","body"),c=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(c),c}if(typeof e=="string"&&this.parseTextAstString(e)===void 0&&!o.is_bitmark(e)&&!(()=>{try{return JSON.parse(e),!0}catch{return false}})())return this.extractPlainText(e,{inputFormat:"bitmarkText"});let{source:a,isBitmark:i}=this.resolveInput(e,void 0),p=o.convert(a,i?"bitmark":"json","text","optimized",false,2,1,false,false);return this.throwOnError(p),p}parseTextAstString(e){let r=e.trim();if(r.startsWith("["))try{let n=JSON.parse(r);if(Array.isArray(n)&&n.every(o=>o!==null&&typeof o=="object"&&"type"in o))return n}catch{}}resolveInput(e,r){if(typeof e!="string"){let a=this.jsonEntries(e);return {source:JSON.stringify(a?a.map(i=>this.toWrapperEntry(i)):e),isBitmark:false}}let n=this.maybeReadFile(e,r);if(h().is_bitmark(n))return {source:n,isBitmark:true};try{let 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(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?.[_e];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 xe(t){let e=[],r=t.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let a=0,i=o,p=-1;for(;i<t.length;){let u=r.indexOf("<table",i),c=r.indexOf("</table",i);if(c===-1)break;if(u!==-1&&u<c)a++,i=u+6;else {a--;let l=r.indexOf(">",c);if(i=l===-1?t.length:l+1,a===0){p=i;break}}}if(p===-1)break;e.push(t.slice(o,p)),n=p;}return e}function Je(t){let e=h().convert_text(t,"textToAst","bitmark++","body");if(e.startsWith("error:"))throw new Error(e.slice(6).trim());return JSON.parse(e)}var E={imageResource:{type:"image",key:"image",valueField:"src"},imageLinkResource:{type:"image-link",key:"imageLink",valueField:"url"},audioResource:{type:"audio",key:"audio",valueField:"src"},audioEmbedResource:{type:"audio-embed",key:"audioEmbed",valueField:"src"},audioLinkResource:{type:"audio-link",key:"audioLink",valueField:"url"},videoResource:{type:"video",key:"video",valueField:"src"},videoEmbedResource:{type:"video-embed",key:"videoEmbed",valueField:"url"},videoLinkResource:{type:"video-link",key:"videoLink",valueField:"url"},stillImageFilmEmbedResource:{type:"still-image-film-embed",key:"stillImageFilmEmbed",valueField:"url"},stillImageFilmLinkResource:{type:"still-image-film-link",key:"stillImageFilmLink",valueField:"url"},articleResource:{type:"article",key:"article",valueField:"body"},documentResource:{type:"document",key:"document",valueField:"url"},documentEmbedResource:{type:"document-embed",key:"documentEmbed",valueField:"url"},documentLinkResource:{type:"document-link",key:"documentLink",valueField:"url"},documentDownloadResource:{type:"document-download",key:"documentDownload",valueField:"url"},appLinkResource:{type:"app-link",key:"appLink",valueField:"url"},websiteLinkResource:{type:"website-link",key:"websiteLink",valueField:"url"}};function O(t){return (e,r,n)=>{if(!r)return;let{value:o,...a}=r,i={[t.valueField]:o??""};for(let[p,u]of Object.entries(a))u!==void 0&&(i[p]=u);return {type:t.type,[t.key]:i}}}var We=Object.fromEntries(Object.values(E).map(t=>[t.type,t])),ne=class{constructor(){F(this,"imageResource",O(E.imageResource));F(this,"imageLinkResource",O(E.imageLinkResource));F(this,"audioResource",O(E.audioResource));F(this,"audioEmbedResource",O(E.audioEmbedResource));F(this,"audioLinkResource",O(E.audioLinkResource));F(this,"videoResource",O(E.videoResource));F(this,"videoEmbedResource",O(E.videoEmbedResource));F(this,"videoLinkResource",O(E.videoLinkResource));F(this,"stillImageFilmEmbedResource",O(E.stillImageFilmEmbedResource));F(this,"stillImageFilmLinkResource",O(E.stillImageFilmLinkResource));F(this,"articleResource",O(E.articleResource));F(this,"documentResource",O(E.documentResource));F(this,"documentEmbedResource",O(E.documentEmbedResource));F(this,"documentLinkResource",O(E.documentLinkResource));F(this,"documentDownloadResource",O(E.documentDownloadResource));F(this,"appLinkResource",O(E.appLinkResource));F(this,"websiteLinkResource",O(E.websiteLinkResource));}resourceFromResourceJson(e,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,a=[];for(let i of o){let p=We[i.type];if(!p)continue;let u=i[p.key]??{},{[p.valueField]:c,...l}=u,m=O(p)(void 0,{value:c,...l});m&&a.push(m);}if(a.length!==0)return n?a[0]:a}resourceFromResourceDataJson(e,r,n){if(!n)return;let o=We[r];if(!o)return;let a=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:p,src:u,body:c,...l}=i,m=p??u??c??a;return O(o)(e,{value:m,...l})}};var ht={string:"string",file:"file"},Ot={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},Tt={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},Ft={v2:2,v3:3},vt={v1:1,v2:2},Rt={peggy:"peggy"},Et={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},Pt={text:"text",json:"json",pojo:"pojo"},Bt={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},St={tag:"tag",body:"body"};var Ne={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"},Ce={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 It(t){return t.replace(/-([a-z0-9])/gu,(e,r)=>r.toUpperCase())}var ke;function D(){if(!ke){let t=h(),e=JSON.parse(t.info("all","json","",false,2,true,false,false)),r={_standard:"_standard"};for(let{name:n}of e)r[It(n)]=n;ke=r;}return ke}var Ve=new Proxy({},{get:(t,e)=>typeof e=="string"?D()[e]:void 0,has:(t,e)=>typeof e=="string"&&e in D(),ownKeys:()=>Reflect.ownKeys(D()),getOwnPropertyDescriptor:(t,e)=>typeof e=="string"&&e in D()?{value:D()[e],enumerable:true,configurable:true,writable:false}:void 0});function Me(t,e){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${t}]`:L(t,e),has:()=>L(t,e),ownKeys:()=>L(t,e)})}var He=Me("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),Ue=Me("BoundingBoxIndex","bpg-internal bounding-box utility");function P(t,e){return class{constructor(){L(t,e);}}}var jt="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",Ge=P("Ast",jt),De=P("BitmarkGenerator",B),ze=P("BitmarkStringGenerator",B),$e=P("BitmarkFileGenerator",B),Ke=P("JsonGenerator",B),Ye=P("JsonStringGenerator",B),Xe=P("JsonFileGenerator",B),qe=P("HtmlTableGenerator",B),Qe=P("HtmlTableParser",B),Ze=P("BitmarkParser",B),et=P("JsonParser",B),tt=P("StringWriter",B),nt=P("FileWriter",B),rt=P("StreamWriter",B);function At(t,e,r){return r===void 0?{path:t,op:e}:{path:t,op:e,value:r}}Se(U);async function $n(t){return typeof t>"u"&&(t=new URL(`bitmark_wasm_bg.wasm?v=${G.version}`,import.meta.url)),de(t)}function Kn(){return G.version}function Yn(t,e={}){return oe(t,e.stage??"lex")}function Xn(t,e={}){let r=H(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 qn(t,e={}){let r=t.map(o=>o!==null&&typeof o=="object"&&"bit"in o&&typeof o.bit=="object"?o:{bit:o}),n=H(JSON.stringify(r),"json","bitmark",e.mode??"optimized",false,2,1,false,false);if(n.startsWith("error:"))throw new Error(n.slice(6).trim());return n}function Qn(t,e={}){return H(t,e.inputFormat??"auto",e.outputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1,e.includeUnknownProperties??false,e.mappingReport??false)}function Zn(t,e={}){return ue(t,e.inputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function er(t){let e=ce(t);if(e.startsWith("error:"))throw new Error(e);return Number.parseInt(e,10)}function tr(t){return JSON.parse(le(t))}function nr(t,e={}){if(e.preHook||e.postHook)return Ee(U,t,e);let r=e.patch===void 0?"":typeof e.patch=="string"?e.patch:JSON.stringify(e.patch);return pe(t,e.inputFormat??"auto",e.outputFormat??"json",e.mode??"optimized",r,e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function rr(t,e={}){return Pe(U,t,e,Be)}function or(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return ie(t,r,n)}function ir(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return se(t,r,n)}function sr(t={}){let e=t.infoType??"list",r=t.format??"text",n=t.bit??"",o=t.pretty??false,a=t.indent??2,i=t.includeDeprecated??false,p=t.onlyDeprecated??false,u=t.full??false;return ae(e,r,n,o,a,i,p,u)}export{Xn as bitmarkToObjects,or as breakscapeText,Zn as canonicalize,Qn as convert,er as countBits,sr as info,$n as init,ve as initSync,ot as legacy,Yn as lex,qn as objectsToBitmark,At as patchEntry,tr as splitBits,nr as transform,rr as transformParallel,ir as unbreakscapeText,Kn as version};//# sourceMappingURL=bitmark-parser.min.js.map
|
|
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
|
|
5
5
|
//# sourceMappingURL=bitmark-parser.min.js.map
|