@solidpepper/solidpepper-solidgeneration 0.2.6 → 0.2.8

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.
@@ -92,6 +92,7 @@ class DataSheet {
92
92
  this.variantTables = [];
93
93
  this.variantTableFirstHeight = 0;
94
94
  this.variantTableLastHeight = 0;
95
+ this.overflowBehavior = 'none';
95
96
  // Provisoire
96
97
  this.backgroundWidth = 0;
97
98
  this.backgroundHeight = 0;
@@ -125,11 +126,11 @@ class DataSheet {
125
126
  line-height: 120%;
126
127
  overflow: hidden;
127
128
  text-align: left;
128
- padding: 5px;
129
+ padding: var(--vertical-padding, 5px) var(--horizontal-padding, 5px);
129
130
  border-width: 0.8px;
130
131
  border-color: rgb(0, 0, 0);
131
132
  border-style: solid;
132
- font-family: "serif";
133
+ font-family: sans-serif;
133
134
  font-size: 16px;
134
135
  color: rgb(0, 0, 0);
135
136
  font-style: normal;
@@ -138,9 +139,9 @@ class DataSheet {
138
139
  background-color: rgba(0, 0, 0, 0);
139
140
  min-height: inherit;
140
141
  }
141
- foreignObject td div.wrap { display: flex;text-align: inherit;justify-content: inherit;min-height: inherit;align-items: inherit;font-family: inherit !important; }
142
- foreignObject .cellContent div {width: max-content;}
143
- foreignObject .cellContent {display: flex; align-items: inherit; justify-content: inherit; width: 100%; height: auto;flex-direction: column;}
142
+ foreignObject td div.wrap, foreignObject th div.wrap { display: flex; flex-direction: column; text-align: inherit; justify-content: inherit; min-height: inherit; align-items: inherit; font-family: inherit !important; width: 100%; }
143
+ foreignObject .cellContent div, foreignObject td div.wrap > div, foreignObject th div.wrap > div { width: 100%; min-height: 1em; }
144
+ foreignObject .cellContent { display: flex; align-items: inherit; justify-content: inherit; width: 100%; height: auto; flex-direction: column; }
144
145
  foreignObject [locked='true'].fake-textarea > * {
145
146
  max-width: 100%;
146
147
  }
@@ -340,6 +341,7 @@ class DataSheet {
340
341
  this.publicationTemplateBackgroundLeftMargin = 0;
341
342
  this.publicationTemplateBackgroundFooterY = 0;
342
343
  this.publicationTemplateBackgroundMarginX = 0;
344
+ this.overflowBehavior = 'none';
343
345
  this.pricesListCurrency = '';
344
346
  this.gabarits.length = 0;
345
347
  this.defaultGabaritGuid = null;
@@ -498,12 +500,140 @@ class DataSheetSVG {
498
500
  dsSingleton.token = token;
499
501
  dsSingleton.loadAttributes();
500
502
  }
503
+ parseBackgroundSvgDimensions(backgroundSvg) {
504
+ if (!backgroundSvg)
505
+ return;
506
+ try {
507
+ const allElements = this.GetAllTags(backgroundSvg);
508
+ allElements?.forEach((element) => {
509
+ const tagName = element.tagName?.toLowerCase();
510
+ if (tagName === 'svg') {
511
+ const heightAttr = element.getAttribute('height') ||
512
+ element.getAttribute('data-height');
513
+ if (heightAttr) {
514
+ const parsedH = parseFloat(heightAttr);
515
+ if (!isNaN(parsedH) && parsedH > 0) {
516
+ this.DataSheet.publicationTemplateHeight = parsedH;
517
+ }
518
+ }
519
+ const widthAttr = element.getAttribute('width') ||
520
+ element.getAttribute('data-width');
521
+ if (widthAttr) {
522
+ const parsedW = parseFloat(widthAttr);
523
+ if (!isNaN(parsedW) && parsedW > 0) {
524
+ this.DataSheet.publicationTemplateWidth = parsedW;
525
+ }
526
+ }
527
+ const viewBox = element.getAttribute('viewBox');
528
+ if (viewBox) {
529
+ const vbParts = viewBox.trim().split(/[\s,]+/);
530
+ if (vbParts.length === 4) {
531
+ const vbW = parseFloat(vbParts[2]);
532
+ const vbH = parseFloat(vbParts[3]);
533
+ if ((!this.DataSheet.publicationTemplateWidth ||
534
+ this.DataSheet.publicationTemplateWidth === 0) &&
535
+ !isNaN(vbW) &&
536
+ vbW > 0) {
537
+ this.DataSheet.publicationTemplateWidth = vbW;
538
+ }
539
+ if ((!this.DataSheet.publicationTemplateHeight ||
540
+ this.DataSheet.publicationTemplateHeight === 0) &&
541
+ !isNaN(vbH) &&
542
+ vbH > 0) {
543
+ this.DataSheet.publicationTemplateHeight = vbH;
544
+ }
545
+ }
546
+ }
547
+ // HEADER HEIGHT
548
+ const attrHeader = element.getAttribute('data-margin-top') ||
549
+ element.getAttribute('data-header-height') ||
550
+ element.getAttribute('data-margin-vertical');
551
+ const parsedHeader = parseFloat(attrHeader);
552
+ if (!isNaN(parsedHeader)) {
553
+ this.DataSheet.publicationTemplateBackgroundHeightHeader =
554
+ parsedHeader;
555
+ }
556
+ else if (!this.DataSheet.publicationTemplateBackgroundHeightHeader) {
557
+ this.DataSheet.publicationTemplateBackgroundHeightHeader = 0;
558
+ }
559
+ // FOOTER HEIGHT
560
+ const attrFooter = element.getAttribute('data-margin-bottom') ||
561
+ element.getAttribute('data-footer-height') ||
562
+ element.getAttribute('data-margin-vertical');
563
+ const parsedFooter = parseFloat(attrFooter);
564
+ if (!isNaN(parsedFooter)) {
565
+ this.DataSheet.publicationTemplateBackgroundHeightFooter =
566
+ parsedFooter;
567
+ this.DataSheet.publicationTemplateBackgroundFooterY =
568
+ (this.DataSheet.publicationTemplateHeight || 1122) - parsedFooter;
569
+ }
570
+ else {
571
+ this.DataSheet.publicationTemplateBackgroundHeightFooter =
572
+ this.DataSheet.publicationTemplateBackgroundHeightFooter || 0;
573
+ this.DataSheet.publicationTemplateBackgroundFooterY =
574
+ (this.DataSheet.publicationTemplateHeight || 1122) -
575
+ this.DataSheet.publicationTemplateBackgroundHeightFooter;
576
+ }
577
+ // MARGIN
578
+ const attrMarginLeft = element.getAttribute('data-margin-left') ||
579
+ element.getAttribute('data-margin-horizontal');
580
+ const attrMarginRight = element.getAttribute('data-margin-right') ||
581
+ element.getAttribute('data-margin-horizontal');
582
+ const parsedMarginLeft = parseFloat(attrMarginLeft);
583
+ if (!isNaN(parsedMarginLeft)) {
584
+ this.DataSheet.publicationTemplateBackgroundLeftMargin =
585
+ parsedMarginLeft;
586
+ }
587
+ else if (!this.DataSheet.publicationTemplateBackgroundLeftMargin) {
588
+ this.DataSheet.publicationTemplateBackgroundLeftMargin = 0;
589
+ }
590
+ const parsedMarginRight = parseFloat(attrMarginRight);
591
+ if (!isNaN(parsedMarginRight)) {
592
+ this.DataSheet.publicationTemplateBackgroundRightMargin =
593
+ parsedMarginRight;
594
+ this.DataSheet.publicationTemplateBackgroundMarginX =
595
+ (this.DataSheet.publicationTemplateWidth || 793) - parsedMarginRight;
596
+ }
597
+ else if (!this.DataSheet.publicationTemplateBackgroundRightMargin) {
598
+ this.DataSheet.publicationTemplateBackgroundRightMargin = 0;
599
+ this.DataSheet.publicationTemplateBackgroundMarginX =
600
+ this.DataSheet.publicationTemplateWidth || 793;
601
+ }
602
+ }
603
+ // STYLE
604
+ else if (tagName === 'style') {
605
+ const styleContent = element.textContent;
606
+ const importMatch = styleContent.match(/@import\s+url\("https:\/\/fonts\.googleapis\.com.*?"\);/);
607
+ if (importMatch &&
608
+ !this.DataSheet.DictImportFontFamily.push(importMatch[0])) {
609
+ this.DataSheet.importFontFamily += importMatch[0] + ' ';
610
+ this.DataSheet.DictImportFontFamily.push(importMatch[0]);
611
+ }
612
+ const fontFaceMatches = styleContent.match(/@font-face\s*\{[^}]+\}/g);
613
+ if (fontFaceMatches) {
614
+ fontFaceMatches.forEach((block) => {
615
+ if (!this.DataSheet.DictImportFontFamily.push(block)) {
616
+ this.DataSheet.importFontFamily += block + '\n';
617
+ this.DataSheet.DictImportFontFamily.push(block);
618
+ }
619
+ });
620
+ }
621
+ }
622
+ });
623
+ }
624
+ catch (e) {
625
+ console.warn('[SOLIDGENERATION] Error parsing background dimensions:', e);
626
+ }
627
+ }
501
628
  async GenerateSvgFiles(lstSkus, backgroundTplLeft, backgroundTplRight, sectionId = '', fast = false) {
502
629
  let AllTplProductsBlock = '';
503
630
  let tplProductBlock = '';
504
631
  let tplRowProductsBlocks = '';
505
632
  let pathNewSvgFile = '';
506
633
  try {
634
+ if (backgroundTplLeft || backgroundTplRight) {
635
+ this.parseBackgroundSvgDimensions(backgroundTplLeft || backgroundTplRight);
636
+ }
507
637
  if (sectionId == '' || sectionId == null) {
508
638
  pathNewSvgFile = 'temp[';
509
639
  }
@@ -537,7 +667,7 @@ class DataSheetSVG {
537
667
  }
538
668
  }
539
669
  let initDoc = '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' +
540
- '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="' +
670
+ '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" data-sp-version="1.105" viewBox="' +
541
671
  vbx +
542
672
  ' ' +
543
673
  vby +
@@ -940,8 +1070,11 @@ class DataSheetSVG {
940
1070
  widths +
941
1071
  aWidths[nbBlockInRow] -
942
1072
  (nbBlockInRow > 0 ? gMarginLeft : 0);
1073
+ newTplGroup = newTplGroup
1074
+ .replace(/<foreignobject/gi, '<foreignObject')
1075
+ .replace(/<\/foreignobject>/gi, '</foreignObject>');
943
1076
  // Check how many table variants are presents in the product block
944
- const pattern = /<foreignObject id="tableVariant".*?<\/foreignObject>/gs;
1077
+ const pattern = /<foreignObject[^>]*id=["']tableVariant["'][^>]*>[\s\S]*?<\/foreignObject>/gi;
945
1078
  const matches = newTplGroup.match(pattern);
946
1079
  // Manage the variants tables if they are more than 1 (change of column / page)
947
1080
  if (this.debugTable) {
@@ -949,15 +1082,23 @@ class DataSheetSVG {
949
1082
  }
950
1083
  if (matches &&
951
1084
  matches.length > 1 &&
952
- jObject.splitVariantTable !== false) {
1085
+ (jObject.splitVariantTable !== false ||
1086
+ matches.some((m) => m.includes('data-split-continuation="true"')))) {
953
1087
  let otherPage = newTplGroup;
954
1088
  const priorHeights = heights;
955
1089
  skipPart = true;
956
1090
  for (let i = 0; i < matches.length; i++) {
957
1091
  newTplGroup = otherPage;
958
- for (let n = 0; n < matches.length; n++) {
959
- if (n !== i) {
960
- newTplGroup = newTplGroup.replace(matches[n], '');
1092
+ if (i > 0 &&
1093
+ matches[i].includes('data-split-continuation="true"')) {
1094
+ const continuationTable = matches[i].replace(/(?<![a-zA-Z])y\s*=\s*"-?\d+(?:\.\d+)?"/g, `y="${headerShift}"`);
1095
+ newTplGroup = `<g>${continuationTable}</g>`;
1096
+ }
1097
+ else {
1098
+ for (let n = 0; n < matches.length; n++) {
1099
+ if (n !== i) {
1100
+ newTplGroup = newTplGroup.replace(matches[n], '');
1101
+ }
961
1102
  }
962
1103
  }
963
1104
  const matchHeightRes = this.getActualBlockHeight(newTplGroup, origBlockHeight, blockY);
@@ -1015,9 +1156,10 @@ class DataSheetSVG {
1015
1156
  newRowHeights +
1016
1157
  matchBlockHeight -
1017
1158
  blockY;
1018
- if ((allBlockHeight <=
1019
- this.DataSheet.publicationTemplateBackgroundFooterY ||
1020
- (nbRow === 0 && aHeightsRows.length === 0)) &&
1159
+ if (i === 0 &&
1160
+ (allBlockHeight <=
1161
+ this.DataSheet.publicationTemplateBackgroundFooterY ||
1162
+ (nbRow === 0 && aHeightsRows.length === 0)) &&
1021
1163
  allBlockHeight != 0) {
1022
1164
  const diffY = newRowHeights - heights;
1023
1165
  heights = newRowHeights;
@@ -1063,7 +1205,9 @@ class DataSheetSVG {
1063
1205
  };
1064
1206
  fileList.push(json);
1065
1207
  newTplGroup = this.ChangeAllX(newTplGroup, nbBlockInRow, this.DataSheet.publicationTemplateBackgroundLeftMargin);
1066
- newTplGroup = this.ChangeAllYBis(newTplGroup, -priorHeights);
1208
+ if (!matches[i].includes('data-split-continuation="true"')) {
1209
+ newTplGroup = this.ChangeAllYBis(newTplGroup, -priorHeights);
1210
+ }
1067
1211
  AllTplProductsBlock = '';
1068
1212
  newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
1069
1213
  tplRowProductsBlocks = newTplGroup;
@@ -1074,7 +1218,9 @@ class DataSheetSVG {
1074
1218
  aGabaritMarginRights = [];
1075
1219
  aGabaritMarginRights.push(gMarginRight);
1076
1220
  aHeightsRows = [];
1077
- aHeightsRows.push(Math.max(origBlockHeight, matchBlockHeight));
1221
+ aHeightsRows.push(i > 0
1222
+ ? matchBlockHeight
1223
+ : Math.max(origBlockHeight, matchBlockHeight));
1078
1224
  aRowMarginTops = [];
1079
1225
  aRowMarginTops.push(gMarginTop);
1080
1226
  aRowMarginBottoms = [];
@@ -1530,6 +1676,17 @@ class DataSheetSVG {
1530
1676
  for (const missingFilter of uniqueMissingFilters) {
1531
1677
  tempSvg = tempSvg.split(missingFilter).join('');
1532
1678
  }
1679
+ const now = new Date();
1680
+ const day = String(now.getDate()).padStart(2, '0');
1681
+ const month = String(now.getMonth() + 1).padStart(2, '0');
1682
+ const year = now.getFullYear();
1683
+ const hours = String(now.getHours()).padStart(2, '0');
1684
+ const minutes = String(now.getMinutes()).padStart(2, '0');
1685
+ const dateStr = `${day}/${month}/${year}`;
1686
+ const dateCompleteStr = `${day}/${month}/${year} ${hours}:${minutes}`;
1687
+ tempSvg = tempSvg
1688
+ .replace(/\{\{(DateGeneration|Date_Generation|dateGeneration|date_generation)\}\}/gi, dateStr)
1689
+ .replace(/\{\{(DateCompleteGeneration|Date_Complete_Generation|dateCompleteGeneration|date_complete_generation)\}\}/gi, dateCompleteStr);
1533
1690
  return tempSvg;
1534
1691
  }
1535
1692
  RemoveUnwantedSVGTagsOld(svgContent) {
@@ -2262,13 +2419,23 @@ class DataSheetSVG {
2262
2419
  ProductTable: false,
2263
2420
  Barcode: false,
2264
2421
  QRCode: false,
2422
+ overflowBehavior: 'none',
2265
2423
  };
2266
2424
  // element est un objet du domparser, verifier que c'est le cas
2267
2425
  if (element == null) {
2268
2426
  return tag;
2269
2427
  }
2270
2428
  tag.XmlTag = element;
2271
- tag.IdTag = element.getAttribute('id');
2429
+ let elemId = element.getAttribute('id');
2430
+ if (!elemId) {
2431
+ elemId =
2432
+ element.getAttribute('data-id') ||
2433
+ (element.getAttribute('data-type')
2434
+ ? `${element.getAttribute('data-type')}-${Math.random().toString(36).substr(2, 7)}`
2435
+ : `tag-${Math.random().toString(36).substr(2, 7)}`);
2436
+ element.setAttribute('id', elemId);
2437
+ }
2438
+ tag.IdTag = elemId;
2272
2439
  const [yVal, xVal] = this.GetXY(tag.XmlTag);
2273
2440
  tag.YTotal = this.safeParseFloat(yVal);
2274
2441
  tag.X = this.safeParseFloat(xVal);
@@ -2334,6 +2501,11 @@ class DataSheetSVG {
2334
2501
  : table.getAttribute('data-remove-empty-cells') === 'false'
2335
2502
  ? false
2336
2503
  : this.DataSheet.publicationTemplateSettingVariants?.['hideEmptyCells'] === true;
2504
+ this.DataSheet.overflowBehavior =
2505
+ table.getAttribute('data-overflow-behavior') ||
2506
+ this.DataSheet.publicationTemplateSettingVariants?.['overflowBehavior'] ||
2507
+ 'none';
2508
+ tag.overflowBehavior = this.DataSheet.overflowBehavior;
2337
2509
  // Récup la première ligne du tableau
2338
2510
  const firstRow = table.querySelector('tr');
2339
2511
  if (firstRow) {
@@ -2381,6 +2553,11 @@ class DataSheetSVG {
2381
2553
  : table.getAttribute('data-remove-empty-cells') === 'false'
2382
2554
  ? false
2383
2555
  : this.DataSheet.publicationTemplateSettingVariants?.['hideEmptyCells'] === true;
2556
+ this.DataSheet.overflowBehavior =
2557
+ table.getAttribute('data-overflow-behavior') ||
2558
+ this.DataSheet.publicationTemplateSettingVariants?.['overflowBehavior'] ||
2559
+ 'none';
2560
+ tag.overflowBehavior = this.DataSheet.overflowBehavior;
2384
2561
  }
2385
2562
  }
2386
2563
  else if (tag.XmlTag.getAttribute('data-type').includes('barcode')) {
@@ -2412,11 +2589,21 @@ class DataSheetSVG {
2412
2589
  tag.ProductTable = true;
2413
2590
  tag.Image = false;
2414
2591
  tag.VariantsTable = false;
2592
+ const table = tag.XmlTag.querySelector('table');
2593
+ if (table) {
2594
+ tag.overflowBehavior =
2595
+ table.getAttribute('data-overflow-behavior') || 'none';
2596
+ }
2415
2597
  }
2416
2598
  else if (dataType.includes('variantsTable')) {
2417
2599
  tag.VariantsTable = true;
2418
2600
  tag.Image = false;
2419
2601
  tag.ProductTable = false;
2602
+ const table = tag.XmlTag.querySelector('table');
2603
+ if (table) {
2604
+ tag.overflowBehavior =
2605
+ table.getAttribute('data-overflow-behavior') || 'none';
2606
+ }
2420
2607
  }
2421
2608
  else {
2422
2609
  tag.nbFieldToReplace = 0;
@@ -2667,8 +2854,13 @@ class DataSheetSVG {
2667
2854
  this.addStyle(styles, 'padding-right', variant?.padding?.horizontal);
2668
2855
  this.addStyle(styles, 'border-width', header?.border?.width);
2669
2856
  this.addStyle(styles, 'border-color', header?.border?.color);
2670
- this.addStyle(styles, 'border-style', header?.border?.stroke);
2671
- this.addStyle(styles, 'font-family', header?.text?.font ? `'${header.text.font}'` : undefined);
2857
+ const headerFont = header?.text?.font
2858
+ ? header.text.font.replace(/['"]/g, '').trim()
2859
+ : 'sans-serif';
2860
+ const headerFontFamily = ['sans-serif', 'serif', 'monospace'].includes(headerFont.toLowerCase())
2861
+ ? headerFont
2862
+ : `'${headerFont}', sans-serif`;
2863
+ this.addStyle(styles, 'font-family', headerFontFamily);
2672
2864
  this.addStyle(styles, 'font-size', header?.text?.size);
2673
2865
  this.addStyle(styles, 'color', header?.text?.color);
2674
2866
  this.addStyle(styles, 'font-style', header?.text?.style);
@@ -3177,8 +3369,13 @@ class DataSheetSVG {
3177
3369
  this.addStyle(styles, 'padding-right', variant?.padding?.horizontal);
3178
3370
  this.addStyle(styles, 'border-width', body?.border?.width);
3179
3371
  this.addStyle(styles, 'border-color', body?.border?.color);
3180
- this.addStyle(styles, 'border-style', body?.border?.stroke);
3181
- this.addStyle(styles, 'font-family', body?.text?.font ? `'${body.text.font}'` : undefined);
3372
+ const bodyFont = body?.text?.font
3373
+ ? body.text.font.replace(/['"]/g, '').trim()
3374
+ : 'sans-serif';
3375
+ const bodyFontFamily = ['sans-serif', 'serif', 'monospace'].includes(bodyFont.toLowerCase())
3376
+ ? bodyFont
3377
+ : `'${bodyFont}', sans-serif`;
3378
+ this.addStyle(styles, 'font-family', bodyFontFamily);
3182
3379
  this.addStyle(styles, 'font-size', body?.text?.size);
3183
3380
  this.addStyle(styles, 'color', body?.text?.color);
3184
3381
  this.addStyle(styles, 'font-style', body?.text?.style);
@@ -3470,8 +3667,25 @@ class DataSheetSVG {
3470
3667
  }
3471
3668
  try {
3472
3669
  // Cas spéciaux
3473
- if (field == 'publication_date') {
3474
- newVal = new Date().toLocaleDateString('fr-FR');
3670
+ const cleanId = (idVal || field || '')
3671
+ .toLowerCase()
3672
+ .replace(/[\s_-]/g, '');
3673
+ if (cleanId === 'dategeneration' || field === 'publication_date') {
3674
+ const d = new Date();
3675
+ const day = String(d.getDate()).padStart(2, '0');
3676
+ const month = String(d.getMonth() + 1).padStart(2, '0');
3677
+ const year = d.getFullYear();
3678
+ newVal = `${day}/${month}/${year}`;
3679
+ return newVal;
3680
+ }
3681
+ if (cleanId === 'datecompletegeneration') {
3682
+ const d = new Date();
3683
+ const day = String(d.getDate()).padStart(2, '0');
3684
+ const month = String(d.getMonth() + 1).padStart(2, '0');
3685
+ const year = d.getFullYear();
3686
+ const hours = String(d.getHours()).padStart(2, '0');
3687
+ const minutes = String(d.getMinutes()).padStart(2, '0');
3688
+ newVal = `${day}/${month}/${year} ${hours}:${minutes}`;
3475
3689
  return newVal;
3476
3690
  }
3477
3691
  const attrObj = jRowSku['attributeObject'] || [];
@@ -4268,8 +4482,9 @@ class DataSheetSVG {
4268
4482
  const originalTpl = tpl;
4269
4483
  tpl = tpl.replace(/>\s+</g, '><');
4270
4484
  tpl = tpl.replace(/foreignObject\s*\.cellContent\s*div\s*\{[^}]*max-content[^}]*\}/g, function (match) {
4271
- return match.replace('max-content', 'fit-content');
4485
+ return match.replace('max-content', '100%');
4272
4486
  });
4487
+ tpl = tpl.replace(/foreignObject\s+td\s+div\.wrap\s*\{[^}]*\}/g, 'foreignObject td div.wrap, foreignObject th div.wrap, foreignObject .cellContent { display: flex; flex-direction: column; text-align: inherit; justify-content: inherit; min-height: inherit; align-items: inherit; font-family: inherit !important; width: 100%; }');
4273
4488
  let templateVersion = '';
4274
4489
  const versionMatch = tpl.match(/data-sp-version=["']([^"']+)["']/);
4275
4490
  if (versionMatch) {
@@ -4456,7 +4671,7 @@ class DataSheetSVG {
4456
4671
  else {
4457
4672
  field = this.getPropertyOfField(idVal);
4458
4673
  }
4459
- const tspans = container.querySelectorAll('tspan');
4674
+ const tspans = container.querySelectorAll('tspan, span.textAttribute, [data-type="attribute"]');
4460
4675
  let replaced = false;
4461
4676
  for (let j = 0; j < tspans.length; j++) {
4462
4677
  const tspan = tspans[j];
@@ -4482,9 +4697,42 @@ class DataSheetSVG {
4482
4697
  }
4483
4698
  let valueToInsert = this.getNewVal(field, rowToUse, idVal, tag, showText === 'true', showPicto === 'true', separator, keepAttributes);
4484
4699
  valueToInsert = this.applyTextTransform(valueToInsert, textTransform);
4700
+ const isValEmpty = valueToInsert === null ||
4701
+ valueToInsert === undefined ||
4702
+ (typeof valueToInsert === 'string' &&
4703
+ valueToInsert.trim() === '');
4704
+ if (isValEmpty &&
4705
+ (tspan.hasAttribute('deleteline') ||
4706
+ tspan.getAttribute('deleteline') === 'true' ||
4707
+ tspan.hasAttribute('deleteblock') ||
4708
+ tspan.getAttribute('deleteblock') === 'true')) {
4709
+ let lineDiv = tspan.closest('div');
4710
+ if (lineDiv &&
4711
+ !lineDiv.classList.contains('cellContent') &&
4712
+ !lineDiv.classList.contains('wrap') &&
4713
+ lineDiv.parentElement) {
4714
+ lineDiv.remove();
4715
+ }
4716
+ else {
4717
+ tspan.remove();
4718
+ }
4719
+ replaced = true;
4720
+ if (tag.XmlTag.getAttribute('data-type') !== 'productTable') {
4721
+ break;
4722
+ }
4723
+ continue;
4724
+ }
4485
4725
  if (valueToInsert != null &&
4486
4726
  innerHTML.includes(placeholder)) {
4487
- const newValue = this.replaceDynamicTextInHtml(innerHTML, placeholder, valueToInsert);
4727
+ let formattedVal = valueToInsert;
4728
+ if (formattedVal &&
4729
+ typeof formattedVal === 'string' &&
4730
+ formattedVal.includes('\n')) {
4731
+ formattedVal = formattedVal
4732
+ .replace(/\r\n/g, '<br/>')
4733
+ .replace(/\n/g, '<br/>');
4734
+ }
4735
+ const newValue = this.replaceDynamicTextInHtml(innerHTML, placeholder, formattedVal);
4488
4736
  if (tag.XmlTag.getAttribute('data-type') === 'productTable') {
4489
4737
  tspan.insertAdjacentHTML('beforebegin', newValue);
4490
4738
  tspan.remove();
@@ -4494,7 +4742,9 @@ class DataSheetSVG {
4494
4742
  }
4495
4743
  }
4496
4744
  replaced = true;
4497
- break;
4745
+ if (tag.XmlTag.getAttribute('data-type') !== 'productTable') {
4746
+ break;
4747
+ }
4498
4748
  }
4499
4749
  }
4500
4750
  if (!replaced) {
@@ -4929,7 +5179,7 @@ class DataSheetSVG {
4929
5179
  if (tag.XmlTag.hasAttribute('data-type') &&
4930
5180
  tag.XmlTag.getAttribute('data-type').includes('productTable')) {
4931
5181
  // REPLACE TSPAN VARIABLES IN TABLE CELLS
4932
- const cellTspans = tag.XmlTag.querySelectorAll('tspan');
5182
+ const cellTspans = tag.XmlTag.querySelectorAll('tspan, span.textAttribute, [data-type="attribute"]');
4933
5183
  cellTspans.forEach((tspan) => {
4934
5184
  const tspanText = tspan.textContent?.trim() ?? '';
4935
5185
  const match = tspanText.match(/^\{\{([\w\W]+?)\}\}$/);
@@ -4950,22 +5200,94 @@ class DataSheetSVG {
4950
5200
  const showPicto = tspan.getAttribute('data-show-picto') || 'false';
4951
5201
  const separator = tspan.getAttribute('data-separator') || ', ';
4952
5202
  const textTransform = tspan.getAttribute('data-text-transform');
4953
- let cellVal = this.getNewVal(fieldForCell, jRowSku, idVal, tag, showText === 'true', showPicto === 'true', separator, keepAttributes);
5203
+ let cellVal = this.getNewVal(fieldForCell || '', jRowSku, idVal, tag, showText === 'true', showPicto === 'true', separator, keepAttributes);
4954
5204
  cellVal = this.applyTextTransform(cellVal, textTransform);
4955
- const placeholder = document.createTextNode(cellVal ?? '');
4956
- tspan.parentNode?.insertBefore(placeholder, tspan);
4957
- tspan.remove();
5205
+ const isEmpty = cellVal === null ||
5206
+ cellVal === undefined ||
5207
+ (typeof cellVal === 'string' && cellVal.trim() === '');
5208
+ if (isEmpty &&
5209
+ (tspan.hasAttribute('deleteline') ||
5210
+ tspan.getAttribute('deleteline') === 'true' ||
5211
+ tspan.hasAttribute('deleteblock') ||
5212
+ tspan.getAttribute('deleteblock') === 'true')) {
5213
+ let lineDiv = tspan.closest('div');
5214
+ if (lineDiv &&
5215
+ !lineDiv.classList.contains('cellContent') &&
5216
+ !lineDiv.classList.contains('wrap') &&
5217
+ lineDiv.parentElement) {
5218
+ lineDiv.remove();
5219
+ return;
5220
+ }
5221
+ else {
5222
+ tspan.remove();
5223
+ return;
5224
+ }
5225
+ }
5226
+ if (cellVal &&
5227
+ typeof cellVal === 'string' &&
5228
+ cellVal.includes('\n')) {
5229
+ cellVal = cellVal
5230
+ .replace(/\r\n/g, '<br/>')
5231
+ .replace(/\n/g, '<br/>');
5232
+ }
5233
+ if (cellVal &&
5234
+ typeof cellVal === 'string' &&
5235
+ (cellVal.includes('<br') || cellVal.includes('<'))) {
5236
+ const temp = document.createElement('span');
5237
+ temp.innerHTML = cellVal;
5238
+ while (temp.firstChild) {
5239
+ tspan.parentNode?.insertBefore(temp.firstChild, tspan);
5240
+ }
5241
+ tspan.remove();
5242
+ }
5243
+ else {
5244
+ const placeholder = document.createTextNode(cellVal ?? '');
5245
+ tspan.parentNode?.insertBefore(placeholder, tspan);
5246
+ tspan.remove();
5247
+ }
4958
5248
  }
4959
5249
  });
4960
- // Un-wrap .cellContent and .cellcontent divs in the original XmlTag
4961
- const cellContents = tag.XmlTag.querySelectorAll('.cellContent, .cellcontent');
4962
- cellContents.forEach((cellContent) => {
4963
- const parent = cellContent.parentNode;
4964
- if (parent) {
4965
- while (cellContent.firstChild) {
4966
- parent.insertBefore(cellContent.firstChild, cellContent);
5250
+ // ALSO handle any remaining raw {{attribute}} placeholders in table cells
5251
+ const cells = tag.XmlTag.querySelectorAll('td, th');
5252
+ cells.forEach((cell) => {
5253
+ if (cell.innerHTML && cell.innerHTML.includes('{{')) {
5254
+ cell.innerHTML = cell.innerHTML.replace(/\{\{([\w\W]+?)\}\}/g, (fullMatch, idVal) => {
5255
+ if (idVal.toLowerCase() === 'page' ||
5256
+ idVal.toLowerCase() === 'pagetotal')
5257
+ return fullMatch;
5258
+ let fieldForCell = idVal
5259
+ .toLowerCase()
5260
+ .includes('sku')
5261
+ ? this.getPropertyOfField(idVal.replace(/sku/i, ''))
5262
+ : this.getPropertyOfField(idVal);
5263
+ let val = this.getNewVal(fieldForCell || '', jRowSku, idVal, tag, true, false, ', ', keepAttributes);
5264
+ if (val &&
5265
+ typeof val === 'string' &&
5266
+ val.includes('\n')) {
5267
+ val = val
5268
+ .replace(/\r\n/g, '<br/>')
5269
+ .replace(/\n/g, '<br/>');
5270
+ }
5271
+ return val ?? '';
5272
+ });
5273
+ }
5274
+ });
5275
+ tag.XmlTag.querySelectorAll('.wrap, .cellContent').forEach((div) => {
5276
+ div.style.setProperty('display', 'flex', 'important');
5277
+ div.style.setProperty('flex-direction', 'column', 'important');
5278
+ div.style.setProperty('width', '100%', 'important');
5279
+ });
5280
+ // Synchronize gap between .wrap and .cellContent if present
5281
+ tag.XmlTag.querySelectorAll('td, th').forEach((cell) => {
5282
+ const wrap = cell.querySelector('.wrap');
5283
+ const cellContent = cell.querySelector('.cellContent');
5284
+ if (wrap && cellContent) {
5285
+ if (cellContent.style.gap && !wrap.style.gap) {
5286
+ wrap.style.gap = cellContent.style.gap;
5287
+ }
5288
+ else if (wrap.style.gap && !cellContent.style.gap) {
5289
+ cellContent.style.gap = wrap.style.gap;
4967
5290
  }
4968
- parent.removeChild(cellContent);
4969
5291
  }
4970
5292
  });
4971
5293
  // FIX THE SIZE (WIDTH & HEIGHT)
@@ -4999,6 +5321,42 @@ class DataSheetSVG {
4999
5321
  if (size.width) {
5000
5322
  tag.XmlTag.setAttribute('width', String(size.width));
5001
5323
  }
5324
+ const tableEl = tag.XmlTag.querySelector('table');
5325
+ const overflowBehavior = tableEl?.getAttribute('data-overflow-behavior') ||
5326
+ tag.XmlTag.getAttribute('data-overflow-behavior') ||
5327
+ tag.overflowBehavior ||
5328
+ this.DataSheet.overflowBehavior ||
5329
+ 'none';
5330
+ if (overflowBehavior === 'cut_and_restart') {
5331
+ const tableY = parseFloat(tag.XmlTag.getAttribute('y')) ||
5332
+ (tag.RectPosition ? parseFloat(tag.RectPosition['y']) : 0) ||
5333
+ 0;
5334
+ const tableX = parseFloat(tag.XmlTag.getAttribute('x')) ||
5335
+ (tag.RectPosition ? parseFloat(tag.RectPosition['x']) : 0) ||
5336
+ 0;
5337
+ const headerHeight = this.DataSheet.publicationTemplateBackgroundHeightHeader || 0;
5338
+ const tableTopOnPage = (allBlocksHeight > 0 ? allBlocksHeight : headerHeight) +
5339
+ tableY;
5340
+ const footerY = this.DataSheet.publicationTemplateBackgroundFooterY > 0
5341
+ ? this.DataSheet.publicationTemplateBackgroundFooterY
5342
+ : this.DataSheet.publicationTemplateHeight > 0
5343
+ ? this.DataSheet.publicationTemplateHeight -
5344
+ (this.DataSheet.publicationTemplateBackgroundHeightFooter || 0)
5345
+ : this.DataSheet.backgroundHeight > 0
5346
+ ? this.DataSheet.backgroundHeight -
5347
+ (this.DataSheet.backgroundMarginBottom || 0)
5348
+ : 1122;
5349
+ const availableFirstHeight = footerY - tableTopOnPage;
5350
+ const fullPageHeight = footerY - headerHeight;
5351
+ if (size.height > availableFirstHeight &&
5352
+ availableFirstHeight > 40) {
5353
+ const splitChunks = this.splitProductTable(tag.XmlTag, size.width, availableFirstHeight, fullPageHeight, tableX, tableY, tpl);
5354
+ if (splitChunks && splitChunks.length > 1) {
5355
+ tag.splitHtml = splitChunks.join('');
5356
+ tag.XmlTag.setAttribute('id', 'tableVariant');
5357
+ }
5358
+ }
5359
+ }
5002
5360
  }
5003
5361
  }
5004
5362
  else {
@@ -5206,7 +5564,8 @@ class DataSheetSVG {
5206
5564
  element.outerHTML = tagToUpdate.XmlTag.outerHTML;
5207
5565
  }
5208
5566
  else if (tagToUpdate.ProductTable == true) {
5209
- element.outerHTML = tagToUpdate.XmlTag.outerHTML;
5567
+ element.outerHTML =
5568
+ tagToUpdate.splitHtml || tagToUpdate.XmlTag.outerHTML;
5210
5569
  }
5211
5570
  else if (tagToUpdate.Image == true) {
5212
5571
  element.innerHTML = tagToUpdate.XmlTag.innerHTML;
@@ -5256,7 +5615,8 @@ class DataSheetSVG {
5256
5615
  element.outerHTML = tagToUpdate.XmlTag.outerHTML;
5257
5616
  }
5258
5617
  else if (tagToUpdate.ProductTable == true) {
5259
- element.outerHTML = tagToUpdate.XmlTag.outerHTML;
5618
+ element.outerHTML =
5619
+ tagToUpdate.splitHtml || tagToUpdate.XmlTag.outerHTML;
5260
5620
  }
5261
5621
  else if (tagToUpdate.Image == true) {
5262
5622
  element.innerHTML = tagToUpdate.XmlTag.innerHTML;
@@ -5463,6 +5823,17 @@ class DataSheetSVG {
5463
5823
  gabaritSvgUpdated = gabaritSvgUpdated.replace(/<body.*?>|<\/body>/g, '');
5464
5824
  gabaritSvgUpdated = gabaritSvgUpdated.replace(/<head.*?>|<\/head>/g, '');
5465
5825
  tpl = gabaritSvgUpdated;
5826
+ const now = new Date();
5827
+ const day = String(now.getDate()).padStart(2, '0');
5828
+ const month = String(now.getMonth() + 1).padStart(2, '0');
5829
+ const year = now.getFullYear();
5830
+ const hours = String(now.getHours()).padStart(2, '0');
5831
+ const minutes = String(now.getMinutes()).padStart(2, '0');
5832
+ const dateStr = `${day}/${month}/${year}`;
5833
+ const dateCompleteStr = `${day}/${month}/${year} ${hours}:${minutes}`;
5834
+ tpl = tpl
5835
+ .replace(/\{\{(DateGeneration|Date_Generation|dateGeneration|date_generation)\}\}/gi, dateStr)
5836
+ .replace(/\{\{(DateCompleteGeneration|Date_Complete_Generation|dateCompleteGeneration|date_complete_generation)\}\}/gi, dateCompleteStr);
5466
5837
  if (!keepAttributes) {
5467
5838
  tpl = tpl.replace(/\{\{(?!(Page|PageTotal)\b)[^}]*\}\}/gi, '');
5468
5839
  }
@@ -5685,15 +6056,23 @@ class DataSheetSVG {
5685
6056
  document.body.removeChild(tempDiv);
5686
6057
  return { width: 0, height: 0 };
5687
6058
  }
5688
- // Un-wrap .cellContent divs to prevent max-content / fit-content CSS styles from blocking wrapping
5689
- const cellContents = tableElement.querySelectorAll('.cellContent, .cellcontent');
5690
- cellContents.forEach((cellContent) => {
5691
- const parent = cellContent.parentNode;
5692
- if (parent) {
5693
- while (cellContent.firstChild) {
5694
- parent.insertBefore(cellContent.firstChild, cellContent);
6059
+ tableElement
6060
+ .querySelectorAll('.wrap, .cellContent')
6061
+ .forEach((div) => {
6062
+ div.style.setProperty('display', 'flex', 'important');
6063
+ div.style.setProperty('flex-direction', 'column', 'important');
6064
+ div.style.setProperty('width', '100%', 'important');
6065
+ });
6066
+ tableElement.querySelectorAll('td, th').forEach((cell) => {
6067
+ const wrap = cell.querySelector('.wrap');
6068
+ const cellContent = cell.querySelector('.cellContent');
6069
+ if (wrap && cellContent) {
6070
+ if (cellContent.style.gap && !wrap.style.gap) {
6071
+ wrap.style.gap = cellContent.style.gap;
6072
+ }
6073
+ else if (wrap.style.gap && !cellContent.style.gap) {
6074
+ cellContent.style.gap = wrap.style.gap;
5695
6075
  }
5696
- parent.removeChild(cellContent);
5697
6076
  }
5698
6077
  });
5699
6078
  // 1. Lire le colgroup d'origine pour obtenir les largeurs fixes
@@ -5784,6 +6163,13 @@ class DataSheetSVG {
5784
6163
  div.style.setProperty('word-break', 'break-word', 'important');
5785
6164
  div.style.setProperty('overflow-wrap', 'break-word', 'important');
5786
6165
  });
6166
+ cell
6167
+ .querySelectorAll('div.wrap, .cellContent')
6168
+ .forEach((wrap) => {
6169
+ wrap.style.setProperty('display', 'flex', 'important');
6170
+ wrap.style.setProperty('flex-direction', 'column', 'important');
6171
+ wrap.style.setProperty('width', '100%', 'important');
6172
+ });
5787
6173
  }
5788
6174
  });
5789
6175
  };
@@ -5862,6 +6248,100 @@ class DataSheetSVG {
5862
6248
  document.body.removeChild(tempDiv);
5863
6249
  return { width: finalWidth, height: finalHeight };
5864
6250
  }
6251
+ splitProductTable(foEl, tableWidth, availableFirstHeight, fullPageHeight, tableX, tableY, tpl) {
6252
+ const table = foEl.querySelector('table');
6253
+ if (!table)
6254
+ return [];
6255
+ const tempDiv = document.createElement('div');
6256
+ let stylesHtml = '';
6257
+ if (tpl) {
6258
+ const styleMatches = tpl.match(/<style[^>]*>([\s\S]*?)<\/style>/gi);
6259
+ if (styleMatches) {
6260
+ stylesHtml = styleMatches.join('');
6261
+ }
6262
+ }
6263
+ if (this.DataSheet.importFontFamily) {
6264
+ stylesHtml += `<style>${this.DataSheet.importFontFamily}</style>`;
6265
+ }
6266
+ const tableClone = table.cloneNode(true);
6267
+ tempDiv.innerHTML = stylesHtml;
6268
+ tempDiv.appendChild(tableClone);
6269
+ tempDiv.style.position = 'absolute';
6270
+ tempDiv.style.visibility = 'hidden';
6271
+ tempDiv.style.pointerEvents = 'none';
6272
+ tempDiv.style.left = '-9999px';
6273
+ tempDiv.style.top = '-9999px';
6274
+ tempDiv.style.width = `${tableWidth}px`;
6275
+ document.body.appendChild(tempDiv);
6276
+ const thead = tableClone.querySelector('thead');
6277
+ const theadHeight = thead ? thead.getBoundingClientRect().height : 0;
6278
+ const theadHtml = thead ? thead.outerHTML : '';
6279
+ const colgroup = tableClone.querySelector('colgroup');
6280
+ const colgroupHtml = colgroup ? colgroup.outerHTML : '';
6281
+ const tableAttrs = [];
6282
+ Array.from(table.attributes).forEach((attr) => {
6283
+ tableAttrs.push(`${attr.name}="${attr.value.replace(/"/g, '&quot;')}"`);
6284
+ });
6285
+ const tableAttrsStr = tableAttrs.join(' ');
6286
+ const tbody = tableClone.querySelector('tbody');
6287
+ const allRows = tbody
6288
+ ? Array.from(tbody.querySelectorAll('tr'))
6289
+ : Array.from(tableClone.querySelectorAll('tr')).filter((r) => !thead || !thead.contains(r));
6290
+ if (allRows.length <= 1) {
6291
+ document.body.removeChild(tempDiv);
6292
+ return [];
6293
+ }
6294
+ const rowHeights = allRows.map((row) => {
6295
+ const h = row.getBoundingClientRect().height;
6296
+ return h > 0 ? Math.ceil(h) : 25;
6297
+ });
6298
+ const chunks = [];
6299
+ let currentChunkRows = [];
6300
+ let currentChunkHeight = theadHeight;
6301
+ let currentMaxHeight = availableFirstHeight;
6302
+ for (let idx = 0; idx < allRows.length; idx++) {
6303
+ const row = allRows[idx];
6304
+ const rHeight = rowHeights[idx];
6305
+ if (currentChunkRows.length > 0 &&
6306
+ currentChunkHeight + rHeight > currentMaxHeight) {
6307
+ chunks.push({
6308
+ rows: currentChunkRows,
6309
+ height: currentChunkHeight,
6310
+ });
6311
+ currentChunkRows = [row];
6312
+ currentChunkHeight = theadHeight + rHeight;
6313
+ currentMaxHeight = fullPageHeight;
6314
+ }
6315
+ else {
6316
+ currentChunkRows.push(row);
6317
+ currentChunkHeight += rHeight;
6318
+ }
6319
+ }
6320
+ if (currentChunkRows.length > 0) {
6321
+ chunks.push({
6322
+ rows: currentChunkRows,
6323
+ height: currentChunkHeight,
6324
+ });
6325
+ }
6326
+ document.body.removeChild(tempDiv);
6327
+ if (chunks.length <= 1) {
6328
+ return [];
6329
+ }
6330
+ const foChunks = [];
6331
+ const continuationY = this.DataSheet.publicationTemplateBackgroundHeightHeader || 0;
6332
+ for (let k = 0; k < chunks.length; k++) {
6333
+ const chunk = chunks[k];
6334
+ const rowsHtml = chunk.rows.map((r) => r.outerHTML).join('');
6335
+ const tableHtml = `<table ${tableAttrsStr}>${colgroupHtml}${theadHtml}<tbody>${rowsHtml}</tbody></table>`;
6336
+ const isFirst = k === 0;
6337
+ const posX = tableX;
6338
+ const posY = tableY;
6339
+ const continuationAttr = isFirst ? '' : ' data-split-continuation="true"';
6340
+ const foString = `<foreignObject id="tableVariant" data-type="productTable"${continuationAttr} x="${posX}" y="${posY}" width="${tableWidth}" height="${chunk.height}" style="overflow: visible;">${tableHtml}</foreignObject>`;
6341
+ foChunks.push(foString);
6342
+ }
6343
+ return foChunks;
6344
+ }
5865
6345
  async deleteBlock(svg) {
5866
6346
  try {
5867
6347
  const parser = new DOMParser();
@@ -5887,11 +6367,14 @@ class DataSheetSVG {
5887
6367
  const parser = new DOMParser();
5888
6368
  const doc = parser.parseFromString(`<wrapper>${svg}</wrapper>`, 'text/html');
5889
6369
  const wrapper = doc.body.firstElementChild;
5890
- const tspans = wrapper.querySelectorAll('tspan[deleteline="true"], TSPAN[deleteline="true"]');
6370
+ const tspans = wrapper.querySelectorAll('[deleteline="true"], [deleteline], tspan[deleteline="true"], TSPAN[deleteline="true"], span[deleteline="true"], SPAN[deleteline="true"]');
5891
6371
  tspans.forEach((tspan) => {
5892
6372
  if (tspan.textContent.trim() === '') {
5893
6373
  const lineDiv = tspan.closest('div');
5894
- if (lineDiv && lineDiv !== wrapper.firstElementChild) {
6374
+ if (lineDiv &&
6375
+ lineDiv !== wrapper.firstElementChild &&
6376
+ !lineDiv.classList.contains('wrap') &&
6377
+ !lineDiv.classList.contains('cellContent')) {
5895
6378
  lineDiv.remove();
5896
6379
  }
5897
6380
  }
@@ -6358,10 +6841,11 @@ class DataSheetSVG {
6358
6841
  getActualBlockHeight(svgContent, initialBlockHeight, blockY = 0) {
6359
6842
  if (!svgContent)
6360
6843
  return { actualHeight: initialBlockHeight, updatedSvg: svgContent };
6361
- const hasDynamicElements = /id=["']tableVariant["']/i.test(svgContent) ||
6844
+ const hasTable = /id=["']tableVariant["']/i.test(svgContent) ||
6362
6845
  /data-info=["']variantTable["']/i.test(svgContent) ||
6363
- /<foreignObject/i.test(svgContent);
6364
- if (!hasDynamicElements) {
6846
+ /data-type=["'](productTable|variantsTable)["']/i.test(svgContent) ||
6847
+ /<table\b/i.test(svgContent);
6848
+ if (!hasTable) {
6365
6849
  return { actualHeight: initialBlockHeight, updatedSvg: svgContent };
6366
6850
  }
6367
6851
  let maxBottom = 0;
@@ -6935,7 +7419,7 @@ class DataSheetSku {
6935
7419
  }
6936
7420
  let lstSkuObjects = res?.sku || [];
6937
7421
  if (lstSkuObjects == null || lstSkuObjects.length === 0) {
6938
- console.error('[DATASHEET-GENERATION][DataSheetSku] lstSkuObjects is null or empty for SKU:', sourceId);
7422
+ console.error('[DATASHEET-GENERATION][DataSheetSku] lstSkuObjects is null or empty for SKU:', sourceId, 'with productSheetGuid:', this.DataSheet.productSheetGuid);
6939
7423
  this.DataSheet.currentStep = 99;
6940
7424
  return [];
6941
7425
  }
@@ -6967,68 +7451,16 @@ class DataSheetSku {
6967
7451
  if (!background || !backgroundTpl) {
6968
7452
  console.error('[DATASHEET-GENERATION][DataSheetSku] Background or SVG image is missing for section:', section, 'background object:', background);
6969
7453
  }
7454
+ if (backgroundTpl) {
7455
+ this.DataSheetSVG.parseBackgroundSvgDimensions(backgroundTpl);
7456
+ }
6970
7457
  let allBackgroundTags = this.DataSheetSVG.GetSvgGroupToReplace(backgroundTpl);
6971
7458
  let allElements = this.DataSheetSVG.GetAllTags(backgroundTpl);
6972
7459
  let group = false;
6973
7460
  allElements?.forEach((element) => {
6974
7461
  const tagName = element.tagName?.toLowerCase();
6975
- if (tagName === 'svg') {
6976
- // HEADER HEIGHT
6977
- const attrHeader = element.getAttribute('data-margin-top') ||
6978
- element.getAttribute('data-header-height') ||
6979
- element.getAttribute('data-margin-vertical');
6980
- const parsedHeader = parseFloat(attrHeader);
6981
- if (!isNaN(parsedHeader)) {
6982
- this.DataSheet.publicationTemplateBackgroundHeightHeader =
6983
- parsedHeader;
6984
- }
6985
- else {
6986
- this.DataSheet.publicationTemplateBackgroundHeightHeader = 0;
6987
- }
6988
- // FOOTER HEIGHT
6989
- const attrFooter = element.getAttribute('data-margin-bottom') ||
6990
- element.getAttribute('data-footer-height') ||
6991
- element.getAttribute('data-margin-vertical');
6992
- const parsedFooter = parseFloat(attrFooter);
6993
- if (!isNaN(parsedFooter)) {
6994
- this.DataSheet.publicationTemplateBackgroundHeightFooter =
6995
- parsedFooter;
6996
- this.DataSheet.publicationTemplateBackgroundFooterY =
6997
- this.DataSheet.publicationTemplateHeight - parsedFooter;
6998
- }
6999
- else {
7000
- this.DataSheet.publicationTemplateBackgroundHeightFooter = 0;
7001
- this.DataSheet.publicationTemplateBackgroundFooterY =
7002
- this.DataSheet.publicationTemplateHeight;
7003
- }
7004
- // MARGIN
7005
- const attrMarginLeft = element.getAttribute('data-margin-left') ||
7006
- element.getAttribute('data-margin-horizontal');
7007
- const attrMarginRight = element.getAttribute('data-margin-right') ||
7008
- element.getAttribute('data-margin-horizontal');
7009
- const parsedMarginLeft = parseFloat(attrMarginLeft);
7010
- if (!isNaN(parsedMarginLeft)) {
7011
- this.DataSheet.publicationTemplateBackgroundLeftMargin =
7012
- parsedMarginLeft;
7013
- }
7014
- else {
7015
- this.DataSheet.publicationTemplateBackgroundLeftMargin = 0;
7016
- }
7017
- const parsedMarginRight = parseFloat(attrMarginRight);
7018
- if (!isNaN(parsedMarginRight)) {
7019
- this.DataSheet.publicationTemplateBackgroundRightMargin =
7020
- parsedMarginRight;
7021
- this.DataSheet.publicationTemplateBackgroundMarginX =
7022
- this.DataSheet.publicationTemplateWidth - parsedMarginRight;
7023
- }
7024
- else {
7025
- this.DataSheet.publicationTemplateBackgroundRightMargin = 0;
7026
- this.DataSheet.publicationTemplateBackgroundMarginX =
7027
- this.DataSheet.publicationTemplateWidth;
7028
- }
7029
- }
7030
7462
  // GROUPE <g>
7031
- else if (tagName === 'g') {
7463
+ if (tagName === 'g') {
7032
7464
  group = true;
7033
7465
  const tag = this.DataSheetSVG.SetAllInfos(element);
7034
7466
  lstBackgroundTags.push(tag);
@@ -7122,9 +7554,18 @@ class DataSheetSku {
7122
7554
  }
7123
7555
  }
7124
7556
  }
7557
+ if (currentBackgroundTpl) {
7558
+ this.DataSheetSVG.parseBackgroundSvgDimensions(currentBackgroundTpl);
7559
+ }
7125
7560
  let i = 0;
7126
7561
  for (const jObject of lstSkus) {
7127
7562
  let aJobject = [];
7563
+ if (pageConfig) {
7564
+ const gabGuid = pageConfig.gabaritGuid || pageConfig.gabarit;
7565
+ if (gabGuid) {
7566
+ jObject.gabaritName = this.DataSheet.defaultGabaritGuid;
7567
+ }
7568
+ }
7128
7569
  aJobject.push(jObject);
7129
7570
  if (jObject && jObject.type === PublicationDataType.CALLOUT) {
7130
7571
  const cGuid = jObject.publicationDataCallout ||
@@ -7969,8 +8410,16 @@ class DataSheetController {
7969
8410
  }
7970
8411
  }
7971
8412
  if (publication) {
7972
- if (!dataSheet.productSheetGuid && (publication.publicationProductSheetAssetGuid || publication.publicationproductsheetassetguid)) {
7973
- dataSheet.productSheetGuid = publication.publicationProductSheetAssetGuid || publication.publicationproductsheetassetguid;
8413
+ if (!dataSheet.productSheetGuid &&
8414
+ (publication.publicationProductSheetGuid ||
8415
+ publication.publicationproductsheetguid ||
8416
+ publication.publicationProductSheetAssetGuid ||
8417
+ publication.publicationproductsheetassetguid)) {
8418
+ dataSheet.productSheetGuid =
8419
+ publication.publicationProductSheetGuid ||
8420
+ publication.publicationproductsheetguid ||
8421
+ publication.publicationProductSheetAssetGuid ||
8422
+ publication.publicationproductsheetassetguid;
7974
8423
  }
7975
8424
  if (source == 2) {
7976
8425
  dataSheet.currentObjectName = publication.publicationName;
@@ -7998,12 +8447,20 @@ class DataSheetController {
7998
8447
  if (publication.publicationTemplateGuid) {
7999
8448
  templateGuid = publication.publicationTemplateGuid;
8000
8449
  }
8001
- const pubPages = publication.publicationPages || publication.PublicationPages || publication._publicationPages || [];
8002
- if ((!dataSheet.pagesSettings || dataSheet.pagesSettings.length === 0) && pubPages.length > 0) {
8450
+ const pubPages = publication.publicationPages ||
8451
+ publication.PublicationPages ||
8452
+ publication._publicationPages ||
8453
+ [];
8454
+ if ((!dataSheet.pagesSettings || dataSheet.pagesSettings.length === 0) &&
8455
+ pubPages.length > 0) {
8003
8456
  dataSheet.pagesSettings = pubPages.map((page) => ({
8004
- backgroundGuid: page.background || page.publicationpagebackground || page.backgroundGuid,
8005
- gabaritGuid: page.gabarit || page.publicationpagedefaultgabarit || page.gabaritGuid,
8006
- order: page.order || page.publicationpageorder || 0
8457
+ backgroundGuid: page.background ||
8458
+ page.publicationpagebackground ||
8459
+ page.backgroundGuid,
8460
+ gabaritGuid: page.gabarit ||
8461
+ page.publicationpagedefaultgabarit ||
8462
+ page.gabaritGuid,
8463
+ order: page.order || page.publicationpageorder || 0,
8007
8464
  }));
8008
8465
  }
8009
8466
  }