@@ -31,8 +31,6 @@ function useDimensions<T extends HTMLElement>(
3131
3232 useLayoutEffect ( ( ) => {
3333 if ( ref . current ) {
34- const rect = ref . current . getBoundingClientRect ( )
35-
3634 const pll = ref . current . querySelector (
3735 ".prev-longest-line"
3836 )
@@ -50,8 +48,8 @@ function useDimensions<T extends HTMLElement>(
5048 ? plw ! / ( pll . textContent ?. length || 1 )
5149 : nlw ! / ( nll ! . textContent ?. length || 1 )
5250 setDimensions ( {
53- width : rect . width ,
54- height : rect . height ,
51+ width : getWidthWithoutPadding ( ref . current ) ,
52+ height : getHeightWithoutPadding ( ref . current ) ,
5553 lineWidths : [
5654 plw || nlw || DEFAULT_WIDTH ,
5755 nlw || plw || DEFAULT_WIDTH ,
@@ -73,6 +71,23 @@ function useDimensions<T extends HTMLElement>(
7371 }
7472}
7573
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+
7691function depsChanged (
7792 oldDeps : React . DependencyList ,
7893 newDeps : React . DependencyList
0 commit comments