Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 committed Jan 2, 2024
1 parent d854409 commit 544b781
Showing 1 changed file with 5 additions and 28 deletions.
33 changes: 5 additions & 28 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,10 @@ export function svgHasOnlyPathChild(svg: string): boolean {

if (mode) return true;

let path = 0;
const fill = [];

for (let idx = 0; idx < svgAst.children?.[0]?.children?.length; idx++) {
const child = svgAst.children?.[0]?.children[idx];
const isRect = child?.name === 'rect' && child?.attributes?.fill;
const isCircle = child?.name === 'circle' && child?.attributes?.fill;
const isEllipse = child?.name === 'ellipse' && child?.attributes?.fill;
const isPolygon = child?.name === 'polygon' && child?.attributes?.fill;
const isPolyline = child?.name === 'polyline' && child?.attributes?.fill;

if (child.name === 'path' || isRect || isCircle || isEllipse || isPolygon || isPolyline) {
path = path + 1;
}

if (child?.attributes?.fill && child?.attributes?.fill !== 'none') {
fill.push(JSON.stringify(stringToColor(child?.attributes?.fill)));
Expand All @@ -61,33 +51,20 @@ export function svgHasOnlyPathChild(svg: string): boolean {
for (let j = 0; j < child.children?.length; j++) {
const child2 = child.children[j];

const isRect = child2?.name === 'rect' && child2?.attributes?.fill;
const isCircle = child2?.name === 'circle' && child2?.attributes?.fill;
const isEllipse = child2?.name === 'ellipse' && child2?.attributes?.fill;
const isPolygon = child2?.name === 'polygon' && child2?.attributes?.fill;
const isPolyline = child2?.name === 'polyline' && child2?.attributes?.fill;

if (child2.name === 'path' || isRect || isCircle || isEllipse || isPolygon || isPolyline) {
path = path + 1;
}

if (child2?.attributes?.fill && child2?.attributes?.fill !== 'none') {
fill.push(JSON.stringify(stringToColor(child2?.attributes?.fill)));
}
}
}
}

if (fill.length === 1) return true;
if (!fill.length || fill.length === 1) return true;

if (fill.length > 1) {
const fillSet = new Set(fill);
const fillSet = new Set(fill);

if (fillSet.size > 1) {
return false;
}
return true;
if (fillSet.size > 1) {
return false;
}

return path > 1 ? false : true;
return true;
}

0 comments on commit 544b781

Please sign in to comment.