@swisspost/internet-header 1.13.10 → 1.13.11

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 (250) hide show
  1. package/dist/cjs/focus-trap.cjs.entry.js +1553 -0
  2. package/dist/cjs/{index-e9ddb87b.js → index-e67ee869.js} +323 -18
  3. package/dist/cjs/index.cjs.js +15 -15
  4. package/dist/cjs/{klp-widget.controller-209f3662.js → klp-widget.controller-14bfba32.js} +1 -2
  5. package/dist/cjs/{language.service-8320b331.js → language.service-5591951f.js} +1 -1
  6. package/dist/cjs/loader.cjs.js +2 -2
  7. package/dist/cjs/{post-internet-breadcrumbs-09c2485b.js → post-internet-breadcrumbs-cd00e828.js} +9 -583
  8. package/dist/cjs/{post-internet-footer-8c6e2179.js → post-internet-footer-451c6936.js} +9 -9
  9. package/dist/cjs/{post-internet-header-d7fbc29b.js → post-internet-header-ecbdbe86.js} +22 -22
  10. package/dist/cjs/{post-klp-login-widget-59fa70e2.js → post-klp-login-widget-4784e543.js} +6 -6
  11. package/dist/cjs/post-klp-login-widget.cjs.entry.js +5 -5
  12. package/dist/cjs/{post-language-switch-8b73236a.js → post-language-switch-7ee44d13.js} +6 -6
  13. package/dist/cjs/post-language-switch.cjs.entry.js +6 -6
  14. package/dist/cjs/{post-logo-5ebbdc72.js → post-logo-508c8b1e.js} +2 -2
  15. package/dist/cjs/post-logo.cjs.entry.js +3 -3
  16. package/dist/cjs/{post-main-navigation-ce12e638.js → post-main-navigation-9ae98522.js} +17 -18
  17. package/dist/cjs/post-main-navigation.cjs.entry.js +6 -6
  18. package/dist/cjs/{post-meta-navigation-0216753f.js → post-meta-navigation-72b92c2a.js} +2 -2
  19. package/dist/cjs/post-meta-navigation.cjs.entry.js +3 -3
  20. package/dist/cjs/post-search-690c4d32.js +596 -0
  21. package/dist/cjs/post-search.cjs.entry.js +6 -6
  22. package/dist/cjs/{post-skiplinks-29c1973b.js → post-skiplinks-608b9533.js} +5 -5
  23. package/dist/cjs/post-skiplinks.cjs.entry.js +5 -5
  24. package/dist/cjs/{store-aac36a39.js → store-bb0e8d2e.js} +1 -1
  25. package/dist/cjs/{svg-icon.component-c5427667.js → svg-icon.component-d7f2aceb.js} +1 -1
  26. package/dist/cjs/{svg-sprite.component-34a4da43.js → svg-sprite.component-004c728e.js} +1 -1
  27. package/dist/cjs/swisspost-internet-breadcrumbs.cjs.entry.js +6 -6
  28. package/dist/cjs/swisspost-internet-footer.cjs.entry.js +5 -5
  29. package/dist/cjs/swisspost-internet-header.cjs.entry.js +6 -6
  30. package/dist/cjs/swisspost-internet-header.cjs.js +3 -3
  31. package/dist/collection/collection-manifest.json +3 -2
  32. package/dist/collection/components/post-internet-breadcrumbs/components/overlay.component.js +1 -2
  33. package/dist/collection/components/post-internet-breadcrumbs/post-internet-breadcrumbs.css +1 -1
  34. package/dist/collection/components/post-internet-breadcrumbs/post-internet-breadcrumbs.js +2 -2
  35. package/dist/collection/components/post-internet-footer/components/post-footer-block-contact.component.js +2 -2
  36. package/dist/collection/components/post-internet-footer/post-internet-footer.js +2 -2
  37. package/dist/collection/components/post-internet-header/post-internet-header.js +2 -2
  38. package/dist/collection/components/post-klp-login-widget/klp-widget.controller.js +1 -2
  39. package/dist/collection/components/post-klp-login-widget/post-klp-login-widget.js +1 -1
  40. package/dist/collection/components/post-language-switch/components/post-language-switch-list.js +1 -1
  41. package/dist/collection/components/post-language-switch/post-language-switch.js +3 -3
  42. package/dist/collection/components/post-main-navigation/components/level-one-action.component.js +5 -5
  43. package/dist/collection/components/post-main-navigation/post-main-navigation.js +9 -10
  44. package/dist/collection/components/post-meta-navigation/post-meta-navigation.js +2 -2
  45. package/dist/collection/components/post-search/post-search.css +23 -15
  46. package/dist/collection/components/post-search/post-search.js +12 -7
  47. package/dist/collection/components/post-skiplinks/post-skiplinks.js +1 -1
  48. package/dist/collection/components/shared/focus-trap.js +78 -0
  49. package/dist/collection/services/search/coveo.service.js +1 -1
  50. package/dist/collection/services/search/parcel.service.js +2 -2
  51. package/dist/collection/services/search/places.service.js +2 -2
  52. package/dist/components/focus-trap.d.ts +11 -0
  53. package/dist/components/focus-trap.js +6 -0
  54. package/dist/components/focus-trap2.js +1568 -0
  55. package/dist/components/index.js +2 -0
  56. package/dist/components/klp-widget.controller.js +1 -2
  57. package/dist/components/post-klp-login-widget2.js +1 -1
  58. package/dist/components/post-language-switch2.js +1 -1
  59. package/dist/components/post-main-navigation2.js +12 -13
  60. package/dist/components/post-search2.js +17 -11
  61. package/dist/components/post-skiplinks2.js +1 -1
  62. package/dist/components/swisspost-internet-breadcrumbs.js +11 -579
  63. package/dist/components/swisspost-internet-footer.js +5 -5
  64. package/dist/components/swisspost-internet-header.js +24 -18
  65. package/dist/docs.json +99 -18
  66. package/dist/esm/focus-trap.entry.js +1549 -0
  67. package/dist/esm/{index-9deab2c6.js → index-607344a5.js} +323 -18
  68. package/dist/esm/index.js +15 -15
  69. package/dist/esm/{klp-widget.controller-099061a3.js → klp-widget.controller-b101390d.js} +1 -2
  70. package/dist/esm/{language.service-e186d7dd.js → language.service-2df27b6a.js} +1 -1
  71. package/dist/esm/loader.js +3 -3
  72. package/dist/esm/{post-internet-breadcrumbs-7ae97585.js → post-internet-breadcrumbs-d7f7f87f.js} +9 -583
  73. package/dist/esm/{post-internet-footer-c9b6481e.js → post-internet-footer-b4161a6c.js} +9 -9
  74. package/dist/esm/{post-internet-header-f7d3d57b.js → post-internet-header-8279d078.js} +22 -22
  75. package/dist/esm/{post-klp-login-widget-f138e519.js → post-klp-login-widget-58d9e3e2.js} +6 -6
  76. package/dist/esm/post-klp-login-widget.entry.js +5 -5
  77. package/dist/esm/{post-language-switch-313a6a5c.js → post-language-switch-85afcb97.js} +6 -6
  78. package/dist/esm/post-language-switch.entry.js +6 -6
  79. package/dist/esm/{post-logo-1e5668dc.js → post-logo-6ea4c487.js} +2 -2
  80. package/dist/esm/post-logo.entry.js +3 -3
  81. package/dist/esm/{post-main-navigation-45e3060f.js → post-main-navigation-9d539ab7.js} +17 -18
  82. package/dist/esm/post-main-navigation.entry.js +6 -6
  83. package/dist/esm/{post-meta-navigation-01dc595f.js → post-meta-navigation-895bef11.js} +2 -2
  84. package/dist/esm/post-meta-navigation.entry.js +3 -3
  85. package/dist/esm/post-search-6e306c06.js +594 -0
  86. package/dist/esm/post-search.entry.js +6 -6
  87. package/dist/esm/{post-skiplinks-b6f29605.js → post-skiplinks-814427b2.js} +5 -5
  88. package/dist/esm/post-skiplinks.entry.js +5 -5
  89. package/dist/esm/{store-29728e96.js → store-59bf455d.js} +1 -1
  90. package/dist/esm/{svg-icon.component-58139665.js → svg-icon.component-8b45252e.js} +1 -1
  91. package/dist/esm/{svg-sprite.component-f4f3f81e.js → svg-sprite.component-6c834657.js} +1 -1
  92. package/dist/esm/swisspost-internet-breadcrumbs.entry.js +6 -6
  93. package/dist/esm/swisspost-internet-footer.entry.js +5 -5
  94. package/dist/esm/swisspost-internet-header.entry.js +6 -6
  95. package/dist/esm/swisspost-internet-header.js +4 -4
  96. package/dist/esm-es5/focus-trap.entry.js +10 -0
  97. package/dist/esm-es5/index-607344a5.js +1 -0
  98. package/dist/esm-es5/index.js +1 -1
  99. package/dist/esm-es5/{klp-widget.controller-099061a3.js → klp-widget.controller-b101390d.js} +1 -1
  100. package/dist/esm-es5/{language.service-e186d7dd.js → language.service-2df27b6a.js} +1 -1
  101. package/dist/esm-es5/loader.js +1 -1
  102. package/dist/esm-es5/post-internet-breadcrumbs-d7f7f87f.js +1 -0
  103. package/dist/esm-es5/post-internet-footer-b4161a6c.js +1 -0
  104. package/dist/esm-es5/post-internet-header-8279d078.js +1 -0
  105. package/dist/esm-es5/{post-klp-login-widget-f138e519.js → post-klp-login-widget-58d9e3e2.js} +1 -1
  106. package/dist/esm-es5/post-klp-login-widget.entry.js +1 -1
  107. package/dist/esm-es5/post-language-switch-85afcb97.js +1 -0
  108. package/dist/esm-es5/post-language-switch.entry.js +1 -1
  109. package/dist/esm-es5/{post-logo-1e5668dc.js → post-logo-6ea4c487.js} +1 -1
  110. package/dist/esm-es5/post-logo.entry.js +1 -1
  111. package/dist/esm-es5/post-main-navigation-9d539ab7.js +1 -0
  112. package/dist/esm-es5/post-main-navigation.entry.js +1 -1
  113. package/dist/esm-es5/{post-meta-navigation-01dc595f.js → post-meta-navigation-895bef11.js} +1 -1
  114. package/dist/esm-es5/post-meta-navigation.entry.js +1 -1
  115. package/dist/esm-es5/post-search-6e306c06.js +1 -0
  116. package/dist/esm-es5/post-search.entry.js +1 -1
  117. package/dist/esm-es5/{post-skiplinks-b6f29605.js → post-skiplinks-814427b2.js} +1 -1
  118. package/dist/esm-es5/post-skiplinks.entry.js +1 -1
  119. package/dist/esm-es5/{store-29728e96.js → store-59bf455d.js} +1 -1
  120. package/dist/esm-es5/svg-icon.component-8b45252e.js +1 -0
  121. package/dist/esm-es5/{svg-sprite.component-f4f3f81e.js → svg-sprite.component-6c834657.js} +1 -1
  122. package/dist/esm-es5/swisspost-internet-breadcrumbs.entry.js +1 -1
  123. package/dist/esm-es5/swisspost-internet-footer.entry.js +1 -1
  124. package/dist/esm-es5/swisspost-internet-header.entry.js +1 -1
  125. package/dist/esm-es5/swisspost-internet-header.js +1 -1
  126. package/dist/swisspost-internet-header/index.esm.js +1 -1
  127. package/dist/swisspost-internet-header/p-0643f977.js +1 -0
  128. package/dist/swisspost-internet-header/p-067578af.entry.js +1 -0
  129. package/dist/swisspost-internet-header/p-0bb2f252.js +1 -0
  130. package/dist/swisspost-internet-header/p-0e26e283.system.js +1 -0
  131. package/dist/swisspost-internet-header/p-13b25740.js +1 -0
  132. package/dist/swisspost-internet-header/p-27de5cd4.system.entry.js +1 -0
  133. package/dist/swisspost-internet-header/{p-3d025bca.system.js → p-28543187.system.js} +1 -1
  134. package/dist/swisspost-internet-header/{p-35a9d4ae.js → p-286e501c.js} +1 -1
  135. package/dist/swisspost-internet-header/{p-f1bca231.system.js → p-29965ca9.system.js} +1 -1
  136. package/dist/swisspost-internet-header/p-2a7cb38b.system.js +1 -0
  137. package/dist/swisspost-internet-header/{p-a881c817.system.js → p-2bb736c5.system.js} +1 -1
  138. package/dist/swisspost-internet-header/p-2d7abdc0.entry.js +1 -0
  139. package/dist/swisspost-internet-header/{p-bde95a71.system.js → p-2f7c5bd5.system.js} +1 -1
  140. package/dist/swisspost-internet-header/{p-2e00bab4.js → p-32bd7cb9.js} +1 -1
  141. package/dist/swisspost-internet-header/p-388a9b3c.system.entry.js +1 -0
  142. package/dist/swisspost-internet-header/p-3a497703.entry.js +11 -0
  143. package/dist/swisspost-internet-header/p-43f111fb.system.entry.js +1 -0
  144. package/dist/swisspost-internet-header/{p-cb1c5219.js → p-49021214.js} +1 -1
  145. package/dist/swisspost-internet-header/{p-d0793471.system.js → p-4d4d3ea2.system.js} +1 -1
  146. package/dist/swisspost-internet-header/{p-85813a11.js → p-4f5e96be.js} +1 -1
  147. package/dist/swisspost-internet-header/p-507a1aa1.entry.js +1 -0
  148. package/dist/swisspost-internet-header/p-5f5b27e0.system.js +1 -0
  149. package/dist/swisspost-internet-header/{p-2dcaaac5.system.js → p-5f82dead.system.js} +1 -1
  150. package/dist/swisspost-internet-header/p-61c44b55.entry.js +1 -0
  151. package/dist/swisspost-internet-header/p-672e2b72.js +1 -0
  152. package/dist/swisspost-internet-header/p-6786aa21.js +1 -0
  153. package/dist/swisspost-internet-header/p-6acdc01c.system.entry.js +10 -0
  154. package/dist/swisspost-internet-header/p-6b24c17a.system.entry.js +1 -0
  155. package/dist/swisspost-internet-header/p-7500c126.system.entry.js +1 -0
  156. package/dist/swisspost-internet-header/p-7512fef9.js +1 -0
  157. package/dist/swisspost-internet-header/{p-4eea8bcd.system.js → p-75d40407.system.js} +1 -1
  158. package/dist/swisspost-internet-header/p-760d604f.js +1 -0
  159. package/dist/swisspost-internet-header/p-7aaa346f.entry.js +1 -0
  160. package/dist/swisspost-internet-header/p-83780dd4.system.js +1 -0
  161. package/dist/swisspost-internet-header/p-91676998.system.entry.js +1 -0
  162. package/dist/swisspost-internet-header/p-99fc974a.system.entry.js +1 -0
  163. package/dist/swisspost-internet-header/p-9bcaad92.system.entry.js +1 -0
  164. package/dist/swisspost-internet-header/p-a025bd85.system.entry.js +1 -0
  165. package/dist/swisspost-internet-header/p-a1e9c54b.system.js +2 -0
  166. package/dist/swisspost-internet-header/{p-de3a8e62.system.js → p-aeb4cf5c.system.js} +1 -1
  167. package/dist/swisspost-internet-header/{p-678019cb.js → p-b07d0f11.js} +1 -1
  168. package/dist/swisspost-internet-header/p-b70cc30e.entry.js +1 -0
  169. package/dist/swisspost-internet-header/{p-7a585242.system.js → p-b8291f85.system.js} +1 -1
  170. package/dist/swisspost-internet-header/p-b90e75e8.entry.js +1 -0
  171. package/dist/swisspost-internet-header/p-bce3a409.entry.js +1 -0
  172. package/dist/swisspost-internet-header/p-bd1b44bc.js +1 -0
  173. package/dist/swisspost-internet-header/p-bf49aa72.system.js +1 -0
  174. package/dist/swisspost-internet-header/p-c1b5f811.js +2 -0
  175. package/dist/swisspost-internet-header/p-c60a6b5e.system.entry.js +1 -0
  176. package/dist/swisspost-internet-header/p-cfa585dc.js +1 -0
  177. package/dist/swisspost-internet-header/p-db2b6582.entry.js +1 -0
  178. package/dist/swisspost-internet-header/p-dec84965.system.js +1 -0
  179. package/dist/swisspost-internet-header/p-e97ae5c1.system.js +1 -0
  180. package/dist/swisspost-internet-header/p-ed6ab713.entry.js +1 -0
  181. package/dist/swisspost-internet-header/p-edf88566.system.js +1 -0
  182. package/dist/swisspost-internet-header/{p-d7b3988c.js → p-eeae2fed.js} +1 -1
  183. package/dist/swisspost-internet-header/swisspost-internet-header.css +1 -1
  184. package/dist/swisspost-internet-header/swisspost-internet-header.esm.js +1 -1
  185. package/dist/swisspost-internet-header/swisspost-internet-header.js +1 -1
  186. package/dist/types/components/post-internet-breadcrumbs/post-internet-breadcrumbs.d.ts +11 -8
  187. package/dist/types/components/post-language-switch/post-language-switch.d.ts +13 -3
  188. package/dist/types/components/post-main-navigation/post-main-navigation.d.ts +19 -13
  189. package/dist/types/components/post-meta-navigation/post-meta-navigation.d.ts +7 -0
  190. package/dist/types/components/post-search/post-search.d.ts +11 -4
  191. package/dist/types/components/shared/focus-trap.d.ts +17 -0
  192. package/dist/types/components.d.ts +73 -1
  193. package/dist/types/models/header.model.d.ts +4 -2
  194. package/dist/types/stencil-public-runtime.d.ts +3 -8
  195. package/loader/cdn.js +1 -2
  196. package/loader/index.cjs.js +1 -2
  197. package/loader/index.es2017.js +1 -2
  198. package/loader/index.js +1 -2
  199. package/package.json +15 -15
  200. package/dist/cjs/post-search-8cdb662e.js +0 -596
  201. package/dist/collection/components/post-internet-breadcrumbs/components/focus-trap.component.js +0 -41
  202. package/dist/esm/post-search-3a9f21c4.js +0 -594
  203. package/dist/esm-es5/index-9deab2c6.js +0 -1
  204. package/dist/esm-es5/post-internet-breadcrumbs-7ae97585.js +0 -6
  205. package/dist/esm-es5/post-internet-footer-c9b6481e.js +0 -1
  206. package/dist/esm-es5/post-internet-header-f7d3d57b.js +0 -1
  207. package/dist/esm-es5/post-language-switch-313a6a5c.js +0 -1
  208. package/dist/esm-es5/post-main-navigation-45e3060f.js +0 -1
  209. package/dist/esm-es5/post-search-3a9f21c4.js +0 -1
  210. package/dist/esm-es5/svg-icon.component-58139665.js +0 -1
  211. package/dist/swisspost-internet-header/p-033f4fbe.entry.js +0 -1
  212. package/dist/swisspost-internet-header/p-057f32b6.js +0 -1
  213. package/dist/swisspost-internet-header/p-079867d3.system.js +0 -1
  214. package/dist/swisspost-internet-header/p-116b8ff0.system.js +0 -1
  215. package/dist/swisspost-internet-header/p-17c754f2.entry.js +0 -1
  216. package/dist/swisspost-internet-header/p-1b37bb14.js +0 -2
  217. package/dist/swisspost-internet-header/p-24f83792.entry.js +0 -1
  218. package/dist/swisspost-internet-header/p-2afa4d26.system.js +0 -1
  219. package/dist/swisspost-internet-header/p-3457f6d9.js +0 -1
  220. package/dist/swisspost-internet-header/p-3b1ccdab.entry.js +0 -1
  221. package/dist/swisspost-internet-header/p-40b1e640.entry.js +0 -1
  222. package/dist/swisspost-internet-header/p-455e3b4e.entry.js +0 -1
  223. package/dist/swisspost-internet-header/p-4d9ca96c.system.entry.js +0 -1
  224. package/dist/swisspost-internet-header/p-52ab2e14.system.entry.js +0 -1
  225. package/dist/swisspost-internet-header/p-6262f647.entry.js +0 -1
  226. package/dist/swisspost-internet-header/p-65ba132d.entry.js +0 -1
  227. package/dist/swisspost-internet-header/p-6a8338b7.system.entry.js +0 -1
  228. package/dist/swisspost-internet-header/p-6ec4bb44.js +0 -1
  229. package/dist/swisspost-internet-header/p-70bd4f89.system.entry.js +0 -1
  230. package/dist/swisspost-internet-header/p-71b946fc.system.entry.js +0 -1
  231. package/dist/swisspost-internet-header/p-72d70641.js +0 -1
  232. package/dist/swisspost-internet-header/p-752d6e46.system.js +0 -1
  233. package/dist/swisspost-internet-header/p-760b8d08.system.entry.js +0 -1
  234. package/dist/swisspost-internet-header/p-786a288d.system.entry.js +0 -1
  235. package/dist/swisspost-internet-header/p-7bd55d1d.system.js +0 -1
  236. package/dist/swisspost-internet-header/p-863de8cb.js +0 -1
  237. package/dist/swisspost-internet-header/p-8983c9bd.system.entry.js +0 -1
  238. package/dist/swisspost-internet-header/p-8b4c6f7c.system.js +0 -2
  239. package/dist/swisspost-internet-header/p-94ddd446.js +0 -1
  240. package/dist/swisspost-internet-header/p-a4afbf29.system.js +0 -1
  241. package/dist/swisspost-internet-header/p-adbbadae.entry.js +0 -1
  242. package/dist/swisspost-internet-header/p-b9a4af9f.system.js +0 -1
  243. package/dist/swisspost-internet-header/p-d11efd7d.system.js +0 -6
  244. package/dist/swisspost-internet-header/p-d7a9b5b7.js +0 -1
  245. package/dist/swisspost-internet-header/p-dfd42dc7.js +0 -1
  246. package/dist/swisspost-internet-header/p-e04d5ef8.js +0 -6
  247. package/dist/swisspost-internet-header/p-e67e39f8.entry.js +0 -1
  248. package/dist/swisspost-internet-header/p-e6b441a6.system.entry.js +0 -1
  249. package/dist/swisspost-internet-header/p-eb8959b3.system.entry.js +0 -1
  250. package/dist/types/components/post-internet-breadcrumbs/components/focus-trap.component.d.ts +0 -12
@@ -0,0 +1,1553 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-e67ee869.js');
6
+
7
+ /*!
8
+ * tabbable 6.2.0
9
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
10
+ */
11
+ // NOTE: separate `:not()` selectors has broader browser support than the newer
12
+ // `:not([inert], [inert] *)` (Feb 2023)
13
+ // CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes
14
+ // the entire query to fail, resulting in no nodes found, which will break a lot
15
+ // of things... so we have to rely on JS to identify nodes inside an inert container
16
+ var candidateSelectors = ['input:not([inert])', 'select:not([inert])', 'textarea:not([inert])', 'a[href]:not([inert])', 'button:not([inert])', '[tabindex]:not(slot):not([inert])', 'audio[controls]:not([inert])', 'video[controls]:not([inert])', '[contenteditable]:not([contenteditable="false"]):not([inert])', 'details>summary:first-of-type:not([inert])', 'details:not([inert])'];
17
+ var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
18
+ var NoElement = typeof Element === 'undefined';
19
+ var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
20
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
21
+ var _element$getRootNode;
22
+ return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
23
+ } : function (element) {
24
+ return element === null || element === void 0 ? void 0 : element.ownerDocument;
25
+ };
26
+
27
+ /**
28
+ * Determines if a node is inert or in an inert ancestor.
29
+ * @param {Element} [node]
30
+ * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
31
+ * see if any of them are inert. If false, only `node` itself is considered.
32
+ * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
33
+ * False if `node` is falsy.
34
+ */
35
+ var isInert = function isInert(node, lookUp) {
36
+ var _node$getAttribute;
37
+ if (lookUp === void 0) {
38
+ lookUp = true;
39
+ }
40
+ // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
41
+ // JS API property; we have to check the attribute, which can either be empty or 'true';
42
+ // if it's `null` (not specified) or 'false', it's an active element
43
+ var inertAtt = node === null || node === void 0 ? void 0 : (_node$getAttribute = node.getAttribute) === null || _node$getAttribute === void 0 ? void 0 : _node$getAttribute.call(node, 'inert');
44
+ var inert = inertAtt === '' || inertAtt === 'true';
45
+
46
+ // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
47
+ // if it weren't for `matches()` not being a function on shadow roots; the following
48
+ // code works for any kind of node
49
+ // CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`
50
+ // so it likely would not support `:is([inert] *)` either...
51
+ var result = inert || lookUp && node && isInert(node.parentNode); // recursive
52
+
53
+ return result;
54
+ };
55
+
56
+ /**
57
+ * Determines if a node's content is editable.
58
+ * @param {Element} [node]
59
+ * @returns True if it's content-editable; false if it's not or `node` is falsy.
60
+ */
61
+ var isContentEditable = function isContentEditable(node) {
62
+ var _node$getAttribute2;
63
+ // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
64
+ // to use the attribute directly to check for this, which can either be empty or 'true';
65
+ // if it's `null` (not specified) or 'false', it's a non-editable element
66
+ var attValue = node === null || node === void 0 ? void 0 : (_node$getAttribute2 = node.getAttribute) === null || _node$getAttribute2 === void 0 ? void 0 : _node$getAttribute2.call(node, 'contenteditable');
67
+ return attValue === '' || attValue === 'true';
68
+ };
69
+
70
+ /**
71
+ * @param {Element} el container to check in
72
+ * @param {boolean} includeContainer add container to check
73
+ * @param {(node: Element) => boolean} filter filter candidates
74
+ * @returns {Element[]}
75
+ */
76
+ var getCandidates = function getCandidates(el, includeContainer, filter) {
77
+ // even if `includeContainer=false`, we still have to check it for inertness because
78
+ // if it's inert, all its children are inert
79
+ if (isInert(el)) {
80
+ return [];
81
+ }
82
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
83
+ if (includeContainer && matches.call(el, candidateSelector)) {
84
+ candidates.unshift(el);
85
+ }
86
+ candidates = candidates.filter(filter);
87
+ return candidates;
88
+ };
89
+
90
+ /**
91
+ * @callback GetShadowRoot
92
+ * @param {Element} element to check for shadow root
93
+ * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
94
+ */
95
+
96
+ /**
97
+ * @callback ShadowRootFilter
98
+ * @param {Element} shadowHostNode the element which contains shadow content
99
+ * @returns {boolean} true if a shadow root could potentially contain valid candidates.
100
+ */
101
+
102
+ /**
103
+ * @typedef {Object} CandidateScope
104
+ * @property {Element} scopeParent contains inner candidates
105
+ * @property {Element[]} candidates list of candidates found in the scope parent
106
+ */
107
+
108
+ /**
109
+ * @typedef {Object} IterativeOptions
110
+ * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
111
+ * if a function, implies shadow support is enabled and either returns the shadow root of an element
112
+ * or a boolean stating if it has an undisclosed shadow root
113
+ * @property {(node: Element) => boolean} filter filter candidates
114
+ * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
115
+ * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
116
+ */
117
+
118
+ /**
119
+ * @param {Element[]} elements list of element containers to match candidates from
120
+ * @param {boolean} includeContainer add container list to check
121
+ * @param {IterativeOptions} options
122
+ * @returns {Array.<Element|CandidateScope>}
123
+ */
124
+ var getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
125
+ var candidates = [];
126
+ var elementsToCheck = Array.from(elements);
127
+ while (elementsToCheck.length) {
128
+ var element = elementsToCheck.shift();
129
+ if (isInert(element, false)) {
130
+ // no need to look up since we're drilling down
131
+ // anything inside this container will also be inert
132
+ continue;
133
+ }
134
+ if (element.tagName === 'SLOT') {
135
+ // add shadow dom slot scope (slot itself cannot be focusable)
136
+ var assigned = element.assignedElements();
137
+ var content = assigned.length ? assigned : element.children;
138
+ var nestedCandidates = getCandidatesIteratively(content, true, options);
139
+ if (options.flatten) {
140
+ candidates.push.apply(candidates, nestedCandidates);
141
+ } else {
142
+ candidates.push({
143
+ scopeParent: element,
144
+ candidates: nestedCandidates
145
+ });
146
+ }
147
+ } else {
148
+ // check candidate element
149
+ var validCandidate = matches.call(element, candidateSelector);
150
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
151
+ candidates.push(element);
152
+ }
153
+
154
+ // iterate over shadow content if possible
155
+ var shadowRoot = element.shadowRoot ||
156
+ // check for an undisclosed shadow
157
+ typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
158
+
159
+ // no inert look up because we're already drilling down and checking for inertness
160
+ // on the way down, so all containers to this root node should have already been
161
+ // vetted as non-inert
162
+ var validShadowRoot = !isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
163
+ if (shadowRoot && validShadowRoot) {
164
+ // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
165
+ // shadow exists, so look at light dom children as fallback BUT create a scope for any
166
+ // child candidates found because they're likely slotted elements (elements that are
167
+ // children of the web component element (which has the shadow), in the light dom, but
168
+ // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
169
+ // _after_ we return from this recursive call
170
+ var _nestedCandidates = getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
171
+ if (options.flatten) {
172
+ candidates.push.apply(candidates, _nestedCandidates);
173
+ } else {
174
+ candidates.push({
175
+ scopeParent: element,
176
+ candidates: _nestedCandidates
177
+ });
178
+ }
179
+ } else {
180
+ // there's not shadow so just dig into the element's (light dom) children
181
+ // __without__ giving the element special scope treatment
182
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
183
+ }
184
+ }
185
+ }
186
+ return candidates;
187
+ };
188
+
189
+ /**
190
+ * @private
191
+ * Determines if the node has an explicitly specified `tabindex` attribute.
192
+ * @param {HTMLElement} node
193
+ * @returns {boolean} True if so; false if not.
194
+ */
195
+ var hasTabIndex = function hasTabIndex(node) {
196
+ return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
197
+ };
198
+
199
+ /**
200
+ * Determine the tab index of a given node.
201
+ * @param {HTMLElement} node
202
+ * @returns {number} Tab order (negative, 0, or positive number).
203
+ * @throws {Error} If `node` is falsy.
204
+ */
205
+ var getTabIndex = function getTabIndex(node) {
206
+ if (!node) {
207
+ throw new Error('No node provided');
208
+ }
209
+ if (node.tabIndex < 0) {
210
+ // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
211
+ // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
212
+ // yet they are still part of the regular tab order; in FF, they get a default
213
+ // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
214
+ // order, consider their tab index to be 0.
215
+ // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
216
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
217
+ if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
218
+ return 0;
219
+ }
220
+ }
221
+ return node.tabIndex;
222
+ };
223
+
224
+ /**
225
+ * Determine the tab index of a given node __for sort order purposes__.
226
+ * @param {HTMLElement} node
227
+ * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
228
+ * has tabIndex -1, but needs to be sorted by document order in order for its content to be
229
+ * inserted into the correct sort position.
230
+ * @returns {number} Tab order (negative, 0, or positive number).
231
+ */
232
+ var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
233
+ var tabIndex = getTabIndex(node);
234
+ if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
235
+ return 0;
236
+ }
237
+ return tabIndex;
238
+ };
239
+ var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
240
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
241
+ };
242
+ var isInput = function isInput(node) {
243
+ return node.tagName === 'INPUT';
244
+ };
245
+ var isHiddenInput = function isHiddenInput(node) {
246
+ return isInput(node) && node.type === 'hidden';
247
+ };
248
+ var isDetailsWithSummary = function isDetailsWithSummary(node) {
249
+ var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
250
+ return child.tagName === 'SUMMARY';
251
+ });
252
+ return r;
253
+ };
254
+ var getCheckedRadio = function getCheckedRadio(nodes, form) {
255
+ for (var i = 0; i < nodes.length; i++) {
256
+ if (nodes[i].checked && nodes[i].form === form) {
257
+ return nodes[i];
258
+ }
259
+ }
260
+ };
261
+ var isTabbableRadio = function isTabbableRadio(node) {
262
+ if (!node.name) {
263
+ return true;
264
+ }
265
+ var radioScope = node.form || getRootNode(node);
266
+ var queryRadios = function queryRadios(name) {
267
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
268
+ };
269
+ var radioSet;
270
+ if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
271
+ radioSet = queryRadios(window.CSS.escape(node.name));
272
+ } else {
273
+ try {
274
+ radioSet = queryRadios(node.name);
275
+ } catch (err) {
276
+ // eslint-disable-next-line no-console
277
+ console.error('Looks like you have a radio button with a name attribute containing invalid CSS selector characters and need the CSS.escape polyfill: %s', err.message);
278
+ return false;
279
+ }
280
+ }
281
+ var checked = getCheckedRadio(radioSet, node.form);
282
+ return !checked || checked === node;
283
+ };
284
+ var isRadio = function isRadio(node) {
285
+ return isInput(node) && node.type === 'radio';
286
+ };
287
+ var isNonTabbableRadio = function isNonTabbableRadio(node) {
288
+ return isRadio(node) && !isTabbableRadio(node);
289
+ };
290
+
291
+ // determines if a node is ultimately attached to the window's document
292
+ var isNodeAttached = function isNodeAttached(node) {
293
+ var _nodeRoot;
294
+ // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
295
+ // (but NOT _the_ document; see second 'If' comment below for more).
296
+ // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
297
+ // is attached, and the one we need to check if it's in the document or not (because the
298
+ // shadow, and all nodes it contains, is never considered in the document since shadows
299
+ // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
300
+ // is hidden, or is not in the document itself but is detached, it will affect the shadow's
301
+ // visibility, including all the nodes it contains). The host could be any normal node,
302
+ // or a custom element (i.e. web component). Either way, that's the one that is considered
303
+ // part of the document, not the shadow root, nor any of its children (i.e. the node being
304
+ // tested).
305
+ // To further complicate things, we have to look all the way up until we find a shadow HOST
306
+ // that is attached (or find none) because the node might be in nested shadows...
307
+ // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
308
+ // document (per the docs) and while it's a Document-type object, that document does not
309
+ // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
310
+ // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
311
+ // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
312
+ // node is actually detached.
313
+ // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
314
+ // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
315
+ // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
316
+ // `ownerDocument` will be `null`, hence the optional chaining on it.
317
+ var nodeRoot = node && getRootNode(node);
318
+ var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
319
+
320
+ // in some cases, a detached node will return itself as the root instead of a document or
321
+ // shadow root object, in which case, we shouldn't try to look further up the host chain
322
+ var attached = false;
323
+ if (nodeRoot && nodeRoot !== node) {
324
+ var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
325
+ attached = !!((_nodeRootHost = nodeRootHost) !== null && _nodeRootHost !== void 0 && (_nodeRootHost$ownerDo = _nodeRootHost.ownerDocument) !== null && _nodeRootHost$ownerDo !== void 0 && _nodeRootHost$ownerDo.contains(nodeRootHost) || node !== null && node !== void 0 && (_node$ownerDocument = node.ownerDocument) !== null && _node$ownerDocument !== void 0 && _node$ownerDocument.contains(node));
326
+ while (!attached && nodeRootHost) {
327
+ var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
328
+ // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
329
+ // which means we need to get the host's host and check if that parent host is contained
330
+ // in (i.e. attached to) the document
331
+ nodeRoot = getRootNode(nodeRootHost);
332
+ nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
333
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
334
+ }
335
+ }
336
+ return attached;
337
+ };
338
+ var isZeroArea = function isZeroArea(node) {
339
+ var _node$getBoundingClie = node.getBoundingClientRect(),
340
+ width = _node$getBoundingClie.width,
341
+ height = _node$getBoundingClie.height;
342
+ return width === 0 && height === 0;
343
+ };
344
+ var isHidden = function isHidden(node, _ref) {
345
+ var displayCheck = _ref.displayCheck,
346
+ getShadowRoot = _ref.getShadowRoot;
347
+ // NOTE: visibility will be `undefined` if node is detached from the document
348
+ // (see notes about this further down), which means we will consider it visible
349
+ // (this is legacy behavior from a very long way back)
350
+ // NOTE: we check this regardless of `displayCheck="none"` because this is a
351
+ // _visibility_ check, not a _display_ check
352
+ if (getComputedStyle(node).visibility === 'hidden') {
353
+ return true;
354
+ }
355
+ var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
356
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
357
+ if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
358
+ return true;
359
+ }
360
+ if (!displayCheck || displayCheck === 'full' || displayCheck === 'legacy-full') {
361
+ if (typeof getShadowRoot === 'function') {
362
+ // figure out if we should consider the node to be in an undisclosed shadow and use the
363
+ // 'non-zero-area' fallback
364
+ var originalNode = node;
365
+ while (node) {
366
+ var parentElement = node.parentElement;
367
+ var rootNode = getRootNode(node);
368
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
369
+ ) {
370
+ // node has an undisclosed shadow which means we can only treat it as a black box, so we
371
+ // fall back to a non-zero-area test
372
+ return isZeroArea(node);
373
+ } else if (node.assignedSlot) {
374
+ // iterate up slot
375
+ node = node.assignedSlot;
376
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
377
+ // cross shadow boundary
378
+ node = rootNode.host;
379
+ } else {
380
+ // iterate up normal dom
381
+ node = parentElement;
382
+ }
383
+ }
384
+ node = originalNode;
385
+ }
386
+ // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
387
+ // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
388
+ // it might be a falsy value, which means shadow DOM support is disabled
389
+
390
+ // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
391
+ // now we can just test to see if it would normally be visible or not, provided it's
392
+ // attached to the main document.
393
+ // NOTE: We must consider case where node is inside a shadow DOM and given directly to
394
+ // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
395
+
396
+ if (isNodeAttached(node)) {
397
+ // this works wherever the node is: if there's at least one client rect, it's
398
+ // somehow displayed; it also covers the CSS 'display: contents' case where the
399
+ // node itself is hidden in place of its contents; and there's no need to search
400
+ // up the hierarchy either
401
+ return !node.getClientRects().length;
402
+ }
403
+
404
+ // Else, the node isn't attached to the document, which means the `getClientRects()`
405
+ // API will __always__ return zero rects (this can happen, for example, if React
406
+ // is used to render nodes onto a detached tree, as confirmed in this thread:
407
+ // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
408
+ //
409
+ // It also means that even window.getComputedStyle(node).display will return `undefined`
410
+ // because styles are only computed for nodes that are in the document.
411
+ //
412
+ // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
413
+ // somehow. Though it was never stated officially, anyone who has ever used tabbable
414
+ // APIs on nodes in detached containers has actually implicitly used tabbable in what
415
+ // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
416
+ // considering __everything__ to be visible because of the innability to determine styles.
417
+ //
418
+ // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
419
+ // nodes as visible with the 'none' fallback.__
420
+ if (displayCheck !== 'legacy-full') {
421
+ return true; // hidden
422
+ }
423
+ // else, fallback to 'none' mode and consider the node visible
424
+ } else if (displayCheck === 'non-zero-area') {
425
+ // NOTE: Even though this tests that the node's client rect is non-zero to determine
426
+ // whether it's displayed, and that a detached node will __always__ have a zero-area
427
+ // client rect, we don't special-case for whether the node is attached or not. In
428
+ // this mode, we do want to consider nodes that have a zero area to be hidden at all
429
+ // times, and that includes attached or not.
430
+ return isZeroArea(node);
431
+ }
432
+
433
+ // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
434
+ // it's visible
435
+ return false;
436
+ };
437
+
438
+ // form fields (nested) inside a disabled fieldset are not focusable/tabbable
439
+ // unless they are in the _first_ <legend> element of the top-most disabled
440
+ // fieldset
441
+ var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
442
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
443
+ var parentNode = node.parentElement;
444
+ // check if `node` is contained in a disabled <fieldset>
445
+ while (parentNode) {
446
+ if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
447
+ // look for the first <legend> among the children of the disabled <fieldset>
448
+ for (var i = 0; i < parentNode.children.length; i++) {
449
+ var child = parentNode.children.item(i);
450
+ // when the first <legend> (in document order) is found
451
+ if (child.tagName === 'LEGEND') {
452
+ // if its parent <fieldset> is not nested in another disabled <fieldset>,
453
+ // return whether `node` is a descendant of its first <legend>
454
+ return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
455
+ }
456
+ }
457
+ // the disabled <fieldset> containing `node` has no <legend>
458
+ return true;
459
+ }
460
+ parentNode = parentNode.parentElement;
461
+ }
462
+ }
463
+
464
+ // else, node's tabbable/focusable state should not be affected by a fieldset's
465
+ // enabled/disabled state
466
+ return false;
467
+ };
468
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
469
+ if (node.disabled ||
470
+ // we must do an inert look up to filter out any elements inside an inert ancestor
471
+ // because we're limited in the type of selectors we can use in JSDom (see related
472
+ // note related to `candidateSelectors`)
473
+ isInert(node) || isHiddenInput(node) || isHidden(node, options) ||
474
+ // For a details element with a summary, the summary element gets the focus
475
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
476
+ return false;
477
+ }
478
+ return true;
479
+ };
480
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
481
+ if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
482
+ return false;
483
+ }
484
+ return true;
485
+ };
486
+ var isValidShadowRootTabbable = function isValidShadowRootTabbable(shadowHostNode) {
487
+ var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
488
+ if (isNaN(tabIndex) || tabIndex >= 0) {
489
+ return true;
490
+ }
491
+ // If a custom element has an explicit negative tabindex,
492
+ // browsers will not allow tab targeting said element's children.
493
+ return false;
494
+ };
495
+
496
+ /**
497
+ * @param {Array.<Element|CandidateScope>} candidates
498
+ * @returns Element[]
499
+ */
500
+ var sortByOrder = function sortByOrder(candidates) {
501
+ var regularTabbables = [];
502
+ var orderedTabbables = [];
503
+ candidates.forEach(function (item, i) {
504
+ var isScope = !!item.scopeParent;
505
+ var element = isScope ? item.scopeParent : item;
506
+ var candidateTabindex = getSortOrderTabIndex(element, isScope);
507
+ var elements = isScope ? sortByOrder(item.candidates) : element;
508
+ if (candidateTabindex === 0) {
509
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
510
+ } else {
511
+ orderedTabbables.push({
512
+ documentOrder: i,
513
+ tabIndex: candidateTabindex,
514
+ item: item,
515
+ isScope: isScope,
516
+ content: elements
517
+ });
518
+ }
519
+ });
520
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
521
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
522
+ return acc;
523
+ }, []).concat(regularTabbables);
524
+ };
525
+ var tabbable = function tabbable(container, options) {
526
+ options = options || {};
527
+ var candidates;
528
+ if (options.getShadowRoot) {
529
+ candidates = getCandidatesIteratively([container], options.includeContainer, {
530
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
531
+ flatten: false,
532
+ getShadowRoot: options.getShadowRoot,
533
+ shadowRootFilter: isValidShadowRootTabbable
534
+ });
535
+ } else {
536
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
537
+ }
538
+ return sortByOrder(candidates);
539
+ };
540
+ var focusable = function focusable(container, options) {
541
+ options = options || {};
542
+ var candidates;
543
+ if (options.getShadowRoot) {
544
+ candidates = getCandidatesIteratively([container], options.includeContainer, {
545
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
546
+ flatten: true,
547
+ getShadowRoot: options.getShadowRoot
548
+ });
549
+ } else {
550
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
551
+ }
552
+ return candidates;
553
+ };
554
+ var isTabbable = function isTabbable(node, options) {
555
+ options = options || {};
556
+ if (!node) {
557
+ throw new Error('No node provided');
558
+ }
559
+ if (matches.call(node, candidateSelector) === false) {
560
+ return false;
561
+ }
562
+ return isNodeMatchingSelectorTabbable(options, node);
563
+ };
564
+ var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
565
+ var isFocusable = function isFocusable(node, options) {
566
+ options = options || {};
567
+ if (!node) {
568
+ throw new Error('No node provided');
569
+ }
570
+ if (matches.call(node, focusableCandidateSelector) === false) {
571
+ return false;
572
+ }
573
+ return isNodeMatchingSelectorFocusable(options, node);
574
+ };
575
+
576
+ /*!
577
+ * focus-trap 7.5.4
578
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
579
+ */
580
+
581
+ function ownKeys(e, r) {
582
+ var t = Object.keys(e);
583
+ if (Object.getOwnPropertySymbols) {
584
+ var o = Object.getOwnPropertySymbols(e);
585
+ r && (o = o.filter(function (r) {
586
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
587
+ })), t.push.apply(t, o);
588
+ }
589
+ return t;
590
+ }
591
+ function _objectSpread2(e) {
592
+ for (var r = 1; r < arguments.length; r++) {
593
+ var t = null != arguments[r] ? arguments[r] : {};
594
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
595
+ _defineProperty(e, r, t[r]);
596
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
597
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
598
+ });
599
+ }
600
+ return e;
601
+ }
602
+ function _defineProperty(obj, key, value) {
603
+ key = _toPropertyKey(key);
604
+ if (key in obj) {
605
+ Object.defineProperty(obj, key, {
606
+ value: value,
607
+ enumerable: true,
608
+ configurable: true,
609
+ writable: true
610
+ });
611
+ } else {
612
+ obj[key] = value;
613
+ }
614
+ return obj;
615
+ }
616
+ function _toPrimitive(input, hint) {
617
+ if (typeof input !== "object" || input === null) return input;
618
+ var prim = input[Symbol.toPrimitive];
619
+ if (prim !== undefined) {
620
+ var res = prim.call(input, hint || "default");
621
+ if (typeof res !== "object") return res;
622
+ throw new TypeError("@@toPrimitive must return a primitive value.");
623
+ }
624
+ return (hint === "string" ? String : Number)(input);
625
+ }
626
+ function _toPropertyKey(arg) {
627
+ var key = _toPrimitive(arg, "string");
628
+ return typeof key === "symbol" ? key : String(key);
629
+ }
630
+
631
+ var activeFocusTraps = {
632
+ activateTrap: function activateTrap(trapStack, trap) {
633
+ if (trapStack.length > 0) {
634
+ var activeTrap = trapStack[trapStack.length - 1];
635
+ if (activeTrap !== trap) {
636
+ activeTrap.pause();
637
+ }
638
+ }
639
+ var trapIndex = trapStack.indexOf(trap);
640
+ if (trapIndex === -1) {
641
+ trapStack.push(trap);
642
+ } else {
643
+ // move this existing trap to the front of the queue
644
+ trapStack.splice(trapIndex, 1);
645
+ trapStack.push(trap);
646
+ }
647
+ },
648
+ deactivateTrap: function deactivateTrap(trapStack, trap) {
649
+ var trapIndex = trapStack.indexOf(trap);
650
+ if (trapIndex !== -1) {
651
+ trapStack.splice(trapIndex, 1);
652
+ }
653
+ if (trapStack.length > 0) {
654
+ trapStack[trapStack.length - 1].unpause();
655
+ }
656
+ }
657
+ };
658
+ var isSelectableInput = function isSelectableInput(node) {
659
+ return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
660
+ };
661
+ var isEscapeEvent = function isEscapeEvent(e) {
662
+ return (e === null || e === void 0 ? void 0 : e.key) === 'Escape' || (e === null || e === void 0 ? void 0 : e.key) === 'Esc' || (e === null || e === void 0 ? void 0 : e.keyCode) === 27;
663
+ };
664
+ var isTabEvent = function isTabEvent(e) {
665
+ return (e === null || e === void 0 ? void 0 : e.key) === 'Tab' || (e === null || e === void 0 ? void 0 : e.keyCode) === 9;
666
+ };
667
+
668
+ // checks for TAB by default
669
+ var isKeyForward = function isKeyForward(e) {
670
+ return isTabEvent(e) && !e.shiftKey;
671
+ };
672
+
673
+ // checks for SHIFT+TAB by default
674
+ var isKeyBackward = function isKeyBackward(e) {
675
+ return isTabEvent(e) && e.shiftKey;
676
+ };
677
+ var delay = function delay(fn) {
678
+ return setTimeout(fn, 0);
679
+ };
680
+
681
+ // Array.find/findIndex() are not supported on IE; this replicates enough
682
+ // of Array.findIndex() for our needs
683
+ var findIndex = function findIndex(arr, fn) {
684
+ var idx = -1;
685
+ arr.every(function (value, i) {
686
+ if (fn(value)) {
687
+ idx = i;
688
+ return false; // break
689
+ }
690
+
691
+ return true; // next
692
+ });
693
+
694
+ return idx;
695
+ };
696
+
697
+ /**
698
+ * Get an option's value when it could be a plain value, or a handler that provides
699
+ * the value.
700
+ * @param {*} value Option's value to check.
701
+ * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
702
+ * @returns {*} The `value`, or the handler's returned value.
703
+ */
704
+ var valueOrHandler = function valueOrHandler(value) {
705
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
706
+ params[_key - 1] = arguments[_key];
707
+ }
708
+ return typeof value === 'function' ? value.apply(void 0, params) : value;
709
+ };
710
+ var getActualTarget = function getActualTarget(event) {
711
+ // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
712
+ // shadow host. However, event.target.composedPath() will be an array of
713
+ // nodes "clicked" from inner-most (the actual element inside the shadow) to
714
+ // outer-most (the host HTML document). If we have access to composedPath(),
715
+ // then use its first element; otherwise, fall back to event.target (and
716
+ // this only works for an _open_ shadow DOM; otherwise,
717
+ // composedPath()[0] === event.target always).
718
+ return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
719
+ };
720
+
721
+ // NOTE: this must be _outside_ `createFocusTrap()` to make sure all traps in this
722
+ // current instance use the same stack if `userOptions.trapStack` isn't specified
723
+ var internalTrapStack = [];
724
+ var createFocusTrap = function createFocusTrap(elements, userOptions) {
725
+ // SSR: a live trap shouldn't be created in this type of environment so this
726
+ // should be safe code to execute if the `document` option isn't specified
727
+ var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
728
+ var trapStack = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.trapStack) || internalTrapStack;
729
+ var config = _objectSpread2({
730
+ returnFocusOnDeactivate: true,
731
+ escapeDeactivates: true,
732
+ delayInitialFocus: true,
733
+ isKeyForward: isKeyForward,
734
+ isKeyBackward: isKeyBackward
735
+ }, userOptions);
736
+ var state = {
737
+ // containers given to createFocusTrap()
738
+ // @type {Array<HTMLElement>}
739
+ containers: [],
740
+ // list of objects identifying tabbable nodes in `containers` in the trap
741
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
742
+ // is active, but the trap should never get to a state where there isn't at least one group
743
+ // with at least one tabbable node in it (that would lead to an error condition that would
744
+ // result in an error being thrown)
745
+ // @type {Array<{
746
+ // container: HTMLElement,
747
+ // tabbableNodes: Array<HTMLElement>, // empty if none
748
+ // focusableNodes: Array<HTMLElement>, // empty if none
749
+ // posTabIndexesFound: boolean,
750
+ // firstTabbableNode: HTMLElement|undefined,
751
+ // lastTabbableNode: HTMLElement|undefined,
752
+ // firstDomTabbableNode: HTMLElement|undefined,
753
+ // lastDomTabbableNode: HTMLElement|undefined,
754
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
755
+ // }>}
756
+ containerGroups: [],
757
+ // same order/length as `containers` list
758
+
759
+ // references to objects in `containerGroups`, but only those that actually have
760
+ // tabbable nodes in them
761
+ // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
762
+ // the same length
763
+ tabbableGroups: [],
764
+ nodeFocusedBeforeActivation: null,
765
+ mostRecentlyFocusedNode: null,
766
+ active: false,
767
+ paused: false,
768
+ // timer ID for when delayInitialFocus is true and initial focus in this trap
769
+ // has been delayed during activation
770
+ delayInitialFocusTimer: undefined,
771
+ // the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any
772
+ recentNavEvent: undefined
773
+ };
774
+ var trap; // eslint-disable-line prefer-const -- some private functions reference it, and its methods reference private functions, so we must declare here and define later
775
+
776
+ /**
777
+ * Gets a configuration option value.
778
+ * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,
779
+ * value will be taken from this object. Otherwise, value will be taken from base configuration.
780
+ * @param {string} optionName Name of the option whose value is sought.
781
+ * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`
782
+ * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.
783
+ */
784
+ var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
785
+ return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
786
+ };
787
+
788
+ /**
789
+ * Finds the index of the container that contains the element.
790
+ * @param {HTMLElement} element
791
+ * @param {Event} [event] If available, and `element` isn't directly found in any container,
792
+ * the event's composed path is used to see if includes any known trap containers in the
793
+ * case where the element is inside a Shadow DOM.
794
+ * @returns {number} Index of the container in either `state.containers` or
795
+ * `state.containerGroups` (the order/length of these lists are the same); -1
796
+ * if the element isn't found.
797
+ */
798
+ var findContainerIndex = function findContainerIndex(element, event) {
799
+ var composedPath = typeof (event === null || event === void 0 ? void 0 : event.composedPath) === 'function' ? event.composedPath() : undefined;
800
+ // NOTE: search `containerGroups` because it's possible a group contains no tabbable
801
+ // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)
802
+ // and we still need to find the element in there
803
+ return state.containerGroups.findIndex(function (_ref) {
804
+ var container = _ref.container,
805
+ tabbableNodes = _ref.tabbableNodes;
806
+ return container.contains(element) || ( // fall back to explicit tabbable search which will take into consideration any
807
+ // web components if the `tabbableOptions.getShadowRoot` option was used for
808
+ // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
809
+ // look inside web components even if open)
810
+ composedPath === null || composedPath === void 0 ? void 0 : composedPath.includes(container)) || tabbableNodes.find(function (node) {
811
+ return node === element;
812
+ });
813
+ });
814
+ };
815
+
816
+ /**
817
+ * Gets the node for the given option, which is expected to be an option that
818
+ * can be either a DOM node, a string that is a selector to get a node, `false`
819
+ * (if a node is explicitly NOT given), or a function that returns any of these
820
+ * values.
821
+ * @param {string} optionName
822
+ * @returns {undefined | false | HTMLElement | SVGElement} Returns
823
+ * `undefined` if the option is not specified; `false` if the option
824
+ * resolved to `false` (node explicitly not given); otherwise, the resolved
825
+ * DOM node.
826
+ * @throws {Error} If the option is set, not `false`, and is not, or does not
827
+ * resolve to a node.
828
+ */
829
+ var getNodeForOption = function getNodeForOption(optionName) {
830
+ var optionValue = config[optionName];
831
+ if (typeof optionValue === 'function') {
832
+ for (var _len2 = arguments.length, params = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
833
+ params[_key2 - 1] = arguments[_key2];
834
+ }
835
+ optionValue = optionValue.apply(void 0, params);
836
+ }
837
+ if (optionValue === true) {
838
+ optionValue = undefined; // use default value
839
+ }
840
+
841
+ if (!optionValue) {
842
+ if (optionValue === undefined || optionValue === false) {
843
+ return optionValue;
844
+ }
845
+ // else, empty string (invalid), null (invalid), 0 (invalid)
846
+
847
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
848
+ }
849
+ var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
850
+
851
+ if (typeof optionValue === 'string') {
852
+ node = doc.querySelector(optionValue); // resolve to node, or null if fails
853
+ if (!node) {
854
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
855
+ }
856
+ }
857
+ return node;
858
+ };
859
+ var getInitialFocusNode = function getInitialFocusNode() {
860
+ var node = getNodeForOption('initialFocus');
861
+
862
+ // false explicitly indicates we want no initialFocus at all
863
+ if (node === false) {
864
+ return false;
865
+ }
866
+ if (node === undefined || !isFocusable(node, config.tabbableOptions)) {
867
+ // option not specified nor focusable: use fallback options
868
+ if (findContainerIndex(doc.activeElement) >= 0) {
869
+ node = doc.activeElement;
870
+ } else {
871
+ var firstTabbableGroup = state.tabbableGroups[0];
872
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
873
+
874
+ // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
875
+ node = firstTabbableNode || getNodeForOption('fallbackFocus');
876
+ }
877
+ }
878
+ if (!node) {
879
+ throw new Error('Your focus-trap needs to have at least one focusable element');
880
+ }
881
+ return node;
882
+ };
883
+ var updateTabbableNodes = function updateTabbableNodes() {
884
+ state.containerGroups = state.containers.map(function (container) {
885
+ var tabbableNodes = tabbable(container, config.tabbableOptions);
886
+
887
+ // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
888
+ // are a superset of tabbable nodes since nodes with negative `tabindex` attributes
889
+ // are focusable but not tabbable
890
+ var focusableNodes = focusable(container, config.tabbableOptions);
891
+ var firstTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[0] : undefined;
892
+ var lastTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : undefined;
893
+ var firstDomTabbableNode = focusableNodes.find(function (node) {
894
+ return isTabbable(node);
895
+ });
896
+ var lastDomTabbableNode = focusableNodes.slice().reverse().find(function (node) {
897
+ return isTabbable(node);
898
+ });
899
+ var posTabIndexesFound = !!tabbableNodes.find(function (node) {
900
+ return getTabIndex(node) > 0;
901
+ });
902
+ return {
903
+ container: container,
904
+ tabbableNodes: tabbableNodes,
905
+ focusableNodes: focusableNodes,
906
+ /** True if at least one node with positive `tabindex` was found in this container. */
907
+ posTabIndexesFound: posTabIndexesFound,
908
+ /** First tabbable node in container, __tabindex__ order; `undefined` if none. */
909
+ firstTabbableNode: firstTabbableNode,
910
+ /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */
911
+ lastTabbableNode: lastTabbableNode,
912
+ // NOTE: DOM order is NOT NECESSARILY "document position" order, but figuring that out
913
+ // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
914
+ // because that API doesn't work with Shadow DOM as well as it should (@see
915
+ // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,
916
+ // to address an edge case related to positive tabindex support, this seems like a much easier,
917
+ // "close enough most of the time" alternative for positive tabindexes which should generally
918
+ // be avoided anyway...
919
+ /** First tabbable node in container, __DOM__ order; `undefined` if none. */
920
+ firstDomTabbableNode: firstDomTabbableNode,
921
+ /** Last tabbable node in container, __DOM__ order; `undefined` if none. */
922
+ lastDomTabbableNode: lastDomTabbableNode,
923
+ /**
924
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
925
+ * in this container, if any.
926
+ * @param {HTMLElement} node
927
+ * @param {boolean} [forward] True if going in forward tab order; false if going
928
+ * in reverse.
929
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
930
+ */
931
+ nextTabbableNode: function nextTabbableNode(node) {
932
+ var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
933
+ var nodeIdx = tabbableNodes.indexOf(node);
934
+ if (nodeIdx < 0) {
935
+ // either not tabbable nor focusable, or was focused but not tabbable (negative tabindex):
936
+ // since `node` should at least have been focusable, we assume that's the case and mimic
937
+ // what browsers do, which is set focus to the next node in __document position order__,
938
+ // regardless of positive tabindexes, if any -- and for reasons explained in the NOTE
939
+ // above related to `firstDomTabbable` and `lastDomTabbable` properties, we fall back to
940
+ // basic DOM order
941
+ if (forward) {
942
+ return focusableNodes.slice(focusableNodes.indexOf(node) + 1).find(function (el) {
943
+ return isTabbable(el);
944
+ });
945
+ }
946
+ return focusableNodes.slice(0, focusableNodes.indexOf(node)).reverse().find(function (el) {
947
+ return isTabbable(el);
948
+ });
949
+ }
950
+ return tabbableNodes[nodeIdx + (forward ? 1 : -1)];
951
+ }
952
+ };
953
+ });
954
+ state.tabbableGroups = state.containerGroups.filter(function (group) {
955
+ return group.tabbableNodes.length > 0;
956
+ });
957
+
958
+ // throw if no groups have tabbable nodes and we don't have a fallback focus node either
959
+ if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
960
+ ) {
961
+ throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
962
+ }
963
+
964
+ // NOTE: Positive tabindexes are only properly supported in single-container traps because
965
+ // doing it across multiple containers where tabindexes could be all over the place
966
+ // would require Tabbable to support multiple containers, would require additional
967
+ // specialized Shadow DOM support, and would require Tabbable's multi-container support
968
+ // to look at those containers in document position order rather than user-provided
969
+ // order (as they are treated in Focus-trap, for legacy reasons). See discussion on
970
+ // https://github.com/focus-trap/focus-trap/issues/375 for more details.
971
+ if (state.containerGroups.find(function (g) {
972
+ return g.posTabIndexesFound;
973
+ }) && state.containerGroups.length > 1) {
974
+ throw new Error("At least one node with a positive tabindex was found in one of your focus-trap's multiple containers. Positive tabindexes are only supported in single-container focus-traps.");
975
+ }
976
+ };
977
+
978
+ /**
979
+ * Gets the current activeElement. If it's a web-component and has open shadow-root
980
+ * it will recursively search inside shadow roots for the "true" activeElement.
981
+ *
982
+ * @param {Document | ShadowRoot} el
983
+ *
984
+ * @returns {HTMLElement} The element that currently has the focus
985
+ **/
986
+ var getActiveElement = function getActiveElement(el) {
987
+ var activeElement = el.activeElement;
988
+ if (!activeElement) {
989
+ return;
990
+ }
991
+ if (activeElement.shadowRoot && activeElement.shadowRoot.activeElement !== null) {
992
+ return getActiveElement(activeElement.shadowRoot);
993
+ }
994
+ return activeElement;
995
+ };
996
+ var tryFocus = function tryFocus(node) {
997
+ if (node === false) {
998
+ return;
999
+ }
1000
+ if (node === getActiveElement(document)) {
1001
+ return;
1002
+ }
1003
+ if (!node || !node.focus) {
1004
+ tryFocus(getInitialFocusNode());
1005
+ return;
1006
+ }
1007
+ node.focus({
1008
+ preventScroll: !!config.preventScroll
1009
+ });
1010
+ // NOTE: focus() API does not trigger focusIn event so set MRU node manually
1011
+ state.mostRecentlyFocusedNode = node;
1012
+ if (isSelectableInput(node)) {
1013
+ node.select();
1014
+ }
1015
+ };
1016
+ var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
1017
+ var node = getNodeForOption('setReturnFocus', previousActiveElement);
1018
+ return node ? node : node === false ? false : previousActiveElement;
1019
+ };
1020
+
1021
+ /**
1022
+ * Finds the next node (in either direction) where focus should move according to a
1023
+ * keyboard focus-in event.
1024
+ * @param {Object} params
1025
+ * @param {Node} [params.target] Known target __from which__ to navigate, if any.
1026
+ * @param {KeyboardEvent|FocusEvent} [params.event] Event to use if `target` isn't known (event
1027
+ * will be used to determine the `target`). Ignored if `target` is specified.
1028
+ * @param {boolean} [params.isBackward] True if focus should move backward.
1029
+ * @returns {Node|undefined} The next node, or `undefined` if a next node couldn't be
1030
+ * determined given the current state of the trap.
1031
+ */
1032
+ var findNextNavNode = function findNextNavNode(_ref2) {
1033
+ var target = _ref2.target,
1034
+ event = _ref2.event,
1035
+ _ref2$isBackward = _ref2.isBackward,
1036
+ isBackward = _ref2$isBackward === void 0 ? false : _ref2$isBackward;
1037
+ target = target || getActualTarget(event);
1038
+ updateTabbableNodes();
1039
+ var destinationNode = null;
1040
+ if (state.tabbableGroups.length > 0) {
1041
+ // make sure the target is actually contained in a group
1042
+ // NOTE: the target may also be the container itself if it's focusable
1043
+ // with tabIndex='-1' and was given initial focus
1044
+ var containerIndex = findContainerIndex(target, event);
1045
+ var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
1046
+ if (containerIndex < 0) {
1047
+ // target not found in any group: quite possible focus has escaped the trap,
1048
+ // so bring it back into...
1049
+ if (isBackward) {
1050
+ // ...the last node in the last group
1051
+ destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
1052
+ } else {
1053
+ // ...the first node in the first group
1054
+ destinationNode = state.tabbableGroups[0].firstTabbableNode;
1055
+ }
1056
+ } else if (isBackward) {
1057
+ // REVERSE
1058
+
1059
+ // is the target the first tabbable node in a group?
1060
+ var startOfGroupIndex = findIndex(state.tabbableGroups, function (_ref3) {
1061
+ var firstTabbableNode = _ref3.firstTabbableNode;
1062
+ return target === firstTabbableNode;
1063
+ });
1064
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
1065
+ // an exception case where the target is either the container itself, or
1066
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1067
+ // and user clicked on it or node was programmatically given focus)
1068
+ // and is not followed by any other tabbable node, in which
1069
+ // case, we should handle shift+tab as if focus were on the container's
1070
+ // first tabbable node, and go to the last tabbable node of the LAST group
1071
+ startOfGroupIndex = containerIndex;
1072
+ }
1073
+ if (startOfGroupIndex >= 0) {
1074
+ // YES: then shift+tab should go to the last tabbable node in the
1075
+ // previous group (and wrap around to the last tabbable node of
1076
+ // the LAST group if it's the first tabbable node of the FIRST group)
1077
+ var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
1078
+ var destinationGroup = state.tabbableGroups[destinationGroupIndex];
1079
+ destinationNode = getTabIndex(target) >= 0 ? destinationGroup.lastTabbableNode : destinationGroup.lastDomTabbableNode;
1080
+ } else if (!isTabEvent(event)) {
1081
+ // user must have customized the nav keys so we have to move focus manually _within_
1082
+ // the active group: do this based on the order determined by tabbable()
1083
+ destinationNode = containerGroup.nextTabbableNode(target, false);
1084
+ }
1085
+ } else {
1086
+ // FORWARD
1087
+
1088
+ // is the target the last tabbable node in a group?
1089
+ var lastOfGroupIndex = findIndex(state.tabbableGroups, function (_ref4) {
1090
+ var lastTabbableNode = _ref4.lastTabbableNode;
1091
+ return target === lastTabbableNode;
1092
+ });
1093
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
1094
+ // an exception case where the target is the container itself, or
1095
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1096
+ // and user clicked on it or node was programmatically given focus)
1097
+ // and is not followed by any other tabbable node, in which
1098
+ // case, we should handle tab as if focus were on the container's
1099
+ // last tabbable node, and go to the first tabbable node of the FIRST group
1100
+ lastOfGroupIndex = containerIndex;
1101
+ }
1102
+ if (lastOfGroupIndex >= 0) {
1103
+ // YES: then tab should go to the first tabbable node in the next
1104
+ // group (and wrap around to the first tabbable node of the FIRST
1105
+ // group if it's the last tabbable node of the LAST group)
1106
+ var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
1107
+ var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
1108
+ destinationNode = getTabIndex(target) >= 0 ? _destinationGroup.firstTabbableNode : _destinationGroup.firstDomTabbableNode;
1109
+ } else if (!isTabEvent(event)) {
1110
+ // user must have customized the nav keys so we have to move focus manually _within_
1111
+ // the active group: do this based on the order determined by tabbable()
1112
+ destinationNode = containerGroup.nextTabbableNode(target);
1113
+ }
1114
+ }
1115
+ } else {
1116
+ // no groups available
1117
+ // NOTE: the fallbackFocus option does not support returning false to opt-out
1118
+ destinationNode = getNodeForOption('fallbackFocus');
1119
+ }
1120
+ return destinationNode;
1121
+ };
1122
+
1123
+ // This needs to be done on mousedown and touchstart instead of click
1124
+ // so that it precedes the focus event.
1125
+ var checkPointerDown = function checkPointerDown(e) {
1126
+ var target = getActualTarget(e);
1127
+ if (findContainerIndex(target, e) >= 0) {
1128
+ // allow the click since it ocurred inside the trap
1129
+ return;
1130
+ }
1131
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1132
+ // immediately deactivate the trap
1133
+ trap.deactivate({
1134
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
1135
+ // which will result in the outside click setting focus to the node
1136
+ // that was clicked (and if not focusable, to "nothing"); by setting
1137
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
1138
+ // on activation (or the configured `setReturnFocus` node), whether the
1139
+ // outside click was on a focusable node or not
1140
+ returnFocus: config.returnFocusOnDeactivate
1141
+ });
1142
+ return;
1143
+ }
1144
+
1145
+ // This is needed for mobile devices.
1146
+ // (If we'll only let `click` events through,
1147
+ // then on mobile they will be blocked anyways if `touchstart` is blocked.)
1148
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1149
+ // allow the click outside the trap to take place
1150
+ return;
1151
+ }
1152
+
1153
+ // otherwise, prevent the click
1154
+ e.preventDefault();
1155
+ };
1156
+
1157
+ // In case focus escapes the trap for some strange reason, pull it back in.
1158
+ // NOTE: the focusIn event is NOT cancelable, so if focus escapes, it may cause unexpected
1159
+ // scrolling if the node that got focused was out of view; there's nothing we can do to
1160
+ // prevent that from happening by the time we discover that focus escaped
1161
+ var checkFocusIn = function checkFocusIn(event) {
1162
+ var target = getActualTarget(event);
1163
+ var targetContained = findContainerIndex(target, event) >= 0;
1164
+
1165
+ // In Firefox when you Tab out of an iframe the Document is briefly focused.
1166
+ if (targetContained || target instanceof Document) {
1167
+ if (targetContained) {
1168
+ state.mostRecentlyFocusedNode = target;
1169
+ }
1170
+ } else {
1171
+ // escaped! pull it back in to where it just left
1172
+ event.stopImmediatePropagation();
1173
+
1174
+ // focus will escape if the MRU node had a positive tab index and user tried to nav forward;
1175
+ // it will also escape if the MRU node had a 0 tab index and user tried to nav backward
1176
+ // toward a node with a positive tab index
1177
+ var nextNode; // next node to focus, if we find one
1178
+ var navAcrossContainers = true;
1179
+ if (state.mostRecentlyFocusedNode) {
1180
+ if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {
1181
+ // MRU container index must be >=0 otherwise we wouldn't have it as an MRU node...
1182
+ var mruContainerIdx = findContainerIndex(state.mostRecentlyFocusedNode);
1183
+ // there MAY not be any tabbable nodes in the container if there are at least 2 containers
1184
+ // and the MRU node is focusable but not tabbable (focus-trap requires at least 1 container
1185
+ // with at least one tabbable node in order to function, so this could be the other container
1186
+ // with nothing tabbable in it)
1187
+ var tabbableNodes = state.containerGroups[mruContainerIdx].tabbableNodes;
1188
+ if (tabbableNodes.length > 0) {
1189
+ // MRU tab index MAY not be found if the MRU node is focusable but not tabbable
1190
+ var mruTabIdx = tabbableNodes.findIndex(function (node) {
1191
+ return node === state.mostRecentlyFocusedNode;
1192
+ });
1193
+ if (mruTabIdx >= 0) {
1194
+ if (config.isKeyForward(state.recentNavEvent)) {
1195
+ if (mruTabIdx + 1 < tabbableNodes.length) {
1196
+ nextNode = tabbableNodes[mruTabIdx + 1];
1197
+ navAcrossContainers = false;
1198
+ }
1199
+ // else, don't wrap within the container as focus should move to next/previous
1200
+ // container
1201
+ } else {
1202
+ if (mruTabIdx - 1 >= 0) {
1203
+ nextNode = tabbableNodes[mruTabIdx - 1];
1204
+ navAcrossContainers = false;
1205
+ }
1206
+ // else, don't wrap within the container as focus should move to next/previous
1207
+ // container
1208
+ }
1209
+ // else, don't find in container order without considering direction too
1210
+ }
1211
+ }
1212
+ // else, no tabbable nodes in that container (which means we must have at least one other
1213
+ // container with at least one tabbable node in it, otherwise focus-trap would've thrown
1214
+ // an error the last time updateTabbableNodes() was run): find next node among all known
1215
+ // containers
1216
+ } else {
1217
+ // check to see if there's at least one tabbable node with a positive tab index inside
1218
+ // the trap because focus seems to escape when navigating backward from a tabbable node
1219
+ // with tabindex=0 when this is the case (instead of wrapping to the tabbable node with
1220
+ // the greatest positive tab index like it should)
1221
+ if (!state.containerGroups.some(function (g) {
1222
+ return g.tabbableNodes.some(function (n) {
1223
+ return getTabIndex(n) > 0;
1224
+ });
1225
+ })) {
1226
+ // no containers with tabbable nodes with positive tab indexes which means the focus
1227
+ // escaped for some other reason and we should just execute the fallback to the
1228
+ // MRU node or initial focus node, if any
1229
+ navAcrossContainers = false;
1230
+ }
1231
+ }
1232
+ } else {
1233
+ // no MRU node means we're likely in some initial condition when the trap has just
1234
+ // been activated and initial focus hasn't been given yet, in which case we should
1235
+ // fall through to trying to focus the initial focus node, which is what should
1236
+ // happen below at this point in the logic
1237
+ navAcrossContainers = false;
1238
+ }
1239
+ if (navAcrossContainers) {
1240
+ nextNode = findNextNavNode({
1241
+ // move FROM the MRU node, not event-related node (which will be the node that is
1242
+ // outside the trap causing the focus escape we're trying to fix)
1243
+ target: state.mostRecentlyFocusedNode,
1244
+ isBackward: config.isKeyBackward(state.recentNavEvent)
1245
+ });
1246
+ }
1247
+ if (nextNode) {
1248
+ tryFocus(nextNode);
1249
+ } else {
1250
+ tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
1251
+ }
1252
+ }
1253
+ state.recentNavEvent = undefined; // clear
1254
+ };
1255
+
1256
+ // Hijack key nav events on the first and last focusable nodes of the trap,
1257
+ // in order to prevent focus from escaping. If it escapes for even a
1258
+ // moment it can end up scrolling the page and causing confusion so we
1259
+ // kind of need to capture the action at the keydown phase.
1260
+ var checkKeyNav = function checkKeyNav(event) {
1261
+ var isBackward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1262
+ state.recentNavEvent = event;
1263
+ var destinationNode = findNextNavNode({
1264
+ event: event,
1265
+ isBackward: isBackward
1266
+ });
1267
+ if (destinationNode) {
1268
+ if (isTabEvent(event)) {
1269
+ // since tab natively moves focus, we wouldn't have a destination node unless we
1270
+ // were on the edge of a container and had to move to the next/previous edge, in
1271
+ // which case we want to prevent default to keep the browser from moving focus
1272
+ // to where it normally would
1273
+ event.preventDefault();
1274
+ }
1275
+ tryFocus(destinationNode);
1276
+ }
1277
+ // else, let the browser take care of [shift+]tab and move the focus
1278
+ };
1279
+
1280
+ var checkKey = function checkKey(event) {
1281
+ if (isEscapeEvent(event) && valueOrHandler(config.escapeDeactivates, event) !== false) {
1282
+ event.preventDefault();
1283
+ trap.deactivate();
1284
+ return;
1285
+ }
1286
+ if (config.isKeyForward(event) || config.isKeyBackward(event)) {
1287
+ checkKeyNav(event, config.isKeyBackward(event));
1288
+ }
1289
+ };
1290
+ var checkClick = function checkClick(e) {
1291
+ var target = getActualTarget(e);
1292
+ if (findContainerIndex(target, e) >= 0) {
1293
+ return;
1294
+ }
1295
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1296
+ return;
1297
+ }
1298
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1299
+ return;
1300
+ }
1301
+ e.preventDefault();
1302
+ e.stopImmediatePropagation();
1303
+ };
1304
+
1305
+ //
1306
+ // EVENT LISTENERS
1307
+ //
1308
+
1309
+ var addListeners = function addListeners() {
1310
+ if (!state.active) {
1311
+ return;
1312
+ }
1313
+
1314
+ // There can be only one listening focus trap at a time
1315
+ activeFocusTraps.activateTrap(trapStack, trap);
1316
+
1317
+ // Delay ensures that the focused element doesn't capture the event
1318
+ // that caused the focus trap activation.
1319
+ state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
1320
+ tryFocus(getInitialFocusNode());
1321
+ }) : tryFocus(getInitialFocusNode());
1322
+ doc.addEventListener('focusin', checkFocusIn, true);
1323
+ doc.addEventListener('mousedown', checkPointerDown, {
1324
+ capture: true,
1325
+ passive: false
1326
+ });
1327
+ doc.addEventListener('touchstart', checkPointerDown, {
1328
+ capture: true,
1329
+ passive: false
1330
+ });
1331
+ doc.addEventListener('click', checkClick, {
1332
+ capture: true,
1333
+ passive: false
1334
+ });
1335
+ doc.addEventListener('keydown', checkKey, {
1336
+ capture: true,
1337
+ passive: false
1338
+ });
1339
+ return trap;
1340
+ };
1341
+ var removeListeners = function removeListeners() {
1342
+ if (!state.active) {
1343
+ return;
1344
+ }
1345
+ doc.removeEventListener('focusin', checkFocusIn, true);
1346
+ doc.removeEventListener('mousedown', checkPointerDown, true);
1347
+ doc.removeEventListener('touchstart', checkPointerDown, true);
1348
+ doc.removeEventListener('click', checkClick, true);
1349
+ doc.removeEventListener('keydown', checkKey, true);
1350
+ return trap;
1351
+ };
1352
+
1353
+ //
1354
+ // MUTATION OBSERVER
1355
+ //
1356
+
1357
+ var checkDomRemoval = function checkDomRemoval(mutations) {
1358
+ var isFocusedNodeRemoved = mutations.some(function (mutation) {
1359
+ var removedNodes = Array.from(mutation.removedNodes);
1360
+ return removedNodes.some(function (node) {
1361
+ return node === state.mostRecentlyFocusedNode;
1362
+ });
1363
+ });
1364
+
1365
+ // If the currently focused is removed then browsers will move focus to the
1366
+ // <body> element. If this happens, try to move focus back into the trap.
1367
+ if (isFocusedNodeRemoved) {
1368
+ tryFocus(getInitialFocusNode());
1369
+ }
1370
+ };
1371
+
1372
+ // Use MutationObserver - if supported - to detect if focused node is removed
1373
+ // from the DOM.
1374
+ var mutationObserver = typeof window !== 'undefined' && 'MutationObserver' in window ? new MutationObserver(checkDomRemoval) : undefined;
1375
+ var updateObservedNodes = function updateObservedNodes() {
1376
+ if (!mutationObserver) {
1377
+ return;
1378
+ }
1379
+ mutationObserver.disconnect();
1380
+ if (state.active && !state.paused) {
1381
+ state.containers.map(function (container) {
1382
+ mutationObserver.observe(container, {
1383
+ subtree: true,
1384
+ childList: true
1385
+ });
1386
+ });
1387
+ }
1388
+ };
1389
+
1390
+ //
1391
+ // TRAP DEFINITION
1392
+ //
1393
+
1394
+ trap = {
1395
+ get active() {
1396
+ return state.active;
1397
+ },
1398
+ get paused() {
1399
+ return state.paused;
1400
+ },
1401
+ activate: function activate(activateOptions) {
1402
+ if (state.active) {
1403
+ return this;
1404
+ }
1405
+ var onActivate = getOption(activateOptions, 'onActivate');
1406
+ var onPostActivate = getOption(activateOptions, 'onPostActivate');
1407
+ var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
1408
+ if (!checkCanFocusTrap) {
1409
+ updateTabbableNodes();
1410
+ }
1411
+ state.active = true;
1412
+ state.paused = false;
1413
+ state.nodeFocusedBeforeActivation = doc.activeElement;
1414
+ onActivate === null || onActivate === void 0 || onActivate();
1415
+ var finishActivation = function finishActivation() {
1416
+ if (checkCanFocusTrap) {
1417
+ updateTabbableNodes();
1418
+ }
1419
+ addListeners();
1420
+ updateObservedNodes();
1421
+ onPostActivate === null || onPostActivate === void 0 || onPostActivate();
1422
+ };
1423
+ if (checkCanFocusTrap) {
1424
+ checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
1425
+ return this;
1426
+ }
1427
+ finishActivation();
1428
+ return this;
1429
+ },
1430
+ deactivate: function deactivate(deactivateOptions) {
1431
+ if (!state.active) {
1432
+ return this;
1433
+ }
1434
+ var options = _objectSpread2({
1435
+ onDeactivate: config.onDeactivate,
1436
+ onPostDeactivate: config.onPostDeactivate,
1437
+ checkCanReturnFocus: config.checkCanReturnFocus
1438
+ }, deactivateOptions);
1439
+ clearTimeout(state.delayInitialFocusTimer); // noop if undefined
1440
+ state.delayInitialFocusTimer = undefined;
1441
+ removeListeners();
1442
+ state.active = false;
1443
+ state.paused = false;
1444
+ updateObservedNodes();
1445
+ activeFocusTraps.deactivateTrap(trapStack, trap);
1446
+ var onDeactivate = getOption(options, 'onDeactivate');
1447
+ var onPostDeactivate = getOption(options, 'onPostDeactivate');
1448
+ var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
1449
+ var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
1450
+ onDeactivate === null || onDeactivate === void 0 || onDeactivate();
1451
+ var finishDeactivation = function finishDeactivation() {
1452
+ delay(function () {
1453
+ if (returnFocus) {
1454
+ tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1455
+ }
1456
+ onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate();
1457
+ });
1458
+ };
1459
+ if (returnFocus && checkCanReturnFocus) {
1460
+ checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
1461
+ return this;
1462
+ }
1463
+ finishDeactivation();
1464
+ return this;
1465
+ },
1466
+ pause: function pause(pauseOptions) {
1467
+ if (state.paused || !state.active) {
1468
+ return this;
1469
+ }
1470
+ var onPause = getOption(pauseOptions, 'onPause');
1471
+ var onPostPause = getOption(pauseOptions, 'onPostPause');
1472
+ state.paused = true;
1473
+ onPause === null || onPause === void 0 || onPause();
1474
+ removeListeners();
1475
+ updateObservedNodes();
1476
+ onPostPause === null || onPostPause === void 0 || onPostPause();
1477
+ return this;
1478
+ },
1479
+ unpause: function unpause(unpauseOptions) {
1480
+ if (!state.paused || !state.active) {
1481
+ return this;
1482
+ }
1483
+ var onUnpause = getOption(unpauseOptions, 'onUnpause');
1484
+ var onPostUnpause = getOption(unpauseOptions, 'onPostUnpause');
1485
+ state.paused = false;
1486
+ onUnpause === null || onUnpause === void 0 || onUnpause();
1487
+ updateTabbableNodes();
1488
+ addListeners();
1489
+ updateObservedNodes();
1490
+ onPostUnpause === null || onPostUnpause === void 0 || onPostUnpause();
1491
+ return this;
1492
+ },
1493
+ updateContainerElements: function updateContainerElements(containerElements) {
1494
+ var elementsAsArray = [].concat(containerElements).filter(Boolean);
1495
+ state.containers = elementsAsArray.map(function (element) {
1496
+ return typeof element === 'string' ? doc.querySelector(element) : element;
1497
+ });
1498
+ if (state.active) {
1499
+ updateTabbableNodes();
1500
+ }
1501
+ updateObservedNodes();
1502
+ return this;
1503
+ }
1504
+ };
1505
+
1506
+ // initialize container elements
1507
+ trap.updateContainerElements(elements);
1508
+ return trap;
1509
+ };
1510
+
1511
+ const FocusTrap = class {
1512
+ constructor(hostRef) {
1513
+ index.registerInstance(this, hostRef);
1514
+ this.active = false;
1515
+ this.trap = undefined;
1516
+ }
1517
+ handleActiveChange(active) {
1518
+ this.toggleTrap(active);
1519
+ }
1520
+ connectedCallback() {
1521
+ var _a;
1522
+ if (!this.trap) {
1523
+ this.trap = createFocusTrap((_a = this.host) === null || _a === void 0 ? void 0 : _a.firstElementChild, {
1524
+ allowOutsideClick: true,
1525
+ });
1526
+ }
1527
+ }
1528
+ componentDidLoad() {
1529
+ this.toggleTrap(this.active);
1530
+ }
1531
+ disconnectedCallback() {
1532
+ var _a;
1533
+ (_a = this.trap) === null || _a === void 0 ? void 0 : _a.deactivate();
1534
+ }
1535
+ toggleTrap(active) {
1536
+ var _a, _b;
1537
+ if (active) {
1538
+ (_a = this.trap) === null || _a === void 0 ? void 0 : _a.activate();
1539
+ }
1540
+ else {
1541
+ (_b = this.trap) === null || _b === void 0 ? void 0 : _b.deactivate();
1542
+ }
1543
+ }
1544
+ render() {
1545
+ return (index.h(index.Host, { key: '40e6912cae0ae3e92b46cf4d251e1b1a47320d0f' }, index.h("slot", { key: '39fe2c6ad0e0b419090ac8270840a83e49c286cf' })));
1546
+ }
1547
+ get host() { return index.getElement(this); }
1548
+ static get watchers() { return {
1549
+ "active": ["handleActiveChange"]
1550
+ }; }
1551
+ };
1552
+
1553
+ exports.focus_trap = FocusTrap;