diff --git a/dist/index.js b/dist/index.js index df71bdb..904c28c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,2 +1,2 @@ -var t=/^\/\/a.storyblok.com\/f\/[0-9]+\/[0-9]+x[0-9]+\/[A-Za-z0-9]+\/[\S]+\.[a-z]+/;function e(e){var a=null,n=null;if("string"==typeof e&&(a=e),"object"==typeof e&&(a=e.image,n=e.base64?e.base64:null),!(a=t.test(a)?a:null))return!1;var i=a.replace("//a.storyblok.com/",""),r=i.split("/"),s=r[4],o=r[2].split("x").map(function(t){return parseInt(t,10)}),u=o[0],l=o[1];return{originalPath:i,extension:s.split(".")[1],metadata:{dimensions:{width:u,height:l,aspectRatio:u/l},lqip:n}}}var a="https://img2.storyblok.com",n=[1,1.5,2,3],i=[.25,.5,1,1.5,2,3],r={quality:100,smartCrop:!0,format:null,fill:null,toFormat:null,base64:null,useBase64:!0},s=Object.assign({},r,{maxWidth:800,maxHeight:null}),o=Object.assign({},r,{width:400,height:null});function u(t){var e=t.includes("filters:format(webp)"),a=/[a-f0-9]+-\d+x\d+\.webp/.test(t);return e||a}function l(t,e){var n=e.width,i=e.height,r=e.smartCrop,s=e.quality,o=e.format,u=e.fill,l=t.split("."),h=a;n&&i&&(h+="/"+n+"x"+i),r&&(h+="/smart");var c=[s&&"quality("+s+")",o&&o!==l[1]&&"format("+o+")",u&&"fill("+u+")"];return(c=c.filter(function(t){return!0===Boolean(t)})).length>0&&(h+=function(t){return t.reduce(function(t,e,a){return t+":"+e},"/filters")}(c)),h+"/"+t}exports.getFixedGatsbyImage=function(t,a){void 0===a&&(a={});var i=e(t);if(!i)return null;var r=Object.assign({},o,a),s=r.width,h=r.height,c=r.base64,b=r.useBase64,p=i.metadata,f=p.dimensions,m=p.lqip,g=i.originalPath,d=f.aspectRatio;r.height&&(d=s/r.height);var w=null;r.toFormat?w=r.toFormat:u(g)&&(w="jpg");var j=n.map(function(t){return Math.round(s*t)}).filter(function(t){return t0&&(h+=function(t){return t.reduce(function(t,e,a){return t+":"+e},"/filters")}(c)),h+"/"+t}exports.getFixedGatsbyImage=function(t,a){void 0===a&&(a={});var i=e(t);if(!i)return null;var r=Object.assign({},o,a),s=r.width,h=r.height,c=r.base64,p=r.useBase64,b=i.metadata,f=b.dimensions,m=b.lqip,g=i.originalPath,d=f.aspectRatio;r.height&&(d=s/r.height);var w=null;r.toFormat?w=r.toFormat:u(g)&&(w="jpg");var j=n.map(function(t){return Math.round(s*t)}).filter(function(t){return t parseInt(num, 10))\n let [, extension] = filename.split('.')\n\n let aspectRatio = width / height\n let metadata = { dimensions: { width, height, aspectRatio }, lqip }\n\n return {\n originalPath,\n extension,\n metadata\n }\n}\n\nexport default getBasicImageProps\n","export const DEFAULT_FIXED_WIDTH = 400\nexport const DEFAULT_FLUID_MAX_WIDTH = 800\nexport const STORYBLOK_BASE_URL = 'https://img2.storyblok.com'\n\nexport const sizeMultipliersFixed = [1, 1.5, 2, 3]\nexport const sizeMultipliersFluid = [0.25, 0.5, 1, 1.5, 2, 3]\n\nexport const defaultOptions = {\n quality: 100,\n smartCrop: true,\n format: null,\n fill: null,\n toFormat: null,\n base64: null,\n useBase64: true\n}\n\nexport const defaultFluidOptions = {\n ...defaultOptions,\n maxWidth: DEFAULT_FLUID_MAX_WIDTH,\n maxHeight: null\n}\n\nexport const defaultFixedOptions = {\n ...defaultOptions,\n width: DEFAULT_FIXED_WIDTH,\n height: null\n}\n","export function applyFilters(filters) {\n return filters.reduce((acc, currentFilter, i) => {\n return `${acc}:${currentFilter}`\n }, '/filters')\n}\n\nexport function isWebP(url) {\n const isConverted = url.includes('filters:format(webp)')\n const isOriginal = /[a-f0-9]+-\\d+x\\d+\\.webp/.test(url)\n return isConverted || isOriginal\n}\n","import { STORYBLOK_BASE_URL } from '../defaults'\nimport { applyFilters } from './helpers'\n\nfunction buildImageUrl(originalPath, image) {\n let { width, height, smartCrop, quality, format, fill } = image\n\n let [, extension] = originalPath.split('.')\n\n let url = STORYBLOK_BASE_URL\n\n if (width && height) {\n url += `/${width}x${height}`\n }\n\n if (smartCrop) {\n url += `/smart`\n }\n\n let filters = [\n ...[quality && `quality(${quality})`],\n ...[format && format !== extension && `format(${format})`],\n ...[fill && `fill(${fill})`]\n ]\n\n // remove falsy elements\n filters = filters.filter(element => Boolean(element) === true)\n\n if (filters.length > 0) {\n url += applyFilters(filters)\n }\n\n // add original path at the end\n url += `/${originalPath}`\n\n return url\n}\n\nexport default buildImageUrl\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFixed, defaultFixedOptions } from './defaults'\n\nfunction getFixedGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFixedOptions,\n ...args\n }\n\n let { width, height, base64, useBase64 } = options\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.height) {\n desiredAspectRatio = width / options.height\n }\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let widths = sizeMultipliersFixed.map(scale => Math.round(width * scale))\n let initial = { webp: [], base: [] }\n\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth, i) => {\n let resolution = `${sizeMultipliersFixed[i]}x`\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n ...options,\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...size,\n ...(forceConvert && { format: forceConvert })\n })\n\n acc.webp.push(`${webpUrl} ${resolution}`)\n acc.base.push(`${baseUrl} ${resolution}`)\n\n return acc\n }, initial)\n\n let outputHeight = Math.round(height ? height : width / desiredAspectRatio)\n\n let imgSize = {\n ...options,\n width: width,\n height: outputHeight\n }\n\n let src = buildUrl(originalPath, {\n ...imgSize,\n ...(forceConvert && { format: forceConvert })\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n // base64String\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n width: Math.round(width),\n height: outputHeight,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null\n }\n}\n\nexport default getFixedGatsbyImage\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFluid, defaultFluidOptions } from './defaults'\n\nfunction getFluidGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFluidOptions,\n ...args\n }\n\n let { maxWidth, base64, useBase64 } = options\n\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.maxHeight) {\n desiredAspectRatio = maxWidth / options.maxHeight\n }\n\n let maxHeight = options.maxHeight || Math.round(maxWidth / dimensions.aspectRatio)\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let sizes = options.sizes || `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`\n let widths = sizeMultipliersFluid\n .map(scale => Math.round(maxWidth * scale))\n .filter(width => width < dimensions.width)\n .concat(dimensions.width)\n\n let initial = { webp: [], base: [] }\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth) => {\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: forceConvert }\n })\n\n acc.webp.push(`${webpUrl} ${currentWidth}w`)\n acc.base.push(`${baseUrl} ${currentWidth}w`)\n return acc\n }, initial)\n\n let imgSize = { width: maxWidth, height: maxHeight }\n\n let src = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: forceConvert }\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null,\n sizes\n }\n}\n\nexport default getFluidGatsbyImage\n"],"names":["const","validImageUrlPattern","getBasicImageProps","image","url","lqip","base64","test","originalPath","replace","split","map","num","parseInt","filename","dimensions","width","height","STORYBLOK_BASE_URL","sizeMultipliersFixed","sizeMultipliersFluid","defaultOptions","quality","smartCrop","format","fill","toFormat","useBase64","defaultFluidOptions","Object","maxWidth","maxHeight","defaultFixedOptions","isWebP","isConverted","includes","isOriginal","buildImageUrl","filters","filter","element","Boolean","length","reduce","acc","currentFilter","i","applyFilters","args","imageProps","options","desiredAspectRatio","aspectRatio","forceConvert","srcSets","scale","Math","round","currentWidth","resolution","currentHeight","size","webpUrl","buildUrl","baseUrl","webp","push","base","outputHeight","imgSize","src","srcWebp","srcSet","join","srcSetWebp","sizes","concat"],"mappings":"AAAAA,IAAMC,EAAuB,8EAE7B,SAASC,EAAmBC,OACtBC,EAAM,KACNC,EAAO,QAEU,iBAAVF,IACTC,EAAMD,GAGa,iBAAVA,IACTC,EAAMD,EAAMA,MACZE,EAAOF,EAAMG,OAASH,EAAMG,OAAS,QAGvCF,EAAMH,EAAqBM,KAAKH,GAAOA,EAAM,aAGpC,MAGLI,EAAeJ,EAAIK,QAAQ,qBAA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EAAeH,EAAQxB,SACdO,EAAOzB,KAChB6C,EAAe,WAGbsB,EAAQzB,EAAQyB,sBAAwB7C,gBAAsBA,OAO9DwB,EANSlC,EACVT,aAAI4C,UAASC,KAAKC,MAAM3B,EAAWyB,KACnChB,gBAAOvB,UAASA,EAAQD,EAAWC,QACnC4D,OAAO7D,EAAWC,OAIlBuB,gBAAOmB,UAAgBA,EAAe3C,EAAWC,QACjD2B,gBAAQC,EAAKc,OAGRG,EAAO,CACT7C,MAAO0C,EACPzC,OAJkBuC,KAAKC,MAAMC,EAAeP,IAO1CW,EAAUC,EAASvD,EAAcqB,iBAChCqB,EACAW,GACErC,OAAQ,UAGXwC,EAAUD,EAASvD,EAAcqB,iBAChCqB,EACAW,GACErC,OAAQ6B,YAGfT,EAAIqB,KAAKC,KAAQJ,MAAWJ,OAC5Bd,EAAIuB,KAAKD,KAAQF,MAAWN,OACrBd,GAzBG,CAAEqB,KAAM,GAAIE,KAAM,KA4B5BE,EAAU,CAAErD,MAAOc,EAAUb,OAAQc,GAErCuC,EAAMP,EAASvD,EAAcqB,iBAC5BqB,EACAmB,GACE7C,OAAQ6B,KAGXkB,EAAUR,EAASvD,EAAcqB,iBAChCqB,EACAmB,GACE7C,OAAQ,gBAGR,CACLlB,OAAQqB,EAAYrB,GAAUD,EAAO,KACrC+C,YAAaD,MACbmB,UACAC,EACAC,OAAQlB,EAAQa,KAAKM,KAAK,QAAU,KACpCC,WAAYpB,EAAQW,KAAKQ,KAAK,QAAU,WACxCE"} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../src/utils/getBasicImageProps.js","../src/defaults.js","../src/utils/helpers.js","../src/utils/buildImageUrl.js","../src/getFixedGatsbyImage.js","../src/getFluidGatsbyImage.js"],"sourcesContent":["const validImageUrlPattern = /^(https?:)?\\/\\/a.storyblok.com\\/f\\/[0-9]+\\/[0-9]+x[0-9]+\\/[A-Za-z0-9]+\\/[\\S]+\\.[a-z]+/\n\nfunction getBasicImageProps(image) {\n let url = null\n let lqip = null\n\n if (typeof image === 'string') {\n url = image\n }\n\n if (typeof image === 'object') {\n url = image.image\n lqip = image.base64 ? image.base64 : null\n }\n\n url = validImageUrlPattern.test(url) ? url : null\n\n if (!url) {\n return false\n }\n\n const storyblokRegex = /^(https?:)?\\/\\/a.storyblok.com\\//\n let originalPath = url.replace(storyblokRegex, '')\n\n let [, , dimensions, , filename] = originalPath.split('/')\n let [width, height] = dimensions.split('x').map(num => parseInt(num, 10))\n let [, extension] = filename.split('.')\n\n let aspectRatio = width / height\n let metadata = { dimensions: { width, height, aspectRatio }, lqip }\n\n return {\n originalPath,\n extension,\n metadata\n }\n}\n\nexport default getBasicImageProps\n","export const DEFAULT_FIXED_WIDTH = 400\nexport const DEFAULT_FLUID_MAX_WIDTH = 800\nexport const STORYBLOK_BASE_URL = 'https://img2.storyblok.com'\n\nexport const sizeMultipliersFixed = [1, 1.5, 2, 3]\nexport const sizeMultipliersFluid = [0.25, 0.5, 1, 1.5, 2, 3]\n\nexport const defaultOptions = {\n quality: 100,\n smartCrop: true,\n format: null,\n fill: null,\n toFormat: null,\n base64: null,\n useBase64: true\n}\n\nexport const defaultFluidOptions = {\n ...defaultOptions,\n maxWidth: DEFAULT_FLUID_MAX_WIDTH,\n maxHeight: null\n}\n\nexport const defaultFixedOptions = {\n ...defaultOptions,\n width: DEFAULT_FIXED_WIDTH,\n height: null\n}\n","export function applyFilters(filters) {\n return filters.reduce((acc, currentFilter, i) => {\n return `${acc}:${currentFilter}`\n }, '/filters')\n}\n\nexport function isWebP(url) {\n const isConverted = url.includes('filters:format(webp)')\n const isOriginal = /[a-f0-9]+-\\d+x\\d+\\.webp/.test(url)\n return isConverted || isOriginal\n}\n","import { STORYBLOK_BASE_URL } from '../defaults'\nimport { applyFilters } from './helpers'\n\nfunction buildImageUrl(originalPath, image) {\n let { width, height, smartCrop, quality, format, fill } = image\n\n let [, extension] = originalPath.split('.')\n\n let url = STORYBLOK_BASE_URL\n\n if (width && height) {\n url += `/${width}x${height}`\n }\n\n if (smartCrop) {\n url += `/smart`\n }\n\n let filters = [\n ...[quality && `quality(${quality})`],\n ...[format && format !== extension && `format(${format})`],\n ...[fill && `fill(${fill})`]\n ]\n\n // remove falsy elements\n filters = filters.filter(element => Boolean(element) === true)\n\n if (filters.length > 0) {\n url += applyFilters(filters)\n }\n\n // add original path at the end\n url += `/${originalPath}`\n\n return url\n}\n\nexport default buildImageUrl\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFixed, defaultFixedOptions } from './defaults'\n\nfunction getFixedGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFixedOptions,\n ...args\n }\n\n let { width, height, base64, useBase64 } = options\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.height) {\n desiredAspectRatio = width / options.height\n }\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let widths = sizeMultipliersFixed.map(scale => Math.round(width * scale))\n let initial = { webp: [], base: [] }\n\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth, i) => {\n let resolution = `${sizeMultipliersFixed[i]}x`\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n ...options,\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...size,\n ...(forceConvert && { format: forceConvert })\n })\n\n acc.webp.push(`${webpUrl} ${resolution}`)\n acc.base.push(`${baseUrl} ${resolution}`)\n\n return acc\n }, initial)\n\n let outputHeight = Math.round(height ? height : width / desiredAspectRatio)\n\n let imgSize = {\n ...options,\n width: width,\n height: outputHeight\n }\n\n let src = buildUrl(originalPath, {\n ...imgSize,\n ...(forceConvert && { format: forceConvert })\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n // base64String\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n width: Math.round(width),\n height: outputHeight,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null\n }\n}\n\nexport default getFixedGatsbyImage\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFluid, defaultFluidOptions } from './defaults'\n\nfunction getFluidGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFluidOptions,\n ...args\n }\n\n let { maxWidth, base64, useBase64 } = options\n\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.maxHeight) {\n desiredAspectRatio = maxWidth / options.maxHeight\n }\n\n let maxHeight = options.maxHeight || Math.round(maxWidth / dimensions.aspectRatio)\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let sizes = options.sizes || `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`\n let widths = sizeMultipliersFluid\n .map(scale => Math.round(maxWidth * scale))\n .filter(width => width < dimensions.width)\n .concat(dimensions.width)\n\n let initial = { webp: [], base: [] }\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth) => {\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: forceConvert }\n })\n\n acc.webp.push(`${webpUrl} ${currentWidth}w`)\n acc.base.push(`${baseUrl} ${currentWidth}w`)\n return acc\n }, initial)\n\n let imgSize = { width: maxWidth, height: maxHeight }\n\n let src = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: forceConvert }\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null,\n sizes\n }\n}\n\nexport default getFluidGatsbyImage\n"],"names":["const","validImageUrlPattern","getBasicImageProps","image","url","lqip","base64","test","originalPath","replace","split","map","num","parseInt","filename","dimensions","width","height","STORYBLOK_BASE_URL","sizeMultipliersFixed","sizeMultipliersFluid","defaultOptions","quality","smartCrop","format","fill","toFormat","useBase64","defaultFluidOptions","Object","maxWidth","maxHeight","defaultFixedOptions","isWebP","isConverted","includes","isOriginal","buildImageUrl","filters","filter","element","Boolean","length","reduce","acc","currentFilter","i","applyFilters","args","imageProps","options","desiredAspectRatio","aspectRatio","forceConvert","srcSets","scale","Math","round","currentWidth","resolution","currentHeight","size","webpUrl","buildUrl","baseUrl","webp","push","base","outputHeight","imgSize","src","srcWebp","srcSet","join","srcSetWebp","sizes","concat"],"mappings":"AAAAA,IAAMC,EAAuB,wFAE7B,SAASC,EAAmBC,OACtBC,EAAM,KACNC,EAAO,QAEU,iBAAVF,IACTC,EAAMD,GAGa,iBAAVA,IACTC,EAAMD,EAAMA,MACZE,EAAOF,EAAMG,OAASH,EAAMG,OAAS,QAGvCF,EAAMH,EAAqBM,KAAKH,GAAOA,EAAM,aAGpC,MAILI,EAAeJ,EAAIK,QADA,mCACwB,MAEZD,EAAaE,MA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,EAAOzB,KAChB6C,EAAe,WAGbsB,EAAQzB,EAAQyB,sBAAwB7C,gBAAsBA,OAO9DwB,EANSlC,EACVT,aAAI4C,UAASC,KAAKC,MAAM3B,EAAWyB,KACnChB,gBAAOvB,UAASA,EAAQD,EAAWC,QACnC4D,OAAO7D,EAAWC,OAIlBuB,gBAAOmB,UAAgBA,EAAe3C,EAAWC,QACjD2B,gBAAQC,EAAKc,OAGRG,EAAO,CACT7C,MAAO0C,EACPzC,OAJkBuC,KAAKC,MAAMC,EAAeP,IAO1CW,EAAUC,EAASvD,EAAcqB,iBAChCqB,EACAW,GACErC,OAAQ,UAGXwC,EAAUD,EAASvD,EAAcqB,iBAChCqB,EACAW,GACErC,OAAQ6B,YAGfT,EAAIqB,KAAKC,KAAQJ,MAAWJ,OAC5Bd,EAAIuB,KAAKD,KAAQF,MAAWN,OACrBd,GAzBG,CAAEqB,KAAM,GAAIE,KAAM,KA4B5BE,EAAU,CAAErD,MAAOc,EAAUb,OAAQc,GAErCuC,EAAMP,EAASvD,EAAcqB,iBAC5BqB,EACAmB,GACE7C,OAAQ6B,KAGXkB,EAAUR,EAASvD,EAAcqB,iBAChCqB,EACAmB,GACE7C,OAAQ,gBAGR,CACLlB,OAAQqB,EAAYrB,GAAUD,EAAO,KACrC+C,YAAaD,MACbmB,UACAC,EACAC,OAAQlB,EAAQa,KAAKM,KAAK,QAAU,KACpCC,WAAYpB,EAAQW,KAAKQ,KAAK,QAAU,WACxCE"} \ No newline at end of file diff --git a/dist/index.mjs b/dist/index.mjs index 8ae3103..9b3a8f6 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1,2 +1,2 @@ -var t=/^\/\/a.storyblok.com\/f\/[0-9]+\/[0-9]+x[0-9]+\/[A-Za-z0-9]+\/[\S]+\.[a-z]+/;function e(e){var a=null,n=null;if("string"==typeof e&&(a=e),"object"==typeof e&&(a=e.image,n=e.base64?e.base64:null),!(a=t.test(a)?a:null))return!1;var i=a.replace("//a.storyblok.com/",""),r=i.split("/"),s=r[4],o=r[2].split("x").map(function(t){return parseInt(t,10)}),u=o[0],l=o[1];return{originalPath:i,extension:s.split(".")[1],metadata:{dimensions:{width:u,height:l,aspectRatio:u/l},lqip:n}}}var a="https://img2.storyblok.com",n=[1,1.5,2,3],i=[.25,.5,1,1.5,2,3],r={quality:100,smartCrop:!0,format:null,fill:null,toFormat:null,base64:null,useBase64:!0},s=Object.assign({},r,{maxWidth:800,maxHeight:null}),o=Object.assign({},r,{width:400,height:null});function u(t){var e=t.includes("filters:format(webp)"),a=/[a-f0-9]+-\d+x\d+\.webp/.test(t);return e||a}function l(t,e){var n=e.width,i=e.height,r=e.smartCrop,s=e.quality,o=e.format,u=e.fill,l=t.split("."),h=a;n&&i&&(h+="/"+n+"x"+i),r&&(h+="/smart");var c=[s&&"quality("+s+")",o&&o!==l[1]&&"format("+o+")",u&&"fill("+u+")"];return(c=c.filter(function(t){return!0===Boolean(t)})).length>0&&(h+=function(t){return t.reduce(function(t,e,a){return t+":"+e},"/filters")}(c)),h+"/"+t}function h(t,a){void 0===a&&(a={});var i=e(t);if(!i)return null;var r=Object.assign({},o,a),s=r.width,h=r.height,c=r.base64,p=r.useBase64,b=i.metadata,f=b.dimensions,m=b.lqip,g=i.originalPath,d=f.aspectRatio;r.height&&(d=s/r.height);var w=null;r.toFormat?w=r.toFormat:u(g)&&(w="jpg");var j=n.map(function(t){return Math.round(s*t)}).filter(function(t){return t0&&(h+=function(t){return t.reduce(function(t,e,a){return t+":"+e},"/filters")}(c)),h+"/"+t}function h(t,a){void 0===a&&(a={});var i=e(t);if(!i)return null;var r=Object.assign({},o,a),s=r.width,h=r.height,c=r.base64,p=r.useBase64,b=i.metadata,f=b.dimensions,m=b.lqip,g=i.originalPath,d=f.aspectRatio;r.height&&(d=s/r.height);var w=null;r.toFormat?w=r.toFormat:u(g)&&(w="jpg");var j=n.map(function(t){return Math.round(s*t)}).filter(function(t){return t parseInt(num, 10))\n let [, extension] = filename.split('.')\n\n let aspectRatio = width / height\n let metadata = { dimensions: { width, height, aspectRatio }, lqip }\n\n return {\n originalPath,\n extension,\n metadata\n }\n}\n\nexport default getBasicImageProps\n","export const DEFAULT_FIXED_WIDTH = 400\nexport const DEFAULT_FLUID_MAX_WIDTH = 800\nexport const STORYBLOK_BASE_URL = 'https://img2.storyblok.com'\n\nexport const sizeMultipliersFixed = [1, 1.5, 2, 3]\nexport const sizeMultipliersFluid = [0.25, 0.5, 1, 1.5, 2, 3]\n\nexport const defaultOptions = {\n quality: 100,\n smartCrop: true,\n format: null,\n fill: null,\n toFormat: null,\n base64: null,\n useBase64: true\n}\n\nexport const defaultFluidOptions = {\n ...defaultOptions,\n maxWidth: DEFAULT_FLUID_MAX_WIDTH,\n maxHeight: null\n}\n\nexport const defaultFixedOptions = {\n ...defaultOptions,\n width: DEFAULT_FIXED_WIDTH,\n height: null\n}\n","export function applyFilters(filters) {\n return filters.reduce((acc, currentFilter, i) => {\n return `${acc}:${currentFilter}`\n }, '/filters')\n}\n\nexport function isWebP(url) {\n const isConverted = url.includes('filters:format(webp)')\n const isOriginal = /[a-f0-9]+-\\d+x\\d+\\.webp/.test(url)\n return isConverted || isOriginal\n}\n","import { STORYBLOK_BASE_URL } from '../defaults'\nimport { applyFilters } from './helpers'\n\nfunction buildImageUrl(originalPath, image) {\n let { width, height, smartCrop, quality, format, fill } = image\n\n let [, extension] = originalPath.split('.')\n\n let url = STORYBLOK_BASE_URL\n\n if (width && height) {\n url += `/${width}x${height}`\n }\n\n if (smartCrop) {\n url += `/smart`\n }\n\n let filters = [\n ...[quality && `quality(${quality})`],\n ...[format && format !== extension && `format(${format})`],\n ...[fill && `fill(${fill})`]\n ]\n\n // remove falsy elements\n filters = filters.filter(element => Boolean(element) === true)\n\n if (filters.length > 0) {\n url += applyFilters(filters)\n }\n\n // add original path at the end\n url += `/${originalPath}`\n\n return url\n}\n\nexport default buildImageUrl\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFixed, defaultFixedOptions } from './defaults'\n\nfunction getFixedGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFixedOptions,\n ...args\n }\n\n let { width, height, base64, useBase64 } = options\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.height) {\n desiredAspectRatio = width / options.height\n }\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let widths = sizeMultipliersFixed.map(scale => Math.round(width * scale))\n let initial = { webp: [], base: [] }\n\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth, i) => {\n let resolution = `${sizeMultipliersFixed[i]}x`\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n ...options,\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...size,\n ...(forceConvert && { format: forceConvert })\n })\n\n acc.webp.push(`${webpUrl} ${resolution}`)\n acc.base.push(`${baseUrl} ${resolution}`)\n\n return acc\n }, initial)\n\n let outputHeight = Math.round(height ? height : width / desiredAspectRatio)\n\n let imgSize = {\n ...options,\n width: width,\n height: outputHeight\n }\n\n let src = buildUrl(originalPath, {\n ...imgSize,\n ...(forceConvert && { format: forceConvert })\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n // base64String\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n width: Math.round(width),\n height: outputHeight,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null\n }\n}\n\nexport default getFixedGatsbyImage\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFluid, defaultFluidOptions } from './defaults'\n\nfunction getFluidGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFluidOptions,\n ...args\n }\n\n let { maxWidth, base64, useBase64 } = options\n\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.maxHeight) {\n desiredAspectRatio = maxWidth / options.maxHeight\n }\n\n let maxHeight = options.maxHeight || Math.round(maxWidth / dimensions.aspectRatio)\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let sizes = options.sizes || `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`\n let widths = sizeMultipliersFluid\n .map(scale => Math.round(maxWidth * scale))\n .filter(width => width < dimensions.width)\n .concat(dimensions.width)\n\n let initial = { webp: [], base: [] }\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth) => {\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: forceConvert }\n })\n\n acc.webp.push(`${webpUrl} ${currentWidth}w`)\n acc.base.push(`${baseUrl} ${currentWidth}w`)\n return acc\n }, initial)\n\n let imgSize = { width: maxWidth, height: maxHeight }\n\n let src = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: forceConvert }\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null,\n sizes\n }\n}\n\nexport default getFluidGatsbyImage\n"],"names":["const","validImageUrlPattern","getBasicImageProps","image","url","lqip","base64","test","originalPath","replace","split","map","num","parseInt","filename","dimensions","width","height","STORYBLOK_BASE_URL","sizeMultipliersFixed","sizeMultipliersFluid","defaultOptions","quality","smartCrop","format","fill","toFormat","useBase64","defaultFluidOptions","Object","maxWidth","maxHeight","defaultFixedOptions","isWebP","isConverted","includes","isOriginal","buildImageUrl","filters","filter","element","Boolean","length","reduce","acc","currentFilter","i","applyFilters","getFixedGatsbyImage","args","imageProps","options","desiredAspectRatio","aspectRatio","forceConvert","srcSets","scale","Math","round","currentWidth","resolution","currentHeight","size","webpUrl","buildUrl","baseUrl","webp","push","base","outputHeight","imgSize","src","srcWebp","srcSet","join","srcSetWebp","getFluidGatsbyImage","sizes","concat"],"mappings":"AAAAA,IAAMC,EAAuB,8EAE7B,SAASC,EAAmBC,OACtBC,EAAM,KACNC,EAAO,QAEU,iBAAVF,IACTC,EAAMD,GAGa,iBAAVA,IACTC,EAAMD,EAAMA,MACZE,EAAOF,EAAMG,OAASH,EAAMG,OAAS,QAGvCF,EAAMH,EAAqBM,KAAKH,GAAOA,EAAM,aAGpC,MAGLI,EAAeJ,EAAIK,QAAQ,qBAAsB,MAElBD,EAAaE,MAAM,mBACrBA,MAAM,KAAKC,aAAIC,UAAOC,SAASD,EAAK,0BAM9D,cACLJ,YANkBM,EAASJ,MAAM,iBAGpB,CAAEK,WAAY,OAAEC,SAAOC,cADpBD,EAAQC,QACmCZ,IC5BxDL,IAEMkB,EAAqB,6BAErBC,EAAuB,CAAC,EAAG,IAAK,EAAG,GACnCC,EAAuB,CAAC,IAAM,GAAK,EAAG,IAAK,EAAG,GAE9CC,EAAiB,CA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G,EAAO,CACT9C,MAAO2C,EACP1C,OAJkBwC,KAAKC,MAAMC,EAAeP,IAO1CW,EAAUC,EAASxD,EAAcqB,iBAChCsB,EACAW,GACEtC,OAAQ,UAGXyC,EAAUD,EAASxD,EAAcqB,iBAChCsB,EACAW,GACEtC,OAAQ8B,YAGfV,EAAIsB,KAAKC,KAAQJ,MAAWJ,OAC5Bf,EAAIwB,KAAKD,KAAQF,MAAWN,OACrBf,GAzBG,CAAEsB,KAAM,GAAIE,KAAM,KA4B5BE,EAAU,CAAEtD,MAAOc,EAAUb,OAAQc,GAErCwC,EAAMP,EAASxD,EAAcqB,iBAC5BsB,EACAmB,GACE9C,OAAQ8B,KAGXkB,EAAUR,EAASxD,EAAcqB,iBAChCsB,EACAmB,GACE9C,OAAQ,gBAGR,CACLlB,OAAQqB,EAAYrB,GAAUD,EAAO,KACrCgD,YAAaD,MACbmB,UACAC,EACAC,OAAQlB,EAAQa,KAAKM,KAAK,QAAU,KACpCC,WAAYpB,EAAQW,KAAKQ,KAAK,QAAU,WACxCG"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../src/utils/getBasicImageProps.js","../src/defaults.js","../src/utils/helpers.js","../src/utils/buildImageUrl.js","../src/getFixedGatsbyImage.js","../src/getFluidGatsbyImage.js"],"sourcesContent":["const validImageUrlPattern = /^(https?:)?\\/\\/a.storyblok.com\\/f\\/[0-9]+\\/[0-9]+x[0-9]+\\/[A-Za-z0-9]+\\/[\\S]+\\.[a-z]+/\n\nfunction getBasicImageProps(image) {\n let url = null\n let lqip = null\n\n if (typeof image === 'string') {\n url = image\n }\n\n if (typeof image === 'object') {\n url = image.image\n lqip = image.base64 ? image.base64 : null\n }\n\n url = validImageUrlPattern.test(url) ? url : null\n\n if (!url) {\n return false\n }\n\n const storyblokRegex = /^(https?:)?\\/\\/a.storyblok.com\\//\n let originalPath = url.replace(storyblokRegex, '')\n\n let [, , dimensions, , filename] = originalPath.split('/')\n let [width, height] = dimensions.split('x').map(num => parseInt(num, 10))\n let [, extension] = filename.split('.')\n\n let aspectRatio = width / height\n let metadata = { dimensions: { width, height, aspectRatio }, lqip }\n\n return {\n originalPath,\n extension,\n metadata\n }\n}\n\nexport default getBasicImageProps\n","export const DEFAULT_FIXED_WIDTH = 400\nexport const DEFAULT_FLUID_MAX_WIDTH = 800\nexport const STORYBLOK_BASE_URL = 'https://img2.storyblok.com'\n\nexport const sizeMultipliersFixed = [1, 1.5, 2, 3]\nexport const sizeMultipliersFluid = [0.25, 0.5, 1, 1.5, 2, 3]\n\nexport const defaultOptions = {\n quality: 100,\n smartCrop: true,\n format: null,\n fill: null,\n toFormat: null,\n base64: null,\n useBase64: true\n}\n\nexport const defaultFluidOptions = {\n ...defaultOptions,\n maxWidth: DEFAULT_FLUID_MAX_WIDTH,\n maxHeight: null\n}\n\nexport const defaultFixedOptions = {\n ...defaultOptions,\n width: DEFAULT_FIXED_WIDTH,\n height: null\n}\n","export function applyFilters(filters) {\n return filters.reduce((acc, currentFilter, i) => {\n return `${acc}:${currentFilter}`\n }, '/filters')\n}\n\nexport function isWebP(url) {\n const isConverted = url.includes('filters:format(webp)')\n const isOriginal = /[a-f0-9]+-\\d+x\\d+\\.webp/.test(url)\n return isConverted || isOriginal\n}\n","import { STORYBLOK_BASE_URL } from '../defaults'\nimport { applyFilters } from './helpers'\n\nfunction buildImageUrl(originalPath, image) {\n let { width, height, smartCrop, quality, format, fill } = image\n\n let [, extension] = originalPath.split('.')\n\n let url = STORYBLOK_BASE_URL\n\n if (width && height) {\n url += `/${width}x${height}`\n }\n\n if (smartCrop) {\n url += `/smart`\n }\n\n let filters = [\n ...[quality && `quality(${quality})`],\n ...[format && format !== extension && `format(${format})`],\n ...[fill && `fill(${fill})`]\n ]\n\n // remove falsy elements\n filters = filters.filter(element => Boolean(element) === true)\n\n if (filters.length > 0) {\n url += applyFilters(filters)\n }\n\n // add original path at the end\n url += `/${originalPath}`\n\n return url\n}\n\nexport default buildImageUrl\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFixed, defaultFixedOptions } from './defaults'\n\nfunction getFixedGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFixedOptions,\n ...args\n }\n\n let { width, height, base64, useBase64 } = options\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.height) {\n desiredAspectRatio = width / options.height\n }\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let widths = sizeMultipliersFixed.map(scale => Math.round(width * scale))\n let initial = { webp: [], base: [] }\n\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth, i) => {\n let resolution = `${sizeMultipliersFixed[i]}x`\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n ...options,\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...size,\n ...(forceConvert && { format: forceConvert })\n })\n\n acc.webp.push(`${webpUrl} ${resolution}`)\n acc.base.push(`${baseUrl} ${resolution}`)\n\n return acc\n }, initial)\n\n let outputHeight = Math.round(height ? height : width / desiredAspectRatio)\n\n let imgSize = {\n ...options,\n width: width,\n height: outputHeight\n }\n\n let src = buildUrl(originalPath, {\n ...imgSize,\n ...(forceConvert && { format: forceConvert })\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n // base64String\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n width: Math.round(width),\n height: outputHeight,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null\n }\n}\n\nexport default getFixedGatsbyImage\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFluid, defaultFluidOptions } from './defaults'\n\nfunction getFluidGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFluidOptions,\n ...args\n }\n\n let { maxWidth, base64, useBase64 } = options\n\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.maxHeight) {\n desiredAspectRatio = maxWidth / options.maxHeight\n }\n\n let maxHeight = options.maxHeight || Math.round(maxWidth / dimensions.aspectRatio)\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let sizes = options.sizes || `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`\n let widths = sizeMultipliersFluid\n .map(scale => Math.round(maxWidth * scale))\n .filter(width => width < dimensions.width)\n .concat(dimensions.width)\n\n let initial = { webp: [], base: [] }\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth) => {\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: forceConvert }\n })\n\n acc.webp.push(`${webpUrl} ${currentWidth}w`)\n acc.base.push(`${baseUrl} ${currentWidth}w`)\n return acc\n }, initial)\n\n let imgSize = { width: maxWidth, height: maxHeight }\n\n let src = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: forceConvert }\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null,\n sizes\n }\n}\n\nexport default getFluidGatsbyImage\n"],"names":["const","validImageUrlPattern","getBasicImageProps","image","url","lqip","base64","test","originalPath","replace","split","map","num","parseInt","filename","dimensions","width","height","STORYBLOK_BASE_URL","sizeMultipliersFixed","sizeMultipliersFluid","defaultOptions","quality","smartCrop","format","fill","toFormat","useBase64","defaultFluidOptions","Object","maxWidth","maxHeight","defaultFixedOptions","isWebP","isConverted","includes","isOriginal","buildImageUrl","filters","filter","element","Boolean","length","reduce","acc","currentFilter","i","applyFilters","getFixedGatsbyImage","args","imageProps","options","desiredAspectRatio","aspectRatio","forceConvert","srcSets","scale","Math","round","currentWidth","resolution","currentHeight","size","webpUrl","buildUrl","baseUrl","webp","push","base","outputHeight","imgSize","src","srcWebp","srcSet","join","srcSetWebp","getFluidGatsbyImage","sizes","concat"],"mappings":"AAAAA,IAAMC,EAAuB,wFAE7B,SAASC,EAAmBC,OACtBC,EAAM,KACNC,EAAO,QAEU,iBAAVF,IACTC,EAAMD,GAGa,iBAAVA,IACTC,EAAMD,EAAMA,MACZE,EAAOF,EAAMG,OAASH,EAAMG,OAAS,QAGvCF,EAAMH,EAAqBM,KAAKH,GAAOA,EAAM,aAGpC,MAILI,EAAeJ,EAAIK,QADA,mCACwB,MAEZD,EAAaE,MAAM,mBACrBA,MAAM,KAAKC,aAAIC,UAAOC,SAASD,EAAK,0BAM9D,cACLJ,YANkBM,EAASJ,MAAM,iBAGpB,CAAEK,WAAY,OAAEC,SAAOC,cADpBD,EAAQC,QACmCZ,IC7BxDL,IAEMkB,EAAqB,6BAErBC,EAAuB,CAAC,EAAG,IAAK,EAAG,GACnCC,EAAuB,CAAC,IAAM,GAAK,EAAG,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,QACjD2B,gBAAQC,EAAKe,OAGRG,EAAO,CACT9C,MAAO2C,EACP1C,OAJkBwC,KAAKC,MAAMC,EAAeP,IAO1CW,EAAUC,EAASxD,EAAcqB,iBAChCsB,EACAW,GACEtC,OAAQ,UAGXyC,EAAUD,EAASxD,EAAcqB,iBAChCsB,EACAW,GACEtC,OAAQ8B,YAGfV,EAAIsB,KAAKC,KAAQJ,MAAWJ,OAC5Bf,EAAIwB,KAAKD,KAAQF,MAAWN,OACrBf,GAzBG,CAAEsB,KAAM,GAAIE,KAAM,KA4B5BE,EAAU,CAAEtD,MAAOc,EAAUb,OAAQc,GAErCwC,EAAMP,EAASxD,EAAcqB,iBAC5BsB,EACAmB,GACE9C,OAAQ8B,KAGXkB,EAAUR,EAASxD,EAAcqB,iBAChCsB,EACAmB,GACE9C,OAAQ,gBAGR,CACLlB,OAAQqB,EAAYrB,GAAUD,EAAO,KACrCgD,YAAaD,MACbmB,UACAC,EACAC,OAAQlB,EAAQa,KAAKM,KAAK,QAAU,KACpCC,WAAYpB,EAAQW,KAAKQ,KAAK,QAAU,WACxCG"} \ No newline at end of file diff --git a/dist/index.umd.js b/dist/index.umd.js index 153a8cd..230cccc 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.gatsbyStoryblokImage={})}(this,function(t){var e=/^\/\/a.storyblok.com\/f\/[0-9]+\/[0-9]+x[0-9]+\/[A-Za-z0-9]+\/[\S]+\.[a-z]+/;function a(t){var a=null,n=null;if("string"==typeof t&&(a=t),"object"==typeof t&&(a=t.image,n=t.base64?t.base64:null),!(a=e.test(a)?a:null))return!1;var i=a.replace("//a.storyblok.com/",""),r=i.split("/"),s=r[4],o=r[2].split("x").map(function(t){return parseInt(t,10)}),u=o[0],l=o[1];return{originalPath:i,extension:s.split(".")[1],metadata:{dimensions:{width:u,height:l,aspectRatio:u/l},lqip:n}}}var n="https://img2.storyblok.com",i=[1,1.5,2,3],r=[.25,.5,1,1.5,2,3],s={quality:100,smartCrop:!0,format:null,fill:null,toFormat:null,base64:null,useBase64:!0},o=Object.assign({},s,{maxWidth:800,maxHeight:null}),u=Object.assign({},s,{width:400,height:null});function l(t){var e=t.includes("filters:format(webp)"),a=/[a-f0-9]+-\d+x\d+\.webp/.test(t);return e||a}function c(t,e){var a=e.width,i=e.height,r=e.smartCrop,s=e.quality,o=e.format,u=e.fill,l=t.split("."),c=n;a&&i&&(c+="/"+a+"x"+i),r&&(c+="/smart");var h=[s&&"quality("+s+")",o&&o!==l[1]&&"format("+o+")",u&&"fill("+u+")"];return(h=h.filter(function(t){return!0===Boolean(t)})).length>0&&(c+=function(t){return t.reduce(function(t,e,a){return t+":"+e},"/filters")}(h)),c+"/"+t}t.getFixedGatsbyImage=function(t,e){void 0===e&&(e={});var n=a(t);if(!n)return null;var r=Object.assign({},u,e),s=r.width,o=r.height,h=r.base64,f=r.useBase64,p=n.metadata,b=p.dimensions,d=p.lqip,m=n.originalPath,g=b.aspectRatio;r.height&&(g=s/r.height);var w=null;r.toFormat?w=r.toFormat:l(m)&&(w="jpg");var j=i.map(function(t){return Math.round(s*t)}).filter(function(t){return t0&&(h+=function(t){return t.reduce(function(t,e,a){return t+":"+e},"/filters")}(c)),h+"/"+t}t.getFixedGatsbyImage=function(t,e){void 0===e&&(e={});var n=a(t);if(!n)return null;var r=Object.assign({},u,e),s=r.width,o=r.height,c=r.base64,p=r.useBase64,f=n.metadata,b=f.dimensions,d=f.lqip,m=n.originalPath,g=b.aspectRatio;r.height&&(g=s/r.height);var w=null;r.toFormat?w=r.toFormat:l(m)&&(w="jpg");var j=i.map(function(t){return Math.round(s*t)}).filter(function(t){return t parseInt(num, 10))\n let [, extension] = filename.split('.')\n\n let aspectRatio = width / height\n let metadata = { dimensions: { width, height, aspectRatio }, lqip }\n\n return {\n originalPath,\n extension,\n metadata\n }\n}\n\nexport default getBasicImageProps\n","export const DEFAULT_FIXED_WIDTH = 400\nexport const DEFAULT_FLUID_MAX_WIDTH = 800\nexport const STORYBLOK_BASE_URL = 'https://img2.storyblok.com'\n\nexport const sizeMultipliersFixed = [1, 1.5, 2, 3]\nexport const sizeMultipliersFluid = [0.25, 0.5, 1, 1.5, 2, 3]\n\nexport const defaultOptions = {\n quality: 100,\n smartCrop: true,\n format: null,\n fill: null,\n toFormat: null,\n base64: null,\n useBase64: true\n}\n\nexport const defaultFluidOptions = {\n ...defaultOptions,\n maxWidth: DEFAULT_FLUID_MAX_WIDTH,\n maxHeight: null\n}\n\nexport const defaultFixedOptions = {\n ...defaultOptions,\n width: DEFAULT_FIXED_WIDTH,\n height: null\n}\n","export function applyFilters(filters) {\n return filters.reduce((acc, currentFilter, i) => {\n return `${acc}:${currentFilter}`\n }, '/filters')\n}\n\nexport function isWebP(url) {\n const isConverted = url.includes('filters:format(webp)')\n const isOriginal = /[a-f0-9]+-\\d+x\\d+\\.webp/.test(url)\n return isConverted || isOriginal\n}\n","import { STORYBLOK_BASE_URL } from '../defaults'\nimport { applyFilters } from './helpers'\n\nfunction buildImageUrl(originalPath, image) {\n let { width, height, smartCrop, quality, format, fill } = image\n\n let [, extension] = originalPath.split('.')\n\n let url = STORYBLOK_BASE_URL\n\n if (width && height) {\n url += `/${width}x${height}`\n }\n\n if (smartCrop) {\n url += `/smart`\n }\n\n let filters = [\n ...[quality && `quality(${quality})`],\n ...[format && format !== extension && `format(${format})`],\n ...[fill && `fill(${fill})`]\n ]\n\n // remove falsy elements\n filters = filters.filter(element => Boolean(element) === true)\n\n if (filters.length > 0) {\n url += applyFilters(filters)\n }\n\n // add original path at the end\n url += `/${originalPath}`\n\n return url\n}\n\nexport default buildImageUrl\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFixed, defaultFixedOptions } from './defaults'\n\nfunction getFixedGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFixedOptions,\n ...args\n }\n\n let { width, height, base64, useBase64 } = options\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.height) {\n desiredAspectRatio = width / options.height\n }\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let widths = sizeMultipliersFixed.map(scale => Math.round(width * scale))\n let initial = { webp: [], base: [] }\n\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth, i) => {\n let resolution = `${sizeMultipliersFixed[i]}x`\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n ...options,\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...size,\n ...(forceConvert && { format: forceConvert })\n })\n\n acc.webp.push(`${webpUrl} ${resolution}`)\n acc.base.push(`${baseUrl} ${resolution}`)\n\n return acc\n }, initial)\n\n let outputHeight = Math.round(height ? height : width / desiredAspectRatio)\n\n let imgSize = {\n ...options,\n width: width,\n height: outputHeight\n }\n\n let src = buildUrl(originalPath, {\n ...imgSize,\n ...(forceConvert && { format: forceConvert })\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n // base64String\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n width: Math.round(width),\n height: outputHeight,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null\n }\n}\n\nexport default getFixedGatsbyImage\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFluid, defaultFluidOptions } from './defaults'\n\nfunction getFluidGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFluidOptions,\n ...args\n }\n\n let { maxWidth, base64, useBase64 } = options\n\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.maxHeight) {\n desiredAspectRatio = maxWidth / options.maxHeight\n }\n\n let maxHeight = options.maxHeight || Math.round(maxWidth / dimensions.aspectRatio)\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let sizes = options.sizes || `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`\n let widths = sizeMultipliersFluid\n .map(scale => Math.round(maxWidth * scale))\n .filter(width => width < dimensions.width)\n .concat(dimensions.width)\n\n let initial = { webp: [], base: [] }\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth) => {\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: forceConvert }\n })\n\n acc.webp.push(`${webpUrl} ${currentWidth}w`)\n acc.base.push(`${baseUrl} ${currentWidth}w`)\n return acc\n }, initial)\n\n let imgSize = { width: maxWidth, height: maxHeight }\n\n let src = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: forceConvert }\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null,\n sizes\n }\n}\n\nexport default getFluidGatsbyImage\n"],"names":["const","validImageUrlPattern","getBasicImageProps","image","url","lqip","base64","test","originalPath","replace","split","map","num","parseInt","filename","dimensions","width","height","STORYBLOK_BASE_URL","sizeMultipliersFixed","sizeMultipliersFluid","defaultOptions","quality","smartCrop","format","fill","toFormat","useBase64","defaultFluidOptions","Object","maxWidth","maxHeight","defaultFixedOptions","isWebP","isConverted","includes","isOriginal","buildImageUrl","filters","filter","element","Boolean","length","reduce","acc","currentFilter","i","applyFilters","args","imageProps","options","desiredAspectRatio","aspectRatio","forceConvert","srcSets","scale","Math","round","currentWidth","resolution","currentHeight","size","webpUrl","buildUrl","baseUrl","webp","push","base","outputHeight","imgSize","src","srcWebp","srcSet","join","srcSetWebp","sizes","concat"],"mappings":"0LAAAA,IAAMC,EAAuB,8EAE7B,SAASC,EAAmBC,OACtBC,EAAM,KACNC,EAAO,QAEU,iBAAVF,IACTC,EAAMD,GAGa,iBAAVA,IACTC,EAAMD,EAAMA,MACZE,EAAOF,EAAMG,OAASH,EAAMG,OAAS,QAGvCF,EAAMH,EAAqBM,KAAKH,GAAOA,EAAM,aAGpC,MAGLI,EAAeJ,EAAIK,QAAQ,qBAAsB,MAElBD,EAAaE,MAAM,mBACrBA,MAAM,KAAKC,aAAIC,UAAOC,SAASD,EAAK,0BAM9D,cACLJ,YANkBM,EAASJ,MAAM,iBAGpB,CAAEK,WAAY,OAAEC,SAAOC,cADpBD,EAAQC,QACmCZ,IC5BxDL,IAEMkB,EAAqB,6BAErBC,EAAuB,CAAC,EAAG,IAAK,EAAG,GACnCC,EAAuB,CAAC,IAAM,GAAK,EAAG,IAAK,EAAG,GAE9CC,EAAiB,CAC5BC,QAAS,IACTC,WAAW,EACXC,OAAQ,KACRC,KAAM,KACNC,SAAU,KACVpB,OAAQ,KACRqB,WAAW,GAGAC,EAAsBC,iBAC9BR,GACHS,SAl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AASvD,EAAcqB,iBAChCqB,EACAW,GACErC,OAAQ6B,YAGfT,EAAIqB,KAAKC,KAAQJ,MAAWJ,OAC5Bd,EAAIuB,KAAKD,KAAQF,MAAWN,OACrBd,GAzBG,CAAEqB,KAAM,GAAIE,KAAM,KA4B5BE,EAAU,CAAErD,MAAOc,EAAUb,OAAQc,GAErCuC,EAAMP,EAASvD,EAAcqB,iBAC5BqB,EACAmB,GACE7C,OAAQ6B,KAGXkB,EAAUR,EAASvD,EAAcqB,iBAChCqB,EACAmB,GACE7C,OAAQ,gBAGR,CACLlB,OAAQqB,EAAYrB,GAAUD,EAAO,KACrC+C,YAAaD,MACbmB,UACAC,EACAC,OAAQlB,EAAQa,KAAKM,KAAK,QAAU,KACpCC,WAAYpB,EAAQW,KAAKQ,KAAK,QAAU,WACxCE"} \ No newline at end of file +{"version":3,"file":"index.umd.js","sources":["../src/utils/getBasicImageProps.js","../src/defaults.js","../src/utils/helpers.js","../src/utils/buildImageUrl.js","../src/getFixedGatsbyImage.js","../src/getFluidGatsbyImage.js"],"sourcesContent":["const validImageUrlPattern = /^(https?:)?\\/\\/a.storyblok.com\\/f\\/[0-9]+\\/[0-9]+x[0-9]+\\/[A-Za-z0-9]+\\/[\\S]+\\.[a-z]+/\n\nfunction getBasicImageProps(image) {\n let url = null\n let lqip = null\n\n if (typeof image === 'string') {\n url = image\n }\n\n if (typeof image === 'object') {\n url = image.image\n lqip = image.base64 ? image.base64 : null\n }\n\n url = validImageUrlPattern.test(url) ? url : null\n\n if (!url) {\n return false\n }\n\n const storyblokRegex = /^(https?:)?\\/\\/a.storyblok.com\\//\n let originalPath = url.replace(storyblokRegex, '')\n\n let [, , dimensions, , filename] = originalPath.split('/')\n let [width, height] = dimensions.split('x').map(num => parseInt(num, 10))\n let [, extension] = filename.split('.')\n\n let aspectRatio = width / height\n let metadata = { dimensions: { width, height, aspectRatio }, lqip }\n\n return {\n originalPath,\n extension,\n metadata\n }\n}\n\nexport default getBasicImageProps\n","export const DEFAULT_FIXED_WIDTH = 400\nexport const DEFAULT_FLUID_MAX_WIDTH = 800\nexport const STORYBLOK_BASE_URL = 'https://img2.storyblok.com'\n\nexport const sizeMultipliersFixed = [1, 1.5, 2, 3]\nexport const sizeMultipliersFluid = [0.25, 0.5, 1, 1.5, 2, 3]\n\nexport const defaultOptions = {\n quality: 100,\n smartCrop: true,\n format: null,\n fill: null,\n toFormat: null,\n base64: null,\n useBase64: true\n}\n\nexport const defaultFluidOptions = {\n ...defaultOptions,\n maxWidth: DEFAULT_FLUID_MAX_WIDTH,\n maxHeight: null\n}\n\nexport const defaultFixedOptions = {\n ...defaultOptions,\n width: DEFAULT_FIXED_WIDTH,\n height: null\n}\n","export function applyFilters(filters) {\n return filters.reduce((acc, currentFilter, i) => {\n return `${acc}:${currentFilter}`\n }, '/filters')\n}\n\nexport function isWebP(url) {\n const isConverted = url.includes('filters:format(webp)')\n const isOriginal = /[a-f0-9]+-\\d+x\\d+\\.webp/.test(url)\n return isConverted || isOriginal\n}\n","import { STORYBLOK_BASE_URL } from '../defaults'\nimport { applyFilters } from './helpers'\n\nfunction buildImageUrl(originalPath, image) {\n let { width, height, smartCrop, quality, format, fill } = image\n\n let [, extension] = originalPath.split('.')\n\n let url = STORYBLOK_BASE_URL\n\n if (width && height) {\n url += `/${width}x${height}`\n }\n\n if (smartCrop) {\n url += `/smart`\n }\n\n let filters = [\n ...[quality && `quality(${quality})`],\n ...[format && format !== extension && `format(${format})`],\n ...[fill && `fill(${fill})`]\n ]\n\n // remove falsy elements\n filters = filters.filter(element => Boolean(element) === true)\n\n if (filters.length > 0) {\n url += applyFilters(filters)\n }\n\n // add original path at the end\n url += `/${originalPath}`\n\n return url\n}\n\nexport default buildImageUrl\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFixed, defaultFixedOptions } from './defaults'\n\nfunction getFixedGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFixedOptions,\n ...args\n }\n\n let { width, height, base64, useBase64 } = options\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.height) {\n desiredAspectRatio = width / options.height\n }\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let widths = sizeMultipliersFixed.map(scale => Math.round(width * scale))\n let initial = { webp: [], base: [] }\n\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth, i) => {\n let resolution = `${sizeMultipliersFixed[i]}x`\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n ...options,\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...size,\n ...(forceConvert && { format: forceConvert })\n })\n\n acc.webp.push(`${webpUrl} ${resolution}`)\n acc.base.push(`${baseUrl} ${resolution}`)\n\n return acc\n }, initial)\n\n let outputHeight = Math.round(height ? height : width / desiredAspectRatio)\n\n let imgSize = {\n ...options,\n width: width,\n height: outputHeight\n }\n\n let src = buildUrl(originalPath, {\n ...imgSize,\n ...(forceConvert && { format: forceConvert })\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n // base64String\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n width: Math.round(width),\n height: outputHeight,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null\n }\n}\n\nexport default getFixedGatsbyImage\n","import getBasicImageProps from './utils/getBasicImageProps'\nimport buildUrl from './utils/buildImageUrl'\nimport { isWebP } from './utils/helpers'\nimport { sizeMultipliersFluid, defaultFluidOptions } from './defaults'\n\nfunction getFluidGatsbyImage(image, args = {}) {\n let imageProps = getBasicImageProps(image)\n\n if (!imageProps) {\n return null\n }\n\n let options = {\n ...defaultFluidOptions,\n ...args\n }\n\n let { maxWidth, base64, useBase64 } = options\n\n let {\n metadata: { dimensions, lqip },\n originalPath\n } = imageProps\n\n let desiredAspectRatio = dimensions.aspectRatio\n\n // If we're cropping, calculate the specified aspect ratio\n if (options.maxHeight) {\n desiredAspectRatio = maxWidth / options.maxHeight\n }\n\n let maxHeight = options.maxHeight || Math.round(maxWidth / dimensions.aspectRatio)\n\n let forceConvert = null\n if (options.toFormat) {\n forceConvert = options.toFormat\n } else if (isWebP(originalPath)) {\n forceConvert = 'jpg'\n }\n\n let sizes = options.sizes || `(max-width: ${maxWidth}px) 100vw, ${maxWidth}px`\n let widths = sizeMultipliersFluid\n .map(scale => Math.round(maxWidth * scale))\n .filter(width => width < dimensions.width)\n .concat(dimensions.width)\n\n let initial = { webp: [], base: [] }\n let srcSets = widths\n .filter(currentWidth => currentWidth < dimensions.width)\n .reduce((acc, currentWidth) => {\n let currentHeight = Math.round(currentWidth / desiredAspectRatio)\n\n let size = {\n width: currentWidth,\n height: currentHeight\n }\n\n let webpUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: 'webp' }\n })\n\n let baseUrl = buildUrl(originalPath, {\n ...options,\n ...size,\n ...{ format: forceConvert }\n })\n\n acc.webp.push(`${webpUrl} ${currentWidth}w`)\n acc.base.push(`${baseUrl} ${currentWidth}w`)\n return acc\n }, initial)\n\n let imgSize = { width: maxWidth, height: maxHeight }\n\n let src = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: forceConvert }\n })\n\n let srcWebp = buildUrl(originalPath, {\n ...options,\n ...imgSize,\n ...{ format: 'webp' }\n })\n\n return {\n base64: useBase64 ? base64 || lqip : null,\n aspectRatio: desiredAspectRatio,\n src,\n srcWebp,\n srcSet: srcSets.base.join(',\\n') || null,\n srcSetWebp: srcSets.webp.join(',\\n') || null,\n sizes\n }\n}\n\nexport default getFluidGatsbyImage\n"],"names":["const","validImageUrlPattern","getBasicImageProps","image","url","lqip","base64","test","originalPath","replace","split","map","num","parseInt","filename","dimensions","width","height","STORYBLOK_BASE_URL","sizeMultipliersFixed","sizeMultipliersFluid","defaultOptions","quality","smartCrop","format","fill","toFormat","useBase64","defaultFluidOptions","Object","maxWidth","maxHeight","defaultFixedOptions","isWebP","isConverted","includes","isOriginal","buildImageUrl","filters","filter","element","Boolean","length","reduce","acc","currentFilter","i","applyFilters","args","imageProps","options","desiredAspectRatio","aspectRatio","forceConvert","srcSets","scale","Math","round","currentWidth","resolution","currentHeight","size","webpUrl","buildUrl","baseUrl","webp","push","base","outputHeight","imgSize","src","srcWebp","srcSet","join","srcSetWebp","sizes","concat"],"mappings":"0LAAAA,IAAMC,EAAuB,wFAE7B,SAASC,EAAmBC,OACtBC,EAAM,KACNC,EAAO,QAEU,iBAAVF,IACTC,EAAMD,GAGa,iBAAVA,IACTC,EAAMD,EAAMA,MACZE,EAAOF,EAAMG,OAASH,EAAMG,OAAS,QAGvCF,EAAMH,EAAqBM,KAAKH,GAAOA,EAAM,aAGpC,MAILI,EAAeJ,EAAIK,QADA,mCACwB,MAEZD,EAAaE,MAAM,mBACrBA,MAAM,KAAKC,aAAIC,UAAOC,SAASD,EAAK,0BAM9D,cACLJ,YANkBM,EAASJ,MAAM,iBAGpB,CAAEK,WAAY,OAAEC,SAAOC,cADpBD,EAAQC,QACmCZ,IC7BxDL,IAEMkB,EAAqB,6BAErBC,EAAuB,CAAC,EAAG,IAAK,EAAG,GACnCC,EAAuB,CAAC,IAAM,GAAK,EAAG,IAAK,EAAG,GAE9CC,EAAiB,CAC5BC,QAAS,IACTC,WAAW,EACXC,OAAQ,KACRC,KAAM,KACNC,SAAU,KACVpB,OAAQ,KACRqB,WAAW,GAGAC,EAAsBC,iBAC9BR,GACHS,SAlBqC,IAmBrCC,U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BAChCqB,EACAW,GACErC,OAAQ6B,YAGfT,EAAIqB,KAAKC,KAAQJ,MAAWJ,OAC5Bd,EAAIuB,KAAKD,KAAQF,MAAWN,OACrBd,GAzBG,CAAEqB,KAAM,GAAIE,KAAM,KA4B5BE,EAAU,CAAErD,MAAOc,EAAUb,OAAQc,GAErCuC,EAAMP,EAASvD,EAAcqB,iBAC5BqB,EACAmB,GACE7C,OAAQ6B,KAGXkB,EAAUR,EAASvD,EAAcqB,iBAChCqB,EACAmB,GACE7C,OAAQ,gBAGR,CACLlB,OAAQqB,EAAYrB,GAAUD,EAAO,KACrC+C,YAAaD,MACbmB,UACAC,EACAC,OAAQlB,EAAQa,KAAKM,KAAK,QAAU,KACpCC,WAAYpB,EAAQW,KAAKQ,KAAK,QAAU,WACxCE"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 38c885b..59efa7d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gatsby-storyblok-image", - "version": "0.2.2", + "version": "0.2.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index de15900..82791e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gatsby-storyblok-image", - "version": "0.2.2", + "version": "0.2.3", "description": "Adds gatsby-image to Gatsby & Storyblok as a content source.", "source": "src/index.js", "main": "dist/index.js",