han-excel-builder 1.0.4 → 1.0.5
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/han-excel.cjs.js +1 -1
- package/dist/han-excel.cjs.js.map +1 -1
- package/dist/han-excel.es.js +26 -8
- package/dist/han-excel.es.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/package.json +1 -1
package/dist/han-excel.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("exceljs"),t=require("file-saver");class s{listeners=new Map;on(e,t,s={}){this.listeners.has(e)||this.listeners.set(e,[]);const r={type:e,listener:t,options:{once:!1,async:!1,priority:0,stopPropagation:!1,...s},id:this.generateId(),active:!0,timestamp:new Date};return this.listeners.get(e).push(r),this.listeners.get(e).sort((e,t)=>(t.options.priority||0)-(e.options.priority||0)),r.id}once(e,t,s={}){return this.on(e,t,{...s,once:!0})}off(e,t){const s=this.listeners.get(e);if(!s)return!1;const r=s.findIndex(e=>e.id===t);return-1!==r&&(s.splice(r,1),!0)}offAll(e){const t=this.listeners.get(e);if(!t)return 0;const s=t.length;return this.listeners.delete(e),s}async emit(e){const t=e.type||"default",s=this.listeners.get(t);if(!s||0===s.length)return;const r=s.filter(e=>e.active);for(const o of r)try{if(o.options.once&&(o.active=!1),o.options.async?await o.listener(e):o.listener(e),o.options.stopPropagation)break}catch(i){console.error(`Error in event listener for ${t}:`,i)}this.cleanupInactiveListeners(t)}emitSync(e){const t=e.type||"default",s=this.listeners.get(t);if(!s||0===s.length)return;const r=s.filter(e=>e.active);for(const o of r)try{if(o.options.once&&(o.active=!1),o.listener(e),o.options.stopPropagation)break}catch(i){console.error(`Error in event listener for ${t}:`,i)}this.cleanupInactiveListeners(t)}clear(){this.listeners.clear()}getListeners(e){return this.listeners.get(e)||[]}getListenerCount(e){return this.listeners.get(e)?.length||0}getEventTypes(){return Array.from(this.listeners.keys())}generateId(){return Math.random().toString(36).substr(2,9)}cleanupInactiveListeners(e){const t=this.listeners.get(e);if(t){const s=t.filter(e=>e.active);s.length!==t.length&&this.listeners.set(e,s)}}}var r=(e=>(e.STRING="string",e.NUMBER="number",e.BOOLEAN="boolean",e.DATE="date",e.PERCENTAGE="percentage",e.CURRENCY="currency",e.LINK="link",e.FORMULA="formula",e))(r||{}),i=(e=>(e.GENERAL="General",e.NUMBER="#,##0",e.NUMBER_DECIMALS="#,##0.00",e.CURRENCY="$#,##0.00",e.CURRENCY_INTEGER="$#,##0",e.PERCENTAGE="0%",e.PERCENTAGE_DECIMALS="0.00%",e.DATE="dd/mm/yyyy",e.DATE_TIME="dd/mm/yyyy hh:mm",e.TIME="hh:mm:ss",e.CUSTOM="custom",e))(i||{}),o=(e=>(e.LEFT="left",e.CENTER="center",e.RIGHT="right",e.FILL="fill",e.JUSTIFY="justify",e.CENTER_CONTINUOUS="centerContinuous",e.DISTRIBUTED="distributed",e))(o||{}),l=(e=>(e.TOP="top",e.MIDDLE="middle",e.BOTTOM="bottom",e.DISTRIBUTED="distributed",e.JUSTIFY="justify",e))(l||{}),n=(e=>(e.THIN="thin",e.MEDIUM="medium",e.THICK="thick",e.DOTTED="dotted",e.DASHED="dashed",e.DOUBLE="double",e.HAIR="hair",e.MEDIUM_DASHED="mediumDashed",e.DASH_DOT="dashDot",e.MEDIUM_DASH_DOT="mediumDashDot",e.DASH_DOT_DOT="dashDotDot",e.MEDIUM_DASH_DOT_DOT="mediumDashDotDot",e.SLANT_DASH_DOT="slantDashDot",e))(n||{}),a=(e=>(e.NORMAL="normal",e.BOLD="bold",e.ITALIC="italic",e.BOLD_ITALIC="bold italic",e))(a||{}),h=(e=>(e.VALIDATION_ERROR="VALIDATION_ERROR",e.BUILD_ERROR="BUILD_ERROR",e.STYLE_ERROR="STYLE_ERROR",e.WORKSHEET_ERROR="WORKSHEET_ERROR",e.CELL_ERROR="CELL_ERROR",e))(h||{});class d{config;tables=[];currentRow=1;currentCol=1;headerPointers=new Map;isBuilt=!1;headers=[];subHeaders=[];body=[];footers=[];constructor(e){this.config=e}addHeader(e){return this.headers.push(e),this}addSubHeaders(e){return this.subHeaders.push(...e),this}addRow(e){return Array.isArray(e)?this.body.push(...e):this.body.push(e),this}addFooter(e){return Array.isArray(e)?this.footers.push(...e):this.footers.push(e),this}addTable(e={}){const t={name:e.name||`Table_${this.tables.length+1}`,headers:e.headers||[],subHeaders:e.subHeaders||[],body:e.body||[],footers:e.footers||[],showBorders:!1!==e.showBorders,showStripes:!1!==e.showStripes,style:e.style||"TableStyleLight1",...e};return this.tables.push(t),this}finalizeTable(){0===this.tables.length&&this.addTable();const e=this.tables[this.tables.length-1];if(!e)throw new Error("No se pudo obtener la tabla actual");return this.headers.length>0&&(e.headers=[...e.headers||[],...this.headers]),this.subHeaders.length>0&&(e.subHeaders=[...e.subHeaders||[],...this.subHeaders]),this.body.length>0&&(e.body=[...e.body||[],...this.body]),this.footers.length>0&&(e.footers=[...e.footers||[],...this.footers]),this.headers=[],this.subHeaders=[],this.body=[],this.footers=[],this}getTable(e){return this.tables.find(t=>t.name===e)}async build(e,t={}){const s=e.addWorksheet(this.config.name,{properties:{defaultRowHeight:this.config.defaultRowHeight||20,tabColor:this.config.tabColor},pageSetup:this.config.pageSetup});let r=1;if(this.tables.length>0)for(let i=0;i<this.tables.length;i++){const e=this.tables[i];e&&(r=await this.buildTable(s,e,r,i>0))}else r=await this.buildLegacyContent(s,r);this.isBuilt=!0}async buildTable(e,t,s,r=!1){let i=s;if(r&&(i+=2),t.headers&&t.headers.length>0)for(const o of t.headers){if(e.addRow([o.value]),o.mergeCell){const s=this.calculateTableMaxColumns(t);e.mergeCells(i,1,i,s)}o.styles&&e.getRow(i).eachCell(e=>{e.style=this.convertStyle(o.styles)}),this.applyCellDimensions(e,i,1,o),i++}if(t.subHeaders&&t.subHeaders.length>0&&(i=this.buildNestedHeaders(e,i,t.subHeaders)),t.body&&t.body.length>0)for(const o of t.body)i=this.addDataRowRecursive(e,i,o);if(t.footers&&t.footers.length>0)for(const o of t.footers)i=this.addFooterRow(e,i,o);return(t.showBorders||t.showStripes)&&this.applyTableStyle(e,t,s,i-1),i}async buildLegacyContent(e,t){let s=t;this.headers.length>0&&this.headers.forEach(t=>{e.addRow([t.value]),t.mergeCell&&e.mergeCells(s,1,s,this.getMaxColumns()||1),t.styles&&e.getRow(s).eachCell(e=>{e.style=this.convertStyle(t.styles)}),this.applyCellDimensions(e,s,1,t),s++}),this.subHeaders.length>0&&(s=this.buildNestedHeaders(e,s,this.subHeaders));for(const r of this.body)s=this.addDataRowRecursive(e,s,r);if(this.footers.length>0)for(const r of this.footers)s=this.addFooterRow(e,s,r);return s}calculateTableMaxColumns(e){let t=0;if(e.subHeaders&&e.subHeaders.length>0)for(const s of e.subHeaders)t+=this.calculateHeaderColSpan(s);return t||1}applyTableStyle(e,t,s,r){const i=this.calculateTableMaxColumns(t);if(t.showBorders)for(let o=s;o<=r;o++)for(let t=1;t<=i;t++){const s=e.getRow(o).getCell(t);s.style||(s.style={}),s.style.border||(s.style.border={top:{style:"thin",color:{argb:"FF8EAADB"}},left:{style:"thin",color:{argb:"FF8EAADB"}},bottom:{style:"thin",color:{argb:"FF8EAADB"}},right:{style:"thin",color:{argb:"FF8EAADB"}}})}if(t.showStripes)for(let o=s;o<=r;o++)if((o-s)%2==1)for(let t=1;t<=i;t++){const s=e.getRow(o).getCell(t);s.style||(s.style={}),s.style.fill||(s.style.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFF2F2F2"}})}}buildNestedHeaders(e,t,s){let r=t;const i=this.getMaxHeaderDepth(s);for(let o=0;o<i;o++){const t=e.getRow(r);let i=1;for(const l of s)if(0===o){const s=this.getHeaderAtDepth(l,o,i),n=t.getCell(i);n.value=s.value,s.style&&(n.style=this.convertStyle(s.style)),this.applyCellDimensions(e,r,i,l),i+=s.colSpan}else if(l.children&&l.children.length>0)for(const s of l.children){const o=t.getCell(i);o.value="string"==typeof s.value?s.value:String(s.value||""),(s.styles||l.styles)&&(o.style=this.convertStyle(s.styles||l.styles)),this.applyCellDimensions(e,r,i,s),i+=this.calculateHeaderColSpan(s)}else{t.getCell(i).value=null,i+=1}r++}return this.applyAllMerges(e,t,r-1,s),r}getHeaderAtDepth(e,t,s){const r=this.calculateHeaderColSpan(e);if(0===t){const t=r>1?{start:s,end:s+r-1}:null;return{value:"string"==typeof e.value?e.value:String(e.value||""),style:e.styles,colSpan:r,mergeRange:t}}if(e.children&&e.children.length>0){const r=e.children[t];if(r){const t=this.calculateHeaderColSpan(r),i=t>1?{start:s,end:s+t-1}:null;return{value:"string"==typeof r.value?r.value:String(r.value||""),style:r.styles||e.styles,colSpan:t,mergeRange:i}}}return{value:null,style:null,colSpan:1}}applyAllMerges(e,t,s,r){this.getMaxHeaderDepth(r)<=1||this.applySmartMerges(e,t,s,r)}applySmartMerges(e,t,s,r){if(this.getMaxHeaderDepth(r)<=1)return;let i=1;for(const o of r)this.applySmartMergesForHeader(e,t,s,o,i),i+=this.calculateHeaderColSpan(o)}applySmartMergesForHeader(e,t,s,r,i){const o=this.calculateHeaderColSpan(r);if(r.children&&0!==r.children.length){o>1&&e.mergeCells(t,i,t,i+o-1);let l=i;for(const i of r.children)this.applySmartMergesForHeader(e,t+1,s,i,l),l+=this.calculateHeaderColSpan(i)}else e.mergeCells(t,i,s,i+o-1)}calculateHeaderColSpan(e){return e.children&&0!==e.children.length?e.children.reduce((e,t)=>e+this.calculateHeaderColSpan(t),0):1}getMaxHeaderDepth(e){let t=1;for(const s of e)if(s.children&&s.children.length>0){const e=this.getMaxHeaderDepth(s.children);t=Math.max(t,e+1)}return t}getMaxColumns(){let e=0;for(const t of this.subHeaders)e+=this.calculateHeaderColSpan(t);return e}validate(){return this.headers.length||this.body.length?{success:!0,data:!0}:{success:!1,error:{type:h.VALIDATION_ERROR,message:"La hoja no tiene datos"}}}calculateDataColumnPositions(){const e={};let t=1;for(const s of this.subHeaders)if(s.children&&s.children.length>0)for(const r of s.children)r.key&&(e[r.key]=t),r.value&&(e[String(r.value)]=t),t++;else s.key&&(e[s.key]=t),s.value&&(e[String(s.value)]=t),t++;return e}addFooterRow(e,t,s){const r=this.calculateDataColumnPositions();let i;s.key&&r[s.key]?i=r[s.key]:s.header&&r[s.header]&&(i=r[s.header]),void 0===i&&(i=1);const o=e.getRow(t),l=o.getCell(i);if(l.value=s.value,s.styles&&(l.style=this.convertStyle(s.styles)),s.numberFormat&&(l.numFmt=s.numberFormat),this.applyCellDimensions(e,t,i,s),s.mergeCell&&s.mergeTo&&e.mergeCells(t,i,t,s.mergeTo),s.children&&s.children.length>0)for(const n of s.children)if(n){let s;if(n.key&&r[n.key]?s=r[n.key]:n.header&&r[n.header]&&(s=r[n.header]),void 0!==s){const r=o.getCell(s);r.value=n.value,n.styles&&(r.style=this.convertStyle(n.styles)),n.numberFormat&&(r.numFmt=n.numberFormat),this.applyCellDimensions(e,t,s,n)}}return s.jump?t+1:t}applyCellDimensions(e,t,s,r){if(void 0!==r.rowHeight){e.getRow(t).height=r.rowHeight}if(void 0!==r.colWidth){e.getColumn(s).width=r.colWidth}}addDataRowRecursive(e,t,s){const r=this.calculateDataColumnPositions();let i;s.key&&r[s.key]?i=r[s.key]:s.header&&r[s.header]&&(i=r[s.header]),void 0===i&&(i=1);const o=e.getRow(t),l=o.getCell(i);if(l.value=s.value,s.styles&&(l.style=this.convertStyle(s.styles)),s.numberFormat&&(l.numFmt=s.numberFormat),this.applyCellDimensions(e,t,i,s),s.children&&s.children.length>0)for(const n of s.children)if(n){let s;if(n.key&&r[n.key]?s=r[n.key]:n.header&&r[n.header]&&(s=r[n.header]),void 0!==s){const r=o.getCell(s);r.value=n.value,n.styles&&(r.style=this.convertStyle(n.styles)),n.numberFormat&&(r.numFmt=n.numberFormat),this.applyCellDimensions(e,t,s,n)}}return s.jump?t+1:t}convertColor(e){if(e){if("object"==typeof e&&e.argb)return e;if("object"==typeof e&&"r"in e&&"g"in e&&"b"in e){return{argb:`FF${e.r.toString(16).padStart(2,"0")}${e.g.toString(16).padStart(2,"0")}${e.b.toString(16).padStart(2,"0")}`.toUpperCase()}}if("string"==typeof e){let t=e.replace("#","");return 3===t.length&&(t=t.split("").map(e=>e+e).join("")),6===t.length&&(t="FF"+t.toUpperCase()),{argb:t}}return"object"==typeof e&&"theme"in e?e:void 0}}convertStyle(e){if(!e)return{};const t={};if(e.font&&(t.font={name:e.font.family||e.font.name,size:e.font.size,bold:e.font.bold,italic:e.font.italic,underline:e.font.underline,color:this.convertColor(e.font.color)}),e.fill){const s=e.fill.pattern||"solid",r="solid"===s?e.fill.backgroundColor||e.fill.foregroundColor:e.fill.foregroundColor||e.fill.backgroundColor,i="solid"!==s?e.fill.backgroundColor:void 0;t.fill={type:e.fill.type||"pattern",pattern:s,fgColor:this.convertColor(r),bgColor:i?this.convertColor(i):void 0},t.fill.bgColor||delete t.fill.bgColor}if(e.border&&(t.border={},e.border.top&&(t.border.top={style:e.border.top.style,color:this.convertColor(e.border.top.color)}),e.border.left&&(t.border.left={style:e.border.left.style,color:this.convertColor(e.border.left.color)}),e.border.bottom&&(t.border.bottom={style:e.border.bottom.style,color:this.convertColor(e.border.bottom.color)}),e.border.right&&(t.border.right={style:e.border.right.style,color:this.convertColor(e.border.right.color)})),e.alignment){if(t.alignment={},void 0!==e.alignment.horizontal){["left","center","right","fill","justify","centerContinuous","distributed"].includes(e.alignment.horizontal)&&(t.alignment.horizontal=e.alignment.horizontal)}if(void 0!==e.alignment.vertical){["top","middle","bottom","distributed","justify"].includes(e.alignment.vertical)&&(t.alignment.vertical=e.alignment.vertical)}if(void 0!==e.alignment.wrapText&&(t.alignment.wrapText=Boolean(e.alignment.wrapText)),void 0!==e.alignment.shrinkToFit&&(t.alignment.shrinkToFit=Boolean(e.alignment.shrinkToFit)),void 0!==e.alignment.indent&&"number"==typeof e.alignment.indent&&(t.alignment.indent=e.alignment.indent),void 0!==e.alignment.textRotation&&"number"==typeof e.alignment.textRotation&&(t.alignment.textRotation=e.alignment.textRotation),void 0!==e.alignment.readingOrder){["left-to-right","right-to-left","context"].includes(e.alignment.readingOrder)&&(t.alignment.readingOrder=e.alignment.readingOrder)}0===Object.keys(t.alignment).length&&delete t.alignment}return e.numFmt&&(t.numFmt=e.numFmt),t}}var c=(e=>(e.WORKSHEET_ADDED="worksheetAdded",e.WORKSHEET_REMOVED="worksheetRemoved",e.WORKSHEET_UPDATED="worksheetUpdated",e.BUILD_STARTED="buildStarted",e.BUILD_PROGRESS="buildProgress",e.BUILD_COMPLETED="buildCompleted",e.BUILD_ERROR="buildError",e.DOWNLOAD_STARTED="downloadStarted",e.DOWNLOAD_PROGRESS="downloadProgress",e.DOWNLOAD_COMPLETED="downloadCompleted",e.DOWNLOAD_ERROR="downloadError",e))(c||{});class u{config;worksheets=new Map;currentWorksheet;isBuilding=!1;stats;eventEmitter;constructor(e={}){this.config={enableValidation:!0,enableEvents:!0,enablePerformanceMonitoring:!1,maxWorksheets:255,maxRowsPerWorksheet:1048576,maxColumnsPerWorksheet:16384,memoryLimit:104857600,...e},this.stats=this.initializeStats(),this.eventEmitter=new s}addWorksheet(e,t={}){if(this.worksheets.has(e))throw new Error(`Worksheet "${e}" already exists`);const s={name:e,defaultRowHeight:20,defaultColWidth:10,...this.config.defaultWorksheetConfig,...t},r=new d(s);return this.worksheets.set(e,r),this.currentWorksheet=r,this.emitEvent(c.WORKSHEET_ADDED,{worksheetName:e}),r}getWorksheet(e){return this.worksheets.get(e)}removeWorksheet(e){const t=this.worksheets.get(e);return!!t&&(this.worksheets.delete(e),this.currentWorksheet===t&&(this.currentWorksheet=void 0),this.emitEvent(c.WORKSHEET_REMOVED,{worksheetName:e}),!0)}setCurrentWorksheet(e){const t=this.worksheets.get(e);return!!t&&(this.currentWorksheet=t,!0)}async build(t={}){if(this.isBuilding)return{success:!1,error:{type:h.BUILD_ERROR,message:"Build already in progress",stack:(new Error).stack||""}};this.isBuilding=!0;const s=Date.now();try{this.emitEvent(c.BUILD_STARTED);const r=new e.Workbook;this.config.metadata&&(r.creator=this.config.metadata.author||"Han Excel Builder",r.lastModifiedBy=this.config.metadata.author||"Han Excel Builder",r.created=this.config.metadata.created||new Date,r.modified=this.config.metadata.modified||new Date,this.config.metadata.title&&(r.title=this.config.metadata.title),this.config.metadata.subject&&(r.subject=this.config.metadata.subject),this.config.metadata.keywords&&(r.keywords=this.config.metadata.keywords),this.config.metadata.category&&(r.category=this.config.metadata.category),this.config.metadata.description&&(r.description=this.config.metadata.description));for(const e of this.worksheets.values())await e.build(r,t);const i=await r.xlsx.writeBuffer({compression:t.compressionLevel||6}),o=Date.now();this.stats.buildTime=o-s,this.stats.fileSize=i.byteLength;const l={success:!0,data:i};return this.emitEvent(c.BUILD_COMPLETED,{buildTime:this.stats.buildTime,fileSize:this.stats.fileSize}),l}catch(r){const e={success:!1,error:{type:h.BUILD_ERROR,message:r instanceof Error?r.message:"Unknown build error",stack:r instanceof Error&&r.stack||""}};return this.emitEvent(c.BUILD_ERROR,{error:e.error}),e}finally{this.isBuilding=!1}}async generateAndDownload(e,s={}){const r=await this.build(s);if(!r.success)return r;try{this.emitEvent(c.DOWNLOAD_STARTED,{fileName:e});const i=new Blob([r.data],{type:s.mimeType||"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});return t(i,e),this.emitEvent(c.DOWNLOAD_COMPLETED,{fileName:e}),{success:!0,data:void 0}}catch(i){const e={success:!1,error:{type:h.BUILD_ERROR,message:i instanceof Error?i.message:"Download failed",stack:i instanceof Error&&i.stack||""}};return this.emitEvent(c.DOWNLOAD_ERROR,{error:e.error}),e}}async toBuffer(e={}){return this.build(e)}async toBlob(e={}){const t=await this.build(e);if(!t.success)return t;return{success:!0,data:new Blob([t.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}}validate(){const e=[];0===this.worksheets.size&&e.push("No worksheets found");for(const[t,s]of this.worksheets.entries()){const r=s.validate();r.success||e.push(`Worksheet "${t}": ${r.error?.message}`)}return e.length>0?{success:!1,error:{type:h.VALIDATION_ERROR,message:e.join("; "),stack:(new Error).stack||""}}:{success:!0,data:!0}}clear(){this.worksheets.clear(),this.currentWorksheet=void 0}getStats(){return{...this.stats}}on(e,t){return this.eventEmitter.on(e,t)}off(e,t){return this.eventEmitter.off(e,t)}removeAllListeners(e){e?this.eventEmitter.offAll(e):this.eventEmitter.clear()}emitEvent(e,t){const s={type:e,data:t||{},timestamp:new Date};this.eventEmitter.emitSync(s)}initializeStats(){return{totalWorksheets:0,totalCells:0,memoryUsage:0,buildTime:0,fileSize:0,stylesUsed:0,formulasUsed:0,conditionalFormatsUsed:0,performance:{headersTime:0,dataTime:0,stylesTime:0,writeTime:0}}}}class y{style={};constructor(){this.style.alignment={horizontal:o.CENTER,vertical:l.MIDDLE,wrapText:!0,shrinkToFit:!0}}static create(){return new y}fontName(e){return this.style.font||(this.style.font={}),this.style.font.name=e,this}fontSize(e){return this.style.font||(this.style.font={}),this.style.font.size=e,this}fontStyle(e){return this.style.font||(this.style.font={}),this.style.font.style=e,this}fontColor(e){return this.style.font||(this.style.font={}),this.style.font.color=e,this}fontBold(){return this.style.font||(this.style.font={}),this.style.font.bold=!0,this}fontItalic(){return this.style.font||(this.style.font={}),this.style.font.italic=!0,this}fontUnderline(){return this.style.font||(this.style.font={}),this.style.font.underline=!0,this}border(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.top=s,this.style.border.left=s,this.style.border.bottom=s,this.style.border.right=s,this}borderTop(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.top=s,this}borderLeft(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.left=s,this}borderBottom(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.bottom=s,this}borderRight(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.right=s,this}backgroundColor(e){return this.style.fill||(this.style.fill={type:"pattern"}),this.style.fill.backgroundColor=e,this.style.fill.pattern="solid",this}horizontalAlign(e){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=e,this}verticalAlign(e){return this.style.alignment||(this.style.alignment={}),this.style.alignment.vertical=e,this}centerAlign(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=o.CENTER,this.style.alignment.vertical=l.MIDDLE,this}leftAlign(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=o.LEFT,this}rightAlign(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=o.RIGHT,this}wrapText(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.wrapText=!0,this}numberFormat(e){return this.style.numberFormat=e,this}striped(){return this.style.striped=!0,this}conditionalFormat(e){return this.style.conditionalFormats||(this.style.conditionalFormats=[]),this.style.conditionalFormats.push(e),this}build(){return this.style}reset(){return this.style={},this.style.alignment={horizontal:o.CENTER,vertical:l.MIDDLE,wrapText:!0},this}clone(){const e=new y;return e.style=JSON.parse(JSON.stringify(this.style)),e}}var f=(e=>(e.CREATED="created",e.UPDATED="updated",e.DELETED="deleted",e.STYLED="styled",e.VALIDATED="validated",e))(f||{}),g=(e=>(e.CREATED="created",e.UPDATED="updated",e.DELETED="deleted",e.TABLE_ADDED="tableAdded",e.TABLE_REMOVED="tableRemoved",e.CELL_ADDED="cellAdded",e.CELL_UPDATED="cellUpdated",e.CELL_DELETED="cellDeleted",e))(g||{}),m=(e=>(e.HEADER="header",e.SUBHEADER="subheader",e.DATA="data",e.FOOTER="footer",e.TOTAL="total",e.HIGHLIGHT="highlight",e.WARNING="warning",e.ERROR="error",e.SUCCESS="success",e.INFO="info",e))(m||{});exports.BorderStyle=n,exports.BuilderEventType=c,exports.CellEventType=f,exports.CellType=r,exports.ErrorType=h,exports.EventEmitter=s,exports.ExcelBuilder=u,exports.FontStyle=a,exports.HorizontalAlignment=o,exports.NumberFormat=i,exports.StyleBuilder=y,exports.StylePreset=m,exports.VerticalAlignment=l,exports.Worksheet=d,exports.WorksheetEventType=g,exports.default=u;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("exceljs"),t=require("file-saver");class s{listeners=new Map;on(e,t,s={}){this.listeners.has(e)||this.listeners.set(e,[]);const r={type:e,listener:t,options:{once:!1,async:!1,priority:0,stopPropagation:!1,...s},id:this.generateId(),active:!0,timestamp:new Date};return this.listeners.get(e).push(r),this.listeners.get(e).sort((e,t)=>(t.options.priority||0)-(e.options.priority||0)),r.id}once(e,t,s={}){return this.on(e,t,{...s,once:!0})}off(e,t){const s=this.listeners.get(e);if(!s)return!1;const r=s.findIndex(e=>e.id===t);return-1!==r&&(s.splice(r,1),!0)}offAll(e){const t=this.listeners.get(e);if(!t)return 0;const s=t.length;return this.listeners.delete(e),s}async emit(e){const t=e.type||"default",s=this.listeners.get(t);if(!s||0===s.length)return;const r=s.filter(e=>e.active);for(const o of r)try{if(o.options.once&&(o.active=!1),o.options.async?await o.listener(e):o.listener(e),o.options.stopPropagation)break}catch(i){console.error(`Error in event listener for ${t}:`,i)}this.cleanupInactiveListeners(t)}emitSync(e){const t=e.type||"default",s=this.listeners.get(t);if(!s||0===s.length)return;const r=s.filter(e=>e.active);for(const o of r)try{if(o.options.once&&(o.active=!1),o.listener(e),o.options.stopPropagation)break}catch(i){console.error(`Error in event listener for ${t}:`,i)}this.cleanupInactiveListeners(t)}clear(){this.listeners.clear()}getListeners(e){return this.listeners.get(e)||[]}getListenerCount(e){return this.listeners.get(e)?.length||0}getEventTypes(){return Array.from(this.listeners.keys())}generateId(){return Math.random().toString(36).substr(2,9)}cleanupInactiveListeners(e){const t=this.listeners.get(e);if(t){const s=t.filter(e=>e.active);s.length!==t.length&&this.listeners.set(e,s)}}}var r=(e=>(e.STRING="string",e.NUMBER="number",e.BOOLEAN="boolean",e.DATE="date",e.PERCENTAGE="percentage",e.CURRENCY="currency",e.LINK="link",e.FORMULA="formula",e))(r||{}),i=(e=>(e.GENERAL="General",e.NUMBER="#,##0",e.NUMBER_DECIMALS="#,##0.00",e.CURRENCY="$#,##0.00",e.CURRENCY_INTEGER="$#,##0",e.PERCENTAGE="0%",e.PERCENTAGE_DECIMALS="0.00%",e.DATE="dd/mm/yyyy",e.DATE_TIME="dd/mm/yyyy hh:mm",e.TIME="hh:mm:ss",e.CUSTOM="custom",e))(i||{}),o=(e=>(e.LEFT="left",e.CENTER="center",e.RIGHT="right",e.FILL="fill",e.JUSTIFY="justify",e.CENTER_CONTINUOUS="centerContinuous",e.DISTRIBUTED="distributed",e))(o||{}),l=(e=>(e.TOP="top",e.MIDDLE="middle",e.BOTTOM="bottom",e.DISTRIBUTED="distributed",e.JUSTIFY="justify",e))(l||{}),n=(e=>(e.THIN="thin",e.MEDIUM="medium",e.THICK="thick",e.DOTTED="dotted",e.DASHED="dashed",e.DOUBLE="double",e.HAIR="hair",e.MEDIUM_DASHED="mediumDashed",e.DASH_DOT="dashDot",e.MEDIUM_DASH_DOT="mediumDashDot",e.DASH_DOT_DOT="dashDotDot",e.MEDIUM_DASH_DOT_DOT="mediumDashDotDot",e.SLANT_DASH_DOT="slantDashDot",e))(n||{}),a=(e=>(e.NORMAL="normal",e.BOLD="bold",e.ITALIC="italic",e.BOLD_ITALIC="bold italic",e))(a||{}),h=(e=>(e.VALIDATION_ERROR="VALIDATION_ERROR",e.BUILD_ERROR="BUILD_ERROR",e.STYLE_ERROR="STYLE_ERROR",e.WORKSHEET_ERROR="WORKSHEET_ERROR",e.CELL_ERROR="CELL_ERROR",e))(h||{});class d{config;tables=[];currentRow=1;currentCol=1;headerPointers=new Map;isBuilt=!1;headers=[];subHeaders=[];body=[];footers=[];constructor(e){this.config=e}addHeader(e){return this.headers.push(e),this}addSubHeaders(e){return this.subHeaders.push(...e),this}addRow(e){return Array.isArray(e)?this.body.push(...e):this.body.push(e),this}addFooter(e){return Array.isArray(e)?this.footers.push(...e):this.footers.push(e),this}addTable(e={}){const t={name:e.name||`Table_${this.tables.length+1}`,headers:e.headers||[],subHeaders:e.subHeaders||[],body:e.body||[],footers:e.footers||[],showBorders:!1!==e.showBorders,showStripes:!1!==e.showStripes,style:e.style||"TableStyleLight1",...e};return this.tables.push(t),this}finalizeTable(){0===this.tables.length&&this.addTable();const e=this.tables[this.tables.length-1];if(!e)throw new Error("No se pudo obtener la tabla actual");return this.headers.length>0&&(e.headers=[...e.headers||[],...this.headers]),this.subHeaders.length>0&&(e.subHeaders=[...e.subHeaders||[],...this.subHeaders]),this.body.length>0&&(e.body=[...e.body||[],...this.body]),this.footers.length>0&&(e.footers=[...e.footers||[],...this.footers]),this.headers=[],this.subHeaders=[],this.body=[],this.footers=[],this}getTable(e){return this.tables.find(t=>t.name===e)}async build(e,t={}){const s=e.addWorksheet(this.config.name,{properties:{defaultRowHeight:this.config.defaultRowHeight||20,tabColor:this.config.tabColor},pageSetup:this.config.pageSetup});let r=1;if(this.tables.length>0)for(let i=0;i<this.tables.length;i++){const e=this.tables[i];e&&(r=await this.buildTable(s,e,r,i>0))}else r=await this.buildLegacyContent(s,r);this.isBuilt=!0}async buildTable(e,t,s,r=!1){let i=s;if(r&&(i+=2),t.headers&&t.headers.length>0)for(const o of t.headers){if(e.addRow([this.processCellValue(o)]),o.mergeCell){const s=this.calculateTableMaxColumns(t);e.mergeCells(i,1,i,s)}o.styles&&e.getRow(i).eachCell(e=>{e.style=this.convertStyle(o.styles)}),this.applyCellDimensions(e,i,1,o),i++}if(t.subHeaders&&t.subHeaders.length>0&&(i=this.buildNestedHeaders(e,i,t.subHeaders)),t.body&&t.body.length>0)for(const o of t.body)i=this.addDataRowRecursive(e,i,o);if(t.footers&&t.footers.length>0)for(const o of t.footers)i=this.addFooterRow(e,i,o);return(t.showBorders||t.showStripes)&&this.applyTableStyle(e,t,s,i-1),i}async buildLegacyContent(e,t){let s=t;this.headers.length>0&&this.headers.forEach(t=>{e.addRow([this.processCellValue(t)]),t.mergeCell&&e.mergeCells(s,1,s,this.getMaxColumns()||1),t.styles&&e.getRow(s).eachCell(e=>{e.style=this.convertStyle(t.styles)}),this.applyCellDimensions(e,s,1,t),s++}),this.subHeaders.length>0&&(s=this.buildNestedHeaders(e,s,this.subHeaders));for(const r of this.body)s=this.addDataRowRecursive(e,s,r);if(this.footers.length>0)for(const r of this.footers)s=this.addFooterRow(e,s,r);return s}calculateTableMaxColumns(e){let t=0;if(e.subHeaders&&e.subHeaders.length>0)for(const s of e.subHeaders)t+=this.calculateHeaderColSpan(s);return t||1}applyTableStyle(e,t,s,r){const i=this.calculateTableMaxColumns(t);if(t.showBorders)for(let o=s;o<=r;o++)for(let t=1;t<=i;t++){const s=e.getRow(o).getCell(t);s.style||(s.style={}),s.style.border||(s.style.border={top:{style:"thin",color:{argb:"FF8EAADB"}},left:{style:"thin",color:{argb:"FF8EAADB"}},bottom:{style:"thin",color:{argb:"FF8EAADB"}},right:{style:"thin",color:{argb:"FF8EAADB"}}})}if(t.showStripes)for(let o=s;o<=r;o++)if((o-s)%2==1)for(let t=1;t<=i;t++){const s=e.getRow(o).getCell(t);s.style||(s.style={}),s.style.fill||(s.style.fill={type:"pattern",pattern:"solid",fgColor:{argb:"FFF2F2F2"}})}}buildNestedHeaders(e,t,s){let r=t;const i=this.getMaxHeaderDepth(s);for(let o=0;o<i;o++){const t=e.getRow(r);let i=1;for(const l of s)if(0===o){const s=this.getHeaderAtDepth(l,o,i),n=t.getCell(i);n.value=this.processCellValue(l),s.style&&(n.style=this.convertStyle(s.style)),this.applyCellDimensions(e,r,i,l),i+=s.colSpan}else if(l.children&&l.children.length>0)for(const s of l.children){const o=t.getCell(i);o.value=this.processCellValue(s),(s.styles||l.styles)&&(o.style=this.convertStyle(s.styles||l.styles)),this.applyCellDimensions(e,r,i,s),i+=this.calculateHeaderColSpan(s)}else{t.getCell(i).value=null,i+=1}r++}return this.applyAllMerges(e,t,r-1,s),r}getHeaderAtDepth(e,t,s){const r=this.calculateHeaderColSpan(e);if(0===t){const t=r>1?{start:s,end:s+r-1}:null;return{value:"string"==typeof e.value?e.value:String(e.value||""),style:e.styles,colSpan:r,mergeRange:t}}if(e.children&&e.children.length>0){const r=e.children[t];if(r){const t=this.calculateHeaderColSpan(r),i=t>1?{start:s,end:s+t-1}:null;return{value:"string"==typeof r.value?r.value:String(r.value||""),style:r.styles||e.styles,colSpan:t,mergeRange:i}}}return{value:null,style:null,colSpan:1}}applyAllMerges(e,t,s,r){this.getMaxHeaderDepth(r)<=1||this.applySmartMerges(e,t,s,r)}applySmartMerges(e,t,s,r){if(this.getMaxHeaderDepth(r)<=1)return;let i=1;for(const o of r)this.applySmartMergesForHeader(e,t,s,o,i),i+=this.calculateHeaderColSpan(o)}applySmartMergesForHeader(e,t,s,r,i){const o=this.calculateHeaderColSpan(r);if(r.children&&0!==r.children.length){o>1&&e.mergeCells(t,i,t,i+o-1);let l=i;for(const i of r.children)this.applySmartMergesForHeader(e,t+1,s,i,l),l+=this.calculateHeaderColSpan(i)}else e.mergeCells(t,i,s,i+o-1)}calculateHeaderColSpan(e){return e.children&&0!==e.children.length?e.children.reduce((e,t)=>e+this.calculateHeaderColSpan(t),0):1}getMaxHeaderDepth(e){let t=1;for(const s of e)if(s.children&&s.children.length>0){const e=this.getMaxHeaderDepth(s.children);t=Math.max(t,e+1)}return t}getMaxColumns(){let e=0;for(const t of this.subHeaders)e+=this.calculateHeaderColSpan(t);return e}validate(){return this.headers.length||this.body.length?{success:!0,data:!0}:{success:!1,error:{type:h.VALIDATION_ERROR,message:"La hoja no tiene datos"}}}calculateDataColumnPositions(){const e={};let t=1;for(const s of this.subHeaders)if(s.children&&s.children.length>0)for(const r of s.children)r.key&&(e[r.key]=t),r.value&&(e[String(r.value)]=t),t++;else s.key&&(e[s.key]=t),s.value&&(e[String(s.value)]=t),t++;return e}addFooterRow(e,t,s){const r=this.calculateDataColumnPositions();let i;s.key&&r[s.key]?i=r[s.key]:s.header&&r[s.header]&&(i=r[s.header]),void 0===i&&(i=1);const o=e.getRow(t),l=o.getCell(i);if(l.value=this.processCellValue(s),s.styles&&(l.style=this.convertStyle(s.styles)),s.numberFormat&&(l.numFmt=s.numberFormat),this.applyCellDimensions(e,t,i,s),s.mergeCell&&s.mergeTo&&e.mergeCells(t,i,t,s.mergeTo),s.children&&s.children.length>0)for(const n of s.children)if(n){let s;if(n.key&&r[n.key]?s=r[n.key]:n.header&&r[n.header]&&(s=r[n.header]),void 0!==s){const r=o.getCell(s);r.value=this.processCellValue(n),n.styles&&(r.style=this.convertStyle(n.styles)),n.numberFormat&&(r.numFmt=n.numberFormat),this.applyCellDimensions(e,t,s,n)}}return s.jump?t+1:t}applyCellDimensions(e,t,s,r){if(void 0!==r.rowHeight){e.getRow(t).height=r.rowHeight}if(void 0!==r.colWidth){e.getColumn(s).width=r.colWidth}}processCellValue(e){if(e.link||e.type===r.LINK){const t=e.link||("string"==typeof e.value?e.value:"");if(!t||""===t.trim())return e.value;const s=e.mask||e.value||t;return{text:String(s),hyperlink:t}}return e.value}addDataRowRecursive(e,t,s){const r=this.calculateDataColumnPositions();let i;s.key&&r[s.key]?i=r[s.key]:s.header&&r[s.header]&&(i=r[s.header]),void 0===i&&(i=1);const o=e.getRow(t),l=o.getCell(i);if(l.value=this.processCellValue(s),s.styles&&(l.style=this.convertStyle(s.styles)),s.numberFormat&&(l.numFmt=s.numberFormat),this.applyCellDimensions(e,t,i,s),s.children&&s.children.length>0)for(const n of s.children)if(n){let s;if(n.key&&r[n.key]?s=r[n.key]:n.header&&r[n.header]&&(s=r[n.header]),void 0!==s){const r=o.getCell(s);r.value=this.processCellValue(n),n.styles&&(r.style=this.convertStyle(n.styles)),n.numberFormat&&(r.numFmt=n.numberFormat),this.applyCellDimensions(e,t,s,n)}}return s.jump?t+1:t}convertColor(e){if(e){if("object"==typeof e&&e.argb)return e;if("object"==typeof e&&"r"in e&&"g"in e&&"b"in e){return{argb:`FF${e.r.toString(16).padStart(2,"0")}${e.g.toString(16).padStart(2,"0")}${e.b.toString(16).padStart(2,"0")}`.toUpperCase()}}if("string"==typeof e){let t=e.replace("#","");return 3===t.length&&(t=t.split("").map(e=>e+e).join("")),6===t.length&&(t="FF"+t.toUpperCase()),{argb:t}}return"object"==typeof e&&"theme"in e?e:void 0}}convertStyle(e){if(!e)return{};const t={};if(e.font&&(t.font={name:e.font.family||e.font.name,size:e.font.size,bold:e.font.bold,italic:e.font.italic,underline:e.font.underline,color:this.convertColor(e.font.color)}),e.fill){const s=e.fill.pattern||"solid",r="solid"===s?e.fill.backgroundColor||e.fill.foregroundColor:e.fill.foregroundColor||e.fill.backgroundColor,i="solid"!==s?e.fill.backgroundColor:void 0;t.fill={type:e.fill.type||"pattern",pattern:s,fgColor:this.convertColor(r),bgColor:i?this.convertColor(i):void 0},t.fill.bgColor||delete t.fill.bgColor}if(e.border&&(t.border={},e.border.top&&(t.border.top={style:e.border.top.style,color:this.convertColor(e.border.top.color)}),e.border.left&&(t.border.left={style:e.border.left.style,color:this.convertColor(e.border.left.color)}),e.border.bottom&&(t.border.bottom={style:e.border.bottom.style,color:this.convertColor(e.border.bottom.color)}),e.border.right&&(t.border.right={style:e.border.right.style,color:this.convertColor(e.border.right.color)})),e.alignment){if(t.alignment={},void 0!==e.alignment.horizontal){["left","center","right","fill","justify","centerContinuous","distributed"].includes(e.alignment.horizontal)&&(t.alignment.horizontal=e.alignment.horizontal)}if(void 0!==e.alignment.vertical){["top","middle","bottom","distributed","justify"].includes(e.alignment.vertical)&&(t.alignment.vertical=e.alignment.vertical)}if(void 0!==e.alignment.wrapText&&(t.alignment.wrapText=Boolean(e.alignment.wrapText)),void 0!==e.alignment.shrinkToFit&&(t.alignment.shrinkToFit=Boolean(e.alignment.shrinkToFit)),void 0!==e.alignment.indent&&"number"==typeof e.alignment.indent&&(t.alignment.indent=e.alignment.indent),void 0!==e.alignment.textRotation&&"number"==typeof e.alignment.textRotation&&(t.alignment.textRotation=e.alignment.textRotation),void 0!==e.alignment.readingOrder){["left-to-right","right-to-left","context"].includes(e.alignment.readingOrder)&&(t.alignment.readingOrder=e.alignment.readingOrder)}0===Object.keys(t.alignment).length&&delete t.alignment}return e.numFmt&&(t.numFmt=e.numFmt),t}}var c=(e=>(e.WORKSHEET_ADDED="worksheetAdded",e.WORKSHEET_REMOVED="worksheetRemoved",e.WORKSHEET_UPDATED="worksheetUpdated",e.BUILD_STARTED="buildStarted",e.BUILD_PROGRESS="buildProgress",e.BUILD_COMPLETED="buildCompleted",e.BUILD_ERROR="buildError",e.DOWNLOAD_STARTED="downloadStarted",e.DOWNLOAD_PROGRESS="downloadProgress",e.DOWNLOAD_COMPLETED="downloadCompleted",e.DOWNLOAD_ERROR="downloadError",e))(c||{});class u{config;worksheets=new Map;currentWorksheet;isBuilding=!1;stats;eventEmitter;constructor(e={}){this.config={enableValidation:!0,enableEvents:!0,enablePerformanceMonitoring:!1,maxWorksheets:255,maxRowsPerWorksheet:1048576,maxColumnsPerWorksheet:16384,memoryLimit:104857600,...e},this.stats=this.initializeStats(),this.eventEmitter=new s}addWorksheet(e,t={}){if(this.worksheets.has(e))throw new Error(`Worksheet "${e}" already exists`);const s={name:e,defaultRowHeight:20,defaultColWidth:10,...this.config.defaultWorksheetConfig,...t},r=new d(s);return this.worksheets.set(e,r),this.currentWorksheet=r,this.emitEvent(c.WORKSHEET_ADDED,{worksheetName:e}),r}getWorksheet(e){return this.worksheets.get(e)}removeWorksheet(e){const t=this.worksheets.get(e);return!!t&&(this.worksheets.delete(e),this.currentWorksheet===t&&(this.currentWorksheet=void 0),this.emitEvent(c.WORKSHEET_REMOVED,{worksheetName:e}),!0)}setCurrentWorksheet(e){const t=this.worksheets.get(e);return!!t&&(this.currentWorksheet=t,!0)}async build(t={}){if(this.isBuilding)return{success:!1,error:{type:h.BUILD_ERROR,message:"Build already in progress",stack:(new Error).stack||""}};this.isBuilding=!0;const s=Date.now();try{this.emitEvent(c.BUILD_STARTED);const r=new e.Workbook;this.config.metadata&&(r.creator=this.config.metadata.author||"Han Excel Builder",r.lastModifiedBy=this.config.metadata.author||"Han Excel Builder",r.created=this.config.metadata.created||new Date,r.modified=this.config.metadata.modified||new Date,this.config.metadata.title&&(r.title=this.config.metadata.title),this.config.metadata.subject&&(r.subject=this.config.metadata.subject),this.config.metadata.keywords&&(r.keywords=this.config.metadata.keywords),this.config.metadata.category&&(r.category=this.config.metadata.category),this.config.metadata.description&&(r.description=this.config.metadata.description));for(const e of this.worksheets.values())await e.build(r,t);const i=await r.xlsx.writeBuffer({compression:t.compressionLevel||6}),o=Date.now();this.stats.buildTime=o-s,this.stats.fileSize=i.byteLength;const l={success:!0,data:i};return this.emitEvent(c.BUILD_COMPLETED,{buildTime:this.stats.buildTime,fileSize:this.stats.fileSize}),l}catch(r){const e={success:!1,error:{type:h.BUILD_ERROR,message:r instanceof Error?r.message:"Unknown build error",stack:r instanceof Error&&r.stack||""}};return this.emitEvent(c.BUILD_ERROR,{error:e.error}),e}finally{this.isBuilding=!1}}async generateAndDownload(e,s={}){const r=await this.build(s);if(!r.success)return r;try{this.emitEvent(c.DOWNLOAD_STARTED,{fileName:e});const i=new Blob([r.data],{type:s.mimeType||"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});return t(i,e),this.emitEvent(c.DOWNLOAD_COMPLETED,{fileName:e}),{success:!0,data:void 0}}catch(i){const e={success:!1,error:{type:h.BUILD_ERROR,message:i instanceof Error?i.message:"Download failed",stack:i instanceof Error&&i.stack||""}};return this.emitEvent(c.DOWNLOAD_ERROR,{error:e.error}),e}}async toBuffer(e={}){return this.build(e)}async toBlob(e={}){const t=await this.build(e);if(!t.success)return t;return{success:!0,data:new Blob([t.data],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"})}}validate(){const e=[];0===this.worksheets.size&&e.push("No worksheets found");for(const[t,s]of this.worksheets.entries()){const r=s.validate();r.success||e.push(`Worksheet "${t}": ${r.error?.message}`)}return e.length>0?{success:!1,error:{type:h.VALIDATION_ERROR,message:e.join("; "),stack:(new Error).stack||""}}:{success:!0,data:!0}}clear(){this.worksheets.clear(),this.currentWorksheet=void 0}getStats(){return{...this.stats}}on(e,t){return this.eventEmitter.on(e,t)}off(e,t){return this.eventEmitter.off(e,t)}removeAllListeners(e){e?this.eventEmitter.offAll(e):this.eventEmitter.clear()}emitEvent(e,t){const s={type:e,data:t||{},timestamp:new Date};this.eventEmitter.emitSync(s)}initializeStats(){return{totalWorksheets:0,totalCells:0,memoryUsage:0,buildTime:0,fileSize:0,stylesUsed:0,formulasUsed:0,conditionalFormatsUsed:0,performance:{headersTime:0,dataTime:0,stylesTime:0,writeTime:0}}}}class y{style={};constructor(){this.style.alignment={horizontal:o.CENTER,vertical:l.MIDDLE,wrapText:!0,shrinkToFit:!0}}static create(){return new y}fontName(e){return this.style.font||(this.style.font={}),this.style.font.name=e,this}fontSize(e){return this.style.font||(this.style.font={}),this.style.font.size=e,this}fontStyle(e){return this.style.font||(this.style.font={}),this.style.font.style=e,this}fontColor(e){return this.style.font||(this.style.font={}),this.style.font.color=e,this}fontBold(){return this.style.font||(this.style.font={}),this.style.font.bold=!0,this}fontItalic(){return this.style.font||(this.style.font={}),this.style.font.italic=!0,this}fontUnderline(){return this.style.font||(this.style.font={}),this.style.font.underline=!0,this}border(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.top=s,this.style.border.left=s,this.style.border.bottom=s,this.style.border.right=s,this}borderTop(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.top=s,this}borderLeft(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.left=s,this}borderBottom(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.bottom=s,this}borderRight(e,t){this.style.border||(this.style.border={});const s={style:e};return void 0!==t&&(s.color=t),this.style.border.right=s,this}backgroundColor(e){return this.style.fill||(this.style.fill={type:"pattern"}),this.style.fill.backgroundColor=e,this.style.fill.pattern="solid",this}horizontalAlign(e){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=e,this}verticalAlign(e){return this.style.alignment||(this.style.alignment={}),this.style.alignment.vertical=e,this}centerAlign(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=o.CENTER,this.style.alignment.vertical=l.MIDDLE,this}leftAlign(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=o.LEFT,this}rightAlign(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.horizontal=o.RIGHT,this}wrapText(){return this.style.alignment||(this.style.alignment={}),this.style.alignment.wrapText=!0,this}numberFormat(e){return this.style.numberFormat=e,this}striped(){return this.style.striped=!0,this}conditionalFormat(e){return this.style.conditionalFormats||(this.style.conditionalFormats=[]),this.style.conditionalFormats.push(e),this}build(){return this.style}reset(){return this.style={},this.style.alignment={horizontal:o.CENTER,vertical:l.MIDDLE,wrapText:!0},this}clone(){const e=new y;return e.style=JSON.parse(JSON.stringify(this.style)),e}}var f=(e=>(e.CREATED="created",e.UPDATED="updated",e.DELETED="deleted",e.STYLED="styled",e.VALIDATED="validated",e))(f||{}),g=(e=>(e.CREATED="created",e.UPDATED="updated",e.DELETED="deleted",e.TABLE_ADDED="tableAdded",e.TABLE_REMOVED="tableRemoved",e.CELL_ADDED="cellAdded",e.CELL_UPDATED="cellUpdated",e.CELL_DELETED="cellDeleted",e))(g||{}),m=(e=>(e.HEADER="header",e.SUBHEADER="subheader",e.DATA="data",e.FOOTER="footer",e.TOTAL="total",e.HIGHLIGHT="highlight",e.WARNING="warning",e.ERROR="error",e.SUCCESS="success",e.INFO="info",e))(m||{});exports.BorderStyle=n,exports.BuilderEventType=c,exports.CellEventType=f,exports.CellType=r,exports.ErrorType=h,exports.EventEmitter=s,exports.ExcelBuilder=u,exports.FontStyle=a,exports.HorizontalAlignment=o,exports.NumberFormat=i,exports.StyleBuilder=y,exports.StylePreset=m,exports.VerticalAlignment=l,exports.Worksheet=d,exports.WorksheetEventType=g,exports.default=u;
|
|
2
2
|
//# sourceMappingURL=han-excel.cjs.js.map
|