filens-preview 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -7
- package/dist/all-in-one/THIRD-PARTY-NOTICES.txt +870 -0
- package/dist/all-in-one/filens.js +5069 -114897
- package/dist/index.d.ts +2 -0
- package/dist/split/THIRD-PARTY-NOTICES.txt +870 -0
- package/dist/split/chunks/archive-haip2eOP.js +1 -0
- package/dist/split/chunks/browser-video-session-C_14e_mG.js +1 -0
- package/dist/split/chunks/cad-5oTkbaDV.js +7 -0
- package/dist/split/chunks/core-EjELrtsP.js +17 -0
- package/dist/split/chunks/diagram-BRcdlitF.js +1 -0
- package/dist/split/chunks/docx-I39iDYpR.js +1 -0
- package/dist/split/chunks/ebook-BRfadCGl.js +5 -0
- package/dist/split/chunks/index-C4jdVbDq.js +1 -0
- package/dist/split/chunks/index-DkF8PBGR.js +1 -0
- package/dist/split/chunks/iwork-DXq9Adf7.js +4 -0
- package/dist/split/chunks/media-runtime-B6322raw.js +1 -0
- package/dist/split/chunks/mindmap-CyR3TRfx.js +1 -0
- package/dist/split/chunks/model3d-BEt6INTt.js +55 -0
- package/dist/split/chunks/mp4box.all-Bw_Tlr0T-D0URDfA1.js +1 -0
- package/dist/split/chunks/panorama-ChsqnvWC.js +973 -0
- package/dist/split/chunks/pdf-Dzzffz3p.js +12 -0
- package/dist/split/chunks/vendor-C1aIdQ-w.js +4115 -0
- package/dist/split/chunks/xlsx-CITQo0Od.js +3 -0
- package/dist/split/converter-image.wasm +0 -0
- package/dist/split/filens.js +2 -5012
- package/package.json +1 -1
- package/dist/split/chunks/archive-B4jVwD9o.js +0 -921
- package/dist/split/chunks/cad-DMg-lGJX.js +0 -2405
- package/dist/split/chunks/core--zVW212C.js +0 -14627
- package/dist/split/chunks/diagram-CDwCA6LZ.js +0 -654
- package/dist/split/chunks/docx-CuQfFJqr.js +0 -299
- package/dist/split/chunks/ebook-CLlJ8KX3.js +0 -623
- package/dist/split/chunks/iwork-dNVC0X8j.js +0 -772
- package/dist/split/chunks/media-runtime-gcsBQMuo.js +0 -48
- package/dist/split/chunks/mindmap-g0-VoK-K.js +0 -560
- package/dist/split/chunks/model3d-1G1CC52V.js +0 -5093
- package/dist/split/chunks/panorama-D7GVivtM.js +0 -5972
- package/dist/split/chunks/pdf-CecYOWld.js +0 -17898
- package/dist/split/chunks/vendor-DPFNKNkh.js +0 -59575
- package/dist/split/chunks/xlsx-Co26yo-R.js +0 -818
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var K=Object.defineProperty;var Q=(t,e,r)=>e in t?K(t,e,{enumerable:true,configurable:true,writable:true,value:r}):t[e]=r;var v=(t,e,r)=>Q(t,typeof e!="symbol"?e+"":e,r);import{o as ee,i as W,j as te,c as re,a as se,d as ne,k as ie,g as oe,l as ae}from"./core-EjELrtsP.js";import{f as le}from"./vendor-C1aIdQ-w.js";function he(t,e){var b,p;if(t.includes("<!")||(b=e.fontStyles)!=null&&b.length&&/<cols\b/.test(t))return;const r=/<sheetData\s*>/.exec(t);if(!r)return;const s=r.index+r[0].length,n=t.indexOf("</sheetData>",s);if(n<0)return;const i=t.slice(s,n);if(/<(?:f|is)\b/.test(i))return;const o=[],a=/\s*<row\b([^<>]*?)(?:\/>|>([\s\S]*?)<\/row\s*>)/gy,d=/\s*<c\b([^<>]*?)(?:\/>|>([\s\S]*?)<\/c\s*>)/gy;let u=0,f=0,m=0;for(;u<i.length;){a.lastIndex=u;const l=a.exec(i);if(!l){if(i.slice(u).trim())return;break}const g=Z(l[1]);if(!g)return;const c=Number(g.r??o.length+1);if(!Number.isInteger(c)||c<1)return;const w=[],S=l[2]??"";let y=0;for(;y<S.length;){d.lastIndex=y;const A=d.exec(S);if(!A){if(S.slice(y).trim())return;break}const C=Z(A[1]);if(!C)return;const I=A[2]??"",N=/^\s*(?:<v\s*>([\s\S]*?)<\/v\s*>|<v\s*\/>)?\s*$/.exec(I);if(!N)return;const E=N[1]??"";if(E.trim()&&!/^[\s]*[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?\s*$/.test(E)&&!/^\s*(?:true|false)\s*$/.test(E)||C.t&&!["n","s","b"].includes(C.t))return;if(C.r){const $=/^([A-Z]+)([1-9]\d*)$/i.exec(C.r);if(!$)return;let T=0;for(const Y of $[1].toUpperCase())T=T*26+Y.charCodeAt(0)-64;const L=C.t==="s"?e.sharedStrings[Number(E)]??"":C.t==="b"?E.trim()==="1"||E.trim()==="true"?"TRUE":"FALSE":E,R={ref:C.r,row:Number($[2]),column:T,value:L},J=["1","true"].includes(g.customFormat)?g.s:void 0,D=(p=e.fontStyles)==null?void 0:p[Number(C.s??J??0)];D&&(R.font=D),w.push(R),m=Math.max(m,T)}y=d.lastIndex}o.push({index:c,cells:w}),f=Math.max(f,c),u=a.lastIndex}return{id:e.id,name:e.name,rows:o,columnCount:m,rowCount:f}}function Z(t){const e=Object.create(null),r=/\s+([A-Za-z_:][\w:.-]*)\s*=\s*(?:"([^"<>&]*)"|'([^'<>&]*)')/gy;let s=0;for(;s<t.length;){r.lastIndex=s;const n=r.exec(t);if(!n)return t.slice(s).trim()?void 0:e;e[n[1]]=n[2]??n[3],s=r.lastIndex}return e}const ce=1e5,M=new le.XMLParser({ignoreAttributes:false,attributeNamePrefix:"",textNodeName:"#text",parseTagValue:false,parseAttributeValue:false,trimValues:false,processEntities:{enabled:true,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:ce,maxExpandedLength:1e5,maxEntityCount:100}});async function fe(t,e){var l,g;if(k(e==null?void 0:e.signal),Ne(((l=e==null?void 0:e.route)==null?void 0:l.sourceFormat)??(e==null?void 0:e.descriptor.extension))==="csv")return de(t,e);const s=await ue(t,e);k(e==null?void 0:e.signal);const n=await ee(s);k(e==null?void 0:e.signal);const i=[],o=await _(n,"xl/workbook.xml",e==null?void 0:e.signal),a=await _(n,"xl/_rels/workbook.xml.rels",e==null?void 0:e.signal),d=await pe(n,e==null?void 0:e.signal);k(e==null?void 0:e.signal);const u=M.parse(o),f=be(a),m=await ve(n,f,e==null?void 0:e.signal),b=ye(u),p=[];for(const c of b){k(e==null?void 0:e.signal);const w=f.find(A=>A.id===c.relationshipId);if(!w){i.push(`Missing relationship for sheet ${c.name}.`);continue}const S=O(w.target),y=await((g=n.get(S))==null?void 0:g.text());if(k(e==null?void 0:e.signal),!y){i.push(`Missing worksheet file for sheet ${c.name}.`);continue}p.push(ke(y,{id:c.sheetId,name:c.name,sharedStrings:d,fontStyles:m.styles}))}return{sheets:p,warnings:i,fonts:m.fonts}}async function de(t,e){k(e==null?void 0:e.signal);const r=await me(t,e);k(e==null?void 0:e.signal);const{rows:s,columnCount:n}=we(r);return{sheets:[{id:"csv",name:Te(e==null?void 0:e.descriptor.name),rows:s,columnCount:n,rowCount:s.length}],warnings:[]}}async function ue(t,e){if(typeof t=="string"){const r=await fetch(t,{signal:e==null?void 0:e.signal});if(!r.ok)throw new Error(`Failed to load XLSX source: ${r.status} ${r.statusText}`.trim());return new Uint8Array(await r.arrayBuffer())}return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t instanceof ArrayBuffer?new Uint8Array(t):t instanceof Blob?new Uint8Array(await t.arrayBuffer()):new Uint8Array}async function me(t,e){if(typeof t=="string"){if(t.trimStart().toLowerCase().startsWith("data:"))return ge(t);const r=await fetch(t,{signal:e==null?void 0:e.signal});if(!r.ok)throw new Error(`Failed to load CSV source: ${r.status} ${r.statusText}`.trim());return r.text()}return t instanceof Blob?t.text():ArrayBuffer.isView(t)?new TextDecoder().decode(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)):t instanceof ArrayBuffer?new TextDecoder().decode(t):String(t)}function ge(t){const e=t.indexOf(",");if(e<0)return t;const r=t.slice(0,e).toLowerCase(),s=t.slice(e+1);return r.endsWith(";base64")?new TextDecoder().decode(Uint8Array.from(atob(s),n=>n.charCodeAt(0))):decodeURIComponent(s)}function we(t){t=t.replace(/^\uFEFF/,"");const e=[],r=[],s=f=>{for(;r.length<f.length;)r.push(q(r.length+1));const m=e.length+1,b=String(m),p=new Array(f.length);for(let l=0;l<f.length;l++)p[l]={ref:r[l]+b,row:m,column:l+1,value:f[l]};e.push({index:m,cells:p})};if(!t.includes('"')){const f=t.split(/\r\n|\r|\n/);t.length&&/[\r\n]$/.test(t)&&f.pop();for(const m of f)s(m.split(","));return{rows:e,columnCount:r.length}}let n=[],i="",o=0,a=0,d=0,u=false;for(;o<t.length;){if(u){const m=t.indexOf('"',o);if(m<0){i+=t.slice(o),a=o=t.length;break}i+=t.slice(o,m),o=m+1,t[o]==='"'?(i+='"',o++):u=false,a=o;continue}const f=t[o];if(f==='"'&&i.length===0&&o===a){u=true,a=++o;continue}if(f===","){n.push(i+t.slice(a,o)),i="",a=++o;continue}if(f==="\r"||f===`
|
|
2
|
+
`){n.push(i+t.slice(a,o)),s(n),n=[],i="",f==="\r"&&t[o+1]===`
|
|
3
|
+
`?o+=2:o+=1,d=a=o;continue}o+=1}return(d<t.length||t.length===0)&&(n.push(i+t.slice(a,o)),s(n)),{rows:e,columnCount:r.length}}function k(t){if(t!=null&&t.aborted)throw new DOMException("Workbook preview aborted.","AbortError")}async function _(t,e,r){k(r);const s=t.get(e);if(!s)throw new Error(`Invalid XLSX file: missing ${e}.`);const n=await s.text();return k(r),n}async function pe(t,e){k(e);const r=t.get("xl/sharedStrings.xml");if(!r)return[];const s=await r.text();k(e);const n=M.parse(s);return F(h(n,["sst","si"])).map(V)}function V(t){const e=h(t,["t"]);if(e!=null)return B(e);const r=F(h(t,["r"]));return r.length?r.map(s=>B(h(s,["t"]))).join(""):""}function B(t){if(typeof t=="string")return t;const e=h(t,["#text"]);return typeof e=="string"?e:""}function be(t){const e=M.parse(t);return F(h(e,["Relationships","Relationship"])).map(r=>({id:String(h(r,["Id"])??""),target:String(h(r,["Target"])??""),type:String(h(r,["Type"])??"")})).filter(r=>r.id&&r.target)}function ye(t){return F(h(t,["workbook","sheets","sheet"])).map(e=>({name:String(h(e,["name"])??"Sheet"),sheetId:String(h(e,["sheetId"])??h(e,["name"])??"sheet"),relationshipId:String(h(e,["r:id"])??"")})).filter(e=>e.relationshipId)}async function ve(t,e,r){var b,p,l,g;const s=O(((b=e.find(c=>{var w;return(w=c.type)==null?void 0:w.endsWith("/styles")}))==null?void 0:b.target)??"styles.xml"),n=await((p=t.get(s))==null?void 0:p.text());if(k(r),!n)return{fonts:[],styles:[]};const i=M.parse(n),o=O(((l=e.find(c=>{var w;return(w=c.type)==null?void 0:w.endsWith("/theme")}))==null?void 0:l.target)??"theme/theme1.xml"),a=await((g=t.get(o))==null?void 0:g.text());k(r);const d=a?M.parse(a):void 0,u=F(h(i,["styleSheet","fonts","font"])).map(c=>{const w=h(c,["scheme","val"]),S=w==="major"||w==="minor"?U(d,["theme","themeElements","fontScheme",`${w}Font`,"latin"]):void 0,y=U(S,["typeface"]),A=typeof y=="string"&&y.trim()?y:void 0,C=String(A??h(c,["name","val"])??"").trim(),I=Number(U(S,["pitchFamily"])),N=Number.isInteger(I)&&I>=0&&I<=255,E=N&&(I&3)===1?"fixed":N&&(I&3)===2?"variable":void 0,$=N?W(I>>4):{},T=U(S,["panose"]),L=h(c,["b"]),R=L!==void 0&&!["0","false"].includes(String(h(L,["val"])??L))?700:400;return{fontFamily:C||void 0,traits:{...A?{...$,...te(typeof T=="string"?T:void 0),...W(void 0,E)}:W(h(c,["family","val"])),weight:R}}}),f=F(h(i,["styleSheet","cellStyleXfs","xf"])),m=F(h(i,["styleSheet","cellXfs","xf"]));return{fonts:u,styles:m.map(c=>{const w=f[Number(h(c,["xfId"])??0)],y=["0","false"].includes(String(h(c,["applyFont"])))?h(w,["fontId"]):h(c,["fontId"])??h(w,["fontId"]);return u[Number(y??0)]})}}function U(t,e){for(const r of e){if(!t||typeof t!="object")return;const s=t,n=Object.keys(s).find(i=>i.split(":").pop()===r);t=n?s[n]:void 0}return t}function ke(t,e){const r=he(t,e);if(r)return r;const s=M.parse(t),n=F(h(s,["worksheet","sheetData","row"])),i=[],o=F(h(s,["worksheet","cols","col"]));let a=0,d=0;for(const u of n){const f=Number(h(u,["r"])??i.length+1);d=Math.max(d,f);const m=["1","true"].includes(String(h(u,["customFormat"])))?h(u,["s"]):void 0,b=F(h(u,["c"])).map(p=>{var S;const l=Se(p,e.sharedStrings);if(!l)return null;const g=o.find(y=>l.column>=Number(h(y,["min"]))&&l.column<=Number(h(y,["max"]))),c=h(p,["s"])??m??h(g,["style"])??0,w=(S=e.fontStyles)==null?void 0:S[Number(c)];return w&&(l.font=w),l}).filter(p=>p!=null);for(const p of b)a=Math.max(a,p.column);i.push({index:f,cells:b})}return{id:e.id,name:e.name,rows:i,columnCount:a,rowCount:d}}function Se(t,e){const r=String(h(t,["r"])??"");if(!r)return null;const s=P(r),n=String(h(t,["t"])??""),i=Ce(t),o=xe(t);let a=i??"";if(n==="s")a=e[Number(i??"")]??"";else if(n==="b"){const d=i==null?void 0:i.trim();a=d==="1"||d==="true"?"TRUE":"FALSE"}else n==="inlineStr"&&(a=V(h(t,["is"])));return{ref:r,row:s.row,column:s.column,value:a,...o?{formula:o,needsCalculation:i==null}:{}}}function Ce(t){const e=h(t,["v"]);return e==null?null:String(e)}function xe(t){const e=h(t,["f"]);if(typeof e=="string")return e;const r=h(e,["#text"]);return typeof r=="string"?r:""}function j(t,e,r=new Set){if(!e.formula||!e.needsCalculation)return e.value;if(r.has(e.ref))return`=${e.formula}`;r.add(e.ref);try{const s=new Ee(e.formula,n=>Fe(t,n,r)).read();e.value=String(s)}catch{e.value=`=${e.formula}`}finally{r.delete(e.ref),e.needsCalculation=false}return e.value}const z=new WeakMap;function Fe(t,e,r){const s=P(e.replace(/\$/g,""));let n=z.get(t);if(!n){n=new Map;for(const d of t.rows)for(const u of d.cells)n.set(`${d.index}:${u.column}`,u);z.set(t,n)}const i=n.get(`${s.row}:${s.column}`);if(!i)return 0;const o=j(t,i,r).trim();if(o==="")return 0;if(o.toUpperCase()==="TRUE")return 1;if(o.toUpperCase()==="FALSE")return 0;const a=Number(o);if(!Number.isFinite(a))throw new Error(`Formula reference ${e} is not numeric.`);return a}class Ee{constructor(e,r){v(this,"tokens");v(this,"index",0);this.readCell=r,this.tokens=Ae(e.replace(/^=/,"").trim())}read(){const e=this.readExpression();if(this.index!==this.tokens.length||Array.isArray(e)||!Number.isFinite(e))throw new Error("Unsupported formula.");return e}readExpression(){let e=this.readTerm();for(;this.peek()==="+"||this.peek()==="-";){const r=this.take(),s=this.readTerm();e=r==="+"?x(e)+x(s):x(e)-x(s)}return e}readTerm(){let e=this.readPower();for(;this.peek()==="*"||this.peek()==="/";){const r=this.take(),s=this.readPower();e=r==="*"?x(e)*x(s):x(e)/x(s)}return e}readPower(){let e=this.readUnary();return this.peek()==="^"&&(this.take(),e=x(e)**x(this.readPower())),e}readUnary(){return this.peek()==="+"||this.peek()==="-"?(this.take()==="-"?-1:1)*x(this.readUnary()):this.readPrimary()}readPrimary(){const e=this.take();if(e==="("){const r=this.readExpression();return this.expect(")"),r}if(/^(?:\d+(?:\.\d*)?|\.\d+)(?:E[+-]?\d+)?$/i.test(e))return Number(e);if(/^\$?[A-Z]+\$?\d+$/i.test(e))return this.peek()!==":"?this.readCell(e):(this.take(),this.readRange(e,this.take()));if(/^[A-Z][A-Z0-9_.]*$/i.test(e)){if(e.toUpperCase()==="TRUE")return 1;if(e.toUpperCase()==="FALSE")return 0;if(e.toUpperCase()!=="SUM")throw new Error("Unsupported function.");this.expect("(");const r=[];if(this.peek()!==")")do{const s=this.readExpression();r.push(...Array.isArray(s)?s:[s])}while(this.peek()===","&&this.take());return this.expect(")"),r.reduce((s,n)=>s+n,0)}throw new Error("Unsupported formula token.")}readRange(e,r){if(!/^\$?[A-Z]+\$?\d+$/i.test(r))throw new Error("Invalid range.");const s=P(e.replace(/\$/g,"")),n=P(r.replace(/\$/g,"")),i=[];for(let o=Math.min(s.row,n.row);o<=Math.max(s.row,n.row);o+=1)for(let a=Math.min(s.column,n.column);a<=Math.max(s.column,n.column);a+=1)i.push(this.readCell(`${q(a)}${o}`));return i}peek(){return this.tokens[this.index]??""}take(){const e=this.tokens[this.index];if(!e)throw new Error("Unexpected end of formula.");return this.index+=1,e}expect(e){if(this.take()!==e)throw new Error(`Expected ${e}.`)}}function x(t){if(Array.isArray(t))throw new Error("Range cannot be used as a scalar.");return t}function Ae(t){const e=[],r=/\s*((?:\d+(?:\.\d*)?|\.\d+)(?:E[+-]?\d+)?|\$?[A-Z]+\$?\d+|[A-Z][A-Z0-9_.]*|[()+\-*/^,:])/iy;let s=0;for(;s<t.length;){r.lastIndex=s;const n=r.exec(t);if(!n)throw new Error("Unsupported formula token.");e.push(n[1]??""),s=r.lastIndex}return e}function P(t){const e=/^([A-Z]+)(\d+)$/i.exec(t);return e?{column:Ie(e[1]??"A"),row:Number(e[2]??1)}:{row:1,column:1}}function Ie(t){let e=0;for(const r of t.toUpperCase())e=e*26+r.charCodeAt(0)-64;return e}function q(t){let e=t,r="";for(;e>0;){const s=(e-1)%26;r=String.fromCharCode(65+s)+r,e=Math.floor((e-1)/26)}return r||"A"}function Te(t){var r;return(((r=String(t??"").split(/[?#]/,1)[0])==null?void 0:r.split(/[\\/]/).pop())??"").replace(/\.[^.]+$/,"")||"CSV"}function Ne(t){return String(t??"").trim().replace(/^\./,"").toLowerCase()}function O(t){const e=t.replace(/\\/g,"/").replace(/^\//,"");return e.startsWith("xl/")?e:`xl/${e}`}function h(t,e){let r=t;for(const s of e){if(!r||typeof r!="object")return;r=r[s]}return r}function F(t){return t==null?[]:Array.isArray(t)?t:[t]}const X=100,Me=[{extensions:["xlsx"],family:"workbook",driverId:"xlsx",targetFormat:"xlsx"},{extensions:["csv"],family:"workbook",driverId:"xlsx",targetFormat:"csv",contentTypes:["text/csv","application/csv"]}];class $e{constructor(e,r={}){v(this,"listeners",{loading:new Set,rendered:new Set,error:new Set,statechange:new Set,warnings:new Set});v(this,"root");v(this,"tabs");v(this,"grid");v(this,"workbook",null);v(this,"loadGeneration",0);v(this,"loadController");v(this,"removeAbortListener");v(this,"state");v(this,"fontLoading");v(this,"fontReferences",[]);v(this,"allFontReferences",[]);v(this,"handleGridScroll",()=>{var i;const e2=(i=this.workbook)==null?void 0:i.sheets[this.state.activeSheetIndex],r2=this.grid.querySelector("tbody");if(!e2||!r2||this.grid.scrollHeight-this.grid.scrollTop-this.grid.clientHeight>this.grid.clientHeight*2)return;const s=r2.rows.length,n=Math.max(e2.rowCount,1);s>=n||H(r2,e2,s+1,Math.min(s+X,n))});this.host=e,this.root=document.createElement("div"),this.root.className="xlsxv-preview",this.tabs=document.createElement("div"),this.tabs.className="xlsxv-sheet-tabs",this.grid=document.createElement("div"),this.grid.className="xlsxv-grid",this.root.replaceChildren(this.tabs,this.grid),this.host.replaceChildren(this.root),this.grid.addEventListener("scroll",this.handleGridScroll,{passive:true}),this.state={loading:false,error:null,family:"workbook",warnings:[],capabilities:{workbook:true,sheets:true,search:true,download:true},activeSheetIndex:0,sheets:[],scale:r.initialScale??1},this.fontLoading=se(this,e.ownerDocument,r)}async load(e,r){var a,d,u;this.fontLoading.reset(r.signal,((a=r.route)==null?void 0:a.targetFormat)??r.descriptor.extension??"xlsx");const s=++this.loadGeneration;(d=this.loadController)==null||d.abort(),(u=this.removeAbortListener)==null||u.call(this),this.releaseWorkbook();const n=new AbortController;this.loadController=n;const i=r.signal,o=()=>{n.abort(),s===this.loadGeneration&&(this.releaseWorkbook(),this.state.loading=false,this.emit("statechange",this.state))};i==null||i.addEventListener("abort",o,{once:true}),this.removeAbortListener=()=>i==null?void 0:i.removeEventListener("abort",o),this.state={...this.state,loading:true,error:null,title:r.descriptor.name,warnings:[]},this.emit("loading",this.state),this.emit("statechange",this.state);try{i!=null&&i.aborted&&o();const f=await fe(e,{...r,signal:n.signal});if(s!==this.loadGeneration)return;if(n.signal.aborted)throw new DOMException("Workbook preview aborted.","AbortError");this.workbook=f;const m=new Set;for(const l of f.sheets)for(const g of l.rows)for(const c of g.cells)c.font&&m.add(c.font);this.allFontReferences=(f.fonts??[]).map(l=>({...l})),this.fontReferences=this.allFontReferences.filter((l,g)=>m.has(f.fonts[g]));const b=ne(f.fonts??[],this.host.ownerDocument,{substitute:true}),p=new Map(b.fonts.map(l=>[JSON.stringify([l.fontFamily,l.classification]),l.resolvedFontFamily]));for(const l of f.fonts??[]){const g=p.get(JSON.stringify([l.fontFamily,ie(l.fontFamily??"",l.traits)]));g&&(l.resolvedFontFamily=g)}this.state={...this.state,loading:false,error:null,warnings:[...new Set([...this.workbook.warnings,...b.warnings])],fonts:b.fonts,activeSheetIndex:0,sheets:this.workbook.sheets.map((l,g)=>({id:l.id||String(g+1),name:l.name}))},this.render(),this.state.warnings.length&&this.emit("warnings",this.state.warnings),this.emit("rendered",this.state),this.emit("statechange",this.state)}catch(f){if(s!==this.loadGeneration)return;if(this.releaseWorkbook(),this.state.loading=false,n.signal.aborted)throw new DOMException("Workbook preview aborted.","AbortError");const m=f instanceof Error?f:new Error(String(f));throw this.state.error=m.message,this.emit("error",m),this.emit("statechange",this.state),m}}destroy(){var e,r;this.fontLoading.destroy(),this.loadGeneration++,(e=this.loadController)==null||e.abort(),(r=this.removeAbortListener)==null||r.call(this),this.releaseWorkbook(),this.state.loading=false,this.grid.removeEventListener("scroll",this.handleGridScroll),this.root.replaceChildren(),this.root.parentElement===this.host&&this.host.replaceChildren();for(const s of Object.values(this.listeners))s.clear()}getState(){var e;return{...this.state,warnings:this.state.warnings.slice(),fonts:(e=this.state.fonts)==null?void 0:e.map(r=>({...r,classification:r.classification?{...r.classification}:void 0})),sheets:this.state.sheets.slice()}}getFontReferences(){return this.fontReferences}refreshFonts(e){var s,n;if(!this.workbook||(s=this.loadController)!=null&&s.signal.aborted)return;this.fontReferences=e.references,this.allFontReferences=this.allFontReferences.map(i=>e.references.find(o=>{var a,d;return o.fontFamily===i.fontFamily&&((a=o.traits)==null?void 0:a.weight)===((d=i.traits)==null?void 0:d.weight)})??i);const r=oe({...e,references:this.allFontReferences},this.host.ownerDocument);for(const i of this.workbook.fonts??[]){const o=e.references.find(a=>{var d,u;return a.fontFamily===i.fontFamily&&((d=a.traits)==null?void 0:d.weight)===((u=i.traits)==null?void 0:u.weight)});o!=null&&o.resolvedFontFamily&&(i.resolvedFontFamily=o.resolvedFontFamily)}if(this.state.fonts=r.fonts,this.state.warnings=[...new Set([...this.workbook.warnings,...r.warnings])],e.loaded.length||e.relayout){const i=this.workbook.sheets[this.state.activeSheetIndex],o=this.grid.scrollTop,a=this.grid.scrollLeft,d=((n=this.grid.querySelector("tbody"))==null?void 0:n.rows.length)??X;i&&this.grid.replaceChildren(G(i,d)),this.grid.scrollTop=o,this.grid.scrollLeft=a}this.emit("warnings",this.state.warnings),this.emit("rendered",this.getState()),this.emit("statechange",this.getState())}on(e,r){return this.listeners[e].add(r),()=>{this.listeners[e].delete(r)}}goToPage(e){this.goToSheet(e)}next(){this.goToSheet(Math.min(this.state.activeSheetIndex+1,Math.max(this.state.sheets.length-1,0)))}prev(){this.goToSheet(Math.max(this.state.activeSheetIndex-1,0))}goToSheet(e){if(!Number.isInteger(e)||!this.workbook)return;const r=Math.max(0,Math.min(e,Math.max(this.state.sheets.length-1,0)));r!==this.state.activeSheetIndex&&(this.state.activeSheetIndex=r,this.render(),this.emit("statechange",this.state))}render(){this.renderTabs(),this.renderActiveSheet()}renderTabs(){this.tabs.replaceChildren();for(const[e,r]of this.state.sheets.entries()){const s=document.createElement("button");s.type="button",s.className="xlsxv-sheet-tab",s.classList.toggle("is-active",e===this.state.activeSheetIndex),s.textContent=r.name,s.addEventListener("click",()=>this.goToSheet(e)),this.tabs.appendChild(s)}}renderActiveSheet(){var r;const e=(r=this.workbook)==null?void 0:r.sheets[this.state.activeSheetIndex];this.grid.replaceChildren(),this.grid.scrollTop=this.grid.scrollLeft=0,e&&this.grid.appendChild(G(e,Math.min(Math.max(e.rowCount,1),X)))}releaseWorkbook(){this.fontReferences=[],this.allFontReferences=[],this.workbook=null,this.tabs.replaceChildren(),this.grid.replaceChildren(),this.grid.scrollTop=this.grid.scrollLeft=0,this.state.activeSheetIndex=0,this.state.sheets=[],this.state.fonts=[]}emit(e,r){for(const s of this.listeners[e])s(r)}}function Xe(){return{id:"xlsx",family:"workbook",supports:t=>["xlsx","csv"].includes(Le(t)),createSession:(t,e)=>new $e(t,e)}}function Oe(t=re()){return[...Me,...t.filter(e=>!e.extensions.some(r=>{var s;return r==="xlsx"||r==="csv"&&!((s=e.conversion)!=null&&s.required)}))]}function G(t,e=Math.max(t.rowCount,1)){const r=document.createElement("table");r.className="xlsxv-table";const s=document.createElement("thead"),n=document.createElement("tr"),i=document.createElement("th");i.className="xlsxv-corner",n.appendChild(i);for(let a=1;a<=Math.max(t.columnCount,1);a+=1){const d=document.createElement("th");d.className="xlsxv-col-header",d.textContent=Re(a),n.appendChild(d)}s.appendChild(n),r.appendChild(s);const o=document.createElement("tbody");return H(o,t,1,e),r.appendChild(o),r}function H(t,e,r,s){var a,d;if(r>s)return;const n=new Map,i=new Map;for(const u of e.rows)u.index>=r&&u.index<=s&&i.set(u.index,u);const o=document.createDocumentFragment();for(let u=r;u<=s;u+=1){const f=i.get(u),m=document.createElement("tr"),b=document.createElement("th");b.className="xlsxv-row-header",b.textContent=String(u),m.appendChild(b);const p=new Map((f==null?void 0:f.cells.map(l=>[l.column,l]))??[]);for(let l=1;l<=Math.max(e.columnCount,1);l+=1){const g=document.createElement("td");g.className="xlsxv-cell";const c=p.get(l);if(g.textContent=c?j(e,c):"",(a=c==null?void 0:c.font)!=null&&a.fontFamily){let w=n.get(c.font);w||(w=ae(c.font.fontFamily,c.font.traits,c.font.resolvedFontFamily?[c.font.resolvedFontFamily]:[]),n.set(c.font,w)),g.style.fontFamily=w,(d=c.font.traits)!=null&&d.weight&&(g.style.fontWeight=String(c.font.traits.weight))}m.appendChild(g)}o.appendChild(m)}t.appendChild(o)}function Le(t){return t.trim().replace(/^\./,"").toLowerCase()}function Re(t){let e=t,r="";for(;e>0;){const s=(e-1)%26;r=String.fromCharCode(65+s)+r,e=Math.floor((e-1)/26)}return r||"A"}export{X as R,H as a,Xe as b,G as c,Oe as d};
|
|
Binary file
|