@@ -19,15 +19,13 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
1919 const [ height , setHeight ] = useState ( 0 )
2020 const [ width , setWidth ] = useState ( 0 )
2121 const [ radius , setRadius ] = useState ( array ( 4 , 0 ) )
22+ const [ boxSizing , setBoxSizing ] = useState ( 'content-box' )
2223
2324 const [ transition , setTransition ] = useState ( array ( 4 , 0 ) )
2425
2526 const [ background , setBackground ] = useState ( { } )
2627 const [ border , setBorder ] = useState ( { width : array ( 4 , 0 ) } )
2728 const [ borderImage , setBorderImage ] = useState ( { } )
28- // const [borderColor, setBorderColor] = useState(array(4, 'transparent'))
29- // const [borderOpacity, setBorderOpacity] = useState(array(4, 0))
30- // const [borderWidth, setBorderWidth] = useState(array(4, 0))
3129 const [ shadows , setShadows ] = useState ( array ( 2 , [ ] ) )
3230
3331 const [ path , setPath ] = useState ( 'Z' )
@@ -39,6 +37,7 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
3937 updateStates ( {
4038 div,
4139 style,
40+ setBoxSizing,
4241 setPadding,
4342 setHeight,
4443 setWidth,
@@ -77,27 +76,34 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
7776 ) . join ( ',' )
7877 ) )
7978 setPath ( generateSvgSquircle ( height , width , radius ) )
80- } , [ height , width , radius , border . width ] )
79+ } , [ height , width , radius , border , padding ] )
8180
8281 useEffect ( ( ) => {
82+ const currentSvgRef = svgRef . current
8383 // patch for webkit's svg bug
84- if ( svgRef . current )
84+ if ( currentSvgRef )
8585 setTimeout ( ( ) => {
86- const oldPosition = svgRef . current . style . position || ''
87- svgRef . current . style . display = 'none'
88- svgRef . current . style . position = 'absolute'
86+ const oldPosition = currentSvgRef . style . position || ''
87+ currentSvgRef . style . display = 'none'
88+ currentSvgRef . style . position = 'absolute'
8989 setTimeout ( ( ) => {
90- svgRef . current . style . display = ''
91- svgRef . current . style . position = oldPosition
90+ currentSvgRef . style . display = ''
91+ currentSvgRef . style . position = oldPosition
9292 } , 10 )
9393 } , 0 )
9494 } , [ radius , border , borderImage ] )
9595
96- const pathIsEmpty = ( path . startsWith ( 'Z' ) || path === '' )
96+ const invisibleBorderStyles = {
97+ borderWidth : border . width . map ( v => v + 'px' ) . join ( ' ' ) ,
98+ borderStyle : 'solid' ,
99+ borderColor : 'transparent' ,
100+ }
101+
102+ const pathIsEmpty = path . startsWith ( 'Z' ) || path === ''
97103 const divStyle = {
98104 ...style ,
99105 ...( pathIsEmpty ? { } : {
100- border : 'none' ,
106+ ... invisibleBorderStyles ,
101107 borderImage : 'none' ,
102108 background : 'transparent' ,
103109 boxShadow : dontConvertShadow
@@ -110,8 +116,11 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
110116 }
111117
112118 const shapeComponentStyles = {
119+ // height: boxSizing === 'border-box' ? height : height - (border.width[0] + padding[0] + border.width[2] + padding[2]),
120+ // width: boxSizing === 'border-box' ? width : width - (border.width[1] + padding[1] + border.width[3] + padding[3]),
113121 height,
114122 width,
123+ padding : padding . map ( n => n + 'px' ) . join ( ' ' ) ,
115124 position : 'fixed' ,
116125 left : 0 ,
117126 top : 0 ,
@@ -121,13 +130,14 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
121130
122131 const widenedBorderWidth = border . width . map ( v => v + Math . max ( .5 , v * .1 ) )
123132
124- return < div { ...props } style = { divStyle } ref = { div } >
133+ return < div { ...props } style = { divStyle } ref = { div } data-rrd-overwritten = { pathIsEmpty ? 'false' : 'true' } >
125134 { pathIsEmpty ? null : < ShadowRoot >
126135 < div style = { {
127136 transform : 'scale(1)'
128137 } } >
129138 < div style = { {
130139 ...shapeComponentStyles ,
140+ ...invisibleBorderStyles ,
131141 clipPath : `path("${ path } ")` ,
132142 // inset shadow only
133143 boxShadow : shadows [ 1 ] . join ( ',' ) ,
@@ -139,11 +149,14 @@ export default function RoundDiv({style, children, dontConvertShadow, ...props})
139149 } } />
140150 < div style = { {
141151 ...shapeComponentStyles ,
152+ ...invisibleBorderStyles ,
142153 clipPath : `path("${ path } ")`
143154 } } >
144155 < div style = { {
145- height : height - ( widenedBorderWidth [ 0 ] + widenedBorderWidth [ 2 ] ) ,
146- width : width - ( widenedBorderWidth [ 1 ] + widenedBorderWidth [ 3 ] ) ,
156+ height,
157+ width,
158+ // boxSizing: 'border-box',
159+ transform : `translate(-${ border . width [ 3 ] } px, -${ border . width [ 0 ] } px)` ,
147160 clipPath : `path("M0,0V${ height } H${ width } V0Z${ innerPath } ")` ,
148161 borderRadius : radius . map ( n => ( n - 1 ) + 'px' ) . join ( ' ' ) ,
149162 borderColor : border . color ,
0 commit comments