{“version”:3,“file”:“retina.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”:“AAeA,MAAM,SAAS,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC;AAMhD,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,gBAAgB,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAK7E,MAAM,UAAU,GAAG,2BAA2B,CAAC;AAC/C,MAAM,aAAa,GAAG,+BAA+B,CAAC;AAKtD,MAAM,QAAQ,GAAG,YAAY,CAAC;AAK9B,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAS3C,SAAS,QAAQ,CAAC,MAAM,EAAE;EACxB,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;CAC3C;AAWD,SAAS,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