@getflip/swirl-components 0.534.0 → 0.534.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/components.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "timestamp": "2026-11-05T17:54:49",
2
+ "timestamp": "2026-11-10T13:27:51",
3
3
  "compiler": {
4
4
  "name": "@stencil/core",
5
5
  "version": "4.43.1",
@@ -2265,10 +2265,6 @@ const SwirlTable = class {
2265
2265
  */
2266
2266
  this.virtualizationKeepRowsRendered = [];
2267
2267
  this.liveRegionText = "";
2268
- this.triggerRerender = utils.debounce(async () => {
2269
- await this.updateLayout();
2270
- this.updateEmptyState();
2271
- }, 0, true);
2272
2268
  this.updateLayout = debouncePromise(async () => {
2273
2269
  this.resetCellStyles();
2274
2270
  this.resetColumnStyles();
@@ -2448,7 +2444,7 @@ const SwirlTable = class {
2448
2444
  this.setupDragDrop();
2449
2445
  }
2450
2446
  if (rowWasAddedOrRemoved || rowIndexChanged) {
2451
- this.syncVirtualizedRows();
2447
+ this.syncVirtualizedRows({ layOutCells: rowWasAddedOrRemoved });
2452
2448
  }
2453
2449
  });
2454
2450
  this.startRowMutationObserver();
@@ -2545,7 +2541,10 @@ const SwirlTable = class {
2545
2541
  * Force a re-render of the table
2546
2542
  */
2547
2543
  async rerender() {
2548
- this.triggerRerender();
2544
+ // updateLayout is debounced with a trailing call, so a row that loads
2545
+ // while a layout runs still gets laid out.
2546
+ await this.updateLayout();
2547
+ this.updateEmptyState();
2549
2548
  }
2550
2549
  resetEmptyRowStyles() {
2551
2550
  const emptyRow = this.el.querySelector(".table__empty-row");
@@ -2647,11 +2646,14 @@ const SwirlTable = class {
2647
2646
  layOutCellsAndColumns() {
2648
2647
  const columns = this.getColumns();
2649
2648
  const cells = this.getCells();
2649
+ // Measure every column before sizing any cell. The table is as wide as its
2650
+ // widest row, so sizing one column's cells moves the columns not measured
2651
+ // yet.
2652
+ const columnProperties = columns.map((column, colIndex) => this.calculateColumnProperties(column, columns, colIndex));
2650
2653
  columns.forEach((column, colIndex) => {
2651
2654
  const cellsOfColumn = this.getCellsForColumn(cells, columns, colIndex);
2652
- const columnProperties = this.calculateColumnProperties(column, columns, colIndex);
2653
- cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties));
2654
- this.applyColumnStyles(column, columnProperties);
2655
+ cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties[colIndex]));
2656
+ this.applyColumnStyles(column, columnProperties[colIndex]);
2655
2657
  });
2656
2658
  }
2657
2659
  getCellsForColumn(cells, columns, colIndex) {
@@ -2821,13 +2823,19 @@ const SwirlTable = class {
2821
2823
  * Measures and positions rows after they were added, removed or re-indexed.
2822
2824
  * The focused row's index is read again first, as it changes when e.g. a row
2823
2825
  * is inserted above it.
2826
+ *
2827
+ * Added rows and cells are laid out too: a row calls `rerender()` only when
2828
+ * it first loads, so cells added to a drawn row would get no width.
2824
2829
  */
2825
- syncVirtualizedRows() {
2830
+ syncVirtualizedRows({ layOutCells }) {
2826
2831
  if (!this.virtualizer) {
2827
2832
  return;
2828
2833
  }
2829
2834
  this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within"));
2830
2835
  this.virtualizer.sync();
2836
+ if (layOutCells) {
2837
+ this.updateLayout();
2838
+ }
2831
2839
  }
2832
2840
  /** Keeps the focused row drawn, so it doesn't lose focus. */
2833
2841
  trackFocusedRow(target) {
@@ -2848,9 +2856,9 @@ const SwirlTable = class {
2848
2856
  "table--show-empty-state": this.empty && !this.loading,
2849
2857
  "table--keyboard-move": this.movingViaKeyboard,
2850
2858
  });
2851
- return (index$1.h(index$1.Host, { key: '5fd51d538c87dce53702fa483657035e251d3507' }, index$1.h("div", { key: '7ec3b5830bcc7b0dfc5324f554b80b442b7bc290', class: className }, this.enableDragDrop && (index$1.h("swirl-visually-hidden", { key: '2928eb420bb8cad6477917a1883aeeffda3260eb' }, index$1.h("span", { key: 'fc615afed57d8dbfbf636f9e8feb9c6ef76ae72b', "aria-live": "assertive" }, this.liveRegionText))), index$1.h("div", { key: '4b7d5b9c4691d1828d0c24fc635d8e7c5dc48cf4', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, index$1.h("div", { key: '9669435927eb4944290b4fdcb4083ef1473c000e', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
2859
+ return (index$1.h(index$1.Host, { key: '24e14d3eb739219aa9965fe16ccff5e9dae28180' }, index$1.h("div", { key: '25deaf84f1bb1131977e6e07f45ac2301585354d', class: className }, this.enableDragDrop && (index$1.h("swirl-visually-hidden", { key: '277292ebfaa8c1ada6c5c982b214efbda5f2f8a9' }, index$1.h("span", { key: 'e07ea9745ee40064160001ed0d702971cce78efa', "aria-live": "assertive" }, this.liveRegionText))), index$1.h("div", { key: 'f6919c9d48793c1abba7901b4365817ae7dfc5dc', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, index$1.h("div", { key: 'b7d1bb696755df6fd20983eebf6b800685a59983', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
2852
2860
  ? this.virtualizationRowCount + 1
2853
- : undefined, role: "table", class: "table__table" }, this.caption && (index$1.h("swirl-visually-hidden", { key: '6806eedf8d1aa22b3ee8f51736032ead77a502cc' }, index$1.h("div", { key: 'bea8e3d31ba2e81461ff8e4d056ee3ea718707ea', id: "caption" }, this.caption))), index$1.h("div", { key: '386fa4a8c2d31471a43580b62ad1003cfbcf224d', role: "rowgroup" }, index$1.h("div", { key: 'aebae228fab2eb7d4a688bb50ee069e7138001c1', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, index$1.h("slot", { key: '111dd938896772934ba589167ee254936c8bbe9d', name: "columns" }))), index$1.h("div", { key: '7a6b87e277bd50dfc8c5ff3e680aabe95384bb7f', class: "table__body", ref: (el) => (this.bodyEl = el) }, index$1.h("slot", { key: 'a766d1ff38bf321fac0b3c52a686d57d2b4551ea', name: "rows" }), index$1.h("div", { key: 'a26bec40f580546c85e3dd1007c913d53da4c18a', class: "table__empty-row", role: "row" }, index$1.h("div", { key: 'cd9793a4e353a88bfb04658354f247ddfd621e20', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, index$1.h("slot", { key: '3c79cf8327876b4be8e237e6d43c918d6f6dbda0', name: "empty" }), !hasEmptyStateSlotAssignment && (index$1.h("swirl-text", { key: '6f2d3365cd41f0242f8dc6720aed3c5bc1edf4fb', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
2861
+ : undefined, role: "table", class: "table__table" }, this.caption && (index$1.h("swirl-visually-hidden", { key: '013e2aff85772e44a3cdbb67dc4479d8eb581ffc' }, index$1.h("div", { key: '9f1b0dda1fe39b823e6df87dae2285e71a738265', id: "caption" }, this.caption))), index$1.h("div", { key: '9cd533c163bd42c8ebb4f641a91860170a2ca3e3', role: "rowgroup" }, index$1.h("div", { key: '0516399b0ed45a6f8e817fa9f342a188738fca0d', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, index$1.h("slot", { key: '9924e00f3ac41423e4cf183ad3f0c993f9235d83', name: "columns" }))), index$1.h("div", { key: '0be013c95ef6910e4a27b388282403843cd520ea', class: "table__body", ref: (el) => (this.bodyEl = el) }, index$1.h("slot", { key: 'f5660dcec786b0091ec3cbe38407948173146147', name: "rows" }), index$1.h("div", { key: 'db077c06ab60df00e149468bb54f52ebeb40cd66', class: "table__empty-row", role: "row" }, index$1.h("div", { key: 'd7b514fe706e96437496ee4f7f5b2b0052943629', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, index$1.h("slot", { key: '8b1c1f506c3a5479def5c178856900103a05e1d6', name: "empty" }), !hasEmptyStateSlotAssignment && (index$1.h("swirl-text", { key: 'f94bccc0907f8052c63cebdfb7b99c8708d1ab76', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
2854
2862
  }
2855
2863
  get el() { return index$1.getElement(this); }
2856
2864
  static get watchers() { return {
@@ -2,7 +2,7 @@ import debouncePromise from "debounce-promise";
2
2
  import { h, Host, } from "@stencil/core";
3
3
  import classNames from "classnames";
4
4
  import Sortable from "sortablejs";
5
- import { debounce, getScrollParent, isMobileViewport, querySelectorAllDeep, } from "../../utils";
5
+ import { getScrollParent, isMobileViewport, querySelectorAllDeep, } from "../../utils";
6
6
  import { SwirlTableVirtualizer, } from "./swirl-table-virtualizer";
7
7
  const defaultDragDropInstructions = {
8
8
  end: "Dropped. Final position in table: {position} of {rowCount}.",
@@ -29,10 +29,6 @@ export class SwirlTable {
29
29
  */
30
30
  this.virtualizationKeepRowsRendered = [];
31
31
  this.liveRegionText = "";
32
- this.triggerRerender = debounce(async () => {
33
- await this.updateLayout();
34
- this.updateEmptyState();
35
- }, 0, true);
36
32
  this.updateLayout = debouncePromise(async () => {
37
33
  this.resetCellStyles();
38
34
  this.resetColumnStyles();
@@ -212,7 +208,7 @@ export class SwirlTable {
212
208
  this.setupDragDrop();
213
209
  }
214
210
  if (rowWasAddedOrRemoved || rowIndexChanged) {
215
- this.syncVirtualizedRows();
211
+ this.syncVirtualizedRows({ layOutCells: rowWasAddedOrRemoved });
216
212
  }
217
213
  });
218
214
  this.startRowMutationObserver();
@@ -309,7 +305,10 @@ export class SwirlTable {
309
305
  * Force a re-render of the table
310
306
  */
311
307
  async rerender() {
312
- this.triggerRerender();
308
+ // updateLayout is debounced with a trailing call, so a row that loads
309
+ // while a layout runs still gets laid out.
310
+ await this.updateLayout();
311
+ this.updateEmptyState();
313
312
  }
314
313
  resetEmptyRowStyles() {
315
314
  const emptyRow = this.el.querySelector(".table__empty-row");
@@ -411,11 +410,14 @@ export class SwirlTable {
411
410
  layOutCellsAndColumns() {
412
411
  const columns = this.getColumns();
413
412
  const cells = this.getCells();
413
+ // Measure every column before sizing any cell. The table is as wide as its
414
+ // widest row, so sizing one column's cells moves the columns not measured
415
+ // yet.
416
+ const columnProperties = columns.map((column, colIndex) => this.calculateColumnProperties(column, columns, colIndex));
414
417
  columns.forEach((column, colIndex) => {
415
418
  const cellsOfColumn = this.getCellsForColumn(cells, columns, colIndex);
416
- const columnProperties = this.calculateColumnProperties(column, columns, colIndex);
417
- cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties));
418
- this.applyColumnStyles(column, columnProperties);
419
+ cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties[colIndex]));
420
+ this.applyColumnStyles(column, columnProperties[colIndex]);
419
421
  });
420
422
  }
421
423
  getCellsForColumn(cells, columns, colIndex) {
@@ -585,13 +587,19 @@ export class SwirlTable {
585
587
  * Measures and positions rows after they were added, removed or re-indexed.
586
588
  * The focused row's index is read again first, as it changes when e.g. a row
587
589
  * is inserted above it.
590
+ *
591
+ * Added rows and cells are laid out too: a row calls `rerender()` only when
592
+ * it first loads, so cells added to a drawn row would get no width.
588
593
  */
589
- syncVirtualizedRows() {
594
+ syncVirtualizedRows({ layOutCells }) {
590
595
  if (!this.virtualizer) {
591
596
  return;
592
597
  }
593
598
  this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within"));
594
599
  this.virtualizer.sync();
600
+ if (layOutCells) {
601
+ this.updateLayout();
602
+ }
595
603
  }
596
604
  /** Keeps the focused row drawn, so it doesn't lose focus. */
597
605
  trackFocusedRow(target) {
@@ -612,9 +620,9 @@ export class SwirlTable {
612
620
  "table--show-empty-state": this.empty && !this.loading,
613
621
  "table--keyboard-move": this.movingViaKeyboard,
614
622
  });
615
- return (h(Host, { key: '5fd51d538c87dce53702fa483657035e251d3507' }, h("div", { key: '7ec3b5830bcc7b0dfc5324f554b80b442b7bc290', class: className }, this.enableDragDrop && (h("swirl-visually-hidden", { key: '2928eb420bb8cad6477917a1883aeeffda3260eb' }, h("span", { key: 'fc615afed57d8dbfbf636f9e8feb9c6ef76ae72b', "aria-live": "assertive" }, this.liveRegionText))), h("div", { key: '4b7d5b9c4691d1828d0c24fc635d8e7c5dc48cf4', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, h("div", { key: '9669435927eb4944290b4fdcb4083ef1473c000e', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
623
+ return (h(Host, { key: '24e14d3eb739219aa9965fe16ccff5e9dae28180' }, h("div", { key: '25deaf84f1bb1131977e6e07f45ac2301585354d', class: className }, this.enableDragDrop && (h("swirl-visually-hidden", { key: '277292ebfaa8c1ada6c5c982b214efbda5f2f8a9' }, h("span", { key: 'e07ea9745ee40064160001ed0d702971cce78efa', "aria-live": "assertive" }, this.liveRegionText))), h("div", { key: 'f6919c9d48793c1abba7901b4365817ae7dfc5dc', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, h("div", { key: 'b7d1bb696755df6fd20983eebf6b800685a59983', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
616
624
  ? this.virtualizationRowCount + 1
617
- : undefined, role: "table", class: "table__table" }, this.caption && (h("swirl-visually-hidden", { key: '6806eedf8d1aa22b3ee8f51736032ead77a502cc' }, h("div", { key: 'bea8e3d31ba2e81461ff8e4d056ee3ea718707ea', id: "caption" }, this.caption))), h("div", { key: '386fa4a8c2d31471a43580b62ad1003cfbcf224d', role: "rowgroup" }, h("div", { key: 'aebae228fab2eb7d4a688bb50ee069e7138001c1', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, h("slot", { key: '111dd938896772934ba589167ee254936c8bbe9d', name: "columns" }))), h("div", { key: '7a6b87e277bd50dfc8c5ff3e680aabe95384bb7f', class: "table__body", ref: (el) => (this.bodyEl = el) }, h("slot", { key: 'a766d1ff38bf321fac0b3c52a686d57d2b4551ea', name: "rows" }), h("div", { key: 'a26bec40f580546c85e3dd1007c913d53da4c18a', class: "table__empty-row", role: "row" }, h("div", { key: 'cd9793a4e353a88bfb04658354f247ddfd621e20', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, h("slot", { key: '3c79cf8327876b4be8e237e6d43c918d6f6dbda0', name: "empty" }), !hasEmptyStateSlotAssignment && (h("swirl-text", { key: '6f2d3365cd41f0242f8dc6720aed3c5bc1edf4fb', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
625
+ : undefined, role: "table", class: "table__table" }, this.caption && (h("swirl-visually-hidden", { key: '013e2aff85772e44a3cdbb67dc4479d8eb581ffc' }, h("div", { key: '9f1b0dda1fe39b823e6df87dae2285e71a738265', id: "caption" }, this.caption))), h("div", { key: '9cd533c163bd42c8ebb4f641a91860170a2ca3e3', role: "rowgroup" }, h("div", { key: '0516399b0ed45a6f8e817fa9f342a188738fca0d', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, h("slot", { key: '9924e00f3ac41423e4cf183ad3f0c993f9235d83', name: "columns" }))), h("div", { key: '0be013c95ef6910e4a27b388282403843cd520ea', class: "table__body", ref: (el) => (this.bodyEl = el) }, h("slot", { key: 'f5660dcec786b0091ec3cbe38407948173146147', name: "rows" }), h("div", { key: 'db077c06ab60df00e149468bb54f52ebeb40cd66', class: "table__empty-row", role: "row" }, h("div", { key: 'd7b514fe706e96437496ee4f7f5b2b0052943629', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, h("slot", { key: '8b1c1f506c3a5479def5c178856900103a05e1d6', name: "empty" }), !hasEmptyStateSlotAssignment && (h("swirl-text", { key: 'f94bccc0907f8052c63cebdfb7b99c8708d1ab76', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
618
626
  }
619
627
  static get is() { return "swirl-table"; }
620
628
  static get encapsulation() { return "scoped"; }
@@ -1 +1 @@
1
- import{proxyCustomElement as t,HTMLElement as i,createEvent as s,h as e,Host as h,transformTag as n}from"@stencil/core/internal/client";import{g as l,c as r}from"./index2.js";import{S as o}from"./sortable.esm.js";import{d as a,o as u,i as c,q as d}from"./utils.js";import{d as f}from"./swirl-text2.js";import{d as b}from"./swirl-visually-hidden2.js";var v,w,p=l((w||(w=1,v=function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=void 0,h=void 0,n=void 0,l=[];return function(){var o=function(t){return"function"==typeof t?t():t}(i),a=(new Date).getTime(),u=!e||a-e>o;e=a;for(var c=arguments.length,d=Array(c),f=0;f<c;f++)d[f]=arguments[f];if(u&&s.leading)return s.accumulate?Promise.resolve(t.call(this,[d])).then((function(t){return t[0]})):Promise.resolve(t.call.apply(t,[this].concat(d)));if(h?clearTimeout(n):h=function(){var t={};return t.promise=new Promise((function(i,s){t.resolve=i,t.reject=s})),t}(),l.push(d),n=setTimeout(r.bind(this),o),s.accumulate){var b=l.length-1;return h.promise.then((function(t){return t[b]}))}return h.promise};function r(){var i=h;clearTimeout(n),Promise.resolve(s.accumulate?t.call(this,l):t.apply(this,l[l.length-1])).then(i.resolve,i.reject),l=[],h=null}}),v));function m(t,i,s){let e,h=s.initialDeps??[],n=!0;function l(){const l=t();return l.length!==h.length||l.some(((t,i)=>h[i]!==t))?(h=l,e=i(...l),!(null==s?void 0:s.onChange)||n&&s.skipInitialOnChange||s.onChange(e),n=!1,e):e}return l.updateDeps=t=>{h=t},l}function g(t){if(void 0===t)throw Error("Unexpected undefined");return t}const y=(t,i)=>Math.abs(t-i)<1.01,x=(t,i,s)=>{let e;return Object.assign((function(...h){t.clearTimeout(e),e=t.setTimeout((()=>i.apply(this,h)),s)}),{cancel:()=>{t.clearTimeout(e)}})};let M;const k=()=>{if(void 0!==M)return M;if("undefined"==typeof navigator)return M=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return M=!0;const t=navigator.maxTouchPoints;return M="MacIntel"===navigator.platform&&void 0!==t&&t>0};let S;const _={capture:!0,passive:!0};class C{constructor(t){this.host=t,this._touch=null,this.inMotion=()=>null!==this._touch&&"lateFling"!==this._touch.phase,this.dragging=()=>{var t;return"down"===(null==(t=this._touch)?void 0:t.phase)&&this._touch.moved},this.tail=()=>{var t;return"tail"===(null==(t=this._touch)?void 0:t.phase)?this._touch.moved?"fling":"tap":null},this.onScroll=({isScrolling:t,ownReadBack:i,moved:s,external:e})=>{var h,n,l;return t&&"tail"===(null==(h=this._touch)?void 0:h.phase)?this._openTail(this._touch.moved||!i,!1):"lateFling"===(null==(n=this._touch)?void 0:n.phase)&&(this.host.now()>this._touch.until?this._touch=null:e&&t&&s&&this._openTail(!0,!1)),!(i||!t||!s||"down"!==(null==(l=this._touch)?void 0:l.phase)||(this._touch.moved=!0,0))},this.touchStart=()=>{this.end(),this._touch={phase:"down",moved:!1}},this.touchEnd=()=>{var t;const i="down"===(null==(t=this._touch)?void 0:t.phase)&&this._touch.moved;this.end(),this._openTail(i,i)},this.end=()=>{var t;const i=this.host.getWindow();"tail"===(null==(t=this._touch)?void 0:t.phase)&&null!=i&&i.clearTimeout(this._touch.timerId),this._touch=null},this.listen=t=>{const i=()=>this.touchStart(),s=()=>this.touchEnd();return t.addEventListener("touchstart",i,_),t.addEventListener("touchend",s,_),t.addEventListener("touchcancel",s,_),()=>{t.removeEventListener("touchstart",i,_),t.removeEventListener("touchend",s,_),t.removeEventListener("touchcancel",s,_),this.end()}},this._openTail=(t,i)=>{const s=this.host.getWindow();if(null==s)return;this.end();const e={phase:"tail",moved:t,awaitingFling:i,timerId:s.setTimeout((()=>{this.host.tailStillMoving()?this._openTail(e.moved,e.awaitingFling):(this._touch=e.awaitingFling?{phase:"lateFling",until:this.host.now()+1e3}:null,this.host.onTailClosed())}),150)};this._touch=e}}get touch(){return this._touch}}const R=t=>{const{clientWidth:i,clientHeight:s}=t;return{width:i,height:s}},z=t=>{const i=new Set;return{schedule:s=>{const e=t.requestAnimationFrame((()=>{i.delete(e),s()}));i.add(e)},cancel:()=>{i.forEach((i=>t.cancelAnimationFrame(i))),i.clear()}}},A=t=>t,I=t=>{const i=t.overscan*Math.max(t.lanes??1,1),s=Math.max(t.startIndex-i,0),e=Math.min(t.endIndex+i,t.count-1)-s+1,h=Array(e);for(let t=0;t<e;t++)h[t]=s+t;return h},O=(t,i)=>{const s=t.scrollElement;if(!s)return;const e=t.targetWindow;if(!e)return;const h=t=>{const{width:s,height:e}=t;i({width:Math.round(s),height:Math.round(e)})};if(h(R(s)),!e.ResizeObserver)return()=>{};const n=z(e),l=new e.ResizeObserver((()=>{const i=()=>{h(R(s))};t.options.useAnimationFrameWithResizeObserver?n.schedule(i):i()}));return l.observe(s,{box:"content-box"}),()=>{l.unobserve(s),n.cancel()}},E={passive:!0},D=(t,i)=>{const s=t.scrollElement;if(!s)return;const e=()=>{i({width:s.innerWidth,height:s.innerHeight})};return e(),s.addEventListener("resize",e,E),()=>{s.removeEventListener("resize",e)}},F="undefined"==typeof window||"onscrollend"in window,T=(t,i,s)=>{const e=t.scrollElement;if(!e)return;const h=t.targetWindow;if(!h)return;const n=t.options.useScrollendEvent&&F;let l=0;const r=n?null:x(h,(()=>i(s(e),!1)),t.options.isScrollingResetDelay),o=t=>()=>{l=s(e),null==r||r(),i(l,t)},a=o(!0),u=o(!1);return e.addEventListener("scroll",a,E),n&&e.addEventListener("scrollend",u,E),()=>{e.removeEventListener("scroll",a),n&&e.removeEventListener("scrollend",u),null==r||r.cancel()}},W=(t,i)=>T(t,i,(i=>{const{horizontal:s,isRtl:e}=t.options;return s?i.scrollLeft*(e?-1:1):i.scrollTop})),V=(t,i)=>T(t,i,(i=>t.options.horizontal?i.scrollX:i.scrollY)),L=(t,i,s)=>{if(s.options.useCachedMeasurements){const i=s.indexFromElement(t),e=s.options.getItemKey(i);return s.itemSizeCache.get(e)??s.options.estimateSize(i)}if(null==i?void 0:i.borderBoxSize){const t=i.borderBoxSize[0];if(t)return Math.round(t[s.options.horizontal?"inlineSize":"blockSize"])}if(!i){const i=s.indexFromElement(t),e=s.options.getItemKey(i),h=s.itemSizeCache.get(e);if(void 0!==h)return h}return t[s.options.horizontal?"offsetWidth":"offsetHeight"]},j=(t,{adjustments:i=0,behavior:s},e)=>{var h,n;null==(n=null==(h=e.scrollElement)?void 0:h.scrollTo)||n.call(h,{[e.options.horizontal?"left":"top"]:t+i,behavior:s})},q=j,B=j,P=(t,i)=>"smooth"===t?i?"smoothLanded":"smooth":"instant",K=t=>"smooth"===(null==t?void 0:t.phase)||"smoothLanded"===(null==t?void 0:t.phase);class H{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._iosGesture=new C({getWindow:()=>this.targetWindow,now:()=>this.now(),tailStillMoving:()=>{const t=this.scrollState;if("queued"!==(null==t?void 0:t.phase)||null!==this.pendingWrite)return!1;const i=this._readElementOffset();return!(null===i||null===this._lastElementOffset||Math.abs(i-this._lastElementOffset)<1||(this._lastElementOffset=i,t.samples=[...t.samples??[],{t:this.now(),offset:i}],0))},onTailClosed:()=>{const t=this.scrollState;"queued"===(null==t?void 0:t.phase)&&function(t){const i=t[t.length-1];if(void 0===i)return!1;let s=t.length-2;for(;s>=0&&i.t-t[s].t<40;)s--;if(s<0)return!1;const e=t[s];return Math.abs(i.offset-e.offset)/(i.t-e.t)>=.05}(t.samples??[])&&(this.scrollState=null),this._flushHoldIfReady(!0),this._writeAwaitingCommand(),this._retryClampedAdjustment()}}),this._lastElementOffset=null,this.pendingWrite=null,this._clampedAdjustment=null,this.elementsCache=new Map,this._resizeBatch=null,this.now=()=>{var t,i,s;return(null==(s=null==(i=null==(t=this.targetWindow)?void 0:t.performance)?void 0:i.now)?void 0:s.call(i))??Date.now()},this.observer=(()=>{let t=null,i=null,s=!1,e=!1;const h=new Set,n=()=>{if(t)return t;const e=this.targetWindow;if(!e||!e.ResizeObserver)return null;const h=i=z(e);return t=new e.ResizeObserver((t=>{const i=()=>{const i={sync:!1};this._resizeBatch=i;try{t.forEach(l)}finally{this._resizeBatch=null,i.notify&&(this.notify(i.sync),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment(),this.measureElement(null))}};if(this.options.useAnimationFrameWithResizeObserver)h.schedule(i);else{s=!0;try{i()}finally{s=!1}}}))},l=t=>{const i=t.target,s=this.indexFromElement(i);if(i.isConnected)this.isIndexInRange(s)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(i,t,this));else{this.observer.unobserve(i);for(const[t,s]of this.elementsCache)if(s===i){this.elementsCache.delete(t);break}}};return{disconnect:()=>{var s;null==(s=n())||s.disconnect(),null==i||i.cancel(),h.clear(),e=!1,t=null,i=null},observe:l=>{const r=n();r&&(s?(h.add(l),e||(e=!0,null==i||i.schedule((()=>{e=!1,h.forEach((i=>{i.isConnected&&(null==t||t.observe(i,{box:"border-box"}))})),h.clear()})))):r.observe(l,{box:"border-box"}))},unobserve:t=>{var i;h.delete(t),null==(i=n())||i.unobserve(t)}}})(),this.range=null,this.setOptions=t=>{var i;const s={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:A,rangeExtractor:I,onChange:()=>{},measureElement:L,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const i in t){const e=t[i];void 0!==e&&(s[i]=e)}const e=this.options;let h=null,n=null,l=!1;if(void 0!==e&&e.enabled&&s.enabled&&"end"===s.anchorTo&&null!==this.scrollElement){const t=e.count,r=s.count,o=this.getMeasurements(),a=(null==(i=this._singleLaneMeasurements)?void 0:i.items)??o,u=t=>function(t){return"object"==typeof t?t.key:t}(a[t]),c=t>0?u(0):null,d=t>0?u(t-1):null;if(r!==t||t>0&&r>0&&(s.getItemKey(0)!==c||s.getItemKey(r-1)!==d)){l=!0;const i=t>0?this.getVirtualItemForOffset(this.getScrollOffset())??o[0]:null;i&&(h=[i.key,this.getScrollOffset()-i.start]);const a=!0===s.followOnAppend?"auto":s.followOnAppend||null;a&&r>0&&this.isAtEnd(e.scrollEndThreshold)&&(0===t||s.getItemKey(r-1)!==d)&&(r>t||function(t,i,s,e){if(0===i)return!1;const h=e(0),n=new Set;let l=0;for(;l<t;){const t=s(l);if(t===h)break;n.add(t),l++}const r=t-l;if(0===r||r>=i)return!1;for(let t=0;t<r;t++)if(e(t)!==s(l+t))return!1;for(let t=r;t<i;t++)if(n.has(e(t)))return!1;return!0}(t,r,u,s.getItemKey))&&(n=a)}}this.options=s,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let r=null;if(h&&null!==this.scrollOffset&&!this._awaitingCommandReadBack()){const[t,i]=h,s=this.getMeasurements(),{count:e,getItemKey:l}=this.options;let o=0;for(;o<e&&l(o)!==t;)o++;if(o<e){const t=s[o];if(t){const s=Math.max(0,t.start+i);n||s===this.scrollOffset||(r=s-this.scrollOffset,this.scrollOffset=s)}}}n?this.pendingScrollAnchor={kind:"follow",behavior:n}:null!==r&&(this._canWriteScroll()?this.pendingScrollAnchor={kind:"anchor",delta:r}:(this._holdOffset+=r,this._followOffsetTarget(r)))},this.notify=t=>{var i,s;null==(s=(i=this.options).onChange)||s.call(i,this,t)},this.maybeNotify=m((()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null])),(t=>{this.notify(t)}),{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{var t;this.unsubs.filter(Boolean).forEach((t=>t())),this.unsubs=[],this.observer.disconnect(),null!=this.rafId&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,null==(t=this._momentumStop)||t.restore(),this._momentumStop=null,this.isScrolling=!1,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._clampedAdjustment=null,this.pendingWrite=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const i=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==i){if(this.cleanup(),!i)return void this.maybeNotify();this.scrollElement=i,this.targetWindow=this.scrollElement&&"ownerDocument"in this.scrollElement?this.scrollElement.ownerDocument.defaultView:(null==(t=this.scrollElement)?void 0:t.window)??null,this.elementsCache.forEach((t=>{this.observer.observe(t)})),this.unsubs.push(this.options.observeElementRect(this,(t=>{this.scrollRect=t,this.maybeNotify()}))),this.unsubs.push(this.options.observeElementOffset(this,((t,i)=>{var s,e,h,n;const l=i?this._elementMaxScrollOffset():null,r=this._reportedOverscroll;this._reportedOverscroll=t<0||null!==l&&t>l+1;const o=t;this._lastElementOffset=o,t=this._toLayoutOffset(t);const a=this._classifyScrollEvent(t,i,l);if("spurious"===a)return;"readBack"===a?t=this.pendingWrite.target:"clampedReadBack"===a&&null!=(null==(s=this.scrollState)?void 0:s.index)&&t<this.getMaxScrollOffset()-1.5?this.scrollState.lastTargetOffset=t:function({kind:t,offset:i,command:s,target:e}){return"spurious"!==t&&"readBack"!==t&&"clampedReadBack"!==t&&null!=(null==s?void 0:s.index)&&"queued"!==s.phase&&!(t=>"smooth"===t||"smoothFinishing"===t)(s.phase)&&!y(i,s.lastTargetOffset)&&!y(i,e())&&"clampedEcho"!==t}({kind:a,offset:t,command:this.scrollState,target:()=>this.getScrollStateTarget(this.scrollState)})&&(this.scrollState=null),this.pendingWrite=null,null!==this._clampedAdjustment&&Math.abs(t-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null);const u=this.getScrollOffset(),c=this.scrollDirection;this.scrollDirection=i?u===t?this.scrollDirection:u<t?"forward":"backward":null,this.scrollOffset=t,this.isScrolling=i;const d=this.scrollState;if("queued"===(null==d?void 0:d.phase)&&"external"===a&&i)if(r||this._reportedOverscroll)d.samples=[];else{const t=this.now();d.samples=[...(d.samples??[]).filter((i=>t-i.t<=200)),{t,offset:o}],(null!==c&&this.scrollDirection!==c||function(t){const i=t[t.length-1];if(void 0===i)return!1;let s=t.length-2;for(;s>=0&&i.t-t[s].t<40;)s--;if(s<0)return!1;const e=t[s];let h=s-1;for(;h>=0&&e.t-t[h].t<40;)h--;if(h<0)return!1;const n=t[h],l=(i.offset-e.offset)/(i.t-e.t),r=(e.offset-n.offset)/(e.t-n.t);return l*r>=0&&Math.abs(l)>=2*Math.abs(r)&&Math.abs(l)-Math.abs(r)>=.8}(d.samples))&&(this.scrollState=null)}this._iosGesture.onScroll({isScrolling:i,ownReadBack:"readBack"===a,moved:t!==u,external:"external"===a&&"smooth"!==(null==(e=this.scrollState)?void 0:e.phase)&&"smoothFinishing"!==(null==(h=this.scrollState)?void 0:h.phase)})&&"queued"===(null==(n=this.scrollState)?void 0:n.phase)&&(this.scrollState=null),this._flushHoldIfReady(!0),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()}))),"addEventListener"in this.scrollElement&&this.unsubs.push(this._iosGesture.listen(this.scrollElement)),this._scrollToOffset(this.getScrollOffset())}this._noteClampMax();const s=this.pendingScrollAnchor;this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled&&("anchor"===s.kind?this._canWriteScroll()?K(this.scrollState)&&!y(this.getScrollOffset()-s.delta,this.scrollState.lastTargetOffset)||(this._followOffsetTarget(s.delta),this._scrollToOffset(this.getScrollOffset())):(this._holdOffset+=s.delta,this._followOffsetTarget(s.delta),this.notify(!1)):this.scrollToEnd({behavior:s.behavior})),this._flushHoldIfReady(!1),this._retryClampedAdjustment()},this._classifyScrollEvent=(t,i,s)=>{var e;return function({offset:t,isScrolling:i,elementMax:s,holdOffset:e,scrollOffset:h,pendingWrite:n,clampedMaxAtWrite:l}){var r;return i&&null===n&&t===h?"spurious":null!==n&&Math.abs(t-n.target)<1.5?"readBack":null!==n&&!n.smooth&&null!==s&&n.target>s+e+.5&&Math.abs(t-(s+e))<1.5||null!==n&&!n.smooth&&(null==(r=n.lowMaxes)?void 0:r.some((i=>Math.abs(t-i)<1.5)))?"clampedReadBack":null!==l&&Math.abs(t-l)<1.5?"clampedEcho":"external"}({offset:t,isScrolling:i,elementMax:s,holdOffset:this._holdOffset,scrollOffset:this.scrollOffset,pendingWrite:this.pendingWrite,clampedMaxAtWrite:(null==(e=this._clampedAdjustment)?void 0:e.maxAtWrite)??null})},this._retryClampedAdjustment=()=>{if(null===this._clampedAdjustment||!this.scrollElement||!this.options.enabled||!this._canWriteScroll())return;const{target:t,maxAtWrite:i}=this._clampedAdjustment,s=this.getMaxScrollOffset();s>i+.5&&(this._clampedAdjustment=t>s+.5?{target:t,maxAtWrite:s}:null,this._scrollToOffset(t))},this._writeAwaitingCommand=()=>{const t=this.scrollState;if(null===t||"queued"!==t.phase)return;const{behavior:i}=t;this.getMeasurements();const s=this.getScrollStateTarget(t);t.lastTargetOffset=s,this._clampedAdjustment=null,t.phase=P(i,null!=t.index&&y(s,this.getScrollOffset())),this._scrollToOffset(s,{behavior:i}),this.scheduleScrollReconcile()},this._readElementOffset=()=>{const t=this.scrollElement;if(null==t)return null;const{horizontal:i,isRtl:s}=this.options;return"number"==typeof t.scrollTop?i?t.scrollLeft*(s?-1:1):t.scrollTop:"number"==typeof t.scrollY?i?t.scrollX:t.scrollY:null},this._canWriteScroll=()=>!(k()&&this._iosGesture.inMotion()||this._reportedOverscroll),this._flushHoldIfReady=t=>{var i;if(0===this._holdOffset)return;if(!this.scrollElement||!this.options.enabled)return;if(!this._canWriteScroll())return;if("smooth"===(null==(i=this.scrollState)?void 0:i.phase))return;this._holdOffset=0,null!==this.scrollOffset&&this.scrollOffset<0&&(this.scrollOffset=0),this.notify(t);const s=this.getCommandWrittenOffset()??this.getScrollOffset();this._clampedAdjustment=this._clampedBy(s),this._scrollToOffset(s)},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??("function"==typeof this.options.initialOffset?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=m((()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap]),((t,i,s,e,h,n,l,r)=>(void 0!==this.prevLanes&&this.prevLanes!==n&&(this.lanesChangedFlag=!0),this.prevLanes=n,this.pendingMin=null,{count:t,paddingStart:i,scrollMargin:s,getItemKey:e,enabled:h,lanes:n,laneAssignmentMode:l,gap:r})),{key:!1}),this.isIndexInRange=t=>t>=0&&t<this.options.count,this.getMeasurements=m((()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion]),(({count:t,paddingStart:i,scrollMargin:s,getItemKey:e,enabled:h,lanes:n,laneAssignmentMode:l,gap:r})=>{var o;const a=this.itemSizeCache;if(!h)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const i of this.laneAssignments.keys())i>=t&&this.laneAssignments.delete(i);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),0!==this.measurementsCache.length||this.lanesSettling||(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach((t=>{this.itemSizeCache.set(t.key,t.size)})));const u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),1===n){const h=2*t;let n=null==(o=this._singleLaneMeasurements)?void 0:o.flat;if(!n||n.length<h){const t=new Float64Array(h);n&&u>0&&t.set(n.subarray(0,2*u)),n=t}const l=0===u?Array(t):this._singleLaneMeasurements.items.slice();let c;if(0===u)c=i+s;else{const t=u-1;c=n[2*t]+n[2*t+1]+r}for(let i=u;i<t;i++){const t=e(i);l[i]=t;const s=a.get(t),h="number"==typeof s?s:this.options.estimateSize(i);n[2*i]=c,n[2*i+1]=h,c+=h+r}this._singleLaneMeasurements={flat:n,items:l};const d=function(t,i){const s=t.length;return new Proxy(t,{get(t,e,h){if("string"==typeof e){const h=e.charCodeAt(0);if(h>=48&&h<=57){const h=+e;if(Number.isInteger(h)&&h>=0&&h<s){let s=t[h];if("object"!=typeof s){const e=i[2*h];s=t[h]={index:h,key:s,start:e,size:i[2*h+1],end:e+i[2*h+1],lane:0}}return s}}if("length"===e)return s}return Reflect.get(t,e,h)}})}(l,n);return this.measurementsCache=d,d}const c=this.measurementsCache.slice(0,u),d=Array(n).fill(void 0),f=new Float64Array(n);let b=0;for(let t=0;t<u;t++){const i=c[t];i&&(void 0===d[i.lane]&&b++,d[i.lane]=t,f[i.lane]=i.end)}for(let h=u;h<t;h++){const t=e(h),o=this.laneAssignments.get(h);let u,v;const w="estimate"===l||a.has(t);if(void 0!==o&&this.options.lanes>1){u=o;const t=d[u],e=void 0!==t?c[t]:void 0;v=e?e.end+r:i+s}else if(b===n){let t=0,i=f[0],s=d[0];for(let e=1;e<n;e++){const h=f[e];(h<i||h===i&&d[e]<s)&&(t=e,i=h,s=d[e])}u=t,v=i+r,w&&this.laneAssignments.set(h,u)}else u=h%this.options.lanes,v=i+s,w&&this.laneAssignments.set(h,u);const p=a.get(t),m="number"==typeof p?p:this.options.estimateSize(h),g=v+m;c[h]={index:h,start:v,size:m,end:g,key:t,lane:u},void 0===d[u]&&b++,d[u]=h,f[u]=g}return this.measurementsCache=c,c}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=m((()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes,this._getLayoutTotalSize()+this.options.scrollMargin]),((t,i,s,e,h)=>0===t.length||0===i?(this.range=null,null):(this.range=function(t,i,s,e,h){const n=t.length-1;if(t.length<=e)return{startIndex:0,endIndex:n};if(1===e&&null!==h){const t=function(t,i,s){let e=0;for(;e<=i;){const h=(e+i)/2|0,n=t[2*h];if(n<s)e=h+1;else{if(!(n>s))return h;i=h-1}}return e>0?e-1:0}(h,n,s);let e=t;const l=s+i;for(;e<n&&h[2*e]+h[2*e+1]<l;)e++;return{startIndex:t,endIndex:e}}let l=N(0,n,(i=>t[i].start),s),r=l;if(1===e)for(;r<n&&t[r].end<s+i;)r++;else if(e>1){const h=Array(e).fill(0);for(;r<n&&h.some((t=>t<s+i));){const i=t[r];h[i.lane]=i.end,r++}const o=Array(e).fill(s+i);for(;l>=0&&o.some((t=>t>=s));){const i=t[l];o[i.lane]=i.start,l--}l=Math.max(0,l-l%e),r=Math.min(n,r+(e-1-r%e))}return{startIndex:l,endIndex:r}}(t,i,Math.min(s,Math.max(h-i,0)),e,1===e&&null!==this._singleLaneMeasurements?this._singleLaneMeasurements.flat:null),this.range)),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=m((()=>{let t=null,i=null;const s=this.calculateRange();return s&&(t=s.startIndex,i=s.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,i]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,i,this.options.lanes]}),((t,i,s,e,h,n)=>null===e||null===h?[]:t({startIndex:e,endIndex:h,overscan:i,count:s,lanes:n})),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const i=this.options.indexAttribute,s=t.getAttribute(i);return s?parseInt(s,10):(console.warn(`Missing attribute name '${i}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var i;if(!K(this.scrollState))return!0;const s=this.scrollState.index??(null==(i=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))?void 0:i.index);if(void 0!==s&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2));return t>=Math.max(0,s-i)&&t<=Math.min(this.options.count-1,s+i)}return!0},this.measureElement=t=>{if(!t)return void this.elementsCache.forEach(((t,i)=>{t.isConnected||(this.observer.unobserve(t),this.elementsCache.delete(i))}));const i=this.indexFromElement(t);if(!this.isIndexInRange(i))return;const s=this.options.getItemKey(i),e=this.elementsCache.get(s);e!==t&&(e&&this.observer.unobserve(e),this.observer.observe(t),this.elementsCache.set(s,t)),t.isConnected&&(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(i)&&this.resizeItem(i,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,i)=>{var s,e,h;if(!this.isIndexInRange(t))return;let n,l,r;(null==(s=this._resizeBatch)?void 0:s.sync)&&this.getMeasurements();const o=null==(e=this._singleLaneMeasurements)?void 0:e.flat;if(1===this.options.lanes&&null!=o)r=this.options.getItemKey(t),l=o[2*t],n=o[2*t+1];else{const i=this.measurementsCache[t];if(!i)return;r=i.key,l=i.start,n=i.size}const a=this.itemSizeCache.get(r)??n,u=i-a;if(0!==u){const s="end"===this.options.anchorTo&&!K(this.scrollState)&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,e=s?this._getLayoutTotalSize():0,o=this.getScrollOffset(),c=this.itemSizeCache.has(r)?l+a<=o&&"backward"!==this.scrollDirection:l<o,d=!K(this.scrollState)&&(void 0!==this.shouldAdjustScrollPositionOnItemSizeChange?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:r,start:l,size:n,end:l+n,lane:0},u,this):c);(null===this.pendingMin||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(r,i),this.itemSizeCacheVersion++;let f=!1;if(this._awaitingCommandReadBack()||(s?f=this.applyScrollAdjustment(this._getLayoutTotalSize()-e):d&&(f=this.applyScrollAdjustment(u))),this._resizeBatch)return this._resizeBatch.notify=!0,void((h=this._resizeBatch).sync||(h.sync=f));this.notify(f),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment()}},this.getVirtualItems=m((()=>[this.getVirtualIndexes(),this.getMeasurements(),this._holdOffset]),((t,i,s)=>{const e=[];for(let h=0,n=t.length;h<n;h++){const n=i[t[h]];e.push(0===s?n:{...n,start:n.start-s,end:n.end-s})}return e}),{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{var i;const s=this.getMeasurements();if(0===s.length)return;const e=null==(i=this._singleLaneMeasurements)?void 0:i.flat,h=N(0,s.length-1,1===this.options.lanes&&null!=e?t=>e[2*t]:t=>g(s[t]).start,t);return g(s[h])},this._noteClampMax=()=>{if(!this._awaitingCommandReadBack())return;const t=this._elementMaxScrollOffset();if(null===t)return;const i=this.pendingWrite,s=Math.max(t,0)+this._holdOffset;if(s>=i.target)return;const e=i.lowMaxes??(i.lowMaxes=[]);e[e.length-1]!==s&&e.push(s)},this.getMaxScrollOffset=()=>(this._elementMaxScrollOffset()??0)+this._holdOffset,this._toLayoutOffset=t=>{var i;let s=t+this._holdOffset;return"anchor"===(null==(i=this.pendingScrollAnchor)?void 0:i.kind)&&(s+=this.pendingScrollAnchor.delta),s},this._elementMaxScrollOffset=()=>{const t=this.scrollElement;if(null===t)return null;if("scrollHeight"in t)return this.options.horizontal?t.scrollWidth-t.clientWidth:t.scrollHeight-t.clientHeight;if("document"in t){const i=t.document.documentElement;return this.options.horizontal?i.scrollWidth-t.innerWidth:i.scrollHeight-t.innerHeight}return null},this._momentumStop=null,this._stopMomentum=t=>{const i=this.scrollElement,s=this.targetWindow;if(null===i||null===s)return;const e="document"in i?i.document.scrollingElement:i;if(!(null==e?void 0:e.style))return;if(this._momentumStop)return void(this._momentumStop.done=t);const{style:h}=e,n=this.options.horizontal?"overflow-x":"overflow-y",l=h.getPropertyValue(n),r=h.getPropertyPriority(n),o=()=>this.options.horizontal?e.clientHeight:e.clientWidth,a=o();if(h.setProperty(n,"hidden","important"),o()!==a)return void h.setProperty(n,l,r);const u={restore:()=>"hidden"===h.getPropertyValue(n)&&"important"===h.getPropertyPriority(n)&&(h.setProperty(n,l,r),!0),done:t};this._momentumStop=u,s.requestAnimationFrame((()=>s.requestAnimationFrame((()=>{this._momentumStop===u&&(this._momentumStop=null,u.restore()&&u.done())}))))},this._clampedBy=t=>{const i=this._elementMaxScrollOffset();if(null===i)return null;const s=i+this._holdOffset;return t>s+.5?{target:t,maxAtWrite:s}:null},this.getVirtualDistanceFromEnd=()=>Math.max(this._getLayoutTotalSize()+this.options.scrollMargin-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,i,s=0)=>{if(!this.scrollElement)return 0;const e=this.getSize(),h=this.getScrollOffset();"auto"===i&&(i=t>=h+e?"end":"start"),"center"===i?t+=(s-e)/2:"end"===i&&(t-=e);const n=this.getMaxScrollOffset();return Math.max(Math.min(n,t),0)},this.getOffsetForIndex=(t,i="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const s=this.getSize(),e=this.getScrollOffset(),h=this.measurementsCache[t];if(h){if("auto"===i)if(h.end>=e+s-this.options.scrollPaddingEnd)i="end";else{if(!(h.start<=e+this.options.scrollPaddingStart))return[e,i];i="start"}if("end"===i&&t===this.options.count-1){const t=this.getMaxScrollOffset();return[Math.max(Math.min(t-this.options.paddingEnd+this.options.scrollPaddingEnd,t),0),i]}return[this.getOffsetForAlignment("end"===i?h.end+this.options.scrollPaddingEnd:h.start-this.options.scrollPaddingStart,i,h.size),i]}},this.scrollToOffset=(t,{align:i="start",behavior:s="auto"}={})=>{this._startScroll({index:null,align:i},this.getOffsetForAlignment(t,i),s,"absolute")},this.scrollToIndex=(t,{align:i="auto",behavior:s="auto"}={})=>{const e=this.getOffsetForIndex(t=Math.max(0,Math.min(t,this.options.count-1)),i);if(!e)return;const[h,n]=e;this._startScroll({index:t,align:n},h,s,"absolute")},this.scrollBy=(t,{behavior:i="auto"}={})=>{const s=this.getOffsetForAlignment((this.getCommandWrittenOffset()??this.getScrollOffset())+t,"start");this._startScroll({index:null,align:"start"},s,i,"relative")},this.scrollToEnd=({behavior:t="auto"}={})=>{this.options.count>0?this._startScroll({index:this.options.count-1,align:"end",toEnd:!0},Math.max(this.getMaxScrollOffset(),0),t,"absolute"):this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.cancelScroll=()=>{null!=this.rafId&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null},this.getTotalSize=()=>Math.max(this._getLayoutTotalSize()-this._holdOffset,0),this._getLayoutTotalSize=()=>{var t,i;const s=this.getMeasurements();let e;if(0===s.length)e=this.options.paddingStart;else if(1===this.options.lanes){const h=s.length-1,n=null==(t=this._singleLaneMeasurements)?void 0:t.flat;e=null!=n?n[2*h]+n[2*h+1]:(null==(i=s[h])?void 0:i.end)??0}else{const t=Array(this.options.lanes).fill(null);let i=s.length-1;for(;i>=0&&t.some((t=>null===t));){const e=s[i];null===t[e.lane]&&(t[e.lane]=e.end),i--}e=Math.max(...t.filter((t=>null!==t)))}return Math.max(e-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const t=[];if(0===this.itemSizeCache.size)return t;const i=this.getMeasurements();for(const s of i)s&&this.itemSizeCache.has(s.key)&&t.push({index:s.index,key:s.key,start:s.start,size:s.size,end:s.end,lane:s.lane});return t},this._scrollToOffset=(t,{adjustments:i,behavior:s}={})=>{const e={target:t+(i??0),smooth:"smooth"===s};return this.pendingWrite=e,this.options.scrollToFn(t-this._holdOffset,{behavior:s,adjustments:i},this),e},this.getCommandWrittenOffset=()=>null===this.scrollState||null===this.pendingWrite||this.pendingWrite.smooth?null:this.pendingWrite.target,this._awaitingCommandReadBack=()=>{const t=this.getCommandWrittenOffset();return!(k()&&this._iosGesture.dragging()||null===t||y(t,this.getScrollOffset()))},this._followOffsetTarget=t=>{null!==this.scrollState&&null==this.scrollState.index&&(this.scrollState.lastTargetOffset+=t)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}get scrollAdjustments(){return 0}applyScrollAdjustment(t,i){if(0===t)return!1;if(this._followOffsetTarget(t),this._canWriteScroll()){const s=this.getScrollOffset();this._clampedAdjustment=this._clampedBy(s+t);const e=this._scrollToOffset(s,{adjustments:t,behavior:i});return null!==this.scrollOffset&&(this.pendingWrite===e&&(this.scrollOffset+=t),this.scrollOffset<0&&(this.scrollOffset=0)),!0}return this._holdOffset+=t,null!==this.scrollOffset&&(this.scrollOffset+=t),!0}scheduleScrollReconcile(){this.targetWindow?null==this.rafId&&(this.rafId=this.targetWindow.requestAnimationFrame((()=>{this.rafId=null,this.reconcileScroll()}))):this.scrollState=null}getScrollStateTarget(t){const i=t.toEnd?[Math.max(this.getMaxScrollOffset(),0)]:null!=t.index?this.getOffsetForIndex(t.index,t.align):void 0;return i?i[0]:t.lastTargetOffset}reconcileScroll(){if(!this.scrollState)return;if(!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3)return void(this.scrollState=null);if("queued"===this.scrollState.phase)return void this.scheduleScrollReconcile();this.getMeasurements();const t=this.getScrollStateTarget(this.scrollState),i=null==this.scrollState.index?1:this.options.useAnimationFrameWithResizeObserver?3:2,s=t!==this.scrollState.lastTargetOffset;if(!s&&y(t,this.getScrollOffset())){if("smooth"===this.scrollState.phase?this.scrollState.phase="smoothLanded":"smoothFinishing"===this.scrollState.phase&&(this.scrollState.phase="instant"),this.scrollState.stableFrames++,this.scrollState.stableFrames>=i)return this.getScrollOffset()!==t&&this._scrollToOffset(t,{behavior:"auto"}),void(this.scrollState=null)}else if(this.scrollState.stableFrames=0,s){const i=this.getSize()||600,s=Math.abs(t-this.getScrollOffset()),e=K(this.scrollState)&&s>i;this.scrollState.lastTargetOffset=t,e?this.scrollState.phase="smooth":"smooth"===this.scrollState.phase?this.scrollState.phase="smoothFinishing":"smoothLanded"===this.scrollState.phase&&(this.scrollState.phase="instant"),this._scrollToOffset(t,{behavior:e?"smooth":"auto"})}this.scheduleScrollReconcile()}_startScroll(t,i,s,e){this.pendingScrollAnchor=null,this._clampedAdjustment=null;const h=this._iosGesture.tail();if("absolute"===e&&null!==h){if("fling"===h&&(!k()||(void 0!==S?S:S=k()&&"undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("overflow-anchor: auto"))))return this._stopMomentum((()=>{const t=this.scrollState;"queued"!==(null==t?void 0:t.phase)||"fling"!==this._iosGesture.tail()||this._reportedOverscroll||(this._iosGesture.end(),this._flushHoldIfReady(!0),this._writeAwaitingCommand())})),this.scrollState={...t,startedAt:this.now(),lastTargetOffset:i,stableFrames:0,phase:"queued",behavior:s,samples:[]},void this.scheduleScrollReconcile();this._iosGesture.end()}this.scrollState={...t,startedAt:this.now(),lastTargetOffset:i,stableFrames:0,behavior:s,phase:P(s,null!=t.index&&y(i,this.getScrollOffset()))},this._scrollToOffset(i,{behavior:s}),this.scheduleScrollReconcile()}}const N=(t,i,s,e)=>{for(;t<=i;){const h=(t+i)/2|0,n=s(h);if(n<e)t=h+1;else{if(!(n>e))return h;i=h-1}}return t>0?t-1:0};class U{constructor(t,i,s,e){this.bodyEl=t,this.scrollElement=i,this.config=s,this.onIndexesChange=e,this.measuredIndexes=new WeakMap,this.observedRows=new Set,this.resizeObserver=new ResizeObserver((t=>this.resizeRows(t.map((({borderBoxSize:t,target:i})=>({row:i,height:t[0].blockSize})))))),this.indexes=[],this.isResizingRows=!1,this.hasChangeWhileResizing=!1,this.bodyEl.style.overflowAnchor="none",this.scrollMargin=this.measureScrollMargin(),this.virtualizer=new H(this.options()),this.unmount=this.virtualizer._didMount(),this.virtualizer._willUpdate(),this.update()}setConfig(t){this.config=t,this.applyOptions()}sync(){this.updateScrollMargin(),this.observedRows.forEach((t=>{t.isConnected||(this.resizeObserver.unobserve(t),this.observedRows.delete(t))}));const t=this.getRenderedRows();t.forEach((t=>{this.observedRows.has(t)||(this.observedRows.add(t),this.resizeObserver.observe(t))})),this.resizeRows(t.filter((t=>this.measuredIndexes.get(t)!==G(t))).map((t=>({row:t,height:t.getBoundingClientRect().height})))),this.layout()}destroy(){this.unmount(),this.resizeObserver.disconnect(),this.observedRows.clear(),this.bodyEl.style.overflowAnchor="",this.bodyEl.style.paddingTop="",this.bodyEl.style.paddingBottom="",this.getRenderedRows().forEach((t=>t.style.marginTop=""))}applyOptions(){this.virtualizer.setOptions(this.options()),this.virtualizer._willUpdate(),this.update()}update(){if(this.updateScrollMargin())return;const t=this.virtualizer.getVirtualItems().map((({index:t})=>t));(function(t,i){return t.length===i.length&&t.every(((t,s)=>t===i[s]))})(t,this.indexes)||(this.indexes=t,this.onIndexesChange(t)),this.layout()}updateScrollMargin(){const t=this.measureScrollMargin();return!(Math.abs(t-this.scrollMargin)<1||(this.scrollMargin=t,this.applyOptions(),0))}resizeRows(t){this.isResizingRows=!0;try{t.forEach((({row:t,height:i})=>{const s=G(t);t.isConnected&&!Number.isNaN(s)&&0!==i&&(this.measuredIndexes.set(t,s),this.virtualizer.resizeItem(s,i))}))}finally{this.isResizingRows=!1}this.hasChangeWhileResizing&&(this.hasChangeWhileResizing=!1,this.update())}handleChange(){this.isResizingRows?this.hasChangeWhileResizing=!0:this.update()}layout(){const t=new Map(this.virtualizer.getVirtualItems().map((t=>[t.index,t])));let i;this.getRenderedRows().forEach((s=>{const e=G(s),h=t.get(e);if(!h)return;s.index!==e+2&&(s.index=e+2);const n=h.start-this.scrollMargin;void 0===i?($(this.bodyEl,"paddingTop",n),$(s,"marginTop",0)):$(s,"marginTop",n-i),i=h.end-this.scrollMargin})),void 0===i&&$(this.bodyEl,"paddingTop",0),$(this.bodyEl,"paddingBottom",this.virtualizer.getTotalSize()-(i??0))}getRenderedRows(){return Array.from(this.bodyEl.querySelectorAll("swirl-table-row[data-index]"))}options(){const{estimatedRowHeight:t,keptIndexes:i,overscan:s,rowCount:e}=this.config,h=this.scrollElement instanceof Window;return{count:e,estimateSize:()=>t,getScrollElement:()=>this.scrollElement,initialOffset:()=>this.scrollElement instanceof Window?this.scrollElement.scrollY:this.scrollElement.scrollTop,overscan:s,scrollMargin:this.scrollMargin,rangeExtractor:t=>function(t,i){return[...new Set([...t,...i])].sort(((t,i)=>t-i))}(I(t),i.filter((t=>Number.isInteger(t)&&t>=0&&t<e))),observeElementRect:h?D:O,observeElementOffset:h?V:W,scrollToFn:h?q:B,onChange:()=>this.handleChange()}}measureScrollMargin(){const t=this.bodyEl.getBoundingClientRect().top;return this.scrollElement instanceof Window?t+this.scrollElement.scrollY:t-this.scrollElement.getBoundingClientRect().top+this.scrollElement.scrollTop}}function G(t){return Number(t.dataset.index)}function $(t,i,s){const e=s>0?s+"px":"";t.style[i]!==e&&(t.style[i]=e)}const J={end:"Dropped. Final position in table: {position} of {rowCount}.",initial:"Press space to move the row.",moved:"Current position in table: {position} of {rowCount}.",start:"Row grabbed. Current position in table: {position} of {rowCount}. Press up and down arrow keys to change position, Space to drop."},Q=t(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.dropRow=s(this,"dropRow",7),this.virtualizationRowsChange=s(this,"virtualizationRowsChange",7),this.dragDropInstructions=J,this.emptyStateLabel="No results found.",this.virtualizationEstimatedRowHeight=56,this.virtualizationOverscan=10,this.virtualizationKeepRowsRendered=[],this.liveRegionText="",this.triggerRerender=a((async()=>{await this.updateLayout(),this.updateEmptyState()}),0,!0),this.updateLayout=p((async()=>{this.resetCellStyles(),this.resetColumnStyles(),this.resetEmptyRowStyles(),this.resetRowGroupStyles(),this.layoutEmptyRow(),this.layoutRowGroups(),this.layOutCellsAndColumns(),this.updateScrolledState()}),16,{leading:!0}),this.onScroll=()=>{this.updateScrolledState()},this.onFocus=t=>{if(this.trackFocusedRow(t.target),this.movingViaKeyboard){const t=this.el.querySelector(".table-row--moving");t&&this.focusDragHandleOfRow(t)}const i=!!t.target?.closest(this.dragDropHandle);""===this.liveRegionText&&i&&this.updateLiveRegionText("initial")},this.onBlur=t=>{const i=t.relatedTarget;this.el.contains(i)||this.trackFocusedRow(null);const s=!!i?.closest(this.dragDropHandle);this.el.contains(i)&&s||""!==this.liveRegionText&&this.updateLiveRegionText()},this.onKeyDown=t=>{if(!this.enableDragDrop)return;const i=t.target?.closest("swirl-table-row");t.target?.closest(this.dragDropHandle)&&("Space"===t.code?(t.preventDefault(),t.stopPropagation(),this.toggleKeyboardMove(i)):"ArrowUp"===t.code?(t.preventDefault(),t.stopPropagation(),this.moveRow(i,"up")):"ArrowDown"===t.code?(t.preventDefault(),t.stopPropagation(),this.moveRow(i,"down")):"Escape"===t.code&&(t.preventDefault(),t.stopPropagation(),this.cancelKeyboardMove()))}}async componentDidLoad(){this.setupIntersectionObserver(),this.setupMutationObservers(),this.updateVirtualizer(),queueMicrotask((()=>{this.setupDragDrop()}))}disconnectedCallback(){this.intersectionObserver?.disconnect(),this.columnMutationObserver?.disconnect(),this.rowMutationObserver?.disconnect(),this.sortable?.destroy(),this.destroyVirtualizer()}handleVirtualizationChange(){this.updateVirtualizer()}get virtualizerConfig(){if(this.enableVirtualization&&this.virtualizationRowCount)return{estimatedRowHeight:this.virtualizationEstimatedRowHeight,keptIndexes:void 0===this.focusedRowIndex?this.virtualizationKeepRowsRendered??[]:[...this.virtualizationKeepRowsRendered??[],this.focusedRowIndex],overscan:this.virtualizationOverscan,rowCount:this.virtualizationRowCount}}updateVirtualizer(){if(!this.bodyEl)return;const t=this.virtualizerConfig;if(!t){const t=!!this.virtualizer;return this.destroyVirtualizer(),void(this.enableVirtualization&&t&&queueMicrotask((()=>this.virtualizationRowsChange.emit({indexes:[]}))))}if(this.virtualizer)return this.virtualizer.setConfig(t),void(this.virtualizer.scrollElement===window&&this.updateScrollParent());this.bodyEl.style.paddingBottom=t.rowCount*t.estimatedRowHeight+"px",this.virtualizer=new U(this.bodyEl,u(this.el),t,(t=>queueMicrotask((()=>this.virtualizationRowsChange.emit({indexes:t})))))}destroyVirtualizer(){this.virtualizer?.destroy(),this.virtualizer=void 0}handleEnableDragDropChange(){queueMicrotask((()=>{this.setupDragDrop()}))}setupIntersectionObserver(){this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange.bind(this),{threshold:0}),this.intersectionObserver.observe(this.container)}setupMutationObservers(){this.columnMutationObserver=new MutationObserver((t=>{t.some((t=>t.addedNodes.length||t.removedNodes.length))&&this.updateLayout()})),this.columnMutationObserver.observe(this.headerEl,{childList:!0,subtree:!0}),this.rowMutationObserver=new MutationObserver((t=>{const i=t.some((t=>t.addedNodes.length||t.removedNodes.length)),s=t.some((t=>"attributes"===t.type));i&&(this.updateEmptyState(),this.setupDragDrop()),(i||s)&&this.syncVirtualizedRows()})),this.startRowMutationObserver()}startRowMutationObserver(){this.rowMutationObserver?.observe(this.bodyEl,{attributeFilter:["data-index"],childList:!0,subtree:!0})}stopRowMutationObserver(){this.rowMutationObserver?.disconnect()}setupDragDrop(){if(this.sortable&&(this.sortable.destroy(),this.sortable=void 0),this.enableDragDrop){if(this.el.querySelector("swirl-table-row-group"))return void console.warn('[Swirl] Drag & drop is not yet supported for swirl-tables using the "swirl-table-row-group" component.');if(!this.dragDropHandle)return void console.warn('[Swirl] swirl-table required the "dragDropHandle" prop to be set when drag & drop is enabled.');const t=this.el.querySelector('[slot="rows"]');this.dragDropContainer="SWIRL-TABLE-ROW"!==t?.tagName?t??this.bodyEl:this.bodyEl,this.sortable=new o(this.dragDropContainer,{animation:100,direction:"vertical",handle:this.dragDropHandle,fallbackOnBody:!0,group:"swirl-table-"+(""+Math.random()).substring(2),onStart:()=>{this.stopRowMutationObserver()},onEnd:t=>{t.stopPropagation();const{to:i,newIndex:s,oldIndex:e,item:h}=t;this.dropRow.emit({newIndex:s,oldIndex:e,item:h,itemId:h.id??h.querySelector(":scope > swirl-table-row").id,newNextSiblingItemId:s<i.children.length-1?i.children[s+1].id:void 0,newPrevSiblingItemId:s>0?i.children[s-1].id:void 0}),this.startRowMutationObserver()}})}}async onVisibilityChange(t){t.some((t=>t.isIntersecting))&&setTimeout((async()=>{this.updateScrollParent(),await this.updateLayout()}),100)}updateScrollParent(){this.virtualizer&&u(this.el)!==this.virtualizer.scrollElement&&(this.destroyVirtualizer(),this.updateVirtualizer())}async componentDidRender(){await this.updateLayout(),this.updateEmptyState()}async onWindowResize(){await this.updateLayout()}async rerender(){this.triggerRerender()}resetEmptyRowStyles(){const t=this.el.querySelector(".table__empty-row");t&&(t.style.width="")}resetRowGroupStyles(){Array.from(this.el.querySelectorAll("swirl-table-row-group")).forEach((t=>{t.shadowRoot.querySelector(".table-row-group__header-row")&&(t.shadowRoot.querySelector(".table-row-group__header-row").style.width="")}))}resetColumnStyles(){this.getColumns().forEach((t=>{t.classList.remove("table-column--has-shadow","table-column--is-sticky","table-column--is-sticky-right"),t.style.right="",t.style.left="",t.style.position="",t.style.zIndex=""}))}resetCellStyles(){this.getCells().forEach((t=>{t.classList.remove("table-cell--has-shadow","table-cell--is-sticky","table-cell--is-sticky-right"),t.style.flex="",t.style.left="",t.style.right="",t.style.position="",t.style.zIndex=""}))}updateScrolledState(){const t=c();if(void 0===this.container)return;const i=this.container.scrollWidth>this.container.clientWidth,s=this.container.scrollLeft>0,e=Math.ceil(this.container.clientWidth+this.container.scrollLeft)>=Math.floor(this.container.scrollWidth);i!==this.scrollable&&(i&&!t?this.container.classList.add("table__container--scrollable"):this.container.classList.remove("table__container--scrollable")),s!==this.scrolled&&(s&&!t?this.container.classList.add("table__container--scrolled"):this.container.classList.remove("table__container--scrolled")),e!==this.scrolledToEnd&&(e&&!t?this.container.classList.add("table__container--scrolled-to-end"):this.container.classList.remove("table__container--scrolled-to-end"))}getColumns(){return Array.from(this.el.querySelectorAll("swirl-table-column"))}getCells(){return Array.from(this.el.querySelectorAll("swirl-table-cell"))}layoutEmptyRow(){const t=this.el.querySelector(".table__empty-row");if(!t)return;const i=this.el.querySelector(".table__container").scrollWidth+"px";t.style.width=i}layoutRowGroups(){const t=Array.from(this.el.querySelectorAll("swirl-table-row-group")),i=this.el.querySelector(".table__container")?.scrollWidth+"px";t.forEach((t=>{t.shadowRoot.querySelector(".table-row-group__header-row")&&(t.shadowRoot.querySelector(".table-row-group__header-row").style.width=i)}))}layOutCellsAndColumns(){const t=this.getColumns(),i=this.getCells();t.forEach(((s,e)=>{const h=this.getCellsForColumn(i,t,e),n=this.calculateColumnProperties(s,t,e);h.forEach((t=>this.applyCellStyles(t,s,n))),this.applyColumnStyles(s,n)}))}getCellsForColumn(t,i,s){return t.filter(((t,e)=>(s-e)%i.length==0))}calculateColumnProperties(t,i,s){return{leftOffsetForStickyColumn:t.sticky?this.getLeftOffsetForStickyColumn(i,s):0,columnWidth:t.getBoundingClientRect().width+"px",isLastColumnSticky:t.sticky&&i.length===s+1,hasShadowRight:t.sticky&&!this.hasStickyColumnsToRight(i,s)}}applyCellStyles(t,i,s){const{leftOffsetForStickyColumn:e,columnWidth:h,isLastColumnSticky:n,hasShadowRight:l}=s;t.style.flex=h?"0 0 "+h:"",c()||(i.sticky&&!n&&(t.classList.add("table-cell--is-sticky"),t.style.left=e+"px",l&&t.classList.add("table-cell--has-shadow-right")),n&&t.classList.add("table-cell--is-sticky-right","table-cell--has-shadow-left"))}applyColumnStyles(t,i){if(c())return;const{leftOffsetForStickyColumn:s,isLastColumnSticky:e,hasShadowRight:h}=i;t.sticky&&!e&&(t.classList.add("table-column--is-sticky"),t.style.left=s+"px",h&&t.classList.add("table-column--has-shadow-right")),e&&t.classList.add("table-column--is-sticky-right","table-column--has-shadow-left")}getLeftOffsetForStickyColumn(t,i){return t.slice(0,i).reduce(((t,i)=>{if(i.sticky)return t+i.getBoundingClientRect().width}),0)}hasStickyColumnsToRight(t,i){return t.slice(i+1,t.length-1).some((t=>t.sticky))}updateEmptyState(){if(this.enableVirtualization&&this.virtualizationRowCount)return void(this.empty=!1);const t=this.el.querySelector('[slot="rows"]');this.empty=!t||0===t.children.length}updateLiveRegionText(t,i={}){let s=t?this.dragDropInstructions[t]:"";for(const[t,e]of Object.entries(i??{}))s=s.replaceAll(`{${t}}`,e+"");s!==this.liveRegionText&&(this.liveRegionText=s)}toggleKeyboardMove(t){this.movingViaKeyboard?this.endKeyboardMove(t):this.startKeyboardMove(t)}startKeyboardMove(t){this.movingViaKeyboard=!0,this.positionBeforeKeyboardMove=Array.from(this.dragDropContainer.children).indexOf(t),t.classList.add("table-row--moving"),this.updateLiveRegionText("start",{position:Array.from(this.dragDropContainer.children).indexOf(t)+1,rowCount:this.dragDropContainer.children.length})}endKeyboardMove(t){this.movingViaKeyboard=!1,t.classList.remove("table-row--moving"),this.updateLiveRegionText("end",{position:Array.from(this.dragDropContainer.children).indexOf(t)+1,rowCount:this.dragDropContainer.children.length}),this.dropRow.emit({item:t,newIndex:Array.from(this.dragDropContainer.children).indexOf(t),oldIndex:this.positionBeforeKeyboardMove,itemId:t.id,newNextSiblingItemId:Array.from(this.dragDropContainer.children).indexOf(t)<this.dragDropContainer.children.length-1?this.dragDropContainer.children[Array.from(this.dragDropContainer.children).indexOf(t)+1].id:void 0,newPrevSiblingItemId:Array.from(this.dragDropContainer.children).indexOf(t)>0?this.dragDropContainer.children[Array.from(this.dragDropContainer.children).indexOf(t)-1].id:void 0}),this.positionBeforeKeyboardMove=void 0}cancelKeyboardMove(){if(!this.movingViaKeyboard)return;const t=this.el.querySelector(".table-row--moving");t&&(t.classList.remove("table-row--moving"),this.movingViaKeyboard=!1,void 0!==this.positionBeforeKeyboardMove&&this.dragDropContainer.insertBefore(t,this.dragDropContainer.children[this.positionBeforeKeyboardMove]))}moveRow(t,i){if(!this.movingViaKeyboard)return;let s;if("up"===i){const i=Array.from(this.dragDropContainer.children).indexOf(t);s=Math.max(0,i-1),this.dragDropContainer.insertBefore(t,this.dragDropContainer.children[s])}else{const i=Array.from(this.dragDropContainer.children).indexOf(t);s=Math.min(this.dragDropContainer.children.length-1,i+1),this.dragDropContainer.insertBefore(t,this.dragDropContainer.children[s+1])}this.updateLiveRegionText("moved",{position:s+1,rowCount:this.dragDropContainer.children.length}),this.focusDragHandleOfRow(t)}focusDragHandleOfRow(t){const i=d(t,this.dragDropHandle)?.[0];"BUTTON"===i.tagName?i.focus():i.querySelector("button")?.focus()}syncVirtualizedRows(){this.virtualizer&&(this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within")),this.virtualizer.sync())}trackFocusedRow(t){if(!this.enableVirtualization)return;const i=t?.closest("swirl-table-row[data-index]")?.dataset.index,s=void 0===i?void 0:Number(i);s!==this.focusedRowIndex&&(this.focusedRowIndex=s,this.updateVirtualizer())}render(){const t=!!this.el.querySelector('[slot="empty"]'),i=r("table",{"table--show-empty-state":this.empty&&!this.loading,"table--keyboard-move":this.movingViaKeyboard});return e(h,{key:"5fd51d538c87dce53702fa483657035e251d3507"},e("div",{key:"7ec3b5830bcc7b0dfc5324f554b80b442b7bc290",class:i},this.enableDragDrop&&e("swirl-visually-hidden",{key:"2928eb420bb8cad6477917a1883aeeffda3260eb"},e("span",{key:"fc615afed57d8dbfbf636f9e8feb9c6ef76ae72b","aria-live":"assertive"},this.liveRegionText)),e("div",{key:"4b7d5b9c4691d1828d0c24fc635d8e7c5dc48cf4",class:"table__container",onFocusin:this.onFocus,onFocusout:this.onBlur,onKeyDown:this.onKeyDown,onScroll:this.onScroll,ref:t=>this.container=t,tabIndex:-1},e("div",{key:"9669435927eb4944290b4fdcb4083ef1473c000e","aria-describedby":this.caption?"caption":void 0,"aria-label":this.label,"aria-rowcount":this.enableVirtualization&&this.virtualizationRowCount?this.virtualizationRowCount+1:void 0,role:"table",class:"table__table"},this.caption&&e("swirl-visually-hidden",{key:"6806eedf8d1aa22b3ee8f51736032ead77a502cc"},e("div",{key:"bea8e3d31ba2e81461ff8e4d056ee3ea718707ea",id:"caption"},this.caption)),e("div",{key:"386fa4a8c2d31471a43580b62ad1003cfbcf224d",role:"rowgroup"},e("div",{key:"aebae228fab2eb7d4a688bb50ee069e7138001c1",class:"table__header","aria-rowindex":this.enableVirtualization?1:void 0,ref:t=>this.headerEl=t,role:"row"},e("slot",{key:"111dd938896772934ba589167ee254936c8bbe9d",name:"columns"}))),e("div",{key:"7a6b87e277bd50dfc8c5ff3e680aabe95384bb7f",class:"table__body",ref:t=>this.bodyEl=t},e("slot",{key:"a766d1ff38bf321fac0b3c52a686d57d2b4551ea",name:"rows"}),e("div",{key:"a26bec40f580546c85e3dd1007c913d53da4c18a",class:"table__empty-row",role:"row"},e("div",{key:"cd9793a4e353a88bfb04658354f247ddfd621e20","aria-colspan":this.getColumns().length,class:"table__empty-row-cell",role:"cell"},e("slot",{key:"3c79cf8327876b4be8e237e6d43c918d6f6dbda0",name:"empty"}),!t&&e("swirl-text",{key:"6f2d3365cd41f0242f8dc6720aed3c5bc1edf4fb",align:"center",size:"sm"},this.emptyStateLabel))))))))}get el(){return this}static get watchers(){return{enableVirtualization:[{handleVirtualizationChange:0}],virtualizationRowCount:[{handleVirtualizationChange:0}],virtualizationEstimatedRowHeight:[{handleVirtualizationChange:0}],virtualizationOverscan:[{handleVirtualizationChange:0}],virtualizationKeepRowsRendered:[{handleVirtualizationChange:0}],enableDragDrop:[{handleEnableDragDropChange:0}]}}static get style(){return".sc-swirl-table-h{--swirl-table-shadow-rgba:rgba(23, 23, 23, 0.2);position:relative;display:block}.sc-swirl-table-h *.sc-swirl-table{box-sizing:border-box}html.theme-dark.sc-swirl-table-h,html.theme-dark .sc-swirl-table-h{--swirl-table-shadow-rgba:rgba(0, 0, 0, 0.2)}.table--keyboard-move.sc-swirl-table:focus-within{--swirl-table-moving-row-border:var(--s-border-width-default) solid var(--s-border-highlight)}.table--show-empty-state.sc-swirl-table .table__empty-row.sc-swirl-table{display:flex}.table__container.sc-swirl-table{position:relative;overflow:auto;width:100%}.table__container--scrolled.sc-swirl-table{--swirl-table-sticky-right-shadow:4px 0 16px -4px var(--swirl-table-shadow-rgba), 2px 0 4px -2px var(--swirl-table-shadow-rgba)}.table__container--scrollable.sc-swirl-table:not(.table__container--scrolled-to-end){--swirl-table-sticky-left-shadow:0px 4px 16px 0px var(--swirl-table-shadow-rgba), 0px 1px 4px 0px var(--swirl-table-shadow-rgba)}.table__table.sc-swirl-table{width:-moz-max-content;width:max-content;min-width:max(20rem, 100%)}.table__header.sc-swirl-table-s>*,.table__header .sc-swirl-table-s>*{display:flex}.table__empty-row.sc-swirl-table{display:none}.table__empty-row-cell.sc-swirl-table{display:flex;overflow:auto;padding-top:var(--s-space-8);padding-right:var(--s-space-16);padding-bottom:var(--s-space-8);padding-left:var(--s-space-16);flex-basis:0;flex-grow:1;flex-shrink:1;align-items:center;background-color:var(--s-surface-default)}.table__empty-row-cell.sc-swirl-table>*.sc-swirl-table{flex-grow:1}"}},[262,"swirl-table",{caption:[1],dragDropHandle:[1,"drag-drop-handle"],dragDropInstructions:[16],emptyStateLabel:[1,"empty-state-label"],enableDragDrop:[4,"enable-drag-drop"],label:[1],loading:[4],enableVirtualization:[4,"enable-virtualization"],virtualizationRowCount:[2,"virtualization-row-count"],virtualizationEstimatedRowHeight:[2,"virtualization-estimated-row-height"],virtualizationOverscan:[2,"virtualization-overscan"],virtualizationKeepRowsRendered:[16],empty:[32],liveRegionText:[32],scrollable:[32],scrolled:[32],scrolledToEnd:[32],rerender:[64]},[[9,"resize","onWindowResize"]],{enableVirtualization:[{handleVirtualizationChange:0}],virtualizationRowCount:[{handleVirtualizationChange:0}],virtualizationEstimatedRowHeight:[{handleVirtualizationChange:0}],virtualizationOverscan:[{handleVirtualizationChange:0}],virtualizationKeepRowsRendered:[{handleVirtualizationChange:0}],enableDragDrop:[{handleEnableDragDropChange:0}]}]),X=Q,Y=function(){"undefined"!=typeof customElements&&["swirl-table","swirl-text","swirl-visually-hidden"].forEach((t=>{switch(t){case"swirl-table":customElements.get(n(t))||customElements.define(n(t),Q);break;case"swirl-text":customElements.get(n(t))||f();break;case"swirl-visually-hidden":customElements.get(n(t))||b()}}))};export{X as SwirlTable,Y as defineCustomElement}
1
+ import{proxyCustomElement as t,HTMLElement as i,createEvent as s,h as e,Host as h,transformTag as n}from"@stencil/core/internal/client";import{g as l,c as r}from"./index2.js";import{S as o}from"./sortable.esm.js";import{o as a,i as u,q as c}from"./utils.js";import{d}from"./swirl-text2.js";import{d as f}from"./swirl-visually-hidden2.js";var b,v,w=l((v||(v=1,b=function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},e=void 0,h=void 0,n=void 0,l=[];return function(){var o=function(t){return"function"==typeof t?t():t}(i),a=(new Date).getTime(),u=!e||a-e>o;e=a;for(var c=arguments.length,d=Array(c),f=0;f<c;f++)d[f]=arguments[f];if(u&&s.leading)return s.accumulate?Promise.resolve(t.call(this,[d])).then((function(t){return t[0]})):Promise.resolve(t.call.apply(t,[this].concat(d)));if(h?clearTimeout(n):h=function(){var t={};return t.promise=new Promise((function(i,s){t.resolve=i,t.reject=s})),t}(),l.push(d),n=setTimeout(r.bind(this),o),s.accumulate){var b=l.length-1;return h.promise.then((function(t){return t[b]}))}return h.promise};function r(){var i=h;clearTimeout(n),Promise.resolve(s.accumulate?t.call(this,l):t.apply(this,l[l.length-1])).then(i.resolve,i.reject),l=[],h=null}}),b));function p(t,i,s){let e,h=s.initialDeps??[],n=!0;function l(){const l=t();return l.length!==h.length||l.some(((t,i)=>h[i]!==t))?(h=l,e=i(...l),!(null==s?void 0:s.onChange)||n&&s.skipInitialOnChange||s.onChange(e),n=!1,e):e}return l.updateDeps=t=>{h=t},l}function m(t){if(void 0===t)throw Error("Unexpected undefined");return t}const g=(t,i)=>Math.abs(t-i)<1.01,y=(t,i,s)=>{let e;return Object.assign((function(...h){t.clearTimeout(e),e=t.setTimeout((()=>i.apply(this,h)),s)}),{cancel:()=>{t.clearTimeout(e)}})};let x;const M=()=>{if(void 0!==x)return x;if("undefined"==typeof navigator)return x=!1;if(/iP(hone|od|ad)/.test(navigator.userAgent))return x=!0;const t=navigator.maxTouchPoints;return x="MacIntel"===navigator.platform&&void 0!==t&&t>0};let k;const S={capture:!0,passive:!0};class _{constructor(t){this.host=t,this._touch=null,this.inMotion=()=>null!==this._touch&&"lateFling"!==this._touch.phase,this.dragging=()=>{var t;return"down"===(null==(t=this._touch)?void 0:t.phase)&&this._touch.moved},this.tail=()=>{var t;return"tail"===(null==(t=this._touch)?void 0:t.phase)?this._touch.moved?"fling":"tap":null},this.onScroll=({isScrolling:t,ownReadBack:i,moved:s,external:e})=>{var h,n,l;return t&&"tail"===(null==(h=this._touch)?void 0:h.phase)?this._openTail(this._touch.moved||!i,!1):"lateFling"===(null==(n=this._touch)?void 0:n.phase)&&(this.host.now()>this._touch.until?this._touch=null:e&&t&&s&&this._openTail(!0,!1)),!(i||!t||!s||"down"!==(null==(l=this._touch)?void 0:l.phase)||(this._touch.moved=!0,0))},this.touchStart=()=>{this.end(),this._touch={phase:"down",moved:!1}},this.touchEnd=()=>{var t;const i="down"===(null==(t=this._touch)?void 0:t.phase)&&this._touch.moved;this.end(),this._openTail(i,i)},this.end=()=>{var t;const i=this.host.getWindow();"tail"===(null==(t=this._touch)?void 0:t.phase)&&null!=i&&i.clearTimeout(this._touch.timerId),this._touch=null},this.listen=t=>{const i=()=>this.touchStart(),s=()=>this.touchEnd();return t.addEventListener("touchstart",i,S),t.addEventListener("touchend",s,S),t.addEventListener("touchcancel",s,S),()=>{t.removeEventListener("touchstart",i,S),t.removeEventListener("touchend",s,S),t.removeEventListener("touchcancel",s,S),this.end()}},this._openTail=(t,i)=>{const s=this.host.getWindow();if(null==s)return;this.end();const e={phase:"tail",moved:t,awaitingFling:i,timerId:s.setTimeout((()=>{this.host.tailStillMoving()?this._openTail(e.moved,e.awaitingFling):(this._touch=e.awaitingFling?{phase:"lateFling",until:this.host.now()+1e3}:null,this.host.onTailClosed())}),150)};this._touch=e}}get touch(){return this._touch}}const C=t=>{const{clientWidth:i,clientHeight:s}=t;return{width:i,height:s}},R=t=>{const i=new Set;return{schedule:s=>{const e=t.requestAnimationFrame((()=>{i.delete(e),s()}));i.add(e)},cancel:()=>{i.forEach((i=>t.cancelAnimationFrame(i))),i.clear()}}},z=t=>t,A=t=>{const i=t.overscan*Math.max(t.lanes??1,1),s=Math.max(t.startIndex-i,0),e=Math.min(t.endIndex+i,t.count-1)-s+1,h=Array(e);for(let t=0;t<e;t++)h[t]=s+t;return h},I=(t,i)=>{const s=t.scrollElement;if(!s)return;const e=t.targetWindow;if(!e)return;const h=t=>{const{width:s,height:e}=t;i({width:Math.round(s),height:Math.round(e)})};if(h(C(s)),!e.ResizeObserver)return()=>{};const n=R(e),l=new e.ResizeObserver((()=>{const i=()=>{h(C(s))};t.options.useAnimationFrameWithResizeObserver?n.schedule(i):i()}));return l.observe(s,{box:"content-box"}),()=>{l.unobserve(s),n.cancel()}},O={passive:!0},E=(t,i)=>{const s=t.scrollElement;if(!s)return;const e=()=>{i({width:s.innerWidth,height:s.innerHeight})};return e(),s.addEventListener("resize",e,O),()=>{s.removeEventListener("resize",e)}},D="undefined"==typeof window||"onscrollend"in window,F=(t,i,s)=>{const e=t.scrollElement;if(!e)return;const h=t.targetWindow;if(!h)return;const n=t.options.useScrollendEvent&&D;let l=0;const r=n?null:y(h,(()=>i(s(e),!1)),t.options.isScrollingResetDelay),o=t=>()=>{l=s(e),null==r||r(),i(l,t)},a=o(!0),u=o(!1);return e.addEventListener("scroll",a,O),n&&e.addEventListener("scrollend",u,O),()=>{e.removeEventListener("scroll",a),n&&e.removeEventListener("scrollend",u),null==r||r.cancel()}},T=(t,i)=>F(t,i,(i=>{const{horizontal:s,isRtl:e}=t.options;return s?i.scrollLeft*(e?-1:1):i.scrollTop})),W=(t,i)=>F(t,i,(i=>t.options.horizontal?i.scrollX:i.scrollY)),V=(t,i,s)=>{if(s.options.useCachedMeasurements){const i=s.indexFromElement(t),e=s.options.getItemKey(i);return s.itemSizeCache.get(e)??s.options.estimateSize(i)}if(null==i?void 0:i.borderBoxSize){const t=i.borderBoxSize[0];if(t)return Math.round(t[s.options.horizontal?"inlineSize":"blockSize"])}if(!i){const i=s.indexFromElement(t),e=s.options.getItemKey(i),h=s.itemSizeCache.get(e);if(void 0!==h)return h}return t[s.options.horizontal?"offsetWidth":"offsetHeight"]},L=(t,{adjustments:i=0,behavior:s},e)=>{var h,n;null==(n=null==(h=e.scrollElement)?void 0:h.scrollTo)||n.call(h,{[e.options.horizontal?"left":"top"]:t+i,behavior:s})},j=L,q=L,B=(t,i)=>"smooth"===t?i?"smoothLanded":"smooth":"instant",P=t=>"smooth"===(null==t?void 0:t.phase)||"smoothLanded"===(null==t?void 0:t.phase);class K{constructor(t){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache=new Map,this.itemSizeCacheVersion=0,this.laneAssignments=new Map,this.pendingMin=null,this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.pendingScrollAnchor=null,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._iosGesture=new _({getWindow:()=>this.targetWindow,now:()=>this.now(),tailStillMoving:()=>{const t=this.scrollState;if("queued"!==(null==t?void 0:t.phase)||null!==this.pendingWrite)return!1;const i=this._readElementOffset();return!(null===i||null===this._lastElementOffset||Math.abs(i-this._lastElementOffset)<1||(this._lastElementOffset=i,t.samples=[...t.samples??[],{t:this.now(),offset:i}],0))},onTailClosed:()=>{const t=this.scrollState;"queued"===(null==t?void 0:t.phase)&&function(t){const i=t[t.length-1];if(void 0===i)return!1;let s=t.length-2;for(;s>=0&&i.t-t[s].t<40;)s--;if(s<0)return!1;const e=t[s];return Math.abs(i.offset-e.offset)/(i.t-e.t)>=.05}(t.samples??[])&&(this.scrollState=null),this._flushHoldIfReady(!0),this._writeAwaitingCommand(),this._retryClampedAdjustment()}}),this._lastElementOffset=null,this.pendingWrite=null,this._clampedAdjustment=null,this.elementsCache=new Map,this._resizeBatch=null,this.now=()=>{var t,i,s;return(null==(s=null==(i=null==(t=this.targetWindow)?void 0:t.performance)?void 0:i.now)?void 0:s.call(i))??Date.now()},this.observer=(()=>{let t=null,i=null,s=!1,e=!1;const h=new Set,n=()=>{if(t)return t;const e=this.targetWindow;if(!e||!e.ResizeObserver)return null;const h=i=R(e);return t=new e.ResizeObserver((t=>{const i=()=>{const i={sync:!1};this._resizeBatch=i;try{t.forEach(l)}finally{this._resizeBatch=null,i.notify&&(this.notify(i.sync),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment(),this.measureElement(null))}};if(this.options.useAnimationFrameWithResizeObserver)h.schedule(i);else{s=!0;try{i()}finally{s=!1}}}))},l=t=>{const i=t.target,s=this.indexFromElement(i);if(i.isConnected)this.isIndexInRange(s)&&this.shouldMeasureDuringScroll(s)&&this.resizeItem(s,this.options.measureElement(i,t,this));else{this.observer.unobserve(i);for(const[t,s]of this.elementsCache)if(s===i){this.elementsCache.delete(t);break}}};return{disconnect:()=>{var s;null==(s=n())||s.disconnect(),null==i||i.cancel(),h.clear(),e=!1,t=null,i=null},observe:l=>{const r=n();r&&(s?(h.add(l),e||(e=!0,null==i||i.schedule((()=>{e=!1,h.forEach((i=>{i.isConnected&&(null==t||t.observe(i,{box:"border-box"}))})),h.clear()})))):r.observe(l,{box:"border-box"}))},unobserve:t=>{var i;h.delete(t),null==(i=n())||i.unobserve(t)}}})(),this.range=null,this.setOptions=t=>{var i;const s={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:z,rangeExtractor:A,onChange:()=>{},measureElement:V,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,anchorTo:"start",followOnAppend:!1,scrollEndThreshold:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",useCachedMeasurements:!1};for(const i in t){const e=t[i];void 0!==e&&(s[i]=e)}const e=this.options;let h=null,n=null,l=!1;if(void 0!==e&&e.enabled&&s.enabled&&"end"===s.anchorTo&&null!==this.scrollElement){const t=e.count,r=s.count,o=this.getMeasurements(),a=(null==(i=this._singleLaneMeasurements)?void 0:i.items)??o,u=t=>function(t){return"object"==typeof t?t.key:t}(a[t]),c=t>0?u(0):null,d=t>0?u(t-1):null;if(r!==t||t>0&&r>0&&(s.getItemKey(0)!==c||s.getItemKey(r-1)!==d)){l=!0;const i=t>0?this.getVirtualItemForOffset(this.getScrollOffset())??o[0]:null;i&&(h=[i.key,this.getScrollOffset()-i.start]);const a=!0===s.followOnAppend?"auto":s.followOnAppend||null;a&&r>0&&this.isAtEnd(e.scrollEndThreshold)&&(0===t||s.getItemKey(r-1)!==d)&&(r>t||function(t,i,s,e){if(0===i)return!1;const h=e(0),n=new Set;let l=0;for(;l<t;){const t=s(l);if(t===h)break;n.add(t),l++}const r=t-l;if(0===r||r>=i)return!1;for(let t=0;t<r;t++)if(e(t)!==s(l+t))return!1;for(let t=r;t<i;t++)if(n.has(e(t)))return!1;return!0}(t,r,u,s.getItemKey))&&(n=a)}}this.options=s,l&&(this.pendingMin=0,this.itemSizeCacheVersion++);let r=null;if(h&&null!==this.scrollOffset&&!this._awaitingCommandReadBack()){const[t,i]=h,s=this.getMeasurements(),{count:e,getItemKey:l}=this.options;let o=0;for(;o<e&&l(o)!==t;)o++;if(o<e){const t=s[o];if(t){const s=Math.max(0,t.start+i);n||s===this.scrollOffset||(r=s-this.scrollOffset,this.scrollOffset=s)}}}n?this.pendingScrollAnchor={kind:"follow",behavior:n}:null!==r&&(this._canWriteScroll()?this.pendingScrollAnchor={kind:"anchor",delta:r}:(this._holdOffset+=r,this._followOffsetTarget(r)))},this.notify=t=>{var i,s;null==(s=(i=this.options).onChange)||s.call(i,this,t)},this.maybeNotify=p((()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null])),(t=>{this.notify(t)}),{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{var t;this.unsubs.filter(Boolean).forEach((t=>t())),this.unsubs=[],this.observer.disconnect(),null!=this.rafId&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,null==(t=this._momentumStop)||t.restore(),this._momentumStop=null,this.isScrolling=!1,this.scrollDirection=null,this._holdOffset=0,this._reportedOverscroll=!1,this._clampedAdjustment=null,this.pendingWrite=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const i=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==i){if(this.cleanup(),!i)return void this.maybeNotify();this.scrollElement=i,this.targetWindow=this.scrollElement&&"ownerDocument"in this.scrollElement?this.scrollElement.ownerDocument.defaultView:(null==(t=this.scrollElement)?void 0:t.window)??null,this.elementsCache.forEach((t=>{this.observer.observe(t)})),this.unsubs.push(this.options.observeElementRect(this,(t=>{this.scrollRect=t,this.maybeNotify()}))),this.unsubs.push(this.options.observeElementOffset(this,((t,i)=>{var s,e,h,n;const l=i?this._elementMaxScrollOffset():null,r=this._reportedOverscroll;this._reportedOverscroll=t<0||null!==l&&t>l+1;const o=t;this._lastElementOffset=o,t=this._toLayoutOffset(t);const a=this._classifyScrollEvent(t,i,l);if("spurious"===a)return;"readBack"===a?t=this.pendingWrite.target:"clampedReadBack"===a&&null!=(null==(s=this.scrollState)?void 0:s.index)&&t<this.getMaxScrollOffset()-1.5?this.scrollState.lastTargetOffset=t:function({kind:t,offset:i,command:s,target:e}){return"spurious"!==t&&"readBack"!==t&&"clampedReadBack"!==t&&null!=(null==s?void 0:s.index)&&"queued"!==s.phase&&!(t=>"smooth"===t||"smoothFinishing"===t)(s.phase)&&!g(i,s.lastTargetOffset)&&!g(i,e())&&"clampedEcho"!==t}({kind:a,offset:t,command:this.scrollState,target:()=>this.getScrollStateTarget(this.scrollState)})&&(this.scrollState=null),this.pendingWrite=null,null!==this._clampedAdjustment&&Math.abs(t-this._clampedAdjustment.maxAtWrite)>=1.5&&(this._clampedAdjustment=null);const u=this.getScrollOffset(),c=this.scrollDirection;this.scrollDirection=i?u===t?this.scrollDirection:u<t?"forward":"backward":null,this.scrollOffset=t,this.isScrolling=i;const d=this.scrollState;if("queued"===(null==d?void 0:d.phase)&&"external"===a&&i)if(r||this._reportedOverscroll)d.samples=[];else{const t=this.now();d.samples=[...(d.samples??[]).filter((i=>t-i.t<=200)),{t,offset:o}],(null!==c&&this.scrollDirection!==c||function(t){const i=t[t.length-1];if(void 0===i)return!1;let s=t.length-2;for(;s>=0&&i.t-t[s].t<40;)s--;if(s<0)return!1;const e=t[s];let h=s-1;for(;h>=0&&e.t-t[h].t<40;)h--;if(h<0)return!1;const n=t[h],l=(i.offset-e.offset)/(i.t-e.t),r=(e.offset-n.offset)/(e.t-n.t);return l*r>=0&&Math.abs(l)>=2*Math.abs(r)&&Math.abs(l)-Math.abs(r)>=.8}(d.samples))&&(this.scrollState=null)}this._iosGesture.onScroll({isScrolling:i,ownReadBack:"readBack"===a,moved:t!==u,external:"external"===a&&"smooth"!==(null==(e=this.scrollState)?void 0:e.phase)&&"smoothFinishing"!==(null==(h=this.scrollState)?void 0:h.phase)})&&"queued"===(null==(n=this.scrollState)?void 0:n.phase)&&(this.scrollState=null),this._flushHoldIfReady(!0),this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()}))),"addEventListener"in this.scrollElement&&this.unsubs.push(this._iosGesture.listen(this.scrollElement)),this._scrollToOffset(this.getScrollOffset())}this._noteClampMax();const s=this.pendingScrollAnchor;this.pendingScrollAnchor=null,s&&this.scrollElement&&this.options.enabled&&("anchor"===s.kind?this._canWriteScroll()?P(this.scrollState)&&!g(this.getScrollOffset()-s.delta,this.scrollState.lastTargetOffset)||(this._followOffsetTarget(s.delta),this._scrollToOffset(this.getScrollOffset())):(this._holdOffset+=s.delta,this._followOffsetTarget(s.delta),this.notify(!1)):this.scrollToEnd({behavior:s.behavior})),this._flushHoldIfReady(!1),this._retryClampedAdjustment()},this._classifyScrollEvent=(t,i,s)=>{var e;return function({offset:t,isScrolling:i,elementMax:s,holdOffset:e,scrollOffset:h,pendingWrite:n,clampedMaxAtWrite:l}){var r;return i&&null===n&&t===h?"spurious":null!==n&&Math.abs(t-n.target)<1.5?"readBack":null!==n&&!n.smooth&&null!==s&&n.target>s+e+.5&&Math.abs(t-(s+e))<1.5||null!==n&&!n.smooth&&(null==(r=n.lowMaxes)?void 0:r.some((i=>Math.abs(t-i)<1.5)))?"clampedReadBack":null!==l&&Math.abs(t-l)<1.5?"clampedEcho":"external"}({offset:t,isScrolling:i,elementMax:s,holdOffset:this._holdOffset,scrollOffset:this.scrollOffset,pendingWrite:this.pendingWrite,clampedMaxAtWrite:(null==(e=this._clampedAdjustment)?void 0:e.maxAtWrite)??null})},this._retryClampedAdjustment=()=>{if(null===this._clampedAdjustment||!this.scrollElement||!this.options.enabled||!this._canWriteScroll())return;const{target:t,maxAtWrite:i}=this._clampedAdjustment,s=this.getMaxScrollOffset();s>i+.5&&(this._clampedAdjustment=t>s+.5?{target:t,maxAtWrite:s}:null,this._scrollToOffset(t))},this._writeAwaitingCommand=()=>{const t=this.scrollState;if(null===t||"queued"!==t.phase)return;const{behavior:i}=t;this.getMeasurements();const s=this.getScrollStateTarget(t);t.lastTargetOffset=s,this._clampedAdjustment=null,t.phase=B(i,null!=t.index&&g(s,this.getScrollOffset())),this._scrollToOffset(s,{behavior:i}),this.scheduleScrollReconcile()},this._readElementOffset=()=>{const t=this.scrollElement;if(null==t)return null;const{horizontal:i,isRtl:s}=this.options;return"number"==typeof t.scrollTop?i?t.scrollLeft*(s?-1:1):t.scrollTop:"number"==typeof t.scrollY?i?t.scrollX:t.scrollY:null},this._canWriteScroll=()=>!(M()&&this._iosGesture.inMotion()||this._reportedOverscroll),this._flushHoldIfReady=t=>{var i;if(0===this._holdOffset)return;if(!this.scrollElement||!this.options.enabled)return;if(!this._canWriteScroll())return;if("smooth"===(null==(i=this.scrollState)?void 0:i.phase))return;this._holdOffset=0,null!==this.scrollOffset&&this.scrollOffset<0&&(this.scrollOffset=0),this.notify(t);const s=this.getCommandWrittenOffset()??this.getScrollOffset();this._clampedAdjustment=this._clampedBy(s),this._scrollToOffset(s)},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??("function"==typeof this.options.initialOffset?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getMeasurementOptions=p((()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode,this.options.gap]),((t,i,s,e,h,n,l,r)=>(void 0!==this.prevLanes&&this.prevLanes!==n&&(this.lanesChangedFlag=!0),this.prevLanes=n,this.pendingMin=null,{count:t,paddingStart:i,scrollMargin:s,getItemKey:e,enabled:h,lanes:n,laneAssignmentMode:l,gap:r})),{key:!1}),this.isIndexInRange=t=>t>=0&&t<this.options.count,this.getMeasurements=p((()=>[this.getMeasurementOptions(),this.itemSizeCacheVersion]),(({count:t,paddingStart:i,scrollMargin:s,getItemKey:e,enabled:h,lanes:n,laneAssignmentMode:l,gap:r})=>{var o;const a=this.itemSizeCache;if(!h)return this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const i of this.laneAssignments.keys())i>=t&&this.laneAssignments.delete(i);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this._singleLaneMeasurements=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMin=null),0!==this.measurementsCache.length||this.lanesSettling||(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach((t=>{this.itemSizeCache.set(t.key,t.size)})));const u=this.lanesSettling?0:this.pendingMin??0;if(this.pendingMin=null,this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1),1===n){const h=2*t;let n=null==(o=this._singleLaneMeasurements)?void 0:o.flat;if(!n||n.length<h){const t=new Float64Array(h);n&&u>0&&t.set(n.subarray(0,2*u)),n=t}const l=0===u?Array(t):this._singleLaneMeasurements.items.slice();let c;if(0===u)c=i+s;else{const t=u-1;c=n[2*t]+n[2*t+1]+r}for(let i=u;i<t;i++){const t=e(i);l[i]=t;const s=a.get(t),h="number"==typeof s?s:this.options.estimateSize(i);n[2*i]=c,n[2*i+1]=h,c+=h+r}this._singleLaneMeasurements={flat:n,items:l};const d=function(t,i){const s=t.length;return new Proxy(t,{get(t,e,h){if("string"==typeof e){const h=e.charCodeAt(0);if(h>=48&&h<=57){const h=+e;if(Number.isInteger(h)&&h>=0&&h<s){let s=t[h];if("object"!=typeof s){const e=i[2*h];s=t[h]={index:h,key:s,start:e,size:i[2*h+1],end:e+i[2*h+1],lane:0}}return s}}if("length"===e)return s}return Reflect.get(t,e,h)}})}(l,n);return this.measurementsCache=d,d}const c=this.measurementsCache.slice(0,u),d=Array(n).fill(void 0),f=new Float64Array(n);let b=0;for(let t=0;t<u;t++){const i=c[t];i&&(void 0===d[i.lane]&&b++,d[i.lane]=t,f[i.lane]=i.end)}for(let h=u;h<t;h++){const t=e(h),o=this.laneAssignments.get(h);let u,v;const w="estimate"===l||a.has(t);if(void 0!==o&&this.options.lanes>1){u=o;const t=d[u],e=void 0!==t?c[t]:void 0;v=e?e.end+r:i+s}else if(b===n){let t=0,i=f[0],s=d[0];for(let e=1;e<n;e++){const h=f[e];(h<i||h===i&&d[e]<s)&&(t=e,i=h,s=d[e])}u=t,v=i+r,w&&this.laneAssignments.set(h,u)}else u=h%this.options.lanes,v=i+s,w&&this.laneAssignments.set(h,u);const p=a.get(t),m="number"==typeof p?p:this.options.estimateSize(h),g=v+m;c[h]={index:h,start:v,size:m,end:g,key:t,lane:u},void 0===d[u]&&b++,d[u]=h,f[u]=g}return this.measurementsCache=c,c}),{key:!1,debug:()=>this.options.debug}),this.calculateRange=p((()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes,this._getLayoutTotalSize()+this.options.scrollMargin]),((t,i,s,e,h)=>0===t.length||0===i?(this.range=null,null):(this.range=function(t,i,s,e,h){const n=t.length-1;if(t.length<=e)return{startIndex:0,endIndex:n};if(1===e&&null!==h){const t=function(t,i,s){let e=0;for(;e<=i;){const h=(e+i)/2|0,n=t[2*h];if(n<s)e=h+1;else{if(!(n>s))return h;i=h-1}}return e>0?e-1:0}(h,n,s);let e=t;const l=s+i;for(;e<n&&h[2*e]+h[2*e+1]<l;)e++;return{startIndex:t,endIndex:e}}let l=H(0,n,(i=>t[i].start),s),r=l;if(1===e)for(;r<n&&t[r].end<s+i;)r++;else if(e>1){const h=Array(e).fill(0);for(;r<n&&h.some((t=>t<s+i));){const i=t[r];h[i.lane]=i.end,r++}const o=Array(e).fill(s+i);for(;l>=0&&o.some((t=>t>=s));){const i=t[l];o[i.lane]=i.start,l--}l=Math.max(0,l-l%e),r=Math.min(n,r+(e-1-r%e))}return{startIndex:l,endIndex:r}}(t,i,Math.min(s,Math.max(h-i,0)),e,1===e&&null!==this._singleLaneMeasurements?this._singleLaneMeasurements.flat:null),this.range)),{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=p((()=>{let t=null,i=null;const s=this.calculateRange();return s&&(t=s.startIndex,i=s.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,i]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,i,this.options.lanes]}),((t,i,s,e,h,n)=>null===e||null===h?[]:t({startIndex:e,endIndex:h,overscan:i,count:s,lanes:n})),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const i=this.options.indexAttribute,s=t.getAttribute(i);return s?parseInt(s,10):(console.warn(`Missing attribute name '${i}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var i;if(!P(this.scrollState))return!0;const s=this.scrollState.index??(null==(i=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))?void 0:i.index);if(void 0!==s&&this.range){const i=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2));return t>=Math.max(0,s-i)&&t<=Math.min(this.options.count-1,s+i)}return!0},this.measureElement=t=>{if(!t)return void this.elementsCache.forEach(((t,i)=>{t.isConnected||(this.observer.unobserve(t),this.elementsCache.delete(i))}));const i=this.indexFromElement(t);if(!this.isIndexInRange(i))return;const s=this.options.getItemKey(i),e=this.elementsCache.get(s);e!==t&&(e&&this.observer.unobserve(e),this.observer.observe(t),this.elementsCache.set(s,t)),t.isConnected&&(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(i)&&this.resizeItem(i,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,i)=>{var s,e,h;if(!this.isIndexInRange(t))return;let n,l,r;(null==(s=this._resizeBatch)?void 0:s.sync)&&this.getMeasurements();const o=null==(e=this._singleLaneMeasurements)?void 0:e.flat;if(1===this.options.lanes&&null!=o)r=this.options.getItemKey(t),l=o[2*t],n=o[2*t+1];else{const i=this.measurementsCache[t];if(!i)return;r=i.key,l=i.start,n=i.size}const a=this.itemSizeCache.get(r)??n,u=i-a;if(0!==u){const s="end"===this.options.anchorTo&&!P(this.scrollState)&&this.getVirtualDistanceFromEnd()<=this.options.scrollEndThreshold,e=s?this._getLayoutTotalSize():0,o=this.getScrollOffset(),c=this.itemSizeCache.has(r)?l+a<=o&&"backward"!==this.scrollDirection:l<o,d=!P(this.scrollState)&&(void 0!==this.shouldAdjustScrollPositionOnItemSizeChange?this.shouldAdjustScrollPositionOnItemSizeChange(this.measurementsCache[t]??{index:t,key:r,start:l,size:n,end:l+n,lane:0},u,this):c);(null===this.pendingMin||t<this.pendingMin)&&(this.pendingMin=t),this.itemSizeCache.set(r,i),this.itemSizeCacheVersion++;let f=!1;if(this._awaitingCommandReadBack()||(s?f=this.applyScrollAdjustment(this._getLayoutTotalSize()-e):d&&(f=this.applyScrollAdjustment(u))),this._resizeBatch)return this._resizeBatch.notify=!0,void((h=this._resizeBatch).sync||(h.sync=f));this.notify(f),this._noteClampMax(),this._flushHoldIfReady(!0),this._retryClampedAdjustment()}},this.getVirtualItems=p((()=>[this.getVirtualIndexes(),this.getMeasurements(),this._holdOffset]),((t,i,s)=>{const e=[];for(let h=0,n=t.length;h<n;h++){const n=i[t[h]];e.push(0===s?n:{...n,start:n.start-s,end:n.end-s})}return e}),{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{var i;const s=this.getMeasurements();if(0===s.length)return;const e=null==(i=this._singleLaneMeasurements)?void 0:i.flat,h=H(0,s.length-1,1===this.options.lanes&&null!=e?t=>e[2*t]:t=>m(s[t]).start,t);return m(s[h])},this._noteClampMax=()=>{if(!this._awaitingCommandReadBack())return;const t=this._elementMaxScrollOffset();if(null===t)return;const i=this.pendingWrite,s=Math.max(t,0)+this._holdOffset;if(s>=i.target)return;const e=i.lowMaxes??(i.lowMaxes=[]);e[e.length-1]!==s&&e.push(s)},this.getMaxScrollOffset=()=>(this._elementMaxScrollOffset()??0)+this._holdOffset,this._toLayoutOffset=t=>{var i;let s=t+this._holdOffset;return"anchor"===(null==(i=this.pendingScrollAnchor)?void 0:i.kind)&&(s+=this.pendingScrollAnchor.delta),s},this._elementMaxScrollOffset=()=>{const t=this.scrollElement;if(null===t)return null;if("scrollHeight"in t)return this.options.horizontal?t.scrollWidth-t.clientWidth:t.scrollHeight-t.clientHeight;if("document"in t){const i=t.document.documentElement;return this.options.horizontal?i.scrollWidth-t.innerWidth:i.scrollHeight-t.innerHeight}return null},this._momentumStop=null,this._stopMomentum=t=>{const i=this.scrollElement,s=this.targetWindow;if(null===i||null===s)return;const e="document"in i?i.document.scrollingElement:i;if(!(null==e?void 0:e.style))return;if(this._momentumStop)return void(this._momentumStop.done=t);const{style:h}=e,n=this.options.horizontal?"overflow-x":"overflow-y",l=h.getPropertyValue(n),r=h.getPropertyPriority(n),o=()=>this.options.horizontal?e.clientHeight:e.clientWidth,a=o();if(h.setProperty(n,"hidden","important"),o()!==a)return void h.setProperty(n,l,r);const u={restore:()=>"hidden"===h.getPropertyValue(n)&&"important"===h.getPropertyPriority(n)&&(h.setProperty(n,l,r),!0),done:t};this._momentumStop=u,s.requestAnimationFrame((()=>s.requestAnimationFrame((()=>{this._momentumStop===u&&(this._momentumStop=null,u.restore()&&u.done())}))))},this._clampedBy=t=>{const i=this._elementMaxScrollOffset();if(null===i)return null;const s=i+this._holdOffset;return t>s+.5?{target:t,maxAtWrite:s}:null},this.getVirtualDistanceFromEnd=()=>Math.max(this._getLayoutTotalSize()+this.options.scrollMargin-this.getSize()-this.getScrollOffset(),0),this.getDistanceFromEnd=()=>Math.max(this.getMaxScrollOffset()-this.getScrollOffset(),0),this.isAtEnd=(t=this.options.scrollEndThreshold)=>this.getDistanceFromEnd()<=t,this.getOffsetForAlignment=(t,i,s=0)=>{if(!this.scrollElement)return 0;const e=this.getSize(),h=this.getScrollOffset();"auto"===i&&(i=t>=h+e?"end":"start"),"center"===i?t+=(s-e)/2:"end"===i&&(t-=e);const n=this.getMaxScrollOffset();return Math.max(Math.min(n,t),0)},this.getOffsetForIndex=(t,i="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const s=this.getSize(),e=this.getScrollOffset(),h=this.measurementsCache[t];if(h){if("auto"===i)if(h.end>=e+s-this.options.scrollPaddingEnd)i="end";else{if(!(h.start<=e+this.options.scrollPaddingStart))return[e,i];i="start"}if("end"===i&&t===this.options.count-1){const t=this.getMaxScrollOffset();return[Math.max(Math.min(t-this.options.paddingEnd+this.options.scrollPaddingEnd,t),0),i]}return[this.getOffsetForAlignment("end"===i?h.end+this.options.scrollPaddingEnd:h.start-this.options.scrollPaddingStart,i,h.size),i]}},this.scrollToOffset=(t,{align:i="start",behavior:s="auto"}={})=>{this._startScroll({index:null,align:i},this.getOffsetForAlignment(t,i),s,"absolute")},this.scrollToIndex=(t,{align:i="auto",behavior:s="auto"}={})=>{const e=this.getOffsetForIndex(t=Math.max(0,Math.min(t,this.options.count-1)),i);if(!e)return;const[h,n]=e;this._startScroll({index:t,align:n},h,s,"absolute")},this.scrollBy=(t,{behavior:i="auto"}={})=>{const s=this.getOffsetForAlignment((this.getCommandWrittenOffset()??this.getScrollOffset())+t,"start");this._startScroll({index:null,align:"start"},s,i,"relative")},this.scrollToEnd=({behavior:t="auto"}={})=>{this.options.count>0?this._startScroll({index:this.options.count-1,align:"end",toEnd:!0},Math.max(this.getMaxScrollOffset(),0),t,"absolute"):this.scrollToOffset(Math.max(this.getTotalSize()-this.getSize(),0),{behavior:t})},this.cancelScroll=()=>{null!=this.rafId&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null},this.getTotalSize=()=>Math.max(this._getLayoutTotalSize()-this._holdOffset,0),this._getLayoutTotalSize=()=>{var t,i;const s=this.getMeasurements();let e;if(0===s.length)e=this.options.paddingStart;else if(1===this.options.lanes){const h=s.length-1,n=null==(t=this._singleLaneMeasurements)?void 0:t.flat;e=null!=n?n[2*h]+n[2*h+1]:(null==(i=s[h])?void 0:i.end)??0}else{const t=Array(this.options.lanes).fill(null);let i=s.length-1;for(;i>=0&&t.some((t=>null===t));){const e=s[i];null===t[e.lane]&&(t[e.lane]=e.end),i--}e=Math.max(...t.filter((t=>null!==t)))}return Math.max(e-this.options.scrollMargin+this.options.paddingEnd,0)},this.takeSnapshot=()=>{const t=[];if(0===this.itemSizeCache.size)return t;const i=this.getMeasurements();for(const s of i)s&&this.itemSizeCache.has(s.key)&&t.push({index:s.index,key:s.key,start:s.start,size:s.size,end:s.end,lane:s.lane});return t},this._scrollToOffset=(t,{adjustments:i,behavior:s}={})=>{const e={target:t+(i??0),smooth:"smooth"===s};return this.pendingWrite=e,this.options.scrollToFn(t-this._holdOffset,{behavior:s,adjustments:i},this),e},this.getCommandWrittenOffset=()=>null===this.scrollState||null===this.pendingWrite||this.pendingWrite.smooth?null:this.pendingWrite.target,this._awaitingCommandReadBack=()=>{const t=this.getCommandWrittenOffset();return!(M()&&this._iosGesture.dragging()||null===t||g(t,this.getScrollOffset()))},this._followOffsetTarget=t=>{null!==this.scrollState&&null==this.scrollState.index&&(this.scrollState.lastTargetOffset+=t)},this.measure=()=>{this.pendingMin=null,this.itemSizeCache.clear(),this.laneAssignments.clear(),this.itemSizeCacheVersion++,this.notify(!1)},this.setOptions(t)}get scrollAdjustments(){return 0}applyScrollAdjustment(t,i){if(0===t)return!1;if(this._followOffsetTarget(t),this._canWriteScroll()){const s=this.getScrollOffset();this._clampedAdjustment=this._clampedBy(s+t);const e=this._scrollToOffset(s,{adjustments:t,behavior:i});return null!==this.scrollOffset&&(this.pendingWrite===e&&(this.scrollOffset+=t),this.scrollOffset<0&&(this.scrollOffset=0)),!0}return this._holdOffset+=t,null!==this.scrollOffset&&(this.scrollOffset+=t),!0}scheduleScrollReconcile(){this.targetWindow?null==this.rafId&&(this.rafId=this.targetWindow.requestAnimationFrame((()=>{this.rafId=null,this.reconcileScroll()}))):this.scrollState=null}getScrollStateTarget(t){const i=t.toEnd?[Math.max(this.getMaxScrollOffset(),0)]:null!=t.index?this.getOffsetForIndex(t.index,t.align):void 0;return i?i[0]:t.lastTargetOffset}reconcileScroll(){if(!this.scrollState)return;if(!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3)return void(this.scrollState=null);if("queued"===this.scrollState.phase)return void this.scheduleScrollReconcile();this.getMeasurements();const t=this.getScrollStateTarget(this.scrollState),i=null==this.scrollState.index?1:this.options.useAnimationFrameWithResizeObserver?3:2,s=t!==this.scrollState.lastTargetOffset;if(!s&&g(t,this.getScrollOffset())){if("smooth"===this.scrollState.phase?this.scrollState.phase="smoothLanded":"smoothFinishing"===this.scrollState.phase&&(this.scrollState.phase="instant"),this.scrollState.stableFrames++,this.scrollState.stableFrames>=i)return this.getScrollOffset()!==t&&this._scrollToOffset(t,{behavior:"auto"}),void(this.scrollState=null)}else if(this.scrollState.stableFrames=0,s){const i=this.getSize()||600,s=Math.abs(t-this.getScrollOffset()),e=P(this.scrollState)&&s>i;this.scrollState.lastTargetOffset=t,e?this.scrollState.phase="smooth":"smooth"===this.scrollState.phase?this.scrollState.phase="smoothFinishing":"smoothLanded"===this.scrollState.phase&&(this.scrollState.phase="instant"),this._scrollToOffset(t,{behavior:e?"smooth":"auto"})}this.scheduleScrollReconcile()}_startScroll(t,i,s,e){this.pendingScrollAnchor=null,this._clampedAdjustment=null;const h=this._iosGesture.tail();if("absolute"===e&&null!==h){if("fling"===h&&(!M()||(void 0!==k?k:k=M()&&"undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("overflow-anchor: auto"))))return this._stopMomentum((()=>{const t=this.scrollState;"queued"!==(null==t?void 0:t.phase)||"fling"!==this._iosGesture.tail()||this._reportedOverscroll||(this._iosGesture.end(),this._flushHoldIfReady(!0),this._writeAwaitingCommand())})),this.scrollState={...t,startedAt:this.now(),lastTargetOffset:i,stableFrames:0,phase:"queued",behavior:s,samples:[]},void this.scheduleScrollReconcile();this._iosGesture.end()}this.scrollState={...t,startedAt:this.now(),lastTargetOffset:i,stableFrames:0,behavior:s,phase:B(s,null!=t.index&&g(i,this.getScrollOffset()))},this._scrollToOffset(i,{behavior:s}),this.scheduleScrollReconcile()}}const H=(t,i,s,e)=>{for(;t<=i;){const h=(t+i)/2|0,n=s(h);if(n<e)t=h+1;else{if(!(n>e))return h;i=h-1}}return t>0?t-1:0};class N{constructor(t,i,s,e){this.bodyEl=t,this.scrollElement=i,this.config=s,this.onIndexesChange=e,this.measuredIndexes=new WeakMap,this.observedRows=new Set,this.resizeObserver=new ResizeObserver((t=>this.resizeRows(t.map((({borderBoxSize:t,target:i})=>({row:i,height:t[0].blockSize})))))),this.indexes=[],this.isResizingRows=!1,this.hasChangeWhileResizing=!1,this.bodyEl.style.overflowAnchor="none",this.scrollMargin=this.measureScrollMargin(),this.virtualizer=new K(this.options()),this.unmount=this.virtualizer._didMount(),this.virtualizer._willUpdate(),this.update()}setConfig(t){this.config=t,this.applyOptions()}sync(){this.updateScrollMargin(),this.observedRows.forEach((t=>{t.isConnected||(this.resizeObserver.unobserve(t),this.observedRows.delete(t))}));const t=this.getRenderedRows();t.forEach((t=>{this.observedRows.has(t)||(this.observedRows.add(t),this.resizeObserver.observe(t))})),this.resizeRows(t.filter((t=>this.measuredIndexes.get(t)!==U(t))).map((t=>({row:t,height:t.getBoundingClientRect().height})))),this.layout()}destroy(){this.unmount(),this.resizeObserver.disconnect(),this.observedRows.clear(),this.bodyEl.style.overflowAnchor="",this.bodyEl.style.paddingTop="",this.bodyEl.style.paddingBottom="",this.getRenderedRows().forEach((t=>t.style.marginTop=""))}applyOptions(){this.virtualizer.setOptions(this.options()),this.virtualizer._willUpdate(),this.update()}update(){if(this.updateScrollMargin())return;const t=this.virtualizer.getVirtualItems().map((({index:t})=>t));(function(t,i){return t.length===i.length&&t.every(((t,s)=>t===i[s]))})(t,this.indexes)||(this.indexes=t,this.onIndexesChange(t)),this.layout()}updateScrollMargin(){const t=this.measureScrollMargin();return!(Math.abs(t-this.scrollMargin)<1||(this.scrollMargin=t,this.applyOptions(),0))}resizeRows(t){this.isResizingRows=!0;try{t.forEach((({row:t,height:i})=>{const s=U(t);t.isConnected&&!Number.isNaN(s)&&0!==i&&(this.measuredIndexes.set(t,s),this.virtualizer.resizeItem(s,i))}))}finally{this.isResizingRows=!1}this.hasChangeWhileResizing&&(this.hasChangeWhileResizing=!1,this.update())}handleChange(){this.isResizingRows?this.hasChangeWhileResizing=!0:this.update()}layout(){const t=new Map(this.virtualizer.getVirtualItems().map((t=>[t.index,t])));let i;this.getRenderedRows().forEach((s=>{const e=U(s),h=t.get(e);if(!h)return;s.index!==e+2&&(s.index=e+2);const n=h.start-this.scrollMargin;void 0===i?(G(this.bodyEl,"paddingTop",n),G(s,"marginTop",0)):G(s,"marginTop",n-i),i=h.end-this.scrollMargin})),void 0===i&&G(this.bodyEl,"paddingTop",0),G(this.bodyEl,"paddingBottom",this.virtualizer.getTotalSize()-(i??0))}getRenderedRows(){return Array.from(this.bodyEl.querySelectorAll("swirl-table-row[data-index]"))}options(){const{estimatedRowHeight:t,keptIndexes:i,overscan:s,rowCount:e}=this.config,h=this.scrollElement instanceof Window;return{count:e,estimateSize:()=>t,getScrollElement:()=>this.scrollElement,initialOffset:()=>this.scrollElement instanceof Window?this.scrollElement.scrollY:this.scrollElement.scrollTop,overscan:s,scrollMargin:this.scrollMargin,rangeExtractor:t=>function(t,i){return[...new Set([...t,...i])].sort(((t,i)=>t-i))}(A(t),i.filter((t=>Number.isInteger(t)&&t>=0&&t<e))),observeElementRect:h?E:I,observeElementOffset:h?W:T,scrollToFn:h?j:q,onChange:()=>this.handleChange()}}measureScrollMargin(){const t=this.bodyEl.getBoundingClientRect().top;return this.scrollElement instanceof Window?t+this.scrollElement.scrollY:t-this.scrollElement.getBoundingClientRect().top+this.scrollElement.scrollTop}}function U(t){return Number(t.dataset.index)}function G(t,i,s){const e=s>0?s+"px":"";t.style[i]!==e&&(t.style[i]=e)}const $={end:"Dropped. Final position in table: {position} of {rowCount}.",initial:"Press space to move the row.",moved:"Current position in table: {position} of {rowCount}.",start:"Row grabbed. Current position in table: {position} of {rowCount}. Press up and down arrow keys to change position, Space to drop."},J=t(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.dropRow=s(this,"dropRow",7),this.virtualizationRowsChange=s(this,"virtualizationRowsChange",7),this.dragDropInstructions=$,this.emptyStateLabel="No results found.",this.virtualizationEstimatedRowHeight=56,this.virtualizationOverscan=10,this.virtualizationKeepRowsRendered=[],this.liveRegionText="",this.updateLayout=w((async()=>{this.resetCellStyles(),this.resetColumnStyles(),this.resetEmptyRowStyles(),this.resetRowGroupStyles(),this.layoutEmptyRow(),this.layoutRowGroups(),this.layOutCellsAndColumns(),this.updateScrolledState()}),16,{leading:!0}),this.onScroll=()=>{this.updateScrolledState()},this.onFocus=t=>{if(this.trackFocusedRow(t.target),this.movingViaKeyboard){const t=this.el.querySelector(".table-row--moving");t&&this.focusDragHandleOfRow(t)}const i=!!t.target?.closest(this.dragDropHandle);""===this.liveRegionText&&i&&this.updateLiveRegionText("initial")},this.onBlur=t=>{const i=t.relatedTarget;this.el.contains(i)||this.trackFocusedRow(null);const s=!!i?.closest(this.dragDropHandle);this.el.contains(i)&&s||""!==this.liveRegionText&&this.updateLiveRegionText()},this.onKeyDown=t=>{if(!this.enableDragDrop)return;const i=t.target?.closest("swirl-table-row");t.target?.closest(this.dragDropHandle)&&("Space"===t.code?(t.preventDefault(),t.stopPropagation(),this.toggleKeyboardMove(i)):"ArrowUp"===t.code?(t.preventDefault(),t.stopPropagation(),this.moveRow(i,"up")):"ArrowDown"===t.code?(t.preventDefault(),t.stopPropagation(),this.moveRow(i,"down")):"Escape"===t.code&&(t.preventDefault(),t.stopPropagation(),this.cancelKeyboardMove()))}}async componentDidLoad(){this.setupIntersectionObserver(),this.setupMutationObservers(),this.updateVirtualizer(),queueMicrotask((()=>{this.setupDragDrop()}))}disconnectedCallback(){this.intersectionObserver?.disconnect(),this.columnMutationObserver?.disconnect(),this.rowMutationObserver?.disconnect(),this.sortable?.destroy(),this.destroyVirtualizer()}handleVirtualizationChange(){this.updateVirtualizer()}get virtualizerConfig(){if(this.enableVirtualization&&this.virtualizationRowCount)return{estimatedRowHeight:this.virtualizationEstimatedRowHeight,keptIndexes:void 0===this.focusedRowIndex?this.virtualizationKeepRowsRendered??[]:[...this.virtualizationKeepRowsRendered??[],this.focusedRowIndex],overscan:this.virtualizationOverscan,rowCount:this.virtualizationRowCount}}updateVirtualizer(){if(!this.bodyEl)return;const t=this.virtualizerConfig;if(!t){const t=!!this.virtualizer;return this.destroyVirtualizer(),void(this.enableVirtualization&&t&&queueMicrotask((()=>this.virtualizationRowsChange.emit({indexes:[]}))))}if(this.virtualizer)return this.virtualizer.setConfig(t),void(this.virtualizer.scrollElement===window&&this.updateScrollParent());this.bodyEl.style.paddingBottom=t.rowCount*t.estimatedRowHeight+"px",this.virtualizer=new N(this.bodyEl,a(this.el),t,(t=>queueMicrotask((()=>this.virtualizationRowsChange.emit({indexes:t})))))}destroyVirtualizer(){this.virtualizer?.destroy(),this.virtualizer=void 0}handleEnableDragDropChange(){queueMicrotask((()=>{this.setupDragDrop()}))}setupIntersectionObserver(){this.intersectionObserver=new IntersectionObserver(this.onVisibilityChange.bind(this),{threshold:0}),this.intersectionObserver.observe(this.container)}setupMutationObservers(){this.columnMutationObserver=new MutationObserver((t=>{t.some((t=>t.addedNodes.length||t.removedNodes.length))&&this.updateLayout()})),this.columnMutationObserver.observe(this.headerEl,{childList:!0,subtree:!0}),this.rowMutationObserver=new MutationObserver((t=>{const i=t.some((t=>t.addedNodes.length||t.removedNodes.length)),s=t.some((t=>"attributes"===t.type));i&&(this.updateEmptyState(),this.setupDragDrop()),(i||s)&&this.syncVirtualizedRows({layOutCells:i})})),this.startRowMutationObserver()}startRowMutationObserver(){this.rowMutationObserver?.observe(this.bodyEl,{attributeFilter:["data-index"],childList:!0,subtree:!0})}stopRowMutationObserver(){this.rowMutationObserver?.disconnect()}setupDragDrop(){if(this.sortable&&(this.sortable.destroy(),this.sortable=void 0),this.enableDragDrop){if(this.el.querySelector("swirl-table-row-group"))return void console.warn('[Swirl] Drag & drop is not yet supported for swirl-tables using the "swirl-table-row-group" component.');if(!this.dragDropHandle)return void console.warn('[Swirl] swirl-table required the "dragDropHandle" prop to be set when drag & drop is enabled.');const t=this.el.querySelector('[slot="rows"]');this.dragDropContainer="SWIRL-TABLE-ROW"!==t?.tagName?t??this.bodyEl:this.bodyEl,this.sortable=new o(this.dragDropContainer,{animation:100,direction:"vertical",handle:this.dragDropHandle,fallbackOnBody:!0,group:"swirl-table-"+(""+Math.random()).substring(2),onStart:()=>{this.stopRowMutationObserver()},onEnd:t=>{t.stopPropagation();const{to:i,newIndex:s,oldIndex:e,item:h}=t;this.dropRow.emit({newIndex:s,oldIndex:e,item:h,itemId:h.id??h.querySelector(":scope > swirl-table-row").id,newNextSiblingItemId:s<i.children.length-1?i.children[s+1].id:void 0,newPrevSiblingItemId:s>0?i.children[s-1].id:void 0}),this.startRowMutationObserver()}})}}async onVisibilityChange(t){t.some((t=>t.isIntersecting))&&setTimeout((async()=>{this.updateScrollParent(),await this.updateLayout()}),100)}updateScrollParent(){this.virtualizer&&a(this.el)!==this.virtualizer.scrollElement&&(this.destroyVirtualizer(),this.updateVirtualizer())}async componentDidRender(){await this.updateLayout(),this.updateEmptyState()}async onWindowResize(){await this.updateLayout()}async rerender(){await this.updateLayout(),this.updateEmptyState()}resetEmptyRowStyles(){const t=this.el.querySelector(".table__empty-row");t&&(t.style.width="")}resetRowGroupStyles(){Array.from(this.el.querySelectorAll("swirl-table-row-group")).forEach((t=>{t.shadowRoot.querySelector(".table-row-group__header-row")&&(t.shadowRoot.querySelector(".table-row-group__header-row").style.width="")}))}resetColumnStyles(){this.getColumns().forEach((t=>{t.classList.remove("table-column--has-shadow","table-column--is-sticky","table-column--is-sticky-right"),t.style.right="",t.style.left="",t.style.position="",t.style.zIndex=""}))}resetCellStyles(){this.getCells().forEach((t=>{t.classList.remove("table-cell--has-shadow","table-cell--is-sticky","table-cell--is-sticky-right"),t.style.flex="",t.style.left="",t.style.right="",t.style.position="",t.style.zIndex=""}))}updateScrolledState(){const t=u();if(void 0===this.container)return;const i=this.container.scrollWidth>this.container.clientWidth,s=this.container.scrollLeft>0,e=Math.ceil(this.container.clientWidth+this.container.scrollLeft)>=Math.floor(this.container.scrollWidth);i!==this.scrollable&&(i&&!t?this.container.classList.add("table__container--scrollable"):this.container.classList.remove("table__container--scrollable")),s!==this.scrolled&&(s&&!t?this.container.classList.add("table__container--scrolled"):this.container.classList.remove("table__container--scrolled")),e!==this.scrolledToEnd&&(e&&!t?this.container.classList.add("table__container--scrolled-to-end"):this.container.classList.remove("table__container--scrolled-to-end"))}getColumns(){return Array.from(this.el.querySelectorAll("swirl-table-column"))}getCells(){return Array.from(this.el.querySelectorAll("swirl-table-cell"))}layoutEmptyRow(){const t=this.el.querySelector(".table__empty-row");if(!t)return;const i=this.el.querySelector(".table__container").scrollWidth+"px";t.style.width=i}layoutRowGroups(){const t=Array.from(this.el.querySelectorAll("swirl-table-row-group")),i=this.el.querySelector(".table__container")?.scrollWidth+"px";t.forEach((t=>{t.shadowRoot.querySelector(".table-row-group__header-row")&&(t.shadowRoot.querySelector(".table-row-group__header-row").style.width=i)}))}layOutCellsAndColumns(){const t=this.getColumns(),i=this.getCells(),s=t.map(((i,s)=>this.calculateColumnProperties(i,t,s)));t.forEach(((e,h)=>{this.getCellsForColumn(i,t,h).forEach((t=>this.applyCellStyles(t,e,s[h]))),this.applyColumnStyles(e,s[h])}))}getCellsForColumn(t,i,s){return t.filter(((t,e)=>(s-e)%i.length==0))}calculateColumnProperties(t,i,s){return{leftOffsetForStickyColumn:t.sticky?this.getLeftOffsetForStickyColumn(i,s):0,columnWidth:t.getBoundingClientRect().width+"px",isLastColumnSticky:t.sticky&&i.length===s+1,hasShadowRight:t.sticky&&!this.hasStickyColumnsToRight(i,s)}}applyCellStyles(t,i,s){const{leftOffsetForStickyColumn:e,columnWidth:h,isLastColumnSticky:n,hasShadowRight:l}=s;t.style.flex=h?"0 0 "+h:"",u()||(i.sticky&&!n&&(t.classList.add("table-cell--is-sticky"),t.style.left=e+"px",l&&t.classList.add("table-cell--has-shadow-right")),n&&t.classList.add("table-cell--is-sticky-right","table-cell--has-shadow-left"))}applyColumnStyles(t,i){if(u())return;const{leftOffsetForStickyColumn:s,isLastColumnSticky:e,hasShadowRight:h}=i;t.sticky&&!e&&(t.classList.add("table-column--is-sticky"),t.style.left=s+"px",h&&t.classList.add("table-column--has-shadow-right")),e&&t.classList.add("table-column--is-sticky-right","table-column--has-shadow-left")}getLeftOffsetForStickyColumn(t,i){return t.slice(0,i).reduce(((t,i)=>{if(i.sticky)return t+i.getBoundingClientRect().width}),0)}hasStickyColumnsToRight(t,i){return t.slice(i+1,t.length-1).some((t=>t.sticky))}updateEmptyState(){if(this.enableVirtualization&&this.virtualizationRowCount)return void(this.empty=!1);const t=this.el.querySelector('[slot="rows"]');this.empty=!t||0===t.children.length}updateLiveRegionText(t,i={}){let s=t?this.dragDropInstructions[t]:"";for(const[t,e]of Object.entries(i??{}))s=s.replaceAll(`{${t}}`,e+"");s!==this.liveRegionText&&(this.liveRegionText=s)}toggleKeyboardMove(t){this.movingViaKeyboard?this.endKeyboardMove(t):this.startKeyboardMove(t)}startKeyboardMove(t){this.movingViaKeyboard=!0,this.positionBeforeKeyboardMove=Array.from(this.dragDropContainer.children).indexOf(t),t.classList.add("table-row--moving"),this.updateLiveRegionText("start",{position:Array.from(this.dragDropContainer.children).indexOf(t)+1,rowCount:this.dragDropContainer.children.length})}endKeyboardMove(t){this.movingViaKeyboard=!1,t.classList.remove("table-row--moving"),this.updateLiveRegionText("end",{position:Array.from(this.dragDropContainer.children).indexOf(t)+1,rowCount:this.dragDropContainer.children.length}),this.dropRow.emit({item:t,newIndex:Array.from(this.dragDropContainer.children).indexOf(t),oldIndex:this.positionBeforeKeyboardMove,itemId:t.id,newNextSiblingItemId:Array.from(this.dragDropContainer.children).indexOf(t)<this.dragDropContainer.children.length-1?this.dragDropContainer.children[Array.from(this.dragDropContainer.children).indexOf(t)+1].id:void 0,newPrevSiblingItemId:Array.from(this.dragDropContainer.children).indexOf(t)>0?this.dragDropContainer.children[Array.from(this.dragDropContainer.children).indexOf(t)-1].id:void 0}),this.positionBeforeKeyboardMove=void 0}cancelKeyboardMove(){if(!this.movingViaKeyboard)return;const t=this.el.querySelector(".table-row--moving");t&&(t.classList.remove("table-row--moving"),this.movingViaKeyboard=!1,void 0!==this.positionBeforeKeyboardMove&&this.dragDropContainer.insertBefore(t,this.dragDropContainer.children[this.positionBeforeKeyboardMove]))}moveRow(t,i){if(!this.movingViaKeyboard)return;let s;if("up"===i){const i=Array.from(this.dragDropContainer.children).indexOf(t);s=Math.max(0,i-1),this.dragDropContainer.insertBefore(t,this.dragDropContainer.children[s])}else{const i=Array.from(this.dragDropContainer.children).indexOf(t);s=Math.min(this.dragDropContainer.children.length-1,i+1),this.dragDropContainer.insertBefore(t,this.dragDropContainer.children[s+1])}this.updateLiveRegionText("moved",{position:s+1,rowCount:this.dragDropContainer.children.length}),this.focusDragHandleOfRow(t)}focusDragHandleOfRow(t){const i=c(t,this.dragDropHandle)?.[0];"BUTTON"===i.tagName?i.focus():i.querySelector("button")?.focus()}syncVirtualizedRows({layOutCells:t}){this.virtualizer&&(this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within")),this.virtualizer.sync(),t&&this.updateLayout())}trackFocusedRow(t){if(!this.enableVirtualization)return;const i=t?.closest("swirl-table-row[data-index]")?.dataset.index,s=void 0===i?void 0:Number(i);s!==this.focusedRowIndex&&(this.focusedRowIndex=s,this.updateVirtualizer())}render(){const t=!!this.el.querySelector('[slot="empty"]'),i=r("table",{"table--show-empty-state":this.empty&&!this.loading,"table--keyboard-move":this.movingViaKeyboard});return e(h,{key:"24e14d3eb739219aa9965fe16ccff5e9dae28180"},e("div",{key:"25deaf84f1bb1131977e6e07f45ac2301585354d",class:i},this.enableDragDrop&&e("swirl-visually-hidden",{key:"277292ebfaa8c1ada6c5c982b214efbda5f2f8a9"},e("span",{key:"e07ea9745ee40064160001ed0d702971cce78efa","aria-live":"assertive"},this.liveRegionText)),e("div",{key:"f6919c9d48793c1abba7901b4365817ae7dfc5dc",class:"table__container",onFocusin:this.onFocus,onFocusout:this.onBlur,onKeyDown:this.onKeyDown,onScroll:this.onScroll,ref:t=>this.container=t,tabIndex:-1},e("div",{key:"b7d1bb696755df6fd20983eebf6b800685a59983","aria-describedby":this.caption?"caption":void 0,"aria-label":this.label,"aria-rowcount":this.enableVirtualization&&this.virtualizationRowCount?this.virtualizationRowCount+1:void 0,role:"table",class:"table__table"},this.caption&&e("swirl-visually-hidden",{key:"013e2aff85772e44a3cdbb67dc4479d8eb581ffc"},e("div",{key:"9f1b0dda1fe39b823e6df87dae2285e71a738265",id:"caption"},this.caption)),e("div",{key:"9cd533c163bd42c8ebb4f641a91860170a2ca3e3",role:"rowgroup"},e("div",{key:"0516399b0ed45a6f8e817fa9f342a188738fca0d",class:"table__header","aria-rowindex":this.enableVirtualization?1:void 0,ref:t=>this.headerEl=t,role:"row"},e("slot",{key:"9924e00f3ac41423e4cf183ad3f0c993f9235d83",name:"columns"}))),e("div",{key:"0be013c95ef6910e4a27b388282403843cd520ea",class:"table__body",ref:t=>this.bodyEl=t},e("slot",{key:"f5660dcec786b0091ec3cbe38407948173146147",name:"rows"}),e("div",{key:"db077c06ab60df00e149468bb54f52ebeb40cd66",class:"table__empty-row",role:"row"},e("div",{key:"d7b514fe706e96437496ee4f7f5b2b0052943629","aria-colspan":this.getColumns().length,class:"table__empty-row-cell",role:"cell"},e("slot",{key:"8b1c1f506c3a5479def5c178856900103a05e1d6",name:"empty"}),!t&&e("swirl-text",{key:"f94bccc0907f8052c63cebdfb7b99c8708d1ab76",align:"center",size:"sm"},this.emptyStateLabel))))))))}get el(){return this}static get watchers(){return{enableVirtualization:[{handleVirtualizationChange:0}],virtualizationRowCount:[{handleVirtualizationChange:0}],virtualizationEstimatedRowHeight:[{handleVirtualizationChange:0}],virtualizationOverscan:[{handleVirtualizationChange:0}],virtualizationKeepRowsRendered:[{handleVirtualizationChange:0}],enableDragDrop:[{handleEnableDragDropChange:0}]}}static get style(){return".sc-swirl-table-h{--swirl-table-shadow-rgba:rgba(23, 23, 23, 0.2);position:relative;display:block}.sc-swirl-table-h *.sc-swirl-table{box-sizing:border-box}html.theme-dark.sc-swirl-table-h,html.theme-dark .sc-swirl-table-h{--swirl-table-shadow-rgba:rgba(0, 0, 0, 0.2)}.table--keyboard-move.sc-swirl-table:focus-within{--swirl-table-moving-row-border:var(--s-border-width-default) solid var(--s-border-highlight)}.table--show-empty-state.sc-swirl-table .table__empty-row.sc-swirl-table{display:flex}.table__container.sc-swirl-table{position:relative;overflow:auto;width:100%}.table__container--scrolled.sc-swirl-table{--swirl-table-sticky-right-shadow:4px 0 16px -4px var(--swirl-table-shadow-rgba), 2px 0 4px -2px var(--swirl-table-shadow-rgba)}.table__container--scrollable.sc-swirl-table:not(.table__container--scrolled-to-end){--swirl-table-sticky-left-shadow:0px 4px 16px 0px var(--swirl-table-shadow-rgba), 0px 1px 4px 0px var(--swirl-table-shadow-rgba)}.table__table.sc-swirl-table{width:-moz-max-content;width:max-content;min-width:max(20rem, 100%)}.table__header.sc-swirl-table-s>*,.table__header .sc-swirl-table-s>*{display:flex}.table__empty-row.sc-swirl-table{display:none}.table__empty-row-cell.sc-swirl-table{display:flex;overflow:auto;padding-top:var(--s-space-8);padding-right:var(--s-space-16);padding-bottom:var(--s-space-8);padding-left:var(--s-space-16);flex-basis:0;flex-grow:1;flex-shrink:1;align-items:center;background-color:var(--s-surface-default)}.table__empty-row-cell.sc-swirl-table>*.sc-swirl-table{flex-grow:1}"}},[262,"swirl-table",{caption:[1],dragDropHandle:[1,"drag-drop-handle"],dragDropInstructions:[16],emptyStateLabel:[1,"empty-state-label"],enableDragDrop:[4,"enable-drag-drop"],label:[1],loading:[4],enableVirtualization:[4,"enable-virtualization"],virtualizationRowCount:[2,"virtualization-row-count"],virtualizationEstimatedRowHeight:[2,"virtualization-estimated-row-height"],virtualizationOverscan:[2,"virtualization-overscan"],virtualizationKeepRowsRendered:[16],empty:[32],liveRegionText:[32],scrollable:[32],scrolled:[32],scrolledToEnd:[32],rerender:[64]},[[9,"resize","onWindowResize"]],{enableVirtualization:[{handleVirtualizationChange:0}],virtualizationRowCount:[{handleVirtualizationChange:0}],virtualizationEstimatedRowHeight:[{handleVirtualizationChange:0}],virtualizationOverscan:[{handleVirtualizationChange:0}],virtualizationKeepRowsRendered:[{handleVirtualizationChange:0}],enableDragDrop:[{handleEnableDragDropChange:0}]}]),Q=J,X=function(){"undefined"!=typeof customElements&&["swirl-table","swirl-text","swirl-visually-hidden"].forEach((t=>{switch(t){case"swirl-table":customElements.get(n(t))||customElements.define(n(t),J);break;case"swirl-text":customElements.get(n(t))||d();break;case"swirl-visually-hidden":customElements.get(n(t))||f()}}))};export{Q as SwirlTable,X as defineCustomElement}
@@ -1,7 +1,7 @@
1
1
  import { r as registerInstance, c as createEvent, h, a as Host, d as getElement } from './index-Dz56lJ37.js';
2
2
  import { g as getDefaultExportFromCjs, c as classnames } from './index-orsBiyT_.js';
3
3
  import { S as Sortable } from './sortable.esm-CMrz6687.js';
4
- import { d as debounce$1, u as getScrollParent, i as isMobileViewport, q as querySelectorAllDeep } from './utils-D23VxAsw.js';
4
+ import { u as getScrollParent, i as isMobileViewport, q as querySelectorAllDeep } from './utils-D23VxAsw.js';
5
5
 
6
6
  var dist;
7
7
  var hasRequiredDist;
@@ -2263,10 +2263,6 @@ const SwirlTable = class {
2263
2263
  */
2264
2264
  this.virtualizationKeepRowsRendered = [];
2265
2265
  this.liveRegionText = "";
2266
- this.triggerRerender = debounce$1(async () => {
2267
- await this.updateLayout();
2268
- this.updateEmptyState();
2269
- }, 0, true);
2270
2266
  this.updateLayout = debouncePromise(async () => {
2271
2267
  this.resetCellStyles();
2272
2268
  this.resetColumnStyles();
@@ -2446,7 +2442,7 @@ const SwirlTable = class {
2446
2442
  this.setupDragDrop();
2447
2443
  }
2448
2444
  if (rowWasAddedOrRemoved || rowIndexChanged) {
2449
- this.syncVirtualizedRows();
2445
+ this.syncVirtualizedRows({ layOutCells: rowWasAddedOrRemoved });
2450
2446
  }
2451
2447
  });
2452
2448
  this.startRowMutationObserver();
@@ -2543,7 +2539,10 @@ const SwirlTable = class {
2543
2539
  * Force a re-render of the table
2544
2540
  */
2545
2541
  async rerender() {
2546
- this.triggerRerender();
2542
+ // updateLayout is debounced with a trailing call, so a row that loads
2543
+ // while a layout runs still gets laid out.
2544
+ await this.updateLayout();
2545
+ this.updateEmptyState();
2547
2546
  }
2548
2547
  resetEmptyRowStyles() {
2549
2548
  const emptyRow = this.el.querySelector(".table__empty-row");
@@ -2645,11 +2644,14 @@ const SwirlTable = class {
2645
2644
  layOutCellsAndColumns() {
2646
2645
  const columns = this.getColumns();
2647
2646
  const cells = this.getCells();
2647
+ // Measure every column before sizing any cell. The table is as wide as its
2648
+ // widest row, so sizing one column's cells moves the columns not measured
2649
+ // yet.
2650
+ const columnProperties = columns.map((column, colIndex) => this.calculateColumnProperties(column, columns, colIndex));
2648
2651
  columns.forEach((column, colIndex) => {
2649
2652
  const cellsOfColumn = this.getCellsForColumn(cells, columns, colIndex);
2650
- const columnProperties = this.calculateColumnProperties(column, columns, colIndex);
2651
- cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties));
2652
- this.applyColumnStyles(column, columnProperties);
2653
+ cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties[colIndex]));
2654
+ this.applyColumnStyles(column, columnProperties[colIndex]);
2653
2655
  });
2654
2656
  }
2655
2657
  getCellsForColumn(cells, columns, colIndex) {
@@ -2819,13 +2821,19 @@ const SwirlTable = class {
2819
2821
  * Measures and positions rows after they were added, removed or re-indexed.
2820
2822
  * The focused row's index is read again first, as it changes when e.g. a row
2821
2823
  * is inserted above it.
2824
+ *
2825
+ * Added rows and cells are laid out too: a row calls `rerender()` only when
2826
+ * it first loads, so cells added to a drawn row would get no width.
2822
2827
  */
2823
- syncVirtualizedRows() {
2828
+ syncVirtualizedRows({ layOutCells }) {
2824
2829
  if (!this.virtualizer) {
2825
2830
  return;
2826
2831
  }
2827
2832
  this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within"));
2828
2833
  this.virtualizer.sync();
2834
+ if (layOutCells) {
2835
+ this.updateLayout();
2836
+ }
2829
2837
  }
2830
2838
  /** Keeps the focused row drawn, so it doesn't lose focus. */
2831
2839
  trackFocusedRow(target) {
@@ -2846,9 +2854,9 @@ const SwirlTable = class {
2846
2854
  "table--show-empty-state": this.empty && !this.loading,
2847
2855
  "table--keyboard-move": this.movingViaKeyboard,
2848
2856
  });
2849
- return (h(Host, { key: '5fd51d538c87dce53702fa483657035e251d3507' }, h("div", { key: '7ec3b5830bcc7b0dfc5324f554b80b442b7bc290', class: className }, this.enableDragDrop && (h("swirl-visually-hidden", { key: '2928eb420bb8cad6477917a1883aeeffda3260eb' }, h("span", { key: 'fc615afed57d8dbfbf636f9e8feb9c6ef76ae72b', "aria-live": "assertive" }, this.liveRegionText))), h("div", { key: '4b7d5b9c4691d1828d0c24fc635d8e7c5dc48cf4', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, h("div", { key: '9669435927eb4944290b4fdcb4083ef1473c000e', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
2857
+ return (h(Host, { key: '24e14d3eb739219aa9965fe16ccff5e9dae28180' }, h("div", { key: '25deaf84f1bb1131977e6e07f45ac2301585354d', class: className }, this.enableDragDrop && (h("swirl-visually-hidden", { key: '277292ebfaa8c1ada6c5c982b214efbda5f2f8a9' }, h("span", { key: 'e07ea9745ee40064160001ed0d702971cce78efa', "aria-live": "assertive" }, this.liveRegionText))), h("div", { key: 'f6919c9d48793c1abba7901b4365817ae7dfc5dc', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, h("div", { key: 'b7d1bb696755df6fd20983eebf6b800685a59983', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
2850
2858
  ? this.virtualizationRowCount + 1
2851
- : undefined, role: "table", class: "table__table" }, this.caption && (h("swirl-visually-hidden", { key: '6806eedf8d1aa22b3ee8f51736032ead77a502cc' }, h("div", { key: 'bea8e3d31ba2e81461ff8e4d056ee3ea718707ea', id: "caption" }, this.caption))), h("div", { key: '386fa4a8c2d31471a43580b62ad1003cfbcf224d', role: "rowgroup" }, h("div", { key: 'aebae228fab2eb7d4a688bb50ee069e7138001c1', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, h("slot", { key: '111dd938896772934ba589167ee254936c8bbe9d', name: "columns" }))), h("div", { key: '7a6b87e277bd50dfc8c5ff3e680aabe95384bb7f', class: "table__body", ref: (el) => (this.bodyEl = el) }, h("slot", { key: 'a766d1ff38bf321fac0b3c52a686d57d2b4551ea', name: "rows" }), h("div", { key: 'a26bec40f580546c85e3dd1007c913d53da4c18a', class: "table__empty-row", role: "row" }, h("div", { key: 'cd9793a4e353a88bfb04658354f247ddfd621e20', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, h("slot", { key: '3c79cf8327876b4be8e237e6d43c918d6f6dbda0', name: "empty" }), !hasEmptyStateSlotAssignment && (h("swirl-text", { key: '6f2d3365cd41f0242f8dc6720aed3c5bc1edf4fb', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
2859
+ : undefined, role: "table", class: "table__table" }, this.caption && (h("swirl-visually-hidden", { key: '013e2aff85772e44a3cdbb67dc4479d8eb581ffc' }, h("div", { key: '9f1b0dda1fe39b823e6df87dae2285e71a738265', id: "caption" }, this.caption))), h("div", { key: '9cd533c163bd42c8ebb4f641a91860170a2ca3e3', role: "rowgroup" }, h("div", { key: '0516399b0ed45a6f8e817fa9f342a188738fca0d', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, h("slot", { key: '9924e00f3ac41423e4cf183ad3f0c993f9235d83', name: "columns" }))), h("div", { key: '0be013c95ef6910e4a27b388282403843cd520ea', class: "table__body", ref: (el) => (this.bodyEl = el) }, h("slot", { key: 'f5660dcec786b0091ec3cbe38407948173146147', name: "rows" }), h("div", { key: 'db077c06ab60df00e149468bb54f52ebeb40cd66', class: "table__empty-row", role: "row" }, h("div", { key: 'd7b514fe706e96437496ee4f7f5b2b0052943629', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, h("slot", { key: '8b1c1f506c3a5479def5c178856900103a05e1d6', name: "empty" }), !hasEmptyStateSlotAssignment && (h("swirl-text", { key: 'f94bccc0907f8052c63cebdfb7b99c8708d1ab76', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
2852
2860
  }
2853
2861
  get el() { return getElement(this); }
2854
2862
  static get watchers() { return {