@roadtrip/components 3.41.1 → 3.42.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 (51) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/road-alert.cjs.entry.js +1 -1
  3. package/dist/cjs/road-alert.cjs.entry.js.map +1 -1
  4. package/dist/cjs/road-badge_14.cjs.entry.js +1613 -13
  5. package/dist/cjs/road-badge_14.cjs.entry.js.map +1 -1
  6. package/dist/cjs/road-card.cjs.entry.js +46 -16
  7. package/dist/cjs/road-card.cjs.entry.js.map +1 -1
  8. package/dist/cjs/roadtrip.cjs.js +1 -1
  9. package/dist/collection/components/alert/alert.css +1 -1
  10. package/dist/collection/components/button/button.css +75 -5
  11. package/dist/collection/components/button/button.js +26 -1
  12. package/dist/collection/components/button/button.js.map +1 -1
  13. package/dist/collection/components/button/button.stories.js +67 -0
  14. package/dist/collection/components/card/card.css +58 -11
  15. package/dist/collection/components/card/card.js +90 -20
  16. package/dist/collection/components/card/card.js.map +1 -1
  17. package/dist/collection/components/card/card.stories.js +330 -75
  18. package/dist/collection/components/drawer/drawer.css +0 -3
  19. package/dist/collection/components/drawer/drawer.js +31 -10
  20. package/dist/collection/components/drawer/drawer.js.map +1 -1
  21. package/dist/esm/loader.js +1 -1
  22. package/dist/esm/road-alert.entry.js +1 -1
  23. package/dist/esm/road-alert.entry.js.map +1 -1
  24. package/dist/esm/road-badge_14.entry.js +1613 -13
  25. package/dist/esm/road-badge_14.entry.js.map +1 -1
  26. package/dist/esm/road-card.entry.js +46 -16
  27. package/dist/esm/road-card.entry.js.map +1 -1
  28. package/dist/esm/roadtrip.js +1 -1
  29. package/dist/html.html-data.json +12 -0
  30. package/dist/roadtrip/p-24ea87a9.entry.js +18 -0
  31. package/dist/roadtrip/p-24ea87a9.entry.js.map +1 -0
  32. package/dist/roadtrip/p-294a4a83.entry.js +2 -0
  33. package/dist/roadtrip/p-294a4a83.entry.js.map +1 -0
  34. package/dist/roadtrip/p-d89d49b2.entry.js +2 -0
  35. package/dist/roadtrip/p-d89d49b2.entry.js.map +1 -0
  36. package/dist/roadtrip/roadtrip.css +1 -1
  37. package/dist/roadtrip/roadtrip.esm.js +1 -1
  38. package/dist/roadtrip/roadtrip.esm.js.map +1 -1
  39. package/dist/types/components/button/button.d.ts +4 -0
  40. package/dist/types/components/card/card.d.ts +15 -5
  41. package/dist/types/components/drawer/drawer.d.ts +9 -4
  42. package/dist/types/components.d.ts +28 -4
  43. package/hydrate/index.js +1764 -130
  44. package/hydrate/index.mjs +1764 -130
  45. package/package.json +5 -4
  46. package/dist/roadtrip/p-07db2ee1.entry.js +0 -10
  47. package/dist/roadtrip/p-07db2ee1.entry.js.map +0 -1
  48. package/dist/roadtrip/p-36f8563a.entry.js +0 -2
  49. package/dist/roadtrip/p-36f8563a.entry.js.map +0 -1
  50. package/dist/roadtrip/p-4182495e.entry.js +0 -2
  51. package/dist/roadtrip/p-4182495e.entry.js.map +0 -1
@@ -36,7 +36,7 @@ const Badge = class {
36
36
  };
37
37
  Badge.style = RoadBadgeStyle0;
38
38
 
39
- const buttonCss = ":host{--border-radius:0.25rem;--font-size:var(--road-button-medium);--margin-bottom:1rem;--padding-start:1.5rem;--padding-end:1.5rem;box-sizing:border-box;display:inline-flex;display:-webkit-inline-flex;align-items:center;justify-content:center;height:3rem;padding:0;margin-bottom:var(--margin-bottom);font-family:var(--road-font, sans-serif);font-size:var(--font-size);font-weight:700;line-height:1.375;color:var(--road-grey-10);text-decoration:none;white-space:nowrap;vertical-align:middle;background:transparent;border:1px solid transparent;border-radius:var(--border-radius);transition:background 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms}:host(:hover){text-decoration:none}:host(.focus-visible){text-decoration:underline;outline:auto}.button-native{position:relative;display:flex;flex-flow:row nowrap;flex-shrink:0;align-items:center;justify-content:center;width:100%;height:100%;padding:0 var(--padding-end) 0 var(--padding-start);margin:0;font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;color:inherit;text-align:inherit;text-decoration:none;text-indent:inherit;text-overflow:inherit;text-transform:inherit;letter-spacing:inherit;white-space:inherit;cursor:pointer;background:transparent;border:none;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}:host(.btn-default:not([disabled]).focus-visible){background:var(--road-grey-80)}:host(.btn-primary){color:var(--road-on-button-primary);background:var(--road-button-primary)}:host(.btn-primary) ::slotted(road-icon){color:var(--road-on-button-primary)}:host(.btn-primary:not([disabled]):hover),:host(.btn-primary:not([disabled]).focus-visible){background:var(--road-button-primary-variant);outline:0}:host(.btn-secondary){color:var(--road-on-button-secondary);background:var(--road-button-secondary)}:host(.btn-secondary) ::slotted(road-icon){color:var(--road-on-button-secondary)}:host(.btn-secondary:not([disabled]):hover),:host(.btn-secondary:not([disabled]).focus-visible){background:var(--road-button-secondary-variant)}:host(.btn-destructive){color:var(--road-on-button-destructive-primary);background:var(--road-button-destructive-primary)}:host(.btn-destructive) ::slotted(road-icon){color:var(--road-on-button-destructive-primary)}:host(.btn-destructive:not([disabled]):hover),:host(.btn-destructive:not([disabled]).focus-visible){background:var(--road-button-destructive-primary-variant)}:host(.btn-link){font-weight:400;color:var(--road-link-primary);text-decoration:underline;background:transparent}:host(.btn-link:not([disabled]):hover),:host(.btn-link:not([disabled]).focus-visible){color:var(--road-primary-30)}:host(.btn-outline-primary),:host(.btn-outline-secondary),:host(.btn-outline-default),:host(.btn-outline-destructive){background:transparent}:host(.btn-outline-default){color:var(--road-on-surface-weak);background:var(--road-surface);border-color:var(--road-input-outline)}:host(.btn-outline-default) ::slotted(road-icon){color:var(--road-on-surface-weak)}:host(.btn-outline-default:hover),:host(.btn-outline-default.focus-visible){background:var(--road-grey-80)}:host(.btn-ghost){color:var(--road-on-button-ghost)}:host(.btn-ghost) ::slotted(road-icon){color:var(--road-on-button-ghost)}:host(.btn-ghost:hover),:host(.btn-ghost.focus-visible){background:var(--road-button-ghost-variant)}:host([aria-disabled].btn-outline-primary){background:none}:host(.btn-outline-primary){color:var(--road-button-primary);border-color:var(--road-button-tertiary-outline)}:host(.btn-outline-primary) ::slotted(road-icon){color:var(--road-button-primary)}:host(.btn-outline-primary:hover),:host(.btn-outline-primary.focus-visible){background:var(--road-button-tertiary-variant)}:host(.btn-outline-secondary){color:var(--road-button-secondary);border-color:var(--road-button-secondary)}:host(.btn-outline-secondary) ::slotted(road-icon){color:var(--road-button-secondary)}:host(.btn-outline-secondary:hover),:host(.btn-outline-secondary.focus-visible){background:var(--road-button-tertiary-variant)}:host(.btn-outline-destructive){color:var(--road-on-button-destructive-secondary);border-color:var(--road-button-destructive-outline)}:host(.btn-outline-destructive) ::slotted(road-icon){color:var(--road-on-button-destructive-secondary)}:host(.btn-outline-destructive:hover),:host(.btn-outline-destructive.focus-visible){background:var(--road-button-destructive-secondary-variant)}:host([aria-disabled]){color:var(--road-on-surface-disabled);pointer-events:none;cursor:not-allowed;background-color:var(--road-surface-disabled);border-color:1px solid var(--road-surface-disabled)}:host([aria-disabled]) ::slotted(road-icon){color:var(--road-on-surface-disabled)}.button-native:disabled{cursor:not-allowed}::slotted([slot=\"start\"]){margin-right:0.5rem}::slotted([slot=\"end\"]){margin-left:0.5rem}:host(.btn-xl){height:3.5rem}:host(.btn-xl) ::slotted(road-icon){width:2rem;height:2rem}:host(.btn-icon.btn-xl){width:56px}:host(.btn-lg){height:3rem}:host(.btn-lg) ::slotted(road-icon){width:2rem;height:2rem}:host(.btn-icon.btn-lg){width:48px}:host(.btn-md){--font-size:var(--road-font-size-14);height:2.5rem}:host(.btn-md) ::slotted(road-icon){width:1.5rem;height:1.5rem}:host(.btn-icon.btn-md){width:40px}:host(.btn-sm){--font-size:var(--road-font-size-14);height:2rem}:host(.btn-sm) ::slotted(road-icon){width:1.25rem;height:1.25rem}:host(.btn-icon.btn-sm){width:32px}:host(.btn-block){width:100%}:host(.btn-icon) .button-native{padding:0}::slotted(road-badge){position:absolute;top:4px;left:calc(50% + 0.375rem);box-sizing:border-box;height:auto}";
39
+ const buttonCss = ":host{--border-radius:0.25rem;--font-size:var(--road-button-medium);--margin-bottom:1rem;--padding-start:1.5rem;--padding-end:1.5rem;box-sizing:border-box;display:inline-flex;display:-webkit-inline-flex;align-items:center;justify-content:center;height:3rem;padding:0;margin-bottom:var(--margin-bottom);font-family:var(--road-font, sans-serif);font-size:var(--font-size);font-weight:700;line-height:1.375;color:var(--road-grey-10);text-decoration:none;white-space:nowrap;vertical-align:middle;background:transparent;border:1px solid transparent;border-radius:var(--border-radius);transition:background 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms}:host(:hover){text-decoration:none}:host(.focus-visible){text-decoration:underline;outline:auto}.button-native{position:relative;display:flex;flex-flow:row nowrap;flex-shrink:0;align-items:center;justify-content:center;width:100%;height:100%;padding:0 var(--padding-end) 0 var(--padding-start);margin:0;font-family:inherit;font-size:inherit;font-style:inherit;font-weight:inherit;color:inherit;text-align:inherit;text-decoration:none;text-indent:inherit;text-overflow:inherit;text-transform:inherit;letter-spacing:inherit;white-space:inherit;cursor:pointer;background:transparent;border:none;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}:host(.btn-default:not([disabled]).focus-visible){background:var(--road-grey-80)}:host(.btn-primary){color:var(--road-on-button-primary);background:var(--road-button-primary)}:host(.btn-primary) ::slotted(road-icon){color:var(--road-on-button-primary)}:host(.btn-primary:not([disabled]):hover),:host(.btn-primary:not([disabled]).focus-visible){background:var(--road-button-primary-variant);outline:0}:host(.btn-secondary){color:var(--road-on-button-secondary);background:var(--road-button-secondary)}:host(.btn-secondary) ::slotted(road-icon){color:var(--road-on-button-secondary)}:host(.btn-secondary:not([disabled]):hover),:host(.btn-secondary:not([disabled]).focus-visible){background:var(--road-button-secondary-variant)}:host(.btn-destructive){color:var(--road-on-button-destructive-primary);background:var(--road-button-destructive-primary)}:host(.btn-destructive) ::slotted(road-icon){color:var(--road-on-button-destructive-primary)}:host(.btn-destructive:not([disabled]):hover),:host(.btn-destructive:not([disabled]).focus-visible){background:var(--road-button-destructive-primary-variant)}:host(.btn-link){font-weight:400;color:var(--road-link-primary);text-decoration:underline;background:transparent}:host(.btn-link:not([disabled]):hover),:host(.btn-link:not([disabled]).focus-visible){color:var(--road-primary-30)}:host(.btn-outline-primary),:host(.btn-outline-secondary),:host(.btn-outline-default),:host(.btn-outline-destructive){background:transparent}:host(.btn-outline-default){color:var(--road-on-surface-weak);background:var(--road-surface);border-color:var(--road-input-outline)}:host(.btn-outline-default) ::slotted(road-icon){color:var(--road-on-surface-weak)}:host(.btn-outline-default:hover),:host(.btn-outline-default.focus-visible){background:var(--road-grey-80)}:host(.btn-outline-default.focus-visible),:host(.btn-outline-default:focus-visible){background:var(--road-surface-disabled);outline-offset:1px;outline:2px solid var(--road-outline)}:host(.btn-outline-default) .button-native:focus,:host(.btn-outline-default) .button-native:focus-visible{outline:none}:host(.btn-ghost){color:var(--road-on-button-ghost)}:host(.btn-ghost:not(.btn-inverse):hover){background:var(--road-button-ghost-variant)}:host(.btn-ghost:not(.btn-inverse).focus-visible),:host(.btn-ghost:not(.btn-inverse):focus-visible){background:var(--road-button-ghost-variant);outline-offset:1px;outline:2px solid var(--road-button-ghost-variant)}:host(.btn-ghost:not(.btn-inverse)) .button-native:focus,:host(.btn-ghost:not(.btn-inverse)) .button-native:focus-visible{outline:none}:host(.btn-outline-ghost:not(.btn-inverse):hover){background:var(--road-surface-disabled)}:host(.btn-outline-ghost:not(.btn-inverse).focus-visible),:host(.btn-outline-ghost:not(.btn-inverse):focus-visible){border:1px solid var(--road-outline);background:var(--road-surface-disabled);outline-offset:1px;outline:2px solid var(--road-outline)}:host(.btn-outline-ghost:not(.btn-inverse)) .button-native:focus,:host(.btn-outline-ghost:not(.btn-inverse)) .button-native:focus-visible{outline:none}:host(.btn-inverse) .button-native:focus,:host(.btn-inverse) .button-native:focus-visible{outline:none}:host(.btn-inverse) ::slotted(road-icon){color:var(--road-on-button-ghost)}:host(.btn-inverse:hover){outline:1px solid var(--road-on-header-surface)}:host(.btn-inverse.focus-visible),:host(.btn-inverse:focus-visible){outline:thick double var(--road-on-header-surface)}:host([aria-disabled].btn-inverse){border:1px solid var(--road-on-header-surface-disabled);background:var(--road-on-header-surface-disabled)}:host([aria-disabled].btn-inverse) ::slotted(road-icon){color:var(--road-on-header-surface-disabled)}:host([aria-disabled].btn-outline-primary){background:none}:host(.btn-outline-primary){color:var(--road-button-primary);border-color:var(--road-button-tertiary-outline)}:host(.btn-outline-primary) ::slotted(road-icon){color:var(--road-button-primary)}:host(.btn-outline-primary:hover),:host(.btn-outline-primary.focus-visible){background:var(--road-button-tertiary-variant)}:host(.btn-outline-secondary){color:var(--road-button-secondary);border-color:var(--road-button-secondary)}:host(.btn-outline-secondary) ::slotted(road-icon){color:var(--road-button-secondary)}:host(.btn-outline-secondary:hover),:host(.btn-outline-secondary.focus-visible){background:var(--road-button-tertiary-variant)}:host(.btn-outline-destructive){color:var(--road-on-button-destructive-secondary);border-color:var(--road-button-destructive-outline)}:host(.btn-outline-destructive) ::slotted(road-icon){color:var(--road-on-button-destructive-secondary)}:host(.btn-outline-destructive:hover),:host(.btn-outline-destructive.focus-visible){background:var(--road-button-destructive-secondary-variant)}:host([aria-disabled]){color:var(--road-on-surface-disabled);pointer-events:none;cursor:not-allowed;background-color:var(--road-surface-disabled);border-color:1px solid var(--road-surface-disabled)}:host([aria-disabled]) ::slotted(road-icon){color:var(--road-on-surface-disabled)}.button-native:disabled{cursor:not-allowed}::slotted([slot=\"start\"]){margin-right:0.5rem}::slotted([slot=\"end\"]){margin-left:0.5rem}:host(.btn-xl){height:3.5rem}:host(.btn-xl) ::slotted(road-icon){width:2rem;height:2rem}:host(.btn-icon.btn-xl){width:56px}:host(.btn-lg){height:3rem}:host(.btn-lg) ::slotted(road-icon){width:2rem;height:2rem}:host(.btn-icon.btn-lg){width:48px}:host(.btn-md){--font-size:var(--road-font-size-14);height:2.5rem}:host(.btn-md) ::slotted(road-icon){width:1.5rem;height:1.5rem}:host(.btn-icon.btn-md){width:40px}:host(.btn-sm){--font-size:var(--road-font-size-14);height:2rem}:host(.btn-sm) ::slotted(road-icon){width:1.25rem;height:1.25rem}:host(.btn-icon.btn-sm){width:32px}:host(.btn-block){width:100%}:host(.btn-icon) .button-native{padding:0}::slotted(road-badge){position:absolute;top:4px;left:calc(50% + 0.375rem);box-sizing:border-box;height:auto}";
40
40
  const RoadButtonStyle0 = buttonCss;
41
41
 
42
42
  const Button = class {
@@ -58,6 +58,10 @@ const Button = class {
58
58
  * The type of the button.
59
59
  */
60
60
  this.buttonType = 'button';
61
+ /**
62
+ * If `true`, the button will use inverse colors (when in headers or dark backgrounds).
63
+ */
64
+ this.inverse = false;
61
65
  /**
62
66
  * If `true`, display only an icon in the button.
63
67
  */
@@ -115,7 +119,8 @@ const Button = class {
115
119
  const sizeClass = this.size !== undefined ? `btn-${this.size}` : '';
116
120
  const expandClass = this.expand ? 'btn-block' : '';
117
121
  const iconOnlyClass = this.iconOnly ? 'btn-icon' : '';
118
- return (index.h(index.Host, { key: '79d849dd58e95934ff3ab4c9c5b5edd65fb4c899', class: [colorClass, sizeClass, expandClass, iconOnlyClass].filter(Boolean).join(' '), onClick: this.onClick, "aria-disabled": disabled ? 'true' : null }, index.h(TagType, Object.assign({ key: '764448aaf4c6c221563aa2d9b00c0b55c0fdea21' }, attrs, { class: "button-native", part: "native", disabled: disabled, onFocus: this.onFocus, onBlur: this.onBlur }), index.h("slot", { key: '54a7978f6da8b45b48db0ab31cec66d592172e90', name: "start" }), index.h("slot", { key: '09f29be168b254fa9e3d73273938493d14cbca2f' }), index.h("slot", { key: '8a014e7ebeed34446a89729ff771ac0a7c97639e', name: "end" }))));
122
+ const inverseClass = this.inverse ? 'btn-inverse' : '';
123
+ return (index.h(index.Host, { key: '10bf8a00e2cf0abe8a3116ed54c9bce15fae6b0f', class: [colorClass, sizeClass, expandClass, iconOnlyClass, inverseClass].filter(Boolean).join(' '), onClick: this.onClick, "aria-disabled": disabled ? 'true' : null }, index.h(TagType, Object.assign({ key: 'b4d651d32195f88f6958d3261cd88ee46476ea95' }, attrs, { class: "button-native", part: "native", disabled: disabled, onFocus: this.onFocus, onBlur: this.onBlur }), index.h("slot", { key: '8e931be9fcf7a6894ed71921f110c3726d2a4215', name: "start" }), index.h("slot", { key: '4a26d78cb726e7487e8ac5fb5006b7b7c70185b3' }), index.h("slot", { key: 'a8f44025e68ce0142b3eee4991d9c86bb22233ee', name: "end" }))));
119
124
  }
120
125
  get el() { return index.getElement(this); }
121
126
  };
@@ -305,7 +310,1587 @@ const Counter = class {
305
310
  let counterIds = 0;
306
311
  Counter.style = RoadCounterStyle0;
307
312
 
308
- const drawerCss = ":host{--background:var(--road-surface);--color:var(--road-on-surface);--header-icon:var(--road-on-surface);--header-color:var(--road-on-surface);--header-background:var(--road-surface);--header-delimiter:0;--back-chevron-color:var(--road-icon);--max-height:auto;--z-index:10;position:fixed;top:0;left:0;z-index:var(--z-index);display:flex;justify-content:flex-start;width:100%;height:100%;overflow:hidden;font-family:var(--road-font, sans-serif);line-height:1.5;color:var(--color);visibility:hidden !important;opacity:0;transition:opacity 0.15s linear, visibility 0.15s}.drawer-overlay{position:absolute;top:0;right:0;bottom:0;left:0;display:block;touch-action:none;cursor:pointer;background:var(--road-overlay)}.drawer-dialog{position:relative;width:100%;pointer-events:none;transition:transform 0.3s ease-out;transform:translateX(-100%)}:host(.drawer-right){justify-content:flex-end}:host(.drawer-right) .drawer-dialog{transform:translateX(100%)}:host(.drawer-bottom){align-items:flex-end}:host(.drawer-bottom) .drawer-dialog{width:100%;max-height:var(--max-height);transform:translateY(100%)}:host(.drawer-bottom) .drawer-content{height:auto}.drawer-content{position:relative;display:flex;flex-direction:column;width:100%;height:100vh;max-height:100vh;pointer-events:auto;background-color:var(--background);background-clip:padding-box;box-shadow:var(--road-elevation-hight)}.drawer-header{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;height:3.5rem;color:var(--header-color);background:var(--header-background);border-color:var(--road-grey-300);border-style:solid;border-width:var(--header-delimiter)}.drawer-header road-icon{flex-shrink:0;color:var(--header-icon)}.drawer-footer{padding:var(--road-spacing-05);background-color:var(--road-surface)}.drawer-footer.remove-padding{padding:0}.drawer-header-inverse{--header-icon:var(--road-on-primary);--header-color:var(--road-on-primary);--header-background:var(--road-primary-variant);margin-bottom:2.5rem}.drawer-action,.drawer-close{display:flex;align-items:center;justify-content:center;height:3.5rem;padding:0.5rem;font-family:inherit;font-size:0.875rem;color:inherit;cursor:pointer;background:transparent;border:0;appearance:none;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}.drawer-header:not(.drawer-header-inverse) .drawer-action road-icon{color:var(--back-chevron-color)}.drawer-action~.drawer-title,.drawer-close~.drawer-title{padding-left:0}.drawer-action-left,.drawer-close-left{margin-right:auto}.drawer-title{display:flex;flex-grow:1;align-items:center;justify-content:center;height:3.5rem;padding-left:3.5rem;margin:0;font-size:var(--road-body-medium)}.drawer-body{overflow-y:auto;padding:0 var(--road-spacing-05) var(--road-spacing-05)}.drawer-body.remove-padding{padding:0}:host(.drawer-right) .drawer-body,:host(.drawer-left) .drawer-body{height:calc(100vh - 3.5rem)}.drawer-inner{padding:0 1rem 2.5rem}@media (min-width: 768px){.drawer-inner{padding:0 2rem 2.5rem}.drawer-body{padding:0 var(--road-spacing-08) var(--road-spacing-05)}.drawer-body.remove-padding{padding:0}.drawer-footer{padding:var(--road-spacing-05) var(--road-spacing-08)}.drawer-footer.remove-padding{padding:0}}:host(.drawer-open){visibility:visible !important;opacity:1}:host(.drawer-open) .drawer-dialog{transform:none}";
313
+ /*!
314
+ * tabbable 6.3.0
315
+ * @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
316
+ */
317
+ // NOTE: separate `:not()` selectors has broader browser support than the newer
318
+ // `:not([inert], [inert] *)` (Feb 2023)
319
+ // CAREFUL: JSDom does not support `:not([inert] *)` as a selector; using it causes
320
+ // the entire query to fail, resulting in no nodes found, which will break a lot
321
+ // of things... so we have to rely on JS to identify nodes inside an inert container
322
+ 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])'];
323
+ var candidateSelector = /* #__PURE__ */candidateSelectors.join(',');
324
+ var NoElement = typeof Element === 'undefined';
325
+ var matches = NoElement ? function () {} : Element.prototype.matches || Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
326
+ var getRootNode = !NoElement && Element.prototype.getRootNode ? function (element) {
327
+ var _element$getRootNode;
328
+ return element === null || element === void 0 ? void 0 : (_element$getRootNode = element.getRootNode) === null || _element$getRootNode === void 0 ? void 0 : _element$getRootNode.call(element);
329
+ } : function (element) {
330
+ return element === null || element === void 0 ? void 0 : element.ownerDocument;
331
+ };
332
+
333
+ /**
334
+ * Determines if a node is inert or in an inert ancestor.
335
+ * @param {Element} [node]
336
+ * @param {boolean} [lookUp] If true and `node` is not inert, looks up at ancestors to
337
+ * see if any of them are inert. If false, only `node` itself is considered.
338
+ * @returns {boolean} True if inert itself or by way of being in an inert ancestor.
339
+ * False if `node` is falsy.
340
+ */
341
+ var _isInert = function isInert(node, lookUp) {
342
+ var _node$getAttribute;
343
+ if (lookUp === void 0) {
344
+ lookUp = true;
345
+ }
346
+ // CAREFUL: JSDom does not support inert at all, so we can't use the `HTMLElement.inert`
347
+ // JS API property; we have to check the attribute, which can either be empty or 'true';
348
+ // if it's `null` (not specified) or 'false', it's an active element
349
+ 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');
350
+ var inert = inertAtt === '' || inertAtt === 'true';
351
+
352
+ // NOTE: this could also be handled with `node.matches('[inert], :is([inert] *)')`
353
+ // if it weren't for `matches()` not being a function on shadow roots; the following
354
+ // code works for any kind of node
355
+ // CAREFUL: JSDom does not appear to support certain selectors like `:not([inert] *)`
356
+ // so it likely would not support `:is([inert] *)` either...
357
+ var result = inert || lookUp && node && _isInert(node.parentNode); // recursive
358
+
359
+ return result;
360
+ };
361
+
362
+ /**
363
+ * Determines if a node's content is editable.
364
+ * @param {Element} [node]
365
+ * @returns True if it's content-editable; false if it's not or `node` is falsy.
366
+ */
367
+ var isContentEditable = function isContentEditable(node) {
368
+ var _node$getAttribute2;
369
+ // CAREFUL: JSDom does not support the `HTMLElement.isContentEditable` API so we have
370
+ // to use the attribute directly to check for this, which can either be empty or 'true';
371
+ // if it's `null` (not specified) or 'false', it's a non-editable element
372
+ 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');
373
+ return attValue === '' || attValue === 'true';
374
+ };
375
+
376
+ /**
377
+ * @param {Element} el container to check in
378
+ * @param {boolean} includeContainer add container to check
379
+ * @param {(node: Element) => boolean} filter filter candidates
380
+ * @returns {Element[]}
381
+ */
382
+ var getCandidates = function getCandidates(el, includeContainer, filter) {
383
+ // even if `includeContainer=false`, we still have to check it for inertness because
384
+ // if it's inert, all its children are inert
385
+ if (_isInert(el)) {
386
+ return [];
387
+ }
388
+ var candidates = Array.prototype.slice.apply(el.querySelectorAll(candidateSelector));
389
+ if (includeContainer && matches.call(el, candidateSelector)) {
390
+ candidates.unshift(el);
391
+ }
392
+ candidates = candidates.filter(filter);
393
+ return candidates;
394
+ };
395
+
396
+ /**
397
+ * @callback GetShadowRoot
398
+ * @param {Element} element to check for shadow root
399
+ * @returns {ShadowRoot|boolean} ShadowRoot if available or boolean indicating if a shadowRoot is attached but not available.
400
+ */
401
+
402
+ /**
403
+ * @callback ShadowRootFilter
404
+ * @param {Element} shadowHostNode the element which contains shadow content
405
+ * @returns {boolean} true if a shadow root could potentially contain valid candidates.
406
+ */
407
+
408
+ /**
409
+ * @typedef {Object} CandidateScope
410
+ * @property {Element} scopeParent contains inner candidates
411
+ * @property {Element[]} candidates list of candidates found in the scope parent
412
+ */
413
+
414
+ /**
415
+ * @typedef {Object} IterativeOptions
416
+ * @property {GetShadowRoot|boolean} getShadowRoot true if shadow support is enabled; falsy if not;
417
+ * if a function, implies shadow support is enabled and either returns the shadow root of an element
418
+ * or a boolean stating if it has an undisclosed shadow root
419
+ * @property {(node: Element) => boolean} filter filter candidates
420
+ * @property {boolean} flatten if true then result will flatten any CandidateScope into the returned list
421
+ * @property {ShadowRootFilter} shadowRootFilter filter shadow roots;
422
+ */
423
+
424
+ /**
425
+ * @param {Element[]} elements list of element containers to match candidates from
426
+ * @param {boolean} includeContainer add container list to check
427
+ * @param {IterativeOptions} options
428
+ * @returns {Array.<Element|CandidateScope>}
429
+ */
430
+ var _getCandidatesIteratively = function getCandidatesIteratively(elements, includeContainer, options) {
431
+ var candidates = [];
432
+ var elementsToCheck = Array.from(elements);
433
+ while (elementsToCheck.length) {
434
+ var element = elementsToCheck.shift();
435
+ if (_isInert(element, false)) {
436
+ // no need to look up since we're drilling down
437
+ // anything inside this container will also be inert
438
+ continue;
439
+ }
440
+ if (element.tagName === 'SLOT') {
441
+ // add shadow dom slot scope (slot itself cannot be focusable)
442
+ var assigned = element.assignedElements();
443
+ var content = assigned.length ? assigned : element.children;
444
+ var nestedCandidates = _getCandidatesIteratively(content, true, options);
445
+ if (options.flatten) {
446
+ candidates.push.apply(candidates, nestedCandidates);
447
+ } else {
448
+ candidates.push({
449
+ scopeParent: element,
450
+ candidates: nestedCandidates
451
+ });
452
+ }
453
+ } else {
454
+ // check candidate element
455
+ var validCandidate = matches.call(element, candidateSelector);
456
+ if (validCandidate && options.filter(element) && (includeContainer || !elements.includes(element))) {
457
+ candidates.push(element);
458
+ }
459
+
460
+ // iterate over shadow content if possible
461
+ var shadowRoot = element.shadowRoot ||
462
+ // check for an undisclosed shadow
463
+ typeof options.getShadowRoot === 'function' && options.getShadowRoot(element);
464
+
465
+ // no inert look up because we're already drilling down and checking for inertness
466
+ // on the way down, so all containers to this root node should have already been
467
+ // vetted as non-inert
468
+ var validShadowRoot = !_isInert(shadowRoot, false) && (!options.shadowRootFilter || options.shadowRootFilter(element));
469
+ if (shadowRoot && validShadowRoot) {
470
+ // add shadow dom scope IIF a shadow root node was given; otherwise, an undisclosed
471
+ // shadow exists, so look at light dom children as fallback BUT create a scope for any
472
+ // child candidates found because they're likely slotted elements (elements that are
473
+ // children of the web component element (which has the shadow), in the light dom, but
474
+ // slotted somewhere _inside_ the undisclosed shadow) -- the scope is created below,
475
+ // _after_ we return from this recursive call
476
+ var _nestedCandidates = _getCandidatesIteratively(shadowRoot === true ? element.children : shadowRoot.children, true, options);
477
+ if (options.flatten) {
478
+ candidates.push.apply(candidates, _nestedCandidates);
479
+ } else {
480
+ candidates.push({
481
+ scopeParent: element,
482
+ candidates: _nestedCandidates
483
+ });
484
+ }
485
+ } else {
486
+ // there's not shadow so just dig into the element's (light dom) children
487
+ // __without__ giving the element special scope treatment
488
+ elementsToCheck.unshift.apply(elementsToCheck, element.children);
489
+ }
490
+ }
491
+ }
492
+ return candidates;
493
+ };
494
+
495
+ /**
496
+ * @private
497
+ * Determines if the node has an explicitly specified `tabindex` attribute.
498
+ * @param {HTMLElement} node
499
+ * @returns {boolean} True if so; false if not.
500
+ */
501
+ var hasTabIndex = function hasTabIndex(node) {
502
+ return !isNaN(parseInt(node.getAttribute('tabindex'), 10));
503
+ };
504
+
505
+ /**
506
+ * Determine the tab index of a given node.
507
+ * @param {HTMLElement} node
508
+ * @returns {number} Tab order (negative, 0, or positive number).
509
+ * @throws {Error} If `node` is falsy.
510
+ */
511
+ var getTabIndex = function getTabIndex(node) {
512
+ if (!node) {
513
+ throw new Error('No node provided');
514
+ }
515
+ if (node.tabIndex < 0) {
516
+ // in Chrome, <details/>, <audio controls/> and <video controls/> elements get a default
517
+ // `tabIndex` of -1 when the 'tabindex' attribute isn't specified in the DOM,
518
+ // yet they are still part of the regular tab order; in FF, they get a default
519
+ // `tabIndex` of 0; since Chrome still puts those elements in the regular tab
520
+ // order, consider their tab index to be 0.
521
+ // Also browsers do not return `tabIndex` correctly for contentEditable nodes;
522
+ // so if they don't have a tabindex attribute specifically set, assume it's 0.
523
+ if ((/^(AUDIO|VIDEO|DETAILS)$/.test(node.tagName) || isContentEditable(node)) && !hasTabIndex(node)) {
524
+ return 0;
525
+ }
526
+ }
527
+ return node.tabIndex;
528
+ };
529
+
530
+ /**
531
+ * Determine the tab index of a given node __for sort order purposes__.
532
+ * @param {HTMLElement} node
533
+ * @param {boolean} [isScope] True for a custom element with shadow root or slot that, by default,
534
+ * has tabIndex -1, but needs to be sorted by document order in order for its content to be
535
+ * inserted into the correct sort position.
536
+ * @returns {number} Tab order (negative, 0, or positive number).
537
+ */
538
+ var getSortOrderTabIndex = function getSortOrderTabIndex(node, isScope) {
539
+ var tabIndex = getTabIndex(node);
540
+ if (tabIndex < 0 && isScope && !hasTabIndex(node)) {
541
+ return 0;
542
+ }
543
+ return tabIndex;
544
+ };
545
+ var sortOrderedTabbables = function sortOrderedTabbables(a, b) {
546
+ return a.tabIndex === b.tabIndex ? a.documentOrder - b.documentOrder : a.tabIndex - b.tabIndex;
547
+ };
548
+ var isInput = function isInput(node) {
549
+ return node.tagName === 'INPUT';
550
+ };
551
+ var isHiddenInput = function isHiddenInput(node) {
552
+ return isInput(node) && node.type === 'hidden';
553
+ };
554
+ var isDetailsWithSummary = function isDetailsWithSummary(node) {
555
+ var r = node.tagName === 'DETAILS' && Array.prototype.slice.apply(node.children).some(function (child) {
556
+ return child.tagName === 'SUMMARY';
557
+ });
558
+ return r;
559
+ };
560
+ var getCheckedRadio = function getCheckedRadio(nodes, form) {
561
+ for (var i = 0; i < nodes.length; i++) {
562
+ if (nodes[i].checked && nodes[i].form === form) {
563
+ return nodes[i];
564
+ }
565
+ }
566
+ };
567
+ var isTabbableRadio = function isTabbableRadio(node) {
568
+ if (!node.name) {
569
+ return true;
570
+ }
571
+ var radioScope = node.form || getRootNode(node);
572
+ var queryRadios = function queryRadios(name) {
573
+ return radioScope.querySelectorAll('input[type="radio"][name="' + name + '"]');
574
+ };
575
+ var radioSet;
576
+ if (typeof window !== 'undefined' && typeof window.CSS !== 'undefined' && typeof window.CSS.escape === 'function') {
577
+ radioSet = queryRadios(window.CSS.escape(node.name));
578
+ } else {
579
+ try {
580
+ radioSet = queryRadios(node.name);
581
+ } catch (err) {
582
+ // eslint-disable-next-line no-console
583
+ 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);
584
+ return false;
585
+ }
586
+ }
587
+ var checked = getCheckedRadio(radioSet, node.form);
588
+ return !checked || checked === node;
589
+ };
590
+ var isRadio = function isRadio(node) {
591
+ return isInput(node) && node.type === 'radio';
592
+ };
593
+ var isNonTabbableRadio = function isNonTabbableRadio(node) {
594
+ return isRadio(node) && !isTabbableRadio(node);
595
+ };
596
+
597
+ // determines if a node is ultimately attached to the window's document
598
+ var isNodeAttached = function isNodeAttached(node) {
599
+ var _nodeRoot;
600
+ // The root node is the shadow root if the node is in a shadow DOM; some document otherwise
601
+ // (but NOT _the_ document; see second 'If' comment below for more).
602
+ // If rootNode is shadow root, it'll have a host, which is the element to which the shadow
603
+ // is attached, and the one we need to check if it's in the document or not (because the
604
+ // shadow, and all nodes it contains, is never considered in the document since shadows
605
+ // behave like self-contained DOMs; but if the shadow's HOST, which is part of the document,
606
+ // is hidden, or is not in the document itself but is detached, it will affect the shadow's
607
+ // visibility, including all the nodes it contains). The host could be any normal node,
608
+ // or a custom element (i.e. web component). Either way, that's the one that is considered
609
+ // part of the document, not the shadow root, nor any of its children (i.e. the node being
610
+ // tested).
611
+ // To further complicate things, we have to look all the way up until we find a shadow HOST
612
+ // that is attached (or find none) because the node might be in nested shadows...
613
+ // If rootNode is not a shadow root, it won't have a host, and so rootNode should be the
614
+ // document (per the docs) and while it's a Document-type object, that document does not
615
+ // appear to be the same as the node's `ownerDocument` for some reason, so it's safer
616
+ // to ignore the rootNode at this point, and use `node.ownerDocument`. Otherwise,
617
+ // using `rootNode.contains(node)` will _always_ be true we'll get false-positives when
618
+ // node is actually detached.
619
+ // NOTE: If `nodeRootHost` or `node` happens to be the `document` itself (which is possible
620
+ // if a tabbable/focusable node was quickly added to the DOM, focused, and then removed
621
+ // from the DOM as in https://github.com/focus-trap/focus-trap-react/issues/905), then
622
+ // `ownerDocument` will be `null`, hence the optional chaining on it.
623
+ var nodeRoot = node && getRootNode(node);
624
+ var nodeRootHost = (_nodeRoot = nodeRoot) === null || _nodeRoot === void 0 ? void 0 : _nodeRoot.host;
625
+
626
+ // in some cases, a detached node will return itself as the root instead of a document or
627
+ // shadow root object, in which case, we shouldn't try to look further up the host chain
628
+ var attached = false;
629
+ if (nodeRoot && nodeRoot !== node) {
630
+ var _nodeRootHost, _nodeRootHost$ownerDo, _node$ownerDocument;
631
+ 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));
632
+ while (!attached && nodeRootHost) {
633
+ var _nodeRoot2, _nodeRootHost2, _nodeRootHost2$ownerD;
634
+ // since it's not attached and we have a root host, the node MUST be in a nested shadow DOM,
635
+ // which means we need to get the host's host and check if that parent host is contained
636
+ // in (i.e. attached to) the document
637
+ nodeRoot = getRootNode(nodeRootHost);
638
+ nodeRootHost = (_nodeRoot2 = nodeRoot) === null || _nodeRoot2 === void 0 ? void 0 : _nodeRoot2.host;
639
+ attached = !!((_nodeRootHost2 = nodeRootHost) !== null && _nodeRootHost2 !== void 0 && (_nodeRootHost2$ownerD = _nodeRootHost2.ownerDocument) !== null && _nodeRootHost2$ownerD !== void 0 && _nodeRootHost2$ownerD.contains(nodeRootHost));
640
+ }
641
+ }
642
+ return attached;
643
+ };
644
+ var isZeroArea = function isZeroArea(node) {
645
+ var _node$getBoundingClie = node.getBoundingClientRect(),
646
+ width = _node$getBoundingClie.width,
647
+ height = _node$getBoundingClie.height;
648
+ return width === 0 && height === 0;
649
+ };
650
+ var isHidden = function isHidden(node, _ref) {
651
+ var displayCheck = _ref.displayCheck,
652
+ getShadowRoot = _ref.getShadowRoot;
653
+ if (displayCheck === 'full-native') {
654
+ if ('checkVisibility' in node) {
655
+ // Chrome >= 105, Edge >= 105, Firefox >= 106, Safari >= 17.4
656
+ // @see https://developer.mozilla.org/en-US/docs/Web/API/Element/checkVisibility#browser_compatibility
657
+ var visible = node.checkVisibility({
658
+ // Checking opacity might be desirable for some use cases, but natively,
659
+ // opacity zero elements _are_ focusable and tabbable.
660
+ checkOpacity: false,
661
+ opacityProperty: false,
662
+ contentVisibilityAuto: true,
663
+ visibilityProperty: true,
664
+ // This is an alias for `visibilityProperty`. Contemporary browsers
665
+ // support both. However, this alias has wider browser support (Chrome
666
+ // >= 105 and Firefox >= 106, vs. Chrome >= 121 and Firefox >= 122), so
667
+ // we include it anyway.
668
+ checkVisibilityCSS: true
669
+ });
670
+ return !visible;
671
+ }
672
+ // Fall through to manual visibility checks
673
+ }
674
+
675
+ // NOTE: visibility will be `undefined` if node is detached from the document
676
+ // (see notes about this further down), which means we will consider it visible
677
+ // (this is legacy behavior from a very long way back)
678
+ // NOTE: we check this regardless of `displayCheck="none"` because this is a
679
+ // _visibility_ check, not a _display_ check
680
+ if (getComputedStyle(node).visibility === 'hidden') {
681
+ return true;
682
+ }
683
+ var isDirectSummary = matches.call(node, 'details>summary:first-of-type');
684
+ var nodeUnderDetails = isDirectSummary ? node.parentElement : node;
685
+ if (matches.call(nodeUnderDetails, 'details:not([open]) *')) {
686
+ return true;
687
+ }
688
+ if (!displayCheck || displayCheck === 'full' ||
689
+ // full-native can run this branch when it falls through in case
690
+ // Element#checkVisibility is unsupported
691
+ displayCheck === 'full-native' || displayCheck === 'legacy-full') {
692
+ if (typeof getShadowRoot === 'function') {
693
+ // figure out if we should consider the node to be in an undisclosed shadow and use the
694
+ // 'non-zero-area' fallback
695
+ var originalNode = node;
696
+ while (node) {
697
+ var parentElement = node.parentElement;
698
+ var rootNode = getRootNode(node);
699
+ if (parentElement && !parentElement.shadowRoot && getShadowRoot(parentElement) === true // check if there's an undisclosed shadow
700
+ ) {
701
+ // node has an undisclosed shadow which means we can only treat it as a black box, so we
702
+ // fall back to a non-zero-area test
703
+ return isZeroArea(node);
704
+ } else if (node.assignedSlot) {
705
+ // iterate up slot
706
+ node = node.assignedSlot;
707
+ } else if (!parentElement && rootNode !== node.ownerDocument) {
708
+ // cross shadow boundary
709
+ node = rootNode.host;
710
+ } else {
711
+ // iterate up normal dom
712
+ node = parentElement;
713
+ }
714
+ }
715
+ node = originalNode;
716
+ }
717
+ // else, `getShadowRoot` might be true, but all that does is enable shadow DOM support
718
+ // (i.e. it does not also presume that all nodes might have undisclosed shadows); or
719
+ // it might be a falsy value, which means shadow DOM support is disabled
720
+
721
+ // Since we didn't find it sitting in an undisclosed shadow (or shadows are disabled)
722
+ // now we can just test to see if it would normally be visible or not, provided it's
723
+ // attached to the main document.
724
+ // NOTE: We must consider case where node is inside a shadow DOM and given directly to
725
+ // `isTabbable()` or `isFocusable()` -- regardless of `getShadowRoot` option setting.
726
+
727
+ if (isNodeAttached(node)) {
728
+ // this works wherever the node is: if there's at least one client rect, it's
729
+ // somehow displayed; it also covers the CSS 'display: contents' case where the
730
+ // node itself is hidden in place of its contents; and there's no need to search
731
+ // up the hierarchy either
732
+ return !node.getClientRects().length;
733
+ }
734
+
735
+ // Else, the node isn't attached to the document, which means the `getClientRects()`
736
+ // API will __always__ return zero rects (this can happen, for example, if React
737
+ // is used to render nodes onto a detached tree, as confirmed in this thread:
738
+ // https://github.com/facebook/react/issues/9117#issuecomment-284228870)
739
+ //
740
+ // It also means that even window.getComputedStyle(node).display will return `undefined`
741
+ // because styles are only computed for nodes that are in the document.
742
+ //
743
+ // NOTE: THIS HAS BEEN THE CASE FOR YEARS. It is not new, nor is it caused by tabbable
744
+ // somehow. Though it was never stated officially, anyone who has ever used tabbable
745
+ // APIs on nodes in detached containers has actually implicitly used tabbable in what
746
+ // was later (as of v5.2.0 on Apr 9, 2021) called `displayCheck="none"` mode -- essentially
747
+ // considering __everything__ to be visible because of the innability to determine styles.
748
+ //
749
+ // v6.0.0: As of this major release, the default 'full' option __no longer treats detached
750
+ // nodes as visible with the 'none' fallback.__
751
+ if (displayCheck !== 'legacy-full') {
752
+ return true; // hidden
753
+ }
754
+ // else, fallback to 'none' mode and consider the node visible
755
+ } else if (displayCheck === 'non-zero-area') {
756
+ // NOTE: Even though this tests that the node's client rect is non-zero to determine
757
+ // whether it's displayed, and that a detached node will __always__ have a zero-area
758
+ // client rect, we don't special-case for whether the node is attached or not. In
759
+ // this mode, we do want to consider nodes that have a zero area to be hidden at all
760
+ // times, and that includes attached or not.
761
+ return isZeroArea(node);
762
+ }
763
+
764
+ // visible, as far as we can tell, or per current `displayCheck=none` mode, we assume
765
+ // it's visible
766
+ return false;
767
+ };
768
+
769
+ // form fields (nested) inside a disabled fieldset are not focusable/tabbable
770
+ // unless they are in the _first_ <legend> element of the top-most disabled
771
+ // fieldset
772
+ var isDisabledFromFieldset = function isDisabledFromFieldset(node) {
773
+ if (/^(INPUT|BUTTON|SELECT|TEXTAREA)$/.test(node.tagName)) {
774
+ var parentNode = node.parentElement;
775
+ // check if `node` is contained in a disabled <fieldset>
776
+ while (parentNode) {
777
+ if (parentNode.tagName === 'FIELDSET' && parentNode.disabled) {
778
+ // look for the first <legend> among the children of the disabled <fieldset>
779
+ for (var i = 0; i < parentNode.children.length; i++) {
780
+ var child = parentNode.children.item(i);
781
+ // when the first <legend> (in document order) is found
782
+ if (child.tagName === 'LEGEND') {
783
+ // if its parent <fieldset> is not nested in another disabled <fieldset>,
784
+ // return whether `node` is a descendant of its first <legend>
785
+ return matches.call(parentNode, 'fieldset[disabled] *') ? true : !child.contains(node);
786
+ }
787
+ }
788
+ // the disabled <fieldset> containing `node` has no <legend>
789
+ return true;
790
+ }
791
+ parentNode = parentNode.parentElement;
792
+ }
793
+ }
794
+
795
+ // else, node's tabbable/focusable state should not be affected by a fieldset's
796
+ // enabled/disabled state
797
+ return false;
798
+ };
799
+ var isNodeMatchingSelectorFocusable = function isNodeMatchingSelectorFocusable(options, node) {
800
+ if (node.disabled ||
801
+ // we must do an inert look up to filter out any elements inside an inert ancestor
802
+ // because we're limited in the type of selectors we can use in JSDom (see related
803
+ // note related to `candidateSelectors`)
804
+ _isInert(node) || isHiddenInput(node) || isHidden(node, options) ||
805
+ // For a details element with a summary, the summary element gets the focus
806
+ isDetailsWithSummary(node) || isDisabledFromFieldset(node)) {
807
+ return false;
808
+ }
809
+ return true;
810
+ };
811
+ var isNodeMatchingSelectorTabbable = function isNodeMatchingSelectorTabbable(options, node) {
812
+ if (isNonTabbableRadio(node) || getTabIndex(node) < 0 || !isNodeMatchingSelectorFocusable(options, node)) {
813
+ return false;
814
+ }
815
+ return true;
816
+ };
817
+ var isShadowRootTabbable = function isShadowRootTabbable(shadowHostNode) {
818
+ var tabIndex = parseInt(shadowHostNode.getAttribute('tabindex'), 10);
819
+ if (isNaN(tabIndex) || tabIndex >= 0) {
820
+ return true;
821
+ }
822
+ // If a custom element has an explicit negative tabindex,
823
+ // browsers will not allow tab targeting said element's children.
824
+ return false;
825
+ };
826
+
827
+ /**
828
+ * @param {Array.<Element|CandidateScope>} candidates
829
+ * @returns Element[]
830
+ */
831
+ var _sortByOrder = function sortByOrder(candidates) {
832
+ var regularTabbables = [];
833
+ var orderedTabbables = [];
834
+ candidates.forEach(function (item, i) {
835
+ var isScope = !!item.scopeParent;
836
+ var element = isScope ? item.scopeParent : item;
837
+ var candidateTabindex = getSortOrderTabIndex(element, isScope);
838
+ var elements = isScope ? _sortByOrder(item.candidates) : element;
839
+ if (candidateTabindex === 0) {
840
+ isScope ? regularTabbables.push.apply(regularTabbables, elements) : regularTabbables.push(element);
841
+ } else {
842
+ orderedTabbables.push({
843
+ documentOrder: i,
844
+ tabIndex: candidateTabindex,
845
+ item: item,
846
+ isScope: isScope,
847
+ content: elements
848
+ });
849
+ }
850
+ });
851
+ return orderedTabbables.sort(sortOrderedTabbables).reduce(function (acc, sortable) {
852
+ sortable.isScope ? acc.push.apply(acc, sortable.content) : acc.push(sortable.content);
853
+ return acc;
854
+ }, []).concat(regularTabbables);
855
+ };
856
+ var tabbable = function tabbable(container, options) {
857
+ options = options || {};
858
+ var candidates;
859
+ if (options.getShadowRoot) {
860
+ candidates = _getCandidatesIteratively([container], options.includeContainer, {
861
+ filter: isNodeMatchingSelectorTabbable.bind(null, options),
862
+ flatten: false,
863
+ getShadowRoot: options.getShadowRoot,
864
+ shadowRootFilter: isShadowRootTabbable
865
+ });
866
+ } else {
867
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorTabbable.bind(null, options));
868
+ }
869
+ return _sortByOrder(candidates);
870
+ };
871
+ var focusable = function focusable(container, options) {
872
+ options = options || {};
873
+ var candidates;
874
+ if (options.getShadowRoot) {
875
+ candidates = _getCandidatesIteratively([container], options.includeContainer, {
876
+ filter: isNodeMatchingSelectorFocusable.bind(null, options),
877
+ flatten: true,
878
+ getShadowRoot: options.getShadowRoot
879
+ });
880
+ } else {
881
+ candidates = getCandidates(container, options.includeContainer, isNodeMatchingSelectorFocusable.bind(null, options));
882
+ }
883
+ return candidates;
884
+ };
885
+ var isTabbable = function isTabbable(node, options) {
886
+ options = options || {};
887
+ if (!node) {
888
+ throw new Error('No node provided');
889
+ }
890
+ if (matches.call(node, candidateSelector) === false) {
891
+ return false;
892
+ }
893
+ return isNodeMatchingSelectorTabbable(options, node);
894
+ };
895
+ var focusableCandidateSelector = /* #__PURE__ */candidateSelectors.concat('iframe').join(',');
896
+ var isFocusable = function isFocusable(node, options) {
897
+ options = options || {};
898
+ if (!node) {
899
+ throw new Error('No node provided');
900
+ }
901
+ if (matches.call(node, focusableCandidateSelector) === false) {
902
+ return false;
903
+ }
904
+ return isNodeMatchingSelectorFocusable(options, node);
905
+ };
906
+
907
+ /*!
908
+ * focus-trap 7.6.6
909
+ * @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
910
+ */
911
+
912
+ function _arrayLikeToArray(r, a) {
913
+ (null == a || a > r.length) && (a = r.length);
914
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
915
+ return n;
916
+ }
917
+ function _arrayWithoutHoles(r) {
918
+ if (Array.isArray(r)) return _arrayLikeToArray(r);
919
+ }
920
+ function _defineProperty(e, r, t) {
921
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
922
+ value: t,
923
+ enumerable: true,
924
+ configurable: true,
925
+ writable: true
926
+ }) : e[r] = t, e;
927
+ }
928
+ function _iterableToArray(r) {
929
+ if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
930
+ }
931
+ function _nonIterableSpread() {
932
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
933
+ }
934
+ function ownKeys(e, r) {
935
+ var t = Object.keys(e);
936
+ if (Object.getOwnPropertySymbols) {
937
+ var o = Object.getOwnPropertySymbols(e);
938
+ r && (o = o.filter(function (r) {
939
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
940
+ })), t.push.apply(t, o);
941
+ }
942
+ return t;
943
+ }
944
+ function _objectSpread2(e) {
945
+ for (var r = 1; r < arguments.length; r++) {
946
+ var t = null != arguments[r] ? arguments[r] : {};
947
+ r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
948
+ _defineProperty(e, r, t[r]);
949
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
950
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
951
+ });
952
+ }
953
+ return e;
954
+ }
955
+ function _toConsumableArray(r) {
956
+ return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
957
+ }
958
+ function _toPrimitive(t, r) {
959
+ if ("object" != typeof t || !t) return t;
960
+ var e = t[Symbol.toPrimitive];
961
+ if (void 0 !== e) {
962
+ var i = e.call(t, r);
963
+ if ("object" != typeof i) return i;
964
+ throw new TypeError("@@toPrimitive must return a primitive value.");
965
+ }
966
+ return ("string" === r ? String : Number)(t);
967
+ }
968
+ function _toPropertyKey(t) {
969
+ var i = _toPrimitive(t, "string");
970
+ return "symbol" == typeof i ? i : i + "";
971
+ }
972
+ function _unsupportedIterableToArray(r, a) {
973
+ if (r) {
974
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
975
+ var t = {}.toString.call(r).slice(8, -1);
976
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
977
+ }
978
+ }
979
+
980
+ var activeFocusTraps = {
981
+ activateTrap: function activateTrap(trapStack, trap) {
982
+ if (trapStack.length > 0) {
983
+ var activeTrap = trapStack[trapStack.length - 1];
984
+ if (activeTrap !== trap) {
985
+ activeTrap._setPausedState(true);
986
+ }
987
+ }
988
+ var trapIndex = trapStack.indexOf(trap);
989
+ if (trapIndex === -1) {
990
+ trapStack.push(trap);
991
+ } else {
992
+ // move this existing trap to the front of the queue
993
+ trapStack.splice(trapIndex, 1);
994
+ trapStack.push(trap);
995
+ }
996
+ },
997
+ deactivateTrap: function deactivateTrap(trapStack, trap) {
998
+ var trapIndex = trapStack.indexOf(trap);
999
+ if (trapIndex !== -1) {
1000
+ trapStack.splice(trapIndex, 1);
1001
+ }
1002
+ if (trapStack.length > 0 && !trapStack[trapStack.length - 1]._isManuallyPaused()) {
1003
+ trapStack[trapStack.length - 1]._setPausedState(false);
1004
+ }
1005
+ }
1006
+ };
1007
+ var isSelectableInput = function isSelectableInput(node) {
1008
+ return node.tagName && node.tagName.toLowerCase() === 'input' && typeof node.select === 'function';
1009
+ };
1010
+ var isEscapeEvent = function isEscapeEvent(e) {
1011
+ 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;
1012
+ };
1013
+ var isTabEvent = function isTabEvent(e) {
1014
+ return (e === null || e === void 0 ? void 0 : e.key) === 'Tab' || (e === null || e === void 0 ? void 0 : e.keyCode) === 9;
1015
+ };
1016
+
1017
+ // checks for TAB by default
1018
+ var isKeyForward = function isKeyForward(e) {
1019
+ return isTabEvent(e) && !e.shiftKey;
1020
+ };
1021
+
1022
+ // checks for SHIFT+TAB by default
1023
+ var isKeyBackward = function isKeyBackward(e) {
1024
+ return isTabEvent(e) && e.shiftKey;
1025
+ };
1026
+ var delay = function delay(fn) {
1027
+ return setTimeout(fn, 0);
1028
+ };
1029
+
1030
+ /**
1031
+ * Get an option's value when it could be a plain value, or a handler that provides
1032
+ * the value.
1033
+ * @param {*} value Option's value to check.
1034
+ * @param {...*} [params] Any parameters to pass to the handler, if `value` is a function.
1035
+ * @returns {*} The `value`, or the handler's returned value.
1036
+ */
1037
+ var valueOrHandler = function valueOrHandler(value) {
1038
+ for (var _len = arguments.length, params = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1039
+ params[_key - 1] = arguments[_key];
1040
+ }
1041
+ return typeof value === 'function' ? value.apply(void 0, params) : value;
1042
+ };
1043
+ var getActualTarget = function getActualTarget(event) {
1044
+ // NOTE: If the trap is _inside_ a shadow DOM, event.target will always be the
1045
+ // shadow host. However, event.target.composedPath() will be an array of
1046
+ // nodes "clicked" from inner-most (the actual element inside the shadow) to
1047
+ // outer-most (the host HTML document). If we have access to composedPath(),
1048
+ // then use its first element; otherwise, fall back to event.target (and
1049
+ // this only works for an _open_ shadow DOM; otherwise,
1050
+ // composedPath()[0] === event.target always).
1051
+ return event.target.shadowRoot && typeof event.composedPath === 'function' ? event.composedPath()[0] : event.target;
1052
+ };
1053
+
1054
+ // NOTE: this must be _outside_ `createFocusTrap()` to make sure all traps in this
1055
+ // current instance use the same stack if `userOptions.trapStack` isn't specified
1056
+ var internalTrapStack = [];
1057
+ var createFocusTrap = function createFocusTrap(elements, userOptions) {
1058
+ // SSR: a live trap shouldn't be created in this type of environment so this
1059
+ // should be safe code to execute if the `document` option isn't specified
1060
+ var doc = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.document) || document;
1061
+ var trapStack = (userOptions === null || userOptions === void 0 ? void 0 : userOptions.trapStack) || internalTrapStack;
1062
+ var config = _objectSpread2({
1063
+ returnFocusOnDeactivate: true,
1064
+ escapeDeactivates: true,
1065
+ delayInitialFocus: true,
1066
+ isKeyForward: isKeyForward,
1067
+ isKeyBackward: isKeyBackward
1068
+ }, userOptions);
1069
+ var state = {
1070
+ // containers given to createFocusTrap()
1071
+ // @type {Array<HTMLElement>}
1072
+ containers: [],
1073
+ // list of objects identifying tabbable nodes in `containers` in the trap
1074
+ // NOTE: it's possible that a group has no tabbable nodes if nodes get removed while the trap
1075
+ // is active, but the trap should never get to a state where there isn't at least one group
1076
+ // with at least one tabbable node in it (that would lead to an error condition that would
1077
+ // result in an error being thrown)
1078
+ // @type {Array<{
1079
+ // container: HTMLElement,
1080
+ // tabbableNodes: Array<HTMLElement>, // empty if none
1081
+ // focusableNodes: Array<HTMLElement>, // empty if none
1082
+ // posTabIndexesFound: boolean,
1083
+ // firstTabbableNode: HTMLElement|undefined,
1084
+ // lastTabbableNode: HTMLElement|undefined,
1085
+ // firstDomTabbableNode: HTMLElement|undefined,
1086
+ // lastDomTabbableNode: HTMLElement|undefined,
1087
+ // nextTabbableNode: (node: HTMLElement, forward: boolean) => HTMLElement|undefined
1088
+ // }>}
1089
+ containerGroups: [],
1090
+ // same order/length as `containers` list
1091
+
1092
+ // references to objects in `containerGroups`, but only those that actually have
1093
+ // tabbable nodes in them
1094
+ // NOTE: same order as `containers` and `containerGroups`, but __not necessarily__
1095
+ // the same length
1096
+ tabbableGroups: [],
1097
+ nodeFocusedBeforeActivation: null,
1098
+ mostRecentlyFocusedNode: null,
1099
+ active: false,
1100
+ paused: false,
1101
+ manuallyPaused: false,
1102
+ // timer ID for when delayInitialFocus is true and initial focus in this trap
1103
+ // has been delayed during activation
1104
+ delayInitialFocusTimer: undefined,
1105
+ // the most recent KeyboardEvent for the configured nav key (typically [SHIFT+]TAB), if any
1106
+ recentNavEvent: undefined
1107
+ };
1108
+ 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
1109
+
1110
+ /**
1111
+ * Gets a configuration option value.
1112
+ * @param {Object|undefined} configOverrideOptions If true, and option is defined in this set,
1113
+ * value will be taken from this object. Otherwise, value will be taken from base configuration.
1114
+ * @param {string} optionName Name of the option whose value is sought.
1115
+ * @param {string|undefined} [configOptionName] Name of option to use __instead of__ `optionName`
1116
+ * IIF `configOverrideOptions` is not defined. Otherwise, `optionName` is used.
1117
+ */
1118
+ var getOption = function getOption(configOverrideOptions, optionName, configOptionName) {
1119
+ return configOverrideOptions && configOverrideOptions[optionName] !== undefined ? configOverrideOptions[optionName] : config[configOptionName || optionName];
1120
+ };
1121
+
1122
+ /**
1123
+ * Finds the index of the container that contains the element.
1124
+ * @param {HTMLElement} element
1125
+ * @param {Event} [event] If available, and `element` isn't directly found in any container,
1126
+ * the event's composed path is used to see if includes any known trap containers in the
1127
+ * case where the element is inside a Shadow DOM.
1128
+ * @returns {number} Index of the container in either `state.containers` or
1129
+ * `state.containerGroups` (the order/length of these lists are the same); -1
1130
+ * if the element isn't found.
1131
+ */
1132
+ var findContainerIndex = function findContainerIndex(element, event) {
1133
+ var composedPath = typeof (event === null || event === void 0 ? void 0 : event.composedPath) === 'function' ? event.composedPath() : undefined;
1134
+ // NOTE: search `containerGroups` because it's possible a group contains no tabbable
1135
+ // nodes, but still contains focusable nodes (e.g. if they all have `tabindex=-1`)
1136
+ // and we still need to find the element in there
1137
+ return state.containerGroups.findIndex(function (_ref) {
1138
+ var container = _ref.container,
1139
+ tabbableNodes = _ref.tabbableNodes;
1140
+ return container.contains(element) || (// fall back to explicit tabbable search which will take into consideration any
1141
+ // web components if the `tabbableOptions.getShadowRoot` option was used for
1142
+ // the trap, enabling shadow DOM support in tabbable (`Node.contains()` doesn't
1143
+ // look inside web components even if open)
1144
+ composedPath === null || composedPath === void 0 ? void 0 : composedPath.includes(container)) || tabbableNodes.find(function (node) {
1145
+ return node === element;
1146
+ });
1147
+ });
1148
+ };
1149
+
1150
+ /**
1151
+ * Gets the node for the given option, which is expected to be an option that
1152
+ * can be either a DOM node, a string that is a selector to get a node, `false`
1153
+ * (if a node is explicitly NOT given), or a function that returns any of these
1154
+ * values.
1155
+ * @param {string} optionName
1156
+ * @param {Object} options
1157
+ * @param {boolean} [options.hasFallback] True if the option could be a selector string
1158
+ * and the option allows for a fallback scenario in the case where the selector is
1159
+ * valid but does not match a node (i.e. the queried node doesn't exist in the DOM).
1160
+ * @param {Array} [options.params] Params to pass to the option if it's a function.
1161
+ * @returns {undefined | null | false | HTMLElement | SVGElement} Returns
1162
+ * `undefined` if the option is not specified; `null` if the option didn't resolve
1163
+ * to a node but `options.hasFallback=true`, `false` if the option resolved to `false`
1164
+ * (node explicitly not given); otherwise, the resolved DOM node.
1165
+ * @throws {Error} If the option is set, not `false`, and is not, or does not
1166
+ * resolve to a node, unless the option is a selector string and `options.hasFallback=true`.
1167
+ */
1168
+ var getNodeForOption = function getNodeForOption(optionName) {
1169
+ var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1170
+ _ref2$hasFallback = _ref2.hasFallback,
1171
+ hasFallback = _ref2$hasFallback === void 0 ? false : _ref2$hasFallback,
1172
+ _ref2$params = _ref2.params,
1173
+ params = _ref2$params === void 0 ? [] : _ref2$params;
1174
+ var optionValue = config[optionName];
1175
+ if (typeof optionValue === 'function') {
1176
+ optionValue = optionValue.apply(void 0, _toConsumableArray(params));
1177
+ }
1178
+ if (optionValue === true) {
1179
+ optionValue = undefined; // use default value
1180
+ }
1181
+ if (!optionValue) {
1182
+ if (optionValue === undefined || optionValue === false) {
1183
+ return optionValue;
1184
+ }
1185
+ // else, empty string (invalid), null (invalid), 0 (invalid)
1186
+
1187
+ throw new Error("`".concat(optionName, "` was specified but was not a node, or did not return a node"));
1188
+ }
1189
+ var node = optionValue; // could be HTMLElement, SVGElement, or non-empty string at this point
1190
+
1191
+ if (typeof optionValue === 'string') {
1192
+ try {
1193
+ node = doc.querySelector(optionValue); // resolve to node, or null if fails
1194
+ } catch (err) {
1195
+ throw new Error("`".concat(optionName, "` appears to be an invalid selector; error=\"").concat(err.message, "\""));
1196
+ }
1197
+ if (!node) {
1198
+ if (!hasFallback) {
1199
+ throw new Error("`".concat(optionName, "` as selector refers to no known node"));
1200
+ }
1201
+ // else, `node` MUST be `null` because that's what `Document.querySelector()` returns
1202
+ // if the selector is valid but doesn't match anything
1203
+ }
1204
+ }
1205
+ return node;
1206
+ };
1207
+ var getInitialFocusNode = function getInitialFocusNode() {
1208
+ var node = getNodeForOption('initialFocus', {
1209
+ hasFallback: true
1210
+ });
1211
+
1212
+ // false explicitly indicates we want no initialFocus at all
1213
+ if (node === false) {
1214
+ return false;
1215
+ }
1216
+ if (node === undefined || node && !isFocusable(node, config.tabbableOptions)) {
1217
+ // option not specified nor focusable: use fallback options
1218
+ if (findContainerIndex(doc.activeElement) >= 0) {
1219
+ node = doc.activeElement;
1220
+ } else {
1221
+ var firstTabbableGroup = state.tabbableGroups[0];
1222
+ var firstTabbableNode = firstTabbableGroup && firstTabbableGroup.firstTabbableNode;
1223
+
1224
+ // NOTE: `fallbackFocus` option function cannot return `false` (not supported)
1225
+ node = firstTabbableNode || getNodeForOption('fallbackFocus');
1226
+ }
1227
+ } else if (node === null) {
1228
+ // option is a VALID selector string that doesn't yield a node: use the `fallbackFocus`
1229
+ // option instead of the default behavior when the option isn't specified at all
1230
+ node = getNodeForOption('fallbackFocus');
1231
+ }
1232
+ if (!node) {
1233
+ throw new Error('Your focus-trap needs to have at least one focusable element');
1234
+ }
1235
+ return node;
1236
+ };
1237
+ var updateTabbableNodes = function updateTabbableNodes() {
1238
+ state.containerGroups = state.containers.map(function (container) {
1239
+ var tabbableNodes = tabbable(container, config.tabbableOptions);
1240
+
1241
+ // NOTE: if we have tabbable nodes, we must have focusable nodes; focusable nodes
1242
+ // are a superset of tabbable nodes since nodes with negative `tabindex` attributes
1243
+ // are focusable but not tabbable
1244
+ var focusableNodes = focusable(container, config.tabbableOptions);
1245
+ var firstTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[0] : undefined;
1246
+ var lastTabbableNode = tabbableNodes.length > 0 ? tabbableNodes[tabbableNodes.length - 1] : undefined;
1247
+ var firstDomTabbableNode = focusableNodes.find(function (node) {
1248
+ return isTabbable(node);
1249
+ });
1250
+ var lastDomTabbableNode = focusableNodes.slice().reverse().find(function (node) {
1251
+ return isTabbable(node);
1252
+ });
1253
+ var posTabIndexesFound = !!tabbableNodes.find(function (node) {
1254
+ return getTabIndex(node) > 0;
1255
+ });
1256
+ return {
1257
+ container: container,
1258
+ tabbableNodes: tabbableNodes,
1259
+ focusableNodes: focusableNodes,
1260
+ /** True if at least one node with positive `tabindex` was found in this container. */
1261
+ posTabIndexesFound: posTabIndexesFound,
1262
+ /** First tabbable node in container, __tabindex__ order; `undefined` if none. */
1263
+ firstTabbableNode: firstTabbableNode,
1264
+ /** Last tabbable node in container, __tabindex__ order; `undefined` if none. */
1265
+ lastTabbableNode: lastTabbableNode,
1266
+ // NOTE: DOM order is NOT NECESSARILY "document position" order, but figuring that out
1267
+ // would require more than just https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
1268
+ // because that API doesn't work with Shadow DOM as well as it should (@see
1269
+ // https://github.com/whatwg/dom/issues/320) and since this first/last is only needed, so far,
1270
+ // to address an edge case related to positive tabindex support, this seems like a much easier,
1271
+ // "close enough most of the time" alternative for positive tabindexes which should generally
1272
+ // be avoided anyway...
1273
+ /** First tabbable node in container, __DOM__ order; `undefined` if none. */
1274
+ firstDomTabbableNode: firstDomTabbableNode,
1275
+ /** Last tabbable node in container, __DOM__ order; `undefined` if none. */
1276
+ lastDomTabbableNode: lastDomTabbableNode,
1277
+ /**
1278
+ * Finds the __tabbable__ node that follows the given node in the specified direction,
1279
+ * in this container, if any.
1280
+ * @param {HTMLElement} node
1281
+ * @param {boolean} [forward] True if going in forward tab order; false if going
1282
+ * in reverse.
1283
+ * @returns {HTMLElement|undefined} The next tabbable node, if any.
1284
+ */
1285
+ nextTabbableNode: function nextTabbableNode(node) {
1286
+ var forward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
1287
+ var nodeIdx = tabbableNodes.indexOf(node);
1288
+ if (nodeIdx < 0) {
1289
+ // either not tabbable nor focusable, or was focused but not tabbable (negative tabindex):
1290
+ // since `node` should at least have been focusable, we assume that's the case and mimic
1291
+ // what browsers do, which is set focus to the next node in __document position order__,
1292
+ // regardless of positive tabindexes, if any -- and for reasons explained in the NOTE
1293
+ // above related to `firstDomTabbable` and `lastDomTabbable` properties, we fall back to
1294
+ // basic DOM order
1295
+ if (forward) {
1296
+ return focusableNodes.slice(focusableNodes.indexOf(node) + 1).find(function (el) {
1297
+ return isTabbable(el);
1298
+ });
1299
+ }
1300
+ return focusableNodes.slice(0, focusableNodes.indexOf(node)).reverse().find(function (el) {
1301
+ return isTabbable(el);
1302
+ });
1303
+ }
1304
+ return tabbableNodes[nodeIdx + (forward ? 1 : -1)];
1305
+ }
1306
+ };
1307
+ });
1308
+ state.tabbableGroups = state.containerGroups.filter(function (group) {
1309
+ return group.tabbableNodes.length > 0;
1310
+ });
1311
+
1312
+ // throw if no groups have tabbable nodes and we don't have a fallback focus node either
1313
+ if (state.tabbableGroups.length <= 0 && !getNodeForOption('fallbackFocus') // returning false not supported for this option
1314
+ ) {
1315
+ throw new Error('Your focus-trap must have at least one container with at least one tabbable node in it at all times');
1316
+ }
1317
+
1318
+ // NOTE: Positive tabindexes are only properly supported in single-container traps because
1319
+ // doing it across multiple containers where tabindexes could be all over the place
1320
+ // would require Tabbable to support multiple containers, would require additional
1321
+ // specialized Shadow DOM support, and would require Tabbable's multi-container support
1322
+ // to look at those containers in document position order rather than user-provided
1323
+ // order (as they are treated in Focus-trap, for legacy reasons). See discussion on
1324
+ // https://github.com/focus-trap/focus-trap/issues/375 for more details.
1325
+ if (state.containerGroups.find(function (g) {
1326
+ return g.posTabIndexesFound;
1327
+ }) && state.containerGroups.length > 1) {
1328
+ 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.");
1329
+ }
1330
+ };
1331
+
1332
+ /**
1333
+ * Gets the current activeElement. If it's a web-component and has open shadow-root
1334
+ * it will recursively search inside shadow roots for the "true" activeElement.
1335
+ *
1336
+ * @param {Document | ShadowRoot} el
1337
+ *
1338
+ * @returns {HTMLElement} The element that currently has the focus
1339
+ **/
1340
+ var _getActiveElement = function getActiveElement(el) {
1341
+ var activeElement = el.activeElement;
1342
+ if (!activeElement) {
1343
+ return;
1344
+ }
1345
+ if (activeElement.shadowRoot && activeElement.shadowRoot.activeElement !== null) {
1346
+ return _getActiveElement(activeElement.shadowRoot);
1347
+ }
1348
+ return activeElement;
1349
+ };
1350
+ var _tryFocus = function tryFocus(node) {
1351
+ if (node === false) {
1352
+ return;
1353
+ }
1354
+ if (node === _getActiveElement(document)) {
1355
+ return;
1356
+ }
1357
+ if (!node || !node.focus) {
1358
+ _tryFocus(getInitialFocusNode());
1359
+ return;
1360
+ }
1361
+ node.focus({
1362
+ preventScroll: !!config.preventScroll
1363
+ });
1364
+ // NOTE: focus() API does not trigger focusIn event so set MRU node manually
1365
+ state.mostRecentlyFocusedNode = node;
1366
+ if (isSelectableInput(node)) {
1367
+ node.select();
1368
+ }
1369
+ };
1370
+ var getReturnFocusNode = function getReturnFocusNode(previousActiveElement) {
1371
+ var node = getNodeForOption('setReturnFocus', {
1372
+ params: [previousActiveElement]
1373
+ });
1374
+ return node ? node : node === false ? false : previousActiveElement;
1375
+ };
1376
+
1377
+ /**
1378
+ * Finds the next node (in either direction) where focus should move according to a
1379
+ * keyboard focus-in event.
1380
+ * @param {Object} params
1381
+ * @param {Node} [params.target] Known target __from which__ to navigate, if any.
1382
+ * @param {KeyboardEvent|FocusEvent} [params.event] Event to use if `target` isn't known (event
1383
+ * will be used to determine the `target`). Ignored if `target` is specified.
1384
+ * @param {boolean} [params.isBackward] True if focus should move backward.
1385
+ * @returns {Node|undefined} The next node, or `undefined` if a next node couldn't be
1386
+ * determined given the current state of the trap.
1387
+ */
1388
+ var findNextNavNode = function findNextNavNode(_ref3) {
1389
+ var target = _ref3.target,
1390
+ event = _ref3.event,
1391
+ _ref3$isBackward = _ref3.isBackward,
1392
+ isBackward = _ref3$isBackward === void 0 ? false : _ref3$isBackward;
1393
+ target = target || getActualTarget(event);
1394
+ updateTabbableNodes();
1395
+ var destinationNode = null;
1396
+ if (state.tabbableGroups.length > 0) {
1397
+ // make sure the target is actually contained in a group
1398
+ // NOTE: the target may also be the container itself if it's focusable
1399
+ // with tabIndex='-1' and was given initial focus
1400
+ var containerIndex = findContainerIndex(target, event);
1401
+ var containerGroup = containerIndex >= 0 ? state.containerGroups[containerIndex] : undefined;
1402
+ if (containerIndex < 0) {
1403
+ // target not found in any group: quite possible focus has escaped the trap,
1404
+ // so bring it back into...
1405
+ if (isBackward) {
1406
+ // ...the last node in the last group
1407
+ destinationNode = state.tabbableGroups[state.tabbableGroups.length - 1].lastTabbableNode;
1408
+ } else {
1409
+ // ...the first node in the first group
1410
+ destinationNode = state.tabbableGroups[0].firstTabbableNode;
1411
+ }
1412
+ } else if (isBackward) {
1413
+ // REVERSE
1414
+
1415
+ // is the target the first tabbable node in a group?
1416
+ var startOfGroupIndex = state.tabbableGroups.findIndex(function (_ref4) {
1417
+ var firstTabbableNode = _ref4.firstTabbableNode;
1418
+ return target === firstTabbableNode;
1419
+ });
1420
+ if (startOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target, false))) {
1421
+ // an exception case where the target is either the container itself, or
1422
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1423
+ // and user clicked on it or node was programmatically given focus)
1424
+ // and is not followed by any other tabbable node, in which
1425
+ // case, we should handle shift+tab as if focus were on the container's
1426
+ // first tabbable node, and go to the last tabbable node of the LAST group
1427
+ startOfGroupIndex = containerIndex;
1428
+ }
1429
+ if (startOfGroupIndex >= 0) {
1430
+ // YES: then shift+tab should go to the last tabbable node in the
1431
+ // previous group (and wrap around to the last tabbable node of
1432
+ // the LAST group if it's the first tabbable node of the FIRST group)
1433
+ var destinationGroupIndex = startOfGroupIndex === 0 ? state.tabbableGroups.length - 1 : startOfGroupIndex - 1;
1434
+ var destinationGroup = state.tabbableGroups[destinationGroupIndex];
1435
+ destinationNode = getTabIndex(target) >= 0 ? destinationGroup.lastTabbableNode : destinationGroup.lastDomTabbableNode;
1436
+ } else if (!isTabEvent(event)) {
1437
+ // user must have customized the nav keys so we have to move focus manually _within_
1438
+ // the active group: do this based on the order determined by tabbable()
1439
+ destinationNode = containerGroup.nextTabbableNode(target, false);
1440
+ }
1441
+ } else {
1442
+ // FORWARD
1443
+
1444
+ // is the target the last tabbable node in a group?
1445
+ var lastOfGroupIndex = state.tabbableGroups.findIndex(function (_ref5) {
1446
+ var lastTabbableNode = _ref5.lastTabbableNode;
1447
+ return target === lastTabbableNode;
1448
+ });
1449
+ if (lastOfGroupIndex < 0 && (containerGroup.container === target || isFocusable(target, config.tabbableOptions) && !isTabbable(target, config.tabbableOptions) && !containerGroup.nextTabbableNode(target))) {
1450
+ // an exception case where the target is the container itself, or
1451
+ // a non-tabbable node that was given focus (i.e. tabindex is negative
1452
+ // and user clicked on it or node was programmatically given focus)
1453
+ // and is not followed by any other tabbable node, in which
1454
+ // case, we should handle tab as if focus were on the container's
1455
+ // last tabbable node, and go to the first tabbable node of the FIRST group
1456
+ lastOfGroupIndex = containerIndex;
1457
+ }
1458
+ if (lastOfGroupIndex >= 0) {
1459
+ // YES: then tab should go to the first tabbable node in the next
1460
+ // group (and wrap around to the first tabbable node of the FIRST
1461
+ // group if it's the last tabbable node of the LAST group)
1462
+ var _destinationGroupIndex = lastOfGroupIndex === state.tabbableGroups.length - 1 ? 0 : lastOfGroupIndex + 1;
1463
+ var _destinationGroup = state.tabbableGroups[_destinationGroupIndex];
1464
+ destinationNode = getTabIndex(target) >= 0 ? _destinationGroup.firstTabbableNode : _destinationGroup.firstDomTabbableNode;
1465
+ } else if (!isTabEvent(event)) {
1466
+ // user must have customized the nav keys so we have to move focus manually _within_
1467
+ // the active group: do this based on the order determined by tabbable()
1468
+ destinationNode = containerGroup.nextTabbableNode(target);
1469
+ }
1470
+ }
1471
+ } else {
1472
+ // no groups available
1473
+ // NOTE: the fallbackFocus option does not support returning false to opt-out
1474
+ destinationNode = getNodeForOption('fallbackFocus');
1475
+ }
1476
+ return destinationNode;
1477
+ };
1478
+
1479
+ // This needs to be done on mousedown and touchstart instead of click
1480
+ // so that it precedes the focus event.
1481
+ var checkPointerDown = function checkPointerDown(e) {
1482
+ var target = getActualTarget(e);
1483
+ if (findContainerIndex(target, e) >= 0) {
1484
+ // allow the click since it ocurred inside the trap
1485
+ return;
1486
+ }
1487
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1488
+ // immediately deactivate the trap
1489
+ trap.deactivate({
1490
+ // NOTE: by setting `returnFocus: false`, deactivate() will do nothing,
1491
+ // which will result in the outside click setting focus to the node
1492
+ // that was clicked (and if not focusable, to "nothing"); by setting
1493
+ // `returnFocus: true`, we'll attempt to re-focus the node originally-focused
1494
+ // on activation (or the configured `setReturnFocus` node), whether the
1495
+ // outside click was on a focusable node or not
1496
+ returnFocus: config.returnFocusOnDeactivate
1497
+ });
1498
+ return;
1499
+ }
1500
+
1501
+ // This is needed for mobile devices.
1502
+ // (If we'll only let `click` events through,
1503
+ // then on mobile they will be blocked anyways if `touchstart` is blocked.)
1504
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1505
+ // allow the click outside the trap to take place
1506
+ return;
1507
+ }
1508
+
1509
+ // otherwise, prevent the click
1510
+ e.preventDefault();
1511
+ };
1512
+
1513
+ // In case focus escapes the trap for some strange reason, pull it back in.
1514
+ // NOTE: the focusIn event is NOT cancelable, so if focus escapes, it may cause unexpected
1515
+ // scrolling if the node that got focused was out of view; there's nothing we can do to
1516
+ // prevent that from happening by the time we discover that focus escaped
1517
+ var checkFocusIn = function checkFocusIn(event) {
1518
+ var target = getActualTarget(event);
1519
+ var targetContained = findContainerIndex(target, event) >= 0;
1520
+
1521
+ // In Firefox when you Tab out of an iframe the Document is briefly focused.
1522
+ if (targetContained || target instanceof Document) {
1523
+ if (targetContained) {
1524
+ state.mostRecentlyFocusedNode = target;
1525
+ }
1526
+ } else {
1527
+ // escaped! pull it back in to where it just left
1528
+ event.stopImmediatePropagation();
1529
+
1530
+ // focus will escape if the MRU node had a positive tab index and user tried to nav forward;
1531
+ // it will also escape if the MRU node had a 0 tab index and user tried to nav backward
1532
+ // toward a node with a positive tab index
1533
+ var nextNode; // next node to focus, if we find one
1534
+ var navAcrossContainers = true;
1535
+ if (state.mostRecentlyFocusedNode) {
1536
+ if (getTabIndex(state.mostRecentlyFocusedNode) > 0) {
1537
+ // MRU container index must be >=0 otherwise we wouldn't have it as an MRU node...
1538
+ var mruContainerIdx = findContainerIndex(state.mostRecentlyFocusedNode);
1539
+ // there MAY not be any tabbable nodes in the container if there are at least 2 containers
1540
+ // and the MRU node is focusable but not tabbable (focus-trap requires at least 1 container
1541
+ // with at least one tabbable node in order to function, so this could be the other container
1542
+ // with nothing tabbable in it)
1543
+ var tabbableNodes = state.containerGroups[mruContainerIdx].tabbableNodes;
1544
+ if (tabbableNodes.length > 0) {
1545
+ // MRU tab index MAY not be found if the MRU node is focusable but not tabbable
1546
+ var mruTabIdx = tabbableNodes.findIndex(function (node) {
1547
+ return node === state.mostRecentlyFocusedNode;
1548
+ });
1549
+ if (mruTabIdx >= 0) {
1550
+ if (config.isKeyForward(state.recentNavEvent)) {
1551
+ if (mruTabIdx + 1 < tabbableNodes.length) {
1552
+ nextNode = tabbableNodes[mruTabIdx + 1];
1553
+ navAcrossContainers = false;
1554
+ }
1555
+ // else, don't wrap within the container as focus should move to next/previous
1556
+ // container
1557
+ } else {
1558
+ if (mruTabIdx - 1 >= 0) {
1559
+ nextNode = tabbableNodes[mruTabIdx - 1];
1560
+ navAcrossContainers = false;
1561
+ }
1562
+ // else, don't wrap within the container as focus should move to next/previous
1563
+ // container
1564
+ }
1565
+ // else, don't find in container order without considering direction too
1566
+ }
1567
+ }
1568
+ // else, no tabbable nodes in that container (which means we must have at least one other
1569
+ // container with at least one tabbable node in it, otherwise focus-trap would've thrown
1570
+ // an error the last time updateTabbableNodes() was run): find next node among all known
1571
+ // containers
1572
+ } else {
1573
+ // check to see if there's at least one tabbable node with a positive tab index inside
1574
+ // the trap because focus seems to escape when navigating backward from a tabbable node
1575
+ // with tabindex=0 when this is the case (instead of wrapping to the tabbable node with
1576
+ // the greatest positive tab index like it should)
1577
+ if (!state.containerGroups.some(function (g) {
1578
+ return g.tabbableNodes.some(function (n) {
1579
+ return getTabIndex(n) > 0;
1580
+ });
1581
+ })) {
1582
+ // no containers with tabbable nodes with positive tab indexes which means the focus
1583
+ // escaped for some other reason and we should just execute the fallback to the
1584
+ // MRU node or initial focus node, if any
1585
+ navAcrossContainers = false;
1586
+ }
1587
+ }
1588
+ } else {
1589
+ // no MRU node means we're likely in some initial condition when the trap has just
1590
+ // been activated and initial focus hasn't been given yet, in which case we should
1591
+ // fall through to trying to focus the initial focus node, which is what should
1592
+ // happen below at this point in the logic
1593
+ navAcrossContainers = false;
1594
+ }
1595
+ if (navAcrossContainers) {
1596
+ nextNode = findNextNavNode({
1597
+ // move FROM the MRU node, not event-related node (which will be the node that is
1598
+ // outside the trap causing the focus escape we're trying to fix)
1599
+ target: state.mostRecentlyFocusedNode,
1600
+ isBackward: config.isKeyBackward(state.recentNavEvent)
1601
+ });
1602
+ }
1603
+ if (nextNode) {
1604
+ _tryFocus(nextNode);
1605
+ } else {
1606
+ _tryFocus(state.mostRecentlyFocusedNode || getInitialFocusNode());
1607
+ }
1608
+ }
1609
+ state.recentNavEvent = undefined; // clear
1610
+ };
1611
+
1612
+ // Hijack key nav events on the first and last focusable nodes of the trap,
1613
+ // in order to prevent focus from escaping. If it escapes for even a
1614
+ // moment it can end up scrolling the page and causing confusion so we
1615
+ // kind of need to capture the action at the keydown phase.
1616
+ var checkKeyNav = function checkKeyNav(event) {
1617
+ var isBackward = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1618
+ state.recentNavEvent = event;
1619
+ var destinationNode = findNextNavNode({
1620
+ event: event,
1621
+ isBackward: isBackward
1622
+ });
1623
+ if (destinationNode) {
1624
+ if (isTabEvent(event)) {
1625
+ // since tab natively moves focus, we wouldn't have a destination node unless we
1626
+ // were on the edge of a container and had to move to the next/previous edge, in
1627
+ // which case we want to prevent default to keep the browser from moving focus
1628
+ // to where it normally would
1629
+ event.preventDefault();
1630
+ }
1631
+ _tryFocus(destinationNode);
1632
+ }
1633
+ // else, let the browser take care of [shift+]tab and move the focus
1634
+ };
1635
+ var checkTabKey = function checkTabKey(event) {
1636
+ if (config.isKeyForward(event) || config.isKeyBackward(event)) {
1637
+ checkKeyNav(event, config.isKeyBackward(event));
1638
+ }
1639
+ };
1640
+
1641
+ // we use a different event phase for the Escape key to allow canceling the event and checking for this in escapeDeactivates
1642
+ var checkEscapeKey = function checkEscapeKey(event) {
1643
+ if (isEscapeEvent(event) && valueOrHandler(config.escapeDeactivates, event) !== false) {
1644
+ event.preventDefault();
1645
+ trap.deactivate();
1646
+ }
1647
+ };
1648
+ var checkClick = function checkClick(e) {
1649
+ var target = getActualTarget(e);
1650
+ if (findContainerIndex(target, e) >= 0) {
1651
+ return;
1652
+ }
1653
+ if (valueOrHandler(config.clickOutsideDeactivates, e)) {
1654
+ return;
1655
+ }
1656
+ if (valueOrHandler(config.allowOutsideClick, e)) {
1657
+ return;
1658
+ }
1659
+ e.preventDefault();
1660
+ e.stopImmediatePropagation();
1661
+ };
1662
+
1663
+ //
1664
+ // EVENT LISTENERS
1665
+ //
1666
+
1667
+ var addListeners = function addListeners() {
1668
+ if (!state.active) {
1669
+ return;
1670
+ }
1671
+
1672
+ // There can be only one listening focus trap at a time
1673
+ activeFocusTraps.activateTrap(trapStack, trap);
1674
+
1675
+ // Delay ensures that the focused element doesn't capture the event
1676
+ // that caused the focus trap activation.
1677
+ state.delayInitialFocusTimer = config.delayInitialFocus ? delay(function () {
1678
+ _tryFocus(getInitialFocusNode());
1679
+ }) : _tryFocus(getInitialFocusNode());
1680
+ doc.addEventListener('focusin', checkFocusIn, true);
1681
+ doc.addEventListener('mousedown', checkPointerDown, {
1682
+ capture: true,
1683
+ passive: false
1684
+ });
1685
+ doc.addEventListener('touchstart', checkPointerDown, {
1686
+ capture: true,
1687
+ passive: false
1688
+ });
1689
+ doc.addEventListener('click', checkClick, {
1690
+ capture: true,
1691
+ passive: false
1692
+ });
1693
+ doc.addEventListener('keydown', checkTabKey, {
1694
+ capture: true,
1695
+ passive: false
1696
+ });
1697
+ doc.addEventListener('keydown', checkEscapeKey);
1698
+ return trap;
1699
+ };
1700
+ var removeListeners = function removeListeners() {
1701
+ if (!state.active) {
1702
+ return;
1703
+ }
1704
+ doc.removeEventListener('focusin', checkFocusIn, true);
1705
+ doc.removeEventListener('mousedown', checkPointerDown, true);
1706
+ doc.removeEventListener('touchstart', checkPointerDown, true);
1707
+ doc.removeEventListener('click', checkClick, true);
1708
+ doc.removeEventListener('keydown', checkTabKey, true);
1709
+ doc.removeEventListener('keydown', checkEscapeKey);
1710
+ return trap;
1711
+ };
1712
+
1713
+ //
1714
+ // MUTATION OBSERVER
1715
+ //
1716
+
1717
+ var checkDomRemoval = function checkDomRemoval(mutations) {
1718
+ var isFocusedNodeRemoved = mutations.some(function (mutation) {
1719
+ var removedNodes = Array.from(mutation.removedNodes);
1720
+ return removedNodes.some(function (node) {
1721
+ return node === state.mostRecentlyFocusedNode;
1722
+ });
1723
+ });
1724
+
1725
+ // If the currently focused is removed then browsers will move focus to the
1726
+ // <body> element. If this happens, try to move focus back into the trap.
1727
+ if (isFocusedNodeRemoved) {
1728
+ _tryFocus(getInitialFocusNode());
1729
+ }
1730
+ };
1731
+
1732
+ // Use MutationObserver - if supported - to detect if focused node is removed
1733
+ // from the DOM.
1734
+ var mutationObserver = typeof window !== 'undefined' && 'MutationObserver' in window ? new MutationObserver(checkDomRemoval) : undefined;
1735
+ var updateObservedNodes = function updateObservedNodes() {
1736
+ if (!mutationObserver) {
1737
+ return;
1738
+ }
1739
+ mutationObserver.disconnect();
1740
+ if (state.active && !state.paused) {
1741
+ state.containers.map(function (container) {
1742
+ mutationObserver.observe(container, {
1743
+ subtree: true,
1744
+ childList: true
1745
+ });
1746
+ });
1747
+ }
1748
+ };
1749
+
1750
+ //
1751
+ // TRAP DEFINITION
1752
+ //
1753
+
1754
+ trap = {
1755
+ get active() {
1756
+ return state.active;
1757
+ },
1758
+ get paused() {
1759
+ return state.paused;
1760
+ },
1761
+ activate: function activate(activateOptions) {
1762
+ if (state.active) {
1763
+ return this;
1764
+ }
1765
+ var onActivate = getOption(activateOptions, 'onActivate');
1766
+ var onPostActivate = getOption(activateOptions, 'onPostActivate');
1767
+ var checkCanFocusTrap = getOption(activateOptions, 'checkCanFocusTrap');
1768
+ if (!checkCanFocusTrap) {
1769
+ updateTabbableNodes();
1770
+ }
1771
+ state.active = true;
1772
+ state.paused = false;
1773
+ state.nodeFocusedBeforeActivation = _getActiveElement(doc);
1774
+ onActivate === null || onActivate === void 0 || onActivate();
1775
+ var finishActivation = function finishActivation() {
1776
+ if (checkCanFocusTrap) {
1777
+ updateTabbableNodes();
1778
+ }
1779
+ addListeners();
1780
+ updateObservedNodes();
1781
+ onPostActivate === null || onPostActivate === void 0 || onPostActivate();
1782
+ };
1783
+ if (checkCanFocusTrap) {
1784
+ checkCanFocusTrap(state.containers.concat()).then(finishActivation, finishActivation);
1785
+ return this;
1786
+ }
1787
+ finishActivation();
1788
+ return this;
1789
+ },
1790
+ deactivate: function deactivate(deactivateOptions) {
1791
+ if (!state.active) {
1792
+ return this;
1793
+ }
1794
+ var options = _objectSpread2({
1795
+ onDeactivate: config.onDeactivate,
1796
+ onPostDeactivate: config.onPostDeactivate,
1797
+ checkCanReturnFocus: config.checkCanReturnFocus
1798
+ }, deactivateOptions);
1799
+ clearTimeout(state.delayInitialFocusTimer); // noop if undefined
1800
+ state.delayInitialFocusTimer = undefined;
1801
+ removeListeners();
1802
+ state.active = false;
1803
+ state.paused = false;
1804
+ updateObservedNodes();
1805
+ activeFocusTraps.deactivateTrap(trapStack, trap);
1806
+ var onDeactivate = getOption(options, 'onDeactivate');
1807
+ var onPostDeactivate = getOption(options, 'onPostDeactivate');
1808
+ var checkCanReturnFocus = getOption(options, 'checkCanReturnFocus');
1809
+ var returnFocus = getOption(options, 'returnFocus', 'returnFocusOnDeactivate');
1810
+ onDeactivate === null || onDeactivate === void 0 || onDeactivate();
1811
+ var finishDeactivation = function finishDeactivation() {
1812
+ delay(function () {
1813
+ if (returnFocus) {
1814
+ _tryFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation));
1815
+ }
1816
+ onPostDeactivate === null || onPostDeactivate === void 0 || onPostDeactivate();
1817
+ });
1818
+ };
1819
+ if (returnFocus && checkCanReturnFocus) {
1820
+ checkCanReturnFocus(getReturnFocusNode(state.nodeFocusedBeforeActivation)).then(finishDeactivation, finishDeactivation);
1821
+ return this;
1822
+ }
1823
+ finishDeactivation();
1824
+ return this;
1825
+ },
1826
+ pause: function pause(pauseOptions) {
1827
+ if (!state.active) {
1828
+ return this;
1829
+ }
1830
+ state.manuallyPaused = true;
1831
+ return this._setPausedState(true, pauseOptions);
1832
+ },
1833
+ unpause: function unpause(unpauseOptions) {
1834
+ if (!state.active) {
1835
+ return this;
1836
+ }
1837
+ state.manuallyPaused = false;
1838
+ if (trapStack[trapStack.length - 1] !== this) {
1839
+ return this;
1840
+ }
1841
+ return this._setPausedState(false, unpauseOptions);
1842
+ },
1843
+ updateContainerElements: function updateContainerElements(containerElements) {
1844
+ var elementsAsArray = [].concat(containerElements).filter(Boolean);
1845
+ state.containers = elementsAsArray.map(function (element) {
1846
+ return typeof element === 'string' ? doc.querySelector(element) : element;
1847
+ });
1848
+ if (state.active) {
1849
+ updateTabbableNodes();
1850
+ }
1851
+ updateObservedNodes();
1852
+ return this;
1853
+ }
1854
+ };
1855
+ Object.defineProperties(trap, {
1856
+ _isManuallyPaused: {
1857
+ value: function value() {
1858
+ return state.manuallyPaused;
1859
+ }
1860
+ },
1861
+ _setPausedState: {
1862
+ value: function value(paused, options) {
1863
+ if (state.paused === paused) {
1864
+ return this;
1865
+ }
1866
+ state.paused = paused;
1867
+ if (paused) {
1868
+ var onPause = getOption(options, 'onPause');
1869
+ var onPostPause = getOption(options, 'onPostPause');
1870
+ onPause === null || onPause === void 0 || onPause();
1871
+ removeListeners();
1872
+ updateObservedNodes();
1873
+ onPostPause === null || onPostPause === void 0 || onPostPause();
1874
+ } else {
1875
+ var onUnpause = getOption(options, 'onUnpause');
1876
+ var onPostUnpause = getOption(options, 'onPostUnpause');
1877
+ onUnpause === null || onUnpause === void 0 || onUnpause();
1878
+ updateTabbableNodes();
1879
+ addListeners();
1880
+ updateObservedNodes();
1881
+ onPostUnpause === null || onPostUnpause === void 0 || onPostUnpause();
1882
+ }
1883
+ return this;
1884
+ }
1885
+ }
1886
+ });
1887
+
1888
+ // initialize container elements
1889
+ trap.updateContainerElements(elements);
1890
+ return trap;
1891
+ };
1892
+
1893
+ const drawerCss = ":host{--background:var(--road-surface);--color:var(--road-on-surface);--header-icon:var(--road-on-surface);--header-color:var(--road-on-surface);--header-background:var(--road-surface);--header-delimiter:0;--back-chevron-color:var(--road-icon);--max-height:auto;--z-index:10;position:fixed;top:0;left:0;z-index:var(--z-index);display:flex;justify-content:flex-start;width:100%;height:100%;overflow:hidden;font-family:var(--road-font, sans-serif);line-height:1.5;color:var(--color);visibility:hidden !important;opacity:0;transition:opacity 0.15s linear, visibility 0.15s}.drawer-overlay{position:absolute;top:0;right:0;bottom:0;left:0;display:block;touch-action:none;cursor:pointer;background:var(--road-overlay)}.drawer-dialog{position:relative;width:100%;pointer-events:none;transition:transform 0.3s ease-out;transform:translateX(-100%)}:host(.drawer-right){justify-content:flex-end}:host(.drawer-right) .drawer-dialog{transform:translateX(100%)}:host(.drawer-bottom){align-items:flex-end}:host(.drawer-bottom) .drawer-dialog{width:100%;max-height:var(--max-height);transform:translateY(100%)}:host(.drawer-bottom) .drawer-content{height:auto}.drawer-content{position:relative;display:flex;flex-direction:column;width:100%;height:100vh;max-height:100vh;pointer-events:auto;background-color:var(--background);background-clip:padding-box;box-shadow:var(--road-elevation-hight)}.drawer-header{display:flex;flex-shrink:0;align-items:center;justify-content:flex-end;color:var(--header-color);background:var(--header-background);border-color:var(--road-grey-300);border-style:solid;border-width:var(--header-delimiter)}.drawer-header road-icon{flex-shrink:0;color:var(--header-icon)}.drawer-footer{padding:var(--road-spacing-05);background-color:var(--road-surface)}.drawer-footer.remove-padding{padding:0}.drawer-header-inverse{--header-icon:var(--road-on-primary);--header-color:var(--road-on-primary);--header-background:var(--road-primary-variant);margin-bottom:2.5rem}.drawer-action,.drawer-close{display:flex;align-items:center;justify-content:center;padding:0.5rem;font-family:inherit;font-size:0.875rem;color:inherit;cursor:pointer;background:transparent;border:0;appearance:none;-webkit-tap-highlight-color:rgba(0, 0, 0, 0)}.drawer-header:not(.drawer-header-inverse) .drawer-action road-icon{color:var(--back-chevron-color)}.drawer-action~.drawer-title,.drawer-close~.drawer-title{padding-left:0}.drawer-action-left,.drawer-close-left{margin-right:auto}.drawer-title{display:flex;flex-grow:1;align-items:center;justify-content:center;padding-left:3.5rem;margin:0;font-size:var(--road-body-medium)}.drawer-body{overflow-y:auto;padding:0 var(--road-spacing-05) var(--road-spacing-05)}.drawer-body.remove-padding{padding:0}:host(.drawer-right) .drawer-body,:host(.drawer-left) .drawer-body{height:calc(100vh - 3.5rem)}.drawer-inner{padding:0 1rem 2.5rem}@media (min-width: 768px){.drawer-inner{padding:0 2rem 2.5rem}.drawer-body{padding:0 var(--road-spacing-08) var(--road-spacing-05)}.drawer-body.remove-padding{padding:0}.drawer-footer{padding:var(--road-spacing-05) var(--road-spacing-08)}.drawer-footer.remove-padding{padding:0}}:host(.drawer-open){visibility:visible !important;opacity:1}:host(.drawer-open) .drawer-dialog{transform:none}";
309
1894
  const RoadDrawerStyle0 = drawerCss;
310
1895
 
311
1896
  const Drawer = class {
@@ -319,8 +1904,8 @@ const Drawer = class {
319
1904
  */
320
1905
  this.isOpen = false;
321
1906
  /**
322
- * Set removePadding property to true to remove padding for drawer body
323
- */
1907
+ * Set removePadding property to true to remove padding for drawer body
1908
+ */
324
1909
  this.removePadding = false;
325
1910
  /**
326
1911
  * position of the drawer. e.g. left, right, bottom
@@ -391,24 +1976,30 @@ const Drawer = class {
391
1976
  handleOpen(openValue) {
392
1977
  if (openValue === true) {
393
1978
  this.onOpen.emit();
394
- // Focus the first button element after the drawer is opened
395
- setTimeout(() => this.focusFirstButton(), 50); // Add a slight delay to ensure the element is rendered
1979
+ // Focus the first button element after the drawer is opened then focus trap
1980
+ setTimeout(() => {
1981
+ var _a;
1982
+ this.focusFirstElement();
1983
+ (_a = this.focusTrap) === null || _a === void 0 ? void 0 : _a.activate();
1984
+ }, 50); // Add a slight delay to ensure the element is rendered
396
1985
  }
397
1986
  else {
398
1987
  this.el.addEventListener('transitionend', () => {
1988
+ var _a;
1989
+ (_a = this.focusTrap) === null || _a === void 0 ? void 0 : _a.deactivate();
399
1990
  this.onClose.emit();
400
1991
  this.el.shadowRoot && (this.el.shadowRoot.querySelector('.drawer-body').scrollTop = 0);
401
1992
  }, { once: true });
402
1993
  }
403
1994
  }
404
1995
  /**
405
- * Find and focus the first button element in the drawer
1996
+ * Find and focus the first element in the drawer
406
1997
  */
407
- focusFirstButton() {
1998
+ focusFirstElement() {
408
1999
  var _a;
409
- const buttonElement = (_a = this.el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('button');
410
- if (buttonElement) {
411
- buttonElement.focus(); // Focus the first button element
2000
+ const firstElement = (_a = this.el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelectorAll('a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [contenteditable], [tabindex]:not([tabindex="-1"])')[0];
2001
+ if (firstElement) {
2002
+ firstElement.focus();
412
2003
  }
413
2004
  }
414
2005
  /**
@@ -423,9 +2014,18 @@ const Drawer = class {
423
2014
  * Call close function when clicking an element with data-dismiss="modal" attribute
424
2015
  */
425
2016
  componentDidLoad() {
2017
+ var _a;
426
2018
  this.el.querySelectorAll('[data-dismiss="modal"]').forEach(item => {
427
2019
  item.addEventListener('click', () => this.close());
428
2020
  });
2021
+ const drawerContent = (_a = this.el.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector(".drawer-dialog");
2022
+ this.focusTrap = createFocusTrap(drawerContent, {
2023
+ onActivate: () => drawerContent === null || drawerContent === void 0 ? void 0 : drawerContent.classList.add("focus-trapped"),
2024
+ onDeactivate: () => drawerContent === null || drawerContent === void 0 ? void 0 : drawerContent.classList.remove("focus-trapped"),
2025
+ tabbableOptions: {
2026
+ getShadowRoot: true,
2027
+ },
2028
+ });
429
2029
  }
430
2030
  render() {
431
2031
  var _a, _b, _c, _d;
@@ -441,7 +2041,7 @@ const Drawer = class {
441
2041
  const drawerWidthValue = this.position === 'bottom' ? '100%' : `${this.drawerWidth}px`;
442
2042
  const footerSlotElement = (_d = this.el.shadowRoot) === null || _d === void 0 ? void 0 : _d.querySelector('slot[name="footer"]');
443
2043
  const hasFooterContent = footerSlotElement instanceof HTMLSlotElement && footerSlotElement.assignedNodes().length > 0;
444
- return (index.h(index.Host, { key: '8a221daad83a03c6635059b21b807ea546f94033', class: `${drawerIsOpenClass} drawer-${this.position}`, tabindex: "0", role: "dialog", "aria-label": ariaLabel }, index.h("div", { key: '28de6daf4125334413589e02b3c568936fd54596', class: "drawer-overlay", onClick: this.onClick, tabindex: "-1" }), index.h("div", { key: '555dd191eb27d3b5b0e97d1a0a29065e1d019195', class: "drawer-dialog", style: { maxWidth: drawerWidthValue }, role: "document", tabindex: "0" }, index.h("div", { key: 'ca12f58fd65bec534130f96de55781440a99a3f3', class: "drawer-content" }, index.h("header", { key: '3fbdbf60e39f0bb41de438fca2f90dd7368d2360', class: `drawer-header ${inverseHeaderClass} ${drawerDelimiterClass}` }, backIconElement, this.drawerTitle ? (index.h("h2", { class: "drawer-title" }, this.drawerTitle)) : (index.h("div", { class: "drawer-title" }, index.h("slot", { name: "title" }))), closeIconElement), index.h("div", { key: '2c87df1cd3e5aeaff575e06a21cc95bb58e123d5', class: `drawer-body ${removePaddingClass}` }, index.h("slot", { key: '146a53a578800960a1ec69a9ad73fab9f7ec1d08' })), index.h("footer", { key: 'b67cf3313766e0b1ec4e903c536c68f8dfbc3cc9', class: `drawer-footer ${removePaddingClass}`, style: { display: hasFooterContent ? 'block' : 'none' } }, index.h("slot", { key: '2fa3f2e7b39ec3b03fba1a76ceb3a5c64d00c0e5', name: "footer" }))))));
2044
+ return (index.h(index.Host, { key: 'a2f62ec1ecc2d5452041c1aef21c219dfb7d37e5', class: `${drawerIsOpenClass} drawer-${this.position}`, tabindex: "0", role: "dialog", "aria-label": ariaLabel }, index.h("div", { key: '483e792abee343f79a36594eb391203521dac055', class: "drawer-overlay", onClick: this.onClick, tabindex: "-1" }), index.h("div", { key: 'b0692ac024a6f402915f482177b867f1d3fa5144', class: "drawer-dialog", style: { maxWidth: drawerWidthValue }, role: "document", tabindex: "0" }, index.h("div", { key: '6afd92780745fe0f6817adb5fba8649a9de0cdd9', class: "drawer-content" }, index.h("header", { key: '5248706c77aeaa4ce3332acfe7f3b605cbe7fd54', class: `drawer-header ${inverseHeaderClass} ${drawerDelimiterClass}` }, backIconElement, this.drawerTitle ? (index.h("h2", { class: "drawer-title" }, this.drawerTitle)) : (index.h("div", { class: "drawer-title" }, index.h("slot", { name: "title" }))), closeIconElement), index.h("div", { key: '42ade4a899a1f381af1463ac5217c245de22c241', class: `drawer-body ${removePaddingClass}` }, index.h("slot", { key: 'adb1a893b61941e6488ba3bc233540ca18d90252' })), index.h("footer", { key: '7fb54e5564e98777a3fbf3474d323f7fe1eb0e07', class: `drawer-footer ${removePaddingClass}`, style: { display: hasFooterContent ? 'block' : 'none' } }, index.h("slot", { key: '37f2d0ec86cccc74795bc9a8fb509c5ded347f92', name: "footer" }))))));
445
2045
  }
446
2046
  get el() { return index.getElement(this); }
447
2047
  static get watchers() { return {