@cas-smartdesign/virtual-list 7.0.2 → 7.2.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,10 +1,10 @@
1
1
  import { LitElement as p, unsafeCSS as b, css as _, html as x } from "lit";
2
- import { property as d } from "lit/decorators/property.js";
2
+ import { property as l } from "lit/decorators/property.js";
3
3
  import f, { generator as g } from "@cas-smartdesign/list-item";
4
4
  class C {
5
- getOffsetForIndexAndAlignment(e, t, i, n, s, a) {
6
- const m = Math.max(0, a * n), u = Math.min(m, e * n), c = Math.max(0, e * n - s + n);
7
- switch (t) {
5
+ getOffsetForIndexAndAlignment(t, e, i, n, s, r) {
6
+ const m = Math.max(0, r * n), u = Math.min(m, t * n), c = Math.max(0, t * n - s + n);
7
+ switch (e) {
8
8
  case "start":
9
9
  return u;
10
10
  case "end":
@@ -13,28 +13,27 @@ class C {
13
13
  const I = Math.round(c + (u - c) / 2);
14
14
  return I < Math.ceil(s / 2) ? 0 : I > m + Math.floor(s / 2) ? m : I;
15
15
  }
16
- case "auto":
17
16
  default:
18
17
  return i >= c && i <= u ? i : i < c ? c : u;
19
18
  }
20
19
  }
21
20
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- debounce(e) {
23
- let t;
21
+ debounce(t) {
22
+ let e;
24
23
  return (...i) => {
25
- t && window.cancelAnimationFrame(t), t = window.requestAnimationFrame(() => {
26
- e(...i), t = null;
24
+ e && window.cancelAnimationFrame(e), e = window.requestAnimationFrame(() => {
25
+ t(...i), e = null;
27
26
  });
28
27
  };
29
28
  }
30
29
  }
31
30
  const w = new C();
32
31
  class T {
33
- constructor(e = 100, t = 5) {
34
- this.pageSize = e, this.preloadedItemsCount = t, this._finalSizeIsKnown = !1, this._itemCache = [], this._lastRequestedFirstIndex = 0, this._lastRequestedLastIndex = 0, this._lastLoadedIndex = 0, this.handleListDataRequest = (i) => {
32
+ constructor(t = 100, e = 5) {
33
+ this.pageSize = t, this.preloadedItemsCount = e, this._finalSizeIsKnown = !1, this._itemCache = [], this._lastRequestedFirstIndex = 0, this._lastRequestedLastIndex = 0, this._lastLoadedIndex = 0, this.handleListDataRequest = (i) => {
35
34
  const { startIndex: n, stopIndex: s } = i.detail;
36
35
  this._lastRequestedFirstIndex = n, this._lastRequestedLastIndex = s, this._list.items = this._itemCache.slice(n, s + 1), !this.finalSizeIsKnown && this._lastLoadedIndex < s + this.preloadedItemsCount && this.requestData();
37
- }, this.itemCount = e;
36
+ }, this.itemCount = t;
38
37
  }
39
38
  get currentPage() {
40
39
  return this.items.length == 0 && this.finalSizeIsKnown ? 0 : Math.floor((this.items.length - 1) / this.pageSize);
@@ -42,26 +41,26 @@ class T {
42
41
  get finalSizeIsKnown() {
43
42
  return this._finalSizeIsKnown;
44
43
  }
45
- set finalSizeIsKnown(e) {
46
- this._finalSizeIsKnown = e, e && (this.itemCount = this._itemCache.length), this._list && (this._list.finalSizeIsKnown = e);
44
+ set finalSizeIsKnown(t) {
45
+ this._finalSizeIsKnown = t, t && (this.itemCount = this._itemCache.length), this._list && (this._list.finalSizeIsKnown = t);
47
46
  }
48
47
  get itemCount() {
49
48
  return this._itemCount;
50
49
  }
51
- set itemCount(e) {
52
- this._itemCount = e, this._list && (this._list.itemCount = e);
50
+ set itemCount(t) {
51
+ this._itemCount = t, this._list && (this._list.itemCount = t);
53
52
  }
54
53
  get items() {
55
54
  return this._itemCache;
56
55
  }
57
- set items(e) {
58
- this._itemCache = e, this.onItemsChange();
56
+ set items(t) {
57
+ this._itemCache = t, this.onItemsChange();
59
58
  }
60
- addItems(e) {
61
- this._itemCache = this._itemCache.concat(e), this.onItemsChange();
59
+ addItems(t) {
60
+ this._itemCache = this._itemCache.concat(t), this.onItemsChange();
62
61
  }
63
- connectList(e) {
64
- this._list && this._list.removeEventListener("data-request", this.handleListDataRequest), this._list = e, e.itemCount = this.itemCount, e.addEventListener("data-request", this.handleListDataRequest), e.finalSizeIsKnown = this._finalSizeIsKnown;
62
+ connectList(t) {
63
+ this._list && this._list.removeEventListener("data-request", this.handleListDataRequest), this._list = t, t.itemCount = this.itemCount, t.addEventListener("data-request", this.handleListDataRequest), t.finalSizeIsKnown = this._finalSizeIsKnown;
65
64
  }
66
65
  onItemsChange() {
67
66
  this._pendingDataRequest = !1, this._lastLoadedIndex = this._itemCache.length - 1, this.finalSizeIsKnown ? this.itemCount = this._itemCache.length : this._lastLoadedIndex > this.itemCount && (this.itemCount = this._lastLoadedIndex), this._list && (this._list.items = this._itemCache.slice(this._lastRequestedFirstIndex, this._lastRequestedLastIndex + 1));
@@ -76,23 +75,23 @@ class T {
76
75
  );
77
76
  }
78
77
  }
79
- const S = ":host{display:block;position:relative;contain:layout}:host(:focus){outline:none}:host(:focus-visible) ::slotted([focused]){box-shadow:0 0 0 1px #1467ba inset}.container{width:100%}.container>::slotted(*){width:100%;position:absolute;box-sizing:border-box}.container>::slotted(:not([last])){border-bottom:1px solid #d9d9d9}";
80
- var v = Object.defineProperty, A = Object.getOwnPropertyDescriptor, l = (h, e, t, i) => {
81
- for (var n = i > 1 ? void 0 : i ? A(e, t) : e, s = h.length - 1, a; s >= 0; s--)
82
- (a = h[s]) && (n = (i ? a(e, t, n) : a(n)) || n);
83
- return i && n && v(e, t, n), n;
78
+ const v = ":host{display:block;position:relative;contain:layout;--sd-virtual-list-focus-highlight-color: #1467ba;--sd-virtual-list-item-separator-color: #d9d9d9}:host(:focus){outline:none}:host(:focus-visible) ::slotted([focused]){box-shadow:0 0 0 1px var(--sd-virtual-list-focus-highlight-color) inset}.container{width:100%}.container>::slotted(*){width:100%;position:absolute;box-sizing:border-box}.container>::slotted(:not([last])){border-bottom:1px solid var(--sd-virtual-list-item-separator-color)}";
79
+ var S = Object.defineProperty, A = Object.getOwnPropertyDescriptor, d = (h, t, e, i) => {
80
+ for (var n = i > 1 ? void 0 : i ? A(t, e) : t, s = h.length - 1, r; s >= 0; s--)
81
+ (r = h[s]) && (n = (i ? r(t, e, n) : r(n)) || n);
82
+ return i && n && S(t, e, n), n;
84
83
  }, y = /* @__PURE__ */ ((h) => (h.TriggerOnly = "trigger-only", h.Single = "single", h.Multi = "multi", h))(y || {});
85
84
  let L = 0;
86
- var r;
87
- const o = (r = class extends p {
85
+ var a;
86
+ const o = (a = class extends p {
88
87
  constructor() {
89
- super(), this.items = [], this.selectionType = "trigger-only", this.id = r.ID + "_" + L++, this.role = "listbox", this.itemGenerator = g, this._lastKnownScrollTop = 0, this._lastRenderedScrollTop = 0, this._itemsRenderData = [], this._elementCache = /* @__PURE__ */ new Map(), this._visibleItemsNum = 0, this._selectedIndices = [], this._focusIndex = -1, this._lastKnownHeight = 0, this.onScroll = () => {
88
+ super(), this.items = [], this.selectionType = "trigger-only", this.id = a.ID + "_" + L++, this.role = "listbox", this.itemGenerator = g, this._lastKnownScrollTop = 0, this._lastRenderedScrollTop = 0, this._itemsRenderData = [], this._elementCache = /* @__PURE__ */ new Map(), this._visibleItemsNum = 0, this._selectedIndices = [], this._focusIndex = -1, this._lastKnownHeight = 0, this.onScroll = () => {
90
89
  this._lastKnownScrollTop = this.scrollTop;
91
- const e = this._lastRenderedScrollTop - this._lastKnownScrollTop;
92
- Math.abs(e) >= this.itemHeight && (this._lastRenderedScrollTop = this._lastKnownScrollTop, this.requestUpdate());
93
- }, this.handleKeyDown = (e) => {
94
- let t = !0;
95
- switch (e.key) {
90
+ const t = this._lastRenderedScrollTop - this._lastKnownScrollTop;
91
+ Math.abs(t) >= this.itemHeight && (this._lastRenderedScrollTop = this._lastKnownScrollTop, this.requestUpdate());
92
+ }, this.handleKeyDown = (t) => {
93
+ let e = !0;
94
+ switch (t.key) {
96
95
  case "Down":
97
96
  case "ArrowDown":
98
97
  this.focusIndex = (this.focusIndex + 1) % this.itemCount;
@@ -102,7 +101,7 @@ const o = (r = class extends p {
102
101
  this.focusIndex > 0 ? this.focusIndex-- : this.finalSizeIsKnown && (this.focusIndex = this.itemCount - 1);
103
102
  break;
104
103
  case "Enter":
105
- this.handleSelection(this.focusIndex, e);
104
+ this.handleSelection(this.focusIndex, t);
106
105
  break;
107
106
  case "End":
108
107
  this.focusIndex = this.itemCount - 1;
@@ -117,10 +116,10 @@ const o = (r = class extends p {
117
116
  this.focusIndex = this.normalizeIndex(this.focusIndex - this._visibleItemsNum + 1);
118
117
  break;
119
118
  default:
120
- t = !1;
119
+ e = !1;
121
120
  break;
122
121
  }
123
- t && (e.preventDefault(), e.stopPropagation());
122
+ e && (t.preventDefault(), t.stopPropagation());
124
123
  }, this._resizeObserver = new ResizeObserver(() => {
125
124
  this._lastKnownHeight !== this.offsetHeight && (this._lastKnownHeight = this.offsetHeight, this.requestUpdate());
126
125
  });
@@ -128,36 +127,36 @@ const o = (r = class extends p {
128
127
  get focusTarget() {
129
128
  return this.hasAttribute("focus-target");
130
129
  }
131
- set focusTarget(e) {
132
- this.toggleAttribute("focus-target", e);
130
+ set focusTarget(t) {
131
+ this.toggleAttribute("focus-target", t);
133
132
  }
134
133
  get focusIndex() {
135
134
  return this._focusIndex;
136
135
  }
137
- set focusIndex(e) {
138
- if (e >= -1 && e < this.itemCount) {
139
- const t = this._focusIndex;
140
- this._focusIndex = e, (e <= this._firstVisibleIndex || this._lastVisibleIndex <= e) && this.scrollToItem(e), t != e && (e == -1 && this.removeAttribute("aria-activedescendant"), this.requestUpdate("focusIndex", t));
136
+ set focusIndex(t) {
137
+ if (t >= -1 && t < this.itemCount) {
138
+ const e = this._focusIndex;
139
+ this._focusIndex = t, (t <= this._firstVisibleIndex || this._lastVisibleIndex <= t) && this.scrollToItem(t), e != t && (t == -1 && this.removeAttribute("aria-activedescendant"), this.requestUpdate("focusIndex", e));
141
140
  }
142
141
  }
143
142
  get selectedIndices() {
144
143
  return this._selectedIndices;
145
144
  }
146
- set selectedIndices(e) {
147
- e ? this._selectedIndices = e.map((t) => Number(t)) : this._selectedIndices = [], this.requestUpdate("selectedIndices");
145
+ set selectedIndices(t) {
146
+ t ? this._selectedIndices = t.map((e) => Number(e)) : this._selectedIndices = [], this.requestUpdate("selectedIndices");
148
147
  }
149
- scrollToItem(e, t = "auto") {
148
+ scrollToItem(t, e = "auto") {
150
149
  this.scrollTop = w.getOffsetForIndexAndAlignment(
151
- this.normalizeIndex(e),
152
- t,
150
+ this.normalizeIndex(t),
151
+ e,
153
152
  this.scrollTop,
154
153
  this.itemHeight,
155
154
  this.height,
156
155
  this.itemCount
157
156
  ), this._lastKnownScrollTop = this.scrollTop;
158
157
  }
159
- getListItem(e) {
160
- return !this.shadowRoot || e < this._firstVisibleIndex || this._lastVisibleIndex < e ? null : this.querySelector(`[item-index="${e}"]`);
158
+ getListItem(t) {
159
+ return !this.shadowRoot || t < this._firstVisibleIndex || this._lastVisibleIndex < t ? null : this.querySelector(`[item-index="${t}"]`);
161
160
  }
162
161
  connectedCallback() {
163
162
  super.connectedCallback(), this._resizeObserver.observe(this), this.scrollTop !== this._lastKnownScrollTop && (this.scrollTop = this._lastKnownScrollTop, this.requestUpdate());
@@ -165,9 +164,9 @@ const o = (r = class extends p {
165
164
  disconnectedCallback() {
166
165
  super.disconnectedCallback(), this._resizeObserver.disconnect();
167
166
  }
168
- firstUpdated(e) {
169
- super.firstUpdated(e), this.addEventListener("scroll", this.onScroll), this.addEventListener("keydown", this.handleKeyDown), this.addEventListener("click", this.handleClick), this.addEventListener("mousedown", (t) => {
170
- t.button == 1 && t.preventDefault();
167
+ firstUpdated(t) {
168
+ super.firstUpdated(t), this.addEventListener("scroll", this.onScroll), this.addEventListener("keydown", this.handleKeyDown), this.addEventListener("click", this.handleClick), this.addEventListener("mousedown", (e) => {
169
+ e.button == 1 && e.preventDefault();
171
170
  }), this.addEventListener("auxclick", this.handleClick), this.addEventListener("focus", () => {
172
171
  this.matches(":focus-visible") && (this.focusIndex == -1 ? (this.selectedIndices && (this.focusIndex = this.selectedIndices[0]), this.focusIndex == -1 && this.itemCount > 0 && (this.focusIndex = 0)) : this.updateFocusedItemAttributes());
173
172
  }), this.addEventListener("blur", () => {
@@ -175,13 +174,13 @@ const o = (r = class extends p {
175
174
  }), this.selectedIndices.length > 0 && this.scrollToItem(this.selectedIndices[0], "center");
176
175
  }
177
176
  updateFocusedItemAttributes() {
178
- const e = this.getListItem(this.focusIndex);
179
- e && (this.focusTarget || document.activeElement == this ? (e.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", e.id)) : (e.removeAttribute("focused"), this.removeAttribute("aria-activedescendant")));
177
+ const t = this.getListItem(this.focusIndex);
178
+ t && (this.focusTarget || document.activeElement == this ? (t.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", t.id)) : (t.removeAttribute("focused"), this.removeAttribute("aria-activedescendant")));
180
179
  }
181
180
  static get styles() {
182
181
  return [
183
182
  _`
184
- ${b(S)}
183
+ ${b(v)}
185
184
  `
186
185
  ];
187
186
  }
@@ -192,39 +191,39 @@ const o = (r = class extends p {
192
191
  </div>
193
192
  `;
194
193
  }
195
- updated(e) {
196
- if (super.updated(e), this._lastRenderedScrollTop = this._lastKnownScrollTop, this.updateItems(), (this._increaseWidthOnNextRenderIfNeeded || this._reachedMaxWidth) && //
194
+ updated(t) {
195
+ if (super.updated(t), this._lastRenderedScrollTop = this._lastKnownScrollTop, this.updateItems(), (this._increaseWidthOnNextRenderIfNeeded || this._reachedMaxWidth) && //
197
196
  this._firstVisibleIndex < this._lastVisibleIndex)
198
197
  if (this.querySelector("[item-index]"))
199
198
  this.adjustWidthIfNeeded();
200
199
  else {
201
- const t = new MutationObserver(() => {
202
- this.adjustWidthIfNeeded(), t.disconnect();
200
+ const e = new MutationObserver(() => {
201
+ this.adjustWidthIfNeeded(), e.disconnect();
203
202
  });
204
- t.observe(this);
203
+ e.observe(this);
205
204
  }
206
205
  }
207
206
  adjustWidthIfNeeded() {
208
207
  this._increaseWidthOnNextRenderIfNeeded ? (this._increaseWidthOnNextRenderIfNeeded = !1, window.requestAnimationFrame(() => {
209
- const e = Number.parseInt(getComputedStyle(this).maxWidth) - this.offsetWidth;
210
- if (e == 0)
208
+ const t = Number.parseInt(getComputedStyle(this).maxWidth) - this.offsetWidth;
209
+ if (t == 0)
211
210
  this._reachedMaxWidth = !0, this.enableLineClampOnItemsIfNeeded();
212
211
  else {
213
212
  this._reachedMaxWidth = !1;
214
- const t = [...this.querySelectorAll("[item-index]")].map((n) => {
213
+ const e = [...this.querySelectorAll("[item-index]")].map((n) => {
215
214
  if (n instanceof f) {
216
215
  n.enableLineClamp = !1;
217
216
  const s = n.missingWidthForTexts;
218
- return s > e && (n.enableLineClamp = !0), s;
217
+ return s > t && (n.enableLineClamp = !0), s;
219
218
  }
220
- }), i = Math.max(...t);
219
+ }), i = Math.max(...e);
221
220
  i > 0 && (this.style.width = `${this.offsetWidth + i}px`);
222
221
  }
223
222
  })) : this._reachedMaxWidth && this.enableLineClampOnItemsIfNeeded();
224
223
  }
225
224
  enableLineClampOnItemsIfNeeded() {
226
- this.querySelectorAll("[item-index]").forEach((e) => {
227
- e instanceof f && (e.enableLineClamp = e.enableLineClamp || e.missingWidthForTexts > 0);
225
+ this.querySelectorAll("[item-index]").forEach((t) => {
226
+ t instanceof f && (t.enableLineClamp = t.enableLineClamp || t.missingWidthForTexts > 0);
228
227
  });
229
228
  }
230
229
  /**
@@ -237,122 +236,122 @@ const o = (r = class extends p {
237
236
  this._increaseWidthOnNextRenderIfNeeded = !0;
238
237
  }
239
238
  updateItems() {
240
- const e = [...this.querySelectorAll("[item-index]")], t = /* @__PURE__ */ new Map(), i = document.createDocumentFragment();
239
+ const t = [...this.querySelectorAll("[item-index]")], e = /* @__PURE__ */ new Map(), i = document.createDocumentFragment();
241
240
  for (const n of this._itemsRenderData) {
242
241
  const s = this.renderItem(n);
243
- s.parentElement || i.appendChild(s), t.set(n.dataHash, s);
244
- const a = e.indexOf(s);
245
- a !== -1 && e.splice(a, 1);
242
+ s.parentElement || i.appendChild(s), e.set(n.dataHash, s);
243
+ const r = t.indexOf(s);
244
+ r !== -1 && t.splice(r, 1);
246
245
  }
247
246
  this.appendChild(i);
248
- for (const n of e)
247
+ for (const n of t)
249
248
  n instanceof f && (n.enableLineClamp = !1), this.removeChild(n);
250
- t.forEach((n, s) => {
249
+ e.forEach((n, s) => {
251
250
  this._elementCache.set(s, n);
252
251
  });
253
252
  }
254
- renderItem({ index: e, top: t, dataHash: i, data: n }) {
253
+ renderItem({ index: t, top: e, dataHash: i, data: n }) {
255
254
  let s;
256
- return n ? this._elementCache.has(i) ? (s = this._elementCache.get(i), this._elementCache.delete(i)) : (s = this.itemGenerator(n, e), s.setAttribute("slot", "items")) : (s = document.createElement("div"), s.setAttribute("placeholder-item", ""), s.setAttribute("slot", "items")), Object.assign(s.style, {
257
- transform: `translateY(${t}px)`,
255
+ return n ? this._elementCache.has(i) ? (s = this._elementCache.get(i), this._elementCache.delete(i)) : (s = this.itemGenerator(n, t), s.setAttribute("slot", "items")) : (s = document.createElement("div"), s.setAttribute("placeholder-item", ""), s.setAttribute("slot", "items")), Object.assign(s.style, {
256
+ transform: `translateY(${e}px)`,
258
257
  height: `${this.itemHeight}px`
259
- }), s.setAttribute("item-index", e.toString()), s.setAttribute("aria-setsize", String(this.finalSizeIsKnown ? this.itemCount : -1)), s.setAttribute("aria-posinset", String(e + 1)), (!s.id || s.id.startsWith(this.id + "_item_")) && (s.id = this.id + "_item_" + e), this.itemCount - 1 == e ? s.setAttribute("last", "") : s.removeAttribute("last"), this.updateSelectedAttribute(e, s), this.updateFocusedAttribute(e, s), s;
258
+ }), s.setAttribute("item-index", t.toString()), s.setAttribute("aria-setsize", String(this.finalSizeIsKnown ? this.itemCount : -1)), s.setAttribute("aria-posinset", String(t + 1)), (!s.id || s.id.startsWith(this.id + "_item_")) && (s.id = this.id + "_item_" + t), this.itemCount - 1 == t ? s.setAttribute("last", "") : s.removeAttribute("last"), this.updateSelectedAttribute(t, s), this.updateFocusedAttribute(t, s), s;
260
259
  }
261
- updateFocusedAttribute(e, t) {
262
- this.focusIndex == e && (this.focusTarget || document.activeElement == this) ? (t.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", t.id)) : t.removeAttribute("focused");
260
+ updateFocusedAttribute(t, e) {
261
+ this.focusIndex == t && (this.focusTarget || document.activeElement == this) ? (e.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", e.id)) : e.removeAttribute("focused");
263
262
  }
264
- updateSelectedAttribute(e, t) {
265
- const i = this.selectedIndices.indexOf(e) !== -1;
266
- i ? t.setAttribute("selected", "") : t.removeAttribute("selected"), t.setAttribute("aria-selected", String(i));
263
+ updateSelectedAttribute(t, e) {
264
+ const i = this.selectedIndices.indexOf(t) !== -1;
265
+ i ? e.setAttribute("selected", "") : e.removeAttribute("selected"), e.setAttribute("aria-selected", String(i));
267
266
  }
268
267
  updateItemsRenderData() {
269
268
  if (this._itemsRenderData = [], this._visibleItemsNum = Math.min(Math.ceil(this.height / this.itemHeight), this.itemCount), this._visibleItemsNum > 0) {
270
269
  this._firstVisibleIndex = this.normalizeIndex(Math.floor(this._lastKnownScrollTop / this.itemHeight)), this._lastVisibleIndex = this.normalizeIndex(this._firstVisibleIndex + this._visibleItemsNum);
271
- const e = this.normalizeIndex(this._firstVisibleIndex - 2), t = this.normalizeIndex(this._lastVisibleIndex + 2);
272
- this.requestData(e, t);
273
- for (let i = e; i <= t; i++) {
274
- const n = i - e, s = this.items[n];
275
- let a;
276
- s ? a = JSON.stringify(s) : a = `placeholder-${n}`, this._itemsRenderData.push({
270
+ const t = this.normalizeIndex(this._firstVisibleIndex - 2), e = this.normalizeIndex(this._lastVisibleIndex + 2);
271
+ this.requestData(t, e);
272
+ for (let i = t; i <= e; i++) {
273
+ const n = i - t, s = this.items[n];
274
+ let r;
275
+ s ? r = JSON.stringify(s) : r = `placeholder-${n}`, this._itemsRenderData.push({
277
276
  index: i,
278
277
  top: this.itemHeight * i,
279
278
  physicalIndex: n,
280
- dataHash: a,
279
+ dataHash: r,
281
280
  data: s
282
281
  });
283
282
  }
284
283
  } else
285
284
  this._firstVisibleIndex = 0, this._lastVisibleIndex = 0;
286
285
  }
287
- normalizeIndex(e) {
288
- return Math.max(0, Math.min(e, this.itemCount - 1));
286
+ normalizeIndex(t) {
287
+ return Math.max(0, Math.min(t, this.itemCount - 1));
289
288
  }
290
289
  get height() {
291
290
  return this.offsetHeight;
292
291
  }
293
- requestData(e, t) {
294
- !Number.isNaN(e) && !Number.isNaN(t) && this.dispatchEvent(
292
+ requestData(t, e) {
293
+ !Number.isNaN(t) && !Number.isNaN(e) && this.dispatchEvent(
295
294
  new CustomEvent("data-request", {
296
295
  detail: {
297
- startIndex: e,
298
- stopIndex: t
296
+ startIndex: t,
297
+ stopIndex: e
299
298
  }
300
299
  })
301
300
  );
302
301
  }
303
- handleSelection(e, t) {
304
- if (e < 0 || this.itemCount <= e)
302
+ handleSelection(t, e) {
303
+ if (t < 0 || this.itemCount <= t)
305
304
  return;
306
- const i = this.getListItem(e);
305
+ const i = this.getListItem(t);
307
306
  if (i.getAttribute("aria-disabled") == "true" || i.hasAttribute("disabled"))
308
307
  return;
309
308
  let n = !0;
310
309
  if (this.selectionType !== "trigger-only") {
311
- const s = this.selectedIndices.indexOf(e);
312
- n = s == -1, n ? this.selectionType === "single" ? this.selectedIndices = [e] : this.selectedIndices.push(e) : this.selectedIndices.splice(s, 1), this.requestUpdate("selectedIndices");
310
+ const s = this.selectedIndices.indexOf(t);
311
+ n = s == -1, n ? this.selectionType === "single" ? this.selectedIndices = [t] : this.selectedIndices.push(t) : this.selectedIndices.splice(s, 1), this.requestUpdate("selectedIndices");
313
312
  }
314
- this.focusIndex = e, this.dispatchSelectionEvent(e, n, t);
313
+ this.focusIndex = t, this.dispatchSelectionEvent(t, n, e);
315
314
  }
316
- dispatchSelectionEvent(e, t, i) {
315
+ dispatchSelectionEvent(t, e, i) {
317
316
  this.dispatchEvent(
318
317
  new CustomEvent("selection", {
319
- detail: { index: e, selected: t, originalEvent: i }
318
+ detail: { index: t, selected: e, originalEvent: i }
320
319
  })
321
320
  );
322
321
  }
323
- handleClick(e) {
324
- const t = e.composedPath().find((i) => i.hasAttribute && i.hasAttribute("item-index"));
325
- if (t) {
326
- const i = parseInt(t.getAttribute("item-index"));
327
- Number.isInteger(i) && ((e.button == 0 || e.button == 1) && this.handleSelection(i, e), this.focusIndex = i);
322
+ handleClick(t) {
323
+ const e = t.composedPath().find((i) => i.hasAttribute && i.hasAttribute("item-index"));
324
+ if (e) {
325
+ const i = parseInt(e.getAttribute("item-index"));
326
+ Number.isInteger(i) && ((t.button == 0 || t.button == 1) && this.handleSelection(i, t), this.focusIndex = i);
328
327
  }
329
328
  }
330
- }, r.ID = "sd-virtual-list", r.ensureDefined = () => {
331
- f.ensureDefined(), customElements.get(r.ID) || customElements.define(r.ID, r);
332
- }, r);
333
- l([
334
- d({ type: Number, attribute: "item-height", reflect: !0 })
329
+ }, a.ID = "sd-virtual-list", a.ensureDefined = () => {
330
+ f.ensureDefined(), customElements.get(a.ID) || customElements.define(a.ID, a);
331
+ }, a);
332
+ d([
333
+ l({ type: Number, attribute: "item-height", reflect: !0 })
335
334
  ], o.prototype, "itemHeight", 2);
336
- l([
337
- d({ type: Number })
335
+ d([
336
+ l({ type: Number })
338
337
  ], o.prototype, "itemCount", 2);
339
- l([
340
- d({ type: Array, attribute: !1 })
338
+ d([
339
+ l({ type: Array, attribute: !1 })
341
340
  ], o.prototype, "items", 2);
342
- l([
343
- d({ type: String, attribute: "selection-type", reflect: !0, noAccessor: !0 })
341
+ d([
342
+ l({ type: String, attribute: "selection-type", reflect: !0, noAccessor: !0 })
344
343
  ], o.prototype, "selectionType", 2);
345
- l([
346
- d({ type: String, attribute: !0, reflect: !0 })
344
+ d([
345
+ l({ type: String, attribute: !0, reflect: !0 })
347
346
  ], o.prototype, "id", 2);
348
- l([
349
- d({ type: String, reflect: !0 })
347
+ d([
348
+ l({ type: String, reflect: !0 })
350
349
  ], o.prototype, "role", 2);
351
- l([
352
- d({ type: Number, attribute: "focus-index", reflect: !0 })
350
+ d([
351
+ l({ type: Number, attribute: "focus-index", reflect: !0 })
353
352
  ], o.prototype, "focusIndex", 1);
354
- l([
355
- d({ type: Array, attribute: !1 })
353
+ d([
354
+ l({ type: Array, attribute: !1 })
356
355
  ], o.prototype, "selectedIndices", 1);
357
356
  let D = o;
358
357
  D.ensureDefined();