@mdgate/xlsx 0.4.1 → 0.5.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.
Files changed (2) hide show
  1. package/dist/index.js +1 -1
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{create as vi}from"@mdgate/core";import{detectOleDoc as Yi,detectZipDoc as ji}from"@mdgate/containers";import{documentToMarkdown as Bi}from"@mdgate/document";import{fileExtension as Mi}from"@mdgate/utils";import{CompoundFile as Li,hasOleMagic as Oi,Package as Ki,probeOle as Qi}from"@mdgate/containers";import{ConvertError as F}from"@mdgate/core";import{ConvertError as H}from"@mdgate/core";import{emptyDocument as Dn,heading as Ln,MAX_EXPANSION as On,plain as rn,resolveHeaderRows as Kn}from"@mdgate/document";import{warn as Qn}from"@mdgate/utils";import{cleanText as Vn}from"@mdgate/utils";var $={kind:"empty"};function w(n,i,e){if(i==="datetime")return{kind:"datetime",value:n,duration:!1,is1904:e};if(i==="timedelta")return{kind:"datetime",value:n,duration:!0,is1904:e};return{kind:"float",value:n}}function Z(n,i,e){if(i==="datetime")return{kind:"datetime",value:n,duration:!1,is1904:e};if(i==="timedelta")return{kind:"datetime",value:n,duration:!0,is1904:e};return{kind:"int",value:n}}var Jn={0:"Null",7:"Div0",15:"Value",23:"Ref",29:"Name",36:"Num",42:"NA",43:"GettingData"},Xn={"#NULL!":"Null","#DIV/0!":"Div0","#VALUE!":"Value","#REF!":"Ref","#NAME?":"Name","#NUM!":"Num","#N/A":"NA","#DATA!":"GettingData","#GETTING_DATA":"GettingData"};function R(n){let i=Jn[n];return i===void 0?void 0:{kind:"error",name:i}}function en(n){return{kind:"error",name:Xn[n]??n.replace(/^#/,"")}}function tn(n){switch(n.kind){case"empty":return"";case"string":return Vn(n.value);case"float":return nn(n.value);case"int":return String(n.value);case"bool":return n.value?"TRUE":"FALSE";case"error":return`#${n.name}`;case"datetime":if(n.duration)return qn(n.value);if(Math.abs(n.value)<1)return Rn(n.value);return Cn(n.value,n.is1904)??nn(n.value);case"datetimeIso":case"durationIso":return n.value}}function nn(n){if(Number.isNaN(n))return"NaN";if(n===Number.POSITIVE_INFINITY)return"inf";if(n===Number.NEGATIVE_INFINITY)return"-inf";let i=Number.parseFloat(n.toExponential(14));if(Number.isNaN(i))return String(n);return Gn(i)}function Gn(n){if(Object.is(n,-0))return"0";let i=n.toString();if(!/[eE]/.test(i))return i;let e=i.match(/^([+-]?)(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/);if(e===null)return i;let t=e[1]==="-"?"-":"",r=e[2]+(e[3]??""),s=1+Number(e[4]);if(s<=0)return`${t}0.${"0".repeat(-s)}${r}`;if(s>=r.length)return`${t}${r}${"0".repeat(s-r.length)}`;let u=r.slice(0,s),l=r.slice(s);return`${t}${u}.${l}`}function Rn(n){let i=Math.round(Math.abs(n)*86400)%86400,e=Math.floor(i/3600),t=Math.floor(i%3600/60),r=i%60;return`${P(e)}:${P(t)}:${P(r)}`}function qn(n){let i=n<0?"-":"",e=Math.round(Math.abs(n)*86400),t=Math.floor(e/3600),r=Math.floor(e%3600/60),o=e%60;return`${i}${t}:${P(r)}:${P(o)}`}var zn=1462,Tn=86400000,Zn=Date.UTC(1899,11,30);function Cn(n,i){let e=i?n+zn:n;if(e<60)e+=1;let t=Math.round(e*Tn),r=Zn+t;if(!Number.isFinite(r))return;let o=new Date(r);if(Number.isNaN(o.getTime()))return;let s=o.getUTCFullYear();if(s<0||s>9999)return;let u=`${s}-${P(o.getUTCMonth()+1)}-${P(o.getUTCDate())} ${P(o.getUTCHours())}:${P(o.getUTCMinutes())}:${P(o.getUTCSeconds())}`;return u.endsWith(" 00:00:00")?u.slice(0,-9):u}function P(n){return n<10?`0${n}`:String(n)}function S(n){if(n.length===0)return;let i=Number.POSITIVE_INFINITY,e=0,t=Number.POSITIVE_INFINITY,r=0;for(let l of n){if(l.row<i)i=l.row;if(l.row>e)e=l.row;if(l.col<t)t=l.col;if(l.col>r)r=l.col}let o=r-t+1,s=e-i+1,u=Array(o*s).fill($);for(let l of n){let y=(l.row-i)*o+(l.col-t);if(y>=0&&y<u.length)u[y]=l.value}return{start:[i,t],height:s,width:o,values:u}}function un(n){let i=Dn(),e=n.length>1,t=0,r=0;for(let o of n){if(r+=1,o.height===0||o.width===0||o.values.length===0)continue;try{let s=bn(o);if(s===void 0)continue;if(e)i.blocks.push(Ln(2,[rn(o.name)]));i.blocks.push({type:"table",table:s})}catch(s){if(s instanceof H&&s.isFatal())throw s;Qn(`skipping unreadable sheet ${JSON.stringify(o.name)}: ${s instanceof Error?s.message:String(s)}`),t+=1}}if(r>0&&t===r&&i.blocks.length===0)throw H.malformed("no sheet in the workbook could be read");return i}function bn(n){let{start:i,height:e,width:t,values:r,merges:o}=n,s=o.length>0?new Map:void 0,u=o.length>0?new Map:void 0;if(s!==void 0&&u!==void 0){let c=0n;for(let x of o){let h=Math.max(x.start[0],i[0]),f=Math.max(x.start[1],i[1]),k=Math.min(x.end[0]+1,i[0]+e),A=Math.min(x.end[1]+1,i[1]+t);if(h>=k||f>=A)continue;let g=h-i[0],m=f-i[1],I=k-i[0],W=A-i[1];if(I-g===1&&W-m===1)continue;let _=W-m,a=I-g;if(c+=BigInt(_)*BigInt(a)-1n,c>BigInt(On))throw H.resourceLimit("max_expansion","table span expansion exceeds the content budget");s.set(C(g,m),[_,a]);for(let z=g;z<I;z+=1)for(let T=m;T<W;T+=1)if(z!==g||T!==m)u.set(C(z,T),[g,m])}}let l=Array(e);for(let c=0;c<e;c+=1){let x=Array(t),h=c*t;for(let f=0;f<t;f+=1){let k=u?.get(C(c,f));if(k!==void 0){x[f]={type:"covered",originRow:k[0],originCol:k[1]};continue}let A=r[h+f]??$,g=A.kind==="empty"?"":tn(A),m=s?.get(C(c,f));x[f]={type:"origin",cell:{blocks:g.length===0?[]:[{type:"paragraph",inlines:[rn(g)]}],colSpan:m?.[0]??1,rowSpan:m?.[1]??1}}}l[c]=x}while(l.length>0){if(!l[l.length-1].every((h)=>h.type!=="origin"||h.cell.blocks.length===0))break;l.pop()}if(l.length===0)return;let y={grid:l,headerRows:0,kind:"data"};return y.headerRows=Kn(y,0),y}function C(n,i){return n*65536+i}import{MAX_RECORDS as sn,readOleStream as Hn}from"@mdgate/containers";import{ConvertError as J}from"@mdgate/core";import{decode as Yn,encodingExists as jn,warn as Y}from"@mdgate/utils";function V(n){let i=!1,e=!1,t=0,r=" ",o=!1,s=!1;for(let u of n){if(i)i=!1;else if(u==="_"||u==="\\"||u==="*")i=!0;else if(u==='"'&&e)e=!1;else if(e);else if(u==='"')e=!0;else if(u===";")return"other";else if(u==="[")t+=1;else if(u==="]"&&t===1&&o)return"timedelta";else if(u==="]")t=Math.max(0,t-1);else if((u==="a"||u==="A")&&!s&&t===0)s=!0;else if((u==="p"||u==="m"||u==="/"||u==="P"||u==="M")&&s&&t===0)return"datetime";else if(!s&&t===0&&(u==="d"||u==="m"||u==="h"||u==="y"||u==="s"||u==="D"||u==="M"||u==="H"||u==="Y"||u==="S"))return"datetime";else if(o&&u.toLowerCase()===r.toLowerCase());else o=r==="["&&(u==="m"||u==="h"||u==="s"||u==="M"||u==="H"||u==="S");r=u}return"other"}function on(n){switch(n){case"14":case"15":case"16":case"17":case"18":case"19":case"20":case"21":case"22":case"45":case"47":return"datetime";case"46":return"timedelta";default:return"other"}}function D(n){if(n>=14&&n<=22||n===45||n===47)return"datetime";if(n===46)return"timedelta";return"other"}var hn=new TextDecoder("latin1"),Bn=new TextDecoder("utf-8"),Mn=new TextDecoder("utf-16le"),En=new TextDecoder("utf-16be"),X=new DataView(new ArrayBuffer(8));function xn(n){let i=vn(n),e=8,t=ln(1200),r=!1,o=[],s=[],u=new Map,l=[];yn(i,(h,f,k)=>{switch(h){case 47:if(p(f,0)!==0)throw J.encrypted();break;case 66:t=ln(p(f,0));break;case 34:if(p(f,0)===1)r=!0;break;case 1054:{let A=li(f,t,e);if(A!==void 0)u.set(A.ifmt,A.format);break}case 224:if(f.length>=4)l.push(p(f,2));break;case 133:{let A=si(k??new L(h,f,[]),t,e);if(A!==void 0)o.push(A);break}case 2057:{let A=oi(f);if(A!==void 0)e=A;break}case 252:s.push(...fi(k??new L(h,f,[]),t));break;default:break}if(h===10&&o.length>0)return"count";return});let y=l.map((h)=>u.get(h)??D(h)),c=[],x=0;for(let h of o){if(h.pos>=i.length){Y(`skipping unreadable sheet ${JSON.stringify(h.name)}: bound offset past end of stream`),x+=1;continue}try{let f=dn(i.subarray(h.pos),h.name,t,e,s,y,r);if(f!==void 0)c.push(f)}catch(f){if(f instanceof J&&f.isFatal())throw f;if(f instanceof J&&f.code==="encrypted")throw f;Y(`skipping unreadable sheet ${JSON.stringify(h.name)}: ${f instanceof Error?f.message:String(f)}`),x+=1}}if(o.length>0&&x===o.length)throw J.malformed("no sheet in the workbook could be read");return c}function vn(n){for(let i of["Workbook","Book","WORKBOOK","BOOK"])if(n.exists(i))return Hn(n,i);throw J.malformed("unreadable workbook: Cannot find Workbook stream")}function dn(n,i,e,t,r,o,s){let u=[],l=[],y;yn(n,(x,h)=>{switch(x){case 515:{let f=_n(h,o,s);if(f!==void 0)u.push(f);break}case 516:case 214:{let f=ti(h,e,t);if(f!==void 0)u.push(f);break}case 517:{let f=an(h);if(f!==void 0)u.push(f);break}case 519:{if(y!==void 0){let f=j(h,e,t);if(f!==void 0)u.push({row:y[0],col:y[1],value:{kind:"string",value:f}})}break}case 638:{let f=ni(h,o,s);if(f!==void 0)u.push(f);break}case 253:{let f=ri(h,r);if(f!==void 0)u.push(f);break}case 189:ii(h,u,o,s);break;case 229:ei(h,l);break;case 6:{if(h.length<20)break;let f=p(h,0),k=p(h,2),A=o[p(h,4)];y=[f,k];let g=ui(h.subarray(6,14),A,s);if(g!==void 0&&g.kind!=="empty")u.push({row:f,col:k,value:g});break}case 10:return!1;default:break}return});let c=S(u);if(c===void 0)return;return{name:i,...c,merges:l}}function _n(n,i,e){if(n.length<14)return;let t=p(n,0),r=p(n,2),o=i[p(n,4)],s=pn(n,6);return{row:t,col:r,value:w(s,o,e)}}function an(n){if(n.length<8)return;let i=p(n,0),e=p(n,2);if(n[7]===0)return{row:i,col:e,value:{kind:"bool",value:n[6]!==0}};if(n[7]===1){let t=R(n[6]);return t===void 0?void 0:{row:i,col:e,value:t}}return}function ni(n,i,e){if(n.length<10)return;return{row:p(n,0),col:p(n,2),value:cn(n.subarray(4,10),i,e)}}function ii(n,i,e,t){if(n.length<6)return;let r=p(n,0),o=p(n,2),s=p(n,n.length-2);if(n.length!==6+6*(s-o+1))return;let u=o;for(let l=4;l+6<=n.length-2;l+=6)i.push({row:r,col:u,value:cn(n.subarray(l,l+6),e,t)}),u+=1}function cn(n,i,e){let t=(n[2]&1)!==0,r=(n[2]&2)!==0,o=i[p(n,0)];if(r){let u=pi(n,2)>>2;if(t&&u%100!==0)return w(u/100,o,e);return Z(t?Math.trunc(u/100):u,o,e)}X.setUint32(0,0,!0),X.setUint32(4,G(n,2)&4294967292,!0);let s=X.getFloat64(0,!0);return w(t?s/100:s,o,e)}function ei(n,i){if(n.length<2)return;let e=p(n,0);for(let t=0;t<e;t+=1){let r=2+t*8;if(r+8>n.length)break;i.push({start:[p(n,r),p(n,r+4)],end:[p(n,r+2),p(n,r+6)]})}}function ti(n,i,e){if(n.length<6)return;let t=j(n.subarray(6),i,e);if(t===void 0)return;return{row:p(n,0),col:p(n,2),value:{kind:"string",value:t}}}function ri(n,i){if(n.length<10)return;let e=G(n,6),t=i[e];if(t===void 0)return;return{row:p(n,0),col:p(n,2),value:{kind:"string",value:t}}}function ui(n,i,e){if(n.length<8)return;if(n[6]===255&&n[7]===255)switch(n[0]){case 0:return;case 1:return{kind:"bool",value:n[2]!==0};case 2:return R(n[2])??$;case 3:return{kind:"string",value:""};default:return $}return w(pn(n,0),i,e)}function oi(n){if(n.length<2)return;let i=p(n,0),e=n.length>=4?p(n,2):0;switch(i){case 512:case 2:case 7:return 2;case 768:return 3;case 1024:return 4;case 1280:return 5;case 1536:return 8;case 0:return e===4096?5:8;default:return 8}}function si(n,i,e){if(n.data.length<6)return;let t=G(n.data,0);n.consume(6);let r=ci(n,i,e);if(r===void 0)return;return{pos:t,name:r.replace(/\0/g,"")}}function li(n,i,e){if(n.length<2)return;let t=p(n,0);if(!(t>=5&&t<=8||t>=23&&t<=26||t>=41&&t<=44||t>=63&&t<=66||t>=164&&t<=382)){Y(`skipping invalid number format id ${t}`);return}let o=j(n.subarray(2),i,e);if(o===void 0)return;return{ifmt:t,format:V(o)}}function fi(n,i){if(n.data.length<8)return[];n.consume(8);let e=[];while(!n.exhausted())e.push(hi(n,i));return e}function hi(n,i){if(n.exhausted())return"";if(n.remaining()<3&&!n.continueRecord())return"";if(n.remaining()<3)return"";let e=n.u16(),t=n.u8(),r=(t&1)!==0,o=0,s=0;if((t&8)!==0){if(n.remaining()<2&&!n.continueRecord())return"";o=n.u16()}if((t&4)!==0){if(n.remaining()<4&&!n.continueRecord())return"";s=n.i32()}let u=xi(i,e,n,r);return n.skip(o*4),n.skip(Math.max(0,s)),u}function xi(n,i,e,t){let r=i,o=t,s="";while(r>0){let{chars:u,decoded:l,bytes:y}=n.decodeTo(e.rest(),r,o);if(e.consume(y),s+=u,r-=l,r>0){if(!e.continueRecord())break;if(e.remaining()<1)break;o=(e.u8()&1)!==0}}return s}function ci(n,i,e){let t=e===8;if(n.remaining()<(t?2:1))return;let r=n.u8(),o;if(t)o=(n.u8()&1)!==0;let s=i.decodeTo(n.rest(),r,o);return n.consume(s.bytes),s.chars}function j(n,i,e){let t=e===8?3:2;if(n.length<t){if(n.length===2&&p(n,0)===0)return"";return}let r=p(n,0),o=e===8?(n[2]&1)!==0:void 0;return i.decodeTo(n.subarray(t),r,o).chars}function ln(n){let i=yi(n),e=i!=="utf16-le"&&i!=="utf16-be"&&i!=="utf8";return{name:i,decodeTo(t,r,o){let s=o??(i==="utf8"||e?void 0:!1);if(s===void 0){let l=Math.min(t.length,r);return{chars:fn(t.subarray(0,l),i),decoded:l,bytes:l}}if(s===!1){let l=Math.min(t.length,r);return{chars:hn.decode(t.subarray(0,l)),decoded:l,bytes:l}}let u=Math.min(Math.floor(t.length/2),r);return{chars:fn(t.subarray(0,2*u),"utf16-le"),decoded:u,bytes:2*u}}}}function fn(n,i){if(i==="utf8")return Bn.decode(n);if(i==="utf16-le")return Mn.decode(n);if(i==="utf16-be")return En.decode(n);if(jn(i))return Yn(n,i);return hn.decode(n)}function yi(n){return{437:"cp437",850:"cp850",852:"cp852",855:"cp855",857:"cp857",860:"cp860",861:"cp861",862:"cp862",863:"cp863",864:"cp864",865:"cp865",866:"cp866",869:"cp869",874:"windows-874",932:"shiftjis",936:"gbk",949:"euc-kr",950:"big5",1200:"utf16-le",1201:"utf16-be",1250:"windows-1250",1251:"windows-1251",1252:"windows-1252",1253:"windows-1253",1254:"windows-1254",1255:"windows-1255",1256:"windows-1256",1257:"windows-1257",1258:"windows-1258",1e4:"macintosh",10001:"shiftjis",10007:"koi8-r",20127:"ascii",20866:"koi8-r",21866:"koi8-u",28591:"iso-8859-1",28592:"iso-8859-2",28595:"iso-8859-5",28597:"iso-8859-7",28599:"iso-8859-9",28605:"iso-8859-15",50220:"iso-2022-jp",50221:"iso-2022-jp",50222:"iso-2022-jp",51932:"euc-jp",51949:"euc-kr",52936:"gb2312",54936:"gb18030",65000:"utf8",65001:"utf8"}[n]??"windows-1252"}class L{typ;parts;i=0;o=0;constructor(n,i,e){this.typ=n,this.parts=[i,...e]}remaining(){let n=this.parts[this.i];return n===void 0?0:n.length-this.o}rest(){let n=this.parts[this.i];return n===void 0?new Uint8Array(0):n.subarray(this.o)}exhausted(){while(this.i<this.parts.length){if(this.remaining()>0)return!1;if(!this.continueRecord())return!0}return!0}continueRecord(){if(this.i+1>=this.parts.length)return!1;return this.i+=1,this.o=0,!0}consume(n){this.o+=n;while(this.i<this.parts.length&&this.o>=(this.parts[this.i]?.length??0))if(this.o-=this.parts[this.i].length,this.i+=1,this.i>=this.parts.length){this.o=0;break}}skip(n){let i=n;while(i>0){if(this.remaining()===0&&!this.continueRecord())return;let e=Math.min(i,this.remaining());this.consume(e),i-=e}}u8(){if(this.remaining()<1&&!this.continueRecord())return 0;let n=this.rest()[0]??0;return this.consume(1),n}u16(){if(this.remaining()>=2){let n=p(this.rest(),0);return this.consume(2),n}return this.u8()|this.u8()<<8}i32(){let n=this.u8(),i=this.u8(),e=this.u8(),t=this.u8();return(n|i<<8|e<<16|t<<24)<<0}get data(){if(this.parts.length===1)return this.parts[0].subarray(this.o);let n=[],i=0;for(let r=this.i;r<this.parts.length;r+=1){let o=r===this.i?this.parts[r].subarray(this.o):this.parts[r];n.push(o),i+=o.length}let e=new Uint8Array(i),t=0;for(let r of n)e.set(r,t),t+=r.length;return e}}function yn(n,i){let e=0,t=0,r=!1;while(e+4<=n.length){let o=p(n,e),s=p(n,e+2);if(e+4+s>n.length)break;let u=n.subarray(e+4,e+4+s);e+=4+s;let l;if(e+4<=n.length&&p(n,e)===60){let c=[];while(e+4<=n.length&&p(n,e)===60){let x=p(n,e+2);if(e+4+x>n.length)break;c.push(n.subarray(e+4,e+4+x)),e+=4+x}l=new L(o,u,c)}if(t+=1,t>sn)throw J.resourceLimit("max_records",`workbook stream exceeds ${sn} records`);if(r)continue;let y=i(o,l!==void 0?l.data:u,l);if(y===!1)return;if(y==="count")r=!0}}function p(n,i){return i+1<n.length?n[i]|n[i+1]<<8:0}function G(n,i){if(i+3>=n.length)return 0;return(n[i]|n[i+1]<<8|n[i+2]<<16|n[i+3]<<24)>>>0}function pi(n,i){return G(n,i)<<0}function pn(n,i){if(i+8>n.length)return Number.NaN;return X.setUint32(0,G(n,i),!0),X.setUint32(4,G(n,i+4),!0),X.getFloat64(0,!0)}import{readRels as ki,relsPartFor as Ai,resolve as mn}from"@mdgate/containers";import{ConvertError as O}from"@mdgate/core";import{warn as gi}from"@mdgate/utils";var mi="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",wi="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";function wn(n){let i=n.hasPart("xl/workbook.bin")?"xl/workbook.bin":void 0;if(i===void 0)throw O.malformed("unreadable workbook: missing xl/workbook.bin");let e=ki(n,Ai(i)),t=Pi(n,e,i),r=Ni(n,e,i),{sheets:o,is1904:s}=Ui(n,e,i),u=[],l=0;for(let y of o)try{let c=Fi(n,y.path,y.name,t,r,s);if(c!==void 0)u.push(c)}catch(c){if(c instanceof O&&c.isFatal())throw c;gi(`skipping unreadable sheet ${JSON.stringify(y.name)}: ${c instanceof Error?c.message:String(c)}`),l+=1}if(o.length>0&&l===o.length)throw O.malformed("no sheet in the workbook could be read");return u}function Pi(n,i,e){let t=Pn(n,i,e,mi)??"xl/sharedStrings.bin",r=n.optionalPart(t);if(r===void 0)return[];let o=new q(r),s=[];try{o.nextSkipBlocks(159,[],s)}catch{return[]}let u=Uint8Array.from(s),l=u.length>=8?U(u,4):0,y=[];for(let c=0;c<l;c+=1)try{o.nextSkipBlocks(19,[[35,36]],s);let x=Uint8Array.from(s);if(x.length>1)y.push(K(x.subarray(1)))}catch{break}return y}function Ni(n,i,e){let t=Pn(n,i,e,wi)??"xl/styles.bin",r=n.optionalPart(t);if(r===void 0)return[];let o=new q(r),s=[],u=new Map,l=[];try{for(;;){let y=o.readType();if(y===void 0)break;if(o.fillBuffer(s),y===615){let c=Uint8Array.from(s),x=An(c,0);for(let h=0;h<x;h+=1){o.nextSkipBlocks(44,[],s);let f=Uint8Array.from(s);if(f.length<2)continue;let k=kn(f,0);u.set(k,V(K(f.subarray(2))))}}else if(y===617){let c=Uint8Array.from(s),x=An(c,0);for(let h=0;h<x;h+=1){o.nextSkipBlocks(47,[],s);let f=Uint8Array.from(s),k=f.length>=4?kn(f,2):0,A=D(k);l.push(A==="other"?u.get(k)??"other":A)}break}}}catch{}return l}function Ui(n,i,e){let t=n.requiredPart(e),r=new q(t),o=[],s=!1,u=[];for(;;){let l=r.readType();if(l===void 0)break;r.fillBuffer(o);let y=Uint8Array.from(o);if(l===153){if(y.length>0)s=(y[0]&1)!==0}else if(l===156){if(y.length<12)continue;let c=U(y,8);if(c===4294967295)continue;let x=c*2;if(12+x>y.length)continue;let h=new TextDecoder("utf-16le").decode(y.subarray(12,12+x)),f=i.get(h);if(f===void 0||f.mode!=="internal")continue;let k;try{k=f.target.startsWith("/")?f.target.replace(/^\/+/,""):mn(e,f.target).path}catch{continue}let A=K(y.subarray(12+x));u.push({name:A,path:k})}else if(l===144)break}return{sheets:u,is1904:s}}function Fi(n,i,e,t,r,o){let s=n.optionalPart(i);if(s===void 0)return;let u=new q(s),l=[];try{u.nextSkipBlocks(148,[[129,void 0],[147,void 0]],l),u.nextSkipBlocks(145,[[133,134],[37,38],[485,void 0],[390,391]],l)}catch{return}let y=[],c=0;for(;;){let h=u.readType();if(h===void 0)break;u.fillBuffer(l);let f=Uint8Array.from(l);if(h===146)break;if(h===0){if(f.length>=4)c=U(f,0);if(c>1048576)break;continue}let k=Ii(h,f,t,r,o);if(k===void 0||k.kind==="empty")continue;let A=f.length>=4?U(f,0):0;y.push({row:c,col:A,value:k})}let x=S(y);if(x===void 0)return;return{name:e,...x,merges:[]}}function Ii(n,i,e,t,r){let o=Wi(t,i);switch(n){case 2:{if(i.length<12)return;let s=i[8],u=(s&1)!==0,l=(s&2)!==0,y=new Uint8Array(i.subarray(8,12));if(y[0]=y[0]&252,l){let h=$i(y,0)>>2;if(u)return w(h/100,o,r);return Z(h,void 0,r)}let c=new Uint8Array(8);c.set(y,4);let x=gn(c,0);return w(u?x/100:x,o,r)}case 3:{if(i.length<9)return;return R(i[8])}case 4:case 10:return{kind:"bool",value:(i[8]??0)!==0};case 5:case 9:return i.length>=16?w(gn(i,8),o,r):void 0;case 6:case 8:return i.length>8?{kind:"string",value:K(i.subarray(8))}:void 0;case 7:{if(i.length<12)return;let s=e[U(i,8)];return s===void 0?void 0:{kind:"string",value:s}}default:return}}function Wi(n,i){if(i.length<7)return;let e=i[4]|i[5]<<8|i[6]<<16;return n[e]}function Pn(n,i,e,t){let r=i.firstOfType(t);if(r===void 0)return;try{let o=mn(e,r.target);if(n.hasPart(o.path))return o.path}catch{return}return}class q{bytes;pos=0;constructor(n){this.bytes=n}readType(){if(this.pos>=this.bytes.length)return;let n=this.bytes[this.pos];if(this.pos+=1,(n&128)===128){if(this.pos>=this.bytes.length)return;let i=this.bytes[this.pos];return this.pos+=1,(n&127)+((i&127)<<7)}return n}fillBuffer(n){if(this.pos>=this.bytes.length)return n.length=0,0;let i=this.bytes[this.pos];this.pos+=1;let e=i&127;for(let r=1;r<4&&(i&128)!==0;r+=1){if(this.pos>=this.bytes.length)break;i=this.bytes[this.pos],this.pos+=1,e+=(i&127)<<7*r}let t=Math.min(this.bytes.length,this.pos+e);n.length=0;for(let r=this.pos;r<t;r+=1)n.push(this.bytes[r]);return this.pos=t,n.length}nextSkipBlocks(n,i,e){for(;;){let t=this.readType();if(t===void 0)throw O.malformed("unreadable workbook: truncated xlsb records");let r=this.fillBuffer(e);if(t===n)return r;let o=i.find((s)=>s[0]===t);if(o!==void 0&&o[1]!==void 0){let s=o[1];while(this.readType()!==s)this.fillBuffer(e);this.fillBuffer(e)}}}}function K(n){if(n.length<4)return"";let i=U(n,0),e=Math.min(n.length,4+i*2);return new TextDecoder("utf-16le").decode(n.subarray(4,e))}function kn(n,i){return n[i]|n[i+1]<<8}function U(n,i){return(n[i]|n[i+1]<<8|n[i+2]<<16|n[i+3]<<24)>>>0}function An(n,i){return U(n,i)}function $i(n,i){let e=U(n,i);return e>2147483647?e-4294967296:e}function gn(n,i){if(i+8>n.length)return Number.NaN;return new DataView(n.buffer,n.byteOffset+i,8).getFloat64(0,!0)}import{parseXml as Si,readRels as Nn,relsPartFor as Vi,relType as Ji,resolve as M}from"@mdgate/containers";import{ConvertError as B}from"@mdgate/core";import{warn as b}from"@mdgate/utils";var Xi="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",Gi="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";function E(n){let i=Ri(n),e=[],t=0;for(let r of i.sheets)try{let o=Zi(n,r.path,r.name,i);if(o!==void 0)e.push(o)}catch(o){if(o instanceof B&&o.isFatal())throw o;b(`skipping unreadable sheet ${JSON.stringify(r.name)}: ${o instanceof Error?o.message:String(o)}`),t+=1}if(i.sheets.length>0&&t===i.sheets.length)throw B.malformed("no sheet in the workbook could be read");return e}function Ri(n){let e=Nn(n,"_rels/.rels").firstOfType(Ji.OFFICE_DOCUMENT),t="xl/workbook.xml";if(e!==void 0)try{t=M("",e.target).path}catch{}let r=[],o=[],s=!1,u=[],l=Nn(n,Vi(t)),y=Un(n,l,t,Xi)??Fn(t,"sharedStrings.xml"),c=Un(n,l,t,Gi)??Fn(t,"styles.xml"),x=n.optionalXmlPart(y);if(x!==void 0)qi(x,r);let h=n.optionalXmlPart(c);if(h!==void 0)Ti(h,o);let f=n.optionalXmlPart(t);if(f!==void 0)s=In(f,l,t,u);else if(n.hasPart(t)===!1&&n.hasPart("xl/workbook.xml")){let k=n.optionalXmlPart("xl/workbook.xml");if(k!==void 0)s=In(k,l,"xl/workbook.xml",u)}return{sheets:u,strings:r,formats:o,is1904:s}}function Un(n,i,e,t){let r=i.firstOfType(t);if(r===void 0)return;try{let o=M(e,r.target);if(n.hasPart(o.path))return o.path}catch{return}return}function Fn(n,i){let e=n.lastIndexOf("/");return e<0?i:`${n.slice(0,e+1)}${i}`}function In(n,i,e,t){let r=!1,o=N(n,"workbook")??n;for(let u of o.childElems())if(u.local==="workbookPr"){let l=u.attrAny("date1904");r=l==="1"||l==="true"}let s=N(o,"sheets");if(s===void 0)return r;for(let u of s.childElems()){if(u.local!=="sheet")continue;let l=u.attrAny("name"),y=u.attrAny("id");if(l===void 0||y===void 0)continue;let c=i.internalTarget(y);if(c===void 0){b(`skipping sheet ${JSON.stringify(l)}: missing worksheet relationship`);continue}let x;try{x=c.startsWith("/")?c.replace(/^\/+/,""):M(e,c).path}catch(h){b(`skipping sheet ${JSON.stringify(l)}: ${h instanceof Error?h.message:String(h)}`);continue}t.push({name:l,path:x})}return r}function qi(n,i){let e=N(n,"sst")??n;for(let t of e.childElems()){if(t.local!=="si")continue;i.push($n(t))}}function $n(n){let i="",e=!1,t=(r,o)=>{if(r.local==="rPh")return;if(r.local==="t"&&!o){e=!0;let s=r.attr("http://www.w3.org/XML/1998/namespace","space")==="preserve",u=r.text();i+=s?u:zi(u);return}for(let s of r.childElems())t(s,o||r.local==="rPh")};return t(n,!1),e?i:""}function zi(n){let i=0,e=n.length;while(i<e&&Wn(n.charCodeAt(i)))i+=1;while(e>i&&Wn(n.charCodeAt(e-1)))e-=1;return n.slice(i,e)}function Wn(n){return n===32||n===9||n===10||n===13}function Ti(n,i){let e=N(n,"styleSheet")??n,t=new Map,r=N(e,"numFmts");if(r!==void 0)for(let s of r.childElems()){if(s.local!=="numFmt")continue;let u=s.attrAny("numFmtId"),l=s.attrAny("formatCode");if(u!==void 0&&l!==void 0)t.set(u,l)}let o=N(e,"cellXfs");if(o===void 0)return;for(let s of o.childElems()){if(s.local!=="xf")continue;let u=s.attrAny("numFmtId");if(u===void 0){i.push("other");continue}let l=t.get(u);i.push(l!==void 0?V(l):on(u))}}function Zi(n,i,e,t){let r=n.optionalPart(i);if(r===void 0)return;let o;try{o=Si(r)}catch(x){if(x instanceof B&&x.isFatal())throw x;throw x}let s=N(o,"worksheet")??o,u=N(s,"sheetData");if(u===void 0)return;let l=[];for(let x of u.childElems()){if(x.local!=="row")continue;let h,f=x.attrAny("r");if(f!==void 0){let A=Number.parseInt(f,10);if(Number.isFinite(A)&&A>0)h=A-1}let k=0;for(let A of x.childElems()){if(A.local!=="c")continue;let g=Q(A.attrAny("r")),m=g?.row??h??0,I=g?.col??k;k=I+1;let W=Ci(A,t);if(W.kind==="empty")continue;l.push({row:m,col:I,value:W})}}let y=S(l);if(y===void 0)return;let c=[];try{let x=N(s,"mergeCells");if(x!==void 0)for(let h of x.childElems()){if(h.local!=="mergeCell")continue;let f=h.attrAny("ref");if(f===void 0)continue;let k=Di(f);if(k!==void 0)c.push(k)}}catch(x){b(`skipping unreadable merged-region list for ${JSON.stringify(e)}: ${x instanceof Error?x.message:String(x)}`)}return{name:e,...y,merges:c}}function Ci(n,i){let e=n.attrAny("t"),t=n.attrAny("s"),r="other";if(t!==void 0){let u=Number.parseInt(t,10);r=Number.isFinite(u)?i.formats[u]:void 0}let o,s;for(let u of n.childElems())if(u.local==="is")o=$n(u);else if(u.local==="v")s=u.text();if(e==="inlineStr"||e==="is")return o===void 0?{kind:"empty"}:{kind:"string",value:o};if(o!==void 0&&s===void 0)return{kind:"string",value:o};if(s===void 0)return{kind:"empty"};switch(e){case"s":{if(s.length===0)return{kind:"empty"};let u=Number.parseInt(s,10),l=Number.isFinite(u)?i.strings[u]:void 0;return l===void 0?{kind:"empty"}:{kind:"string",value:l}}case"b":return{kind:"bool",value:s!=="0"};case"d":return{kind:"datetimeIso",value:s};case"e":return en(s);case"str":return{kind:"string",value:s};case"n":case void 0:{if(s.length===0)return{kind:"empty"};let u=Number.parseFloat(s);if(Number.isFinite(u)||u===Number.POSITIVE_INFINITY||u===Number.NEGATIVE_INFINITY)return w(u,r,i.is1904);if(e===void 0)return{kind:"string",value:s};return{kind:"empty"}}default:return{kind:"empty"}}}function Q(n){if(n===void 0||n.length===0)return;let i=0,e=0,t=0;while(i<n.length){let r=n.charCodeAt(i);if(r>=65&&r<=90)e=e*26+(r-64);else if(r>=97&&r<=122)e=e*26+(r-96);else if(r>=48&&r<=57){t=r-48,i+=1;break}else return;i+=1}while(i<n.length){let r=n.charCodeAt(i);if(r<48||r>57)return;t=t*10+(r-48),i+=1}if(t<1||e<1)return;return{row:t-1,col:e-1}}function Di(n){let i=n.indexOf(":");if(i<0){let r=Q(n);return r===void 0?void 0:{start:[r.row,r.col],end:[r.row,r.col]}}let e=Q(n.slice(0,i)),t=Q(n.slice(i+1));if(e===void 0||t===void 0)return;return{start:[e.row,e.col],end:[t.row,t.col]}}function N(n,i){return n.childElems().find((e)=>e.local===i)}function Sn(n){try{return un(bi(n))}catch(i){throw v(i)}}function bi(n){if(Oi(n)){let e;try{e=Li.open(n)}catch(t){throw v(t)}if(e.exists("EncryptionInfo")||e.exists("EncryptedPackage"))throw F.encrypted();return xn(e)}if(!Hi(n))throw F.malformed("unreadable workbook: Cannot detect file format");let i;try{i=Ki.open(n)}catch(e){let t=Qi(n);if(t!==void 0)throw t;throw v(e)}if(i.hasPart("xl/workbook.xml"))return E(i);if(i.hasPart("xl/workbook.bin"))return wn(i);return E(i)}function Hi(n){return n.length>=4&&n[0]===80&&n[1]===75&&n[2]===3&&n[3]===4}function v(n){if(n instanceof F){if(n.code==="encrypted"||n.code==="resourceLimit"||n.code==="io")return n;if(n.code==="malformed"){if(n.message.toLowerCase().includes("password"))return F.encrypted();if(n.message.startsWith("malformed document: unreadable workbook:"))return n;if(n.message.startsWith("malformed document: no sheet"))return n;return F.malformed(`unreadable workbook: ${n.detail??n.message}`)}return n}let i=n instanceof Error?n.message:String(n);if(i.toLowerCase().includes("password"))return F.encrypted();return F.malformed(`unreadable workbook: ${i}`)}var Ei=new Set(["xlsx","xlsm","xlsb","xls","xltx","xltm","xlt"]);function d(){return{id:"xlsx",sniff(n,i){if(ji(n)==="xlsx"||Yi(n)==="xls")return 2;if(i?.path!==void 0&&Ei.has(Mi(i.path)??""))return 1;return 0},convert(n){return{markdown:Bi(Sn(n))}}}}var di=vi([d()]);function _i(n,i){return di(n,i)}export{d as xlsx,_i as toMarkdown};
1
+ import{create as Mi}from"@mdgate/core";import{detectOleDoc as Qi,detectZipDoc as bi}from"@mdgate/containers";import{documentToMarkdown as Hi}from"@mdgate/document";import{fileExtension as Yi}from"@mdgate/utils";import{CompoundFile as zi,hasOleMagic as qi,Package as Ti,probeOle as Zi}from"@mdgate/containers";import{ConvertError as S}from"@mdgate/core";import{ConvertError as nn}from"@mdgate/core";import{emptyDocument as zn,heading as qn,plain as en,resolveHeaderRows as Tn}from"@mdgate/document";import{warn as Zn}from"@mdgate/utils";import{cleanText as Wn}from"@mdgate/utils";var I={kind:"empty"};function m(n,i,e){if(i==="datetime")return{kind:"datetime",value:n,duration:!1,is1904:e};if(i==="timedelta")return{kind:"datetime",value:n,duration:!0,is1904:e};return{kind:"float",value:n}}function z(n,i,e){if(i==="datetime")return{kind:"datetime",value:n,duration:!1,is1904:e};if(i==="timedelta")return{kind:"datetime",value:n,duration:!0,is1904:e};return{kind:"int",value:n}}var $n={0:"Null",7:"Div0",15:"Value",23:"Ref",29:"Name",36:"Num",42:"NA",43:"GettingData"},Xn={"#NULL!":"Null","#DIV/0!":"Div0","#VALUE!":"Value","#REF!":"Ref","#NAME?":"Name","#NUM!":"Num","#N/A":"NA","#DATA!":"GettingData","#GETTING_DATA":"GettingData"};function V(n){let i=$n[n];return i===void 0?void 0:{kind:"error",name:i}}function _(n){return{kind:"error",name:Xn[n]??n.replace(/^#/,"")}}function a(n){switch(n.kind){case"empty":return"";case"string":return Wn(n.value);case"float":return d(n.value);case"int":return String(n.value);case"bool":return n.value?"TRUE":"FALSE";case"error":return`#${n.name}`;case"datetime":if(n.duration)return Jn(n.value);if(Math.abs(n.value)<1)return Vn(n.value);return Dn(n.value,n.is1904)??d(n.value);case"datetimeIso":case"durationIso":return n.value}}function d(n){if(Number.isNaN(n))return"NaN";if(n===Number.POSITIVE_INFINITY)return"inf";if(n===Number.NEGATIVE_INFINITY)return"-inf";let i=Number.parseFloat(n.toExponential(14));if(Number.isNaN(i))return String(n);return Rn(i)}function Rn(n){if(Object.is(n,-0))return"0";let i=n.toString();if(!/[eE]/.test(i))return i;let e=i.match(/^([+-]?)(\d+)(?:\.(\d+))?[eE]([+-]?\d+)$/);if(e===null)return i;let t=e[1]==="-"?"-":"",r=e[2]+(e[3]??""),s=1+Number(e[4]);if(s<=0)return`${t}0.${"0".repeat(-s)}${r}`;if(s>=r.length)return`${t}${r}${"0".repeat(s-r.length)}`;let o=r.slice(0,s),l=r.slice(s);return`${t}${o}.${l}`}function Vn(n){let i=Math.round(Math.abs(n)*86400)%86400,e=Math.floor(i/3600),t=Math.floor(i%3600/60),r=i%60;return`${w(e)}:${w(t)}:${w(r)}`}function Jn(n){let i=n<0?"-":"",e=Math.round(Math.abs(n)*86400),t=Math.floor(e/3600),r=Math.floor(e%3600/60),u=e%60;return`${i}${t}:${w(r)}:${w(u)}`}var Cn=1462,Gn=86400000,On=Date.UTC(1899,11,30);function Dn(n,i){let e=i?n+Cn:n;if(e<60)e+=1;let t=Math.round(e*Gn),r=On+t;if(!Number.isFinite(r))return;let u=new Date(r);if(Number.isNaN(u.getTime()))return;let s=u.getUTCFullYear();if(s<0||s>9999)return;let o=`${s}-${w(u.getUTCMonth()+1)}-${w(u.getUTCDate())} ${w(u.getUTCHours())}:${w(u.getUTCMinutes())}:${w(u.getUTCSeconds())}`;return o.endsWith(" 00:00:00")?o.slice(0,-9):o}function w(n){return n<10?`0${n}`:String(n)}function W(n){if(n.length===0)return;let i=Number.POSITIVE_INFINITY,e=0,t=Number.POSITIVE_INFINITY,r=0;for(let l of n){if(l.row<i)i=l.row;if(l.row>e)e=l.row;if(l.col<t)t=l.col;if(l.col>r)r=l.col}let u=r-t+1,s=e-i+1,o=Array(u*s).fill(I);for(let l of n){let x=(l.row-i)*u+(l.col-t);if(x>=0&&x<o.length)o[x]=l.value}return{start:[i,t],height:s,width:u,values:o}}function tn(n){let i=zn(),e=n.length>1,t=0,r=0;for(let u of n){if(r+=1,u.height===0||u.width===0||u.values.length===0)continue;try{let s=Ln(u);if(s===void 0)continue;if(e)i.blocks.push(qn(2,[en(u.name)]));i.blocks.push({type:"table",table:s})}catch(s){if(s instanceof nn&&s.isFatal())throw s;Zn(`skipping unreadable sheet ${JSON.stringify(u.name)}: ${s instanceof Error?s.message:String(s)}`),t+=1}}if(r>0&&t===r&&i.blocks.length===0)throw nn.malformed("no sheet in the workbook could be read");return i}function Ln(n){let{start:i,height:e,width:t,values:r,merges:u}=n,s=u.length>0?new Map:void 0,o=u.length>0?new Map:void 0;if(s!==void 0&&o!==void 0)for(let c of u){let y=Math.max(c.start[0],i[0]),h=Math.max(c.start[1],i[1]),f=Math.min(c.end[0]+1,i[0]+e),A=Math.min(c.end[1]+1,i[1]+t);if(y>=f||h>=A)continue;let k=y-i[0],g=h-i[1],N=f-i[0],F=A-i[1];if(N-k===1&&F-g===1)continue;let G=F-g,In=N-k;s.set(q(k,g),[G,In]);for(let O=k;O<N;O+=1)for(let D=g;D<F;D+=1)if(O!==k||D!==g)o.set(q(O,D),[k,g])}let l=Array(e);for(let c=0;c<e;c+=1){let y=Array(t),h=c*t;for(let f=0;f<t;f+=1){let A=o?.get(q(c,f));if(A!==void 0){y[f]={type:"covered",originRow:A[0],originCol:A[1]};continue}let k=r[h+f]??I,g=k.kind==="empty"?"":a(k),N=s?.get(q(c,f));y[f]={type:"origin",cell:{blocks:g.length===0?[]:[{type:"paragraph",inlines:[en(g)]}],colSpan:N?.[0]??1,rowSpan:N?.[1]??1}}}l[c]=y}while(l.length>0){if(!l[l.length-1].every((h)=>h.type!=="origin"||h.cell.blocks.length===0))break;l.pop()}if(l.length===0)return;let x={grid:l,headerRows:0,kind:"data"};return x.headerRows=Tn(x,0),x}function q(n,i){return n*65536+i}import{readOleStream as Kn}from"@mdgate/containers";import{ConvertError as J}from"@mdgate/core";import{decode as Qn,encodingExists as bn,warn as H}from"@mdgate/utils";function $(n){let i=!1,e=!1,t=0,r=" ",u=!1,s=!1;for(let o of n){if(i)i=!1;else if(o==="_"||o==="\\"||o==="*")i=!0;else if(o==='"'&&e)e=!1;else if(e);else if(o==='"')e=!0;else if(o===";")return"other";else if(o==="[")t+=1;else if(o==="]"&&t===1&&u)return"timedelta";else if(o==="]")t=Math.max(0,t-1);else if((o==="a"||o==="A")&&!s&&t===0)s=!0;else if((o==="p"||o==="m"||o==="/"||o==="P"||o==="M")&&s&&t===0)return"datetime";else if(!s&&t===0&&(o==="d"||o==="m"||o==="h"||o==="y"||o==="s"||o==="D"||o==="M"||o==="H"||o==="Y"||o==="S"))return"datetime";else if(u&&o.toLowerCase()===r.toLowerCase());else u=r==="["&&(o==="m"||o==="h"||o==="s"||o==="M"||o==="H"||o==="S");r=o}return"other"}function rn(n){switch(n){case"14":case"15":case"16":case"17":case"18":case"19":case"20":case"21":case"22":case"45":case"47":return"datetime";case"46":return"timedelta";default:return"other"}}function T(n){if(n>=14&&n<=22||n===45||n===47)return"datetime";if(n===46)return"timedelta";return"other"}var sn=new TextDecoder("latin1"),Hn=new TextDecoder("utf-8"),Yn=new TextDecoder("utf-16le"),jn=new TextDecoder("utf-16be"),X=new DataView(new ArrayBuffer(8));function ln(n){let i=Mn(n),e=8,t=on(1200),r=!1,u=[],s=[],o=new Map,l=[];hn(i,(h,f,A)=>{switch(h){case 47:if(p(f,0)!==0)throw J.encrypted();break;case 66:t=on(p(f,0));break;case 34:if(p(f,0)===1)r=!0;break;case 1054:{let k=oi(f,t,e);if(k!==void 0)o.set(k.ifmt,k.format);break}case 224:if(f.length>=4)l.push(p(f,2));break;case 133:{let k=ri(A??new Z(h,f,[]),t,e);if(k!==void 0)u.push(k);break}case 2057:{let k=ti(f);if(k!==void 0)e=k;break}case 252:s.push(...ui(A??new Z(h,f,[]),t));break;default:break}if(h===10&&u.length>0)return!1;return});let x=l.map((h)=>o.get(h)??T(h)),c=[],y=0;for(let h of u){if(h.pos>=i.length){H(`skipping unreadable sheet ${JSON.stringify(h.name)}: bound offset past end of stream`),y+=1;continue}try{let f=Bn(i.subarray(h.pos),h.name,t,e,s,x,r);if(f!==void 0)c.push(f)}catch(f){if(f instanceof J&&f.isFatal())throw f;if(f instanceof J&&f.code==="encrypted")throw f;H(`skipping unreadable sheet ${JSON.stringify(h.name)}: ${f instanceof Error?f.message:String(f)}`),y+=1}}if(u.length>0&&y===u.length)throw J.malformed("no sheet in the workbook could be read");return c}function Mn(n){for(let i of["Workbook","Book","WORKBOOK","BOOK"])if(n.exists(i))return Kn(n,i);throw J.malformed("unreadable workbook: Cannot find Workbook stream")}function Bn(n,i,e,t,r,u,s){let o=[],l=[],x;hn(n,(y,h)=>{switch(y){case 515:{let f=En(h,u,s);if(f!==void 0)o.push(f);break}case 516:case 214:{let f=ni(h,e,t);if(f!==void 0)o.push(f);break}case 517:{let f=vn(h);if(f!==void 0)o.push(f);break}case 519:{if(x!==void 0){let f=Y(h,e,t);if(f!==void 0)o.push({row:x[0],col:x[1],value:{kind:"string",value:f}})}break}case 638:{let f=dn(h,u,s);if(f!==void 0)o.push(f);break}case 253:{let f=ii(h,r);if(f!==void 0)o.push(f);break}case 189:_n(h,o,u,s);break;case 229:an(h,l);break;case 6:{if(h.length<20)break;let f=p(h,0),A=p(h,2),k=u[p(h,4)];x=[f,A];let g=ei(h.subarray(6,14),k,s);if(g!==void 0&&g.kind!=="empty")o.push({row:f,col:A,value:g});break}case 10:return!1;default:break}return});let c=W(o);if(c===void 0)return;return{name:i,...c,merges:l}}function En(n,i,e){if(n.length<14)return;let t=p(n,0),r=p(n,2),u=i[p(n,4)],s=xn(n,6);return{row:t,col:r,value:m(s,u,e)}}function vn(n){if(n.length<8)return;let i=p(n,0),e=p(n,2);if(n[7]===0)return{row:i,col:e,value:{kind:"bool",value:n[6]!==0}};if(n[7]===1){let t=V(n[6]);return t===void 0?void 0:{row:i,col:e,value:t}}return}function dn(n,i,e){if(n.length<10)return;return{row:p(n,0),col:p(n,2),value:fn(n.subarray(4,10),i,e)}}function _n(n,i,e,t){if(n.length<6)return;let r=p(n,0),u=p(n,2),s=p(n,n.length-2);if(n.length!==6+6*(s-u+1))return;let o=u;for(let l=4;l+6<=n.length-2;l+=6)i.push({row:r,col:o,value:fn(n.subarray(l,l+6),e,t)}),o+=1}function fn(n,i,e){let t=(n[2]&1)!==0,r=(n[2]&2)!==0,u=i[p(n,0)];if(r){let o=xi(n,2)>>2;if(t&&o%100!==0)return m(o/100,u,e);return z(t?Math.trunc(o/100):o,u,e)}X.setUint32(0,0,!0),X.setUint32(4,R(n,2)&4294967292,!0);let s=X.getFloat64(0,!0);return m(t?s/100:s,u,e)}function an(n,i){if(n.length<2)return;let e=p(n,0);for(let t=0;t<e;t+=1){let r=2+t*8;if(r+8>n.length)break;i.push({start:[p(n,r),p(n,r+4)],end:[p(n,r+2),p(n,r+6)]})}}function ni(n,i,e){if(n.length<6)return;let t=Y(n.subarray(6),i,e);if(t===void 0)return;return{row:p(n,0),col:p(n,2),value:{kind:"string",value:t}}}function ii(n,i){if(n.length<10)return;let e=R(n,6),t=i[e];if(t===void 0)return;return{row:p(n,0),col:p(n,2),value:{kind:"string",value:t}}}function ei(n,i,e){if(n.length<8)return;if(n[6]===255&&n[7]===255)switch(n[0]){case 0:return;case 1:return{kind:"bool",value:n[2]!==0};case 2:return V(n[2])??I;case 3:return{kind:"string",value:""};default:return I}return m(xn(n,0),i,e)}function ti(n){if(n.length<2)return;let i=p(n,0),e=n.length>=4?p(n,2):0;switch(i){case 512:case 2:case 7:return 2;case 768:return 3;case 1024:return 4;case 1280:return 5;case 1536:return 8;case 0:return e===4096?5:8;default:return 8}}function ri(n,i,e){if(n.data.length<6)return;let t=R(n.data,0);n.consume(6);let r=fi(n,i,e);if(r===void 0)return;return{pos:t,name:r.replace(/\0/g,"")}}function oi(n,i,e){if(n.length<2)return;let t=p(n,0);if(!(t>=5&&t<=8||t>=23&&t<=26||t>=41&&t<=44||t>=63&&t<=66||t>=164&&t<=382)){H(`skipping invalid number format id ${t}`);return}let u=Y(n.subarray(2),i,e);if(u===void 0)return;return{ifmt:t,format:$(u)}}function ui(n,i){if(n.data.length<8)return[];n.consume(8);let e=[];while(!n.exhausted())e.push(si(n,i));return e}function si(n,i){if(n.exhausted())return"";if(n.remaining()<3&&!n.continueRecord())return"";if(n.remaining()<3)return"";let e=n.u16(),t=n.u8(),r=(t&1)!==0,u=0,s=0;if((t&8)!==0){if(n.remaining()<2&&!n.continueRecord())return"";u=n.u16()}if((t&4)!==0){if(n.remaining()<4&&!n.continueRecord())return"";s=n.i32()}let o=li(i,e,n,r);return n.skip(u*4),n.skip(Math.max(0,s)),o}function li(n,i,e,t){let r=i,u=t,s="";while(r>0){let{chars:o,decoded:l,bytes:x}=n.decodeTo(e.rest(),r,u);if(e.consume(x),s+=o,r-=l,r>0){if(!e.continueRecord())break;if(e.remaining()<1)break;u=(e.u8()&1)!==0}}return s}function fi(n,i,e){let t=e===8;if(n.remaining()<(t?2:1))return;let r=n.u8(),u;if(t)u=(n.u8()&1)!==0;let s=i.decodeTo(n.rest(),r,u);return n.consume(s.bytes),s.chars}function Y(n,i,e){let t=e===8?3:2;if(n.length<t){if(n.length===2&&p(n,0)===0)return"";return}let r=p(n,0),u=e===8?(n[2]&1)!==0:void 0;return i.decodeTo(n.subarray(t),r,u).chars}function on(n){let i=hi(n),e=i!=="utf16-le"&&i!=="utf16-be"&&i!=="utf8";return{name:i,decodeTo(t,r,u){let s=u??(i==="utf8"||e?void 0:!1);if(s===void 0){let l=Math.min(t.length,r);return{chars:un(t.subarray(0,l),i),decoded:l,bytes:l}}if(s===!1){let l=Math.min(t.length,r);return{chars:sn.decode(t.subarray(0,l)),decoded:l,bytes:l}}let o=Math.min(Math.floor(t.length/2),r);return{chars:un(t.subarray(0,2*o),"utf16-le"),decoded:o,bytes:2*o}}}}function un(n,i){if(i==="utf8")return Hn.decode(n);if(i==="utf16-le")return Yn.decode(n);if(i==="utf16-be")return jn.decode(n);if(bn(i))return Qn(n,i);return sn.decode(n)}function hi(n){return{437:"cp437",850:"cp850",852:"cp852",855:"cp855",857:"cp857",860:"cp860",861:"cp861",862:"cp862",863:"cp863",864:"cp864",865:"cp865",866:"cp866",869:"cp869",874:"windows-874",932:"shiftjis",936:"gbk",949:"euc-kr",950:"big5",1200:"utf16-le",1201:"utf16-be",1250:"windows-1250",1251:"windows-1251",1252:"windows-1252",1253:"windows-1253",1254:"windows-1254",1255:"windows-1255",1256:"windows-1256",1257:"windows-1257",1258:"windows-1258",1e4:"macintosh",10001:"shiftjis",10007:"koi8-r",20127:"ascii",20866:"koi8-r",21866:"koi8-u",28591:"iso-8859-1",28592:"iso-8859-2",28595:"iso-8859-5",28597:"iso-8859-7",28599:"iso-8859-9",28605:"iso-8859-15",50220:"iso-2022-jp",50221:"iso-2022-jp",50222:"iso-2022-jp",51932:"euc-jp",51949:"euc-kr",52936:"gb2312",54936:"gb18030",65000:"utf8",65001:"utf8"}[n]??"windows-1252"}class Z{typ;parts;i=0;o=0;constructor(n,i,e){this.typ=n,this.parts=[i,...e]}remaining(){let n=this.parts[this.i];return n===void 0?0:n.length-this.o}rest(){let n=this.parts[this.i];return n===void 0?new Uint8Array(0):n.subarray(this.o)}exhausted(){while(this.i<this.parts.length){if(this.remaining()>0)return!1;if(!this.continueRecord())return!0}return!0}continueRecord(){if(this.i+1>=this.parts.length)return!1;return this.i+=1,this.o=0,!0}consume(n){this.o+=n;while(this.i<this.parts.length&&this.o>=(this.parts[this.i]?.length??0))if(this.o-=this.parts[this.i].length,this.i+=1,this.i>=this.parts.length){this.o=0;break}}skip(n){let i=n;while(i>0){if(this.remaining()===0&&!this.continueRecord())return;let e=Math.min(i,this.remaining());this.consume(e),i-=e}}u8(){if(this.remaining()<1&&!this.continueRecord())return 0;let n=this.rest()[0]??0;return this.consume(1),n}u16(){if(this.remaining()>=2){let n=p(this.rest(),0);return this.consume(2),n}return this.u8()|this.u8()<<8}i32(){let n=this.u8(),i=this.u8(),e=this.u8(),t=this.u8();return(n|i<<8|e<<16|t<<24)<<0}get data(){if(this.parts.length===1)return this.parts[0].subarray(this.o);let n=[],i=0;for(let r=this.i;r<this.parts.length;r+=1){let u=r===this.i?this.parts[r].subarray(this.o):this.parts[r];n.push(u),i+=u.length}let e=new Uint8Array(i),t=0;for(let r of n)e.set(r,t),t+=r.length;return e}}function hn(n,i){let e=0;while(e+4<=n.length){let t=p(n,e),r=p(n,e+2);if(e+4+r>n.length)break;let u=n.subarray(e+4,e+4+r);e+=4+r;let s;if(e+4<=n.length&&p(n,e)===60){let l=[];while(e+4<=n.length&&p(n,e)===60){let x=p(n,e+2);if(e+4+x>n.length)break;l.push(n.subarray(e+4,e+4+x)),e+=4+x}s=new Z(t,u,l)}if(i(t,s!==void 0?s.data:u,s)===!1)return}}function p(n,i){return i+1<n.length?n[i]|n[i+1]<<8:0}function R(n,i){if(i+3>=n.length)return 0;return(n[i]|n[i+1]<<8|n[i+2]<<16|n[i+3]<<24)>>>0}function xi(n,i){return R(n,i)<<0}function xn(n,i){if(i+8>n.length)return Number.NaN;return X.setUint32(0,R(n,i),!0),X.setUint32(4,R(n,i+4),!0),X.getFloat64(0,!0)}import{readRels as ci,relsPartFor as yi,resolve as kn}from"@mdgate/containers";import{ConvertError as L}from"@mdgate/core";import{warn as pi}from"@mdgate/utils";var ki="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",Ai="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";function An(n){let i=n.hasPart("xl/workbook.bin")?"xl/workbook.bin":void 0;if(i===void 0)throw L.malformed("unreadable workbook: missing xl/workbook.bin");let e=ci(n,yi(i)),t=gi(n,e,i),r=mi(n,e,i),{sheets:u,is1904:s}=wi(n,e,i),o=[],l=0;for(let x of u)try{let c=Pi(n,x.path,x.name,t,r,s);if(c!==void 0)o.push(c)}catch(c){if(c instanceof L&&c.isFatal())throw c;pi(`skipping unreadable sheet ${JSON.stringify(x.name)}: ${c instanceof Error?c.message:String(c)}`),l+=1}if(u.length>0&&l===u.length)throw L.malformed("no sheet in the workbook could be read");return o}function gi(n,i,e){let t=gn(n,i,e,ki)??"xl/sharedStrings.bin",r=n.optionalPart(t);if(r===void 0)return[];let u=new C(r),s=[];try{u.nextSkipBlocks(159,[],s)}catch{return[]}let o=Uint8Array.from(s),l=o.length>=8?U(o,4):0,x=[];for(let c=0;c<l;c+=1)try{u.nextSkipBlocks(19,[[35,36]],s);let y=Uint8Array.from(s);if(y.length>1)x.push(K(y.subarray(1)))}catch{break}return x}function mi(n,i,e){let t=gn(n,i,e,Ai)??"xl/styles.bin",r=n.optionalPart(t);if(r===void 0)return[];let u=new C(r),s=[],o=new Map,l=[];try{for(;;){let x=u.readType();if(x===void 0)break;if(u.fillBuffer(s),x===615){let c=Uint8Array.from(s),y=yn(c,0);for(let h=0;h<y;h+=1){u.nextSkipBlocks(44,[],s);let f=Uint8Array.from(s);if(f.length<2)continue;let A=cn(f,0);o.set(A,$(K(f.subarray(2))))}}else if(x===617){let c=Uint8Array.from(s),y=yn(c,0);for(let h=0;h<y;h+=1){u.nextSkipBlocks(47,[],s);let f=Uint8Array.from(s),A=f.length>=4?cn(f,2):0,k=T(A);l.push(k==="other"?o.get(A)??"other":k)}break}}}catch{}return l}function wi(n,i,e){let t=n.requiredPart(e),r=new C(t),u=[],s=!1,o=[];for(;;){let l=r.readType();if(l===void 0)break;r.fillBuffer(u);let x=Uint8Array.from(u);if(l===153){if(x.length>0)s=(x[0]&1)!==0}else if(l===156){if(x.length<12)continue;let c=U(x,8);if(c===4294967295)continue;let y=c*2;if(12+y>x.length)continue;let h=new TextDecoder("utf-16le").decode(x.subarray(12,12+y)),f=i.get(h);if(f===void 0||f.mode!=="internal")continue;let A;try{A=f.target.startsWith("/")?f.target.replace(/^\/+/,""):kn(e,f.target).path}catch{continue}let k=K(x.subarray(12+y));o.push({name:k,path:A})}else if(l===144)break}return{sheets:o,is1904:s}}function Pi(n,i,e,t,r,u){let s=n.optionalPart(i);if(s===void 0)return;let o=new C(s),l=[];try{o.nextSkipBlocks(148,[[129,void 0],[147,void 0]],l),o.nextSkipBlocks(145,[[133,134],[37,38],[485,void 0],[390,391]],l)}catch{return}let x=[],c=0;for(;;){let h=o.readType();if(h===void 0)break;o.fillBuffer(l);let f=Uint8Array.from(l);if(h===146)break;if(h===0){if(f.length>=4)c=U(f,0);if(c>1048576)break;continue}let A=Ni(h,f,t,r,u);if(A===void 0||A.kind==="empty")continue;let k=f.length>=4?U(f,0):0;x.push({row:c,col:k,value:A})}let y=W(x);if(y===void 0)return;return{name:e,...y,merges:[]}}function Ni(n,i,e,t,r){let u=Ui(t,i);switch(n){case 2:{if(i.length<12)return;let s=i[8],o=(s&1)!==0,l=(s&2)!==0,x=new Uint8Array(i.subarray(8,12));if(x[0]=x[0]&252,l){let h=Si(x,0)>>2;if(o)return m(h/100,u,r);return z(h,void 0,r)}let c=new Uint8Array(8);c.set(x,4);let y=pn(c,0);return m(o?y/100:y,u,r)}case 3:{if(i.length<9)return;return V(i[8])}case 4:case 10:return{kind:"bool",value:(i[8]??0)!==0};case 5:case 9:return i.length>=16?m(pn(i,8),u,r):void 0;case 6:case 8:return i.length>8?{kind:"string",value:K(i.subarray(8))}:void 0;case 7:{if(i.length<12)return;let s=e[U(i,8)];return s===void 0?void 0:{kind:"string",value:s}}default:return}}function Ui(n,i){if(i.length<7)return;let e=i[4]|i[5]<<8|i[6]<<16;return n[e]}function gn(n,i,e,t){let r=i.firstOfType(t);if(r===void 0)return;try{let u=kn(e,r.target);if(n.hasPart(u.path))return u.path}catch{return}return}class C{bytes;pos=0;constructor(n){this.bytes=n}readType(){if(this.pos>=this.bytes.length)return;let n=this.bytes[this.pos];if(this.pos+=1,(n&128)===128){if(this.pos>=this.bytes.length)return;let i=this.bytes[this.pos];return this.pos+=1,(n&127)+((i&127)<<7)}return n}fillBuffer(n){if(this.pos>=this.bytes.length)return n.length=0,0;let i=this.bytes[this.pos];this.pos+=1;let e=i&127;for(let r=1;r<4&&(i&128)!==0;r+=1){if(this.pos>=this.bytes.length)break;i=this.bytes[this.pos],this.pos+=1,e+=(i&127)<<7*r}let t=Math.min(this.bytes.length,this.pos+e);n.length=0;for(let r=this.pos;r<t;r+=1)n.push(this.bytes[r]);return this.pos=t,n.length}nextSkipBlocks(n,i,e){for(;;){let t=this.readType();if(t===void 0)throw L.malformed("unreadable workbook: truncated xlsb records");let r=this.fillBuffer(e);if(t===n)return r;let u=i.find((s)=>s[0]===t);if(u!==void 0&&u[1]!==void 0){let s=u[1];while(this.readType()!==s)this.fillBuffer(e);this.fillBuffer(e)}}}}function K(n){if(n.length<4)return"";let i=U(n,0),e=Math.min(n.length,4+i*2);return new TextDecoder("utf-16le").decode(n.subarray(4,e))}function cn(n,i){return n[i]|n[i+1]<<8}function U(n,i){return(n[i]|n[i+1]<<8|n[i+2]<<16|n[i+3]<<24)>>>0}function yn(n,i){return U(n,i)}function Si(n,i){let e=U(n,i);return e>2147483647?e-4294967296:e}function pn(n,i){if(i+8>n.length)return Number.NaN;return new DataView(n.buffer,n.byteOffset+i,8).getFloat64(0,!0)}import{parseXml as Fi,readRels as mn,relsPartFor as Ii,relType as Wi,resolve as M}from"@mdgate/containers";import{ConvertError as j}from"@mdgate/core";import{warn as b}from"@mdgate/utils";var $i="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings",Xi="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles";function B(n){let i=Ri(n),e=[],t=0;for(let r of i.sheets)try{let u=Gi(n,r.path,r.name,i);if(u!==void 0)e.push(u)}catch(u){if(u instanceof j&&u.isFatal())throw u;b(`skipping unreadable sheet ${JSON.stringify(r.name)}: ${u instanceof Error?u.message:String(u)}`),t+=1}if(i.sheets.length>0&&t===i.sheets.length)throw j.malformed("no sheet in the workbook could be read");return e}function Ri(n){let e=mn(n,"_rels/.rels").firstOfType(Wi.OFFICE_DOCUMENT),t="xl/workbook.xml";if(e!==void 0)try{t=M("",e.target).path}catch{}let r=[],u=[],s=!1,o=[],l=mn(n,Ii(t)),x=wn(n,l,t,$i)??Pn(t,"sharedStrings.xml"),c=wn(n,l,t,Xi)??Pn(t,"styles.xml"),y=n.optionalXmlPart(x);if(y!==void 0)Vi(y,r);let h=n.optionalXmlPart(c);if(h!==void 0)Ci(h,u);let f=n.optionalXmlPart(t);if(f!==void 0)s=Nn(f,l,t,o);else if(n.hasPart(t)===!1&&n.hasPart("xl/workbook.xml")){let A=n.optionalXmlPart("xl/workbook.xml");if(A!==void 0)s=Nn(A,l,"xl/workbook.xml",o)}return{sheets:o,strings:r,formats:u,is1904:s}}function wn(n,i,e,t){let r=i.firstOfType(t);if(r===void 0)return;try{let u=M(e,r.target);if(n.hasPart(u.path))return u.path}catch{return}return}function Pn(n,i){let e=n.lastIndexOf("/");return e<0?i:`${n.slice(0,e+1)}${i}`}function Nn(n,i,e,t){let r=!1,u=P(n,"workbook")??n;for(let o of u.childElems())if(o.local==="workbookPr"){let l=o.attrAny("date1904");r=l==="1"||l==="true"}let s=P(u,"sheets");if(s===void 0)return r;for(let o of s.childElems()){if(o.local!=="sheet")continue;let l=o.attrAny("name"),x=o.attrAny("id");if(l===void 0||x===void 0)continue;let c=i.internalTarget(x);if(c===void 0){b(`skipping sheet ${JSON.stringify(l)}: missing worksheet relationship`);continue}let y;try{y=c.startsWith("/")?c.replace(/^\/+/,""):M(e,c).path}catch(h){b(`skipping sheet ${JSON.stringify(l)}: ${h instanceof Error?h.message:String(h)}`);continue}t.push({name:l,path:y})}return r}function Vi(n,i){let e=P(n,"sst")??n;for(let t of e.childElems()){if(t.local!=="si")continue;i.push(Sn(t))}}function Sn(n){let i="",e=!1,t=(r,u)=>{if(r.local==="rPh")return;if(r.local==="t"&&!u){e=!0;let s=r.attr("http://www.w3.org/XML/1998/namespace","space")==="preserve",o=r.text();i+=s?o:Ji(o);return}for(let s of r.childElems())t(s,u||r.local==="rPh")};return t(n,!1),e?i:""}function Ji(n){let i=0,e=n.length;while(i<e&&Un(n.charCodeAt(i)))i+=1;while(e>i&&Un(n.charCodeAt(e-1)))e-=1;return n.slice(i,e)}function Un(n){return n===32||n===9||n===10||n===13}function Ci(n,i){let e=P(n,"styleSheet")??n,t=new Map,r=P(e,"numFmts");if(r!==void 0)for(let s of r.childElems()){if(s.local!=="numFmt")continue;let o=s.attrAny("numFmtId"),l=s.attrAny("formatCode");if(o!==void 0&&l!==void 0)t.set(o,l)}let u=P(e,"cellXfs");if(u===void 0)return;for(let s of u.childElems()){if(s.local!=="xf")continue;let o=s.attrAny("numFmtId");if(o===void 0){i.push("other");continue}let l=t.get(o);i.push(l!==void 0?$(l):rn(o))}}function Gi(n,i,e,t){let r=n.optionalPart(i);if(r===void 0)return;let u;try{u=Fi(r)}catch(y){if(y instanceof j&&y.isFatal())throw y;throw y}let s=P(u,"worksheet")??u,o=P(s,"sheetData");if(o===void 0)return;let l=[];for(let y of o.childElems()){if(y.local!=="row")continue;let h,f=y.attrAny("r");if(f!==void 0){let k=Number.parseInt(f,10);if(Number.isFinite(k)&&k>0)h=k-1}let A=0;for(let k of y.childElems()){if(k.local!=="c")continue;let g=Q(k.attrAny("r")),N=g?.row??h??0,F=g?.col??A;A=F+1;let G=Oi(k,t);if(G.kind==="empty")continue;l.push({row:N,col:F,value:G})}}let x=W(l);if(x===void 0)return;let c=[];try{let y=P(s,"mergeCells");if(y!==void 0)for(let h of y.childElems()){if(h.local!=="mergeCell")continue;let f=h.attrAny("ref");if(f===void 0)continue;let A=Di(f);if(A!==void 0)c.push(A)}}catch(y){b(`skipping unreadable merged-region list for ${JSON.stringify(e)}: ${y instanceof Error?y.message:String(y)}`)}return{name:e,...x,merges:c}}function Oi(n,i){let e=n.attrAny("t"),t=n.attrAny("s"),r="other";if(t!==void 0){let o=Number.parseInt(t,10);r=Number.isFinite(o)?i.formats[o]:void 0}let u,s;for(let o of n.childElems())if(o.local==="is")u=Sn(o);else if(o.local==="v")s=o.text();if(e==="inlineStr"||e==="is")return u===void 0?{kind:"empty"}:{kind:"string",value:u};if(u!==void 0&&s===void 0)return{kind:"string",value:u};if(s===void 0)return{kind:"empty"};switch(e){case"s":{if(s.length===0)return{kind:"empty"};let o=Number.parseInt(s,10),l=Number.isFinite(o)?i.strings[o]:void 0;return l===void 0?{kind:"empty"}:{kind:"string",value:l}}case"b":return{kind:"bool",value:s!=="0"};case"d":return{kind:"datetimeIso",value:s};case"e":return _(s);case"str":return{kind:"string",value:s};case"n":case void 0:{if(s.length===0)return{kind:"empty"};let o=Number.parseFloat(s);if(Number.isFinite(o)||o===Number.POSITIVE_INFINITY||o===Number.NEGATIVE_INFINITY)return m(o,r,i.is1904);if(e===void 0)return{kind:"string",value:s};return{kind:"empty"}}default:return{kind:"empty"}}}function Q(n){if(n===void 0||n.length===0)return;let i=0,e=0,t=0;while(i<n.length){let r=n.charCodeAt(i);if(r>=65&&r<=90)e=e*26+(r-64);else if(r>=97&&r<=122)e=e*26+(r-96);else if(r>=48&&r<=57){t=r-48,i+=1;break}else return;i+=1}while(i<n.length){let r=n.charCodeAt(i);if(r<48||r>57)return;t=t*10+(r-48),i+=1}if(t<1||e<1)return;return{row:t-1,col:e-1}}function Di(n){let i=n.indexOf(":");if(i<0){let r=Q(n);return r===void 0?void 0:{start:[r.row,r.col],end:[r.row,r.col]}}let e=Q(n.slice(0,i)),t=Q(n.slice(i+1));if(e===void 0||t===void 0)return;return{start:[e.row,e.col],end:[t.row,t.col]}}function P(n,i){return n.childElems().find((e)=>e.local===i)}function Fn(n){try{return tn(Li(n))}catch(i){throw E(i)}}function Li(n){if(qi(n)){let e;try{e=zi.open(n)}catch(t){throw E(t)}if(e.exists("EncryptionInfo")||e.exists("EncryptedPackage"))throw S.encrypted();return ln(e)}if(!Ki(n))throw S.malformed("unreadable workbook: Cannot detect file format");let i;try{i=Ti.open(n)}catch(e){let t=Zi(n);if(t!==void 0)throw t;throw E(e)}if(i.hasPart("xl/workbook.xml"))return B(i);if(i.hasPart("xl/workbook.bin"))return An(i);return B(i)}function Ki(n){return n.length>=4&&n[0]===80&&n[1]===75&&n[2]===3&&n[3]===4}function E(n){if(n instanceof S){if(n.code==="encrypted"||n.isFatal()||n.code==="io")return n;if(n.code==="malformed"){if(n.message.toLowerCase().includes("password"))return S.encrypted();if(n.message.startsWith("malformed document: unreadable workbook:"))return n;if(n.message.startsWith("malformed document: no sheet"))return n;return S.malformed(`unreadable workbook: ${n.detail??n.message}`)}return n}let i=n instanceof Error?n.message:String(n);if(i.toLowerCase().includes("password"))return S.encrypted();return S.malformed(`unreadable workbook: ${i}`)}var ji=new Set(["xlsx","xlsm","xlsb","xls","xltx","xltm","xlt"]);function v(){return{id:"xlsx",sniff(n,i){if(bi(n)==="xlsx"||Qi(n)==="xls")return 2;if(i?.path!==void 0&&ji.has(Yi(i.path)??""))return 1;return 0},convert(n){return{markdown:Hi(Fn(n))}}}}var Bi=Mi([v()]);function Ei(n,i){return Bi(n,i)}export{v as xlsx,Ei as toMarkdown};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mdgate/xlsx",
3
- "version": "0.4.1",
3
+ "version": "0.5.1",
4
4
  "description": "mdgate Excel converter (xlsx/xlsm/xlsb/xls)",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -22,10 +22,10 @@
22
22
  "prepublishOnly": "bun run build"
23
23
  },
24
24
  "dependencies": {
25
- "@mdgate/containers": "0.4.1",
26
- "@mdgate/core": "0.4.1",
27
- "@mdgate/document": "0.4.1",
28
- "@mdgate/utils": "0.4.1"
25
+ "@mdgate/containers": "0.5.1",
26
+ "@mdgate/core": "0.5.1",
27
+ "@mdgate/document": "0.5.1",
28
+ "@mdgate/utils": "0.5.1"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"