File size: 723 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const PAGE_MARGIN_LARGE = 32 * 2;
const PAGE_MARGIN_MEDIUM = 24 * 2;
const PAGE_MARGIN_SMALL = 10 * 2;
const SIDEBAR_WIDTH = 240;
const MAX_CONTENT_WIDTH = 720;

/**
 * Returns the available content width in full post for the reader at the current viewport width
 */
export default function contentWidth() {
	if ( typeof document === 'undefined' ) {
		return undefined;
	}

	const clientWidth = document.documentElement.clientWidth;
	if ( clientWidth > 1040 ) {
		return MAX_CONTENT_WIDTH;
	}
	if ( clientWidth > 928 ) {
		return clientWidth - ( SIDEBAR_WIDTH + PAGE_MARGIN_LARGE );
	}
	if ( clientWidth > 660 ) {
		return clientWidth - ( SIDEBAR_WIDTH + PAGE_MARGIN_MEDIUM );
	}
	return clientWidth - PAGE_MARGIN_SMALL;
}