@gmb/bitmark-parser 6.1.3 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -98,10 +98,88 @@ Query information about supported bit types.
98
98
 
99
99
  Return the library version string.
100
100
 
101
+ ### Typed API (generated types)
102
+
103
+ TypeScript types for the parser's JSON are **generated from `bitmark.json`**
104
+ (`npm run schema:ts`, automatic in the build): per-bit types (`ArticleBit`,
105
+ `ClozeBit`, …) form the `Bit` discriminated union (narrow on `bit.type`),
106
+ `AnyBit` is the loose merged view, `BitEntry` is the `{bit, parser?, bitmark?}`
107
+ envelope, and resource/card content have named types (`ImageResource`,
108
+ `FlashcardBitCard`, …).
109
+
110
+ ```ts
111
+ import { parseBits, generateBits, patchEntry, type ArticleBit } from "@gmb/bitmark-parser";
112
+
113
+ // bitmark → typed entries
114
+ const entries = parseBits("[.article]\nHello **world**");
115
+ if (entries[0].bit.type === "article") console.log(entries[0].bit.body);
116
+
117
+ // author bits as typed literals (no builder needed) → bitmark
118
+ const article: ArticleBit = { type: "article", body: "Hello" };
119
+ const bitmark = generateBits([article]);
120
+
121
+ // typed round-trip editing
122
+ entries[0].bit.id = ["42"];
123
+ const edited = generateBits(entries);
124
+
125
+ // patch values typed from the literal path
126
+ const patch = patchEntry("id", "append", "1234");
127
+ ```
128
+
129
+ See `examples/` for runnable scripts covering the whole API (executed by
130
+ `npm test`, so they stay correct), and run `npm run docs` for generated API
131
+ documentation (TypeDoc → `docs/api/`).
132
+
101
133
  #### `generate(json: string): string`
102
134
 
103
135
  Generate bitmark text from JSON. **Not yet implemented** — throws an error.
104
136
 
137
+ ## Legacy API (bpg-compatible)
138
+
139
+ A compatibility facade for consumers migrating from
140
+ `@gmb/bitmark-parser-generator` (bpg v5.31.x). Only the import changes:
141
+
142
+ ```ts
143
+ // before: import { BitmarkParserGenerator } from "@gmb/bitmark-parser-generator";
144
+ import { BitmarkParserGenerator } from "@gmb/bitmark-parser/legacy";
145
+ // or: import { legacy } from "@gmb/bitmark-parser";
146
+
147
+ const bpg = new BitmarkParserGenerator();
148
+ const json = bpg.convert("[.article]\nHello **world**", { outputFormat: "json" });
149
+ ```
150
+
151
+ Supported (bpg-compatible signatures and return shapes): `convert`,
152
+ `upgrade`, `info`, `version`, `breakscapeText` / `unbreakscapeText`,
153
+ `convertText`, `textAstToPlainText`, `extractPlainText`, `convertHtmlTable`, `createAst`,
154
+ `bitmarkTextParse`, the `Builder` / `ResourceBuilder` classes, the
155
+ `Input` / `Output` / `InputFormat` / `BitType` (config-derived) /
156
+ `TextMarkType` / `TextNodeType` enums, and the option / JSON model types
157
+ (vendored from bpg, exposed only via `legacy`). Node file input/output
158
+ (`Input.file`, `outputFile`) works as in bpg; the browser build throws on
159
+ file writes, as bpg does.
160
+
161
+ Differences (all loud, never silent):
162
+
163
+ - **bitmark v3 only** — `bitmarkVersion: 2`, `cardSetVersion: 1` and
164
+ `jsonOptions.textAsPlainText: true` throw.
165
+ - **Strict option policy** — options with no equivalent here throw a
166
+ `LegacyUnsupportedError` naming the option (`explicitTextFormat`,
167
+ `prettifyJson`, `noBreakscaping`, `excludeUnknownProperties`,
168
+ `debugGenerationInline`). Exception: `bitmarkParserType` is accepted and
169
+ ignored — bpg itself ignores it. `jsonOptions.enableWarnings` is accepted
170
+ (parser warnings are always carried in the output envelope).
171
+ - **The AST is bit JSON** — `createAst` / `Output.ast` /
172
+ `Builder.buildBit` produce the bit JSON ("pseudo-AST"), not bpg's
173
+ internal TS node model. It round-trips through `convert`, but bpg's
174
+ `Ast` walker (and the generator/parser/writer internals) throw as
175
+ unsupported.
176
+ - **`convertHtmlTable`** converts HTML `<table>` markup ↔ table bits via
177
+ the core's html mapping (the `<bitmark-bit>` envelope is added/stripped
178
+ at the boundary). The markup produced *inside* `<table>` follows this
179
+ parser's html mapping and may differ from bpg's in detail.
180
+ `keepUnknownTags` / `noBreakscaping` throw.
181
+ - `version()` reports this package's version (6.x), not a bpg version.
182
+
105
183
  ## CLI
106
184
 
107
185
  The CLI binary is `bitmark`.
@@ -1,3 +1,5 @@
1
- var _t=Object.defineProperty;var at=(t,e)=>{for(var r in e)_t(t,r,{get:e[r],enumerable:true});};var E={};at(E,{breakscape_text:()=>H,canonicalize:()=>C,convert:()=>R,count_bits:()=>D,default:()=>$,fullize:()=>U,info:()=>N,initSync:()=>tt,is_bitmark:()=>ut,lex:()=>z,optimize:()=>L,parse:()=>j,prettify:()=>dt,split_bits:()=>G,split_json_bits:()=>pt,transform:()=>M,unbreakscape_text:()=>V});var n,p=0,W=null;function A(){return (W===null||W.byteLength===0)&&(W=new Uint8Array(n.memory.buffer)),W}var B=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},ct=typeof B.encodeInto=="function"?function(t,e){return B.encodeInto(t,e)}:function(t,e){let r=B.encode(t);return e.set(r),{read:t.length,written:r.length}};function d(t,e,r){if(r===void 0){let a=B.encode(t),c=e(a.length,1)>>>0;return A().subarray(c,c+a.length).set(a),p=a.length,c}let i=t.length,_=e(i,1)>>>0,s=A(),o=0;for(;o<i;o++){let a=t.charCodeAt(o);if(a>127)break;s[_+o]=a;}if(o!==i){o!==0&&(t=t.slice(o)),_=r(_,i,i=o+t.length*3,1)>>>0;let a=A().subarray(_+o,_+i),c=ct(t,a);o+=c.written,_=r(_,i,o,1)>>>0;}return p=o,_}var v=null;function l(){return (v===null||v.buffer.detached===true||v.buffer.detached===void 0&&v.buffer!==n.memory.buffer)&&(v=new DataView(n.memory.buffer)),v}var X=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&X.decode();function k(t,e){return t=t>>>0,X.decode(A().subarray(t,t+e))}function z(t,e){let r,i;try{let o=n.__wbindgen_add_to_stack_pointer(-16),a=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),c=p,u=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p;n.lex(o,a,c,u,f);var _=l().getInt32(o+0,!0),s=l().getInt32(o+4,!0);return r=_,i=s,k(_,s)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(r,i,1);}}function j(t,e){let r,i;try{let o=n.__wbindgen_add_to_stack_pointer(-16),a=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),c=p,u=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p;n.parse(o,a,c,u,f);var _=l().getInt32(o+0,!0),s=l().getInt32(o+4,!0);return r=_,i=s,k(_,s)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(r,i,1);}}function H(t,e,r){let i,_;try{let a=n.__wbindgen_add_to_stack_pointer(-16),c=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),u=p,f=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),g=p,b=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p;n.breakscape_text(a,c,u,f,g,b,x);var s=l().getInt32(a+0,!0),o=l().getInt32(a+4,!0);return i=s,_=o,k(s,o)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(i,_,1);}}function V(t,e,r){let i,_;try{let a=n.__wbindgen_add_to_stack_pointer(-16),c=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),u=p,f=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),g=p,b=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p;n.unbreakscape_text(a,c,u,f,g,b,x);var s=l().getInt32(a+0,!0),o=l().getInt32(a+4,!0);return i=s,_=o,k(s,o)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(i,_,1);}}function pt(t){let e,r;try{let s=n.__wbindgen_add_to_stack_pointer(-16),o=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),a=p;n.split_json_bits(s,o,a);var i=l().getInt32(s+0,!0),_=l().getInt32(s+4,!0);return e=i,r=_,k(i,_)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(e,r,1);}}function dt(t,e){let r,i;try{let o=n.__wbindgen_add_to_stack_pointer(-16),a=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),c=p;n.prettify(o,a,c,e);var _=l().getInt32(o+0,!0),s=l().getInt32(o+4,!0);return r=_,i=s,k(_,s)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(r,i,1);}}function M(t,e,r,i,_,s,o,a){let c,u;try{let b=n.__wbindgen_add_to_stack_pointer(-16),x=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),m=p,w=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),y=p,h=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),T=p,O=d(i,n.__wbindgen_export_0,n.__wbindgen_export_1),J=p,it=d(_,n.__wbindgen_export_0,n.__wbindgen_export_1),st=p;n.transform(b,x,m,w,y,h,T,O,J,it,st,s,o,a);var f=l().getInt32(b+0,!0),g=l().getInt32(b+4,!0);return c=f,u=g,k(f,g)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(c,u,1);}}function N(t,e,r,i,_){let s,o;try{let u=n.__wbindgen_add_to_stack_pointer(-16),f=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),g=p,b=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p,m=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),w=p;n.info(u,f,g,b,x,m,w,i,_);var a=l().getInt32(u+0,!0),c=l().getInt32(u+4,!0);return s=a,o=c,k(a,c)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(s,o,1);}}function R(t,e,r,i,_,s,o){let a,c;try{let g=n.__wbindgen_add_to_stack_pointer(-16),b=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p,m=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),w=p,y=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),h=p,T=d(i,n.__wbindgen_export_0,n.__wbindgen_export_1),O=p;n.convert(g,b,x,m,w,y,h,T,O,_,s,o);var u=l().getInt32(g+0,!0),f=l().getInt32(g+4,!0);return a=u,c=f,k(u,f)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(a,c,1);}}function L(t,e,r,i){let _,s;try{let c=n.__wbindgen_add_to_stack_pointer(-16),u=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p,g=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),b=p;n.optimize(c,u,f,g,b,r,i);var o=l().getInt32(c+0,!0),a=l().getInt32(c+4,!0);return _=o,s=a,k(o,a)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(_,s,1);}}function U(t,e,r,i){let _,s;try{let c=n.__wbindgen_add_to_stack_pointer(-16),u=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p,g=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),b=p;n.fullize(c,u,f,g,b,r,i);var o=l().getInt32(c+0,!0),a=l().getInt32(c+4,!0);return _=o,s=a,k(o,a)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(_,s,1);}}function C(t,e,r,i,_,s){let o,a;try{let f=n.__wbindgen_add_to_stack_pointer(-16),g=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),b=p,x=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),m=p,w=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),y=p;n.canonicalize(f,g,b,x,m,w,y,i,_,s);var c=l().getInt32(f+0,!0),u=l().getInt32(f+4,!0);return o=c,a=u,k(c,u)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(o,a,1);}}function D(t){let e,r;try{let s=n.__wbindgen_add_to_stack_pointer(-16),o=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),a=p;n.count_bits(s,o,a);var i=l().getInt32(s+0,!0),_=l().getInt32(s+4,!0);return e=i,r=_,k(i,_)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(e,r,1);}}function G(t){let e,r;try{let s=n.__wbindgen_add_to_stack_pointer(-16),o=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),a=p;n.split_bits(s,o,a);var i=l().getInt32(s+0,!0),_=l().getInt32(s+4,!0);return e=i,r=_,k(i,_)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(e,r,1);}}function ut(t){let e=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),r=p;return n.is_bitmark(e,r)!==0}async function ft(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(i){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",i);else throw i}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 Y(){let t={};return t.wbg={},t}function Z(t,e){return n=t.exports,et.__wbindgen_wasm_module=e,v=null,W=null,n}function tt(t){if(n!==void 0)return n;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=Y();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));let r=new WebAssembly.Instance(t,e);return Z(r,t)}async function et(t){if(n!==void 0)return n;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=Y();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:i}=await ft(await t,e);return Z(r,i)}var $=et;var q={version:"6.1.3"};function I(t){return t.startsWith("error:")}function S(t){let e=t instanceof Error?t.message:String(t);return e.startsWith("error:")?e:`error: ${e}`}function lt(t){let e=t.trim();return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):t}function gt(t){if(t===void 0)return [];if(typeof t=="string"){let e=t.trim();return e===""?[]:JSON.parse(e)}return t}function bt(t,e,r){if(r){let s=t.split_bits(e);if(I(s))throw new Error(s);let o=JSON.parse(s);return o.map(a=>({view:{format:"bitmark",index:a.index,total:o.length,source:a.source},source:a.source}))}let i=t.split_json_bits(e);if(I(i))throw new Error(i);let _=JSON.parse(i);return _.map((s,o)=>({view:{format:"json",index:o,total:_.length,bit:s.bit},source:JSON.stringify([s])}))}function K(t,e,r){let i=r.mode??"optimized",_=r.outputFormat??"json",s=r.spacesAroundValues??1,o=r.indent??2,a=r.pretty??false,c=r.inputFormat??"auto",u=c==="bitmark"||c!=="json"&&t.is_bitmark(e),f=u?"bitmark":"json",g=gt(r.patch),b=bt(t,e,u),x=b.length,m=[],w=[];for(let y=0;y<x;y++){let{view:h,source:T}=b[y];h.index=y,h.total=x;let O=r.preHook?r.preHook(h)||{}:{};if(O.drop)continue;let J=O.patches?[...g,...O.patches]:g;m.push({index:y,source:T,inputFormat:f,outputFormat:O.outputFormat??_,mode:i,patchJson:JSON.stringify(J),spacesAroundValues:s}),w.push(h);}return {jobs:m,views:w,output:_,pretty:a,indent:o}}function mt(t,e){let r=t.transform(e.source,e.inputFormat,e.outputFormat,e.mode,e.patchJson,false,2,e.spacesAroundValues);return I(r)?r:e.outputFormat==="json"?lt(r):r}function Q(t,e,r,i,_){if(r==="bitmark"||r==="text")return e.join(`
2
- `);let s=`[${e.join(",")}]`;return i?t.prettify(s,_):s}function nt(t,e,r){let i;try{i=K(t,e,r);}catch(s){return S(s)}let _=[];for(let s=0;s<i.jobs.length;s++){let o=mt(t,i.jobs[s]);if(I(o))return o;r.postHook?.(i.views[s],o),_.push(o);}return Q(t,_,i.output,i.pretty,i.indent)}async function rt(t,e,r,i){let _;try{_=K(t,e,r);}catch(o){return S(o)}let s;try{s=await i(_.jobs,r.workers??4);}catch(o){return S(o)}for(let o=0;o<s.length;o++){if(I(s[o]))return s[o];r.postHook?.(_.views[o],s[o]);}return Q(t,s,_.output,_.pretty,_.indent)}function ot(t,e){if(t.length===0)return Promise.resolve([]);let r=Math.max(1,Math.min(e,t.length)),i=new URL("./worker-entry.js",import.meta.url);return new Promise((_,s)=>{let o=new Array(t.length),a=0,c=0,u=false,f=[],g=()=>{for(let m of f)m.terminate();},b=m=>{u||(u=true,g(),s(m));},x=m=>{if(u||a>=t.length)return;let w=a++;m.postMessage({id:w,job:t[w]});};for(let m=0;m<r;m++){let w=new Worker(i,{type:"module"});f.push(w),w.onmessage=y=>{let h=y.data;if(!u){if(!h.ok){b(new Error(h.error??"worker job failed"));return}if(o[h.id]=h.element,c++,c===t.length){u=true,g(),_(o);return}x(w);}},w.onerror=y=>b(new Error(y.message||"worker error"));}for(let m of f)x(m);})}async function zt(t){return typeof t>"u"&&(t=new URL(`bitmark_wasm_bg.wasm?v=${q.version}`,import.meta.url)),$(t)}function jt(){return q.version}function Ht(t,e={}){return z(t,e.stage??"lex")}function Vt(t,e={}){return j(t,e.mode??"optimized")}function Mt(t,e={}){return R(t,e.inputFormat??"auto",e.outputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function Nt(t,e={}){return L(t,e.inputFormat??"auto",e.pretty??false,e.indent??2)}function wt(t,e={}){return U(t,e.inputFormat??"auto",e.pretty??false,e.indent??2)}var Rt=wt;function Lt(t,e={}){return C(t,e.inputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function Ut(t){let e=D(t);if(e.startsWith("error:"))throw new Error(e);return Number.parseInt(e,10)}function Ct(t){return JSON.parse(G(t))}function Dt(t,e={}){if(e.preHook||e.postHook)return nt(E,t,e);let r=e.patch===void 0?"":typeof e.patch=="string"?e.patch:JSON.stringify(e.patch);return M(t,e.inputFormat??"auto",e.outputFormat??"json",e.mode??"optimized",r,e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function Gt(t,e={}){return rt(E,t,e,ot)}function $t(t,e={}){let r=e.format??"bitmark++",i=e.location??"body";return H(t,r,i)}function qt(t,e={}){let r=e.format??"bitmark++",i=e.location??"body";return V(t,r,i)}function Kt(t={}){let e=t.infoType??"list",r=t.format??"text",i=t.bit??"",_=t.pretty??false,s=t.indent??2;return N(e,r,i,_,s)}export{$t as breakscapeText,Lt as canonicalize,Mt as convert,Ut as countBits,Rt as expand,wt as fullize,Kt as info,zt as init,tt as initSync,Ht as lex,Nt as optimize,Vt as parse,Ct as splitBits,Dt as transform,Gt as transformParallel,qt as unbreakscapeText,jt as version};//# sourceMappingURL=bitmark-parser.min.js.map
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 a=`[${t.join(",")}]`;return n?e.prettify(a,o):a}function Pt(e,t,r){let n;try{n=ft(e,t,r);}catch(a){return K(a)}let o=[];for(let a=0;a<n.jobs.length;a++){let i=ye(e,n.jobs[a]);if(W(i))return i;r.postHook?.(n.views[a],i),o.push(i);}return _t(e,o,n.output,n.pretty,n.indent)}async function St(e,t,r,n){let o;try{o=ft(e,t,r);}catch(i){return K(i)}let a;try{a=await n(o.jobs,r.workers??4);}catch(i){return K(i)}for(let i=0;i<a.length;i++){if(W(a[i]))return a[i];r.postHook?.(o.views[i],a[i]);}return _t(e,a,o.output,o.pretty,o.indent)}function It(e,t){if(e.length===0)return Promise.resolve([]);let r=Math.max(1,Math.min(t,e.length)),n=new URL("./worker-entry.js",import.meta.url);return new Promise((o,a)=>{let i=new Array(e.length),p=0,u=0,c=false,d=[],l=()=>{for(let g of d)g.terminate();},m=g=>{c||(c=true,l(),a(g));},k=g=>{if(c||p>=e.length)return;let y=p++;g.postMessage({id:y,job:e[y]});};for(let g=0;g<r;g++){let y=new Worker(n,{type:"module"});d.push(y),y.onmessage=b=>{let R=b.data;if(!c){if(!R.ok){m(new Error(R.error??"worker job failed"));return}if(i[R.id]=R.element,u++,u===e.length){c=true,l(),o(i);return}k(y);}},y.onerror=b=>m(new Error(b.message||"worker error"));}for(let g of d)k(g);})}var bt;function jt(e){bt=e;}function w(){if(!bt)throw new Error("legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)");return bt}var ie={};Tt(ie,{Ast:()=>Ut,BitType:()=>Ct,BitmarkFileGenerator:()=>Kt,BitmarkGenerator:()=>Dt,BitmarkParser:()=>te,BitmarkParserGenerator:()=>et,BitmarkParserType:()=>Be,BitmarkStringGenerator:()=>$t,BitmarkVersion:()=>ve,BodyTextFormat:()=>Se,BoundingBoxIndex:()=>zt,Builder:()=>tt,CardSetVersion:()=>Re,FileWriter:()=>re,HtmlTableGenerator:()=>Qt,HtmlTableParser:()=>Zt,InfoFormat:()=>Pe,InfoType:()=>Ee,Input:()=>Oe,InputFormat:()=>Fe,JsonFileGenerator:()=>Xt,JsonGenerator:()=>Yt,JsonParser:()=>ee,JsonStringGenerator:()=>qt,LegacyUnsupportedError:()=>N,NodeType:()=>Gt,Output:()=>Te,ResourceBuilder:()=>nt,StreamWriter:()=>oe,StringWriter:()=>ne,TextLocation:()=>Ie,TextMarkType:()=>Vt,TextNodeType:()=>Mt,bitmarkTextParse:()=>Wt,isPseudoAst:()=>Lt});var N=class extends Error{constructor(t){super(t),this.name="LegacyUnsupportedError";}};function A(e,t){throw new N(`'${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}function P(e,t){throw new N(`Option '${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}var yt="bitmark v2 output is not supported (this parser is bitmark v3 only)";function xt(e){e.bitmarkVersion===2&&P("bitmarkVersion: 2",yt);}function q(e){e.explicitTextFormat&&P("bitmarkOptions.explicitTextFormat"),e.prettifyJson!==void 0&&e.prettifyJson!==false&&P("bitmarkOptions.prettifyJson","embedded-JSON body prettification is not supported"),e.cardSetVersion===1&&P("bitmarkOptions.cardSetVersion: 1",yt),e.debugGenerationInline&&P("bitmarkOptions.debugGenerationInline"),e.noBreakscaping&&P("bitmarkOptions.noBreakscaping");}function X(e){e.textAsPlainText&&P("jsonOptions.textAsPlainText",yt),e.excludeUnknownProperties&&P("jsonOptions.excludeUnknownProperties"),e.debugGenerationInline&&P("jsonOptions.debugGenerationInline");}function V(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 At=Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");function M(e){let t={bits:e};return Object.defineProperty(t,At,{value:true,enumerable:false}),t}function Lt(e){return e!==null&&typeof e=="object"&&(At in e||Array.isArray(e.bits))}var kt=Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser"),ke={bitType:"type",textFormat:"format",flashcards:"cards",markConfig:"marks"},we={"bitmark--":"bitmark++","bitmark+":"bitmark++"},he=["title","subtitle","item","lead","pageNumber","marginNumber","hint","instruction","caption"],tt=class{buildBitmark(t){let r=M(t.bits??[]);return t.errors!==void 0&&(r.errors=t.errors),r}buildBit(t,r){let n=w(),o={...t},a=o.bitType;this.assertKnownBitType(a);let i={};i.type=a,o.isCommented&&(i.type="_comment",i.originalType=a),delete o.bitType,delete o.isCommented;let p=o.textFormat;p!==void 0&&(i.format=we[p]??p,delete o.textFormat),delete o.resourceType;let u=o.body;u!=null&&typeof u=="object"&&"body"in u&&(i.body=u.body,delete o.body),o.example!==void 0?(i.isExample=true,i.example=o.example,delete o.example,delete o.__isDefaultExample):o.__isDefaultExample&&(i.isExample=true,delete o.__isDefaultExample);let c=o.resources;c!==void 0&&(Array.isArray(c)?c.length===1?i.resource=c[0]:c.length>1&&(i.resources=c):i.resource=c,delete o.resources);let d=o.parser;delete o.parser;let l=o.extraProperties;delete o.extraProperties;for(let[y,b]of Object.entries(o))b!==void 0&&(i[ke[y]??y]=b);if(l)for(let[y,b]of Object.entries(l))y in i||(i[y]=b);this.parseStringTexts(i);let m=n.convert(JSON.stringify([{bit:i}]),"json","json","optimized",false,2,1);if(m.startsWith("error:"))throw new Error(m.slice(6).trim());let g=JSON.parse(m)[0]?.bit??i;for(let[y,b]of Object.entries(i))y in g||b===false||b===""||b===null||Array.isArray(b)&&b.length===0||(g[y]=b);return d!==void 0&&Object.defineProperty(g,kt,{value:d,enumerable:false}),g}buildHighlight(t,r){if(!r)return;let n={...r},o=n.attrs;return o&&Object.assign(n,o),{type:"highlight",texts:Array.isArray(n.texts)?n.texts.filter(p=>p!=null).map(p=>({text:p.text??"",isCorrect:p.isCorrect??false,isHighlighted:p.isHighlighted??false,...Jt(p,["text","isCorrect","isHighlighted"])})):[],prefix:n.prefix??"",postfix:n.postfix??"",...Jt(n,["type","texts","prefix","postfix","attrs"]),attrs:{}}}parseStringTexts(t){let r=w(),n=(i,p)=>{if(i==="")return i;let u=r.convert_text(i,"textToAst","bitmark++",p);try{return JSON.parse(u)}catch{return i}},o=t.format,a=o===void 0||o==="bitmark++"||o==="bitmark+";typeof t.body=="string"&&a&&(t.body=n(t.body,"body"));for(let i of he){let p=t[i];typeof p=="string"&&(t[i]=n(p,"tag"));}}assertKnownBitType(t){let r=w(),n=false;if(t!==void 0)try{n=JSON.parse(r.info("bit","json",t,!1,2)).error===void 0;}catch{n=false;}if(!n)throw new Error(`No config found for bit: ${t}`)}};function Jt(e,t){let r={};for(let[n,o]of Object.entries(e))o!==void 0&&!t.includes(n)&&(r[n]=o);return r}var et=class{version(){return z.version}convert(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);xt(n),q(a),X(o),this.checkBrowserFileWrite(n.outputFile);let i=w(),{source:p,isBitmark:u}=this.resolveInput(t,n.inputFormat),c=n.outputFormat??(u?"json":"bitmark"),d=c==="ast"?"json":c,{pretty:l,indent:m}=V(o.prettify),k=Q(a.spacesAroundValues),g=i.convert(p,u?"bitmark":"json",d,"optimized",l,m,k);if(this.throwOnError(g),c==="bitmark"||c==="text")return this.deliver(g,n.outputFile,n.fileOptions);if(c==="json")return n.outputFile?this.deliver(g,n.outputFile,n.fileOptions):l||o.stringify?g:JSON.parse(g);let y=M(JSON.parse(g));return n.outputFile?this.deliver(JSON.stringify(y),n.outputFile,n.fileOptions):y}upgrade(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);xt(n),q(a),X(o),this.checkBrowserFileWrite(n.outputFile);let i=w(),{source:p,isBitmark:u}=this.resolveInput(t,n.inputFormat),{pretty:c,indent:d}=V(o.prettify),l=Q(a.spacesAroundValues),m=i.canonicalize(p,u?"bitmark":"json","optimized",c,d,l);return this.throwOnError(m),u?this.deliver(m,n.outputFile,n.fileOptions):n.outputFile?this.deliver(m,n.outputFile,n.fileOptions):c||o.stringify?m:JSON.parse(m)}info(t){let r=Object.assign({},t),n=w(),o=r.type??"list",a=r.outputFormat??"text",{pretty:i,indent:p}=V(r.prettify),u=a==="pojo"?"json":a,c=n.info(o,u,r.bit??"",i,p);return this.throwOnError(c),a==="pojo"?JSON.parse(c):c}generateConfig(t){A("BitmarkParserGenerator.generateConfig","bpg-internal development tool");}convertHtmlTable(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);q(a),X(o),n.keepUnknownTags&&P("keepUnknownTags"),n.noBreakscaping&&P("noBreakscaping"),this.checkBrowserFileWrite(n.outputFile);let i=w(),p=typeof t=="string"?this.maybeReadFile(t,void 0):"";if(!(n.inputFormat==="html"||n.inputFormat===void 0&&typeof t=="string"&&/<table[\s>]/iu.test(p))){let{source:I,isBitmark:j}=this.resolveInput(t,void 0),J=i.convert(I,j?"bitmark":"json","html","optimized",false,2,1);return this.throwOnError(J),this.deliver(wt(J).join(`
3
+ `),n.outputFile,n.fileOptions)}let c=n.tableFormat==="table"?"table":"table-extended",d=wt(p).map(I=>`<bitmark-bit data-type="${c}" data-format="bitmark++">${I}</bitmark-bit>`).join(""),l=n.outputFormat??"bitmark",{pretty:m,indent:k}=V(o.prettify),g=Q(a.spacesAroundValues);if(l==="html"){let I=i.convert(d,"html","html","optimized",false,2,1);return this.throwOnError(I),this.deliver(wt(I).join(`
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
3
5
  //# sourceMappingURL=bitmark-parser.min.js.map