@ukic/web-components 3.25.0 → 3.27.0

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 (328) hide show
  1. package/components/OpenInNew.js +5 -0
  2. package/components/OpenInNew.js.map +1 -0
  3. package/components/check-icon.js +8 -0
  4. package/components/check-icon.js.map +1 -0
  5. package/components/chevron-icon.js +8 -0
  6. package/components/chevron-icon.js.map +1 -0
  7. package/components/close-icon.js +10 -0
  8. package/components/close-icon.js.map +1 -0
  9. package/components/constants.js +184 -0
  10. package/components/constants.js.map +1 -0
  11. package/components/custom-elements.d.ts +2 -0
  12. package/components/helpers.js +547 -0
  13. package/components/helpers.js.map +1 -0
  14. package/components/ic-accordion-group.d.ts +11 -0
  15. package/components/ic-accordion-group.js +191 -0
  16. package/components/ic-accordion-group.js.map +1 -0
  17. package/components/ic-accordion.d.ts +11 -0
  18. package/components/ic-accordion.js +188 -0
  19. package/components/ic-accordion.js.map +1 -0
  20. package/components/ic-action-chip.d.ts +11 -0
  21. package/components/ic-action-chip.js +164 -0
  22. package/components/ic-action-chip.js.map +1 -0
  23. package/components/ic-alert.d.ts +11 -0
  24. package/components/ic-alert.js +193 -0
  25. package/components/ic-alert.js.map +1 -0
  26. package/components/ic-back-to-top.d.ts +11 -0
  27. package/components/ic-back-to-top.js +216 -0
  28. package/components/ic-back-to-top.js.map +1 -0
  29. package/components/ic-badge.d.ts +11 -0
  30. package/components/ic-badge.js +222 -0
  31. package/components/ic-badge.js.map +1 -0
  32. package/components/ic-breadcrumb-group.d.ts +11 -0
  33. package/components/ic-breadcrumb-group.js +278 -0
  34. package/components/ic-breadcrumb-group.js.map +1 -0
  35. package/components/ic-breadcrumb.d.ts +11 -0
  36. package/components/ic-breadcrumb.js +8 -0
  37. package/components/ic-breadcrumb.js.map +1 -0
  38. package/components/ic-breadcrumb2.js +145 -0
  39. package/components/ic-breadcrumb2.js.map +1 -0
  40. package/components/ic-button.d.ts +11 -0
  41. package/components/ic-button.js +8 -0
  42. package/components/ic-button.js.map +1 -0
  43. package/components/ic-button2.js +509 -0
  44. package/components/ic-button2.js.map +1 -0
  45. package/components/ic-card-horizontal.d.ts +11 -0
  46. package/components/ic-card-horizontal.js +214 -0
  47. package/components/ic-card-horizontal.js.map +1 -0
  48. package/components/ic-card-vertical.d.ts +11 -0
  49. package/components/ic-card-vertical.js +219 -0
  50. package/components/ic-card-vertical.js.map +1 -0
  51. package/components/ic-checkbox-group.d.ts +11 -0
  52. package/components/ic-checkbox-group.js +198 -0
  53. package/components/ic-checkbox-group.js.map +1 -0
  54. package/components/ic-checkbox.d.ts +11 -0
  55. package/components/ic-checkbox.js +202 -0
  56. package/components/ic-checkbox.js.map +1 -0
  57. package/components/ic-chip.d.ts +11 -0
  58. package/components/ic-chip.js +183 -0
  59. package/components/ic-chip.js.map +1 -0
  60. package/components/ic-classification-banner.d.ts +11 -0
  61. package/components/ic-classification-banner.js +102 -0
  62. package/components/ic-classification-banner.js.map +1 -0
  63. package/components/ic-data-list.d.ts +11 -0
  64. package/components/ic-data-list.js +63 -0
  65. package/components/ic-data-list.js.map +1 -0
  66. package/components/ic-data-row.d.ts +11 -0
  67. package/components/ic-data-row.js +115 -0
  68. package/components/ic-data-row.js.map +1 -0
  69. package/components/ic-dialog.d.ts +11 -0
  70. package/components/ic-dialog.js +366 -0
  71. package/components/ic-dialog.js.map +1 -0
  72. package/components/ic-divider.d.ts +11 -0
  73. package/components/ic-divider.js +8 -0
  74. package/components/ic-divider.js.map +1 -0
  75. package/components/ic-divider2.js +148 -0
  76. package/components/ic-divider2.js.map +1 -0
  77. package/components/ic-empty-state.d.ts +11 -0
  78. package/components/ic-empty-state.js +82 -0
  79. package/components/ic-empty-state.js.map +1 -0
  80. package/components/ic-footer-link-group.d.ts +11 -0
  81. package/components/ic-footer-link-group.js +101 -0
  82. package/components/ic-footer-link-group.js.map +1 -0
  83. package/components/ic-footer-link.d.ts +11 -0
  84. package/components/ic-footer-link.js +95 -0
  85. package/components/ic-footer-link.js.map +1 -0
  86. package/components/ic-footer.d.ts +11 -0
  87. package/components/ic-footer.js +156 -0
  88. package/components/ic-footer.js.map +1 -0
  89. package/components/ic-hero.d.ts +11 -0
  90. package/components/ic-hero.js +145 -0
  91. package/components/ic-hero.js.map +1 -0
  92. package/components/ic-horizontal-scroll.d.ts +11 -0
  93. package/components/ic-horizontal-scroll.js +8 -0
  94. package/components/ic-horizontal-scroll.js.map +1 -0
  95. package/components/ic-horizontal-scroll2.js +240 -0
  96. package/components/ic-horizontal-scroll2.js.map +1 -0
  97. package/components/ic-input-component-container.d.ts +11 -0
  98. package/components/ic-input-component-container.js +8 -0
  99. package/components/ic-input-component-container.js.map +1 -0
  100. package/components/ic-input-component-container2.js +95 -0
  101. package/components/ic-input-component-container2.js.map +1 -0
  102. package/components/ic-input-container.d.ts +11 -0
  103. package/components/ic-input-container.js +8 -0
  104. package/components/ic-input-container.js.map +1 -0
  105. package/components/ic-input-container2.js +47 -0
  106. package/components/ic-input-container2.js.map +1 -0
  107. package/components/ic-input-label.d.ts +11 -0
  108. package/components/ic-input-label.js +8 -0
  109. package/components/ic-input-label.js.map +1 -0
  110. package/components/ic-input-label2.js +121 -0
  111. package/components/ic-input-label2.js.map +1 -0
  112. package/components/ic-input-validation.d.ts +11 -0
  113. package/components/ic-input-validation.js +8 -0
  114. package/components/ic-input-validation.js.map +1 -0
  115. package/components/ic-input-validation2.js +90 -0
  116. package/components/ic-input-validation2.js.map +1 -0
  117. package/components/ic-layout-grid-item.d.ts +11 -0
  118. package/components/ic-layout-grid-item.js +95 -0
  119. package/components/ic-layout-grid-item.js.map +1 -0
  120. package/components/ic-layout-grid.d.ts +11 -0
  121. package/components/ic-layout-grid.js +188 -0
  122. package/components/ic-layout-grid.js.map +1 -0
  123. package/components/ic-link.d.ts +11 -0
  124. package/components/ic-link.js +8 -0
  125. package/components/ic-link.js.map +1 -0
  126. package/components/ic-link2.js +135 -0
  127. package/components/ic-link2.js.map +1 -0
  128. package/components/ic-loading-indicator.d.ts +11 -0
  129. package/components/ic-loading-indicator.js +8 -0
  130. package/components/ic-loading-indicator.js.map +1 -0
  131. package/components/ic-loading-indicator2.js +278 -0
  132. package/components/ic-loading-indicator2.js.map +1 -0
  133. package/components/ic-menu-group.d.ts +11 -0
  134. package/components/ic-menu-group.js +47 -0
  135. package/components/ic-menu-group.js.map +1 -0
  136. package/components/ic-menu-item.d.ts +11 -0
  137. package/components/ic-menu-item.js +8 -0
  138. package/components/ic-menu-item.js.map +1 -0
  139. package/components/ic-menu-item2.js +171 -0
  140. package/components/ic-menu-item2.js.map +1 -0
  141. package/components/ic-menu.d.ts +11 -0
  142. package/components/ic-menu.js +8 -0
  143. package/components/ic-menu.js.map +1 -0
  144. package/components/ic-menu2.js +2590 -0
  145. package/components/ic-menu2.js.map +1 -0
  146. package/components/ic-navigation-button.d.ts +11 -0
  147. package/components/ic-navigation-button.js +175 -0
  148. package/components/ic-navigation-button.js.map +1 -0
  149. package/components/ic-navigation-group.d.ts +11 -0
  150. package/components/ic-navigation-group.js +326 -0
  151. package/components/ic-navigation-group.js.map +1 -0
  152. package/components/ic-navigation-item.d.ts +11 -0
  153. package/components/ic-navigation-item.js +294 -0
  154. package/components/ic-navigation-item.js.map +1 -0
  155. package/components/ic-navigation-menu.d.ts +11 -0
  156. package/components/ic-navigation-menu.js +8 -0
  157. package/components/ic-navigation-menu.js.map +1 -0
  158. package/components/ic-navigation-menu2.js +188 -0
  159. package/components/ic-navigation-menu2.js.map +1 -0
  160. package/components/ic-page-header.d.ts +11 -0
  161. package/components/ic-page-header.js +196 -0
  162. package/components/ic-page-header.js.map +1 -0
  163. package/components/ic-pagination-bar.d.ts +11 -0
  164. package/components/ic-pagination-bar.js +523 -0
  165. package/components/ic-pagination-bar.js.map +1 -0
  166. package/components/ic-pagination-item.d.ts +11 -0
  167. package/components/ic-pagination-item.js +8 -0
  168. package/components/ic-pagination-item.js.map +1 -0
  169. package/components/ic-pagination-item2.js +107 -0
  170. package/components/ic-pagination-item2.js.map +1 -0
  171. package/components/ic-pagination.d.ts +11 -0
  172. package/components/ic-pagination.js +8 -0
  173. package/components/ic-pagination.js.map +1 -0
  174. package/components/ic-pagination2.js +379 -0
  175. package/components/ic-pagination2.js.map +1 -0
  176. package/components/ic-popover-menu.d.ts +11 -0
  177. package/components/ic-popover-menu.js +369 -0
  178. package/components/ic-popover-menu.js.map +1 -0
  179. package/components/ic-radio-group.d.ts +11 -0
  180. package/components/ic-radio-group.js +317 -0
  181. package/components/ic-radio-group.js.map +1 -0
  182. package/components/ic-radio-option.d.ts +11 -0
  183. package/components/ic-radio-option.js +211 -0
  184. package/components/ic-radio-option.js.map +1 -0
  185. package/components/ic-search-bar.d.ts +11 -0
  186. package/components/ic-search-bar.js +719 -0
  187. package/components/ic-search-bar.js.map +1 -0
  188. package/components/ic-section-container.d.ts +11 -0
  189. package/components/ic-section-container.js +8 -0
  190. package/components/ic-section-container.js.map +1 -0
  191. package/components/ic-section-container2.js +50 -0
  192. package/components/ic-section-container2.js.map +1 -0
  193. package/components/ic-select.d.ts +11 -0
  194. package/components/ic-select.js +8 -0
  195. package/components/ic-select.js.map +1 -0
  196. package/components/ic-select2.js +806 -0
  197. package/components/ic-select2.js.map +1 -0
  198. package/components/ic-side-navigation.d.ts +11 -0
  199. package/components/ic-side-navigation.js +568 -0
  200. package/components/ic-side-navigation.js.map +1 -0
  201. package/components/ic-skeleton.d.ts +11 -0
  202. package/components/ic-skeleton.js +81 -0
  203. package/components/ic-skeleton.js.map +1 -0
  204. package/components/ic-skip-link.d.ts +11 -0
  205. package/components/ic-skip-link.js +91 -0
  206. package/components/ic-skip-link.js.map +1 -0
  207. package/components/ic-status-tag.d.ts +11 -0
  208. package/components/ic-status-tag.js +85 -0
  209. package/components/ic-status-tag.js.map +1 -0
  210. package/components/ic-step.d.ts +11 -0
  211. package/components/ic-step.js +200 -0
  212. package/components/ic-step.js.map +1 -0
  213. package/components/ic-stepper.d.ts +11 -0
  214. package/components/ic-stepper.js +340 -0
  215. package/components/ic-stepper.js.map +1 -0
  216. package/components/ic-switch.d.ts +11 -0
  217. package/components/ic-switch.js +164 -0
  218. package/components/ic-switch.js.map +1 -0
  219. package/components/ic-tab-context.d.ts +11 -0
  220. package/components/ic-tab-context.js +275 -0
  221. package/components/ic-tab-context.js.map +1 -0
  222. package/components/ic-tab-group.d.ts +11 -0
  223. package/components/ic-tab-group.js +89 -0
  224. package/components/ic-tab-group.js.map +1 -0
  225. package/components/ic-tab-panel.d.ts +11 -0
  226. package/components/ic-tab-panel.js +63 -0
  227. package/components/ic-tab-panel.js.map +1 -0
  228. package/components/ic-tab.d.ts +11 -0
  229. package/components/ic-tab.js +143 -0
  230. package/components/ic-tab.js.map +1 -0
  231. package/components/ic-text-field.d.ts +11 -0
  232. package/components/ic-text-field.js +8 -0
  233. package/components/ic-text-field.js.map +1 -0
  234. package/components/ic-text-field2.js +532 -0
  235. package/components/ic-text-field2.js.map +1 -0
  236. package/components/ic-theme.d.ts +11 -0
  237. package/components/ic-theme.js +105 -0
  238. package/components/ic-theme.js.map +1 -0
  239. package/components/ic-toast-region.d.ts +11 -0
  240. package/components/ic-toast-region.js +76 -0
  241. package/components/ic-toast-region.js.map +1 -0
  242. package/components/ic-toast.d.ts +11 -0
  243. package/components/ic-toast.js +295 -0
  244. package/components/ic-toast.js.map +1 -0
  245. package/components/ic-toggle-button-group.d.ts +11 -0
  246. package/components/ic-toggle-button-group.js +323 -0
  247. package/components/ic-toggle-button-group.js.map +1 -0
  248. package/components/ic-toggle-button.d.ts +11 -0
  249. package/components/ic-toggle-button.js +235 -0
  250. package/components/ic-toggle-button.js.map +1 -0
  251. package/components/ic-tooltip.d.ts +11 -0
  252. package/components/ic-tooltip.js +8 -0
  253. package/components/ic-tooltip.js.map +1 -0
  254. package/components/ic-tooltip2.js +2078 -0
  255. package/components/ic-tooltip2.js.map +1 -0
  256. package/components/ic-top-navigation.d.ts +11 -0
  257. package/components/ic-top-navigation.js +320 -0
  258. package/components/ic-top-navigation.js.map +1 -0
  259. package/components/ic-typography.d.ts +11 -0
  260. package/components/ic-typography.js +8 -0
  261. package/components/ic-typography.js.map +1 -0
  262. package/components/ic-typography2.js +228 -0
  263. package/components/ic-typography2.js.map +1 -0
  264. package/components/index.d.ts +33 -0
  265. package/components/index.js +4 -0
  266. package/components/index.js.map +1 -0
  267. package/components/package.json +9 -0
  268. package/dist/cjs/core.cjs.js +1 -1
  269. package/dist/cjs/ic-button_3.cjs.entry.js.map +1 -1
  270. package/dist/cjs/ic-input-component-container_3.cjs.entry.js +63 -37
  271. package/dist/cjs/ic-input-component-container_3.cjs.entry.js.map +1 -1
  272. package/dist/cjs/ic-pagination_3.cjs.entry.js +17 -17
  273. package/dist/cjs/ic-pagination_3.cjs.entry.js.map +1 -1
  274. package/dist/cjs/ic-section-container.cjs.entry.js.map +1 -1
  275. package/dist/cjs/ic-top-navigation.cjs.entry.js +12 -8
  276. package/dist/cjs/ic-top-navigation.cjs.entry.js.map +1 -1
  277. package/dist/cjs/loader.cjs.js +1 -1
  278. package/dist/collection/components/ic-menu/ic-menu.css +19 -0
  279. package/dist/collection/components/ic-menu/ic-menu.js +62 -36
  280. package/dist/collection/components/ic-menu/ic-menu.js.map +1 -1
  281. package/dist/collection/components/ic-menu/ic-menu.types.js.map +1 -1
  282. package/dist/collection/components/ic-select/ic-select.js +17 -17
  283. package/dist/collection/components/ic-select/ic-select.js.map +1 -1
  284. package/dist/collection/components/ic-select/ic-select_(single).stories.js +54 -0
  285. package/dist/collection/components/ic-top-navigation/ic-top-navigation.js +33 -9
  286. package/dist/collection/components/ic-top-navigation/ic-top-navigation.js.map +1 -1
  287. package/dist/collection/components/ic-top-navigation/ic-top-navigation.stories.js +26 -0
  288. package/dist/components/ic-menu2.js +63 -37
  289. package/dist/components/ic-menu2.js.map +1 -1
  290. package/dist/components/ic-page-header.js.map +1 -1
  291. package/dist/components/ic-popover-menu.js.map +1 -1
  292. package/dist/components/ic-radio-group.js.map +1 -1
  293. package/dist/components/ic-radio-option.js.map +1 -1
  294. package/dist/components/ic-select2.js +17 -17
  295. package/dist/components/ic-select2.js.map +1 -1
  296. package/dist/components/ic-top-navigation.js +13 -8
  297. package/dist/components/ic-top-navigation.js.map +1 -1
  298. package/dist/core/core.esm.js +1 -1
  299. package/dist/core/core.esm.js.map +1 -1
  300. package/dist/core/{p-46e5a58b.entry.js → p-12474095.entry.js} +2 -2
  301. package/dist/core/p-12474095.entry.js.map +1 -0
  302. package/dist/core/p-98dee727.entry.js.map +1 -1
  303. package/dist/core/p-d1220d2a.entry.js.map +1 -1
  304. package/dist/core/p-e0b66371.entry.js +2 -0
  305. package/dist/core/p-e0b66371.entry.js.map +1 -0
  306. package/dist/core/{p-171a19bf.entry.js → p-fdc4376e.entry.js} +2 -2
  307. package/dist/core/p-fdc4376e.entry.js.map +1 -0
  308. package/dist/esm/core.js +1 -1
  309. package/dist/esm/ic-button_3.entry.js.map +1 -1
  310. package/dist/esm/ic-input-component-container_3.entry.js +63 -37
  311. package/dist/esm/ic-input-component-container_3.entry.js.map +1 -1
  312. package/dist/esm/ic-pagination_3.entry.js +17 -17
  313. package/dist/esm/ic-pagination_3.entry.js.map +1 -1
  314. package/dist/esm/ic-section-container.entry.js.map +1 -1
  315. package/dist/esm/ic-top-navigation.entry.js +12 -8
  316. package/dist/esm/ic-top-navigation.entry.js.map +1 -1
  317. package/dist/esm/loader.js +1 -1
  318. package/dist/types/components/ic-menu/ic-menu.types.d.ts +1 -0
  319. package/dist/types/components/ic-top-navigation/ic-top-navigation.d.ts +4 -1
  320. package/dist/types/components.d.ts +10 -2
  321. package/hydrate/index.js +93 -62
  322. package/hydrate/index.mjs +93 -62
  323. package/package.json +4 -2
  324. package/vscode-data.json +5 -1
  325. package/dist/core/p-171a19bf.entry.js.map +0 -1
  326. package/dist/core/p-343670b4.entry.js +0 -2
  327. package/dist/core/p-343670b4.entry.js.map +0 -1
  328. package/dist/core/p-46e5a58b.entry.js.map +0 -1
@@ -0,0 +1,2590 @@
1
+ import { proxyCustomElement, HTMLElement, createEvent, h, Fragment, Host } from '@stencil/core/internal/client';
2
+ import { c as checkIcon } from './check-icon.js';
3
+ import { K as isMacDevice, o as onComponentRequiredPropUndefined, L as getOptionsWithoutGroupTitlesCount } from './helpers.js';
4
+ import { f as IC_CUSTOM_ALLOWED_COMPONENTS } from './constants.js';
5
+ import { d as defineCustomElement$4 } from './ic-button2.js';
6
+ import { d as defineCustomElement$3 } from './ic-loading-indicator2.js';
7
+ import { c as createPopper, d as defineCustomElement$2 } from './ic-tooltip2.js';
8
+ import { d as defineCustomElement$1 } from './ic-typography2.js';
9
+
10
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
11
+
12
+ var purify = {exports: {}};
13
+
14
+ /*! @license DOMPurify 3.4.0 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.4.0/LICENSE */
15
+
16
+ (function (module, exports) {
17
+ (function (global, factory) {
18
+ module.exports = factory() ;
19
+ })(commonjsGlobal, (function () {
20
+ const {
21
+ entries,
22
+ setPrototypeOf,
23
+ isFrozen,
24
+ getPrototypeOf,
25
+ getOwnPropertyDescriptor
26
+ } = Object;
27
+ let {
28
+ freeze,
29
+ seal,
30
+ create
31
+ } = Object; // eslint-disable-line import/no-mutable-exports
32
+ let {
33
+ apply,
34
+ construct
35
+ } = typeof Reflect !== 'undefined' && Reflect;
36
+ if (!freeze) {
37
+ freeze = function freeze(x) {
38
+ return x;
39
+ };
40
+ }
41
+ if (!seal) {
42
+ seal = function seal(x) {
43
+ return x;
44
+ };
45
+ }
46
+ if (!apply) {
47
+ apply = function apply(func, thisArg) {
48
+ for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
49
+ args[_key - 2] = arguments[_key];
50
+ }
51
+ return func.apply(thisArg, args);
52
+ };
53
+ }
54
+ if (!construct) {
55
+ construct = function construct(Func) {
56
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
57
+ args[_key2 - 1] = arguments[_key2];
58
+ }
59
+ return new Func(...args);
60
+ };
61
+ }
62
+ const arrayForEach = unapply(Array.prototype.forEach);
63
+ const arrayLastIndexOf = unapply(Array.prototype.lastIndexOf);
64
+ const arrayPop = unapply(Array.prototype.pop);
65
+ const arrayPush = unapply(Array.prototype.push);
66
+ const arraySplice = unapply(Array.prototype.splice);
67
+ const stringToLowerCase = unapply(String.prototype.toLowerCase);
68
+ const stringToString = unapply(String.prototype.toString);
69
+ const stringMatch = unapply(String.prototype.match);
70
+ const stringReplace = unapply(String.prototype.replace);
71
+ const stringIndexOf = unapply(String.prototype.indexOf);
72
+ const stringTrim = unapply(String.prototype.trim);
73
+ const objectHasOwnProperty = unapply(Object.prototype.hasOwnProperty);
74
+ const regExpTest = unapply(RegExp.prototype.test);
75
+ const typeErrorCreate = unconstruct(TypeError);
76
+ /**
77
+ * Creates a new function that calls the given function with a specified thisArg and arguments.
78
+ *
79
+ * @param func - The function to be wrapped and called.
80
+ * @returns A new function that calls the given function with a specified thisArg and arguments.
81
+ */
82
+ function unapply(func) {
83
+ return function (thisArg) {
84
+ if (thisArg instanceof RegExp) {
85
+ thisArg.lastIndex = 0;
86
+ }
87
+ for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
88
+ args[_key3 - 1] = arguments[_key3];
89
+ }
90
+ return apply(func, thisArg, args);
91
+ };
92
+ }
93
+ /**
94
+ * Creates a new function that constructs an instance of the given constructor function with the provided arguments.
95
+ *
96
+ * @param func - The constructor function to be wrapped and called.
97
+ * @returns A new function that constructs an instance of the given constructor function with the provided arguments.
98
+ */
99
+ function unconstruct(Func) {
100
+ return function () {
101
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
102
+ args[_key4] = arguments[_key4];
103
+ }
104
+ return construct(Func, args);
105
+ };
106
+ }
107
+ /**
108
+ * Add properties to a lookup table
109
+ *
110
+ * @param set - The set to which elements will be added.
111
+ * @param array - The array containing elements to be added to the set.
112
+ * @param transformCaseFunc - An optional function to transform the case of each element before adding to the set.
113
+ * @returns The modified set with added elements.
114
+ */
115
+ function addToSet(set, array) {
116
+ let transformCaseFunc = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : stringToLowerCase;
117
+ if (setPrototypeOf) {
118
+ // Make 'in' and truthy checks like Boolean(set.constructor)
119
+ // independent of any properties defined on Object.prototype.
120
+ // Prevent prototype setters from intercepting set as a this value.
121
+ setPrototypeOf(set, null);
122
+ }
123
+ let l = array.length;
124
+ while (l--) {
125
+ let element = array[l];
126
+ if (typeof element === 'string') {
127
+ const lcElement = transformCaseFunc(element);
128
+ if (lcElement !== element) {
129
+ // Config presets (e.g. tags.js, attrs.js) are immutable.
130
+ if (!isFrozen(array)) {
131
+ array[l] = lcElement;
132
+ }
133
+ element = lcElement;
134
+ }
135
+ }
136
+ set[element] = true;
137
+ }
138
+ return set;
139
+ }
140
+ /**
141
+ * Clean up an array to harden against CSPP
142
+ *
143
+ * @param array - The array to be cleaned.
144
+ * @returns The cleaned version of the array
145
+ */
146
+ function cleanArray(array) {
147
+ for (let index = 0; index < array.length; index++) {
148
+ const isPropertyExist = objectHasOwnProperty(array, index);
149
+ if (!isPropertyExist) {
150
+ array[index] = null;
151
+ }
152
+ }
153
+ return array;
154
+ }
155
+ /**
156
+ * Shallow clone an object
157
+ *
158
+ * @param object - The object to be cloned.
159
+ * @returns A new object that copies the original.
160
+ */
161
+ function clone(object) {
162
+ const newObject = create(null);
163
+ for (const [property, value] of entries(object)) {
164
+ const isPropertyExist = objectHasOwnProperty(object, property);
165
+ if (isPropertyExist) {
166
+ if (Array.isArray(value)) {
167
+ newObject[property] = cleanArray(value);
168
+ } else if (value && typeof value === 'object' && value.constructor === Object) {
169
+ newObject[property] = clone(value);
170
+ } else {
171
+ newObject[property] = value;
172
+ }
173
+ }
174
+ }
175
+ return newObject;
176
+ }
177
+ /**
178
+ * This method automatically checks if the prop is function or getter and behaves accordingly.
179
+ *
180
+ * @param object - The object to look up the getter function in its prototype chain.
181
+ * @param prop - The property name for which to find the getter function.
182
+ * @returns The getter function found in the prototype chain or a fallback function.
183
+ */
184
+ function lookupGetter(object, prop) {
185
+ while (object !== null) {
186
+ const desc = getOwnPropertyDescriptor(object, prop);
187
+ if (desc) {
188
+ if (desc.get) {
189
+ return unapply(desc.get);
190
+ }
191
+ if (typeof desc.value === 'function') {
192
+ return unapply(desc.value);
193
+ }
194
+ }
195
+ object = getPrototypeOf(object);
196
+ }
197
+ function fallbackValue() {
198
+ return null;
199
+ }
200
+ return fallbackValue;
201
+ }
202
+
203
+ const html$1 = freeze(['a', 'abbr', 'acronym', 'address', 'area', 'article', 'aside', 'audio', 'b', 'bdi', 'bdo', 'big', 'blink', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'content', 'data', 'datalist', 'dd', 'decorator', 'del', 'details', 'dfn', 'dialog', 'dir', 'div', 'dl', 'dt', 'element', 'em', 'fieldset', 'figcaption', 'figure', 'font', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meter', 'nav', 'nobr', 'ol', 'optgroup', 'option', 'output', 'p', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'search', 'section', 'select', 'shadow', 'slot', 'small', 'source', 'spacer', 'span', 'strike', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'tr', 'track', 'tt', 'u', 'ul', 'var', 'video', 'wbr']);
204
+ const svg$1 = freeze(['svg', 'a', 'altglyph', 'altglyphdef', 'altglyphitem', 'animatecolor', 'animatemotion', 'animatetransform', 'circle', 'clippath', 'defs', 'desc', 'ellipse', 'enterkeyhint', 'exportparts', 'filter', 'font', 'g', 'glyph', 'glyphref', 'hkern', 'image', 'inputmode', 'line', 'lineargradient', 'marker', 'mask', 'metadata', 'mpath', 'part', 'path', 'pattern', 'polygon', 'polyline', 'radialgradient', 'rect', 'stop', 'style', 'switch', 'symbol', 'text', 'textpath', 'title', 'tref', 'tspan', 'view', 'vkern']);
205
+ const svgFilters = freeze(['feBlend', 'feColorMatrix', 'feComponentTransfer', 'feComposite', 'feConvolveMatrix', 'feDiffuseLighting', 'feDisplacementMap', 'feDistantLight', 'feDropShadow', 'feFlood', 'feFuncA', 'feFuncB', 'feFuncG', 'feFuncR', 'feGaussianBlur', 'feImage', 'feMerge', 'feMergeNode', 'feMorphology', 'feOffset', 'fePointLight', 'feSpecularLighting', 'feSpotLight', 'feTile', 'feTurbulence']);
206
+ // List of SVG elements that are disallowed by default.
207
+ // We still need to know them so that we can do namespace
208
+ // checks properly in case one wants to add them to
209
+ // allow-list.
210
+ const svgDisallowed = freeze(['animate', 'color-profile', 'cursor', 'discard', 'font-face', 'font-face-format', 'font-face-name', 'font-face-src', 'font-face-uri', 'foreignobject', 'hatch', 'hatchpath', 'mesh', 'meshgradient', 'meshpatch', 'meshrow', 'missing-glyph', 'script', 'set', 'solidcolor', 'unknown', 'use']);
211
+ const mathMl$1 = freeze(['math', 'menclose', 'merror', 'mfenced', 'mfrac', 'mglyph', 'mi', 'mlabeledtr', 'mmultiscripts', 'mn', 'mo', 'mover', 'mpadded', 'mphantom', 'mroot', 'mrow', 'ms', 'mspace', 'msqrt', 'mstyle', 'msub', 'msup', 'msubsup', 'mtable', 'mtd', 'mtext', 'mtr', 'munder', 'munderover', 'mprescripts']);
212
+ // Similarly to SVG, we want to know all MathML elements,
213
+ // even those that we disallow by default.
214
+ const mathMlDisallowed = freeze(['maction', 'maligngroup', 'malignmark', 'mlongdiv', 'mscarries', 'mscarry', 'msgroup', 'mstack', 'msline', 'msrow', 'semantics', 'annotation', 'annotation-xml', 'mprescripts', 'none']);
215
+ const text = freeze(['#text']);
216
+
217
+ const html = freeze(['accept', 'action', 'align', 'alt', 'autocapitalize', 'autocomplete', 'autopictureinpicture', 'autoplay', 'background', 'bgcolor', 'border', 'capture', 'cellpadding', 'cellspacing', 'checked', 'cite', 'class', 'clear', 'color', 'cols', 'colspan', 'controls', 'controlslist', 'coords', 'crossorigin', 'datetime', 'decoding', 'default', 'dir', 'disabled', 'disablepictureinpicture', 'disableremoteplayback', 'download', 'draggable', 'enctype', 'enterkeyhint', 'exportparts', 'face', 'for', 'headers', 'height', 'hidden', 'high', 'href', 'hreflang', 'id', 'inert', 'inputmode', 'integrity', 'ismap', 'kind', 'label', 'lang', 'list', 'loading', 'loop', 'low', 'max', 'maxlength', 'media', 'method', 'min', 'minlength', 'multiple', 'muted', 'name', 'nonce', 'noshade', 'novalidate', 'nowrap', 'open', 'optimum', 'part', 'pattern', 'placeholder', 'playsinline', 'popover', 'popovertarget', 'popovertargetaction', 'poster', 'preload', 'pubdate', 'radiogroup', 'readonly', 'rel', 'required', 'rev', 'reversed', 'role', 'rows', 'rowspan', 'spellcheck', 'scope', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'srclang', 'start', 'src', 'srcset', 'step', 'style', 'summary', 'tabindex', 'title', 'translate', 'type', 'usemap', 'valign', 'value', 'width', 'wrap', 'xmlns', 'slot']);
218
+ const svg = freeze(['accent-height', 'accumulate', 'additive', 'alignment-baseline', 'amplitude', 'ascent', 'attributename', 'attributetype', 'azimuth', 'basefrequency', 'baseline-shift', 'begin', 'bias', 'by', 'class', 'clip', 'clippathunits', 'clip-path', 'clip-rule', 'color', 'color-interpolation', 'color-interpolation-filters', 'color-profile', 'color-rendering', 'cx', 'cy', 'd', 'dx', 'dy', 'diffuseconstant', 'direction', 'display', 'divisor', 'dur', 'edgemode', 'elevation', 'end', 'exponent', 'fill', 'fill-opacity', 'fill-rule', 'filter', 'filterunits', 'flood-color', 'flood-opacity', 'font-family', 'font-size', 'font-size-adjust', 'font-stretch', 'font-style', 'font-variant', 'font-weight', 'fx', 'fy', 'g1', 'g2', 'glyph-name', 'glyphref', 'gradientunits', 'gradienttransform', 'height', 'href', 'id', 'image-rendering', 'in', 'in2', 'intercept', 'k', 'k1', 'k2', 'k3', 'k4', 'kerning', 'keypoints', 'keysplines', 'keytimes', 'lang', 'lengthadjust', 'letter-spacing', 'kernelmatrix', 'kernelunitlength', 'lighting-color', 'local', 'marker-end', 'marker-mid', 'marker-start', 'markerheight', 'markerunits', 'markerwidth', 'maskcontentunits', 'maskunits', 'max', 'mask', 'mask-type', 'media', 'method', 'mode', 'min', 'name', 'numoctaves', 'offset', 'operator', 'opacity', 'order', 'orient', 'orientation', 'origin', 'overflow', 'paint-order', 'path', 'pathlength', 'patterncontentunits', 'patterntransform', 'patternunits', 'points', 'preservealpha', 'preserveaspectratio', 'primitiveunits', 'r', 'rx', 'ry', 'radius', 'refx', 'refy', 'repeatcount', 'repeatdur', 'restart', 'result', 'rotate', 'scale', 'seed', 'shape-rendering', 'slope', 'specularconstant', 'specularexponent', 'spreadmethod', 'startoffset', 'stddeviation', 'stitchtiles', 'stop-color', 'stop-opacity', 'stroke-dasharray', 'stroke-dashoffset', 'stroke-linecap', 'stroke-linejoin', 'stroke-miterlimit', 'stroke-opacity', 'stroke', 'stroke-width', 'style', 'surfacescale', 'systemlanguage', 'tabindex', 'tablevalues', 'targetx', 'targety', 'transform', 'transform-origin', 'text-anchor', 'text-decoration', 'text-rendering', 'textlength', 'type', 'u1', 'u2', 'unicode', 'values', 'viewbox', 'visibility', 'version', 'vert-adv-y', 'vert-origin-x', 'vert-origin-y', 'width', 'word-spacing', 'wrap', 'writing-mode', 'xchannelselector', 'ychannelselector', 'x', 'x1', 'x2', 'xmlns', 'y', 'y1', 'y2', 'z', 'zoomandpan']);
219
+ const mathMl = freeze(['accent', 'accentunder', 'align', 'bevelled', 'close', 'columnalign', 'columnlines', 'columnspacing', 'columnspan', 'denomalign', 'depth', 'dir', 'display', 'displaystyle', 'encoding', 'fence', 'frame', 'height', 'href', 'id', 'largeop', 'length', 'linethickness', 'lquote', 'lspace', 'mathbackground', 'mathcolor', 'mathsize', 'mathvariant', 'maxsize', 'minsize', 'movablelimits', 'notation', 'numalign', 'open', 'rowalign', 'rowlines', 'rowspacing', 'rowspan', 'rspace', 'rquote', 'scriptlevel', 'scriptminsize', 'scriptsizemultiplier', 'selection', 'separator', 'separators', 'stretchy', 'subscriptshift', 'supscriptshift', 'symmetric', 'voffset', 'width', 'xmlns']);
220
+ const xml = freeze(['xlink:href', 'xml:id', 'xlink:title', 'xml:space', 'xmlns:xlink']);
221
+
222
+ // eslint-disable-next-line unicorn/better-regex
223
+ const MUSTACHE_EXPR = seal(/\{\{[\w\W]*|[\w\W]*\}\}/gm); // Specify template detection regex for SAFE_FOR_TEMPLATES mode
224
+ const ERB_EXPR = seal(/<%[\w\W]*|[\w\W]*%>/gm);
225
+ const TMPLIT_EXPR = seal(/\$\{[\w\W]*/gm); // eslint-disable-line unicorn/better-regex
226
+ const DATA_ATTR = seal(/^data-[\-\w.\u00B7-\uFFFF]+$/); // eslint-disable-line no-useless-escape
227
+ const ARIA_ATTR = seal(/^aria-[\-\w]+$/); // eslint-disable-line no-useless-escape
228
+ const IS_ALLOWED_URI = seal(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i // eslint-disable-line no-useless-escape
229
+ );
230
+ const IS_SCRIPT_OR_DATA = seal(/^(?:\w+script|data):/i);
231
+ const ATTR_WHITESPACE = seal(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g // eslint-disable-line no-control-regex
232
+ );
233
+ const DOCTYPE_NAME = seal(/^html$/i);
234
+ const CUSTOM_ELEMENT = seal(/^[a-z][.\w]*(-[.\w]+)+$/i);
235
+
236
+ var EXPRESSIONS = /*#__PURE__*/Object.freeze({
237
+ __proto__: null,
238
+ ARIA_ATTR: ARIA_ATTR,
239
+ ATTR_WHITESPACE: ATTR_WHITESPACE,
240
+ CUSTOM_ELEMENT: CUSTOM_ELEMENT,
241
+ DATA_ATTR: DATA_ATTR,
242
+ DOCTYPE_NAME: DOCTYPE_NAME,
243
+ ERB_EXPR: ERB_EXPR,
244
+ IS_ALLOWED_URI: IS_ALLOWED_URI,
245
+ IS_SCRIPT_OR_DATA: IS_SCRIPT_OR_DATA,
246
+ MUSTACHE_EXPR: MUSTACHE_EXPR,
247
+ TMPLIT_EXPR: TMPLIT_EXPR
248
+ });
249
+
250
+ /* eslint-disable @typescript-eslint/indent */
251
+ // https://developer.mozilla.org/en-US/docs/Web/API/Node/nodeType
252
+ const NODE_TYPE = {
253
+ element: 1,
254
+ text: 3,
255
+ // Deprecated
256
+ progressingInstruction: 7,
257
+ comment: 8,
258
+ document: 9};
259
+ const getGlobal = function getGlobal() {
260
+ return typeof window === 'undefined' ? null : window;
261
+ };
262
+ /**
263
+ * Creates a no-op policy for internal use only.
264
+ * Don't export this function outside this module!
265
+ * @param trustedTypes The policy factory.
266
+ * @param purifyHostElement The Script element used to load DOMPurify (to determine policy name suffix).
267
+ * @return The policy created (or null, if Trusted Types
268
+ * are not supported or creating the policy failed).
269
+ */
270
+ const _createTrustedTypesPolicy = function _createTrustedTypesPolicy(trustedTypes, purifyHostElement) {
271
+ if (typeof trustedTypes !== 'object' || typeof trustedTypes.createPolicy !== 'function') {
272
+ return null;
273
+ }
274
+ // Allow the callers to control the unique policy name
275
+ // by adding a data-tt-policy-suffix to the script element with the DOMPurify.
276
+ // Policy creation with duplicate names throws in Trusted Types.
277
+ let suffix = null;
278
+ const ATTR_NAME = 'data-tt-policy-suffix';
279
+ if (purifyHostElement && purifyHostElement.hasAttribute(ATTR_NAME)) {
280
+ suffix = purifyHostElement.getAttribute(ATTR_NAME);
281
+ }
282
+ const policyName = 'dompurify' + (suffix ? '#' + suffix : '');
283
+ try {
284
+ return trustedTypes.createPolicy(policyName, {
285
+ createHTML(html) {
286
+ return html;
287
+ },
288
+ createScriptURL(scriptUrl) {
289
+ return scriptUrl;
290
+ }
291
+ });
292
+ } catch (_) {
293
+ // Policy creation failed (most likely another DOMPurify script has
294
+ // already run). Skip creating the policy, as this will only cause errors
295
+ // if TT are enforced.
296
+ console.warn('TrustedTypes policy ' + policyName + ' could not be created.');
297
+ return null;
298
+ }
299
+ };
300
+ const _createHooksMap = function _createHooksMap() {
301
+ return {
302
+ afterSanitizeAttributes: [],
303
+ afterSanitizeElements: [],
304
+ afterSanitizeShadowDOM: [],
305
+ beforeSanitizeAttributes: [],
306
+ beforeSanitizeElements: [],
307
+ beforeSanitizeShadowDOM: [],
308
+ uponSanitizeAttribute: [],
309
+ uponSanitizeElement: [],
310
+ uponSanitizeShadowNode: []
311
+ };
312
+ };
313
+ function createDOMPurify() {
314
+ let window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGlobal();
315
+ const DOMPurify = root => createDOMPurify(root);
316
+ DOMPurify.version = '3.4.0';
317
+ DOMPurify.removed = [];
318
+ if (!window || !window.document || window.document.nodeType !== NODE_TYPE.document || !window.Element) {
319
+ // Not running in a browser, provide a factory function
320
+ // so that you can pass your own Window
321
+ DOMPurify.isSupported = false;
322
+ return DOMPurify;
323
+ }
324
+ let {
325
+ document
326
+ } = window;
327
+ const originalDocument = document;
328
+ const currentScript = originalDocument.currentScript;
329
+ const {
330
+ DocumentFragment,
331
+ HTMLTemplateElement,
332
+ Node,
333
+ Element,
334
+ NodeFilter,
335
+ NamedNodeMap = window.NamedNodeMap || window.MozNamedAttrMap,
336
+ HTMLFormElement,
337
+ DOMParser,
338
+ trustedTypes
339
+ } = window;
340
+ const ElementPrototype = Element.prototype;
341
+ const cloneNode = lookupGetter(ElementPrototype, 'cloneNode');
342
+ const remove = lookupGetter(ElementPrototype, 'remove');
343
+ const getNextSibling = lookupGetter(ElementPrototype, 'nextSibling');
344
+ const getChildNodes = lookupGetter(ElementPrototype, 'childNodes');
345
+ const getParentNode = lookupGetter(ElementPrototype, 'parentNode');
346
+ // As per issue #47, the web-components registry is inherited by a
347
+ // new document created via createHTMLDocument. As per the spec
348
+ // (http://w3c.github.io/webcomponents/spec/custom/#creating-and-passing-registries)
349
+ // a new empty registry is used when creating a template contents owner
350
+ // document, so we use that as our parent document to ensure nothing
351
+ // is inherited.
352
+ if (typeof HTMLTemplateElement === 'function') {
353
+ const template = document.createElement('template');
354
+ if (template.content && template.content.ownerDocument) {
355
+ document = template.content.ownerDocument;
356
+ }
357
+ }
358
+ let trustedTypesPolicy;
359
+ let emptyHTML = '';
360
+ const {
361
+ implementation,
362
+ createNodeIterator,
363
+ createDocumentFragment,
364
+ getElementsByTagName
365
+ } = document;
366
+ const {
367
+ importNode
368
+ } = originalDocument;
369
+ let hooks = _createHooksMap();
370
+ /**
371
+ * Expose whether this browser supports running the full DOMPurify.
372
+ */
373
+ DOMPurify.isSupported = typeof entries === 'function' && typeof getParentNode === 'function' && implementation && implementation.createHTMLDocument !== undefined;
374
+ const {
375
+ MUSTACHE_EXPR,
376
+ ERB_EXPR,
377
+ TMPLIT_EXPR,
378
+ DATA_ATTR,
379
+ ARIA_ATTR,
380
+ IS_SCRIPT_OR_DATA,
381
+ ATTR_WHITESPACE,
382
+ CUSTOM_ELEMENT
383
+ } = EXPRESSIONS;
384
+ let {
385
+ IS_ALLOWED_URI: IS_ALLOWED_URI$1
386
+ } = EXPRESSIONS;
387
+ /**
388
+ * We consider the elements and attributes below to be safe. Ideally
389
+ * don't add any new ones but feel free to remove unwanted ones.
390
+ */
391
+ /* allowed element names */
392
+ let ALLOWED_TAGS = null;
393
+ const DEFAULT_ALLOWED_TAGS = addToSet({}, [...html$1, ...svg$1, ...svgFilters, ...mathMl$1, ...text]);
394
+ /* Allowed attribute names */
395
+ let ALLOWED_ATTR = null;
396
+ const DEFAULT_ALLOWED_ATTR = addToSet({}, [...html, ...svg, ...mathMl, ...xml]);
397
+ /*
398
+ * Configure how DOMPurify should handle custom elements and their attributes as well as customized built-in elements.
399
+ * @property {RegExp|Function|null} tagNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any custom elements)
400
+ * @property {RegExp|Function|null} attributeNameCheck one of [null, regexPattern, predicate]. Default: `null` (disallow any attributes not on the allow list)
401
+ * @property {boolean} allowCustomizedBuiltInElements allow custom elements derived from built-ins if they pass CUSTOM_ELEMENT_HANDLING.tagNameCheck. Default: `false`.
402
+ */
403
+ let CUSTOM_ELEMENT_HANDLING = Object.seal(create(null, {
404
+ tagNameCheck: {
405
+ writable: true,
406
+ configurable: false,
407
+ enumerable: true,
408
+ value: null
409
+ },
410
+ attributeNameCheck: {
411
+ writable: true,
412
+ configurable: false,
413
+ enumerable: true,
414
+ value: null
415
+ },
416
+ allowCustomizedBuiltInElements: {
417
+ writable: true,
418
+ configurable: false,
419
+ enumerable: true,
420
+ value: false
421
+ }
422
+ }));
423
+ /* Explicitly forbidden tags (overrides ALLOWED_TAGS/ADD_TAGS) */
424
+ let FORBID_TAGS = null;
425
+ /* Explicitly forbidden attributes (overrides ALLOWED_ATTR/ADD_ATTR) */
426
+ let FORBID_ATTR = null;
427
+ /* Config object to store ADD_TAGS/ADD_ATTR functions (when used as functions) */
428
+ const EXTRA_ELEMENT_HANDLING = Object.seal(create(null, {
429
+ tagCheck: {
430
+ writable: true,
431
+ configurable: false,
432
+ enumerable: true,
433
+ value: null
434
+ },
435
+ attributeCheck: {
436
+ writable: true,
437
+ configurable: false,
438
+ enumerable: true,
439
+ value: null
440
+ }
441
+ }));
442
+ /* Decide if ARIA attributes are okay */
443
+ let ALLOW_ARIA_ATTR = true;
444
+ /* Decide if custom data attributes are okay */
445
+ let ALLOW_DATA_ATTR = true;
446
+ /* Decide if unknown protocols are okay */
447
+ let ALLOW_UNKNOWN_PROTOCOLS = false;
448
+ /* Decide if self-closing tags in attributes are allowed.
449
+ * Usually removed due to a mXSS issue in jQuery 3.0 */
450
+ let ALLOW_SELF_CLOSE_IN_ATTR = true;
451
+ /* Output should be safe for common template engines.
452
+ * This means, DOMPurify removes data attributes, mustaches and ERB
453
+ */
454
+ let SAFE_FOR_TEMPLATES = false;
455
+ /* Output should be safe even for XML used within HTML and alike.
456
+ * This means, DOMPurify removes comments when containing risky content.
457
+ */
458
+ let SAFE_FOR_XML = true;
459
+ /* Decide if document with <html>... should be returned */
460
+ let WHOLE_DOCUMENT = false;
461
+ /* Track whether config is already set on this instance of DOMPurify. */
462
+ let SET_CONFIG = false;
463
+ /* Decide if all elements (e.g. style, script) must be children of
464
+ * document.body. By default, browsers might move them to document.head */
465
+ let FORCE_BODY = false;
466
+ /* Decide if a DOM `HTMLBodyElement` should be returned, instead of a html
467
+ * string (or a TrustedHTML object if Trusted Types are supported).
468
+ * If `WHOLE_DOCUMENT` is enabled a `HTMLHtmlElement` will be returned instead
469
+ */
470
+ let RETURN_DOM = false;
471
+ /* Decide if a DOM `DocumentFragment` should be returned, instead of a html
472
+ * string (or a TrustedHTML object if Trusted Types are supported) */
473
+ let RETURN_DOM_FRAGMENT = false;
474
+ /* Try to return a Trusted Type object instead of a string, return a string in
475
+ * case Trusted Types are not supported */
476
+ let RETURN_TRUSTED_TYPE = false;
477
+ /* Output should be free from DOM clobbering attacks?
478
+ * This sanitizes markups named with colliding, clobberable built-in DOM APIs.
479
+ */
480
+ let SANITIZE_DOM = true;
481
+ /* Achieve full DOM Clobbering protection by isolating the namespace of named
482
+ * properties and JS variables, mitigating attacks that abuse the HTML/DOM spec rules.
483
+ *
484
+ * HTML/DOM spec rules that enable DOM Clobbering:
485
+ * - Named Access on Window (§7.3.3)
486
+ * - DOM Tree Accessors (§3.1.5)
487
+ * - Form Element Parent-Child Relations (§4.10.3)
488
+ * - Iframe srcdoc / Nested WindowProxies (§4.8.5)
489
+ * - HTMLCollection (§4.2.10.2)
490
+ *
491
+ * Namespace isolation is implemented by prefixing `id` and `name` attributes
492
+ * with a constant string, i.e., `user-content-`
493
+ */
494
+ let SANITIZE_NAMED_PROPS = false;
495
+ const SANITIZE_NAMED_PROPS_PREFIX = 'user-content-';
496
+ /* Keep element content when removing element? */
497
+ let KEEP_CONTENT = true;
498
+ /* If a `Node` is passed to sanitize(), then performs sanitization in-place instead
499
+ * of importing it into a new Document and returning a sanitized copy */
500
+ let IN_PLACE = false;
501
+ /* Allow usage of profiles like html, svg and mathMl */
502
+ let USE_PROFILES = {};
503
+ /* Tags to ignore content of when KEEP_CONTENT is true */
504
+ let FORBID_CONTENTS = null;
505
+ const DEFAULT_FORBID_CONTENTS = addToSet({}, ['annotation-xml', 'audio', 'colgroup', 'desc', 'foreignobject', 'head', 'iframe', 'math', 'mi', 'mn', 'mo', 'ms', 'mtext', 'noembed', 'noframes', 'noscript', 'plaintext', 'script', 'style', 'svg', 'template', 'thead', 'title', 'video', 'xmp']);
506
+ /* Tags that are safe for data: URIs */
507
+ let DATA_URI_TAGS = null;
508
+ const DEFAULT_DATA_URI_TAGS = addToSet({}, ['audio', 'video', 'img', 'source', 'image', 'track']);
509
+ /* Attributes safe for values like "javascript:" */
510
+ let URI_SAFE_ATTRIBUTES = null;
511
+ const DEFAULT_URI_SAFE_ATTRIBUTES = addToSet({}, ['alt', 'class', 'for', 'id', 'label', 'name', 'pattern', 'placeholder', 'role', 'summary', 'title', 'value', 'style', 'xmlns']);
512
+ const MATHML_NAMESPACE = 'http://www.w3.org/1998/Math/MathML';
513
+ const SVG_NAMESPACE = 'http://www.w3.org/2000/svg';
514
+ const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
515
+ /* Document namespace */
516
+ let NAMESPACE = HTML_NAMESPACE;
517
+ let IS_EMPTY_INPUT = false;
518
+ /* Allowed XHTML+XML namespaces */
519
+ let ALLOWED_NAMESPACES = null;
520
+ const DEFAULT_ALLOWED_NAMESPACES = addToSet({}, [MATHML_NAMESPACE, SVG_NAMESPACE, HTML_NAMESPACE], stringToString);
521
+ let MATHML_TEXT_INTEGRATION_POINTS = addToSet({}, ['mi', 'mo', 'mn', 'ms', 'mtext']);
522
+ let HTML_INTEGRATION_POINTS = addToSet({}, ['annotation-xml']);
523
+ // Certain elements are allowed in both SVG and HTML
524
+ // namespace. We need to specify them explicitly
525
+ // so that they don't get erroneously deleted from
526
+ // HTML namespace.
527
+ const COMMON_SVG_AND_HTML_ELEMENTS = addToSet({}, ['title', 'style', 'font', 'a', 'script']);
528
+ /* Parsing of strict XHTML documents */
529
+ let PARSER_MEDIA_TYPE = null;
530
+ const SUPPORTED_PARSER_MEDIA_TYPES = ['application/xhtml+xml', 'text/html'];
531
+ const DEFAULT_PARSER_MEDIA_TYPE = 'text/html';
532
+ let transformCaseFunc = null;
533
+ /* Keep a reference to config to pass to hooks */
534
+ let CONFIG = null;
535
+ /* Ideally, do not touch anything below this line */
536
+ /* ______________________________________________ */
537
+ const formElement = document.createElement('form');
538
+ const isRegexOrFunction = function isRegexOrFunction(testValue) {
539
+ return testValue instanceof RegExp || testValue instanceof Function;
540
+ };
541
+ /**
542
+ * _parseConfig
543
+ *
544
+ * @param cfg optional config literal
545
+ */
546
+ // eslint-disable-next-line complexity
547
+ const _parseConfig = function _parseConfig() {
548
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
549
+ if (CONFIG && CONFIG === cfg) {
550
+ return;
551
+ }
552
+ /* Shield configuration object from tampering */
553
+ if (!cfg || typeof cfg !== 'object') {
554
+ cfg = {};
555
+ }
556
+ /* Shield configuration object from prototype pollution */
557
+ cfg = clone(cfg);
558
+ PARSER_MEDIA_TYPE =
559
+ // eslint-disable-next-line unicorn/prefer-includes
560
+ SUPPORTED_PARSER_MEDIA_TYPES.indexOf(cfg.PARSER_MEDIA_TYPE) === -1 ? DEFAULT_PARSER_MEDIA_TYPE : cfg.PARSER_MEDIA_TYPE;
561
+ // HTML tags and attributes are not case-sensitive, converting to lowercase. Keeping XHTML as is.
562
+ transformCaseFunc = PARSER_MEDIA_TYPE === 'application/xhtml+xml' ? stringToString : stringToLowerCase;
563
+ /* Set configuration parameters */
564
+ ALLOWED_TAGS = objectHasOwnProperty(cfg, 'ALLOWED_TAGS') ? addToSet({}, cfg.ALLOWED_TAGS, transformCaseFunc) : DEFAULT_ALLOWED_TAGS;
565
+ ALLOWED_ATTR = objectHasOwnProperty(cfg, 'ALLOWED_ATTR') ? addToSet({}, cfg.ALLOWED_ATTR, transformCaseFunc) : DEFAULT_ALLOWED_ATTR;
566
+ ALLOWED_NAMESPACES = objectHasOwnProperty(cfg, 'ALLOWED_NAMESPACES') ? addToSet({}, cfg.ALLOWED_NAMESPACES, stringToString) : DEFAULT_ALLOWED_NAMESPACES;
567
+ URI_SAFE_ATTRIBUTES = objectHasOwnProperty(cfg, 'ADD_URI_SAFE_ATTR') ? addToSet(clone(DEFAULT_URI_SAFE_ATTRIBUTES), cfg.ADD_URI_SAFE_ATTR, transformCaseFunc) : DEFAULT_URI_SAFE_ATTRIBUTES;
568
+ DATA_URI_TAGS = objectHasOwnProperty(cfg, 'ADD_DATA_URI_TAGS') ? addToSet(clone(DEFAULT_DATA_URI_TAGS), cfg.ADD_DATA_URI_TAGS, transformCaseFunc) : DEFAULT_DATA_URI_TAGS;
569
+ FORBID_CONTENTS = objectHasOwnProperty(cfg, 'FORBID_CONTENTS') ? addToSet({}, cfg.FORBID_CONTENTS, transformCaseFunc) : DEFAULT_FORBID_CONTENTS;
570
+ FORBID_TAGS = objectHasOwnProperty(cfg, 'FORBID_TAGS') ? addToSet({}, cfg.FORBID_TAGS, transformCaseFunc) : clone({});
571
+ FORBID_ATTR = objectHasOwnProperty(cfg, 'FORBID_ATTR') ? addToSet({}, cfg.FORBID_ATTR, transformCaseFunc) : clone({});
572
+ USE_PROFILES = objectHasOwnProperty(cfg, 'USE_PROFILES') ? cfg.USE_PROFILES : false;
573
+ ALLOW_ARIA_ATTR = cfg.ALLOW_ARIA_ATTR !== false; // Default true
574
+ ALLOW_DATA_ATTR = cfg.ALLOW_DATA_ATTR !== false; // Default true
575
+ ALLOW_UNKNOWN_PROTOCOLS = cfg.ALLOW_UNKNOWN_PROTOCOLS || false; // Default false
576
+ ALLOW_SELF_CLOSE_IN_ATTR = cfg.ALLOW_SELF_CLOSE_IN_ATTR !== false; // Default true
577
+ SAFE_FOR_TEMPLATES = cfg.SAFE_FOR_TEMPLATES || false; // Default false
578
+ SAFE_FOR_XML = cfg.SAFE_FOR_XML !== false; // Default true
579
+ WHOLE_DOCUMENT = cfg.WHOLE_DOCUMENT || false; // Default false
580
+ RETURN_DOM = cfg.RETURN_DOM || false; // Default false
581
+ RETURN_DOM_FRAGMENT = cfg.RETURN_DOM_FRAGMENT || false; // Default false
582
+ RETURN_TRUSTED_TYPE = cfg.RETURN_TRUSTED_TYPE || false; // Default false
583
+ FORCE_BODY = cfg.FORCE_BODY || false; // Default false
584
+ SANITIZE_DOM = cfg.SANITIZE_DOM !== false; // Default true
585
+ SANITIZE_NAMED_PROPS = cfg.SANITIZE_NAMED_PROPS || false; // Default false
586
+ KEEP_CONTENT = cfg.KEEP_CONTENT !== false; // Default true
587
+ IN_PLACE = cfg.IN_PLACE || false; // Default false
588
+ IS_ALLOWED_URI$1 = cfg.ALLOWED_URI_REGEXP || IS_ALLOWED_URI;
589
+ NAMESPACE = cfg.NAMESPACE || HTML_NAMESPACE;
590
+ MATHML_TEXT_INTEGRATION_POINTS = cfg.MATHML_TEXT_INTEGRATION_POINTS || MATHML_TEXT_INTEGRATION_POINTS;
591
+ HTML_INTEGRATION_POINTS = cfg.HTML_INTEGRATION_POINTS || HTML_INTEGRATION_POINTS;
592
+ CUSTOM_ELEMENT_HANDLING = cfg.CUSTOM_ELEMENT_HANDLING || create(null);
593
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck)) {
594
+ CUSTOM_ELEMENT_HANDLING.tagNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.tagNameCheck;
595
+ }
596
+ if (cfg.CUSTOM_ELEMENT_HANDLING && isRegexOrFunction(cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)) {
597
+ CUSTOM_ELEMENT_HANDLING.attributeNameCheck = cfg.CUSTOM_ELEMENT_HANDLING.attributeNameCheck;
598
+ }
599
+ if (cfg.CUSTOM_ELEMENT_HANDLING && typeof cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements === 'boolean') {
600
+ CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements = cfg.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements;
601
+ }
602
+ if (SAFE_FOR_TEMPLATES) {
603
+ ALLOW_DATA_ATTR = false;
604
+ }
605
+ if (RETURN_DOM_FRAGMENT) {
606
+ RETURN_DOM = true;
607
+ }
608
+ /* Parse profile info */
609
+ if (USE_PROFILES) {
610
+ ALLOWED_TAGS = addToSet({}, text);
611
+ ALLOWED_ATTR = create(null);
612
+ if (USE_PROFILES.html === true) {
613
+ addToSet(ALLOWED_TAGS, html$1);
614
+ addToSet(ALLOWED_ATTR, html);
615
+ }
616
+ if (USE_PROFILES.svg === true) {
617
+ addToSet(ALLOWED_TAGS, svg$1);
618
+ addToSet(ALLOWED_ATTR, svg);
619
+ addToSet(ALLOWED_ATTR, xml);
620
+ }
621
+ if (USE_PROFILES.svgFilters === true) {
622
+ addToSet(ALLOWED_TAGS, svgFilters);
623
+ addToSet(ALLOWED_ATTR, svg);
624
+ addToSet(ALLOWED_ATTR, xml);
625
+ }
626
+ if (USE_PROFILES.mathMl === true) {
627
+ addToSet(ALLOWED_TAGS, mathMl$1);
628
+ addToSet(ALLOWED_ATTR, mathMl);
629
+ addToSet(ALLOWED_ATTR, xml);
630
+ }
631
+ }
632
+ /* Always reset function-based ADD_TAGS / ADD_ATTR checks to prevent
633
+ * leaking across calls when switching from function to array config */
634
+ EXTRA_ELEMENT_HANDLING.tagCheck = null;
635
+ EXTRA_ELEMENT_HANDLING.attributeCheck = null;
636
+ /* Merge configuration parameters */
637
+ if (cfg.ADD_TAGS) {
638
+ if (typeof cfg.ADD_TAGS === 'function') {
639
+ EXTRA_ELEMENT_HANDLING.tagCheck = cfg.ADD_TAGS;
640
+ } else {
641
+ if (ALLOWED_TAGS === DEFAULT_ALLOWED_TAGS) {
642
+ ALLOWED_TAGS = clone(ALLOWED_TAGS);
643
+ }
644
+ addToSet(ALLOWED_TAGS, cfg.ADD_TAGS, transformCaseFunc);
645
+ }
646
+ }
647
+ if (cfg.ADD_ATTR) {
648
+ if (typeof cfg.ADD_ATTR === 'function') {
649
+ EXTRA_ELEMENT_HANDLING.attributeCheck = cfg.ADD_ATTR;
650
+ } else {
651
+ if (ALLOWED_ATTR === DEFAULT_ALLOWED_ATTR) {
652
+ ALLOWED_ATTR = clone(ALLOWED_ATTR);
653
+ }
654
+ addToSet(ALLOWED_ATTR, cfg.ADD_ATTR, transformCaseFunc);
655
+ }
656
+ }
657
+ if (cfg.ADD_URI_SAFE_ATTR) {
658
+ addToSet(URI_SAFE_ATTRIBUTES, cfg.ADD_URI_SAFE_ATTR, transformCaseFunc);
659
+ }
660
+ if (cfg.FORBID_CONTENTS) {
661
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
662
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
663
+ }
664
+ addToSet(FORBID_CONTENTS, cfg.FORBID_CONTENTS, transformCaseFunc);
665
+ }
666
+ if (cfg.ADD_FORBID_CONTENTS) {
667
+ if (FORBID_CONTENTS === DEFAULT_FORBID_CONTENTS) {
668
+ FORBID_CONTENTS = clone(FORBID_CONTENTS);
669
+ }
670
+ addToSet(FORBID_CONTENTS, cfg.ADD_FORBID_CONTENTS, transformCaseFunc);
671
+ }
672
+ /* Add #text in case KEEP_CONTENT is set to true */
673
+ if (KEEP_CONTENT) {
674
+ ALLOWED_TAGS['#text'] = true;
675
+ }
676
+ /* Add html, head and body to ALLOWED_TAGS in case WHOLE_DOCUMENT is true */
677
+ if (WHOLE_DOCUMENT) {
678
+ addToSet(ALLOWED_TAGS, ['html', 'head', 'body']);
679
+ }
680
+ /* Add tbody to ALLOWED_TAGS in case tables are permitted, see #286, #365 */
681
+ if (ALLOWED_TAGS.table) {
682
+ addToSet(ALLOWED_TAGS, ['tbody']);
683
+ delete FORBID_TAGS.tbody;
684
+ }
685
+ if (cfg.TRUSTED_TYPES_POLICY) {
686
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createHTML !== 'function') {
687
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');
688
+ }
689
+ if (typeof cfg.TRUSTED_TYPES_POLICY.createScriptURL !== 'function') {
690
+ throw typeErrorCreate('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');
691
+ }
692
+ // Overwrite existing TrustedTypes policy.
693
+ trustedTypesPolicy = cfg.TRUSTED_TYPES_POLICY;
694
+ // Sign local variables required by `sanitize`.
695
+ emptyHTML = trustedTypesPolicy.createHTML('');
696
+ } else {
697
+ // Uninitialized policy, attempt to initialize the internal dompurify policy.
698
+ if (trustedTypesPolicy === undefined) {
699
+ trustedTypesPolicy = _createTrustedTypesPolicy(trustedTypes, currentScript);
700
+ }
701
+ // If creating the internal policy succeeded sign internal variables.
702
+ if (trustedTypesPolicy !== null && typeof emptyHTML === 'string') {
703
+ emptyHTML = trustedTypesPolicy.createHTML('');
704
+ }
705
+ }
706
+ // Prevent further manipulation of configuration.
707
+ // Not available in IE8, Safari 5, etc.
708
+ if (freeze) {
709
+ freeze(cfg);
710
+ }
711
+ CONFIG = cfg;
712
+ };
713
+ /* Keep track of all possible SVG and MathML tags
714
+ * so that we can perform the namespace checks
715
+ * correctly. */
716
+ const ALL_SVG_TAGS = addToSet({}, [...svg$1, ...svgFilters, ...svgDisallowed]);
717
+ const ALL_MATHML_TAGS = addToSet({}, [...mathMl$1, ...mathMlDisallowed]);
718
+ /**
719
+ * @param element a DOM element whose namespace is being checked
720
+ * @returns Return false if the element has a
721
+ * namespace that a spec-compliant parser would never
722
+ * return. Return true otherwise.
723
+ */
724
+ const _checkValidNamespace = function _checkValidNamespace(element) {
725
+ let parent = getParentNode(element);
726
+ // In JSDOM, if we're inside shadow DOM, then parentNode
727
+ // can be null. We just simulate parent in this case.
728
+ if (!parent || !parent.tagName) {
729
+ parent = {
730
+ namespaceURI: NAMESPACE,
731
+ tagName: 'template'
732
+ };
733
+ }
734
+ const tagName = stringToLowerCase(element.tagName);
735
+ const parentTagName = stringToLowerCase(parent.tagName);
736
+ if (!ALLOWED_NAMESPACES[element.namespaceURI]) {
737
+ return false;
738
+ }
739
+ if (element.namespaceURI === SVG_NAMESPACE) {
740
+ // The only way to switch from HTML namespace to SVG
741
+ // is via <svg>. If it happens via any other tag, then
742
+ // it should be killed.
743
+ if (parent.namespaceURI === HTML_NAMESPACE) {
744
+ return tagName === 'svg';
745
+ }
746
+ // The only way to switch from MathML to SVG is via`
747
+ // svg if parent is either <annotation-xml> or MathML
748
+ // text integration points.
749
+ if (parent.namespaceURI === MATHML_NAMESPACE) {
750
+ return tagName === 'svg' && (parentTagName === 'annotation-xml' || MATHML_TEXT_INTEGRATION_POINTS[parentTagName]);
751
+ }
752
+ // We only allow elements that are defined in SVG
753
+ // spec. All others are disallowed in SVG namespace.
754
+ return Boolean(ALL_SVG_TAGS[tagName]);
755
+ }
756
+ if (element.namespaceURI === MATHML_NAMESPACE) {
757
+ // The only way to switch from HTML namespace to MathML
758
+ // is via <math>. If it happens via any other tag, then
759
+ // it should be killed.
760
+ if (parent.namespaceURI === HTML_NAMESPACE) {
761
+ return tagName === 'math';
762
+ }
763
+ // The only way to switch from SVG to MathML is via
764
+ // <math> and HTML integration points
765
+ if (parent.namespaceURI === SVG_NAMESPACE) {
766
+ return tagName === 'math' && HTML_INTEGRATION_POINTS[parentTagName];
767
+ }
768
+ // We only allow elements that are defined in MathML
769
+ // spec. All others are disallowed in MathML namespace.
770
+ return Boolean(ALL_MATHML_TAGS[tagName]);
771
+ }
772
+ if (element.namespaceURI === HTML_NAMESPACE) {
773
+ // The only way to switch from SVG to HTML is via
774
+ // HTML integration points, and from MathML to HTML
775
+ // is via MathML text integration points
776
+ if (parent.namespaceURI === SVG_NAMESPACE && !HTML_INTEGRATION_POINTS[parentTagName]) {
777
+ return false;
778
+ }
779
+ if (parent.namespaceURI === MATHML_NAMESPACE && !MATHML_TEXT_INTEGRATION_POINTS[parentTagName]) {
780
+ return false;
781
+ }
782
+ // We disallow tags that are specific for MathML
783
+ // or SVG and should never appear in HTML namespace
784
+ return !ALL_MATHML_TAGS[tagName] && (COMMON_SVG_AND_HTML_ELEMENTS[tagName] || !ALL_SVG_TAGS[tagName]);
785
+ }
786
+ // For XHTML and XML documents that support custom namespaces
787
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && ALLOWED_NAMESPACES[element.namespaceURI]) {
788
+ return true;
789
+ }
790
+ // The code should never reach this place (this means
791
+ // that the element somehow got namespace that is not
792
+ // HTML, SVG, MathML or allowed via ALLOWED_NAMESPACES).
793
+ // Return false just in case.
794
+ return false;
795
+ };
796
+ /**
797
+ * _forceRemove
798
+ *
799
+ * @param node a DOM node
800
+ */
801
+ const _forceRemove = function _forceRemove(node) {
802
+ arrayPush(DOMPurify.removed, {
803
+ element: node
804
+ });
805
+ try {
806
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove
807
+ getParentNode(node).removeChild(node);
808
+ } catch (_) {
809
+ remove(node);
810
+ }
811
+ };
812
+ /**
813
+ * _removeAttribute
814
+ *
815
+ * @param name an Attribute name
816
+ * @param element a DOM node
817
+ */
818
+ const _removeAttribute = function _removeAttribute(name, element) {
819
+ try {
820
+ arrayPush(DOMPurify.removed, {
821
+ attribute: element.getAttributeNode(name),
822
+ from: element
823
+ });
824
+ } catch (_) {
825
+ arrayPush(DOMPurify.removed, {
826
+ attribute: null,
827
+ from: element
828
+ });
829
+ }
830
+ element.removeAttribute(name);
831
+ // We void attribute values for unremovable "is" attributes
832
+ if (name === 'is') {
833
+ if (RETURN_DOM || RETURN_DOM_FRAGMENT) {
834
+ try {
835
+ _forceRemove(element);
836
+ } catch (_) {}
837
+ } else {
838
+ try {
839
+ element.setAttribute(name, '');
840
+ } catch (_) {}
841
+ }
842
+ }
843
+ };
844
+ /**
845
+ * _initDocument
846
+ *
847
+ * @param dirty - a string of dirty markup
848
+ * @return a DOM, filled with the dirty markup
849
+ */
850
+ const _initDocument = function _initDocument(dirty) {
851
+ /* Create a HTML document */
852
+ let doc = null;
853
+ let leadingWhitespace = null;
854
+ if (FORCE_BODY) {
855
+ dirty = '<remove></remove>' + dirty;
856
+ } else {
857
+ /* If FORCE_BODY isn't used, leading whitespace needs to be preserved manually */
858
+ const matches = stringMatch(dirty, /^[\r\n\t ]+/);
859
+ leadingWhitespace = matches && matches[0];
860
+ }
861
+ if (PARSER_MEDIA_TYPE === 'application/xhtml+xml' && NAMESPACE === HTML_NAMESPACE) {
862
+ // Root of XHTML doc must contain xmlns declaration (see https://www.w3.org/TR/xhtml1/normative.html#strict)
863
+ dirty = '<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>' + dirty + '</body></html>';
864
+ }
865
+ const dirtyPayload = trustedTypesPolicy ? trustedTypesPolicy.createHTML(dirty) : dirty;
866
+ /*
867
+ * Use the DOMParser API by default, fallback later if needs be
868
+ * DOMParser not work for svg when has multiple root element.
869
+ */
870
+ if (NAMESPACE === HTML_NAMESPACE) {
871
+ try {
872
+ doc = new DOMParser().parseFromString(dirtyPayload, PARSER_MEDIA_TYPE);
873
+ } catch (_) {}
874
+ }
875
+ /* Use createHTMLDocument in case DOMParser is not available */
876
+ if (!doc || !doc.documentElement) {
877
+ doc = implementation.createDocument(NAMESPACE, 'template', null);
878
+ try {
879
+ doc.documentElement.innerHTML = IS_EMPTY_INPUT ? emptyHTML : dirtyPayload;
880
+ } catch (_) {
881
+ // Syntax error if dirtyPayload is invalid xml
882
+ }
883
+ }
884
+ const body = doc.body || doc.documentElement;
885
+ if (dirty && leadingWhitespace) {
886
+ body.insertBefore(document.createTextNode(leadingWhitespace), body.childNodes[0] || null);
887
+ }
888
+ /* Work on whole document or just its body */
889
+ if (NAMESPACE === HTML_NAMESPACE) {
890
+ return getElementsByTagName.call(doc, WHOLE_DOCUMENT ? 'html' : 'body')[0];
891
+ }
892
+ return WHOLE_DOCUMENT ? doc.documentElement : body;
893
+ };
894
+ /**
895
+ * Creates a NodeIterator object that you can use to traverse filtered lists of nodes or elements in a document.
896
+ *
897
+ * @param root The root element or node to start traversing on.
898
+ * @return The created NodeIterator
899
+ */
900
+ const _createNodeIterator = function _createNodeIterator(root) {
901
+ return createNodeIterator.call(root.ownerDocument || root, root,
902
+ // eslint-disable-next-line no-bitwise
903
+ NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT | NodeFilter.SHOW_TEXT | NodeFilter.SHOW_PROCESSING_INSTRUCTION | NodeFilter.SHOW_CDATA_SECTION, null);
904
+ };
905
+ /**
906
+ * _isClobbered
907
+ *
908
+ * @param element element to check for clobbering attacks
909
+ * @return true if clobbered, false if safe
910
+ */
911
+ const _isClobbered = function _isClobbered(element) {
912
+ return element instanceof HTMLFormElement && (typeof element.nodeName !== 'string' || typeof element.textContent !== 'string' || typeof element.removeChild !== 'function' || !(element.attributes instanceof NamedNodeMap) || typeof element.removeAttribute !== 'function' || typeof element.setAttribute !== 'function' || typeof element.namespaceURI !== 'string' || typeof element.insertBefore !== 'function' || typeof element.hasChildNodes !== 'function');
913
+ };
914
+ /**
915
+ * Checks whether the given object is a DOM node.
916
+ *
917
+ * @param value object to check whether it's a DOM node
918
+ * @return true is object is a DOM node
919
+ */
920
+ const _isNode = function _isNode(value) {
921
+ return typeof Node === 'function' && value instanceof Node;
922
+ };
923
+ function _executeHooks(hooks, currentNode, data) {
924
+ arrayForEach(hooks, hook => {
925
+ hook.call(DOMPurify, currentNode, data, CONFIG);
926
+ });
927
+ }
928
+ /**
929
+ * _sanitizeElements
930
+ *
931
+ * @protect nodeName
932
+ * @protect textContent
933
+ * @protect removeChild
934
+ * @param currentNode to check for permission to exist
935
+ * @return true if node was killed, false if left alive
936
+ */
937
+ const _sanitizeElements = function _sanitizeElements(currentNode) {
938
+ let content = null;
939
+ /* Execute a hook if present */
940
+ _executeHooks(hooks.beforeSanitizeElements, currentNode, null);
941
+ /* Check if element is clobbered or can clobber */
942
+ if (_isClobbered(currentNode)) {
943
+ _forceRemove(currentNode);
944
+ return true;
945
+ }
946
+ /* Now let's check the element's type and name */
947
+ const tagName = transformCaseFunc(currentNode.nodeName);
948
+ /* Execute a hook if present */
949
+ _executeHooks(hooks.uponSanitizeElement, currentNode, {
950
+ tagName,
951
+ allowedTags: ALLOWED_TAGS
952
+ });
953
+ /* Detect mXSS attempts abusing namespace confusion */
954
+ if (SAFE_FOR_XML && currentNode.hasChildNodes() && !_isNode(currentNode.firstElementChild) && regExpTest(/<[/\w!]/g, currentNode.innerHTML) && regExpTest(/<[/\w!]/g, currentNode.textContent)) {
955
+ _forceRemove(currentNode);
956
+ return true;
957
+ }
958
+ /* Remove risky CSS construction leading to mXSS */
959
+ if (SAFE_FOR_XML && currentNode.namespaceURI === HTML_NAMESPACE && tagName === 'style' && _isNode(currentNode.firstElementChild)) {
960
+ _forceRemove(currentNode);
961
+ return true;
962
+ }
963
+ /* Remove any occurrence of processing instructions */
964
+ if (currentNode.nodeType === NODE_TYPE.progressingInstruction) {
965
+ _forceRemove(currentNode);
966
+ return true;
967
+ }
968
+ /* Remove any kind of possibly harmful comments */
969
+ if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
970
+ _forceRemove(currentNode);
971
+ return true;
972
+ }
973
+ /* Remove element if anything forbids its presence */
974
+ if (FORBID_TAGS[tagName] || !(EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function && EXTRA_ELEMENT_HANDLING.tagCheck(tagName)) && !ALLOWED_TAGS[tagName]) {
975
+ /* Check if we have a custom element to handle */
976
+ if (!FORBID_TAGS[tagName] && _isBasicCustomElement(tagName)) {
977
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, tagName)) {
978
+ return false;
979
+ }
980
+ if (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(tagName)) {
981
+ return false;
982
+ }
983
+ }
984
+ /* Keep content except for bad-listed elements */
985
+ if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
986
+ const parentNode = getParentNode(currentNode) || currentNode.parentNode;
987
+ const childNodes = getChildNodes(currentNode) || currentNode.childNodes;
988
+ if (childNodes && parentNode) {
989
+ const childCount = childNodes.length;
990
+ for (let i = childCount - 1; i >= 0; --i) {
991
+ const childClone = cloneNode(childNodes[i], true);
992
+ childClone.__removalCount = (currentNode.__removalCount || 0) + 1;
993
+ parentNode.insertBefore(childClone, getNextSibling(currentNode));
994
+ }
995
+ }
996
+ }
997
+ _forceRemove(currentNode);
998
+ return true;
999
+ }
1000
+ /* Check whether element has a valid namespace */
1001
+ if (currentNode instanceof Element && !_checkValidNamespace(currentNode)) {
1002
+ _forceRemove(currentNode);
1003
+ return true;
1004
+ }
1005
+ /* Make sure that older browsers don't get fallback-tag mXSS */
1006
+ if ((tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(/<\/no(script|embed|frames)/i, currentNode.innerHTML)) {
1007
+ _forceRemove(currentNode);
1008
+ return true;
1009
+ }
1010
+ /* Sanitize element content to be template-safe */
1011
+ if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
1012
+ /* Get the element's text content */
1013
+ content = currentNode.textContent;
1014
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1015
+ content = stringReplace(content, expr, ' ');
1016
+ });
1017
+ if (currentNode.textContent !== content) {
1018
+ arrayPush(DOMPurify.removed, {
1019
+ element: currentNode.cloneNode()
1020
+ });
1021
+ currentNode.textContent = content;
1022
+ }
1023
+ }
1024
+ /* Execute a hook if present */
1025
+ _executeHooks(hooks.afterSanitizeElements, currentNode, null);
1026
+ return false;
1027
+ };
1028
+ /**
1029
+ * _isValidAttribute
1030
+ *
1031
+ * @param lcTag Lowercase tag name of containing element.
1032
+ * @param lcName Lowercase attribute name.
1033
+ * @param value Attribute value.
1034
+ * @return Returns true if `value` is valid, otherwise false.
1035
+ */
1036
+ // eslint-disable-next-line complexity
1037
+ const _isValidAttribute = function _isValidAttribute(lcTag, lcName, value) {
1038
+ /* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */
1039
+ if (FORBID_ATTR[lcName]) {
1040
+ return false;
1041
+ }
1042
+ /* Make sure attribute cannot clobber */
1043
+ if (SANITIZE_DOM && (lcName === 'id' || lcName === 'name') && (value in document || value in formElement)) {
1044
+ return false;
1045
+ }
1046
+ /* Allow valid data-* attributes: At least one character after "-"
1047
+ (https://html.spec.whatwg.org/multipage/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes)
1048
+ XML-compatible (https://html.spec.whatwg.org/multipage/infrastructure.html#xml-compatible and http://www.w3.org/TR/xml/#d0e804)
1049
+ We don't need to check the value; it's always URI safe. */
1050
+ if (ALLOW_DATA_ATTR && !FORBID_ATTR[lcName] && regExpTest(DATA_ATTR, lcName)) ; else if (ALLOW_ARIA_ATTR && regExpTest(ARIA_ATTR, lcName)) ; else if (EXTRA_ELEMENT_HANDLING.attributeCheck instanceof Function && EXTRA_ELEMENT_HANDLING.attributeCheck(lcName, lcTag)) ; else if (!ALLOWED_ATTR[lcName] || FORBID_ATTR[lcName]) {
1051
+ if (
1052
+ // First condition does a very basic check if a) it's basically a valid custom element tagname AND
1053
+ // b) if the tagName passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1054
+ // and c) if the attribute name passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.attributeNameCheck
1055
+ _isBasicCustomElement(lcTag) && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, lcTag) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(lcTag)) && (CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.attributeNameCheck, lcName) || CUSTOM_ELEMENT_HANDLING.attributeNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.attributeNameCheck(lcName, lcTag)) ||
1056
+ // Alternative, second condition checks if it's an `is`-attribute, AND
1057
+ // the value passes whatever the user has configured for CUSTOM_ELEMENT_HANDLING.tagNameCheck
1058
+ lcName === 'is' && CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements && (CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOM_ELEMENT_HANDLING.tagNameCheck, value) || CUSTOM_ELEMENT_HANDLING.tagNameCheck instanceof Function && CUSTOM_ELEMENT_HANDLING.tagNameCheck(value))) ; else {
1059
+ return false;
1060
+ }
1061
+ /* Check value is safe. First, is attr inert? If so, is safe */
1062
+ } else if (URI_SAFE_ATTRIBUTES[lcName]) ; else if (regExpTest(IS_ALLOWED_URI$1, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if ((lcName === 'src' || lcName === 'xlink:href' || lcName === 'href') && lcTag !== 'script' && stringIndexOf(value, 'data:') === 0 && DATA_URI_TAGS[lcTag]) ; else if (ALLOW_UNKNOWN_PROTOCOLS && !regExpTest(IS_SCRIPT_OR_DATA, stringReplace(value, ATTR_WHITESPACE, ''))) ; else if (value) {
1063
+ return false;
1064
+ } else ;
1065
+ return true;
1066
+ };
1067
+ /**
1068
+ * _isBasicCustomElement
1069
+ * checks if at least one dash is included in tagName, and it's not the first char
1070
+ * for more sophisticated checking see https://github.com/sindresorhus/validate-element-name
1071
+ *
1072
+ * @param tagName name of the tag of the node to sanitize
1073
+ * @returns Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
1074
+ */
1075
+ const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1076
+ return tagName !== 'annotation-xml' && stringMatch(tagName, CUSTOM_ELEMENT);
1077
+ };
1078
+ /**
1079
+ * _sanitizeAttributes
1080
+ *
1081
+ * @protect attributes
1082
+ * @protect nodeName
1083
+ * @protect removeAttribute
1084
+ * @protect setAttribute
1085
+ *
1086
+ * @param currentNode to sanitize
1087
+ */
1088
+ const _sanitizeAttributes = function _sanitizeAttributes(currentNode) {
1089
+ /* Execute a hook if present */
1090
+ _executeHooks(hooks.beforeSanitizeAttributes, currentNode, null);
1091
+ const {
1092
+ attributes
1093
+ } = currentNode;
1094
+ /* Check if we have attributes; if not we might have a text node */
1095
+ if (!attributes || _isClobbered(currentNode)) {
1096
+ return;
1097
+ }
1098
+ const hookEvent = {
1099
+ attrName: '',
1100
+ attrValue: '',
1101
+ keepAttr: true,
1102
+ allowedAttributes: ALLOWED_ATTR,
1103
+ forceKeepAttr: undefined
1104
+ };
1105
+ let l = attributes.length;
1106
+ /* Go backwards over all attributes; safely remove bad ones */
1107
+ while (l--) {
1108
+ const attr = attributes[l];
1109
+ const {
1110
+ name,
1111
+ namespaceURI,
1112
+ value: attrValue
1113
+ } = attr;
1114
+ const lcName = transformCaseFunc(name);
1115
+ const initValue = attrValue;
1116
+ let value = name === 'value' ? initValue : stringTrim(initValue);
1117
+ /* Execute a hook if present */
1118
+ hookEvent.attrName = lcName;
1119
+ hookEvent.attrValue = value;
1120
+ hookEvent.keepAttr = true;
1121
+ hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
1122
+ _executeHooks(hooks.uponSanitizeAttribute, currentNode, hookEvent);
1123
+ value = hookEvent.attrValue;
1124
+ /* Full DOM Clobbering protection via namespace isolation,
1125
+ * Prefix id and name attributes with `user-content-`
1126
+ */
1127
+ if (SANITIZE_NAMED_PROPS && (lcName === 'id' || lcName === 'name')) {
1128
+ // Remove the attribute with this value
1129
+ _removeAttribute(name, currentNode);
1130
+ // Prefix the value and later re-create the attribute with the sanitized value
1131
+ value = SANITIZE_NAMED_PROPS_PREFIX + value;
1132
+ }
1133
+ /* Work around a security issue with comments inside attributes */
1134
+ if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i, value)) {
1135
+ _removeAttribute(name, currentNode);
1136
+ continue;
1137
+ }
1138
+ /* Make sure we cannot easily use animated hrefs, even if animations are allowed */
1139
+ if (lcName === 'attributename' && stringMatch(value, 'href')) {
1140
+ _removeAttribute(name, currentNode);
1141
+ continue;
1142
+ }
1143
+ /* Did the hooks approve of the attribute? */
1144
+ if (hookEvent.forceKeepAttr) {
1145
+ continue;
1146
+ }
1147
+ /* Did the hooks approve of the attribute? */
1148
+ if (!hookEvent.keepAttr) {
1149
+ _removeAttribute(name, currentNode);
1150
+ continue;
1151
+ }
1152
+ /* Work around a security issue in jQuery 3.0 */
1153
+ if (!ALLOW_SELF_CLOSE_IN_ATTR && regExpTest(/\/>/i, value)) {
1154
+ _removeAttribute(name, currentNode);
1155
+ continue;
1156
+ }
1157
+ /* Sanitize attribute content to be template-safe */
1158
+ if (SAFE_FOR_TEMPLATES) {
1159
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1160
+ value = stringReplace(value, expr, ' ');
1161
+ });
1162
+ }
1163
+ /* Is `value` valid for this attribute? */
1164
+ const lcTag = transformCaseFunc(currentNode.nodeName);
1165
+ if (!_isValidAttribute(lcTag, lcName, value)) {
1166
+ _removeAttribute(name, currentNode);
1167
+ continue;
1168
+ }
1169
+ /* Handle attributes that require Trusted Types */
1170
+ if (trustedTypesPolicy && typeof trustedTypes === 'object' && typeof trustedTypes.getAttributeType === 'function') {
1171
+ if (namespaceURI) ; else {
1172
+ switch (trustedTypes.getAttributeType(lcTag, lcName)) {
1173
+ case 'TrustedHTML':
1174
+ {
1175
+ value = trustedTypesPolicy.createHTML(value);
1176
+ break;
1177
+ }
1178
+ case 'TrustedScriptURL':
1179
+ {
1180
+ value = trustedTypesPolicy.createScriptURL(value);
1181
+ break;
1182
+ }
1183
+ }
1184
+ }
1185
+ }
1186
+ /* Handle invalid data-* attribute set by try-catching it */
1187
+ if (value !== initValue) {
1188
+ try {
1189
+ if (namespaceURI) {
1190
+ currentNode.setAttributeNS(namespaceURI, name, value);
1191
+ } else {
1192
+ /* Fallback to setAttribute() for browser-unrecognized namespaces e.g. "x-schema". */
1193
+ currentNode.setAttribute(name, value);
1194
+ }
1195
+ if (_isClobbered(currentNode)) {
1196
+ _forceRemove(currentNode);
1197
+ } else {
1198
+ arrayPop(DOMPurify.removed);
1199
+ }
1200
+ } catch (_) {
1201
+ _removeAttribute(name, currentNode);
1202
+ }
1203
+ }
1204
+ }
1205
+ /* Execute a hook if present */
1206
+ _executeHooks(hooks.afterSanitizeAttributes, currentNode, null);
1207
+ };
1208
+ /**
1209
+ * _sanitizeShadowDOM
1210
+ *
1211
+ * @param fragment to iterate over recursively
1212
+ */
1213
+ const _sanitizeShadowDOM2 = function _sanitizeShadowDOM(fragment) {
1214
+ let shadowNode = null;
1215
+ const shadowIterator = _createNodeIterator(fragment);
1216
+ /* Execute a hook if present */
1217
+ _executeHooks(hooks.beforeSanitizeShadowDOM, fragment, null);
1218
+ while (shadowNode = shadowIterator.nextNode()) {
1219
+ /* Execute a hook if present */
1220
+ _executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1221
+ /* Sanitize tags and elements */
1222
+ _sanitizeElements(shadowNode);
1223
+ /* Check attributes next */
1224
+ _sanitizeAttributes(shadowNode);
1225
+ /* Deep shadow DOM detected */
1226
+ if (shadowNode.content instanceof DocumentFragment) {
1227
+ _sanitizeShadowDOM2(shadowNode.content);
1228
+ }
1229
+ }
1230
+ /* Execute a hook if present */
1231
+ _executeHooks(hooks.afterSanitizeShadowDOM, fragment, null);
1232
+ };
1233
+ // eslint-disable-next-line complexity
1234
+ DOMPurify.sanitize = function (dirty) {
1235
+ let cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1236
+ let body = null;
1237
+ let importedNode = null;
1238
+ let currentNode = null;
1239
+ let returnNode = null;
1240
+ /* Make sure we have a string to sanitize.
1241
+ DO NOT return early, as this will return the wrong type if
1242
+ the user has requested a DOM object rather than a string */
1243
+ IS_EMPTY_INPUT = !dirty;
1244
+ if (IS_EMPTY_INPUT) {
1245
+ dirty = '<!-->';
1246
+ }
1247
+ /* Stringify, in case dirty is an object */
1248
+ if (typeof dirty !== 'string' && !_isNode(dirty)) {
1249
+ if (typeof dirty.toString === 'function') {
1250
+ dirty = dirty.toString();
1251
+ if (typeof dirty !== 'string') {
1252
+ throw typeErrorCreate('dirty is not a string, aborting');
1253
+ }
1254
+ } else {
1255
+ throw typeErrorCreate('toString is not a function');
1256
+ }
1257
+ }
1258
+ /* Return dirty HTML if DOMPurify cannot run */
1259
+ if (!DOMPurify.isSupported) {
1260
+ return dirty;
1261
+ }
1262
+ /* Assign config vars */
1263
+ if (!SET_CONFIG) {
1264
+ _parseConfig(cfg);
1265
+ }
1266
+ /* Clean up removed elements */
1267
+ DOMPurify.removed = [];
1268
+ /* Check if dirty is correctly typed for IN_PLACE */
1269
+ if (typeof dirty === 'string') {
1270
+ IN_PLACE = false;
1271
+ }
1272
+ if (IN_PLACE) {
1273
+ /* Do some early pre-sanitization to avoid unsafe root nodes */
1274
+ if (dirty.nodeName) {
1275
+ const tagName = transformCaseFunc(dirty.nodeName);
1276
+ if (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) {
1277
+ throw typeErrorCreate('root node is forbidden and cannot be sanitized in-place');
1278
+ }
1279
+ }
1280
+ } else if (dirty instanceof Node) {
1281
+ /* If dirty is a DOM element, append to an empty document to avoid
1282
+ elements being stripped by the parser */
1283
+ body = _initDocument('<!---->');
1284
+ importedNode = body.ownerDocument.importNode(dirty, true);
1285
+ if (importedNode.nodeType === NODE_TYPE.element && importedNode.nodeName === 'BODY') {
1286
+ /* Node is already a body, use as is */
1287
+ body = importedNode;
1288
+ } else if (importedNode.nodeName === 'HTML') {
1289
+ body = importedNode;
1290
+ } else {
1291
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1292
+ body.appendChild(importedNode);
1293
+ }
1294
+ } else {
1295
+ /* Exit directly if we have nothing to do */
1296
+ if (!RETURN_DOM && !SAFE_FOR_TEMPLATES && !WHOLE_DOCUMENT &&
1297
+ // eslint-disable-next-line unicorn/prefer-includes
1298
+ dirty.indexOf('<') === -1) {
1299
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(dirty) : dirty;
1300
+ }
1301
+ /* Initialize the document to work on */
1302
+ body = _initDocument(dirty);
1303
+ /* Check we have a DOM node from the data */
1304
+ if (!body) {
1305
+ return RETURN_DOM ? null : RETURN_TRUSTED_TYPE ? emptyHTML : '';
1306
+ }
1307
+ }
1308
+ /* Remove first element node (ours) if FORCE_BODY is set */
1309
+ if (body && FORCE_BODY) {
1310
+ _forceRemove(body.firstChild);
1311
+ }
1312
+ /* Get node iterator */
1313
+ const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
1314
+ /* Now start iterating over the created document */
1315
+ while (currentNode = nodeIterator.nextNode()) {
1316
+ /* Sanitize tags and elements */
1317
+ _sanitizeElements(currentNode);
1318
+ /* Check attributes next */
1319
+ _sanitizeAttributes(currentNode);
1320
+ /* Shadow DOM detected, sanitize it */
1321
+ if (currentNode.content instanceof DocumentFragment) {
1322
+ _sanitizeShadowDOM2(currentNode.content);
1323
+ }
1324
+ }
1325
+ /* If we sanitized `dirty` in-place, return it. */
1326
+ if (IN_PLACE) {
1327
+ return dirty;
1328
+ }
1329
+ /* Return sanitized string or DOM */
1330
+ if (RETURN_DOM) {
1331
+ if (SAFE_FOR_TEMPLATES) {
1332
+ body.normalize();
1333
+ let html = body.innerHTML;
1334
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1335
+ html = stringReplace(html, expr, ' ');
1336
+ });
1337
+ body.innerHTML = html;
1338
+ }
1339
+ if (RETURN_DOM_FRAGMENT) {
1340
+ returnNode = createDocumentFragment.call(body.ownerDocument);
1341
+ while (body.firstChild) {
1342
+ // eslint-disable-next-line unicorn/prefer-dom-node-append
1343
+ returnNode.appendChild(body.firstChild);
1344
+ }
1345
+ } else {
1346
+ returnNode = body;
1347
+ }
1348
+ if (ALLOWED_ATTR.shadowroot || ALLOWED_ATTR.shadowrootmode) {
1349
+ /*
1350
+ AdoptNode() is not used because internal state is not reset
1351
+ (e.g. the past names map of a HTMLFormElement), this is safe
1352
+ in theory but we would rather not risk another attack vector.
1353
+ The state that is cloned by importNode() is explicitly defined
1354
+ by the specs.
1355
+ */
1356
+ returnNode = importNode.call(originalDocument, returnNode, true);
1357
+ }
1358
+ return returnNode;
1359
+ }
1360
+ let serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
1361
+ /* Serialize doctype if allowed */
1362
+ if (WHOLE_DOCUMENT && ALLOWED_TAGS['!doctype'] && body.ownerDocument && body.ownerDocument.doctype && body.ownerDocument.doctype.name && regExpTest(DOCTYPE_NAME, body.ownerDocument.doctype.name)) {
1363
+ serializedHTML = '<!DOCTYPE ' + body.ownerDocument.doctype.name + '>\n' + serializedHTML;
1364
+ }
1365
+ /* Sanitize final string template-safe */
1366
+ if (SAFE_FOR_TEMPLATES) {
1367
+ arrayForEach([MUSTACHE_EXPR, ERB_EXPR, TMPLIT_EXPR], expr => {
1368
+ serializedHTML = stringReplace(serializedHTML, expr, ' ');
1369
+ });
1370
+ }
1371
+ return trustedTypesPolicy && RETURN_TRUSTED_TYPE ? trustedTypesPolicy.createHTML(serializedHTML) : serializedHTML;
1372
+ };
1373
+ DOMPurify.setConfig = function () {
1374
+ let cfg = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1375
+ _parseConfig(cfg);
1376
+ SET_CONFIG = true;
1377
+ };
1378
+ DOMPurify.clearConfig = function () {
1379
+ CONFIG = null;
1380
+ SET_CONFIG = false;
1381
+ };
1382
+ DOMPurify.isValidAttribute = function (tag, attr, value) {
1383
+ /* Initialize shared config vars if necessary. */
1384
+ if (!CONFIG) {
1385
+ _parseConfig({});
1386
+ }
1387
+ const lcTag = transformCaseFunc(tag);
1388
+ const lcName = transformCaseFunc(attr);
1389
+ return _isValidAttribute(lcTag, lcName, value);
1390
+ };
1391
+ DOMPurify.addHook = function (entryPoint, hookFunction) {
1392
+ if (typeof hookFunction !== 'function') {
1393
+ return;
1394
+ }
1395
+ arrayPush(hooks[entryPoint], hookFunction);
1396
+ };
1397
+ DOMPurify.removeHook = function (entryPoint, hookFunction) {
1398
+ if (hookFunction !== undefined) {
1399
+ const index = arrayLastIndexOf(hooks[entryPoint], hookFunction);
1400
+ return index === -1 ? undefined : arraySplice(hooks[entryPoint], index, 1)[0];
1401
+ }
1402
+ return arrayPop(hooks[entryPoint]);
1403
+ };
1404
+ DOMPurify.removeHooks = function (entryPoint) {
1405
+ hooks[entryPoint] = [];
1406
+ };
1407
+ DOMPurify.removeAllHooks = function () {
1408
+ hooks = _createHooksMap();
1409
+ };
1410
+ return DOMPurify;
1411
+ }
1412
+ var purify = createDOMPurify();
1413
+
1414
+ return purify;
1415
+
1416
+ }));
1417
+
1418
+ }(purify));
1419
+
1420
+ const purifier = purify.exports;
1421
+
1422
+ /* istanbul ignore next */
1423
+ const getCustomElementHandling = (allowICPrefix) => ({
1424
+ CUSTOM_ELEMENT_HANDLING: {
1425
+ tagNameCheck: (tagName) => (allowICPrefix && tagName.startsWith("ic-")) ||
1426
+ IC_CUSTOM_ALLOWED_COMPONENTS.includes(tagName),
1427
+ attributeNameCheck: /.*/,
1428
+ },
1429
+ });
1430
+ const sanitizeHTMLString = (html) => {
1431
+ return purifier.sanitize(html, getCustomElementHandling(true));
1432
+ };
1433
+ const sanitizeHTMLIconString = (html) => {
1434
+ return purifier.sanitize(html, getCustomElementHandling(false));
1435
+ };
1436
+
1437
+ const icMenuCss = "html.sc-ic-menu{line-height:1.15;-webkit-text-size-adjust:100%}body.sc-ic-menu{margin:0}main.sc-ic-menu{display:block}h1.sc-ic-menu{font-size:2em;margin:0.67em 0}hr.sc-ic-menu{box-sizing:content-box;height:0;overflow:visible}pre.sc-ic-menu{font-family:monospace, monospace;font-size:1em}a.sc-ic-menu{background-color:transparent}abbr[title].sc-ic-menu{border-bottom:none;text-decoration:underline;-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b.sc-ic-menu,strong.sc-ic-menu{font-weight:bolder}code.sc-ic-menu,kbd.sc-ic-menu,samp.sc-ic-menu{font-family:monospace, monospace;font-size:1em}small.sc-ic-menu{font-size:80%}sub.sc-ic-menu,sup.sc-ic-menu{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub.sc-ic-menu{bottom:-0.25em}sup.sc-ic-menu{top:-0.5em}img.sc-ic-menu{border-style:none}button.sc-ic-menu,input.sc-ic-menu,optgroup.sc-ic-menu,select.sc-ic-menu,textarea.sc-ic-menu{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button.sc-ic-menu,input.sc-ic-menu{overflow:visible}button.sc-ic-menu,select.sc-ic-menu{text-transform:none}button.sc-ic-menu,[type=\"button\"].sc-ic-menu,[type=\"reset\"].sc-ic-menu,[type=\"submit\"].sc-ic-menu{-webkit-appearance:button}button.sc-ic-menu::-moz-focus-inner,[type=\"button\"].sc-ic-menu::-moz-focus-inner,[type=\"reset\"].sc-ic-menu::-moz-focus-inner,[type=\"submit\"].sc-ic-menu::-moz-focus-inner{border-style:none;padding:0}button.sc-ic-menu:-moz-focusring,[type=\"button\"].sc-ic-menu:-moz-focusring,[type=\"reset\"].sc-ic-menu:-moz-focusring,[type=\"submit\"].sc-ic-menu:-moz-focusring{outline:1px dotted ButtonText}fieldset.sc-ic-menu{padding:0.35em 0.75em 0.625em}legend.sc-ic-menu{box-sizing:border-box;color:inherit;display:table;max-width:100%;padding:0;white-space:normal}progress.sc-ic-menu{vertical-align:baseline}textarea.sc-ic-menu{overflow:auto}[type=\"checkbox\"].sc-ic-menu,[type=\"radio\"].sc-ic-menu{box-sizing:border-box;padding:0}[type=\"number\"].sc-ic-menu::-webkit-inner-spin-button,[type=\"number\"].sc-ic-menu::-webkit-outer-spin-button{height:auto}[type=\"search\"].sc-ic-menu{-webkit-appearance:textfield;outline-offset:-2px}[type=\"search\"].sc-ic-menu::-webkit-search-decoration{-webkit-appearance:none}.sc-ic-menu::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}details.sc-ic-menu{display:block}summary.sc-ic-menu{display:list-item}template.sc-ic-menu{display:none}[hidden].sc-ic-menu{display:none}html.sc-ic-menu,body.sc-ic-menu,div.sc-ic-menu,span.sc-ic-menu,applet.sc-ic-menu,object.sc-ic-menu,iframe.sc-ic-menu,h1.sc-ic-menu,h2.sc-ic-menu,h3.sc-ic-menu,h4.sc-ic-menu,h5.sc-ic-menu,h6.sc-ic-menu,p.sc-ic-menu,blockquote.sc-ic-menu,pre.sc-ic-menu,a.sc-ic-menu,abbr.sc-ic-menu,acronym.sc-ic-menu,address.sc-ic-menu,big.sc-ic-menu,cite.sc-ic-menu,code.sc-ic-menu,del.sc-ic-menu,dfn.sc-ic-menu,em.sc-ic-menu,img.sc-ic-menu,ins.sc-ic-menu,kbd.sc-ic-menu,q.sc-ic-menu,s.sc-ic-menu,samp.sc-ic-menu,small.sc-ic-menu,strike.sc-ic-menu,strong.sc-ic-menu,sub.sc-ic-menu,sup.sc-ic-menu,tt.sc-ic-menu,var.sc-ic-menu,b.sc-ic-menu,u.sc-ic-menu,i.sc-ic-menu,center.sc-ic-menu,dl.sc-ic-menu,dt.sc-ic-menu,dd.sc-ic-menu,ol.sc-ic-menu,ul.sc-ic-menu,li.sc-ic-menu,fieldset.sc-ic-menu,form.sc-ic-menu,label.sc-ic-menu,legend.sc-ic-menu,table.sc-ic-menu,caption.sc-ic-menu,tbody.sc-ic-menu,tfoot.sc-ic-menu,thead.sc-ic-menu,tr.sc-ic-menu,th.sc-ic-menu,td.sc-ic-menu,article.sc-ic-menu,aside.sc-ic-menu,canvas.sc-ic-menu,details.sc-ic-menu,embed.sc-ic-menu,figure.sc-ic-menu,figcaption.sc-ic-menu,footer.sc-ic-menu,header.sc-ic-menu,hgroup.sc-ic-menu,menu.sc-ic-menu,nav.sc-ic-menu,output.sc-ic-menu,ruby.sc-ic-menu,section.sc-ic-menu,summary.sc-ic-menu,time.sc-ic-menu,mark.sc-ic-menu,audio.sc-ic-menu,video.sc-ic-menu{margin:0;padding:0;border:0;font-size:100%;font-style:inherit;vertical-align:baseline}@media (prefers-reduced-motion: no-preference){.ic-menu-open.sc-ic-menu-h .menu.sc-ic-menu{transition:max-height var(--ic-transition-duration-slow)}}.sc-ic-menu-h{max-height:0;width:var(--menu-width, var(--input-width, 20rem));color:var(--menu-item-text-color, var(--ic-menu-list-option-text-color));--ic-typography-color:var(\n --menu-item-text-color,\n var(--ic-menu-list-option-text-color)\n );background-color:var(\n --menu-bg-color,\n var(--ic-menu-list-option-background-color)\n );position:relative;z-index:var(--ic-z-index-menu);box-sizing:border-box;box-shadow:var(--ic-elevation-overlay);border-radius:var(--ic-border-radius)}.ic-menu-open.sc-ic-menu-h:not(.ic-menu-no-focus):focus-within{box-shadow:var(--ic-border-focus);outline:var(--ic-hc-focus-outline)}.ic-select-select-all-focused.sc-ic-menu-h{box-shadow:var(--ic-elevation-overlay) !important}#retry-button.sc-ic-menu::part(button){height:var(--ic-space-lg)}.small.sc-ic-menu #retry-button.sc-ic-menu::part(button){height:var(--ic-space-md)}.on-dialog.sc-ic-menu-h{inset:auto !important}.menu.sc-ic-menu{text-decoration:none;list-style-type:none;border-radius:1px;background-color:var(\n --menu-bg-color,\n var(--ic-menu-list-option-background-color)\n );visibility:hidden;max-height:0;overflow-y:hidden}.menu.sc-ic-menu:has(+.option-bar).sc-ic-menu{border-radius:0 0 1px 1px}.menu-scroll.sc-ic-menu{overflow-y:auto}.menu.sc-ic-menu:focus-visible{outline:none}.ic-menu-open.sc-ic-menu-h{max-height:none;display:flex;flex-direction:column-reverse;border:var(--ic-border-width) solid\n var(--menu-border-color, var(--ic-menu-border-color));transition:box-shadow var(--ic-easing-transition-fast)}.ic-menu-open.sc-ic-menu-h .menu.sc-ic-menu{visibility:visible;max-height:calc(var(--ic-space-xl) * 10 + var(--ic-space-xxxs))}.ic-menu-open.sc-ic-menu-h .option-bar.sc-ic-menu{visibility:visible}.ic-menu-open.sc-ic-menu-h .select-all-button.sc-ic-menu{display:block}.ic-menu-full-width.sc-ic-menu-h{width:100%}.option.sc-ic-menu{padding:var(--ic-space-xs) calc(var(--ic-space-xs) - var(--ic-space-1px));cursor:pointer;display:flex;align-items:center;gap:var(--ic-space-xs)}.loading-option.sc-ic-menu p.sc-ic-menu{margin-bottom:0 !important}.option.sc-ic-menu:not(.loading-option){justify-content:space-between}.ic-menu-small.sc-ic-menu-h .option.sc-ic-menu{padding:var(--ic-space-xxs) calc(var(--ic-space-xs) - var(--ic-space-1px))}.ic-menu-large.sc-ic-menu-h .option.sc-ic-menu{padding:var(--ic-space-sm) calc(var(--ic-space-xs) - var(--ic-space-1px))}.option.sc-ic-menu:last-child{border-radius:0 0 1px 1px}.sc-ic-menu:not(.menu:has(+.option-bar)).sc-ic-menu .option.sc-ic-menu:first-child{border-radius:1px 1px 0 0}.option.sc-ic-menu:not(.disabled-option):hover{background-color:var(--ic-menu-list-option-hover-background-color)}.option.sc-ic-menu:not(.disabled-option):active{background-color:var(--ic-menu-list-option-pressed-background-color)}.option.sc-ic-menu:focus-visible{outline:var(--ic-hc-focus-outline)}.option.sc-ic-menu:not(.disabled-option) .option-description.sc-ic-menu{--ic-typography-color:var(\n --menu-item-desc-text-color,\n var(--ic-menu-list-option-description-text-color)\n )}.option.sc-ic-menu .option-label.sc-ic-menu{display:flex;flex-direction:row;align-items:top}.option.sc-ic-menu .option-label.sc-ic-menu ic-typography.sc-ic-menu{max-width:100%;word-wrap:break-word}.option.sc-ic-menu .option-element.sc-ic-menu{margin-top:var(--ic-space-xxs)}.option.sc-ic-menu .option-icon.sc-ic-menu{height:var(--ic-space-md);width:var(--ic-space-md);margin-top:var(--ic-space-xxs);margin-right:var(--ic-space-xxs)}.option-text-container.sc-ic-menu{pointer-events:none;width:100%}.option-text-container.show-check-icon.sc-ic-menu{flex-grow:1}.option.loading-option.sc-ic-menu .option-text-container.sc-ic-menu{margin-left:calc(var(--ic-space-xs) + var(--ic-space-xxxs));color:var(--ic-menu-loading-list-option-text-color);--ic-typography-color:var(--ic-menu-loading-list-option-text-color)}.error-icon-svg.sc-ic-menu{height:var(--ic-space-md);width:var(--ic-space-md);fill:var(--ic-atoms-status-icon-error);align-self:center;display:flex;margin-right:calc(var(--ic-space-xxs) * 1.2)}.loading-error-info.sc-ic-menu{display:flex}.check-icon.sc-ic-menu{height:var(--ic-space-lg);min-width:var(--ic-space-lg);width:var(--ic-space-lg);pointer-events:none}.focused-option.sc-ic-menu .check-icon.sc-ic-menu *.sc-ic-menu{fill:currentcolor}.sc-ic-menu:first-child>.option-group-title.sc-ic-menu{padding:var(--ic-space-xs) calc(var(--ic-space-xs) - var(--ic-space-1px))\n var(--ic-space-xs)}.option-group-title.sc-ic-menu{padding:var(--ic-space-lg) calc(var(--ic-space-xs) - var(--ic-space-1px))\n var(--ic-space-xs);--ic-typography-color:var(--ic-menu-option-group-label-text-color)}.ic-menu-small.sc-ic-menu-h .option-group-title.sc-ic-menu{padding:var(--ic-space-sm) calc(var(--ic-space-xs) - var(--ic-space-1px))\n var(--ic-space-xxs)}.last-recommended-option.sc-ic-menu{border-bottom:var(--ic-menu-last-recommended-option-border)}.disabled-option.sc-ic-menu{color:var(--ic-atoms-list-option-text-disabled-light);--ic-typography-color:var(--ic-atoms-list-option-text-disabled-light);cursor:default;pointer-events:none}.focus-border.sc-ic-menu{border-radius:var(--ic-border-radius);padding:var(--ic-space-xxs);border:var(--ic-space-xxxs) dashed transparent;border-color:var(--ic-popover-menu-border);background-color:var(--ic-color-focus-inner) !important;--icon-height:auto}.focus-disabled.sc-ic-menu{background-color:var(--ic-color-focus-inner) !important;padding:calc(var(--ic-space-xs) - var(--ic-space-xxxs) - var(--ic-space-xxs))\n calc(\n var(--ic-space-xs) - var(--ic-space-1px) - var(--ic-space-xxxs) -\n var(--ic-space-xxs)\n )}.focused-option.sc-ic-menu,.focused-option.sc-ic-menu .option-description.sc-ic-menu{background-color:var(--ic-color-focus-inner) !important;color:var(--ic-atoms-list-option-text-focused-light) !important;--ic-typography-color:var(\n --ic-atoms-list-option-text-focused-light\n ) !important}.no-results.sc-ic-menu-h li.sc-ic-menu{cursor:no-drop}.no-results.sc-ic-menu-h li.sc-ic-menu:hover{background-color:transparent}.option-bar.sc-ic-menu{padding:var(--ic-space-xxs) var(--ic-space-xs);display:flex;align-items:center;justify-content:space-between;background-color:var(--ic-menu-option-bar-background-color);visibility:hidden;border-bottom:var(--ic-border-width) solid\n var(--ic-menu-option-bar-divider-color);border-radius:1px 1px 0 0}.option-bar.sc-ic-menu p.sc-ic-menu{margin-bottom:0 !important}.ic-menu-large.sc-ic-menu-h .option-bar.sc-ic-menu{padding:var(--ic-space-xs)}.select-all-button.sc-ic-menu{display:none}.select-all-button.sc-ic-menu:focus{z-index:calc(var(--ic-z-index-menu) + 1)}@media (forced-colors: active){.focused-option.sc-ic-menu{outline:none;border:0.125rem solid transparent}.disabled-option.sc-ic-menu{color:GrayText;--ic-typography-color:GrayText}}@media screen AND (max-width: 22rem){.sc-ic-menu-h{max-width:var(--menu-width, var(--input-width, 20rem));width:100%}}@media (prefers-reduced-motion: reduce){.ic-menu-open.sc-ic-menu-h{transition:none}}";
1438
+ const IcMenuStyle0 = icMenuCss;
1439
+
1440
+ const Menu = /*@__PURE__*/ proxyCustomElement(class Menu extends HTMLElement {
1441
+ constructor() {
1442
+ super();
1443
+ this.__registerHost();
1444
+ this.icClear = createEvent(this, "icClear", 7);
1445
+ this.menuKeyPress = createEvent(this, "menuKeyPress", 7);
1446
+ this.menuOptionId = createEvent(this, "menuOptionId", 7);
1447
+ this.menuOptionSelect = createEvent(this, "menuOptionSelect", 7);
1448
+ this.menuOptionSelectAll = createEvent(this, "menuOptionSelectAll", 7);
1449
+ this.menuStateChange = createEvent(this, "menuStateChange", 7);
1450
+ this.retryButtonClicked = createEvent(this, "retryButtonClicked", 7);
1451
+ this.timeoutBlur = createEvent(this, "timeoutBlur", 7);
1452
+ this.ungroupedOptionsSet = createEvent(this, "ungroupedOptionsSet", 7);
1453
+ this.ACTIVE_DESCENDANT = "aria-activedescendant";
1454
+ this.CLEAR_BUTTON_ID = "clear-button";
1455
+ this.SEARCH_BAR_TAG = "IC-SEARCH-BAR";
1456
+ this.disabledOptionSelected = false;
1457
+ this.hasPreviouslyBlurred = false;
1458
+ this.hasTimedOut = false;
1459
+ this.isLoading = false;
1460
+ this.lastOptionSelected = null; // Index of last option selected
1461
+ this.lastOptionFocused = null; // Index of last option focused
1462
+ this.multiOptionClicked = null;
1463
+ this.preventClickOpen = false; // Prevents menu re-opening immediately after it is closed on blur when clicking input.
1464
+ this.preventMenuFocus = false; // (When multiple) ensures focus moves straight to select all button from menu.
1465
+ this.shiftPressed = false;
1466
+ this.ungroupedOptions = [];
1467
+ this.focusFromSearchKeypress = false;
1468
+ this.initialOptionsListRender = false;
1469
+ this.keyboardNav = false;
1470
+ this.preventIncorrectTabOrder = false;
1471
+ this.popperProps = {};
1472
+ /**
1473
+ * Determines whether options manually set as values (by pressing 'Enter') when they receive focus using keyboard navigation.
1474
+ */
1475
+ this.activationType = "automatic";
1476
+ /**
1477
+ * @internal If `true`, autofocus will be applied on selected item when menu is open.
1478
+ */
1479
+ this.autofocusOnSelected = true;
1480
+ /**
1481
+ * If `true`, the menu will close when an option is selected.
1482
+ */
1483
+ this.closeOnSelect = true;
1484
+ /**
1485
+ * If `true`, the menu will fill the width of the container.
1486
+ */
1487
+ this.fullWidth = false;
1488
+ /**
1489
+ * The custom name for the label field for IcMenuOption.
1490
+ */
1491
+ this.labelField = "label";
1492
+ /**
1493
+ * @internal - flag to specify if menu is in a ic-select multiple.
1494
+ */
1495
+ this.multiSelect = false;
1496
+ /**
1497
+ * @internal - flag to specify if menu is in a searchable ic-select.
1498
+ */
1499
+ this.searchableSelect = false;
1500
+ /**
1501
+ * @internal - flag to specify if menu is in a ic-search-bar.
1502
+ */
1503
+ this.searchBar = false;
1504
+ /**
1505
+ * Specify the mode search bar uses to search. `navigation` allows for quick lookups of a set of values, `query` allows for more general searches.
1506
+ */
1507
+ this.searchMode = "navigation";
1508
+ /**
1509
+ * @internal If `true`, the icOptionSelect event will be fired on enter instead of ArrowUp and ArrowDown.
1510
+ */
1511
+ this.selectOnEnter = false;
1512
+ /**
1513
+ * The size of the menu.
1514
+ */
1515
+ this.size = "medium";
1516
+ /**
1517
+ * The custom name for the value field for IcMenuOption.
1518
+ */
1519
+ this.valueField = "value";
1520
+ /**
1521
+ * @internal If `true`, allows the menu to receive focus when opened.
1522
+ */
1523
+ this.allowMenuFocus = true;
1524
+ this.emitOptionId = (index) => {
1525
+ let option;
1526
+ if (index >= 0 && index < this.ungroupedOptions.length) {
1527
+ option = this.ungroupedOptions[index];
1528
+ }
1529
+ else if (this.ungroupedOptions.length > 0) {
1530
+ option =
1531
+ index < 0
1532
+ ? this.ungroupedOptions[this.ungroupedOptions.length - 1]
1533
+ : this.ungroupedOptions[0];
1534
+ }
1535
+ if (option) {
1536
+ this.menuOptionId.emit({
1537
+ optionId: this.getOptionId(option[this.valueField]),
1538
+ });
1539
+ }
1540
+ else {
1541
+ this.menuOptionId.emit({ optionId: undefined });
1542
+ }
1543
+ };
1544
+ this.handleClearListener = () => {
1545
+ this.optionHighlighted = "";
1546
+ };
1547
+ this.handleSubmitSearch = () => {
1548
+ const highlightedOptionIndex = this.options.findIndex((option) => option[this.valueField] === this.optionHighlighted);
1549
+ this.setInputValue(highlightedOptionIndex);
1550
+ };
1551
+ this.handleMenuChange = (open, focusInput) => {
1552
+ var _a;
1553
+ this.menuStateChange.emit({ open, focusInput });
1554
+ if (!open) {
1555
+ if (focusInput !== false) {
1556
+ if (this.allowMenuFocus) {
1557
+ (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.focus();
1558
+ }
1559
+ this.preventClickOpen = false;
1560
+ }
1561
+ // Reset optionHighlighted so previously highlighted option doesn't get reselected when Enter pressed
1562
+ if (this.multiSelect) {
1563
+ this.optionHighlighted = undefined;
1564
+ this.multiOptionClicked = null;
1565
+ }
1566
+ }
1567
+ };
1568
+ this.setNextOptionValue = (selectedOptionIndex) => {
1569
+ const nextIndex = selectedOptionIndex % this.ungroupedOptions.length;
1570
+ const nextOption = this.ungroupedOptions[nextIndex];
1571
+ this.setHighlightedOption(nextIndex);
1572
+ if (nextOption.disabled) {
1573
+ this.menuOptionId.emit({
1574
+ optionId: this.getOptionId(nextOption[this.valueField]),
1575
+ });
1576
+ }
1577
+ else {
1578
+ this.menuOptionSelect.emit({
1579
+ value: nextOption[this.valueField],
1580
+ optionId: this.getOptionId(nextOption[this.valueField]),
1581
+ });
1582
+ }
1583
+ };
1584
+ this.setPreviousOptionValue = (selectedOptionIndex) => {
1585
+ const prevIndex = selectedOptionIndex % this.ungroupedOptions.length;
1586
+ const prevOption = this.ungroupedOptions[prevIndex];
1587
+ this.setHighlightedOption(prevIndex);
1588
+ if (prevOption.disabled) {
1589
+ this.menuOptionId.emit({
1590
+ optionId: this.getOptionId(prevOption[this.valueField]),
1591
+ });
1592
+ }
1593
+ else {
1594
+ this.menuOptionSelect.emit({
1595
+ value: prevOption[this.valueField],
1596
+ optionId: this.getOptionId(prevOption[this.valueField]),
1597
+ });
1598
+ }
1599
+ };
1600
+ // Open menu when up or down arrow keys are pressed
1601
+ this.arrowBehaviour = (event) => {
1602
+ event.preventDefault();
1603
+ this.handleMenuChange(true);
1604
+ };
1605
+ this.getMenuOptions = () => this.searchBar ? this.options : this.ungroupedOptions;
1606
+ // Set option that is focused and so should show focus state
1607
+ this.setHighlightedOption = (highlightedIndex) => {
1608
+ const menuOptions = this.getMenuOptions();
1609
+ menuOptions[highlightedIndex] &&
1610
+ !menuOptions[highlightedIndex].timedOut &&
1611
+ (this.optionHighlighted =
1612
+ menuOptions[highlightedIndex][this.valueField] || undefined);
1613
+ };
1614
+ // Determines keyboard behaviour when selection is automatic
1615
+ // (i.e. you don't have to press Enter select an option - just focus on it)
1616
+ // and menu is closed
1617
+ this.autoSetInputValueKeyboardOpen = (event) => {
1618
+ const selectedOptionIndex = this.ungroupedOptions.findIndex((option) => option[this.valueField] === this.value);
1619
+ this.keyboardNav = false;
1620
+ switch (event.key) {
1621
+ case "ArrowDown": {
1622
+ this.keyboardNav = true;
1623
+ this.arrowBehaviour(event);
1624
+ const nextIndex = selectedOptionIndex < this.ungroupedOptions.length - 1
1625
+ ? selectedOptionIndex + 1
1626
+ : 0;
1627
+ this.setNextOptionValue(nextIndex);
1628
+ this.emitOptionId(nextIndex);
1629
+ break;
1630
+ }
1631
+ case "ArrowUp": {
1632
+ this.keyboardNav = true;
1633
+ this.arrowBehaviour(event);
1634
+ const prevIndex = selectedOptionIndex > 0
1635
+ ? selectedOptionIndex - 1
1636
+ : this.ungroupedOptions.length - 1;
1637
+ this.setPreviousOptionValue(prevIndex);
1638
+ this.emitOptionId(prevIndex);
1639
+ break;
1640
+ }
1641
+ case "Home": {
1642
+ this.keyboardNav = true;
1643
+ event.preventDefault();
1644
+ this.arrowBehaviour(event);
1645
+ this.setNextOptionValue(-1);
1646
+ this.emitOptionId(0);
1647
+ break;
1648
+ }
1649
+ case "End": {
1650
+ this.keyboardNav = true;
1651
+ event.preventDefault();
1652
+ this.arrowBehaviour(event);
1653
+ this.setPreviousOptionValue(this.ungroupedOptions.length);
1654
+ this.emitOptionId(this.ungroupedOptions.length - 1);
1655
+ break;
1656
+ }
1657
+ case " ":
1658
+ case "Enter":
1659
+ if (event.target.id !== this.CLEAR_BUTTON_ID) {
1660
+ this.handleMenuChange(true);
1661
+ }
1662
+ break;
1663
+ }
1664
+ };
1665
+ this.selectHighlightedOption = (options, highlightedOptionIndex) => {
1666
+ if (!this.isLoading && !this.hasTimedOut) {
1667
+ this.keyboardNav = true;
1668
+ }
1669
+ const isOpen = this.searchBar || this.searchableSelect || this.open;
1670
+ if (isOpen) {
1671
+ if (highlightedOptionIndex >= 0) {
1672
+ if (options[highlightedOptionIndex] !== undefined) {
1673
+ if (this.searchBar &&
1674
+ options[highlightedOptionIndex].disabled === true) {
1675
+ this.disabledOptionSelected = true;
1676
+ this.optionHighlighted = undefined;
1677
+ }
1678
+ else {
1679
+ this.setInputValue(highlightedOptionIndex);
1680
+ }
1681
+ }
1682
+ }
1683
+ else {
1684
+ this.setInputValue(highlightedOptionIndex);
1685
+ }
1686
+ }
1687
+ else {
1688
+ this.handleMenuChange(true);
1689
+ }
1690
+ };
1691
+ // Check if option is selected based on the index of the option
1692
+ this.isOptionSelected = (index) => {
1693
+ const menuOptions = this.getMenuOptions();
1694
+ return this.value
1695
+ ? this.value.includes(menuOptions[index][this.valueField])
1696
+ : false;
1697
+ };
1698
+ // Deselect currently selected options when shift pressed, but keep certain options selected
1699
+ this.deselectSelectedOptions = (optionsToKeepSelected) => {
1700
+ const menuOptions = this.getMenuOptions();
1701
+ if (this.value) {
1702
+ const selectedOptionIndexes = this.value.map((value) => {
1703
+ return menuOptions.findIndex((option) => option[this.valueField] === value);
1704
+ });
1705
+ // Call setInputValue (which toggles the selected state) on options that need to be deselected
1706
+ selectedOptionIndexes.forEach((index) => !optionsToKeepSelected.includes(index) && this.setInputValue(index));
1707
+ }
1708
+ };
1709
+ // Determines keyboard behaviour when selection is manual (i.e. when you have to press Enter to select an option)
1710
+ this.manualSetInputValueKeyboardOpen = (event) => {
1711
+ const menuOptions = this.getMenuOptions();
1712
+ // For preventing focus disappearing on currently focused option when Shift / Cmd / Ctrl pressed
1713
+ // (i.e. when user is likely in the middle of executing a keyboard combination to select options)
1714
+ const isKeyboardCombination = event.shiftKey || event.metaKey || event.ctrlKey;
1715
+ const highlightedOptionIndex = this.getOptionHighlightedIndex();
1716
+ const clickedMultiOptionIndex = menuOptions.findIndex((option) => option[this.valueField] === this.multiOptionClicked);
1717
+ const getOptionId = (index) => { var _a; return (_a = Array.from(this.host.querySelectorAll("li"))[index]) === null || _a === void 0 ? void 0 : _a.id; };
1718
+ // Space press should be equivalent to Enter when multi-select
1719
+ if (event.key === " " && this.multiSelect) {
1720
+ this.handleOptionSelect(event, highlightedOptionIndex);
1721
+ }
1722
+ else {
1723
+ switch (event.key) {
1724
+ case "ArrowDown":
1725
+ this.keyboardNav = true;
1726
+ this.arrowBehaviour(event);
1727
+ if (this.multiOptionClicked) {
1728
+ // Set focus to option last clicked
1729
+ // Prevents it resetting to the top of the menu when user switches to using keyboard
1730
+ this.setHighlightedOption(clickedMultiOptionIndex);
1731
+ this.multiOptionClicked = null;
1732
+ }
1733
+ else {
1734
+ this.handleSingleShiftSelect(event, highlightedOptionIndex, menuOptions);
1735
+ if (highlightedOptionIndex < menuOptions.length - 1) {
1736
+ this.setHighlightedOption(highlightedOptionIndex + 1);
1737
+ this.menuOptionId.emit({
1738
+ optionId: getOptionId(highlightedOptionIndex + 1),
1739
+ });
1740
+ this.handleSingleShiftSelect(event, highlightedOptionIndex + 1, menuOptions);
1741
+ }
1742
+ else {
1743
+ this.setHighlightedOption(0);
1744
+ this.menuOptionId.emit({
1745
+ optionId: getOptionId(0),
1746
+ });
1747
+ this.handleSingleShiftSelect(event, 0, menuOptions);
1748
+ }
1749
+ // Deselect currently selected options if arrow was pressed for first time after shift is held
1750
+ if (this.multiSelect && this.shiftPressed) {
1751
+ this.deselectSelectedOptions([
1752
+ highlightedOptionIndex,
1753
+ this.getOptionHighlightedIndex(),
1754
+ ]);
1755
+ this.shiftPressed = false;
1756
+ }
1757
+ }
1758
+ this.lastOptionFocused = this.getOptionHighlightedIndex();
1759
+ this.preventIncorrectTabOrder = false;
1760
+ this.focusFromSearchKeypress = false;
1761
+ break;
1762
+ case "ArrowUp":
1763
+ this.keyboardNav = true;
1764
+ this.arrowBehaviour(event);
1765
+ if (this.multiOptionClicked) {
1766
+ // Set focus to option last clicked
1767
+ // Prevents it resetting to the bottom of the menu when user switches to using keyboard
1768
+ this.setHighlightedOption(clickedMultiOptionIndex);
1769
+ this.multiOptionClicked = null;
1770
+ }
1771
+ else {
1772
+ this.handleSingleShiftSelect(event, highlightedOptionIndex, menuOptions);
1773
+ if (highlightedOptionIndex <= 0 ||
1774
+ highlightedOptionIndex > menuOptions.length + 1) {
1775
+ this.setHighlightedOption(menuOptions.length - 1);
1776
+ this.menuOptionId.emit({
1777
+ optionId: getOptionId(menuOptions.length - 1),
1778
+ });
1779
+ this.handleSingleShiftSelect(event, menuOptions.length - 1, menuOptions);
1780
+ }
1781
+ else {
1782
+ this.setHighlightedOption(highlightedOptionIndex - 1);
1783
+ this.menuOptionId.emit({
1784
+ optionId: getOptionId(highlightedOptionIndex - 1),
1785
+ });
1786
+ this.handleSingleShiftSelect(event, highlightedOptionIndex - 1, menuOptions);
1787
+ }
1788
+ // Deselect currently selected options if arrow was pressed for first time after shift is held
1789
+ if (this.multiSelect && this.shiftPressed) {
1790
+ this.deselectSelectedOptions([
1791
+ highlightedOptionIndex,
1792
+ this.getOptionHighlightedIndex(),
1793
+ ]);
1794
+ this.shiftPressed = false;
1795
+ }
1796
+ }
1797
+ this.lastOptionFocused = this.getOptionHighlightedIndex();
1798
+ this.preventIncorrectTabOrder = false;
1799
+ this.focusFromSearchKeypress = false;
1800
+ break;
1801
+ case "Home": {
1802
+ const startOptionIndex = 0;
1803
+ this.keyboardNav = true;
1804
+ event.preventDefault();
1805
+ this.arrowBehaviour(event);
1806
+ this.setHighlightedOption(startOptionIndex);
1807
+ this.menuOptionId.emit({
1808
+ optionId: getOptionId(startOptionIndex),
1809
+ });
1810
+ if (event.shiftKey && event.ctrlKey) {
1811
+ this.handleMultipleShiftSelect(startOptionIndex);
1812
+ }
1813
+ this.lastOptionFocused = startOptionIndex;
1814
+ this.lastOptionSelected = startOptionIndex;
1815
+ break;
1816
+ }
1817
+ case "End": {
1818
+ const endOptionIndex = menuOptions.length - 1;
1819
+ this.keyboardNav = true;
1820
+ event.preventDefault();
1821
+ this.arrowBehaviour(event);
1822
+ this.setHighlightedOption(endOptionIndex);
1823
+ this.menuOptionId.emit({
1824
+ optionId: getOptionId(endOptionIndex),
1825
+ });
1826
+ if (event.shiftKey && event.ctrlKey) {
1827
+ this.handleMultipleShiftSelect(endOptionIndex);
1828
+ }
1829
+ this.lastOptionFocused = endOptionIndex;
1830
+ this.lastOptionSelected = endOptionIndex;
1831
+ break;
1832
+ }
1833
+ case " ":
1834
+ if (!isKeyboardCombination) {
1835
+ this.keyboardNav = false;
1836
+ }
1837
+ if (this.searchBar || this.searchableSelect) {
1838
+ break;
1839
+ }
1840
+ else {
1841
+ if (event.target.id !== this.CLEAR_BUTTON_ID) {
1842
+ this.handleMenuChange(true);
1843
+ }
1844
+ }
1845
+ break;
1846
+ case "Enter":
1847
+ event.preventDefault();
1848
+ if (!isKeyboardCombination) {
1849
+ this.keyboardNav = false;
1850
+ }
1851
+ this.handleOptionSelect(event, highlightedOptionIndex);
1852
+ break;
1853
+ case "Escape":
1854
+ if (this.open) {
1855
+ event.stopImmediatePropagation();
1856
+ }
1857
+ this.handleMenuChange(false, !this.allowMenuFocus);
1858
+ this.menuOptionId.emit({ optionId: undefined });
1859
+ break;
1860
+ case "a":
1861
+ // Checks if Cmd (meta) key is pressed if Mac device (while excluding meta key on Windows)
1862
+ // Otherwise, if a different OS, checks Ctrl key
1863
+ if (this.multiSelect &&
1864
+ ((isMacDevice() && event.metaKey) ||
1865
+ (!isMacDevice() && event.ctrlKey))) {
1866
+ this.emitSelectAllEvents();
1867
+ this.lastOptionFocused = null;
1868
+ this.lastOptionSelected = null;
1869
+ }
1870
+ break;
1871
+ case "Shift":
1872
+ case "Tab":
1873
+ if (event.key === "Shift") {
1874
+ this.shiftPressed = true;
1875
+ }
1876
+ if (this.searchBar) {
1877
+ this.keyboardNav = true;
1878
+ }
1879
+ if (this.multiSelect) {
1880
+ if (this.open && !event.shiftKey && this.selectAllButton) {
1881
+ event.preventDefault();
1882
+ this.selectAllButton.focus(); // Move focus to select all button instead of focused option
1883
+ this.preventMenuFocus = true;
1884
+ this.preventClickOpen = true;
1885
+ this.optionHighlighted = undefined; // Stop any option focus states showing when focus moved to select all button
1886
+ }
1887
+ }
1888
+ else {
1889
+ this.preventIncorrectTabOrder = true;
1890
+ }
1891
+ break;
1892
+ default:
1893
+ if (!isKeyboardCombination) {
1894
+ this.keyboardNav = false;
1895
+ }
1896
+ this.focusOnSearchOrSelectInput(menuOptions, highlightedOptionIndex);
1897
+ }
1898
+ }
1899
+ };
1900
+ this.setInputValue = (highlightedOptionIndex) => {
1901
+ const menuOptions = this.getMenuOptions();
1902
+ if (menuOptions[highlightedOptionIndex] !== undefined &&
1903
+ !menuOptions[highlightedOptionIndex].disabled) {
1904
+ this.menuOptionSelect.emit({
1905
+ value: menuOptions[highlightedOptionIndex][this.valueField],
1906
+ });
1907
+ }
1908
+ if (this.closeOnSelect) {
1909
+ this.optionHighlighted = undefined;
1910
+ this.menuOptionId.emit({ optionId: undefined });
1911
+ }
1912
+ if (this.closeOnSelect) {
1913
+ if (!this.hasTimedOut) {
1914
+ this.handleMenuChange(false);
1915
+ }
1916
+ else {
1917
+ this.parentEl.setFocus();
1918
+ }
1919
+ }
1920
+ };
1921
+ this.handleOptionClick = (event) => {
1922
+ const { value, label } = event.target.dataset;
1923
+ if (this.multiSelect) {
1924
+ const menuOptions = this.getMenuOptions();
1925
+ const selectedOptionIndex = menuOptions.findIndex((option) => option[this.valueField] === value);
1926
+ this.handleOptionSelect(event, selectedOptionIndex, true);
1927
+ this.multiOptionClicked = value || null;
1928
+ }
1929
+ else {
1930
+ this.menuOptionSelect.emit({ value, label });
1931
+ this.handleMenuChange(false);
1932
+ }
1933
+ this.optionHighlighted = undefined;
1934
+ };
1935
+ this.handleRetry = () => {
1936
+ this.retryButtonClicked.emit({ value: this.value });
1937
+ };
1938
+ this.handleRetryKeyDown = (ev) => {
1939
+ if (ev.key === "Enter" || ev.key === " ") {
1940
+ ev.preventDefault();
1941
+ this.retryButtonClicked.emit({ value: this.value, keyPressed: ev.key });
1942
+ }
1943
+ };
1944
+ this.handleBlur = (event) => {
1945
+ var _a, _b, _c, _d;
1946
+ if (event.relatedTarget !== this.inputEl) {
1947
+ if (event.relatedTarget === this.selectAllButton) {
1948
+ (_a = this.menu) === null || _a === void 0 ? void 0 : _a.removeAttribute(this.ACTIVE_DESCENDANT);
1949
+ }
1950
+ if (!(((_b = this.menu) === null || _b === void 0 ? void 0 : _b.contains(event.relatedTarget)) ||
1951
+ event.relatedTarget === this.selectAllButton)) {
1952
+ this.handleMenuChange(false, this.hasPreviouslyBlurred);
1953
+ (_c = this.menu) === null || _c === void 0 ? void 0 : _c.removeAttribute(this.ACTIVE_DESCENDANT);
1954
+ this.lastOptionFocused = null;
1955
+ this.lastOptionSelected = null;
1956
+ }
1957
+ }
1958
+ else {
1959
+ this.handleMenuChange(false);
1960
+ this.preventClickOpen = true;
1961
+ (_d = this.menu) === null || _d === void 0 ? void 0 : _d.removeAttribute(this.ACTIVE_DESCENDANT);
1962
+ this.lastOptionFocused = null;
1963
+ this.lastOptionSelected = null;
1964
+ }
1965
+ if (!this.searchBar)
1966
+ this.hasPreviouslyBlurred = !!event.relatedTarget;
1967
+ };
1968
+ this.handleMouseDown = (event) => {
1969
+ event.preventDefault();
1970
+ };
1971
+ this.handleMenuKeyUp = (event) => {
1972
+ if (event.key === "Tab" && event.shiftKey) {
1973
+ this.preventClickOpen = false;
1974
+ }
1975
+ if (event.key === "Enter" && this.disabledOptionSelected) {
1976
+ this.disabledOptionSelected = false;
1977
+ event.stopImmediatePropagation();
1978
+ }
1979
+ if (event.key === "Shift") {
1980
+ this.shiftPressed = false;
1981
+ }
1982
+ };
1983
+ this.handleSelectAllClick = () => {
1984
+ var _a;
1985
+ this.keyboardNav = false;
1986
+ if (this.allowMenuFocus) {
1987
+ (_a = this.menu) === null || _a === void 0 ? void 0 : _a.focus();
1988
+ }
1989
+ this.emitSelectAllEvents();
1990
+ this.lastOptionFocused = null;
1991
+ this.lastOptionSelected = null;
1992
+ };
1993
+ this.handleSelectAllBlur = (event) => {
1994
+ var _a, _b, _c;
1995
+ this.host.classList.remove("ic-select-select-all-focused");
1996
+ const relatedTarget = event.relatedTarget;
1997
+ if (!((_a = this.menu) === null || _a === void 0 ? void 0 : _a.contains(relatedTarget)) &&
1998
+ !((_c = (_b = this.parentEl) === null || _b === void 0 ? void 0 : _b.shadowRoot) === null || _c === void 0 ? void 0 : _c.contains(relatedTarget))) {
1999
+ this.handleMenuChange(false, false);
2000
+ }
2001
+ };
2002
+ this.handleSelectAllFocus = () => {
2003
+ this.host.classList.add("ic-select-select-all-focused");
2004
+ this.lastOptionFocused = null;
2005
+ this.lastOptionSelected = null;
2006
+ };
2007
+ // Fix for Safari - select all button click was causing menu to close
2008
+ this.handleSelectAllMouseDown = (event) => {
2009
+ event.preventDefault();
2010
+ };
2011
+ // When shift key is being used to select contiguous options one by one on a multi-select
2012
+ // I.e. holding shift and pressing up and down arrow keys
2013
+ this.handleSingleShiftSelect = (event, optionToSelectIndex, options) => {
2014
+ if (this.multiSelect &&
2015
+ event.shiftKey &&
2016
+ !this.isOptionSelected(optionToSelectIndex)) {
2017
+ this.selectHighlightedOption(options, optionToSelectIndex);
2018
+ this.lastOptionSelected = optionToSelectIndex;
2019
+ }
2020
+ };
2021
+ // When shift key is being used to select multiple options at once on a multi-select
2022
+ // I.e. holding shift when selecting another option
2023
+ this.handleMultipleShiftSelect = (lastOptionInSelection, useFocusForSelection = false, firstOptionSelected = null) => {
2024
+ this.shiftPressed = false;
2025
+ const firstOptionInSelection = firstOptionSelected === null
2026
+ ? this.getFirstOptionInSelection(useFocusForSelection)
2027
+ : firstOptionSelected;
2028
+ if (firstOptionInSelection !== null) {
2029
+ const optionsToSelect = [];
2030
+ if (firstOptionInSelection < lastOptionInSelection) {
2031
+ for (let i = firstOptionInSelection; i < lastOptionInSelection + 1; i++) {
2032
+ optionsToSelect.push(i);
2033
+ }
2034
+ }
2035
+ else {
2036
+ for (let i = firstOptionInSelection; i > lastOptionInSelection - 1; i--) {
2037
+ optionsToSelect.push(i);
2038
+ }
2039
+ }
2040
+ optionsToSelect.forEach((optionIndex) => !this.isOptionSelected(optionIndex) && this.setInputValue(optionIndex));
2041
+ this.deselectSelectedOptions(optionsToSelect);
2042
+ }
2043
+ };
2044
+ this.handleOptionSelect = (event, optionIndex, useFocusForSelection = false) => {
2045
+ const menuOptions = this.getMenuOptions();
2046
+ const firstOptionInSelection = this.getFirstOptionInSelection(useFocusForSelection);
2047
+ if (event.shiftKey && firstOptionInSelection !== null) {
2048
+ this.handleMultipleShiftSelect(optionIndex, useFocusForSelection, firstOptionInSelection);
2049
+ }
2050
+ else {
2051
+ this.selectHighlightedOption(menuOptions, optionIndex);
2052
+ }
2053
+ this.lastOptionFocused = optionIndex;
2054
+ this.lastOptionSelected = optionIndex;
2055
+ };
2056
+ this.getFirstOptionInSelection = (useFocusForSelection) => {
2057
+ return useFocusForSelection && this.lastOptionFocused !== null
2058
+ ? this.lastOptionFocused
2059
+ : this.lastOptionSelected !== null
2060
+ ? this.lastOptionSelected
2061
+ : null;
2062
+ };
2063
+ this.emitSelectAllEvents = () => {
2064
+ var _a, _b;
2065
+ // Select all if there is either no value or not all options are selected
2066
+ // 'true' means select all, 'false' means clear all
2067
+ const enabledOptionsCount = this.ungroupedOptions.filter((option) => !option.disabled).length;
2068
+ this.menuOptionSelectAll.emit({
2069
+ select: !this.value || !(((_a = this.value) === null || _a === void 0 ? void 0 : _a.length) === enabledOptionsCount),
2070
+ });
2071
+ // Emit clear event if all non-disabled options are selected
2072
+ if (((_b = this.value) === null || _b === void 0 ? void 0 : _b.length) === enabledOptionsCount) {
2073
+ this.icClear.emit();
2074
+ }
2075
+ };
2076
+ this.emitMenuKeyPress = (isNavKey, key) => {
2077
+ this.menuKeyPress.emit({ isNavKey: isNavKey, key: key });
2078
+ };
2079
+ // Determines keyboard behaviour when selection is automatic
2080
+ // (i.e. you don't have to press Enter select an option - just focus on it)
2081
+ // and menu is focused
2082
+ this.autoSetValueOnMenuKeyDown = (event) => {
2083
+ var _a;
2084
+ event.cancelBubble = true;
2085
+ const highlightedOptionIndex = this.getOptionHighlightedIndex();
2086
+ const selectedOptionIndex = highlightedOptionIndex >= 0
2087
+ ? highlightedOptionIndex
2088
+ : this.ungroupedOptions.findIndex((option) => option[this.valueField] === this.value);
2089
+ const isSearchableSelect = !!this.inputEl && this.inputEl.tagName === "INPUT";
2090
+ this.keyboardNav = false;
2091
+ switch (event.key) {
2092
+ case " ":
2093
+ event.preventDefault();
2094
+ break;
2095
+ case "ArrowUp":
2096
+ if (!this.hasTimedOut) {
2097
+ event.preventDefault();
2098
+ const prevIndex = selectedOptionIndex > 0
2099
+ ? selectedOptionIndex - 1
2100
+ : this.ungroupedOptions.length - 1;
2101
+ this.setPreviousOptionValue(prevIndex);
2102
+ this.emitOptionId(prevIndex);
2103
+ this.keyboardNav = true;
2104
+ }
2105
+ break;
2106
+ case "ArrowDown":
2107
+ if (!this.hasTimedOut) {
2108
+ event.preventDefault();
2109
+ const nextIndex = selectedOptionIndex < this.ungroupedOptions.length - 1
2110
+ ? selectedOptionIndex + 1
2111
+ : 0;
2112
+ this.setNextOptionValue(nextIndex);
2113
+ this.emitOptionId(nextIndex);
2114
+ this.keyboardNav = true;
2115
+ }
2116
+ break;
2117
+ case "Home":
2118
+ this.menuOptionSelect.emit({
2119
+ value: this.ungroupedOptions[0][this.valueField],
2120
+ });
2121
+ this.emitOptionId(0);
2122
+ this.keyboardNav = true;
2123
+ break;
2124
+ case "End":
2125
+ this.menuOptionSelect.emit({
2126
+ value: this.ungroupedOptions[this.ungroupedOptions.length - 1][this.valueField],
2127
+ });
2128
+ this.emitOptionId(this.ungroupedOptions.length - 1);
2129
+ this.keyboardNav = true;
2130
+ break;
2131
+ case "Enter":
2132
+ !this.hasTimedOut && this.handleMenuChange(false);
2133
+ break;
2134
+ case "Escape":
2135
+ this.handleMenuChange(false, !this.allowMenuFocus);
2136
+ break;
2137
+ case "Backspace":
2138
+ break;
2139
+ case "Shift":
2140
+ break;
2141
+ default:
2142
+ if (isSearchableSelect && event.key !== "Tab" && !this.hasTimedOut) {
2143
+ (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.focus();
2144
+ }
2145
+ if (event.key.length === 1) {
2146
+ this.keyboardNav = true;
2147
+ }
2148
+ break;
2149
+ }
2150
+ this.emitMenuKeyPress(this.keyboardNav, event.key);
2151
+ };
2152
+ this.getOptionId = (value) => {
2153
+ return `${this.menuId}-${value}`;
2154
+ };
2155
+ this.getOptionAriaLabel = (option, parentOption) => {
2156
+ let ariaLabel = option[this.labelField];
2157
+ if (option.description) {
2158
+ ariaLabel = `${ariaLabel}, ${option.description}`;
2159
+ }
2160
+ if (option.element) {
2161
+ ariaLabel = `${ariaLabel}, ${option.element.ariaLabel}`;
2162
+ }
2163
+ if (parentOption) {
2164
+ return `${ariaLabel}, ${parentOption[this.labelField]} group`;
2165
+ }
2166
+ else {
2167
+ return ariaLabel;
2168
+ }
2169
+ };
2170
+ this.getSortedOptions = (options) => {
2171
+ let sorted = [];
2172
+ if (options.sort) {
2173
+ sorted = options.sort((optionA, optionB) => optionA.recommended && !optionB.recommended ? -1 : 0);
2174
+ }
2175
+ return sorted;
2176
+ };
2177
+ this.getOptionHighlightedIndex = () => {
2178
+ const menuOptions = this.getMenuOptions();
2179
+ return menuOptions.findIndex((option) => option[this.valueField] === this.optionHighlighted);
2180
+ };
2181
+ this.isManualMode = this.activationType === "manual";
2182
+ // Scroll to highlighted option, or selected option if no highlighted option (i.e. when the menu opens)
2183
+ this.scrollToSelected = () => {
2184
+ var _a;
2185
+ const menu = this.menu;
2186
+ const selectedOption = this.selectOnEnter || this.searchableSelect || this.multiSelect
2187
+ ? this.host.querySelector(`li[data-value="${this.optionHighlighted}"]`)
2188
+ : menu.querySelector(".option[aria-selected='true']");
2189
+ if (selectedOption) {
2190
+ const menuRect = menu.getBoundingClientRect();
2191
+ const optionRect = selectedOption.getBoundingClientRect();
2192
+ if (optionRect.top < menuRect.top) {
2193
+ menu.scrollTop -= menuRect.top - optionRect.top;
2194
+ }
2195
+ else if (optionRect.bottom > menuRect.bottom) {
2196
+ menu.scrollTop += optionRect.bottom - menuRect.bottom;
2197
+ }
2198
+ // 'aria-activedescendant' affects screen reader focus
2199
+ // https://www.w3.org/TR/2017/WD-wai-aria-practices-1.1-20170628/#kbd_focus_activedescendant
2200
+ (_a = this.menu) === null || _a === void 0 ? void 0 : _a.setAttribute(this.ACTIVE_DESCENDANT, selectedOption.id);
2201
+ if (this.allowMenuFocus) {
2202
+ selectedOption.focus();
2203
+ }
2204
+ }
2205
+ };
2206
+ // Set 'ungroupedOptions' variable and emit its value
2207
+ // - this is all the options with disabled options and group titles removed
2208
+ this.loadUngroupedOptions = () => {
2209
+ if (this.options.length > 0 && this.options.map) {
2210
+ this.options.map((option) => {
2211
+ if (option.children) {
2212
+ option.children.map((option) => !option.disabled && this.ungroupedOptions.push(option));
2213
+ }
2214
+ else {
2215
+ this.ungroupedOptions.push(option);
2216
+ }
2217
+ });
2218
+ }
2219
+ this.ungroupedOptions = this.getSortedOptions(this.ungroupedOptions);
2220
+ this.ungroupedOptionsSet.emit({ options: this.ungroupedOptions });
2221
+ };
2222
+ this.setMenuScrollbar = () => {
2223
+ var _a;
2224
+ let optionsHeight = 0;
2225
+ this.host
2226
+ .querySelectorAll(".option, .option-group-title")
2227
+ .forEach((option) => (optionsHeight += option.clientHeight));
2228
+ if (optionsHeight >= 320) {
2229
+ (_a = this.menu) === null || _a === void 0 ? void 0 : _a.classList.add("menu-scroll");
2230
+ }
2231
+ };
2232
+ this.handleTimeoutBlur = (ev) => {
2233
+ this.timeoutBlur.emit({ ev });
2234
+ };
2235
+ this.optionContent = (option, selected) => {
2236
+ var _a;
2237
+ const showCheckIcon = !!option[this.valueField] &&
2238
+ !!this.value &&
2239
+ selected &&
2240
+ ((_a = this.parentEl) === null || _a === void 0 ? void 0 : _a.tagName) !== this.SEARCH_BAR_TAG;
2241
+ return (h(Fragment, null, option.loading && h("ic-loading-indicator", { size: "icon" }), h("div", { class: {
2242
+ "option-text-container": true,
2243
+ "show-check-icon": showCheckIcon,
2244
+ "focus-border": (this.keyboardNav || this.initialOptionsListRender) &&
2245
+ option[this.valueField] === this.optionHighlighted &&
2246
+ !!option.disabled,
2247
+ } }, (option.icon || !option.hideLabel) && (h("div", { class: "option-label" }, option.icon && (h("div", { class: "option-icon", innerHTML: sanitizeHTMLIconString(option.icon), "aria-hidden": "true" })), !option.hideLabel && (h("ic-typography", { variant: "body", "aria-hidden": "true" }, option[this.labelField])))), option.description && (h("ic-typography", { id: `${this.getOptionId(option[this.valueField])}-description`, class: "option-description", variant: "caption", "aria-hidden": "true" }, h("p", null, option.description))), option.element && (h("div", { class: {
2248
+ "option-element": option.icon || !option.hideLabel || option.description,
2249
+ }, innerHTML: sanitizeHTMLString(option.element.component), "aria-hidden": "true" }))), showCheckIcon && (h("span", { class: "check-icon", innerHTML: checkIcon, "aria-hidden": "true" }))));
2250
+ };
2251
+ this.displayOption = (option, selected, index, parentOption) => {
2252
+ var _a;
2253
+ const { open, keyboardNav, isManualMode, initialOptionsListRender, optionHighlighted, options, } = this;
2254
+ return (h("li", Object.assign({ id: this.getOptionId(option[this.valueField]), class: {
2255
+ option: true,
2256
+ "focused-option": isManualMode
2257
+ ? (keyboardNav || initialOptionsListRender) &&
2258
+ option[this.valueField] === optionHighlighted &&
2259
+ !option.disabled
2260
+ : keyboardNav &&
2261
+ option[this.valueField] === optionHighlighted &&
2262
+ !option.disabled,
2263
+ "focus-disabled": isManualMode
2264
+ ? (keyboardNav || initialOptionsListRender) &&
2265
+ option[this.valueField] === optionHighlighted &&
2266
+ !!option.disabled
2267
+ : keyboardNav &&
2268
+ option[this.valueField] === optionHighlighted &&
2269
+ !!option.disabled,
2270
+ "last-recommended-option": !!(option.recommended &&
2271
+ options[index + 1] &&
2272
+ !options[index + 1].recommended),
2273
+ "disabled-option": !!option.disabled,
2274
+ "loading-option": !!option.loading,
2275
+ timeout: !!option.timedOut,
2276
+ }, role: "option", tabindex: !this.allowMenuFocus
2277
+ ? "-1"
2278
+ : open &&
2279
+ (selected || option[this.valueField] === optionHighlighted) &&
2280
+ keyboardNav
2281
+ ? "0"
2282
+ : "-1", "aria-label": this.getOptionAriaLabel(option, parentOption), "aria-selected": selected ? "true" : "false", "aria-disabled": option.disabled ? "true" : "false", onClick: !option.timedOut && !option.loading
2283
+ ? this.handleOptionClick
2284
+ : undefined, onBlur: this.handleBlur, onMouseDown: this.handleMouseDown, "data-value": option[this.valueField], "data-label": option[this.labelField] }, ((_a = option.htmlProps) !== null && _a !== void 0 ? _a : {})), option.timedOut ? (h(Fragment, null, h("div", { class: "loading-error-info" }, h("svg", { class: "error-icon-svg", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 24 24", fill: "#000000" }, h("title", null, "Error"), h("g", null, h("path", { d: "M8.77 3L3.5 8.27V15.73L8.77 21H16.23L21.5 15.73V8.27L16.23 3M8.91 7L12.5 10.59L16.09 7L17.5 8.41L13.91 12L17.5 15.59L16.09 17L12.5 13.41L8.91 17L7.5 15.59L11.09 12L7.5 8.41" }))), h("ic-typography", { variant: "label" }, option[this.labelField])), h("ic-button", { size: "small", variant: "tertiary", onClick: this.handleRetry, onKeyDown: this.handleRetryKeyDown, onBlur: this.handleTimeoutBlur, id: "retry-button" }, "Retry"))) : (this.optionContent(option, selected))));
2285
+ };
2286
+ }
2287
+ watchOpenHandler() {
2288
+ if (!this.open && this.popperInstance) {
2289
+ this.popperInstance.destroy();
2290
+ this.popperInstance = null;
2291
+ }
2292
+ }
2293
+ watchOptionsHandler(newOptions) {
2294
+ this.hasTimedOut = newOptions.some((opt) => opt.timedOut);
2295
+ this.isLoading = newOptions.some((opt) => opt.loading);
2296
+ this.ungroupedOptions = [];
2297
+ this.loadUngroupedOptions();
2298
+ }
2299
+ connectedCallback() {
2300
+ if (this.searchBar) {
2301
+ if (this.searchMode === "navigation")
2302
+ this.setHighlightedOption(0);
2303
+ this.initialOptionsListRender = true;
2304
+ }
2305
+ }
2306
+ disconnectedCallback() {
2307
+ var _a, _b, _c;
2308
+ (_a = this.popperInstance) === null || _a === void 0 ? void 0 : _a.destroy();
2309
+ (_b = this.parentEl) === null || _b === void 0 ? void 0 : _b.removeEventListener("icClear", this.handleClearListener);
2310
+ (_c = this.parentEl) === null || _c === void 0 ? void 0 : _c.removeEventListener("icSubmitSearch", this.handleSubmitSearch);
2311
+ }
2312
+ componentWillLoad() {
2313
+ var _a, _b, _c, _d;
2314
+ this.loadUngroupedOptions();
2315
+ (_a = this.parentEl) === null || _a === void 0 ? void 0 : _a.addEventListener("icClear", this.handleClearListener);
2316
+ (_b = this.parentEl) === null || _b === void 0 ? void 0 : _b.addEventListener("icSubmitSearch", this.handleSubmitSearch);
2317
+ this.hasTimedOut = (_c = this.options) === null || _c === void 0 ? void 0 : _c.some((opt) => opt.timedOut);
2318
+ this.isLoading = (_d = this.options) === null || _d === void 0 ? void 0 : _d.some((opt) => opt.loading);
2319
+ }
2320
+ componentDidLoad() {
2321
+ if (this.searchBar &&
2322
+ this.parentEl.disableAutoFiltering) {
2323
+ this.focusFromSearchKeypress = true;
2324
+ }
2325
+ onComponentRequiredPropUndefined([
2326
+ { prop: this.open, propName: "open" },
2327
+ { prop: this.options, propName: "options" },
2328
+ { prop: this.menuId, propName: "menu-id" },
2329
+ { prop: this.inputLabel, propName: "input-label" },
2330
+ //NOTE: no check for value, input-el or anchor-el as otherwise get console errors on first load of select component
2331
+ ], "Menu");
2332
+ }
2333
+ componentDidUpdate() {
2334
+ const inputValueInOptions = this.options.some((option) => option[this.valueField] === this.value);
2335
+ if (this.menu &&
2336
+ this.open &&
2337
+ this.options.length !== 0 &&
2338
+ !this.preventMenuFocus) {
2339
+ if (this.value &&
2340
+ this.keyboardNav &&
2341
+ inputValueInOptions &&
2342
+ this.autofocusOnSelected &&
2343
+ !this.searchableSelect) {
2344
+ this.scrollToSelected();
2345
+ }
2346
+ else if (!!this.optionHighlighted &&
2347
+ !this.focusFromSearchKeypress &&
2348
+ !this.preventIncorrectTabOrder) {
2349
+ const highlightedEl = this.host.querySelector(`li[data-value="${this.optionHighlighted}"]`);
2350
+ if (highlightedEl) {
2351
+ this.menu.setAttribute(this.ACTIVE_DESCENDANT, highlightedEl.id);
2352
+ if (this.allowMenuFocus) {
2353
+ highlightedEl.focus();
2354
+ }
2355
+ }
2356
+ }
2357
+ else if (this.inputEl &&
2358
+ this.inputEl.tagName !== "INPUT" &&
2359
+ this.allowMenuFocus) {
2360
+ this.menu.focus();
2361
+ }
2362
+ }
2363
+ if (this.menu && this.open) {
2364
+ this.scrollToSelected();
2365
+ }
2366
+ this.preventMenuFocus = false;
2367
+ }
2368
+ componentDidRender() {
2369
+ if (this.open && !this.popperInstance && this.anchorEl) {
2370
+ this.initPopperJs(this.anchorEl);
2371
+ }
2372
+ if (this.open && !!this.options.length) {
2373
+ this.setMenuScrollbar();
2374
+ }
2375
+ }
2376
+ /**
2377
+ * @internal If menu is opened with the mouse, emit menuStateChange custom event.
2378
+ */
2379
+ async handleClickOpen() {
2380
+ if (!this.preventClickOpen) {
2381
+ this.menuStateChange.emit({ open: !this.open });
2382
+ this.keyboardNav = false;
2383
+ }
2384
+ this.preventClickOpen = false;
2385
+ }
2386
+ /**
2387
+ * Used alongside activationType
2388
+ * If menu is opened via keyboard navigation (i.e. Enter, ArrowUp or ArrowDown), emit optionSelect custom event.
2389
+ * @param {KeyboardEvent} event The keyboard event which is available when handleKeyboardOpen is invoked.
2390
+ */
2391
+ async handleKeyboardOpen(event) {
2392
+ if (this.activationType === "automatic") {
2393
+ this.autoSetInputValueKeyboardOpen(event);
2394
+ }
2395
+ else {
2396
+ this.manualSetInputValueKeyboardOpen(event);
2397
+ }
2398
+ }
2399
+ /**
2400
+ * Used alongside activationType
2401
+ * If menu is open and user navigates options via keyboard, emit optionSelect custom event.
2402
+ * @param {KeyboardEvent} event The keyboard event which is available when handleMenuKeydown is invoked.
2403
+ */
2404
+ async handleMenuKeyDown(event) {
2405
+ if (this.activationType === "automatic") {
2406
+ this.autoSetValueOnMenuKeyDown(event);
2407
+ }
2408
+ else if (this.activationType === "manual" && !this.searchBar) {
2409
+ this.manualSetInputValueKeyboardOpen(event);
2410
+ }
2411
+ }
2412
+ /**
2413
+ * @internal Used to highlight the first option in the menu.
2414
+ */
2415
+ async handleSetFirstOption() {
2416
+ this.setHighlightedOption(0);
2417
+ }
2418
+ /**
2419
+ * @internal Used to initialize popperJS with an anchor element.
2420
+ * 5/12/2023: Tested with Floating UI, however, discovered inconsistent
2421
+ * boundary behaviour so sticking with PopperJS.
2422
+ */
2423
+ async initPopperJs(anchor) {
2424
+ // Placements set to "-start" to accommodate for custom menu width - menu should always be aligned to the left
2425
+ this.popperInstance = createPopper(anchor, this.host, Object.assign({ placement: "bottom-start", modifiers: [
2426
+ {
2427
+ name: "offset",
2428
+ options: {
2429
+ offset: [0, 7],
2430
+ },
2431
+ },
2432
+ {
2433
+ name: "flip",
2434
+ options: {
2435
+ fallbackPlacements: ["top-start"],
2436
+ rootBoundary: "viewport",
2437
+ },
2438
+ },
2439
+ ] }, this.popperProps));
2440
+ }
2441
+ /**
2442
+ * @internal This method allows props to be added to the PopperJS createPopper instance outside of the menu
2443
+ * @param props object - createPopper props set externally
2444
+ */
2445
+ async setExternalPopperProps(props) {
2446
+ this.popperProps = props;
2447
+ }
2448
+ focusOnSearchOrSelectInput(menuOptions, highlightedOptionIndex) {
2449
+ if (!menuOptions[highlightedOptionIndex])
2450
+ return;
2451
+ if (this.searchBar) {
2452
+ this.parentEl.setFocus();
2453
+ if (this.searchMode === "navigation")
2454
+ this.setHighlightedOption(0);
2455
+ }
2456
+ if (this.searchableSelect) {
2457
+ this.parentEl.setFocus();
2458
+ }
2459
+ this.focusFromSearchKeypress = true;
2460
+ }
2461
+ render() {
2462
+ const { inputLabel, options, menuId, value, fullWidth, hasTimedOut, isLoading, size, open, inputEl, keyboardNav, parentEl, SEARCH_BAR_TAG, multiSelect, } = this;
2463
+ const enabledOptionsCount = this.ungroupedOptions.filter((option) => !option.disabled).length;
2464
+ const selectAllButtonText = `${(value === null || value === void 0 ? void 0 : value.length) === enabledOptionsCount ? "Clear" : "Select"} all`;
2465
+ const hasNoResults = this.host.classList.contains("no-results");
2466
+ return (h(Host, { key: 'f2126f99757d13606827ea1eac7c08b023b97bae', class: {
2467
+ "ic-menu-full-width": !!fullWidth,
2468
+ "ic-menu-no-focus": ((inputEl === null || inputEl === void 0 ? void 0 : inputEl.tagName) === "INPUT" &&
2469
+ (parentEl === null || parentEl === void 0 ? void 0 : parentEl.tagName) !== SEARCH_BAR_TAG) ||
2470
+ hasTimedOut ||
2471
+ isLoading,
2472
+ [`ic-menu-${size}`]: true,
2473
+ "ic-menu-open": open && options.length !== 0,
2474
+ "ic-menu-multiple": multiSelect,
2475
+ } }, options.length !== 0 && (h("ul", { key: '9b41a2c0ab9d6b08dca829db341614b248675050', id: menuId, class: "menu", role: "listbox", "aria-label": `${inputLabel} pop-up`, "aria-multiselectable": multiSelect ? "true" : "false", "aria-activedescendant": this.optionHighlighted
2476
+ ? this.getOptionId(this.optionHighlighted)
2477
+ : undefined, tabindex: !this.allowMenuFocus
2478
+ ? "-1"
2479
+ : open &&
2480
+ !keyboardNav &&
2481
+ ((inputEl === null || inputEl === void 0 ? void 0 : inputEl.tagName) !== "INPUT" ||
2482
+ (parentEl === null || parentEl === void 0 ? void 0 : parentEl.tagName) === SEARCH_BAR_TAG)
2483
+ ? "0"
2484
+ : "-1", ref: (el) => (this.menu = el), onKeyDown: this.handleMenuKeyDown, onKeyUp: this.handleMenuKeyUp, onBlur: this.handleBlur }, this.getSortedOptions(options).map((option, index) => {
2485
+ if (option.children) {
2486
+ if (option.children.length > 0) {
2487
+ return (h("div", null, h("ic-typography", { class: "option-group-title", role: "presentation", variant: "subtitle-small" }, h("p", null, option[this.labelField])), option.children.map((childOption) => childOption[this.labelField] &&
2488
+ this.displayOption(childOption, multiSelect
2489
+ ? value === null || value === void 0 ? void 0 : value.includes(childOption[this.valueField])
2490
+ : childOption[this.valueField] === value, index, option))));
2491
+ }
2492
+ else {
2493
+ return null;
2494
+ }
2495
+ }
2496
+ else {
2497
+ // Display option only if it has a label (rather than displaying an empty space)
2498
+ return (option[this.labelField] &&
2499
+ this.displayOption(option, multiSelect
2500
+ ? value === null || value === void 0 ? void 0 : value.includes(option[this.valueField])
2501
+ : option[this.valueField] === value, index));
2502
+ }
2503
+ }))), options.length !== 0 &&
2504
+ multiSelect &&
2505
+ !isLoading &&
2506
+ !hasTimedOut &&
2507
+ !hasNoResults && (h("div", { key: '7440008eccba1fc099d09ae3916e0d186686d59e', class: "option-bar" }, h("ic-typography", { key: '802bd46a5d028a541060eb4cc57c2c4607cb1b86' }, h("p", { key: '17a482e5bbff099b44550f9800980a649a319358' }, `${value ? value.length : 0}/${getOptionsWithoutGroupTitlesCount(this.options)} selected`)), h("ic-button", { key: '5aa400fd2be98bc038400b699c33bd2b1814cb5d', class: "select-all-button", "aria-label": `${selectAllButtonText} options for ${inputLabel}`, ref: (el) => (this.selectAllButton = el), variant: "tertiary", onClick: this.handleSelectAllClick, onMouseDown: this.handleSelectAllMouseDown, onBlur: this.handleSelectAllBlur, onFocus: this.handleSelectAllFocus, size: size === "small" ? "small" : "medium" }, selectAllButtonText)))));
2508
+ }
2509
+ get host() { return this; }
2510
+ static get watchers() { return {
2511
+ "open": ["watchOpenHandler"],
2512
+ "options": ["watchOptionsHandler"]
2513
+ }; }
2514
+ static get style() { return IcMenuStyle0; }
2515
+ }, [2, "ic-menu", {
2516
+ "activationType": [1, "activation-type"],
2517
+ "anchorEl": [16],
2518
+ "autofocusOnSelected": [4, "autofocus-on-selected"],
2519
+ "closeOnSelect": [4, "close-on-select"],
2520
+ "fullWidth": [4, "full-width"],
2521
+ "inputEl": [16],
2522
+ "inputLabel": [1, "input-label"],
2523
+ "labelField": [1, "label-field"],
2524
+ "menuId": [1, "menu-id"],
2525
+ "multiSelect": [4, "multi-select"],
2526
+ "open": [516],
2527
+ "parentEl": [16],
2528
+ "searchableSelect": [4, "searchable-select"],
2529
+ "searchBar": [4, "search-bar"],
2530
+ "searchMode": [1, "search-mode"],
2531
+ "selectOnEnter": [4, "select-on-enter"],
2532
+ "size": [1],
2533
+ "options": [16],
2534
+ "value": [1],
2535
+ "valueField": [1, "value-field"],
2536
+ "allowMenuFocus": [4, "allow-menu-focus"],
2537
+ "focusFromSearchKeypress": [32],
2538
+ "initialOptionsListRender": [32],
2539
+ "keyboardNav": [32],
2540
+ "optionHighlighted": [32],
2541
+ "preventIncorrectTabOrder": [32],
2542
+ "menuOptions": [32],
2543
+ "popperProps": [32],
2544
+ "handleClickOpen": [64],
2545
+ "handleKeyboardOpen": [64],
2546
+ "handleMenuKeyDown": [64],
2547
+ "handleSetFirstOption": [64],
2548
+ "initPopperJs": [64],
2549
+ "setExternalPopperProps": [64]
2550
+ }, undefined, {
2551
+ "open": ["watchOpenHandler"],
2552
+ "options": ["watchOptionsHandler"]
2553
+ }]);
2554
+ function defineCustomElement() {
2555
+ if (typeof customElements === "undefined") {
2556
+ return;
2557
+ }
2558
+ const components = ["ic-menu", "ic-button", "ic-loading-indicator", "ic-tooltip", "ic-typography"];
2559
+ components.forEach(tagName => { switch (tagName) {
2560
+ case "ic-menu":
2561
+ if (!customElements.get(tagName)) {
2562
+ customElements.define(tagName, Menu);
2563
+ }
2564
+ break;
2565
+ case "ic-button":
2566
+ if (!customElements.get(tagName)) {
2567
+ defineCustomElement$4();
2568
+ }
2569
+ break;
2570
+ case "ic-loading-indicator":
2571
+ if (!customElements.get(tagName)) {
2572
+ defineCustomElement$3();
2573
+ }
2574
+ break;
2575
+ case "ic-tooltip":
2576
+ if (!customElements.get(tagName)) {
2577
+ defineCustomElement$2();
2578
+ }
2579
+ break;
2580
+ case "ic-typography":
2581
+ if (!customElements.get(tagName)) {
2582
+ defineCustomElement$1();
2583
+ }
2584
+ break;
2585
+ } });
2586
+ }
2587
+
2588
+ export { Menu as M, defineCustomElement as d };
2589
+
2590
+ //# sourceMappingURL=ic-menu2.js.map