ugcinc-render 1.8.224 → 1.8.225

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.
@@ -835,6 +835,28 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
835
835
  const canvas = document.createElement("canvas");
836
836
  measureCtx = canvas.getContext("2d");
837
837
  }
838
+ const attachmentPrefixes = ["image-", "story-reply-image-", "story-reply-bar-", "story-reply-text-"];
839
+ const getMessageGroupBounds = (messageElementId) => {
840
+ const elem = elementMap.get(messageElementId);
841
+ if (!elem) return void 0;
842
+ const actualHeight = getActualElementHeight(elem, textValues, measureCtx);
843
+ let top = elem.y;
844
+ let bottom = elem.y + actualHeight;
845
+ let left = elem.x;
846
+ let right = elem.x + elem.width;
847
+ const msgIdSuffix = messageElementId.replace(/^message-/, "");
848
+ for (const prefix of attachmentPrefixes) {
849
+ const assocElem = elementMap.get(`${prefix}${msgIdSuffix}`);
850
+ if (assocElem) {
851
+ const assocHeight = getActualElementHeight(assocElem, textValues, measureCtx);
852
+ top = Math.min(top, assocElem.y);
853
+ bottom = Math.max(bottom, assocElem.y + assocHeight);
854
+ left = Math.min(left, assocElem.x);
855
+ right = Math.max(right, assocElem.x + assocElem.width);
856
+ }
857
+ }
858
+ return { top, bottom, left, right };
859
+ };
838
860
  let cropY = 0;
839
861
  let cropHeight = canvasHeight;
840
862
  if (dynamicCrop.vertical?.enabled) {
@@ -860,16 +882,24 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
860
882
  let topY = 0;
861
883
  let bottomY = canvasHeight;
862
884
  if (startElementId) {
863
- const startElem = elementMap.get(startElementId);
864
- if (startElem) {
865
- topY = startElem.y;
885
+ const bounds = getMessageGroupBounds(startElementId);
886
+ if (bounds) {
887
+ topY = bounds.top;
888
+ } else {
889
+ const startElem = elementMap.get(startElementId);
890
+ if (startElem) topY = startElem.y;
866
891
  }
867
892
  }
868
893
  if (endElementId) {
869
- const endElem = elementMap.get(endElementId);
870
- if (endElem) {
871
- const actualHeight = getActualElementHeight(endElem, textValues, measureCtx);
872
- bottomY = endElem.y + actualHeight;
894
+ const bounds = getMessageGroupBounds(endElementId);
895
+ if (bounds) {
896
+ bottomY = bounds.bottom;
897
+ } else {
898
+ const endElem = elementMap.get(endElementId);
899
+ if (endElem) {
900
+ const actualHeight = getActualElementHeight(endElem, textValues, measureCtx);
901
+ bottomY = endElem.y + actualHeight;
902
+ }
873
903
  }
874
904
  }
875
905
  cropY = Math.max(0, topY - paddingStart);
@@ -904,15 +934,21 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
904
934
  let leftX = 0;
905
935
  let rightX = canvasWidth;
906
936
  if (startElementId) {
907
- const startElem = elementMap.get(startElementId);
908
- if (startElem) {
909
- leftX = startElem.x;
937
+ const bounds = getMessageGroupBounds(startElementId);
938
+ if (bounds) {
939
+ leftX = bounds.left;
940
+ } else {
941
+ const startElem = elementMap.get(startElementId);
942
+ if (startElem) leftX = startElem.x;
910
943
  }
911
944
  }
912
945
  if (endElementId) {
913
- const endElem = elementMap.get(endElementId);
914
- if (endElem) {
915
- rightX = endElem.x + endElem.width;
946
+ const bounds = getMessageGroupBounds(endElementId);
947
+ if (bounds) {
948
+ rightX = bounds.right;
949
+ } else {
950
+ const endElem = elementMap.get(endElementId);
951
+ if (endElem) rightX = endElem.x + endElem.width;
916
952
  }
917
953
  }
918
954
  cropX = Math.max(0, leftX - paddingStart);
package/dist/index.js CHANGED
@@ -1532,6 +1532,28 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
1532
1532
  const canvas = document.createElement("canvas");
1533
1533
  measureCtx = canvas.getContext("2d");
1534
1534
  }
1535
+ const attachmentPrefixes = ["image-", "story-reply-image-", "story-reply-bar-", "story-reply-text-"];
1536
+ const getMessageGroupBounds = (messageElementId) => {
1537
+ const elem = elementMap.get(messageElementId);
1538
+ if (!elem) return void 0;
1539
+ const actualHeight = getActualElementHeight(elem, textValues, measureCtx);
1540
+ let top = elem.y;
1541
+ let bottom = elem.y + actualHeight;
1542
+ let left = elem.x;
1543
+ let right = elem.x + elem.width;
1544
+ const msgIdSuffix = messageElementId.replace(/^message-/, "");
1545
+ for (const prefix of attachmentPrefixes) {
1546
+ const assocElem = elementMap.get(`${prefix}${msgIdSuffix}`);
1547
+ if (assocElem) {
1548
+ const assocHeight = getActualElementHeight(assocElem, textValues, measureCtx);
1549
+ top = Math.min(top, assocElem.y);
1550
+ bottom = Math.max(bottom, assocElem.y + assocHeight);
1551
+ left = Math.min(left, assocElem.x);
1552
+ right = Math.max(right, assocElem.x + assocElem.width);
1553
+ }
1554
+ }
1555
+ return { top, bottom, left, right };
1556
+ };
1535
1557
  let cropY = 0;
1536
1558
  let cropHeight = canvasHeight;
1537
1559
  if (dynamicCrop.vertical?.enabled) {
@@ -1557,16 +1579,24 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
1557
1579
  let topY = 0;
1558
1580
  let bottomY = canvasHeight;
1559
1581
  if (startElementId) {
1560
- const startElem = elementMap.get(startElementId);
1561
- if (startElem) {
1562
- topY = startElem.y;
1582
+ const bounds = getMessageGroupBounds(startElementId);
1583
+ if (bounds) {
1584
+ topY = bounds.top;
1585
+ } else {
1586
+ const startElem = elementMap.get(startElementId);
1587
+ if (startElem) topY = startElem.y;
1563
1588
  }
1564
1589
  }
1565
1590
  if (endElementId) {
1566
- const endElem = elementMap.get(endElementId);
1567
- if (endElem) {
1568
- const actualHeight = getActualElementHeight(endElem, textValues, measureCtx);
1569
- bottomY = endElem.y + actualHeight;
1591
+ const bounds = getMessageGroupBounds(endElementId);
1592
+ if (bounds) {
1593
+ bottomY = bounds.bottom;
1594
+ } else {
1595
+ const endElem = elementMap.get(endElementId);
1596
+ if (endElem) {
1597
+ const actualHeight = getActualElementHeight(endElem, textValues, measureCtx);
1598
+ bottomY = endElem.y + actualHeight;
1599
+ }
1570
1600
  }
1571
1601
  }
1572
1602
  cropY = Math.max(0, topY - paddingStart);
@@ -1601,15 +1631,21 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
1601
1631
  let leftX = 0;
1602
1632
  let rightX = canvasWidth;
1603
1633
  if (startElementId) {
1604
- const startElem = elementMap.get(startElementId);
1605
- if (startElem) {
1606
- leftX = startElem.x;
1634
+ const bounds = getMessageGroupBounds(startElementId);
1635
+ if (bounds) {
1636
+ leftX = bounds.left;
1637
+ } else {
1638
+ const startElem = elementMap.get(startElementId);
1639
+ if (startElem) leftX = startElem.x;
1607
1640
  }
1608
1641
  }
1609
1642
  if (endElementId) {
1610
- const endElem = elementMap.get(endElementId);
1611
- if (endElem) {
1612
- rightX = endElem.x + endElem.width;
1643
+ const bounds = getMessageGroupBounds(endElementId);
1644
+ if (bounds) {
1645
+ rightX = bounds.right;
1646
+ } else {
1647
+ const endElem = elementMap.get(endElementId);
1648
+ if (endElem) rightX = endElem.x + endElem.width;
1613
1649
  }
1614
1650
  }
1615
1651
  cropX = Math.max(0, leftX - paddingStart);
package/dist/index.mjs CHANGED
@@ -47,7 +47,7 @@ import {
47
47
  resolveCaptionStyle,
48
48
  resolveElementPositions,
49
49
  wrapText
50
- } from "./chunk-2BNW6ZNK.mjs";
50
+ } from "./chunk-4WPUQ7LJ.mjs";
51
51
 
52
52
  // src/types/element.ts
53
53
  var DIMENSION_PRESETS = {
@@ -908,6 +908,28 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
908
908
  const canvas = document.createElement("canvas");
909
909
  measureCtx = canvas.getContext("2d");
910
910
  }
911
+ const attachmentPrefixes = ["image-", "story-reply-image-", "story-reply-bar-", "story-reply-text-"];
912
+ const getMessageGroupBounds = (messageElementId) => {
913
+ const elem = elementMap.get(messageElementId);
914
+ if (!elem) return void 0;
915
+ const actualHeight = getActualElementHeight(elem, textValues, measureCtx);
916
+ let top = elem.y;
917
+ let bottom = elem.y + actualHeight;
918
+ let left = elem.x;
919
+ let right = elem.x + elem.width;
920
+ const msgIdSuffix = messageElementId.replace(/^message-/, "");
921
+ for (const prefix of attachmentPrefixes) {
922
+ const assocElem = elementMap.get(`${prefix}${msgIdSuffix}`);
923
+ if (assocElem) {
924
+ const assocHeight = getActualElementHeight(assocElem, textValues, measureCtx);
925
+ top = Math.min(top, assocElem.y);
926
+ bottom = Math.max(bottom, assocElem.y + assocHeight);
927
+ left = Math.min(left, assocElem.x);
928
+ right = Math.max(right, assocElem.x + assocElem.width);
929
+ }
930
+ }
931
+ return { top, bottom, left, right };
932
+ };
911
933
  let cropY = 0;
912
934
  let cropHeight = canvasHeight;
913
935
  if (dynamicCrop.vertical?.enabled) {
@@ -933,16 +955,24 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
933
955
  let topY = 0;
934
956
  let bottomY = canvasHeight;
935
957
  if (startElementId) {
936
- const startElem = elementMap.get(startElementId);
937
- if (startElem) {
938
- topY = startElem.y;
958
+ const bounds = getMessageGroupBounds(startElementId);
959
+ if (bounds) {
960
+ topY = bounds.top;
961
+ } else {
962
+ const startElem = elementMap.get(startElementId);
963
+ if (startElem) topY = startElem.y;
939
964
  }
940
965
  }
941
966
  if (endElementId) {
942
- const endElem = elementMap.get(endElementId);
943
- if (endElem) {
944
- const actualHeight = getActualElementHeight(endElem, textValues, measureCtx);
945
- bottomY = endElem.y + actualHeight;
967
+ const bounds = getMessageGroupBounds(endElementId);
968
+ if (bounds) {
969
+ bottomY = bounds.bottom;
970
+ } else {
971
+ const endElem = elementMap.get(endElementId);
972
+ if (endElem) {
973
+ const actualHeight = getActualElementHeight(endElem, textValues, measureCtx);
974
+ bottomY = endElem.y + actualHeight;
975
+ }
946
976
  }
947
977
  }
948
978
  cropY = Math.max(0, topY - paddingStart);
@@ -977,15 +1007,21 @@ function calculateCropBounds(elements, dynamicCrop, canvasWidth, canvasHeight, t
977
1007
  let leftX = 0;
978
1008
  let rightX = canvasWidth;
979
1009
  if (startElementId) {
980
- const startElem = elementMap.get(startElementId);
981
- if (startElem) {
982
- leftX = startElem.x;
1010
+ const bounds = getMessageGroupBounds(startElementId);
1011
+ if (bounds) {
1012
+ leftX = bounds.left;
1013
+ } else {
1014
+ const startElem = elementMap.get(startElementId);
1015
+ if (startElem) leftX = startElem.x;
983
1016
  }
984
1017
  }
985
1018
  if (endElementId) {
986
- const endElem = elementMap.get(endElementId);
987
- if (endElem) {
988
- rightX = endElem.x + endElem.width;
1019
+ const bounds = getMessageGroupBounds(endElementId);
1020
+ if (bounds) {
1021
+ rightX = bounds.right;
1022
+ } else {
1023
+ const endElem = elementMap.get(endElementId);
1024
+ if (endElem) rightX = endElem.x + endElem.width;
989
1025
  }
990
1026
  }
991
1027
  cropX = Math.max(0, leftX - paddingStart);
@@ -47,7 +47,7 @@ import {
47
47
  resolveCaptionStyle,
48
48
  resolveElementPositions,
49
49
  wrapText
50
- } from "../chunk-2BNW6ZNK.mjs";
50
+ } from "../chunk-4WPUQ7LJ.mjs";
51
51
  export {
52
52
  APPLE_EMOJI_FONT,
53
53
  CAPTION_PRESETS,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ugcinc-render",
3
- "version": "1.8.224",
3
+ "version": "1.8.225",
4
4
  "description": "Unified rendering package for UGC Inc - shared types, components, and compositions for pixel-perfect client/server rendering",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",