@mdgate/containers 0.6.11 → 0.6.13
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/dist/archive.d.ts +2 -0
- package/dist/index.js +5 -5
- package/package.json +3 -3
package/dist/archive.d.ts
CHANGED
|
@@ -15,6 +15,8 @@ export declare class Package {
|
|
|
15
15
|
hasPart(name: string): boolean;
|
|
16
16
|
/** Part names present in the archive (no leading slash). */
|
|
17
17
|
partNames(): string[];
|
|
18
|
+
/** True when any entry is password-protected or uses an Apple/AES zip method. */
|
|
19
|
+
hasEncryptedEntries(): boolean;
|
|
18
20
|
requiredPart(name: string): Uint8Array;
|
|
19
21
|
/**
|
|
20
22
|
* Absent is valid (`undefined`, silent); an unreadable part is skipped
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{ConvertError as P}from"@mdgate/core";import{decode as v0,inflateRaw as h0,warn as u6}from"@mdgate/utils";import{ConvertError as g}from"@mdgate/core";var Z6=[208,207,17,224,161,177,26,225],y=4294967295,K6=4294967294,j0=4294967293,P0=4294967292,M0=4294967295,A=4294967290,I6=0;var A6=2,F0=5;class T{bytes;sectorSize;miniSectorSize;miniCutoff;fat;miniFat;entries;miniStream;constructor($,J,Q,K,Y,Z,G){this.bytes=$,this.sectorSize=J,this.miniSectorSize=Q,this.miniCutoff=K,this.fat=Y,this.miniFat=Z,this.entries=G}static open($){if($.length<512||!q6($,Z6))throw g.malformed("not an OLE2 compound file");let J=new DataView($.buffer,$.byteOffset,$.byteLength);if(J.getUint16(28,!0)!==65534)throw g.malformed("not an OLE2 compound file: bad byte order");let K=J.getUint16(30,!0);if(K!==9&&K!==12)throw g.malformed("not an OLE2 compound file: bad sector shift");let Y=1<<K,Z=J.getUint16(32,!0),G=Z===0?64:1<<Z,W=J.getUint16(26,!0),X=J.getUint32(44,!0),D=J.getUint32(48,!0),U=J.getUint32(56,!0)||4096,j=J.getUint32(60,!0),M=J.getUint32(64,!0),x=J.getUint32(68,!0),z=J.getUint32(72,!0),F=[];for(let V=0;V<109;V+=1){let O=J.getUint32(76+V*4,!0);if(O<=A)F.push(O)}let q=x,w=new Set;for(let V=0;V<z&&q<=A;V+=1){if(w.has(q))break;w.add(q);let O=Y6(q,Y),I=Y/4;if(O+Y>$.length)break;let c=new DataView($.buffer,$.byteOffset+O,Y);for(let E=0;E<I-1;E+=1){let C=c.getUint32(E*4,!0);if(C<=A)F.push(C)}q=c.getUint32((I-1)*4,!0)}if(F.length<X);let B=[],Q6=Math.min(F.length,X||F.length,1e6);for(let V=0;V<Q6;V+=1){let O=F[V],I=Y6(O,Y);if(I+Y>$.length)break;let c=new DataView($.buffer,$.byteOffset+I,Y),E=Y/4;for(let C=0;C<E;C+=1)B.push(c.getUint32(C*4,!0))}let L=Math.max(0,Math.floor(($.length+Y-1)/Y)-1);while(B.length>L){let V=B[B.length-1];if(V===0||V===P0||V===j0||V===y||V===K6)B.pop();else break}while(B.length>L&&B[B.length-1]===y)B.pop();if(B.length>L)throw g.malformed(`not an OLE2 compound file: Malformed FAT (FAT has ${B.length} entries, but file has only ${L} sectors)`);while(B.length<L)B.push(y);let l=[];if(M>0&&j<=A){let V=d($,B,Y,j,M*Y),O=new DataView(V.buffer,V.byteOffset,V.byteLength);for(let I=0;I+4<=V.length;I+=4)l.push(O.getUint32(I,!0))}let m=d($,B,Y,D,$.length),b=[];for(let V=0;V+128<=m.length;V+=128)b.push(_0(m,V,W));if(b.length===0||b[0].type!==F0)throw g.malformed("not an OLE2 compound file: missing root storage");return new T($,Y,G,U,B,l,b)}readRootStorage(){let $=this.entries[0];if($===void 0)return[];let J=[];return this.walkSiblings($.child,J),J}exists($){return this.lookup($)!==void 0}readStream($){let J=this.lookup($);if(J===void 0||J.type!==A6)throw g.missingPart($);return this.readEntryBytes(J,Number.MAX_SAFE_INTEGER)}lookup($){let J=$.split("/").filter((Y)=>Y.length>0);if(J.length===0)return this.entries[0];let Q=this.entries[0]?.child??M0,K;for(let Y of J){if(K=this.findChild(Q,Y),K===void 0)return;Q=K.child}return K}findChild($,J){let Q=new Set,K=[$];while(K.length>0){let Y=K.pop();if(Y>A||Q.has(Y))continue;Q.add(Y);let Z=this.entries[Y];if(Z===void 0||Z.type===I6)continue;if(R0(Z.name,J))return Z;K.push(Z.left,Z.right)}return}walkSiblings($,J){let Q=new Set,K=(Y)=>{if(Y>A||Q.has(Y))return;Q.add(Y);let Z=this.entries[Y];if(Z===void 0||Z.type===I6)return;K(Z.left),J.push({name:Z.name,type:Z.type}),K(Z.right)};K($)}readEntryBytes($,J){let Q=Math.min($.size,J);if($.size<this.miniCutoff&&$.type===A6)return this.readMiniChain($.start,Q);return d(this.bytes,this.fat,this.sectorSize,$.start,Q)}readMiniChain($,J){if(this.miniStream===void 0){let G=this.entries[0];this.miniStream=d(this.bytes,this.fat,this.sectorSize,G.start,G.size)}let Q=new Uint8Array(J),K=0,Y=$,Z=new Set;while(K<J&&Y<=A){if(Z.has(Y))break;Z.add(Y);let G=Y*this.miniSectorSize,W=Math.min(this.miniSectorSize,J-K);if(G+W>this.miniStream.length)break;Q.set(this.miniStream.subarray(G,G+W),K),K+=W,Y=this.miniFat[Y]??K6}return K===J?Q:Q.subarray(0,K)}}var N0=Z6;function v($){return q6($,Z6)}function q6($,J){if($.length<J.length)return!1;for(let Q=0;Q<J.length;Q+=1)if($[Q]!==J[Q])return!1;return!0}function R0($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function Y6($,J){return($+1)*J}function d($,J,Q,K,Y){if(K>A||Y<=0)return new Uint8Array(0);let Z=[],G=0,W=K,X=new Set;while(G<Y&&W<=A){if(X.has(W)||X.size>1e6)break;X.add(W);let D=Y6(W,Q);if(D>=$.length)break;let U=Math.min(Q,Y-G,$.length-D);if(U<=0)break;if(Z.push($.subarray(D,D+U)),G+=U,W=J[W]??K6,W===y)break}return L0(Z,G)}function _0($,J,Q){let K=new DataView($.buffer,$.byteOffset+J,128),Y=K.getUint16(64,!0),Z=Math.max(0,Math.min(64,Y>0?Y-2:0)),G=new TextDecoder("utf-16le").decode($.subarray(J,J+Z)),W=$[J+66]??0,X=K.getUint32(68,!0),D=K.getUint32(72,!0),U=K.getUint32(76,!0),j=K.getUint32(116,!0),M=Number(K.getBigUint64(120,!0));if(Q===3)M=K.getUint32(120,!0);if(!Number.isFinite(M)||M<0)M=0;return{name:G,type:W,left:X,right:D,child:U,start:j,size:M}}function L0($,J){if($.length===1&&$[0].length===J)return $[0];let Q=new Uint8Array(J),K=0;for(let Y of $)Q.set(Y,K),K+=Y.length;return Q}import{ConvertError as O0}from"@mdgate/core";import{debug as z6,decode as I0,encodingExists as A0,warn as q0}from"@mdgate/utils";var H={W:"http://schemas.openxmlformats.org/wordprocessingml/2006/main",R:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",A:"http://schemas.openxmlformats.org/drawingml/2006/main",PIC:"http://schemas.openxmlformats.org/drawingml/2006/picture",WP:"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",MC:"http://schemas.openxmlformats.org/markup-compatibility/2006",CHART:"http://schemas.openxmlformats.org/drawingml/2006/chart",DGM:"http://schemas.openxmlformats.org/drawingml/2006/diagram",P:"http://schemas.openxmlformats.org/presentationml/2006/main",PKG_RELS:"http://schemas.openxmlformats.org/package/2006/relationships",OFFICE:"urn:oasis:names:tc:opendocument:xmlns:office:1.0",TEXT:"urn:oasis:names:tc:opendocument:xmlns:text:1.0",TABLE:"urn:oasis:names:tc:opendocument:xmlns:table:1.0",DRAW:"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",STYLE:"urn:oasis:names:tc:opendocument:xmlns:style:1.0",FO:"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",PRESENTATION:"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0",MANIFEST:"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",XLINK:"http://www.w3.org/1999/xlink",XML:"http://www.w3.org/XML/1998/namespace",SVG_COMPAT:"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0",VML:"urn:schemas-microsoft-com:vml",O_VML:"urn:schemas-microsoft-com:office:office",WPS:"http://schemas.microsoft.com/office/word/2010/wordprocessingShape",WPG:"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"},z0=H.XML,T0="http://www.w3.org/2000/xmlns/",w6=[];class n{ns;local;attrs;children;_elems;constructor($,J,Q=w6,K=[]){this.ns=$,this.local=J,this.attrs=Q,this.children=K}is($,J){return this.local===J&&this.ns===$}attr($,J){return this.attrQualified($,J)??this.attrUnqualified(J)}attrQualified($,J){let Q=this.attrs;for(let K=0;K<Q.length;K+=1){let Y=Q[K];if(Y.local===J&&Y.ns===$)return Y.value}return}attrUnqualified($){let J=this.attrs;for(let Q=0;Q<J.length;Q+=1){let K=J[Q];if(K.local===$&&K.ns===void 0)return K.value}return}attrAny($){let J=this.attrs;for(let Q=0;Q<J.length;Q+=1){let K=J[Q];if(K.local===$)return K.value}return}childElems(){if(this._elems!==void 0)return this._elems;let $=[],J=this.children;for(let Q=0;Q<J.length;Q+=1){let K=J[Q];if(K.type==="elem")$.push(K.elem)}return this._elems=$,$}find($,J){let Q=this.children;for(let K=0;K<Q.length;K+=1){let Y=Q[K];if(Y.type==="elem"&&Y.elem.local===J&&Y.elem.ns===$)return Y.elem}return}findAll($,J){let Q=[],K=this.children;for(let Y=0;Y<K.length;Y+=1){let Z=K[Y];if(Z.type==="elem"&&Z.elem.local===J&&Z.elem.ns===$)Q.push(Z.elem)}return Q}*descendantNodes(){let $=this.children.slice();$.reverse();while($.length>0){let J=$.pop();if(J.type==="elem"){let Q=$.length;for(let K of J.elem.children)$.push(K);x0($,Q)}yield J}}*descendantElems(){for(let $ of this.descendantNodes())if($.type==="elem")yield $.elem}firstDescendant($,J){for(let Q of this.descendantElems())if(Q.is($,J))return Q;return}*descendants($,J){for(let Q of this.descendantElems())if(Q.is($,J))yield Q}*descendantsAny($){for(let J of this.descendantElems())if(J.local===$)yield J}text(){let $="";for(let J of this.descendantNodes())if(J.type==="text")$+=J.text;return $}}class C6{prefixes=[new Map];ownsMap=[!0];defaultNs=[void 0];push(){this.prefixes.push(this.prefixes[this.prefixes.length-1]),this.ownsMap.push(!1),this.defaultNs.push(this.defaultNs[this.defaultNs.length-1])}pop(){this.prefixes.pop(),this.ownsMap.pop(),this.defaultNs.pop()}applyDecls($){for(let J of $)if(J.rawName==="xmlns")this.defaultNs[this.defaultNs.length-1]=J.value.length===0?void 0:J.value;else if(J.rawName.startsWith("xmlns:")){if(!this.ownsMap[this.ownsMap.length-1])this.prefixes[this.prefixes.length-1]=new Map(this.prefixes[this.prefixes.length-1]),this.ownsMap[this.ownsMap.length-1]=!0;let Q=J.rawName.slice(6);this.prefixes[this.prefixes.length-1].set(Q,J.value.length===0?void 0:J.value)}}lookupPrefix($){if($==="xml")return z0;if($==="xmlns")return T0;return this.prefixes[this.prefixes.length-1].get($)}resolveElement($){let J=$.indexOf(":");if(J>=0){let K=$.slice(0,J),Y=$.slice(J+1),Z=this.lookupPrefix(K);return{ns:Z,local:Y,bound:Z!==void 0||K==="xml"||K==="xmlns"}}let Q=this.defaultNs[this.defaultNs.length-1];return{ns:Q,local:$,bound:Q!==void 0}}resolveAttribute($){let J=$.indexOf(":");if(J>=0){let Q=$.slice(0,J),K=$.slice(J+1);return{ns:this.lookupPrefix(Q),local:K}}return{ns:void 0,local:$}}}function u($){let J=E0($,"http://purl.oclc.org/ooxml/");if(J===void 0)return;let Q=J.indexOf("/");if(Q<0)return;let K=J.slice(0,Q),Y=J.slice(Q+1);return`http://schemas.openxmlformats.org/${K}/2006/${Y}`}function g6($){switch($){case"http://openoffice.org/2000/office":case"http://openoffice.org/2001/office":return H.OFFICE;case"http://openoffice.org/2000/text":return H.TEXT;case"http://openoffice.org/2000/table":return H.TABLE;case"http://openoffice.org/2000/drawing":return H.DRAW;case"http://openoffice.org/2000/presentation":return H.PRESENTATION;case"http://openoffice.org/2000/style":return H.STYLE;case"http://openoffice.org/2001/manifest":case"http://openoffice.org/2000/manifest":return H.MANIFEST;case"http://www.w3.org/1999/XSL/Format":return H.FO;default:return}}var S6=0,x6=1,E6=2,h=3,D6=4,v6=5;function i($){let J=w0($),Q=new h6(J),K=new C6,Y=new Map,Z=new Map,G=new n(void 0,""),W=[],X=!1;for(;;){let D;try{D=Q.next()}catch(U){let j=U instanceof Error?U.message:String(U);throw O0.malformed(`unparseable xml: ${j}`)}switch(D){case x6:{K.push(),K.applyDecls(Q.attrs);let U=k0(Q.name,Q.attrs,K,Y,Z);if(Q.empty)W6(W,G,{type:"elem",elem:U}),K.pop();else W.push(U);break}case E6:{let U=W.pop();if(U===void 0)X=!0;else{if(U.local!==Q.local)X=!0;W6(W,G,{type:"elem",elem:U}),K.pop()}break}case h:{if(Q.text.length>0)G6(W,G,Q.text);break}case D6:{let U=X6(Q.name)??`&${Q.name};`;G6(W,G,U);break}case v6:{G6(W,G,Q.text);break}case S6:if(W.length>0){X=!0;while(W.length>0)W6(W,G,{type:"elem",elem:W.pop()})}if(X)q0("recovered malformed xml (unclosed or mismatched elements)");return G}}}function W6($,J,Q){let K=$[$.length-1];if(K!==void 0)K.children.push(Q);else J.children.push(Q)}function G6($,J,Q){let K=$[$.length-1]?.children??J.children,Y=K[K.length-1];if(Y?.type==="text")Y.text+=Q;else K.push({type:"text",text:Q})}function T6($,J){let Q=$.get(J);if(Q!==void 0)return Q;let K=u(J)??g6(J)??J;return $.set(J,K),K}function k6($,J){let Q=$.get(J);if(Q!==void 0)return Q;return $.set(J,J),J}function k0($,J,Q,K,Y){let Z=Q.resolveElement($),G=Z.ns!==void 0?T6(K,Z.ns):void 0,W=w6,X=!1;for(let D of J){if(D.rawName==="xmlns"||D.rawName.startsWith("xmlns:"))continue;let U=Q.resolveAttribute(D.rawName);if(!X)W=[],X=!0;W.push({ns:U.ns!==void 0?T6(K,U.ns):void 0,local:k6(Y,U.local),value:D.value})}if(Z.local==="Choice"&&G===H.MC){let D=W.find((U)=>U.local==="Requires");if(D!==void 0)D.value=D.value.split(/\s+/).filter((U)=>U.length>0).map((U)=>{let j=Q.resolveElement(`${U}:x`);if(j.bound&&j.ns!==void 0)return u(j.ns)??j.ns;return U}).join(" ")}return new n(G,k6(Y,Z.local),W)}function w0($){if($.length>=2&&$[0]===255&&$[1]===254)return new TextDecoder("utf-16le").decode($);if($.length>=2&&$[0]===254&&$[1]===255)return new TextDecoder("utf-16be").decode($);if($.length>=3&&$[0]===239&&$[1]===187&&$[2]===191)return new TextDecoder("utf-8").decode($.subarray(3));let J=$.subarray(0,Math.min($.length,200)),Q=C0(J);if(Q!==void 0){let K=g0(Q);if(K!==void 0&&K!=="utf8"&&K!=="utf-8")return I0($,K)}return new TextDecoder("utf-8").decode($)}function C0($){let J;try{J=new TextDecoder("utf-8",{fatal:!0}).decode($)}catch{return}let Q=J.indexOf("encoding");if(Q<0)return;let K=J.slice(Q+8).trimStart();if(!K.startsWith("="))return;K=K.slice(1).trimStart();let Y=K[0];if(Y!=='"'&&Y!=="'")return;K=K.slice(1);let Z=K.indexOf(Y);if(Z<0)return;return K.slice(0,Z)}function g0($){let J=$.trim().toLowerCase().replace(/_/g,"-"),K={"utf-8":"utf8",utf8:"utf8","utf-16":"utf16-le","utf-16le":"utf16-le","utf-16be":"utf16-be","iso-8859-1":"iso-8859-1","latin-1":"iso-8859-1",latin1:"iso-8859-1","windows-1252":"windows-1252","cp-1252":"windows-1252",cp1252:"windows-1252","windows-1251":"windows-1251","windows-1250":"windows-1250","windows-874":"windows-874",gbk:"gbk",gb2312:"gb2312",gb18030:"gb18030",big5:"big5","shift-jis":"shiftjis",shiftjis:"shiftjis","euc-jp":"euc-jp","euc-kr":"euc-kr",koi8r:"koi8-r","koi8-r":"koi8-r"}[J]??J;return A0(K)?K:void 0}function X6($){if($.startsWith("#")){let Q=$.slice(1),K=Q.startsWith("x")||Q.startsWith("X"),Y=K?Q.slice(1):Q,Z=Number.parseInt(Y,K?16:10);if(!Number.isFinite(Z))return;try{return String.fromCodePoint(Z)}catch{return}}return{amp:"&",lt:"<",gt:">",apos:"'",quot:'"',nbsp:" ",shy:"",mdash:"—",ndash:"–",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",hellip:"…",copy:"©",reg:"®",trade:"™",deg:"°",middot:"·",bull:"•",sect:"§",para:"¶",laquo:"«",raquo:"»",times:"×",divide:"÷",plusmn:"±",frac12:"½",frac14:"¼",eacute:"é",egrave:"è",agrave:"à",ccedil:"ç",uuml:"ü",ouml:"ö",auml:"ä",szlig:"ß",aring:"å",oslash:"ø",aelig:"æ",euro:"€",pound:"£",yen:"¥",cent:"¢"}[$]}class h6{s;i=0;name="";local="";text="";empty=!1;attrs=[];constructor($){this.s=$}next(){if(this.i>=this.s.length)return S6;if(this.s.charCodeAt(this.i)===60)return this.markup();return this.textRun()}markup(){if(this.startsWith("<?"))return this.skipUntil("?>"),this.next();if(this.startsWith("<!--")){this.i+=4;let $=this.s.indexOf("-->",this.i);if($<0)throw Error("unterminated comment");return this.i=$+3,this.next()}if(this.startsWith("<![CDATA[")){this.i+=9;let $=this.s.indexOf("]]>",this.i);if($<0)throw Error("unterminated cdata");return this.text=this.s.slice(this.i,$),this.i=$+3,v6}if(this.startsWith("<!"))return this.skipDoctype(),this.next();if(this.startsWith("</")){this.i+=2;let $=this.readName();if(this.skipWs(),this.s[this.i]===">")this.i+=1;return this.local=S0($),E6}if(this.i+=1,this.name=this.readName(),this.attrs=this.readAttrs(),this.skipWs(),this.empty=!1,this.s[this.i]==="/"&&this.s[this.i+1]===">")this.i+=2,this.empty=!0;else if(this.s[this.i]===">")this.i+=1;return x6}textRun(){let $=this.i;while(this.i<this.s.length){let J=this.s.charCodeAt(this.i);if(J===60)break;if(J===38){if(this.i>$)return this.text=this.s.slice($,this.i),h;let Q=this.readReference();if(Q.type==="general")return this.name=Q.name,D6;return this.i=$,this.textRunSlow()}this.i+=1}return this.text=this.s.slice($,this.i),h}textRunSlow(){let $="";while(this.i<this.s.length){let J=this.s.charCodeAt(this.i);if(J===60)break;if(J===38){let K=this.readReference();if(K.type==="general"){if($.length>0)return this.i=K.rewind,this.text=$,h;return this.name=K.name,D6}$+=K.text;continue}let Q=this.i;this.i+=1;while(this.i<this.s.length){let K=this.s.charCodeAt(this.i);if(K===60||K===38)break;this.i+=1}$+=this.s.slice(Q,this.i)}return this.text=$,h}readReference(){let $=this.i;this.i+=1;let J=this.s.indexOf(";",this.i);if(J<0)return{type:"char",text:"&"};let Q=this.s.slice(this.i,J);if(this.i=J+1,Q.startsWith("#")||Q==="amp"||Q==="lt"||Q==="gt"||Q==="apos"||Q==="quot")return{type:"char",text:X6(Q)??`&${Q};`};return{type:"general",name:Q,rewind:$}}readName(){let $=this.i;while(this.i<this.s.length){let J=this.s.charCodeAt(this.i);if(J===47||J===62||J===61||J===32||J===9||J===10||J===13)break;this.i+=1}return this.s.slice($,this.i)}readAttrs(){let $=[];for(;;){this.skipWs();let J=this.s[this.i];if(J===void 0||J===">"||J==="/")break;let Q=this.readName();if(Q.length===0){this.i+=1;continue}if(this.skipWs(),this.s[this.i]!=="="){z6(`dropping undecodable attribute: ${Q}`);continue}this.i+=1,this.skipWs();let K=this.readAttrValue();if(K===void 0){z6(`dropping undecodable attribute: ${Q}`);continue}$.push({rawName:Q,value:K})}return $}readAttrValue(){let $=this.s.charCodeAt(this.i);if($!==34&&$!==39)return;this.i+=1;let J=this.i,Q=!1;while(this.i<this.s.length){let Y=this.s.charCodeAt(this.i);if(Y===$){let Z=this.s.slice(J,this.i);return this.i+=1,Q?o(Z):Z}if(Y===38)return this.i=J,this.readAttrValueSlow($);if(Y===9||Y===10||Y===13)Q=!0;this.i+=1}let K=this.s.slice(J,this.i);return Q?o(K):K}readAttrValueSlow($){let J="";while(this.i<this.s.length){let Q=this.s.charCodeAt(this.i);if(Q===$)return this.i+=1,o(J);if(Q===38){let Y=this.readReference();if(Y.type==="char")J+=Y.text;else J+=X6(Y.name)??`&${Y.name};`;continue}let K=this.i;this.i+=1;while(this.i<this.s.length){let Y=this.s.charCodeAt(this.i);if(Y===$||Y===38)break;this.i+=1}J+=this.s.slice(K,this.i)}return o(J)}skipWs(){while(this.i<this.s.length){let $=this.s.charCodeAt(this.i);if($!==32&&$!==9&&$!==10&&$!==13)break;this.i+=1}}startsWith($){return this.s.startsWith($,this.i)}skipUntil($){let J=this.s.indexOf($,this.i);this.i=J<0?this.s.length:J+$.length}skipDoctype(){this.i+=2;let $=0;while(this.i<this.s.length){let J=this.s[this.i];if(J==='"'||J==="'"){let Q=J;this.i+=1;while(this.i<this.s.length&&this.s[this.i]!==Q)this.i+=1;if(this.i<this.s.length)this.i+=1;continue}if(J==="<")$+=1;else if(J===">"){if($===0){this.i+=1;return}$-=1}this.i+=1}}}function S0($){let J=$.indexOf(":");return J<0?$:$.slice(J+1)}function o($){if($.indexOf("\t")<0&&$.indexOf(`
|
|
2
|
-
`)<0&&$.indexOf("\r")<0)return $;return $.replace(/[\t\n\r]/g," ")}function x0($,J){let Q=J,K=$.length-1;while(Q<K){let Y=$[Q];$[Q]=$[K],$[K]=Y,Q+=1,K-=1}}function E0($,J){return $.startsWith(J)?$.slice(J.length):void 0}var u0=67324752,f0=33639248;var p0=101075792,l0=117853008,m0=0,b0=8;class U6{length;bytes;byName=new Map;constructor($,J){this.bytes=$,this.length=J.length;for(let Q of J)if(!this.byName.has(Q.name))this.byName.set(Q.name,Q)}static open($){let J=y0($);if(J<0)throw P.malformed("not a readable zip archive: invalid Zip archive: Could not find EOCD");let Q=r($),K=N(Q,J+10),Y=R(Q,J+12),Z=R(Q,J+16);if(K===65535||Y===4294967295||Z===4294967295){let D=o0($,J);if(D!==void 0)K=D.entryCount,Y=D.cdSize,Z=D.cdOffset}if(Z+Y>$.length)throw P.malformed("not a readable zip archive: truncated central directory");let G=[],W=Z,X=Math.min($.length,Z+Y);while(W+46<=X&&G.length<K){if(R(Q,W)!==f0)throw P.malformed("not a readable zip archive: bad central directory");let D=N(Q,W+8),U=N(Q,W+10),j=R(Q,W+16),M=R(Q,W+20),x=R(Q,W+24),z=N(Q,W+28),F=N(Q,W+30),q=N(Q,W+32),w=R(Q,W+42),B=$.subarray(W+46,W+46+z);if(W+46+z+F+q>$.length)throw P.malformed("not a readable zip archive: truncated entry");let Q6=$.subarray(W+46+z,W+46+z+F),L=n0(Q6,{uncompressedSize:x,compressedSize:M,headerOffset:w});x=L.uncompressedSize,M=L.compressedSize,w=L.headerOffset;let l=(D&2048)!==0,m=i0(B,l);G.push({name:m,method:U,flags:D,crc:j,compressedSize:M,uncompressedSize:x,headerOffset:w}),W+=46+z+F+q}return new U6($,G)}indexForName($){return this.byName.get($)}partNames(){return[...this.byName.keys()]}readCompressed($){let J=r(this.bytes),Q=$.headerOffset;if(Q+30>this.bytes.length||R(J,Q)!==u0)throw Error("bad local file header");let K=N(J,Q+26),Y=N(J,Q+28),Z=Q+30+K+Y,G=Z+$.compressedSize;if(Z>this.bytes.length)throw Error("truncated local file header");if($.compressedSize>0&&G>this.bytes.length)throw Error("truncated compressed data");return this.bytes.subarray(Z,Math.min(G,this.bytes.length))}}class f{zip;cache=new Map;constructor($){this.zip=$}static open($){let J;try{J=U6.open($)}catch(Q){if(Q instanceof P)throw Q;let K=Q instanceof Error?Q.message:String(Q);throw P.malformed(`not a readable zip archive: ${K}`)}return new f(J)}part($){$=f6($);let J=this.cache.get($);if(J!==void 0)return J;let Q=this.zip.indexForName($);if(Q===void 0)return;let K;try{K=this.decompress(Q,Number.MAX_SAFE_INTEGER)}catch(Y){if(Y instanceof P)throw Y;let Z=Y instanceof Error?Y.message:String(Y);throw P.malformedPart($,`corrupt archive entry: ${Z}`)}return this.cache.set($,K),K}hasPart($){return this.zip.indexForName(f6($))!==void 0}partNames(){return this.zip.partNames()}requiredPart($){let J=this.part($);if(J===void 0)throw P.missingPart($);return J}optionalPart($){try{return this.part($)}catch(J){if(J instanceof P&&J.isFatal())throw J;u6(`skipping unreadable part ${$}: ${J instanceof Error?J.message:String(J)}`);return}}optionalXmlPart($){let J=this.optionalPart($);if(J===void 0)return;try{return i(J)}catch(Q){if(Q instanceof P&&Q.isFatal())throw Q;u6(`skipping corrupt part ${$}: ${Q instanceof Error?Q.message:String(Q)}`);return}}requiredXmlPart($){return i(this.requiredPart($))}decompress($,J){if(($.flags&1)!==0)throw Error("encrypted zip entry");let Q;try{Q=this.zip.readCompressed($)}catch(Y){let Z=Y instanceof Error?Y.message:String(Y);throw P.malformedPart($.name,`unreadable archive entry: ${Z}`)}let K;if($.method===m0){let Y=$.uncompressedSize>0?$.uncompressedSize:Q.length;K=Q.subarray(0,Math.min(Y,Q.length))}else if($.method===b0)K=d0(Q,J);else throw Error(`unsupported compression method ${$.method}`);if(K.length<=J-1&&$.crc!==0&&t0(K)!==$.crc)throw Error("crc mismatch");return K}}function c0($){if(!v($))return;try{let J=T.open($);if(J.exists("EncryptionInfo")||J.exists("EncryptedPackage"))return P.encrypted()}catch{}return P.malformed("OLE compound document where an OOXML package was expected (legacy binary format?)")}function d0($,J){return h0($,J)}function y0($){let J=Math.max(0,$.length-65557);for(let Q=$.length-22;Q>=J;Q-=1)if($[Q]===80&&$[Q+1]===75&&$[Q+2]===5&&$[Q+3]===6){let K=$[Q+20]|$[Q+21]<<8;if(Q+22+K===$.length)return Q}return-1}function o0($,J){if(J<20)return;let Q=r($),K=J-20;if(R(Q,K)!==l0)return;let Y=k(Q,K+8);if(Y+56>$.length||R(Q,Y)!==p0)return;return{entryCount:k(Q,Y+32),cdSize:k(Q,Y+40),cdOffset:k(Q,Y+48)}}function n0($,J){let Q=0,K=r($);while(Q+4<=$.length){let Y=N(K,Q),Z=N(K,Q+2),G=Q+4;if(G+Z>$.length)break;if(Y===1){let W=G,{uncompressedSize:X,compressedSize:D,headerOffset:U}=J;if(X===4294967295&&W+8<=G+Z)X=k(K,W),W+=8;if(D===4294967295&&W+8<=G+Z)D=k(K,W),W+=8;if(U===4294967295&&W+8<=G+Z)U=k(K,W);return{uncompressedSize:X,compressedSize:D,headerOffset:U}}Q=G+Z}return J}function i0($,J){if(J)return new TextDecoder("utf-8",{fatal:!1}).decode($);return v0($,"cp437")}function f6($){let J=0;while(J<$.length&&$.charCodeAt(J)===47)J+=1;return $.slice(J)}function r($){return new DataView($.buffer,$.byteOffset,$.byteLength)}function N($,J){return $.getUint16(J,!0)}function R($,J){return $.getUint32(J,!0)}function k($,J){let Q=$.getUint32(J,!0),K=$.getUint32(J+4,!0);if(K>2097151)return Number.POSITIVE_INFINITY;return K*4294967296+Q}var r0=a0();function a0(){let $=new Uint32Array(256);for(let J=0;J<256;J+=1){let Q=J;for(let K=0;K<8;K+=1)Q=Q&1?3988292384^Q>>>1:Q>>>1;$[J]=Q>>>0}return $}function s0($){let J=4294967295;for(let Q=0;Q<$.length;Q+=1)J=r0[(J^$[Q])&255]^J>>>8;return(J^4294967295)>>>0}function t0($){return s0($)}import{ConvertError as p6}from"@mdgate/core";function e0($,J){if(!Number.isSafeInteger(J)||J<0||J+2>$.length)return;return $[J]|$[J+1]<<8}function $$($,J){if(!Number.isSafeInteger(J)||J<0||J+4>$.length)return;return($[J]|$[J+1]<<8|$[J+2]<<16|$[J+3]<<24)>>>0}function J$($,J){try{return $.readStream(J)}catch(Q){if(Q instanceof p6)throw Q;let K=Q instanceof Error?Q.message:String(Q);throw p6.malformedPart(J,`unreadable stream: ${K}`)}}import{trim as y6}from"@mdgate/utils";import{ConvertError as l6}from"@mdgate/core";function p($,J){let Q,K=J.indexOf("#");if(K>=0)Q=V6(J.slice(K+1)),J=J.slice(0,K);let Y=J.indexOf("?");if(Y>=0)J=J.slice(0,Y);if(J.length===0)return{path:$,fragment:Q};let Z=[];if(!J.startsWith("/")){let G=$.lastIndexOf("/");if(G>=0){for(let W of $.slice(0,G).split("/"))if(W.length>0)Z.push(W)}}for(let G of J.split("/")){if(G.length===0||G===".")continue;if(G===".."){Z.pop();continue}let W=V6(G);if(W.includes("/")||W.includes("\\"))throw l6.malformed(`percent-encoded separator in package reference segment ${c6(G)}`);if(W==="."||W==="..")throw l6.malformed(`percent-encoded traversal in package reference segment ${c6(G)}`);Z.push(W)}return{path:Z.join("/"),fragment:Q}}function Q$($){return V6($)}var K$=new TextEncoder;function V6($){let J=K$.encode($),Q=[],K=0;while(K<J.length){if(J[K]===37&&K+2<J.length){let Y=J[K+1],Z=J[K+2];if(m6(Y)&&m6(Z)){Q.push(b6(Y)<<4|b6(Z)),K+=3;continue}}Q.push(J[K]),K+=1}return new TextDecoder("utf-8",{fatal:!1}).decode(Uint8Array.from(Q))}function m6($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function b6($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}function c6($){return JSON.stringify($)}import{warn as d6}from"@mdgate/utils";var B6={OFFICE_DOCUMENT:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",STYLES:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",NUMBERING:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",FOOTNOTES:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",ENDNOTES:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"};class a{map;constructor($=new Map){this.map=$}get($){return this.map.get($)}internalTarget($){let J=this.map.get($);return J!==void 0&&J.mode==="internal"?J.target:void 0}entries(){return this.map.entries()}firstOfType($){let J,Q;for(let[K,Y]of this.map)if(Y.relType===$&&Y.mode==="internal"){if(J===void 0||K<J)J=K,Q=Y}return Q}}function H6($,J){let Q=$.optionalXmlPart(J);if(Q===void 0)return new a;let K=new Map;for(let Y of Q.descendants(H.PKG_RELS,"Relationship")){let Z=Y.attrAny("Id"),G=Y.attrAny("Target");if(Z===void 0||G===void 0)continue;let W=Y.attrAny("TargetMode"),X=W!==void 0&&W.toLowerCase()==="external"?"external":"internal",D=Y.attrAny("Type")??"",U=u(D)??D;K.set(Z,{target:G,relType:U,mode:X})}return new a(K)}function Y$($,J,Q,K){let Y=J.get(K);if(Y===void 0||Y.mode!=="internal")return;let Z;try{Z=p(Q,Y.target)}catch(W){d6(`skipping unresolvable relationship target ${JSON.stringify(Y.target)}: ${W instanceof Error?W.message:String(W)}`);return}let G=$.optionalPart(Z.path);if(G===void 0){d6(`relationship target ${Z.path} is missing`);return}return[Z.path,G]}function Z$($){let J=$.lastIndexOf("/");if(J>=0)return`${$.slice(0,J)}/_rels/${$.slice(J+1)}.rels`;return`_rels/${$}.rels`}var o6="http://schemas.openxmlformats.org/package/2006/content-types",j6="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",W$="http://schemas.openxmlformats.org/spreadsheetml/2006/main";function G$($){if($.length<4||$[0]!==80||$[1]!==75||$[2]!==3||$[3]!==4)return;try{return X$($)}catch{return}}function D$($){if(!v($))return;let J;try{J=T.open($)}catch{return}try{for(let Q of J.readRootStorage()){let K=Q.name;if(_(K,"WordDocument"))return"doc";if(_(K,"PowerPoint Document"))return"ppt";if(_(K,"Workbook")||_(K,"Book"))return"xls";if(_(K,"VisioDocument"))return"vsd";if(M$(K))return"hwp";if(F$(K))return"one"}}catch{return}return}function X$($){let J;try{J=f.open($)}catch{return}let Q=V$(J,"mimetype");if(Q!==void 0){let Y=N$(Q);if(Y===void 0)return;return n6(y6(Y))}try{let Z=H6(J,"_rels/.rels").firstOfType(B6.OFFICE_DOCUMENT);if(Z!==void 0){let G;try{G=p("",Z.target)}catch{G=void 0}if(G!==void 0){let W=P6(J,"[Content_Types].xml");if(W!==void 0){let D=B$(W,G.path);if(D!==void 0){let U=H$(D);if(U!==void 0)return U}}let X=P6(J,G.path);if(X!==void 0){let D=X.childElems()[0],U=D!==void 0?j$(D):void 0;if(U!==void 0)return U}return P$(G.path)}}}catch{}for(let[Y,Z]of[["word/document.xml","docx"],["ppt/presentation.xml","pptx"],["xl/workbook.xml","xlsx"],["xl/workbook.bin","xlsx"],["visio/document.xml","vsdx"],["Contents/content.hpf","hwpx"]])if(J.hasPart(Y))return Z;try{let Y=P6(J,"META-INF/manifest.xml");if(Y!==void 0){for(let Z of Y.descendants(j6,"file-entry"))if(Z.attr(j6,"full-path")==="/"){let G=Z.attr(j6,"media-type");if(G!==void 0)return n6(y6(G))}}}catch{}if(J.hasPart("META-INF/container.xml"))return"epub";let K=U$(J);if(K!==void 0)return K;return}function U$($){let J=$.partNames();if(J.length===0)return;let Q=!1,K=!1,Y=!1,Z=!1,G=!1,W=!1;for(let X of J){let D=X.toLowerCase();if(D.endsWith(".iwa")){if(Q=!0,D.endsWith("/document.iwa")||D==="document.iwa")Y=!0;if(D.includes("slide")||D.includes("masterslide"))G=!0;if(D.includes("calculationengine")||D.includes("tables/"))W=!0}if(D==="index.zip")K=!0;if(D==="index.xml"||D.endsWith("/index.xml")||D.endsWith("index.apxl"))Z=!0;if(D.endsWith("presentation.apxl"))G=!0}if(!Q&&!K&&!Z&&!G)return;if(!Q&&K&&!Z)return;if(!Y&&!K&&!Z&&!G&&!W)return;if(G&&!W)return"keynote";if(W&&!G)return"numbers";if(Y||Z)return"pages";return}function V$($,J){try{return $.optionalPart(J)}catch{return}}function P6($,J){try{return $.optionalXmlPart(J)}catch{return}}function n6($){switch($.endsWith("-template")?$.slice(0,-9):$){case"application/epub+zip":case"application/x-ibooks+zip":return"epub";case"application/vnd.oasis.opendocument.text":return"odt";case"application/vnd.oasis.opendocument.spreadsheet":return"ods";case"application/vnd.oasis.opendocument.presentation":return"odp";case"application/vnd.oasis.opendocument.graphics":return"odg";case"application/vnd.sun.xml.writer":return"odt";case"application/vnd.sun.xml.calc":return"ods";case"application/vnd.sun.xml.impress":return"odp";case"application/vnd.sun.xml.draw":return"odg";case"application/hwp+zip":case"application/vnd.hancom.hwpx":return"hwpx";default:return}}function B$($,J){let Q=`/${J}`;for(let Z of $.descendants(o6,"Override")){let G=Z.attrAny("PartName");if(G!==void 0&&_(G,Q)){let W=Z.attrAny("ContentType");if(W!==void 0)return W}}let K=J.lastIndexOf(".");if(K<0)return;let Y=J.slice(K+1);for(let Z of $.descendants(o6,"Default")){let G=Z.attrAny("Extension");if(G!==void 0&&_(G,Y))return Z.attrAny("ContentType")}return}function H$($){let J=$.toLowerCase();if(J.includes("wordprocessingml"))return"docx";if(J.includes("presentationml"))return"pptx";if(J.includes("spreadsheetml")||J.includes("ms-excel"))return"xlsx";if(J.includes("visio")||J.includes("vnd.ms-visio"))return"vsdx";return}function j$($){switch($.ns){case H.W:return"docx";case H.P:return"pptx";case W$:return"xlsx";default:return}}function P$($){if($.startsWith("word/"))return"docx";if($.startsWith("ppt/"))return"pptx";if($.startsWith("xl/"))return"xlsx";if($.startsWith("visio/"))return"vsdx";return}function M$($){let J=$.charCodeAt(0)===5?$.slice(1):$;return _($,"FileHeader")||_(J,"HwpSummaryInformation")||_($,"HWPDocumentInfo")}function F$($){return $.length>=7&&$.slice(0,7).toLowerCase()==="onenote"}function _($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function N$($){try{return new TextDecoder("utf-8",{fatal:!0}).decode($)}catch{return}}import{asciiStartsWith as J0,decode as i6,trim as S}from"@mdgate/utils";function R$($){if(I$($)){let J=A$($);if(J.length>1||J.length===1&&J0($,"From "))return{contentType:"application/mbox",headers:[],filename:void 0,bytes:new Uint8Array(0),parts:J.map((Q)=>s(Q))}}return s(O$($))}function _$($){let J=[],Q=(K)=>{J.push(K);for(let Y of K.parts)Q(Y)};return Q($),J}function Q0($){let J=W0($);if(J!==void 0){let Q=G0($,J);if(Q!==void 0&&r6(Q)&&!F6(Q))return Q}return O6($,(Q)=>r6(Q)&&!F6(Q))}function K0($){return O6($,(J)=>J.contentType==="text/plain"&&J.parts.length===0&&!F6(J))}function L$($){let J=Q0($),Q=K0($),K=[],Y=(Z)=>{if(Z.parts.length>0){for(let G of Z.parts)Y(G);return}if(Z===J||Z===Q)return;if(Y0(Z.contentType)||Z0(Z.contentType))return;K.push(Z)};return Y($),K}function J6($,J){let Q=J.toLowerCase();for(let K=$.headers.length-1;K>=0;K-=1)if($.headers[K].name===Q)return $.headers[K].value;return}function s($){let J=z$($),Q=w$(J.headers),K=N6(Q,"content-type")??"text/plain",Y=X0(K),Z=S$(Q,Y.params),G=(N6(Q,"content-transfer-encoding")??"7bit").trim().toLowerCase(),W=u$(J.body,G);if(Y0(Y.type)){let X=Y.params.get("boundary");if(X===void 0||X.length===0)return{contentType:Y.type,headers:Q,filename:Z,bytes:W,parts:[]};let U=l$(W,X).map((j)=>s(j));return{contentType:Y.type,headers:Q,filename:Z,bytes:new Uint8Array(0),parts:U}}if(Z0(Y.type)){let X=s(W);return{contentType:Y.type,headers:Q,filename:Z,bytes:W,parts:[X]}}return{contentType:Y.type,headers:Q,filename:Z,bytes:W,parts:[]}}function Y0($){return $.startsWith("multipart/")}function Z0($){return $==="message/rfc822"||$==="message/global"||$==="message/news"}function r6($){return $.contentType==="text/html"&&$.parts.length===0}function F6($){let J=J6($,"content-disposition");if(J===void 0)return!1;let Q=J.indexOf(";");return(Q<0?J:J.slice(0,Q)).trim().toLowerCase()==="attachment"}function O6($,J){if(J($))return $;for(let Q of $.parts){let K=O6(Q,J);if(K!==void 0)return K}return}function W0($){let J=J6($,"content-type");if($.contentType==="multipart/related"&&J!==void 0){let Q=X0(J).params.get("start");if(Q!==void 0&&Q.length>0)return D0(Q)}for(let Q of $.parts){let K=W0(Q);if(K!==void 0)return K}return}function G0($,J){let Q=J6($,"content-id");if(Q!==void 0&&D0(Q)===J)return $;for(let K of $.parts){let Y=G0(K,J);if(Y!==void 0)return Y}return}function D0($){let J=S($);if(J.startsWith("<")&&J.endsWith(">")&&J.length>=2)J=J.slice(1,-1);return J}function N6($,J){let Q=J.toLowerCase();for(let K=$.length-1;K>=0;K-=1)if($[K].name===Q)return $[K].value;return}function O$($){if($.length>=3&&$[0]===239&&$[1]===187&&$[2]===191)return $.subarray(3);return $}function I$($){return J0($,"From ")}function A$($){let J=[],Q=0;while(Q<$.length){if(R6($,Q))J.push(Q);Q=t($,Q)}if(J.length===0)return[];let K=[];for(let Y=0;Y<J.length;Y+=1){let Z=J[Y],G=t($,Z),W=Y+1<J.length?J[Y+1]:$.length;if(G>W)continue;K.push(q$($.subarray(G,W)))}return K}function R6($,J){return J+5<=$.length&&$[J]===70&&$[J+1]===114&&$[J+2]===111&&$[J+3]===109&&$[J+4]===32}function q$($){let J=0,Q=0;while(Q<$.length){if($[Q]===62&&R6($,Q+1))J+=1;Q=t($,Q)}if(J===0)return $;let K=new Uint8Array($.length-J),Y=0,Z=0;while(Y<$.length){if($[Y]===62&&R6($,Y+1))Y+=1;let G=t($,Y);K.set($.subarray(Y,G),Z),Z+=G-Y,Y=G}return K.subarray(0,Z)}function t($,J){while(J<$.length){let Q=$[J];if(J+=1,Q===10)return J;if(Q===13){if(J<$.length&&$[J]===10)J+=1;return J}}return J}function z$($){let J=T$($);if(J!==void 0)return{headers:$.subarray(0,J.sep),body:$.subarray(J.body)};if(k$($))return{headers:$,body:$.subarray($.length)};return{headers:$.subarray(0,0),body:$}}function T$($){let J=$.length;for(let Q=0;Q<J;Q+=1){let K=$[Q];if(K===10&&Q+1<$.length&&$[Q+1]===10)return{sep:Q+1,body:Q+2};if(K===13&&Q+1<$.length&&$[Q+1]===10){if(Q+3<$.length&&$[Q+2]===13&&$[Q+3]===10)return{sep:Q+2,body:Q+4};if(Q+2<$.length&&$[Q+2]===10)return{sep:Q+2,body:Q+3}}if(K===13&&Q+1<$.length&&$[Q+1]===13)return{sep:Q+1,body:Q+2}}return}function k$($){let J=0;while(J<$.length&&($[J]===32||$[J]===9))J+=1;if(J>=$.length)return!1;let Q=J;while(J<$.length&&$[J]!==13&&$[J]!==10&&$[J]!==58)J+=1;if(J>=$.length||$[J]!==58||J===Q)return!1;for(let K=Q;K<J;K+=1){let Y=$[K];if(!(Y>=65&&Y<=90||Y>=97&&Y<=122||Y>=48&&Y<=57||Y===45))return!1}return!0}function w$($){if($.length===0)return[];let J=C$(H0($)),Q=[],K=0;while(K<J.length){let Y=J.indexOf(`
|
|
3
|
-
`,K);if(Y<0)Y=J.length;let Z=J.slice(K,Y);if(Z.endsWith("\r"))Z=Z.slice(0,-1);if(K=Y+1,Z.length===0)continue;let G=Z.indexOf(":");if(G<=0)continue;let W=Z.slice(0,G).trim().toLowerCase();if(W.length===0)continue;let
|
|
4
|
-
`&&
|
|
5
|
-
`||K==="\r")&&
|
|
1
|
+
import{ConvertError as P}from"@mdgate/core";import{decode as h0,inflateRaw as u0,warn as u6}from"@mdgate/utils";import{ConvertError as C}from"@mdgate/core";var Z6=[208,207,17,224,161,177,26,225],y=4294967295,K6=4294967294,P0=4294967293,F0=4294967292,M0=4294967295,q=4294967290,I6=0;var q6=2,N0=5;class T{bytes;sectorSize;miniSectorSize;miniCutoff;fat;miniFat;entries;miniStream;constructor($,J,Q,K,Y,Z,G){this.bytes=$,this.sectorSize=J,this.miniSectorSize=Q,this.miniCutoff=K,this.fat=Y,this.miniFat=Z,this.entries=G}static open($){if($.length<512||!A6($,Z6))throw C.malformed("not an OLE2 compound file");let J=new DataView($.buffer,$.byteOffset,$.byteLength);if(J.getUint16(28,!0)!==65534)throw C.malformed("not an OLE2 compound file: bad byte order");let K=J.getUint16(30,!0);if(K!==9&&K!==12)throw C.malformed("not an OLE2 compound file: bad sector shift");let Y=1<<K,Z=J.getUint16(32,!0),G=Z===0?64:1<<Z,W=J.getUint16(26,!0),U=J.getUint32(44,!0),X=J.getUint32(48,!0),D=J.getUint32(56,!0)||4096,j=J.getUint32(60,!0),F=J.getUint32(64,!0),x=J.getUint32(68,!0),z=J.getUint32(72,!0),M=[];for(let V=0;V<109;V+=1){let O=J.getUint32(76+V*4,!0);if(O<=q)M.push(O)}let A=x,w=new Set;for(let V=0;V<z&&A<=q;V+=1){if(w.has(A))break;w.add(A);let O=Y6(A,Y),I=Y/4;if(O+Y>$.length)break;let c=new DataView($.buffer,$.byteOffset+O,Y);for(let E=0;E<I-1;E+=1){let g=c.getUint32(E*4,!0);if(g<=q)M.push(g)}A=c.getUint32((I-1)*4,!0)}if(M.length<U);let B=[],Q6=Math.min(M.length,U||M.length,1e6);for(let V=0;V<Q6;V+=1){let O=M[V],I=Y6(O,Y);if(I+Y>$.length)break;let c=new DataView($.buffer,$.byteOffset+I,Y),E=Y/4;for(let g=0;g<E;g+=1)B.push(c.getUint32(g*4,!0))}let _=Math.max(0,Math.floor(($.length+Y-1)/Y)-1);while(B.length>_){let V=B[B.length-1];if(V===0||V===F0||V===P0||V===y||V===K6)B.pop();else break}while(B.length>_&&B[B.length-1]===y)B.pop();if(B.length>_)throw C.malformed(`not an OLE2 compound file: Malformed FAT (FAT has ${B.length} entries, but file has only ${_} sectors)`);while(B.length<_)B.push(y);let l=[];if(F>0&&j<=q){let V=d($,B,Y,j,F*Y),O=new DataView(V.buffer,V.byteOffset,V.byteLength);for(let I=0;I+4<=V.length;I+=4)l.push(O.getUint32(I,!0))}let m=d($,B,Y,X,$.length),b=[];for(let V=0;V+128<=m.length;V+=128)b.push(_0(m,V,W));if(b.length===0||b[0].type!==N0)throw C.malformed("not an OLE2 compound file: missing root storage");return new T($,Y,G,D,B,l,b)}readRootStorage(){let $=this.entries[0];if($===void 0)return[];let J=[];return this.walkSiblings($.child,J),J}exists($){return this.lookup($)!==void 0}readStream($){let J=this.lookup($);if(J===void 0||J.type!==q6)throw C.missingPart($);return this.readEntryBytes(J,Number.MAX_SAFE_INTEGER)}lookup($){let J=$.split("/").filter((Y)=>Y.length>0);if(J.length===0)return this.entries[0];let Q=this.entries[0]?.child??M0,K;for(let Y of J){if(K=this.findChild(Q,Y),K===void 0)return;Q=K.child}return K}findChild($,J){let Q=new Set,K=[$];while(K.length>0){let Y=K.pop();if(Y>q||Q.has(Y))continue;Q.add(Y);let Z=this.entries[Y];if(Z===void 0||Z.type===I6)continue;if(L0(Z.name,J))return Z;K.push(Z.left,Z.right)}return}walkSiblings($,J){let Q=new Set,K=(Y)=>{if(Y>q||Q.has(Y))return;Q.add(Y);let Z=this.entries[Y];if(Z===void 0||Z.type===I6)return;K(Z.left),J.push({name:Z.name,type:Z.type}),K(Z.right)};K($)}readEntryBytes($,J){let Q=Math.min($.size,J);if($.size<this.miniCutoff&&$.type===q6)return this.readMiniChain($.start,Q);return d(this.bytes,this.fat,this.sectorSize,$.start,Q)}readMiniChain($,J){if(this.miniStream===void 0){let G=this.entries[0];this.miniStream=d(this.bytes,this.fat,this.sectorSize,G.start,G.size)}let Q=new Uint8Array(J),K=0,Y=$,Z=new Set;while(K<J&&Y<=q){if(Z.has(Y))break;Z.add(Y);let G=Y*this.miniSectorSize,W=Math.min(this.miniSectorSize,J-K);if(G+W>this.miniStream.length)break;Q.set(this.miniStream.subarray(G,G+W),K),K+=W,Y=this.miniFat[Y]??K6}return K===J?Q:Q.subarray(0,K)}}var R0=Z6;function v($){return A6($,Z6)}function A6($,J){if($.length<J.length)return!1;for(let Q=0;Q<J.length;Q+=1)if($[Q]!==J[Q])return!1;return!0}function L0($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function Y6($,J){return($+1)*J}function d($,J,Q,K,Y){if(K>q||Y<=0)return new Uint8Array(0);let Z=[],G=0,W=K,U=new Set;while(G<Y&&W<=q){if(U.has(W)||U.size>1e6)break;U.add(W);let X=Y6(W,Q);if(X>=$.length)break;let D=Math.min(Q,Y-G,$.length-X);if(D<=0)break;if(Z.push($.subarray(X,X+D)),G+=D,W=J[W]??K6,W===y)break}return O0(Z,G)}function _0($,J,Q){let K=new DataView($.buffer,$.byteOffset+J,128),Y=K.getUint16(64,!0),Z=Math.max(0,Math.min(64,Y>0?Y-2:0)),G=new TextDecoder("utf-16le").decode($.subarray(J,J+Z)),W=$[J+66]??0,U=K.getUint32(68,!0),X=K.getUint32(72,!0),D=K.getUint32(76,!0),j=K.getUint32(116,!0),F=Number(K.getBigUint64(120,!0));if(Q===3)F=K.getUint32(120,!0);if(!Number.isFinite(F)||F<0)F=0;return{name:G,type:W,left:U,right:X,child:D,start:j,size:F}}function O0($,J){if($.length===1&&$[0].length===J)return $[0];let Q=new Uint8Array(J),K=0;for(let Y of $)Q.set(Y,K),K+=Y.length;return Q}import{ConvertError as I0}from"@mdgate/core";import{debug as z6,decode as q0,encodingExists as A0,warn as z0}from"@mdgate/utils";var H={W:"http://schemas.openxmlformats.org/wordprocessingml/2006/main",R:"http://schemas.openxmlformats.org/officeDocument/2006/relationships",A:"http://schemas.openxmlformats.org/drawingml/2006/main",PIC:"http://schemas.openxmlformats.org/drawingml/2006/picture",WP:"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing",MC:"http://schemas.openxmlformats.org/markup-compatibility/2006",CHART:"http://schemas.openxmlformats.org/drawingml/2006/chart",DGM:"http://schemas.openxmlformats.org/drawingml/2006/diagram",P:"http://schemas.openxmlformats.org/presentationml/2006/main",PKG_RELS:"http://schemas.openxmlformats.org/package/2006/relationships",OFFICE:"urn:oasis:names:tc:opendocument:xmlns:office:1.0",TEXT:"urn:oasis:names:tc:opendocument:xmlns:text:1.0",TABLE:"urn:oasis:names:tc:opendocument:xmlns:table:1.0",DRAW:"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0",STYLE:"urn:oasis:names:tc:opendocument:xmlns:style:1.0",FO:"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0",PRESENTATION:"urn:oasis:names:tc:opendocument:xmlns:presentation:1.0",MANIFEST:"urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",XLINK:"http://www.w3.org/1999/xlink",XML:"http://www.w3.org/XML/1998/namespace",SVG_COMPAT:"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0",VML:"urn:schemas-microsoft-com:vml",O_VML:"urn:schemas-microsoft-com:office:office",WPS:"http://schemas.microsoft.com/office/word/2010/wordprocessingShape",WPG:"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"},T0=H.XML,k0="http://www.w3.org/2000/xmlns/",w6=[];class n{ns;local;attrs;children;_elems;constructor($,J,Q=w6,K=[]){this.ns=$,this.local=J,this.attrs=Q,this.children=K}is($,J){return this.local===J&&this.ns===$}attr($,J){return this.attrQualified($,J)??this.attrUnqualified(J)}attrQualified($,J){let Q=this.attrs;for(let K=0;K<Q.length;K+=1){let Y=Q[K];if(Y.local===J&&Y.ns===$)return Y.value}return}attrUnqualified($){let J=this.attrs;for(let Q=0;Q<J.length;Q+=1){let K=J[Q];if(K.local===$&&K.ns===void 0)return K.value}return}attrAny($){let J=this.attrs;for(let Q=0;Q<J.length;Q+=1){let K=J[Q];if(K.local===$)return K.value}return}childElems(){if(this._elems!==void 0)return this._elems;let $=[],J=this.children;for(let Q=0;Q<J.length;Q+=1){let K=J[Q];if(K.type==="elem")$.push(K.elem)}return this._elems=$,$}find($,J){let Q=this.children;for(let K=0;K<Q.length;K+=1){let Y=Q[K];if(Y.type==="elem"&&Y.elem.local===J&&Y.elem.ns===$)return Y.elem}return}findAll($,J){let Q=[],K=this.children;for(let Y=0;Y<K.length;Y+=1){let Z=K[Y];if(Z.type==="elem"&&Z.elem.local===J&&Z.elem.ns===$)Q.push(Z.elem)}return Q}*descendantNodes(){let $=this.children.slice();$.reverse();while($.length>0){let J=$.pop();if(J.type==="elem"){let Q=$.length;for(let K of J.elem.children)$.push(K);E0($,Q)}yield J}}*descendantElems(){for(let $ of this.descendantNodes())if($.type==="elem")yield $.elem}firstDescendant($,J){for(let Q of this.descendantElems())if(Q.is($,J))return Q;return}*descendants($,J){for(let Q of this.descendantElems())if(Q.is($,J))yield Q}*descendantsAny($){for(let J of this.descendantElems())if(J.local===$)yield J}text(){let $="";for(let J of this.descendantNodes())if(J.type==="text")$+=J.text;return $}}class g6{prefixes=[new Map];ownsMap=[!0];defaultNs=[void 0];push(){this.prefixes.push(this.prefixes[this.prefixes.length-1]),this.ownsMap.push(!1),this.defaultNs.push(this.defaultNs[this.defaultNs.length-1])}pop(){this.prefixes.pop(),this.ownsMap.pop(),this.defaultNs.pop()}applyDecls($){for(let J of $)if(J.rawName==="xmlns")this.defaultNs[this.defaultNs.length-1]=J.value.length===0?void 0:J.value;else if(J.rawName.startsWith("xmlns:")){if(!this.ownsMap[this.ownsMap.length-1])this.prefixes[this.prefixes.length-1]=new Map(this.prefixes[this.prefixes.length-1]),this.ownsMap[this.ownsMap.length-1]=!0;let Q=J.rawName.slice(6);this.prefixes[this.prefixes.length-1].set(Q,J.value.length===0?void 0:J.value)}}lookupPrefix($){if($==="xml")return T0;if($==="xmlns")return k0;return this.prefixes[this.prefixes.length-1].get($)}resolveElement($){let J=$.indexOf(":");if(J>=0){let K=$.slice(0,J),Y=$.slice(J+1),Z=this.lookupPrefix(K);return{ns:Z,local:Y,bound:Z!==void 0||K==="xml"||K==="xmlns"}}let Q=this.defaultNs[this.defaultNs.length-1];return{ns:Q,local:$,bound:Q!==void 0}}resolveAttribute($){let J=$.indexOf(":");if(J>=0){let Q=$.slice(0,J),K=$.slice(J+1);return{ns:this.lookupPrefix(Q),local:K}}return{ns:void 0,local:$}}}function u($){let J=v0($,"http://purl.oclc.org/ooxml/");if(J===void 0)return;let Q=J.indexOf("/");if(Q<0)return;let K=J.slice(0,Q),Y=J.slice(Q+1);return`http://schemas.openxmlformats.org/${K}/2006/${Y}`}function C6($){switch($){case"http://openoffice.org/2000/office":case"http://openoffice.org/2001/office":return H.OFFICE;case"http://openoffice.org/2000/text":return H.TEXT;case"http://openoffice.org/2000/table":return H.TABLE;case"http://openoffice.org/2000/drawing":return H.DRAW;case"http://openoffice.org/2000/presentation":return H.PRESENTATION;case"http://openoffice.org/2000/style":return H.STYLE;case"http://openoffice.org/2001/manifest":case"http://openoffice.org/2000/manifest":return H.MANIFEST;case"http://www.w3.org/1999/XSL/Format":return H.FO;default:return}}var S6=0,x6=1,E6=2,h=3,X6=4,v6=5;function i($){let J=g0($),Q=new h6(J),K=new g6,Y=new Map,Z=new Map,G=new n(void 0,""),W=[],U=!1;for(;;){let X;try{X=Q.next()}catch(D){let j=D instanceof Error?D.message:String(D);throw I0.malformed(`unparseable xml: ${j}`)}switch(X){case x6:{K.push(),K.applyDecls(Q.attrs);let D=w0(Q.name,Q.attrs,K,Y,Z);if(Q.empty)W6(W,G,{type:"elem",elem:D}),K.pop();else W.push(D);break}case E6:{let D=W.pop();if(D===void 0)U=!0;else{if(D.local!==Q.local)U=!0;W6(W,G,{type:"elem",elem:D}),K.pop()}break}case h:{if(Q.text.length>0)G6(W,G,Q.text);break}case X6:{let D=U6(Q.name)??`&${Q.name};`;G6(W,G,D);break}case v6:{G6(W,G,Q.text);break}case S6:if(W.length>0){U=!0;while(W.length>0)W6(W,G,{type:"elem",elem:W.pop()})}if(U)z0("recovered malformed xml (unclosed or mismatched elements)");return G}}}function W6($,J,Q){let K=$[$.length-1];if(K!==void 0)K.children.push(Q);else J.children.push(Q)}function G6($,J,Q){let K=$[$.length-1]?.children??J.children,Y=K[K.length-1];if(Y?.type==="text")Y.text+=Q;else K.push({type:"text",text:Q})}function T6($,J){let Q=$.get(J);if(Q!==void 0)return Q;let K=u(J)??C6(J)??J;return $.set(J,K),K}function k6($,J){let Q=$.get(J);if(Q!==void 0)return Q;return $.set(J,J),J}function w0($,J,Q,K,Y){let Z=Q.resolveElement($),G=Z.ns!==void 0?T6(K,Z.ns):void 0,W=w6,U=!1;for(let X of J){if(X.rawName==="xmlns"||X.rawName.startsWith("xmlns:"))continue;let D=Q.resolveAttribute(X.rawName);if(!U)W=[],U=!0;W.push({ns:D.ns!==void 0?T6(K,D.ns):void 0,local:k6(Y,D.local),value:X.value})}if(Z.local==="Choice"&&G===H.MC){let X=W.find((D)=>D.local==="Requires");if(X!==void 0)X.value=X.value.split(/\s+/).filter((D)=>D.length>0).map((D)=>{let j=Q.resolveElement(`${D}:x`);if(j.bound&&j.ns!==void 0)return u(j.ns)??j.ns;return D}).join(" ")}return new n(G,k6(Y,Z.local),W)}function g0($){if($.length>=2&&$[0]===255&&$[1]===254)return new TextDecoder("utf-16le").decode($);if($.length>=2&&$[0]===254&&$[1]===255)return new TextDecoder("utf-16be").decode($);if($.length>=3&&$[0]===239&&$[1]===187&&$[2]===191)return new TextDecoder("utf-8").decode($.subarray(3));let J=$.subarray(0,Math.min($.length,200)),Q=C0(J);if(Q!==void 0){let K=S0(Q);if(K!==void 0&&K!=="utf8"&&K!=="utf-8")return q0($,K)}return new TextDecoder("utf-8").decode($)}function C0($){let J;try{J=new TextDecoder("utf-8",{fatal:!0}).decode($)}catch{return}let Q=J.indexOf("encoding");if(Q<0)return;let K=J.slice(Q+8).trimStart();if(!K.startsWith("="))return;K=K.slice(1).trimStart();let Y=K[0];if(Y!=='"'&&Y!=="'")return;K=K.slice(1);let Z=K.indexOf(Y);if(Z<0)return;return K.slice(0,Z)}function S0($){let J=$.trim().toLowerCase().replace(/_/g,"-"),K={"utf-8":"utf8",utf8:"utf8","utf-16":"utf16-le","utf-16le":"utf16-le","utf-16be":"utf16-be","iso-8859-1":"iso-8859-1","latin-1":"iso-8859-1",latin1:"iso-8859-1","windows-1252":"windows-1252","cp-1252":"windows-1252",cp1252:"windows-1252","windows-1251":"windows-1251","windows-1250":"windows-1250","windows-874":"windows-874",gbk:"gbk",gb2312:"gb2312",gb18030:"gb18030",big5:"big5","shift-jis":"shiftjis",shiftjis:"shiftjis","euc-jp":"euc-jp","euc-kr":"euc-kr",koi8r:"koi8-r","koi8-r":"koi8-r"}[J]??J;return A0(K)?K:void 0}function U6($){if($.startsWith("#")){let Q=$.slice(1),K=Q.startsWith("x")||Q.startsWith("X"),Y=K?Q.slice(1):Q,Z=Number.parseInt(Y,K?16:10);if(!Number.isFinite(Z))return;try{return String.fromCodePoint(Z)}catch{return}}return{amp:"&",lt:"<",gt:">",apos:"'",quot:'"',nbsp:" ",shy:"",mdash:"—",ndash:"–",lsquo:"‘",rsquo:"’",ldquo:"“",rdquo:"”",hellip:"…",copy:"©",reg:"®",trade:"™",deg:"°",middot:"·",bull:"•",sect:"§",para:"¶",laquo:"«",raquo:"»",times:"×",divide:"÷",plusmn:"±",frac12:"½",frac14:"¼",eacute:"é",egrave:"è",agrave:"à",ccedil:"ç",uuml:"ü",ouml:"ö",auml:"ä",szlig:"ß",aring:"å",oslash:"ø",aelig:"æ",euro:"€",pound:"£",yen:"¥",cent:"¢"}[$]}class h6{s;i=0;name="";local="";text="";empty=!1;attrs=[];constructor($){this.s=$}next(){if(this.i>=this.s.length)return S6;if(this.s.charCodeAt(this.i)===60)return this.markup();return this.textRun()}markup(){if(this.startsWith("<?"))return this.skipUntil("?>"),this.next();if(this.startsWith("<!--")){this.i+=4;let $=this.s.indexOf("-->",this.i);if($<0)throw Error("unterminated comment");return this.i=$+3,this.next()}if(this.startsWith("<![CDATA[")){this.i+=9;let $=this.s.indexOf("]]>",this.i);if($<0)throw Error("unterminated cdata");return this.text=this.s.slice(this.i,$),this.i=$+3,v6}if(this.startsWith("<!"))return this.skipDoctype(),this.next();if(this.startsWith("</")){this.i+=2;let $=this.readName();if(this.skipWs(),this.s[this.i]===">")this.i+=1;return this.local=x0($),E6}if(this.i+=1,this.name=this.readName(),this.attrs=this.readAttrs(),this.skipWs(),this.empty=!1,this.s[this.i]==="/"&&this.s[this.i+1]===">")this.i+=2,this.empty=!0;else if(this.s[this.i]===">")this.i+=1;return x6}textRun(){let $=this.i;while(this.i<this.s.length){let J=this.s.charCodeAt(this.i);if(J===60)break;if(J===38){if(this.i>$)return this.text=this.s.slice($,this.i),h;let Q=this.readReference();if(Q.type==="general")return this.name=Q.name,X6;return this.i=$,this.textRunSlow()}this.i+=1}return this.text=this.s.slice($,this.i),h}textRunSlow(){let $="";while(this.i<this.s.length){let J=this.s.charCodeAt(this.i);if(J===60)break;if(J===38){let K=this.readReference();if(K.type==="general"){if($.length>0)return this.i=K.rewind,this.text=$,h;return this.name=K.name,X6}$+=K.text;continue}let Q=this.i;this.i+=1;while(this.i<this.s.length){let K=this.s.charCodeAt(this.i);if(K===60||K===38)break;this.i+=1}$+=this.s.slice(Q,this.i)}return this.text=$,h}readReference(){let $=this.i;this.i+=1;let J=this.s.indexOf(";",this.i);if(J<0)return{type:"char",text:"&"};let Q=this.s.slice(this.i,J);if(this.i=J+1,Q.startsWith("#")||Q==="amp"||Q==="lt"||Q==="gt"||Q==="apos"||Q==="quot")return{type:"char",text:U6(Q)??`&${Q};`};return{type:"general",name:Q,rewind:$}}readName(){let $=this.i;while(this.i<this.s.length){let J=this.s.charCodeAt(this.i);if(J===47||J===62||J===61||J===32||J===9||J===10||J===13)break;this.i+=1}return this.s.slice($,this.i)}readAttrs(){let $=[];for(;;){this.skipWs();let J=this.s[this.i];if(J===void 0||J===">"||J==="/")break;let Q=this.readName();if(Q.length===0){this.i+=1;continue}if(this.skipWs(),this.s[this.i]!=="="){z6(`dropping undecodable attribute: ${Q}`);continue}this.i+=1,this.skipWs();let K=this.readAttrValue();if(K===void 0){z6(`dropping undecodable attribute: ${Q}`);continue}$.push({rawName:Q,value:K})}return $}readAttrValue(){let $=this.s.charCodeAt(this.i);if($!==34&&$!==39)return;this.i+=1;let J=this.i,Q=!1;while(this.i<this.s.length){let Y=this.s.charCodeAt(this.i);if(Y===$){let Z=this.s.slice(J,this.i);return this.i+=1,Q?o(Z):Z}if(Y===38)return this.i=J,this.readAttrValueSlow($);if(Y===9||Y===10||Y===13)Q=!0;this.i+=1}let K=this.s.slice(J,this.i);return Q?o(K):K}readAttrValueSlow($){let J="";while(this.i<this.s.length){let Q=this.s.charCodeAt(this.i);if(Q===$)return this.i+=1,o(J);if(Q===38){let Y=this.readReference();if(Y.type==="char")J+=Y.text;else J+=U6(Y.name)??`&${Y.name};`;continue}let K=this.i;this.i+=1;while(this.i<this.s.length){let Y=this.s.charCodeAt(this.i);if(Y===$||Y===38)break;this.i+=1}J+=this.s.slice(K,this.i)}return o(J)}skipWs(){while(this.i<this.s.length){let $=this.s.charCodeAt(this.i);if($!==32&&$!==9&&$!==10&&$!==13)break;this.i+=1}}startsWith($){return this.s.startsWith($,this.i)}skipUntil($){let J=this.s.indexOf($,this.i);this.i=J<0?this.s.length:J+$.length}skipDoctype(){this.i+=2;let $=0;while(this.i<this.s.length){let J=this.s[this.i];if(J==='"'||J==="'"){let Q=J;this.i+=1;while(this.i<this.s.length&&this.s[this.i]!==Q)this.i+=1;if(this.i<this.s.length)this.i+=1;continue}if(J==="<")$+=1;else if(J===">"){if($===0){this.i+=1;return}$-=1}this.i+=1}}}function x0($){let J=$.indexOf(":");return J<0?$:$.slice(J+1)}function o($){if($.indexOf("\t")<0&&$.indexOf(`
|
|
2
|
+
`)<0&&$.indexOf("\r")<0)return $;return $.replace(/[\t\n\r]/g," ")}function E0($,J){let Q=J,K=$.length-1;while(Q<K){let Y=$[Q];$[Q]=$[K],$[K]=Y,Q+=1,K-=1}}function v0($,J){return $.startsWith(J)?$.slice(J.length):void 0}var f0=67324752,p0=33639248;var l0=101075792,m0=117853008,b0=0,c0=8,d0=99,y0=25451,o0=25452;function p6($){return $===d0||$===y0||$===o0}class D6{length;bytes;byName=new Map;constructor($,J){this.bytes=$,this.length=J.length;for(let Q of J)if(!this.byName.has(Q.name))this.byName.set(Q.name,Q)}static open($){let J=r0($);if(J<0)throw P.malformed("not a readable zip archive: invalid Zip archive: Could not find EOCD");let Q=r($),K=N(Q,J+10),Y=R(Q,J+12),Z=R(Q,J+16);if(K===65535||Y===4294967295||Z===4294967295){let X=a0($,J);if(X!==void 0)K=X.entryCount,Y=X.cdSize,Z=X.cdOffset}if(Z+Y>$.length)throw P.malformed("not a readable zip archive: truncated central directory");let G=[],W=Z,U=Math.min($.length,Z+Y);while(W+46<=U&&G.length<K){if(R(Q,W)!==p0)throw P.malformed("not a readable zip archive: bad central directory");let X=N(Q,W+8),D=N(Q,W+10),j=R(Q,W+16),F=R(Q,W+20),x=R(Q,W+24),z=N(Q,W+28),M=N(Q,W+30),A=N(Q,W+32),w=R(Q,W+42),B=$.subarray(W+46,W+46+z);if(W+46+z+M+A>$.length)throw P.malformed("not a readable zip archive: truncated entry");let Q6=$.subarray(W+46+z,W+46+z+M),_=s0(Q6,{uncompressedSize:x,compressedSize:F,headerOffset:w});x=_.uncompressedSize,F=_.compressedSize,w=_.headerOffset;let l=(X&2048)!==0,m=t0(B,l);G.push({name:m,method:D,flags:X,crc:j,compressedSize:F,uncompressedSize:x,headerOffset:w}),W+=46+z+M+A}return new D6($,G)}indexForName($){return this.byName.get($)}partNames(){return[...this.byName.keys()]}hasEncryptedEntries(){for(let $ of this.byName.values()){if(($.flags&1)!==0)return!0;if(p6($.method))return!0}return!1}readCompressed($){let J=r(this.bytes),Q=$.headerOffset;if(Q+30>this.bytes.length||R(J,Q)!==f0)throw Error("bad local file header");let K=N(J,Q+26),Y=N(J,Q+28),Z=Q+30+K+Y,G=Z+$.compressedSize;if(Z>this.bytes.length)throw Error("truncated local file header");if($.compressedSize>0&&G>this.bytes.length)throw Error("truncated compressed data");return this.bytes.subarray(Z,Math.min(G,this.bytes.length))}}class f{zip;cache=new Map;constructor($){this.zip=$}static open($){let J;try{J=D6.open($)}catch(Q){if(Q instanceof P)throw Q;let K=Q instanceof Error?Q.message:String(Q);throw P.malformed(`not a readable zip archive: ${K}`)}return new f(J)}part($){$=f6($);let J=this.cache.get($);if(J!==void 0)return J;let Q=this.zip.indexForName($);if(Q===void 0)return;let K;try{K=this.decompress(Q,Number.MAX_SAFE_INTEGER)}catch(Y){if(Y instanceof P)throw Y;let Z=Y instanceof Error?Y.message:String(Y);throw P.malformedPart($,`corrupt archive entry: ${Z}`)}return this.cache.set($,K),K}hasPart($){return this.zip.indexForName(f6($))!==void 0}partNames(){return this.zip.partNames()}hasEncryptedEntries(){return this.zip.hasEncryptedEntries()}requiredPart($){let J=this.part($);if(J===void 0)throw P.missingPart($);return J}optionalPart($){try{return this.part($)}catch(J){if(J instanceof P&&J.isFatal())throw J;u6(`skipping unreadable part ${$}: ${J instanceof Error?J.message:String(J)}`);return}}optionalXmlPart($){let J=this.optionalPart($);if(J===void 0)return;try{return i(J)}catch(Q){if(Q instanceof P&&Q.isFatal())throw Q;u6(`skipping corrupt part ${$}: ${Q instanceof Error?Q.message:String(Q)}`);return}}requiredXmlPart($){return i(this.requiredPart($))}decompress($,J){if(($.flags&1)!==0||p6($.method))throw P.encrypted();let Q;try{Q=this.zip.readCompressed($)}catch(Y){let Z=Y instanceof Error?Y.message:String(Y);throw P.malformedPart($.name,`unreadable archive entry: ${Z}`)}let K;if($.method===b0){let Y=$.uncompressedSize>0?$.uncompressedSize:Q.length;K=Q.subarray(0,Math.min(Y,Q.length))}else if($.method===c0)K=i0(Q,J);else throw Error(`unsupported compression method ${$.method}`);if(K.length<=J-1&&$.crc!==0&&Q$(K)!==$.crc)throw Error("crc mismatch");return K}}function n0($){if(!v($))return;try{let J=T.open($);if(J.exists("EncryptionInfo")||J.exists("EncryptedPackage"))return P.encrypted()}catch{}return P.malformed("OLE compound document where an OOXML package was expected (legacy binary format?)")}function i0($,J){return u0($,J)}function r0($){let J=Math.max(0,$.length-65557);for(let Q=$.length-22;Q>=J;Q-=1)if($[Q]===80&&$[Q+1]===75&&$[Q+2]===5&&$[Q+3]===6){let K=$[Q+20]|$[Q+21]<<8;if(Q+22+K===$.length)return Q}return-1}function a0($,J){if(J<20)return;let Q=r($),K=J-20;if(R(Q,K)!==m0)return;let Y=k(Q,K+8);if(Y+56>$.length||R(Q,Y)!==l0)return;return{entryCount:k(Q,Y+32),cdSize:k(Q,Y+40),cdOffset:k(Q,Y+48)}}function s0($,J){let Q=0,K=r($);while(Q+4<=$.length){let Y=N(K,Q),Z=N(K,Q+2),G=Q+4;if(G+Z>$.length)break;if(Y===1){let W=G,{uncompressedSize:U,compressedSize:X,headerOffset:D}=J;if(U===4294967295&&W+8<=G+Z)U=k(K,W),W+=8;if(X===4294967295&&W+8<=G+Z)X=k(K,W),W+=8;if(D===4294967295&&W+8<=G+Z)D=k(K,W);return{uncompressedSize:U,compressedSize:X,headerOffset:D}}Q=G+Z}return J}function t0($,J){if(J)return new TextDecoder("utf-8",{fatal:!1}).decode($);return h0($,"cp437")}function f6($){let J=0;while(J<$.length&&$.charCodeAt(J)===47)J+=1;return $.slice(J)}function r($){return new DataView($.buffer,$.byteOffset,$.byteLength)}function N($,J){return $.getUint16(J,!0)}function R($,J){return $.getUint32(J,!0)}function k($,J){let Q=$.getUint32(J,!0),K=$.getUint32(J+4,!0);if(K>2097151)return Number.POSITIVE_INFINITY;return K*4294967296+Q}var e0=$$();function $$(){let $=new Uint32Array(256);for(let J=0;J<256;J+=1){let Q=J;for(let K=0;K<8;K+=1)Q=Q&1?3988292384^Q>>>1:Q>>>1;$[J]=Q>>>0}return $}function J$($){let J=4294967295;for(let Q=0;Q<$.length;Q+=1)J=e0[(J^$[Q])&255]^J>>>8;return(J^4294967295)>>>0}function Q$($){return J$($)}import{ConvertError as l6}from"@mdgate/core";function K$($,J){if(!Number.isSafeInteger(J)||J<0||J+2>$.length)return;return $[J]|$[J+1]<<8}function Y$($,J){if(!Number.isSafeInteger(J)||J<0||J+4>$.length)return;return($[J]|$[J+1]<<8|$[J+2]<<16|$[J+3]<<24)>>>0}function Z$($,J){try{return $.readStream(J)}catch(Q){if(Q instanceof l6)throw Q;let K=Q instanceof Error?Q.message:String(Q);throw l6.malformedPart(J,`unreadable stream: ${K}`)}}import{trim as o6}from"@mdgate/utils";import{ConvertError as m6}from"@mdgate/core";function p($,J){let Q,K=J.indexOf("#");if(K>=0)Q=V6(J.slice(K+1)),J=J.slice(0,K);let Y=J.indexOf("?");if(Y>=0)J=J.slice(0,Y);if(J.length===0)return{path:$,fragment:Q};let Z=[];if(!J.startsWith("/")){let G=$.lastIndexOf("/");if(G>=0){for(let W of $.slice(0,G).split("/"))if(W.length>0)Z.push(W)}}for(let G of J.split("/")){if(G.length===0||G===".")continue;if(G===".."){Z.pop();continue}let W=V6(G);if(W.includes("/")||W.includes("\\"))throw m6.malformed(`percent-encoded separator in package reference segment ${d6(G)}`);if(W==="."||W==="..")throw m6.malformed(`percent-encoded traversal in package reference segment ${d6(G)}`);Z.push(W)}return{path:Z.join("/"),fragment:Q}}function W$($){return V6($)}var G$=new TextEncoder;function V6($){let J=G$.encode($),Q=[],K=0;while(K<J.length){if(J[K]===37&&K+2<J.length){let Y=J[K+1],Z=J[K+2];if(b6(Y)&&b6(Z)){Q.push(c6(Y)<<4|c6(Z)),K+=3;continue}}Q.push(J[K]),K+=1}return new TextDecoder("utf-8",{fatal:!1}).decode(Uint8Array.from(Q))}function b6($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function c6($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}function d6($){return JSON.stringify($)}import{warn as y6}from"@mdgate/utils";var B6={OFFICE_DOCUMENT:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",STYLES:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",NUMBERING:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",FOOTNOTES:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",ENDNOTES:"http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes"};class a{map;constructor($=new Map){this.map=$}get($){return this.map.get($)}internalTarget($){let J=this.map.get($);return J!==void 0&&J.mode==="internal"?J.target:void 0}entries(){return this.map.entries()}firstOfType($){let J,Q;for(let[K,Y]of this.map)if(Y.relType===$&&Y.mode==="internal"){if(J===void 0||K<J)J=K,Q=Y}return Q}}function H6($,J){let Q=$.optionalXmlPart(J);if(Q===void 0)return new a;let K=new Map;for(let Y of Q.descendants(H.PKG_RELS,"Relationship")){let Z=Y.attrAny("Id"),G=Y.attrAny("Target");if(Z===void 0||G===void 0)continue;let W=Y.attrAny("TargetMode"),U=W!==void 0&&W.toLowerCase()==="external"?"external":"internal",X=Y.attrAny("Type")??"",D=u(X)??X;K.set(Z,{target:G,relType:D,mode:U})}return new a(K)}function X$($,J,Q,K){let Y=J.get(K);if(Y===void 0||Y.mode!=="internal")return;let Z;try{Z=p(Q,Y.target)}catch(W){y6(`skipping unresolvable relationship target ${JSON.stringify(Y.target)}: ${W instanceof Error?W.message:String(W)}`);return}let G=$.optionalPart(Z.path);if(G===void 0){y6(`relationship target ${Z.path} is missing`);return}return[Z.path,G]}function U$($){let J=$.lastIndexOf("/");if(J>=0)return`${$.slice(0,J)}/_rels/${$.slice(J+1)}.rels`;return`_rels/${$}.rels`}var n6="http://schemas.openxmlformats.org/package/2006/content-types",j6="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",D$="http://schemas.openxmlformats.org/spreadsheetml/2006/main";function V$($){if($.length<4||$[0]!==80||$[1]!==75||$[2]!==3||$[3]!==4)return;try{return H$($)}catch{return}}function B$($){if(!v($))return;let J;try{J=T.open($)}catch{return}try{for(let Q of J.readRootStorage()){let K=Q.name;if(L(K,"WordDocument"))return"doc";if(L(K,"PowerPoint Document"))return"ppt";if(L(K,"Workbook")||L(K,"Book"))return"xls";if(L(K,"VisioDocument"))return"vsd";if(L$(K))return"hwp";if(_$(K))return"one"}}catch{return}return}function H$($){let J;try{J=f.open($)}catch{return}let Q=P$(J,"mimetype");if(Q!==void 0){let Y=O$(Q);if(Y===void 0)return;return i6(o6(Y))}try{let Z=H6(J,"_rels/.rels").firstOfType(B6.OFFICE_DOCUMENT);if(Z!==void 0){let G;try{G=p("",Z.target)}catch{G=void 0}if(G!==void 0){let W=P6(J,"[Content_Types].xml");if(W!==void 0){let X=F$(W,G.path);if(X!==void 0){let D=M$(X);if(D!==void 0)return D}}let U=P6(J,G.path);if(U!==void 0){let X=U.childElems()[0],D=X!==void 0?N$(X):void 0;if(D!==void 0)return D}return R$(G.path)}}}catch{}for(let[Y,Z]of[["word/document.xml","docx"],["ppt/presentation.xml","pptx"],["xl/workbook.xml","xlsx"],["xl/workbook.bin","xlsx"],["visio/document.xml","vsdx"],["Contents/content.hpf","hwpx"]])if(J.hasPart(Y))return Z;try{let Y=P6(J,"META-INF/manifest.xml");if(Y!==void 0){for(let Z of Y.descendants(j6,"file-entry"))if(Z.attr(j6,"full-path")==="/"){let G=Z.attr(j6,"media-type");if(G!==void 0)return i6(o6(G))}}}catch{}if(J.hasPart("META-INF/container.xml"))return"epub";let K=j$(J);if(K!==void 0)return K;return}function j$($){let J=$.partNames();if(J.length===0)return;let Q=!1,K=!1,Y=!1,Z=!1,G=!1,W=!1;for(let U of J){let X=U.toLowerCase();if(X.endsWith(".iwa")){if(Q=!0,X.endsWith("/document.iwa")||X==="document.iwa")Y=!0;if(X.includes("slide")||X.includes("masterslide"))G=!0;if(X.includes("calculationengine")||X.includes("tables/"))W=!0}if(X==="index.zip")K=!0;if(X==="index.xml"||X.endsWith("/index.xml")||X.endsWith("index.apxl"))Z=!0;if(X.endsWith("presentation.apxl"))G=!0}if(!Q&&!K&&!Z&&!G)return;if(!Q&&K&&!Z)return;if(!Y&&!K&&!Z&&!G&&!W)return;if(G&&!W)return"keynote";if(W&&!G)return"numbers";if(Y||Z)return"pages";return}function P$($,J){try{return $.optionalPart(J)}catch{return}}function P6($,J){try{return $.optionalXmlPart(J)}catch{return}}function i6($){switch($.endsWith("-template")?$.slice(0,-9):$){case"application/epub+zip":case"application/x-ibooks+zip":return"epub";case"application/vnd.oasis.opendocument.text":return"odt";case"application/vnd.oasis.opendocument.spreadsheet":return"ods";case"application/vnd.oasis.opendocument.presentation":return"odp";case"application/vnd.oasis.opendocument.graphics":return"odg";case"application/vnd.sun.xml.writer":return"odt";case"application/vnd.sun.xml.calc":return"ods";case"application/vnd.sun.xml.impress":return"odp";case"application/vnd.sun.xml.draw":return"odg";case"application/hwp+zip":case"application/vnd.hancom.hwpx":return"hwpx";default:return}}function F$($,J){let Q=`/${J}`;for(let Z of $.descendants(n6,"Override")){let G=Z.attrAny("PartName");if(G!==void 0&&L(G,Q)){let W=Z.attrAny("ContentType");if(W!==void 0)return W}}let K=J.lastIndexOf(".");if(K<0)return;let Y=J.slice(K+1);for(let Z of $.descendants(n6,"Default")){let G=Z.attrAny("Extension");if(G!==void 0&&L(G,Y))return Z.attrAny("ContentType")}return}function M$($){let J=$.toLowerCase();if(J.includes("wordprocessingml"))return"docx";if(J.includes("presentationml"))return"pptx";if(J.includes("spreadsheetml")||J.includes("ms-excel"))return"xlsx";if(J.includes("visio")||J.includes("vnd.ms-visio"))return"vsdx";return}function N$($){switch($.ns){case H.W:return"docx";case H.P:return"pptx";case D$:return"xlsx";default:return}}function R$($){if($.startsWith("word/"))return"docx";if($.startsWith("ppt/"))return"pptx";if($.startsWith("xl/"))return"xlsx";if($.startsWith("visio/"))return"vsdx";return}function L$($){let J=$.charCodeAt(0)===5?$.slice(1):$;return L($,"FileHeader")||L(J,"HwpSummaryInformation")||L($,"HWPDocumentInfo")}function _$($){return $.length>=7&&$.slice(0,7).toLowerCase()==="onenote"}function L($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function O$($){try{return new TextDecoder("utf-8",{fatal:!0}).decode($)}catch{return}}import{asciiStartsWith as Q0,decode as r6,trim as S}from"@mdgate/utils";function I$($){if(T$($)){let J=k$($);if(J.length>1||J.length===1&&Q0($,"From "))return{contentType:"application/mbox",headers:[],filename:void 0,bytes:new Uint8Array(0),parts:J.map((Q)=>s(Q))}}return s(z$($))}function q$($){let J=[],Q=(K)=>{J.push(K);for(let Y of K.parts)Q(Y)};return Q($),J}function K0($){let J=G0($);if(J!==void 0){let Q=X0($,J);if(Q!==void 0&&a6(Q)&&!M6(Q))return Q}return O6($,(Q)=>a6(Q)&&!M6(Q))}function Y0($){return O6($,(J)=>J.contentType==="text/plain"&&J.parts.length===0&&!M6(J))}function A$($){let J=K0($),Q=Y0($),K=[],Y=(Z)=>{if(Z.parts.length>0){for(let G of Z.parts)Y(G);return}if(Z===J||Z===Q)return;if(Z0(Z.contentType)||W0(Z.contentType))return;K.push(Z)};return Y($),K}function J6($,J){let Q=J.toLowerCase();for(let K=$.headers.length-1;K>=0;K-=1)if($.headers[K].name===Q)return $.headers[K].value;return}function s($){let J=g$($),Q=x$(J.headers),K=N6(Q,"content-type")??"text/plain",Y=D0(K),Z=h$(Q,Y.params),G=(N6(Q,"content-transfer-encoding")??"7bit").trim().toLowerCase(),W=m$(J.body,G);if(Z0(Y.type)){let U=Y.params.get("boundary");if(U===void 0||U.length===0)return{contentType:Y.type,headers:Q,filename:Z,bytes:W,parts:[]};let D=d$(W,U).map((j)=>s(j));return{contentType:Y.type,headers:Q,filename:Z,bytes:new Uint8Array(0),parts:D}}if(W0(Y.type)){let U=s(W);return{contentType:Y.type,headers:Q,filename:Z,bytes:W,parts:[U]}}return{contentType:Y.type,headers:Q,filename:Z,bytes:W,parts:[]}}function Z0($){return $.startsWith("multipart/")}function W0($){return $==="message/rfc822"||$==="message/global"||$==="message/news"}function a6($){return $.contentType==="text/html"&&$.parts.length===0}function M6($){let J=J6($,"content-disposition");if(J===void 0)return!1;let Q=J.indexOf(";");return(Q<0?J:J.slice(0,Q)).trim().toLowerCase()==="attachment"}function O6($,J){if(J($))return $;for(let Q of $.parts){let K=O6(Q,J);if(K!==void 0)return K}return}function G0($){let J=J6($,"content-type");if($.contentType==="multipart/related"&&J!==void 0){let Q=D0(J).params.get("start");if(Q!==void 0&&Q.length>0)return U0(Q)}for(let Q of $.parts){let K=G0(Q);if(K!==void 0)return K}return}function X0($,J){let Q=J6($,"content-id");if(Q!==void 0&&U0(Q)===J)return $;for(let K of $.parts){let Y=X0(K,J);if(Y!==void 0)return Y}return}function U0($){let J=S($);if(J.startsWith("<")&&J.endsWith(">")&&J.length>=2)J=J.slice(1,-1);return J}function N6($,J){let Q=J.toLowerCase();for(let K=$.length-1;K>=0;K-=1)if($[K].name===Q)return $[K].value;return}function z$($){if($.length>=3&&$[0]===239&&$[1]===187&&$[2]===191)return $.subarray(3);return $}function T$($){return Q0($,"From ")}function k$($){let J=[],Q=0;while(Q<$.length){if(R6($,Q))J.push(Q);Q=t($,Q)}if(J.length===0)return[];let K=[];for(let Y=0;Y<J.length;Y+=1){let Z=J[Y],G=t($,Z),W=Y+1<J.length?J[Y+1]:$.length;if(G>W)continue;K.push(w$($.subarray(G,W)))}return K}function R6($,J){return J+5<=$.length&&$[J]===70&&$[J+1]===114&&$[J+2]===111&&$[J+3]===109&&$[J+4]===32}function w$($){let J=0,Q=0;while(Q<$.length){if($[Q]===62&&R6($,Q+1))J+=1;Q=t($,Q)}if(J===0)return $;let K=new Uint8Array($.length-J),Y=0,Z=0;while(Y<$.length){if($[Y]===62&&R6($,Y+1))Y+=1;let G=t($,Y);K.set($.subarray(Y,G),Z),Z+=G-Y,Y=G}return K.subarray(0,Z)}function t($,J){while(J<$.length){let Q=$[J];if(J+=1,Q===10)return J;if(Q===13){if(J<$.length&&$[J]===10)J+=1;return J}}return J}function g$($){let J=C$($);if(J!==void 0)return{headers:$.subarray(0,J.sep),body:$.subarray(J.body)};if(S$($))return{headers:$,body:$.subarray($.length)};return{headers:$.subarray(0,0),body:$}}function C$($){let J=$.length;for(let Q=0;Q<J;Q+=1){let K=$[Q];if(K===10&&Q+1<$.length&&$[Q+1]===10)return{sep:Q+1,body:Q+2};if(K===13&&Q+1<$.length&&$[Q+1]===10){if(Q+3<$.length&&$[Q+2]===13&&$[Q+3]===10)return{sep:Q+2,body:Q+4};if(Q+2<$.length&&$[Q+2]===10)return{sep:Q+2,body:Q+3}}if(K===13&&Q+1<$.length&&$[Q+1]===13)return{sep:Q+1,body:Q+2}}return}function S$($){let J=0;while(J<$.length&&($[J]===32||$[J]===9))J+=1;if(J>=$.length)return!1;let Q=J;while(J<$.length&&$[J]!==13&&$[J]!==10&&$[J]!==58)J+=1;if(J>=$.length||$[J]!==58||J===Q)return!1;for(let K=Q;K<J;K+=1){let Y=$[K];if(!(Y>=65&&Y<=90||Y>=97&&Y<=122||Y>=48&&Y<=57||Y===45))return!1}return!0}function x$($){if($.length===0)return[];let J=E$(j0($)),Q=[],K=0;while(K<J.length){let Y=J.indexOf(`
|
|
3
|
+
`,K);if(Y<0)Y=J.length;let Z=J.slice(K,Y);if(Z.endsWith("\r"))Z=Z.slice(0,-1);if(K=Y+1,Z.length===0)continue;let G=Z.indexOf(":");if(G<=0)continue;let W=Z.slice(0,G).trim().toLowerCase();if(W.length===0)continue;let U=u$(S(Z.slice(G+1)));Q.push({name:W,value:U})}return Q}function E$($){let J="";for(let Q=0;Q<$.length;Q+=1){let K=$[Q];if(K==="\r"&&$[Q+1]===`
|
|
4
|
+
`&&L6($[Q+2])){J+=" ",Q+=2;continue}if((K===`
|
|
5
|
+
`||K==="\r")&&L6($[Q+1])){J+=" ",Q+=1;continue}J+=K}return J}function L6($){return $===" "||$==="\t"}function D0($){let J=_6($,";"),Q=S(J<0?$:$.slice(0,J)).toLowerCase(),K=Q.length>0?Q:"application/octet-stream",Y=V0(J<0?"":$.slice(J+1));return{type:K,params:Y}}function V0($){let J=new Map,Q=0;while(Q<$.length){while(Q<$.length&&($[Q]===";"||$[Q]===" "||$[Q]==="\t"))Q+=1;if(Q>=$.length)break;let K=$.slice(Q),Y=_6(K,";"),Z=S(Y<0?K:K.slice(0,Y));Q+=Y<0?K.length:Y+1;let G=_6(Z,"=");if(G<=0)continue;let W=S(Z.slice(0,G)).toLowerCase();if(W.length===0)continue;J.set(W,v$(S(Z.slice(G+1))))}return J}function _6($,J){let Q=!1;for(let K=0;K<$.length;K+=1){let Y=$[K];if(Q){if(Y==="\\"){K+=1;continue}if(Y==='"')Q=!1;continue}if(Y==='"'){Q=!0;continue}if(Y===J)return K}return-1}function v$($){if($.length>=2&&$.startsWith('"')&&$.endsWith('"')){let J="";for(let Q=1;Q<$.length-1;Q+=1){if($[Q]==="\\"&&Q+1<$.length-1){Q+=1,J+=$[Q];continue}J+=$[Q]}return J}return $}function h$($,J){let Q=N6($,"content-disposition");if(Q!==void 0){let K=s6(V0(Q));if(K!==void 0)return K}return s6(J)}function s6($){let J=t6($,"filename")??$.get("filename*");if(J!==void 0){let Z=e6(J);if(Z.length>0)return Z}let Q=$.get("filename");if(Q!==void 0&&Q.length>0)return Q;let K=t6($,"name")??$.get("name*");if(K!==void 0){let Z=e6(K);if(Z.length>0)return Z}let Y=$.get("name");return Y!==void 0&&Y.length>0?Y:void 0}function t6($,J){if(!$.has(`${J}*0`)&&!$.has(`${J}*0*`))return;let Q="";for(let K=0;K<64;K+=1){let Y=$.get(`${J}*${K}*`);if(Y!==void 0){Q+=Y;continue}let Z=$.get(`${J}*${K}`);if(Z===void 0)break;Q+=Z}return Q.length>0?Q:void 0}function e6($){let J=$.indexOf("'");if(J<0)return F6($,"utf-8");let Q=$.indexOf("'",J+1);if(Q<0)return F6($,"utf-8");let K=$.slice(0,J)||"utf-8";return F6($.slice(Q+1),K)}function F6($,J){let Q=new Uint8Array($.length),K=0;for(let Y=0;Y<$.length;Y+=1){if($[Y]==="%"&&Y+2<$.length&&e($[Y+1])&&e($[Y+2])){Q[K]=$6($[Y+1])<<4|$6($[Y+2]),K+=1,Y+=2;continue}Q[K]=$.charCodeAt(Y)&255,K+=1}return B0(Q.subarray(0,K),J)}function u$($){let J=/=\?([^?]+)\?([bBqQ])\?([^?]*)\?=/g,Q="",K=0,Y=-1,Z;while((Z=J.exec($))!==void 0&&Z!==null){let G=Z.index,W=$.slice(K,G);if(Y>=0&&f$(W));else Q+=W;Q+=p$(Z[1],Z[2],Z[3]),K=G+Z[0].length,Y=K}if(K===0)return $;return Q+$.slice(K)}function f$($){for(let J=0;J<$.length;J+=1)if(!L6($[J]))return!1;return $.length>0}function p$($,J,Q){let K=J.toUpperCase(),Y;if(K==="B")Y=H0(new TextEncoder().encode(Q));else Y=l$(Q);return B0(Y,$)}function l$($){let J=new Uint8Array($.length),Q=0;for(let K=0;K<$.length;K+=1){let Y=$[K];if(Y==="_"){J[Q]=32,Q+=1;continue}if(Y==="="&&K+2<$.length&&e($[K+1])&&e($[K+2])){J[Q]=$6($[K+1])<<4|$6($[K+2]),Q+=1,K+=2;continue}J[Q]=$.charCodeAt(K)&255,Q+=1}return J.subarray(0,Q)}function B0($,J){try{return r6($,J)}catch{try{return r6($,"utf-8")}catch{return j0($)}}}function m$($,J){if(J==="base64")return H0($);if(J==="quoted-printable")return b$($);return $}function b$($){let J=new Uint8Array($.length),Q=0;for(let K=0;K<$.length;K+=1){let Y=$[K];if(Y===61){let Z=$[K+1],G=$[K+2];if(Z===13&&G===10){K+=2;continue}if(Z===10||Z===13){K+=1;continue}if(Z!==void 0&&G!==void 0&&$0(Z)&&$0(G)){J[Q]=J0(Z)<<4|J0(G),Q+=1,K+=2;continue}}if(Y===9||Y===32){let Z=K+1;while(Z<$.length&&($[Z]===9||$[Z]===32))Z+=1;if(Z<$.length&&($[Z]===13||$[Z]===10)){K=Z-1;continue}}J[Q]=Y,Q+=1}return J.subarray(0,Q)}var c$=(()=>{let $=new Uint8Array(128).fill(255),J="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(let Q=0;Q<64;Q+=1)$["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".charCodeAt(Q)]=Q;return $[45]=62,$[95]=63,$})();function H0($){let J=Math.floor($.length/4)*3+3,Q=new Uint8Array(J),K=0,Y=0,Z=0;for(let G=0;G<$.length;G+=1){let W=$[G];if(W===61)break;if(W>=128)continue;let U=c$[W];if(U===255)continue;if(K=K<<6|U,Y+=6,Y>=8)Y-=8,Q[Z]=K>>Y&255,Z+=1}return Q.subarray(0,Z)}function d$($,J){if(J.length===0)return[];let Q=new TextEncoder().encode(`--${J}`),K=[],Y=[],Z=0;while(Z+Q.length<=$.length){let W=i$($,Q,Z);if(W<0)break;if(!y$($,W)){Z=W+1;continue}K.push(W);let U=W+Q.length;Y.push($[U]===45&&$[U+1]===45),Z=U}let G=[];for(let W=0;W<K.length;W+=1){if(Y[W])break;let U=o$($,K[W]+Q.length),X=W+1<K.length?K[W+1]:$.length;G.push($.subarray(U,n$($,U,X)))}return G}function y$($,J){if(J===0)return!0;let Q=$[J-1];return Q===10||Q===13}function o$($,J){if($[J]===45&&$[J+1]===45)J+=2;while(J<$.length&&($[J]===32||$[J]===9))J+=1;if($[J]===13)J+=1;if($[J]===10)J+=1;return J}function n$($,J,Q){let K=Q;if(K>J&&$[K-1]===10)K-=1;if(K>J&&$[K-1]===13)K-=1;return K}function i$($,J,Q){if(J.length===0)return Q;let K=J[0],Y=Q+($.length-J.length);for(let Z=Q;Z<=Y;Z+=1){if($[Z]!==K)continue;let G=!0;for(let W=1;W<J.length;W+=1)if($[Z+W]!==J[W]){G=!1;break}if(G)return Z}return-1}function j0($){if($.length<=4096)return String.fromCharCode(...$);let Q=[];for(let K=0;K<$.length;K+=4096)Q.push(String.fromCharCode(...$.subarray(K,K+4096)));return Q.join("")}function e($){return $>="0"&&$<="9"||$>="a"&&$<="f"||$>="A"&&$<="F"}function $6($){if($>="0"&&$<="9")return $.charCodeAt(0)-48;if($>="a"&&$<="f")return $.charCodeAt(0)-87;return $.charCodeAt(0)-55}function $0($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function J0($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}export{q$ as walkMimeParts,p as resolve,U$ as relsPartFor,B6 as relType,X$ as relTargetBytes,H6 as readRels,Z$ as readOleStream,n0 as probeOle,i as parseXml,I$ as parseMime,H as ns,C6 as normalizeStarOfficeUri,u as normalizeOoxmlUri,Y0 as mimeTextPlain,K0 as mimeTextHtml,J6 as mimeHeader,A$ as mimeAttachments,v as hasOleMagic,Y$ as getU32,K$ as getU16,V$ as detectZipDoc,B$ as detectOleDoc,W$ as decodeFragment,a as Relationships,f as Package,R0 as OLE_MAGIC_BYTES,n as Element,T as CompoundFile};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/containers",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13",
|
|
4
4
|
"description": "mdgate container parsing: ZIP/OPC packages, OLE compound files, XML",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"prepublishOnly": "bun run build"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mdgate/core": "0.6.
|
|
32
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/core": "0.6.13",
|
|
32
|
+
"@mdgate/utils": "0.6.13"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|