@gmb/bitmark-parser 6.1.3 → 6.1.4
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 +46 -0
- package/dist/browser/bitmark-parser.min.js +4 -2
- 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 +1091 -1
- package/dist/browser/cjs/index.cjs.map +1 -1
- package/dist/browser/cjs/index.d.cts +1761 -1
- package/dist/browser/esm/bitmark_wasm_bg.wasm +0 -0
- package/dist/browser/esm/index.d.ts +1761 -1
- package/dist/browser/esm/index.js +1090 -1
- package/dist/browser/esm/index.js.map +1 -1
- package/dist/browser/esm/worker-entry.js.map +1 -1
- package/dist/index.cjs +1100 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +191 -1
- package/dist/index.d.ts +191 -1
- package/dist/index.js +1092 -3
- package/dist/index.js.map +1 -1
- package/dist/legacy.cjs +1170 -0
- package/dist/legacy.cjs.map +1 -0
- package/dist/legacy.d.cts +1568 -0
- package/dist/legacy.d.ts +1568 -0
- package/dist/legacy.js +1095 -0
- package/dist/legacy.js.map +1 -0
- package/package.json +13 -7
- package/wasm/bitmark_wasm.d.ts +10 -0
- package/wasm/bitmark_wasm.js +39 -0
- package/wasm/bitmark_wasm_bg.wasm +0 -0
- package/wasm/bitmark_wasm_bg.wasm.d.ts +1 -0
- package/wasm/package.json +1 -1
package/README.md
CHANGED
|
@@ -102,6 +102,52 @@ Return the library version string.
|
|
|
102
102
|
|
|
103
103
|
Generate bitmark text from JSON. **Not yet implemented** — throws an error.
|
|
104
104
|
|
|
105
|
+
## Legacy API (bpg-compatible)
|
|
106
|
+
|
|
107
|
+
A compatibility facade for consumers migrating from
|
|
108
|
+
`@gmb/bitmark-parser-generator` (bpg v5.31.x). Only the import changes:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
// before: import { BitmarkParserGenerator } from "@gmb/bitmark-parser-generator";
|
|
112
|
+
import { BitmarkParserGenerator } from "@gmb/bitmark-parser/legacy";
|
|
113
|
+
// or: import { legacy } from "@gmb/bitmark-parser";
|
|
114
|
+
|
|
115
|
+
const bpg = new BitmarkParserGenerator();
|
|
116
|
+
const json = bpg.convert("[.article]\nHello **world**", { outputFormat: "json" });
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Supported (bpg-compatible signatures and return shapes): `convert`,
|
|
120
|
+
`upgrade`, `info`, `version`, `breakscapeText` / `unbreakscapeText`,
|
|
121
|
+
`convertText`, `textAstToPlainText`, `extractPlainText`, `convertHtmlTable`, `createAst`,
|
|
122
|
+
`bitmarkTextParse`, the `Builder` / `ResourceBuilder` classes, the
|
|
123
|
+
`Input` / `Output` / `InputFormat` / `BitType` (config-derived) /
|
|
124
|
+
`TextMarkType` / `TextNodeType` enums, and the option / JSON model types
|
|
125
|
+
(vendored from bpg, exposed only via `legacy`). Node file input/output
|
|
126
|
+
(`Input.file`, `outputFile`) works as in bpg; the browser build throws on
|
|
127
|
+
file writes, as bpg does.
|
|
128
|
+
|
|
129
|
+
Differences (all loud, never silent):
|
|
130
|
+
|
|
131
|
+
- **bitmark v3 only** — `bitmarkVersion: 2`, `cardSetVersion: 1` and
|
|
132
|
+
`jsonOptions.textAsPlainText: true` throw.
|
|
133
|
+
- **Strict option policy** — options with no equivalent here throw a
|
|
134
|
+
`LegacyUnsupportedError` naming the option (`explicitTextFormat`,
|
|
135
|
+
`prettifyJson`, `noBreakscaping`, `excludeUnknownProperties`,
|
|
136
|
+
`debugGenerationInline`). Exception: `bitmarkParserType` is accepted and
|
|
137
|
+
ignored — bpg itself ignores it. `jsonOptions.enableWarnings` is accepted
|
|
138
|
+
(parser warnings are always carried in the output envelope).
|
|
139
|
+
- **The AST is bit JSON** — `createAst` / `Output.ast` /
|
|
140
|
+
`Builder.buildBit` produce the bit JSON ("pseudo-AST"), not bpg's
|
|
141
|
+
internal TS node model. It round-trips through `convert`, but bpg's
|
|
142
|
+
`Ast` walker (and the generator/parser/writer internals) throw as
|
|
143
|
+
unsupported.
|
|
144
|
+
- **`convertHtmlTable`** converts HTML `<table>` markup ↔ table bits via
|
|
145
|
+
the core's html mapping (the `<bitmark-bit>` envelope is added/stripped
|
|
146
|
+
at the boundary). The markup produced *inside* `<table>` follows this
|
|
147
|
+
parser's html mapping and may differ from bpg's in detail.
|
|
148
|
+
`keepUnknownTags` / `noBreakscaping` throw.
|
|
149
|
+
- `version()` reports this package's version (6.x), not a bpg version.
|
|
150
|
+
|
|
105
151
|
## CLI
|
|
106
152
|
|
|
107
153
|
The CLI binary is `bitmark`.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
var _t=Object.defineProperty;var at=(t,e)=>{for(var r in e)_t(t,r,{get:e[r],enumerable:true});};var E={};at(E,{breakscape_text:()=>H,canonicalize:()=>C,convert:()=>R,count_bits:()=>D,default:()=>$,fullize:()=>U,info:()=>N,initSync:()=>tt,is_bitmark:()=>ut,lex:()=>z,optimize:()=>L,parse:()=>j,prettify:()=>dt,split_bits:()=>G,split_json_bits:()=>pt,transform:()=>M,unbreakscape_text:()=>V});var n,p=0,W=null;function A(){return (W===null||W.byteLength===0)&&(W=new Uint8Array(n.memory.buffer)),W}var B=typeof TextEncoder<"u"?new TextEncoder("utf-8"):{encode:()=>{throw Error("TextEncoder not available")}},ct=typeof B.encodeInto=="function"?function(t,e){return B.encodeInto(t,e)}:function(t,e){let r=B.encode(t);return e.set(r),{read:t.length,written:r.length}};function d(t,e,r){if(r===void 0){let a=B.encode(t),c=e(a.length,1)>>>0;return A().subarray(c,c+a.length).set(a),p=a.length,c}let i=t.length,_=e(i,1)>>>0,s=A(),o=0;for(;o<i;o++){let a=t.charCodeAt(o);if(a>127)break;s[_+o]=a;}if(o!==i){o!==0&&(t=t.slice(o)),_=r(_,i,i=o+t.length*3,1)>>>0;let a=A().subarray(_+o,_+i),c=ct(t,a);o+=c.written,_=r(_,i,o,1)>>>0;}return p=o,_}var v=null;function l(){return (v===null||v.buffer.detached===true||v.buffer.detached===void 0&&v.buffer!==n.memory.buffer)&&(v=new DataView(n.memory.buffer)),v}var X=typeof TextDecoder<"u"?new TextDecoder("utf-8",{ignoreBOM:true,fatal:true}):{decode:()=>{throw Error("TextDecoder not available")}};typeof TextDecoder<"u"&&X.decode();function k(t,e){return t=t>>>0,X.decode(A().subarray(t,t+e))}function z(t,e){let r,i;try{let o=n.__wbindgen_add_to_stack_pointer(-16),a=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),c=p,u=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p;n.lex(o,a,c,u,f);var _=l().getInt32(o+0,!0),s=l().getInt32(o+4,!0);return r=_,i=s,k(_,s)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(r,i,1);}}function j(t,e){let r,i;try{let o=n.__wbindgen_add_to_stack_pointer(-16),a=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),c=p,u=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p;n.parse(o,a,c,u,f);var _=l().getInt32(o+0,!0),s=l().getInt32(o+4,!0);return r=_,i=s,k(_,s)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(r,i,1);}}function H(t,e,r){let i,_;try{let a=n.__wbindgen_add_to_stack_pointer(-16),c=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),u=p,f=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),g=p,b=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p;n.breakscape_text(a,c,u,f,g,b,x);var s=l().getInt32(a+0,!0),o=l().getInt32(a+4,!0);return i=s,_=o,k(s,o)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(i,_,1);}}function V(t,e,r){let i,_;try{let a=n.__wbindgen_add_to_stack_pointer(-16),c=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),u=p,f=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),g=p,b=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p;n.unbreakscape_text(a,c,u,f,g,b,x);var s=l().getInt32(a+0,!0),o=l().getInt32(a+4,!0);return i=s,_=o,k(s,o)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(i,_,1);}}function pt(t){let e,r;try{let s=n.__wbindgen_add_to_stack_pointer(-16),o=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),a=p;n.split_json_bits(s,o,a);var i=l().getInt32(s+0,!0),_=l().getInt32(s+4,!0);return e=i,r=_,k(i,_)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(e,r,1);}}function dt(t,e){let r,i;try{let o=n.__wbindgen_add_to_stack_pointer(-16),a=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),c=p;n.prettify(o,a,c,e);var _=l().getInt32(o+0,!0),s=l().getInt32(o+4,!0);return r=_,i=s,k(_,s)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(r,i,1);}}function M(t,e,r,i,_,s,o,a){let c,u;try{let b=n.__wbindgen_add_to_stack_pointer(-16),x=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),m=p,w=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),y=p,h=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),T=p,O=d(i,n.__wbindgen_export_0,n.__wbindgen_export_1),J=p,it=d(_,n.__wbindgen_export_0,n.__wbindgen_export_1),st=p;n.transform(b,x,m,w,y,h,T,O,J,it,st,s,o,a);var f=l().getInt32(b+0,!0),g=l().getInt32(b+4,!0);return c=f,u=g,k(f,g)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(c,u,1);}}function N(t,e,r,i,_){let s,o;try{let u=n.__wbindgen_add_to_stack_pointer(-16),f=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),g=p,b=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p,m=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),w=p;n.info(u,f,g,b,x,m,w,i,_);var a=l().getInt32(u+0,!0),c=l().getInt32(u+4,!0);return s=a,o=c,k(a,c)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(s,o,1);}}function R(t,e,r,i,_,s,o){let a,c;try{let g=n.__wbindgen_add_to_stack_pointer(-16),b=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),x=p,m=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),w=p,y=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),h=p,T=d(i,n.__wbindgen_export_0,n.__wbindgen_export_1),O=p;n.convert(g,b,x,m,w,y,h,T,O,_,s,o);var u=l().getInt32(g+0,!0),f=l().getInt32(g+4,!0);return a=u,c=f,k(u,f)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(a,c,1);}}function L(t,e,r,i){let _,s;try{let c=n.__wbindgen_add_to_stack_pointer(-16),u=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p,g=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),b=p;n.optimize(c,u,f,g,b,r,i);var o=l().getInt32(c+0,!0),a=l().getInt32(c+4,!0);return _=o,s=a,k(o,a)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(_,s,1);}}function U(t,e,r,i){let _,s;try{let c=n.__wbindgen_add_to_stack_pointer(-16),u=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),f=p,g=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),b=p;n.fullize(c,u,f,g,b,r,i);var o=l().getInt32(c+0,!0),a=l().getInt32(c+4,!0);return _=o,s=a,k(o,a)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(_,s,1);}}function C(t,e,r,i,_,s){let o,a;try{let f=n.__wbindgen_add_to_stack_pointer(-16),g=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),b=p,x=d(e,n.__wbindgen_export_0,n.__wbindgen_export_1),m=p,w=d(r,n.__wbindgen_export_0,n.__wbindgen_export_1),y=p;n.canonicalize(f,g,b,x,m,w,y,i,_,s);var c=l().getInt32(f+0,!0),u=l().getInt32(f+4,!0);return o=c,a=u,k(c,u)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(o,a,1);}}function D(t){let e,r;try{let s=n.__wbindgen_add_to_stack_pointer(-16),o=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),a=p;n.count_bits(s,o,a);var i=l().getInt32(s+0,!0),_=l().getInt32(s+4,!0);return e=i,r=_,k(i,_)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(e,r,1);}}function G(t){let e,r;try{let s=n.__wbindgen_add_to_stack_pointer(-16),o=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),a=p;n.split_bits(s,o,a);var i=l().getInt32(s+0,!0),_=l().getInt32(s+4,!0);return e=i,r=_,k(i,_)}finally{n.__wbindgen_add_to_stack_pointer(16),n.__wbindgen_export_2(e,r,1);}}function ut(t){let e=d(t,n.__wbindgen_export_0,n.__wbindgen_export_1),r=p;return n.is_bitmark(e,r)!==0}async function ft(t,e){if(typeof Response=="function"&&t instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(t,e)}catch(i){if(t.headers.get("Content-Type")!="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",i);else throw i}let r=await t.arrayBuffer();return await WebAssembly.instantiate(r,e)}else {let r=await WebAssembly.instantiate(t,e);return r instanceof WebAssembly.Instance?{instance:r,module:t}:r}}function Y(){let t={};return t.wbg={},t}function Z(t,e){return n=t.exports,et.__wbindgen_wasm_module=e,v=null,W=null,n}function tt(t){if(n!==void 0)return n;typeof t<"u"&&(Object.getPrototypeOf(t)===Object.prototype?{module:t}=t:console.warn("using deprecated parameters for `initSync()`; pass a single object instead"));let e=Y();t instanceof WebAssembly.Module||(t=new WebAssembly.Module(t));let r=new WebAssembly.Instance(t,e);return Z(r,t)}async function et(t){if(n!==void 0)return n;typeof t<"u"&&(Object.getPrototypeOf(t)===Object.prototype?{module_or_path:t}=t:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),typeof t>"u"&&(t=new URL("bitmark_wasm_bg.wasm",import.meta.url));let e=Y();(typeof t=="string"||typeof Request=="function"&&t instanceof Request||typeof URL=="function"&&t instanceof URL)&&(t=fetch(t));let{instance:r,module:i}=await ft(await t,e);return Z(r,i)}var $=et;var q={version:"6.1.3"};function I(t){return t.startsWith("error:")}function S(t){let e=t instanceof Error?t.message:String(t);return e.startsWith("error:")?e:`error: ${e}`}function lt(t){let e=t.trim();return e.startsWith("[")&&e.endsWith("]")?e.slice(1,-1):t}function gt(t){if(t===void 0)return [];if(typeof t=="string"){let e=t.trim();return e===""?[]:JSON.parse(e)}return t}function bt(t,e,r){if(r){let s=t.split_bits(e);if(I(s))throw new Error(s);let o=JSON.parse(s);return o.map(a=>({view:{format:"bitmark",index:a.index,total:o.length,source:a.source},source:a.source}))}let i=t.split_json_bits(e);if(I(i))throw new Error(i);let _=JSON.parse(i);return _.map((s,o)=>({view:{format:"json",index:o,total:_.length,bit:s.bit},source:JSON.stringify([s])}))}function K(t,e,r){let i=r.mode??"optimized",_=r.outputFormat??"json",s=r.spacesAroundValues??1,o=r.indent??2,a=r.pretty??false,c=r.inputFormat??"auto",u=c==="bitmark"||c!=="json"&&t.is_bitmark(e),f=u?"bitmark":"json",g=gt(r.patch),b=bt(t,e,u),x=b.length,m=[],w=[];for(let y=0;y<x;y++){let{view:h,source:T}=b[y];h.index=y,h.total=x;let O=r.preHook?r.preHook(h)||{}:{};if(O.drop)continue;let J=O.patches?[...g,...O.patches]:g;m.push({index:y,source:T,inputFormat:f,outputFormat:O.outputFormat??_,mode:i,patchJson:JSON.stringify(J),spacesAroundValues:s}),w.push(h);}return {jobs:m,views:w,output:_,pretty:a,indent:o}}function mt(t,e){let r=t.transform(e.source,e.inputFormat,e.outputFormat,e.mode,e.patchJson,false,2,e.spacesAroundValues);return I(r)?r:e.outputFormat==="json"?lt(r):r}function Q(t,e,r,i,_){if(r==="bitmark"||r==="text")return e.join(`
|
|
2
|
-
`);let
|
|
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
|
|
3
5
|
//# sourceMappingURL=bitmark-parser.min.js.map
|