@mdgate/xlsx 0.6.5 → 0.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +11 -5
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
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:throw J.encrypted();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,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdgate/xlsx",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "mdgate Excel converter (xlsx/xlsm/xlsb/xls)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://demo.mdgate.dev",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/mdgate/converters.git",
|
|
11
|
+
"directory": "packages/xlsx"
|
|
12
|
+
},
|
|
7
13
|
"sideEffects": false,
|
|
8
14
|
"exports": {
|
|
9
15
|
".": {
|
|
@@ -22,10 +28,10 @@
|
|
|
22
28
|
"prepublishOnly": "bun run build"
|
|
23
29
|
},
|
|
24
30
|
"dependencies": {
|
|
25
|
-
"@mdgate/containers": "0.6.
|
|
26
|
-
"@mdgate/core": "0.6.
|
|
27
|
-
"@mdgate/document": "0.6.
|
|
28
|
-
"@mdgate/utils": "0.6.
|
|
31
|
+
"@mdgate/containers": "0.6.7",
|
|
32
|
+
"@mdgate/core": "0.6.7",
|
|
33
|
+
"@mdgate/document": "0.6.7",
|
|
34
|
+
"@mdgate/utils": "0.6.7"
|
|
29
35
|
},
|
|
30
36
|
"publishConfig": {
|
|
31
37
|
"access": "public"
|