@solidpepper/solidpepper-solidgeneration 0.1.6 → 0.1.7

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.
@@ -5093,8 +5093,43 @@ class DataSheetSVG {
5093
5093
  }
5094
5094
  keepOnlySideRegex(svg, sideToKeep) {
5095
5095
  const sideToRemove = sideToKeep === 'left' ? 'right' : 'left';
5096
+ if (typeof DOMParser !== 'undefined' && typeof XMLSerializer !== 'undefined') {
5097
+ try {
5098
+ const parser = new DOMParser();
5099
+ const doc = parser.parseFromString(svg, 'image/svg+xml');
5100
+ const parserErrors = doc.getElementsByTagName('parsererror');
5101
+ if (parserErrors.length === 0) {
5102
+ // Robustly remove the unwanted side
5103
+ const elementsToRemove = doc.querySelectorAll(`[data-side="${sideToRemove}"]`);
5104
+ elementsToRemove.forEach(el => el.remove());
5105
+ // Clean up visibility constraints on the kept side
5106
+ const elementsToKeep = doc.querySelectorAll(`[data-side="${sideToKeep}"]`);
5107
+ elementsToKeep.forEach(el => {
5108
+ if (el instanceof SVGElement || el instanceof HTMLElement) {
5109
+ el.style.removeProperty('display');
5110
+ el.style.removeProperty('visibility');
5111
+ }
5112
+ });
5113
+ const serializer = new XMLSerializer();
5114
+ return serializer.serializeToString(doc);
5115
+ }
5116
+ }
5117
+ catch (e) {
5118
+ console.warn('DOMParser failed in keepOnlySideRegex, falling back to regex method:', e);
5119
+ }
5120
+ }
5096
5121
  const regex = new RegExp(`<g[^>]*data-side=["']${sideToRemove}["'][\\s\\S]*?<\\/g>`, 'i');
5097
- return svg.replace(regex, '');
5122
+ let cleanedSvg = svg.replace(regex, '');
5123
+ // Also clean up visibility/pointer-events styles on the kept side using regex for environments without DOMParser
5124
+ const keptSideRegex = new RegExp(`(<g[^>]*data-side=["']${sideToKeep}["'][^>]*style=["'])([^"']*)(["']>)`, 'i');
5125
+ cleanedSvg = cleanedSvg.replace(keptSideRegex, (match, before, styleContent, after) => {
5126
+ const cleanStyle = styleContent
5127
+ .replace(/visibility\s*:\s*hidden\s*;?/gi, '')
5128
+ .replace(/pointer-events\s*:\s*none\s*;?/gi, '')
5129
+ .trim();
5130
+ return before + cleanStyle + after;
5131
+ });
5132
+ return cleanedSvg;
5098
5133
  }
5099
5134
  applyTextTransform(val, transform) {
5100
5135
  if (!val || typeof val !== 'string' || !transform)