vrembem 4.0.0-next.25 → 4.0.0-next.26

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.
package/dev/index.js CHANGED
@@ -5,7 +5,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
5
5
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
6
6
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
7
7
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
8
- var _handler, _focusable, _handleFocusTrap, _handleFocusLock, _handleClick, _handleKeydown, _handleClick2, _handleKeydown2, _handleKeydown3;
8
+ var _handler, _entryPrototype, _focusable, _handleFocusTrap, _handleFocusLock, _handleClick, _handleKeydown, _handleClick2, _handleKeydown2, _handleKeydown3;
9
9
  class Breakpoint {
10
10
  constructor(value, handler) {
11
11
  __privateAdd(this, _handler);
@@ -43,8 +43,72 @@ class Breakpoint {
43
43
  }
44
44
  _handler = new WeakMap();
45
45
  class Collection {
46
- constructor() {
46
+ constructor(options = {}) {
47
+ __privateAdd(this, _entryPrototype);
48
+ const root = this;
49
+ this.module = this.constructor.name;
47
50
  this.collection = [];
51
+ this.settings = Object.assign({ dataConfig: "config" }, options);
52
+ __privateSet(this, _entryPrototype, {
53
+ applySettings(obj) {
54
+ return Object.assign(this.settings, obj);
55
+ },
56
+ getDataConfig() {
57
+ return Object.assign(this.dataConfig, getConfig(this.el, this.getSetting("dataConfig")));
58
+ },
59
+ getCustomProps() {
60
+ return Object.assign(this.customProps, getCustomProps(this.el, root.module, this.customPropKeys));
61
+ },
62
+ getSetting(key) {
63
+ const camel = toCamel(key);
64
+ const kebab = toKebab(key);
65
+ if ("dataConfig" in this && camel in this.dataConfig) {
66
+ return this.dataConfig[camel];
67
+ }
68
+ if ("customProps" in this && kebab in this.customProps) {
69
+ return this.customProps[kebab];
70
+ }
71
+ if ("settings" in this && camel in this.settings) {
72
+ return this.settings[camel];
73
+ }
74
+ if ("settings" in root && camel in root.settings) {
75
+ return root.settings[camel];
76
+ }
77
+ throw new Error(`${root.module} setting does not exist: ${key}`);
78
+ },
79
+ teleport(ref = this.getSetting("teleport"), method = this.getSetting("teleportMethod")) {
80
+ if (!this.returnRef) {
81
+ this.returnRef = teleport(this.el, ref, method);
82
+ return this.el;
83
+ } else {
84
+ console.error("Element has already been teleported:", this.el);
85
+ return false;
86
+ }
87
+ },
88
+ teleportReturn() {
89
+ if (this.returnRef) {
90
+ this.returnRef = teleport(this.el, this.returnRef);
91
+ return this.el;
92
+ } else {
93
+ console.error("No return reference found:", this.el);
94
+ return false;
95
+ }
96
+ }
97
+ });
98
+ }
99
+ createEntry(query, overrides = {}) {
100
+ const el = getElement(query);
101
+ const entry = Object.create(__privateGet(this, _entryPrototype));
102
+ Object.assign(entry, {
103
+ id: el == null ? void 0 : el.id,
104
+ el,
105
+ settings: {},
106
+ dataConfig: {},
107
+ customProps: {},
108
+ customPropKeys: [],
109
+ returnRef: null
110
+ }, overrides);
111
+ return entry;
48
112
  }
49
113
  async register(item) {
50
114
  await this.deregister(item);
@@ -77,11 +141,10 @@ class Collection {
77
141
  return this.collection;
78
142
  }
79
143
  get(value, key = "id") {
80
- return this.collection.find((item) => {
81
- return item[key] === value;
82
- });
144
+ return this.collection.find((entry) => entry[key] === value);
83
145
  }
84
146
  }
147
+ _entryPrototype = new WeakMap();
85
148
  class FocusTrap {
86
149
  constructor(el = null, selectorFocus = "[data-focus]") {
87
150
  __privateAdd(this, _focusable);
@@ -211,11 +274,31 @@ function cssVar(property, options) {
211
274
  }
212
275
  }
213
276
  }
214
- function getConfig$1(el, dataConfig) {
277
+ function getConfig(el, dataConfig = "config") {
215
278
  const string = el.getAttribute(`data-${dataConfig}`) || "";
216
279
  const json = string.replace(/'/g, '"');
217
280
  return json ? JSON.parse(json) : {};
218
281
  }
282
+ function getCustomProps(el, module, array) {
283
+ const styles = getComputedStyle(el);
284
+ const result = {};
285
+ for (let i = 0; i < array.length; i++) {
286
+ const prefix = getPrefix();
287
+ const value = styles.getPropertyValue(`--${prefix}${module.toLowerCase()}-${array[i]}`).trim();
288
+ if (value) {
289
+ result[array[i]] = value;
290
+ }
291
+ }
292
+ return result;
293
+ }
294
+ function getElement(query) {
295
+ if (typeof query === "string") {
296
+ return document.getElementById(query);
297
+ } else if (query instanceof HTMLElement) {
298
+ return query;
299
+ }
300
+ return void 0;
301
+ }
219
302
  function localStore(key, enable = true) {
220
303
  const local = localStorage.getItem(key);
221
304
  const store = local ? JSON.parse(local) : {};
@@ -319,6 +402,12 @@ function themeStore(options) {
319
402
  api.callback("onInit");
320
403
  return api;
321
404
  }
405
+ function toCamel(value) {
406
+ return value.split("-").map((word, index2) => index2 === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1)).join("");
407
+ }
408
+ function toKebab(value) {
409
+ return value.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
410
+ }
322
411
  function transition(el, from, to, duration = "transition-duration") {
323
412
  return new Promise((resolve) => {
324
413
  if (typeof duration === "string") {
@@ -361,9 +450,9 @@ function setInert(state, selector) {
361
450
  });
362
451
  }
363
452
  }
364
- function updateGlobalState(state, config) {
365
- setInert(!!state, config.selectorInert);
366
- setOverflowHidden(!!state, config.selectorOverflow);
453
+ function updateGlobalState(state, selectorInert, selectorOverflow) {
454
+ setInert(!!state, selectorInert);
455
+ setOverflowHidden(!!state, selectorOverflow);
367
456
  }
368
457
  const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
369
458
  __proto__: null,
@@ -371,22 +460,24 @@ const index = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
371
460
  Collection,
372
461
  FocusTrap,
373
462
  cssVar,
374
- getConfig: getConfig$1,
463
+ getConfig,
464
+ getCustomProps,
465
+ getElement,
375
466
  getPrefix,
376
467
  localStore,
377
468
  teleport,
378
469
  themeStore,
470
+ toCamel,
471
+ toKebab,
379
472
  transition,
380
473
  updateGlobalState
381
474
  }, Symbol.toStringTag, { value: "Module" }));
382
475
  const defaults$2 = {
383
- autoMount: false,
384
476
  // Data attributes
385
477
  dataOpen: "drawer-open",
386
478
  dataClose: "drawer-close",
387
479
  dataToggle: "drawer-toggle",
388
480
  dataBreakpoint: "drawer-breakpoint",
389
- dataConfig: "drawer-config",
390
481
  // Selectors
391
482
  selectorDrawer: ".drawer",
392
483
  selectorDialog: ".drawer__dialog",
@@ -408,6 +499,8 @@ const defaults$2 = {
408
499
  store: true,
409
500
  storeKey: "VB:DrawerState",
410
501
  setTabindex: true,
502
+ teleport: null,
503
+ teleportMethod: "prepend",
411
504
  transition: true,
412
505
  transitionDuration: "drawer-transition-duration"
413
506
  };
@@ -548,61 +641,57 @@ async function deregister$2(obj, close2 = true) {
548
641
  }
549
642
  return this.collection;
550
643
  }
551
- async function open$2(query, enableTransition, focus = true) {
644
+ async function open$2(query, transitionOverride, focus = true) {
552
645
  const entry = getDrawer.call(this, query);
553
- const config = { ...this.settings, ...entry.settings };
554
- if (enableTransition !== void 0) config.transition = enableTransition;
555
646
  if (entry.state === "closed" || entry.state === "indeterminate") {
556
647
  entry.state = "opening";
557
- if (config.transition) {
648
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
558
649
  await transition(entry.el, {
559
- start: config.stateClosing,
560
- finish: config.stateClosed
650
+ start: entry.getSetting("stateClosing"),
651
+ finish: entry.getSetting("stateClosed")
561
652
  }, {
562
- start: config.stateOpening,
563
- finish: config.stateOpened
564
- }, config.transitionDuration);
653
+ start: entry.getSetting("stateOpening"),
654
+ finish: entry.getSetting("stateOpened")
655
+ }, entry.getSetting("transitionDuration"));
565
656
  } else {
566
- entry.el.classList.add(config.stateOpened);
567
- entry.el.classList.remove(config.stateClosed);
657
+ entry.el.classList.add(entry.getSetting("stateOpened"));
658
+ entry.el.classList.remove(entry.getSetting("stateClosed"));
568
659
  }
569
660
  entry.state = "opened";
570
- if (entry.mode === "modal") updateGlobalState(true, config);
661
+ if (entry.mode === "modal") updateGlobalState(true, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
571
662
  if (focus) {
572
663
  updateFocusState$1.call(this, entry);
573
664
  }
574
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "opened", {
665
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
575
666
  detail: this,
576
667
  bubbles: true
577
668
  }));
578
669
  }
579
670
  return entry;
580
671
  }
581
- async function close$2(query, enableTransition, focus = true) {
672
+ async function close$2(query, transitionOverride, focus = true) {
582
673
  const entry = getDrawer.call(this, query);
583
- const config = { ...this.settings, ...entry.settings };
584
- if (enableTransition !== void 0) config.transition = enableTransition;
585
674
  if (entry.state === "opened" || entry.state === "indeterminate") {
586
675
  entry.state = "closing";
587
676
  document.activeElement.blur();
588
- if (config.transition) {
677
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
589
678
  await transition(entry.el, {
590
- start: config.stateOpening,
591
- finish: config.stateOpened
679
+ start: entry.getSetting("stateOpening"),
680
+ finish: entry.getSetting("stateOpened")
592
681
  }, {
593
- start: config.stateClosing,
594
- finish: config.stateClosed
595
- }, config.transitionDuration);
682
+ start: entry.getSetting("stateClosing"),
683
+ finish: entry.getSetting("stateClosed")
684
+ }, entry.getSetting("transitionDuration"));
596
685
  } else {
597
- entry.el.classList.add(config.stateClosed);
598
- entry.el.classList.remove(config.stateOpened);
686
+ entry.el.classList.add(entry.getSetting("stateClosed"));
687
+ entry.el.classList.remove(entry.getSetting("stateOpened"));
599
688
  }
600
689
  entry.state = "closed";
601
- if (entry.mode === "modal") updateGlobalState(false, config);
690
+ if (entry.mode === "modal") updateGlobalState(false, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
602
691
  if (focus) {
603
692
  updateFocusState$1.call(this, entry);
604
693
  }
605
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "closed", {
694
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
606
695
  detail: this,
607
696
  bubbles: true
608
697
  }));
@@ -630,7 +719,7 @@ function switchMode(entry) {
630
719
  async function toInline(entry) {
631
720
  entry.el.classList.remove(entry.getSetting("classModal"));
632
721
  entry.dialog.removeAttribute("aria-modal");
633
- updateGlobalState(false, { ...this.settings, ...entry.settings });
722
+ updateGlobalState(false, entry.getSetting("selectorInert"), entry.getSetting("selectorOverflow"));
634
723
  this.focusTrap.unmount();
635
724
  await applyInlineState(entry);
636
725
  entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "switchMode", {
@@ -654,13 +743,42 @@ async function register$2(el, config = {}) {
654
743
  const root = this;
655
744
  const breakpoint = new Breakpoint();
656
745
  let _mode, _state = "indeterminate";
657
- const entry = {
658
- id: el.id,
659
- el,
746
+ const entry = this.createEntry(el);
747
+ Object.assign(entry, {
660
748
  dialog: null,
661
749
  trigger: null,
662
- settings: { ...getConfig$1(el, this.settings.dataConfig), ...config },
663
750
  inlineState: "indeterminate",
751
+ open(transition2, focus) {
752
+ return open$2.call(root, this, transition2, focus);
753
+ },
754
+ close(transition2, focus) {
755
+ return close$2.call(root, this, transition2, focus);
756
+ },
757
+ toggle(transition2, focus) {
758
+ return toggle.call(root, this, transition2, focus);
759
+ },
760
+ deregister() {
761
+ return deregister$2.call(root, this);
762
+ },
763
+ mountBreakpoint() {
764
+ const value = this.breakpoint;
765
+ const handler = this.handleBreakpoint.bind(this);
766
+ breakpoint.mount(value, handler);
767
+ return this;
768
+ },
769
+ unmountBreakpoint() {
770
+ breakpoint.unmount();
771
+ return this;
772
+ },
773
+ handleBreakpoint(event) {
774
+ const bpMode = event.matches ? "inline" : "modal";
775
+ if (this.mode != bpMode) {
776
+ this.mode = bpMode;
777
+ }
778
+ return this;
779
+ }
780
+ });
781
+ Object.defineProperties(entry, Object.getOwnPropertyDescriptors({
664
782
  get breakpoint() {
665
783
  return getBreakpoint.call(root, el);
666
784
  },
@@ -691,47 +809,20 @@ async function register$2(el, config = {}) {
691
809
  this.el.classList.remove(this.getSetting("stateClosed"));
692
810
  this.el.classList.remove(this.getSetting("stateClosing"));
693
811
  }
694
- },
695
- open(transition2, focus) {
696
- return open$2.call(root, this, transition2, focus);
697
- },
698
- close(transition2, focus) {
699
- return close$2.call(root, this, transition2, focus);
700
- },
701
- toggle(transition2, focus) {
702
- return toggle.call(root, this, transition2, focus);
703
- },
704
- deregister() {
705
- return deregister$2.call(root, this);
706
- },
707
- mountBreakpoint() {
708
- const value = this.breakpoint;
709
- const handler = this.handleBreakpoint.bind(this);
710
- breakpoint.mount(value, handler);
711
- return this;
712
- },
713
- unmountBreakpoint() {
714
- breakpoint.unmount();
715
- return this;
716
- },
717
- handleBreakpoint(event) {
718
- const bpMode = event.matches ? "inline" : "modal";
719
- if (this.mode != bpMode) {
720
- this.mode = bpMode;
721
- }
722
- return this;
723
- },
724
- getSetting(key) {
725
- return key in this.settings ? this.settings[key] : root.settings[key];
726
812
  }
727
- };
813
+ }));
814
+ entry.applySettings(config);
815
+ entry.getDataConfig();
816
+ if (entry.getSetting("teleport")) {
817
+ entry.teleport();
818
+ }
728
819
  this.collection.push(entry);
729
820
  const dialog = el.querySelector(entry.getSetting("selectorDialog"));
730
821
  entry.dialog = dialog ? dialog : el;
731
822
  if (entry.getSetting("setTabindex")) {
732
823
  entry.dialog.setAttribute("tabindex", "-1");
733
824
  }
734
- await applyInitialState(entry);
825
+ applyInitialState(entry);
735
826
  entry.inlineState = entry.state;
736
827
  entry.mode = el.classList.contains(entry.getSetting("classModal")) ? "modal" : "inline";
737
828
  if (entry.breakpoint) {
@@ -741,16 +832,13 @@ async function register$2(el, config = {}) {
741
832
  }
742
833
  class Drawer extends Collection {
743
834
  constructor(options) {
744
- super();
835
+ super({ ...defaults$2, ...options });
745
836
  __privateAdd(this, _handleClick);
746
837
  __privateAdd(this, _handleKeydown);
747
- this.defaults = defaults$2;
748
- this.settings = { ...this.defaults, ...options };
749
838
  this.focusTrap = new FocusTrap();
750
839
  this.store = localStore(this.settings.storeKey, this.settings.store);
751
840
  __privateSet(this, _handleClick, handleClick$2.bind(this));
752
841
  __privateSet(this, _handleKeydown, handleKeydown$2.bind(this));
753
- if (this.settings.autoMount) this.mount();
754
842
  }
755
843
  get activeModal() {
756
844
  return this.collection.find((entry) => {
@@ -802,12 +890,10 @@ class Drawer extends Collection {
802
890
  _handleClick = new WeakMap();
803
891
  _handleKeydown = new WeakMap();
804
892
  const defaults$1 = {
805
- autoMount: false,
806
893
  // Data attributes
807
894
  dataOpen: "modal-open",
808
895
  dataClose: "modal-close",
809
896
  dataReplace: "modal-replace",
810
- dataConfig: "modal-config",
811
897
  // Selectors
812
898
  selectorModal: ".modal",
813
899
  selectorDialog: ".modal__dialog",
@@ -824,9 +910,9 @@ const defaults$1 = {
824
910
  // Feature settings
825
911
  customEventPrefix: "modal:",
826
912
  eventListeners: true,
913
+ setTabindex: true,
827
914
  teleport: null,
828
915
  teleportMethod: "append",
829
- setTabindex: true,
830
916
  transition: true,
831
917
  transitionDuration: "modal-transition-duration"
832
918
  };
@@ -876,7 +962,7 @@ async function handleClick$1(event) {
876
962
  return selector === "*" ? this.closeAll() : this.close(selector);
877
963
  }
878
964
  }
879
- if (this.active && event.target.matches(this.settings.selectorScreen) && !this.active.required) {
965
+ if (this.active && event.target.matches(this.settings.selectorScreen) && !this.active.isRequired) {
880
966
  return this.close(this.active.id);
881
967
  }
882
968
  }
@@ -908,62 +994,58 @@ async function deregister$1(obj, close2 = true) {
908
994
  }
909
995
  return this.collection;
910
996
  }
911
- async function open$1(query, enableTransition, focus = true) {
997
+ async function open$1(query, transitionOverride = void 0, focus = true) {
912
998
  const entry = getModal.call(this, query);
913
- const config = { ...this.settings, ...entry.settings };
914
- if (enableTransition !== void 0) config.transition = enableTransition;
915
999
  this.stack.moveToTop(entry);
916
1000
  if (entry.state === "closed") {
917
1001
  entry.state = "opening";
918
1002
  this.stack.add(entry);
919
- if (config.transition) {
1003
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
920
1004
  await transition(entry.el, {
921
- start: config.stateClosing,
922
- finish: config.stateClosed
1005
+ start: entry.getSetting("stateClosing"),
1006
+ finish: entry.getSetting("stateClosed")
923
1007
  }, {
924
- start: config.stateOpening,
925
- finish: config.stateOpened
926
- }, config.transitionDuration);
1008
+ start: entry.getSetting("stateOpening"),
1009
+ finish: entry.getSetting("stateOpened")
1010
+ }, entry.getSetting("transitionDuration"));
927
1011
  } else {
928
- entry.el.classList.add(config.stateOpened);
929
- entry.el.classList.remove(config.stateClosed);
1012
+ entry.el.classList.add(entry.getSetting("stateOpened"));
1013
+ entry.el.classList.remove(entry.getSetting("stateClosed"));
930
1014
  }
931
1015
  entry.state = "opened";
932
1016
  }
933
1017
  if (focus) {
934
1018
  updateFocusState.call(this);
935
1019
  }
936
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "opened", {
1020
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "opened", {
937
1021
  detail: this,
938
1022
  bubbles: true
939
1023
  }));
940
1024
  return entry;
941
1025
  }
942
- async function close$1(query, enableTransition, focus = true) {
1026
+ async function close$1(query, transitionOverride, focus = true) {
943
1027
  const entry = query ? getModal.call(this, query) : this.active;
944
1028
  if (entry && entry.state === "opened") {
945
1029
  entry.state = "closing";
946
- const config = { ...this.settings, ...entry.settings };
947
- if (enableTransition !== void 0) config.transition = enableTransition;
948
1030
  document.activeElement.blur();
949
- if (config.transition) {
1031
+ if (transitionOverride != void 0 ? transitionOverride : entry.getSetting("transition")) {
950
1032
  await transition(entry.el, {
951
- start: config.stateOpening,
952
- finish: config.stateOpened
1033
+ start: entry.getSetting("stateOpening"),
1034
+ finish: entry.getSetting("stateOpened")
953
1035
  }, {
954
- start: config.stateClosing,
955
- finish: config.stateClosed
956
- }, config.transitionDuration);
1036
+ start: entry.getSetting("stateClosing"),
1037
+ finish: entry.getSetting("stateClosed")
1038
+ }, entry.getSetting("transitionDuration"));
957
1039
  } else {
958
- entry.el.classList.add(config.stateClosed);
959
- entry.el.classList.remove(config.stateOpened);
1040
+ entry.el.classList.add(entry.getSetting("stateClosed"));
1041
+ entry.el.classList.remove(entry.getSetting("stateOpened"));
960
1042
  }
961
1043
  this.stack.remove(entry);
962
1044
  entry.state = "closed";
963
1045
  if (focus) {
964
1046
  updateFocusState.call(this);
965
1047
  }
966
- entry.el.dispatchEvent(new CustomEvent(config.customEventPrefix + "closed", {
1048
+ entry.el.dispatchEvent(new CustomEvent(entry.getSetting("customEventPrefix") + "closed", {
967
1049
  detail: this,
968
1050
  bubbles: true
969
1051
  }));
@@ -1001,16 +1083,10 @@ async function replace(query, transition2, focus = true) {
1001
1083
  async function register$1(el, config = {}) {
1002
1084
  await deregister$1.call(this, el, false);
1003
1085
  const root = this;
1004
- const entry = {
1005
- id: el.id,
1086
+ const entry = this.createEntry(el);
1087
+ Object.assign(entry, {
1006
1088
  state: "closed",
1007
- el,
1008
1089
  dialog: null,
1009
- get required() {
1010
- return this.dialog.matches(this.getSetting("selectorRequired"));
1011
- },
1012
- returnRef: null,
1013
- settings: { ...getConfig$1(el, this.settings.dataConfig), ...config },
1014
1090
  open(transition2, focus) {
1015
1091
  return open$1.call(root, this, transition2, focus);
1016
1092
  },
@@ -1022,29 +1098,15 @@ async function register$1(el, config = {}) {
1022
1098
  },
1023
1099
  deregister() {
1024
1100
  return deregister$1.call(root, this);
1025
- },
1026
- teleport(ref = this.getSetting("teleport"), method = this.getSetting("teleportMethod")) {
1027
- if (!this.returnRef) {
1028
- this.returnRef = teleport(this.el, ref, method);
1029
- return this.el;
1030
- } else {
1031
- console.error("Element has already been teleported:", this.el);
1032
- return false;
1033
- }
1034
- },
1035
- teleportReturn() {
1036
- if (this.returnRef) {
1037
- this.returnRef = teleport(this.el, this.returnRef);
1038
- return this.el;
1039
- } else {
1040
- console.error("No return reference found:", this.el);
1041
- return false;
1042
- }
1043
- },
1044
- getSetting(key) {
1045
- return key in this.settings ? this.settings[key] : root.settings[key];
1046
1101
  }
1047
- };
1102
+ });
1103
+ Object.defineProperties(entry, Object.getOwnPropertyDescriptors({
1104
+ get isRequired() {
1105
+ return this.dialog.matches(this.getSetting("selectorRequired"));
1106
+ }
1107
+ }));
1108
+ entry.applySettings(config);
1109
+ entry.getDataConfig();
1048
1110
  const dialog = el.querySelector(entry.getSetting("selectorDialog"));
1049
1111
  entry.dialog = dialog ? dialog : el;
1050
1112
  entry.dialog.setAttribute("aria-modal", "true");
@@ -1058,12 +1120,12 @@ async function register$1(el, config = {}) {
1058
1120
  entry.teleport();
1059
1121
  }
1060
1122
  this.collection.push(entry);
1061
- if (entry.el.classList.contains(this.settings.stateOpened)) {
1123
+ if (entry.el.classList.contains(entry.getSetting("stateOpened"))) {
1062
1124
  await entry.open(false);
1063
1125
  } else {
1064
- entry.el.classList.remove(this.settings.stateOpening);
1065
- entry.el.classList.remove(this.settings.stateClosing);
1066
- entry.el.classList.add(this.settings.stateClosed);
1126
+ entry.el.classList.remove(entry.getSetting("stateOpening"));
1127
+ entry.el.classList.remove(entry.getSetting("stateClosing"));
1128
+ entry.el.classList.add(entry.getSetting("stateClosed"));
1067
1129
  }
1068
1130
  return entry;
1069
1131
  }
@@ -1074,7 +1136,8 @@ function stack(settings) {
1074
1136
  return [...stackArray];
1075
1137
  },
1076
1138
  get top() {
1077
- return stackArray[stackArray.length - 1];
1139
+ const result = stackArray[stackArray.length - 1];
1140
+ return result ? result : null;
1078
1141
  },
1079
1142
  updateIndex() {
1080
1143
  stackArray.forEach((entry, index2) => {
@@ -1084,7 +1147,7 @@ function stack(settings) {
1084
1147
  });
1085
1148
  },
1086
1149
  updateGlobalState() {
1087
- updateGlobalState(this.top, settings);
1150
+ updateGlobalState(this.top, settings.selectorInert, settings.selectorOverflow);
1088
1151
  this.updateIndex();
1089
1152
  },
1090
1153
  add(entry) {
@@ -1117,17 +1180,14 @@ function stack(settings) {
1117
1180
  }
1118
1181
  class Modal extends Collection {
1119
1182
  constructor(options) {
1120
- super();
1183
+ super({ ...defaults$1, ...options });
1121
1184
  __privateAdd(this, _handleClick2);
1122
1185
  __privateAdd(this, _handleKeydown2);
1123
- this.defaults = defaults$1;
1124
- this.settings = { ...this.defaults, ...options };
1125
1186
  this.trigger = null;
1126
1187
  this.focusTrap = new FocusTrap();
1127
1188
  this.stack = stack(this.settings);
1128
1189
  __privateSet(this, _handleClick2, handleClick$1.bind(this));
1129
1190
  __privateSet(this, _handleKeydown2, handleKeydown$1.bind(this));
1130
- if (this.settings.autoMount) this.mount();
1131
1191
  }
1132
1192
  get active() {
1133
1193
  return this.stack.top;
@@ -1185,46 +1245,57 @@ class Modal extends Collection {
1185
1245
  _handleClick2 = new WeakMap();
1186
1246
  _handleKeydown2 = new WeakMap();
1187
1247
  const defaults = {
1188
- autoMount: false,
1189
1248
  // Selectors
1190
1249
  selectorPopover: ".popover",
1191
1250
  selectorTooltip: ".popover_tooltip",
1192
1251
  selectorArrow: ".popover__arrow",
1193
1252
  // State classes
1194
1253
  stateActive: "is-active",
1254
+ // Custom property defaults
1255
+ placement: "bottom",
1256
+ event: "click",
1257
+ offset: 0,
1258
+ flipPadding: 0,
1259
+ shiftPadding: 0,
1260
+ arrowPadding: 0,
1261
+ toggleDelay: 0,
1195
1262
  // Feature settings
1196
1263
  eventListeners: true,
1197
- eventType: "click",
1198
- placement: "bottom",
1199
- hoverToggleDelay: 0
1264
+ teleport: null,
1265
+ teleportMethod: "append"
1200
1266
  };
1201
- function getConfig(el, settings) {
1202
- const styles = getComputedStyle(el);
1203
- const config = {
1204
- "placement": settings.placement,
1205
- "event": settings.eventType,
1206
- "offset": 0,
1207
- "overflow-padding": 0,
1208
- "flip-padding": 0,
1209
- "arrow-element": settings.selectorArrow,
1210
- "arrow-padding": 0,
1211
- "toggle-delay": settings.hoverToggleDelay
1212
- };
1213
- for (const prop in config) {
1214
- const prefix = getPrefix();
1215
- const value = styles.getPropertyValue(`--${prefix}popover-${prop}`).trim();
1216
- if (value) {
1217
- config[prop] = value;
1267
+ function applyPositionStyle(el, x, y) {
1268
+ Object.assign(el.style, {
1269
+ left: x != null ? `${x}px` : "",
1270
+ top: y != null ? `${y}px` : ""
1271
+ });
1272
+ }
1273
+ function getDelay(popover, index2) {
1274
+ let value = popover.getSetting("toggle-delay");
1275
+ if (typeof value == "string") {
1276
+ if (value.indexOf(",") > -1) {
1277
+ value = value.split(",");
1218
1278
  }
1279
+ if (value.indexOf(" ") > -1) {
1280
+ value = value.split(" ");
1281
+ }
1282
+ }
1283
+ if (Array.isArray(value)) {
1284
+ value = value[index2];
1285
+ }
1286
+ const number = Number(value);
1287
+ if (!Number.isNaN(number)) {
1288
+ return number;
1289
+ } else {
1290
+ throw new Error(`Provided delay value is not a number: "${value}"`);
1219
1291
  }
1220
- return config;
1221
1292
  }
1222
1293
  function getPadding(value) {
1223
1294
  let padding;
1224
1295
  const array = typeof value === "string" ? value.trim().split(" ") : [value];
1225
- array.forEach(function(item, index2) {
1226
- array[index2] = parseInt(item, 10);
1227
- });
1296
+ for (let index2 = 0; index2 < array.length; index2++) {
1297
+ array[index2] = Number(array[index2]);
1298
+ }
1228
1299
  switch (array.length) {
1229
1300
  case 1:
1230
1301
  padding = array[0];
@@ -1259,29 +1330,20 @@ function getPadding(value) {
1259
1330
  }
1260
1331
  return padding;
1261
1332
  }
1262
- function getModifiers(options) {
1263
- return [{
1264
- name: "offset",
1265
- options: {
1266
- offset: [0, parseInt(options["offset"], 10)]
1267
- }
1268
- }, {
1269
- name: "preventOverflow",
1270
- options: {
1271
- padding: getPadding(options["overflow-padding"])
1272
- }
1273
- }, {
1274
- name: "flip",
1275
- options: {
1276
- padding: getPadding(options["flip-padding"])
1277
- }
1278
- }, {
1279
- name: "arrow",
1280
- options: {
1281
- element: options["arrow-element"],
1282
- padding: getPadding(options["arrow-padding"])
1333
+ function getMiddlewareOptions(popover) {
1334
+ return {
1335
+ offset: Number(popover.getSetting("offset")),
1336
+ flip: {
1337
+ padding: getPadding(popover.getSetting("flip-padding"))
1338
+ },
1339
+ shift: {
1340
+ padding: getPadding(popover.getSetting("shift-padding"))
1341
+ },
1342
+ arrow: {
1343
+ element: popover.getSetting("selectorArrow"),
1344
+ padding: getPadding(popover.getSetting("arrow-padding"))
1283
1345
  }
1284
- }];
1346
+ };
1285
1347
  }
1286
1348
  function getPopover(query) {
1287
1349
  const entry = typeof query === "string" ? this.get(query) : this.get(query.id);
@@ -1331,13 +1393,7 @@ async function close(query) {
1331
1393
  if (!popover.isTooltip) {
1332
1394
  popover.trigger.setAttribute("aria-expanded", "false");
1333
1395
  }
1334
- popover.popper.setOptions({
1335
- placement: popover.config["placement"],
1336
- modifiers: [
1337
- { name: "eventListeners", enabled: false },
1338
- ...getModifiers(popover.config)
1339
- ]
1340
- });
1396
+ popover.cleanup();
1341
1397
  popover.state = "closed";
1342
1398
  if (popover.trigger === this.trigger) {
1343
1399
  this.trigger = null;
@@ -1369,16 +1425,6 @@ function closeCheck(popover) {
1369
1425
  }, 1);
1370
1426
  }
1371
1427
  function handleClick(popover) {
1372
- const tooltipId = popover.trigger.getAttribute("aria-describedby");
1373
- if (tooltipId) {
1374
- const entry = this.get(tooltipId);
1375
- if (entry.isTooltip) {
1376
- if (entry.toggleDelayId) {
1377
- clearTimeout(entry.toggleDelayId);
1378
- }
1379
- entry.close();
1380
- }
1381
- }
1382
1428
  if (popover.state === "opened") {
1383
1429
  popover.close();
1384
1430
  } else {
@@ -1387,30 +1433,41 @@ function handleClick(popover) {
1387
1433
  handleDocumentClick.call(this, popover);
1388
1434
  }
1389
1435
  }
1436
+ function handleTooltipClick(popover) {
1437
+ if (popover.isTooltip) {
1438
+ if (popover.toggleDelayId) {
1439
+ clearTimeout(popover.toggleDelayId);
1440
+ }
1441
+ popover.close();
1442
+ }
1443
+ }
1390
1444
  function handleMouseEnter(popover, event) {
1445
+ popover.isHovered = event;
1391
1446
  if (event.type == "focus" && !popover.trigger.matches(":focus-visible")) {
1392
1447
  return;
1393
1448
  }
1394
- const isExpanded = popover.trigger.getAttribute("aria-expanded");
1395
- if (isExpanded && isExpanded == "true") {
1396
- return;
1397
- }
1398
1449
  if (popover.toggleDelayId) {
1399
1450
  clearTimeout(popover.toggleDelayId);
1400
1451
  }
1401
- const delay = this.activeTooltip ? 0 : popover.config["toggle-delay"];
1402
- if (this.activeTooltip) this.activeTooltip.close();
1452
+ const isExpanded = popover.trigger.getAttribute("aria-expanded");
1453
+ if (isExpanded && isExpanded == "true") return;
1454
+ const delay = this.activeHover ? 0 : getDelay(popover, 0);
1455
+ if (this.activeHover) this.activeHover.close();
1403
1456
  popover.toggleDelayId = setTimeout(() => {
1404
1457
  if (popover.id) popover.open();
1405
1458
  }, delay);
1406
1459
  }
1407
- function handleMouseLeave(popover) {
1408
- if (popover.toggleDelayId) {
1409
- clearTimeout(popover.toggleDelayId);
1410
- }
1411
- popover.toggleDelayId = setTimeout(() => {
1412
- closeCheck.call(this, popover);
1413
- }, popover.config["toggle-delay"]);
1460
+ function handleMouseLeave(popover, event) {
1461
+ setTimeout(() => {
1462
+ popover.isHovered = event;
1463
+ if (popover.isHovered) return;
1464
+ if (popover.toggleDelayId) {
1465
+ clearTimeout(popover.toggleDelayId);
1466
+ }
1467
+ popover.toggleDelayId = setTimeout(() => {
1468
+ closeCheck.call(this, popover);
1469
+ }, getDelay(popover, 1));
1470
+ }, 1);
1414
1471
  }
1415
1472
  function handleKeydown(event) {
1416
1473
  switch (event.key) {
@@ -1447,567 +1504,1072 @@ function handleDocumentClick(popover) {
1447
1504
  }
1448
1505
  });
1449
1506
  }
1450
- var top = "top";
1451
- var bottom = "bottom";
1452
- var right = "right";
1453
- var left = "left";
1454
- var auto = "auto";
1455
- var basePlacements = [top, bottom, right, left];
1456
- var start = "start";
1457
- var end = "end";
1458
- var clippingParents = "clippingParents";
1459
- var viewport = "viewport";
1460
- var popper = "popper";
1461
- var reference = "reference";
1462
- var variationPlacements = /* @__PURE__ */ basePlacements.reduce(function(acc, placement) {
1463
- return acc.concat([placement + "-" + start, placement + "-" + end]);
1464
- }, []);
1465
- var placements = /* @__PURE__ */ [].concat(basePlacements, [auto]).reduce(function(acc, placement) {
1466
- return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
1467
- }, []);
1468
- var beforeRead = "beforeRead";
1469
- var read = "read";
1470
- var afterRead = "afterRead";
1471
- var beforeMain = "beforeMain";
1472
- var main = "main";
1473
- var afterMain = "afterMain";
1474
- var beforeWrite = "beforeWrite";
1475
- var write = "write";
1476
- var afterWrite = "afterWrite";
1477
- var modifierPhases = [beforeRead, read, afterRead, beforeMain, main, afterMain, beforeWrite, write, afterWrite];
1478
- function getNodeName(element) {
1479
- return element ? (element.nodeName || "").toLowerCase() : null;
1480
- }
1481
- function getWindow(node) {
1482
- if (node == null) {
1483
- return window;
1484
- }
1485
- if (node.toString() !== "[object Window]") {
1486
- var ownerDocument = node.ownerDocument;
1487
- return ownerDocument ? ownerDocument.defaultView || window : window;
1488
- }
1489
- return node;
1490
- }
1491
- function isElement(node) {
1492
- var OwnElement = getWindow(node).Element;
1493
- return node instanceof OwnElement || node instanceof Element;
1494
- }
1495
- function isHTMLElement(node) {
1496
- var OwnElement = getWindow(node).HTMLElement;
1497
- return node instanceof OwnElement || node instanceof HTMLElement;
1498
- }
1499
- function isShadowRoot(node) {
1500
- if (typeof ShadowRoot === "undefined") {
1501
- return false;
1502
- }
1503
- var OwnElement = getWindow(node).ShadowRoot;
1504
- return node instanceof OwnElement || node instanceof ShadowRoot;
1505
- }
1506
- function applyStyles(_ref) {
1507
- var state = _ref.state;
1508
- Object.keys(state.elements).forEach(function(name) {
1509
- var style = state.styles[name] || {};
1510
- var attributes = state.attributes[name] || {};
1511
- var element = state.elements[name];
1512
- if (!isHTMLElement(element) || !getNodeName(element)) {
1513
- return;
1507
+ async function deregister(obj) {
1508
+ const index2 = this.collection.findIndex((entry) => {
1509
+ return entry.id === obj.id;
1510
+ });
1511
+ if (index2 >= 0) {
1512
+ const entry = this.collection[index2];
1513
+ if (entry.state === "opened") {
1514
+ entry.close();
1514
1515
  }
1515
- Object.assign(element.style, style);
1516
- Object.keys(attributes).forEach(function(name2) {
1517
- var value = attributes[name2];
1518
- if (value === false) {
1519
- element.removeAttribute(name2);
1520
- } else {
1521
- element.setAttribute(name2, value === true ? "" : value);
1522
- }
1516
+ entry.cleanup();
1517
+ deregisterEventListeners(entry);
1518
+ if (entry.getSetting("teleport")) {
1519
+ entry.teleportReturn();
1520
+ }
1521
+ Object.getOwnPropertyNames(entry).forEach((prop) => {
1522
+ delete entry[prop];
1523
1523
  });
1524
- });
1524
+ this.collection.splice(index2, 1);
1525
+ }
1526
+ return this.collection;
1525
1527
  }
1526
- function effect$2(_ref2) {
1527
- var state = _ref2.state;
1528
- var initialStyles = {
1529
- popper: {
1530
- position: state.options.strategy,
1531
- left: "0",
1532
- top: "0",
1533
- margin: "0"
1534
- },
1535
- arrow: {
1536
- position: "absolute"
1537
- },
1538
- reference: {}
1539
- };
1540
- Object.assign(state.elements.popper.style, initialStyles.popper);
1541
- state.styles = initialStyles;
1542
- if (state.elements.arrow) {
1543
- Object.assign(state.elements.arrow.style, initialStyles.arrow);
1544
- }
1545
- return function() {
1546
- Object.keys(state.elements).forEach(function(name) {
1547
- var element = state.elements[name];
1548
- var attributes = state.attributes[name] || {};
1549
- var styleProperties = Object.keys(state.styles.hasOwnProperty(name) ? state.styles[name] : initialStyles[name]);
1550
- var style = styleProperties.reduce(function(style2, property) {
1551
- style2[property] = "";
1552
- return style2;
1553
- }, {});
1554
- if (!isHTMLElement(element) || !getNodeName(element)) {
1555
- return;
1556
- }
1557
- Object.assign(element.style, style);
1558
- Object.keys(attributes).forEach(function(attribute) {
1559
- element.removeAttribute(attribute);
1528
+ function deregisterEventListeners(entry) {
1529
+ if (entry._eventListeners) {
1530
+ entry._eventListeners.forEach((evObj) => {
1531
+ evObj.el.forEach((el) => {
1532
+ evObj.type.forEach((type) => {
1533
+ entry[el].removeEventListener(type, evObj.listener, false);
1534
+ });
1560
1535
  });
1561
1536
  });
1562
- };
1537
+ delete entry._eventListeners;
1538
+ }
1539
+ return entry;
1563
1540
  }
1564
- const applyStyles$1 = {
1565
- name: "applyStyles",
1566
- enabled: true,
1567
- phase: "write",
1568
- fn: applyStyles,
1569
- effect: effect$2,
1570
- requires: ["computeStyles"]
1541
+ const min = Math.min;
1542
+ const max = Math.max;
1543
+ const round = Math.round;
1544
+ const floor = Math.floor;
1545
+ const createCoords = (v) => ({
1546
+ x: v,
1547
+ y: v
1548
+ });
1549
+ const oppositeSideMap = {
1550
+ left: "right",
1551
+ right: "left",
1552
+ bottom: "top",
1553
+ top: "bottom"
1554
+ };
1555
+ const oppositeAlignmentMap = {
1556
+ start: "end",
1557
+ end: "start"
1571
1558
  };
1572
- function getBasePlacement(placement) {
1559
+ function clamp(start, value, end) {
1560
+ return max(start, min(value, end));
1561
+ }
1562
+ function evaluate(value, param) {
1563
+ return typeof value === "function" ? value(param) : value;
1564
+ }
1565
+ function getSide(placement) {
1573
1566
  return placement.split("-")[0];
1574
1567
  }
1575
- var max = Math.max;
1576
- var min = Math.min;
1577
- var round = Math.round;
1578
- function getUAString() {
1579
- var uaData = navigator.userAgentData;
1580
- if (uaData != null && uaData.brands && Array.isArray(uaData.brands)) {
1581
- return uaData.brands.map(function(item) {
1582
- return item.brand + "/" + item.version;
1583
- }).join(" ");
1584
- }
1585
- return navigator.userAgent;
1568
+ function getAlignment(placement) {
1569
+ return placement.split("-")[1];
1586
1570
  }
1587
- function isLayoutViewport() {
1588
- return !/^((?!chrome|android).)*safari/i.test(getUAString());
1571
+ function getOppositeAxis(axis) {
1572
+ return axis === "x" ? "y" : "x";
1589
1573
  }
1590
- function getBoundingClientRect(element, includeScale, isFixedStrategy) {
1591
- if (includeScale === void 0) {
1592
- includeScale = false;
1574
+ function getAxisLength(axis) {
1575
+ return axis === "y" ? "height" : "width";
1576
+ }
1577
+ function getSideAxis(placement) {
1578
+ return ["top", "bottom"].includes(getSide(placement)) ? "y" : "x";
1579
+ }
1580
+ function getAlignmentAxis(placement) {
1581
+ return getOppositeAxis(getSideAxis(placement));
1582
+ }
1583
+ function getAlignmentSides(placement, rects, rtl) {
1584
+ if (rtl === void 0) {
1585
+ rtl = false;
1586
+ }
1587
+ const alignment = getAlignment(placement);
1588
+ const alignmentAxis = getAlignmentAxis(placement);
1589
+ const length = getAxisLength(alignmentAxis);
1590
+ let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
1591
+ if (rects.reference[length] > rects.floating[length]) {
1592
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
1593
+ }
1594
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
1595
+ }
1596
+ function getExpandedPlacements(placement) {
1597
+ const oppositePlacement = getOppositePlacement(placement);
1598
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
1599
+ }
1600
+ function getOppositeAlignmentPlacement(placement) {
1601
+ return placement.replace(/start|end/g, (alignment) => oppositeAlignmentMap[alignment]);
1602
+ }
1603
+ function getSideList(side, isStart, rtl) {
1604
+ const lr = ["left", "right"];
1605
+ const rl = ["right", "left"];
1606
+ const tb = ["top", "bottom"];
1607
+ const bt = ["bottom", "top"];
1608
+ switch (side) {
1609
+ case "top":
1610
+ case "bottom":
1611
+ if (rtl) return isStart ? rl : lr;
1612
+ return isStart ? lr : rl;
1613
+ case "left":
1614
+ case "right":
1615
+ return isStart ? tb : bt;
1616
+ default:
1617
+ return [];
1593
1618
  }
1594
- if (isFixedStrategy === void 0) {
1595
- isFixedStrategy = false;
1619
+ }
1620
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
1621
+ const alignment = getAlignment(placement);
1622
+ let list = getSideList(getSide(placement), direction === "start", rtl);
1623
+ if (alignment) {
1624
+ list = list.map((side) => side + "-" + alignment);
1625
+ if (flipAlignment) {
1626
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
1627
+ }
1596
1628
  }
1597
- var clientRect = element.getBoundingClientRect();
1598
- var scaleX = 1;
1599
- var scaleY = 1;
1600
- if (includeScale && isHTMLElement(element)) {
1601
- scaleX = element.offsetWidth > 0 ? round(clientRect.width) / element.offsetWidth || 1 : 1;
1602
- scaleY = element.offsetHeight > 0 ? round(clientRect.height) / element.offsetHeight || 1 : 1;
1603
- }
1604
- var _ref = isElement(element) ? getWindow(element) : window, visualViewport = _ref.visualViewport;
1605
- var addVisualOffsets = !isLayoutViewport() && isFixedStrategy;
1606
- var x = (clientRect.left + (addVisualOffsets && visualViewport ? visualViewport.offsetLeft : 0)) / scaleX;
1607
- var y = (clientRect.top + (addVisualOffsets && visualViewport ? visualViewport.offsetTop : 0)) / scaleY;
1608
- var width = clientRect.width / scaleX;
1609
- var height = clientRect.height / scaleY;
1629
+ return list;
1630
+ }
1631
+ function getOppositePlacement(placement) {
1632
+ return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
1633
+ }
1634
+ function expandPaddingObject(padding) {
1635
+ return {
1636
+ top: 0,
1637
+ right: 0,
1638
+ bottom: 0,
1639
+ left: 0,
1640
+ ...padding
1641
+ };
1642
+ }
1643
+ function getPaddingObject(padding) {
1644
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
1645
+ top: padding,
1646
+ right: padding,
1647
+ bottom: padding,
1648
+ left: padding
1649
+ };
1650
+ }
1651
+ function rectToClientRect(rect) {
1652
+ const {
1653
+ x,
1654
+ y,
1655
+ width,
1656
+ height
1657
+ } = rect;
1610
1658
  return {
1611
1659
  width,
1612
1660
  height,
1613
1661
  top: y,
1662
+ left: x,
1614
1663
  right: x + width,
1615
1664
  bottom: y + height,
1616
- left: x,
1617
1665
  x,
1618
1666
  y
1619
1667
  };
1620
1668
  }
1621
- function getLayoutRect(element) {
1622
- var clientRect = getBoundingClientRect(element);
1623
- var width = element.offsetWidth;
1624
- var height = element.offsetHeight;
1625
- if (Math.abs(clientRect.width - width) <= 1) {
1626
- width = clientRect.width;
1669
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
1670
+ let {
1671
+ reference,
1672
+ floating
1673
+ } = _ref;
1674
+ const sideAxis = getSideAxis(placement);
1675
+ const alignmentAxis = getAlignmentAxis(placement);
1676
+ const alignLength = getAxisLength(alignmentAxis);
1677
+ const side = getSide(placement);
1678
+ const isVertical = sideAxis === "y";
1679
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
1680
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
1681
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
1682
+ let coords;
1683
+ switch (side) {
1684
+ case "top":
1685
+ coords = {
1686
+ x: commonX,
1687
+ y: reference.y - floating.height
1688
+ };
1689
+ break;
1690
+ case "bottom":
1691
+ coords = {
1692
+ x: commonX,
1693
+ y: reference.y + reference.height
1694
+ };
1695
+ break;
1696
+ case "right":
1697
+ coords = {
1698
+ x: reference.x + reference.width,
1699
+ y: commonY
1700
+ };
1701
+ break;
1702
+ case "left":
1703
+ coords = {
1704
+ x: reference.x - floating.width,
1705
+ y: commonY
1706
+ };
1707
+ break;
1708
+ default:
1709
+ coords = {
1710
+ x: reference.x,
1711
+ y: reference.y
1712
+ };
1627
1713
  }
1628
- if (Math.abs(clientRect.height - height) <= 1) {
1629
- height = clientRect.height;
1714
+ switch (getAlignment(placement)) {
1715
+ case "start":
1716
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
1717
+ break;
1718
+ case "end":
1719
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
1720
+ break;
1630
1721
  }
1631
- return {
1632
- x: element.offsetLeft,
1633
- y: element.offsetTop,
1634
- width,
1635
- height
1722
+ return coords;
1723
+ }
1724
+ const computePosition$1 = async (reference, floating, config) => {
1725
+ const {
1726
+ placement = "bottom",
1727
+ strategy = "absolute",
1728
+ middleware = [],
1729
+ platform: platform2
1730
+ } = config;
1731
+ const validMiddleware = middleware.filter(Boolean);
1732
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
1733
+ let rects = await platform2.getElementRects({
1734
+ reference,
1735
+ floating,
1736
+ strategy
1737
+ });
1738
+ let {
1739
+ x,
1740
+ y
1741
+ } = computeCoordsFromPlacement(rects, placement, rtl);
1742
+ let statefulPlacement = placement;
1743
+ let middlewareData = {};
1744
+ let resetCount = 0;
1745
+ for (let i = 0; i < validMiddleware.length; i++) {
1746
+ const {
1747
+ name,
1748
+ fn
1749
+ } = validMiddleware[i];
1750
+ const {
1751
+ x: nextX,
1752
+ y: nextY,
1753
+ data,
1754
+ reset
1755
+ } = await fn({
1756
+ x,
1757
+ y,
1758
+ initialPlacement: placement,
1759
+ placement: statefulPlacement,
1760
+ strategy,
1761
+ middlewareData,
1762
+ rects,
1763
+ platform: platform2,
1764
+ elements: {
1765
+ reference,
1766
+ floating
1767
+ }
1768
+ });
1769
+ x = nextX != null ? nextX : x;
1770
+ y = nextY != null ? nextY : y;
1771
+ middlewareData = {
1772
+ ...middlewareData,
1773
+ [name]: {
1774
+ ...middlewareData[name],
1775
+ ...data
1776
+ }
1777
+ };
1778
+ if (reset && resetCount <= 50) {
1779
+ resetCount++;
1780
+ if (typeof reset === "object") {
1781
+ if (reset.placement) {
1782
+ statefulPlacement = reset.placement;
1783
+ }
1784
+ if (reset.rects) {
1785
+ rects = reset.rects === true ? await platform2.getElementRects({
1786
+ reference,
1787
+ floating,
1788
+ strategy
1789
+ }) : reset.rects;
1790
+ }
1791
+ ({
1792
+ x,
1793
+ y
1794
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
1795
+ }
1796
+ i = -1;
1797
+ }
1798
+ }
1799
+ return {
1800
+ x,
1801
+ y,
1802
+ placement: statefulPlacement,
1803
+ strategy,
1804
+ middlewareData
1805
+ };
1806
+ };
1807
+ async function detectOverflow(state, options) {
1808
+ var _await$platform$isEle;
1809
+ if (options === void 0) {
1810
+ options = {};
1811
+ }
1812
+ const {
1813
+ x,
1814
+ y,
1815
+ platform: platform2,
1816
+ rects,
1817
+ elements,
1818
+ strategy
1819
+ } = state;
1820
+ const {
1821
+ boundary = "clippingAncestors",
1822
+ rootBoundary = "viewport",
1823
+ elementContext = "floating",
1824
+ altBoundary = false,
1825
+ padding = 0
1826
+ } = evaluate(options, state);
1827
+ const paddingObject = getPaddingObject(padding);
1828
+ const altContext = elementContext === "floating" ? "reference" : "floating";
1829
+ const element = elements[altBoundary ? altContext : elementContext];
1830
+ const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
1831
+ element: ((_await$platform$isEle = await (platform2.isElement == null ? void 0 : platform2.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform2.getDocumentElement == null ? void 0 : platform2.getDocumentElement(elements.floating)),
1832
+ boundary,
1833
+ rootBoundary,
1834
+ strategy
1835
+ }));
1836
+ const rect = elementContext === "floating" ? {
1837
+ x,
1838
+ y,
1839
+ width: rects.floating.width,
1840
+ height: rects.floating.height
1841
+ } : rects.reference;
1842
+ const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
1843
+ const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
1844
+ x: 1,
1845
+ y: 1
1846
+ } : {
1847
+ x: 1,
1848
+ y: 1
1849
+ };
1850
+ const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
1851
+ elements,
1852
+ rect,
1853
+ offsetParent,
1854
+ strategy
1855
+ }) : rect);
1856
+ return {
1857
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
1858
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
1859
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
1860
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
1636
1861
  };
1637
1862
  }
1638
- function contains(parent, child) {
1639
- var rootNode = child.getRootNode && child.getRootNode();
1640
- if (parent.contains(child)) {
1641
- return true;
1642
- } else if (rootNode && isShadowRoot(rootNode)) {
1643
- var next = child;
1644
- do {
1645
- if (next && parent.isSameNode(next)) {
1646
- return true;
1863
+ const arrow$1 = (options) => ({
1864
+ name: "arrow",
1865
+ options,
1866
+ async fn(state) {
1867
+ const {
1868
+ x,
1869
+ y,
1870
+ placement,
1871
+ rects,
1872
+ platform: platform2,
1873
+ elements,
1874
+ middlewareData
1875
+ } = state;
1876
+ const {
1877
+ element,
1878
+ padding = 0
1879
+ } = evaluate(options, state) || {};
1880
+ if (element == null) {
1881
+ return {};
1882
+ }
1883
+ const paddingObject = getPaddingObject(padding);
1884
+ const coords = {
1885
+ x,
1886
+ y
1887
+ };
1888
+ const axis = getAlignmentAxis(placement);
1889
+ const length = getAxisLength(axis);
1890
+ const arrowDimensions = await platform2.getDimensions(element);
1891
+ const isYAxis = axis === "y";
1892
+ const minProp = isYAxis ? "top" : "left";
1893
+ const maxProp = isYAxis ? "bottom" : "right";
1894
+ const clientProp = isYAxis ? "clientHeight" : "clientWidth";
1895
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
1896
+ const startDiff = coords[axis] - rects.reference[axis];
1897
+ const arrowOffsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(element));
1898
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
1899
+ if (!clientSize || !await (platform2.isElement == null ? void 0 : platform2.isElement(arrowOffsetParent))) {
1900
+ clientSize = elements.floating[clientProp] || rects.floating[length];
1901
+ }
1902
+ const centerToReference = endDiff / 2 - startDiff / 2;
1903
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
1904
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
1905
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
1906
+ const min$1 = minPadding;
1907
+ const max2 = clientSize - arrowDimensions[length] - maxPadding;
1908
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
1909
+ const offset2 = clamp(min$1, center, max2);
1910
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset2 && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
1911
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max2 : 0;
1912
+ return {
1913
+ [axis]: coords[axis] + alignmentOffset,
1914
+ data: {
1915
+ [axis]: offset2,
1916
+ centerOffset: center - offset2 - alignmentOffset,
1917
+ ...shouldAddOffset && {
1918
+ alignmentOffset
1919
+ }
1920
+ },
1921
+ reset: shouldAddOffset
1922
+ };
1923
+ }
1924
+ });
1925
+ const flip$1 = function(options) {
1926
+ if (options === void 0) {
1927
+ options = {};
1928
+ }
1929
+ return {
1930
+ name: "flip",
1931
+ options,
1932
+ async fn(state) {
1933
+ var _middlewareData$arrow, _middlewareData$flip;
1934
+ const {
1935
+ placement,
1936
+ middlewareData,
1937
+ rects,
1938
+ initialPlacement,
1939
+ platform: platform2,
1940
+ elements
1941
+ } = state;
1942
+ const {
1943
+ mainAxis: checkMainAxis = true,
1944
+ crossAxis: checkCrossAxis = true,
1945
+ fallbackPlacements: specifiedFallbackPlacements,
1946
+ fallbackStrategy = "bestFit",
1947
+ fallbackAxisSideDirection = "none",
1948
+ flipAlignment = true,
1949
+ ...detectOverflowOptions
1950
+ } = evaluate(options, state);
1951
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
1952
+ return {};
1953
+ }
1954
+ const side = getSide(placement);
1955
+ const initialSideAxis = getSideAxis(initialPlacement);
1956
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
1957
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
1958
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
1959
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
1960
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
1961
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
1962
+ }
1963
+ const placements = [initialPlacement, ...fallbackPlacements];
1964
+ const overflow = await detectOverflow(state, detectOverflowOptions);
1965
+ const overflows = [];
1966
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
1967
+ if (checkMainAxis) {
1968
+ overflows.push(overflow[side]);
1969
+ }
1970
+ if (checkCrossAxis) {
1971
+ const sides = getAlignmentSides(placement, rects, rtl);
1972
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
1647
1973
  }
1648
- next = next.parentNode || next.host;
1649
- } while (next);
1974
+ overflowsData = [...overflowsData, {
1975
+ placement,
1976
+ overflows
1977
+ }];
1978
+ if (!overflows.every((side2) => side2 <= 0)) {
1979
+ var _middlewareData$flip2, _overflowsData$filter;
1980
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
1981
+ const nextPlacement = placements[nextIndex];
1982
+ if (nextPlacement) {
1983
+ return {
1984
+ data: {
1985
+ index: nextIndex,
1986
+ overflows: overflowsData
1987
+ },
1988
+ reset: {
1989
+ placement: nextPlacement
1990
+ }
1991
+ };
1992
+ }
1993
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter((d) => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
1994
+ if (!resetPlacement) {
1995
+ switch (fallbackStrategy) {
1996
+ case "bestFit": {
1997
+ var _overflowsData$filter2;
1998
+ const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
1999
+ if (hasFallbackAxisSideDirection) {
2000
+ const currentSideAxis = getSideAxis(d.placement);
2001
+ return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
2002
+ // reading directions favoring greater width.
2003
+ currentSideAxis === "y";
2004
+ }
2005
+ return true;
2006
+ }).map((d) => [d.placement, d.overflows.filter((overflow2) => overflow2 > 0).reduce((acc, overflow2) => acc + overflow2, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
2007
+ if (placement2) {
2008
+ resetPlacement = placement2;
2009
+ }
2010
+ break;
2011
+ }
2012
+ case "initialPlacement":
2013
+ resetPlacement = initialPlacement;
2014
+ break;
2015
+ }
2016
+ }
2017
+ if (placement !== resetPlacement) {
2018
+ return {
2019
+ reset: {
2020
+ placement: resetPlacement
2021
+ }
2022
+ };
2023
+ }
2024
+ }
2025
+ return {};
2026
+ }
2027
+ };
2028
+ };
2029
+ async function convertValueToCoords(state, options) {
2030
+ const {
2031
+ placement,
2032
+ platform: platform2,
2033
+ elements
2034
+ } = state;
2035
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
2036
+ const side = getSide(placement);
2037
+ const alignment = getAlignment(placement);
2038
+ const isVertical = getSideAxis(placement) === "y";
2039
+ const mainAxisMulti = ["left", "top"].includes(side) ? -1 : 1;
2040
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
2041
+ const rawValue = evaluate(options, state);
2042
+ let {
2043
+ mainAxis,
2044
+ crossAxis,
2045
+ alignmentAxis
2046
+ } = typeof rawValue === "number" ? {
2047
+ mainAxis: rawValue,
2048
+ crossAxis: 0,
2049
+ alignmentAxis: null
2050
+ } : {
2051
+ mainAxis: rawValue.mainAxis || 0,
2052
+ crossAxis: rawValue.crossAxis || 0,
2053
+ alignmentAxis: rawValue.alignmentAxis
2054
+ };
2055
+ if (alignment && typeof alignmentAxis === "number") {
2056
+ crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
1650
2057
  }
1651
- return false;
2058
+ return isVertical ? {
2059
+ x: crossAxis * crossAxisMulti,
2060
+ y: mainAxis * mainAxisMulti
2061
+ } : {
2062
+ x: mainAxis * mainAxisMulti,
2063
+ y: crossAxis * crossAxisMulti
2064
+ };
1652
2065
  }
1653
- function getComputedStyle$1(element) {
1654
- return getWindow(element).getComputedStyle(element);
2066
+ const offset$1 = function(options) {
2067
+ if (options === void 0) {
2068
+ options = 0;
2069
+ }
2070
+ return {
2071
+ name: "offset",
2072
+ options,
2073
+ async fn(state) {
2074
+ var _middlewareData$offse, _middlewareData$arrow;
2075
+ const {
2076
+ x,
2077
+ y,
2078
+ placement,
2079
+ middlewareData
2080
+ } = state;
2081
+ const diffCoords = await convertValueToCoords(state, options);
2082
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
2083
+ return {};
2084
+ }
2085
+ return {
2086
+ x: x + diffCoords.x,
2087
+ y: y + diffCoords.y,
2088
+ data: {
2089
+ ...diffCoords,
2090
+ placement
2091
+ }
2092
+ };
2093
+ }
2094
+ };
2095
+ };
2096
+ const shift$1 = function(options) {
2097
+ if (options === void 0) {
2098
+ options = {};
2099
+ }
2100
+ return {
2101
+ name: "shift",
2102
+ options,
2103
+ async fn(state) {
2104
+ const {
2105
+ x,
2106
+ y,
2107
+ placement
2108
+ } = state;
2109
+ const {
2110
+ mainAxis: checkMainAxis = true,
2111
+ crossAxis: checkCrossAxis = false,
2112
+ limiter = {
2113
+ fn: (_ref) => {
2114
+ let {
2115
+ x: x2,
2116
+ y: y2
2117
+ } = _ref;
2118
+ return {
2119
+ x: x2,
2120
+ y: y2
2121
+ };
2122
+ }
2123
+ },
2124
+ ...detectOverflowOptions
2125
+ } = evaluate(options, state);
2126
+ const coords = {
2127
+ x,
2128
+ y
2129
+ };
2130
+ const overflow = await detectOverflow(state, detectOverflowOptions);
2131
+ const crossAxis = getSideAxis(getSide(placement));
2132
+ const mainAxis = getOppositeAxis(crossAxis);
2133
+ let mainAxisCoord = coords[mainAxis];
2134
+ let crossAxisCoord = coords[crossAxis];
2135
+ if (checkMainAxis) {
2136
+ const minSide = mainAxis === "y" ? "top" : "left";
2137
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
2138
+ const min2 = mainAxisCoord + overflow[minSide];
2139
+ const max2 = mainAxisCoord - overflow[maxSide];
2140
+ mainAxisCoord = clamp(min2, mainAxisCoord, max2);
2141
+ }
2142
+ if (checkCrossAxis) {
2143
+ const minSide = crossAxis === "y" ? "top" : "left";
2144
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
2145
+ const min2 = crossAxisCoord + overflow[minSide];
2146
+ const max2 = crossAxisCoord - overflow[maxSide];
2147
+ crossAxisCoord = clamp(min2, crossAxisCoord, max2);
2148
+ }
2149
+ const limitedCoords = limiter.fn({
2150
+ ...state,
2151
+ [mainAxis]: mainAxisCoord,
2152
+ [crossAxis]: crossAxisCoord
2153
+ });
2154
+ return {
2155
+ ...limitedCoords,
2156
+ data: {
2157
+ x: limitedCoords.x - x,
2158
+ y: limitedCoords.y - y,
2159
+ enabled: {
2160
+ [mainAxis]: checkMainAxis,
2161
+ [crossAxis]: checkCrossAxis
2162
+ }
2163
+ }
2164
+ };
2165
+ }
2166
+ };
2167
+ };
2168
+ const limitShift$1 = function(options) {
2169
+ if (options === void 0) {
2170
+ options = {};
2171
+ }
2172
+ return {
2173
+ options,
2174
+ fn(state) {
2175
+ const {
2176
+ x,
2177
+ y,
2178
+ placement,
2179
+ rects,
2180
+ middlewareData
2181
+ } = state;
2182
+ const {
2183
+ offset: offset2 = 0,
2184
+ mainAxis: checkMainAxis = true,
2185
+ crossAxis: checkCrossAxis = true
2186
+ } = evaluate(options, state);
2187
+ const coords = {
2188
+ x,
2189
+ y
2190
+ };
2191
+ const crossAxis = getSideAxis(placement);
2192
+ const mainAxis = getOppositeAxis(crossAxis);
2193
+ let mainAxisCoord = coords[mainAxis];
2194
+ let crossAxisCoord = coords[crossAxis];
2195
+ const rawOffset = evaluate(offset2, state);
2196
+ const computedOffset = typeof rawOffset === "number" ? {
2197
+ mainAxis: rawOffset,
2198
+ crossAxis: 0
2199
+ } : {
2200
+ mainAxis: 0,
2201
+ crossAxis: 0,
2202
+ ...rawOffset
2203
+ };
2204
+ if (checkMainAxis) {
2205
+ const len = mainAxis === "y" ? "height" : "width";
2206
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
2207
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
2208
+ if (mainAxisCoord < limitMin) {
2209
+ mainAxisCoord = limitMin;
2210
+ } else if (mainAxisCoord > limitMax) {
2211
+ mainAxisCoord = limitMax;
2212
+ }
2213
+ }
2214
+ if (checkCrossAxis) {
2215
+ var _middlewareData$offse, _middlewareData$offse2;
2216
+ const len = mainAxis === "y" ? "width" : "height";
2217
+ const isOriginSide = ["top", "left"].includes(getSide(placement));
2218
+ const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
2219
+ const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
2220
+ if (crossAxisCoord < limitMin) {
2221
+ crossAxisCoord = limitMin;
2222
+ } else if (crossAxisCoord > limitMax) {
2223
+ crossAxisCoord = limitMax;
2224
+ }
2225
+ }
2226
+ return {
2227
+ [mainAxis]: mainAxisCoord,
2228
+ [crossAxis]: crossAxisCoord
2229
+ };
2230
+ }
2231
+ };
2232
+ };
2233
+ function hasWindow() {
2234
+ return typeof window !== "undefined";
1655
2235
  }
1656
- function isTableElement(element) {
1657
- return ["table", "td", "th"].indexOf(getNodeName(element)) >= 0;
1658
- }
1659
- function getDocumentElement(element) {
1660
- return ((isElement(element) ? element.ownerDocument : (
1661
- // $FlowFixMe[prop-missing]
1662
- element.document
1663
- )) || window.document).documentElement;
1664
- }
1665
- function getParentNode(element) {
1666
- if (getNodeName(element) === "html") {
1667
- return element;
1668
- }
1669
- return (
1670
- // this is a quicker (but less type safe) way to save quite some bytes from the bundle
1671
- // $FlowFixMe[incompatible-return]
1672
- // $FlowFixMe[prop-missing]
1673
- element.assignedSlot || // step into the shadow DOM of the parent of a slotted node
1674
- element.parentNode || // DOM Element detected
1675
- (isShadowRoot(element) ? element.host : null) || // ShadowRoot detected
1676
- // $FlowFixMe[incompatible-call]: HTMLElement is a Node
1677
- getDocumentElement(element)
1678
- );
2236
+ function getNodeName(node) {
2237
+ if (isNode(node)) {
2238
+ return (node.nodeName || "").toLowerCase();
2239
+ }
2240
+ return "#document";
1679
2241
  }
1680
- function getTrueOffsetParent(element) {
1681
- if (!isHTMLElement(element) || // https://github.com/popperjs/popper-core/issues/837
1682
- getComputedStyle$1(element).position === "fixed") {
1683
- return null;
2242
+ function getWindow(node) {
2243
+ var _node$ownerDocument;
2244
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
2245
+ }
2246
+ function getDocumentElement(node) {
2247
+ var _ref;
2248
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
2249
+ }
2250
+ function isNode(value) {
2251
+ if (!hasWindow()) {
2252
+ return false;
1684
2253
  }
1685
- return element.offsetParent;
2254
+ return value instanceof Node || value instanceof getWindow(value).Node;
1686
2255
  }
1687
- function getContainingBlock(element) {
1688
- var isFirefox = /firefox/i.test(getUAString());
1689
- var isIE = /Trident/i.test(getUAString());
1690
- if (isIE && isHTMLElement(element)) {
1691
- var elementCss = getComputedStyle$1(element);
1692
- if (elementCss.position === "fixed") {
1693
- return null;
1694
- }
2256
+ function isElement(value) {
2257
+ if (!hasWindow()) {
2258
+ return false;
1695
2259
  }
1696
- var currentNode = getParentNode(element);
1697
- if (isShadowRoot(currentNode)) {
1698
- currentNode = currentNode.host;
2260
+ return value instanceof Element || value instanceof getWindow(value).Element;
2261
+ }
2262
+ function isHTMLElement(value) {
2263
+ if (!hasWindow()) {
2264
+ return false;
2265
+ }
2266
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
2267
+ }
2268
+ function isShadowRoot(value) {
2269
+ if (!hasWindow() || typeof ShadowRoot === "undefined") {
2270
+ return false;
1699
2271
  }
1700
- while (isHTMLElement(currentNode) && ["html", "body"].indexOf(getNodeName(currentNode)) < 0) {
1701
- var css = getComputedStyle$1(currentNode);
1702
- if (css.transform !== "none" || css.perspective !== "none" || css.contain === "paint" || ["transform", "perspective"].indexOf(css.willChange) !== -1 || isFirefox && css.willChange === "filter" || isFirefox && css.filter && css.filter !== "none") {
2272
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
2273
+ }
2274
+ function isOverflowElement(element) {
2275
+ const {
2276
+ overflow,
2277
+ overflowX,
2278
+ overflowY,
2279
+ display
2280
+ } = getComputedStyle$1(element);
2281
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !["inline", "contents"].includes(display);
2282
+ }
2283
+ function isTableElement(element) {
2284
+ return ["table", "td", "th"].includes(getNodeName(element));
2285
+ }
2286
+ function isTopLayer(element) {
2287
+ return [":popover-open", ":modal"].some((selector) => {
2288
+ try {
2289
+ return element.matches(selector);
2290
+ } catch (e) {
2291
+ return false;
2292
+ }
2293
+ });
2294
+ }
2295
+ function isContainingBlock(elementOrCss) {
2296
+ const webkit = isWebKit();
2297
+ const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
2298
+ return css.transform !== "none" || css.perspective !== "none" || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || ["transform", "perspective", "filter"].some((value) => (css.willChange || "").includes(value)) || ["paint", "layout", "strict", "content"].some((value) => (css.contain || "").includes(value));
2299
+ }
2300
+ function getContainingBlock(element) {
2301
+ let currentNode = getParentNode(element);
2302
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
2303
+ if (isContainingBlock(currentNode)) {
1703
2304
  return currentNode;
1704
- } else {
1705
- currentNode = currentNode.parentNode;
2305
+ } else if (isTopLayer(currentNode)) {
2306
+ return null;
1706
2307
  }
2308
+ currentNode = getParentNode(currentNode);
1707
2309
  }
1708
2310
  return null;
1709
2311
  }
1710
- function getOffsetParent(element) {
1711
- var window2 = getWindow(element);
1712
- var offsetParent = getTrueOffsetParent(element);
1713
- while (offsetParent && isTableElement(offsetParent) && getComputedStyle$1(offsetParent).position === "static") {
1714
- offsetParent = getTrueOffsetParent(offsetParent);
1715
- }
1716
- if (offsetParent && (getNodeName(offsetParent) === "html" || getNodeName(offsetParent) === "body" && getComputedStyle$1(offsetParent).position === "static")) {
1717
- return window2;
1718
- }
1719
- return offsetParent || getContainingBlock(element) || window2;
1720
- }
1721
- function getMainAxisFromPlacement(placement) {
1722
- return ["top", "bottom"].indexOf(placement) >= 0 ? "x" : "y";
2312
+ function isWebKit() {
2313
+ if (typeof CSS === "undefined" || !CSS.supports) return false;
2314
+ return CSS.supports("-webkit-backdrop-filter", "none");
1723
2315
  }
1724
- function within(min$1, value, max$1) {
1725
- return max(min$1, min(value, max$1));
2316
+ function isLastTraversableNode(node) {
2317
+ return ["html", "body", "#document"].includes(getNodeName(node));
1726
2318
  }
1727
- function withinMaxClamp(min2, value, max2) {
1728
- var v = within(min2, value, max2);
1729
- return v > max2 ? max2 : v;
2319
+ function getComputedStyle$1(element) {
2320
+ return getWindow(element).getComputedStyle(element);
1730
2321
  }
1731
- function getFreshSideObject() {
2322
+ function getNodeScroll(element) {
2323
+ if (isElement(element)) {
2324
+ return {
2325
+ scrollLeft: element.scrollLeft,
2326
+ scrollTop: element.scrollTop
2327
+ };
2328
+ }
1732
2329
  return {
1733
- top: 0,
1734
- right: 0,
1735
- bottom: 0,
1736
- left: 0
2330
+ scrollLeft: element.scrollX,
2331
+ scrollTop: element.scrollY
1737
2332
  };
1738
2333
  }
1739
- function mergePaddingObject(paddingObject) {
1740
- return Object.assign({}, getFreshSideObject(), paddingObject);
1741
- }
1742
- function expandToHashMap(value, keys) {
1743
- return keys.reduce(function(hashMap, key) {
1744
- hashMap[key] = value;
1745
- return hashMap;
1746
- }, {});
2334
+ function getParentNode(node) {
2335
+ if (getNodeName(node) === "html") {
2336
+ return node;
2337
+ }
2338
+ const result = (
2339
+ // Step into the shadow DOM of the parent of a slotted node.
2340
+ node.assignedSlot || // DOM Element detected.
2341
+ node.parentNode || // ShadowRoot detected.
2342
+ isShadowRoot(node) && node.host || // Fallback.
2343
+ getDocumentElement(node)
2344
+ );
2345
+ return isShadowRoot(result) ? result.host : result;
1747
2346
  }
1748
- var toPaddingObject = function toPaddingObject2(padding, state) {
1749
- padding = typeof padding === "function" ? padding(Object.assign({}, state.rects, {
1750
- placement: state.placement
1751
- })) : padding;
1752
- return mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
1753
- };
1754
- function arrow(_ref) {
1755
- var _state$modifiersData$;
1756
- var state = _ref.state, name = _ref.name, options = _ref.options;
1757
- var arrowElement = state.elements.arrow;
1758
- var popperOffsets2 = state.modifiersData.popperOffsets;
1759
- var basePlacement = getBasePlacement(state.placement);
1760
- var axis = getMainAxisFromPlacement(basePlacement);
1761
- var isVertical = [left, right].indexOf(basePlacement) >= 0;
1762
- var len = isVertical ? "height" : "width";
1763
- if (!arrowElement || !popperOffsets2) {
1764
- return;
2347
+ function getNearestOverflowAncestor(node) {
2348
+ const parentNode = getParentNode(node);
2349
+ if (isLastTraversableNode(parentNode)) {
2350
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
1765
2351
  }
1766
- var paddingObject = toPaddingObject(options.padding, state);
1767
- var arrowRect = getLayoutRect(arrowElement);
1768
- var minProp = axis === "y" ? top : left;
1769
- var maxProp = axis === "y" ? bottom : right;
1770
- var endDiff = state.rects.reference[len] + state.rects.reference[axis] - popperOffsets2[axis] - state.rects.popper[len];
1771
- var startDiff = popperOffsets2[axis] - state.rects.reference[axis];
1772
- var arrowOffsetParent = getOffsetParent(arrowElement);
1773
- var clientSize = arrowOffsetParent ? axis === "y" ? arrowOffsetParent.clientHeight || 0 : arrowOffsetParent.clientWidth || 0 : 0;
1774
- var centerToReference = endDiff / 2 - startDiff / 2;
1775
- var min2 = paddingObject[minProp];
1776
- var max2 = clientSize - arrowRect[len] - paddingObject[maxProp];
1777
- var center = clientSize / 2 - arrowRect[len] / 2 + centerToReference;
1778
- var offset2 = within(min2, center, max2);
1779
- var axisProp = axis;
1780
- state.modifiersData[name] = (_state$modifiersData$ = {}, _state$modifiersData$[axisProp] = offset2, _state$modifiersData$.centerOffset = offset2 - center, _state$modifiersData$);
1781
- }
1782
- function effect$1(_ref2) {
1783
- var state = _ref2.state, options = _ref2.options;
1784
- var _options$element = options.element, arrowElement = _options$element === void 0 ? "[data-popper-arrow]" : _options$element;
1785
- if (arrowElement == null) {
1786
- return;
2352
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
2353
+ return parentNode;
1787
2354
  }
1788
- if (typeof arrowElement === "string") {
1789
- arrowElement = state.elements.popper.querySelector(arrowElement);
1790
- if (!arrowElement) {
1791
- return;
1792
- }
2355
+ return getNearestOverflowAncestor(parentNode);
2356
+ }
2357
+ function getOverflowAncestors(node, list, traverseIframes) {
2358
+ var _node$ownerDocument2;
2359
+ if (list === void 0) {
2360
+ list = [];
1793
2361
  }
1794
- if (!contains(state.elements.popper, arrowElement)) {
1795
- return;
2362
+ if (traverseIframes === void 0) {
2363
+ traverseIframes = true;
2364
+ }
2365
+ const scrollableAncestor = getNearestOverflowAncestor(node);
2366
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
2367
+ const win = getWindow(scrollableAncestor);
2368
+ if (isBody) {
2369
+ const frameElement = getFrameElement(win);
2370
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
2371
+ }
2372
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
2373
+ }
2374
+ function getFrameElement(win) {
2375
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
2376
+ }
2377
+ function getCssDimensions(element) {
2378
+ const css = getComputedStyle$1(element);
2379
+ let width = parseFloat(css.width) || 0;
2380
+ let height = parseFloat(css.height) || 0;
2381
+ const hasOffset = isHTMLElement(element);
2382
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
2383
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
2384
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
2385
+ if (shouldFallback) {
2386
+ width = offsetWidth;
2387
+ height = offsetHeight;
1796
2388
  }
1797
- state.elements.arrow = arrowElement;
1798
- }
1799
- const arrow$1 = {
1800
- name: "arrow",
1801
- enabled: true,
1802
- phase: "main",
1803
- fn: arrow,
1804
- effect: effect$1,
1805
- requires: ["popperOffsets"],
1806
- requiresIfExists: ["preventOverflow"]
1807
- };
1808
- function getVariation(placement) {
1809
- return placement.split("-")[1];
1810
- }
1811
- var unsetSides = {
1812
- top: "auto",
1813
- right: "auto",
1814
- bottom: "auto",
1815
- left: "auto"
1816
- };
1817
- function roundOffsetsByDPR(_ref, win) {
1818
- var x = _ref.x, y = _ref.y;
1819
- var dpr = win.devicePixelRatio || 1;
1820
2389
  return {
1821
- x: round(x * dpr) / dpr || 0,
1822
- y: round(y * dpr) / dpr || 0
2390
+ width,
2391
+ height,
2392
+ $: shouldFallback
1823
2393
  };
1824
2394
  }
1825
- function mapToStyles(_ref2) {
1826
- var _Object$assign2;
1827
- var popper2 = _ref2.popper, popperRect = _ref2.popperRect, placement = _ref2.placement, variation = _ref2.variation, offsets = _ref2.offsets, position = _ref2.position, gpuAcceleration = _ref2.gpuAcceleration, adaptive = _ref2.adaptive, roundOffsets = _ref2.roundOffsets, isFixed = _ref2.isFixed;
1828
- var _offsets$x = offsets.x, x = _offsets$x === void 0 ? 0 : _offsets$x, _offsets$y = offsets.y, y = _offsets$y === void 0 ? 0 : _offsets$y;
1829
- var _ref3 = typeof roundOffsets === "function" ? roundOffsets({
1830
- x,
1831
- y
1832
- }) : {
2395
+ function unwrapElement(element) {
2396
+ return !isElement(element) ? element.contextElement : element;
2397
+ }
2398
+ function getScale(element) {
2399
+ const domElement = unwrapElement(element);
2400
+ if (!isHTMLElement(domElement)) {
2401
+ return createCoords(1);
2402
+ }
2403
+ const rect = domElement.getBoundingClientRect();
2404
+ const {
2405
+ width,
2406
+ height,
2407
+ $
2408
+ } = getCssDimensions(domElement);
2409
+ let x = ($ ? round(rect.width) : rect.width) / width;
2410
+ let y = ($ ? round(rect.height) : rect.height) / height;
2411
+ if (!x || !Number.isFinite(x)) {
2412
+ x = 1;
2413
+ }
2414
+ if (!y || !Number.isFinite(y)) {
2415
+ y = 1;
2416
+ }
2417
+ return {
1833
2418
  x,
1834
2419
  y
1835
2420
  };
1836
- x = _ref3.x;
1837
- y = _ref3.y;
1838
- var hasX = offsets.hasOwnProperty("x");
1839
- var hasY = offsets.hasOwnProperty("y");
1840
- var sideX = left;
1841
- var sideY = top;
1842
- var win = window;
1843
- if (adaptive) {
1844
- var offsetParent = getOffsetParent(popper2);
1845
- var heightProp = "clientHeight";
1846
- var widthProp = "clientWidth";
1847
- if (offsetParent === getWindow(popper2)) {
1848
- offsetParent = getDocumentElement(popper2);
1849
- if (getComputedStyle$1(offsetParent).position !== "static" && position === "absolute") {
1850
- heightProp = "scrollHeight";
1851
- widthProp = "scrollWidth";
2421
+ }
2422
+ const noOffsets = /* @__PURE__ */ createCoords(0);
2423
+ function getVisualOffsets(element) {
2424
+ const win = getWindow(element);
2425
+ if (!isWebKit() || !win.visualViewport) {
2426
+ return noOffsets;
2427
+ }
2428
+ return {
2429
+ x: win.visualViewport.offsetLeft,
2430
+ y: win.visualViewport.offsetTop
2431
+ };
2432
+ }
2433
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
2434
+ if (isFixed === void 0) {
2435
+ isFixed = false;
2436
+ }
2437
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
2438
+ return false;
2439
+ }
2440
+ return isFixed;
2441
+ }
2442
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
2443
+ if (includeScale === void 0) {
2444
+ includeScale = false;
2445
+ }
2446
+ if (isFixedStrategy === void 0) {
2447
+ isFixedStrategy = false;
2448
+ }
2449
+ const clientRect = element.getBoundingClientRect();
2450
+ const domElement = unwrapElement(element);
2451
+ let scale = createCoords(1);
2452
+ if (includeScale) {
2453
+ if (offsetParent) {
2454
+ if (isElement(offsetParent)) {
2455
+ scale = getScale(offsetParent);
1852
2456
  }
1853
- }
1854
- offsetParent = offsetParent;
1855
- if (placement === top || (placement === left || placement === right) && variation === end) {
1856
- sideY = bottom;
1857
- var offsetY = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.height : (
1858
- // $FlowFixMe[prop-missing]
1859
- offsetParent[heightProp]
1860
- );
1861
- y -= offsetY - popperRect.height;
1862
- y *= gpuAcceleration ? 1 : -1;
1863
- }
1864
- if (placement === left || (placement === top || placement === bottom) && variation === end) {
1865
- sideX = right;
1866
- var offsetX = isFixed && offsetParent === win && win.visualViewport ? win.visualViewport.width : (
1867
- // $FlowFixMe[prop-missing]
1868
- offsetParent[widthProp]
1869
- );
1870
- x -= offsetX - popperRect.width;
1871
- x *= gpuAcceleration ? 1 : -1;
1872
- }
1873
- }
1874
- var commonStyles = Object.assign({
1875
- position
1876
- }, adaptive && unsetSides);
1877
- var _ref4 = roundOffsets === true ? roundOffsetsByDPR({
1878
- x,
1879
- y
1880
- }, getWindow(popper2)) : {
2457
+ } else {
2458
+ scale = getScale(element);
2459
+ }
2460
+ }
2461
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
2462
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
2463
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
2464
+ let width = clientRect.width / scale.x;
2465
+ let height = clientRect.height / scale.y;
2466
+ if (domElement) {
2467
+ const win = getWindow(domElement);
2468
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
2469
+ let currentWin = win;
2470
+ let currentIFrame = getFrameElement(currentWin);
2471
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
2472
+ const iframeScale = getScale(currentIFrame);
2473
+ const iframeRect = currentIFrame.getBoundingClientRect();
2474
+ const css = getComputedStyle$1(currentIFrame);
2475
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
2476
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
2477
+ x *= iframeScale.x;
2478
+ y *= iframeScale.y;
2479
+ width *= iframeScale.x;
2480
+ height *= iframeScale.y;
2481
+ x += left;
2482
+ y += top;
2483
+ currentWin = getWindow(currentIFrame);
2484
+ currentIFrame = getFrameElement(currentWin);
2485
+ }
2486
+ }
2487
+ return rectToClientRect({
2488
+ width,
2489
+ height,
1881
2490
  x,
1882
2491
  y
1883
- };
1884
- x = _ref4.x;
1885
- y = _ref4.y;
1886
- if (gpuAcceleration) {
1887
- var _Object$assign;
1888
- return Object.assign({}, commonStyles, (_Object$assign = {}, _Object$assign[sideY] = hasY ? "0" : "", _Object$assign[sideX] = hasX ? "0" : "", _Object$assign.transform = (win.devicePixelRatio || 1) <= 1 ? "translate(" + x + "px, " + y + "px)" : "translate3d(" + x + "px, " + y + "px, 0)", _Object$assign));
1889
- }
1890
- return Object.assign({}, commonStyles, (_Object$assign2 = {}, _Object$assign2[sideY] = hasY ? y + "px" : "", _Object$assign2[sideX] = hasX ? x + "px" : "", _Object$assign2.transform = "", _Object$assign2));
1891
- }
1892
- function computeStyles(_ref5) {
1893
- var state = _ref5.state, options = _ref5.options;
1894
- var _options$gpuAccelerat = options.gpuAcceleration, gpuAcceleration = _options$gpuAccelerat === void 0 ? true : _options$gpuAccelerat, _options$adaptive = options.adaptive, adaptive = _options$adaptive === void 0 ? true : _options$adaptive, _options$roundOffsets = options.roundOffsets, roundOffsets = _options$roundOffsets === void 0 ? true : _options$roundOffsets;
1895
- var commonStyles = {
1896
- placement: getBasePlacement(state.placement),
1897
- variation: getVariation(state.placement),
1898
- popper: state.elements.popper,
1899
- popperRect: state.rects.popper,
1900
- gpuAcceleration,
1901
- isFixed: state.options.strategy === "fixed"
1902
- };
1903
- if (state.modifiersData.popperOffsets != null) {
1904
- state.styles.popper = Object.assign({}, state.styles.popper, mapToStyles(Object.assign({}, commonStyles, {
1905
- offsets: state.modifiersData.popperOffsets,
1906
- position: state.options.strategy,
1907
- adaptive,
1908
- roundOffsets
1909
- })));
1910
- }
1911
- if (state.modifiersData.arrow != null) {
1912
- state.styles.arrow = Object.assign({}, state.styles.arrow, mapToStyles(Object.assign({}, commonStyles, {
1913
- offsets: state.modifiersData.arrow,
1914
- position: "absolute",
1915
- adaptive: false,
1916
- roundOffsets
1917
- })));
1918
- }
1919
- state.attributes.popper = Object.assign({}, state.attributes.popper, {
1920
- "data-popper-placement": state.placement
1921
2492
  });
1922
2493
  }
1923
- const computeStyles$1 = {
1924
- name: "computeStyles",
1925
- enabled: true,
1926
- phase: "beforeWrite",
1927
- fn: computeStyles,
1928
- data: {}
1929
- };
1930
- var passive = {
1931
- passive: true
1932
- };
1933
- function effect(_ref) {
1934
- var state = _ref.state, instance = _ref.instance, options = _ref.options;
1935
- var _options$scroll = options.scroll, scroll = _options$scroll === void 0 ? true : _options$scroll, _options$resize = options.resize, resize = _options$resize === void 0 ? true : _options$resize;
1936
- var window2 = getWindow(state.elements.popper);
1937
- var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
1938
- if (scroll) {
1939
- scrollParents.forEach(function(scrollParent) {
1940
- scrollParent.addEventListener("scroll", instance.update, passive);
1941
- });
1942
- }
1943
- if (resize) {
1944
- window2.addEventListener("resize", instance.update, passive);
1945
- }
1946
- return function() {
1947
- if (scroll) {
1948
- scrollParents.forEach(function(scrollParent) {
1949
- scrollParent.removeEventListener("scroll", instance.update, passive);
1950
- });
2494
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
2495
+ let {
2496
+ elements,
2497
+ rect,
2498
+ offsetParent,
2499
+ strategy
2500
+ } = _ref;
2501
+ const isFixed = strategy === "fixed";
2502
+ const documentElement = getDocumentElement(offsetParent);
2503
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
2504
+ if (offsetParent === documentElement || topLayer && isFixed) {
2505
+ return rect;
2506
+ }
2507
+ let scroll = {
2508
+ scrollLeft: 0,
2509
+ scrollTop: 0
2510
+ };
2511
+ let scale = createCoords(1);
2512
+ const offsets = createCoords(0);
2513
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
2514
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2515
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
2516
+ scroll = getNodeScroll(offsetParent);
1951
2517
  }
1952
- if (resize) {
1953
- window2.removeEventListener("resize", instance.update, passive);
2518
+ if (isHTMLElement(offsetParent)) {
2519
+ const offsetRect = getBoundingClientRect(offsetParent);
2520
+ scale = getScale(offsetParent);
2521
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
2522
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1954
2523
  }
2524
+ }
2525
+ return {
2526
+ width: rect.width * scale.x,
2527
+ height: rect.height * scale.y,
2528
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x,
2529
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y
1955
2530
  };
1956
2531
  }
1957
- const eventListeners = {
1958
- name: "eventListeners",
1959
- enabled: true,
1960
- phase: "write",
1961
- fn: function fn() {
1962
- },
1963
- effect,
1964
- data: {}
1965
- };
1966
- var hash$1 = {
1967
- left: "right",
1968
- right: "left",
1969
- bottom: "top",
1970
- top: "bottom"
1971
- };
1972
- function getOppositePlacement(placement) {
1973
- return placement.replace(/left|right|bottom|top/g, function(matched) {
1974
- return hash$1[matched];
1975
- });
2532
+ function getClientRects(element) {
2533
+ return Array.from(element.getClientRects());
1976
2534
  }
1977
- var hash = {
1978
- start: "end",
1979
- end: "start"
1980
- };
1981
- function getOppositeVariationPlacement(placement) {
1982
- return placement.replace(/start|end/g, function(matched) {
1983
- return hash[matched];
1984
- });
2535
+ function getWindowScrollBarX(element, rect) {
2536
+ const leftScroll = getNodeScroll(element).scrollLeft;
2537
+ if (!rect) {
2538
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
2539
+ }
2540
+ return rect.left + leftScroll;
1985
2541
  }
1986
- function getWindowScroll(node) {
1987
- var win = getWindow(node);
1988
- var scrollLeft = win.pageXOffset;
1989
- var scrollTop = win.pageYOffset;
2542
+ function getDocumentRect(element) {
2543
+ const html = getDocumentElement(element);
2544
+ const scroll = getNodeScroll(element);
2545
+ const body = element.ownerDocument.body;
2546
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
2547
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
2548
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
2549
+ const y = -scroll.scrollTop;
2550
+ if (getComputedStyle$1(body).direction === "rtl") {
2551
+ x += max(html.clientWidth, body.clientWidth) - width;
2552
+ }
1990
2553
  return {
1991
- scrollLeft,
1992
- scrollTop
2554
+ width,
2555
+ height,
2556
+ x,
2557
+ y
1993
2558
  };
1994
2559
  }
1995
- function getWindowScrollBarX(element) {
1996
- return getBoundingClientRect(getDocumentElement(element)).left + getWindowScroll(element).scrollLeft;
1997
- }
1998
2560
  function getViewportRect(element, strategy) {
1999
- var win = getWindow(element);
2000
- var html = getDocumentElement(element);
2001
- var visualViewport = win.visualViewport;
2002
- var width = html.clientWidth;
2003
- var height = html.clientHeight;
2004
- var x = 0;
2005
- var y = 0;
2561
+ const win = getWindow(element);
2562
+ const html = getDocumentElement(element);
2563
+ const visualViewport = win.visualViewport;
2564
+ let width = html.clientWidth;
2565
+ let height = html.clientHeight;
2566
+ let x = 0;
2567
+ let y = 0;
2006
2568
  if (visualViewport) {
2007
2569
  width = visualViewport.width;
2008
2570
  height = visualViewport.height;
2009
- var layoutViewport = isLayoutViewport();
2010
- if (layoutViewport || !layoutViewport && strategy === "fixed") {
2571
+ const visualViewportBased = isWebKit();
2572
+ if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
2011
2573
  x = visualViewport.offsetLeft;
2012
2574
  y = visualViewport.offsetTop;
2013
2575
  }
@@ -2015,22 +2577,19 @@ function getViewportRect(element, strategy) {
2015
2577
  return {
2016
2578
  width,
2017
2579
  height,
2018
- x: x + getWindowScrollBarX(element),
2580
+ x,
2019
2581
  y
2020
2582
  };
2021
2583
  }
2022
- function getDocumentRect(element) {
2023
- var _element$ownerDocumen;
2024
- var html = getDocumentElement(element);
2025
- var winScroll = getWindowScroll(element);
2026
- var body = (_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body;
2027
- var width = max(html.scrollWidth, html.clientWidth, body ? body.scrollWidth : 0, body ? body.clientWidth : 0);
2028
- var height = max(html.scrollHeight, html.clientHeight, body ? body.scrollHeight : 0, body ? body.clientHeight : 0);
2029
- var x = -winScroll.scrollLeft + getWindowScrollBarX(element);
2030
- var y = -winScroll.scrollTop;
2031
- if (getComputedStyle$1(body || html).direction === "rtl") {
2032
- x += max(html.clientWidth, body ? body.clientWidth : 0) - width;
2033
- }
2584
+ function getInnerBoundingClientRect(element, strategy) {
2585
+ const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
2586
+ const top = clientRect.top + element.clientTop;
2587
+ const left = clientRect.left + element.clientLeft;
2588
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
2589
+ const width = element.clientWidth * scale.x;
2590
+ const height = element.clientHeight * scale.y;
2591
+ const x = left * scale.x;
2592
+ const y = top * scale.y;
2034
2593
  return {
2035
2594
  width,
2036
2595
  height,
@@ -2038,794 +2597,358 @@ function getDocumentRect(element) {
2038
2597
  y
2039
2598
  };
2040
2599
  }
2041
- function isScrollParent(element) {
2042
- var _getComputedStyle = getComputedStyle$1(element), overflow = _getComputedStyle.overflow, overflowX = _getComputedStyle.overflowX, overflowY = _getComputedStyle.overflowY;
2043
- return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
2044
- }
2045
- function getScrollParent(node) {
2046
- if (["html", "body", "#document"].indexOf(getNodeName(node)) >= 0) {
2047
- return node.ownerDocument.body;
2048
- }
2049
- if (isHTMLElement(node) && isScrollParent(node)) {
2050
- return node;
2600
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
2601
+ let rect;
2602
+ if (clippingAncestor === "viewport") {
2603
+ rect = getViewportRect(element, strategy);
2604
+ } else if (clippingAncestor === "document") {
2605
+ rect = getDocumentRect(getDocumentElement(element));
2606
+ } else if (isElement(clippingAncestor)) {
2607
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
2608
+ } else {
2609
+ const visualOffsets = getVisualOffsets(element);
2610
+ rect = {
2611
+ ...clippingAncestor,
2612
+ x: clippingAncestor.x - visualOffsets.x,
2613
+ y: clippingAncestor.y - visualOffsets.y
2614
+ };
2051
2615
  }
2052
- return getScrollParent(getParentNode(node));
2616
+ return rectToClientRect(rect);
2053
2617
  }
2054
- function listScrollParents(element, list) {
2055
- var _element$ownerDocumen;
2056
- if (list === void 0) {
2057
- list = [];
2618
+ function hasFixedPositionAncestor(element, stopNode) {
2619
+ const parentNode = getParentNode(element);
2620
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
2621
+ return false;
2058
2622
  }
2059
- var scrollParent = getScrollParent(element);
2060
- var isBody = scrollParent === ((_element$ownerDocumen = element.ownerDocument) == null ? void 0 : _element$ownerDocumen.body);
2061
- var win = getWindow(scrollParent);
2062
- var target = isBody ? [win].concat(win.visualViewport || [], isScrollParent(scrollParent) ? scrollParent : []) : scrollParent;
2063
- var updatedList = list.concat(target);
2064
- return isBody ? updatedList : (
2065
- // $FlowFixMe[incompatible-call]: isBody tells us target will be an HTMLElement here
2066
- updatedList.concat(listScrollParents(getParentNode(target)))
2067
- );
2068
- }
2069
- function rectToClientRect(rect) {
2070
- return Object.assign({}, rect, {
2071
- left: rect.x,
2072
- top: rect.y,
2073
- right: rect.x + rect.width,
2074
- bottom: rect.y + rect.height
2075
- });
2076
- }
2077
- function getInnerBoundingClientRect(element, strategy) {
2078
- var rect = getBoundingClientRect(element, false, strategy === "fixed");
2079
- rect.top = rect.top + element.clientTop;
2080
- rect.left = rect.left + element.clientLeft;
2081
- rect.bottom = rect.top + element.clientHeight;
2082
- rect.right = rect.left + element.clientWidth;
2083
- rect.width = element.clientWidth;
2084
- rect.height = element.clientHeight;
2085
- rect.x = rect.left;
2086
- rect.y = rect.top;
2087
- return rect;
2088
- }
2089
- function getClientRectFromMixedType(element, clippingParent, strategy) {
2090
- return clippingParent === viewport ? rectToClientRect(getViewportRect(element, strategy)) : isElement(clippingParent) ? getInnerBoundingClientRect(clippingParent, strategy) : rectToClientRect(getDocumentRect(getDocumentElement(element)));
2091
- }
2092
- function getClippingParents(element) {
2093
- var clippingParents2 = listScrollParents(getParentNode(element));
2094
- var canEscapeClipping = ["absolute", "fixed"].indexOf(getComputedStyle$1(element).position) >= 0;
2095
- var clipperElement = canEscapeClipping && isHTMLElement(element) ? getOffsetParent(element) : element;
2096
- if (!isElement(clipperElement)) {
2097
- return [];
2098
- }
2099
- return clippingParents2.filter(function(clippingParent) {
2100
- return isElement(clippingParent) && contains(clippingParent, clipperElement) && getNodeName(clippingParent) !== "body";
2101
- });
2623
+ return getComputedStyle$1(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
2624
+ }
2625
+ function getClippingElementAncestors(element, cache) {
2626
+ const cachedResult = cache.get(element);
2627
+ if (cachedResult) {
2628
+ return cachedResult;
2629
+ }
2630
+ let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
2631
+ let currentContainingBlockComputedStyle = null;
2632
+ const elementIsFixed = getComputedStyle$1(element).position === "fixed";
2633
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
2634
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
2635
+ const computedStyle = getComputedStyle$1(currentNode);
2636
+ const currentNodeIsContaining = isContainingBlock(currentNode);
2637
+ if (!currentNodeIsContaining && computedStyle.position === "fixed") {
2638
+ currentContainingBlockComputedStyle = null;
2639
+ }
2640
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && ["absolute", "fixed"].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
2641
+ if (shouldDropCurrentNode) {
2642
+ result = result.filter((ancestor) => ancestor !== currentNode);
2643
+ } else {
2644
+ currentContainingBlockComputedStyle = computedStyle;
2645
+ }
2646
+ currentNode = getParentNode(currentNode);
2647
+ }
2648
+ cache.set(element, result);
2649
+ return result;
2102
2650
  }
2103
- function getClippingRect(element, boundary, rootBoundary, strategy) {
2104
- var mainClippingParents = boundary === "clippingParents" ? getClippingParents(element) : [].concat(boundary);
2105
- var clippingParents2 = [].concat(mainClippingParents, [rootBoundary]);
2106
- var firstClippingParent = clippingParents2[0];
2107
- var clippingRect = clippingParents2.reduce(function(accRect, clippingParent) {
2108
- var rect = getClientRectFromMixedType(element, clippingParent, strategy);
2651
+ function getClippingRect(_ref) {
2652
+ let {
2653
+ element,
2654
+ boundary,
2655
+ rootBoundary,
2656
+ strategy
2657
+ } = _ref;
2658
+ const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
2659
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
2660
+ const firstClippingAncestor = clippingAncestors[0];
2661
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
2662
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
2109
2663
  accRect.top = max(rect.top, accRect.top);
2110
2664
  accRect.right = min(rect.right, accRect.right);
2111
2665
  accRect.bottom = min(rect.bottom, accRect.bottom);
2112
2666
  accRect.left = max(rect.left, accRect.left);
2113
2667
  return accRect;
2114
- }, getClientRectFromMixedType(element, firstClippingParent, strategy));
2115
- clippingRect.width = clippingRect.right - clippingRect.left;
2116
- clippingRect.height = clippingRect.bottom - clippingRect.top;
2117
- clippingRect.x = clippingRect.left;
2118
- clippingRect.y = clippingRect.top;
2119
- return clippingRect;
2120
- }
2121
- function computeOffsets(_ref) {
2122
- var reference2 = _ref.reference, element = _ref.element, placement = _ref.placement;
2123
- var basePlacement = placement ? getBasePlacement(placement) : null;
2124
- var variation = placement ? getVariation(placement) : null;
2125
- var commonX = reference2.x + reference2.width / 2 - element.width / 2;
2126
- var commonY = reference2.y + reference2.height / 2 - element.height / 2;
2127
- var offsets;
2128
- switch (basePlacement) {
2129
- case top:
2130
- offsets = {
2131
- x: commonX,
2132
- y: reference2.y - element.height
2133
- };
2134
- break;
2135
- case bottom:
2136
- offsets = {
2137
- x: commonX,
2138
- y: reference2.y + reference2.height
2139
- };
2140
- break;
2141
- case right:
2142
- offsets = {
2143
- x: reference2.x + reference2.width,
2144
- y: commonY
2145
- };
2146
- break;
2147
- case left:
2148
- offsets = {
2149
- x: reference2.x - element.width,
2150
- y: commonY
2151
- };
2152
- break;
2153
- default:
2154
- offsets = {
2155
- x: reference2.x,
2156
- y: reference2.y
2157
- };
2158
- }
2159
- var mainAxis = basePlacement ? getMainAxisFromPlacement(basePlacement) : null;
2160
- if (mainAxis != null) {
2161
- var len = mainAxis === "y" ? "height" : "width";
2162
- switch (variation) {
2163
- case start:
2164
- offsets[mainAxis] = offsets[mainAxis] - (reference2[len] / 2 - element[len] / 2);
2165
- break;
2166
- case end:
2167
- offsets[mainAxis] = offsets[mainAxis] + (reference2[len] / 2 - element[len] / 2);
2168
- break;
2169
- }
2170
- }
2171
- return offsets;
2172
- }
2173
- function detectOverflow(state, options) {
2174
- if (options === void 0) {
2175
- options = {};
2176
- }
2177
- var _options = options, _options$placement = _options.placement, placement = _options$placement === void 0 ? state.placement : _options$placement, _options$strategy = _options.strategy, strategy = _options$strategy === void 0 ? state.strategy : _options$strategy, _options$boundary = _options.boundary, boundary = _options$boundary === void 0 ? clippingParents : _options$boundary, _options$rootBoundary = _options.rootBoundary, rootBoundary = _options$rootBoundary === void 0 ? viewport : _options$rootBoundary, _options$elementConte = _options.elementContext, elementContext = _options$elementConte === void 0 ? popper : _options$elementConte, _options$altBoundary = _options.altBoundary, altBoundary = _options$altBoundary === void 0 ? false : _options$altBoundary, _options$padding = _options.padding, padding = _options$padding === void 0 ? 0 : _options$padding;
2178
- var paddingObject = mergePaddingObject(typeof padding !== "number" ? padding : expandToHashMap(padding, basePlacements));
2179
- var altContext = elementContext === popper ? reference : popper;
2180
- var popperRect = state.rects.popper;
2181
- var element = state.elements[altBoundary ? altContext : elementContext];
2182
- var clippingClientRect = getClippingRect(isElement(element) ? element : element.contextElement || getDocumentElement(state.elements.popper), boundary, rootBoundary, strategy);
2183
- var referenceClientRect = getBoundingClientRect(state.elements.reference);
2184
- var popperOffsets2 = computeOffsets({
2185
- reference: referenceClientRect,
2186
- element: popperRect,
2187
- strategy: "absolute",
2188
- placement
2189
- });
2190
- var popperClientRect = rectToClientRect(Object.assign({}, popperRect, popperOffsets2));
2191
- var elementClientRect = elementContext === popper ? popperClientRect : referenceClientRect;
2192
- var overflowOffsets = {
2193
- top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
2194
- bottom: elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom,
2195
- left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
2196
- right: elementClientRect.right - clippingClientRect.right + paddingObject.right
2197
- };
2198
- var offsetData = state.modifiersData.offset;
2199
- if (elementContext === popper && offsetData) {
2200
- var offset2 = offsetData[placement];
2201
- Object.keys(overflowOffsets).forEach(function(key) {
2202
- var multiply = [right, bottom].indexOf(key) >= 0 ? 1 : -1;
2203
- var axis = [top, bottom].indexOf(key) >= 0 ? "y" : "x";
2204
- overflowOffsets[key] += offset2[axis] * multiply;
2205
- });
2206
- }
2207
- return overflowOffsets;
2208
- }
2209
- function computeAutoPlacement(state, options) {
2210
- if (options === void 0) {
2211
- options = {};
2212
- }
2213
- var _options = options, placement = _options.placement, boundary = _options.boundary, rootBoundary = _options.rootBoundary, padding = _options.padding, flipVariations = _options.flipVariations, _options$allowedAutoP = _options.allowedAutoPlacements, allowedAutoPlacements = _options$allowedAutoP === void 0 ? placements : _options$allowedAutoP;
2214
- var variation = getVariation(placement);
2215
- var placements$1 = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function(placement2) {
2216
- return getVariation(placement2) === variation;
2217
- }) : basePlacements;
2218
- var allowedPlacements = placements$1.filter(function(placement2) {
2219
- return allowedAutoPlacements.indexOf(placement2) >= 0;
2220
- });
2221
- if (allowedPlacements.length === 0) {
2222
- allowedPlacements = placements$1;
2223
- }
2224
- var overflows = allowedPlacements.reduce(function(acc, placement2) {
2225
- acc[placement2] = detectOverflow(state, {
2226
- placement: placement2,
2227
- boundary,
2228
- rootBoundary,
2229
- padding
2230
- })[getBasePlacement(placement2)];
2231
- return acc;
2232
- }, {});
2233
- return Object.keys(overflows).sort(function(a, b) {
2234
- return overflows[a] - overflows[b];
2235
- });
2236
- }
2237
- function getExpandedFallbackPlacements(placement) {
2238
- if (getBasePlacement(placement) === auto) {
2239
- return [];
2240
- }
2241
- var oppositePlacement = getOppositePlacement(placement);
2242
- return [getOppositeVariationPlacement(placement), oppositePlacement, getOppositeVariationPlacement(oppositePlacement)];
2243
- }
2244
- function flip(_ref) {
2245
- var state = _ref.state, options = _ref.options, name = _ref.name;
2246
- if (state.modifiersData[name]._skip) {
2247
- return;
2248
- }
2249
- var _options$mainAxis = options.mainAxis, checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis, _options$altAxis = options.altAxis, checkAltAxis = _options$altAxis === void 0 ? true : _options$altAxis, specifiedFallbackPlacements = options.fallbackPlacements, padding = options.padding, boundary = options.boundary, rootBoundary = options.rootBoundary, altBoundary = options.altBoundary, _options$flipVariatio = options.flipVariations, flipVariations = _options$flipVariatio === void 0 ? true : _options$flipVariatio, allowedAutoPlacements = options.allowedAutoPlacements;
2250
- var preferredPlacement = state.options.placement;
2251
- var basePlacement = getBasePlacement(preferredPlacement);
2252
- var isBasePlacement = basePlacement === preferredPlacement;
2253
- var fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipVariations ? [getOppositePlacement(preferredPlacement)] : getExpandedFallbackPlacements(preferredPlacement));
2254
- var placements2 = [preferredPlacement].concat(fallbackPlacements).reduce(function(acc, placement2) {
2255
- return acc.concat(getBasePlacement(placement2) === auto ? computeAutoPlacement(state, {
2256
- placement: placement2,
2257
- boundary,
2258
- rootBoundary,
2259
- padding,
2260
- flipVariations,
2261
- allowedAutoPlacements
2262
- }) : placement2);
2263
- }, []);
2264
- var referenceRect = state.rects.reference;
2265
- var popperRect = state.rects.popper;
2266
- var checksMap = /* @__PURE__ */ new Map();
2267
- var makeFallbackChecks = true;
2268
- var firstFittingPlacement = placements2[0];
2269
- for (var i = 0; i < placements2.length; i++) {
2270
- var placement = placements2[i];
2271
- var _basePlacement = getBasePlacement(placement);
2272
- var isStartVariation = getVariation(placement) === start;
2273
- var isVertical = [top, bottom].indexOf(_basePlacement) >= 0;
2274
- var len = isVertical ? "width" : "height";
2275
- var overflow = detectOverflow(state, {
2276
- placement,
2277
- boundary,
2278
- rootBoundary,
2279
- altBoundary,
2280
- padding
2281
- });
2282
- var mainVariationSide = isVertical ? isStartVariation ? right : left : isStartVariation ? bottom : top;
2283
- if (referenceRect[len] > popperRect[len]) {
2284
- mainVariationSide = getOppositePlacement(mainVariationSide);
2285
- }
2286
- var altVariationSide = getOppositePlacement(mainVariationSide);
2287
- var checks = [];
2288
- if (checkMainAxis) {
2289
- checks.push(overflow[_basePlacement] <= 0);
2290
- }
2291
- if (checkAltAxis) {
2292
- checks.push(overflow[mainVariationSide] <= 0, overflow[altVariationSide] <= 0);
2293
- }
2294
- if (checks.every(function(check) {
2295
- return check;
2296
- })) {
2297
- firstFittingPlacement = placement;
2298
- makeFallbackChecks = false;
2299
- break;
2300
- }
2301
- checksMap.set(placement, checks);
2302
- }
2303
- if (makeFallbackChecks) {
2304
- var numberOfChecks = flipVariations ? 3 : 1;
2305
- var _loop = function _loop2(_i2) {
2306
- var fittingPlacement = placements2.find(function(placement2) {
2307
- var checks2 = checksMap.get(placement2);
2308
- if (checks2) {
2309
- return checks2.slice(0, _i2).every(function(check) {
2310
- return check;
2311
- });
2312
- }
2313
- });
2314
- if (fittingPlacement) {
2315
- firstFittingPlacement = fittingPlacement;
2316
- return "break";
2317
- }
2318
- };
2319
- for (var _i = numberOfChecks; _i > 0; _i--) {
2320
- var _ret = _loop(_i);
2321
- if (_ret === "break") break;
2322
- }
2323
- }
2324
- if (state.placement !== firstFittingPlacement) {
2325
- state.modifiersData[name]._skip = true;
2326
- state.placement = firstFittingPlacement;
2327
- state.reset = true;
2328
- }
2329
- }
2330
- const flip$1 = {
2331
- name: "flip",
2332
- enabled: true,
2333
- phase: "main",
2334
- fn: flip,
2335
- requiresIfExists: ["offset"],
2336
- data: {
2337
- _skip: false
2338
- }
2339
- };
2340
- function getSideOffsets(overflow, rect, preventedOffsets) {
2341
- if (preventedOffsets === void 0) {
2342
- preventedOffsets = {
2343
- x: 0,
2344
- y: 0
2345
- };
2346
- }
2668
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
2347
2669
  return {
2348
- top: overflow.top - rect.height - preventedOffsets.y,
2349
- right: overflow.right - rect.width + preventedOffsets.x,
2350
- bottom: overflow.bottom - rect.height + preventedOffsets.y,
2351
- left: overflow.left - rect.width - preventedOffsets.x
2670
+ width: clippingRect.right - clippingRect.left,
2671
+ height: clippingRect.bottom - clippingRect.top,
2672
+ x: clippingRect.left,
2673
+ y: clippingRect.top
2352
2674
  };
2353
2675
  }
2354
- function isAnySideFullyClipped(overflow) {
2355
- return [top, right, bottom, left].some(function(side) {
2356
- return overflow[side] >= 0;
2357
- });
2358
- }
2359
- function hide(_ref) {
2360
- var state = _ref.state, name = _ref.name;
2361
- var referenceRect = state.rects.reference;
2362
- var popperRect = state.rects.popper;
2363
- var preventedOffsets = state.modifiersData.preventOverflow;
2364
- var referenceOverflow = detectOverflow(state, {
2365
- elementContext: "reference"
2366
- });
2367
- var popperAltOverflow = detectOverflow(state, {
2368
- altBoundary: true
2369
- });
2370
- var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
2371
- var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
2372
- var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
2373
- var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
2374
- state.modifiersData[name] = {
2375
- referenceClippingOffsets,
2376
- popperEscapeOffsets,
2377
- isReferenceHidden,
2378
- hasPopperEscaped
2379
- };
2380
- state.attributes.popper = Object.assign({}, state.attributes.popper, {
2381
- "data-popper-reference-hidden": isReferenceHidden,
2382
- "data-popper-escaped": hasPopperEscaped
2383
- });
2384
- }
2385
- const hide$1 = {
2386
- name: "hide",
2387
- enabled: true,
2388
- phase: "main",
2389
- requiresIfExists: ["preventOverflow"],
2390
- fn: hide
2391
- };
2392
- function distanceAndSkiddingToXY(placement, rects, offset2) {
2393
- var basePlacement = getBasePlacement(placement);
2394
- var invertDistance = [left, top].indexOf(basePlacement) >= 0 ? -1 : 1;
2395
- var _ref = typeof offset2 === "function" ? offset2(Object.assign({}, rects, {
2396
- placement
2397
- })) : offset2, skidding = _ref[0], distance = _ref[1];
2398
- skidding = skidding || 0;
2399
- distance = (distance || 0) * invertDistance;
2400
- return [left, right].indexOf(basePlacement) >= 0 ? {
2401
- x: distance,
2402
- y: skidding
2403
- } : {
2404
- x: skidding,
2405
- y: distance
2406
- };
2407
- }
2408
- function offset(_ref2) {
2409
- var state = _ref2.state, options = _ref2.options, name = _ref2.name;
2410
- var _options$offset = options.offset, offset2 = _options$offset === void 0 ? [0, 0] : _options$offset;
2411
- var data = placements.reduce(function(acc, placement) {
2412
- acc[placement] = distanceAndSkiddingToXY(placement, state.rects, offset2);
2413
- return acc;
2414
- }, {});
2415
- var _data$state$placement = data[state.placement], x = _data$state$placement.x, y = _data$state$placement.y;
2416
- if (state.modifiersData.popperOffsets != null) {
2417
- state.modifiersData.popperOffsets.x += x;
2418
- state.modifiersData.popperOffsets.y += y;
2419
- }
2420
- state.modifiersData[name] = data;
2421
- }
2422
- const offset$1 = {
2423
- name: "offset",
2424
- enabled: true,
2425
- phase: "main",
2426
- requires: ["popperOffsets"],
2427
- fn: offset
2428
- };
2429
- function popperOffsets(_ref) {
2430
- var state = _ref.state, name = _ref.name;
2431
- state.modifiersData[name] = computeOffsets({
2432
- reference: state.rects.reference,
2433
- element: state.rects.popper,
2434
- strategy: "absolute",
2435
- placement: state.placement
2436
- });
2437
- }
2438
- const popperOffsets$1 = {
2439
- name: "popperOffsets",
2440
- enabled: true,
2441
- phase: "read",
2442
- fn: popperOffsets,
2443
- data: {}
2444
- };
2445
- function getAltAxis(axis) {
2446
- return axis === "x" ? "y" : "x";
2447
- }
2448
- function preventOverflow(_ref) {
2449
- var state = _ref.state, options = _ref.options, name = _ref.name;
2450
- var _options$mainAxis = options.mainAxis, checkMainAxis = _options$mainAxis === void 0 ? true : _options$mainAxis, _options$altAxis = options.altAxis, checkAltAxis = _options$altAxis === void 0 ? false : _options$altAxis, boundary = options.boundary, rootBoundary = options.rootBoundary, altBoundary = options.altBoundary, padding = options.padding, _options$tether = options.tether, tether = _options$tether === void 0 ? true : _options$tether, _options$tetherOffset = options.tetherOffset, tetherOffset = _options$tetherOffset === void 0 ? 0 : _options$tetherOffset;
2451
- var overflow = detectOverflow(state, {
2452
- boundary,
2453
- rootBoundary,
2454
- padding,
2455
- altBoundary
2456
- });
2457
- var basePlacement = getBasePlacement(state.placement);
2458
- var variation = getVariation(state.placement);
2459
- var isBasePlacement = !variation;
2460
- var mainAxis = getMainAxisFromPlacement(basePlacement);
2461
- var altAxis = getAltAxis(mainAxis);
2462
- var popperOffsets2 = state.modifiersData.popperOffsets;
2463
- var referenceRect = state.rects.reference;
2464
- var popperRect = state.rects.popper;
2465
- var tetherOffsetValue = typeof tetherOffset === "function" ? tetherOffset(Object.assign({}, state.rects, {
2466
- placement: state.placement
2467
- })) : tetherOffset;
2468
- var normalizedTetherOffsetValue = typeof tetherOffsetValue === "number" ? {
2469
- mainAxis: tetherOffsetValue,
2470
- altAxis: tetherOffsetValue
2471
- } : Object.assign({
2472
- mainAxis: 0,
2473
- altAxis: 0
2474
- }, tetherOffsetValue);
2475
- var offsetModifierState = state.modifiersData.offset ? state.modifiersData.offset[state.placement] : null;
2476
- var data = {
2477
- x: 0,
2478
- y: 0
2479
- };
2480
- if (!popperOffsets2) {
2481
- return;
2482
- }
2483
- if (checkMainAxis) {
2484
- var _offsetModifierState$;
2485
- var mainSide = mainAxis === "y" ? top : left;
2486
- var altSide = mainAxis === "y" ? bottom : right;
2487
- var len = mainAxis === "y" ? "height" : "width";
2488
- var offset2 = popperOffsets2[mainAxis];
2489
- var min$1 = offset2 + overflow[mainSide];
2490
- var max$1 = offset2 - overflow[altSide];
2491
- var additive = tether ? -popperRect[len] / 2 : 0;
2492
- var minLen = variation === start ? referenceRect[len] : popperRect[len];
2493
- var maxLen = variation === start ? -popperRect[len] : -referenceRect[len];
2494
- var arrowElement = state.elements.arrow;
2495
- var arrowRect = tether && arrowElement ? getLayoutRect(arrowElement) : {
2496
- width: 0,
2497
- height: 0
2498
- };
2499
- var arrowPaddingObject = state.modifiersData["arrow#persistent"] ? state.modifiersData["arrow#persistent"].padding : getFreshSideObject();
2500
- var arrowPaddingMin = arrowPaddingObject[mainSide];
2501
- var arrowPaddingMax = arrowPaddingObject[altSide];
2502
- var arrowLen = within(0, referenceRect[len], arrowRect[len]);
2503
- var minOffset = isBasePlacement ? referenceRect[len] / 2 - additive - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis : minLen - arrowLen - arrowPaddingMin - normalizedTetherOffsetValue.mainAxis;
2504
- var maxOffset = isBasePlacement ? -referenceRect[len] / 2 + additive + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis : maxLen + arrowLen + arrowPaddingMax + normalizedTetherOffsetValue.mainAxis;
2505
- var arrowOffsetParent = state.elements.arrow && getOffsetParent(state.elements.arrow);
2506
- var clientOffset = arrowOffsetParent ? mainAxis === "y" ? arrowOffsetParent.clientTop || 0 : arrowOffsetParent.clientLeft || 0 : 0;
2507
- var offsetModifierValue = (_offsetModifierState$ = offsetModifierState == null ? void 0 : offsetModifierState[mainAxis]) != null ? _offsetModifierState$ : 0;
2508
- var tetherMin = offset2 + minOffset - offsetModifierValue - clientOffset;
2509
- var tetherMax = offset2 + maxOffset - offsetModifierValue;
2510
- var preventedOffset = within(tether ? min(min$1, tetherMin) : min$1, offset2, tether ? max(max$1, tetherMax) : max$1);
2511
- popperOffsets2[mainAxis] = preventedOffset;
2512
- data[mainAxis] = preventedOffset - offset2;
2513
- }
2514
- if (checkAltAxis) {
2515
- var _offsetModifierState$2;
2516
- var _mainSide = mainAxis === "x" ? top : left;
2517
- var _altSide = mainAxis === "x" ? bottom : right;
2518
- var _offset = popperOffsets2[altAxis];
2519
- var _len = altAxis === "y" ? "height" : "width";
2520
- var _min = _offset + overflow[_mainSide];
2521
- var _max = _offset - overflow[_altSide];
2522
- var isOriginSide = [top, left].indexOf(basePlacement) !== -1;
2523
- var _offsetModifierValue = (_offsetModifierState$2 = offsetModifierState == null ? void 0 : offsetModifierState[altAxis]) != null ? _offsetModifierState$2 : 0;
2524
- var _tetherMin = isOriginSide ? _min : _offset - referenceRect[_len] - popperRect[_len] - _offsetModifierValue + normalizedTetherOffsetValue.altAxis;
2525
- var _tetherMax = isOriginSide ? _offset + referenceRect[_len] + popperRect[_len] - _offsetModifierValue - normalizedTetherOffsetValue.altAxis : _max;
2526
- var _preventedOffset = tether && isOriginSide ? withinMaxClamp(_tetherMin, _offset, _tetherMax) : within(tether ? _tetherMin : _min, _offset, tether ? _tetherMax : _max);
2527
- popperOffsets2[altAxis] = _preventedOffset;
2528
- data[altAxis] = _preventedOffset - _offset;
2529
- }
2530
- state.modifiersData[name] = data;
2531
- }
2532
- const preventOverflow$1 = {
2533
- name: "preventOverflow",
2534
- enabled: true,
2535
- phase: "main",
2536
- fn: preventOverflow,
2537
- requiresIfExists: ["offset"]
2538
- };
2539
- function getHTMLElementScroll(element) {
2676
+ function getDimensions(element) {
2677
+ const {
2678
+ width,
2679
+ height
2680
+ } = getCssDimensions(element);
2540
2681
  return {
2541
- scrollLeft: element.scrollLeft,
2542
- scrollTop: element.scrollTop
2682
+ width,
2683
+ height
2543
2684
  };
2544
2685
  }
2545
- function getNodeScroll(node) {
2546
- if (node === getWindow(node) || !isHTMLElement(node)) {
2547
- return getWindowScroll(node);
2548
- } else {
2549
- return getHTMLElementScroll(node);
2550
- }
2551
- }
2552
- function isElementScaled(element) {
2553
- var rect = element.getBoundingClientRect();
2554
- var scaleX = round(rect.width) / element.offsetWidth || 1;
2555
- var scaleY = round(rect.height) / element.offsetHeight || 1;
2556
- return scaleX !== 1 || scaleY !== 1;
2557
- }
2558
- function getCompositeRect(elementOrVirtualElement, offsetParent, isFixed) {
2559
- if (isFixed === void 0) {
2560
- isFixed = false;
2561
- }
2562
- var isOffsetParentAnElement = isHTMLElement(offsetParent);
2563
- var offsetParentIsScaled = isHTMLElement(offsetParent) && isElementScaled(offsetParent);
2564
- var documentElement = getDocumentElement(offsetParent);
2565
- var rect = getBoundingClientRect(elementOrVirtualElement, offsetParentIsScaled, isFixed);
2566
- var scroll = {
2686
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
2687
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
2688
+ const documentElement = getDocumentElement(offsetParent);
2689
+ const isFixed = strategy === "fixed";
2690
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
2691
+ let scroll = {
2567
2692
  scrollLeft: 0,
2568
2693
  scrollTop: 0
2569
2694
  };
2570
- var offsets = {
2571
- x: 0,
2572
- y: 0
2573
- };
2695
+ const offsets = createCoords(0);
2574
2696
  if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
2575
- if (getNodeName(offsetParent) !== "body" || // https://github.com/popperjs/popper-core/issues/1078
2576
- isScrollParent(documentElement)) {
2697
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
2577
2698
  scroll = getNodeScroll(offsetParent);
2578
2699
  }
2579
- if (isHTMLElement(offsetParent)) {
2580
- offsets = getBoundingClientRect(offsetParent, true);
2581
- offsets.x += offsetParent.clientLeft;
2582
- offsets.y += offsetParent.clientTop;
2700
+ if (isOffsetParentAnElement) {
2701
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
2702
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
2703
+ offsets.y = offsetRect.y + offsetParent.clientTop;
2583
2704
  } else if (documentElement) {
2584
2705
  offsets.x = getWindowScrollBarX(documentElement);
2585
2706
  }
2586
2707
  }
2708
+ let htmlX = 0;
2709
+ let htmlY = 0;
2710
+ if (documentElement && !isOffsetParentAnElement && !isFixed) {
2711
+ const htmlRect = documentElement.getBoundingClientRect();
2712
+ htmlY = htmlRect.top + scroll.scrollTop;
2713
+ htmlX = htmlRect.left + scroll.scrollLeft - // RTL <body> scrollbar.
2714
+ getWindowScrollBarX(documentElement, htmlRect);
2715
+ }
2716
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlX;
2717
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlY;
2587
2718
  return {
2588
- x: rect.left + scroll.scrollLeft - offsets.x,
2589
- y: rect.top + scroll.scrollTop - offsets.y,
2719
+ x,
2720
+ y,
2590
2721
  width: rect.width,
2591
2722
  height: rect.height
2592
2723
  };
2593
2724
  }
2594
- function order(modifiers) {
2595
- var map = /* @__PURE__ */ new Map();
2596
- var visited = /* @__PURE__ */ new Set();
2597
- var result = [];
2598
- modifiers.forEach(function(modifier) {
2599
- map.set(modifier.name, modifier);
2600
- });
2601
- function sort(modifier) {
2602
- visited.add(modifier.name);
2603
- var requires = [].concat(modifier.requires || [], modifier.requiresIfExists || []);
2604
- requires.forEach(function(dep) {
2605
- if (!visited.has(dep)) {
2606
- var depModifier = map.get(dep);
2607
- if (depModifier) {
2608
- sort(depModifier);
2609
- }
2610
- }
2611
- });
2612
- result.push(modifier);
2725
+ function isStaticPositioned(element) {
2726
+ return getComputedStyle$1(element).position === "static";
2727
+ }
2728
+ function getTrueOffsetParent(element, polyfill) {
2729
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === "fixed") {
2730
+ return null;
2731
+ }
2732
+ if (polyfill) {
2733
+ return polyfill(element);
2613
2734
  }
2614
- modifiers.forEach(function(modifier) {
2615
- if (!visited.has(modifier.name)) {
2616
- sort(modifier);
2735
+ let rawOffsetParent = element.offsetParent;
2736
+ if (getDocumentElement(element) === rawOffsetParent) {
2737
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
2738
+ }
2739
+ return rawOffsetParent;
2740
+ }
2741
+ function getOffsetParent(element, polyfill) {
2742
+ const win = getWindow(element);
2743
+ if (isTopLayer(element)) {
2744
+ return win;
2745
+ }
2746
+ if (!isHTMLElement(element)) {
2747
+ let svgOffsetParent = getParentNode(element);
2748
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
2749
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
2750
+ return svgOffsetParent;
2751
+ }
2752
+ svgOffsetParent = getParentNode(svgOffsetParent);
2617
2753
  }
2618
- });
2619
- return result;
2754
+ return win;
2755
+ }
2756
+ let offsetParent = getTrueOffsetParent(element, polyfill);
2757
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
2758
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
2759
+ }
2760
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
2761
+ return win;
2762
+ }
2763
+ return offsetParent || getContainingBlock(element) || win;
2620
2764
  }
2621
- function orderModifiers(modifiers) {
2622
- var orderedModifiers = order(modifiers);
2623
- return modifierPhases.reduce(function(acc, phase) {
2624
- return acc.concat(orderedModifiers.filter(function(modifier) {
2625
- return modifier.phase === phase;
2626
- }));
2627
- }, []);
2628
- }
2629
- function debounce(fn2) {
2630
- var pending;
2631
- return function() {
2632
- if (!pending) {
2633
- pending = new Promise(function(resolve) {
2634
- Promise.resolve().then(function() {
2635
- pending = void 0;
2636
- resolve(fn2());
2637
- });
2638
- });
2765
+ const getElementRects = async function(data) {
2766
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
2767
+ const getDimensionsFn = this.getDimensions;
2768
+ const floatingDimensions = await getDimensionsFn(data.floating);
2769
+ return {
2770
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
2771
+ floating: {
2772
+ x: 0,
2773
+ y: 0,
2774
+ width: floatingDimensions.width,
2775
+ height: floatingDimensions.height
2639
2776
  }
2640
- return pending;
2641
2777
  };
2642
- }
2643
- function mergeByName(modifiers) {
2644
- var merged = modifiers.reduce(function(merged2, current) {
2645
- var existing = merged2[current.name];
2646
- merged2[current.name] = existing ? Object.assign({}, existing, current, {
2647
- options: Object.assign({}, existing.options, current.options),
2648
- data: Object.assign({}, existing.data, current.data)
2649
- }) : current;
2650
- return merged2;
2651
- }, {});
2652
- return Object.keys(merged).map(function(key) {
2653
- return merged[key];
2654
- });
2655
- }
2656
- var DEFAULT_OPTIONS = {
2657
- placement: "bottom",
2658
- modifiers: [],
2659
- strategy: "absolute"
2660
2778
  };
2661
- function areValidElements() {
2662
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2663
- args[_key] = arguments[_key];
2664
- }
2665
- return !args.some(function(element) {
2666
- return !(element && typeof element.getBoundingClientRect === "function");
2667
- });
2668
- }
2669
- function popperGenerator(generatorOptions) {
2670
- if (generatorOptions === void 0) {
2671
- generatorOptions = {};
2672
- }
2673
- var _generatorOptions = generatorOptions, _generatorOptions$def = _generatorOptions.defaultModifiers, defaultModifiers2 = _generatorOptions$def === void 0 ? [] : _generatorOptions$def, _generatorOptions$def2 = _generatorOptions.defaultOptions, defaultOptions = _generatorOptions$def2 === void 0 ? DEFAULT_OPTIONS : _generatorOptions$def2;
2674
- return function createPopper2(reference2, popper2, options) {
2675
- if (options === void 0) {
2676
- options = defaultOptions;
2779
+ function isRTL(element) {
2780
+ return getComputedStyle$1(element).direction === "rtl";
2781
+ }
2782
+ const platform = {
2783
+ convertOffsetParentRelativeRectToViewportRelativeRect,
2784
+ getDocumentElement,
2785
+ getClippingRect,
2786
+ getOffsetParent,
2787
+ getElementRects,
2788
+ getClientRects,
2789
+ getDimensions,
2790
+ getScale,
2791
+ isElement,
2792
+ isRTL
2793
+ };
2794
+ function observeMove(element, onMove) {
2795
+ let io = null;
2796
+ let timeoutId;
2797
+ const root = getDocumentElement(element);
2798
+ function cleanup() {
2799
+ var _io;
2800
+ clearTimeout(timeoutId);
2801
+ (_io = io) == null || _io.disconnect();
2802
+ io = null;
2803
+ }
2804
+ function refresh(skip, threshold) {
2805
+ if (skip === void 0) {
2806
+ skip = false;
2807
+ }
2808
+ if (threshold === void 0) {
2809
+ threshold = 1;
2810
+ }
2811
+ cleanup();
2812
+ const {
2813
+ left,
2814
+ top,
2815
+ width,
2816
+ height
2817
+ } = element.getBoundingClientRect();
2818
+ if (!skip) {
2819
+ onMove();
2820
+ }
2821
+ if (!width || !height) {
2822
+ return;
2677
2823
  }
2678
- var state = {
2679
- placement: "bottom",
2680
- orderedModifiers: [],
2681
- options: Object.assign({}, DEFAULT_OPTIONS, defaultOptions),
2682
- modifiersData: {},
2683
- elements: {
2684
- reference: reference2,
2685
- popper: popper2
2686
- },
2687
- attributes: {},
2688
- styles: {}
2824
+ const insetTop = floor(top);
2825
+ const insetRight = floor(root.clientWidth - (left + width));
2826
+ const insetBottom = floor(root.clientHeight - (top + height));
2827
+ const insetLeft = floor(left);
2828
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
2829
+ const options = {
2830
+ rootMargin,
2831
+ threshold: max(0, min(1, threshold)) || 1
2689
2832
  };
2690
- var effectCleanupFns = [];
2691
- var isDestroyed = false;
2692
- var instance = {
2693
- state,
2694
- setOptions: function setOptions(setOptionsAction) {
2695
- var options2 = typeof setOptionsAction === "function" ? setOptionsAction(state.options) : setOptionsAction;
2696
- cleanupModifierEffects();
2697
- state.options = Object.assign({}, defaultOptions, state.options, options2);
2698
- state.scrollParents = {
2699
- reference: isElement(reference2) ? listScrollParents(reference2) : reference2.contextElement ? listScrollParents(reference2.contextElement) : [],
2700
- popper: listScrollParents(popper2)
2701
- };
2702
- var orderedModifiers = orderModifiers(mergeByName([].concat(defaultModifiers2, state.options.modifiers)));
2703
- state.orderedModifiers = orderedModifiers.filter(function(m) {
2704
- return m.enabled;
2705
- });
2706
- runModifierEffects();
2707
- return instance.update();
2708
- },
2709
- // Sync update – it will always be executed, even if not necessary. This
2710
- // is useful for low frequency updates where sync behavior simplifies the
2711
- // logic.
2712
- // For high frequency updates (e.g. `resize` and `scroll` events), always
2713
- // prefer the async Popper#update method
2714
- forceUpdate: function forceUpdate() {
2715
- if (isDestroyed) {
2716
- return;
2717
- }
2718
- var _state$elements = state.elements, reference3 = _state$elements.reference, popper3 = _state$elements.popper;
2719
- if (!areValidElements(reference3, popper3)) {
2720
- return;
2833
+ let isFirstUpdate = true;
2834
+ function handleObserve(entries) {
2835
+ const ratio = entries[0].intersectionRatio;
2836
+ if (ratio !== threshold) {
2837
+ if (!isFirstUpdate) {
2838
+ return refresh();
2721
2839
  }
2722
- state.rects = {
2723
- reference: getCompositeRect(reference3, getOffsetParent(popper3), state.options.strategy === "fixed"),
2724
- popper: getLayoutRect(popper3)
2725
- };
2726
- state.reset = false;
2727
- state.placement = state.options.placement;
2728
- state.orderedModifiers.forEach(function(modifier) {
2729
- return state.modifiersData[modifier.name] = Object.assign({}, modifier.data);
2730
- });
2731
- for (var index2 = 0; index2 < state.orderedModifiers.length; index2++) {
2732
- if (state.reset === true) {
2733
- state.reset = false;
2734
- index2 = -1;
2735
- continue;
2736
- }
2737
- var _state$orderedModifie = state.orderedModifiers[index2], fn2 = _state$orderedModifie.fn, _state$orderedModifie2 = _state$orderedModifie.options, _options = _state$orderedModifie2 === void 0 ? {} : _state$orderedModifie2, name = _state$orderedModifie.name;
2738
- if (typeof fn2 === "function") {
2739
- state = fn2({
2740
- state,
2741
- options: _options,
2742
- name,
2743
- instance
2744
- }) || state;
2745
- }
2840
+ if (!ratio) {
2841
+ timeoutId = setTimeout(() => {
2842
+ refresh(false, 1e-7);
2843
+ }, 1e3);
2844
+ } else {
2845
+ refresh(false, ratio);
2746
2846
  }
2747
- },
2748
- // Async and optimistically optimized update – it will not be executed if
2749
- // not necessary (debounced to run at most once-per-tick)
2750
- update: debounce(function() {
2751
- return new Promise(function(resolve) {
2752
- instance.forceUpdate();
2753
- resolve(state);
2754
- });
2755
- }),
2756
- destroy: function destroy() {
2757
- cleanupModifierEffects();
2758
- isDestroyed = true;
2759
2847
  }
2760
- };
2761
- if (!areValidElements(reference2, popper2)) {
2762
- return instance;
2848
+ isFirstUpdate = false;
2763
2849
  }
2764
- instance.setOptions(options).then(function(state2) {
2765
- if (!isDestroyed && options.onFirstUpdate) {
2766
- options.onFirstUpdate(state2);
2767
- }
2768
- });
2769
- function runModifierEffects() {
2770
- state.orderedModifiers.forEach(function(_ref) {
2771
- var name = _ref.name, _ref$options = _ref.options, options2 = _ref$options === void 0 ? {} : _ref$options, effect2 = _ref.effect;
2772
- if (typeof effect2 === "function") {
2773
- var cleanupFn = effect2({
2774
- state,
2775
- name,
2776
- instance,
2777
- options: options2
2778
- });
2779
- var noopFn = function noopFn2() {
2780
- };
2781
- effectCleanupFns.push(cleanupFn || noopFn);
2782
- }
2783
- });
2784
- }
2785
- function cleanupModifierEffects() {
2786
- effectCleanupFns.forEach(function(fn2) {
2787
- return fn2();
2850
+ try {
2851
+ io = new IntersectionObserver(handleObserve, {
2852
+ ...options,
2853
+ // Handle <iframe>s
2854
+ root: root.ownerDocument
2788
2855
  });
2789
- effectCleanupFns = [];
2790
- }
2791
- return instance;
2792
- };
2793
- }
2794
- var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$1];
2795
- var createPopper = /* @__PURE__ */ popperGenerator({
2796
- defaultModifiers
2797
- });
2798
- async function deregister(obj) {
2799
- const index2 = this.collection.findIndex((entry) => {
2800
- return entry.id === obj.id;
2801
- });
2802
- if (index2 >= 0) {
2803
- const entry = this.collection[index2];
2804
- if (entry.state === "opened") {
2805
- entry.close();
2856
+ } catch (e) {
2857
+ io = new IntersectionObserver(handleObserve, options);
2806
2858
  }
2807
- entry.popper.destroy();
2808
- deregisterEventListeners(entry);
2809
- Object.getOwnPropertyNames(entry).forEach((prop) => {
2810
- delete entry[prop];
2811
- });
2812
- this.collection.splice(index2, 1);
2859
+ io.observe(element);
2813
2860
  }
2814
- return this.collection;
2861
+ refresh(true);
2862
+ return cleanup;
2815
2863
  }
2816
- function deregisterEventListeners(entry) {
2817
- if (entry.__eventListeners) {
2818
- entry.__eventListeners.forEach((evObj) => {
2819
- evObj.el.forEach((el) => {
2820
- evObj.type.forEach((type) => {
2821
- entry[el].removeEventListener(type, evObj.listener, false);
2864
+ function autoUpdate(reference, floating, update, options) {
2865
+ if (options === void 0) {
2866
+ options = {};
2867
+ }
2868
+ const {
2869
+ ancestorScroll = true,
2870
+ ancestorResize = true,
2871
+ elementResize = typeof ResizeObserver === "function",
2872
+ layoutShift = typeof IntersectionObserver === "function",
2873
+ animationFrame = false
2874
+ } = options;
2875
+ const referenceEl = unwrapElement(reference);
2876
+ const ancestors = ancestorScroll || ancestorResize ? [...referenceEl ? getOverflowAncestors(referenceEl) : [], ...getOverflowAncestors(floating)] : [];
2877
+ ancestors.forEach((ancestor) => {
2878
+ ancestorScroll && ancestor.addEventListener("scroll", update, {
2879
+ passive: true
2880
+ });
2881
+ ancestorResize && ancestor.addEventListener("resize", update);
2882
+ });
2883
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
2884
+ let reobserveFrame = -1;
2885
+ let resizeObserver = null;
2886
+ if (elementResize) {
2887
+ resizeObserver = new ResizeObserver((_ref) => {
2888
+ let [firstEntry] = _ref;
2889
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
2890
+ resizeObserver.unobserve(floating);
2891
+ cancelAnimationFrame(reobserveFrame);
2892
+ reobserveFrame = requestAnimationFrame(() => {
2893
+ var _resizeObserver;
2894
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
2822
2895
  });
2823
- });
2896
+ }
2897
+ update();
2824
2898
  });
2825
- delete entry.__eventListeners;
2826
- }
2827
- return entry;
2899
+ if (referenceEl && !animationFrame) {
2900
+ resizeObserver.observe(referenceEl);
2901
+ }
2902
+ resizeObserver.observe(floating);
2903
+ }
2904
+ let frameId;
2905
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
2906
+ if (animationFrame) {
2907
+ frameLoop();
2908
+ }
2909
+ function frameLoop() {
2910
+ const nextRefRect = getBoundingClientRect(reference);
2911
+ if (prevRefRect && (nextRefRect.x !== prevRefRect.x || nextRefRect.y !== prevRefRect.y || nextRefRect.width !== prevRefRect.width || nextRefRect.height !== prevRefRect.height)) {
2912
+ update();
2913
+ }
2914
+ prevRefRect = nextRefRect;
2915
+ frameId = requestAnimationFrame(frameLoop);
2916
+ }
2917
+ update();
2918
+ return () => {
2919
+ var _resizeObserver2;
2920
+ ancestors.forEach((ancestor) => {
2921
+ ancestorScroll && ancestor.removeEventListener("scroll", update);
2922
+ ancestorResize && ancestor.removeEventListener("resize", update);
2923
+ });
2924
+ cleanupIo == null || cleanupIo();
2925
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
2926
+ resizeObserver = null;
2927
+ if (animationFrame) {
2928
+ cancelAnimationFrame(frameId);
2929
+ }
2930
+ };
2828
2931
  }
2932
+ const offset = offset$1;
2933
+ const shift = shift$1;
2934
+ const flip = flip$1;
2935
+ const arrow = arrow$1;
2936
+ const limitShift = limitShift$1;
2937
+ const computePosition = (reference, floating, options) => {
2938
+ const cache = /* @__PURE__ */ new Map();
2939
+ const mergedOptions = {
2940
+ platform,
2941
+ ...options
2942
+ };
2943
+ const platformWithCache = {
2944
+ ...mergedOptions.platform,
2945
+ _c: cache
2946
+ };
2947
+ return computePosition$1(reference, floating, {
2948
+ ...mergedOptions,
2949
+ platform: platformWithCache
2950
+ });
2951
+ };
2829
2952
  async function open(query) {
2830
2953
  const popover = getPopover.call(this, query);
2831
2954
  popover.el.inert = false;
@@ -2833,31 +2956,56 @@ async function open(query) {
2833
2956
  if (!popover.isTooltip) {
2834
2957
  popover.trigger.setAttribute("aria-expanded", "true");
2835
2958
  }
2836
- popover.config = getConfig(popover.el, this.settings);
2837
- popover.popper.setOptions({
2838
- placement: popover.config["placement"],
2839
- modifiers: [
2840
- { name: "eventListeners", enabled: true },
2841
- ...getModifiers(popover.config)
2842
- ]
2959
+ popover.getCustomProps();
2960
+ const middlewareOptions = getMiddlewareOptions(popover);
2961
+ const arrowEl = popover.el.querySelector(middlewareOptions.arrow.element);
2962
+ middlewareOptions.arrow.element = arrowEl ? arrowEl : void 0;
2963
+ popover.cleanup = autoUpdate(popover.trigger, popover.el, () => {
2964
+ computePosition(popover.trigger, popover.el, {
2965
+ placement: popover.getSetting("placement"),
2966
+ middleware: [
2967
+ flip(middlewareOptions.flip),
2968
+ shift({ ...middlewareOptions.shift, limiter: limitShift() }),
2969
+ offset(middlewareOptions.offset),
2970
+ arrow(middlewareOptions.arrow)
2971
+ ]
2972
+ }).then(({ x, y, placement, middlewareData }) => {
2973
+ if (!popover.el) {
2974
+ return;
2975
+ }
2976
+ applyPositionStyle(popover.el, x, y);
2977
+ if (middlewareOptions.arrow.element && middlewareData.arrow) {
2978
+ const { x: x2, y: y2 } = middlewareData.arrow;
2979
+ applyPositionStyle(middlewareOptions.arrow.element, x2, y2);
2980
+ }
2981
+ popover.el.setAttribute("data-floating-placement", placement);
2982
+ });
2843
2983
  });
2844
- popover.popper.update();
2845
2984
  popover.state = "opened";
2846
2985
  return popover;
2847
2986
  }
2848
- async function register(el, trigger) {
2849
- deregister.call(this, el);
2987
+ async function register(el, trigger, config = {}) {
2988
+ await deregister.call(this, el);
2850
2989
  const root = this;
2851
- const entry = {
2852
- id: el.id,
2990
+ const _isHovered = {
2991
+ el: false,
2992
+ trigger: false
2993
+ };
2994
+ const _customPropKeys = [
2995
+ "placement",
2996
+ "event",
2997
+ "offset",
2998
+ "flip-padding",
2999
+ "shift-padding",
3000
+ "arrow-padding",
3001
+ "toggle-delay"
3002
+ ];
3003
+ const entry = this.createEntry(el, { customPropKeys: _customPropKeys });
3004
+ Object.assign(entry, {
2853
3005
  state: "closed",
2854
- el,
2855
3006
  trigger,
2856
3007
  toggleDelayId: null,
2857
- popper: createPopper(trigger, el),
2858
- config: getConfig(el, this.settings),
2859
- get isTooltip() {
2860
- return !!el.closest(root.settings.selectorTooltip) || el.getAttribute("role") == "tooltip";
3008
+ cleanup: () => {
2861
3009
  },
2862
3010
  open() {
2863
3011
  return open.call(root, this);
@@ -2868,7 +3016,33 @@ async function register(el, trigger) {
2868
3016
  deregister() {
2869
3017
  return deregister.call(root, this);
2870
3018
  }
2871
- };
3019
+ });
3020
+ Object.defineProperties(entry, Object.getOwnPropertyDescriptors({
3021
+ set isHovered(event) {
3022
+ const state = event.type == "mouseenter" ? true : event.type == "mouseleave" ? false : void 0;
3023
+ if (state == void 0) return;
3024
+ switch (event.target) {
3025
+ case this.el:
3026
+ _isHovered.el = state;
3027
+ break;
3028
+ case this.trigger:
3029
+ _isHovered.trigger = state;
3030
+ break;
3031
+ }
3032
+ },
3033
+ get isHovered() {
3034
+ return _isHovered.el || _isHovered.trigger;
3035
+ },
3036
+ get isTooltip() {
3037
+ return !!el.closest(root.settings.selectorTooltip) || el.getAttribute("role") == "tooltip";
3038
+ }
3039
+ }));
3040
+ if (entry.isTooltip) {
3041
+ entry.settings.event = "hover";
3042
+ }
3043
+ entry.applySettings(config);
3044
+ entry.getDataConfig();
3045
+ entry.getCustomProps();
2872
3046
  if (entry.isTooltip) {
2873
3047
  entry.el.setAttribute("role", "tooltip");
2874
3048
  }
@@ -2876,6 +3050,9 @@ async function register(el, trigger) {
2876
3050
  entry.trigger.setAttribute("aria-expanded", "false");
2877
3051
  }
2878
3052
  registerEventListeners.call(this, entry);
3053
+ if (entry.getSetting("teleport")) {
3054
+ entry.teleport();
3055
+ }
2879
3056
  this.collection.push(entry);
2880
3057
  if (entry.el.classList.contains(this.settings.stateActive)) {
2881
3058
  await entry.open();
@@ -2883,25 +3060,26 @@ async function register(el, trigger) {
2883
3060
  } else {
2884
3061
  entry.el.inert = true;
2885
3062
  }
2886
- entry.popper.setOptions({
2887
- placement: entry.config["placement"]
2888
- });
2889
3063
  return entry;
2890
3064
  }
2891
3065
  function registerEventListeners(entry) {
2892
- if (!entry.__eventListeners) {
2893
- const eventType = entry.isTooltip ? "hover" : entry.config["event"];
3066
+ if (!entry._eventListeners) {
3067
+ const eventType = entry.getSetting("event");
2894
3068
  if (eventType === "hover") {
2895
- entry.__eventListeners = [{
2896
- el: ["trigger"],
3069
+ entry._eventListeners = [{
3070
+ el: ["el", "trigger"],
2897
3071
  type: ["mouseenter", "focus"],
2898
3072
  listener: handleMouseEnter.bind(this, entry)
2899
3073
  }, {
2900
3074
  el: ["el", "trigger"],
2901
3075
  type: ["mouseleave", "focusout"],
2902
3076
  listener: handleMouseLeave.bind(this, entry)
3077
+ }, {
3078
+ el: ["trigger"],
3079
+ type: ["click"],
3080
+ listener: handleTooltipClick.bind(this, entry)
2903
3081
  }];
2904
- entry.__eventListeners.forEach((evObj) => {
3082
+ entry._eventListeners.forEach((evObj) => {
2905
3083
  evObj.el.forEach((el) => {
2906
3084
  evObj.type.forEach((type) => {
2907
3085
  entry[el].addEventListener(type, evObj.listener, false);
@@ -2909,12 +3087,12 @@ function registerEventListeners(entry) {
2909
3087
  });
2910
3088
  });
2911
3089
  } else {
2912
- entry.__eventListeners = [{
3090
+ entry._eventListeners = [{
2913
3091
  el: ["trigger"],
2914
3092
  type: ["click"],
2915
3093
  listener: handleClick.bind(this, entry)
2916
3094
  }];
2917
- entry.__eventListeners.forEach((evObj) => {
3095
+ entry._eventListeners.forEach((evObj) => {
2918
3096
  evObj.el.forEach((el) => {
2919
3097
  evObj.type.forEach((type) => {
2920
3098
  entry[el].addEventListener(type, evObj.listener, false);
@@ -2927,19 +3105,18 @@ function registerEventListeners(entry) {
2927
3105
  }
2928
3106
  class Popover extends Collection {
2929
3107
  constructor(options) {
2930
- super();
3108
+ super({ ...defaults, ...options });
2931
3109
  __privateAdd(this, _handleKeydown3);
2932
- this.defaults = defaults;
2933
- this.settings = { ...this.defaults, ...options };
2934
3110
  this.trigger = null;
2935
3111
  __privateSet(this, _handleKeydown3, handleKeydown.bind(this));
2936
- if (this.settings.autoMount) this.mount();
2937
3112
  }
2938
3113
  get active() {
2939
3114
  return this.collection.find((popover) => popover.state == "opened");
2940
3115
  }
2941
- get activeTooltip() {
2942
- return this.collection.find((popover) => popover.state == "opened" && popover.isTooltip);
3116
+ get activeHover() {
3117
+ return this.collection.find((popover) => {
3118
+ return popover.state == "opened" && popover.getSetting("event") == "hover";
3119
+ });
2943
3120
  }
2944
3121
  async mount(options) {
2945
3122
  if (options) this.settings = { ...this.settings, ...options };
@@ -2974,10 +3151,10 @@ class Popover extends Collection {
2974
3151
  }
2975
3152
  document.removeEventListener("keydown", __privateGet(this, _handleKeydown3), false);
2976
3153
  }
2977
- register(query) {
3154
+ register(query, config = {}) {
2978
3155
  const els = getPopoverElements.call(this, query);
2979
3156
  if (els.error) return Promise.reject(els.error);
2980
- return register.call(this, els.popover, els.trigger);
3157
+ return register.call(this, els.popover, els.trigger, config);
2981
3158
  }
2982
3159
  deregister(query) {
2983
3160
  let obj = this.get(query.id || query);