@mdgate/containers 0.1.0 → 0.1.1

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/detect.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /** What a ZIP-based document container holds. */
2
- export type ZipDocKind = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'ods' | 'odp' | 'epub' | 'pages' | 'numbers' | 'keynote';
2
+ export type ZipDocKind = 'docx' | 'pptx' | 'xlsx' | 'odt' | 'ods' | 'odp' | 'odg' | 'epub' | 'pages' | 'numbers' | 'keynote' | 'vsdx' | 'hwpx';
3
3
  /** What an OLE compound file holds. */
4
- export type OleDocKind = 'doc' | 'ppt' | 'xls';
4
+ export type OleDocKind = 'doc' | 'ppt' | 'xls' | 'vsd' | 'hwp' | 'one';
5
5
  /**
6
6
  * Classify a ZIP-based document container by its content. Returns undefined
7
7
  * for non-ZIP bytes and unrecognized packages. Never throws.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { getU16, getU32, readOleStream } from './binary.js';
3
3
  export { CompoundFile, hasOleMagic, OLE_MAGIC_BYTES } from './cfb.js';
4
4
  export { detectOleDoc, detectZipDoc, type OleDocKind, type ZipDocKind, } from './detect.js';
5
5
  export { MAX_ENTRY_BYTES, MAX_ENTRY_COUNT, MAX_RECORD_DEPTH, MAX_RECORDS, MAX_TOTAL_BYTES, MAX_XML_DEPTH, MAX_XML_NODES, } from './limits.js';
6
+ export { type MimeHeader, type MimePart, mimeAttachments, mimeHeader, mimeTextHtml, mimeTextPlain, parseMime, walkMimeParts, } from './mime.js';
6
7
  export { decodeFragment, resolve, type Target } from './path.js';
7
8
  export { type Relationship, Relationships, type RelTarget, readRels, relsPartFor, relTargetBytes, relType, type TargetMode, } from './relationships.js';
8
9
  export { type Attr, Element, normalizeOoxmlUri, ns, parseXml, type XmlNode, } from './xml.js';
package/dist/index.js CHANGED
@@ -1,2 +1,5 @@
1
- import{ConvertError as P}from"@mdgate/core";import{decode as U6,InflateLimitError as V6,inflateRaw as Y6,warn as T1}from"@mdgate/utils";import{ConvertError as _}from"@mdgate/core";var L=134217728,$1=536870912,m=1e5,c=256,i=2000000,y1=64,f1=16000000;var W1=[208,207,17,224,161,177,26,225],n=4294967295,R1=4294967294,d1=4294967293,m1=4294967292,c1=4294967295,N=4294967290,F1=0;var L1=2,i1=5;class z{bytes;sectorSize;miniSectorSize;miniCutoff;fat;miniFat;entries;miniStream;constructor(J,Q,$,K,W,Z,G){this.bytes=J,this.sectorSize=Q,this.miniSectorSize=$,this.miniCutoff=K,this.fat=W,this.miniFat=Z,this.entries=G}static open(J){if(J.length<512||!M1(J,W1))throw _.malformed("not an OLE2 compound file");let Q=new DataView(J.buffer,J.byteOffset,J.byteLength);if(Q.getUint16(28,!0)!==65534)throw _.malformed("not an OLE2 compound file: bad byte order");let K=Q.getUint16(30,!0);if(K!==9&&K!==12)throw _.malformed("not an OLE2 compound file: bad sector shift");let W=1<<K,Z=Q.getUint16(32,!0),G=Z===0?64:1<<Z,H=Q.getUint16(26,!0),U=Q.getUint32(44,!0),D=Q.getUint32(48,!0),V=Q.getUint32(56,!0)||4096,Y=Q.getUint32(60,!0),X=Q.getUint32(64,!0),h=Q.getUint32(68,!0),k=Q.getUint32(72,!0),F=[];for(let j=0;j<109;j+=1){let q=Q.getUint32(76+j*4,!0);if(q<=N)F.push(q)}let w=h,T=new Set;for(let j=0;j<k&&w<=N;j+=1){if(T.has(w))break;T.add(w);let q=K1(w,W),O=W/4;if(q+W>J.length)break;let d=new DataView(J.buffer,J.byteOffset+q,W);for(let v=0;v<O-1;v+=1){let C=d.getUint32(v*4,!0);if(C<=N)F.push(C)}w=d.getUint32((O-1)*4,!0)}if(F.length<U);let B=[],Q1=Math.min(F.length,U||F.length,1e6);for(let j=0;j<Q1;j+=1){let q=F[j],O=K1(q,W);if(O+W>J.length)break;let d=new DataView(J.buffer,J.byteOffset+O,W),v=W/4;for(let C=0;C<v;C+=1)B.push(d.getUint32(C*4,!0))}let I=Math.max(0,Math.floor((J.length+W-1)/W)-1);while(B.length>I){let j=B[B.length-1];if(j===0||j===m1||j===d1||j===n)B.pop();else break}while(B.length>I&&B[B.length-1]===n)B.pop();if(B.length>I)throw _.malformed(`not an OLE2 compound file: Malformed FAT (FAT has ${B.length} entries, but file has only ${I} sectors)`);while(B.length<I)B.push(n);let y=[];if(X>0&&Y<=N){let j=o(J,B,W,Y,X*W),q=new DataView(j.buffer,j.byteOffset,j.byteLength);for(let O=0;O+4<=j.length;O+=4)y.push(q.getUint32(O,!0))}let f=o(J,B,W,D,L),S=[];for(let j=0;j+128<=f.length;j+=128)if(S.push(a1(f,j,H)),S.length>1e5)break;if(S.length===0||S[0].type!==i1)throw _.malformed("not an OLE2 compound file: missing root storage");return new z(J,W,G,V,B,y,S)}readRootStorage(){let J=this.entries[0];if(J===void 0)return[];let Q=[];return this.walkSiblings(J.child,Q),Q}exists(J){return this.lookup(J)!==void 0}readStream(J){let Q=this.lookup(J);if(Q===void 0||Q.type!==L1)throw _.missingPart(J);if(Q.size>L)throw _.resourceLimit("max_entry_bytes",`${J} stream exceeds the read cap`);let $=this.readEntryBytes(Q,L+1);if($.length>L)throw _.resourceLimit("max_entry_bytes",`${J} stream exceeds the read cap`);return $}lookup(J){let Q=J.split("/").filter((W)=>W.length>0);if(Q.length===0)return this.entries[0];let $=this.entries[0]?.child??c1,K;for(let W of Q){if(K=this.findChild($,W),K===void 0)return;$=K.child}return K}findChild(J,Q){let $=new Set,K=[J];while(K.length>0){let W=K.pop();if(W>N||$.has(W))continue;$.add(W);let Z=this.entries[W];if(Z===void 0||Z.type===F1)continue;if(n1(Z.name,Q))return Z;K.push(Z.left,Z.right)}return}walkSiblings(J,Q){let $=new Set,K=(W)=>{if(W>N||$.has(W)||$.size>1e5)return;$.add(W);let Z=this.entries[W];if(Z===void 0||Z.type===F1)return;K(Z.left),Q.push({name:Z.name,type:Z.type}),K(Z.right)};K(J)}readEntryBytes(J,Q){let $=Math.min(J.size,Q);if(J.size<this.miniCutoff&&J.type===L1)return this.readMiniChain(J.start,$);return o(this.bytes,this.fat,this.sectorSize,J.start,$)}readMiniChain(J,Q){if(this.miniStream===void 0){let G=this.entries[0];this.miniStream=o(this.bytes,this.fat,this.sectorSize,G.start,G.size)}let $=new Uint8Array(Q),K=0,W=J,Z=new Set;while(K<Q&&W<=N){if(Z.has(W))break;Z.add(W);let G=W*this.miniSectorSize,H=Math.min(this.miniSectorSize,Q-K);if(G+H>this.miniStream.length)break;$.set(this.miniStream.subarray(G,G+H),K),K+=H,W=this.miniFat[W]??R1}return K===Q?$:$.subarray(0,K)}}var o1=W1;function E(J){return M1(J,W1)}function M1(J,Q){if(J.length<Q.length)return!1;for(let $=0;$<Q.length;$+=1)if(J[$]!==Q[$])return!1;return!0}function n1(J,Q){return J.length===Q.length&&J.toLowerCase()===Q.toLowerCase()}function K1(J,Q){return(J+1)*Q}function o(J,Q,$,K,W){if(K>N||W<=0)return new Uint8Array(0);let Z=[],G=0,H=K,U=new Set;while(G<W&&H<=N){if(U.has(H)||U.size>1e6)break;U.add(H);let D=K1(H,$);if(D>=J.length)break;let V=Math.min($,W-G,J.length-D);if(V<=0)break;if(Z.push(J.subarray(D,D+V)),G+=V,H=Q[H]??R1,H===n)break}return s1(Z,G)}function a1(J,Q,$){let K=new DataView(J.buffer,J.byteOffset+Q,128),W=K.getUint16(64,!0),Z=Math.max(0,Math.min(64,W>0?W-2:0)),G=new TextDecoder("utf-16le").decode(J.subarray(Q,Q+Z)),H=J[Q+66]??0,U=K.getUint32(68,!0),D=K.getUint32(72,!0),V=K.getUint32(76,!0),Y=K.getUint32(116,!0),X=Number(K.getBigUint64(120,!0));if($===3)X=K.getUint32(120,!0);if(!Number.isFinite(X)||X<0)X=0;return{name:G,type:H,left:U,right:D,child:V,start:Y,size:X}}function s1(J,Q){if(J.length===1&&J[0].length===Q)return J[0];let $=new Uint8Array(Q),K=0;for(let W of J)$.set(W,K),K+=W.length;return $}import{ConvertError as G1}from"@mdgate/core";import{debug as I1,decode as r1,encodingExists as t1,warn as e1}from"@mdgate/utils";var A={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"},J6=A.XML,Q6="http://www.w3.org/2000/xmlns/",N1=[];class r{ns;local;attrs;children;_elems;constructor(J,Q,$=N1,K=[]){this.ns=J,this.local=Q,this.attrs=$,this.children=K}is(J,Q){return this.local===Q&&this.ns===J}attr(J,Q){return this.attrQualified(J,Q)??this.attrUnqualified(Q)}attrQualified(J,Q){let $=this.attrs;for(let K=0;K<$.length;K+=1){let W=$[K];if(W.local===Q&&W.ns===J)return W.value}return}attrUnqualified(J){let Q=this.attrs;for(let $=0;$<Q.length;$+=1){let K=Q[$];if(K.local===J&&K.ns===void 0)return K.value}return}attrAny(J){let Q=this.attrs;for(let $=0;$<Q.length;$+=1){let K=Q[$];if(K.local===J)return K.value}return}childElems(){if(this._elems!==void 0)return this._elems;let J=[],Q=this.children;for(let $=0;$<Q.length;$+=1){let K=Q[$];if(K.type==="elem")J.push(K.elem)}return this._elems=J,J}find(J,Q){let $=this.children;for(let K=0;K<$.length;K+=1){let W=$[K];if(W.type==="elem"&&W.elem.local===Q&&W.elem.ns===J)return W.elem}return}findAll(J,Q){let $=[],K=this.children;for(let W=0;W<K.length;W+=1){let Z=K[W];if(Z.type==="elem"&&Z.elem.local===Q&&Z.elem.ns===J)$.push(Z.elem)}return $}*descendantNodes(){let J=this.children.slice();J.reverse();while(J.length>0){let Q=J.pop();if(Q.type==="elem"){let $=J.length;for(let K of Q.elem.children)J.push(K);G6(J,$)}yield Q}}*descendantElems(){for(let J of this.descendantNodes())if(J.type==="elem")yield J.elem}firstDescendant(J,Q){for(let $ of this.descendantElems())if($.is(J,Q))return $;return}*descendants(J,Q){for(let $ of this.descendantElems())if($.is(J,Q))yield $}*descendantsAny(J){for(let Q of this.descendantElems())if(Q.local===J)yield Q}text(){let J="";for(let Q of this.descendantNodes())if(Q.type==="text")J+=Q.text;return J}}class w1{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(J){for(let Q of J)if(Q.rawName==="xmlns")this.defaultNs[this.defaultNs.length-1]=Q.value.length===0?void 0:Q.value;else if(Q.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.rawName.slice(6);this.prefixes[this.prefixes.length-1].set($,Q.value.length===0?void 0:Q.value)}}lookupPrefix(J){if(J==="xml")return J6;if(J==="xmlns")return Q6;return this.prefixes[this.prefixes.length-1].get(J)}resolveElement(J){let Q=J.indexOf(":");if(Q>=0){let K=J.slice(0,Q),W=J.slice(Q+1),Z=this.lookupPrefix(K);return{ns:Z,local:W,bound:Z!==void 0||K==="xml"||K==="xmlns"}}let $=this.defaultNs[this.defaultNs.length-1];return{ns:$,local:J,bound:$!==void 0}}resolveAttribute(J){let Q=J.indexOf(":");if(Q>=0){let $=J.slice(0,Q),K=J.slice(Q+1);return{ns:this.lookupPrefix($),local:K}}return{ns:void 0,local:J}}}function u(J){let Q=D6(J,"http://purl.oclc.org/ooxml/");if(Q===void 0)return;let $=Q.indexOf("/");if($<0)return;let K=Q.slice(0,$),W=Q.slice($+1);return`http://schemas.openxmlformats.org/${K}/2006/${W}`}var _1=0,A1=1,k1=2,p=3,D1=4,z1=5;function t(J){let Q=K6(J),$=new g1(Q),K=new w1,W=new Map,Z=new Map,G=new r(void 0,""),H=[],U=0,D=!1;for(;;){let V;try{V=$.next()}catch(Y){let X=Y instanceof Error?Y.message:String(Y);throw G1.malformed(`unparseable xml: ${X}`)}switch(V){case A1:{if(!$.empty&&H.length>=c)throw G1.resourceLimit("max_xml_depth",`element nesting exceeds ${c}`);a(U),U+=1,K.push(),K.applyDecls($.attrs);let Y=$6($.name,$.attrs,K,W,Z);if($.empty)Z1(H,G,{type:"elem",elem:Y}),K.pop();else H.push(Y);break}case k1:{let Y=H.pop();if(Y===void 0)D=!0;else{if(Y.local!==$.local)D=!0;Z1(H,G,{type:"elem",elem:Y}),K.pop()}break}case p:{if($.text.length>0)a(U),U+=1,H1(H,G,$.text);break}case D1:{let Y=U1($.name)??`&${$.name};`;a(U),U+=1,H1(H,G,Y);break}case z1:{a(U),U+=1,H1(H,G,$.text);break}case _1:if(H.length>0){D=!0;while(H.length>0)Z1(H,G,{type:"elem",elem:H.pop()})}if(D)e1("recovered malformed xml (unclosed or mismatched elements)");return G}}}function a(J){if(J+1>i)throw G1.resourceLimit("max_xml_nodes",`part exceeds ${i} xml nodes`)}function Z1(J,Q,$){let K=J[J.length-1];if(K!==void 0)K.children.push($);else Q.children.push($)}function H1(J,Q,$){let K=J[J.length-1]?.children??Q.children,W=K[K.length-1];if(W?.type==="text")W.text+=$;else K.push({type:"text",text:$})}function q1(J,Q){let $=J.get(Q);if($!==void 0)return $;let K=u(Q)??Q;return J.set(Q,K),K}function O1(J,Q){let $=J.get(Q);if($!==void 0)return $;return J.set(Q,Q),Q}function $6(J,Q,$,K,W){let Z=$.resolveElement(J),G=Z.ns!==void 0?q1(K,Z.ns):void 0,H=N1,U=!1;for(let D of Q){if(D.rawName==="xmlns"||D.rawName.startsWith("xmlns:"))continue;let V=$.resolveAttribute(D.rawName);if(!U)H=[],U=!0;H.push({ns:V.ns!==void 0?q1(K,V.ns):void 0,local:O1(W,V.local),value:D.value})}if(Z.local==="Choice"&&G===A.MC){let D=H.find((V)=>V.local==="Requires");if(D!==void 0)D.value=D.value.split(/\s+/).filter((V)=>V.length>0).map((V)=>{let Y=$.resolveElement(`${V}:x`);if(Y.bound&&Y.ns!==void 0)return u(Y.ns)??Y.ns;return V}).join(" ")}return new r(G,O1(W,Z.local),H)}function K6(J){if(J.length>=2&&J[0]===255&&J[1]===254)return new TextDecoder("utf-16le").decode(J);if(J.length>=2&&J[0]===254&&J[1]===255)return new TextDecoder("utf-16be").decode(J);if(J.length>=3&&J[0]===239&&J[1]===187&&J[2]===191)return new TextDecoder("utf-8").decode(J.subarray(3));let Q=J.subarray(0,Math.min(J.length,200)),$=W6(Q);if($!==void 0){let K=Z6($);if(K!==void 0&&K!=="utf8"&&K!=="utf-8")return r1(J,K)}return new TextDecoder("utf-8").decode(J)}function W6(J){let Q;try{Q=new TextDecoder("utf-8",{fatal:!0}).decode(J)}catch{return}let $=Q.indexOf("encoding");if($<0)return;let K=Q.slice($+8).trimStart();if(!K.startsWith("="))return;K=K.slice(1).trimStart();let W=K[0];if(W!=='"'&&W!=="'")return;K=K.slice(1);let Z=K.indexOf(W);if(Z<0)return;return K.slice(0,Z)}function Z6(J){let Q=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"}[Q]??Q;return t1(K)?K:void 0}function U1(J){if(J.startsWith("#")){let $=J.slice(1),K=$.startsWith("x")||$.startsWith("X"),W=K?$.slice(1):$,Z=Number.parseInt(W,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:"¢"}[J]}class g1{s;i=0;name="";local="";text="";empty=!1;attrs=[];constructor(J){this.s=J}next(){if(this.i>=this.s.length)return _1;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 J=this.s.indexOf("-->",this.i);if(J<0)throw Error("unterminated comment");return this.i=J+3,this.next()}if(this.startsWith("<![CDATA[")){this.i+=9;let J=this.s.indexOf("]]>",this.i);if(J<0)throw Error("unterminated cdata");return this.text=this.s.slice(this.i,J),this.i=J+3,z1}if(this.startsWith("<!"))return this.skipDoctype(),this.next();if(this.startsWith("</")){this.i+=2;let J=this.readName();if(this.skipWs(),this.s[this.i]===">")this.i+=1;return this.local=H6(J),k1}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 A1}textRun(){let J=this.i;while(this.i<this.s.length){let Q=this.s.charCodeAt(this.i);if(Q===60)break;if(Q===38){if(this.i>J)return this.text=this.s.slice(J,this.i),p;let $=this.readReference();if($.type==="general")return this.name=$.name,D1;return this.i=J,this.textRunSlow()}this.i+=1}return this.text=this.s.slice(J,this.i),p}textRunSlow(){let J="";while(this.i<this.s.length){let Q=this.s.charCodeAt(this.i);if(Q===60)break;if(Q===38){let K=this.readReference();if(K.type==="general"){if(J.length>0)return this.i=K.rewind,this.text=J,p;return this.name=K.name,D1}J+=K.text;continue}let $=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}J+=this.s.slice($,this.i)}return this.text=J,p}readReference(){let J=this.i;this.i+=1;let Q=this.s.indexOf(";",this.i);if(Q<0)return{type:"char",text:"&"};let $=this.s.slice(this.i,Q);if(this.i=Q+1,$.startsWith("#")||$==="amp"||$==="lt"||$==="gt"||$==="apos"||$==="quot")return{type:"char",text:U1($)??`&${$};`};return{type:"general",name:$,rewind:J}}readName(){let J=this.i;while(this.i<this.s.length){let Q=this.s.charCodeAt(this.i);if(Q===47||Q===62||Q===61||Q===32||Q===9||Q===10||Q===13)break;this.i+=1}return this.s.slice(J,this.i)}readAttrs(){let J=[];for(;;){this.skipWs();let Q=this.s[this.i];if(Q===void 0||Q===">"||Q==="/")break;let $=this.readName();if($.length===0){this.i+=1;continue}if(this.skipWs(),this.s[this.i]!=="="){I1(`dropping undecodable attribute: ${$}`);continue}this.i+=1,this.skipWs();let K=this.readAttrValue();if(K===void 0){I1(`dropping undecodable attribute: ${$}`);continue}J.push({rawName:$,value:K})}return J}readAttrValue(){let J=this.s.charCodeAt(this.i);if(J!==34&&J!==39)return;this.i+=1;let Q=this.i,$=!1;while(this.i<this.s.length){let W=this.s.charCodeAt(this.i);if(W===J){let Z=this.s.slice(Q,this.i);return this.i+=1,$?s(Z):Z}if(W===38)return this.i=Q,this.readAttrValueSlow(J);if(W===9||W===10||W===13)$=!0;this.i+=1}let K=this.s.slice(Q,this.i);return $?s(K):K}readAttrValueSlow(J){let Q="";while(this.i<this.s.length){let $=this.s.charCodeAt(this.i);if($===J)return this.i+=1,s(Q);if($===38){let W=this.readReference();if(W.type==="char")Q+=W.text;else Q+=U1(W.name)??`&${W.name};`;continue}let K=this.i;this.i+=1;while(this.i<this.s.length){let W=this.s.charCodeAt(this.i);if(W===J||W===38)break;this.i+=1}Q+=this.s.slice(K,this.i)}return s(Q)}skipWs(){while(this.i<this.s.length){let J=this.s.charCodeAt(this.i);if(J!==32&&J!==9&&J!==10&&J!==13)break;this.i+=1}}startsWith(J){return this.s.startsWith(J,this.i)}skipUntil(J){let Q=this.s.indexOf(J,this.i);this.i=Q<0?this.s.length:Q+J.length}skipDoctype(){this.i+=2;let J=0;while(this.i<this.s.length){let Q=this.s[this.i];if(Q==='"'||Q==="'"){let $=Q;this.i+=1;while(this.i<this.s.length&&this.s[this.i]!==$)this.i+=1;if(this.i<this.s.length)this.i+=1;continue}if(Q==="<")J+=1;else if(Q===">"){if(J===0){this.i+=1;return}J-=1}this.i+=1}}}function H6(J){let Q=J.indexOf(":");return Q<0?J:J.slice(Q+1)}function s(J){if(J.indexOf("\t")<0&&J.indexOf(`
2
- `)<0&&J.indexOf("\r")<0)return J;return J.replace(/[\t\n\r]/g," ")}function G6(J,Q){let $=Q,K=J.length-1;while($<K){let W=J[$];J[$]=J[K],J[K]=W,$+=1,K-=1}}function D6(J,Q){return J.startsWith(Q)?J.slice(Q.length):void 0}var j6=67324752,B6=33639248;var P6=101075792,X6=117853008,F6=0,L6=8;class V1{length;bytes;byName=new Map;constructor(J,Q){this.bytes=J,this.length=Q.length;for(let $ of Q)if(!this.byName.has($.name))this.byName.set($.name,$)}static open(J){let Q=I6(J);if(Q<0)throw P.malformed("not a readable zip archive: invalid Zip archive: Could not find EOCD");let $=e(J),K=R($,Q+10),W=M($,Q+12),Z=M($,Q+16);if(K===65535||W===4294967295||Z===4294967295){let D=q6(J,Q);if(D!==void 0)K=D.entryCount,W=D.cdSize,Z=D.cdOffset}if(K>m);if(Z+W>J.length)throw P.malformed("not a readable zip archive: truncated central directory");let G=[],H=Z,U=Math.min(J.length,Z+W);while(H+46<=U&&G.length<K){if(M($,H)!==B6)throw P.malformed("not a readable zip archive: bad central directory");let D=R($,H+8),V=R($,H+10),Y=M($,H+16),X=M($,H+20),h=M($,H+24),k=R($,H+28),F=R($,H+30),w=R($,H+32),T=M($,H+42),B=J.subarray(H+46,H+46+k);if(H+46+k+F+w>J.length)throw P.malformed("not a readable zip archive: truncated entry");let Q1=J.subarray(H+46+k,H+46+k+F),I=O6(Q1,{uncompressedSize:h,compressedSize:X,headerOffset:T});h=I.uncompressedSize,X=I.compressedSize,T=I.headerOffset;let y=(D&2048)!==0,f=N6(B,y);G.push({name:f,method:V,flags:D,crc:Y,compressedSize:X,uncompressedSize:h,headerOffset:T}),H+=46+k+F+w}return new V1(J,G)}indexForName(J){return this.byName.get(J)}partNames(){return[...this.byName.keys()]}readCompressed(J){let Q=e(this.bytes),$=J.headerOffset;if($+30>this.bytes.length||M(Q,$)!==j6)throw Error("bad local file header");let K=R(Q,$+26),W=R(Q,$+28),Z=$+30+K+W,G=Z+J.compressedSize;if(Z>this.bytes.length)throw Error("truncated local file header");if(J.compressedSize>0&&G>this.bytes.length)throw Error("truncated compressed data");return this.bytes.subarray(Z,Math.min(G,this.bytes.length))}}class l{zip;totalRead=0;cache=new Map;constructor(J){this.zip=J}static open(J){let Q;try{Q=V1.open(J)}catch($){if($ instanceof P)throw $;let K=$ instanceof Error?$.message:String($);throw P.malformed(`not a readable zip archive: ${K}`)}if(Q.length>m)throw P.resourceLimit("max_entry_count",`archive contains ${Q.length} entries`);return new l(Q)}part(J){J=C1(J);let Q=this.cache.get(J);if(Q!==void 0)return Q;let $=this.zip.indexForName(J);if($===void 0)return;if($.uncompressedSize>L)throw P.resourceLimit("max_entry_bytes",`${J} declares ${$.uncompressedSize} decompressed bytes`);let K=Math.max(0,$1-this.totalRead),W=Math.min(L,K),Z;try{Z=this.decompress($,W+1)}catch(G){if(G instanceof P)throw G;let H=G instanceof Error?G.message:String(G);throw P.malformedPart(J,`corrupt archive entry: ${H}`)}if(Z.length>W){if(K<L)throw P.resourceLimit("max_total_bytes",`${J} exceeds the archive's remaining decompression budget`);throw P.resourceLimit("max_entry_bytes",`${J} exceeds the decompression cap`)}return this.totalRead+=Z.length,this.cache.set(J,Z),Z}hasPart(J){return this.zip.indexForName(C1(J))!==void 0}partNames(){return this.zip.partNames()}requiredPart(J){let Q=this.part(J);if(Q===void 0)throw P.missingPart(J);return Q}optionalPart(J){try{return this.part(J)}catch(Q){if(Q instanceof P&&Q.isFatal())throw Q;T1(`skipping unreadable part ${J}: ${Q instanceof Error?Q.message:String(Q)}`);return}}optionalXmlPart(J){let Q=this.optionalPart(J);if(Q===void 0)return;try{return t(Q)}catch($){if($ instanceof P&&$.isFatal())throw $;T1(`skipping corrupt part ${J}: ${$ instanceof Error?$.message:String($)}`);return}}requiredXmlPart(J){return t(this.requiredPart(J))}decompress(J,Q){if((J.flags&1)!==0)throw Error("encrypted zip entry");let $;try{$=this.zip.readCompressed(J)}catch(W){let Z=W instanceof Error?W.message:String(W);throw P.malformedPart(J.name,`unreadable archive entry: ${Z}`)}let K;if(J.method===F6){let W=J.uncompressedSize>0?J.uncompressedSize:$.length;K=$.subarray(0,Math.min(W,Q,$.length))}else if(J.method===L6)K=M6($,Q);else throw Error(`unsupported compression method ${J.method}`);if(K.length<=Q-1&&J.crc!==0&&k6(K)!==J.crc)throw Error("crc mismatch");return K}}function R6(J){if(!E(J))return;try{let Q=z.open(J);if(Q.exists("EncryptionInfo")||Q.exists("EncryptedPackage"))return P.encrypted()}catch{}return P.malformed("OLE compound document where an OOXML package was expected (legacy binary format?)")}function M6(J,Q){try{return Y6(J,Q)}catch($){if($ instanceof V6)return new Uint8Array(Q);throw $}}function I6(J){let Q=Math.max(0,J.length-65557);for(let $=J.length-22;$>=Q;$-=1)if(J[$]===80&&J[$+1]===75&&J[$+2]===5&&J[$+3]===6){let K=J[$+20]|J[$+21]<<8;if($+22+K===J.length)return $}return-1}function q6(J,Q){if(Q<20)return;let $=e(J),K=Q-20;if(M($,K)!==X6)return;let W=g($,K+8);if(W+56>J.length||M($,W)!==P6)return;return{entryCount:g($,W+32),cdSize:g($,W+40),cdOffset:g($,W+48)}}function O6(J,Q){let $=0,K=e(J);while($+4<=J.length){let W=R(K,$),Z=R(K,$+2),G=$+4;if(G+Z>J.length)break;if(W===1){let H=G,{uncompressedSize:U,compressedSize:D,headerOffset:V}=Q;if(U===4294967295&&H+8<=G+Z)U=g(K,H),H+=8;if(D===4294967295&&H+8<=G+Z)D=g(K,H),H+=8;if(V===4294967295&&H+8<=G+Z)V=g(K,H);return{uncompressedSize:U,compressedSize:D,headerOffset:V}}$=G+Z}return Q}function N6(J,Q){if(Q)return new TextDecoder("utf-8",{fatal:!1}).decode(J);return U6(J,"cp437")}function C1(J){let Q=0;while(Q<J.length&&J.charCodeAt(Q)===47)Q+=1;return J.slice(Q)}function e(J){return new DataView(J.buffer,J.byteOffset,J.byteLength)}function R(J,Q){return J.getUint16(Q,!0)}function M(J,Q){return J.getUint32(Q,!0)}function g(J,Q){let $=J.getUint32(Q,!0),K=J.getUint32(Q+4,!0);if(K>2097151)return Number.POSITIVE_INFINITY;return K*4294967296+$}var w6=_6();function _6(){let J=new Uint32Array(256);for(let Q=0;Q<256;Q+=1){let $=Q;for(let K=0;K<8;K+=1)$=$&1?3988292384^$>>>1:$>>>1;J[Q]=$>>>0}return J}function A6(J){let Q=4294967295;for(let $=0;$<J.length;$+=1)Q=w6[(Q^J[$])&255]^Q>>>8;return(Q^4294967295)>>>0}function k6(J){return A6(J)}import{ConvertError as x1}from"@mdgate/core";function z6(J,Q){if(!Number.isSafeInteger(Q)||Q<0||Q+2>J.length)return;return J[Q]|J[Q+1]<<8}function g6(J,Q){if(!Number.isSafeInteger(Q)||Q<0||Q+4>J.length)return;return(J[Q]|J[Q+1]<<8|J[Q+2]<<16|J[Q+3]<<24)>>>0}function T6(J,Q){try{return J.readStream(Q)}catch($){if($ instanceof x1)throw $;let K=$ instanceof Error?$.message:String($);throw x1.malformedPart(Q,`unreadable stream: ${K}`)}}import{trim as u1}from"@mdgate/utils";import{ConvertError as h1}from"@mdgate/core";function b(J,Q){let $,K=Q.indexOf("#");if(K>=0)$=Y1(Q.slice(K+1)),Q=Q.slice(0,K);let W=Q.indexOf("?");if(W>=0)Q=Q.slice(0,W);if(Q.length===0)return{path:J,fragment:$};let Z=[];if(!Q.startsWith("/")){let G=J.lastIndexOf("/");if(G>=0){for(let H of J.slice(0,G).split("/"))if(H.length>0)Z.push(H)}}for(let G of Q.split("/")){if(G.length===0||G===".")continue;if(G===".."){Z.pop();continue}let H=Y1(G);if(H.includes("/")||H.includes("\\"))throw h1.malformed(`percent-encoded separator in package reference segment ${E1(G)}`);if(H==="."||H==="..")throw h1.malformed(`percent-encoded traversal in package reference segment ${E1(G)}`);Z.push(H)}return{path:Z.join("/"),fragment:$}}function C6(J){return Y1(J)}var x6=new TextEncoder;function Y1(J){let Q=x6.encode(J),$=[],K=0;while(K<Q.length){if(Q[K]===37&&K+2<Q.length){let W=Q[K+1],Z=Q[K+2];if(S1(W)&&S1(Z)){$.push(v1(W)<<4|v1(Z)),K+=3;continue}}$.push(Q[K]),K+=1}return new TextDecoder("utf-8",{fatal:!1}).decode(Uint8Array.from($))}function S1(J){return J>=48&&J<=57||J>=65&&J<=70||J>=97&&J<=102}function v1(J){if(J>=48&&J<=57)return J-48;if(J>=65&&J<=70)return J-55;return J-87}function E1(J){return JSON.stringify(J)}import{warn as p1}from"@mdgate/utils";var j1={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 J1{map;constructor(J=new Map){this.map=J}get(J){return this.map.get(J)}internalTarget(J){let Q=this.map.get(J);return Q!==void 0&&Q.mode==="internal"?Q.target:void 0}entries(){return this.map.entries()}firstOfType(J){let Q,$;for(let[K,W]of this.map)if(W.relType===J&&W.mode==="internal"){if(Q===void 0||K<Q)Q=K,$=W}return $}}function B1(J,Q){let $=J.optionalXmlPart(Q);if($===void 0)return new J1;let K=new Map;for(let W of $.descendants(A.PKG_RELS,"Relationship")){let Z=W.attrAny("Id"),G=W.attrAny("Target");if(Z===void 0||G===void 0)continue;let H=W.attrAny("TargetMode"),U=H!==void 0&&H.toLowerCase()==="external"?"external":"internal",D=W.attrAny("Type")??"",V=u(D)??D;K.set(Z,{target:G,relType:V,mode:U})}return new J1(K)}function h6(J,Q,$,K){let W=Q.get(K);if(W===void 0||W.mode!=="internal")return;let Z;try{Z=b($,W.target)}catch(H){p1(`skipping unresolvable relationship target ${JSON.stringify(W.target)}: ${H instanceof Error?H.message:String(H)}`);return}let G=J.optionalPart(Z.path);if(G===void 0){p1(`relationship target ${Z.path} is missing`);return}return[Z.path,G]}function S6(J){let Q=J.lastIndexOf("/");if(Q>=0)return`${J.slice(0,Q)}/_rels/${J.slice(Q+1)}.rels`;return`_rels/${J}.rels`}var l1="http://schemas.openxmlformats.org/package/2006/content-types",P1="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",v6="http://schemas.openxmlformats.org/spreadsheetml/2006/main";function E6(J){if(J.length<4||J[0]!==80||J[1]!==75||J[2]!==3||J[3]!==4)return;try{return u6(J)}catch{return}}function p6(J){if(!E(J))return;let Q;try{Q=z.open(J)}catch{return}try{for(let $ of Q.readRootStorage()){let K=$.name;if(x(K,"WordDocument"))return"doc";if(x(K,"PowerPoint Document"))return"ppt";if(x(K,"Workbook")||x(K,"Book"))return"xls"}}catch{return}return}function u6(J){let Q;try{Q=l.open(J)}catch{return}let $=b6(Q,"mimetype");if($!==void 0){let W=c6($);if(W===void 0)return;return b1(u1(W))}try{let Z=B1(Q,"_rels/.rels").firstOfType(j1.OFFICE_DOCUMENT);if(Z!==void 0){let G;try{G=b("",Z.target)}catch{G=void 0}if(G!==void 0){let H=X1(Q,"[Content_Types].xml");if(H!==void 0){let D=y6(H,G.path);if(D!==void 0){let V=f6(D);if(V!==void 0)return V}}let U=X1(Q,G.path);if(U!==void 0){let D=U.childElems()[0],V=D!==void 0?d6(D):void 0;if(V!==void 0)return V}return m6(G.path)}}}catch{}for(let[W,Z]of[["word/document.xml","docx"],["ppt/presentation.xml","pptx"],["xl/workbook.xml","xlsx"],["xl/workbook.bin","xlsx"]])if(Q.hasPart(W))return Z;try{let W=X1(Q,"META-INF/manifest.xml");if(W!==void 0){for(let Z of W.descendants(P1,"file-entry"))if(Z.attr(P1,"full-path")==="/"){let G=Z.attr(P1,"media-type");if(G!==void 0)return b1(u1(G))}}}catch{}if(Q.hasPart("META-INF/container.xml"))return"epub";let K=l6(Q);if(K!==void 0)return K;return}function l6(J){let Q=J.partNames();if(Q.length===0)return;let $=!1,K=!1,W=!1,Z=!1,G=!1;for(let H of Q){let U=H.toLowerCase();if(U.includes("encrypted")||U.endsWith(".iwae"))return;if(U.endsWith(".iwa")){if($=!0,U.endsWith("/document.iwa")||U==="document.iwa")W=!0;if(U.includes("slide")||U.includes("masterslide"))Z=!0;if(U.includes("calculationengine")||U.includes("tables/"))G=!0}if(U==="index.zip")K=!0}if(!$&&!K)return;if(!$&&K)return;if(!W&&!K&&!Z&&!G)return;if(Z&&!G)return"keynote";if(G&&!Z)return"numbers";if(W)return"pages";return}function b6(J,Q){try{return J.optionalPart(Q)}catch{return}}function X1(J,Q){try{return J.optionalXmlPart(Q)}catch{return}}function b1(J){switch(J.endsWith("-template")?J.slice(0,-9):J){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";default:return}}function y6(J,Q){let $=`/${Q}`;for(let Z of J.descendants(l1,"Override")){let G=Z.attrAny("PartName");if(G!==void 0&&x(G,$)){let H=Z.attrAny("ContentType");if(H!==void 0)return H}}let K=Q.lastIndexOf(".");if(K<0)return;let W=Q.slice(K+1);for(let Z of J.descendants(l1,"Default")){let G=Z.attrAny("Extension");if(G!==void 0&&x(G,W))return Z.attrAny("ContentType")}return}function f6(J){let Q=J.toLowerCase();if(Q.includes("wordprocessingml"))return"docx";if(Q.includes("presentationml"))return"pptx";if(Q.includes("spreadsheetml")||Q.includes("ms-excel"))return"xlsx";return}function d6(J){switch(J.ns){case A.W:return"docx";case A.P:return"pptx";case v6:return"xlsx";default:return}}function m6(J){if(J.startsWith("word/"))return"docx";if(J.startsWith("ppt/"))return"pptx";if(J.startsWith("xl/"))return"xlsx";return}function x(J,Q){return J.length===Q.length&&J.toLowerCase()===Q.toLowerCase()}function c6(J){try{return new TextDecoder("utf-8",{fatal:!0}).decode(J)}catch{return}}export{b as resolve,S6 as relsPartFor,j1 as relType,h6 as relTargetBytes,B1 as readRels,T6 as readOleStream,R6 as probeOle,t as parseXml,A as ns,u as normalizeOoxmlUri,E as hasOleMagic,g6 as getU32,z6 as getU16,E6 as detectZipDoc,p6 as detectOleDoc,C6 as decodeFragment,J1 as Relationships,l as Package,o1 as OLE_MAGIC_BYTES,i as MAX_XML_NODES,c as MAX_XML_DEPTH,$1 as MAX_TOTAL_BYTES,y1 as MAX_RECORD_DEPTH,f1 as MAX_RECORDS,m as MAX_ENTRY_COUNT,L as MAX_ENTRY_BYTES,r as Element,z as CompoundFile};
1
+ import{ConvertError as P}from"@mdgate/core";import{decode as n0,InflateLimitError as i0,inflateRaw as r0,warn as o6}from"@mdgate/utils";import{ConvertError as _}from"@mdgate/core";var B=134217728,Y6=536870912,n=1e5,i=256,r=2000000,A0=64,k0=16000000;var j6=[208,207,17,224,161,177,26,225],s=4294967295,v6=4294967294,_0=4294967293,w0=4294967292,g0=4294967295,M=4294967290,x6=0;var S6=2,T0=5;class C{bytes;sectorSize;miniSectorSize;miniCutoff;fat;miniFat;entries;miniStream;constructor($,J,Q,K,W,Z,G){this.bytes=$,this.sectorSize=J,this.miniSectorSize=Q,this.miniCutoff=K,this.fat=W,this.miniFat=Z,this.entries=G}static open($){if($.length<512||!h6($,j6))throw _.malformed("not an OLE2 compound file");let J=new DataView($.buffer,$.byteOffset,$.byteLength);if(J.getUint16(28,!0)!==65534)throw _.malformed("not an OLE2 compound file: bad byte order");let K=J.getUint16(30,!0);if(K!==9&&K!==12)throw _.malformed("not an OLE2 compound file: bad sector shift");let W=1<<K,Z=J.getUint16(32,!0),G=Z===0?64:1<<Z,U=J.getUint16(26,!0),D=J.getUint32(44,!0),V=J.getUint32(48,!0),H=J.getUint32(56,!0)||4096,Y=J.getUint32(60,!0),X=J.getUint32(64,!0),g=J.getUint32(68,!0),T=J.getUint32(72,!0),L=[];for(let F=0;F<109;F+=1){let q=J.getUint32(76+F*4,!0);if(q<=M)L.push(q)}let k=g,S=new Set;for(let F=0;F<T&&k<=M;F+=1){if(S.has(k))break;S.add(k);let q=F6(k,W),z=W/4;if(q+W>$.length)break;let o=new DataView($.buffer,$.byteOffset+q,W);for(let u=0;u<z-1;u+=1){let v=o.getUint32(u*4,!0);if(v<=M)L.push(v)}k=o.getUint32((z-1)*4,!0)}if(L.length<D);let j=[],H6=Math.min(L.length,D||L.length,1e6);for(let F=0;F<H6;F+=1){let q=L[F],z=F6(q,W);if(z+W>$.length)break;let o=new DataView($.buffer,$.byteOffset+z,W),u=W/4;for(let v=0;v<u;v+=1)j.push(o.getUint32(v*4,!0))}let R=Math.max(0,Math.floor(($.length+W-1)/W)-1);while(j.length>R){let F=j[j.length-1];if(F===0||F===w0||F===_0||F===s)j.pop();else break}while(j.length>R&&j[j.length-1]===s)j.pop();if(j.length>R)throw _.malformed(`not an OLE2 compound file: Malformed FAT (FAT has ${j.length} entries, but file has only ${R} sectors)`);while(j.length<R)j.push(s);let d=[];if(X>0&&Y<=M){let F=a($,j,W,Y,X*W),q=new DataView(F.buffer,F.byteOffset,F.byteLength);for(let z=0;z+4<=F.length;z+=4)d.push(q.getUint32(z,!0))}let y=a($,j,W,V,B),E=[];for(let F=0;F+128<=y.length;F+=128)if(E.push(S0(y,F,U)),E.length>1e5)break;if(E.length===0||E[0].type!==T0)throw _.malformed("not an OLE2 compound file: missing root storage");return new C($,W,G,H,j,d,E)}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!==S6)throw _.missingPart($);if(J.size>B)throw _.resourceLimit("max_entry_bytes",`${$} stream exceeds the read cap`);let Q=this.readEntryBytes(J,B+1);if(Q.length>B)throw _.resourceLimit("max_entry_bytes",`${$} stream exceeds the read cap`);return Q}lookup($){let J=$.split("/").filter((W)=>W.length>0);if(J.length===0)return this.entries[0];let Q=this.entries[0]?.child??g0,K;for(let W of J){if(K=this.findChild(Q,W),K===void 0)return;Q=K.child}return K}findChild($,J){let Q=new Set,K=[$];while(K.length>0){let W=K.pop();if(W>M||Q.has(W))continue;Q.add(W);let Z=this.entries[W];if(Z===void 0||Z.type===x6)continue;if(x0(Z.name,J))return Z;K.push(Z.left,Z.right)}return}walkSiblings($,J){let Q=new Set,K=(W)=>{if(W>M||Q.has(W)||Q.size>1e5)return;Q.add(W);let Z=this.entries[W];if(Z===void 0||Z.type===x6)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===S6)return this.readMiniChain($.start,Q);return a(this.bytes,this.fat,this.sectorSize,$.start,Q)}readMiniChain($,J){if(this.miniStream===void 0){let G=this.entries[0];this.miniStream=a(this.bytes,this.fat,this.sectorSize,G.start,G.size)}let Q=new Uint8Array(J),K=0,W=$,Z=new Set;while(K<J&&W<=M){if(Z.has(W))break;Z.add(W);let G=W*this.miniSectorSize,U=Math.min(this.miniSectorSize,J-K);if(G+U>this.miniStream.length)break;Q.set(this.miniStream.subarray(G,G+U),K),K+=U,W=this.miniFat[W]??v6}return K===J?Q:Q.subarray(0,K)}}var C0=j6;function f($){return h6($,j6)}function h6($,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 x0($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function F6($,J){return($+1)*J}function a($,J,Q,K,W){if(K>M||W<=0)return new Uint8Array(0);let Z=[],G=0,U=K,D=new Set;while(G<W&&U<=M){if(D.has(U)||D.size>1e6)break;D.add(U);let V=F6(U,Q);if(V>=$.length)break;let H=Math.min(Q,W-G,$.length-V);if(H<=0)break;if(Z.push($.subarray(V,V+H)),G+=H,U=J[U]??v6,U===s)break}return v0(Z,G)}function S0($,J,Q){let K=new DataView($.buffer,$.byteOffset+J,128),W=K.getUint16(64,!0),Z=Math.max(0,Math.min(64,W>0?W-2:0)),G=new TextDecoder("utf-16le").decode($.subarray(J,J+Z)),U=$[J+66]??0,D=K.getUint32(68,!0),V=K.getUint32(72,!0),H=K.getUint32(76,!0),Y=K.getUint32(116,!0),X=Number(K.getBigUint64(120,!0));if(Q===3)X=K.getUint32(120,!0);if(!Number.isFinite(X)||X<0)X=0;return{name:G,type:U,left:D,right:V,child:H,start:Y,size:X}}function v0($,J){if($.length===1&&$[0].length===J)return $[0];let Q=new Uint8Array(J),K=0;for(let W of $)Q.set(W,K),K+=W.length;return Q}import{ConvertError as B6}from"@mdgate/core";import{debug as E6,decode as h0,encodingExists as E0,warn as u0}from"@mdgate/utils";var w={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"},f0=w.XML,p0="http://www.w3.org/2000/xmlns/",p6=[];class $6{ns;local;attrs;children;_elems;constructor($,J,Q=p6,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 W=Q[K];if(W.local===J&&W.ns===$)return W.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 W=Q[K];if(W.type==="elem"&&W.elem.local===J&&W.elem.ns===$)return W.elem}return}findAll($,J){let Q=[],K=this.children;for(let W=0;W<K.length;W+=1){let Z=K[W];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);y0($,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 l6{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 f0;if($==="xmlns")return p0;return this.prefixes[this.prefixes.length-1].get($)}resolveElement($){let J=$.indexOf(":");if(J>=0){let K=$.slice(0,J),W=$.slice(J+1),Z=this.lookupPrefix(K);return{ns:Z,local:W,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 l($){let J=o0($,"http://purl.oclc.org/ooxml/");if(J===void 0)return;let Q=J.indexOf("/");if(Q<0)return;let K=J.slice(0,Q),W=J.slice(Q+1);return`http://schemas.openxmlformats.org/${K}/2006/${W}`}var m6=0,c6=1,b6=2,p=3,L6=4,d6=5;function J6($){let J=m0($),Q=new y6(J),K=new l6,W=new Map,Z=new Map,G=new $6(void 0,""),U=[],D=0,V=!1;for(;;){let H;try{H=Q.next()}catch(Y){let X=Y instanceof Error?Y.message:String(Y);throw B6.malformed(`unparseable xml: ${X}`)}switch(H){case c6:{if(!Q.empty&&U.length>=i)throw B6.resourceLimit("max_xml_depth",`element nesting exceeds ${i}`);t(D),D+=1,K.push(),K.applyDecls(Q.attrs);let Y=l0(Q.name,Q.attrs,K,W,Z);if(Q.empty)P6(U,G,{type:"elem",elem:Y}),K.pop();else U.push(Y);break}case b6:{let Y=U.pop();if(Y===void 0)V=!0;else{if(Y.local!==Q.local)V=!0;P6(U,G,{type:"elem",elem:Y}),K.pop()}break}case p:{if(Q.text.length>0)t(D),D+=1,X6(U,G,Q.text);break}case L6:{let Y=O6(Q.name)??`&${Q.name};`;t(D),D+=1,X6(U,G,Y);break}case d6:{t(D),D+=1,X6(U,G,Q.text);break}case m6:if(U.length>0){V=!0;while(U.length>0)P6(U,G,{type:"elem",elem:U.pop()})}if(V)u0("recovered malformed xml (unclosed or mismatched elements)");return G}}}function t($){if($+1>r)throw B6.resourceLimit("max_xml_nodes",`part exceeds ${r} xml nodes`)}function P6($,J,Q){let K=$[$.length-1];if(K!==void 0)K.children.push(Q);else J.children.push(Q)}function X6($,J,Q){let K=$[$.length-1]?.children??J.children,W=K[K.length-1];if(W?.type==="text")W.text+=Q;else K.push({type:"text",text:Q})}function u6($,J){let Q=$.get(J);if(Q!==void 0)return Q;let K=l(J)??J;return $.set(J,K),K}function f6($,J){let Q=$.get(J);if(Q!==void 0)return Q;return $.set(J,J),J}function l0($,J,Q,K,W){let Z=Q.resolveElement($),G=Z.ns!==void 0?u6(K,Z.ns):void 0,U=p6,D=!1;for(let V of J){if(V.rawName==="xmlns"||V.rawName.startsWith("xmlns:"))continue;let H=Q.resolveAttribute(V.rawName);if(!D)U=[],D=!0;U.push({ns:H.ns!==void 0?u6(K,H.ns):void 0,local:f6(W,H.local),value:V.value})}if(Z.local==="Choice"&&G===w.MC){let V=U.find((H)=>H.local==="Requires");if(V!==void 0)V.value=V.value.split(/\s+/).filter((H)=>H.length>0).map((H)=>{let Y=Q.resolveElement(`${H}:x`);if(Y.bound&&Y.ns!==void 0)return l(Y.ns)??Y.ns;return H}).join(" ")}return new $6(G,f6(W,Z.local),U)}function m0($){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=b0(Q);if(K!==void 0&&K!=="utf8"&&K!=="utf-8")return h0($,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 W=K[0];if(W!=='"'&&W!=="'")return;K=K.slice(1);let Z=K.indexOf(W);if(Z<0)return;return K.slice(0,Z)}function b0($){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 E0(K)?K:void 0}function O6($){if($.startsWith("#")){let Q=$.slice(1),K=Q.startsWith("x")||Q.startsWith("X"),W=K?Q.slice(1):Q,Z=Number.parseInt(W,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 y6{s;i=0;name="";local="";text="";empty=!1;attrs=[];constructor($){this.s=$}next(){if(this.i>=this.s.length)return m6;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,d6}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=d0($),b6}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 c6}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),p;let Q=this.readReference();if(Q.type==="general")return this.name=Q.name,L6;return this.i=$,this.textRunSlow()}this.i+=1}return this.text=this.s.slice($,this.i),p}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=$,p;return this.name=K.name,L6}$+=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=$,p}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:O6(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]!=="="){E6(`dropping undecodable attribute: ${Q}`);continue}this.i+=1,this.skipWs();let K=this.readAttrValue();if(K===void 0){E6(`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 W=this.s.charCodeAt(this.i);if(W===$){let Z=this.s.slice(J,this.i);return this.i+=1,Q?e(Z):Z}if(W===38)return this.i=J,this.readAttrValueSlow($);if(W===9||W===10||W===13)Q=!0;this.i+=1}let K=this.s.slice(J,this.i);return Q?e(K):K}readAttrValueSlow($){let J="";while(this.i<this.s.length){let Q=this.s.charCodeAt(this.i);if(Q===$)return this.i+=1,e(J);if(Q===38){let W=this.readReference();if(W.type==="char")J+=W.text;else J+=O6(W.name)??`&${W.name};`;continue}let K=this.i;this.i+=1;while(this.i<this.s.length){let W=this.s.charCodeAt(this.i);if(W===$||W===38)break;this.i+=1}J+=this.s.slice(K,this.i)}return e(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 d0($){let J=$.indexOf(":");return J<0?$:$.slice(J+1)}function e($){if($.indexOf("\t")<0&&$.indexOf(`
2
+ `)<0&&$.indexOf("\r")<0)return $;return $.replace(/[\t\n\r]/g," ")}function y0($,J){let Q=J,K=$.length-1;while(Q<K){let W=$[Q];$[Q]=$[K],$[K]=W,Q+=1,K-=1}}function o0($,J){return $.startsWith(J)?$.slice(J.length):void 0}var a0=67324752,s0=33639248;var t0=101075792,e0=117853008,$$=0,J$=8;class N6{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=W$($);if(J<0)throw P.malformed("not a readable zip archive: invalid Zip archive: Could not find EOCD");let Q=Q6($),K=O(Q,J+10),W=N(Q,J+12),Z=N(Q,J+16);if(K===65535||W===4294967295||Z===4294967295){let V=Z$($,J);if(V!==void 0)K=V.entryCount,W=V.cdSize,Z=V.cdOffset}if(K>n);if(Z+W>$.length)throw P.malformed("not a readable zip archive: truncated central directory");let G=[],U=Z,D=Math.min($.length,Z+W);while(U+46<=D&&G.length<K){if(N(Q,U)!==s0)throw P.malformed("not a readable zip archive: bad central directory");let V=O(Q,U+8),H=O(Q,U+10),Y=N(Q,U+16),X=N(Q,U+20),g=N(Q,U+24),T=O(Q,U+28),L=O(Q,U+30),k=O(Q,U+32),S=N(Q,U+42),j=$.subarray(U+46,U+46+T);if(U+46+T+L+k>$.length)throw P.malformed("not a readable zip archive: truncated entry");let H6=$.subarray(U+46+T,U+46+T+L),R=G$(H6,{uncompressedSize:g,compressedSize:X,headerOffset:S});g=R.uncompressedSize,X=R.compressedSize,S=R.headerOffset;let d=(V&2048)!==0,y=U$(j,d);G.push({name:y,method:H,flags:V,crc:Y,compressedSize:X,uncompressedSize:g,headerOffset:S}),U+=46+T+L+k}return new N6($,G)}indexForName($){return this.byName.get($)}partNames(){return[...this.byName.keys()]}readCompressed($){let J=Q6(this.bytes),Q=$.headerOffset;if(Q+30>this.bytes.length||N(J,Q)!==a0)throw Error("bad local file header");let K=O(J,Q+26),W=O(J,Q+28),Z=Q+30+K+W,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 m{zip;totalRead=0;cache=new Map;constructor($){this.zip=$}static open($){let J;try{J=N6.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}`)}if(J.length>n)throw P.resourceLimit("max_entry_count",`archive contains ${J.length} entries`);return new m(J)}part($){$=n6($);let J=this.cache.get($);if(J!==void 0)return J;let Q=this.zip.indexForName($);if(Q===void 0)return;if(Q.uncompressedSize>B)throw P.resourceLimit("max_entry_bytes",`${$} declares ${Q.uncompressedSize} decompressed bytes`);let K=Math.max(0,Y6-this.totalRead),W=Math.min(B,K),Z;try{Z=this.decompress(Q,W+1)}catch(G){if(G instanceof P)throw G;let U=G instanceof Error?G.message:String(G);throw P.malformedPart($,`corrupt archive entry: ${U}`)}if(Z.length>W){if(K<B)throw P.resourceLimit("max_total_bytes",`${$} exceeds the archive's remaining decompression budget`);throw P.resourceLimit("max_entry_bytes",`${$} exceeds the decompression cap`)}return this.totalRead+=Z.length,this.cache.set($,Z),Z}hasPart($){return this.zip.indexForName(n6($))!==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;o6(`skipping unreadable part ${$}: ${J instanceof Error?J.message:String(J)}`);return}}optionalXmlPart($){let J=this.optionalPart($);if(J===void 0)return;try{return J6(J)}catch(Q){if(Q instanceof P&&Q.isFatal())throw Q;o6(`skipping corrupt part ${$}: ${Q instanceof Error?Q.message:String(Q)}`);return}}requiredXmlPart($){return J6(this.requiredPart($))}decompress($,J){if(($.flags&1)!==0)throw Error("encrypted zip entry");let Q;try{Q=this.zip.readCompressed($)}catch(W){let Z=W instanceof Error?W.message:String(W);throw P.malformedPart($.name,`unreadable archive entry: ${Z}`)}let K;if($.method===$$){let W=$.uncompressedSize>0?$.uncompressedSize:Q.length;K=Q.subarray(0,Math.min(W,J,Q.length))}else if($.method===J$)K=K$(Q,J);else throw Error(`unsupported compression method ${$.method}`);if(K.length<=J-1&&$.crc!==0&&Y$(K)!==$.crc)throw Error("crc mismatch");return K}}function Q$($){if(!f($))return;try{let J=C.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 K$($,J){try{return r0($,J)}catch(Q){if(Q instanceof i0)return new Uint8Array(J);throw Q}}function W$($){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 Z$($,J){if(J<20)return;let Q=Q6($),K=J-20;if(N(Q,K)!==e0)return;let W=x(Q,K+8);if(W+56>$.length||N(Q,W)!==t0)return;return{entryCount:x(Q,W+32),cdSize:x(Q,W+40),cdOffset:x(Q,W+48)}}function G$($,J){let Q=0,K=Q6($);while(Q+4<=$.length){let W=O(K,Q),Z=O(K,Q+2),G=Q+4;if(G+Z>$.length)break;if(W===1){let U=G,{uncompressedSize:D,compressedSize:V,headerOffset:H}=J;if(D===4294967295&&U+8<=G+Z)D=x(K,U),U+=8;if(V===4294967295&&U+8<=G+Z)V=x(K,U),U+=8;if(H===4294967295&&U+8<=G+Z)H=x(K,U);return{uncompressedSize:D,compressedSize:V,headerOffset:H}}Q=G+Z}return J}function U$($,J){if(J)return new TextDecoder("utf-8",{fatal:!1}).decode($);return n0($,"cp437")}function n6($){let J=0;while(J<$.length&&$.charCodeAt(J)===47)J+=1;return $.slice(J)}function Q6($){return new DataView($.buffer,$.byteOffset,$.byteLength)}function O($,J){return $.getUint16(J,!0)}function N($,J){return $.getUint32(J,!0)}function x($,J){let Q=$.getUint32(J,!0),K=$.getUint32(J+4,!0);if(K>2097151)return Number.POSITIVE_INFINITY;return K*4294967296+Q}var D$=V$();function V$(){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 H$($){let J=4294967295;for(let Q=0;Q<$.length;Q+=1)J=D$[(J^$[Q])&255]^J>>>8;return(J^4294967295)>>>0}function Y$($){return H$($)}import{ConvertError as i6}from"@mdgate/core";function F$($,J){if(!Number.isSafeInteger(J)||J<0||J+2>$.length)return;return $[J]|$[J+1]<<8}function j$($,J){if(!Number.isSafeInteger(J)||J<0||J+4>$.length)return;return($[J]|$[J+1]<<8|$[J+2]<<16|$[J+3]<<24)>>>0}function P$($,J){try{return $.readStream(J)}catch(Q){if(Q instanceof i6)throw Q;let K=Q instanceof Error?Q.message:String(Q);throw i6.malformedPart(J,`unreadable stream: ${K}`)}}import{trim as $0}from"@mdgate/utils";import{ConvertError as r6}from"@mdgate/core";function c($,J){let Q,K=J.indexOf("#");if(K>=0)Q=I6(J.slice(K+1)),J=J.slice(0,K);let W=J.indexOf("?");if(W>=0)J=J.slice(0,W);if(J.length===0)return{path:$,fragment:Q};let Z=[];if(!J.startsWith("/")){let G=$.lastIndexOf("/");if(G>=0){for(let U of $.slice(0,G).split("/"))if(U.length>0)Z.push(U)}}for(let G of J.split("/")){if(G.length===0||G===".")continue;if(G===".."){Z.pop();continue}let U=I6(G);if(U.includes("/")||U.includes("\\"))throw r6.malformed(`percent-encoded separator in package reference segment ${t6(G)}`);if(U==="."||U==="..")throw r6.malformed(`percent-encoded traversal in package reference segment ${t6(G)}`);Z.push(U)}return{path:Z.join("/"),fragment:Q}}function X$($){return I6($)}var B$=new TextEncoder;function I6($){let J=B$.encode($),Q=[],K=0;while(K<J.length){if(J[K]===37&&K+2<J.length){let W=J[K+1],Z=J[K+2];if(a6(W)&&a6(Z)){Q.push(s6(W)<<4|s6(Z)),K+=3;continue}}Q.push(J[K]),K+=1}return new TextDecoder("utf-8",{fatal:!1}).decode(Uint8Array.from(Q))}function a6($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function s6($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}function t6($){return JSON.stringify($)}import{warn as e6}from"@mdgate/utils";var R6={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 K6{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,W]of this.map)if(W.relType===$&&W.mode==="internal"){if(J===void 0||K<J)J=K,Q=W}return Q}}function q6($,J){let Q=$.optionalXmlPart(J);if(Q===void 0)return new K6;let K=new Map;for(let W of Q.descendants(w.PKG_RELS,"Relationship")){let Z=W.attrAny("Id"),G=W.attrAny("Target");if(Z===void 0||G===void 0)continue;let U=W.attrAny("TargetMode"),D=U!==void 0&&U.toLowerCase()==="external"?"external":"internal",V=W.attrAny("Type")??"",H=l(V)??V;K.set(Z,{target:G,relType:H,mode:D})}return new K6(K)}function L$($,J,Q,K){let W=J.get(K);if(W===void 0||W.mode!=="internal")return;let Z;try{Z=c(Q,W.target)}catch(U){e6(`skipping unresolvable relationship target ${JSON.stringify(W.target)}: ${U instanceof Error?U.message:String(U)}`);return}let G=$.optionalPart(Z.path);if(G===void 0){e6(`relationship target ${Z.path} is missing`);return}return[Z.path,G]}function O$($){let J=$.lastIndexOf("/");if(J>=0)return`${$.slice(0,J)}/_rels/${$.slice(J+1)}.rels`;return`_rels/${$}.rels`}var J0="http://schemas.openxmlformats.org/package/2006/content-types",z6="urn:oasis:names:tc:opendocument:xmlns:manifest:1.0",N$="http://schemas.openxmlformats.org/spreadsheetml/2006/main";function I$($){if($.length<4||$[0]!==80||$[1]!==75||$[2]!==3||$[3]!==4)return;try{return q$($)}catch{return}}function R$($){if(!f($))return;let J;try{J=C.open($)}catch{return}try{for(let Q of J.readRootStorage()){let K=Q.name;if(I(K,"WordDocument"))return"doc";if(I(K,"PowerPoint Document"))return"ppt";if(I(K,"Workbook")||I(K,"Book"))return"xls";if(I(K,"VisioDocument"))return"vsd";if(g$(K))return"hwp";if(T$(K))return"one"}}catch{return}return}function q$($){let J;try{J=m.open($)}catch{return}let Q=M$(J,"mimetype");if(Q!==void 0){let W=C$(Q);if(W===void 0)return;return Q0($0(W))}try{let Z=q6(J,"_rels/.rels").firstOfType(R6.OFFICE_DOCUMENT);if(Z!==void 0){let G;try{G=c("",Z.target)}catch{G=void 0}if(G!==void 0){let U=M6(J,"[Content_Types].xml");if(U!==void 0){let V=A$(U,G.path);if(V!==void 0){let H=k$(V);if(H!==void 0)return H}}let D=M6(J,G.path);if(D!==void 0){let V=D.childElems()[0],H=V!==void 0?_$(V):void 0;if(H!==void 0)return H}return w$(G.path)}}}catch{}for(let[W,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(W))return Z;try{let W=M6(J,"META-INF/manifest.xml");if(W!==void 0){for(let Z of W.descendants(z6,"file-entry"))if(Z.attr(z6,"full-path")==="/"){let G=Z.attr(z6,"media-type");if(G!==void 0)return Q0($0(G))}}}catch{}if(J.hasPart("META-INF/container.xml"))return"epub";let K=z$(J);if(K!==void 0)return K;return}function z$($){let J=$.partNames();if(J.length===0)return;let Q=!1,K=!1,W=!1,Z=!1,G=!1;for(let U of J){let D=U.toLowerCase();if(D.includes("encrypted")||D.endsWith(".iwae"))return;if(D.endsWith(".iwa")){if(Q=!0,D.endsWith("/document.iwa")||D==="document.iwa")W=!0;if(D.includes("slide")||D.includes("masterslide"))Z=!0;if(D.includes("calculationengine")||D.includes("tables/"))G=!0}if(D==="index.zip")K=!0}if(!Q&&!K)return;if(!Q&&K)return;if(!W&&!K&&!Z&&!G)return;if(Z&&!G)return"keynote";if(G&&!Z)return"numbers";if(W)return"pages";return}function M$($,J){try{return $.optionalPart(J)}catch{return}}function M6($,J){try{return $.optionalXmlPart(J)}catch{return}}function Q0($){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 A$($,J){let Q=`/${J}`;for(let Z of $.descendants(J0,"Override")){let G=Z.attrAny("PartName");if(G!==void 0&&I(G,Q)){let U=Z.attrAny("ContentType");if(U!==void 0)return U}}let K=J.lastIndexOf(".");if(K<0)return;let W=J.slice(K+1);for(let Z of $.descendants(J0,"Default")){let G=Z.attrAny("Extension");if(G!==void 0&&I(G,W))return Z.attrAny("ContentType")}return}function k$($){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 _$($){switch($.ns){case w.W:return"docx";case w.P:return"pptx";case N$:return"xlsx";default:return}}function w$($){if($.startsWith("word/"))return"docx";if($.startsWith("ppt/"))return"pptx";if($.startsWith("xl/"))return"xlsx";if($.startsWith("visio/"))return"vsdx";return}function g$($){let J=$.charCodeAt(0)===5?$.slice(1):$;return I($,"FileHeader")||I(J,"HwpSummaryInformation")||I($,"HWPDocumentInfo")}function T$($){return $.length>=7&&$.slice(0,7).toLowerCase()==="onenote"}function I($,J){return $.length===J.length&&$.toLowerCase()===J.toLowerCase()}function C$($){try{return new TextDecoder("utf-8",{fatal:!0}).decode($)}catch{return}}import{ConvertError as A}from"@mdgate/core";import{asciiStartsWith as F0,decode as K0,trim as h}from"@mdgate/utils";var W0=32,W6=1e4,b=262144;function x$($){let J={parts:0};if(u$($)){let Q=f$($);if(Q.length>1||Q.length===1&&F0($,"From ")){let K=Q.map((W)=>Z6(W,1,J));return{contentType:"application/mbox",headers:[],filename:void 0,bytes:new Uint8Array(0),parts:K}}}return Z6(E$($),1,J)}function S$($){let J=[],Q=(K)=>{J.push(K);for(let W of K.parts)Q(W)};return Q($),J}function j0($){let J=L0($);if(J!==void 0){let Q=O0($,J);if(Q!==void 0&&Z0(Q)&&!k6(Q))return Q}return C6($,(Q)=>Z0(Q)&&!k6(Q))}function P0($){return C6($,(J)=>J.contentType==="text/plain"&&J.parts.length===0&&!k6(J))}function v$($){let J=j0($),Q=P0($),K=[],W=(Z)=>{if(Z.parts.length>0){for(let G of Z.parts)W(G);return}if(Z===J||Z===Q)return;if(X0(Z.contentType)||B0(Z.contentType))return;K.push(Z)};return W($),K}function V6($,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 Z6($,J,Q){h$(Q,J);let K=l$($),W=c$(K.headers),Z=_6(W,"content-type")??"text/plain",G=I0(Z),U=y$(W,G.params),D=(_6(W,"content-transfer-encoding")??"7bit").trim().toLowerCase(),V=a$(K.body,D);if(X0(G.type)){let H=G.params.get("boundary");if(H===void 0||H.length===0)return{contentType:G.type,headers:W,filename:U,bytes:V,parts:[]};let X=e$(V,H).map((g)=>Z6(g,J+1,Q));return{contentType:G.type,headers:W,filename:U,bytes:new Uint8Array(0),parts:X}}if(B0(G.type)){let H=Z6(V,J+1,Q);return{contentType:G.type,headers:W,filename:U,bytes:V,parts:[H]}}return{contentType:G.type,headers:W,filename:U,bytes:V,parts:[]}}function h$($,J){if(J>W0)throw A.resourceLimit("max_mime_depth",`part nesting exceeds ${W0}`);if($.parts+=1,$.parts>W6)throw A.resourceLimit("max_mime_parts",`message exceeds ${W6} parts`)}function X0($){return $.startsWith("multipart/")}function B0($){return $==="message/rfc822"||$==="message/global"||$==="message/news"}function Z0($){return $.contentType==="text/html"&&$.parts.length===0}function k6($){let J=V6($,"content-disposition");if(J===void 0)return!1;let Q=J.indexOf(";");return(Q<0?J:J.slice(0,Q)).trim().toLowerCase()==="attachment"}function C6($,J){if(J($))return $;for(let Q of $.parts){let K=C6(Q,J);if(K!==void 0)return K}return}function L0($){let J=V6($,"content-type");if($.contentType==="multipart/related"&&J!==void 0){let Q=I0(J).params.get("start");if(Q!==void 0&&Q.length>0)return N0(Q)}for(let Q of $.parts){let K=L0(Q);if(K!==void 0)return K}return}function O0($,J){let Q=V6($,"content-id");if(Q!==void 0&&N0(Q)===J)return $;for(let K of $.parts){let W=O0(K,J);if(W!==void 0)return W}return}function N0($){let J=h($);if(J.startsWith("<")&&J.endsWith(">")&&J.length>=2)J=J.slice(1,-1);return J}function _6($,J){let Q=J.toLowerCase();for(let K=$.length-1;K>=0;K-=1)if($[K].name===Q)return $[K].value;return}function E$($){if($.length>=3&&$[0]===239&&$[1]===187&&$[2]===191)return $.subarray(3);return $}function u$($){return F0($,"From ")}function f$($){let J=[],Q=0;while(Q<$.length){if(w6($,Q))J.push(Q);Q=G6($,Q)}if(J.length===0)return[];let K=[];for(let W=0;W<J.length;W+=1){let Z=J[W],G=G6($,Z),U=W+1<J.length?J[W+1]:$.length;if(G>U)continue;K.push(p$($.subarray(G,U)))}return K}function w6($,J){return J+5<=$.length&&$[J]===70&&$[J+1]===114&&$[J+2]===111&&$[J+3]===109&&$[J+4]===32}function p$($){let J=0,Q=0;while(Q<$.length){if($[Q]===62&&w6($,Q+1))J+=1;Q=G6($,Q)}if(J===0)return $;let K=new Uint8Array($.length-J),W=0,Z=0;while(W<$.length){if($[W]===62&&w6($,W+1))W+=1;let G=G6($,W);K.set($.subarray(W,G),Z),Z+=G-W,W=G}return K.subarray(0,Z)}function G6($,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 l$($){let J=m$($);if(J!==void 0){if(J.sep>b)throw A.resourceLimit("max_mime_headers",`header block exceeds ${b} bytes`);return{headers:$.subarray(0,J.sep),body:$.subarray(J.body)}}if($.length>b&&G0($))throw A.resourceLimit("max_mime_headers",`header block exceeds ${b} bytes`);if(G0($))return{headers:$,body:$.subarray($.length)};return{headers:$.subarray(0,0),body:$}}function m$($){let J=Math.min($.length,b+4);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 G0($){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 W=$[K];if(!(W>=65&&W<=90||W>=97&&W<=122||W>=48&&W<=57||W===45))return!1}return!0}function c$($){if($.length===0)return[];let J=b$(M0($)),Q=[],K=0;while(K<J.length){let W=J.indexOf(`
3
+ `,K);if(W<0)W=J.length;let Z=J.slice(K,W);if(Z.endsWith("\r"))Z=Z.slice(0,-1);if(K=W+1,Z.length===0)continue;let G=Z.indexOf(":");if(G<=0)continue;let U=Z.slice(0,G).trim().toLowerCase();if(U.length===0)continue;let D=o$(h(Z.slice(G+1)));Q.push({name:U,value:D})}return Q}function b$($){let J="";for(let Q=0;Q<$.length;Q+=1){let K=$[Q];if(K==="\r"&&$[Q+1]===`
4
+ `&&g6($[Q+2])){J+=" ",Q+=2;continue}if((K===`
5
+ `||K==="\r")&&g6($[Q+1])){J+=" ",Q+=1;continue}J+=K}return J}function g6($){return $===" "||$==="\t"}function I0($){let J=T6($,";"),Q=h(J<0?$:$.slice(0,J)).toLowerCase(),K=Q.length>0?Q:"application/octet-stream",W=R0(J<0?"":$.slice(J+1));return{type:K,params:W}}function R0($){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),W=T6(K,";"),Z=h(W<0?K:K.slice(0,W));Q+=W<0?K.length:W+1;let G=T6(Z,"=");if(G<=0)continue;let U=h(Z.slice(0,G)).toLowerCase();if(U.length===0)continue;J.set(U,d$(h(Z.slice(G+1))))}return J}function T6($,J){let Q=!1;for(let K=0;K<$.length;K+=1){let W=$[K];if(Q){if(W==="\\"){K+=1;continue}if(W==='"')Q=!1;continue}if(W==='"'){Q=!0;continue}if(W===J)return K}return-1}function d$($){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 y$($,J){let Q=_6($,"content-disposition");if(Q!==void 0){let K=U0(R0(Q));if(K!==void 0)return K}return U0(J)}function U0($){let J=D0($,"filename")??$.get("filename*");if(J!==void 0){let Z=V0(J);if(Z.length>0)return Z}let Q=$.get("filename");if(Q!==void 0&&Q.length>0)return Q;let K=D0($,"name")??$.get("name*");if(K!==void 0){let Z=V0(K);if(Z.length>0)return Z}let W=$.get("name");return W!==void 0&&W.length>0?W:void 0}function D0($,J){if(!$.has(`${J}*0`)&&!$.has(`${J}*0*`))return;let Q="";for(let K=0;K<64;K+=1){let W=$.get(`${J}*${K}*`);if(W!==void 0){Q+=W;continue}let Z=$.get(`${J}*${K}`);if(Z===void 0)break;Q+=Z}return Q.length>0?Q:void 0}function V0($){let J=$.indexOf("'");if(J<0)return A6($,"utf-8");let Q=$.indexOf("'",J+1);if(Q<0)return A6($,"utf-8");let K=$.slice(0,J)||"utf-8";return A6($.slice(Q+1),K)}function A6($,J){let Q=new Uint8Array($.length),K=0;for(let W=0;W<$.length;W+=1){if($[W]==="%"&&W+2<$.length&&U6($[W+1])&&U6($[W+2])){Q[K]=D6($[W+1])<<4|D6($[W+2]),K+=1,W+=2;continue}Q[K]=$.charCodeAt(W)&255,K+=1}return q0(Q.subarray(0,K),J)}function o$($){let J=/=\?([^?]+)\?([bBqQ])\?([^?]*)\?=/g,Q="",K=0,W=-1,Z;while((Z=J.exec($))!==void 0&&Z!==null){let G=Z.index,U=$.slice(K,G);if(W>=0&&n$(U));else Q+=U;Q+=i$(Z[1],Z[2],Z[3]),K=G+Z[0].length,W=K}if(K===0)return $;return Q+$.slice(K)}function n$($){for(let J=0;J<$.length;J+=1)if(!g6($[J]))return!1;return $.length>0}function i$($,J,Q){let K=J.toUpperCase(),W;if(K==="B")W=z0(new TextEncoder().encode(Q));else W=r$(Q);return q0(W,$)}function r$($){let J=new Uint8Array($.length),Q=0;for(let K=0;K<$.length;K+=1){let W=$[K];if(W==="_"){J[Q]=32,Q+=1;continue}if(W==="="&&K+2<$.length&&U6($[K+1])&&U6($[K+2])){J[Q]=D6($[K+1])<<4|D6($[K+2]),Q+=1,K+=2;continue}J[Q]=$.charCodeAt(K)&255,Q+=1}return J.subarray(0,Q)}function q0($,J){try{return K0($,J)}catch{try{return K0($,"utf-8")}catch{return M0($)}}}function a$($,J){if(J==="base64")return z0($);if(J==="quoted-printable")return s$($);return $}function s$($){if($.length>B)throw A.resourceLimit("max_entry_bytes","quoted-printable body exceeds the read cap");let J=new Uint8Array($.length),Q=0;for(let K=0;K<$.length;K+=1){let W=$[K];if(W===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&&H0(Z)&&H0(G)){J[Q]=Y0(Z)<<4|Y0(G),Q+=1,K+=2;continue}}if(W===9||W===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]=W,Q+=1}return J.subarray(0,Q)}var t$=(()=>{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 z0($){let J=Math.floor($.length/4)*3+3;if(J>B&&$.length>B)throw A.resourceLimit("max_entry_bytes","base64 body exceeds the read cap");let Q=Math.min(J,B+1),K=new Uint8Array(Q),W=0,Z=0,G=0;for(let U=0;U<$.length;U+=1){let D=$[U];if(D===61)break;if(D>=128)continue;let V=t$[D];if(V===255)continue;if(W=W<<6|V,Z+=6,Z>=8){if(Z-=8,G>=Q)throw A.resourceLimit("max_entry_bytes","base64 body exceeds the read cap");K[G]=W>>Z&255,G+=1}}if(G>B)throw A.resourceLimit("max_entry_bytes","base64 body exceeds the read cap");return K.subarray(0,G)}function e$($,J){if(J.length===0)return[];let Q=new TextEncoder().encode(`--${J}`),K=[],W=[],Z=0;while(Z+Q.length<=$.length){let U=KJ($,Q,Z);if(U<0)break;if(!$J($,U)){Z=U+1;continue}K.push(U);let D=U+Q.length;if(W.push($[D]===45&&$[D+1]===45),Z=D,K.length>W6+2)throw A.resourceLimit("max_mime_parts",`message exceeds ${W6} parts`)}let G=[];for(let U=0;U<K.length;U+=1){if(W[U])break;let D=JJ($,K[U]+Q.length),V=U+1<K.length?K[U+1]:-1;if(V<0)break;G.push($.subarray(D,QJ($,D,V)))}return G}function $J($,J){if(J===0)return!0;let Q=$[J-1];return Q===10||Q===13}function JJ($,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 QJ($,J,Q){let K=Q;if(K>J&&$[K-1]===10)K-=1;if(K>J&&$[K-1]===13)K-=1;return K}function KJ($,J,Q){if(J.length===0)return Q;let K=J[0],W=Q+($.length-J.length);for(let Z=Q;Z<=W;Z+=1){if($[Z]!==K)continue;let G=!0;for(let U=1;U<J.length;U+=1)if($[Z+U]!==J[U]){G=!1;break}if(G)return Z}return-1}function M0($){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 U6($){return $>="0"&&$<="9"||$>="a"&&$<="f"||$>="A"&&$<="F"}function D6($){if($>="0"&&$<="9")return $.charCodeAt(0)-48;if($>="a"&&$<="f")return $.charCodeAt(0)-87;return $.charCodeAt(0)-55}function H0($){return $>=48&&$<=57||$>=65&&$<=70||$>=97&&$<=102}function Y0($){if($>=48&&$<=57)return $-48;if($>=65&&$<=70)return $-55;return $-87}export{S$ as walkMimeParts,c as resolve,O$ as relsPartFor,R6 as relType,L$ as relTargetBytes,q6 as readRels,P$ as readOleStream,Q$ as probeOle,J6 as parseXml,x$ as parseMime,w as ns,l as normalizeOoxmlUri,P0 as mimeTextPlain,j0 as mimeTextHtml,V6 as mimeHeader,v$ as mimeAttachments,f as hasOleMagic,j$ as getU32,F$ as getU16,I$ as detectZipDoc,R$ as detectOleDoc,X$ as decodeFragment,K6 as Relationships,m as Package,C0 as OLE_MAGIC_BYTES,r as MAX_XML_NODES,i as MAX_XML_DEPTH,Y6 as MAX_TOTAL_BYTES,A0 as MAX_RECORD_DEPTH,k0 as MAX_RECORDS,n as MAX_ENTRY_COUNT,B as MAX_ENTRY_BYTES,$6 as Element,C as CompoundFile};
package/dist/mime.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ export interface MimeHeader {
2
+ name: string;
3
+ value: string;
4
+ }
5
+ export interface MimePart {
6
+ contentType: string;
7
+ headers: MimeHeader[];
8
+ filename: string | undefined;
9
+ bytes: Uint8Array;
10
+ parts: MimePart[];
11
+ }
12
+ /**
13
+ * Parse an RFC 822 / MIME document (`.eml`, `.mhtml`) or an mbox of such
14
+ * documents into a part tree. Transfer encodings are decoded; charset is not.
15
+ */
16
+ export declare function parseMime(bytes: Uint8Array): MimePart;
17
+ /** Preorder walk including `root`. */
18
+ export declare function walkMimeParts(root: MimePart): MimePart[];
19
+ /** First `text/html` leaf that is not an attachment (honors `start=`). */
20
+ export declare function mimeTextHtml(root: MimePart): MimePart | undefined;
21
+ /** First `text/plain` leaf that is not an attachment. */
22
+ export declare function mimeTextPlain(root: MimePart): MimePart | undefined;
23
+ /**
24
+ * Leaf parts that are not the chosen text bodies. Includes `attachment`
25
+ * disposition, related resources, and unnamed non-text leaves.
26
+ */
27
+ export declare function mimeAttachments(root: MimePart): MimePart[];
28
+ /** Last header of `name` (case-insensitive). */
29
+ export declare function mimeHeader(part: MimePart, name: string): string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/containers",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "mdgate container parsing: ZIP/OPC packages, OLE compound files, XML",
5
5
  "type": "module",
6
6
  "license": "MIT",