@mdgate/containers 0.5.1 → 0.5.2

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/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export { detectOleDoc, detectZipDoc, type OleDocKind, type ZipDocKind, } from '.
5
5
  export { type MimeHeader, type MimePart, mimeAttachments, mimeHeader, mimeTextHtml, mimeTextPlain, parseMime, walkMimeParts, } from './mime.js';
6
6
  export { decodeFragment, resolve, type Target } from './path.js';
7
7
  export { type Relationship, Relationships, type RelTarget, readRels, relsPartFor, relTargetBytes, relType, type TargetMode, } from './relationships.js';
8
- export { type Attr, Element, normalizeOoxmlUri, ns, parseXml, type XmlNode, } from './xml.js';
8
+ export { type Attr, Element, normalizeOoxmlUri, normalizeStarOfficeUri, ns, parseXml, type XmlNode, } from './xml.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import{ConvertError as j}from"@mdgate/core";import{decode as E0,inflateRaw as v0,warn as h6}from"@mdgate/utils";import{ConvertError as g}from"@mdgate/core";var Y6=[208,207,17,224,161,177,26,225],y=4294967295,A6=4294967294,B0=4294967293,j0=4294967292,P0=4294967295,O=4294967290,I6=0;var O6=2,M0=5;class T{bytes;sectorSize;miniSectorSize;miniCutoff;fat;miniFat;entries;miniStream;constructor($,J,Q,K,Y,W,G){this.bytes=$,this.sectorSize=J,this.miniSectorSize=Q,this.miniCutoff=K,this.fat=Y,this.miniFat=W,this.entries=G}static open($){if($.length<512||!q6($,Y6))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,W=J.getUint16(32,!0),G=W===0?64:1<<W,Z=J.getUint16(26,!0),X=J.getUint32(44,!0),U=J.getUint32(48,!0),D=J.getUint32(56,!0)||4096,B=J.getUint32(60,!0),P=J.getUint32(64,!0),S=J.getUint32(68,!0),z=J.getUint32(72,!0),M=[];for(let V=0;V<109;V+=1){let L=J.getUint32(76+V*4,!0);if(L<=O)M.push(L)}let A=S,w=new Set;for(let V=0;V<z&&A<=O;V+=1){if(w.has(A))break;w.add(A);let L=K6(A,Y),I=Y/4;if(L+Y>$.length)break;let c=new DataView($.buffer,$.byteOffset+L,Y);for(let E=0;E<I-1;E+=1){let C=c.getUint32(E*4,!0);if(C<=O)M.push(C)}A=c.getUint32((I-1)*4,!0)}if(M.length<X);let H=[],Q6=Math.min(M.length,X||M.length,1e6);for(let V=0;V<Q6;V+=1){let L=M[V],I=K6(L,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)H.push(c.getUint32(C*4,!0))}let _=Math.max(0,Math.floor(($.length+Y-1)/Y)-1);while(H.length>_){let V=H[H.length-1];if(V===0||V===j0||V===B0||V===y)H.pop();else break}while(H.length>_&&H[H.length-1]===y)H.pop();if(H.length>_)throw g.malformed(`not an OLE2 compound file: Malformed FAT (FAT has ${H.length} entries, but file has only ${_} sectors)`);while(H.length<_)H.push(y);let l=[];if(P>0&&B<=O){let V=d($,H,Y,B,P*Y),L=new DataView(V.buffer,V.byteOffset,V.byteLength);for(let I=0;I+4<=V.length;I+=4)l.push(L.getUint32(I,!0))}let m=d($,H,Y,U,$.length),b=[];for(let V=0;V+128<=m.length;V+=128)b.push(R0(m,V,Z));if(b.length===0||b[0].type!==M0)throw g.malformed("not an OLE2 compound file: missing root storage");return new T($,Y,G,D,H,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!==O6)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??P0,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>O||Q.has(Y))continue;Q.add(Y);let W=this.entries[Y];if(W===void 0||W.type===I6)continue;if(N0(W.name,J))return W;K.push(W.left,W.right)}return}walkSiblings($,J){let Q=new Set,K=(Y)=>{if(Y>O||Q.has(Y))return;Q.add(Y);let W=this.entries[Y];if(W===void 0||W.type===I6)return;K(W.left),J.push({name:W.name,type:W.type}),K(W.right)};K($)}readEntryBytes($,J){let Q=Math.min($.size,J);if($.size<this.miniCutoff&&$.type===O6)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=$,W=new Set;while(K<J&&Y<=O){if(W.has(Y))break;W.add(Y);let G=Y*this.miniSectorSize,Z=Math.min(this.miniSectorSize,J-K);if(G+Z>this.miniStream.length)break;Q.set(this.miniStream.subarray(G,G+Z),K),K+=Z,Y=this.miniFat[Y]??A6}return K===J?Q:Q.subarray(0,K)}}var F0=Y6;function v($){return q6($,Y6)}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 N0($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function K6($,J){return($+1)*J}function d($,J,Q,K,Y){if(K>O||Y<=0)return new Uint8Array(0);let W=[],G=0,Z=K,X=new Set;while(G<Y&&Z<=O){if(X.has(Z)||X.size>1e6)break;X.add(Z);let U=K6(Z,Q);if(U>=$.length)break;let D=Math.min(Q,Y-G,$.length-U);if(D<=0)break;if(W.push($.subarray(U,U+D)),G+=D,Z=J[Z]??A6,Z===y)break}return _0(W,G)}function R0($,J,Q){let K=new DataView($.buffer,$.byteOffset+J,128),Y=K.getUint16(64,!0),W=Math.max(0,Math.min(64,Y>0?Y-2:0)),G=new TextDecoder("utf-16le").decode($.subarray(J,J+W)),Z=$[J+66]??0,X=K.getUint32(68,!0),U=K.getUint32(72,!0),D=K.getUint32(76,!0),B=K.getUint32(116,!0),P=Number(K.getBigUint64(120,!0));if(Q===3)P=K.getUint32(120,!0);if(!Number.isFinite(P)||P<0)P=0;return{name:G,type:Z,left:X,right:U,child:D,start:B,size:P}}function _0($,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 L0}from"@mdgate/core";import{debug as z6,decode as I0,encodingExists as O0,warn as A0}from"@mdgate/utils";var q={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"},q0=q.XML,z0="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 W=K[Y];if(W.type==="elem"&&W.elem.local===J&&W.elem.ns===$)Q.push(W.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 q0;if($==="xmlns")return z0;return this.prefixes[this.prefixes.length-1].get($)}resolveElement($){let J=$.indexOf(":");if(J>=0){let K=$.slice(0,J),Y=$.slice(J+1),W=this.lookupPrefix(K);return{ns:W,local:Y,bound:W!==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=S0($,"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}`}var g6=0,x6=1,S6=2,h=3,G6=4,E6=5;function i($){let J=k0($),Q=new v6(J),K=new C6,Y=new Map,W=new Map,G=new n(void 0,""),Z=[],X=!1;for(;;){let U;try{U=Q.next()}catch(D){let B=D instanceof Error?D.message:String(D);throw L0.malformed(`unparseable xml: ${B}`)}switch(U){case x6:{K.push(),K.applyDecls(Q.attrs);let D=T0(Q.name,Q.attrs,K,Y,W);if(Q.empty)W6(Z,G,{type:"elem",elem:D}),K.pop();else Z.push(D);break}case S6:{let D=Z.pop();if(D===void 0)X=!0;else{if(D.local!==Q.local)X=!0;W6(Z,G,{type:"elem",elem:D}),K.pop()}break}case h:{if(Q.text.length>0)Z6(Z,G,Q.text);break}case G6:{let D=X6(Q.name)??`&${Q.name};`;Z6(Z,G,D);break}case E6:{Z6(Z,G,Q.text);break}case g6:if(Z.length>0){X=!0;while(Z.length>0)W6(Z,G,{type:"elem",elem:Z.pop()})}if(X)A0("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 Z6($,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)??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 T0($,J,Q,K,Y){let W=Q.resolveElement($),G=W.ns!==void 0?T6(K,W.ns):void 0,Z=w6,X=!1;for(let U of J){if(U.rawName==="xmlns"||U.rawName.startsWith("xmlns:"))continue;let D=Q.resolveAttribute(U.rawName);if(!X)Z=[],X=!0;Z.push({ns:D.ns!==void 0?T6(K,D.ns):void 0,local:k6(Y,D.local),value:U.value})}if(W.local==="Choice"&&G===q.MC){let U=Z.find((D)=>D.local==="Requires");if(U!==void 0)U.value=U.value.split(/\s+/).filter((D)=>D.length>0).map((D)=>{let B=Q.resolveElement(`${D}:x`);if(B.bound&&B.ns!==void 0)return u(B.ns)??B.ns;return D}).join(" ")}return new n(G,k6(Y,W.local),Z)}function k0($){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=w0(J);if(Q!==void 0){let K=C0(Q);if(K!==void 0&&K!=="utf8"&&K!=="utf-8")return I0($,K)}return new TextDecoder("utf-8").decode($)}function w0($){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 W=K.indexOf(Y);if(W<0)return;return K.slice(0,W)}function C0($){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 O0(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,W=Number.parseInt(Y,K?16:10);if(!Number.isFinite(W))return;try{return String.fromCodePoint(W)}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 v6{s;i=0;name="";local="";text="";empty=!1;attrs=[];constructor($){this.s=$}next(){if(this.i>=this.s.length)return g6;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,E6}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=g0($),S6}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,G6;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,G6}$+=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 W=this.s.slice(J,this.i);return this.i+=1,Q?o(W):W}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 g0($){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 S0($,J){return $.startsWith(J)?$.slice(J.length):void 0}var h0=67324752,u0=33639248;var f0=101075792,p0=117853008,l0=0,m0=8;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=d0($);if(J<0)throw j.malformed("not a readable zip archive: invalid Zip archive: Could not find EOCD");let Q=r($),K=F(Q,J+10),Y=N(Q,J+12),W=N(Q,J+16);if(K===65535||Y===4294967295||W===4294967295){let U=y0($,J);if(U!==void 0)K=U.entryCount,Y=U.cdSize,W=U.cdOffset}if(W+Y>$.length)throw j.malformed("not a readable zip archive: truncated central directory");let G=[],Z=W,X=Math.min($.length,W+Y);while(Z+46<=X&&G.length<K){if(N(Q,Z)!==u0)throw j.malformed("not a readable zip archive: bad central directory");let U=F(Q,Z+8),D=F(Q,Z+10),B=N(Q,Z+16),P=N(Q,Z+20),S=N(Q,Z+24),z=F(Q,Z+28),M=F(Q,Z+30),A=F(Q,Z+32),w=N(Q,Z+42),H=$.subarray(Z+46,Z+46+z);if(Z+46+z+M+A>$.length)throw j.malformed("not a readable zip archive: truncated entry");let Q6=$.subarray(Z+46+z,Z+46+z+M),_=o0(Q6,{uncompressedSize:S,compressedSize:P,headerOffset:w});S=_.uncompressedSize,P=_.compressedSize,w=_.headerOffset;let l=(U&2048)!==0,m=n0(H,l);G.push({name:m,method:D,flags:U,crc:B,compressedSize:P,uncompressedSize:S,headerOffset:w}),Z+=46+z+M+A}return new D6($,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||N(J,Q)!==h0)throw Error("bad local file header");let K=F(J,Q+26),Y=F(J,Q+28),W=Q+30+K+Y,G=W+$.compressedSize;if(W>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(W,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 j)throw Q;let K=Q instanceof Error?Q.message:String(Q);throw j.malformed(`not a readable zip archive: ${K}`)}return new f(J)}part($){$=u6($);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 j)throw Y;let W=Y instanceof Error?Y.message:String(Y);throw j.malformedPart($,`corrupt archive entry: ${W}`)}return this.cache.set($,K),K}hasPart($){return this.zip.indexForName(u6($))!==void 0}partNames(){return this.zip.partNames()}requiredPart($){let J=this.part($);if(J===void 0)throw j.missingPart($);return J}optionalPart($){try{return this.part($)}catch(J){if(J instanceof j&&J.isFatal())throw J;h6(`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 j&&Q.isFatal())throw Q;h6(`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 W=Y instanceof Error?Y.message:String(Y);throw j.malformedPart($.name,`unreadable archive entry: ${W}`)}let K;if($.method===l0){let Y=$.uncompressedSize>0?$.uncompressedSize:Q.length;K=Q.subarray(0,Math.min(Y,Q.length))}else if($.method===m0)K=c0(Q,J);else throw Error(`unsupported compression method ${$.method}`);if(K.length<=J-1&&$.crc!==0&&s0(K)!==$.crc)throw Error("crc mismatch");return K}}function b0($){if(!v($))return;try{let J=T.open($);if(J.exists("EncryptionInfo")||J.exists("EncryptedPackage"))return j.encrypted()}catch{}return j.malformed("OLE compound document where an OOXML package was expected (legacy binary format?)")}function c0($,J){return v0($,J)}function d0($){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 y0($,J){if(J<20)return;let Q=r($),K=J-20;if(N(Q,K)!==p0)return;let Y=k(Q,K+8);if(Y+56>$.length||N(Q,Y)!==f0)return;return{entryCount:k(Q,Y+32),cdSize:k(Q,Y+40),cdOffset:k(Q,Y+48)}}function o0($,J){let Q=0,K=r($);while(Q+4<=$.length){let Y=F(K,Q),W=F(K,Q+2),G=Q+4;if(G+W>$.length)break;if(Y===1){let Z=G,{uncompressedSize:X,compressedSize:U,headerOffset:D}=J;if(X===4294967295&&Z+8<=G+W)X=k(K,Z),Z+=8;if(U===4294967295&&Z+8<=G+W)U=k(K,Z),Z+=8;if(D===4294967295&&Z+8<=G+W)D=k(K,Z);return{uncompressedSize:X,compressedSize:U,headerOffset:D}}Q=G+W}return J}function n0($,J){if(J)return new TextDecoder("utf-8",{fatal:!1}).decode($);return E0($,"cp437")}function u6($){let J=0;while(J<$.length&&$.charCodeAt(J)===47)J+=1;return $.slice(J)}function r($){return new DataView($.buffer,$.byteOffset,$.byteLength)}function F($,J){return $.getUint16(J,!0)}function N($,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 i0=r0();function r0(){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 a0($){let J=4294967295;for(let Q=0;Q<$.length;Q+=1)J=i0[(J^$[Q])&255]^J>>>8;return(J^4294967295)>>>0}function s0($){return a0($)}import{ConvertError as f6}from"@mdgate/core";function t0($,J){if(!Number.isSafeInteger(J)||J<0||J+2>$.length)return;return $[J]|$[J+1]<<8}function e0($,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){try{return $.readStream(J)}catch(Q){if(Q instanceof f6)throw Q;let K=Q instanceof Error?Q.message:String(Q);throw f6.malformedPart(J,`unreadable stream: ${K}`)}}import{trim as d6}from"@mdgate/utils";import{ConvertError as p6}from"@mdgate/core";function p($,J){let Q,K=J.indexOf("#");if(K>=0)Q=U6(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 W=[];if(!J.startsWith("/")){let G=$.lastIndexOf("/");if(G>=0){for(let Z of $.slice(0,G).split("/"))if(Z.length>0)W.push(Z)}}for(let G of J.split("/")){if(G.length===0||G===".")continue;if(G===".."){W.pop();continue}let Z=U6(G);if(Z.includes("/")||Z.includes("\\"))throw p6.malformed(`percent-encoded separator in package reference segment ${b6(G)}`);if(Z==="."||Z==="..")throw p6.malformed(`percent-encoded traversal in package reference segment ${b6(G)}`);W.push(Z)}return{path:W.join("/"),fragment:Q}}function J$($){return U6($)}var Q$=new TextEncoder;function U6($){let J=Q$.encode($),Q=[],K=0;while(K<J.length){if(J[K]===37&&K+2<J.length){let Y=J[K+1],W=J[K+2];if(l6(Y)&&l6(W)){Q.push(m6(Y)<<4|m6(W)),K+=3;continue}}Q.push(J[K]),K+=1}return new TextDecoder("utf-8",{fatal:!1}).decode(Uint8Array.from(Q))}function l6($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function m6($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}function b6($){return JSON.stringify($)}import{warn as c6}from"@mdgate/utils";var V6={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(q.PKG_RELS,"Relationship")){let W=Y.attrAny("Id"),G=Y.attrAny("Target");if(W===void 0||G===void 0)continue;let Z=Y.attrAny("TargetMode"),X=Z!==void 0&&Z.toLowerCase()==="external"?"external":"internal",U=Y.attrAny("Type")??"",D=u(U)??U;K.set(W,{target:G,relType:D,mode:X})}return new a(K)}function K$($,J,Q,K){let Y=J.get(K);if(Y===void 0||Y.mode!=="internal")return;let W;try{W=p(Q,Y.target)}catch(Z){c6(`skipping unresolvable relationship target ${JSON.stringify(Y.target)}: ${Z instanceof Error?Z.message:String(Z)}`);return}let G=$.optionalPart(W.path);if(G===void 0){c6(`relationship target ${W.path} is missing`);return}return[W.path,G]}function Y$($){let J=$.lastIndexOf("/");if(J>=0)return`${$.slice(0,J)}/_rels/${$.slice(J+1)}.rels`;return`_rels/${$}.rels`}var y6="http://schemas.openxmlformats.org/package/2006/content-types",B6="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",W$="http://schemas.openxmlformats.org/spreadsheetml/2006/main";function Z$($){if($.length<4||$[0]!==80||$[1]!==75||$[2]!==3||$[3]!==4)return;try{return X$($)}catch{return}}function G$($){if(!v($))return;let J;try{J=T.open($)}catch{return}try{for(let Q of J.readRootStorage()){let K=Q.name;if(R(K,"WordDocument"))return"doc";if(R(K,"PowerPoint Document"))return"ppt";if(R(K,"Workbook")||R(K,"Book"))return"xls";if(R(K,"VisioDocument"))return"vsd";if(P$(K))return"hwp";if(M$(K))return"one"}}catch{return}return}function X$($){let J;try{J=f.open($)}catch{return}let Q=U$(J,"mimetype");if(Q!==void 0){let Y=F$(Q);if(Y===void 0)return;return o6(d6(Y))}try{let W=H6(J,"_rels/.rels").firstOfType(V6.OFFICE_DOCUMENT);if(W!==void 0){let G;try{G=p("",W.target)}catch{G=void 0}if(G!==void 0){let Z=j6(J,"[Content_Types].xml");if(Z!==void 0){let U=V$(Z,G.path);if(U!==void 0){let D=H$(U);if(D!==void 0)return D}}let X=j6(J,G.path);if(X!==void 0){let U=X.childElems()[0],D=U!==void 0?B$(U):void 0;if(D!==void 0)return D}return j$(G.path)}}}catch{}for(let[Y,W]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 W;try{let Y=j6(J,"META-INF/manifest.xml");if(Y!==void 0){for(let W of Y.descendants(B6,"file-entry"))if(W.attr(B6,"full-path")==="/"){let G=W.attr(B6,"media-type");if(G!==void 0)return o6(d6(G))}}}catch{}if(J.hasPart("META-INF/container.xml"))return"epub";let K=D$(J);if(K!==void 0)return K;return}function D$($){let J=$.partNames();if(J.length===0)return;let Q=!1,K=!1,Y=!1,W=!1,G=!1;for(let Z of J){let X=Z.toLowerCase();if(X.includes("encrypted")||X.endsWith(".iwae"))return;if(X.endsWith(".iwa")){if(Q=!0,X.endsWith("/document.iwa")||X==="document.iwa")Y=!0;if(X.includes("slide")||X.includes("masterslide"))W=!0;if(X.includes("calculationengine")||X.includes("tables/"))G=!0}if(X==="index.zip")K=!0}if(!Q&&!K)return;if(!Q&&K)return;if(!Y&&!K&&!W&&!G)return;if(W&&!G)return"keynote";if(G&&!W)return"numbers";if(Y)return"pages";return}function U$($,J){try{return $.optionalPart(J)}catch{return}}function j6($,J){try{return $.optionalXmlPart(J)}catch{return}}function o6($){switch($.endsWith("-template")?$.slice(0,-9):$){case"application/epub+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/hwp+zip":case"application/vnd.hancom.hwpx":return"hwpx";default:return}}function V$($,J){let Q=`/${J}`;for(let W of $.descendants(y6,"Override")){let G=W.attrAny("PartName");if(G!==void 0&&R(G,Q)){let Z=W.attrAny("ContentType");if(Z!==void 0)return Z}}let K=J.lastIndexOf(".");if(K<0)return;let Y=J.slice(K+1);for(let W of $.descendants(y6,"Default")){let G=W.attrAny("Extension");if(G!==void 0&&R(G,Y))return W.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 B$($){switch($.ns){case q.W:return"docx";case q.P:return"pptx";case W$:return"xlsx";default:return}}function j$($){if($.startsWith("word/"))return"docx";if($.startsWith("ppt/"))return"pptx";if($.startsWith("xl/"))return"xlsx";if($.startsWith("visio/"))return"vsdx";return}function P$($){let J=$.charCodeAt(0)===5?$.slice(1):$;return R($,"FileHeader")||R(J,"HwpSummaryInformation")||R($,"HWPDocumentInfo")}function M$($){return $.length>=7&&$.slice(0,7).toLowerCase()==="onenote"}function R($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function F$($){try{return new TextDecoder("utf-8",{fatal:!0}).decode($)}catch{return}}import{asciiStartsWith as $0,decode as n6,trim as x}from"@mdgate/utils";function N$($){if(I$($)){let J=O$($);if(J.length>1||J.length===1&&$0($,"From "))return{contentType:"application/mbox",headers:[],filename:void 0,bytes:new Uint8Array(0),parts:J.map((Q)=>s(Q))}}return s(L$($))}function R$($){let J=[],Q=(K)=>{J.push(K);for(let Y of K.parts)Q(Y)};return Q($),J}function J0($){let J=W0($);if(J!==void 0){let Q=Z0($,J);if(Q!==void 0&&i6(Q)&&!M6(Q))return Q}return L6($,(Q)=>i6(Q)&&!M6(Q))}function Q0($){return L6($,(J)=>J.contentType==="text/plain"&&J.parts.length===0&&!M6(J))}function _$($){let J=J0($),Q=Q0($),K=[],Y=(W)=>{if(W.parts.length>0){for(let G of W.parts)Y(G);return}if(W===J||W===Q)return;if(K0(W.contentType)||Y0(W.contentType))return;K.push(W)};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=q$($),Q=k$(J.headers),K=F6(Q,"content-type")??"text/plain",Y=X0(K),W=g$(Q,Y.params),G=(F6(Q,"content-transfer-encoding")??"7bit").trim().toLowerCase(),Z=h$(J.body,G);if(K0(Y.type)){let X=Y.params.get("boundary");if(X===void 0||X.length===0)return{contentType:Y.type,headers:Q,filename:W,bytes:Z,parts:[]};let D=p$(Z,X).map((B)=>s(B));return{contentType:Y.type,headers:Q,filename:W,bytes:new Uint8Array(0),parts:D}}if(Y0(Y.type)){let X=s(Z);return{contentType:Y.type,headers:Q,filename:W,bytes:Z,parts:[X]}}return{contentType:Y.type,headers:Q,filename:W,bytes:Z,parts:[]}}function K0($){return $.startsWith("multipart/")}function Y0($){return $==="message/rfc822"||$==="message/global"||$==="message/news"}function i6($){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 L6($,J){if(J($))return $;for(let Q of $.parts){let K=L6(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 G0(Q)}for(let Q of $.parts){let K=W0(Q);if(K!==void 0)return K}return}function Z0($,J){let Q=J6($,"content-id");if(Q!==void 0&&G0(Q)===J)return $;for(let K of $.parts){let Y=Z0(K,J);if(Y!==void 0)return Y}return}function G0($){let J=x($);if(J.startsWith("<")&&J.endsWith(">")&&J.length>=2)J=J.slice(1,-1);return J}function F6($,J){let Q=J.toLowerCase();for(let K=$.length-1;K>=0;K-=1)if($[K].name===Q)return $[K].value;return}function L$($){if($.length>=3&&$[0]===239&&$[1]===187&&$[2]===191)return $.subarray(3);return $}function I$($){return $0($,"From ")}function O$($){let J=[],Q=0;while(Q<$.length){if(N6($,Q))J.push(Q);Q=t($,Q)}if(J.length===0)return[];let K=[];for(let Y=0;Y<J.length;Y+=1){let W=J[Y],G=t($,W),Z=Y+1<J.length?J[Y+1]:$.length;if(G>Z)continue;K.push(A$($.subarray(G,Z)))}return K}function N6($,J){return J+5<=$.length&&$[J]===70&&$[J+1]===114&&$[J+2]===111&&$[J+3]===109&&$[J+4]===32}function A$($){let J=0,Q=0;while(Q<$.length){if($[Q]===62&&N6($,Q+1))J+=1;Q=t($,Q)}if(J===0)return $;let K=new Uint8Array($.length-J),Y=0,W=0;while(Y<$.length){if($[Y]===62&&N6($,Y+1))Y+=1;let G=t($,Y);K.set($.subarray(Y,G),W),W+=G-Y,Y=G}return K.subarray(0,W)}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 q$($){let J=z$($);if(J!==void 0)return{headers:$.subarray(0,J.sep),body:$.subarray(J.body)};if(T$($))return{headers:$,body:$.subarray($.length)};return{headers:$.subarray(0,0),body:$}}function z$($){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 T$($){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 k$($){if($.length===0)return[];let J=w$(H0($)),Q=[],K=0;while(K<J.length){let Y=J.indexOf(`
3
- `,K);if(Y<0)Y=J.length;let W=J.slice(K,Y);if(W.endsWith("\r"))W=W.slice(0,-1);if(K=Y+1,W.length===0)continue;let G=W.indexOf(":");if(G<=0)continue;let Z=W.slice(0,G).trim().toLowerCase();if(Z.length===0)continue;let X=x$(x(W.slice(G+1)));Q.push({name:Z,value:X})}return Q}function w$($){let J="";for(let Q=0;Q<$.length;Q+=1){let K=$[Q];if(K==="\r"&&$[Q+1]===`
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 Y6=[208,207,17,224,161,177,26,225],y=4294967295,A6=4294967294,j0=4294967293,P0=4294967292,M0=4294967295,A=4294967290,I6=0;var O6=2,F0=5;class T{bytes;sectorSize;miniSectorSize;miniCutoff;fat;miniFat;entries;miniStream;constructor($,J,Q,K,Y,W,G){this.bytes=$,this.sectorSize=J,this.miniSectorSize=Q,this.miniCutoff=K,this.fat=Y,this.miniFat=W,this.entries=G}static open($){if($.length<512||!q6($,Y6))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,W=J.getUint16(32,!0),G=W===0?64:1<<W,Z=J.getUint16(26,!0),X=J.getUint32(44,!0),U=J.getUint32(48,!0),D=J.getUint32(56,!0)||4096,j=J.getUint32(60,!0),M=J.getUint32(64,!0),S=J.getUint32(68,!0),z=J.getUint32(72,!0),F=[];for(let V=0;V<109;V+=1){let I=J.getUint32(76+V*4,!0);if(I<=A)F.push(I)}let q=S,w=new Set;for(let V=0;V<z&&q<=A;V+=1){if(w.has(q))break;w.add(q);let I=K6(q,Y),O=Y/4;if(I+Y>$.length)break;let c=new DataView($.buffer,$.byteOffset+I,Y);for(let E=0;E<O-1;E+=1){let C=c.getUint32(E*4,!0);if(C<=A)F.push(C)}q=c.getUint32((O-1)*4,!0)}if(F.length<X);let H=[],Q6=Math.min(F.length,X||F.length,1e6);for(let V=0;V<Q6;V+=1){let I=F[V],O=K6(I,Y);if(O+Y>$.length)break;let c=new DataView($.buffer,$.byteOffset+O,Y),E=Y/4;for(let C=0;C<E;C+=1)H.push(c.getUint32(C*4,!0))}let L=Math.max(0,Math.floor(($.length+Y-1)/Y)-1);while(H.length>L){let V=H[H.length-1];if(V===0||V===P0||V===j0||V===y)H.pop();else break}while(H.length>L&&H[H.length-1]===y)H.pop();if(H.length>L)throw g.malformed(`not an OLE2 compound file: Malformed FAT (FAT has ${H.length} entries, but file has only ${L} sectors)`);while(H.length<L)H.push(y);let l=[];if(M>0&&j<=A){let V=d($,H,Y,j,M*Y),I=new DataView(V.buffer,V.byteOffset,V.byteLength);for(let O=0;O+4<=V.length;O+=4)l.push(I.getUint32(O,!0))}let m=d($,H,Y,U,$.length),b=[];for(let V=0;V+128<=m.length;V+=128)b.push(_0(m,V,Z));if(b.length===0||b[0].type!==F0)throw g.malformed("not an OLE2 compound file: missing root storage");return new T($,Y,G,D,H,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!==O6)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 W=this.entries[Y];if(W===void 0||W.type===I6)continue;if(R0(W.name,J))return W;K.push(W.left,W.right)}return}walkSiblings($,J){let Q=new Set,K=(Y)=>{if(Y>A||Q.has(Y))return;Q.add(Y);let W=this.entries[Y];if(W===void 0||W.type===I6)return;K(W.left),J.push({name:W.name,type:W.type}),K(W.right)};K($)}readEntryBytes($,J){let Q=Math.min($.size,J);if($.size<this.miniCutoff&&$.type===O6)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=$,W=new Set;while(K<J&&Y<=A){if(W.has(Y))break;W.add(Y);let G=Y*this.miniSectorSize,Z=Math.min(this.miniSectorSize,J-K);if(G+Z>this.miniStream.length)break;Q.set(this.miniStream.subarray(G,G+Z),K),K+=Z,Y=this.miniFat[Y]??A6}return K===J?Q:Q.subarray(0,K)}}var N0=Y6;function v($){return q6($,Y6)}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 K6($,J){return($+1)*J}function d($,J,Q,K,Y){if(K>A||Y<=0)return new Uint8Array(0);let W=[],G=0,Z=K,X=new Set;while(G<Y&&Z<=A){if(X.has(Z)||X.size>1e6)break;X.add(Z);let U=K6(Z,Q);if(U>=$.length)break;let D=Math.min(Q,Y-G,$.length-U);if(D<=0)break;if(W.push($.subarray(U,U+D)),G+=D,Z=J[Z]??A6,Z===y)break}return L0(W,G)}function _0($,J,Q){let K=new DataView($.buffer,$.byteOffset+J,128),Y=K.getUint16(64,!0),W=Math.max(0,Math.min(64,Y>0?Y-2:0)),G=new TextDecoder("utf-16le").decode($.subarray(J,J+W)),Z=$[J+66]??0,X=K.getUint32(68,!0),U=K.getUint32(72,!0),D=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:Z,left:X,right:U,child:D,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 I0}from"@mdgate/core";import{debug as z6,decode as O0,encodingExists as A0,warn as q0}from"@mdgate/utils";var B={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=B.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 W=K[Y];if(W.type==="elem"&&W.elem.local===J&&W.elem.ns===$)Q.push(W.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);S0($,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),W=this.lookupPrefix(K);return{ns:W,local:Y,bound:W!==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 B.OFFICE;case"http://openoffice.org/2000/text":return B.TEXT;case"http://openoffice.org/2000/table":return B.TABLE;case"http://openoffice.org/2000/drawing":return B.DRAW;case"http://openoffice.org/2000/presentation":return B.PRESENTATION;case"http://openoffice.org/2000/style":return B.STYLE;case"http://openoffice.org/2001/manifest":case"http://openoffice.org/2000/manifest":return B.MANIFEST;case"http://www.w3.org/1999/XSL/Format":return B.FO;default:return}}var x6=0,S6=1,E6=2,h=3,G6=4,v6=5;function i($){let J=w0($),Q=new h6(J),K=new C6,Y=new Map,W=new Map,G=new n(void 0,""),Z=[],X=!1;for(;;){let U;try{U=Q.next()}catch(D){let j=D instanceof Error?D.message:String(D);throw I0.malformed(`unparseable xml: ${j}`)}switch(U){case S6:{K.push(),K.applyDecls(Q.attrs);let D=k0(Q.name,Q.attrs,K,Y,W);if(Q.empty)W6(Z,G,{type:"elem",elem:D}),K.pop();else Z.push(D);break}case E6:{let D=Z.pop();if(D===void 0)X=!0;else{if(D.local!==Q.local)X=!0;W6(Z,G,{type:"elem",elem:D}),K.pop()}break}case h:{if(Q.text.length>0)Z6(Z,G,Q.text);break}case G6:{let D=X6(Q.name)??`&${Q.name};`;Z6(Z,G,D);break}case v6:{Z6(Z,G,Q.text);break}case x6:if(Z.length>0){X=!0;while(Z.length>0)W6(Z,G,{type:"elem",elem:Z.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 Z6($,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 W=Q.resolveElement($),G=W.ns!==void 0?T6(K,W.ns):void 0,Z=w6,X=!1;for(let U of J){if(U.rawName==="xmlns"||U.rawName.startsWith("xmlns:"))continue;let D=Q.resolveAttribute(U.rawName);if(!X)Z=[],X=!0;Z.push({ns:D.ns!==void 0?T6(K,D.ns):void 0,local:k6(Y,D.local),value:U.value})}if(W.local==="Choice"&&G===B.MC){let U=Z.find((D)=>D.local==="Requires");if(U!==void 0)U.value=U.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,W.local),Z)}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 O0($,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 W=K.indexOf(Y);if(W<0)return;return K.slice(0,W)}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,W=Number.parseInt(Y,K?16:10);if(!Number.isFinite(W))return;try{return String.fromCodePoint(W)}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 x6;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 S6}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,G6;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,G6}$+=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 W=this.s.slice(J,this.i);return this.i+=1,Q?o(W):W}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 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 S0($,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 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=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),W=R(Q,J+16);if(K===65535||Y===4294967295||W===4294967295){let U=o0($,J);if(U!==void 0)K=U.entryCount,Y=U.cdSize,W=U.cdOffset}if(W+Y>$.length)throw P.malformed("not a readable zip archive: truncated central directory");let G=[],Z=W,X=Math.min($.length,W+Y);while(Z+46<=X&&G.length<K){if(R(Q,Z)!==f0)throw P.malformed("not a readable zip archive: bad central directory");let U=N(Q,Z+8),D=N(Q,Z+10),j=R(Q,Z+16),M=R(Q,Z+20),S=R(Q,Z+24),z=N(Q,Z+28),F=N(Q,Z+30),q=N(Q,Z+32),w=R(Q,Z+42),H=$.subarray(Z+46,Z+46+z);if(Z+46+z+F+q>$.length)throw P.malformed("not a readable zip archive: truncated entry");let Q6=$.subarray(Z+46+z,Z+46+z+F),L=n0(Q6,{uncompressedSize:S,compressedSize:M,headerOffset:w});S=L.uncompressedSize,M=L.compressedSize,w=L.headerOffset;let l=(U&2048)!==0,m=i0(H,l);G.push({name:m,method:D,flags:U,crc:j,compressedSize:M,uncompressedSize:S,headerOffset:w}),Z+=46+z+F+q}return new D6($,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),W=Q+30+K+Y,G=W+$.compressedSize;if(W>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(W,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 W=Y instanceof Error?Y.message:String(Y);throw P.malformedPart($,`corrupt archive entry: ${W}`)}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 W=Y instanceof Error?Y.message:String(Y);throw P.malformedPart($.name,`unreadable archive entry: ${W}`)}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),W=N(K,Q+2),G=Q+4;if(G+W>$.length)break;if(Y===1){let Z=G,{uncompressedSize:X,compressedSize:U,headerOffset:D}=J;if(X===4294967295&&Z+8<=G+W)X=k(K,Z),Z+=8;if(U===4294967295&&Z+8<=G+W)U=k(K,Z),Z+=8;if(D===4294967295&&Z+8<=G+W)D=k(K,Z);return{uncompressedSize:X,compressedSize:U,headerOffset:D}}Q=G+W}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=U6(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 W=[];if(!J.startsWith("/")){let G=$.lastIndexOf("/");if(G>=0){for(let Z of $.slice(0,G).split("/"))if(Z.length>0)W.push(Z)}}for(let G of J.split("/")){if(G.length===0||G===".")continue;if(G===".."){W.pop();continue}let Z=U6(G);if(Z.includes("/")||Z.includes("\\"))throw l6.malformed(`percent-encoded separator in package reference segment ${c6(G)}`);if(Z==="."||Z==="..")throw l6.malformed(`percent-encoded traversal in package reference segment ${c6(G)}`);W.push(Z)}return{path:W.join("/"),fragment:Q}}function Q$($){return U6($)}var K$=new TextEncoder;function U6($){let J=K$.encode($),Q=[],K=0;while(K<J.length){if(J[K]===37&&K+2<J.length){let Y=J[K+1],W=J[K+2];if(m6(Y)&&m6(W)){Q.push(b6(Y)<<4|b6(W)),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 V6={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(B.PKG_RELS,"Relationship")){let W=Y.attrAny("Id"),G=Y.attrAny("Target");if(W===void 0||G===void 0)continue;let Z=Y.attrAny("TargetMode"),X=Z!==void 0&&Z.toLowerCase()==="external"?"external":"internal",U=Y.attrAny("Type")??"",D=u(U)??U;K.set(W,{target:G,relType:D,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 W;try{W=p(Q,Y.target)}catch(Z){d6(`skipping unresolvable relationship target ${JSON.stringify(Y.target)}: ${Z instanceof Error?Z.message:String(Z)}`);return}let G=$.optionalPart(W.path);if(G===void 0){d6(`relationship target ${W.path} is missing`);return}return[W.path,G]}function W$($){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",B6="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",Z$="http://schemas.openxmlformats.org/spreadsheetml/2006/main";function G$($){if($.length<4||$[0]!==80||$[1]!==75||$[2]!==3||$[3]!==4)return;try{return D$($)}catch{return}}function X$($){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 D$($){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 W=H6(J,"_rels/.rels").firstOfType(V6.OFFICE_DOCUMENT);if(W!==void 0){let G;try{G=p("",W.target)}catch{G=void 0}if(G!==void 0){let Z=j6(J,"[Content_Types].xml");if(Z!==void 0){let U=H$(Z,G.path);if(U!==void 0){let D=B$(U);if(D!==void 0)return D}}let X=j6(J,G.path);if(X!==void 0){let U=X.childElems()[0],D=U!==void 0?j$(U):void 0;if(D!==void 0)return D}return P$(G.path)}}}catch{}for(let[Y,W]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 W;try{let Y=j6(J,"META-INF/manifest.xml");if(Y!==void 0){for(let W of Y.descendants(B6,"file-entry"))if(W.attr(B6,"full-path")==="/"){let G=W.attr(B6,"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,W=!1,G=!1;for(let Z of J){let X=Z.toLowerCase();if(X.includes("encrypted")||X.endsWith(".iwae"))return;if(X.endsWith(".iwa")){if(Q=!0,X.endsWith("/document.iwa")||X==="document.iwa")Y=!0;if(X.includes("slide")||X.includes("masterslide"))W=!0;if(X.includes("calculationengine")||X.includes("tables/"))G=!0}if(X==="index.zip")K=!0}if(!Q&&!K)return;if(!Q&&K)return;if(!Y&&!K&&!W&&!G)return;if(W&&!G)return"keynote";if(G&&!W)return"numbers";if(Y)return"pages";return}function V$($,J){try{return $.optionalPart(J)}catch{return}}function j6($,J){try{return $.optionalXmlPart(J)}catch{return}}function n6($){switch($.endsWith("-template")?$.slice(0,-9):$){case"application/epub+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 H$($,J){let Q=`/${J}`;for(let W of $.descendants(o6,"Override")){let G=W.attrAny("PartName");if(G!==void 0&&_(G,Q)){let Z=W.attrAny("ContentType");if(Z!==void 0)return Z}}let K=J.lastIndexOf(".");if(K<0)return;let Y=J.slice(K+1);for(let W of $.descendants(o6,"Default")){let G=W.attrAny("Extension");if(G!==void 0&&_(G,Y))return W.attrAny("ContentType")}return}function B$($){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 B.W:return"docx";case B.P:return"pptx";case Z$: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 x}from"@mdgate/utils";function R$($){if(O$($)){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(I$($))}function _$($){let J=[],Q=(K)=>{J.push(K);for(let Y of K.parts)Q(Y)};return Q($),J}function Q0($){let J=Z0($);if(J!==void 0){let Q=G0($,J);if(Q!==void 0&&r6(Q)&&!M6(Q))return Q}return L6($,(Q)=>r6(Q)&&!M6(Q))}function K0($){return L6($,(J)=>J.contentType==="text/plain"&&J.parts.length===0&&!M6(J))}function L$($){let J=Q0($),Q=K0($),K=[],Y=(W)=>{if(W.parts.length>0){for(let G of W.parts)Y(G);return}if(W===J||W===Q)return;if(Y0(W.contentType)||W0(W.contentType))return;K.push(W)};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=F6(Q,"content-type")??"text/plain",Y=D0(K),W=x$(Q,Y.params),G=(F6(Q,"content-transfer-encoding")??"7bit").trim().toLowerCase(),Z=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:W,bytes:Z,parts:[]};let D=l$(Z,X).map((j)=>s(j));return{contentType:Y.type,headers:Q,filename:W,bytes:new Uint8Array(0),parts:D}}if(W0(Y.type)){let X=s(Z);return{contentType:Y.type,headers:Q,filename:W,bytes:Z,parts:[X]}}return{contentType:Y.type,headers:Q,filename:W,bytes:Z,parts:[]}}function Y0($){return $.startsWith("multipart/")}function W0($){return $==="message/rfc822"||$==="message/global"||$==="message/news"}function r6($){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 L6($,J){if(J($))return $;for(let Q of $.parts){let K=L6(Q,J);if(K!==void 0)return K}return}function Z0($){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 X0(Q)}for(let Q of $.parts){let K=Z0(Q);if(K!==void 0)return K}return}function G0($,J){let Q=J6($,"content-id");if(Q!==void 0&&X0(Q)===J)return $;for(let K of $.parts){let Y=G0(K,J);if(Y!==void 0)return Y}return}function X0($){let J=x($);if(J.startsWith("<")&&J.endsWith(">")&&J.length>=2)J=J.slice(1,-1);return J}function F6($,J){let Q=J.toLowerCase();for(let K=$.length-1;K>=0;K-=1)if($[K].name===Q)return $[K].value;return}function I$($){if($.length>=3&&$[0]===239&&$[1]===187&&$[2]===191)return $.subarray(3);return $}function O$($){return J0($,"From ")}function A$($){let J=[],Q=0;while(Q<$.length){if(N6($,Q))J.push(Q);Q=t($,Q)}if(J.length===0)return[];let K=[];for(let Y=0;Y<J.length;Y+=1){let W=J[Y],G=t($,W),Z=Y+1<J.length?J[Y+1]:$.length;if(G>Z)continue;K.push(q$($.subarray(G,Z)))}return K}function N6($,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&&N6($,Q+1))J+=1;Q=t($,Q)}if(J===0)return $;let K=new Uint8Array($.length-J),Y=0,W=0;while(Y<$.length){if($[Y]===62&&N6($,Y+1))Y+=1;let G=t($,Y);K.set($.subarray(Y,G),W),W+=G-Y,Y=G}return K.subarray(0,W)}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$(B0($)),Q=[],K=0;while(K<J.length){let Y=J.indexOf(`
3
+ `,K);if(Y<0)Y=J.length;let W=J.slice(K,Y);if(W.endsWith("\r"))W=W.slice(0,-1);if(K=Y+1,W.length===0)continue;let G=W.indexOf(":");if(G<=0)continue;let Z=W.slice(0,G).trim().toLowerCase();if(Z.length===0)continue;let X=S$(x(W.slice(G+1)));Q.push({name:Z,value:X})}return Q}function C$($){let J="";for(let Q=0;Q<$.length;Q+=1){let K=$[Q];if(K==="\r"&&$[Q+1]===`
4
4
  `&&R6($[Q+2])){J+=" ",Q+=2;continue}if((K===`
5
- `||K==="\r")&&R6($[Q+1])){J+=" ",Q+=1;continue}J+=K}return J}function R6($){return $===" "||$==="\t"}function X0($){let J=_6($,";"),Q=x(J<0?$:$.slice(0,J)).toLowerCase(),K=Q.length>0?Q:"application/octet-stream",Y=D0(J<0?"":$.slice(J+1));return{type:K,params:Y}}function D0($){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,";"),W=x(Y<0?K:K.slice(0,Y));Q+=Y<0?K.length:Y+1;let G=_6(W,"=");if(G<=0)continue;let Z=x(W.slice(0,G)).toLowerCase();if(Z.length===0)continue;J.set(Z,C$(x(W.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 C$($){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 g$($,J){let Q=F6($,"content-disposition");if(Q!==void 0){let K=r6(D0(Q));if(K!==void 0)return K}return r6(J)}function r6($){let J=a6($,"filename")??$.get("filename*");if(J!==void 0){let W=s6(J);if(W.length>0)return W}let Q=$.get("filename");if(Q!==void 0&&Q.length>0)return Q;let K=a6($,"name")??$.get("name*");if(K!==void 0){let W=s6(K);if(W.length>0)return W}let Y=$.get("name");return Y!==void 0&&Y.length>0?Y:void 0}function a6($,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 W=$.get(`${J}*${K}`);if(W===void 0)break;Q+=W}return Q.length>0?Q:void 0}function s6($){let J=$.indexOf("'");if(J<0)return P6($,"utf-8");let Q=$.indexOf("'",J+1);if(Q<0)return P6($,"utf-8");let K=$.slice(0,J)||"utf-8";return P6($.slice(Q+1),K)}function P6($,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 U0(Q.subarray(0,K),J)}function x$($){let J=/=\?([^?]+)\?([bBqQ])\?([^?]*)\?=/g,Q="",K=0,Y=-1,W;while((W=J.exec($))!==void 0&&W!==null){let G=W.index,Z=$.slice(K,G);if(Y>=0&&S$(Z));else Q+=Z;Q+=E$(W[1],W[2],W[3]),K=G+W[0].length,Y=K}if(K===0)return $;return Q+$.slice(K)}function S$($){for(let J=0;J<$.length;J+=1)if(!R6($[J]))return!1;return $.length>0}function E$($,J,Q){let K=J.toUpperCase(),Y;if(K==="B")Y=V0(new TextEncoder().encode(Q));else Y=v$(Q);return U0(Y,$)}function v$($){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 U0($,J){try{return n6($,J)}catch{try{return n6($,"utf-8")}catch{return H0($)}}}function h$($,J){if(J==="base64")return V0($);if(J==="quoted-printable")return u$($);return $}function u$($){let J=new Uint8Array($.length),Q=0;for(let K=0;K<$.length;K+=1){let Y=$[K];if(Y===61){let W=$[K+1],G=$[K+2];if(W===13&&G===10){K+=2;continue}if(W===10||W===13){K+=1;continue}if(W!==void 0&&G!==void 0&&t6(W)&&t6(G)){J[Q]=e6(W)<<4|e6(G),Q+=1,K+=2;continue}}if(Y===9||Y===32){let W=K+1;while(W<$.length&&($[W]===9||$[W]===32))W+=1;if(W<$.length&&($[W]===13||$[W]===10)){K=W-1;continue}}J[Q]=Y,Q+=1}return J.subarray(0,Q)}var f$=(()=>{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 V0($){let J=Math.floor($.length/4)*3+3,Q=new Uint8Array(J),K=0,Y=0,W=0;for(let G=0;G<$.length;G+=1){let Z=$[G];if(Z===61)break;if(Z>=128)continue;let X=f$[Z];if(X===255)continue;if(K=K<<6|X,Y+=6,Y>=8)Y-=8,Q[W]=K>>Y&255,W+=1}return Q.subarray(0,W)}function p$($,J){if(J.length===0)return[];let Q=new TextEncoder().encode(`--${J}`),K=[],Y=[],W=0;while(W+Q.length<=$.length){let Z=c$($,Q,W);if(Z<0)break;if(!l$($,Z)){W=Z+1;continue}K.push(Z);let X=Z+Q.length;Y.push($[X]===45&&$[X+1]===45),W=X}let G=[];for(let Z=0;Z<K.length;Z+=1){if(Y[Z])break;let X=m$($,K[Z]+Q.length),U=Z+1<K.length?K[Z+1]:-1;if(U<0)break;G.push($.subarray(X,b$($,X,U)))}return G}function l$($,J){if(J===0)return!0;let Q=$[J-1];return Q===10||Q===13}function m$($,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 b$($,J,Q){let K=Q;if(K>J&&$[K-1]===10)K-=1;if(K>J&&$[K-1]===13)K-=1;return K}function c$($,J,Q){if(J.length===0)return Q;let K=J[0],Y=Q+($.length-J.length);for(let W=Q;W<=Y;W+=1){if($[W]!==K)continue;let G=!0;for(let Z=1;Z<J.length;Z+=1)if($[W+Z]!==J[Z]){G=!1;break}if(G)return W}return-1}function H0($){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 t6($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function e6($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}export{R$ as walkMimeParts,p as resolve,Y$ as relsPartFor,V6 as relType,K$ as relTargetBytes,H6 as readRels,$$ as readOleStream,b0 as probeOle,i as parseXml,N$ as parseMime,q as ns,u as normalizeOoxmlUri,Q0 as mimeTextPlain,J0 as mimeTextHtml,J6 as mimeHeader,_$ as mimeAttachments,v as hasOleMagic,e0 as getU32,t0 as getU16,Z$ as detectZipDoc,G$ as detectOleDoc,J$ as decodeFragment,a as Relationships,f as Package,F0 as OLE_MAGIC_BYTES,n as Element,T as CompoundFile};
5
+ `||K==="\r")&&R6($[Q+1])){J+=" ",Q+=1;continue}J+=K}return J}function R6($){return $===" "||$==="\t"}function D0($){let J=_6($,";"),Q=x(J<0?$:$.slice(0,J)).toLowerCase(),K=Q.length>0?Q:"application/octet-stream",Y=U0(J<0?"":$.slice(J+1));return{type:K,params:Y}}function U0($){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,";"),W=x(Y<0?K:K.slice(0,Y));Q+=Y<0?K.length:Y+1;let G=_6(W,"=");if(G<=0)continue;let Z=x(W.slice(0,G)).toLowerCase();if(Z.length===0)continue;J.set(Z,g$(x(W.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 g$($){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 x$($,J){let Q=F6($,"content-disposition");if(Q!==void 0){let K=a6(U0(Q));if(K!==void 0)return K}return a6(J)}function a6($){let J=s6($,"filename")??$.get("filename*");if(J!==void 0){let W=t6(J);if(W.length>0)return W}let Q=$.get("filename");if(Q!==void 0&&Q.length>0)return Q;let K=s6($,"name")??$.get("name*");if(K!==void 0){let W=t6(K);if(W.length>0)return W}let Y=$.get("name");return Y!==void 0&&Y.length>0?Y:void 0}function s6($,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 W=$.get(`${J}*${K}`);if(W===void 0)break;Q+=W}return Q.length>0?Q:void 0}function t6($){let J=$.indexOf("'");if(J<0)return P6($,"utf-8");let Q=$.indexOf("'",J+1);if(Q<0)return P6($,"utf-8");let K=$.slice(0,J)||"utf-8";return P6($.slice(Q+1),K)}function P6($,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 V0(Q.subarray(0,K),J)}function S$($){let J=/=\?([^?]+)\?([bBqQ])\?([^?]*)\?=/g,Q="",K=0,Y=-1,W;while((W=J.exec($))!==void 0&&W!==null){let G=W.index,Z=$.slice(K,G);if(Y>=0&&E$(Z));else Q+=Z;Q+=v$(W[1],W[2],W[3]),K=G+W[0].length,Y=K}if(K===0)return $;return Q+$.slice(K)}function E$($){for(let J=0;J<$.length;J+=1)if(!R6($[J]))return!1;return $.length>0}function v$($,J,Q){let K=J.toUpperCase(),Y;if(K==="B")Y=H0(new TextEncoder().encode(Q));else Y=h$(Q);return V0(Y,$)}function h$($){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 V0($,J){try{return i6($,J)}catch{try{return i6($,"utf-8")}catch{return B0($)}}}function u$($,J){if(J==="base64")return H0($);if(J==="quoted-printable")return f$($);return $}function f$($){let J=new Uint8Array($.length),Q=0;for(let K=0;K<$.length;K+=1){let Y=$[K];if(Y===61){let W=$[K+1],G=$[K+2];if(W===13&&G===10){K+=2;continue}if(W===10||W===13){K+=1;continue}if(W!==void 0&&G!==void 0&&e6(W)&&e6(G)){J[Q]=$0(W)<<4|$0(G),Q+=1,K+=2;continue}}if(Y===9||Y===32){let W=K+1;while(W<$.length&&($[W]===9||$[W]===32))W+=1;if(W<$.length&&($[W]===13||$[W]===10)){K=W-1;continue}}J[Q]=Y,Q+=1}return J.subarray(0,Q)}var p$=(()=>{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,W=0;for(let G=0;G<$.length;G+=1){let Z=$[G];if(Z===61)break;if(Z>=128)continue;let X=p$[Z];if(X===255)continue;if(K=K<<6|X,Y+=6,Y>=8)Y-=8,Q[W]=K>>Y&255,W+=1}return Q.subarray(0,W)}function l$($,J){if(J.length===0)return[];let Q=new TextEncoder().encode(`--${J}`),K=[],Y=[],W=0;while(W+Q.length<=$.length){let Z=d$($,Q,W);if(Z<0)break;if(!m$($,Z)){W=Z+1;continue}K.push(Z);let X=Z+Q.length;Y.push($[X]===45&&$[X+1]===45),W=X}let G=[];for(let Z=0;Z<K.length;Z+=1){if(Y[Z])break;let X=b$($,K[Z]+Q.length),U=Z+1<K.length?K[Z+1]:$.length;G.push($.subarray(X,c$($,X,U)))}return G}function m$($,J){if(J===0)return!0;let Q=$[J-1];return Q===10||Q===13}function b$($,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 c$($,J,Q){let K=Q;if(K>J&&$[K-1]===10)K-=1;if(K>J&&$[K-1]===13)K-=1;return K}function d$($,J,Q){if(J.length===0)return Q;let K=J[0],Y=Q+($.length-J.length);for(let W=Q;W<=Y;W+=1){if($[W]!==K)continue;let G=!0;for(let Z=1;Z<J.length;Z+=1)if($[W+Z]!==J[Z]){G=!1;break}if(G)return W}return-1}function B0($){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 e6($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function $0($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}export{_$ as walkMimeParts,p as resolve,W$ as relsPartFor,V6 as relType,Y$ as relTargetBytes,H6 as readRels,J$ as readOleStream,c0 as probeOle,i as parseXml,R$ as parseMime,B as ns,g6 as normalizeStarOfficeUri,u as normalizeOoxmlUri,K0 as mimeTextPlain,Q0 as mimeTextHtml,J6 as mimeHeader,L$ as mimeAttachments,v as hasOleMagic,$$ as getU32,e0 as getU16,G$ as detectZipDoc,X$ as detectOleDoc,Q$ as decodeFragment,a as Relationships,f as Package,N0 as OLE_MAGIC_BYTES,n as Element,T as CompoundFile};
package/dist/xml.d.ts CHANGED
@@ -71,4 +71,6 @@ export declare class Element {
71
71
  * `2006` version segment dropped.
72
72
  */
73
73
  export declare function normalizeOoxmlUri(uri: string): string | undefined;
74
+ /** StarOffice 6 / OpenOffice.org 1.x vocabularies map onto ODF 1.0 names. */
75
+ export declare function normalizeStarOfficeUri(uri: string): string | undefined;
74
76
  export declare function parseXml(bytes: Uint8Array): Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/containers",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "mdgate container parsing: ZIP/OPC packages, OLE compound files, XML",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,8 +22,8 @@
22
22
  "prepublishOnly": "bun run build"
23
23
  },
24
24
  "dependencies": {
25
- "@mdgate/core": "0.5.1",
26
- "@mdgate/utils": "0.5.1"
25
+ "@mdgate/core": "0.5.2",
26
+ "@mdgate/utils": "0.5.2"
27
27
  },
28
28
  "publishConfig": {
29
29
  "access": "public"