@solidpepper/solidpepper-solidgeneration 0.1.6 → 0.1.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.
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import JsBarcode from 'jsbarcode';
|
|
2
2
|
import QrCodeStyling from 'qr-code-styling';
|
|
3
|
+
import { firstValueFrom } from 'rxjs';
|
|
4
|
+
import * as i0 from '@angular/core';
|
|
5
|
+
import { Injectable } from '@angular/core';
|
|
6
|
+
import * as i1 from '@angular/common/http';
|
|
7
|
+
import * as i2 from '@solidpepper/solidpepper-service';
|
|
8
|
+
import * as i3 from 'ngx-toastr';
|
|
9
|
+
import * as i4 from '@ngx-translate/core';
|
|
10
|
+
import * as i5 from '@angular/platform-browser';
|
|
3
11
|
|
|
4
12
|
// src/app/models/data-sheet.model.ts
|
|
5
13
|
var SourceData;
|
|
@@ -19,6 +27,7 @@ var TypeDatasheet;
|
|
|
19
27
|
class DataSheet {
|
|
20
28
|
constructor(init) {
|
|
21
29
|
this.previewId = 0;
|
|
30
|
+
this.versionName = null;
|
|
22
31
|
this.coverPage = '';
|
|
23
32
|
this.pagesSettings = [];
|
|
24
33
|
this.importFontFamily = '';
|
|
@@ -39,7 +48,8 @@ class DataSheet {
|
|
|
39
48
|
this.backgroundVariation = false;
|
|
40
49
|
this.backgroundVariationColor = 'transparent';
|
|
41
50
|
this.hideEmptyCells = false;
|
|
42
|
-
this.
|
|
51
|
+
this.publicationTemplateTemplateGuid = null;
|
|
52
|
+
this.productSheetGuid = null;
|
|
43
53
|
this.currentWidth = 0;
|
|
44
54
|
this.lastGabaritHeight = 0;
|
|
45
55
|
// Only for front
|
|
@@ -149,6 +159,13 @@ class DataSheet {
|
|
|
149
159
|
.hidden {
|
|
150
160
|
display: none;
|
|
151
161
|
}
|
|
162
|
+
|
|
163
|
+
mark {
|
|
164
|
+
padding: 0.1875em;
|
|
165
|
+
display: inline-block;
|
|
166
|
+
width: fit-content;
|
|
167
|
+
color: inherit;
|
|
168
|
+
}
|
|
152
169
|
`;
|
|
153
170
|
this.mapping = [];
|
|
154
171
|
this.startPageNumber = 1;
|
|
@@ -178,8 +195,11 @@ class DataSheet {
|
|
|
178
195
|
}
|
|
179
196
|
}
|
|
180
197
|
GetBlockY(allTags) {
|
|
181
|
-
let tag = allTags.find((x) => x.IdTag
|
|
182
|
-
|
|
198
|
+
let tag = allTags.find((x) => x.IdTag && x.IdTag.toLowerCase() === 'block');
|
|
199
|
+
if (tag) {
|
|
200
|
+
return parseFloat(tag.YTotal) || 0;
|
|
201
|
+
}
|
|
202
|
+
return 0;
|
|
183
203
|
}
|
|
184
204
|
setStyleTagForTableVariants() {
|
|
185
205
|
try {
|
|
@@ -189,7 +209,8 @@ class DataSheet {
|
|
|
189
209
|
let nbColumn = this.publicationTemplateSettingVariants['headerRow'].length;
|
|
190
210
|
this.publicationTemplateSettingVariantsTableStyle = '<style>';
|
|
191
211
|
// Table
|
|
192
|
-
tableStyle +=
|
|
212
|
+
tableStyle +=
|
|
213
|
+
'width: ' + this.publicationTemplateSettingVariants['width'] + 'px;';
|
|
193
214
|
tableStyle += 'border-collapse: collapse;}';
|
|
194
215
|
// Header
|
|
195
216
|
// th += "padding-bottom: " + this.publicationTemplateSettingVariants["padding"]["vertical"] + ";";
|
|
@@ -198,7 +219,10 @@ class DataSheet {
|
|
|
198
219
|
// th += "padding-right: " + this.publicationTemplateSettingVariants["padding"]["horizontal"] + ";}";
|
|
199
220
|
for (let i = 0; i < nbColumn; i++) {
|
|
200
221
|
th += '.thCol' + i + '{';
|
|
201
|
-
th +=
|
|
222
|
+
th +=
|
|
223
|
+
' width: ' +
|
|
224
|
+
this.publicationTemplateSettingVariants['headerRow'][i]['width'] +
|
|
225
|
+
';';
|
|
202
226
|
th +=
|
|
203
227
|
'border-width: ' +
|
|
204
228
|
this.publicationTemplateSettingVariants['headerRow'][i]['border']['width'] +
|
|
@@ -240,7 +264,10 @@ class DataSheet {
|
|
|
240
264
|
// td += "padding-right: " + this.publicationTemplateSettingVariants["padding"]["horizontal"] + ";}";
|
|
241
265
|
for (let i = 0; i < nbColumn; i++) {
|
|
242
266
|
td += '.tdCol' + i + '{';
|
|
243
|
-
td +=
|
|
267
|
+
td +=
|
|
268
|
+
' width: ' +
|
|
269
|
+
this.publicationTemplateSettingVariants['headerRow'][i]['width'] +
|
|
270
|
+
';';
|
|
244
271
|
td +=
|
|
245
272
|
'text-align:' +
|
|
246
273
|
this.publicationTemplateSettingVariants['bodyRow'][i]['text']['alignment'] +
|
|
@@ -275,7 +302,8 @@ class DataSheet {
|
|
|
275
302
|
';';
|
|
276
303
|
td += '}';
|
|
277
304
|
}
|
|
278
|
-
this.publicationTemplateSettingVariantsTableStyle +=
|
|
305
|
+
this.publicationTemplateSettingVariantsTableStyle +=
|
|
306
|
+
tableStyle + th + td + '</style>';
|
|
279
307
|
}
|
|
280
308
|
catch (ex) {
|
|
281
309
|
//console.error(ex);
|
|
@@ -332,6 +360,11 @@ class DataSheetSingleton {
|
|
|
332
360
|
this.fields = [];
|
|
333
361
|
this.token = '';
|
|
334
362
|
this.apiUrl = '';
|
|
363
|
+
this.instanceId = Math.random();
|
|
364
|
+
this.gabarits = {};
|
|
365
|
+
this.backgrounds = {};
|
|
366
|
+
this.marketing = {};
|
|
367
|
+
//console.log('[DataSheetSingleton] Constructor called. instanceId:', this.instanceId);
|
|
335
368
|
}
|
|
336
369
|
static getInstance() {
|
|
337
370
|
if (!DataSheetSingleton.instance) {
|
|
@@ -339,6 +372,39 @@ class DataSheetSingleton {
|
|
|
339
372
|
}
|
|
340
373
|
return DataSheetSingleton.instance;
|
|
341
374
|
}
|
|
375
|
+
getGabarits(templateGuid) {
|
|
376
|
+
const cached = this.gabarits[templateGuid];
|
|
377
|
+
return cached ? [...cached] : null;
|
|
378
|
+
}
|
|
379
|
+
setGabarits(templateGuid, list) {
|
|
380
|
+
this.gabarits[templateGuid] = [...list];
|
|
381
|
+
}
|
|
382
|
+
getBackgrounds(templateGuid) {
|
|
383
|
+
const cached = this.backgrounds[templateGuid];
|
|
384
|
+
return cached ? [...cached] : null;
|
|
385
|
+
}
|
|
386
|
+
setBackgrounds(templateGuid, list) {
|
|
387
|
+
this.backgrounds[templateGuid] = [...list];
|
|
388
|
+
}
|
|
389
|
+
getMarketing(templateGuid) {
|
|
390
|
+
const cached = this.marketing[templateGuid];
|
|
391
|
+
return cached ? [...cached] : null;
|
|
392
|
+
}
|
|
393
|
+
setMarketing(templateGuid, list) {
|
|
394
|
+
this.marketing[templateGuid] = [...list];
|
|
395
|
+
}
|
|
396
|
+
clearTemplatesCache(templateGuid) {
|
|
397
|
+
if (templateGuid) {
|
|
398
|
+
delete this.gabarits[templateGuid];
|
|
399
|
+
delete this.backgrounds[templateGuid];
|
|
400
|
+
delete this.marketing[templateGuid];
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
this.gabarits = {};
|
|
404
|
+
this.backgrounds = {};
|
|
405
|
+
this.marketing = {};
|
|
406
|
+
}
|
|
407
|
+
}
|
|
342
408
|
async getAttributesByType(attributeType, attributeGroup = '') {
|
|
343
409
|
if (!this.token || !this.apiUrl) {
|
|
344
410
|
throw new Error('DataSheetSingleton: token or apiUrl not set');
|
|
@@ -399,6 +465,9 @@ class DataSheetSingleton {
|
|
|
399
465
|
this.attributes = [];
|
|
400
466
|
this.token = '';
|
|
401
467
|
this.apiUrl = '';
|
|
468
|
+
this.gabarits = {};
|
|
469
|
+
this.backgrounds = {};
|
|
470
|
+
this.marketing = {};
|
|
402
471
|
}
|
|
403
472
|
}
|
|
404
473
|
|
|
@@ -474,6 +543,10 @@ class DataSheetSVG {
|
|
|
474
543
|
let blockWidth = 0;
|
|
475
544
|
let aWidths = [];
|
|
476
545
|
let aHeightsRows = [];
|
|
546
|
+
let aGabaritMarginLefts = [];
|
|
547
|
+
let aGabaritMarginRights = [];
|
|
548
|
+
let aRowMarginTops = [];
|
|
549
|
+
let aRowMarginBottoms = [];
|
|
477
550
|
let firstGTag = true;
|
|
478
551
|
// for (let tag of allBackgroundTags) {
|
|
479
552
|
// if (tag.XmlTag?.localName === "g" && firstGTag) {
|
|
@@ -498,6 +571,92 @@ class DataSheetSVG {
|
|
|
498
571
|
if (true) {
|
|
499
572
|
// datasheet.asettemplatefile != ''
|
|
500
573
|
// pour jObject dans lstSkus
|
|
574
|
+
const gabaritDimCache = new Map();
|
|
575
|
+
const getBlockDimensionsAndMarginsCached = (jObj) => {
|
|
576
|
+
let defaultGabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
|
|
577
|
+
let gabaritName = jObj.gabaritName + '.svg';
|
|
578
|
+
let gabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.name == gabaritName);
|
|
579
|
+
if (gabarit == undefined || gabarit == null) {
|
|
580
|
+
gabarit = defaultGabarit;
|
|
581
|
+
}
|
|
582
|
+
if (gabarit == null || gabarit == undefined) {
|
|
583
|
+
gabarit = this.DataSheet.gabarits[0];
|
|
584
|
+
}
|
|
585
|
+
if (!gabarit) {
|
|
586
|
+
return {
|
|
587
|
+
width: 0,
|
|
588
|
+
height: 0,
|
|
589
|
+
marginTop: 0,
|
|
590
|
+
marginBottom: 0,
|
|
591
|
+
marginLeft: 0,
|
|
592
|
+
marginRight: 0,
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
const cacheKey = gabarit.guid || gabarit.name || '';
|
|
596
|
+
if (gabaritDimCache.has(cacheKey)) {
|
|
597
|
+
return gabaritDimCache.get(cacheKey);
|
|
598
|
+
}
|
|
599
|
+
const dim = this.getBlockDimensionsAndMargins(jObj);
|
|
600
|
+
gabaritDimCache.set(cacheKey, dim);
|
|
601
|
+
return dim;
|
|
602
|
+
};
|
|
603
|
+
const getRowInfo = (startIdx) => {
|
|
604
|
+
let idx = startIdx;
|
|
605
|
+
let widths = this.DataSheet.publicationTemplateBackgroundLeftMargin;
|
|
606
|
+
let maxBlockHeight = 0;
|
|
607
|
+
let maxMarginTop = 0;
|
|
608
|
+
let maxMarginBottom = 0;
|
|
609
|
+
let blocksInRow = [];
|
|
610
|
+
while (idx < lstSkus.length) {
|
|
611
|
+
let jObj = lstSkus[idx];
|
|
612
|
+
if (!jObj ||
|
|
613
|
+
jObj === '{}' ||
|
|
614
|
+
(jObj.sku == null &&
|
|
615
|
+
jObj.type !== 'LINEBREAK' &&
|
|
616
|
+
jObj.type !== 'PAGEBREAK')) {
|
|
617
|
+
idx++;
|
|
618
|
+
continue;
|
|
619
|
+
}
|
|
620
|
+
if (jObj.type === 'LINEBREAK' || jObj.type === 'PAGEBREAK') {
|
|
621
|
+
if (blocksInRow.length === 0) {
|
|
622
|
+
idx++;
|
|
623
|
+
}
|
|
624
|
+
break;
|
|
625
|
+
}
|
|
626
|
+
let dim = getBlockDimensionsAndMarginsCached(jObj);
|
|
627
|
+
let blockWidth = dim.width;
|
|
628
|
+
let gMarginLeft = dim.marginLeft;
|
|
629
|
+
let gMarginRight = dim.marginRight;
|
|
630
|
+
let currentWidths = widths;
|
|
631
|
+
if (blocksInRow.length > 0) {
|
|
632
|
+
let prevDim = blocksInRow[blocksInRow.length - 1];
|
|
633
|
+
currentWidths += prevDim.marginRight + gMarginLeft;
|
|
634
|
+
}
|
|
635
|
+
let rowTotalWidth = currentWidths + blockWidth;
|
|
636
|
+
if (blocksInRow.length > 0 &&
|
|
637
|
+
rowTotalWidth >
|
|
638
|
+
this.DataSheet.publicationTemplateBackgroundMarginX) {
|
|
639
|
+
break;
|
|
640
|
+
}
|
|
641
|
+
widths = currentWidths + blockWidth;
|
|
642
|
+
maxBlockHeight = Math.max(maxBlockHeight, dim.height);
|
|
643
|
+
maxMarginTop = Math.max(maxMarginTop, dim.marginTop);
|
|
644
|
+
maxMarginBottom = Math.max(maxMarginBottom, dim.marginBottom);
|
|
645
|
+
blocksInRow.push(dim);
|
|
646
|
+
idx++;
|
|
647
|
+
}
|
|
648
|
+
return {
|
|
649
|
+
nextStartIdx: idx,
|
|
650
|
+
maxHeight: maxBlockHeight,
|
|
651
|
+
maxMarginTop,
|
|
652
|
+
maxMarginBottom,
|
|
653
|
+
count: blocksInRow.length,
|
|
654
|
+
};
|
|
655
|
+
};
|
|
656
|
+
let currentIdx = 0;
|
|
657
|
+
let currentRowMaxHeight = 0;
|
|
658
|
+
let currentRowMaxMarginTop = 0;
|
|
659
|
+
let currentRowMaxMarginBottom = 0;
|
|
501
660
|
for (let jObject of lstSkus) {
|
|
502
661
|
// IF PREVIEW AND PREVIEWID != DATASHEET.PREVIEWID THEN CONTINUE
|
|
503
662
|
if (this.DataSheet.preview) {
|
|
@@ -506,77 +665,206 @@ class DataSheetSVG {
|
|
|
506
665
|
}
|
|
507
666
|
}
|
|
508
667
|
skipPart = false;
|
|
509
|
-
if (jObject != null &&
|
|
510
|
-
|
|
668
|
+
if (jObject != null &&
|
|
669
|
+
jObject != '{}' &&
|
|
670
|
+
(jObject.sku != null ||
|
|
671
|
+
jObject.type === 'LINEBREAK' ||
|
|
672
|
+
jObject.type === 'PAGEBREAK')) {
|
|
673
|
+
if (jObject.type === 'PAGEBREAK') {
|
|
674
|
+
AllTplProductsBlock += tplRowProductsBlocks;
|
|
675
|
+
tplRowProductsBlocks = '';
|
|
676
|
+
AllTplProductsBlock += this.addCuttingLine() + '</svg>';
|
|
677
|
+
this.DataSheet.leftPage = !this.DataSheet.leftPage;
|
|
678
|
+
backgroundTpl = this.DataSheet.leftPage
|
|
679
|
+
? backgroundTplRight
|
|
680
|
+
: backgroundTplLeft;
|
|
681
|
+
AllTplProductsBlock =
|
|
682
|
+
initDoc +
|
|
683
|
+
'<style>' +
|
|
684
|
+
this.DataSheet.importFontFamily.replace(/&/g, '&') +
|
|
685
|
+
this.DataSheet.defaultStyle +
|
|
686
|
+
'</style>' +
|
|
687
|
+
backgroundTpl +
|
|
688
|
+
AllTplProductsBlock;
|
|
689
|
+
AllTplProductsBlock =
|
|
690
|
+
this.CleanMissingFilters(AllTplProductsBlock);
|
|
691
|
+
let json = {
|
|
692
|
+
name: pathNewSvgFile + count + '].svg',
|
|
693
|
+
sectionId: sectionId,
|
|
694
|
+
svg: AllTplProductsBlock,
|
|
695
|
+
};
|
|
696
|
+
fileList.push(json);
|
|
697
|
+
AllTplProductsBlock = '';
|
|
698
|
+
aWidths = [];
|
|
699
|
+
aGabaritMarginLefts = [];
|
|
700
|
+
aGabaritMarginRights = [];
|
|
701
|
+
aHeightsRows = [];
|
|
702
|
+
aRowMarginTops = [];
|
|
703
|
+
aRowMarginBottoms = [];
|
|
704
|
+
count++;
|
|
705
|
+
nbRow = 0;
|
|
706
|
+
nbBlock = 0;
|
|
707
|
+
nbBlockInRow = 0;
|
|
708
|
+
this.DataSheet.progress +=
|
|
709
|
+
(50 / this.DataSheet.maxSections) *
|
|
710
|
+
0.8 *
|
|
711
|
+
(1 / this.DataSheet.maxSkusSection);
|
|
712
|
+
this.DataSheet.nbSkusSection++;
|
|
713
|
+
currentIdx++;
|
|
714
|
+
continue;
|
|
715
|
+
}
|
|
716
|
+
if (jObject.type === 'LINEBREAK') {
|
|
717
|
+
if (nbBlockInRow > 0) {
|
|
718
|
+
AllTplProductsBlock += tplRowProductsBlocks;
|
|
719
|
+
tplRowProductsBlocks = '';
|
|
720
|
+
const rowInfo = getRowInfo(currentIdx + 1);
|
|
721
|
+
currentRowMaxHeight = rowInfo.maxHeight;
|
|
722
|
+
currentRowMaxMarginTop = rowInfo.maxMarginTop;
|
|
723
|
+
currentRowMaxMarginBottom = rowInfo.maxMarginBottom;
|
|
724
|
+
nbRow++;
|
|
725
|
+
aHeightsRows.push(currentRowMaxHeight);
|
|
726
|
+
aRowMarginTops.push(currentRowMaxMarginTop);
|
|
727
|
+
aRowMarginBottoms.push(currentRowMaxMarginBottom);
|
|
728
|
+
nbBlockInRow = 0;
|
|
729
|
+
aWidths = [];
|
|
730
|
+
aGabaritMarginLefts = [];
|
|
731
|
+
aGabaritMarginRights = [];
|
|
732
|
+
}
|
|
733
|
+
this.DataSheet.progress +=
|
|
734
|
+
(50 / this.DataSheet.maxSections) *
|
|
735
|
+
0.8 *
|
|
736
|
+
(1 / this.DataSheet.maxSkusSection);
|
|
737
|
+
this.DataSheet.nbSkusSection++;
|
|
738
|
+
currentIdx++;
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
let defaultGabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
|
|
511
742
|
let gabaritName = jObject.gabaritName + '.svg';
|
|
512
|
-
let gabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.
|
|
743
|
+
let gabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.name == gabaritName);
|
|
513
744
|
if (gabarit == undefined || gabarit == null) {
|
|
514
745
|
gabarit = defaultGabarit;
|
|
515
746
|
}
|
|
516
747
|
if (gabarit == null || gabarit == undefined) {
|
|
517
748
|
gabarit = this.DataSheet.gabarits[0];
|
|
518
749
|
}
|
|
750
|
+
let firstRowTopMargin = 0;
|
|
751
|
+
let blockY = 0;
|
|
519
752
|
// Reset
|
|
520
753
|
this.DataSheet.variantTables = [];
|
|
521
754
|
this.DataSheet.variantTableFirstHeight = 0;
|
|
522
755
|
this.DataSheet.variantTableLastHeight = 0;
|
|
523
|
-
this.DataSheet.assetTemplatePathFile = gabarit.
|
|
756
|
+
this.DataSheet.assetTemplatePathFile = gabarit.pathFile;
|
|
524
757
|
this.DataSheet.publicationTemplateSettingVariants =
|
|
525
|
-
gabarit.
|
|
758
|
+
gabarit.settingVariants;
|
|
526
759
|
this.DataSheet.publicationTemplateProductBlockWidth = !isNaN(gabarit.width)
|
|
527
|
-
? parseFloat(gabarit.width)
|
|
760
|
+
? parseFloat(gabarit.width.toString())
|
|
528
761
|
: 0;
|
|
529
762
|
if (jObject != '{}') {
|
|
530
763
|
let tplProductBlock = gabarit.svgImage;
|
|
531
764
|
//tplProductBlock = tplProductBlock.replace('<svg', `<svg "`);
|
|
532
765
|
let allTags = this.GetSvgGroupToReplace(tplProductBlock);
|
|
533
766
|
let blocksHeight = 0;
|
|
534
|
-
let blockTag = allTags.find((x) => x.IdTag
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
blocksHeight += aHeightsRows[i];
|
|
539
|
-
}
|
|
540
|
-
if (nbBlockInRow >=
|
|
541
|
-
this.DataSheet.publicationTemplateBackgroundMarginX /
|
|
542
|
-
blockWidth) {
|
|
543
|
-
blocksHeight += aHeightsRows[aHeightsRows.length - 1];
|
|
544
|
-
}
|
|
545
|
-
blocksHeight =
|
|
546
|
-
this.DataSheet.publicationTemplateProductBlockY +
|
|
547
|
-
blocksHeight;
|
|
767
|
+
let blockTag = allTags.find((x) => x.IdTag && x.IdTag.toLowerCase() === 'block');
|
|
768
|
+
if (blockTag) {
|
|
769
|
+
blockHeight = parseFloat(blockTag.Height);
|
|
770
|
+
blockWidth = parseFloat(blockTag.Width);
|
|
548
771
|
}
|
|
549
772
|
else {
|
|
550
|
-
|
|
773
|
+
blockHeight = gabarit.height
|
|
774
|
+
? parseFloat(gabarit.height.toString())
|
|
775
|
+
: 0;
|
|
776
|
+
blockWidth = gabarit.width
|
|
777
|
+
? parseFloat(gabarit.width.toString())
|
|
778
|
+
: 0;
|
|
551
779
|
}
|
|
552
|
-
|
|
780
|
+
const gMarginLeft = gabarit.leftMargin || 0;
|
|
781
|
+
const gMarginRight = gabarit.rightMargin || 0;
|
|
782
|
+
let widths = this.DataSheet.publicationTemplateBackgroundLeftMargin;
|
|
783
|
+
for (let i = 0; i < nbBlockInRow; i++) {
|
|
784
|
+
widths +=
|
|
785
|
+
aWidths[i] +
|
|
786
|
+
aGabaritMarginRights[i] +
|
|
787
|
+
aGabaritMarginLefts[i + 1];
|
|
788
|
+
}
|
|
789
|
+
let RowTotalWidth = widths + blockWidth - (nbBlockInRow > 0 ? gMarginLeft : 0);
|
|
790
|
+
const willWrap = RowTotalWidth >
|
|
791
|
+
this.DataSheet.publicationTemplateBackgroundMarginX &&
|
|
792
|
+
RowTotalWidth != 0;
|
|
793
|
+
let heights = 0;
|
|
794
|
+
for (let i = 0; i < nbRow; i++) {
|
|
795
|
+
const rHeight = aHeightsRows[i] || 0;
|
|
796
|
+
const rMarginBottom = aRowMarginBottoms[i] || 0;
|
|
797
|
+
const rMarginTopNext = aRowMarginTops[i + 1] || 0;
|
|
798
|
+
heights += rHeight + rMarginBottom + rMarginTopNext;
|
|
799
|
+
}
|
|
800
|
+
const headerShift = this.DataSheet.publicationTemplateBackgroundHeightHeader;
|
|
801
|
+
const gMarginTop = gabarit.headerHeight || 0;
|
|
802
|
+
let currentBlockYTop = 0;
|
|
803
|
+
if (willWrap) {
|
|
804
|
+
const nextRowHeights = heights +
|
|
805
|
+
(aHeightsRows[nbRow] || 0) +
|
|
806
|
+
(aRowMarginBottoms[nbRow] || 0) +
|
|
807
|
+
gMarginTop;
|
|
808
|
+
currentBlockYTop = headerShift + nextRowHeights;
|
|
809
|
+
}
|
|
810
|
+
else {
|
|
811
|
+
currentBlockYTop = headerShift + heights;
|
|
812
|
+
}
|
|
813
|
+
const currentBlockYBottom = currentBlockYTop + blockHeight;
|
|
814
|
+
if (currentBlockYBottom >
|
|
553
815
|
this.DataSheet.publicationTemplateBackgroundFooterY) {
|
|
554
816
|
blocksHeight = 0;
|
|
555
817
|
}
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
let
|
|
561
|
-
|
|
562
|
-
|
|
818
|
+
else {
|
|
819
|
+
let blockY = this.DataSheet.GetBlockY(allTags);
|
|
820
|
+
blocksHeight = currentBlockYTop + blockY;
|
|
821
|
+
}
|
|
822
|
+
let newTplGroup = await this.GenerateProductBlock(tplProductBlock, gabarit.templateGuid, gabarit.guid, jObject, allTags, blocksHeight, nbBlockInRow);
|
|
823
|
+
blockTag = allTags.find((x) => x.IdTag && x.IdTag.toLowerCase() === 'block');
|
|
824
|
+
if (blockTag) {
|
|
825
|
+
blockHeight = parseFloat(blockTag.Height);
|
|
826
|
+
blockWidth = parseFloat(blockTag.Width);
|
|
827
|
+
}
|
|
828
|
+
else {
|
|
829
|
+
blockHeight = gabarit.height
|
|
830
|
+
? parseFloat(gabarit.height.toString())
|
|
831
|
+
: 0;
|
|
832
|
+
blockWidth = gabarit.width
|
|
833
|
+
? parseFloat(gabarit.width.toString())
|
|
834
|
+
: 0;
|
|
835
|
+
}
|
|
836
|
+
blockY = this.DataSheet.GetBlockY(allTags);
|
|
837
|
+
let allBlockHeight = 0;
|
|
838
|
+
heights = 0;
|
|
839
|
+
for (let i = 0; i < nbRow; i++) {
|
|
840
|
+
const rHeight = aHeightsRows[i] || 0;
|
|
841
|
+
const rMarginBottom = aRowMarginBottoms[i] || 0;
|
|
842
|
+
const rMarginTopNext = aRowMarginTops[i + 1] || 0;
|
|
843
|
+
heights += rHeight + rMarginBottom + rMarginTopNext;
|
|
844
|
+
}
|
|
845
|
+
let totalYShift = headerShift + heights - blockY;
|
|
846
|
+
if (totalYShift !== 0) {
|
|
847
|
+
newTplGroup = this.ChangeAllYBis(newTplGroup, totalYShift);
|
|
563
848
|
}
|
|
564
849
|
this.DataSheet.publicationTemplateProductBlockY =
|
|
565
850
|
blockY +
|
|
566
851
|
this.DataSheet.publicationTemplateBackgroundHeightHeader;
|
|
852
|
+
const gMarginBottom = gabarit.footerHeight || 0;
|
|
567
853
|
allTags = [];
|
|
568
854
|
aWidths.push(blockWidth);
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
let
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
widths += aWidths[i];
|
|
578
|
-
}
|
|
855
|
+
aGabaritMarginLefts.push(gMarginLeft);
|
|
856
|
+
aGabaritMarginRights.push(gMarginRight);
|
|
857
|
+
widths = this.DataSheet.publicationTemplateBackgroundLeftMargin;
|
|
858
|
+
for (let i = 0; i < nbBlockInRow; i++) {
|
|
859
|
+
widths +=
|
|
860
|
+
aWidths[i] +
|
|
861
|
+
aGabaritMarginRights[i] +
|
|
862
|
+
aGabaritMarginLefts[i + 1];
|
|
579
863
|
}
|
|
864
|
+
RowTotalWidth =
|
|
865
|
+
widths +
|
|
866
|
+
aWidths[nbBlockInRow] -
|
|
867
|
+
(nbBlockInRow > 0 ? gMarginLeft : 0);
|
|
580
868
|
// Check how many table variants are presents in the product block
|
|
581
869
|
const pattern = /<foreignObject id="tableVariant".*?<\/foreignObject>/gs;
|
|
582
870
|
const matches = newTplGroup.match(pattern);
|
|
@@ -605,44 +893,65 @@ class DataSheetSVG {
|
|
|
605
893
|
}
|
|
606
894
|
newTplGroup = this.ChangeAllYBis(newTplGroup, heights);
|
|
607
895
|
}
|
|
896
|
+
newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
|
|
608
897
|
tplRowProductsBlocks += newTplGroup;
|
|
609
898
|
if (aHeightsRows.length == 0) {
|
|
610
899
|
aHeightsRows.push(blockHeight);
|
|
900
|
+
aRowMarginTops.push(gMarginTop);
|
|
901
|
+
aRowMarginBottoms.push(gMarginBottom);
|
|
611
902
|
}
|
|
612
|
-
else
|
|
613
|
-
aHeightsRows[nbRow]
|
|
903
|
+
else {
|
|
904
|
+
if (aHeightsRows[nbRow] < blockHeight) {
|
|
905
|
+
aHeightsRows[nbRow] = blockHeight;
|
|
906
|
+
}
|
|
907
|
+
if (aRowMarginTops[nbRow] < gMarginTop) {
|
|
908
|
+
aRowMarginTops[nbRow] = gMarginTop;
|
|
909
|
+
}
|
|
910
|
+
if (aRowMarginBottoms[nbRow] < gMarginBottom) {
|
|
911
|
+
aRowMarginBottoms[nbRow] = gMarginBottom;
|
|
912
|
+
}
|
|
614
913
|
}
|
|
615
914
|
nbBlockInRow++;
|
|
616
915
|
nbBlock++;
|
|
617
916
|
widths += blockWidth;
|
|
618
917
|
aWidths.push(blockWidth);
|
|
918
|
+
aGabaritMarginLefts.push(gMarginLeft);
|
|
919
|
+
aGabaritMarginRights.push(gMarginRight);
|
|
619
920
|
}
|
|
620
921
|
else if (RowTotalWidth != 0) {
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
heights += aHeightsRows[j];
|
|
627
|
-
}
|
|
628
|
-
}
|
|
922
|
+
const newRowHeights = heights +
|
|
923
|
+
(aHeightsRows[nbRow] || 0) +
|
|
924
|
+
(aRowMarginBottoms[nbRow] || 0) +
|
|
925
|
+
gMarginTop;
|
|
926
|
+
blockY = this.DataSheet.GetBlockY(allTags);
|
|
629
927
|
allBlockHeight =
|
|
630
928
|
this.DataSheet.publicationTemplateProductBlockY +
|
|
631
|
-
|
|
632
|
-
this.DataSheet.variantTableFirstHeight
|
|
633
|
-
|
|
634
|
-
|
|
929
|
+
newRowHeights +
|
|
930
|
+
this.DataSheet.variantTableFirstHeight -
|
|
931
|
+
blockY;
|
|
932
|
+
if ((allBlockHeight <=
|
|
933
|
+
this.DataSheet.publicationTemplateBackgroundFooterY ||
|
|
934
|
+
nbRow === 0) &&
|
|
635
935
|
allBlockHeight != 0 &&
|
|
636
936
|
i == 0) {
|
|
937
|
+
const diffY = newRowHeights - heights;
|
|
938
|
+
heights = newRowHeights;
|
|
637
939
|
newTplGroup = this.ChangeAllIdsGroup(newTplGroup, nbBlock);
|
|
638
|
-
newTplGroup = this.ChangeAllYBis(newTplGroup,
|
|
940
|
+
newTplGroup = this.ChangeAllYBis(newTplGroup, diffY);
|
|
639
941
|
newTplGroup = this.ChangeAllX(newTplGroup, nbBlockInRow, this.DataSheet.publicationTemplateBackgroundLeftMargin);
|
|
640
942
|
AllTplProductsBlock += tplRowProductsBlocks;
|
|
943
|
+
newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
|
|
641
944
|
tplRowProductsBlocks = newTplGroup;
|
|
642
945
|
aWidths = [];
|
|
643
946
|
aWidths.push(blockWidth);
|
|
947
|
+
aGabaritMarginLefts = [];
|
|
948
|
+
aGabaritMarginLefts.push(gMarginLeft);
|
|
949
|
+
aGabaritMarginRights = [];
|
|
950
|
+
aGabaritMarginRights.push(gMarginRight);
|
|
644
951
|
nbRow++;
|
|
645
952
|
aHeightsRows.push(this.DataSheet.variantTableFirstHeight);
|
|
953
|
+
aRowMarginTops.push(gMarginTop);
|
|
954
|
+
aRowMarginBottoms.push(gMarginBottom);
|
|
646
955
|
}
|
|
647
956
|
// Go on a new page (314)
|
|
648
957
|
else {
|
|
@@ -669,12 +978,22 @@ class DataSheetSVG {
|
|
|
669
978
|
};
|
|
670
979
|
fileList.push(json);
|
|
671
980
|
newTplGroup = this.ChangeAllX(newTplGroup, nbBlockInRow, this.DataSheet.publicationTemplateBackgroundLeftMargin);
|
|
981
|
+
newTplGroup = this.ChangeAllYBis(newTplGroup, -heights);
|
|
672
982
|
AllTplProductsBlock = '';
|
|
983
|
+
newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
|
|
673
984
|
tplRowProductsBlocks = newTplGroup;
|
|
674
985
|
aWidths = [];
|
|
675
986
|
aWidths.push(blockWidth);
|
|
987
|
+
aGabaritMarginLefts = [];
|
|
988
|
+
aGabaritMarginLefts.push(gMarginLeft);
|
|
989
|
+
aGabaritMarginRights = [];
|
|
990
|
+
aGabaritMarginRights.push(gMarginRight);
|
|
676
991
|
aHeightsRows = [];
|
|
677
992
|
aHeightsRows.push(blockHeight);
|
|
993
|
+
aRowMarginTops = [];
|
|
994
|
+
aRowMarginTops.push(gMarginTop);
|
|
995
|
+
aRowMarginBottoms = [];
|
|
996
|
+
aRowMarginBottoms.push(gMarginBottom);
|
|
678
997
|
count++;
|
|
679
998
|
nbRow = 0;
|
|
680
999
|
nbBlock = 0;
|
|
@@ -701,49 +1020,70 @@ class DataSheetSVG {
|
|
|
701
1020
|
RowTotalWidth != 0) {
|
|
702
1021
|
newTplGroup = this.ChangeAllIdsGroup(newTplGroup, nbBlock);
|
|
703
1022
|
newTplGroup = this.ChangeAllX(newTplGroup, nbBlockInRow, widths);
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
if (i < nbRow) {
|
|
707
|
-
heights += aHeightsRows[i];
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
newTplGroup = this.ChangeAllYBis(newTplGroup, heights);
|
|
711
|
-
}
|
|
1023
|
+
// Shift is already handled on line 374
|
|
1024
|
+
newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
|
|
712
1025
|
tplRowProductsBlocks += newTplGroup;
|
|
713
1026
|
if (aHeightsRows.length == 0) {
|
|
714
|
-
|
|
1027
|
+
const rowInfo = getRowInfo(currentIdx);
|
|
1028
|
+
currentRowMaxHeight = rowInfo.maxHeight;
|
|
1029
|
+
currentRowMaxMarginTop = rowInfo.maxMarginTop;
|
|
1030
|
+
currentRowMaxMarginBottom = rowInfo.maxMarginBottom;
|
|
1031
|
+
aHeightsRows.push(currentRowMaxHeight);
|
|
1032
|
+
aRowMarginTops.push(currentRowMaxMarginTop);
|
|
1033
|
+
aRowMarginBottoms.push(currentRowMaxMarginBottom);
|
|
715
1034
|
}
|
|
716
|
-
else
|
|
717
|
-
aHeightsRows[nbRow]
|
|
1035
|
+
else {
|
|
1036
|
+
if (aHeightsRows[nbRow] < blockHeight) {
|
|
1037
|
+
aHeightsRows[nbRow] = blockHeight;
|
|
1038
|
+
}
|
|
1039
|
+
if (aRowMarginTops[nbRow] < gMarginTop) {
|
|
1040
|
+
aRowMarginTops[nbRow] = gMarginTop;
|
|
1041
|
+
}
|
|
1042
|
+
if (aRowMarginBottoms[nbRow] < gMarginBottom) {
|
|
1043
|
+
aRowMarginBottoms[nbRow] = gMarginBottom;
|
|
1044
|
+
}
|
|
718
1045
|
}
|
|
719
1046
|
nbBlockInRow++;
|
|
720
1047
|
}
|
|
721
1048
|
else if (RowTotalWidth != 0) {
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
1049
|
+
const rowInfo = getRowInfo(currentIdx);
|
|
1050
|
+
const currentRowMaxHeight = rowInfo.maxHeight;
|
|
1051
|
+
const currentRowMaxMarginTop = rowInfo.maxMarginTop;
|
|
1052
|
+
const currentRowMaxMarginBottom = rowInfo.maxMarginBottom;
|
|
1053
|
+
const newRowHeights = heights +
|
|
1054
|
+
(aHeightsRows[nbRow] || 0) +
|
|
1055
|
+
(aRowMarginBottoms[nbRow] || 0) +
|
|
1056
|
+
currentRowMaxMarginTop;
|
|
730
1057
|
allBlockHeight =
|
|
731
1058
|
this.DataSheet.publicationTemplateProductBlockY +
|
|
732
|
-
|
|
733
|
-
|
|
1059
|
+
newRowHeights +
|
|
1060
|
+
currentRowMaxHeight -
|
|
1061
|
+
blockY;
|
|
734
1062
|
// Go on a new line (401)
|
|
735
|
-
if (allBlockHeight <=
|
|
736
|
-
this.DataSheet.publicationTemplateBackgroundFooterY
|
|
1063
|
+
if ((allBlockHeight <=
|
|
1064
|
+
this.DataSheet.publicationTemplateBackgroundFooterY ||
|
|
1065
|
+
nbRow === 0) &&
|
|
737
1066
|
allBlockHeight != 0) {
|
|
1067
|
+
const diffY = newRowHeights - heights;
|
|
1068
|
+
heights = newRowHeights;
|
|
738
1069
|
newTplGroup = this.ChangeAllIdsGroup(newTplGroup, nbBlock);
|
|
739
|
-
newTplGroup = this.ChangeAllYBis(newTplGroup,
|
|
740
|
-
newTplGroup = this.ChangeAllX(newTplGroup,
|
|
1070
|
+
newTplGroup = this.ChangeAllYBis(newTplGroup, diffY);
|
|
1071
|
+
newTplGroup = this.ChangeAllX(newTplGroup, 0, this.DataSheet.publicationTemplateBackgroundLeftMargin);
|
|
741
1072
|
AllTplProductsBlock += tplRowProductsBlocks;
|
|
1073
|
+
newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
|
|
742
1074
|
tplRowProductsBlocks = newTplGroup;
|
|
743
1075
|
aWidths = [];
|
|
744
1076
|
aWidths.push(blockWidth);
|
|
1077
|
+
aGabaritMarginLefts = [];
|
|
1078
|
+
aGabaritMarginLefts.push(gMarginLeft);
|
|
1079
|
+
aGabaritMarginRights = [];
|
|
1080
|
+
aGabaritMarginRights.push(gMarginRight);
|
|
745
1081
|
nbRow++;
|
|
746
|
-
aHeightsRows.push(
|
|
1082
|
+
aHeightsRows.push(currentRowMaxHeight);
|
|
1083
|
+
aRowMarginTops.push(currentRowMaxMarginTop);
|
|
1084
|
+
aRowMarginBottoms.push(currentRowMaxMarginBottom);
|
|
1085
|
+
nbBlockInRow = 0;
|
|
1086
|
+
nbBlock++;
|
|
747
1087
|
}
|
|
748
1088
|
// Go on a new page (418)
|
|
749
1089
|
else if (allBlockHeight != 0) {
|
|
@@ -769,18 +1109,30 @@ class DataSheetSVG {
|
|
|
769
1109
|
svg: AllTplProductsBlock,
|
|
770
1110
|
};
|
|
771
1111
|
fileList.push(json);
|
|
772
|
-
newTplGroup = this.ChangeAllX(newTplGroup,
|
|
1112
|
+
newTplGroup = this.ChangeAllX(newTplGroup, 0, this.DataSheet.publicationTemplateBackgroundLeftMargin);
|
|
1113
|
+
newTplGroup = this.ChangeAllYBis(newTplGroup, -heights);
|
|
773
1114
|
AllTplProductsBlock = '';
|
|
1115
|
+
newTplGroup = this.wrapTemplateGroup(newTplGroup, jObject, gabarit, nbBlock);
|
|
774
1116
|
tplRowProductsBlocks = newTplGroup;
|
|
775
1117
|
aWidths = [];
|
|
776
1118
|
aWidths.push(blockWidth);
|
|
1119
|
+
aGabaritMarginLefts = [];
|
|
1120
|
+
aGabaritMarginLefts.push(gMarginLeft);
|
|
1121
|
+
aGabaritMarginRights = [];
|
|
1122
|
+
aGabaritMarginRights.push(gMarginRight);
|
|
777
1123
|
aHeightsRows = [];
|
|
778
|
-
aHeightsRows.push(
|
|
1124
|
+
aHeightsRows.push(currentRowMaxHeight);
|
|
1125
|
+
aRowMarginTops = [];
|
|
1126
|
+
aRowMarginTops.push(currentRowMaxMarginTop);
|
|
1127
|
+
aRowMarginBottoms = [];
|
|
1128
|
+
aRowMarginBottoms.push(currentRowMaxMarginBottom);
|
|
779
1129
|
count++;
|
|
780
1130
|
nbRow = 0;
|
|
781
1131
|
nbBlock = 0;
|
|
1132
|
+
nbBlockInRow = 0;
|
|
782
1133
|
}
|
|
783
1134
|
nbBlockInRow = 0;
|
|
1135
|
+
nbBlock++;
|
|
784
1136
|
}
|
|
785
1137
|
else {
|
|
786
1138
|
console.log('[ERROR] RowTotalWidth is 0, this should not happen.');
|
|
@@ -807,6 +1159,7 @@ class DataSheetSVG {
|
|
|
807
1159
|
0.8 *
|
|
808
1160
|
(1 / this.DataSheet.maxSkusSection);
|
|
809
1161
|
this.DataSheet.nbSkusSection++;
|
|
1162
|
+
currentIdx++;
|
|
810
1163
|
}
|
|
811
1164
|
}
|
|
812
1165
|
AllTplProductsBlock +=
|
|
@@ -837,6 +1190,56 @@ class DataSheetSVG {
|
|
|
837
1190
|
return [];
|
|
838
1191
|
}
|
|
839
1192
|
}
|
|
1193
|
+
getBlockDimensionsAndMargins(jObject) {
|
|
1194
|
+
let defaultGabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.guid == this.DataSheet.defaultGabaritGuid);
|
|
1195
|
+
let gabaritName = jObject.gabaritName + '.svg';
|
|
1196
|
+
let gabarit = this.DataSheet.gabarits.find((gabarit) => gabarit.name == gabaritName);
|
|
1197
|
+
if (gabarit == undefined || gabarit == null) {
|
|
1198
|
+
gabarit = defaultGabarit;
|
|
1199
|
+
}
|
|
1200
|
+
if (gabarit == null || gabarit == undefined) {
|
|
1201
|
+
gabarit = this.DataSheet.gabarits[0];
|
|
1202
|
+
}
|
|
1203
|
+
if (!gabarit) {
|
|
1204
|
+
return {
|
|
1205
|
+
width: 0,
|
|
1206
|
+
height: 0,
|
|
1207
|
+
marginTop: 0,
|
|
1208
|
+
marginBottom: 0,
|
|
1209
|
+
marginLeft: 0,
|
|
1210
|
+
marginRight: 0,
|
|
1211
|
+
};
|
|
1212
|
+
}
|
|
1213
|
+
let blockHeight = 0;
|
|
1214
|
+
let blockWidth = 0;
|
|
1215
|
+
let tplProductBlock = gabarit.svgImage;
|
|
1216
|
+
if (tplProductBlock) {
|
|
1217
|
+
let allTags = this.GetSvgGroupToReplace(tplProductBlock);
|
|
1218
|
+
let blockTag = allTags.find((x) => x.IdTag && x.IdTag.toLowerCase() === 'block');
|
|
1219
|
+
if (blockTag) {
|
|
1220
|
+
blockHeight = parseFloat(blockTag.Height);
|
|
1221
|
+
blockWidth = parseFloat(blockTag.Width);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
if (!blockHeight) {
|
|
1225
|
+
blockHeight = gabarit.height ? parseFloat(gabarit.height.toString()) : 0;
|
|
1226
|
+
}
|
|
1227
|
+
if (!blockWidth) {
|
|
1228
|
+
blockWidth = gabarit.width ? parseFloat(gabarit.width.toString()) : 0;
|
|
1229
|
+
}
|
|
1230
|
+
const marginTop = gabarit.headerHeight || 0;
|
|
1231
|
+
const marginBottom = gabarit.footerHeight || 0;
|
|
1232
|
+
const marginLeft = gabarit.leftMargin || 0;
|
|
1233
|
+
const marginRight = gabarit.rightMargin || 0;
|
|
1234
|
+
return {
|
|
1235
|
+
width: blockWidth,
|
|
1236
|
+
height: blockHeight,
|
|
1237
|
+
marginTop,
|
|
1238
|
+
marginBottom,
|
|
1239
|
+
marginLeft,
|
|
1240
|
+
marginRight,
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
840
1243
|
async GenerateProductBlock(tplProductBlock, templateGuid, publicationTemplateGuid, product, allTags = null, blocksHeight = 0, nbBlockInRow = 0, keepAttributes = false) {
|
|
841
1244
|
if (allTags == null)
|
|
842
1245
|
allTags = this.GetSvgGroupToReplace(tplProductBlock);
|
|
@@ -909,16 +1312,70 @@ class DataSheetSVG {
|
|
|
909
1312
|
}
|
|
910
1313
|
}
|
|
911
1314
|
RemoveUnwantedSVGTags(svgContent) {
|
|
1315
|
+
let svgId = '';
|
|
1316
|
+
const svgIdMatch = svgContent.match(/<svg[^>]*?id="([^"]+)"/i);
|
|
1317
|
+
if (svgIdMatch) {
|
|
1318
|
+
svgId = svgIdMatch[1];
|
|
1319
|
+
}
|
|
1320
|
+
else {
|
|
1321
|
+
const styleIdMatch = svgContent.match(/<style[^>]*?id="style-([^"]+)"/i);
|
|
1322
|
+
if (styleIdMatch) {
|
|
1323
|
+
svgId = styleIdMatch[1];
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
912
1326
|
const match = svgContent.match(/^<svg[\s\S]*?>([\s\S]*?)<\/svg>/);
|
|
913
1327
|
if (match && match[1]) {
|
|
914
1328
|
svgContent = match[1];
|
|
915
1329
|
svgContent = svgContent.replace(/<style[\s\S]*?<\/style>/, '');
|
|
916
1330
|
}
|
|
1331
|
+
if (svgId) {
|
|
1332
|
+
svgContent = svgContent.replace(/<g(?![^>]*?id=)/i, `<g id="${svgId}"`);
|
|
1333
|
+
}
|
|
917
1334
|
svgContent = svgContent.replace(/<g xmlns="http:\/\/www\.w3\.org\/2000\/svg">/gs, '<g>');
|
|
918
1335
|
svgContent = svgContent.replace(/<\/g>/gs, '</g>');
|
|
919
1336
|
svgContent = svgContent.replace(/<title.*?>Layer 1.*?<\/title>/gs, '');
|
|
920
1337
|
return svgContent;
|
|
921
1338
|
}
|
|
1339
|
+
getAttributeFromSvg(svg, attrName) {
|
|
1340
|
+
if (!svg)
|
|
1341
|
+
return '';
|
|
1342
|
+
const regex = new RegExp(`<svg[^>]*?\\b${attrName}=["']([^"']+)["']`, 'i');
|
|
1343
|
+
const match = svg.match(regex);
|
|
1344
|
+
return match ? match[1] : '';
|
|
1345
|
+
}
|
|
1346
|
+
wrapTemplateGroup(tplGroup, jObject, gabarit, nbBlock) {
|
|
1347
|
+
if (!tplGroup)
|
|
1348
|
+
return tplGroup;
|
|
1349
|
+
let skuGuid = jObject?.skuguid || '';
|
|
1350
|
+
if (!skuGuid || skuGuid === '00000000-0000-0000-0000-000000000000') {
|
|
1351
|
+
skuGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-skuGuid');
|
|
1352
|
+
}
|
|
1353
|
+
let skuRef = jObject?.sku || '';
|
|
1354
|
+
if (!skuRef) {
|
|
1355
|
+
skuRef = this.getAttributeFromSvg(gabarit?.svgImage, 'data-sku');
|
|
1356
|
+
}
|
|
1357
|
+
let templateGuid = gabarit?.templateGuid || '';
|
|
1358
|
+
if (!templateGuid ||
|
|
1359
|
+
templateGuid === '00000000-0000-0000-0000-000000000000') {
|
|
1360
|
+
templateGuid = this.DataSheet?.publicationTemplateTemplateGuid || '';
|
|
1361
|
+
}
|
|
1362
|
+
if (!templateGuid ||
|
|
1363
|
+
templateGuid === '00000000-0000-0000-0000-000000000000') {
|
|
1364
|
+
templateGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-templateGuid');
|
|
1365
|
+
}
|
|
1366
|
+
let assetGuid = gabarit?.templateGuid || '';
|
|
1367
|
+
if (!assetGuid || assetGuid === '00000000-0000-0000-0000-000000000000') {
|
|
1368
|
+
assetGuid = this.DataSheet?.publicationTemplateTemplateGuid || '';
|
|
1369
|
+
}
|
|
1370
|
+
if (!assetGuid || assetGuid === '00000000-0000-0000-0000-000000000000') {
|
|
1371
|
+
assetGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-assetGuid');
|
|
1372
|
+
}
|
|
1373
|
+
let blockGuid = gabarit?.guid || '';
|
|
1374
|
+
if (!blockGuid || blockGuid === '00000000-0000-0000-0000-000000000000') {
|
|
1375
|
+
blockGuid = this.getAttributeFromSvg(gabarit?.svgImage, 'data-blockGuid');
|
|
1376
|
+
}
|
|
1377
|
+
return `<g data-type="template" id="template_${nbBlock + 1}" data-skuGuid="${skuGuid}" data-sku="${skuRef}" data-assetGuid="${assetGuid}" data-templateGuid="${templateGuid}" data-blockGuid="${blockGuid}">${tplGroup}</g>`;
|
|
1378
|
+
}
|
|
922
1379
|
CleanMissingFilters(svgContent) {
|
|
923
1380
|
const filterRegex = /filter="url\(#([^"]+)\)"/g;
|
|
924
1381
|
let filterMatch;
|
|
@@ -2877,24 +3334,43 @@ class DataSheetSVG {
|
|
|
2877
3334
|
}
|
|
2878
3335
|
const attrObj = jRowSku['attributeObject'] || [];
|
|
2879
3336
|
const attrPub = jRowSku['attributePublication'] || [];
|
|
2880
|
-
|
|
3337
|
+
let checkKey = field && jRowSku.hasOwnProperty(field) ? field : idVal;
|
|
3338
|
+
let hasValidProp = false;
|
|
3339
|
+
if (((field && jRowSku.hasOwnProperty(field)) ||
|
|
3340
|
+
(idVal && jRowSku.hasOwnProperty(idVal))) &&
|
|
2881
3341
|
!idVal.toLowerCase().includes('sku images') &&
|
|
2882
3342
|
(tag == null || tag.Image == false)) {
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
3343
|
+
let val = jRowSku[checkKey];
|
|
3344
|
+
if (val !== null &&
|
|
3345
|
+
val !== undefined &&
|
|
3346
|
+
val !== '' &&
|
|
3347
|
+
(!Array.isArray(val) || val.length > 0)) {
|
|
3348
|
+
hasValidProp = true;
|
|
2888
3349
|
}
|
|
2889
3350
|
}
|
|
3351
|
+
if (hasValidProp) {
|
|
3352
|
+
newVal = jRowSku[checkKey];
|
|
3353
|
+
}
|
|
2890
3354
|
else if (tag != null && tag.Image == true) {
|
|
2891
3355
|
let index = parseInt(tag.XmlTag.getAttribute('number'));
|
|
2892
|
-
|
|
2893
|
-
|
|
3356
|
+
let key = field && jRowSku[field] != null ? field : idVal;
|
|
3357
|
+
if (jRowSku[key] != null &&
|
|
3358
|
+
(!Array.isArray(jRowSku[key]) || jRowSku[key].length > 0)) {
|
|
3359
|
+
newVal = jRowSku[key];
|
|
2894
3360
|
let valuePairs = new Map();
|
|
2895
3361
|
let i = 0;
|
|
2896
|
-
|
|
2897
|
-
|
|
3362
|
+
let assetsArray = [];
|
|
3363
|
+
if (Array.isArray(newVal)) {
|
|
3364
|
+
assetsArray = newVal.map((val) => String(val ?? ''));
|
|
3365
|
+
}
|
|
3366
|
+
else if (typeof newVal === 'string') {
|
|
3367
|
+
assetsArray = newVal.split('#');
|
|
3368
|
+
}
|
|
3369
|
+
else if (newVal != null) {
|
|
3370
|
+
assetsArray = [String(newVal)];
|
|
3371
|
+
}
|
|
3372
|
+
assetsArray.forEach((asset) => {
|
|
3373
|
+
if (asset && asset.trim() !== '') {
|
|
2898
3374
|
valuePairs.set(i, asset);
|
|
2899
3375
|
i += 1;
|
|
2900
3376
|
}
|
|
@@ -2916,16 +3392,38 @@ class DataSheetSVG {
|
|
|
2916
3392
|
}
|
|
2917
3393
|
}
|
|
2918
3394
|
}
|
|
2919
|
-
else if (attrObj.
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
3395
|
+
else if (attrObj.find((x) => {
|
|
3396
|
+
if (!x)
|
|
3397
|
+
return false;
|
|
3398
|
+
const keys = Object.keys(x).map((k) => k.toUpperCase());
|
|
3399
|
+
return ((field && keys.includes(field.toUpperCase())) ||
|
|
3400
|
+
(idVal && keys.includes(idVal.toUpperCase())));
|
|
3401
|
+
}) != null) {
|
|
3402
|
+
let foundObj = attrObj.find((x) => {
|
|
3403
|
+
if (!x)
|
|
3404
|
+
return false;
|
|
3405
|
+
const keys = Object.keys(x).map((k) => k.toUpperCase());
|
|
3406
|
+
return ((field && keys.includes(field.toUpperCase())) ||
|
|
3407
|
+
(idVal && keys.includes(idVal.toUpperCase())));
|
|
3408
|
+
});
|
|
3409
|
+
const matchedKey = Object.keys(foundObj).find((k) => (field && k.toUpperCase() === field.toUpperCase()) ||
|
|
3410
|
+
(idVal && k.toUpperCase() === idVal.toUpperCase()));
|
|
3411
|
+
newVal = matchedKey ? foundObj[matchedKey] : '';
|
|
2924
3412
|
let valuePairs = new Map();
|
|
2925
3413
|
let i = 0;
|
|
2926
3414
|
if (newVal != null) {
|
|
2927
|
-
|
|
2928
|
-
|
|
3415
|
+
let assetsArray = [];
|
|
3416
|
+
if (Array.isArray(newVal)) {
|
|
3417
|
+
assetsArray = newVal.map((val) => String(val ?? ''));
|
|
3418
|
+
}
|
|
3419
|
+
else if (typeof newVal === 'string') {
|
|
3420
|
+
assetsArray = newVal.split('#');
|
|
3421
|
+
}
|
|
3422
|
+
else {
|
|
3423
|
+
assetsArray = [String(newVal)];
|
|
3424
|
+
}
|
|
3425
|
+
assetsArray.forEach((asset) => {
|
|
3426
|
+
if (asset && asset.trim() !== '') {
|
|
2929
3427
|
valuePairs.set(i, asset);
|
|
2930
3428
|
i += 1;
|
|
2931
3429
|
}
|
|
@@ -2963,18 +3461,39 @@ class DataSheetSVG {
|
|
|
2963
3461
|
newVal = urlBase + newVal;
|
|
2964
3462
|
}
|
|
2965
3463
|
}
|
|
2966
|
-
else if (attrPub.
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
3464
|
+
else if (attrPub.find((x) => {
|
|
3465
|
+
if (!x)
|
|
3466
|
+
return false;
|
|
3467
|
+
const keys = Object.keys(x).map((k) => k.toUpperCase());
|
|
3468
|
+
return ((field && keys.includes(field.toUpperCase())) ||
|
|
3469
|
+
(idVal && keys.includes(idVal.toUpperCase())));
|
|
3470
|
+
}) != null) {
|
|
3471
|
+
let foundObj = attrPub.find((x) => {
|
|
3472
|
+
if (!x)
|
|
3473
|
+
return false;
|
|
3474
|
+
const keys = Object.keys(x).map((k) => k.toUpperCase());
|
|
3475
|
+
return ((field && keys.includes(field.toUpperCase())) ||
|
|
3476
|
+
(idVal && keys.includes(idVal.toUpperCase())));
|
|
3477
|
+
});
|
|
3478
|
+
const matchedKey = Object.keys(foundObj).find((k) => (field && k.toUpperCase() === field.toUpperCase()) ||
|
|
3479
|
+
(idVal && k.toUpperCase() === idVal.toUpperCase()));
|
|
3480
|
+
newVal = matchedKey ? foundObj[matchedKey] : '';
|
|
2972
3481
|
console.log(newVal);
|
|
2973
3482
|
let valuePairs = new Map();
|
|
2974
3483
|
let i = 0;
|
|
2975
3484
|
if (newVal != null) {
|
|
2976
|
-
|
|
2977
|
-
|
|
3485
|
+
let assetsArray = [];
|
|
3486
|
+
if (Array.isArray(newVal)) {
|
|
3487
|
+
assetsArray = newVal.map((val) => String(val ?? ''));
|
|
3488
|
+
}
|
|
3489
|
+
else if (typeof newVal === 'string') {
|
|
3490
|
+
assetsArray = newVal.split('#');
|
|
3491
|
+
}
|
|
3492
|
+
else {
|
|
3493
|
+
assetsArray = [String(newVal)];
|
|
3494
|
+
}
|
|
3495
|
+
assetsArray.forEach((asset) => {
|
|
3496
|
+
if (asset && asset.trim() !== '') {
|
|
2978
3497
|
valuePairs.set(i, asset);
|
|
2979
3498
|
i += 1;
|
|
2980
3499
|
}
|
|
@@ -3087,7 +3606,12 @@ class DataSheetSVG {
|
|
|
3087
3606
|
}
|
|
3088
3607
|
}
|
|
3089
3608
|
}
|
|
3090
|
-
else if (field.includes('price')
|
|
3609
|
+
else if (field.includes('price') &&
|
|
3610
|
+
jRowSku['priceObject'] &&
|
|
3611
|
+
((Array.isArray(jRowSku['priceObject']) &&
|
|
3612
|
+
jRowSku['priceObject'].length > 0) ||
|
|
3613
|
+
(!Array.isArray(jRowSku['priceObject']) &&
|
|
3614
|
+
Object.keys(jRowSku['priceObject']).length > 0))) {
|
|
3091
3615
|
if (jRowSku['priceObject'] && jRowSku['priceObject'].length > 0) {
|
|
3092
3616
|
let priceObjectIndex0 = jRowSku['priceObject'][0];
|
|
3093
3617
|
let fieldName = field.substring(0, field.indexOf('['));
|
|
@@ -3141,55 +3665,55 @@ class DataSheetSVG {
|
|
|
3141
3665
|
newVal = '';
|
|
3142
3666
|
}
|
|
3143
3667
|
}
|
|
3144
|
-
else if (field.includes('stock')
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
newVal = '';
|
|
3150
|
-
}
|
|
3668
|
+
else if (field.includes('stock') &&
|
|
3669
|
+
jRowSku['stockObject'] &&
|
|
3670
|
+
jRowSku['stockObject'][field] != null &&
|
|
3671
|
+
jRowSku['stockObject'][field] !== '') {
|
|
3672
|
+
newVal = jRowSku['stockObject'][field].toString();
|
|
3151
3673
|
}
|
|
3152
|
-
else if (field.includes('supplier')
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
newVal = '';
|
|
3158
|
-
}
|
|
3674
|
+
else if (field.includes('supplier') &&
|
|
3675
|
+
jRowSku['supplierObject'] &&
|
|
3676
|
+
jRowSku['supplierObject'][field] != null &&
|
|
3677
|
+
jRowSku['supplierObject'][field] !== '') {
|
|
3678
|
+
newVal = jRowSku['supplierObject'][field].toString();
|
|
3159
3679
|
}
|
|
3160
|
-
else if (idVal.includes('Classification')
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
}
|
|
3175
|
-
else {
|
|
3176
|
-
newVal = '';
|
|
3177
|
-
}
|
|
3680
|
+
else if (idVal.includes('Classification') &&
|
|
3681
|
+
jRowSku['categoryObject'] &&
|
|
3682
|
+
jRowSku['categoryObject'].toString().trim() !== '') {
|
|
3683
|
+
let categoryString = jRowSku['categoryObject'].toString();
|
|
3684
|
+
let splitCategories = categoryString.split('#');
|
|
3685
|
+
newVal = splitCategories[splitCategories.length - 1];
|
|
3686
|
+
let length = idVal.length;
|
|
3687
|
+
let pos = idVal.indexOf('[');
|
|
3688
|
+
let endPos = idVal.indexOf(']');
|
|
3689
|
+
let index;
|
|
3690
|
+
if (pos !== -1 && endPos !== -1 && endPos > pos) {
|
|
3691
|
+
index = parseInt(idVal.substring(pos + 1, endPos));
|
|
3692
|
+
if (index - 1 < splitCategories.length) {
|
|
3693
|
+
newVal = splitCategories[index - 1];
|
|
3178
3694
|
}
|
|
3179
3695
|
else {
|
|
3180
|
-
newVal =
|
|
3696
|
+
newVal = '';
|
|
3181
3697
|
}
|
|
3182
3698
|
}
|
|
3183
3699
|
else {
|
|
3184
|
-
newVal =
|
|
3700
|
+
newVal = splitCategories[splitCategories.length - 1];
|
|
3185
3701
|
}
|
|
3186
3702
|
}
|
|
3187
3703
|
else {
|
|
3188
3704
|
let attributeSku = jRowSku['attributeObject'];
|
|
3189
3705
|
if (attributeSku && attributeSku.length > 0) {
|
|
3190
|
-
let att = jRowSku['attributeObject'].filter((x) =>
|
|
3706
|
+
let att = jRowSku['attributeObject'].filter((x) => {
|
|
3707
|
+
if (!x)
|
|
3708
|
+
return false;
|
|
3709
|
+
const keys = Object.keys(x).map((k) => k.toUpperCase());
|
|
3710
|
+
return ((field && keys.includes(field.toUpperCase())) ||
|
|
3711
|
+
(idVal && keys.includes(idVal.toUpperCase())));
|
|
3712
|
+
});
|
|
3191
3713
|
if (att.length > 0) {
|
|
3192
|
-
|
|
3714
|
+
const matchedKey = Object.keys(att[0]).find((k) => (field && k.toUpperCase() === field.toUpperCase()) ||
|
|
3715
|
+
(idVal && k.toUpperCase() === idVal.toUpperCase()));
|
|
3716
|
+
newVal = matchedKey && att[0][matchedKey] ? att[0][matchedKey] : '';
|
|
3193
3717
|
let searchFieldInAttributes = this.DataSheet.attributes.find((attribute) => attribute['attributeGuid'] == field);
|
|
3194
3718
|
if (searchFieldInAttributes) {
|
|
3195
3719
|
if (newVal == '{}') {
|
|
@@ -3254,9 +3778,18 @@ class DataSheetSVG {
|
|
|
3254
3778
|
if (attributePublicationSku &&
|
|
3255
3779
|
attributePublicationSku.length > 0 &&
|
|
3256
3780
|
newVal == '') {
|
|
3257
|
-
let attr = attributePublicationSku.filter((x) =>
|
|
3781
|
+
let attr = attributePublicationSku.filter((x) => {
|
|
3782
|
+
if (!x)
|
|
3783
|
+
return false;
|
|
3784
|
+
const keys = Object.keys(x).map((k) => k.toUpperCase());
|
|
3785
|
+
return ((field && keys.includes(field.toUpperCase())) ||
|
|
3786
|
+
(idVal && keys.includes(idVal.toUpperCase())));
|
|
3787
|
+
});
|
|
3258
3788
|
if (attr && attr[0]) {
|
|
3259
|
-
|
|
3789
|
+
const matchedKey = Object.keys(attr[0]).find((k) => (field && k.toUpperCase() === field.toUpperCase()) ||
|
|
3790
|
+
(idVal && k.toUpperCase() === idVal.toUpperCase()));
|
|
3791
|
+
newVal =
|
|
3792
|
+
matchedKey && attr[0][matchedKey] ? attr[0][matchedKey] : '';
|
|
3260
3793
|
let searchFieldInAttributes = this.DataSheet.attributes.find((attribute) => attribute['attributeGuid'] == field);
|
|
3261
3794
|
if (searchFieldInAttributes) {
|
|
3262
3795
|
if (newVal == '{}') {
|
|
@@ -3296,7 +3829,7 @@ class DataSheetSVG {
|
|
|
3296
3829
|
fontSize +
|
|
3297
3830
|
'; height: ' +
|
|
3298
3831
|
fontSize +
|
|
3299
|
-
';"/>' +
|
|
3832
|
+
'; object-fit: contain;"/>' +
|
|
3300
3833
|
' ';
|
|
3301
3834
|
}
|
|
3302
3835
|
// TEXT
|
|
@@ -3598,10 +4131,26 @@ class DataSheetSVG {
|
|
|
3598
4131
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3599
4132
|
}
|
|
3600
4133
|
async ReplaceFieldsTemplateSVG(jRowSku, tpl, allTags, allBlocksHeight = 0, nbBlockInRow = 0, keepAttributes = false) {
|
|
4134
|
+
const originalTpl = tpl;
|
|
3601
4135
|
tpl = tpl.replace(/>\s+</g, '><');
|
|
3602
4136
|
tpl = tpl.replace(/foreignObject\s*\.cellContent\s*div\s*\{[^}]*max-content[^}]*\}/g, function (match) {
|
|
3603
4137
|
return match.replace('max-content', 'fit-content');
|
|
3604
4138
|
});
|
|
4139
|
+
let templateVersion = '';
|
|
4140
|
+
const versionMatch = tpl.match(/data-sp-version=["']([^"']+)["']/);
|
|
4141
|
+
if (versionMatch) {
|
|
4142
|
+
templateVersion = versionMatch[1];
|
|
4143
|
+
}
|
|
4144
|
+
const legacyVersions = [
|
|
4145
|
+
'',
|
|
4146
|
+
'1.0',
|
|
4147
|
+
'1.1',
|
|
4148
|
+
'1.101',
|
|
4149
|
+
'1.102',
|
|
4150
|
+
'1.103',
|
|
4151
|
+
'1.104',
|
|
4152
|
+
];
|
|
4153
|
+
const isLegacyVersion = legacyVersions.indexOf(templateVersion) !== -1;
|
|
3605
4154
|
let oldVal;
|
|
3606
4155
|
let newVal = '';
|
|
3607
4156
|
let field = '';
|
|
@@ -3635,8 +4184,8 @@ class DataSheetSVG {
|
|
|
3635
4184
|
this.GetRectPositions(tag, allTags);
|
|
3636
4185
|
if (tag.VariantsTable == true) {
|
|
3637
4186
|
if (jRowSku.hasOwnProperty('skus')) {
|
|
3638
|
-
const blockTag = allTags.find((x) => x.IdTag.toLowerCase() === 'block');
|
|
3639
|
-
const blockWidth = blockTag.Width;
|
|
4187
|
+
const blockTag = allTags.find((x) => x.IdTag && x.IdTag.toLowerCase() === 'block');
|
|
4188
|
+
const blockWidth = blockTag ? blockTag.Width : 0;
|
|
3640
4189
|
let yVal = parseFloat(tag.RectPosition['y']);
|
|
3641
4190
|
tag.RectPosition['y'] = Math.round(yVal + numberToAddToTableY);
|
|
3642
4191
|
const tables = await this.getNewValTable(jRowSku, tag, tpl, allBlocksHeight, blockWidth, nbBlockInRow, keepAttributes);
|
|
@@ -3697,16 +4246,15 @@ class DataSheetSVG {
|
|
|
3697
4246
|
}
|
|
3698
4247
|
}
|
|
3699
4248
|
else if (tag.QRCode == true) {
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
newVal = this.getNewVal(field, jRowSku, fieldName);
|
|
4249
|
+
const parentA = tag.XmlTag.parentElement;
|
|
4250
|
+
const isAnchor = parentA && parentA.tagName.toLowerCase() === 'a';
|
|
4251
|
+
const fixedLink = isAnchor
|
|
4252
|
+
? parentA.getAttribute('href') ||
|
|
4253
|
+
parentA.getAttributeNS('http://www.w3.org/1999/xlink', 'href') ||
|
|
4254
|
+
''
|
|
4255
|
+
: '';
|
|
4256
|
+
if (fixedLink) {
|
|
4257
|
+
newVal = fixedLink;
|
|
3710
4258
|
if (newVal != null && newVal != '') {
|
|
3711
4259
|
try {
|
|
3712
4260
|
newVal = await this.GenerateQRCode(tag, newVal);
|
|
@@ -3718,7 +4266,42 @@ class DataSheetSVG {
|
|
|
3718
4266
|
}
|
|
3719
4267
|
}
|
|
3720
4268
|
else {
|
|
3721
|
-
|
|
4269
|
+
const dataUrl = tag.XmlTag.getAttribute('data-url');
|
|
4270
|
+
if (dataUrl != null && dataUrl != '') {
|
|
4271
|
+
const resolvedUrl = this.GetTagUrl(tag, jRowSku, keepAttributes);
|
|
4272
|
+
newVal = resolvedUrl || '';
|
|
4273
|
+
if (newVal != null && newVal != '') {
|
|
4274
|
+
try {
|
|
4275
|
+
newVal = await this.GenerateQRCode(tag, newVal);
|
|
4276
|
+
}
|
|
4277
|
+
catch (e) {
|
|
4278
|
+
console.log('[ERROR] Error generating QRCode: ' + e);
|
|
4279
|
+
newVal = '';
|
|
4280
|
+
}
|
|
4281
|
+
}
|
|
4282
|
+
}
|
|
4283
|
+
else if (tag.XmlTag.getAttribute('data-field') != null) {
|
|
4284
|
+
let fieldName = tag.XmlTag.getAttribute('data-field');
|
|
4285
|
+
if (fieldName.toLowerCase().includes('sku')) {
|
|
4286
|
+
field = this.getPropertyOfField(fieldName.replace('sku', ''));
|
|
4287
|
+
}
|
|
4288
|
+
else {
|
|
4289
|
+
field = this.getPropertyOfField(fieldName);
|
|
4290
|
+
}
|
|
4291
|
+
newVal = this.getNewVal(field, jRowSku, fieldName);
|
|
4292
|
+
if (newVal != null && newVal != '') {
|
|
4293
|
+
try {
|
|
4294
|
+
newVal = await this.GenerateQRCode(tag, newVal);
|
|
4295
|
+
}
|
|
4296
|
+
catch (e) {
|
|
4297
|
+
console.log('[ERROR] Error generating QRCode: ' + e);
|
|
4298
|
+
newVal = '';
|
|
4299
|
+
}
|
|
4300
|
+
}
|
|
4301
|
+
}
|
|
4302
|
+
else {
|
|
4303
|
+
newVal = '';
|
|
4304
|
+
}
|
|
3722
4305
|
}
|
|
3723
4306
|
}
|
|
3724
4307
|
else if (tag.Type == 'HTML') {
|
|
@@ -3823,9 +4406,168 @@ class DataSheetSVG {
|
|
|
3823
4406
|
? ` data-url-sd="${newVal}"`
|
|
3824
4407
|
: '';
|
|
3825
4408
|
const hdAttr = ` data-url-hd="${urlHD}"`;
|
|
4409
|
+
const objectFit = tag.XmlTag.getAttribute('data-object-fit') || 'contain';
|
|
4410
|
+
const parseBorderShorthand = (borderStr) => {
|
|
4411
|
+
borderStr = borderStr.trim();
|
|
4412
|
+
if (!borderStr || borderStr === 'none') {
|
|
4413
|
+
return { width: '0px', style: 'none', color: 'transparent' };
|
|
4414
|
+
}
|
|
4415
|
+
let color = 'rgb(0, 0, 0)';
|
|
4416
|
+
let rest = borderStr;
|
|
4417
|
+
const rgbMatch = borderStr.match(/(rgba?|hsla?)\([^\)]+\)/i);
|
|
4418
|
+
if (rgbMatch) {
|
|
4419
|
+
color = rgbMatch[0];
|
|
4420
|
+
rest = borderStr.replace(color, '').trim();
|
|
4421
|
+
}
|
|
4422
|
+
else {
|
|
4423
|
+
const tokens = borderStr.split(/\s+/);
|
|
4424
|
+
if (tokens.length >= 3) {
|
|
4425
|
+
const lastToken = tokens[tokens.length - 1];
|
|
4426
|
+
const isWidth = /^\d+(\.\d+)?(px|em|rem|pt|%)?$/.test(lastToken);
|
|
4427
|
+
const isStyle = /^(solid|dashed|dotted|double|groove|ridge|inset|outset|none)$/i.test(lastToken);
|
|
4428
|
+
if (!isWidth && !isStyle) {
|
|
4429
|
+
color = lastToken;
|
|
4430
|
+
tokens.pop();
|
|
4431
|
+
rest = tokens.join(' ');
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
}
|
|
4435
|
+
const tokens = rest.split(/\s+/).filter(Boolean);
|
|
4436
|
+
let width = '0px';
|
|
4437
|
+
let style = 'solid';
|
|
4438
|
+
for (const token of tokens) {
|
|
4439
|
+
if (/^\d+(\.\d+)?(px|em|rem|pt|%)?$/.test(token)) {
|
|
4440
|
+
width = token;
|
|
4441
|
+
if (/^\d+$/.test(width))
|
|
4442
|
+
width += 'px';
|
|
4443
|
+
}
|
|
4444
|
+
else if (/^(solid|dashed|dotted|double|groove|ridge|inset|outset|none)$/i.test(token)) {
|
|
4445
|
+
style = token;
|
|
4446
|
+
}
|
|
4447
|
+
else {
|
|
4448
|
+
color = token;
|
|
4449
|
+
}
|
|
4450
|
+
}
|
|
4451
|
+
return { width, style, color };
|
|
4452
|
+
};
|
|
4453
|
+
const getStyleProperty = (el, prop) => {
|
|
4454
|
+
if (!el || !el.style)
|
|
4455
|
+
return '';
|
|
4456
|
+
const camelProp = prop.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
4457
|
+
let val = el.style[camelProp] || el.style.getPropertyValue(prop);
|
|
4458
|
+
if (!val && el.getAttribute('style')) {
|
|
4459
|
+
const styleAttr = el.getAttribute('style') || '';
|
|
4460
|
+
const regex = new RegExp(`(?:^|;)\\s*${prop}\\s*:\\s*([^;]+)`, 'i');
|
|
4461
|
+
const match = styleAttr.match(regex);
|
|
4462
|
+
if (match) {
|
|
4463
|
+
val = match[1].trim();
|
|
4464
|
+
}
|
|
4465
|
+
}
|
|
4466
|
+
// Fallback for border shorthand expansion
|
|
4467
|
+
if (!val) {
|
|
4468
|
+
const sideMatch = prop.match(/^border-(top|right|bottom|left)-(width|style|color)$/i);
|
|
4469
|
+
if (sideMatch) {
|
|
4470
|
+
const side = sideMatch[1];
|
|
4471
|
+
const subProp = sideMatch[2];
|
|
4472
|
+
const sideShorthand = getStyleProperty(el, `border-${side}`);
|
|
4473
|
+
if (sideShorthand && sideShorthand !== 'none') {
|
|
4474
|
+
const parsed = parseBorderShorthand(sideShorthand);
|
|
4475
|
+
if (subProp === 'width')
|
|
4476
|
+
return parsed.width;
|
|
4477
|
+
if (subProp === 'style')
|
|
4478
|
+
return parsed.style;
|
|
4479
|
+
if (subProp === 'color')
|
|
4480
|
+
return parsed.color;
|
|
4481
|
+
}
|
|
4482
|
+
}
|
|
4483
|
+
else if (prop === 'border-width' ||
|
|
4484
|
+
prop === 'border-style' ||
|
|
4485
|
+
prop === 'border-color') {
|
|
4486
|
+
const borderShorthand = getStyleProperty(el, 'border');
|
|
4487
|
+
if (borderShorthand && borderShorthand !== 'none') {
|
|
4488
|
+
const parsed = parseBorderShorthand(borderShorthand);
|
|
4489
|
+
if (prop === 'border-width')
|
|
4490
|
+
return parsed.width;
|
|
4491
|
+
if (prop === 'border-style')
|
|
4492
|
+
return parsed.style;
|
|
4493
|
+
if (prop === 'border-color')
|
|
4494
|
+
return parsed.color;
|
|
4495
|
+
}
|
|
4496
|
+
}
|
|
4497
|
+
}
|
|
4498
|
+
return val || '';
|
|
4499
|
+
};
|
|
4500
|
+
const originalDiv = tag.XmlTag.querySelector('div');
|
|
4501
|
+
let borderStyleCss = '';
|
|
4502
|
+
let borderRadiusCss = '';
|
|
4503
|
+
if (originalDiv && !isLegacyVersion) {
|
|
4504
|
+
const getBorderSideStyle = (side) => {
|
|
4505
|
+
const shorthand = getStyleProperty(originalDiv, `border-${side}`);
|
|
4506
|
+
if (shorthand)
|
|
4507
|
+
return shorthand;
|
|
4508
|
+
const w = getStyleProperty(originalDiv, `border-${side}-width`);
|
|
4509
|
+
const s = getStyleProperty(originalDiv, `border-${side}-style`) ||
|
|
4510
|
+
'solid';
|
|
4511
|
+
const c = getStyleProperty(originalDiv, `border-${side}-color`) ||
|
|
4512
|
+
'rgb(0, 0, 0)';
|
|
4513
|
+
if (w) {
|
|
4514
|
+
return `${w} ${s} ${c}`;
|
|
4515
|
+
}
|
|
4516
|
+
return '';
|
|
4517
|
+
};
|
|
4518
|
+
const borderTop = getBorderSideStyle('top');
|
|
4519
|
+
const borderRight = getBorderSideStyle('right');
|
|
4520
|
+
const borderBottom = getBorderSideStyle('bottom');
|
|
4521
|
+
const borderLeft = getBorderSideStyle('left');
|
|
4522
|
+
if (borderTop || borderRight || borderBottom || borderLeft) {
|
|
4523
|
+
const gWidth = getStyleProperty(originalDiv, 'border-width') || '0px';
|
|
4524
|
+
const gStyle = getStyleProperty(originalDiv, 'border-style') || 'solid';
|
|
4525
|
+
const gColor = getStyleProperty(originalDiv, 'border-color') ||
|
|
4526
|
+
'rgb(0, 0, 0)';
|
|
4527
|
+
const globalFallback = `${gWidth} ${gStyle} ${gColor}`;
|
|
4528
|
+
borderStyleCss = `
|
|
4529
|
+
border-top: ${borderTop || globalFallback};
|
|
4530
|
+
border-right: ${borderRight || globalFallback};
|
|
4531
|
+
border-bottom: ${borderBottom || globalFallback};
|
|
4532
|
+
border-left: ${borderLeft || globalFallback};
|
|
4533
|
+
`;
|
|
4534
|
+
}
|
|
4535
|
+
else {
|
|
4536
|
+
const borderWidth = getStyleProperty(originalDiv, 'border-width') || '0px';
|
|
4537
|
+
const borderStyle = getStyleProperty(originalDiv, 'border-style') || 'solid';
|
|
4538
|
+
const borderColor = getStyleProperty(originalDiv, 'border-color') ||
|
|
4539
|
+
'rgb(0, 0, 0)';
|
|
4540
|
+
borderStyleCss = `border: ${borderWidth} ${borderStyle} ${borderColor};`;
|
|
4541
|
+
}
|
|
4542
|
+
const topLeftRadius = getStyleProperty(originalDiv, 'border-top-left-radius');
|
|
4543
|
+
const topRightRadius = getStyleProperty(originalDiv, 'border-top-right-radius');
|
|
4544
|
+
const bottomRightRadius = getStyleProperty(originalDiv, 'border-bottom-right-radius');
|
|
4545
|
+
const bottomLeftRadius = getStyleProperty(originalDiv, 'border-bottom-left-radius');
|
|
4546
|
+
if (topLeftRadius ||
|
|
4547
|
+
topRightRadius ||
|
|
4548
|
+
bottomRightRadius ||
|
|
4549
|
+
bottomLeftRadius) {
|
|
4550
|
+
borderRadiusCss = `
|
|
4551
|
+
border-top-left-radius: ${topLeftRadius || '0px'};
|
|
4552
|
+
border-top-right-radius: ${topRightRadius || '0px'};
|
|
4553
|
+
border-bottom-right-radius: ${bottomRightRadius || '0px'};
|
|
4554
|
+
border-bottom-left-radius: ${bottomLeftRadius || '0px'};
|
|
4555
|
+
`;
|
|
4556
|
+
}
|
|
4557
|
+
else {
|
|
4558
|
+
const gRadius = getStyleProperty(originalDiv, 'border-radius');
|
|
4559
|
+
borderRadiusCss = gRadius ? `border-radius: ${gRadius};` : '';
|
|
4560
|
+
}
|
|
4561
|
+
}
|
|
4562
|
+
else {
|
|
4563
|
+
borderStyleCss = `border: 0px solid rgb(0, 0, 0);`;
|
|
4564
|
+
}
|
|
4565
|
+
const fitStyle = objectFit === 'contain'
|
|
4566
|
+
? 'width: 100%; height: 100%; object-fit: contain; vector-effect: non-scaling-stroke;'
|
|
4567
|
+
: `width: 100%; height: 100%; object-fit: ${objectFit}; vector-effect: non-scaling-stroke;`;
|
|
3826
4568
|
let htmlToReplace = `
|
|
3827
4569
|
<img height="100%" width="100%"
|
|
3828
|
-
style="
|
|
4570
|
+
style="${fitStyle}"
|
|
3829
4571
|
stroke="null" src="${newVal}"${sdAttr}${hdAttr}${assetGuidAttr} />
|
|
3830
4572
|
`;
|
|
3831
4573
|
htmlToReplace = `
|
|
@@ -3836,7 +4578,12 @@ class DataSheetSVG {
|
|
|
3836
4578
|
display: flex;
|
|
3837
4579
|
justify-content: center;
|
|
3838
4580
|
align-items: center;
|
|
3839
|
-
|
|
4581
|
+
${borderStyleCss}
|
|
4582
|
+
${borderRadiusCss}
|
|
4583
|
+
box-sizing: border-box;
|
|
4584
|
+
overflow: hidden;
|
|
4585
|
+
position: relative;
|
|
4586
|
+
isolation: isolate;
|
|
3840
4587
|
vector-effect: non-scaling-stroke;
|
|
3841
4588
|
"
|
|
3842
4589
|
stroke="null">
|
|
@@ -3925,6 +4672,9 @@ class DataSheetSVG {
|
|
|
3925
4672
|
newVal = await this.deleteBlock(newVal);
|
|
3926
4673
|
newVal = await this.deleteLine(newVal);
|
|
3927
4674
|
tag.XmlTag.innerHTML = newVal;
|
|
4675
|
+
if (tag.XmlTag.getAttribute('data-type') === 'text') {
|
|
4676
|
+
this.optimizeTextElement(tag.XmlTag, tpl);
|
|
4677
|
+
}
|
|
3928
4678
|
if (tag.XmlTag.hasAttribute('data-type') &&
|
|
3929
4679
|
tag.XmlTag.getAttribute('data-type').includes('productTable')) {
|
|
3930
4680
|
// REPLACE TSPAN VARIABLES IN TABLE CELLS
|
|
@@ -4194,6 +4944,14 @@ class DataSheetSVG {
|
|
|
4194
4944
|
}
|
|
4195
4945
|
else {
|
|
4196
4946
|
element.innerHTML = tagToUpdate.XmlTag.innerHTML;
|
|
4947
|
+
if (tagToUpdate.XmlTag.getAttribute('data-type') === 'text') {
|
|
4948
|
+
if (tagToUpdate.XmlTag.hasAttribute('width')) {
|
|
4949
|
+
element.setAttribute('width', tagToUpdate.XmlTag.getAttribute('width'));
|
|
4950
|
+
}
|
|
4951
|
+
if (tagToUpdate.XmlTag.hasAttribute('height')) {
|
|
4952
|
+
element.setAttribute('height', tagToUpdate.XmlTag.getAttribute('height'));
|
|
4953
|
+
}
|
|
4954
|
+
}
|
|
4197
4955
|
}
|
|
4198
4956
|
}
|
|
4199
4957
|
}
|
|
@@ -4229,6 +4987,60 @@ class DataSheetSVG {
|
|
|
4229
4987
|
}
|
|
4230
4988
|
}
|
|
4231
4989
|
});
|
|
4990
|
+
// Traiter le masquage conditionnel (data-hide-if-attribute)
|
|
4991
|
+
let hideIfElements = domSVG.querySelectorAll('[data-hide-if-attribute]');
|
|
4992
|
+
const cleanValueForHide = (val) => {
|
|
4993
|
+
if (val === null || val === undefined)
|
|
4994
|
+
return '';
|
|
4995
|
+
let str = String(val);
|
|
4996
|
+
// Remove HTML/SVG tags
|
|
4997
|
+
str = str.replace(/<[^>]*>/g, '');
|
|
4998
|
+
// Decode basic HTML entities
|
|
4999
|
+
str = str
|
|
5000
|
+
.replace(/ /g, ' ')
|
|
5001
|
+
.replace(/&/g, '&')
|
|
5002
|
+
.replace(/</g, '<')
|
|
5003
|
+
.replace(/>/g, '>');
|
|
5004
|
+
// Strip list bullets
|
|
5005
|
+
str = str.replace(/[•●▪◦*]/g, '');
|
|
5006
|
+
// Normalize line endings and whitespace
|
|
5007
|
+
str = str.replace(/(\r\n|\n|\r)/g, ' ');
|
|
5008
|
+
str = str.replace(/\s+/g, ' ');
|
|
5009
|
+
str = str.trim();
|
|
5010
|
+
// Handle literal "null" or "undefined" strings
|
|
5011
|
+
if (str.toLowerCase() === 'null' || str.toLowerCase() === 'undefined') {
|
|
5012
|
+
return '';
|
|
5013
|
+
}
|
|
5014
|
+
return str;
|
|
5015
|
+
};
|
|
5016
|
+
hideIfElements.forEach((element) => {
|
|
5017
|
+
let attrName = element.getAttribute('data-hide-if-attribute') || '';
|
|
5018
|
+
let op = element.getAttribute('data-hide-if-operator') || 'is_null';
|
|
5019
|
+
let compareVal = element.getAttribute('data-hide-if-value') || '';
|
|
5020
|
+
let field = this.getPropertyOfField(attrName) || '';
|
|
5021
|
+
let actualValue = this.getNewVal(field, jRowSku, attrName);
|
|
5022
|
+
let cleanActual = cleanValueForHide(actualValue).toLowerCase();
|
|
5023
|
+
let cleanCompare = cleanValueForHide(compareVal).toLowerCase();
|
|
5024
|
+
let shouldHide = false;
|
|
5025
|
+
switch (op) {
|
|
5026
|
+
case 'is_null':
|
|
5027
|
+
shouldHide = cleanActual === '';
|
|
5028
|
+
break;
|
|
5029
|
+
case 'is_not_null':
|
|
5030
|
+
shouldHide = cleanActual !== '';
|
|
5031
|
+
break;
|
|
5032
|
+
case 'equals':
|
|
5033
|
+
shouldHide = cleanActual === cleanCompare;
|
|
5034
|
+
break;
|
|
5035
|
+
case 'not_equals':
|
|
5036
|
+
shouldHide = cleanActual !== cleanCompare;
|
|
5037
|
+
break;
|
|
5038
|
+
}
|
|
5039
|
+
if (shouldHide) {
|
|
5040
|
+
element.remove();
|
|
5041
|
+
}
|
|
5042
|
+
});
|
|
5043
|
+
this.resolveAnchors(domSVG, originalTpl);
|
|
4232
5044
|
let gabaritSvgUpdated = domSVG.documentElement.innerHTML;
|
|
4233
5045
|
// Supprimer les balises inutiles (<html>, <body>, <head>)
|
|
4234
5046
|
gabaritSvgUpdated = gabaritSvgUpdated.replace(/<html.*?>|<\/html>/g, '');
|
|
@@ -4240,22 +5052,20 @@ class DataSheetSVG {
|
|
|
4240
5052
|
}
|
|
4241
5053
|
return tpl;
|
|
4242
5054
|
}
|
|
4243
|
-
|
|
4244
|
-
foEl.
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
5055
|
+
optimizeTextElement(foEl, tpl) {
|
|
5056
|
+
const textarea = foEl.querySelector('.fake-textarea');
|
|
5057
|
+
if (!textarea)
|
|
5058
|
+
return;
|
|
5059
|
+
const locked = textarea.getAttribute('locked');
|
|
5060
|
+
const isFixed = locked === 'true';
|
|
5061
|
+
const isWidth = locked === 'width';
|
|
5062
|
+
const isHeight = locked !== 'true' && locked !== 'width';
|
|
5063
|
+
if (isFixed) {
|
|
5064
|
+
return;
|
|
4252
5065
|
}
|
|
4253
|
-
const foWidth = parseFloat(foEl.getAttribute('width')) ||
|
|
4254
|
-
|
|
4255
|
-
0;
|
|
4256
|
-
// Monter le foreignObject dans un div temporaire en DOM (comme removeEmptyColumns pour variantsTable)
|
|
5066
|
+
const foWidth = parseFloat(foEl.getAttribute('width')) || 0;
|
|
5067
|
+
const foHeight = parseFloat(foEl.getAttribute('height')) || 0;
|
|
4257
5068
|
const tempDiv = document.createElement('div');
|
|
4258
|
-
// Styles application
|
|
4259
5069
|
let stylesHtml = '';
|
|
4260
5070
|
if (tpl) {
|
|
4261
5071
|
const styleMatches = tpl.match(/<style[^>]*>([\s\S]*?)<\/style>/gi);
|
|
@@ -4266,6 +5076,11 @@ class DataSheetSVG {
|
|
|
4266
5076
|
if (this.DataSheet.importFontFamily) {
|
|
4267
5077
|
stylesHtml += `<style>${this.DataSheet.importFontFamily}</style>`;
|
|
4268
5078
|
}
|
|
5079
|
+
let textareaId = textarea.getAttribute('id');
|
|
5080
|
+
if (!textareaId) {
|
|
5081
|
+
textareaId = 'gen-text-' + Math.random().toString(36).substr(2, 9);
|
|
5082
|
+
textarea.setAttribute('id', textareaId);
|
|
5083
|
+
}
|
|
4269
5084
|
const wrappedContent = this.getHierarchyWrapper(foEl, foEl.outerHTML);
|
|
4270
5085
|
tempDiv.innerHTML = stylesHtml + wrappedContent;
|
|
4271
5086
|
tempDiv.style.position = 'absolute';
|
|
@@ -4275,33 +5090,177 @@ class DataSheetSVG {
|
|
|
4275
5090
|
tempDiv.style.top = '-9999px';
|
|
4276
5091
|
tempDiv.style.width = 'auto';
|
|
4277
5092
|
document.body.appendChild(tempDiv);
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
5093
|
+
try {
|
|
5094
|
+
const textareaElement = tempDiv.querySelector(`#${textareaId}`);
|
|
5095
|
+
if (textareaElement) {
|
|
5096
|
+
let parentFo = textareaElement.closest('foreignObject');
|
|
5097
|
+
// Split long text wrapping into separate divs to prevent overlap and highlight blockiness
|
|
5098
|
+
const lineDivs = Array.from(textareaElement.querySelectorAll('div')).filter((d) => {
|
|
5099
|
+
return d.querySelectorAll('div').length === 0;
|
|
5100
|
+
});
|
|
5101
|
+
const findTextNode = (node) => {
|
|
5102
|
+
if (node.nodeType === Node.TEXT_NODE &&
|
|
5103
|
+
node.textContent?.trim() !== '') {
|
|
5104
|
+
return node;
|
|
5105
|
+
}
|
|
5106
|
+
for (let child of Array.from(node.childNodes)) {
|
|
5107
|
+
const found = findTextNode(child);
|
|
5108
|
+
if (found)
|
|
5109
|
+
return found;
|
|
5110
|
+
}
|
|
5111
|
+
return null;
|
|
5112
|
+
};
|
|
5113
|
+
let domChanged = false;
|
|
5114
|
+
lineDivs.forEach((lineDiv) => {
|
|
5115
|
+
const text = lineDiv.textContent || '';
|
|
5116
|
+
if (!text.trim())
|
|
5117
|
+
return;
|
|
5118
|
+
const computedStyle = window.getComputedStyle(lineDiv);
|
|
5119
|
+
const fontFamily = computedStyle.fontFamily || 'sans-serif';
|
|
5120
|
+
const fontSize = computedStyle.fontSize || '24px';
|
|
5121
|
+
const canvas = document.createElement('canvas');
|
|
5122
|
+
const ctx = canvas.getContext('2d');
|
|
5123
|
+
if (!ctx)
|
|
5124
|
+
return;
|
|
5125
|
+
ctx.font = `${fontSize} ${fontFamily}`;
|
|
5126
|
+
const textWidth = ctx.measureText(text).width;
|
|
5127
|
+
if (foWidth > 0 && textWidth > foWidth) {
|
|
5128
|
+
const words = text.split(' ');
|
|
5129
|
+
const linesOfText = [];
|
|
5130
|
+
let currentLine = '';
|
|
5131
|
+
for (let word of words) {
|
|
5132
|
+
const testLine = currentLine ? currentLine + ' ' + word : word;
|
|
5133
|
+
const testWidth = ctx.measureText(testLine).width;
|
|
5134
|
+
if (testWidth > foWidth && currentLine) {
|
|
5135
|
+
linesOfText.push(currentLine);
|
|
5136
|
+
currentLine = word;
|
|
5137
|
+
}
|
|
5138
|
+
else {
|
|
5139
|
+
currentLine = testLine;
|
|
5140
|
+
}
|
|
5141
|
+
}
|
|
5142
|
+
if (currentLine) {
|
|
5143
|
+
linesOfText.push(currentLine);
|
|
5144
|
+
}
|
|
5145
|
+
if (linesOfText.length > 1) {
|
|
5146
|
+
domChanged = true;
|
|
5147
|
+
let previousLine = lineDiv;
|
|
5148
|
+
for (let i = 0; i < linesOfText.length; i++) {
|
|
5149
|
+
if (i === 0) {
|
|
5150
|
+
const textNode = findTextNode(lineDiv);
|
|
5151
|
+
if (textNode) {
|
|
5152
|
+
textNode.textContent = linesOfText[0];
|
|
5153
|
+
}
|
|
5154
|
+
}
|
|
5155
|
+
else {
|
|
5156
|
+
const clone = lineDiv.cloneNode(true);
|
|
5157
|
+
const textNode = findTextNode(clone);
|
|
5158
|
+
if (textNode) {
|
|
5159
|
+
textNode.textContent = linesOfText[i];
|
|
5160
|
+
}
|
|
5161
|
+
lineDiv.parentNode.insertBefore(clone, previousLine.nextSibling);
|
|
5162
|
+
previousLine = clone;
|
|
5163
|
+
}
|
|
5164
|
+
}
|
|
5165
|
+
}
|
|
5166
|
+
}
|
|
5167
|
+
});
|
|
5168
|
+
if (domChanged) {
|
|
5169
|
+
const originalTextarea = foEl.querySelector('.fake-textarea');
|
|
5170
|
+
if (originalTextarea) {
|
|
5171
|
+
originalTextarea.innerHTML = textareaElement.innerHTML;
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5174
|
+
if (isWidth) {
|
|
5175
|
+
textareaElement.style.width = 'max-content';
|
|
5176
|
+
textareaElement.style.whiteSpace = 'nowrap';
|
|
5177
|
+
textareaElement.style.display = 'inline-block';
|
|
5178
|
+
const rect = textareaElement.getBoundingClientRect();
|
|
5179
|
+
const naturalWidth = Math.ceil(rect.width);
|
|
5180
|
+
foEl.setAttribute('width', (naturalWidth + 4).toString());
|
|
5181
|
+
}
|
|
5182
|
+
else if (isHeight) {
|
|
5183
|
+
if (parentFo) {
|
|
5184
|
+
parentFo.setAttribute('width', foWidth.toString());
|
|
5185
|
+
parentFo.removeAttribute('height');
|
|
5186
|
+
}
|
|
5187
|
+
textareaElement.style.width = foWidth + 'px';
|
|
5188
|
+
textareaElement.style.height = 'auto';
|
|
5189
|
+
const rect = textareaElement.getBoundingClientRect();
|
|
5190
|
+
const naturalHeight = Math.ceil(rect.height);
|
|
5191
|
+
foEl.setAttribute('height', (naturalHeight + 4).toString());
|
|
5192
|
+
}
|
|
5193
|
+
}
|
|
5194
|
+
}
|
|
5195
|
+
catch (e) {
|
|
5196
|
+
console.error('Error optimizing text element height/width:', e);
|
|
5197
|
+
}
|
|
5198
|
+
finally {
|
|
5199
|
+
document.body.removeChild(tempDiv);
|
|
5200
|
+
}
|
|
5201
|
+
}
|
|
5202
|
+
optimizeProductTable(foEl, tpl) {
|
|
5203
|
+
foEl.style.setProperty('overflow', 'visible', 'important');
|
|
5204
|
+
const table = foEl.querySelector('table');
|
|
5205
|
+
if (!table)
|
|
5206
|
+
return { width: 0, height: 0 };
|
|
5207
|
+
let tableId = table.getAttribute('id');
|
|
5208
|
+
if (!tableId) {
|
|
5209
|
+
tableId = 'generation-table-' + Math.random().toString(36).substr(2, 9);
|
|
5210
|
+
table.setAttribute('id', tableId);
|
|
5211
|
+
}
|
|
5212
|
+
const foWidth = parseFloat(foEl.getAttribute('width')) ||
|
|
5213
|
+
foEl.getBoundingClientRect().width ||
|
|
5214
|
+
0;
|
|
5215
|
+
// Monter le foreignObject dans un div temporaire en DOM (comme removeEmptyColumns pour variantsTable)
|
|
5216
|
+
const tempDiv = document.createElement('div');
|
|
5217
|
+
// Styles application
|
|
5218
|
+
let stylesHtml = '';
|
|
5219
|
+
if (tpl) {
|
|
5220
|
+
const styleMatches = tpl.match(/<style[^>]*>([\s\S]*?)<\/style>/gi);
|
|
5221
|
+
if (styleMatches) {
|
|
5222
|
+
stylesHtml = styleMatches.join('');
|
|
5223
|
+
}
|
|
5224
|
+
}
|
|
5225
|
+
if (this.DataSheet.importFontFamily) {
|
|
5226
|
+
stylesHtml += `<style>${this.DataSheet.importFontFamily}</style>`;
|
|
5227
|
+
}
|
|
5228
|
+
const wrappedContent = this.getHierarchyWrapper(foEl, foEl.outerHTML);
|
|
5229
|
+
tempDiv.innerHTML = stylesHtml + wrappedContent;
|
|
5230
|
+
tempDiv.style.position = 'absolute';
|
|
5231
|
+
tempDiv.style.visibility = 'hidden';
|
|
5232
|
+
tempDiv.style.pointerEvents = 'none';
|
|
5233
|
+
tempDiv.style.left = '-9999px';
|
|
5234
|
+
tempDiv.style.top = '-9999px';
|
|
5235
|
+
tempDiv.style.width = 'auto';
|
|
5236
|
+
document.body.appendChild(tempDiv);
|
|
5237
|
+
const tableElement = tempDiv.querySelector(`#${tableId}`);
|
|
5238
|
+
if (!tableElement) {
|
|
5239
|
+
document.body.removeChild(tempDiv);
|
|
5240
|
+
return { width: 0, height: 0 };
|
|
5241
|
+
}
|
|
5242
|
+
// Un-wrap .cellContent divs to prevent max-content / fit-content CSS styles from blocking wrapping
|
|
5243
|
+
const cellContents = tableElement.querySelectorAll('.cellContent, .cellcontent');
|
|
5244
|
+
cellContents.forEach((cellContent) => {
|
|
5245
|
+
const parent = cellContent.parentNode;
|
|
5246
|
+
if (parent) {
|
|
5247
|
+
while (cellContent.firstChild) {
|
|
5248
|
+
parent.insertBefore(cellContent.firstChild, cellContent);
|
|
5249
|
+
}
|
|
5250
|
+
parent.removeChild(cellContent);
|
|
5251
|
+
}
|
|
5252
|
+
});
|
|
5253
|
+
// 1. Lire le colgroup d'origine pour obtenir les largeurs fixes
|
|
5254
|
+
const originalColgroup = table.querySelector('colgroup');
|
|
5255
|
+
const originalCols = originalColgroup
|
|
5256
|
+
? Array.from(originalColgroup.querySelectorAll('col'))
|
|
5257
|
+
: [];
|
|
5258
|
+
const originalColWidths = [];
|
|
5259
|
+
originalCols.forEach((col) => {
|
|
5260
|
+
let width = null;
|
|
5261
|
+
if (col) {
|
|
5262
|
+
let w = col.style.width || col.getAttribute('width');
|
|
5263
|
+
if (!w) {
|
|
4305
5264
|
const styleAttr = col.getAttribute('style');
|
|
4306
5265
|
if (styleAttr) {
|
|
4307
5266
|
const matchWidth = styleAttr.match(/width:\s*([^;]+)/);
|
|
@@ -4482,11 +5441,13 @@ class DataSheetSVG {
|
|
|
4482
5441
|
const parser = new DOMParser();
|
|
4483
5442
|
const doc = parser.parseFromString(`<wrapper>${svg}</wrapper>`, 'text/html');
|
|
4484
5443
|
const wrapper = doc.body.firstElementChild;
|
|
4485
|
-
const
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
5444
|
+
const tspans = wrapper.querySelectorAll('tspan[deleteline="true"], TSPAN[deleteline="true"]');
|
|
5445
|
+
tspans.forEach((tspan) => {
|
|
5446
|
+
if (tspan.textContent.trim() === '') {
|
|
5447
|
+
const lineDiv = tspan.closest('div');
|
|
5448
|
+
if (lineDiv && lineDiv !== wrapper.firstElementChild) {
|
|
5449
|
+
lineDiv.remove();
|
|
5450
|
+
}
|
|
4490
5451
|
}
|
|
4491
5452
|
});
|
|
4492
5453
|
svg = wrapper.innerHTML;
|
|
@@ -4498,9 +5459,9 @@ class DataSheetSVG {
|
|
|
4498
5459
|
}
|
|
4499
5460
|
}
|
|
4500
5461
|
getBackgroundSectionForPreview(section) {
|
|
4501
|
-
let defaultBackground = this.DataSheet.backgrounds.find((background) => background.
|
|
5462
|
+
let defaultBackground = this.DataSheet.backgrounds.find((background) => background.guid == this.DataSheet.defaultBackgroundGuid);
|
|
4502
5463
|
let backgroundNameSection = section.spreadName + '.svg';
|
|
4503
|
-
let background = this.DataSheet.backgrounds.find((background) => background.
|
|
5464
|
+
let background = this.DataSheet.backgrounds.find((background) => background.name == backgroundNameSection);
|
|
4504
5465
|
if (background == undefined) {
|
|
4505
5466
|
background = defaultBackground;
|
|
4506
5467
|
}
|
|
@@ -4540,7 +5501,7 @@ class DataSheetSVG {
|
|
|
4540
5501
|
this.DataSheet.publicationTemplateBackgroundRightMargin =
|
|
4541
5502
|
background.rightMargin;
|
|
4542
5503
|
this.DataSheet.publicationTemplateBackgroundMarginX =
|
|
4543
|
-
this.DataSheet.publicationTemplateWidth - background.
|
|
5504
|
+
this.DataSheet.publicationTemplateWidth - background.rightMargin;
|
|
4544
5505
|
return background;
|
|
4545
5506
|
}
|
|
4546
5507
|
getMarketingSectionForPreview(section) {
|
|
@@ -4568,11 +5529,23 @@ class DataSheetSVG {
|
|
|
4568
5529
|
this.DataSheet.publicationTemplateBackgroundLeftMargin = mark.leftMargin;
|
|
4569
5530
|
this.DataSheet.publicationTemplateBackgroundRightMargin = mark.rightMargin;
|
|
4570
5531
|
this.DataSheet.publicationTemplateBackgroundMarginX =
|
|
4571
|
-
this.DataSheet.publicationTemplateWidth - mark.
|
|
5532
|
+
this.DataSheet.publicationTemplateWidth - mark.rightMargin;
|
|
4572
5533
|
return mark;
|
|
4573
5534
|
}
|
|
4574
5535
|
// EXPORT
|
|
4575
5536
|
async getCleanedSVGString(svg, soft = false) {
|
|
5537
|
+
if (!svg || !svg.trim().includes('<svg')) {
|
|
5538
|
+
const excerpt = svg ? svg.substring(0, 300) : '(vide)';
|
|
5539
|
+
if (svg &&
|
|
5540
|
+
(svg.toLowerCase().includes('<!doctype html') ||
|
|
5541
|
+
svg.toLowerCase().includes('<html'))) {
|
|
5542
|
+
console.error("[getCleanedSVGString] Une page HTML a été reçue à la place d'un SVG. ", excerpt);
|
|
5543
|
+
}
|
|
5544
|
+
else {
|
|
5545
|
+
console.error('[getCleanedSVGString] Contenu SVG invalide ou vide. Début:', excerpt);
|
|
5546
|
+
}
|
|
5547
|
+
return undefined;
|
|
5548
|
+
}
|
|
4576
5549
|
const svgWithImgFixed = this.selfCloseImgTags(svg);
|
|
4577
5550
|
const sanitizedSVGString = this.sanitizeSVGString(svgWithImgFixed);
|
|
4578
5551
|
const parser = new DOMParser();
|
|
@@ -4842,7 +5815,7 @@ class DataSheetSVG {
|
|
|
4842
5815
|
let height;
|
|
4843
5816
|
try {
|
|
4844
5817
|
// Trouver le tag "block"
|
|
4845
|
-
const blockTag = allTags.find((x) => x.IdTag.toLowerCase() === 'block');
|
|
5818
|
+
const blockTag = allTags.find((x) => x.IdTag && x.IdTag.toLowerCase() === 'block');
|
|
4846
5819
|
if (!blockTag || !blockTag.XmlTag)
|
|
4847
5820
|
throw new Error('blockTag introuvable ou invalide');
|
|
4848
5821
|
const heightAttr = blockTag.XmlTag.getAttribute('height');
|
|
@@ -5092,9 +6065,47 @@ class DataSheetSVG {
|
|
|
5092
6065
|
return `<line x1="${x0}" y1="${y0}" x2="${x1}" y2="${y1}" stroke="black" stroke-width="1"/>`;
|
|
5093
6066
|
}
|
|
5094
6067
|
keepOnlySideRegex(svg, sideToKeep) {
|
|
6068
|
+
if (!svg)
|
|
6069
|
+
return null;
|
|
5095
6070
|
const sideToRemove = sideToKeep === 'left' ? 'right' : 'left';
|
|
6071
|
+
if (typeof DOMParser !== 'undefined' &&
|
|
6072
|
+
typeof XMLSerializer !== 'undefined') {
|
|
6073
|
+
try {
|
|
6074
|
+
const parser = new DOMParser();
|
|
6075
|
+
const doc = parser.parseFromString(svg, 'image/svg+xml');
|
|
6076
|
+
const parserErrors = doc.getElementsByTagName('parsererror');
|
|
6077
|
+
if (parserErrors.length === 0) {
|
|
6078
|
+
// Robustly remove the unwanted side
|
|
6079
|
+
const elementsToRemove = doc.querySelectorAll(`[data-side="${sideToRemove}"]`);
|
|
6080
|
+
elementsToRemove.forEach((el) => el.remove());
|
|
6081
|
+
// Clean up visibility constraints on the kept side
|
|
6082
|
+
const elementsToKeep = doc.querySelectorAll(`[data-side="${sideToKeep}"]`);
|
|
6083
|
+
elementsToKeep.forEach((el) => {
|
|
6084
|
+
if (el instanceof SVGElement || el instanceof HTMLElement) {
|
|
6085
|
+
el.style.removeProperty('display');
|
|
6086
|
+
el.style.removeProperty('visibility');
|
|
6087
|
+
}
|
|
6088
|
+
});
|
|
6089
|
+
const serializer = new XMLSerializer();
|
|
6090
|
+
return serializer.serializeToString(doc);
|
|
6091
|
+
}
|
|
6092
|
+
}
|
|
6093
|
+
catch (e) {
|
|
6094
|
+
console.warn('DOMParser failed in keepOnlySideRegex, falling back to regex method:', e);
|
|
6095
|
+
}
|
|
6096
|
+
}
|
|
5096
6097
|
const regex = new RegExp(`<g[^>]*data-side=["']${sideToRemove}["'][\\s\\S]*?<\\/g>`, 'i');
|
|
5097
|
-
|
|
6098
|
+
let cleanedSvg = svg.replace(regex, '');
|
|
6099
|
+
// Also clean up visibility/pointer-events styles on the kept side using regex for environments without DOMParser
|
|
6100
|
+
const keptSideRegex = new RegExp(`(<g[^>]*data-side=["']${sideToKeep}["'][^>]*style=["'])([^"']*)(["']>)`, 'i');
|
|
6101
|
+
cleanedSvg = cleanedSvg.replace(keptSideRegex, (match, before, styleContent, after) => {
|
|
6102
|
+
const cleanStyle = styleContent
|
|
6103
|
+
.replace(/visibility\s*:\s*hidden\s*;?/gi, '')
|
|
6104
|
+
.replace(/pointer-events\s*:\s*none\s*;?/gi, '')
|
|
6105
|
+
.trim();
|
|
6106
|
+
return before + cleanStyle + after;
|
|
6107
|
+
});
|
|
6108
|
+
return cleanedSvg;
|
|
5098
6109
|
}
|
|
5099
6110
|
applyTextTransform(val, transform) {
|
|
5100
6111
|
if (!val || typeof val !== 'string' || !transform)
|
|
@@ -5112,11 +6123,1728 @@ class DataSheetSVG {
|
|
|
5112
6123
|
return val;
|
|
5113
6124
|
}
|
|
5114
6125
|
}
|
|
6126
|
+
resolveAnchors(domSVG, originalTpl) {
|
|
6127
|
+
const originalDoc = new DOMParser().parseFromString(originalTpl, 'text/html');
|
|
6128
|
+
const getElementGeometry = (el) => {
|
|
6129
|
+
const [yStr, xStr] = this.GetXY(el);
|
|
6130
|
+
const x = xStr ? parseFloat(xStr) : 0;
|
|
6131
|
+
const y = yStr ? parseFloat(yStr) : 0;
|
|
6132
|
+
const width = el.getAttribute('width')
|
|
6133
|
+
? parseFloat(el.getAttribute('width'))
|
|
6134
|
+
: 0;
|
|
6135
|
+
const height = el.getAttribute('height')
|
|
6136
|
+
? parseFloat(el.getAttribute('height'))
|
|
6137
|
+
: 0;
|
|
6138
|
+
return { x, y, width, height };
|
|
6139
|
+
};
|
|
6140
|
+
const anchoredElements = Array.from(domSVG.querySelectorAll('[data-anchor-target]'));
|
|
6141
|
+
if (anchoredElements.length === 0)
|
|
6142
|
+
return;
|
|
6143
|
+
const adj = new Map();
|
|
6144
|
+
const inDegree = new Map();
|
|
6145
|
+
anchoredElements.forEach((el) => {
|
|
6146
|
+
const id = el.getAttribute('id');
|
|
6147
|
+
if (id) {
|
|
6148
|
+
inDegree.set(id, 0);
|
|
6149
|
+
}
|
|
6150
|
+
});
|
|
6151
|
+
anchoredElements.forEach((el) => {
|
|
6152
|
+
const id = el.getAttribute('id');
|
|
6153
|
+
const targetId = el.getAttribute('data-anchor-target');
|
|
6154
|
+
if (id && targetId) {
|
|
6155
|
+
if (!adj.has(targetId)) {
|
|
6156
|
+
adj.set(targetId, []);
|
|
6157
|
+
}
|
|
6158
|
+
adj.get(targetId).push(el);
|
|
6159
|
+
const targetIsAnchored = anchoredElements.some((ae) => ae.getAttribute('id') === targetId);
|
|
6160
|
+
if (targetIsAnchored) {
|
|
6161
|
+
inDegree.set(id, (inDegree.get(id) || 0) + 1);
|
|
6162
|
+
}
|
|
6163
|
+
}
|
|
6164
|
+
});
|
|
6165
|
+
const queue = [];
|
|
6166
|
+
anchoredElements.forEach((el) => {
|
|
6167
|
+
const id = el.getAttribute('id');
|
|
6168
|
+
if (id && (inDegree.get(id) || 0) === 0) {
|
|
6169
|
+
queue.push(el);
|
|
6170
|
+
}
|
|
6171
|
+
});
|
|
6172
|
+
const sortedElements = [];
|
|
6173
|
+
const visited = new Set();
|
|
6174
|
+
while (queue.length > 0) {
|
|
6175
|
+
const el = queue.shift();
|
|
6176
|
+
const id = el.getAttribute('id');
|
|
6177
|
+
if (id) {
|
|
6178
|
+
if (visited.has(id))
|
|
6179
|
+
continue;
|
|
6180
|
+
visited.add(id);
|
|
6181
|
+
sortedElements.push(el);
|
|
6182
|
+
const neighbors = adj.get(id) || [];
|
|
6183
|
+
neighbors.forEach((neighbor) => {
|
|
6184
|
+
const neighborId = neighbor.getAttribute('id');
|
|
6185
|
+
if (neighborId) {
|
|
6186
|
+
const deg = (inDegree.get(neighborId) || 0) - 1;
|
|
6187
|
+
inDegree.set(neighborId, deg);
|
|
6188
|
+
if (deg <= 0) {
|
|
6189
|
+
queue.push(neighbor);
|
|
6190
|
+
}
|
|
6191
|
+
}
|
|
6192
|
+
});
|
|
6193
|
+
}
|
|
6194
|
+
}
|
|
6195
|
+
sortedElements.forEach((el) => {
|
|
6196
|
+
const targetId = el.getAttribute('data-anchor-target');
|
|
6197
|
+
if (!targetId)
|
|
6198
|
+
return;
|
|
6199
|
+
const targetEl = domSVG.getElementById(targetId);
|
|
6200
|
+
if (!targetEl)
|
|
6201
|
+
return;
|
|
6202
|
+
const elId = el.getAttribute('id') || '';
|
|
6203
|
+
const originalEl = originalDoc.getElementById(elId);
|
|
6204
|
+
const originalTargetEl = originalDoc.getElementById(targetId);
|
|
6205
|
+
if (!originalEl || !originalTargetEl)
|
|
6206
|
+
return;
|
|
6207
|
+
const origB = getElementGeometry(originalEl);
|
|
6208
|
+
const origA = getElementGeometry(originalTargetEl);
|
|
6209
|
+
const currA = getElementGeometry(targetEl);
|
|
6210
|
+
const currB = getElementGeometry(el);
|
|
6211
|
+
let newX = currB.x;
|
|
6212
|
+
let newY = currB.y;
|
|
6213
|
+
const xType = el.getAttribute('data-anchor-x-type') || 'left';
|
|
6214
|
+
if (xType === 'right') {
|
|
6215
|
+
const origRightA = origA.x + origA.width;
|
|
6216
|
+
const offsetX = origB.x - origRightA;
|
|
6217
|
+
const currRightA = currA.x + currA.width;
|
|
6218
|
+
newX = currRightA + offsetX;
|
|
6219
|
+
}
|
|
6220
|
+
else if (xType === 'left') {
|
|
6221
|
+
const offsetX = origB.x - origA.x;
|
|
6222
|
+
newX = currA.x + offsetX;
|
|
6223
|
+
}
|
|
6224
|
+
const yType = el.getAttribute('data-anchor-y-type') || 'bottom';
|
|
6225
|
+
if (yType === 'bottom') {
|
|
6226
|
+
const origBottomA = origA.y + origA.height;
|
|
6227
|
+
const offsetY = origB.y - origBottomA;
|
|
6228
|
+
const currBottomA = currA.y + currA.height;
|
|
6229
|
+
newY = currBottomA + offsetY;
|
|
6230
|
+
}
|
|
6231
|
+
else if (yType === 'top') {
|
|
6232
|
+
const offsetY = origB.y - origA.y;
|
|
6233
|
+
newY = currA.y + offsetY;
|
|
6234
|
+
}
|
|
6235
|
+
el.setAttribute('x', newX.toString());
|
|
6236
|
+
el.setAttribute('y', newY.toString());
|
|
6237
|
+
});
|
|
6238
|
+
}
|
|
6239
|
+
}
|
|
6240
|
+
|
|
6241
|
+
class DataSheetSku {
|
|
6242
|
+
constructor(dataSheetSVG, dataSheet) {
|
|
6243
|
+
this.languagePreviewSelected = 'fr';
|
|
6244
|
+
this.skusSection = [];
|
|
6245
|
+
this.skusSectionPreview = [];
|
|
6246
|
+
if (!dataSheet) {
|
|
6247
|
+
throw new Error('DataSheet instance is required to create a DataSheetSVG');
|
|
6248
|
+
}
|
|
6249
|
+
this.DataSheet = dataSheet;
|
|
6250
|
+
this.DataSheetSVG = dataSheetSVG;
|
|
6251
|
+
}
|
|
6252
|
+
async setPublicationsService(publicationsService) {
|
|
6253
|
+
if (!publicationsService) {
|
|
6254
|
+
throw new Error('PublicationsService instance is required');
|
|
6255
|
+
}
|
|
6256
|
+
this.publicationsService = publicationsService;
|
|
6257
|
+
}
|
|
6258
|
+
async GenerateAllInOneExportFile(sourceId, option1PerPage, displayModeVariant, multiColumns = true) {
|
|
6259
|
+
try {
|
|
6260
|
+
this.DataSheet.currentStep = 1;
|
|
6261
|
+
let res = null;
|
|
6262
|
+
if (this.publicationsService) {
|
|
6263
|
+
res = await this.publicationsService
|
|
6264
|
+
.getSkuPreview(sourceId, this.DataSheet.language, this.DataSheet.ratebase, this.DataSheet.priceListGuid, this.DataSheet.accountGuid, this.DataSheet.productSheetGuid)
|
|
6265
|
+
.toPromise();
|
|
6266
|
+
}
|
|
6267
|
+
let lstSkuObjects = res?.sku || [];
|
|
6268
|
+
if (lstSkuObjects == null || lstSkuObjects.length === 0) {
|
|
6269
|
+
this.DataSheet.currentStep = 99;
|
|
6270
|
+
return [];
|
|
6271
|
+
}
|
|
6272
|
+
this.DataSheet.nameFinalName = lstSkuObjects[0]['sku'].toString();
|
|
6273
|
+
this.DataSheet.currentObjectName = lstSkuObjects[0]['sku'].toString();
|
|
6274
|
+
if (this.DataSheet.nameFinalName != null) {
|
|
6275
|
+
this.DataSheet.nameFinalName = String(this.DataSheet.nameFinalName)
|
|
6276
|
+
.replace(/\//g, '-')
|
|
6277
|
+
.replace(/\\/g, '-')
|
|
6278
|
+
.replace(/\+/g, '-');
|
|
6279
|
+
}
|
|
6280
|
+
let sections = [{ name: this.DataSheet.nameFinalName }];
|
|
6281
|
+
let lstBackgroundTags = [];
|
|
6282
|
+
let coverTpl = '';
|
|
6283
|
+
let arrayFiles = [];
|
|
6284
|
+
// boucler sur sections
|
|
6285
|
+
this.DataSheet.maxSections = sections.length;
|
|
6286
|
+
this.DataSheet.nbSections = 0;
|
|
6287
|
+
for (let section of sections) {
|
|
6288
|
+
//this.DataSheet.currentSectionName = section.name;
|
|
6289
|
+
let files = [];
|
|
6290
|
+
this.DataSheet.progress += (50 / sections.length) * 0.2;
|
|
6291
|
+
this.DataSheet.currentStep = 2;
|
|
6292
|
+
this.DataSheet.nbSkusSection = 0;
|
|
6293
|
+
this.DataSheet.maxSkusSection = lstSkuObjects.length;
|
|
6294
|
+
let pages = [];
|
|
6295
|
+
let background = this.DataSheetSVG.getBackgroundSectionForPreview(section);
|
|
6296
|
+
let backgroundTpl = background.svgImage;
|
|
6297
|
+
let allBackgroundTags = this.DataSheetSVG.GetSvgGroupToReplace(backgroundTpl);
|
|
6298
|
+
let allElements = this.DataSheetSVG.GetAllTags(backgroundTpl);
|
|
6299
|
+
let group = false;
|
|
6300
|
+
allElements?.forEach((element) => {
|
|
6301
|
+
const tagName = element.tagName?.toLowerCase();
|
|
6302
|
+
if (tagName === 'svg') {
|
|
6303
|
+
// HEADER HEIGHT
|
|
6304
|
+
const attrHeader = element.getAttribute('data-margin-top') || element.getAttribute('data-header-height') || element.getAttribute('data-margin-vertical');
|
|
6305
|
+
const parsedHeader = parseFloat(attrHeader);
|
|
6306
|
+
if (!isNaN(parsedHeader)) {
|
|
6307
|
+
this.DataSheet.publicationTemplateBackgroundHeightHeader =
|
|
6308
|
+
parsedHeader;
|
|
6309
|
+
}
|
|
6310
|
+
else {
|
|
6311
|
+
this.DataSheet.publicationTemplateBackgroundHeightHeader = 0;
|
|
6312
|
+
}
|
|
6313
|
+
// FOOTER HEIGHT
|
|
6314
|
+
const attrFooter = element.getAttribute('data-margin-bottom') || element.getAttribute('data-footer-height') || element.getAttribute('data-margin-vertical');
|
|
6315
|
+
const parsedFooter = parseFloat(attrFooter);
|
|
6316
|
+
if (!isNaN(parsedFooter)) {
|
|
6317
|
+
this.DataSheet.publicationTemplateBackgroundHeightFooter =
|
|
6318
|
+
parsedFooter;
|
|
6319
|
+
this.DataSheet.publicationTemplateBackgroundFooterY =
|
|
6320
|
+
this.DataSheet.publicationTemplateHeight - parsedFooter;
|
|
6321
|
+
}
|
|
6322
|
+
else {
|
|
6323
|
+
this.DataSheet.publicationTemplateBackgroundHeightFooter = 0;
|
|
6324
|
+
this.DataSheet.publicationTemplateBackgroundFooterY =
|
|
6325
|
+
this.DataSheet.publicationTemplateHeight;
|
|
6326
|
+
}
|
|
6327
|
+
// MARGIN
|
|
6328
|
+
const attrMarginLeft = element.getAttribute('data-margin-left') || element.getAttribute('data-margin-horizontal');
|
|
6329
|
+
const attrMarginRight = element.getAttribute('data-margin-right') || element.getAttribute('data-margin-horizontal');
|
|
6330
|
+
const parsedMarginLeft = parseFloat(attrMarginLeft);
|
|
6331
|
+
if (!isNaN(parsedMarginLeft)) {
|
|
6332
|
+
this.DataSheet.publicationTemplateBackgroundLeftMargin =
|
|
6333
|
+
parsedMarginLeft;
|
|
6334
|
+
}
|
|
6335
|
+
else {
|
|
6336
|
+
this.DataSheet.publicationTemplateBackgroundLeftMargin = 0;
|
|
6337
|
+
}
|
|
6338
|
+
const parsedMarginRight = parseFloat(attrMarginRight);
|
|
6339
|
+
if (!isNaN(parsedMarginRight)) {
|
|
6340
|
+
this.DataSheet.publicationTemplateBackgroundRightMargin =
|
|
6341
|
+
parsedMarginRight;
|
|
6342
|
+
this.DataSheet.publicationTemplateBackgroundMarginX =
|
|
6343
|
+
this.DataSheet.publicationTemplateWidth - parsedMarginRight;
|
|
6344
|
+
}
|
|
6345
|
+
else {
|
|
6346
|
+
this.DataSheet.publicationTemplateBackgroundRightMargin = 0;
|
|
6347
|
+
this.DataSheet.publicationTemplateBackgroundMarginX =
|
|
6348
|
+
this.DataSheet.publicationTemplateWidth;
|
|
6349
|
+
}
|
|
6350
|
+
}
|
|
6351
|
+
// GROUPE <g>
|
|
6352
|
+
else if (tagName === 'g') {
|
|
6353
|
+
group = true;
|
|
6354
|
+
const tag = this.DataSheetSVG.SetAllInfos(element);
|
|
6355
|
+
lstBackgroundTags.push(tag);
|
|
6356
|
+
}
|
|
6357
|
+
// STYLE
|
|
6358
|
+
else if (tagName === 'style') {
|
|
6359
|
+
const styleContent = element.textContent;
|
|
6360
|
+
const importMatch = styleContent.match(/@import\s+url\("https:\/\/fonts\.googleapis\.com.*?"\);/);
|
|
6361
|
+
if (importMatch &&
|
|
6362
|
+
!this.DataSheet.DictImportFontFamily.push(importMatch[0])) {
|
|
6363
|
+
this.DataSheet.importFontFamily += importMatch[0] + ' ';
|
|
6364
|
+
this.DataSheet.DictImportFontFamily.push(importMatch[0]);
|
|
6365
|
+
}
|
|
6366
|
+
const fontFaceMatches = styleContent.match(/@font-face\s*\{[^}]+\}/g);
|
|
6367
|
+
if (fontFaceMatches) {
|
|
6368
|
+
fontFaceMatches.forEach((block) => {
|
|
6369
|
+
if (!this.DataSheet.DictImportFontFamily.push(block)) {
|
|
6370
|
+
this.DataSheet.importFontFamily += block + '\n';
|
|
6371
|
+
this.DataSheet.DictImportFontFamily.push(block);
|
|
6372
|
+
}
|
|
6373
|
+
});
|
|
6374
|
+
}
|
|
6375
|
+
}
|
|
6376
|
+
// GROUPED ELEMENTS INSIDE <g>
|
|
6377
|
+
else if (group === true &&
|
|
6378
|
+
element.parentElement?.tagName?.toLowerCase() === 'g') {
|
|
6379
|
+
const tag = this.DataSheetSVG.SetAllInfos(element);
|
|
6380
|
+
lstBackgroundTags.push(tag);
|
|
6381
|
+
}
|
|
6382
|
+
});
|
|
6383
|
+
let lstSkus = [];
|
|
6384
|
+
lstSkus = [];
|
|
6385
|
+
if (displayModeVariant === 2) {
|
|
6386
|
+
for (const jObject of lstSkuObjects) {
|
|
6387
|
+
if (jObject != null && jObject !== '') {
|
|
6388
|
+
if ('hasVariant' in jObject) {
|
|
6389
|
+
if (jObject['hasVariant'] === 'true') {
|
|
6390
|
+
if (Array.isArray(jObject['skus']) &&
|
|
6391
|
+
Array.isArray(jObject['skus'][0]) &&
|
|
6392
|
+
jObject['skus'][0].length > 0) {
|
|
6393
|
+
for (const sku of jObject['skus'][0]) {
|
|
6394
|
+
lstSkus.push(sku);
|
|
6395
|
+
}
|
|
6396
|
+
}
|
|
6397
|
+
}
|
|
6398
|
+
else {
|
|
6399
|
+
lstSkus.push(jObject);
|
|
6400
|
+
}
|
|
6401
|
+
}
|
|
6402
|
+
else {
|
|
6403
|
+
lstSkus.push(jObject);
|
|
6404
|
+
}
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6408
|
+
else {
|
|
6409
|
+
lstSkus = [...lstSkuObjects];
|
|
6410
|
+
}
|
|
6411
|
+
let fileIndex = 0;
|
|
6412
|
+
const pagesConfigs = this.DataSheet.pagesSettings || [];
|
|
6413
|
+
const iterations = pagesConfigs.length > 0 ? pagesConfigs.length : 1;
|
|
6414
|
+
for (let p = 0; p < iterations; p++) {
|
|
6415
|
+
const pageConfig = pagesConfigs[p];
|
|
6416
|
+
let currentBackgroundTpl = backgroundTpl;
|
|
6417
|
+
if (pageConfig) {
|
|
6418
|
+
if (pageConfig.backgroundGuid) {
|
|
6419
|
+
const bg = this.DataSheet.backgrounds.find((b) => b.backgroundGuid === pageConfig.backgroundGuid);
|
|
6420
|
+
if (bg && bg.svgImage) {
|
|
6421
|
+
currentBackgroundTpl = bg.svgImage;
|
|
6422
|
+
}
|
|
6423
|
+
}
|
|
6424
|
+
if (pageConfig.gabaritGuid) {
|
|
6425
|
+
this.DataSheet.defaultGabaritGuid = pageConfig.gabaritGuid;
|
|
6426
|
+
}
|
|
6427
|
+
}
|
|
6428
|
+
let i = 0;
|
|
6429
|
+
for (const jObject of lstSkus) {
|
|
6430
|
+
let aJobject = [];
|
|
6431
|
+
aJobject.push(jObject);
|
|
6432
|
+
const newFiles = await this.DataSheetSVG.GenerateSvgFiles(aJobject, currentBackgroundTpl, currentBackgroundTpl, fileIndex.toString());
|
|
6433
|
+
if (newFiles) {
|
|
6434
|
+
files = files.concat(newFiles);
|
|
6435
|
+
fileIndex += newFiles.length;
|
|
6436
|
+
}
|
|
6437
|
+
aJobject.length = 0; // clear array
|
|
6438
|
+
i++;
|
|
6439
|
+
}
|
|
6440
|
+
}
|
|
6441
|
+
lstBackgroundTags = [];
|
|
6442
|
+
arrayFiles = arrayFiles.concat(files);
|
|
6443
|
+
this.DataSheet.nbSections++;
|
|
6444
|
+
}
|
|
6445
|
+
return arrayFiles;
|
|
6446
|
+
}
|
|
6447
|
+
catch (e) {
|
|
6448
|
+
console.log('[ERROR] Error in GenerateAllInOneExportFile:', e);
|
|
6449
|
+
return null;
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6452
|
+
}
|
|
6453
|
+
|
|
6454
|
+
class DataSheetPublication {
|
|
6455
|
+
constructor(dataSheetSVG, dataSheet, publication = null, sectionActiveObject = null, skusSection = []) {
|
|
6456
|
+
this.languagePreviewSelected = 'fr';
|
|
6457
|
+
this.skusSection = [];
|
|
6458
|
+
this.skusSectionPreview = [];
|
|
6459
|
+
if (!dataSheet) {
|
|
6460
|
+
throw new Error('DataSheet instance is required to create a DataSheetSVG');
|
|
6461
|
+
}
|
|
6462
|
+
this.DataSheet = dataSheet;
|
|
6463
|
+
this.DataSheetSVG = dataSheetSVG;
|
|
6464
|
+
this.publication = publication;
|
|
6465
|
+
this.sectionActiveObject = sectionActiveObject;
|
|
6466
|
+
this.skusSection = skusSection;
|
|
6467
|
+
}
|
|
6468
|
+
async setPublicationsService(publicationsService) {
|
|
6469
|
+
if (!publicationsService) {
|
|
6470
|
+
throw new Error('PublicationsService instance is required');
|
|
6471
|
+
}
|
|
6472
|
+
this.publicationsService = publicationsService;
|
|
6473
|
+
}
|
|
6474
|
+
async setDamAssetsService(damAssetsService) {
|
|
6475
|
+
this.damAssetsService = damAssetsService;
|
|
6476
|
+
}
|
|
6477
|
+
async setDocumentsService(documentsService) {
|
|
6478
|
+
this.documentsService = documentsService;
|
|
6479
|
+
}
|
|
6480
|
+
async GenerateAllInOneExportFile(sourceId, option1PerPage, displayModeVariant, multiColumns = true) {
|
|
6481
|
+
try {
|
|
6482
|
+
let publication = this.publication;
|
|
6483
|
+
if (publication?.publicationCoverpage != '' &&
|
|
6484
|
+
publication?.publicationCoverpage != null &&
|
|
6485
|
+
publication?.publicationCoverpage != undefined) {
|
|
6486
|
+
this.DataSheet.leftPage = !this.DataSheet.leftPage;
|
|
6487
|
+
}
|
|
6488
|
+
this.DataSheet.nameFinalName = publication.publicationGuid;
|
|
6489
|
+
if (this.DataSheet.nameFinalName != null) {
|
|
6490
|
+
this.DataSheet.nameFinalName = String(this.DataSheet.nameFinalName)
|
|
6491
|
+
.replace(/\//g, '-')
|
|
6492
|
+
.replace(/\\/g, '-')
|
|
6493
|
+
.replace(/\+/g, '-');
|
|
6494
|
+
}
|
|
6495
|
+
let sections = [];
|
|
6496
|
+
if (this.DataSheet.preview) {
|
|
6497
|
+
sections = this.sectionActiveObject ? [this.sectionActiveObject] : [];
|
|
6498
|
+
}
|
|
6499
|
+
else {
|
|
6500
|
+
sections = [];
|
|
6501
|
+
if (sections.length == 0) {
|
|
6502
|
+
console.log('[PUBLICATIONS] No pages detected try to get pages');
|
|
6503
|
+
if (!this.publicationsService) {
|
|
6504
|
+
throw new Error('PublicationsService instance is required');
|
|
6505
|
+
}
|
|
6506
|
+
const pages = await firstValueFrom(this.publicationsService.getPageOfPublication(publication));
|
|
6507
|
+
sections = pages['getPublicationPages'];
|
|
6508
|
+
}
|
|
6509
|
+
}
|
|
6510
|
+
let lstSkuObjects = [];
|
|
6511
|
+
let lstBackgroundTags = [];
|
|
6512
|
+
let coverTpl = '';
|
|
6513
|
+
let arrayFiles = [];
|
|
6514
|
+
// boucler sur sections
|
|
6515
|
+
this.DataSheet.maxSections = sections.length;
|
|
6516
|
+
this.DataSheet.nbSections = 0;
|
|
6517
|
+
for (let section of sections) {
|
|
6518
|
+
this.DataSheet.currentSectionName = section.name;
|
|
6519
|
+
let files = [];
|
|
6520
|
+
this.DataSheet.currentStep = 1;
|
|
6521
|
+
lstSkuObjects = [];
|
|
6522
|
+
if (this.DataSheet.preview) {
|
|
6523
|
+
let skus = this.skusSection;
|
|
6524
|
+
for (let sku of skus) {
|
|
6525
|
+
if (sku == null || sku == undefined) {
|
|
6526
|
+
continue;
|
|
6527
|
+
}
|
|
6528
|
+
lstSkuObjects.push(sku);
|
|
6529
|
+
}
|
|
6530
|
+
}
|
|
6531
|
+
else {
|
|
6532
|
+
if (section.type === 'DOCUMENT') {
|
|
6533
|
+
if (!this.publicationsService) {
|
|
6534
|
+
throw new Error('PublicationsService instance is required');
|
|
6535
|
+
}
|
|
6536
|
+
const resVal = await this.publicationsService
|
|
6537
|
+
.getSkuForThisPage(section)
|
|
6538
|
+
.toPromise();
|
|
6539
|
+
const skusVal = resVal?.['getPublicationProductsOfAPage'];
|
|
6540
|
+
if (Array.isArray(skusVal)) {
|
|
6541
|
+
for (let sku of skusVal) {
|
|
6542
|
+
if (sku)
|
|
6543
|
+
lstSkuObjects.push(sku);
|
|
6544
|
+
}
|
|
6545
|
+
}
|
|
6546
|
+
}
|
|
6547
|
+
else {
|
|
6548
|
+
if (!this.publicationsService) {
|
|
6549
|
+
throw new Error('PublicationsService instance is required');
|
|
6550
|
+
}
|
|
6551
|
+
const res = await this.publicationsService
|
|
6552
|
+
.getSkuForThisPagePreview(publication.publicationGuid, section.pageId, this.DataSheet.language, this.DataSheet.ratebase, this.DataSheet.priceListGuid, this.DataSheet.accountGuid, 99999)
|
|
6553
|
+
.toPromise();
|
|
6554
|
+
let skus = res?.['skus'];
|
|
6555
|
+
if (!Array.isArray(skus)) {
|
|
6556
|
+
console.log('[ERROR] No SKUs found for this page:', section.pageId);
|
|
6557
|
+
skus = [];
|
|
6558
|
+
}
|
|
6559
|
+
for (let sku of skus) {
|
|
6560
|
+
if (sku == null || sku == undefined) {
|
|
6561
|
+
continue;
|
|
6562
|
+
}
|
|
6563
|
+
lstSkuObjects.push(sku);
|
|
6564
|
+
}
|
|
6565
|
+
}
|
|
6566
|
+
}
|
|
6567
|
+
this.DataSheet.progress += (50 / sections.length) * 0.2;
|
|
6568
|
+
this.DataSheet.currentStep = 2;
|
|
6569
|
+
this.DataSheet.nbSkusSection = 0;
|
|
6570
|
+
this.DataSheet.maxSkusSection = lstSkuObjects.length;
|
|
6571
|
+
let attributePublication = this.publication?.publicationAttributes
|
|
6572
|
+
? this.publication.publicationAttributes
|
|
6573
|
+
: null;
|
|
6574
|
+
// --- Collect and resolve asset GUIDs ---
|
|
6575
|
+
const assetGuidToNameMap = new Map();
|
|
6576
|
+
if (Array.isArray(attributePublication) && this.damAssetsService) {
|
|
6577
|
+
const assetGuidsToFetch = new Set();
|
|
6578
|
+
lstSkuObjects.forEach((sku) => {
|
|
6579
|
+
attributePublication.forEach((info) => {
|
|
6580
|
+
const attrs = info.attributes;
|
|
6581
|
+
if (!Array.isArray(attrs))
|
|
6582
|
+
return;
|
|
6583
|
+
attrs.forEach((attr) => {
|
|
6584
|
+
if (['image', 'file'].includes(attr.attributeType)) {
|
|
6585
|
+
let val = attr.attributeValue;
|
|
6586
|
+
if (Array.isArray(val)) {
|
|
6587
|
+
val.forEach((g) => {
|
|
6588
|
+
if (g && typeof g === 'string')
|
|
6589
|
+
assetGuidsToFetch.add(g);
|
|
6590
|
+
});
|
|
6591
|
+
}
|
|
6592
|
+
else if (val && typeof val === 'string') {
|
|
6593
|
+
assetGuidsToFetch.add(val);
|
|
6594
|
+
}
|
|
6595
|
+
}
|
|
6596
|
+
});
|
|
6597
|
+
});
|
|
6598
|
+
});
|
|
6599
|
+
if (assetGuidsToFetch.size > 0) {
|
|
6600
|
+
try {
|
|
6601
|
+
const res = await firstValueFrom(this.damAssetsService.getAssetByGuids({
|
|
6602
|
+
assetGuids: Array.from(assetGuidsToFetch),
|
|
6603
|
+
}));
|
|
6604
|
+
const assets = res?.['assets'];
|
|
6605
|
+
if (Array.isArray(assets)) {
|
|
6606
|
+
assets.forEach((asset) => {
|
|
6607
|
+
if (asset?.assetGuid && asset?.assetName) {
|
|
6608
|
+
assetGuidToNameMap.set(asset.assetGuid, asset.assetName);
|
|
6609
|
+
}
|
|
6610
|
+
});
|
|
6611
|
+
}
|
|
6612
|
+
}
|
|
6613
|
+
catch (e) {
|
|
6614
|
+
console.error("Erreur lors du chargement des noms d'assets :", e);
|
|
6615
|
+
}
|
|
6616
|
+
}
|
|
6617
|
+
}
|
|
6618
|
+
lstSkuObjects.forEach((sku) => {
|
|
6619
|
+
try {
|
|
6620
|
+
const skuObj = sku;
|
|
6621
|
+
let existingAttributes = Array.isArray(skuObj.attributePublication)
|
|
6622
|
+
? skuObj.attributePublication
|
|
6623
|
+
: [];
|
|
6624
|
+
const attributeDict = {};
|
|
6625
|
+
existingAttributes.forEach((item) => {
|
|
6626
|
+
const guid = Object.keys(item)[0];
|
|
6627
|
+
const val = item[guid];
|
|
6628
|
+
attributeDict[guid] = val;
|
|
6629
|
+
});
|
|
6630
|
+
// Merge page-level attributes from the SKU's section
|
|
6631
|
+
const pageAttributes = skuObj.pageAttributes;
|
|
6632
|
+
if (Array.isArray(pageAttributes)) {
|
|
6633
|
+
pageAttributes.forEach((group) => {
|
|
6634
|
+
if (group && Array.isArray(group.attributes)) {
|
|
6635
|
+
group.attributes.forEach((attr) => {
|
|
6636
|
+
const guid = attr.attributeGuid;
|
|
6637
|
+
if (!guid)
|
|
6638
|
+
return;
|
|
6639
|
+
const lang = this.languagePreviewSelected.toLowerCase();
|
|
6640
|
+
let val = null;
|
|
6641
|
+
if (attr.attributeValue && typeof attr.attributeValue === 'object') {
|
|
6642
|
+
val = attr.attributeValue[lang] || attr.attributeValue[this.languagePreviewSelected] || '';
|
|
6643
|
+
}
|
|
6644
|
+
else {
|
|
6645
|
+
val = attr.attributeValue || '';
|
|
6646
|
+
}
|
|
6647
|
+
if (val !== null && val !== undefined && val !== '') {
|
|
6648
|
+
attributeDict[guid] = val;
|
|
6649
|
+
}
|
|
6650
|
+
});
|
|
6651
|
+
}
|
|
6652
|
+
});
|
|
6653
|
+
}
|
|
6654
|
+
if (Array.isArray(attributePublication)) {
|
|
6655
|
+
attributePublication.forEach((info) => {
|
|
6656
|
+
const attrs = info.attributes;
|
|
6657
|
+
if (!Array.isArray(attrs))
|
|
6658
|
+
return;
|
|
6659
|
+
attrs.forEach((attr) => {
|
|
6660
|
+
const guid = attr.attributeGuid;
|
|
6661
|
+
if (!guid)
|
|
6662
|
+
return;
|
|
6663
|
+
const lang = this.languagePreviewSelected.toLowerCase();
|
|
6664
|
+
let val = null;
|
|
6665
|
+
if (attr.attributeType === 'image' ||
|
|
6666
|
+
Array.isArray(attr.attributeValue)) {
|
|
6667
|
+
val = attr.attributeValue;
|
|
6668
|
+
}
|
|
6669
|
+
else if (attr.attributeValue &&
|
|
6670
|
+
typeof attr.attributeValue === 'object') {
|
|
6671
|
+
val = attr.attributeValue[lang];
|
|
6672
|
+
}
|
|
6673
|
+
else {
|
|
6674
|
+
val = attr.attributeValue;
|
|
6675
|
+
}
|
|
6676
|
+
const isOptionType = [
|
|
6677
|
+
'dropDown',
|
|
6678
|
+
'radio',
|
|
6679
|
+
'checkbox',
|
|
6680
|
+
'multiSelect',
|
|
6681
|
+
].includes(attr.attributeType);
|
|
6682
|
+
if (isOptionType && attr.attributeOptions) {
|
|
6683
|
+
let options = attr.attributeOptions;
|
|
6684
|
+
if (typeof options === 'string') {
|
|
6685
|
+
try {
|
|
6686
|
+
options = JSON.parse(options);
|
|
6687
|
+
}
|
|
6688
|
+
catch (e) {
|
|
6689
|
+
console.error('Erreur parsing options de publication :', e);
|
|
6690
|
+
}
|
|
6691
|
+
}
|
|
6692
|
+
if (options && typeof options === 'object') {
|
|
6693
|
+
const resolveOption = (optKey) => {
|
|
6694
|
+
if (!optKey)
|
|
6695
|
+
return '';
|
|
6696
|
+
const opt = options[optKey];
|
|
6697
|
+
if (!opt)
|
|
6698
|
+
return optKey;
|
|
6699
|
+
return opt[lang] || opt['fr'] || opt['en'] || optKey;
|
|
6700
|
+
};
|
|
6701
|
+
if (Array.isArray(val)) {
|
|
6702
|
+
val = val
|
|
6703
|
+
.map((optKey) => resolveOption(optKey))
|
|
6704
|
+
.filter((v) => v !== '')
|
|
6705
|
+
.join('#');
|
|
6706
|
+
}
|
|
6707
|
+
else if (val) {
|
|
6708
|
+
val = resolveOption(val);
|
|
6709
|
+
}
|
|
6710
|
+
}
|
|
6711
|
+
}
|
|
6712
|
+
const isAssetType = ['image', 'file'].includes(attr.attributeType);
|
|
6713
|
+
if (isAssetType) {
|
|
6714
|
+
const resolveAsset = (guid) => {
|
|
6715
|
+
if (!guid)
|
|
6716
|
+
return '';
|
|
6717
|
+
return assetGuidToNameMap.get(guid) || guid;
|
|
6718
|
+
};
|
|
6719
|
+
if (Array.isArray(val)) {
|
|
6720
|
+
val = val
|
|
6721
|
+
.map((g) => resolveAsset(g))
|
|
6722
|
+
.filter((v) => v !== '')
|
|
6723
|
+
.join('#');
|
|
6724
|
+
}
|
|
6725
|
+
else if (val) {
|
|
6726
|
+
val = resolveAsset(val);
|
|
6727
|
+
}
|
|
6728
|
+
}
|
|
6729
|
+
// -----------------------
|
|
6730
|
+
const hasValidValue = val !== null &&
|
|
6731
|
+
val !== undefined &&
|
|
6732
|
+
(Array.isArray(val)
|
|
6733
|
+
? val.length > 0
|
|
6734
|
+
: val.toString().trim() !== '');
|
|
6735
|
+
if (hasValidValue) {
|
|
6736
|
+
const existingVal = attributeDict[guid];
|
|
6737
|
+
const hasExisting = existingVal !== null &&
|
|
6738
|
+
existingVal !== undefined &&
|
|
6739
|
+
(Array.isArray(existingVal)
|
|
6740
|
+
? existingVal.length > 0
|
|
6741
|
+
: existingVal.toString().trim() !== '');
|
|
6742
|
+
if (!hasExisting) {
|
|
6743
|
+
attributeDict[guid] = val;
|
|
6744
|
+
}
|
|
6745
|
+
}
|
|
6746
|
+
});
|
|
6747
|
+
});
|
|
6748
|
+
}
|
|
6749
|
+
const mergedAttributes = Object.entries(attributeDict).map(([key, value]) => ({ [key]: value }));
|
|
6750
|
+
skuObj.attributePublication = mergedAttributes;
|
|
6751
|
+
}
|
|
6752
|
+
catch (e) {
|
|
6753
|
+
console.error("Erreur de traitement d'un SKU:", e);
|
|
6754
|
+
}
|
|
6755
|
+
});
|
|
6756
|
+
let pages = [];
|
|
6757
|
+
if (section.type === 'MARKETING') {
|
|
6758
|
+
let countPage = 0;
|
|
6759
|
+
for (let sku of lstSkuObjects) {
|
|
6760
|
+
if (sku == null || sku == undefined) {
|
|
6761
|
+
continue;
|
|
6762
|
+
}
|
|
6763
|
+
let background = this.DataSheetSVG.getMarketingSectionForPreview(sku);
|
|
6764
|
+
if (background == null) {
|
|
6765
|
+
continue;
|
|
6766
|
+
}
|
|
6767
|
+
let backgroundTpl = background.svgImage;
|
|
6768
|
+
let allBackgroundTags = this.DataSheetSVG.GetSvgGroupToReplace(backgroundTpl);
|
|
6769
|
+
let allElements = this.DataSheetSVG.GetAllTags(backgroundTpl);
|
|
6770
|
+
let group = false;
|
|
6771
|
+
if (allElements != null) {
|
|
6772
|
+
allElements.forEach((element) => {
|
|
6773
|
+
const tagName = element.tagName?.toLowerCase();
|
|
6774
|
+
if (tagName === 'svg') {
|
|
6775
|
+
// HEADER HEIGHT
|
|
6776
|
+
const attrHeader = element.getAttribute('data-margin-top') || element.getAttribute('data-header-height') || element.getAttribute('data-margin-vertical');
|
|
6777
|
+
const parsedHeader = Number.parseFloat(attrHeader);
|
|
6778
|
+
if (Number.isNaN(parsedHeader)) {
|
|
6779
|
+
this.DataSheet.publicationTemplateBackgroundHeightHeader = 0;
|
|
6780
|
+
}
|
|
6781
|
+
else {
|
|
6782
|
+
this.DataSheet.publicationTemplateBackgroundHeightHeader =
|
|
6783
|
+
parsedHeader;
|
|
6784
|
+
}
|
|
6785
|
+
// FOOTER HEIGHT
|
|
6786
|
+
const attrFooter = element.getAttribute('data-margin-bottom') || element.getAttribute('data-footer-height') || element.getAttribute('data-margin-vertical');
|
|
6787
|
+
const parsedFooter = Number.parseFloat(attrFooter);
|
|
6788
|
+
if (Number.isNaN(parsedFooter)) {
|
|
6789
|
+
this.DataSheet.publicationTemplateBackgroundHeightFooter = 0;
|
|
6790
|
+
this.DataSheet.publicationTemplateBackgroundFooterY =
|
|
6791
|
+
this.DataSheet.publicationTemplateHeight;
|
|
6792
|
+
}
|
|
6793
|
+
else {
|
|
6794
|
+
this.DataSheet.publicationTemplateBackgroundHeightFooter =
|
|
6795
|
+
parsedFooter;
|
|
6796
|
+
this.DataSheet.publicationTemplateBackgroundFooterY =
|
|
6797
|
+
this.DataSheet.publicationTemplateHeight - parsedFooter;
|
|
6798
|
+
}
|
|
6799
|
+
// MARGIN
|
|
6800
|
+
const attrMarginLeft = element.getAttribute('data-margin-left') || element.getAttribute('data-margin-horizontal');
|
|
6801
|
+
const attrMarginRight = element.getAttribute('data-margin-right') || element.getAttribute('data-margin-horizontal');
|
|
6802
|
+
const parsedMarginLeft = Number.parseFloat(attrMarginLeft);
|
|
6803
|
+
if (Number.isNaN(parsedMarginLeft)) {
|
|
6804
|
+
this.DataSheet.publicationTemplateBackgroundLeftMargin = 0;
|
|
6805
|
+
}
|
|
6806
|
+
else {
|
|
6807
|
+
this.DataSheet.publicationTemplateBackgroundLeftMargin = parsedMarginLeft;
|
|
6808
|
+
}
|
|
6809
|
+
const parsedMarginRight = Number.parseFloat(attrMarginRight);
|
|
6810
|
+
if (Number.isNaN(parsedMarginRight)) {
|
|
6811
|
+
this.DataSheet.publicationTemplateBackgroundRightMargin = 0;
|
|
6812
|
+
this.DataSheet.publicationTemplateBackgroundMarginX = this.DataSheet.publicationTemplateWidth;
|
|
6813
|
+
}
|
|
6814
|
+
else {
|
|
6815
|
+
this.DataSheet.publicationTemplateBackgroundRightMargin = parsedMarginRight;
|
|
6816
|
+
this.DataSheet.publicationTemplateBackgroundMarginX = this.DataSheet.publicationTemplateWidth - parsedMarginRight;
|
|
6817
|
+
}
|
|
6818
|
+
}
|
|
6819
|
+
// GROUPE <g>
|
|
6820
|
+
else if (tagName === 'g') {
|
|
6821
|
+
group = true;
|
|
6822
|
+
const tag = this.DataSheetSVG.SetAllInfos(element);
|
|
6823
|
+
lstBackgroundTags.push(tag);
|
|
6824
|
+
}
|
|
6825
|
+
// STYLE
|
|
6826
|
+
else if (tagName === 'style') {
|
|
6827
|
+
const styleContent = element.textContent;
|
|
6828
|
+
const importMatch = styleContent.match(/@import\s+url\("https:\/\/fonts\.googleapis\.com.*?"\);/);
|
|
6829
|
+
if (importMatch &&
|
|
6830
|
+
!this.DataSheet.DictImportFontFamily.push(importMatch[0])) {
|
|
6831
|
+
this.DataSheet.importFontFamily += importMatch[0] + ' ';
|
|
6832
|
+
this.DataSheet.DictImportFontFamily.push(importMatch[0]);
|
|
6833
|
+
}
|
|
6834
|
+
const fontFaceMatches = styleContent.match(/@font-face\s*\{[^}]+\}/g);
|
|
6835
|
+
if (fontFaceMatches) {
|
|
6836
|
+
fontFaceMatches.forEach((block) => {
|
|
6837
|
+
if (!this.DataSheet.DictImportFontFamily.push(block)) {
|
|
6838
|
+
this.DataSheet.importFontFamily += block + '\n';
|
|
6839
|
+
this.DataSheet.DictImportFontFamily.push(block);
|
|
6840
|
+
}
|
|
6841
|
+
});
|
|
6842
|
+
}
|
|
6843
|
+
}
|
|
6844
|
+
// GROUPED ELEMENTS INSIDE <g>
|
|
6845
|
+
else if (group === true &&
|
|
6846
|
+
element.parentElement?.tagName?.toLowerCase() === 'g') {
|
|
6847
|
+
const tag = this.DataSheetSVG.SetAllInfos(element);
|
|
6848
|
+
lstBackgroundTags.push(tag);
|
|
6849
|
+
}
|
|
6850
|
+
});
|
|
6851
|
+
}
|
|
6852
|
+
let lstSkus = [];
|
|
6853
|
+
let files2 = await this.DataSheetSVG.GenerateSvgFiles(lstSkus, backgroundTpl, backgroundTpl, section.pageId.toString());
|
|
6854
|
+
if (files2 != null) {
|
|
6855
|
+
files2[0]['name'] = files2[0]['name'].replace(/_page\[\d+\]/, `_page[${countPage}]`);
|
|
6856
|
+
files = files.concat(files2);
|
|
6857
|
+
countPage++;
|
|
6858
|
+
}
|
|
6859
|
+
lstBackgroundTags = [];
|
|
6860
|
+
}
|
|
6861
|
+
}
|
|
6862
|
+
else if (section.type === 'DOCUMENT') {
|
|
6863
|
+
try {
|
|
6864
|
+
for (const sku of lstSkuObjects) {
|
|
6865
|
+
if (sku && sku.documentGuid) {
|
|
6866
|
+
if (!this.documentsService) {
|
|
6867
|
+
throw new Error('DocumentsService instance is required');
|
|
6868
|
+
}
|
|
6869
|
+
const resDoc = await this.documentsService
|
|
6870
|
+
.getDocument(sku.documentGuid)
|
|
6871
|
+
.toPromise();
|
|
6872
|
+
if (resDoc && resDoc['template']) {
|
|
6873
|
+
const nbPages = resDoc['template'].length;
|
|
6874
|
+
for (let i = 0; i < nbPages; i++) {
|
|
6875
|
+
this.DataSheet.leftPage = !this.DataSheet.leftPage;
|
|
6876
|
+
}
|
|
6877
|
+
}
|
|
6878
|
+
}
|
|
6879
|
+
}
|
|
6880
|
+
}
|
|
6881
|
+
catch (e) {
|
|
6882
|
+
console.error('[ERROR] Error processing DOCUMENT section for page alternation:', e);
|
|
6883
|
+
}
|
|
6884
|
+
continue;
|
|
6885
|
+
}
|
|
6886
|
+
else {
|
|
6887
|
+
let background = this.DataSheetSVG.getBackgroundSectionForPreview(section);
|
|
6888
|
+
let backgroundTpl = background.svgImage;
|
|
6889
|
+
let allBackgroundTags = this.DataSheetSVG.GetSvgGroupToReplace(backgroundTpl);
|
|
6890
|
+
// 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
|
|
6891
|
+
let backgroundTplLeft = this.DataSheetSVG.keepOnlySideRegex(backgroundTpl, 'left');
|
|
6892
|
+
let backgroundTplRight = this.DataSheetSVG.keepOnlySideRegex(backgroundTpl, 'right');
|
|
6893
|
+
let allElements = this.DataSheetSVG.GetAllTags(backgroundTplLeft);
|
|
6894
|
+
let group = false;
|
|
6895
|
+
if (allElements) {
|
|
6896
|
+
allElements.forEach((element) => {
|
|
6897
|
+
const tagName = element.tagName?.toLowerCase();
|
|
6898
|
+
if (tagName === 'svg') {
|
|
6899
|
+
// HEADER HEIGHT
|
|
6900
|
+
const attrHeader = element.getAttribute('data-margin-top') || element.getAttribute('data-header-height') || element.getAttribute('data-margin-vertical') || '0';
|
|
6901
|
+
const parsedHeader = Number.parseFloat(attrHeader);
|
|
6902
|
+
if (Number.isNaN(parsedHeader)) {
|
|
6903
|
+
this.DataSheet.publicationTemplateBackgroundHeightHeader = 0;
|
|
6904
|
+
}
|
|
6905
|
+
else {
|
|
6906
|
+
this.DataSheet.publicationTemplateBackgroundHeightHeader =
|
|
6907
|
+
parsedHeader;
|
|
6908
|
+
}
|
|
6909
|
+
// FOOTER HEIGHT
|
|
6910
|
+
const attrFooter = element.getAttribute('data-margin-bottom') || element.getAttribute('data-footer-height') || element.getAttribute('data-margin-vertical') || '0';
|
|
6911
|
+
const parsedFooter = Number.parseFloat(attrFooter);
|
|
6912
|
+
if (Number.isNaN(parsedFooter)) {
|
|
6913
|
+
this.DataSheet.publicationTemplateBackgroundHeightFooter = 0;
|
|
6914
|
+
this.DataSheet.publicationTemplateBackgroundFooterY =
|
|
6915
|
+
this.DataSheet.publicationTemplateHeight;
|
|
6916
|
+
}
|
|
6917
|
+
else {
|
|
6918
|
+
this.DataSheet.publicationTemplateBackgroundHeightFooter =
|
|
6919
|
+
parsedFooter;
|
|
6920
|
+
this.DataSheet.publicationTemplateBackgroundFooterY =
|
|
6921
|
+
this.DataSheet.publicationTemplateHeight - parsedFooter;
|
|
6922
|
+
}
|
|
6923
|
+
// MARGIN
|
|
6924
|
+
const attrMarginLeft = element.getAttribute('data-margin-left') || element.getAttribute('data-margin-horizontal') || '0';
|
|
6925
|
+
const attrMarginRight = element.getAttribute('data-margin-right') || element.getAttribute('data-margin-horizontal') || '0';
|
|
6926
|
+
const parsedMarginLeft = Number.parseFloat(attrMarginLeft);
|
|
6927
|
+
if (Number.isNaN(parsedMarginLeft)) {
|
|
6928
|
+
this.DataSheet.publicationTemplateBackgroundLeftMargin = 0;
|
|
6929
|
+
}
|
|
6930
|
+
else {
|
|
6931
|
+
this.DataSheet.publicationTemplateBackgroundLeftMargin = parsedMarginLeft;
|
|
6932
|
+
}
|
|
6933
|
+
const parsedMarginRight = Number.parseFloat(attrMarginRight);
|
|
6934
|
+
if (Number.isNaN(parsedMarginRight)) {
|
|
6935
|
+
this.DataSheet.publicationTemplateBackgroundRightMargin = 0;
|
|
6936
|
+
this.DataSheet.publicationTemplateBackgroundMarginX = this.DataSheet.publicationTemplateWidth;
|
|
6937
|
+
}
|
|
6938
|
+
else {
|
|
6939
|
+
this.DataSheet.publicationTemplateBackgroundRightMargin = parsedMarginRight;
|
|
6940
|
+
this.DataSheet.publicationTemplateBackgroundMarginX = this.DataSheet.publicationTemplateWidth - parsedMarginRight;
|
|
6941
|
+
}
|
|
6942
|
+
}
|
|
6943
|
+
// GROUPE <g>
|
|
6944
|
+
else if (tagName === 'g') {
|
|
6945
|
+
group = true;
|
|
6946
|
+
const tag = this.DataSheetSVG.SetAllInfos(element);
|
|
6947
|
+
lstBackgroundTags.push(tag);
|
|
6948
|
+
}
|
|
6949
|
+
// STYLE
|
|
6950
|
+
else if (tagName === 'style') {
|
|
6951
|
+
const styleContent = element.textContent;
|
|
6952
|
+
const importMatch = styleContent.match(/@import\s+url\("https:\/\/fonts\.googleapis\.com.*?"\);/);
|
|
6953
|
+
if (importMatch &&
|
|
6954
|
+
!this.DataSheet.DictImportFontFamily.push(importMatch[0])) {
|
|
6955
|
+
this.DataSheet.importFontFamily += importMatch[0] + ' ';
|
|
6956
|
+
this.DataSheet.DictImportFontFamily.push(importMatch[0]);
|
|
6957
|
+
}
|
|
6958
|
+
const fontFaceMatches = styleContent.match(/@font-face\s*\{[^}]+\}/g);
|
|
6959
|
+
if (fontFaceMatches) {
|
|
6960
|
+
fontFaceMatches.forEach((block) => {
|
|
6961
|
+
if (!this.DataSheet.DictImportFontFamily.push(block)) {
|
|
6962
|
+
this.DataSheet.importFontFamily += block + '\n';
|
|
6963
|
+
this.DataSheet.DictImportFontFamily.push(block);
|
|
6964
|
+
}
|
|
6965
|
+
});
|
|
6966
|
+
}
|
|
6967
|
+
}
|
|
6968
|
+
// GROUPED ELEMENTS INSIDE <g>
|
|
6969
|
+
else if (group === true &&
|
|
6970
|
+
element.parentElement?.tagName?.toLowerCase() === 'g') {
|
|
6971
|
+
const tag = this.DataSheetSVG.SetAllInfos(element);
|
|
6972
|
+
lstBackgroundTags.push(tag);
|
|
6973
|
+
}
|
|
6974
|
+
});
|
|
6975
|
+
}
|
|
6976
|
+
let lstSkus = [];
|
|
6977
|
+
lstSkus = [];
|
|
6978
|
+
if (displayModeVariant === 2) {
|
|
6979
|
+
for (const jObject of lstSkuObjects) {
|
|
6980
|
+
if (jObject != null && jObject !== '') {
|
|
6981
|
+
if ('hasVariant' in jObject) {
|
|
6982
|
+
if (jObject['hasVariant'] === 'true') {
|
|
6983
|
+
if (Array.isArray(jObject['skus']) &&
|
|
6984
|
+
Array.isArray(jObject['skus'][0]) &&
|
|
6985
|
+
jObject['skus'][0].length > 0) {
|
|
6986
|
+
for (const sku of jObject['skus'][0]) {
|
|
6987
|
+
lstSkus.push(sku);
|
|
6988
|
+
}
|
|
6989
|
+
}
|
|
6990
|
+
}
|
|
6991
|
+
else {
|
|
6992
|
+
lstSkus.push(jObject);
|
|
6993
|
+
}
|
|
6994
|
+
}
|
|
6995
|
+
else {
|
|
6996
|
+
lstSkus.push(jObject);
|
|
6997
|
+
}
|
|
6998
|
+
}
|
|
6999
|
+
}
|
|
7000
|
+
}
|
|
7001
|
+
else {
|
|
7002
|
+
lstSkus = [...lstSkuObjects];
|
|
7003
|
+
}
|
|
7004
|
+
files = await this.DataSheetSVG.GenerateSvgFiles(lstSkus, backgroundTplLeft, backgroundTplRight, section.pageId.toString());
|
|
7005
|
+
lstBackgroundTags = [];
|
|
7006
|
+
}
|
|
7007
|
+
arrayFiles = arrayFiles.concat(files);
|
|
7008
|
+
this.DataSheet.nbSections++;
|
|
7009
|
+
}
|
|
7010
|
+
return arrayFiles;
|
|
7011
|
+
}
|
|
7012
|
+
catch (e) {
|
|
7013
|
+
console.log('[ERROR] Error in GenerateAllInOneExportFilePublication:', e);
|
|
7014
|
+
return null;
|
|
7015
|
+
}
|
|
7016
|
+
}
|
|
7017
|
+
}
|
|
7018
|
+
|
|
7019
|
+
class DataSheetController {
|
|
7020
|
+
constructor(http, _generationService, _publicationsService, _priceListService, _attributes, _templates, _publicationsTemplates, _toastr, _notificationService, tr, sanitizer, _damAssets, _documents) {
|
|
7021
|
+
this.http = http;
|
|
7022
|
+
this._generationService = _generationService;
|
|
7023
|
+
this._publicationsService = _publicationsService;
|
|
7024
|
+
this._priceListService = _priceListService;
|
|
7025
|
+
this._attributes = _attributes;
|
|
7026
|
+
this._templates = _templates;
|
|
7027
|
+
this._publicationsTemplates = _publicationsTemplates;
|
|
7028
|
+
this._toastr = _toastr;
|
|
7029
|
+
this._notificationService = _notificationService;
|
|
7030
|
+
this.tr = tr;
|
|
7031
|
+
this.sanitizer = sanitizer;
|
|
7032
|
+
this._damAssets = _damAssets;
|
|
7033
|
+
this._documents = _documents;
|
|
7034
|
+
this.generations = [];
|
|
7035
|
+
this.numGenerations = 0;
|
|
7036
|
+
this.pricesListAvailable = [];
|
|
7037
|
+
this.datasheetPreview = null;
|
|
7038
|
+
this.currentPreviewId = 0;
|
|
7039
|
+
}
|
|
7040
|
+
async GenerateSVG(request) {
|
|
7041
|
+
let json = request;
|
|
7042
|
+
let source = json.source;
|
|
7043
|
+
if (json.sourceGuid === 'all' && source === 3) {
|
|
7044
|
+
source = 1;
|
|
7045
|
+
json.source = 1;
|
|
7046
|
+
}
|
|
7047
|
+
let dataSheet = new DataSheet();
|
|
7048
|
+
dataSheet.versionName = json.versionName;
|
|
7049
|
+
if (json.productSheetGuid) {
|
|
7050
|
+
dataSheet.productSheetGuid = json.productSheetGuid;
|
|
7051
|
+
}
|
|
7052
|
+
dataSheet.preview = json.preview === false ? json.preview : true;
|
|
7053
|
+
// Start le mettre sur page de droite par défaut
|
|
7054
|
+
dataSheet.leftPage = json.leftPage === true ? json.leftPage : false;
|
|
7055
|
+
if (dataSheet.preview) {
|
|
7056
|
+
this.currentPreviewId++;
|
|
7057
|
+
dataSheet.previewId = this.currentPreviewId;
|
|
7058
|
+
}
|
|
7059
|
+
dataSheet.imageFastPreview =
|
|
7060
|
+
json.imageFastPreview === false ? json.imageFastPreview : true;
|
|
7061
|
+
dataSheet.currentStep = 0;
|
|
7062
|
+
let dataSheetSVG = new DataSheetSVG(dataSheet);
|
|
7063
|
+
if (dataSheet.preview) {
|
|
7064
|
+
dataSheetSVG.previewId = dataSheet.previewId;
|
|
7065
|
+
}
|
|
7066
|
+
let activeToast = null;
|
|
7067
|
+
if (!dataSheet.preview) {
|
|
7068
|
+
let num = this.numGenerations;
|
|
7069
|
+
const res = await this.tr.get('generation').toPromise();
|
|
7070
|
+
this.translate = res;
|
|
7071
|
+
dataSheet.translate = this.translate;
|
|
7072
|
+
let gen = {
|
|
7073
|
+
id: num,
|
|
7074
|
+
source: source,
|
|
7075
|
+
sourceGuid: json.sourceGuid,
|
|
7076
|
+
datasheet: dataSheet,
|
|
7077
|
+
date: new Date(),
|
|
7078
|
+
};
|
|
7079
|
+
this.generations.push(gen);
|
|
7080
|
+
this.numGenerations++;
|
|
7081
|
+
activeToast = this._toastr.show('GENERATIONS', 'GENERATION', {
|
|
7082
|
+
positionClass: 'toast-bottom-right',
|
|
7083
|
+
toastClass: 'ngx-toastr',
|
|
7084
|
+
enableHtml: true,
|
|
7085
|
+
timeOut: 0,
|
|
7086
|
+
extendedTimeOut: 0,
|
|
7087
|
+
//toastComponent: ToastComponent
|
|
7088
|
+
});
|
|
7089
|
+
let data = {
|
|
7090
|
+
notifications: {
|
|
7091
|
+
notificationTypeText: 'GENERATION',
|
|
7092
|
+
notificationGeneration: gen,
|
|
7093
|
+
},
|
|
7094
|
+
};
|
|
7095
|
+
activeToast.toastRef.componentInstance.data = data;
|
|
7096
|
+
}
|
|
7097
|
+
let sourceGuids = [];
|
|
7098
|
+
if (source === 4) {
|
|
7099
|
+
sourceGuids = json.sourceGuid;
|
|
7100
|
+
}
|
|
7101
|
+
else {
|
|
7102
|
+
json.sourceGuid =
|
|
7103
|
+
json.sourceGuid === null ||
|
|
7104
|
+
json.sourceGuid === undefined ||
|
|
7105
|
+
json.sourceGuid === ''
|
|
7106
|
+
? ''
|
|
7107
|
+
: json.sourceGuid;
|
|
7108
|
+
}
|
|
7109
|
+
let type = json.type;
|
|
7110
|
+
let displayModeVariant = json.displayModeVariant;
|
|
7111
|
+
dataSheet.language = json.language;
|
|
7112
|
+
dataSheet.coverPage = json.coverPage;
|
|
7113
|
+
let assetTemplate = json.assetTemplate;
|
|
7114
|
+
let pageTemplate = json.pageTemplate;
|
|
7115
|
+
dataSheet.highDefinition = json.highDefinition ?? false;
|
|
7116
|
+
dataSheet.ratebase = json.ratebase;
|
|
7117
|
+
dataSheet.priceListGuid =
|
|
7118
|
+
json.priceListGuid ?? '00000000-0000-0000-0000-000000000000';
|
|
7119
|
+
dataSheet.accountGuid = json.accountGuid;
|
|
7120
|
+
let startPageNumber = 1;
|
|
7121
|
+
// Prépare (= 25% of progress : attributes + fields + prices + gabarits + backgrounds each one : 5%)
|
|
7122
|
+
dataSheet.attributes = json.attributes;
|
|
7123
|
+
if (!dataSheet.attributes || dataSheet.attributes.length === 0) {
|
|
7124
|
+
const [resDropDown, resMultiSelect, resRadio, resCheckbox, resDropDownPublication, resMultiSelectPublication, resRadioPublication, resCheckBoxPublication,] = await Promise.all([
|
|
7125
|
+
this._attributes.getAttributesByType('dropDown', 'skus').toPromise(),
|
|
7126
|
+
this._attributes.getAttributesByType('multiSelect', 'skus').toPromise(),
|
|
7127
|
+
this._attributes.getAttributesByType('radio', 'skus').toPromise(),
|
|
7128
|
+
this._attributes.getAttributesByType('checkbox', 'skus').toPromise(),
|
|
7129
|
+
this._attributes
|
|
7130
|
+
.getAttributesByType('dropDown', 'publications')
|
|
7131
|
+
.toPromise(),
|
|
7132
|
+
this._attributes
|
|
7133
|
+
.getAttributesByType('multiSelect', 'publications')
|
|
7134
|
+
.toPromise(),
|
|
7135
|
+
this._attributes
|
|
7136
|
+
.getAttributesByType('radio', 'publications')
|
|
7137
|
+
.toPromise(),
|
|
7138
|
+
this._attributes
|
|
7139
|
+
.getAttributesByType('checkbox', 'publications')
|
|
7140
|
+
.toPromise(),
|
|
7141
|
+
]);
|
|
7142
|
+
let attributes = [];
|
|
7143
|
+
dataSheet.attributes = attributes.concat(resDropDown['attributes'], resMultiSelect['attributes'], resRadio['attributes'], resCheckbox['attributes'], resDropDownPublication['attributes'], resMultiSelectPublication['attributes'], resRadioPublication['attributes'], resCheckBoxPublication['attributes']);
|
|
7144
|
+
}
|
|
7145
|
+
dataSheet.progress += 5;
|
|
7146
|
+
dataSheet.fields = json.fields;
|
|
7147
|
+
if (!dataSheet.fields || dataSheet.fields.length === 0) {
|
|
7148
|
+
const res = await this._publicationsService
|
|
7149
|
+
.getFieldsPublications()
|
|
7150
|
+
.toPromise();
|
|
7151
|
+
dataSheet.fields = res?.['fields'];
|
|
7152
|
+
}
|
|
7153
|
+
dataSheet.progress += 5;
|
|
7154
|
+
if (dataSheet.ratebase == 0) {
|
|
7155
|
+
dataSheet.accountGuid = '';
|
|
7156
|
+
}
|
|
7157
|
+
else {
|
|
7158
|
+
dataSheet.priceListGuid = '00000000-0000-0000-0000-000000000000';
|
|
7159
|
+
}
|
|
7160
|
+
dataSheet.pricesListCurrency = json.pricesListCurrency;
|
|
7161
|
+
if (!dataSheet.pricesListCurrency ||
|
|
7162
|
+
dataSheet.pricesListCurrency === '' ||
|
|
7163
|
+
dataSheet.pricesListCurrency === undefined) {
|
|
7164
|
+
dataSheet = await this.getPricesListAvailable(dataSheet);
|
|
7165
|
+
if (dataSheet.pricesListCurrency === '' ||
|
|
7166
|
+
dataSheet.pricesListCurrency === undefined) {
|
|
7167
|
+
dataSheet.pricesListCurrency = '€';
|
|
7168
|
+
}
|
|
7169
|
+
}
|
|
7170
|
+
dataSheet.progress += 5;
|
|
7171
|
+
dataSheet.gabarits = json.gabarits;
|
|
7172
|
+
dataSheet.backgrounds = json.backgrounds;
|
|
7173
|
+
dataSheet.marketing = json.marketing;
|
|
7174
|
+
dataSheet.defaultGabaritGuid = json.defaultGabaritGuid;
|
|
7175
|
+
dataSheet.defaultBackgroundGuid = json.defaultBackgroundGuid;
|
|
7176
|
+
dataSheet.pagesSettings = json.pagesSettings;
|
|
7177
|
+
dataSheet.bleedMargin = json.bleedMargin === true;
|
|
7178
|
+
if (dataSheet.bleedMargin) {
|
|
7179
|
+
dataSheet.showCuttingLine = json.cuttingLines === true;
|
|
7180
|
+
}
|
|
7181
|
+
let publication = null;
|
|
7182
|
+
let templateGuid = '00000000-0000-0000-0000-000000000000';
|
|
7183
|
+
if (source == 2) {
|
|
7184
|
+
publication = json.publication;
|
|
7185
|
+
if (publication == null || publication == undefined) {
|
|
7186
|
+
const res = await this._publicationsService
|
|
7187
|
+
.getPublication(json.sourceGuid)
|
|
7188
|
+
.toPromise();
|
|
7189
|
+
publication = res?.['publication'];
|
|
7190
|
+
}
|
|
7191
|
+
if (publication) {
|
|
7192
|
+
dataSheet.currentObjectName = publication.publicationName;
|
|
7193
|
+
startPageNumber = publication.startPageNumber || 1;
|
|
7194
|
+
dataSheet.leftPage = publication.publicationPageStartLeft === true;
|
|
7195
|
+
if (dataSheet.language == null ||
|
|
7196
|
+
dataSheet.language === '' ||
|
|
7197
|
+
dataSheet.language === undefined) {
|
|
7198
|
+
dataSheet.language = publication.publicationLanguage;
|
|
7199
|
+
}
|
|
7200
|
+
if (dataSheet.ratebase == undefined || dataSheet.ratebase == null) {
|
|
7201
|
+
dataSheet.ratebase = publication.publicationRatebase;
|
|
7202
|
+
dataSheet.priceListGuid =
|
|
7203
|
+
publication.publicationPriceListGuid ||
|
|
7204
|
+
'00000000-0000-0000-0000-000000000000';
|
|
7205
|
+
dataSheet.accountGuid = publication.publicationAccountGuid || '';
|
|
7206
|
+
if (dataSheet.ratebase == 0) {
|
|
7207
|
+
dataSheet.accountGuid = '';
|
|
7208
|
+
}
|
|
7209
|
+
else {
|
|
7210
|
+
dataSheet.priceListGuid = '00000000-0000-0000-0000-000000000000';
|
|
7211
|
+
}
|
|
7212
|
+
}
|
|
7213
|
+
}
|
|
7214
|
+
// Template
|
|
7215
|
+
templateGuid =
|
|
7216
|
+
publication.publicationTemplateGuid ||
|
|
7217
|
+
'00000000-0000-0000-0000-000000000000';
|
|
7218
|
+
}
|
|
7219
|
+
else {
|
|
7220
|
+
if (json.templateGuid) {
|
|
7221
|
+
templateGuid = json.templateGuid;
|
|
7222
|
+
}
|
|
7223
|
+
}
|
|
7224
|
+
dataSheet.publicationTemplateTemplateGuid = templateGuid;
|
|
7225
|
+
if (dataSheet.defaultGabaritGuid == null ||
|
|
7226
|
+
dataSheet.defaultGabaritGuid === '' ||
|
|
7227
|
+
dataSheet.defaultGabaritGuid == undefined ||
|
|
7228
|
+
dataSheet.defaultBackgroundGuid == null ||
|
|
7229
|
+
dataSheet.defaultBackgroundGuid === '' ||
|
|
7230
|
+
dataSheet.defaultBackgroundGuid == undefined) {
|
|
7231
|
+
let template = await this.getTemplateInfo(templateGuid);
|
|
7232
|
+
if (template) {
|
|
7233
|
+
dataSheet.defaultGabaritGuid = template.defaultProductBlock;
|
|
7234
|
+
dataSheet.defaultBackgroundGuid = template.defaultBackground;
|
|
7235
|
+
}
|
|
7236
|
+
}
|
|
7237
|
+
if (dataSheet.gabarits == null ||
|
|
7238
|
+
dataSheet.gabarits == undefined ||
|
|
7239
|
+
dataSheet.gabarits.length === 0) {
|
|
7240
|
+
let gabarits = await this.updateGabaritsList(templateGuid, dataSheet.preview ? false : true);
|
|
7241
|
+
dataSheet.gabarits = gabarits;
|
|
7242
|
+
}
|
|
7243
|
+
dataSheet.progress += 3.33;
|
|
7244
|
+
if (dataSheet.backgrounds == null ||
|
|
7245
|
+
dataSheet.backgrounds == undefined ||
|
|
7246
|
+
dataSheet.backgrounds.length === 0) {
|
|
7247
|
+
let backgrounds = await this.updateBackgroundsList(templateGuid, dataSheet.preview ? false : true);
|
|
7248
|
+
dataSheet.backgrounds = backgrounds;
|
|
7249
|
+
}
|
|
7250
|
+
dataSheet.progress += 3.33;
|
|
7251
|
+
if (dataSheet.marketing == null ||
|
|
7252
|
+
dataSheet.marketing == undefined ||
|
|
7253
|
+
dataSheet.marketing.length === 0) {
|
|
7254
|
+
let marketing = await this.updateMarketingList(templateGuid, dataSheet.preview ? false : true);
|
|
7255
|
+
dataSheet.marketing = marketing;
|
|
7256
|
+
}
|
|
7257
|
+
dataSheet.progress += 3.33;
|
|
7258
|
+
if (dataSheet.gabarits == null ||
|
|
7259
|
+
dataSheet.gabarits == undefined ||
|
|
7260
|
+
dataSheet.gabarits.length === 0) {
|
|
7261
|
+
dataSheet.currentStep = 99;
|
|
7262
|
+
return [];
|
|
7263
|
+
}
|
|
7264
|
+
if (dataSheet.backgrounds == null ||
|
|
7265
|
+
dataSheet.backgrounds == undefined ||
|
|
7266
|
+
dataSheet.backgrounds.length === 0) {
|
|
7267
|
+
dataSheet.currentStep = 99;
|
|
7268
|
+
return [];
|
|
7269
|
+
}
|
|
7270
|
+
if (dataSheet.preview) {
|
|
7271
|
+
this.datasheetPreview = dataSheet;
|
|
7272
|
+
}
|
|
7273
|
+
// Everything is ok so PROGRESS = 25%
|
|
7274
|
+
dataSheet.progress = 25;
|
|
7275
|
+
let files = [];
|
|
7276
|
+
switch (source) {
|
|
7277
|
+
case 1: // All SKUS
|
|
7278
|
+
//console.log('[PDF] Fetching SKU list for global batch generation...');
|
|
7279
|
+
try {
|
|
7280
|
+
const res = await this._generationService
|
|
7281
|
+
.getSkusDatas(json.language, json.attributeSkuGuid, templateGuid, json.onlyNeedRegeneration)
|
|
7282
|
+
.toPromise();
|
|
7283
|
+
const skuGuids = res.skuGuids || [];
|
|
7284
|
+
const concurrencyLimit = 5;
|
|
7285
|
+
let currentIndex = 0;
|
|
7286
|
+
const executeTask = async () => {
|
|
7287
|
+
while (currentIndex < skuGuids.length) {
|
|
7288
|
+
const skuGuid = skuGuids[currentIndex++];
|
|
7289
|
+
const currentCount = currentIndex;
|
|
7290
|
+
// console.log(
|
|
7291
|
+
// `[PDF] Generating SKU ${currentCount} of ${skuGuids.length}...`,
|
|
7292
|
+
// );
|
|
7293
|
+
try {
|
|
7294
|
+
let singleJson = {
|
|
7295
|
+
...json,
|
|
7296
|
+
source: 3,
|
|
7297
|
+
sourceGuid: skuGuid,
|
|
7298
|
+
attributes: dataSheet.attributes,
|
|
7299
|
+
fields: dataSheet.fields,
|
|
7300
|
+
gabarits: dataSheet.gabarits,
|
|
7301
|
+
backgrounds: dataSheet.backgrounds,
|
|
7302
|
+
marketing: dataSheet.marketing,
|
|
7303
|
+
pricesListCurrency: dataSheet.pricesListCurrency,
|
|
7304
|
+
defaultGabaritGuid: dataSheet.defaultGabaritGuid,
|
|
7305
|
+
defaultBackgroundGuid: dataSheet.defaultBackgroundGuid,
|
|
7306
|
+
preview: false,
|
|
7307
|
+
};
|
|
7308
|
+
await this.GenerateSVG(singleJson);
|
|
7309
|
+
}
|
|
7310
|
+
catch (err) {
|
|
7311
|
+
console.error(`[ERROR][BATCH] Error in global batch generation: ${skuGuid}`);
|
|
7312
|
+
}
|
|
7313
|
+
}
|
|
7314
|
+
};
|
|
7315
|
+
const workers = [];
|
|
7316
|
+
for (let i = 0; i < Math.min(concurrencyLimit, skuGuids.length); i++) {
|
|
7317
|
+
workers.push(executeTask());
|
|
7318
|
+
}
|
|
7319
|
+
await Promise.all(workers);
|
|
7320
|
+
return ['BATCH_COMPLETED'];
|
|
7321
|
+
}
|
|
7322
|
+
catch (err) {
|
|
7323
|
+
console.error('[PDF] Error in global batch generation:', err);
|
|
7324
|
+
return [];
|
|
7325
|
+
}
|
|
7326
|
+
case 2: // Publication
|
|
7327
|
+
//console.log("Generate SVG for publication");
|
|
7328
|
+
let dataSheetPublication = new DataSheetPublication(dataSheetSVG, dataSheet, publication, json.sectionActiveObject, json.skusSection);
|
|
7329
|
+
dataSheetPublication.setPublicationsService(this._publicationsService);
|
|
7330
|
+
dataSheetPublication.setDamAssetsService(this._damAssets);
|
|
7331
|
+
dataSheetPublication.setDocumentsService(this._documents);
|
|
7332
|
+
files = await dataSheetPublication.GenerateAllInOneExportFile(json.sourceGuid, json.option1PerPage, displayModeVariant, json.multiColumns);
|
|
7333
|
+
dataSheetPublication = null;
|
|
7334
|
+
break;
|
|
7335
|
+
case 3: // SKUs
|
|
7336
|
+
//console.log('Generate SVG for SKUs');
|
|
7337
|
+
let dataSheetSku = new DataSheetSku(dataSheetSVG, dataSheet);
|
|
7338
|
+
dataSheetSku.setPublicationsService(this._publicationsService);
|
|
7339
|
+
files = await dataSheetSku.GenerateAllInOneExportFile(json.sourceGuid, json.option1PerPage, displayModeVariant, json.multiColumns);
|
|
7340
|
+
dataSheetSku = null;
|
|
7341
|
+
break;
|
|
7342
|
+
case 4: // Variants
|
|
7343
|
+
for (let sourceGuid of sourceGuids) {
|
|
7344
|
+
dataSheet.progress = 25;
|
|
7345
|
+
let dataSheetSku = new DataSheetSku(dataSheetSVG, dataSheet);
|
|
7346
|
+
dataSheetSku.setPublicationsService(this._publicationsService);
|
|
7347
|
+
let files2 = await dataSheetSku.GenerateAllInOneExportFile(sourceGuid, json.option1PerPage, displayModeVariant, json.multiColumns);
|
|
7348
|
+
dataSheetSku = null;
|
|
7349
|
+
for (let file of files2) {
|
|
7350
|
+
file.sourceGuid = sourceGuid;
|
|
7351
|
+
}
|
|
7352
|
+
files.push(...files2);
|
|
7353
|
+
}
|
|
7354
|
+
break;
|
|
7355
|
+
}
|
|
7356
|
+
dataSheet.progress = 75;
|
|
7357
|
+
dataSheet.currentStep = 3;
|
|
7358
|
+
if (files == null || files == undefined || files.length === 0) {
|
|
7359
|
+
dataSheet.currentStep = 99;
|
|
7360
|
+
console.log('[ERROR] Files is null or undefined or empty');
|
|
7361
|
+
return [];
|
|
7362
|
+
}
|
|
7363
|
+
if (dataSheet.preview) {
|
|
7364
|
+
dataSheet.progress = 100;
|
|
7365
|
+
for (let file of files) {
|
|
7366
|
+
if (file.svg) {
|
|
7367
|
+
try {
|
|
7368
|
+
// let cleanedSvg = await dataSheetSVG.getCleanedSVGString(file.svg);
|
|
7369
|
+
// cleanedSvg = this.forceArialFont(cleanedSvg);
|
|
7370
|
+
// const base64 = btoa(unescape(encodeURIComponent(cleanedSvg)));
|
|
7371
|
+
// const dataUri = `data:image/svg+xml;base64,${base64}`;
|
|
7372
|
+
// file.svgImg = this.sanitizer.bypassSecurityTrustUrl(dataUri);
|
|
7373
|
+
}
|
|
7374
|
+
catch (e) {
|
|
7375
|
+
console.error('Error converting SVG to base64:', e);
|
|
7376
|
+
file.svgImg = null;
|
|
7377
|
+
}
|
|
7378
|
+
}
|
|
7379
|
+
}
|
|
7380
|
+
dataSheet.cleanMemory();
|
|
7381
|
+
dataSheetSVG = null;
|
|
7382
|
+
}
|
|
7383
|
+
else {
|
|
7384
|
+
// Si ok (75%)
|
|
7385
|
+
for (let file of files) {
|
|
7386
|
+
if (file.svg) {
|
|
7387
|
+
let cleanedSvg = await dataSheetSVG.getCleanedSVGString(file.svg);
|
|
7388
|
+
file.svg = cleanedSvg;
|
|
7389
|
+
}
|
|
7390
|
+
}
|
|
7391
|
+
// Some data
|
|
7392
|
+
json.defaultGabaritGuid = dataSheet.defaultGabaritGuid;
|
|
7393
|
+
json.leftPage = dataSheet.leftPage;
|
|
7394
|
+
// this.pdfService.generatePdfByFile(json, files).subscribe({
|
|
7395
|
+
// next: (response) => {
|
|
7396
|
+
// dataSheet.currentStep = 4;
|
|
7397
|
+
// dataSheet.progress = 90;
|
|
7398
|
+
// },
|
|
7399
|
+
// error: (error) => {
|
|
7400
|
+
// dataSheet.currentStep = 99;
|
|
7401
|
+
// console.error('Error generating PDF:', error);
|
|
7402
|
+
// },
|
|
7403
|
+
// });
|
|
7404
|
+
try {
|
|
7405
|
+
const response = await this._generationService.generatePdfByFile(json, files);
|
|
7406
|
+
dataSheet.currentStep = 4;
|
|
7407
|
+
dataSheet.progress = 90;
|
|
7408
|
+
}
|
|
7409
|
+
catch (error) {
|
|
7410
|
+
dataSheet.currentStep = 99;
|
|
7411
|
+
console.error('Error generating PDF:', error);
|
|
7412
|
+
}
|
|
7413
|
+
let notificationsSubscription = this._notificationService
|
|
7414
|
+
.getUpdate()
|
|
7415
|
+
.subscribe((data) => {
|
|
7416
|
+
this._notificationService.getNotifications().subscribe((res) => {
|
|
7417
|
+
let notification = res['notifications'][0];
|
|
7418
|
+
if (notification['notificationTitle']['fr'] ===
|
|
7419
|
+
'Génération terminée !') {
|
|
7420
|
+
dataSheet.currentStep = 5;
|
|
7421
|
+
dataSheet.progress = 100;
|
|
7422
|
+
dataSheet.downloadLink = notification['notificationAttached'];
|
|
7423
|
+
dataSheet.cleanMemory();
|
|
7424
|
+
dataSheetSVG = null;
|
|
7425
|
+
setTimeout(() => {
|
|
7426
|
+
if (activeToast) {
|
|
7427
|
+
activeToast.toastRef.close();
|
|
7428
|
+
}
|
|
7429
|
+
activeToast = null;
|
|
7430
|
+
}, 6000);
|
|
7431
|
+
notificationsSubscription.unsubscribe();
|
|
7432
|
+
}
|
|
7433
|
+
});
|
|
7434
|
+
});
|
|
7435
|
+
}
|
|
7436
|
+
return files;
|
|
7437
|
+
}
|
|
7438
|
+
forceArialFont(svgString) {
|
|
7439
|
+
const styleTag = `<style>* { font-family: Arial, sans-serif !important; }</style>`;
|
|
7440
|
+
return svgString.replace(/(<svg[^>]*>)/, `$1${styleTag}`);
|
|
7441
|
+
}
|
|
7442
|
+
async getPricesListAvailable(datasheet) {
|
|
7443
|
+
try {
|
|
7444
|
+
const res = await this._priceListService.getAllPriceList().toPromise();
|
|
7445
|
+
this.pricesListAvailable = res?.['pricesLists'];
|
|
7446
|
+
const priceListSelected = this.pricesListAvailable.find((pl) => pl.pricesListGuid == datasheet.priceListGuid);
|
|
7447
|
+
if (priceListSelected) {
|
|
7448
|
+
datasheet.pricesListCurrency = priceListSelected.pricesListCurrency;
|
|
7449
|
+
}
|
|
7450
|
+
return datasheet;
|
|
7451
|
+
}
|
|
7452
|
+
catch (error) {
|
|
7453
|
+
console.error('Erreur lors de la récupération des listes de prix :', error);
|
|
7454
|
+
return datasheet;
|
|
7455
|
+
}
|
|
7456
|
+
}
|
|
7457
|
+
async getTemplateInfo(templateGuid) {
|
|
7458
|
+
try {
|
|
7459
|
+
const template = await this._templates
|
|
7460
|
+
.getTemplate(templateGuid)
|
|
7461
|
+
.toPromise();
|
|
7462
|
+
return template;
|
|
7463
|
+
}
|
|
7464
|
+
catch (err) {
|
|
7465
|
+
console.error('Erreur dans getTemplateInfo :', err);
|
|
7466
|
+
return null;
|
|
7467
|
+
}
|
|
7468
|
+
}
|
|
7469
|
+
async updateGabaritsList(templateGuid, forceRefresh = false) {
|
|
7470
|
+
const singleton = DataSheetSingleton.getInstance();
|
|
7471
|
+
const cached = singleton.getGabarits(templateGuid);
|
|
7472
|
+
// console.log(
|
|
7473
|
+
// `[DataSheetController] updateGabaritsList: instanceId=${singleton.instanceId}, templateGuid=${templateGuid}, forceRefresh=${forceRefresh}, cacheExists=${!!cached}, cacheLength=${cached ? cached.length : 0}`,
|
|
7474
|
+
// );
|
|
7475
|
+
if (!forceRefresh && cached && cached.length > 0) {
|
|
7476
|
+
// console.log(
|
|
7477
|
+
// `[DataSheetController] updateGabaritsList: cache HIT for ${templateGuid}`,
|
|
7478
|
+
// );
|
|
7479
|
+
return cached;
|
|
7480
|
+
}
|
|
7481
|
+
// console.log(
|
|
7482
|
+
// `[DataSheetController] updateGabaritsList: Fetching template product blocks from server (forceRefresh=${forceRefresh})`,
|
|
7483
|
+
// );
|
|
7484
|
+
try {
|
|
7485
|
+
const res = await this._publicationsTemplates
|
|
7486
|
+
.getTemplateProductBlocks(templateGuid)
|
|
7487
|
+
.toPromise();
|
|
7488
|
+
const rawGabarits = res?.['productBlocks'] || [];
|
|
7489
|
+
// console.log(
|
|
7490
|
+
// `[DataSheetController] updateGabaritsList: API returned ${rawGabarits.length} productBlocks`,
|
|
7491
|
+
// );
|
|
7492
|
+
const gabarits = await this.loadGabaritsSvg(rawGabarits);
|
|
7493
|
+
// console.log(
|
|
7494
|
+
// `[DataSheetController] updateGabaritsList: loaded ${gabarits.length} SVGs`,
|
|
7495
|
+
// );
|
|
7496
|
+
singleton.setGabarits(templateGuid, gabarits);
|
|
7497
|
+
return gabarits;
|
|
7498
|
+
}
|
|
7499
|
+
catch (e) {
|
|
7500
|
+
console.error('Erreur dans updateGabaritsList :', e);
|
|
7501
|
+
return [];
|
|
7502
|
+
}
|
|
7503
|
+
}
|
|
7504
|
+
async updateBackgroundsList(templateGuid, forceRefresh = false) {
|
|
7505
|
+
const singleton = DataSheetSingleton.getInstance();
|
|
7506
|
+
const cached = singleton.getBackgrounds(templateGuid);
|
|
7507
|
+
// console.log(
|
|
7508
|
+
// `[DataSheetController] updateBackgroundsList: instanceId=${singleton.instanceId}, templateGuid=${templateGuid}, forceRefresh=${forceRefresh}, cacheExists=${!!cached}, cacheLength=${cached ? cached.length : 0}`,
|
|
7509
|
+
// );
|
|
7510
|
+
if (!forceRefresh && cached && cached.length > 0) {
|
|
7511
|
+
// console.log(
|
|
7512
|
+
// `[DataSheetController] updateBackgroundsList: cache HIT for ${templateGuid}`,
|
|
7513
|
+
// );
|
|
7514
|
+
return cached;
|
|
7515
|
+
}
|
|
7516
|
+
// console.log(
|
|
7517
|
+
// `[DataSheetController] updateBackgroundsList: Fetching template backgrounds from server (forceRefresh=${forceRefresh})`,
|
|
7518
|
+
// );
|
|
7519
|
+
try {
|
|
7520
|
+
const res = await this._publicationsTemplates
|
|
7521
|
+
.getTemplateBackgrounds(templateGuid)
|
|
7522
|
+
.toPromise();
|
|
7523
|
+
const rawBackgrounds = res?.['backgrounds'] || [];
|
|
7524
|
+
// console.log(
|
|
7525
|
+
// `[DataSheetController] updateBackgroundsList: API returned ${rawBackgrounds.length} backgrounds`,
|
|
7526
|
+
// );
|
|
7527
|
+
const backgrounds = await this.loadBackgroundsSvg(rawBackgrounds);
|
|
7528
|
+
// console.log(
|
|
7529
|
+
// `[DataSheetController] updateBackgroundsList: loaded ${backgrounds.length} SVGs`,
|
|
7530
|
+
// );
|
|
7531
|
+
singleton.setBackgrounds(templateGuid, backgrounds);
|
|
7532
|
+
return backgrounds;
|
|
7533
|
+
}
|
|
7534
|
+
catch (e) {
|
|
7535
|
+
console.error('Erreur dans updateBackgroundsList :', e);
|
|
7536
|
+
return [];
|
|
7537
|
+
}
|
|
7538
|
+
}
|
|
7539
|
+
async updateMarketingList(templateGuid, forceRefresh = false) {
|
|
7540
|
+
const singleton = DataSheetSingleton.getInstance();
|
|
7541
|
+
const cached = singleton.getMarketing(templateGuid);
|
|
7542
|
+
// console.log(
|
|
7543
|
+
// `[DataSheetController] updateMarketingList: instanceId=${singleton.instanceId}, templateGuid=${templateGuid}, forceRefresh=${forceRefresh}, cacheExists=${!!cached}, cacheLength=${cached ? cached.length : 0}`,
|
|
7544
|
+
// );
|
|
7545
|
+
if (!forceRefresh && cached && cached.length > 0) {
|
|
7546
|
+
// console.log(
|
|
7547
|
+
// `[DataSheetController] updateMarketingList: cache HIT for ${templateGuid}`,
|
|
7548
|
+
// );
|
|
7549
|
+
return cached;
|
|
7550
|
+
}
|
|
7551
|
+
// console.log(
|
|
7552
|
+
// `[DataSheetController] updateMarketingList: Fetching template marketing from server (forceRefresh=${forceRefresh})`,
|
|
7553
|
+
// );
|
|
7554
|
+
try {
|
|
7555
|
+
const res = await this._publicationsTemplates
|
|
7556
|
+
.getTemplateMarketings(templateGuid)
|
|
7557
|
+
.toPromise();
|
|
7558
|
+
const rawMarketing = res?.['marketing'] || [];
|
|
7559
|
+
// console.log(
|
|
7560
|
+
// `[DataSheetController] updateMarketingList: API returned ${rawMarketing.length} marketing`,
|
|
7561
|
+
// );
|
|
7562
|
+
const marketing = await this.loadMarketingSvg(rawMarketing);
|
|
7563
|
+
// console.log(
|
|
7564
|
+
// `[DataSheetController] updateMarketingList: loaded ${marketing.length} SVGs`,
|
|
7565
|
+
// );
|
|
7566
|
+
singleton.setMarketing(templateGuid, marketing);
|
|
7567
|
+
return marketing;
|
|
7568
|
+
}
|
|
7569
|
+
catch (e) {
|
|
7570
|
+
console.error('Erreur dans updateMarketingList :', e);
|
|
7571
|
+
return [];
|
|
7572
|
+
}
|
|
7573
|
+
}
|
|
7574
|
+
async loadGabaritsSvg(gabarits) {
|
|
7575
|
+
const loadedGabarits = [];
|
|
7576
|
+
for (let template of gabarits) {
|
|
7577
|
+
const date = Date.now();
|
|
7578
|
+
const url = `${template.url}?date=${date}`;
|
|
7579
|
+
try {
|
|
7580
|
+
const data = await this.http
|
|
7581
|
+
.get(url, { responseType: 'text' })
|
|
7582
|
+
.toPromise();
|
|
7583
|
+
if (!data || !data.trim().includes('<svg')) {
|
|
7584
|
+
template.svgImage = null;
|
|
7585
|
+
template.isSvgLoaded = false;
|
|
7586
|
+
}
|
|
7587
|
+
else {
|
|
7588
|
+
const widthMatch = data.match(/width="(\d+)(\.\d+)?"/);
|
|
7589
|
+
const heightMatch = data.match(/height="(\d+)(\.\d+)?"/);
|
|
7590
|
+
const width = widthMatch
|
|
7591
|
+
? Number.parseFloat(widthMatch[1] + (widthMatch[2] || ''))
|
|
7592
|
+
: 0;
|
|
7593
|
+
const height = heightMatch
|
|
7594
|
+
? Number.parseFloat(heightMatch[1] + (heightMatch[2] || ''))
|
|
7595
|
+
: 0;
|
|
7596
|
+
const footerHeightMatch = data.match(/data-margin-bottom="(\d+)(\.\d+)?"/) ||
|
|
7597
|
+
data.match(/data-footer-height="(\d+)(\.\d+)?"/) ||
|
|
7598
|
+
data.match(/data-margin-vertical="(\d+)(\.\d+)?"/);
|
|
7599
|
+
const headerHeightMatch = data.match(/data-margin-top="(\d+)(\.\d+)?"/) ||
|
|
7600
|
+
data.match(/data-header-height="(\d+)(\.\d+)?"/) ||
|
|
7601
|
+
data.match(/data-margin-vertical="(\d+)(\.\d+)?"/);
|
|
7602
|
+
const rightMarginMatch = data.match(/data-margin-right="(\d+)(\.\d+)?"/) ||
|
|
7603
|
+
data.match(/data-margin-horizontal="(\d+)(\.\d+)?"/);
|
|
7604
|
+
const leftMarginMatch = data.match(/data-margin-left="(\d+)(\.\d+)?"/) ||
|
|
7605
|
+
data.match(/data-margin-horizontal="(\d+)(\.\d+)?"/);
|
|
7606
|
+
template.width = width;
|
|
7607
|
+
template.height = height;
|
|
7608
|
+
template.footerHeight = footerHeightMatch
|
|
7609
|
+
? Number.parseFloat(footerHeightMatch[1] + (footerHeightMatch[2] || ''))
|
|
7610
|
+
: 0;
|
|
7611
|
+
template.headerHeight = headerHeightMatch
|
|
7612
|
+
? Number.parseFloat(headerHeightMatch[1] + (headerHeightMatch[2] || ''))
|
|
7613
|
+
: 0;
|
|
7614
|
+
template.rightMargin = rightMarginMatch
|
|
7615
|
+
? Number.parseFloat(rightMarginMatch[1] + (rightMarginMatch[2] || ''))
|
|
7616
|
+
: 0;
|
|
7617
|
+
template.leftMargin = leftMarginMatch
|
|
7618
|
+
? Number.parseFloat(leftMarginMatch[1] + (leftMarginMatch[2] || ''))
|
|
7619
|
+
: 0;
|
|
7620
|
+
template.svgImage = data;
|
|
7621
|
+
template.isSvgLoaded = true;
|
|
7622
|
+
}
|
|
7623
|
+
}
|
|
7624
|
+
catch (err) {
|
|
7625
|
+
template.svgImage = null;
|
|
7626
|
+
template.isSvgLoaded = false;
|
|
7627
|
+
}
|
|
7628
|
+
loadedGabarits.push(template);
|
|
7629
|
+
}
|
|
7630
|
+
return loadedGabarits;
|
|
7631
|
+
}
|
|
7632
|
+
async loadBackgroundsSvg(backgrounds) {
|
|
7633
|
+
const loadedBackgrounds = [];
|
|
7634
|
+
for (let template of backgrounds) {
|
|
7635
|
+
const date = Date.now();
|
|
7636
|
+
const url = `${template.url}?date=${date}`;
|
|
7637
|
+
try {
|
|
7638
|
+
const data = await this.http
|
|
7639
|
+
.get(url, { responseType: 'text' })
|
|
7640
|
+
.toPromise();
|
|
7641
|
+
if (!data || !data.trim().includes('<svg')) {
|
|
7642
|
+
template.svgImage = null;
|
|
7643
|
+
template.isSvgLoaded = false;
|
|
7644
|
+
}
|
|
7645
|
+
else {
|
|
7646
|
+
const widthMatch = data.match(/width="(\d+)(\.\d+)?"/);
|
|
7647
|
+
const heightMatch = data.match(/height="(\d+)(\.\d+)?"/);
|
|
7648
|
+
const width = widthMatch
|
|
7649
|
+
? Number.parseFloat(widthMatch[1] + (widthMatch[2] || ''))
|
|
7650
|
+
: 0;
|
|
7651
|
+
const height = heightMatch
|
|
7652
|
+
? Number.parseFloat(heightMatch[1] + (heightMatch[2] || ''))
|
|
7653
|
+
: 0;
|
|
7654
|
+
const footerHeightMatch = data.match(/data-margin-bottom="(\d+)(\.\d+)?"/) ||
|
|
7655
|
+
data.match(/data-footer-height="(\d+)(\.\d+)?"/) ||
|
|
7656
|
+
data.match(/data-margin-vertical="(\d+)(\.\d+)?"/);
|
|
7657
|
+
const headerHeightMatch = data.match(/data-margin-top="(\d+)(\.\d+)?"/) ||
|
|
7658
|
+
data.match(/data-header-height="(\d+)(\.\d+)?"/) ||
|
|
7659
|
+
data.match(/data-margin-vertical="(\d+)(\.\d+)?"/);
|
|
7660
|
+
const rightMarginMatch = data.match(/data-margin-right="(\d+)(\.\d+)?"/) ||
|
|
7661
|
+
data.match(/data-margin-horizontal="(\d+)(\.\d+)?"/);
|
|
7662
|
+
const leftMarginMatch = data.match(/data-margin-left="(\d+)(\.\d+)?"/) ||
|
|
7663
|
+
data.match(/data-margin-horizontal="(\d+)(\.\d+)?"/);
|
|
7664
|
+
const bleedMarginRight = data.match(/data-bleed-margin-right="(\d+)(\.\d+)?"/);
|
|
7665
|
+
const bleedMarginLeft = data.match(/data-bleed-margin-left="(\d+)(\.\d+)?"/);
|
|
7666
|
+
const bleedMarginTop = data.match(/data-bleed-margin-top="(\d+)(\.\d+)?"/);
|
|
7667
|
+
const bleedMarginBottom = data.match(/data-bleed-margin-bottom="(\d+)(\.\d+)?"/);
|
|
7668
|
+
template.width = width;
|
|
7669
|
+
template.height = height;
|
|
7670
|
+
template.footerHeight = footerHeightMatch
|
|
7671
|
+
? Number.parseFloat(footerHeightMatch[1] + (footerHeightMatch[2] || ''))
|
|
7672
|
+
: 0;
|
|
7673
|
+
template.headerHeight = headerHeightMatch
|
|
7674
|
+
? Number.parseFloat(headerHeightMatch[1] + (headerHeightMatch[2] || ''))
|
|
7675
|
+
: 0;
|
|
7676
|
+
template.rightMargin = rightMarginMatch
|
|
7677
|
+
? Number.parseFloat(rightMarginMatch[1] + (rightMarginMatch[2] || ''))
|
|
7678
|
+
: 0;
|
|
7679
|
+
template.leftMargin = leftMarginMatch
|
|
7680
|
+
? Number.parseFloat(leftMarginMatch[1] + (leftMarginMatch[2] || ''))
|
|
7681
|
+
: 0;
|
|
7682
|
+
template.bleedMarginRight = bleedMarginRight
|
|
7683
|
+
? Number.parseFloat(bleedMarginRight[1] + (bleedMarginRight[2] || ''))
|
|
7684
|
+
: 0;
|
|
7685
|
+
template.bleedMarginLeft = bleedMarginLeft
|
|
7686
|
+
? Number.parseFloat(bleedMarginLeft[1] + (bleedMarginLeft[2] || ''))
|
|
7687
|
+
: 0;
|
|
7688
|
+
template.bleedMarginTop = bleedMarginTop
|
|
7689
|
+
? Number.parseFloat(bleedMarginTop[1] + (bleedMarginTop[2] || ''))
|
|
7690
|
+
: 0;
|
|
7691
|
+
template.bleedMarginBottom = bleedMarginBottom
|
|
7692
|
+
? Number.parseFloat(bleedMarginBottom[1] + (bleedMarginBottom[2] || ''))
|
|
7693
|
+
: 0;
|
|
7694
|
+
let data2 = data
|
|
7695
|
+
.replace(/width=".*?"/, '')
|
|
7696
|
+
.replace(/height=".*?"/, '');
|
|
7697
|
+
data2 = data.replace('<svg', `<svg viewBox="0 0 ${width} ${height}"`);
|
|
7698
|
+
template.svgImage = data2;
|
|
7699
|
+
template.isSvgLoaded = true;
|
|
7700
|
+
}
|
|
7701
|
+
}
|
|
7702
|
+
catch (err) {
|
|
7703
|
+
template.svgImage = null;
|
|
7704
|
+
template.isSvgLoaded = false;
|
|
7705
|
+
console.error(`[loadBackgroundsSvg] Erreur lors du chargement du SVG depuis "${url}" :`, err);
|
|
7706
|
+
}
|
|
7707
|
+
loadedBackgrounds.push(template);
|
|
7708
|
+
}
|
|
7709
|
+
return loadedBackgrounds;
|
|
7710
|
+
}
|
|
7711
|
+
async loadMarketingSvg(marketing) {
|
|
7712
|
+
const loadedMarketing = [];
|
|
7713
|
+
for (let template of marketing) {
|
|
7714
|
+
const date = Date.now();
|
|
7715
|
+
const url = `${template.url}?date=${date}`;
|
|
7716
|
+
try {
|
|
7717
|
+
const data = await this.http
|
|
7718
|
+
.get(url, { responseType: 'text' })
|
|
7719
|
+
.toPromise();
|
|
7720
|
+
if (!data || !data.trim().includes('<svg')) {
|
|
7721
|
+
template.svgImage = null;
|
|
7722
|
+
template.isSvgLoaded = false;
|
|
7723
|
+
}
|
|
7724
|
+
else {
|
|
7725
|
+
const widthMatch = data.match(/width="(\d+)(\.\d+)?"/);
|
|
7726
|
+
const heightMatch = data.match(/height="(\d+)(\.\d+)?"/);
|
|
7727
|
+
const width = widthMatch
|
|
7728
|
+
? Number.parseFloat(widthMatch[1] + (widthMatch[2] || ''))
|
|
7729
|
+
: 0;
|
|
7730
|
+
const height = heightMatch
|
|
7731
|
+
? Number.parseFloat(heightMatch[1] + (heightMatch[2] || ''))
|
|
7732
|
+
: 0;
|
|
7733
|
+
const footerHeightMatch = data.match(/data-margin-bottom="(\d+)(\.\d+)?"/) ||
|
|
7734
|
+
data.match(/data-footer-height="(\d+)(\.\d+)?"/) ||
|
|
7735
|
+
data.match(/data-margin-vertical="(\d+)(\.\d+)?"/);
|
|
7736
|
+
const headerHeightMatch = data.match(/data-margin-top="(\d+)(\.\d+)?"/) ||
|
|
7737
|
+
data.match(/data-header-height="(\d+)(\.\d+)?"/) ||
|
|
7738
|
+
data.match(/data-margin-vertical="(\d+)(\.\d+)?"/);
|
|
7739
|
+
const rightMarginMatch = data.match(/data-margin-right="(\d+)(\.\d+)?"/) ||
|
|
7740
|
+
data.match(/data-margin-horizontal="(\d+)(\.\d+)?"/);
|
|
7741
|
+
const leftMarginMatch = data.match(/data-margin-left="(\d+)(\.\d+)?"/) ||
|
|
7742
|
+
data.match(/data-margin-horizontal="(\d+)(\.\d+)?"/);
|
|
7743
|
+
const bleedMarginRight = data.match(/data-bleed-margin-right="(\d+)(\.\d+)?"/);
|
|
7744
|
+
const bleedMarginLeft = data.match(/data-bleed-margin-left="(\d+)(\.\d+)?"/);
|
|
7745
|
+
const bleedMarginTop = data.match(/data-bleed-margin-top="(\d+)(\.\d+)?"/);
|
|
7746
|
+
const bleedMarginBottom = data.match(/data-bleed-margin-bottom="(\d+)(\.\d+)?"/);
|
|
7747
|
+
template.width = width;
|
|
7748
|
+
template.height = height;
|
|
7749
|
+
template.footerHeight = footerHeightMatch
|
|
7750
|
+
? Number.parseFloat(footerHeightMatch[1] + (footerHeightMatch[2] || ''))
|
|
7751
|
+
: 0;
|
|
7752
|
+
template.headerHeight = headerHeightMatch
|
|
7753
|
+
? Number.parseFloat(headerHeightMatch[1] + (headerHeightMatch[2] || ''))
|
|
7754
|
+
: 0;
|
|
7755
|
+
template.rightMargin = rightMarginMatch
|
|
7756
|
+
? Number.parseFloat(rightMarginMatch[1] + (rightMarginMatch[2] || ''))
|
|
7757
|
+
: 0;
|
|
7758
|
+
template.leftMargin = leftMarginMatch
|
|
7759
|
+
? Number.parseFloat(leftMarginMatch[1] + (leftMarginMatch[2] || ''))
|
|
7760
|
+
: 0;
|
|
7761
|
+
template.bleedMarginRight = bleedMarginRight
|
|
7762
|
+
? Number.parseFloat(bleedMarginRight[1] + (bleedMarginRight[2] || ''))
|
|
7763
|
+
: 0;
|
|
7764
|
+
template.bleedMarginLeft = bleedMarginLeft
|
|
7765
|
+
? Number.parseFloat(bleedMarginLeft[1] + (bleedMarginLeft[2] || ''))
|
|
7766
|
+
: 0;
|
|
7767
|
+
template.bleedMarginTop = bleedMarginTop
|
|
7768
|
+
? Number.parseFloat(bleedMarginTop[1] + (bleedMarginTop[2] || ''))
|
|
7769
|
+
: 0;
|
|
7770
|
+
template.bleedMarginBottom = bleedMarginBottom
|
|
7771
|
+
? Number.parseFloat(bleedMarginBottom[1] + (bleedMarginBottom[2] || ''))
|
|
7772
|
+
: 0;
|
|
7773
|
+
let data2 = data
|
|
7774
|
+
.replace(/width=".*?"/, '')
|
|
7775
|
+
.replace(/height=".*?"/, '');
|
|
7776
|
+
data2 = data.replace('<svg', `<svg viewBox="0 0 ${width} ${height}"`);
|
|
7777
|
+
template.svgImage = data2;
|
|
7778
|
+
template.isSvgLoaded = true;
|
|
7779
|
+
}
|
|
7780
|
+
}
|
|
7781
|
+
catch (err) {
|
|
7782
|
+
template.svgImage = null;
|
|
7783
|
+
template.isSvgLoaded = false;
|
|
7784
|
+
}
|
|
7785
|
+
loadedMarketing.push(template);
|
|
7786
|
+
}
|
|
7787
|
+
return loadedMarketing;
|
|
7788
|
+
}
|
|
7789
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.12", ngImport: i0, type: DataSheetController, deps: [{ token: i1.HttpClient }, { token: i2.GenerationService }, { token: i2.PublicationsService }, { token: i2.PricesTaxService }, { token: i2.AttributesService }, { token: i2.TemplatesService }, { token: i2.PublicationsTemplatesService }, { token: i3.ToastrService }, { token: i2.NotificationServiceService }, { token: i4.TranslateService }, { token: i5.DomSanitizer }, { token: i2.DamAssetsService }, { token: i2.DocumentsService }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
7790
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.3.12", ngImport: i0, type: DataSheetController, providedIn: 'root' }); }
|
|
7791
|
+
}
|
|
7792
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.12", ngImport: i0, type: DataSheetController, decorators: [{
|
|
7793
|
+
type: Injectable,
|
|
7794
|
+
args: [{
|
|
7795
|
+
providedIn: 'root',
|
|
7796
|
+
}]
|
|
7797
|
+
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.GenerationService }, { type: i2.PublicationsService }, { type: i2.PricesTaxService }, { type: i2.AttributesService }, { type: i2.TemplatesService }, { type: i2.PublicationsTemplatesService }, { type: i3.ToastrService }, { type: i2.NotificationServiceService }, { type: i4.TranslateService }, { type: i5.DomSanitizer }, { type: i2.DamAssetsService }, { type: i2.DocumentsService }] });
|
|
7798
|
+
|
|
7799
|
+
/**
|
|
7800
|
+
* Calculates the size (width or height) of a product block when layed out in a grid.
|
|
7801
|
+
*/
|
|
7802
|
+
function calculateBlockDimension(pageSize, pageMarginStart, pageMarginEnd, gap, blocksCount, isWidth = false) {
|
|
7803
|
+
if (blocksCount <= 0)
|
|
7804
|
+
return 0;
|
|
7805
|
+
const innerSize = pageSize - pageMarginStart - pageMarginEnd;
|
|
7806
|
+
const rawSize = (innerSize - (blocksCount - 1) * gap) / blocksCount;
|
|
7807
|
+
// We truncate/round down to exactly 6 decimal places.
|
|
7808
|
+
// This guarantees the block size is never rounded up (which would exceed the page boundary due to float precision).
|
|
7809
|
+
return rawSize > 0 ? Math.floor(rawSize * 1000000) / 1000000 : 0;
|
|
7810
|
+
}
|
|
7811
|
+
/**
|
|
7812
|
+
* Simulates a product block grid layout and returns coordinates of each block.
|
|
7813
|
+
* Coordinates and fitting logic match the physical page constraints, respecting margins.
|
|
7814
|
+
*/
|
|
7815
|
+
function simulateProductBlocks(pageWidth, pageHeight, pageMarginTop, pageMarginBottom, pageMarginLeft, pageMarginRight, blockWidth, blockHeight, verticalGap, horizontalGap) {
|
|
7816
|
+
const innerWidth = pageWidth - pageMarginLeft - pageMarginRight;
|
|
7817
|
+
const innerHeight = pageHeight - pageMarginTop - pageMarginBottom;
|
|
7818
|
+
if (innerWidth <= 0 || innerHeight <= 0 || blockWidth <= 0 || blockHeight <= 0) {
|
|
7819
|
+
return { blocksPerRow: 0, blocksPerColumn: 0, blocks: [] };
|
|
7820
|
+
}
|
|
7821
|
+
// Calculate maximum columns and rows that can fit physically using pure mathematical formulas.
|
|
7822
|
+
const cols = Math.floor((innerWidth + horizontalGap) / (blockWidth + horizontalGap));
|
|
7823
|
+
const rows = Math.floor((innerHeight + verticalGap) / (blockHeight + verticalGap));
|
|
7824
|
+
const blocks = [];
|
|
7825
|
+
for (let row = 0; row < rows; row++) {
|
|
7826
|
+
for (let col = 0; col < cols; col++) {
|
|
7827
|
+
// Under asymmetric margin logic, x and y are shifted precisely:
|
|
7828
|
+
const x = pageMarginLeft + col * (blockWidth + horizontalGap);
|
|
7829
|
+
const y = pageMarginTop + row * (blockHeight + verticalGap);
|
|
7830
|
+
blocks.push({
|
|
7831
|
+
x,
|
|
7832
|
+
y,
|
|
7833
|
+
width: blockWidth,
|
|
7834
|
+
height: blockHeight,
|
|
7835
|
+
});
|
|
7836
|
+
}
|
|
7837
|
+
}
|
|
7838
|
+
return {
|
|
7839
|
+
blocksPerRow: cols,
|
|
7840
|
+
blocksPerColumn: rows,
|
|
7841
|
+
blocks,
|
|
7842
|
+
};
|
|
5115
7843
|
}
|
|
5116
7844
|
|
|
5117
7845
|
/**
|
|
5118
7846
|
* Generated bundle index. Do not edit.
|
|
5119
7847
|
*/
|
|
5120
7848
|
|
|
5121
|
-
export { DataSheet, DataSheetSVG, DataSheetSingleton, SourceData, TypeDatasheet };
|
|
7849
|
+
export { DataSheet, DataSheetController, DataSheetPublication, DataSheetSVG, DataSheetSingleton, DataSheetSku, SourceData, TypeDatasheet, calculateBlockDimension, simulateProductBlocks };
|
|
5122
7850
|
//# sourceMappingURL=solidpepper-solidpepper-solidgeneration.mjs.map
|