@solidpepper/solidpepper-solidgeneration 0.2.0 → 0.2.1
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.
|
@@ -474,6 +474,7 @@ class DataSheetSingleton {
|
|
|
474
474
|
class DataSheetSVG {
|
|
475
475
|
constructor(dataSheet) {
|
|
476
476
|
this.previewId = 0;
|
|
477
|
+
this.debugTable = false;
|
|
477
478
|
if (!dataSheet) {
|
|
478
479
|
throw new Error('DataSheet instance is required to create a DataSheetSVG');
|
|
479
480
|
}
|
|
@@ -782,9 +783,9 @@ class DataSheetSVG {
|
|
|
782
783
|
let widths = this.DataSheet.publicationTemplateBackgroundLeftMargin;
|
|
783
784
|
for (let i = 0; i < nbBlockInRow; i++) {
|
|
784
785
|
widths +=
|
|
785
|
-
aWidths[i] +
|
|
786
|
-
aGabaritMarginRights[i] +
|
|
787
|
-
aGabaritMarginLefts[i + 1];
|
|
786
|
+
(aWidths[i] || 0) +
|
|
787
|
+
(aGabaritMarginRights[i] || 0) +
|
|
788
|
+
(aGabaritMarginLefts[i + 1] || 0);
|
|
788
789
|
}
|
|
789
790
|
let RowTotalWidth = widths + blockWidth - (nbBlockInRow > 0 ? gMarginLeft : 0);
|
|
790
791
|
const willWrap = RowTotalWidth >
|
|
@@ -816,8 +817,7 @@ class DataSheetSVG {
|
|
|
816
817
|
blocksHeight = 0;
|
|
817
818
|
}
|
|
818
819
|
else {
|
|
819
|
-
|
|
820
|
-
blocksHeight = currentBlockYTop + blockY;
|
|
820
|
+
blocksHeight = currentBlockYTop;
|
|
821
821
|
}
|
|
822
822
|
let newTplGroup = await this.GenerateProductBlock(tplProductBlock, gabarit.templateGuid, gabarit.guid, jObject, allTags, blocksHeight, nbBlockInRow);
|
|
823
823
|
blockTag = allTags.find((x) => x.IdTag && x.IdTag.toLowerCase() === 'block');
|
|
@@ -834,6 +834,10 @@ class DataSheetSVG {
|
|
|
834
834
|
: 0;
|
|
835
835
|
}
|
|
836
836
|
blockY = this.DataSheet.GetBlockY(allTags);
|
|
837
|
+
const origBlockHeight = blockHeight;
|
|
838
|
+
const heightRes = this.getActualBlockHeight(newTplGroup, blockHeight, blockY);
|
|
839
|
+
blockHeight = heightRes.actualHeight;
|
|
840
|
+
newTplGroup = heightRes.updatedSvg;
|
|
837
841
|
let allBlockHeight = 0;
|
|
838
842
|
heights = 0;
|
|
839
843
|
for (let i = 0; i < nbRow; i++) {
|
|
@@ -857,9 +861,9 @@ class DataSheetSVG {
|
|
|
857
861
|
widths = this.DataSheet.publicationTemplateBackgroundLeftMargin;
|
|
858
862
|
for (let i = 0; i < nbBlockInRow; i++) {
|
|
859
863
|
widths +=
|
|
860
|
-
aWidths[i] +
|
|
861
|
-
aGabaritMarginRights[i] +
|
|
862
|
-
aGabaritMarginLefts[i + 1];
|
|
864
|
+
(aWidths[i] || 0) +
|
|
865
|
+
(aGabaritMarginRights[i] || 0) +
|
|
866
|
+
(aGabaritMarginLefts[i + 1] || 0);
|
|
863
867
|
}
|
|
864
868
|
RowTotalWidth =
|
|
865
869
|
widths +
|
|
@@ -869,8 +873,14 @@ class DataSheetSVG {
|
|
|
869
873
|
const pattern = /<foreignObject id="tableVariant".*?<\/foreignObject>/gs;
|
|
870
874
|
const matches = newTplGroup.match(pattern);
|
|
871
875
|
// Manage the variants tables if they are more than 1 (change of column / page)
|
|
872
|
-
if (
|
|
876
|
+
if (this.debugTable) {
|
|
877
|
+
console.log(`[GEN-DEBUG] Matches check for Item ${currentIdx + 1}: matches=${matches?.length}, splitVariantTable=${jObject.splitVariantTable}, heights=${heights}, blockHeight=${blockHeight}`);
|
|
878
|
+
}
|
|
879
|
+
if (matches &&
|
|
880
|
+
matches.length > 1 &&
|
|
881
|
+
jObject.splitVariantTable !== false) {
|
|
873
882
|
let otherPage = newTplGroup;
|
|
883
|
+
const priorHeights = heights;
|
|
874
884
|
skipPart = true;
|
|
875
885
|
for (let i = 0; i < matches.length; i++) {
|
|
876
886
|
newTplGroup = otherPage;
|
|
@@ -879,6 +889,11 @@ class DataSheetSVG {
|
|
|
879
889
|
newTplGroup = newTplGroup.replace(matches[n], '');
|
|
880
890
|
}
|
|
881
891
|
}
|
|
892
|
+
const matchHeightRes = this.getActualBlockHeight(newTplGroup, origBlockHeight, blockY);
|
|
893
|
+
const matchBlockHeight = matchHeightRes.actualHeight;
|
|
894
|
+
if (this.debugTable) {
|
|
895
|
+
console.log(`[GEN-DEBUG] Item ${currentIdx + 1} match ${i + 1}/${matches.length}: matchBlockHeight=${matchBlockHeight}, origBlockHeight=${origBlockHeight}, priorHeights=${priorHeights}`);
|
|
896
|
+
}
|
|
882
897
|
// Go on a new column
|
|
883
898
|
let newColumn = false;
|
|
884
899
|
if (newColumn) {
|
|
@@ -927,13 +942,12 @@ class DataSheetSVG {
|
|
|
927
942
|
allBlockHeight =
|
|
928
943
|
this.DataSheet.publicationTemplateProductBlockY +
|
|
929
944
|
newRowHeights +
|
|
930
|
-
|
|
945
|
+
matchBlockHeight -
|
|
931
946
|
blockY;
|
|
932
947
|
if ((allBlockHeight <=
|
|
933
948
|
this.DataSheet.publicationTemplateBackgroundFooterY ||
|
|
934
949
|
(nbRow === 0 && aHeightsRows.length === 0)) &&
|
|
935
|
-
allBlockHeight != 0
|
|
936
|
-
i == 0) {
|
|
950
|
+
allBlockHeight != 0) {
|
|
937
951
|
const diffY = newRowHeights - heights;
|
|
938
952
|
heights = newRowHeights;
|
|
939
953
|
newTplGroup = this.ChangeAllIdsGroup(newTplGroup, nbBlock);
|
|
@@ -949,7 +963,7 @@ class DataSheetSVG {
|
|
|
949
963
|
aGabaritMarginRights = [];
|
|
950
964
|
aGabaritMarginRights.push(gMarginRight);
|
|
951
965
|
nbRow++;
|
|
952
|
-
aHeightsRows.push(
|
|
966
|
+
aHeightsRows.push(Math.max(origBlockHeight, matchBlockHeight));
|
|
953
967
|
aRowMarginTops.push(gMarginTop);
|
|
954
968
|
aRowMarginBottoms.push(gMarginBottom);
|
|
955
969
|
}
|
|
@@ -978,7 +992,7 @@ class DataSheetSVG {
|
|
|
978
992
|
};
|
|
979
993
|
fileList.push(json);
|
|
980
994
|
newTplGroup = this.ChangeAllX(newTplGroup, nbBlockInRow, this.DataSheet.publicationTemplateBackgroundLeftMargin);
|
|
981
|
-
newTplGroup = this.ChangeAllYBis(newTplGroup, -
|
|
995
|
+
newTplGroup = this.ChangeAllYBis(newTplGroup, -priorHeights);
|
|
982
996
|
AllTplProductsBlock = '';
|
|
983
997
|
newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
|
|
984
998
|
tplRowProductsBlocks = newTplGroup;
|
|
@@ -989,7 +1003,7 @@ class DataSheetSVG {
|
|
|
989
1003
|
aGabaritMarginRights = [];
|
|
990
1004
|
aGabaritMarginRights.push(gMarginRight);
|
|
991
1005
|
aHeightsRows = [];
|
|
992
|
-
aHeightsRows.push(
|
|
1006
|
+
aHeightsRows.push(Math.max(origBlockHeight, matchBlockHeight));
|
|
993
1007
|
aRowMarginTops = [];
|
|
994
1008
|
aRowMarginTops.push(gMarginTop);
|
|
995
1009
|
aRowMarginBottoms = [];
|
|
@@ -998,6 +1012,7 @@ class DataSheetSVG {
|
|
|
998
1012
|
nbRow = 0;
|
|
999
1013
|
nbBlock = 0;
|
|
1000
1014
|
nbBlockInRow = 0;
|
|
1015
|
+
heights = 0;
|
|
1001
1016
|
widths =
|
|
1002
1017
|
this.DataSheet.publicationTemplateBackgroundLeftMargin +
|
|
1003
1018
|
blockWidth;
|
|
@@ -1025,7 +1040,7 @@ class DataSheetSVG {
|
|
|
1025
1040
|
tplRowProductsBlocks += newTplGroup;
|
|
1026
1041
|
if (aHeightsRows.length == 0) {
|
|
1027
1042
|
const rowInfo = getRowInfo(currentIdx);
|
|
1028
|
-
currentRowMaxHeight = rowInfo.maxHeight;
|
|
1043
|
+
currentRowMaxHeight = Math.max(rowInfo.maxHeight, blockHeight);
|
|
1029
1044
|
currentRowMaxMarginTop = rowInfo.maxMarginTop;
|
|
1030
1045
|
currentRowMaxMarginBottom = rowInfo.maxMarginBottom;
|
|
1031
1046
|
aHeightsRows.push(currentRowMaxHeight);
|
|
@@ -1047,7 +1062,7 @@ class DataSheetSVG {
|
|
|
1047
1062
|
}
|
|
1048
1063
|
else if (RowTotalWidth != 0) {
|
|
1049
1064
|
const rowInfo = getRowInfo(currentIdx);
|
|
1050
|
-
const currentRowMaxHeight = rowInfo.maxHeight;
|
|
1065
|
+
const currentRowMaxHeight = Math.max(rowInfo.maxHeight, blockHeight);
|
|
1051
1066
|
const currentRowMaxMarginTop = rowInfo.maxMarginTop;
|
|
1052
1067
|
const currentRowMaxMarginBottom = rowInfo.maxMarginBottom;
|
|
1053
1068
|
const newRowHeights = heights +
|
|
@@ -1082,8 +1097,7 @@ class DataSheetSVG {
|
|
|
1082
1097
|
aHeightsRows.push(currentRowMaxHeight);
|
|
1083
1098
|
aRowMarginTops.push(currentRowMaxMarginTop);
|
|
1084
1099
|
aRowMarginBottoms.push(currentRowMaxMarginBottom);
|
|
1085
|
-
nbBlockInRow =
|
|
1086
|
-
nbBlock++;
|
|
1100
|
+
nbBlockInRow = 1;
|
|
1087
1101
|
}
|
|
1088
1102
|
// Go on a new page (418)
|
|
1089
1103
|
else if (allBlockHeight != 0) {
|
|
@@ -1129,10 +1143,9 @@ class DataSheetSVG {
|
|
|
1129
1143
|
count++;
|
|
1130
1144
|
nbRow = 0;
|
|
1131
1145
|
nbBlock = 0;
|
|
1132
|
-
nbBlockInRow =
|
|
1146
|
+
nbBlockInRow = 1;
|
|
1147
|
+
heights = 0;
|
|
1133
1148
|
}
|
|
1134
|
-
nbBlockInRow = 0;
|
|
1135
|
-
nbBlock++;
|
|
1136
1149
|
}
|
|
1137
1150
|
else {
|
|
1138
1151
|
console.log('[ERROR] RowTotalWidth is 0, this should not happen.');
|
|
@@ -1600,6 +1613,11 @@ class DataSheetSVG {
|
|
|
1600
1613
|
}
|
|
1601
1614
|
}
|
|
1602
1615
|
ChangeAllYBis(tplGroup, blockHeight) {
|
|
1616
|
+
if (typeof blockHeight !== 'number' ||
|
|
1617
|
+
isNaN(blockHeight) ||
|
|
1618
|
+
blockHeight === 0) {
|
|
1619
|
+
return tplGroup;
|
|
1620
|
+
}
|
|
1603
1621
|
const patternTag = /<[\w\W]+?.>/g;
|
|
1604
1622
|
const patternHeight = /height\s*=\s*"([^"]*)"/;
|
|
1605
1623
|
const patternY = /(?<![a-zA-Z])y\s*=\s*"-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?"/g;
|
|
@@ -2650,8 +2668,9 @@ class DataSheetSVG {
|
|
|
2650
2668
|
skus = jRowSku['skus'] && jRowSku['skus'][0] ? jRowSku['skus'][0] : [];
|
|
2651
2669
|
let currentRow = '';
|
|
2652
2670
|
let currentRowWithoutStyle = '';
|
|
2653
|
-
let startWithNewPage = jRowSku['splitVariantTable'] ===
|
|
2671
|
+
let startWithNewPage = jRowSku['splitVariantTable'] === false ? true : false;
|
|
2654
2672
|
let startY = 0;
|
|
2673
|
+
let accumulatedTableHeight = 0;
|
|
2655
2674
|
let allRows = [];
|
|
2656
2675
|
let allRowsWithoutStyle = [];
|
|
2657
2676
|
// Préparer les cellules pour pouvoir supprimer les colonnes non voulus si besoin
|
|
@@ -2754,32 +2773,18 @@ class DataSheetSVG {
|
|
|
2754
2773
|
}
|
|
2755
2774
|
if (iSku === 0) {
|
|
2756
2775
|
if (!startWithNewPage) {
|
|
2757
|
-
|
|
2758
|
-
this.DataSheet.publicationTemplateBackgroundLeftMargin +
|
|
2759
|
-
this.DataSheet.publicationTemplateBackgroundRightMargin;
|
|
2760
|
-
if (currentWidthLine + blockWidth >
|
|
2761
|
-
this.DataSheet.backgroundWidth) {
|
|
2762
|
-
if (allBlocksHeight == 0) {
|
|
2763
|
-
allBlocksHeight =
|
|
2764
|
-
this.DataSheet.publicationTemplateBackgroundHeightHeader;
|
|
2765
|
-
}
|
|
2766
|
-
startY = allBlocksHeight + this.DataSheet.lastGabaritHeight;
|
|
2767
|
-
}
|
|
2768
|
-
else {
|
|
2769
|
-
startY = allBlocksHeight;
|
|
2770
|
-
}
|
|
2771
|
-
if (startY + newHeight >
|
|
2772
|
-
this.DataSheet.publicationTemplateBackgroundFooterY) {
|
|
2773
|
-
startY = this.DataSheet.publicationTemplateBackgroundHeightHeader;
|
|
2774
|
-
}
|
|
2776
|
+
startY = allBlocksHeight;
|
|
2775
2777
|
}
|
|
2776
2778
|
else {
|
|
2777
2779
|
startY = this.DataSheet.publicationTemplateBackgroundHeightHeader;
|
|
2778
2780
|
}
|
|
2779
2781
|
}
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
|
|
2782
|
+
const currentTableYPos = parseFloat(tag.RectPosition['y']) || 0;
|
|
2783
|
+
const totalBottomPos = startY + currentTableYPos + newHeight;
|
|
2784
|
+
const isOverflow = totalBottomPos > this.DataSheet.publicationTemplateBackgroundFooterY;
|
|
2785
|
+
if (this.debugTable) {
|
|
2786
|
+
console.log(`[TABLE-SPLIT-LOG] SKU ${iSku + 1}/${skus.length} (${sku.code || sku.skuCode || 'sku'}): startY=${startY}, tableY=${currentTableYPos}, newHeight=${newHeight}, totalBottom=${totalBottomPos}, FooterY=${this.DataSheet.publicationTemplateBackgroundFooterY}, overflow=${isOverflow}, nbTables=${nbTables}`);
|
|
2787
|
+
}
|
|
2783
2788
|
if (skus[skus.length - 1] === sku && skus.length === 1) {
|
|
2784
2789
|
tables[nbTables] =
|
|
2785
2790
|
newTag +
|
|
@@ -2797,15 +2802,8 @@ class DataSheetSVG {
|
|
|
2797
2802
|
currentRow +
|
|
2798
2803
|
'</tbody></table></foreignObject>';
|
|
2799
2804
|
}
|
|
2800
|
-
else if ((tag.RectPosition['y']
|
|
2801
|
-
this.DataSheet.publicationTemplateBackgroundFooterY
|
|
2802
|
-
nbTables < maxBlockInRow - nbBlockInRow) ||
|
|
2803
|
-
tag.RectPosition['y'] + newHeight + startY >
|
|
2804
|
-
this.DataSheet.publicationTemplateBackgroundFooterY ||
|
|
2805
|
-
(tag.RectPosition['y'] + newHeight + startY >
|
|
2806
|
-
this.DataSheet.publicationTemplateBackgroundFooterY &&
|
|
2807
|
-
maxBlockInRow === 1 &&
|
|
2808
|
-
nbTables === 0)) {
|
|
2805
|
+
else if (startY + (parseFloat(tag.RectPosition['y']) || 0) + newHeight >
|
|
2806
|
+
this.DataSheet.publicationTemplateBackgroundFooterY) {
|
|
2809
2807
|
htmlContent = htmlContent.replace(currentRowWithoutStyle, '');
|
|
2810
2808
|
const parser = new DOMParser();
|
|
2811
2809
|
const doc = parser.parseFromString(htmlContent, 'text/html');
|
|
@@ -2840,6 +2838,7 @@ class DataSheetSVG {
|
|
|
2840
2838
|
tables[nbTables] +
|
|
2841
2839
|
'</tbody></table></foreignObject>';
|
|
2842
2840
|
nbTables++;
|
|
2841
|
+
accumulatedTableHeight += newHeight;
|
|
2843
2842
|
tableWithoutStyle = currentRowWithoutStyle;
|
|
2844
2843
|
tables.push(currentRow);
|
|
2845
2844
|
}
|
|
@@ -2890,6 +2889,7 @@ class DataSheetSVG {
|
|
|
2890
2889
|
}
|
|
2891
2890
|
}
|
|
2892
2891
|
else if (skus[skus.length - 1] === sku) {
|
|
2892
|
+
const currentTableY = parseFloat(tag.RectPosition['y']);
|
|
2893
2893
|
tables[nbTables] =
|
|
2894
2894
|
newTag +
|
|
2895
2895
|
' width="' +
|
|
@@ -2899,7 +2899,7 @@ class DataSheetSVG {
|
|
|
2899
2899
|
'" x="' +
|
|
2900
2900
|
tag.RectPosition['x'] +
|
|
2901
2901
|
'" y="' +
|
|
2902
|
-
|
|
2902
|
+
currentTableY +
|
|
2903
2903
|
'">' +
|
|
2904
2904
|
newVal +
|
|
2905
2905
|
tables[nbTables] +
|
|
@@ -3478,7 +3478,6 @@ class DataSheetSVG {
|
|
|
3478
3478
|
const matchedKey = Object.keys(foundObj).find((k) => (field && k.toUpperCase() === field.toUpperCase()) ||
|
|
3479
3479
|
(idVal && k.toUpperCase() === idVal.toUpperCase()));
|
|
3480
3480
|
newVal = matchedKey ? foundObj[matchedKey] : '';
|
|
3481
|
-
console.log(newVal);
|
|
3482
3481
|
let valuePairs = new Map();
|
|
3483
3482
|
let i = 0;
|
|
3484
3483
|
if (newVal != null) {
|
|
@@ -4721,7 +4720,29 @@ class DataSheetSVG {
|
|
|
4721
4720
|
const size = this.optimizeProductTable(tag.XmlTag, tpl);
|
|
4722
4721
|
tag.XmlTag.style.setProperty('overflow', 'visible', 'important');
|
|
4723
4722
|
if (size.height) {
|
|
4723
|
+
const oldHeight = parseFloat(tag.XmlTag.getAttribute('height')) || 0;
|
|
4724
4724
|
tag.XmlTag.setAttribute('height', String(size.height));
|
|
4725
|
+
const newHeight = size.height;
|
|
4726
|
+
if (newHeight > oldHeight && oldHeight > 0) {
|
|
4727
|
+
const deltaY = newHeight - oldHeight;
|
|
4728
|
+
const tableY = parseFloat(tag.XmlTag.getAttribute('y')) || 0;
|
|
4729
|
+
const tableBottom = tableY + oldHeight;
|
|
4730
|
+
allTags.forEach((otherTag) => {
|
|
4731
|
+
if (otherTag !== tag && otherTag.XmlTag) {
|
|
4732
|
+
if (otherTag.XmlTag.hasAttribute('data-anchor-target')) {
|
|
4733
|
+
return;
|
|
4734
|
+
}
|
|
4735
|
+
const otherY = parseFloat(otherTag.XmlTag.getAttribute('y')) || 0;
|
|
4736
|
+
if (otherY > tableY + 10) {
|
|
4737
|
+
const newOtherY = otherY + deltaY;
|
|
4738
|
+
otherTag.XmlTag.setAttribute('y', String(newOtherY));
|
|
4739
|
+
if (otherTag.RectPosition) {
|
|
4740
|
+
otherTag.RectPosition.y = newOtherY;
|
|
4741
|
+
}
|
|
4742
|
+
}
|
|
4743
|
+
}
|
|
4744
|
+
});
|
|
4745
|
+
}
|
|
4725
4746
|
}
|
|
4726
4747
|
if (size.width) {
|
|
4727
4748
|
tag.XmlTag.setAttribute('width', String(size.width));
|
|
@@ -5809,6 +5830,79 @@ class DataSheetSVG {
|
|
|
5809
5830
|
reader.readAsDataURL(blob);
|
|
5810
5831
|
});
|
|
5811
5832
|
}
|
|
5833
|
+
getActualBlockHeight(svgContent, initialBlockHeight, blockY = 0) {
|
|
5834
|
+
if (!svgContent)
|
|
5835
|
+
return { actualHeight: initialBlockHeight, updatedSvg: svgContent };
|
|
5836
|
+
let maxBottom = 0;
|
|
5837
|
+
try {
|
|
5838
|
+
// 1. Measure foreignObjects (tables, textareas, etc.)
|
|
5839
|
+
const foRegex = /<foreignObject[\s\S]*?>/gi;
|
|
5840
|
+
let match;
|
|
5841
|
+
while ((match = foRegex.exec(svgContent)) !== null) {
|
|
5842
|
+
const foTag = match[0];
|
|
5843
|
+
const yMatch = foTag.match(/\by=["']([^"']+)["']/i);
|
|
5844
|
+
const heightMatch = foTag.match(/\bheight=["']([^"']+)["']/i);
|
|
5845
|
+
const foY = yMatch ? parseFloat(yMatch[1]) : 0;
|
|
5846
|
+
const foHeight = heightMatch ? parseFloat(heightMatch[1]) : 0;
|
|
5847
|
+
if (!isNaN(foHeight) && foHeight > 0) {
|
|
5848
|
+
const foBottom = (isNaN(foY) ? 0 : foY) + foHeight;
|
|
5849
|
+
if (foBottom > maxBottom) {
|
|
5850
|
+
maxBottom = foBottom;
|
|
5851
|
+
}
|
|
5852
|
+
}
|
|
5853
|
+
}
|
|
5854
|
+
// 2. Measure images, text, path, rects (excluding background block rect)
|
|
5855
|
+
const elemRegex = /<(rect|image|text|path|ellipse|circle)[\s\S]*?>/gi;
|
|
5856
|
+
while ((match = elemRegex.exec(svgContent)) !== null) {
|
|
5857
|
+
const tagStr = match[0];
|
|
5858
|
+
const idMatch = tagStr.match(/\bid=["']([^"']+)["']/i);
|
|
5859
|
+
if (idMatch && idMatch[1].toLowerCase().includes('block')) {
|
|
5860
|
+
continue;
|
|
5861
|
+
}
|
|
5862
|
+
const yMatch = tagStr.match(/\b(y|cy)=["']([^"']+)["']/i);
|
|
5863
|
+
const heightMatch = tagStr.match(/\b(height|r|ry)=["']([^"']+)["']/i);
|
|
5864
|
+
const eY = yMatch ? parseFloat(yMatch[2]) : 0;
|
|
5865
|
+
const eH = heightMatch ? parseFloat(heightMatch[2]) : 0;
|
|
5866
|
+
if (!isNaN(eH) && eH > 0) {
|
|
5867
|
+
const eBottom = (isNaN(eY) ? 0 : eY) + eH;
|
|
5868
|
+
if (eBottom > maxBottom) {
|
|
5869
|
+
maxBottom = eBottom;
|
|
5870
|
+
}
|
|
5871
|
+
}
|
|
5872
|
+
else if (!isNaN(eY) && eY > 0) {
|
|
5873
|
+
const eBottom = eY + 20;
|
|
5874
|
+
if (eBottom > maxBottom) {
|
|
5875
|
+
maxBottom = eBottom;
|
|
5876
|
+
}
|
|
5877
|
+
}
|
|
5878
|
+
}
|
|
5879
|
+
}
|
|
5880
|
+
catch (e) {
|
|
5881
|
+
console.error('Error calculating actual block height:', e);
|
|
5882
|
+
}
|
|
5883
|
+
let calculatedHeight = initialBlockHeight;
|
|
5884
|
+
if (maxBottom > 0) {
|
|
5885
|
+
calculatedHeight = Math.ceil(maxBottom - blockY);
|
|
5886
|
+
}
|
|
5887
|
+
// Update background block rect height in svgContent if present
|
|
5888
|
+
let updatedSvg = svgContent;
|
|
5889
|
+
try {
|
|
5890
|
+
const blockRectRegex = /(<rect[^>]*?\bid=["']block["'][^>]*?\bheight=["'])([^"']+)(["'])/i;
|
|
5891
|
+
if (blockRectRegex.test(updatedSvg)) {
|
|
5892
|
+
updatedSvg = updatedSvg.replace(blockRectRegex, `$1${calculatedHeight}$3`);
|
|
5893
|
+
}
|
|
5894
|
+
else {
|
|
5895
|
+
const blockRectAlt = /(<rect[^>]*?\bheight=["'])([^"']+)(["'][^>]*?\bid=["']block["'])/i;
|
|
5896
|
+
if (blockRectAlt.test(updatedSvg)) {
|
|
5897
|
+
updatedSvg = updatedSvg.replace(blockRectAlt, `$1${calculatedHeight}$3`);
|
|
5898
|
+
}
|
|
5899
|
+
}
|
|
5900
|
+
}
|
|
5901
|
+
catch (e) {
|
|
5902
|
+
console.error('Error updating block rect height in SVG:', e);
|
|
5903
|
+
}
|
|
5904
|
+
return { actualHeight: calculatedHeight, updatedSvg };
|
|
5905
|
+
}
|
|
5812
5906
|
// DVG TAG
|
|
5813
5907
|
ChangeBlockHeight(svgContents, newHeight, oldHeight, allTags, currentTag) {
|
|
5814
5908
|
let updateHeight = false;
|