slim-select 3.2.0 → 3.4.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.
@@ -1,4 +1,4 @@
1
- class A {
1
+ class L {
2
2
  main;
3
3
  // Placeholder
4
4
  placeholder;
@@ -59,13 +59,18 @@ class A {
59
59
  disabled;
60
60
  hide;
61
61
  constructor(e) {
62
- e || (e = {}), this.main = e.main || "ss-main", this.placeholder = e.placeholder || "ss-placeholder", this.values = e.values || "ss-values", this.single = e.single || "ss-single", this.max = e.max || "ss-max", this.value = e.value || "ss-value", this.valueText = e.valueText || "ss-value-text", this.valueDelete = e.valueDelete || "ss-value-delete", this.valueOut = e.valueOut || "ss-value-out", this.deselect = e.deselect || "ss-deselect", this.deselectPath = e.deselectPath || "M10,10 L90,90 M10,90 L90,10", this.arrow = e.arrow || "ss-arrow", this.arrowClose = e.arrowClose || "M10,30 L50,70 L90,30", this.arrowOpen = e.arrowOpen || "M10,70 L50,30 L90,70", this.content = e.content || "ss-content", this.contentOpen = e.contentOpen || "ss-open", this.dirAbove = e.dirAbove || "ss-dir-above", this.dirBelow = e.dirBelow || "ss-dir-below", this.search = e.search || "ss-search", this.searchHighlighter = e.searchHighlighter || "ss-search-highlight", this.searching = e.searching || "ss-searching", this.addable = e.addable || "ss-addable", this.addablePath = e.addablePath || "M50,10 L50,90 M10,50 L90,50", this.list = e.list || "ss-list", this.optgroup = e.optgroup || "ss-optgroup", this.optgroupLabel = e.optgroupLabel || "ss-optgroup-label", this.optgroupLabelText = e.optgroupLabelText || "ss-optgroup-label-text", this.optgroupActions = e.optgroupActions || "ss-optgroup-actions", this.optgroupSelectAll = e.optgroupSelectAll || "ss-selectall", this.optgroupSelectAllBox = e.optgroupSelectAllBox || "M60,10 L10,10 L10,90 L90,90 L90,50", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M30,45 L50,70 L90,10", this.optgroupClosable = e.optgroupClosable || "ss-closable", this.option = e.option || "ss-option", this.optionDelete = e.optionDelete || "M10,10 L90,90 M10,90 L90,10", this.highlighted = e.highlighted || "ss-highlighted", this.mainOpen = e.mainOpen || "ss-open", this.close = e.close || "ss-close", this.selected = e.selected || "ss-selected", this.error = e.error || "ss-error", this.disabled = e.disabled || "ss-disabled", this.hide = e.hide || "ss-hide";
62
+ e || (e = {});
63
+ let t = (s = "", i = "") => `${s} ${i}`.trim();
64
+ 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.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.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 || "M60,10 L10,10 L10,90 L90,90 L90,50", this.optgroupSelectAllCheck = e.optgroupSelectAllCheck || "M30,45 L50,70 L90,10", 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.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);
65
+ }
66
+ getFirst(e) {
67
+ return this[e].split(" ")[0];
63
68
  }
64
69
  }
65
- function C() {
70
+ function y() {
66
71
  return Math.random().toString(36).substring(2, 10);
67
72
  }
68
- function T(p, e) {
73
+ function x(p, e) {
69
74
  function t(i, l) {
70
75
  return l && i && i.classList && i.classList.contains(l) || l && i && i.dataset && i.dataset.id && i.dataset.id === e ? i : null;
71
76
  }
@@ -74,16 +79,16 @@ function T(p, e) {
74
79
  }
75
80
  return t(p, e) || s(p, e);
76
81
  }
77
- function O(p, e = 50, t = !1) {
82
+ function S(p, e = 50, t = !1) {
78
83
  let s;
79
84
  return function(...i) {
80
- const l = self, a = () => {
85
+ const l = self, n = () => {
81
86
  s = null, t || p.apply(l, i);
82
- }, n = t && !s;
83
- clearTimeout(s), s = setTimeout(a, e), n && p.apply(l, i);
87
+ }, a = t && !s;
88
+ clearTimeout(s), s = setTimeout(n, e), a && p.apply(l, i);
84
89
  };
85
90
  }
86
- function L(p, e) {
91
+ function O(p, e) {
87
92
  return JSON.stringify(p) === JSON.stringify(e);
88
93
  }
89
94
  function D(p) {
@@ -105,10 +110,10 @@ class u {
105
110
  data;
106
111
  mandatory;
107
112
  constructor(e) {
108
- this.id = !e.id || e.id === "" ? C() : 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 : !1, this.selected = e.selected !== void 0 ? e.selected : !1, this.display = e.display !== void 0 ? e.display : !0, this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.mandatory = e.mandatory !== void 0 ? e.mandatory : !1, this.placeholder = e.placeholder !== void 0 ? e.placeholder : !1, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
113
+ this.id = !e.id || e.id === "" ? y() : 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 : !1, this.selected = e.selected !== void 0 ? e.selected : !1, this.display = e.display !== void 0 ? e.display : !0, this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.mandatory = e.mandatory !== void 0 ? e.mandatory : !1, this.placeholder = e.placeholder !== void 0 ? e.placeholder : !1, this.class = e.class || "", this.style = e.style || "", this.data = e.data || {};
109
114
  }
110
115
  }
111
- class g {
116
+ class m {
112
117
  id;
113
118
  label;
114
119
  selectAll;
@@ -116,7 +121,7 @@ class g {
116
121
  closable;
117
122
  options;
118
123
  constructor(e) {
119
- if (this.id = !e.id || e.id === "" ? C() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.closable = e.closable || "off", this.options = [], e.options)
124
+ if (this.id = !e.id || e.id === "" ? y() : e.id, this.label = e.label || "", this.selectAll = e.selectAll === void 0 ? !1 : e.selectAll, this.selectAllText = e.selectAllText || "Select All", this.closable = e.closable || "off", this.options = [], e.options)
120
125
  for (const t of e.options)
121
126
  this.options.push(new u(t));
122
127
  }
@@ -135,7 +140,7 @@ class k {
135
140
  return new Error("Data must be an array");
136
141
  for (let t of e)
137
142
  if (t)
138
- if (t instanceof g || "label" in t) {
143
+ if (t instanceof m || "label" in t) {
139
144
  if (!("label" in t))
140
145
  return new Error("Optgroup must have a label");
141
146
  if ("options" in t && t.options)
@@ -160,11 +165,11 @@ class k {
160
165
  let t = [];
161
166
  return e.forEach((s) => {
162
167
  if (s) {
163
- if (s instanceof g || "label" in s) {
168
+ if (s instanceof m || "label" in s) {
164
169
  let i = [];
165
170
  "options" in s && s.options && s.options.forEach((l) => {
166
171
  i.push(new u(l));
167
- }), i.length > 0 && t.push(new g(s));
172
+ }), i.length > 0 && t.push(new m(s));
168
173
  }
169
174
  (s instanceof u || "text" in s) && t.push(new u(s));
170
175
  }
@@ -174,22 +179,22 @@ class k {
174
179
  const s = this.partialToFullData(e);
175
180
  if (t) {
176
181
  const i = this.getSelectedOptions(), l = [];
177
- i.forEach((a) => {
178
- let n = !1;
182
+ i.forEach((n) => {
183
+ let a = !1;
179
184
  for (const o of s) {
180
- if (o instanceof u && o.id === a.id) {
181
- n = !0;
185
+ if (o instanceof u && o.id === n.id) {
186
+ a = !0;
182
187
  break;
183
188
  }
184
- if (o instanceof g) {
185
- for (const c of o.options)
186
- if (c.id === a.id) {
187
- n = !0;
189
+ if (o instanceof m) {
190
+ for (const h of o.options)
191
+ if (h.id === n.id) {
192
+ a = !0;
188
193
  break;
189
194
  }
190
195
  }
191
196
  }
192
- n || l.push(a);
197
+ a || l.push(n);
193
198
  }), this.data = [...l, ...s];
194
199
  } else
195
200
  this.data = s;
@@ -217,18 +222,18 @@ class k {
217
222
  setSelectedBy(e, t) {
218
223
  let s = null, i = !1;
219
224
  const l = [];
220
- for (let n of this.data) {
221
- if (n instanceof g)
222
- for (let o of n.options) {
225
+ for (let a of this.data) {
226
+ if (a instanceof m)
227
+ for (let o of a.options) {
223
228
  s || (s = o);
224
- let c = o[e] || "";
225
- o.selected = i ? !1 : t.includes(c), o.selected && (l.push(o), this.selectType === "single" && (i = !0));
229
+ let h = o[e] || "";
230
+ o.selected = i ? !1 : t.includes(h), o.selected && (l.push(o), this.selectType === "single" && (i = !0));
226
231
  }
227
- n instanceof u && (s || (s = n), n.selected = i ? !1 : t.includes(n[e]), n.selected && (l.push(n), this.selectType === "single" && (i = !0)));
232
+ a instanceof u && (s || (s = a), a.selected = i ? !1 : t.includes(a[e]), a.selected && (l.push(a), this.selectType === "single" && (i = !0)));
228
233
  }
229
234
  this.selectType === "single" && s && !i && (s.selected = !0, l.push(s));
230
- const a = t.map((n) => l.find((o) => o[e] === n)?.id || "");
231
- this.selectedOrder = a;
235
+ const n = t.map((a) => l.find((o) => o[e] === a)?.id || "");
236
+ this.selectedOrder = n;
232
237
  }
233
238
  getSelected() {
234
239
  return this.getSelectedOptions().map((e) => e.id);
@@ -241,7 +246,7 @@ class k {
241
246
  }
242
247
  getOptgroupByID(e) {
243
248
  for (let t of this.data)
244
- if (t instanceof g && t.id === e)
249
+ if (t instanceof m && t.id === e)
245
250
  return t;
246
251
  return null;
247
252
  }
@@ -255,7 +260,7 @@ class k {
255
260
  getFirstOption() {
256
261
  let e = null;
257
262
  for (let t of this.data)
258
- if (t instanceof g ? e = t.options[0] : t instanceof u && (e = t), e)
263
+ if (t instanceof m ? e = t.options[0] : t instanceof u && (e = t), e)
259
264
  break;
260
265
  return e;
261
266
  }
@@ -268,13 +273,13 @@ class k {
268
273
  filter(e, t) {
269
274
  const s = [];
270
275
  return this.data.forEach((i) => {
271
- if (i instanceof g) {
276
+ if (i instanceof m) {
272
277
  let l = [];
273
- if (i.options.forEach((n) => {
274
- (!e || e(n)) && (t ? l.push(new u(n)) : s.push(new u(n)));
278
+ if (i.options.forEach((a) => {
279
+ (!e || e(a)) && (t ? l.push(new u(a)) : s.push(new u(a)));
275
280
  }), l.length > 0) {
276
- let n = new g(i);
277
- n.options = l, s.push(n);
281
+ let a = new m(i);
282
+ a.options = l, s.push(a);
278
283
  }
279
284
  }
280
285
  i instanceof u && (!e || e(i)) && s.push(new u(i));
@@ -303,6 +308,8 @@ class N {
303
308
  callbacks;
304
309
  // Used to compute the range selection
305
310
  lastSelectedOption;
311
+ // Timeout tracking for cleanup
312
+ closeAnimationTimeout = null;
306
313
  // Elements
307
314
  main;
308
315
  content;
@@ -311,18 +318,35 @@ class N {
311
318
  constructor(e, t, s, i) {
312
319
  this.store = s, this.settings = e, this.classes = t, this.callbacks = i, this.lastSelectedOption = null, 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);
313
320
  }
321
+ // Helper method to add classes that may contain spaces
322
+ // Splits by spaces and adds each class individually to avoid DOMException
323
+ addClasses(e, t) {
324
+ if (!t || t.trim() === "")
325
+ return;
326
+ const s = t.split(" ").filter((i) => i.trim() !== "");
327
+ for (const i of s)
328
+ e.classList.add(i.trim());
329
+ }
330
+ // Helper method to remove classes that may contain spaces
331
+ removeClasses(e, t) {
332
+ if (!t || t.trim() === "")
333
+ return;
334
+ const s = t.split(" ").filter((i) => i.trim() !== "");
335
+ for (const i of s)
336
+ e.classList.remove(i.trim());
337
+ }
314
338
  // Remove disabled classes
315
339
  enable() {
316
- this.main.main.classList.remove(this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
340
+ this.removeClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "false"), this.content.search.input.disabled = !1;
317
341
  }
318
342
  // Set disabled classes
319
343
  disable() {
320
- this.main.main.classList.add(this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
344
+ this.addClasses(this.main.main, this.classes.disabled), this.main.main.setAttribute("aria-disabled", "true"), this.content.search.input.disabled = !0;
321
345
  }
322
346
  open() {
323
- this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true");
347
+ this.main.arrow.path.setAttribute("d", this.classes.arrowOpen), this.main.main.setAttribute("aria-expanded", "true"), this.closeAnimationTimeout && (clearTimeout(this.closeAnimationTimeout), this.closeAnimationTimeout = null);
324
348
  const t = this.settings.openPosition === "up" ? this.classes.dirAbove : this.classes.dirBelow;
325
- this.main.main.classList.add(t), this.content.main.classList.add(t), this.content.main.classList.add(this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), this.moveContent();
349
+ this.addClasses(this.main.main, t), this.addClasses(this.content.main, t), this.addClasses(this.content.main, this.classes.contentOpen), this.content.search.input.removeAttribute("aria-hidden"), this.moveContent();
326
350
  const s = this.store.getSelectedOptions();
327
351
  if (s.length) {
328
352
  const i = s[s.length - 1].id, l = this.content.list.querySelector('[data-id="' + i + '"]');
@@ -330,10 +354,10 @@ class N {
330
354
  }
331
355
  }
332
356
  close() {
333
- this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.content.main.classList.remove(this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
357
+ this.main.main.setAttribute("aria-expanded", "false"), this.main.arrow.path.setAttribute("d", this.classes.arrowClose), this.removeClasses(this.content.main, this.classes.contentOpen), this.content.search.input.setAttribute("aria-hidden", "true"), this.main.main.removeAttribute("aria-activedescendant");
334
358
  const e = this.getAnimationTiming();
335
- setTimeout(() => {
336
- this.main.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow), this.content.main.classList.remove(this.classes.dirAbove, this.classes.dirBelow);
359
+ this.closeAnimationTimeout = setTimeout(() => {
360
+ 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), this.closeAnimationTimeout = null;
337
361
  }, e);
338
362
  }
339
363
  getAnimationTiming() {
@@ -347,7 +371,7 @@ class N {
347
371
  return 200;
348
372
  }
349
373
  updateClassStyles() {
350
- if (this.main.main.className = "", this.main.main.removeAttribute("style"), this.content.main.className = "", this.content.main.removeAttribute("style"), this.main.main.classList.add(this.classes.main), this.content.main.classList.add(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)
374
+ 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)
351
375
  for (const e of this.settings.class)
352
376
  e.trim() !== "" && (this.main.main.classList.add(e.trim()), this.content.main.classList.add(e.trim()));
353
377
  (this.settings.contentPosition === "relative" || this.settings.contentPosition === "fixed") && this.content.main.classList.add("ss-" + this.settings.contentPosition);
@@ -358,63 +382,65 @@ class N {
358
382
  }
359
383
  mainDiv() {
360
384
  const e = document.createElement("div");
361
- e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (c) => {
362
- switch (c.key) {
385
+ e.dataset.id = this.settings.id, e.setAttribute("aria-label", this.settings.ariaLabel), e.tabIndex = 0, e.onkeydown = (h) => {
386
+ switch (h.key) {
363
387
  case "ArrowUp":
364
388
  case "ArrowDown":
365
- return this.callbacks.open(), c.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
389
+ return this.callbacks.open(), h.key === "ArrowDown" ? this.highlight("down") : this.highlight("up"), !1;
366
390
  case "Tab":
367
391
  return this.callbacks.close(), !0;
368
392
  // Continue doing normal tabbing
369
393
  case "Enter":
370
394
  case " ":
371
395
  this.callbacks.open();
372
- const r = this.content.list.querySelector("." + this.classes.highlighted);
396
+ const r = this.content.list.querySelector(
397
+ "." + this.classes.getFirst("highlighted")
398
+ );
373
399
  return r && r.click(), !1;
374
400
  case "Escape":
375
401
  return this.callbacks.close(), !1;
376
402
  }
377
- return c.key.length === 1 && this.callbacks.open(), !0;
378
- }, e.onclick = (c) => {
403
+ return h.key.length === 1 && this.callbacks.open(), !0;
404
+ }, e.onclick = (h) => {
379
405
  this.settings.disabled || (this.settings.isOpen ? this.callbacks.close() : this.callbacks.open());
380
406
  };
381
407
  const t = document.createElement("div");
382
- t.classList.add(this.classes.values), e.appendChild(t);
408
+ this.addClasses(t, this.classes.values), e.appendChild(t);
383
409
  const s = document.createElement("div");
384
- s.classList.add(this.classes.deselect);
410
+ this.addClasses(s, this.classes.deselect);
385
411
  const i = this.store?.getSelectedOptions();
386
- !this.settings.allowDeselect || this.settings.isMultiple && i && i.length <= 0 ? s.classList.add(this.classes.hide) : s.classList.remove(this.classes.hide), s.onclick = (c) => {
387
- if (c.stopPropagation(), this.settings.disabled)
412
+ !this.settings.allowDeselect || this.settings.isMultiple && i && i.length <= 0 ? this.addClasses(s, this.classes.hide) : this.removeClasses(s, this.classes.hide), s.onclick = (h) => {
413
+ if (h.stopPropagation(), this.settings.disabled)
388
414
  return;
389
415
  let r = !0;
390
- const h = this.store.getSelectedOptions(), f = [];
391
- if (this.callbacks.beforeChange && (r = this.callbacks.beforeChange(f, h) === !0), r) {
416
+ const c = this.store.getSelectedOptions(), f = [];
417
+ if (this.callbacks.beforeChange && (r = this.callbacks.beforeChange(f, c) === !0), r) {
392
418
  if (this.settings.isMultiple)
393
419
  this.callbacks.setSelected([], !1), this.updateDeselectAll();
394
420
  else {
395
- const d = this.store.getFirstOption(), m = d ? d.id : "";
396
- this.callbacks.setSelected(m, !1);
421
+ const d = this.store.getFirstOption(), g = d ? d.id : "";
422
+ this.callbacks.setSelected(g, !1);
397
423
  }
398
424
  this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(this.store.getSelectedOptions());
399
425
  }
400
426
  };
401
427
  const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
402
428
  l.setAttribute("viewBox", "0 0 100 100");
403
- const a = document.createElementNS("http://www.w3.org/2000/svg", "path");
404
- a.setAttribute("d", this.classes.deselectPath), l.appendChild(a), s.appendChild(l), e.appendChild(s);
405
- const n = document.createElementNS("http://www.w3.org/2000/svg", "svg");
406
- n.classList.add(this.classes.arrow), n.setAttribute("viewBox", "0 0 100 100");
429
+ const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
430
+ n.setAttribute("d", this.classes.deselectPath), l.appendChild(n), s.appendChild(l), e.appendChild(s);
431
+ const a = document.createElementNS("http://www.w3.org/2000/svg", "svg");
432
+ this.addClasses(a, this.classes.arrow), a.setAttribute("viewBox", "0 0 100 100");
407
433
  const o = document.createElementNS("http://www.w3.org/2000/svg", "path");
408
- return o.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && n.classList.add(this.classes.hide), n.appendChild(o), e.appendChild(n), {
434
+ return o.setAttribute("d", this.classes.arrowClose), this.settings.alwaysOpen && this.addClasses(a, this.classes.hide), a.appendChild(o), e.appendChild(a), {
409
435
  main: e,
410
436
  values: t,
411
437
  deselect: {
412
438
  main: s,
413
439
  svg: l,
414
- path: a
440
+ path: n
415
441
  },
416
442
  arrow: {
417
- main: n,
443
+ main: a,
418
444
  path: o
419
445
  }
420
446
  };
@@ -427,7 +453,7 @@ class N {
427
453
  let t = this.settings.placeholderText;
428
454
  e.length && (e[0].html !== "" ? t = e[0].html : e[0].text !== "" && (t = e[0].text));
429
455
  const s = document.createElement("div");
430
- return s.classList.add(this.classes.placeholder), s.innerHTML = t, s;
456
+ return this.addClasses(s, this.classes.placeholder), s.innerHTML = t, s;
431
457
  }
432
458
  // Get selected values and append to multiSelected values container
433
459
  // and remove those who shouldnt exist
@@ -444,9 +470,9 @@ class N {
444
470
  this.main.values.innerHTML = this.placeholder().outerHTML;
445
471
  else {
446
472
  const s = document.createElement("div");
447
- s.classList.add(this.classes.single), t.html ? s.innerHTML = t.html : s.innerText = t.text, this.main.values.innerHTML = s.outerHTML;
473
+ this.addClasses(s, this.classes.single), t.html ? s.innerHTML = t.html : s.innerText = t.text, this.main.values.innerHTML = s.outerHTML;
448
474
  }
449
- !this.settings.allowDeselect || !e.length ? this.main.deselect.main.classList.add(this.classes.hide) : this.main.deselect.main.classList.remove(this.classes.hide);
475
+ !this.settings.allowDeselect || !e.length ? this.addClasses(this.main.deselect.main, this.classes.hide) : this.removeClasses(this.main.deselect.main, this.classes.hide);
450
476
  }
451
477
  renderMultipleValues() {
452
478
  let e = this.main.values.childNodes, t = this.store.filter((i) => i.selected && i.display, !1);
@@ -454,62 +480,62 @@ class N {
454
480
  this.main.values.innerHTML = this.placeholder().outerHTML;
455
481
  return;
456
482
  } else {
457
- const i = this.main.values.querySelector("." + this.classes.placeholder);
483
+ const i = this.main.values.querySelector("." + this.classes.getFirst("placeholder"));
458
484
  i && i.remove();
459
485
  }
460
486
  if (t.length > this.settings.maxValuesShown) {
461
487
  const i = document.createElement("div");
462
- i.classList.add(this.classes.max), i.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = i.outerHTML;
488
+ this.addClasses(i, this.classes.max), i.textContent = this.settings.maxValuesMessage.replace("{number}", t.length.toString()), this.main.values.innerHTML = i.outerHTML;
463
489
  return;
464
490
  } else {
465
- const i = this.main.values.querySelector("." + this.classes.max);
491
+ const i = this.main.values.querySelector("." + this.classes.getFirst("max"));
466
492
  i && i.remove();
467
493
  }
468
494
  this.settings.keepOrder && (t = this.store.selectedOrderOptions(t));
469
495
  let s = [];
470
496
  for (let i = 0; i < e.length; i++) {
471
- const l = e[i], a = l.getAttribute("data-id");
472
- a && (t.filter((o) => o.id === a, !1).length || s.push(l));
497
+ const l = e[i], n = l.getAttribute("data-id");
498
+ n && (t.filter((o) => o.id === n, !1).length || s.push(l));
473
499
  }
474
500
  for (const i of s)
475
- i.classList.add(this.classes.valueOut), setTimeout(() => {
501
+ this.addClasses(i, this.classes.valueOut), setTimeout(() => {
476
502
  this.main.values.hasChildNodes() && this.main.values.contains(i) && this.main.values.removeChild(i);
477
503
  }, 100);
478
504
  e = this.main.values.childNodes;
479
505
  for (let i = 0; i < t.length; i++) {
480
506
  let l = !0;
481
- for (let a = 0; a < e.length; a++)
482
- t[i].id === String(e[a].dataset.id) && (l = !1);
507
+ for (let n = 0; n < e.length; n++)
508
+ t[i].id === String(e[n].dataset.id) && (l = !1);
483
509
  l && (this.settings.keepOrder ? this.main.values.appendChild(this.multipleValue(t[i])) : e.length === 0 ? this.main.values.appendChild(this.multipleValue(t[i])) : i === 0 ? this.main.values.insertBefore(this.multipleValue(t[i]), e[i]) : e[i - 1].insertAdjacentElement("afterend", this.multipleValue(t[i])));
484
510
  }
485
511
  }
486
512
  multipleValue(e) {
487
513
  const t = document.createElement("div");
488
- t.classList.add(this.classes.value), t.dataset.id = e.id;
514
+ this.addClasses(t, this.classes.value), t.dataset.id = e.id;
489
515
  const s = document.createElement("div");
490
- if (s.classList.add(this.classes.valueText), s.textContent = e.text, t.appendChild(s), !e.mandatory) {
516
+ if (this.addClasses(s, this.classes.valueText), s.textContent = e.text, t.appendChild(s), !e.mandatory) {
491
517
  const i = document.createElement("div");
492
- i.classList.add(this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (n) => {
493
- if (n.preventDefault(), n.stopPropagation(), this.settings.disabled)
518
+ this.addClasses(i, this.classes.valueDelete), i.setAttribute("tabindex", "0"), i.onclick = (a) => {
519
+ if (a.preventDefault(), a.stopPropagation(), this.settings.disabled)
494
520
  return;
495
521
  let o = !0;
496
- const c = this.store.getSelectedOptions(), r = c.filter((h) => h.selected && h.id !== e.id, !0);
497
- if (!(this.settings.minSelected && r.length < this.settings.minSelected) && (this.callbacks.beforeChange && (o = this.callbacks.beforeChange(r, c) === !0), o)) {
498
- let h = [];
522
+ const h = this.store.getSelectedOptions(), r = h.filter((c) => c.selected && c.id !== e.id, !0);
523
+ if (!(this.settings.minSelected && r.length < this.settings.minSelected) && (this.callbacks.beforeChange && (o = this.callbacks.beforeChange(r, h) === !0), o)) {
524
+ let c = [];
499
525
  for (const f of r) {
500
- if (f instanceof g)
526
+ if (f instanceof m)
501
527
  for (const d of f.options)
502
- d.id && h.push(d.id);
503
- f instanceof u && h.push(f.id);
528
+ d.id && c.push(d.id);
529
+ f instanceof u && c.push(f.id);
504
530
  }
505
- this.callbacks.setSelected(h, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(r), this.updateDeselectAll();
531
+ this.callbacks.setSelected(c, !1), this.settings.closeOnSelect && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(r), this.updateDeselectAll();
506
532
  }
507
533
  };
508
534
  const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
509
535
  l.setAttribute("viewBox", "0 0 100 100");
510
- const a = document.createElementNS("http://www.w3.org/2000/svg", "path");
511
- a.setAttribute("d", this.classes.optionDelete), l.appendChild(a), i.appendChild(l), t.appendChild(i), i.onkeydown = (n) => {
512
- n.key === "Enter" && i.click();
536
+ const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
537
+ n.setAttribute("d", this.classes.optionDelete), l.appendChild(n), i.appendChild(l), t.appendChild(i), i.onkeydown = (a) => {
538
+ a.key === "Enter" && i.click();
513
539
  };
514
540
  }
515
541
  return t;
@@ -542,12 +568,12 @@ class N {
542
568
  }
543
569
  searchDiv() {
544
570
  const e = document.createElement("div"), t = document.createElement("input"), s = document.createElement("div");
545
- e.classList.add(this.classes.search);
571
+ this.addClasses(e, this.classes.search);
546
572
  const i = {
547
573
  main: e,
548
574
  input: t
549
575
  };
550
- if (this.settings.showSearch || (e.classList.add(this.classes.hide), t.readOnly = !0), t.type = "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"), t.oninput = O((l) => {
576
+ if (this.settings.showSearch || (this.addClasses(e, this.classes.hide), t.readOnly = !0), t.type = "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"), t.oninput = S((l) => {
551
577
  this.callbacks.search(l.target.value);
552
578
  }, 100), t.onkeydown = (l) => {
553
579
  switch (l.key) {
@@ -560,28 +586,32 @@ class N {
560
586
  case "Escape":
561
587
  return this.callbacks.close(), !1;
562
588
  case " ":
563
- const a = this.content.list.querySelector("." + this.classes.highlighted);
564
- return a ? (a.click(), !1) : !0;
589
+ const n = this.content.list.querySelector(
590
+ "." + this.classes.getFirst("highlighted")
591
+ );
592
+ return n ? (n.click(), !1) : !0;
565
593
  case "Enter":
566
- const n = this.content.list.querySelector("." + this.classes.highlighted);
567
- return n ? (n.click(), !1) : this.callbacks.addable ? (s.click(), !1) : !0;
594
+ const a = this.content.list.querySelector(
595
+ "." + this.classes.getFirst("highlighted")
596
+ );
597
+ return a ? (a.click(), !1) : this.callbacks.addable ? (s.click(), !1) : !0;
568
598
  }
569
599
  return !0;
570
600
  }, e.appendChild(t), this.callbacks.addable) {
571
- s.classList.add(this.classes.addable);
601
+ this.addClasses(s, this.classes.addable);
572
602
  const l = document.createElementNS("http://www.w3.org/2000/svg", "svg");
573
603
  l.setAttribute("viewBox", "0 0 100 100");
574
- const a = document.createElementNS("http://www.w3.org/2000/svg", "path");
575
- a.setAttribute("d", this.classes.addablePath), l.appendChild(a), s.appendChild(l), s.onclick = (n) => {
576
- if (n.preventDefault(), n.stopPropagation(), !this.callbacks.addable)
604
+ const n = document.createElementNS("http://www.w3.org/2000/svg", "path");
605
+ n.setAttribute("d", this.classes.addablePath), l.appendChild(n), s.appendChild(l), s.onclick = (a) => {
606
+ if (a.preventDefault(), a.stopPropagation(), !this.callbacks.addable)
577
607
  return;
578
608
  const o = this.content.search.input.value.trim();
579
609
  if (o === "") {
580
610
  this.content.search.input.focus();
581
611
  return;
582
612
  }
583
- const c = (h) => {
584
- let f = new u(h);
613
+ const h = (c) => {
614
+ let f = new u(c);
585
615
  if (this.callbacks.addOption(f), this.settings.isMultiple) {
586
616
  let d = this.store.getSelected();
587
617
  d.push(f.id), this.callbacks.setSelected(d, !0);
@@ -591,19 +621,19 @@ class N {
591
621
  this.callbacks.close();
592
622
  }, 100);
593
623
  }, r = this.callbacks.addable(o);
594
- r === !1 || r === void 0 || r === null || (r instanceof Promise ? r.then((h) => {
595
- typeof h == "string" ? c({
596
- text: h,
597
- value: h
598
- }) : r instanceof Error ? this.renderError(r.message) : c(h);
599
- }) : typeof r == "string" ? c({
624
+ r === !1 || r === void 0 || r === null || (r instanceof Promise ? r.then((c) => {
625
+ typeof c == "string" ? h({
626
+ text: c,
627
+ value: c
628
+ }) : r instanceof Error ? this.renderError(r.message) : h(c);
629
+ }) : typeof r == "string" ? h({
600
630
  text: r,
601
631
  value: r
602
- }) : r instanceof Error ? this.renderError(r.message) : c(r));
632
+ }) : r instanceof Error ? this.renderError(r.message) : h(r));
603
633
  }, e.appendChild(s), i.addable = {
604
634
  main: s,
605
635
  svg: l,
606
- path: a
636
+ path: n
607
637
  };
608
638
  }
609
639
  return i;
@@ -612,71 +642,73 @@ class N {
612
642
  this.content.search.input.focus({ preventScroll: !0 });
613
643
  }
614
644
  getOptions(e = !1, t = !1, s = !1) {
615
- let i = "." + this.classes.option;
616
- return e && (i += ":not(." + this.classes.placeholder + ")"), t && (i += ":not(." + this.classes.disabled + ")"), s && (i += ":not(." + this.classes.hide + ")"), Array.from(this.content.list.querySelectorAll(i));
645
+ let i = "." + this.classes.getFirst("option");
646
+ return e && (i += ":not(." + this.classes.getFirst("placeholder") + ")"), t && (i += ":not(." + this.classes.getFirst("disabled") + ")"), s && (i += ":not(." + this.classes.getFirst("hide") + ")"), Array.from(this.content.list.querySelectorAll(i));
617
647
  }
618
648
  // highlightUp is used to highlight the previous option in the list
619
649
  highlight(e) {
620
650
  const t = this.getOptions(!0, !0, !0);
621
651
  if (t.length === 0)
622
652
  return;
623
- if (t.length === 1 && !t[0].classList.contains(this.classes.highlighted)) {
624
- t[0].classList.add(this.classes.highlighted);
653
+ if (t.length === 1 && !t[0].classList.contains(this.classes.getFirst("highlighted"))) {
654
+ this.addClasses(t[0], this.classes.highlighted);
625
655
  return;
626
656
  }
627
657
  let s = !1;
628
658
  for (const l of t)
629
- l.classList.contains(this.classes.highlighted) && (s = !0);
659
+ l.classList.contains(this.classes.getFirst("highlighted")) && (s = !0);
630
660
  if (!s) {
631
661
  for (const l of t)
632
- if (l.classList.contains(this.classes.selected)) {
633
- l.classList.add(this.classes.highlighted);
662
+ if (l.classList.contains(this.classes.getFirst("selected"))) {
663
+ this.addClasses(l, this.classes.highlighted);
634
664
  break;
635
665
  }
636
666
  }
637
667
  for (let l = 0; l < t.length; l++)
638
- if (t[l].classList.contains(this.classes.highlighted)) {
639
- const a = t[l];
640
- a.classList.remove(this.classes.highlighted);
641
- const n = a.parentElement;
642
- if (n && n.classList.contains(this.classes.mainOpen)) {
643
- const r = n.querySelector("." + this.classes.optgroupLabel);
668
+ if (t[l].classList.contains(this.classes.getFirst("highlighted"))) {
669
+ const n = t[l];
670
+ this.removeClasses(n, this.classes.highlighted);
671
+ const a = n.parentElement;
672
+ if (a && a.classList.contains(this.classes.getFirst("mainOpen"))) {
673
+ const r = a.querySelector("." + this.classes.getFirst("optgroupLabel"));
644
674
  r && r.click();
645
675
  }
646
676
  let o = t[e === "down" ? l + 1 < t.length ? l + 1 : 0 : l - 1 >= 0 ? l - 1 : t.length - 1];
647
- o.classList.add(this.classes.highlighted), this.ensureElementInView(this.content.list, o), o.id && this.main.main.setAttribute("aria-activedescendant", o.id);
648
- const c = o.parentElement;
649
- if (c && c.classList.contains(this.classes.close)) {
650
- const r = c.querySelector("." + this.classes.optgroupLabel);
677
+ this.addClasses(o, this.classes.highlighted), this.ensureElementInView(this.content.list, o), o.id && this.main.main.setAttribute("aria-activedescendant", o.id);
678
+ const h = o.parentElement;
679
+ if (h && h.classList.contains(this.classes.getFirst("close"))) {
680
+ const r = h.querySelector(
681
+ "." + this.classes.getFirst("optgroupLabel")
682
+ );
651
683
  r && r.click();
652
684
  }
653
685
  return;
654
686
  }
655
687
  const i = t[e === "down" ? 0 : t.length - 1];
656
- i.classList.add(this.classes.highlighted), i.id && this.main.main.setAttribute("aria-activedescendant", i.id), this.ensureElementInView(this.content.list, i);
688
+ this.addClasses(i, this.classes.highlighted), i.id && this.main.main.setAttribute("aria-activedescendant", i.id), this.ensureElementInView(this.content.list, i);
657
689
  }
658
690
  // Create main container that options will reside
659
691
  listDiv() {
660
692
  const e = document.createElement("div");
661
- e.classList.add(this.classes.list);
693
+ this.addClasses(e, this.classes.list);
662
694
  const t = this.settings.id + "-list";
663
695
  return e.id = t, e.dataset.id = t, e;
664
696
  }
665
697
  renderError(e) {
666
698
  this.content.list.innerHTML = "";
667
699
  const t = document.createElement("div");
668
- t.classList.add(this.classes.error), t.textContent = e, this.content.list.appendChild(t);
700
+ this.addClasses(t, this.classes.error), t.textContent = e, this.content.list.appendChild(t);
669
701
  }
670
702
  renderSearching() {
671
703
  this.content.list.innerHTML = "";
672
704
  const e = document.createElement("div");
673
- e.classList.add(this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e);
705
+ this.addClasses(e, this.classes.searching), e.textContent = this.settings.searchingText, this.content.list.appendChild(e);
674
706
  }
675
707
  // Take in data and add options to
676
708
  renderOptions(e) {
677
709
  if (this.content.list.innerHTML = "", e.length === 0) {
678
710
  const s = document.createElement("div");
679
- s.classList.add(this.classes.search), this.callbacks.addable ? s.innerHTML = this.settings.addableText.replace("{value}", this.content.search.input.value) : s.innerHTML = this.settings.searchText, this.content.list.appendChild(s);
711
+ this.addClasses(s, this.classes.search), this.callbacks.addable ? s.innerHTML = this.settings.addableText.replace("{value}", this.content.search.input.value) : s.innerHTML = this.settings.searchText, this.content.list.appendChild(s);
680
712
  return;
681
713
  }
682
714
  this.settings.allowDeselect && !this.settings.isMultiple && (this.store.filter((i) => i.placeholder, !1).length || this.store.addOption(
@@ -690,62 +722,62 @@ class N {
690
722
  ));
691
723
  const t = document.createDocumentFragment();
692
724
  for (const s of e) {
693
- if (s instanceof g) {
725
+ if (s instanceof m) {
694
726
  const i = document.createElement("div");
695
- i.classList.add(this.classes.optgroup);
727
+ this.addClasses(i, this.classes.optgroup);
696
728
  const l = document.createElement("div");
697
- l.classList.add(this.classes.optgroupLabel), i.appendChild(l);
698
- const a = document.createElement("div");
699
- a.classList.add(this.classes.optgroupLabelText), a.textContent = s.label, l.appendChild(a);
729
+ this.addClasses(l, this.classes.optgroupLabel), i.appendChild(l);
700
730
  const n = document.createElement("div");
701
- if (n.classList.add(this.classes.optgroupActions), l.appendChild(n), this.settings.isMultiple && s.selectAll) {
731
+ this.addClasses(n, this.classes.optgroupLabelText), n.textContent = s.label, l.appendChild(n);
732
+ const a = document.createElement("div");
733
+ if (this.addClasses(a, this.classes.optgroupActions), l.appendChild(a), this.settings.isMultiple && s.selectAll) {
702
734
  const o = document.createElement("div");
703
- o.classList.add(this.classes.optgroupSelectAll);
704
- let c = !0;
705
- for (const m of s.options)
706
- if (!m.selected) {
707
- c = !1;
735
+ this.addClasses(o, this.classes.optgroupSelectAll);
736
+ let h = !0;
737
+ for (const g of s.options)
738
+ if (!g.selected) {
739
+ h = !1;
708
740
  break;
709
741
  }
710
- c && o.classList.add(this.classes.selected);
742
+ h && this.addClasses(o, this.classes.selected);
711
743
  const r = document.createElement("span");
712
744
  r.textContent = s.selectAllText, o.appendChild(r);
713
- const h = document.createElementNS("http://www.w3.org/2000/svg", "svg");
714
- h.setAttribute("viewBox", "0 0 100 100"), o.appendChild(h);
745
+ const c = document.createElementNS("http://www.w3.org/2000/svg", "svg");
746
+ c.setAttribute("viewBox", "0 0 100 100"), o.appendChild(c);
715
747
  const f = document.createElementNS("http://www.w3.org/2000/svg", "path");
716
- f.setAttribute("d", this.classes.optgroupSelectAllBox), h.appendChild(f);
748
+ f.setAttribute("d", this.classes.optgroupSelectAllBox), c.appendChild(f);
717
749
  const d = document.createElementNS("http://www.w3.org/2000/svg", "path");
718
- d.setAttribute("d", this.classes.optgroupSelectAllCheck), h.appendChild(d), o.addEventListener("click", (m) => {
719
- m.preventDefault(), m.stopPropagation();
750
+ d.setAttribute("d", this.classes.optgroupSelectAllCheck), c.appendChild(d), o.addEventListener("click", (g) => {
751
+ g.preventDefault(), g.stopPropagation();
720
752
  const v = this.store.getSelected();
721
- if (c) {
722
- const w = v.filter((S) => {
753
+ if (h) {
754
+ const C = v.filter((w) => {
723
755
  for (const b of s.options)
724
- if (S === b.id)
756
+ if (w === b.id)
725
757
  return !1;
726
758
  return !0;
727
759
  });
728
- this.callbacks.setSelected(w, !0);
760
+ this.callbacks.setSelected(C, !0);
729
761
  return;
730
762
  } else {
731
- let w = s.options.map((b) => b.id).filter((b) => b !== void 0);
732
- const S = v.concat(w);
763
+ let C = s.options.map((b) => b.id).filter((b) => b !== void 0);
764
+ const w = v.concat(C);
733
765
  for (const b of s.options)
734
766
  b.id && !this.store.getOptionByID(b.id) && this.callbacks.addOption(new u(b));
735
- this.callbacks.setSelected(S, !0);
767
+ this.callbacks.setSelected(w, !0);
736
768
  return;
737
769
  }
738
- }), n.appendChild(o);
770
+ }), a.appendChild(o);
739
771
  }
740
772
  if (s.closable !== "off") {
741
773
  const o = document.createElement("div");
742
- o.classList.add(this.classes.optgroupClosable);
743
- const c = document.createElementNS("http://www.w3.org/2000/svg", "svg");
744
- c.setAttribute("viewBox", "0 0 100 100"), c.classList.add(this.classes.arrow), o.appendChild(c);
774
+ this.addClasses(o, this.classes.optgroupClosable);
775
+ const h = document.createElementNS("http://www.w3.org/2000/svg", "svg");
776
+ h.setAttribute("viewBox", "0 0 100 100"), this.addClasses(h, this.classes.arrow), o.appendChild(h);
745
777
  const r = document.createElementNS("http://www.w3.org/2000/svg", "path");
746
- c.appendChild(r), s.options.some((h) => h.selected) || this.content.search.input.value.trim() !== "" ? (o.classList.add(this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "open" ? (i.classList.add(this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "close" && (i.classList.add(this.classes.close), r.setAttribute("d", this.classes.arrowClose)), l.addEventListener("click", (h) => {
747
- h.preventDefault(), h.stopPropagation(), i.classList.contains(this.classes.close) ? (i.classList.remove(this.classes.close), i.classList.add(this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : (i.classList.remove(this.classes.mainOpen), i.classList.add(this.classes.close), r.setAttribute("d", this.classes.arrowClose));
748
- }), n.appendChild(o);
778
+ h.appendChild(r), s.options.some((c) => c.selected) || this.content.search.input.value.trim() !== "" ? (this.addClasses(o, this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "open" ? (this.addClasses(i, this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : s.closable === "close" && (this.addClasses(i, this.classes.close), r.setAttribute("d", this.classes.arrowClose)), l.addEventListener("click", (c) => {
779
+ c.preventDefault(), c.stopPropagation(), i.classList.contains(this.classes.getFirst("close")) ? (this.removeClasses(i, this.classes.close), this.addClasses(i, this.classes.mainOpen), r.setAttribute("d", this.classes.arrowOpen)) : (this.removeClasses(i, this.classes.mainOpen), this.addClasses(i, this.classes.close), r.setAttribute("d", this.classes.arrowClose));
780
+ }), a.appendChild(o);
749
781
  }
750
782
  i.appendChild(l);
751
783
  for (const o of s.options)
@@ -759,83 +791,95 @@ class N {
759
791
  option(e) {
760
792
  if (e.placeholder) {
761
793
  const s = document.createElement("div");
762
- return s.classList.add(this.classes.option), s.classList.add(this.classes.hide), s;
794
+ return this.addClasses(s, this.classes.option), this.addClasses(s, this.classes.hide), s;
763
795
  }
764
796
  const t = document.createElement("div");
765
- return t.dataset.id = e.id, t.id = this.settings.id + "-" + e.id, t.classList.add(this.classes.option), t.setAttribute("role", "option"), e.class && e.class.split(" ").forEach((s) => {
797
+ 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((s) => {
766
798
  t.classList.add(s);
767
799
  }), e.style && (t.style.cssText = e.style), this.settings.searchHighlight && this.content.search.input.value.trim() !== "" ? t.innerHTML = this.highlightText(
768
800
  e.html !== "" ? e.html : e.text,
769
801
  this.content.search.input.value,
770
802
  this.classes.searchHighlighter
771
- ) : e.html !== "" ? t.innerHTML = e.html : t.textContent = e.text, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), e.display || t.classList.add(this.classes.hide), e.disabled && t.classList.add(this.classes.disabled), e.selected && this.settings.hideSelected && t.classList.add(this.classes.hide), e.selected ? (t.classList.add(this.classes.selected), t.setAttribute("aria-selected", "true"), this.main.main.setAttribute("aria-activedescendant", t.id)) : (t.classList.remove(this.classes.selected), t.setAttribute("aria-selected", "false")), t.addEventListener("click", (s) => {
803
+ ) : e.html !== "" ? t.innerHTML = e.html : t.textContent = e.text, this.settings.showOptionTooltips && t.textContent && t.setAttribute("title", t.textContent), 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", (s) => {
772
804
  s.preventDefault(), s.stopPropagation();
773
- const i = this.store.getSelected(), l = s.currentTarget, a = String(l.dataset.id), n = s.ctrlKey || s.metaKey;
774
- if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !n)
805
+ const i = this.store.getSelected(), l = s.currentTarget, n = String(l.dataset.id), a = s.ctrlKey || s.metaKey;
806
+ if (e.disabled || !this.settings.isMultiple && e.selected && !this.settings.allowDeselect || e.selected && e.mandatory || this.settings.isMultiple && this.settings.maxSelected <= i.length && !e.selected || this.settings.isMultiple && this.settings.minSelected >= i.length && e.selected && !a)
775
807
  return;
776
808
  let o = !1;
777
- const c = this.store.getSelectedOptions();
809
+ const h = this.store.getSelectedOptions();
778
810
  let r = [];
779
811
  if (this.settings.isMultiple) {
780
- const h = c.some((d) => d.id === a);
812
+ const c = h.some((d) => d.id === n);
781
813
  if (s.shiftKey && this.lastSelectedOption) {
782
- const d = this.store.getDataOptions(), m = d.findIndex((w) => w.id === this.lastSelectedOption.id), v = d.findIndex((w) => w.id === e.id);
783
- if (m >= 0 && v >= 0) {
784
- const w = Math.min(m, v), S = Math.max(m, v), y = d.slice(w, S + 1).filter((x) => !c.find((E) => E.id === x.id));
785
- c.length + y.length <= this.settings.maxSelected ? r = c.concat(y) : r = c;
814
+ const d = this.store.getDataOptions(), g = d.findIndex((C) => C.id === this.lastSelectedOption.id), v = d.findIndex((C) => C.id === e.id);
815
+ if (g >= 0 && v >= 0) {
816
+ const C = Math.min(g, v), w = Math.max(g, v), E = d.slice(C, w + 1).filter((A) => !h.find((T) => T.id === A.id));
817
+ h.length + E.length <= this.settings.maxSelected ? r = h.concat(E) : r = h;
786
818
  } else
787
- r = c;
788
- } else n ? (h ? r = c.filter((d) => d.id !== a) : r = c.concat(e), this.lastSelectedOption = e) : (h ? r = c.filter((d) => d.id !== a) : r = c.concat(e), this.lastSelectedOption = e);
819
+ r = h;
820
+ } else a ? (c ? r = h.filter((d) => d.id !== n) : r = h.concat(e), this.lastSelectedOption = e) : (c ? r = h.filter((d) => d.id !== n) : r = h.concat(e), this.lastSelectedOption = e);
789
821
  }
790
- if (this.settings.isMultiple || (e.selected ? r = [] : r = [e]), this.callbacks.beforeChange || (o = !0), this.callbacks.beforeChange && (this.callbacks.beforeChange(r, c) === !1 ? o = !1 : o = !0), o) {
791
- this.store.getOptionByID(a) || this.callbacks.addOption(e), this.callbacks.setSelected(
822
+ if (this.settings.isMultiple || (e.selected ? r = [] : r = [e]), this.callbacks.beforeChange || (o = !0), this.callbacks.beforeChange && (this.callbacks.beforeChange(r, h) === !1 ? o = !1 : o = !0), o) {
823
+ this.store.getOptionByID(n) || this.callbacks.addOption(e), this.callbacks.setSelected(
792
824
  r.map((d) => d.id),
793
825
  !1
794
826
  );
795
- const h = s.ctrlKey || s.metaKey || s.shiftKey;
796
- this.settings.closeOnSelect && !(this.settings.isMultiple && h) && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(r);
827
+ const c = s.ctrlKey || s.metaKey || s.shiftKey;
828
+ this.settings.closeOnSelect && !(this.settings.isMultiple && c) && this.callbacks.close(), this.callbacks.afterChange && this.callbacks.afterChange(r);
797
829
  }
798
830
  }), t;
799
831
  }
800
832
  destroy() {
801
- this.main.main.remove(), this.content.main.remove();
833
+ this.closeAnimationTimeout && (clearTimeout(this.closeAnimationTimeout), this.closeAnimationTimeout = null), this.main.main.remove(), this.content.main.remove();
802
834
  }
803
835
  highlightText(e, t, s) {
804
836
  const i = t.trim();
805
837
  if (i === "")
806
838
  return e;
807
- const l = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), a = document.createElement("div");
808
- a.innerHTML = e;
809
- const n = (o) => {
839
+ const l = i.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), n = document.createElement("div");
840
+ n.innerHTML = e;
841
+ const a = (o) => {
810
842
  if (o.nodeType === Node.TEXT_NODE) {
811
- const c = o.textContent || "", r = new RegExp("(" + l + ")", "i");
812
- if (r.test(c)) {
813
- const h = document.createElement("span");
814
- c.split(r).forEach((d, m) => {
843
+ const h = o.textContent || "", r = new RegExp("(" + l + ")", "i");
844
+ if (r.test(h)) {
845
+ const c = document.createElement("span");
846
+ h.split(r).forEach((d, g) => {
815
847
  if (d && r.test(d)) {
816
848
  const v = document.createElement("mark");
817
- v.className = s, v.textContent = d, h.appendChild(v);
818
- } else d && h.appendChild(document.createTextNode(d));
819
- }), o.parentNode?.replaceChild(h, o);
849
+ v.className = s, v.textContent = d, c.appendChild(v);
850
+ } else d && c.appendChild(document.createTextNode(d));
851
+ }), o.parentNode?.replaceChild(c, o);
820
852
  }
821
- } else o.nodeType === Node.ELEMENT_NODE && Array.from(o.childNodes).forEach((c) => n(c));
853
+ } else o.nodeType === Node.ELEMENT_NODE && Array.from(o.childNodes).forEach((h) => a(h));
822
854
  };
823
- return Array.from(a.childNodes).forEach((o) => n(o)), a.innerHTML;
855
+ return Array.from(n.childNodes).forEach((o) => a(o)), n.innerHTML;
856
+ }
857
+ setContentDirection(e) {
858
+ const t = e === "above", s = t ? this.classes.dirAbove : this.classes.dirBelow, i = t ? this.classes.dirBelow : this.classes.dirAbove;
859
+ if (this.removeClasses(this.main.main, i), this.addClasses(this.main.main, s), this.removeClasses(this.content.main, i), this.addClasses(this.content.main, s), t) {
860
+ const l = this.main.main.offsetHeight, n = this.content.main.offsetHeight;
861
+ this.content.main.style.margin = "-" + (l + n - 1) + "px 0px 0px 0px";
862
+ } else
863
+ this.content.main.style.margin = "-1px 0px 0px 0px";
864
+ }
865
+ setContentPosition() {
866
+ if (this.settings.contentPosition === "relative")
867
+ return;
868
+ const e = this.main.main.getBoundingClientRect();
869
+ let t, s;
870
+ this.settings.contentPosition === "fixed" ? (t = e.top + e.height, s = e.left) : (t = e.top + window.scrollY + e.height, s = e.left + window.scrollX), this.content.main.style.top = t + "px", this.content.main.style.left = s + "px";
871
+ const i = this.settings.contentWidth;
872
+ this.content.main.style.width = "", this.content.main.style.minWidth = "", this.content.main.style.maxWidth = "", i ? i.startsWith(">") ? this.content.main.style.minWidth = i.slice(1) : i.startsWith("<") ? this.content.main.style.maxWidth = i.slice(1) : this.content.main.style.width = i : this.content.main.style.width = e.width + "px";
824
873
  }
825
874
  moveContentAbove() {
826
- const e = this.main.main.offsetHeight, t = this.content.main.offsetHeight;
827
- this.main.main.classList.remove(this.classes.dirBelow), this.main.main.classList.add(this.classes.dirAbove), this.content.main.classList.remove(this.classes.dirBelow), this.content.main.classList.add(this.classes.dirAbove);
828
- const s = this.main.main.getBoundingClientRect();
829
- this.content.main.style.margin = "-" + (e + t - 1) + "px 0px 0px 0px", this.content.main.style.top = s.top + s.height + (this.settings.contentPosition === "fixed" ? 0 : window.scrollY) + "px", this.content.main.style.left = s.left + (this.settings.contentPosition === "fixed" ? 0 : window.scrollX) + "px", this.content.main.style.width = s.width + "px";
875
+ this.setContentDirection("above"), this.setContentPosition();
830
876
  }
831
877
  moveContentBelow() {
832
- this.main.main.classList.remove(this.classes.dirAbove), this.main.main.classList.add(this.classes.dirBelow), this.content.main.classList.remove(this.classes.dirAbove), this.content.main.classList.add(this.classes.dirBelow);
833
- const e = this.main.main.getBoundingClientRect();
834
- this.content.main.style.margin = "-1px 0px 0px 0px", this.settings.contentPosition !== "relative" && (this.content.main.style.top = e.top + e.height + (this.settings.contentPosition === "fixed" ? 0 : window.scrollY) + "px", this.content.main.style.left = e.left + (this.settings.contentPosition === "fixed" ? 0 : window.scrollX) + "px", this.content.main.style.width = e.width + "px");
878
+ this.setContentDirection("below"), this.setContentPosition();
835
879
  }
836
880
  ensureElementInView(e, t) {
837
- const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, l = t.offsetTop, a = l + t.clientHeight;
838
- l < s ? e.scrollTop -= s - l : a > i && (e.scrollTop += a - i);
881
+ const s = e.scrollTop + e.offsetTop, i = s + e.clientHeight, l = t.offsetTop, n = l + t.clientHeight;
882
+ l < s ? e.scrollTop -= s - l : n > i && (e.scrollTop += n - i);
839
883
  }
840
884
  putContent() {
841
885
  const e = this.main.main.offsetHeight, t = this.main.main.getBoundingClientRect(), s = this.content.main.offsetHeight;
@@ -845,8 +889,8 @@ class N {
845
889
  updateDeselectAll() {
846
890
  if (!this.store || !this.settings)
847
891
  return;
848
- const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, l = this.main.deselect.main, a = this.classes.hide;
849
- i && !(s && !t) ? l.classList.remove(a) : l.classList.add(a);
892
+ const e = this.store.getSelectedOptions(), t = e && e.length > 0, s = this.settings.isMultiple, i = this.settings.allowDeselect, l = this.main.deselect.main, n = this.classes.hide;
893
+ i && !(s && !t) ? this.removeClasses(l, n) : this.addClasses(l, n);
850
894
  }
851
895
  }
852
896
  class M {
@@ -909,22 +953,22 @@ class M {
909
953
  if (!this.listen)
910
954
  return;
911
955
  let t = !1, s = !1, i = !1, l = !1;
912
- for (const a of e) {
913
- if (a.target === this.select && (a.attributeName === "disabled" && (s = !0), a.attributeName === "class" && (t = !0), a.type === "childList")) {
914
- for (const n of Array.from(a.addedNodes))
915
- if (n.nodeName === "OPTION" && n.value === this.select.value) {
956
+ for (const n of e) {
957
+ if (n.target === this.select && (n.attributeName === "disabled" && (s = !0), n.attributeName === "class" && (t = !0), n.type === "childList")) {
958
+ for (const a of Array.from(n.addedNodes))
959
+ if (a.nodeName === "OPTION" && a.value === this.select.value) {
916
960
  l = !0;
917
961
  break;
918
962
  }
919
963
  i = !0;
920
964
  }
921
- (a.target.nodeName === "OPTGROUP" || a.target.nodeName === "OPTION") && (i = !0);
965
+ (n.target.nodeName === "OPTGROUP" || n.target.nodeName === "OPTION") && (i = !0);
922
966
  }
923
967
  if (t && this.onClassChange && this.onClassChange(this.select.className.split(" ")), s && this.onDisabledChange && (this.changeListen(!1), this.onDisabledChange(this.select.disabled), this.changeListen(!0)), i && this.onOptionsChange) {
924
968
  if (this.isUpdating) {
925
969
  if (this.select.options.length > 0) {
926
- const a = this.getData();
927
- a.length > 0 && (this.pendingOptionsChange = a);
970
+ const n = this.getData();
971
+ n.length > 0 && (this.pendingOptionsChange = n);
928
972
  }
929
973
  l && this.select.dispatchEvent(new Event("change"));
930
974
  return;
@@ -981,8 +1025,8 @@ class M {
981
1025
  const i = s.childNodes;
982
1026
  for (const l of i)
983
1027
  if (l.nodeName === "OPTION") {
984
- const a = l;
985
- a.selected && e.push(this.getDataFromOption(a));
1028
+ const n = l;
1029
+ n.selected && e.push(this.getDataFromOption(n));
986
1030
  }
987
1031
  }
988
1032
  if (s.nodeName === "OPTION") {
@@ -1001,10 +1045,10 @@ class M {
1001
1045
  for (const s of t) {
1002
1046
  if (s.nodeName === "OPTGROUP") {
1003
1047
  const l = s.childNodes;
1004
- for (const a of l)
1005
- if (a.nodeName === "OPTION") {
1006
- const n = a;
1007
- n.selected = e.includes(n.id);
1048
+ for (const n of l)
1049
+ if (n.nodeName === "OPTION") {
1050
+ const a = n;
1051
+ a.selected = e.includes(a.id);
1008
1052
  }
1009
1053
  }
1010
1054
  if (s.nodeName === "OPTION") {
@@ -1024,10 +1068,10 @@ class M {
1024
1068
  for (const s of t) {
1025
1069
  if (s.nodeName === "OPTGROUP") {
1026
1070
  const l = s.childNodes;
1027
- for (const a of l)
1028
- if (a.nodeName === "OPTION") {
1029
- const n = a;
1030
- n.selected = e.includes(n.value);
1071
+ for (const n of l)
1072
+ if (n.nodeName === "OPTION") {
1073
+ const a = n;
1074
+ a.selected = e.includes(a.value);
1031
1075
  }
1032
1076
  }
1033
1077
  if (s.nodeName === "OPTION") {
@@ -1046,7 +1090,7 @@ class M {
1046
1090
  if (!(!e || e.length === 0)) {
1047
1091
  this.isUpdating = !0, this.pendingOptionsChange = null, this.changeListen(!1), this.select.innerHTML = "";
1048
1092
  for (const t of e)
1049
- t instanceof g && this.select.appendChild(this.createOptgroup(t)), t instanceof u && this.select.appendChild(this.createOption(t));
1093
+ t instanceof m && this.select.appendChild(this.createOptgroup(t)), t instanceof u && this.select.appendChild(this.createOption(t));
1050
1094
  if (this.select.dispatchEvent(new Event("change", { bubbles: !0 })), this.changeListen(!0), this.isUpdating = !1, this.pendingOptionsChange !== null) {
1051
1095
  const t = this.pendingOptionsChange;
1052
1096
  t.length > 0 && this.onOptionsChange ? (this.pendingOptionsChange = null, this.changeListen(!1), this.onOptionsChange(t), this.changeListen(!0)) : this.pendingOptionsChange = null;
@@ -1071,7 +1115,7 @@ class M {
1071
1115
  // Find and handle labels associated with this select
1072
1116
  setupLabelHandlers() {
1073
1117
  const e = [], t = this.select.id;
1074
- t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
1118
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((n) => e.push(n));
1075
1119
  let s = this.select.parentElement;
1076
1120
  for (; s && s !== document.body; ) {
1077
1121
  if (s.tagName === "LABEL") {
@@ -1083,17 +1127,17 @@ class M {
1083
1127
  Array.from(new Set(e)).forEach((l) => {
1084
1128
  if (l.__slimSelectLabelHandler)
1085
1129
  return;
1086
- const a = (n) => {
1087
- const o = n.target;
1088
- n.preventDefault(), o === l && this.onLabelClick && this.onLabelClick();
1130
+ const n = (a) => {
1131
+ const o = a.target, h = x(o, this.select.dataset.id);
1132
+ a.preventDefault(), !h && this.onLabelClick && this.onLabelClick();
1089
1133
  };
1090
- l.__slimSelectLabelHandler = a, l.addEventListener("click", a, { capture: !0, passive: !1 });
1134
+ l.__slimSelectLabelHandler = n, l.addEventListener("click", n, { capture: !0, passive: !1 });
1091
1135
  });
1092
1136
  }
1093
1137
  // Remove label handlers
1094
1138
  removeLabelHandlers() {
1095
1139
  const e = [], t = this.select.id;
1096
- t && document.querySelectorAll(`label[for="${t}"]`).forEach((a) => e.push(a));
1140
+ t && document.querySelectorAll(`label[for="${t}"]`).forEach((n) => e.push(n));
1097
1141
  let s = this.select.parentElement;
1098
1142
  for (; s && s !== document.body; ) {
1099
1143
  if (s.tagName === "LABEL") {
@@ -1103,8 +1147,8 @@ class M {
1103
1147
  s = s.parentElement;
1104
1148
  }
1105
1149
  Array.from(new Set(e)).forEach((l) => {
1106
- const a = l.__slimSelectLabelHandler;
1107
- a && (l.removeEventListener("click", a, { capture: !0 }), delete l.__slimSelectLabelHandler);
1150
+ const n = l.__slimSelectLabelHandler;
1151
+ n && (l.removeEventListener("click", n, { capture: !0 }), delete l.__slimSelectLabelHandler);
1108
1152
  });
1109
1153
  }
1110
1154
  destroy() {
@@ -1137,6 +1181,7 @@ class P {
1137
1181
  closeOnSelect;
1138
1182
  contentLocation;
1139
1183
  contentPosition;
1184
+ contentWidth;
1140
1185
  openPosition;
1141
1186
  placeholderText;
1142
1187
  allowDeselect;
@@ -1150,10 +1195,10 @@ class P {
1150
1195
  maxValuesMessage;
1151
1196
  addableText;
1152
1197
  constructor(e) {
1153
- e || (e = {}), this.id = "ss-" + C(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.keepSearch = e.keepSearch !== void 0 ? e.keepSearch : !1, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, this.contentLocation = e.contentLocation || document.body, this.contentPosition = e.contentPosition || "absolute", this.openPosition = e.openPosition || "auto", this.placeholderText = e.placeholderText !== void 0 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, 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}';
1198
+ e || (e = {}), this.id = "ss-" + y(), this.style = e.style || "", this.class = e.class || [], this.disabled = e.disabled !== void 0 ? e.disabled : !1, this.alwaysOpen = e.alwaysOpen !== void 0 ? e.alwaysOpen : !1, this.showSearch = e.showSearch !== void 0 ? e.showSearch : !0, this.focusSearch = e.focusSearch !== void 0 ? e.focusSearch : !0, this.keepSearch = e.keepSearch !== void 0 ? e.keepSearch : !1, this.ariaLabel = e.ariaLabel || "Combobox", this.searchPlaceholder = e.searchPlaceholder || "Search...", this.searchText = e.searchText || "No Results", this.searchingText = e.searchingText || "Searching...", this.searchHighlight = e.searchHighlight !== void 0 ? e.searchHighlight : !1, this.closeOnSelect = e.closeOnSelect !== void 0 ? e.closeOnSelect : !0, 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 ? e.placeholderText : "Select Value", this.allowDeselect = e.allowDeselect !== void 0 ? e.allowDeselect : !1, this.hideSelected = e.hideSelected !== void 0 ? e.hideSelected : !1, this.keepOrder = e.keepOrder !== void 0 ? e.keepOrder : !1, this.showOptionTooltips = e.showOptionTooltips !== void 0 ? e.showOptionTooltips : !1, 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}';
1154
1199
  }
1155
1200
  }
1156
- class I {
1201
+ class F {
1157
1202
  selectEl;
1158
1203
  // Classes
1159
1204
  settings;
@@ -1185,18 +1230,18 @@ class I {
1185
1230
  e.events && e.events.error && e.events.error(new Error("Element isnt of type select"));
1186
1231
  return;
1187
1232
  }
1188
- this.selectEl.dataset.ssid && this.destroy(), this.settings = new P(e.settings), this.cssClasses = new A(e.cssClasses);
1233
+ this.selectEl.dataset.ssid && this.destroy(), this.settings = new P(e.settings), this.cssClasses = new L(e.cssClasses);
1189
1234
  const t = ["beforeOpen", "afterOpen", "beforeClose", "afterClose"];
1190
- for (const n in e.events)
1191
- e.events.hasOwnProperty(n) && (t.indexOf(n) !== -1 ? this.events[n] = O(e.events[n], 100) : this.events[n] = e.events[n]);
1192
- 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 M(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.onValueChange = (n) => {
1193
- this.setSelected(n.map((o) => o.id));
1194
- }, this.select.onClassChange = (n) => {
1195
- this.settings.class = n, this.render.updateClassStyles();
1196
- }, this.select.onDisabledChange = (n) => {
1197
- n ? this.disable() : this.enable();
1198
- }, this.select.onOptionsChange = (n) => {
1199
- this.setData(n || []);
1235
+ for (const a in e.events)
1236
+ e.events.hasOwnProperty(a) && (t.indexOf(a) !== -1 ? this.events[a] = S(e.events[a], 100) : this.events[a] = e.events[a]);
1237
+ 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 M(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.onValueChange = (a) => {
1238
+ this.setSelected(a.map((o) => o.id));
1239
+ }, this.select.onClassChange = (a) => {
1240
+ this.settings.class = a, this.render.updateClassStyles();
1241
+ }, this.select.onDisabledChange = (a) => {
1242
+ a ? this.disable() : this.enable();
1243
+ }, this.select.onOptionsChange = (a) => {
1244
+ this.setData(a || []);
1200
1245
  }, this.select.onLabelClick = () => {
1201
1246
  this.settings.disabled || (this.settings.isOpen ? this.close() : this.open());
1202
1247
  };
@@ -1213,8 +1258,8 @@ class I {
1213
1258
  afterChange: this.events.afterChange
1214
1259
  };
1215
1260
  this.render = new N(this.settings, this.cssClasses, this.store, i), this.render.renderValues(), this.render.renderOptions(this.store.getData());
1216
- const l = this.selectEl.getAttribute("aria-label"), a = this.selectEl.getAttribute("aria-labelledby");
1217
- l ? this.render.main.main.setAttribute("aria-label", l) : a && this.render.main.main.setAttribute("aria-labelledby", a), this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), window.addEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.addEventListener("scroll", this.windowScroll, !1), document.addEventListener("visibilitychange", this.windowVisibilityChange), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.select.setupLabelHandlers(), this.selectEl.slim = this;
1261
+ const l = this.selectEl.getAttribute("aria-label"), n = this.selectEl.getAttribute("aria-labelledby");
1262
+ l ? this.render.main.main.setAttribute("aria-label", l) : n && this.render.main.main.setAttribute("aria-labelledby", n), this.selectEl.parentNode && this.selectEl.parentNode.insertBefore(this.render.main.main, this.selectEl.nextSibling), window.addEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.addEventListener("scroll", this.windowScroll, !1), document.addEventListener("visibilitychange", this.windowVisibilityChange), this.settings.disabled && this.disable(), this.settings.alwaysOpen && this.open(), this.select.setupLabelHandlers(), this.selectEl.slim = this;
1218
1263
  }
1219
1264
  // Set to enabled and remove disabled classes
1220
1265
  enable() {
@@ -1235,7 +1280,7 @@ class I {
1235
1280
  }
1236
1281
  this.store.setData(e);
1237
1282
  const i = this.store.getData();
1238
- this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !L(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1283
+ this.select.updateOptions(i), this.render.renderValues(), this.render.renderOptions(i), this.events.afterChange && !O(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1239
1284
  }
1240
1285
  getSelected() {
1241
1286
  let e = this.store.getSelectedOptions();
@@ -1246,31 +1291,31 @@ class I {
1246
1291
  const s = this.store.getSelected(), i = this.store.getDataOptions();
1247
1292
  e = Array.isArray(e) ? e : [e];
1248
1293
  const l = [];
1249
- for (const n of e) {
1250
- if (i.find((o) => o.id == n)) {
1251
- l.push(n);
1294
+ for (const a of e) {
1295
+ if (i.find((o) => o.id == a)) {
1296
+ l.push(a);
1252
1297
  continue;
1253
1298
  }
1254
- for (const o of i.filter((c) => c.value == n))
1299
+ for (const o of i.filter((h) => h.value == a))
1255
1300
  l.push(o.id);
1256
1301
  }
1257
1302
  this.store.setSelectedBy("id", l);
1258
- const a = this.store.getData();
1259
- this.select.updateOptions(a), this.render.renderValues(), this.render.content.search.input.value !== "" ? this.search(this.render.content.search.input.value) : this.render.renderOptions(a), t && this.events.afterChange && !L(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1303
+ const n = this.store.getData();
1304
+ this.select.updateOptions(n), this.render.renderValues(), this.render.content.search.input.value !== "" ? this.search(this.render.content.search.input.value) : this.render.renderOptions(n), t && this.events.afterChange && !O(s, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1260
1305
  }
1261
1306
  addOption(e) {
1262
1307
  const t = this.store.getSelected();
1263
1308
  this.store.getDataOptions().some((i) => i.value === (e.value ?? e.text)) || this.store.addOption(e);
1264
1309
  const s = this.store.getData();
1265
- this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !L(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1310
+ this.select.updateOptions(s), this.render.renderValues(), this.render.renderOptions(s), this.events.afterChange && !O(t, this.store.getSelected()) && this.events.afterChange(this.store.getSelectedOptions());
1266
1311
  }
1267
1312
  open() {
1268
- this.settings.disabled || this.settings.isOpen || (this.events.beforeOpen && this.events.beforeOpen(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.openTimeout = setTimeout(() => {
1313
+ this.settings.disabled || this.settings.isOpen || (this.closeTimeout && (clearTimeout(this.closeTimeout), this.closeTimeout = null), this.events.beforeOpen && this.events.beforeOpen(), this.render.open(), this.settings.showSearch && this.settings.focusSearch && this.render.searchFocus(), this.settings.isOpen = !0, this.openTimeout = setTimeout(() => {
1269
1314
  this.events.afterOpen && this.events.afterOpen(), this.settings.isOpen && (this.settings.isFullOpen = !0), document.addEventListener("click", this.documentClick);
1270
1315
  }, this.settings.timeoutDelay), this.settings.contentPosition === "absolute" && (this.settings.intervalMove && clearInterval(this.settings.intervalMove), this.settings.intervalMove = setInterval(this.render.moveContent.bind(this.render), 500)));
1271
1316
  }
1272
1317
  close(e = null) {
1273
- !this.settings.isOpen || this.settings.alwaysOpen || (this.events.beforeClose && this.events.beforeClose(), this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && this.search(""), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
1318
+ !this.settings.isOpen || this.settings.alwaysOpen || (this.openTimeout && (clearTimeout(this.openTimeout), this.openTimeout = null), this.events.beforeClose && this.events.beforeClose(), this.render.close(), !this.settings.keepSearch && this.render.content.search.input.value !== "" && this.search(""), this.render.mainFocus(e), this.settings.isOpen = !1, this.settings.isFullOpen = !1, this.closeTimeout = setTimeout(() => {
1274
1319
  this.events.afterClose && this.events.afterClose(), document.removeEventListener("click", this.documentClick);
1275
1320
  }, this.settings.timeoutDelay), this.settings.intervalMove && clearInterval(this.settings.intervalMove));
1276
1321
  }
@@ -1299,16 +1344,16 @@ class I {
1299
1344
  destroy() {
1300
1345
  this.openTimeout && (clearTimeout(this.openTimeout), this.openTimeout = null), this.closeTimeout && (clearTimeout(this.closeTimeout), this.closeTimeout = null), this.settings.intervalMove && (clearInterval(this.settings.intervalMove), this.settings.intervalMove = null), document.removeEventListener("click", this.documentClick), window.removeEventListener("resize", this.windowResize, !1), this.settings.openPosition === "auto" && window.removeEventListener("scroll", this.windowScroll, !1), document.removeEventListener("visibilitychange", this.windowVisibilityChange), this.store.setData([]), this.render.destroy(), this.select.destroy();
1301
1346
  }
1302
- windowResize = O(() => {
1347
+ windowResize = S(() => {
1303
1348
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1304
1349
  });
1305
1350
  // Event listener for window scrolling
1306
- windowScroll = O(() => {
1351
+ windowScroll = S(() => {
1307
1352
  !this.settings.isOpen && !this.settings.isFullOpen || this.render.moveContent();
1308
1353
  });
1309
1354
  // Event listener for document click
1310
1355
  documentClick = (e) => {
1311
- this.settings.isOpen && e.target && !T(e.target, this.settings.id) && this.close(e.type);
1356
+ this.settings.isOpen && e.target && !x(e.target, this.settings.id) && this.close(e.type);
1312
1357
  };
1313
1358
  // Event Listener for window visibility change
1314
1359
  windowVisibilityChange = () => {
@@ -1316,9 +1361,9 @@ class I {
1316
1361
  };
1317
1362
  }
1318
1363
  export {
1319
- g as Optgroup,
1364
+ m as Optgroup,
1320
1365
  u as Option,
1321
1366
  P as Settings,
1322
- I as default
1367
+ F as default
1323
1368
  };
1324
1369
  //# sourceMappingURL=slimselect.es.js.map