@@ -58241,6 +58241,7 @@ function nanoid(size = 21) {
58241
58241
}
58242
58242
58243
58243
// src/docx-document.ts
58244
+ var import_node_crypto2 = require("node:crypto");
58244
58245
var import_xmlbuilder23 = __toESM(require_lib12());
58245
58246
58246
58247
// src/helpers/render-document-file.ts
@@ -58566,13 +58567,21 @@ function hex3ToHex(red, green, blue) {
58566
58567
58567
58568
// src/utils/unit-conversion.ts
58568
58569
var pixelRegex = /([\d.]+)px/i;
58570
+ var emRegex = /([\d.]+)em/i;
58571
+ var remRegex = /([\d.]+)rem/i;
58569
58572
var percentageRegex = /([\d.]+)%/i;
58570
58573
var pointRegex = /([\d.]+)pt/i;
58571
58574
var cmRegex = /([\d.]+)cm/i;
58572
58575
var inchRegex = /([\d.]+)in/i;
58573
58576
function pixelToEMU(pixelValue) {
58574
58577
return Math.round(pixelValue * 9525);
58575
58578
}
58579
+ function emToEmu(emValue) {
58580
+ return pixelToEMU(emValue * 16);
58581
+ }
58582
+ function remToEmu(remValue) {
58583
+ return pixelToEMU(remValue * 16);
58584
+ }
58576
58585
function TWIPToEMU(TWIPValue) {
58577
58586
return Math.round(TWIPValue * 635);
58578
58587
}
@@ -59207,27 +59216,40 @@ function computeImageDimensions(vNode, attributes) {
59207
59216
let modifiedHeight;
59208
59217
let modifiedWidth;
59209
59218
if (vNode.properties && vNode.properties.style) {
59210
- if (vNode.properties.style.width) {
59211
- if (vNode.properties.style.width !== "auto") {
59212
- if (pixelRegex.test(vNode.properties.style.width)) {
59213
- modifiedWidth = pixelToEMU(vNode.properties.style.width.match(pixelRegex)[1]);
59214
- } else if (percentageRegex.test(vNode.properties.style.width)) {
59215
- const percentageValue = vNode.properties.style.width.match(percentageRegex)[1];
59219
+ const styleWidth = vNode.properties.style.width;
59220
+ const styleHeight = vNode.properties.style.height;
59221
+ if (styleWidth) {
59222
+ if (styleWidth !== "auto") {
59223
+ if (pixelRegex.test(styleWidth)) {
59224
+ modifiedWidth = pixelToEMU(styleWidth.match(pixelRegex)[1]);
59225
+ } else if (emRegex.test(styleWidth)) {
59226
+ modifiedWidth = emToEmu(styleWidth.match(emRegex)[1]);
59227
+ } else if (remRegex.test(styleWidth)) {
59228
+ modifiedWidth = remToEmu(styleWidth.match(remRegex)[1]);
59229
+ } else if (percentageRegex.test(styleWidth)) {
59230
+ const percentageValue = styleWidth.match(percentageRegex)[1];
59216
59231
modifiedWidth = Math.round(percentageValue / 100 * originalWidthInEMU);
59232
+ } else {
59233
+ modifiedWidth = originalWidthInEMU;
59234
+ modifiedHeight = originalHeightInEMU;
59217
59235
}
59218
59236
} else {
59219
- if (vNode.properties.style.height && vNode.properties.style.height === "auto") {
59237
+ if (styleHeight && styleHeight === "auto") {
59220
59238
modifiedWidth = originalWidthInEMU;
59221
59239
modifiedHeight = originalHeightInEMU;
59222
59240
}
59223
59241
}
59224
59242
}
59225
- if (vNode.properties.style.height) {
59226
- if (vNode.properties.style.height !== "auto") {
59227
- if (pixelRegex.test(vNode.properties.style.height)) {
59228
- modifiedHeight = pixelToEMU(vNode.properties.style.height.match(pixelRegex)[1]);
59229
- } else if (percentageRegex.test(vNode.properties.style.height)) {
59230
- const percentageValue = vNode.properties.style.width.match(percentageRegex)[1];
59243
+ if (styleHeight) {
59244
+ if (styleHeight !== "auto") {
59245
+ if (pixelRegex.test(styleHeight)) {
59246
+ modifiedHeight = pixelToEMU(styleHeight.match(pixelRegex)[1]);
59247
+ } else if (emRegex.test(styleWidth)) {
59248
+ modifiedWidth = emToEmu(styleWidth.match(emRegex)[1]);
59249
+ } else if (remRegex.test(styleWidth)) {
59250
+ modifiedWidth = emToEmu(styleWidth.match(remRegex)[1]);
59251
+ } else if (percentageRegex.test(styleHeight)) {
59252
+ const percentageValue = styleWidth.match(percentageRegex)[1];
59231
59253
modifiedHeight = Math.round(percentageValue / 100 * originalHeightInEMU);
59232
59254
if (!modifiedWidth) {
59233
59255
modifiedWidth = Math.round(modifiedHeight * aspectRatio);
@@ -59248,13 +59270,16 @@ function computeImageDimensions(vNode, attributes) {
59248
59270
modifiedHeight = Math.round(modifiedWidth / aspectRatio);
59249
59271
} else if (modifiedHeight && !modifiedWidth) {
59250
59272
modifiedWidth = Math.round(modifiedHeight * aspectRatio);
59273
+ } else {
59274
+ modifiedWidth = originalWidthInEMU;
59275
+ modifiedHeight = originalHeightInEMU;
59251
59276
}
59252
59277
} else {
59253
59278
modifiedWidth = originalWidthInEMU;
59254
59279
modifiedHeight = originalHeightInEMU;
59255
59280
}
59256
59281
attributes.width = modifiedWidth;
59257
- attributes.height = modifiedHeight || 0 ;
59282
+ attributes.height = modifiedHeight;
59258
59283
}
59259
59284
async function buildParagraph(vNode, attributes, docxDocumentInstance) {
59260
59285
const paragraphFragment = import_xmlbuilder2.fragment({ namespaceAlias: { w: namespaces_default.w } }).ele("@w", "p");
@@ -59790,14 +59815,14 @@ function buildTableProperties(attributes) {
59790
59815
break;
59791
59816
}
59792
59817
case "tableCellSpacing": {
59793
- const tableCellSpacingFragment = buildTableCellSpacing(attributes[key] );
59818
+ const tableCellSpacingFragment = buildTableCellSpacing(attributes.tableCellSpacing );
59794
59819
tablePropertiesFragment.import(tableCellSpacingFragment);
59795
59820
delete attributes.tableCellSpacing;
59796
59821
break;
59797
59822
}
59798
59823
case "width": {
59799
- if (attributes[key] ) {
59800
- const tableWidthFragment = buildTableWidth(attributes[key] );
59824
+ if (attributes.width ) {
59825
+ const tableWidthFragment = buildTableWidth(attributes.width );
59801
59826
tablePropertiesFragment.import(tableWidthFragment);
59802
59827
}
59803
59828
delete attributes.width;
@@ -59967,8 +59992,11 @@ async function buildTable(vNode, attributes, docxDocumentInstance) {
59967
59992
function buildPresetGeometry() {
59968
59993
return import_xmlbuilder2.fragment({ namespaceAlias: { a: namespaces_default.a } }).ele("@a", "prstGeom").att("prst", "rect").up();
59969
59994
}
59970
- function buildExtents({ width = 0, height = 0 }) {
59971
- return import_xmlbuilder2.fragment({ namespaceAlias: { a: namespaces_default.a } }).ele("@a", "ext").att("cx", String(width)).att("cy", String(height)).up();
59995
+ function buildExtents({ width, height }) {
59996
+ if (!width && !height) {
59997
+ return;
59998
+ }
59999
+ return import_xmlbuilder2.fragment({ namespaceAlias: { a: namespaces_default.a } }).ele("@a", "ext").att("cx", String(width || "")).att("cy", String(height || "")).up();
59972
60000
}
59973
60001
function buildOffset() {
59974
60002
return import_xmlbuilder2.fragment({ namespaceAlias: { a: namespaces_default.a } }).ele("@a", "off").att("x", "0").att("y", "0").up();
@@ -59980,7 +60008,9 @@ function buildGraphicFrameTransform(attributes) {
59980
60008
const offsetFragment = buildOffset();
59981
60009
graphicFrameTransformFragment.import(offsetFragment);
59982
60010
const extentsFragment = buildExtents(attributes);
59983
- graphicFrameTransformFragment.import(extentsFragment);
60011
+ if (extentsFragment) {
60012
+ graphicFrameTransformFragment.import(extentsFragment);
60013
+ }
59984
60014
graphicFrameTransformFragment.up();
59985
60015
return graphicFrameTransformFragment;
59986
60016
}
@@ -60046,8 +60076,8 @@ function buildPicture({
60046
60076
fileNameWithExtension,
60047
60077
description,
60048
60078
relationshipId,
60049
- width = 0 ,
60050
- height = 0
60079
+ width,
60080
+ height
60051
60081
}) {
60052
60082
const pictureFragment = import_xmlbuilder2.fragment({ namespaceAlias: { pic: namespaces_default.pic } }).ele("@pic", "pic");
60053
60083
const nonVisualPicturePropertiesFragment = buildNonVisualPictureProperties(id || 0, fileNameWithExtension || "", description || "");
@@ -60084,8 +60114,11 @@ function buildWrapSquare() {
60084
60114
function buildEffectExtentFragment() {
60085
60115
return import_xmlbuilder2.fragment({ namespaceAlias: { wp: namespaces_default.wp } }).ele("@wp", "effectExtent").att("b", "0").att("l", "0").att("r", "0").att("t", "0").up();
60086
60116
}
60087
- function buildExtent({ width = 0, height = 0 }) {
60088
- return import_xmlbuilder2.fragment({ namespaceAlias: { wp: namespaces_default.wp } }).ele("@wp", "extent").att("cx", String(width)).att("cy", String(height)).up();
60117
+ function buildExtent({ width, height }) {
60118
+ if (!width && !height) {
60119
+ return;
60120
+ }
60121
+ return import_xmlbuilder2.fragment({ namespaceAlias: { wp: namespaces_default.wp } }).ele("@wp", "extent").att("cx", String(width || "")).att("cy", String(height || "")).up();
60089
60122
}
60090
60123
function buildPositionV() {
60091
60124
return import_xmlbuilder2.fragment({ namespaceAlias: { wp: namespaces_default.wp } }).ele("@wp", "positionV").att("relativeFrom", "paragraph").ele("@wp", "posOffset").txt("19050").up();
@@ -60110,7 +60143,9 @@ function buildAnchoredDrawing(graphicType, attributes) {
60110
60143
width: attributes.width,
60111
60144
height: attributes.height
60112
60145
});
60113
- anchoredDrawingFragment.import(extentFragment);
60146
+ if (extentFragment) {
60147
+ anchoredDrawingFragment.import(extentFragment);
60148
+ }
60114
60149
const effectExtentFragment = buildEffectExtentFragment();
60115
60150
anchoredDrawingFragment.import(effectExtentFragment);
60116
60151
const wrapSquareFragment = buildWrapSquare();
@@ -60130,7 +60165,9 @@ function buildInlineDrawing(graphicType, attributes) {
60130
60165
width: attributes.width,
60131
60166
height: attributes.height
60132
60167
});
60133
- inlineDrawingFragment.import(extentFragment);
60168
+ if (extentFragment) {
60169
+ inlineDrawingFragment.import(extentFragment);
60170
+ }
60134
60171
const effectExtentFragment = buildEffectExtentFragment();
60135
60172
inlineDrawingFragment.import(effectExtentFragment);
60136
60173
const drawingObjectNonVisualPropertiesFragment = buildDrawingObjectNonVisualProperties(attributes.id || 0, attributes.fileNameWithExtension || "");
@@ -61041,6 +61078,9 @@ class ListStyleBuilder {
61041
61078
}
61042
61079
61043
61080
// src/docx-document.ts
61081
+ function sha1(content) {
61082
+ return import_node_crypto2.createHash("sha1").update(content).digest("hex");
61083
+ }
61044
61084
function generateContentTypesFragments(contentTypesXML2, type, objects) {
61045
61085
if (objects && Array.isArray(objects)) {
61046
61086
objects.forEach((object) => {
@@ -61357,7 +61397,9 @@ class DocxDocument {
61357
61397
throw new Error("Invalid data URL");
61358
61398
}
61359
61399
const fileExtension = fileData.extension === "octet-stream" ? "png" : fileData.extension;
61360
- const fileNameWithExtension = `image-${nanoid()}.${fileExtension}`;
61400
+ const randId = nanoid(8);
61401
+ const contentHash = sha1(fileData.base64Content);
61402
+ const fileNameWithExtension = `image-${randId}-${contentHash}.${fileExtension}`;
61361
61403
this.lastMediaId += 1;
61362
61404
return {
61363
61405
id: this.lastMediaId,
0 commit comments