@dropins/tools 1.3.0-beta4 → 1.3.0-beta5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunks/Image.js +1 -1
- package/lib/aem/assets.js +1 -1
- package/lib/aem/assets.js.map +1 -1
- package/package.json +1 -1
- package/types/elsie/src/lib/aem/assets.d.ts +77 -30
- package/lib/aem/assets.test.d.ts +0 -1
- package/lib/aem/assets.test.js +0 -4
- package/lib/aem/assets.test.js.map +0 -1
- package/lib/aem/configs.test.d.ts +0 -1
- package/lib/aem/configs.test.js +0 -4
- package/lib/aem/configs.test.js.map +0 -1
package/chunks/Image.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{jsx as o}from"../preact-jsx-runtime.js";import{G as w,T as c,k as x,h as y}from"./icons/Add.js";import{IntlProvider as f}from"../i18n.js";import{d as n}from"./cjs.js";import{R as T,
|
|
3
|
+
import{jsx as o}from"../preact-jsx-runtime.js";import{G as w,T as c,k as x,h as y}from"./icons/Add.js";import{IntlProvider as f}from"../i18n.js";import{d as n}from"./cjs.js";import{R as T,g as S,c as I}from"./vcomponent.js";const P={ExampleComponentName:{item:{label:"string"}},Pagination:{backwardButton:{ariaLabel:"Go to previous page"},forwardButton:{ariaLabel:"Go to next page"}},Incrementer:{decreaseLabel:"Decrease Quantity",increaseLabel:"Increase Quantity",label:"Quantity",errorMessage:"Enter a valid quantity",minQuantityMessage:"Enter at least {{minQuantity}}",maxQuantityMessage:"Maximum quantity is {{maxQuantity}}"},Modal:{Close:{label:"Close"}},InputPassword:{placeholder:"Password",floatingLabel:"Password",buttonShowTitle:"Click to show password",buttonHideTitle:"Click to hide password"},PasswordStatusIndicator:{chartTwoSymbols:"Use characters and numbers or symbols",chartThreeSymbols:"Use characters, numbers and symbols",chartFourSymbols:"Use uppercase characters, lowercase characters, numbers and symbols",messageLengthPassword:"At least {minLength} characters long"},InlineAlert:{dismissLabel:"Dismiss Alert"},PriceSummary:{subTotal:{label:"Subtotal",withTaxes:"Including taxes",withoutTaxes:"excluding taxes"},shipping:{label:"Shipping",editZipAction:"Apply",estimated:"Estimated Shipping",estimatedDestination:"Estimated Shipping to ",destinationLinkAriaLabel:"Change destination",zipPlaceholder:"Zip Code",withTaxes:"Including taxes",withoutTaxes:"excluding taxes",alternateField:{zip:"Estimate using country/zip",state:"Estimate using country/state"}},taxes:{total:"Tax Total",totalOnly:"Tax",breakdown:"Taxes",showBreakdown:"Show Tax Breakdown",hideBreakdown:"Hide Tax Breakdown",estimated:"Estimated Tax"},total:{estimated:"Estimated Total",label:"Total",withoutTax:"Total excluding taxes"}},ProgressSpinner:{updating:{label:"Item is updating"},updatingChildren:{label:"Items are updating"}},PriceRange:{from:{label:"From"},to:{label:"to"},asLowAs:{label:"As low as"}},Swatches:{outOfStock:{label:"out of stock swatch"},selected:{label:"swatch selected"},swatch:{label:"swatch"}},Accordion:{open:{label:"Open"},close:{label:"Close"}},CartItem:{each:{label:"each"},pricePerItem:{label:"price per item"},quantity:{label:"Quantity"},remove:{label:"Remove {product} from the cart"},removeDefault:{label:"Remove item from the cart"},taxIncluded:{label:"incl. VAT"},taxExcluded:{label:"excl. tax"},updating:{label:"{product} is updating"}},InputDate:{picker:"Select a date"}},r={Dropin:P},d={default:r,en_US:r},k=e=>n(d.default,d[e]||{}),v=w({locale:"en-US"}),C=({lang:e="en_US",langDefinitions:t={},children:a})=>{const l=c(()=>{const i=n(t.default,t[e]??{});return n(k(e),i)},[e,t]),s=e.replace("_","-");return o(v.Provider,{value:{locale:s},children:o(f,{definition:l,children:o(x,{children:a})})})},B=new T(o(C,{})),D=({className:e,src:t,params:a,loading:l="lazy",srcSet:s,onLoad:i,...u})=>{const[m,p]=y(!1),b=c(()=>{if(s)return s;if(!(!t||!a))return S(t,{...a})},[a,t,s]),h=g=>{p(!0),i==null||i(g)};return o("img",{...u,className:I(["dropin-image",["dropin-image--loaded",m],e]),loading:l,onLoad:h,src:t,srcSet:b})};export{D as I,v as U,C as a,B as p};
|
|
4
4
|
//# sourceMappingURL=Image.js.map
|
package/lib/aem/assets.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! Copyright 2025 Adobe
|
|
2
2
|
All Rights Reserved. */
|
|
3
|
-
import{getConfigValue as
|
|
3
|
+
import{getConfigValue as O}from"./configs.js";import{p as f,I as g}from"../../chunks/Image.js";import"../../chunks/cjs.js";import"../../chunks/get-path-value.js";import"../../preact-jsx-runtime.js";import"../../chunks/icons/Add.js";import"../../i18n.js";import"../../chunks/vcomponent.js";import"../../chunks/image-params-keymap.js";import"../../signals.js";const b=["gif","jpg","jpeg","png","webp"],v=[90,180,270],U=["h","v","hv"];function l(e){let t=e;if(t.startsWith("//")){const{protocol:s}=window.location;t=s+t}return t}function I(e){return U.includes(e)}function L(e){return v.includes(e)}function y(e){return b.includes(e)}function u(e,t,s){if(e!==void 0&&!t(e))throw new Error(s)}function h(){const e=O("commerce-assets-enabled");return e&&(typeof e=="string"&&e.toLowerCase()==="true"||typeof e=="boolean"&&e===!0)}function R(){return{quality:80,format:"webp"}}function A(e){return!!(typeof e=="string"?new URL(l(e)):e).pathname.startsWith("/adobe/assets/urn:aaid:aem")}function w(e,t,s={}){const r={...R(),...s},{format:i,crop:n,...o}=r;u(i,y,"Invalid format"),u(o.flip,I,"Invalid flip"),u(o.rotate,L,"Invalid rotation");const a=Object.fromEntries(Object.entries(o).map(([p,d])=>[p,String(d)])),c=new URLSearchParams(a);if(n){const[p,d]=[n.xOrigin||0,n.yOrigin||0],[P,E]=[n.width||100,n.height||100],S=`${p}p,${d}p,${P}p,${E}p`;c.set("crop",S)}return`${e}/as/${t}.${i}?${c.toString()}`}function q(e,t,s={}){if(!h())return e;const r=new URL(l(e));if(!A(r))return e;const i=r.origin+r.pathname;return w(i,t,s)}function _(e){return t=>{const{wrapper:s,alias:m,params:r,imageProps:i}=e;if(!i.src)throw new Error("An image source is required. Please provide a `src` or `imageProps.src`.");const n=s??document.createElement("div"),o=w(i.src,m,r),a={width:r.width,height:r.height,crop:void 0,fit:void 0,auto:void 0},c={...i,width:r.width,height:r.height,src:o,params:a};f.render(g,c)(n),t.replaceWith(n)}}function x(e,t){function s(){const i=t.wrapper??document.createElement("div"),{imageProps:n,params:o}=t,a={...n,width:o.width,height:o.height};f.render(g,a)(i),e.replaceWith(i)}if(!h()){s();return}if(!t.imageProps.src)throw new Error("An image source is required. Please provide a `src` or `imageProps.src`.");const r=new URL(l(t.imageProps.src));if(!A(r)){s();return}_(t)(e)}export{w as generateAemAssetsOptimizedUrl,R as getDefaultAemAssetsOptimizationParams,h as isAemAssetsEnabled,A as isAemAssetsUrl,_ as makeAemAssetsImageSlot,q as tryGenerateAemAssetsOptimizedUrl,x as tryRenderAemAssetsImage};
|
|
4
4
|
//# sourceMappingURL=assets.js.map
|
package/lib/aem/assets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assets.js","sources":["/@dropins/tools/src/lib/aem/assets.ts"],"sourcesContent":["import { provider as UI, Image } from '@adobe-commerce/elsie/components';\nimport { getConfigValue } from '@adobe-commerce/elsie/lib/aem/configs';\n\ninterface AemAssetsParams {\n quality?: number;\n format?: string;\n crop?: {\n xOrigin?: number;\n yOrigin?: number;\n width?: number;\n height?: number;\n };\n size?: {\n width?: number;\n height?: number;\n };\n width?: number;\n height?: number;\n [key: string]: any;\n}\n\ninterface AemAssetsImageConfig {\n wrapper?: HTMLElement;\n alias: string;\n params: AemAssetsParams;\n imageProps: {\n src: string;\n width?: number;\n height?: number;\n [key: string]: any;\n };\n src?: string;\n}\n\ninterface RenderContext {\n replaceWith: (element: HTMLElement) => void;\n}\n\nexport function isAemAssetsEnabled(): boolean {\n const config = getConfigValue('commerce-assets-enabled');\n\n return config && (\n (typeof config === 'string' && config.toLowerCase() === 'true')\n || (typeof config === 'boolean' && config === true)\n );\n}\n\nexport function getDefaultAemAssetsOptimizationParams(): { quality: number; format: string } {\n // See: https://adobe-aem-assets-delivery-experimental.redoc.ly/\n return {\n quality: 80,\n format: 'webp',\n };\n}\n\n/**\n * Normalizes the given URL to ensure it is a valid URL.\n * @param {string} url - The URL to normalize.\n * @returns {string} The normalized URL.\n */\nfunction normalizeUrl(url: string): string {\n let imageUrl = url;\n\n if (imageUrl.startsWith('//')) {\n // Use current window's protocol.\n const { protocol } = window.location;\n console.log('protocol', protocol);\n imageUrl = protocol + imageUrl;\n }\n\n return imageUrl;\n}\n\nexport function isAemAssetsUrl(url: string | URL): boolean {\n const assetsUrl = typeof url === 'string' ? new URL(normalizeUrl(url)) : url;\n\n if (!assetsUrl.pathname.startsWith('/adobe/assets/urn:aaid:aem')) {\n return false;\n }\n\n return true;\n}\n\nexport function generateAemAssetsOptimizedUrl(url: string, alias: string, params: AemAssetsParams = {}): string {\n const defaultParams = getDefaultAemAssetsOptimizationParams();\n const mergedParams: AemAssetsParams = { ...defaultParams, ...params };\n\n // Destructure the ones that need special handling\n const {\n format,\n crop,\n size,\n ...optimizedParams\n } = mergedParams;\n\n const searchParams = new URLSearchParams(optimizedParams);\n\n if (crop) {\n const [xOrigin, yOrigin] = [crop.xOrigin || 0, crop.yOrigin || 0];\n const [width, height] = [crop.width || 100, crop.height || 100];\n\n const cropTransform = `${xOrigin}p,${yOrigin}p,${width}p,${height}p`;\n searchParams.set('crop', cropTransform);\n }\n\n // Both values must be present\n if (size && size.width && size.height) {\n searchParams.set('size', `${size.width},${size.height}`);\n }\n\n return `${url}/as/${alias}.${format}?${searchParams.toString()}`;\n}\n\nexport function tryGenerateAemAssetsOptimizedUrl(url: string, alias: string, params: AemAssetsParams = {}): string {\n const assetsEnabled = isAemAssetsEnabled();\n\n if (!(assetsEnabled)) {\n // No-op, doesn't do anything.\n return url;\n }\n\n const assetsUrl = new URL(normalizeUrl(url));\n\n if (!isAemAssetsUrl(assetsUrl)) {\n // Not an AEM Assets URL, so no-op.\n return url;\n }\n\n const base = assetsUrl.origin + assetsUrl.pathname;\n return generateAemAssetsOptimizedUrl(base, alias, params);\n}\n\nexport function makeAemAssetsImageSlot(\n config: AemAssetsImageConfig,\n) {\n return (ctx: RenderContext) => {\n const {\n wrapper,\n alias,\n params,\n imageProps,\n src,\n } = config;\n\n const container = wrapper ?? document.createElement('div');\n const imageSrc = generateAemAssetsOptimizedUrl(src || imageProps.src, alias, params);\n\n UI.render(Image as any, {\n ...imageProps,\n\n src: imageSrc,\n params: {\n width: params.width,\n\n // If not null, they will be applied by default.\n // And they are not compatible with the AEM Assets API.\n crop: null,\n fit: null,\n auto: null,\n },\n })(container);\n\n ctx.replaceWith(container);\n };\n}\n\nexport function tryRenderAemAssetsImage(ctx: RenderContext, config: AemAssetsImageConfig): void {\n // Renders an equivalent of the default image.\n function renderDefaultImage(): void {\n const container = config.wrapper ?? document.createElement('div');\n const { imageProps } = config;\n\n (UI.render as any)(Image, imageProps)(container);\n ctx.replaceWith(container);\n }\n\n const assetsEnabled = isAemAssetsEnabled();\n\n if (!(assetsEnabled)) {\n // No-op, render the default image.\n renderDefaultImage();\n return;\n }\n\n const { imageProps, src, ...slotConfig } = config;\n const assetsUrl = new URL(normalizeUrl(src ?? imageProps.src));\n\n if (!isAemAssetsUrl(assetsUrl)) {\n // Not an AEM Assets URL, so render the default image.\n renderDefaultImage();\n return;\n }\n\n makeAemAssetsImageSlot({\n // Use the default image props for params and src.\n // Unless overriden by the slot config.\n src: assetsUrl.toString(),\n params: {\n width: imageProps.width,\n height: imageProps.height,\n ...slotConfig.params,\n },\n imageProps,\n alias: slotConfig.alias,\n wrapper: slotConfig.wrapper,\n })(ctx);\n}\n"],"names":["isAemAssetsEnabled","config","getConfigValue","getDefaultAemAssetsOptimizationParams","normalizeUrl","url","imageUrl","protocol","isAemAssetsUrl","generateAemAssetsOptimizedUrl","alias","params","mergedParams","format","crop","size","optimizedParams","searchParams","xOrigin","yOrigin","width","height","cropTransform","tryGenerateAemAssetsOptimizedUrl","assetsUrl","base","makeAemAssetsImageSlot","ctx","wrapper","imageProps","src","container","imageSrc","UI","Image","tryRenderAemAssetsImage","renderDefaultImage","slotConfig"],"mappings":"sWAsCO,SAASA,GAA8B,CACtC,MAAAC,EAASC,EAAe,yBAAyB,EAEhD,OAAAD,IACJ,OAAOA,GAAW,UAAYA,EAAO,gBAAkB,QACpD,OAAOA,GAAW,WAAaA,IAAW,GAElD,CAEO,SAASE,GAA6E,CAEpF,MAAA,CACL,QAAS,GACT,OAAQ,MACV,CACF,CAOA,SAASC,EAAaC,EAAqB,CACzC,IAAIC,EAAWD,EAEX,GAAAC,EAAS,WAAW,IAAI,EAAG,CAEvB,KAAA,CAAE,SAAAC,GAAa,OAAO,SACpB,QAAA,IAAI,WAAYA,CAAQ,EAChCD,EAAWC,EAAWD,CAAA,CAGjB,OAAAA,CACT,CAEO,SAASE,EAAeH,EAA4B,CAGzD,MAAK,GAFa,OAAOA,GAAQ,SAAW,IAAI,IAAID,EAAaC,CAAG,CAAC,EAAIA,GAE1D,SAAS,WAAW,4BAA4B,CAKjE,CAEO,SAASI,EAA8BJ,EAAaK,EAAeC,EAA0B,CAAA,EAAY,CAE9G,MAAMC,EAAgC,CAAE,GADlBT,EAAsC,EACF,GAAGQ,CAAO,EAG9D,CACJ,OAAAE,EACA,KAAAC,EACA,KAAAC,EACA,GAAGC,CAAA,EACDJ,EAEEK,EAAe,IAAI,gBAAgBD,CAAe,EAExD,GAAIF,EAAM,CACF,KAAA,CAACI,EAASC,CAAO,EAAI,CAACL,EAAK,SAAW,EAAGA,EAAK,SAAW,CAAC,EAC1D,CAACM,EAAOC,CAAM,EAAI,CAACP,EAAK,OAAS,IAAKA,EAAK,QAAU,GAAG,EAExDQ,EAAgB,GAAGJ,CAAO,KAAKC,CAAO,KAAKC,CAAK,KAAKC,CAAM,IACpDJ,EAAA,IAAI,OAAQK,CAAa,CAAA,CAIxC,OAAIP,GAAQA,EAAK,OAASA,EAAK,QAChBE,EAAA,IAAI,OAAQ,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0B,GAAOD,EAAW,GAAG,CAAC,EAEzD,GAAA,CAACrB,EAAegB,CAAS,EAAG,CAEXY,EAAA,EACnB,MAAA,CAGqBV,EAAA,CAGrB,IAAKF,EAAU,SAAS,EACxB,OAAQ,CACN,MAAOK,EAAW,MAClB,OAAQA,EAAW,OACnB,GAAGQ,EAAW,MAChB,EACA,WAAAR,EACA,MAAOQ,EAAW,MAClB,QAASA,EAAW,OACrB,CAAA,EAAEV,CAAG,CACR"}
|
|
1
|
+
{"version":3,"file":"assets.js","sources":["/@dropins/tools/src/lib/aem/assets.ts"],"sourcesContent":["import {\n provider as UI,\n Image,\n type ImageProps,\n} from '@adobe-commerce/elsie/components';\n\nimport { getConfigValue } from '@adobe-commerce/elsie/lib/aem/configs';\nimport type { ResolveImageUrlOptions } from '../resolve-image';\n\nconst AEM_ASSETS_FORMATS = ['gif', 'jpg', 'jpeg', 'png', 'webp'] as const;\nconst AEM_ASSETS_ALLOWED_ROTATIONS = [90, 180, 270] as const;\nconst AEM_ASSETS_ALLOWED_FLIPS = ['h', 'v', 'hv'] as const;\n\n/** The allowed formats for the `AEM Assets` image optimization API. */\nexport type AemAssetsFormat = (typeof AEM_ASSETS_FORMATS)[number];\n\n/** The allowed rotations for the `AEM Assets` image optimization API. */\nexport type AemAssetsRotation = (typeof AEM_ASSETS_ALLOWED_ROTATIONS)[number];\n\n/** The allowed flips for the `AEM Assets` image optimization API. */\nexport type AemAssetsFlip = (typeof AEM_ASSETS_ALLOWED_FLIPS)[number];\n\n/**\n * Defines a crop region of an image.\n * @example\n * ```ts\n * // Crop the image to a 80% width and height, starting at 10% from the top and left.\n * const cropSettings: AemAssetsCropSettings = {\n * xOrigin: 10,\n * yOrigin: 10,\n * width: 80,\n * height: 80,\n * };\n */\nexport interface AemAssetsCropSettings {\n /** The (relative) x origin of the crop (between 0 and 100) */\n xOrigin?: number;\n\n /** The (relative) y origin of the crop (between 0 and 100) */\n yOrigin?: number;\n\n /** The width of the crop (between 0 and 100) */\n width?: number;\n\n /** The height of the crop (between 0 and 100) */\n height?: number;\n}\n\n/**\n * The parameters accepted by the `AEM Assets` image optimization API.\n * @see https://adobe-aem-assets-delivery-experimental.redoc.ly/\n */\nexport interface AemAssetsParams {\n format: AemAssetsFormat;\n rotate?: AemAssetsRotation;\n flip?: AemAssetsFlip;\n crop?: AemAssetsCropSettings;\n\n width?: number;\n height?: number;\n quality?: number;\n\n attachment?: boolean;\n sharpen?: boolean;\n blur?: number;\n dpr?: number;\n smartCrop?: string;\n\n // For future updates we may miss.\n [key: string]: unknown;\n}\n\ntype WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] };\n\n/** The parameters to be applied to the asset (known width required when using a slot) */\nexport type AemAssetsImageSlotConfigParams = WithRequired<\n Partial<AemAssetsParams>,\n 'width'\n>;\n\n/** The configuration for an image slot. */\nexport interface AemAssetsImageSlotConfig {\n /** The alias (i.e. seoName) of the image */\n alias: string;\n\n /** The props to be applied to the underlying {@link Image} component */\n imageProps: Partial<Omit<ImageProps, 'params' | 'width' | 'height'>> & {\n src: string;\n };\n\n /** The parameters to be applied to the asset (known width required when using a slot) */\n params: AemAssetsImageSlotConfigParams;\n\n /** The element that will contain the image in the slot */\n wrapper?: HTMLElement;\n}\n\ninterface RenderContext {\n replaceWith: (element: HTMLElement) => void;\n}\n\n/**\n * Normalizes the given URL to ensure it is a valid URL.\n * @param {string} url - The URL to normalize.\n * @returns {string} The normalized URL.\n */\nfunction normalizeUrl(url: string): string {\n let imageUrl = url;\n\n if (imageUrl.startsWith('//')) {\n // Use current window's protocol.\n const { protocol } = window.location;\n imageUrl = protocol + imageUrl;\n }\n\n return imageUrl;\n}\n\n/** Returns whether the given value is a valid flip. */\nfunction isValidFlip(flip: unknown): flip is AemAssetsFlip {\n return AEM_ASSETS_ALLOWED_FLIPS.includes(flip as AemAssetsFlip);\n}\n\n/** Returns whether the given value is a valid rotation. */\nfunction isValidRotation(rotation: unknown): rotation is AemAssetsRotation {\n return AEM_ASSETS_ALLOWED_ROTATIONS.includes(rotation as AemAssetsRotation);\n}\n\n/** Returns whether the given value is a valid format. */\nfunction isValidFormat(format: unknown): format is AemAssetsFormat {\n return AEM_ASSETS_FORMATS.includes(format as AemAssetsFormat);\n}\n\n/** Asserts that the given value is valid. */\nfunction assertUnionParameter(\n value: unknown,\n validator: (value: unknown) => boolean,\n errorMessage: string\n): void {\n if (value !== undefined && !validator(value)) {\n throw new Error(errorMessage);\n }\n}\n\n/** Returns whether AEM Assets is enabled in the Storefront. */\nexport function isAemAssetsEnabled(): boolean {\n const config = getConfigValue('commerce-assets-enabled');\n\n return (\n config &&\n ((typeof config === 'string' && config.toLowerCase() === 'true') ||\n (typeof config === 'boolean' && config === true))\n );\n}\n\n/** The default optimization parameters used globally, unless overriden (per use). */\nexport function getDefaultAemAssetsOptimizationParams(): AemAssetsParams {\n // See: https://adobe-aem-assets-delivery-experimental.redoc.ly/\n return {\n quality: 80,\n format: 'webp',\n };\n}\n\n/** Returns true if the given URL is an AEM Assets URL. */\nexport function isAemAssetsUrl(url: string | URL): boolean {\n const assetsUrl = typeof url === 'string' ? new URL(normalizeUrl(url)) : url;\n\n if (!assetsUrl.pathname.startsWith('/adobe/assets/urn:aaid:aem')) {\n return false;\n }\n\n return true;\n}\n\n/** Generates an optimized URL for AEM Assets. */\nexport function generateAemAssetsOptimizedUrl(\n assetUrl: string,\n alias: string,\n params: Partial<AemAssetsParams> = {}\n): string {\n const defaultParams = getDefaultAemAssetsOptimizationParams();\n const mergedParams: AemAssetsParams = { ...defaultParams, ...params };\n\n // Destructure the ones that need special handling/validation.\n const { format, crop, ...optimizedParams } = mergedParams;\n assertUnionParameter(format, isValidFormat, 'Invalid format');\n assertUnionParameter(optimizedParams.flip, isValidFlip, 'Invalid flip');\n assertUnionParameter(\n optimizedParams.rotate,\n isValidRotation,\n 'Invalid rotation'\n );\n\n const stringifiedParams = Object.fromEntries(\n Object.entries(optimizedParams).map(([key, value]) => [key, String(value)])\n );\n\n const searchParams = new URLSearchParams(stringifiedParams);\n\n if (crop) {\n const [xOrigin, yOrigin] = [crop.xOrigin || 0, crop.yOrigin || 0];\n const [width, height] = [crop.width || 100, crop.height || 100];\n\n const cropTransform = `${xOrigin}p,${yOrigin}p,${width}p,${height}p`;\n searchParams.set('crop', cropTransform);\n }\n\n return `${assetUrl}/as/${alias}.${format}?${searchParams.toString()}`;\n}\n\n/**\n * Tries to generate an optimized URL for AEM Assets. Returns the given\n * url if AEM Assets is not enabled or is not an AEM Assets URL.\n */\nexport function tryGenerateAemAssetsOptimizedUrl(\n assetUrl: string,\n alias: string,\n params: Partial<AemAssetsParams> = {}\n): string {\n const assetsEnabled = isAemAssetsEnabled();\n\n if (!assetsEnabled) {\n // No-op, doesn't do anything.\n return assetUrl;\n }\n\n const assetsUrl = new URL(normalizeUrl(assetUrl));\n\n if (!isAemAssetsUrl(assetsUrl)) {\n // Not an AEM Assets URL, so no-op.\n return assetUrl;\n }\n\n const base = assetsUrl.origin + assetsUrl.pathname;\n return generateAemAssetsOptimizedUrl(base, alias, params);\n}\n\n/** Creates a slot that renders an AEM Assets image. */\nexport function makeAemAssetsImageSlot(config: AemAssetsImageSlotConfig) {\n return (ctx: RenderContext) => {\n const { wrapper, alias, params, imageProps } = config;\n\n if (!imageProps.src) {\n throw new Error(\n 'An image source is required. Please provide a `src` or `imageProps.src`.'\n );\n }\n\n const container = wrapper ?? document.createElement('div');\n const imageSrc = generateAemAssetsOptimizedUrl(\n imageProps.src,\n alias,\n params\n );\n\n const imageComponentParams: ResolveImageUrlOptions = {\n width: params.width,\n height: params.height,\n\n // If this is not done, they will be applied by default.\n // And they are not compatible with the AEM Assets API.\n crop: undefined,\n fit: undefined,\n auto: undefined,\n };\n\n const imageComponentProps: ImageProps = {\n ...imageProps,\n width: params.width,\n height: params.height,\n\n src: imageSrc,\n params: imageComponentParams,\n };\n\n UI.render(Image, imageComponentProps)(container);\n ctx.replaceWith(container);\n };\n}\n\nexport function tryRenderAemAssetsImage(\n ctx: RenderContext,\n config: AemAssetsImageSlotConfig\n): void {\n // Renders an equivalent of the default image.\n function renderDefaultImage(): void {\n const container = config.wrapper ?? document.createElement('div');\n const { imageProps, params } = config;\n const imageComponentProps: ImageProps = {\n ...imageProps,\n width: params.width,\n height: params.height,\n };\n\n UI.render(Image, imageComponentProps)(container);\n ctx.replaceWith(container);\n }\n\n const assetsEnabled = isAemAssetsEnabled();\n\n if (!assetsEnabled) {\n // No-op, render the default image.\n renderDefaultImage();\n return;\n }\n\n if (!config.imageProps.src) {\n throw new Error(\n 'An image source is required. Please provide a `src` or `imageProps.src`.'\n );\n }\n\n const assetsUrl = new URL(normalizeUrl(config.imageProps.src));\n\n if (!isAemAssetsUrl(assetsUrl)) {\n // Not an AEM Assets URL, so render the default image.\n renderDefaultImage();\n return;\n }\n\n makeAemAssetsImageSlot(config)(ctx);\n}\n"],"names":["AEM_ASSETS_FORMATS","AEM_ASSETS_ALLOWED_ROTATIONS","AEM_ASSETS_ALLOWED_FLIPS","normalizeUrl","url","imageUrl","protocol","isValidFlip","flip","isValidRotation","rotation","isValidFormat","format","assertUnionParameter","value","validator","errorMessage","isAemAssetsEnabled","config","getConfigValue","getDefaultAemAssetsOptimizationParams","isAemAssetsUrl","generateAemAssetsOptimizedUrl","assetUrl","alias","params","mergedParams","crop","optimizedParams","stringifiedParams","key","searchParams","xOrigin","yOrigin","width","height","cropTransform","tryGenerateAemAssetsOptimizedUrl","assetsUrl","base","makeAemAssetsImageSlot","ctx","wrapper","imageProps","container","imageSrc","imageComponentParams","imageComponentProps","UI","Image","tryRenderAemAssetsImage","renderDefaultImage"],"mappings":"sWASA,MAAMA,EAAqB,CAAC,MAAO,MAAO,OAAQ,MAAO,MAAM,EACzDC,EAA+B,CAAC,GAAI,IAAK,GAAG,EAC5CC,EAA2B,CAAC,IAAK,IAAK,IAAI,EA+FhD,SAASC,EAAaC,EAAqB,CACzC,IAAIC,EAAWD,EAEX,GAAAC,EAAS,WAAW,IAAI,EAAG,CAEvB,KAAA,CAA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EN,SAASiC,GAA2B,CAClC,MAAMP,EAAY1B,EAAO,SAAW,SAAS,cAAc,KAAK,EAC1D,CAAE,WAAAyB,EAAY,OAAAlB,CAAA,EAAWP,EACzB6B,EAAkC,CACtC,GAAGJ,EACH,MAAOlB,EAAO,MACd,OAAQA,EAAO,MACjB,EAEAuB,EAAG,OAAOC,EAAOF,CAAmB,EAAEH,CAAS,EAC/CH,EAAI,YAAYG,CAAS,CAAA,CAK3B,GAAI,CAFkB3B,EAAmB,EAErB,CAECkC,EAAA,EACnB,MAAA,CAGE,GAAA,CAACjC,EAAO,WAAW,IACrB,MAAM,IAAI,MACR,0EACF,EAGF,MAAMoB,EAAY,IAAI,IAAInC,EAAae,EAAO,WAAW,GAAG,CAAC,EAEzD,GAAA,CAACG,EAAeiB,CAAS,EAAG,CAEXa,EAAA,EACnB,MAAA,CAGqBX,EAAAtB,CAAM,EAAEuB,CAAG,CACpC"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/tools", "version": "1.3.0-
|
|
1
|
+
{"name": "@dropins/tools", "version": "1.3.0-beta5", "license": "SEE LICENSE IN LICENSE.md"}
|
|
@@ -1,44 +1,91 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ImageProps } from '../../components';
|
|
2
|
+
|
|
3
|
+
declare const AEM_ASSETS_FORMATS: readonly ["gif", "jpg", "jpeg", "png", "webp"];
|
|
4
|
+
declare const AEM_ASSETS_ALLOWED_ROTATIONS: readonly [90, 180, 270];
|
|
5
|
+
declare const AEM_ASSETS_ALLOWED_FLIPS: readonly ["h", "v", "hv"];
|
|
6
|
+
/** The allowed formats for the `AEM Assets` image optimization API. */
|
|
7
|
+
export type AemAssetsFormat = (typeof AEM_ASSETS_FORMATS)[number];
|
|
8
|
+
/** The allowed rotations for the `AEM Assets` image optimization API. */
|
|
9
|
+
export type AemAssetsRotation = (typeof AEM_ASSETS_ALLOWED_ROTATIONS)[number];
|
|
10
|
+
/** The allowed flips for the `AEM Assets` image optimization API. */
|
|
11
|
+
export type AemAssetsFlip = (typeof AEM_ASSETS_ALLOWED_FLIPS)[number];
|
|
12
|
+
/**
|
|
13
|
+
* Defines a crop region of an image.
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Crop the image to a 80% width and height, starting at 10% from the top and left.
|
|
17
|
+
* const cropSettings: AemAssetsCropSettings = {
|
|
18
|
+
* xOrigin: 10,
|
|
19
|
+
* yOrigin: 10,
|
|
20
|
+
* width: 80,
|
|
21
|
+
* height: 80,
|
|
22
|
+
* };
|
|
23
|
+
*/
|
|
24
|
+
export interface AemAssetsCropSettings {
|
|
25
|
+
/** The (relative) x origin of the crop (between 0 and 100) */
|
|
26
|
+
xOrigin?: number;
|
|
27
|
+
/** The (relative) y origin of the crop (between 0 and 100) */
|
|
28
|
+
yOrigin?: number;
|
|
29
|
+
/** The width of the crop (between 0 and 100) */
|
|
14
30
|
width?: number;
|
|
31
|
+
/** The height of the crop (between 0 and 100) */
|
|
15
32
|
height?: number;
|
|
16
|
-
[key: string]: any;
|
|
17
33
|
}
|
|
18
|
-
|
|
19
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The parameters accepted by the `AEM Assets` image optimization API.
|
|
36
|
+
* @see https://adobe-aem-assets-delivery-experimental.redoc.ly/
|
|
37
|
+
*/
|
|
38
|
+
export interface AemAssetsParams {
|
|
39
|
+
format: AemAssetsFormat;
|
|
40
|
+
rotate?: AemAssetsRotation;
|
|
41
|
+
flip?: AemAssetsFlip;
|
|
42
|
+
crop?: AemAssetsCropSettings;
|
|
43
|
+
width?: number;
|
|
44
|
+
height?: number;
|
|
45
|
+
quality?: number;
|
|
46
|
+
attachment?: boolean;
|
|
47
|
+
sharpen?: boolean;
|
|
48
|
+
blur?: number;
|
|
49
|
+
dpr?: number;
|
|
50
|
+
smartCrop?: string;
|
|
51
|
+
[key: string]: unknown;
|
|
52
|
+
}
|
|
53
|
+
type WithRequired<T, K extends keyof T> = T & {
|
|
54
|
+
[P in K]-?: T[P];
|
|
55
|
+
};
|
|
56
|
+
/** The parameters to be applied to the asset (known width required when using a slot) */
|
|
57
|
+
export type AemAssetsImageSlotConfigParams = WithRequired<Partial<AemAssetsParams>, 'width'>;
|
|
58
|
+
/** The configuration for an image slot. */
|
|
59
|
+
export interface AemAssetsImageSlotConfig {
|
|
60
|
+
/** The alias (i.e. seoName) of the image */
|
|
20
61
|
alias: string;
|
|
21
|
-
|
|
22
|
-
imageProps: {
|
|
62
|
+
/** The props to be applied to the underlying {@link Image} component */
|
|
63
|
+
imageProps: Partial<Omit<ImageProps, 'params' | 'width' | 'height'>> & {
|
|
23
64
|
src: string;
|
|
24
|
-
width?: number;
|
|
25
|
-
height?: number;
|
|
26
|
-
[key: string]: any;
|
|
27
65
|
};
|
|
28
|
-
|
|
66
|
+
/** The parameters to be applied to the asset (known width required when using a slot) */
|
|
67
|
+
params: AemAssetsImageSlotConfigParams;
|
|
68
|
+
/** The element that will contain the image in the slot */
|
|
69
|
+
wrapper?: HTMLElement;
|
|
29
70
|
}
|
|
30
71
|
interface RenderContext {
|
|
31
72
|
replaceWith: (element: HTMLElement) => void;
|
|
32
73
|
}
|
|
74
|
+
/** Returns whether AEM Assets is enabled in the Storefront. */
|
|
33
75
|
export declare function isAemAssetsEnabled(): boolean;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
76
|
+
/** The default optimization parameters used globally, unless overriden (per use). */
|
|
77
|
+
export declare function getDefaultAemAssetsOptimizationParams(): AemAssetsParams;
|
|
78
|
+
/** Returns true if the given URL is an AEM Assets URL. */
|
|
38
79
|
export declare function isAemAssetsUrl(url: string | URL): boolean;
|
|
39
|
-
|
|
40
|
-
export declare function
|
|
41
|
-
|
|
42
|
-
|
|
80
|
+
/** Generates an optimized URL for AEM Assets. */
|
|
81
|
+
export declare function generateAemAssetsOptimizedUrl(assetUrl: string, alias: string, params?: Partial<AemAssetsParams>): string;
|
|
82
|
+
/**
|
|
83
|
+
* Tries to generate an optimized URL for AEM Assets. Returns the given
|
|
84
|
+
* url if AEM Assets is not enabled or is not an AEM Assets URL.
|
|
85
|
+
*/
|
|
86
|
+
export declare function tryGenerateAemAssetsOptimizedUrl(assetUrl: string, alias: string, params?: Partial<AemAssetsParams>): string;
|
|
87
|
+
/** Creates a slot that renders an AEM Assets image. */
|
|
88
|
+
export declare function makeAemAssetsImageSlot(config: AemAssetsImageSlotConfig): (ctx: RenderContext) => void;
|
|
89
|
+
export declare function tryRenderAemAssetsImage(ctx: RenderContext, config: AemAssetsImageSlotConfig): void;
|
|
43
90
|
export {};
|
|
44
91
|
//# sourceMappingURL=assets.d.ts.map
|
package/lib/aem/assets.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../types/elsie/src/lib/aem/assets.test'
|
package/lib/aem/assets.test.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/*! Copyright 2025 Adobe
|
|
2
|
-
All Rights Reserved. */
|
|
3
|
-
import{isAemAssetsEnabled as m,getDefaultAemAssetsOptimizationParams as n,isAemAssetsUrl as l,generateAemAssetsOptimizedUrl as o,tryGenerateAemAssetsOptimizedUrl as i,makeAemAssetsImageSlot as c,tryRenderAemAssetsImage as p}from"./assets.js";import{getConfigValue as r}from"./configs.js";import"../../chunks/Image.js";import"../../preact-jsx-runtime.js";import"../../chunks/icons/Add.js";import"../../i18n.js";import"../../chunks/cjs.js";import"../../chunks/vcomponent.js";import"../../chunks/image-params-keymap.js";import"../../signals.js";import"../../chunks/get-path-value.js";jest.mock("./configs",()=>({getConfigValue:jest.fn().mockImplementation(e=>{if(e==="commerce-assets-enabled")return!0})}));Object.defineProperty(window,"location",{value:{pathname:"/",origin:"https://example.com",protocol:"https:"}});describe("AEM Assets",()=>{beforeEach(()=>{jest.clearAllMocks()}),test("should be enabled",()=>{expect(m()).toBe(!0),r.mockReturnValueOnce("true"),expect(m()).toBe(!0)}),test("should be disabled",()=>{r.mockReturnValueOnce(!1),expect(m()).toBe(!1)}),test("should return default optimization params",()=>{const e=n();expect(e).toEqual({quality:80,format:"webp"})}),test("should return true if url is aem assets url",()=>{expect(l("https://example.com/adobe/assets/urn:aaid:aem:1234567890")).toBe(!0)}),test("should return false if url is not aem assets url",()=>{expect(l("https://example.com/image.jpg")).toBe(!1)}),test("should return true if url is aem assets url with protocol relative path",()=>{expect(l("//example.com/adobe/assets/urn:aaid:aem:1234567890")).toBe(!0)}),test("should generate aem assets optimized url",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp"});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80")}),test("should generate aem assets optimized url with default params",()=>{const a=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test");expect(a).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80")}),test("should generate aem assets optimized url with crop",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",crop:{xOrigin:0,yOrigin:0}});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p")}),test("should generate aem assets optimized url with size",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",size:{width:100,height:100}});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&size=100%2C100")}),test("should generate aem assets optimized url with width and height",()=>{const t=o("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",width:100,height:100});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100")}),test("should try generate aem assets optimized url",()=>{const t=i("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",width:100,height:100});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100")}),test("should try generate aem assets optimized url with default params",()=>{const a=i("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test");expect(a).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80")}),test("should try generate aem assets optimized url with crop",()=>{const t=i("https://example.com/adobe/assets/urn:aaid:aem:1234567890","test",{quality:80,format:"webp",crop:{xOrigin:0,yOrigin:0,width:100,height:100}});expect(t).toBe("https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p")}),test("should return original url if aem assets is disabled",()=>{r.mockReturnValueOnce(!1);const e="https://example.com/adobe/assets/urn:aaid:aem:1234567890",t=i(e,"test",{quality:80,format:"webp"});expect(t).toBe(e)}),test("should return original url if url is not aem assets url",()=>{const e="https://example.com/image.jpg",t=i(e,"test",{quality:80,format:"webp"});expect(t).toBe(e)}),test("should make aem assets image slot",()=>{const e=c({alias:"test",params:{},imageProps:{src:"https://example.com/adobe/assets/urn:aaid:aem:1234567890"}}),s=document.createElement("div");e({replaceWith:a=>{s.appendChild(a)}})}),test("should try render aem assets image",()=>{const e=document.createElement("div");p({replaceWith:t=>{e.appendChild(t)}},{alias:"test",params:{},imageProps:{src:"https://example.com/adobe/assets/urn:aaid:aem:1234567890"}})}),test("should render default image if aem assets is disabled",()=>{r.mockReturnValueOnce(!1);const e=document.createElement("div");p({replaceWith:t=>{e.appendChild(t)}},{alias:"test",params:{},imageProps:{src:"https://example.com/adobe/assets/urn:aaid:aem:1234567890"}})}),test("should render default image if url is not aem assets url",()=>{const e=document.createElement("div");p({replaceWith:t=>{e.appendChild(t)}},{alias:"test",params:{},imageProps:{src:"https://example.com/image.jpg"}})})});
|
|
4
|
-
//# sourceMappingURL=assets.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"assets.test.js","sources":["/@dropins/tools/src/lib/aem/assets.test.ts"],"sourcesContent":["import {\n isAemAssetsEnabled,\n getDefaultAemAssetsOptimizationParams,\n isAemAssetsUrl,\n generateAemAssetsOptimizedUrl,\n tryGenerateAemAssetsOptimizedUrl,\n makeAemAssetsImageSlot,\n tryRenderAemAssetsImage,\n} from './assets';\n\nimport { getConfigValue } from './configs';\n\n// Mock the config\njest.mock('./configs', () => ({\n getConfigValue: jest.fn().mockImplementation((key: string) => {\n if (key === 'commerce-assets-enabled') {\n return true;\n }\n return undefined;\n }),\n}));\n\n// Mock window.location\nObject.defineProperty(window, 'location', {\nvalue: {\n pathname: '/',\n origin: 'https://example.com',\n protocol: 'https:',\n},\n});\n\ndescribe('AEM Assets', () => {\n beforeEach(() => {\n jest.clearAllMocks();\n });\n\n test('should be enabled', () => {\n expect(isAemAssetsEnabled()).toBe(true);\n\n (getConfigValue as jest.Mock).mockReturnValueOnce('true');\n expect(isAemAssetsEnabled()).toBe(true);\n });\n\n test('should be disabled', () => {\n (getConfigValue as jest.Mock).mockReturnValueOnce(false);\n expect(isAemAssetsEnabled()).toBe(false);\n });\n\n test('should return default optimization params', () => {\n const params = getDefaultAemAssetsOptimizationParams();\n expect(params).toEqual({\n quality: 80,\n format: 'webp',\n });\n });\n\n test('should return true if url is aem assets url', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n expect(isAemAssetsUrl(url)).toBe(true);\n });\n\n test('should return false if url is not aem assets url', () => {\n const url = 'https://example.com/image.jpg';\n expect(isAemAssetsUrl(url)).toBe(false);\n });\n\n test('should return true if url is aem assets url with protocol relative path', () => {\n const url = '//example.com/adobe/assets/urn:aaid:aem:1234567890';\n expect(isAemAssetsUrl(url)).toBe(true);\n });\n\n test('should generate aem assets optimized url', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80');\n });\n\n test('should generate aem assets optimized url with default params', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80');\n });\n\n test('should generate aem assets optimized url with crop', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n crop: {\n xOrigin: 0,\n yOrigin: 0,\n },\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p');\n });\n\n test('should generate aem assets optimized url with size', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n size: {\n width: 100,\n height: 100,\n },\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&size=100%2C100');\n });\n\n test('should generate aem assets optimized url with width and height', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n width: 100,\n height: 100,\n };\n const optimizedUrl = generateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100');\n });\n\n test('should try generate aem assets optimized url', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n width: 100,\n height: 100,\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&width=100&height=100');\n });\n\n test('should try generate aem assets optimized url with default params', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80');\n });\n\n test('should try generate aem assets optimized url with crop', () => {\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n crop: {\n xOrigin: 0,\n yOrigin: 0,\n width: 100,\n height: 100,\n },\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe('https://example.com/adobe/assets/urn:aaid:aem:1234567890/as/test.webp?quality=80&crop=0p%2C0p%2C100p%2C100p');\n }); \n\n test('should return original url if aem assets is disabled', () => {\n (getConfigValue as jest.Mock).mockReturnValueOnce(false);\n const url = 'https://example.com/adobe/assets/urn:aaid:aem:1234567890';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params); \n expect(optimizedUrl).toBe(url);\n });\n\n test('should return original url if url is not aem assets url', () => {\n const url = 'https://example.com/image.jpg';\n const alias = 'test';\n const params = {\n quality: 80,\n format: 'webp',\n };\n const optimizedUrl = tryGenerateAemAssetsOptimizedUrl(url, alias, params);\n expect(optimizedUrl).toBe(url);\n });\n\n test('should make aem assets image slot', () => {\n const slot = makeAemAssetsImageSlot({\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/adobe/assets/urn:aaid:aem:1234567890',\n },\n });\n const container = document.createElement('div');\n slot({ replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n } });\n });\n\n test('should try render aem assets image', () => {\n const container = document.createElement('div');\n const ctx = {\n replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n },\n };\n const config = {\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/adobe/assets/urn:aaid:aem:1234567890',\n },\n };\n tryRenderAemAssetsImage(ctx, config);\n });\n\n test('should render default image if aem assets is disabled', () => {\n (getConfigValue as jest.Mock).mockReturnValueOnce(false);\n const container = document.createElement('div');\n const ctx = {\n replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n },\n };\n const config = {\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/adobe/assets/urn:aaid:aem:1234567890',\n },\n };\n tryRenderAemAssetsImage(ctx, config);\n });\n\n test('should render default image if url is not aem assets url', () => {\n const container = document.createElement('div');\n const ctx = {\n replaceWith: (element: HTMLElement) => {\n container.appendChild(element);\n },\n };\n const config = {\n alias: 'test',\n params: {},\n imageProps: {\n src: 'https://example.com/image.jpg',\n },\n };\n tryRenderAemAssetsImage(ctx, config);\n });\n});"],"names":["key","isAemAssetsEnabled","getConfigValue","params","getDefaultAemAssetsOptimizationParams","isAemAssetsUrl","optimizedUrl","generateAemAssetsOptimizedUrl","tryGenerateAemAssetsOptimizedUrl","url","slot","makeAemAssetsImageSlot","container","element","tryRenderAemAssetsImage"],"mappings":"qkBAaA,KAAK,KAAK,YAAa,KAAO,CAC5B,eAAgB,KAAK,GAAK,EAAA,mBAAoBA,GAAgB,CAC5D,GAAIA,IAAQ,0BACH,MAAA,EAGV,CAAA,CACH,EAAE,EAGF,OAAO,eAAe,OAAQ,WAAY,CAC1C,MAAO,CACH,SAAU,IACV,OAAQ,sBACR,SAAU,QAAA,CAEd,CAAC,EAED,SAAS,aAAc,IAAM,CAC3B,WAAW,IAAM,CACf,KAAK,cAAc,CAAA,CACpB,EAED,KAAK,oBAAqB,IAAM,CAC9B,OAAOC,EAAmB,CAAC,EAAE,KAAK,EAAI,EAErCC,EA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AAYC,CAAO,CAAA,EAC5B,CAAA,CACJ,EAED,KAAK,qCAAsC,IAAM,CACzC,MAAAD,EAAY,SAAS,cAAc,KAAK,EAa9CE,EAZY,CACV,YAAcD,GAAyB,CACrCD,EAAU,YAAYC,CAAO,CAAA,CAEjC,EACe,CACb,MAAO,OACP,OAAQ,CAAC,EACT,WAAY,CACV,IAAK,0DAAA,CAET,CACmC,CAAA,CACpC,EAED,KAAK,wDAAyD,IAAM,CACjEX,EAA6B,oBAAoB,EAAK,EACjD,MAAAU,EAAY,SAAS,cAAc,KAAK,EAa9CE,EAZY,CACV,YAAcD,GAAyB,CACrCD,EAAU,YAAYC,CAAO,CAAA,CAEjC,EACe,CACb,MAAO,OACP,OAAQ,CAAC,EACT,WAAY,CACV,IAAK,0DAAA,CAET,CACmC,CAAA,CACpC,EAED,KAAK,2DAA4D,IAAM,CAC/D,MAAAD,EAAY,SAAS,cAAc,KAAK,EAa9CE,EAZY,CACV,YAAcD,GAAyB,CACrCD,EAAU,YAAYC,CAAO,CAAA,CAEjC,EACe,CACb,MAAO,OACP,OAAQ,CAAC,EACT,WAAY,CACV,IAAK,+BAAA,CAET,CACmC,CAAA,CACpC,CACH,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '../../types/elsie/src/lib/aem/configs.test'
|
package/lib/aem/configs.test.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/*! Copyright 2025 Adobe
|
|
2
|
-
All Rights Reserved. */
|
|
3
|
-
import{initializeConfig as o,getConfigValue as s,getRootPath as n,getListOfRootPaths as c,isMultistore as u,getHeaders as a,resetConfig as f}from"./configs.js";import"../../chunks/cjs.js";import"../../chunks/get-path-value.js";describe("AEM Config",()=>{const t={public:{default:{headers:{all:{"x-test":"test"},commerce:{"x-commerce":"commerce"}}}}};beforeEach(()=>{i("/"),f()}),afterEach(()=>{jest.clearAllMocks(),jest.restoreAllMocks()}),test("should initialize config (default)",()=>{const e={public:{default:{foo:"bar"}}},l=o(e);expect(l).toEqual(e.public.default)}),test("should initialize config with default config if root path is not found",()=>{i("/not-found/");const e=o(t);expect(e).toEqual(t.public.default)}),test("should initialize config with default config if root path is empty",()=>{i("/sub-path/");const e=o({...t,public:{...t.public,"/sub-path/":{}}});expect(e).toEqual(t.public.default)}),test("should initialize config with overrides if root path is not empty",()=>{i("/sub-path/");const e=o({...t,public:{...t.public,"/sub-path/":{headers:{all:{"x-test":"test2"}}}}});expect(e).toEqual({headers:{all:{"x-test":"test2"},commerce:{"x-commerce":"commerce"}}})}),test("should throw error if no config is initialized",async()=>{expect(()=>s("foo")).toThrow("Configuration not initialized. Call initializeConfig() first.")}),test("should get config value",async()=>{o({public:{default:{foo:"bar"}}}),expect(s("foo")).toBe("bar")}),test("should get config value from root path",()=>{i("/sub-path/"),o({...t,public:{...t.public,"/sub-path/":{foo:"baz",nested:{foo:"nested"}}}}),expect(s("headers.all.x-test")).toBe("test"),expect(s("foo")).toBe("baz"),expect(s("nested.foo")).toBe("nested")}),test("should warn if value is not found",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{});o(t),s("foo.bar"),expect(e).toHaveBeenCalledWith("Property foo.bar does not exist in the object")}),test("should warn if the root path has no config",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{}),l=n(null);expect(l).toBe("/"),expect(e).toHaveBeenCalledWith("No config found. Please call initializeConfig() first.")}),test("should warn if the root path is not found",async()=>{i("/no-found/");const e=n({public:{default:{}}});expect(e).toBe("/")}),test("should get default root path",async()=>{i("/path/"),o(t),expect(n()).toBe("/")}),test("should get root path from public config",async()=>{i("/test/"),o({...t,public:{...t.public,"/test/":{}}}),expect(n()).toBe("/test/")}),test("should get list of root paths",async()=>{o({...t,public:{...t.public,"/test/":{},"/test2/":{}}}),expect(c()).toEqual(["/test/","/test2/"])}),test("should warn if list of root paths has no config",async()=>{const e=jest.spyOn(console,"warn").mockImplementation(()=>{}),l=c();expect(e).toHaveBeenCalledWith("No config found. Please call initializeConfig() first."),expect(l).toEqual([])}),test("should check if multistore",async()=>{o(t),expect(u()).toBe(!1),o({...t,public:{...t.public,"/test/":{}}}),expect(u()).toBe(!0)}),test("should throw error if headers are not initialized",async()=>{expect(()=>a("all")).toThrow("Configuration not initialized. Call initializeConfig() first.")}),test("should get headers",async()=>{o(t),expect(a("all")).toEqual(t.public.default.headers.all),expect(a("commerce")).toEqual({...t.public.default.headers.all,...t.public.default.headers.commerce})}),test('should get "all" headers if no config is found',async()=>{o(t),expect(a("not-found")).toEqual({...t.public.default.headers.all})}),test("should get empty headers if no config is found",async()=>{o({public:{default:{}}}),expect(a("not-found")).toEqual({})})});function i(t){Object.defineProperty(window,"location",{value:{pathname:t,origin:"http://localhost"}})}
|
|
4
|
-
//# sourceMappingURL=configs.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"configs.test.js","sources":["/@dropins/tools/src/lib/aem/configs.test.ts"],"sourcesContent":["import {\n resetConfig,\n getRootPath,\n getListOfRootPaths,\n isMultistore,\n getConfigValue,\n getHeaders,\n initializeConfig,\n} from './configs';\n\ndescribe('AEM Config', () => {\n const mockConfig = {\n public: {\n default: {\n headers: {\n all: {\n 'x-test': 'test',\n },\n commerce: {\n 'x-commerce': 'commerce',\n },\n },\n },\n },\n };\n\n beforeEach(() => {\n mockLocation('/');\n resetConfig();\n });\n\n afterEach(() => {\n jest.clearAllMocks();\n jest.restoreAllMocks();\n });\n\n test('should initialize config (default)', () => {\n const mockConfig = {\n public: {\n default: {\n foo: 'bar',\n },\n },\n };\n\n const rootConfig = initializeConfig(mockConfig);\n\n // Test config value retrieval\n expect(rootConfig).toEqual(mockConfig.public.default);\n });\n\n test('should initialize config with default config if root path is not found', () => {\n mockLocation('/not-found/');\n\n const rootConfig = initializeConfig(mockConfig);\n\n // Test config value retrieval\n expect(rootConfig).toEqual(mockConfig.public.default);\n });\n\n test('should initialize config with default config if root path is empty', () => {\n mockLocation('/sub-path/');\n\n const rootConfig = initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/sub-path/': {},\n },\n });\n\n // Test config value retrieval\n expect(rootConfig).toEqual(mockConfig.public.default);\n });\n\n test('should initialize config with overrides if root path is not empty', () => {\n mockLocation('/sub-path/');\n\n const rootConfig = initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/sub-path/': {\n headers: {\n all: {\n 'x-test': 'test2',\n },\n },\n },\n },\n });\n\n // Test config value retrieval\n expect(rootConfig).toEqual({\n headers: {\n all: {\n 'x-test': 'test2',\n },\n commerce: {\n 'x-commerce': 'commerce',\n },\n },\n });\n });\n\n test('should throw error if no config is initialized', async () => {\n expect(() => getConfigValue('foo')).toThrow(\n 'Configuration not initialized. Call initializeConfig() first.'\n );\n });\n\n test('should get config value', async () => {\n initializeConfig({\n public: {\n default: {\n foo: 'bar',\n },\n },\n });\n\n expect(getConfigValue('foo')).toBe('bar');\n });\n\n test('should get config value from root path', () => {\n mockLocation('/sub-path/');\n\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/sub-path/': {\n foo: 'baz',\n nested: {\n foo: 'nested',\n },\n },\n },\n });\n\n expect(getConfigValue('headers.all.x-test')).toBe('test');\n expect(getConfigValue('foo')).toBe('baz');\n expect(getConfigValue('nested.foo')).toBe('nested');\n });\n\n test('should warn if value is not found', async () => {\n const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});\n initializeConfig(mockConfig);\n\n getConfigValue('foo.bar');\n\n expect(consoleSpy).toHaveBeenCalledWith(\n 'Property foo.bar does not exist in the object'\n );\n });\n\n test('should warn if the root path has no config', async () => {\n const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});\n\n const rootPath = getRootPath(null);\n\n expect(rootPath).toBe('/');\n\n expect(consoleSpy).toHaveBeenCalledWith(\n 'No config found. Please call initializeConfig() first.'\n );\n });\n\n test('should warn if the root path is not found', async () => {\n mockLocation('/no-found/');\n\n const rootPath = getRootPath({\n public: {\n default: {},\n },\n });\n\n expect(rootPath).toBe('/');\n });\n\n test('should get default root path', async () => {\n mockLocation('/path/');\n\n initializeConfig(mockConfig);\n\n expect(getRootPath()).toBe('/');\n });\n\n test('should get root path from public config', async () => {\n mockLocation('/test/');\n\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/test/': {},\n },\n });\n\n expect(getRootPath()).toBe('/test/');\n });\n\n test('should get list of root paths', async () => {\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/test/': {},\n '/test2/': {},\n },\n });\n\n expect(getListOfRootPaths()).toEqual(['/test/', '/test2/']);\n });\n\n test('should warn if list of root paths has no config', async () => {\n const consoleSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});\n\n const rootPaths = getListOfRootPaths();\n\n expect(consoleSpy).toHaveBeenCalledWith(\n 'No config found. Please call initializeConfig() first.'\n );\n\n expect(rootPaths).toEqual([]);\n });\n\n test('should check if multistore', async () => {\n initializeConfig(mockConfig);\n\n expect(isMultistore()).toBe(false);\n\n initializeConfig({\n ...mockConfig,\n public: {\n ...mockConfig.public,\n '/test/': {},\n },\n });\n\n expect(isMultistore()).toBe(true);\n });\n\n test('should throw error if headers are not initialized', async () => {\n expect(() => getHeaders('all')).toThrow(\n 'Configuration not initialized. Call initializeConfig() first.'\n );\n });\n\n test('should get headers', async () => {\n initializeConfig(mockConfig);\n\n // All headers\n expect(getHeaders('all')).toEqual(mockConfig.public.default.headers.all);\n expect(getHeaders('commerce')).toEqual({\n ...mockConfig.public.default.headers.all,\n ...mockConfig.public.default.headers.commerce,\n });\n });\n\n test('should get \"all\" headers if no config is found', async () => {\n initializeConfig(mockConfig);\n\n expect(getHeaders('not-found')).toEqual({\n ...mockConfig.public.default.headers.all,\n });\n });\n\n test('should get empty headers if no config is found', async () => {\n initializeConfig({\n public: {\n default: {},\n },\n });\n\n expect(getHeaders('not-found')).toEqual({});\n });\n});\n\nfunction mockLocation(pathname: string) {\n Object.defineProperty(window, 'location', {\n value: {\n pathname,\n origin: 'http://localhost',\n },\n });\n}\n"],"names":["mockConfig","mockLocation","resetConfig","rootConfig","initializeConfig","getConfigValue","consoleSpy","rootPath","getRootPath","getListOfRootPaths","rootPaths","isMultistore","getHeaders","pathname"],"mappings":"mOAUA,SAAS,aAAc,IAAM,CAC3B,MAAMA,EAAa,CACjB,OAAQ,CACN,QAAS,CACP,QAAS,CACP,IAAK,CACH,SAAU,MACZ,EACA,SAAU,CACR,aAAc,UAAA,CAChB,CACF,CACF,CAEJ,EAEA,WAAW,IAAM,CACfC,EAAa,GAAG,EACJC,EAAA,CAAA,CACb,EAED,UAAU,IAAM,CACd,KAAK,cAAc,EACnB,KAAK,gBAAgB,CAAA,CACtB,EAED,KAAK,qCAAsC,IAAM,CAC/C,MAAMF,EAAa,CACjB,OAAQ,CACN,QAAS,CACP,IAAK,KAAA,CACP,CAEJ,EAEMG,EAAaC,EAAiBJ,CAAU,EAG9C,OAAOG,CAAU,EAAE,QAAQH,EAAW,OAAO,OAAO,CAAA,CACrD,EAED,KAAK,yEAA0E,IAAM,CACnFC,EAAa,aAAa,EAEpB,MAAAE,EAAaC,EAAiBJ,CAAU,EAG9C,OAAOG,CAAU,EAAE,QAAQH,EAAW,OAAO,OAAO,CAAA,CACrD,EAED,KAAK,qEAAsE,IAAM,CAC/EC,EAAa,YAAY,EAEzB,MAAME,EAAaC,EAAiB,CAClC,GAAGJ,EACH,OAAQ,CACN,GAAGA,EAAW,OACd,aAAc,CAAA,CAAC,CACjB,CACD,EAGD,OAAOG,CAAU,EAAE,QAAQH,EAAW,OAAO,OAAO,CAAA,CACrD,EAED,KAAK,oEAAqE,IAAM,CAC9EC,EAAa,YAAY,EAEzB,MAAME,EAAaC,EAAiB,CAClC,GAAGJ,EACH,OAAQ,CACN,GAAGA,EAAW,OACd,aAAc,CACZ,QAAS,CACP,IAAK,CACH,SAAU,OAAA,CACZ,CACF,CACF,CACF,CACD,EAGM,OAAAG,CAAU,EAAE,QAAQ,CACzB,QAAS,CACP,IAA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