@cj-tech-master/excelts 6.0.0 → 6.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 (33) hide show
  1. package/dist/browser/modules/excel/anchor.js +10 -4
  2. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +13 -0
  3. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +32 -1
  4. package/dist/browser/modules/excel/stream/worksheet-writer.d.ts +56 -2
  5. package/dist/browser/modules/excel/stream/worksheet-writer.js +90 -3
  6. package/dist/browser/modules/excel/utils/drawing-utils.d.ts +77 -0
  7. package/dist/browser/modules/excel/utils/drawing-utils.js +113 -0
  8. package/dist/browser/modules/excel/worksheet.js +1 -1
  9. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.d.ts +0 -1
  10. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +43 -64
  11. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +2 -19
  12. package/dist/cjs/modules/excel/anchor.js +10 -4
  13. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +31 -0
  14. package/dist/cjs/modules/excel/stream/worksheet-writer.js +89 -2
  15. package/dist/cjs/modules/excel/utils/drawing-utils.js +118 -0
  16. package/dist/cjs/modules/excel/worksheet.js +1 -1
  17. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +42 -63
  18. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +2 -19
  19. package/dist/esm/modules/excel/anchor.js +10 -4
  20. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +32 -1
  21. package/dist/esm/modules/excel/stream/worksheet-writer.js +90 -3
  22. package/dist/esm/modules/excel/utils/drawing-utils.js +113 -0
  23. package/dist/esm/modules/excel/worksheet.js +1 -1
  24. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +43 -64
  25. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +2 -19
  26. package/dist/iife/excelts.iife.js +237 -73
  27. package/dist/iife/excelts.iife.js.map +1 -1
  28. package/dist/iife/excelts.iife.min.js +34 -34
  29. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +13 -0
  30. package/dist/types/modules/excel/stream/worksheet-writer.d.ts +56 -2
  31. package/dist/types/modules/excel/utils/drawing-utils.d.ts +77 -0
  32. package/dist/types/modules/excel/xlsx/xform/sheet/worksheet-xform.d.ts +0 -1
  33. package/package.json +1 -1
@@ -71,6 +71,13 @@ export interface WorksheetWriterLike {
71
71
  committed?: boolean;
72
72
  stream: any;
73
73
  commit(): void;
74
+ /** Drawing model — populated after commit if images were added */
75
+ drawing?: {
76
+ rId: string;
77
+ name: string;
78
+ anchors: any[];
79
+ rels: any[];
80
+ };
74
81
  }
75
82
  export interface WorksheetWriterConstructor<T extends WorksheetWriterLike> {
76
83
  new (options: {
@@ -129,6 +136,12 @@ export declare abstract class WorkbookWriterBase<TWorksheetWriter extends Worksh
129
136
  * Add media files - can be overridden by Node.js for file system support
130
137
  */
131
138
  addMedia(): Promise<void[]>;
139
+ /**
140
+ * Generate drawing XML and drawing relationship files for worksheets that have images.
141
+ * Must be called after _commitWorksheets() so that each WorksheetWriter has built its
142
+ * drawing model, and after addMedia() so that media files are already in the ZIP.
143
+ */
144
+ protected addDrawings(): void;
132
145
  addApp(): Promise<void>;
133
146
  addCore(): Promise<void>;
134
147
  addSharedStrings(): Promise<void>;
@@ -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 } from "../types.js";
6
+ import type { RowBreak, ColBreak, PageSetup, HeaderFooter, WorksheetProperties, WorksheetView, WorksheetState, AutoFilter, WorksheetProtection, ConditionalFormattingOptions, AddImageRange } from "../types.js";
7
7
  interface WorksheetWriterOptions {
8
8
  id: number;
9
9
  name?: string;
@@ -16,6 +16,34 @@ interface WorksheetWriterOptions {
16
16
  autoFilter?: AutoFilter;
17
17
  headerFooter?: Partial<HeaderFooter>;
18
18
  }
19
+ /** Internal model for an image added via addImage(). */
20
+ interface WriterImageModel {
21
+ type: "image";
22
+ imageId: string;
23
+ range: {
24
+ tl: {
25
+ nativeCol: number;
26
+ nativeColOff: number;
27
+ nativeRow: number;
28
+ nativeRowOff: number;
29
+ };
30
+ br?: {
31
+ nativeCol: number;
32
+ nativeColOff: number;
33
+ nativeRow: number;
34
+ nativeRowOff: number;
35
+ };
36
+ ext?: {
37
+ width: number;
38
+ height: number;
39
+ };
40
+ editAs?: string;
41
+ };
42
+ hyperlinks?: {
43
+ hyperlink?: string;
44
+ tooltip?: string;
45
+ };
46
+ }
19
47
  declare class WorksheetWriter {
20
48
  id: number;
21
49
  name: string;
@@ -69,6 +97,8 @@ declare class WorksheetWriter {
69
97
  startedData: boolean;
70
98
  private _background?;
71
99
  private _headerRowCount?;
100
+ /** Drawing model — populated during commit if images were added */
101
+ private _drawing?;
72
102
  /** Relationship Id - assigned by WorkbookWriter */
73
103
  rId?: string;
74
104
  constructor(options: WorksheetWriterOptions);
@@ -99,8 +129,23 @@ declare class WorksheetWriter {
99
129
  mergeCells(...cells: (string | number)[]): void;
100
130
  addConditionalFormatting(cf: ConditionalFormattingOptions): void;
101
131
  removeConditionalFormatting(filter?: number | ((cf: ConditionalFormattingOptions) => boolean)): void;
102
- addBackgroundImage(imageId: number): void;
132
+ addBackgroundImage(imageId: string | number): void;
103
133
  getBackgroundImageId(): number | undefined;
134
+ /**
135
+ * Using the image id from `WorkbookWriter.addImage`,
136
+ * embed an image within the worksheet to cover a range.
137
+ */
138
+ addImage(imageId: string | number, range: AddImageRange): void;
139
+ /**
140
+ * Return the images that have been added to this worksheet.
141
+ * Each entry contains imageId and the normalised range (with native anchors).
142
+ */
143
+ getImages(): ReadonlyArray<WriterImageModel>;
144
+ /**
145
+ * Parse the user-supplied range into a normalised internal model
146
+ * mirroring what the regular Worksheet / Image class does.
147
+ */
148
+ private _parseImageRange;
104
149
  protect(password?: string, options?: Partial<WorksheetProtection>): Promise<void>;
105
150
  unprotect(): void;
106
151
  private _write;
@@ -122,9 +167,18 @@ declare class WorksheetWriter {
122
167
  private _writePageSetup;
123
168
  private _writeHeaderFooter;
124
169
  private _writeAutoFilter;
170
+ private _writeDrawing;
171
+ /** Returns the drawing model if images were added, for the workbook writer. */
172
+ get drawing(): {
173
+ rId: string;
174
+ name: string;
175
+ anchors: any[];
176
+ rels: any[];
177
+ } | undefined;
125
178
  private _writeBackground;
126
179
  private _writeLegacyData;
127
180
  private _writeDimensions;
128
181
  private _writeCloseWorksheet;
129
182
  }
130
183
  export { WorksheetWriter };
184
+ export type { WriterImageModel };
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Shared utilities for building drawing models (anchors + relationships)
3
+ * used by both the streaming WorksheetWriter and the non-streaming WorkSheetXform.
4
+ *
5
+ * This eliminates the duplicated anchor/rel building logic and provides
6
+ * a single, correct image-rel deduplication strategy.
7
+ */
8
+ interface DrawingAnchor {
9
+ picture: {
10
+ rId: string;
11
+ hyperlinks?: {
12
+ tooltip?: string;
13
+ rId: string;
14
+ };
15
+ };
16
+ range: any;
17
+ }
18
+ interface DrawingRel {
19
+ Id: string;
20
+ Type: string;
21
+ Target: string;
22
+ TargetMode?: string;
23
+ }
24
+ interface DrawingModel {
25
+ anchors: DrawingAnchor[];
26
+ rels: DrawingRel[];
27
+ }
28
+ interface ImageMedium {
29
+ imageId: string | number;
30
+ range: any;
31
+ hyperlinks?: {
32
+ hyperlink?: string;
33
+ tooltip?: string;
34
+ };
35
+ }
36
+ /**
37
+ * Resolves a media filename into the drawing-level relative target path.
38
+ *
39
+ * In the non-streaming path, media entries have separate `name` and `extension`
40
+ * fields (e.g. name="image0", extension="png").
41
+ * In the streaming path, `name` already includes the extension (e.g. "image0.png").
42
+ *
43
+ * This function accepts both forms and returns e.g. `"../media/image0.png"`.
44
+ */
45
+ export declare function resolveMediaTarget(medium: {
46
+ name?: string;
47
+ extension?: string;
48
+ }): string;
49
+ /** Options for {@link buildDrawingAnchorsAndRels}. */
50
+ interface BuildDrawingOptions {
51
+ /** Look up a book-level image by its id. Return `undefined` if not found. */
52
+ getBookImage: (imageId: string | number) => {
53
+ name?: string;
54
+ extension?: string;
55
+ } | undefined;
56
+ /** Generate the next unique rId string for the drawing rels. */
57
+ nextRId: (rels: DrawingRel[]) => string;
58
+ }
59
+ /**
60
+ * Build the drawing anchors and relationships from a list of image media entries.
61
+ *
62
+ * This is the core logic shared between:
63
+ * - `WorksheetWriter._writeDrawing()` (streaming)
64
+ * - `WorkSheetXform.prepare()` (non-streaming)
65
+ *
66
+ * It correctly deduplicates image rels: if the same `imageId` is used for
67
+ * multiple anchors, only one image relationship is created and shared.
68
+ */
69
+ export declare function buildDrawingAnchorsAndRels(media: ImageMedium[], existingRels: DrawingRel[], options: BuildDrawingOptions): DrawingModel;
70
+ /**
71
+ * Filter drawing anchors to remove invalid entries before XML generation.
72
+ *
73
+ * Shared between streaming `WorkbookWriterBase.addDrawings()` and
74
+ * non-streaming `XLSX.addDrawings()`.
75
+ */
76
+ export declare function filterDrawingAnchors(anchors: any[]): any[];
77
+ export {};
@@ -5,7 +5,6 @@ declare class WorkSheetXform extends BaseXform {
5
5
  };
6
6
  private ignoreNodes;
7
7
  parser: any;
8
- private preImageId;
9
8
  static WORKSHEET_ATTRIBUTES: {
10
9
  xmlns: string;
11
10
  "xmlns:r": string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cj-tech-master/excelts",
3
- "version": "6.0.0",
3
+ "version": "6.1.0",
4
4
  "description": "TypeScript Excel Workbook Manager - Read and Write xlsx and csv Files.",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",