@@ -62,35 +62,43 @@ const BVIconBase = {
6262 ...commonIconProps
6363 } ,
6464 render ( h , { data, props } ) {
65- const fontScale = toFloat ( props . fontScale ) || 1
66- const scale = toFloat ( props . scale ) || 1
65+ const fontScale = Math . max ( toFloat ( props . fontScale ) || 1 , 0 ) || 1
66+ const scale = Math . max ( toFloat ( props . scale ) || 1 , 0 ) || 1
6767 const rotate = toFloat ( props . rotate ) || 0
6868 const shiftH = toFloat ( props . shiftH ) || 0
6969 const shiftV = toFloat ( props . shiftV ) || 0
7070 const flipH = props . flipH
7171 const flipV = props . flipV
72- // Compute the transforms. Note that order is important
73- // CSS transforms are applied in order from right to left
74- // and we want flipping to occur before rotation, and
75- // shifting is applied last
72+ // Compute the transforms. Note that order is important as
73+ // SVG transforms are applied in order from left to right
74+ // and we want flipping/scale to occur before rotation.
75+ // Note shifting is applied separately. Assumes that the
76+ // viewbox is `0 0 20 20` (`10 10` is the center)
77+ const hasScale = flipH || flipV || scale !== 1
78+ const hasTransforms = hasScale || rotate
79+ const hasShift = shiftH || shiftV
7680 const transforms = [
77- shiftH ? `translateX(${ ( 100 * shiftH ) / 16 } %)` : null ,
78- shiftV ? `translateY(${ ( - 100 * shiftV ) / 16 } %)` : null ,
79- rotate ? `rotate(${ rotate } deg)` : null ,
80- flipH || flipV || scale !== 1
81- ? `scale(${ ( flipH ? - 1 : 1 ) * scale } , ${ ( flipV ? - 1 : 1 ) * scale } )`
82- : null
81+ hasTransforms ? 'translate(10 10)' : null ,
82+ hasScale ? `scale(${ ( flipH ? - 1 : 1 ) * scale } ${ ( flipV ? - 1 : 1 ) * scale } )` : null ,
83+ rotate ? `rotate(${ rotate } )` : null ,
84+ hasTransforms ? 'translate(-10 -10)' : null
8385 ] . filter ( identity )
8486
85- // We wrap the content in a `<g>` for handling the transforms
86- const $inner = h ( 'g' , {
87- style : {
88- transform : transforms . join ( ' ' ) || null ,
89- transformOrigin : transforms . length > 0 ? 'center' : null
90- } ,
87+ // We wrap the content in a `<g>` for handling the transforms (except shift)
88+ let $inner = h ( 'g' , {
89+ attrs : { transform : transforms . join ( ' ' ) || null } ,
9190 domProps : { innerHTML : props . content || '' }
9291 } )
9392
93+ // If needed, we wrap in an additional `<g>` in order to handle the shifting
94+ if ( hasShift ) {
95+ $inner = h (
96+ 'g' ,
97+ { attrs : { transform : `translate(${ ( 20 * shiftH ) / 16 } ${ ( - 20 * shiftV ) / 16 } )` } } ,
98+ [ $inner ]
99+ )
100+ }
101+
94102 return h (
95103 'svg' ,
96104 mergeData (
0 commit comments