@@ -62,35 +62,43 @@ const BVIconBase = {
62
62
...commonIconProps
63
63
} ,
64
64
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
67
67
const rotate = toFloat ( props . rotate ) || 0
68
68
const shiftH = toFloat ( props . shiftH ) || 0
69
69
const shiftV = toFloat ( props . shiftV ) || 0
70
70
const flipH = props . flipH
71
71
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
76
80
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
83
85
] . filter ( identity )
84
86
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 } ,
91
90
domProps : { innerHTML : props . content || '' }
92
91
} )
93
92
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
+
94
102
return h (
95
103
'svg' ,
96
104
mergeData (
0 commit comments