@burst/imagekit
Advanced tools
| interface DrupalImageField { | ||
| url?: null | string; | ||
| alt?: null | string; | ||
| width?: null | number; | ||
| height?: null | number; | ||
| entity?: null | { | ||
| url?: null | string; | ||
| focalPoint?: null | { | ||
| x?: null | number; | ||
| y?: null | number; | ||
| }; | ||
| }; | ||
| } | ||
| export declare type ImagekitSrc = string | DrupalImageField; | ||
| interface ParsedSource { | ||
| url?: string; | ||
| width?: number; | ||
| height?: number; | ||
| x?: number; | ||
| y?: number; | ||
| } | ||
| export declare function parseSource(src: ImagekitSrc): ParsedSource; | ||
| export {}; |
@@ -0,1 +1,2 @@ | ||
| import { ImagekitSrc } from './parse-source'; | ||
| interface Transformations { | ||
@@ -40,18 +41,4 @@ /** | ||
| } | ||
| interface DrupalImageField { | ||
| url?: null | string; | ||
| width?: null | number; | ||
| height?: null | number; | ||
| entity?: null | { | ||
| focalPoint?: null | { | ||
| x?: null | number; | ||
| y?: null | number; | ||
| }; | ||
| }; | ||
| } | ||
| export interface Options { | ||
| src: string | (DrupalImageField & { | ||
| entity?: DrupalImageField | null; | ||
| alt?: string | null; | ||
| }); | ||
| src: ImagekitSrc; | ||
| transformations?: Transformations | Transformations[]; | ||
@@ -58,0 +45,0 @@ } |
@@ -42,2 +42,20 @@ 'use strict'; | ||
| function parseSource(src) { | ||
| var _src$entity, _src$entity2, _src$entity2$focalPoi, _src$entity3, _src$entity3$focalPoi; | ||
| if (typeof src === 'string') { | ||
| return { | ||
| url: src | ||
| }; | ||
| } | ||
| return { | ||
| url: (src === null || src === void 0 ? void 0 : (_src$entity = src.entity) === null || _src$entity === void 0 ? void 0 : _src$entity.url) || (src === null || src === void 0 ? void 0 : src.url) || undefined, | ||
| width: (src === null || src === void 0 ? void 0 : src.width) || undefined, | ||
| height: (src === null || src === void 0 ? void 0 : src.height) || undefined, | ||
| x: (src === null || src === void 0 ? void 0 : (_src$entity2 = src.entity) === null || _src$entity2 === void 0 ? void 0 : (_src$entity2$focalPoi = _src$entity2.focalPoint) === null || _src$entity2$focalPoi === void 0 ? void 0 : _src$entity2$focalPoi.x) || undefined, | ||
| y: ((_src$entity3 = src.entity) === null || _src$entity3 === void 0 ? void 0 : (_src$entity3$focalPoi = _src$entity3.focalPoint) === null || _src$entity3$focalPoi === void 0 ? void 0 : _src$entity3$focalPoi.y) || undefined | ||
| }; | ||
| } | ||
| function createImagekitTransformationsParameters(transformations) { | ||
@@ -116,7 +134,6 @@ var parameters = []; | ||
| function createImagekitUrl(options) { | ||
| var _drupalImageField$ent, _drupalImageField$ent2, _drupalImageField$ent3, _drupalImageField$ent4; | ||
| var _parseSource = parseSource(options.src), | ||
| src = _parseSource.url, | ||
| focalPoint = _objectWithoutPropertiesLoose(_parseSource, ["url"]); | ||
| var drupalImageField = getDrupalImageField(options.src); | ||
| var src = drupalImageField === null || drupalImageField === void 0 ? void 0 : drupalImageField.url; | ||
| if (!src) { | ||
@@ -131,8 +148,2 @@ throw new Error('You need to provide either an image trough the "src" option, or provide an image with an "url" property.'); | ||
| var originalTransformations = Array.isArray(options.transformations) ? options.transformations : [options.transformations]; | ||
| var focalPoint = drupalImageField && { | ||
| width: drupalImageField.width, | ||
| height: drupalImageField.height, | ||
| x: (_drupalImageField$ent = drupalImageField.entity) === null || _drupalImageField$ent === void 0 ? void 0 : (_drupalImageField$ent2 = _drupalImageField$ent.focalPoint) === null || _drupalImageField$ent2 === void 0 ? void 0 : _drupalImageField$ent2.x, | ||
| y: (_drupalImageField$ent3 = drupalImageField.entity) === null || _drupalImageField$ent3 === void 0 ? void 0 : (_drupalImageField$ent4 = _drupalImageField$ent3.focalPoint) === null || _drupalImageField$ent4 === void 0 ? void 0 : _drupalImageField$ent4.y | ||
| }; | ||
@@ -172,12 +183,2 @@ if ((focalPoint === null || focalPoint === void 0 ? void 0 : focalPoint.x) && focalPoint.y && focalPoint.width && focalPoint.height) { | ||
| function getDrupalImageField(f) { | ||
| var _f$entity, _f$entity$entity; | ||
| if (typeof f === 'string') return { | ||
| url: f | ||
| }; | ||
| if ((_f$entity = f.entity) === null || _f$entity === void 0 ? void 0 : (_f$entity$entity = _f$entity.entity) === null || _f$entity$entity === void 0 ? void 0 : _f$entity$entity.focalPoint) return f.entity; | ||
| return f; | ||
| } | ||
| function ImagekitImage(props) { | ||
@@ -184,0 +185,0 @@ var _props$breakpoints, _props$breakpoints2; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"imagekit.cjs.development.js","sources":["../src/create-imagekit-url.ts","../src/imagekit-image.tsx"],"sourcesContent":["interface Transformations {\n /**\n * Width -\n * Used to specify the width of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, it acts as a\n * percentage width. Therefore, 0.1 means 10% of the original width, 0.4\n * means 40% of the original width, and so on.\n */\n w?: number;\n\n /**\n * Height -\n * Used to specify the height of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, the value acts as\n * a percentage height. Therefore, 0.1 means 10% of the original height, 0.4\n * means 40% of the original height, and so on.\n */\n h?: number;\n\n /**\n * Aspect ratio -\n * Used to specify the aspect ratio of the output image or the ratio of width\n * to height of the output image. This parameter must be used along with\n * either the height(h) or width(w) parameter. The format for specifying this\n * transformation is ar-<width>-<height>\n */\n ar?: number;\n\n /**\n * Crop Mode -\n * If only, one of the height(h) or width(w) dimension is specified, then\n * ImageKit.io adjusts the other dimension accordingly to preserve aspect\n * ratio and no cropping takes place.\n * But when you specify both height(h) and width(w) dimension, you need to\n * choose the right cropping strategy based on your website layout and desired\n * output image.\n */\n cm?:\n | 'pad_resize'\n | 'force'\n | 'at_max'\n | 'at_least'\n | 'maintain_ratio' // Default cropping\n | 'extract'\n | 'pad_extract';\n\n fo?: 'default' | 'auto' | 'face';\n\n xc?: number;\n yc?: number;\n}\n\ninterface DrupalImageField {\n url?: null | string;\n width?: null | number;\n height?: null | number;\n entity?: null | {\n focalPoint?: null | {\n x?: null | number;\n y?: null | number;\n };\n };\n}\n\nexport interface Options {\n src:\n | string\n | (DrupalImageField & {\n entity?: DrupalImageField | null;\n alt?: string | null;\n });\n transformations?: Transformations | Transformations[];\n}\n\nfunction createImagekitTransformationsParameters(\n transformations: Transformations,\n) {\n const parameters = [];\n const { w, h } = calculateDimensions(transformations);\n if (w) {\n parameters.push(`w-${Math.round(w)}`);\n }\n if (h) {\n parameters.push(`h-${Math.round(h)}`);\n }\n const { cm } = transformations;\n if (cm && cm !== 'maintain_ratio') {\n parameters.push(\n `${['pad_resize', 'extract', 'pad_extract'].includes(cm) ? 'cm' : 'c'}-${\n transformations.cm\n }`,\n );\n }\n if (transformations.fo && transformations.fo !== 'default') {\n parameters.push(`fo-${transformations.fo}`);\n }\n if (transformations.xc) {\n parameters.push(`xc-${transformations.xc}`);\n }\n if (transformations.yc) {\n parameters.push(`yc-${transformations.yc}`);\n }\n\n return parameters.length ? parameters.join(',') : null;\n}\n\nexport function calculateDimensions({\n w,\n h,\n ar,\n}: {\n w?: number;\n h?: number;\n ar?: number;\n}): { w: number | undefined; h: number | undefined; ar: number | undefined } {\n if (\n (typeof w === typeof h && typeof h === typeof ar) ||\n (!ar && typeof w !== typeof h)\n )\n return { w, h, ar };\n\n if (w && h) {\n return { w, h, ar: w / h };\n }\n if (w && ar) {\n return { w, h: w / ar, ar };\n }\n if (h && ar) {\n return { w: h * ar, h, ar };\n }\n\n throw new Error(\n 'Make sure that if \"ar\" is set, that you also set \"w\" or \"h\".',\n );\n}\n\nexport function createImagekitUrl(options: Options) {\n const drupalImageField = getDrupalImageField(options.src);\n const src = drupalImageField?.url;\n if (!src) {\n throw new Error(\n 'You need to provide either an image trough the \"src\" option, or provide an image with an \"url\" property.',\n );\n }\n if (!options.transformations) {\n return src;\n }\n\n let originalTransformations = Array.isArray(options.transformations)\n ? options.transformations\n : [options.transformations];\n\n const focalPoint = drupalImageField && {\n width: drupalImageField.width,\n height: drupalImageField.height,\n x: drupalImageField.entity?.focalPoint?.x,\n y: drupalImageField.entity?.focalPoint?.y,\n };\n\n if (focalPoint?.x && focalPoint.y && focalPoint.width && focalPoint.height) {\n const targetDimensions = calculateDimensions(originalTransformations[0]);\n if (targetDimensions.ar) {\n // We need to make the smallest crop - we calculate the dimensions on both\n // the width and height as source, and take the smallest one.\n const sourceDimensionsCropW = calculateDimensions({\n ar: targetDimensions.ar,\n w: focalPoint.width,\n });\n const sourceDimensionsCropH = calculateDimensions({\n ar: targetDimensions.ar,\n h: focalPoint.height,\n });\n const sourceDimensionsCrop =\n sourceDimensionsCropW.h! < sourceDimensionsCropH.h!\n ? sourceDimensionsCropW\n : sourceDimensionsCropH;\n\n originalTransformations = [\n {\n ...sourceDimensionsCrop,\n cm: 'extract',\n xc: containWithinBoundary(\n focalPoint.width,\n focalPoint.x,\n sourceDimensionsCrop.w!,\n ),\n yc: containWithinBoundary(\n focalPoint.height,\n focalPoint.y,\n sourceDimensionsCrop.h!,\n ),\n },\n ...originalTransformations,\n ];\n }\n }\n\n const transformations = originalTransformations\n .map(createImagekitTransformationsParameters)\n .filter(s => s)\n .join(':');\n\n return transformations ? `${src}?tr=${transformations}` : src;\n}\n\nexport function containWithinBoundary(\n srcSize: number,\n focalCenter: number,\n targetSize: number,\n) {\n if (srcSize === targetSize) return undefined;\n return Math.min(\n Math.max(targetSize / 2, focalCenter),\n srcSize - targetSize / 2,\n );\n}\n\nfunction getDrupalImageField(\n f: string | (DrupalImageField & { entity?: DrupalImageField | null }),\n): DrupalImageField {\n if (typeof f === 'string') return { url: f };\n if (f.entity?.entity?.focalPoint) return f.entity;\n return f;\n}\n","/* eslint-disable no-param-reassign, jsx-a11y/alt-text */\nimport React, { ComponentPropsWithRef } from 'react';\nimport {\n calculateDimensions,\n createImagekitUrl,\n Options,\n} from './create-imagekit-url';\n\ninterface SizeTransformations {\n w?: number;\n h?: number;\n ar?: number;\n}\n\ntype BreakpointSetting =\n | number\n | [number, SizeTransformations | number]\n | SizeTransformations;\n\ninterface Props extends Omit<ComponentPropsWithRef<'img'>, 'src'> {\n src: Options['src'];\n breakpoints?: BreakpointSetting[];\n aspectRatio?: number;\n transformations?: Options['transformations'];\n}\n\nexport function ImagekitImage(props: Props) {\n const { src, transformations, breakpoints, aspectRatio, ...imgProps } = props;\n\n // If there are no breakpoints or an srcSet has already been provided, there\n // is nothing special we can do here. Just return an img component.\n if (!props.breakpoints?.length || props.srcSet) {\n return (\n <img src={createImagekitUrl({ src, transformations })} {...imgProps} />\n );\n }\n\n const imgSources: {\n // Used as key of this source.\n ar: number | undefined;\n\n // Used to calculate the props.\n minMax: { min?: number; max?: number }[];\n breakpoints: NormalizedBreakpoint[];\n\n // Calculated props.\n srcSet?: string;\n sizes?: string;\n media?: string;\n }[] = [];\n\n let largestImageUrl: [number, string] | null = null;\n\n if (props.breakpoints?.length && !props.srcSet) {\n const normalizedBreakpoints = props.breakpoints\n .map(normalizeBreakpoint)\n .map(b => {\n // If no ar was provided, use the aspectRatio prop.\n const sizes = { ar: props.aspectRatio, ...b[1] };\n\n // If there is an aspectRatio but no width, use the maxWidth as image\n // width.\n if (!sizes.h && !sizes.w && sizes.ar) {\n // eslint-disable-next-line prefer-destructuring\n sizes.w = b[0];\n }\n\n // Now calculate the final dimensions.\n const dimensions = calculateDimensions(sizes);\n\n // If no maxWidth was given and there was only a height and aspect ratio\n // available, we use the calculated w dimension as maxWidth.\n return [b[0] || dimensions.w, dimensions] as const;\n });\n\n normalizedBreakpoints.forEach(([maxWidth, sizes], i) => {\n // Set up the new image source.\n let set = imgSources.find(s => s.ar === sizes.ar);\n if (!set) {\n set = {\n ar: sizes.ar,\n minMax: [],\n breakpoints: [],\n };\n imgSources.push(set);\n }\n set.breakpoints.push([maxWidth, sizes]);\n\n // If the previous breakpoint has another aspect ratio, this is a new\n // source. This means that the min-width of this source is one pixel more\n // as the max-width of the previous source (which is the previous\n // breakpoint).\n const previousBreakpoint = normalizedBreakpoints[i - 1];\n if (!previousBreakpoint || previousBreakpoint[1].ar !== sizes.ar) {\n set.minMax.push({\n min: previousBreakpoint?.[0] ? previousBreakpoint[0] + 1 : undefined,\n });\n }\n\n // Set the max-width (will be overwritten until the last max-width of this\n // source).\n set.minMax[set.minMax.length - 1].max = maxWidth;\n });\n\n if (!imgSources.length) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).',\n );\n }\n\n // To make sure that the largest image is always shown, we remove the last\n // maxWidth on the source containing the last breakpoint.\n const largestSource = imgSources.find(\n source =>\n source.ar ===\n normalizedBreakpoints[normalizedBreakpoints.length - 1][1].ar,\n );\n if (largestSource) {\n delete largestSource.minMax[largestSource.minMax.length - 1].max;\n }\n\n imgSources.forEach((source, si) => {\n // Now, calculate the srcSet of every source.\n source.srcSet = source.breakpoints\n .map(([, sizes]) => {\n const imagekitUrlBreakpoint = createImagekitUrl({\n src,\n transformations: [\n ...(Array.isArray(transformations)\n ? transformations\n : transformations\n ? [transformations]\n : []),\n sizes,\n ],\n });\n\n if (sizes.w && (!largestImageUrl || largestImageUrl[0] < sizes.w)) {\n largestImageUrl = [sizes.w, imagekitUrlBreakpoint];\n }\n\n return `${imagekitUrlBreakpoint} ${sizes.w}w`;\n })\n .join(', ');\n\n // Calculate the sizes of every source.\n source.sizes =\n (source.breakpoints.length >= 2 &&\n !source.breakpoints.every(s => s[0] === s[1].w) &&\n source.breakpoints\n .map(([, sizes], i) => {\n const previousBreakpoint = source.breakpoints[i - 1];\n if (!previousBreakpoint || !previousBreakpoint[0]) {\n return `${sizes.w}px`;\n }\n return `(min-width: ${previousBreakpoint[0] + 1}px) ${sizes.w}px`;\n })\n .reverse()\n .join(', ')) ||\n '100vw';\n\n // Calculate the media prop of all sources.\n // If it's the first item, it will always be rendered. So there is no need\n // for a media query then.\n // If there is only one item in the minMax (there should be at least one)\n // then we only need to print it if it has a 'min'.\n if (si > 0 && (source.minMax.length > 1 || source.minMax[0].min)) {\n source.media = source.minMax\n .map(({ min, max }) =>\n min && max\n ? `(min-width: ${min}px) and (max-width: ${max}px)`\n : min\n ? `(min-width: ${min}px)`\n : `(max-width: ${max}px)`,\n )\n .join(', ');\n }\n });\n }\n\n if (!largestImageUrl) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.',\n );\n }\n\n // If there is just one source, we can do everything in one img element.\n if (imgSources.length === 1) {\n return (\n <img\n src={largestImageUrl[1]}\n srcSet={imgSources[0].srcSet}\n sizes={imgSources[0].sizes}\n {...imgProps}\n />\n );\n }\n\n // If it's more then one source, we will render a picture element. We need the\n // largest imgSource on top.\n imgSources.reverse();\n\n return (\n <picture>\n {imgSources.map(source => (\n <source\n key={source.ar || 'original'}\n media={source.media}\n srcSet={source.srcSet}\n sizes={source.sizes}\n />\n ))}\n <img\n src={largestImageUrl[1]}\n alt={(typeof props.src !== 'string' && props.src.alt) || undefined}\n {...imgProps}\n />\n </picture>\n );\n}\n\ntype NormalizedBreakpoint = [number | undefined, SizeTransformations];\n\nfunction normalizeBreakpoint(\n breakpoint: BreakpointSetting,\n): NormalizedBreakpoint {\n return typeof breakpoint === 'number'\n ? [breakpoint, { w: breakpoint }]\n : Array.isArray(breakpoint)\n ? [\n breakpoint[0],\n typeof breakpoint[1] === 'number'\n ? { w: breakpoint[1] }\n : breakpoint[1],\n ]\n : [breakpoint.w, breakpoint];\n}\n"],"names":["createImagekitTransformationsParameters","transformations","parameters","calculateDimensions","w","h","push","Math","round","cm","includes","fo","xc","yc","length","join","ar","Error","createImagekitUrl","options","drupalImageField","getDrupalImageField","src","url","originalTransformations","Array","isArray","focalPoint","width","height","x","entity","y","targetDimensions","sourceDimensionsCropW","sourceDimensionsCropH","sourceDimensionsCrop","containWithinBoundary","map","filter","s","srcSize","focalCenter","targetSize","undefined","min","max","f","ImagekitImage","props","breakpoints","imgProps","srcSet","React","imgSources","largestImageUrl","normalizedBreakpoints","normalizeBreakpoint","b","sizes","aspectRatio","dimensions","forEach","i","maxWidth","set","find","minMax","previousBreakpoint","largestSource","source","si","imagekitUrlBreakpoint","every","reverse","media","key","alt","breakpoint"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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M,EAAEkB,MAAM,CAAClB;AACfO,MAAAA,KAAK,EAAEW,MAAM,CAACX;KAJhB,CADoB;AAAA,GAArB,CADH,EASEN,mBAAA,MAAA;AACE/B,IAAAA,GAAG,EAAEiC,eAAe,CAAC,CAAD;AACpBsB,IAAAA,GAAG,EAAG,OAAO5B,KAAK,CAAC3B,GAAb,KAAqB,QAArB,IAAiC2B,KAAK,CAAC3B,GAAN,CAAUuD,GAA5C,IAAoDjC;KACrDO,SAHN,CATF,CADF;AAiBD;;AAID,SAASM,mBAAT,CACEqB,UADF;AAGE,SAAO,OAAOA,UAAP,KAAsB,QAAtB,GACH,CAACA,UAAD,EAAa;AAAE1E,IAAAA,CAAC,EAAE0E;AAAL,GAAb,CADG,GAEHrD,KAAK,CAACC,OAAN,CAAcoD,UAAd,IACA,CACEA,UAAU,CAAC,CAAD,CADZ,EAEE,OAAOA,UAAU,CAAC,CAAD,CAAjB,KAAyB,QAAzB,GACI;AAAE1E,IAAAA,CAAC,EAAE0E,UAAU,CAAC,CAAD;AAAf,GADJ,GAEIA,UAAU,CAAC,CAAD,CAJhB,CADA,GAOA,CAACA,UAAU,CAAC1E,CAAZ,EAAe0E,UAAf,CATJ;AAUD;;;;;"} | ||
| {"version":3,"file":"imagekit.cjs.development.js","sources":["../src/parse-source.ts","../src/create-imagekit-url.ts","../src/imagekit-image.tsx"],"sourcesContent":["interface DrupalImageField {\n url?: null | string;\n alt?: null | string;\n width?: null | number;\n height?: null | number;\n entity?: null | {\n url?: null | string;\n focalPoint?: null | {\n x?: null | number;\n y?: null | number;\n };\n };\n}\n\nexport type ImagekitSrc = string | DrupalImageField;\n\ninterface ParsedSource {\n url?: string;\n width?: number;\n height?: number;\n x?: number;\n y?: number;\n}\n\nexport function parseSource(src: ImagekitSrc): ParsedSource {\n if (typeof src === 'string') {\n return { url: src };\n }\n return {\n url: src?.entity?.url || src?.url || undefined,\n width: src?.width || undefined,\n height: src?.height || undefined,\n x: src?.entity?.focalPoint?.x || undefined,\n y: src.entity?.focalPoint?.y || undefined,\n };\n}\n","import { ImagekitSrc, parseSource } from './parse-source';\n\ninterface Transformations {\n /**\n * Width -\n * Used to specify the width of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, it acts as a\n * percentage width. Therefore, 0.1 means 10% of the original width, 0.4\n * means 40% of the original width, and so on.\n */\n w?: number;\n\n /**\n * Height -\n * Used to specify the height of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, the value acts as\n * a percentage height. Therefore, 0.1 means 10% of the original height, 0.4\n * means 40% of the original height, and so on.\n */\n h?: number;\n\n /**\n * Aspect ratio -\n * Used to specify the aspect ratio of the output image or the ratio of width\n * to height of the output image. This parameter must be used along with\n * either the height(h) or width(w) parameter. The format for specifying this\n * transformation is ar-<width>-<height>\n */\n ar?: number;\n\n /**\n * Crop Mode -\n * If only, one of the height(h) or width(w) dimension is specified, then\n * ImageKit.io adjusts the other dimension accordingly to preserve aspect\n * ratio and no cropping takes place.\n * But when you specify both height(h) and width(w) dimension, you need to\n * choose the right cropping strategy based on your website layout and desired\n * output image.\n */\n cm?:\n | 'pad_resize'\n | 'force'\n | 'at_max'\n | 'at_least'\n | 'maintain_ratio' // Default cropping\n | 'extract'\n | 'pad_extract';\n\n fo?: 'default' | 'auto' | 'face';\n\n xc?: number;\n yc?: number;\n}\n\nexport interface Options {\n src: ImagekitSrc;\n transformations?: Transformations | Transformations[];\n}\n\nfunction createImagekitTransformationsParameters(\n transformations: Transformations,\n) {\n const parameters = [];\n const { w, h } = calculateDimensions(transformations);\n if (w) {\n parameters.push(`w-${Math.round(w)}`);\n }\n if (h) {\n parameters.push(`h-${Math.round(h)}`);\n }\n const { cm } = transformations;\n if (cm && cm !== 'maintain_ratio') {\n parameters.push(\n `${['pad_resize', 'extract', 'pad_extract'].includes(cm) ? 'cm' : 'c'}-${\n transformations.cm\n }`,\n );\n }\n if (transformations.fo && transformations.fo !== 'default') {\n parameters.push(`fo-${transformations.fo}`);\n }\n if (transformations.xc) {\n parameters.push(`xc-${transformations.xc}`);\n }\n if (transformations.yc) {\n parameters.push(`yc-${transformations.yc}`);\n }\n\n return parameters.length ? parameters.join(',') : null;\n}\n\nexport function calculateDimensions({\n w,\n h,\n ar,\n}: {\n w?: number;\n h?: number;\n ar?: number;\n}): { w: number | undefined; h: number | undefined; ar: number | undefined } {\n if (\n (typeof w === typeof h && typeof h === typeof ar) ||\n (!ar && typeof w !== typeof h)\n )\n return { w, h, ar };\n\n if (w && h) {\n return { w, h, ar: w / h };\n }\n if (w && ar) {\n return { w, h: w / ar, ar };\n }\n if (h && ar) {\n return { w: h * ar, h, ar };\n }\n\n throw new Error(\n 'Make sure that if \"ar\" is set, that you also set \"w\" or \"h\".',\n );\n}\n\nexport function createImagekitUrl(options: Options) {\n const { url: src, ...focalPoint } = parseSource(options.src);\n if (!src) {\n throw new Error(\n 'You need to provide either an image trough the \"src\" option, or provide an image with an \"url\" property.',\n );\n }\n if (!options.transformations) {\n return src;\n }\n\n let originalTransformations = Array.isArray(options.transformations)\n ? options.transformations\n : [options.transformations];\n\n if (focalPoint?.x && focalPoint.y && focalPoint.width && focalPoint.height) {\n const targetDimensions = calculateDimensions(originalTransformations[0]);\n if (targetDimensions.ar) {\n // We need to make the smallest crop - we calculate the dimensions on both\n // the width and height as source, and take the smallest one.\n const sourceDimensionsCropW = calculateDimensions({\n ar: targetDimensions.ar,\n w: focalPoint.width,\n });\n const sourceDimensionsCropH = calculateDimensions({\n ar: targetDimensions.ar,\n h: focalPoint.height,\n });\n const sourceDimensionsCrop =\n sourceDimensionsCropW.h! < sourceDimensionsCropH.h!\n ? sourceDimensionsCropW\n : sourceDimensionsCropH;\n\n originalTransformations = [\n {\n ...sourceDimensionsCrop,\n cm: 'extract',\n xc: containWithinBoundary(\n focalPoint.width,\n focalPoint.x,\n sourceDimensionsCrop.w!,\n ),\n yc: containWithinBoundary(\n focalPoint.height,\n focalPoint.y,\n sourceDimensionsCrop.h!,\n ),\n },\n ...originalTransformations,\n ];\n }\n }\n\n const transformations = originalTransformations\n .map(createImagekitTransformationsParameters)\n .filter(s => s)\n .join(':');\n\n return transformations ? `${src}?tr=${transformations}` : src;\n}\n\nexport function containWithinBoundary(\n srcSize: number,\n focalCenter: number,\n targetSize: number,\n) {\n if (srcSize === targetSize) return undefined;\n return Math.min(\n Math.max(targetSize / 2, focalCenter),\n srcSize - targetSize / 2,\n );\n}\n","/* eslint-disable no-param-reassign, jsx-a11y/alt-text */\nimport React, { ComponentPropsWithRef } from 'react';\nimport {\n calculateDimensions,\n createImagekitUrl,\n Options,\n} from './create-imagekit-url';\n\ninterface SizeTransformations {\n w?: number;\n h?: number;\n ar?: number;\n}\n\ntype BreakpointSetting =\n | number\n | [number, SizeTransformations | number]\n | SizeTransformations;\n\ninterface Props extends Omit<ComponentPropsWithRef<'img'>, 'src'> {\n src: Options['src'];\n breakpoints?: BreakpointSetting[];\n aspectRatio?: number;\n transformations?: Options['transformations'];\n}\n\nexport function ImagekitImage(props: Props) {\n const { src, transformations, breakpoints, aspectRatio, ...imgProps } = props;\n\n // If there are no breakpoints or an srcSet has already been provided, there\n // is nothing special we can do here. Just return an img component.\n if (!props.breakpoints?.length || props.srcSet) {\n return (\n <img src={createImagekitUrl({ src, transformations })} {...imgProps} />\n );\n }\n\n const imgSources: {\n // Used as key of this source.\n ar: number | undefined;\n\n // Used to calculate the props.\n minMax: { min?: number; max?: number }[];\n breakpoints: NormalizedBreakpoint[];\n\n // Calculated props.\n srcSet?: string;\n sizes?: string;\n media?: string;\n }[] = [];\n\n let largestImageUrl: [number, string] | null = null;\n\n if (props.breakpoints?.length && !props.srcSet) {\n const normalizedBreakpoints = props.breakpoints\n .map(normalizeBreakpoint)\n .map(b => {\n // If no ar was provided, use the aspectRatio prop.\n const sizes = { ar: props.aspectRatio, ...b[1] };\n\n // If there is an aspectRatio but no width, use the maxWidth as image\n // width.\n if (!sizes.h && !sizes.w && sizes.ar) {\n // eslint-disable-next-line prefer-destructuring\n sizes.w = b[0];\n }\n\n // Now calculate the final dimensions.\n const dimensions = calculateDimensions(sizes);\n\n // If no maxWidth was given and there was only a height and aspect ratio\n // available, we use the calculated w dimension as maxWidth.\n return [b[0] || dimensions.w, dimensions] as const;\n });\n\n normalizedBreakpoints.forEach(([maxWidth, sizes], i) => {\n // Set up the new image source.\n let set = imgSources.find(s => s.ar === sizes.ar);\n if (!set) {\n set = {\n ar: sizes.ar,\n minMax: [],\n breakpoints: [],\n };\n imgSources.push(set);\n }\n set.breakpoints.push([maxWidth, sizes]);\n\n // If the previous breakpoint has another aspect ratio, this is a new\n // source. This means that the min-width of this source is one pixel more\n // as the max-width of the previous source (which is the previous\n // breakpoint).\n const previousBreakpoint = normalizedBreakpoints[i - 1];\n if (!previousBreakpoint || previousBreakpoint[1].ar !== sizes.ar) {\n set.minMax.push({\n min: previousBreakpoint?.[0] ? previousBreakpoint[0] + 1 : undefined,\n });\n }\n\n // Set the max-width (will be overwritten until the last max-width of this\n // source).\n set.minMax[set.minMax.length - 1].max = maxWidth;\n });\n\n if (!imgSources.length) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).',\n );\n }\n\n // To make sure that the largest image is always shown, we remove the last\n // maxWidth on the source containing the last breakpoint.\n const largestSource = imgSources.find(\n source =>\n source.ar ===\n normalizedBreakpoints[normalizedBreakpoints.length - 1][1].ar,\n );\n if (largestSource) {\n delete largestSource.minMax[largestSource.minMax.length - 1].max;\n }\n\n imgSources.forEach((source, si) => {\n // Now, calculate the srcSet of every source.\n source.srcSet = source.breakpoints\n .map(([, sizes]) => {\n const imagekitUrlBreakpoint = createImagekitUrl({\n src,\n transformations: [\n ...(Array.isArray(transformations)\n ? transformations\n : transformations\n ? [transformations]\n : []),\n sizes,\n ],\n });\n\n if (sizes.w && (!largestImageUrl || largestImageUrl[0] < sizes.w)) {\n largestImageUrl = [sizes.w, imagekitUrlBreakpoint];\n }\n\n return `${imagekitUrlBreakpoint} ${sizes.w}w`;\n })\n .join(', ');\n\n // Calculate the sizes of every source.\n source.sizes =\n (source.breakpoints.length >= 2 &&\n !source.breakpoints.every(s => s[0] === s[1].w) &&\n source.breakpoints\n .map(([, sizes], i) => {\n const previousBreakpoint = source.breakpoints[i - 1];\n if (!previousBreakpoint || !previousBreakpoint[0]) {\n return `${sizes.w}px`;\n }\n return `(min-width: ${previousBreakpoint[0] + 1}px) ${sizes.w}px`;\n })\n .reverse()\n .join(', ')) ||\n '100vw';\n\n // Calculate the media prop of all sources.\n // If it's the first item, it will always be rendered. So there is no need\n // for a media query then.\n // If there is only one item in the minMax (there should be at least one)\n // then we only need to print it if it has a 'min'.\n if (si > 0 && (source.minMax.length > 1 || source.minMax[0].min)) {\n source.media = source.minMax\n .map(({ min, max }) =>\n min && max\n ? `(min-width: ${min}px) and (max-width: ${max}px)`\n : min\n ? `(min-width: ${min}px)`\n : `(max-width: ${max}px)`,\n )\n .join(', ');\n }\n });\n }\n\n if (!largestImageUrl) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.',\n );\n }\n\n // If there is just one source, we can do everything in one img element.\n if (imgSources.length === 1) {\n return (\n <img\n src={largestImageUrl[1]}\n srcSet={imgSources[0].srcSet}\n sizes={imgSources[0].sizes}\n {...imgProps}\n />\n );\n }\n\n // If it's more then one source, we will render a picture element. We need the\n // largest imgSource on top.\n imgSources.reverse();\n\n return (\n <picture>\n {imgSources.map(source => (\n <source\n key={source.ar || 'original'}\n media={source.media}\n srcSet={source.srcSet}\n sizes={source.sizes}\n />\n ))}\n <img\n src={largestImageUrl[1]}\n alt={(typeof props.src !== 'string' && props.src.alt) || undefined}\n {...imgProps}\n />\n </picture>\n );\n}\n\ntype NormalizedBreakpoint = [number | undefined, SizeTransformations];\n\nfunction normalizeBreakpoint(\n breakpoint: BreakpointSetting,\n): NormalizedBreakpoint {\n return typeof breakpoint === 'number'\n ? [breakpoint, { w: breakpoint }]\n : Array.isArray(breakpoint)\n ? [\n breakpoint[0],\n typeof breakpoint[1] === 'number'\n ? { w: breakpoint[1] }\n : breakpoint[1],\n ]\n : [breakpoint.w, breakpoint];\n}\n"],"names":["parseSource","src","url","entity","undefined","width","height","x","focalPoint","y","createImagekitTransformationsParameters","transformations","parameters","calculateDimensions","w","h","push","Math","round","cm","includes","fo","xc","yc","length","join","ar","Error","createImagekitUrl","options","originalTransformations","Array","isArray","targetDimensions","sourceDimensionsCropW","sourceDimensionsCropH","sourceDimensionsCrop","containWithinBoundary","map","filter","s","srcSize","focalCenter","targetSize","min","max","ImagekitImage","props","breakpoints","imgProps","srcSet","React","imgSources","largestImageUrl","normalizedBreakpoints","normalizeBreakpoint","b","sizes","aspectRatio","dimensions","forEach","i","maxWidth","set","find","minMax","previousBreakpoint","largestSource","source","si","imagekitUrlBreakpoint","every","reverse","media","key","alt","breakpoint"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAwBgBA,YAAYC;;;AAC1B,MAAI,OAAOA,GAAP,KAAe,QAAnB,EAA6B;AAC3B,WAAO;AAAEC,MAAAA,GAAG,EAAED;AAAP,KAAP;AACD;;AACD,SAAO;AACLC,IAAAA,GAAG,EAAE,CAAAD,GAAG,SAAH,IAAAA,GAAG,WAAH,2BAAAA,GAAG,CAAEE,MAAL,4DAAaD,GAAb,MAAoBD,GAApB,aAAoBA,GAApB,uBAAoBA,GAAG,CAAEC,GAAzB,KAAgCE,SADhC;AAELC,IAAAA,KAAK,EAAE,CAAAJ,GAAG,SAAH,IAAAA,GAAG,WAAH,YAAAA,GAAG,CAAEI,KAAL,KAAcD,SAFhB;AAGLE,IAAAA,MAAM,EAAE,CAAAL,GAAG,SAAH,IAAAA,GAAG,WAAH,YAAAA,GAAG,CAAEK,MAAL,KAAeF,SAHlB;AAILG,IAAAA,CAAC,EAAE,CAAAN,GAAG,SAAH,IAAAA,GAAG,WAAH,4BAAAA,GAAG,CAAEE,MAAL,uFAAaK,UAAb,gFAAyBD,CAAzB,KAA8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,KAAyB,QAAzB,GACI;AAAE9D,IAAAA,CAAC,EAAE8D,UAAU,CAAC,CAAD;AAAf,GADJ,GAEIA,UAAU,CAAC,CAAD,CAJhB,CADA,GAOA,CAACA,UAAU,CAAC9D,CAAZ,EAAe8D,UAAf,CATJ;AAUD;;;;;"} |
@@ -1,2 +0,2 @@ | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r,t=(r=require("react"))&&"object"==typeof r&&"default"in r?r.default:r;function e(){return(e=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}function n(r){var t=[],e=a(r),n=e.w,i=e.h;n&&t.push("w-"+Math.round(n)),i&&t.push("h-"+Math.round(i));var o=r.cm;return o&&"maintain_ratio"!==o&&t.push((["pad_resize","extract","pad_extract"].includes(o)?"cm":"c")+"-"+r.cm),r.fo&&"default"!==r.fo&&t.push("fo-"+r.fo),r.xc&&t.push("xc-"+r.xc),r.yc&&t.push("yc-"+r.yc),t.length?t.join(","):null}function a(r){var t=r.w,e=r.h,n=r.ar;if(typeof t==typeof e&&typeof e==typeof n||!n&&typeof t!=typeof e)return{w:t,h:e,ar:n};if(t&&e)return{w:t,h:e,ar:t/e};if(t&&n)return{w:t,h:t/n,ar:n};if(e&&n)return{w:e*n,h:e,ar:n};throw new Error('Make sure that if "ar" is set, that you also set "w" or "h".')}function i(r){var t,i,s,u,c,h,l,f="string"==typeof(c=r.src)?{url:c}:(null===(h=c.entity)||void 0===h||null===(l=h.entity)||void 0===l?void 0:l.focalPoint)?c.entity:c,p=null==f?void 0:f.url;if(!p)throw new Error('You need to provide either an image trough the "src" option, or provide an image with an "url" property.');if(!r.transformations)return p;var m=Array.isArray(r.transformations)?r.transformations:[r.transformations],d=f&&{width:f.width,height:f.height,x:null===(t=f.entity)||void 0===t||null===(i=t.focalPoint)||void 0===i?void 0:i.x,y:null===(s=f.entity)||void 0===s||null===(u=s.focalPoint)||void 0===u?void 0:u.y};if((null==d?void 0:d.x)&&d.y&&d.width&&d.height){var v=a(m[0]);if(v.ar){var w=a({ar:v.ar,w:d.width}),y=a({ar:v.ar,h:d.height}),g=w.h<y.h?w:y;m=[e({},g,{cm:"extract",xc:o(d.width,d.x,g.w),yc:o(d.height,d.y,g.h)})].concat(m)}}var x=m.map(n).filter((function(r){return r})).join(":");return x?p+"?tr="+x:p}function o(r,t,e){if(r!==e)return Math.min(Math.max(e/2,t),r-e/2)}function s(r){return"number"==typeof r?[r,{w:r}]:Array.isArray(r)?[r[0],"number"==typeof r[1]?{w:r[1]}:r[1]]:[r.w,r]}exports.ImagekitImage=function(r){var n,o,u=r.src,c=r.transformations,h=function(r,t){if(null==r)return{};var e,n,a={},i=Object.keys(r);for(n=0;n<i.length;n++)t.indexOf(e=i[n])>=0||(a[e]=r[e]);return a}(r,["src","transformations","breakpoints","aspectRatio"]);if(!(null===(n=r.breakpoints)||void 0===n?void 0:n.length)||r.srcSet)return t.createElement("img",Object.assign({src:i({src:u,transformations:c})},h));var l=[],f=null;if((null===(o=r.breakpoints)||void 0===o?void 0:o.length)&&!r.srcSet){var p=r.breakpoints.map(s).map((function(t){var n=e({ar:r.aspectRatio},t[1]);n.h||n.w||!n.ar||(n.w=t[0]);var i=a(n);return[t[0]||i.w,i]}));if(p.forEach((function(r,t){var e=r[0],n=r[1],a=l.find((function(r){return r.ar===n.ar}));a||l.push(a={ar:n.ar,minMax:[],breakpoints:[]}),a.breakpoints.push([e,n]);var i=p[t-1];i&&i[1].ar===n.ar||a.minMax.push({min:(null==i?void 0:i[0])?i[0]+1:void 0}),a.minMax[a.minMax.length-1].max=e})),!l.length)throw new Error("Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).");var m=l.find((function(r){return r.ar===p[p.length-1][1].ar}));m&&delete m.minMax[m.minMax.length-1].max,l.forEach((function(r,t){r.srcSet=r.breakpoints.map((function(r){var t=r[1],e=i({src:u,transformations:[].concat(Array.isArray(c)?c:c?[c]:[],[t])});return t.w&&(!f||f[0]<t.w)&&(f=[t.w,e]),e+" "+t.w+"w"})).join(", "),r.sizes=r.breakpoints.length>=2&&!r.breakpoints.every((function(r){return r[0]===r[1].w}))&&r.breakpoints.map((function(t,e){var n=t[1],a=r.breakpoints[e-1];return a&&a[0]?"(min-width: "+(a[0]+1)+"px) "+n.w+"px":n.w+"px"})).reverse().join(", ")||"100vw",t>0&&(r.minMax.length>1||r.minMax[0].min)&&(r.media=r.minMax.map((function(r){var t=r.min,e=r.max;return t&&e?"(min-width: "+t+"px) and (max-width: "+e+"px)":t?"(min-width: "+t+"px)":"(max-width: "+e+"px)"})).join(", "))}))}if(!f)throw new Error("Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.");return 1===l.length?t.createElement("img",Object.assign({src:f[1],srcSet:l[0].srcSet,sizes:l[0].sizes},h)):(l.reverse(),t.createElement("picture",null,l.map((function(r){return t.createElement("source",{key:r.ar||"original",media:r.media,srcSet:r.srcSet,sizes:r.sizes})})),t.createElement("img",Object.assign({src:f[1],alt:"string"!=typeof r.src&&r.src.alt||void 0},h))))},exports.createImagekitUrl=i; | ||
| "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r,t=(r=require("react"))&&"object"==typeof r&&"default"in r?r.default:r;function e(){return(e=Object.assign||function(r){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(r[n]=e[n])}return r}).apply(this,arguments)}function n(r,t){if(null==r)return{};var e,n,i={},a=Object.keys(r);for(n=0;n<a.length;n++)t.indexOf(e=a[n])>=0||(i[e]=r[e]);return i}function i(r){var t=[],e=a(r),n=e.w,i=e.h;n&&t.push("w-"+Math.round(n)),i&&t.push("h-"+Math.round(i));var o=r.cm;return o&&"maintain_ratio"!==o&&t.push((["pad_resize","extract","pad_extract"].includes(o)?"cm":"c")+"-"+r.cm),r.fo&&"default"!==r.fo&&t.push("fo-"+r.fo),r.xc&&t.push("xc-"+r.xc),r.yc&&t.push("yc-"+r.yc),t.length?t.join(","):null}function a(r){var t=r.w,e=r.h,n=r.ar;if(typeof t==typeof e&&typeof e==typeof n||!n&&typeof t!=typeof e)return{w:t,h:e,ar:n};if(t&&e)return{w:t,h:e,ar:t/e};if(t&&n)return{w:t,h:t/n,ar:n};if(e&&n)return{w:e*n,h:e,ar:n};throw new Error('Make sure that if "ar" is set, that you also set "w" or "h".')}function o(r){var t=function(r){var t,e,n,i,a;return"string"==typeof r?{url:r}:{url:(null==r||null===(t=r.entity)||void 0===t?void 0:t.url)||(null==r?void 0:r.url)||void 0,width:(null==r?void 0:r.width)||void 0,height:(null==r?void 0:r.height)||void 0,x:(null==r||null===(e=r.entity)||void 0===e||null===(n=e.focalPoint)||void 0===n?void 0:n.x)||void 0,y:(null===(i=r.entity)||void 0===i||null===(a=i.focalPoint)||void 0===a?void 0:a.y)||void 0}}(r.src),o=t.url,u=n(t,["url"]);if(!o)throw new Error('You need to provide either an image trough the "src" option, or provide an image with an "url" property.');if(!r.transformations)return o;var c=Array.isArray(r.transformations)?r.transformations:[r.transformations];if((null==u?void 0:u.x)&&u.y&&u.width&&u.height){var l=a(c[0]);if(l.ar){var h=a({ar:l.ar,w:u.width}),f=a({ar:l.ar,h:u.height}),p=h.h<f.h?h:f;c=[e({},p,{cm:"extract",xc:s(u.width,u.x,p.w),yc:s(u.height,u.y,p.h)})].concat(c)}}var m=c.map(i).filter((function(r){return r})).join(":");return m?o+"?tr="+m:o}function s(r,t,e){if(r!==e)return Math.min(Math.max(e/2,t),r-e/2)}function u(r){return"number"==typeof r?[r,{w:r}]:Array.isArray(r)?[r[0],"number"==typeof r[1]?{w:r[1]}:r[1]]:[r.w,r]}exports.ImagekitImage=function(r){var i,s,c=r.src,l=r.transformations,h=n(r,["src","transformations","breakpoints","aspectRatio"]);if(!(null===(i=r.breakpoints)||void 0===i?void 0:i.length)||r.srcSet)return t.createElement("img",Object.assign({src:o({src:c,transformations:l})},h));var f=[],p=null;if((null===(s=r.breakpoints)||void 0===s?void 0:s.length)&&!r.srcSet){var m=r.breakpoints.map(u).map((function(t){var n=e({ar:r.aspectRatio},t[1]);n.h||n.w||!n.ar||(n.w=t[0]);var i=a(n);return[t[0]||i.w,i]}));if(m.forEach((function(r,t){var e=r[0],n=r[1],i=f.find((function(r){return r.ar===n.ar}));i||f.push(i={ar:n.ar,minMax:[],breakpoints:[]}),i.breakpoints.push([e,n]);var a=m[t-1];a&&a[1].ar===n.ar||i.minMax.push({min:(null==a?void 0:a[0])?a[0]+1:void 0}),i.minMax[i.minMax.length-1].max=e})),!f.length)throw new Error("Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).");var d=f.find((function(r){return r.ar===m[m.length-1][1].ar}));d&&delete d.minMax[d.minMax.length-1].max,f.forEach((function(r,t){r.srcSet=r.breakpoints.map((function(r){var t=r[1],e=o({src:c,transformations:[].concat(Array.isArray(l)?l:l?[l]:[],[t])});return t.w&&(!p||p[0]<t.w)&&(p=[t.w,e]),e+" "+t.w+"w"})).join(", "),r.sizes=r.breakpoints.length>=2&&!r.breakpoints.every((function(r){return r[0]===r[1].w}))&&r.breakpoints.map((function(t,e){var n=t[1],i=r.breakpoints[e-1];return i&&i[0]?"(min-width: "+(i[0]+1)+"px) "+n.w+"px":n.w+"px"})).reverse().join(", ")||"100vw",t>0&&(r.minMax.length>1||r.minMax[0].min)&&(r.media=r.minMax.map((function(r){var t=r.min,e=r.max;return t&&e?"(min-width: "+t+"px) and (max-width: "+e+"px)":t?"(min-width: "+t+"px)":"(max-width: "+e+"px)"})).join(", "))}))}if(!p)throw new Error("Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.");return 1===f.length?t.createElement("img",Object.assign({src:p[1],srcSet:f[0].srcSet,sizes:f[0].sizes},h)):(f.reverse(),t.createElement("picture",null,f.map((function(r){return t.createElement("source",{key:r.ar||"original",media:r.media,srcSet:r.srcSet,sizes:r.sizes})})),t.createElement("img",Object.assign({src:p[1],alt:"string"!=typeof r.src&&r.src.alt||void 0},h))))},exports.createImagekitUrl=o; | ||
| //# sourceMappingURL=imagekit.cjs.production.min.js.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"imagekit.cjs.production.min.js","sources":["../src/create-imagekit-url.ts","../src/imagekit-image.tsx"],"sourcesContent":["interface Transformations {\n /**\n * Width -\n * Used to specify the width of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, it acts as a\n * percentage width. Therefore, 0.1 means 10% of the original width, 0.4\n * means 40% of the original width, and so on.\n */\n w?: number;\n\n /**\n * Height -\n * Used to specify the height of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, the value acts as\n * a percentage height. Therefore, 0.1 means 10% of the original height, 0.4\n * means 40% of the original height, and so on.\n */\n h?: number;\n\n /**\n * Aspect ratio -\n * Used to specify the aspect ratio of the output image or the ratio of width\n * to height of the output image. This parameter must be used along with\n * either the height(h) or width(w) parameter. The format for specifying this\n * transformation is ar-<width>-<height>\n */\n ar?: number;\n\n /**\n * Crop Mode -\n * If only, one of the height(h) or width(w) dimension is specified, then\n * ImageKit.io adjusts the other dimension accordingly to preserve aspect\n * ratio and no cropping takes place.\n * But when you specify both height(h) and width(w) dimension, you need to\n * choose the right cropping strategy based on your website layout and desired\n * output image.\n */\n cm?:\n | 'pad_resize'\n | 'force'\n | 'at_max'\n | 'at_least'\n | 'maintain_ratio' // Default cropping\n | 'extract'\n | 'pad_extract';\n\n fo?: 'default' | 'auto' | 'face';\n\n xc?: number;\n yc?: number;\n}\n\ninterface DrupalImageField {\n url?: null | string;\n width?: null | number;\n height?: null | number;\n entity?: null | {\n focalPoint?: null | {\n x?: null | number;\n y?: null | number;\n };\n };\n}\n\nexport interface Options {\n src:\n | string\n | (DrupalImageField & {\n entity?: DrupalImageField | null;\n alt?: string | null;\n });\n transformations?: Transformations | Transformations[];\n}\n\nfunction createImagekitTransformationsParameters(\n transformations: Transformations,\n) {\n const parameters = [];\n const { w, h } = calculateDimensions(transformations);\n if (w) {\n parameters.push(`w-${Math.round(w)}`);\n }\n if (h) {\n parameters.push(`h-${Math.round(h)}`);\n }\n const { cm } = transformations;\n if (cm && cm !== 'maintain_ratio') {\n parameters.push(\n `${['pad_resize', 'extract', 'pad_extract'].includes(cm) ? 'cm' : 'c'}-${\n transformations.cm\n }`,\n );\n }\n if (transformations.fo && transformations.fo !== 'default') {\n parameters.push(`fo-${transformations.fo}`);\n }\n if (transformations.xc) {\n parameters.push(`xc-${transformations.xc}`);\n }\n if (transformations.yc) {\n parameters.push(`yc-${transformations.yc}`);\n }\n\n return parameters.length ? parameters.join(',') : null;\n}\n\nexport function calculateDimensions({\n w,\n h,\n ar,\n}: {\n w?: number;\n h?: number;\n ar?: number;\n}): { w: number | undefined; h: number | undefined; ar: number | undefined } {\n if (\n (typeof w === typeof h && typeof h === typeof ar) ||\n (!ar && typeof w !== typeof h)\n )\n return { w, h, ar };\n\n if (w && h) {\n return { w, h, ar: w / h };\n }\n if (w && ar) {\n return { w, h: w / ar, ar };\n }\n if (h && ar) {\n return { w: h * ar, h, ar };\n }\n\n throw new Error(\n 'Make sure that if \"ar\" is set, that you also set \"w\" or \"h\".',\n );\n}\n\nexport function createImagekitUrl(options: Options) {\n const drupalImageField = getDrupalImageField(options.src);\n const src = drupalImageField?.url;\n if (!src) {\n throw new Error(\n 'You need to provide either an image trough the \"src\" option, or provide an image with an \"url\" property.',\n );\n }\n if (!options.transformations) {\n return src;\n }\n\n let originalTransformations = Array.isArray(options.transformations)\n ? options.transformations\n : [options.transformations];\n\n const focalPoint = drupalImageField && {\n width: drupalImageField.width,\n height: drupalImageField.height,\n x: drupalImageField.entity?.focalPoint?.x,\n y: drupalImageField.entity?.focalPoint?.y,\n };\n\n if (focalPoint?.x && focalPoint.y && focalPoint.width && focalPoint.height) {\n const targetDimensions = calculateDimensions(originalTransformations[0]);\n if (targetDimensions.ar) {\n // We need to make the smallest crop - we calculate the dimensions on both\n // the width and height as source, and take the smallest one.\n const sourceDimensionsCropW = calculateDimensions({\n ar: targetDimensions.ar,\n w: focalPoint.width,\n });\n const sourceDimensionsCropH = calculateDimensions({\n ar: targetDimensions.ar,\n h: focalPoint.height,\n });\n const sourceDimensionsCrop =\n sourceDimensionsCropW.h! < sourceDimensionsCropH.h!\n ? sourceDimensionsCropW\n : sourceDimensionsCropH;\n\n originalTransformations = [\n {\n ...sourceDimensionsCrop,\n cm: 'extract',\n xc: containWithinBoundary(\n focalPoint.width,\n focalPoint.x,\n sourceDimensionsCrop.w!,\n ),\n yc: containWithinBoundary(\n focalPoint.height,\n focalPoint.y,\n sourceDimensionsCrop.h!,\n ),\n },\n ...originalTransformations,\n ];\n }\n }\n\n const transformations = originalTransformations\n .map(createImagekitTransformationsParameters)\n .filter(s => s)\n .join(':');\n\n return transformations ? `${src}?tr=${transformations}` : src;\n}\n\nexport function containWithinBoundary(\n srcSize: number,\n focalCenter: number,\n targetSize: number,\n) {\n if (srcSize === targetSize) return undefined;\n return Math.min(\n Math.max(targetSize / 2, focalCenter),\n srcSize - targetSize / 2,\n );\n}\n\nfunction getDrupalImageField(\n f: string | (DrupalImageField & { entity?: DrupalImageField | null }),\n): DrupalImageField {\n if (typeof f === 'string') return { url: f };\n if (f.entity?.entity?.focalPoint) return f.entity;\n return f;\n}\n","/* eslint-disable no-param-reassign, jsx-a11y/alt-text */\nimport React, { ComponentPropsWithRef } from 'react';\nimport {\n calculateDimensions,\n createImagekitUrl,\n Options,\n} from './create-imagekit-url';\n\ninterface SizeTransformations {\n w?: number;\n h?: number;\n ar?: number;\n}\n\ntype BreakpointSetting =\n | number\n | [number, SizeTransformations | number]\n | SizeTransformations;\n\ninterface Props extends Omit<ComponentPropsWithRef<'img'>, 'src'> {\n src: Options['src'];\n breakpoints?: BreakpointSetting[];\n aspectRatio?: number;\n transformations?: Options['transformations'];\n}\n\nexport function ImagekitImage(props: Props) {\n const { src, transformations, breakpoints, aspectRatio, ...imgProps } = props;\n\n // If there are no breakpoints or an srcSet has already been provided, there\n // is nothing special we can do here. Just return an img component.\n if (!props.breakpoints?.length || props.srcSet) {\n return (\n <img src={createImagekitUrl({ src, transformations })} {...imgProps} />\n );\n }\n\n const imgSources: {\n // Used as key of this source.\n ar: number | undefined;\n\n // Used to calculate the props.\n minMax: { min?: number; max?: number }[];\n breakpoints: NormalizedBreakpoint[];\n\n // Calculated props.\n srcSet?: string;\n sizes?: string;\n media?: string;\n }[] = [];\n\n let largestImageUrl: [number, string] | null = null;\n\n if (props.breakpoints?.length && !props.srcSet) {\n const normalizedBreakpoints = props.breakpoints\n .map(normalizeBreakpoint)\n .map(b => {\n // If no ar was provided, use the aspectRatio prop.\n const sizes = { ar: props.aspectRatio, ...b[1] };\n\n // If there is an aspectRatio but no width, use the maxWidth as image\n // width.\n if (!sizes.h && !sizes.w && sizes.ar) {\n // eslint-disable-next-line prefer-destructuring\n sizes.w = b[0];\n }\n\n // Now calculate the final dimensions.\n const dimensions = calculateDimensions(sizes);\n\n // If no maxWidth was given and there was only a height and aspect ratio\n // available, we use the calculated w dimension as maxWidth.\n return [b[0] || dimensions.w, dimensions] as const;\n });\n\n normalizedBreakpoints.forEach(([maxWidth, sizes], i) => {\n // Set up the new image source.\n let set = imgSources.find(s => s.ar === sizes.ar);\n if (!set) {\n set = {\n ar: sizes.ar,\n minMax: [],\n breakpoints: [],\n };\n imgSources.push(set);\n }\n set.breakpoints.push([maxWidth, sizes]);\n\n // If the previous breakpoint has another aspect ratio, this is a new\n // source. This means that the min-width of this source is one pixel more\n // as the max-width of the previous source (which is the previous\n // breakpoint).\n const previousBreakpoint = normalizedBreakpoints[i - 1];\n if (!previousBreakpoint || previousBreakpoint[1].ar !== sizes.ar) {\n set.minMax.push({\n min: previousBreakpoint?.[0] ? previousBreakpoint[0] + 1 : undefined,\n });\n }\n\n // Set the max-width (will be overwritten until the last max-width of this\n // source).\n set.minMax[set.minMax.length - 1].max = maxWidth;\n });\n\n if (!imgSources.length) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).',\n );\n }\n\n // To make sure that the largest image is always shown, we remove the last\n // maxWidth on the source containing the last breakpoint.\n const largestSource = imgSources.find(\n source =>\n source.ar ===\n normalizedBreakpoints[normalizedBreakpoints.length - 1][1].ar,\n );\n if (largestSource) {\n delete largestSource.minMax[largestSource.minMax.length - 1].max;\n }\n\n imgSources.forEach((source, si) => {\n // Now, calculate the srcSet of every source.\n source.srcSet = source.breakpoints\n .map(([, sizes]) => {\n const imagekitUrlBreakpoint = createImagekitUrl({\n src,\n transformations: [\n ...(Array.isArray(transformations)\n ? transformations\n : transformations\n ? [transformations]\n : []),\n sizes,\n ],\n });\n\n if (sizes.w && (!largestImageUrl || largestImageUrl[0] < sizes.w)) {\n largestImageUrl = [sizes.w, imagekitUrlBreakpoint];\n }\n\n return `${imagekitUrlBreakpoint} ${sizes.w}w`;\n })\n .join(', ');\n\n // Calculate the sizes of every source.\n source.sizes =\n (source.breakpoints.length >= 2 &&\n !source.breakpoints.every(s => s[0] === s[1].w) &&\n source.breakpoints\n .map(([, sizes], i) => {\n const previousBreakpoint = source.breakpoints[i - 1];\n if (!previousBreakpoint || !previousBreakpoint[0]) {\n return `${sizes.w}px`;\n }\n return `(min-width: ${previousBreakpoint[0] + 1}px) ${sizes.w}px`;\n })\n .reverse()\n .join(', ')) ||\n '100vw';\n\n // Calculate the media prop of all sources.\n // If it's the first item, it will always be rendered. So there is no need\n // for a media query then.\n // If there is only one item in the minMax (there should be at least one)\n // then we only need to print it if it has a 'min'.\n if (si > 0 && (source.minMax.length > 1 || source.minMax[0].min)) {\n source.media = source.minMax\n .map(({ min, max }) =>\n min && max\n ? `(min-width: ${min}px) and (max-width: ${max}px)`\n : min\n ? `(min-width: ${min}px)`\n : `(max-width: ${max}px)`,\n )\n .join(', ');\n }\n });\n }\n\n if (!largestImageUrl) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.',\n );\n }\n\n // If there is just one source, we can do everything in one img element.\n if (imgSources.length === 1) {\n return (\n <img\n src={largestImageUrl[1]}\n srcSet={imgSources[0].srcSet}\n sizes={imgSources[0].sizes}\n {...imgProps}\n />\n );\n }\n\n // If it's more then one source, we will render a picture element. We need the\n // largest imgSource on top.\n imgSources.reverse();\n\n return (\n <picture>\n {imgSources.map(source => (\n <source\n key={source.ar || 'original'}\n media={source.media}\n srcSet={source.srcSet}\n sizes={source.sizes}\n />\n ))}\n <img\n src={largestImageUrl[1]}\n alt={(typeof props.src !== 'string' && props.src.alt) || undefined}\n {...imgProps}\n />\n </picture>\n );\n}\n\ntype NormalizedBreakpoint = [number | undefined, SizeTransformations];\n\nfunction normalizeBreakpoint(\n breakpoint: BreakpointSetting,\n): NormalizedBreakpoint {\n return typeof breakpoint === 'number'\n ? [breakpoint, { w: breakpoint }]\n : Array.isArray(breakpoint)\n ? [\n breakpoint[0],\n typeof breakpoint[1] === 'number'\n ? { w: breakpoint[1] }\n : breakpoint[1],\n ]\n : [breakpoint.w, breakpoint];\n}\n"],"names":["createImagekitTransformationsParameters","transformations","parameters","calculateDimensions","w","h","push","Math","round","cm","includes","fo","xc","yc","length","join","ar","Error","createImagekitUrl","options","f","drupalImageField","src","url","entity","_f$entity","_f$entity$entity","focalPoint","originalTransformations","Array","isArray","width","height","x","_drupalImageField$ent","_drupalImageField$ent2","y","_drupalImageField$ent3","_drupalImageField$ent4","targetDimensions","sourceDimensionsCropW","sourceDimensionsCropH","sourceDimensionsCrop","containWithinBoundary","map","filter","s","srcSize","focalCenter","targetSize","min","max","normalizeBreakpoint","breakpoint","props","breakpoints","_props$breakpoints","srcSet","React","imgProps","imgSources","largestImageUrl","normalizedBreakpoints","b","sizes","aspectRatio","dimensions","forEach","i","maxWidth","set","find","minMax","previousBreakpoint","undefined","largestSource","source","si","imagekitUrlBreakpoint","every","reverse","media","key","alt"],"mappings":"+VA0EA,SAASA,EACPC,OAEMC,EAAa,KACFC,EAAo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J+D,aAIAA,EAAM5D,KAAOyD,GAAmBA,EAAgB,GAAKG,EAAM5D,KAC7DyD,EAAkB,CAACG,EAAM5D,EAAG0E,IAGpBA,MAAyBd,EAAM5D,SAE1CW,KAAK,MAGR6D,EAAOZ,MACJY,EAAOrB,YAAYzC,QAAU,IAC3B8D,EAAOrB,YAAYwB,OAAM,SAAAjC,UAAKA,EAAE,KAAOA,EAAE,GAAG1C,MAC7CwE,EAAOrB,YACJX,KAAI,WAAYwB,OAARJ,OACDS,EAAqBG,EAAOrB,YAAYa,EAAI,UAC7CK,GAAuBA,EAAmB,mBAGzBA,EAAmB,GAAK,UAAQT,EAAM5D,OAFhD4D,EAAM5D,UAInB4E,UACAjE,KAAK,OACV,QAOE8D,EAAK,IAAMD,EAAOJ,OAAO1D,OAAS,GAAK8D,EAAOJ,OAAO,GAAGtB,OAC1D0B,EAAOK,MAAQL,EAAOJ,OACnB5B,KAAI,gBAAGM,IAAAA,IAAKC,IAAAA,WACXD,GAAOC,iBACYD,yBAA0BC,QACzCD,iBACeA,uBACAC,WAEpBpC,KAAK,cAKT8C,QACG,IAAI5C,MACR,gHAKsB,IAAtB2C,EAAW9C,OAEX4C,qCACEpC,IAAKuC,EAAgB,GACrBJ,OAAQG,EAAW,GAAGH,OACtBO,MAAOJ,EAAW,GAAGI,OACjBL,KAOVC,EAAWoB,UAGTtB,+BACGE,EAAWhB,KAAI,SAAAgC,UACdlB,0BACEwB,IAAKN,EAAO5D,IAAM,WAClBiE,MAAOL,EAAOK,MACdxB,OAAQmB,EAAOnB,OACfO,MAAOY,EAAOZ,WAGlBN,qCACEpC,IAAKuC,EAAgB,GACrBsB,IAA2B,iBAAd7B,EAAMhC,KAAoBgC,EAAMhC,IAAI6D,UAAQT,GACrDf"} | ||
| {"version":3,"file":"imagekit.cjs.production.min.js","sources":["../src/create-imagekit-url.ts","../src/parse-source.ts","../src/imagekit-image.tsx"],"sourcesContent":["import { ImagekitSrc, parseSource } from './parse-source';\n\ninterface Transformations {\n /**\n * Width -\n * Used to specify the width of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, it acts as a\n * percentage width. Therefore, 0.1 means 10% of the original width, 0.4\n * means 40% of the original width, and so on.\n */\n w?: number;\n\n /**\n * Height -\n * Used to specify the height of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, the value acts as\n * a percentage height. Therefore, 0.1 means 10% of the original height, 0.4\n * means 40% of the original height, and so on.\n */\n h?: number;\n\n /**\n * Aspect ratio -\n * Used to specify the aspect ratio of the output image or the ratio of width\n * to height of the output image. This parameter must be used along with\n * either the height(h) or width(w) parameter. The format for specifying this\n * transformation is ar-<width>-<height>\n */\n ar?: number;\n\n /**\n * Crop Mode -\n * If only, one of the height(h) or width(w) dimension is specified, then\n * ImageKit.io adjusts the other dimension accordingly to preserve aspect\n * ratio and no cropping takes place.\n * But when you specify both height(h) and width(w) dimension, you need to\n * choose the right cropping strategy based on your website layout and desired\n * output image.\n */\n cm?:\n | 'pad_resize'\n | 'force'\n | 'at_max'\n | 'at_least'\n | 'maintain_ratio' // Default cropping\n | 'extract'\n | 'pad_extract';\n\n fo?: 'default' | 'auto' | 'face';\n\n xc?: number;\n yc?: number;\n}\n\nexport interface Options {\n src: ImagekitSrc;\n transformations?: Transformations | Transformations[];\n}\n\nfunction createImagekitTransformationsParameters(\n transformations: Transformations,\n) {\n const parameters = [];\n const { w, h } = calculateDimensions(transformations);\n if (w) {\n parameters.push(`w-${Math.round(w)}`);\n }\n if (h) {\n parameters.push(`h-${Math.round(h)}`);\n }\n const { cm } = transformations;\n if (cm && cm !== 'maintain_ratio') {\n parameters.push(\n `${['pad_resize', 'extract', 'pad_extract'].includes(cm) ? 'cm' : 'c'}-${\n transformations.cm\n }`,\n );\n }\n if (transformations.fo && transformations.fo !== 'default') {\n parameters.push(`fo-${transformations.fo}`);\n }\n if (transformations.xc) {\n parameters.push(`xc-${transformations.xc}`);\n }\n if (transformations.yc) {\n parameters.push(`yc-${transformations.yc}`);\n }\n\n return parameters.length ? parameters.join(',') : null;\n}\n\nexport function calculateDimensions({\n w,\n h,\n ar,\n}: {\n w?: number;\n h?: number;\n ar?: number;\n}): { w: number | undefined; h: number | undefined; ar: number | undefined } {\n if (\n (typeof w === typeof h && typeof h === typeof ar) ||\n (!ar && typeof w !== typeof h)\n )\n return { w, h, ar };\n\n if (w && h) {\n return { w, h, ar: w / h };\n }\n if (w && ar) {\n return { w, h: w / ar, ar };\n }\n if (h && ar) {\n return { w: h * ar, h, ar };\n }\n\n throw new Error(\n 'Make sure that if \"ar\" is set, that you also set \"w\" or \"h\".',\n );\n}\n\nexport function createImagekitUrl(options: Options) {\n const { url: src, ...focalPoint } = parseSource(options.src);\n if (!src) {\n throw new Error(\n 'You need to provide either an image trough the \"src\" option, or provide an image with an \"url\" property.',\n );\n }\n if (!options.transformations) {\n return src;\n }\n\n let originalTransformations = Array.isArray(options.transformations)\n ? options.transformations\n : [options.transformations];\n\n if (focalPoint?.x && focalPoint.y && focalPoint.width && focalPoint.height) {\n const targetDimensions = calculateDimensions(originalTransformations[0]);\n if (targetDimensions.ar) {\n // We need to make the smallest crop - we calculate the dimensions on both\n // the width and height as source, and take the smallest one.\n const sourceDimensionsCropW = calculateDimensions({\n ar: targetDimensions.ar,\n w: focalPoint.width,\n });\n const sourceDimensionsCropH = calculateDimensions({\n ar: targetDimensions.ar,\n h: focalPoint.height,\n });\n const sourceDimensionsCrop =\n sourceDimensionsCropW.h! < sourceDimensionsCropH.h!\n ? sourceDimensionsCropW\n : sourceDimensionsCropH;\n\n originalTransformations = [\n {\n ...sourceDimensionsCrop,\n cm: 'extract',\n xc: containWithinBoundary(\n focalPoint.width,\n focalPoint.x,\n sourceDimensionsCrop.w!,\n ),\n yc: containWithinBoundary(\n focalPoint.height,\n focalPoint.y,\n sourceDimensionsCrop.h!,\n ),\n },\n ...originalTransformations,\n ];\n }\n }\n\n const transformations = originalTransformations\n .map(createImagekitTransformationsParameters)\n .filter(s => s)\n .join(':');\n\n return transformations ? `${src}?tr=${transformations}` : src;\n}\n\nexport function containWithinBoundary(\n srcSize: number,\n focalCenter: number,\n targetSize: number,\n) {\n if (srcSize === targetSize) return undefined;\n return Math.min(\n Math.max(targetSize / 2, focalCenter),\n srcSize - targetSize / 2,\n );\n}\n","interface DrupalImageField {\n url?: null | string;\n alt?: null | string;\n width?: null | number;\n height?: null | number;\n entity?: null | {\n url?: null | string;\n focalPoint?: null | {\n x?: null | number;\n y?: null | number;\n };\n };\n}\n\nexport type ImagekitSrc = string | DrupalImageField;\n\ninterface ParsedSource {\n url?: string;\n width?: number;\n height?: number;\n x?: number;\n y?: number;\n}\n\nexport function parseSource(src: ImagekitSrc): ParsedSource {\n if (typeof src === 'string') {\n return { url: src };\n }\n return {\n url: src?.entity?.url || src?.url || undefined,\n width: src?.width || undefined,\n height: src?.height || undefined,\n x: src?.entity?.focalPoint?.x || undefined,\n y: src.entity?.focalPoint?.y || undefined,\n };\n}\n","/* eslint-disable no-param-reassign, jsx-a11y/alt-text */\nimport React, { ComponentPropsWithRef } from 'react';\nimport {\n calculateDimensions,\n createImagekitUrl,\n Options,\n} from './create-imagekit-url';\n\ninterface SizeTransformations {\n w?: number;\n h?: number;\n ar?: number;\n}\n\ntype BreakpointSetting =\n | number\n | [number, SizeTransformations | number]\n | SizeTransformations;\n\ninterface Props extends Omit<ComponentPropsWithRef<'img'>, 'src'> {\n src: Options['src'];\n breakpoints?: BreakpointSetting[];\n aspectRatio?: number;\n transformations?: Options['transformations'];\n}\n\nexport function ImagekitImage(props: Props) {\n const { src, transformations, breakpoints, aspectRatio, ...imgProps } = props;\n\n // If there are no breakpoints or an srcSet has already been provided, there\n // is nothing special we can do here. Just return an img component.\n if (!props.breakpoints?.length || props.srcSet) {\n return (\n <img src={createImagekitUrl({ src, transformations })} {...imgProps} />\n );\n }\n\n const imgSources: {\n // Used as key of this source.\n ar: number | undefined;\n\n // Used to calculate the props.\n minMax: { min?: number; max?: number }[];\n breakpoints: NormalizedBreakpoint[];\n\n // Calculated props.\n srcSet?: string;\n sizes?: string;\n media?: string;\n }[] = [];\n\n let largestImageUrl: [number, string] | null = null;\n\n if (props.breakpoints?.length && !props.srcSet) {\n const normalizedBreakpoints = props.breakpoints\n .map(normalizeBreakpoint)\n .map(b => {\n // If no ar was provided, use the aspectRatio prop.\n const sizes = { ar: props.aspectRatio, ...b[1] };\n\n // If there is an aspectRatio but no width, use the maxWidth as image\n // width.\n if (!sizes.h && !sizes.w && sizes.ar) {\n // eslint-disable-next-line prefer-destructuring\n sizes.w = b[0];\n }\n\n // Now calculate the final dimensions.\n const dimensions = calculateDimensions(sizes);\n\n // If no maxWidth was given and there was only a height and aspect ratio\n // available, we use the calculated w dimension as maxWidth.\n return [b[0] || dimensions.w, dimensions] as const;\n });\n\n normalizedBreakpoints.forEach(([maxWidth, sizes], i) => {\n // Set up the new image source.\n let set = imgSources.find(s => s.ar === sizes.ar);\n if (!set) {\n set = {\n ar: sizes.ar,\n minMax: [],\n breakpoints: [],\n };\n imgSources.push(set);\n }\n set.breakpoints.push([maxWidth, sizes]);\n\n // If the previous breakpoint has another aspect ratio, this is a new\n // source. This means that the min-width of this source is one pixel more\n // as the max-width of the previous source (which is the previous\n // breakpoint).\n const previousBreakpoint = normalizedBreakpoints[i - 1];\n if (!previousBreakpoint || previousBreakpoint[1].ar !== sizes.ar) {\n set.minMax.push({\n min: previousBreakpoint?.[0] ? previousBreakpoint[0] + 1 : undefined,\n });\n }\n\n // Set the max-width (will be overwritten until the last max-width of this\n // source).\n set.minMax[set.minMax.length - 1].max = maxWidth;\n });\n\n if (!imgSources.length) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).',\n );\n }\n\n // To make sure that the largest image is always shown, we remove the last\n // maxWidth on the source containing the last breakpoint.\n const largestSource = imgSources.find(\n source =>\n source.ar ===\n normalizedBreakpoints[normalizedBreakpoints.length - 1][1].ar,\n );\n if (largestSource) {\n delete largestSource.minMax[largestSource.minMax.length - 1].max;\n }\n\n imgSources.forEach((source, si) => {\n // Now, calculate the srcSet of every source.\n source.srcSet = source.breakpoints\n .map(([, sizes]) => {\n const imagekitUrlBreakpoint = createImagekitUrl({\n src,\n transformations: [\n ...(Array.isArray(transformations)\n ? transformations\n : transformations\n ? [transformations]\n : []),\n sizes,\n ],\n });\n\n if (sizes.w && (!largestImageUrl || largestImageUrl[0] < sizes.w)) {\n largestImageUrl = [sizes.w, imagekitUrlBreakpoint];\n }\n\n return `${imagekitUrlBreakpoint} ${sizes.w}w`;\n })\n .join(', ');\n\n // Calculate the sizes of every source.\n source.sizes =\n (source.breakpoints.length >= 2 &&\n !source.breakpoints.every(s => s[0] === s[1].w) &&\n source.breakpoints\n .map(([, sizes], i) => {\n const previousBreakpoint = source.breakpoints[i - 1];\n if (!previousBreakpoint || !previousBreakpoint[0]) {\n return `${sizes.w}px`;\n }\n return `(min-width: ${previousBreakpoint[0] + 1}px) ${sizes.w}px`;\n })\n .reverse()\n .join(', ')) ||\n '100vw';\n\n // Calculate the media prop of all sources.\n // If it's the first item, it will always be rendered. So there is no need\n // for a media query then.\n // If there is only one item in the minMax (there should be at least one)\n // then we only need to print it if it has a 'min'.\n if (si > 0 && (source.minMax.length > 1 || source.minMax[0].min)) {\n source.media = source.minMax\n .map(({ min, max }) =>\n min && max\n ? `(min-width: ${min}px) and (max-width: ${max}px)`\n : min\n ? `(min-width: ${min}px)`\n : `(max-width: ${max}px)`,\n )\n .join(', ');\n }\n });\n }\n\n if (!largestImageUrl) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.',\n );\n }\n\n // If there is just one source, we can do everything in one img element.\n if (imgSources.length === 1) {\n return (\n <img\n src={largestImageUrl[1]}\n srcSet={imgSources[0].srcSet}\n sizes={imgSources[0].sizes}\n {...imgProps}\n />\n );\n }\n\n // If it's more then one source, we will render a picture element. We need the\n // largest imgSource on top.\n imgSources.reverse();\n\n return (\n <picture>\n {imgSources.map(source => (\n <source\n key={source.ar || 'original'}\n media={source.media}\n srcSet={source.srcSet}\n sizes={source.sizes}\n />\n ))}\n <img\n src={largestImageUrl[1]}\n alt={(typeof props.src !== 'string' && props.src.alt) || undefined}\n {...imgProps}\n />\n </picture>\n );\n}\n\ntype NormalizedBreakpoint = [number | undefined, SizeTransformations];\n\nfunction normalizeBreakpoint(\n breakpoint: BreakpointSetting,\n): NormalizedBreakpoint {\n return typeof breakpoint === 'number'\n ? [breakpoint, { w: breakpoint }]\n : Array.isArray(breakpoint)\n ? [\n breakpoint[0],\n typeof breakpoint[1] === 'number'\n ? { w: breakpoint[1] }\n : breakpoint[1],\n ]\n : [breakpoint.w, breakpoint];\n}\n"],"names":["createImagekitTransformationsParameters","transformations","parameters","calculateDimensions","w","h","push","Math","round","cm","includes","fo","xc","yc","length","join","ar","Error","createImagekitUrl","options","src","url","entity","undefined","width","height","x","focalPoint","y","parseSource","originalTransformations","Array","isArray","targetDimensions","sourceDimensionsCropW","sourceDimensionsCropH","sourceDimensionsCrop","containWithinBoundary","map","filter","s","srcSize","focalCenter","targetSize","min","max","normalizeBreakpoint","breakpoint","props","breakpoints","_props$breakpoints","srcSet","React","imgProps","imgSources","largestImageUrl","normalizedBreakpoints","b","sizes","aspectRatio","dimensions","forEach","i","maxWidth","set","find","minMax","previousBreakpoint","largestSource","source","si","imagekitUrlBreakpoint","every","reverse","media","key","alt"],"mappings":"meA2DA,SAASA,EACPC,OAEMC,EAAa,KACFC,EAAoBF,GAA7BG,IAAAA,EAAGC,IAAAA,EACPD,GACFF,EAAWI,UAAUC,KAAKC,MAAMJ,IAE9BC,GACFH,EAAWI,UAAUC,KAAKC,MAAMH,QAE1BI,EAAOR,EAAPQ,UACJA,GAAa,mBAAPA,GACRP,EAAWI,MACN,CAAC,aAAc,UAAW,eAAeI,SAASD,GAAM,KAAO,SAChER,EAAgBQ,IAIlBR,EAAgBU,IAA6B,YAAvBV,EAAgBU,IACxCT,EAAWI,WAAWL,EAAgBU,IAEpC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B,YAAYa,EAAI,UAC7CK,GAAuBA,EAAmB,mBAGzBA,EAAmB,GAAK,UAAQT,EAAMtD,OAFhDsD,EAAMtD,UAInBqE,UACA1D,KAAK,OACV,QAOEuD,EAAK,IAAMD,EAAOH,OAAOpD,OAAS,GAAKuD,EAAOH,OAAO,GAAGtB,OAC1DyB,EAAOK,MAAQL,EAAOH,OACnB5B,KAAI,gBAAGM,IAAAA,IAAKC,IAAAA,WACXD,GAAOC,iBACYD,yBAA0BC,QACzCD,iBACeA,uBACAC,WAEpB9B,KAAK,cAKTwC,QACG,IAAItC,MACR,gHAKsB,IAAtBqC,EAAWxC,OAEXsC,qCACEhC,IAAKmC,EAAgB,GACrBJ,OAAQG,EAAW,GAAGH,OACtBO,MAAOJ,EAAW,GAAGI,OACjBL,KAOVC,EAAWmB,UAGTrB,+BACGE,EAAWhB,KAAI,SAAA+B,UACdjB,0BACEuB,IAAKN,EAAOrD,IAAM,WAClB0D,MAAOL,EAAOK,MACdvB,OAAQkB,EAAOlB,OACfO,MAAOW,EAAOX,WAGlBN,qCACEhC,IAAKmC,EAAgB,GACrBqB,IAA2B,iBAAd5B,EAAM5B,KAAoB4B,EAAM5B,IAAIwD,UAAQrD,GACrD8B"} |
+21
-20
@@ -36,2 +36,20 @@ import React from 'react'; | ||
| function parseSource(src) { | ||
| var _src$entity, _src$entity2, _src$entity2$focalPoi, _src$entity3, _src$entity3$focalPoi; | ||
| if (typeof src === 'string') { | ||
| return { | ||
| url: src | ||
| }; | ||
| } | ||
| return { | ||
| url: (src === null || src === void 0 ? void 0 : (_src$entity = src.entity) === null || _src$entity === void 0 ? void 0 : _src$entity.url) || (src === null || src === void 0 ? void 0 : src.url) || undefined, | ||
| width: (src === null || src === void 0 ? void 0 : src.width) || undefined, | ||
| height: (src === null || src === void 0 ? void 0 : src.height) || undefined, | ||
| x: (src === null || src === void 0 ? void 0 : (_src$entity2 = src.entity) === null || _src$entity2 === void 0 ? void 0 : (_src$entity2$focalPoi = _src$entity2.focalPoint) === null || _src$entity2$focalPoi === void 0 ? void 0 : _src$entity2$focalPoi.x) || undefined, | ||
| y: ((_src$entity3 = src.entity) === null || _src$entity3 === void 0 ? void 0 : (_src$entity3$focalPoi = _src$entity3.focalPoint) === null || _src$entity3$focalPoi === void 0 ? void 0 : _src$entity3$focalPoi.y) || undefined | ||
| }; | ||
| } | ||
| function createImagekitTransformationsParameters(transformations) { | ||
@@ -110,7 +128,6 @@ var parameters = []; | ||
| function createImagekitUrl(options) { | ||
| var _drupalImageField$ent, _drupalImageField$ent2, _drupalImageField$ent3, _drupalImageField$ent4; | ||
| var _parseSource = parseSource(options.src), | ||
| src = _parseSource.url, | ||
| focalPoint = _objectWithoutPropertiesLoose(_parseSource, ["url"]); | ||
| var drupalImageField = getDrupalImageField(options.src); | ||
| var src = drupalImageField === null || drupalImageField === void 0 ? void 0 : drupalImageField.url; | ||
| if (!src) { | ||
@@ -125,8 +142,2 @@ throw new Error('You need to provide either an image trough the "src" option, or provide an image with an "url" property.'); | ||
| var originalTransformations = Array.isArray(options.transformations) ? options.transformations : [options.transformations]; | ||
| var focalPoint = drupalImageField && { | ||
| width: drupalImageField.width, | ||
| height: drupalImageField.height, | ||
| x: (_drupalImageField$ent = drupalImageField.entity) === null || _drupalImageField$ent === void 0 ? void 0 : (_drupalImageField$ent2 = _drupalImageField$ent.focalPoint) === null || _drupalImageField$ent2 === void 0 ? void 0 : _drupalImageField$ent2.x, | ||
| y: (_drupalImageField$ent3 = drupalImageField.entity) === null || _drupalImageField$ent3 === void 0 ? void 0 : (_drupalImageField$ent4 = _drupalImageField$ent3.focalPoint) === null || _drupalImageField$ent4 === void 0 ? void 0 : _drupalImageField$ent4.y | ||
| }; | ||
@@ -166,12 +177,2 @@ if ((focalPoint === null || focalPoint === void 0 ? void 0 : focalPoint.x) && focalPoint.y && focalPoint.width && focalPoint.height) { | ||
| function getDrupalImageField(f) { | ||
| var _f$entity, _f$entity$entity; | ||
| if (typeof f === 'string') return { | ||
| url: f | ||
| }; | ||
| if ((_f$entity = f.entity) === null || _f$entity === void 0 ? void 0 : (_f$entity$entity = _f$entity.entity) === null || _f$entity$entity === void 0 ? void 0 : _f$entity$entity.focalPoint) return f.entity; | ||
| return f; | ||
| } | ||
| function ImagekitImage(props) { | ||
@@ -178,0 +179,0 @@ var _props$breakpoints, _props$breakpoints2; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"imagekit.esm.js","sources":["../src/create-imagekit-url.ts","../src/imagekit-image.tsx"],"sourcesContent":["interface Transformations {\n /**\n * Width -\n * Used to specify the width of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, it acts as a\n * percentage width. Therefore, 0.1 means 10% of the original width, 0.4\n * means 40% of the original width, and so on.\n */\n w?: number;\n\n /**\n * Height -\n * Used to specify the height of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, the value acts as\n * a percentage height. Therefore, 0.1 means 10% of the original height, 0.4\n * means 40% of the original height, and so on.\n */\n h?: number;\n\n /**\n * Aspect ratio -\n * Used to specify the aspect ratio of the output image or the ratio of width\n * to height of the output image. This parameter must be used along with\n * either the height(h) or width(w) parameter. The format for specifying this\n * transformation is ar-<width>-<height>\n */\n ar?: number;\n\n /**\n * Crop Mode -\n * If only, one of the height(h) or width(w) dimension is specified, then\n * ImageKit.io adjusts the other dimension accordingly to preserve aspect\n * ratio and no cropping takes place.\n * But when you specify both height(h) and width(w) dimension, you need to\n * choose the right cropping strategy based on your website layout and desired\n * output image.\n */\n cm?:\n | 'pad_resize'\n | 'force'\n | 'at_max'\n | 'at_least'\n | 'maintain_ratio' // Default cropping\n | 'extract'\n | 'pad_extract';\n\n fo?: 'default' | 'auto' | 'face';\n\n xc?: number;\n yc?: number;\n}\n\ninterface DrupalImageField {\n url?: null | string;\n width?: null | number;\n height?: null | number;\n entity?: null | {\n focalPoint?: null | {\n x?: null | number;\n y?: null | number;\n };\n };\n}\n\nexport interface Options {\n src:\n | string\n | (DrupalImageField & {\n entity?: DrupalImageField | null;\n alt?: string | null;\n });\n transformations?: Transformations | Transformations[];\n}\n\nfunction createImagekitTransformationsParameters(\n transformations: Transformations,\n) {\n const parameters = [];\n const { w, h } = calculateDimensions(transformations);\n if (w) {\n parameters.push(`w-${Math.round(w)}`);\n }\n if (h) {\n parameters.push(`h-${Math.round(h)}`);\n }\n const { cm } = transformations;\n if (cm && cm !== 'maintain_ratio') {\n parameters.push(\n `${['pad_resize', 'extract', 'pad_extract'].includes(cm) ? 'cm' : 'c'}-${\n transformations.cm\n }`,\n );\n }\n if (transformations.fo && transformations.fo !== 'default') {\n parameters.push(`fo-${transformations.fo}`);\n }\n if (transformations.xc) {\n parameters.push(`xc-${transformations.xc}`);\n }\n if (transformations.yc) {\n parameters.push(`yc-${transformations.yc}`);\n }\n\n return parameters.length ? parameters.join(',') : null;\n}\n\nexport function calculateDimensions({\n w,\n h,\n ar,\n}: {\n w?: number;\n h?: number;\n ar?: number;\n}): { w: number | undefined; h: number | undefined; ar: number | undefined } {\n if (\n (typeof w === typeof h && typeof h === typeof ar) ||\n (!ar && typeof w !== typeof h)\n )\n return { w, h, ar };\n\n if (w && h) {\n return { w, h, ar: w / h };\n }\n if (w && ar) {\n return { w, h: w / ar, ar };\n }\n if (h && ar) {\n return { w: h * ar, h, ar };\n }\n\n throw new Error(\n 'Make sure that if \"ar\" is set, that you also set \"w\" or \"h\".',\n );\n}\n\nexport function createImagekitUrl(options: Options) {\n const drupalImageField = getDrupalImageField(options.src);\n const src = drupalImageField?.url;\n if (!src) {\n throw new Error(\n 'You need to provide either an image trough the \"src\" option, or provide an image with an \"url\" property.',\n );\n }\n if (!options.transformations) {\n return src;\n }\n\n let originalTransformations = Array.isArray(options.transformations)\n ? options.transformations\n : [options.transformations];\n\n const focalPoint = drupalImageField && {\n width: drupalImageField.width,\n height: drupalImageField.height,\n x: drupalImageField.entity?.focalPoint?.x,\n y: drupalImageField.entity?.focalPoint?.y,\n };\n\n if (focalPoint?.x && focalPoint.y && focalPoint.width && focalPoint.height) {\n const targetDimensions = calculateDimensions(originalTransformations[0]);\n if (targetDimensions.ar) {\n // We need to make the smallest crop - we calculate the dimensions on both\n // the width and height as source, and take the smallest one.\n const sourceDimensionsCropW = calculateDimensions({\n ar: targetDimensions.ar,\n w: focalPoint.width,\n });\n const sourceDimensionsCropH = calculateDimensions({\n ar: targetDimensions.ar,\n h: focalPoint.height,\n });\n const sourceDimensionsCrop =\n sourceDimensionsCropW.h! < sourceDimensionsCropH.h!\n ? sourceDimensionsCropW\n : sourceDimensionsCropH;\n\n originalTransformations = [\n {\n ...sourceDimensionsCrop,\n cm: 'extract',\n xc: containWithinBoundary(\n focalPoint.width,\n focalPoint.x,\n sourceDimensionsCrop.w!,\n ),\n yc: containWithinBoundary(\n focalPoint.height,\n focalPoint.y,\n sourceDimensionsCrop.h!,\n ),\n },\n ...originalTransformations,\n ];\n }\n }\n\n const transformations = originalTransformations\n .map(createImagekitTransformationsParameters)\n .filter(s => s)\n .join(':');\n\n return transformations ? `${src}?tr=${transformations}` : src;\n}\n\nexport function containWithinBoundary(\n srcSize: number,\n focalCenter: number,\n targetSize: number,\n) {\n if (srcSize === targetSize) return undefined;\n return Math.min(\n Math.max(targetSize / 2, focalCenter),\n srcSize - targetSize / 2,\n );\n}\n\nfunction getDrupalImageField(\n f: string | (DrupalImageField & { entity?: DrupalImageField | null }),\n): DrupalImageField {\n if (typeof f === 'string') return { url: f };\n if (f.entity?.entity?.focalPoint) return f.entity;\n return f;\n}\n","/* eslint-disable no-param-reassign, jsx-a11y/alt-text */\nimport React, { ComponentPropsWithRef } from 'react';\nimport {\n calculateDimensions,\n createImagekitUrl,\n Options,\n} from './create-imagekit-url';\n\ninterface SizeTransformations {\n w?: number;\n h?: number;\n ar?: number;\n}\n\ntype BreakpointSetting =\n | number\n | [number, SizeTransformations | number]\n | SizeTransformations;\n\ninterface Props extends Omit<ComponentPropsWithRef<'img'>, 'src'> {\n src: Options['src'];\n breakpoints?: BreakpointSetting[];\n aspectRatio?: number;\n transformations?: Options['transformations'];\n}\n\nexport function ImagekitImage(props: Props) {\n const { src, transformations, breakpoints, aspectRatio, ...imgProps } = props;\n\n // If there are no breakpoints or an srcSet has already been provided, there\n // is nothing special we can do here. Just return an img component.\n if (!props.breakpoints?.length || props.srcSet) {\n return (\n <img src={createImagekitUrl({ src, transformations })} {...imgProps} />\n );\n }\n\n const imgSources: {\n // Used as key of this source.\n ar: number | undefined;\n\n // Used to calculate the props.\n minMax: { min?: number; max?: number }[];\n breakpoints: NormalizedBreakpoint[];\n\n // Calculated props.\n srcSet?: string;\n sizes?: string;\n media?: string;\n }[] = [];\n\n let largestImageUrl: [number, string] | null = null;\n\n if (props.breakpoints?.length && !props.srcSet) {\n const normalizedBreakpoints = props.breakpoints\n .map(normalizeBreakpoint)\n .map(b => {\n // If no ar was provided, use the aspectRatio prop.\n const sizes = { ar: props.aspectRatio, ...b[1] };\n\n // If there is an aspectRatio but no width, use the maxWidth as image\n // width.\n if (!sizes.h && !sizes.w && sizes.ar) {\n // eslint-disable-next-line prefer-destructuring\n sizes.w = b[0];\n }\n\n // Now calculate the final dimensions.\n const dimensions = calculateDimensions(sizes);\n\n // If no maxWidth was given and there was only a height and aspect ratio\n // available, we use the calculated w dimension as maxWidth.\n return [b[0] || dimensions.w, dimensions] as const;\n });\n\n normalizedBreakpoints.forEach(([maxWidth, sizes], i) => {\n // Set up the new image source.\n let set = imgSources.find(s => s.ar === sizes.ar);\n if (!set) {\n set = {\n ar: sizes.ar,\n minMax: [],\n breakpoints: [],\n };\n imgSources.push(set);\n }\n set.breakpoints.push([maxWidth, sizes]);\n\n // If the previous breakpoint has another aspect ratio, this is a new\n // source. This means that the min-width of this source is one pixel more\n // as the max-width of the previous source (which is the previous\n // breakpoint).\n const previousBreakpoint = normalizedBreakpoints[i - 1];\n if (!previousBreakpoint || previousBreakpoint[1].ar !== sizes.ar) {\n set.minMax.push({\n min: previousBreakpoint?.[0] ? previousBreakpoint[0] + 1 : undefined,\n });\n }\n\n // Set the max-width (will be overwritten until the last max-width of this\n // source).\n set.minMax[set.minMax.length - 1].max = maxWidth;\n });\n\n if (!imgSources.length) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).',\n );\n }\n\n // To make sure that the largest image is always shown, we remove the last\n // maxWidth on the source containing the last breakpoint.\n const largestSource = imgSources.find(\n source =>\n source.ar ===\n normalizedBreakpoints[normalizedBreakpoints.length - 1][1].ar,\n );\n if (largestSource) {\n delete largestSource.minMax[largestSource.minMax.length - 1].max;\n }\n\n imgSources.forEach((source, si) => {\n // Now, calculate the srcSet of every source.\n source.srcSet = source.breakpoints\n .map(([, sizes]) => {\n const imagekitUrlBreakpoint = createImagekitUrl({\n src,\n transformations: [\n ...(Array.isArray(transformations)\n ? transformations\n : transformations\n ? [transformations]\n : []),\n sizes,\n ],\n });\n\n if (sizes.w && (!largestImageUrl || largestImageUrl[0] < sizes.w)) {\n largestImageUrl = [sizes.w, imagekitUrlBreakpoint];\n }\n\n return `${imagekitUrlBreakpoint} ${sizes.w}w`;\n })\n .join(', ');\n\n // Calculate the sizes of every source.\n source.sizes =\n (source.breakpoints.length >= 2 &&\n !source.breakpoints.every(s => s[0] === s[1].w) &&\n source.breakpoints\n .map(([, sizes], i) => {\n const previousBreakpoint = source.breakpoints[i - 1];\n if (!previousBreakpoint || !previousBreakpoint[0]) {\n return `${sizes.w}px`;\n }\n return `(min-width: ${previousBreakpoint[0] + 1}px) ${sizes.w}px`;\n })\n .reverse()\n .join(', ')) ||\n '100vw';\n\n // Calculate the media prop of all sources.\n // If it's the first item, it will always be rendered. So there is no need\n // for a media query then.\n // If there is only one item in the minMax (there should be at least one)\n // then we only need to print it if it has a 'min'.\n if (si > 0 && (source.minMax.length > 1 || source.minMax[0].min)) {\n source.media = source.minMax\n .map(({ min, max }) =>\n min && max\n ? `(min-width: ${min}px) and (max-width: ${max}px)`\n : min\n ? `(min-width: ${min}px)`\n : `(max-width: ${max}px)`,\n )\n .join(', ');\n }\n });\n }\n\n if (!largestImageUrl) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.',\n );\n }\n\n // If there is just one source, we can do everything in one img element.\n if (imgSources.length === 1) {\n return (\n <img\n src={largestImageUrl[1]}\n srcSet={imgSources[0].srcSet}\n sizes={imgSources[0].sizes}\n {...imgProps}\n />\n );\n }\n\n // If it's more then one source, we will render a picture element. We need the\n // largest imgSource on top.\n imgSources.reverse();\n\n return (\n <picture>\n {imgSources.map(source => (\n <source\n key={source.ar || 'original'}\n media={source.media}\n srcSet={source.srcSet}\n sizes={source.sizes}\n />\n ))}\n <img\n src={largestImageUrl[1]}\n alt={(typeof props.src !== 'string' && props.src.alt) || undefined}\n {...imgProps}\n />\n </picture>\n );\n}\n\ntype NormalizedBreakpoint = [number | undefined, SizeTransformations];\n\nfunction normalizeBreakpoint(\n breakpoint: BreakpointSetting,\n): NormalizedBreakpoint {\n return typeof breakpoint === 'number'\n ? [breakpoint, { w: breakpoint }]\n : Array.isArray(breakpoint)\n ? [\n breakpoint[0],\n typeof breakpoint[1] === 'number'\n ? { w: breakpoint[1] }\n : breakpoint[1],\n ]\n : [breakpoint.w, breakpoint];\n}\n"],"names":["createImagekitTransformationsParameters","transformations","parameters","calculateDimensions","w","h","push","Math","round","cm","includes","fo","xc","yc","length","join","ar","Error","createImagekitUrl","options","drupalImageField","getDrupalImageField","src","url","originalTransformations","Array","isArray","focalPoint","width","height","x","entity","y","targetDimensions","sourceDimensionsCropW","sourceDimensionsCropH","sourceDimensionsCrop","containWithinBoundary","map","filter","s","srcSize","focalCenter","targetSize","undefined","min","max","f","ImagekitImage","props","breakpoints","imgProps","srcSet","React","imgSources","largestImageUrl","normalizedBreakpoints","normalizeBreakpoint","b","sizes","aspectRatio","dimensions","forEach","i","maxWidth","set","find","minMax","previousBreakpoint","largestSource","source","si","imagekitUrlBreakpoint","every","reverse","media","key","alt","breakpoint"],"mappings":";;;;;;;;;;;;;;;;;;;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EAAEkB,MAAM,CAAClB;AACfO,MAAAA,KAAK,EAAEW,MAAM,CAACX;KAJhB,CADoB;AAAA,GAArB,CADH,EASEN,mBAAA,MAAA;AACE/B,IAAAA,GAAG,EAAEiC,eAAe,CAAC,CAAD;AACpBsB,IAAAA,GAAG,EAAG,OAAO5B,KAAK,CAAC3B,GAAb,KAAqB,QAArB,IAAiC2B,KAAK,CAAC3B,GAAN,CAAUuD,GAA5C,IAAoDjC;KACrDO,SAHN,CATF,CADF;AAiBD;;AAID,SAASM,mBAAT,CACEqB,UADF;AAGE,SAAO,OAAOA,UAAP,KAAsB,QAAtB,GACH,CAACA,UAAD,EAAa;AAAE1E,IAAAA,CAAC,EAAE0E;AAAL,GAAb,CADG,GAEHrD,KAAK,CAACC,OAAN,CAAcoD,UAAd,IACA,CACEA,UAAU,CAAC,CAAD,CADZ,EAEE,OAAOA,UAAU,CAAC,CAAD,CAAjB,KAAyB,QAAzB,GACI;AAAE1E,IAAAA,CAAC,EAAE0E,UAAU,CAAC,CAAD;AAAf,GADJ,GAEIA,UAAU,CAAC,CAAD,CAJhB,CADA,GAOA,CAACA,UAAU,CAAC1E,CAAZ,EAAe0E,UAAf,CATJ;AAUD;;;;"} | ||
| {"version":3,"file":"imagekit.esm.js","sources":["../src/parse-source.ts","../src/create-imagekit-url.ts","../src/imagekit-image.tsx"],"sourcesContent":["interface DrupalImageField {\n url?: null | string;\n alt?: null | string;\n width?: null | number;\n height?: null | number;\n entity?: null | {\n url?: null | string;\n focalPoint?: null | {\n x?: null | number;\n y?: null | number;\n };\n };\n}\n\nexport type ImagekitSrc = string | DrupalImageField;\n\ninterface ParsedSource {\n url?: string;\n width?: number;\n height?: number;\n x?: number;\n y?: number;\n}\n\nexport function parseSource(src: ImagekitSrc): ParsedSource {\n if (typeof src === 'string') {\n return { url: src };\n }\n return {\n url: src?.entity?.url || src?.url || undefined,\n width: src?.width || undefined,\n height: src?.height || undefined,\n x: src?.entity?.focalPoint?.x || undefined,\n y: src.entity?.focalPoint?.y || undefined,\n };\n}\n","import { ImagekitSrc, parseSource } from './parse-source';\n\ninterface Transformations {\n /**\n * Width -\n * Used to specify the width of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, it acts as a\n * percentage width. Therefore, 0.1 means 10% of the original width, 0.4\n * means 40% of the original width, and so on.\n */\n w?: number;\n\n /**\n * Height -\n * Used to specify the height of the output image. Accepts integer value\n * greater than 1. If a value between 0 and 1 is specified, the value acts as\n * a percentage height. Therefore, 0.1 means 10% of the original height, 0.4\n * means 40% of the original height, and so on.\n */\n h?: number;\n\n /**\n * Aspect ratio -\n * Used to specify the aspect ratio of the output image or the ratio of width\n * to height of the output image. This parameter must be used along with\n * either the height(h) or width(w) parameter. The format for specifying this\n * transformation is ar-<width>-<height>\n */\n ar?: number;\n\n /**\n * Crop Mode -\n * If only, one of the height(h) or width(w) dimension is specified, then\n * ImageKit.io adjusts the other dimension accordingly to preserve aspect\n * ratio and no cropping takes place.\n * But when you specify both height(h) and width(w) dimension, you need to\n * choose the right cropping strategy based on your website layout and desired\n * output image.\n */\n cm?:\n | 'pad_resize'\n | 'force'\n | 'at_max'\n | 'at_least'\n | 'maintain_ratio' // Default cropping\n | 'extract'\n | 'pad_extract';\n\n fo?: 'default' | 'auto' | 'face';\n\n xc?: number;\n yc?: number;\n}\n\nexport interface Options {\n src: ImagekitSrc;\n transformations?: Transformations | Transformations[];\n}\n\nfunction createImagekitTransformationsParameters(\n transformations: Transformations,\n) {\n const parameters = [];\n const { w, h } = calculateDimensions(transformations);\n if (w) {\n parameters.push(`w-${Math.round(w)}`);\n }\n if (h) {\n parameters.push(`h-${Math.round(h)}`);\n }\n const { cm } = transformations;\n if (cm && cm !== 'maintain_ratio') {\n parameters.push(\n `${['pad_resize', 'extract', 'pad_extract'].includes(cm) ? 'cm' : 'c'}-${\n transformations.cm\n }`,\n );\n }\n if (transformations.fo && transformations.fo !== 'default') {\n parameters.push(`fo-${transformations.fo}`);\n }\n if (transformations.xc) {\n parameters.push(`xc-${transformations.xc}`);\n }\n if (transformations.yc) {\n parameters.push(`yc-${transformations.yc}`);\n }\n\n return parameters.length ? parameters.join(',') : null;\n}\n\nexport function calculateDimensions({\n w,\n h,\n ar,\n}: {\n w?: number;\n h?: number;\n ar?: number;\n}): { w: number | undefined; h: number | undefined; ar: number | undefined } {\n if (\n (typeof w === typeof h && typeof h === typeof ar) ||\n (!ar && typeof w !== typeof h)\n )\n return { w, h, ar };\n\n if (w && h) {\n return { w, h, ar: w / h };\n }\n if (w && ar) {\n return { w, h: w / ar, ar };\n }\n if (h && ar) {\n return { w: h * ar, h, ar };\n }\n\n throw new Error(\n 'Make sure that if \"ar\" is set, that you also set \"w\" or \"h\".',\n );\n}\n\nexport function createImagekitUrl(options: Options) {\n const { url: src, ...focalPoint } = parseSource(options.src);\n if (!src) {\n throw new Error(\n 'You need to provide either an image trough the \"src\" option, or provide an image with an \"url\" property.',\n );\n }\n if (!options.transformations) {\n return src;\n }\n\n let originalTransformations = Array.isArray(options.transformations)\n ? options.transformations\n : [options.transformations];\n\n if (focalPoint?.x && focalPoint.y && focalPoint.width && focalPoint.height) {\n const targetDimensions = calculateDimensions(originalTransformations[0]);\n if (targetDimensions.ar) {\n // We need to make the smallest crop - we calculate the dimensions on both\n // the width and height as source, and take the smallest one.\n const sourceDimensionsCropW = calculateDimensions({\n ar: targetDimensions.ar,\n w: focalPoint.width,\n });\n const sourceDimensionsCropH = calculateDimensions({\n ar: targetDimensions.ar,\n h: focalPoint.height,\n });\n const sourceDimensionsCrop =\n sourceDimensionsCropW.h! < sourceDimensionsCropH.h!\n ? sourceDimensionsCropW\n : sourceDimensionsCropH;\n\n originalTransformations = [\n {\n ...sourceDimensionsCrop,\n cm: 'extract',\n xc: containWithinBoundary(\n focalPoint.width,\n focalPoint.x,\n sourceDimensionsCrop.w!,\n ),\n yc: containWithinBoundary(\n focalPoint.height,\n focalPoint.y,\n sourceDimensionsCrop.h!,\n ),\n },\n ...originalTransformations,\n ];\n }\n }\n\n const transformations = originalTransformations\n .map(createImagekitTransformationsParameters)\n .filter(s => s)\n .join(':');\n\n return transformations ? `${src}?tr=${transformations}` : src;\n}\n\nexport function containWithinBoundary(\n srcSize: number,\n focalCenter: number,\n targetSize: number,\n) {\n if (srcSize === targetSize) return undefined;\n return Math.min(\n Math.max(targetSize / 2, focalCenter),\n srcSize - targetSize / 2,\n );\n}\n","/* eslint-disable no-param-reassign, jsx-a11y/alt-text */\nimport React, { ComponentPropsWithRef } from 'react';\nimport {\n calculateDimensions,\n createImagekitUrl,\n Options,\n} from './create-imagekit-url';\n\ninterface SizeTransformations {\n w?: number;\n h?: number;\n ar?: number;\n}\n\ntype BreakpointSetting =\n | number\n | [number, SizeTransformations | number]\n | SizeTransformations;\n\ninterface Props extends Omit<ComponentPropsWithRef<'img'>, 'src'> {\n src: Options['src'];\n breakpoints?: BreakpointSetting[];\n aspectRatio?: number;\n transformations?: Options['transformations'];\n}\n\nexport function ImagekitImage(props: Props) {\n const { src, transformations, breakpoints, aspectRatio, ...imgProps } = props;\n\n // If there are no breakpoints or an srcSet has already been provided, there\n // is nothing special we can do here. Just return an img component.\n if (!props.breakpoints?.length || props.srcSet) {\n return (\n <img src={createImagekitUrl({ src, transformations })} {...imgProps} />\n );\n }\n\n const imgSources: {\n // Used as key of this source.\n ar: number | undefined;\n\n // Used to calculate the props.\n minMax: { min?: number; max?: number }[];\n breakpoints: NormalizedBreakpoint[];\n\n // Calculated props.\n srcSet?: string;\n sizes?: string;\n media?: string;\n }[] = [];\n\n let largestImageUrl: [number, string] | null = null;\n\n if (props.breakpoints?.length && !props.srcSet) {\n const normalizedBreakpoints = props.breakpoints\n .map(normalizeBreakpoint)\n .map(b => {\n // If no ar was provided, use the aspectRatio prop.\n const sizes = { ar: props.aspectRatio, ...b[1] };\n\n // If there is an aspectRatio but no width, use the maxWidth as image\n // width.\n if (!sizes.h && !sizes.w && sizes.ar) {\n // eslint-disable-next-line prefer-destructuring\n sizes.w = b[0];\n }\n\n // Now calculate the final dimensions.\n const dimensions = calculateDimensions(sizes);\n\n // If no maxWidth was given and there was only a height and aspect ratio\n // available, we use the calculated w dimension as maxWidth.\n return [b[0] || dimensions.w, dimensions] as const;\n });\n\n normalizedBreakpoints.forEach(([maxWidth, sizes], i) => {\n // Set up the new image source.\n let set = imgSources.find(s => s.ar === sizes.ar);\n if (!set) {\n set = {\n ar: sizes.ar,\n minMax: [],\n breakpoints: [],\n };\n imgSources.push(set);\n }\n set.breakpoints.push([maxWidth, sizes]);\n\n // If the previous breakpoint has another aspect ratio, this is a new\n // source. This means that the min-width of this source is one pixel more\n // as the max-width of the previous source (which is the previous\n // breakpoint).\n const previousBreakpoint = normalizedBreakpoints[i - 1];\n if (!previousBreakpoint || previousBreakpoint[1].ar !== sizes.ar) {\n set.minMax.push({\n min: previousBreakpoint?.[0] ? previousBreakpoint[0] + 1 : undefined,\n });\n }\n\n // Set the max-width (will be overwritten until the last max-width of this\n // source).\n set.minMax[set.minMax.length - 1].max = maxWidth;\n });\n\n if (!imgSources.length) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be at least one image source (collection of breakpoints with the same aspect ratio).',\n );\n }\n\n // To make sure that the largest image is always shown, we remove the last\n // maxWidth on the source containing the last breakpoint.\n const largestSource = imgSources.find(\n source =>\n source.ar ===\n normalizedBreakpoints[normalizedBreakpoints.length - 1][1].ar,\n );\n if (largestSource) {\n delete largestSource.minMax[largestSource.minMax.length - 1].max;\n }\n\n imgSources.forEach((source, si) => {\n // Now, calculate the srcSet of every source.\n source.srcSet = source.breakpoints\n .map(([, sizes]) => {\n const imagekitUrlBreakpoint = createImagekitUrl({\n src,\n transformations: [\n ...(Array.isArray(transformations)\n ? transformations\n : transformations\n ? [transformations]\n : []),\n sizes,\n ],\n });\n\n if (sizes.w && (!largestImageUrl || largestImageUrl[0] < sizes.w)) {\n largestImageUrl = [sizes.w, imagekitUrlBreakpoint];\n }\n\n return `${imagekitUrlBreakpoint} ${sizes.w}w`;\n })\n .join(', ');\n\n // Calculate the sizes of every source.\n source.sizes =\n (source.breakpoints.length >= 2 &&\n !source.breakpoints.every(s => s[0] === s[1].w) &&\n source.breakpoints\n .map(([, sizes], i) => {\n const previousBreakpoint = source.breakpoints[i - 1];\n if (!previousBreakpoint || !previousBreakpoint[0]) {\n return `${sizes.w}px`;\n }\n return `(min-width: ${previousBreakpoint[0] + 1}px) ${sizes.w}px`;\n })\n .reverse()\n .join(', ')) ||\n '100vw';\n\n // Calculate the media prop of all sources.\n // If it's the first item, it will always be rendered. So there is no need\n // for a media query then.\n // If there is only one item in the minMax (there should be at least one)\n // then we only need to print it if it has a 'min'.\n if (si > 0 && (source.minMax.length > 1 || source.minMax[0].min)) {\n source.media = source.minMax\n .map(({ min, max }) =>\n min && max\n ? `(min-width: ${min}px) and (max-width: ${max}px)`\n : min\n ? `(min-width: ${min}px)`\n : `(max-width: ${max}px)`,\n )\n .join(', ');\n }\n });\n }\n\n if (!largestImageUrl) {\n throw new Error(\n 'Internal @burst/imagekit error - when there are breakpoints, there should be one image url generated.',\n );\n }\n\n // If there is just one source, we can do everything in one img element.\n if (imgSources.length === 1) {\n return (\n <img\n src={largestImageUrl[1]}\n srcSet={imgSources[0].srcSet}\n sizes={imgSources[0].sizes}\n {...imgProps}\n />\n );\n }\n\n // If it's more then one source, we will render a picture element. We need the\n // largest imgSource on top.\n imgSources.reverse();\n\n return (\n <picture>\n {imgSources.map(source => (\n <source\n key={source.ar || 'original'}\n media={source.media}\n srcSet={source.srcSet}\n sizes={source.sizes}\n />\n ))}\n <img\n src={largestImageUrl[1]}\n alt={(typeof props.src !== 'string' && props.src.alt) || undefined}\n {...imgProps}\n />\n </picture>\n );\n}\n\ntype NormalizedBreakpoint = [number | undefined, SizeTransformations];\n\nfunction normalizeBreakpoint(\n breakpoint: BreakpointSetting,\n): NormalizedBreakpoint {\n return typeof breakpoint === 'number'\n ? [breakpoint, { w: breakpoint }]\n : Array.isArray(breakpoint)\n ? [\n breakpoint[0],\n typeof breakpoint[1] === 'number'\n ? { w: breakpoint[1] }\n : breakpoint[1],\n ]\n : [breakpoint.w, breakpoint];\n}\n"],"names":["parseSource","src","url","entity","undefined","width","height","x","focalPoint","y","createImagekitTransformationsParameters","transformations","parameters","calculateDimensions","w","h","push","Math","round","cm","includes","fo","xc","yc","length","join","ar","Error","createImagekitUrl","options","originalTransformations","Array","isArray","targetDimensions","sourceDimensionsCropW","sourceDimensionsCropH","sourceDimensionsCrop","containWithinBoundary","map","filter","s","srcSize","focalCenter","targetSize","min","max","ImagekitImage","props","breakpoints","imgProps","srcSet","React","imgSources","largestImageUrl","normalizedBreakpoints","normalizeBreakpoint","b","sizes","aspectRatio","dimensions","forEach","i","maxWidth","set","find","minMax","previousBreakpoint","largestSource","source","si","imagekitUrlBreakpoint","every","reverse","media","key","alt","breakpoint"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAwBgBA,YAAYC;;;AAC1B,MAAI,OAAOA,GAAP,KAAe,QAAnB,EAA6B;AAC3B,WAAO;AAAEC,MAAAA,GAAG,EAAED;AAAP,KAAP;AACD;;AACD,SAAO;AACLC,IAAAA,GAAG,EAAE,CAAAD,GAAG,SAAH,IAAAA,GAAG,WAAH,2BAAAA,GAAG,CAAEE,MAAL,4DAAaD,GAAb,MAAoBD,GAApB,aAAoBA,GAApB,uBAAoBA,GAAG,CAAEC,GAAzB,KAAgCE,SADhC;AAELC,IAAAA,KAAK,EAAE,CAAAJ,GAAG,SAAH,IAAAA,GAAG,WAAH,YAAAA,GAAG,CAAEI,KAAL,KAAcD,SAFhB;AAGLE,IAAAA,MAAM,EAAE,CAAAL,GAAG,SAAH,IAAAA,GAAG,WAAH,YAAAA,GAAG,CAAEK,MAAL,KAAeF,SAHlB;AAILG,IAAAA,CAAC,EAAE,CAAAN,GAAG,SAAH,IAAAA,GAAG,WAAH,4BAAAA,GAAG,CAAEE,MAAL,uFAAaK,UAAb,gFAAyBD,CAAzB,KAA8BH,SAJ5B;AA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,GACI;AAAE9D,IAAAA,CAAC,EAAE8D,UAAU,CAAC,CAAD;AAAf,GADJ,GAEIA,UAAU,CAAC,CAAD,CAJhB,CADA,GAOA,CAACA,UAAU,CAAC9D,CAAZ,EAAe8D,UAAf,CATJ;AAUD;;;;"} |
+1
-0
| export { createImagekitUrl } from './create-imagekit-url'; | ||
| export { ImagekitImage } from './imagekit-image'; | ||
| export { ImagekitSrc } from './parse-source'; |
+1
-1
@@ -5,3 +5,3 @@ { | ||
| "repository": "https://git.burst-digital.com/protected/utils/react-components", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "sideEffects": false, | ||
@@ -8,0 +8,0 @@ "main": "dist/index.js", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
106665
0.51%13
8.33%685
1.93%0
-100%