@cj-tech-master/excelts 9.0.0 → 9.1.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 (96) hide show
  1. package/dist/browser/index.browser.d.ts +2 -0
  2. package/dist/browser/index.browser.js +2 -0
  3. package/dist/browser/index.d.ts +2 -0
  4. package/dist/browser/index.js +2 -0
  5. package/dist/browser/modules/excel/image.d.ts +27 -2
  6. package/dist/browser/modules/excel/image.js +23 -1
  7. package/dist/browser/modules/excel/stream/worksheet-writer.d.ts +16 -1
  8. package/dist/browser/modules/excel/stream/worksheet-writer.js +68 -0
  9. package/dist/browser/modules/excel/types.d.ts +72 -0
  10. package/dist/browser/modules/excel/utils/drawing-utils.d.ts +4 -0
  11. package/dist/browser/modules/excel/utils/drawing-utils.js +5 -0
  12. package/dist/browser/modules/excel/utils/ooxml-paths.d.ts +4 -0
  13. package/dist/browser/modules/excel/utils/ooxml-paths.js +15 -0
  14. package/dist/browser/modules/excel/utils/watermark-image.d.ts +67 -0
  15. package/dist/browser/modules/excel/utils/watermark-image.js +383 -0
  16. package/dist/browser/modules/excel/worksheet.d.ts +39 -1
  17. package/dist/browser/modules/excel/worksheet.js +99 -0
  18. package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +3 -2
  19. package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +6 -1
  20. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-fill-xform.d.ts +2 -1
  21. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-fill-xform.js +0 -1
  22. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-xform.d.ts +3 -1
  23. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-xform.js +22 -6
  24. package/dist/browser/modules/excel/xlsx/xform/drawing/pic-xform.d.ts +3 -0
  25. package/dist/browser/modules/excel/xlsx/xform/drawing/pic-xform.js +5 -1
  26. package/dist/browser/modules/excel/xlsx/xform/drawing/vml-drawing-xform.d.ts +19 -0
  27. package/dist/browser/modules/excel/xlsx/xform/drawing/vml-drawing-xform.js +103 -4
  28. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +135 -8
  29. package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +1 -0
  30. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +53 -1
  31. package/dist/browser/modules/pdf/core/pdf-writer.d.ts +1 -1
  32. package/dist/browser/modules/pdf/core/pdf-writer.js +2 -1
  33. package/dist/browser/modules/pdf/index.d.ts +1 -1
  34. package/dist/browser/modules/pdf/render/page-renderer.d.ts +29 -1
  35. package/dist/browser/modules/pdf/render/page-renderer.js +394 -25
  36. package/dist/browser/modules/pdf/render/pdf-exporter.js +84 -47
  37. package/dist/browser/modules/pdf/types.d.ts +235 -0
  38. package/dist/cjs/index.js +5 -2
  39. package/dist/cjs/modules/excel/image.js +23 -1
  40. package/dist/cjs/modules/excel/stream/worksheet-writer.js +68 -0
  41. package/dist/cjs/modules/excel/utils/drawing-utils.js +5 -0
  42. package/dist/cjs/modules/excel/utils/ooxml-paths.js +19 -0
  43. package/dist/cjs/modules/excel/utils/watermark-image.js +386 -0
  44. package/dist/cjs/modules/excel/worksheet.js +99 -0
  45. package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +3 -2
  46. package/dist/cjs/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +6 -1
  47. package/dist/cjs/modules/excel/xlsx/xform/drawing/blip-fill-xform.js +0 -1
  48. package/dist/cjs/modules/excel/xlsx/xform/drawing/blip-xform.js +22 -6
  49. package/dist/cjs/modules/excel/xlsx/xform/drawing/pic-xform.js +5 -1
  50. package/dist/cjs/modules/excel/xlsx/xform/drawing/vml-drawing-xform.js +103 -4
  51. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +134 -7
  52. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +52 -0
  53. package/dist/cjs/modules/pdf/core/pdf-writer.js +2 -1
  54. package/dist/cjs/modules/pdf/render/page-renderer.js +396 -25
  55. package/dist/cjs/modules/pdf/render/pdf-exporter.js +83 -46
  56. package/dist/esm/index.browser.js +2 -0
  57. package/dist/esm/index.js +2 -0
  58. package/dist/esm/modules/excel/image.js +23 -1
  59. package/dist/esm/modules/excel/stream/worksheet-writer.js +68 -0
  60. package/dist/esm/modules/excel/utils/drawing-utils.js +5 -0
  61. package/dist/esm/modules/excel/utils/ooxml-paths.js +15 -0
  62. package/dist/esm/modules/excel/utils/watermark-image.js +383 -0
  63. package/dist/esm/modules/excel/worksheet.js +99 -0
  64. package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +3 -2
  65. package/dist/esm/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +6 -1
  66. package/dist/esm/modules/excel/xlsx/xform/drawing/blip-fill-xform.js +0 -1
  67. package/dist/esm/modules/excel/xlsx/xform/drawing/blip-xform.js +22 -6
  68. package/dist/esm/modules/excel/xlsx/xform/drawing/pic-xform.js +5 -1
  69. package/dist/esm/modules/excel/xlsx/xform/drawing/vml-drawing-xform.js +103 -4
  70. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +135 -8
  71. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +53 -1
  72. package/dist/esm/modules/pdf/core/pdf-writer.js +2 -1
  73. package/dist/esm/modules/pdf/render/page-renderer.js +394 -25
  74. package/dist/esm/modules/pdf/render/pdf-exporter.js +84 -47
  75. package/dist/iife/excelts.iife.js +2390 -469
  76. package/dist/iife/excelts.iife.js.map +1 -1
  77. package/dist/iife/excelts.iife.min.js +47 -47
  78. package/dist/types/index.browser.d.ts +2 -0
  79. package/dist/types/index.d.ts +2 -0
  80. package/dist/types/modules/excel/image.d.ts +27 -2
  81. package/dist/types/modules/excel/stream/worksheet-writer.d.ts +16 -1
  82. package/dist/types/modules/excel/types.d.ts +72 -0
  83. package/dist/types/modules/excel/utils/drawing-utils.d.ts +4 -0
  84. package/dist/types/modules/excel/utils/ooxml-paths.d.ts +4 -0
  85. package/dist/types/modules/excel/utils/watermark-image.d.ts +67 -0
  86. package/dist/types/modules/excel/worksheet.d.ts +39 -1
  87. package/dist/types/modules/excel/xlsx/xform/drawing/blip-fill-xform.d.ts +2 -1
  88. package/dist/types/modules/excel/xlsx/xform/drawing/blip-xform.d.ts +3 -1
  89. package/dist/types/modules/excel/xlsx/xform/drawing/pic-xform.d.ts +3 -0
  90. package/dist/types/modules/excel/xlsx/xform/drawing/vml-drawing-xform.d.ts +19 -0
  91. package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +1 -0
  92. package/dist/types/modules/pdf/core/pdf-writer.d.ts +1 -1
  93. package/dist/types/modules/pdf/index.d.ts +1 -1
  94. package/dist/types/modules/pdf/render/page-renderer.d.ts +29 -1
  95. package/dist/types/modules/pdf/types.d.ts +235 -0
  96. package/package.json +1 -1
@@ -15,6 +15,8 @@ export { DataValidations } from "./modules/excel/data-validations.js";
15
15
  export { FormCheckbox } from "./modules/excel/form-control.js";
16
16
  export * from "./modules/excel/enums.js";
17
17
  export * from "./modules/excel/types.js";
18
+ export { createTextWatermarkImage } from "./modules/excel/utils/watermark-image.js";
19
+ export type { TextWatermarkImageOptions } from "./modules/excel/utils/watermark-image.js";
18
20
  export type { PivotTable, PivotTableModel, PivotTableValue, PivotTableSource, CacheField, SharedItemValue, DataField, PivotTableSubtotal, RecordValue, ParsedCacheDefinition, ParsedCacheRecords } from "./modules/excel/pivot-table.js";
19
21
  export type { FormCheckboxModel, FormCheckboxOptions, FormControlRange, FormControlAnchor } from "./modules/excel/form-control.js";
20
22
  export { WorkbookWriter } from "./modules/excel/stream/workbook-writer.browser.js";
@@ -15,6 +15,8 @@ export { WorksheetWriter } from "./modules/excel/stream/worksheet-writer.js";
15
15
  export { WorksheetReader } from "./modules/excel/stream/worksheet-reader.js";
16
16
  export * from "./modules/excel/enums.js";
17
17
  export * from "./modules/excel/types.js";
18
+ export { createTextWatermarkImage } from "./modules/excel/utils/watermark-image.js";
19
+ export type { TextWatermarkImageOptions } from "./modules/excel/utils/watermark-image.js";
18
20
  export type { PivotTable, PivotTableModel, PivotTableValue, PivotTableSource, CacheField, SharedItemValue, DataField, PivotTableSubtotal, RecordValue, ParsedCacheDefinition, ParsedCacheRecords } from "./modules/excel/pivot-table.js";
19
21
  export type { FormCheckboxModel, FormCheckboxOptions, FormControlRange, FormControlAnchor } from "./modules/excel/form-control.js";
20
22
  export type { WorkbookReaderOptions, ParseEvent, SharedStringEvent, WorksheetReadyEvent, HyperlinksEvent } from "./modules/excel/stream/workbook-reader.js";
@@ -19,6 +19,19 @@ interface BackgroundModel {
19
19
  type: "background";
20
20
  imageId: string;
21
21
  }
22
+ interface WatermarkModel {
23
+ type: "watermark";
24
+ imageId: string;
25
+ /** Opacity 0-1 for overlay mode */
26
+ opacity?: number;
27
+ }
28
+ interface HeaderImageModel {
29
+ type: "headerImage";
30
+ imageId: string;
31
+ headerWidth?: number;
32
+ headerHeight?: number;
33
+ applyTo?: "all" | "odd" | "even" | "first";
34
+ }
22
35
  interface ImageRangeModel {
23
36
  tl: AnchorModel;
24
37
  br?: AnchorModel;
@@ -31,7 +44,7 @@ interface ImageModel {
31
44
  hyperlinks?: ImageHyperlinks;
32
45
  range: ImageRangeModel;
33
46
  }
34
- type Model = BackgroundModel | ImageModel;
47
+ type Model = BackgroundModel | ImageModel | WatermarkModel | HeaderImageModel;
35
48
  type ImageModelInput = ModelInput;
36
49
  interface RangeInput {
37
50
  tl?: AnchorModel | {
@@ -51,15 +64,27 @@ interface ModelInput {
51
64
  imageId: string;
52
65
  range?: string | RangeInput | ImageRangeModel;
53
66
  hyperlinks?: ImageHyperlinks;
67
+ opacity?: number;
68
+ headerWidth?: number;
69
+ headerHeight?: number;
70
+ applyTo?: "all" | "odd" | "even" | "first";
54
71
  }
55
72
  declare class Image {
56
73
  readonly worksheet: Worksheet;
57
74
  type?: string;
58
75
  imageId?: string;
59
76
  range?: ImageRange;
77
+ /** Opacity for watermark overlay mode (0-1). */
78
+ opacity?: number;
79
+ /** Header image width in points. */
80
+ headerWidth?: number;
81
+ /** Header image height in points. */
82
+ headerHeight?: number;
83
+ /** Header watermark applyTo setting. */
84
+ applyTo?: "all" | "odd" | "even" | "first";
60
85
  constructor(worksheet: Worksheet, model?: ModelInput);
61
86
  get model(): Model;
62
- set model({ type, imageId, range, hyperlinks }: ModelInput);
87
+ set model({ type, imageId, range, hyperlinks, opacity, headerWidth, headerHeight, applyTo }: ModelInput);
63
88
  clone(worksheet?: Worksheet): Image;
64
89
  }
65
90
  export { Image, type Model as ImageModel, type ImageModelInput };
@@ -3,7 +3,7 @@ import { Row } from "../row.js";
3
3
  import type { Cell } from "../cell.js";
4
4
  import { Column } from "../column.js";
5
5
  import { DataValidations } from "../data-validations.js";
6
- import type { RowBreak, ColBreak, PageSetup, HeaderFooter, WorksheetProperties, WorksheetView, WorksheetState, AutoFilter, WorksheetProtection, ConditionalFormattingOptions, AddImageRange } from "../types.js";
6
+ import type { RowBreak, ColBreak, PageSetup, HeaderFooter, WorksheetProperties, WorksheetView, WorksheetState, AutoFilter, WorksheetProtection, ConditionalFormattingOptions, AddImageRange, WatermarkOptions } from "../types.js";
7
7
  interface WorksheetWriterOptions {
8
8
  id: number;
9
9
  name?: string;
@@ -97,6 +97,8 @@ declare class WorksheetWriter {
97
97
  startedData: boolean;
98
98
  private _background?;
99
99
  private _headerRowCount?;
100
+ /** Watermark configuration */
101
+ private _watermark;
100
102
  /** Drawing model — populated during commit if images were added */
101
103
  private _drawing?;
102
104
  /** Relationship Id - assigned by WorkbookWriter */
@@ -141,6 +143,19 @@ declare class WorksheetWriter {
141
143
  * Each entry contains imageId and the normalised range (with native anchors).
142
144
  */
143
145
  getImages(): ReadonlyArray<WriterImageModel>;
146
+ /**
147
+ * Add a watermark to the worksheet using an image from `WorkbookWriter.addImage()`.
148
+ * Supports overlay mode (DrawingML with transparency) and header mode (VML behind content).
149
+ */
150
+ addWatermark(options: WatermarkOptions): void;
151
+ /**
152
+ * Get the current watermark configuration.
153
+ */
154
+ getWatermark(): WatermarkOptions | null;
155
+ /**
156
+ * Remove the watermark from the worksheet.
157
+ */
158
+ removeWatermark(): void;
144
159
  /**
145
160
  * Parse the user-supplied range into a normalised internal model
146
161
  * mirroring what the regular Worksheet / Image class does.
@@ -368,6 +368,78 @@ export interface ImageHyperlinkValue {
368
368
  hyperlink: string;
369
369
  tooltip?: string;
370
370
  }
371
+ /**
372
+ * Watermark placement mode in the Excel worksheet.
373
+ *
374
+ * - `"overlay"` — Places the watermark image as a DrawingML picture on top of cells.
375
+ * Visible on screen AND when printed. Supports transparency via `<a:alphaModFix>`.
376
+ * Users can move/delete the watermark unless the sheet is protected.
377
+ *
378
+ * - `"header"` — Places the watermark image in the page header using VML.
379
+ * Renders behind cell content. Visible in Page Layout view and Print Preview.
380
+ * Cannot be accidentally moved/deleted. The standard "true watermark" approach.
381
+ */
382
+ export type WatermarkMode = "overlay" | "header";
383
+ /**
384
+ * Options for adding a watermark to a worksheet.
385
+ *
386
+ * @example Overlay watermark (visible on screen + prints):
387
+ * ```typescript
388
+ * const imgId = workbook.addImage({ buffer: pngData, extension: "png" });
389
+ * worksheet.addWatermark({
390
+ * imageId: imgId,
391
+ * mode: "overlay",
392
+ * opacity: 0.15
393
+ * });
394
+ * ```
395
+ *
396
+ * @example Header watermark (behind content, prints correctly):
397
+ * ```typescript
398
+ * const imgId = workbook.addImage({ buffer: pngData, extension: "png" });
399
+ * worksheet.addWatermark({
400
+ * imageId: imgId,
401
+ * mode: "header"
402
+ * });
403
+ * ```
404
+ */
405
+ export interface WatermarkOptions {
406
+ /** Image ID obtained from `workbook.addImage()`. */
407
+ imageId: string | number;
408
+ /**
409
+ * Watermark placement mode.
410
+ * @default "overlay"
411
+ */
412
+ mode?: WatermarkMode;
413
+ /**
414
+ * Opacity for overlay mode (0 = fully transparent, 1 = fully opaque).
415
+ * Expressed as a percentage in OOXML (e.g. 0.15 = 15000 out of 100000).
416
+ * Only applies to `"overlay"` mode. In `"header"` mode, transparency
417
+ * must be baked into the image itself (use a PNG with alpha channel).
418
+ * @default 0.15
419
+ */
420
+ opacity?: number;
421
+ /**
422
+ * Image width in points (for "header" mode VML rendering).
423
+ * @default 467.25
424
+ */
425
+ headerWidth?: number;
426
+ /**
427
+ * Image height in points (for "header" mode VML rendering).
428
+ * @default 311.25
429
+ */
430
+ headerHeight?: number;
431
+ /**
432
+ * Which header sections to apply the watermark to (only for "header" mode).
433
+ *
434
+ * - `"all"` — applies to oddHeader, evenHeader, and firstHeader
435
+ * - `"odd"` — applies only to oddHeader (standard pages)
436
+ * - `"even"` — applies only to evenHeader
437
+ * - `"first"` — applies only to firstHeader
438
+ *
439
+ * @default "all"
440
+ */
441
+ applyTo?: "all" | "odd" | "even" | "first";
442
+ }
371
443
  export type Location = {
372
444
  top: number;
373
445
  left: number;
@@ -12,6 +12,8 @@ interface DrawingAnchor {
12
12
  tooltip?: string;
13
13
  rId: string;
14
14
  };
15
+ /** Alpha modulation for transparency (OOXML percentage, e.g. 15000 = 15%). */
16
+ alphaModFix?: number;
15
17
  };
16
18
  range: any;
17
19
  }
@@ -32,6 +34,8 @@ interface ImageMedium {
32
34
  hyperlink?: string;
33
35
  tooltip?: string;
34
36
  };
37
+ /** Opacity 0-1 for watermark overlay mode. */
38
+ opacity?: number;
35
39
  }
36
40
  /**
37
41
  * Resolves a media filename into the drawing-level relative target path.
@@ -21,6 +21,7 @@ export declare function isBinaryEntryPath(path: string): boolean;
21
21
  export declare function getDrawingNameFromPath(path: string): string | undefined;
22
22
  export declare function getDrawingNameFromRelsPath(path: string): string | undefined;
23
23
  export declare function getVmlDrawingNameFromPath(path: string): string | undefined;
24
+ export declare function getVmlDrawingHFNameFromPath(path: string): string | undefined;
24
25
  export declare function getCommentsIndexFromPath(path: string): string | undefined;
25
26
  export declare function getTableNameFromPath(path: string): string | undefined;
26
27
  export declare function getPivotTableNameFromPath(path: string): string | undefined;
@@ -37,6 +38,8 @@ export declare function worksheetRelTarget(sheetId: number | string): string;
37
38
  export declare function commentsPath(sheetId: number | string): string;
38
39
  export declare function commentsPathFromName(commentName: string): string;
39
40
  export declare function vmlDrawingPath(sheetId: number | string): string;
41
+ export declare function vmlDrawingHFPath(sheetId: number | string): string;
42
+ export declare function vmlDrawingHFRelsPath(sheetId: number | string): string;
40
43
  export declare function tablePath(target: string): string;
41
44
  export declare function drawingPath(drawingName: string): string;
42
45
  export declare function drawingRelsPath(drawingName: string): string;
@@ -56,6 +59,7 @@ export declare const OOXML_REL_TARGETS: {
56
59
  export declare function pivotCacheDefinitionRelTargetFromWorkbook(n: number | string): string;
57
60
  export declare function commentsRelTargetFromWorksheet(sheetId: number | string): string;
58
61
  export declare function vmlDrawingRelTargetFromWorksheet(sheetId: number | string): string;
62
+ export declare function vmlDrawingHFRelTargetFromWorksheet(sheetId: number | string): string;
59
63
  export declare function drawingRelTargetFromWorksheet(drawingName: string): string;
60
64
  export declare function vmlDrawingRelTargetFromWorksheetName(vmlName: string): string;
61
65
  export declare function commentsRelTargetFromWorksheetName(commentName: string): string;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Zero-dependency text-to-PNG watermark image generator.
3
+ *
4
+ * Renders text into a semi-transparent PNG suitable for use as an Excel watermark.
5
+ * Uses a built-in bitmap font for ASCII characters — no Canvas or external fonts required.
6
+ * PNG data is deflate-compressed using the archive module's built-in compressor.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * const png = createTextWatermarkImage("CONFIDENTIAL", {
11
+ * fontSize: 48,
12
+ * color: { r: 128, g: 128, b: 128 },
13
+ * opacity: 40,
14
+ * rotation: -45
15
+ * });
16
+ * const imgId = workbook.addImage({ buffer: png, extension: "png" });
17
+ * worksheet.addWatermark({ imageId: imgId });
18
+ * ```
19
+ */
20
+ /**
21
+ * Options for text watermark image generation.
22
+ */
23
+ export interface TextWatermarkImageOptions {
24
+ /**
25
+ * Approximate font size in pixels (glyph height).
26
+ * The built-in bitmap font is 8px tall; values larger than 8 are achieved by
27
+ * integer scaling. e.g. fontSize 48 → 6x scale.
28
+ * @default 48
29
+ */
30
+ fontSize?: number;
31
+ /**
32
+ * Text color as RGB (0-255 each).
33
+ * @default { r: 128, g: 128, b: 128 }
34
+ */
35
+ color?: {
36
+ r: number;
37
+ g: number;
38
+ b: number;
39
+ };
40
+ /**
41
+ * Opacity as a percentage (0 = fully transparent, 100 = fully opaque).
42
+ *
43
+ * Note: this is a **0–100 percentage** used when rendering the PNG image pixels.
44
+ * It is different from `WatermarkOptions.opacity` (which is 0–1) used by
45
+ * `worksheet.addWatermark()` for DrawingML `alphaModFix`.
46
+ *
47
+ * @default 40
48
+ */
49
+ opacity?: number;
50
+ /**
51
+ * Rotation in degrees (positive = counter-clockwise).
52
+ * @default -45
53
+ */
54
+ rotation?: number;
55
+ /**
56
+ * Padding in pixels around the text (before rotation).
57
+ * @default 20
58
+ */
59
+ padding?: number;
60
+ }
61
+ /**
62
+ * Generate a PNG image containing watermark text.
63
+ *
64
+ * The image has an alpha channel so the watermark is semi-transparent.
65
+ * Works in both Node.js and browsers with zero dependencies.
66
+ */
67
+ export declare function createTextWatermarkImage(text: string, options?: TextWatermarkImageOptions): Uint8Array;
@@ -9,7 +9,7 @@ import { FormCheckbox, type FormCheckboxModel, type FormCheckboxOptions, type Fo
9
9
  import { type PivotTable, type PivotTableModel } from "./pivot-table.js";
10
10
  import { type Origin } from "./utils/address.js";
11
11
  import type { Workbook } from "./workbook.js";
12
- import type { AddImageRange, AutoFilter, CellValue, ColBreak, ConditionalFormattingOptions, DataValidation, RowBreak, RowValues, TableProperties, WorksheetProperties, WorksheetState, WorksheetView } from "./types.js";
12
+ import type { AddImageRange, AutoFilter, CellValue, ColBreak, ConditionalFormattingOptions, DataValidation, RowBreak, RowValues, TableProperties, WatermarkOptions, WorksheetProperties, WorksheetState, WorksheetView } from "./types.js";
13
13
  type DataValidationModel = {
14
14
  [address: string]: DataValidation | undefined;
15
15
  };
@@ -108,6 +108,7 @@ interface WorksheetModel {
108
108
  pivotTables: PivotTable[];
109
109
  conditionalFormattings: ConditionalFormattingOptions[];
110
110
  formControls: FormCheckboxModel[];
111
+ watermark?: WatermarkOptions | null;
111
112
  cols?: ColumnModel[];
112
113
  rows?: RowModel[];
113
114
  dimensions?: Range;
@@ -144,6 +145,8 @@ declare class Worksheet {
144
145
  private _headerRowCount?;
145
146
  /** Loaded drawing data (for charts, etc.) - preserved for round-trip */
146
147
  private _drawing;
148
+ /** Watermark configuration for overlay or header mode */
149
+ private _watermark;
147
150
  constructor(options: WorksheetOptions);
148
151
  get name(): string;
149
152
  set name(name: string | undefined);
@@ -306,6 +309,41 @@ declare class Worksheet {
306
309
  */
307
310
  addBackgroundImage(imageId: string | number): void;
308
311
  getBackgroundImageId(): string | undefined;
312
+ /**
313
+ * Add a watermark to the worksheet using an image from `workbook.addImage()`.
314
+ *
315
+ * The watermark can be placed in one of two modes:
316
+ *
317
+ * - **overlay** (default): Places the watermark image as a drawing on top of cells.
318
+ * Visible on screen AND when printed. Supports transparency via DrawingML `alphaModFix`.
319
+ *
320
+ * - **header**: Places the watermark image in the page header using VML.
321
+ * Visible in Page Layout view and when printed. Renders behind cell content.
322
+ * Transparency must be baked into the image (PNG with alpha channel).
323
+ *
324
+ * @param options - Watermark configuration
325
+ *
326
+ * @example Overlay watermark with transparency:
327
+ * ```typescript
328
+ * const imgId = workbook.addImage({ buffer: pngData, extension: "png" });
329
+ * worksheet.addWatermark({ imageId: imgId, opacity: 0.15 });
330
+ * ```
331
+ *
332
+ * @example Header watermark (behind content):
333
+ * ```typescript
334
+ * const imgId = workbook.addImage({ buffer: pngData, extension: "png" });
335
+ * worksheet.addWatermark({ imageId: imgId, mode: "header" });
336
+ * ```
337
+ */
338
+ addWatermark(options: WatermarkOptions): void;
339
+ /**
340
+ * Get the current watermark configuration, or null if none is set.
341
+ */
342
+ getWatermark(): WatermarkOptions | null;
343
+ /**
344
+ * Remove the watermark from the worksheet.
345
+ */
346
+ removeWatermark(): void;
309
347
  /**
310
348
  * Add a form control checkbox to the worksheet.
311
349
  *
@@ -1,5 +1,6 @@
1
1
  import { BaseXform } from "../base-xform.js";
2
2
  import { BlipXform } from "./blip-xform.js";
3
+ import type { BlipModel } from "./blip-xform.js";
3
4
  declare class BlipFillXform extends BaseXform {
4
5
  map: {
5
6
  [key: string]: BlipXform;
@@ -8,7 +9,7 @@ declare class BlipFillXform extends BaseXform {
8
9
  model: any;
9
10
  constructor();
10
11
  get tag(): string;
11
- render(xmlStream: any, model: any): void;
12
+ render(xmlStream: any, model: BlipModel): void;
12
13
  parseOpen(node: any): boolean;
13
14
  parseText(): void;
14
15
  parseClose(name: string): boolean;
@@ -1,6 +1,8 @@
1
1
  import { BaseXform } from "../base-xform.js";
2
2
  interface BlipModel {
3
3
  rId: string;
4
+ /** Alpha modulation (opacity) as OOXML percentage (e.g. 15000 = 15%). */
5
+ alphaModFix?: number;
4
6
  }
5
7
  declare class BlipXform extends BaseXform<BlipModel> {
6
8
  constructor();
@@ -10,4 +12,4 @@ declare class BlipXform extends BaseXform<BlipModel> {
10
12
  parseText(): void;
11
13
  parseClose(name: string): boolean;
12
14
  }
13
- export { BlipXform };
15
+ export { BlipXform, type BlipModel };
@@ -1,6 +1,9 @@
1
1
  import { BaseXform } from "../base-xform.js";
2
2
  interface PicModel {
3
3
  index?: number;
4
+ rId?: string;
5
+ /** Alpha modulation for transparency (OOXML percentage, e.g. 15000 = 15%). */
6
+ alphaModFix?: number;
4
7
  [key: string]: any;
5
8
  }
6
9
  declare class PicXform extends BaseXform {
@@ -9,11 +9,22 @@ import { type FormCheckboxModel } from "../../../form-control.js";
9
9
  *
10
10
  * This unified xform renders both into a single VML file.
11
11
  */
12
+ /** Header/footer image model for VML rendering. */
13
+ interface VmlHeaderImageModel {
14
+ /** rId referencing the image in the VML drawing's .rels */
15
+ imageRelId: string;
16
+ /** Image width in points */
17
+ width?: number;
18
+ /** Image height in points */
19
+ height?: number;
20
+ }
12
21
  interface VmlDrawingModel {
13
22
  /** Comment/note shapes */
14
23
  comments?: any[];
15
24
  /** Form control checkboxes */
16
25
  formControls?: FormCheckboxModel[];
26
+ /** Header/footer image (for watermark in header mode) */
27
+ headerImage?: VmlHeaderImageModel;
17
28
  }
18
29
  declare class VmlDrawingXform extends BaseXform<VmlDrawingModel> {
19
30
  map: {
@@ -26,6 +37,10 @@ declare class VmlDrawingXform extends BaseXform<VmlDrawingModel> {
26
37
  * Render VML drawing containing both notes and form controls
27
38
  */
28
39
  render(xmlStream: any, model?: VmlDrawingModel): void;
40
+ /**
41
+ * Render a header/footer image shape for watermark
42
+ */
43
+ private _renderHeaderImageShape;
29
44
  /**
30
45
  * Render a checkbox form control shape
31
46
  */
@@ -33,6 +48,10 @@ declare class VmlDrawingXform extends BaseXform<VmlDrawingModel> {
33
48
  parseOpen(node: any): boolean;
34
49
  parseText(text: string): void;
35
50
  parseClose(name: string): boolean;
51
+ private _parsingHeaderImage;
52
+ private _headerImageRelId?;
53
+ private _headerImageWidth?;
54
+ private _headerImageHeight?;
36
55
  static DRAWING_ATTRIBUTES: {
37
56
  "xmlns:v": string;
38
57
  "xmlns:o": string;
@@ -223,6 +223,7 @@ declare class XLSX {
223
223
  _processDrawingEntry(stream: IParseStream, model: any, name: string, rawData?: Uint8Array): Promise<void>;
224
224
  _processDrawingRelsEntry(entry: any, model: any, name: string): Promise<void>;
225
225
  _processVmlDrawingEntry(entry: any, model: any, name: string): Promise<void>;
226
+ _processVmlDrawingHFEntry(entry: any, model: any, _name: string): Promise<void>;
226
227
  _processThemeEntry(stream: IParseStream, model: any, name: string): Promise<void>;
227
228
  _processPivotTableEntry(stream: IParseStream, model: any, name: string): Promise<void>;
228
229
  _processPivotTableRelsEntry(stream: IParseStream, model: any, name: string): Promise<void>;
@@ -71,7 +71,7 @@ export declare class PdfWriter {
71
71
  parentRef: number;
72
72
  width: number;
73
73
  height: number;
74
- contentsRef: number;
74
+ contentsRef: number | string;
75
75
  resourcesRef: number;
76
76
  annotRefs?: number[];
77
77
  }): number;
@@ -47,7 +47,7 @@ export { excelToPdf } from "./excel-bridge.js";
47
47
  /** Read a PDF file and extract text, images, and metadata. */
48
48
  export { readPdf } from "./reader/pdf-reader.js";
49
49
  export type { PdfCell, PdfRow, PdfColumn, PdfSheet, PdfBook, PdfImage } from "./pdf.js";
50
- export type { PdfExportOptions, PdfOrientation, PdfPageSize, PdfMargins, PdfColor, PageSizeName } from "./types.js";
50
+ export type { PdfExportOptions, PdfOrientation, PdfPageSize, PdfMargins, PdfColor, PageSizeName, PdfWatermark, PdfTextWatermark, PdfImageWatermark, PdfWatermarkFilter } from "./types.js";
51
51
  export { PageSizes } from "./types.js";
52
52
  export type { ReadPdfOptions, ReadPdfResult, ReadPdfPage } from "./reader/pdf-reader.js";
53
53
  export type { PdfMetadata } from "./reader/metadata-reader.js";
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { PdfContentStream } from "../core/pdf-stream.js";
13
13
  import type { FontManager } from "../font/font-manager.js";
14
- import type { LayoutPage, ResolvedPdfOptions, PdfRect } from "../types.js";
14
+ import type { LayoutPage, ResolvedPdfOptions, PdfRect, PdfWatermark } from "../types.js";
15
15
  /**
16
16
  * Result of rendering a page.
17
17
  */
@@ -40,3 +40,31 @@ export declare function computeTextX(align: "left" | "center" | "right", rect: {
40
40
  * Uses a greedy word-wrap algorithm.
41
41
  */
42
42
  export declare function wrapTextLines(text: string, measure: (s: string) => number, maxWidth: number): string[];
43
+ /**
44
+ * Result of rendering a watermark on a page.
45
+ * Contains any alpha values and image XObjects that need to be registered
46
+ * in the page's resource dictionary.
47
+ */
48
+ export interface WatermarkRenderResult {
49
+ /** Alpha values used by the watermark. */
50
+ alphaValues: number[];
51
+ /** Image XObject entries: name → raw image data + format. */
52
+ imageXObjects: Array<{
53
+ name: string;
54
+ data: Uint8Array;
55
+ format: "jpeg" | "png";
56
+ }>;
57
+ }
58
+ /**
59
+ * Render a watermark onto a PDF content stream.
60
+ * This should be called BEFORE the cell/grid content is rendered so the
61
+ * watermark sits behind everything (under-content).
62
+ */
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
+ };