@cj-tech-master/excelts 8.1.2 → 9.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.
- package/README.md +2 -2
- package/README_zh.md +2 -2
- package/dist/browser/modules/excel/cell.js +11 -7
- package/dist/browser/modules/excel/column.js +7 -6
- package/dist/browser/modules/excel/row.js +5 -1
- package/dist/browser/modules/excel/stream/worksheet-reader.js +3 -2
- package/dist/browser/modules/excel/utils/cell-format.js +64 -2
- package/dist/browser/modules/pdf/excel-bridge.d.ts +4 -3
- package/dist/browser/modules/pdf/excel-bridge.js +18 -5
- package/dist/browser/modules/pdf/index.d.ts +3 -3
- package/dist/browser/modules/pdf/index.js +3 -3
- package/dist/browser/modules/pdf/pdf.d.ts +7 -6
- package/dist/browser/modules/pdf/pdf.js +7 -6
- package/dist/browser/modules/pdf/reader/pdf-reader.d.ts +8 -7
- package/dist/browser/modules/pdf/reader/pdf-reader.js +81 -74
- package/dist/browser/modules/pdf/render/constants.d.ts +30 -0
- package/dist/browser/modules/pdf/render/constants.js +30 -0
- package/dist/browser/modules/pdf/render/layout-engine.d.ts +2 -1
- package/dist/browser/modules/pdf/render/layout-engine.js +359 -156
- package/dist/browser/modules/pdf/render/page-renderer.d.ts +2 -2
- package/dist/browser/modules/pdf/render/page-renderer.js +245 -107
- package/dist/browser/modules/pdf/render/pdf-exporter.d.ts +3 -2
- package/dist/browser/modules/pdf/render/pdf-exporter.js +145 -105
- package/dist/browser/modules/pdf/render/style-converter.js +27 -26
- package/dist/browser/modules/pdf/types.d.ts +8 -0
- package/dist/browser/utils/utils.base.d.ts +5 -0
- package/dist/browser/utils/utils.base.js +10 -0
- package/dist/cjs/modules/excel/cell.js +11 -7
- package/dist/cjs/modules/excel/column.js +7 -6
- package/dist/cjs/modules/excel/row.js +5 -1
- package/dist/cjs/modules/excel/stream/worksheet-reader.js +3 -2
- package/dist/cjs/modules/excel/utils/cell-format.js +64 -2
- package/dist/cjs/modules/pdf/excel-bridge.js +18 -5
- package/dist/cjs/modules/pdf/index.js +3 -3
- package/dist/cjs/modules/pdf/pdf.js +7 -6
- package/dist/cjs/modules/pdf/reader/pdf-reader.js +81 -74
- package/dist/cjs/modules/pdf/render/constants.js +33 -0
- package/dist/cjs/modules/pdf/render/layout-engine.js +359 -156
- package/dist/cjs/modules/pdf/render/page-renderer.js +245 -107
- package/dist/cjs/modules/pdf/render/pdf-exporter.js +145 -105
- package/dist/cjs/modules/pdf/render/style-converter.js +27 -26
- package/dist/cjs/utils/utils.base.js +11 -0
- package/dist/esm/modules/excel/cell.js +11 -7
- package/dist/esm/modules/excel/column.js +7 -6
- package/dist/esm/modules/excel/row.js +5 -1
- package/dist/esm/modules/excel/stream/worksheet-reader.js +3 -2
- package/dist/esm/modules/excel/utils/cell-format.js +64 -2
- package/dist/esm/modules/pdf/excel-bridge.js +18 -5
- package/dist/esm/modules/pdf/index.js +3 -3
- package/dist/esm/modules/pdf/pdf.js +7 -6
- package/dist/esm/modules/pdf/reader/pdf-reader.js +81 -74
- package/dist/esm/modules/pdf/render/constants.js +30 -0
- package/dist/esm/modules/pdf/render/layout-engine.js +359 -156
- package/dist/esm/modules/pdf/render/page-renderer.js +245 -107
- package/dist/esm/modules/pdf/render/pdf-exporter.js +145 -105
- package/dist/esm/modules/pdf/render/style-converter.js +27 -26
- package/dist/esm/utils/utils.base.js +10 -0
- package/dist/iife/excelts.iife.js +1022 -677
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +48 -48
- package/dist/types/modules/pdf/excel-bridge.d.ts +4 -3
- package/dist/types/modules/pdf/index.d.ts +3 -3
- package/dist/types/modules/pdf/pdf.d.ts +7 -6
- package/dist/types/modules/pdf/reader/pdf-reader.d.ts +8 -7
- package/dist/types/modules/pdf/render/constants.d.ts +30 -0
- package/dist/types/modules/pdf/render/layout-engine.d.ts +2 -1
- package/dist/types/modules/pdf/render/page-renderer.d.ts +2 -2
- package/dist/types/modules/pdf/render/pdf-exporter.d.ts +3 -2
- package/dist/types/modules/pdf/types.d.ts +8 -0
- package/dist/types/utils/utils.base.d.ts +5 -0
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*
|
|
12
12
|
* const workbook = new Workbook();
|
|
13
13
|
* // ... build workbook ...
|
|
14
|
-
* const pdf = excelToPdf(workbook);
|
|
14
|
+
* const pdf = await excelToPdf(workbook);
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
import type { Workbook } from "../excel/workbook.js";
|
|
@@ -21,9 +21,10 @@ import { type PdfExportOptions } from "./types.js";
|
|
|
21
21
|
*
|
|
22
22
|
* This is a convenience function that converts the Workbook to the PDF module's
|
|
23
23
|
* data model and then generates the PDF.
|
|
24
|
+
* Yields to the event loop between each output page during layout and rendering.
|
|
24
25
|
*
|
|
25
26
|
* @param workbook - An Excel Workbook instance
|
|
26
27
|
* @param options - PDF export options
|
|
27
|
-
* @returns PDF file as a Uint8Array
|
|
28
|
+
* @returns Promise of PDF file as a Uint8Array
|
|
28
29
|
*/
|
|
29
|
-
export declare function excelToPdf(workbook: Workbook, options?: PdfExportOptions): Uint8Array
|
|
30
|
+
export declare function excelToPdf(workbook: Workbook, options?: PdfExportOptions): Promise<Uint8Array>;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* ```typescript
|
|
8
8
|
* import { pdf } from "excelts/pdf";
|
|
9
9
|
*
|
|
10
|
-
* const bytes = pdf([
|
|
10
|
+
* const bytes = await pdf([
|
|
11
11
|
* ["Product", "Revenue"],
|
|
12
12
|
* ["Widget", 1000],
|
|
13
13
|
* ["Gadget", 2500]
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
* const workbook = new Workbook();
|
|
23
23
|
* const sheet = workbook.addWorksheet("Sales");
|
|
24
24
|
* sheet.addRow(["Product", "Revenue"]);
|
|
25
|
-
* const bytes = excelToPdf(workbook);
|
|
25
|
+
* const bytes = await excelToPdf(workbook);
|
|
26
26
|
* ```
|
|
27
27
|
*
|
|
28
28
|
* @example Read PDF — extract text, images, and metadata:
|
|
29
29
|
* ```typescript
|
|
30
30
|
* import { readPdf } from "excelts/pdf";
|
|
31
31
|
*
|
|
32
|
-
* const result = readPdf(pdfBytes);
|
|
32
|
+
* const result = await readPdf(pdfBytes);
|
|
33
33
|
* console.log(result.text); // All text
|
|
34
34
|
* console.log(result.pages[0].text); // Page 1 text
|
|
35
35
|
* console.log(result.pages[0].images); // Page 1 images
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* ```typescript
|
|
9
9
|
* import { pdf } from "@cj-tech-master/excelts/pdf";
|
|
10
10
|
*
|
|
11
|
-
* const bytes = pdf([
|
|
11
|
+
* const bytes = await pdf([
|
|
12
12
|
* ["Product", "Revenue"],
|
|
13
13
|
* ["Widget", 1000],
|
|
14
14
|
* ["Gadget", 2500]
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*
|
|
18
18
|
* @example With options:
|
|
19
19
|
* ```typescript
|
|
20
|
-
* const bytes = pdf([
|
|
20
|
+
* const bytes = await pdf([
|
|
21
21
|
* ["Name", "Score"],
|
|
22
22
|
* ["Alice", 95],
|
|
23
23
|
* ["Bob", 87]
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
*
|
|
27
27
|
* @example Multiple sheets:
|
|
28
28
|
* ```typescript
|
|
29
|
-
* const bytes = pdf({
|
|
29
|
+
* const bytes = await pdf({
|
|
30
30
|
* sheets: [
|
|
31
31
|
* { name: "Sales", data: [["Product", "Revenue"], ["Widget", 1000]] },
|
|
32
32
|
* { name: "Costs", data: [["Item", "Amount"], ["Rent", 500]] }
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
*
|
|
37
37
|
* @example With column widths and styles:
|
|
38
38
|
* ```typescript
|
|
39
|
-
* const bytes = pdf({
|
|
39
|
+
* const bytes = await pdf({
|
|
40
40
|
* name: "Report",
|
|
41
41
|
* columns: [{ width: 25 }, { width: 15 }],
|
|
42
42
|
* data: [
|
|
@@ -113,9 +113,10 @@ export type PdfInput = PdfRow[] | PdfSheet | PdfBook;
|
|
|
113
113
|
* Generate a PDF.
|
|
114
114
|
*
|
|
115
115
|
* Accepts anything from a plain 2D array to a multi-sheet workbook.
|
|
116
|
+
* Yields to the event loop between each output page during layout and rendering.
|
|
116
117
|
*
|
|
117
118
|
* @param input - 2D array, sheet object, or workbook object
|
|
118
119
|
* @param options - PDF export options (page size, margins, etc.)
|
|
119
|
-
* @returns PDF file as Uint8Array
|
|
120
|
+
* @returns Promise of PDF file as Uint8Array
|
|
120
121
|
*/
|
|
121
|
-
export declare function pdf(input: PdfInput, options?: PdfExportOptions): Uint8Array
|
|
122
|
+
export declare function pdf(input: PdfInput, options?: PdfExportOptions): Promise<Uint8Array>;
|
|
@@ -16,18 +16,18 @@
|
|
|
16
16
|
* - Cross-reference tables and streams (PDF 1.5+)
|
|
17
17
|
* - Incremental updates and xref recovery
|
|
18
18
|
*
|
|
19
|
-
* @example
|
|
19
|
+
* @example Text extraction:
|
|
20
20
|
* ```typescript
|
|
21
21
|
* import { readPdf } from "excelts/pdf";
|
|
22
22
|
*
|
|
23
|
-
* const pdf = readPdf(pdfBytes);
|
|
23
|
+
* const pdf = await readPdf(pdfBytes);
|
|
24
24
|
* console.log(pdf.text); // All text from all pages
|
|
25
25
|
* console.log(pdf.pages[0].text); // Text from page 1
|
|
26
26
|
* ```
|
|
27
27
|
*
|
|
28
28
|
* @example Image extraction:
|
|
29
29
|
* ```typescript
|
|
30
|
-
* const pdf = readPdf(pdfBytes);
|
|
30
|
+
* const pdf = await readPdf(pdfBytes);
|
|
31
31
|
* for (const image of pdf.pages[0].images) {
|
|
32
32
|
* console.log(image.format, image.width, image.height);
|
|
33
33
|
* fs.writeFileSync(`image.${image.format}`, image.data);
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
*
|
|
37
37
|
* @example Metadata:
|
|
38
38
|
* ```typescript
|
|
39
|
-
* const pdf = readPdf(pdfBytes);
|
|
39
|
+
* const pdf = await readPdf(pdfBytes);
|
|
40
40
|
* console.log(pdf.metadata.title);
|
|
41
41
|
* console.log(pdf.metadata.author);
|
|
42
42
|
* console.log(pdf.metadata.pageCount);
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
*
|
|
45
45
|
* @example Encrypted PDF:
|
|
46
46
|
* ```typescript
|
|
47
|
-
* const pdf = readPdf(pdfBytes, { password: "secret" });
|
|
47
|
+
* const pdf = await readPdf(pdfBytes, { password: "secret" });
|
|
48
48
|
* ```
|
|
49
49
|
*/
|
|
50
50
|
import type { TextLine } from "./text-reconstruction.js";
|
|
@@ -133,11 +133,12 @@ export interface ReadPdfResult {
|
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
135
135
|
* Read a PDF file and extract text, images, and metadata.
|
|
136
|
+
* Yields to the event loop between pages to avoid blocking.
|
|
136
137
|
*
|
|
137
138
|
* @param data - Raw PDF file bytes
|
|
138
139
|
* @param options - Extraction options
|
|
139
|
-
* @returns
|
|
140
|
+
* @returns Promise of extracted content
|
|
140
141
|
* @throws {PdfStructureError} If the PDF structure is invalid
|
|
141
142
|
* @throws {PdfError} If decryption fails (wrong password)
|
|
142
143
|
*/
|
|
143
|
-
export declare function readPdf(data: Uint8Array, options?: ReadPdfOptions): ReadPdfResult
|
|
144
|
+
export declare function readPdf(data: Uint8Array, options?: ReadPdfOptions): Promise<ReadPdfResult>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared rendering constants used by both the layout engine and page renderer.
|
|
3
|
+
*
|
|
4
|
+
* Keeping these in one place ensures row-height computation and text rendering
|
|
5
|
+
* use exactly the same values, preventing clipped or overlapping content.
|
|
6
|
+
*/
|
|
7
|
+
/** Horizontal cell padding in points (left + right = 2 × CELL_PADDING_H). */
|
|
8
|
+
export declare const CELL_PADDING_H = 3;
|
|
9
|
+
/** Vertical cell padding in points (top + bottom = 2 × CELL_PADDING_V). */
|
|
10
|
+
export declare const CELL_PADDING_V = 2;
|
|
11
|
+
/**
|
|
12
|
+
* Line-height multiplier applied to the font size.
|
|
13
|
+
*
|
|
14
|
+
* Excel's default row height for an 11pt font is 15pt, which after removing
|
|
15
|
+
* vertical padding (2 × 2 = 4pt) leaves 11pt × 1.0 — but Excel also adds
|
|
16
|
+
* internal leading. A factor of 1.2 matches standard PDF/typographic practice
|
|
17
|
+
* and keeps text readable without inflating row heights.
|
|
18
|
+
*/
|
|
19
|
+
export declare const LINE_HEIGHT_FACTOR = 1.2;
|
|
20
|
+
/** Width of one indent level in points (~3 characters at 11pt). */
|
|
21
|
+
export declare const INDENT_WIDTH = 10;
|
|
22
|
+
/**
|
|
23
|
+
* Excel column widths are measured in characters of the default font's digit width.
|
|
24
|
+
* For Calibri 11pt (the default), maxDigitWidth ≈ 7 pixels at 96 DPI.
|
|
25
|
+
* Excel adds 5 pixels of padding per column (4px text margin + 1px gridline).
|
|
26
|
+
* To convert to PDF points: (charWidth × 7 + 5) × (72/96).
|
|
27
|
+
*/
|
|
28
|
+
export declare const MAX_DIGIT_WIDTH_PX = 7;
|
|
29
|
+
export declare const EXCEL_COLUMN_PADDING_PX = 5;
|
|
30
|
+
export declare const PX_TO_PT: number;
|
|
@@ -20,6 +20,7 @@ import type { PdfSheetData, ResolvedPdfOptions, LayoutPage } from "../types.js";
|
|
|
20
20
|
import type { FontManager } from "../font/font-manager.js";
|
|
21
21
|
/**
|
|
22
22
|
* Compute the layout for a sheet across one or more PDF pages.
|
|
23
|
+
* Yields to the event loop between each output page.
|
|
23
24
|
*/
|
|
24
|
-
export declare function layoutSheet(sheet: PdfSheetData, options: ResolvedPdfOptions, fontManager: FontManager): LayoutPage[]
|
|
25
|
+
export declare function layoutSheet(sheet: PdfSheetData, options: ResolvedPdfOptions, fontManager: FontManager): Promise<LayoutPage[]>;
|
|
25
26
|
export declare function paginateRows(rowHeights: number[], availableHeight: number, repeatRowCount: number, rowBreaks: Set<number>): number[][];
|
|
@@ -30,11 +30,11 @@ export declare function renderPage(page: LayoutPage, options: ResolvedPdfOptions
|
|
|
30
30
|
* E.g. alpha=0.504 → "GS5040", alpha=0.506 → "GS5060"
|
|
31
31
|
*/
|
|
32
32
|
export declare function alphaGsName(alpha: number): string;
|
|
33
|
-
export declare function computeTextStartY(verticalAlign: "top" | "middle" | "bottom", rect: PdfRect, totalTextHeight: number, ascent: number): number;
|
|
33
|
+
export declare function computeTextStartY(verticalAlign: "top" | "middle" | "bottom", rect: PdfRect, totalTextHeight: number, ascent: number, padV?: number): number;
|
|
34
34
|
export declare function computeTextX(align: "left" | "center" | "right", rect: {
|
|
35
35
|
x: number;
|
|
36
36
|
width: number;
|
|
37
|
-
}, textWidth: number, indentPts?: number): number;
|
|
37
|
+
}, textWidth: number, indentPts?: number, padH?: number): number;
|
|
38
38
|
/**
|
|
39
39
|
* Wrap text into lines that fit within the given width.
|
|
40
40
|
* Uses a greedy word-wrap algorithm.
|
|
@@ -10,10 +10,11 @@
|
|
|
10
10
|
import { type PdfWorkbook, type PdfExportOptions } from "../types.js";
|
|
11
11
|
/**
|
|
12
12
|
* Export a PdfWorkbook to PDF format.
|
|
13
|
+
* Yields to the event loop between each output page during layout and rendering.
|
|
13
14
|
*
|
|
14
15
|
* @param workbook - The workbook data to export
|
|
15
16
|
* @param options - Export options controlling layout, pagination, and appearance
|
|
16
|
-
* @returns PDF file as a Uint8Array
|
|
17
|
+
* @returns Promise of PDF file as a Uint8Array
|
|
17
18
|
* @throws {PdfError} If the workbook has no sheets or export fails
|
|
18
19
|
*/
|
|
19
|
-
export declare function exportPdf(workbook: PdfWorkbook, options?: PdfExportOptions): Uint8Array
|
|
20
|
+
export declare function exportPdf(workbook: PdfWorkbook, options?: PdfExportOptions): Promise<Uint8Array>;
|
|
@@ -99,6 +99,8 @@ export interface PdfCellData {
|
|
|
99
99
|
export interface PdfRowData {
|
|
100
100
|
hidden?: boolean;
|
|
101
101
|
height?: number;
|
|
102
|
+
/** Whether the height was explicitly set by the user (vs auto-calculated) */
|
|
103
|
+
customHeight?: boolean;
|
|
102
104
|
/** Cells keyed by 1-based column number */
|
|
103
105
|
cells: Map<number, PdfCellData>;
|
|
104
106
|
}
|
|
@@ -432,6 +434,8 @@ export interface LayoutCell {
|
|
|
432
434
|
indent: number;
|
|
433
435
|
/** Text rotation in degrees (0-90 ccw, 91-180 cw) or "vertical" for stacked */
|
|
434
436
|
textRotation: number | "vertical";
|
|
437
|
+
/** Extra width (in points) that text can overflow into adjacent empty cells */
|
|
438
|
+
textOverflowWidth: number;
|
|
435
439
|
}
|
|
436
440
|
/**
|
|
437
441
|
* A single run within a rich text cell.
|
|
@@ -465,6 +469,8 @@ export interface LayoutBorder {
|
|
|
465
469
|
color: PdfColor;
|
|
466
470
|
/** Dash pattern (empty array = solid) */
|
|
467
471
|
dashPattern: number[];
|
|
472
|
+
/** Whether this is a double-line border */
|
|
473
|
+
isDouble?: boolean;
|
|
468
474
|
}
|
|
469
475
|
/**
|
|
470
476
|
* A single page of laid-out content.
|
|
@@ -496,6 +502,8 @@ export interface LayoutPage {
|
|
|
496
502
|
rowHeights: number[];
|
|
497
503
|
/** Images to render on this page */
|
|
498
504
|
images: LayoutImage[];
|
|
505
|
+
/** Scale factor applied to this page (for fitToPage) */
|
|
506
|
+
scaleFactor: number;
|
|
499
507
|
}
|
|
500
508
|
/**
|
|
501
509
|
* A positioned image on a PDF page.
|
|
@@ -78,3 +78,8 @@ export declare function uint8ArrayToBase64(bytes: Uint8Array): string;
|
|
|
78
78
|
* Convert string to UTF-16LE Uint8Array (used for Excel password hashing)
|
|
79
79
|
*/
|
|
80
80
|
export declare function stringToUtf16Le(str: string): Uint8Array;
|
|
81
|
+
/**
|
|
82
|
+
* Yield to the event loop via a macrotask.
|
|
83
|
+
* Uses `setTimeout(0)` which works in both Node.js and browsers.
|
|
84
|
+
*/
|
|
85
|
+
export declare function yieldToEventLoop(): Promise<void>;
|
package/package.json
CHANGED