docxmlater 11.0.8 → 11.0.10
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/core/DocumentParser.d.ts.map +1 -1
- package/dist/core/DocumentParser.js +4 -4
- package/dist/core/DocumentParser.js.map +1 -1
- 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/core/DocumentParser.js +4 -4
- package/dist/esm/core/DocumentParser.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/core/DocumentParser.ts +11 -6
- 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"]}
|
|
@@ -2666,18 +2666,18 @@ export class DocumentParser {
|
|
|
2666
2666
|
if (!runsByParagraph.has(fr.paragraphIndex)) {
|
|
2667
2667
|
runsByParagraph.set(fr.paragraphIndex, new Set());
|
|
2668
2668
|
}
|
|
2669
|
-
runsByParagraph.get(fr.paragraphIndex).add(fr.
|
|
2669
|
+
runsByParagraph.get(fr.paragraphIndex).add(fr.run);
|
|
2670
2670
|
}
|
|
2671
2671
|
const affectedParagraphIndices = Array.from(runsByParagraph.keys()).sort((a, b) => a - b);
|
|
2672
2672
|
for (const pIdx of affectedParagraphIndices) {
|
|
2673
2673
|
const paragraph = allParagraphs[pIdx];
|
|
2674
|
-
const
|
|
2674
|
+
const runsToRemove = runsByParagraph.get(pIdx);
|
|
2675
2675
|
const content = paragraph.getContent();
|
|
2676
2676
|
if (pIdx === targetParagraphIndex) {
|
|
2677
2677
|
const newContent = [];
|
|
2678
2678
|
let hyperlinkInserted = false;
|
|
2679
2679
|
for (let rIdx = 0; rIdx < content.length; rIdx++) {
|
|
2680
|
-
if (
|
|
2680
|
+
if (runsToRemove.has(content[rIdx])) {
|
|
2681
2681
|
if (!hyperlinkInserted) {
|
|
2682
2682
|
newContent.push(hyperlink);
|
|
2683
2683
|
hyperlinkInserted = true;
|
|
@@ -2690,7 +2690,7 @@ export class DocumentParser {
|
|
|
2690
2690
|
paragraph.setContent(newContent);
|
|
2691
2691
|
}
|
|
2692
2692
|
else {
|
|
2693
|
-
const newContent = content.filter((
|
|
2693
|
+
const newContent = content.filter((item) => !runsToRemove.has(item));
|
|
2694
2694
|
paragraph.setContent(newContent);
|
|
2695
2695
|
}
|
|
2696
2696
|
}
|