@@ -31,8 +31,6 @@ function useDimensions<T extends HTMLElement>(
31
31
32
32
useLayoutEffect ( ( ) => {
33
33
if ( ref . current ) {
34
- const rect = ref . current . getBoundingClientRect ( )
35
-
36
34
const pll = ref . current . querySelector (
37
35
".prev-longest-line"
38
36
)
@@ -50,8 +48,8 @@ function useDimensions<T extends HTMLElement>(
50
48
? plw ! / ( pll . textContent ?. length || 1 )
51
49
: nlw ! / ( nll ! . textContent ?. length || 1 )
52
50
setDimensions ( {
53
- width : rect . width ,
54
- height : rect . height ,
51
+ width : getWidthWithoutPadding ( ref . current ) ,
52
+ height : getHeightWithoutPadding ( ref . current ) ,
55
53
lineWidths : [
56
54
plw || nlw || DEFAULT_WIDTH ,
57
55
nlw || plw || DEFAULT_WIDTH ,
@@ -73,6 +71,23 @@ function useDimensions<T extends HTMLElement>(
73
71
}
74
72
}
75
73
74
+ function getWidthWithoutPadding ( element : HTMLElement ) {
75
+ const computedStyle = getComputedStyle ( element )
76
+ return (
77
+ element . clientWidth -
78
+ parseFloat ( computedStyle . paddingLeft ) -
79
+ parseFloat ( computedStyle . paddingRight )
80
+ )
81
+ }
82
+ function getHeightWithoutPadding ( element : HTMLElement ) {
83
+ const computedStyle = getComputedStyle ( element )
84
+ return (
85
+ element . clientHeight -
86
+ parseFloat ( computedStyle . paddingTop ) -
87
+ parseFloat ( computedStyle . paddingBottom )
88
+ )
89
+ }
90
+
76
91
function depsChanged (
77
92
oldDeps : React . DependencyList ,
78
93
newDeps : React . DependencyList
0 commit comments