svgfusion 1.10.0 → 1.11.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 +60 -7
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +276 -276
- package/dist/index.mjs +276 -276
- package/package.json +2 -1
package/dist/cli.js
CHANGED
|
@@ -81063,7 +81063,8 @@ var SVGTransformer = class {
|
|
|
81063
81063
|
metadata: {
|
|
81064
81064
|
originalColors: colorMappings.map((m5) => m5.originalColor),
|
|
81065
81065
|
optimizationApplied: optimize,
|
|
81066
|
-
features
|
|
81066
|
+
features,
|
|
81067
|
+
hasClassAttributes: this.hasClassAttributes(transformedAst)
|
|
81067
81068
|
}
|
|
81068
81069
|
};
|
|
81069
81070
|
}
|
|
@@ -81179,6 +81180,18 @@ var SVGTransformer = class {
|
|
|
81179
81180
|
children: element.children.map((child) => this.deepCloneElement(child))
|
|
81180
81181
|
};
|
|
81181
81182
|
}
|
|
81183
|
+
/**
|
|
81184
|
+
* Check if the SVG has any class attributes in its elements
|
|
81185
|
+
*/
|
|
81186
|
+
hasClassAttributes(ast) {
|
|
81187
|
+
const checkElement = (element) => {
|
|
81188
|
+
if (element.attributes.class || element.attributes.className) {
|
|
81189
|
+
return true;
|
|
81190
|
+
}
|
|
81191
|
+
return element.children.some((child) => checkElement(child));
|
|
81192
|
+
};
|
|
81193
|
+
return checkElement(ast.root);
|
|
81194
|
+
}
|
|
81182
81195
|
};
|
|
81183
81196
|
|
|
81184
81197
|
// src/generators/react.ts
|
|
@@ -81272,17 +81285,25 @@ var ComponentGenerator = class {
|
|
|
81272
81285
|
/**
|
|
81273
81286
|
* Generate color props interface/type definitions
|
|
81274
81287
|
*/
|
|
81275
|
-
generateColorProps(colorMappings) {
|
|
81288
|
+
generateColorProps(colorMappings, includeClassProps = true) {
|
|
81276
81289
|
if (colorMappings.length === 0) return "";
|
|
81277
81290
|
return colorMappings.map((mapping) => {
|
|
81278
81291
|
const propName = mapping.variableName;
|
|
81279
81292
|
const className = `${propName}Class`;
|
|
81280
81293
|
if (this.options.typescript) {
|
|
81281
|
-
|
|
81294
|
+
let props = ` ${propName}?: string;`;
|
|
81295
|
+
if (includeClassProps) {
|
|
81296
|
+
props += `
|
|
81282
81297
|
${className}?: string;`;
|
|
81298
|
+
}
|
|
81299
|
+
return props;
|
|
81283
81300
|
} else {
|
|
81284
|
-
|
|
81301
|
+
let props = ` ${propName}: PropTypes.string,`;
|
|
81302
|
+
if (includeClassProps) {
|
|
81303
|
+
props += `
|
|
81285
81304
|
${className}: PropTypes.string,`;
|
|
81305
|
+
}
|
|
81306
|
+
return props;
|
|
81286
81307
|
}
|
|
81287
81308
|
}).join("\n");
|
|
81288
81309
|
}
|
|
@@ -101444,6 +101465,7 @@ ${childrenJsx}
|
|
|
101444
101465
|
attributesToJsxWithClasses(attributes) {
|
|
101445
101466
|
const jsxAttributes = [];
|
|
101446
101467
|
const classNames = [];
|
|
101468
|
+
const hasOriginalClass = "class" in attributes || "className" in attributes;
|
|
101447
101469
|
Object.entries(attributes).forEach(([key2, value]) => {
|
|
101448
101470
|
const jsxKey = toReactProp(key2);
|
|
101449
101471
|
if ((key2 === "fill" || key2 === "stroke") && value.startsWith("{") && value.endsWith("}")) {
|
|
@@ -101463,11 +101485,29 @@ ${childrenJsx}
|
|
|
101463
101485
|
}
|
|
101464
101486
|
});
|
|
101465
101487
|
if (classNames.length > 0) {
|
|
101488
|
+
const originalClass = attributes.class || attributes.className;
|
|
101466
101489
|
if (classNames.length === 1) {
|
|
101467
|
-
|
|
101490
|
+
if (originalClass) {
|
|
101491
|
+
jsxAttributes.push(
|
|
101492
|
+
`className={\`${originalClass} \${${classNames[0]}}\`}`
|
|
101493
|
+
);
|
|
101494
|
+
} else {
|
|
101495
|
+
jsxAttributes.push(`className={${classNames[0]}}`);
|
|
101496
|
+
}
|
|
101468
101497
|
} else {
|
|
101469
101498
|
const combinedClasses = classNames.map((cls) => `\${${cls}}`).join(" ");
|
|
101470
|
-
|
|
101499
|
+
if (originalClass) {
|
|
101500
|
+
jsxAttributes.push(
|
|
101501
|
+
`className={\`${originalClass} ${combinedClasses}\`}`
|
|
101502
|
+
);
|
|
101503
|
+
} else {
|
|
101504
|
+
jsxAttributes.push(`className={\`${combinedClasses}\`}`);
|
|
101505
|
+
}
|
|
101506
|
+
}
|
|
101507
|
+
} else if (hasOriginalClass) {
|
|
101508
|
+
const originalClass = attributes.class || attributes.className;
|
|
101509
|
+
if (originalClass) {
|
|
101510
|
+
jsxAttributes.push(`className="${originalClass}"`);
|
|
101471
101511
|
}
|
|
101472
101512
|
}
|
|
101473
101513
|
return jsxAttributes;
|
|
@@ -101598,6 +101638,7 @@ ${children}
|
|
|
101598
101638
|
const { tag, attributes, children, content } = element;
|
|
101599
101639
|
const vueAttributes = [];
|
|
101600
101640
|
const classVars = [];
|
|
101641
|
+
const hasOriginalClass = "class" in attributes;
|
|
101601
101642
|
Object.entries(attributes).forEach(([key2, value]) => {
|
|
101602
101643
|
if (value.startsWith("{") && value.endsWith("}")) {
|
|
101603
101644
|
const variableName = value.slice(1, -1);
|
|
@@ -101611,7 +101652,19 @@ ${children}
|
|
|
101611
101652
|
}
|
|
101612
101653
|
});
|
|
101613
101654
|
if (classVars.length > 0) {
|
|
101614
|
-
|
|
101655
|
+
const originalClass = attributes.class;
|
|
101656
|
+
if (originalClass) {
|
|
101657
|
+
vueAttributes.push(
|
|
101658
|
+
`:class="[${classVars.join(", ")}, '${originalClass}']"`
|
|
101659
|
+
);
|
|
101660
|
+
} else {
|
|
101661
|
+
vueAttributes.push(`:class="[${classVars.join(", ")}]"`);
|
|
101662
|
+
}
|
|
101663
|
+
} else if (hasOriginalClass) {
|
|
101664
|
+
const originalClass = attributes.class;
|
|
101665
|
+
if (originalClass) {
|
|
101666
|
+
vueAttributes.push(`class="${originalClass}"`);
|
|
101667
|
+
}
|
|
101615
101668
|
}
|
|
101616
101669
|
const attributeString = vueAttributes.length > 0 ? " " + vueAttributes.join(" ") : "";
|
|
101617
101670
|
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
|
*/
|
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
|
*/
|