@cj-tech-master/excelts 9.1.0 → 9.2.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 (147) hide show
  1. package/README.md +16 -1
  2. package/dist/browser/modules/archive/compression/crc32.js +1 -1
  3. package/dist/browser/modules/archive/crypto/aes.d.ts +0 -8
  4. package/dist/browser/modules/archive/crypto/aes.js +1 -20
  5. package/dist/browser/modules/archive/crypto/index.d.ts +2 -1
  6. package/dist/browser/modules/archive/crypto/index.js +3 -1
  7. package/dist/browser/modules/csv/parse/row-processor.d.ts +1 -1
  8. package/dist/browser/modules/csv/worker/worker-script.generated.js +1 -1
  9. package/dist/browser/modules/excel/utils/cell-matrix.js +1 -0
  10. package/dist/browser/modules/excel/utils/encryptor.browser.d.ts +4 -5
  11. package/dist/browser/modules/excel/utils/encryptor.browser.js +7 -12
  12. package/dist/browser/modules/excel/utils/encryptor.d.ts +1 -1
  13. package/dist/browser/modules/excel/utils/encryptor.js +4 -7
  14. package/dist/browser/modules/pdf/builder/document-builder.d.ts +517 -0
  15. package/dist/browser/modules/pdf/builder/document-builder.js +1493 -0
  16. package/dist/browser/modules/pdf/builder/form-appearance.d.ts +56 -0
  17. package/dist/browser/modules/pdf/builder/form-appearance.js +140 -0
  18. package/dist/browser/modules/pdf/builder/image-utils.d.ts +39 -0
  19. package/dist/browser/modules/pdf/builder/image-utils.js +129 -0
  20. package/dist/browser/modules/pdf/builder/pdf-editor.d.ts +230 -0
  21. package/dist/browser/modules/pdf/builder/pdf-editor.js +1574 -0
  22. package/dist/browser/modules/pdf/builder/resource-merger.d.ts +41 -0
  23. package/dist/browser/modules/pdf/builder/resource-merger.js +258 -0
  24. package/dist/browser/modules/pdf/core/digital-signature.d.ts +109 -0
  25. package/dist/browser/modules/pdf/core/digital-signature.js +659 -0
  26. package/dist/browser/modules/pdf/core/encryption.js +8 -7
  27. package/dist/browser/modules/pdf/core/pdf-object.d.ts +11 -0
  28. package/dist/browser/modules/pdf/core/pdf-object.js +38 -0
  29. package/dist/browser/modules/pdf/core/pdf-stream.d.ts +32 -0
  30. package/dist/browser/modules/pdf/core/pdf-stream.js +66 -0
  31. package/dist/browser/modules/pdf/core/pdf-writer.d.ts +55 -1
  32. package/dist/browser/modules/pdf/core/pdf-writer.js +271 -6
  33. package/dist/browser/modules/pdf/core/pdfa.d.ts +62 -0
  34. package/dist/browser/modules/pdf/core/pdfa.js +261 -0
  35. package/dist/browser/modules/pdf/index.d.ts +11 -0
  36. package/dist/browser/modules/pdf/index.js +9 -0
  37. package/dist/browser/modules/pdf/reader/bookmark-extractor.d.ts +35 -0
  38. package/dist/browser/modules/pdf/reader/bookmark-extractor.js +324 -0
  39. package/dist/browser/modules/pdf/reader/pdf-decrypt.js +6 -5
  40. package/dist/browser/modules/pdf/reader/pdf-reader.d.ts +17 -0
  41. package/dist/browser/modules/pdf/reader/pdf-reader.js +26 -2
  42. package/dist/browser/modules/pdf/reader/table-extractor.d.ts +69 -0
  43. package/dist/browser/modules/pdf/reader/table-extractor.js +365 -0
  44. package/dist/browser/modules/pdf/render/layout-engine.d.ts +21 -1
  45. package/dist/browser/modules/pdf/render/layout-engine.js +112 -5
  46. package/dist/browser/modules/pdf/render/page-renderer.d.ts +2 -9
  47. package/dist/browser/modules/pdf/render/page-renderer.js +62 -103
  48. package/dist/browser/modules/pdf/render/pdf-exporter.js +2 -61
  49. package/dist/browser/modules/pdf/render/style-converter.d.ts +4 -0
  50. package/dist/browser/modules/pdf/render/style-converter.js +1 -1
  51. package/dist/browser/modules/pdf/types.d.ts +14 -1
  52. package/dist/browser/modules/stream/browser/readable.js +8 -2
  53. package/dist/browser/utils/crypto.browser.d.ts +64 -0
  54. package/dist/browser/{modules/pdf/core/crypto.js → utils/crypto.browser.js} +91 -101
  55. package/dist/browser/utils/crypto.d.ts +97 -0
  56. package/dist/browser/utils/crypto.js +209 -0
  57. package/dist/cjs/modules/archive/compression/crc32.js +1 -1
  58. package/dist/cjs/modules/archive/crypto/aes.js +2 -23
  59. package/dist/cjs/modules/archive/crypto/index.js +3 -1
  60. package/dist/cjs/modules/csv/worker/worker-script.generated.js +1 -1
  61. package/dist/cjs/modules/excel/utils/cell-matrix.js +1 -0
  62. package/dist/cjs/modules/excel/utils/encryptor.browser.js +7 -12
  63. package/dist/cjs/modules/excel/utils/encryptor.js +4 -10
  64. package/dist/cjs/modules/pdf/builder/document-builder.js +1532 -0
  65. package/dist/cjs/modules/pdf/builder/form-appearance.js +145 -0
  66. package/dist/cjs/modules/pdf/builder/image-utils.js +135 -0
  67. package/dist/cjs/modules/pdf/builder/pdf-editor.js +1612 -0
  68. package/dist/cjs/modules/pdf/builder/resource-merger.js +263 -0
  69. package/dist/cjs/modules/pdf/core/digital-signature.js +667 -0
  70. package/dist/cjs/modules/pdf/core/encryption.js +8 -7
  71. package/dist/cjs/modules/pdf/core/pdf-object.js +38 -0
  72. package/dist/cjs/modules/pdf/core/pdf-stream.js +66 -0
  73. package/dist/cjs/modules/pdf/core/pdf-writer.js +272 -6
  74. package/dist/cjs/modules/pdf/core/pdfa.js +266 -0
  75. package/dist/cjs/modules/pdf/index.js +19 -1
  76. package/dist/cjs/modules/pdf/reader/bookmark-extractor.js +327 -0
  77. package/dist/cjs/modules/pdf/reader/pdf-decrypt.js +6 -5
  78. package/dist/cjs/modules/pdf/reader/pdf-reader.js +26 -2
  79. package/dist/cjs/modules/pdf/reader/table-extractor.js +368 -0
  80. package/dist/cjs/modules/pdf/render/layout-engine.js +113 -4
  81. package/dist/cjs/modules/pdf/render/page-renderer.js +63 -105
  82. package/dist/cjs/modules/pdf/render/pdf-exporter.js +3 -62
  83. package/dist/cjs/modules/pdf/render/style-converter.js +1 -0
  84. package/dist/cjs/modules/stream/browser/readable.js +8 -2
  85. package/dist/cjs/{modules/pdf/core/crypto.js → utils/crypto.browser.js} +95 -102
  86. package/dist/cjs/utils/crypto.js +228 -0
  87. package/dist/esm/modules/archive/compression/crc32.js +1 -1
  88. package/dist/esm/modules/archive/crypto/aes.js +1 -20
  89. package/dist/esm/modules/archive/crypto/index.js +3 -1
  90. package/dist/esm/modules/csv/worker/worker-script.generated.js +1 -1
  91. package/dist/esm/modules/excel/utils/cell-matrix.js +1 -0
  92. package/dist/esm/modules/excel/utils/encryptor.browser.js +7 -12
  93. package/dist/esm/modules/excel/utils/encryptor.js +4 -7
  94. package/dist/esm/modules/pdf/builder/document-builder.js +1493 -0
  95. package/dist/esm/modules/pdf/builder/form-appearance.js +140 -0
  96. package/dist/esm/modules/pdf/builder/image-utils.js +129 -0
  97. package/dist/esm/modules/pdf/builder/pdf-editor.js +1574 -0
  98. package/dist/esm/modules/pdf/builder/resource-merger.js +258 -0
  99. package/dist/esm/modules/pdf/core/digital-signature.js +659 -0
  100. package/dist/esm/modules/pdf/core/encryption.js +8 -7
  101. package/dist/esm/modules/pdf/core/pdf-object.js +38 -0
  102. package/dist/esm/modules/pdf/core/pdf-stream.js +66 -0
  103. package/dist/esm/modules/pdf/core/pdf-writer.js +271 -6
  104. package/dist/esm/modules/pdf/core/pdfa.js +261 -0
  105. package/dist/esm/modules/pdf/index.js +9 -0
  106. package/dist/esm/modules/pdf/reader/bookmark-extractor.js +324 -0
  107. package/dist/esm/modules/pdf/reader/pdf-decrypt.js +6 -5
  108. package/dist/esm/modules/pdf/reader/pdf-reader.js +26 -2
  109. package/dist/esm/modules/pdf/reader/table-extractor.js +365 -0
  110. package/dist/esm/modules/pdf/render/layout-engine.js +112 -5
  111. package/dist/esm/modules/pdf/render/page-renderer.js +62 -103
  112. package/dist/esm/modules/pdf/render/pdf-exporter.js +2 -61
  113. package/dist/esm/modules/pdf/render/style-converter.js +1 -1
  114. package/dist/esm/modules/stream/browser/readable.js +8 -2
  115. package/dist/esm/{modules/pdf/core/crypto.js → utils/crypto.browser.js} +91 -101
  116. package/dist/esm/utils/crypto.js +209 -0
  117. package/dist/iife/excelts.iife.js +1248 -1074
  118. package/dist/iife/excelts.iife.js.map +1 -1
  119. package/dist/iife/excelts.iife.min.js +53 -54
  120. package/dist/types/modules/archive/crypto/aes.d.ts +0 -8
  121. package/dist/types/modules/archive/crypto/index.d.ts +2 -1
  122. package/dist/types/modules/csv/parse/row-processor.d.ts +1 -1
  123. package/dist/types/modules/excel/utils/encryptor.browser.d.ts +4 -5
  124. package/dist/types/modules/excel/utils/encryptor.d.ts +1 -1
  125. package/dist/types/modules/pdf/builder/document-builder.d.ts +517 -0
  126. package/dist/types/modules/pdf/builder/form-appearance.d.ts +56 -0
  127. package/dist/types/modules/pdf/builder/image-utils.d.ts +39 -0
  128. package/dist/types/modules/pdf/builder/pdf-editor.d.ts +230 -0
  129. package/dist/types/modules/pdf/builder/resource-merger.d.ts +41 -0
  130. package/dist/types/modules/pdf/core/digital-signature.d.ts +109 -0
  131. package/dist/types/modules/pdf/core/pdf-object.d.ts +11 -0
  132. package/dist/types/modules/pdf/core/pdf-stream.d.ts +32 -0
  133. package/dist/types/modules/pdf/core/pdf-writer.d.ts +55 -1
  134. package/dist/types/modules/pdf/core/pdfa.d.ts +62 -0
  135. package/dist/types/modules/pdf/index.d.ts +11 -0
  136. package/dist/types/modules/pdf/reader/bookmark-extractor.d.ts +35 -0
  137. package/dist/types/modules/pdf/reader/pdf-reader.d.ts +17 -0
  138. package/dist/types/modules/pdf/reader/table-extractor.d.ts +69 -0
  139. package/dist/types/modules/pdf/render/layout-engine.d.ts +21 -1
  140. package/dist/types/modules/pdf/render/page-renderer.d.ts +2 -9
  141. package/dist/types/modules/pdf/render/style-converter.d.ts +4 -0
  142. package/dist/types/modules/pdf/types.d.ts +14 -1
  143. package/dist/types/utils/crypto.browser.d.ts +64 -0
  144. package/dist/types/utils/crypto.d.ts +97 -0
  145. package/package.json +110 -111
  146. package/dist/browser/modules/pdf/core/crypto.d.ts +0 -65
  147. package/dist/types/modules/pdf/core/crypto.d.ts +0 -65
@@ -52,7 +52,9 @@ import type { TextFragment } from "./content-interpreter.js";
52
52
  import type { ExtractedImage } from "./image-extractor.js";
53
53
  import type { PdfAnnotation } from "./annotation-extractor.js";
54
54
  import type { PdfFormField } from "./form-extractor.js";
55
+ import type { PdfBookmark } from "./bookmark-extractor.js";
55
56
  import type { PdfMetadata } from "./metadata-reader.js";
57
+ import type { PdfTable } from "./table-extractor.js";
56
58
  /**
57
59
  * Options for reading a PDF.
58
60
  */
@@ -94,6 +96,17 @@ export interface ReadPdfOptions {
94
96
  * @default true
95
97
  */
96
98
  extractFormFields?: boolean;
99
+ /**
100
+ * Whether to extract bookmarks (document outline / table of contents).
101
+ * @default true
102
+ */
103
+ extractBookmarks?: boolean;
104
+ /**
105
+ * Whether to extract tables from pages using text positioning heuristics.
106
+ * Opt-in since table detection is heavier than plain text extraction.
107
+ * @default false
108
+ */
109
+ extractTables?: boolean;
97
110
  }
98
111
  /**
99
112
  * A single page from a read PDF.
@@ -111,6 +124,8 @@ export interface ReadPdfPage {
111
124
  images: ExtractedImage[];
112
125
  /** Extracted annotations (links, comments, highlights, etc.) */
113
126
  annotations: PdfAnnotation[];
127
+ /** Tables detected from text fragment positioning (opt-in via extractTables) */
128
+ tables: PdfTable[];
114
129
  /** Page width in points */
115
130
  width: number;
116
131
  /** Page height in points */
@@ -130,6 +145,8 @@ export interface ReadPdfResult {
130
145
  metadata: PdfMetadata;
131
146
  /** Form fields extracted from AcroForm (document-level) */
132
147
  formFields: PdfFormField[];
148
+ /** Bookmarks (document outline) extracted from the outline tree */
149
+ bookmarks: PdfBookmark[];
133
150
  }
134
151
  /**
135
152
  * Read a PDF file and extract text, images, and metadata.
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Table extraction from PDF pages using text fragment positioning.
3
+ *
4
+ * Detects tabular structures by analyzing the spatial layout of text fragments.
5
+ * Since PDF content streams typically render tables as positioned text (with or
6
+ * without drawn grid lines), this module uses a text-only heuristic:
7
+ *
8
+ * 1. Group fragments into lines by Y proximity
9
+ * 2. Detect column boundaries from consistent X-position clusters
10
+ * 3. Identify contiguous blocks of multi-column lines as tables
11
+ * 4. Map fragments to cells based on column/line membership
12
+ *
13
+ * @see content-interpreter.ts for TextFragment extraction
14
+ * @see text-reconstruction.ts for line grouping logic
15
+ */
16
+ import type { TextFragment } from "./content-interpreter.js";
17
+ /**
18
+ * A single cell in a PDF table.
19
+ */
20
+ export interface PdfTableCell {
21
+ /** Text content of the cell */
22
+ text: string;
23
+ /** X position in page coordinates (points) */
24
+ x: number;
25
+ /** Y position in page coordinates (points) */
26
+ y: number;
27
+ /** Width of the cell in points */
28
+ width: number;
29
+ /** Height of the cell in points */
30
+ height: number;
31
+ /** Number of rows this cell spans (default 1) */
32
+ rowSpan?: number;
33
+ /** Number of columns this cell spans (default 1) */
34
+ colSpan?: number;
35
+ }
36
+ /**
37
+ * A single row in a PDF table.
38
+ */
39
+ export interface PdfTableRow {
40
+ /** Cells in this row, ordered left-to-right */
41
+ cells: PdfTableCell[];
42
+ }
43
+ /**
44
+ * A table extracted from a PDF page.
45
+ */
46
+ export interface PdfTable {
47
+ /** Rows in this table, ordered top-to-bottom */
48
+ rows: PdfTableRow[];
49
+ /** X position of the table (left edge) in page coordinates */
50
+ x: number;
51
+ /** Y position of the table (top edge) in page coordinates */
52
+ y: number;
53
+ /** Width of the table in points */
54
+ width: number;
55
+ /** Height of the table in points */
56
+ height: number;
57
+ }
58
+ /**
59
+ * Extract tables from a page's text fragments.
60
+ *
61
+ * Uses text positioning heuristics to detect tabular structures without
62
+ * relying on drawn lines or grid paths.
63
+ *
64
+ * @param fragments - Text fragments from `extractTextFromPage`
65
+ * @param pageWidth - Page width in points
66
+ * @param pageHeight - Page height in points
67
+ * @returns Array of detected tables
68
+ */
69
+ export declare function extractTables(fragments: TextFragment[], pageWidth: number, pageHeight: number): PdfTable[];
@@ -16,7 +16,7 @@
16
16
  * - Handle repeated header rows
17
17
  * - Skip hidden rows and columns
18
18
  */
19
- import type { PdfSheetData, ResolvedPdfOptions, LayoutPage } from "../types.js";
19
+ import type { PdfSheetData, ResolvedPdfOptions, LayoutPage, LayoutCell, LayoutBorder } 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.
@@ -24,3 +24,23 @@ import type { FontManager } from "../font/font-manager.js";
24
24
  */
25
25
  export declare function layoutSheet(sheet: PdfSheetData, options: ResolvedPdfOptions, fontManager: FontManager): Promise<LayoutPage[]>;
26
26
  export declare function paginateRows(rowHeights: number[], availableHeight: number, repeatRowCount: number, rowBreaks: Set<number>): number[][];
27
+ /**
28
+ * Border precedence weight.
29
+ *
30
+ * When two adjacent cells both declare a border on a shared edge the winning
31
+ * border is chosen by: 1. thicker wins, 2. solid beats dashed,
32
+ * 3. double beats single, 4. darker colour wins (tie-break).
33
+ *
34
+ * Returns a numeric score – higher score wins.
35
+ */
36
+ export declare function borderPrecedence(b: LayoutBorder): number;
37
+ /**
38
+ * Resolve shared borders between adjacent cells.
39
+ *
40
+ * For each shared edge, determine the winning border (by precedence), then:
41
+ * - The cell that "owns" the winning border keeps it in `borders` for drawing.
42
+ * - The losing cell has that border side set to `null` (it won't draw).
43
+ * - Both cells' `borderInsets` are updated to reflect the winning border's
44
+ * half-width, so text padding accounts for the line that is actually there.
45
+ */
46
+ export declare function resolveSharedBorders(cellGrid: Map<string, LayoutCell>, rowCount: number, colCount: number): void;
@@ -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, padV?: number): number;
33
+ export declare function computeTextStartY(verticalAlign: "top" | "middle" | "bottom", rect: PdfRect, totalTextHeight: number, ascent: number, padVTop?: number, padVBottom?: 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, padH?: number): number;
37
+ }, textWidth: number, indentPts?: number, padHLeft?: number, padHRight?: number): number;
38
38
  /**
39
39
  * Wrap text into lines that fit within the given width.
40
40
  * Uses a greedy word-wrap algorithm.
@@ -61,10 +61,3 @@ export interface WatermarkRenderResult {
61
61
  * watermark sits behind everything (under-content).
62
62
  */
63
63
  export declare function renderWatermark(stream: PdfContentStream, page: LayoutPage, watermark: PdfWatermark, fontManager: FontManager): WatermarkRenderResult;
64
- /**
65
- * Parse image dimensions from raw JPEG or PNG data without a full decode.
66
- */
67
- export declare function parseImageDimensions(data: Uint8Array, format: "jpeg" | "png"): {
68
- width: number;
69
- height: number;
70
- };
@@ -53,6 +53,10 @@ export declare function extractFontProperties(font: Partial<PdfFontStyle> | unde
53
53
  * Other patterns are approximated or ignored.
54
54
  */
55
55
  export declare function excelFillToPdfColor(fill: PdfFillData | undefined): PdfColor | null;
56
+ /**
57
+ * Map border styles to PDF line widths.
58
+ */
59
+ export declare function borderStyleToLineWidth(style: string): number;
56
60
  /**
57
61
  * Convert border data to PDF LayoutBorders.
58
62
  */
@@ -655,8 +655,21 @@ export interface LayoutCell {
655
655
  verticalAlign: "top" | "middle" | "bottom";
656
656
  /** Whether text wrapping is enabled */
657
657
  wrapText: boolean;
658
- /** Border definitions for this cell */
658
+ /** Border definitions for this cell (after shared-edge resolution: only edges this cell draws) */
659
659
  borders: LayoutBorders;
660
+ /**
661
+ * Effective border insets in points for text padding.
662
+ *
663
+ * On a shared edge the border line is drawn by only one of the two cells,
664
+ * but it still visually intrudes into both. These values record the actual
665
+ * half-width intrusion on each side regardless of which cell draws the line.
666
+ */
667
+ borderInsets: {
668
+ top: number;
669
+ right: number;
670
+ bottom: number;
671
+ left: number;
672
+ };
660
673
  /** Number of columns this cell spans (for merged cells) */
661
674
  colSpan: number;
662
675
  /** Number of rows this cell spans (for merged cells) */
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Cryptographic primitives — Browser version.
3
+ *
4
+ * Uses pure JavaScript for synchronous operations (SHA-256, MD5, AES-CBC, RC4)
5
+ * since Web Crypto API is async-only and cannot replace synchronous call sites.
6
+ *
7
+ * Uses Web Crypto API for:
8
+ * - `randomBytes` (crypto.getRandomValues — truly random)
9
+ * - `rsaVerify` / `rsaSign` (SubtleCrypto — hardware-accelerated)
10
+ *
11
+ * Exports the same API as `crypto.ts` (Node.js version).
12
+ */
13
+ export declare function aesCbcEncrypt(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
14
+ export declare function aesCbcDecrypt(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
15
+ export declare function aesCbcDecryptRaw(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
16
+ export declare function aesCbcEncryptRaw(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
17
+ export declare function aesEcbEncrypt(block: Uint8Array, key: Uint8Array): Uint8Array;
18
+ export declare function sha256(input: Uint8Array): Uint8Array;
19
+ export declare function md5(input: Uint8Array): Uint8Array;
20
+ /**
21
+ * RC4 stream cipher.
22
+ * @deprecated Only used for reading legacy encrypted PDFs.
23
+ */
24
+ export declare function rc4(key: Uint8Array, data: Uint8Array): Uint8Array;
25
+ /**
26
+ * Generate cryptographically secure random bytes.
27
+ * Uses crypto.getRandomValues (available in all modern browsers).
28
+ */
29
+ export declare function randomBytes(length: number): Uint8Array;
30
+ /**
31
+ * Compute a hash digest using Web Crypto API.
32
+ *
33
+ * NOTE: In the browser, this is async. The Node.js version is sync.
34
+ * For callers that need sync hashing, use `sha256()` or `md5()` directly.
35
+ *
36
+ * @param algorithm - Hash algorithm name (e.g., "SHA-256", "SHA-512", "SHA-1").
37
+ * @param data - Data to hash
38
+ * @returns The digest bytes
39
+ */
40
+ export declare function hashAsync(algorithm: string, data: Uint8Array): Promise<Uint8Array>;
41
+ /**
42
+ * Compute a hash digest synchronously (pure JS — SHA-256 and MD5 only).
43
+ *
44
+ * @param algorithm - "SHA-256" or "MD5" (case-insensitive, hyphens optional)
45
+ * @param data - Data to hash
46
+ * @returns The digest bytes
47
+ * @throws If algorithm is not SHA-256 or MD5
48
+ */
49
+ export declare function hash(algorithm: string, data: Uint8Array): Uint8Array;
50
+ /**
51
+ * Verify an RSA PKCS#1 v1.5 signature.
52
+ *
53
+ * @param publicKeyDer - DER-encoded SubjectPublicKeyInfo
54
+ * @param signature - The signature bytes
55
+ * @param data - The signed data (will be hashed with SHA-256)
56
+ */
57
+ export declare function rsaVerify(publicKeyDer: Uint8Array, signature: Uint8Array, data: Uint8Array): Promise<boolean>;
58
+ /**
59
+ * Create an RSA PKCS#1 v1.5 signature.
60
+ *
61
+ * @param privateKeyDer - DER-encoded PKCS#8 private key
62
+ * @param data - The data to sign (will be hashed with SHA-256)
63
+ */
64
+ export declare function rsaSign(privateKeyDer: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Cryptographic primitives — Node.js version.
3
+ *
4
+ * Uses `node:crypto` for maximum performance where possible.
5
+ * Pure JS fallbacks for operations where `node:crypto` would be inconvenient
6
+ * (e.g., AES-CBC with specific PDF padding semantics).
7
+ *
8
+ * The browser counterpart (`crypto.browser.ts`) provides the same API using
9
+ * pure JS implementations for synchronous ops and Web Crypto for async ops.
10
+ *
11
+ * Shared by: PDF (encryption/decryption), Archive (via re-export if needed),
12
+ * and digital signature infrastructure.
13
+ *
14
+ * @see FIPS 197 — AES
15
+ * @see FIPS 180-4 — SHA-256
16
+ * @see RFC 1321 — MD5
17
+ * @see RFC 2104 — HMAC
18
+ */
19
+ /**
20
+ * SHA-256 hash function.
21
+ * @returns 32-byte digest
22
+ */
23
+ export declare function sha256(input: Uint8Array): Uint8Array;
24
+ /**
25
+ * HMAC-SHA256 (RFC 2104).
26
+ * @returns 32-byte MAC
27
+ */
28
+ export declare function hmacSha256(key: Uint8Array, message: Uint8Array): Uint8Array;
29
+ /**
30
+ * MD5 hash function (RFC 1321).
31
+ * @returns 16-byte digest
32
+ */
33
+ export declare function md5(input: Uint8Array): Uint8Array;
34
+ /**
35
+ * AES-CBC encryption with PKCS#7 padding.
36
+ * Supports AES-128 (16-byte key) and AES-256 (32-byte key).
37
+ */
38
+ export declare function aesCbcEncrypt(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
39
+ /**
40
+ * AES-CBC decryption with PKCS#7 padding removal.
41
+ * Supports AES-128 (16-byte key) and AES-256 (32-byte key).
42
+ */
43
+ export declare function aesCbcDecrypt(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
44
+ /**
45
+ * AES-CBC decryption WITHOUT PKCS#7 padding removal.
46
+ * Used for key derivation where the output length is known.
47
+ */
48
+ export declare function aesCbcDecryptRaw(ciphertext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
49
+ /**
50
+ * AES-CBC encryption WITHOUT PKCS#7 padding.
51
+ * Used when the plaintext is already block-aligned.
52
+ *
53
+ * @throws if plaintext length is not a multiple of 16.
54
+ */
55
+ export declare function aesCbcEncryptRaw(plaintext: Uint8Array, key: Uint8Array, iv: Uint8Array): Uint8Array;
56
+ /**
57
+ * AES-ECB encryption of a single 16-byte block (no padding, no IV).
58
+ */
59
+ export declare function aesEcbEncrypt(block: Uint8Array, key: Uint8Array): Uint8Array;
60
+ /**
61
+ * RC4 stream cipher.
62
+ * @deprecated Only used for reading legacy encrypted PDFs.
63
+ */
64
+ export declare function rc4(key: Uint8Array, data: Uint8Array): Uint8Array;
65
+ /**
66
+ * Generate cryptographically secure random bytes.
67
+ */
68
+ export declare function randomBytes(length: number): Uint8Array;
69
+ /**
70
+ * Compute a hash digest using any algorithm supported by the platform.
71
+ *
72
+ * @param algorithm - Hash algorithm name (e.g., "SHA-256", "SHA-512", "SHA-1", "MD5").
73
+ * Normalized internally: hyphens removed, lowercased.
74
+ * @param data - Data to hash
75
+ * @returns The digest bytes
76
+ */
77
+ export declare function hash(algorithm: string, data: Uint8Array): Uint8Array;
78
+ /**
79
+ * Async version of `hash()` — same behavior, but returns a Promise for API
80
+ * parity with the browser version.
81
+ */
82
+ export declare function hashAsync(algorithm: string, data: Uint8Array): Promise<Uint8Array>;
83
+ /**
84
+ * Verify an RSA PKCS#1 v1.5 signature.
85
+ *
86
+ * @param publicKeyDer - DER-encoded SubjectPublicKeyInfo
87
+ * @param signature - The signature bytes
88
+ * @param data - The signed data (will be hashed with SHA-256)
89
+ */
90
+ export declare function rsaVerify(publicKeyDer: Uint8Array, signature: Uint8Array, data: Uint8Array): Promise<boolean>;
91
+ /**
92
+ * Create an RSA PKCS#1 v1.5 signature.
93
+ *
94
+ * @param privateKeyDer - DER-encoded PKCS#8 private key
95
+ * @param data - The data to sign (will be hashed with SHA-256)
96
+ */
97
+ export declare function rsaSign(privateKeyDer: Uint8Array, data: Uint8Array): Promise<Uint8Array>;
package/package.json CHANGED
@@ -1,13 +1,47 @@
1
1
  {
2
2
  "name": "@cj-tech-master/excelts",
3
- "version": "9.1.0",
3
+ "version": "9.2.0",
4
4
  "description": "Zero-dependency TypeScript toolkit — Excel (XLSX), PDF, CSV, Markdown, XML, ZIP/TAR, and streaming.",
5
- "type": "module",
6
- "main": "./dist/cjs/index.js",
7
- "module": "./dist/esm/index.js",
8
- "types": "./dist/types/index.d.ts",
9
- "publishConfig": {
10
- "access": "public"
5
+ "keywords": [
6
+ "archive",
7
+ "compression",
8
+ "cross-platform",
9
+ "csv",
10
+ "csv-parser",
11
+ "csv-writer",
12
+ "deflate",
13
+ "dom",
14
+ "excel",
15
+ "excel-to-pdf",
16
+ "gfm",
17
+ "gzip",
18
+ "markdown",
19
+ "markdown-table",
20
+ "openxml",
21
+ "pdf",
22
+ "pdf-generation",
23
+ "rfc4180",
24
+ "sax",
25
+ "spreadsheet",
26
+ "stream",
27
+ "streaming",
28
+ "tar",
29
+ "typescript",
30
+ "workbook",
31
+ "xlsx",
32
+ "xlsx-reader",
33
+ "xlsx-writer",
34
+ "xml",
35
+ "xml-parser",
36
+ "xml-writer",
37
+ "zero-dependency",
38
+ "zip",
39
+ "zip64",
40
+ "zlib"
41
+ ],
42
+ "homepage": "https://github.com/cjnoname/excelts#readme",
43
+ "bugs": {
44
+ "url": "https://github.com/cjnoname/excelts/issues"
11
45
  },
12
46
  "license": "MIT",
13
47
  "author": {
@@ -18,20 +52,43 @@
18
52
  "type": "git",
19
53
  "url": "https://github.com/cjnoname/excelts.git"
20
54
  },
21
- "homepage": "https://github.com/cjnoname/excelts#readme",
22
- "bugs": {
23
- "url": "https://github.com/cjnoname/excelts/issues"
24
- },
25
- "engines": {
26
- "node": ">=22.0.0"
27
- },
28
- "browserslist": [
29
- "chrome >= 89",
30
- "edge >= 89",
31
- "firefox >= 102",
32
- "safari >= 14.1",
33
- "opera >= 75"
55
+ "files": [
56
+ "dist",
57
+ "LICENSE",
58
+ "THIRD_PARTY_NOTICES.md",
59
+ "README.md",
60
+ "README_zh.md"
34
61
  ],
62
+ "type": "module",
63
+ "sideEffects": false,
64
+ "main": "./dist/cjs/index.js",
65
+ "module": "./dist/esm/index.js",
66
+ "types": "./dist/types/index.d.ts",
67
+ "typesVersions": {
68
+ "*": {
69
+ "zip": [
70
+ "dist/types/modules/archive/index.d.ts"
71
+ ],
72
+ "csv": [
73
+ "dist/types/modules/csv/index.d.ts"
74
+ ],
75
+ "markdown": [
76
+ "dist/types/modules/markdown/index.d.ts"
77
+ ],
78
+ "stream": [
79
+ "dist/types/modules/stream/index.d.ts"
80
+ ],
81
+ "pdf": [
82
+ "dist/types/modules/pdf/index.d.ts"
83
+ ],
84
+ "xml": [
85
+ "dist/types/modules/xml/index.d.ts"
86
+ ],
87
+ "browser": [
88
+ "dist/browser/index.browser.d.ts"
89
+ ]
90
+ }
91
+ },
35
92
  "exports": {
36
93
  ".": {
37
94
  "browser": {
@@ -137,86 +194,18 @@
137
194
  },
138
195
  "./package.json": "./package.json"
139
196
  },
140
- "files": [
141
- "dist",
142
- "LICENSE",
143
- "THIRD_PARTY_NOTICES.md",
144
- "README.md",
145
- "README_zh.md"
146
- ],
147
- "sideEffects": false,
148
- "typesVersions": {
149
- "*": {
150
- "zip": [
151
- "dist/types/modules/archive/index.d.ts"
152
- ],
153
- "csv": [
154
- "dist/types/modules/csv/index.d.ts"
155
- ],
156
- "markdown": [
157
- "dist/types/modules/markdown/index.d.ts"
158
- ],
159
- "stream": [
160
- "dist/types/modules/stream/index.d.ts"
161
- ],
162
- "pdf": [
163
- "dist/types/modules/pdf/index.d.ts"
164
- ],
165
- "xml": [
166
- "dist/types/modules/xml/index.d.ts"
167
- ],
168
- "browser": [
169
- "dist/browser/index.browser.d.ts"
170
- ]
171
- }
197
+ "publishConfig": {
198
+ "access": "public"
172
199
  },
173
- "keywords": [
174
- "excel",
175
- "xlsx",
176
- "xlsx-reader",
177
- "xlsx-writer",
178
- "openxml",
179
- "spreadsheet",
180
- "workbook",
181
- "pdf",
182
- "pdf-generation",
183
- "excel-to-pdf",
184
- "csv",
185
- "csv-parser",
186
- "csv-writer",
187
- "rfc4180",
188
- "markdown",
189
- "markdown-table",
190
- "gfm",
191
- "xml",
192
- "xml-parser",
193
- "xml-writer",
194
- "sax",
195
- "dom",
196
- "zip",
197
- "zip64",
198
- "tar",
199
- "archive",
200
- "compression",
201
- "gzip",
202
- "zlib",
203
- "deflate",
204
- "stream",
205
- "streaming",
206
- "typescript",
207
- "zero-dependency",
208
- "cross-platform"
209
- ],
210
200
  "devDependencies": {
211
201
  "@eslint/js": "^10.0.1",
212
202
  "@rspack/core": "^1.7.11",
213
- "@types/node": "^25.5.2",
214
- "@typescript-eslint/eslint-plugin": "^8.58.0",
215
- "@typescript-eslint/parser": "^8.58.0",
216
- "@typescript/native-preview": "^7.0.0-dev.20260404.1",
217
- "@vitest/browser": "^4.1.2",
218
- "@vitest/browser-playwright": "^4.1.2",
219
- "@vitest/ui": "^4.1.2",
203
+ "@types/node": "^25.6.0",
204
+ "@typescript-eslint/parser": "^8.58.2",
205
+ "@typescript/native-preview": "^7.0.0-dev.20260413.1",
206
+ "@vitest/browser": "^4.1.4",
207
+ "@vitest/browser-playwright": "^4.1.4",
208
+ "@vitest/ui": "^4.1.4",
220
209
  "concurrently": "^9.2.1",
221
210
  "cross-env": "^10.1.0",
222
211
  "esbuild": "^0.28.0",
@@ -224,28 +213,38 @@
224
213
  "eslint-config-prettier": "^10.1.8",
225
214
  "eslint-import-resolver-typescript": "^4.4.4",
226
215
  "eslint-plugin-import-x": "^4.16.2",
227
- "eslint-plugin-oxlint": "^1.58.0",
216
+ "eslint-plugin-oxlint": "^1.60.0",
228
217
  "eslint-plugin-unused-imports": "^4.4.1",
229
- "fast-xml-parser": "^5.5.10",
218
+ "fast-xml-parser": "^5.5.12",
230
219
  "husky": "^9.1.7",
231
- "oxlint": "^1.58.0",
220
+ "oxfmt": "^0.45.0",
221
+ "oxlint": "^1.60.0",
222
+ "oxlint-tsgolint": "latest",
232
223
  "playwright": "^1.59.1",
233
- "prettier": "^3.8.1",
234
224
  "rimraf": "^6.1.3",
235
- "rolldown": "^1.0.0-rc.13",
225
+ "rolldown": "^1.0.0-rc.15",
236
226
  "rollup-plugin-visualizer": "^7.0.1",
237
227
  "typescript": "^6.0.2",
238
- "typescript-eslint": "^8.58.0",
239
- "vitest": "^4.1.2"
228
+ "vitest": "^4.1.4"
229
+ },
230
+ "browserslist": [
231
+ "chrome >= 89",
232
+ "edge >= 89",
233
+ "firefox >= 102",
234
+ "safari >= 14.1",
235
+ "opera >= 75"
236
+ ],
237
+ "engines": {
238
+ "node": ">=22.0.0"
240
239
  },
241
240
  "scripts": {
242
241
  "example": "node scripts/run-examples.ts",
243
242
  "generate:csv-worker": "node scripts/generate-csv-worker-script.ts",
244
- "check": "concurrently --raw \"npm run type\" \"npm run lint\"",
245
- "test": "vitest run && npm run test:browser --",
246
- "test:browser": "npm run generate:csv-worker && rimraf dist && npm run build:browser:bundle && vitest run --config vitest.browser.config.ts",
243
+ "check": "concurrently --raw \"pnpm run type\" \"pnpm run lint\"",
244
+ "test": "vitest run && pnpm run test:browser --",
245
+ "test:browser": "pnpm run generate:csv-worker && rimraf dist && pnpm run build:browser:bundle && vitest run --config vitest.browser.config.ts",
247
246
  "test:watch": "vitest",
248
- "build": "npm run generate:csv-worker && rimraf dist && concurrently \"npm run build:esm\" \"npm run build:cjs\" \"npm run build:browser\" \"npm run build:browser:bundle\" && npm run build:verify",
247
+ "build": "pnpm run generate:csv-worker && rimraf dist && concurrently \"pnpm run build:esm\" \"pnpm run build:cjs\" \"pnpm run build:browser\" \"pnpm run build:browser:bundle\" && pnpm run build:verify",
249
248
  "build:verify": "tsc --noEmit --ignoreConfig --module NodeNext --moduleResolution NodeNext --lib ESNext,DOM --types node dist/types/index.d.ts dist/types/modules/archive/index.d.ts dist/types/modules/csv/index.d.ts dist/types/modules/markdown/index.d.ts dist/types/modules/pdf/index.d.ts dist/types/modules/stream/index.d.ts dist/types/modules/xml/index.d.ts",
250
249
  "verify:treeshake": "node scripts/treeshake-verify.ts",
251
250
  "analyze:browser": "rimraf dist && node --input-type=module -e \"import { execSync } from 'node:child_process'; process.env.ANALYZE='true'; execSync('rolldown -c rolldown.config.ts', { stdio: 'inherit' });\"",
@@ -253,13 +252,13 @@
253
252
  "lint": "eslint && oxlint",
254
253
  "lint:fix": "eslint --fix && oxlint --fix",
255
254
  "type": "tsgo --noEmit",
256
- "format": "prettier --write \"**/*.{js,ts,json,md}\"",
257
- "benchmark": "rimraf dist && npm run build && node --expose-gc scripts/benchmark.ts",
258
- "benchmark:compress": "rimraf dist && npm run build && node --expose-gc scripts/benchmark-compress.ts",
255
+ "format": "oxfmt",
256
+ "benchmark": "rimraf dist && pnpm run build && node --expose-gc scripts/benchmark.ts",
257
+ "benchmark:compress": "rimraf dist && pnpm run build && node --expose-gc scripts/benchmark-compress.ts",
259
258
  "build:esm": "tsc --project tsconfig.esm.json && node scripts/fix-esm-imports.ts",
260
259
  "build:cjs": "tsc --project tsconfig.cjs.json && node scripts/fix-cjs-imports.ts",
261
260
  "build:browser": "tsc --project tsconfig.browser.json && node scripts/fix-esm-imports.ts --dist dist/browser --types dist/browser && node scripts/fix-browser-imports.ts --dir dist/browser",
262
261
  "build:browser:bundle": "rolldown -c rolldown.config.ts",
263
- "preversion": "npm run lint && npm run type && npm run build && npm run test"
262
+ "preversion": "pnpm run lint && pnpm run type && pnpm run build && pnpm run test"
264
263
  }
265
264
  }