{"version":3,"file":"socialWallMarkup-CazB7pYx.js","sources":["../../node_modules/date-fns/esm/startOfDay/index.js","../../node_modules/date-fns/esm/differenceInCalendarDays/index.js","../../node_modules/date-fns/esm/differenceInDays/index.js","../../node_modules/date-fns/esm/differenceInMinutes/index.js","../../src/foundation/Icons/play.ts","../../src/foundation/Icons/socials/socials.ts","../../src/project/AramcoLife/social-wall/markup/socialWallMarkup.ts"],"sourcesContent":["import toDate from '../toDate/index.js';\nimport requiredArgs from '../_lib/requiredArgs/index.js';\n/**\n * @name startOfDay\n * @category Day Helpers\n * @summary Return the start of a day for the given date.\n *\n * @description\n * Return the start of a day for the given date.\n * The result will be in the local timezone.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} date - the original date\n * @returns {Date} the start of a day\n * @throws {TypeError} 1 argument required\n *\n * @example\n * // The start of a day for 2 September 2014 11:55:00:\n * var result = startOfDay(new Date(2014, 8, 2, 11, 55, 0))\n * //=> Tue Sep 02 2014 00:00:00\n */\n\nexport default function startOfDay(dirtyDate) {\n requiredArgs(1, arguments);\n var date = toDate(dirtyDate);\n date.setHours(0, 0, 0, 0);\n return date;\n}","import getTimezoneOffsetInMilliseconds from '../_lib/getTimezoneOffsetInMilliseconds/index.js';\nimport startOfDay from '../startOfDay/index.js';\nimport requiredArgs from '../_lib/requiredArgs/index.js';\nvar MILLISECONDS_IN_DAY = 86400000;\n/**\n * @name differenceInCalendarDays\n * @category Day Helpers\n * @summary Get the number of calendar days between the given dates.\n *\n * @description\n * Get the number of calendar days between the given dates. This means that the times are removed\n * from the dates and then the difference in days is calculated.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the later date\n * @param {Date|Number} dateRight - the earlier date\n * @returns {Number} the number of calendar days\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // How many calendar days are between\n * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?\n * var result = differenceInCalendarDays(\n * new Date(2012, 6, 2, 0, 0),\n * new Date(2011, 6, 2, 23, 0)\n * )\n * //=> 366\n * // How many calendar days are between\n * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?\n * var result = differenceInCalendarDays(\n * new Date(2011, 6, 3, 0, 1),\n * new Date(2011, 6, 2, 23, 59)\n * )\n * //=> 1\n */\n\nexport default function differenceInCalendarDays(dirtyDateLeft, dirtyDateRight) {\n requiredArgs(2, arguments);\n var startOfDayLeft = startOfDay(dirtyDateLeft);\n var startOfDayRight = startOfDay(dirtyDateRight);\n var timestampLeft = startOfDayLeft.getTime() - getTimezoneOffsetInMilliseconds(startOfDayLeft);\n var timestampRight = startOfDayRight.getTime() - getTimezoneOffsetInMilliseconds(startOfDayRight); // Round the number of days to the nearest integer\n // because the number of milliseconds in a day is not constant\n // (e.g. it's different in the day of the daylight saving time clock shift)\n\n return Math.round((timestampLeft - timestampRight) / MILLISECONDS_IN_DAY);\n}","import toDate from '../toDate/index.js';\nimport differenceInCalendarDays from '../differenceInCalendarDays/index.js';\nimport requiredArgs from '../_lib/requiredArgs/index.js'; // Like `compareAsc` but uses local time not UTC, which is needed\n// for accurate equality comparisons of UTC timestamps that end up\n// having the same representation in local time, e.g. one hour before\n// DST ends vs. the instant that DST ends.\n\nfunction compareLocalAsc(dateLeft, dateRight) {\n var diff = dateLeft.getFullYear() - dateRight.getFullYear() || dateLeft.getMonth() - dateRight.getMonth() || dateLeft.getDate() - dateRight.getDate() || dateLeft.getHours() - dateRight.getHours() || dateLeft.getMinutes() - dateRight.getMinutes() || dateLeft.getSeconds() - dateRight.getSeconds() || dateLeft.getMilliseconds() - dateRight.getMilliseconds();\n\n if (diff < 0) {\n return -1;\n } else if (diff > 0) {\n return 1; // Return 0 if diff is 0; return NaN if diff is NaN\n } else {\n return diff;\n }\n}\n/**\n * @name differenceInDays\n * @category Day Helpers\n * @summary Get the number of full days between the given dates.\n *\n * @description\n * Get the number of full day periods between two dates. Fractional days are\n * truncated towards zero.\n *\n * One \"full day\" is the distance between a local time in one day to the same\n * local time on the next or previous day. A full day can sometimes be less than\n * or more than 24 hours if a daylight savings change happens between two dates.\n *\n * To ignore DST and only measure exact 24-hour periods, use this instead:\n * `Math.floor(differenceInHours(dateLeft, dateRight)/24)|0`.\n *\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the later date\n * @param {Date|Number} dateRight - the earlier date\n * @returns {Number} the number of full days according to the local timezone\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // How many full days are between\n * // 2 July 2011 23:00:00 and 2 July 2012 00:00:00?\n * var result = differenceInDays(\n * new Date(2012, 6, 2, 0, 0),\n * new Date(2011, 6, 2, 23, 0)\n * )\n * //=> 365\n * // How many full days are between\n * // 2 July 2011 23:59:00 and 3 July 2011 00:01:00?\n * var result = differenceInDays(\n * new Date(2011, 6, 3, 0, 1),\n * new Date(2011, 6, 2, 23, 59)\n * )\n * //=> 0\n * // How many full days are between\n * // 1 March 2020 0:00 and 1 June 2020 0:00 ?\n * // Note: because local time is used, the\n * // result will always be 92 days, even in\n * // time zones where DST starts and the\n * // period has only 92*24-1 hours.\n * var result = differenceInDays(\n * new Date(2020, 5, 1),\n * new Date(2020, 2, 1)\n * )\n//=> 92\n */\n\n\nexport default function differenceInDays(dirtyDateLeft, dirtyDateRight) {\n requiredArgs(2, arguments);\n var dateLeft = toDate(dirtyDateLeft);\n var dateRight = toDate(dirtyDateRight);\n var sign = compareLocalAsc(dateLeft, dateRight);\n var difference = Math.abs(differenceInCalendarDays(dateLeft, dateRight));\n dateLeft.setDate(dateLeft.getDate() - sign * difference); // Math.abs(diff in full days - diff in calendar days) === 1 if last calendar day is not full\n // If so, result must be decreased by 1 in absolute value\n\n var isLastDayNotFull = compareLocalAsc(dateLeft, dateRight) === -sign;\n var result = sign * (difference - isLastDayNotFull); // Prevent negative zero\n\n return result === 0 ? 0 : result;\n}","import differenceInMilliseconds from '../differenceInMilliseconds/index.js';\nimport requiredArgs from '../_lib/requiredArgs/index.js';\nvar MILLISECONDS_IN_MINUTE = 60000;\n/**\n * @name differenceInMinutes\n * @category Minute Helpers\n * @summary Get the number of minutes between the given dates.\n *\n * @description\n * Get the signed number of full (rounded towards 0) minutes between the given dates.\n *\n * ### v2.0.0 breaking changes:\n *\n * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).\n *\n * @param {Date|Number} dateLeft - the later date\n * @param {Date|Number} dateRight - the earlier date\n * @returns {Number} the number of minutes\n * @throws {TypeError} 2 arguments required\n *\n * @example\n * // How many minutes are between 2 July 2014 12:07:59 and 2 July 2014 12:20:00?\n * var result = differenceInMinutes(\n * new Date(2014, 6, 2, 12, 20, 0),\n * new Date(2014, 6, 2, 12, 7, 59)\n * )\n * //=> 12\n *\n * @example\n * // How many minutes are from 10:01:59 to 10:00:00\n * var result = differenceInMinutes(\n * new Date(2000, 0, 1, 10, 0, 0),\n * new Date(2000, 0, 1, 10, 1, 59)\n * )\n * //=> -1\n */\n\nexport default function differenceInMinutes(dirtyDateLeft, dirtyDateRight) {\n requiredArgs(2, arguments);\n var diff = differenceInMilliseconds(dirtyDateLeft, dirtyDateRight) / MILLISECONDS_IN_MINUTE;\n return diff > 0 ? Math.floor(diff) : Math.ceil(diff);\n}","export const playIcon = `\r\n\t\r\n`;","export const instagramLogo = `\r\n\t\r\n`;\r\n\r\nexport const linkedinLogo = `\r\n\t\r\n`;\r\n\r\nexport const xLogo = `\r\n\t\r\n`;\r\n\r\nexport const facebookLogo = `\r\n\t\r\n`;\r\n","import { differenceInDays, differenceInHours, differenceInMinutes, format } from \"date-fns\";\r\nimport { playIcon } from \"~/foundation/Icons/play\";\r\nimport { facebookLogo, instagramLogo, linkedinLogo, xLogo } from \"~/foundation/Icons/socials/socials\";\r\nimport { type DistinctSocialWallElements, type SocialWallElement, type SocialWallListDictionary } from \"../../generated-types\";\r\n\r\ntype ExtendedSocialWallElement = SocialWallElement & {\r\n\tpostImage: string;\r\n};\r\n\r\nexport const removeLoader = (container: HTMLElement) => {\r\n\tconst loaderElement = container.querySelector(\".loader\");\r\n\tif (loaderElement) {\r\n\t\tloaderElement.remove();\r\n\t}\r\n};\r\n\r\nexport const addVideoEventListeners = (mediaWrappers: NodeListOf) => {\r\n\tmediaWrappers.forEach(wrapper => {\r\n\t\tconst thumbnail = wrapper.querySelector(\".thumbnail\") as HTMLElement;\r\n\t\tconst playIcon = wrapper.querySelector(\".thumbnail__play-icon\") as HTMLElement;\r\n\t\tconst video = wrapper.querySelector(\"video\") as HTMLVideoElement;\r\n\r\n\t\tif (playIcon && video) {\r\n\t\t\tconst playVideo = () => {\r\n\t\t\t\tthumbnail.classList.add(\"hidden\");\r\n\t\t\t\tvideo.classList.remove(\"hidden\");\r\n\t\t\t\tvideo.play();\r\n\t\t\t};\r\n\r\n\t\t\tplayIcon.addEventListener(\"click\", playVideo);\r\n\t\t\tplayIcon.addEventListener(\"keydown\", (event) => {\r\n\t\t\t\tif (event.key === \"Enter\" || event.key === \" \") {\r\n\t\t\t\t\tevent.preventDefault();\r\n\t\t\t\t\tplayVideo();\r\n\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\t});\r\n};\r\n\r\nexport const handleMediaLoad = async (mediaWrapper: Element) => {\r\n\treturn new Promise((resolve) => {\r\n\t\tconst img = mediaWrapper.querySelector('img.social-image');\r\n\t\tconst video = mediaWrapper.querySelector('video');\r\n\r\n\t\tif (img) {\r\n\t\t\timg.onload = () => {\r\n\t\t\t\timg.classList.remove(\"hidden\");\r\n\t\t\t\tresolve();\r\n\t\t\t};\r\n\t\t\timg.onerror = () => {\r\n\t\t\t\tmediaWrapper?.classList.add(\"no-img\");\r\n\t\t\t\tresolve();\r\n\t\t\t};\r\n\t\t\t// // Trigger load for images that might be cached\r\n\t\t\t// if (img.complete) {\r\n\t\t\t// \timg.onload!(new Event('load'));\r\n\t\t\t// }\r\n\t\t} else if (video) {\r\n\t\t\t// For videos, we don't actually load the video, just make sure the thumbnail is visible\r\n\t\t\tconst thumbnail = mediaWrapper.querySelector('.thumbnail');\r\n\t\t\tconst thumbnailImg = mediaWrapper.querySelector('.thumbnail img');\r\n\r\n\t\t\tthumbnailImg!.onload = () => {\r\n\t\t\t\tthumbnail!.classList.remove(\"hidden\");\r\n\t\t\t\tresolve();\r\n\t\t\t};\r\n\t\t\tthumbnailImg!.onerror = () => {\r\n\t\t\t\tmediaWrapper?.classList.add(\"no-img\");\r\n\t\t\t\tresolve();\r\n\t\t\t};\r\n\t\t} else {\r\n\t\t\tresolve();\r\n\t\t}\r\n\r\n\t});\r\n};\r\n\r\nexport const formatDate = (postDate: string, dictionary?: SocialWallListDictionary): string => {\r\n\tconst now = new Date();\r\n\tconst postDateObj = new Date(postDate);\r\n\tconst minutesDiff = differenceInMinutes(now, postDateObj);\r\n\tconst hoursDiff = differenceInHours(now, postDateObj);\r\n\tconst daysDiff = differenceInDays(now, postDateObj);\r\n\r\n\tif (minutesDiff < 60) {\r\n\t\treturn `${minutesDiff} ${dictionary?.minutesLabel || \"minutes\"}`;\r\n\t} else if (hoursDiff < 24) {\r\n\t\treturn `${hoursDiff} ${hoursDiff === 1 ? `${dictionary?.hourLabel || \"hour\"}` : `${dictionary?.hoursLabel || \"hours\"}`}`;\r\n\t} else if (daysDiff < 7) {\r\n\t\tconst remainingHours = hoursDiff % 24;\r\n\t\treturn `${daysDiff} ${daysDiff === 1 ? `${dictionary?.dayLabel || \"day\"}` : `${dictionary?.daysLabel || \"days\"}`}${remainingHours ? ` ${remainingHours} ${remainingHours === 1 ? `${dictionary?.hourLabel || \"hour\"}` : `${dictionary?.hoursLabel || \"hours\"}`}` : \"\"}`;\r\n\t} else {\r\n\t\treturn format(postDateObj, \"dd MMMM HH:mm\");\r\n\t}\r\n};\r\n\r\n// Get social icon based on the platform\r\nexport const renderSocialIcon = (socialIcon: string) => {\r\n\tswitch (socialIcon) {\r\n\t\tcase \"facebook\": return facebookLogo;\r\n\t\tcase \"twitter\": return xLogo;\r\n\t\tcase \"instagram\": return instagramLogo;\r\n\t\tcase \"linkedin\": return linkedinLogo;\r\n\t\tdefault: return null;\r\n\t}\r\n};\r\n\r\n// Render social links\r\nexport const renderSocialLinks = (elements: SocialWallElement[]) => {\r\n\treturn elements.map(item => `\r\n \r\n ${renderSocialIcon(item.platform || \"\")}\r\n `).join(\"\");\r\n};\r\n\r\n// Render media (image or video)\r\nexport const renderMedia = async (item: DistinctSocialWallElements) => {\r\n\tconst mediaWrapper = document.createElement(\"div\");\r\n\tmediaWrapper.classList.add(\"media-wrapper\");\r\n\r\n\tconst selectedImage = item.elements\r\n\t\t?.sort((a, b) => {\r\n\t\t\t// Image order: facebook, x (twitter string in the API), linkedin, instagram - prioritize facebook\r\n\t\t\tconst platformOrder = [\"facebook\", \"twitter\", \"linkedin\", \"instagram\"];\r\n\t\t\tconst aIndex = platformOrder.indexOf(a.platform || \"\");\r\n\t\t\tconst bIndex = platformOrder.indexOf(b.platform || \"\");\r\n\t\t\treturn aIndex - bIndex;\r\n\t\t})\r\n\t\t?.find(\r\n\t\t\t(x): x is ExtendedSocialWallElement =>\r\n\t\t\t\t!!(x as ExtendedSocialWallElement).postImage &&\r\n (x as ExtendedSocialWallElement).postImage !== item.imageUrl\r\n\t\t)?.postImage || item.imageUrl;\r\n\r\n\tif (item.videoUrl) {\r\n\t\tmediaWrapper.innerHTML = `\r\n\t\t\t