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