UNPKG

arc-xp-custom-blocks

Version:

arc libraries for ingala

60 lines (59 loc) 2.48 kB
var __defProp = Object.defineProperty; var __getOwnPropSymbols = Object.getOwnPropertySymbols; var __hasOwnProp = Object.prototype.hasOwnProperty; var __propIsEnum = Object.prototype.propertyIsEnumerable; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __spreadValues = (a, b) => { for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]); if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) { if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]); } return a; }; function generateResizedImageUrl(promoItem = {}, config = {}, width, height) { const { resizerTokenVersion = "1", resizerURL } = config; const { auth, url } = promoItem; if (!resizerURL) { return null; } if (!promoItem.auth || !promoItem.auth[resizerTokenVersion]) { return null; } const imageUrl = url.includes("images.arcpublishing.com") ? url.split("/").pop() : encodeURIComponent(url); const focalPoint = getFocalPoint(promoItem); const focalPointType = focalPoint.hasCoords ? { focal: `${focalPoint.x},${focalPoint.y}` } : { smart: true }; if (!width && !height) { ({ width, height } = promoItem); } const params = new URLSearchParams(); const queryParams = __spreadValues({ auth: auth[resizerTokenVersion], height, width }, focalPointType); Object.entries(queryParams).forEach(([key, value]) => { value && params.set(key, value); }); return `${resizerURL}/${imageUrl}?${params.toString()}`; } function getFocalPoint(promoItem) { var _a, _b, _c, _d, _e, _f; const hasFocalPoint = Boolean(promoItem == null ? void 0 : promoItem.focal_point); const hasComposerFocalPoint = Boolean((_b = (_a = promoItem == null ? void 0 : promoItem.additional_properties) == null ? void 0 : _a.focal_point) == null ? void 0 : _b.max); let focalPoint = [(_d = (_c = promoItem == null ? void 0 : promoItem.focal_point) == null ? void 0 : _c.x) != null ? _d : 0, (_f = (_e = promoItem == null ? void 0 : promoItem.focal_point) == null ? void 0 : _e.y) != null ? _f : 0]; if (hasComposerFocalPoint) { focalPoint = promoItem.additional_properties.focal_point.max; } return { hasCoords: hasFocalPoint || hasComposerFocalPoint, x: focalPoint[0], y: focalPoint[1] }; } export { generateResizedImageUrl as default };