@gmb/bitmark-parser 6.8.0 → 6.9.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 +19 -2
- package/dist/browser/bitmark-parser.min.js +4 -4
- package/dist/browser/bitmark-parser.min.js.map +1 -1
- package/dist/browser/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/cjs/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/cjs/index.cjs +11 -8
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +1238 -21
- package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/esm/index.d.ts +1238 -21
- package/dist/browser/esm/index.js +11 -8
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/index.cjs +9 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1237 -20
- package/dist/index.d.ts +1237 -20
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +5 -5
- package/dist/legacy.cjs.map +1 -1
- package/dist/legacy.d.cts +3 -1
- package/dist/legacy.d.ts +3 -1
- package/dist/legacy.js +5 -5
- package/dist/legacy.js.map +1 -1
- package/package.json +6 -6
- package/schema/bitmark.schema.json +4612 -421
- package/wasm/bitmark_wasm.d.ts +6 -1
- package/wasm/bitmark_wasm.js +10 -2
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +1 -1
- package/wasm/package.json +1 -1
package/README.md
CHANGED
|
@@ -146,13 +146,26 @@ Unbreakscape text (unescape bitmark special characters).
|
|
|
146
146
|
|
|
147
147
|
#### info(options?: InfoOptions): string
|
|
148
148
|
|
|
149
|
-
Query information about supported bit types.
|
|
149
|
+
Query information about supported bit types. `"bit"`/`"all"` default to a
|
|
150
|
+
compact view — one line per tag with its format, effective count and default,
|
|
151
|
+
chains and card-set tags nested. With `full: true` they report the complete
|
|
152
|
+
detail: body/footer/resource rules, default provenance (configured vs
|
|
153
|
+
format-natural), nullability (absence as a distinct state — orthogonal to
|
|
154
|
+
defaults), JSON keys, per-context overrides, and the card set structure. `"deprecated"` lists deprecated bits with their deprecation
|
|
155
|
+
version and (separately) any migration target.
|
|
150
156
|
|
|
151
157
|
- `infoType` — `"list"` (default), `"bit"`, `"all"`, or `"deprecated"`
|
|
152
158
|
- `format` — `"text"` (default) or `"json"`
|
|
153
159
|
- `bit` — filter to a specific bit type (when `infoType` is `"bit"`)
|
|
154
160
|
- `pretty` — prettify JSON output (default: `false`)
|
|
155
161
|
- `indent` — indent size for pretty JSON (default: `2`)
|
|
162
|
+
- `includeDeprecated` — include deprecated bits in `"list"`/`"all"` (default: `false`)
|
|
163
|
+
- `onlyDeprecated` — restrict `"list"`/`"all"` to deprecated bits (default: `false`)
|
|
164
|
+
- `full` — complete detail for `"bit"`/`"all"` (default: `false` = compact view)
|
|
165
|
+
|
|
166
|
+
The WASM build omits bit/tag descriptions, group-inheritance provenance and
|
|
167
|
+
raw mapping patterns (native-CLI-only, via the `info-meta` cargo feature) to
|
|
168
|
+
keep the binary small.
|
|
156
169
|
|
|
157
170
|
#### version(): string
|
|
158
171
|
|
|
@@ -329,7 +342,11 @@ bitmark unbreakscape input.txt
|
|
|
329
342
|
# Query bit type information
|
|
330
343
|
bitmark info
|
|
331
344
|
bitmark info all -f json --pretty
|
|
332
|
-
bitmark info
|
|
345
|
+
bitmark info --bit article # compact: one line per tag (format, count, default)
|
|
346
|
+
bitmark info --bit article --full # full detail: defaults, provenance, keys, card set
|
|
347
|
+
bitmark info deprecated # deprecated bits + migration targets
|
|
348
|
+
bitmark info list --all # include deprecated bits in the listing
|
|
349
|
+
bitmark info list --deprecated # only deprecated bits
|
|
333
350
|
```
|
|
334
351
|
|
|
335
352
|
All commands support `-o, --output <file>` and `-a, --append` flags. Commands that accept input support file paths, literal strings, or stdin (when no arguments are given).
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var we=Object.defineProperty;var st=(t,e,r)=>e in t?we(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var he=(t,e)=>{for(var r in e)we(t,r,{get:e[r],enumerable:true});};var
|
|
2
|
-
`);let
|
|
3
|
-
`),n.outputFile,n.fileOptions)}let c=n.tableFormat==="table"?"table":"table-extended",l=xe(p).map(
|
|
4
|
-
`),n.outputFile,n.fileOptions)}let k=d==="ast"?"json":d,m=i.convert(l,"html",k,"optimized",f,y,x,false,false);if(this.throwOnError(m),d==="bitmark"||d==="text")return this.deliver(m,n.outputFile,n.fileOptions);if(d==="json")return n.outputFile?this.deliver(m,n.outputFile,n.fileOptions):f||o.stringify?m:JSON.parse(m);let g=V(JSON.parse(m));return n.outputFile?this.deliver(JSON.stringify(g),n.outputFile,n.fileOptions):g}createAst(e,r){let n=Object.assign({},r),o=h(),{source:s,isBitmark:i}=this.resolveInput(e,n.inputFormat),p=o.convert(s,i?"bitmark":"json","json","optimized",false,2,1,true,false);return this.throwOnError(p),V(JSON.parse(p))}breakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),s=this.maybeReadFile(e,n.inputFormat),i=o.breakscape_text(s,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}unbreakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),s=this.maybeReadFile(e,n.inputFormat),i=o.unbreakscape_text(s,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}convertText(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions);this.checkBrowserFileWrite(n.outputFile);let s=h(),i=n.textFormat===void 0||Z(n.textFormat)==="bitmark++",p=n.textLocation??"body",u,c;if(typeof e=="string"?(u=this.maybeReadFile(e,n.inputFormat),c=this.parseTextAstString(u)):(u=JSON.stringify(e),c=Array.isArray(e)?e:void 0),c!==void 0){let x=i?s.convert_text(JSON.stringify(c),"astToText","bitmark++",p):s.convert_text(JSON.stringify(c),"astToPlainText","plainText",p);return this.throwOnError(x),this.deliver(x,n.outputFile,n.fileOptions)}let l=s.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(l);let{pretty:d,indent:f}=W(o.prettify),y=d?s.prettify(l,f):l;return n.outputFile?this.deliver(y,n.outputFile,n.fileOptions):d?y:JSON.parse(l)}textAstToPlainText(e,r){let o=h().convert_text(typeof e=="string"?e:JSON.stringify(e),"astToPlainText","bitmark++","body");return this.throwOnError(o),o}extractPlainText(e,r){let n=r?.inputFormat,o=h();if(n==="plainText")return typeof e=="string"?String(e):"";if(n==="bitmarkText"){let u=o.convert_text(String(e),"textToAst","bitmark++","body"),c=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(c),c}if(typeof e=="string"&&this.parseTextAstString(e)===void 0&&!o.is_bitmark(e)&&!(()=>{try{return JSON.parse(e),!0}catch{return false}})())return this.extractPlainText(e,{inputFormat:"bitmarkText"});let{source:s,isBitmark:i}=this.resolveInput(e,void 0),p=o.convert(s,i?"bitmark":"json","text","optimized",false,2,1,false,false);return this.throwOnError(p),p}parseTextAstString(e){let r=e.trim();if(r.startsWith("["))try{let n=JSON.parse(r);if(Array.isArray(n)&&n.every(o=>o!==null&&typeof o=="object"&&"type"in o))return n}catch{}}resolveInput(e,r){if(typeof e!="string"){let s=this.jsonEntries(e);return {source:JSON.stringify(s?s.map(i=>this.toWrapperEntry(i)):e),isBitmark:false}}let n=this.maybeReadFile(e,r);if(h().is_bitmark(n))return {source:n,isBitmark:true};try{let s=JSON.parse(n),i=this.jsonEntries(s);if(i)return {source:JSON.stringify(i.map(p=>this.toWrapperEntry(p))),isBitmark:!1}}catch{return {source:n,isBitmark:true}}return {source:n,isBitmark:false}}jsonEntries(e){if(Array.isArray(e))return e;if(e!==null&&typeof e=="object"){let r=e;if(Array.isArray(r.bits))return r.bits;if("bit"in r)return [r];if(typeof r.type=="string")return [{bit:r}]}}toWrapperEntry(e){if(e!==null&&typeof e=="object"&&"bit"in e)return e;let r={bit:e},n=e?.[_e];return n!==void 0&&(r.parser=n),r}maybeReadFile(e,r){if(r==="string")return e;return e;}checkBrowserFileWrite(e){if(e&&true)throw new Error("Cannot write to file in browser environment")}deliver(e,r,n){if(!r)return e;throw new Error("Cannot write to file in browser environment");}throwOnError(e){if(e.startsWith("error:"))throw new Error(e.slice(6).trim())}};function xe(t){let e=[],r=t.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let s=0,i=o,p=-1;for(;i<t.length;){let u=r.indexOf("<table",i),c=r.indexOf("</table",i);if(c===-1)break;if(u!==-1&&u<c)s++,i=u+6;else {s--;let l=r.indexOf(">",c);if(i=l===-1?t.length:l+1,s===0){p=i;break}}}if(p===-1)break;e.push(t.slice(o,p)),n=p;}return e}function Je(t){let e=h().convert_text(t,"textToAst","bitmark++","body");if(e.startsWith("error:"))throw new Error(e.slice(6).trim());return JSON.parse(e)}var R={imageResource:{type:"image",key:"image",valueField:"src"},imageLinkResource:{type:"image-link",key:"imageLink",valueField:"url"},audioResource:{type:"audio",key:"audio",valueField:"src"},audioEmbedResource:{type:"audio-embed",key:"audioEmbed",valueField:"src"},audioLinkResource:{type:"audio-link",key:"audioLink",valueField:"url"},videoResource:{type:"video",key:"video",valueField:"src"},videoEmbedResource:{type:"video-embed",key:"videoEmbed",valueField:"url"},videoLinkResource:{type:"video-link",key:"videoLink",valueField:"url"},stillImageFilmEmbedResource:{type:"still-image-film-embed",key:"stillImageFilmEmbed",valueField:"url"},stillImageFilmLinkResource:{type:"still-image-film-link",key:"stillImageFilmLink",valueField:"url"},articleResource:{type:"article",key:"article",valueField:"body"},documentResource:{type:"document",key:"document",valueField:"url"},documentEmbedResource:{type:"document-embed",key:"documentEmbed",valueField:"url"},documentLinkResource:{type:"document-link",key:"documentLink",valueField:"url"},documentDownloadResource:{type:"document-download",key:"documentDownload",valueField:"url"},appLinkResource:{type:"app-link",key:"appLink",valueField:"url"},websiteLinkResource:{type:"website-link",key:"websiteLink",valueField:"url"}};function O(t){return (e,r,n)=>{if(!r)return;let{value:o,...s}=r,i={[t.valueField]:o??""};for(let[p,u]of Object.entries(s))u!==void 0&&(i[p]=u);return {type:t.type,[t.key]:i}}}var We=Object.fromEntries(Object.values(R).map(t=>[t.type,t])),ne=class{constructor(){T(this,"imageResource",O(R.imageResource));T(this,"imageLinkResource",O(R.imageLinkResource));T(this,"audioResource",O(R.audioResource));T(this,"audioEmbedResource",O(R.audioEmbedResource));T(this,"audioLinkResource",O(R.audioLinkResource));T(this,"videoResource",O(R.videoResource));T(this,"videoEmbedResource",O(R.videoEmbedResource));T(this,"videoLinkResource",O(R.videoLinkResource));T(this,"stillImageFilmEmbedResource",O(R.stillImageFilmEmbedResource));T(this,"stillImageFilmLinkResource",O(R.stillImageFilmLinkResource));T(this,"articleResource",O(R.articleResource));T(this,"documentResource",O(R.documentResource));T(this,"documentEmbedResource",O(R.documentEmbedResource));T(this,"documentLinkResource",O(R.documentLinkResource));T(this,"documentDownloadResource",O(R.documentDownloadResource));T(this,"appLinkResource",O(R.appLinkResource));T(this,"websiteLinkResource",O(R.websiteLinkResource));}resourceFromResourceJson(e,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,s=[];for(let i of o){let p=We[i.type];if(!p)continue;let u=i[p.key]??{},{[p.valueField]:c,...l}=u,d=O(p)(void 0,{value:c,...l});d&&s.push(d);}if(s.length!==0)return n?s[0]:s}resourceFromResourceDataJson(e,r,n){if(!n)return;let o=We[r];if(!o)return;let s=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:p,src:u,body:c,...l}=i,d=p??u??c??s;return O(o)(e,{value:d,...l})}};var ht={string:"string",file:"file"},Ot={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},Tt={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},Ft={v2:2,v3:3},vt={v1:1,v2:2},Rt={peggy:"peggy"},Et={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},Pt={text:"text",json:"json",pojo:"pojo"},Bt={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},St={tag:"tag",body:"body"};var Ne={bold:"bold",light:"light",italic:"italic",highlight:"highlight",highlightOrange:"highlightOrange",highlightYellow:"highlightYellow",highlightGreen:"highlightGreen",highlightBlue:"highlightBlue",highlightPurple:"highlightPurple",highlightPink:"highlightPink",highlightBrown:"highlightBrown",highlightBlack:"highlightBlack",highlightWhite:"highlightWhite",highlightGray:"highlightGray",strike:"strike",subscript:"subscript",superscript:"superscript",ins:"ins",del:"del",underline:"underline",doubleUnderline:"doubleUnderline",circle:"circle",languageEmRed:"languageEmRed",languageEmOrange:"languageEmOrange",languageEmYellow:"languageEmYellow",languageEmGreen:"languageEmGreen",languageEmBlue:"languageEmBlue",languageEmPurple:"languageEmPurple",languageEmPink:"languageEmPink",languageEmBrown:"languageEmBrown",languageEmBlack:"languageEmBlack",languageEmWhite:"languageEmWhite",languageEmGray:"languageEmGray",languageEm:"languageEm",userUnderline:"userUnderline",userDoubleUnderline:"userDoubleUnderline",userStrike:"userStrike",userCircle:"userCircle",userHighlight:"userHighlight",notranslate:"notranslate",link:"link",ref:"ref",xref:"xref",extref:"extref",footnote:"footnote",footnoteStar:"footnote*",symbol:"symbol",var:"var",code:"code",timer:"timer",duration:"duration",color:"color",colorPicker:"colorPicker",comment:"comment"},Ce={text:"text",hardBreak:"hardBreak",paragraph:"paragraph",heading:"heading",section:"section",noBulletList:"noBulletList",bulletList:"bulletList",orderedList:"orderedList",orderedListRoman:"orderedListRoman",orderedListRomanLower:"orderedListRomanLower",letteredList:"letteredList",letteredListLower:"letteredListLower",taskList:"taskList",listItem:"listItem",taskItem:"taskItem",image:"image",imageInline:"imageInline",codeBlock:"codeBlock",latex:"latex",gap:"gap",select:"select",highlight:"highlight",mark:"mark"};function It(t){return t.replace(/-([a-z0-9])/gu,(e,r)=>r.toUpperCase())}var ke;function z(){if(!ke){let t=h(),e=JSON.parse(t.info("all","json","",false,2)),r={_standard:"_standard"};for(let{name:n}of e)r[It(n)]=n;ke=r;}return ke}var Ve=new Proxy({},{get:(t,e)=>typeof e=="string"?z()[e]:void 0,has:(t,e)=>typeof e=="string"&&e in z(),ownKeys:()=>Reflect.ownKeys(z()),getOwnPropertyDescriptor:(t,e)=>typeof e=="string"&&e in z()?{value:z()[e],enumerable:true,configurable:true,writable:false}:void 0});function Me(t,e){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${t}]`:L(t,e),has:()=>L(t,e),ownKeys:()=>L(t,e)})}var He=Me("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),Ue=Me("BoundingBoxIndex","bpg-internal bounding-box utility");function P(t,e){return class{constructor(){L(t,e);}}}var jt="the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave",B="internal class of bpg's TS implementation",Ge=P("Ast",jt),ze=P("BitmarkGenerator",B),De=P("BitmarkStringGenerator",B),$e=P("BitmarkFileGenerator",B),Ke=P("JsonGenerator",B),Ye=P("JsonStringGenerator",B),Xe=P("JsonFileGenerator",B),qe=P("HtmlTableGenerator",B),Qe=P("HtmlTableParser",B),Ze=P("BitmarkParser",B),et=P("JsonParser",B),tt=P("StringWriter",B),nt=P("FileWriter",B),rt=P("StreamWriter",B);function At(t,e,r){return r===void 0?{path:t,op:e}:{path:t,op:e,value:r}}Se(U);async function $n(t){return typeof t>"u"&&(t=new URL(`bitmark_wasm_bg.wasm?v=${G.version}`,import.meta.url)),de(t)}function Kn(){return G.version}function Yn(t,e={}){return oe(t,e.stage??"lex")}function Xn(t,e={}){let r=H(t,"bitmark","json",e.mode??"optimized",false,2,1,e.includeUnknownProperties??false,false);if(r.startsWith("error:"))throw new Error(r.slice(6).trim());return JSON.parse(r)}function qn(t,e={}){let r=t.map(o=>o!==null&&typeof o=="object"&&"bit"in o&&typeof o.bit=="object"?o:{bit:o}),n=H(JSON.stringify(r),"json","bitmark",e.mode??"optimized",false,2,1,false,false);if(n.startsWith("error:"))throw new Error(n.slice(6).trim());return n}function Qn(t,e={}){return H(t,e.inputFormat??"auto",e.outputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1,e.includeUnknownProperties??false,e.mappingReport??false)}function Zn(t,e={}){return ue(t,e.inputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function er(t){let e=ce(t);if(e.startsWith("error:"))throw new Error(e);return Number.parseInt(e,10)}function tr(t){return JSON.parse(le(t))}function nr(t,e={}){if(e.preHook||e.postHook)return Ee(U,t,e);let r=e.patch===void 0?"":typeof e.patch=="string"?e.patch:JSON.stringify(e.patch);return pe(t,e.inputFormat??"auto",e.outputFormat??"json",e.mode??"optimized",r,e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function rr(t,e={}){return Pe(U,t,e,Be)}function or(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return ie(t,r,n)}function ir(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return se(t,r,n)}function sr(t={}){let e=t.infoType??"list",r=t.format??"text",n=t.bit??"",o=t.pretty??false,s=t.indent??2;return ae(e,r,n,o,s)}export{Xn as bitmarkToObjects,or as breakscapeText,Zn as canonicalize,Qn as convert,er as countBits,sr as info,$n as init,ve as initSync,ot as legacy,Yn as lex,qn as objectsToBitmark,At as patchEntry,tr as splitBits,nr as transform,rr as transformParallel,ir as unbreakscapeText,Kn as version};//# sourceMappingURL=bitmark-parser.min.js.map
|
|
1
|
+
var we=Object.defineProperty;var st=(t,e,r)=>e in t?we(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var he=(t,e)=>{for(var r in e)we(t,r,{get:e[r],enumerable:true});};var F=(t,e,r)=>st(t,typeof e!="symbol"?e+"":e,r);var U={};he(U,{breakscape_text:()=>ie,canonicalize:()=>ue,convert:()=>H,convert_text:()=>lt,count_bits:()=>ce,default:()=>de,info:()=>ae,initSync:()=>ve,is_bitmark:()=>pt,lex:()=>oe,prettify:()=>ct,split_bits:()=>le,split_json_bits:()=>ut,transform:()=>pe,unbreakscape_text:()=>se});var s,b=0,M=null;function z(){return (M===null||M.byteLength===0)&&(M=new Uint8Array(s.memory.buffer)),M}var $=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},at=typeof $.encodeInto=="function"?function(t,e){return $.encodeInto(t,e)}:function(t,e){let r=$.encode(t);return e.set(r),{read:t.length,written:r.length}};function _(t,e,r){if(r===void 0){let p=$.encode(t),u=e(p.length,1)>>>0;return z().subarray(u,u+p.length).set(p),b=p.length,u}let n=t.length,o=e(n,1)>>>0,a=z(),i=0;for(;i<n;i++){let p=t.charCodeAt(i);if(p>127)break;a[o+i]=p;}if(i!==n){i!==0&&(t=t.slice(i)),o=r(o,n,n=i+t.length*3,1)>>>0;let p=z().subarray(o+i,o+n),u=at(t,p);i+=u.written,o=r(o,n,i,1)>>>0;}return b=i,o}var J=null;function w(){return (J===null||J.buffer.detached===true||J.buffer.detached===void 0&&J.buffer!==s.memory.buffer)&&(J=new DataView(s.memory.buffer)),J}var Oe=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&Oe.decode();function S(t,e){return t=t>>>0,Oe.decode(z().subarray(t,t+e))}function oe(t,e){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),u=b,c=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),l=b;s.lex(i,p,u,c,l);var o=w().getInt32(i+0,!0),a=w().getInt32(i+4,!0);return r=o,n=a,S(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function ie(t,e,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),c=b,l=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),m=b,f=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),y=b;s.breakscape_text(p,u,c,l,m,f,y);var a=w().getInt32(p+0,!0),i=w().getInt32(p+4,!0);return n=a,o=i,S(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function se(t,e,r){let n,o;try{let p=s.__wbindgen_add_to_stack_pointer(-16),u=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),c=b,l=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),m=b,f=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),y=b;s.unbreakscape_text(p,u,c,l,m,f,y);var a=w().getInt32(p+0,!0),i=w().getInt32(p+4,!0);return n=a,o=i,S(a,i)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(n,o,1);}}function ae(t,e,r,n,o,a,i,p){let u,c;try{let f=s.__wbindgen_add_to_stack_pointer(-16),y=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),T=b;s.info(f,y,x,k,d,g,T,n,o,a,i,p);var l=w().getInt32(f+0,!0),m=w().getInt32(f+4,!0);return u=l,c=m,S(l,m)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(u,c,1);}}function pe(t,e,r,n,o,a,i,p){let u,c;try{let f=s.__wbindgen_add_to_stack_pointer(-16),y=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b,g=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),T=b,j=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),A=b,re=_(o,s.__wbindgen_export_0,s.__wbindgen_export_1),it=b;s.transform(f,y,x,k,d,g,T,j,A,re,it,a,i,p);var l=w().getInt32(f+0,!0),m=w().getInt32(f+4,!0);return u=l,c=m,S(l,m)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(u,c,1);}}function H(t,e,r,n,o,a,i,p,u){let c,l;try{let y=s.__wbindgen_add_to_stack_pointer(-16),x=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),k=b,d=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),g=b,T=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),j=b,A=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),re=b;s.convert(y,x,k,d,g,T,j,A,re,o,a,i,p,u);var m=w().getInt32(y+0,!0),f=w().getInt32(y+4,!0);return c=m,l=f,S(m,f)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(c,l,1);}}function ue(t,e,r,n,o,a){let i,p;try{let l=s.__wbindgen_add_to_stack_pointer(-16),m=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),f=b,y=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b;s.canonicalize(l,m,f,y,x,k,d,n,o,a);var u=w().getInt32(l+0,!0),c=w().getInt32(l+4,!0);return i=u,p=c,S(u,c)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(i,p,1);}}function ce(t){let e,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),p=b;s.count_bits(a,i,p);var n=w().getInt32(a+0,!0),o=w().getInt32(a+4,!0);return e=n,r=o,S(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(e,r,1);}}function le(t){let e,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),p=b;s.split_bits(a,i,p);var n=w().getInt32(a+0,!0),o=w().getInt32(a+4,!0);return e=n,r=o,S(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(e,r,1);}}function pt(t){let e=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),r=b;return s.is_bitmark(e,r)!==0}function ut(t){let e,r;try{let a=s.__wbindgen_add_to_stack_pointer(-16),i=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),p=b;s.split_json_bits(a,i,p);var n=w().getInt32(a+0,!0),o=w().getInt32(a+4,!0);return e=n,r=o,S(n,o)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(e,r,1);}}function ct(t,e){let r,n;try{let i=s.__wbindgen_add_to_stack_pointer(-16),p=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),u=b;s.prettify(i,p,u,e);var o=w().getInt32(i+0,!0),a=w().getInt32(i+4,!0);return r=o,n=a,S(o,a)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(r,n,1);}}function lt(t,e,r,n){let o,a;try{let u=s.__wbindgen_add_to_stack_pointer(-16),c=_(t,s.__wbindgen_export_0,s.__wbindgen_export_1),l=b,m=_(e,s.__wbindgen_export_0,s.__wbindgen_export_1),f=b,y=_(r,s.__wbindgen_export_0,s.__wbindgen_export_1),x=b,k=_(n,s.__wbindgen_export_0,s.__wbindgen_export_1),d=b;s.convert_text(u,c,l,m,f,y,x,k,d);var i=w().getInt32(u+0,!0),p=w().getInt32(u+4,!0);return o=i,a=p,S(i,p)}finally{s.__wbindgen_add_to_stack_pointer(16),s.__wbindgen_export_2(o,a,1);}}async function dt(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(n){if(t.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",n);else throw n}let r=await t.arrayBuffer();return await WebAssembly.instantiate(r,e)}else {let r=await WebAssembly.instantiate(t,e);return r instanceof WebAssembly.Instance?{instance:r,module:t}:r}}function Te(){let t={};return t.wbg={},t}function Fe(t,e){return s=t.exports,Re.__wbindgen_wasm_module=e,J=null,M=null,s}function ve(t){if(s!==void 0)return s;typeof t<"u"&&(Object.getPrototypeOf(t)===Object.prototype?{module:t}=t:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let e=Te();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));let r=new WebAssembly.Instance(t,e);return Fe(r,t)}async function Re(t){if(s!==void 0)return s;typeof t<"u"&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof t>"u"&&(t=new URL("bitmark_wasm_bg.wasm",import.meta.url));let e=Te();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:n}=await dt(await t,e);return Fe(r,n)}var de=Re;var G={version:"6.9.0"};function N(t){return t.startsWith("error:")}function K(t){let e=t instanceof Error?t.message:String(t);return e.startsWith("error:")?e:`error: ${e}`}function mt(t){let e=t.trim();return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):t}function ft(t){if(t===void 0)return [];if(typeof t=="string"){let e=t.trim();return e===""?[]:JSON.parse(e)}return t}function gt(t,e,r){if(r){let a=t.split_bits(e);if(N(a))throw new Error(a);let i=JSON.parse(a);return i.map(p=>({view:{format:"bitmark",index:p.index,total:i.length,source:p.source},source:p.source}))}let n=t.split_json_bits(e);if(N(n))throw new Error(n);let o=JSON.parse(n);return o.map((a,i)=>({view:{format:"json",index:i,total:o.length,bit:a.bit??{}},source:JSON.stringify([a])}))}function me(t,e,r){let n=r.mode??"optimized",o=r.outputFormat??"json",a=r.spacesAroundValues??1,i=r.indent??2,p=r.pretty??false,u=r.inputFormat??"auto",c=u==="bitmark"||u!=="json"&&t.is_bitmark(e),l=c?"bitmark":"json",m=ft(r.patch),f=gt(t,e,c),y=f.length,x=[],k=[];for(let d=0;d<y;d++){let{view:g,source:T}=f[d];g.index=d,g.total=y;let j=r.preHook?r.preHook(g)||{}:{};if(j.drop)continue;let A=j.patches?[...m,...j.patches]:m;x.push({index:d,source:T,inputFormat:l,outputFormat:j.outputFormat??o,mode:n,patchJson:JSON.stringify(A),spacesAroundValues:a}),k.push(g);}return {jobs:x,views:k,output:o,pretty:p,indent:i}}function bt(t,e){let r=t.transform(e.source,e.inputFormat,e.outputFormat,e.mode,e.patchJson,false,2,e.spacesAroundValues);return N(r)?r:e.outputFormat==="json"?mt(r):r}function fe(t,e,r,n,o){if(r==="bitmark"||r==="text")return e.join(`
|
|
2
|
+
`);let a=`[${e.join(",")}]`;return n?t.prettify(a,o):a}function Ee(t,e,r){let n;try{n=me(t,e,r);}catch(a){return K(a)}let o=[];for(let a=0;a<n.jobs.length;a++){let i=bt(t,n.jobs[a]);if(N(i))return i;r.postHook?.(n.views[a],i),o.push(i);}return fe(t,o,n.output,n.pretty,n.indent)}async function Pe(t,e,r,n){let o;try{o=me(t,e,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(N(a[i]))return a[i];r.postHook?.(o.views[i],a[i]);}return fe(t,a,o.output,o.pretty,o.indent)}function Be(t,e){if(t.length===0)return Promise.resolve([]);let r=Math.max(1,Math.min(e,t.length)),n=new URL("./worker-entry.js",import.meta.url);return new Promise((o,a)=>{let i=new Array(t.length),p=0,u=0,c=false,l=[],m=()=>{for(let x of l)x.terminate();},f=x=>{c||(c=true,m(),a(x));},y=x=>{if(c||p>=t.length)return;let k=p++;x.postMessage({id:k,job:t[k]});};for(let x=0;x<r;x++){let k=new Worker(n,{type:"module"});l.push(k),k.onmessage=d=>{let g=d.data;if(!c){if(!g.ok){f(new Error(g.error??"worker job failed"));return}if(i[g.id]=g.element,u++,u===t.length){c=true,m(),o(i);return}y(k);}},k.onerror=d=>f(new Error(d.message||"worker error"));}for(let x of l)y(x);})}var ge;function Se(t){ge=t;}function h(){if(!ge)throw new Error("legacy API not initialised: the WASM module has not been provided (browser consumers must call init() first)");return ge}var ot={};he(ot,{Ast:()=>Ge,BitType:()=>Ve,BitmarkFileGenerator:()=>$e,BitmarkGenerator:()=>De,BitmarkParser:()=>Ze,BitmarkParserGenerator:()=>te,BitmarkParserType:()=>Rt,BitmarkStringGenerator:()=>ze,BitmarkVersion:()=>Ft,BodyTextFormat:()=>Bt,BoundingBoxIndex:()=>Ue,Builder:()=>ee,CardSetVersion:()=>vt,FileWriter:()=>nt,HtmlTableGenerator:()=>qe,HtmlTableParser:()=>Qe,InfoFormat:()=>Pt,InfoType:()=>Et,Input:()=>ht,InputFormat:()=>Tt,JsonFileGenerator:()=>Xe,JsonGenerator:()=>Ke,JsonParser:()=>et,JsonStringGenerator:()=>Ye,LegacyUnsupportedError:()=>C,NodeType:()=>He,Output:()=>Ot,ResourceBuilder:()=>ne,StreamWriter:()=>rt,StringWriter:()=>tt,TextLocation:()=>St,TextMarkType:()=>Ne,TextNodeType:()=>Ce,bitmarkTextParse:()=>Je,isPseudoAst:()=>je});var C=class extends Error{constructor(e){super(e),this.name="LegacyUnsupportedError";}};function L(t,e){throw new C(`'${t}' is not supported by the @gmb/bitmark-parser legacy API`+(e?`: ${e}`:""))}function I(t,e){throw new C(`Option '${t}' is not supported by the @gmb/bitmark-parser legacy API`+(e?`: ${e}`:""))}var be="bitmark v2 output is not supported (this parser is bitmark v3 only)";function ye(t){t.bitmarkVersion===2&&I("bitmarkVersion: 2",be);}function X(t){t.explicitTextFormat&&I("bitmarkOptions.explicitTextFormat"),t.cardSetVersion===1&&I("bitmarkOptions.cardSetVersion: 1",be),t.debugGenerationInline&&I("bitmarkOptions.debugGenerationInline"),t.noBreakscaping&&I("bitmarkOptions.noBreakscaping");}function q(t){t.textAsPlainText&&I("jsonOptions.textAsPlainText",be),t.debugGenerationInline&&I("jsonOptions.debugGenerationInline");}function W(t){return t===true?{pretty:true,indent:2}:typeof t=="number"&&t>0?{pretty:true,indent:t}:{pretty:false,indent:2}}function Q(t){return t===void 0||t===true?1:t===false?0:Math.max(0,Math.min(10,t))}function Z(t){switch(t){case "text":case "latex":case "json":case "xml":return "plainText";default:return "bitmark++"}}var Ie=Symbol.for("@gmb/bitmark-parser/legacy-pseudo-ast");function V(t){let e={bits:t};return Object.defineProperty(e,Ie,{value:true,enumerable:false}),e}function je(t){return t!==null&&typeof t=="object"&&(Ie in t||Array.isArray(t.bits))}var Ae={"extractor-image":{key:"images",resourceType:"image"},"extractor-image-collapsible":{key:"images",resourceType:"image"},"images-logo-grave":{key:"logos",resourceType:"image"},"prototype-images":{key:"images",resourceType:"image"}};var _e=Symbol.for("@gmb/bitmark-parser/legacy-built-bit-parser"),_t={bitType:"type",textFormat:"format",flashcards:"cards",markConfig:"marks"},xt={"bitmark--":"bitmark++","bitmark+":"bitmark++"},kt={bitmark:"bitmark++",text:"text",json:"json",latex:"latex",xml:"xml"},wt=["title","subtitle","item","lead","pageNumber","marginNumber","hint","instruction","caption"],ee=class{buildBitmark(e){let r=V(e.bits??[]);return e.errors!==void 0&&(r.errors=e.errors),r}buildBit(e,r){let n=h(),o={...e},a=o.bitType,i=this.getBitConfig(a),p={};p.type=a,o.isCommented&&(p.type="_comment",p.originalType=a),delete o.bitType,delete o.isCommented;let u=o.textFormat;u!==void 0?(p.format=xt[u]??u,delete o.textFormat):p.format=kt[i.bodyFormat??""]??"bitmark++",delete o.resourceType;let c=o.body;c!=null&&typeof c=="object"&&"body"in c&&(p.body=c.body,delete o.body),o.example!==void 0?(p.isExample=true,p.example=o.example,delete o.example,delete o.__isDefaultExample):o.__isDefaultExample&&(p.isExample=true,delete o.__isDefaultExample);let l=o.resources;if(l!==void 0&&a!==void 0){let d=Array.isArray(l)?l:[l],g=Ae[a];g?p[g.key]=d.filter(T=>T!==null&&typeof T=="object"&&T.type===g.resourceType):d.length>=1&&(p.resource=d[0]),delete o.resources;}let m=o.parser;delete o.parser;let f=o.extraProperties;delete o.extraProperties;for(let[d,g]of Object.entries(o))g!==void 0&&(p[_t[d]??d]=g);if(f)for(let[d,g]of Object.entries(f))d in p||(p[d]=g);this.parseStringTexts(p);let y=n.convert(JSON.stringify([{bit:p}]),"json","json","optimized",false,2,1,false,false);if(y.startsWith("error:"))throw new Error(y.slice(6).trim());let k=JSON.parse(y)[0]?.bit??p;for(let[d,g]of Object.entries(p))d in k||g===false||g===""||g===null||Array.isArray(g)&&g.length===0||(k[d]=g);return m!==void 0&&Object.defineProperty(k,_e,{value:m,enumerable:false}),k}buildHighlight(e,r){if(!r)return;let n={...r},o=n.attrs;return o&&Object.assign(n,o),{type:"highlight",texts:Array.isArray(n.texts)?n.texts.filter(p=>p!=null).map(p=>({text:p.text??"",isCorrect:p.isCorrect??false,isHighlighted:p.isHighlighted??false,...Le(p,["text","isCorrect","isHighlighted"])})):[],prefix:n.prefix??"",postfix:n.postfix??"",...Le(n,["type","texts","prefix","postfix","attrs"]),attrs:{}}}parseStringTexts(e){let r=h(),n=(i,p)=>{if(i==="")return i;let u=r.convert_text(i,"textToAst","bitmark++",p);try{return JSON.parse(u)}catch{return i}},o=e.format,a=o===void 0||o==="bitmark++"||o==="bitmark+";if(typeof e.body=="string")if(o==="json")try{e.body=JSON.parse(e.body);}catch{e.body=null;}else a&&(e.body=n(e.body,"body"));for(let i of wt){let p=e[i];typeof p=="string"&&(e[i]=n(p,"tag"));}}getBitConfig(e){let r=h();if(e!==void 0)try{let n=JSON.parse(r.info("bit","json",e,!1,2,!1,!1,!0));if(n.error===void 0)return {bodyFormat:n.body?.format}}catch{}throw new Error(`No config found for bit: ${e}`)}};function Le(t,e){let r={};for(let[n,o]of Object.entries(t))o!==void 0&&!e.includes(n)&&(r[n]=o);return r}var te=class{version(){return G.version}convert(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);ye(n),X(a),q(o),this.checkBrowserFileWrite(n.outputFile);let i=h(),{source:p,isBitmark:u}=this.resolveInput(e,n.inputFormat),c=n.outputFormat??(u?"json":"bitmark"),l=c==="ast"?"json":c,{pretty:m,indent:f}=W(o.prettify),y=l==="bitmark"?W(a.prettifyJson):{pretty:m,indent:f},x=Q(a.spacesAroundValues),k=!o.excludeUnknownProperties,d=i.convert(p,u?"bitmark":"json",l,"optimized",y.pretty,y.indent,x,k,false);if(this.throwOnError(d),c==="bitmark"||c==="text")return this.deliver(d,n.outputFile,n.fileOptions);if(c==="json")return n.outputFile?this.deliver(d,n.outputFile,n.fileOptions):m||o.stringify?d:JSON.parse(d);let g=V(JSON.parse(d));return n.outputFile?this.deliver(JSON.stringify(g),n.outputFile,n.fileOptions):g}upgrade(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);ye(n),X(a),q(o),this.checkBrowserFileWrite(n.outputFile);let i=h(),{source:p,isBitmark:u}=this.resolveInput(e,n.inputFormat),{pretty:c,indent:l}=W(u?a.prettifyJson:o.prettify),m=Q(a.spacesAroundValues),f=i.canonicalize(p,u?"bitmark":"json","optimized",c,l,m);return this.throwOnError(f),u?this.deliver(f,n.outputFile,n.fileOptions):n.outputFile?this.deliver(f,n.outputFile,n.fileOptions):c||o.stringify?f:JSON.parse(f)}info(e){let r=Object.assign({},e),n=h(),o=r.type??"list",a=r.outputFormat??"text",{pretty:i,indent:p}=W(r.prettify),u=a==="pojo"?"json":a,c=n.info(o,u,r.bit??"",i,p,false,false,true);return this.throwOnError(c),a==="pojo"?JSON.parse(c):c}generateConfig(e){L("BitmarkParserGenerator.generateConfig","bpg-internal development tool");}convertHtmlTable(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions),a=Object.assign({},n.bitmarkOptions);X(a),q(o),n.keepUnknownTags&&I("keepUnknownTags"),n.noBreakscaping&&I("noBreakscaping"),this.checkBrowserFileWrite(n.outputFile);let i=h(),p=typeof e=="string"?this.maybeReadFile(e,void 0):"";if(!(n.inputFormat==="html"||n.inputFormat===void 0&&typeof e=="string"&&/<table[\s>]/iu.test(p))){let{source:T,isBitmark:j}=this.resolveInput(e,void 0),A=i.convert(T,j?"bitmark":"json","html","optimized",false,2,1,false,false);return this.throwOnError(A),this.deliver(xe(A).join(`
|
|
3
|
+
`),n.outputFile,n.fileOptions)}let c=n.tableFormat==="table"?"table":"table-extended",l=xe(p).map(T=>`<bitmark-bit data-type="${c}" data-format="bitmark++">${T}</bitmark-bit>`).join(""),m=n.outputFormat??"bitmark",{pretty:f,indent:y}=W(o.prettify),x=Q(a.spacesAroundValues);if(m==="html"){let T=i.convert(l,"html","html","optimized",false,2,1,false,false);return this.throwOnError(T),this.deliver(xe(T).join(`
|
|
4
|
+
`),n.outputFile,n.fileOptions)}let k=m==="ast"?"json":m,d=i.convert(l,"html",k,"optimized",f,y,x,false,false);if(this.throwOnError(d),m==="bitmark"||m==="text")return this.deliver(d,n.outputFile,n.fileOptions);if(m==="json")return n.outputFile?this.deliver(d,n.outputFile,n.fileOptions):f||o.stringify?d:JSON.parse(d);let g=V(JSON.parse(d));return n.outputFile?this.deliver(JSON.stringify(g),n.outputFile,n.fileOptions):g}createAst(e,r){let n=Object.assign({},r),o=h(),{source:a,isBitmark:i}=this.resolveInput(e,n.inputFormat),p=o.convert(a,i?"bitmark":"json","json","optimized",false,2,1,true,false);return this.throwOnError(p),V(JSON.parse(p))}breakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),a=this.maybeReadFile(e,n.inputFormat),i=o.breakscape_text(a,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}unbreakscapeText(e,r){if(!e)return e;let n=Object.assign({},r);this.checkBrowserFileWrite(n.outputFile);let o=h(),a=this.maybeReadFile(e,n.inputFormat),i=o.unbreakscape_text(a,Z(n.textFormat),n.textLocation??"body");return this.deliver(i,n.outputFile,n.fileOptions)}convertText(e,r){let n=Object.assign({},r),o=Object.assign({},n.jsonOptions);this.checkBrowserFileWrite(n.outputFile);let a=h(),i=n.textFormat===void 0||Z(n.textFormat)==="bitmark++",p=n.textLocation??"body",u,c;if(typeof e=="string"?(u=this.maybeReadFile(e,n.inputFormat),c=this.parseTextAstString(u)):(u=JSON.stringify(e),c=Array.isArray(e)?e:void 0),c!==void 0){let x=i?a.convert_text(JSON.stringify(c),"astToText","bitmark++",p):a.convert_text(JSON.stringify(c),"astToPlainText","plainText",p);return this.throwOnError(x),this.deliver(x,n.outputFile,n.fileOptions)}let l=a.convert_text(u,"textToAst",i?"bitmark++":"plainText","body");this.throwOnError(l);let{pretty:m,indent:f}=W(o.prettify),y=m?a.prettify(l,f):l;return n.outputFile?this.deliver(y,n.outputFile,n.fileOptions):m?y:JSON.parse(l)}textAstToPlainText(e,r){let o=h().convert_text(typeof e=="string"?e:JSON.stringify(e),"astToPlainText","bitmark++","body");return this.throwOnError(o),o}extractPlainText(e,r){let n=r?.inputFormat,o=h();if(n==="plainText")return typeof e=="string"?String(e):"";if(n==="bitmarkText"){let u=o.convert_text(String(e),"textToAst","bitmark++","body"),c=o.convert_text(u,"astToPlainText","bitmark++","body");return this.throwOnError(c),c}if(typeof e=="string"&&this.parseTextAstString(e)===void 0&&!o.is_bitmark(e)&&!(()=>{try{return JSON.parse(e),!0}catch{return false}})())return this.extractPlainText(e,{inputFormat:"bitmarkText"});let{source:a,isBitmark:i}=this.resolveInput(e,void 0),p=o.convert(a,i?"bitmark":"json","text","optimized",false,2,1,false,false);return this.throwOnError(p),p}parseTextAstString(e){let r=e.trim();if(r.startsWith("["))try{let n=JSON.parse(r);if(Array.isArray(n)&&n.every(o=>o!==null&&typeof o=="object"&&"type"in o))return n}catch{}}resolveInput(e,r){if(typeof e!="string"){let a=this.jsonEntries(e);return {source:JSON.stringify(a?a.map(i=>this.toWrapperEntry(i)):e),isBitmark:false}}let n=this.maybeReadFile(e,r);if(h().is_bitmark(n))return {source:n,isBitmark:true};try{let a=JSON.parse(n),i=this.jsonEntries(a);if(i)return {source:JSON.stringify(i.map(p=>this.toWrapperEntry(p))),isBitmark:!1}}catch{return {source:n,isBitmark:true}}return {source:n,isBitmark:false}}jsonEntries(e){if(Array.isArray(e))return e;if(e!==null&&typeof e=="object"){let r=e;if(Array.isArray(r.bits))return r.bits;if("bit"in r)return [r];if(typeof r.type=="string")return [{bit:r}]}}toWrapperEntry(e){if(e!==null&&typeof e=="object"&&"bit"in e)return e;let r={bit:e},n=e?.[_e];return n!==void 0&&(r.parser=n),r}maybeReadFile(e,r){if(r==="string")return e;return e;}checkBrowserFileWrite(e){if(e&&true)throw new Error("Cannot write to file in browser environment")}deliver(e,r,n){if(!r)return e;throw new Error("Cannot write to file in browser environment");}throwOnError(e){if(e.startsWith("error:"))throw new Error(e.slice(6).trim())}};function xe(t){let e=[],r=t.toLowerCase(),n=0;for(;;){let o=r.indexOf("<table",n);if(o===-1)break;let a=0,i=o,p=-1;for(;i<t.length;){let u=r.indexOf("<table",i),c=r.indexOf("</table",i);if(c===-1)break;if(u!==-1&&u<c)a++,i=u+6;else {a--;let l=r.indexOf(">",c);if(i=l===-1?t.length:l+1,a===0){p=i;break}}}if(p===-1)break;e.push(t.slice(o,p)),n=p;}return e}function Je(t){let e=h().convert_text(t,"textToAst","bitmark++","body");if(e.startsWith("error:"))throw new Error(e.slice(6).trim());return JSON.parse(e)}var E={imageResource:{type:"image",key:"image",valueField:"src"},imageLinkResource:{type:"image-link",key:"imageLink",valueField:"url"},audioResource:{type:"audio",key:"audio",valueField:"src"},audioEmbedResource:{type:"audio-embed",key:"audioEmbed",valueField:"src"},audioLinkResource:{type:"audio-link",key:"audioLink",valueField:"url"},videoResource:{type:"video",key:"video",valueField:"src"},videoEmbedResource:{type:"video-embed",key:"videoEmbed",valueField:"url"},videoLinkResource:{type:"video-link",key:"videoLink",valueField:"url"},stillImageFilmEmbedResource:{type:"still-image-film-embed",key:"stillImageFilmEmbed",valueField:"url"},stillImageFilmLinkResource:{type:"still-image-film-link",key:"stillImageFilmLink",valueField:"url"},articleResource:{type:"article",key:"article",valueField:"body"},documentResource:{type:"document",key:"document",valueField:"url"},documentEmbedResource:{type:"document-embed",key:"documentEmbed",valueField:"url"},documentLinkResource:{type:"document-link",key:"documentLink",valueField:"url"},documentDownloadResource:{type:"document-download",key:"documentDownload",valueField:"url"},appLinkResource:{type:"app-link",key:"appLink",valueField:"url"},websiteLinkResource:{type:"website-link",key:"websiteLink",valueField:"url"}};function O(t){return (e,r,n)=>{if(!r)return;let{value:o,...a}=r,i={[t.valueField]:o??""};for(let[p,u]of Object.entries(a))u!==void 0&&(i[p]=u);return {type:t.type,[t.key]:i}}}var We=Object.fromEntries(Object.values(E).map(t=>[t.type,t])),ne=class{constructor(){F(this,"imageResource",O(E.imageResource));F(this,"imageLinkResource",O(E.imageLinkResource));F(this,"audioResource",O(E.audioResource));F(this,"audioEmbedResource",O(E.audioEmbedResource));F(this,"audioLinkResource",O(E.audioLinkResource));F(this,"videoResource",O(E.videoResource));F(this,"videoEmbedResource",O(E.videoEmbedResource));F(this,"videoLinkResource",O(E.videoLinkResource));F(this,"stillImageFilmEmbedResource",O(E.stillImageFilmEmbedResource));F(this,"stillImageFilmLinkResource",O(E.stillImageFilmLinkResource));F(this,"articleResource",O(E.articleResource));F(this,"documentResource",O(E.documentResource));F(this,"documentEmbedResource",O(E.documentEmbedResource));F(this,"documentLinkResource",O(E.documentLinkResource));F(this,"documentDownloadResource",O(E.documentDownloadResource));F(this,"appLinkResource",O(E.appLinkResource));F(this,"websiteLinkResource",O(E.websiteLinkResource));}resourceFromResourceJson(e,r){if(!r)return;let n=!Array.isArray(r),o=n?[r]:r,a=[];for(let i of o){let p=We[i.type];if(!p)continue;let u=i[p.key]??{},{[p.valueField]:c,...l}=u,m=O(p)(void 0,{value:c,...l});m&&a.push(m);}if(a.length!==0)return n?a[0]:a}resourceFromResourceDataJson(e,r,n){if(!n)return;let o=We[r];if(!o)return;let a=typeof n=="string"?n:void 0,i=typeof n=="object"?n:{},{url:p,src:u,body:c,...l}=i,m=p??u??c??a;return O(o)(e,{value:m,...l})}};var ht={string:"string",file:"file"},Ot={bitmark:"bitmark",json:"json",ast:"ast",text:"text"},Tt={bitmark:"bitmark",bitmarkText:"bitmarkText",plainText:"plainText",html:"html"},Ft={v2:2,v3:3},vt={v1:1,v2:2},Rt={peggy:"peggy"},Et={list:"list",deprecated:"deprecated",all:"all",bit:"bit"},Pt={text:"text",json:"json",pojo:"pojo"},Bt={plainText:"text",latex:"latex",json:"json",xml:"xml",bitmarkPlusPlus:"bitmark++"},St={tag:"tag",body:"body"};var Ne={bold:"bold",light:"light",italic:"italic",highlight:"highlight",highlightOrange:"highlightOrange",highlightYellow:"highlightYellow",highlightGreen:"highlightGreen",highlightBlue:"highlightBlue",highlightPurple:"highlightPurple",highlightPink:"highlightPink",highlightBrown:"highlightBrown",highlightBlack:"highlightBlack",highlightWhite:"highlightWhite",highlightGray:"highlightGray",strike:"strike",subscript:"subscript",superscript:"superscript",ins:"ins",del:"del",underline:"underline",doubleUnderline:"doubleUnderline",circle:"circle",languageEmRed:"languageEmRed",languageEmOrange:"languageEmOrange",languageEmYellow:"languageEmYellow",languageEmGreen:"languageEmGreen",languageEmBlue:"languageEmBlue",languageEmPurple:"languageEmPurple",languageEmPink:"languageEmPink",languageEmBrown:"languageEmBrown",languageEmBlack:"languageEmBlack",languageEmWhite:"languageEmWhite",languageEmGray:"languageEmGray",languageEm:"languageEm",userUnderline:"userUnderline",userDoubleUnderline:"userDoubleUnderline",userStrike:"userStrike",userCircle:"userCircle",userHighlight:"userHighlight",notranslate:"notranslate",link:"link",ref:"ref",xref:"xref",extref:"extref",footnote:"footnote",footnoteStar:"footnote*",symbol:"symbol",var:"var",code:"code",timer:"timer",duration:"duration",color:"color",colorPicker:"colorPicker",comment:"comment"},Ce={text:"text",hardBreak:"hardBreak",paragraph:"paragraph",heading:"heading",section:"section",noBulletList:"noBulletList",bulletList:"bulletList",orderedList:"orderedList",orderedListRoman:"orderedListRoman",orderedListRomanLower:"orderedListRomanLower",letteredList:"letteredList",letteredListLower:"letteredListLower",taskList:"taskList",listItem:"listItem",taskItem:"taskItem",image:"image",imageInline:"imageInline",codeBlock:"codeBlock",latex:"latex",gap:"gap",select:"select",highlight:"highlight",mark:"mark"};function It(t){return t.replace(/-([a-z0-9])/gu,(e,r)=>r.toUpperCase())}var ke;function D(){if(!ke){let t=h(),e=JSON.parse(t.info("all","json","",false,2,true,false,false)),r={_standard:"_standard"};for(let{name:n}of e)r[It(n)]=n;ke=r;}return ke}var Ve=new Proxy({},{get:(t,e)=>typeof e=="string"?D()[e]:void 0,has:(t,e)=>typeof e=="string"&&e in D(),ownKeys:()=>Reflect.ownKeys(D()),getOwnPropertyDescriptor:(t,e)=>typeof e=="string"&&e in D()?{value:D()[e],enumerable:true,configurable:true,writable:false}:void 0});function Me(t,e){return new Proxy({},{get:(r,n)=>n===Symbol.toPrimitive||n==="toString"||n===Symbol.toStringTag?()=>`[unsupported ${t}]`:L(t,e),has:()=>L(t,e),ownKeys:()=>L(t,e)})}var He=Me("NodeType","it names bpg's internal AST nodes; the legacy AST is bit JSON (see createAst)"),Ue=Me("BoundingBoxIndex","bpg-internal bounding-box utility");function P(t,e){return class{constructor(){L(t,e);}}}var jt="the legacy AST is bit JSON, not bpg's internal node model; walking it with bpg NodeType names would silently misbehave",B="internal class of bpg's TS implementation",Ge=P("Ast",jt),De=P("BitmarkGenerator",B),ze=P("BitmarkStringGenerator",B),$e=P("BitmarkFileGenerator",B),Ke=P("JsonGenerator",B),Ye=P("JsonStringGenerator",B),Xe=P("JsonFileGenerator",B),qe=P("HtmlTableGenerator",B),Qe=P("HtmlTableParser",B),Ze=P("BitmarkParser",B),et=P("JsonParser",B),tt=P("StringWriter",B),nt=P("FileWriter",B),rt=P("StreamWriter",B);function At(t,e,r){return r===void 0?{path:t,op:e}:{path:t,op:e,value:r}}Se(U);async function $n(t){return typeof t>"u"&&(t=new URL(`bitmark_wasm_bg.wasm?v=${G.version}`,import.meta.url)),de(t)}function Kn(){return G.version}function Yn(t,e={}){return oe(t,e.stage??"lex")}function Xn(t,e={}){let r=H(t,"bitmark","json",e.mode??"optimized",false,2,1,e.includeUnknownProperties??false,false);if(r.startsWith("error:"))throw new Error(r.slice(6).trim());return JSON.parse(r)}function qn(t,e={}){let r=t.map(o=>o!==null&&typeof o=="object"&&"bit"in o&&typeof o.bit=="object"?o:{bit:o}),n=H(JSON.stringify(r),"json","bitmark",e.mode??"optimized",false,2,1,false,false);if(n.startsWith("error:"))throw new Error(n.slice(6).trim());return n}function Qn(t,e={}){return H(t,e.inputFormat??"auto",e.outputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1,e.includeUnknownProperties??false,e.mappingReport??false)}function Zn(t,e={}){return ue(t,e.inputFormat??"auto",e.mode??"optimized",e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function er(t){let e=ce(t);if(e.startsWith("error:"))throw new Error(e);return Number.parseInt(e,10)}function tr(t){return JSON.parse(le(t))}function nr(t,e={}){if(e.preHook||e.postHook)return Ee(U,t,e);let r=e.patch===void 0?"":typeof e.patch=="string"?e.patch:JSON.stringify(e.patch);return pe(t,e.inputFormat??"auto",e.outputFormat??"json",e.mode??"optimized",r,e.pretty??false,e.indent??2,e.spacesAroundValues??1)}function rr(t,e={}){return Pe(U,t,e,Be)}function or(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return ie(t,r,n)}function ir(t,e={}){let r=e.format??"bitmark++",n=e.location??"body";return se(t,r,n)}function sr(t={}){let e=t.infoType??"list",r=t.format??"text",n=t.bit??"",o=t.pretty??false,a=t.indent??2,i=t.includeDeprecated??false,p=t.onlyDeprecated??false,u=t.full??false;return ae(e,r,n,o,a,i,p,u)}export{Xn as bitmarkToObjects,or as breakscapeText,Zn as canonicalize,Qn as convert,er as countBits,sr as info,$n as init,ve as initSync,ot as legacy,Yn as lex,qn as objectsToBitmark,At as patchEntry,tr as splitBits,nr as transform,rr as transformParallel,ir as unbreakscapeText,Kn as version};//# sourceMappingURL=bitmark-parser.min.js.map
|
|
5
5
|
//# sourceMappingURL=bitmark-parser.min.js.map
|