@solidpepper/solidpepper-solidgeneration 0.2.1 → 0.2.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.
@@ -3445,19 +3445,16 @@ class DataSheetSVG {
3445
3445
  newVal = '';
3446
3446
  }
3447
3447
  }
3448
- let urlBase = '';
3449
- if (jRowSku['skuImagesDetail'] != null &&
3450
- jRowSku['skuImagesDetail'] != '') {
3451
- if (jRowSku['skuImagesDetail'][0] != null &&
3452
- jRowSku['skuImagesDetail'][0] != '') {
3453
- urlBase = jRowSku['skuImagesDetail'][0].assetUrlOriginal;
3454
- urlBase = urlBase.substring(0, urlBase.lastIndexOf('/') + 1);
3455
- }
3456
- }
3448
+ let urlBase = this.getUrlBase(jRowSku);
3457
3449
  if (urlBase != null &&
3458
3450
  urlBase != '' &&
3459
3451
  newVal != null &&
3460
- newVal != '') {
3452
+ newVal != '' &&
3453
+ typeof newVal === 'string' &&
3454
+ !newVal.startsWith('http://') &&
3455
+ !newVal.startsWith('https://') &&
3456
+ !newVal.startsWith('data:') &&
3457
+ !newVal.startsWith('/')) {
3461
3458
  newVal = urlBase + newVal;
3462
3459
  }
3463
3460
  }
@@ -3514,19 +3511,16 @@ class DataSheetSVG {
3514
3511
  newVal = '';
3515
3512
  }
3516
3513
  }
3517
- let urlBase = '';
3518
- if (jRowSku['skuImagesDetail'] != null &&
3519
- jRowSku['skuImagesDetail'] != '') {
3520
- if (jRowSku['skuImagesDetail'][0] != null &&
3521
- jRowSku['skuImagesDetail'][0] != '') {
3522
- urlBase = jRowSku['skuImagesDetail'][0].assetUrlOriginal;
3523
- urlBase = urlBase.substring(0, urlBase.lastIndexOf('/') + 1);
3524
- }
3525
- }
3514
+ let urlBase = this.getUrlBase(jRowSku);
3526
3515
  if (urlBase != null &&
3527
3516
  urlBase != '' &&
3528
3517
  newVal != null &&
3529
- newVal != '') {
3518
+ newVal != '' &&
3519
+ typeof newVal === 'string' &&
3520
+ !newVal.startsWith('http://') &&
3521
+ !newVal.startsWith('https://') &&
3522
+ !newVal.startsWith('data:') &&
3523
+ !newVal.startsWith('/')) {
3530
3524
  newVal = urlBase + newVal;
3531
3525
  }
3532
3526
  }
@@ -4377,20 +4371,79 @@ class DataSheetSVG {
4377
4371
  let skuImagesDetail = [];
4378
4372
  if (jRowSku &&
4379
4373
  jRowSku['skuImagesDetail'] &&
4374
+ Array.isArray(jRowSku['skuImagesDetail']) &&
4380
4375
  jRowSku['skuImagesDetail'].length > 0) {
4381
- skuImagesDetail = jRowSku['skuImagesDetail'].filter((image) => image && image.assetName === newVal);
4382
- if (skuImagesDetail.length > 0) {
4383
- if (this.DataSheet.preview &&
4384
- this.DataSheet.imageFastPreview == true) {
4385
- newVal = skuImagesDetail[0].assetUrlSmall;
4376
+ const cleanNewVal = this.getCleanFilename(newVal);
4377
+ const cleanNewValNoExt = this.getFileNameWithoutExt(newVal).toLowerCase();
4378
+ skuImagesDetail = jRowSku['skuImagesDetail'].filter((image) => {
4379
+ if (!image)
4380
+ return false;
4381
+ if (image.assetName === newVal || image.assetGuid === newVal)
4382
+ return true;
4383
+ if (image.assetName && this.getCleanFilename(image.assetName).toLowerCase() === cleanNewVal.toLowerCase()) {
4384
+ return true;
4385
+ }
4386
+ if (image.assetName && this.getFileNameWithoutExt(image.assetName).toLowerCase() === cleanNewValNoExt) {
4387
+ return true;
4386
4388
  }
4387
- else if (this.DataSheet.highDefinition == false) {
4388
- newVal = skuImagesDetail[0].assetUrlMedium;
4389
- urlHD = skuImagesDetail[0].assetUrlOriginal;
4389
+ const urls = [
4390
+ image.assetUrlOriginal,
4391
+ image.assetUrlMedium,
4392
+ image.assetUrlSmall,
4393
+ image.assetUrlBig,
4394
+ ].filter(Boolean);
4395
+ for (const url of urls) {
4396
+ if (url === newVal)
4397
+ return true;
4398
+ if (this.getCleanFilename(url).toLowerCase() === cleanNewVal.toLowerCase())
4399
+ return true;
4400
+ if (this.getFileNameWithoutExt(url).toLowerCase() === cleanNewValNoExt)
4401
+ return true;
4402
+ }
4403
+ return false;
4404
+ });
4405
+ }
4406
+ if (skuImagesDetail.length === 0 && jRowSku && jRowSku['skuDefaultImage']) {
4407
+ const defaultImg = jRowSku['skuDefaultImage'];
4408
+ const cleanNewValNoExt = this.getFileNameWithoutExt(newVal).toLowerCase();
4409
+ const defaultNameNoExt = this.getFileNameWithoutExt(defaultImg.assetName || defaultImg.assetUrlOriginal || '').toLowerCase();
4410
+ if (!cleanNewValNoExt || cleanNewValNoExt === defaultNameNoExt || defaultImg.assetGuid === newVal) {
4411
+ skuImagesDetail = [defaultImg];
4412
+ }
4413
+ }
4414
+ if (skuImagesDetail.length > 0) {
4415
+ const matchedAsset = skuImagesDetail[0];
4416
+ if (this.DataSheet.preview &&
4417
+ this.DataSheet.imageFastPreview == true) {
4418
+ newVal = matchedAsset.assetUrlSmall || matchedAsset.assetUrlMedium || matchedAsset.assetUrlBig || matchedAsset.assetUrlOriginal || newVal;
4419
+ urlHD = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4420
+ }
4421
+ else if (this.DataSheet.highDefinition == false) {
4422
+ newVal = matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || matchedAsset.assetUrlBig || matchedAsset.assetUrlOriginal || newVal;
4423
+ urlHD = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4424
+ }
4425
+ else {
4426
+ newVal = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4427
+ urlHD = matchedAsset.assetUrlOriginal || matchedAsset.assetUrlBig || matchedAsset.assetUrlMedium || matchedAsset.assetUrlSmall || newVal;
4428
+ }
4429
+ }
4430
+ else {
4431
+ let urlBase = this.getUrlBase(jRowSku);
4432
+ if (urlBase && typeof newVal === 'string' && !newVal.startsWith('http://') && !newVal.startsWith('https://') && !newVal.startsWith('data:') && !newVal.startsWith('/')) {
4433
+ newVal = urlBase + newVal;
4434
+ }
4435
+ urlHD = newVal;
4436
+ if (typeof newVal === 'string' &&
4437
+ (this.DataSheet.highDefinition == false || (this.DataSheet.preview && this.DataSheet.imageFastPreview == true))) {
4438
+ if (this.DataSheet.preview && this.DataSheet.imageFastPreview == true) {
4439
+ newVal = newVal
4440
+ .replace(/\/original\//i, '/small/')
4441
+ .replace(/\.[a-zA-Z0-9]+(?=\?|#|$)/i, '.webp');
4390
4442
  }
4391
4443
  else {
4392
- newVal = skuImagesDetail[0].assetUrlOriginal;
4393
- urlHD = skuImagesDetail[0].assetUrlOriginal;
4444
+ newVal = newVal
4445
+ .replace(/\/original\//i, '/medium/')
4446
+ .replace(/\.[a-zA-Z0-9]+(?=\?|#|$)/i, '.webp');
4394
4447
  }
4395
4448
  }
4396
4449
  }
@@ -5115,6 +5168,56 @@ class DataSheetSVG {
5115
5168
  const textareaElement = tempDiv.querySelector(`#${textareaId}`);
5116
5169
  if (textareaElement) {
5117
5170
  let parentFo = textareaElement.closest('foreignObject');
5171
+ const splitDivAtBr = (div) => {
5172
+ const br = div.querySelector('br');
5173
+ if (!br || !div.parentNode)
5174
+ return false;
5175
+ const nextDiv = div.cloneNode(true);
5176
+ let currInDiv = div.querySelector('br');
5177
+ while (currInDiv && currInDiv !== div) {
5178
+ const parent = currInDiv.parentNode;
5179
+ if (!parent)
5180
+ break;
5181
+ while (currInDiv.nextSibling) {
5182
+ parent.removeChild(currInDiv.nextSibling);
5183
+ }
5184
+ const toRemove = currInDiv;
5185
+ currInDiv = parent;
5186
+ if (toRemove.nodeName.toLowerCase() === 'br') {
5187
+ parent.removeChild(toRemove);
5188
+ }
5189
+ }
5190
+ let currInNext = nextDiv.querySelector('br');
5191
+ while (currInNext && currInNext !== nextDiv) {
5192
+ const parent = currInNext.parentNode;
5193
+ if (!parent)
5194
+ break;
5195
+ while (currInNext.previousSibling) {
5196
+ parent.removeChild(currInNext.previousSibling);
5197
+ }
5198
+ const toRemove = currInNext;
5199
+ currInNext = parent;
5200
+ if (toRemove.nodeName.toLowerCase() === 'br') {
5201
+ parent.removeChild(toRemove);
5202
+ }
5203
+ }
5204
+ div.parentNode.insertBefore(nextDiv, div.nextSibling);
5205
+ if (!nextDiv.textContent || !nextDiv.textContent.trim()) {
5206
+ nextDiv.remove();
5207
+ }
5208
+ return true;
5209
+ };
5210
+ let hasBr = true;
5211
+ while (hasBr) {
5212
+ hasBr = false;
5213
+ const divsWithBr = Array.from(textareaElement.querySelectorAll('div')).filter((d) => d.querySelector('br') !== null);
5214
+ for (const d of divsWithBr) {
5215
+ if (splitDivAtBr(d)) {
5216
+ hasBr = true;
5217
+ break;
5218
+ }
5219
+ }
5220
+ }
5118
5221
  // Split long text wrapping into separate divs to prevent overlap and highlight blockiness
5119
5222
  const lineDivs = Array.from(textareaElement.querySelectorAll('div')).filter((d) => {
5120
5223
  return d.querySelectorAll('div').length === 0;
@@ -5833,6 +5936,11 @@ class DataSheetSVG {
5833
5936
  getActualBlockHeight(svgContent, initialBlockHeight, blockY = 0) {
5834
5937
  if (!svgContent)
5835
5938
  return { actualHeight: initialBlockHeight, updatedSvg: svgContent };
5939
+ const hasVariantTable = /id=["']tableVariant["']/i.test(svgContent) ||
5940
+ /data-info=["']variantTable["']/i.test(svgContent);
5941
+ if (!hasVariantTable) {
5942
+ return { actualHeight: initialBlockHeight, updatedSvg: svgContent };
5943
+ }
5836
5944
  let maxBottom = 0;
5837
5945
  try {
5838
5946
  // 1. Measure foreignObjects (tables, textareas, etc.)
@@ -5882,7 +5990,7 @@ class DataSheetSVG {
5882
5990
  }
5883
5991
  let calculatedHeight = initialBlockHeight;
5884
5992
  if (maxBottom > 0) {
5885
- calculatedHeight = Math.ceil(maxBottom - blockY);
5993
+ calculatedHeight = Math.max(initialBlockHeight, Math.ceil(maxBottom - blockY));
5886
5994
  }
5887
5995
  // Update background block rect height in svgContent if present
5888
5996
  let updatedSvg = svgContent;
@@ -6330,6 +6438,47 @@ class DataSheetSVG {
6330
6438
  el.setAttribute('y', newY.toString());
6331
6439
  });
6332
6440
  }
6441
+ getUrlBase(sku) {
6442
+ if (!sku)
6443
+ return '';
6444
+ if (Array.isArray(sku['skuImagesDetail']) &&
6445
+ sku['skuImagesDetail'].length > 0) {
6446
+ for (const img of sku['skuImagesDetail']) {
6447
+ if (!img)
6448
+ continue;
6449
+ const url = img.assetUrlOriginal ||
6450
+ img.assetUrlMedium ||
6451
+ img.assetUrlSmall ||
6452
+ img.assetUrlBig;
6453
+ if (url && typeof url === 'string' && url.includes('/')) {
6454
+ return url.substring(0, url.lastIndexOf('/') + 1);
6455
+ }
6456
+ }
6457
+ }
6458
+ if (sku['skuDefaultImage']) {
6459
+ const defaultImg = sku['skuDefaultImage'];
6460
+ const url = defaultImg.assetUrlOriginal ||
6461
+ defaultImg.assetUrlMedium ||
6462
+ defaultImg.assetUrlSmall ||
6463
+ defaultImg.assetUrlBig;
6464
+ if (url && typeof url === 'string' && url.includes('/')) {
6465
+ return url.substring(0, url.lastIndexOf('/') + 1);
6466
+ }
6467
+ }
6468
+ return '';
6469
+ }
6470
+ getCleanFilename(str) {
6471
+ if (!str || typeof str !== 'string')
6472
+ return '';
6473
+ const noQuery = str.split('?')[0].split('#')[0];
6474
+ const lastSlash = noQuery.lastIndexOf('/');
6475
+ return lastSlash !== -1 ? noQuery.substring(lastSlash + 1) : noQuery;
6476
+ }
6477
+ getFileNameWithoutExt(str) {
6478
+ const fn = this.getCleanFilename(str);
6479
+ const lastDot = fn.lastIndexOf('.');
6480
+ return lastDot !== -1 ? fn.substring(0, lastDot) : fn;
6481
+ }
6333
6482
  }
6334
6483
 
6335
6484
  class DataSheetSku {