tethysfaceid
Version:
1 lines • 12 kB
JSON
{"ast":null,"code":"\"use strict\";\n\nvar _interopRequireDefault = require(\"@babel/runtime/helpers/interopRequireDefault\");\n\nexports.__esModule = true;\nexports.default = Image;\n\nvar _objectWithoutPropertiesLoose2 = _interopRequireDefault(require(\"@babel/runtime/helpers/objectWithoutPropertiesLoose\"));\n\nvar _extends2 = _interopRequireDefault(require(\"@babel/runtime/helpers/extends\"));\n\nvar _react = _interopRequireDefault(require(\"react\"));\n\nvar _toBase = require(\"../next-server/lib/to-base-64\");\n\nvar _imageConfig = require(\"../next-server/server/image-config\");\n\nvar _useIntersection = require(\"./use-intersection\");\n\nif (true) {\n ;\n global.__NEXT_IMAGE_IMPORTED = true;\n}\n\nconst VALID_LOADING_VALUES = ['lazy', 'eager', undefined];\nconst loaders = new Map([['imgix', imgixLoader], ['cloudinary', cloudinaryLoader], ['akamai', akamaiLoader], ['default', defaultLoader]]);\nconst VALID_LAYOUT_VALUES = ['fill', 'fixed', 'intrinsic', 'responsive', undefined];\nconst {\n deviceSizes: configDeviceSizes,\n imageSizes: configImageSizes,\n loader: configLoader,\n path: configPath,\n domains: configDomains\n} = process.env.__NEXT_IMAGE_OPTS || _imageConfig.imageConfigDefault; // sort smallest to largest\n\nconst allSizes = [...configDeviceSizes, ...configImageSizes];\nconfigDeviceSizes.sort((a, b) => a - b);\nallSizes.sort((a, b) => a - b);\n\nfunction getWidths(width, layout) {\n if (typeof width !== 'number' || layout === 'fill' || layout === 'responsive') {\n return {\n widths: configDeviceSizes,\n kind: 'w'\n };\n }\n\n const widths = [...new Set([width, width * 2, width * 3].map(w => allSizes.find(p => p >= w) || allSizes[allSizes.length - 1]))];\n return {\n widths,\n kind: 'x'\n };\n}\n\nfunction callLoader(loaderProps) {\n const load = loaders.get(configLoader);\n\n if (load) {\n return load((0, _extends2.default)({\n root: configPath\n }, loaderProps));\n }\n\n throw new Error(`Unknown \"loader\" found in \"next.config.js\". Expected: ${_imageConfig.VALID_LOADERS.join(', ')}. Received: ${configLoader}`);\n}\n\nfunction generateImgAttrs({\n src,\n unoptimized,\n layout,\n width,\n quality,\n sizes\n}) {\n if (unoptimized) {\n return {\n src\n };\n }\n\n const {\n widths,\n kind\n } = getWidths(width, layout);\n const last = widths.length - 1;\n const srcSet = widths.map((w, i) => `${callLoader({\n src,\n quality,\n width: w\n })} ${kind === 'w' ? w : i + 1}${kind}`).join(', ');\n\n if (!sizes && kind === 'w') {\n sizes = widths.map((w, i) => i === last ? `${w}px` : `(max-width: ${w}px) ${w}px`).join(', ');\n }\n\n src = callLoader({\n src,\n quality,\n width: widths[last]\n });\n return {\n src,\n sizes,\n srcSet\n };\n}\n\nfunction getInt(x) {\n if (typeof x === 'number') {\n return x;\n }\n\n if (typeof x === 'string') {\n return parseInt(x, 10);\n }\n\n return undefined;\n}\n\nfunction Image(_ref) {\n let {\n src,\n sizes,\n unoptimized = false,\n priority = false,\n loading,\n className,\n quality,\n width,\n height,\n objectFit,\n objectPosition\n } = _ref,\n all = (0, _objectWithoutPropertiesLoose2.default)(_ref, [\"src\", \"sizes\", \"unoptimized\", \"priority\", \"loading\", \"className\", \"quality\", \"width\", \"height\", \"objectFit\", \"objectPosition\"]);\n let rest = all;\n let layout = sizes ? 'responsive' : 'intrinsic';\n let unsized = false;\n\n if ('unsized' in rest) {\n unsized = Boolean(rest.unsized); // Remove property so it's not spread into image:\n\n delete rest['unsized'];\n } else if ('layout' in rest) {\n // Override default layout if the user specified one:\n if (rest.layout) layout = rest.layout; // Remove property so it's not spread into image:\n\n delete rest['layout'];\n }\n\n if (false) {\n if (!src) {\n throw new Error(`Image is missing required \"src\" property. Make sure you pass \"src\" in props to the \\`next/image\\` component. Received: ${JSON.stringify({\n width,\n height,\n quality\n })}`);\n }\n\n if (!VALID_LAYOUT_VALUES.includes(layout)) {\n throw new Error(`Image with src \"${src}\" has invalid \"layout\" property. Provided \"${layout}\" should be one of ${VALID_LAYOUT_VALUES.map(String).join(',')}.`);\n }\n\n if (!VALID_LOADING_VALUES.includes(loading)) {\n throw new Error(`Image with src \"${src}\" has invalid \"loading\" property. Provided \"${loading}\" should be one of ${VALID_LOADING_VALUES.map(String).join(',')}.`);\n }\n\n if (priority && loading === 'lazy') {\n throw new Error(`Image with src \"${src}\" has both \"priority\" and \"loading='lazy'\" properties. Only one should be used.`);\n }\n\n if (unsized) {\n throw new Error(`Image with src \"${src}\" has deprecated \"unsized\" property, which was removed in favor of the \"layout='fill'\" property`);\n }\n }\n\n let isLazy = !priority && (loading === 'lazy' || typeof loading === 'undefined');\n\n if (src && src.startsWith('data:')) {\n // https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs\n unoptimized = true;\n isLazy = false;\n }\n\n const [setRef, isIntersected] = (0, _useIntersection.useIntersection)({\n rootMargin: '200px',\n disabled: !isLazy\n });\n const isVisible = !isLazy || isIntersected;\n const widthInt = getInt(width);\n const heightInt = getInt(height);\n const qualityInt = getInt(quality);\n let wrapperStyle;\n let sizerStyle;\n let sizerSvg;\n let imgStyle = {\n visibility: isVisible ? 'visible' : 'hidden',\n position: 'absolute',\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n boxSizing: 'border-box',\n padding: 0,\n border: 'none',\n margin: 'auto',\n display: 'block',\n width: 0,\n height: 0,\n minWidth: '100%',\n maxWidth: '100%',\n minHeight: '100%',\n maxHeight: '100%',\n objectFit,\n objectPosition\n };\n\n if (typeof widthInt !== 'undefined' && typeof heightInt !== 'undefined' && layout !== 'fill') {\n // <Image src=\"i.png\" width=\"100\" height=\"100\" />\n const quotient = heightInt / widthInt;\n const paddingTop = isNaN(quotient) ? '100%' : `${quotient * 100}%`;\n\n if (layout === 'responsive') {\n // <Image src=\"i.png\" width=\"100\" height=\"100\" layout=\"responsive\" />\n wrapperStyle = {\n display: 'block',\n overflow: 'hidden',\n position: 'relative',\n boxSizing: 'border-box',\n margin: 0\n };\n sizerStyle = {\n display: 'block',\n boxSizing: 'border-box',\n paddingTop\n };\n } else if (layout === 'intrinsic') {\n // <Image src=\"i.png\" width=\"100\" height=\"100\" layout=\"intrinsic\" />\n wrapperStyle = {\n display: 'inline-block',\n maxWidth: '100%',\n overflow: 'hidden',\n position: 'relative',\n boxSizing: 'border-box',\n margin: 0\n };\n sizerStyle = {\n boxSizing: 'border-box',\n display: 'block',\n maxWidth: '100%'\n };\n sizerSvg = `<svg width=\"${widthInt}\" height=\"${heightInt}\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"/>`;\n } else if (layout === 'fixed') {\n // <Image src=\"i.png\" width=\"100\" height=\"100\" layout=\"fixed\" />\n wrapperStyle = {\n overflow: 'hidden',\n boxSizing: 'border-box',\n display: 'inline-block',\n position: 'relative',\n width: widthInt,\n height: heightInt\n };\n }\n } else if (typeof widthInt === 'undefined' && typeof heightInt === 'undefined' && layout === 'fill') {\n // <Image src=\"i.png\" layout=\"fill\" />\n wrapperStyle = {\n display: 'block',\n overflow: 'hidden',\n position: 'absolute',\n top: 0,\n left: 0,\n bottom: 0,\n right: 0,\n boxSizing: 'border-box',\n margin: 0\n };\n } else {\n // <Image src=\"i.png\" />\n if (false) {\n throw new Error(`Image with src \"${src}\" must use \"width\" and \"height\" properties or \"layout='fill'\" property.`);\n }\n }\n\n let imgAttributes = {\n src: 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'\n };\n\n if (isVisible) {\n imgAttributes = generateImgAttrs({\n src,\n unoptimized,\n layout,\n width: widthInt,\n quality: qualityInt,\n sizes\n });\n }\n\n if (unsized) {\n wrapperStyle = undefined;\n sizerStyle = undefined;\n imgStyle = undefined;\n }\n\n return /*#__PURE__*/_react.default.createElement(\"div\", {\n style: wrapperStyle\n }, sizerStyle ? /*#__PURE__*/_react.default.createElement(\"div\", {\n style: sizerStyle\n }, sizerSvg ? /*#__PURE__*/_react.default.createElement(\"img\", {\n style: {\n maxWidth: '100%',\n display: 'block'\n },\n alt: \"\",\n \"aria-hidden\": true,\n role: \"presentation\",\n src: `data:image/svg+xml;base64,${(0, _toBase.toBase64)(sizerSvg)}`\n }) : null) : null, /*#__PURE__*/_react.default.createElement(\"img\", Object.assign({}, rest, imgAttributes, {\n decoding: \"async\",\n className: className,\n ref: setRef,\n style: imgStyle\n })));\n} //BUILT IN LOADERS\n\n\nfunction normalizeSrc(src) {\n return src[0] === '/' ? src.slice(1) : src;\n}\n\nfunction imgixLoader({\n root,\n src,\n width,\n quality\n}) {\n // Demo: https://static.imgix.net/daisy.png?format=auto&fit=max&w=300\n const params = ['auto=format', 'fit=max', 'w=' + width];\n let paramsString = '';\n\n if (quality) {\n params.push('q=' + quality);\n }\n\n if (params.length) {\n paramsString = '?' + params.join('&');\n }\n\n return `${root}${normalizeSrc(src)}${paramsString}`;\n}\n\nfunction akamaiLoader({\n root,\n src,\n width\n}) {\n return `${root}${normalizeSrc(src)}?imwidth=${width}`;\n}\n\nfunction cloudinaryLoader({\n root,\n src,\n width,\n quality\n}) {\n // Demo: https://res.cloudinary.com/demo/image/upload/w_300,c_limit/turtles.jpg\n const params = ['f_auto', 'c_limit', 'w_' + width];\n let paramsString = '';\n\n if (quality) {\n params.push('q_' + quality);\n }\n\n if (params.length) {\n paramsString = params.join(',') + '/';\n }\n\n return `${root}${paramsString}${normalizeSrc(src)}`;\n}\n\nfunction defaultLoader({\n root,\n src,\n width,\n quality\n}) {\n if (false) {\n const missingValues = []; // these should always be provided but make sure they are\n\n if (!src) missingValues.push('src');\n if (!width) missingValues.push('width');\n\n if (missingValues.length > 0) {\n throw new Error(`Next Image Optimization requires ${missingValues.join(', ')} to be provided. Make sure you pass them as props to the \\`next/image\\` component. Received: ${JSON.stringify({\n src,\n width,\n quality\n })}`);\n }\n\n if (src.startsWith('//')) {\n throw new Error(`Failed to parse src \"${src}\" on \\`next/image\\`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)`);\n }\n\n if (!src.startsWith('/') && configDomains) {\n let parsedSrc;\n\n try {\n parsedSrc = new URL(src);\n } catch (err) {\n console.error(err);\n throw new Error(`Failed to parse src \"${src}\" on \\`next/image\\`, if using relative image it must start with a leading slash \"/\" or be an absolute URL (http:// or https://)`);\n }\n\n if (!configDomains.includes(parsedSrc.hostname)) {\n throw new Error(`Invalid src prop (${src}) on \\`next/image\\`, hostname \"${parsedSrc.hostname}\" is not configured under images in your \\`next.config.js\\`\\n` + `See more info: https://err.sh/next.js/next-image-unconfigured-host`);\n }\n }\n }\n\n return `${root}?url=${encodeURIComponent(src)}&w=${width}&q=${quality || 75}`;\n}","map":null,"metadata":{},"sourceType":"script"}