svgfusion 1.10.0 → 1.12.0

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.
package/dist/cli.js CHANGED
@@ -80774,6 +80774,16 @@ var ColorSplittingFeature = class {
80774
80774
  newAttributes["stop-color"]
80775
80775
  )}}`;
80776
80776
  }
80777
+ if (this.isDrawableElement(el2.tag)) {
80778
+ const originalHadFill = el2.attributes.fill !== void 0 && el2.attributes.fill !== "";
80779
+ const originalHadStroke = el2.attributes.stroke !== void 0 && el2.attributes.stroke !== "";
80780
+ if (originalHadFill && !originalHadStroke && !newAttributes.stroke) {
80781
+ newAttributes.stroke = "none";
80782
+ }
80783
+ if (originalHadStroke && !originalHadFill && !newAttributes.fill) {
80784
+ newAttributes.fill = "none";
80785
+ }
80786
+ }
80777
80787
  return { ...el2, attributes: newAttributes };
80778
80788
  });
80779
80789
  }
@@ -80819,6 +80829,24 @@ var ColorSplittingFeature = class {
80819
80829
  )
80820
80830
  };
80821
80831
  }
80832
+ /**
80833
+ * Check if an element is a drawable SVG element that can have fill/stroke
80834
+ */
80835
+ isDrawableElement(tag) {
80836
+ const drawableElements = [
80837
+ "path",
80838
+ "circle",
80839
+ "ellipse",
80840
+ "line",
80841
+ "rect",
80842
+ "polygon",
80843
+ "polyline",
80844
+ "text",
80845
+ "tspan",
80846
+ "use"
80847
+ ];
80848
+ return drawableElements.includes(tag);
80849
+ }
80822
80850
  /**
80823
80851
  * Check if a color value is valid and should be replaced
80824
80852
  */
@@ -81063,7 +81091,8 @@ var SVGTransformer = class {
81063
81091
  metadata: {
81064
81092
  originalColors: colorMappings.map((m5) => m5.originalColor),
81065
81093
  optimizationApplied: optimize,
81066
- features
81094
+ features,
81095
+ hasClassAttributes: this.hasClassAttributes(transformedAst)
81067
81096
  }
81068
81097
  };
81069
81098
  }
@@ -81179,6 +81208,18 @@ var SVGTransformer = class {
81179
81208
  children: element.children.map((child) => this.deepCloneElement(child))
81180
81209
  };
81181
81210
  }
81211
+ /**
81212
+ * Check if the SVG has any class attributes in its elements
81213
+ */
81214
+ hasClassAttributes(ast) {
81215
+ const checkElement = (element) => {
81216
+ if (element.attributes.class || element.attributes.className) {
81217
+ return true;
81218
+ }
81219
+ return element.children.some((child) => checkElement(child));
81220
+ };
81221
+ return checkElement(ast.root);
81222
+ }
81182
81223
  };
81183
81224
 
81184
81225
  // src/generators/react.ts
@@ -81272,17 +81313,25 @@ var ComponentGenerator = class {
81272
81313
  /**
81273
81314
  * Generate color props interface/type definitions
81274
81315
  */
81275
- generateColorProps(colorMappings) {
81316
+ generateColorProps(colorMappings, includeClassProps = true) {
81276
81317
  if (colorMappings.length === 0) return "";
81277
81318
  return colorMappings.map((mapping) => {
81278
81319
  const propName = mapping.variableName;
81279
81320
  const className = `${propName}Class`;
81280
81321
  if (this.options.typescript) {
81281
- return ` ${propName}?: string;
81322
+ let props = ` ${propName}?: string;`;
81323
+ if (includeClassProps) {
81324
+ props += `
81282
81325
  ${className}?: string;`;
81326
+ }
81327
+ return props;
81283
81328
  } else {
81284
- return ` ${propName}: PropTypes.string,
81329
+ let props = ` ${propName}: PropTypes.string,`;
81330
+ if (includeClassProps) {
81331
+ props += `
81285
81332
  ${className}: PropTypes.string,`;
81333
+ }
81334
+ return props;
81286
81335
  }
81287
81336
  }).join("\n");
81288
81337
  }
@@ -101444,6 +101493,7 @@ ${childrenJsx}
101444
101493
  attributesToJsxWithClasses(attributes) {
101445
101494
  const jsxAttributes = [];
101446
101495
  const classNames = [];
101496
+ const hasOriginalClass = "class" in attributes || "className" in attributes;
101447
101497
  Object.entries(attributes).forEach(([key2, value]) => {
101448
101498
  const jsxKey = toReactProp(key2);
101449
101499
  if ((key2 === "fill" || key2 === "stroke") && value.startsWith("{") && value.endsWith("}")) {
@@ -101463,11 +101513,29 @@ ${childrenJsx}
101463
101513
  }
101464
101514
  });
101465
101515
  if (classNames.length > 0) {
101516
+ const originalClass = attributes.class || attributes.className;
101466
101517
  if (classNames.length === 1) {
101467
- jsxAttributes.push(`className={${classNames[0]}}`);
101518
+ if (originalClass) {
101519
+ jsxAttributes.push(
101520
+ `className={\`${originalClass} \${${classNames[0]}}\`}`
101521
+ );
101522
+ } else {
101523
+ jsxAttributes.push(`className={${classNames[0]}}`);
101524
+ }
101468
101525
  } else {
101469
101526
  const combinedClasses = classNames.map((cls) => `\${${cls}}`).join(" ");
101470
- jsxAttributes.push(`className={\`${combinedClasses}\`}`);
101527
+ if (originalClass) {
101528
+ jsxAttributes.push(
101529
+ `className={\`${originalClass} ${combinedClasses}\`}`
101530
+ );
101531
+ } else {
101532
+ jsxAttributes.push(`className={\`${combinedClasses}\`}`);
101533
+ }
101534
+ }
101535
+ } else if (hasOriginalClass) {
101536
+ const originalClass = attributes.class || attributes.className;
101537
+ if (originalClass) {
101538
+ jsxAttributes.push(`className="${originalClass}"`);
101471
101539
  }
101472
101540
  }
101473
101541
  return jsxAttributes;
@@ -101598,6 +101666,7 @@ ${children}
101598
101666
  const { tag, attributes, children, content } = element;
101599
101667
  const vueAttributes = [];
101600
101668
  const classVars = [];
101669
+ const hasOriginalClass = "class" in attributes;
101601
101670
  Object.entries(attributes).forEach(([key2, value]) => {
101602
101671
  if (value.startsWith("{") && value.endsWith("}")) {
101603
101672
  const variableName = value.slice(1, -1);
@@ -101611,7 +101680,19 @@ ${children}
101611
101680
  }
101612
101681
  });
101613
101682
  if (classVars.length > 0) {
101614
- vueAttributes.push(`:class="[${classVars.join(", ")}]"`);
101683
+ const originalClass = attributes.class;
101684
+ if (originalClass) {
101685
+ vueAttributes.push(
101686
+ `:class="[${classVars.join(", ")}, '${originalClass}']"`
101687
+ );
101688
+ } else {
101689
+ vueAttributes.push(`:class="[${classVars.join(", ")}]"`);
101690
+ }
101691
+ } else if (hasOriginalClass) {
101692
+ const originalClass = attributes.class;
101693
+ if (originalClass) {
101694
+ vueAttributes.push(`class="${originalClass}"`);
101695
+ }
101615
101696
  }
101616
101697
  const attributeString = vueAttributes.length > 0 ? " " + vueAttributes.join(" ") : "";
101617
101698
  if (children.length === 0 && !content) {
package/dist/index.d.mts CHANGED
@@ -91,6 +91,7 @@ interface TransformationResult {
91
91
  originalColors: string[];
92
92
  optimizationApplied: boolean;
93
93
  features: string[];
94
+ hasClassAttributes: boolean;
94
95
  };
95
96
  }
96
97
  /**
@@ -145,6 +146,10 @@ declare class SVGTransformer {
145
146
  * Deep clone SVG element
146
147
  */
147
148
  private deepCloneElement;
149
+ /**
150
+ * Check if the SVG has any class attributes in its elements
151
+ */
152
+ private hasClassAttributes;
148
153
  }
149
154
 
150
155
  /**
@@ -195,7 +200,7 @@ declare abstract class ComponentGenerator {
195
200
  /**
196
201
  * Generate color props interface/type definitions
197
202
  */
198
- protected generateColorProps(colorMappings: ColorMapping[]): string;
203
+ protected generateColorProps(colorMappings: ColorMapping[], includeClassProps?: boolean): string;
199
204
  /**
200
205
  * Generate default props for colors
201
206
  */
@@ -445,6 +450,10 @@ declare class ColorSplittingFeature {
445
450
  * Transform element and all its children
446
451
  */
447
452
  private transformElement;
453
+ /**
454
+ * Check if an element is a drawable SVG element that can have fill/stroke
455
+ */
456
+ private isDrawableElement;
448
457
  /**
449
458
  * Check if a color value is valid and should be replaced
450
459
  */
package/dist/index.d.ts CHANGED
@@ -91,6 +91,7 @@ interface TransformationResult {
91
91
  originalColors: string[];
92
92
  optimizationApplied: boolean;
93
93
  features: string[];
94
+ hasClassAttributes: boolean;
94
95
  };
95
96
  }
96
97
  /**
@@ -145,6 +146,10 @@ declare class SVGTransformer {
145
146
  * Deep clone SVG element
146
147
  */
147
148
  private deepCloneElement;
149
+ /**
150
+ * Check if the SVG has any class attributes in its elements
151
+ */
152
+ private hasClassAttributes;
148
153
  }
149
154
 
150
155
  /**
@@ -195,7 +200,7 @@ declare abstract class ComponentGenerator {
195
200
  /**
196
201
  * Generate color props interface/type definitions
197
202
  */
198
- protected generateColorProps(colorMappings: ColorMapping[]): string;
203
+ protected generateColorProps(colorMappings: ColorMapping[], includeClassProps?: boolean): string;
199
204
  /**
200
205
  * Generate default props for colors
201
206
  */
@@ -445,6 +450,10 @@ declare class ColorSplittingFeature {
445
450
  * Transform element and all its children
446
451
  */
447
452
  private transformElement;
453
+ /**
454
+ * Check if an element is a drawable SVG element that can have fill/stroke
455
+ */
456
+ private isDrawableElement;
448
457
  /**
449
458
  * Check if a color value is valid and should be replaced
450
459
  */