@mdgate/xlsx 0.1.0 → 0.4.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/README.md +1 -1
- package/dist/index.js +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{create as vi}from"@mdgate/core";import{detectOleDoc as bi,detectZipDoc as Mi}from"@mdgate/containers";import{documentToMarkdown as ji}from"@mdgate/document";import{fileExtension as Bi}from"@mdgate/utils";import{CompoundFile as Di,hasOleMagic as Oi,Package as Yi,probeOle as Hi}from"@mdgate/containers";import{ConvertError as F}from"@mdgate/core";import{ConvertError as Q}from"@mdgate/core";import{emptyDocument as Tn,heading as Dn,MAX_EXPANSION as On,plain as tn,resolveHeaderRows as Yn}from"@mdgate/document";import{warn as Hn}from"@mdgate/utils";import{cleanText as Vn}from"@mdgate/utils";var W={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 rn(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 Ln(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 r=e[1]==="-"?"-":"",t=e[2]+(e[3]??""),s=1+Number(e[4]);if(s<=0)return`${r}0.${"0".repeat(-s)}${t}`;if(s>=t.length)return`${r}${t}${"0".repeat(s-t.length)}`;let u=t.slice(0,s),l=t.slice(s);return`${r}${u}.${l}`}function Rn(n){let i=Math.round(Math.abs(n)*86400)%86400,e=Math.floor(i/3600),r=Math.floor(i%3600/60),t=i%60;return`${P(e)}:${P(r)}:${P(t)}`}function qn(n){let i=n<0?"-":"",e=Math.round(Math.abs(n)*86400),r=Math.floor(e/3600),t=Math.floor(e%3600/60),o=e%60;return`${i}${r}:${P(t)}:${P(o)}`}var zn=1462,Cn=86400000,Zn=Date.UTC(1899,11,30);function Ln(n,i){let e=i?n+zn:n;if(e<60)e+=1;let r=Math.round(e*Cn),t=Zn+r;if(!Number.isFinite(t))return;let o=new Date(t);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 $(n){if(n.length===0)return;let i=Number.POSITIVE_INFINITY,e=0,r=Number.POSITIVE_INFINITY,t=0;for(let l of n){if(l.row<i)i=l.row;if(l.row>e)e=l.row;if(l.col<r)r=l.col;if(l.col>t)t=l.col}let o=t-r+1,s=e-i+1,u=Array(o*s).fill(W);for(let l of n){let y=(l.row-i)*o+(l.col-r);if(y>=0&&y<u.length)u[y]=l.value}return{start:[i,r],height:s,width:o,values:u}}function un(n){let i=Tn(),e=n.length>1,r=0,t=0;for(let o of n){if(t+=1,o.height===0||o.width===0||o.values.length===0)continue;try{let s=Kn(o);if(s===void 0)continue;if(e)i.blocks.push(Dn(2,[tn(o.name)]));i.blocks.push({type:"table",table:s})}catch(s){if(s instanceof Q&&s.isFatal())throw s;Hn(`skipping unreadable sheet ${JSON.stringify(o.name)}: ${s instanceof Error?s.message:String(s)}`),r+=1}}if(t>0&&r===t&&i.blocks.length===0)throw Q.malformed("no sheet in the workbook could be read");return i}function Kn(n){let{start:i,height:e,width:r,values:t,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]),p=Math.min(x.end[0]+1,i[0]+e),g=Math.min(x.end[1]+1,i[1]+r);if(h>=p||f>=g)continue;let A=h-i[0],m=f-i[1],I=p-i[0],S=g-i[1];if(I-A===1&&S-m===1)continue;let _=S-m,a=I-A;if(c+=BigInt(_)*BigInt(a)-1n,c>BigInt(On))throw Q.resourceLimit("max_expansion","table span expansion exceeds the content budget");s.set(L(A,m),[_,a]);for(let z=A;z<I;z+=1)for(let C=m;C<S;C+=1)if(z!==A||C!==m)u.set(L(z,C),[A,m])}}let l=Array(e);for(let c=0;c<e;c+=1){let x=Array(r),h=c*r;for(let f=0;f<r;f+=1){let p=u?.get(L(c,f));if(p!==void 0){x[f]={type:"covered",originRow:p[0],originCol:p[1]};continue}let g=t[h+f]??W,A=g.kind==="empty"?"":rn(g),m=s?.get(L(c,f));x[f]={type:"origin",cell:{blocks:A.length===0?[]:[{type:"paragraph",inlines:[tn(A)]}],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=Yn(y,0),y}function L(n,i){return n*65536+i}import{MAX_RECORDS as sn,readOleStream as Qn}from"@mdgate/containers";import{ConvertError as J}from"@mdgate/core";import{decode as bn,encodingExists as Mn,warn as b}from"@mdgate/utils";function V(n){let i=!1,e=!1,r=0,t=" ",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==="[")r+=1;else if(u==="]"&&r===1&&o)return"timedelta";else if(u==="]")r=Math.max(0,r-1);else if((u==="a"||u==="A")&&!s&&r===0)s=!0;else if((u==="p"||u==="m"||u==="/"||u==="P"||u==="M")&&s&&r===0)return"datetime";else if(!s&&r===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()===t.toLowerCase());else o=t==="["&&(u==="m"||u==="h"||u==="s"||u==="M"||u==="H"||u==="S");t=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 T(n){if(n>=14&&n<=22||n===45||n===47)return"datetime";if(n===46)return"timedelta";return"other"}var hn=new TextDecoder("latin1"),jn=new TextDecoder("utf-8"),Bn=new TextDecoder("utf-16le"),En=new TextDecoder("utf-16be"),X=new DataView(new ArrayBuffer(8));function xn(n){let i=vn(n),e=8,r=ln(1200),t=!1,o=[],s=[],u=new Map,l=[];yn(i,(h,f,p)=>{switch(h){case 47:if(k(f,0)!==0)throw J.encrypted();break;case 66:r=ln(k(f,0));break;case 34:if(k(f,0)===1)t=!0;break;case 1054:{let g=li(f,r,e);if(g!==void 0)u.set(g.ifmt,g.format);break}case 224:if(f.length>=4)l.push(k(f,2));break;case 133:{let g=si(p??new D(h,f,[]),r,e);if(g!==void 0)o.push(g);break}case 2057:{let g=oi(f);if(g!==void 0)e=g;break}case 252:s.push(...fi(p??new D(h,f,[]),r));break;default:break}if(h===10&&o.length>0)return"count";return});let y=l.map((h)=>u.get(h)??T(h)),c=[],x=0;for(let h of o){if(h.pos>=i.length){b(`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,r,e,s,y,t);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;b(`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 Qn(n,i);throw J.malformed("unreadable workbook: Cannot find Workbook stream")}function dn(n,i,e,r,t,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=ri(h,e,r);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=M(h,e,r);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=ti(h,t);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=k(h,0),p=k(h,2),g=o[k(h,4)];y=[f,p];let A=ui(h.subarray(6,14),g,s);if(A!==void 0&&A.kind!=="empty")u.push({row:f,col:p,value:A});break}case 10:return!1;default:break}return});let c=$(u);if(c===void 0)return;return{name:i,...c,merges:l}}function _n(n,i,e){if(n.length<14)return;let r=k(n,0),t=k(n,2),o=i[k(n,4)],s=kn(n,6);return{row:r,col:t,value:w(s,o,e)}}function an(n){if(n.length<8)return;let i=k(n,0),e=k(n,2);if(n[7]===0)return{row:i,col:e,value:{kind:"bool",value:n[6]!==0}};if(n[7]===1){let r=R(n[6]);return r===void 0?void 0:{row:i,col:e,value:r}}return}function ni(n,i,e){if(n.length<10)return;return{row:k(n,0),col:k(n,2),value:cn(n.subarray(4,10),i,e)}}function ii(n,i,e,r){if(n.length<6)return;let t=k(n,0),o=k(n,2),s=k(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:t,col:u,value:cn(n.subarray(l,l+6),e,r)}),u+=1}function cn(n,i,e){let r=(n[2]&1)!==0,t=(n[2]&2)!==0,o=i[k(n,0)];if(t){let u=ki(n,2)>>2;if(r&&u%100!==0)return w(u/100,o,e);return Z(r?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(r?s/100:s,o,e)}function ei(n,i){if(n.length<2)return;let e=k(n,0);for(let r=0;r<e;r+=1){let t=2+r*8;if(t+8>n.length)break;i.push({start:[k(n,t),k(n,t+4)],end:[k(n,t+2),k(n,t+6)]})}}function ri(n,i,e){if(n.length<6)return;let r=M(n.subarray(6),i,e);if(r===void 0)return;return{row:k(n,0),col:k(n,2),value:{kind:"string",value:r}}}function ti(n,i){if(n.length<10)return;let e=G(n,6),r=i[e];if(r===void 0)return;return{row:k(n,0),col:k(n,2),value:{kind:"string",value:r}}}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])??W;case 3:return{kind:"string",value:""};default:return W}return w(kn(n,0),i,e)}function oi(n){if(n.length<2)return;let i=k(n,0),e=n.length>=4?k(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 r=G(n.data,0);n.consume(6);let t=ci(n,i,e);if(t===void 0)return;return{pos:r,name:t.replace(/\0/g,"")}}function li(n,i,e){if(n.length<2)return;let r=k(n,0);if(!(r>=5&&r<=8||r>=23&&r<=26||r>=41&&r<=44||r>=63&&r<=66||r>=164&&r<=382)){b(`skipping invalid number format id ${r}`);return}let o=M(n.subarray(2),i,e);if(o===void 0)return;return{ifmt:r,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(),r=n.u8(),t=(r&1)!==0,o=0,s=0;if((r&8)!==0){if(n.remaining()<2&&!n.continueRecord())return"";o=n.u16()}if((r&4)!==0){if(n.remaining()<4&&!n.continueRecord())return"";s=n.i32()}let u=xi(i,e,n,t);return n.skip(o*4),n.skip(Math.max(0,s)),u}function xi(n,i,e,r){let t=i,o=r,s="";while(t>0){let{chars:u,decoded:l,bytes:y}=n.decodeTo(e.rest(),t,o);if(e.consume(y),s+=u,t-=l,t>0){if(!e.continueRecord())break;if(e.remaining()<1)break;o=(e.u8()&1)!==0}}return s}function ci(n,i,e){let r=e===8;if(n.remaining()<(r?2:1))return;let t=n.u8(),o;if(r)o=(n.u8()&1)!==0;let s=i.decodeTo(n.rest(),t,o);return n.consume(s.bytes),s.chars}function M(n,i,e){let r=e===8?3:2;if(n.length<r){if(n.length===2&&k(n,0)===0)return"";return}let t=k(n,0),o=e===8?(n[2]&1)!==0:void 0;return i.decodeTo(n.subarray(r),t,o).chars}function ln(n){let i=yi(n),e=i!=="utf16-le"&&i!=="utf16-be"&&i!=="utf8";return{name:i,decodeTo(r,t,o){let s=o??(i==="utf8"||e?void 0:!1);if(s===void 0){let l=Math.min(r.length,t);return{chars:fn(r.subarray(0,l),i),decoded:l,bytes:l}}if(s===!1){let l=Math.min(r.length,t);return{chars:hn.decode(r.subarray(0,l)),decoded:l,bytes:l}}let u=Math.min(Math.floor(r.length/2),t);return{chars:fn(r.subarray(0,2*u),"utf16-le"),decoded:u,bytes:2*u}}}}function fn(n,i){if(i==="utf8")return jn.decode(n);if(i==="utf16-le")return Bn.decode(n);if(i==="utf16-be")return En.decode(n);if(Mn(i))return bn(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 D{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=k(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(),r=this.u8();return(n|i<<8|e<<16|r<<24)<<0}get data(){if(this.parts.length===1)return this.parts[0].subarray(this.o);let n=[],i=0;for(let t=this.i;t<this.parts.length;t+=1){let o=t===this.i?this.parts[t].subarray(this.o):this.parts[t];n.push(o),i+=o.length}let e=new Uint8Array(i),r=0;for(let t of n)e.set(t,r),r+=t.length;return e}}function yn(n,i){let e=0,r=0,t=!1;while(e+4<=n.length){let o=k(n,e),s=k(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&&k(n,e)===60){let c=[];while(e+4<=n.length&&k(n,e)===60){let x=k(n,e+2);if(e+4+x>n.length)break;c.push(n.subarray(e+4,e+4+x)),e+=4+x}l=new D(o,u,c)}if(r+=1,r>sn)throw J.resourceLimit("max_records",`workbook stream exceeds ${sn} records`);if(t)continue;let y=i(o,l!==void 0?l.data:u,l);if(y===!1)return;if(y==="count")t=!0}}function k(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 ki(n,i){return G(n,i)<<0}function kn(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 pi,relsPartFor as gi,resolve as mn}from"@mdgate/containers";import{ConvertError as O}from"@mdgate/core";import{warn as Ai}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=pi(n,gi(i)),r=Pi(n,e,i),t=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,r,t,s);if(c!==void 0)u.push(c)}catch(c){if(c instanceof O&&c.isFatal())throw c;Ai(`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 r=Pn(n,i,e,mi)??"xl/sharedStrings.bin",t=n.optionalPart(r);if(t===void 0)return[];let o=new q(t),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(Y(x.subarray(1)))}catch{break}return y}function Ni(n,i,e){let r=Pn(n,i,e,wi)??"xl/styles.bin",t=n.optionalPart(r);if(t===void 0)return[];let o=new q(t),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=gn(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 p=pn(f,0);u.set(p,V(Y(f.subarray(2))))}}else if(y===617){let c=Uint8Array.from(s),x=gn(c,0);for(let h=0;h<x;h+=1){o.nextSkipBlocks(47,[],s);let f=Uint8Array.from(s),p=f.length>=4?pn(f,2):0,g=T(p);l.push(g==="other"?u.get(p)??"other":g)}break}}}catch{}return l}function Ui(n,i,e){let r=n.requiredPart(e),t=new q(r),o=[],s=!1,u=[];for(;;){let l=t.readType();if(l===void 0)break;t.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 p;try{p=f.target.startsWith("/")?f.target.replace(/^\/+/,""):mn(e,f.target).path}catch{continue}let g=Y(y.subarray(12+x));u.push({name:g,path:p})}else if(l===144)break}return{sheets:u,is1904:s}}function Fi(n,i,e,r,t,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 p=Ii(h,f,r,t,o);if(p===void 0||p.kind==="empty")continue;let g=f.length>=4?U(f,0):0;y.push({row:c,col:g,value:p})}let x=$(y);if(x===void 0)return;return{name:e,...x,merges:[]}}function Ii(n,i,e,r,t){let o=Si(r,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=Wi(y,0)>>2;if(u)return w(h/100,o,t);return Z(h,void 0,t)}let c=new Uint8Array(8);c.set(y,4);let x=An(c,0);return w(u?x/100:x,o,t)}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(An(i,8),o,t):void 0;case 6:case 8:return i.length>8?{kind:"string",value:Y(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 Si(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,r){let t=i.firstOfType(r);if(t===void 0)return;try{let o=mn(e,t.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 t=1;t<4&&(i&128)!==0;t+=1){if(this.pos>=this.bytes.length)break;i=this.bytes[this.pos],this.pos+=1,e+=(i&127)<<7*t}let r=Math.min(this.bytes.length,this.pos+e);n.length=0;for(let t=this.pos;t<r;t+=1)n.push(this.bytes[t]);return this.pos=r,n.length}nextSkipBlocks(n,i,e){for(;;){let r=this.readType();if(r===void 0)throw O.malformed("unreadable workbook: truncated xlsb records");let t=this.fillBuffer(e);if(r===n)return t;let o=i.find((s)=>s[0]===r);if(o!==void 0&&o[1]!==void 0){let s=o[1];while(this.readType()!==s)this.fillBuffer(e);this.fillBuffer(e)}}}}function Y(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 pn(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 gn(n,i){return U(n,i)}function Wi(n,i){let e=U(n,i);return e>2147483647?e-4294967296:e}function An(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 $i,readRels as Nn,relsPartFor as Vi,relType as Ji,resolve as B}from"@mdgate/containers";import{ConvertError as j}from"@mdgate/core";import{warn as K}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=[],r=0;for(let t of i.sheets)try{let o=Zi(n,t.path,t.name,i);if(o!==void 0)e.push(o)}catch(o){if(o instanceof j&&o.isFatal())throw o;K(`skipping unreadable sheet ${JSON.stringify(t.name)}: ${o instanceof Error?o.message:String(o)}`),r+=1}if(i.sheets.length>0&&r===i.sheets.length)throw j.malformed("no sheet in the workbook could be read");return e}function Ri(n){let e=Nn(n,"_rels/.rels").firstOfType(Ji.OFFICE_DOCUMENT),r="xl/workbook.xml";if(e!==void 0)try{r=B("",e.target).path}catch{}let t=[],o=[],s=!1,u=[],l=Nn(n,Vi(r)),y=Un(n,l,r,Xi)??Fn(r,"sharedStrings.xml"),c=Un(n,l,r,Gi)??Fn(r,"styles.xml"),x=n.optionalXmlPart(y);if(x!==void 0)qi(x,t);let h=n.optionalXmlPart(c);if(h!==void 0)Ci(h,o);let f=n.optionalXmlPart(r);if(f!==void 0)s=In(f,l,r,u);else if(n.hasPart(r)===!1&&n.hasPart("xl/workbook.xml")){let p=n.optionalXmlPart("xl/workbook.xml");if(p!==void 0)s=In(p,l,"xl/workbook.xml",u)}return{sheets:u,strings:t,formats:o,is1904:s}}function Un(n,i,e,r){let t=i.firstOfType(r);if(t===void 0)return;try{let o=B(e,t.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,r){let t=!1,o=N(n,"workbook")??n;for(let u of o.childElems())if(u.local==="workbookPr"){let l=u.attrAny("date1904");t=l==="1"||l==="true"}let s=N(o,"sheets");if(s===void 0)return t;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){K(`skipping sheet ${JSON.stringify(l)}: missing worksheet relationship`);continue}let x;try{x=c.startsWith("/")?c.replace(/^\/+/,""):B(e,c).path}catch(h){K(`skipping sheet ${JSON.stringify(l)}: ${h instanceof Error?h.message:String(h)}`);continue}r.push({name:l,path:x})}return t}function qi(n,i){let e=N(n,"sst")??n;for(let r of e.childElems()){if(r.local!=="si")continue;i.push(Wn(r))}}function Wn(n){let i="",e=!1,r=(t,o)=>{if(t.local==="rPh")return;if(t.local==="t"&&!o){e=!0;let s=t.attr("http://www.w3.org/XML/1998/namespace","space")==="preserve",u=t.text();i+=s?u:zi(u);return}for(let s of t.childElems())r(s,o||t.local==="rPh")};return r(n,!1),e?i:""}function zi(n){let i=0,e=n.length;while(i<e&&Sn(n.charCodeAt(i)))i+=1;while(e>i&&Sn(n.charCodeAt(e-1)))e-=1;return n.slice(i,e)}function Sn(n){return n===32||n===9||n===10||n===13}function Ci(n,i){let e=N(n,"styleSheet")??n,r=new Map,t=N(e,"numFmts");if(t!==void 0)for(let s of t.childElems()){if(s.local!=="numFmt")continue;let u=s.attrAny("numFmtId"),l=s.attrAny("formatCode");if(u!==void 0&&l!==void 0)r.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=r.get(u);i.push(l!==void 0?V(l):on(u))}}function Zi(n,i,e,r){let t=n.optionalPart(i);if(t===void 0)return;let o;try{o=$i(t)}catch(x){if(x instanceof j&&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 g=Number.parseInt(f,10);if(Number.isFinite(g)&&g>0)h=g-1}let p=0;for(let g of x.childElems()){if(g.local!=="c")continue;let A=H(g.attrAny("r")),m=A?.row??h??0,I=A?.col??p;p=I+1;let S=Li(g,r);if(S.kind==="empty")continue;l.push({row:m,col:I,value:S})}}let y=$(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 p=Ti(f);if(p!==void 0)c.push(p)}}catch(x){K(`skipping unreadable merged-region list for ${JSON.stringify(e)}: ${x instanceof Error?x.message:String(x)}`)}return{name:e,...y,merges:c}}function Li(n,i){let e=n.attrAny("t"),r=n.attrAny("s"),t="other";if(r!==void 0){let u=Number.parseInt(r,10);t=Number.isFinite(u)?i.formats[u]:void 0}let o,s;for(let u of n.childElems())if(u.local==="is")o=Wn(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,t,i.is1904);if(e===void 0)return{kind:"string",value:s};return{kind:"empty"}}default:return{kind:"empty"}}}function H(n){if(n===void 0||n.length===0)return;let i=0,e=0,r=0;while(i<n.length){let t=n.charCodeAt(i);if(t>=65&&t<=90)e=e*26+(t-64);else if(t>=97&&t<=122)e=e*26+(t-96);else if(t>=48&&t<=57){r=t-48,i+=1;break}else return;i+=1}while(i<n.length){let t=n.charCodeAt(i);if(t<48||t>57)return;r=r*10+(t-48),i+=1}if(r<1||e<1)return;return{row:r-1,col:e-1}}function Ti(n){let i=n.indexOf(":");if(i<0){let t=H(n);return t===void 0?void 0:{start:[t.row,t.col],end:[t.row,t.col]}}let e=H(n.slice(0,i)),r=H(n.slice(i+1));if(e===void 0||r===void 0)return;return{start:[e.row,e.col],end:[r.row,r.col]}}function N(n,i){return n.childElems().find((e)=>e.local===i)}function $n(n){try{return un(Ki(n))}catch(i){throw v(i)}}function Ki(n){if(Oi(n)){let e;try{e=Di.open(n)}catch(r){throw v(r)}if(e.exists("EncryptionInfo")||e.exists("EncryptedPackage"))throw F.encrypted();return xn(e)}if(!Qi(n))throw F.malformed("unreadable workbook: Cannot detect file format");let i;try{i=Yi.open(n)}catch(e){let r=Hi(n);if(r!==void 0)throw r;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 Qi(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"]);function d(){return{id:"xlsx",sniff(n,i){if(Mi(n)==="xlsx"||bi(n)==="xls")return 2;if(i?.path!==void 0&&Ei.has(Bi(i.path)??""))return 1;return 0},convert(n){return{markdown:ji($n(n))}}}}var di=vi([d()]);function _i(n,i){return di(n,i)}export{d as xlsx,_i as toMarkdown};
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/xlsx",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.4.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.1
|
|
26
|
-
"@mdgate/core": "0.1
|
|
27
|
-
"@mdgate/document": "0.1
|
|
28
|
-
"@mdgate/utils": "0.1
|
|
25
|
+
"@mdgate/containers": "0.4.1",
|
|
26
|
+
"@mdgate/core": "0.4.1",
|
|
27
|
+
"@mdgate/document": "0.4.1",
|
|
28
|
+
"@mdgate/utils": "0.4.1"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public"
|