import { SizeMode } from '../core/models' ; export interface Layoutable { width ? : number ; height ? : number ; frameWidth ? : number ; frameHeight ? : number ; target : any ; sizeMode ? : SizeMode ; } export interface Layout { [ key ] : any ; width : string | number ; height : string | number ; top : number ; left : number ; bottom : number ; right : number ; position : 'absolute' ; overflow : 'hidden' ; } export interface SizeWithAspect { width : number ; height : number ; aspect : number ; } /**
 *
 */ export function getOuterSize ( data ) { const width = Math . floor ( data . width || data . frameWidth || data . target . innerWidth ( ) ) ; const height = Math . floor ( data . height || data . frameHeight || data . target . innerHeight ( ) ) ; return { aspect : width / height , height , width } ; } export function getComputedSize ( data ) { const size = getOuterSize ( data ) ; if ( typeof window . getComputedStyle !== 'function' ) { return size ; } const style = window . getComputedStyle ( data . target [ 0 ] ) ; if ( ! style . width ) { return size ; } size . width = Math . floor ( Number ( style . width . replace ( 'px' , '' ) ) ) ; size . height = Math . floor ( size . width / size . aspect ) ; return size ; } /**
 *
 */ export function getInnerSize ( data ) { const width = Math . floor ( data . frameWidth || data . width || data . target . innerWidth ( ) ) ; const height = Math . floor ( data . frameHeight || data . height || data . target . innerHeight ( ) ) ; return { aspect : width / height , height , width } ; } /**
 *
 */ export function getInnerLayout ( mode , inner , outer ) { const isFit = mode === 'fit' ; const isFill = mode === 'fill' ; const isMatch = mode === 'stretch' ; const layout = { width : '100%' , height : '100%' , top : 0 , left : 0 , bottom : 0 , right : 0 , position : 'absolute' , overflow : 'hidden' } ; if ( ! mode || isMatch ) { return layout ; } const aspectIsGreater = inner . aspect >= outer . aspect ; let width = inner . width ; let height = inner . height ; if ( isFit && aspectIsGreater || isFill && ! aspectIsGreater ) { width = outer . width ; height = outer . width / inner . aspect ; } if ( isFill && aspectIsGreater || isFit && ! aspectIsGreater ) { height = outer . height ; width = outer . height * inner . aspect ; } width = Math . floor ( width ) ; height = Math . floor ( height ) ; layout . width = width ; layout . height = height ; layout . top = Math . floor ( ( outer . height - height ) / 2 ) ; layout . left = Math . floor ( ( outer . width - width ) / 2 ) ; layout . right = layout . left ; layout . bottom = layout . top ; return layout ; }