import { IBreakpoint } from '../../../../../shared/models/IBreakpoint' ; import { IImageSize } from '../../../../../shared/models/IImageSize' ; import { IResponsiveImageData } from '../../../../../shared/models/IResponsiveImageData' ; import { BreakpointSize } from '../shared/enums/BreakpointSize' ; class Breakpoint implements IBreakpoint { screenSize : BreakpointSize ; imageSize : IImageSize ; pathToImage : string ; constructor ( screenSize , imageSize , pathToImage ) { this . screenSize = screenSize ; this . imageSize = imageSize ; this . pathToImage = pathToImage ; } } export default class ResponsiveImage implements IResponsiveImageData { breakpoints : IBreakpoint [ ] ; pathToImage : string ; param { string } pathToImage returns { ResponsiveImage } static create ( pathToImage = null ) { return new ResponsiveImage ( pathToImage ) ; } constructor ( pathToImage ) { this . breakpoints = [ ] ; this . pathToImage = pathToImage ; } private getBreakpointPath ( screenSize ) { const filename = this . pathToImage . split ( '/' ) . pop ( ) ; const directoryURI = this . pathToImage . substring ( 0 , this . pathToImage . length - filename . length ) ; const extension = filename . split ( '.' ) . pop ( ) ; const filenameWithoutExtension = filename . substring ( 0 , filename . length - extension . length - 1 ) ; return directoryURI + filename + '_' + screenSize + '.' + extension ; } param { BreakpointSize } screenSize param { IImageSize } imageSize returns { ResponsiveImage } breakpoint ( screenSize , imageSize ) { const breakpointPath = this . pathToImage ? this . getBreakpointPath ( screenSize ) : null ; this . breakpoints . push ( new Breakpoint ( screenSize , imageSize , breakpointPath ) ) ; return this ; } }