import { isPresent , notNull } from 'polar-shared/src/Preconditions' ; import { PHZMetadata } from '../../phz/PHZMetadata' ; import { Logger } from 'polar-shared/src/logger/Logger' ; import { ScrollBox } from 'polar-content-capture/src/capture/Captured' ; import { Optional } from 'polar-shared/src/util/ts/Optional' ; import { Reducers } from 'polar-shared/src/util/Reducers' ; import { IDimensions } from "../../util/IDimensions" ; const log = Logger . create ( ) ; export class Descriptors { public static calculateDocDimensions ( descriptor ? ) { let width = 800 ; let minHeight = 1100 ; if ( ! descriptor ) { return { width , minHeight } ; } if ( descriptor . browser ) { width = descriptor . browser . deviceEmulation . screenSize . width ; log . info ( "Setting width from device emulation: " + width ) ; } const scrollBox = this . computeScrollBox ( descriptor ) ; if ( scrollBox . isPresent ( ) && scrollBox . get ( ) . width > width ) { if ( ! isPresent ( scrollBox . get ( ) . widthOverflow ) || scrollBox . get ( ) . widthOverflow === 'visible' ) { width = scrollBox . get ( ) . width ; } log . info ( "Setting width from scroll settings: " + width ) ; } minHeight = ( 11 / 8.5 ) * width ; return { width , minHeight } ; } public static computeScrollBox ( descriptor ) { return this . computeScrollBoxFromBoxes ( descriptor . scrollBox , descriptor . scroll ) ; } public static computeScrollBoxFromBoxes ( scrollBox ? , scroll ? ) { return [ Optional . of ( scrollBox ) , Optional . of ( scroll ) ] . filter ( current => current . isPresent ( ) ) . filter ( current => current . map ( scrollBox => this . isScrollBox ( scrollBox ) ) . getOrElse ( false ) ) . reduce ( Reducers . FIRST , Optional . empty ( ) ) ; } public static isScrollBox ( scrollBox ) { return typeof scrollBox . width === 'number' && typeof scrollBox . height === 'number' ; } } export interface DocDimensions { width : number ; minHeight : number ; }