docgen-utils 1.0.22 → 1.0.23

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/bundle.js CHANGED
@@ -67134,6 +67134,28 @@ ${generateStylesCss(styleMap, themeFonts)}
67134
67134
  const imgEl = el;
67135
67135
  const natW = imgEl.naturalWidth;
67136
67136
  const natH = imgEl.naturalHeight;
67137
+ let objectPosition;
67138
+ const objPos = imgComputed.objectPosition;
67139
+ if (objPos && objectFit === "cover") {
67140
+ const parts = objPos.trim().split(/\s+/);
67141
+ const parseFraction = (val, dimension) => {
67142
+ if (val.endsWith("%")) {
67143
+ return parseFloat(val) / 100;
67144
+ }
67145
+ const px = parseFloat(val);
67146
+ if (!isNaN(px) && dimension > 0) {
67147
+ return px / dimension;
67148
+ }
67149
+ return 0.5;
67150
+ };
67151
+ const displayW = wasClipped ? clippedW : rect2.width;
67152
+ const displayH = wasClipped ? clippedH : rect2.height;
67153
+ const xFrac = parts.length >= 1 ? parseFraction(parts[0], displayW) : 0.5;
67154
+ const yFrac = parts.length >= 2 ? parseFraction(parts[1], displayH) : xFrac;
67155
+ if (Math.abs(xFrac - 0.5) > 1e-3 || Math.abs(yFrac - 0.5) > 1e-3) {
67156
+ objectPosition = [xFrac, yFrac];
67157
+ }
67158
+ }
67137
67159
  const imageElement = {
67138
67160
  type: isFullSlideImage ? "slideBackgroundImage" : "image",
67139
67161
  src: imgSrc,
@@ -67145,10 +67167,13 @@ ${generateStylesCss(styleMap, themeFonts)}
67145
67167
  },
67146
67168
  sizing: objectFit === "cover" ? { type: "cover" } : null
67147
67169
  };
67148
- if (objectFit === "cover" && natW > 0 && natH > 0 && !isFullSlideImage) {
67170
+ if (objectFit === "cover" && natW > 0 && natH > 0) {
67149
67171
  imageElement.naturalWidth = natW;
67150
67172
  imageElement.naturalHeight = natH;
67151
67173
  }
67174
+ if (objectPosition) {
67175
+ imageElement.objectPosition = objectPosition;
67176
+ }
67152
67177
  if (imgRectRadius !== null) {
67153
67178
  imageElement.rectRadius = imgRectRadius;
67154
67179
  }
@@ -68473,6 +68498,29 @@ ${generateStylesCss(styleMap, themeFonts)}
68473
68498
  }
68474
68499
  return runs;
68475
68500
  }
68501
+ function computeCoverCrop(naturalWidth, naturalHeight, boxW, boxH, objectPosition) {
68502
+ const imgRatio = naturalHeight / naturalWidth;
68503
+ const boxRatio = boxH / boxW;
68504
+ const isBoxBased = boxRatio > imgRatio;
68505
+ const effW = isBoxBased ? boxH / imgRatio : boxW;
68506
+ const effH = isBoxBased ? boxH : boxW * imgRatio;
68507
+ const [anchorX, anchorY] = objectPosition ?? [0.5, 0.5];
68508
+ const excessW = effW - boxW;
68509
+ const excessH = effH - boxH;
68510
+ const cropX = excessW * anchorX;
68511
+ const cropY = excessH * anchorY;
68512
+ return {
68513
+ effW,
68514
+ effH,
68515
+ sizing: {
68516
+ type: "crop",
68517
+ x: cropX,
68518
+ y: cropY,
68519
+ w: boxW,
68520
+ h: boxH
68521
+ }
68522
+ };
68523
+ }
68476
68524
  function sleep(ms) {
68477
68525
  return new Promise((resolve) => setTimeout(resolve, ms));
68478
68526
  }
@@ -68582,7 +68630,12 @@ ${generateStylesCss(styleMap, themeFonts)}
68582
68630
  w: el.position.w,
68583
68631
  h: el.position.h
68584
68632
  };
68585
- if (el.sizing && el.sizing.type) {
68633
+ if (el.sizing && el.sizing.type === "cover" && el.naturalWidth && el.naturalHeight) {
68634
+ const crop = computeCoverCrop(el.naturalWidth, el.naturalHeight, el.position.w, el.position.h, el.objectPosition);
68635
+ imageOptions.w = crop.effW;
68636
+ imageOptions.h = crop.effH;
68637
+ imageOptions.sizing = crop.sizing;
68638
+ } else if (el.sizing && el.sizing.type) {
68586
68639
  imageOptions.sizing = { type: el.sizing.type, w: el.position.w, h: el.position.h };
68587
68640
  }
68588
68641
  if (el.brightness !== void 0)
@@ -68624,22 +68677,10 @@ ${generateStylesCss(styleMap, themeFonts)}
68624
68677
  h: el.position.h
68625
68678
  };
68626
68679
  if (el.sizing && el.sizing.type === "cover" && el.naturalWidth && el.naturalHeight) {
68627
- const imgRatio = el.naturalHeight / el.naturalWidth;
68628
- const boxRatio = el.position.h / el.position.w;
68629
- const isBoxBased = boxRatio > imgRatio;
68630
- const effW = isBoxBased ? el.position.h / imgRatio : el.position.w;
68631
- const effH = isBoxBased ? el.position.h : el.position.w * imgRatio;
68632
- const cropX = (effW - el.position.w) / 2;
68633
- const cropY = (effH - el.position.h) / 2;
68634
- imageOptions.w = effW;
68635
- imageOptions.h = effH;
68636
- imageOptions.sizing = {
68637
- type: "crop",
68638
- x: cropX,
68639
- y: cropY,
68640
- w: el.position.w,
68641
- h: el.position.h
68642
- };
68680
+ const crop = computeCoverCrop(el.naturalWidth, el.naturalHeight, el.position.w, el.position.h, el.objectPosition);
68681
+ imageOptions.w = crop.effW;
68682
+ imageOptions.h = crop.effH;
68683
+ imageOptions.sizing = crop.sizing;
68643
68684
  } else if (el.sizing && el.sizing.type) {
68644
68685
  imageOptions.sizing = { type: el.sizing.type, w: el.position.w, h: el.position.h };
68645
68686
  }