File size: 1,743 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { DEFAULT_VIEWPORT_WIDTH, MOBILE_VIEWPORT_WIDTH } from '../constants';
import type { Design } from '../types';
import type { MShotsOptions } from '@automattic/onboarding';

type MShotInputOptions = {
	scrollable?: boolean;
	highRes?: boolean;
	isMobile?: boolean;
	oldHighResImageLoading?: boolean; // Temporary for A/B test.
};

// Used for both prefetching and loading design screenshots
export const getMShotOptions = ( {
	scrollable,
	highRes,
	isMobile,
	oldHighResImageLoading,
}: MShotInputOptions = {} ): MShotsOptions => {
	// Take care changing these values, as the design-picker CSS animations are written for these values (see the *__landscape and *__portrait classes)

	// These settings are arbitrary. Switching from the previous settings (1199x3600) to these settings reduces page weight from 70 MB to ~5 MB,
	// These settings are intended to, at best, be temporary. A long-term solution for this should probably have values determined by A/B tests,
	// end up serving WEBPs instead of JPEGs, spend fewer bits on parts of images that are not displayed, and possibly display fewer images.
	//
	// See #88786 for more info.
	let w = 500;
	let screen_height = 1100;
	if ( oldHighResImageLoading ) {
		w = highRes ? 1199 : 600;
		screen_height = 3600;
	}
	return {
		vpw: isMobile ? MOBILE_VIEWPORT_WIDTH : DEFAULT_VIEWPORT_WIDTH,
		vph: scrollable ? 1600 : 1040,
		w: w,
		screen_height: screen_height,
		oldHighResImageLoading: oldHighResImageLoading,
	};
};

export function isBlankCanvasDesign( design?: Design ): boolean {
	if ( ! design ) {
		return false;
	}
	return /blank-canvas/i.test( design.slug ) && ! design.is_virtual;
}

export const getDesignSlug = ( design: Design ) => design.recipe?.slug || design.slug;