@solidpepper/solidpepper-solidgeneration 0.2.4 → 0.2.5

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.
@@ -1,10 +1,11 @@
1
1
  import JsBarcode from 'jsbarcode';
2
2
  import QrCodeStyling from 'qr-code-styling';
3
+ import * as i2 from '@solidpepper/solidpepper-service';
4
+ import { PublicationDataType } from '@solidpepper/solidpepper-service';
3
5
  import { firstValueFrom } from 'rxjs';
4
6
  import * as i0 from '@angular/core';
5
7
  import { Injectable } from '@angular/core';
6
8
  import * as i1 from '@angular/common/http';
7
- import * as i2 from '@solidpepper/solidpepper-service';
8
9
  import * as i3 from 'ngx-toastr';
9
10
  import * as i4 from '@ngx-translate/core';
10
11
  import * as i5 from '@angular/platform-browser';
@@ -60,6 +61,7 @@ class DataSheet {
60
61
  this.backgrounds = [];
61
62
  this.defaultBackgroundGuid = null;
62
63
  this.marketing = [];
64
+ this.callouts = {};
63
65
  this.preview = true;
64
66
  this.imageFastPreview = true;
65
67
  this.bleedMargin = false;
@@ -364,6 +366,7 @@ class DataSheetSingleton {
364
366
  this.gabarits = {};
365
367
  this.backgrounds = {};
366
368
  this.marketing = {};
369
+ this.callouts = {};
367
370
  //console.log('[DataSheetSingleton] Constructor called. instanceId:', this.instanceId);
368
371
  }
369
372
  static getInstance() {
@@ -393,16 +396,25 @@ class DataSheetSingleton {
393
396
  setMarketing(templateGuid, list) {
394
397
  this.marketing[templateGuid] = [...list];
395
398
  }
399
+ getCallouts(templateGuid) {
400
+ const cached = this.callouts[templateGuid];
401
+ return cached ? [...cached] : null;
402
+ }
403
+ setCallouts(templateGuid, list) {
404
+ this.callouts[templateGuid] = [...list];
405
+ }
396
406
  clearTemplatesCache(templateGuid) {
397
407
  if (templateGuid) {
398
408
  delete this.gabarits[templateGuid];
399
409
  delete this.backgrounds[templateGuid];
400
410
  delete this.marketing[templateGuid];
411
+ delete this.callouts[templateGuid];
401
412
  }
402
413
  else {
403
414
  this.gabarits = {};
404
415
  this.backgrounds = {};
405
416
  this.marketing = {};
417
+ this.callouts = {};
406
418
  }
407
419
  }
408
420
  async getAttributesByType(attributeType, attributeGroup = '') {
@@ -574,16 +586,35 @@ class DataSheetSVG {
574
586
  // pour jObject dans lstSkus
575
587
  const gabaritDimCache = new Map();
576
588
  const getBlockDimensionsAndMarginsCached = (jObj) => {
577
- let defaultGabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
578
- let gabaritName = jObj.gabaritName + '.svg';
579
- let gabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.name == gabaritName);
580
- if (gabarit == undefined || gabarit == null) {
581
- gabarit = defaultGabarit;
589
+ let gabarit = null;
590
+ if (jObj.type === PublicationDataType.CALLOUT) {
591
+ const calloutGuid = jObj.publicationDataCallout;
592
+ const calloutsList = this.DataSheet.callouts?.[calloutGuid] ||
593
+ DataSheetSingleton.getInstance().getCallouts(calloutGuid) ||
594
+ [];
595
+ const gName = (jObj.gabaritName || '').endsWith('.svg')
596
+ ? jObj.gabaritName
597
+ : jObj.gabaritName + '.svg';
598
+ gabarit = calloutsList.find((c) => c.name === gName ||
599
+ c.name === jObj.gabaritName ||
600
+ c.guid === jObj.gabaritName);
601
+ if (!gabarit && calloutsList.length > 0) {
602
+ gabarit =
603
+ calloutsList.find((c) => c.isDefault) || calloutsList[0];
604
+ }
582
605
  }
583
- if (gabarit == null || gabarit == undefined) {
584
- gabarit = this.DataSheet.gabarits[0];
606
+ else {
607
+ let defaultGabarit = (this.DataSheet.gabarits || []).find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
608
+ let gabaritName = (jObj.gabaritName || '') + '.svg';
609
+ gabarit = (this.DataSheet.gabarits || []).find((gabarit) => gabarit.name == gabaritName || gabarit.name == jObj.gabaritName);
610
+ if (gabarit == undefined || gabarit == null) {
611
+ gabarit = defaultGabarit;
612
+ }
613
+ if (gabarit == null || gabarit == undefined) {
614
+ gabarit = (this.DataSheet.gabarits || [])[0];
615
+ }
585
616
  }
586
- if (!gabarit) {
617
+ if (!gabarit || !gabarit.svgImage) {
587
618
  return {
588
619
  width: 0,
589
620
  height: 0,
@@ -593,7 +624,9 @@ class DataSheetSVG {
593
624
  marginRight: 0,
594
625
  };
595
626
  }
596
- const cacheKey = gabarit.guid || gabarit.name || '';
627
+ const cacheKey = (jObj.type === PublicationDataType.CALLOUT
628
+ ? 'callout_'
629
+ : 'gabarit_') + (gabarit.guid || gabarit.name || '');
597
630
  if (gabaritDimCache.has(cacheKey)) {
598
631
  return gabaritDimCache.get(cacheKey);
599
632
  }
@@ -613,18 +646,24 @@ class DataSheetSVG {
613
646
  if (!jObj ||
614
647
  jObj === '{}' ||
615
648
  (jObj.sku == null &&
616
- jObj.type !== 'LINEBREAK' &&
617
- jObj.type !== 'PAGEBREAK')) {
649
+ jObj.type !== PublicationDataType.LINEBREAK &&
650
+ jObj.type !== PublicationDataType.PAGEBREAK &&
651
+ jObj.type !== PublicationDataType.CALLOUT)) {
618
652
  idx++;
619
653
  continue;
620
654
  }
621
- if (jObj.type === 'LINEBREAK' || jObj.type === 'PAGEBREAK') {
655
+ if (jObj.type === PublicationDataType.LINEBREAK ||
656
+ jObj.type === PublicationDataType.PAGEBREAK) {
622
657
  if (blocksInRow.length === 0) {
623
658
  idx++;
624
659
  }
625
660
  break;
626
661
  }
627
662
  let dim = getBlockDimensionsAndMarginsCached(jObj);
663
+ if (dim.width === 0 && dim.height === 0) {
664
+ idx++;
665
+ continue;
666
+ }
628
667
  let blockWidth = dim.width;
629
668
  let gMarginLeft = dim.marginLeft;
630
669
  let gMarginRight = dim.marginRight;
@@ -669,9 +708,10 @@ class DataSheetSVG {
669
708
  if (jObject != null &&
670
709
  jObject != '{}' &&
671
710
  (jObject.sku != null ||
672
- jObject.type === 'LINEBREAK' ||
673
- jObject.type === 'PAGEBREAK')) {
674
- if (jObject.type === 'PAGEBREAK') {
711
+ jObject.type === PublicationDataType.LINEBREAK ||
712
+ jObject.type === PublicationDataType.PAGEBREAK ||
713
+ jObject.type === PublicationDataType.CALLOUT)) {
714
+ if (jObject.type === PublicationDataType.PAGEBREAK) {
675
715
  AllTplProductsBlock += tplRowProductsBlocks;
676
716
  tplRowProductsBlocks = '';
677
717
  AllTplProductsBlock += this.addCuttingLine() + '</svg>';
@@ -714,7 +754,7 @@ class DataSheetSVG {
714
754
  currentIdx++;
715
755
  continue;
716
756
  }
717
- if (jObject.type === 'LINEBREAK') {
757
+ if (jObject.type === PublicationDataType.LINEBREAK) {
718
758
  if (nbBlockInRow > 0) {
719
759
  AllTplProductsBlock += tplRowProductsBlocks;
720
760
  tplRowProductsBlocks = '';
@@ -739,14 +779,45 @@ class DataSheetSVG {
739
779
  currentIdx++;
740
780
  continue;
741
781
  }
742
- let defaultGabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
743
- let gabaritName = jObject.gabaritName + '.svg';
744
- let gabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.name == gabaritName);
745
- if (gabarit == undefined || gabarit == null) {
746
- gabarit = defaultGabarit;
782
+ let gabarit = null;
783
+ if (jObject.type === PublicationDataType.CALLOUT) {
784
+ const calloutGuid = jObject.publicationDataCallout ||
785
+ jObject.PublicationDataCallout;
786
+ const calloutsList = this.DataSheet.callouts?.[calloutGuid] ||
787
+ DataSheetSingleton.getInstance().getCallouts(calloutGuid) ||
788
+ [];
789
+ const gName = (jObject.gabaritName || '').endsWith('.svg')
790
+ ? jObject.gabaritName
791
+ : jObject.gabaritName + '.svg';
792
+ gabarit = calloutsList.find((c) => c.name === gName ||
793
+ c.name === jObject.gabaritName ||
794
+ c.guid === jObject.gabaritName);
795
+ if (!gabarit && calloutsList.length > 0) {
796
+ gabarit =
797
+ calloutsList.find((c) => c.isDefault) || calloutsList[0];
798
+ }
747
799
  }
748
- if (gabarit == null || gabarit == undefined) {
749
- gabarit = this.DataSheet.gabarits[0];
800
+ else {
801
+ let defaultGabarit = (this.DataSheet.gabarits || []).find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
802
+ let gabaritName = (jObject.gabaritName || '') + '.svg';
803
+ gabarit = (this.DataSheet.gabarits || []).find((gabarit) => gabarit.name == gabaritName ||
804
+ gabarit.name == jObject.gabaritName);
805
+ if (gabarit == undefined || gabarit == null) {
806
+ gabarit = defaultGabarit;
807
+ }
808
+ if (gabarit == null || gabarit == undefined) {
809
+ gabarit = (this.DataSheet.gabarits || [])[0];
810
+ }
811
+ }
812
+ if (!gabarit || !gabarit.svgImage) {
813
+ console.warn('[SOLIDGENERATION] Skipping block with missing/invalid gabarit:', jObject);
814
+ this.DataSheet.progress +=
815
+ (50 / this.DataSheet.maxSections) *
816
+ 0.8 *
817
+ (1 / this.DataSheet.maxSkusSection);
818
+ this.DataSheet.nbSkusSection++;
819
+ currentIdx++;
820
+ continue;
750
821
  }
751
822
  let firstRowTopMargin = 0;
752
823
  let blockY = 0;
@@ -1204,16 +1275,34 @@ class DataSheetSVG {
1204
1275
  }
1205
1276
  }
1206
1277
  getBlockDimensionsAndMargins(jObject) {
1207
- let defaultGabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
1208
- let gabaritName = jObject.gabaritName + '.svg';
1209
- let gabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.name == gabaritName);
1210
- if (gabarit == undefined || gabarit == null) {
1211
- gabarit = defaultGabarit;
1278
+ let gabarit = null;
1279
+ if (jObject.type === PublicationDataType.CALLOUT) {
1280
+ const calloutGuid = jObject.publicationDataCallout || jObject.PublicationDataCallout;
1281
+ const calloutsList = this.DataSheet.callouts?.[calloutGuid] ||
1282
+ DataSheetSingleton.getInstance().getCallouts(calloutGuid) ||
1283
+ [];
1284
+ const gName = (jObject.gabaritName || '').endsWith('.svg')
1285
+ ? jObject.gabaritName
1286
+ : jObject.gabaritName + '.svg';
1287
+ gabarit = calloutsList.find((c) => c.name === gName ||
1288
+ c.name === jObject.gabaritName ||
1289
+ c.guid === jObject.gabaritName);
1290
+ if (!gabarit && calloutsList.length > 0) {
1291
+ gabarit = calloutsList.find((c) => c.isDefault) || calloutsList[0];
1292
+ }
1212
1293
  }
1213
- if (gabarit == null || gabarit == undefined) {
1214
- gabarit = this.DataSheet.gabarits[0];
1294
+ else {
1295
+ let defaultGabarit = (this.DataSheet.gabarits || []).find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
1296
+ let gabaritName = (jObject.gabaritName || '') + '.svg';
1297
+ gabarit = (this.DataSheet.gabarits || []).find((gabarit) => gabarit.name == gabaritName || gabarit.name == jObject.gabaritName);
1298
+ if (gabarit == undefined || gabarit == null) {
1299
+ gabarit = defaultGabarit;
1300
+ }
1301
+ if (gabarit == null || gabarit == undefined) {
1302
+ gabarit = (this.DataSheet.gabarits || [])[0];
1303
+ }
1215
1304
  }
1216
- if (!gabarit) {
1305
+ if (!gabarit || !gabarit.svgImage) {
1217
1306
  return {
1218
1307
  width: 0,
1219
1308
  height: 0,
@@ -1367,34 +1456,63 @@ class DataSheetSVG {
1367
1456
  if (!skuRef) {
1368
1457
  skuRef = this.getAttributeFromSvg(gabarit?.svgImage, 'data-sku');
1369
1458
  }
1370
- let templateGuid = gabarit?.templateGuid || '';
1371
- if (!templateGuid ||
1372
- templateGuid === '00000000-0000-0000-0000-000000000000') {
1373
- templateGuid = this.DataSheet?.publicationTemplateTemplateGuid || '';
1459
+ const isCallout = jObject?.type === PublicationDataType.CALLOUT ||
1460
+ gabarit?.type?.toLowerCase() === 'callout' ||
1461
+ gabarit?.assetType?.toLowerCase() === 'callout';
1462
+ let templateGuid = '';
1463
+ if (isCallout) {
1464
+ templateGuid =
1465
+ jObject?.publicationDataCallout ||
1466
+ gabarit?.templateGuid ||
1467
+ gabarit?.publicationTemplateTemplateGuid ||
1468
+ '';
1469
+ if (!templateGuid ||
1470
+ templateGuid === '00000000-0000-0000-0000-000000000000') {
1471
+ templateGuid =
1472
+ this.getAttributeFromSvg(gabarit?.svgImage, 'data-templateGuid') ||
1473
+ this.getAttributeFromSvg(gabarit?.svgImage, 'data-assetGuid');
1474
+ }
1374
1475
  }
1375
- if (!templateGuid ||
1376
- templateGuid === '00000000-0000-0000-0000-000000000000') {
1377
- templateGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-templateGuid');
1476
+ else {
1477
+ templateGuid = gabarit?.templateGuid || '';
1478
+ if (!templateGuid ||
1479
+ templateGuid === '00000000-0000-0000-0000-000000000000') {
1480
+ templateGuid = this.DataSheet?.publicationTemplateTemplateGuid || '';
1481
+ }
1482
+ if (!templateGuid ||
1483
+ templateGuid === '00000000-0000-0000-0000-000000000000') {
1484
+ templateGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-templateGuid');
1485
+ }
1378
1486
  }
1379
- let assetGuid = gabarit?.templateGuid || '';
1380
- if (!assetGuid || assetGuid === '00000000-0000-0000-0000-000000000000') {
1381
- assetGuid = this.DataSheet?.publicationTemplateTemplateGuid || '';
1487
+ let assetGuid = '';
1488
+ if (isCallout) {
1489
+ assetGuid =
1490
+ jObject?.publicationDataCallout || gabarit?.templateGuid || '';
1491
+ if (!assetGuid || assetGuid === '00000000-0000-0000-0000-000000000000') {
1492
+ assetGuid =
1493
+ this.getAttributeFromSvg(gabarit?.svgImage, 'data-assetGuid') ||
1494
+ this.getAttributeFromSvg(gabarit?.svgImage, 'data-templateGuid');
1495
+ }
1382
1496
  }
1383
- if (!assetGuid || assetGuid === '00000000-0000-0000-0000-000000000000') {
1384
- assetGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-assetGuid');
1497
+ else {
1498
+ assetGuid = gabarit?.templateGuid || '';
1499
+ if (!assetGuid || assetGuid === '00000000-0000-0000-0000-000000000000') {
1500
+ assetGuid = this.DataSheet?.publicationTemplateTemplateGuid || '';
1501
+ }
1502
+ if (!assetGuid || assetGuid === '00000000-0000-0000-0000-000000000000') {
1503
+ assetGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-assetGuid');
1504
+ }
1385
1505
  }
1386
1506
  let blockGuid = gabarit?.guid || '';
1387
1507
  if (!blockGuid || blockGuid === '00000000-0000-0000-0000-000000000000') {
1388
1508
  blockGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-blockGuid');
1389
1509
  }
1390
- const sanitizedRef = (skuRef || '')
1391
- .toString()
1392
- .trim()
1393
- .replace(/[\s\W]+/g, '-');
1510
+ const sanitizedRef = (skuRef || '').toString().trim();
1394
1511
  const groupId = sanitizedRef
1395
- ? `group_${nbBlock + 1}_${sanitizedRef}`
1396
- : `group_${nbBlock + 1}`;
1397
- return `<g data-type="template" id="${groupId}" data-skuGuid="${skuGuid}" data-sku="${skuRef}" data-assetGuid="${assetGuid}" data-templateGuid="${templateGuid}" data-blockGuid="${blockGuid}">${tplGroup}</g>`;
1512
+ ? `group(${nbBlock + 1}) - ${sanitizedRef}`
1513
+ : `group(${nbBlock + 1})`;
1514
+ const dataType = isCallout ? 'callout' : 'template';
1515
+ return `<g data-type="${dataType}" id="${groupId}" data-skuGuid="${skuGuid}" data-sku="${skuRef}" data-assetGuid="${assetGuid}" data-templateGuid="${templateGuid}" data-blockGuid="${blockGuid}">${tplGroup}</g>`;
1398
1516
  }
1399
1517
  CleanMissingFilters(svgContent) {
1400
1518
  const filterRegex = /filter="url\(#([^"]+)\)"/g;
@@ -4421,10 +4539,13 @@ class DataSheetSVG {
4421
4539
  return false;
4422
4540
  if (image.assetName === newVal || image.assetGuid === newVal)
4423
4541
  return true;
4424
- if (image.assetName && this.getCleanFilename(image.assetName).toLowerCase() === cleanNewVal.toLowerCase()) {
4542
+ if (image.assetName &&
4543
+ this.getCleanFilename(image.assetName).toLowerCase() ===
4544
+ cleanNewVal.toLowerCase()) {
4425
4545
  return true;
4426
4546
  }
4427
- if (image.assetName && this.getFileNameWithoutExt(image.assetName).toLowerCase() === cleanNewValNoExt) {
4547
+ if (image.assetName &&
4548
+ this.getFileNameWithoutExt(image.assetName).toLowerCase() === cleanNewValNoExt) {
4428
4549
  return true;
4429
4550
  }
4430
4551
  const urls = [
@@ -4436,19 +4557,25 @@ class DataSheetSVG {
4436
4557
  for (const url of urls) {
4437
4558
  if (url === newVal)
4438
4559
  return true;
4439
- if (this.getCleanFilename(url).toLowerCase() === cleanNewVal.toLowerCase())
4560
+ if (this.getCleanFilename(url).toLowerCase() ===
4561
+ cleanNewVal.toLowerCase())
4440
4562
  return true;
4441
- if (this.getFileNameWithoutExt(url).toLowerCase() === cleanNewValNoExt)
4563
+ if (this.getFileNameWithoutExt(url).toLowerCase() ===
4564
+ cleanNewValNoExt)
4442
4565
  return true;
4443
4566
  }
4444
4567
  return false;
4445
4568
  });
4446
4569
  }
4447
- if (skuImagesDetail.length === 0 && jRowSku && jRowSku['skuDefaultImage']) {
4570
+ if (skuImagesDetail.length === 0 &&
4571
+ jRowSku &&
4572
+ jRowSku['skuDefaultImage']) {
4448
4573
  const defaultImg = jRowSku['skuDefaultImage'];
4449
4574
  const cleanNewValNoExt = this.getFileNameWithoutExt(newVal).toLowerCase();
4450
4575
  const defaultNameNoExt = this.getFileNameWithoutExt(defaultImg.assetName || defaultImg.assetUrlOriginal || '').toLowerCase();
4451
- if (!cleanNewValNoExt || cleanNewValNoExt === defaultNameNoExt || defaultImg.assetGuid === newVal) {
4576
+ if (!cleanNewValNoExt ||
4577
+ cleanNewValNoExt === defaultNameNoExt ||
4578
+ defaultImg.assetGuid === newVal) {
4452
4579
  skuImagesDetail = [defaultImg];
4453
4580
  }
4454
4581
  }
@@ -4456,27 +4583,65 @@ class DataSheetSVG {
4456
4583
  const matchedAsset = skuImagesDetail[0];
4457
4584
  if (this.DataSheet.preview &&
4458
4585
  this.DataSheet.imageFastPreview == true) {
4459
- newVal = matchedAsset.assetUrlSmall || matchedAsset.assetUrlMedium || matchedAsset.assetUrlBig || matchedAsset.assetUrlOriginal || newVal;
4460
- urlHD = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4586
+ newVal =
4587
+ matchedAsset.assetUrlSmall ||
4588
+ matchedAsset.assetUrlMedium ||
4589
+ matchedAsset.assetUrlBig ||
4590
+ matchedAsset.assetUrlOriginal ||
4591
+ newVal;
4592
+ urlHD =
4593
+ matchedAsset.assetUrlOriginal ||
4594
+ matchedAsset.assetUrlBig ||
4595
+ matchedAsset.assetUrlMedium ||
4596
+ matchedAsset.assetUrlSmall ||
4597
+ newVal;
4461
4598
  }
4462
4599
  else if (this.DataSheet.highDefinition == false) {
4463
- newVal = matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || matchedAsset.assetUrlBig || matchedAsset.assetUrlOriginal || newVal;
4464
- urlHD = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4600
+ newVal =
4601
+ matchedAsset.assetUrlMedium ||
4602
+ matchedAsset.assetUrlSmall ||
4603
+ matchedAsset.assetUrlBig ||
4604
+ matchedAsset.assetUrlOriginal ||
4605
+ newVal;
4606
+ urlHD =
4607
+ matchedAsset.assetUrlOriginal ||
4608
+ matchedAsset.assetUrlBig ||
4609
+ matchedAsset.assetUrlMedium ||
4610
+ matchedAsset.assetUrlSmall ||
4611
+ newVal;
4465
4612
  }
4466
4613
  else {
4467
- newVal = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4468
- urlHD = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4614
+ newVal =
4615
+ matchedAsset.assetUrlOriginal ||
4616
+ matchedAsset.assetUrlBig ||
4617
+ matchedAsset.assetUrlMedium ||
4618
+ matchedAsset.assetUrlSmall ||
4619
+ newVal;
4620
+ urlHD =
4621
+ matchedAsset.assetUrlOriginal ||
4622
+ matchedAsset.assetUrlBig ||
4623
+ matchedAsset.assetUrlMedium ||
4624
+ matchedAsset.assetUrlSmall ||
4625
+ newVal;
4469
4626
  }
4470
4627
  }
4471
4628
  else {
4472
4629
  let urlBase = this.getUrlBase(jRowSku);
4473
- if (urlBase && typeof newVal === 'string' && !newVal.startsWith('http://') && !newVal.startsWith('https://') && !newVal.startsWith('data:') && !newVal.startsWith('/')) {
4630
+ if (urlBase &&
4631
+ typeof newVal === 'string' &&
4632
+ !newVal.startsWith('http://') &&
4633
+ !newVal.startsWith('https://') &&
4634
+ !newVal.startsWith('data:') &&
4635
+ !newVal.startsWith('/')) {
4474
4636
  newVal = urlBase + newVal;
4475
4637
  }
4476
4638
  urlHD = newVal;
4477
4639
  if (typeof newVal === 'string' &&
4478
- (this.DataSheet.highDefinition == false || (this.DataSheet.preview && this.DataSheet.imageFastPreview == true))) {
4479
- if (this.DataSheet.preview && this.DataSheet.imageFastPreview == true) {
4640
+ (this.DataSheet.highDefinition == false ||
4641
+ (this.DataSheet.preview &&
4642
+ this.DataSheet.imageFastPreview == true))) {
4643
+ if (this.DataSheet.preview &&
4644
+ this.DataSheet.imageFastPreview == true) {
4480
4645
  newVal = newVal
4481
4646
  .replace(/\/original\//i, '/small/')
4482
4647
  .replace(/\.[a-zA-Z0-9]+(?=\?|#|$)/i, '.webp');
@@ -4765,7 +4930,8 @@ class DataSheetSVG {
4765
4930
  newVal = await this.deleteBlock(newVal);
4766
4931
  newVal = await this.deleteLine(newVal);
4767
4932
  tag.XmlTag.innerHTML = newVal;
4768
- if (tag.XmlTag.getAttribute('data-type') === 'text') {
4933
+ if (tag.XmlTag.getAttribute('data-type') === 'text' ||
4934
+ tag.XmlTag.querySelector('.fake-textarea')) {
4769
4935
  this.optimizeTextElement(tag.XmlTag, tpl);
4770
4936
  }
4771
4937
  if (tag.XmlTag.hasAttribute('data-type') &&
@@ -5037,6 +5203,55 @@ class DataSheetSVG {
5037
5203
  }
5038
5204
  }
5039
5205
  }
5206
+ else if (element.nodeName.toLowerCase() === 'foreignobject') {
5207
+ let tag = this.SetAllInfos(element);
5208
+ let tagToUpdate = allTags.find((tagToUpdate) => tagToUpdate.IdTag == tag.IdTag);
5209
+ if (tagToUpdate != null) {
5210
+ if (tagToUpdate.XmlTag == null) {
5211
+ element.remove();
5212
+ }
5213
+ else if (tagToUpdate.VariantsTable == true) {
5214
+ element.outerHTML = tagToUpdate.XmlTag.outerHTML;
5215
+ }
5216
+ else if (tagToUpdate.ProductTable == true) {
5217
+ element.outerHTML = tagToUpdate.XmlTag.outerHTML;
5218
+ }
5219
+ else if (tagToUpdate.Image == true) {
5220
+ element.innerHTML = tagToUpdate.XmlTag.innerHTML;
5221
+ if (element.getAttribute('data-type') === 'dynamicImage') {
5222
+ element.setAttribute('data-type', 'image');
5223
+ }
5224
+ }
5225
+ else {
5226
+ element.innerHTML = tagToUpdate.XmlTag.innerHTML;
5227
+ if (tagToUpdate.XmlTag.getAttribute('data-type') === 'text' ||
5228
+ tagToUpdate.XmlTag.querySelector('.fake-textarea')) {
5229
+ if (tagToUpdate.XmlTag.hasAttribute('x')) {
5230
+ element.setAttribute('x', tagToUpdate.XmlTag.getAttribute('x'));
5231
+ element.removeAttribute('transform');
5232
+ }
5233
+ if (tagToUpdate.XmlTag.hasAttribute('y')) {
5234
+ element.setAttribute('y', tagToUpdate.XmlTag.getAttribute('y'));
5235
+ element.removeAttribute('transform');
5236
+ }
5237
+ if (tagToUpdate.XmlTag.hasAttribute('width')) {
5238
+ const w = tagToUpdate.XmlTag.getAttribute('width');
5239
+ element.setAttribute('width', w);
5240
+ if (element.style && element.style.width) {
5241
+ element.style.width = w + 'px';
5242
+ }
5243
+ }
5244
+ if (tagToUpdate.XmlTag.hasAttribute('height')) {
5245
+ const h = tagToUpdate.XmlTag.getAttribute('height');
5246
+ element.setAttribute('height', h);
5247
+ if (element.style && element.style.height) {
5248
+ element.style.height = h + 'px';
5249
+ }
5250
+ }
5251
+ }
5252
+ }
5253
+ }
5254
+ }
5040
5255
  else if (group == true) {
5041
5256
  if (element.parentNode ? element.parentNode.nodeName == 'g' : false) {
5042
5257
  let tag = this.SetAllInfos(element);
@@ -5059,12 +5274,29 @@ class DataSheetSVG {
5059
5274
  }
5060
5275
  else {
5061
5276
  element.innerHTML = tagToUpdate.XmlTag.innerHTML;
5062
- if (tagToUpdate.XmlTag.getAttribute('data-type') === 'text') {
5277
+ if (tagToUpdate.XmlTag.getAttribute('data-type') === 'text' ||
5278
+ tagToUpdate.XmlTag.querySelector('.fake-textarea')) {
5279
+ if (tagToUpdate.XmlTag.hasAttribute('x')) {
5280
+ element.setAttribute('x', tagToUpdate.XmlTag.getAttribute('x'));
5281
+ element.removeAttribute('transform');
5282
+ }
5283
+ if (tagToUpdate.XmlTag.hasAttribute('y')) {
5284
+ element.setAttribute('y', tagToUpdate.XmlTag.getAttribute('y'));
5285
+ element.removeAttribute('transform');
5286
+ }
5063
5287
  if (tagToUpdate.XmlTag.hasAttribute('width')) {
5064
- element.setAttribute('width', tagToUpdate.XmlTag.getAttribute('width'));
5288
+ const w = tagToUpdate.XmlTag.getAttribute('width');
5289
+ element.setAttribute('width', w);
5290
+ if (element.style && element.style.width) {
5291
+ element.style.width = w + 'px';
5292
+ }
5065
5293
  }
5066
5294
  if (tagToUpdate.XmlTag.hasAttribute('height')) {
5067
- element.setAttribute('height', tagToUpdate.XmlTag.getAttribute('height'));
5295
+ const h = tagToUpdate.XmlTag.getAttribute('height');
5296
+ element.setAttribute('height', h);
5297
+ if (element.style && element.style.height) {
5298
+ element.style.height = h + 'px';
5299
+ }
5068
5300
  }
5069
5301
  }
5070
5302
  }
@@ -5132,7 +5364,8 @@ class DataSheetSVG {
5132
5364
  let attrName = element.getAttribute('data-hide-if-attribute') || '';
5133
5365
  let op = element.getAttribute('data-hide-if-operator') || 'is_null';
5134
5366
  let compareVal = element.getAttribute('data-hide-if-value') || '';
5135
- let variantAttr = element.getAttribute('data-hide-if-variant') || element.getAttribute('data-variant');
5367
+ let variantAttr = element.getAttribute('data-hide-if-variant') ||
5368
+ element.getAttribute('data-variant');
5136
5369
  let rowToUse = jRowSku;
5137
5370
  let variantExists = false;
5138
5371
  if (variantAttr != null && variantAttr !== '') {
@@ -5163,7 +5396,9 @@ class DataSheetSVG {
5163
5396
  let cleanCompare = cleanValueForHide(compareVal).toLowerCase();
5164
5397
  // Vérifier si l'attribut est de type multiSelect
5165
5398
  const normAttr = attrName.toLowerCase().trim();
5166
- const allAttrs = (this.DataSheet && this.DataSheet.attributes) || DataSheetSingleton.getInstance().attributes || [];
5399
+ const allAttrs = (this.DataSheet && this.DataSheet.attributes) ||
5400
+ DataSheetSingleton.getInstance().attributes ||
5401
+ [];
5167
5402
  const getAttrString = (val) => {
5168
5403
  if (!val)
5169
5404
  return '';
@@ -5176,12 +5411,19 @@ class DataSheetSVG {
5176
5411
  const matchedAttr = allAttrs.find((a) => (a && a.id && getAttrString(a.id) === normAttr) ||
5177
5412
  (a && a.attributeId && getAttrString(a.attributeId) === normAttr) ||
5178
5413
  (a && a.guid && getAttrString(a.guid) === normAttr) ||
5179
- (a && a.attributeGuid && getAttrString(a.attributeGuid) === normAttr) ||
5180
- (a && a.attributeName && getAttrString(a.attributeName) === normAttr) ||
5414
+ (a &&
5415
+ a.attributeGuid &&
5416
+ getAttrString(a.attributeGuid) === normAttr) ||
5417
+ (a &&
5418
+ a.attributeName &&
5419
+ getAttrString(a.attributeName) === normAttr) ||
5181
5420
  (a && a.code && getAttrString(a.code) === normAttr) ||
5182
- (a && a.attributeCode && getAttrString(a.attributeCode) === normAttr));
5421
+ (a &&
5422
+ a.attributeCode &&
5423
+ getAttrString(a.attributeCode) === normAttr));
5183
5424
  const isMultiSelectAttr = !!(matchedAttr &&
5184
- (matchedAttr.attributeType === 'multiSelect' || matchedAttr.type === 'multiSelect'));
5425
+ (matchedAttr.attributeType === 'multiSelect' ||
5426
+ matchedAttr.type === 'multiSelect'));
5185
5427
  let actualValues = [];
5186
5428
  if (isMultiSelectAttr) {
5187
5429
  if (Array.isArray(actualValue)) {
@@ -5240,7 +5482,9 @@ class DataSheetSVG {
5240
5482
  const isFixed = locked === 'true';
5241
5483
  const isWidth = locked === 'width';
5242
5484
  const isHeight = locked !== 'true' && locked !== 'width';
5243
- if (isFixed) {
5485
+ const isMinimize = textarea.getAttribute('data-minimize') === 'true' ||
5486
+ foEl.getAttribute('data-minimize') === 'true';
5487
+ if (isFixed && !isMinimize) {
5244
5488
  return;
5245
5489
  }
5246
5490
  const foWidth = parseFloat(foEl.getAttribute('width')) || 0;
@@ -5274,151 +5518,129 @@ class DataSheetSVG {
5274
5518
  const textareaElement = tempDiv.querySelector(`#${textareaId}`);
5275
5519
  if (textareaElement) {
5276
5520
  let parentFo = textareaElement.closest('foreignObject');
5277
- const splitDivAtBr = (div) => {
5278
- const br = div.querySelector('br');
5279
- if (!br || !div.parentNode)
5280
- return false;
5281
- const nextDiv = div.cloneNode(true);
5282
- let currInDiv = div.querySelector('br');
5283
- while (currInDiv && currInDiv !== div) {
5284
- const parent = currInDiv.parentNode;
5285
- if (!parent)
5286
- break;
5287
- while (currInDiv.nextSibling) {
5288
- parent.removeChild(currInDiv.nextSibling);
5289
- }
5290
- const toRemove = currInDiv;
5291
- currInDiv = parent;
5292
- if (toRemove.nodeName.toLowerCase() === 'br') {
5293
- parent.removeChild(toRemove);
5294
- }
5521
+ const direction = textarea.getAttribute('data-direction') ||
5522
+ foEl.getAttribute('data-direction') ||
5523
+ (isWidth ? 'ltr' : 'ttb');
5524
+ const [initialYStr, initialXStr] = this.GetXY(foEl);
5525
+ const initialX = initialXStr !== '' && initialXStr !== null
5526
+ ? parseFloat(initialXStr)
5527
+ : parseFloat(foEl.getAttribute('x')) || 0;
5528
+ const initialY = initialYStr !== '' && initialYStr !== null
5529
+ ? parseFloat(initialYStr)
5530
+ : parseFloat(foEl.getAttribute('y')) || 0;
5531
+ if (isWidth) {
5532
+ if (parentFo) {
5533
+ parentFo.setAttribute('width', '99999');
5534
+ parentFo.setAttribute('height', foHeight.toString());
5295
5535
  }
5296
- let currInNext = nextDiv.querySelector('br');
5297
- while (currInNext && currInNext !== nextDiv) {
5298
- const parent = currInNext.parentNode;
5299
- if (!parent)
5300
- break;
5301
- while (currInNext.previousSibling) {
5302
- parent.removeChild(currInNext.previousSibling);
5303
- }
5304
- const toRemove = currInNext;
5305
- currInNext = parent;
5306
- if (toRemove.nodeName.toLowerCase() === 'br') {
5307
- parent.removeChild(toRemove);
5308
- }
5536
+ textareaElement.style.setProperty('width', 'max-content', 'important');
5537
+ textareaElement.style.setProperty('max-width', 'none', 'important');
5538
+ textareaElement.style.setProperty('height', 'auto', 'important');
5539
+ textareaElement.style.setProperty('min-height', '0', 'important');
5540
+ textareaElement.style.display = 'inline-block';
5541
+ const rect = textareaElement.getBoundingClientRect();
5542
+ const naturalWidth = Math.ceil(rect.width);
5543
+ const naturalHeight = Math.ceil(rect.height);
5544
+ const newWidth = naturalWidth + 4;
5545
+ if (direction === 'rtl') {
5546
+ const deltaW = newWidth - foWidth;
5547
+ const newX = initialX - deltaW;
5548
+ foEl.setAttribute('x', newX.toString());
5549
+ foEl.removeAttribute('transform');
5309
5550
  }
5310
- div.parentNode.insertBefore(nextDiv, div.nextSibling);
5311
- if (!nextDiv.textContent || !nextDiv.textContent.trim()) {
5312
- nextDiv.remove();
5551
+ foEl.setAttribute('width', newWidth.toString());
5552
+ if (isMinimize) {
5553
+ foEl.setAttribute('height', Math.min(foHeight, naturalHeight + 4).toString());
5313
5554
  }
5314
- return true;
5315
- };
5316
- let hasBr = true;
5317
- while (hasBr) {
5318
- hasBr = false;
5319
- const divsWithBr = Array.from(textareaElement.querySelectorAll('div')).filter((d) => d.querySelector('br') !== null);
5320
- for (const d of divsWithBr) {
5321
- if (splitDivAtBr(d)) {
5322
- hasBr = true;
5323
- break;
5324
- }
5555
+ else {
5556
+ foEl.setAttribute('height', Math.max(foHeight, naturalHeight + 4).toString());
5325
5557
  }
5326
5558
  }
5327
- // Split long text wrapping into separate divs to prevent overlap and highlight blockiness
5328
- const lineDivs = Array.from(textareaElement.querySelectorAll('div')).filter((d) => {
5329
- return d.querySelectorAll('div').length === 0;
5330
- });
5331
- const findTextNode = (node) => {
5332
- if (node.nodeType === Node.TEXT_NODE &&
5333
- node.textContent?.trim() !== '') {
5334
- return node;
5335
- }
5336
- for (let child of Array.from(node.childNodes)) {
5337
- const found = findTextNode(child);
5338
- if (found)
5339
- return found;
5340
- }
5341
- return null;
5342
- };
5343
- let domChanged = false;
5344
- lineDivs.forEach((lineDiv) => {
5345
- const text = lineDiv.textContent || '';
5346
- if (!text.trim())
5347
- return;
5348
- const computedStyle = window.getComputedStyle(lineDiv);
5349
- const fontFamily = computedStyle.fontFamily || 'sans-serif';
5350
- const fontSize = computedStyle.fontSize || '24px';
5351
- const canvas = document.createElement('canvas');
5352
- const ctx = canvas.getContext('2d');
5353
- if (!ctx)
5354
- return;
5355
- ctx.font = `${fontSize} ${fontFamily}`;
5356
- const textWidth = ctx.measureText(text).width;
5357
- if (foWidth > 0 && textWidth > foWidth) {
5358
- const words = text.split(' ');
5359
- const linesOfText = [];
5360
- let currentLine = '';
5361
- for (let word of words) {
5362
- const testLine = currentLine ? currentLine + ' ' + word : word;
5363
- const testWidth = ctx.measureText(testLine).width;
5364
- if (testWidth > foWidth && currentLine) {
5365
- linesOfText.push(currentLine);
5366
- currentLine = word;
5367
- }
5368
- else {
5369
- currentLine = testLine;
5370
- }
5371
- }
5372
- if (currentLine) {
5373
- linesOfText.push(currentLine);
5374
- }
5375
- if (linesOfText.length > 1) {
5376
- domChanged = true;
5377
- let previousLine = lineDiv;
5378
- for (let i = 0; i < linesOfText.length; i++) {
5379
- if (i === 0) {
5380
- const textNode = findTextNode(lineDiv);
5381
- if (textNode) {
5382
- textNode.textContent = linesOfText[0];
5383
- }
5384
- }
5385
- else {
5386
- const clone = lineDiv.cloneNode(true);
5387
- const textNode = findTextNode(clone);
5388
- if (textNode) {
5389
- textNode.textContent = linesOfText[i];
5390
- }
5391
- lineDiv.parentNode.insertBefore(clone, previousLine.nextSibling);
5392
- previousLine = clone;
5393
- }
5394
- }
5395
- }
5396
- }
5397
- });
5398
- if (domChanged) {
5399
- const originalTextarea = foEl.querySelector('.fake-textarea');
5400
- if (originalTextarea) {
5401
- originalTextarea.innerHTML = textareaElement.innerHTML;
5559
+ else if (isHeight) {
5560
+ if (parentFo) {
5561
+ parentFo.setAttribute('width', foWidth.toString());
5562
+ parentFo.setAttribute('height', 'auto');
5402
5563
  }
5403
- }
5404
- if (isWidth) {
5405
- textareaElement.style.width = 'max-content';
5406
- textareaElement.style.whiteSpace = 'nowrap';
5564
+ textareaElement.style.setProperty('width', 'max-content', 'important');
5565
+ textareaElement.style.setProperty('max-width', foWidth + 'px', 'important');
5566
+ textareaElement.style.setProperty('height', 'auto', 'important');
5567
+ textareaElement.style.setProperty('min-height', '0', 'important');
5568
+ textareaElement.style.setProperty('max-height', 'none', 'important');
5407
5569
  textareaElement.style.display = 'inline-block';
5570
+ textareaElement.style.wordBreak = 'break-word';
5571
+ textareaElement.style.overflowWrap = 'break-word';
5572
+ if (textarea) {
5573
+ textarea.style.wordBreak = 'break-word';
5574
+ textarea.style.overflowWrap = 'break-word';
5575
+ }
5408
5576
  const rect = textareaElement.getBoundingClientRect();
5409
5577
  const naturalWidth = Math.ceil(rect.width);
5410
- foEl.setAttribute('width', (naturalWidth + 4).toString());
5411
- }
5412
- else if (isHeight) {
5578
+ const naturalHeight = Math.ceil(rect.height);
5579
+ const newHeight = naturalHeight + 4;
5580
+ if (direction === 'btt') {
5581
+ const deltaH = newHeight - foHeight;
5582
+ const newY = initialY - deltaH;
5583
+ foEl.setAttribute('y', newY.toString());
5584
+ foEl.removeAttribute('transform');
5585
+ }
5586
+ foEl.setAttribute('height', newHeight.toString());
5587
+ if (isMinimize) {
5588
+ const newWidth = Math.min(foWidth, naturalWidth + 4);
5589
+ if (direction === 'rtl') {
5590
+ const deltaW = newWidth - foWidth;
5591
+ const newX = initialX - deltaW;
5592
+ foEl.setAttribute('x', newX.toString());
5593
+ foEl.removeAttribute('transform');
5594
+ }
5595
+ foEl.setAttribute('width', newWidth.toString());
5596
+ }
5597
+ }
5598
+ else if (isFixed && isMinimize) {
5413
5599
  if (parentFo) {
5414
5600
  parentFo.setAttribute('width', foWidth.toString());
5415
- parentFo.removeAttribute('height');
5601
+ parentFo.setAttribute('height', foHeight.toString());
5602
+ }
5603
+ textareaElement.style.setProperty('width', 'max-content', 'important');
5604
+ textareaElement.style.setProperty('max-width', foWidth + 'px', 'important');
5605
+ textareaElement.style.setProperty('height', 'auto', 'important');
5606
+ textareaElement.style.setProperty('min-height', '0', 'important');
5607
+ textareaElement.style.setProperty('max-height', foHeight + 'px', 'important');
5608
+ textareaElement.style.display = 'inline-block';
5609
+ textareaElement.style.wordBreak = 'break-word';
5610
+ textareaElement.style.overflowWrap = 'break-word';
5611
+ if (textarea) {
5612
+ textarea.style.wordBreak = 'break-word';
5613
+ textarea.style.overflowWrap = 'break-word';
5416
5614
  }
5417
- textareaElement.style.width = foWidth + 'px';
5418
- textareaElement.style.height = 'auto';
5419
5615
  const rect = textareaElement.getBoundingClientRect();
5616
+ const naturalWidth = Math.ceil(rect.width);
5420
5617
  const naturalHeight = Math.ceil(rect.height);
5421
- foEl.setAttribute('height', (naturalHeight + 4).toString());
5618
+ const newWidth = Math.min(foWidth, naturalWidth + 4);
5619
+ const newHeight = Math.min(foHeight, naturalHeight + 4);
5620
+ if (direction === 'rtl') {
5621
+ const deltaW = newWidth - foWidth;
5622
+ const newX = initialX - deltaW;
5623
+ foEl.setAttribute('x', newX.toString());
5624
+ foEl.removeAttribute('transform');
5625
+ }
5626
+ if (direction === 'btt') {
5627
+ const deltaH = newHeight - foHeight;
5628
+ const newY = initialY - deltaH;
5629
+ foEl.setAttribute('y', newY.toString());
5630
+ foEl.removeAttribute('transform');
5631
+ }
5632
+ foEl.setAttribute('width', newWidth.toString());
5633
+ foEl.setAttribute('height', newHeight.toString());
5634
+ }
5635
+ if (textarea) {
5636
+ textarea.setAttribute('locked', 'true');
5637
+ textarea.style.width = '100%';
5638
+ textarea.style.height = '100%';
5639
+ textarea.style.wordBreak = 'break-word';
5640
+ textarea.style.overflowWrap = 'break-word';
5641
+ textarea.style.whiteSpace = 'normal';
5642
+ textarea.style.maxHeight = 'none';
5643
+ textarea.style.maxWidth = 'none';
5422
5644
  }
5423
5645
  }
5424
5646
  }
@@ -5689,7 +5911,8 @@ class DataSheetSVG {
5689
5911
  }
5690
5912
  }
5691
5913
  getBackgroundSectionForPreview(section) {
5692
- if (!this.DataSheet.backgrounds || this.DataSheet.backgrounds.length === 0) {
5914
+ if (!this.DataSheet.backgrounds ||
5915
+ this.DataSheet.backgrounds.length === 0) {
5693
5916
  return null;
5694
5917
  }
5695
5918
  let defaultBackground = this.DataSheet.backgrounds.find((background) => background.guid == this.DataSheet.defaultBackgroundGuid);
@@ -5792,7 +6015,9 @@ class DataSheetSVG {
5792
6015
  return background;
5793
6016
  }
5794
6017
  getMarketingSectionForPreview(section) {
5795
- if (!this.DataSheet.marketing || this.DataSheet.marketing.length === 0 || !section) {
6018
+ if (!this.DataSheet.marketing ||
6019
+ this.DataSheet.marketing.length === 0 ||
6020
+ !section) {
5796
6021
  return null;
5797
6022
  }
5798
6023
  const identifier = section.gabaritName ||
@@ -5800,7 +6025,9 @@ class DataSheetSVG {
5800
6025
  section.gabaritGuid ||
5801
6026
  section.guid ||
5802
6027
  section.name;
5803
- if (!identifier || typeof identifier !== 'string' || identifier.trim() === '') {
6028
+ if (!identifier ||
6029
+ typeof identifier !== 'string' ||
6030
+ identifier.trim() === '') {
5804
6031
  return null;
5805
6032
  }
5806
6033
  const idLower = identifier.trim().toLowerCase();
@@ -5812,7 +6039,9 @@ class DataSheetSVG {
5812
6039
  if (mGuidLower && (mGuidLower === idLower || mGuidLower === idClean)) {
5813
6040
  return true;
5814
6041
  }
5815
- const mMarketingNameLower = (m.marketingName || '').toString().toLowerCase();
6042
+ const mMarketingNameLower = (m.marketingName || '')
6043
+ .toString()
6044
+ .toLowerCase();
5816
6045
  const mMarketingClean = mMarketingNameLower.replace(/\.svg$/i, '');
5817
6046
  if (mMarketingNameLower &&
5818
6047
  (mMarketingNameLower === idLower ||
@@ -6135,9 +6364,10 @@ class DataSheetSVG {
6135
6364
  getActualBlockHeight(svgContent, initialBlockHeight, blockY = 0) {
6136
6365
  if (!svgContent)
6137
6366
  return { actualHeight: initialBlockHeight, updatedSvg: svgContent };
6138
- const hasVariantTable = /id=["']tableVariant["']/i.test(svgContent) ||
6139
- /data-info=["']variantTable["']/i.test(svgContent);
6140
- if (!hasVariantTable) {
6367
+ const hasDynamicElements = /id=["']tableVariant["']/i.test(svgContent) ||
6368
+ /data-info=["']variantTable["']/i.test(svgContent) ||
6369
+ /<foreignObject/i.test(svgContent);
6370
+ if (!hasDynamicElements) {
6141
6371
  return { actualHeight: initialBlockHeight, updatedSvg: svgContent };
6142
6372
  }
6143
6373
  let maxBottom = 0;
@@ -6691,6 +6921,9 @@ class DataSheetSku {
6691
6921
  this.DataSheet = dataSheet;
6692
6922
  this.DataSheetSVG = dataSheetSVG;
6693
6923
  }
6924
+ async setDataSheetsController(dataSheetsController) {
6925
+ this.dataSheetsController = dataSheetsController;
6926
+ }
6694
6927
  async setPublicationsService(publicationsService) {
6695
6928
  if (!publicationsService) {
6696
6929
  throw new Error('PublicationsService instance is required');
@@ -6877,6 +7110,21 @@ class DataSheetSku {
6877
7110
  for (const jObject of lstSkus) {
6878
7111
  let aJobject = [];
6879
7112
  aJobject.push(jObject);
7113
+ if (jObject && jObject.type === PublicationDataType.CALLOUT) {
7114
+ const cGuid = jObject.publicationDataCallout ||
7115
+ jObject.PublicationDataCallout;
7116
+ const needForce = !this.DataSheet.preview;
7117
+ if (cGuid && (!this.DataSheet.callouts?.[cGuid] || needForce)) {
7118
+ let loaded = [];
7119
+ if (this.dataSheetsController) {
7120
+ loaded =
7121
+ await this.dataSheetsController.updateCalloutsList(cGuid, needForce);
7122
+ }
7123
+ if (!this.DataSheet.callouts)
7124
+ this.DataSheet.callouts = {};
7125
+ this.DataSheet.callouts[cGuid] = loaded;
7126
+ }
7127
+ }
6880
7128
  const newFiles = await this.DataSheetSVG.GenerateSvgFiles(aJobject, currentBackgroundTpl, currentBackgroundTpl, fileIndex.toString());
6881
7129
  if (newFiles) {
6882
7130
  files = files.concat(newFiles);
@@ -6913,6 +7161,9 @@ class DataSheetPublication {
6913
7161
  this.sectionActiveObject = sectionActiveObject;
6914
7162
  this.skusSection = skusSection;
6915
7163
  }
7164
+ async setDataSheetsController(dataSheetsController) {
7165
+ this.dataSheetsController = dataSheetsController;
7166
+ }
6916
7167
  async setPublicationsService(publicationsService) {
6917
7168
  if (!publicationsService) {
6918
7169
  throw new Error('PublicationsService instance is required');
@@ -7350,9 +7601,22 @@ class DataSheetPublication {
7350
7601
  let background = this.DataSheetSVG.getBackgroundSectionForPreview(section);
7351
7602
  let backgroundTpl = background?.svgImage || '';
7352
7603
  let allBackgroundTags = this.DataSheetSVG.GetSvgGroupToReplace(backgroundTpl);
7353
- // Get the backgroundTpl left page (= 1st g) and right page (= 2nd g if exist else the first g) for double page layout, the idea is to remove left/right g for each page
7354
- let backgroundTplLeft = this.DataSheetSVG.keepOnlySideRegex(backgroundTpl, 'left');
7355
- let backgroundTplRight = this.DataSheetSVG.keepOnlySideRegex(backgroundTpl, 'right');
7604
+ const hasDataSide = backgroundTpl.includes('data-side');
7605
+ const isDoublePage = backgroundTpl.includes('data-double-page="true"') ||
7606
+ backgroundTpl.includes("data-double-page='true'");
7607
+ let backgroundTplLeft = backgroundTpl;
7608
+ let backgroundTplRight = backgroundTpl;
7609
+ if (hasDataSide) {
7610
+ if (isDoublePage) {
7611
+ backgroundTplLeft = this.DataSheetSVG.keepOnlySideRegex(backgroundTpl, 'left');
7612
+ backgroundTplRight = this.DataSheetSVG.keepOnlySideRegex(backgroundTpl, 'right');
7613
+ }
7614
+ else {
7615
+ const onlyRight = this.DataSheetSVG.keepOnlySideRegex(backgroundTpl, 'right');
7616
+ backgroundTplLeft = onlyRight;
7617
+ backgroundTplRight = onlyRight;
7618
+ }
7619
+ }
7356
7620
  let allElements = this.DataSheetSVG.GetAllTags(backgroundTplLeft);
7357
7621
  let group = false;
7358
7622
  if (allElements) {
@@ -7478,6 +7742,24 @@ class DataSheetPublication {
7478
7742
  else {
7479
7743
  lstSkus = [...lstSkuObjects];
7480
7744
  }
7745
+ if (lstSkus && lstSkus.length > 0) {
7746
+ for (const item of lstSkus) {
7747
+ if (item && item.type === PublicationDataType.CALLOUT) {
7748
+ const cGuid = item.publicationDataCallout ||
7749
+ item.PublicationDataCallout;
7750
+ const needForce = !this.DataSheet.preview;
7751
+ if (cGuid && (!this.DataSheet.callouts?.[cGuid] || needForce)) {
7752
+ let loaded = [];
7753
+ if (this.dataSheetsController) {
7754
+ loaded = await this.dataSheetsController.updateCalloutsList(cGuid, needForce);
7755
+ }
7756
+ if (!this.DataSheet.callouts)
7757
+ this.DataSheet.callouts = {};
7758
+ this.DataSheet.callouts[cGuid] = loaded;
7759
+ }
7760
+ }
7761
+ }
7762
+ }
7481
7763
  files = await this.DataSheetSVG.GenerateSvgFiles(lstSkus, backgroundTplLeft, backgroundTplRight, section.pageId.toString());
7482
7764
  lstBackgroundTags = [];
7483
7765
  }
@@ -7803,6 +8085,7 @@ class DataSheetController {
7803
8085
  case 2: // Publication
7804
8086
  //console.log("Generate SVG for publication");
7805
8087
  let dataSheetPublication = new DataSheetPublication(dataSheetSVG, dataSheet, publication, json.sectionActiveObject, json.skusSection);
8088
+ dataSheetPublication.setDataSheetsController(this);
7806
8089
  dataSheetPublication.setPublicationsService(this._publicationsService);
7807
8090
  dataSheetPublication.setDamAssetsService(this._damAssets);
7808
8091
  dataSheetPublication.setDocumentsService(this._documents);
@@ -7812,6 +8095,7 @@ class DataSheetController {
7812
8095
  case 3: // SKUs
7813
8096
  //console.log('Generate SVG for SKUs');
7814
8097
  let dataSheetSku = new DataSheetSku(dataSheetSVG, dataSheet);
8098
+ dataSheetSku.setDataSheetsController(this);
7815
8099
  dataSheetSku.setPublicationsService(this._publicationsService);
7816
8100
  files = await dataSheetSku.GenerateAllInOneExportFile(json.sourceGuid, json.option1PerPage, displayModeVariant, json.multiColumns);
7817
8101
  dataSheetSku = null;
@@ -7820,6 +8104,7 @@ class DataSheetController {
7820
8104
  for (let sourceGuid of sourceGuids) {
7821
8105
  dataSheet.progress = 25;
7822
8106
  let dataSheetSku = new DataSheetSku(dataSheetSVG, dataSheet);
8107
+ dataSheetSku.setDataSheetsController(this);
7823
8108
  dataSheetSku.setPublicationsService(this._publicationsService);
7824
8109
  let files2 = await dataSheetSku.GenerateAllInOneExportFile(sourceGuid, json.option1PerPage, displayModeVariant, json.multiColumns);
7825
8110
  dataSheetSku = null;
@@ -7978,6 +8263,29 @@ class DataSheetController {
7978
8263
  return [];
7979
8264
  }
7980
8265
  }
8266
+ async updateCalloutsList(templateGuid, forceRefresh = false) {
8267
+ const singleton = DataSheetSingleton.getInstance();
8268
+ const cached = singleton.getCallouts(templateGuid);
8269
+ if (!forceRefresh && cached && cached.length > 0) {
8270
+ return cached;
8271
+ }
8272
+ try {
8273
+ const res = await this._publicationsTemplates
8274
+ .getTemplateCallouts(templateGuid)
8275
+ .toPromise();
8276
+ const rawCallouts = res?.['callouts'] ||
8277
+ res?.['productBlocks'] ||
8278
+ res ||
8279
+ [];
8280
+ const callouts = await this.loadGabaritsSvg(Array.isArray(rawCallouts) ? rawCallouts : []);
8281
+ singleton.setCallouts(templateGuid, callouts);
8282
+ return callouts;
8283
+ }
8284
+ catch (e) {
8285
+ console.error('Erreur dans updateCalloutsList :', e);
8286
+ return [];
8287
+ }
8288
+ }
7981
8289
  async updateBackgroundsList(templateGuid, forceRefresh = false) {
7982
8290
  const singleton = DataSheetSingleton.getInstance();
7983
8291
  const cached = singleton.getBackgrounds(templateGuid);
@@ -8048,6 +8356,9 @@ class DataSheetController {
8048
8356
  return [];
8049
8357
  }
8050
8358
  }
8359
+ clearTemplatesCache(templateGuid) {
8360
+ DataSheetSingleton.getInstance().clearTemplatesCache(templateGuid);
8361
+ }
8051
8362
  async loadGabaritsSvg(gabarits) {
8052
8363
  const loadedGabarits = [];
8053
8364
  for (let template of gabarits) {