Skip to content

Commit 7587cc3

Browse files
committed
Add latest builds
1 parent b6a2a64 commit 7587cc3

File tree

2 files changed

+138
-54
lines changed

2 files changed

+138
-54
lines changed

Diff for: dist/index-cjs.js

+69-27
Original file line numberDiff line numberDiff line change
@@ -58241,6 +58241,7 @@ function nanoid(size = 21) {
5824158241
}
5824258242

5824358243
// src/docx-document.ts
58244+
var import_node_crypto2 = require("node:crypto");
5824458245
var import_xmlbuilder23 = __toESM(require_lib12());
5824558246

5824658247
// src/helpers/render-document-file.ts
@@ -58566,13 +58567,21 @@ function hex3ToHex(red, green, blue) {
5856658567

5856758568
// src/utils/unit-conversion.ts
5856858569
var pixelRegex = /([\d.]+)px/i;
58570+
var emRegex = /([\d.]+)em/i;
58571+
var remRegex = /([\d.]+)rem/i;
5856958572
var percentageRegex = /([\d.]+)%/i;
5857058573
var pointRegex = /([\d.]+)pt/i;
5857158574
var cmRegex = /([\d.]+)cm/i;
5857258575
var inchRegex = /([\d.]+)in/i;
5857358576
function pixelToEMU(pixelValue) {
5857458577
return Math.round(pixelValue * 9525);
5857558578
}
58579+
function emToEmu(emValue) {
58580+
return pixelToEMU(emValue * 16);
58581+
}
58582+
function remToEmu(remValue) {
58583+
return pixelToEMU(remValue * 16);
58584+
}
5857658585
function TWIPToEMU(TWIPValue) {
5857758586
return Math.round(TWIPValue * 635);
5857858587
}
@@ -59207,27 +59216,40 @@ function computeImageDimensions(vNode, attributes) {
5920759216
let modifiedHeight;
5920859217
let modifiedWidth;
5920959218
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];
5921659231
modifiedWidth = Math.round(percentageValue / 100 * originalWidthInEMU);
59232+
} else {
59233+
modifiedWidth = originalWidthInEMU;
59234+
modifiedHeight = originalHeightInEMU;
5921759235
}
5921859236
} else {
59219-
if (vNode.properties.style.height && vNode.properties.style.height === "auto") {
59237+
if (styleHeight && styleHeight === "auto") {
5922059238
modifiedWidth = originalWidthInEMU;
5922159239
modifiedHeight = originalHeightInEMU;
5922259240
}
5922359241
}
5922459242
}
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];
5923159253
modifiedHeight = Math.round(percentageValue / 100 * originalHeightInEMU);
5923259254
if (!modifiedWidth) {
5923359255
modifiedWidth = Math.round(modifiedHeight * aspectRatio);
@@ -59248,13 +59270,16 @@ function computeImageDimensions(vNode, attributes) {
5924859270
modifiedHeight = Math.round(modifiedWidth / aspectRatio);
5924959271
} else if (modifiedHeight && !modifiedWidth) {
5925059272
modifiedWidth = Math.round(modifiedHeight * aspectRatio);
59273+
} else {
59274+
modifiedWidth = originalWidthInEMU;
59275+
modifiedHeight = originalHeightInEMU;
5925159276
}
5925259277
} else {
5925359278
modifiedWidth = originalWidthInEMU;
5925459279
modifiedHeight = originalHeightInEMU;
5925559280
}
5925659281
attributes.width = modifiedWidth;
59257-
attributes.height = modifiedHeight || 0;
59282+
attributes.height = modifiedHeight;
5925859283
}
5925959284
async function buildParagraph(vNode, attributes, docxDocumentInstance) {
5926059285
const paragraphFragment = import_xmlbuilder2.fragment({ namespaceAlias: { w: namespaces_default.w } }).ele("@w", "p");
@@ -59790,14 +59815,14 @@ function buildTableProperties(attributes) {
5979059815
break;
5979159816
}
5979259817
case "tableCellSpacing": {
59793-
const tableCellSpacingFragment = buildTableCellSpacing(attributes[key]);
59818+
const tableCellSpacingFragment = buildTableCellSpacing(attributes.tableCellSpacing);
5979459819
tablePropertiesFragment.import(tableCellSpacingFragment);
5979559820
delete attributes.tableCellSpacing;
5979659821
break;
5979759822
}
5979859823
case "width": {
59799-
if (attributes[key]) {
59800-
const tableWidthFragment = buildTableWidth(attributes[key]);
59824+
if (attributes.width) {
59825+
const tableWidthFragment = buildTableWidth(attributes.width);
5980159826
tablePropertiesFragment.import(tableWidthFragment);
5980259827
}
5980359828
delete attributes.width;
@@ -59967,8 +59992,11 @@ async function buildTable(vNode, attributes, docxDocumentInstance) {
5996759992
function buildPresetGeometry() {
5996859993
return import_xmlbuilder2.fragment({ namespaceAlias: { a: namespaces_default.a } }).ele("@a", "prstGeom").att("prst", "rect").up();
5996959994
}
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();
5997260000
}
5997360001
function buildOffset() {
5997460002
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) {
5998060008
const offsetFragment = buildOffset();
5998160009
graphicFrameTransformFragment.import(offsetFragment);
5998260010
const extentsFragment = buildExtents(attributes);
59983-
graphicFrameTransformFragment.import(extentsFragment);
60011+
if (extentsFragment) {
60012+
graphicFrameTransformFragment.import(extentsFragment);
60013+
}
5998460014
graphicFrameTransformFragment.up();
5998560015
return graphicFrameTransformFragment;
5998660016
}
@@ -60046,8 +60076,8 @@ function buildPicture({
6004660076
fileNameWithExtension,
6004760077
description,
6004860078
relationshipId,
60049-
width = 0,
60050-
height = 0
60079+
width,
60080+
height
6005160081
}) {
6005260082
const pictureFragment = import_xmlbuilder2.fragment({ namespaceAlias: { pic: namespaces_default.pic } }).ele("@pic", "pic");
6005360083
const nonVisualPicturePropertiesFragment = buildNonVisualPictureProperties(id || 0, fileNameWithExtension || "", description || "");
@@ -60084,8 +60114,11 @@ function buildWrapSquare() {
6008460114
function buildEffectExtentFragment() {
6008560115
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();
6008660116
}
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();
6008960122
}
6009060123
function buildPositionV() {
6009160124
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) {
6011060143
width: attributes.width,
6011160144
height: attributes.height
6011260145
});
60113-
anchoredDrawingFragment.import(extentFragment);
60146+
if (extentFragment) {
60147+
anchoredDrawingFragment.import(extentFragment);
60148+
}
6011460149
const effectExtentFragment = buildEffectExtentFragment();
6011560150
anchoredDrawingFragment.import(effectExtentFragment);
6011660151
const wrapSquareFragment = buildWrapSquare();
@@ -60130,7 +60165,9 @@ function buildInlineDrawing(graphicType, attributes) {
6013060165
width: attributes.width,
6013160166
height: attributes.height
6013260167
});
60133-
inlineDrawingFragment.import(extentFragment);
60168+
if (extentFragment) {
60169+
inlineDrawingFragment.import(extentFragment);
60170+
}
6013460171
const effectExtentFragment = buildEffectExtentFragment();
6013560172
inlineDrawingFragment.import(effectExtentFragment);
6013660173
const drawingObjectNonVisualPropertiesFragment = buildDrawingObjectNonVisualProperties(attributes.id || 0, attributes.fileNameWithExtension || "");
@@ -61041,6 +61078,9 @@ class ListStyleBuilder {
6104161078
}
6104261079

6104361080
// src/docx-document.ts
61081+
function sha1(content) {
61082+
return import_node_crypto2.createHash("sha1").update(content).digest("hex");
61083+
}
6104461084
function generateContentTypesFragments(contentTypesXML2, type, objects) {
6104561085
if (objects && Array.isArray(objects)) {
6104661086
objects.forEach((object) => {
@@ -61357,7 +61397,9 @@ class DocxDocument {
6135761397
throw new Error("Invalid data URL");
6135861398
}
6135961399
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}`;
6136161403
this.lastMediaId += 1;
6136261404
return {
6136361405
id: this.lastMediaId,

0 commit comments

Comments
 (0)