@adobe/alloy 2.32.0 → 2.32.1-beta.1

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.
Files changed (89) hide show
  1. package/components.json +4 -0
  2. package/dist/alloy.js +12590 -11194
  3. package/dist/alloy.min.js +1 -1
  4. package/dist/alloyServiceWorker.js +7 -19
  5. package/dist/alloyServiceWorker.min.js +1 -1
  6. package/dist/types/browser/src/allOptionalComponents.d.ts +2 -0
  7. package/dist/types/browser/src/components/componentCreators.d.ts +1 -0
  8. package/dist/types/browser/src/index.d.ts +4 -2
  9. package/dist/types/browser/src/initializeStandalone.d.ts +4 -0
  10. package/dist/types/core/src/components/Audiences/index.d.ts +1 -1
  11. package/dist/types/core/src/components/Audiences/injectProcessResponse.d.ts +1 -1
  12. package/dist/types/core/src/components/Identity/injectHandleResponseForIdSyncs.d.ts +1 -1
  13. package/dist/types/core/src/components/MediaAnalyticsBridge/createGetInstance.d.ts +1 -1
  14. package/dist/types/core/src/components/MediaAnalyticsBridge/createMediaHelper.d.ts +7 -56
  15. package/dist/types/core/src/core/componentCreators.d.ts +0 -1
  16. package/dist/utils/createEventMergeId.js +38 -30
  17. package/dist/utils/deepAssign.js +10 -4
  18. package/package.json +9 -13
  19. package/rollup.config.js +9 -15
  20. package/scripts/alloyBuilder.js +34 -42
  21. package/scripts/helpers/componentMetadata.js +25 -0
  22. package/scripts/helpers/generateEntryPoint.js +29 -0
  23. package/src/allOptionalComponents.js +14 -0
  24. package/src/components/ActivityCollector/attachClickActivityCollector.js +55 -0
  25. package/src/components/ActivityCollector/configValidators.js +52 -0
  26. package/src/components/ActivityCollector/createClickActivityStorage.js +33 -0
  27. package/src/components/ActivityCollector/createClickedElementProperties.js +224 -0
  28. package/src/components/ActivityCollector/createGetClickedElementProperties.js +68 -0
  29. package/src/components/ActivityCollector/createInjectClickedElementProperties.js +80 -0
  30. package/src/components/ActivityCollector/createRecallAndInjectClickedElementProperties.js +45 -0
  31. package/src/components/ActivityCollector/createStorePageViewProperties.js +20 -0
  32. package/src/components/ActivityCollector/getLinkName.js +145 -0
  33. package/src/components/ActivityCollector/getLinkRegion.js +65 -0
  34. package/src/components/ActivityCollector/index.js +132 -0
  35. package/src/components/ActivityCollector/utils/activityMapExtensionEnabled.js +16 -0
  36. package/src/components/ActivityCollector/utils/createTransientStorage.js +26 -0
  37. package/src/components/ActivityCollector/utils/determineLinkType.js +27 -0
  38. package/src/components/ActivityCollector/utils/dom/elementHasClickHandler.js +15 -0
  39. package/src/components/ActivityCollector/utils/dom/extractDomain.js +20 -0
  40. package/src/components/ActivityCollector/utils/dom/findClickableElement.js +36 -0
  41. package/src/components/ActivityCollector/utils/dom/getAbsoluteUrlFromAnchorElement.js +25 -0
  42. package/src/components/ActivityCollector/utils/dom/isButtonSubmitElement.js +15 -0
  43. package/src/components/ActivityCollector/utils/dom/isDownloadLink.js +27 -0
  44. package/src/components/ActivityCollector/utils/dom/isExitLink.js +24 -0
  45. package/src/components/ActivityCollector/utils/dom/isInputSubmitElement.js +26 -0
  46. package/src/components/ActivityCollector/utils/dom/isSupportedAnchorElement.js +24 -0
  47. package/src/components/ActivityCollector/utils/dom/isSupportedTextNode.js +27 -0
  48. package/src/components/ActivityCollector/utils/hasPageName.js +23 -0
  49. package/src/components/ActivityCollector/utils/isDifferentDomains.js +19 -0
  50. package/src/components/ActivityCollector/utils/trimQueryFromUrl.js +31 -0
  51. package/src/components/ActivityCollector/utils/truncateWhiteSpace.js +22 -0
  52. package/src/components/ActivityCollector/validateClickCollectionConfig.js +47 -0
  53. package/src/components/componentCreators.js +13 -0
  54. package/src/index.js +10 -2
  55. package/src/initializeStandalone.js +34 -0
  56. package/src/standalone.js +3 -26
  57. package/.browserslistrc +0 -2
  58. package/babel.config.js +0 -76
  59. package/dist/types/core/src/constants/sessionDataKeys.d.ts +0 -1
  60. package/scripts/helpers/entryPointGeneratorBabelPlugin.js +0 -101
  61. /package/dist/types/{core → browser}/src/components/ActivityCollector/attachClickActivityCollector.d.ts +0 -0
  62. /package/dist/types/{core → browser}/src/components/ActivityCollector/configValidators.d.ts +0 -0
  63. /package/dist/types/{core → browser}/src/components/ActivityCollector/createClickActivityStorage.d.ts +0 -0
  64. /package/dist/types/{core → browser}/src/components/ActivityCollector/createClickedElementProperties.d.ts +0 -0
  65. /package/dist/types/{core → browser}/src/components/ActivityCollector/createGetClickedElementProperties.d.ts +0 -0
  66. /package/dist/types/{core → browser}/src/components/ActivityCollector/createInjectClickedElementProperties.d.ts +0 -0
  67. /package/dist/types/{core → browser}/src/components/ActivityCollector/createRecallAndInjectClickedElementProperties.d.ts +0 -0
  68. /package/dist/types/{core → browser}/src/components/ActivityCollector/createStorePageViewProperties.d.ts +0 -0
  69. /package/dist/types/{core → browser}/src/components/ActivityCollector/getLinkName.d.ts +0 -0
  70. /package/dist/types/{core → browser}/src/components/ActivityCollector/getLinkRegion.d.ts +0 -0
  71. /package/dist/types/{core → browser}/src/components/ActivityCollector/index.d.ts +0 -0
  72. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/activityMapExtensionEnabled.d.ts +0 -0
  73. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/createTransientStorage.d.ts +0 -0
  74. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/determineLinkType.d.ts +0 -0
  75. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/elementHasClickHandler.d.ts +0 -0
  76. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/extractDomain.d.ts +0 -0
  77. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/findClickableElement.d.ts +0 -0
  78. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/getAbsoluteUrlFromAnchorElement.d.ts +0 -0
  79. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/isButtonSubmitElement.d.ts +0 -0
  80. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/isDownloadLink.d.ts +0 -0
  81. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/isExitLink.d.ts +0 -0
  82. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/isInputSubmitElement.d.ts +0 -0
  83. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/isSupportedAnchorElement.d.ts +0 -0
  84. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/dom/isSupportedTextNode.d.ts +0 -0
  85. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/hasPageName.d.ts +0 -0
  86. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/isDifferentDomains.d.ts +0 -0
  87. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/trimQueryFromUrl.d.ts +0 -0
  88. /package/dist/types/{core → browser}/src/components/ActivityCollector/utils/truncateWhiteSpace.d.ts +0 -0
  89. /package/dist/types/{core → browser}/src/components/ActivityCollector/validateClickCollectionConfig.d.ts +0 -0
@@ -0,0 +1,145 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import truncateWhiteSpace from "./utils/truncateWhiteSpace.js";
14
+ import isSupportedTextNode from "./utils/dom/isSupportedTextNode.js";
15
+
16
+ /**
17
+ * Orders and returns specified node and its child nodes in arrays of supported
18
+ * and unsupported nodes.
19
+ * @param {*} node The node to extract supported and unsupported nodes from.
20
+ * @returns {{supportedNodes: Array, includesUnsupportedNodes: boolean}} Node support object.
21
+ */
22
+ const extractSupportedNodes = (node) => {
23
+ let supportedNodes = [];
24
+ let includesUnsupportedNodes = false;
25
+ if (isSupportedTextNode(node)) {
26
+ supportedNodes.push(node);
27
+ if (node.childNodes) {
28
+ const childNodes = Array.prototype.slice.call(node.childNodes);
29
+ childNodes.forEach((childNode) => {
30
+ const nodes = extractSupportedNodes(childNode);
31
+ supportedNodes = supportedNodes.concat(nodes.supportedNodes);
32
+ includesUnsupportedNodes =
33
+ includesUnsupportedNodes || nodes.includesUnsupportedNodes;
34
+ });
35
+ }
36
+ } else {
37
+ includesUnsupportedNodes = true;
38
+ }
39
+ return {
40
+ supportedNodes,
41
+ includesUnsupportedNodes,
42
+ };
43
+ };
44
+
45
+ /**
46
+ * Returns the value of a node attribute.
47
+ * @param {*} node The node holding the attribute.
48
+ * @param {string} attributeName The name of the attribute.
49
+ * @param {string} nodeName Optional node name constraint.
50
+ * @returns {string} Attribute value or undefined.
51
+ */
52
+ const getNodeAttributeValue = (node, attributeName, nodeName) => {
53
+ let attributeValue;
54
+ if (!nodeName || nodeName === node.nodeName.toUpperCase()) {
55
+ attributeValue = node.getAttribute(attributeName);
56
+ }
57
+ return attributeValue;
58
+ };
59
+
60
+ /**
61
+ * Extracts the children supported nodes attributes map
62
+ * @param {*} nodes The nodes array holding the children nodes.
63
+ * The returned map contains the supported not empty children attributes values.
64
+ * */
65
+ const getChildrenAttributes = (nodes) => {
66
+ const attributes = {
67
+ texts: [],
68
+ };
69
+ nodes.supportedNodes.forEach((supportedNode) => {
70
+ if (supportedNode.getAttribute) {
71
+ if (!attributes.alt) {
72
+ attributes.alt = truncateWhiteSpace(supportedNode.getAttribute("alt"));
73
+ }
74
+ if (!attributes.title) {
75
+ attributes.title = truncateWhiteSpace(
76
+ supportedNode.getAttribute("title"),
77
+ );
78
+ }
79
+ if (!attributes.inputValue) {
80
+ attributes.inputValue = truncateWhiteSpace(
81
+ getNodeAttributeValue(supportedNode, "value", "INPUT"),
82
+ );
83
+ }
84
+ if (!attributes.imgSrc) {
85
+ attributes.imgSrc = truncateWhiteSpace(
86
+ getNodeAttributeValue(supportedNode, "src", "IMG"),
87
+ );
88
+ }
89
+ if (!attributes.ariaLabel) {
90
+ attributes.ariaLabel = truncateWhiteSpace(
91
+ supportedNode.getAttribute("aria-label"),
92
+ );
93
+ }
94
+ if (!attributes.name) {
95
+ attributes.name = truncateWhiteSpace(
96
+ supportedNode.getAttribute("name"),
97
+ );
98
+ }
99
+ }
100
+ if (supportedNode.nodeValue) {
101
+ attributes.texts.push(supportedNode.nodeValue);
102
+ }
103
+ });
104
+ return attributes;
105
+ };
106
+
107
+ /**
108
+ * Extracts a link-name from a given node.
109
+ *
110
+ * The returned link-name is set to one of the following (in order of priority):
111
+ *
112
+ * 1. Clicked node innerText
113
+ * 2. Clicked node textContent
114
+ * 3. Clicked node and its child nodes nodeValue appended together.
115
+ * 4. Clicked node alt attribute or node descendant alt attribute.
116
+ * Whichever is found first.
117
+ * 5. Clicked node text attribute or node descendant text attribute.
118
+ * Whichever is found first.
119
+ * 6. Clicked node INPUT descendant value attribute.
120
+ * Whichever is found first.
121
+ * 7. Clicked node IMG descendant src attribute.
122
+ * Whichever is found first.
123
+ *
124
+ * @param {*} node The node to find link text for.
125
+ * @returns {string} link-name or an empty string if not link-name is found.
126
+ */
127
+ export default (node) => {
128
+ let nodeText = truncateWhiteSpace(node.innerText || node.textContent);
129
+ const nodes = extractSupportedNodes(node);
130
+ // if contains unsupported nodes we want children node attributes
131
+ if (!nodeText || nodes.includesUnsupportedNodes) {
132
+ const attributesMap = getChildrenAttributes(nodes);
133
+ nodeText = truncateWhiteSpace(attributesMap.texts.join(""));
134
+ if (!nodeText) {
135
+ nodeText =
136
+ attributesMap.alt ||
137
+ attributesMap.title ||
138
+ attributesMap.inputValue ||
139
+ attributesMap.imgSrc ||
140
+ attributesMap.ariaLabel ||
141
+ attributesMap.name;
142
+ }
143
+ }
144
+ return nodeText || "";
145
+ };
@@ -0,0 +1,65 @@
1
+ /*
2
+ Copyright 2022 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import truncateWhiteSpace from "./utils/truncateWhiteSpace.js";
14
+ import { isNonEmptyString } from "@adobe/alloy-core/utils";
15
+
16
+ const semanticElements = /^(HEADER|MAIN|FOOTER|NAV)$/i;
17
+
18
+ const getAriaRegionLabel = (node) => {
19
+ let regionLabel;
20
+ if (node.role === "region" && isNonEmptyString(node["aria-label"])) {
21
+ regionLabel = node["aria-label"];
22
+ }
23
+ return regionLabel;
24
+ };
25
+
26
+ const getSectionNodeName = (node) => {
27
+ let nodeName;
28
+ if (node && node.nodeName) {
29
+ if (node.nodeName.match(semanticElements)) {
30
+ nodeName = node.nodeName;
31
+ }
32
+ }
33
+ return nodeName;
34
+ };
35
+
36
+ /**
37
+ * Extracts a node link-region.
38
+ *
39
+ * The link-region is determined by traversing up the DOM
40
+ * looking for a region that is determined in order of priority:
41
+ *
42
+ * 1. element.id
43
+ * 2. Aria region label
44
+ * 3. Semantic element name
45
+ * 4. BODY (if no other link-region is found).
46
+ *
47
+ * @param {*} node The node to find link region for.
48
+ * @returns {string} link-region.
49
+ */
50
+ export default (node) => {
51
+ let linkParentNode = node.parentNode;
52
+ let regionName;
53
+ while (linkParentNode) {
54
+ regionName = truncateWhiteSpace(
55
+ linkParentNode.id ||
56
+ getAriaRegionLabel(linkParentNode) ||
57
+ getSectionNodeName(linkParentNode),
58
+ );
59
+ if (regionName) {
60
+ return regionName;
61
+ }
62
+ linkParentNode = linkParentNode.parentNode;
63
+ }
64
+ return "BODY";
65
+ };
@@ -0,0 +1,132 @@
1
+ /*
2
+ Copyright 2019 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import attachClickActivityCollector from "./attachClickActivityCollector.js";
14
+ import configValidators from "./configValidators.js";
15
+ import createInjectClickedElementProperties from "./createInjectClickedElementProperties.js";
16
+ import createRecallAndInjectClickedElementProperties from "./createRecallAndInjectClickedElementProperties.js";
17
+ import createGetClickedElementProperties from "./createGetClickedElementProperties.js";
18
+ import createClickActivityStorage from "./createClickActivityStorage.js";
19
+ import createStorePageViewProperties from "./createStorePageViewProperties.js";
20
+ import validateClickCollectionConfig from "./validateClickCollectionConfig.js";
21
+ import getLinkName from "./getLinkName.js";
22
+ import getLinkRegion from "./getLinkRegion.js";
23
+ import getAbsoluteUrlFromAnchorElement from "./utils/dom/getAbsoluteUrlFromAnchorElement.js";
24
+ import findClickableElement from "./utils/dom/findClickableElement.js";
25
+ import determineLinkType from "./utils/determineLinkType.js";
26
+ import hasPageName from "./utils/hasPageName.js";
27
+ import createTransientStorage from "./utils/createTransientStorage.js";
28
+ import { injectStorage } from "@adobe/alloy-core/utils";
29
+
30
+ const getClickedElementProperties = createGetClickedElementProperties({
31
+ window,
32
+ getLinkName,
33
+ getLinkRegion,
34
+ getAbsoluteUrlFromAnchorElement,
35
+ findClickableElement,
36
+ determineLinkType,
37
+ });
38
+
39
+ let clickActivityStorage;
40
+ const initClickActivityStorage = (config) => {
41
+ if (!clickActivityStorage) {
42
+ const createNamespacedStorage = injectStorage(window);
43
+ const nameSpacedStorage = createNamespacedStorage(config.orgId || "");
44
+ // Use transient in-memory if sessionStorage is disabled
45
+ const transientStorage = createTransientStorage();
46
+ const storage = config.clickCollection.sessionStorageEnabled
47
+ ? nameSpacedStorage.session
48
+ : transientStorage;
49
+ clickActivityStorage = createClickActivityStorage({ storage });
50
+ }
51
+ };
52
+
53
+ const createActivityCollector = ({
54
+ config,
55
+ eventManager,
56
+ handleError,
57
+ logger,
58
+ }) => {
59
+ validateClickCollectionConfig(config, logger);
60
+
61
+ const clickCollection = config.clickCollection;
62
+ if (!clickActivityStorage) {
63
+ initClickActivityStorage(config);
64
+ }
65
+
66
+ const injectClickedElementProperties = createInjectClickedElementProperties({
67
+ config,
68
+ logger,
69
+ clickActivityStorage,
70
+ getClickedElementProperties,
71
+ });
72
+
73
+ const recallAndInjectClickedElementProperties =
74
+ createRecallAndInjectClickedElementProperties({
75
+ clickActivityStorage,
76
+ });
77
+
78
+ const storePageViewProperties = createStorePageViewProperties({
79
+ clickActivityStorage,
80
+ });
81
+
82
+ return {
83
+ lifecycle: {
84
+ onComponentsRegistered(tools) {
85
+ const { lifecycle } = tools;
86
+ attachClickActivityCollector({
87
+ eventManager,
88
+ lifecycle,
89
+ handleError,
90
+ });
91
+ // TODO: createScrollActivityCollector ...
92
+ },
93
+ onClick({ event, clickedElement }) {
94
+ injectClickedElementProperties({
95
+ event,
96
+ clickedElement,
97
+ });
98
+ },
99
+ onBeforeEvent({ event }) {
100
+ if (hasPageName(event)) {
101
+ if (clickCollection.eventGroupingEnabled) {
102
+ recallAndInjectClickedElementProperties(event);
103
+ }
104
+ storePageViewProperties(event, logger, clickActivityStorage);
105
+ }
106
+ },
107
+ },
108
+ };
109
+ };
110
+
111
+ createActivityCollector.namespace = "ActivityCollector";
112
+ createActivityCollector.configValidators = configValidators;
113
+ createActivityCollector.buildOnInstanceConfiguredExtraParams = ({
114
+ config,
115
+ logger,
116
+ }) => {
117
+ if (!clickActivityStorage) {
118
+ initClickActivityStorage(config);
119
+ }
120
+ return {
121
+ getLinkDetails: (targetElement) => {
122
+ return getClickedElementProperties({
123
+ clickActivityStorage,
124
+ clickedElement: targetElement,
125
+ config,
126
+ logger,
127
+ }).properties;
128
+ },
129
+ };
130
+ };
131
+
132
+ export default createActivityCollector;
@@ -0,0 +1,16 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ const ACTIVITY_MAP_EXTENSION_ID = "cppXYctnr";
14
+
15
+ export default (context = document) =>
16
+ context.getElementById(ACTIVITY_MAP_EXTENSION_ID) !== null;
@@ -0,0 +1,26 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default () => {
14
+ const storage = {};
15
+ return {
16
+ getItem: (key) => {
17
+ return storage[key];
18
+ },
19
+ setItem: (key, value) => {
20
+ storage[key] = value;
21
+ },
22
+ removeItem: (key) => {
23
+ delete storage[key];
24
+ },
25
+ };
26
+ };
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import isDownloadLink from "./dom/isDownloadLink.js";
14
+ import isExitLink from "./dom/isExitLink.js";
15
+ import { isNonEmptyString } from "@adobe/alloy-core/utils";
16
+
17
+ export default (window, config, linkUrl, clickedObj) => {
18
+ let linkType = "other";
19
+ if (isNonEmptyString(linkUrl)) {
20
+ if (isDownloadLink(config.downloadLinkQualifier, linkUrl, clickedObj)) {
21
+ linkType = "download";
22
+ } else if (isExitLink(window, linkUrl)) {
23
+ linkType = "exit";
24
+ }
25
+ }
26
+ return linkType;
27
+ };
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default (element) => {
14
+ return !element ? false : !!element.onclick;
15
+ };
@@ -0,0 +1,20 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default (uri) => {
14
+ let fullUrl = uri;
15
+ if (!/^https?:\/\//i.test(fullUrl)) {
16
+ fullUrl = `${window.location.protocol}//${uri}`;
17
+ }
18
+ const url = new URL(fullUrl);
19
+ return url.hostname;
20
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import isSupportedAnchorElement from "./isSupportedAnchorElement.js";
14
+ import elementHasClickHandler from "./elementHasClickHandler.js";
15
+ import isInputSubmitElement from "./isInputSubmitElement.js";
16
+ import isButtonSubmitElement from "./isButtonSubmitElement.js";
17
+
18
+ export default (element) => {
19
+ let node = element;
20
+ while (node) {
21
+ // Stop looking when BODY is reached
22
+ if (node.nodeName && node.nodeName === "BODY") {
23
+ break;
24
+ }
25
+ if (
26
+ isSupportedAnchorElement(node) ||
27
+ elementHasClickHandler(node) ||
28
+ isInputSubmitElement(node) ||
29
+ isButtonSubmitElement(node)
30
+ ) {
31
+ return node;
32
+ }
33
+ node = node.parentNode;
34
+ }
35
+ return null;
36
+ };
@@ -0,0 +1,25 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default (window, element) => {
14
+ const base = window.location.href;
15
+ let href = element.href || "";
16
+ // Some objects (like SVG animations) can contain a href object instead of a string
17
+ if (typeof href !== "string") {
18
+ href = "";
19
+ }
20
+ try {
21
+ return new URL(href, base).href;
22
+ } catch {
23
+ return base;
24
+ }
25
+ };
@@ -0,0 +1,15 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default (element) => {
14
+ return element.tagName === "BUTTON" && element.type === "submit";
15
+ };
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import trimQueryFromUrl from "../trimQueryFromUrl.js";
14
+
15
+ export default (downloadLinkQualifier, linkUrl, clickedObj) => {
16
+ let result = false;
17
+ if (linkUrl) {
18
+ if (clickedObj && clickedObj.download) {
19
+ result = true;
20
+ } else if (downloadLinkQualifier) {
21
+ const re = new RegExp(downloadLinkQualifier);
22
+ const trimmedLinkUrl = trimQueryFromUrl(linkUrl).toLowerCase();
23
+ result = re.test(trimmedLinkUrl);
24
+ }
25
+ }
26
+ return result;
27
+ };
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ import trimQueryFromUrl from "../trimQueryFromUrl.js";
14
+
15
+ export default (window, linkUrl) => {
16
+ let result = false;
17
+ // window.location.hostname should always be defined, but checking just in case
18
+ if (linkUrl && window.location.hostname) {
19
+ const currentHostname = window.location.hostname.toLowerCase();
20
+ const trimmedLinkUrl = trimQueryFromUrl(linkUrl).toLowerCase();
21
+ result = trimmedLinkUrl.indexOf(currentHostname) < 0;
22
+ }
23
+ return result;
24
+ };
@@ -0,0 +1,26 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default (element) => {
14
+ if (element.tagName === "INPUT") {
15
+ const type = element.getAttribute("type");
16
+ if (type === "submit") {
17
+ return true;
18
+ }
19
+ // Image type input elements are considered submit elements.
20
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/image
21
+ if (type === "image" && element.src) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ };
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ export default (element) => {
14
+ if (
15
+ element.href &&
16
+ (element.tagName === "A" || element.tagName === "AREA") &&
17
+ (!element.onclick ||
18
+ !element.protocol ||
19
+ element.protocol.toLowerCase().indexOf("javascript") < 0)
20
+ ) {
21
+ return true;
22
+ }
23
+ return false;
24
+ };
@@ -0,0 +1,27 @@
1
+ /*
2
+ Copyright 2024 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ const unsupportedNodeNames = /^(SCRIPT|STYLE|LINK|CANVAS|NOSCRIPT|#COMMENT)$/i;
14
+
15
+ /**
16
+ * Determines if a node qualifies as a supported link text node.
17
+ * @param {*} node Node to determine support for.
18
+ * @returns {boolean}
19
+ */
20
+ export default (node) => {
21
+ if (node && node.nodeName) {
22
+ if (node.nodeName.match(unsupportedNodeNames)) {
23
+ return false;
24
+ }
25
+ }
26
+ return true;
27
+ };