Skip to content

Commit 62fa353

Browse files
committed
Apply changes rikschennink#69
1 parent e251efe commit 62fa353

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

src/fitty.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,44 @@ export default ((w) => {
7070
// get available width from parent node
7171
f.availableWidth = f.element.parentNode.clientWidth;
7272

73-
// the space our target element uses
73+
74+
// get available height from parent node
75+
f.availableHeight = f.element.parentNode.clientHeight;
76+
77+
// the width our target element uses
7478
f.currentWidth = f.element.scrollWidth;
7579

80+
// the height our target element uses
81+
f.currentHeight = f.element.scrollHeight;
82+
7683
// remember current font size
7784
f.previousFontSize = f.currentFontSize;
7885

7986
// let's calculate the new font size
8087
f.currentFontSize = Math.min(
81-
Math.max(f.minSize, (f.availableWidth / f.currentWidth) * f.previousFontSize),
88+
Math.min(
89+
Math.max(
90+
f.minSize,
91+
(f.availableWidth / f.currentWidth) * f.previousFontSize
92+
),
93+
f.maxSize
94+
),
95+
Math.min(
96+
Math.max(
97+
f.minSize,
98+
(f.availableHeight / f.currentHeight) * f.previousFontSize
99+
),
82100
f.maxSize
101+
)
83102
);
84103

85104
// if allows wrapping, only wrap when at minimum font size (otherwise would break container)
86105
f.whiteSpace = f.multiLine && f.currentFontSize === f.minSize ? 'normal' : 'nowrap';
87106
};
88107

89108
// should always redraw if is not dirty layout, if is dirty layout, only redraw if size has changed
90-
const shouldRedraw = (f) =>
91-
f.dirty !== DrawState.DIRTY_LAYOUT ||
92-
(f.dirty === DrawState.DIRTY_LAYOUT &&
93-
f.element.parentNode.clientWidth !== f.availableWidth);
109+
const shouldRedraw = f => f.dirty !== DrawState.DIRTY_LAYOUT || (f.dirty === DrawState.DIRTY_LAYOUT && (f.element.parentNode.clientWidth !== f.availableWidth || f.element.parentNode.clientHeight !== f.availableHeight)); // every fitty element is tested for invalid styles
94110

95-
// every fitty element is tested for invalid styles
96111
const computeStyle = (f) => {
97112
// get style properties
98113
const style = w.getComputedStyle(f.element, null);

0 commit comments

Comments
 (0)