@harbour-enterprises/superdoc 0.6.1 → 0.6.3

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.
@@ -1811,7 +1811,7 @@ const FileOptions = buffer$1.FileOptions;
1811
1811
  const INSPECT_MAX_BYTES = buffer$1.INSPECT_MAX_BYTES;
1812
1812
  const SlowBuffer = buffer$1.SlowBuffer;
1813
1813
  const TranscodeEncoding = buffer$1.TranscodeEncoding;
1814
- const atob = buffer$1.atob;
1814
+ const atob$1 = buffer$1.atob;
1815
1815
  const btoa = buffer$1.btoa;
1816
1816
  const constants$1 = buffer$1.constants;
1817
1817
  const isAscii = buffer$1.isAscii;
@@ -1830,7 +1830,7 @@ const dist = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty
1830
1830
  INSPECT_MAX_BYTES,
1831
1831
  SlowBuffer,
1832
1832
  TranscodeEncoding,
1833
- atob,
1833
+ atob: atob$1,
1834
1834
  btoa,
1835
1835
  constants: constants$1,
1836
1836
  default: Buffer$B,
@@ -50463,15 +50463,49 @@ function translateMark(mark) {
50463
50463
  }
50464
50464
  return markElement;
50465
50465
  }
50466
+ function getPngDimensions(base64) {
50467
+ const type2 = base64.split(";")[0].split("/")[1];
50468
+ if (!base64 || type2 !== "png") {
50469
+ return {
50470
+ originalWidth: void 0,
50471
+ originalHeight: void 0
50472
+ };
50473
+ }
50474
+ let header = base64.split(",")[1].slice(0, 50);
50475
+ let uint8 = Uint8Array.from(atob(header), (c) => c.charCodeAt(0));
50476
+ let dataView = new DataView(uint8.buffer, 0, 28);
50477
+ return {
50478
+ originalWidth: dataView.getInt32(16),
50479
+ originalHeight: dataView.getInt32(20)
50480
+ };
50481
+ }
50482
+ function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
50483
+ let scaledWidth = originalWidth;
50484
+ let scaledHeight = originalHeight;
50485
+ let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
50486
+ scaledWidth = Math.round(scaledWidth * ratio);
50487
+ scaledHeight = Math.round(scaledHeight * ratio);
50488
+ return { scaledWidth, scaledHeight };
50489
+ }
50466
50490
  function translateImageNode(params, imageSize) {
50467
50491
  const {
50468
50492
  node: { attrs = {}, marks = [] }
50469
50493
  } = params;
50470
50494
  let imageId = attrs.rId;
50471
- const size = attrs.size ? {
50495
+ const { originalWidth, originalHeight } = getPngDimensions(attrs.imageSrc);
50496
+ let size = attrs.size ? {
50472
50497
  w: pixelsToEmu(attrs.size.width),
50473
50498
  h: pixelsToEmu(attrs.size.height)
50474
50499
  } : imageSize;
50500
+ if (originalWidth && originalHeight) {
50501
+ const boxWidthPx = emuToPixels(size.w);
50502
+ const boxHeightPx = emuToPixels(size.h);
50503
+ const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
50504
+ size = {
50505
+ w: pixelsToEmu(scaledWidth),
50506
+ h: pixelsToEmu(scaledHeight)
50507
+ };
50508
+ }
50475
50509
  if (params.node.type === "image" && !imageId) {
50476
50510
  const path2 = attrs.src?.split("word/")[1];
50477
50511
  imageId = addNewImageRelationship(params, path2);
@@ -52855,7 +52889,7 @@ const _SuperConverter = class _SuperConverter {
52855
52889
  return;
52856
52890
  }
52857
52891
  }
52858
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.6.1") {
52892
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.6.3") {
52859
52893
  const customLocation = "docProps/custom.xml";
52860
52894
  if (!docx[customLocation]) {
52861
52895
  docx[customLocation] = generateCustomXml();
@@ -53102,7 +53136,7 @@ function storeSuperdocVersion(docx) {
53102
53136
  function generateCustomXml() {
53103
53137
  return DEFAULT_CUSTOM_XML;
53104
53138
  }
53105
- function generateSuperdocVersion(version2 = "0.6.1") {
53139
+ function generateSuperdocVersion(version2 = "0.6.3") {
53106
53140
  return {
53107
53141
  type: "element",
53108
53142
  name: "property",
@@ -53174,4 +53208,4 @@ export {
53174
53208
  twipsToLines as y,
53175
53209
  pixelsToTwips as z
53176
53210
  };
53177
- //# sourceMappingURL=converter-DLphK5U8.js.map
53211
+ //# sourceMappingURL=converter-DtoSnlsM.js.map