@gmb/bitmark-parser 6.1.4 → 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,6 +98,38 @@ 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.
@@ -1,5 +1,5 @@
1
- var Ot=Object.defineProperty;var pe=(e,t,r)=>t in e?Ot(e,t,{enumerable:true,configurable:true,writable:true,value:r}):e[t]=r;var Tt=(e,t)=>{for(var r in t)Ot(e,r,{get:t[r],enumerable:true});};var O=(e,t,r)=>pe(e,typeof t!="symbol"?t+"":t,r);var H={};Tt(H,{breakscape_text:()=>ot,canonicalize:()=>dt,convert:()=>pt,convert_text:()=>le,count_bits:()=>lt,default:()=>mt,fullize:()=>ct,info:()=>at,initSync:()=>Et,is_bitmark:()=>ge,lex:()=>nt,optimize:()=>ut,parse:()=>rt,prettify:()=>de,split_bits:()=>gt,split_json_bits:()=>ce,transform:()=>st,unbreakscape_text:()=>it});var s,f=0,V=null;function z(){return (V===null||V.byteLength===0)&&(V=new Uint8Array(s.memory.buffer)),V}var D=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},ue=typeof D.encodeInto=="function"?function(e,t){return D.encodeInto(e,t)}:function(e,t){let r=D.encode(e);return t.set(r),{read:e.length,written:r.length}};function _(e,t,r){if(r===void 0){let p=D.encode(e),u=t(p.length,1)>>>0;return z().subarray(u,u+p.length).set(p),f=p.length,u}let n=e.length,o=t(n,1)>>>0,a=z(),i=0;for(;i<n;i++){let p=e.charCodeAt(i);if(p>127)break;a[o+i]=p;}if(i!==n){i!==0&&(e=e.slice(i)),o=r(o,n,n=i+e.length*3,1)>>>0;let p=z().subarray(o+i,o+n),u=ue(e,p);i+=u.written,o=r(o,n,i,1)>>>0;}return f=i,o}var L=null;function x(){return (L===null||L.buffer.detached===true||L.buffer.detached===void 0&&L.buffer!==s.memory.buffer)&&(L=new DataView(s.memory.buffer)),L}var vt=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&vt.decode();function E(e,t){return e=e>>>0,vt.decode(z().subarray(e,e+t))}function nt(e,t){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),u=f,c=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f;s.lex(i,p,u,c,d);var o=x().getInt32(i+0,!0),a=x().getInt32(i+4,!0);return r=o,n=a,E(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function rt(e,t){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),u=f,c=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f;s.parse(i,p,u,c,d);var o=x().getInt32(i+0,!0),a=x().getInt32(i+4,!0);return r=o,n=a,E(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function ot(e,t,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),c=f,d=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),l=f,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f;s.breakscape_text(p,u,c,d,l,g,k);var a=x().getInt32(p+0,!0),i=x().getInt32(p+4,!0);return n=a,o=i,E(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function it(e,t,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),c=f,d=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),l=f,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f;s.unbreakscape_text(p,u,c,d,l,g,k);var a=x().getInt32(p+0,!0),i=x().getInt32(p+4,!0);return n=a,o=i,E(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function ce(e){let t,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),p=f;s.split_json_bits(a,i,p);var n=x().getInt32(a+0,!0),o=x().getInt32(a+4,!0);return t=n,r=o,E(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(t,r,1);}}function de(e,t){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),u=f;s.prettify(i,p,u,t);var o=x().getInt32(i+0,!0),a=x().getInt32(i+4,!0);return r=o,n=a,E(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function le(e,t,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f,l=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f,k=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),m=f,y=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),b=f;s.convert_text(u,c,d,l,g,k,m,y,b);var i=x().getInt32(u+0,!0),p=x().getInt32(u+4,!0);return o=i,a=p,E(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}function st(e,t,r,n,o,a,i,p){let u,c;try{let g=s.__wbindgen_add_to_stack_pointer(-16),k=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),m=f,y=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),b=f,v=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),S=f,j=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),J=f,se=_(o,s.__wbindgen_export_0,s.__wbindgen_export_1),ae=f;s.transform(g,k,m,y,b,v,S,j,J,se,ae,a,i,p);var d=x().getInt32(g+0,!0),l=x().getInt32(g+4,!0);return u=d,c=l,E(d,l)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(u,c,1);}}function at(e,t,r,n,o){let a,i;try{let c=s.__wbindgen_add_to_stack_pointer(-16),d=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),l=f,g=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f,m=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),y=f;s.info(c,d,l,g,k,m,y,n,o);var p=x().getInt32(c+0,!0),u=x().getInt32(c+4,!0);return a=p,i=u,E(p,u)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(a,i,1);}}function pt(e,t,r,n,o,a,i){let p,u;try{let l=s.__wbindgen_add_to_stack_pointer(-16),g=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),k=f,m=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),y=f,b=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),v=f,S=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),j=f;s.convert(l,g,k,m,y,b,v,S,j,o,a,i);var c=x().getInt32(l+0,!0),d=x().getInt32(l+4,!0);return p=c,u=d,E(c,d)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(p,u,1);}}function ut(e,t,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f,l=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f;s.optimize(u,c,d,l,g,r,n);var i=x().getInt32(u+0,!0),p=x().getInt32(u+4,!0);return o=i,a=p,E(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}function ct(e,t,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=f,l=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f;s.fullize(u,c,d,l,g,r,n);var i=x().getInt32(u+0,!0),p=x().getInt32(u+4,!0);return o=i,a=p,E(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}function dt(e,t,r,n,o,a){let i,p;try{let d=s.__wbindgen_add_to_stack_pointer(-16),l=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),g=f,k=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),m=f,y=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),b=f;s.canonicalize(d,l,g,k,m,y,b,n,o,a);var u=x().getInt32(d+0,!0),c=x().getInt32(d+4,!0);return i=u,p=c,E(u,c)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(i,p,1);}}function lt(e){let t,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),p=f;s.count_bits(a,i,p);var n=x().getInt32(a+0,!0),o=x().getInt32(a+4,!0);return t=n,r=o,E(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(t,r,1);}}function gt(e){let t,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),p=f;s.split_bits(a,i,p);var n=x().getInt32(a+0,!0),o=x().getInt32(a+4,!0);return t=n,r=o,E(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(t,r,1);}}function ge(e){let t=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),r=f;return s.is_bitmark(t,r)!==0}async function me(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(n){if(e.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n);else throw n}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else {let r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}}function Ft(){let e={};return e.wbg={},e}function Rt(e,t){return s=e.exports,Bt.__wbindgen_wasm_module=t,L=null,V=null,s}function Et(e){if(s!==void 0)return s;typeof e<"u"&&(Object.getPrototypeOf(e)===Object.prototype?{module:e}=e:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let t=Ft();e instanceof WebAssembly.Module||(e=new WebAssembly.Module(e));let r=new WebAssembly.Instance(e,t);return Rt(r,e)}async function Bt(e){if(s!==void 0)return s;typeof e<"u"&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof e>"u"&&(e=new URL("bitmark_wasm_bg.wasm",import.meta.url));let t=Ft();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:r,module:n}=await me(await e,t);return Rt(r,n)}var mt=Bt;var G={version:"6.1.4"};function W(e){return e.startsWith("error:")}function K(e){let t=e instanceof Error?e.message:String(e);return t.startsWith("error:")?t:`error: ${t}`}function fe(e){let t=e.trim();return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):e}function _e(e){if(e===void 0)return [];if(typeof e=="string"){let t=e.trim();return t===""?[]:JSON.parse(t)}return e}function be(e,t,r){if(r){let a=e.split_bits(t);if(W(a))throw new Error(a);let i=JSON.parse(a);return i.map(p=>({view:{format:"bitmark",index:p.index,total:i.length,source:p.source},source:p.source}))}let n=e.split_json_bits(t);if(W(n))throw new Error(n);let o=JSON.parse(n);return o.map((a,i)=>({view:{format:"json",index:i,total:o.length,bit:a.bit},source:JSON.stringify([a])}))}function ft(e,t,r){let n=r.mode??"optimized",o=r.outputFormat??"json",a=r.spacesAroundValues??1,i=r.indent??2,p=r.pretty??false,u=r.inputFormat??"auto",c=u==="bitmark"||u!=="json"&&e.is_bitmark(t),d=c?"bitmark":"json",l=_e(r.patch),g=be(e,t,c),k=g.length,m=[],y=[];for(let b=0;b<k;b++){let{view:v,source:S}=g[b];v.index=b,v.total=k;let j=r.preHook?r.preHook(v)||{}:{};if(j.drop)continue;let J=j.patches?[...l,...j.patches]:l;m.push({index:b,source:S,inputFormat:d,outputFormat:j.outputFormat??o,mode:n,patchJson:JSON.stringify(J),spacesAroundValues:a}),y.push(v);}return {jobs:m,views:y,output:o,pretty:p,indent:i}}function ye(e,t){let r=e.transform(t.source,t.inputFormat,t.outputFormat,t.mode,t.patchJson,false,2,t.spacesAroundValues);return W(r)?r:t.outputFormat==="json"?fe(r):r}function _t(e,t,r,n,o){if(r==="bitmark"||r==="text")return t.join(`
2
- `);let a=`[${t.join(",")}]`;return n?e.prettify(a,o):a}function It(e,t,r){let n;try{n=ft(e,t,r);}catch(a){return K(a)}let o=[];for(let a=0;a<n.jobs.length;a++){let i=ye(e,n.jobs[a]);if(W(i))return i;r.postHook?.(n.views[a],i),o.push(i);}return _t(e,o,n.output,n.pretty,n.indent)}async function Pt(e,t,r,n){let o;try{o=ft(e,t,r);}catch(i){return K(i)}let a;try{a=await n(o.jobs,r.workers??4);}catch(i){return K(i)}for(let i=0;i<a.length;i++){if(W(a[i]))return a[i];r.postHook?.(o.views[i],a[i]);}return _t(e,a,o.output,o.pretty,o.indent)}function St(e,t){if(e.length===0)return Promise.resolve([]);let r=Math.max(1,Math.min(t,e.length)),n=new URL("./worker-entry.js",import.meta.url);return new Promise((o,a)=>{let i=new Array(e.length),p=0,u=0,c=false,d=[],l=()=>{for(let m of d)m.terminate();},g=m=>{c||(c=true,l(),a(m));},k=m=>{if(c||p>=e.length)return;let y=p++;m.postMessage({id:y,job:e[y]});};for(let m=0;m<r;m++){let y=new Worker(n,{type:"module"});d.push(y),y.onmessage=b=>{let v=b.data;if(!c){if(!v.ok){g(new Error(v.error??"worker job failed"));return}if(i[v.id]=v.element,u++,u===e.length){c=true,l(),o(i);return}k(y);}},y.onerror=b=>g(new Error(b.message||"worker error"));}for(let m of d)k(m);})}var bt;function jt(e){bt=e;}function w(){if(!bt)throw new Error("legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)");return bt}var ie={};Tt(ie,{Ast:()=>zt,BitType:()=>Vt,BitmarkFileGenerator:()=>$t,BitmarkGenerator:()=>Dt,BitmarkParser:()=>te,BitmarkParserGenerator:()=>tt,BitmarkParserType:()=>Ee,BitmarkStringGenerator:()=>Kt,BitmarkVersion:()=>Fe,BodyTextFormat:()=>Pe,BoundingBoxIndex:()=>Ut,Builder:()=>Z,CardSetVersion:()=>Re,FileWriter:()=>re,HtmlTableGenerator:()=>Qt,HtmlTableParser:()=>Zt,InfoFormat:()=>Ie,InfoType:()=>Be,Input:()=>Oe,InputFormat:()=>ve,JsonFileGenerator:()=>Xt,JsonGenerator:()=>Yt,JsonParser:()=>ee,JsonStringGenerator:()=>qt,LegacyUnsupportedError:()=>N,NodeType:()=>Gt,Output:()=>Te,ResourceBuilder:()=>et,StreamWriter:()=>oe,StringWriter:()=>ne,TextLocation:()=>Se,TextMarkType:()=>Ct,TextNodeType:()=>Mt,bitmarkTextParse:()=>Wt,isPseudoAst:()=>Lt});var N=class extends Error{constructor(t){super(t),this.name="LegacyUnsupportedError";}};function A(e,t){throw new N(`'${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}function I(e,t){throw new N(`Option '${e}' is not supported by the @gmb/bitmark-parser legacy API`+(t?`: ${t}`:""))}var yt="bitmark v2 output is not supported (this parser is bitmark v3 only)";function xt(e){e.bitmarkVersion===2&&I("bitmarkVersion: 2",yt);}function Y(e){e.explicitTextFormat&&I("bitmarkOptions.explicitTextFormat"),e.prettifyJson!==void 0&&e.prettifyJson!==false&&I("bitmarkOptions.prettifyJson","embedded-JSON body prettification is not supported"),e.cardSetVersion===1&&I("bitmarkOptions.cardSetVersion: 1",yt),e.debugGenerationInline&&I("bitmarkOptions.debugGenerationInline"),e.noBreakscaping&&I("bitmarkOptions.noBreakscaping");}function q(e){e.textAsPlainText&&I("jsonOptions.textAsPlainText",yt),e.excludeUnknownProperties&&I("jsonOptions.excludeUnknownProperties"),e.debugGenerationInline&&I("jsonOptions.debugGenerationInline");}function C(e){return e===true?{pretty:true,indent:2}:typeof e=="number"&&e>0?{pretty:true,indent:e}:{pretty:false,indent:2}}function X(e){return e===void 0||e===true?1:e===false?0:Math.max(0,Math.min(10,e))}function Q(e){switch(e){case "text":case "latex":case "json":case "xml":return "plainText";default:return "bitmark++"}}var At=Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");function M(e){let t={bits:e};return Object.defineProperty(t,At,{value:true,enumerable:false}),t}function Lt(e){return e!==null&&typeof e=="object"&&(At in e||Array.isArray(e.bits))}var kt=Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser"),ke={bitType:"type",textFormat:"format",flashcards:"cards",markConfig:"marks"},we={"bitmark--":"bitmark++","bitmark+":"bitmark++"},he=["title","subtitle","item","lead","pageNumber","marginNumber","hint","instruction","caption"],Z=class{buildBitmark(t){let r=M(t.bits??[]);return t.errors!==void 0&&(r.errors=t.errors),r}buildBit(t,r){let n=w(),o={...t},a=o.bitType;this.assertKnownBitType(a);let i={};i.type=a,o.isCommented&&(i.type="_comment",i.originalType=a),delete o.bitType,delete o.isCommented;let p=o.textFormat;p!==void 0&&(i.format=we[p]??p,delete o.textFormat),delete o.resourceType;let u=o.body;u!=null&&typeof u=="object"&&"body"in u&&(i.body=u.body,delete o.body),o.example!==void 0?(i.isExample=true,i.example=o.example,delete o.example,delete o.__isDefaultExample):o.__isDefaultExample&&(i.isExample=true,delete o.__isDefaultExample);let c=o.resources;c!==void 0&&(Array.isArray(c)?c.length===1?i.resource=c[0]:c.length>1&&(i.resources=c):i.resource=c,delete o.resources);let d=o.parser;delete o.parser;let l=o.extraProperties;delete o.extraProperties;for(let[y,b]of Object.entries(o))b!==void 0&&(i[ke[y]??y]=b);if(l)for(let[y,b]of Object.entries(l))y in i||(i[y]=b);this.parseStringTexts(i);let g=n.convert(JSON.stringify([{bit:i}]),"json","json","optimized",false,2,1);if(g.startsWith("error:"))throw new Error(g.slice(6).trim());let m=JSON.parse(g)[0]?.bit??i;for(let[y,b]of Object.entries(i))y in m||b===false||b===""||b===null||Array.isArray(b)&&b.length===0||(m[y]=b);return d!==void 0&&Object.defineProperty(m,kt,{value:d,enumerable:false}),m}buildHighlight(t,r){if(!r)return;let n={...r},o=n.attrs;return o&&Object.assign(n,o),{type:"highlight",texts:Array.isArray(n.texts)?n.texts.filter(p=>p!=null).map(p=>({text:p.text??"",isCorrect:p.isCorrect??false,isHighlighted:p.isHighlighted??false,...Jt(p,["text","isCorrect","isHighlighted"])})):[],prefix:n.prefix??"",postfix:n.postfix??"",...Jt(n,["type","texts","prefix","postfix","attrs"]),attrs:{}}}parseStringTexts(t){let r=w(),n=(i,p)=>{if(i==="")return i;let u=r.convert_text(i,"textToAst","bitmark++",p);try{return JSON.parse(u)}catch{return i}},o=t.format,a=o===void 0||o==="bitmark++"||o==="bitmark+";typeof t.body=="string"&&a&&(t.body=n(t.body,"body"));for(let i of he){let p=t[i];typeof p=="string"&&(t[i]=n(p,"tag"));}}assertKnownBitType(t){let r=w(),n=false;if(t!==void 0)try{n=JSON.parse(r.info("bit","json",t,!1,2)).error===void 0;}catch{n=false;}if(!n)throw new Error(`No config found for bit: ${t}`)}};function Jt(e,t){let r={};for(let[n,o]of Object.entries(e))o!==void 0&&!t.includes(n)&&(r[n]=o);return r}var tt=class{version(){return G.version}convert(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);xt(n),Y(a),q(o),this.checkBrowserFileWrite(n.outputFile);let i=w(),{source:p,isBitmark:u}=this.resolveInput(t,n.inputFormat),c=n.outputFormat??(u?"json":"bitmark"),d=c==="ast"?"json":c,{pretty:l,indent:g}=C(o.prettify),k=X(a.spacesAroundValues),m=i.convert(p,u?"bitmark":"json",d,"optimized",l,g,k);if(this.throwOnError(m),c==="bitmark"||c==="text")return this.deliver(m,n.outputFile,n.fileOptions);if(c==="json")return n.outputFile?this.deliver(m,n.outputFile,n.fileOptions):l||o.stringify?m:JSON.parse(m);let y=M(JSON.parse(m));return n.outputFile?this.deliver(JSON.stringify(y),n.outputFile,n.fileOptions):y}upgrade(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);xt(n),Y(a),q(o),this.checkBrowserFileWrite(n.outputFile);let i=w(),{source:p,isBitmark:u}=this.resolveInput(t,n.inputFormat),{pretty:c,indent:d}=C(o.prettify),l=X(a.spacesAroundValues),g=i.canonicalize(p,u?"bitmark":"json","optimized",c,d,l);return this.throwOnError(g),u?this.deliver(g,n.outputFile,n.fileOptions):n.outputFile?this.deliver(g,n.outputFile,n.fileOptions):c||o.stringify?g:JSON.parse(g)}info(t){let r=Object.assign({},t),n=w(),o=r.type??"list",a=r.outputFormat??"text",{pretty:i,indent:p}=C(r.prettify),u=a==="pojo"?"json":a,c=n.info(o,u,r.bit??"",i,p);return this.throwOnError(c),a==="pojo"?JSON.parse(c):c}generateConfig(t){A("BitmarkParserGenerator.generateConfig","bpg-internal development tool");}convertHtmlTable(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);Y(a),q(o),n.keepUnknownTags&&I("keepUnknownTags"),n.noBreakscaping&&I("noBreakscaping"),this.checkBrowserFileWrite(n.outputFile);let i=w(),p=typeof t=="string"?this.maybeReadFile(t,void 0):"";if(!(n.inputFormat==="html"||n.inputFormat===void 0&&typeof t=="string"&&/<table[\s>]/iu.test(p))){let{source:S,isBitmark:j}=this.resolveInput(t,void 0),J=i.convert(S,j?"bitmark":"json","html","optimized",false,2,1);return this.throwOnError(J),this.deliver(wt(J).join(`
3
- `),n.outputFile,n.fileOptions)}let c=n.tableFormat==="table"?"table":"table-extended",d=wt(p).map(S=>`<bitmark-bit data-type="${c}" data-format="bitmark++">${S}</bitmark-bit>`).join(""),l=n.outputFormat??"bitmark",{pretty:g,indent:k}=C(o.prettify),m=X(a.spacesAroundValues);if(l==="html"){let S=i.convert(d,"html","html","optimized",false,2,1);return this.throwOnError(S),this.deliver(wt(S).join(`
4
- `),n.outputFile,n.fileOptions)}let y=l==="ast"?"json":l,b=i.convert(d,"html",y,"optimized",g,k,m);if(this.throwOnError(b),l==="bitmark"||l==="text")return this.deliver(b,n.outputFile,n.fileOptions);if(l==="json")return n.outputFile?this.deliver(b,n.outputFile,n.fileOptions):g||o.stringify?b:JSON.parse(b);let v=M(JSON.parse(b));return n.outputFile?this.deliver(JSON.stringify(v),n.outputFile,n.fileOptions):v}createAst(t,r){let n=Object.assign({},r),o=w(),{source:a,isBitmark:i}=this.resolveInput(t,n.inputFormat),p=o.convert(a,i?"bitmark":"json","json","optimized",false,2,1);return this.throwOnError(p),M(JSON.parse(p))}breakscapeText(t,r){if(!t)return t;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=w(),a=this.maybeReadFile(t,n.inputFormat),i=o.breakscape_text(a,Q(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}unbreakscapeText(t,r){if(!t)return t;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=w(),a=this.maybeReadFile(t,n.inputFormat),i=o.unbreakscape_text(a,Q(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}convertText(t,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions);this.checkBrowserFileWrite(n.outputFile);let a=w(),i=n.textFormat===void 0||Q(n.textFormat)==="bitmark++",p=n.textLocation??"body",u,c;if(typeof t=="string"?(u=this.maybeReadFile(t,n.inputFormat),c=this.parseTextAstString(u)):(u=JSON.stringify(t),c=Array.isArray(t)?t:void 0),c!==void 0){let m=i?a.convert_text(JSON.stringify(c),"astToText","bitmark++",p):a.convert_text(JSON.stringify(c),"astToPlainText","plainText",p);return this.throwOnError(m),this.deliver(m,n.outputFile,n.fileOptions)}let d=a.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(d);let{pretty:l,indent:g}=C(o.prettify),k=l?a.prettify(d,g):d;return n.outputFile?this.deliver(k,n.outputFile,n.fileOptions):l?k:JSON.parse(d)}textAstToPlainText(t,r){let o=w().convert_text(typeof t=="string"?t:JSON.stringify(t),"astToPlainText","bitmark++","body");return this.throwOnError(o),o}extractPlainText(t,r){let n=r?.inputFormat,o=w();if(n==="plainText")return typeof t=="string"?String(t):"";if(n==="bitmarkText"){let u=o.convert_text(String(t),"textToAst","bitmark++","body"),c=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(c),c}if(typeof t=="string"&&this.parseTextAstString(t)===void 0&&!o.is_bitmark(t)&&!(()=>{try{return JSON.parse(t),!0}catch{return false}})())return this.extractPlainText(t,{inputFormat:"bitmarkText"});let{source:a,isBitmark:i}=this.resolveInput(t,void 0),p=o.convert(a,i?"bitmark":"json","text","optimized",false,2,1);return this.throwOnError(p),p}parseTextAstString(t){let r=t.trim();if(r.startsWith("["))try{let n=JSON.parse(r);if(Array.isArray(n)&&n.every(o=>o!==null&&typeof o=="object"&&"type"in o))return n}catch{}}resolveInput(t,r){if(typeof t!="string"){let a=this.jsonEntries(t);return {source:JSON.stringify(a?a.map(i=>this.toWrapperEntry(i)):t),isBitmark:false}}let n=this.maybeReadFile(t,r);if(w().is_bitmark(n))return {source:n,isBitmark:true};try{let a=JSON.parse(n),i=this.jsonEntries(a);if(i)return {source:JSON.stringify(i.map(p=>this.toWrapperEntry(p))),isBitmark:!1}}catch{return {source:n,isBitmark:true}}return {source:n,isBitmark:false}}jsonEntries(t){if(Array.isArray(t))return t;if(t!==null&&typeof t=="object"){let r=t;if(Array.isArray(r.bits))return r.bits;if("bit"in r)return [r];if(typeof r.type=="string")return [{bit:r}]}}toWrapperEntry(t){if(t!==null&&typeof t=="object"&&"bit"in t)return t;let r={bit:t},n=t?.[kt];return n!==void 0&&(r.parser=n),r}maybeReadFile(t,r){if(r==="string")return t;return t;}checkBrowserFileWrite(t){if(t&&true)throw new Error("Cannot write to file in browser environment")}deliver(t,r,n){if(!r)return t;throw new Error("Cannot write to file in browser environment");}throwOnError(t){if(t.startsWith("error:"))throw new Error(t.slice(6).trim())}};function wt(e){let t=[],r=e.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let a=0,i=o,p=-1;for(;i<e.length;){let u=r.indexOf("<table",i),c=r.indexOf("</table",i);if(c===-1)break;if(u!==-1&&u<c)a++,i=u+6;else {a--;let d=r.indexOf(">",c);if(i=d===-1?e.length:d+1,a===0){p=i;break}}}if(p===-1)break;t.push(e.slice(o,p)),n=p;}return t}function Wt(e){let t=w().convert_text(e,"textToAst","bitmark++","body");if(t.startsWith("error:"))throw new Error(t.slice(6).trim());return JSON.parse(t)}var T={imageResource:{type:"image",key:"image",valueField:"src"},imageLinkResource:{type:"image-link",key:"imageLink",valueField:"url"},audioResource:{type:"audio",key:"audio",valueField:"src"},audioEmbedResource:{type:"audio-embed",key:"audioEmbed",valueField:"src"},audioLinkResource:{type:"audio-link",key:"audioLink",valueField:"url"},videoResource:{type:"video",key:"video",valueField:"src"},videoEmbedResource:{type:"video-embed",key:"videoEmbed",valueField:"url"},videoLinkResource:{type:"video-link",key:"videoLink",valueField:"url"},stillImageFilmEmbedResource:{type:"still-image-film-embed",key:"stillImageFilmEmbed",valueField:"url"},stillImageFilmLinkResource:{type:"still-image-film-link",key:"stillImageFilmLink",valueField:"url"},articleResource:{type:"article",key:"article",valueField:"body"},documentResource:{type:"document",key:"document",valueField:"url"},documentEmbedResource:{type:"document-embed",key:"documentEmbed",valueField:"url"},documentLinkResource:{type:"document-link",key:"documentLink",valueField:"url"},documentDownloadResource:{type:"document-download",key:"documentDownload",valueField:"url"},appLinkResource:{type:"app-link",key:"appLink",valueField:"url"},websiteLinkResource:{type:"website-link",key:"websiteLink",valueField:"url"}};function h(e){return (t,r,n)=>{if(!r)return;let{value:o,...a}=r,i={[e.valueField]:o??""};for(let[p,u]of Object.entries(a))u!==void 0&&(i[p]=u);return {type:e.type,[e.key]:i}}}var Nt=Object.fromEntries(Object.values(T).map(e=>[e.type,e])),et=class{constructor(){O(this,"imageResource",h(T.imageResource));O(this,"imageLinkResource",h(T.imageLinkResource));O(this,"audioResource",h(T.audioResource));O(this,"audioEmbedResource",h(T.audioEmbedResource));O(this,"audioLinkResource",h(T.audioLinkResource));O(this,"videoResource",h(T.videoResource));O(this,"videoEmbedResource",h(T.videoEmbedResource));O(this,"videoLinkResource",h(T.videoLinkResource));O(this,"stillImageFilmEmbedResource",h(T.stillImageFilmEmbedResource));O(this,"stillImageFilmLinkResource",h(T.stillImageFilmLinkResource));O(this,"articleResource",h(T.articleResource));O(this,"documentResource",h(T.documentResource));O(this,"documentEmbedResource",h(T.documentEmbedResource));O(this,"documentLinkResource",h(T.documentLinkResource));O(this,"documentDownloadResource",h(T.documentDownloadResource));O(this,"appLinkResource",h(T.appLinkResource));O(this,"websiteLinkResource",h(T.websiteLinkResource));}resourceFromResourceJson(t,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,a=[];for(let i of o){let p=Nt[i.type];if(!p)continue;let u=i[p.key]??{},{[p.valueField]:c,...d}=u,l=h(p)(void 0,{value:c,...d});l&&a.push(l);}if(a.length!==0)return n?a[0]:a}resourceFromResourceDataJson(t,r,n){if(!n)return;let o=Nt[r];if(!o)return;let a=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:p,src:u,body:c,...d}=i,l=p??u??c??a;return h(o)(t,{value:l,...d})}};var Oe={string:"string",file:"file"},Te={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},ve={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},Fe={v2:2,v3:3},Re={v1:1,v2:2},Ee={peggy:"peggy"},Be={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},Ie={text:"text",json:"json",pojo:"pojo"},Pe={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},Se={tag:"tag",body:"body"};var Ct={bold:"bold",light:"light",italic:"italic",highlight:"highlight",highlightOrange:"highlightOrange",highlightYellow:"highlightYellow",highlightGreen:"highlightGreen",highlightBlue:"highlightBlue",highlightPurple:"highlightPurple",highlightPink:"highlightPink",highlightBrown:"highlightBrown",highlightBlack:"highlightBlack",highlightWhite:"highlightWhite",highlightGray:"highlightGray",strike:"strike",subscript:"subscript",superscript:"superscript",ins:"ins",del:"del",underline:"underline",doubleUnderline:"doubleUnderline",circle:"circle",languageEmRed:"languageEmRed",languageEmOrange:"languageEmOrange",languageEmYellow:"languageEmYellow",languageEmGreen:"languageEmGreen",languageEmBlue:"languageEmBlue",languageEmPurple:"languageEmPurple",languageEmPink:"languageEmPink",languageEmBrown:"languageEmBrown",languageEmBlack:"languageEmBlack",languageEmWhite:"languageEmWhite",languageEmGray:"languageEmGray",languageEm:"languageEm",userUnderline:"userUnderline",userDoubleUnderline:"userDoubleUnderline",userStrike:"userStrike",userCircle:"userCircle",userHighlight:"userHighlight",notranslate:"notranslate",link:"link",ref:"ref",xref:"xref",extref:"extref",footnote:"footnote",footnoteStar:"footnote*",symbol:"symbol",var:"var",code:"code",timer:"timer",duration:"duration",color:"color",colorPicker:"colorPicker",comment:"comment"},Mt={text:"text",hardBreak:"hardBreak",paragraph:"paragraph",heading:"heading",section:"section",noBulletList:"noBulletList",bulletList:"bulletList",orderedList:"orderedList",orderedListRoman:"orderedListRoman",orderedListRomanLower:"orderedListRomanLower",letteredList:"letteredList",letteredListLower:"letteredListLower",taskList:"taskList",listItem:"listItem",taskItem:"taskItem",image:"image",imageInline:"imageInline",codeBlock:"codeBlock",latex:"latex",gap:"gap",select:"select",highlight:"highlight",mark:"mark"};function je(e){return e.replace(/-([a-z0-9])/gu,(t,r)=>r.toUpperCase())}var ht;function U(){if(!ht){let e=w(),t=JSON.parse(e.info("all","json","",false,2)),r={_standard:"_standard"};for(let{name:n}of t)r[je(n)]=n;ht=r;}return ht}var Vt=new Proxy({},{get:(e,t)=>typeof t=="string"?U()[t]:void 0,has:(e,t)=>typeof t=="string"&&t in U(),ownKeys:()=>Reflect.ownKeys(U()),getOwnPropertyDescriptor:(e,t)=>typeof t=="string"&&t in U()?{value:U()[t],enumerable:true,configurable:true,writable:false}:void 0});function Ht(e,t){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${e}]`:A(e,t),has:()=>A(e,t),ownKeys:()=>A(e,t)})}var Gt=Ht("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),Ut=Ht("BoundingBoxIndex","bpg-internal bounding-box utility");function B(e,t){return class{constructor(){A(e,t);}}}var Ae="the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave",P="internal class of bpg's TS implementation",zt=B("Ast",Ae),Dt=B("BitmarkGenerator",P),Kt=B("BitmarkStringGenerator",P),$t=B("BitmarkFileGenerator",P),Yt=B("JsonGenerator",P),qt=B("JsonStringGenerator",P),Xt=B("JsonFileGenerator",P),Qt=B("HtmlTableGenerator",P),Zt=B("HtmlTableParser",P),te=B("BitmarkParser",P),ee=B("JsonParser",P),ne=B("StringWriter",P),re=B("FileWriter",P),oe=B("StreamWriter",P);jt(H);async function Gn(e){return typeof e>"u"&&(e=new URL(`bitmark_wasm_bg.wasm?v=${G.version}`,import.meta.url)),mt(e)}function Un(){return G.version}function zn(e,t={}){return nt(e,t.stage??"lex")}function Dn(e,t={}){return rt(e,t.mode??"optimized")}function Kn(e,t={}){return pt(e,t.inputFormat??"auto",t.outputFormat??"auto",t.mode??"optimized",t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function $n(e,t={}){return ut(e,t.inputFormat??"auto",t.pretty??false,t.indent??2)}function Le(e,t={}){return ct(e,t.inputFormat??"auto",t.pretty??false,t.indent??2)}var Yn=Le;function qn(e,t={}){return dt(e,t.inputFormat??"auto",t.mode??"optimized",t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function Xn(e){let t=lt(e);if(t.startsWith("error:"))throw new Error(t);return Number.parseInt(t,10)}function Qn(e){return JSON.parse(gt(e))}function Zn(e,t={}){if(t.preHook||t.postHook)return It(H,e,t);let r=t.patch===void 0?"":typeof t.patch=="string"?t.patch:JSON.stringify(t.patch);return st(e,t.inputFormat??"auto",t.outputFormat??"json",t.mode??"optimized",r,t.pretty??false,t.indent??2,t.spacesAroundValues??1)}function tr(e,t={}){return Pt(H,e,t,St)}function er(e,t={}){let r=t.format??"bitmark++",n=t.location??"body";return ot(e,r,n)}function nr(e,t={}){let r=t.format??"bitmark++",n=t.location??"body";return it(e,r,n)}function rr(e={}){let t=e.infoType??"list",r=e.format??"text",n=e.bit??"",o=e.pretty??false,a=e.indent??2;return at(t,r,n,o,a)}export{er as breakscapeText,qn as canonicalize,Kn as convert,Xn as countBits,Yn as expand,Le as fullize,rr as info,Gn as init,Et as initSync,ie as legacy,zn as lex,$n as optimize,Dn as parse,Qn as splitBits,Zn as transform,tr as transformParallel,nr as unbreakscapeText,Un as version};//# sourceMappingURL=bitmark-parser.min.js.map
1
+ var 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
5
5
  //# sourceMappingURL=bitmark-parser.min.js.map