File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,7 +63,14 @@ const LinearGradient = ( {
6363const NOOP = ( ) => { }
6464
6565const getSvgDef = ( href , viewBox = '0 0 24 24' ) => {
66- return `<svg viewBox="${ viewBox } "><use href="${ href } " xlink:href="${ href } "></use></svg>`
66+ const viewBoxValues = viewBox . trim ( ) . split ( / [ \s , ] + / )
67+ // The symbol keeps its original origin to map its paths, while the wrapper
68+ // starts at zero so the <use> instance remains inside the visible viewport.
69+ const normalizedViewBox = viewBoxValues . length === 4 && viewBoxValues . every ( value => Number . isFinite ( Number ( value ) ) )
70+ ? `0 0 ${ viewBoxValues [ 2 ] } ${ viewBoxValues [ 3 ] } `
71+ : viewBox
72+
73+ return `<svg viewBox="${ normalizedViewBox } "><use href="${ href } " xlink:href="${ href } "></use></svg>`
6774}
6875
6976const generateIconId = ( ) => {
@@ -457,4 +464,3 @@ Icon.InspectorControls = Edit
457464Icon . addAttributes = addAttributes
458465
459466Icon . addStyles = addStyles
460-
Original file line number Diff line number Diff line change @@ -72,10 +72,15 @@ const parseSVGString = svgString => {
7272 while ( ( attrMatch = attrRegex . exec ( attributesPart ) ) !== null ) {
7373 const key = attrMatch [ 1 ]
7474 const attrNameLower = key . toLowerCase ( )
75+ const value = attrMatch [ 2 ] || attrMatch [ 3 ] || attrMatch [ 4 ] || ''
7576 // Skip width and height as symbols don't need them
76- if ( attrNameLower !== 'width' && attrNameLower !== 'height' && ! attrNameLower . startsWith ( 'on' ) ) {
77- // Value can be in double quotes, single quotes, or unquoted
78- const value = attrMatch [ 2 ] || attrMatch [ 3 ] || attrMatch [ 4 ] || ''
77+ // Skip explicit fills so each <use> instance can inherit its block's icon color.
78+ // Preserve fill="none" because it is structural for stroke-based icons.
79+ if ( attrNameLower !== 'width' &&
80+ attrNameLower !== 'height' &&
81+ ! attrNameLower . startsWith ( 'on' ) &&
82+ ( attrNameLower !== 'fill' || value . trim ( ) . toLowerCase ( ) === 'none' )
83+ ) {
7984 svgAttributes [ key ] = value
8085 }
8186 }
You can’t perform that action at this time.
0 commit comments