@cj-tech-master/excelts 9.5.9 → 9.6.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 (60) hide show
  1. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +17 -0
  2. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +23 -1
  3. package/dist/browser/modules/excel/stream/workbook-writer.js +6 -0
  4. package/dist/browser/modules/excel/stream/worksheet-writer.d.ts +6 -0
  5. package/dist/browser/modules/excel/stream/worksheet-writer.js +29 -3
  6. package/dist/browser/modules/excel/types.d.ts +17 -0
  7. package/dist/browser/modules/excel/utils/drawing-utils.d.ts +46 -4
  8. package/dist/browser/modules/excel/utils/drawing-utils.js +64 -6
  9. package/dist/browser/modules/excel/workbook.browser.d.ts +38 -1
  10. package/dist/browser/modules/excel/workbook.browser.js +36 -1
  11. package/dist/browser/modules/excel/worksheet.d.ts +13 -1
  12. package/dist/browser/modules/excel/worksheet.js +35 -4
  13. package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +6 -0
  14. package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.d.ts +6 -0
  15. package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +32 -0
  16. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-xform.d.ts +5 -0
  17. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-xform.js +14 -6
  18. package/dist/browser/modules/excel/xlsx/xform/drawing/pic-xform.d.ts +2 -0
  19. package/dist/browser/modules/excel/xlsx/xform/drawing/pic-xform.js +2 -1
  20. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +14 -10
  21. package/dist/browser/modules/excel/xlsx/xlsx.browser.d.ts +2 -0
  22. package/dist/browser/modules/excel/xlsx/xlsx.browser.js +7 -1
  23. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +22 -0
  24. package/dist/cjs/modules/excel/stream/workbook-writer.js +6 -0
  25. package/dist/cjs/modules/excel/stream/worksheet-writer.js +27 -1
  26. package/dist/cjs/modules/excel/utils/drawing-utils.js +67 -6
  27. package/dist/cjs/modules/excel/workbook.browser.js +36 -1
  28. package/dist/cjs/modules/excel/worksheet.js +34 -3
  29. package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +6 -0
  30. package/dist/cjs/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +32 -0
  31. package/dist/cjs/modules/excel/xlsx/xform/drawing/blip-xform.js +14 -6
  32. package/dist/cjs/modules/excel/xlsx/xform/drawing/pic-xform.js +2 -1
  33. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +13 -9
  34. package/dist/cjs/modules/excel/xlsx/xlsx.browser.js +6 -0
  35. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +23 -1
  36. package/dist/esm/modules/excel/stream/workbook-writer.js +6 -0
  37. package/dist/esm/modules/excel/stream/worksheet-writer.js +29 -3
  38. package/dist/esm/modules/excel/utils/drawing-utils.js +64 -6
  39. package/dist/esm/modules/excel/workbook.browser.js +36 -1
  40. package/dist/esm/modules/excel/worksheet.js +35 -4
  41. package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +6 -0
  42. package/dist/esm/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +32 -0
  43. package/dist/esm/modules/excel/xlsx/xform/drawing/blip-xform.js +14 -6
  44. package/dist/esm/modules/excel/xlsx/xform/drawing/pic-xform.js +2 -1
  45. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +14 -10
  46. package/dist/esm/modules/excel/xlsx/xlsx.browser.js +7 -1
  47. package/dist/iife/excelts.iife.js +195 -26
  48. package/dist/iife/excelts.iife.js.map +1 -1
  49. package/dist/iife/excelts.iife.min.js +35 -35
  50. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +17 -0
  51. package/dist/types/modules/excel/stream/worksheet-writer.d.ts +6 -0
  52. package/dist/types/modules/excel/types.d.ts +17 -0
  53. package/dist/types/modules/excel/utils/drawing-utils.d.ts +46 -4
  54. package/dist/types/modules/excel/workbook.browser.d.ts +38 -1
  55. package/dist/types/modules/excel/worksheet.d.ts +13 -1
  56. package/dist/types/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.d.ts +6 -0
  57. package/dist/types/modules/excel/xlsx/xform/drawing/blip-xform.d.ts +5 -0
  58. package/dist/types/modules/excel/xlsx/xform/drawing/pic-xform.d.ts +2 -0
  59. package/dist/types/modules/excel/xlsx/xlsx.browser.d.ts +2 -0
  60. package/package.json +7 -7
@@ -186,6 +186,23 @@ export declare abstract class WorkbookWriterBase<TWorksheetWriter extends Worksh
186
186
  private _commitWorksheets;
187
187
  commit(): Promise<void>;
188
188
  get nextId(): number;
189
+ /**
190
+ * Register an image with the workbook and return its numeric id.
191
+ *
192
+ * Supply `buffer`/`base64`/`filename` to **embed** the bytes, or only `link`
193
+ * (a URL or local file path) to reference it **externally** — in which case
194
+ * no bytes are written into the package and the relationship is emitted with
195
+ * `TargetMode="External"`. If both are provided, embedding wins.
196
+ *
197
+ * Linked images work with cell pictures and overlay watermarks; worksheet
198
+ * background images and header/footer (VML) watermarks cannot be linked.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const id = wb.addImage({ extension: "png", link: "https://example.com/logo.png" });
203
+ * ws.addImage(id, "B2:D6");
204
+ * ```
205
+ */
189
206
  addImage(image: ImageData): number;
190
207
  getImage(id: number): Medium | undefined;
191
208
  /**
@@ -179,6 +179,12 @@ declare class WorksheetWriter {
179
179
  /**
180
180
  * Add a watermark to the worksheet using an image from `WorkbookWriter.addImage()`.
181
181
  * Supports overlay mode (DrawingML with transparency) and header mode (VML behind content).
182
+ *
183
+ * `mode: "overlay"` supports external (linked) images; `mode: "header"` does
184
+ * not — VML header/footer images require embedded media, so a linked image
185
+ * with `mode: "header"` throws an `ImageError`.
186
+ *
187
+ * @throws {ImageError} If `mode: "header"` is used with an external (linked) image.
182
188
  */
183
189
  addWatermark(options: WatermarkOptions): void;
184
190
  /**
@@ -480,6 +480,23 @@ export interface ImageData {
480
480
  base64?: string;
481
481
  filename?: string;
482
482
  buffer?: Buffer;
483
+ /**
484
+ * Reference the image as an **external link** instead of embedding its bytes.
485
+ *
486
+ * When set (and `buffer`/`base64`/`filename` are all omitted), the image is
487
+ * written as a linked DrawingML picture (`<a:blip r:link>`) whose relationship
488
+ * uses `TargetMode="External"`. No bytes are stored in the `.xlsx` package, so
489
+ * the file size stays small. The value may be either:
490
+ *
491
+ * - an absolute/relative URL (e.g. `"https://example.com/logo.png"`), or
492
+ * - a local file path (e.g. `"file:///C:/images/logo.png"` or `"images/logo.png"`).
493
+ *
494
+ * Note: Excel treats linked images as volatile — a moved/missing target shows a
495
+ * broken-image placeholder, and modern Excel may not auto-load remote URLs for
496
+ * security reasons. Use embedding (`buffer`/`base64`) when self-contained files
497
+ * are required.
498
+ */
499
+ link?: string;
483
500
  }
484
501
  export interface ImagePosition {
485
502
  tl: {
@@ -14,6 +14,11 @@ export interface DrawingAnchor {
14
14
  };
15
15
  /** Alpha modulation for transparency (OOXML percentage, e.g. 15000 = 15%). */
16
16
  alphaModFix?: number;
17
+ /**
18
+ * When true, the picture references an external linked image
19
+ * (`<a:blip r:link>`) instead of an embedded one (`<a:blip r:embed>`).
20
+ */
21
+ external?: boolean;
17
22
  };
18
23
  range: any;
19
24
  }
@@ -37,6 +42,19 @@ interface ImageMedium {
37
42
  /** Opacity 0-1 for watermark overlay mode. */
38
43
  opacity?: number;
39
44
  }
45
+ /**
46
+ * Minimal shape of a book-level media entry needed by the embed-vs-link
47
+ * decision and image-rel construction. Carries the optional link target plus
48
+ * the three mutually-exclusive embedded byte sources.
49
+ */
50
+ export interface MediaLike {
51
+ name?: string;
52
+ extension?: string;
53
+ link?: string;
54
+ buffer?: unknown;
55
+ base64?: unknown;
56
+ filename?: unknown;
57
+ }
40
58
  /**
41
59
  * Resolves a media filename into the drawing-level relative target path.
42
60
  *
@@ -50,13 +68,37 @@ export declare function resolveMediaTarget(medium: {
50
68
  name?: string;
51
69
  extension?: string;
52
70
  }): string;
71
+ /**
72
+ * Determine whether a media entry is an **external (linked) image** rather than
73
+ * an embedded one. An external image carries a `link` target and supplies no
74
+ * embedded bytes (`buffer`/`base64`/`filename`). Embedding always takes
75
+ * precedence: if any byte source is present the image is embedded even if a
76
+ * `link` was also provided.
77
+ */
78
+ export declare function isExternalImage(medium: MediaLike): boolean;
79
+ /**
80
+ * Best-effort image extension inference from an external link's path.
81
+ *
82
+ * Normalises to the extension vocabulary used by `ImageData`
83
+ * (`"jpeg" | "png" | "gif"`); unknown extensions fall back to `"png"`.
84
+ * The extension is advisory only for linked images — the relationship
85
+ * Target carries the real reference — but keeping it within the documented
86
+ * set avoids surprising consumers that branch on `medium.extension`.
87
+ */
88
+ export declare function inferExternalImageExtension(link: string): "jpeg" | "png" | "gif";
89
+ /**
90
+ * Build an image relationship for the given rId, choosing between an embedded
91
+ * package target (`../media/imageN.ext`) and an external link target
92
+ * (`TargetMode="External"`) based on whether the image is external.
93
+ *
94
+ * Shared by the drawing, background, and watermark write paths so the
95
+ * embed-vs-link decision lives in exactly one place.
96
+ */
97
+ export declare function buildImageRel(rId: string, bookImage: MediaLike): DrawingRel;
53
98
  /** Options for {@link buildDrawingAnchorsAndRels}. */
54
99
  interface BuildDrawingOptions {
55
100
  /** Look up a book-level image by its id. Return `undefined` if not found. */
56
- getBookImage: (imageId: string | number) => {
57
- name?: string;
58
- extension?: string;
59
- } | undefined;
101
+ getBookImage: (imageId: string | number) => MediaLike | undefined;
60
102
  /** Generate the next unique rId string for the drawing rels. */
61
103
  nextRId: (rels: DrawingRel[]) => string;
62
104
  }
@@ -32,6 +32,8 @@ export interface WorkbookMedia {
32
32
  buffer?: ExcelBuffer | Uint8Array;
33
33
  base64?: string;
34
34
  name?: string;
35
+ /** External link target — when set, the image is referenced, not embedded. */
36
+ link?: string;
35
37
  }
36
38
  /** Internal model type for serialization */
37
39
  export interface WorkbookModel {
@@ -782,7 +784,42 @@ declare class Workbook {
782
784
  unregisterFunction(name: string): boolean;
783
785
  clearThemes(): void;
784
786
  /**
785
- * Add Image to Workbook and return the id
787
+ * Register an image with the workbook and return its numeric id. Pass the id
788
+ * to {@link Worksheet.addImage}, {@link Worksheet.addBackgroundImage}, or
789
+ * {@link Worksheet.addWatermark} to place it.
790
+ *
791
+ * The image is either **embedded** or **linked (external)**:
792
+ *
793
+ * - **Embedded** — supply `buffer`, `base64`, or `filename`. The bytes are
794
+ * written into the `.xlsx` package (`xl/media/imageN.ext`). Self-contained,
795
+ * but inflates file size.
796
+ * - **Linked (external)** — supply only `link` (a URL or local file path).
797
+ * No bytes are stored; the package keeps a relationship with
798
+ * `TargetMode="External"` and the picture is rendered via `<a:blip r:link>`.
799
+ * Keeps the file small, but the image is resolved by Excel at open time.
800
+ *
801
+ * If both bytes and a `link` are provided, **embedding wins**.
802
+ *
803
+ * Linked images work with **cell pictures** ({@link Worksheet.addImage}) and
804
+ * **overlay watermarks** ({@link Worksheet.addWatermark} with `mode:
805
+ * "overlay"`). Worksheet background images and header/footer (VML) watermarks
806
+ * cannot be linked — they require an embedded image.
807
+ *
808
+ * Note: Excel treats linked images as volatile — a moved/missing target
809
+ * shows a broken-image placeholder, and modern Excel may not auto-load
810
+ * remote URLs for security reasons. Prefer embedding for self-contained files.
811
+ *
812
+ * @example Embedded image
813
+ * ```typescript
814
+ * const id = workbook.addImage({ buffer: pngBytes, extension: "png" });
815
+ * worksheet.addImage(id, "B2:D6");
816
+ * ```
817
+ *
818
+ * @example Linked (external) image — no bytes stored
819
+ * ```typescript
820
+ * const id = workbook.addImage({ extension: "png", link: "https://example.com/logo.png" });
821
+ * worksheet.addImage(id, "B2:D6");
822
+ * ```
786
823
  */
787
824
  addImage(image: ImageData): number;
788
825
  getImage(id: number | string): WorkbookMedia | undefined;
@@ -467,7 +467,12 @@ declare class Worksheet {
467
467
  */
468
468
  removeSparklineGroup(groupOrIndex: SparklineGroup | number): boolean;
469
469
  /**
470
- * Using the image id from `Workbook.addImage`, set the background to the worksheet
470
+ * Using the image id from `Workbook.addImage`, set the background to the worksheet.
471
+ *
472
+ * The image must be **embedded** (`buffer`/`base64`/`filename`). Worksheet
473
+ * background pictures (`<picture r:id>`) do not support external (linked)
474
+ * images — Excel silently drops a background whose relationship uses
475
+ * `TargetMode="External"`, so this rejects linked images up front.
471
476
  */
472
477
  addBackgroundImage(imageId: string | number): void;
473
478
  getBackgroundImageId(): string | undefined;
@@ -483,7 +488,14 @@ declare class Worksheet {
483
488
  * Visible in Page Layout view and when printed. Renders behind cell content.
484
489
  * Transparency must be baked into the image (PNG with alpha channel).
485
490
  *
491
+ * **External (linked) images:** `mode: "overlay"` supports external images
492
+ * (registered via `workbook.addImage({ link })`). `mode: "header"` does
493
+ * **not** — VML header/footer images require embedded media, so passing a
494
+ * linked image with `mode: "header"` throws an `ImageError`. Use an embedded
495
+ * image (`buffer`/`base64`/`filename`) or switch to `mode: "overlay"`.
496
+ *
486
497
  * @param options - Watermark configuration
498
+ * @throws {ImageError} If `mode: "header"` is used with an external (linked) image.
487
499
  *
488
500
  * @example Overlay watermark with transparency:
489
501
  * ```typescript
@@ -9,5 +9,11 @@ declare abstract class BaseCellAnchorXform extends BaseXform {
9
9
  parseOpen(node: any): boolean;
10
10
  parseText(text: string): void;
11
11
  reconcilePicture(model: any, options: any): any;
12
+ /**
13
+ * Resolve (or create) the media entry for an external linked image. The
14
+ * synthesized entry is appended to `options.media` and indexed by its link
15
+ * so repeated references to the same external image share one entry.
16
+ */
17
+ private reconcileExternalPicture;
12
18
  }
13
19
  export { BaseCellAnchorXform };
@@ -3,6 +3,11 @@ interface BlipModel {
3
3
  rId: string;
4
4
  /** Alpha modulation (opacity) as OOXML percentage (e.g. 15000 = 15%). */
5
5
  alphaModFix?: number;
6
+ /**
7
+ * When true, the blip references an external linked image via `r:link`
8
+ * instead of an embedded one via `r:embed`.
9
+ */
10
+ external?: boolean;
6
11
  }
7
12
  declare class BlipXform extends BaseXform<BlipModel> {
8
13
  constructor();
@@ -4,6 +4,8 @@ interface PicModel {
4
4
  rId?: string;
5
5
  /** Alpha modulation for transparency (OOXML percentage, e.g. 15000 = 15%). */
6
6
  alphaModFix?: number;
7
+ /** When true, render the picture as an external linked image (`r:link`). */
8
+ external?: boolean;
7
9
  [key: string]: any;
8
10
  }
9
11
  declare class PicXform extends BaseXform {
@@ -187,6 +187,8 @@ export interface WorkbookMediaLike {
187
187
  filename?: string;
188
188
  buffer?: Uint8Array;
189
189
  base64?: string;
190
+ /** External link target — when set, the image is referenced, not embedded. */
191
+ link?: string;
190
192
  }
191
193
  export interface MediaModel {
192
194
  media: WorkbookMediaLike[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cj-tech-master/excelts",
3
- "version": "9.5.9",
3
+ "version": "9.6.0",
4
4
  "description": "Zero-dependency TypeScript toolkit — Excel (XLSX), PDF, CSV, Markdown, XML, ZIP/TAR, and streaming.",
5
5
  "keywords": [
6
6
  "archive",
@@ -300,23 +300,23 @@
300
300
  "access": "public"
301
301
  },
302
302
  "devDependencies": {
303
- "@rspack/core": "^2.0.4",
303
+ "@rspack/core": "^2.0.5",
304
304
  "@types/node": "^25.9.1",
305
- "@typescript/native-preview": "^7.0.0-dev.20260521.1",
305
+ "@typescript/native-preview": "^7.0.0-dev.20260527.2",
306
306
  "@vitest/browser": "^4.1.7",
307
307
  "@vitest/browser-playwright": "^4.1.7",
308
308
  "@vitest/ui": "^4.1.7",
309
- "concurrently": "^9.2.1",
309
+ "concurrently": "^10.0.0",
310
310
  "cross-env": "^10.1.0",
311
311
  "esbuild": "^0.28.0",
312
312
  "fast-xml-parser": "^5.8.0",
313
313
  "husky": "^9.1.7",
314
- "oxfmt": "^0.51.0",
315
- "oxlint": "^1.66.0",
314
+ "oxfmt": "^0.52.0",
315
+ "oxlint": "^1.67.0",
316
316
  "oxlint-tsgolint": "latest",
317
317
  "playwright": "^1.60.0",
318
318
  "rimraf": "^6.1.3",
319
- "rolldown": "^1.0.2",
319
+ "rolldown": "^1.0.3",
320
320
  "rollup-plugin-visualizer": "^7.0.1",
321
321
  "typescript": "^6.0.3",
322
322
  "vitest": "^4.1.7"