docxmlater 11.0.8 → 11.0.9
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.
- package/dist/elements/Image.d.ts +2 -0
- package/dist/elements/Image.d.ts.map +1 -1
- package/dist/elements/Image.js +6 -0
- package/dist/elements/Image.js.map +1 -1
- package/dist/elements/ImageRun.d.ts.map +1 -1
- package/dist/elements/ImageRun.js +9 -1
- package/dist/elements/ImageRun.js.map +1 -1
- package/dist/esm/elements/Image.js +6 -0
- package/dist/esm/elements/Image.js.map +1 -1
- package/dist/esm/elements/ImageRun.js +9 -1
- package/dist/esm/elements/ImageRun.js.map +1 -1
- package/package.json +1 -1
- package/src/elements/Image.ts +14 -0
- package/src/elements/ImageRun.ts +15 -2
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImageRun = void 0;
|
|
4
4
|
const Run_js_1 = require("./Run.js");
|
|
5
|
+
const XMLBuilder_js_1 = require("../xml/XMLBuilder.js");
|
|
5
6
|
class ImageRun extends Run_js_1.Run {
|
|
6
7
|
imageElement;
|
|
7
8
|
_rawRunXml;
|
|
@@ -20,7 +21,14 @@ class ImageRun extends Run_js_1.Run {
|
|
|
20
21
|
}
|
|
21
22
|
toXML() {
|
|
22
23
|
if (this._rawRunXml) {
|
|
23
|
-
|
|
24
|
+
if (!this.imageElement.isMutated()) {
|
|
25
|
+
return { name: '__rawXml', rawXml: this._rawRunXml };
|
|
26
|
+
}
|
|
27
|
+
const drawingXml = XMLBuilder_js_1.XMLBuilder.elementToString(this.imageElement.toXML());
|
|
28
|
+
const spliced = this._rawRunXml.replace(/<w:drawing\b[\s\S]*<\/w:drawing>/, drawingXml);
|
|
29
|
+
if (spliced !== this._rawRunXml) {
|
|
30
|
+
return { name: '__rawXml', rawXml: spliced };
|
|
31
|
+
}
|
|
24
32
|
}
|
|
25
33
|
const drawing = this.imageElement.toXML();
|
|
26
34
|
const children = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ImageRun.js","sourceRoot":"","sources":["../../src/elements/ImageRun.ts"],"names":[],"mappings":";;;AAQA,qCAA+B;
|
|
1
|
+
{"version":3,"file":"ImageRun.js","sourceRoot":"","sources":["../../src/elements/ImageRun.ts"],"names":[],"mappings":";;;AAQA,qCAA+B;AAE/B,wDAA8D;AAc9D,MAAa,QAAS,SAAQ,YAAG;IACvB,YAAY,CAAQ;IACpB,UAAU,CAAU;IAM5B,YAAY,KAAY;QAGtB,KAAK,CAAC,EAAE,CAAC,CAAC;QACV,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;IAC5B,CAAC;IAED,YAAY,CAAC,GAAW;QACtB,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IACxB,CAAC;IAED,YAAY;QACV,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAMD,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;IAOD,KAAK;QACH,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAEpB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,EAAE,CAAC;gBACnC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,CAAC;YACvD,CAAC;YAKD,MAAM,UAAU,GAAG,0BAAU,CAAC,eAAe,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC;YACzE,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,kCAAkC,EAAE,UAAU,CAAC,CAAC;YACxF,IAAI,OAAO,KAAK,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;YAC/C,CAAC;QAEH,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAiB,EAAE,CAAC;QAMlC,MAAM,GAAG,GAAG,YAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAC/D,IAAI,GAAG;YAAE,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC5B,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACvB,OAAO;YACL,IAAI,EAAE,KAAK;YACX,QAAQ;SACT,CAAC;IACJ,CAAC;CACF;AApED,4BAoEC","sourcesContent":["/**\n * ImageRun - A run that contains an image (drawing)\n * Extends Run class for type-safe paragraph content\n *\n * This is a specialized Run that contains a drawing instead of text.\n * It generates proper w:r (run) XML with w:drawing child element.\n */\n\nimport { Run } from './Run.js';\nimport { Image } from './Image.js';\nimport { XMLElement, XMLBuilder } from '../xml/XMLBuilder.js';\n\n/**\n * ImageRun - A run containing an embedded image\n *\n * In WordprocessingML, images are embedded in runs as drawing elements:\n * <w:r>\n * <w:drawing>\n * <wp:inline>\n * ... image data ...\n * </wp:inline>\n * </w:drawing>\n * </w:r>\n */\nexport class ImageRun extends Run {\n private imageElement: Image;\n private _rawRunXml?: string;\n\n /**\n * Creates a new image run\n * @param image The image to embed in this run\n */\n constructor(image: Image) {\n // Call parent constructor with empty text\n // The text is irrelevant for image runs\n super('');\n this.imageElement = image;\n }\n\n setRawRunXml(xml: string): void {\n this._rawRunXml = xml;\n }\n\n getRawRunXml(): string | undefined {\n return this._rawRunXml;\n }\n\n /**\n * Gets the image element\n * @returns Image instance\n */\n getImageElement(): Image {\n return this.imageElement;\n }\n\n /**\n * Override toXML to generate image-specific XML\n * Generates a w:r element containing w:drawing instead of w:t\n * @returns XMLElement with w:r containing w:drawing\n */\n toXML(): XMLElement {\n if (this._rawRunXml) {\n // No live mutation since parse — emit the captured run XML verbatim (round-trip).\n if (!this.imageElement.isMutated()) {\n return { name: '__rawXml', rawXml: this._rawRunXml };\n }\n // The live image was mutated (e.g. setBorder/setSize). Splice the regenerated\n // <w:drawing> into the captured run XML so the change applies while preserving the\n // run's rPr and other captured details — a full regenerate would drop the parsed\n // rPr (not modeled on revision-nested image runs) and can clip the image in Word.\n const drawingXml = XMLBuilder.elementToString(this.imageElement.toXML());\n const spliced = this._rawRunXml.replace(/<w:drawing\\b[\\s\\S]*<\\/w:drawing>/, drawingXml);\n if (spliced !== this._rawRunXml) {\n return { name: '__rawXml', rawXml: spliced };\n }\n // No <w:drawing> found to splice (unexpected) — fall through to full regeneration.\n }\n const drawing = this.imageElement.toXML();\n const children: XMLElement[] = [];\n // Per ECMA-376 §17.3.2.28, w:rPr (if present) must precede the run's\n // content. For runs containing an inline drawing, the rPr's w:rFonts\n // affects line metrics in Word; dropping it shifts the baseline and\n // can let images (with shadow effectExtent) overflow their containing\n // cell. Emit rPr whenever the run carries formatting.\n const rPr = Run.generateRunPropertiesXML(this.getFormatting());\n if (rPr) children.push(rPr);\n children.push(drawing);\n return {\n name: 'w:r',\n children,\n };\n }\n}\n"]}
|
|
@@ -24,6 +24,7 @@ export class Image {
|
|
|
24
24
|
flipH = false;
|
|
25
25
|
flipV = false;
|
|
26
26
|
border;
|
|
27
|
+
_mutated = false;
|
|
27
28
|
presetGeometry = 'rect';
|
|
28
29
|
compressionState = 'none';
|
|
29
30
|
bwMode = 'auto';
|
|
@@ -530,8 +531,12 @@ export class Image {
|
|
|
530
531
|
setSize(width, height) {
|
|
531
532
|
this.width = width;
|
|
532
533
|
this.height = height;
|
|
534
|
+
this._mutated = true;
|
|
533
535
|
return this;
|
|
534
536
|
}
|
|
537
|
+
isMutated() {
|
|
538
|
+
return this._mutated;
|
|
539
|
+
}
|
|
535
540
|
async updateImageData(newSource) {
|
|
536
541
|
this.source = newSource;
|
|
537
542
|
this.imageData = undefined;
|
|
@@ -904,6 +909,7 @@ export class Image {
|
|
|
904
909
|
this.effectExtent.top = Math.max(this.effectExtent.top, halfBorderEmu);
|
|
905
910
|
this.effectExtent.right = Math.max(this.effectExtent.right, halfBorderEmu);
|
|
906
911
|
this.effectExtent.bottom = Math.max(this.effectExtent.bottom, halfBorderEmu);
|
|
912
|
+
this._mutated = true;
|
|
907
913
|
return this;
|
|
908
914
|
}
|
|
909
915
|
removeBorder() {
|