-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
fix(gatsby-remark-images): allow tracedSVG to accept object with settings #28242
Conversation
// this plugin also allow to use key names and not exact values | ||
`TURNPOLICY_BLACK`, | ||
`TURNPOLICY_WHITE`, | ||
`TURNPOLICY_LEFT`, | ||
`TURNPOLICY_RIGHT`, | ||
`TURNPOLICY_MINORITY`, | ||
`TURNPOLICY_MAJORITY`, | ||
// it also allow using actual policy values | ||
Potrace.TURNPOLICY_BLACK, | ||
Potrace.TURNPOLICY_WHITE, | ||
Potrace.TURNPOLICY_LEFT, | ||
Potrace.TURNPOLICY_RIGHT, | ||
Potrace.TURNPOLICY_MINORITY, | ||
Potrace.TURNPOLICY_MAJORITY |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 ways of setting it is covered by
gatsby/packages/gatsby-remark-images/src/index.js
Lines 264 to 271 in 70b81a6
// Translate Potrace constants (e.g. TURNPOLICY_LEFT, COLOR_AUTO) to the values Potrace expects | |
const { Potrace } = require(`potrace`) | |
const argsKeys = Object.keys(args) | |
args = argsKeys.reduce((result, key) => { | |
const value = args[key] | |
result[key] = Potrace.hasOwnProperty(value) ? Potrace[value] : value | |
return result | |
}, {}) |
color: Joi.string().default(`lightgray`), | ||
background: Joi.string().default(`transparent`), | ||
}) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Defaults and some of extra restrictions are coming from:
- defaults set by
gatsby-plugin-sharp
-gatsby/packages/gatsby-plugin-sharp/src/trace-svg.js
Lines 126 to 131 in 70b81a6
const defaultArgs = { color: `lightgray`, optTolerance: 0.4, turdSize: 100, turnPolicy: potrace.Potrace.TURNPOLICY_MAJORITY, } - defaults set by
node-potrace
- https://github.com/Iwasawafag/node-potrace/blob/b86608eaf3b9c5fea6d6b2034c762ea666e70ec6/lib/Potrace.js#L28-L38 - valid options / ranges from validation inside
node-potrace
- https://github.com/Iwasawafag/node-potrace/blob/b86608eaf3b9c5fea6d6b2034c762ea666e70ec6/lib/Potrace.js#L981-L997
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also - maybe it's safer to remove defaults, because it's not this plugin that set them. My main motivation to add those defaults is that maybe they are (or will be) displayed in some form - if they are not, then better remove them as they can get out of sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks reasonable to me :). What do you think of that @mxstbr ?
…ings (#28242) (#28552) * fix(gatsby-remark-images): allow tracedSVG to accept object with settings * fix test setup that was testing same thing twice (cherry picked from commit 23ecf2d) Co-authored-by: Michal Piechowiak <[email protected]>
Published in |
…ings (gatsbyjs#28242) * fix(gatsby-remark-images): allow tracedSVG to accept object with settings * fix test setup that was testing same thing twice
Description
Currently plugin validation schema only supports
true/false
, but plugin does support setting detailed settings with object notation too -gatsby/packages/gatsby-remark-images/src/index.js
Line 262 in 70b81a6
Related Issues
Fixes #28217