@harbour-enterprises/superdoc 0.6.1 → 0.6.2

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.
@@ -1813,7 +1813,7 @@ const FileOptions = buffer$1.FileOptions;
1813
1813
  const INSPECT_MAX_BYTES = buffer$1.INSPECT_MAX_BYTES;
1814
1814
  const SlowBuffer = buffer$1.SlowBuffer;
1815
1815
  const TranscodeEncoding = buffer$1.TranscodeEncoding;
1816
- const atob = buffer$1.atob;
1816
+ const atob$1 = buffer$1.atob;
1817
1817
  const btoa = buffer$1.btoa;
1818
1818
  const constants$1 = buffer$1.constants;
1819
1819
  const isAscii = buffer$1.isAscii;
@@ -1832,7 +1832,7 @@ const dist = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty
1832
1832
  INSPECT_MAX_BYTES,
1833
1833
  SlowBuffer,
1834
1834
  TranscodeEncoding,
1835
- atob,
1835
+ atob: atob$1,
1836
1836
  btoa,
1837
1837
  constants: constants$1,
1838
1838
  default: Buffer$B,
@@ -50437,15 +50437,49 @@ function translateMark(mark) {
50437
50437
  }
50438
50438
  return markElement;
50439
50439
  }
50440
+ function getPngDimensions(base64) {
50441
+ const type2 = base64.split(";")[0].split("/")[1];
50442
+ if (!base64 || type2 !== "png") {
50443
+ return {
50444
+ originalWidth: void 0,
50445
+ originalHeight: void 0
50446
+ };
50447
+ }
50448
+ let header = base64.split(",")[1].slice(0, 50);
50449
+ let uint8 = Uint8Array.from(atob(header), (c2) => c2.charCodeAt(0));
50450
+ let dataView = new DataView(uint8.buffer, 0, 28);
50451
+ return {
50452
+ originalWidth: dataView.getInt32(16),
50453
+ originalHeight: dataView.getInt32(20)
50454
+ };
50455
+ }
50456
+ function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
50457
+ let scaledWidth = originalWidth;
50458
+ let scaledHeight = originalHeight;
50459
+ let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
50460
+ scaledWidth = Math.round(scaledWidth * ratio);
50461
+ scaledHeight = Math.round(scaledHeight * ratio);
50462
+ return { scaledWidth, scaledHeight };
50463
+ }
50440
50464
  function translateImageNode(params2, imageSize) {
50441
50465
  const {
50442
50466
  node: { attrs = {}, marks = [] }
50443
50467
  } = params2;
50444
50468
  let imageId = attrs.rId;
50445
- const size2 = attrs.size ? {
50469
+ const { originalWidth, originalHeight } = getPngDimensions(attrs.imageSrc);
50470
+ let size2 = attrs.size ? {
50446
50471
  w: pixelsToEmu(attrs.size.width),
50447
50472
  h: pixelsToEmu(attrs.size.height)
50448
50473
  } : imageSize;
50474
+ if (originalWidth && originalHeight) {
50475
+ const boxWidthPx = emuToPixels(size2.w);
50476
+ const boxHeightPx = emuToPixels(size2.h);
50477
+ const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
50478
+ size2 = {
50479
+ w: pixelsToEmu(scaledWidth),
50480
+ h: pixelsToEmu(scaledHeight)
50481
+ };
50482
+ }
50449
50483
  if (params2.node.type === "image" && !imageId) {
50450
50484
  const path2 = attrs.src?.split("word/")[1];
50451
50485
  imageId = addNewImageRelationship(params2, path2);
@@ -52813,7 +52847,7 @@ const _SuperConverter = class _SuperConverter2 {
52813
52847
  return;
52814
52848
  }
52815
52849
  }
52816
- static updateDocumentVersion(docx = this.convertedXml, version2 = "0.6.1") {
52850
+ static updateDocumentVersion(docx = this.convertedXml, version2 = "0.6.2") {
52817
52851
  const customLocation = "docProps/custom.xml";
52818
52852
  if (!docx[customLocation]) {
52819
52853
  docx[customLocation] = generateCustomXml();
@@ -53053,7 +53087,7 @@ function storeSuperdocVersion(docx) {
53053
53087
  function generateCustomXml() {
53054
53088
  return DEFAULT_CUSTOM_XML;
53055
53089
  }
53056
- function generateSuperdocVersion(version2 = "0.6.1") {
53090
+ function generateSuperdocVersion(version2 = "0.6.2") {
53057
53091
  return {
53058
53092
  type: "element",
53059
53093
  name: "property",
@@ -66875,7 +66909,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
66875
66909
  * @returns {Y.Doc | undefined} Updated Y.Doc if any, otherwise undefined
66876
66910
  */
66877
66911
  processCollaborationMigrations() {
66878
- console.debug("[checkVersionMigrations] Current editor version", "0.6.1");
66912
+ console.debug("[checkVersionMigrations] Current editor version", "0.6.2");
66879
66913
  if (!this.options.ydoc) return;
66880
66914
  const metaMap = this.options.ydoc.getMap("meta");
66881
66915
  let docVersion = metaMap.get("version");
@@ -87137,4 +87171,4 @@ export {
87137
87171
  helpers as k,
87138
87172
  index as l
87139
87173
  };
87140
- //# sourceMappingURL=super-editor.es-8AR-vN66.js.map
87174
+ //# sourceMappingURL=super-editor.es-BTmZ_2zD.js.map