svgfusion 1.13.0 → 1.14.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,40 @@ var ColorSplittingFeature = class {
80774
80774
  newAttributes["stop-color"]
80775
80775
  )}}`;
80776
80776
  }
80777
+ if (newAttributes.style) {
80778
+ let updatedStyle = newAttributes.style;
80779
+ const fillMatch = updatedStyle.match(/fill:\s*([^;]+)/);
80780
+ if (fillMatch) {
80781
+ const fillColor = fillMatch[1].trim();
80782
+ if (colorMap.has(fillColor)) {
80783
+ updatedStyle = updatedStyle.replace(
80784
+ /fill:\s*[^;]+/,
80785
+ `fill: {${colorMap.get(fillColor)}}`
80786
+ );
80787
+ }
80788
+ }
80789
+ const strokeMatch = updatedStyle.match(/stroke:\s*([^;]+)/);
80790
+ if (strokeMatch) {
80791
+ const strokeColor = strokeMatch[1].trim();
80792
+ if (colorMap.has(strokeColor)) {
80793
+ updatedStyle = updatedStyle.replace(
80794
+ /stroke:\s*[^;]+/,
80795
+ `stroke: {${colorMap.get(strokeColor)}}`
80796
+ );
80797
+ }
80798
+ }
80799
+ const stopColorMatch = updatedStyle.match(/stop-color:\s*([^;]+)/);
80800
+ if (stopColorMatch) {
80801
+ const stopColor = stopColorMatch[1].trim();
80802
+ if (colorMap.has(stopColor)) {
80803
+ updatedStyle = updatedStyle.replace(
80804
+ /stop-color:\s*[^;]+/,
80805
+ `stop-color: {${colorMap.get(stopColor)}}`
80806
+ );
80807
+ }
80808
+ }
80809
+ newAttributes.style = updatedStyle;
80810
+ }
80777
80811
  if (this.isDrawableElement(el2.tag)) {
80778
80812
  const originalHadFill = el2.attributes.fill !== void 0 && el2.attributes.fill !== "";
80779
80813
  const originalHadStroke = el2.attributes.stroke !== void 0 && el2.attributes.stroke !== "";
@@ -80815,6 +80849,17 @@ var ColorSplittingFeature = class {
80815
80849
  attribute: "stop-color"
80816
80850
  });
80817
80851
  }
80852
+ if (element.attributes.style) {
80853
+ const styleColors = this.extractColorsFromStyle(element.attributes.style);
80854
+ styleColors.forEach((color) => {
80855
+ colors.push({
80856
+ value: color.value,
80857
+ type: color.type,
80858
+ element,
80859
+ attribute: "style"
80860
+ });
80861
+ });
80862
+ }
80818
80863
  element.children.forEach((child) => this.traverseElement(child, colors));
80819
80864
  }
80820
80865
  /**
@@ -80883,6 +80928,34 @@ var ColorSplittingFeature = class {
80883
80928
  ];
80884
80929
  return namedColors.includes(color.toLowerCase());
80885
80930
  }
80931
+ /**
80932
+ * Extract colors from style attribute
80933
+ */
80934
+ extractColorsFromStyle(style) {
80935
+ const colors = [];
80936
+ const fillMatch = style.match(/fill:\s*([^;]+)/);
80937
+ if (fillMatch) {
80938
+ const fillColor = fillMatch[1].trim();
80939
+ if (this.isValidColor(fillColor)) {
80940
+ colors.push({ value: fillColor, type: "fill" });
80941
+ }
80942
+ }
80943
+ const strokeMatch = style.match(/stroke:\s*([^;]+)/);
80944
+ if (strokeMatch) {
80945
+ const strokeColor = strokeMatch[1].trim();
80946
+ if (this.isValidColor(strokeColor)) {
80947
+ colors.push({ value: strokeColor, type: "stroke" });
80948
+ }
80949
+ }
80950
+ const stopColorMatch = style.match(/stop-color:\s*([^;]+)/);
80951
+ if (stopColorMatch) {
80952
+ const stopColor = stopColorMatch[1].trim();
80953
+ if (this.isValidColor(stopColor)) {
80954
+ colors.push({ value: stopColor, type: "stop-color" });
80955
+ }
80956
+ }
80957
+ return colors;
80958
+ }
80886
80959
  };
80887
80960
 
80888
80961
  // src/features/stroke-fixing.ts
@@ -80925,12 +80998,6 @@ var StrokeFixingFeature = class {
80925
80998
  if (this.options.preserveExisting && element.attributes["vector-effect"]) {
80926
80999
  return false;
80927
81000
  }
80928
- if (this.options.onlyIfStrokePresent) {
80929
- const hasStroke = element.attributes.stroke && element.attributes.stroke !== "none" && element.attributes.stroke !== "transparent";
80930
- if (!hasStroke) {
80931
- return false;
80932
- }
80933
- }
80934
81001
  const strokeElements = [
80935
81002
  "path",
80936
81003
  "line",
@@ -81113,7 +81180,8 @@ var SVGTransformer = class {
81113
81180
  */
81114
81181
  applyFixedStrokeWidth(ast) {
81115
81182
  const strokeFixingFeature = new StrokeFixingFeature({
81116
- onlyIfStrokePresent: true,
81183
+ onlyIfStrokePresent: false,
81184
+ // Apply to all stroke-capable elements for consistent scaling
81117
81185
  preserveExisting: true
81118
81186
  });
81119
81187
  const result = strokeFixingFeature.apply(ast.root);
@@ -101496,14 +101564,26 @@ ${childrenJsx}
101496
101564
  const hasOriginalClass = "class" in attributes || "className" in attributes;
101497
101565
  Object.entries(attributes).forEach(([key2, value]) => {
101498
101566
  const jsxKey = toReactProp(key2);
101499
- if ((key2 === "fill" || key2 === "stroke") && value.startsWith("{") && value.endsWith("}")) {
101567
+ if (key2 === "vector-effect" && value === "non-scaling-stroke") {
101568
+ jsxAttributes.push(
101569
+ `vectorEffect={isFixedStrokeWidth ? 'non-scaling-stroke' : undefined}`
101570
+ );
101571
+ } else if ((key2 === "fill" || key2 === "stroke") && value.startsWith("{") && value.endsWith("}")) {
101500
101572
  const colorVar = value.slice(1, -1);
101501
101573
  jsxAttributes.push(`${jsxKey}=${value}`);
101502
101574
  const classVar = `${colorVar}Class`;
101503
101575
  classNames.push(classVar);
101504
101576
  } else if (key2 === "style") {
101505
101577
  const styleObj = this.parseStyleString(value);
101506
- jsxAttributes.push(`style={${JSON.stringify(styleObj)}}`);
101578
+ const styleEntries = Object.entries(styleObj).map(([prop, val]) => {
101579
+ if (typeof val === "string" && val.startsWith("{") && val.endsWith("}")) {
101580
+ const varName = val.slice(1, -1);
101581
+ return `${prop}: ${varName}`;
101582
+ } else {
101583
+ return `${prop}: '${val}'`;
101584
+ }
101585
+ });
101586
+ jsxAttributes.push(`style={{ ${styleEntries.join(", ")} }}`);
101507
101587
  } else {
101508
101588
  if (value.startsWith("{") && value.endsWith("}")) {
101509
101589
  jsxAttributes.push(`${jsxKey}=${value}`);
@@ -101668,7 +101748,14 @@ ${children}
101668
101748
  const classVars = [];
101669
101749
  const hasOriginalClass = "class" in attributes;
101670
101750
  Object.entries(attributes).forEach(([key2, value]) => {
101671
- if (value.startsWith("{") && value.endsWith("}")) {
101751
+ if (key2 === "vector-effect" && value === "non-scaling-stroke") {
101752
+ vueAttributes.push(
101753
+ `:vector-effect="props.isFixedStrokeWidth ? 'non-scaling-stroke' : undefined"`
101754
+ );
101755
+ } else if (key2 === "style") {
101756
+ const parsedStyle = this.parseStyleStringForVue(value);
101757
+ vueAttributes.push(`:style="${parsedStyle}"`);
101758
+ } else if (value.startsWith("{") && value.endsWith("}")) {
101672
101759
  const variableName = value.slice(1, -1);
101673
101760
  vueAttributes.push(`:${key2}="props.${variableName}"`);
101674
101761
  if (key2 === "fill" || key2 === "stroke") {
@@ -101879,6 +101966,28 @@ ${children}
101879
101966
  ${className}?: string;`;
101880
101967
  }).join("\n");
101881
101968
  }
101969
+ /**
101970
+ * Parse style string for Vue template syntax
101971
+ */
101972
+ parseStyleStringForVue(styleStr) {
101973
+ const styleEntries = [];
101974
+ styleStr.split(";").forEach((declaration) => {
101975
+ const colonIndex = declaration.indexOf(":");
101976
+ if (colonIndex > 0) {
101977
+ const property = declaration.slice(0, colonIndex).trim();
101978
+ const value = declaration.slice(colonIndex + 1).trim();
101979
+ if (property && value) {
101980
+ if (value.startsWith("{") && value.endsWith("}")) {
101981
+ const variableName = value.slice(1, -1);
101982
+ styleEntries.push(`'${property}': props.${variableName}`);
101983
+ } else {
101984
+ styleEntries.push(`'${property}': '${value}'`);
101985
+ }
101986
+ }
101987
+ }
101988
+ });
101989
+ return `{ ${styleEntries.join(", ")} }`;
101990
+ }
101882
101991
  /**
101883
101992
  * Generate SVG root attributes for Vue template
101884
101993
  */
package/dist/index.d.mts CHANGED
@@ -348,6 +348,10 @@ declare class VueGenerator extends ComponentGenerator {
348
348
  * Generate TypeScript interface for color props
349
349
  */
350
350
  private generateColorPropsInterface;
351
+ /**
352
+ * Parse style string for Vue template syntax
353
+ */
354
+ private parseStyleStringForVue;
351
355
  /**
352
356
  * Generate SVG root attributes for Vue template
353
357
  */
@@ -458,6 +462,10 @@ declare class ColorSplittingFeature {
458
462
  * Check if a color value is valid and should be replaced
459
463
  */
460
464
  private isValidColor;
465
+ /**
466
+ * Extract colors from style attribute
467
+ */
468
+ private extractColorsFromStyle;
461
469
  }
462
470
 
463
471
  /**
package/dist/index.d.ts CHANGED
@@ -348,6 +348,10 @@ declare class VueGenerator extends ComponentGenerator {
348
348
  * Generate TypeScript interface for color props
349
349
  */
350
350
  private generateColorPropsInterface;
351
+ /**
352
+ * Parse style string for Vue template syntax
353
+ */
354
+ private parseStyleStringForVue;
351
355
  /**
352
356
  * Generate SVG root attributes for Vue template
353
357
  */
@@ -458,6 +462,10 @@ declare class ColorSplittingFeature {
458
462
  * Check if a color value is valid and should be replaced
459
463
  */
460
464
  private isValidColor;
465
+ /**
466
+ * Extract colors from style attribute
467
+ */
468
+ private extractColorsFromStyle;
461
469
  }
462
470
 
463
471
  /**