{"version":3,"sources":["webpack:///./src/Avensia.Common/Features/Shared/Image/index.tsx","webpack:///./src/Avensia.Common/Features/Shared/image-sizes.ts","webpack:///./src/Avensia.Common/Features/Shared/Image/noimage.svg"],"names":["Status","ImageTransition","_glitz_react__WEBPACK_IMPORTED_MODULE_2__","img","tslib__WEBPACK_IMPORTED_MODULE_0__","maxWidth","_Style__WEBPACK_IMPORTED_MODULE_6__","property","__webpack_exports__","Object","_super","Img","props","_this","call","this","src","checkIfCachedByBrowser","image","isCached","assumeCachedByBrowser","srcUrl","findBrowserCachedResource","state","status","Fulfilled","Pending","Rejected","prototype","componentWillMount","mounted","loadResource","componentWillReceiveProps","nextProps","preset","componentDidUpdate","prevProps","componentWillUnmount","originalSrc","promise","currentLoad","Promise","resolve","reject","Image","assign","onload","onerror","complete","naturalWidth","load","requestAnimationFrame","cached","width","browserCachedResources","height","naturalHeight","currentSrc","rememberBrowserCachedResource","_a","sent","setState","quality","url","_avensia_scope__WEBPACK_IMPORTED_MODULE_3__","searchParams","set","String","sizes","render","compose","pendingPreview","restProps","react__WEBPACK_IMPORTED_MODULE_1___default","a","createElement","innerRef","css","cache","_image_sizes__WEBPACK_IMPORTED_MODULE_4__","Thumb","opacity","_noimage_svg__WEBPACK_IMPORTED_MODULE_5___default","className","style","Component","test","pathname","Size","__webpack_require__","d","getSizes","Tiny","Small","Medium","Large","Huge","Gigantic","React","Noimage","key","stroke","strokeWidth","displayName","defaultProps","viewBox","preserveAspectRatio","module","exports","default"],"mappings":"8FAcKA,yEAPCC,EAAkBC,EAAA,EAAOC,IAAIC,EAAA,GACjCC,SAAU,QACPC,EAAA,IAAmBC,SAAU,eAKlC,SAAKP,GACHA,IAAA,qBACAA,IAAA,uBACAA,IAAA,yBAHF,CAAKA,WAgBUQ,EAAA,EAAAC,OAAAP,EAAA,GAAM,SAAAQ,GAMjB,SAAAC,EAAYC,GAAZ,IAAAC,EACEH,EAAAI,KAAAC,KAAMH,IAAMG,YAFdF,EAAAG,IAAqB,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sBAAAgF,IAAAC,EAAAC,EAAAlF,EAAA,sBAAAmF,IAAA,SAAYH,GACVA,IAAA,iBACAA,IAAA,eACAA,IAAA,iBACAA,IAAA,mBACAA,IAAA,iBACAA,IAAA,eACAA,IAAA,uBACAA,IAAA,uBARF,CAAYA,WAaL,IAAMG,EAAW,iBAAiB,OAAAhC,MACtC6B,EAAKR,OAAQ,GACdrB,EAAC6B,EAAKI,MAAO,IACbjC,EAAC6B,EAAKK,OAAQ,IACdlC,EAAC6B,EAAKM,QAAS,IACfnC,EAAC6B,EAAKO,OAAQ,KACdpC,EAAC6B,EAAKQ,MAAO,KACbrC,EAAC6B,EAAKS,UAAW,6BCpBnB,IAAAC,EAAYT,EAAQ,GAEpB,SAAAU,EAAAvF,GACA,OAAAsF,EAAAvB,cAAA,MAAA/D,GAAAsF,EAAAvB,cAAA,QAAwEtB,MAAA,OAAAE,OAAA,OAAA0B,QAAA,OAAAmB,IAAA,IAAwDF,EAAAvB,cAAA,QAA8Be,EAAA,2CAAAW,OAAA,OAAApB,QAAA,OAAAqB,YAAA,IAAAF,IAAA,MAG9JD,EAAAI,YAAA,UAEAJ,EAAAK,cAAwBC,QAAA,cAAAC,oBAAA,QAExBC,EAAAC,QAAAT,EAEAA,EAAAU,QAAAV","file":"assets/1.chunk.e26a458e119754c46ea4.js","sourcesContent":["import React from 'react';\r\nimport { styled, StyledProps } from '@glitz/react';\r\nimport { URLX, relativeUrl } from '@avensia/scope';\r\nimport { getSizes, Size as Preset } from '../image-sizes';\r\nimport NoImage from './noimage.svg';\r\nimport * as style from '../Style';\r\n\r\nconst ImageTransition = styled.img({\r\n maxWidth: '100%',\r\n ...style.transition({ property: 'opacity' }),\r\n});\r\n\r\nexport { Size as Preset } from '../image-sizes';\r\n\r\nenum Status {\r\n Pending,\r\n Rejected,\r\n Fulfilled,\r\n}\r\n\r\ntype PropType = StyledProps &\r\n React.ImgHTMLAttributes & {\r\n preset?: Preset;\r\n pendingPreview?: boolean;\r\n };\r\n\r\ntype StateType = {\r\n status?: Status;\r\n};\r\n\r\nexport default styled(\r\n class Img extends React.Component {\r\n mounted: boolean;\r\n isCached: boolean;\r\n currentLoad: Promise;\r\n src: string | null = null;\r\n constructor(props: PropType) {\r\n super(props);\r\n this.src = this.srcUrl();\r\n\r\n this.isCached = !!props.src && !!findBrowserCachedResource(this.src);\r\n this.state = {\r\n status: props.src ? (this.isCached ? Status.Fulfilled : Status.Pending) : Status.Rejected,\r\n };\r\n }\r\n componentWillMount() {\r\n this.mounted = true;\r\n\r\n if (!this.isCached && this.src) {\r\n this.loadResource(this.src);\r\n }\r\n }\r\n componentWillReceiveProps(nextProps: PropType) {\r\n if (this.props.src !== nextProps.src || this.props.preset !== nextProps.preset) {\r\n if (this.props.src !== nextProps.src) {\r\n this.src = this.srcUrl(nextProps.src, nextProps.preset);\r\n }\r\n\r\n if (this.src) {\r\n this.loadResource(this.src);\r\n }\r\n }\r\n }\r\n componentDidUpdate(prevProps: PropType) {\r\n if (!this.props.src) {\r\n this.status(Status.Rejected);\r\n } else if (this.props.src !== prevProps.src || this.props.preset !== prevProps.preset) {\r\n if (!this.isCached) {\r\n this.status(Status.Pending);\r\n }\r\n }\r\n }\r\n componentWillUnmount() {\r\n this.mounted = false;\r\n }\r\n async loadResource(src: string) {\r\n const originalSrc = this.props.src;\r\n const promise = (this.currentLoad = load(src));\r\n\r\n try {\r\n const image = await promise;\r\n rememberBrowserCachedResource(image, originalSrc);\r\n if (this.mounted && this.currentLoad === promise) {\r\n this.status(Status.Fulfilled);\r\n }\r\n } catch (e) {\r\n if (this.mounted && this.currentLoad === promise) {\r\n this.status(Status.Rejected);\r\n }\r\n }\r\n }\r\n status(status: Status) {\r\n if (this.state.status !== status) {\r\n this.setState({ status });\r\n }\r\n }\r\n srcUrl(src = this.props.src, preset = this.props.preset, quality?: number): string {\r\n if (src) {\r\n const url = new URLX(src);\r\n\r\n if (typeof preset === 'number') {\r\n url.searchParams.set('w', String(sizes[preset]));\r\n url.searchParams.set('h', String(sizes[preset]));\r\n url.searchParams.set('mode', 'max');\r\n }\r\n\r\n if (quality) {\r\n url.searchParams.set('quality', String(quality));\r\n }\r\n\r\n return relativeUrl(url);\r\n }\r\n\r\n return null;\r\n }\r\n checkIfCachedByBrowser = (image: HTMLImageElement) => (this.isCached = assumeCachedByBrowser(image));\r\n render() {\r\n if (this.src) {\r\n const { status } = this.state;\r\n\r\n const { compose, preset, pendingPreview, ...restProps } = this.props;\r\n\r\n if (status === Status.Fulfilled) {\r\n return (\r\n \r\n );\r\n }\r\n\r\n if (this.src) {\r\n const cache = findBrowserCachedResource(this.props.src);\r\n\r\n if (cache) {\r\n return (\r\n \r\n );\r\n }\r\n\r\n if (status === Status.Pending) {\r\n return pendingPreview ? (\r\n \r\n ) : (\r\n \r\n );\r\n }\r\n }\r\n }\r\n\r\n return ;\r\n }\r\n },\r\n);\r\n\r\nfunction load(src: string) {\r\n return new Promise((resolve, reject) => {\r\n const image = new Image();\r\n Object.assign(image, {\r\n onload: () => resolve(image),\r\n onerror: () => reject(),\r\n src,\r\n });\r\n\r\n if (image.complete) {\r\n if (image.naturalWidth > 0) {\r\n resolve(image);\r\n } else {\r\n reject();\r\n }\r\n }\r\n });\r\n}\r\n\r\nconst sizes = getSizes();\r\n\r\ntype ResourceType = {\r\n width: number;\r\n height: number;\r\n src: string;\r\n};\r\n\r\nconst browserCachedResources: { [src: string]: ResourceType } = {};\r\n\r\nfunction findBrowserCachedResource(originalSrc: string) {\r\n return browserCachedResources[originalSrc];\r\n}\r\n\r\nfunction rememberBrowserCachedResource(image: HTMLImageElement, originalSrc: string) {\r\n // Firefox has an ugly tendency to report naturalWidth as 0 when a SW is active.\r\n // But if we wait just a little bit, the sizes have been calculated. Broken\r\n // images should be uncommon, so we can afford the setTimeout here\r\n requestAnimationFrame(() => {\r\n if (image && assumeCachedByBrowser(image)) {\r\n const cached = findBrowserCachedResource(originalSrc);\r\n if (!cached || image.naturalWidth > cached.width) {\r\n browserCachedResources[originalSrc] = {\r\n width: image.naturalWidth,\r\n height: image.naturalHeight,\r\n src: image.currentSrc,\r\n };\r\n }\r\n }\r\n });\r\n}\r\n\r\nfunction assumeCachedByBrowser(image: HTMLImageElement) {\r\n if (!image) {\r\n return false;\r\n }\r\n const url = new URLX(image.src);\r\n\r\n // Firefox and IE has a bug where svg reports 0 for natural size in some cases\r\n if (/\\.svg/.test(url.pathname)) {\r\n return false;\r\n }\r\n return image.complete && image.naturalWidth > 0;\r\n}\r\n","export enum Size {\r\n Thumb,\r\n Tiny,\r\n Small,\r\n Medium,\r\n Large,\r\n Huge,\r\n Gigantic,\r\n Original,\r\n}\r\n\r\ntype SizesType = { [key: number]: number };\r\n\r\nexport const getSizes = (): SizesType => ({\r\n [Size.Thumb]: 60,\r\n [Size.Tiny]: 320,\r\n [Size.Small]: 640,\r\n [Size.Medium]: 960,\r\n [Size.Large]: 1280,\r\n [Size.Huge]: 1920,\r\n [Size.Gigantic]: 3200,\r\n});\r\n\r\nexport function getPresetFromWidth(estimatedWidth: number, availableSizes: SizesType): Size {\r\n return parseInt(Object.keys(availableSizes).find(sizeKey => availableSizes[sizeKey] >= estimatedWidth), 10);\r\n}\r\n","var React = require('react');\n\nfunction Noimage (props) {\n return React.createElement(\"svg\",props,[React.createElement(\"rect\",{\"width\":\"100%\",\"height\":\"100%\",\"opacity\":\".075\",\"key\":0}),React.createElement(\"path\",{\"d\":\"M.497 479.54L479.497.5m-479 0l479 479.04\",\"stroke\":\"#fff\",\"opacity\":\".175\",\"strokeWidth\":\"5\",\"key\":1})]);\n}\n\nNoimage.displayName = \"Noimage\";\n\nNoimage.defaultProps = {\"viewBox\":\"0 0 480 480\",\"preserveAspectRatio\":\"none\"};\n\nmodule.exports = Noimage;\n\nNoimage.default = Noimage;\n"],"sourceRoot":""}