@cj-tech-master/excelts 6.2.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +45 -17
  2. package/README_zh.md +43 -15
  3. package/dist/browser/index.browser.d.ts +1 -1
  4. package/dist/browser/index.browser.js +1 -1
  5. package/dist/browser/index.d.ts +2 -2
  6. package/dist/browser/index.js +1 -1
  7. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +0 -2
  8. package/dist/browser/modules/excel/stream/workbook-writer.d.ts +2 -2
  9. package/dist/browser/modules/excel/types.d.ts +0 -2
  10. package/dist/browser/modules/pdf/excel-bridge.d.ts +29 -0
  11. package/dist/browser/modules/pdf/excel-bridge.js +423 -0
  12. package/dist/browser/modules/pdf/index.d.ts +22 -24
  13. package/dist/browser/modules/pdf/index.js +22 -25
  14. package/dist/browser/modules/pdf/pdf.d.ts +121 -0
  15. package/dist/browser/modules/pdf/pdf.js +255 -0
  16. package/dist/browser/modules/pdf/render/layout-engine.d.ts +10 -8
  17. package/dist/browser/modules/pdf/render/layout-engine.js +115 -209
  18. package/dist/browser/modules/pdf/render/pdf-exporter.d.ts +9 -62
  19. package/dist/browser/modules/pdf/render/pdf-exporter.js +38 -78
  20. package/dist/browser/modules/pdf/render/style-converter.d.ts +20 -18
  21. package/dist/browser/modules/pdf/render/style-converter.js +24 -23
  22. package/dist/browser/modules/pdf/types.d.ts +193 -11
  23. package/dist/browser/modules/pdf/types.js +22 -1
  24. package/dist/cjs/index.js +3 -3
  25. package/dist/cjs/modules/pdf/excel-bridge.js +426 -0
  26. package/dist/cjs/modules/pdf/index.js +25 -28
  27. package/dist/cjs/modules/pdf/pdf.js +258 -0
  28. package/dist/cjs/modules/pdf/render/layout-engine.js +116 -210
  29. package/dist/cjs/modules/pdf/render/pdf-exporter.js +37 -79
  30. package/dist/cjs/modules/pdf/render/style-converter.js +24 -23
  31. package/dist/cjs/modules/pdf/types.js +23 -2
  32. package/dist/esm/index.browser.js +1 -1
  33. package/dist/esm/index.js +1 -1
  34. package/dist/esm/modules/pdf/excel-bridge.js +423 -0
  35. package/dist/esm/modules/pdf/index.js +22 -25
  36. package/dist/esm/modules/pdf/pdf.js +255 -0
  37. package/dist/esm/modules/pdf/render/layout-engine.js +115 -209
  38. package/dist/esm/modules/pdf/render/pdf-exporter.js +38 -78
  39. package/dist/esm/modules/pdf/render/style-converter.js +24 -23
  40. package/dist/esm/modules/pdf/types.js +22 -1
  41. package/dist/iife/excelts.iife.js +728 -251
  42. package/dist/iife/excelts.iife.js.map +1 -1
  43. package/dist/iife/excelts.iife.min.js +34 -34
  44. package/dist/types/index.browser.d.ts +1 -1
  45. package/dist/types/index.d.ts +2 -2
  46. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +0 -2
  47. package/dist/types/modules/excel/stream/workbook-writer.d.ts +2 -2
  48. package/dist/types/modules/excel/types.d.ts +0 -2
  49. package/dist/types/modules/pdf/excel-bridge.d.ts +29 -0
  50. package/dist/types/modules/pdf/index.d.ts +22 -24
  51. package/dist/types/modules/pdf/pdf.d.ts +121 -0
  52. package/dist/types/modules/pdf/render/layout-engine.d.ts +10 -8
  53. package/dist/types/modules/pdf/render/pdf-exporter.d.ts +9 -62
  54. package/dist/types/modules/pdf/render/style-converter.d.ts +20 -18
  55. package/dist/types/modules/pdf/types.d.ts +193 -11
  56. package/package.json +1 -1
package/README.md CHANGED
@@ -6,15 +6,12 @@ Modern TypeScript Excel Workbook Manager - Read, manipulate and write spreadshee
6
6
 
7
7
  ## About This Project
8
8
 
9
- ExcelTS is a modern TypeScript Excel workbook manager with:
9
+ ExcelTS is a zero-dependency TypeScript toolkit for spreadsheets and documents:
10
10
 
11
- - 🚀 **Zero Runtime Dependencies** - Pure TypeScript implementation with no external packages
12
- - **Broad Runtime Support** - LTS Node.js, Bun, and modern browsers (Chrome, Firefox, Safari, Edge)
13
- - ✅ **Full TypeScript Support** - Complete type definitions and modern TypeScript patterns
14
- - ✅ **Modern Build System** - Using Rolldown for faster builds
15
- - ✅ **Enhanced Testing** - Migrated to Vitest with browser testing support
16
- - ✅ **ESM First** - Native ES Module support with CommonJS compatibility
17
- - ✅ **Named Exports** - All exports are named for better tree-shaking
11
+ - 🚀 **Zero Runtime Dependencies** Pure TypeScript, no external packages
12
+ - 📦 **Five Modules** Excel (XLSX/JSON), PDF (standalone engine + Excel bridge), CSV (RFC 4180), Archive (ZIP/TAR), Stream (cross-platform)
13
+ - ✅ **Cross-Platform** Node.js 22+, Bun, Chrome 89+, Firefox 102+, Safari 14.1+
14
+ - ✅ **ESM First** Native ES Modules with CommonJS compatibility and full tree-shaking
18
15
 
19
16
  ## Translations
20
17
 
@@ -104,7 +101,7 @@ cell.fill = {
104
101
  - Pivot tables
105
102
 
106
103
  - **PDF Export**
107
- - Zero-dependency Excel-to-PDF conversion
104
+ - Full-featured, zero-dependency PDF engine (standalone or with Excel)
108
105
  - Full cell styling (fonts, colors, borders, fills, alignment)
109
106
  - Automatic pagination with repeat header rows
110
107
  - TrueType font embedding for Unicode/CJK text
@@ -141,7 +138,7 @@ import { Readable, pipeline, createTransform } from "@cj-tech-master/excelts/str
141
138
 
142
139
  Each subpath supports `browser`, `import` (ESM), and `require` (CJS) conditions. See the module READMEs for details:
143
140
 
144
- - [PDF Module](src/modules/pdf/README.md) - Zero-dependency Excel-to-PDF export with encryption and font embedding
141
+ - [PDF Module](src/modules/pdf/README.md) - Full-featured zero-dependency PDF engine with encryption and font embedding
145
142
  - [CSV Module](src/modules/csv/README.md) - RFC 4180 parser/formatter, streaming, data generation
146
143
  - [Archive Module](src/modules/archive/README.md) - ZIP/TAR create/read/edit, compression, encryption
147
144
  - [Stream Module](src/modules/stream/README.md) - Cross-platform Readable/Writable/Transform/Duplex
@@ -151,7 +148,7 @@ Each subpath supports `browser`, `import` (ESM), and `require` (CJS) conditions.
151
148
  Export any workbook to PDF with zero external dependencies:
152
149
 
153
150
  ```javascript
154
- import { Workbook, exportPdf } from "@cj-tech-master/excelts";
151
+ import { Workbook, excelToPdf } from "@cj-tech-master/excelts";
155
152
 
156
153
  const workbook = new Workbook();
157
154
  const sheet = workbook.addWorksheet("Report");
@@ -163,7 +160,7 @@ sheet.addRow({ product: "Widget", revenue: 1000 });
163
160
  sheet.getColumn("revenue").numFmt = "$#,##0.00";
164
161
 
165
162
  // One-line export
166
- const pdf = exportPdf(workbook, {
163
+ const pdf = excelToPdf(workbook, {
167
164
  showGridLines: true,
168
165
  showPageNumbers: true,
169
166
  title: "Sales Report"
@@ -184,13 +181,13 @@ window.open(url);
184
181
  ```javascript
185
182
  const workbook = new Workbook();
186
183
  await workbook.xlsx.readFile("input.xlsx");
187
- const pdf = exportPdf(workbook);
184
+ const pdf = excelToPdf(workbook);
188
185
  ```
189
186
 
190
187
  ### Encryption
191
188
 
192
189
  ```javascript
193
- const pdf = exportPdf(workbook, {
190
+ const pdf = excelToPdf(workbook, {
194
191
  encryption: {
195
192
  ownerPassword: "admin",
196
193
  userPassword: "reader",
@@ -204,11 +201,42 @@ const pdf = exportPdf(workbook, {
204
201
  ```javascript
205
202
  import { readFileSync } from "fs";
206
203
 
207
- const pdf = exportPdf(workbook, {
204
+ const pdf = excelToPdf(workbook, {
208
205
  font: readFileSync("NotoSansSC-Regular.ttf") // TrueType font for CJK text
209
206
  });
210
207
  ```
211
208
 
209
+ ### Standalone PDF (No Excel)
210
+
211
+ Generate PDFs from plain data — no workbook, no Map objects, no boilerplate:
212
+
213
+ ```javascript
214
+ import { pdf } from "@cj-tech-master/excelts/pdf";
215
+
216
+ // Simplest — pass a 2D array
217
+ const bytes = pdf([
218
+ ["Product", "Revenue"],
219
+ ["Widget", 1000],
220
+ ["Gadget", 2500]
221
+ ]);
222
+
223
+ // With column widths and styled cells
224
+ const bytes = pdf(
225
+ {
226
+ name: "Report",
227
+ columns: [
228
+ { width: 25, header: "Product" },
229
+ { width: 15, header: "Revenue" }
230
+ ],
231
+ data: [
232
+ ["Widget", 1000],
233
+ ["Gadget", 2500]
234
+ ]
235
+ },
236
+ { showGridLines: true }
237
+ );
238
+ ```
239
+
212
240
  For the full API reference and all options, see the [PDF Module documentation](src/modules/pdf/README.md).
213
241
 
214
242
  ## Archive Utilities (ZIP/TAR)
@@ -506,8 +534,8 @@ import {
506
534
  xmlDecode,
507
535
 
508
536
  // PDF export
509
- exportPdf, // Workbook -> Uint8Array (PDF)
510
- PdfExporter, // Class-based PDF export
537
+ pdf, // Simplest: pdf([["A", 1], ["B", 2]]) → Uint8Array
538
+ excelToPdf, // Workbook -> Uint8Array (Excel-to-PDF)
511
539
  PageSizes, // Built-in page size definitions
512
540
  PdfError, // Base PDF error
513
541
  PdfRenderError, // Layout/rendering failures
package/README_zh.md CHANGED
@@ -6,15 +6,12 @@
6
6
 
7
7
  ## 关于本项目
8
8
 
9
- ExcelTS 是现代化的 TypeScript Excel 工作簿管理器,具有以下特性:
9
+ ExcelTS 是零依赖的 TypeScript 电子表格与文档工具包:
10
10
 
11
- - 🚀 **零运行时依赖** - 纯 TypeScript 实现,无任何外部包依赖
12
- - **广泛运行时支持** - 支持 LTS Node.js、Bun 及主流最新浏览器(Chrome、Firefox、Safari、Edge)
13
- - ✅ **完整的 TypeScript 支持** - 完整的类型定义和现代 TypeScript 模式
14
- - ✅ **现代构建系统** - 使用 Rolldown 进行更快的构建
15
- - ✅ **增强的测试** - 迁移到 Vitest 并支持浏览器测试
16
- - ✅ **ESM 优先** - 原生 ES Module 支持,兼容 CommonJS
17
- - ✅ **命名导出** - 所有导出都是命名导出,更好的 tree-shaking
11
+ - 🚀 **零运行时依赖** 纯 TypeScript 实现,无任何外部包依赖
12
+ - 📦 **五大模块** Excel(XLSX/JSON)、PDF(独立引擎 + Excel 桥接)、CSV(RFC 4180)、Archive(ZIP/TAR)、Stream(跨平台)
13
+ - ✅ **跨平台** Node.js 22+、Bun、Chrome 89+、Firefox 102+、Safari 14.1+
14
+ - ✅ **ESM 优先** 原生 ES Modules,兼容 CommonJS,完整 tree-shaking 支持
18
15
 
19
16
  ## 翻译
20
17
 
@@ -151,7 +148,7 @@ import { Readable, pipeline, createTransform } from "@cj-tech-master/excelts/str
151
148
  零依赖将任意工作簿导出为 PDF:
152
149
 
153
150
  ```javascript
154
- import { Workbook, exportPdf } from "@cj-tech-master/excelts";
151
+ import { Workbook, excelToPdf } from "@cj-tech-master/excelts";
155
152
 
156
153
  const workbook = new Workbook();
157
154
  const sheet = workbook.addWorksheet("报告");
@@ -163,7 +160,7 @@ sheet.addRow({ product: "组件A", revenue: 1000 });
163
160
  sheet.getColumn("revenue").numFmt = "¥#,##0.00";
164
161
 
165
162
  // 一行导出
166
- const pdf = exportPdf(workbook, {
163
+ const pdf = excelToPdf(workbook, {
167
164
  showGridLines: true,
168
165
  showPageNumbers: true,
169
166
  title: "销售报告"
@@ -184,13 +181,13 @@ window.open(url);
184
181
  ```javascript
185
182
  const workbook = new Workbook();
186
183
  await workbook.xlsx.readFile("input.xlsx");
187
- const pdf = exportPdf(workbook);
184
+ const pdf = excelToPdf(workbook);
188
185
  ```
189
186
 
190
187
  ### 加密
191
188
 
192
189
  ```javascript
193
- const pdf = exportPdf(workbook, {
190
+ const pdf = excelToPdf(workbook, {
194
191
  encryption: {
195
192
  ownerPassword: "admin",
196
193
  userPassword: "reader",
@@ -204,11 +201,42 @@ const pdf = exportPdf(workbook, {
204
201
  ```javascript
205
202
  import { readFileSync } from "fs";
206
203
 
207
- const pdf = exportPdf(workbook, {
204
+ const pdf = excelToPdf(workbook, {
208
205
  font: readFileSync("NotoSansSC-Regular.ttf") // 嵌入 TrueType 字体以支持中文
209
206
  });
210
207
  ```
211
208
 
209
+ ### 独立 PDF 生成(无需 Excel)
210
+
211
+ 无需工作簿,直接从数组数据生成 PDF:
212
+
213
+ ```javascript
214
+ import { pdf } from "@cj-tech-master/excelts/pdf";
215
+
216
+ // 最简方式 — 传入二维数组
217
+ const bytes = pdf([
218
+ ["产品", "收入"],
219
+ ["组件A", 1000],
220
+ ["组件B", 2500]
221
+ ]);
222
+
223
+ // 带列宽和样式
224
+ const bytes = pdf(
225
+ {
226
+ name: "报告",
227
+ columns: [
228
+ { width: 25, header: "产品" },
229
+ { width: 15, header: "收入" }
230
+ ],
231
+ data: [
232
+ ["组件A", 1000],
233
+ ["组件B", 2500]
234
+ ]
235
+ },
236
+ { showGridLines: true }
237
+ );
238
+ ```
239
+
212
240
  完整 API 参考和所有选项请查看 [PDF 模块文档](src/modules/pdf/README.md)。
213
241
 
214
242
  ## 归档工具(ZIP/TAR)
@@ -504,8 +532,8 @@ import {
504
532
  xmlDecode,
505
533
 
506
534
  // PDF 导出
507
- exportPdf, // Workbook -> Uint8Array (PDF)
508
- PdfExporter, // 基于类的 PDF 导出
535
+ pdf, // 最简单:pdf([["A", 1], ["B", 2]]) → Uint8Array
536
+ excelToPdf, // Workbook -> Uint8Array(Excel 转 PDF
509
537
  PageSizes, // 内置页面尺寸定义
510
538
  PdfError, // PDF 基础错误
511
539
  PdfRenderError, // 布局/渲染错误
@@ -37,6 +37,6 @@ export { xmlEncode, xmlDecode } from "./utils/utils.base.js";
37
37
  export { DateParser, DateFormatter, getSupportedFormats, type DateFormat } from "./utils/datetime.js";
38
38
  export { BaseError, type BaseErrorOptions, toError, errorToJSON, getErrorChain, getRootCause } from "./utils/errors.js";
39
39
  export { concatUint8Arrays, toUint8Array, stringToUint8Array, uint8ArrayToString } from "./utils/binary.js";
40
- export { PdfExporter, exportPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
40
+ export { pdf, excelToPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
41
41
  export type { PdfExportOptions, PdfPageSize, PdfOrientation, PdfMargins, PageSizeName, PdfColor } from "./modules/pdf/index.js";
42
42
  export { ExcelError, isExcelError, ExcelFileError, ExcelDownloadError, ExcelNotSupportedError, ExcelStreamStateError, InvalidAddressError, ColumnOutOfBoundsError, RowOutOfBoundsError, MergeConflictError, InvalidValueTypeError, XmlParseError, WorksheetNameError, PivotTableError, TableError, ImageError, MaxItemsExceededError } from "./modules/excel/errors.js";
@@ -58,7 +58,7 @@ export { concatUint8Arrays, toUint8Array, stringToUint8Array, uint8ArrayToString
58
58
  // =============================================================================
59
59
  // PDF Export (Browser-compatible, zero external dependencies)
60
60
  // =============================================================================
61
- export { PdfExporter, exportPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
61
+ export { pdf, excelToPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
62
62
  // =============================================================================
63
63
  // Errors
64
64
  // =============================================================================
@@ -19,7 +19,7 @@ export type { PivotTable, PivotTableModel, PivotTableValue, PivotTableSource, Ca
19
19
  export type { FormCheckboxModel, FormCheckboxOptions, FormControlRange, FormControlAnchor } from "./modules/excel/form-control.js";
20
20
  export type { WorkbookReaderOptions, ParseEvent, SharedStringEvent, WorksheetReadyEvent, HyperlinksEvent } from "./modules/excel/stream/workbook-reader.js";
21
21
  export type { WorksheetReaderOptions, WorksheetEvent, RowEvent, HyperlinkEvent, WorksheetHyperlink } from "./modules/excel/stream/worksheet-reader.js";
22
- export type { WorkbookWriterOptions, WorkbookZipOptions, ZipOptions, ZlibOptions } from "./modules/excel/stream/workbook-writer.js";
22
+ export type { WorkbookWriterOptions, WorkbookZipOptions, ZlibOptions } from "./modules/excel/stream/workbook-writer.js";
23
23
  export type { CsvOptions, CsvInput } from "./modules/excel/workbook.js";
24
24
  export { CsvParserStream, CsvFormatterStream, createCsvParserStream, createCsvFormatterStream } from "./modules/csv/stream/index.js";
25
25
  export { DefinedNames, type DefinedNameModel } from "./modules/excel/defined-names.js";
@@ -37,6 +37,6 @@ export { xmlEncode, xmlDecode } from "./utils/utils.base.js";
37
37
  export { DateParser, DateFormatter, getSupportedFormats, type DateFormat } from "./utils/datetime.js";
38
38
  export { BaseError, type BaseErrorOptions, toError, errorToJSON, getErrorChain, getRootCause } from "./utils/errors.js";
39
39
  export { concatUint8Arrays, toUint8Array, stringToUint8Array, uint8ArrayToString } from "./utils/binary.js";
40
- export { PdfExporter, exportPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
40
+ export { pdf, excelToPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
41
41
  export type { PdfExportOptions, PdfPageSize, PdfOrientation, PdfMargins, PageSizeName, PdfColor } from "./modules/pdf/index.js";
42
42
  export { ExcelError, isExcelError, ExcelFileError, ExcelDownloadError, ExcelNotSupportedError, ExcelStreamStateError, InvalidAddressError, ColumnOutOfBoundsError, RowOutOfBoundsError, MergeConflictError, InvalidValueTypeError, XmlParseError, WorksheetNameError, PivotTableError, TableError, ImageError, MaxItemsExceededError } from "./modules/excel/errors.js";
@@ -54,7 +54,7 @@ export { concatUint8Arrays, toUint8Array, stringToUint8Array, uint8ArrayToString
54
54
  // =============================================================================
55
55
  // PDF Export
56
56
  // =============================================================================
57
- export { PdfExporter, exportPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
57
+ export { pdf, excelToPdf, PageSizes, PdfError, PdfRenderError, PdfFontError, PdfStructureError, isPdfError } from "./modules/pdf/index.js";
58
58
  // =============================================================================
59
59
  // Errors
60
60
  // =============================================================================
@@ -42,8 +42,6 @@ export interface WorkbookZipOptions {
42
42
  level?: number;
43
43
  };
44
44
  }
45
- /** @deprecated Use {@link WorkbookZipOptions} instead */
46
- export type ZipOptions = WorkbookZipOptions;
47
45
  export interface WorkbookWriterOptions {
48
46
  created?: Date;
49
47
  modified?: Date;
@@ -4,8 +4,8 @@
4
4
  * Extends base with file path support and file system image loading.
5
5
  */
6
6
  import { WorksheetWriter } from "./worksheet-writer.js";
7
- import { WorkbookWriterBase, type WorkbookWriterOptions as BaseOptions, type WorkbookZipOptions, type ZipOptions, type ZlibOptions } from "./workbook-writer.browser.js";
8
- export type { WorkbookZipOptions, ZipOptions, ZlibOptions };
7
+ import { WorkbookWriterBase, type WorkbookWriterOptions as BaseOptions, type WorkbookZipOptions, type ZlibOptions } from "./workbook-writer.browser.js";
8
+ export type { WorkbookZipOptions, ZlibOptions };
9
9
  export interface WorkbookWriterOptions extends BaseOptions {
10
10
  /** If stream not specified, this field specifies the path to a file to write the XLSX workbook to */
11
11
  filename?: string;
@@ -326,8 +326,6 @@ export interface ImageData {
326
326
  filename?: string;
327
327
  buffer?: Buffer;
328
328
  }
329
- /** @deprecated Use {@link ImageData} instead */
330
- export type Image = ImageData;
331
329
  export interface ImagePosition {
332
330
  tl: {
333
331
  col: number;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Excel-to-PDF Bridge
3
+ *
4
+ * Converts Excel Workbook data into the PDF module's independent data model.
5
+ * This is the ONLY file in the PDF module that imports from @excel.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { Workbook } from "excelts";
10
+ * import { excelToPdf } from "excelts/pdf";
11
+ *
12
+ * const workbook = new Workbook();
13
+ * // ... build workbook ...
14
+ * const pdf = excelToPdf(workbook);
15
+ * ```
16
+ */
17
+ import type { Workbook } from "../excel/workbook.js";
18
+ import { type PdfExportOptions } from "./types.js";
19
+ /**
20
+ * Export an Excel Workbook directly to PDF.
21
+ *
22
+ * This is a convenience function that converts the Workbook to the PDF module's
23
+ * data model and then generates the PDF.
24
+ *
25
+ * @param workbook - An Excel Workbook instance
26
+ * @param options - PDF export options
27
+ * @returns PDF file as a Uint8Array
28
+ */
29
+ export declare function excelToPdf(workbook: Workbook, options?: PdfExportOptions): Uint8Array;