add-to-calendar-button 2.3.2 → 2.3.3

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.
@@ -7,22 +7,22 @@ const tzlibActions = require('timezones-ical-library');
7
7
  * Add to Calendar Button
8
8
  * ++++++++++++++++++++++
9
9
  *
10
- * Version: 2.3.2
10
+ * Version: 2.3.3
11
11
  * Creator: Jens Kuerschner (https://jenskuerschner.de)
12
12
  * Project: https://github.com/add2cal/add-to-calendar-button
13
13
  * License: Elastic License 2.0 (ELv2) (https://github.com/add2cal/add-to-calendar-button/blob/main/LICENSE.txt)
14
14
  * Note: DO NOT REMOVE THE COPYRIGHT NOTICE ABOVE!
15
15
  *
16
16
  */
17
- const atcbVersion = '2.3.2';
18
- const atcbCssTemplate = {
17
+ const atcbVersion = '2.3.3';
18
+ const atcbCssTemplate = {
19
19
  if (typeof window === 'undefined') {
20
20
  return false;
21
21
  } else {
22
22
  return true;
23
23
  }
24
24
  };
25
- const isiOS = isBrowser()
25
+ const atcbIsiOS = atcbIsBrowser()
26
26
  ? () => {
27
27
  if ((/iPad|iPhone|iPod/i.test(navigator.userAgent || navigator.vendor || window.opera) && !window.MSStream) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) {
28
28
  return true;
@@ -33,7 +33,7 @@ const isiOS = isBrowser()
33
33
  : () => {
34
34
  return false;
35
35
  };
36
- const isAndroid = isBrowser()
36
+ const atcbIsAndroid = atcbIsBrowser()
37
37
  ? () => {
38
38
  if (/android/i.test(navigator.userAgent || navigator.vendor || window.opera) && !window.MSStream) {
39
39
  return true;
@@ -44,7 +44,7 @@ const isAndroid = isBrowser()
44
44
  : () => {
45
45
  return false;
46
46
  };
47
- /*const isChrome = isBrowser()
47
+ /*const isChrome = atcbIsBrowser()
48
48
  ? () => {
49
49
  if (/chrome|chromium|crios|google inc/i.test(navigator.userAgent || navigator.vendor)) {
50
50
  return true;
@@ -55,7 +55,7 @@ const isAndroid = isBrowser()
55
55
  : () => {
56
56
  return false;
57
57
  };*/
58
- const isSafari = isBrowser()
58
+ const atcbIsSafari = atcbIsBrowser()
59
59
  ? () => {
60
60
  if (/^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent || navigator.vendor)) {
61
61
  return true;
@@ -66,14 +66,14 @@ const isSafari = isBrowser()
66
66
  : () => {
67
67
  return false;
68
68
  };
69
- const isMobile = () => {
70
- if (isAndroid() || isiOS()) {
69
+ const atcbIsMobile = () => {
70
+ if (atcbIsAndroid() || atcbIsiOS()) {
71
71
  return true;
72
72
  } else {
73
73
  return false;
74
74
  }
75
75
  };
76
- const isWebView = isBrowser()
76
+ const atcbIsWebView = atcbIsBrowser()
77
77
  ? () => {
78
78
  if (/(; ?wv|(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari))/i.test(navigator.userAgent || navigator.vendor)) {
79
79
  return true;
@@ -84,7 +84,7 @@ const isWebView = isBrowser()
84
84
  : () => {
85
85
  return false;
86
86
  };
87
- const isProblematicWebView = isBrowser()
87
+ const atcbIsProblematicWebView = atcbIsBrowser()
88
88
  ? () => {
89
89
  if (/(Instagram)/i.test(navigator.userAgent || navigator.vendor || window.opera)) {
90
90
  return true;
@@ -95,7 +95,7 @@ const isProblematicWebView = isBrowser()
95
95
  : () => {
96
96
  return false;
97
97
  };
98
- const atcbDefaultTarget = isWebView() ? '_system' : '_blank';
98
+ const atcbDefaultTarget = atcbIsWebView() ? '_system' : '_blank';
99
99
  const atcbOptions = ['apple', 'google', 'ical', 'ms365', 'outlookcom', 'msteams', 'yahoo'];
100
100
  const atcbValidRecurrOptions = ['apple', 'google', 'ical'];
101
101
  const atcbInvalidSubscribeOptions = ['msteams'];
@@ -103,6 +103,7 @@ const atcbiOSInvalidOptions = ['ical'];
103
103
  const atcbStates = [];
104
104
  const atcbWcParams = [
105
105
  'debug',
106
+ 'cspnonce',
106
107
  'name',
107
108
  'dates',
108
109
  'description',
@@ -324,8 +325,8 @@ function atcb_decorate_data_options(data) {
324
325
  iCalGiven = true;
325
326
  }
326
327
  if (
327
- (isiOS() && atcbiOSInvalidOptions.includes(optionName)) ||
328
- (data.recurrence != null && data.recurrence != '' && (!atcbValidRecurrOptions.includes(optionName) || (data.recurrence_until != null && data.recurrence_until != '' && (optionName === 'apple' || optionName === 'ical')) || (isiOS() && optionName === 'google'))) ||
328
+ (atcbIsiOS() && atcbiOSInvalidOptions.includes(optionName)) ||
329
+ (data.recurrence != null && data.recurrence != '' && (!atcbValidRecurrOptions.includes(optionName) || (data.recurrence_until != null && data.recurrence_until != '' && (optionName === 'apple' || optionName === 'ical')) || (atcbIsiOS() && optionName === 'google'))) ||
329
330
  (data.subscribe && atcbInvalidSubscribeOptions.includes(optionName))
330
331
  ) {
331
332
  continue;
@@ -334,13 +335,13 @@ function atcb_decorate_data_options(data) {
334
335
  data.optionLabels.push(optionLabel);
335
336
  }
336
337
  if (newOptions.length === 0) {
337
- if (!isiOS()) {
338
+ if (!atcbIsiOS()) {
338
339
  newOptions.push('ical');
339
340
  data.optionLabels.push('');
340
341
  }
341
342
  iCalGiven = true;
342
343
  }
343
- if (isiOS() && iCalGiven && !appleGiven) {
344
+ if (atcbIsiOS() && iCalGiven && !appleGiven) {
344
345
  newOptions.push('apple');
345
346
  data.optionLabels.push('');
346
347
  }
@@ -405,7 +406,7 @@ function atcb_decorate_sizes(size) {
405
406
  return sizes;
406
407
  }
407
408
  function atcb_decorate_light_mode(lightMode = '') {
408
- if (lightMode == 'system' && isBrowser()) {
409
+ if (lightMode == 'system' && atcbIsBrowser()) {
409
410
  const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
410
411
  return prefersDarkScheme.matches ? 'dark' : 'light';
411
412
  }
@@ -1964,6 +1965,9 @@ function atcb_generate_modal_host(host, data, reset = true) {
1964
1965
 
1965
1966
  function atcb_generate_rich_data(data, parent) {
1966
1967
  const schemaEl = document.createElement('script');
1968
+ if (parent.hasAttribute('cspnonce')) {
1969
+ schemaEl.setAttribute('nonce', parent.getAttribute('cspnonce'));
1970
+ }
1967
1971
  schemaEl.type = 'application/ld+json';
1968
1972
  const schemaContentMulti = [];
1969
1973
  if (data.dates.length > 1) {
@@ -2170,7 +2174,7 @@ function atcb_generate_subscribe_links(host, linkType, data, keyboardTrigger) {
2170
2174
  const adjustedFileUrl = data.icsFile.replace('https://', 'webcal://');
2171
2175
  switch (linkType) {
2172
2176
  case 'ical': // also for apple (see above)
2173
- if (isMobile()) {
2177
+ if (atcbIsMobile()) {
2174
2178
  atcb_subscribe_ical(data.icsFile);
2175
2179
  break;
2176
2180
  }
@@ -2283,7 +2287,7 @@ function atcb_generate_google(data) {
2283
2287
  }
2284
2288
  if (data.location != null && data.location != '') {
2285
2289
  urlParts.push('location=' + encodeURIComponent(data.location));
2286
- if (isiOS()) {
2290
+ if (atcbIsiOS()) {
2287
2291
  if (tmpDataDescription.length > 0) {
2288
2292
  tmpDataDescription.push('<br><br>');
2289
2293
  }
@@ -2329,7 +2333,7 @@ function atcb_generate_yahoo(data) {
2329
2333
  function atcb_generate_microsoft(data, type = '365') {
2330
2334
  const urlParts = [];
2331
2335
  const basePath = (function () {
2332
- if (isMobile()) {
2336
+ if (atcbIsMobile()) {
2333
2337
  return '/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent';
2334
2338
  }
2335
2339
  return '/calendar/action/compose?rru=addevent';
@@ -2363,7 +2367,7 @@ function atcb_generate_msteams(data) {
2363
2367
  const urlParts = [];
2364
2368
  const baseUrl = 'https://teams.microsoft.com/l/meeting/new?';
2365
2369
  const formattedDate = atcb_generate_time(data, 'delimiters', 'msteams', true);
2366
- if (!formattedDate.allday || isMobile()) {
2370
+ if (!formattedDate.allday || atcbIsMobile()) {
2367
2371
  urlParts.push('startTime=' + encodeURIComponent(formattedDate.start));
2368
2372
  urlParts.push('endTime=' + encodeURIComponent(formattedDate.end));
2369
2373
  } else {
@@ -2410,7 +2414,7 @@ function atcb_generate_ical(host, data, subEvent = 'all', keyboardTrigger = fals
2410
2414
  }
2411
2415
  return '';
2412
2416
  })();
2413
- if (givenIcsFile != '' && (!isiOS() || (isiOS() && isWebView() && data.bypassWebViewCheck == true))) {
2417
+ if (givenIcsFile != '' && (!atcbIsiOS() || (atcbIsiOS() && atcbIsWebView() && data.bypassWebViewCheck == true))) {
2414
2418
  atcb_save_file(givenIcsFile, filename);
2415
2419
  return;
2416
2420
  }
@@ -2507,7 +2511,7 @@ function atcb_generate_ical(host, data, subEvent = 'all', keyboardTrigger = fals
2507
2511
  }
2508
2512
  return 'data:text/calendar;charset=utf-8,' + encodeURIComponent(ics_lines.join('\r\n'));
2509
2513
  })();
2510
- if ((isiOS() && !isSafari()) || (isWebView() && (isiOS() || (isAndroid() && isProblematicWebView())))) {
2514
+ if ((atcbIsiOS() && !atcbIsSafari()) || (atcbIsWebView() && (atcbIsiOS() || (atcbIsAndroid() && atcbIsProblematicWebView())))) {
2511
2515
  atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger);
2512
2516
  return;
2513
2517
  }
@@ -2533,7 +2537,7 @@ function atcb_determine_ical_filename(data, subEvent) {
2533
2537
  }
2534
2538
  function atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger) {
2535
2539
  atcb_copy_to_clipboard(dataUrl);
2536
- if (isiOS() && !isSafari()) {
2540
+ if (atcbIsiOS() && !atcbIsSafari()) {
2537
2541
  atcb_create_modal(
2538
2542
  host,
2539
2543
  data,
@@ -2561,7 +2565,7 @@ function atcb_save_file(file, filename) {
2561
2565
  const save = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
2562
2566
  save.rel = 'noopener';
2563
2567
  save.href = file;
2564
- if (isMobile()) {
2568
+ if (atcbIsMobile()) {
2565
2569
  save.target = '_self';
2566
2570
  } else {
2567
2571
  save.target = '_blank';
@@ -2627,11 +2631,11 @@ function atcb_generate_time(data, style = 'delimiters', targetCal = 'general', a
2627
2631
  const endDate = data.endDate.split('-');
2628
2632
  const newStartDate = new Date(Date.UTC(startDate[0], startDate[1] - 1, startDate[2], 12, 0, 0));
2629
2633
  const newEndDate = new Date(Date.UTC(endDate[0], endDate[1] - 1, endDate[2], 12, 0, 0));
2630
- if (targetCal === 'google' || (targetCal === 'microsoft' && !isMobile()) || targetCal === 'msteams' || targetCal === 'ical') {
2634
+ if (targetCal === 'google' || (targetCal === 'microsoft' && !atcbIsMobile()) || targetCal === 'msteams' || targetCal === 'ical') {
2631
2635
  newEndDate.setDate(newEndDate.getDate() + 1);
2632
2636
  }
2633
2637
  if (targetCal === 'msteams') {
2634
- if (isMobile()) {
2638
+ if (atcbIsMobile()) {
2635
2639
  const offset = newStartDate.getTimezoneOffset();
2636
2640
  const formattedOffset = (function () {
2637
2641
  if (offset < 0) {
@@ -2695,7 +2699,7 @@ function atcb_secure_url(url, throwError = true) {
2695
2699
  }
2696
2700
  }
2697
2701
  function atcb_validEmail(email) {
2698
- if (!/^.{0,70}@.{1,30}\.[\w.]{2,9}$/.test(email)) {
2702
+ if (!/^.{0,70}@.{1,30}\.[a-zA-Z]{2,9}$/.test(email)) {
2699
2703
  return false;
2700
2704
  }
2701
2705
  return true;
@@ -2840,7 +2844,7 @@ function atcb_copy_to_clipboard(dataString) {
2840
2844
  tmpInput.contentEditable = true;
2841
2845
  tmpInput.readOnly = false;
2842
2846
  tmpInput.value = dataString;
2843
- if (isiOS()) {
2847
+ if (atcbIsiOS()) {
2844
2848
  var range = document.createRange();
2845
2849
  range.selectNodeContents(tmpInput);
2846
2850
  var selection = window.getSelection();
@@ -2889,7 +2893,7 @@ function atcb_log_event(event, trigger, identifier) {
2889
2893
  if (parentEl) {
2890
2894
  parentEl.setAttribute('atcb-last-event', event + ':' + trigger);
2891
2895
  }
2892
- if (isBrowser()) {
2896
+ if (atcbIsBrowser()) {
2893
2897
  atcb_push_to_data_layer(event, trigger);
2894
2898
  }
2895
2899
  }
@@ -3466,7 +3470,7 @@ let atcbInitialGlobalInit = false;
3466
3470
  let atcbBtnCount = 0;
3467
3471
  const lightModeMutationObserver = [];
3468
3472
  const template = `<div class="atcb-initialized" style="display:none;position:relative;width:fit-content;"></div>`;
3469
- if (isBrowser()) {
3473
+ if (atcbIsBrowser()) {
3470
3474
  class AddToCalendarButton extends HTMLElement {
3471
3475
  constructor() {
3472
3476
  super();
@@ -3712,6 +3716,9 @@ function atcb_load_css(host, rootObj = null, style = '', inline = false, buttons
3712
3716
  cssGlobalContent.id = 'atcb-global-style';
3713
3717
  const scrollBarWidth = window.innerWidth - document.documentElement.clientWidth;
3714
3718
  cssGlobalContent.innerText = '.atcb-modal-no-scroll { overflow-y: hidden !important; -webkit-overflow-scrolling: touch; } body.atcb-modal-no-scroll { padding-right: ' + scrollBarWidth + 'px; }';
3719
+ if (host.host.hasAttribute('cspnonce')) {
3720
+ cssGlobalContent.setAttribute('nonce', host.host.getAttribute('cspnonce'));
3721
+ }
3715
3722
  document.head.append(cssGlobalContent);
3716
3723
  }
3717
3724
  if (customCss != '' && style == 'custom') {
@@ -3719,6 +3726,9 @@ function atcb_load_css(host, rootObj = null, style = '', inline = false, buttons
3719
3726
  cssFile.setAttribute('rel', 'stylesheet');
3720
3727
  cssFile.setAttribute('type', 'text/css');
3721
3728
  cssFile.setAttribute('href', customCss);
3729
+ if (host.host.hasAttribute('cspnonce')) {
3730
+ cssFile.setAttribute('nonce', host.host.getAttribute('cspnonce'));
3731
+ }
3722
3732
  if (rootObj == null) {
3723
3733
  host.host.style.display = 'none';
3724
3734
  loadExternalCssAsynch(cssFile, host, host.host);
@@ -3732,6 +3742,9 @@ function atcb_load_css(host, rootObj = null, style = '', inline = false, buttons
3732
3742
  }
3733
3743
  if (style != 'none' && atcbCssTemplate[`${style}`] != null) {
3734
3744
  const cssContent = document.createElement('style');
3745
+ if (host.host.hasAttribute('cspnonce')) {
3746
+ cssContent.setAttribute('nonce', host.host.getAttribute('cspnonce'));
3747
+ }
3735
3748
  const overrideDefaultCss = (function () {
3736
3749
  if (host.host.hasAttribute('styleLight')) {
3737
3750
  const output = ':host { ' + atcb_secure_content(host.host.getAttribute('styleLight').replace(/(\\r\\n|\\n|\\r)/g, ''), false) + ' }';
@@ -3793,7 +3806,7 @@ function atcb_render_debug_msg(host, error) {
3793
3806
  }
3794
3807
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3795
3808
  function atcb_action(data, triggerElement, keyboardTrigger = false) {
3796
- if (!isBrowser()) {
3809
+ if (!atcbIsBrowser()) {
3797
3810
  return;
3798
3811
  }
3799
3812
  data = atcb_secure_content(data);
@@ -3849,7 +3862,7 @@ function atcb_action(data, triggerElement, keyboardTrigger = false) {
3849
3862
  atcb_log_event('initialization', data.identifier, data.identifier);
3850
3863
  if (!data.blockInteraction) {
3851
3864
  let host = null;
3852
- if (!oneOption || (data.options[0] !== 'apple' && data.options[0] !== 'ical') || (data.dates && data.dates.length > 1 && data.dates.organizer) || (isMobile())) {
3865
+ if (!oneOption || (data.options[0] !== 'apple' && data.options[0] !== 'ical') || (data.dates && data.dates.length > 1 && data.dates.organizer) || (atcbIsMobile())) {
3853
3866
  host = document.createElement('div');
3854
3867
  host.id = 'atcb-customTrigger-' + data.identifier + '-host';
3855
3868
  if (root == document.body) {
@@ -3928,7 +3941,7 @@ function atcb_get_pro_data(licenseKey) {
3928
3941
  return data;
3929
3942
  }
3930
3943
  function atcb_set_global_event_listener(host, data) {
3931
- if (!isBrowser()) {
3944
+ if (!atcbIsBrowser()) {
3932
3945
  return;
3933
3946
  }
3934
3947
  if (data.lightMode == 'bodyScheme') {
@@ -6,22 +6,22 @@ import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'tim
6
6
  * Add to Calendar Button
7
7
  * ++++++++++++++++++++++
8
8
  *
9
- * Version: 2.3.2
9
+ * Version: 2.3.3
10
10
  * Creator: Jens Kuerschner (https://jenskuerschner.de)
11
11
  * Project: https://github.com/add2cal/add-to-calendar-button
12
12
  * License: Elastic License 2.0 (ELv2) (https://github.com/add2cal/add-to-calendar-button/blob/main/LICENSE.txt)
13
13
  * Note: DO NOT REMOVE THE COPYRIGHT NOTICE ABOVE!
14
14
  *
15
15
  */
16
- const atcbVersion = '2.3.2';
17
- const atcbCssTemplate = {
16
+ const atcbVersion = '2.3.3';
17
+ const atcbCssTemplate = {
18
18
  if (typeof window === 'undefined') {
19
19
  return false;
20
20
  } else {
21
21
  return true;
22
22
  }
23
23
  };
24
- const isiOS = isBrowser()
24
+ const atcbIsiOS = atcbIsBrowser()
25
25
  ? () => {
26
26
  if ((/iPad|iPhone|iPod/i.test(navigator.userAgent || navigator.vendor || window.opera) && !window.MSStream) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1)) {
27
27
  return true;
@@ -32,7 +32,7 @@ const isiOS = isBrowser()
32
32
  : () => {
33
33
  return false;
34
34
  };
35
- const isAndroid = isBrowser()
35
+ const atcbIsAndroid = atcbIsBrowser()
36
36
  ? () => {
37
37
  if (/android/i.test(navigator.userAgent || navigator.vendor || window.opera) && !window.MSStream) {
38
38
  return true;
@@ -43,7 +43,7 @@ const isAndroid = isBrowser()
43
43
  : () => {
44
44
  return false;
45
45
  };
46
- /*const isChrome = isBrowser()
46
+ /*const isChrome = atcbIsBrowser()
47
47
  ? () => {
48
48
  if (/chrome|chromium|crios|google inc/i.test(navigator.userAgent || navigator.vendor)) {
49
49
  return true;
@@ -54,7 +54,7 @@ const isAndroid = isBrowser()
54
54
  : () => {
55
55
  return false;
56
56
  };*/
57
- const isSafari = isBrowser()
57
+ const atcbIsSafari = atcbIsBrowser()
58
58
  ? () => {
59
59
  if (/^((?!chrome|android|crios|fxios).)*safari/i.test(navigator.userAgent || navigator.vendor)) {
60
60
  return true;
@@ -65,14 +65,14 @@ const isSafari = isBrowser()
65
65
  : () => {
66
66
  return false;
67
67
  };
68
- const isMobile = () => {
69
- if (isAndroid() || isiOS()) {
68
+ const atcbIsMobile = () => {
69
+ if (atcbIsAndroid() || atcbIsiOS()) {
70
70
  return true;
71
71
  } else {
72
72
  return false;
73
73
  }
74
74
  };
75
- const isWebView = isBrowser()
75
+ const atcbIsWebView = atcbIsBrowser()
76
76
  ? () => {
77
77
  if (/(; ?wv|(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari))/i.test(navigator.userAgent || navigator.vendor)) {
78
78
  return true;
@@ -83,7 +83,7 @@ const isWebView = isBrowser()
83
83
  : () => {
84
84
  return false;
85
85
  };
86
- const isProblematicWebView = isBrowser()
86
+ const atcbIsProblematicWebView = atcbIsBrowser()
87
87
  ? () => {
88
88
  if (/(Instagram)/i.test(navigator.userAgent || navigator.vendor || window.opera)) {
89
89
  return true;
@@ -94,7 +94,7 @@ const isProblematicWebView = isBrowser()
94
94
  : () => {
95
95
  return false;
96
96
  };
97
- const atcbDefaultTarget = isWebView() ? '_system' : '_blank';
97
+ const atcbDefaultTarget = atcbIsWebView() ? '_system' : '_blank';
98
98
  const atcbOptions = ['apple', 'google', 'ical', 'ms365', 'outlookcom', 'msteams', 'yahoo'];
99
99
  const atcbValidRecurrOptions = ['apple', 'google', 'ical'];
100
100
  const atcbInvalidSubscribeOptions = ['msteams'];
@@ -102,6 +102,7 @@ const atcbiOSInvalidOptions = ['ical'];
102
102
  const atcbStates = [];
103
103
  const atcbWcParams = [
104
104
  'debug',
105
+ 'cspnonce',
105
106
  'name',
106
107
  'dates',
107
108
  'description',
@@ -323,8 +324,8 @@ function atcb_decorate_data_options(data) {
323
324
  iCalGiven = true;
324
325
  }
325
326
  if (
326
- (isiOS() && atcbiOSInvalidOptions.includes(optionName)) ||
327
- (data.recurrence != null && data.recurrence != '' && (!atcbValidRecurrOptions.includes(optionName) || (data.recurrence_until != null && data.recurrence_until != '' && (optionName === 'apple' || optionName === 'ical')) || (isiOS() && optionName === 'google'))) ||
327
+ (atcbIsiOS() && atcbiOSInvalidOptions.includes(optionName)) ||
328
+ (data.recurrence != null && data.recurrence != '' && (!atcbValidRecurrOptions.includes(optionName) || (data.recurrence_until != null && data.recurrence_until != '' && (optionName === 'apple' || optionName === 'ical')) || (atcbIsiOS() && optionName === 'google'))) ||
328
329
  (data.subscribe && atcbInvalidSubscribeOptions.includes(optionName))
329
330
  ) {
330
331
  continue;
@@ -333,13 +334,13 @@ function atcb_decorate_data_options(data) {
333
334
  data.optionLabels.push(optionLabel);
334
335
  }
335
336
  if (newOptions.length === 0) {
336
- if (!isiOS()) {
337
+ if (!atcbIsiOS()) {
337
338
  newOptions.push('ical');
338
339
  data.optionLabels.push('');
339
340
  }
340
341
  iCalGiven = true;
341
342
  }
342
- if (isiOS() && iCalGiven && !appleGiven) {
343
+ if (atcbIsiOS() && iCalGiven && !appleGiven) {
343
344
  newOptions.push('apple');
344
345
  data.optionLabels.push('');
345
346
  }
@@ -404,7 +405,7 @@ function atcb_decorate_sizes(size) {
404
405
  return sizes;
405
406
  }
406
407
  function atcb_decorate_light_mode(lightMode = '') {
407
- if (lightMode == 'system' && isBrowser()) {
408
+ if (lightMode == 'system' && atcbIsBrowser()) {
408
409
  const prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
409
410
  return prefersDarkScheme.matches ? 'dark' : 'light';
410
411
  }
@@ -1963,6 +1964,9 @@ function atcb_generate_modal_host(host, data, reset = true) {
1963
1964
 
1964
1965
  function atcb_generate_rich_data(data, parent) {
1965
1966
  const schemaEl = document.createElement('script');
1967
+ if (parent.hasAttribute('cspnonce')) {
1968
+ schemaEl.setAttribute('nonce', parent.getAttribute('cspnonce'));
1969
+ }
1966
1970
  schemaEl.type = 'application/ld+json';
1967
1971
  const schemaContentMulti = [];
1968
1972
  if (data.dates.length > 1) {
@@ -2169,7 +2173,7 @@ function atcb_generate_subscribe_links(host, linkType, data, keyboardTrigger) {
2169
2173
  const adjustedFileUrl = data.icsFile.replace('https://', 'webcal://');
2170
2174
  switch (linkType) {
2171
2175
  case 'ical': // also for apple (see above)
2172
- if (isMobile()) {
2176
+ if (atcbIsMobile()) {
2173
2177
  atcb_subscribe_ical(data.icsFile);
2174
2178
  break;
2175
2179
  }
@@ -2282,7 +2286,7 @@ function atcb_generate_google(data) {
2282
2286
  }
2283
2287
  if (data.location != null && data.location != '') {
2284
2288
  urlParts.push('location=' + encodeURIComponent(data.location));
2285
- if (isiOS()) {
2289
+ if (atcbIsiOS()) {
2286
2290
  if (tmpDataDescription.length > 0) {
2287
2291
  tmpDataDescription.push('<br><br>');
2288
2292
  }
@@ -2328,7 +2332,7 @@ function atcb_generate_yahoo(data) {
2328
2332
  function atcb_generate_microsoft(data, type = '365') {
2329
2333
  const urlParts = [];
2330
2334
  const basePath = (function () {
2331
- if (isMobile()) {
2335
+ if (atcbIsMobile()) {
2332
2336
  return '/calendar/0/deeplink/compose?path=%2Fcalendar%2Faction%2Fcompose&rru=addevent';
2333
2337
  }
2334
2338
  return '/calendar/action/compose?rru=addevent';
@@ -2362,7 +2366,7 @@ function atcb_generate_msteams(data) {
2362
2366
  const urlParts = [];
2363
2367
  const baseUrl = 'https://teams.microsoft.com/l/meeting/new?';
2364
2368
  const formattedDate = atcb_generate_time(data, 'delimiters', 'msteams', true);
2365
- if (!formattedDate.allday || isMobile()) {
2369
+ if (!formattedDate.allday || atcbIsMobile()) {
2366
2370
  urlParts.push('startTime=' + encodeURIComponent(formattedDate.start));
2367
2371
  urlParts.push('endTime=' + encodeURIComponent(formattedDate.end));
2368
2372
  } else {
@@ -2409,7 +2413,7 @@ function atcb_generate_ical(host, data, subEvent = 'all', keyboardTrigger = fals
2409
2413
  }
2410
2414
  return '';
2411
2415
  })();
2412
- if (givenIcsFile != '' && (!isiOS() || (isiOS() && isWebView() && data.bypassWebViewCheck == true))) {
2416
+ if (givenIcsFile != '' && (!atcbIsiOS() || (atcbIsiOS() && atcbIsWebView() && data.bypassWebViewCheck == true))) {
2413
2417
  atcb_save_file(givenIcsFile, filename);
2414
2418
  return;
2415
2419
  }
@@ -2506,7 +2510,7 @@ function atcb_generate_ical(host, data, subEvent = 'all', keyboardTrigger = fals
2506
2510
  }
2507
2511
  return 'data:text/calendar;charset=utf-8,' + encodeURIComponent(ics_lines.join('\r\n'));
2508
2512
  })();
2509
- if ((isiOS() && !isSafari()) || (isWebView() && (isiOS() || (isAndroid() && isProblematicWebView())))) {
2513
+ if ((atcbIsiOS() && !atcbIsSafari()) || (atcbIsWebView() && (atcbIsiOS() || (atcbIsAndroid() && atcbIsProblematicWebView())))) {
2510
2514
  atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger);
2511
2515
  return;
2512
2516
  }
@@ -2532,7 +2536,7 @@ function atcb_determine_ical_filename(data, subEvent) {
2532
2536
  }
2533
2537
  function atcb_ical_copy_note(host, dataUrl, data, keyboardTrigger) {
2534
2538
  atcb_copy_to_clipboard(dataUrl);
2535
- if (isiOS() && !isSafari()) {
2539
+ if (atcbIsiOS() && !atcbIsSafari()) {
2536
2540
  atcb_create_modal(
2537
2541
  host,
2538
2542
  data,
@@ -2560,7 +2564,7 @@ function atcb_save_file(file, filename) {
2560
2564
  const save = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
2561
2565
  save.rel = 'noopener';
2562
2566
  save.href = file;
2563
- if (isMobile()) {
2567
+ if (atcbIsMobile()) {
2564
2568
  save.target = '_self';
2565
2569
  } else {
2566
2570
  save.target = '_blank';
@@ -2626,11 +2630,11 @@ function atcb_generate_time(data, style = 'delimiters', targetCal = 'general', a
2626
2630
  const endDate = data.endDate.split('-');
2627
2631
  const newStartDate = new Date(Date.UTC(startDate[0], startDate[1] - 1, startDate[2], 12, 0, 0));
2628
2632
  const newEndDate = new Date(Date.UTC(endDate[0], endDate[1] - 1, endDate[2], 12, 0, 0));
2629
- if (targetCal === 'google' || (targetCal === 'microsoft' && !isMobile()) || targetCal === 'msteams' || targetCal === 'ical') {
2633
+ if (targetCal === 'google' || (targetCal === 'microsoft' && !atcbIsMobile()) || targetCal === 'msteams' || targetCal === 'ical') {
2630
2634
  newEndDate.setDate(newEndDate.getDate() + 1);
2631
2635
  }
2632
2636
  if (targetCal === 'msteams') {
2633
- if (isMobile()) {
2637
+ if (atcbIsMobile()) {
2634
2638
  const offset = newStartDate.getTimezoneOffset();
2635
2639
  const formattedOffset = (function () {
2636
2640
  if (offset < 0) {
@@ -2694,7 +2698,7 @@ function atcb_secure_url(url, throwError = true) {
2694
2698
  }
2695
2699
  }
2696
2700
  function atcb_validEmail(email) {
2697
- if (!/^.{0,70}@.{1,30}\.[\w.]{2,9}$/.test(email)) {
2701
+ if (!/^.{0,70}@.{1,30}\.[a-zA-Z]{2,9}$/.test(email)) {
2698
2702
  return false;
2699
2703
  }
2700
2704
  return true;
@@ -2839,7 +2843,7 @@ function atcb_copy_to_clipboard(dataString) {
2839
2843
  tmpInput.contentEditable = true;
2840
2844
  tmpInput.readOnly = false;
2841
2845
  tmpInput.value = dataString;
2842
- if (isiOS()) {
2846
+ if (atcbIsiOS()) {
2843
2847
  var range = document.createRange();
2844
2848
  range.selectNodeContents(tmpInput);
2845
2849
  var selection = window.getSelection();
@@ -2888,7 +2892,7 @@ function atcb_log_event(event, trigger, identifier) {
2888
2892
  if (parentEl) {
2889
2893
  parentEl.setAttribute('atcb-last-event', event + ':' + trigger);
2890
2894
  }
2891
- if (isBrowser()) {
2895
+ if (atcbIsBrowser()) {
2892
2896
  atcb_push_to_data_layer(event, trigger);
2893
2897
  }
2894
2898
  }
@@ -3465,7 +3469,7 @@ let atcbInitialGlobalInit = false;
3465
3469
  let atcbBtnCount = 0;
3466
3470
  const lightModeMutationObserver = [];
3467
3471
  const template = `<div class="atcb-initialized" style="display:none;position:relative;width:fit-content;"></div>`;
3468
- if (isBrowser()) {
3472
+ if (atcbIsBrowser()) {
3469
3473
  class AddToCalendarButton extends HTMLElement {
3470
3474
  constructor() {
3471
3475
  super();
@@ -3711,6 +3715,9 @@ function atcb_load_css(host, rootObj = null, style = '', inline = false, buttons
3711
3715
  cssGlobalContent.id = 'atcb-global-style';
3712
3716
  const scrollBarWidth = window.innerWidth - document.documentElement.clientWidth;
3713
3717
  cssGlobalContent.innerText = '.atcb-modal-no-scroll { overflow-y: hidden !important; -webkit-overflow-scrolling: touch; } body.atcb-modal-no-scroll { padding-right: ' + scrollBarWidth + 'px; }';
3718
+ if (host.host.hasAttribute('cspnonce')) {
3719
+ cssGlobalContent.setAttribute('nonce', host.host.getAttribute('cspnonce'));
3720
+ }
3714
3721
  document.head.append(cssGlobalContent);
3715
3722
  }
3716
3723
  if (customCss != '' && style == 'custom') {
@@ -3718,6 +3725,9 @@ function atcb_load_css(host, rootObj = null, style = '', inline = false, buttons
3718
3725
  cssFile.setAttribute('rel', 'stylesheet');
3719
3726
  cssFile.setAttribute('type', 'text/css');
3720
3727
  cssFile.setAttribute('href', customCss);
3728
+ if (host.host.hasAttribute('cspnonce')) {
3729
+ cssFile.setAttribute('nonce', host.host.getAttribute('cspnonce'));
3730
+ }
3721
3731
  if (rootObj == null) {
3722
3732
  host.host.style.display = 'none';
3723
3733
  loadExternalCssAsynch(cssFile, host, host.host);
@@ -3731,6 +3741,9 @@ function atcb_load_css(host, rootObj = null, style = '', inline = false, buttons
3731
3741
  }
3732
3742
  if (style != 'none' && atcbCssTemplate[`${style}`] != null) {
3733
3743
  const cssContent = document.createElement('style');
3744
+ if (host.host.hasAttribute('cspnonce')) {
3745
+ cssContent.setAttribute('nonce', host.host.getAttribute('cspnonce'));
3746
+ }
3734
3747
  const overrideDefaultCss = (function () {
3735
3748
  if (host.host.hasAttribute('styleLight')) {
3736
3749
  const output = ':host { ' + atcb_secure_content(host.host.getAttribute('styleLight').replace(/(\\r\\n|\\n|\\r)/g, ''), false) + ' }';
@@ -3792,7 +3805,7 @@ function atcb_render_debug_msg(host, error) {
3792
3805
  }
3793
3806
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
3794
3807
  function atcb_action(data, triggerElement, keyboardTrigger = false) {
3795
- if (!isBrowser()) {
3808
+ if (!atcbIsBrowser()) {
3796
3809
  return;
3797
3810
  }
3798
3811
  data = atcb_secure_content(data);
@@ -3848,7 +3861,7 @@ function atcb_action(data, triggerElement, keyboardTrigger = false) {
3848
3861
  atcb_log_event('initialization', data.identifier, data.identifier);
3849
3862
  if (!data.blockInteraction) {
3850
3863
  let host = null;
3851
- if (!oneOption || (data.options[0] !== 'apple' && data.options[0] !== 'ical') || (data.dates && data.dates.length > 1 && data.dates.organizer) || (isMobile())) {
3864
+ if (!oneOption || (data.options[0] !== 'apple' && data.options[0] !== 'ical') || (data.dates && data.dates.length > 1 && data.dates.organizer) || (atcbIsMobile())) {
3852
3865
  host = document.createElement('div');
3853
3866
  host.id = 'atcb-customTrigger-' + data.identifier + '-host';
3854
3867
  if (root == document.body) {
@@ -3927,7 +3940,7 @@ function atcb_get_pro_data(licenseKey) {
3927
3940
  return data;
3928
3941
  }
3929
3942
  function atcb_set_global_event_listener(host, data) {
3930
- if (!isBrowser()) {
3943
+ if (!atcbIsBrowser()) {
3931
3944
  return;
3932
3945
  }
3933
3946
  if (data.lightMode == 'bodyScheme') {
package/index.d.ts CHANGED
@@ -73,6 +73,7 @@ declare module 'add-to-calendar-button' {
73
73
  rsvp?: object | string;
74
74
  bypassWebViewCheck?: boolean | string;
75
75
  debug?: boolean | string;
76
+ nonce?: string;
76
77
  blockInteraction?: boolean | string;
77
78
  styleLight?: string;
78
79
  styleDark?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "add-to-calendar-button",
3
- "version": "2.3.2",
3
+ "version": "2.3.3",
4
4
  "engines": {
5
5
  "node": ">=16.18.1",
6
6
  "npm": ">=8.19.2"