@cj-tech-master/excelts 9.6.1 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +18 -3
  2. package/README_zh.md +18 -3
  3. package/dist/browser/modules/excel/cell.d.ts +4 -0
  4. package/dist/browser/modules/excel/note.js +5 -1
  5. package/dist/browser/modules/excel/row.js +35 -2
  6. package/dist/browser/modules/excel/stream/workbook-writer.browser.d.ts +8 -1
  7. package/dist/browser/modules/excel/stream/workbook-writer.browser.js +22 -2
  8. package/dist/browser/modules/excel/types.d.ts +81 -0
  9. package/dist/browser/modules/excel/utils/drawing-utils.d.ts +8 -0
  10. package/dist/browser/modules/excel/utils/drawing-utils.js +19 -2
  11. package/dist/browser/modules/excel/workbook.browser.d.ts +16 -0
  12. package/dist/browser/modules/excel/workbook.browser.js +32 -2
  13. package/dist/browser/modules/excel/worksheet.d.ts +31 -1
  14. package/dist/browser/modules/excel/worksheet.js +83 -0
  15. package/dist/browser/modules/excel/xlsx/xform/comment/vml-shape-xform.d.ts +7 -0
  16. package/dist/browser/modules/excel/xlsx/xform/comment/vml-shape-xform.js +42 -8
  17. package/dist/browser/modules/excel/xlsx/xform/core/content-types-xform.js +3 -1
  18. package/dist/browser/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +5 -0
  19. package/dist/browser/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +18 -1
  20. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-xform.d.ts +6 -0
  21. package/dist/browser/modules/excel/xlsx/xform/drawing/blip-xform.js +38 -11
  22. package/dist/browser/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.d.ts +1 -0
  23. package/dist/browser/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.js +5 -0
  24. package/dist/browser/modules/excel/xlsx/xform/drawing/pic-xform.d.ts +2 -0
  25. package/dist/browser/modules/excel/xlsx/xform/drawing/pic-xform.js +2 -1
  26. package/dist/browser/modules/excel/xlsx/xform/drawing/shape-xform.d.ts +47 -0
  27. package/dist/browser/modules/excel/xlsx/xform/drawing/shape-xform.js +109 -0
  28. package/dist/browser/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +10 -1
  29. package/dist/browser/modules/excel/xlsx/xform/sheet/worksheet-xform.js +64 -1
  30. package/dist/browser/modules/pdf/builder/document-builder.js +22 -49
  31. package/dist/browser/modules/pdf/builder/pdf-editor.js +1 -1
  32. package/dist/browser/modules/pdf/core/pdf-stream.d.ts +28 -1
  33. package/dist/browser/modules/pdf/core/pdf-stream.js +38 -2
  34. package/dist/browser/modules/pdf/font/font-manager.d.ts +26 -0
  35. package/dist/browser/modules/pdf/font/font-manager.js +35 -18
  36. package/dist/browser/modules/pdf/render/page-renderer.d.ts +51 -3
  37. package/dist/browser/modules/pdf/render/page-renderer.js +111 -18
  38. package/dist/browser/modules/word/advanced/field-engine.js +45 -20
  39. package/dist/browser/modules/word/advanced/glossary.d.ts +10 -36
  40. package/dist/browser/modules/word/advanced/glossary.js +8 -9
  41. package/dist/browser/modules/word/advanced/math-convert.js +94 -12
  42. package/dist/browser/modules/word/advanced/ole-objects.d.ts +28 -0
  43. package/dist/browser/modules/word/advanced/ole-objects.js +122 -19
  44. package/dist/browser/modules/word/advanced/style-map.js +31 -10
  45. package/dist/browser/modules/word/builder/run-builders.d.ts +7 -1
  46. package/dist/browser/modules/word/builder/run-builders.js +7 -1
  47. package/dist/browser/modules/word/constants.d.ts +4 -0
  48. package/dist/browser/modules/word/constants.js +5 -1
  49. package/dist/browser/modules/word/convert/docx-to-semantic.d.ts +2 -1
  50. package/dist/browser/modules/word/convert/docx-to-semantic.js +135 -1
  51. package/dist/browser/modules/word/convert/html/html-import.d.ts +32 -1
  52. package/dist/browser/modules/word/convert/html/html-import.js +167 -14
  53. package/dist/browser/modules/word/convert/html/html.d.ts +2 -2
  54. package/dist/browser/modules/word/convert/html/html.js +1 -1
  55. package/dist/browser/modules/word/convert/markdown/markdown-import.d.ts +48 -18
  56. package/dist/browser/modules/word/convert/markdown/markdown-import.js +279 -69
  57. package/dist/browser/modules/word/convert/markdown/markdown.d.ts +1 -1
  58. package/dist/browser/modules/word/convert/odt/odt.js +407 -56
  59. package/dist/browser/modules/word/html.d.ts +2 -2
  60. package/dist/browser/modules/word/html.js +1 -1
  61. package/dist/browser/modules/word/index.base.d.ts +3 -3
  62. package/dist/browser/modules/word/index.base.js +1 -1
  63. package/dist/browser/modules/word/layout/layout-full.js +326 -19
  64. package/dist/browser/modules/word/layout/render-page.js +35 -8
  65. package/dist/browser/modules/word/markdown.d.ts +1 -1
  66. package/dist/browser/modules/word/query/compat.d.ts +10 -2
  67. package/dist/browser/modules/word/query/compat.js +29 -21
  68. package/dist/browser/modules/word/reader/docx-reader.js +105 -2
  69. package/dist/browser/modules/word/reader/math-parser.js +8 -2
  70. package/dist/browser/modules/word/security/cfb-reader.js +5 -5
  71. package/dist/browser/modules/word/types.d.ts +96 -1
  72. package/dist/browser/modules/word/writer/docx-packager.js +108 -2
  73. package/dist/browser/modules/word/writer/glossary-writer.d.ts +28 -0
  74. package/dist/browser/modules/word/writer/glossary-writer.js +121 -0
  75. package/dist/browser/modules/word/writer/header-footer-writer.js +105 -20
  76. package/dist/browser/modules/word/writer/math-writer.js +7 -2
  77. package/dist/browser/utils/font-metrics.d.ts +8 -0
  78. package/dist/browser/utils/font-metrics.js +43 -0
  79. package/dist/browser/utils/theme-colors.js +4 -1
  80. package/dist/cjs/modules/excel/note.js +5 -1
  81. package/dist/cjs/modules/excel/row.js +35 -2
  82. package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +22 -2
  83. package/dist/cjs/modules/excel/utils/drawing-utils.js +19 -2
  84. package/dist/cjs/modules/excel/workbook.browser.js +31 -1
  85. package/dist/cjs/modules/excel/worksheet.js +83 -0
  86. package/dist/cjs/modules/excel/xlsx/xform/comment/vml-shape-xform.js +42 -8
  87. package/dist/cjs/modules/excel/xlsx/xform/core/content-types-xform.js +3 -1
  88. package/dist/cjs/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +5 -0
  89. package/dist/cjs/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +18 -1
  90. package/dist/cjs/modules/excel/xlsx/xform/drawing/blip-xform.js +38 -11
  91. package/dist/cjs/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.js +5 -0
  92. package/dist/cjs/modules/excel/xlsx/xform/drawing/pic-xform.js +2 -1
  93. package/dist/cjs/modules/excel/xlsx/xform/drawing/shape-xform.js +112 -0
  94. package/dist/cjs/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +10 -1
  95. package/dist/cjs/modules/excel/xlsx/xform/sheet/worksheet-xform.js +64 -1
  96. package/dist/cjs/modules/pdf/builder/document-builder.js +21 -48
  97. package/dist/cjs/modules/pdf/builder/pdf-editor.js +1 -1
  98. package/dist/cjs/modules/pdf/core/pdf-stream.js +38 -2
  99. package/dist/cjs/modules/pdf/font/font-manager.js +35 -18
  100. package/dist/cjs/modules/pdf/render/page-renderer.js +112 -18
  101. package/dist/cjs/modules/word/advanced/field-engine.js +45 -20
  102. package/dist/cjs/modules/word/advanced/glossary.js +8 -9
  103. package/dist/cjs/modules/word/advanced/math-convert.js +94 -12
  104. package/dist/cjs/modules/word/advanced/ole-objects.js +123 -19
  105. package/dist/cjs/modules/word/advanced/style-map.js +31 -10
  106. package/dist/cjs/modules/word/builder/run-builders.js +7 -1
  107. package/dist/cjs/modules/word/constants.js +5 -1
  108. package/dist/cjs/modules/word/convert/docx-to-semantic.js +135 -1
  109. package/dist/cjs/modules/word/convert/html/html-import.js +168 -14
  110. package/dist/cjs/modules/word/convert/html/html.js +2 -1
  111. package/dist/cjs/modules/word/convert/markdown/markdown-import.js +279 -69
  112. package/dist/cjs/modules/word/convert/odt/odt.js +407 -56
  113. package/dist/cjs/modules/word/html.js +2 -1
  114. package/dist/cjs/modules/word/index.base.js +4 -3
  115. package/dist/cjs/modules/word/layout/layout-full.js +325 -18
  116. package/dist/cjs/modules/word/layout/render-page.js +35 -8
  117. package/dist/cjs/modules/word/query/compat.js +29 -21
  118. package/dist/cjs/modules/word/reader/docx-reader.js +104 -1
  119. package/dist/cjs/modules/word/reader/math-parser.js +8 -2
  120. package/dist/cjs/modules/word/security/cfb-reader.js +5 -5
  121. package/dist/cjs/modules/word/writer/docx-packager.js +108 -2
  122. package/dist/cjs/modules/word/writer/glossary-writer.js +124 -0
  123. package/dist/cjs/modules/word/writer/header-footer-writer.js +105 -20
  124. package/dist/cjs/modules/word/writer/math-writer.js +7 -2
  125. package/dist/cjs/utils/font-metrics.js +44 -0
  126. package/dist/cjs/utils/theme-colors.js +4 -1
  127. package/dist/esm/modules/excel/note.js +5 -1
  128. package/dist/esm/modules/excel/row.js +35 -2
  129. package/dist/esm/modules/excel/stream/workbook-writer.browser.js +22 -2
  130. package/dist/esm/modules/excel/utils/drawing-utils.js +19 -2
  131. package/dist/esm/modules/excel/workbook.browser.js +32 -2
  132. package/dist/esm/modules/excel/worksheet.js +83 -0
  133. package/dist/esm/modules/excel/xlsx/xform/comment/vml-shape-xform.js +42 -8
  134. package/dist/esm/modules/excel/xlsx/xform/core/content-types-xform.js +3 -1
  135. package/dist/esm/modules/excel/xlsx/xform/drawing/absolute-anchor-xform.js +5 -0
  136. package/dist/esm/modules/excel/xlsx/xform/drawing/base-cell-anchor-xform.js +18 -1
  137. package/dist/esm/modules/excel/xlsx/xform/drawing/blip-xform.js +38 -11
  138. package/dist/esm/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.js +5 -0
  139. package/dist/esm/modules/excel/xlsx/xform/drawing/pic-xform.js +2 -1
  140. package/dist/esm/modules/excel/xlsx/xform/drawing/shape-xform.js +109 -0
  141. package/dist/esm/modules/excel/xlsx/xform/drawing/two-cell-anchor-xform.js +10 -1
  142. package/dist/esm/modules/excel/xlsx/xform/sheet/worksheet-xform.js +64 -1
  143. package/dist/esm/modules/pdf/builder/document-builder.js +22 -49
  144. package/dist/esm/modules/pdf/builder/pdf-editor.js +1 -1
  145. package/dist/esm/modules/pdf/core/pdf-stream.js +38 -2
  146. package/dist/esm/modules/pdf/font/font-manager.js +35 -18
  147. package/dist/esm/modules/pdf/render/page-renderer.js +111 -18
  148. package/dist/esm/modules/word/advanced/field-engine.js +45 -20
  149. package/dist/esm/modules/word/advanced/glossary.js +8 -9
  150. package/dist/esm/modules/word/advanced/math-convert.js +94 -12
  151. package/dist/esm/modules/word/advanced/ole-objects.js +122 -19
  152. package/dist/esm/modules/word/advanced/style-map.js +31 -10
  153. package/dist/esm/modules/word/builder/run-builders.js +7 -1
  154. package/dist/esm/modules/word/constants.js +5 -1
  155. package/dist/esm/modules/word/convert/docx-to-semantic.js +135 -1
  156. package/dist/esm/modules/word/convert/html/html-import.js +167 -14
  157. package/dist/esm/modules/word/convert/html/html.js +1 -1
  158. package/dist/esm/modules/word/convert/markdown/markdown-import.js +279 -69
  159. package/dist/esm/modules/word/convert/odt/odt.js +407 -56
  160. package/dist/esm/modules/word/html.js +1 -1
  161. package/dist/esm/modules/word/index.base.js +1 -1
  162. package/dist/esm/modules/word/layout/layout-full.js +326 -19
  163. package/dist/esm/modules/word/layout/render-page.js +35 -8
  164. package/dist/esm/modules/word/query/compat.js +29 -21
  165. package/dist/esm/modules/word/reader/docx-reader.js +105 -2
  166. package/dist/esm/modules/word/reader/math-parser.js +8 -2
  167. package/dist/esm/modules/word/security/cfb-reader.js +5 -5
  168. package/dist/esm/modules/word/writer/docx-packager.js +108 -2
  169. package/dist/esm/modules/word/writer/glossary-writer.js +121 -0
  170. package/dist/esm/modules/word/writer/header-footer-writer.js +105 -20
  171. package/dist/esm/modules/word/writer/math-writer.js +7 -2
  172. package/dist/esm/utils/font-metrics.js +43 -0
  173. package/dist/esm/utils/theme-colors.js +4 -1
  174. package/dist/iife/excelts.iife.js +496 -59
  175. package/dist/iife/excelts.iife.js.map +1 -1
  176. package/dist/iife/excelts.iife.min.js +39 -39
  177. package/dist/types/modules/excel/cell.d.ts +4 -0
  178. package/dist/types/modules/excel/stream/workbook-writer.browser.d.ts +8 -1
  179. package/dist/types/modules/excel/types.d.ts +81 -0
  180. package/dist/types/modules/excel/utils/drawing-utils.d.ts +8 -0
  181. package/dist/types/modules/excel/workbook.browser.d.ts +16 -0
  182. package/dist/types/modules/excel/worksheet.d.ts +31 -1
  183. package/dist/types/modules/excel/xlsx/xform/comment/vml-shape-xform.d.ts +7 -0
  184. package/dist/types/modules/excel/xlsx/xform/drawing/blip-xform.d.ts +6 -0
  185. package/dist/types/modules/excel/xlsx/xform/drawing/one-cell-anchor-xform.d.ts +1 -0
  186. package/dist/types/modules/excel/xlsx/xform/drawing/pic-xform.d.ts +2 -0
  187. package/dist/types/modules/excel/xlsx/xform/drawing/shape-xform.d.ts +47 -0
  188. package/dist/types/modules/pdf/core/pdf-stream.d.ts +28 -1
  189. package/dist/types/modules/pdf/font/font-manager.d.ts +26 -0
  190. package/dist/types/modules/pdf/render/page-renderer.d.ts +51 -3
  191. package/dist/types/modules/word/advanced/glossary.d.ts +10 -36
  192. package/dist/types/modules/word/advanced/ole-objects.d.ts +28 -0
  193. package/dist/types/modules/word/builder/run-builders.d.ts +7 -1
  194. package/dist/types/modules/word/constants.d.ts +4 -0
  195. package/dist/types/modules/word/convert/docx-to-semantic.d.ts +2 -1
  196. package/dist/types/modules/word/convert/html/html-import.d.ts +32 -1
  197. package/dist/types/modules/word/convert/html/html.d.ts +2 -2
  198. package/dist/types/modules/word/convert/markdown/markdown-import.d.ts +48 -18
  199. package/dist/types/modules/word/convert/markdown/markdown.d.ts +1 -1
  200. package/dist/types/modules/word/html.d.ts +2 -2
  201. package/dist/types/modules/word/index.base.d.ts +3 -3
  202. package/dist/types/modules/word/markdown.d.ts +1 -1
  203. package/dist/types/modules/word/query/compat.d.ts +10 -2
  204. package/dist/types/modules/word/types.d.ts +96 -1
  205. package/dist/types/modules/word/writer/glossary-writer.d.ts +28 -0
  206. package/dist/types/utils/font-metrics.d.ts +8 -0
  207. package/package.json +3 -1
@@ -43,6 +43,10 @@ export interface NoteConfig {
43
43
  };
44
44
  editAs?: string;
45
45
  anchor?: string;
46
+ /** Comment box width in points. Defaults to 97.8pt when omitted. */
47
+ width?: number;
48
+ /** Comment box height in points. Defaults to 59.1pt when omitted. */
49
+ height?: number;
46
50
  }
47
51
  export interface NoteModel {
48
52
  type: string;
@@ -20,9 +20,16 @@ import type { Writable } from "../../stream/index.js";
20
20
  * Extends the public {@link ImageData} shape with the unique stored name
21
21
  * (`name`) assigned by `addImage`, and pins `type` to `"image"`.
22
22
  */
23
- export interface Medium extends ImageData {
23
+ export interface Medium extends Omit<ImageData, "extension"> {
24
24
  type: "image";
25
25
  name: string;
26
+ /**
27
+ * Widened from `ImageData.extension` so an SVG companion medium can carry
28
+ * the `"svg"` extension (the public `addImage` input stays raster-only).
29
+ */
30
+ extension: string;
31
+ /** Media index of an SVG companion (raster blip + svgBlip extension). */
32
+ svgMediaId?: number;
26
33
  }
27
34
  interface CommentRef {
28
35
  commentName: string;
@@ -497,6 +497,24 @@ export interface ImageData {
497
497
  * are required.
498
498
  */
499
499
  link?: string;
500
+ /**
501
+ * Attach a scalable SVG alongside a raster fallback.
502
+ *
503
+ * Excel stores SVG pictures as a raster `a:blip` (the `extension`/`buffer`/
504
+ * `base64`/`filename` on this object — typically a PNG) plus an
505
+ * `asvg:svgBlip` extension pointing at the vector data. The raster image is
506
+ * what older Excel versions and non-SVG consumers render, so it is required;
507
+ * modern Excel renders the crisp SVG. This library does **not** rasterize —
508
+ * you supply both the SVG bytes and the raster fallback you want embedded.
509
+ */
510
+ svg?: {
511
+ /** SVG bytes (mutually use one of buffer/base64/filename). */
512
+ buffer?: Buffer;
513
+ /** Base64-encoded SVG. */
514
+ base64?: string;
515
+ /** Path to an `.svg` file (Node only). */
516
+ filename?: string;
517
+ };
500
518
  }
501
519
  export interface ImagePosition {
502
520
  tl: {
@@ -556,6 +574,69 @@ export interface ImageHyperlinkValue {
556
574
  hyperlink: string;
557
575
  tooltip?: string;
558
576
  }
577
+ /**
578
+ * Preset geometry for a drawing shape. Mirrors the OOXML `prst` vocabulary;
579
+ * the most common presets are surfaced here, but any valid preset name is
580
+ * accepted as a fallback `string`.
581
+ */
582
+ export type ShapeType = "rect" | "roundRect" | "ellipse" | "triangle" | "line" | "rightArrow" | "leftArrow" | "upArrow" | "downArrow" | "diamond" | "hexagon" | "star5" | (string & {});
583
+ /** Options for `Worksheet.addShape`. */
584
+ export interface AddShapeOptions {
585
+ /** Preset geometry (defaults to `"rect"`). */
586
+ type?: ShapeType;
587
+ /** Where the shape sits — a cell range (e.g. `"B2:D5"`) or anchor object. */
588
+ range: AddImageRange;
589
+ /** Solid fill colour as hex RGB (e.g. `"FF0000"`). Omit for no fill. */
590
+ fillColor?: string;
591
+ /** Outline colour as hex RGB (e.g. `"000000"`). */
592
+ lineColor?: string;
593
+ /** Outline width in points. */
594
+ lineWidth?: number;
595
+ /** Optional centred text label. */
596
+ text?: string;
597
+ /** Display name (defaults to `"Shape N"`). */
598
+ name?: string;
599
+ }
600
+ /** Internal serialized model for a worksheet shape. */
601
+ export interface ShapeModel {
602
+ type: "shape";
603
+ shapeType: string;
604
+ range: AddImageRange;
605
+ fillColor?: string;
606
+ lineColor?: string;
607
+ lineWidth?: number;
608
+ text?: string;
609
+ name?: string;
610
+ /**
611
+ * Resolved anchor coordinates, filled in by the worksheet model getter so
612
+ * the serializer doesn't need range-parsing logic. Mirrors the three image
613
+ * anchoring modes: two-cell (`tl`+`br`), one-cell (`tl`+`ext`) and absolute
614
+ * (`pos`+`ext`). Internal only.
615
+ */
616
+ anchorRange?: {
617
+ tl: {
618
+ nativeCol: number;
619
+ nativeColOff: number;
620
+ nativeRow: number;
621
+ nativeRowOff: number;
622
+ };
623
+ br?: {
624
+ nativeCol: number;
625
+ nativeColOff: number;
626
+ nativeRow: number;
627
+ nativeRowOff: number;
628
+ };
629
+ ext?: {
630
+ width?: number;
631
+ height?: number;
632
+ };
633
+ pos?: {
634
+ x: number;
635
+ y: number;
636
+ };
637
+ editAs?: string;
638
+ };
639
+ }
559
640
  /**
560
641
  * Watermark placement mode in the Excel worksheet.
561
642
  *
@@ -19,6 +19,12 @@ export interface DrawingAnchor {
19
19
  * (`<a:blip r:link>`) instead of an embedded one (`<a:blip r:embed>`).
20
20
  */
21
21
  external?: boolean;
22
+ /**
23
+ * Relationship id of an SVG companion. When set, the raster `a:blip`
24
+ * (referenced by `rId`) carries an `asvg:svgBlip` extension pointing at
25
+ * the SVG media via this id.
26
+ */
27
+ svgRId?: string;
22
28
  };
23
29
  range: any;
24
30
  }
@@ -54,6 +60,8 @@ export interface MediaLike {
54
60
  buffer?: unknown;
55
61
  base64?: unknown;
56
62
  filename?: unknown;
63
+ /** Media index of an SVG companion (raster blip + svgBlip extension). */
64
+ svgMediaId?: number;
57
65
  }
58
66
  /**
59
67
  * Resolves a media filename into the drawing-level relative target path.
@@ -34,6 +34,12 @@ export interface WorkbookMedia {
34
34
  name?: string;
35
35
  /** External link target — when set, the image is referenced, not embedded. */
36
36
  link?: string;
37
+ /**
38
+ * Media index of the SVG companion for this raster image. When set, the
39
+ * picture is written as a raster `a:blip` plus an `asvg:svgBlip` extension
40
+ * referencing the SVG media at this index. Internal bookkeeping only.
41
+ */
42
+ svgMediaId?: number;
37
43
  }
38
44
  /** Internal model type for serialization */
39
45
  export interface WorkbookModel {
@@ -820,6 +826,16 @@ declare class Workbook {
820
826
  * const id = workbook.addImage({ extension: "png", link: "https://example.com/logo.png" });
821
827
  * worksheet.addImage(id, "B2:D6");
822
828
  * ```
829
+ *
830
+ * @example SVG with raster fallback — crisp in modern Excel, safe everywhere
831
+ * ```typescript
832
+ * const id = workbook.addImage({
833
+ * buffer: pngFallbackBytes, // shown by older Excel / non-SVG consumers
834
+ * extension: "png",
835
+ * svg: { buffer: svgBytes } // shown by Excel 2016+
836
+ * });
837
+ * worksheet.addImage(id, "B2:D6");
838
+ * ```
823
839
  */
824
840
  addImage(image: ImageData): number;
825
841
  getImage(id: number | string): WorkbookMedia | undefined;
@@ -14,7 +14,7 @@ import { Range, type RangeInput } from "./range.js";
14
14
  import { Row, type RowModel } from "./row.js";
15
15
  import type { AddSparklineGroupOptions, SparklineGroup } from "./sparkline/index.js";
16
16
  import { Table, type TableModel } from "./table.js";
17
- import type { AddImageRange, AutoFilter, CellValue, ColBreak, ConditionalFormattingOptions, DataValidation, IgnoredError, RowBreak, RowValues, TableProperties, ThreadedComment, WatermarkOptions, WorksheetProperties, WorksheetState, WorksheetView } from "./types.js";
17
+ import type { AddImageRange, AddShapeOptions, AutoFilter, CellValue, ColBreak, ConditionalFormattingOptions, DataValidation, IgnoredError, RowBreak, RowValues, ShapeModel, TableProperties, ThreadedComment, WatermarkOptions, WorksheetProperties, WorksheetState, WorksheetView } from "./types.js";
18
18
  import { type Origin } from "./utils/address.js";
19
19
  import type { Workbook } from "./workbook.js";
20
20
  type DataValidationModel = {
@@ -110,6 +110,7 @@ interface WorksheetModel {
110
110
  views: Partial<WorksheetView>[];
111
111
  autoFilter: AutoFilter | null;
112
112
  media: ImageModel[];
113
+ shapes?: ShapeModel[];
113
114
  sheetProtection: SheetProtection | null;
114
115
  tables: TableModel[];
115
116
  pivotTables: PivotTable[];
@@ -156,6 +157,7 @@ declare class Worksheet {
156
157
  views: Partial<WorksheetView>[];
157
158
  autoFilter: AutoFilter | null;
158
159
  private _media;
160
+ private _shapes;
159
161
  private _charts;
160
162
  private _sparklineGroups;
161
163
  sheetProtection: SheetProtection | null;
@@ -362,6 +364,34 @@ declare class Worksheet {
362
364
  * embed an image within the worksheet to cover a range
363
365
  */
364
366
  addImage(imageId: string | number, range: AddImageRange): void;
367
+ /**
368
+ * Add a free-form drawing shape (rectangle, ellipse, line, text box, …) to
369
+ * the worksheet, anchored to a cell range.
370
+ *
371
+ * Unlike images, shapes need no media file — the geometry, fill, outline and
372
+ * optional text label are written directly into the drawing part.
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * worksheet.addShape({
377
+ * type: "rect",
378
+ * range: "B2:D5",
379
+ * fillColor: "FFD966",
380
+ * lineColor: "000000",
381
+ * lineWidth: 1,
382
+ * text: "Important"
383
+ * });
384
+ * ```
385
+ */
386
+ addShape(options: AddShapeOptions): void;
387
+ /** All shapes added to this worksheet. */
388
+ getShapes(): ShapeModel[];
389
+ /**
390
+ * Resolve a shape's `range` into concrete two-cell anchor coordinates,
391
+ * reusing the `Image` range parser so cell-address/anchor handling stays in
392
+ * one place. Returns a serializable ShapeModel for the worksheet xform.
393
+ */
394
+ private _resolveShapeModel;
365
395
  getImages(): Image[];
366
396
  /**
367
397
  * Add a chart to the worksheet, positioned at the given range.
@@ -5,6 +5,8 @@ interface ShapeModel {
5
5
  insetmode?: string;
6
6
  inset?: number[];
7
7
  };
8
+ width?: number;
9
+ height?: number;
8
10
  };
9
11
  refAddress?: any;
10
12
  }
@@ -20,6 +22,11 @@ declare class VmlShapeXform extends BaseXform {
20
22
  parseOpen(node: any): boolean;
21
23
  parseText(text: string): void;
22
24
  parseClose(name: string): boolean;
25
+ /**
26
+ * Extract a points-valued length (e.g. `width:120pt`) from a VML style
27
+ * string. Returns `undefined` when the property is absent or not in `pt`.
28
+ */
29
+ static parseStyleLength(style: string, prop: "width" | "height"): number | undefined;
23
30
  static V_SHAPE_ATTRIBUTES: (model: ShapeModel, index: number) => any;
24
31
  }
25
32
  export { VmlShapeXform };
@@ -8,6 +8,12 @@ interface BlipModel {
8
8
  * instead of an embedded one via `r:embed`.
9
9
  */
10
10
  external?: boolean;
11
+ /**
12
+ * Relationship id of an SVG companion. When set, the raster blip carries an
13
+ * `asvg:svgBlip` extension referencing the SVG media so Excel 2016+ renders
14
+ * the vector image while older consumers fall back to the raster blip.
15
+ */
16
+ svgRId?: string;
11
17
  }
12
18
  declare class BlipXform extends BaseXform<BlipModel> {
13
19
  constructor();
@@ -6,6 +6,7 @@ interface OneCellModel {
6
6
  ext: any;
7
7
  };
8
8
  picture?: any;
9
+ shape?: any;
9
10
  /** Graphic frame model (for charts and other embedded objects) */
10
11
  graphicFrame?: any;
11
12
  }
@@ -6,6 +6,8 @@ interface PicModel {
6
6
  alphaModFix?: number;
7
7
  /** When true, render the picture as an external linked image (`r:link`). */
8
8
  external?: boolean;
9
+ /** Relationship id of an SVG companion (asvg:svgBlip extension). */
10
+ svgRId?: string;
9
11
  [key: string]: any;
10
12
  }
11
13
  declare class PicXform extends BaseXform {
@@ -0,0 +1,47 @@
1
+ import { BaseXform } from "../base-xform.js";
2
+ /** Fill specification for a drawing shape. */
3
+ export interface ShapeFill {
4
+ /** Solid fill colour as a hex RGB string (e.g. "FF0000"). Omit for no fill. */
5
+ color?: string;
6
+ }
7
+ /** Line (outline) specification for a drawing shape. */
8
+ export interface ShapeLine {
9
+ /** Line colour as a hex RGB string (e.g. "000000"). */
10
+ color?: string;
11
+ /** Line width in points. */
12
+ width?: number;
13
+ }
14
+ /**
15
+ * Model for a user-visible drawing shape (`<xdr:sp>`).
16
+ *
17
+ * Distinct from the form-control shape rendered by `SpXform` — this one is
18
+ * visible, carries a configurable preset geometry, solid fill, outline and an
19
+ * optional text label, and is NOT wrapped in an `a14` AlternateContent block.
20
+ */
21
+ export interface ShapeRenderModel {
22
+ /** Marks this as a user shape so the anchor routes to ShapeXform. */
23
+ kind: "userShape";
24
+ /** Unique drawing id. */
25
+ cNvPrId: number;
26
+ /** Display name (e.g. "Rectangle 1"). */
27
+ name: string;
28
+ /** Preset geometry name (e.g. "rect", "ellipse", "line", "roundRect"). */
29
+ shapeType: string;
30
+ fill?: ShapeFill;
31
+ line?: ShapeLine;
32
+ /** Optional text label centred in the shape. */
33
+ text?: string;
34
+ }
35
+ /**
36
+ * Renders a user-visible drawing shape. Geometry/position is governed by the
37
+ * enclosing anchor (`xfrm` is written as zero, matching how Excel anchors a
38
+ * shape to a cell range), while preset geometry, fill, outline and text are
39
+ * taken from the model. Write-only: shapes are not parsed back on read (the
40
+ * same limitation that already applies to all non-chart drawing content).
41
+ */
42
+ declare class ShapeXform extends BaseXform {
43
+ model: ShapeRenderModel;
44
+ get tag(): string;
45
+ render(xmlStream: any, model: ShapeRenderModel): void;
46
+ }
47
+ export { ShapeXform };
@@ -19,12 +19,30 @@ import type { PdfColor } from "../types.js";
19
19
  * and non-stroking (fills/text). We provide methods for both.
20
20
  */
21
21
  export declare class PdfContentStream {
22
+ /**
23
+ * Content stream fragments in draw order. Most entries are plain operator
24
+ * strings produced eagerly. A function entry is a *deferred* fragment:
25
+ * its body is only evaluated at serialization time. This is required for
26
+ * text whose final byte encoding depends on font decisions (embedded
27
+ * CIDFont vs. Type1/WinAnsi vs. Type3 fallback) that are not finalised
28
+ * until `PdfDocumentBuilder.build()`. Deferring keeps the fragment at its
29
+ * exact draw-order position (preserving z-order) while letting the actual
30
+ * encoding run after the font manager's state is settled.
31
+ */
22
32
  private parts;
23
33
  /**
24
34
  * Append a raw PDF operator string to the content stream.
25
35
  * Use this for operators not covered by the typed API (e.g. `d1` for Type3 glyphs).
26
36
  */
27
37
  raw(operator: string): this;
38
+ /**
39
+ * Append a deferred fragment whose body is evaluated only at serialization
40
+ * time. Used by text drawing so the final byte encoding can be chosen after
41
+ * the document's fonts are resolved at build time. The fragment occupies its
42
+ * draw-order slot immediately, so z-order relative to other operators is
43
+ * preserved.
44
+ */
45
+ deferred(produce: () => string): this;
28
46
  /**
29
47
  * Save the current graphics state (push onto state stack).
30
48
  * Must be balanced with a corresponding restore().
@@ -222,7 +240,16 @@ export declare class PdfContentStream {
222
240
  */
223
241
  roundedRect(x: number, y: number, width: number, height: number, r: number): this;
224
242
  /**
225
- * Get the content stream as a string.
243
+ * Whether any fragment has been appended. Unlike `toString().length > 0`,
244
+ * this does NOT evaluate deferred fragments, so it is safe to call before
245
+ * fonts are resolved (e.g. when probing for overlay content during an
246
+ * editor save, prior to `writeFontResources`). A deferred text fragment
247
+ * counts as content even though its bytes are not produced yet.
248
+ */
249
+ hasContent(): boolean;
250
+ /**
251
+ * Get the content stream as a string. Deferred fragments (see `deferred`)
252
+ * are evaluated here, after font resolution has completed at build time.
226
253
  */
227
254
  toString(): string;
228
255
  /**
@@ -76,9 +76,35 @@ export declare class FontManager {
76
76
  * Get the embedded font's resource name (if registered).
77
77
  */
78
78
  getEmbeddedResourceName(): string;
79
+ /**
80
+ * Resolve the resource name a draw-time-resolved Type1 resource should
81
+ * actually render (and be measured) with, given the font manager's
82
+ * *current* state. If an embedded font exists (possibly auto-discovered
83
+ * at build time, after the text was drawn against a Type1 resource), the
84
+ * embedded resource name is returned so both measurement and encoding go
85
+ * through the CIDFont. Otherwise the original Type1 resource name is kept;
86
+ * `measureText` handles Type3-fallback widths internally from that name.
87
+ *
88
+ * Centralises the routing rule shared by the deferred text renderer and
89
+ * any deferred measurement (anchor alignment, word wrapping) so the two
90
+ * never disagree.
91
+ */
92
+ resolveRenderResourceName(type1ResourceName: string): string;
79
93
  /**
80
94
  * Record that a text string will be rendered, tracking its code points.
81
95
  * Must be called for every text string before writing the PDF.
96
+ *
97
+ * Two sets are maintained because font selection may be decided *after*
98
+ * drawing (e.g. `PdfDocumentBuilder.build()` auto-discovers and embeds a
99
+ * system font once it sees the accumulated non-WinAnsi code points):
100
+ *
101
+ * - `usedCodePoints` — every code point seen, always. If an embedded
102
+ * font ends up being used (whether registered up front or
103
+ * auto-discovered at build time), the subset must cover all of these,
104
+ * including plain ASCII, so the CIDFont can encode the full run.
105
+ * - `type3CodePoints` — non-WinAnsi code points only. Drives the
106
+ * build-time decision to auto-embed a system font, and the Type3
107
+ * fallback when none is available.
82
108
  */
83
109
  trackText(text: string): void;
84
110
  /**
@@ -29,10 +29,58 @@ export declare function renderPage(page: LayoutPage, options: ResolvedPdfOptions
29
29
  * when needed. For each sub-run the matrix origin is advanced along the
30
30
  * text direction (cos, sin) by the rendered width.
31
31
  *
32
- * When `useType3` is false this collapses to a single BT/ET pair — identical
33
- * to the old `emitText()` path but wrapped in begin/end for convenience.
32
+ * The emitted operators are written as a *deferred* fragment (see
33
+ * `PdfContentStream.deferred`). The fragment is only evaluated at
34
+ * serialization time, by which point `PdfDocumentBuilder.build()` has
35
+ * finalised the document's fonts (auto-discovered embedded CIDFont,
36
+ * Type3 fallback, or plain Type1). This is essential: at draw time the
37
+ * font manager has not yet decided whether a non-WinAnsi code point (e.g.
38
+ * U+2192 →) will be served by an embedded font or a Type3 glyph, so eager
39
+ * encoding would irreversibly degrade those characters to spaces via the
40
+ * WinAnsi fallback. Deferring the encode keeps the fragment at its exact
41
+ * draw-order slot (preserving z-order) while choosing the correct bytes
42
+ * once fonts are known.
43
+ *
44
+ * The `useType3` argument is the caller's *draw-time* guess and is ignored;
45
+ * the deferred body recomputes the routing from the now-settled font
46
+ * manager state.
47
+ */
48
+ export declare function emitTextWithMatrix(stream: PdfContentStream, text: string, a: number, b: number, c: number, d: number, tx: number, ty: number, type1ResourceName: string, fontSize: number, fontManager: FontManager, _useType3: boolean): void;
49
+ /** Options for a deferred, font-aware text block (see `emitTextBlock`). */
50
+ export interface TextBlockOptions {
51
+ /** The text to draw (may contain `\n` when `maxWidth` is set). */
52
+ text: string;
53
+ /** Left/anchor x in unrotated page space. */
54
+ x: number;
55
+ /** Baseline y of the first line in unrotated page space. */
56
+ y: number;
57
+ /** Draw-time-resolved Type1 resource name; re-routed at build time. */
58
+ type1ResourceName: string;
59
+ fontSize: number;
60
+ /** Horizontal anchor; applied per line (including each wrapped line). */
61
+ anchor: "start" | "middle" | "end";
62
+ /** Word-wrap width in points; enables multi-line layout when set. */
63
+ maxWidth?: number;
64
+ /** Line-height multiple applied to `fontSize` for wrapped lines. */
65
+ lineHeightFactor: number;
66
+ /** Clockwise rotation in degrees about (x, y); applied to every line. */
67
+ rotation: number;
68
+ }
69
+ /**
70
+ * Emit a text block as a single *deferred* fragment so that anchor
71
+ * alignment, word wrapping, and glyph encoding are all computed at
72
+ * serialization time — after `PdfDocumentBuilder.build()` has finalised the
73
+ * document's fonts.
74
+ *
75
+ * This matters because text measurement (anchor offset, line breaking) must
76
+ * use the *same* font that ultimately renders the glyphs. At draw time the
77
+ * font may still be unresolved (a non-WinAnsi run can trigger a build-time
78
+ * auto-embed of a system CIDFont), so measuring against the provisional
79
+ * Type1/Helvetica metrics would misplace centred/right-aligned text and
80
+ * break lines at the wrong points. Deferring keeps measurement and encoding
81
+ * consistent while preserving the fragment's draw-order slot (z-order).
34
82
  */
35
- export declare function emitTextWithMatrix(stream: PdfContentStream, text: string, a: number, b: number, c: number, d: number, tx: number, ty: number, type1ResourceName: string, fontSize: number, fontManager: FontManager, useType3: boolean): void;
83
+ export declare function emitTextBlock(stream: PdfContentStream, options: TextBlockOptions, fontManager: FontManager): void;
36
84
  /**
37
85
  * Generate a deterministic ExtGState resource name for a given alpha value.
38
86
  * Uses 4 decimal digits to avoid collisions between close alpha values.
@@ -4,45 +4,19 @@
4
4
  * Provides types and utilities for working with Glossary Document parts,
5
5
  * which contain AutoText entries, Quick Parts, and other Building Blocks.
6
6
  *
7
- * INTEGRATION STATUS: This module provides data structures and query helpers
8
- * for building blocks. The actual reading/writing of glossary parts from/to
9
- * DOCX archives is handled via the opaqueParts round-trip mechanism —
10
- * glossary parts in existing files are preserved as opaque parts during
11
- * read/write. This module is useful for:
7
+ * INTEGRATION STATUS: This module provides the glossary data model and query
8
+ * helpers. To embed a glossary in a document, assign a {@link GlossaryDocument}
9
+ * to `doc.glossary`; the packager then serialises it to
10
+ * `word/glossary/document.xml`, registers the `glossaryDocument` relationship,
11
+ * and adds the `[Content_Types].xml` override (the canonical OOXML location
12
+ * Word reads Quick Parts / AutoText from). Glossary parts in existing files are
13
+ * round-tripped via the same channel. This module is useful for:
12
14
  * - Building glossary data structures programmatically
13
15
  * - Querying/filtering building block collections
14
- * - Preparing data for future direct glossary part writing
15
- *
16
- * To add glossary content to a document currently, include it as an
17
- * OpaquePart with path "word/glossary/document.xml".
16
+ * - Assembling a glossary to attach via `doc.glossary`
18
17
  */
19
- import type { BodyContent, SectionProperties } from "../types.js";
20
- /** Building block gallery category. */
21
- export type BuildingBlockGallery = "autoText" | "quickParts" | "coverPages" | "tableOfContents" | "headers" | "footers" | "pageNumbers" | "tables" | "textBoxes" | "watermarks" | "equations" | "bibliographies" | "custom1" | "custom2" | "custom3" | "custom4" | "custom5";
22
- /** A single building block (AutoText/Quick Part) entry. */
23
- export interface BuildingBlock {
24
- /** Name of the building block (displayed in gallery). */
25
- readonly name: string;
26
- /** Gallery this block belongs to. */
27
- readonly gallery: BuildingBlockGallery;
28
- /** Category within the gallery. */
29
- readonly category?: string;
30
- /** Description/tooltip. */
31
- readonly description?: string;
32
- /** The content of the building block. */
33
- readonly content: readonly BodyContent[];
34
- /** Section properties specific to this building block. */
35
- readonly sectionProperties?: SectionProperties;
36
- /** Unique identifier (GUID). */
37
- readonly guid?: string;
38
- }
39
- /** The glossary document model. */
40
- export interface GlossaryDocument {
41
- /** Building block entries. */
42
- readonly blocks: readonly BuildingBlock[];
43
- /** Raw parts preserved for round-trip (style, settings, fontTable). */
44
- readonly rawParts?: ReadonlyMap<string, Uint8Array>;
45
- }
18
+ import type { BodyContent, BuildingBlock, BuildingBlockGallery, GlossaryDocument, SectionProperties } from "../types.js";
19
+ export type { BuildingBlock, BuildingBlockGallery, GlossaryDocument } from "../types.js";
46
20
  /**
47
21
  * Create a building block entry.
48
22
  *
@@ -81,6 +81,8 @@ export interface OleEmbeddingResult {
81
81
  readonly olePart: OpaquePart;
82
82
  /** Suggested rId to use for the OLE binary in the document model. */
83
83
  readonly oleRId: string;
84
+ /** OLE ProgId the embedding was created with (e.g. "Excel.Sheet.12"). */
85
+ readonly progId: string;
84
86
  /** Preview image media part (only when `options.previewImage` was supplied). */
85
87
  readonly previewPart?: OpaquePart;
86
88
  /** Suggested rId for the preview image. */
@@ -113,3 +115,29 @@ export declare function createOleEmbedding(data: Uint8Array, progId: string, opt
113
115
  /** Override preview file name. Defaults to `image<N>.<ext>` from previewContentType. */
114
116
  previewFileName?: string;
115
117
  }): OleEmbeddingResult;
118
+ /**
119
+ * Wire an {@link OleEmbeddingResult} into a document so the OLE object is
120
+ * actually rendered and resolvable, returning a new {@link DocxDocument}.
121
+ *
122
+ * Unlike just stuffing the part into `opaqueParts` (which leaves the binary
123
+ * dangling — no relationship, no body reference), this:
124
+ *
125
+ * - registers the OLE binary (and optional preview) on
126
+ * `doc.oleObjects` so the packager emits a `word/_rels/document.xml.rels`
127
+ * relationship with the exact rId and a `[Content_Types].xml` override;
128
+ * - appends a body paragraph carrying a `<w:object>` / `<o:OLEObject>`
129
+ * that references the same rId and embeds the ProgId, so the object is
130
+ * visible in Word and round-trips through `readDocx`.
131
+ *
132
+ * @param doc - The document to add the OLE object to.
133
+ * @param embedding - Result from {@link createOleEmbedding}.
134
+ * @param options - Display geometry (defaults to a 2"×2" icon box).
135
+ */
136
+ export declare function addOleObject(doc: DocxDocument, embedding: OleEmbeddingResult, options?: {
137
+ /** Display width in points (default 96 = 2 inches at 48pt/in icon). */
138
+ widthPt?: number;
139
+ /** Display height in points (default 96). */
140
+ heightPt?: number;
141
+ /** Display mode. Default "icon". */
142
+ displayAs?: OleDisplayAs;
143
+ }): DocxDocument;
@@ -263,7 +263,13 @@ export declare function mathSubScript(base: MathContent[], subScript: MathConten
263
263
  export declare function mathSubSuperScript(base: MathContent[], subScript: MathContent[], superScript: MathContent[]): MathContent;
264
264
  /** Create a math pre-sub-superscript (subscript/superscript before the base). */
265
265
  export declare function mathPreSubSuperScript(base: MathContent[], preSubScript: MathContent[], preSuperScript: MathContent[]): MathContent;
266
- /** Create a math phantom (invisible expression that takes up space). */
266
+ /**
267
+ * Create a math phantom (an expression that takes up space).
268
+ *
269
+ * Note: in OOXML the phantom base is *shown* by default. To make the classic
270
+ * "occupies space but invisible" phantom pass `{ show: false }`; passing only
271
+ * `transparent: true` is not sufficient to hide the base in Word.
272
+ */
267
273
  export declare function mathPhantom(content: MathContent[], options?: {
268
274
  show?: boolean;
269
275
  zeroWidth?: boolean;
@@ -168,6 +168,10 @@ export declare const ContentType: {
168
168
  readonly Xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
169
169
  readonly CustomXml: "application/xml";
170
170
  readonly VbaProject: "application/vnd.ms-office.vbaProject";
171
+ /** Glossary (Building Blocks) document part. */
172
+ readonly Glossary: "application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml";
173
+ /** OLE embedded object binary. */
174
+ readonly OleObject: "application/vnd.openxmlformats-officedocument.oleObject";
171
175
  };
172
176
  /** Map from image file extension to content type. */
173
177
  export declare const IMAGE_CONTENT_TYPES: Record<string, string>;
@@ -11,7 +11,8 @@
11
11
  * - Hyperlink extraction
12
12
  * - Image registration into ConversionContext
13
13
  * - Table structure with merge (colSpan/rowSpan)
14
- * - List/numbering detection (basic)
14
+ * - List/numbering detection: consecutive numbered paragraphs are aggregated
15
+ * into ordered/unordered `list` blocks with nested sub-lists by level
15
16
  * - Footnote/endnote reference and content
16
17
  * - Math content (text fallback)
17
18
  */