{“version”:3,“file”:“retina.min.js”,“sources”:,“sourcesContent”:[“/* @flow */nn/**n * ————————————————————————–n * Retina.jsn * Licensed under MIT (github.com/strues/retinajs/blob/master/LICENSE)n *n * Retina.js is an open source script that makes it easy to serve high-resolutionn * images to devices with retina displays.n * ————————————————————————–n */nn/*n * Determine whether or not `window` is available.n */nconst hasWindow = typeof window !== 'undefined';nn/*n * Get the device pixel ratio per our environment.n * Default to 1.n */nconst environment = Math.round(hasWindow ? window.devicePixelRatio || 1 : 1);nn/*n * Define a pattern for capturing src url suffixes.n */nconst srcReplace = /(\.[A-z]{3,4}\/?(\?.*)?)$/;nconst inlineReplace = /url\((‘|")?(+)('|")?\)/i;nn/*n * Define our selectors for elements to target.n */nconst selector = '[data-rjs]';nn/*n * Define the attribute we'll use to mark an image as having been processed.n */nconst processedAttr = 'data-rjs-processed';nn/**n * Shortcut for turning some iterable object into an array.n *n * @param {Iterable} object Any iterable object.n *n * @return {Array}n */nfunction arrayify(object) {n return Array.prototype.slice.call(object);n}nn/**n * Chooses the actual image size to fetch, (for example 2 or 3) thatn * will be used to create a suffix like "" or "".n *n * @param {String|Number} cap The number the user provided indicating thatn * they have prepared images up to this size.n *n * @return {Number} The number we'll be using to create a suffix.n */nfunction chooseCap(cap) {n const numericCap = parseInt(cap, 10);nn /*n * If the environment's device pixel ratio is less than what the usern * provided, we'll only grab images at that size.n */n if (environment < numericCap) {n return environment;nn /*n * If the device pixel ratio is greater than or equal to what then * user provided, we'll use what the user provided.n */n } else {n return numericCap;n }n}nn/**n * Makes sure that, since we are going to swap out the source of an image,n * the image does not change size on the page.n *n * @param {Element} image An image element in the DOM.n *n * @return {Element} The same element that was passed in.n */nfunction forceOriginalDimensions(image) {n if (!image.hasAttribute('data-no-resize')) {n if (image.offsetWidth === 0 && image.offsetHeight === 0) {n image.setAttribute('width', image.naturalWidth);n image.setAttribute('height', image.naturalHeight);n } else {n image.setAttribute('width', image.offsetWidth);n image.setAttribute('height', image.offsetHeight);n }n }n return image;n}nn/**n * Determines whether the retina image actually exists on the server.n * If so, swaps out the retina image for the standard one. If not,n * leaves the original image alone.n *n * @param {Element} image An image element in the DOM.n * @param {String} newSrc The url to the retina image.n *n * @return {undefined}n */nfunction setSourceIfAvailable(image, retinaURL) {n const imgType = image.nodeName.toLowerCase();nn /*n * Create a new image element and give it a load listener. When then * load listener fires, it means the URL is correct and we will thenn * attach it to the user's image.n */n const testImage = document.createElement('img');n testImage.addEventListener('load', () => {n /*n * If we're dealing with an image tag, force it's dimensionsn * and set the source attribute. If not, go after the background-imagen * inline style.n */n if (imgType === 'img') {n forceOriginalDimensions(image).setAttribute('src', retinaURL);n } else {n image.style.backgroundImage = `url(${retinaURL})`;n }n });nn /*n * Attach the retina URL to our proxy image to load in the newn * image resource.n */n testImage.setAttribute('src', retinaURL);nn /*n * Mark our image as processed so that it won't be processed again.n */n image.setAttribute(processedAttr, true);n}nn/**n * Attempts to do an image url swap on a given image.n *n * @param {Element} image An image in the DOM.n * @param {String} src The original image source attribute.n * @param {String|Number} rjs The pixel density cap for images provided.n *n * @return {undefined}n */nfunction dynamicSwapImage(image, src, rjs = 1) {n const cap = chooseCap(rjs);nn /*n * Don't do anything if the cap is less than 2 or there is no src.n */n if (src && cap > 1) {n const newSrc = src.replace(srcReplace, `@${cap}x$1`);n setSourceIfAvailable(image, newSrc);n }n}nn/**n * Performs an image url swap on a given image with a provided url.n *n * @param {Element} image An image in the DOM.n * @param {String} src The original image source attribute.n * @param {String} hdsrc The path for a 2x image.n *n * @return {undefined}n */nfunction manualSwapImage(image, src, hdsrc) {n if (environment > 1) {n setSourceIfAvailable(image, hdsrc);n }n}nn/**n * Collects all images matching our selector, and converts ourn * NodeList into an Array so that Array methods will be available to it.n *n * @param {Iterable} images Optional. An Array, jQuery selection, or NodeListn * of elements to affect with retina.js.n *n * @return {Iterable} Contains all elements matching our selector.n */nfunction getImages(images) {n if (!images) {n return typeof document !== 'undefined' ? arrayify(document.querySelectorAll(selector)) : [];n } else {n return typeof images.forEach === 'function' ? images : arrayify(images);n }n}nn/**n * Converts a string like "url(hello.png)" into "hello.png".n *n * @param {Element} img An HTML element with a background image.n *n * @return {String}n */nfunction cleanBgImg(img) {n return img.style.backgroundImage.replace(inlineReplace, '$2');n}nn/**n * Gets all participating images and dynamically swaps out each one for itsn * retina equivalent taking into account the environment capabilities andn * the densities for which the user has provided images.n *n * @param {Iterable} images Optional. An Array, jQuery selection, or NodeListn * of elements to affect with retina.js. If notn * provided, retina.js will grab all images on then * page.n *n * @return {undefined}n */nfunction retina(images) {n getImages(images).forEach(img => {n if (!img.getAttribute(processedAttr)) {n const isImg = img.nodeName.toLowerCase() === 'img';n const src = isImg ? img.getAttribute('src') : cleanBgImg(img);n const rjs = img.getAttribute('data-rjs');n const rjsIsNumber = !isNaN(parseInt(rjs, 10));nn // do not try to load /null image!n if (rjs === null) {n return;n }nn /*n * If the user provided a number, dynamically swap out the image.n * If the user provided a url, do it manually.n */n if (rjsIsNumber) {n dynamicSwapImage(img, src, rjs);n } else {n manualSwapImage(img, src, rjs);n }n }n });n}nn/*n * If this environment has `window`, activate the plugin.n */nif (hasWindow) {n window.addEventListener('load', () => {n retina();n });n window.retinajs = retina;n}nnexport default retina;n”],“names”:,“mappings”:“qLA8CA,aAA0B,OACjBA,OAAMC,SAAND,CAAgBE,KAAhBF,CAAsBG,IAAtBH,IAYT,aAAwB,IAChBI,GAAaC,WAAc,EAAdA,EADG,MAOlBC,IAPkB,KA2BxB,aAAwC,OACjCC,GAAMC,YAAND,CAAmB,gBAAnBA,IACuB,CAAtBA,KAAME,WAANF,EAAkD,CAAvBA,KAAMG,gBAC7BC,aAAa,QAASJ,EAAMK,gBAC5BD,aAAa,SAAUJ,EAAMM,mBAE7BF,aAAa,QAASJ,EAAME,eAC5BE,aAAa,SAAUJ,EAAMG,kBAgBzC,eAAgD,IACxCI,GAAUP,EAAMQ,QAANR,CAAeS,WAAfT,GAOVU,EAAYC,SAASC,aAATD,CAAuB,KAAvBA,IACRE,iB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