@solidpepper/solidpepper-solidgeneration 0.3.1 → 0.3.2
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.
|
@@ -1944,7 +1944,7 @@ class DataSheetSVG {
|
|
|
1944
1944
|
const patternHeight = /height\s*=\s*"([^"]*)"/;
|
|
1945
1945
|
const patternY = /(?<![a-zA-Z])y\s*=\s*"-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?"/g;
|
|
1946
1946
|
const patternYLine = /(?<![a-zA-Z])y\d*\s*=\s*"-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?"/g;
|
|
1947
|
-
const patternRotate = /rotate\(\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s
|
|
1947
|
+
const patternRotate = /rotate\(\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*\)/;
|
|
1948
1948
|
const patternTransformAttribute = /transform="([^"]*)"/;
|
|
1949
1949
|
const patternTranslate = /translate\(\s*([^\s,]+)\s*,\s*([^)]+)\)/;
|
|
1950
1950
|
const patternCY = /(?<![a-zA-Z])cy\s*=\s*"-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?"/g;
|
|
@@ -2121,7 +2121,7 @@ class DataSheetSVG {
|
|
|
2121
2121
|
const patternWidth = /width\s*=\s*"([^"]*)"/;
|
|
2122
2122
|
const patternX = /(?<![a-zA-Z])x\s*=\s*"(-?\d+(\.\d+)?)"/g;
|
|
2123
2123
|
const patternXLine = /(?<![a-zA-Z])x\d*\s*=\s*"(-?\d+(\.\d+)?)"/g;
|
|
2124
|
-
const patternTransform = /rotate\(\s*(-?\d+(?:\.\d+)?)\s
|
|
2124
|
+
const patternTransform = /rotate\(\s*(-?\d+(?:\.\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?)\s*\)/;
|
|
2125
2125
|
//const patternTransform = /rotate\((-?\d+(\.\d+)?)(\s+)(-?\d+(\.\d+)?)(\s+)(-?\d+(\.\d+)?)\)/;
|
|
2126
2126
|
const patternTransformAttribute = /transform="([^"]*)"/;
|
|
2127
2127
|
const patternTranslate = /translate\(\s*([^\s,]+)\s*,\s*([^)]+)\)/;
|
|
@@ -2247,7 +2247,7 @@ class DataSheetSVG {
|
|
|
2247
2247
|
const patternY = /(?<![a-zA-Z])y\s*=\s*"(-?\d+(\.\d+)?)"/g;
|
|
2248
2248
|
const patternYLine = /(?<![a-zA-Z])y\d*\s*=\s*"(-?\d+(\.\d+)?)"/g;
|
|
2249
2249
|
//const patternTransform = /rotate\((-?\d+(\.\d+)?)(\s+)(-?\d+(\.\d+)?)(\s+)(-?\d+(\.\d+)?)\)/;
|
|
2250
|
-
const patternTransform = /rotate\(\s*(-?\d+(?:\.\d+)?)\s
|
|
2250
|
+
const patternTransform = /rotate\(\s*(-?\d+(?:\.\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?)\s*\)/;
|
|
2251
2251
|
const patternTransformAttribute = /transform="([^"]*)"/;
|
|
2252
2252
|
const patternTranslate = /translate\(\s*([^\s,]+)\s*,\s*([^)]+)\)/;
|
|
2253
2253
|
const patternCY = /(?<![a-zA-Z])cy\s*=\s*"(-?\d+(\.\d+)?)"/g;
|
|
@@ -5816,11 +5816,9 @@ class DataSheetSVG {
|
|
|
5816
5816
|
tagToUpdate.XmlTag.querySelector('.fake-textarea')) {
|
|
5817
5817
|
if (tagToUpdate.XmlTag.hasAttribute('x')) {
|
|
5818
5818
|
element.setAttribute('x', tagToUpdate.XmlTag.getAttribute('x'));
|
|
5819
|
-
element.removeAttribute('transform');
|
|
5820
5819
|
}
|
|
5821
5820
|
if (tagToUpdate.XmlTag.hasAttribute('y')) {
|
|
5822
5821
|
element.setAttribute('y', tagToUpdate.XmlTag.getAttribute('y'));
|
|
5823
|
-
element.removeAttribute('transform');
|
|
5824
5822
|
}
|
|
5825
5823
|
if (tagToUpdate.XmlTag.hasAttribute('width')) {
|
|
5826
5824
|
const w = tagToUpdate.XmlTag.getAttribute('width');
|
|
@@ -5836,6 +5834,15 @@ class DataSheetSVG {
|
|
|
5836
5834
|
element.style.height = h + 'px';
|
|
5837
5835
|
}
|
|
5838
5836
|
}
|
|
5837
|
+
const sourceTransform = tagToUpdate.XmlTag.getAttribute('transform');
|
|
5838
|
+
if (sourceTransform) {
|
|
5839
|
+
element.setAttribute('transform', sourceTransform);
|
|
5840
|
+
}
|
|
5841
|
+
const sourceRotation = tagToUpdate.XmlTag.getAttribute('rotation');
|
|
5842
|
+
if (sourceRotation) {
|
|
5843
|
+
element.setAttribute('rotation', sourceRotation);
|
|
5844
|
+
}
|
|
5845
|
+
this.updateElementRotation(element);
|
|
5839
5846
|
}
|
|
5840
5847
|
}
|
|
5841
5848
|
}
|
|
@@ -5860,6 +5867,15 @@ class DataSheetSVG {
|
|
|
5860
5867
|
if (element.getAttribute('data-type') === 'dynamicImage') {
|
|
5861
5868
|
element.setAttribute('data-type', 'image');
|
|
5862
5869
|
}
|
|
5870
|
+
const sourceTransform = tagToUpdate.XmlTag.getAttribute('transform');
|
|
5871
|
+
if (sourceTransform) {
|
|
5872
|
+
element.setAttribute('transform', sourceTransform);
|
|
5873
|
+
}
|
|
5874
|
+
const sourceRotation = tagToUpdate.XmlTag.getAttribute('rotation');
|
|
5875
|
+
if (sourceRotation) {
|
|
5876
|
+
element.setAttribute('rotation', sourceRotation);
|
|
5877
|
+
}
|
|
5878
|
+
this.updateElementRotation(element);
|
|
5863
5879
|
}
|
|
5864
5880
|
else {
|
|
5865
5881
|
element.innerHTML = tagToUpdate.XmlTag.innerHTML;
|
|
@@ -5867,11 +5883,9 @@ class DataSheetSVG {
|
|
|
5867
5883
|
tagToUpdate.XmlTag.querySelector('.fake-textarea')) {
|
|
5868
5884
|
if (tagToUpdate.XmlTag.hasAttribute('x')) {
|
|
5869
5885
|
element.setAttribute('x', tagToUpdate.XmlTag.getAttribute('x'));
|
|
5870
|
-
element.removeAttribute('transform');
|
|
5871
5886
|
}
|
|
5872
5887
|
if (tagToUpdate.XmlTag.hasAttribute('y')) {
|
|
5873
5888
|
element.setAttribute('y', tagToUpdate.XmlTag.getAttribute('y'));
|
|
5874
|
-
element.removeAttribute('transform');
|
|
5875
5889
|
}
|
|
5876
5890
|
if (tagToUpdate.XmlTag.hasAttribute('width')) {
|
|
5877
5891
|
const w = tagToUpdate.XmlTag.getAttribute('width');
|
|
@@ -5889,6 +5903,15 @@ class DataSheetSVG {
|
|
|
5889
5903
|
element.style.height = h + 'px';
|
|
5890
5904
|
}
|
|
5891
5905
|
}
|
|
5906
|
+
const sourceTransform = tagToUpdate.XmlTag.getAttribute('transform');
|
|
5907
|
+
if (sourceTransform) {
|
|
5908
|
+
element.setAttribute('transform', sourceTransform);
|
|
5909
|
+
}
|
|
5910
|
+
const sourceRotation = tagToUpdate.XmlTag.getAttribute('rotation');
|
|
5911
|
+
if (sourceRotation) {
|
|
5912
|
+
element.setAttribute('rotation', sourceRotation);
|
|
5913
|
+
}
|
|
5914
|
+
this.updateElementRotation(element);
|
|
5892
5915
|
}
|
|
5893
5916
|
}
|
|
5894
5917
|
}
|
|
@@ -6216,7 +6239,7 @@ class DataSheetSVG {
|
|
|
6216
6239
|
const deltaW = newWidth - foWidth;
|
|
6217
6240
|
const newX = initialX - deltaW;
|
|
6218
6241
|
foEl.setAttribute('x', newX.toString());
|
|
6219
|
-
|
|
6242
|
+
this.updateElementRotation(foEl);
|
|
6220
6243
|
}
|
|
6221
6244
|
foEl.setAttribute('width', newWidth.toString());
|
|
6222
6245
|
if (isMinimize) {
|
|
@@ -6225,6 +6248,7 @@ class DataSheetSVG {
|
|
|
6225
6248
|
else {
|
|
6226
6249
|
foEl.setAttribute('height', Math.max(foHeight, naturalHeight + 4).toString());
|
|
6227
6250
|
}
|
|
6251
|
+
this.updateElementRotation(foEl);
|
|
6228
6252
|
}
|
|
6229
6253
|
else if (isHeight) {
|
|
6230
6254
|
if (parentFo) {
|
|
@@ -6251,7 +6275,7 @@ class DataSheetSVG {
|
|
|
6251
6275
|
const deltaH = newHeight - foHeight;
|
|
6252
6276
|
const newY = initialY - deltaH;
|
|
6253
6277
|
foEl.setAttribute('y', newY.toString());
|
|
6254
|
-
|
|
6278
|
+
this.updateElementRotation(foEl);
|
|
6255
6279
|
}
|
|
6256
6280
|
foEl.setAttribute('height', newHeight.toString());
|
|
6257
6281
|
if (isMinimize) {
|
|
@@ -6260,10 +6284,11 @@ class DataSheetSVG {
|
|
|
6260
6284
|
const deltaW = newWidth - foWidth;
|
|
6261
6285
|
const newX = initialX - deltaW;
|
|
6262
6286
|
foEl.setAttribute('x', newX.toString());
|
|
6263
|
-
|
|
6287
|
+
this.updateElementRotation(foEl);
|
|
6264
6288
|
}
|
|
6265
6289
|
foEl.setAttribute('width', newWidth.toString());
|
|
6266
6290
|
}
|
|
6291
|
+
this.updateElementRotation(foEl);
|
|
6267
6292
|
}
|
|
6268
6293
|
else if (isFixed && isMinimize) {
|
|
6269
6294
|
if (parentFo) {
|
|
@@ -6291,16 +6316,17 @@ class DataSheetSVG {
|
|
|
6291
6316
|
const deltaW = newWidth - foWidth;
|
|
6292
6317
|
const newX = initialX - deltaW;
|
|
6293
6318
|
foEl.setAttribute('x', newX.toString());
|
|
6294
|
-
|
|
6319
|
+
this.updateElementRotation(foEl);
|
|
6295
6320
|
}
|
|
6296
6321
|
if (direction === 'btt') {
|
|
6297
6322
|
const deltaH = newHeight - foHeight;
|
|
6298
6323
|
const newY = initialY - deltaH;
|
|
6299
6324
|
foEl.setAttribute('y', newY.toString());
|
|
6300
|
-
|
|
6325
|
+
this.updateElementRotation(foEl);
|
|
6301
6326
|
}
|
|
6302
6327
|
foEl.setAttribute('width', newWidth.toString());
|
|
6303
6328
|
foEl.setAttribute('height', newHeight.toString());
|
|
6329
|
+
this.updateElementRotation(foEl);
|
|
6304
6330
|
}
|
|
6305
6331
|
if (textarea) {
|
|
6306
6332
|
textarea.setAttribute('locked', 'true');
|
|
@@ -6895,6 +6921,7 @@ class DataSheetSVG {
|
|
|
6895
6921
|
//this.unwrapForeignObjects(doc);
|
|
6896
6922
|
this.addWidthHeightFromViewBox(svgElement);
|
|
6897
6923
|
this.removeDuplicateAttributes(doc.documentElement);
|
|
6924
|
+
this.ensureElementRotationTransforms(doc.documentElement);
|
|
6898
6925
|
if (!soft) {
|
|
6899
6926
|
await this.convertImgSrcToBase64(svgElement);
|
|
6900
6927
|
}
|
|
@@ -7343,8 +7370,28 @@ class DataSheetSVG {
|
|
|
7343
7370
|
else {
|
|
7344
7371
|
x = svgTranslateX;
|
|
7345
7372
|
}
|
|
7346
|
-
// Nettoyage : supprimer l'attribut transform
|
|
7347
|
-
|
|
7373
|
+
// Nettoyage : supprimer uniquement translate de l'attribut transform
|
|
7374
|
+
const cleanTransform = tagTransform.replace(/translate\([^)]*\)/g, '').trim();
|
|
7375
|
+
if (cleanTransform !== '') {
|
|
7376
|
+
const rotateMatch = cleanTransform.match(/rotate\(\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*\)/);
|
|
7377
|
+
if (rotateMatch) {
|
|
7378
|
+
const angle = rotateMatch[1];
|
|
7379
|
+
const oldCx = parseFloat(rotateMatch[2]);
|
|
7380
|
+
const oldCy = parseFloat(rotateMatch[3]);
|
|
7381
|
+
const tx = parseFloat(svgTranslateX) || 0;
|
|
7382
|
+
const ty = parseFloat(svgTranslateY) || 0;
|
|
7383
|
+
const newCx = oldCx + tx;
|
|
7384
|
+
const newCy = oldCy + ty;
|
|
7385
|
+
const updatedTransform = cleanTransform.replace(rotateMatch[0], `rotate(${angle} ${newCx} ${newCy})`);
|
|
7386
|
+
element.setAttribute('transform', updatedTransform);
|
|
7387
|
+
}
|
|
7388
|
+
else {
|
|
7389
|
+
element.setAttribute('transform', cleanTransform);
|
|
7390
|
+
}
|
|
7391
|
+
}
|
|
7392
|
+
else {
|
|
7393
|
+
element.removeAttribute('transform');
|
|
7394
|
+
}
|
|
7348
7395
|
element.setAttribute('y', y);
|
|
7349
7396
|
element.setAttribute('x', x);
|
|
7350
7397
|
}
|
|
@@ -7648,8 +7695,80 @@ class DataSheetSVG {
|
|
|
7648
7695
|
}
|
|
7649
7696
|
el.setAttribute('x', newX.toString());
|
|
7650
7697
|
el.setAttribute('y', newY.toString());
|
|
7698
|
+
this.updateElementRotation(el);
|
|
7651
7699
|
});
|
|
7652
7700
|
}
|
|
7701
|
+
updateElementRotation(element) {
|
|
7702
|
+
if (!element)
|
|
7703
|
+
return;
|
|
7704
|
+
const rotAttr = element.getAttribute('rotation');
|
|
7705
|
+
const transform = element.getAttribute('transform') || '';
|
|
7706
|
+
if (!rotAttr && !transform.includes('rotate')) {
|
|
7707
|
+
return;
|
|
7708
|
+
}
|
|
7709
|
+
let cleanTrans = transform.replace(/translate\([^)]*\)/g, '').trim();
|
|
7710
|
+
const rotAngle = rotAttr ? parseFloat(rotAttr) : null;
|
|
7711
|
+
const rotMatch = cleanTrans.match(/rotate\(\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*(?:[,\s]\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*[,\s]\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?))?\s*\)/);
|
|
7712
|
+
const angle = rotAngle !== null && !isNaN(rotAngle)
|
|
7713
|
+
? rotAngle
|
|
7714
|
+
: rotMatch
|
|
7715
|
+
? parseFloat(rotMatch[1])
|
|
7716
|
+
: null;
|
|
7717
|
+
if (angle !== null && !isNaN(angle) && Math.abs(angle) > 0.001) {
|
|
7718
|
+
let cx = 0;
|
|
7719
|
+
let cy = 0;
|
|
7720
|
+
const tag = element.tagName.toLowerCase();
|
|
7721
|
+
if (tag === 'line') {
|
|
7722
|
+
const x1 = parseFloat(element.getAttribute('x1') || '0') || 0;
|
|
7723
|
+
const y1 = parseFloat(element.getAttribute('y1') || '0') || 0;
|
|
7724
|
+
const x2 = parseFloat(element.getAttribute('x2') || '0') || 0;
|
|
7725
|
+
const y2 = parseFloat(element.getAttribute('y2') || '0') || 0;
|
|
7726
|
+
cx = (x1 + x2) / 2;
|
|
7727
|
+
cy = (y1 + y2) / 2;
|
|
7728
|
+
}
|
|
7729
|
+
else if (tag === 'circle' || tag === 'ellipse') {
|
|
7730
|
+
cx = parseFloat(element.getAttribute('cx') || '0') || 0;
|
|
7731
|
+
cy = parseFloat(element.getAttribute('cy') || '0') || 0;
|
|
7732
|
+
}
|
|
7733
|
+
else if (element.hasAttribute('x') ||
|
|
7734
|
+
element.hasAttribute('y') ||
|
|
7735
|
+
element.hasAttribute('width') ||
|
|
7736
|
+
element.hasAttribute('height')) {
|
|
7737
|
+
const curX = parseFloat(element.getAttribute('x') || '0') || 0;
|
|
7738
|
+
const curY = parseFloat(element.getAttribute('y') || '0') || 0;
|
|
7739
|
+
const curW = parseFloat(element.getAttribute('width') || '0') || 0;
|
|
7740
|
+
const curH = parseFloat(element.getAttribute('height') || '0') || 0;
|
|
7741
|
+
cx = curX + curW / 2;
|
|
7742
|
+
cy = curY + curH / 2;
|
|
7743
|
+
}
|
|
7744
|
+
else if (rotMatch && rotMatch[2] !== undefined && rotMatch[3] !== undefined) {
|
|
7745
|
+
cx = parseFloat(rotMatch[2]) || 0;
|
|
7746
|
+
cy = parseFloat(rotMatch[3]) || 0;
|
|
7747
|
+
}
|
|
7748
|
+
cleanTrans = cleanTrans.replace(/rotate\([^)]*\)/g, '').trim();
|
|
7749
|
+
const newRotate = `rotate(${angle} ${cx} ${cy})`;
|
|
7750
|
+
element.setAttribute('transform', cleanTrans ? `${cleanTrans} ${newRotate}` : newRotate);
|
|
7751
|
+
}
|
|
7752
|
+
else if (cleanTrans) {
|
|
7753
|
+
element.setAttribute('transform', cleanTrans);
|
|
7754
|
+
}
|
|
7755
|
+
else {
|
|
7756
|
+
element.removeAttribute('transform');
|
|
7757
|
+
}
|
|
7758
|
+
}
|
|
7759
|
+
ensureElementRotationTransforms(root) {
|
|
7760
|
+
if (!root)
|
|
7761
|
+
return;
|
|
7762
|
+
try {
|
|
7763
|
+
const allElements = root.querySelectorAll('*');
|
|
7764
|
+
allElements.forEach((el) => {
|
|
7765
|
+
this.updateElementRotation(el);
|
|
7766
|
+
});
|
|
7767
|
+
}
|
|
7768
|
+
catch (e) {
|
|
7769
|
+
console.warn('[SOLIDGENERATION] Error in ensureElementRotationTransforms:', e);
|
|
7770
|
+
}
|
|
7771
|
+
}
|
|
7653
7772
|
getUrlBase(sku) {
|
|
7654
7773
|
if (!sku)
|
|
7655
7774
|
return '';
|
|
@@ -8334,7 +8453,8 @@ class DataSheetPublication {
|
|
|
8334
8453
|
});
|
|
8335
8454
|
}
|
|
8336
8455
|
let lstSkus = [];
|
|
8337
|
-
|
|
8456
|
+
const sectionKey = section.pageGuid || section.publicationPageGuid || section.pageId.toString();
|
|
8457
|
+
let files2 = await this.DataSheetSVG.GenerateSvgFiles(lstSkus, backgroundTpl, backgroundTpl, sectionKey);
|
|
8338
8458
|
if (files2 != null) {
|
|
8339
8459
|
files2[0]['name'] = files2[0]['name'].replace(/_page\[\d+\]/, `_page[${countPage}]`);
|
|
8340
8460
|
files = files.concat(files2);
|
|
@@ -8530,7 +8650,8 @@ class DataSheetPublication {
|
|
|
8530
8650
|
}
|
|
8531
8651
|
}
|
|
8532
8652
|
}
|
|
8533
|
-
|
|
8653
|
+
const sectionKey = section.pageGuid || section.publicationPageGuid || section.pageId.toString();
|
|
8654
|
+
files = await this.DataSheetSVG.GenerateSvgFiles(lstSkus, backgroundTplLeft, backgroundTplRight, sectionKey);
|
|
8534
8655
|
lstBackgroundTags = [];
|
|
8535
8656
|
}
|
|
8536
8657
|
arrayFiles = arrayFiles.concat(files);
|