add-to-calendar-button
Version:
A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.
892 lines (888 loc) • 273 kB
JavaScript
import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'timezones-ical-library';
/*!
* @preserve
*
* ++++++++++++++++++++++
* Add to Calendar Button
* ++++++++++++++++++++++
*
* Version: 2.8.8
* Creator: Jens Kuerschner (https://jekuer.com)
* Project: https://github.com/add2cal/add-to-calendar-button
* License: Elastic License 2.0 (ELv2) (https://github.com/add2cal/add-to-calendar-button/blob/main/LICENSE.txt)
* Note: DO NOT REMOVE THE COPYRIGHT NOTICE ABOVE!
*
*/
const atcbVersion = '2.8.8';
const atcbCssTemplate = {};
const atcbIsBrowser = () => {
if (typeof window === 'undefined') {
return false;
} else {
return true;
}
};
const atcbIsiOS = atcbIsBrowser()
? () => {
if (/iPad|iPhone|iPod/i.test(navigator.userAgent) && !/MSStream/i.test(navigator.userAgent)) {
return true;
} else {
return false;
}
}
: () => {
return false;
};
const atcbIsAndroid = atcbIsBrowser()
? () => {
if (/android/i.test(navigator.userAgent) && !/MSStream/i.test(navigator.userAgent)) {
return true;
} else {
return false;
}
}
: () => {
return false;
};
/*const atcbIsChrome = atcbIsBrowser()
? () => {
if (/chrome|chromium|crios|google inc/i.test(navigator.userAgent)) {
return true;
} else {
return false;
}
}
: () => {
return false;
};*/
const atcbIsSafari = atcbIsBrowser()
? () => {
if (/^(?:(?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent)) {
return true;
} else {
return false;
}
}
: () => {
return false;
};
const atcbIsMobile = () => {
if (atcbIsAndroid() || atcbIsiOS()) {
return true;
} else {
return false;
}
};
const atcbIsWebView = atcbIsBrowser()
? () => {
if (/; ?wv|(?:iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/i.test(navigator.userAgent)) {
return true;
} else {
return false;
}
}
: () => {
return false;
};
const atcbIsProblematicWebView = atcbIsBrowser()
? () => {
if (/Instagram/i.test(navigator.userAgent)) {
return true;
} else {
return false;
}
}
: () => {
return false;
};
const atcbDefaultTarget = atcbIsWebView() ? '_system' : '_blank';
const atcbOptions = ['apple', 'google', 'ical', 'ms365', 'outlookcom', 'msteams', 'yahoo'];
const atcbValidRecurrOptions = ['apple', 'google', 'ical'];
const atcbInvalidSubscribeOptions = ['msteams'];
const atcbIOSInvalidOptions = ['ical'];
const atcbAndroidInvalidOptions = ['apple'];
const atcbStates = [];
const atcbWcParams = [
'debug',
'proOverride',
'cspnonce',
'identifier',
'name',
'dates',
'description',
'startDate',
'startTime',
'endDate',
'endTime',
'timeZone',
'useUserTZ',
'location',
'status',
'uid',
'organizer',
'attendee',
'icsFile',
'images',
'recurrence',
'recurrence_until',
'recurrence_byDay',
'recurrence_byMonth',
'recurrence_byMonthDay',
'recurrence_weekstart',
'sequence',
'recurrence_interval',
'recurrence_count',
'availability',
'created',
'updated',
'subscribe',
'options',
'optionsMobile',
'optionsIOS',
'iCalFileName',
'listStyle',
'buttonStyle',
'trigger',
'hideIconButton',
'hideIconList',
'hideIconModal',
'hideTextLabelButton',
'hideTextLabelList',
'buttonsList',
'hideBackground',
'hideCheckmark',
'hideBranding',
'size',
'label',
'inline',
'inlineRsvp',
'customLabels',
'customCss',
'lightMode',
'language',
'hideRichData',
'bypassWebViewCheck',
'blockInteraction',
'styleLight',
'styleDark',
'disabled',
'hidden',
'hideButton',
'pastDateHandling',
'proxy',
'fakeMobile',
'fakeIOS',
'fakeAndroid',
'forceOverlay',
'rsvp',
'ty',
'customVar',
'domain',
'dev',
];
const atcbWcProParams = [
'debug',
'proOverride',
'cspnonce',
'attendee',
'images',
'size',
'inline',
'inlineRsvp',
'customLabels',
'customCss',
'lightMode',
'language',
'bypassWebViewCheck',
'blockInteraction',
'styleLight',
'styleDark',
'disabled',
'hidden',
'fakeMobile',
'fakeIOS',
'fakeAndroid',
'forceOverlay',
'customVar',
'proxy',
'domain',
'dev',
];
const atcbWcBooleanParams = [
'debug',
'proOverride',
'useUserTZ',
'hideIconButton',
'hideIconList',
'hideIconModal',
'hideTextLabelButton',
'hideTextLabelList',
'subscribe',
'hideBackground',
'hideCheckmark',
'hideBranding',
'inlineRsvp',
'hideRichData',
'buttonsList',
'inline',
'bypassWebViewCheck',
'blockInteraction',
'disabled',
'hidden',
'hideButton',
'proxy',
'fakeMobile',
'fakeIOS',
'fakeAndroid',
'forceOverlay',
'dev',
];
const atcbWcObjectParams = ['customLabels', 'ty', 'rsvp', 'customVar'];
const atcbWcObjectArrayParams = ['dates'];
const atcbWcArrayParams = ['images', 'options', 'optionsMobile', 'optionsIOS'];
const atcbWcNumberParams = ['sequence', 'recurrence_interval', 'recurrence_count'];
const atcbIcon = {
trigger:
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200.016"><path d="M132.829 7.699c0-4.248 4.199-7.699 9.391-7.699s9.391 3.451 9.391 7.699v33.724c0 4.248-4.199 7.699-9.391 7.699s-9.391-3.451-9.391-7.699zm-5.941 123.747c2.979 0 5.404 2.425 5.404 5.404s-2.425 5.404-5.404 5.404l-21.077-.065-.065 21.045c0 2.979-2.425 5.404-5.404 5.404s-5.404-2.425-5.404-5.404l.065-21.061-21.045-.081c-2.979 0-5.404-2.425-5.404-5.404s2.425-5.404 5.404-5.404l21.061.065.065-21.045c0-2.979 2.425-5.404 5.404-5.404s5.404 2.425 5.404 5.404l-.065 21.077 21.061.065zM48.193 7.699C48.193 3.451 52.393 0 57.585 0s9.391 3.451 9.391 7.699v33.724c0 4.248-4.199 7.699-9.391 7.699s-9.391-3.451-9.391-7.699zM10.417 73.763h179.167V34.945c0-1.302-.537-2.49-1.4-3.369-.863-.863-2.051-1.4-3.369-1.4h-17.171c-2.881 0-5.208-2.327-5.208-5.208s2.327-5.208 5.208-5.208h17.171c4.183 0 7.975 1.709 10.726 4.46S200 30.762 200 34.945v44.043 105.843c0 4.183-1.709 7.975-4.46 10.726s-6.543 4.46-10.726 4.46H15.186c-4.183 0-7.975-1.709-10.726-4.46C1.709 192.79 0 188.997 0 184.814V78.988 34.945c0-4.183 1.709-7.975 4.46-10.726s6.543-4.46 10.726-4.46h18.343c2.881 0 5.208 2.327 5.208 5.208s-2.327 5.208-5.208 5.208H15.186c-1.302 0-2.49.537-3.369 1.4-.863.863-1.4 2.051-1.4 3.369zm179.167 10.433H10.417v100.618c0 1.302.537 2.49 1.4 3.369.863.863 2.051 1.4 3.369 1.4h169.629c1.302 0 2.49-.537 3.369-1.4.863-.863 1.4-2.051 1.4-3.369zM82.08 30.176c-2.881 0-5.208-2.327-5.208-5.208s2.327-5.208 5.208-5.208h34.977c2.881 0 5.208 2.327 5.208 5.208s-2.327 5.208-5.208 5.208z"/></svg>',
apple:
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 245.657"><path d="M167.084 130.514c-.308-31.099 25.364-46.022 26.511-46.761-14.429-21.107-36.91-24.008-44.921-24.335-19.13-1.931-37.323 11.27-47.042 11.27-9.692 0-24.67-10.98-40.532-10.689-20.849.308-40.07 12.126-50.818 30.799-21.661 37.581-5.54 93.281 15.572 123.754 10.313 14.923 22.612 31.688 38.764 31.089 15.549-.612 21.433-10.073 40.242-10.073s24.086 10.073 40.546 9.751c16.737-.308 27.34-15.214 37.585-30.187 11.855-17.318 16.714-34.064 17.009-34.925-.372-.168-32.635-12.525-32.962-49.68l.045-.013zm-30.917-91.287C144.735 28.832 150.524 14.402 148.942 0c-12.344.503-27.313 8.228-36.176 18.609-7.956 9.216-14.906 23.904-13.047 38.011 13.786 1.075 27.862-7.004 36.434-17.376z"/></svg>',
google:
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><path d="M152.637 47.363H47.363v105.273h105.273z" fill="#fff"/><path d="M152.637 200L200 152.637h-47.363z" fill="#f72a25"/><path d="M200 47.363h-47.363v105.273H200z" fill="#fbbc04"/><path d="M152.637 152.637H47.363V200h105.273z" fill="#34a853"/><path d="M0 152.637v31.576A15.788 15.788 0 0 0 15.788 200h31.576v-47.363z" fill="#188038"/><path d="M200 47.363V15.788A15.79 15.79 0 0 0 184.212 0h-31.575v47.363z" fill="#1967d2"/><path d="M15.788 0A15.79 15.79 0 0 0 0 15.788v136.849h47.363V47.363h105.274V0z" fill="#4285f4"/><path d="M68.962 129.02c-3.939-2.653-6.657-6.543-8.138-11.67l9.131-3.76c.83 3.158 2.279 5.599 4.346 7.341 2.051 1.742 4.557 2.588 7.471 2.588 2.995 0 5.55-.911 7.699-2.718 2.148-1.823 3.223-4.134 3.223-6.934 0-2.865-1.139-5.208-3.402-7.031s-5.111-2.718-8.496-2.718h-5.273v-9.033h4.736c2.913 0 5.387-.781 7.389-2.376 2.002-1.579 2.995-3.743 2.995-6.494 0-2.441-.895-4.395-2.686-5.859s-4.053-2.197-6.803-2.197c-2.686 0-4.818.716-6.396 2.148s-2.767 3.255-3.451 5.273l-9.033-3.76c1.204-3.402 3.402-6.396 6.624-8.984s7.34-3.89 12.337-3.89c3.695 0 7.031.716 9.977 2.148s5.257 3.418 6.934 5.941c1.676 2.539 2.507 5.387 2.507 8.545 0 3.223-.781 5.941-2.327 8.187-1.546 2.23-3.467 3.955-5.729 5.143v.537a17.39 17.39 0 0 1 7.34 5.729c1.904 2.572 2.865 5.632 2.865 9.212s-.911 6.771-2.718 9.57c-1.823 2.799-4.329 5.013-7.52 6.624s-6.787 2.425-10.775 2.425c-4.622 0-8.887-1.318-12.826-3.988zm56.087-45.312l-10.026 7.243-5.013-7.601 17.985-12.972h6.901v61.198h-9.847z" fill="#1a73e8"/></svg>',
ical: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200.016"><path d="M132.829 7.699c0-4.248 4.199-7.699 9.391-7.699s9.391 3.451 9.391 7.699v33.724c0 4.248-4.199 7.699-9.391 7.699s-9.391-3.451-9.391-7.699zm-25.228 161.263c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm-81.803-59.766c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm40.902 0c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm40.902 0c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm40.918 0c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zM25.798 139.079c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm40.902 0c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm40.902 0c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm40.918 0c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zM25.798 168.962c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zm40.902 0c-.553 0-.993-2.327-.993-5.208s.439-5.208.993-5.208h25.7c.553 0 .993 2.327.993 5.208s-.439 5.208-.993 5.208zM48.193 7.699C48.193 3.451 52.393 0 57.585 0s9.391 3.451 9.391 7.699v33.724c0 4.248-4.199 7.699-9.391 7.699s-9.391-3.451-9.391-7.699zM10.417 73.763h179.15V34.945c0-1.302-.537-2.49-1.4-3.369-.863-.863-2.051-1.4-3.369-1.4h-17.155c-2.881 0-5.208-2.327-5.208-5.208s2.327-5.208 5.208-5.208h17.171c4.183 0 7.975 1.709 10.726 4.46S200 30.762 200 34.945v44.043 105.843c0 4.183-1.709 7.975-4.46 10.726s-6.543 4.46-10.726 4.46H15.186c-4.183 0-7.975-1.709-10.726-4.46C1.709 192.79 0 188.997 0 184.814V78.971 34.945c0-4.183 1.709-7.975 4.46-10.726s6.543-4.46 10.726-4.46h18.343c2.881 0 5.208 2.327 5.208 5.208s-2.327 5.208-5.208 5.208H15.186c-1.302 0-2.49.537-3.369 1.4-.863.863-1.4 2.051-1.4 3.369zm179.167 10.433H10.417v100.618c0 1.302.537 2.49 1.4 3.369.863.863 2.051 1.4 3.369 1.4h169.629c1.302 0 2.49-.537 3.369-1.4.863-.863 1.4-2.051 1.4-3.369zM82.08 30.176c-2.881 0-5.208-2.327-5.208-5.208s2.327-5.208 5.208-5.208h34.977c2.881 0 5.208 2.327 5.208 5.208s-2.327 5.208-5.208 5.208z"/></svg>',
msteams:
'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 186.047"><path d="M195.349 39.535a20.93 20.93 0 1 1-41.86 0 20.93 20.93 0 1 1 41.86 0zm-55.847 30.233h51.66A8.84 8.84 0 0 1 200 78.605v47.056c0 17.938-14.541 32.479-32.479 32.479h0-.154c-17.938.003-32.481-14.537-32.484-32.474v-.005-51.274a4.62 4.62 0 0 1 4.619-4.619z" fill="#5059c9"/><path d="M149.614 69.767H64.34c-4.823.119-8.637 4.122-8.526 8.944v53.67c-.673 28.941 22.223 52.957 51.163 53.665 28.94-.708 51.836-24.725 51.163-53.665v-53.67c.112-4.823-3.703-8.825-8.526-8.944zm-10.079-39.535a30.233 30.233 0 0 1-60.465 0 30.233 30.233 0 0 1 60.465 0z" fill="#7b83eb"/><path opacity=".1" d="M111.628 69.767v75.209c-.023 3.449-2.113 6.547-5.302 7.86-1.015.43-2.107.651-3.209.651H59.907l-1.628-4.651c-1.628-5.337-2.459-10.885-2.465-16.465V78.698c-.112-4.815 3.697-8.811 8.512-8.93z"/><path opacity=".2" d="M106.977 69.767v79.86a8.241 8.241 0 0 1-.651 3.209c-1.313 3.189-4.412 5.279-7.86 5.302H62.093l-2.186-4.651a46.13 46.13 0 0 1-1.628-4.651 56.647 56.647 0 0 1-2.465-16.465V78.698c-.112-4.815 3.697-8.811 8.512-8.93z"/><path opacity=".2" d="M102.326 69.767v70.558a8.58 8.58 0 0 1-8.512 8.512H58.279a56.647 56.647 0 0 1-2.465-16.465V78.698c-.112-4.815 3.697-8.811 8.512-8.93z"/><path opacity=".1" d="M111.628 45.721v14.651l-2.326.093c-.791 0-1.535-.046-2.326-.093-1.57-.104-3.127-.353-4.651-.744a30.233 30.233 0 0 1-20.93-17.767 25.845 25.845 0 0 1-1.488-4.651h23.209c4.693.018 8.494 3.818 8.512 8.512z"/><use xlink:href="#B" opacity=".2" transform="scale(.08973306)"/><path d="M106.977 50.372v10c-1.57-.104-3.127-.353-4.651-.744a30.233 30.233 0 0 1-20.93-17.767h17.07c4.693.018 8.494 3.818 8.512 8.512zm0 19.395v70.558a8.58 8.58 0 0 1-8.512 8.512H58.279a56.647 56.647 0 0 1-2.465-16.465V78.698c-.112-4.815 3.697-8.811 8.512-8.93z" opacity=".2"/><path opacity=".2" d="M102.326 50.372v9.256a30.233 30.233 0 0 1-20.93-17.767h12.419c4.693.018 8.494 3.818 8.512 8.512z"/><linearGradient id="A" gradientUnits="userSpaceOnUse" x1="17.776" y1="35.199" x2="84.55" y2="150.848"><stop offset="0" stop-color="#5a62c3"/><stop offset=".5" stop-color="#4d55bd"/><stop offset="1" stop-color="#3940ab"/></linearGradient><path fill="url(#A)" d="M8.526 41.86H93.8a8.53 8.53 0 0 1 8.526 8.526v85.274a8.53 8.53 0 0 1-8.526 8.526H8.526A8.53 8.53 0 0 1 0 135.66V50.386a8.53 8.53 0 0 1 8.526-8.526z"/><path fill="#fff" d="M73.6 74.316H56.553v46.419h-10.86V74.316H28.726v-9.005H73.6z"/><defs><path id="B" d="M1192.167 561.355v111.442c-17.496-1.161-34.848-3.937-51.833-8.293a336.92 336.92 0 0 1-233.25-198.003h190.228c52.304.198 94.656 42.55 94.855 94.854z"/></defs></svg>',
ms365: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 239.766"><path d="M200 219.785l-.021-.012V20.591L128.615 0 .322 48.172 0 48.234.016 192.257l43.78-17.134V57.943l84.819-20.279-.012 172.285L.088 192.257l128.515 47.456v.053l71.376-19.753v-.227z"/></svg>',
outlookcom:
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 175"><path d="M178.725 0H71.275A8.775 8.775 0 0 0 62.5 8.775v9.975l60.563 18.75L187.5 18.75V8.775A8.775 8.775 0 0 0 178.725 0z" fill="#0364b8"/><path d="M197.813 96.281c.915-2.878 2.187-5.855 2.187-8.781-.002-1.485-.795-2.857-1.491-3.26l-68.434-38.99a9.37 9.37 0 0 0-9.244-.519c-.312.154-.614.325-.906.512l-67.737 38.6-.025.013-.075.044a4.16 4.16 0 0 0-2.088 3.6c.541 2.971 1.272 5.904 2.188 8.781l71.825 52.532z" fill="#0a2767"/><path d="M150 18.75h-43.75L93.619 37.5l12.631 18.75L150 93.75h37.5v-37.5z" fill="#28a8ea"/><path d="M150 18.75h37.5v37.5H150z" fill="#50d9ff"/><path d="M150 93.75l-43.75-37.5H62.5v37.5l43.75 37.5 67.7 11.05z" fill="#0364b8"/><path d="M106.25 56.25v37.5H150v-37.5zM150 93.75v37.5h37.5v-37.5zm-87.5-75h43.75v37.5H62.5z" fill="#0078d4"/><path d="M62.5 93.75h43.75v37.5H62.5z" fill="#064a8c"/><path d="M126.188 145.113l-73.706-53.75 3.094-5.438 68.181 38.825a3.3 3.3 0 0 0 2.625-.075l68.331-38.937 3.1 5.431z" fill="#0a2767" opacity=".5"/><path d="M197.919 91.106l-.088.05-.019.013-67.738 38.588c-2.736 1.764-6.192 1.979-9.125.569l23.588 31.631 51.588 11.257v-.001c2.434-1.761 3.876-4.583 3.875-7.587V87.5c.001 1.488-.793 2.862-2.081 3.606z" fill="#1490df"/><path d="M200 165.625v-4.613l-62.394-35.55-7.531 4.294a9.356 9.356 0 0 1-9.125.569l23.588 31.631 51.588 11.231v.025a9.362 9.362 0 0 0 3.875-7.588z" opacity=".05"/><path d="M199.688 168.019l-68.394-38.956-1.219.688c-2.734 1.766-6.19 1.984-9.125.575l23.588 31.631 51.587 11.256v.001a9.38 9.38 0 0 0 3.562-5.187z" opacity=".1"/><path d="M51.455 90.721c-.733-.467-1.468-1.795-1.455-3.221v78.125c-.007 5.181 4.194 9.382 9.375 9.375h131.25c1.395-.015 2.614-.366 3.813-.813.638-.258 1.252-.652 1.687-.974z" fill="#28a8ea"/><path d="M112.5 141.669V39.581a8.356 8.356 0 0 0-8.331-8.331H62.687v46.6l-10.5 5.987-.031.012-.075.044A4.162 4.162 0 0 0 50 87.5v.031-.031V150h54.169a8.356 8.356 0 0 0 8.331-8.331z" opacity=".1"/><path d="M106.25 147.919V45.831a8.356 8.356 0 0 0-8.331-8.331H62.687v40.35l-10.5 5.987-.031.012-.075.044A4.162 4.162 0 0 0 50 87.5v.031-.031 68.75h47.919a8.356 8.356 0 0 0 8.331-8.331z" opacity=".2"/><path d="M106.25 135.419V45.831a8.356 8.356 0 0 0-8.331-8.331H62.687v40.35l-10.5 5.987-.031.012-.075.044A4.162 4.162 0 0 0 50 87.5v.031-.031 56.25h47.919a8.356 8.356 0 0 0 8.331-8.331z" opacity=".2"/><path d="M100 135.419V45.831a8.356 8.356 0 0 0-8.331-8.331H62.687v40.35l-10.5 5.987-.031.012-.075.044A4.162 4.162 0 0 0 50 87.5v.031-.031 56.25h41.669a8.356 8.356 0 0 0 8.331-8.331z" opacity=".2"/><path d="M8.331 37.5h83.337A8.331 8.331 0 0 1 100 45.831v83.338a8.331 8.331 0 0 1-8.331 8.331H8.331A8.331 8.331 0 0 1 0 129.169V45.831A8.331 8.331 0 0 1 8.331 37.5z" fill="#0078d4"/><path d="M24.169 71.675a26.131 26.131 0 0 1 10.263-11.337 31.031 31.031 0 0 1 16.313-4.087 28.856 28.856 0 0 1 15.081 3.875 25.875 25.875 0 0 1 9.988 10.831 34.981 34.981 0 0 1 3.5 15.938 36.881 36.881 0 0 1-3.606 16.662 26.494 26.494 0 0 1-10.281 11.213 30 30 0 0 1-15.656 3.981 29.556 29.556 0 0 1-15.425-3.919 26.275 26.275 0 0 1-10.112-10.85 34.119 34.119 0 0 1-3.544-15.744 37.844 37.844 0 0 1 3.481-16.563zm10.938 26.613a16.975 16.975 0 0 0 5.769 7.463 15.069 15.069 0 0 0 9.019 2.719 15.831 15.831 0 0 0 9.631-2.806 16.269 16.269 0 0 0 5.606-7.481 28.913 28.913 0 0 0 1.787-10.406 31.644 31.644 0 0 0-1.687-10.538 16.681 16.681 0 0 0-5.413-7.75 14.919 14.919 0 0 0-9.544-2.956 15.581 15.581 0 0 0-9.231 2.744 17.131 17.131 0 0 0-5.9 7.519 29.85 29.85 0 0 0-.044 21.5z" fill="#fff"/></svg>',
yahoo:
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 177.803"><path d="M0 43.284h38.144l22.211 56.822 22.5-56.822h37.135L64.071 177.803H26.694l15.308-35.645L.001 43.284zm163.235 45.403H121.64L158.558 0 200 .002zm-30.699 8.488c12.762 0 23.108 10.346 23.108 23.106s-10.345 23.106-23.108 23.106a23.11 23.11 0 0 1-23.104-23.106 23.11 23.11 0 0 1 23.104-23.106z"/></svg>',
close:
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 200"><path d="M2.321 13.529a7.927 7.927 0 0 1 0-11.208 7.927 7.927 0 0 1 11.208 0l86.471 86.471L186.47 2.321a7.927 7.927 0 0 1 11.209 0 7.927 7.927 0 0 1 0 11.208l-86.474 86.469 86.472 86.473a7.927 7.927 0 0 1-11.209 11.208l-86.471-86.471-86.469 86.471a7.927 7.927 0 0 1-11.208-11.208l86.471-86.473z"/></svg>',
location:
'<svg viewBox="0 0 200 266.42" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="m148.54 230.43c-12.12 13.291-26.234 25.193-42.083 34.82-1.9513 1.431-4.5964 1.6044-6.7645 0.21681-23.416-14.895-43.08-32.782-58.539-52.23-21.334-26.755-34.755-56.414-39.351-84.99-4.6831-28.966-0.30354-56.848 14.114-79.505 5.6805-8.9543 12.944-17.106 21.79-24.153 20.337-16.196 43.557-24.76 66.713-24.586 22.288 0.17345 44.295 8.4773 63.309 25.844 6.6778 6.0707 12.293 13.03 16.89 20.575 15.502 25.54 18.841 58.105 12.033 91.104-6.7212 32.608-23.416 65.737-48.11 92.839zm-48.544-178.91c27.492 0 49.758 22.288 49.758 49.758 0 27.492-22.288 49.758-49.758 49.758-27.492 0-49.758-22.267-49.758-49.758-0.02168-27.492 22.267-49.758 49.758-49.758z" stroke-width="2.1681"/></svg>',
warning:
'<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"><path d="m100 0c27.613 0 52.613 11.195 70.711 29.293 18.094 18.094 29.289 43.098 29.289 70.707 0 27.613-11.195 52.613-29.289 70.711-18.098 18.094-43.098 29.289-70.711 29.289-27.609 0-52.613-11.195-70.707-29.289-18.098-18.098-29.293-43.098-29.293-70.711 0-27.609 11.195-52.613 29.293-70.707 18.094-18.098 43.098-29.293 70.707-29.293zm57.66 42.34c-14.758-14.754-35.145-23.883-57.66-23.883-22.516 0-42.902 9.1289-57.66 23.883-14.754 14.758-23.883 35.145-23.883 57.66 0 22.516 9.1289 42.902 23.883 57.66 14.758 14.754 35.145 23.883 57.66 23.883 22.516 0 42.902-9.1289 57.66-23.883 14.754-14.758 23.883-35.145 23.883-57.66 0-22.516-9.1289-42.902-23.883-57.66z" fill="#f44336" fill-rule="nonzero" stroke-width=".39062"/><g transform="matrix(3.8384 0 0 3.8384 2277.8 -576.85)" style="shape-inside:url(#rect7396);white-space:pre" aria-label="!"><path d="m-563.8 161.59-0.65341 20.185h-5.8381l-0.65341-20.185zm-3.5796 29.503q-1.5199 0-2.6136-1.0795-1.0796-1.0796-1.0796-2.6136 0-1.5057 1.0796-2.571 1.0938-1.0796 2.6136-1.0796 1.4631 0 2.571 1.0796 1.1222 1.0653 1.1222 2.571 0 1.0227-0.52557 1.8608-0.51137 0.83807-1.3494 1.3352-0.82387 0.49715-1.8182 0.49715z"/></g></svg>',
checkmark:
'<svg version="1.1" viewBox="0 0 87.41 79.72" xmlns="http://www.w3.org/2000/svg"><path d="m2.076 33.666s6.0748-0.59297 17.413 4.2983c9.3883 4.5751 11.891 8.3955 11.891 8.3955 5.38-8.65 11.11-16.6 17.16-23.9 10.412-12.578 24.613-22.448 24.613-22.448l14.257-0.012228s-19.308 19.294-32.483 38.51-22.877 41.21-22.877 41.21-9.3948-18.164-14.53-24.53-10.77-11.59-17.52-16.22z" fill="#45b555"/></svg>',
rsvp: '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 104.31 122.88"><g><path d="M25.85,63.15c-0.04-0.12-0.08-0.28-0.1-0.42c-0.22-1.89-0.43-3.98-0.62-5.78c-0.26-2.64-0.55-5.69-0.76-7.83 c-0.14-1.45-0.6-2.83-1.27-3.86c-0.45-0.66-0.95-1.15-1.51-1.39c-0.45-0.18-1-0.2-1.57,0.02c-0.78,0.3-1.65,0.93-2.62,2.03 c-0.86,0.98-1.53,2.29-2.09,3.68c-0.79,2.03-1.26,4.19-1.45,5.67c-0.02,0.1-0.02,0.18-0.06,0.26L8.42,86.07 c-0.08,0.4-0.24,0.76-0.48,1.04c-1.81,2.33-2.95,4.33-3.28,5.95c-0.24,1.19,0,2.15,0.79,2.9l19.8,19.8 c1.26,1.21,2.72,1.97,4.47,2.29c1.91,0.36,4.14,0.16,6.7-0.54c0.04,0,0.1-0.02,0.14-0.02c0.97-0.26,2.24-0.57,3.46-0.88 c5.31-1.29,9.94-2.43,14.23-6.33l5.52-5.76c0.05-0.1,0.14-0.18,0.22-0.26s0.62-0.62,1.35-1.31c3.78-3.69,8.45-8.25,5.61-12.24 l-2.21-2.21c-1.07,1.04-2.21,2.05-3.3,3.02c-1,0.88-1.93,1.69-2.78,2.55c-0.91,0.91-2.38,0.91-3.3,0c-0.91-0.92-0.91-2.38,0-3.3 c0.86-0.86,1.91-1.79,3-2.76c3.74-3.3,8.03-7.07,5.73-10.38l-2.19-2.19c-0.12-0.12-0.22-0.26-0.31-0.4c-1.26,1.29-2.64,2.52-4,3.72 c-1,0.88-1.93,1.69-2.78,2.55c-0.91,0.91-2.38,0.91-3.3,0s-0.91-2.38,0-3.3c0.86-0.86,1.91-1.79,3-2.76 c3.74-3.3,8.03-7.07,5.73-10.38l-2.19-2.19c-0.16-0.16-0.28-0.31-0.38-0.5l-6.42,6.42c-0.91,0.91-2.38,0.91-3.3,0s-0.91-2.38,0-3.3 l17.22-17.25c2.88-2.88,3.54-5.88,2.78-8.15c-0.28-0.83-0.74-1.57-1.31-2.14s-1.31-1.03-2.14-1.31c-2.24-0.74-5.23-0.06-8.19,2.9 l-30.2,30.2c-0.91,0.91-2.38,0.91-3.3,0s-0.91-2.38,0-3.3l3.07-3.07L25.85,63.15L25.85,63.15L25.85,63.15z M83.23,24.31 c-1.22,1.3-3.24,1.34-4.52,0.14c-1.3-1.22-1.34-3.24-0.14-4.52l8.82-9.39c1.22-1.3,3.25-1.34,4.52-0.14 c1.3,1.22,1.34,3.24,0.14,4.52L83.23,24.31L83.23,24.31L83.23,24.31L83.23,24.31z M43.96,23.65c1.3,1.22,1.34,3.25,0.14,4.52 c-1.22,1.3-3.25,1.34-4.52,0.14l-9.4-8.82c-1.29-1.23-1.33-3.25-0.14-4.52c1.22-1.3,3.25-1.34,4.52-0.14L43.96,23.65L43.96,23.65 L43.96,23.65z M63.69,15.96c0.05,1.76-1.34,3.24-3.09,3.3s-3.24-1.34-3.3-3.09L56.91,3.3c-0.06-1.75,1.34-3.24,3.09-3.3 c1.76-0.05,3.24,1.34,3.29,3.09L63.69,15.96L63.69,15.96L63.69,15.96z M76.88,63.31c-1.3-1.22-1.34-3.25-0.14-4.52 c1.22-1.3,3.24-1.34,4.52-0.14l9.39,8.82c1.3,1.22,1.34,3.24,0.14,4.52c-1.22,1.3-3.24,1.34-4.52,0.14L76.88,63.31L76.88,63.31 L76.88,63.31z M88.36,44.35c-1.75,0.06-3.24-1.34-3.3-3.09c-0.05-1.75,1.34-3.24,3.09-3.3l12.86-0.43c1.75-0.06,3.24,1.34,3.3,3.09 s-1.34,3.24-3.09,3.3L88.36,44.35L88.36,44.35L88.36,44.35z M60.88,58.97c0.17,0.1,0.34,0.22,0.5,0.38l2.29,2.29 c0.12,0.12,0.24,0.28,0.34,0.42c2.57,3.52,2.17,6.66,0.42,9.52c0.31,0.12,0.62,0.29,0.86,0.54l2.29,2.29 c0.12,0.12,0.24,0.28,0.34,0.42c2.76,3.8,2.07,7.12,0,10.14c0.1,0.05,0.17,0.14,0.28,0.24l2.29,2.29c0.12,0.12,0.24,0.28,0.34,0.42 c5.31,7.26-1.02,13.42-6.1,18.39l-1.31,1.31l-5.67,5.95l-0.18,0.17c-5.19,4.71-10.33,5.97-16.28,7.42c-1,0.24-2,0.5-3.4,0.86 c-0.04,0-0.06,0.02-0.1,0.02c-3.22,0.88-6.14,1.09-8.76,0.62c-2.66-0.48-4.97-1.67-6.9-3.56L2.31,99.29 c-2-1.93-2.69-4.31-2.12-7.14c0.43-2.26,1.75-4.77,3.81-7.47L9.3,54.74v-0.12c0.24-1.71,0.78-4.24,1.71-6.68 c0.71-1.83,1.67-3.62,2.92-5.07c1.51-1.71,3-2.76,4.47-3.32c1.81-0.69,3.54-0.6,5.07,0.06c1.43,0.6,2.64,1.69,3.56,3.08 c1.12,1.67,1.85,3.8,2.05,6.02c0.16,1.83,0.48,4.85,0.78,7.81l0.24,2.47L53,36.07c4.4-4.4,9.16-5.27,12.97-4.02 c1.53,0.5,2.88,1.33,4,2.45s1.95,2.47,2.45,4c1.26,3.8,0.4,8.63-3.92,12.95l-7.59,7.59L60.88,58.97L60.88,58.97L60.88,58.97z"/></g></svg>',
};
async function atcb_decorate_data(data) {
data = atcb_decorate_data_boolean(data);
data.timeZone = atcb_decorate_data_timezone(data.timeZone);
data = atcb_decorate_data_rrule(data);
data = atcb_decorate_data_options(data);
data = atcb_decorate_data_style(data);
data.sizes = atcb_decorate_sizes(data.size);
data.lightMode = atcb_decorate_light_mode(data.lightMode);
data = atcb_decorate_data_i18n(data);
data = atcb_decorate_data_dates(data);
data = atcb_decorate_data_meta(data);
data = atcb_decorate_data_extend(data);
data = atcb_decorate_data_button_status_handling(data);
data = await atcb_decorate_data_rsvp(data);
return data;
}
function atcb_decorate_data_boolean(data) {
for (let i = 0; i < atcbWcBooleanParams.length; i++) {
const attr = atcbWcBooleanParams[`${i}`];
if (data[`${attr}`]) {
if (typeof data[`${attr}`] !== 'boolean') {
const val = data[`${attr}`].toString().trim().toLowerCase() || '';
data[`${attr}`] = val === '' || val === 'true' ? true : false;
}
} else {
data[`${attr}`] = false;
}
}
return data;
}
function atcb_decorate_data_timezone(tz = null) {
if (!tz || tz === '') {
return 'GMT';
}
return tz;
}
function atcb_decorate_data_rrule(data) {
if (data.recurrence && data.recurrence !== '') {
data.recurrence = data.recurrence.replace(/\s+/g, '').toUpperCase();
if (!/^(?:RRULE:[\w=;,:+\-/\\]+|daily|weekly|monthly|yearly)$/im.test(data.recurrence)) {
data.recurrence = '!wrong rrule format!';
} else {
if (/^RRULE:/i.test(data.recurrence)) {
data.recurrence_simplyfied = false;
const rruleParts = data.recurrence.substring(6).split(';');
const rruleObj = new Object();
rruleParts.forEach(function (rule) {
rruleObj[rule.split('=')[0]] = rule.split('=')[1];
});
data.recurrence_until = rruleObj.UNTIL ? rruleObj.UNTIL : '';
data.recurrence_count = rruleObj.COUNT ? rruleObj.COUNT : '';
data.recurrence_byDay = rruleObj.BYDAY ? rruleObj.BYDAY : '';
data.recurrence_byMonth = rruleObj.BYMONTH ? rruleObj.BYMONTH : '';
data.recurrence_byMonthDay = rruleObj.BYMONTHDAY ? rruleObj.BYMONTHDAY : '';
data.recurrence_interval = rruleObj.INTERVAL ? rruleObj.INTERVAL : 1;
data.recurrence_frequency = rruleObj.FREQ ? rruleObj.FREQ : '';
} else {
data.recurrence_simplyfied = true;
if (!data.recurrence_interval || data.recurrence_interval === '') {
data.recurrence_interval = 1;
}
if (!data.recurrence_weekstart || (data.recurrence_weekstart === '') | (data.recurrence_weekstart.length > 2)) {
data.recurrence_weekstart = 'MO';
}
data.recurrence_frequency = data.recurrence;
data.recurrence = 'RRULE:FREQ=' + data.recurrence + ';WKST=' + data.recurrence_weekstart + ';INTERVAL=' + data.recurrence_interval;
if (data.recurrence_until && data.recurrence_until !== '') {
if (data.endTime && data.endTime !== '') {
data.recurrence = data.recurrence + ';UNTIL=' + data.recurrence_until.replace(/-/g, '').slice(0, 8) + 'T' + data.endTime.replace(':', '') + '00';
} else {
data.recurrence = data.recurrence + ';UNTIL=' + data.recurrence_until.replace(/-/g, '').slice(0, 8);
}
}
if (data.recurrence_count && data.recurrence_count !== '') {
data.recurrence = data.recurrence + ';COUNT=' + data.recurrence_count;
}
if (data.recurrence_byDay && data.recurrence_byDay !== '') {
data.recurrence = data.recurrence + ';BYDAY=' + data.recurrence_byDay;
}
if (data.recurrence_byMonth && data.recurrence_byMonth !== '') {
data.recurrence = data.recurrence + ';BYMONTH=' + data.recurrence_byMonth;
}
if (data.recurrence_byMonthDay && data.recurrence_byMonthDay !== '') {
data.recurrence = data.recurrence + ';BYMONTHDAY=' + data.recurrence_byMonthDay;
}
}
}
}
return data;
}
function atcb_decorate_data_options(data) {
const theOptions = (function () {
if (atcbIsiOS() || data.fakeIOS) {
if (data.optionsIOS && data.optionsIOS.length > 0) {
return data.optionsIOS;
}
if (data.optionsMobile && data.optionsMobile.length > 0) {
return data.optionsMobile;
}
}
if ((atcbIsAndroid() || data.fakeMobile || data.fakeAndroid) && data.optionsMobile && data.optionsMobile.length > 0) {
return data.optionsMobile;
}
return data.options || ['ical'];
})();
let newOptions = [];
let iCalGiven = false;
let appleGiven = false;
for (let i = 0; i < theOptions.length; i++) {
const cleanOption = theOptions[`${i}`].split('|');
const optionName = cleanOption[0].toLowerCase().replace('microsoft', 'ms').replace(/\./, '');
if (optionName === 'apple') {
appleGiven = true;
}
if (optionName === 'ical') {
iCalGiven = true;
}
if (
((atcbIsiOS() || data.fakeIOS) && atcbIOSInvalidOptions.includes(optionName)) ||
((atcbIsAndroid() || data.fakeAndroid) && atcbAndroidInvalidOptions.includes(optionName)) ||
(data.recurrence && data.recurrence !== '' && (!atcbValidRecurrOptions.includes(optionName) || (data.recurrence_until && data.recurrence_until !== '' && (optionName === 'apple' || optionName === 'ical')) || ((atcbIsiOS() || data.fakeIOS) && optionName === 'google'))) ||
(data.subscribe && atcbInvalidSubscribeOptions.includes(optionName))
) {
continue;
}
if ((atcbIsMobile() || data.fakeMobile) && data.subscribe && (optionName === 'ms365' || optionName === 'outlookcom')) {
continue;
}
newOptions.push(optionName);
}
if (data.subscribe && data.icsFile && data.icsFile.startsWith('https://calendar.google.com/calendar/') && !data.icsFile.endsWith('.ics')) {
newOptions = ['google'];
}
if (newOptions.length === 0) {
if (!atcbIsiOS() && !data.fakeIOS) {
newOptions.push('ical');
}
iCalGiven = true;
}
if ((atcbIsiOS() || data.fakeIOS) && iCalGiven && !appleGiven) {
newOptions.push('apple');
}
if ((atcbIsAndroid() || data.fakeAndroid) && appleGiven && !iCalGiven) {
newOptions.push('ical');
}
newOptions.sort();
data.options = newOptions;
return data;
}
function atcb_decorate_data_style(data) {
if (data.inlineRSVP) {
data.inline = true;
}
if (!data.listStyle || data.listStyle === '') {
data.listStyle = 'dropdown';
}
if (data.listStyle === 'modal') {
data.trigger = 'click';
}
if (data.buttonStyle && data.buttonStyle !== '' && data.buttonStyle != 'default') {
if (data.buttonStyle == 'round' || data.buttonStyle == 'text' || data.buttonStyle == 'date' || data.buttonStyle == 'neumorphism') {
data.trigger = 'click';
}
} else {
data.buttonStyle = 'default';
}
if ((data.buttonStyle == 'default' || data.buttonStyle == '3d' || data.buttonStyle == 'flat') && !data.hideTextLabelList && data.hideTextLabelButton && (data.listStyle == 'dropdown' || data.listStyle == 'dropdown-static' || data.listStyle == 'dropup-static')) {
data.listStyle = 'overlay';
}
if (data.buttonsList && data.buttonStyle == 'date') {
data.buttonsList = false;
}
return data;
}
function atcb_decorate_sizes(size) {
const sizes = [];
sizes['l'] = sizes['m'] = sizes['s'] = 16;
if (size && size !== '') {
const sizeParts = size.split('|');
for (let i = 0; i < sizeParts.length; i++) {
sizeParts[`${i}`] = parseInt(sizeParts[`${i}`]);
}
if (sizeParts[0] >= 0 && sizeParts[0] < 11) {
sizes['l'] = sizes['m'] = sizes['s'] = 10 + sizeParts[0];
}
if (sizeParts.length > 2) {
if (sizeParts[1] >= 0 && sizeParts[1] < 11) {
sizes['m'] = 10 + sizeParts[1];
}
if (sizeParts[2] >= 0 && sizeParts[2] < 11) {
sizes['s'] = 10 + sizeParts[2];
}
} else if (sizeParts.length == 2) {
if (sizeParts[1] >= 0 && sizeParts[1] < 11) {
sizes['m'] = sizes['s'] = 10 + sizeParts[1];
}
}
}
return sizes;
}
function atcb_decorate_light_mode(lightMode = '') {
if (lightMode == 'system' && atcbIsBrowser()) {
const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
return prefersDarkScheme.matches ? 'dark' : 'light';
}
if (lightMode != 'bodyScheme' && lightMode != 'dark') {
return 'light';
}
return lightMode;
}
function atcb_decorate_data_i18n(data) {
if (!data.language || data.language === '' || !availableLanguages.includes(data.language)) {
data.language = 'en';
}
if (data.language.length > 2) {
data.language = data.language.substring(0, 2);
}
if (rtlLanguages.includes(data.language)) {
data.rtl = true;
} else {
data.rtl = false;
}
return data;
}
function atcb_decorate_data_dates(data) {
if (data.dates && data.dates.length > 0) {
for (let i = 0; i < data.dates.length; i++) {
if (!data.dates[`${i}`].timeZone && data.timeZone) {
data.dates[`${i}`].timeZone = data.timeZone;
}
if (!data.dates[`${i}`].useUserTZ && data.useUserTZ) {
data.dates[`${i}`].useUserTZ = data.useUserTZ;
}
const cleanedUpDates = atcb_date_cleanup(data.dates[`${i}`]);
data.dates[`${i}`].startDate = cleanedUpDates.startDate;
data.dates[`${i}`].endDate = cleanedUpDates.endDate;
data.dates[`${i}`].startTime = cleanedUpDates.startTime;
data.dates[`${i}`].endTime = cleanedUpDates.endTime;
data.dates[`${i}`].timeZone = cleanedUpDates.timeZone;
data.dates[`${i}`].timestamp = atcb_date_specials_calculation('timestamp', data.dates[`${i}`].startDate, data.dates[`${i}`].startTime, data.dates[`${i}`].timeZone);
data.dates[`${i}`].overdue = atcb_date_specials_calculation('overdue', data.dates[`${i}`].endDate, data.dates[`${i}`].endTime, data.dates[`${i}`].timeZone);
}
} else {
data.dates = [];
data.dates[0] = new Object();
if (data.useUserTZ) data.dates[0].useUserTZ = data.useUserTZ;
const cleanedUpDates = atcb_date_cleanup(data);
data.startDate = data.dates[0].startDate = cleanedUpDates.startDate;
data.endDate = data.dates[0].endDate = cleanedUpDates.endDate;
data.startTime = data.dates[0].startTime = cleanedUpDates.startTime;
data.endTime = data.dates[0].endTime = cleanedUpDates.endTime;
data.timeZone = data.dates[0].timeZone = cleanedUpDates.timeZone;
if (!data.recurrence) {
data.dates[0].overdue = atcb_date_specials_calculation('overdue', data.endDate, data.endTime, data.timeZone);
} else {
data.dates[0].overdue = false;
}
}
const now = new Date();
if (!data.created || data.created === '') {
data.created = atcb_format_datetime(now, 'clean', true);
}
if (!data.updated || data.updated === '') {
data.updated = atcb_format_datetime(now, 'clean', true);
}
return data;
}
function atcb_decorate_data_meta(data) {
if (!data.status || data.status === '') {
data.status = 'CONFIRMED';
}
if (!data.sequence || data.sequence === '') {
data.sequence = 0;
}
return data;
}
function atcb_decorate_data_description(data, i) {
const cleanDescription = (desc) => desc.replace(/(\\r\\n|\\n|\\r|<br(\s*\/?)>)/g, '');
let description = data.dates[`${i}`].description || data.description || '';
if (description) {
description = cleanDescription(description);
if (data.customVar) {
for (const key in data.customVar) {
const sanitizedKey = '%%' + key.replace(/[^\w\-.]/g, '') + '%%';
// eslint-disable-next-line security/detect-non-literal-regexp
description = description.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
}
}
const descriptionHtmlFree = atcb_rewrite_html_elements(description, true);
const descriptionHtmlFreeICal = atcb_rewrite_html_elements(description, true, true);
description = atcb_rewrite_html_elements(description);
data.dates[`${i}`] = { ...data.dates[`${i}`], description, descriptionHtmlFree, descriptionHtmlFreeICal };
} else {
data.dates[`${i}`].descriptionHtmlFree = data.dates[`${i}`].descriptionHtmlFreeICal = data.dates[`${i}`].description = '';
}
return data;
}
function atcb_decorate_data_extend(data) {
for (let i = 0; i < data.dates.length; i++) {
data = atcb_decorate_data_description(data, i);
if (!data.dates[`${i}`].name || data.dates[`${i}`].name === '') {
data.dates[`${i}`].name = data.name;
}
if (!data.dates[`${i}`].status) {
data.dates[`${i}`].status = data.status.toUpperCase();
} else {
data.dates[`${i}`].status = data.dates[`${i}`].status.toUpperCase();
}
if (!data.dates[`${i}`].sequence) {
data.dates[`${i}`].sequence = data.sequence;
}
if (!data.dates[`${i}`].organizer && data.organizer) {
data.dates[`${i}`].organizer = data.organizer;
}
if (!data.dates[`${i}`].attendee && data.attendee) {
data.dates[`${i}`].attendee = data.attendee;
}
if (!data.dates[`${i}`].availability && data.availability) {
data.dates[`${i}`].availability = data.availability.toLowerCase();
} else if (data.dates[`${i}`].availability) {
data.dates[`${i}`].availability = data.dates[`${i}`].availability.toLowerCase();
}
if (!data.dates[`${i}`].location && data.location) {
data.dates[`${i}`].location = data.location;
}
if (data.dates[`${i}`].location && data.dates[`${i}`].location.startsWith('http')) {
data.dates[`${i}`].onlineEvent = true;
} else {
data.dates[`${i}`].onlineEvent = false;
}
if (!data.dates[`${i}`].uid) {
if (i === 0 && data.uid && data.uid !== '') {
data.dates[0].uid = data.uid;
} else {
if (data.uid && data.uid !== '') {
data.dates[`${i}`].uid = data.uid + '-' + (i + 1);
} else {
data.dates[`${i}`].uid = atcb_generate_uuid();
}
}
}
if (data.customVar) {
for (const key in data.customVar) {
const sanitizedKey = '%%' + key.replace(/[^\w\-.]/g, '') + '%%';
// eslint-disable-next-line security/detect-non-literal-regexp
data.dates[`${i}`].name = data.dates[`${i}`].name.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
// eslint-disable-next-line security/detect-non-literal-regexp
data.dates[`${i}`].location = data.dates[`${i}`].location.replace(new RegExp(sanitizedKey, 'gi'), data.customVar[`${key}`]);
}
}
}
if (data.recurrence && data.recurrence !== '') {
data.dates[0].recurrence = data.recurrence;
}
if (data.dates.length > 1) {
data.dates.sort((a, b) => a.timestamp - b.timestamp);
}
return data;
}
function atcb_date_cleanup(dateTimeData) {
function isValidDateFormat(dateStr) {
return /^\d\d\d\d-\d\d-\d\d(?:T\d\d:\d\d)?(?::\d\d)?(?:.\d\d\d)?Z?$/i.test(dateStr);
}
function isValidTodayFormat(dateStr) {
return /^today(?:\+(?:\d|\d\d|\d\d\d|\d\d\d\d))?$/i.test(dateStr);
}
if (!dateTimeData.endDate || dateTimeData.endDate === '') {
dateTimeData.endDate = dateTimeData.startDate;
}
const endpoints = ['start', 'end'];
endpoints.forEach(function (point) {
const dateStr = dateTimeData[point + 'Date'];
if (!isValidDateFormat(dateStr) && !isValidTodayFormat(dateStr)) {
dateTimeData[point + 'Date'] = 'badly-formed';
} else {
if (isValidTodayFormat(dateStr)) dateTimeData[point + 'Date'] = atcb_date_calculation(dateStr);
if (dateTimeData[point + 'Date']) {
const tmpSplitStartDate = dateTimeData[point + 'Date'].split('T');
if (tmpSplitStartDate[1]) {
dateTimeData[point + 'Date'] = tmpSplitStartDate[0];
dateTimeData[point + 'Time'] = tmpSplitStartDate[1];
}
}
if (dateTimeData[point + 'Time'] && dateTimeData[point + 'Time'].length > 5) {
dateTimeData[point + 'Time'] = dateTimeData[point + 'Time'].substring(0, 5);
}
}
});
if (dateTimeData.timeZone === 'currentBrowser' || dateTimeData.useUserTZ) {
const browserTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone || 'GMT';
if (dateTimeData.useUserTZ && dateTimeData.startTime && dateTimeData.startTime !== '' && dateTimeData.endTime && dateTimeData.endTime !== '') {
const newStartDateTime = atcb_translate_via_time_zone(dateTimeData.startDate, dateTimeData.startTime, dateTimeData.timeZone, browserTimezone);
const newEndDateTime = atcb_translate_via_time_zone(dateTimeData.endDate, dateTimeData.endTime, dateTimeData.timeZone, browserTimezone);
dateTimeData.startDate = newStartDateTime[0];
dateTimeData.startTime = newStartDateTime[1];
dateTimeData.endDate = newEndDateTime[0];
dateTimeData.endTime = newEndDateTime[1];
}
dateTimeData.timeZone = browserTimezone;
}
return dateTimeData;
}
function atcb_date_specials_calculation(type, dateString, timeString = null, timeZone) {
try {
const tmpDate = (function () {
if (timeString) {
const offsetEnd = tzlib_get_offset(timeZone, dateString, timeString);
return new Date(dateString + ' ' + timeString + ':00 GMT' + offsetEnd);
}
return new Date(dateString);
})();
if (type === 'timestamp') {
return tmpDate.getTime();
}
if (!timeString) {
tmpDate.setDate(tmpDate.getDate() + 1);
}
const currentUtcDate = new Date().toISOString();
return tmpDate.getTime() < new Date(currentUtcDate).getTime();
} catch {
return false;
}
}
function atcb_date_calculation(dateString) {
const today = new Date();
const todayString = today.getUTCFullYear() + '-' + (today.getUTCMonth() + 1) + '-' + today.getUTCDate();
dateString = dateString.replace(/today/gi, todayString);
const dateStringParts = dateString.split('+');
const dateParts = dateStringParts[0].split('-');
const newDate = new Date(Date.UTC(dateParts[0], dateParts[1] - 1, dateParts[2].substring(0, 2)));
if (dateStringParts[1] && dateStringParts[1] > 0) {
newDate.setDate(newDate.getDate() + parseInt(dateStringParts[1]));
}
try {
return newDate.toISOString().replace(/T(\d{2}:\d{2}:\d{2}\.\d{3})Z/g, '');
} catch {
return false;
}
}
function atcb_decorate_data_button_status_handling(data) {
if (!data.pastDateHandling || (data.pastDateHandling != 'disable' && data.pastDateHandling != 'hide')) {
data.pastDateHandling = 'none';
}
data.allOverdue = (function () {
for (let i = 0; i < data.dates.length; i++) {
if (!data.dates[`${i}`].overdue) {
return false;
}
}
return true;
})();
if (data.allOverdue) {
if (data.pastDateHandling == 'disable') {
data.disabled = true;
} else if (data.pastDateHandling == 'hide') {
data.hidden = true;
}
}
data.allCancelled = (function () {
for (let i = 0; i < data.dates.length; i++) {
if (!data.dates[`${i}`].status || data.dates[`${i}`].status.toLowerCase() !== 'cancelled') {
return false;
}
}
return true;
})();
if (data.disabled || data.hidden) {
data.blockInteraction = true;
}
return data;
}
async function atcb_decorate_data_rsvp(data) {
if (typeof atcb_check_bookings !== 'function' || !data.rsvp || !data.proKey || Object.keys(data.rsvp).length === 0) return data;
data.rsvp.expired = (function () {
if (data.rsvp && data.rsvp.expires && new Date(data.rsvp.expires) < new Date()) {
return true;
}
return false;
})();
if (data.rsvp.max) {
const bookings = await atcb_check_bookings(data.proKey, data.dev);
data.rsvp.seatsLeft = data.rsvp.max - bookings;
if (data.rsvp.seatsLeft < 1) {
data.rsvp.bookedOut = true;
}
if (data.rsvp.expired || data.rsvp.bookedOut) {
data.blockInteraction = true;
}
if (data.blockInteraction) {
data.disabled = true;
}
}
return data;
}
async function atcb_check_required(data) {
if (!data.name || data.name === '') {
throw new Error('Add to Calendar Button generation failed: required name information missing');
}
if (data.dates != null && data.dates.length > 0) {
if (data.subscribe === true && data.dates.length > 1) {
throw new Error('Add to Calendar Button generation failed: a subscription calendar cannot be a multi-date setup');
}
const requiredMultiField = ['name', 'startDate'];
const requiredMultiFieldFlex = ['name'];
return requiredMultiField.every(function (field) {
for (let i = 0; i < data.dates.length; i++) {
if (
(!requiredMultiFieldFlex.includes(`${field}`) && (!data.dates[`${i}`][`${field}`] || data.dates[`${i}`][`${field}`] === '')) ||
(requiredMultiFieldFlex.includes(`${field}`) && (!data.dates[`${i}`][`${field}`] || data.dates[`${i}`][`${field}`] === '') && (!data[`${field}`] || data[`${field}`] === ''))
) {
if (!data.subscribe || field !== 'startDate') {
throw new Error('Add to Calendar Button generation failed: required setting missing [dates array object #' + (i + 1) + '/' + data.dates.length + '] => [' + field + ']');
} else {
data.dates[`${i}`].startDate = 'today';
}
}
}
return true;
});
} else {
const requiredSingleField = ['startDate'];
return requiredSingleField.every(function (field) {
if (!data[`${field}`] || data[`${field}`] === '') {
if (!data.subscribe || field !== 'startDate') {
throw new Error('Add to Calendar Button generation failed: required setting missing [' + field + ']');
} else {
data.startDate = 'today';
}
}
return true;
});
}
}
async function atcb_validate(data) {
const msgPrefix = 'Add to Calendar Button generation (' + data.identifier + ')';
try {
await atcb_validate_icsFile(data, msgPrefix);
await atcb_validate_buttonStyle(data, msgPrefix);
await atcb_validate_subscribe(data, msgPrefix);
await atcb_validate_created(data, msgPrefix);
await atcb_validate_updated(data, msgPrefix);
await atcb_validate_options(data, msgPrefix);
await atcb_validate_date_blocks(data, msgPrefix);
await atcb_validate_rrule(data, msgPrefix);
if (data.recurrence_simplyfied) {
await atcb_validate_rrule_simplyfied(data, msgPrefix);
}
return true;
} catch (e) {
throw new Error(e.message);
}
}
async function atcb_validate_icsFile(data, msgPrefix, i = '', msgSuffix = '') {
const icsFileStr = (function () {
if (i !== '' && data.dates[`${i}`].icsFile) {
return data.dates[`${i}`].icsFile;
}
if (i === '' && data.icsFile) {
return data.icsFile;
}
return '';
})();
if (icsFileStr !== '') {
if (!atcb_secure_url(icsFileStr, false) || (!data.icsFile.startsWith('https://') && !data.icsFile.startsWith('http://'))) {
throw new Error(msgPrefix + ' failed: explicit ics file path not valid' + msgSuffix);
}
}
return true;
}
async function atcb_validate_buttonStyle(data, msgPrefix) {
const availableStyles = ['default', '3d', 'flat', 'round', 'neumorphism', 'text', 'date', 'custom', 'none'];
if (!availableStyles.includes(data.buttonStyle)) {
throw new Error(msgPrefix + ' failed: provided buttonStyle invalid');
}
if (data.customCss && data.customCss !== '' && (!atcb_secure_url(data.customCss, false) || !/\.css(?:$|\?)/.test(data.customCss))) {
throw new Error(msgPrefix + ' failed: customCss provided, but no valid url');
}
if ((!data.customCss || data.customCss === '') && data.buttonStyle === 'custom') {
throw new Error(msgPrefix + ' failed: buttonStyle "custom" selected, but no customCss file provided');
}
if (data.rsvp && (data.buttonStyle === 'date' || data.buttonStyle === 'none')) {
throw new Error(msgPrefix + ' failed: buttonStyle ' + data.buttonStyle + ' is not compatible with the RSVP functionality');
}
return true;
}
async function atcb_validate_subscribe(data, msgPrefix) {
if (data.subscribe === true && (!data.icsFile || data.icsFile === '')) {
throw new Error(msgPrefix + ' failed: a subscription calendar requires a valid explicit ics file as well');
}
return true;
}
async function atcb_validate_created(data, msgPrefix) {
if (!/^\d{8}T\d{6}Z$/.test(data.created)) {
throw new Error(msgPrefix + ' failed: created date format not valid. Needs to be a full ISO-8601 UTC date and time string, formatted YYYYMMDDTHHMMSSZ');
}
return true;
}
async function atcb_validate_updated(data, msgPrefix) {
if (!/^\d{8}T\d{6}Z$/.test(data.updated)) {
throw new Error(msgPrefix + ' failed: updated date format not valid. Needs to be a full ISO-8601 UTC date and time string, formatted YYYYMMDDTHHMMSSZ');
}
return true;
}
async function atcb_validate_options(data, msgPrefix) {
const isValid = data.options.every((option) => {
if (!atcbOptions.includes(option)) {
throw new Error(`${msgPrefix} failed: invalid option [${option}]`);
}
return true;
});
return isValid;
}
async function atcb_validate_date_blocks(data, msgPrefix) {
try {
for (let i = 0; i < data.dates.length; i++) {
const msgSuffix = (function () {
if (data.dates.length === 1) {
return '';
} else {
return ' [dates array object #' + (i + 1) + '/' + data.