slim-select 4.2.3 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/vue/index.js CHANGED
@@ -107,8 +107,6 @@ function g(e, t, n = c, r) {
107
107
  r?.addEventListener("abort", c, { once: !0 }), e.addEventListener("animationend", l), a = setTimeout(s, n);
108
108
  });
109
109
  }
110
- //#endregion
111
- //#region src/slim-select/settings.ts
112
110
  var _ = class {
113
111
  id = "";
114
112
  style = "";
@@ -152,7 +150,7 @@ var _ = class {
152
150
  modal;
153
151
  modalTitle;
154
152
  constructor(e) {
155
- e ||= {}, this.id = "ss-" + x(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 || e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
153
+ e ||= {}, this.id = "ss-" + x(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 && e.disabled, this.alwaysOpen = e.alwaysOpen !== void 0 && e.alwaysOpen, this.showSearch = e.showSearch === void 0 || e.showSearch, this.focusSearch = e.focusSearch === void 0 ? typeof window > "u" || window.innerWidth >= 768 : e.focusSearch, this.keepSearch = e.keepSearch !== void 0 && e.keepSearch, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.resultsText = e.resultsText || "{count} results available", this.deselectText = e.deselectText || "Clear", this.removeText = e.removeText || "Remove", this.searchHighlight = e.searchHighlight !== void 0 && e.searchHighlight, this.closeOnSelect = e.closeOnSelect === void 0 || e.closeOnSelect, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.contentWidth = e.contentWidth || "", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText === void 0 ? "Select Value" : e.placeholderText, this.allowDeselect = e.allowDeselect !== void 0 && e.allowDeselect, this.hideSelected = e.hideSelected !== void 0 && e.hideSelected, this.multiString = e.multiString !== void 0 && e.multiString, this.keepOrder = e.keepOrder !== void 0 && e.keepOrder, this.showOptionTooltips = e.showOptionTooltips !== void 0 && e.showOptionTooltips, this.minSelected = e.minSelected || 0, this.maxSelected = e.maxSelected || 1e3, this.timeoutDelay = e.timeoutDelay || 200, this.maxValuesShown = e.maxValuesShown || 20, this.maxValuesMessage = e.maxValuesMessage || "{number} selected", this.addableText = e.addableText || "Press \"Enter\" to add {value}", this.selectAll = e.selectAll !== void 0 && e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.unselectAllText = e.unselectAllText || "Unselect All", this.modal = e.modal || "mobile", this.modalTitle = e.modalTitle || "";
156
154
  }
157
155
  };
158
156
  //#endregion
@@ -599,6 +597,7 @@ var P = class {
599
597
  classes;
600
598
  positionObserver = null;
601
599
  positionObserverRaf = 0;
600
+ lastObservedContentHeight = -1;
602
601
  overflowShiftRaf = 0;
603
602
  modalElements = null;
604
603
  modalSessionActive = null;
@@ -943,6 +942,9 @@ var P = class {
943
942
  announce(e) {
944
943
  this.settings.showSearch && (this.content.status.textContent = e);
945
944
  }
945
+ repositionOpenContent() {
946
+ this.settings.isOpen && !this.isModalViewActive() && this.settings.contentPosition !== "relative" && this.content.main.classList.contains(this.classes.getFirst("dirAbove")) && this.moveContentAbove();
947
+ }
946
948
  moveContent() {
947
949
  if (!this.isModalViewActive()) {
948
950
  if (this.settings.contentPosition === "relative") {
@@ -961,21 +963,27 @@ var P = class {
961
963
  }
962
964
  }
963
965
  startPositionTracking() {
964
- this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), !(typeof ResizeObserver > "u") && (this.positionObserver = new ResizeObserver(() => {
965
- this.settings.isOpen && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
966
- this.moveContent();
966
+ this.settings.contentPosition !== "absolute" || this.isModalViewActive() || (this.stopPositionTracking(), typeof ResizeObserver < "u" && (this.lastObservedContentHeight = -1, this.positionObserver = new ResizeObserver((e) => {
967
+ if (!this.settings.isOpen) return;
968
+ let t = !1, n = !1;
969
+ for (let r of e) if (r.target === this.content.main) {
970
+ let e = r.contentRect.height;
971
+ e !== this.lastObservedContentHeight && (this.lastObservedContentHeight = e, t = !0);
972
+ } else n = !0;
973
+ (t || n) && (cancelAnimationFrame(this.positionObserverRaf), this.positionObserverRaf = requestAnimationFrame(() => {
974
+ n ? this.moveContent() : this.repositionOpenContent();
967
975
  }));
968
976
  }), this.observePositionTargets()));
969
977
  }
970
978
  stopPositionTracking() {
971
- cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null, this.cancelOverflowShift();
979
+ cancelAnimationFrame(this.positionObserverRaf), this.positionObserver?.disconnect(), this.positionObserver = null, this.lastObservedContentHeight = -1, this.cancelOverflowShift();
972
980
  }
973
981
  observePositionTargets() {
974
982
  if (!this.positionObserver) return;
975
983
  let e = /* @__PURE__ */ new Set(), t = (t) => {
976
- !t || e.has(t) || (e.add(t), this.positionObserver.observe(t));
984
+ t && !e.has(t) && (e.add(t), this.positionObserver.observe(t));
977
985
  };
978
- t(this.main.main);
986
+ t(this.main.main), t(this.content.main);
979
987
  let n = this.main.main.parentElement, r = this.settings.contentLocation;
980
988
  for (let e = 0; n && e < 8 && (t(n), n !== r); e++) n = n.parentElement;
981
989
  }
@@ -1104,12 +1112,12 @@ var P = class {
1104
1112
  renderError(e) {
1105
1113
  this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
1106
1114
  let t = document.createElement("div");
1107
- this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
1115
+ this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t), this.repositionOpenContent();
1108
1116
  }
1109
1117
  renderSearching() {
1110
1118
  this.optionsListIsFullData = !1, this.content.list.innerHTML = "";
1111
1119
  let e = document.createElement("div");
1112
- this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText);
1120
+ this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e), this.announce(this.settings.searchingText), this.repositionOpenContent();
1113
1121
  }
1114
1122
  renderOptions(e) {
1115
1123
  if (this.lastSearchFilterTerm = "", this.lastRenderedOptions = e.map((e) => e instanceof I ? [e] : e.options.map((e) => new I(e))).flat(), this.content.list.innerHTML = "", e.length === 0) {
@@ -1119,7 +1127,7 @@ var P = class {
1119
1127
  let t = this.settings.addableText.replace("{value}", this.content.search.input.value);
1120
1128
  e.innerHTML = t, this.announce(t);
1121
1129
  } else e.innerHTML = this.settings.searchText, this.announce(this.settings.searchText);
1122
- this.content.list.appendChild(e);
1130
+ this.content.list.appendChild(e), this.repositionOpenContent();
1123
1131
  return;
1124
1132
  }
1125
1133
  this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((e) => e.placeholder, !1, !1).length || this.store.addOption(new I({
@@ -1165,7 +1173,7 @@ var P = class {
1165
1173
  i.setAttribute("viewBox", "0 0 100 100"), this.addClasses(i, this.classes.arrow), t.appendChild(i);
1166
1174
  let o = document.createElementNS("http://www.w3.org/2000/svg", "path");
1167
1175
  i.appendChild(o), n.options.some((e) => e.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(t, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "open" ? (this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)) : n.closable === "close" && (this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)), r.addEventListener("click", (n) => {
1168
- n.preventDefault(), n.stopPropagation(), this.isClosableOptgroupOpen(e, t) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)) : (this.closeOtherClosableOptgroups(e), this.removeClasses(e, this.classes.close), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen));
1176
+ n.preventDefault(), n.stopPropagation(), this.isClosableOptgroupOpen(e, t) ? (this.removeClasses(e, this.classes.mainOpen), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.close), o.setAttribute("d", this.classes.arrowClose)) : (this.closeOtherClosableOptgroups(e), this.removeClasses(e, this.classes.close), this.removeClasses(t, this.classes.mainOpen), this.addClasses(e, this.classes.mainOpen), o.setAttribute("d", this.classes.arrowOpen)), this.repositionOpenContent();
1169
1177
  }), a.appendChild(t);
1170
1178
  }
1171
1179
  e.appendChild(r);
@@ -1173,7 +1181,7 @@ var P = class {
1173
1181
  }
1174
1182
  n instanceof I && t.appendChild(this.option(n));
1175
1183
  }
1176
- this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState();
1184
+ this.content.list.appendChild(t), this.setOptionsListFullData(e), this.announce(this.settings.resultsText.replace("{count}", String(this.lastRenderedOptions.length))), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1177
1185
  }
1178
1186
  canFilterOptionsInPlace() {
1179
1187
  return this.optionsListIsFullData ? this.content.list.querySelector("." + this.classes.getFirst("option")) !== null : !1;
@@ -1194,7 +1202,7 @@ var P = class {
1194
1202
  let o = a.placeholder || !a.display || a.selected && this.settings.hideSelected, s = t(a, n);
1195
1203
  o || !s ? (this.addClasses(e, this.classes.hide), this.removeClasses(e, this.classes.highlighted)) : (this.removeClasses(e, this.classes.hide), this.setOptionElementContent(e, a, n), r.push(a)), a.selected ? (this.addClasses(e, this.classes.selected), e.setAttribute("aria-selected", "true")) : (this.removeClasses(e, this.classes.selected), e.setAttribute("aria-selected", "false"));
1196
1204
  }
1197
- this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
1205
+ this.lastRenderedOptions = r, this.updateOptgroupVisibilityAfterSearch(n), r.length === 0 ? this.updateSearchResultsMessage(0, n) : (this.removeListSearchMessage(), this.announce(this.settings.resultsText.replace("{count}", String(r.length)))), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1198
1206
  }
1199
1207
  setOptionsListFullData(e) {
1200
1208
  let t = this.store.getDataOptions(!1), n = e.map((e) => e instanceof I ? [e] : e.options.map((e) => new I(e))).flat();
@@ -1266,7 +1274,7 @@ var P = class {
1266
1274
  let a = e.has(t);
1267
1275
  a ? (this.addClasses(r, this.classes.selected), r.setAttribute("aria-selected", "true"), n = r) : (this.removeClasses(r, this.classes.selected), r.setAttribute("aria-selected", "false")), this.settings.hideSelected && (a ? this.addClasses(r, this.classes.hide) : (this.removeClasses(r, this.classes.hide), i.display || this.addClasses(r, this.classes.hide)));
1268
1276
  }
1269
- !this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState();
1277
+ !this.settings.isMultiple && n ? this.main.main.setAttribute("aria-activedescendant", n.id) : !this.settings.isMultiple && e.size === 0 && this.main.main.removeAttribute("aria-activedescendant"), this.updateOptgroupSelectAllStates(), this.updateGlobalSelectAllState(), this.repositionOpenContent();
1270
1278
  }
1271
1279
  createSelectAllControl(e, t = !1) {
1272
1280
  let n = document.createElement("div");
@@ -1439,7 +1447,7 @@ var P = class {
1439
1447
  this.settings.contentPosition !== "relative" && (this.content.main.style.width = e.width + "px");
1440
1448
  return;
1441
1449
  }
1442
- t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t;
1450
+ t === "auto" ? this.content.main.style.minWidth = e.width + "px" : t.startsWith(">") ? this.content.main.style.minWidth = t.slice(1) : t.startsWith("<") ? this.content.main.style.maxWidth = t.slice(1) : this.content.main.style.width = t;
1443
1451
  }
1444
1452
  cancelOverflowShift() {
1445
1453
  this.overflowShiftRaf &&= (cancelAnimationFrame(this.overflowShiftRaf), 0);
@@ -1480,7 +1488,7 @@ var P = class {
1480
1488
  updateDeselectAll() {
1481
1489
  if (!this.store || !this.settings) return;
1482
1490
  let e = this.store.getSelectedOptions(), t = e && e.length > 0, n = this.settings.isMultiple, r = this.settings.allowDeselect, i = this.isAtMinSelected(), a = this.main.deselect.main, o = this.classes.hide;
1483
- r && !(n && !t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1491
+ r && (!n || t) && !i ? this.removeClasses(a, o) : this.addClasses(a, o);
1484
1492
  }
1485
1493
  };
1486
1494
  //#endregion
@@ -1987,10 +1995,10 @@ var W = class {
1987
1995
  }), this.globalEvents = new P({
1988
1996
  onDocumentClick: this.documentClick.bind(this),
1989
1997
  onWindowResize: () => {
1990
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1998
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
1991
1999
  },
1992
2000
  onWindowScroll: () => {
1993
- !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
2001
+ (this.settings.isOpen || this.settings.isFullOpen) && this.render.moveContent();
1994
2002
  },
1995
2003
  onVisibilityChange: () => {
1996
2004
  document.hidden && this.close({
@@ -2055,7 +2063,7 @@ var W = class {
2055
2063
  source: "api",
2056
2064
  selectionChanged: !1
2057
2065
  }) {
2058
- !this.settings.isOpen || this.settings.alwaysOpen || this.lifecycle.requestClose(e).then((e) => {
2066
+ this.settings.isOpen && !this.settings.alwaysOpen && this.lifecycle.requestClose(e).then((e) => {
2059
2067
  e && (this.settings.isOpen || (this.settings.isOpen = this.lifecycle.isOpen, this.settings.isFullOpen = this.lifecycle.isFullOpen));
2060
2068
  });
2061
2069
  }
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SlimSelectVue={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=class{main;placeholder;values;single;multiString;max;value;valueText;valueDelete;valueOut;deselect;deselectPath;arrow;arrowClose;arrowOpen;content;contentOpen;dirAbove;dirBelow;search;searchHighlighter;searching;status;addable;addablePath;list;optgroup;optgroupLabel;optgroupLabelText;optgroupActions;optgroupSelectAll;optgroupSelectAllBox;optgroupSelectAllCheck;optgroupClosable;option;optionDelete;highlighted;modalOverlay;modalDialog;modalTitle;modalClose;modalContent;mainOpen;close;selected;error;disabled;hide;constructor(e){e||={};let t=(e=``,t=``)=>`${e} ${t}`.trim();this.main=t(`ss-main`,e.main),this.placeholder=t(`ss-placeholder`,e.placeholder),this.values=t(`ss-values`,e.values),this.single=t(`ss-single`,e.single),this.multiString=t(`ss-multi-string`,e.multiString),this.max=t(`ss-max`,e.max),this.value=t(`ss-value`,e.value),this.valueText=t(`ss-value-text`,e.valueText),this.valueDelete=t(`ss-value-delete`,e.valueDelete),this.valueOut=t(`ss-value-out`,e.valueOut),this.deselect=t(`ss-deselect`,e.deselect),this.deselectPath=e.deselectPath||`M10,10 L90,90 M10,90 L90,10`,this.arrow=t(`ss-arrow`,e.arrow),this.arrowClose=e.arrowClose||`M10,30 L50,70 L90,30`,this.arrowOpen=e.arrowOpen||`M10,70 L50,30 L90,70`,this.content=t(`ss-content`,e.content),this.contentOpen=t(`ss-open`,e.contentOpen),this.dirAbove=t(`ss-dir-above`,e.dirAbove),this.dirBelow=t(`ss-dir-below`,e.dirBelow),this.search=t(`ss-search`,e.search),this.searchHighlighter=t(`ss-search-highlight`,e.searchHighlighter),this.searching=t(`ss-searching`,e.searching),this.status=t(`ss-status`,e.status),this.addable=t(`ss-addable`,e.addable),this.addablePath=e.addablePath||`M50,10 L50,90 M10,50 L90,50`,this.list=t(`ss-list`,e.list),this.optgroup=t(`ss-optgroup`,e.optgroup),this.optgroupLabel=t(`ss-optgroup-label`,e.optgroupLabel),this.optgroupLabelText=t(`ss-optgroup-label-text`,e.optgroupLabelText),this.optgroupActions=t(`ss-optgroup-actions`,e.optgroupActions),this.optgroupSelectAll=t(`ss-selectall`,e.optgroupSelectAll),this.optgroupSelectAllBox=e.optgroupSelectAllBox||`M15,15 L85,15 L85,85 L15,85 Z`,this.optgroupSelectAllCheck=e.optgroupSelectAllCheck||`M25,50 L42,68 L75,32`,this.optgroupClosable=t(`ss-closable`,e.optgroupClosable),this.option=t(`ss-option`,e.option),this.optionDelete=e.optionDelete||`M10,10 L90,90 M10,90 L90,10`,this.highlighted=t(`ss-highlighted`,e.highlighted),this.modalOverlay=t(`ss-modal-overlay`,e.modalOverlay),this.modalDialog=t(`ss-modal-dialog`,e.modalDialog),this.modalTitle=t(`ss-modal-title`,e.modalTitle),this.modalClose=t(`ss-modal-close`,e.modalClose),this.modalContent=t(`ss-modal-content`,e.modalContent),this.mainOpen=t(`ss-open`,e.mainOpen),this.close=t(`ss-close`,e.close),this.selected=t(`ss-selected`,e.selected),this.error=t(`ss-error`,e.error),this.disabled=t(`ss-disabled`,e.disabled),this.hide=t(`ss-hide`,e.hide)}getFirst(e){return this[e].split(` `)[0]}},r=200,i=[`transform`,`opacity`];function a(e,t=r){let n=e.trim();if(!n)return t;if(n.endsWith(`ms`)){let e=parseFloat(n);return Number.isNaN(e)?t:e}if(n.endsWith(`s`)){let e=parseFloat(n);return Number.isNaN(e)?t:e*1e3}let i=parseFloat(n);return Number.isNaN(i)?t:i}function o(e,t=r){return a(getComputedStyle(e).getPropertyValue(`--ss-animation-timing`).trim(),t)}function s(e,t,n=r){let i=o(e,n)+50;return t===void 0?i:Math.max(i,t)}function c(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function l(e){return e===void 0?null:new Set(Array.isArray(e)?e:[e])}function u(e,t,n=r,i){if(c()||i?.aborted)return Promise.resolve();let a=l(t);return new Promise(t=>{let r=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`transitionend`,l),i?.removeEventListener(`abort`,c),r&&clearTimeout(r),t())},c=()=>s(),l=t=>{t.target===e&&(a&&(!a.has(t.propertyName)||(a.delete(t.propertyName),a.size>0))||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`transitionend`,l),r=setTimeout(s,n)})}function d(e,t,n=r,i){return c()||i?.aborted?Promise.resolve():new Promise(r=>{let a=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`animationend`,l),i?.removeEventListener(`abort`,c),a&&clearTimeout(a),r())},c=()=>s(),l=n=>{n.target===e&&(t&&n.animationName!==t||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`animationend`,l),a=setTimeout(s,n)})}var f=class{id=``;style=``;class=[];isMultiple=!1;isOpen=!1;isFullOpen=!1;disabled;alwaysOpen;showSearch;focusSearch;keepSearch;ariaLabel;searchPlaceholder;searchText;searchingText;resultsText;deselectText;removeText;searchHighlight;closeOnSelect;contentLocation;contentPosition;contentWidth;openPosition;placeholderText;allowDeselect;hideSelected;multiString;keepOrder;showOptionTooltips;minSelected;maxSelected;timeoutDelay;maxValuesShown;maxValuesMessage;addableText;selectAll;selectAllText;unselectAllText;modal;modalTitle;constructor(e){e||={},this.id=`ss-`+g(),this.style=e.style||``,this.class=e.class||[],this.disabled=e.disabled!==void 0&&e.disabled,this.alwaysOpen=e.alwaysOpen!==void 0&&e.alwaysOpen,this.showSearch=e.showSearch===void 0||e.showSearch,this.focusSearch=e.focusSearch===void 0||e.focusSearch,this.keepSearch=e.keepSearch!==void 0&&e.keepSearch,this.ariaLabel=e.ariaLabel||`Combobox`,this.searchPlaceholder=e.searchPlaceholder||`Search...`,this.searchText=e.searchText||`No Results`,this.searchingText=e.searchingText||`Searching...`,this.resultsText=e.resultsText||`{count} results available`,this.deselectText=e.deselectText||`Clear`,this.removeText=e.removeText||`Remove`,this.searchHighlight=e.searchHighlight!==void 0&&e.searchHighlight,this.closeOnSelect=e.closeOnSelect===void 0||e.closeOnSelect,this.contentLocation=e.contentLocation||document.body,this.contentPosition=e.contentPosition||`absolute`,this.contentWidth=e.contentWidth||``,this.openPosition=e.openPosition||`auto`,this.placeholderText=e.placeholderText===void 0?`Select Value`:e.placeholderText,this.allowDeselect=e.allowDeselect!==void 0&&e.allowDeselect,this.hideSelected=e.hideSelected!==void 0&&e.hideSelected,this.multiString=e.multiString!==void 0&&e.multiString,this.keepOrder=e.keepOrder!==void 0&&e.keepOrder,this.showOptionTooltips=e.showOptionTooltips!==void 0&&e.showOptionTooltips,this.minSelected=e.minSelected||0,this.maxSelected=e.maxSelected||1e3,this.timeoutDelay=e.timeoutDelay||200,this.maxValuesShown=e.maxValuesShown||20,this.maxValuesMessage=e.maxValuesMessage||`{number} selected`,this.addableText=e.addableText||`Press "Enter" to add {value}`,this.selectAll=e.selectAll!==void 0&&e.selectAll,this.selectAllText=e.selectAllText||`Select All`,this.unselectAllText=e.unselectAllText||`Unselect All`,this.modal=e.modal||`mobile`,this.modalTitle=e.modalTitle||``}};function p(e){if(!e)return{};let t={};for(let n of Object.keys(e)){let r=e[n];r!==void 0&&(t[n]=r)}return t}function m(e){let t=e.cloneNode(!0);return t.querySelectorAll(`select, option, optgroup, textarea, input, button`).forEach(e=>e.remove()),t.textContent?.replace(/\s+/g,` `).trim()||``}function h(e){if(e.labels&&e.labels.length>0){let t=Array.from(e.labels).map(m).filter(Boolean);if(t.length>0)return[...new Set(t)].join(` `)}return e.getAttribute(`aria-label`)?.trim()||``}function g(){return Math.random().toString(36).substring(2,10)}function _(e,t){function n(e,n){return n&&e&&e.classList&&e.classList.contains(n)||n&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}function r(e,t){return!e||e===document?null:n(e,t)?e:r(e.parentNode,t)}return n(e,t)||r(e,t)}function v(e,t=50,n=!1){let r;return function(...i){let a=self,o=()=>{r=null,n||e.apply(a,i)},s=n&&!r;clearTimeout(r),r=setTimeout(o,t),s&&e.apply(a,i)}}function y(e,t){if(e.length!==t.length)return!1;let n=[...e].sort(),r=[...t].sort();return n.every((e,t)=>e===r[t])}var b=[`id`,`value`,`text`,`html`,`defaultSelected`,`selected`,`display`,`disabled`,`placeholder`,`class`,`style`,`mandatory`];function x(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}function S(e,t){switch(t){case`id`:return e.id||``;case`value`:return e.value===void 0?e.text||``:e.value||``;case`text`:return e.text||``;case`html`:return e.html||``;case`defaultSelected`:return e.defaultSelected??!1;case`selected`:return e.selected??!1;case`display`:return e.display??!0;case`disabled`:return e.disabled??!1;case`placeholder`:return e.placeholder??!1;case`class`:return e.class||``;case`style`:return e.style||``;case`mandatory`:return e.mandatory??!1;default:return e.data||{}}}function C(e){return!!e&&typeof e==`object`&&`label`in e&&`options`in e}function w(e,t){for(let n of b)if(S(e,n)!==S(t,n))return!1;return x(e.data||{},t.data||{})}function T(e,t){let n=e=>({id:e.id||``,label:e.label||``,selectAll:e.selectAll??!1,closable:e.closable||`off`}),r=n(e),i=n(t);if(r.id!==i.id||r.label!==i.label||r.selectAll!==i.selectAll||r.closable!==i.closable)return!1;let a=e.options||[],o=t.options||[];if(a.length!==o.length)return!1;for(let e=0;e<a.length;e++)if(!w(a[e],o[e]))return!1;return!0}function E(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n],a=C(r);if(a!==C(i))return!1;if(a){if(!T(r,i))return!1;continue}if(!w(r,i))return!1}return!0}function D(e){let t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,e=>`-`+e.toLowerCase());return e[0]===e[0].toUpperCase()?t.substring(1):t}function O(e,t=typeof window<`u`?window.innerWidth:768){return e===`on`||e===`mobile`&&t<768}var k=class{handlers;attached=!1;constructor(e){this.handlers=e}attach(e){this.attached||(this.attached=!0,window.addEventListener(`resize`,this.resizeHandler,!1),e.listenScroll&&window.addEventListener(`scroll`,this.scrollHandler,!1),document.addEventListener(`visibilitychange`,this.visibilityHandler))}attachDocumentClick(){document.addEventListener(`click`,this.handlers.onDocumentClick)}detachDocumentClick(){document.removeEventListener(`click`,this.handlers.onDocumentClick)}detach(e){this.attached&&(this.attached=!1,this.detachDocumentClick(),window.removeEventListener(`resize`,this.resizeHandler,!1),e.listenScroll&&window.removeEventListener(`scroll`,this.scrollHandler,!1),document.removeEventListener(`visibilitychange`,this.visibilityHandler))}resizeHandler=v(()=>{this.handlers.onWindowResize()});scrollHandler=v(()=>{this.handlers.onWindowScroll()});visibilityHandler=()=>{this.handlers.onVisibilityChange()}},A=class{handlers;options;state=`closed`;pendingTimer=null;waitResolvers=[];generation=0;animationAbort=null;constructor(e,t){this.handlers=e,this.options=t}get isOpen(){return this.state===`opening`||this.state===`open`}get isFullOpen(){return this.state===`open`}async requestOpen(){if(this.state===`opening`||this.state===`open`)return;this.cancelPending();let e=++this.generation;if(this.handlers.beforeOpen&&this.handlers.beforeOpen(),this.state=`opening`,await this.waitForPhase(`open`,e),e!==this.generation){this.state===`opening`&&(this.state=`closed`);return}this.state=`open`,this.handlers.afterOpen&&this.handlers.afterOpen(),this.handlers.onOpenReady&&this.handlers.onOpenReady()}async requestClose(e={source:`api`,selectionChanged:!1}){if(this.state===`closed`||this.state===`closing`||this.handlers.beforeClose&&this.handlers.beforeClose(e)===!1)return!1;this.cancelPending();let t=++this.generation;return this.handlers.onClose&&this.handlers.onClose(e),this.state=`closing`,await this.waitForPhase(`close`,t),t===this.generation&&(this.state=`closed`,this.handlers.afterClose&&this.handlers.afterClose(),this.handlers.onCloseReady&&this.handlers.onCloseReady(),!0)}cancelPending(){this.generation++,this.animationAbort?.abort(),this.animationAbort=null,this.pendingTimer&&=(clearTimeout(this.pendingTimer),null);let e=this.waitResolvers.splice(0);for(let t of e)t()}destroy(){this.cancelPending(),this.state=`closed`}waitForPhase(e,t){return new Promise(t=>{let n=!1,r=()=>{if(n)return;n=!0;let e=this.waitResolvers.indexOf(r);e!==-1&&this.waitResolvers.splice(e,1),t()};if(this.waitResolvers.push(r),this.options.waitForAnimation){let t=new AbortController;this.animationAbort=t,this.options.waitForAnimation(e,t.signal).catch(()=>void 0).finally(()=>{this.animationAbort===t&&(this.animationAbort=null),r()})}else this.pendingTimer=setTimeout(()=>{this.pendingTimer=null,r()},this.options.timeoutDelay)}).then(()=>{this.generation})}},j=class{id;value;text;html;defaultSelected;selected;display;disabled;placeholder;class;style;data;mandatory;constructor(e){this.id=!e.id||e.id===``?g():e.id,this.value=e.value===void 0?e.text||``:e.value||``,this.text=e.text||``,this.html=e.html||``,this.defaultSelected=e.defaultSelected!==void 0&&e.defaultSelected,this.selected=e.selected!==void 0&&e.selected,this.display=e.display===void 0||e.display,this.disabled=e.disabled!==void 0&&e.disabled,this.mandatory=e.mandatory!==void 0&&e.mandatory,this.placeholder=e.placeholder!==void 0&&e.placeholder,this.class=e.class||``,this.style=e.style||``,this.data=p(e.data)}},M=class{id;label;selectAll;closable;options;constructor(e){if(this.id=!e.id||e.id===``?g():e.id,this.label=e.label||``,this.selectAll=e.selectAll!==void 0&&e.selectAll,this.closable=e.closable||`off`,this.options=[],e.options)for(let t of e.options)this.options.push(new j(t))}},N=class{selectType=`single`;data=[];selectedOrder=[];catalog=null;constructor(e,t){this.selectType=e,this.setData(t),this.snapshotCatalog()}validateDataArray(e){if(!Array.isArray(e))return Error(`Data must be an array`);for(let t of e)if(t){if(t instanceof M||`label`in t){if(!(`label`in t))return Error(`Optgroup must have a label`);if(`options`in t&&t.options)for(let e of t.options){let t=this.validateOption(e);if(t)return t}}else if(t instanceof j||`text`in t){let e=this.validateOption(t);if(e)return e}else return Error(`Data object must be a valid optgroup or option`)}return null}validateOption(e){return`text`in e?null:Error(`Option must have a text`)}partialToFullData(e){let t=[];return e.forEach(e=>{if(e){if(e instanceof M||`label`in e){let n=[];`options`in e&&e.options&&e.options.forEach(e=>{n.push(new j(e))}),n.length>0&&t.push(new M(e))}(e instanceof j||`text`in e)&&t.push(new j(e))}}),t}snapshotCatalog(){this.catalog=this.cloneData(this.data)}getCatalogData(){return this.cloneData(this.catalog??this.data)}cloneData(e){return e.map(e=>e instanceof M?new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:e.options.map(e=>new j(e instanceof j?{...e}:e))}):new j({...e}))}optionMatchesSelected(e,t){return e.id===t.id||t.value!==``&&e.value!==``&&e.value===t.value}findOptionInData(e,t){for(let n of e){if(n instanceof j){if(this.optionMatchesSelected(n,t))return n;continue}for(let e of n.options)if(this.optionMatchesSelected(e,t))return e}return null}setData(e,t=!1){let n=this.partialToFullData(e),r=[];if(t){r=this.getSelectedOptions();let e=[];r.forEach(t=>{this.findOptionInData(n,t)||e.push(t)}),this.data=[...e,...n];let t=this.selectType===`single`&&r.length===0,i=r.map(e=>{let t=this.findOptionInData(this.data,e);return t?t.id:e.id});this.setSelectedBy(`id`,i,t)}else this.data=n;!t&&this.selectType===`single`&&this.setSelectedBy(`id`,this.getSelected(),!1)}getData(e=!0){return this.filter(null,!0,e)}getDataOptions(e=!0){return this.filter(null,!1,e)}addOption(e,t=!1){if(t){let t=[new j(e)];this.setData(t.concat(this.getData()))}else this.setData(this.getData().concat(new j(e)))}setSelectedBy(e,t,n=!1){let r=null,i=!1,a=[];for(let n of this.data){if(n instanceof M)for(let o of n.options){r||=o;let n=o[e]||``;o.selected=!i&&t.includes(n),o.selected&&(a.push(o),this.selectType===`single`&&(i=!0))}n instanceof j&&(r||=n,n.selected=!i&&t.includes(n[e]),n.selected&&(a.push(n),this.selectType===`single`&&(i=!0)))}this.selectType===`single`&&r&&!i&&!n&&(r.selected=!0,a.push(r));let o=t.map(t=>a.find(n=>n[e]===t)?.id||``);this.selectedOrder=o}getSelected(){return this.getSelectedOptions().map(e=>e.id)}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}getSelectedOptions(){let e=[];for(let t of this.data)if(t instanceof M)for(let n of t.options)n.selected&&e.push(n);else t.selected&&e.push(t);return e}getOptgroupByID(e){for(let t of this.data)if(t instanceof M&&t.id===e)return t;return null}getOptionByID(e){for(let t of this.data)if(t instanceof M){for(let n of t.options)if(n.id===e)return n}else if(t.id===e)return t;return null}getSelectType(){return this.selectType}getFirstOption(){let e=null;for(let t of this.data)if(t instanceof M?e=t.options[0]:t instanceof j&&(e=t),e)break;return e}search(e,t){return e=e.trim(),e===``?this.getData(!1):this.filter(n=>t(n,e),!0,!1)}createOptgroupView(e,t){let n=new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:[]});return n.options=t,n}filter(e,t,n=!0){let r=[];return this.data.forEach(i=>{if(i instanceof M){let a=[];if(i.options.forEach(i=>{(!e||e(i))&&(t?a.push(n?new j(i):i):r.push(n?new j(i):i))}),a.length>0){if(n){let e=new M(i);e.options=a,r.push(e)}else r.push(this.createOptgroupView(i,a))}}i instanceof j&&(!e||e(i))&&r.push(n?new j(i):i)}),r}selectedOrderOptions(e){let t=[];return this.selectedOrder.forEach(n=>{let r=e.find(e=>e.id===n);r&&t.push(r)}),e.forEach(e=>{let n=!1;t.forEach(t=>{if(e.id===t.id){n=!0;return}}),n||t.push(e)}),t}},P=class{settings;store;callbacks;lastSelectedOption;lastRenderedOptions;optionsListIsFullData=!1;lastSearchFilterTerm=``;main;content;classes;positionObserver=null;positionObserverRaf=0;overflowShiftRaf=0;modalElements=null;modalSessionActive=null;bodyScrollLocked=!1;savedBodyOverflow=``;constructor(e,t,n,r){this.store=n,this.settings=e,this.classes=t,this.callbacks=r,this.lastSelectedOption=null,this.lastRenderedOptions=[],this.main=this.mainDiv(),this.content=this.contentDiv(),this.updateClassStyles(),this.updateAriaAttributes(),this.settings.contentPosition!==`relative`&&(this.content.main.style.top=`-9999px`,this.content.main.style.left=`-9999px`,this.content.main.style.margin=`0`,this.content.main.style.width=`auto`),this.settings.contentLocation&&this.settings.contentLocation.appendChild(this.content.main),this.settings.modal!==`off`&&!this.settings.alwaysOpen&&(this.modalElements=this.createModalElements(),document.body.appendChild(this.modalElements.overlay))}requestClose(e,t){this.callbacks.close({source:e,option:t?.option,selectionChanged:t?.selectionChanged??!1})}selectionChanged(e,t){if(e.length!==t.length)return!0;let n=e.map(e=>e.id).sort(),r=t.map(e=>e.id).sort();return n.some((e,t)=>e!==r[t])}closeOnSingleSelectReclick(e){this.settings.closeOnSelect&&this.requestClose(`select`,{option:e,selectionChanged:!1})}addClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.add(t.trim())}removeClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.remove(t.trim())}enable(){this.removeClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`false`),this.content.search.input.disabled=!1}disable(){this.addClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`true`),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute(`d`,this.classes.arrowOpen),this.main.main.setAttribute(`aria-expanded`,`true`);let e=this.resolveModalView();if(!e){let e=this.settings.openPosition===`up`?this.classes.dirAbove:this.classes.dirBelow;this.addClasses(this.main.main,e),this.addClasses(this.content.main,e)}this.addClasses(this.content.main,this.classes.contentOpen),this.content.search.input.removeAttribute(`aria-hidden`),e?this.showModal():this.moveContent();let t=this.store.getSelectedOptions();if(t.length){let e=t[t.length-1].id,n=this.content.list.querySelector(`[data-id="`+e+`"]`);n&&this.ensureElementInView(this.content.list,n)}}isModalViewActive(){return this.modalSessionActive===!0}resolveModalView(){return this.settings.alwaysOpen||this.settings.modal===`off`||!this.modalElements?!1:(this.modalSessionActive===null&&(this.modalSessionActive=O(this.settings.modal)),this.modalSessionActive)}createModalElements(){let e=document.createElement(`div`);this.addClasses(e,this.classes.modalOverlay),this.addClasses(e,this.classes.hide),e.dataset.id=this.settings.id;let t=document.createElement(`div`);this.addClasses(t,this.classes.modalDialog),t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`);let n=null;this.settings.modalTitle?(n=document.createElement(`div`),this.addClasses(n,this.classes.modalTitle),n.id=`${this.settings.id}-modal-title`,n.textContent=this.settings.modalTitle,t.setAttribute(`aria-labelledby`,n.id)):t.setAttribute(`aria-label`,this.settings.ariaLabel);let r=document.createElement(`button`);r.type=`button`,this.addClasses(r,this.classes.modalClose),r.setAttribute(`aria-label`,`Close`),r.onclick=e=>{e.stopPropagation(),this.requestClose(`modal`)};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),r.appendChild(i),e.onclick=t=>{t.target===e&&this.requestClose(`modal`)},n&&t.appendChild(n),e.appendChild(t),{overlay:e,dialog:t,closeButton:r,title:n}}showModal(){this.modalElements&&(this.modalElements.dialog.appendChild(this.content.main),this.addClasses(this.content.main,this.classes.modalContent),this.content.main.appendChild(this.modalElements.closeButton),this.content.main.style.top=``,this.content.main.style.left=``,this.content.main.style.margin=``,this.content.main.style.width=``,this.removeClasses(this.modalElements.overlay,this.classes.hide),requestAnimationFrame(()=>{this.modalElements&&this.addClasses(this.modalElements.overlay,this.classes.contentOpen)}),this.lockBodyScroll())}lockBodyScroll(){this.bodyScrollLocked||=(this.savedBodyOverflow=document.body.style.overflow,document.body.style.overflow=`hidden`,!0)}unlockBodyScroll(){this.bodyScrollLocked&&(document.body.style.overflow=this.savedBodyOverflow,this.bodyScrollLocked=!1,this.savedBodyOverflow=``)}restoreContentOffscreen(){this.settings.contentLocation&&this.settings.contentLocation.appendChild(this.content.main),this.settings.contentPosition!==`relative`&&(this.content.main.style.top=`-9999px`,this.content.main.style.left=`-9999px`,this.content.main.style.margin=`0`,this.content.main.style.width=`auto`)}finalizeModalClose(){this.modalElements&&this.content.main.parentElement===this.modalElements.dialog&&(this.addClasses(this.modalElements.overlay,this.classes.hide),this.removeClasses(this.modalElements.overlay,this.classes.contentOpen),this.removeClasses(this.content.main,this.classes.modalContent),this.modalElements.closeButton.remove(),this.restoreContentOffscreen(),this.unlockBodyScroll())}waitForAnimation(e,t){let n=s(this.content.main,this.settings.timeoutDelay);return u(this.content.main,i,n,t)}close(){this.main.main.setAttribute(`aria-expanded`,`false`),this.main.arrow.path.setAttribute(`d`,this.classes.arrowClose);let e=this.modalSessionActive===!0;this.removeClasses(this.content.main,this.classes.contentOpen),e||(this.removeClasses(this.main.main,this.classes.dirAbove),this.removeClasses(this.main.main,this.classes.dirBelow)),e&&this.modalElements&&this.removeClasses(this.modalElements.overlay,this.classes.contentOpen),this.modalSessionActive=null,this.content.search.input.setAttribute(`aria-hidden`,`true`),this.main.main.removeAttribute(`aria-activedescendant`),this.clearValueChipHighlight()}clearDirectionClasses(){this.removeClasses(this.main.main,this.classes.dirAbove),this.removeClasses(this.main.main,this.classes.dirBelow),this.removeClasses(this.content.main,this.classes.dirAbove),this.removeClasses(this.content.main,this.classes.dirBelow)}updateClassStyles(){if(this.main.main.className=``,this.main.main.removeAttribute(`style`),this.content.main.className=``,this.content.main.removeAttribute(`style`),this.addClasses(this.main.main,this.classes.main),this.addClasses(this.content.main,this.classes.content),this.settings.style!==``&&(this.main.main.style.cssText=this.settings.style,this.content.main.style.cssText=this.settings.style),this.settings.class.length)for(let e of this.settings.class)e.trim()!==``&&(this.main.main.classList.add(e.trim()),this.content.main.classList.add(e.trim()));(this.settings.contentPosition===`relative`||this.settings.contentPosition===`fixed`)&&this.content.main.classList.add(`ss-`+this.settings.contentPosition)}updateAriaAttributes(){let e=this.content.list.id;this.main.main.role=`combobox`,this.main.main.setAttribute(`aria-haspopup`,`listbox`),this.main.main.setAttribute(`aria-controls`,e),this.main.main.setAttribute(`aria-expanded`,`false`),this.content.list.setAttribute(`role`,`listbox`),this.content.list.setAttribute(`aria-label`,this.settings.ariaLabel+` listbox`),this.settings.isMultiple&&this.content.list.setAttribute(`aria-multiselectable`,`true`),this.content.search.input.setAttribute(`aria-controls`,e)}mainDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id,e.setAttribute(`aria-label`,this.settings.ariaLabel),e.tabIndex=0,e.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return this.callbacks.open(),e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`Tab`:return this.requestClose(`tab`),!0;case`Enter`:case` `:this.callbacks.open();let t=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return t&&t.click(),!1;case`Escape`:return this.requestClose(`escape`),!1}return e.key.length===1&&this.callbacks.open(),!0},e.onclick=e=>{this.settings.disabled||(this.settings.isOpen?this.requestClose(`toggle`):this.callbacks.open())};let t=document.createElement(`div`);this.addClasses(t,this.classes.values),e.appendChild(t);let n=document.createElement(`div`);this.addClasses(n,this.classes.deselect),n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,this.settings.deselectText),n.setAttribute(`tabindex`,`0`);let r=this.store?.getSelectedOptions();!this.settings.allowDeselect||this.settings.isMultiple&&r&&r.length<=0||this.isAtMinSelected()?this.addClasses(n,this.classes.hide):this.removeClasses(n,this.classes.hide),n.onclick=e=>{if(e.stopPropagation(),this.settings.disabled||this.settings.isMultiple&&this.isAtMinSelected())return;let t=!0,n=this.store.getSelectedOptions(),r=[],i=``;if(this.settings.isMultiple){let e=this.settings.minSelected,t=this.store.getSelected();if(e>0&&t.length>e)i=this.getMinimumSelectionIds(),r=n.filter(e=>i.includes(e.id));else if(e<=0)i=[];else return}if(this.callbacks.beforeChange&&(t=this.callbacks.beforeChange(r,n)===!0),t){if(this.settings.isMultiple)this.callbacks.setSelected(i,!1),this.updateDeselectAll();else{let e=this.store.getFirstOption(),t=e?e.id:``;this.callbacks.setSelected(t,!1)}this.settings.closeOnSelect&&this.requestClose(`deselect`,{selectionChanged:!0}),this.callbacks.afterChange&&this.callbacks.afterChange(this.store.getSelectedOptions())}},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n.click())};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),n.appendChild(i),e.appendChild(n);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);this.addClasses(o,this.classes.arrow),o.setAttribute(`viewBox`,`0 0 100 100`);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return s.setAttribute(`d`,this.classes.arrowClose),this.settings.alwaysOpen&&this.addClasses(o,this.classes.hide),o.appendChild(s),e.appendChild(o),{main:e,values:t,deselect:{main:n,svg:i,path:a},arrow:{main:o,path:s}}}mainFocus(e){e!==`click`&&this.main.main.focus({preventScroll:!0})}placeholder(){let e=this.store.filter(e=>e.placeholder,!1,!1),t=this.settings.placeholderText;e.length&&(e[0].html===``?e[0].text!==``&&(t=e[0].text):t=e[0].html);let n=document.createElement(`div`);return this.addClasses(n,this.classes.placeholder),n.innerHTML=t,n}renderValues(){if(!this.settings.isMultiple){this.renderSingleValue();return}this.renderMultipleValues(),this.updateDeselectAll()}renderSingleValue(){let e=this.store.filter(e=>e.selected&&!e.placeholder,!1,!1),t=e.length>0?e[0]:null;if(!t)this.main.values.innerHTML=this.placeholder().outerHTML;else{let e=document.createElement(`div`);this.addClasses(e,this.classes.single),t.html?e.innerHTML=t.html:e.innerText=t.text,this.main.values.innerHTML=e.outerHTML}!this.settings.allowDeselect||!e.length?this.addClasses(this.main.deselect.main,this.classes.hide):this.removeClasses(this.main.deselect.main,this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter(e=>e.selected&&e.display,!1,!1);if(t.length===0){this.main.values.innerHTML=this.placeholder().outerHTML;return}{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`placeholder`));e&&e.remove()}if(this.settings.multiString){let e=t;this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e));let n=document.createElement(`div`);this.addClasses(n,this.classes.multiString),n.textContent=e.map(e=>e.text).join(`, `),this.settings.showOptionTooltips&&n.setAttribute(`title`,n.textContent),this.main.values.innerHTML=n.outerHTML;return}if(t.length>this.settings.maxValuesShown){let e=document.createElement(`div`);this.addClasses(e,this.classes.max),e.textContent=this.settings.maxValuesMessage.replace(`{number}`,t.length.toString()),this.main.values.innerHTML=e.outerHTML;return}{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`max`));e&&e.remove()}this.settings.keepOrder&&(t=this.store.selectedOrderOptions(t));let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=i.getAttribute(`data-id`);a&&(t.filter(e=>e.id===a,!1).length||n.push(i))}let r=s(this.content.main,this.settings.timeoutDelay);for(let e of n)this.addClasses(e,this.classes.valueOut),d(e,`ss-valueOut`,r).then(()=>{this.main.values.hasChildNodes()&&this.main.values.contains(e)&&this.main.values.removeChild(e)});e=this.main.values.childNodes;for(let n=0;n<t.length;n++){let r=!0;for(let i=0;i<e.length;i++)t[n].id===String(e[i].dataset.id)&&(r=!1);r&&(this.settings.keepOrder||e.length===0?this.main.values.appendChild(this.multipleValue(t[n])):n===0?this.main.values.insertBefore(this.multipleValue(t[n]),e[n]):e[n-1].insertAdjacentElement(`afterend`,this.multipleValue(t[n])))}this.updateMultipleValueDeleteVisibility()}isAtMinSelected(){return this.settings.isMultiple&&this.settings.minSelected>0&&this.store.getSelectedOptions().length<=this.settings.minSelected}getMinimumSelectionIds(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.slice(0,this.settings.minSelected).map(e=>e.id)}getValueChips(){return!this.settings.isMultiple||this.settings.multiString?[]:Array.from(this.main.values.querySelectorAll(`.`+this.classes.getFirst(`value`))).filter(e=>{if(e.classList.contains(this.classes.getFirst(`valueOut`)))return!1;let t=e.querySelector(`.`+this.classes.getFirst(`valueDelete`));return!!t&&!t.classList.contains(this.classes.getFirst(`hide`))})}getHighlightedValueChip(){return this.getValueChips().find(e=>e.classList.contains(this.classes.getFirst(`highlighted`)))??null}clearValueChipHighlight(){for(let e of Array.from(this.main.values.querySelectorAll(`.`+this.classes.getFirst(`value`))))this.removeClasses(e,this.classes.highlighted)}highlightValueChip(e){this.clearValueChipHighlight(),e&&this.addClasses(e,this.classes.highlighted)}navigateValueChips(e){let t=this.getValueChips();if(t.length===0)return!1;let n=this.getHighlightedValueChip(),r=n?t.indexOf(n):-1;return e===`left`?(r===-1?this.highlightValueChip(t[t.length-1]):r>0&&this.highlightValueChip(t[r-1]),!0):r!==-1&&(r<t.length-1?this.highlightValueChip(t[r+1]):this.clearValueChipHighlight(),!0)}deleteValueChip(e=!1){let t=this.getValueChips();if(t.length===0)return!1;let n=this.getHighlightedValueChip();if(e&&!n)return!1;let r=n??t[t.length-1],i=r.querySelector(`.`+this.classes.getFirst(`valueDelete`));if(!i)return!1;let a=t.indexOf(r),o=n?t[a-1]??t[a+1]??null:null;return i.click(),o&&o!==r&&this.main.values.contains(o)?this.highlightValueChip(o):this.clearValueChipHighlight(),!0}updateMultipleValueDeleteVisibility(){if(!this.settings.isMultiple||this.settings.multiString)return;let e=!this.isAtMinSelected(),t=this.main.values.querySelectorAll(`.`+this.classes.getFirst(`valueDelete`));for(let n of t)e?this.removeClasses(n,this.classes.hide):this.addClasses(n,this.classes.hide)}multipleValue(e){let t=document.createElement(`div`);this.addClasses(t,this.classes.value),t.dataset.id=e.id;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.valueText),n.textContent=e.text,t.appendChild(n),!e.mandatory){let n=document.createElement(`div`);this.addClasses(n,this.classes.valueDelete),n.setAttribute(`tabindex`,`0`),n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,`${this.settings.removeText} ${e.text}`),this.isAtMinSelected()&&this.addClasses(n,this.classes.hide),n.onclick=t=>{if(t.preventDefault(),t.stopPropagation(),this.settings.disabled)return;let n=!0,r=this.store.getSelectedOptions(),i=r.filter(t=>t.selected&&t.id!==e.id,!0);if(!(this.settings.minSelected&&i.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(n=this.callbacks.beforeChange(i,r)===!0),n)){let e=[];for(let t of i){if(t instanceof M)for(let n of t.options)n.id&&e.push(n.id);t instanceof j&&e.push(t.id)}this.callbacks.setSelected(e,!1),this.settings.closeOnSelect&&this.requestClose(`deselect`,{selectionChanged:!0}),this.callbacks.afterChange&&this.callbacks.afterChange(i),this.updateDeselectAll(),this.updateMultipleValueDeleteVisibility()}};let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.optionDelete),r.appendChild(i),n.appendChild(r),t.appendChild(n),n.onkeydown=e=>{e.key===`Enter`&&n.click()}}return t}contentDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id;let t=this.searchDiv();e.appendChild(t.main);let n=document.createElement(`div`);this.addClasses(n,this.classes.status),n.setAttribute(`aria-live`,`polite`),n.setAttribute(`aria-atomic`,`true`),n.setAttribute(`role`,`status`),e.appendChild(n);let r=this.listDiv();return e.appendChild(r),{main:e,search:t,status:n,list:r}}announce(e){this.settings.showSearch&&(this.content.status.textContent=e)}moveContent(){if(!this.isModalViewActive()){if(this.settings.contentPosition===`relative`){this.moveContentBelow();return}if(this.settings.openPosition===`down`){this.moveContentBelow();return}if(this.settings.openPosition===`up`){this.moveContentAbove();return}this.putContent()===`up`?this.moveContentAbove():this.moveContentBelow()}}startPositionTracking(){this.settings.contentPosition!==`absolute`||this.isModalViewActive()||(this.stopPositionTracking(),!(typeof ResizeObserver>`u`)&&(this.positionObserver=new ResizeObserver(()=>{this.settings.isOpen&&(cancelAnimationFrame(this.positionObserverRaf),this.positionObserverRaf=requestAnimationFrame(()=>{this.moveContent()}))}),this.observePositionTargets()))}stopPositionTracking(){cancelAnimationFrame(this.positionObserverRaf),this.positionObserver?.disconnect(),this.positionObserver=null,this.cancelOverflowShift()}observePositionTargets(){if(!this.positionObserver)return;let e=new Set,t=t=>{!t||e.has(t)||(e.add(t),this.positionObserver.observe(t))};t(this.main.main);let n=this.main.main.parentElement,r=this.settings.contentLocation;for(let e=0;n&&e<8&&(t(n),n!==r);e++)n=n.parentElement}searchDiv(){let e=document.createElement(`div`),t=document.createElement(`input`),n=document.createElement(`div`);this.addClasses(e,this.classes.search);let r={main:e,input:t},i=this.settings.selectAll&&this.settings.isMultiple;this.settings.showSearch||(t.readOnly=!0,i?this.addClasses(t,this.classes.hide):this.addClasses(e,this.classes.hide)),t.type=`search`,t.id=`${this.settings.id}-search`,t.placeholder=this.settings.searchPlaceholder,t.tabIndex=-1,t.setAttribute(`aria-label`,this.settings.searchPlaceholder),t.setAttribute(`aria-autocomplete`,`list`),t.setAttribute(`autocapitalize`,`off`),t.setAttribute(`autocomplete`,`off`),t.setAttribute(`autocorrect`,`off`),t.setAttribute(`aria-hidden`,`true`);let a=v(()=>{this.callbacks.search(t.value)},100);if(t.oninput=e=>{e.target.value!==``&&this.clearValueChipHighlight(),a()},t.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return this.clearValueChipHighlight(),e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`ArrowLeft`:case`ArrowRight`:return t.value!==``||!this.navigateValueChips(e.key===`ArrowLeft`?`left`:`right`)||(e.preventDefault(),!1);case`Backspace`:return t.value!==``||!this.deleteValueChip()||(e.preventDefault(),!1);case`Delete`:return t.value!==``||!this.getHighlightedValueChip()||!this.deleteValueChip(!0)||(e.preventDefault(),!1);case`Tab`:return this.requestClose(`tab`),!0;case`Escape`:return this.requestClose(`escape`),!1;case`Enter`:let r=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return r?(r.click(),!1):!this.callbacks.addable||(n.click(),!1)}return e.key.length===1&&this.clearValueChipHighlight(),!0},e.appendChild(t),i){let t=this.createSelectAllControl(()=>this.toggleGlobalSelectAll());e.appendChild(t),r.selectAll=t}if(this.callbacks.addable){this.addClasses(n,this.classes.addable);let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);t.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.addablePath),t.appendChild(i),n.appendChild(t),n.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;let t=this.content.search.input.value.trim();if(t===``){this.content.search.input.focus();return}let n=e=>{let t=new j(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.id),this.callbacks.setSelected(e,!0)}else this.callbacks.setSelected([t.id],!0);if(this.callbacks.search(``),this.settings.closeOnSelect){let e=o(this.content.main);setTimeout(()=>{this.requestClose(`select`,{selectionChanged:!0})},e)}},r=this.callbacks.addable(t);r!==!1&&r!=null&&(r instanceof Promise?r.then(e=>{typeof e==`string`?n({text:e,value:e}):r instanceof Error?this.renderError(r.message):n(e)}):typeof r==`string`?n({text:r,value:r}):r instanceof Error?this.renderError(r.message):n(r))},e.appendChild(n),r.addable={main:n,svg:t,path:i}}return r}searchFocus(){this.content.search.input.focus({preventScroll:!0})}getOptions(e=!1,t=!1,n=!1){let r=`.`+this.classes.getFirst(`option`);return e&&(r+=`:not(.`+this.classes.getFirst(`placeholder`)+`)`),t&&(r+=`:not(.`+this.classes.getFirst(`disabled`)+`)`),n&&(r+=`:not(.`+this.classes.getFirst(`hide`)+`)`),Array.from(this.content.list.querySelectorAll(r))}highlight(e){let t=this.getOptions(!0,!0,!0);if(t.length===0)return;if(t.length===1&&!t[0].classList.contains(this.classes.getFirst(`highlighted`))){this.addClasses(t[0],this.classes.highlighted);return}let n=!1;for(let e of t)e.classList.contains(this.classes.getFirst(`highlighted`))&&(n=!0);if(!n){for(let e of t)if(e.classList.contains(this.classes.getFirst(`selected`))){this.addClasses(e,this.classes.highlighted);break}}for(let n=0;n<t.length;n++)if(t[n].classList.contains(this.classes.getFirst(`highlighted`))){let r=t[n];this.removeClasses(r,this.classes.highlighted);let i=r.parentElement;if(i&&i.classList.contains(this.classes.getFirst(`mainOpen`))){let e=i.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}let a=t[e===`down`?n+1<t.length?n+1:0:n-1>=0?n-1:t.length-1];this.addClasses(a,this.classes.highlighted),this.ensureElementInView(this.content.list,a),a.id&&this.main.main.setAttribute(`aria-activedescendant`,a.id);let o=a.parentElement;if(o&&o.classList.contains(this.classes.getFirst(`close`))){let e=o.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}return}let r=t[e===`down`?0:t.length-1];this.addClasses(r,this.classes.highlighted),r.id&&this.main.main.setAttribute(`aria-activedescendant`,r.id),this.ensureElementInView(this.content.list,r)}listDiv(){let e=document.createElement(`div`);this.addClasses(e,this.classes.list);let t=this.settings.id+`-list`;return e.id=t,e.dataset.id=t,e}renderError(e){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let t=document.createElement(`div`);this.addClasses(t,this.classes.error),t.textContent=e,this.content.list.appendChild(t)}renderSearching(){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let e=document.createElement(`div`);this.addClasses(e,this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e),this.announce(this.settings.searchingText)}renderOptions(e){if(this.lastSearchFilterTerm=``,this.lastRenderedOptions=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat(),this.content.list.innerHTML=``,e.length===0){this.optionsListIsFullData=!1;let e=document.createElement(`div`);if(this.addClasses(e,this.classes.search),this.callbacks.addable){let t=this.settings.addableText.replace(`{value}`,this.content.search.input.value);e.innerHTML=t,this.announce(t)}else e.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(e);return}this.settings.allowDeselect&&!this.settings.isMultiple&&(this.store.filter(e=>e.placeholder,!1,!1).length||this.store.addOption(new j({text:``,value:``,selected:!1,placeholder:!0}),!0));let t=document.createDocumentFragment();for(let n of e){if(n instanceof M){let e=document.createElement(`div`);this.addClasses(e,this.classes.optgroup);let r=document.createElement(`div`);this.addClasses(r,this.classes.optgroupLabel),e.appendChild(r);let i=document.createElement(`div`);this.addClasses(i,this.classes.optgroupLabelText),i.textContent=n.label,r.appendChild(i);let a=document.createElement(`div`);if(this.addClasses(a,this.classes.optgroupActions),r.appendChild(a),this.settings.isMultiple&&n.selectAll){let e=this.createSelectAllControl(()=>{let e=this.store.getSelected();if(this.isOptgroupAllSelected(n.options,new Set(e))){let t=e.filter(e=>{for(let t of n.options)if(e===t.id)return!1;return!0});this.callbacks.setSelected(t,!0);return}{let t=n.options.map(e=>e.id).filter(e=>e!==void 0),r=e.concat(t);for(let e of n.options)e.id&&!this.store.getOptionByID(e.id)&&this.callbacks.addOption(new j(e));this.callbacks.setSelected(r,!0);return}},this.isOptgroupAllSelected(n.options));a.appendChild(e)}if(n.closable!==`off`){let t=document.createElement(`div`);this.addClasses(t,this.classes.optgroupClosable);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),this.addClasses(i,this.classes.arrow),t.appendChild(i);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.appendChild(o),n.options.some(e=>e.selected)||this.content.search.input.value.trim()!==``?(this.addClasses(t,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`open`?(this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`close`&&(this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)),r.addEventListener(`click`,n=>{n.preventDefault(),n.stopPropagation(),this.isClosableOptgroupOpen(e,t)?(this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)):(this.closeOtherClosableOptgroups(e),this.removeClasses(e,this.classes.close),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen))}),a.appendChild(t)}e.appendChild(r);for(let r of n.options)e.appendChild(this.option(new j(r))),t.appendChild(e)}n instanceof j&&t.appendChild(this.option(n))}this.content.list.appendChild(t),this.setOptionsListFullData(e),this.announce(this.settings.resultsText.replace(`{count}`,String(this.lastRenderedOptions.length))),this.updateGlobalSelectAllState()}canFilterOptionsInPlace(){return this.optionsListIsFullData?this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null:!1}resetSearchFilterState(){this.lastSearchFilterTerm=``}filterOptionsInPlace(e,t){let n=e.trim();if(n===this.lastSearchFilterTerm)return;this.lastSearchFilterTerm=n;let r=[],i=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`));for(let e of i){let i=e.dataset.id;if(!i)continue;let a=this.store.getOptionByID(i);if(!a)continue;let o=a.placeholder||!a.display||a.selected&&this.settings.hideSelected,s=t(a,n);o||!s?(this.addClasses(e,this.classes.hide),this.removeClasses(e,this.classes.highlighted)):(this.removeClasses(e,this.classes.hide),this.setOptionElementContent(e,a,n),r.push(a)),a.selected?(this.addClasses(e,this.classes.selected),e.setAttribute(`aria-selected`,`true`)):(this.removeClasses(e,this.classes.selected),e.setAttribute(`aria-selected`,`false`))}this.lastRenderedOptions=r,this.updateOptgroupVisibilityAfterSearch(n),r.length===0?this.updateSearchResultsMessage(0,n):(this.removeListSearchMessage(),this.announce(this.settings.resultsText.replace(`{count}`,String(r.length)))),this.updateOptgroupSelectAllStates(),this.updateGlobalSelectAllState()}setOptionsListFullData(e){let t=this.store.getDataOptions(!1),n=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat();if(n.length!==t.length){this.optionsListIsFullData=!1;return}let r=new Set(t.map(e=>e.id));this.optionsListIsFullData=n.every(e=>r.has(e.id))}isClosableOptgroupOpen(e,t){return e.classList.contains(this.classes.getFirst(`close`))?!1:e.classList.contains(this.classes.getFirst(`mainOpen`))||t.classList.contains(this.classes.getFirst(`mainOpen`))}closeClosableOptgroup(e){let t=e.querySelector(`.`+this.classes.getFirst(`optgroupClosable`));if(!t||e.classList.contains(this.classes.getFirst(`close`)))return;this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close);let n=t.querySelector(`path`);n&&n.setAttribute(`d`,this.classes.arrowClose)}closeOtherClosableOptgroups(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t)n!==e&&this.closeClosableOptgroup(n)}updateOptgroupVisibilityAfterSearch(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),r=!1;for(let e of t)if(!e.classList.contains(this.classes.getFirst(`hide`))){r=!0;break}if(!r){this.addClasses(n,this.classes.hide);continue}this.removeClasses(n,this.classes.hide),e!==``&&(this.removeClasses(n,this.classes.close),this.addClasses(n,this.classes.mainOpen))}}updateSearchResultsMessage(e,t){if(this.removeListSearchMessage(),e>0)return;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.search),this.callbacks.addable){let e=this.settings.addableText.replace(`{value}`,t);n.innerHTML=e,this.announce(e)}else n.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(n)}removeListSearchMessage(){this.content.list.querySelectorAll(`.`+this.classes.getFirst(`search`)).forEach(e=>e.remove())}setOptionElementContent(e,t,n){let r=n.trim();this.settings.searchHighlight&&r!==``?e.innerHTML=this.highlightText(t.html===``?t.text:t.html,r,this.classes.searchHighlighter):t.html===``?e.textContent=t.text:e.innerHTML=t.html,this.settings.showOptionTooltips&&e.textContent?e.setAttribute(`title`,e.textContent):e.removeAttribute(`title`)}hasRenderedOptions(){return this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null}canUpdateOptionSelectionInPlace(){return this.content.search.input.value.trim()===``&&this.hasRenderedOptions()}updateOptionSelection(){let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`)),n=null;for(let r of t){let t=r.dataset.id;if(!t)continue;let i=this.store.getOptionByID(t);if(!i)continue;let a=e.has(t);a?(this.addClasses(r,this.classes.selected),r.setAttribute(`aria-selected`,`true`),n=r):(this.removeClasses(r,this.classes.selected),r.setAttribute(`aria-selected`,`false`)),this.settings.hideSelected&&(a?this.addClasses(r,this.classes.hide):(this.removeClasses(r,this.classes.hide),i.display||this.addClasses(r,this.classes.hide)))}!this.settings.isMultiple&&n?this.main.main.setAttribute(`aria-activedescendant`,n.id):!this.settings.isMultiple&&e.size===0&&this.main.main.removeAttribute(`aria-activedescendant`),this.updateOptgroupSelectAllStates(),this.updateGlobalSelectAllState()}createSelectAllControl(e,t=!1){let n=document.createElement(`div`);this.addClasses(n,this.classes.optgroupSelectAll),n.setAttribute(`role`,`checkbox`),n.setAttribute(`aria-checked`,t?`true`:`false`),n.setAttribute(`aria-label`,this.selectAllLabel(t)),n.tabIndex=-1,t&&this.addClasses(n,this.classes.selected);let r=document.createElement(`span`);r.textContent=this.selectAllLabel(t),n.appendChild(r);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),i.setAttribute(`aria-hidden`,`true`),n.appendChild(i);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);a.setAttribute(`d`,this.classes.optgroupSelectAllBox),i.appendChild(a);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return o.setAttribute(`d`,this.classes.optgroupSelectAllCheck),i.appendChild(o),n.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e()}),n}getSelectableOptions(){return this.store.getDataOptions(!1).filter(e=>!e.disabled&&!e.placeholder&&e.display)}isGlobalAllSelected(e){let t=this.getSelectableOptions();if(t.length===0)return!1;let n=e||new Set(this.store.getSelected());for(let e of t)if(!n.has(e.id))return!1;return!0}toggleGlobalSelectAll(){let e=this.getSelectableOptions(),t=new Set(this.store.getSelected());if(this.isGlobalAllSelected(t)){let t=new Set(e.map(e=>e.id)),n=this.store.getSelected().filter(e=>!t.has(e));this.callbacks.setSelected(n,!0);return}this.callbacks.setSelected(e.map(e=>e.id),!0)}updateGlobalSelectAllState(){let e=this.content.search.selectAll;if(!e||!this.settings.isMultiple||!this.settings.selectAll)return;let t=this.isGlobalAllSelected();t?this.addClasses(e,this.classes.selected):this.removeClasses(e,this.classes.selected),e.setAttribute(`aria-checked`,t?`true`:`false`),e.setAttribute(`aria-label`,this.selectAllLabel(t));let n=e.querySelector(`span`);n&&(n.textContent=this.selectAllLabel(t))}updateOptgroupSelectAllStates(){if(!this.settings.isMultiple)return;let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelector(`.`+this.classes.getFirst(`optgroupSelectAll`));if(!t)continue;let r=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),i=r.length>0;for(let t of r){let n=t.dataset.id;if(!n||!e.has(n)){i=!1;break}}i?this.addClasses(t,this.classes.selected):this.removeClasses(t,this.classes.selected),t.setAttribute(`aria-checked`,i?`true`:`false`),t.setAttribute(`aria-label`,this.selectAllLabel(i));let a=t.querySelector(`span`);a&&(a.textContent=this.selectAllLabel(i))}}selectAllLabel(e){return e?this.settings.unselectAllText:this.settings.selectAllText}isOptgroupAllSelected(e,t){if(e.length===0)return!1;for(let n of e)if(!(t?n.id&&t.has(n.id):n.selected))return!1;return!0}option(e){if(e.placeholder){let e=document.createElement(`div`);return this.addClasses(e,this.classes.option),this.addClasses(e,this.classes.hide),e}let t=document.createElement(`div`);return t.dataset.id=e.id,t.id=this.settings.id+`-`+e.id,this.addClasses(t,this.classes.option),t.setAttribute(`role`,`option`),e.class&&e.class.split(` `).forEach(e=>{t.classList.add(e)}),e.style&&(t.style.cssText=e.style),this.setOptionElementContent(t,e,this.content.search.input.value),e.display||this.addClasses(t,this.classes.hide),e.disabled&&this.addClasses(t,this.classes.disabled),e.selected&&this.settings.hideSelected&&this.addClasses(t,this.classes.hide),e.selected?(this.addClasses(t,this.classes.selected),t.setAttribute(`aria-selected`,`true`),this.main.main.setAttribute(`aria-activedescendant`,t.id)):(this.removeClasses(t,this.classes.selected),t.setAttribute(`aria-selected`,`false`)),t.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation();let n=this.store.getSelected(),r=t.currentTarget,i=String(r.dataset.id),a=this.store.getOptionByID(i)??e,o=n.includes(i),s=t.ctrlKey||t.metaKey;if(e.disabled)return;if(!this.settings.isMultiple&&o&&!this.settings.allowDeselect){this.closeOnSingleSelectReclick(a);return}if(o&&a.mandatory){this.closeOnSingleSelectReclick(a);return}if(this.settings.isMultiple&&this.settings.maxSelected<=n.length&&!o||this.settings.isMultiple&&this.settings.minSelected>=n.length&&o&&!s)return;let c=!1,l=this.store.getSelectedOptions(),u=[];if(this.settings.isMultiple){let n=l.some(e=>e.id===i);if(t.shiftKey&&this.lastSelectedOption){let t=this.lastRenderedOptions,n=t.findIndex(e=>e.id===this.lastSelectedOption.id),r=t.findIndex(t=>t.id===e.id);if(n>=0&&r>=0){let e=Math.min(n,r),i=Math.max(n,r),a=t.slice(e,i+1).filter(e=>!l.find(t=>t.id===e.id));u=l.length+a.length<=this.settings.maxSelected?l.concat(a):l}else u=l}else u=n?l.filter(e=>e.id!==i):l.concat(a),this.lastSelectedOption=a}if(this.settings.isMultiple||(u=o?[]:[a]),this.callbacks.beforeChange||(c=!0),this.callbacks.beforeChange&&(c=this.callbacks.beforeChange(u,l)!==!1),c){this.store.getOptionByID(i)||this.callbacks.addOption(e),this.callbacks.setSelected(u.map(e=>e.id),!1);let n=t.ctrlKey||t.metaKey||t.shiftKey;this.settings.closeOnSelect&&!(this.settings.isMultiple&&n)&&this.requestClose(`select`,{option:a,selectionChanged:this.selectionChanged(l,u)}),this.callbacks.afterChange&&this.callbacks.afterChange(u)}}),t}destroy(){this.stopPositionTracking(),this.modalElements?(this.unlockBodyScroll(),this.content.main.parentElement===this.modalElements.dialog&&this.restoreContentOffscreen(),this.modalElements.overlay.remove(),this.modalElements=null):this.bodyScrollLocked&&this.unlockBodyScroll(),this.main.main.remove(),this.content.main.remove(),this.removeDetachedInstanceDom()}removeDetachedInstanceDom(){let e=this.settings.id,t=this.classes.getFirst(`main`),n=this.classes.getFirst(`content`),r=this.classes.getFirst(`modalOverlay`);document.querySelectorAll(`[data-id="${e}"]`).forEach(e=>{(e.classList.contains(t)||e.classList.contains(n)||e.classList.contains(r))&&e.remove()})}highlightText(e,t,n){let r=t.trim();if(r===``)return e;let i=r.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=document.createElement(`div`);a.innerHTML=e;let o=e=>{if(e.nodeType===Node.TEXT_NODE){let t=e.textContent||``,r=RegExp(`(`+i+`)`,`i`);if(r.test(t)){let i=document.createElement(`span`);t.split(r).forEach((e,t)=>{if(e&&r.test(e)){let t=document.createElement(`mark`);t.className=n,t.textContent=e,i.appendChild(t)}else e&&i.appendChild(document.createTextNode(e))}),e.parentNode?.replaceChild(i,e)}}else e.nodeType===Node.ELEMENT_NODE&&Array.from(e.childNodes).forEach(e=>o(e))};return Array.from(a.childNodes).forEach(e=>o(e)),a.innerHTML}setContentDirection(e){let t=e===`above`,n=t?this.classes.dirAbove:this.classes.dirBelow,r=t?this.classes.dirBelow:this.classes.dirAbove;if(this.removeClasses(this.main.main,r),this.addClasses(this.main.main,n),this.removeClasses(this.content.main,r),this.addClasses(this.content.main,n),t){let e=this.main.main.offsetHeight,t=this.content.main.offsetHeight;this.content.main.style.margin=`-`+(e+t-1)+`px 0px 0px 0px`}else this.content.main.style.margin=`-1px 0px 0px 0px`}setContentPosition(){let e=this.main.main.getBoundingClientRect();if(this.settings.contentPosition===`relative`){this.applyContentWidth(e);return}this.cancelOverflowShift();let t,n;this.settings.contentPosition===`fixed`?(t=e.top+e.height,n=e.left):(t=e.top+window.scrollY+e.height,n=e.left+window.scrollX),this.content.main.style.top=t+`px`,this.content.main.style.left=n+`px`,this.applyContentWidth(e);let r=this.getKnownContentWidth(e);if(r!==null){this.content.main.style.left=this.adjustLeftForOverflow(n,e.left,r)+`px`;return}this.overflowShiftRaf=requestAnimationFrame(()=>{this.overflowShiftRaf=0,this.applyOverflowShiftFromMeasure()})}applyContentWidth(e){let t=this.settings.contentWidth;if(this.content.main.style.width=``,this.content.main.style.minWidth=``,this.content.main.style.maxWidth=``,!t){this.settings.contentPosition!==`relative`&&(this.content.main.style.width=e.width+`px`);return}t.startsWith(`>`)?this.content.main.style.minWidth=t.slice(1):t.startsWith(`<`)?this.content.main.style.maxWidth=t.slice(1):this.content.main.style.width=t}cancelOverflowShift(){this.overflowShiftRaf&&=(cancelAnimationFrame(this.overflowShiftRaf),0)}getKnownContentWidth(e){let t=this.settings.contentWidth;if(!t)return e.width;if(t.startsWith(`>`)||t.startsWith(`<`)||t.includes(`%`))return null;let n=parseFloat(t);return Number.isNaN(n)?null:n}adjustLeftForOverflow(e,t,n){let r=t+n;if(r<=window.innerWidth)return e;let i=e-(r-(window.innerWidth-20));return this.settings.contentPosition===`fixed`?Math.max(0,i):Math.max(window.scrollX,i)}applyOverflowShiftFromMeasure(){let e=this.content.main.getBoundingClientRect().right;if(e<=window.innerWidth)return;let t=e-(window.innerWidth-20),n=(parseFloat(this.content.main.style.left)||0)-t;this.settings.contentPosition===`fixed`?this.content.main.style.left=Math.max(0,n)+`px`:this.content.main.style.left=Math.max(window.scrollX,n)+`px`}moveContentAbove(){this.setContentDirection(`above`),this.setContentPosition()}moveContentBelow(){this.setContentDirection(`below`),this.setContentPosition()}ensureElementInView(e,t){let n=e.scrollTop+e.offsetTop,r=n+e.clientHeight,i=t.offsetTop,a=i+t.clientHeight;i<n?e.scrollTop-=n-i:a>r&&(e.scrollTop+=a-r)}putContent(){let e=this.main.main.offsetHeight,t=this.main.main.getBoundingClientRect(),n=this.content.main.offsetHeight;return window.innerHeight-(t.top+e)<=n&&t.top>n?`up`:`down`}updateDeselectAll(){if(!this.store||!this.settings)return;let e=this.store.getSelectedOptions(),t=e&&e.length>0,n=this.settings.isMultiple,r=this.settings.allowDeselect,i=this.isAtMinSelected(),a=this.main.deselect.main,o=this.classes.hide;r&&!(n&&!t)&&!i?this.removeClasses(a,o):this.addClasses(a,o)}};function F(e,t){let n={classChanged:!1,disabledChanged:!1,optgroupOptionChanged:!1,selectionChanged:!1};for(let r of e){if(r.target===t&&(r.attributeName===`disabled`&&(n.disabledChanged=!0),r.attributeName===`class`&&(n.classChanged=!0),r.type===`childList`)){for(let e of Array.from(r.addedNodes))if(e.nodeName===`OPTION`&&e.value===t.value){n.selectionChanged=!0;break}n.optgroupOptionChanged=!0}(r.target.nodeName===`OPTGROUP`||r.target.nodeName===`OPTION`)&&(n.optgroupOptionChanged=!0)}return n}var I=class{select;onValueChange;onClassChange;onDisabledChange;onOptionsChange;onLabelClick;listen=!1;observer=null;isUpdating=!1;pendingOptionsChange=null;preventNativeSelect=null;preventNativeSelectMousedown=null;preventNativeSelectFocus=null;restoreAriaHiddenOnBlur=null;constructor(e){this.select=e,this.valueChange=this.valueChange.bind(this),this.select.addEventListener(`change`,this.valueChange,{passive:!0}),this.observer=new MutationObserver(this.observeCall.bind(this)),this.changeListen(!0)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){this.select.tabIndex=-1,this.select.style.position=`absolute`,this.select.style.width=`1px`,this.select.style.height=`1px`,this.select.style.opacity=`0`,this.select.style.overflow=`hidden`,this.select.style.pointerEvents=`none`,this.select.style.margin=`0`,this.select.style.padding=`0`,this.select.style.borderWidth=`0`,this.select.style.clipPath=`inset(50%)`,document.activeElement!==this.select&&this.select.setAttribute(`aria-hidden`,`true`),this.preventNativeSelect||(this.preventNativeSelect=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectMousedown=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectFocus=e=>{this.select.removeAttribute(`aria-hidden`),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.restoreAriaHiddenOnBlur=()=>{this.select.setAttribute(`aria-hidden`,`true`)},this.select.addEventListener(`click`,this.preventNativeSelect,{capture:!0,passive:!1}),this.select.addEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0,passive:!1}),this.select.addEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0,passive:!1}),this.select.addEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0,passive:!0}))}showUI(){this.select.removeAttribute(`tabindex`),this.select.style.position=``,this.select.style.width=``,this.select.style.height=``,this.select.style.opacity=``,this.select.style.overflow=``,this.select.style.pointerEvents=``,this.select.style.margin=``,this.select.style.padding=``,this.select.style.borderWidth=``,this.select.style.clipPath=``,this.select.removeAttribute(`aria-hidden`),this.preventNativeSelect&&=(this.select.removeEventListener(`click`,this.preventNativeSelect,{capture:!0}),null),this.preventNativeSelectMousedown&&=(this.select.removeEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0}),null),this.preventNativeSelectFocus&&=(this.select.removeEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0}),null),this.restoreAriaHiddenOnBlur&&=(this.select.removeEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0}),null)}changeListen(e){this.listen=e,e&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),e||this.observer&&this.observer.disconnect()}valueChange(e){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedOptions()),!0}observeCall(e){if(!this.listen)return;let{classChanged:t,disabledChanged:n,optgroupOptionChanged:r,selectionChanged:i}=F(e,this.select),a=i;if(t&&this.onClassChange&&this.onClassChange(this.select.className.split(` `)),n&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),r&&this.clearLeftoverHiddenDisplay(e),r&&this.onOptionsChange){if(this.isUpdating){if(this.select.options.length>0){let e=this.getData();e.length>0&&(this.pendingOptionsChange=e)}a&&this.select.dispatchEvent(new Event(`change`));return}this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0),a=!1}a&&this.select.dispatchEvent(new Event(`change`))}getData(){let e=[],t=this.select.childNodes;for(let n of t)n.nodeName===`OPTGROUP`&&e.push(this.getDataFromOptgroup(n)),n.nodeName===`OPTION`&&e.push(this.getDataFromOption(n));return e}getDataFromOptgroup(e){let t={id:e.id,label:e.label,selectAll:e.dataset?e.dataset.selectall===`true`:!1,closable:e.dataset?e.dataset.closable:`off`,options:[]},n=e.childNodes;for(let e of n)e.nodeName===`OPTION`&&t.options.push(this.getDataFromOption(e));return t}clearLeftoverHiddenDisplay(e){for(let t of e){if(t.target.nodeName!==`OPTION`||t.attributeName!==`hidden`)continue;let e=t.target;!e.hidden&&e.style.display===`none`&&(e.style.display=``)}}getDataFromOption(e){let t=e.hidden||e.hasAttribute(`hidden`);return{id:e.id,value:e.value,text:e.text,html:e.dataset&&e.dataset.html?e.dataset.html:``,defaultSelected:e.defaultSelected,selected:e.selected,display:e.style.display!==`none`&&!t,disabled:e.disabled,mandatory:e.dataset?e.dataset.mandatory===`true`:!1,placeholder:e.dataset.placeholder===`true`,class:e.className,style:e.style.cssText,data:p(e.dataset)}}getSelectedOptions(){let e=[],t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}return e}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}hasOptionValues(e){if(e.length===0)return!0;let t=new Set(Array.from(this.select.options).map(e=>e.value));return e.every(e=>t.has(e))}setSelected(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0)}setSelectedByValue(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0)}updateSelect(e,t,n){this.changeListen(!1),e&&(this.select.dataset.id=e),t&&(this.select.style.cssText=t),n&&(this.select.className=``,n.forEach(e=>{e.trim()!==``&&this.select.classList.add(e.trim())})),this.changeListen(!0)}updateOptions(e){if(!e||e.length===0)return;this.isUpdating=!0,this.pendingOptionsChange=null,this.changeListen(!1);let t=this.getSelectedValues();this.select.innerHTML=``;for(let t of e)t instanceof M&&this.select.appendChild(this.createOptgroup(t)),t instanceof j&&this.select.appendChild(this.createOption(t));if(y(t,this.getSelectedValues())||this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0),this.isUpdating=!1,this.pendingOptionsChange!==null){let e=this.pendingOptionsChange;e.length>0&&this.onOptionsChange?(this.pendingOptionsChange=null,this.changeListen(!1),this.onOptionsChange(e),this.changeListen(!0)):this.pendingOptionsChange=null}}createOptgroup(e){let t=document.createElement(`optgroup`);if(t.id=e.id,t.label=e.label,e.selectAll&&(t.dataset.selectAll=`true`),e.closable!==`off`&&(t.dataset.closable=e.closable),e.options)for(let n of e.options)t.appendChild(this.createOption(n));return t}createOption(e){let t=document.createElement(`option`);return t.id=e.id,t.value=e.value,t.textContent=e.text,e.html!==``&&t.setAttribute(`data-html`,e.html),t.defaultSelected=e.defaultSelected,t.selected=e.selected,e.disabled&&(t.disabled=!0),t.hidden=!e.display,e.placeholder&&t.setAttribute(`data-placeholder`,`true`),e.mandatory&&t.setAttribute(`data-mandatory`,`true`),e.class&&e.class.split(` `).forEach(e=>{t.classList.add(e)}),e.data&&typeof e.data==`object`&&Object.keys(e.data).forEach(n=>{t.setAttribute(`data-`+D(n),e.data[n])}),t}setupLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{if(e.__slimSelectLabelHandler)return;let t=e=>{let t=e.target,n=_(t,this.select.dataset.id);e.preventDefault(),!n&&this.onLabelClick&&this.onLabelClick()};e.__slimSelectLabelHandler=t,e.addEventListener(`click`,t,{capture:!0,passive:!1})})}removeLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{let t=e.__slimSelectLabelHandler;t&&(e.removeEventListener(`click`,t,{capture:!0}),delete e.__slimSelectLabelHandler)})}destroy(){this.changeListen(!1),this.select.removeEventListener(`change`,this.valueChange),this.preventNativeSelect&&=(this.select.removeEventListener(`click`,this.preventNativeSelect,{capture:!0}),null),this.preventNativeSelectMousedown&&=(this.select.removeEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0}),null),this.preventNativeSelectFocus&&=(this.select.removeEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0}),null),this.restoreAriaHiddenOnBlur&&=(this.select.removeEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0}),null),this.observer&&=(this.observer.disconnect(),null),this.removeLabelHandlers(),delete this.select.dataset.id,this.showUI()}};function L(e,t){return E(e.getData(!1),t)}function R(e,t){let n=Array.isArray(t)?t:[t],r=e.getDataOptions(!1),i=[];for(let e of n){if(r.find(t=>t.id==e)){i.push(e);continue}for(let t of r.filter(t=>t.value==e))i.push(t.id)}return i}var z=class{deps;queue=[];flushScheduled=!1;isSyncing=!1;constructor(e){this.deps=e}enqueue(e){if(this.queue.push(e),e.source===`native`){this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flush()));return}this.isSyncing||this.flush()}flush(){if(this.flushScheduled=!1,this.queue.length===0)return;let e=this.coalesceBatch(this.queue);this.queue=[],this.isSyncing=!0;try{for(let t of e)this.applyChange(t)}finally{this.isSyncing=!1,this.queue.length>0&&this.flush()}}coalesceBatch(e){let t=e.some(e=>e.type===`structure`),n=e.some(e=>e.type===`addOption`);if(t||n){let t=e.filter(e=>e.type===`structure`||e.type===`addOption`),n=t[t.length-1];return n?.type===`structure`?[n]:t}let r=e.filter(e=>e.type===`selection`);return r.length>0?[r[r.length-1]]:e}applyChange(e){switch(e.type){case`structure`:this.applyStructure(e.data,e.source,e.preserveSelection,e.isSearchResult);break;case`selection`:this.applySelection(e.values,e.source,e.runAfterChange!==!1);break;case`addOption`:this.applyAddOption(e.option)}}applyStructure(e,t,n=!1,r=!1){let{store:i,select:a,render:o,events:s}=this.deps;if(!r&&L(i,e))return;let c=i.getSelected(),l=i.validateDataArray(e);if(l){s.error?s.error(l):this.deps.onError&&this.deps.onError(l);return}i.setData(e,n);let u=i.getData(!1);r||i.snapshotCatalog(),r||a.updateOptions(u),o.renderValues(),o.renderOptions(u),s.afterChange&&!y(c,i.getSelected())&&s.afterChange(i.getSelectedOptions())}syncNativeSelection(){let{store:e,select:t}=this.deps,n=e.getSelectedOptions(),r=e.getSelectedValues();if(!t.hasOptionValues(r)){if(n.length>0){t.updateOptions(n);return}let r=e.getCatalogData().find(e=>e instanceof j&&e.placeholder===!0);if(r){t.updateOptions([new j({...r,selected:!0})]);return}}t.setSelectedByValue(r)}applySelection(e,t,n){let{store:r,select:i,render:a,events:o}=this.deps,s=r.getSelected(),c=R(r,e);if(y(s,c))return;r.setSelectedBy(`id`,c),this.syncNativeSelection(),a.renderValues();let l=a.content.search.input.value.trim();l===``?a.canUpdateOptionSelectionInPlace()?a.updateOptionSelection():a.renderOptions(r.getData(!1)):a.hasRenderedOptions()?a.updateOptionSelection():this.deps.search&&this.deps.search(l),n&&o.afterChange&&!y(s,r.getSelected())&&o.afterChange(r.getSelectedOptions())}applyAddOption(e){let{store:t,select:n,render:r,events:i}=this.deps,a=t.getSelected(),o=r.content.search.input.value.trim()!==``&&!!this.deps.search,s=e.value??e.text??``,c=e=>{for(let t of e){if(t instanceof M){if(t.options.some(e=>(e.value??e.text)===s))return!0;continue}if((t.value??t.text)===s)return!0}return!1};if(!c(t.getData(!1))){if(o){let n=t.getCatalogData();c(n)||t.setData([...n,new j(e)],!0),t.snapshotCatalog()}else t.addOption(e),t.snapshotCatalog()}let l=t.getData(!1);if(o){let e=t.getSelectedOptions();e.length>0&&n.updateOptions(e)}else n.updateOptions(l);r.renderValues(),r.renderOptions(l),i.afterChange&&!y(a,t.getSelected())&&i.afterChange(t.getSelectedOptions())}},B=class{selectEl;settings;cssClasses;select;store;render;sync;lifecycle;globalEvents;searchGeneration=0;events={search:void 0,searchFilter:(e,t)=>e.text.toLowerCase().indexOf(t.toLowerCase())!==-1,addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0};constructor(e){if(this.selectEl=typeof e.select==`string`?document.querySelector(e.select):e.select,!this.selectEl){e.events&&e.events.error&&e.events.error(Error(`Could not find select element`));return}if(this.selectEl.tagName!==`SELECT`){e.events&&e.events.error&&e.events.error(Error(`Element isnt of type select`));return}this.selectEl.dataset.ssid&&this.destroy(),this.settings=new f(e.settings),e.settings?.selectAll===void 0&&this.selectEl.dataset.selectall===`true`&&(this.settings.selectAll=!0),this.cssClasses=new n(e.cssClasses);let t=[`beforeOpen`,`afterOpen`,`afterClose`];for(let n in e.events)e.events.hasOwnProperty(n)&&(t.indexOf(n)===-1?this.events[n]=e.events[n]:this.events[n]=v(e.events[n],100));this.settings.disabled=e.settings?.disabled?e.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(` `),this.select=new I(this.selectEl),this.selectEl.id||(this.selectEl.id=this.settings.id),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.onClassChange=e=>{this.settings.class=e,this.render.updateClassStyles()},this.select.onDisabledChange=e=>{e?this.disable():this.enable()},this.select.onLabelClick=()=>{this.settings.disabled||(this.settings.isOpen?this.close({source:`toggle`,selectionChanged:!1}):this.open())};let r=e.data?e.data:this.select.getData();this.store=new N(this.settings.isMultiple?`multiple`:`single`,r),e.data&&this.select.updateOptions(this.store.getData());let i={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:(e,t)=>{this.sync.enqueue({type:`selection`,values:e,source:`ui`,runAfterChange:t})},addOption:e=>{this.sync.enqueue({type:`addOption`,option:e,source:`ui`})},search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.settings.modalTitle=e.settings?.modalTitle??h(this.selectEl),this.render=new P(this.settings,this.cssClasses,this.store,i),this.settings.timeoutDelay=s(this.render.content.main,e.settings?.timeoutDelay),this.sync=new z({select:this.select,store:this.store,render:this.render,events:this.events,search:this.search.bind(this)}),this.select.onValueChange=e=>{this.sync.enqueue({type:`selection`,values:e.map(e=>e.id||e.value),source:`native`})},this.select.onOptionsChange=e=>{this.sync.enqueue({type:`structure`,data:e||[],source:`native`})},this.lifecycle=new A({beforeOpen:this.events.beforeOpen,afterOpen:this.events.afterOpen,beforeClose:e=>this.events.beforeClose?.(e),onClose:e=>this.applyClose(e),afterClose:()=>{this.render.clearDirectionClasses(),this.render.finalizeModalClose(),this.events.afterClose&&this.events.afterClose()},onOpenReady:()=>this.globalEvents.attachDocumentClick(),onCloseReady:()=>this.globalEvents.detachDocumentClick()},{timeoutDelay:this.settings.timeoutDelay,waitForAnimation:(e,t)=>this.render.waitForAnimation(e,t)}),this.globalEvents=new k({onDocumentClick:this.documentClick.bind(this),onWindowResize:()=>{!this.settings.isOpen&&!this.settings.isFullOpen||this.render.moveContent()},onWindowScroll:()=>{!this.settings.isOpen&&!this.settings.isFullOpen||this.render.moveContent()},onVisibilityChange:()=>{document.hidden&&this.close({source:`api`,selectionChanged:!1})}}),this.render.renderValues(),this.render.renderOptions(this.store.getData(!1));let a=this.selectEl.getAttribute(`aria-label`),o=this.selectEl.getAttribute(`aria-labelledby`);if(a)this.render.main.main.setAttribute(`aria-label`,a);else if(o)this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,o);else if(this.selectEl.labels&&this.selectEl.labels.length>0){let e=Array.from(this.selectEl.labels).map((e,t)=>(e.id||=`${this.settings.id}-label-${t}`,e.id));this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,e.join(` `))}this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),this.globalEvents.attach({listenScroll:this.settings.openPosition===`auto`}),this.settings.disabled&&this.disable(),this.settings.alwaysOpen&&this.open(),this.select.setupLabelHandlers(),this.selectEl.slim=this}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){this.sync.enqueue({type:`structure`,data:e,source:`api`})}getSelected(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.map(e=>e.value)}setSelected(e,t=!0){this.sync.enqueue({type:`selection`,values:e,source:`api`,runAfterChange:t})}addOption(e){this.sync.enqueue({type:`addOption`,option:e,source:`api`})}open(){if(this.settings.disabled||this.settings.isOpen)return;this.lifecycle.cancelPending(),this.render.open(),this.settings.showSearch&&this.settings.focusSearch&&this.render.searchFocus(),this.settings.isOpen=!0,this.lifecycle.requestOpen().then(()=>{this.settings.isOpen&&(this.settings.isFullOpen=this.lifecycle.isFullOpen,this.settings.isOpen=this.lifecycle.isOpen)}),this.settings.contentPosition===`absolute`&&!this.render.isModalViewActive()&&this.render.startPositionTracking();let e=this.render.content.search.input.value.trim();e!==``&&this.search(e)}close(e={source:`api`,selectionChanged:!1}){!this.settings.isOpen||this.settings.alwaysOpen||this.lifecycle.requestClose(e).then(e=>{e&&(this.settings.isOpen||(this.settings.isOpen=this.lifecycle.isOpen,this.settings.isFullOpen=this.lifecycle.isFullOpen))})}applyClose(e){this.render.close(),!this.settings.keepSearch&&this.render.content.search.input.value!==``&&(this.sync.flush(),this.search(``));let t=e.source===`outside`||e.source===`toggle`;this.render.mainFocus(t?`click`:null),this.settings.isOpen=!1,this.settings.isFullOpen=!1,this.render.stopPositionTracking()}search(e){let t=e.trim();if(t===``){this.render.content.search.input.value=``,this.clearSearch();return}if(this.render.content.search.input.value!==e&&(this.render.content.search.input.value=e),this.events.search){this.runApiSearch(t);return}this.runLocalSearch(t)}clearSearch(){if(this.searchGeneration++,!this.events.search&&this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(``,this.events.searchFilter),this.render.resetSearchFilterState();return}this.render.resetSearchFilterState(),this.sync.enqueue({type:`structure`,data:this.store.getCatalogData(),source:`api`,preserveSelection:!0})}runLocalSearch(e){if(this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(e,this.events.searchFilter);return}let t=this.store.search(e,this.events.searchFilter);this.render.renderOptions(t)}runApiSearch(e){let t=++this.searchGeneration;this.render.renderSearching();let n=this.events.search(e,this.store.getSelectedOptions(),this.store.getCatalogData()),r=n=>{t===this.searchGeneration&&this.render.content.search.input.value.trim()===e&&this.sync.enqueue({type:`structure`,data:n,source:`api`,preserveSelection:!0,isSearchResult:!0})};if(n instanceof Promise){n.then(r).catch(e=>{t===this.searchGeneration&&this.render.renderError(typeof e==`string`?e:e.message)});return}if(Array.isArray(n)){r(n);return}this.render.renderError(`Search event must return a promise or an array of data`)}destroy(){this.lifecycle.destroy(),this.render.stopPositionTracking(),this.globalEvents.detach({listenScroll:this.settings.openPosition===`auto`}),this.store.setData([]),this.render.destroy(),this.select.destroy(),delete this.selectEl.slim}documentClick(e){this.settings.isOpen&&e.target&&!_(e.target,this.settings.id)&&this.close({source:`outside`,selectionChanged:!1})}};function V(e){let n=new WeakMap,r=e=>{if((0,t.isRef)(e)&&(e=(0,t.unref)(e)),(0,t.isReactive)(e)&&(e=(0,t.toRaw)(e)),typeof e!=`object`||!e)return e;if(n.has(e))return n.get(e);if(Array.isArray(e)){let t=[];n.set(e,t);for(let n of e)t.push(r(n));return t}let i={};n.set(e,i);for(let t of Object.keys(e))i[t]=r(e[t]);return i};return r(e)}var H=(0,t.defineComponent)({name:`SlimSelect`,props:{modelValue:{type:[String,Array,void 0]},multiple:{type:Boolean,default:!1},data:{type:Array,required:!0},settings:{type:Object},events:{type:Object,default:()=>({})}},emits:[`update:modelValue`],data(){return{slim:null,lastAppliedData:null}},mounted(){let e={select:this.$refs.slim,data:this.data};this.settings&&(e.settings=this.settings);let t=this.events?.afterChange;e.events={...this.events,afterChange:e=>{this.handleAfterChange(e,t)}},this.slim=new B(e),this.lastAppliedData=structuredClone(V(this.data)),this.syncModelValueToSlimSelect(!1)},beforeUnmount(){this.slim&&this.slim.destroy()},watch:{modelValue:{handler:function(e){this.slim&&this.syncModelValueToSlimSelect(!1)}},data:{handler:function(e){this.slim&&(this.lastAppliedData!==null&&E(this.lastAppliedData,(0,t.toRaw)(e))||(this.slim.setData(e),this.lastAppliedData=structuredClone(V(e)),this.syncModelValueToSlimSelect(!1)))},deep:!0}},computed:{value:{get(){return this.getCleanValue(this.$props.modelValue)},set(e){this.$emit(`update:modelValue`,e)}}},methods:{getSlimSelect(){return this.slim},handleAfterChange(e,t){if(!this.slim)return;let n=this.multiple?e.map(e=>e.value):e.length>0?e[0].value:``,r=this.getCleanValue(this.$props.modelValue),i=this.slim.store.getDataOptions(!1),a=Array.isArray(r)?r.length>0&&r.every(e=>i.some(t=>t.value===e)):r!==``&&i.some(e=>e.value===r),o=Array.isArray(n)?n.length>0&&n.every(e=>i.some(t=>t.value===e)):n!==``&&i.some(e=>e.value===n);(Array.isArray(n)&&Array.isArray(this.value)?JSON.stringify(n.sort())!==JSON.stringify(this.value.sort()):this.value!==n)&&(a||o)&&(this.value=n),t&&t(e)},getCleanValue(e){let t=this.$props.multiple;return typeof e==`string`?t?[e]:e:Array.isArray(e)?t?e:e[0]:t?[]:``},syncModelValueToSlimSelect(e=!1){if(!this.slim||this.$props.modelValue===void 0)return;let t=this.getCleanValue(this.$props.modelValue),n=this.slim.getData().flatMap(e=>`label`in e?e.options:[e]);if(!(Array.isArray(t)?t.length>0&&t.every(e=>n.some(t=>t.value===e)):t!==``&&n.some(e=>e.value===t))&&!Array.isArray(t)&&!n.some(e=>e.placeholder)){let e=this.slim.getData();this.slim.setData([{value:``,text:``,placeholder:!0}].concat(e))}this.slim.setSelected(t,e)}}}),U=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},W=[`multiple`];function G(e,n,r,i,a,o){return(0,t.openBlock)(),(0,t.createElementBlock)(`select`,{multiple:e.multiple,ref:`slim`},null,8,W)}var K=U(H,[[`render`,G]]);e.Optgroup=M,e.Option=j,e.Settings=f,e.default=K});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue")):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.SlimSelectVue={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n=class{main;placeholder;values;single;multiString;max;value;valueText;valueDelete;valueOut;deselect;deselectPath;arrow;arrowClose;arrowOpen;content;contentOpen;dirAbove;dirBelow;search;searchHighlighter;searching;status;addable;addablePath;list;optgroup;optgroupLabel;optgroupLabelText;optgroupActions;optgroupSelectAll;optgroupSelectAllBox;optgroupSelectAllCheck;optgroupClosable;option;optionDelete;highlighted;modalOverlay;modalDialog;modalTitle;modalClose;modalContent;mainOpen;close;selected;error;disabled;hide;constructor(e){e||={};let t=(e=``,t=``)=>`${e} ${t}`.trim();this.main=t(`ss-main`,e.main),this.placeholder=t(`ss-placeholder`,e.placeholder),this.values=t(`ss-values`,e.values),this.single=t(`ss-single`,e.single),this.multiString=t(`ss-multi-string`,e.multiString),this.max=t(`ss-max`,e.max),this.value=t(`ss-value`,e.value),this.valueText=t(`ss-value-text`,e.valueText),this.valueDelete=t(`ss-value-delete`,e.valueDelete),this.valueOut=t(`ss-value-out`,e.valueOut),this.deselect=t(`ss-deselect`,e.deselect),this.deselectPath=e.deselectPath||`M10,10 L90,90 M10,90 L90,10`,this.arrow=t(`ss-arrow`,e.arrow),this.arrowClose=e.arrowClose||`M10,30 L50,70 L90,30`,this.arrowOpen=e.arrowOpen||`M10,70 L50,30 L90,70`,this.content=t(`ss-content`,e.content),this.contentOpen=t(`ss-open`,e.contentOpen),this.dirAbove=t(`ss-dir-above`,e.dirAbove),this.dirBelow=t(`ss-dir-below`,e.dirBelow),this.search=t(`ss-search`,e.search),this.searchHighlighter=t(`ss-search-highlight`,e.searchHighlighter),this.searching=t(`ss-searching`,e.searching),this.status=t(`ss-status`,e.status),this.addable=t(`ss-addable`,e.addable),this.addablePath=e.addablePath||`M50,10 L50,90 M10,50 L90,50`,this.list=t(`ss-list`,e.list),this.optgroup=t(`ss-optgroup`,e.optgroup),this.optgroupLabel=t(`ss-optgroup-label`,e.optgroupLabel),this.optgroupLabelText=t(`ss-optgroup-label-text`,e.optgroupLabelText),this.optgroupActions=t(`ss-optgroup-actions`,e.optgroupActions),this.optgroupSelectAll=t(`ss-selectall`,e.optgroupSelectAll),this.optgroupSelectAllBox=e.optgroupSelectAllBox||`M15,15 L85,15 L85,85 L15,85 Z`,this.optgroupSelectAllCheck=e.optgroupSelectAllCheck||`M25,50 L42,68 L75,32`,this.optgroupClosable=t(`ss-closable`,e.optgroupClosable),this.option=t(`ss-option`,e.option),this.optionDelete=e.optionDelete||`M10,10 L90,90 M10,90 L90,10`,this.highlighted=t(`ss-highlighted`,e.highlighted),this.modalOverlay=t(`ss-modal-overlay`,e.modalOverlay),this.modalDialog=t(`ss-modal-dialog`,e.modalDialog),this.modalTitle=t(`ss-modal-title`,e.modalTitle),this.modalClose=t(`ss-modal-close`,e.modalClose),this.modalContent=t(`ss-modal-content`,e.modalContent),this.mainOpen=t(`ss-open`,e.mainOpen),this.close=t(`ss-close`,e.close),this.selected=t(`ss-selected`,e.selected),this.error=t(`ss-error`,e.error),this.disabled=t(`ss-disabled`,e.disabled),this.hide=t(`ss-hide`,e.hide)}getFirst(e){return this[e].split(` `)[0]}},r=200,i=[`transform`,`opacity`];function a(e,t=r){let n=e.trim();if(!n)return t;if(n.endsWith(`ms`)){let e=parseFloat(n);return Number.isNaN(e)?t:e}if(n.endsWith(`s`)){let e=parseFloat(n);return Number.isNaN(e)?t:e*1e3}let i=parseFloat(n);return Number.isNaN(i)?t:i}function o(e,t=r){return a(getComputedStyle(e).getPropertyValue(`--ss-animation-timing`).trim(),t)}function s(e,t,n=r){let i=o(e,n)+50;return t===void 0?i:Math.max(i,t)}function c(){return typeof window>`u`||typeof window.matchMedia!=`function`?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function l(e){return e===void 0?null:new Set(Array.isArray(e)?e:[e])}function u(e,t,n=r,i){if(c()||i?.aborted)return Promise.resolve();let a=l(t);return new Promise(t=>{let r=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`transitionend`,l),i?.removeEventListener(`abort`,c),r&&clearTimeout(r),t())},c=()=>s(),l=t=>{t.target===e&&(a&&(!a.has(t.propertyName)||(a.delete(t.propertyName),a.size>0))||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`transitionend`,l),r=setTimeout(s,n)})}function d(e,t,n=r,i){return c()||i?.aborted?Promise.resolve():new Promise(r=>{let a=null,o=!1,s=()=>{o||(o=!0,e.removeEventListener(`animationend`,l),i?.removeEventListener(`abort`,c),a&&clearTimeout(a),r())},c=()=>s(),l=n=>{n.target===e&&(t&&n.animationName!==t||s())};i?.addEventListener(`abort`,c,{once:!0}),e.addEventListener(`animationend`,l),a=setTimeout(s,n)})}var f=class{id=``;style=``;class=[];isMultiple=!1;isOpen=!1;isFullOpen=!1;disabled;alwaysOpen;showSearch;focusSearch;keepSearch;ariaLabel;searchPlaceholder;searchText;searchingText;resultsText;deselectText;removeText;searchHighlight;closeOnSelect;contentLocation;contentPosition;contentWidth;openPosition;placeholderText;allowDeselect;hideSelected;multiString;keepOrder;showOptionTooltips;minSelected;maxSelected;timeoutDelay;maxValuesShown;maxValuesMessage;addableText;selectAll;selectAllText;unselectAllText;modal;modalTitle;constructor(e){e||={},this.id=`ss-`+g(),this.style=e.style||``,this.class=e.class||[],this.disabled=e.disabled!==void 0&&e.disabled,this.alwaysOpen=e.alwaysOpen!==void 0&&e.alwaysOpen,this.showSearch=e.showSearch===void 0||e.showSearch,this.focusSearch=e.focusSearch===void 0?typeof window>`u`||window.innerWidth>=768:e.focusSearch,this.keepSearch=e.keepSearch!==void 0&&e.keepSearch,this.ariaLabel=e.ariaLabel||`Combobox`,this.searchPlaceholder=e.searchPlaceholder||`Search...`,this.searchText=e.searchText||`No Results`,this.searchingText=e.searchingText||`Searching...`,this.resultsText=e.resultsText||`{count} results available`,this.deselectText=e.deselectText||`Clear`,this.removeText=e.removeText||`Remove`,this.searchHighlight=e.searchHighlight!==void 0&&e.searchHighlight,this.closeOnSelect=e.closeOnSelect===void 0||e.closeOnSelect,this.contentLocation=e.contentLocation||document.body,this.contentPosition=e.contentPosition||`absolute`,this.contentWidth=e.contentWidth||``,this.openPosition=e.openPosition||`auto`,this.placeholderText=e.placeholderText===void 0?`Select Value`:e.placeholderText,this.allowDeselect=e.allowDeselect!==void 0&&e.allowDeselect,this.hideSelected=e.hideSelected!==void 0&&e.hideSelected,this.multiString=e.multiString!==void 0&&e.multiString,this.keepOrder=e.keepOrder!==void 0&&e.keepOrder,this.showOptionTooltips=e.showOptionTooltips!==void 0&&e.showOptionTooltips,this.minSelected=e.minSelected||0,this.maxSelected=e.maxSelected||1e3,this.timeoutDelay=e.timeoutDelay||200,this.maxValuesShown=e.maxValuesShown||20,this.maxValuesMessage=e.maxValuesMessage||`{number} selected`,this.addableText=e.addableText||`Press "Enter" to add {value}`,this.selectAll=e.selectAll!==void 0&&e.selectAll,this.selectAllText=e.selectAllText||`Select All`,this.unselectAllText=e.unselectAllText||`Unselect All`,this.modal=e.modal||`mobile`,this.modalTitle=e.modalTitle||``}};function p(e){if(!e)return{};let t={};for(let n of Object.keys(e)){let r=e[n];r!==void 0&&(t[n]=r)}return t}function m(e){let t=e.cloneNode(!0);return t.querySelectorAll(`select, option, optgroup, textarea, input, button`).forEach(e=>e.remove()),t.textContent?.replace(/\s+/g,` `).trim()||``}function h(e){if(e.labels&&e.labels.length>0){let t=Array.from(e.labels).map(m).filter(Boolean);if(t.length>0)return[...new Set(t)].join(` `)}return e.getAttribute(`aria-label`)?.trim()||``}function g(){return Math.random().toString(36).substring(2,10)}function _(e,t){function n(e,n){return n&&e&&e.classList&&e.classList.contains(n)||n&&e&&e.dataset&&e.dataset.id&&e.dataset.id===t?e:null}function r(e,t){return!e||e===document?null:n(e,t)?e:r(e.parentNode,t)}return n(e,t)||r(e,t)}function v(e,t=50,n=!1){let r;return function(...i){let a=self,o=()=>{r=null,n||e.apply(a,i)},s=n&&!r;clearTimeout(r),r=setTimeout(o,t),s&&e.apply(a,i)}}function y(e,t){if(e.length!==t.length)return!1;let n=[...e].sort(),r=[...t].sort();return n.every((e,t)=>e===r[t])}var b=[`id`,`value`,`text`,`html`,`defaultSelected`,`selected`,`display`,`disabled`,`placeholder`,`class`,`style`,`mandatory`];function x(e,t){let n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(let r of n)if(e[r]!==t[r])return!1;return!0}function S(e,t){switch(t){case`id`:return e.id||``;case`value`:return e.value===void 0?e.text||``:e.value||``;case`text`:return e.text||``;case`html`:return e.html||``;case`defaultSelected`:return e.defaultSelected??!1;case`selected`:return e.selected??!1;case`display`:return e.display??!0;case`disabled`:return e.disabled??!1;case`placeholder`:return e.placeholder??!1;case`class`:return e.class||``;case`style`:return e.style||``;case`mandatory`:return e.mandatory??!1;default:return e.data||{}}}function C(e){return!!e&&typeof e==`object`&&`label`in e&&`options`in e}function w(e,t){for(let n of b)if(S(e,n)!==S(t,n))return!1;return x(e.data||{},t.data||{})}function T(e,t){let n=e=>({id:e.id||``,label:e.label||``,selectAll:e.selectAll??!1,closable:e.closable||`off`}),r=n(e),i=n(t);if(r.id!==i.id||r.label!==i.label||r.selectAll!==i.selectAll||r.closable!==i.closable)return!1;let a=e.options||[],o=t.options||[];if(a.length!==o.length)return!1;for(let e=0;e<a.length;e++)if(!w(a[e],o[e]))return!1;return!0}function E(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],i=t[n],a=C(r);if(a!==C(i))return!1;if(a){if(!T(r,i))return!1;continue}if(!w(r,i))return!1}return!0}function D(e){let t=e.replace(/[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g,e=>`-`+e.toLowerCase());return e[0]===e[0].toUpperCase()?t.substring(1):t}function O(e,t=typeof window<`u`?window.innerWidth:768){return e===`on`||e===`mobile`&&t<768}var k=class{handlers;attached=!1;constructor(e){this.handlers=e}attach(e){this.attached||(this.attached=!0,window.addEventListener(`resize`,this.resizeHandler,!1),e.listenScroll&&window.addEventListener(`scroll`,this.scrollHandler,!1),document.addEventListener(`visibilitychange`,this.visibilityHandler))}attachDocumentClick(){document.addEventListener(`click`,this.handlers.onDocumentClick)}detachDocumentClick(){document.removeEventListener(`click`,this.handlers.onDocumentClick)}detach(e){this.attached&&(this.attached=!1,this.detachDocumentClick(),window.removeEventListener(`resize`,this.resizeHandler,!1),e.listenScroll&&window.removeEventListener(`scroll`,this.scrollHandler,!1),document.removeEventListener(`visibilitychange`,this.visibilityHandler))}resizeHandler=v(()=>{this.handlers.onWindowResize()});scrollHandler=v(()=>{this.handlers.onWindowScroll()});visibilityHandler=()=>{this.handlers.onVisibilityChange()}},A=class{handlers;options;state=`closed`;pendingTimer=null;waitResolvers=[];generation=0;animationAbort=null;constructor(e,t){this.handlers=e,this.options=t}get isOpen(){return this.state===`opening`||this.state===`open`}get isFullOpen(){return this.state===`open`}async requestOpen(){if(this.state===`opening`||this.state===`open`)return;this.cancelPending();let e=++this.generation;if(this.handlers.beforeOpen&&this.handlers.beforeOpen(),this.state=`opening`,await this.waitForPhase(`open`,e),e!==this.generation){this.state===`opening`&&(this.state=`closed`);return}this.state=`open`,this.handlers.afterOpen&&this.handlers.afterOpen(),this.handlers.onOpenReady&&this.handlers.onOpenReady()}async requestClose(e={source:`api`,selectionChanged:!1}){if(this.state===`closed`||this.state===`closing`||this.handlers.beforeClose&&this.handlers.beforeClose(e)===!1)return!1;this.cancelPending();let t=++this.generation;return this.handlers.onClose&&this.handlers.onClose(e),this.state=`closing`,await this.waitForPhase(`close`,t),t===this.generation&&(this.state=`closed`,this.handlers.afterClose&&this.handlers.afterClose(),this.handlers.onCloseReady&&this.handlers.onCloseReady(),!0)}cancelPending(){this.generation++,this.animationAbort?.abort(),this.animationAbort=null,this.pendingTimer&&=(clearTimeout(this.pendingTimer),null);let e=this.waitResolvers.splice(0);for(let t of e)t()}destroy(){this.cancelPending(),this.state=`closed`}waitForPhase(e,t){return new Promise(t=>{let n=!1,r=()=>{if(n)return;n=!0;let e=this.waitResolvers.indexOf(r);e!==-1&&this.waitResolvers.splice(e,1),t()};if(this.waitResolvers.push(r),this.options.waitForAnimation){let t=new AbortController;this.animationAbort=t,this.options.waitForAnimation(e,t.signal).catch(()=>void 0).finally(()=>{this.animationAbort===t&&(this.animationAbort=null),r()})}else this.pendingTimer=setTimeout(()=>{this.pendingTimer=null,r()},this.options.timeoutDelay)}).then(()=>{this.generation})}},j=class{id;value;text;html;defaultSelected;selected;display;disabled;placeholder;class;style;data;mandatory;constructor(e){this.id=!e.id||e.id===``?g():e.id,this.value=e.value===void 0?e.text||``:e.value||``,this.text=e.text||``,this.html=e.html||``,this.defaultSelected=e.defaultSelected!==void 0&&e.defaultSelected,this.selected=e.selected!==void 0&&e.selected,this.display=e.display===void 0||e.display,this.disabled=e.disabled!==void 0&&e.disabled,this.mandatory=e.mandatory!==void 0&&e.mandatory,this.placeholder=e.placeholder!==void 0&&e.placeholder,this.class=e.class||``,this.style=e.style||``,this.data=p(e.data)}},M=class{id;label;selectAll;closable;options;constructor(e){if(this.id=!e.id||e.id===``?g():e.id,this.label=e.label||``,this.selectAll=e.selectAll!==void 0&&e.selectAll,this.closable=e.closable||`off`,this.options=[],e.options)for(let t of e.options)this.options.push(new j(t))}},N=class{selectType=`single`;data=[];selectedOrder=[];catalog=null;constructor(e,t){this.selectType=e,this.setData(t),this.snapshotCatalog()}validateDataArray(e){if(!Array.isArray(e))return Error(`Data must be an array`);for(let t of e)if(t){if(t instanceof M||`label`in t){if(!(`label`in t))return Error(`Optgroup must have a label`);if(`options`in t&&t.options)for(let e of t.options){let t=this.validateOption(e);if(t)return t}}else if(t instanceof j||`text`in t){let e=this.validateOption(t);if(e)return e}else return Error(`Data object must be a valid optgroup or option`)}return null}validateOption(e){return`text`in e?null:Error(`Option must have a text`)}partialToFullData(e){let t=[];return e.forEach(e=>{if(e){if(e instanceof M||`label`in e){let n=[];`options`in e&&e.options&&e.options.forEach(e=>{n.push(new j(e))}),n.length>0&&t.push(new M(e))}(e instanceof j||`text`in e)&&t.push(new j(e))}}),t}snapshotCatalog(){this.catalog=this.cloneData(this.data)}getCatalogData(){return this.cloneData(this.catalog??this.data)}cloneData(e){return e.map(e=>e instanceof M?new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:e.options.map(e=>new j(e instanceof j?{...e}:e))}):new j({...e}))}optionMatchesSelected(e,t){return e.id===t.id||t.value!==``&&e.value!==``&&e.value===t.value}findOptionInData(e,t){for(let n of e){if(n instanceof j){if(this.optionMatchesSelected(n,t))return n;continue}for(let e of n.options)if(this.optionMatchesSelected(e,t))return e}return null}setData(e,t=!1){let n=this.partialToFullData(e),r=[];if(t){r=this.getSelectedOptions();let e=[];r.forEach(t=>{this.findOptionInData(n,t)||e.push(t)}),this.data=[...e,...n];let t=this.selectType===`single`&&r.length===0,i=r.map(e=>{let t=this.findOptionInData(this.data,e);return t?t.id:e.id});this.setSelectedBy(`id`,i,t)}else this.data=n;!t&&this.selectType===`single`&&this.setSelectedBy(`id`,this.getSelected(),!1)}getData(e=!0){return this.filter(null,!0,e)}getDataOptions(e=!0){return this.filter(null,!1,e)}addOption(e,t=!1){if(t){let t=[new j(e)];this.setData(t.concat(this.getData()))}else this.setData(this.getData().concat(new j(e)))}setSelectedBy(e,t,n=!1){let r=null,i=!1,a=[];for(let n of this.data){if(n instanceof M)for(let o of n.options){r||=o;let n=o[e]||``;o.selected=!i&&t.includes(n),o.selected&&(a.push(o),this.selectType===`single`&&(i=!0))}n instanceof j&&(r||=n,n.selected=!i&&t.includes(n[e]),n.selected&&(a.push(n),this.selectType===`single`&&(i=!0)))}this.selectType===`single`&&r&&!i&&!n&&(r.selected=!0,a.push(r));let o=t.map(t=>a.find(n=>n[e]===t)?.id||``);this.selectedOrder=o}getSelected(){return this.getSelectedOptions().map(e=>e.id)}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}getSelectedOptions(){let e=[];for(let t of this.data)if(t instanceof M)for(let n of t.options)n.selected&&e.push(n);else t.selected&&e.push(t);return e}getOptgroupByID(e){for(let t of this.data)if(t instanceof M&&t.id===e)return t;return null}getOptionByID(e){for(let t of this.data)if(t instanceof M){for(let n of t.options)if(n.id===e)return n}else if(t.id===e)return t;return null}getSelectType(){return this.selectType}getFirstOption(){let e=null;for(let t of this.data)if(t instanceof M?e=t.options[0]:t instanceof j&&(e=t),e)break;return e}search(e,t){return e=e.trim(),e===``?this.getData(!1):this.filter(n=>t(n,e),!0,!1)}createOptgroupView(e,t){let n=new M({id:e.id,label:e.label,selectAll:e.selectAll,closable:e.closable,options:[]});return n.options=t,n}filter(e,t,n=!0){let r=[];return this.data.forEach(i=>{if(i instanceof M){let a=[];if(i.options.forEach(i=>{(!e||e(i))&&(t?a.push(n?new j(i):i):r.push(n?new j(i):i))}),a.length>0){if(n){let e=new M(i);e.options=a,r.push(e)}else r.push(this.createOptgroupView(i,a))}}i instanceof j&&(!e||e(i))&&r.push(n?new j(i):i)}),r}selectedOrderOptions(e){let t=[];return this.selectedOrder.forEach(n=>{let r=e.find(e=>e.id===n);r&&t.push(r)}),e.forEach(e=>{let n=!1;t.forEach(t=>{if(e.id===t.id){n=!0;return}}),n||t.push(e)}),t}},P=class{settings;store;callbacks;lastSelectedOption;lastRenderedOptions;optionsListIsFullData=!1;lastSearchFilterTerm=``;main;content;classes;positionObserver=null;positionObserverRaf=0;lastObservedContentHeight=-1;overflowShiftRaf=0;modalElements=null;modalSessionActive=null;bodyScrollLocked=!1;savedBodyOverflow=``;constructor(e,t,n,r){this.store=n,this.settings=e,this.classes=t,this.callbacks=r,this.lastSelectedOption=null,this.lastRenderedOptions=[],this.main=this.mainDiv(),this.content=this.contentDiv(),this.updateClassStyles(),this.updateAriaAttributes(),this.settings.contentPosition!==`relative`&&(this.content.main.style.top=`-9999px`,this.content.main.style.left=`-9999px`,this.content.main.style.margin=`0`,this.content.main.style.width=`auto`),this.settings.contentLocation&&this.settings.contentLocation.appendChild(this.content.main),this.settings.modal!==`off`&&!this.settings.alwaysOpen&&(this.modalElements=this.createModalElements(),document.body.appendChild(this.modalElements.overlay))}requestClose(e,t){this.callbacks.close({source:e,option:t?.option,selectionChanged:t?.selectionChanged??!1})}selectionChanged(e,t){if(e.length!==t.length)return!0;let n=e.map(e=>e.id).sort(),r=t.map(e=>e.id).sort();return n.some((e,t)=>e!==r[t])}closeOnSingleSelectReclick(e){this.settings.closeOnSelect&&this.requestClose(`select`,{option:e,selectionChanged:!1})}addClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.add(t.trim())}removeClasses(e,t){if(!t||t.trim()===``)return;let n=t.split(` `).filter(e=>e.trim()!==``);for(let t of n)e.classList.remove(t.trim())}enable(){this.removeClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`false`),this.content.search.input.disabled=!1}disable(){this.addClasses(this.main.main,this.classes.disabled),this.main.main.setAttribute(`aria-disabled`,`true`),this.content.search.input.disabled=!0}open(){this.main.arrow.path.setAttribute(`d`,this.classes.arrowOpen),this.main.main.setAttribute(`aria-expanded`,`true`);let e=this.resolveModalView();if(!e){let e=this.settings.openPosition===`up`?this.classes.dirAbove:this.classes.dirBelow;this.addClasses(this.main.main,e),this.addClasses(this.content.main,e)}this.addClasses(this.content.main,this.classes.contentOpen),this.content.search.input.removeAttribute(`aria-hidden`),e?this.showModal():this.moveContent();let t=this.store.getSelectedOptions();if(t.length){let e=t[t.length-1].id,n=this.content.list.querySelector(`[data-id="`+e+`"]`);n&&this.ensureElementInView(this.content.list,n)}}isModalViewActive(){return this.modalSessionActive===!0}resolveModalView(){return this.settings.alwaysOpen||this.settings.modal===`off`||!this.modalElements?!1:(this.modalSessionActive===null&&(this.modalSessionActive=O(this.settings.modal)),this.modalSessionActive)}createModalElements(){let e=document.createElement(`div`);this.addClasses(e,this.classes.modalOverlay),this.addClasses(e,this.classes.hide),e.dataset.id=this.settings.id;let t=document.createElement(`div`);this.addClasses(t,this.classes.modalDialog),t.setAttribute(`role`,`dialog`),t.setAttribute(`aria-modal`,`true`);let n=null;this.settings.modalTitle?(n=document.createElement(`div`),this.addClasses(n,this.classes.modalTitle),n.id=`${this.settings.id}-modal-title`,n.textContent=this.settings.modalTitle,t.setAttribute(`aria-labelledby`,n.id)):t.setAttribute(`aria-label`,this.settings.ariaLabel);let r=document.createElement(`button`);r.type=`button`,this.addClasses(r,this.classes.modalClose),r.setAttribute(`aria-label`,`Close`),r.onclick=e=>{e.stopPropagation(),this.requestClose(`modal`)};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),r.appendChild(i),e.onclick=t=>{t.target===e&&this.requestClose(`modal`)},n&&t.appendChild(n),e.appendChild(t),{overlay:e,dialog:t,closeButton:r,title:n}}showModal(){this.modalElements&&(this.modalElements.dialog.appendChild(this.content.main),this.addClasses(this.content.main,this.classes.modalContent),this.content.main.appendChild(this.modalElements.closeButton),this.content.main.style.top=``,this.content.main.style.left=``,this.content.main.style.margin=``,this.content.main.style.width=``,this.removeClasses(this.modalElements.overlay,this.classes.hide),requestAnimationFrame(()=>{this.modalElements&&this.addClasses(this.modalElements.overlay,this.classes.contentOpen)}),this.lockBodyScroll())}lockBodyScroll(){this.bodyScrollLocked||=(this.savedBodyOverflow=document.body.style.overflow,document.body.style.overflow=`hidden`,!0)}unlockBodyScroll(){this.bodyScrollLocked&&(document.body.style.overflow=this.savedBodyOverflow,this.bodyScrollLocked=!1,this.savedBodyOverflow=``)}restoreContentOffscreen(){this.settings.contentLocation&&this.settings.contentLocation.appendChild(this.content.main),this.settings.contentPosition!==`relative`&&(this.content.main.style.top=`-9999px`,this.content.main.style.left=`-9999px`,this.content.main.style.margin=`0`,this.content.main.style.width=`auto`)}finalizeModalClose(){this.modalElements&&this.content.main.parentElement===this.modalElements.dialog&&(this.addClasses(this.modalElements.overlay,this.classes.hide),this.removeClasses(this.modalElements.overlay,this.classes.contentOpen),this.removeClasses(this.content.main,this.classes.modalContent),this.modalElements.closeButton.remove(),this.restoreContentOffscreen(),this.unlockBodyScroll())}waitForAnimation(e,t){let n=s(this.content.main,this.settings.timeoutDelay);return u(this.content.main,i,n,t)}close(){this.main.main.setAttribute(`aria-expanded`,`false`),this.main.arrow.path.setAttribute(`d`,this.classes.arrowClose);let e=this.modalSessionActive===!0;this.removeClasses(this.content.main,this.classes.contentOpen),e||(this.removeClasses(this.main.main,this.classes.dirAbove),this.removeClasses(this.main.main,this.classes.dirBelow)),e&&this.modalElements&&this.removeClasses(this.modalElements.overlay,this.classes.contentOpen),this.modalSessionActive=null,this.content.search.input.setAttribute(`aria-hidden`,`true`),this.main.main.removeAttribute(`aria-activedescendant`),this.clearValueChipHighlight()}clearDirectionClasses(){this.removeClasses(this.main.main,this.classes.dirAbove),this.removeClasses(this.main.main,this.classes.dirBelow),this.removeClasses(this.content.main,this.classes.dirAbove),this.removeClasses(this.content.main,this.classes.dirBelow)}updateClassStyles(){if(this.main.main.className=``,this.main.main.removeAttribute(`style`),this.content.main.className=``,this.content.main.removeAttribute(`style`),this.addClasses(this.main.main,this.classes.main),this.addClasses(this.content.main,this.classes.content),this.settings.style!==``&&(this.main.main.style.cssText=this.settings.style,this.content.main.style.cssText=this.settings.style),this.settings.class.length)for(let e of this.settings.class)e.trim()!==``&&(this.main.main.classList.add(e.trim()),this.content.main.classList.add(e.trim()));(this.settings.contentPosition===`relative`||this.settings.contentPosition===`fixed`)&&this.content.main.classList.add(`ss-`+this.settings.contentPosition)}updateAriaAttributes(){let e=this.content.list.id;this.main.main.role=`combobox`,this.main.main.setAttribute(`aria-haspopup`,`listbox`),this.main.main.setAttribute(`aria-controls`,e),this.main.main.setAttribute(`aria-expanded`,`false`),this.content.list.setAttribute(`role`,`listbox`),this.content.list.setAttribute(`aria-label`,this.settings.ariaLabel+` listbox`),this.settings.isMultiple&&this.content.list.setAttribute(`aria-multiselectable`,`true`),this.content.search.input.setAttribute(`aria-controls`,e)}mainDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id,e.setAttribute(`aria-label`,this.settings.ariaLabel),e.tabIndex=0,e.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return this.callbacks.open(),e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`Tab`:return this.requestClose(`tab`),!0;case`Enter`:case` `:this.callbacks.open();let t=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return t&&t.click(),!1;case`Escape`:return this.requestClose(`escape`),!1}return e.key.length===1&&this.callbacks.open(),!0},e.onclick=e=>{this.settings.disabled||(this.settings.isOpen?this.requestClose(`toggle`):this.callbacks.open())};let t=document.createElement(`div`);this.addClasses(t,this.classes.values),e.appendChild(t);let n=document.createElement(`div`);this.addClasses(n,this.classes.deselect),n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,this.settings.deselectText),n.setAttribute(`tabindex`,`0`);let r=this.store?.getSelectedOptions();!this.settings.allowDeselect||this.settings.isMultiple&&r&&r.length<=0||this.isAtMinSelected()?this.addClasses(n,this.classes.hide):this.removeClasses(n,this.classes.hide),n.onclick=e=>{if(e.stopPropagation(),this.settings.disabled||this.settings.isMultiple&&this.isAtMinSelected())return;let t=!0,n=this.store.getSelectedOptions(),r=[],i=``;if(this.settings.isMultiple){let e=this.settings.minSelected,t=this.store.getSelected();if(e>0&&t.length>e)i=this.getMinimumSelectionIds(),r=n.filter(e=>i.includes(e.id));else if(e<=0)i=[];else return}if(this.callbacks.beforeChange&&(t=this.callbacks.beforeChange(r,n)===!0),t){if(this.settings.isMultiple)this.callbacks.setSelected(i,!1),this.updateDeselectAll();else{let e=this.store.getFirstOption(),t=e?e.id:``;this.callbacks.setSelected(t,!1)}this.settings.closeOnSelect&&this.requestClose(`deselect`,{selectionChanged:!0}),this.callbacks.afterChange&&this.callbacks.afterChange(this.store.getSelectedOptions())}},n.onkeydown=e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),n.click())};let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);a.setAttribute(`d`,this.classes.deselectPath),i.appendChild(a),n.appendChild(i),e.appendChild(n);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);this.addClasses(o,this.classes.arrow),o.setAttribute(`viewBox`,`0 0 100 100`);let s=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return s.setAttribute(`d`,this.classes.arrowClose),this.settings.alwaysOpen&&this.addClasses(o,this.classes.hide),o.appendChild(s),e.appendChild(o),{main:e,values:t,deselect:{main:n,svg:i,path:a},arrow:{main:o,path:s}}}mainFocus(e){e!==`click`&&this.main.main.focus({preventScroll:!0})}placeholder(){let e=this.store.filter(e=>e.placeholder,!1,!1),t=this.settings.placeholderText;e.length&&(e[0].html===``?e[0].text!==``&&(t=e[0].text):t=e[0].html);let n=document.createElement(`div`);return this.addClasses(n,this.classes.placeholder),n.innerHTML=t,n}renderValues(){if(!this.settings.isMultiple){this.renderSingleValue();return}this.renderMultipleValues(),this.updateDeselectAll()}renderSingleValue(){let e=this.store.filter(e=>e.selected&&!e.placeholder,!1,!1),t=e.length>0?e[0]:null;if(!t)this.main.values.innerHTML=this.placeholder().outerHTML;else{let e=document.createElement(`div`);this.addClasses(e,this.classes.single),t.html?e.innerHTML=t.html:e.innerText=t.text,this.main.values.innerHTML=e.outerHTML}!this.settings.allowDeselect||!e.length?this.addClasses(this.main.deselect.main,this.classes.hide):this.removeClasses(this.main.deselect.main,this.classes.hide)}renderMultipleValues(){let e=this.main.values.childNodes,t=this.store.filter(e=>e.selected&&e.display,!1,!1);if(t.length===0){this.main.values.innerHTML=this.placeholder().outerHTML;return}{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`placeholder`));e&&e.remove()}if(this.settings.multiString){let e=t;this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e));let n=document.createElement(`div`);this.addClasses(n,this.classes.multiString),n.textContent=e.map(e=>e.text).join(`, `),this.settings.showOptionTooltips&&n.setAttribute(`title`,n.textContent),this.main.values.innerHTML=n.outerHTML;return}if(t.length>this.settings.maxValuesShown){let e=document.createElement(`div`);this.addClasses(e,this.classes.max),e.textContent=this.settings.maxValuesMessage.replace(`{number}`,t.length.toString()),this.main.values.innerHTML=e.outerHTML;return}{let e=this.main.values.querySelector(`.`+this.classes.getFirst(`max`));e&&e.remove()}this.settings.keepOrder&&(t=this.store.selectedOrderOptions(t));let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=i.getAttribute(`data-id`);a&&(t.filter(e=>e.id===a,!1).length||n.push(i))}let r=s(this.content.main,this.settings.timeoutDelay);for(let e of n)this.addClasses(e,this.classes.valueOut),d(e,`ss-valueOut`,r).then(()=>{this.main.values.hasChildNodes()&&this.main.values.contains(e)&&this.main.values.removeChild(e)});e=this.main.values.childNodes;for(let n=0;n<t.length;n++){let r=!0;for(let i=0;i<e.length;i++)t[n].id===String(e[i].dataset.id)&&(r=!1);r&&(this.settings.keepOrder||e.length===0?this.main.values.appendChild(this.multipleValue(t[n])):n===0?this.main.values.insertBefore(this.multipleValue(t[n]),e[n]):e[n-1].insertAdjacentElement(`afterend`,this.multipleValue(t[n])))}this.updateMultipleValueDeleteVisibility()}isAtMinSelected(){return this.settings.isMultiple&&this.settings.minSelected>0&&this.store.getSelectedOptions().length<=this.settings.minSelected}getMinimumSelectionIds(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.slice(0,this.settings.minSelected).map(e=>e.id)}getValueChips(){return!this.settings.isMultiple||this.settings.multiString?[]:Array.from(this.main.values.querySelectorAll(`.`+this.classes.getFirst(`value`))).filter(e=>{if(e.classList.contains(this.classes.getFirst(`valueOut`)))return!1;let t=e.querySelector(`.`+this.classes.getFirst(`valueDelete`));return!!t&&!t.classList.contains(this.classes.getFirst(`hide`))})}getHighlightedValueChip(){return this.getValueChips().find(e=>e.classList.contains(this.classes.getFirst(`highlighted`)))??null}clearValueChipHighlight(){for(let e of Array.from(this.main.values.querySelectorAll(`.`+this.classes.getFirst(`value`))))this.removeClasses(e,this.classes.highlighted)}highlightValueChip(e){this.clearValueChipHighlight(),e&&this.addClasses(e,this.classes.highlighted)}navigateValueChips(e){let t=this.getValueChips();if(t.length===0)return!1;let n=this.getHighlightedValueChip(),r=n?t.indexOf(n):-1;return e===`left`?(r===-1?this.highlightValueChip(t[t.length-1]):r>0&&this.highlightValueChip(t[r-1]),!0):r!==-1&&(r<t.length-1?this.highlightValueChip(t[r+1]):this.clearValueChipHighlight(),!0)}deleteValueChip(e=!1){let t=this.getValueChips();if(t.length===0)return!1;let n=this.getHighlightedValueChip();if(e&&!n)return!1;let r=n??t[t.length-1],i=r.querySelector(`.`+this.classes.getFirst(`valueDelete`));if(!i)return!1;let a=t.indexOf(r),o=n?t[a-1]??t[a+1]??null:null;return i.click(),o&&o!==r&&this.main.values.contains(o)?this.highlightValueChip(o):this.clearValueChipHighlight(),!0}updateMultipleValueDeleteVisibility(){if(!this.settings.isMultiple||this.settings.multiString)return;let e=!this.isAtMinSelected(),t=this.main.values.querySelectorAll(`.`+this.classes.getFirst(`valueDelete`));for(let n of t)e?this.removeClasses(n,this.classes.hide):this.addClasses(n,this.classes.hide)}multipleValue(e){let t=document.createElement(`div`);this.addClasses(t,this.classes.value),t.dataset.id=e.id;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.valueText),n.textContent=e.text,t.appendChild(n),!e.mandatory){let n=document.createElement(`div`);this.addClasses(n,this.classes.valueDelete),n.setAttribute(`tabindex`,`0`),n.setAttribute(`role`,`button`),n.setAttribute(`aria-label`,`${this.settings.removeText} ${e.text}`),this.isAtMinSelected()&&this.addClasses(n,this.classes.hide),n.onclick=t=>{if(t.preventDefault(),t.stopPropagation(),this.settings.disabled)return;let n=!0,r=this.store.getSelectedOptions(),i=r.filter(t=>t.selected&&t.id!==e.id,!0);if(!(this.settings.minSelected&&i.length<this.settings.minSelected)&&(this.callbacks.beforeChange&&(n=this.callbacks.beforeChange(i,r)===!0),n)){let e=[];for(let t of i){if(t instanceof M)for(let n of t.options)n.id&&e.push(n.id);t instanceof j&&e.push(t.id)}this.callbacks.setSelected(e,!1),this.settings.closeOnSelect&&this.requestClose(`deselect`,{selectionChanged:!0}),this.callbacks.afterChange&&this.callbacks.afterChange(i),this.updateDeselectAll(),this.updateMultipleValueDeleteVisibility()}};let r=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);r.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.optionDelete),r.appendChild(i),n.appendChild(r),t.appendChild(n),n.onkeydown=e=>{e.key===`Enter`&&n.click()}}return t}contentDiv(){let e=document.createElement(`div`);e.dataset.id=this.settings.id;let t=this.searchDiv();e.appendChild(t.main);let n=document.createElement(`div`);this.addClasses(n,this.classes.status),n.setAttribute(`aria-live`,`polite`),n.setAttribute(`aria-atomic`,`true`),n.setAttribute(`role`,`status`),e.appendChild(n);let r=this.listDiv();return e.appendChild(r),{main:e,search:t,status:n,list:r}}announce(e){this.settings.showSearch&&(this.content.status.textContent=e)}repositionOpenContent(){this.settings.isOpen&&!this.isModalViewActive()&&this.settings.contentPosition!==`relative`&&this.content.main.classList.contains(this.classes.getFirst(`dirAbove`))&&this.moveContentAbove()}moveContent(){if(!this.isModalViewActive()){if(this.settings.contentPosition===`relative`){this.moveContentBelow();return}if(this.settings.openPosition===`down`){this.moveContentBelow();return}if(this.settings.openPosition===`up`){this.moveContentAbove();return}this.putContent()===`up`?this.moveContentAbove():this.moveContentBelow()}}startPositionTracking(){this.settings.contentPosition!==`absolute`||this.isModalViewActive()||(this.stopPositionTracking(),typeof ResizeObserver<`u`&&(this.lastObservedContentHeight=-1,this.positionObserver=new ResizeObserver(e=>{if(!this.settings.isOpen)return;let t=!1,n=!1;for(let r of e)if(r.target===this.content.main){let e=r.contentRect.height;e!==this.lastObservedContentHeight&&(this.lastObservedContentHeight=e,t=!0)}else n=!0;(t||n)&&(cancelAnimationFrame(this.positionObserverRaf),this.positionObserverRaf=requestAnimationFrame(()=>{n?this.moveContent():this.repositionOpenContent()}))}),this.observePositionTargets()))}stopPositionTracking(){cancelAnimationFrame(this.positionObserverRaf),this.positionObserver?.disconnect(),this.positionObserver=null,this.lastObservedContentHeight=-1,this.cancelOverflowShift()}observePositionTargets(){if(!this.positionObserver)return;let e=new Set,t=t=>{t&&!e.has(t)&&(e.add(t),this.positionObserver.observe(t))};t(this.main.main),t(this.content.main);let n=this.main.main.parentElement,r=this.settings.contentLocation;for(let e=0;n&&e<8&&(t(n),n!==r);e++)n=n.parentElement}searchDiv(){let e=document.createElement(`div`),t=document.createElement(`input`),n=document.createElement(`div`);this.addClasses(e,this.classes.search);let r={main:e,input:t},i=this.settings.selectAll&&this.settings.isMultiple;this.settings.showSearch||(t.readOnly=!0,i?this.addClasses(t,this.classes.hide):this.addClasses(e,this.classes.hide)),t.type=`search`,t.id=`${this.settings.id}-search`,t.placeholder=this.settings.searchPlaceholder,t.tabIndex=-1,t.setAttribute(`aria-label`,this.settings.searchPlaceholder),t.setAttribute(`aria-autocomplete`,`list`),t.setAttribute(`autocapitalize`,`off`),t.setAttribute(`autocomplete`,`off`),t.setAttribute(`autocorrect`,`off`),t.setAttribute(`aria-hidden`,`true`);let a=v(()=>{this.callbacks.search(t.value)},100);if(t.oninput=e=>{e.target.value!==``&&this.clearValueChipHighlight(),a()},t.onkeydown=e=>{switch(e.key){case`ArrowUp`:case`ArrowDown`:return this.clearValueChipHighlight(),e.key===`ArrowDown`?this.highlight(`down`):this.highlight(`up`),!1;case`ArrowLeft`:case`ArrowRight`:return t.value!==``||!this.navigateValueChips(e.key===`ArrowLeft`?`left`:`right`)||(e.preventDefault(),!1);case`Backspace`:return t.value!==``||!this.deleteValueChip()||(e.preventDefault(),!1);case`Delete`:return t.value!==``||!this.getHighlightedValueChip()||!this.deleteValueChip(!0)||(e.preventDefault(),!1);case`Tab`:return this.requestClose(`tab`),!0;case`Escape`:return this.requestClose(`escape`),!1;case`Enter`:let r=this.content.list.querySelector(`.`+this.classes.getFirst(`highlighted`));return r?(r.click(),!1):!this.callbacks.addable||(n.click(),!1)}return e.key.length===1&&this.clearValueChipHighlight(),!0},e.appendChild(t),i){let t=this.createSelectAllControl(()=>this.toggleGlobalSelectAll());e.appendChild(t),r.selectAll=t}if(this.callbacks.addable){this.addClasses(n,this.classes.addable);let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);t.setAttribute(`viewBox`,`0 0 100 100`);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.setAttribute(`d`,this.classes.addablePath),t.appendChild(i),n.appendChild(t),n.onclick=e=>{if(e.preventDefault(),e.stopPropagation(),!this.callbacks.addable)return;let t=this.content.search.input.value.trim();if(t===``){this.content.search.input.focus();return}let n=e=>{let t=new j(e);if(this.callbacks.addOption(t),this.settings.isMultiple){let e=this.store.getSelected();e.push(t.id),this.callbacks.setSelected(e,!0)}else this.callbacks.setSelected([t.id],!0);if(this.callbacks.search(``),this.settings.closeOnSelect){let e=o(this.content.main);setTimeout(()=>{this.requestClose(`select`,{selectionChanged:!0})},e)}},r=this.callbacks.addable(t);r!==!1&&r!=null&&(r instanceof Promise?r.then(e=>{typeof e==`string`?n({text:e,value:e}):r instanceof Error?this.renderError(r.message):n(e)}):typeof r==`string`?n({text:r,value:r}):r instanceof Error?this.renderError(r.message):n(r))},e.appendChild(n),r.addable={main:n,svg:t,path:i}}return r}searchFocus(){this.content.search.input.focus({preventScroll:!0})}getOptions(e=!1,t=!1,n=!1){let r=`.`+this.classes.getFirst(`option`);return e&&(r+=`:not(.`+this.classes.getFirst(`placeholder`)+`)`),t&&(r+=`:not(.`+this.classes.getFirst(`disabled`)+`)`),n&&(r+=`:not(.`+this.classes.getFirst(`hide`)+`)`),Array.from(this.content.list.querySelectorAll(r))}highlight(e){let t=this.getOptions(!0,!0,!0);if(t.length===0)return;if(t.length===1&&!t[0].classList.contains(this.classes.getFirst(`highlighted`))){this.addClasses(t[0],this.classes.highlighted);return}let n=!1;for(let e of t)e.classList.contains(this.classes.getFirst(`highlighted`))&&(n=!0);if(!n){for(let e of t)if(e.classList.contains(this.classes.getFirst(`selected`))){this.addClasses(e,this.classes.highlighted);break}}for(let n=0;n<t.length;n++)if(t[n].classList.contains(this.classes.getFirst(`highlighted`))){let r=t[n];this.removeClasses(r,this.classes.highlighted);let i=r.parentElement;if(i&&i.classList.contains(this.classes.getFirst(`mainOpen`))){let e=i.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}let a=t[e===`down`?n+1<t.length?n+1:0:n-1>=0?n-1:t.length-1];this.addClasses(a,this.classes.highlighted),this.ensureElementInView(this.content.list,a),a.id&&this.main.main.setAttribute(`aria-activedescendant`,a.id);let o=a.parentElement;if(o&&o.classList.contains(this.classes.getFirst(`close`))){let e=o.querySelector(`.`+this.classes.getFirst(`optgroupLabel`));e&&e.click()}return}let r=t[e===`down`?0:t.length-1];this.addClasses(r,this.classes.highlighted),r.id&&this.main.main.setAttribute(`aria-activedescendant`,r.id),this.ensureElementInView(this.content.list,r)}listDiv(){let e=document.createElement(`div`);this.addClasses(e,this.classes.list);let t=this.settings.id+`-list`;return e.id=t,e.dataset.id=t,e}renderError(e){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let t=document.createElement(`div`);this.addClasses(t,this.classes.error),t.textContent=e,this.content.list.appendChild(t),this.repositionOpenContent()}renderSearching(){this.optionsListIsFullData=!1,this.content.list.innerHTML=``;let e=document.createElement(`div`);this.addClasses(e,this.classes.searching),e.textContent=this.settings.searchingText,this.content.list.appendChild(e),this.announce(this.settings.searchingText),this.repositionOpenContent()}renderOptions(e){if(this.lastSearchFilterTerm=``,this.lastRenderedOptions=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat(),this.content.list.innerHTML=``,e.length===0){this.optionsListIsFullData=!1;let e=document.createElement(`div`);if(this.addClasses(e,this.classes.search),this.callbacks.addable){let t=this.settings.addableText.replace(`{value}`,this.content.search.input.value);e.innerHTML=t,this.announce(t)}else e.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(e),this.repositionOpenContent();return}this.settings.allowDeselect&&!this.settings.isMultiple&&(this.store.filter(e=>e.placeholder,!1,!1).length||this.store.addOption(new j({text:``,value:``,selected:!1,placeholder:!0}),!0));let t=document.createDocumentFragment();for(let n of e){if(n instanceof M){let e=document.createElement(`div`);this.addClasses(e,this.classes.optgroup);let r=document.createElement(`div`);this.addClasses(r,this.classes.optgroupLabel),e.appendChild(r);let i=document.createElement(`div`);this.addClasses(i,this.classes.optgroupLabelText),i.textContent=n.label,r.appendChild(i);let a=document.createElement(`div`);if(this.addClasses(a,this.classes.optgroupActions),r.appendChild(a),this.settings.isMultiple&&n.selectAll){let e=this.createSelectAllControl(()=>{let e=this.store.getSelected();if(this.isOptgroupAllSelected(n.options,new Set(e))){let t=e.filter(e=>{for(let t of n.options)if(e===t.id)return!1;return!0});this.callbacks.setSelected(t,!0);return}{let t=n.options.map(e=>e.id).filter(e=>e!==void 0),r=e.concat(t);for(let e of n.options)e.id&&!this.store.getOptionByID(e.id)&&this.callbacks.addOption(new j(e));this.callbacks.setSelected(r,!0);return}},this.isOptgroupAllSelected(n.options));a.appendChild(e)}if(n.closable!==`off`){let t=document.createElement(`div`);this.addClasses(t,this.classes.optgroupClosable);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),this.addClasses(i,this.classes.arrow),t.appendChild(i);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);i.appendChild(o),n.options.some(e=>e.selected)||this.content.search.input.value.trim()!==``?(this.addClasses(t,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`open`?(this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)):n.closable===`close`&&(this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)),r.addEventListener(`click`,n=>{n.preventDefault(),n.stopPropagation(),this.isClosableOptgroupOpen(e,t)?(this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close),o.setAttribute(`d`,this.classes.arrowClose)):(this.closeOtherClosableOptgroups(e),this.removeClasses(e,this.classes.close),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.mainOpen),o.setAttribute(`d`,this.classes.arrowOpen)),this.repositionOpenContent()}),a.appendChild(t)}e.appendChild(r);for(let r of n.options)e.appendChild(this.option(new j(r))),t.appendChild(e)}n instanceof j&&t.appendChild(this.option(n))}this.content.list.appendChild(t),this.setOptionsListFullData(e),this.announce(this.settings.resultsText.replace(`{count}`,String(this.lastRenderedOptions.length))),this.updateGlobalSelectAllState(),this.repositionOpenContent()}canFilterOptionsInPlace(){return this.optionsListIsFullData?this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null:!1}resetSearchFilterState(){this.lastSearchFilterTerm=``}filterOptionsInPlace(e,t){let n=e.trim();if(n===this.lastSearchFilterTerm)return;this.lastSearchFilterTerm=n;let r=[],i=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`));for(let e of i){let i=e.dataset.id;if(!i)continue;let a=this.store.getOptionByID(i);if(!a)continue;let o=a.placeholder||!a.display||a.selected&&this.settings.hideSelected,s=t(a,n);o||!s?(this.addClasses(e,this.classes.hide),this.removeClasses(e,this.classes.highlighted)):(this.removeClasses(e,this.classes.hide),this.setOptionElementContent(e,a,n),r.push(a)),a.selected?(this.addClasses(e,this.classes.selected),e.setAttribute(`aria-selected`,`true`)):(this.removeClasses(e,this.classes.selected),e.setAttribute(`aria-selected`,`false`))}this.lastRenderedOptions=r,this.updateOptgroupVisibilityAfterSearch(n),r.length===0?this.updateSearchResultsMessage(0,n):(this.removeListSearchMessage(),this.announce(this.settings.resultsText.replace(`{count}`,String(r.length)))),this.updateOptgroupSelectAllStates(),this.updateGlobalSelectAllState(),this.repositionOpenContent()}setOptionsListFullData(e){let t=this.store.getDataOptions(!1),n=e.map(e=>e instanceof j?[e]:e.options.map(e=>new j(e))).flat();if(n.length!==t.length){this.optionsListIsFullData=!1;return}let r=new Set(t.map(e=>e.id));this.optionsListIsFullData=n.every(e=>r.has(e.id))}isClosableOptgroupOpen(e,t){return e.classList.contains(this.classes.getFirst(`close`))?!1:e.classList.contains(this.classes.getFirst(`mainOpen`))||t.classList.contains(this.classes.getFirst(`mainOpen`))}closeClosableOptgroup(e){let t=e.querySelector(`.`+this.classes.getFirst(`optgroupClosable`));if(!t||e.classList.contains(this.classes.getFirst(`close`)))return;this.removeClasses(e,this.classes.mainOpen),this.removeClasses(t,this.classes.mainOpen),this.addClasses(e,this.classes.close);let n=t.querySelector(`path`);n&&n.setAttribute(`d`,this.classes.arrowClose)}closeOtherClosableOptgroups(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t)n!==e&&this.closeClosableOptgroup(n)}updateOptgroupVisibilityAfterSearch(e){let t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),r=!1;for(let e of t)if(!e.classList.contains(this.classes.getFirst(`hide`))){r=!0;break}if(!r){this.addClasses(n,this.classes.hide);continue}this.removeClasses(n,this.classes.hide),e!==``&&(this.removeClasses(n,this.classes.close),this.addClasses(n,this.classes.mainOpen))}}updateSearchResultsMessage(e,t){if(this.removeListSearchMessage(),e>0)return;let n=document.createElement(`div`);if(this.addClasses(n,this.classes.search),this.callbacks.addable){let e=this.settings.addableText.replace(`{value}`,t);n.innerHTML=e,this.announce(e)}else n.innerHTML=this.settings.searchText,this.announce(this.settings.searchText);this.content.list.appendChild(n)}removeListSearchMessage(){this.content.list.querySelectorAll(`.`+this.classes.getFirst(`search`)).forEach(e=>e.remove())}setOptionElementContent(e,t,n){let r=n.trim();this.settings.searchHighlight&&r!==``?e.innerHTML=this.highlightText(t.html===``?t.text:t.html,r,this.classes.searchHighlighter):t.html===``?e.textContent=t.text:e.innerHTML=t.html,this.settings.showOptionTooltips&&e.textContent?e.setAttribute(`title`,e.textContent):e.removeAttribute(`title`)}hasRenderedOptions(){return this.content.list.querySelector(`.`+this.classes.getFirst(`option`))!==null}canUpdateOptionSelectionInPlace(){return this.content.search.input.value.trim()===``&&this.hasRenderedOptions()}updateOptionSelection(){let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`option`)),n=null;for(let r of t){let t=r.dataset.id;if(!t)continue;let i=this.store.getOptionByID(t);if(!i)continue;let a=e.has(t);a?(this.addClasses(r,this.classes.selected),r.setAttribute(`aria-selected`,`true`),n=r):(this.removeClasses(r,this.classes.selected),r.setAttribute(`aria-selected`,`false`)),this.settings.hideSelected&&(a?this.addClasses(r,this.classes.hide):(this.removeClasses(r,this.classes.hide),i.display||this.addClasses(r,this.classes.hide)))}!this.settings.isMultiple&&n?this.main.main.setAttribute(`aria-activedescendant`,n.id):!this.settings.isMultiple&&e.size===0&&this.main.main.removeAttribute(`aria-activedescendant`),this.updateOptgroupSelectAllStates(),this.updateGlobalSelectAllState(),this.repositionOpenContent()}createSelectAllControl(e,t=!1){let n=document.createElement(`div`);this.addClasses(n,this.classes.optgroupSelectAll),n.setAttribute(`role`,`checkbox`),n.setAttribute(`aria-checked`,t?`true`:`false`),n.setAttribute(`aria-label`,this.selectAllLabel(t)),n.tabIndex=-1,t&&this.addClasses(n,this.classes.selected);let r=document.createElement(`span`);r.textContent=this.selectAllLabel(t),n.appendChild(r);let i=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);i.setAttribute(`viewBox`,`0 0 100 100`),i.setAttribute(`aria-hidden`,`true`),n.appendChild(i);let a=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);a.setAttribute(`d`,this.classes.optgroupSelectAllBox),i.appendChild(a);let o=document.createElementNS(`http://www.w3.org/2000/svg`,`path`);return o.setAttribute(`d`,this.classes.optgroupSelectAllCheck),i.appendChild(o),n.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation(),e()}),n}getSelectableOptions(){return this.store.getDataOptions(!1).filter(e=>!e.disabled&&!e.placeholder&&e.display)}isGlobalAllSelected(e){let t=this.getSelectableOptions();if(t.length===0)return!1;let n=e||new Set(this.store.getSelected());for(let e of t)if(!n.has(e.id))return!1;return!0}toggleGlobalSelectAll(){let e=this.getSelectableOptions(),t=new Set(this.store.getSelected());if(this.isGlobalAllSelected(t)){let t=new Set(e.map(e=>e.id)),n=this.store.getSelected().filter(e=>!t.has(e));this.callbacks.setSelected(n,!0);return}this.callbacks.setSelected(e.map(e=>e.id),!0)}updateGlobalSelectAllState(){let e=this.content.search.selectAll;if(!e||!this.settings.isMultiple||!this.settings.selectAll)return;let t=this.isGlobalAllSelected();t?this.addClasses(e,this.classes.selected):this.removeClasses(e,this.classes.selected),e.setAttribute(`aria-checked`,t?`true`:`false`),e.setAttribute(`aria-label`,this.selectAllLabel(t));let n=e.querySelector(`span`);n&&(n.textContent=this.selectAllLabel(t))}updateOptgroupSelectAllStates(){if(!this.settings.isMultiple)return;let e=new Set(this.store.getSelected()),t=this.content.list.querySelectorAll(`.`+this.classes.getFirst(`optgroup`));for(let n of t){let t=n.querySelector(`.`+this.classes.getFirst(`optgroupSelectAll`));if(!t)continue;let r=n.querySelectorAll(`.`+this.classes.getFirst(`option`)),i=r.length>0;for(let t of r){let n=t.dataset.id;if(!n||!e.has(n)){i=!1;break}}i?this.addClasses(t,this.classes.selected):this.removeClasses(t,this.classes.selected),t.setAttribute(`aria-checked`,i?`true`:`false`),t.setAttribute(`aria-label`,this.selectAllLabel(i));let a=t.querySelector(`span`);a&&(a.textContent=this.selectAllLabel(i))}}selectAllLabel(e){return e?this.settings.unselectAllText:this.settings.selectAllText}isOptgroupAllSelected(e,t){if(e.length===0)return!1;for(let n of e)if(!(t?n.id&&t.has(n.id):n.selected))return!1;return!0}option(e){if(e.placeholder){let e=document.createElement(`div`);return this.addClasses(e,this.classes.option),this.addClasses(e,this.classes.hide),e}let t=document.createElement(`div`);return t.dataset.id=e.id,t.id=this.settings.id+`-`+e.id,this.addClasses(t,this.classes.option),t.setAttribute(`role`,`option`),e.class&&e.class.split(` `).forEach(e=>{t.classList.add(e)}),e.style&&(t.style.cssText=e.style),this.setOptionElementContent(t,e,this.content.search.input.value),e.display||this.addClasses(t,this.classes.hide),e.disabled&&this.addClasses(t,this.classes.disabled),e.selected&&this.settings.hideSelected&&this.addClasses(t,this.classes.hide),e.selected?(this.addClasses(t,this.classes.selected),t.setAttribute(`aria-selected`,`true`),this.main.main.setAttribute(`aria-activedescendant`,t.id)):(this.removeClasses(t,this.classes.selected),t.setAttribute(`aria-selected`,`false`)),t.addEventListener(`click`,t=>{t.preventDefault(),t.stopPropagation();let n=this.store.getSelected(),r=t.currentTarget,i=String(r.dataset.id),a=this.store.getOptionByID(i)??e,o=n.includes(i),s=t.ctrlKey||t.metaKey;if(e.disabled)return;if(!this.settings.isMultiple&&o&&!this.settings.allowDeselect){this.closeOnSingleSelectReclick(a);return}if(o&&a.mandatory){this.closeOnSingleSelectReclick(a);return}if(this.settings.isMultiple&&this.settings.maxSelected<=n.length&&!o||this.settings.isMultiple&&this.settings.minSelected>=n.length&&o&&!s)return;let c=!1,l=this.store.getSelectedOptions(),u=[];if(this.settings.isMultiple){let n=l.some(e=>e.id===i);if(t.shiftKey&&this.lastSelectedOption){let t=this.lastRenderedOptions,n=t.findIndex(e=>e.id===this.lastSelectedOption.id),r=t.findIndex(t=>t.id===e.id);if(n>=0&&r>=0){let e=Math.min(n,r),i=Math.max(n,r),a=t.slice(e,i+1).filter(e=>!l.find(t=>t.id===e.id));u=l.length+a.length<=this.settings.maxSelected?l.concat(a):l}else u=l}else u=n?l.filter(e=>e.id!==i):l.concat(a),this.lastSelectedOption=a}if(this.settings.isMultiple||(u=o?[]:[a]),this.callbacks.beforeChange||(c=!0),this.callbacks.beforeChange&&(c=this.callbacks.beforeChange(u,l)!==!1),c){this.store.getOptionByID(i)||this.callbacks.addOption(e),this.callbacks.setSelected(u.map(e=>e.id),!1);let n=t.ctrlKey||t.metaKey||t.shiftKey;this.settings.closeOnSelect&&!(this.settings.isMultiple&&n)&&this.requestClose(`select`,{option:a,selectionChanged:this.selectionChanged(l,u)}),this.callbacks.afterChange&&this.callbacks.afterChange(u)}}),t}destroy(){this.stopPositionTracking(),this.modalElements?(this.unlockBodyScroll(),this.content.main.parentElement===this.modalElements.dialog&&this.restoreContentOffscreen(),this.modalElements.overlay.remove(),this.modalElements=null):this.bodyScrollLocked&&this.unlockBodyScroll(),this.main.main.remove(),this.content.main.remove(),this.removeDetachedInstanceDom()}removeDetachedInstanceDom(){let e=this.settings.id,t=this.classes.getFirst(`main`),n=this.classes.getFirst(`content`),r=this.classes.getFirst(`modalOverlay`);document.querySelectorAll(`[data-id="${e}"]`).forEach(e=>{(e.classList.contains(t)||e.classList.contains(n)||e.classList.contains(r))&&e.remove()})}highlightText(e,t,n){let r=t.trim();if(r===``)return e;let i=r.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),a=document.createElement(`div`);a.innerHTML=e;let o=e=>{if(e.nodeType===Node.TEXT_NODE){let t=e.textContent||``,r=RegExp(`(`+i+`)`,`i`);if(r.test(t)){let i=document.createElement(`span`);t.split(r).forEach((e,t)=>{if(e&&r.test(e)){let t=document.createElement(`mark`);t.className=n,t.textContent=e,i.appendChild(t)}else e&&i.appendChild(document.createTextNode(e))}),e.parentNode?.replaceChild(i,e)}}else e.nodeType===Node.ELEMENT_NODE&&Array.from(e.childNodes).forEach(e=>o(e))};return Array.from(a.childNodes).forEach(e=>o(e)),a.innerHTML}setContentDirection(e){let t=e===`above`,n=t?this.classes.dirAbove:this.classes.dirBelow,r=t?this.classes.dirBelow:this.classes.dirAbove;if(this.removeClasses(this.main.main,r),this.addClasses(this.main.main,n),this.removeClasses(this.content.main,r),this.addClasses(this.content.main,n),t){let e=this.main.main.offsetHeight,t=this.content.main.offsetHeight;this.content.main.style.margin=`-`+(e+t-1)+`px 0px 0px 0px`}else this.content.main.style.margin=`-1px 0px 0px 0px`}setContentPosition(){let e=this.main.main.getBoundingClientRect();if(this.settings.contentPosition===`relative`){this.applyContentWidth(e);return}this.cancelOverflowShift();let t,n;this.settings.contentPosition===`fixed`?(t=e.top+e.height,n=e.left):(t=e.top+window.scrollY+e.height,n=e.left+window.scrollX),this.content.main.style.top=t+`px`,this.content.main.style.left=n+`px`,this.applyContentWidth(e);let r=this.getKnownContentWidth(e);if(r!==null){this.content.main.style.left=this.adjustLeftForOverflow(n,e.left,r)+`px`;return}this.overflowShiftRaf=requestAnimationFrame(()=>{this.overflowShiftRaf=0,this.applyOverflowShiftFromMeasure()})}applyContentWidth(e){let t=this.settings.contentWidth;if(this.content.main.style.width=``,this.content.main.style.minWidth=``,this.content.main.style.maxWidth=``,!t){this.settings.contentPosition!==`relative`&&(this.content.main.style.width=e.width+`px`);return}t===`auto`?this.content.main.style.minWidth=e.width+`px`:t.startsWith(`>`)?this.content.main.style.minWidth=t.slice(1):t.startsWith(`<`)?this.content.main.style.maxWidth=t.slice(1):this.content.main.style.width=t}cancelOverflowShift(){this.overflowShiftRaf&&=(cancelAnimationFrame(this.overflowShiftRaf),0)}getKnownContentWidth(e){let t=this.settings.contentWidth;if(!t)return e.width;if(t.startsWith(`>`)||t.startsWith(`<`)||t.includes(`%`))return null;let n=parseFloat(t);return Number.isNaN(n)?null:n}adjustLeftForOverflow(e,t,n){let r=t+n;if(r<=window.innerWidth)return e;let i=e-(r-(window.innerWidth-20));return this.settings.contentPosition===`fixed`?Math.max(0,i):Math.max(window.scrollX,i)}applyOverflowShiftFromMeasure(){let e=this.content.main.getBoundingClientRect().right;if(e<=window.innerWidth)return;let t=e-(window.innerWidth-20),n=(parseFloat(this.content.main.style.left)||0)-t;this.settings.contentPosition===`fixed`?this.content.main.style.left=Math.max(0,n)+`px`:this.content.main.style.left=Math.max(window.scrollX,n)+`px`}moveContentAbove(){this.setContentDirection(`above`),this.setContentPosition()}moveContentBelow(){this.setContentDirection(`below`),this.setContentPosition()}ensureElementInView(e,t){let n=e.scrollTop+e.offsetTop,r=n+e.clientHeight,i=t.offsetTop,a=i+t.clientHeight;i<n?e.scrollTop-=n-i:a>r&&(e.scrollTop+=a-r)}putContent(){let e=this.main.main.offsetHeight,t=this.main.main.getBoundingClientRect(),n=this.content.main.offsetHeight;return window.innerHeight-(t.top+e)<=n&&t.top>n?`up`:`down`}updateDeselectAll(){if(!this.store||!this.settings)return;let e=this.store.getSelectedOptions(),t=e&&e.length>0,n=this.settings.isMultiple,r=this.settings.allowDeselect,i=this.isAtMinSelected(),a=this.main.deselect.main,o=this.classes.hide;r&&(!n||t)&&!i?this.removeClasses(a,o):this.addClasses(a,o)}};function F(e,t){let n={classChanged:!1,disabledChanged:!1,optgroupOptionChanged:!1,selectionChanged:!1};for(let r of e){if(r.target===t&&(r.attributeName===`disabled`&&(n.disabledChanged=!0),r.attributeName===`class`&&(n.classChanged=!0),r.type===`childList`)){for(let e of Array.from(r.addedNodes))if(e.nodeName===`OPTION`&&e.value===t.value){n.selectionChanged=!0;break}n.optgroupOptionChanged=!0}(r.target.nodeName===`OPTGROUP`||r.target.nodeName===`OPTION`)&&(n.optgroupOptionChanged=!0)}return n}var I=class{select;onValueChange;onClassChange;onDisabledChange;onOptionsChange;onLabelClick;listen=!1;observer=null;isUpdating=!1;pendingOptionsChange=null;preventNativeSelect=null;preventNativeSelectMousedown=null;preventNativeSelectFocus=null;restoreAriaHiddenOnBlur=null;constructor(e){this.select=e,this.valueChange=this.valueChange.bind(this),this.select.addEventListener(`change`,this.valueChange,{passive:!0}),this.observer=new MutationObserver(this.observeCall.bind(this)),this.changeListen(!0)}enable(){this.select.disabled=!1}disable(){this.select.disabled=!0}hideUI(){this.select.tabIndex=-1,this.select.style.position=`absolute`,this.select.style.width=`1px`,this.select.style.height=`1px`,this.select.style.opacity=`0`,this.select.style.overflow=`hidden`,this.select.style.pointerEvents=`none`,this.select.style.margin=`0`,this.select.style.padding=`0`,this.select.style.borderWidth=`0`,this.select.style.clipPath=`inset(50%)`,document.activeElement!==this.select&&this.select.setAttribute(`aria-hidden`,`true`),this.preventNativeSelect||(this.preventNativeSelect=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectMousedown=e=>{e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.preventNativeSelectFocus=e=>{this.select.removeAttribute(`aria-hidden`),e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation()},this.restoreAriaHiddenOnBlur=()=>{this.select.setAttribute(`aria-hidden`,`true`)},this.select.addEventListener(`click`,this.preventNativeSelect,{capture:!0,passive:!1}),this.select.addEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0,passive:!1}),this.select.addEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0,passive:!1}),this.select.addEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0,passive:!0}))}showUI(){this.select.removeAttribute(`tabindex`),this.select.style.position=``,this.select.style.width=``,this.select.style.height=``,this.select.style.opacity=``,this.select.style.overflow=``,this.select.style.pointerEvents=``,this.select.style.margin=``,this.select.style.padding=``,this.select.style.borderWidth=``,this.select.style.clipPath=``,this.select.removeAttribute(`aria-hidden`),this.preventNativeSelect&&=(this.select.removeEventListener(`click`,this.preventNativeSelect,{capture:!0}),null),this.preventNativeSelectMousedown&&=(this.select.removeEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0}),null),this.preventNativeSelectFocus&&=(this.select.removeEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0}),null),this.restoreAriaHiddenOnBlur&&=(this.select.removeEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0}),null)}changeListen(e){this.listen=e,e&&this.observer&&this.observer.observe(this.select,{subtree:!0,childList:!0,attributes:!0}),e||this.observer&&this.observer.disconnect()}valueChange(e){return this.listen&&this.onValueChange&&this.onValueChange(this.getSelectedOptions()),!0}observeCall(e){if(!this.listen)return;let{classChanged:t,disabledChanged:n,optgroupOptionChanged:r,selectionChanged:i}=F(e,this.select),a=i;if(t&&this.onClassChange&&this.onClassChange(this.select.className.split(` `)),n&&this.onDisabledChange&&(this.changeListen(!1),this.onDisabledChange(this.select.disabled),this.changeListen(!0)),r&&this.clearLeftoverHiddenDisplay(e),r&&this.onOptionsChange){if(this.isUpdating){if(this.select.options.length>0){let e=this.getData();e.length>0&&(this.pendingOptionsChange=e)}a&&this.select.dispatchEvent(new Event(`change`));return}this.changeListen(!1),this.onOptionsChange(this.getData()),this.changeListen(!0),a=!1}a&&this.select.dispatchEvent(new Event(`change`))}getData(){let e=[],t=this.select.childNodes;for(let n of t)n.nodeName===`OPTGROUP`&&e.push(this.getDataFromOptgroup(n)),n.nodeName===`OPTION`&&e.push(this.getDataFromOption(n));return e}getDataFromOptgroup(e){let t={id:e.id,label:e.label,selectAll:e.dataset?e.dataset.selectall===`true`:!1,closable:e.dataset?e.dataset.closable:`off`,options:[]},n=e.childNodes;for(let e of n)e.nodeName===`OPTION`&&t.options.push(this.getDataFromOption(e));return t}clearLeftoverHiddenDisplay(e){for(let t of e){if(t.target.nodeName!==`OPTION`||t.attributeName!==`hidden`)continue;let e=t.target;!e.hidden&&e.style.display===`none`&&(e.style.display=``)}}getDataFromOption(e){let t=e.hidden||e.hasAttribute(`hidden`);return{id:e.id,value:e.value,text:e.text,html:e.dataset&&e.dataset.html?e.dataset.html:``,defaultSelected:e.defaultSelected,selected:e.selected,display:e.style.display!==`none`&&!t,disabled:e.disabled,mandatory:e.dataset?e.dataset.mandatory===`true`:!1,placeholder:e.dataset.placeholder===`true`,class:e.className,style:e.style.cssText,data:p(e.dataset)}}getSelectedOptions(){let e=[],t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}if(n.nodeName===`OPTION`){let t=n;t.selected&&e.push(this.getDataFromOption(t))}}return e}getSelectedValues(){return this.getSelectedOptions().map(e=>e.value)}hasOptionValues(e){if(e.length===0)return!0;let t=new Set(Array.from(this.select.options).map(e=>e.value));return e.every(e=>t.has(e))}setSelected(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.id)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0)}setSelectedByValue(e){this.changeListen(!1);let t=this.select.childNodes;for(let n of t){if(n.nodeName===`OPTGROUP`){let t=n.childNodes;for(let n of t)if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}if(n.nodeName===`OPTION`){let t=n;t.selected=e.includes(t.value)}}let n=this.getSelectedOptions();this.select.multiple||(this.select.value=n.length===1?n[0].value:``),this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0)}updateSelect(e,t,n){this.changeListen(!1),e&&(this.select.dataset.id=e),t&&(this.select.style.cssText=t),n&&(this.select.className=``,n.forEach(e=>{e.trim()!==``&&this.select.classList.add(e.trim())})),this.changeListen(!0)}updateOptions(e){if(!e||e.length===0)return;this.isUpdating=!0,this.pendingOptionsChange=null,this.changeListen(!1);let t=this.getSelectedValues();this.select.innerHTML=``;for(let t of e)t instanceof M&&this.select.appendChild(this.createOptgroup(t)),t instanceof j&&this.select.appendChild(this.createOption(t));if(y(t,this.getSelectedValues())||this.select.dispatchEvent(new Event(`change`,{bubbles:!0})),this.changeListen(!0),this.isUpdating=!1,this.pendingOptionsChange!==null){let e=this.pendingOptionsChange;e.length>0&&this.onOptionsChange?(this.pendingOptionsChange=null,this.changeListen(!1),this.onOptionsChange(e),this.changeListen(!0)):this.pendingOptionsChange=null}}createOptgroup(e){let t=document.createElement(`optgroup`);if(t.id=e.id,t.label=e.label,e.selectAll&&(t.dataset.selectAll=`true`),e.closable!==`off`&&(t.dataset.closable=e.closable),e.options)for(let n of e.options)t.appendChild(this.createOption(n));return t}createOption(e){let t=document.createElement(`option`);return t.id=e.id,t.value=e.value,t.textContent=e.text,e.html!==``&&t.setAttribute(`data-html`,e.html),t.defaultSelected=e.defaultSelected,t.selected=e.selected,e.disabled&&(t.disabled=!0),t.hidden=!e.display,e.placeholder&&t.setAttribute(`data-placeholder`,`true`),e.mandatory&&t.setAttribute(`data-mandatory`,`true`),e.class&&e.class.split(` `).forEach(e=>{t.classList.add(e)}),e.data&&typeof e.data==`object`&&Object.keys(e.data).forEach(n=>{t.setAttribute(`data-`+D(n),e.data[n])}),t}setupLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{if(e.__slimSelectLabelHandler)return;let t=e=>{let t=e.target,n=_(t,this.select.dataset.id);e.preventDefault(),!n&&this.onLabelClick&&this.onLabelClick()};e.__slimSelectLabelHandler=t,e.addEventListener(`click`,t,{capture:!0,passive:!1})})}removeLabelHandlers(){let e=[],t=this.select.id;t&&document.querySelectorAll(`label[for="${t}"]`).forEach(t=>e.push(t));let n=this.select.parentElement;for(;n&&n!==document.body;){if(n.tagName===`LABEL`){e.push(n);break}n=n.parentElement}Array.from(new Set(e)).forEach(e=>{let t=e.__slimSelectLabelHandler;t&&(e.removeEventListener(`click`,t,{capture:!0}),delete e.__slimSelectLabelHandler)})}destroy(){this.changeListen(!1),this.select.removeEventListener(`change`,this.valueChange),this.preventNativeSelect&&=(this.select.removeEventListener(`click`,this.preventNativeSelect,{capture:!0}),null),this.preventNativeSelectMousedown&&=(this.select.removeEventListener(`mousedown`,this.preventNativeSelectMousedown,{capture:!0}),null),this.preventNativeSelectFocus&&=(this.select.removeEventListener(`focus`,this.preventNativeSelectFocus,{capture:!0}),null),this.restoreAriaHiddenOnBlur&&=(this.select.removeEventListener(`blur`,this.restoreAriaHiddenOnBlur,{capture:!0}),null),this.observer&&=(this.observer.disconnect(),null),this.removeLabelHandlers(),delete this.select.dataset.id,this.showUI()}};function L(e,t){return E(e.getData(!1),t)}function R(e,t){let n=Array.isArray(t)?t:[t],r=e.getDataOptions(!1),i=[];for(let e of n){if(r.find(t=>t.id==e)){i.push(e);continue}for(let t of r.filter(t=>t.value==e))i.push(t.id)}return i}var z=class{deps;queue=[];flushScheduled=!1;isSyncing=!1;constructor(e){this.deps=e}enqueue(e){if(this.queue.push(e),e.source===`native`){this.flushScheduled||(this.flushScheduled=!0,queueMicrotask(()=>this.flush()));return}this.isSyncing||this.flush()}flush(){if(this.flushScheduled=!1,this.queue.length===0)return;let e=this.coalesceBatch(this.queue);this.queue=[],this.isSyncing=!0;try{for(let t of e)this.applyChange(t)}finally{this.isSyncing=!1,this.queue.length>0&&this.flush()}}coalesceBatch(e){let t=e.some(e=>e.type===`structure`),n=e.some(e=>e.type===`addOption`);if(t||n){let t=e.filter(e=>e.type===`structure`||e.type===`addOption`),n=t[t.length-1];return n?.type===`structure`?[n]:t}let r=e.filter(e=>e.type===`selection`);return r.length>0?[r[r.length-1]]:e}applyChange(e){switch(e.type){case`structure`:this.applyStructure(e.data,e.source,e.preserveSelection,e.isSearchResult);break;case`selection`:this.applySelection(e.values,e.source,e.runAfterChange!==!1);break;case`addOption`:this.applyAddOption(e.option)}}applyStructure(e,t,n=!1,r=!1){let{store:i,select:a,render:o,events:s}=this.deps;if(!r&&L(i,e))return;let c=i.getSelected(),l=i.validateDataArray(e);if(l){s.error?s.error(l):this.deps.onError&&this.deps.onError(l);return}i.setData(e,n);let u=i.getData(!1);r||i.snapshotCatalog(),r||a.updateOptions(u),o.renderValues(),o.renderOptions(u),s.afterChange&&!y(c,i.getSelected())&&s.afterChange(i.getSelectedOptions())}syncNativeSelection(){let{store:e,select:t}=this.deps,n=e.getSelectedOptions(),r=e.getSelectedValues();if(!t.hasOptionValues(r)){if(n.length>0){t.updateOptions(n);return}let r=e.getCatalogData().find(e=>e instanceof j&&e.placeholder===!0);if(r){t.updateOptions([new j({...r,selected:!0})]);return}}t.setSelectedByValue(r)}applySelection(e,t,n){let{store:r,select:i,render:a,events:o}=this.deps,s=r.getSelected(),c=R(r,e);if(y(s,c))return;r.setSelectedBy(`id`,c),this.syncNativeSelection(),a.renderValues();let l=a.content.search.input.value.trim();l===``?a.canUpdateOptionSelectionInPlace()?a.updateOptionSelection():a.renderOptions(r.getData(!1)):a.hasRenderedOptions()?a.updateOptionSelection():this.deps.search&&this.deps.search(l),n&&o.afterChange&&!y(s,r.getSelected())&&o.afterChange(r.getSelectedOptions())}applyAddOption(e){let{store:t,select:n,render:r,events:i}=this.deps,a=t.getSelected(),o=r.content.search.input.value.trim()!==``&&!!this.deps.search,s=e.value??e.text??``,c=e=>{for(let t of e){if(t instanceof M){if(t.options.some(e=>(e.value??e.text)===s))return!0;continue}if((t.value??t.text)===s)return!0}return!1};if(!c(t.getData(!1))){if(o){let n=t.getCatalogData();c(n)||t.setData([...n,new j(e)],!0),t.snapshotCatalog()}else t.addOption(e),t.snapshotCatalog()}let l=t.getData(!1);if(o){let e=t.getSelectedOptions();e.length>0&&n.updateOptions(e)}else n.updateOptions(l);r.renderValues(),r.renderOptions(l),i.afterChange&&!y(a,t.getSelected())&&i.afterChange(t.getSelectedOptions())}},B=class{selectEl;settings;cssClasses;select;store;render;sync;lifecycle;globalEvents;searchGeneration=0;events={search:void 0,searchFilter:(e,t)=>e.text.toLowerCase().indexOf(t.toLowerCase())!==-1,addable:void 0,beforeChange:void 0,afterChange:void 0,beforeOpen:void 0,afterOpen:void 0,beforeClose:void 0,afterClose:void 0};constructor(e){if(this.selectEl=typeof e.select==`string`?document.querySelector(e.select):e.select,!this.selectEl){e.events&&e.events.error&&e.events.error(Error(`Could not find select element`));return}if(this.selectEl.tagName!==`SELECT`){e.events&&e.events.error&&e.events.error(Error(`Element isnt of type select`));return}this.selectEl.dataset.ssid&&this.destroy(),this.settings=new f(e.settings),e.settings?.selectAll===void 0&&this.selectEl.dataset.selectall===`true`&&(this.settings.selectAll=!0),this.cssClasses=new n(e.cssClasses);let t=[`beforeOpen`,`afterOpen`,`afterClose`];for(let n in e.events)e.events.hasOwnProperty(n)&&(t.indexOf(n)===-1?this.events[n]=e.events[n]:this.events[n]=v(e.events[n],100));this.settings.disabled=e.settings?.disabled?e.settings.disabled:this.selectEl.disabled,this.settings.isMultiple=this.selectEl.multiple,this.settings.style=this.selectEl.style.cssText,this.settings.class=this.selectEl.className.split(` `),this.select=new I(this.selectEl),this.selectEl.id||(this.selectEl.id=this.settings.id),this.select.updateSelect(this.settings.id,this.settings.style,this.settings.class),this.select.hideUI(),this.select.onClassChange=e=>{this.settings.class=e,this.render.updateClassStyles()},this.select.onDisabledChange=e=>{e?this.disable():this.enable()},this.select.onLabelClick=()=>{this.settings.disabled||(this.settings.isOpen?this.close({source:`toggle`,selectionChanged:!1}):this.open())};let r=e.data?e.data:this.select.getData();this.store=new N(this.settings.isMultiple?`multiple`:`single`,r),e.data&&this.select.updateOptions(this.store.getData());let i={open:this.open.bind(this),close:this.close.bind(this),addable:this.events.addable?this.events.addable:void 0,setSelected:(e,t)=>{this.sync.enqueue({type:`selection`,values:e,source:`ui`,runAfterChange:t})},addOption:e=>{this.sync.enqueue({type:`addOption`,option:e,source:`ui`})},search:this.search.bind(this),beforeChange:this.events.beforeChange,afterChange:this.events.afterChange};this.settings.modalTitle=e.settings?.modalTitle??h(this.selectEl),this.render=new P(this.settings,this.cssClasses,this.store,i),this.settings.timeoutDelay=s(this.render.content.main,e.settings?.timeoutDelay),this.sync=new z({select:this.select,store:this.store,render:this.render,events:this.events,search:this.search.bind(this)}),this.select.onValueChange=e=>{this.sync.enqueue({type:`selection`,values:e.map(e=>e.id||e.value),source:`native`})},this.select.onOptionsChange=e=>{this.sync.enqueue({type:`structure`,data:e||[],source:`native`})},this.lifecycle=new A({beforeOpen:this.events.beforeOpen,afterOpen:this.events.afterOpen,beforeClose:e=>this.events.beforeClose?.(e),onClose:e=>this.applyClose(e),afterClose:()=>{this.render.clearDirectionClasses(),this.render.finalizeModalClose(),this.events.afterClose&&this.events.afterClose()},onOpenReady:()=>this.globalEvents.attachDocumentClick(),onCloseReady:()=>this.globalEvents.detachDocumentClick()},{timeoutDelay:this.settings.timeoutDelay,waitForAnimation:(e,t)=>this.render.waitForAnimation(e,t)}),this.globalEvents=new k({onDocumentClick:this.documentClick.bind(this),onWindowResize:()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()},onWindowScroll:()=>{(this.settings.isOpen||this.settings.isFullOpen)&&this.render.moveContent()},onVisibilityChange:()=>{document.hidden&&this.close({source:`api`,selectionChanged:!1})}}),this.render.renderValues(),this.render.renderOptions(this.store.getData(!1));let a=this.selectEl.getAttribute(`aria-label`),o=this.selectEl.getAttribute(`aria-labelledby`);if(a)this.render.main.main.setAttribute(`aria-label`,a);else if(o)this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,o);else if(this.selectEl.labels&&this.selectEl.labels.length>0){let e=Array.from(this.selectEl.labels).map((e,t)=>(e.id||=`${this.settings.id}-label-${t}`,e.id));this.render.main.main.removeAttribute(`aria-label`),this.render.main.main.setAttribute(`aria-labelledby`,e.join(` `))}this.selectEl.parentNode&&this.selectEl.parentNode.insertBefore(this.render.main.main,this.selectEl.nextSibling),this.globalEvents.attach({listenScroll:this.settings.openPosition===`auto`}),this.settings.disabled&&this.disable(),this.settings.alwaysOpen&&this.open(),this.select.setupLabelHandlers(),this.selectEl.slim=this}enable(){this.settings.disabled=!1,this.select.enable(),this.render.enable()}disable(){this.settings.disabled=!0,this.select.disable(),this.render.disable()}getData(){return this.store.getData()}setData(e){this.sync.enqueue({type:`structure`,data:e,source:`api`})}getSelected(){let e=this.store.getSelectedOptions();return this.settings.keepOrder&&(e=this.store.selectedOrderOptions(e)),e.map(e=>e.value)}setSelected(e,t=!0){this.sync.enqueue({type:`selection`,values:e,source:`api`,runAfterChange:t})}addOption(e){this.sync.enqueue({type:`addOption`,option:e,source:`api`})}open(){if(this.settings.disabled||this.settings.isOpen)return;this.lifecycle.cancelPending(),this.render.open(),this.settings.showSearch&&this.settings.focusSearch&&this.render.searchFocus(),this.settings.isOpen=!0,this.lifecycle.requestOpen().then(()=>{this.settings.isOpen&&(this.settings.isFullOpen=this.lifecycle.isFullOpen,this.settings.isOpen=this.lifecycle.isOpen)}),this.settings.contentPosition===`absolute`&&!this.render.isModalViewActive()&&this.render.startPositionTracking();let e=this.render.content.search.input.value.trim();e!==``&&this.search(e)}close(e={source:`api`,selectionChanged:!1}){this.settings.isOpen&&!this.settings.alwaysOpen&&this.lifecycle.requestClose(e).then(e=>{e&&(this.settings.isOpen||(this.settings.isOpen=this.lifecycle.isOpen,this.settings.isFullOpen=this.lifecycle.isFullOpen))})}applyClose(e){this.render.close(),!this.settings.keepSearch&&this.render.content.search.input.value!==``&&(this.sync.flush(),this.search(``));let t=e.source===`outside`||e.source===`toggle`;this.render.mainFocus(t?`click`:null),this.settings.isOpen=!1,this.settings.isFullOpen=!1,this.render.stopPositionTracking()}search(e){let t=e.trim();if(t===``){this.render.content.search.input.value=``,this.clearSearch();return}if(this.render.content.search.input.value!==e&&(this.render.content.search.input.value=e),this.events.search){this.runApiSearch(t);return}this.runLocalSearch(t)}clearSearch(){if(this.searchGeneration++,!this.events.search&&this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(``,this.events.searchFilter),this.render.resetSearchFilterState();return}this.render.resetSearchFilterState(),this.sync.enqueue({type:`structure`,data:this.store.getCatalogData(),source:`api`,preserveSelection:!0})}runLocalSearch(e){if(this.render.canFilterOptionsInPlace()){this.render.filterOptionsInPlace(e,this.events.searchFilter);return}let t=this.store.search(e,this.events.searchFilter);this.render.renderOptions(t)}runApiSearch(e){let t=++this.searchGeneration;this.render.renderSearching();let n=this.events.search(e,this.store.getSelectedOptions(),this.store.getCatalogData()),r=n=>{t===this.searchGeneration&&this.render.content.search.input.value.trim()===e&&this.sync.enqueue({type:`structure`,data:n,source:`api`,preserveSelection:!0,isSearchResult:!0})};if(n instanceof Promise){n.then(r).catch(e=>{t===this.searchGeneration&&this.render.renderError(typeof e==`string`?e:e.message)});return}if(Array.isArray(n)){r(n);return}this.render.renderError(`Search event must return a promise or an array of data`)}destroy(){this.lifecycle.destroy(),this.render.stopPositionTracking(),this.globalEvents.detach({listenScroll:this.settings.openPosition===`auto`}),this.store.setData([]),this.render.destroy(),this.select.destroy(),delete this.selectEl.slim}documentClick(e){this.settings.isOpen&&e.target&&!_(e.target,this.settings.id)&&this.close({source:`outside`,selectionChanged:!1})}};function V(e){let n=new WeakMap,r=e=>{if((0,t.isRef)(e)&&(e=(0,t.unref)(e)),(0,t.isReactive)(e)&&(e=(0,t.toRaw)(e)),typeof e!=`object`||!e)return e;if(n.has(e))return n.get(e);if(Array.isArray(e)){let t=[];n.set(e,t);for(let n of e)t.push(r(n));return t}let i={};n.set(e,i);for(let t of Object.keys(e))i[t]=r(e[t]);return i};return r(e)}var H=(0,t.defineComponent)({name:`SlimSelect`,props:{modelValue:{type:[String,Array,void 0]},multiple:{type:Boolean,default:!1},data:{type:Array,required:!0},settings:{type:Object},events:{type:Object,default:()=>({})}},emits:[`update:modelValue`],data(){return{slim:null,lastAppliedData:null}},mounted(){let e={select:this.$refs.slim,data:this.data};this.settings&&(e.settings=this.settings);let t=this.events?.afterChange;e.events={...this.events,afterChange:e=>{this.handleAfterChange(e,t)}},this.slim=new B(e),this.lastAppliedData=structuredClone(V(this.data)),this.syncModelValueToSlimSelect(!1)},beforeUnmount(){this.slim&&this.slim.destroy()},watch:{modelValue:{handler:function(e){this.slim&&this.syncModelValueToSlimSelect(!1)}},data:{handler:function(e){this.slim&&(this.lastAppliedData!==null&&E(this.lastAppliedData,(0,t.toRaw)(e))||(this.slim.setData(e),this.lastAppliedData=structuredClone(V(e)),this.syncModelValueToSlimSelect(!1)))},deep:!0}},computed:{value:{get(){return this.getCleanValue(this.$props.modelValue)},set(e){this.$emit(`update:modelValue`,e)}}},methods:{getSlimSelect(){return this.slim},handleAfterChange(e,t){if(!this.slim)return;let n=this.multiple?e.map(e=>e.value):e.length>0?e[0].value:``,r=this.getCleanValue(this.$props.modelValue),i=this.slim.store.getDataOptions(!1),a=Array.isArray(r)?r.length>0&&r.every(e=>i.some(t=>t.value===e)):r!==``&&i.some(e=>e.value===r),o=Array.isArray(n)?n.length>0&&n.every(e=>i.some(t=>t.value===e)):n!==``&&i.some(e=>e.value===n);(Array.isArray(n)&&Array.isArray(this.value)?JSON.stringify(n.sort())!==JSON.stringify(this.value.sort()):this.value!==n)&&(a||o)&&(this.value=n),t&&t(e)},getCleanValue(e){let t=this.$props.multiple;return typeof e==`string`?t?[e]:e:Array.isArray(e)?t?e:e[0]:t?[]:``},syncModelValueToSlimSelect(e=!1){if(!this.slim||this.$props.modelValue===void 0)return;let t=this.getCleanValue(this.$props.modelValue),n=this.slim.getData().flatMap(e=>`label`in e?e.options:[e]);if(!(Array.isArray(t)?t.length>0&&t.every(e=>n.some(t=>t.value===e)):t!==``&&n.some(e=>e.value===t))&&!Array.isArray(t)&&!n.some(e=>e.placeholder)){let e=this.slim.getData();this.slim.setData([{value:``,text:``,placeholder:!0}].concat(e))}this.slim.setSelected(t,e)}}}),U=(e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n},W=[`multiple`];function G(e,n,r,i,a,o){return(0,t.openBlock)(),(0,t.createElementBlock)(`select`,{multiple:e.multiple,ref:`slim`},null,8,W)}var K=U(H,[[`render`,G]]);e.Optgroup=M,e.Option=j,e.Settings=f,e.default=K});