Skip to content

Icons: Add a script that normalizes design-tool SVG exports - #85272

Closed
jasmussen wants to merge 5 commits into
trunkfrom
add/icon-normalize-script
Closed

jasmussen wants to merge 5 commits into
trunkfrom
add/icon-normalize-script

Conversation

@jasmussen

Copy link
Copy Markdown
Contributor

What?

Related to #81274.

Design tools export an icon with their own defaults: a width/height pair, a literal fill="none", and the artboard's color on every shape. The library hoists that paint onto the root so an icon inherits currentColor, and validate-collection rejects exports that keep the editor's defaults.

Add npm run normalize-export to make that translation, and document it as a step in the README. It refuses anything it cannot translate faithfully -- a dashed stroke, an inline style, a stroke width other than 1.5 -- because silently dropping one changes the drawing while leaving a file that builds. Running it on an already normalized file is a no-op; --check reports what would change without writing.

Why?

Honestly because this very script helped me redraw 300+ icons to be stroke-based.

Testing Instructions

Export a new SVG drawn in Figma, run this script on it, and see if it passes.

Use of AI Tools

Claude Opus 5.

Design tools export an icon with their own defaults: a width/height pair, a literal fill="none", and the artboard's color on every shape. The library hoists that paint onto the root so an icon inherits currentColor, and validate-collection rejects exports that keep the editor's defaults.

Add `npm run normalize-export` to make that translation, and document it as a step in the README. It refuses anything it cannot translate faithfully -- a dashed stroke, an inline style, a stroke width other than 1.5 -- because silently dropping one changes the drawing while leaving a file that builds. Running it on an already normalized file is a no-op; --check reports what would change without writing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@jasmussen
jasmussen requested a review from a team October 21, 2026 10:31
@jasmussen jasmussen self-assigned this Oct 21, 2026
@jasmussen jasmussen added the [Type] Enhancement A suggestion for improvement. label Oct 21, 2026
@github-actions github-actions Bot added the [Package] Icons /packages/icons label Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jasmussen <joen@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: 0 B

Total Size: 8.64 MB

5353f91 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric fe3b4c0 trunk % Change
timeToFirstByte 42.8 ms +13.2% -4.21% 42.85 ms +10.62% -2.68% -0.12%
largestContentfulPaint 68 ms +5.88% -0% 68 ms +14.71% -5.88% 0%
lcpMinusTtfb 25.5 ms +4.51% -6.67% 24.35 ms +20.53% -8.42% 4.72%
wpBeforeTemplate 22.13 ms +19.52% -2.03% 22.35 ms +9.35% -3.53% -0.98%
wpTemplate 17.2 ms +6.57% -6.4% 16.98 ms +5.59% -1.94% 1.3%
wpTotal 39.45 ms +13.76% -4.28% 39.32 ms +11.8% -2.57% 0.33%
wpMemoryUsage 7.72 MB +0% -0% 7.68 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric fe3b4c0 trunk % Change
timeToFirstByte 37.1 ms +10.11% -2.96% 35.6 ms +5.76% -3.79% 4.21%
largestContentfulPaint 68 ms +5.88% -5.88% 64 ms +6.25% -6.25% 6.25%
lcpMinusTtfb 30.2 ms +3.48% -5.3% 28.95 ms +4.84% -9.15% 4.32%
wpBeforeTemplate 20.04 ms +6.24% -3.09% 19.08 ms +17.24% -0.89% 5.03%
wpTemplate 13.88 ms +1.66% -4.18% 12.73 ms +4.71% -2.59% 9.03%
wpTotal 34.05 ms +11.01% -2.76% 32.91 ms +6.26% -3.98% 3.46%
wpMemoryUsage 6.41 MB +0% -0% 6.37 MB +0% -0% 0.53%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric fe3b4c0 trunk % Change
mediaProcessingJpeg 328.32 ms +0.41% -0.66% 323.94 ms +1.56% -0.07% 1.35%
mediaProcessingAvif 4876.12 ms +1.08% -0.03% 4869.77 ms +0.27% -0.14% 0.13%
mediaProcessingJpegToAvif 3409.59 ms +0.37% -0.22% 3396.85 ms +0.45% -0.45% 0.38%

media-upload

Metric fe3b4c0 trunk % Change
jpegUploadProcessing 1479.19 ms +1.73% -1.01% 1447.47 ms +1.59% -0.7% 2.19%
pngUploadProcessing 254.61 ms +4.06% -2.37% 238.81 ms +8.84% -4.84% 6.62%
largeJpegUploadProcessing 1442.56 ms +0.61% -0.22% 1440.72 ms +0.44% -0.4% 0.13%
multipleImageUploadProcessing 1568.72 ms +2.24% -3.37% 1512.55 ms +1.77% -0.73% 3.71%

post-editor

Metric fe3b4c0 trunk % Change
serverResponse 479.46 ms +4.53% -6.11% 485.73 ms +1.53% -3.21% -1.29%
firstPaint 465.6 ms +9.27% -9.45% 419.22 ms +6.56% -7.01% 11.06%
domContentLoaded 867.99 ms +2.22% -1.91% 817.95 ms +0.82% -1.13% 6.12%
loaded 869.18 ms +2.22% -1.89% 819.1 ms +0.83% -1.16% 6.11%
firstContentfulPaint 496.88 ms +2.39% -5.54% 461.24 ms +1.11% -2.17% 7.73%
firstBlock 2320.55 ms +6.93% -1.36% 2188.94 ms +0.26% -2.25% 6.01%
type 19.87 ms +9.66% -12.43% 17.4 ms +2.7% -12.01% 14.2%
typeWithoutInspector 19.71 ms +6.49% -12.73% 16.73 ms +6.99% -13.15% 17.81%
typeWithTopToolbar 25.28 ms +7.08% -1.31% 23.22 ms +10.12% -5.73% 8.87%
typeContainer 9.45 ms +5.5% -10.37% 7.96 ms +8.29% -2.89% 18.72%
focus 128.48 ms +7.76% -3.42% 123.11 ms +7.63% -8.9% 4.36%
firstFocus 292.38 ms +0% -0% 262.02 ms +0% -0% 11.59%
selectAll 464.25 ms +1.18% -8.17% 420.34 ms +1.71% -3.92% 10.45%
undo 31.1 ms +9.16% -4.79% 29.53 ms +3.56% -8.6% 5.32%
listViewOpen 84.07 ms +7.02% -2.32% 80.7 ms +2.73% -16.47% 4.18%
inserterOpen 44.1 ms +18.91% -6.8% 42.83 ms +1.87% -7.87% 2.97%
inserterHover 12.28 ms +12.46% -10.26% 11.04 ms +7.7% -8.79% 11.23%
inserterSearch 8 ms +8% -7.87% 7.73 ms +10.87% -7.89% 3.49%
loadPatterns 667.45 ms +5.91% -1.74% 650.78 ms +1.36% -4.25% 2.56%
wpTotal 469.68 ms +4.59% -6.21% 476.1 ms +1.54% -3.26% -1.35%
wpMemoryUsage 14.77 MB +0% -0% 14.74 MB +0% -0% 0.24%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric fe3b4c0 trunk % Change
serverResponse 325.37 ms +2.76% -9.79% 321.51 ms +1.11% -10.44% 1.2%
firstPaint 383.43 ms +8.62% -13.82% 362.1 ms +16.13% -8.96% 5.89%
domContentLoaded 668.19 ms +5.95% -0.3% 696.46 ms +1.25% -5.51% -4.06%
loaded 669.01 ms +5.96% -0.29% 697.36 ms +1.24% -5.49% -4.07%
firstContentfulPaint 383.43 ms +8.62% -2.23% 389.61 ms +7.93% -4.35% -1.59%
firstBlock 2095.71 ms +1.25% -1.76% 2078.82 ms +0.69% -2.04% 0.81%
type 15.14 ms +5.28% -5.02% 17.39 ms +10.81% -14.84% -12.94%
navigate 91.99 ms +4.44% -6.48% 95.23 ms +4.37% -2.51% -3.4%
loadPatterns 1117.11 ms +12.31% -16.64% 1258.82 ms +1.13% -9.83% -11.26%
loadPages 951.07 ms +4.95% -4.55% 930.14 ms +3.92% -2.15% 2.25%
wpTotal 317.01 ms +2.66% -10.06% 313.03 ms +1.04% -10.73% 1.27%
wpMemoryUsage 12.79 MB +0% -0% 12.75 MB +0% -0% 0.27%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

5353f91 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

a navigation superseded by the traversal discharges to idle in /test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts, passed after 1 failed attempt.
SyntaxError: Unexpected token 'o', "not hydrated" is not valid JSON
    at readLog (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:28:14)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:47:24
    at waitForLogLength (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:46:2)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/interactivity/router-navigation-lifecycle.spec.ts:693:5

5353f91 Run

@jasmussen

Copy link
Copy Markdown
Contributor Author

I use this script constantly. Mind a review? @WordPress/gutenberg-design

@t-hamano

Copy link
Copy Markdown
Contributor

Sorry for the late reply. What do you think about running this script automatically on commit, e.g. via lint-staged? That way, even if a contributor forgets to run it, invalid icons are much less likely to slip into a PR. If you like the idea, I'd be happy to push it to this PR.

@jasmussen

Copy link
Copy Markdown
Contributor Author

I think that's a great idea, and you are most welcome to push any changes you like—or just create a new PR and I'll close this one in favour of yours.

I want to note due to the age of this PR, we should just double-check that what it outputs is still what we want. In my testing it is, it puts the correct currentColor values and props on the SVG, so I'm just noting that is one part that needs a fresh review.

Thank you!

t-hamano and others added 3 commits November 11, 2026 09:25
Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwrK9Tye4Yh48WoaqB
Run normalize-export through lint-staged before the icons build, so an
export a contributor forgets to normalize is rewritten at commit time,
and one the script cannot translate stops the commit.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwrK9Tye4Yh48WoaqB
The script also runs on committed icons, not only fresh design-tool
exports, and the new name matches the verb-target naming of the other
scripts in lib/.

Co-authored-by: t-hamano <54422211+t-hamano@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011g9URwrK9Tye4Yh48WoaqB
@t-hamano

Copy link
Copy Markdown
Contributor

Since the changes are likely to be quite extensive, I am continuing the work in #86657.

@jasmussen

Copy link
Copy Markdown
Contributor Author

Thank you. I'm closing this in favour of #86657.

@jasmussen jasmussen closed this Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Icons /packages/icons [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants