Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally replace stroke color #68

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

digitalacorn
Copy link

Expose an option to enable or disable the replacement of the stroke colors within the SVG content.

Default behaviour remains the same

@peterdzl
Copy link

@anncwb Hi - Please could you run this trivial update through the workflow for a patch update

@nelsonjd
Copy link

nelsonjd commented Aug 9, 2022

@anncwb I need this too. Can you take a look at this pr? Thanks.

@tangxiangmin
Copy link

+1

@seahindeniz
Copy link

seahindeniz commented Mar 1, 2023

I believe this is not in the scope of this plugin. The expected logic should be handled by an SVGO plugin

@peterdzl
Copy link

peterdzl commented Mar 1, 2023

I believe this is not in the scope of this plugin. The expected logic should be handled by an SVGO plugin

Thanks for the reply - it seems colours are replaced by this module /after/ the SVGO stage. How do you propose this is solved by the SVGO options?

@digitalacorn
Copy link
Author

I have published a forked version which supports disabling the replacement of the stroke colour.
https://www.npmjs.com/package/@digitalacorn/vite-plugin-svg-icons

@alexgilbertDG
Copy link

This should be merge

1 similar comment
@ywenhao
Copy link

ywenhao commented Jun 29, 2023

This should be merge

content = content.replace(/stroke="[a-zA-Z#0-9]*"/, 'stroke="currentColor"')
if (options.replaceStrokeWithCurrentColor) {
// fix cannot change svg color by parent node problem
content = content.replace(/stroke="[a-zA-Z#0-9]*"/, 'stroke="currentColor"')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can replace multiple strokes at once instead of just one.

@bineagu
Copy link

bineagu commented Oct 23, 2023

This is annoying, been playing with svgo options and it drove me mad, only to find out the issue was in this plugin all along.

@mikezotovdev
Copy link

mikezotovdev commented Mar 15, 2024

Hey @anncwb, could you please take a moment to review that MR and merge it? If there are any additional changes or adjustments needed, I'm more than willing to collaborate further to ensure its seamless integration into the project. I hope @digitalacorn also could help.

Here is a little example of inconsistency, that the default behavior of the plugin produces: in the USA SVG flag, it makes white stripes black. And it's not possible to fix it, rather than passing color: #fff, which is not something that I want to do, since the fill color shouldn't be always #fff - there are more flags with not only white strokes. It also affects 17 more flags from one popular library with SVG country flags.

Black USA flag (the stroke was replaced with currentColor):
image

Proof that not only white color is used as a stroke:
telegram-cloud-photo-size-2-5449688246331233981-y

Is there any chance you can merge the changes and deploy a new version of your plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.