@@ -70,16 +70,29 @@ export default ((w) => {
70
70
// get available width from parent node
71
71
f . availableWidth = f . element . parentNode . clientWidth ;
72
72
73
- // the space our target element uses
73
+ // get available height from parent node
74
+ f . availableHeight = f . element . parentNode . clientHeight ;
75
+
76
+ // the width our target element uses
74
77
f . currentWidth = f . element . scrollWidth ;
75
78
79
+ // the height our target element uses
80
+ f . currentHeight = f . element . scrollHeight ;
81
+
76
82
// remember current font size
77
83
f . previousFontSize = f . currentFontSize ;
78
84
79
- // let's calculate the new font size
85
+ // let's calculate the new font size taking into account the width and
86
+ // the height
80
87
f . currentFontSize = Math . min (
81
- Math . max ( f . minSize , ( f . availableWidth / f . currentWidth ) * f . previousFontSize ) ,
82
- f . maxSize
88
+ Math . min (
89
+ Math . max ( f . minSize , ( f . availableWidth / f . currentWidth ) * f . previousFontSize ) ,
90
+ f . maxSize
91
+ ) ,
92
+ Math . min (
93
+ Math . max ( f . minSize , ( f . availableHeight / f . currentHeight ) * f . previousFontSize ) ,
94
+ f . maxSize
95
+ )
83
96
) ;
84
97
85
98
// if allows wrapping, only wrap when at minimum font size (otherwise would break container)
@@ -90,7 +103,8 @@ export default ((w) => {
90
103
const shouldRedraw = ( f ) =>
91
104
f . dirty !== DrawState . DIRTY_LAYOUT ||
92
105
( f . dirty === DrawState . DIRTY_LAYOUT &&
93
- f . element . parentNode . clientWidth !== f . availableWidth ) ;
106
+ ( f . element . parentNode . clientWidth !== f . availableWidth ||
107
+ f . element . parentNode . clientHeight !== f . availableHeight ) ) ;
94
108
95
109
// every fitty element is tested for invalid styles
96
110
const computeStyle = ( f ) => {
0 commit comments