@toolbox-web/grid 2.16.3 → 2.16.4

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.
Files changed (60) hide show
  1. package/index.js +1 -1
  2. package/lib/features/registry.js +1 -1
  3. package/lib/features/registry.js.map +1 -1
  4. package/lib/plugins/clipboard/index.js +1 -1
  5. package/lib/plugins/clipboard/index.js.map +1 -1
  6. package/lib/plugins/column-virtualization/index.js +1 -1
  7. package/lib/plugins/column-virtualization/index.js.map +1 -1
  8. package/lib/plugins/context-menu/index.js +1 -1
  9. package/lib/plugins/context-menu/index.js.map +1 -1
  10. package/lib/plugins/editing/index.js +1 -1
  11. package/lib/plugins/editing/index.js.map +1 -1
  12. package/lib/plugins/export/index.js +1 -1
  13. package/lib/plugins/export/index.js.map +1 -1
  14. package/lib/plugins/filtering/index.js +1 -1
  15. package/lib/plugins/filtering/index.js.map +1 -1
  16. package/lib/plugins/grouping-columns/index.js +1 -1
  17. package/lib/plugins/grouping-columns/index.js.map +1 -1
  18. package/lib/plugins/grouping-rows/index.js +1 -1
  19. package/lib/plugins/grouping-rows/index.js.map +1 -1
  20. package/lib/plugins/master-detail/index.js +1 -1
  21. package/lib/plugins/master-detail/index.js.map +1 -1
  22. package/lib/plugins/multi-sort/index.js +1 -1
  23. package/lib/plugins/multi-sort/index.js.map +1 -1
  24. package/lib/plugins/pinned-columns/index.js +1 -1
  25. package/lib/plugins/pinned-columns/index.js.map +1 -1
  26. package/lib/plugins/pinned-rows/index.js +1 -1
  27. package/lib/plugins/pinned-rows/index.js.map +1 -1
  28. package/lib/plugins/pivot/index.js +1 -1
  29. package/lib/plugins/pivot/index.js.map +1 -1
  30. package/lib/plugins/print/index.js +1 -1
  31. package/lib/plugins/print/index.js.map +1 -1
  32. package/lib/plugins/reorder-columns/index.js +1 -1
  33. package/lib/plugins/reorder-columns/index.js.map +1 -1
  34. package/lib/plugins/reorder-rows/index.js +1 -1
  35. package/lib/plugins/reorder-rows/index.js.map +1 -1
  36. package/lib/plugins/responsive/index.js +1 -1
  37. package/lib/plugins/responsive/index.js.map +1 -1
  38. package/lib/plugins/row-drag-drop/index.js +1 -1
  39. package/lib/plugins/row-drag-drop/index.js.map +1 -1
  40. package/lib/plugins/selection/index.js +1 -1
  41. package/lib/plugins/selection/index.js.map +1 -1
  42. package/lib/plugins/server-side/index.js +1 -1
  43. package/lib/plugins/server-side/index.js.map +1 -1
  44. package/lib/plugins/shell/index.js +1 -1
  45. package/lib/plugins/shell/index.js.map +1 -1
  46. package/lib/plugins/sticky-rows/index.js +1 -1
  47. package/lib/plugins/sticky-rows/index.js.map +1 -1
  48. package/lib/plugins/tooltip/index.js +1 -1
  49. package/lib/plugins/tooltip/index.js.map +1 -1
  50. package/lib/plugins/tree/index.js +1 -1
  51. package/lib/plugins/tree/index.js.map +1 -1
  52. package/lib/plugins/undo-redo/index.js +1 -1
  53. package/lib/plugins/undo-redo/index.js.map +1 -1
  54. package/lib/plugins/visibility/index.js +1 -1
  55. package/lib/plugins/visibility/index.js.map +1 -1
  56. package/package.json +1 -1
  57. package/umd/grid.all.umd.js +1 -1
  58. package/umd/grid.all.umd.js.map +1 -1
  59. package/umd/grid.umd.js +1 -1
  60. package/umd/grid.umd.js.map +1 -1
package/index.js CHANGED
@@ -1 +1 @@
1
- function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}const t="TBW021",o="TBW041",n="TBW061",r="TBW062",i="TBW072",s="TBW073",l="TBW074",a="TBW080",c="TBW090",d="TBW091",h="TBW092",u="TBW093",g="TBW100",f="TBW110",p="TBW111",w="TBW112",m="TBW113",b="TBW114",v="TBW140",C="TBW141",y="TBW142",_="TBW143";function S(t,o,n,r){return`${e(n,r)} ${t}: ${o}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}function R(e,t,o,n){throw new Error(S(e,t,o,n))}function E(e,t,o,n){console.warn(S(e,t,o,n))}function P(e,t,o,n){console.debug(S(e,t,o,n))}function x(e,t,o,n){console.error(S(e,t,o,n))}const A=/{{\s*([^}]+)\s*}}/g,T="__DG_EMPTY__",H=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,M="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),L=new RegExp(`__(proto|defineGetter|defineSetter)|${M.slice(3).join("|")}|this\\b`),k=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing".split("|")),O=/^on\w+$/i,D=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),I=/^\s*(javascript|vbscript|data|blob):/i;function z(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const n of o){const e=n.tagName.toLowerCase();if(k.has(e)){t.push(n);continue}if("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI){if(Array.from(n.attributes).some(e=>O.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}}const o=[];for(const t of n.attributes){const e=t.name.toLowerCase();O.test(e)?o.push(t.name):(D.has(e)&&I.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function N(e,t){const o=function(e){const t=[];let o=0;for(;o<e.length;){const n=e[o];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&o+1<e.length&&e[o+1]>="0"&&e[o+1]<="9"){const n=o;for(;o<e.length&&(e[o]>="0"&&e[o]<="9"||"."===e[o]);)o++;t.push({type:"num",v:Number(e.slice(n,o))});continue}if("'"===n){let n="";for(o++;o<e.length&&"'"!==e[o];)n+=e[o++];if(o>=e.length)return null;o++,t.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=o;for(;o<e.length&&/[\w$.]/.test(e[o]);)o++;t.push({type:"id",v:e.slice(n,o)});continue}if(o+2<e.length){const n=e.slice(o,o+3);if("==="===n||"!=="===n){t.push({type:"op",v:n}),o+=3;continue}}if(o+1<e.length){const n=e.slice(o,o+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){t.push({type:"op",v:n}),o+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;t.push({type:"op",v:n}),o++}else o++}return t}(e);if(!o)return;const n=o;let r=0;function i(){return n[r]}function s(){return n[r++]}function l(e,t){const o=i();return!!o&&(o.type===e&&(void 0===t||o.v===t))}function a(){const e=function(){let e=c();for(;l("op","||");)s(),e=e||c();return e}();if(l("op","?")){s();const t=a();if(!l("op",":"))return;s();const o=a();return e?t:o}return e}function c(){let e=d();for(;l("op","&&");)s(),e=e&&d();return e}function d(){let e=h();for(;;){const t=i();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===h();else if("!=="===t.v)s(),e=e!==h();else if("=="===t.v)s(),e=e==h();else{if("!="!==t.v)break;s(),e=e!=h()}}return e}function h(){let e=u();for(;;){const t=i();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<u();else if(">"===t.v)s(),e=e>u();else if("<="===t.v)s(),e=e<=u();else{if(">="!==t.v)break;s(),e=e>=u()}}return e}function u(){let e=g();for(;;){const t=i();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=g();else{if("-"!==t.v)break;s(),e-=g()}}return e}function g(){let e=f();for(;;){const t=i();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=f();else if("/"===t.v)s(),e/=f();else{if("%"!==t.v)break;s(),e%=f()}}return e}function f(){return l("op","!")?(s(),!f()):p()}function p(){const e=i();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const o=e.slice(4);return t.row?t.row[o]:void 0}return"row"===e?t.row:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=a();return l("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-p()):void 0}}const w=a();return r<n.length?void 0:w}function q(e,t){if(!e||-1===e.indexOf("{{"))return e;const o=[],n=e.replace(A,(e,n)=>{const r=function(e,t){if(e=(e||"").trim(),!e)return T;if(F.test(e))return T;if("value"===e)return null==t.value?T:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const o=e.slice(4),n=t.row?t.row[o]:void 0;return null==n?T:String(n)}if(e.length>80)return T;if(!H.test(e)||L.test(e))return T;const o=e.match(/\./g);if(o&&o.length>1)return T;try{const o=N(e,t),n=null==o?"":String(o);return F.test(n)?T:n||T}catch{return T}}(n,t);return o.push({expr:n.trim(),result:r}),r}),r=(i=n)?i.replace(new RegExp(T,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):i;var i;const s=o.length&&o.every(e=>""===e.result||e.result===T);return F.test(e)||s?"":r}const F=/Reflect|Proxy|ownKeys/;function $(e){if(F.test(e.textContent||"")){for(const t of e.childNodes)t.nodeType===Node.TEXT_NODE&&F.test(t.textContent||"")&&(t.textContent="");F.test(e.textContent||"")&&(e.textContent="")}}function W(e){if(F.test(e)){const e=()=>"";return e.__blocked=!0,e}const t=t=>q(e,t);return t.__blocked=!1,t}const B={STRETCH:"stretch",FIXED:"fixed"},V={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},U={mode:"reduced-motion",duration:200,easing:"ease-out"},G={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function j(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}class Y{static dependencies;static manifest;aliases;version="2.16.3";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const n of Object.keys(t))o[n]=this;for(const n of e){const e=n.userConfig;for(const[r,i]of Object.entries(e)){if(void 0===i)continue;if(!(r in t)){t[r]=i,o[r]=n;continue}if(t[r]===i)continue;const e=o[r]?.constructor.name??this.constructor.name,s=n.constructor.name,l=S("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig;for(const o of Object.keys(t))delete t[o];Object.assign(t,e.userConfig)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const o=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...G,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}setIcon(e,t,o){e.dataset.icon=j(t),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const n=this.#t(t,o);void 0!==n?"string"==typeof n?e.innerHTML=z(n):n instanceof HTMLElement&&(e.innerHTML="",e.appendChild(n.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(o,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(o,n):e.appendChild(o),o}warn(t,o){void 0!==o?console.warn(S(t,o,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(e,t){throw new Error(S(e,t,this.gridElement.id,this.name))}}const X={ROOT:"tbw-grid-root",HEADER:"header",HEADER_ROW:"header-row",HEADER_CELL:"header-cell",ROWS_VIEWPORT:"rows-viewport",ROWS_SPACER:"rows-spacer",ROWS_CONTAINER:"rows",DATA_ROW:"data-grid-row",GROUP_ROW:"group-row",DATA_CELL:"cell",SELECTED:"selected",FOCUSED:"focused",EDITING:"editing",EXPANDED:"expanded",COLLAPSED:"collapsed",DRAGGING:"dragging",RESIZING:"resizing",SORTABLE:"sortable",SORTED_ASC:"sorted-asc",SORTED_DESC:"sorted-desc",HIDDEN:"hidden",STICKY_LEFT:"sticky-left",STICKY_RIGHT:"sticky-right",PINNED_TOP:"pinned-top",PINNED_BOTTOM:"pinned-bottom",TREE_TOGGLE:"tree-toggle",TREE_INDENT:"tree-indent",GROUP_TOGGLE:"group-toggle",GROUP_LABEL:"group-label",GROUP_COUNT:"group-count",RANGE_SELECTION:"range-selection",SELECTION_OVERLAY:"selection-overlay"},K={FIELD:"data-field",GROUP_KEY:"data-group-key"},Z={ROOT:`.${X.ROOT}`,HEADER:`.${X.HEADER}`,HEADER_ROW:`.${X.HEADER_ROW}`,HEADER_CELL:`.${X.HEADER_CELL}`,ROWS_VIEWPORT:`.${X.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${X.ROWS_CONTAINER}`,DATA_ROW:`.${X.DATA_ROW}`,DATA_CELL:`.${X.DATA_CELL}`,GROUP_ROW:`.${X.GROUP_ROW}`,CELL_BY_FIELD:e=>`.${X.DATA_CELL}[${K.FIELD}="${e}"]`,SELECTED_ROWS:`.${X.DATA_ROW}.${X.SELECTED}`,EDITING_CELL:`.${X.DATA_CELL}.${X.EDITING}`},Q={COLOR_BG:"--tbw-color-bg",COLOR_FG:"--tbw-color-fg",COLOR_FG_MUTED:"--tbw-color-fg-muted",COLOR_BORDER:"--tbw-color-border",COLOR_ACCENT:"--tbw-color-accent",COLOR_HEADER_BG:"--tbw-color-header-bg",COLOR_HEADER_FG:"--tbw-color-header-fg",COLOR_SELECTION:"--tbw-color-selection",COLOR_ROW_HOVER:"--tbw-color-row-hover",COLOR_ROW_ALT:"--tbw-color-row-alt",ROW_HEIGHT:"--tbw-row-height",HEADER_HEIGHT:"--tbw-header-height",CELL_PADDING:"--tbw-cell-padding",FONT_FAMILY:"--tbw-font-family",FONT_SIZE:"--tbw-font-size",BORDER_RADIUS:"--tbw-border-radius",FOCUS_OUTLINE:"--tbw-focus-outline"};function J(e,t){if(t)for(const o in t){const n=t[o];null!=n&&e.setAttribute(o,n)}}function ee(e,t,o){const n=document.createElement(e);return J(n,t),n}function te(e,t){const o=document.createElement("div");return e&&(o.className=e),J(o,t),o}function oe(e,t,o){const n=document.createElement("button");return n.type="button",e&&(n.className=e),J(n,t),n}const ne=document.createElement("template");function re(){return ne.content.cloneNode(!0)}function ie(e){const t=document.createDocumentFragment(),o=te(e.hasShell?`${X.ROOT} has-shell`:X.ROOT);if(e.hasShell&&e.shellBody)e.shellHeader&&o.appendChild(e.shellHeader),o.appendChild(e.shellBody);else{const e=te("tbw-grid-content");e.appendChild(re()),o.appendChild(e)}return t.appendChild(o),t}function se(e){const t=te("tbw-shell-header",{part:"shell-header",role:"presentation"});if(e.title){const o=te("tbw-shell-title");o.textContent=e.title,t.appendChild(o)}const o=te("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});t.appendChild(o);const n=te("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const s of e.configButtons)s.hasRender&&n.appendChild(te("tbw-toolbar-content-slot",{"data-toolbar-content":s.id}));for(const s of e.apiButtons)s.hasRender&&n.appendChild(te("tbw-toolbar-content-slot",{"data-toolbar-content":s.id}));const r=e.configButtons.some(e=>e.hasRender)||e.apiButtons.some(e=>e.hasRender),i=e.hasPanels&&!1!==e.showToggle;if(r&&i&&n.appendChild(te("tbw-toolbar-separator")),i){const t=oe(e.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(e.isPanelOpen),"aria-controls":"tbw-tool-panel"});t.dataset.icon="tool-panel",void 0!==e.toolPanelIcon&&(t.innerHTML=z(e.toolPanelIcon)),n.appendChild(t)}return t.appendChild(n),t}function le(e){const t=e.mode??"overlay",o=te("tbw-shell-body",{"data-mode":t}),n=e.panels.length>0,r=1===e.panels.length,i=te("tbw-grid-content");i.appendChild(re());let s=null;if(n){s=ee("aside",{class:e.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":e.position,role:"presentation",id:"tbw-tool-panel",..."dropdown"===t?{popover:"manual"}:{}});const o="left"===e.position?"right":"left";s.appendChild(te("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":o,"aria-hidden":"true"}));const n=e=>{const t=oe(e?"tbw-tool-panel-close tbw-tool-panel-close--inline":"tbw-tool-panel-close",{part:"tool-panel-close","data-panel-close":"",title:"Close panel","aria-label":"Close panel","aria-controls":"tbw-tool-panel"});return t.textContent="✕",t},i=!0===e.showCloseButton&&r;if(e.showCloseButton&&!r){const e=te("tbw-tool-panel-header",{part:"tool-panel-header"});e.appendChild(n(!1)),s.appendChild(e)}const l=te("tbw-tool-panel-content",{role:"presentation"}),a=te("tbw-accordion");for(const t of e.panels){const o=te(`tbw-accordion-section${t.isExpanded?" expanded":""}${r?" single":""}${i?" has-inline-close":""}`,{"data-section":t.id}),s=oe("tbw-accordion-header",{"aria-expanded":String(t.isExpanded),"aria-controls":`tbw-section-${t.id}`});if(r&&s.setAttribute("aria-disabled","true"),t.icon){const e=ee("span",{class:"tbw-accordion-icon"});e.innerHTML=z(t.icon),s.appendChild(e)}const l=ee("span",{class:"tbw-accordion-title"});if(l.textContent=t.title,s.appendChild(l),!r){const t=ee("span",{class:"tbw-accordion-chevron","data-icon":"expand"});void 0!==e.expandIcon&&(t.innerHTML=z(e.expandIcon)),s.appendChild(t)}if(i){const e=te("tbw-accordion-header-row");e.appendChild(s),e.appendChild(n(!0)),o.appendChild(e)}else o.appendChild(s);o.appendChild(te("tbw-accordion-content",{id:`tbw-section-${t.id}`,role:"presentation"})),a.appendChild(o)}l.appendChild(a),s.appendChild(l)}return"left"===e.position&&s?(o.appendChild(s),o.appendChild(i)):(o.appendChild(i),s&&o.appendChild(s)),o}function ae(e){return e?"string"==typeof e?z(e):e.outerHTML:""}function ce(e){return!!e?.header?.title||(!!e?.header?.toolbarContents?.length||(!!e?.toolPanels?.length||(!!e?.headerContents?.length||(!!e?.header?.lightDomContent?.length||!!e?.header?.hasToolButtonsContainer))))}function de(e){return!1!==e?.header?.visible}function he(e,t){const o=e.querySelector("tbw-grid-header");if(!o)return;if(!t.lightDomTitle){const e=o.getAttribute("title");e&&(t.lightDomTitle=e)}const n=o.querySelectorAll("tbw-grid-header-content");n.length>0&&0===t.lightDomHeaderContent.length&&(t.lightDomHeaderContent=Array.from(n)),o.style.display="none"}function ue(e,t,o){const n=e.querySelector(":scope > tbw-grid-tool-buttons");if(!n)return;t.hasToolButtonsContainer=!0;const r="light-dom-toolbar-content";if(t.lightDomToolbarContentIds.has(r))return;const i={id:r,order:0,render:e=>{for(;n.firstChild;)e.appendChild(n.firstChild);return()=>{for(;e.firstChild;)n.appendChild(e.firstChild)}}};t.toolbarContents.set(r,i),t.lightDomToolbarContentIds.add(r),n.style.display="none"}function ge(e,t,o){e.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(e=>{const n=e,r=n.getAttribute("id"),i=n.getAttribute("title");if(!r||!i)return void E("TBW070",`Tool panel missing required id or title attribute: id="${r??""}", title="${i??""}"`);const l=n.getAttribute("icon")??void 0,a=n.getAttribute("tooltip")??void 0,c=parseInt(n.getAttribute("order")??"100",10);let d;const h=o?.(n);if(h)d=h;else{const e=z(n.innerHTML.trim());d=t=>{const o=document.createElement("div");return o.innerHTML=e,t.appendChild(o),()=>o.remove()}}const u=t.toolPanels.get(r);if(u&&!t.lightDomToolPanelIds.has(r))return E(s,`Tool panel "${r}" is already provided by a plugin or the grid API; ignoring the matching light-DOM <tbw-grid-tool-panel>.`),void(n.style.display="none");if(u){if(h){const e=!t.adapterBoundToolPanelIds.has(r),o=u.order!==c||u.icon!==l||u.tooltip!==a;if(u.render=d,u.order=c,u.icon=l,u.tooltip=a,t.adapterBoundToolPanelIds.add(r),e||o){const e=t.panelCleanups.get(r);e&&(e(),t.panelCleanups.delete(r))}}return}const g={id:r,title:i,icon:l,tooltip:a,order:c,render:d};t.toolPanels.set(r,g),t.lightDomToolPanelIds.add(r),h&&t.adapterBoundToolPanelIds.add(r),n.style.display="none"})}function fe(e,t){if(t.contains(e))return!0;const o=e.getRootNode();return o instanceof ShadowRoot&&o.host===t}function pe(e,t){const o=t.lightDomHeaderContent.length>0&&!t.lightDomContentMoved,n=t.headerContents.size>0;if(!o&&!n)return;const r=e.querySelector(".tbw-shell-content");if(!r)return;if(o){for(const e of t.lightDomHeaderContent)e.style.display="",r.appendChild(e);t.lightDomContentMoved=!0}const i=[...t.headerContents.values()].sort((e,t)=>(e.order??100)-(t.order??100));for(const s of i){const e=t.headerContentCleanups.get(s.id);e&&(e(),t.headerContentCleanups.delete(s.id));let o=r.querySelector(`[data-header-content="${s.id}"]`);o||(o=document.createElement("div"),o.setAttribute("data-header-content",s.id),r.appendChild(o));const n=s.render(o);n&&t.headerContentCleanups.set(s.id,n)}}function we(e,t,o){if(t.isPanelOpen)for(const[n,r]of t.toolPanels){const o=t.expandedSections.has(n),i=e.querySelector(`[data-section="${n}"]`),s=i?.querySelector(".tbw-accordion-content");if(!i||!s)continue;i.classList.toggle("expanded",o);const l=i.querySelector(".tbw-accordion-header");if(l&&l.setAttribute("aria-expanded",String(o)),o){if(0===s.children.length){const e=r.render(s);e&&t.panelCleanups.set(n,e)}}else{const e=t.panelCleanups.get(n);e&&(e(),t.panelCleanups.delete(n)),s.innerHTML=""}}}function me(e,t){const o=e.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",t.isPanelOpen),o.setAttribute("aria-pressed",String(t.isPanelOpen)))}function be(e,t){const o=e.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",t.isPanelOpen),t.isPanelOpen||(o.style.width=""))}ne.innerHTML='\n <div class="tbw-scroll-area">\n <div class="rows-body-wrapper">\n <div class="rows-body" role="grid">\n <div class="header" role="rowgroup">\n <div class="header-row" role="row" part="header-row"></div>\n </div>\n <div class="rows-container" role="presentation">\n <div class="rows-viewport" role="presentation">\n <div class="rows"></div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class="faux-vscroll">\n <div class="faux-vscroll-spacer"></div>\n </div>\n <div class="tbw-sr-only" aria-live="polite" aria-atomic="true"></div>\n';const ve="--tbw-tool-panel-anchor";let Ce=0;function ye(){return"undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("anchor-name",ve)}function _e(e,t,o,n){const r=e.querySelector(".tbw-tool-panel");if(r){if(t.dropdownAnchorEl=o,r.dataset.anchor=n?"corner":"below",r.hasAttribute("popover")&&"function"==typeof r.showPopover)try{r.showPopover()}catch{}if(ye()){const e=`${ve}-${++Ce}`;t.dropdownAnchorName=e,o.style.setProperty("anchor-name",e),r.style.setProperty("position-anchor",e),r.style.removeProperty("top"),r.style.removeProperty("left"),r.style.removeProperty("right")}else!function(e,t,o){const n=t.getBoundingClientRect(),r=e.getAttribute("data-position")??"right";if(e.style.position="fixed",e.style.top=`${Math.round((o?n.top:n.bottom)+4)}px`,"left"===r)e.style.left=`${Math.round(n.left)}px`,e.style.right="auto";else{const t="undefined"!=typeof window?window.innerWidth:0;e.style.left="auto",e.style.right=`${Math.round(t-n.right)}px`}}(r,o,n)}}function Se(e){for(const t of e.toolbarContentCleanups.values())t();e.toolbarContentCleanups.clear();for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.headerContentCleanups.values())t();e.headerContentCleanups.clear(),e.lightDomContentMoved=!1}function Re(e,t,o){const n=void 0!==o?.toolPanel?ae(o.toolPanel):void 0,r=void 0!==o?.expand?ae(o.expand):void 0,i=void 0!==o?.collapse?ae(o.collapse):void 0,s=[...e.header?.toolbarContents??[]].sort((e,t)=>(e.order??0)-(t.order??0)),l=[...e.toolPanels??[]].sort((e,t)=>(e.order??100)-(t.order??100));return{headerOptions:{title:e.header?.title??void 0,hasPanels:l.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:n,showToggle:!1!==e.header?.toolPanelToggle&&!0!==e.toolPanel?.locked,configButtons:s.map(e=>({id:e.id,hasElement:!1,hasRender:!!e.render})),apiButtons:[]},bodyOptions:{position:e.toolPanel?.position??"right",mode:e.toolPanel?.mode??"overlay",isPanelOpen:t.isPanelOpen,expandIcon:r,collapseIcon:i,showCloseButton:!1===e.header?.visible&&!0!==e.toolPanel?.locked&&"dropdown"!==(e.toolPanel?.mode??"overlay"),panels:l.map(e=>({id:e.id,title:e.title,icon:ae(e.icon),isExpanded:t.expandedSections.has(e.id)}))}}}function Ee(e,t,o,n){const r=e.querySelector(`.${X.ROOT}`),i=r?.querySelector(".tbw-grid-content");if(!r||!i)return function(e,t,o,n){const r=ce(t),i=[];for(let s=e.firstChild;s;s=s.nextSibling)1===s.nodeType&&s.classList.contains(X.ROOT)||i.push(s);e.replaceChildren();for(const s of i)e.appendChild(s);if(r){const{headerOptions:r,bodyOptions:i}=Re(t,o,n),s=ie({hasShell:!0,shellHeader:de(t)?se(r):void 0,shellBody:le(i)});e.appendChild(s)}else{const t=ie({hasShell:!1});e.appendChild(t)}return r}(e,t,o,n);i.remove();const s=ce(t);if(r.replaceChildren(),s){r.className=`${X.ROOT} has-shell`;const{headerOptions:e,bodyOptions:s}=Re(t,o,n),l=de(t)?se(e):void 0,a=le(s),c=a.querySelector(".tbw-grid-content");c&&c.replaceWith(i),l&&r.appendChild(l),r.appendChild(a)}else r.className=X.ROOT,r.appendChild(i);return s}function Pe(e,t){let o=!1;const n={get isInitialized(){return o},setInitialized(e){o=e},get isPanelOpen(){return e.isPanelOpen},get expandedSections(){return[...e.expandedSections]},openToolPanel(o,r){if(0===e.toolPanels.size)return void E("TBW071","No tool panels registered",t.id);let s;if(void 0!==o&&(e.toolPanels.has(o)?s=o:E(i,`Tool panel "${o}" not found`,t.id)),e.isPanelOpen&&s&&e.expandedSections.has(s))return;if(e.isPanelOpen&&s&&!e.expandedSections.has(s))return void n.toggleToolPanelSection(s);if(e.isPanelOpen)return;if(e.isPanelOpen=!0,0===e.expandedSections.size&&e.toolPanels.size>0)if(s)e.expandedSections.add(s);else{const o=t.effectiveConfig?.shell?.toolPanel?.defaultOpen;if(o&&e.toolPanels.has(o))e.expandedSections.add(o);else{const t=[...e.toolPanels.values()].sort((e,t)=>(e.order??100)-(t.order??100))[0];t&&e.expandedSections.add(t.id)}}else if(s&&!e.expandedSections.has(s)){for(const t of[...e.expandedSections])e.expandedSections.delete(t);e.expandedSections.add(s)}const l=t._renderRoot;if(me(l,e),be(l,e),we(l,e,t._accordionIcons),"dropdown"===t.effectiveConfig?.shell?.toolPanel?.mode){const{el:o,corner:n}=function(e){if(e)return{el:e,corner:!1};const o=t._renderRoot.querySelector("[data-panel-toggle]");return o?{el:o,corner:!1}:{el:t._hostElement,corner:!0}}(r?.anchor);_e(l,e,o,n)}t._emit("tool-panel-open",{sections:n.expandedSections})},closeToolPanel(){if(!e.isPanelOpen)return;if(t.effectiveConfig?.shell?.toolPanel?.locked)return;for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.toolPanels.values())t.onClose?.();e.isPanelOpen=!1;const o=t._renderRoot;me(o,e),be(o,e),"dropdown"===t.effectiveConfig?.shell?.toolPanel?.mode&&function(e,t){const o=e.querySelector(".tbw-tool-panel");if(o){if(o.hasAttribute("popover")&&"function"==typeof o.hidePopover)try{o.hidePopover()}catch{}o.style.removeProperty("position-anchor"),o.style.removeProperty("position"),o.style.removeProperty("top"),o.style.removeProperty("left"),o.style.removeProperty("right"),delete o.dataset.anchor}t.dropdownAnchorEl&&(t.dropdownAnchorEl.style.removeProperty("anchor-name"),t.dropdownAnchorEl=null),t.dropdownAnchorName=null}(o,e),t._emit("tool-panel-close",{})},toggleToolPanel(t){e.isPanelOpen?n.closeToolPanel():n.openToolPanel(void 0,t)},reanchorOpenDropdown(){if(!e.isPanelOpen)return;if("dropdown"!==t.effectiveConfig?.shell?.toolPanel?.mode)return;const o=e.dropdownAnchorEl;if(o&&o.isConnected&&e.dropdownAnchorName&&o.style.getPropertyValue("anchor-name")===e.dropdownAnchorName)return;if(!e.dropdownAnchorName&&o&&o.isConnected&&o!==t._hostElement){const e=t._renderRoot.querySelector(".tbw-tool-panel");if("below"===e?.dataset.anchor)return}const n=t._renderRoot.querySelector("[data-panel-toggle]");if(n&&n!==t._hostElement){if(e.dropdownAnchorName&&ye()&&function(e,t,o){const n=t.dropdownAnchorName;if(!n)return!1;const r=e.querySelector(".tbw-tool-panel");if(!r)return!1;const i=t.dropdownAnchorEl;if(i&&i!==o&&i.style.removeProperty("anchor-name"),o.style.setProperty("anchor-name",n),r.style.setProperty("position-anchor",n),r.style.removeProperty("top"),r.style.removeProperty("left"),r.style.removeProperty("right"),r.dataset.anchor="below",t.dropdownAnchorEl=o,r.hasAttribute("popover")&&"function"==typeof r.showPopover)try{r.showPopover()}catch{}return!0}(t._renderRoot,e,n))return;_e(t._renderRoot,e,n,!1)}else o!==t._hostElement||_e(t._renderRoot,e,t._hostElement,!0)},toggleToolPanelSection(o){const n=e.toolPanels.get(o);if(!n)return void E(i,`Tool panel section "${o}" not found`,t.id);if(1===e.toolPanels.size)return;const r=t._renderRoot,s=e.expandedSections.has(o);if(s){const t=e.panelCleanups.get(o);t&&(t(),e.panelCleanups.delete(o)),n.onClose?.(),e.expandedSections.delete(o),xe(r,o,!1)}else{for(const[t,n]of e.toolPanels)if(t!==o&&e.expandedSections.has(t)){const o=e.panelCleanups.get(t);o&&(o(),e.panelCleanups.delete(t)),n.onClose?.(),e.expandedSections.delete(t),xe(r,t,!1);const i=r.querySelector(`[data-section="${t}"] .tbw-accordion-content`);i&&(i.innerHTML="")}e.expandedSections.add(o),xe(r,o,!0),function(e,t,o){const n=t.toolPanels.get(o);if(!n?.render)return;const r=e.querySelector(`[data-section="${o}"] .tbw-accordion-content`);if(!r)return;const i=n.render(r);i&&t.panelCleanups.set(o,i)}(r,e,o)}t._emit("tool-panel-section-toggle",{id:o,expanded:!s})},getToolPanels:()=>[...e.toolPanels.values()],registerToolPanel(n){e.toolPanels.has(n.id)?E(s,`Tool panel "${n.id}" already registered`,t.id):(e.toolPanels.set(n.id,n),o&&t.refreshShellHeader?.())},unregisterToolPanel(n){if(e.expandedSections.has(n)){const t=e.panelCleanups.get(n);t&&(t(),e.panelCleanups.delete(n)),e.expandedSections.delete(n)}e.toolPanels.delete(n),o&&t.refreshShellHeader?.()},getHeaderContents:()=>[...e.headerContents.values()],registerHeaderContent(n){e.headerContents.has(n.id)?E(l,`Header content "${n.id}" already registered`,t.id):(e.headerContents.set(n.id,n),o&&pe(t._renderRoot,e))},unregisterHeaderContent(o){const n=e.headerContentCleanups.get(o);n&&(n(),e.headerContentCleanups.delete(o));const r=e.headerContents.get(o);r?.onDestroy?.(),e.headerContents.delete(o);const i=t._renderRoot.querySelector(`[data-header-content="${o}"]`);i?.remove()},getToolbarContents:()=>[...e.toolbarContents.values()].sort((e,t)=>(e.order??0)-(t.order??0)),registerToolbarContent(n){e.toolbarContents.has(n.id)?E("TBW075",`Toolbar content "${n.id}" already registered`,t.id):(e.toolbarContents.set(n.id,n),o&&t.refreshShellHeader?.())},unregisterToolbarContent(n){const r=e.toolbarContentCleanups.get(n);r&&(r(),e.toolbarContentCleanups.delete(n));const i=e.toolbarContents.get(n);i?.onDestroy&&i.onDestroy(),e.toolbarContents.delete(n),o&&t.refreshShellHeader?.()}};return n}function xe(e,t,o){const n=e.querySelector(`[data-section="${t}"]`);n&&n.classList.toggle("expanded",o)}class Ae extends Y{name="shell";styles="@layer tbw-base{tbw-grid{.tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}.tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}.tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}.tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease);&:hover{background:var(--tbw-color-row-hover)}&:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}&.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}&:disabled{opacity:.5;cursor:not-allowed}}.tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}.tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}.tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden;touch-action:none}}}@layer tbw-base{tbw-grid{.tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:var(--tbw-z-layer-toolpanel, 31);box-shadow:-2px 0 8px var(--tbw-color-shadow);&[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}&.open{width:var(--tbw-tool-panel-width)}}.tbw-shell-body[data-mode=push]{.tbw-tool-panel{position:relative;inset:auto;flex-shrink:0;box-shadow:none;z-index:auto;border-left:none;border-right:none;&.open{border-left:1px solid var(--tbw-tool-panel-border)}&[data-position=left].open{border-left:none;border-right:1px solid var(--tbw-tool-panel-border)}}.tbw-tool-panel-resize{display:none}}.tbw-tool-panel[popover]{position:fixed;inset:auto;width:var(--tbw-tool-panel-width);max-width:calc(100vw - 16px);height:auto;max-height:min(70vh,480px);overflow:hidden auto;margin:4px 0 0;padding:0;border:1px solid var(--tbw-tool-panel-border);border-radius:var(--tbw-border-radius, 6px);box-shadow:0 8px 24px var(--tbw-color-shadow);transition:none;display:none;&:popover-open,&.open{display:flex;width:var(--tbw-tool-panel-width)}.tbw-tool-panel-resize{display:none}}@supports (anchor-name: --x){.tbw-tool-panel[popover]{top:anchor(bottom);right:anchor(right);left:auto;position-try-fallbacks:flip-block,flip-inline,flip-block flip-inline;&[data-anchor=corner]{top:anchor(top)}&[data-position=left]{left:anchor(left);right:auto}}}.tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease);&[data-handle-position=left]{left:0}&[data-handle-position=right]{right:0}&:hover,&.resizing{background:var(--tbw-color-accent)}}.tbw-tool-panel-header{display:flex;align-items:center;justify-content:flex-end;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}.tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px;&:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}}.tbw-accordion-header-row{display:flex;align-items:stretch;.tbw-accordion-header{flex:1;min-width:0}}.tbw-tool-panel-close--inline{align-self:center;flex-shrink:0;margin-inline-end:8px}.tbw-tool-panel-content{flex:1;overflow:auto}.tbw-accordion{display:flex;flex-direction:column;gap:0}.tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border);&:last-child{border-bottom:none}&.single .tbw-accordion-header{cursor:default;&:hover{background:transparent}}&.expanded{.tbw-accordion-chevron{transform:rotate(90deg)}.tbw-accordion-content{display:block}}}.tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:start;cursor:pointer;user-select:none;&:hover{background:var(--tbw-color-row-hover)}}.tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}.tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}.tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tbw-accordion-content{display:none}}}";#o;#n;#r;#i;#s;#l;#a;#c=!1;get hasState(){return void 0!==this.#o}ensureState(e){if(this.#o)return;const t={toolPanels:/* @__PURE__ */new Map,headerContents:/* @__PURE__ */new Map,toolbarContents:/* @__PURE__ */new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:/* @__PURE__ */new Set,adapterBoundToolPanelIds:/* @__PURE__ */new Set,lightDomToolbarContentIds:/* @__PURE__ */new Set,apiToolPanelIds:/* @__PURE__ */new Set,apiHeaderContentIds:/* @__PURE__ */new Set,isPanelOpen:!1,expandedSections:/* @__PURE__ */new Set,headerContentCleanups:/* @__PURE__ */new Map,panelCleanups:/* @__PURE__ */new Map,toolbarContentCleanups:/* @__PURE__ */new Map,lightDomContentMoved:!1,dropdownAnchorEl:null,dropdownAnchorName:null};this.#o=t,this.#n=Pe(t,e)}get shellState(){return this.#o}get shellController(){return this.#n}get isToolPanelOpen(){return!!this.hasState&&this.shellController.isPanelOpen}get expandedToolPanelSections(){return this.hasState?this.shellController.expandedSections:[]}openToolPanel(e,t){this.shellController?.openToolPanel(e,t)}closeToolPanel(){this.shellController?.closeToolPanel()}toggleToolPanel(e){this.shellController?.toggleToolPanel(e)}toggleToolPanelSection(e){this.shellController?.toggleToolPanelSection(e)}getToolPanels(){return this.hasState?this.shellController.getToolPanels():[]}registerToolPanel(e){this.hasState&&(this.shellState.apiToolPanelIds.add(e.id),this.shellController.registerToolPanel(e))}unregisterToolPanel(e){this.hasState&&(this.shellState.apiToolPanelIds.delete(e),this.shellController.unregisterToolPanel(e))}getHeaderContents(){return this.hasState?this.shellController.getHeaderContents():[]}registerHeaderContent(e){this.hasState&&(this.shellState.apiHeaderContentIds.add(e.id),this.shellController.registerHeaderContent(e))}unregisterHeaderContent(e){this.hasState&&(this.shellState.apiHeaderContentIds.delete(e),this.shellController.unregisterHeaderContent(e))}getToolbarContents(){return this.hasState?this.shellController.getToolbarContents():[]}registerToolbarContent(e){this.shellController?.registerToolbarContent(e)}unregisterToolbarContent(e){this.shellController?.unregisterToolbarContent(e)}attach(e){super.attach(e);const t=()=>this.#d(e);this.#l=t,e._registerLightDomHandler("tbw-grid-header",t),e._registerLightDomHandler("tbw-grid-tool-buttons",t),e._registerLightDomHandler("tbw-grid-tool-panel",t)}#h(e){const t=e._hostElement;he(t,this.shellState),ue(t,this.shellState),ge(t,this.shellState,e._getToolPanelRendererFactory())}#d(e){if(!this.hasState)return;const t=this.shellState,o=t.lightDomTitle,n=t.hasToolButtonsContainer;this.#h(e);const r=t.lightDomTitle,i=t.hasToolButtonsContainer;(r&&!o||i&&!n)&&(e._requestConfigMerge(),e._renderRoot.querySelector(".tbw-shell-header")&&(Se(t),this.afterStructuralRender()))}_parseLightDomHeader(e){const t=e._hostElement;he(t,this.shellState),ue(t,this.shellState)}_parseLightDomToolPanels(e){ge(e._hostElement,this.shellState,e._getToolPanelRendererFactory())}_parseLightDomAll(e){this._parseLightDomHeader(e),this._parseLightDomToolPanels(e)}_prepareForRerender(){this.hasState&&Se(this.shellState)}_renderOpenPanelContent(e){this.hasState&&we(e._renderRoot,this.shellState)}_shouldRenderHeader(e){return ce(e)}processConfig(e){if(!this.hasState)return;const t=this.shellState,o=this.resolvedConfig;if(e.shell={...o,...e.shell},e.shell.header={...o.header,...e.shell.header},t.lightDomTitle&&!e.shell.header.title&&(e.shell.header.title=t.lightDomTitle),t.lightDomHeaderContent?.length>0&&(e.shell.header.lightDomContent=t.lightDomHeaderContent),t.hasToolButtonsContainer&&(e.shell.header.hasToolButtonsContainer=!0),t.toolPanels.size>0){const o=Array.from(t.toolPanels.values());o.sort((e,t)=>(e.order??100)-(t.order??100)),e.shell.toolPanels=o}if(t.headerContents.size>0){const o=Array.from(t.headerContents.values());o.sort((e,t)=>(e.order??100)-(t.order??100)),e.shell.headerContents=o}const n=Array.from(t.toolbarContents.values()),r=this.grid?._sourceConfig?.shell?.header?.toolbarContents??[],i=new Set(r.map(e=>e.id)),s=[...r];for(const l of n)i.has(l.id)||s.push(l);s.sort((e,t)=>(e.order??0)-(t.order??0)),e.shell.header.toolbarContents=s}afterStructuralRender(){const e=this.grid;if(!e||!this.hasState)return;const t=this.shellState;Ee(e._renderRoot,e.effectiveConfig?.shell,{isPanelOpen:t.isPanelOpen,expandedSections:t.expandedSections},e.effectiveConfig?.icons)&&(this.#u(e),this.shellController.setInitialized(!0),this.#g(e))}afterRender(){const e=this.grid;e&&this.hasState&&(this.shellState.isPanelOpen?(this.shellController.reanchorOpenDropdown(),this.#f(e)):this.#p())}#f(e){"dropdown"===e.effectiveConfig?.shell?.toolPanel?.mode?"undefined"!=typeof MutationObserver&&(this.#a||(this.#a=new MutationObserver(()=>{this.grid&&this.hasState&&this.shellState.isPanelOpen?this.shellController.reanchorOpenDropdown():this.#p()})),this.#c||(this.#a.observe(e._renderRoot,{childList:!0,subtree:!0}),this.#c=!0)):this.#p()}#p(){this.#a&&this.#c&&(this.#a.disconnect(),this.#c=!1)}#g(e){const t=this.shellState,o=e._renderRoot,n=e.effectiveConfig?.shell;pe(o,t),function(e,t,o){const n=t?.header?.toolbarContents??[],r=[...o.toolbarContents.values()],i=new Set(n.map(e=>e.id)),s=[...n];for(const l of r)i.has(l.id)||s.push(l);for(const l of s){if(o.toolbarContentCleanups.has(l.id))continue;if(!l.render)continue;const t=e.querySelector(`[data-toolbar-content="${l.id}"]`);if(!t)continue;const n=l.render(t);n&&o.toolbarContentCleanups.set(l.id,n)}}(o,n,t);const r=n?.toolPanel,i=r?.defaultOpen;i&&t.toolPanels.has(i)&&t.expandedSections.add(i);const s=!0===r?.locked||"open"===r?.initialState||void 0===r?.initialState&&void 0!==i&&t.toolPanels.has(i);!t.isPanelOpen&&t.toolPanels.size>0&&s&&this.openToolPanel(),t.isPanelOpen&&(be(o,t),we(o,t,(e.effectiveConfig,e.effectiveConfig)),me(o,t),this.shellController.reanchorOpenDropdown())}#u(e){const t=e._renderRoot,o=e.effectiveConfig?.shell,n=this.shellState;!function(e,t,o,n){const r=e.querySelector(".tbw-shell-toolbar");r&&r.addEventListener("click",e=>{e.target.closest("[data-panel-toggle]")&&n.onPanelToggle()});const i=e.querySelector(".tbw-tool-panel");i&&n.onPanelClose&&i.addEventListener("click",e=>{e.target.closest("[data-panel-close]")&&n.onPanelClose()});const s=e.querySelector(".tbw-accordion");s&&s.addEventListener("click",e=>{const t=e.target.closest(".tbw-accordion-header");if(t){const e=t.closest("[data-section]"),o=e?.getAttribute("data-section");o&&n.onSectionToggle(o)}})}(t,0,0,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onPanelClose:()=>this.closeToolPanel()}),this.#r?.(),this.#r=function(e,t,o){const n=e.querySelector(".tbw-tool-panel"),r=e.querySelector("[data-resize-handle]"),i=e.querySelector(".tbw-shell-body");if(!n||!r||!i)return()=>{};const s=t?.toolPanel?.position??"right";let l=0,a=0,c=0,d=!1;const h=e=>{if(!d)return;e.preventDefault();const t="left"===s?e.clientX-l:l-e.clientX,o=Math.min(c,Math.max(200,a+t));n.style.width=`${o}px`},u=()=>{if(!d)return;d=!1,r.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const e=n.getBoundingClientRect().width;o(e),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",u)},g=e=>{e.preventDefault(),d=!0,l=e.clientX,a=n.getBoundingClientRect().width,c=i.getBoundingClientRect().width-20,r.classList.add("resizing"),n.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",u)};return r.addEventListener("mousedown",g),()=>{r.removeEventListener("mousedown",g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",u)}}(t,o,t=>{e._hostElement.style.setProperty("--tbw-tool-panel-width",`${t}px`)}),this.#i?.(),this.#i=function(e,t,o,n){const r=t?.toolPanel?.mode;if("dropdown"!==r&&!t?.toolPanel?.closeOnClickOutside)return()=>{};if("push"===r)return()=>{};const i=t=>{if(!o.isPanelOpen)return;const r=o.dropdownAnchorEl;for(const o of t.composedPath()){if(null!=r&&o===r)return;if(o instanceof Element&&(o.classList?.contains("tbw-tool-panel")||o.matches?.("[data-panel-toggle]"))&&fe(o,e))return}n()};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)}(e._hostElement,o,n,()=>this.closeToolPanel()),this.#s?.(),this.#s=function(e,t,o){if("push"===e?.toolPanel?.mode)return()=>{};const n=e=>{"Escape"!==e.key||e.defaultPrevented||t.isPanelOpen&&o()};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)}(o,n,()=>this.closeToolPanel())}#w(){this.#r?.(),this.#r=void 0,this.#i?.(),this.#i=void 0,this.#s?.(),this.#s=void 0}detach(){super.detach()}disposeShellState(){this.#w(),this.#p(),this.#a=void 0;const e=this.grid;e&&this.#l&&(e._unregisterLightDomHandler("tbw-grid-header"),e._unregisterLightDomHandler("tbw-grid-tool-buttons"),e._unregisterLightDomHandler("tbw-grid-tool-panel"),this.#l=void 0),this.#o&&(!function(e){for(const t of e.headerContentCleanups.values())t();e.headerContentCleanups.clear();for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.toolbarContentCleanups.values())t();e.toolbarContentCleanups.clear();for(const t of e.toolbarContents.values())t.onDestroy?.();if(e.isPanelOpen)for(const t of e.expandedSections){const o=e.toolPanels.get(t);o?.onClose?.()}e.isPanelOpen=!1,e.expandedSections.clear(),e.toolPanels.clear(),e.headerContents.clear(),e.toolbarContents.clear(),e.lightDomHeaderContent=[],e.lightDomToolPanelIds.clear(),e.adapterBoundToolPanelIds.clear(),e.lightDomToolbarContentIds.clear(),e.lightDomContentMoved=!1}(this.#o),this.#n?.setInitialized(!1))}}function Te(e,t){if(!e)return;const o="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===o?.a11y?.announcements)return;const n=e.querySelector?.(".tbw-sr-only");n&&(n.textContent="",requestAnimationFrame(()=>{n.textContent=t}))}function He(e,t,...o){const n=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,r=n?.a11y?.messages?.[t];return r?r(...o):V[t](...o)}function Me(e,t){if(!(e&&e.length||t&&t.length))return[];if(!e||!e.length)return t||[];if(!t||!t.length)return e;const o={},n=t;for(let s=0;s<n.length;s++){const e=n[s],t=o[e.field];if(t){e.header&&!t.header&&(t.header=e.header),e.type&&!t.type&&(t.type=e.type),e.sortable&&(t.sortable=!0),e.resizable&&(t.resizable=!0),null!=e.width&&null==t.width&&(t.width=e.width),null!=e.minWidth&&null==t.minWidth&&(t.minWidth=e.minWidth),e.__viewTemplate&&(t.__viewTemplate=e.__viewTemplate),e.__headerTemplate&&(t.__headerTemplate=e.__headerTemplate),e.__element&&!t.__element&&(t.__element=e.__element);const o=e.renderer||e.viewRenderer,n=t.renderer||t.viewRenderer;o&&!n&&(t.viewRenderer=o,e.renderer&&(t.renderer=o)),e.editor&&!t.editor&&(t.editor=e.editor),e.headerRenderer&&!t.headerRenderer&&(t.headerRenderer=e.headerRenderer),e.headerLabelRenderer&&!t.headerLabelRenderer&&(t.headerLabelRenderer=e.headerLabelRenderer)}else o[e.field]={...e}}const r=e.map(e=>{const t=o[e.field];if(!t)return e;const n={...e};t.header&&!n.header&&(n.header=t.header),t.type&&!n.type&&(n.type=t.type),n.sortable=e.sortable||t.sortable,!0!==e.resizable&&!0!==t.resizable||(n.resizable=!0),null!=t.width&&null==n.width&&(n.width=t.width),null!=t.minWidth&&null==n.minWidth&&(n.minWidth=t.minWidth),t.__viewTemplate&&(n.__viewTemplate=t.__viewTemplate),t.__headerTemplate&&(n.__headerTemplate=t.__headerTemplate),t.__element&&!n.__element&&(n.__element=t.__element);const r=t.renderer||t.viewRenderer,i=n.renderer||n.viewRenderer;return r&&!i&&(n.viewRenderer=r,t.renderer&&(n.renderer=r)),t.editor&&!n.editor&&(n.editor=t.editor),n.headerRenderer||n.headerLabelRenderer||(t.headerRenderer?n.headerRenderer=t.headerRenderer:t.headerLabelRenderer&&(n.headerLabelRenderer=t.headerLabelRenderer)),delete o[e.field],n}),i=Object.keys(o);for(let s=0;s<i.length;s++)r.push(o[i[s]]);return r}function Le(e,t){try{e.part?.add?.(t)}catch{}const o=e.getAttribute("part");o?o.split(/\s+/).includes(t)||e.setAttribute("part",o+" "+t):e.setAttribute("part",t)}function ke(e){const t=e.effectiveConfig?.fitMode||e.fitMode||B.STRETCH;if(t!==B.STRETCH&&t!==B.FIXED)return;if(e.__didInitialAutoSize)return;if(!e.isConnected)return;const o=Array.from(e._headerRowEl?.children||[]);if(!o.length)return;let n=!1;const r=e._visibleColumns;for(let i=0;i<r.length;i++){const t=r[i];if(t.width)continue;const s=o[i];let l=s?s.scrollWidth:0;for(let o=0;o<e._rowPool.length;o++){const t=e._rowPool[o].children[i];if(t){const e=t.scrollWidth;e>l&&(l=e)}}l>0&&(t.width=l+2,t.__autoSized=!0,n=!0)}n&&Ie(e),e.__didInitialAutoSize=!0}const Oe=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function De(e,t){return"number"==typeof e?`${e}px`:(Oe.test(e)||E("TBW050",`Column '${t??"?"}' has an invalid CSS width value: '${e}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),e)}function Ie(e){const t=e.effectiveConfig?.fitMode||e.fitMode||B.STRETCH;e._gridTemplate=t===B.STRETCH?e._visibleColumns.map(e=>{if(null!=e.width)return De(e.width,e.field);const t=e.minWidth;return null!=t?`minmax(${t}px, 1fr)`:"1fr"}).join(" ").trim():e._visibleColumns.map(e=>null!=e.width?De(e.width,e.field):"max-content").join(" "),e.style.setProperty("--tbw-column-template",e._gridTemplate)}const ze=/* @__PURE__ */new WeakMap;function Ne(e,t,o=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:o});const n=e,r=t.field;let i=ze.get(n);if(i){const e=i.get(r);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,ze.set(n,i);const s=t.valueAccessor({row:e,column:t,rowIndex:o});return i.set(r,{v:s}),s}function qe(e,t){e&&(t?ze.get(e)?.delete(t):ze.delete(e))}function Fe(e,t){return null==e&&null==t?0:null==e?-1:null==t||e>t?1:e<t?-1:0}function $e(e,t,o){const n=o.find(e=>e.field===t.field),r=n?.sortComparator,{field:i,direction:s}=t,l=[...e];return r?n?.valueAccessor?l.sort((e,t)=>r(Ne(e,n),Ne(t,n),e,t)*s):l.sort((e,t)=>r(e[i],t[i],e,t)*s):n?.valueAccessor?Be(l,n,s):We(l,i,s),l}function We(e,t,o){e.sort((e,n)=>{const r=Ve(e,n);if(0!==r)return r;const i=e[t],s=n[t];return null==i&&null==s?0:null==i?-o:null==s||i>s?o:i<s?-o:0})}function Be(e,t,o){e.sort((e,n)=>{const r=Ve(e,n);if(0!==r)return r;const i=Ne(e,t),s=Ne(n,t);return null==i&&null==s?0:null==i?-o:null==s||i>s?o:i<s?-o:0})}function Ve(e,t){const o=!0===e?.__loading;return o===(!0===t?.__loading)?0:o?1:-1}function Ue(e,t,o,n){const r=n.find(e=>e.field===t),i=r?.sortComparator;i?r?.valueAccessor?e.sort((e,t)=>i(Ne(e,r),Ne(t,r),e,t)*o):e.sort((e,n)=>i(e[t],n[t],e,n)*o):r?.valueAccessor?Be(e,r,o):We(e,t,o)}function Ge(e,t,o,n){e._rows=t,e.__rowRenderEpoch++;for(let r=0;r<e._rowPool.length;r++)e._rowPool[r].__epoch=-1;ot(e),e.refreshVirtualWindow(!0),je(e,o,n)}function je(e,t,o){const n={field:t.field,direction:o};e.dispatchEvent(new CustomEvent("sort-change",{detail:n})),e._pluginManager?.emitPluginEvent?.("sort-change",n),Te(e,He(e,0===o?"sortCleared":"sortApplied",t.header??t.field,1===o?"ascending":"descending")),e.requestStateChange?.()}function Ye(e){return e._pluginManager?._hasRowStructurePlugins??!1}function Xe(e,t){if(e._sortState&&e._sortState.field===t.field)if(1===e._sortState.direction)Ke(e,t,-1);else{if(e._sortState=null,Ye(e))return e._requestSchedulerPhase(4,"sort-clear"),void je(e,t,0);e.__rowRenderEpoch++;for(let t=0;t<e._rowPool.length;t++)e._rowPool[t].__epoch=-1;e._rows=e.__originalOrder.slice(),e.__originalOrder=[],ot(e);const o=e._headerRowEl?.querySelectorAll('[role="columnheader"].sortable');if(o)for(let t=0;t<o.length;t++){const n=o[t];n.getAttribute("aria-sort")&&("ascending"!==n.getAttribute("aria-sort")&&"descending"!==n.getAttribute("aria-sort")||e._sortState)||n.setAttribute("aria-sort","none")}e.refreshVirtualWindow(!0),je(e,t,0)}else e._sortState||(e.__originalOrder=e._rows.slice()),Ke(e,t,1)}function Ke(e,t,o){if(e._sortState={field:t.field,direction:o},Ye(e))return e._requestSchedulerPhase(4,"sort-apply"),void je(e,t,o);const n={field:t.field,direction:o},r=e._columns,i=e.effectiveConfig?.sortHandler??$e;if(i===$e)return Ue(e._rows,n.field,o,r),void Ge(e,e._rows,t,o);const s=i(e._rows,n,r);s&&"function"==typeof s.then?s.then(n=>{Ge(e,n,t,o)}):Ge(e,s,t,o)}function Ze(e,t){return!1!==e.effectiveConfig?.sortable&&!0===t.sortable}function Qe(e,t){return!1!==e.effectiveConfig?.resizable&&!1!==t.resizable}function Je(e,t){const o=document.createElement("span");Le(o,"sort-indicator");const n=e._sortState?.field===t.field?e._sortState.direction:0,r=1===n?"sortAsc":-1===n?"sortDesc":"sortNone";o.dataset.icon=j(r);const i=e.icons?.[r];return void 0!==i&&function(e,t){"string"==typeof t?e.innerHTML=z(t):t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}(o,i),o}function et(e,t,o){const n=document.createElement("div");return n.className="resize-handle",n.setAttribute("aria-hidden","true"),n.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),e._resizeController.start(n,t,o)}),n.addEventListener("dblclick",o=>{o.stopPropagation(),o.preventDefault(),e._resizeController.resetColumn(t)}),n}function tt(e,t,o,n){n.classList.add(X.SORTABLE),n.tabIndex=0;const r=e._sortState?.field===t.field?e._sortState.direction:0;n.setAttribute("aria-sort",0===r?"none":1===r?"ascending":"descending"),n.addEventListener("click",o=>{e._resizeController?.isResizing||e._dispatchHeaderClick?.(o,t,n)||Xe(e,t)}),n.addEventListener("keydown",o=>{if("Enter"===o.key||" "===o.key){if(o.preventDefault(),e._dispatchHeaderClick?.(o,t,n))return;Xe(e,t)}})}function ot(e){e._headerRowEl=e.findHeaderRow();const t=e._headerRowEl;t&&(t.innerHTML="",e._visibleColumns.forEach((o,n)=>{const r=document.createElement("div");r.className="cell",Le(r,"header-cell"),r.setAttribute("role","columnheader"),r.setAttribute("aria-colindex",String(n+1)),r.setAttribute("data-field",o.field),r.setAttribute("data-col",String(n)),o.type&&r.setAttribute("data-type",o.type);const i=o.header??o.field,s=e._sortState?.field===o.field?e._sortState.direction:0,l=1===s?"asc":-1===s?"desc":null;if(o.headerRenderer){const t={column:o,value:i,sortState:l,filterActive:!1,cellEl:r,renderSortIcon:()=>Ze(e,o)?Je(e,o):null,renderFilterButton:()=>null},s=o.headerRenderer(t);!function(e,t){if(null!=t)if("string"==typeof t){const o=document.createElement("span");for(o.innerHTML=z(t);o.firstChild;)e.appendChild(o.firstChild)}else t instanceof Node&&e.appendChild(t)}(r,s),Ze(e,o)&&tt(e,o,0,r),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)))}else if(o.headerLabelRenderer){const t={column:o,value:i},s=o.headerLabelRenderer(t),l=document.createElement("span");null==s?l.textContent=i:"string"==typeof s?l.innerHTML=z(s):s instanceof Node&&l.appendChild(s),r.appendChild(l),Ze(e,o)&&(tt(e,o,0,r),r.appendChild(Je(e,o))),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)))}else if(o.__headerTemplate)Array.from(o.__headerTemplate.childNodes).forEach(e=>r.appendChild(e.cloneNode(!0))),Ze(e,o)&&(tt(e,o,0,r),r.appendChild(Je(e,o))),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)));else{const t=document.createElement("span");t.textContent=i,r.appendChild(t),Ze(e,o)&&(tt(e,o,0,r),r.appendChild(Je(e,o))),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)))}t.appendChild(r)}),t.querySelectorAll(`.cell.${X.SORTABLE}`).forEach(e=>{e.getAttribute("aria-sort")||e.setAttribute("aria-sort","none")}),t.children.length>0?(t.setAttribute("role","row"),t.setAttribute("aria-rowindex","1")):(t.removeAttribute("role"),t.removeAttribute("aria-rowindex")))}function nt(e,t){const o=e[0]||{},n=Object.keys(o).map(e=>{const t=o[e],n=null==(r=t)?"string":"number"==typeof r?"number":"boolean"==typeof r?"boolean":r instanceof Date||"string"==typeof r&&/\d{4}-\d{2}-\d{2}/.test(r)&&!isNaN(Date.parse(r))?"date":"string";var r;return{field:e,header:e.charAt(0).toUpperCase()+e.slice(1),type:n}}),r={};return n.forEach(e=>{r[e.field]=e.type||"string"}),{columns:n,typeMap:r}}const rt={STYLE:1,VIRTUALIZATION:2,HEADER:3,ROWS:4,COLUMNS:5,FULL:6};class it{#m;#b=0;#v=0;#C=null;#y=null;#_=null;#S=!1;constructor(e){this.#m=e}requestPhase(e,t){e>this.#b&&(this.#b=e),0===this.#v&&(this.#R(),this.#v=requestAnimationFrame(()=>this.#E()))}whenReady(){return this.#C?this.#C:Promise.resolve()}setInitialReadyResolver(e){this.#_=e}cancel(){0!==this.#v&&(cancelAnimationFrame(this.#v),this.#v=0),this.#b=0,this.#y&&(this.#y(),this.#y=null,this.#C=null)}get isPending(){return 0!==this.#b}get pendingPhase(){return this.#b}#R(){this.#C||(this.#C=new Promise(e=>{this.#y=e}))}#E(){if(this.#v=0,!this.#m._schedulerIsConnected)return this.#b=0,void(this.#y&&(this.#y(),this.#y=null,this.#C=null));const e=this.#b;this.#b=0,e>=rt.COLUMNS&&this.#m._schedulerMergeConfig(),e>=rt.ROWS&&this.#m._schedulerProcessRows(),e>=rt.COLUMNS&&(this.#m._schedulerProcessColumns(),this.#m._schedulerUpdateTemplate()),e>=rt.HEADER&&this.#m._schedulerRenderHeader(),e>=rt.VIRTUALIZATION&&this.#m.refreshVirtualWindow(!0,!0),e>=rt.STYLE&&this.#m._schedulerAfterRender();const t=!this.#S;t&&(this.#S=!0,this.#_?.()),this.#y&&(this.#y(),this.#y=null,this.#C=null),0!==e&&this.#P(e,t)}#P(e,t){const o=this.#m._virtualization,n=o?.enabled?{start:o.start,end:o.end}:null,r={phase:e,initial:t,rowCount:this.#m._rows?.length??0,visibleRange:n};this.#m._hostElement.dispatchEvent(new CustomEvent("render",{detail:r,bubbles:!0,composed:!0}))}}class st{#x;#A;#T;#H;#M;#L={};#k={};#O=!0;#D=[];#I;#z;#N;#q;#m;constructor(e){this.#m=e}get original(){return this.#L}get effective(){return this.#k}get columns(){return this.#k.columns??[]}set columns(e){this.#k.columns=e}get lightDomColumnsCache(){return this.#H}set lightDomColumnsCache(e){this.#H=e}get originalColumnNodes(){return this.#M}set originalColumnNodes(e){this.#M=e}get initialColumnState(){return this.#q}set initialColumnState(e){this.#q=e}get sourcesChanged(){return this.#O}markSourcesChanged(){this.#O=!0}setGridConfig(e){this.#x!==e&&(this.#x=e,this.#O=!0,this.#H=void 0)}getGridConfig(){return this.#x}setColumns(e){this.#A=e,this.#O=!0}getColumns(){return this.#A}setFitMode(e){this.#T=e,this.#O=!0}getFitMode(){return this.#T}merge(){const e=(this.#k.columns?.length??0)>0;if(!this.#O&&e)return;const t=this.#F();this.#O=!1,this.#L=t,Object.freeze(this.#L),this.#L.columns&&Object.freeze(this.#L.columns),this.#k=this.#$(this.#L),this.#W()}#$(e){const t={...e};return e.columns&&(t.columns=e.columns.map(e=>({...e}))),e.shell&&(t.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(e=>({...e})),headerContents:e.shell.headerContents?.map(e=>({...e}))}),t}#W(){const e=this.#k;if(this.#B(),"number"==typeof e.rowHeight&&e.rowHeight>0&&(this.#m._virtualization.rowHeight=e.rowHeight),"fixed"===e.fitMode){this.columns.forEach(e=>{null==e.width&&(e.width=80)})}this.#m._applyAnimationConfig(e)}#B(){const e=this.#k.typeDefaults;if(!e)return;const t=this.columns;for(const o of t){if(!o.type)continue;const t=e[o.type];t&&(o.renderer||o.viewRenderer||!t.renderer||(o.renderer=t.renderer),!o.format&&t.format&&(o.format=t.format),!o.editor&&t.editor&&(o.editor=t.editor),!o.editorParams&&t.editorParams&&(o.editorParams=t.editorParams))}}#F(){const e=this.#x?{...this.#x}:{},t=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#H??[]).map(e=>({...e}));let n=Me(t,o);this.#A&&this.#A.length&&(n=Me(this.#A,o));const r=this.#m.sourceRows;if(0===n.length&&r.length){n=nt(r).columns}return n.length&&(n.forEach(e=>{void 0===e.sortable&&(e.sortable=!0),void 0===e.resizable&&(e.resizable=!0),void 0===e.__originalWidth&&"number"==typeof e.width&&(e.__originalWidth=e.width)}),n.forEach(e=>{e.__viewTemplate&&!e.__compiledView&&(e.__compiledView=W(e.__viewTemplate.innerHTML)),e.__editorTemplate&&!e.__compiledEditor&&(e.__compiledEditor=W(e.__editorTemplate.innerHTML))}),e.columns=n),this.#T&&(e.fitMode=this.#T),e.fitMode||(e.fitMode="stretch"),this.#m._pluginManager?.processConfig?.(e),e.columnState&&!this.#q&&(this.#q=e.columnState),e}collectState(e){const t=this.columns,o=this.#V();return{columns:t.map((t,n)=>{const r={field:t.field,order:n,visible:!t.hidden},i=t;void 0!==i.__renderedWidth?r.width=i.__renderedWidth:void 0!==t.width&&(r.width="string"==typeof t.width?parseFloat(t.width):t.width);const s=o.get(t.field);s&&(r.sort=s);for(const o of e)if(o.getColumnState){const e=o.getColumnState(t.field);e&&Object.assign(r,e)}return r})}}applyState(e,t){if(!e.columns||0===e.columns.length)return;const o=this.columns,n=new Map(e.columns.map(e=>[e.field,e])),r=o.map(e=>{const t=n.get(e.field);if(!t)return e;const o={...e};return void 0!==t.width&&(o.width=t.width,o.__renderedWidth=t.width),void 0!==t.visible&&(o.hidden=!t.visible),o});r.sort((e,t)=>(n.get(e.field)?.order??1/0)-(n.get(t.field)?.order??1/0)),this.columns=r;const i=e.columns.filter(e=>void 0!==e.sort).sort((e,t)=>(e.sort?.priority??0)-(t.sort?.priority??0));if(i.length>0){const e=i[0];e.sort&&(this.#m._sortState={field:e.field,direction:"asc"===e.sort.direction?1:-1})}else this.#m._sortState=null;for(const s of t)if(s.applyColumnState)for(const t of e.columns)s.applyColumnState(t.field,t)}resetState(e){this.#q=void 0,this.#m._sortState=null,this.#k=this.#$(this.#L),this.#W();for(const t of e)if(t.applyColumnState)for(const e of this.columns)t.applyColumnState(e.field,{field:e.field,order:0,visible:!0});this.requestStateChange(e)}#V(){const e=/* @__PURE__ */new Map,t=this.#m._sortState;return t&&e.set(t.field,{direction:1===t.direction?"asc":"desc",priority:0}),e}requestStateChange(e){this.#z&&clearTimeout(this.#z),this.#z=setTimeout(()=>{this.#z=void 0;const t=this.collectState(e);this.#m._emit("column-state-change",t)},100)}setColumnVisible(e,t){const o=this.columns,n=o.find(t=>t.field===e);if(!n)return!1;if(!t&&n.lockVisible)return!1;if(!t){if(0===o.filter(t=>!t.hidden&&t.field!==e).length)return!1}return!!n.hidden!=!t&&(n.hidden=!t,this.#m._emit("column-visibility",{field:e,visible:t,visibleColumns:o.filter(e=>!e.hidden).map(e=>e.field)}),this.#m._clearRowPool(),this.#m._setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(t=>t.field===e);return!!t&&this.setColumnVisible(e,!!t.hidden)}isColumnVisible(e){const t=this.columns.find(t=>t.field===e);return!!t&&!t.hidden}showAllColumns(){const e=this.columns;e.some(e=>e.hidden)&&(e.forEach(e=>e.hidden=!1),this.#m._emit("column-visibility",{visibleColumns:e.map(e=>e.field)}),this.#m._clearRowPool(),this.#m._setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:!0===e.utility}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(e=>[e.field,e])),o=[];for(const n of e){const e=t.get(n);e&&(o.push(e),t.delete(n))}for(const n of t.values())o.push(n);this.columns=o,this.#m._invalidateVisibleColumnsCache(),ot(this.#m),Ie(this.#m),this.#m._requestSchedulerPhase(rt.COLUMNS,"configManager")}parseLightDomColumns(e){this.#H||(this.#M=Array.from(e.querySelectorAll("tbw-grid-column")),this.#H=this.#M.length?function(e){return Array.from(e.querySelectorAll("tbw-grid-column")).map(e=>{const t=e.getAttribute("field")||"";if(!t)return null;const o={field:t,type:e.getAttribute("type")||void 0,header:e.getAttribute("header")||void 0,sortable:e.hasAttribute("sortable")&&"false"!==e.getAttribute("sortable"),__element:e},n=e.getAttribute("width");if(n){const e=parseFloat(n);!isNaN(e)&&/^\d+(\.\d+)?$/.test(n.trim())?o.width=e:o.width=n}const r=e.getAttribute("minWidth")||e.getAttribute("min-width");if(r){const e=parseFloat(r);isNaN(e)||(o.minWidth=e)}e.hasAttribute("resizable")&&(o.resizable="false"!==e.getAttribute("resizable"));const i=e.getAttribute("options");i&&(o.options=i.split(",").map(e=>{const[t,o]=e.includes(":")?e.split(":"):[e.trim(),e.trim()];return{value:t.trim(),label:o?.trim()||t.trim()}}));const s=e.querySelector("tbw-grid-column-view"),l=e.querySelector("tbw-grid-column-editor"),a=e.querySelector("tbw-grid-column-header");s&&(o.__viewTemplate=s),a&&(o.__headerTemplate=a);const c=globalThis.DataGridElement,d=c?.getAdapters?.()??[],h=s??e,u=d.find(e=>e.canHandle(h));if(u){const e=u.createRenderer(h);e&&(o.viewRenderer=e)}const g=l??e,f=d.find(e=>e.canHandle(g));if(f){const e=f.createEditor(g);e&&(o.editor=e)}const p=d.find(t=>t.canHandle(e)&&(t.createHeaderRenderer||t.createHeaderLabelRenderer));if(p){const t=p.createHeaderRenderer?.(e);t&&(o.headerRenderer=t);const n=p.createHeaderLabelRenderer?.(e);n&&(o.headerLabelRenderer=n)}return o}).filter(e=>!!e)}(e):[])}clearLightDomCache(){this.#H=void 0}#U=/* @__PURE__ */new Map;registerLightDomHandler(e,t){this.#U.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#U.delete(e.toLowerCase())}observeLightDOM(e){this.#I&&this.#I.disconnect();const t=/* @__PURE__ */new Set,o=()=>{this.#N=void 0;for(const e of t){const t=this.#U.get(e);t?.()}t.clear()};this.#I=new MutationObserver(e=>{for(const o of e){for(const e of o.addedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;const o=e.tagName.toLowerCase();this.#U.has(o)&&t.add(o)}if("attributes"===o.type&&o.target.nodeType===Node.ELEMENT_NODE){const e=o.target.tagName.toLowerCase();this.#U.has(e)&&t.add(e)}}t.size>0&&!this.#N&&(this.#N=setTimeout(o,0))}),this.#I.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#D.push(e)}notifyChange(){for(const e of this.#D)e()}dispose(){this.#I?.disconnect(),this.#D=[],this.#z&&clearTimeout(this.#z),this.#N&&(clearTimeout(this.#N),this.#N=void 0)}}function lt(e){const t=document.createElement("div");return t.className="tbw-empty-message",t.textContent=e.filteredOut?"No matching rows":"No data to display",t}function at(e,t,o="rows"){const n=document.createElement("div");return n.className="tbw-empty-overlay",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),n.setAttribute("data-overlay-target",o),n.appendChild(function(e,t){const o=(t??lt)(e);if("string"==typeof o){const e=document.createElement("div");return e.className="tbw-empty-message",e.innerHTML=z(o),e}return o}(e,t)),n}function ct(e){e?.remove()}function dt(){if("undefined"!=typeof window&&window.location){const e=window.location.hostname;if("localhost"===e||"127.0.0.1"===e||"::1"===e)return!0}return"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV}function ht(e){return`<span role="checkbox" aria-checked="${e}" aria-label="${e}">${e?"&#x1F5F9;":"&#9744;"}</span>`}function ut(e){if(null==e||""===e)return"";if(e instanceof Date)return isNaN(e.getTime())?"":e.toLocaleDateString();if("number"==typeof e||"string"==typeof e){const t=new Date(e);return isNaN(t.getTime())?"":t.toLocaleDateString()}return""}function gt(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const o=e.closest(".data-grid-row");if(!o)return-1;const n=o.parentElement;if(!n)return-1;const r=n.querySelectorAll(":scope > .data-grid-row");for(let i=0;i<r.length;i++)if(r[i]===o)return i;return-1}function ft(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function pt(e){try{if("rtl"===getComputedStyle(e).direction)return"rtl"}catch{}try{const t=e.closest?.("[dir]")?.getAttribute("dir");if("rtl"===t)return"rtl"}catch{}return"ltr"}function wt(e){return"rtl"===pt(e)}function mt(e,t){return"left"===e||"right"===e?e:"rtl"===t?"start"===e?"right":"left":"start"===e?"left":"right"}function bt(e,t){const o=t.renderer||t.viewRenderer;if(o)return o;if(!t.type)return;const n=e.__frameworkAdapter;if(n?.getTypeDefault){const o=n.getTypeDefault(t.type,e._hostElement);if(o?.renderer)return o.renderer}}function vt(e,t){if(t.format)return t.format;if(!t.type)return;const o=e.__frameworkAdapter;if(o?.getTypeDefault){const n=o.getTypeDefault(t.type,e._hostElement);if(n?.format)return n.format}}const Ct='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function yt(e){return(e.__editingCellCount??0)>0}function _t(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing");e.querySelectorAll(`.cell.${X.EDITING}`).forEach(e=>e.classList.remove(X.EDITING))}const St=document.createElement("template");St.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Rt=document.createElement("template");function Et(){return St.content.firstElementChild.cloneNode(!0)}function Pt(){return Rt.content.firstElementChild.cloneNode(!0)}function xt(e){e.__cellDisplayCache=void 0,e.__cellCacheEpoch=void 0,e.__hasSpecialColumns=void 0}function At(e,t,o,i){const s=t.children,l=e._visibleColumns,a=l.length,c=s.length,d=a<c?a:c,h=e._focusRow,u=e._focusCol,g=e._hasAfterCellRenderHook?.()??!1;let f=e.__hasSpecialColumns;if(void 0===f){f=!1;const t=e.__frameworkAdapter;for(let o=0;o<a;o++){const n=l[o];if(n.__viewTemplate||n.__compiledView||n.renderer||n.viewRenderer||n.externalView||n.format||n.cellClass||"date"===n.type||"boolean"===n.type||n.type&&t?.getTypeDefault?.(n.type,e._hostElement)?.renderer||n.type&&t?.getTypeDefault?.(n.type,e._hostElement)?.format){f=!0;break}}e.__hasSpecialColumns=f}const p=String(i);if(f){for(let n=0;n<d;n++){if(l[n].externalView){if(!s[n].querySelector("[data-external-view]"))return void Tt(e,t,o,i)}}for(let a=0;a<d;a++){const c=l[a],d=s[a];d.getAttribute("data-row")!==p&&d.setAttribute("data-row",p);const f=d.classList.contains(X.EDITING);if(!f){const e=h===i&&u===a;e!==d.classList.contains("cell-focus")&&(d.classList.toggle("cell-focus",e),d.setAttribute("aria-selected",String(e)))}const m=c.cellClass;if(m){const t=d.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&d.classList.remove(e[t])}try{const e=m(Ne(o,c,i),o,c),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let o=0;o<t.length;o++){const n=t[o];n&&"string"==typeof n&&(d.classList.add(n),e+=(e?" ":"")+n)}d.setAttribute("data-dynamic-classes",e)}else d.removeAttribute("data-dynamic-classes")}catch(w){E(n,`cellClass callback error for column '${c.field}': ${w}`,e.id),d.removeAttribute("data-dynamic-classes")}}if(f)continue;const b=bt(e,c);if(b){const n=Ne(o,c,i),r=b({row:o,value:n,field:c.field,column:c,grid:e,cellEl:d});"string"==typeof r?(e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML=z(r)):r instanceof Node?r.parentElement!==d&&(e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML="",d.appendChild(r)):null==r&&(e.__frameworkAdapter?.releaseCell?.(d),d.textContent=null==n?"":String(n)),g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:n,cellElement:d,rowElement:t});continue}if(c.__compiledView){const n=Ne(o,c,i),r=c.__compiledView({row:o,value:n,field:c.field,column:c});c.__compiledView.__blocked?d.textContent="":(d.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML=z(r),$(d)),g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:n,cellElement:d,rowElement:t});continue}if(c.__viewTemplate){const n=Ne(o,c,i),r=c.__viewTemplate.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(r)?d.textContent="":(d.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML=z(q(r,{row:o,value:n})),$(d)),g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:n,cellElement:d,rowElement:t});continue}if(c.externalView)continue;const v=Ne(o,c,i);let C;d.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(d);const y=vt(e,c);if(y){try{const e=y(v,o);C=null==e?"":String(e)}catch(w){E(r,`Format error in column '${c.field}': ${w}`,e.id),C=null==v?"":String(v)}d.textContent=C}else"date"===c.type?(C=ut(v),d.textContent=C):"boolean"===c.type?d.innerHTML=ht(!!v):(C=null==v?"":String(v),d.textContent=C);g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:v,cellElement:d,rowElement:t})}}else for(let n=0;n<d;n++){const r=s[n];if(r.classList.contains(X.EDITING))continue;r.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(r);const a=l[n],c=Ne(o,a,i);r.textContent=null==c?"":String(c),r.getAttribute("data-row")!==p&&r.setAttribute("data-row",p);const d=h===i&&u===n;d!==r.classList.contains("cell-focus")&&(r.classList.toggle("cell-focus",d),r.setAttribute("aria-selected",String(d))),g&&e._afterCellRender?.({row:o,rowIndex:i,column:a,colIndex:n,value:c,cellElement:r,rowElement:t})}}function Tt(e,t,o,i){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const s=e.__frameworkAdapter;if(s?.releaseCell){s.beginBatch?.(e);try{const e=t.children;for(let t=e.length-1;t>=0;t--)s.releaseCell(e[t]);t.innerHTML=""}finally{s.endBatch?.(e)}}else t.innerHTML="";const l=e._visibleColumns,a=l.length,c=e._focusRow,d=e._focusCol,h=e._hasAfterCellRenderHook?.()??!1,u=document.createDocumentFragment();for(let f=0;f<a;f++){const s=l[f],a=Et();a.setAttribute("aria-colindex",String(f+1)),a.setAttribute("data-col",String(f)),a.setAttribute("data-row",String(i)),a.setAttribute("data-field",s.field),a.setAttribute("data-header",s.header??s.field),s.type&&a.setAttribute("data-type",s.type);let p=Ne(o,s,i);const w=vt(e,s);if(w)try{p=w(p,o)}catch(g){E(r,`Format error in column '${s.field}': ${g}`,e.id)}const m=s.__compiledView,b=s.__viewTemplate,v=bt(e,s),C=s.externalView;let y=!1;if(v){const t=v({row:o,value:p,field:s.field,column:s,grid:e,cellEl:a});"string"==typeof t?(a.innerHTML=z(t),y=!0):t instanceof Node?t.parentElement!==a&&(a.textContent="",a.appendChild(t)):null==t&&(a.textContent=null==p?"":String(p))}else if(C){const t=C,n=document.createElement("div");n.setAttribute("data-external-view",""),n.setAttribute("data-field",s.field),a.appendChild(n);const r={row:o,value:p,field:s.field,column:s,grid:e};if(t.mount)try{t.mount({placeholder:n,context:r,spec:t})}catch(g){E("TBW063",`External view mount error for column '${s.field}': ${g}`,e.id)}else queueMicrotask(()=>{try{e.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:n,spec:t,context:r}}))}catch(g){E("TBW064",`External view event dispatch error for column '${s.field}': ${g}`,e.id)}});n.setAttribute("data-mounted","")}else if(m){const e=m({row:o,value:p,field:s.field,column:s}),t=m.__blocked;a.innerHTML=t?"":z(e),y=!0,t&&(a.textContent="",a.setAttribute("data-blocked-template",""))}else if(b){const e=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(e)?(a.textContent="",a.setAttribute("data-blocked-template","")):(a.innerHTML=z(q(e,{row:o,value:p})),y=!0)}else w?a.textContent=null==p?"":String(p):"date"===s.type?a.textContent=ut(p):"boolean"===s.type?a.innerHTML=ht(!!p):a.textContent=null==p?"":String(p);if(y){$(a);const e=a.textContent||"";/Proxy|Reflect\.ownKeys/.test(e)&&(a.textContent=e.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(a.textContent||"")&&(a.textContent=""))}a.hasAttribute("data-blocked-template")&&(a.textContent||"").trim().length&&(a.textContent="");("function"==typeof s.editable?s.editable(o):s.editable)?a.tabIndex=0:"boolean"===s.type&&(a.hasAttribute("tabindex")||(a.tabIndex=0)),c===i&&d===f?(a.classList.add("cell-focus"),a.setAttribute("aria-selected","true")):a.setAttribute("aria-selected","false");const _=s.cellClass;if(_)try{const e=_(Ne(o,s,i),o,s),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(const o of t)o&&"string"==typeof o&&(a.classList.add(o),e+=(e?" ":"")+o);a.setAttribute("data-dynamic-classes",e)}}catch(g){E(n,`cellClass callback error for column '${s.field}': ${g}`,e.id)}h&&e._afterCellRender?.({row:o,rowIndex:i,column:s,colIndex:f,value:p,cellElement:a,rowElement:t}),u.appendChild(a)}t.appendChild(u)}function Ht(e,t,o){if(t.target?.closest(".resize-handle"))return;const n=gt(o.querySelector(".cell[data-row]"));if(n<0)return;const r=e._rows[n];if(!r)return;if(e._dispatchRowClick?.(t,n,r,o))return;const i=t.target?.closest(".cell[data-col]");if(i){const o=Number(i.getAttribute("data-col"));if(!isNaN(o)){if(e._dispatchCellClick?.(t,n,o,i))return;const r=e._focusRow!==n||e._focusCol!==o;if(e._focusRow=n,e._focusCol=o,i.classList.contains(X.EDITING)){r&&(ft(e._bodyEl??e),i.classList.add("cell-focus"));const o=t.target,n=i.contains(o)&&o.matches(Ct)?o:i.querySelector(Ct);try{n?.focus({preventScroll:!0})}catch{}return}Vt(e)}}}function Mt(e,t){return e&&"object"==typeof e?"__rowCacheKey"in e?e.__rowCacheKey:"rowId"in e&&null!=e.rowId?`id:${e.rowId}`:t?`id:${t(e)}`:e:e}function Lt(e,t,o){const n=Mt(t,o);return"string"==typeof n?e.byKey.get(n):n&&"object"==typeof n?e.byRef.get(n):void 0}function kt(e,t,o){if(t<0||t>=e.length)return;const n=e[t],r=o-n.height;if(0!==r){n.height=o,n.measured=!0;for(let o=t+1;o<e.length;o++)e[o].offset+=r}}function Ot(e,t){if(0===e.length)return-1;if(t<=0)return 0;let o=0,n=e.length-1;for(;o<=n;){const r=Math.floor((o+n)/2),i=e[r],s=i.offset+i.height;if(t<i.offset)n=r-1;else{if(!(t>=s))return r;o=r+1}}return Math.max(0,Math.min(o,e.length-1))}function Dt(e,t){const{positionCache:o,heightCache:n,rows:r,start:i,end:s,getPluginHeight:l,getRowId:a}=e;let c=!1;t.forEach(e=>{const t=e.dataset.rowIndex;if(!t)return;const d=parseInt(t,10);if(d<i||d>=s||d>=r.length)return;const h=r[d],u=l?.(h,d);if(void 0!==u){const e=o[d];return void((!e.measured||Math.abs(e.height-u)>1)&&(kt(o,d,u),c=!0))}const g=e.offsetHeight;if(g>0){const e=o[d];(!e.measured||Math.abs(e.height-g)>1)&&(kt(o,d,g),function(e,t,o,n){const r=Mt(t,n);"string"==typeof r?e.byKey.set(r,o):r&&"object"==typeof r&&e.byRef.set(r,o)}(n,h,g,a),c=!0)}});const d=c?function(e){let t=0;for(const o of e)o.measured&&t++;return t}(o):0,h=c?function(e,t){let o=0,n=0;for(const r of e)r.measured&&(o+=r.height,n++);return n>0?o/n:t}(o,e.defaultHeight):0;return{hasChanges:c,measuredCount:d,averageHeight:h}}Rt.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const It=335e5;function zt(e,t,o=It){return{rawContentHeight:e,spacerHeight:Math.min(e,o),viewportHeight:t,capped:e>o}}function Nt(e,t){if(!t.capped)return e;const o=t.spacerHeight-t.viewportHeight,n=t.rawContentHeight-t.viewportHeight;if(o<=0||n<=0)return e;const r=e*n/o;return r<0?0:r>n?n:r}function qt(e,t){if(!t.capped)return e;const o=t.spacerHeight-t.viewportHeight,n=t.rawContentHeight-t.viewportHeight;return o<=0||n<=0?e:e*o/n}function Ft(e){const{totalRows:t,viewportHeight:o,scrollTop:n,rowHeight:r,overscan:i,maxSpacerHeight:s=It}=e,l=Math.ceil(o/r),a=t*r,c=zt(a,o,s),d=Nt(n,c);let h=Math.floor(d/r)-i;h<0&&(h=0);let u=h+l+2*i;return u>t&&(u=t),u===t&&h>0&&(h=Math.max(0,u-l-2*i)),{start:h,end:u,offsetY:h*r,totalHeight:c.spacerHeight,rawContentHeight:a}}function $t(e,t){return e<=t}function Wt(e){"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit()}function Bt(e){if(!e)return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||!!e.isContentEditable}function Vt(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:o,viewportEl:n,scrollMapping:r}=e._virtualization,i=o,s=n?.clientHeight??i?.clientHeight??0;if(i&&s>0){const o=e._focusRow*t,n=r?Nt(i.scrollTop,r):i.scrollTop;if(o<n)i.scrollTop=r?qt(o,r):o;else if(o+t>n+s){const e=o-s+t;i.scrollTop=r?qt(e,r):e}}}const o=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;o||e.refreshVirtualWindow(!1),ft(e._bodyEl),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const n=e._focusRow,r=e._virtualization.start??0,i=e._virtualization.end??e._rows.length;if(n>=r&&n<i){const i=e._bodyEl.querySelectorAll(".data-grid-row")[n-r];let s=i?.children[e._focusCol];if(s&&s.classList?.contains("cell")||(s=i?.querySelector(`.cell[data-col="${e._focusCol}"]`)??i?.querySelector(".cell[data-col]")),s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const n=e.querySelector(".tbw-scroll-area");if(n&&s&&(!o||t?.forceHorizontalScroll))if(t?.forceScrollLeft)n.scrollLeft=0;else if(t?.forceScrollRight)n.scrollLeft=n.scrollWidth-n.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(i??void 0,s)??{left:0,right:0};if(!t.skipScroll){const e=s.getBoundingClientRect(),o=n.getBoundingClientRect(),r=e.left-o.left+n.scrollLeft,i=r+e.width,l=n.scrollLeft+t.left,a=n.scrollLeft+n.clientWidth-t.right;r<l?n.scrollLeft=r-t.left:i>a&&(n.scrollLeft=i-n.clientWidth+t.right)}}if(o&&s.classList.contains(X.EDITING)){const e=s.querySelector(Ct);if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(o&&!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}else if(!o){const t=document.activeElement;t instanceof HTMLElement&&t!==e&&"function"==typeof e.contains&&e.contains(t)&&!t.classList.contains("cell")&&!t.closest(".cell")||t===e||e.focus({preventScroll:!0})}}}}const Ut=/* @__PURE__ */new WeakMap;function Gt(e,t){const o=gt(t),n=function(e){if(!e)return-1;const t=e.getAttribute("data-col");return t?parseInt(t,10):-1}(t);if(o<0||n<0)return;e._focusRow=o,e._focusCol=n,ft(e._bodyEl),t.classList.add("cell-focus"),t.setAttribute("aria-selected","true");const r=t.closest("tbw-grid, [data-tbw-grid]");r&&document.activeElement!==r&&r.focus({preventScroll:!0})}function jt(e,t,o,n){let r=null;const i=o.composedPath?.();if(r=i&&i.length>0?i[0]:o.target,r&&!t.contains(r)){const e=document.elementFromPoint(o.clientX,o.clientY);e&&(r=e)}const s=r?.closest?.("[data-col]"),l=r?.closest?.(".data-grid-row"),a=r?.closest?.(".header-row");let c,d,h,u,g,f;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(h=e._rows[c],f=e._visibleColumns[d],u=f?.field,g=h&&u?h[u]:void 0)),{type:n,row:h,rowIndex:void 0!==c&&c>=0?c:void 0,colIndex:void 0!==d&&d>=0?d:void 0,field:u,value:g,column:f,originalEvent:o,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:void 0!==c&&void 0!==d&&c>=0&&d>=0?{row:c,col:d}:void 0}}function Yt(e,t,o,n){t.addEventListener("keydown",t=>function(e,t){if(e._dispatchKeyDown?.(t))return;const o=e._rows.length-1,n=e._visibleColumns.length-1,r=void 0!==e._activeEditRows&&-1!==e._activeEditRows,i=e._visibleColumns[e._focusCol],s=i?.type,l=t.composedPath?.()??[],a=l.length?l[0]:t.target;if((!a||a===e||a.closest?.(".rows-body"))&&(!Bt(a)||"Home"!==t.key&&"End"!==t.key)&&!(Bt(a)&&("ArrowUp"===t.key||"ArrowDown"===t.key)&&"INPUT"===a.tagName&&"number"===a.type||Bt(a)&&("ArrowLeft"===t.key||"ArrowRight"===t.key)||Bt(a)&&("Enter"===t.key||"Escape"===t.key)||r&&"select"===s&&("ArrowDown"===t.key||"ArrowUp"===t.key))){switch(t.key){case"Tab":return t.preventDefault(),t.shiftKey?e._focusCol>0?e._focusCol-=1:e._focusRow>0&&(e._activeEditRows===e._focusRow&&Wt(e),e._focusRow-=1,e._focusCol=n):e._focusCol<n?e._focusCol+=1:(Wt(e),e._focusRow<o&&(e._focusRow+=1,e._focusCol=0)),void Vt(e);case"ArrowDown":r&&Wt(e),e._focusRow=Math.min(o,e._focusRow+1),t.preventDefault();break;case"ArrowUp":r&&Wt(e),e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault();break;case"ArrowRight":{const o=wt(e);e._focusCol=o?Math.max(0,e._focusCol-1):Math.min(n,e._focusCol+1),t.preventDefault();break}case"ArrowLeft":{const o=wt(e);e._focusCol=o?Math.min(n,e._focusCol+1):Math.max(0,e._focusCol-1),t.preventDefault();break}case"Home":return t.ctrlKey||t.metaKey?(r&&Wt(e),e._focusRow=0,e._focusCol=0):e._focusCol=0,t.preventDefault(),void Vt(e,{forceScrollLeft:!0});case"End":return t.ctrlKey||t.metaKey?(r&&Wt(e),e._focusRow=o,e._focusCol=n):e._focusCol=n,t.preventDefault(),void Vt(e,{forceScrollRight:!0});case"PageDown":e._focusRow=Math.min(o,e._focusRow+20),t.preventDefault();break;case"PageUp":e._focusRow=Math.max(0,e._focusRow-20),t.preventDefault();break;case"Enter":{const o=e._focusRow,n=e._focusCol,r=e._visibleColumns[n],i=e._rows[o],s=r?.field??"",l=s&&i?i[s]:void 0,a=e.querySelector(`[data-row="${o}"][data-col="${n}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,detail:{rowIndex:o,colIndex:n,column:r,field:s,value:l,row:i,cellEl:a,trigger:"keyboard",originalEvent:t}});if(e.dispatchEvent(c),c.defaultPrevented)return void t.preventDefault();break}default:return}Vt(e)}}(e,t),{signal:n}),o.addEventListener("mousedown",t=>function(e,t,o){const n=jt(e,t,o,"mousedown");e._dispatchCellMouseDown?.(n)&&Ut.set(e,!0)}(e,o,t),{signal:n}),document.addEventListener("mousemove",t=>function(e,t,o){if(!Ut.get(e))return;const n=jt(e,t,o,"mousemove");e._dispatchCellMouseMove?.(n)}(e,o,t),{signal:n}),document.addEventListener("mouseup",t=>function(e,t,o){if(!Ut.get(e))return;const n=jt(e,t,o,"mouseup");e._dispatchCellMouseUp?.(n),Ut.set(e,!1)}(e,o,t),{signal:n})}let Xt;function Kt(e){Xt=e}class Zt{#m;#G=/* @__PURE__ */new Set;#j=/* @__PURE__ */new Map;#Y=null;#X=null;constructor(e){this.#m=e,this.#K()}focusCell(e,t){const o=this.#m,n=o._rows.length-1;if(n<0)return;let r;if("string"==typeof t){if(r=o._visibleColumns.findIndex(e=>e.field===t),r<0)return}else r=t;const i=o._visibleColumns.length-1;i<0||(o._focusRow=Math.max(0,Math.min(e,n)),o._focusCol=Math.max(0,Math.min(r,i)),Vt(o))}get focusedCell(){const e=this.#m;if(0===e._rows.length||0===e._visibleColumns.length)return null;const t=e._visibleColumns[e._focusCol];return{rowIndex:e._focusRow,colIndex:e._focusCol,field:t?.field??""}}scrollToRow(e,t){const o=this.#m._virtualization;if(!o.enabled)return;const n=o.container;if(!n)return;const r=this.#m._rows.length;if(0===r)return;const i=Math.max(0,Math.min(e,r-1)),s=t?.align??"nearest",l=t?.behavior??"instant";let a,c;const d=o.positionCache;o.variableHeights&&d&&d.length>i?(a=d[i].offset,c=d[i].height):(a=i*o.rowHeight,c=o.rowHeight);const h=o.viewportEl?.clientHeight??n.clientHeight??0;if(h<=0)return;const u=n.scrollTop,g=a+c,f=u+h;let p;switch(s){case"start":p=a;break;case"center":p=a-h/2+c/2;break;case"end":p=g-h;break;default:if(a>=u&&g<=f)return;p=a<u?a:g-h}p=Math.max(0,p);const w=qt(p,o.scrollMapping);"smooth"===l?n.scrollTo({top:w,behavior:"smooth"}):n.scrollTop=w}scrollToRowById(e,t){const o=this.#m._getRowEntry(e);o&&this.scrollToRow(o.index,t)}registerExternalFocusContainer(e){if(this.#G.has(e))return;this.#G.add(e);const t=new AbortController,o=t.signal,n=this.#m;e.addEventListener("focusin",e=>{n.dataset.hasFocus="",this.#Z(e.target)},{signal:o}),e.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&this.containsFocus(t)||delete n.dataset.hasFocus,null===t&&this.#Q()},{signal:o}),this.#j.set(e,()=>t.abort())}unregisterExternalFocusContainer(e){this.#G.delete(e);const t=this.#j.get(e);t&&(t(),this.#j.delete(e))}containsFocus(e){const t=e??document.activeElement;return!!t&&(!!this.#m.contains(t)||this.isInExternalFocusContainer(t))}isInExternalFocusContainer(e){for(const t of this.#G)if(t.contains(e))return!0;return!1}#K(){const e=this.#m,t=new AbortController,o=t.signal;e.addEventListener("focusin",e=>this.#Z(e.target),{signal:o,capture:!0}),e.addEventListener("focusout",e=>{null===e.relatedTarget&&this.#Q()},{signal:o}),this.#X=()=>t.abort()}#Z(e){if(!(e instanceof HTMLElement))return;if(e===this.#m)return;const t=e.closest?.(".cell");t&&!t.classList.contains("editing")||this.isInExternalFocusContainer(e)||(this.#Y=e)}#Q(){queueMicrotask(()=>{if(!this.#m.isConnected)return;document.activeElement===document.body&&this.restoreLastFocus()})}restoreLastFocus(){const e=this.#Y;if(!e)return!1;if(!e.isConnected)return this.#Y=null,!1;if(e===document.activeElement)return!0;try{e.focus({preventScroll:!0})}catch{return!1}return document.activeElement===e}get lastFocusedElement(){return this.#Y?.isConnected?this.#Y:null}destroy(){for(const e of this.#j.values())e();this.#j.clear(),this.#G.clear(),this.#X?.(),this.#X=null,this.#Y=null}}const Qt="function"==typeof requestIdleCallback;function Jt(e){Qt?cancelIdleCallback(e):clearTimeout(e)}function eo(e,t){if(t){const o=t({size:e});if("string"==typeof o){const e=document.createElement("div");return e.innerHTML=o,e}return o}return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function to(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const o=document.createElement("div");o.className="tbw-row-loading-spinner",t.appendChild(o),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}function oo(e){let t=null,o=null,n=null,r=null;const i=n=>{if(!t)return;const r=n.clientX-t.startX,i=Math.max(40,t.startWidth+r),s=e._visibleColumns[t.colIndex];s.width=i,s.__userResized=!0,s.__renderedWidth=i,null==o&&(o=requestAnimationFrame(()=>{o=null,e.updateTemplate?.()})),e.dispatchEvent(new CustomEvent("column-resize",{detail:{field:s.field,width:i}}))};let s=!1;const l=()=>{const o=null!==t;o&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",l),null!==n&&(document.documentElement.style.cursor=n,n=null),null!==r&&(document.body.style.userSelect=r,r=null),t=null,o&&e.requestStateChange&&e.requestStateChange()};return{get isResizing(){return null!==t||s},start(o,s,a){o.preventDefault();const c=e._headerRowEl??e.findHeaderRow?.();c&&function(t,o){const n=o.querySelectorAll(".cell");for(let r=0;r<e._visibleColumns.length;r++){if(r===t)continue;const o=e._visibleColumns[r];if(null==o.width&&!o.__userResized){const e=n[r],t=e?.getBoundingClientRect().width;t&&(o.width=Math.round(t),o.__userResized=!0,o.__renderedWidth=o.width)}}}(s,c);const d=e._visibleColumns[s],h="number"==typeof d?.width?d.width:void 0,u=d?.__renderedWidth??h??a.getBoundingClientRect().width;t={startX:o.clientX,colIndex:s,startWidth:u},window.addEventListener("mousemove",i),window.addEventListener("mouseup",l),null===n&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",null===r&&(r=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(t){const o=e._visibleColumns[t];o&&(o.__userResized=!1,o.__renderedWidth=void 0,o.width=o.__originalWidth,e.updateTemplate?.(),e.requestStateChange?.(),e.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:o.field,width:o.width}})))},dispose(){l()}}}const no="data-animating",ro={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},io={change:500,insert:300,remove:200};function so(e,t){const o=ro[t],n=getComputedStyle(e).getPropertyValue(o);if(n){const e=function(e){const t=e.trim().toLowerCase();return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?1e3*parseFloat(t):parseFloat(t)}(n);if(!isNaN(e)&&e>0)return e}return io[t]}function lo(e,t,o){if(t<0)return Promise.resolve(!1);const n=e.findRenderedRowElement?.(t);return n?new Promise(e=>{!function(e,t,o){e.removeAttribute(no),e.offsetWidth,e.setAttribute(no,t);const n=so(e,t);setTimeout(()=>{"remove"!==t&&e.removeAttribute(no),o?.()},n)}(n,o,()=>e(!0))}):Promise.resolve(!1)}function ao(e,t){if(t)return t(e);const o=e;return"id"in o&&null!=o.id?String(o.id):"_id"in o&&null!=o._id?String(o._id):void 0}function co(e,t,o){const n=ao(e,o);return void 0===n&&R("TBW040",'Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.',t),n}class ho{#m;constructor(e){this.#m=e}resolveRowId(e){return co(e,this.#m.id,this.#m.effectiveConfig?.getRowId)}getRow(e){return this.#m._getRowEntry(e)?.row}getRowEntry(e){return this.#m._getRowEntry(e)}updateRow(e,t,n="api"){const r=this.#m,i=r._getRowEntry(e);i||R(o,`Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`,r.id);const{row:s,index:l}=i,a=[];for(const[o,c]of Object.entries(t)){const e=s[o];e!==c&&(a.push({field:o,oldValue:e,newValue:c}),s[o]=c,qe(s,o))}for(const{field:o,oldValue:c,newValue:d}of a)r.dispatchEvent(new CustomEvent("cell-change",{detail:{row:s,rowId:e,rowIndex:l,field:o,oldValue:c,newValue:d,changes:t,source:n},bubbles:!0,composed:!0}));a.length>0&&(xt(r),r._requestSchedulerPhase(rt.VIRTUALIZATION,"updateRow"),r._emitDataChange())}updateRows(e,t="api"){const n=this.#m;let r=!1;for(const{id:i,changes:s}of e){const e=n._getRowEntry(i);e||R(o,`Row with ID "${i}" not found. Ensure the row exists and getRowId is correctly configured.`,n.id);const{row:l,index:a}=e;for(const[o,c]of Object.entries(s)){const e=l[o];e!==c&&(r=!0,l[o]=c,qe(l,o),n.dispatchEvent(new CustomEvent("cell-change",{detail:{row:l,rowId:i,rowIndex:a,field:o,oldValue:e,newValue:c,changes:s,source:t},bubbles:!0,composed:!0})))}}r&&(xt(n),n._requestSchedulerPhase(rt.VIRTUALIZATION,"updateRows"),n._emitDataChange())}async insertRow(e,t,o=!0){const n=this.#m,r=Math.max(0,Math.min(e,n._rows.length));n.sourceRows=[...n.sourceRows,t];const i=[...n._rows];i.splice(r,0,t),n._rows=i,n._sortState&&(n.__originalOrder=[...n.__originalOrder,t]),xt(n),n._rebuildRowIdMap(),n.__rowRenderEpoch++;for(let s=0;s<n._rowPool.length;s++)n._rowPool[s].__epoch=-1;n.refreshVirtualWindow(!0),n._emitPluginEvent("row-inserted",{row:t,index:r}),n._emitDataChange(),o&&(await new Promise(e=>requestAnimationFrame(()=>e())),await lo(n,r,"insert"))}async removeRow(e,t=!0){const o=this.#m,n=o._rows[e];if(!n)return;t&&await lo(o,e,"remove");const r=o._rows.indexOf(n);if(r<0)return n;const i=[...o._rows];i.splice(r,1),o._rows=i;const s=o.sourceRows.indexOf(n);if(s>=0){const e=[...o.sourceRows];e.splice(s,1),o.sourceRows=e}if(o._sortState){const e=o.__originalOrder.indexOf(n);if(e>=0){const t=[...o.__originalOrder];t.splice(e,1),o.__originalOrder=t}}xt(o),o._rebuildRowIdMap(),o.__rowRenderEpoch++;for(let l=0;l<o._rowPool.length;l++)o._rowPool[l].__epoch=-1;return o.refreshVirtualWindow(!0),o._emitDataChange(),t&&requestAnimationFrame(()=>{const e=o.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),n}async applyTransaction(e,t=!0){const o=this.#m,n={added:[],updated:[],removed:[]};if(e.remove?.length)for(const{id:l}of e.remove){const e=o._getRowEntry(l);if(!e)continue;const{row:r}=e;if(t){const e=o._rows.indexOf(r);e>=0&&await lo(o,e,"remove")}const i=o._rows.indexOf(r);if(i<0){n.removed.push(r);continue}const s=[...o._rows];s.splice(i,1),o._rows=s;const a=o.sourceRows.indexOf(r);if(a>=0){const e=[...o.sourceRows];e.splice(a,1),o.sourceRows=e}if(o._sortState){const e=o.__originalOrder.indexOf(r);if(e>=0){const t=[...o.__originalOrder];t.splice(e,1),o.__originalOrder=t}}n.removed.push(r)}const r=new Set(e.remove?.map(e=>e.id));if(e.update?.length)for(const{id:l,changes:a}of e.update){if(r.has(l))continue;const e=o._getRowEntry(l);if(!e)continue;const{row:t,index:i}=e;let s=!1;for(const[n,r]of Object.entries(a)){const e=t[n];e!==r&&(s=!0,t[n]=r,qe(t,n),o.dispatchEvent(new CustomEvent("cell-change",{detail:{row:t,rowId:l,rowIndex:i,field:n,oldValue:e,newValue:r,changes:a,source:"api"},bubbles:!0,composed:!0})))}s&&n.updated.push(t)}if(e.add?.length)for(const l of e.add){o.sourceRows=[...o.sourceRows,l];const e=[...o._rows];e.push(l),o._rows=e,o._sortState&&(o.__originalOrder=[...o.__originalOrder,l]),n.added.push(l)}const i=n.added.length>0||n.removed.length>0,s=n.updated.length>0;if(i){xt(o),o._rebuildRowIdMap(),o.__rowRenderEpoch++;for(let e=0;e<o._rowPool.length;e++)o._rowPool[e].__epoch=-1;o.refreshVirtualWindow(!0)}else s&&(xt(o),o._requestSchedulerPhase(rt.VIRTUALIZATION,"applyTransaction"));if((i||s)&&o._emitDataChange(),t&&n.added.length>0){await new Promise(e=>requestAnimationFrame(()=>e()));for(const e of n.added){const t=o._rows.indexOf(e);t>=0&&await lo(o,t,"insert")}}if(t&&n.updated.length>0)for(const l of n.updated){const e=o._rows.indexOf(l);e>=0&&await lo(o,e,"change")}return t&&n.removed.length>0&&requestAnimationFrame(()=>{const e=o.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),n}#J=null;#ee=[];#te=null;applyTransactionAsync(e){return this.#J||(this.#J={add:[],update:[],remove:[]}),e.add&&this.#J.add.push(...e.add),e.update&&this.#J.update.push(...e.update),e.remove&&this.#J.remove.push(...e.remove),new Promise(e=>{this.#ee.push(e),null===this.#te&&(this.#te=requestAnimationFrame(()=>{this.#te=null;const e=this.#J,t=this.#ee;this.#J=null,this.#ee=[],this.applyTransaction(e,!1).then(e=>{for(const o of t)o(e)})}))})}}const uo="tbw-grid-styles";let go="";const fo=/* @__PURE__ */new Map;function po(){const e=function(){const e=Ho.activeTag;return e===Ho.tagName?uo:`${uo}-${e}`}();let t=document.getElementById(e);return t||(t=document.createElement("style"),t.id=e,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function wo(e){const t=Ho.activeTag;return t===Ho.tagName?e:e.replace(/(?<![-\w])tbw-grid(?![-\w])/g,t)}function mo(){const e=po(),t=Array.from(fo.values()).join("\n");e.textContent=`${go}\n\n/* Plugin Styles */\n${t}`}async function bo(e){if(go)return;if("string"==typeof e&&e.length>0)return go=wo(e),void mo();await new Promise(e=>setTimeout(e,50));const t=function(){try{for(const e of Array.from(document.styleSheets))try{const t=Array.from(e.cssRules||[]).map(e=>e.cssText).join("\n");if(t.includes(".tbw-grid-root")&&t.includes("tbw-grid"))return t}catch{continue}}catch(e){E("TBW120",`Failed to extract grid.css from document stylesheets: ${e}`)}return null}();t?(go=wo(t),mo()):"undefined"!=typeof process&&"test"===process.env?.NODE_ENV||E("TBW121",`Could not find grid.css in document.styleSheets. Grid styling will not work. Available stylesheets: ${Array.from(document.styleSheets).map(e=>e.href||"(inline)").join(", ")}`)}function vo(e){e.startY=null,e.startX=null,e.lastY=null,e.lastX=null,e.lastTime=null,e.locked=!1}function Co(e){e.momentumRaf&&(cancelAnimationFrame(e.momentumRaf),e.momentumRaf=0)}function yo(e,t){if(null!==e.lastTime){performance.now()-e.lastTime>60&&(e.velocityY=0,e.velocityX=0)}(Math.abs(e.velocityY)>.1||Math.abs(e.velocityX)>.1)&&function(e,t){const o=.95,n=1;let r=performance.now();const i=()=>{const s=performance.now(),l=s-r;r=s;const a=l/16,c=Math.pow(o,a);e.velocityY*=c,e.velocityX*=c;const d=16*e.velocityY,h=16*e.velocityX,u=Math.abs(d)>=n,g=Math.abs(h)>=n;u&&(t.fauxScrollbar.scrollTop+=d),g&&t.scrollArea&&(t.scrollArea.scrollLeft+=h),e.momentumRaf=u||g?requestAnimationFrame(i):0};e.momentumRaf=requestAnimationFrame(i)}(e,t),vo(e)}function _o(e,t,o,n){e.addEventListener("pointerdown",o=>{"touch"===o.pointerType&&null===t.activePointerId&&(t.activePointerId=o.pointerId,e.setPointerCapture(o.pointerId),function(e,t,o){Co(o),o.startY=t,o.startX=e,o.lastY=t,o.lastX=e,o.lastTime=performance.now(),o.velocityY=0,o.velocityX=0,o.locked=!1}(o.clientX,o.clientY,t))},{passive:!0,signal:n}),e.addEventListener("pointermove",e=>{if(e.pointerId!==t.activePointerId)return;const n=function(e,t,o,n){if(null===o.lastY||null===o.lastX)return!1;const r=performance.now(),i=o.lastY-t,s=o.lastX-e;if(null!==o.lastTime){const e=r-o.lastTime;e>0&&(o.velocityY=i/e,o.velocityX=s/e)}if(o.lastY=t,o.lastX=e,o.lastTime=r,o.locked){const{scrollTop:e,scrollHeight:t,clientHeight:o}=n.fauxScrollbar;if(i>0&&e<t-o||i<0&&e>0?n.fauxScrollbar.scrollTop+=i:0!==i&&window.scrollBy(0,i),n.scrollArea){const{scrollLeft:e,scrollWidth:t,clientWidth:o}=n.scrollArea;s>0&&e<t-o||s<0&&e>0?n.scrollArea.scrollLeft+=s:0!==s&&window.scrollBy(s,0)}return!0}const l=null!==o.startY?Math.abs(o.startY-t):0,a=null!==o.startX?Math.abs(o.startX-e):0;if(l<3&&a<3)return!1;const c=l>=a,{scrollHeight:d,clientHeight:h}=n.fauxScrollbar,u=d-h>0;let g=!1;if(n.scrollArea){const{scrollWidth:e,clientWidth:t}=n.scrollArea;g=e-t>0}return!!(c&&u||!c&&g)&&(o.locked=!0,n.fauxScrollbar.scrollTop+=i,n.scrollArea&&(n.scrollArea.scrollLeft+=s),!0)}(e.clientX,e.clientY,t,o);n&&e.preventDefault()},{passive:!1,signal:n}),e.addEventListener("pointerup",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,yo(t,o))},{passive:!0,signal:n}),e.addEventListener("pointercancel",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,vo(t))},{passive:!0,signal:n}),e.addEventListener("lostpointercapture",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,vo(t))},{passive:!0,signal:n})}const So=[{property:"editable",pluginName:"editing",level:"column",description:"",isUsed:e=>!0===e||"function"==typeof e},{property:"editor",pluginName:"editing",level:"column",description:""},{property:"editorParams",pluginName:"editing",level:"column",description:""},{property:"group",pluginName:"groupingColumns",level:"column",description:""},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:"",isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e}],Ro=[{property:"rowEditable",pluginName:"editing",level:"config",description:"",isUsed:e=>"function"==typeof e},{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:"",isUsed:e=>Array.isArray(e)&&e.length>0}];function Eo(e){return`import { ${Po(e)}Plugin } from '@toolbox-web/grid/plugins/${t=e,t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}';`;var t}function Po(e){return e.charAt(0).toUpperCase()+e.slice(1)}function xo(e,t){return e.some(e=>e.name===t)}class Ao{#m;state;constructor(e,t){this.#m=e,this.state={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:/* @__PURE__ */new Map,byRef:/* @__PURE__ */new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null,scrollMapping:{rawContentHeight:0,spacerHeight:0,viewportHeight:0,capped:!1},...t}}updateCachedGeometry(){const e=this.state,t=e.container,o=e.viewportEl??t;o&&(e.cachedViewportHeight=o.clientHeight),t&&(e.cachedFauxHeight=t.clientHeight);const n=e.scrollAreaEl;n&&(e.cachedScrollAreaHeight=n.clientHeight)}calculateTotalSpacerHeight(e,t=!1){const o=this.state;let n,r,i;if(t){const e=o.container??this.#m._hostElement,t=o.viewportEl??e,s=o.scrollAreaEl;n=e?.clientHeight??0,r=t?.clientHeight??0,i=s?s.clientHeight:n,o.cachedFauxHeight=n,o.cachedViewportHeight=r,o.cachedScrollAreaHeight=i}else n=o.cachedFauxHeight,r=o.cachedViewportHeight,i=o.cachedScrollAreaHeight||n;const s=i-r,l=Math.max(0,n-i);let a;return a=o.variableHeights&&o.positionCache?function(e){if(0===e.length)return 0;const t=e[e.length-1];return t.offset+t.height}(o.positionCache):e*o.rowHeight,o.scrollMapping=zt(a,r),o.scrollMapping.spacerHeight+s+l}initializePositionCache(){const e=this.state;if(!e.variableHeights)return;const t=this.#m,o=t._rows,n=e.rowHeight||28,r=t.effectiveConfig?.rowHeight,i=t.effectiveConfig?.getRowId,s=i?e=>i(e):void 0;e.positionCache=function(e,t,o,n,r){const i=new Array(e.length);let s=0;for(let l=0;l<e.length;l++){const a=e[l];let c=r?.(a,l),d=void 0!==c;void 0===c&&(c=Lt(t,a,n.rowId),d=void 0!==c),void 0===c&&(c=o,d=!1),i[l]={offset:s,height:c,measured:d},s+=c}return i}(o,e.heightCache,n,{rowId:s},(e,o)=>{const n=t._getPluginRowHeight(e,o);if(void 0!==n)return n;if(r){const t=r(e,o);if(void 0!==t&&t>0)return t}});const l=function(e,t,o,n){let r=0,i=0;for(let s=0;s<e.length;s++){const o=e[s];if(o.measured){const e=n?.(t[s],s);void 0===e&&(i+=o.height,r++)}}return{measuredCount:r,averageHeight:r>0?i/r:o}}(e.positionCache,o,n,(e,o)=>t._getPluginRowHeight(e,o));e.measuredCount=l.measuredCount,l.measuredCount>0&&(e.averageHeight=l.averageHeight)}invalidateRowHeight(e,t){const o=this.state;if(!o.variableHeights)return;if(!o.positionCache)return;const n=this.#m._rows;if(e<0||e>=n.length)return;const r=n[e];let i=t;void 0===i&&(i=this.#m._getPluginRowHeight(r,e)),void 0===i&&(i=o.rowHeight);const s=o.positionCache[e];if(s&&!(Math.abs(s.height-i)<1)&&(kt(o.positionCache,e,i),o.totalHeightEl)){const e=this.calculateTotalSpacerHeight(n.length);o.totalHeightEl.style.height=`${e}px`}}measureRenderedRowHeights(e,t){const o=this.state;if(!o.variableHeights)return;if(!o.positionCache)return;const n=this.#m,r=n._bodyEl;if(!r)return;const i=r.querySelectorAll(".data-grid-row"),s=n.effectiveConfig?.getRowId,l=n._rows,a=Dt({positionCache:o.positionCache,heightCache:o.heightCache,rows:l,defaultHeight:o.rowHeight,start:e,end:t,getPluginHeight:(e,t)=>n._getPluginRowHeight(e,t),getRowId:s?e=>s(e):void 0},i);if(a.hasChanges&&(o.measuredCount=a.measuredCount,o.averageHeight=a.averageHeight,o.totalHeightEl)){const e=this.calculateTotalSpacerHeight(l.length);o.totalHeightEl.style.height=`${e}px`}}refreshVirtualWindow(e=!1,t=!1){const o=this.state,n=this.#m,r=n._bodyEl;if(!r)return!1;const i=n._rows.length;if(!o.enabled)return n._renderVisibleRows(0,i),t||n._afterPluginRender(),!0;if(i<=o.bypassThreshold)return o.start=0,o.end=i,e&&(r.style.transform="translateY(0px)"),n._renderVisibleRows(0,i,n.__rowRenderEpoch),e&&o.variableHeights&&this.initializePositionCache(),e&&o.totalHeightEl&&(o.totalHeightEl.style.height=`${this.calculateTotalSpacerHeight(i,!0)}px`),n._updateAriaCounts(i,n._visibleColumns.length),t||n._afterPluginRender(),!0;const s=o.container,l=o.viewportEl??s,a=e?o.cachedViewportHeight=l.clientHeight:o.cachedViewportHeight||(o.cachedViewportHeight=l.clientHeight),c=o.rowHeight,d=Nt(s.scrollTop,o.scrollMapping);let h;e&&o.variableHeights&&this.initializePositionCache();const u=o.positionCache;o.variableHeights&&u&&u.length>0?(h=Ot(u,d),-1===h&&(h=0)):h=Math.floor(d/c),h-=h%2,h<0&&(h=0),i>0&&h>i-1&&(h=i-1);const g=n._adjustPluginVirtualStart(h,d,c);let f;if(void 0!==g&&g<h&&(h=g,h-=h%2,h<0&&(h=0)),o.variableHeights&&u&&u.length>0){const e=a+3*c;let t=0;for(f=h;f<i&&t<e;)t+=u[f].height,f++;const o=Math.ceil(a/c)+3;f-h<o&&(f=Math.min(h+o,i))}else{f=h+(Math.ceil(a/c)+3)}f>i&&(f=i);const p=o.start,w=o.end;if(!e&&h===p&&f===w)return!1;o.start=h,o.end=f;const m=e?o.cachedFauxHeight=s.clientHeight:o.cachedFauxHeight||(o.cachedFauxHeight=s.clientHeight);if(e){const e=o.scrollAreaEl;e&&(o.cachedScrollAreaHeight=e.clientHeight)}if(0===m&&a>0)return n._requestSchedulerPhase(rt.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&o.totalHeightEl){const e=this.calculateTotalSpacerHeight(i);o.totalHeightEl.style.height=`${e}px`}let b;b=o.variableHeights&&u&&u[h]?u[h].offset:h*c;const v=-(d-b);return r.style.transform=`translateY(${v}px)`,n._renderVisibleRows(h,f,n.__rowRenderEpoch),e&&o.variableHeights&&this.measureRenderedRowHeights(h,f),n._updateAriaCounts(i,n._visibleColumns.length),e&&!t&&(n._afterPluginRender(),queueMicrotask(()=>{if(!o.totalHeightEl)return;const e=this.calculateTotalSpacerHeight(i);0===o.cachedFauxHeight&&o.cachedViewportHeight>0||(o.totalHeightEl.style.height=`${e}px`)})),!0}}class To{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=/* @__PURE__ */new Map;cellRenderers=/* @__PURE__ */new Map;headerRenderers=/* @__PURE__ */new Map;cellEditors=/* @__PURE__ */new Map;_hasAfterCellRender=!1;_hasAfterRowRender=!1;_hasProcessRows=!1;_hasRowStructurePlugins=!1;#oe=/* @__PURE__ */new Map;eventListeners=/* @__PURE__ */new Map;queryHandlers=/* @__PURE__ */new Map;attachAll(e){const t=this.#ne(e);for(const o of t)this.attach(o)}#ne(e){if(e.length<2)return e;const t=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map,n=[];for(const r of e){const e=r.constructor,i=t.get(e);if(!i){t.set(e,r),n.push(r);continue}const s=o.get(i)??[];s.push(r),o.set(i,s)}if(0===o.size)return n;for(const[r,i]of o)r.mergeConfigsFrom(i);return n}attach(e){if(function(e,o,n){const r=e.name,i=e.constructor.dependencies??[];for(const s of i){if(s.when&&!s.when(e.resolvedConfig))continue;const i=s.name,l=s.required??!0,a=s.reason;if(o.some(e=>e.name===i))continue;const c=s.severity??(l?"error":void 0);if(!c)continue;const d="error"===c?"requires":"recommends",h=a??`${Po(r)}Plugin ${d} ${Po(i)}Plugin`;if("error"===c){const e=Eo(i);R("TBW020",`Plugin dependency error:\n\n${h}.\n\n → Add the plugin to your gridConfig.plugins array BEFORE ${Po(r)}Plugin:\n ${e}\n plugins: [new ${Po(i)}Plugin(), new ${Po(r)}Plugin()]`,n)}else dt()&&("warn"===c?E(t,`${h}.`,n):P(t,`${h}.`,n))}}(e,this.plugins,this.grid.getAttribute("id")??void 0),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,o]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,o);if(e.headerRenderers)for(const[t,o]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,o);if(e.cellEditors)for(const[t,o]of Object.entries(e.cellEditors))this.cellEditors.set(t,o);this.registerQueryHandlers(e),e.attach(this.grid),this.#re();for(const t of this.plugins)t!==e&&t.onPluginAttached&&t.onPluginAttached(e.name,e)}registerQueryHandlers(e){const t=e.constructor.manifest;if(t?.queries)for(const o of t.queries){let t=this.queryHandlers.get(o.type);t||(t=/* @__PURE__ */new Set,this.queryHandlers.set(o.type,t)),t.add(e)}}unregisterQueryHandlers(e){for(const[t,o]of this.queryHandlers)o.delete(e),0===o.size&&this.queryHandlers.delete(t)}detachAll(){for(const e of this.plugins)for(const t of this.plugins)t!==e&&t.onPluginDetached&&t.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--){const t=this.plugins[e];this.unsubscribeAll(t),this.unregisterQueryHandlers(t),t.detach()}this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear(),this.eventListeners.clear(),this.queryHandlers.clear(),this._hasAfterCellRender=!1,this._hasAfterRowRender=!1,this._hasProcessRows=!1,this.#oe.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e||t.aliases?.includes(e))}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getRegisteredPluginNames(){return this.plugins.map(e=>e.name)}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getPluginStyles(){return this.plugins.filter(e=>e.styles).map(e=>({name:e.name,styles:e.styles}))}processRows(e){if(!this._hasProcessRows)return e;let t=e;for(const o of this.#ie("processRows")){const e=o.processRows(t);e!==t&&(t=e)}return t}processColumns(e){let t=[...e];for(const o of this.#ie("processColumns"))t=o.processColumns(t);return t}processConfig(e){for(const t of this.#ie("processConfig"))t.processConfig(e)}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterStructuralRender(){for(const e of this.#ie("afterStructuralRender"))e.afterStructuralRender()}afterRender(){for(const e of this.#ie("afterRender"))e.afterRender()}afterCellRender(e){for(const t of this.#ie("afterCellRender"))t.afterCellRender(e)}hasAfterCellRenderHook(){return this._hasAfterCellRender}afterRowRender(e){for(const t of this.#ie("afterRowRender"))t.afterRowRender(e)}hasAfterRowRenderHook(){return this._hasAfterRowRender}#re(){this._hasAfterCellRender=this.plugins.some(e=>"function"==typeof e.afterCellRender),this._hasAfterRowRender=this.plugins.some(e=>"function"==typeof e.afterRowRender),this._hasProcessRows=this.plugins.some(e=>"function"==typeof e.processRows),this._hasRowStructurePlugins=this.plugins.some(e=>!0===e.constructor.manifest?.modifiesRowStructure),this.#oe.clear()}#ie(e){let t=this.#oe.get(e);if(t)return t;t=this.plugins.filter(t=>e in t&&"function"==typeof t[e]);const o=t=>{const o=t.constructor.manifest?.hookPriority;if(!o)return 0;return o[e]??0};return t.some(e=>0!==o(e))&&t.sort((e,t)=>o(e)-o(t)),this.#oe.set(e,t),t}onScrollRender(){for(const e of this.#ie("onScrollRender"))e.onScrollRender()}getRowHeight(e,t){for(const o of this.plugins)if("function"==typeof o.getRowHeight){const n=o.getRowHeight(e,t);if(void 0!==n)return n}}hasRowHeightPlugin(){for(const e of this.plugins)if("function"==typeof e.getRowHeight)return!0;return!1}adjustVirtualStart(e,t,o){let n=e;for(const r of this.plugins)if("function"==typeof r.adjustVirtualStart){const i=r.adjustVirtualStart(e,t,o);i<n&&(n=i)}return n}renderRow(e,t,o){for(const n of this.plugins)if(n.renderRow?.(e,t,o))return!0;return!1}queryPlugins(e){const t=[],o=this.queryHandlers.get(e.type);if(o&&o.size>0){for(const n of o){const o=n.handleQuery?.(e);void 0!==o&&t.push(o)}return t}for(const n of this.plugins){const o=n.handleQuery?.(e);void 0!==o&&t.push(o)}return t}subscribe(e,t,o){let n=this.eventListeners.get(t);n||(n=/* @__PURE__ */new Map,this.eventListeners.set(t,n)),n.set(e,o)}unsubscribe(e,t){const o=this.eventListeners.get(t);o&&(o.delete(e),0===o.size&&this.eventListeners.delete(t))}unsubscribeAll(e){for(const[t,o]of this.eventListeners)o.delete(e),0===o.size&&this.eventListeners.delete(t)}emitPluginEvent(e,t){const o=this.eventListeners.get(e);if(o)for(const r of o.values())try{r(t)}catch(n){x("TBW024",`Error in plugin event handler for "${e}": ${n}`,this.grid.getAttribute("id")??void 0)}}onKeyDown(e){for(const t of this.#ie("onKeyDown"))if(t.onKeyDown(e))return!0;return!1}onCellClick(e){for(const t of this.#ie("onCellClick"))if(t.onCellClick(e))return!0;return!1}onRowClick(e){for(const t of this.#ie("onRowClick"))if(t.onRowClick(e))return!0;return!1}onHeaderClick(e){for(const t of this.#ie("onHeaderClick"))if(t.onHeaderClick(e))return!0;return!1}onScroll(e){for(const t of this.#ie("onScroll"))t.onScroll(e)}onCellMouseDown(e){for(const t of this.#ie("onCellMouseDown"))if(t.onCellMouseDown(e))return!0;return!1}onCellMouseMove(e){for(const t of this.#ie("onCellMouseMove"))if(t.onCellMouseMove(e))return!0;return!1}onCellMouseUp(e){for(const t of this.#ie("onCellMouseUp"))if(t.onCellMouseUp(e))return!0;return!1}getHorizontalScrollOffsets(e,t){let o=0,n=0,r=!1;for(const i of this.plugins){const s=i.getHorizontalScrollOffsets?.(e,t);s&&(o+=s.left,n+=s.right,s.skipScroll&&(r=!0))}return{left:o,right:n,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const o=t.getToolPanel?.();o&&e.push({plugin:t,panel:o})}return e.sort((e,t)=>(e.panel.order??0)-(t.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const o=t.getHeaderContent?.();o&&e.push({plugin:t,content:o})}return e.sort((e,t)=>(e.content.order??0)-(t.content.order??0))}}class Ho extends HTMLElement{static tagName="tbw-grid";static version="2.16.3";static activeTag="tbw-grid";static#se=0;static adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode","loading"]}get#le(){return this}#ae=!1;#C;#y;#ce=[];get#k(){return this.#de?.effective??{}}#he=!1;#ue=!1;#ge={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#fe;#pe=0;#we=null;#me=!1;#be=!1;#ve=0;#Ce;#ye={startY:null,startX:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0,locked:!1,activePointerId:null};#_e;#Se;#Re;#Ee;#Pe={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#xe;#Ae;#Te;#He;#Me;#Le;get _pluginManager(){return this.#xe}#ke=!1;#Oe;#De;#q;#de;#Ie;#ze=/* @__PURE__ */new Map;#Ne=!1;#qe=/* @__PURE__ */new Set;#Fe=/* @__PURE__ */new Map;#$e;#We={};#Be=/* @__PURE__ */new Map;#Ve=!1;_rows=[];#Ue=[];get _columns(){return this.#k.columns??[]}set _columns(e){this.#k.columns=e,this.#Ge=void 0}#Ge;get _visibleColumns(){return this.#Ge??=this._columns.filter(e=>!e.hidden)}_invalidateVisibleColumnsCache(){this.#Ge=void 0}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;get _virtualization(){return this.#He.state}set _virtualization(e){Object.assign(this.#He.state,e)}_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#de?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#de&&(this.#de.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#de?.originalColumnNodes}set __originalColumnNodes(e){this.#de&&(this.#de.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=Array.isArray(e)?e:[],o=this.#ce;this.#ce=t,o!==t&&this.#je("rows")}get sourceRows(){return this.#ce}set sourceRows(e){this.#ce=Array.isArray(e)?e:[]}get columns(){return[...this._columns]}set columns(e){const t=this.#de?.getColumns();this.#de?.setColumns(e),t!==e&&this.#je("columns")}get gridConfig(){return this.#k}set gridConfig(e){e&&this.__frameworkAdapter?.processConfig&&(e=this.__frameworkAdapter.processConfig(e));const t=this.#de?.getGridConfig();this.#de?.setGridConfig(e),t!==e&&(this.#de.clearLightDomCache(),this.#je("gridConfig"))}get _sourceConfig(){return this.#de?.getGridConfig()}get fitMode(){return this.#k.fitMode??"stretch"}set fitMode(e){const t=this.#de?.getFitMode();this.#de?.setFitMode(e),t!==e&&this.#je("fitMode")}get loading(){return this.#Ne}set loading(e){const t=this.#Ne;this.#Ne=e,t!==e&&(e?(this.setAttribute("loading",""),this.setAttribute("aria-busy","true")):(this.removeAttribute("loading"),this.removeAttribute("aria-busy")),this.#Ye(),this.#Xe())}setRowLoading(e,t){const o=this.#qe.has(e);t?this.#qe.add(e):this.#qe.delete(e),o!==t&&this.#Ke(e,t)}setCellLoading(e,t,o){let n=this.#Fe.get(e);const r=n?.has(t)??!1;o?(n||(n=/* @__PURE__ */new Set,this.#Fe.set(e,n)),n.add(t)):(n?.delete(t),0===n?.size&&this.#Fe.delete(e)),r!==o&&this.#Ze(e,t,o)}isRowLoading(e){return this.#qe.has(e)}isCellLoading(e,t){return this.#Fe.get(e)?.has(t)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#qe)this.#Ke(e,!1);this.#qe.clear();for(const[e,t]of this.#Fe)for(const o of t)this.#Ze(e,o,!1);this.#Fe.clear()}get effectiveConfig(){return this.#k}get disconnectSignal(){return this.#_e||(this.#_e=new AbortController),this.#_e.signal}constructor(){super(),this.#Qe(),this.#C=new Promise(e=>this.#y=e),this.#He=new Ao(this),this.#Me=new Zt(this),this.#Le=new ho(this),this.#fe=new it(this),this.#fe.setInitialReadyResolver(()=>this.#y?.()),this.#de=new st(this)}#Je(){const e=this.#xe?.getPluginByName("shell"),t=e??(this.#Ie??=new Ae);return t.ensureState(this),t}#et=/* @__PURE__ */new Set;#tt(e){this.#et.has(e)||(this.#et.add(e),E("TBW076",`grid.${e} is deprecated. Enable the shell via \`features: { shell }\` and call \`grid.getPluginByName('shell')?.${e}\` instead.`,this.id))}get#ot(){return this.#Je().shellState}async#Qe(){await bo('@layer tbw-base, tbw-plugins, tbw-theme;\n\n@layer tbw-base{tbw-grid{--tbw-base-icon-size: 1em;--tbw-base-radius: .25em;--tbw-font-size: 1em;--tbw-font-size-sm: .9285em;--tbw-font-size-xs: .7857em;--tbw-font-size-2xs: .7142em;--tbw-spacing-xs: .25em;--tbw-spacing-sm: .375em;--tbw-spacing-md: .5em;--tbw-spacing-lg: .75em;--tbw-spacing-xl: 1em;--tbw-icon-size: var(--tbw-base-icon-size);--tbw-icon-size-sm: .875em;--tbw-checkbox-size: var(--tbw-base-icon-size);--tbw-toggle-size: 1.25em;--tbw-border-radius: var(--tbw-base-radius);--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-warning: light-dark(hsl(38, 92%, 50%), hsl(38, 92%, 50%));--tbw-color-error: light-dark(hsl(0, 65%, 51%), hsl(0, 65%, 55%));--tbw-color-danger: var(--tbw-color-error);--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #666666);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding-v: var(--tbw-spacing-xs);--tbw-cell-padding-h: var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-cell-padding-v) var(--tbw-cell-padding-h);--tbw-cell-padding-input: var(--tbw-spacing-xs) var(--tbw-spacing-sm);--tbw-row-height: 1.75em;--tbw-header-height: 1.875em;--tbw-cell-white-space: nowrap;--tbw-border-width: 1px;--tbw-border-style: solid;--tbw-border-input: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-strong);--tbw-border-header: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-header);--tbw-row-divider: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline-width: 2px;--tbw-focus-outline: var(--tbw-focus-outline-width) var(--tbw-border-style) var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-column-selection-bg: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-resize-handle-width: 2px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-resize-indicator-width: 2px;--tbw-resize-indicator-color: var(--tbw-color-accent);--tbw-resize-indicator-opacity: .6;--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-row-change-duration: .5s;--tbw-row-insert-duration: .3s;--tbw-row-remove-duration: .2s;--tbw-row-change-color: rgba(from var(--tbw-color-accent) r g b / 25%);--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-sort-indicator-display: inline-flex;--tbw-sort-indicator-visibility: visible;--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-density-scale: 1;--tbw-shell-header-height: 2.75em;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: var(--tbw-font-size);--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 17.5em;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 2.5em;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 2em;--tbw-toolbar-button-gap: var(--tbw-spacing-xs);--tbw-panel-padding: var(--tbw-spacing-lg);--tbw-panel-gap: var(--tbw-spacing-md);--tbw-menu-item-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-menu-item-gap: var(--tbw-spacing-md);--tbw-menu-min-width: 10rem;--tbw-button-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-button-padding-sm: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-input-height: var(--tbw-row-height);--tbw-input-padding: 0 var(--tbw-spacing-md);--tbw-detail-padding: var(--tbw-spacing-xl);--tbw-detail-max-height: 31.25rem;--tbw-indicator-size: var(--tbw-spacing-sm);--tbw-icon-expand: "▶";--tbw-icon-collapse: "▼";--tbw-icon-sort-asc: "▲";--tbw-icon-sort-desc: "▼";--tbw-icon-sort-none: "⇅";--tbw-icon-submenu-arrow: "▶";--tbw-icon-drag-handle: "⋮⋮";--tbw-icon-tool-panel: "☰";--tbw-icon-filter: "";--tbw-icon-filter-active: "";--tbw-icon-print: "🖨️";--tbw-icon-expand-mask: none;--tbw-icon-collapse-mask: none;--tbw-icon-sort-asc-mask: none;--tbw-icon-sort-desc-mask: none;--tbw-icon-sort-none-mask: none;--tbw-icon-submenu-arrow-mask: none;--tbw-icon-drag-handle-mask: none;--tbw-icon-tool-panel-mask: none;--tbw-icon-filter-mask: url("data:image/svg+xml,%3Csvg viewBox=\'0 0 16 16\' width=\'12\' height=\'12\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cpath fill=\'currentColor\' d=\'M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z\'/%3E%3C/svg%3E");--tbw-icon-filter-active-mask: var(--tbw-icon-filter-mask);--tbw-icon-print-mask: none}}\n@layer tbw-base{tbw-grid{color-scheme:inherit;position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);font-feature-settings:"tnum","lnum";background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none;&,*{box-sizing:border-box}.tbw-grid-root{position:relative;display:flex;flex-direction:column;height:100%;&.has-shell{display:flex;flex-direction:column;height:100%}&:has(.selected){user-select:none}}.tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}.rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}.rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}.rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible;position:relative}.rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip;touch-action:none;.rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}}.faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30);touch-action:none}.faux-vscroll-spacer{width:1px}.tbw-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}&[data-has-focus]{.cell-focus,.row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}}.sticky-left,.sticky-right{position:sticky;z-index:25}.sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}.sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}}}\n@layer tbw-base{tbw-grid{[data-icon=expand]:empty:before{content:var(--tbw-icon-expand)}[data-icon=collapse]:empty:before{content:var(--tbw-icon-collapse)}[data-icon=sort-asc]:empty:before{content:var(--tbw-icon-sort-asc)}[data-icon=sort-desc]:empty:before{content:var(--tbw-icon-sort-desc)}[data-icon=sort-none]:empty:before{content:var(--tbw-icon-sort-none)}[data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow)}[data-icon=drag-handle]:empty:before{content:var(--tbw-icon-drag-handle)}[data-icon=tool-panel]:empty:before{content:var(--tbw-icon-tool-panel)}[data-icon=print]:empty:before{content:var(--tbw-icon-print)}[data-icon=filter]:empty:before{content:var(--tbw-icon-filter)}[data-icon=filter-active]:empty:before{content:var(--tbw-icon-filter-active)}[data-icon]:empty:before{display:inline-block;vertical-align:middle;-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center}[data-icon=expand]:empty:before{-webkit-mask-image:var(--tbw-icon-expand-mask);mask-image:var(--tbw-icon-expand-mask)}[data-icon=collapse]:empty:before{-webkit-mask-image:var(--tbw-icon-collapse-mask);mask-image:var(--tbw-icon-collapse-mask)}[data-icon=sort-asc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-asc-mask);mask-image:var(--tbw-icon-sort-asc-mask)}[data-icon=sort-desc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-desc-mask);mask-image:var(--tbw-icon-sort-desc-mask)}[data-icon=sort-none]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-none-mask);mask-image:var(--tbw-icon-sort-none-mask)}[data-icon=submenu-arrow]:empty:before{-webkit-mask-image:var(--tbw-icon-submenu-arrow-mask);mask-image:var(--tbw-icon-submenu-arrow-mask)}[data-icon=drag-handle]:empty:before{-webkit-mask-image:var(--tbw-icon-drag-handle-mask);mask-image:var(--tbw-icon-drag-handle-mask)}[data-icon=tool-panel]:empty:before{-webkit-mask-image:var(--tbw-icon-tool-panel-mask);mask-image:var(--tbw-icon-tool-panel-mask)}[data-icon=print]:empty:before{-webkit-mask-image:var(--tbw-icon-print-mask);mask-image:var(--tbw-icon-print-mask)}[data-icon=filter]:empty:before,[data-icon=filter-active]:empty:before{width:var(--tbw-icon-size, 1em);height:var(--tbw-icon-size, 1em);background:currentColor}[data-icon=filter]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-mask);mask-image:var(--tbw-icon-filter-mask)}[data-icon=filter-active]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-active-mask);mask-image:var(--tbw-icon-filter-active-mask)}}.tbw-context-menu [data-icon]:empty:before{display:inline-block;width:1em;height:1em;vertical-align:middle}.tbw-context-menu [data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow, "▶")}}\n@layer tbw-base{tbw-grid{.header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}.header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}.header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start));&:not(:last-child){border-right:2px solid var(--tbw-color-border)}}.header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30);text-transform:var(--tbw-header-text-transform);letter-spacing:var(--tbw-header-letter-spacing);>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:visible;min-width:0;>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:inherit}>span[part~=sort-indicator]{flex-shrink:0;opacity:.6;color:var(--tbw-sort-indicator-color);display:var(--tbw-sort-indicator-display, inline-flex);visibility:var(--tbw-sort-indicator-visibility, visible);transition:opacity .15s,visibility 0s,display 0s allow-discrete;transition-behavior:allow-discrete}&:hover>span[part~=sort-indicator]{display:inline-flex;visibility:visible}&[aria-sort=ascending]>span[part~=sort-indicator],&[aria-sort=descending]>span[part~=sort-indicator]{display:inline-flex;visibility:visible;opacity:1;color:var(--tbw-sort-indicator-active-color)}&:last-child{border-right:0;.resize-handle{right:0;width:calc(var(--tbw-resize-hit-area, 18px) / 2)}}&.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}&.resizable{position:relative}&.sticky-left,&.sticky-right{background:var(--tbw-color-header-bg);z-index:35}}}.header-group-row>.header-group-cell{&.sticky-left,&.sticky-right{background:var(--tbw-color-header-bg);z-index:35}}.sortable{cursor:pointer;user-select:none}.resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-hit-area, 18px) / -2);width:var(--tbw-resize-hit-area, 18px);height:100%;cursor:e-resize;user-select:none;touch-action:none;z-index:20;background:transparent;&:before{content:"";position:absolute;top:0;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:100%;background:var(--tbw-resize-handle-color);border-radius:var(--tbw-resize-handle-border-radius);transition:background .12s ease}&:after{content:"";position:absolute;top:100%;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:0;background:var(--tbw-resize-indicator-color, var(--tbw-color-accent));opacity:0;pointer-events:none;transition:opacity .12s ease,height 0s .12s;z-index:1000}&:hover{&:before{background:var(--tbw-resize-handle-color-hover)}&:after{height:100vh;opacity:var(--tbw-resize-indicator-opacity, .6);transition:opacity .12s ease,height 0s}}}}}\n@layer tbw-base{tbw-grid{.data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style;&:nth-child(2n){background:var(--tbw-color-row-alt)}@media(hover:hover){&:hover{background:var(--tbw-color-row-hover)}}>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis;>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}&:last-child{border-right:0}&[data-type=boolean]{text-align:center;input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}}&.selected:focus-visible,&:focus-visible:not(.cell-focus){outline:none}&.sticky-left,&.sticky-right{background:var(--tbw-color-panel-bg)}}}.selecting .data-grid-row>.cell{user-select:none}}}\n@layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.tbw-row-loading-overlay{position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out;pointer-events:none;display:flex;align-items:center}.tbw-row-loading-spinner{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);margin-left:var(--tbw-spacing-md);width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite}.cell.tbw-cell-loading{position:relative;pointer-events:none;&:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out}&:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:27}}}\n@layer tbw-base{.tbw-empty-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:var(--tbw-spacing-md, 12px);text-align:center;background:light-dark(rgba(255,255,255,.6),rgba(0,0,0,.4));color:var(--tbw-color-text-secondary, var(--tbw-color-text));z-index:999;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-empty-message{font-family:var(--tbw-font-family, inherit);font-size:var(--tbw-font-size-md, 14px);line-height:1.4;max-width:480px;user-select:text}}\n@layer tbw-base{tbw-grid{.tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}.tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}&[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms;.data-grid-row[data-animating]{animation:none}}}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-spin{to{transform:rotate(360deg)}}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}\n@layer tbw-base{@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight;.cell:focus,.cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}.data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms;.data-grid-row[data-animating]{animation:none}}}}\n')}getPlugin(e){return this.#xe?.getPlugin(e)}getPluginByName(e){return this.#xe?.getPluginByName(e)}requestRender(){this.#fe.requestPhase(rt.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#fe.requestPhase(rt.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#fe.requestPhase(rt.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){Ie(this)}requestAfterRender(){this.#fe.requestPhase(rt.STYLE,"plugin:requestAfterRender")}requestVirtualRefresh(){this._virtualization.start=-1,this.refreshVirtualWindow(!1)}#nt(){this.#xe=new To(this);const e=this.#k?.plugins,t=Array.isArray(e)?e:[],o=this.#k?.features;let n,r=[];if(o&&Xt){r=Xt(o).map(e=>this.#rt(e))}if(0===r.length)n=t;else if(0===t.length)n=r;else{const e=new Set(t.map(e=>e.name));n=[...r.filter(t=>!e.has(t.name)),...t]}n.some(e=>"shell"===e.name)?this.#Ie=n.find(e=>"shell"===e.name):(this.#Ie??=new Ae,this.#ze.set("shell",this.#Ie),n=[this.#Ie,...n]),this.#xe.attachAll(n)}#rt(e){const t=this.#ze.get(e.name);return t&&t!==e?(t.refreshUserConfigFrom(e),t):(this.#ze.set(e.name,e),e)}#it(){!function(e){let t=!1;for(const{name:o,styles:n}of e)fo.has(o)||(fo.set(o,wo(n)),t=!0);t&&mo()}(this.#xe?.getPluginStyles()??[])}#st(){const e=this.#k?.plugins,t=Array.isArray(e)?e:[],o=this.#k?.features??void 0,n=o!==this.#Te;if((this.#Ae===t||void 0!==this.#Ae&&this.#Ae.length===t.length&&this.#Ae.every((e,o)=>e===t[o]))&&!n)return void(this.#Ae=t);this.#xe&&this.#xe.detachAll();for(const i of this.#ot.toolPanels.keys()){const e=this.#ot.lightDomToolPanelIds.has(i),t=this.#ot.apiToolPanelIds.has(i);if(!e&&!t){const e=this.#ot.panelCleanups.get(i);e&&(e(),this.#ot.panelCleanups.delete(i)),this.#ot.toolPanels.delete(i)}}for(const i of this.#ot.headerContents.keys()){if(this.#ot.apiHeaderContentIds.has(i))continue;const e=this.#ot.headerContentCleanups.get(i);e&&(e(),this.#ot.headerContentCleanups.delete(i)),this.#ot.headerContents.delete(i)}this.#nt(),this.#it(),this.#Ae=t,this.#Te=o,this.#lt(),this.#at();const r=this.#me;if(this.#me=this.#xe?.getAll().some(e=>e.onScroll)??!1,!r&&this.#me){const e=this.#le.querySelector(".tbw-grid-content")??this.#le.querySelector(".tbw-grid-root");this.#ct(e)}}#dt(){this.#xe?.detachAll()}#at(){if(!this.#xe)return;const e=this.#xe.getToolPanels();for(const{panel:o}of e){if(this.#ot.apiToolPanelIds.has(o.id))continue;if(this.#ot.lightDomToolPanelIds.has(o.id)){E(s,`Tool panel "${o.id}" is provided by a plugin; ignoring the matching light-DOM <tbw-grid-tool-panel>.`,this.id);const e=this.#ot.panelCleanups.get(o.id);e&&(e(),this.#ot.panelCleanups.delete(o.id)),this.#ot.lightDomToolPanelIds.delete(o.id),this.#ot.adapterBoundToolPanelIds.delete(o.id)}this.#ot.toolPanels.set(o.id,o)}const t=this.#xe.getHeaderContents();for(const{content:o}of t)if(!this.#ot.apiHeaderContentIds.has(o.id)){if(this.#ot.headerContents.has(o.id)){E(l,`Header content "${o.id}" is provided by a plugin; ignoring the matching light-DOM definition.`,this.id);const e=this.#ot.headerContentCleanups.get(o.id);e&&(e(),this.#ot.headerContentCleanups.delete(o.id))}this.#ot.headerContents.set(o.id,o)}}#ht(){const e=Ho.getAdapters();if(0===e.length&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return o=>{if(t?.createToolPanelRenderer){const e=t.createToolPanelRenderer(o);if(e)return e}for(const t of e)if(t.createToolPanelRenderer){const e=t.createToolPanelRenderer(o);if(e)return e}}}_registerLightDomHandler(e,t){this.#de.registerLightDomHandler(e,t)}_unregisterLightDomHandler(e){this.#de.unregisterLightDomHandler(e)}_requestConfigMerge(){this.#de.markSourcesChanged(),this.#de.merge()}_getToolPanelRendererFactory(){return this.#ht()}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",Ho.version),this.hasAttribute("data-tbw-grid")||this.setAttribute("data-tbw-grid",""),this.id||(this.id="tbw-grid-"+ ++Ho.#se),this._rows=Array.isArray(this.#ce)?[...this.#ce]:[],this.#_e&&(this.#_e.abort(),this.#ke=!1),this.#_e=new AbortController,this.#Ee&&(Jt(this.#Ee),this.#Ee=void 0),this.#h(),this.#de.parseLightDomColumns(this),this.#de.merge(),this.#nt();const e=this.#k?.plugins;var t,o;this.#Ae=Array.isArray(e)?e:[],this.#Te=this.#k?.features??void 0,this.#at(),this.#ae||(this.#ut(),this.#it(),this.#ae=!0),this.#gt(),this.#Ee=(t=()=>{this.#ft()},o={timeout:100},Qt?requestIdleCallback(t,o):window.setTimeout(()=>{const e=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-e))})},1))}disconnectedCallback(){this.#Ee&&(Jt(this.#Ee),this.#Ee=void 0),this.#ve&&(clearTimeout(this.#ve),this.#ve=0),this.#dt();const e=this.#xe?.getPluginByName("shell")??this.#Ie;e?.disposeShellState(),Co(this.#ye),this.#_e&&(this.#_e.abort(),this.#_e=void 0),this.#Oe?.abort(),this.#Oe=void 0,this.#ke=!1,this._resizeController&&this._resizeController.dispose(),this.#Se&&(this.#Se.disconnect(),this.#Se=void 0),this.#Re&&(this.#Re.disconnect(),this.#Re=void 0,this.#pt=!1,this.#wt=0),xt(this),this.#mt.clear(),this._virtualization.heightCache?.byKey.clear(),this.#Ae=void 0,this.#Te=void 0;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#he=!1}attributeChangedCallback(e,t,o){if("loading"===e){const e=null!==o&&"false"!==o;return void(this.loading!==e&&(this.loading=e))}if(t!==o&&o&&"null"!==o&&"undefined"!==o)if("rows"===e||"columns"===e||"grid-config"===e)try{const t=JSON.parse(o);"rows"===e?this.rows=t:"columns"===e?this.columns=t:"grid-config"===e&&(this.gridConfig=t)}catch{E("TBW130",`Invalid JSON for '${e}' attribute: ${o}`,this.id)}else"fit-mode"===e&&(this.fitMode=o)}#gt(){const e=this.#le.querySelector(".tbw-grid-content")??this.#le.querySelector(".tbw-grid-root");if(this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this.setAttribute("data-upgraded",""),this.#he=!0,this._resizeController=oo(this),this.#bt(),this.#ct(e),this.#ke)return;this.#ke=!0;const t=this.disconnectSignal;Yt(this,this,this.#le,t),this.#lt(),queueMicrotask(()=>this.#vt()),this.#fe.requestPhase(rt.FULL,"afterConnect")}#lt(){const e=this.#k.rowHeight,t=this.#xe.hasRowHeightPlugin();"function"==typeof e||t?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight="number"==typeof e&&e>0?e:this._virtualization.rowHeight||28,this.#He.initializePositionCache(),"function"!=typeof e&&(this.#be=!0)):!t&&"function"!=typeof e&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):"number"==typeof e&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#Ct())}#Ct(){if(this.#xe.hasRowHeightPlugin())return;const e=this.#k.rowHeight;if("number"==typeof e&&e>0)return;const t=this._bodyEl?.querySelector(".data-grid-row");if(!t)return;const o=this.#yt(),n=[],r=this._bodyEl?.querySelectorAll(".data-grid-row");for(const u of r??[]){if(u.style.getPropertyValue("--tbw-row-height"))continue;let e=0;u.querySelectorAll(".cell").forEach(t=>{const o=t.offsetHeight;o>e&&(e=o)});const t=Math.max(u.getBoundingClientRect().height,e);t>0&&n.push(t)}if(0===n.length)return;n.sort((e,t)=>e-t);const i=n.length>>1,s=n.length%2==1?n[i]:(n[i-1]+n[i])/2,l=this._virtualization.rowHeight,a=this.#wt,c=o>0&&a>0&&Math.abs(o-a)>1,d=o>0&&0===a,h=s>0&&s-l>1;if(o>0&&(this.#wt=o),c||d||h){const e=c||d?Math.max(o,s):s;Math.abs(e-l)>1&&(this._virtualization.rowHeight=e,this.#fe.requestPhase(rt.VIRTUALIZATION,"measureRowHeight"))}}#yt(){const e=getComputedStyle(this).getPropertyValue("--tbw-row-height").trim();if(!e)return 0;if(e.endsWith("px"))return parseFloat(e)||0;const t=this._bodyEl?.querySelector('.data-grid-row:not([style*="--tbw-row-height"]) > .cell');if(!t)return 0;const o=parseFloat(getComputedStyle(t).minHeight);return o>0?o:0}#_t(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let o=0;t.forEach(e=>{const t=e.offsetHeight;t>o&&(o=t)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);if(r>0){if(Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r),this.#He.initializePositionCache(),this._virtualization.totalHeightEl){const e=this.#He.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`}}}#ct(e){this.#Oe?.abort(),this.#Oe=new AbortController;const t=this.#Oe.signal,o=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=o??this,this.#me=this.#xe?.getAll().some(e=>e.onScroll)??!1,o&&n){o.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#me)return;const e=o.scrollTop,t=Nt(e,this._virtualization.scrollMapping),r=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-e}px)`;else{const e=this._virtualization.positionCache;let o,i;if(this._virtualization.variableHeights&&e&&e.length>0){o=Ot(e,t),-1===o&&(o=0);const n=o-o%2;i=e[n]?.offset??n*r}else{o=Math.floor(t/r);i=(o-o%2)*r}const s=-(t-i);n.style.transform=`translateY(${s}px)`}this.#we=e,this.#pe||(this.#pe=requestAnimationFrame(()=>{this.#pe=0,null!==this.#we&&(this.#St(this.#we),this.#we=null)}))},{passive:!0,signal:t});const e=this.#le.querySelector(".tbw-scroll-area");this.#De=e,this._virtualization.scrollAreaEl=e,e&&this.#me&&e.addEventListener("scroll",()=>{const t=this.#Pe;t.scrollTop=o.scrollTop,t.scrollLeft=e.scrollLeft,t.scrollHeight=o.scrollHeight,t.scrollWidth=e.scrollWidth,t.clientHeight=o.clientHeight,t.clientWidth=e.clientWidth,this.#xe?.onScroll(t)},{passive:!0,signal:t});const r=this.#le.querySelector(".tbw-grid-content"),i=this.#De;r&&(r.addEventListener("wheel",e=>{try{if(r.querySelector("select:open"))return}catch{}const t=e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY);if(t&&i){const t=e.shiftKey?e.deltaY:e.deltaX,{scrollLeft:o,scrollWidth:n,clientWidth:r}=i;(t>0&&o<n-r||t<0&&o>0)&&(e.preventDefault(),i.scrollLeft+=t)}else if(!t){const{scrollTop:t,scrollHeight:n,clientHeight:r}=o;(e.deltaY>0&&t<n-r||e.deltaY<0&&t>0)&&(e.preventDefault(),o.scrollTop+=e.deltaY)}},{passive:!1,signal:t}),_o(r,this.#ye,{fauxScrollbar:o,scrollArea:i},t))}var r,i,s;this._bodyEl&&(r=this,i=this._bodyEl,s=t,i.addEventListener("mousedown",e=>{const t=e.target.closest(".cell[data-col]");if(!t)return;if(t.classList.contains(X.EDITING))return;const o=e.target;o.draggable||o.closest('[draggable="true"]')||e.preventDefault(),Gt(r,t)},{signal:s}),i.addEventListener("click",e=>{const t=e.target.closest(".data-grid-row");if(t&&Ht(r,e,t),!document.activeElement?.closest(`.cell.${X.EDITING}`)){const t=e.target.closest("tbw-grid, [data-tbw-grid]");t&&t.focus({preventScroll:!0})}},{signal:s}),i.addEventListener("dblclick",e=>{const t=e.target.closest(".data-grid-row");t&&Ht(r,e,t)},{signal:s})),this.#Se?.disconnect(),this._virtualization.viewportEl&&(this.#Se=new ResizeObserver(()=>{this.#Rt(),this.#fe.requestPhase(rt.VIRTUALIZATION,"resize-observer")}),this.#Se.observe(this._virtualization.viewportEl)),this.#le.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#le.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.#le.contains(t)||this.#Me.isInExternalFocusContainer(t))||delete this.dataset.hasFocus},{signal:t})}#pt=!1;#wt=0;#Et(){if(this.#pt)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#pt=!0,this.#Re?.disconnect(),this.#Re=new ResizeObserver(()=>{this.#Ct()}),this.#Re.observe(e))}addEventListener(e,t,o){super.addEventListener(e,t,o)}removeEventListener(e,t,o){super.removeEventListener(e,t,o)}on(e,t){const o=e=>{t(e.detail,e)};return this.addEventListener(e,o),()=>this.removeEventListener(e,o)}#Pt(e,t){this.#he&&this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_emitDataChange(){this.#Pt("data-change",{rowCount:this._rows.length,sourceRowCount:this.#ce.length}),function(e,t,o){if(o===t.lastAnnouncedSourceCount)return;const n=t.lastAnnouncedSourceCount;t.lastAnnouncedSourceCount=o,0===o&&n<0||Te(e,He(e,"dataLoaded",o))}(this,this.#xt,this.#ce.length)}#vt(){const e=this._bodyEl?.querySelectorAll(".data-grid-row");e?.forEach((e,t)=>{const o=t===this._focusRow;e.setAttribute("aria-selected",String(o)),e.querySelectorAll(".cell").forEach((e,t)=>{e.setAttribute("aria-selected",String(o&&t===this._focusCol))})})}#je(e){this.#ge[e]=!0,this.#ue||(this.#ue=!0,queueMicrotask(()=>this.#At()))}#At(){if(!this.#ue||!this.#he)return void(this.#ue=!1);const e=this.#ge;if(this.#ue=!1,this.#ge={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig)return this.#Tt(),void(e.rows&&this.#Ht());e.columns&&this.#Mt(),e.rows&&this.#Ht(),e.fitMode&&this.#Lt()}#Ht(){this._rows=Array.isArray(this.#ce)?[...this.#ce]:[],this.#Ve=!0,this.#fe.requestPhase(rt.ROWS,"applyRowsUpdate")}#kt(){this.#Ve&&this._rebuildRowIdMap()}_rebuildRowIdMap(){this.#Ve=!1,this.#Be.clear();const e=this.#k.getRowId;for(let t=0;t<this._rows.length;t++){const o=ao(this._rows[t],e);void 0!==o&&this.#Be.set(o,{row:this._rows[t],index:t})}}#Mt(){xt(this),this.#de.merge(),this.#bt()}#Lt(){this.#de.merge();if("fixed"===this.#k.fitMode)this.__didInitialAutoSize=!1,ke(this);else{for(let e=0;e<this._columns.length;e++){const t=this._columns[e];!t.__userResized&&t.__autoSized&&delete t.width}Ie(this)}}#Tt(){this.#Je()._parseLightDomHeader(this);const e=!!this.#le.querySelector(".has-shell"),t=!!this.#le.querySelector(".tbw-tool-panel"),o=this.#le.querySelectorAll(".tbw-accordion-section").length,n=this.#le.querySelector(".tbw-tool-panel")?.dataset.position??"right",r=this.#le.querySelector(".tbw-shell-body")?.dataset.mode??"overlay";this.#de.parseLightDomColumns(this),this.#de.merge(),this.#st(),this.#lt(),this.#Je()._parseLightDomToolPanels(this),this.#de.markSourcesChanged(),this.#de.merge();const i=this.#de.initialColumnState;if(i){this.#de.initialColumnState=void 0,this.#q=void 0;const e=this.#xe?.getAll()??[];this.#de.applyState(i,e)}const s=this.#Je()._shouldRenderHeader(this.#k?.shell),l=(this.#k?.shell?.toolPanels?.length??0)>0,a=this.#k?.shell?.toolPanels?.length??0,c=this.#k?.shell?.toolPanel?.position??"right",d=this.#k?.shell?.toolPanel?.mode??"overlay";if(e!==s||!t&&l||t&&a!==o||t&&n!==c||t&&r!==d)return this.#Je()._prepareForRerender(),this.#ut(),this.#it(),this.#gt(),void this._rebuildRowIdMap();e&&this.#Ot(),this.#ot.isPanelOpen&&this.#Je()._renderOpenPanelContent(this),this._rebuildRowIdMap(),this.#fe.requestPhase(rt.COLUMNS,"applyGridConfigUpdate")}#Ot(){const e=this.#le.querySelector(".tbw-shell-header");if(!e)return;const t=this.#k.shell?.header?.title??this.#ot.lightDomTitle;let o=e.querySelector(".tbw-shell-title");t?(o||(o=document.createElement("h2"),o.className="tbw-shell-title",o.setAttribute("part","shell-title"),e.insertBefore(o,e.firstChild)),o.textContent=t):o&&o.remove()}#Dt(){if(this.__rowRenderEpoch++,this.#xe){const e=this.#Ue.length>0?this.#Ue:this._columns,t=e.filter(e=>!e.hidden),o=e.filter(e=>e.hidden),n=this.#xe.processColumns([...t]);if(n!==t){const r=new Set(n.map(e=>e.field));!t.some(e=>r.has(e.field))&&n.length>0?this._columns=[...n,...o]:this._columns=this.#It(e,n,o)}else this._columns=[...e]}}#It(e,t,o){if(0===o.length)return t;const n=/* @__PURE__ */new Map;for(const l of t)n.set(l.field,l);const r=new Set(e.map(e=>e.field)),i=[];for(const l of t)r.has(l.field)||i.push(l);const s=[];for(const l of e){const e=n.get(l.field);e?s.push(e):l.hidden&&s.push(l)}return s.push(...i),s}#zt(){xt(this);const e=this.#ce;if(!Array.isArray(e))return this._rows=[],this._rebuildRowIdMap(),this._virtualization.variableHeights&&this.#He.initializePositionCache(),void this._emitDataChange();if(!this._sortState&&this.#k.initialSort){const{field:e,direction:t}=this.#k.initialSort;this._columns.find(t=>t.field===e)&&(this._sortState={field:e,direction:"desc"===t?-1:1})}this._sortState&&(this.__originalOrder=this._rows);const t=function(e,t,o=!1){if(!e._sortState)return t;const n=e.effectiveConfig?.sortHandler??$e;if(n===$e)return o||(e.__originalOrder=t.slice()),Ue(t,e._sortState.field,e._sortState.direction,e._columns),t;o||(e.__originalOrder=t);const r=n(t,e._sortState,e._columns);return r&&"function"==typeof r.then?t:r}(this,this._sortState?[...e]:e,!0),o=this.#xe?.processRows(t)??t;this._rows=o,this.#Ve=!0,this._emitDataChange()}_renderVisibleRows(e,t,o=this.__rowRenderEpoch){if(this.#Ce||(this.#Ce=(e,t,o)=>this.#xe?.renderRow(e,t,o)??!1),function(e,t,o,n,r){const i=Math.max(0,o-t),s=e._bodyEl,l=e._visibleColumns,a=l.length;let c=e.__cachedHeaderRowCount;for(void 0===c&&(c=e.querySelector(".header-group-row")?2:1,e.__cachedHeaderRowCount=c);e._rowPool.length<i;){const t=Pt();e._rowPool.push(t)}if(e._rowPool.length>i){const t=e.__frameworkAdapter,o=t?.releaseCell;t?.beginBatch?.(e);try{for(let n=i;n<e._rowPool.length;n++){const r=e._rowPool[n];if(o){const e=r.children;for(let n=0;n<e.length;n++){const r=e[n];r.firstElementChild&&o.call(t,r)}}r.parentNode===s&&r.remove()}e._rowPool.length=i}finally{t?.endBatch?.(e)}}const d=r&&!1!==e.__hasRenderRowPlugins,h=e._hasAfterRowRenderHook?.()??!1,u=e._virtualization?.variableHeights&&"function"==typeof e.effectiveConfig?.rowHeight?e.effectiveConfig.rowHeight:null;for(let f=0;f<i;f++){const o=t+f,i=e._rows[o],p=e._rowPool[f];if(p.setAttribute("aria-rowindex",String(o+c+1)),d&&r(i,p,o)){p.__epoch=n,p.__rowDataRef=i,p.parentNode!==s&&s.appendChild(p);continue}const w=p.__epoch,m=p.__rowDataRef;let b=p.children.length;b>a&&p.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&b--;const v=w===n&&b===a,C=m!==i,y=!!e._isGridEditMode;let _=!1;if(v&&C)for(let e=0;e<a;e++)if(l[e].externalView&&!p.querySelector(`.cell[data-col="${e}"] [data-external-view]`)){_=!0;break}if(!v||_){const t=yt(p),r=y&&!C||e._activeEditRows===o;t&&!r?(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),_t(p),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i):t&&r?(At(e,p,i,o),p.__rowDataRef=i):(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i)}else if(C){const t=yt(p),r=e._activeEditRows===o;t&&!r?(_t(p),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i):(At(e,p,i,o),p.__rowDataRef=i)}else{const t=yt(p),r=y||e._activeEditRows===o;t&&!r?(_t(p),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i):At(e,p,i,o)}let S=!1;const R=e._changedRowIdSet;if(R&&R.size>0)try{const t=e.getRowId?.(i);t&&(S=R.has(t))}catch{}S!==p.classList.contains("changed")&&p.classList.toggle("changed",S);const P=e.effectiveConfig?.rowClass;if(P){const t=p.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&p.classList.remove(e[t])}try{const e=P(i),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let o=0;o<t.length;o++){const n=t[o];n&&"string"==typeof n&&(p.classList.add(n),e+=(e?" ":"")+n)}p.setAttribute("data-dynamic-classes",e)}else p.removeAttribute("data-dynamic-classes")}catch(g){E("TBW060",`rowClass callback error: ${g}`,e.id),p.removeAttribute("data-dynamic-classes")}}if(u){const e=u(i,o);void 0!==e&&e>0?p.style.setProperty("--tbw-row-height",`${e}px`):p.style.removeProperty("--tbw-row-height")}h&&e._afterRowRender?.({row:i,rowIndex:o,rowElement:p}),p.parentNode!==s&&s.appendChild(p)}}(this,e,t,o,this.#Ce),this.#qe.size>0)for(const n of this.#qe)this.#Ke(n,!0)}#xt={rowCount:-1,colCount:-1,ariaLabel:void 0,ariaLabelledBy:void 0,ariaDescribedBy:void 0,ariaRoleDescription:void 0,lastAnnouncedSourceCount:-1};_updateAriaCounts(e,t){!function(e,t,o,n,r){if(n===e.rowCount&&r===e.colCount)return!1;const i=e.rowCount;e.rowCount=n,e.colCount=r,t&&(t.setAttribute("aria-rowcount",String(n)),t.setAttribute("aria-colcount",String(r))),n!==i&&o&&(n>0?o.setAttribute("role","rowgroup"):o.removeAttribute("role"))}(this.#xt,this.__rowsBodyEl,this._bodyEl,e,t)}_requestSchedulerPhase(e,t){this.#fe.requestPhase(e,t)}_getPluginRowHeight(e,t){return this.#xe?.getRowHeight?.(e,t)}_adjustPluginVirtualStart(e,t,o){return this.#xe?.adjustVirtualStart(e,t,o)}_afterPluginRender(){this.#xe?.afterRender()}_emitPluginEvent(e,t){this.#xe?.emitPluginEvent(e,t)}_schedulerMergeConfig(){this.#de.parseLightDomColumns(this),this.#de.merge(),this.#st(),function(e,t,o){const n=So,r=Ro,i=/* @__PURE__ */new Map;function s(e,t,o,n,r=!1){i.has(e)||i.set(e,{description:t,importHint:o,fields:[],isConfigProperty:r});const s=i.get(e);s.fields.includes(n)||s.fields.push(n)}const l=e.features;function a(e){return!!l&&!1===l[e]}for(const d of r){const o=e[d.property];if((d.isUsed?d.isUsed(o):void 0!==o)&&!xo(t,d.pluginName)&&!a(d.pluginName)){const e=d.description||`the "${d.property}" ${d.level} property`;s(d.pluginName,e,Eo(d.pluginName),d.property,!0)}}const c=e.columns;if(c&&c.length>0)for(const d of c)for(const e of n){const o=d[e.property];if((e.isUsed?e.isUsed(o):void 0!==o)&&!xo(t,e.pluginName)&&!a(e.pluginName)){const t=d.field||"<unknown>",o=e.description||`the "${e.property}" ${e.level} property`;s(e.pluginName,o,Eo(e.pluginName),t)}}if(i.size>0){const e=[];for(const[t,{description:o,importHint:n,fields:r,isConfigProperty:s}]of i)if(s)e.push(`Config uses ${o}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${n}\n plugins: [new ${Po(t)}Plugin(), ...]`);else{const i=r.slice(0,3).join(", ")+(r.length>3?`, ... (${r.length} total)`:"");e.push(`Column(s) [${i}] use ${o}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${n}\n plugins: [new ${Po(t)}Plugin(), ...]`)}R([...i.values()].some(e=>e.isConfigProperty)?"TBW002":"TBW001",`Configuration error:\n\n${e.join("\n\n")}\n\nThis validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`,o)}}(this.#k,this.#xe?.getPlugins()??[],this.id),function(e,t){const o=[],n=[];for(const r of e){const e=r.constructor.manifest;if(e?.configRules)for(const t of e.configRules){const e=r.config;if(t.check(e)){const e=`[${Po(r.name)}Plugin] Configuration warning: ${t.message}`;"error"===t.severity?o.push(e):n.push(e)}}}if(n.length>0&&dt())for(const r of n)E("TBW004",r,t);o.length>0&&R("TBW003",`Configuration error:\n\n${o.join("\n\n")}`,t)}(this.#xe?.getPlugins()??[],this.id),function(e,t){if(!dt())return;const o=new Set(e.map(e=>e.name)),n=/* @__PURE__ */new Set;for(const r of e){const e=r.constructor.manifest;if(e?.incompatibleWith)for(const i of e.incompatibleWith)if(o.has(i.name)){const e=[r.name,i.name].sort().join("↔");if(n.has(e))continue;n.add(e),E("TBW022",`${Po(r.name)}Plugin and ${Po(i.name)}Plugin are both loaded, but they are currently incompatible.\n\n → ${i.reason}\n\n Consider removing one of these plugins to avoid unexpected behavior.`,t)}}}(this.#xe?.getPlugins()??[],this.id),this.#Nt(),this.#Ue=[...this._columns]}_schedulerProcessColumns(){this.#Dt()}_schedulerProcessRows(){this.#zt()}_schedulerRenderHeader(){ot(this)}_schedulerUpdateTemplate(){Ie(this)}_schedulerAfterRender(){this.#xe?.afterRender(),this.#Xe(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const e=this.#He.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`});"fixed"!==this.#k.fitMode||this.__didInitialAutoSize||(this.__didInitialAutoSize=!0,ke(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,Vt(this)),this._virtualization.enabled&&!this.#pt&&this.#Et(),this.#be&&(this.#be=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#_t()})})),this.#Ne&&this.#Ye()}get _schedulerIsConnected(){return this.isConnected&&this.#he}get _hostElement(){return this}get _renderRoot(){return this.#le}_emit(e,t){this.#Pt(e,t)}get _accordionIcons(){return{expand:this.#k?.icons?.expand??G.expand,collapse:this.#k?.icons?.collapse??G.collapse}}get _shellState(){return this.#ot}_clearRowPool(){const e=this.__frameworkAdapter,t=e?.releaseCell;if(t){e?.beginBatch?.(this);try{for(let o=0;o<this._rowPool.length;o++){const n=this._rowPool[o].children;for(let o=0;o<n.length;o++){const r=n[o];r.firstElementChild&&t.call(e,r)}}this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="")}finally{e?.endBatch?.(this)}}else this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="");this.__rowRenderEpoch++}_setup(){this.#bt()}_applyAnimationConfig(e){const t={...U,...e.animation},o=t.mode??"reduced-motion";let n=1;!1===o||"off"===o?n=0:!0!==o&&"on"!==o||(n=1),this.style.setProperty("--tbw-animation-duration",`${t.duration}ms`),this.style.setProperty("--tbw-animation-easing",t.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode="boolean"==typeof o?o?"on":"off":o}#Nt(){!function(e,t,o){if(!t)return!1;let n=!1;const r=o?.gridAriaLabelledBy,i=r?void 0:function(e){const t=e?.gridAriaLabel;return t||(e?.shell?.header?.title??void 0)}(o);r!==e.ariaLabelledBy&&(e.ariaLabelledBy=r,r?t.setAttribute("aria-labelledby",r):t.removeAttribute("aria-labelledby"),n=!0),i!==e.ariaLabel&&(e.ariaLabel=i,i?t.setAttribute("aria-label",i):t.removeAttribute("aria-label"),n=!0);const s=o?.gridAriaDescribedBy;s!==e.ariaDescribedBy&&(e.ariaDescribedBy=s,s?t.setAttribute("aria-describedby",s):t.removeAttribute("aria-describedby"),n=!0);const l=o?.gridAriaRoleDescription;l!==e.ariaRoleDescription&&(e.ariaRoleDescription=l,l?t.setAttribute("aria-roledescription",l):t.removeAttribute("aria-roledescription"),n=!0)}(this.#xt,this.__rowsBodyEl,this.#k)}#Ye(){const e=this.querySelector(".tbw-grid-root");var t;e&&(this.#Ne?(this.#$e||(this.#$e=function(e){const t=document.createElement("div");return t.className="tbw-loading-overlay",t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.appendChild(eo("large",e)),t}(this.#k?.loadingRenderer)),function(e,t){e.appendChild(t)}(e,this.#$e)):(t=this.#$e,t?.remove()))}#Xe(){!function(e,t,o,n,r,i,s){if(!e)return;if(!function(e,t,o){return!(e||t>0||null===o)}(t,o,r))return ct(s.el),s.el=void 0,s.renderer=void 0,s.target=void 0,s.sourceRows=void 0,void(s.filteredOut=void 0);const l=n.length,a=l>0&&0===o;if(s.el&&s.renderer===r&&s.target===i&&s.sourceRows===n&&s.filteredOut===a)return;const c="grid"===i?e:e.querySelector(".rows-container")??e;ct(s.el),s.el=at({sourceRowCount:l,filteredOut:a},r??void 0,i),function(e,t){e.appendChild(t)}(c,s.el),s.renderer=r,s.target=i,s.sourceRows=n,s.filteredOut=a}(this.querySelector(".tbw-grid-root"),this.#Ne,this._rows.length,this.#ce,this.#k?.emptyRenderer,this.#k?.emptyOverlay??"rows",this.#We)}#Ke(e,t){this.#kt();const o=this.#Be.get(e);if(!o)return;const n=this.findRenderedRowElement?.(o.index);n&&to(n,t)}#Ze(e,t,o){this.#kt();const n=this.#Be.get(e);if(!n)return;const r=this.findRenderedRowElement?.(n.index);if(!r)return;const i=this._visibleColumns.findIndex(e=>e.field===t);if(i<0)return;const s=r.children[i];s&&function(e,t){t?(e.classList.add("tbw-cell-loading"),e.setAttribute("aria-busy","true")):(e.classList.remove("tbw-cell-loading"),e.removeAttribute("aria-busy"))}(s,o)}#bt(){if(this.isConnected&&this._headerRowEl&&this._bodyEl){if(this.#de.parseLightDomColumns(this),this.#q){const e=this.#q;this.#q=void 0,this.#de.merge();const t=this.#xe?.getAll()??[];this.#de.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#fe.requestPhase(rt.FULL,"setup")}}#St(e){const t=this._virtualization.container,o=this.#De,n=o?.scrollLeft??0,r=t?.scrollHeight??0,i=o?.scrollWidth??0,s=t?.clientHeight??0,l=o?.clientWidth??0;if(this.refreshVirtualWindow(!1)&&this.#xe?.onScrollRender(),this._virtualization.variableHeights&&(this.#ve&&clearTimeout(this.#ve),this.#ve=window.setTimeout(()=>{this.#ve=0,this.#He.measureRenderedRowHeights(this._virtualization.start,this._virtualization.end)},100)),this.#me){const t=this.#Pe;t.scrollTop=e,t.scrollLeft=n,t.scrollHeight=r,t.scrollWidth=i,t.clientHeight=s,t.clientWidth=l,this.#xe?.onScroll(t)}this.#Pt("tbw-scroll",{scrollTop:e,scrollHeight:r,clientHeight:s,direction:"vertical"})}findHeaderRow(){return this.#le.querySelector(".header-row")}findRenderedRowElement(e){const t=this._virtualization,o=e-t.start;return o>=0&&o<this._rowPool.length&&o<t.end-t.start?this._rowPool[o]:null}_dispatchCellClick(e,t,o,n){const r=this._rows[t],i=this._visibleColumns[o];if(!r||!i)return!1;const s=i.field,l=r[s],a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:o,column:i,field:s,value:l,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(a),a.defaultPrevented)return!0;const c={row:r,rowIndex:t,colIndex:o,column:i,field:s,value:l,cellEl:n,originalEvent:e},d=this.#xe?.onCellClick(c)??!1;return this.#Pt("cell-click",c),d}_dispatchRowClick(e,t,o,n){if(!o)return!1;const r={rowIndex:t,row:o,rowEl:n,originalEvent:e},i=this.#xe?.onRowClick(r)??!1;return this.#Pt("row-click",r),i}_dispatchHeaderClick(e,t,o){if(!t)return!1;const n={colIndex:this._columns.indexOf(t),field:t.field,column:t,headerEl:o,originalEvent:e};return this.#xe?.onHeaderClick(n)??!1}_dispatchKeyDown(e){return this.#xe?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#xe?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}query(e,t){return this.#xe?.queryPlugins({type:e,context:t})??[]}_dispatchCellMouseDown(e){return this.#xe?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#xe?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#xe?.onCellMouseUp(e)}_afterCellRender(e){this.#xe?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#xe?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#xe?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#xe?.hasAfterRowRenderHook()??!1}async ready(){return this.#C}async forceLayout(){return 0===this.#fe.pendingPhase&&this.#fe.requestPhase(rt.FULL,"forceLayout"),this.#fe.whenReady()}async getConfig(){return Object.freeze({...this.#k||{}})}getRowId(e){return co(e,this.id,this.#k.getRowId)}getRow(e){return this.#Le.getRow(e)}_getRowEntry(e){return this.#kt(),this.#Be.get(e)}updateRow(e,t,o="api"){this.#Le.updateRow(e,t,o)}updateRows(e,t="api"){this.#Le.updateRows(e,t)}animateRow(e,t){return lo(this,e,t)}animateRows(e,t){return function(e,t,o){return Promise.all(t.map(t=>lo(e,t,o))).then(e=>e.filter(Boolean).length)}(this,e,t)}animateRowById(e,t){return function(e,t,o){const n=e._rows??[],r=e.getRowId;if(!r)return Promise.resolve(!1);const i=n.findIndex(e=>{if(null==e)return!1;try{return r(e)===t}catch{return!1}});return i<0?Promise.resolve(!1):lo(e,i,o)}(this,e,t)}async insertRow(e,t,o=!0){return this.#Le.insertRow(e,t,o)}async removeRow(e,t=!0){return this.#Le.removeRow(e,t)}async applyTransaction(e,t=!0){return this.#Le.applyTransaction(e,t)}applyTransactionAsync(e){return this.#Le.applyTransactionAsync(e)}focusCell(e,t){this.#Me.focusCell(e,t)}get focusedCell(){return this.#Me.focusedCell}scrollToRow(e,t){this.#Me.scrollToRow(e,t)}scrollToRowById(e,t){this.#Me.scrollToRowById(e,t)}setColumnVisible(e,t){const o=this.#de.setColumnVisible(e,t);return o&&this.requestStateChange(),o}toggleColumnVisibility(e){const t=this.#de.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#de.isColumnVisible(e)}showAllColumns(){this.#de.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#de.getAllColumns()}setColumnOrder(e){this.#de.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#de.getColumnOrder()}getColumnState(){const e=this.#xe?.getAll()??[];return this.#de.collectState(e)}get columnState(){return this.getColumnState()}applyColumnState(e){e&&(this.#ae?this.#qt(e):(this.#q=e,this.#de.initialColumnState=e))}#qt(e){const t=this._columns,o=this._sortState,n=this.#xe?.getAll()??[];this.#de.applyState(e,n);if(!e.columns.some(e=>void 0!==e.sort)&&this.#Ft(t,o))return this.#Ge=void 0,Ie(this),void this.#fe.requestPhase(rt.STYLE,"column-width");this.#bt()}#Ft(e,t){const o=this._columns,n=this._sortState;if(t?.field!==n?.field||t?.direction!==n?.direction)return!1;if(e.length!==o.length)return!1;for(let r=0;r<e.length;r++){const t=e[r],n=o[r];if(t.field!==n.field)return!1;if(!!t.hidden!=!!n.hidden)return!1}return!0}get sortModel(){return this._sortState?{field:this._sortState.field,direction:1===this._sortState.direction?"asc":"desc"}:null}sort(e,t){if(null===e){if(!this._sortState)return;const e=this._sortState.field;this._sortState=null,this.__rowRenderEpoch++;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].__epoch=-1;return this._rows=this.__originalOrder.slice(),this.__originalOrder=[],ot(this),this.refreshVirtualWindow(!0),this.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e,direction:0}})),this._pluginManager?.emitPluginEvent?.("sort-change",{field:e,direction:0}),void this.requestStateChange?.()}const o=this._columns.find(t=>t.field===e);o&&(t?(this._sortState||(this.__originalOrder=this._rows.slice()),Ke(this,o,"desc"===t?-1:1)):Xe(this,o))}requestStateChange(){const e=this.#xe?.getAll()??[];this.#de.requestStateChange(e)}resetColumnState(){this.#q=void 0,this.__originalOrder=[];const e=this.#xe?.getAll()??[];this.#de.resetState(e),this.#de.merge(),this.#bt()}get isToolPanelOpen(){return this.#tt("isToolPanelOpen"),this.#Je().isToolPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#tt("expandedToolPanelSections"),this.#Je().expandedToolPanelSections}openToolPanel(e){this.#tt("openToolPanel()"),this.#Je().openToolPanel(e)}closeToolPanel(){this.#tt("closeToolPanel()"),this.#Je().closeToolPanel()}toggleToolPanel(){this.#tt("toggleToolPanel()"),this.#Je().toggleToolPanel()}toggleToolPanelSection(e){this.#tt("toggleToolPanelSection()"),this.#Je().toggleToolPanelSection(e)}getToolPanels(){return this.#tt("getToolPanels()"),this.#Je().getToolPanels()}registerToolPanel(e){this.#tt("registerToolPanel()"),this.#Je().registerToolPanel(e)}unregisterToolPanel(e){this.#tt("unregisterToolPanel()"),this.#Je().unregisterToolPanel(e)}getHeaderContents(){return this.#tt("getHeaderContents()"),this.#Je().getHeaderContents()}registerHeaderContent(e){this.#tt("registerHeaderContent()"),this.#Je().registerHeaderContent(e)}unregisterHeaderContent(e){this.#tt("unregisterHeaderContent()"),this.#Je().unregisterHeaderContent(e)}getToolbarContents(){return this.#tt("getToolbarContents()"),this.#Je().getToolbarContents()}registerToolbarContent(e){this.#tt("registerToolbarContent()"),this.#Je().registerToolbarContent(e)}unregisterToolbarContent(e){this.#tt("unregisterToolbarContent()"),this.#Je().unregisterToolbarContent(e)}#$t=!1;refreshShellHeader(){this.#$t||(this.#$t=!0,queueMicrotask(()=>{this.#$t=!1,this.isConnected&&(this.#h(),this.#de.markSourcesChanged(),this.#de.merge(),this.#Je()._prepareForRerender(),this.#xe?.afterStructuralRender(),this.#Wt())}))}#Wt(){const e=this.#le.querySelector(".tbw-grid-content")??this.#le.querySelector(".tbw-grid-root");this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this._resizeController=oo(this),this.#ct(e),this.#fe.requestPhase(rt.COLUMNS,"shellRefresh")}#mt=/* @__PURE__ */new Map;registerStyles(e,t){let o=this.#mt.get(e);o||(o=new CSSStyleSheet,this.#mt.set(e,o)),o.replaceSync(t),this.#Bt()}unregisterStyles(e){this.#mt.delete(e)&&this.#Bt()}getRegisteredStyles(){return Array.from(this.#mt.keys())}#Bt(){const e=Array.from(this.#mt.values()),t=document.adoptedStyleSheets.filter(e=>!Array.from(this.#mt.values()).includes(e));document.adoptedStyleSheets=[...t,...e]}registerExternalFocusContainer(e){this.#Me.registerExternalFocusContainer(e)}unregisterExternalFocusContainer(e){this.#Me.unregisterExternalFocusContainer(e)}containsFocus(e){return this.#Me.containsFocus(e)}get lastFocusedElement(){return this.#Me.lastFocusedElement}restoreLastFocus(){return this.#Me.restoreLastFocus()}#h(){this.#Je()._parseLightDomAll(this)}#Vt(){this.#le.querySelector(".tbw-shell-header")&&(this.#Je()._prepareForRerender(),this.#xe?.afterStructuralRender())}#ft(){const e=()=>{this.__lightDomColumnsCache=void 0,this.#bt()};this.#de.registerLightDomHandler("tbw-grid-column",e),this.#de.registerLightDomHandler("tbw-grid-detail",e),this.#de.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,xt(this),this.#de.parseLightDomColumns(this);const e=this.#ot.lightDomTitle,t=this.#ot.hasToolButtonsContainer;this.#h();const o=this.#ot.lightDomTitle,n=this.#ot.hasToolButtonsContainer;(o&&!e||n&&!t)&&(this.#de.markSourcesChanged(),this.#de.merge(),this.#Vt()),this.#fe.requestPhase(rt.COLUMNS,"refreshColumns")}#Rt(){this.#He.updateCachedGeometry()}refreshVirtualWindow(e=!1,t=!1){return this.#He.refreshVirtualWindow(e,t)}invalidateRowHeight(e,t){this.#He.invalidateRowHeight(e,t)}#ut(){this.#h(),this.#de.markSourcesChanged(),this.#de.merge(),function(e){const t=[];for(let o=e.firstChild;o;o=o.nextSibling)1===o.nodeType&&o.classList.contains(X.ROOT)||t.push(o);e.replaceChildren();for(const o of t)e.appendChild(o);e.appendChild(ie({hasShell:!1}))}(this.#le),this.#xe?.afterStructuralRender()}}!function(){const e=Ho.tagName,t=customElements.get(e);if(!t)return customElements.define(e,Ho),void(Ho.activeTag=e);if(t.version===Ho.version)return void(Ho.activeTag=e);const o=`${e}-v${Ho.version.replace(/[^a-zA-Z0-9]+/g,"-").toLowerCase()}`;customElements.get(o)||customElements.define(o,Ho),Ho.activeTag=o}(),globalThis.DataGridElement||(globalThis.DataGridElement=Ho);const Mo=["canHandle","createRenderer","createEditor","processConfig","getTypeDefault","createToolPanelRenderer","parseDetailElement","parseResponsiveCardElement","releaseCell","unmount","beginBatch","endBatch"];function Lo(e){const t=document.createElement(Ho.activeTag);return e&&(t.gridConfig=e),t}function ko(e,t,o){let n=document,r=!1;return"boolean"==typeof t?r=t:t&&(n=t,r=!!o),r?customElements.whenDefined(Ho.activeTag).then(()=>n.querySelector(e)):n.querySelector(e)}const Oo={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",EDIT_OPEN:"edit-open",EDIT_CLOSE:"edit-close",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change",DATA_CHANGE:"data-change",TBW_SCROLL:"tbw-scroll"},Do={SELECTION_CHANGE:"selection-change",TREE_EXPAND:"tree-expand",TREE_LOAD_START:"tree-load-start",TREE_LOAD_END:"tree-load-end",TREE_LOAD_ERROR:"tree-load-error",FILTER_CHANGE:"filter-change",SORT_MODEL_CHANGE:"sort-model-change",EXPORT_START:"export-start",EXPORT_COMPLETE:"export-complete",CLIPBOARD_COPY:"clipboard-copy",CLIPBOARD_PASTE:"clipboard-paste",CONTEXT_MENU_OPEN:"context-menu-open",CONTEXT_MENU_CLOSE:"context-menu-close",HISTORY_CHANGE:"history-change",SERVER_LOADING:"server-loading",SERVER_ERROR:"server-error",COLUMN_VISIBILITY_CHANGE:"column-visibility-change",COLUMN_REORDER:"column-reorder",DETAIL_EXPAND:"detail-expand",GROUP_EXPAND:"group-expand"};function Io(e,t,o){return o?.valueAccessor?Ne(e,o):e?.[t]}function zo(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}const No={sum:(e,t,o)=>{let n=0;for(let r=0;r<e.length;r++){const i=Io(e[r],t,o);if(zo(i))continue;const s=Number(i);isNaN(s)||(n+=s)}return n},avg:(e,t,o)=>{if(!e.length)return 0;let n=0,r=0;for(let i=0;i<e.length;i++){const s=Io(e[i],t,o);if(zo(s))continue;const l=Number(s);isNaN(l)||(n+=l,r++)}return r>0?n/r:0},count:e=>e.length,min:(e,t,o)=>{if(!e.length)return 0;let n=1/0;for(let r=0;r<e.length;r++){const i=Io(e[r],t,o);if(zo(i))continue;const s=Number(i);isNaN(s)||s<n&&(n=s)}return n===1/0?0:n},max:(e,t,o)=>{if(!e.length)return 0;let n=-1/0;for(let r=0;r<e.length;r++){const i=Io(e[r],t,o);if(zo(i))continue;const s=Number(i);isNaN(s)||s>n&&(n=s)}return n===-1/0?0:n},first:(e,t,o)=>e[0]?Io(e[0],t,o):void 0,last:(e,t,o)=>e.length?Io(e[e.length-1],t,o):void 0},qo=/* @__PURE__ */new Map,Fo={register(e,t){qo.set(e,t)},unregister(e){qo.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:qo.get(e)??No[e]},run(e,t,o,n){const r=this.get(e);return r?r(t,o,n):void 0},has:e=>qo.has(e)||e in No,list:()=>[...Object.keys(No),...qo.keys()]},$o={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function Wo(e){return $o[e]??$o.sum}function Bo(e,t){return Wo(e)(t)}export{Y as BaseGridPlugin,g as C,Mo as CORE_CONSUMED_ADAPTER_METHODS,v as D,V as DEFAULT_A11Y_MESSAGES,U as DEFAULT_ANIMATION_CONFIG,G as DEFAULT_GRID_ICONS,Oo as DGEvents,Ho as DataGridElement,a as E,Ct as F,B as FitModeEnum,Q as GridCSSVars,X as GridClasses,K as GridDataAttrs,Ho as GridElement,Z as GridSelectors,f as M,It as MAX_ELEMENT_HEIGHT_PX,w as N,u as P,Do as PluginEvents,To as PluginManager,rt as RenderPhase,p as T,Te as a,Fo as aggregatorRegistry,$t as b,$e as builtInSort,Ft as c,zt as computeScrollMapping,Lo as createGrid,R as d,Fe as defaultComparator,Vt as e,ut as f,qt as fromVirtualScrollTop,He as g,Wo as getValueAggregator,m as h,b as i,qe as invalidateAccessorCache,to as j,q as k,pt as l,c as m,d as n,x as o,h as p,gt as q,ko as queryGrid,mt as r,Ne as resolveCellValue,Bo as runValueAggregator,z as s,Kt as setFeatureResolver,j as t,Nt as toVirtualScrollTop,ft as u,P as v,E as w,y as x,C as y,_ as z};//# sourceMappingURL=index.js.map
1
+ function e(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}const t="TBW021",o="TBW041",n="TBW061",r="TBW062",i="TBW072",s="TBW073",l="TBW074",a="TBW080",c="TBW090",d="TBW091",h="TBW092",u="TBW093",g="TBW100",f="TBW110",p="TBW111",w="TBW112",m="TBW113",b="TBW114",v="TBW140",C="TBW141",y="TBW142",_="TBW143";function S(t,o,n,r){return`${e(n,r)} ${t}: ${o}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(t)}`}function R(e,t,o,n){throw new Error(S(e,t,o,n))}function E(e,t,o,n){console.warn(S(e,t,o,n))}function P(e,t,o,n){console.debug(S(e,t,o,n))}function x(e,t,o,n){console.error(S(e,t,o,n))}const A=/{{\s*([^}]+)\s*}}/g,T="__DG_EMPTY__",H=/^[\w$. '?+\-*/%:()!<>=,&|]+$/,M="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join("")),L=new RegExp(`__(proto|defineGetter|defineSetter)|${M.slice(3).join("|")}|this\\b`),k=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing".split("|")),O=/^on\w+$/i,D=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),I=/^\s*(javascript|vbscript|data|blob):/i;function z(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],o=e.querySelectorAll("*");for(const n of o){const e=n.tagName.toLowerCase();if(k.has(e)){t.push(n);continue}if("svg"===e||"http://www.w3.org/2000/svg"===n.namespaceURI){if(Array.from(n.attributes).some(e=>O.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(n);continue}}const o=[];for(const t of n.attributes){const e=t.name.toLowerCase();O.test(e)?o.push(t.name):(D.has(e)&&I.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&o.push(t.name)}o.forEach(e=>n.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}function N(e,t){const o=function(e){const t=[];let o=0;for(;o<e.length;){const n=e[o];if(" "!==n){if(n>="0"&&n<="9"||"."===n&&o+1<e.length&&e[o+1]>="0"&&e[o+1]<="9"){const n=o;for(;o<e.length&&(e[o]>="0"&&e[o]<="9"||"."===e[o]);)o++;t.push({type:"num",v:Number(e.slice(n,o))});continue}if("'"===n){let n="";for(o++;o<e.length&&"'"!==e[o];)n+=e[o++];if(o>=e.length)return null;o++,t.push({type:"str",v:n});continue}if(n>="a"&&n<="z"||n>="A"&&n<="Z"||"_"===n||"$"===n){const n=o;for(;o<e.length&&/[\w$.]/.test(e[o]);)o++;t.push({type:"id",v:e.slice(n,o)});continue}if(o+2<e.length){const n=e.slice(o,o+3);if("==="===n||"!=="===n){t.push({type:"op",v:n}),o+=3;continue}}if(o+1<e.length){const n=e.slice(o,o+2);if("=="===n||"!="===n||"<="===n||">="===n||"&&"===n||"||"===n){t.push({type:"op",v:n}),o+=2;continue}}if(!"+-*/%<>!?:(),".includes(n))return null;t.push({type:"op",v:n}),o++}else o++}return t}(e);if(!o)return;const n=o;let r=0;function i(){return n[r]}function s(){return n[r++]}function l(e,t){const o=i();return!!o&&(o.type===e&&(void 0===t||o.v===t))}function a(){const e=function(){let e=c();for(;l("op","||");)s(),e=e||c();return e}();if(l("op","?")){s();const t=a();if(!l("op",":"))return;s();const o=a();return e?t:o}return e}function c(){let e=d();for(;l("op","&&");)s(),e=e&&d();return e}function d(){let e=h();for(;;){const t=i();if(!t||"op"!==t.type)break;if("==="===t.v)s(),e=e===h();else if("!=="===t.v)s(),e=e!==h();else if("=="===t.v)s(),e=e==h();else{if("!="!==t.v)break;s(),e=e!=h()}}return e}function h(){let e=u();for(;;){const t=i();if(!t||"op"!==t.type)break;if("<"===t.v)s(),e=e<u();else if(">"===t.v)s(),e=e>u();else if("<="===t.v)s(),e=e<=u();else{if(">="!==t.v)break;s(),e=e>=u()}}return e}function u(){let e=g();for(;;){const t=i();if(!t||"op"!==t.type)break;if("+"===t.v)s(),e+=g();else{if("-"!==t.v)break;s(),e-=g()}}return e}function g(){let e=f();for(;;){const t=i();if(!t||"op"!==t.type)break;if("*"===t.v)s(),e*=f();else if("/"===t.v)s(),e/=f();else{if("%"!==t.v)break;s(),e%=f()}}return e}function f(){return l("op","!")?(s(),!f()):p()}function p(){const e=i();if(e){if("num"===e.type)return s(),e.v;if("str"===e.type)return s(),e.v;if("id"===e.type)return s(),function(e){if("value"===e)return t.value;if(e.startsWith("row.")){const o=e.slice(4);return t.row?t.row[o]:void 0}return"row"===e?t.row:void 0}(e.v);if("op"===e.type&&"("===e.v){s();const e=a();return l("op",")")&&s(),e}return"op"===e.type&&"-"===e.v?(s(),-p()):void 0}}const w=a();return r<n.length?void 0:w}function q(e,t){if(!e||-1===e.indexOf("{{"))return e;const o=[],n=e.replace(A,(e,n)=>{const r=function(e,t){if(e=(e||"").trim(),!e)return T;if(F.test(e))return T;if("value"===e)return null==t.value?T:String(t.value);if(e.startsWith("row.")&&!/[()?]/.test(e)&&!e.includes(":")){const o=e.slice(4),n=t.row?t.row[o]:void 0;return null==n?T:String(n)}if(e.length>80)return T;if(!H.test(e)||L.test(e))return T;const o=e.match(/\./g);if(o&&o.length>1)return T;try{const o=N(e,t),n=null==o?"":String(o);return F.test(n)?T:n||T}catch{return T}}(n,t);return o.push({expr:n.trim(),result:r}),r}),r=(i=n)?i.replace(new RegExp(T,"g"),"").replace(/Reflect\.[^<>{}\s]+|\bProxy\b|ownKeys\([^)]*\)/g,""):i;var i;const s=o.length&&o.every(e=>""===e.result||e.result===T);return F.test(e)||s?"":r}const F=/Reflect|Proxy|ownKeys/;function $(e){if(F.test(e.textContent||"")){for(const t of e.childNodes)t.nodeType===Node.TEXT_NODE&&F.test(t.textContent||"")&&(t.textContent="");F.test(e.textContent||"")&&(e.textContent="")}}function W(e){if(F.test(e)){const e=()=>"";return e.__blocked=!0,e}const t=t=>q(e,t);return t.__blocked=!1,t}const B={STRETCH:"stretch",FIXED:"fixed"},V={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,columnSelected:e=>`Column ${e} selected`,columnSelectionChanged:e=>`${e} columns selected`,columnSelectionCleared:()=>"Column selection cleared",selectionAxisChanged:e=>"column"===e?"Row selection cleared, column selection active":"Column selection cleared, row selection active",editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},U={mode:"reduced-motion",duration:200,easing:"ease-out"},G={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function j(e){return e.replace(/([A-Z])/g,"-$1").toLowerCase()}class Y{static dependencies;static manifest;aliases;version="2.16.4";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}get resolvedConfig(){return this.#e?this.config:{...this.defaultConfig,...this.userConfig}}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},o={};for(const n of Object.keys(t))o[n]=this;for(const n of e){const e=n.userConfig;for(const[r,i]of Object.entries(e)){if(void 0===i)continue;if(!(r in t)){t[r]=i,o[r]=n;continue}if(t[r]===i)continue;const e=o[r]?.constructor.name??this.constructor.name,s=n.constructor.name,l=S("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${r}" supplied by both ${e} and ${s}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(l)}}Object.assign(this.userConfig,t)}refreshUserConfigFrom(e){const t=this.userConfig;for(const o of Object.keys(t))delete t[o];Object.assign(t,e.userConfig)}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const o=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(o),o.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...G,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),o=parseInt(t,10);if(!isNaN(o))return o}return 200}setIcon(e,t,o){e.dataset.icon=j(t),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const n=this.#t(t,o);void 0!==n?"string"==typeof n?e.innerHTML=z(n):n instanceof HTMLElement&&(e.innerHTML="",e.appendChild(n.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const o=document.createElement("span");o.setAttribute("part","sort-indicator"),o.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(o,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(o,"sortNone"));const n=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return n?e.insertBefore(o,n):e.appendChild(o),o}warn(t,o){void 0!==o?console.warn(S(t,o,this.gridElement.id,this.name)):console.warn(`${e(this.gridElement.id,this.name)} ${t}`)}throwDiagnostic(e,t){throw new Error(S(e,t,this.gridElement.id,this.name))}}const X={ROOT:"tbw-grid-root",HEADER:"header",HEADER_ROW:"header-row",HEADER_CELL:"header-cell",ROWS_VIEWPORT:"rows-viewport",ROWS_SPACER:"rows-spacer",ROWS_CONTAINER:"rows",DATA_ROW:"data-grid-row",GROUP_ROW:"group-row",DATA_CELL:"cell",SELECTED:"selected",FOCUSED:"focused",EDITING:"editing",EXPANDED:"expanded",COLLAPSED:"collapsed",DRAGGING:"dragging",RESIZING:"resizing",SORTABLE:"sortable",SORTED_ASC:"sorted-asc",SORTED_DESC:"sorted-desc",HIDDEN:"hidden",STICKY_LEFT:"sticky-left",STICKY_RIGHT:"sticky-right",PINNED_TOP:"pinned-top",PINNED_BOTTOM:"pinned-bottom",TREE_TOGGLE:"tree-toggle",TREE_INDENT:"tree-indent",GROUP_TOGGLE:"group-toggle",GROUP_LABEL:"group-label",GROUP_COUNT:"group-count",RANGE_SELECTION:"range-selection",SELECTION_OVERLAY:"selection-overlay"},K={FIELD:"data-field",GROUP_KEY:"data-group-key"},Z={ROOT:`.${X.ROOT}`,HEADER:`.${X.HEADER}`,HEADER_ROW:`.${X.HEADER_ROW}`,HEADER_CELL:`.${X.HEADER_CELL}`,ROWS_VIEWPORT:`.${X.ROWS_VIEWPORT}`,ROWS_CONTAINER:`.${X.ROWS_CONTAINER}`,DATA_ROW:`.${X.DATA_ROW}`,DATA_CELL:`.${X.DATA_CELL}`,GROUP_ROW:`.${X.GROUP_ROW}`,CELL_BY_FIELD:e=>`.${X.DATA_CELL}[${K.FIELD}="${e}"]`,SELECTED_ROWS:`.${X.DATA_ROW}.${X.SELECTED}`,EDITING_CELL:`.${X.DATA_CELL}.${X.EDITING}`},Q={COLOR_BG:"--tbw-color-bg",COLOR_FG:"--tbw-color-fg",COLOR_FG_MUTED:"--tbw-color-fg-muted",COLOR_BORDER:"--tbw-color-border",COLOR_ACCENT:"--tbw-color-accent",COLOR_HEADER_BG:"--tbw-color-header-bg",COLOR_HEADER_FG:"--tbw-color-header-fg",COLOR_SELECTION:"--tbw-color-selection",COLOR_ROW_HOVER:"--tbw-color-row-hover",COLOR_ROW_ALT:"--tbw-color-row-alt",ROW_HEIGHT:"--tbw-row-height",HEADER_HEIGHT:"--tbw-header-height",CELL_PADDING:"--tbw-cell-padding",FONT_FAMILY:"--tbw-font-family",FONT_SIZE:"--tbw-font-size",BORDER_RADIUS:"--tbw-border-radius",FOCUS_OUTLINE:"--tbw-focus-outline"};function J(e,t){if(t)for(const o in t){const n=t[o];null!=n&&e.setAttribute(o,n)}}function ee(e,t,o){const n=document.createElement(e);return J(n,t),n}function te(e,t){const o=document.createElement("div");return e&&(o.className=e),J(o,t),o}function oe(e,t,o){const n=document.createElement("button");return n.type="button",e&&(n.className=e),J(n,t),n}const ne=document.createElement("template");function re(){return ne.content.cloneNode(!0)}function ie(e){const t=document.createDocumentFragment(),o=te(e.hasShell?`${X.ROOT} has-shell`:X.ROOT);if(e.hasShell&&e.shellBody)e.shellHeader&&o.appendChild(e.shellHeader),o.appendChild(e.shellBody);else{const e=te("tbw-grid-content");e.appendChild(re()),o.appendChild(e)}return t.appendChild(o),t}function se(e){const t=te("tbw-shell-header",{part:"shell-header",role:"presentation"});if(e.title){const o=te("tbw-shell-title");o.textContent=e.title,t.appendChild(o)}const o=te("tbw-shell-content",{part:"shell-content",role:"presentation","data-light-dom-header-content":""});t.appendChild(o);const n=te("tbw-shell-toolbar",{part:"shell-toolbar",role:"presentation"});for(const s of e.configButtons)s.hasRender&&n.appendChild(te("tbw-toolbar-content-slot",{"data-toolbar-content":s.id}));for(const s of e.apiButtons)s.hasRender&&n.appendChild(te("tbw-toolbar-content-slot",{"data-toolbar-content":s.id}));const r=e.configButtons.some(e=>e.hasRender)||e.apiButtons.some(e=>e.hasRender),i=e.hasPanels&&!1!==e.showToggle;if(r&&i&&n.appendChild(te("tbw-toolbar-separator")),i){const t=oe(e.isPanelOpen?"tbw-toolbar-btn active":"tbw-toolbar-btn",{"data-panel-toggle":"",title:"Settings","aria-label":"Toggle settings panel","aria-pressed":String(e.isPanelOpen),"aria-controls":"tbw-tool-panel"});t.dataset.icon="tool-panel",void 0!==e.toolPanelIcon&&(t.innerHTML=z(e.toolPanelIcon)),n.appendChild(t)}return t.appendChild(n),t}function le(e){const t=e.mode??"overlay",o=te("tbw-shell-body",{"data-mode":t}),n=e.panels.length>0,r=1===e.panels.length,i=te("tbw-grid-content");i.appendChild(re());let s=null;if(n){s=ee("aside",{class:e.isPanelOpen?"tbw-tool-panel open":"tbw-tool-panel",part:"tool-panel","data-position":e.position,role:"presentation",id:"tbw-tool-panel",..."dropdown"===t?{popover:"manual"}:{}});const o="left"===e.position?"right":"left";s.appendChild(te("tbw-tool-panel-resize",{"data-resize-handle":"","data-handle-position":o,"aria-hidden":"true"}));const n=e=>{const t=oe(e?"tbw-tool-panel-close tbw-tool-panel-close--inline":"tbw-tool-panel-close",{part:"tool-panel-close","data-panel-close":"",title:"Close panel","aria-label":"Close panel","aria-controls":"tbw-tool-panel"});return t.textContent="✕",t},i=!0===e.showCloseButton&&r;if(e.showCloseButton&&!r){const e=te("tbw-tool-panel-header",{part:"tool-panel-header"});e.appendChild(n(!1)),s.appendChild(e)}const l=te("tbw-tool-panel-content",{role:"presentation"}),a=te("tbw-accordion");for(const t of e.panels){const o=te(`tbw-accordion-section${t.isExpanded?" expanded":""}${r?" single":""}${i?" has-inline-close":""}`,{"data-section":t.id}),s=oe("tbw-accordion-header",{"aria-expanded":String(t.isExpanded),"aria-controls":`tbw-section-${t.id}`});if(r&&s.setAttribute("aria-disabled","true"),t.icon){const e=ee("span",{class:"tbw-accordion-icon"});e.innerHTML=z(t.icon),s.appendChild(e)}const l=ee("span",{class:"tbw-accordion-title"});if(l.textContent=t.title,s.appendChild(l),!r){const t=ee("span",{class:"tbw-accordion-chevron","data-icon":"expand"});void 0!==e.expandIcon&&(t.innerHTML=z(e.expandIcon)),s.appendChild(t)}if(i){const e=te("tbw-accordion-header-row");e.appendChild(s),e.appendChild(n(!0)),o.appendChild(e)}else o.appendChild(s);o.appendChild(te("tbw-accordion-content",{id:`tbw-section-${t.id}`,role:"presentation"})),a.appendChild(o)}l.appendChild(a),s.appendChild(l)}return"left"===e.position&&s?(o.appendChild(s),o.appendChild(i)):(o.appendChild(i),s&&o.appendChild(s)),o}function ae(e){return e?"string"==typeof e?z(e):e.outerHTML:""}function ce(e){return!!e?.header?.title||(!!e?.header?.toolbarContents?.length||(!!e?.toolPanels?.length||(!!e?.headerContents?.length||(!!e?.header?.lightDomContent?.length||!!e?.header?.hasToolButtonsContainer))))}function de(e){return!1!==e?.header?.visible}function he(e,t){const o=e.querySelector("tbw-grid-header");if(!o)return;if(!t.lightDomTitle){const e=o.getAttribute("title");e&&(t.lightDomTitle=e)}const n=o.querySelectorAll("tbw-grid-header-content");n.length>0&&0===t.lightDomHeaderContent.length&&(t.lightDomHeaderContent=Array.from(n)),o.style.display="none"}function ue(e,t,o){const n=e.querySelector(":scope > tbw-grid-tool-buttons");if(!n)return;t.hasToolButtonsContainer=!0;const r="light-dom-toolbar-content";if(t.lightDomToolbarContentIds.has(r))return;const i={id:r,order:0,render:e=>{for(;n.firstChild;)e.appendChild(n.firstChild);return()=>{for(;e.firstChild;)n.appendChild(e.firstChild)}}};t.toolbarContents.set(r,i),t.lightDomToolbarContentIds.add(r),n.style.display="none"}function ge(e,t,o){e.querySelectorAll(":scope > tbw-grid-tool-panel").forEach(e=>{const n=e,r=n.getAttribute("id"),i=n.getAttribute("title");if(!r||!i)return void E("TBW070",`Tool panel missing required id or title attribute: id="${r??""}", title="${i??""}"`);const l=n.getAttribute("icon")??void 0,a=n.getAttribute("tooltip")??void 0,c=parseInt(n.getAttribute("order")??"100",10);let d;const h=o?.(n);if(h)d=h;else{const e=z(n.innerHTML.trim());d=t=>{const o=document.createElement("div");return o.innerHTML=e,t.appendChild(o),()=>o.remove()}}const u=t.toolPanels.get(r);if(u&&!t.lightDomToolPanelIds.has(r))return E(s,`Tool panel "${r}" is already provided by a plugin or the grid API; ignoring the matching light-DOM <tbw-grid-tool-panel>.`),void(n.style.display="none");if(u){if(h){const e=!t.adapterBoundToolPanelIds.has(r),o=u.order!==c||u.icon!==l||u.tooltip!==a;if(u.render=d,u.order=c,u.icon=l,u.tooltip=a,t.adapterBoundToolPanelIds.add(r),e||o){const e=t.panelCleanups.get(r);e&&(e(),t.panelCleanups.delete(r))}}return}const g={id:r,title:i,icon:l,tooltip:a,order:c,render:d};t.toolPanels.set(r,g),t.lightDomToolPanelIds.add(r),h&&t.adapterBoundToolPanelIds.add(r),n.style.display="none"})}function fe(e,t){if(t.contains(e))return!0;const o=e.getRootNode();return o instanceof ShadowRoot&&o.host===t}function pe(e,t){const o=t.lightDomHeaderContent.length>0&&!t.lightDomContentMoved,n=t.headerContents.size>0;if(!o&&!n)return;const r=e.querySelector(".tbw-shell-content");if(!r)return;if(o){for(const e of t.lightDomHeaderContent)e.style.display="",r.appendChild(e);t.lightDomContentMoved=!0}const i=[...t.headerContents.values()].sort((e,t)=>(e.order??100)-(t.order??100));for(const s of i){const e=t.headerContentCleanups.get(s.id);e&&(e(),t.headerContentCleanups.delete(s.id));let o=r.querySelector(`[data-header-content="${s.id}"]`);o||(o=document.createElement("div"),o.setAttribute("data-header-content",s.id),r.appendChild(o));const n=s.render(o);n&&t.headerContentCleanups.set(s.id,n)}}function we(e,t,o){if(t.isPanelOpen)for(const[n,r]of t.toolPanels){const o=t.expandedSections.has(n),i=e.querySelector(`[data-section="${n}"]`),s=i?.querySelector(".tbw-accordion-content");if(!i||!s)continue;i.classList.toggle("expanded",o);const l=i.querySelector(".tbw-accordion-header");if(l&&l.setAttribute("aria-expanded",String(o)),o){if(0===s.children.length){const e=r.render(s);e&&t.panelCleanups.set(n,e)}}else{const e=t.panelCleanups.get(n);e&&(e(),t.panelCleanups.delete(n)),s.innerHTML=""}}}function me(e,t){const o=e.querySelector("[data-panel-toggle]");o&&(o.classList.toggle("active",t.isPanelOpen),o.setAttribute("aria-pressed",String(t.isPanelOpen)))}function be(e,t){const o=e.querySelector(".tbw-tool-panel");o&&(o.classList.toggle("open",t.isPanelOpen),t.isPanelOpen||(o.style.width=""))}ne.innerHTML='\n <div class="tbw-scroll-area">\n <div class="rows-body-wrapper">\n <div class="rows-body" role="grid">\n <div class="header" role="rowgroup">\n <div class="header-row" role="row" part="header-row"></div>\n </div>\n <div class="rows-container" role="presentation">\n <div class="rows-viewport" role="presentation">\n <div class="rows"></div>\n </div>\n </div>\n </div>\n </div>\n </div>\n <div class="faux-vscroll">\n <div class="faux-vscroll-spacer"></div>\n </div>\n <div class="tbw-sr-only" aria-live="polite" aria-atomic="true"></div>\n';const ve="--tbw-tool-panel-anchor";let Ce=0;function ye(){return"undefined"!=typeof CSS&&"function"==typeof CSS.supports&&CSS.supports("anchor-name",ve)}function _e(e,t,o,n){const r=e.querySelector(".tbw-tool-panel");if(r){if(t.dropdownAnchorEl=o,r.dataset.anchor=n?"corner":"below",r.hasAttribute("popover")&&"function"==typeof r.showPopover)try{r.showPopover()}catch{}if(ye()){const e=`${ve}-${++Ce}`;t.dropdownAnchorName=e,o.style.setProperty("anchor-name",e),r.style.setProperty("position-anchor",e),r.style.removeProperty("top"),r.style.removeProperty("left"),r.style.removeProperty("right")}else!function(e,t,o){const n=t.getBoundingClientRect(),r=e.getAttribute("data-position")??"right";if(e.style.position="fixed",e.style.top=`${Math.round((o?n.top:n.bottom)+4)}px`,"left"===r)e.style.left=`${Math.round(n.left)}px`,e.style.right="auto";else{const t="undefined"!=typeof window?window.innerWidth:0;e.style.left="auto",e.style.right=`${Math.round(t-n.right)}px`}}(r,o,n)}}function Se(e){for(const t of e.toolbarContentCleanups.values())t();e.toolbarContentCleanups.clear();for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.headerContentCleanups.values())t();e.headerContentCleanups.clear(),e.lightDomContentMoved=!1}function Re(e,t,o){const n=void 0!==o?.toolPanel?ae(o.toolPanel):void 0,r=void 0!==o?.expand?ae(o.expand):void 0,i=void 0!==o?.collapse?ae(o.collapse):void 0,s=[...e.header?.toolbarContents??[]].sort((e,t)=>(e.order??0)-(t.order??0)),l=[...e.toolPanels??[]].sort((e,t)=>(e.order??100)-(t.order??100));return{headerOptions:{title:e.header?.title??void 0,hasPanels:l.length>0,isPanelOpen:t.isPanelOpen,toolPanelIcon:n,showToggle:!1!==e.header?.toolPanelToggle&&!0!==e.toolPanel?.locked,configButtons:s.map(e=>({id:e.id,hasElement:!1,hasRender:!!e.render})),apiButtons:[]},bodyOptions:{position:e.toolPanel?.position??"right",mode:e.toolPanel?.mode??"overlay",isPanelOpen:t.isPanelOpen,expandIcon:r,collapseIcon:i,showCloseButton:!1===e.header?.visible&&!0!==e.toolPanel?.locked&&"dropdown"!==(e.toolPanel?.mode??"overlay"),panels:l.map(e=>({id:e.id,title:e.title,icon:ae(e.icon),isExpanded:t.expandedSections.has(e.id)}))}}}function Ee(e,t,o,n){const r=e.querySelector(`.${X.ROOT}`),i=r?.querySelector(".tbw-grid-content");if(!r||!i)return function(e,t,o,n){const r=ce(t),i=[];for(let s=e.firstChild;s;s=s.nextSibling)1===s.nodeType&&s.classList.contains(X.ROOT)||i.push(s);e.replaceChildren();for(const s of i)e.appendChild(s);if(r){const{headerOptions:r,bodyOptions:i}=Re(t,o,n),s=ie({hasShell:!0,shellHeader:de(t)?se(r):void 0,shellBody:le(i)});e.appendChild(s)}else{const t=ie({hasShell:!1});e.appendChild(t)}return r}(e,t,o,n);i.remove();const s=ce(t);if(r.replaceChildren(),s){r.className=`${X.ROOT} has-shell`;const{headerOptions:e,bodyOptions:s}=Re(t,o,n),l=de(t)?se(e):void 0,a=le(s),c=a.querySelector(".tbw-grid-content");c&&c.replaceWith(i),l&&r.appendChild(l),r.appendChild(a)}else r.className=X.ROOT,r.appendChild(i);return s}function Pe(e,t){let o=!1;const n={get isInitialized(){return o},setInitialized(e){o=e},get isPanelOpen(){return e.isPanelOpen},get expandedSections(){return[...e.expandedSections]},openToolPanel(o,r){if(0===e.toolPanels.size)return void E("TBW071","No tool panels registered",t.id);let s;if(void 0!==o&&(e.toolPanels.has(o)?s=o:E(i,`Tool panel "${o}" not found`,t.id)),e.isPanelOpen&&s&&e.expandedSections.has(s))return;if(e.isPanelOpen&&s&&!e.expandedSections.has(s))return void n.toggleToolPanelSection(s);if(e.isPanelOpen)return;if(e.isPanelOpen=!0,0===e.expandedSections.size&&e.toolPanels.size>0)if(s)e.expandedSections.add(s);else{const o=t.effectiveConfig?.shell?.toolPanel?.defaultOpen;if(o&&e.toolPanels.has(o))e.expandedSections.add(o);else{const t=[...e.toolPanels.values()].sort((e,t)=>(e.order??100)-(t.order??100))[0];t&&e.expandedSections.add(t.id)}}else if(s&&!e.expandedSections.has(s)){for(const t of[...e.expandedSections])e.expandedSections.delete(t);e.expandedSections.add(s)}const l=t._renderRoot;if(me(l,e),be(l,e),we(l,e,t._accordionIcons),"dropdown"===t.effectiveConfig?.shell?.toolPanel?.mode){const{el:o,corner:n}=function(e){if(e)return{el:e,corner:!1};const o=t._renderRoot.querySelector("[data-panel-toggle]");return o?{el:o,corner:!1}:{el:t._hostElement,corner:!0}}(r?.anchor);_e(l,e,o,n)}t._emit("tool-panel-open",{sections:n.expandedSections})},closeToolPanel(){if(!e.isPanelOpen)return;if(t.effectiveConfig?.shell?.toolPanel?.locked)return;for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.toolPanels.values())t.onClose?.();e.isPanelOpen=!1;const o=t._renderRoot;me(o,e),be(o,e),"dropdown"===t.effectiveConfig?.shell?.toolPanel?.mode&&function(e,t){const o=e.querySelector(".tbw-tool-panel");if(o){if(o.hasAttribute("popover")&&"function"==typeof o.hidePopover)try{o.hidePopover()}catch{}o.style.removeProperty("position-anchor"),o.style.removeProperty("position"),o.style.removeProperty("top"),o.style.removeProperty("left"),o.style.removeProperty("right"),delete o.dataset.anchor}t.dropdownAnchorEl&&(t.dropdownAnchorEl.style.removeProperty("anchor-name"),t.dropdownAnchorEl=null),t.dropdownAnchorName=null}(o,e),t._emit("tool-panel-close",{})},toggleToolPanel(t){e.isPanelOpen?n.closeToolPanel():n.openToolPanel(void 0,t)},reanchorOpenDropdown(){if(!e.isPanelOpen)return;if("dropdown"!==t.effectiveConfig?.shell?.toolPanel?.mode)return;const o=e.dropdownAnchorEl;if(o&&o.isConnected&&e.dropdownAnchorName&&o.style.getPropertyValue("anchor-name")===e.dropdownAnchorName)return;if(!e.dropdownAnchorName&&o&&o.isConnected&&o!==t._hostElement){const e=t._renderRoot.querySelector(".tbw-tool-panel");if("below"===e?.dataset.anchor)return}const n=t._renderRoot.querySelector("[data-panel-toggle]");if(n&&n!==t._hostElement){if(e.dropdownAnchorName&&ye()&&function(e,t,o){const n=t.dropdownAnchorName;if(!n)return!1;const r=e.querySelector(".tbw-tool-panel");if(!r)return!1;const i=t.dropdownAnchorEl;if(i&&i!==o&&i.style.removeProperty("anchor-name"),o.style.setProperty("anchor-name",n),r.style.setProperty("position-anchor",n),r.style.removeProperty("top"),r.style.removeProperty("left"),r.style.removeProperty("right"),r.dataset.anchor="below",t.dropdownAnchorEl=o,r.hasAttribute("popover")&&"function"==typeof r.showPopover)try{r.showPopover()}catch{}return!0}(t._renderRoot,e,n))return;_e(t._renderRoot,e,n,!1)}else o!==t._hostElement||_e(t._renderRoot,e,t._hostElement,!0)},toggleToolPanelSection(o){const n=e.toolPanels.get(o);if(!n)return void E(i,`Tool panel section "${o}" not found`,t.id);if(1===e.toolPanels.size)return;const r=t._renderRoot,s=e.expandedSections.has(o);if(s){const t=e.panelCleanups.get(o);t&&(t(),e.panelCleanups.delete(o)),n.onClose?.(),e.expandedSections.delete(o),xe(r,o,!1)}else{for(const[t,n]of e.toolPanels)if(t!==o&&e.expandedSections.has(t)){const o=e.panelCleanups.get(t);o&&(o(),e.panelCleanups.delete(t)),n.onClose?.(),e.expandedSections.delete(t),xe(r,t,!1);const i=r.querySelector(`[data-section="${t}"] .tbw-accordion-content`);i&&(i.innerHTML="")}e.expandedSections.add(o),xe(r,o,!0),function(e,t,o){const n=t.toolPanels.get(o);if(!n?.render)return;const r=e.querySelector(`[data-section="${o}"] .tbw-accordion-content`);if(!r)return;const i=n.render(r);i&&t.panelCleanups.set(o,i)}(r,e,o)}t._emit("tool-panel-section-toggle",{id:o,expanded:!s})},getToolPanels:()=>[...e.toolPanels.values()],registerToolPanel(n){e.toolPanels.has(n.id)?E(s,`Tool panel "${n.id}" already registered`,t.id):(e.toolPanels.set(n.id,n),o&&t.refreshShellHeader?.())},unregisterToolPanel(n){if(e.expandedSections.has(n)){const t=e.panelCleanups.get(n);t&&(t(),e.panelCleanups.delete(n)),e.expandedSections.delete(n)}e.toolPanels.delete(n),o&&t.refreshShellHeader?.()},getHeaderContents:()=>[...e.headerContents.values()],registerHeaderContent(n){e.headerContents.has(n.id)?E(l,`Header content "${n.id}" already registered`,t.id):(e.headerContents.set(n.id,n),o&&pe(t._renderRoot,e))},unregisterHeaderContent(o){const n=e.headerContentCleanups.get(o);n&&(n(),e.headerContentCleanups.delete(o));const r=e.headerContents.get(o);r?.onDestroy?.(),e.headerContents.delete(o);const i=t._renderRoot.querySelector(`[data-header-content="${o}"]`);i?.remove()},getToolbarContents:()=>[...e.toolbarContents.values()].sort((e,t)=>(e.order??0)-(t.order??0)),registerToolbarContent(n){e.toolbarContents.has(n.id)?E("TBW075",`Toolbar content "${n.id}" already registered`,t.id):(e.toolbarContents.set(n.id,n),o&&t.refreshShellHeader?.())},unregisterToolbarContent(n){const r=e.toolbarContentCleanups.get(n);r&&(r(),e.toolbarContentCleanups.delete(n));const i=e.toolbarContents.get(n);i?.onDestroy&&i.onDestroy(),e.toolbarContents.delete(n),o&&t.refreshShellHeader?.()}};return n}function xe(e,t,o){const n=e.querySelector(`[data-section="${t}"]`);n&&n.classList.toggle("expanded",o)}class Ae extends Y{name="shell";styles="@layer tbw-base{tbw-grid{.tbw-shell-header{display:flex;align-items:center;gap:8px;min-height:var(--tbw-shell-header-height);padding:0 8px;background:var(--tbw-shell-header-bg);border-bottom:1px solid var(--tbw-shell-header-border);flex-shrink:0}.tbw-shell-title{font-size:var(--tbw-shell-title-font-size);font-weight:var(--tbw-shell-title-font-weight);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tbw-shell-content{flex:1;display:flex;align-items:center;gap:12px;min-width:0;overflow:hidden}.tbw-shell-toolbar{display:flex;align-items:center;gap:var(--tbw-toolbar-button-gap);flex-shrink:0}.tbw-toolbar-btn{display:inline-flex;align-items:center;justify-content:center;width:var(--tbw-toolbar-button-size);height:var(--tbw-toolbar-button-size);padding:0;border:1px solid transparent;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg);cursor:pointer;font-size:16px;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease),border-color var(--tbw-transition-duration) var(--tbw-transition-ease);&:hover{background:var(--tbw-color-row-hover)}&:focus-visible{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}&.active{background:var(--tbw-focus-background);border-color:var(--tbw-color-accent)}&:disabled{opacity:.5;cursor:not-allowed}}.tbw-toolbar-separator{width:1px;height:20px;background:var(--tbw-color-border);margin:0 4px}.tbw-shell-body{position:relative;display:flex;flex:1;min-height:0;overflow:visible}.tbw-grid-content{flex:1;min-width:0;min-height:0;display:flex;flex-direction:row;overflow:hidden;touch-action:none}}}@layer tbw-base{tbw-grid{.tbw-tool-panel{position:absolute;top:0;bottom:0;right:0;width:0;overflow:hidden;background:var(--tbw-tool-panel-bg);border-left:1px solid var(--tbw-tool-panel-border);transition:width var(--tbw-tool-panel-transition);display:flex;flex-direction:column;z-index:var(--tbw-z-layer-toolpanel, 31);box-shadow:-2px 0 8px var(--tbw-color-shadow);&[data-position=left]{right:auto;left:0;border-left:none;border-right:1px solid var(--tbw-tool-panel-border);box-shadow:2px 0 8px var(--tbw-color-shadow)}&.open{width:var(--tbw-tool-panel-width)}}.tbw-shell-body[data-mode=push]{.tbw-tool-panel{position:relative;inset:auto;flex-shrink:0;box-shadow:none;z-index:auto;border-left:none;border-right:none;&.open{border-left:1px solid var(--tbw-tool-panel-border)}&[data-position=left].open{border-left:none;border-right:1px solid var(--tbw-tool-panel-border)}}.tbw-tool-panel-resize{display:none}}.tbw-tool-panel[popover]{position:fixed;inset:auto;width:var(--tbw-tool-panel-width);max-width:calc(100vw - 16px);height:auto;max-height:min(70vh,480px);overflow:hidden auto;margin:4px 0 0;padding:0;border:1px solid var(--tbw-tool-panel-border);border-radius:var(--tbw-border-radius, 6px);box-shadow:0 8px 24px var(--tbw-color-shadow);transition:none;display:none;&:popover-open,&.open{display:flex;width:var(--tbw-tool-panel-width)}.tbw-tool-panel-resize{display:none}}@supports (anchor-name: --x){.tbw-tool-panel[popover]{top:anchor(bottom);right:anchor(right);left:auto;position-try-fallbacks:flip-block,flip-inline,flip-block flip-inline;&[data-anchor=corner]{top:anchor(top)}&[data-position=left]{left:anchor(left);right:auto}}}.tbw-tool-panel-resize{position:absolute;top:0;bottom:0;width:6px;cursor:col-resize;background:transparent;z-index:10;transition:background var(--tbw-transition-duration) var(--tbw-transition-ease);&[data-handle-position=left]{left:0}&[data-handle-position=right]{right:0}&:hover,&.resizing{background:var(--tbw-color-accent)}}.tbw-tool-panel-header{display:flex;align-items:center;justify-content:flex-end;min-height:var(--tbw-tool-panel-header-height);padding:0 12px;border-bottom:1px solid var(--tbw-tool-panel-border);flex-shrink:0}.tbw-tool-panel-title{font-weight:600;font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.tbw-tool-panel-close{display:inline-flex;align-items:center;justify-content:center;width:24px;height:24px;padding:0;border:none;border-radius:var(--tbw-border-radius);background:transparent;color:var(--tbw-color-fg-muted);cursor:pointer;font-size:14px;&:hover{background:var(--tbw-color-row-hover);color:var(--tbw-color-fg)}}.tbw-accordion-header-row{display:flex;align-items:stretch;.tbw-accordion-header{flex:1;min-width:0}}.tbw-tool-panel-close--inline{align-self:center;flex-shrink:0;margin-inline-end:8px}.tbw-tool-panel-content{flex:1;overflow:auto}.tbw-accordion{display:flex;flex-direction:column;gap:0}.tbw-accordion-section{border-bottom:1px solid var(--tbw-tool-panel-border);&:last-child{border-bottom:none}&.single .tbw-accordion-header{cursor:default;&:hover{background:transparent}}&.expanded{.tbw-accordion-chevron{transform:rotate(90deg)}.tbw-accordion-content{display:block}}}.tbw-accordion-header{display:flex;align-items:center;gap:8px;width:100%;padding:10px 12px;border:none;background:transparent;color:var(--tbw-color-fg);font-size:13px;font-weight:600;text-align:start;cursor:pointer;user-select:none;&:hover{background:var(--tbw-color-row-hover)}}.tbw-accordion-chevron{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:10px;color:var(--tbw-color-fg-muted);transition:transform .15s ease;flex-shrink:0}.tbw-accordion-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;font-size:14px;flex-shrink:0}.tbw-accordion-title{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.tbw-accordion-content{display:none}}}";#o;#n;#r;#i;#s;#l;#a;#c=!1;get hasState(){return void 0!==this.#o}ensureState(e){if(this.#o)return;const t={toolPanels:/* @__PURE__ */new Map,headerContents:/* @__PURE__ */new Map,toolbarContents:/* @__PURE__ */new Map,hasToolButtonsContainer:!1,lightDomHeaderContent:[],lightDomTitle:null,lightDomToolPanelIds:/* @__PURE__ */new Set,adapterBoundToolPanelIds:/* @__PURE__ */new Set,lightDomToolbarContentIds:/* @__PURE__ */new Set,apiToolPanelIds:/* @__PURE__ */new Set,apiHeaderContentIds:/* @__PURE__ */new Set,isPanelOpen:!1,expandedSections:/* @__PURE__ */new Set,headerContentCleanups:/* @__PURE__ */new Map,panelCleanups:/* @__PURE__ */new Map,toolbarContentCleanups:/* @__PURE__ */new Map,lightDomContentMoved:!1,dropdownAnchorEl:null,dropdownAnchorName:null};this.#o=t,this.#n=Pe(t,e)}get shellState(){return this.#o}get shellController(){return this.#n}get isToolPanelOpen(){return!!this.hasState&&this.shellController.isPanelOpen}get expandedToolPanelSections(){return this.hasState?this.shellController.expandedSections:[]}openToolPanel(e,t){this.shellController?.openToolPanel(e,t)}closeToolPanel(){this.shellController?.closeToolPanel()}toggleToolPanel(e){this.shellController?.toggleToolPanel(e)}toggleToolPanelSection(e){this.shellController?.toggleToolPanelSection(e)}getToolPanels(){return this.hasState?this.shellController.getToolPanels():[]}registerToolPanel(e){this.hasState&&(this.shellState.apiToolPanelIds.add(e.id),this.shellController.registerToolPanel(e))}unregisterToolPanel(e){this.hasState&&(this.shellState.apiToolPanelIds.delete(e),this.shellController.unregisterToolPanel(e))}getHeaderContents(){return this.hasState?this.shellController.getHeaderContents():[]}registerHeaderContent(e){this.hasState&&(this.shellState.apiHeaderContentIds.add(e.id),this.shellController.registerHeaderContent(e))}unregisterHeaderContent(e){this.hasState&&(this.shellState.apiHeaderContentIds.delete(e),this.shellController.unregisterHeaderContent(e))}getToolbarContents(){return this.hasState?this.shellController.getToolbarContents():[]}registerToolbarContent(e){this.shellController?.registerToolbarContent(e)}unregisterToolbarContent(e){this.shellController?.unregisterToolbarContent(e)}attach(e){super.attach(e);const t=()=>this.#d(e);this.#l=t,e._registerLightDomHandler("tbw-grid-header",t),e._registerLightDomHandler("tbw-grid-tool-buttons",t),e._registerLightDomHandler("tbw-grid-tool-panel",t)}#h(e){const t=e._hostElement;he(t,this.shellState),ue(t,this.shellState),ge(t,this.shellState,e._getToolPanelRendererFactory())}#d(e){if(!this.hasState)return;const t=this.shellState,o=t.lightDomTitle,n=t.hasToolButtonsContainer;this.#h(e);const r=t.lightDomTitle,i=t.hasToolButtonsContainer;(r&&!o||i&&!n)&&(e._requestConfigMerge(),e._renderRoot.querySelector(".tbw-shell-header")&&(Se(t),this.afterStructuralRender()))}_parseLightDomHeader(e){const t=e._hostElement;he(t,this.shellState),ue(t,this.shellState)}_parseLightDomToolPanels(e){ge(e._hostElement,this.shellState,e._getToolPanelRendererFactory())}_parseLightDomAll(e){this._parseLightDomHeader(e),this._parseLightDomToolPanels(e)}_prepareForRerender(){this.hasState&&Se(this.shellState)}_renderOpenPanelContent(e){this.hasState&&we(e._renderRoot,this.shellState)}_shouldRenderHeader(e){return ce(e)}processConfig(e){if(!this.hasState)return;const t=this.shellState,o=this.resolvedConfig;if(e.shell={...o,...e.shell},e.shell.header={...o.header,...e.shell.header},t.lightDomTitle&&!e.shell.header.title&&(e.shell.header.title=t.lightDomTitle),t.lightDomHeaderContent?.length>0&&(e.shell.header.lightDomContent=t.lightDomHeaderContent),t.hasToolButtonsContainer&&(e.shell.header.hasToolButtonsContainer=!0),t.toolPanels.size>0){const o=Array.from(t.toolPanels.values());o.sort((e,t)=>(e.order??100)-(t.order??100)),e.shell.toolPanels=o}if(t.headerContents.size>0){const o=Array.from(t.headerContents.values());o.sort((e,t)=>(e.order??100)-(t.order??100)),e.shell.headerContents=o}const n=Array.from(t.toolbarContents.values()),r=this.grid?._sourceConfig?.shell?.header?.toolbarContents??[],i=new Set(r.map(e=>e.id)),s=[...r];for(const l of n)i.has(l.id)||s.push(l);s.sort((e,t)=>(e.order??0)-(t.order??0)),e.shell.header.toolbarContents=s}afterStructuralRender(){const e=this.grid;if(!e||!this.hasState)return;const t=this.shellState;Ee(e._renderRoot,e.effectiveConfig?.shell,{isPanelOpen:t.isPanelOpen,expandedSections:t.expandedSections},e.effectiveConfig?.icons)&&(this.#u(e),this.shellController.setInitialized(!0),this.#g(e))}afterRender(){const e=this.grid;e&&this.hasState&&(this.shellState.isPanelOpen?(this.shellController.reanchorOpenDropdown(),this.#f(e)):this.#p())}#f(e){"dropdown"===e.effectiveConfig?.shell?.toolPanel?.mode?"undefined"!=typeof MutationObserver&&(this.#a||(this.#a=new MutationObserver(()=>{this.grid&&this.hasState&&this.shellState.isPanelOpen?this.shellController.reanchorOpenDropdown():this.#p()})),this.#c||(this.#a.observe(e._renderRoot,{childList:!0,subtree:!0}),this.#c=!0)):this.#p()}#p(){this.#a&&this.#c&&(this.#a.disconnect(),this.#c=!1)}#g(e){const t=this.shellState,o=e._renderRoot,n=e.effectiveConfig?.shell;pe(o,t),function(e,t,o){const n=t?.header?.toolbarContents??[],r=[...o.toolbarContents.values()],i=new Set(n.map(e=>e.id)),s=[...n];for(const l of r)i.has(l.id)||s.push(l);for(const l of s){if(o.toolbarContentCleanups.has(l.id))continue;if(!l.render)continue;const t=e.querySelector(`[data-toolbar-content="${l.id}"]`);if(!t)continue;const n=l.render(t);n&&o.toolbarContentCleanups.set(l.id,n)}}(o,n,t);const r=n?.toolPanel,i=r?.defaultOpen;i&&t.toolPanels.has(i)&&t.expandedSections.add(i);const s=!0===r?.locked||"open"===r?.initialState||void 0===r?.initialState&&void 0!==i&&t.toolPanels.has(i);!t.isPanelOpen&&t.toolPanels.size>0&&s&&this.openToolPanel(),t.isPanelOpen&&(be(o,t),we(o,t,(e.effectiveConfig,e.effectiveConfig)),me(o,t),this.shellController.reanchorOpenDropdown())}#u(e){const t=e._renderRoot,o=e.effectiveConfig?.shell,n=this.shellState;!function(e,t,o,n){const r=e.querySelector(".tbw-shell-toolbar");r&&r.addEventListener("click",e=>{e.target.closest("[data-panel-toggle]")&&n.onPanelToggle()});const i=e.querySelector(".tbw-tool-panel");i&&n.onPanelClose&&i.addEventListener("click",e=>{e.target.closest("[data-panel-close]")&&n.onPanelClose()});const s=e.querySelector(".tbw-accordion");s&&s.addEventListener("click",e=>{const t=e.target.closest(".tbw-accordion-header");if(t){const e=t.closest("[data-section]"),o=e?.getAttribute("data-section");o&&n.onSectionToggle(o)}})}(t,0,0,{onPanelToggle:()=>this.toggleToolPanel(),onSectionToggle:e=>this.toggleToolPanelSection(e),onPanelClose:()=>this.closeToolPanel()}),this.#r?.(),this.#r=function(e,t,o){const n=e.querySelector(".tbw-tool-panel"),r=e.querySelector("[data-resize-handle]"),i=e.querySelector(".tbw-shell-body");if(!n||!r||!i)return()=>{};const s=t?.toolPanel?.position??"right";let l=0,a=0,c=0,d=!1;const h=e=>{if(!d)return;e.preventDefault();const t="left"===s?e.clientX-l:l-e.clientX,o=Math.min(c,Math.max(200,a+t));n.style.width=`${o}px`},u=()=>{if(!d)return;d=!1,r.classList.remove("resizing"),n.style.transition="",document.body.style.cursor="",document.body.style.userSelect="";const e=n.getBoundingClientRect().width;o(e),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",u)},g=e=>{e.preventDefault(),d=!0,l=e.clientX,a=n.getBoundingClientRect().width,c=i.getBoundingClientRect().width-20,r.classList.add("resizing"),n.style.transition="none",document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",h),document.addEventListener("mouseup",u)};return r.addEventListener("mousedown",g),()=>{r.removeEventListener("mousedown",g),document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",u)}}(t,o,t=>{e._hostElement.style.setProperty("--tbw-tool-panel-width",`${t}px`)}),this.#i?.(),this.#i=function(e,t,o,n){const r=t?.toolPanel?.mode;if("dropdown"!==r&&!t?.toolPanel?.closeOnClickOutside)return()=>{};if("push"===r)return()=>{};const i=t=>{if(!o.isPanelOpen)return;const r=o.dropdownAnchorEl;for(const o of t.composedPath()){if(null!=r&&o===r)return;if(o instanceof Element&&(o.classList?.contains("tbw-tool-panel")||o.matches?.("[data-panel-toggle]"))&&fe(o,e))return}n()};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)}(e._hostElement,o,n,()=>this.closeToolPanel()),this.#s?.(),this.#s=function(e,t,o){if("push"===e?.toolPanel?.mode)return()=>{};const n=e=>{"Escape"!==e.key||e.defaultPrevented||t.isPanelOpen&&o()};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)}(o,n,()=>this.closeToolPanel())}#w(){this.#r?.(),this.#r=void 0,this.#i?.(),this.#i=void 0,this.#s?.(),this.#s=void 0}detach(){super.detach()}disposeShellState(){this.#w(),this.#p(),this.#a=void 0;const e=this.grid;e&&this.#l&&(e._unregisterLightDomHandler("tbw-grid-header"),e._unregisterLightDomHandler("tbw-grid-tool-buttons"),e._unregisterLightDomHandler("tbw-grid-tool-panel"),this.#l=void 0),this.#o&&(!function(e){for(const t of e.headerContentCleanups.values())t();e.headerContentCleanups.clear();for(const t of e.panelCleanups.values())t();e.panelCleanups.clear();for(const t of e.toolbarContentCleanups.values())t();e.toolbarContentCleanups.clear();for(const t of e.toolbarContents.values())t.onDestroy?.();if(e.isPanelOpen)for(const t of e.expandedSections){const o=e.toolPanels.get(t);o?.onClose?.()}e.isPanelOpen=!1,e.expandedSections.clear(),e.toolPanels.clear(),e.headerContents.clear(),e.toolbarContents.clear(),e.lightDomHeaderContent=[],e.lightDomToolPanelIds.clear(),e.adapterBoundToolPanelIds.clear(),e.lightDomToolbarContentIds.clear(),e.lightDomContentMoved=!1}(this.#o),this.#n?.setInitialized(!1))}}function Te(e,t){if(!e)return;const o="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===o?.a11y?.announcements)return;const n=e.querySelector?.(".tbw-sr-only");n&&(n.textContent="",requestAnimationFrame(()=>{n.textContent=t}))}function He(e,t,...o){const n=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,r=n?.a11y?.messages?.[t];return r?r(...o):V[t](...o)}function Me(e,t){if(!(e&&e.length||t&&t.length))return[];if(!e||!e.length)return t||[];if(!t||!t.length)return e;const o={},n=t;for(let s=0;s<n.length;s++){const e=n[s],t=o[e.field];if(t){e.header&&!t.header&&(t.header=e.header),e.type&&!t.type&&(t.type=e.type),e.sortable&&(t.sortable=!0),e.resizable&&(t.resizable=!0),null!=e.width&&null==t.width&&(t.width=e.width),null!=e.minWidth&&null==t.minWidth&&(t.minWidth=e.minWidth),e.__viewTemplate&&(t.__viewTemplate=e.__viewTemplate),e.__headerTemplate&&(t.__headerTemplate=e.__headerTemplate),e.__element&&!t.__element&&(t.__element=e.__element);const o=e.renderer||e.viewRenderer,n=t.renderer||t.viewRenderer;o&&!n&&(t.viewRenderer=o,e.renderer&&(t.renderer=o)),e.editor&&!t.editor&&(t.editor=e.editor),e.headerRenderer&&!t.headerRenderer&&(t.headerRenderer=e.headerRenderer),e.headerLabelRenderer&&!t.headerLabelRenderer&&(t.headerLabelRenderer=e.headerLabelRenderer)}else o[e.field]={...e}}const r=e.map(e=>{const t=o[e.field];if(!t)return e;const n={...e};t.header&&!n.header&&(n.header=t.header),t.type&&!n.type&&(n.type=t.type),n.sortable=e.sortable||t.sortable,!0!==e.resizable&&!0!==t.resizable||(n.resizable=!0),null!=t.width&&null==n.width&&(n.width=t.width),null!=t.minWidth&&null==n.minWidth&&(n.minWidth=t.minWidth),t.__viewTemplate&&(n.__viewTemplate=t.__viewTemplate),t.__headerTemplate&&(n.__headerTemplate=t.__headerTemplate),t.__element&&!n.__element&&(n.__element=t.__element);const r=t.renderer||t.viewRenderer,i=n.renderer||n.viewRenderer;return r&&!i&&(n.viewRenderer=r,t.renderer&&(n.renderer=r)),t.editor&&!n.editor&&(n.editor=t.editor),n.headerRenderer||n.headerLabelRenderer||(t.headerRenderer?n.headerRenderer=t.headerRenderer:t.headerLabelRenderer&&(n.headerLabelRenderer=t.headerLabelRenderer)),delete o[e.field],n}),i=Object.keys(o);for(let s=0;s<i.length;s++)r.push(o[i[s]]);return r}function Le(e,t){try{e.part?.add?.(t)}catch{}const o=e.getAttribute("part");o?o.split(/\s+/).includes(t)||e.setAttribute("part",o+" "+t):e.setAttribute("part",t)}function ke(e){const t=e.effectiveConfig?.fitMode||e.fitMode||B.STRETCH;if(t!==B.STRETCH&&t!==B.FIXED)return;if(e.__didInitialAutoSize)return;if(!e.isConnected)return;const o=Array.from(e._headerRowEl?.children||[]);if(!o.length)return;let n=!1;const r=e._visibleColumns;for(let i=0;i<r.length;i++){const t=r[i];if(t.width)continue;const s=o[i];let l=s?s.scrollWidth:0;for(let o=0;o<e._rowPool.length;o++){const t=e._rowPool[o].children[i];if(t){const e=t.scrollWidth;e>l&&(l=e)}}l>0&&(t.width=l+2,t.__autoSized=!0,n=!0)}n&&Ie(e),e.__didInitialAutoSize=!0}const Oe=/^(?:\d+(?:\.\d+)?(?:px|%|fr|em|rem|ch|vw|vh|vmin|vmax)|calc\(.+\)|min-content|max-content|minmax\(.+\)|fit-content\(.+\)|auto)$/i;function De(e,t){return"number"==typeof e?`${e}px`:(Oe.test(e)||E("TBW050",`Column '${t??"?"}' has an invalid CSS width value: '${e}'. Expected a number (px) or a valid CSS unit string (e.g. '30%', '2fr', 'calc(...)').`),e)}function Ie(e){const t=e.effectiveConfig?.fitMode||e.fitMode||B.STRETCH;e._gridTemplate=t===B.STRETCH?e._visibleColumns.map(e=>{if(null!=e.width)return De(e.width,e.field);const t=e.minWidth;return null!=t?`minmax(${t}px, 1fr)`:"1fr"}).join(" ").trim():e._visibleColumns.map(e=>null!=e.width?De(e.width,e.field):"max-content").join(" "),e.style.setProperty("--tbw-column-template",e._gridTemplate)}const ze=/* @__PURE__ */new WeakMap;function Ne(e,t,o=-1){if(!t.valueAccessor)return e?.[t.field];if("object"!=typeof e||null===e)return t.valueAccessor({row:e,column:t,rowIndex:o});const n=e,r=t.field;let i=ze.get(n);if(i){const e=i.get(r);if(void 0!==e)return e.v}else i=/* @__PURE__ */new Map,ze.set(n,i);const s=t.valueAccessor({row:e,column:t,rowIndex:o});return i.set(r,{v:s}),s}function qe(e,t){e&&(t?ze.get(e)?.delete(t):ze.delete(e))}function Fe(e,t){return null==e&&null==t?0:null==e?-1:null==t||e>t?1:e<t?-1:0}function $e(e,t,o){const n=o.find(e=>e.field===t.field),r=n?.sortComparator,{field:i,direction:s}=t,l=[...e];return r?n?.valueAccessor?l.sort((e,t)=>r(Ne(e,n),Ne(t,n),e,t)*s):l.sort((e,t)=>r(e[i],t[i],e,t)*s):n?.valueAccessor?Be(l,n,s):We(l,i,s),l}function We(e,t,o){e.sort((e,n)=>{const r=Ve(e,n);if(0!==r)return r;const i=e[t],s=n[t];return null==i&&null==s?0:null==i?-o:null==s||i>s?o:i<s?-o:0})}function Be(e,t,o){e.sort((e,n)=>{const r=Ve(e,n);if(0!==r)return r;const i=Ne(e,t),s=Ne(n,t);return null==i&&null==s?0:null==i?-o:null==s||i>s?o:i<s?-o:0})}function Ve(e,t){const o=!0===e?.__loading;return o===(!0===t?.__loading)?0:o?1:-1}function Ue(e,t,o,n){const r=n.find(e=>e.field===t),i=r?.sortComparator;i?r?.valueAccessor?e.sort((e,t)=>i(Ne(e,r),Ne(t,r),e,t)*o):e.sort((e,n)=>i(e[t],n[t],e,n)*o):r?.valueAccessor?Be(e,r,o):We(e,t,o)}function Ge(e,t,o,n){e._rows=t,e.__rowRenderEpoch++;for(let r=0;r<e._rowPool.length;r++)e._rowPool[r].__epoch=-1;ot(e),e.refreshVirtualWindow(!0),je(e,o,n)}function je(e,t,o){const n={field:t.field,direction:o};e.dispatchEvent(new CustomEvent("sort-change",{detail:n})),e._pluginManager?.emitPluginEvent?.("sort-change",n),Te(e,He(e,0===o?"sortCleared":"sortApplied",t.header??t.field,1===o?"ascending":"descending")),e.requestStateChange?.()}function Ye(e){return e._pluginManager?._hasRowStructurePlugins??!1}function Xe(e,t){if(e._sortState&&e._sortState.field===t.field)if(1===e._sortState.direction)Ke(e,t,-1);else{if(e._sortState=null,Ye(e))return e._requestSchedulerPhase(4,"sort-clear"),void je(e,t,0);e.__rowRenderEpoch++;for(let t=0;t<e._rowPool.length;t++)e._rowPool[t].__epoch=-1;e._rows=e.__originalOrder.slice(),e.__originalOrder=[],ot(e);const o=e._headerRowEl?.querySelectorAll('[role="columnheader"].sortable');if(o)for(let t=0;t<o.length;t++){const n=o[t];n.getAttribute("aria-sort")&&("ascending"!==n.getAttribute("aria-sort")&&"descending"!==n.getAttribute("aria-sort")||e._sortState)||n.setAttribute("aria-sort","none")}e.refreshVirtualWindow(!0),je(e,t,0)}else e._sortState||(e.__originalOrder=e._rows.slice()),Ke(e,t,1)}function Ke(e,t,o){if(e._sortState={field:t.field,direction:o},Ye(e))return e._requestSchedulerPhase(4,"sort-apply"),void je(e,t,o);const n={field:t.field,direction:o},r=e._columns,i=e.effectiveConfig?.sortHandler??$e;if(i===$e)return Ue(e._rows,n.field,o,r),void Ge(e,e._rows,t,o);const s=i(e._rows,n,r);s&&"function"==typeof s.then?s.then(n=>{Ge(e,n,t,o)}):Ge(e,s,t,o)}function Ze(e,t){return!1!==e.effectiveConfig?.sortable&&!0===t.sortable}function Qe(e,t){return!1!==e.effectiveConfig?.resizable&&!1!==t.resizable}function Je(e,t){const o=document.createElement("span");Le(o,"sort-indicator");const n=e._sortState?.field===t.field?e._sortState.direction:0,r=1===n?"sortAsc":-1===n?"sortDesc":"sortNone";o.dataset.icon=j(r);const i=e.icons?.[r];return void 0!==i&&function(e,t){"string"==typeof t?e.innerHTML=z(t):t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}(o,i),o}function et(e,t,o){const n=document.createElement("div");return n.className="resize-handle",n.setAttribute("aria-hidden","true"),n.addEventListener("mousedown",n=>{n.stopPropagation(),n.preventDefault(),e._resizeController.start(n,t,o)}),n.addEventListener("dblclick",o=>{o.stopPropagation(),o.preventDefault(),e._resizeController.resetColumn(t)}),n}function tt(e,t,o,n){n.classList.add(X.SORTABLE),n.tabIndex=0;const r=e._sortState?.field===t.field?e._sortState.direction:0;n.setAttribute("aria-sort",0===r?"none":1===r?"ascending":"descending"),n.addEventListener("click",o=>{e._resizeController?.isResizing||e._dispatchHeaderClick?.(o,t,n)||Xe(e,t)}),n.addEventListener("keydown",o=>{if("Enter"===o.key||" "===o.key){if(o.preventDefault(),e._dispatchHeaderClick?.(o,t,n))return;Xe(e,t)}})}function ot(e){e._headerRowEl=e.findHeaderRow();const t=e._headerRowEl;t&&(t.innerHTML="",e._visibleColumns.forEach((o,n)=>{const r=document.createElement("div");r.className="cell",Le(r,"header-cell"),r.setAttribute("role","columnheader"),r.setAttribute("aria-colindex",String(n+1)),r.setAttribute("data-field",o.field),r.setAttribute("data-col",String(n)),o.type&&r.setAttribute("data-type",o.type);const i=o.header??o.field,s=e._sortState?.field===o.field?e._sortState.direction:0,l=1===s?"asc":-1===s?"desc":null;if(o.headerRenderer){const t={column:o,value:i,sortState:l,filterActive:!1,cellEl:r,renderSortIcon:()=>Ze(e,o)?Je(e,o):null,renderFilterButton:()=>null},s=o.headerRenderer(t);!function(e,t){if(null!=t)if("string"==typeof t){const o=document.createElement("span");for(o.innerHTML=z(t);o.firstChild;)e.appendChild(o.firstChild)}else t instanceof Node&&e.appendChild(t)}(r,s),Ze(e,o)&&tt(e,o,0,r),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)))}else if(o.headerLabelRenderer){const t={column:o,value:i},s=o.headerLabelRenderer(t),l=document.createElement("span");null==s?l.textContent=i:"string"==typeof s?l.innerHTML=z(s):s instanceof Node&&l.appendChild(s),r.appendChild(l),Ze(e,o)&&(tt(e,o,0,r),r.appendChild(Je(e,o))),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)))}else if(o.__headerTemplate)Array.from(o.__headerTemplate.childNodes).forEach(e=>r.appendChild(e.cloneNode(!0))),Ze(e,o)&&(tt(e,o,0,r),r.appendChild(Je(e,o))),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)));else{const t=document.createElement("span");t.textContent=i,r.appendChild(t),Ze(e,o)&&(tt(e,o,0,r),r.appendChild(Je(e,o))),Qe(e,o)&&(r.classList.add("resizable"),r.appendChild(et(e,n,r)))}t.appendChild(r)}),t.querySelectorAll(`.cell.${X.SORTABLE}`).forEach(e=>{e.getAttribute("aria-sort")||e.setAttribute("aria-sort","none")}),t.children.length>0?(t.setAttribute("role","row"),t.setAttribute("aria-rowindex","1")):(t.removeAttribute("role"),t.removeAttribute("aria-rowindex")))}function nt(e,t){const o=e[0]||{},n=Object.keys(o).map(e=>{const t=o[e],n=null==(r=t)?"string":"number"==typeof r?"number":"boolean"==typeof r?"boolean":r instanceof Date||"string"==typeof r&&/\d{4}-\d{2}-\d{2}/.test(r)&&!isNaN(Date.parse(r))?"date":"string";var r;return{field:e,header:e.charAt(0).toUpperCase()+e.slice(1),type:n}}),r={};return n.forEach(e=>{r[e.field]=e.type||"string"}),{columns:n,typeMap:r}}const rt={STYLE:1,VIRTUALIZATION:2,HEADER:3,ROWS:4,COLUMNS:5,FULL:6};class it{#m;#b=0;#v=0;#C=null;#y=null;#_=null;#S=!1;constructor(e){this.#m=e}requestPhase(e,t){e>this.#b&&(this.#b=e),0===this.#v&&(this.#R(),this.#v=requestAnimationFrame(()=>this.#E()))}whenReady(){return this.#C?this.#C:Promise.resolve()}setInitialReadyResolver(e){this.#_=e}cancel(){0!==this.#v&&(cancelAnimationFrame(this.#v),this.#v=0),this.#b=0,this.#y&&(this.#y(),this.#y=null,this.#C=null)}get isPending(){return 0!==this.#b}get pendingPhase(){return this.#b}#R(){this.#C||(this.#C=new Promise(e=>{this.#y=e}))}#E(){if(this.#v=0,!this.#m._schedulerIsConnected)return this.#b=0,void(this.#y&&(this.#y(),this.#y=null,this.#C=null));const e=this.#b;this.#b=0,e>=rt.COLUMNS&&this.#m._schedulerMergeConfig(),e>=rt.ROWS&&this.#m._schedulerProcessRows(),e>=rt.COLUMNS&&(this.#m._schedulerProcessColumns(),this.#m._schedulerUpdateTemplate()),e>=rt.HEADER&&this.#m._schedulerRenderHeader(),e>=rt.VIRTUALIZATION&&this.#m.refreshVirtualWindow(!0,!0),e>=rt.STYLE&&this.#m._schedulerAfterRender();const t=!this.#S;t&&(this.#S=!0,this.#_?.()),this.#y&&(this.#y(),this.#y=null,this.#C=null),0!==e&&this.#P(e,t)}#P(e,t){const o=this.#m._virtualization,n=o?.enabled?{start:o.start,end:o.end}:null,r={phase:e,initial:t,rowCount:this.#m._rows?.length??0,visibleRange:n};this.#m._hostElement.dispatchEvent(new CustomEvent("render",{detail:r,bubbles:!0,composed:!0}))}}class st{#x;#A;#T;#H;#M;#L={};#k={};#O=!0;#D=[];#I;#z;#N;#q;#m;constructor(e){this.#m=e}get original(){return this.#L}get effective(){return this.#k}get columns(){return this.#k.columns??[]}set columns(e){this.#k.columns=e}get lightDomColumnsCache(){return this.#H}set lightDomColumnsCache(e){this.#H=e}get originalColumnNodes(){return this.#M}set originalColumnNodes(e){this.#M=e}get initialColumnState(){return this.#q}set initialColumnState(e){this.#q=e}get sourcesChanged(){return this.#O}markSourcesChanged(){this.#O=!0}setGridConfig(e){this.#x!==e&&(this.#x=e,this.#O=!0,this.#H=void 0)}getGridConfig(){return this.#x}setColumns(e){this.#A=e,this.#O=!0}getColumns(){return this.#A}setFitMode(e){this.#T=e,this.#O=!0}getFitMode(){return this.#T}merge(){const e=(this.#k.columns?.length??0)>0;if(!this.#O&&e)return;const t=this.#F();this.#O=!1,this.#L=t,Object.freeze(this.#L),this.#L.columns&&Object.freeze(this.#L.columns),this.#k=this.#$(this.#L),this.#W()}#$(e){const t={...e};return e.columns&&(t.columns=e.columns.map(e=>({...e}))),e.shell&&(t.shell={...e.shell,header:e.shell.header?{...e.shell.header}:void 0,toolPanel:e.shell.toolPanel?{...e.shell.toolPanel}:void 0,toolPanels:e.shell.toolPanels?.map(e=>({...e})),headerContents:e.shell.headerContents?.map(e=>({...e}))}),t}#W(){const e=this.#k;if(this.#B(),"number"==typeof e.rowHeight&&e.rowHeight>0&&(this.#m._virtualization.rowHeight=e.rowHeight),"fixed"===e.fitMode){this.columns.forEach(e=>{null==e.width&&(e.width=80)})}this.#m._applyAnimationConfig(e)}#B(){const e=this.#k.typeDefaults;if(!e)return;const t=this.columns;for(const o of t){if(!o.type)continue;const t=e[o.type];t&&(o.renderer||o.viewRenderer||!t.renderer||(o.renderer=t.renderer),!o.format&&t.format&&(o.format=t.format),!o.editor&&t.editor&&(o.editor=t.editor),!o.editorParams&&t.editorParams&&(o.editorParams=t.editorParams))}}#F(){const e=this.#x?{...this.#x}:{},t=Array.isArray(e.columns)?[...e.columns]:[],o=(this.#H??[]).map(e=>({...e}));let n=Me(t,o);this.#A&&this.#A.length&&(n=Me(this.#A,o));const r=this.#m.sourceRows;if(0===n.length&&r.length){n=nt(r).columns}return n.length&&(n.forEach(e=>{void 0===e.sortable&&(e.sortable=!0),void 0===e.resizable&&(e.resizable=!0),void 0===e.__originalWidth&&"number"==typeof e.width&&(e.__originalWidth=e.width)}),n.forEach(e=>{e.__viewTemplate&&!e.__compiledView&&(e.__compiledView=W(e.__viewTemplate.innerHTML)),e.__editorTemplate&&!e.__compiledEditor&&(e.__compiledEditor=W(e.__editorTemplate.innerHTML))}),e.columns=n),this.#T&&(e.fitMode=this.#T),e.fitMode||(e.fitMode="stretch"),this.#m._pluginManager?.processConfig?.(e),e.columnState&&!this.#q&&(this.#q=e.columnState),e}collectState(e){const t=this.columns,o=this.#V();return{columns:t.map((t,n)=>{const r={field:t.field,order:n,visible:!t.hidden},i=t;void 0!==i.__renderedWidth?r.width=i.__renderedWidth:void 0!==t.width&&(r.width="string"==typeof t.width?parseFloat(t.width):t.width);const s=o.get(t.field);s&&(r.sort=s);for(const o of e)if(o.getColumnState){const e=o.getColumnState(t.field);e&&Object.assign(r,e)}return r})}}applyState(e,t){if(!e.columns||0===e.columns.length)return;const o=this.columns,n=new Map(e.columns.map(e=>[e.field,e])),r=o.map(e=>{const t=n.get(e.field);if(!t)return e;const o={...e};return void 0!==t.width&&(o.width=t.width,o.__renderedWidth=t.width),void 0!==t.visible&&(o.hidden=!t.visible),o});r.sort((e,t)=>(n.get(e.field)?.order??1/0)-(n.get(t.field)?.order??1/0)),this.columns=r;const i=e.columns.filter(e=>void 0!==e.sort).sort((e,t)=>(e.sort?.priority??0)-(t.sort?.priority??0));if(i.length>0){const e=i[0];e.sort&&(this.#m._sortState={field:e.field,direction:"asc"===e.sort.direction?1:-1})}else this.#m._sortState=null;for(const s of t)if(s.applyColumnState)for(const t of e.columns)s.applyColumnState(t.field,t)}resetState(e){this.#q=void 0,this.#m._sortState=null,this.#k=this.#$(this.#L),this.#W();for(const t of e)if(t.applyColumnState)for(const e of this.columns)t.applyColumnState(e.field,{field:e.field,order:0,visible:!0});this.requestStateChange(e)}#V(){const e=/* @__PURE__ */new Map,t=this.#m._sortState;return t&&e.set(t.field,{direction:1===t.direction?"asc":"desc",priority:0}),e}requestStateChange(e){this.#z&&clearTimeout(this.#z),this.#z=setTimeout(()=>{this.#z=void 0;const t=this.collectState(e);this.#m._emit("column-state-change",t)},100)}setColumnVisible(e,t){const o=this.columns,n=o.find(t=>t.field===e);if(!n)return!1;if(!t&&n.lockVisible)return!1;if(!t){if(0===o.filter(t=>!t.hidden&&t.field!==e).length)return!1}return!!n.hidden!=!t&&(n.hidden=!t,this.#m._emit("column-visibility",{field:e,visible:t,visibleColumns:o.filter(e=>!e.hidden).map(e=>e.field)}),this.#m._clearRowPool(),this.#m._setup(),!0)}toggleColumnVisibility(e){const t=this.columns.find(t=>t.field===e);return!!t&&this.setColumnVisible(e,!!t.hidden)}isColumnVisible(e){const t=this.columns.find(t=>t.field===e);return!!t&&!t.hidden}showAllColumns(){const e=this.columns;e.some(e=>e.hidden)&&(e.forEach(e=>e.hidden=!1),this.#m._emit("column-visibility",{visibleColumns:e.map(e=>e.field)}),this.#m._clearRowPool(),this.#m._setup())}getAllColumns(){return this.columns.map(e=>({field:e.field,header:e.header||e.field,visible:!e.hidden,lockVisible:e.lockVisible,utility:!0===e.utility}))}getColumnOrder(){return this.columns.map(e=>e.field)}setColumnOrder(e){if(!e.length)return;const t=new Map(this.columns.map(e=>[e.field,e])),o=[];for(const n of e){const e=t.get(n);e&&(o.push(e),t.delete(n))}for(const n of t.values())o.push(n);this.columns=o,this.#m._invalidateVisibleColumnsCache(),ot(this.#m),Ie(this.#m),this.#m._requestSchedulerPhase(rt.COLUMNS,"configManager")}parseLightDomColumns(e){this.#H||(this.#M=Array.from(e.querySelectorAll("tbw-grid-column")),this.#H=this.#M.length?function(e){return Array.from(e.querySelectorAll("tbw-grid-column")).map(e=>{const t=e.getAttribute("field")||"";if(!t)return null;const o={field:t,type:e.getAttribute("type")||void 0,header:e.getAttribute("header")||void 0,sortable:e.hasAttribute("sortable")&&"false"!==e.getAttribute("sortable"),__element:e},n=e.getAttribute("width");if(n){const e=parseFloat(n);!isNaN(e)&&/^\d+(\.\d+)?$/.test(n.trim())?o.width=e:o.width=n}const r=e.getAttribute("minWidth")||e.getAttribute("min-width");if(r){const e=parseFloat(r);isNaN(e)||(o.minWidth=e)}e.hasAttribute("resizable")&&(o.resizable="false"!==e.getAttribute("resizable"));const i=e.getAttribute("options");i&&(o.options=i.split(",").map(e=>{const[t,o]=e.includes(":")?e.split(":"):[e.trim(),e.trim()];return{value:t.trim(),label:o?.trim()||t.trim()}}));const s=e.querySelector("tbw-grid-column-view"),l=e.querySelector("tbw-grid-column-editor"),a=e.querySelector("tbw-grid-column-header");s&&(o.__viewTemplate=s),a&&(o.__headerTemplate=a);const c=globalThis.DataGridElement,d=c?.getAdapters?.()??[],h=s??e,u=d.find(e=>e.canHandle(h));if(u){const e=u.createRenderer(h);e&&(o.viewRenderer=e)}const g=l??e,f=d.find(e=>e.canHandle(g));if(f){const e=f.createEditor(g);e&&(o.editor=e)}const p=d.find(t=>t.canHandle(e)&&(t.createHeaderRenderer||t.createHeaderLabelRenderer));if(p){const t=p.createHeaderRenderer?.(e);t&&(o.headerRenderer=t);const n=p.createHeaderLabelRenderer?.(e);n&&(o.headerLabelRenderer=n)}return o}).filter(e=>!!e)}(e):[])}clearLightDomCache(){this.#H=void 0}#U=/* @__PURE__ */new Map;registerLightDomHandler(e,t){this.#U.set(e.toLowerCase(),t)}unregisterLightDomHandler(e){this.#U.delete(e.toLowerCase())}observeLightDOM(e){this.#I&&this.#I.disconnect();const t=/* @__PURE__ */new Set,o=()=>{this.#N=void 0;for(const e of t){const t=this.#U.get(e);t?.()}t.clear()};this.#I=new MutationObserver(e=>{for(const o of e){for(const e of o.addedNodes){if(e.nodeType!==Node.ELEMENT_NODE)continue;const o=e.tagName.toLowerCase();this.#U.has(o)&&t.add(o)}if("attributes"===o.type&&o.target.nodeType===Node.ELEMENT_NODE){const e=o.target.tagName.toLowerCase();this.#U.has(e)&&t.add(e)}}t.size>0&&!this.#N&&(this.#N=setTimeout(o,0))}),this.#I.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["title","field","header","width","hidden","id","icon","tooltip","order"]})}onChange(e){this.#D.push(e)}notifyChange(){for(const e of this.#D)e()}dispose(){this.#I?.disconnect(),this.#D=[],this.#z&&clearTimeout(this.#z),this.#N&&(clearTimeout(this.#N),this.#N=void 0)}}function lt(e){const t=document.createElement("div");return t.className="tbw-empty-message",t.textContent=e.filteredOut?"No matching rows":"No data to display",t}function at(e,t,o="rows"){const n=document.createElement("div");return n.className="tbw-empty-overlay",n.setAttribute("role","status"),n.setAttribute("aria-live","polite"),n.setAttribute("data-overlay-target",o),n.appendChild(function(e,t){const o=(t??lt)(e);if("string"==typeof o){const e=document.createElement("div");return e.className="tbw-empty-message",e.innerHTML=z(o),e}return o}(e,t)),n}function ct(e){e?.remove()}function dt(){if("undefined"!=typeof window&&window.location){const e=window.location.hostname;if("localhost"===e||"127.0.0.1"===e||"::1"===e)return!0}return"undefined"!=typeof process&&"production"!==process.env?.NODE_ENV}function ht(e){return`<span role="checkbox" aria-checked="${e}" aria-label="${e}">${e?"&#x1F5F9;":"&#9744;"}</span>`}function ut(e){if(null==e||""===e)return"";if(e instanceof Date)return isNaN(e.getTime())?"":e.toLocaleDateString();if("number"==typeof e||"string"==typeof e){const t=new Date(e);return isNaN(t.getTime())?"":t.toLocaleDateString()}return""}function gt(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const o=e.closest(".data-grid-row");if(!o)return-1;const n=o.parentElement;if(!n)return-1;const r=n.querySelectorAll(":scope > .data-grid-row");for(let i=0;i<r.length;i++)if(r[i]===o)return i;return-1}function ft(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function pt(e){try{if("rtl"===getComputedStyle(e).direction)return"rtl"}catch{}try{const t=e.closest?.("[dir]")?.getAttribute("dir");if("rtl"===t)return"rtl"}catch{}return"ltr"}function wt(e){return"rtl"===pt(e)}function mt(e,t){return"left"===e||"right"===e?e:"rtl"===t?"start"===e?"right":"left":"start"===e?"left":"right"}function bt(e,t){const o=t.renderer||t.viewRenderer;if(o)return o;if(!t.type)return;const n=e.__frameworkAdapter;if(n?.getTypeDefault){const o=n.getTypeDefault(t.type,e._hostElement);if(o?.renderer)return o.renderer}}function vt(e,t){if(t.format)return t.format;if(!t.type)return;const o=e.__frameworkAdapter;if(o?.getTypeDefault){const n=o.getTypeDefault(t.type,e._hostElement);if(n?.format)return n.format}}const Ct='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function yt(e){return(e.__editingCellCount??0)>0}function _t(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing");e.querySelectorAll(`.cell.${X.EDITING}`).forEach(e=>e.classList.remove(X.EDITING))}const St=document.createElement("template");St.innerHTML='<div class="cell" role="gridcell" part="cell"></div>';const Rt=document.createElement("template");function Et(){return St.content.firstElementChild.cloneNode(!0)}function Pt(){return Rt.content.firstElementChild.cloneNode(!0)}function xt(e){e.__cellDisplayCache=void 0,e.__cellCacheEpoch=void 0,e.__hasSpecialColumns=void 0}function At(e,t,o,i){const s=t.children,l=e._visibleColumns,a=l.length,c=s.length,d=a<c?a:c,h=e._focusRow,u=e._focusCol,g=e._hasAfterCellRenderHook?.()??!1;let f=e.__hasSpecialColumns;if(void 0===f){f=!1;const t=e.__frameworkAdapter;for(let o=0;o<a;o++){const n=l[o];if(n.__viewTemplate||n.__compiledView||n.renderer||n.viewRenderer||n.externalView||n.format||n.cellClass||"date"===n.type||"boolean"===n.type||n.type&&t?.getTypeDefault?.(n.type,e._hostElement)?.renderer||n.type&&t?.getTypeDefault?.(n.type,e._hostElement)?.format){f=!0;break}}e.__hasSpecialColumns=f}const p=String(i);if(f){for(let n=0;n<d;n++){if(l[n].externalView){if(!s[n].querySelector("[data-external-view]"))return void Tt(e,t,o,i)}}for(let a=0;a<d;a++){const c=l[a],d=s[a];d.getAttribute("data-row")!==p&&d.setAttribute("data-row",p);const f=d.classList.contains(X.EDITING);if(!f){const e=h===i&&u===a;e!==d.classList.contains("cell-focus")&&(d.classList.toggle("cell-focus",e),d.setAttribute("aria-selected",String(e)))}const m=c.cellClass;if(m){const t=d.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&d.classList.remove(e[t])}try{const e=m(Ne(o,c,i),o,c),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let o=0;o<t.length;o++){const n=t[o];n&&"string"==typeof n&&(d.classList.add(n),e+=(e?" ":"")+n)}d.setAttribute("data-dynamic-classes",e)}else d.removeAttribute("data-dynamic-classes")}catch(w){E(n,`cellClass callback error for column '${c.field}': ${w}`,e.id),d.removeAttribute("data-dynamic-classes")}}if(f)continue;const b=bt(e,c);if(b){const n=Ne(o,c,i),r=b({row:o,value:n,field:c.field,column:c,grid:e,cellEl:d});"string"==typeof r?(e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML=z(r)):r instanceof Node?r.parentElement!==d&&(e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML="",d.appendChild(r)):null==r&&(e.__frameworkAdapter?.releaseCell?.(d),d.textContent=null==n?"":String(n)),g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:n,cellElement:d,rowElement:t});continue}if(c.__compiledView){const n=Ne(o,c,i),r=c.__compiledView({row:o,value:n,field:c.field,column:c});c.__compiledView.__blocked?d.textContent="":(d.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML=z(r),$(d)),g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:n,cellElement:d,rowElement:t});continue}if(c.__viewTemplate){const n=Ne(o,c,i),r=c.__viewTemplate.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(r)?d.textContent="":(d.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(d),d.innerHTML=z(q(r,{row:o,value:n})),$(d)),g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:n,cellElement:d,rowElement:t});continue}if(c.externalView)continue;const v=Ne(o,c,i);let C;d.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(d);const y=vt(e,c);if(y){try{const e=y(v,o);C=null==e?"":String(e)}catch(w){E(r,`Format error in column '${c.field}': ${w}`,e.id),C=null==v?"":String(v)}d.textContent=C}else"date"===c.type?(C=ut(v),d.textContent=C):"boolean"===c.type?d.innerHTML=ht(!!v):(C=null==v?"":String(v),d.textContent=C);g&&e._afterCellRender?.({row:o,rowIndex:i,column:c,colIndex:a,value:v,cellElement:d,rowElement:t})}}else for(let n=0;n<d;n++){const r=s[n];if(r.classList.contains(X.EDITING))continue;r.firstElementChild&&e.__frameworkAdapter?.releaseCell?.(r);const a=l[n],c=Ne(o,a,i);r.textContent=null==c?"":String(c),r.getAttribute("data-row")!==p&&r.setAttribute("data-row",p);const d=h===i&&u===n;d!==r.classList.contains("cell-focus")&&(r.classList.toggle("cell-focus",d),r.setAttribute("aria-selected",String(d))),g&&e._afterCellRender?.({row:o,rowIndex:i,column:a,colIndex:n,value:c,cellElement:r,rowElement:t})}}function Tt(e,t,o,i){t.classList.remove("tbw-row-loading"),t.removeAttribute("aria-busy");const s=e.__frameworkAdapter;if(s?.releaseCell){s.beginBatch?.(e);try{const e=t.children;for(let t=e.length-1;t>=0;t--)s.releaseCell(e[t]);t.innerHTML=""}finally{s.endBatch?.(e)}}else t.innerHTML="";const l=e._visibleColumns,a=l.length,c=e._focusRow,d=e._focusCol,h=e._hasAfterCellRenderHook?.()??!1,u=document.createDocumentFragment();for(let f=0;f<a;f++){const s=l[f],a=Et();a.setAttribute("aria-colindex",String(f+1)),a.setAttribute("data-col",String(f)),a.setAttribute("data-row",String(i)),a.setAttribute("data-field",s.field),a.setAttribute("data-header",s.header??s.field),s.type&&a.setAttribute("data-type",s.type);let p=Ne(o,s,i);const w=vt(e,s);if(w)try{p=w(p,o)}catch(g){E(r,`Format error in column '${s.field}': ${g}`,e.id)}const m=s.__compiledView,b=s.__viewTemplate,v=bt(e,s),C=s.externalView;let y=!1;if(v){const t=v({row:o,value:p,field:s.field,column:s,grid:e,cellEl:a});"string"==typeof t?(a.innerHTML=z(t),y=!0):t instanceof Node?t.parentElement!==a&&(a.textContent="",a.appendChild(t)):null==t&&(a.textContent=null==p?"":String(p))}else if(C){const t=C,n=document.createElement("div");n.setAttribute("data-external-view",""),n.setAttribute("data-field",s.field),a.appendChild(n);const r={row:o,value:p,field:s.field,column:s,grid:e};if(t.mount)try{t.mount({placeholder:n,context:r,spec:t})}catch(g){E("TBW063",`External view mount error for column '${s.field}': ${g}`,e.id)}else queueMicrotask(()=>{try{e.dispatchEvent(new CustomEvent("mount-external-view",{bubbles:!0,composed:!0,detail:{placeholder:n,spec:t,context:r}}))}catch(g){E("TBW064",`External view event dispatch error for column '${s.field}': ${g}`,e.id)}});n.setAttribute("data-mounted","")}else if(m){const e=m({row:o,value:p,field:s.field,column:s}),t=m.__blocked;a.innerHTML=t?"":z(e),y=!0,t&&(a.textContent="",a.setAttribute("data-blocked-template",""))}else if(b){const e=b.innerHTML;/Reflect\.|\bProxy\b|ownKeys\(/.test(e)?(a.textContent="",a.setAttribute("data-blocked-template","")):(a.innerHTML=z(q(e,{row:o,value:p})),y=!0)}else w?a.textContent=null==p?"":String(p):"date"===s.type?a.textContent=ut(p):"boolean"===s.type?a.innerHTML=ht(!!p):a.textContent=null==p?"":String(p);if(y){$(a);const e=a.textContent||"";/Proxy|Reflect\.ownKeys/.test(e)&&(a.textContent=e.replace(/Proxy|Reflect\.ownKeys/g,"").trim(),/Proxy|Reflect\.ownKeys/.test(a.textContent||"")&&(a.textContent=""))}a.hasAttribute("data-blocked-template")&&(a.textContent||"").trim().length&&(a.textContent="");("function"==typeof s.editable?s.editable(o):s.editable)?a.tabIndex=0:"boolean"===s.type&&(a.hasAttribute("tabindex")||(a.tabIndex=0)),c===i&&d===f?(a.classList.add("cell-focus"),a.setAttribute("aria-selected","true")):a.setAttribute("aria-selected","false");const _=s.cellClass;if(_)try{const e=_(Ne(o,s,i),o,s),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(const o of t)o&&"string"==typeof o&&(a.classList.add(o),e+=(e?" ":"")+o);a.setAttribute("data-dynamic-classes",e)}}catch(g){E(n,`cellClass callback error for column '${s.field}': ${g}`,e.id)}h&&e._afterCellRender?.({row:o,rowIndex:i,column:s,colIndex:f,value:p,cellElement:a,rowElement:t}),u.appendChild(a)}t.appendChild(u)}function Ht(e,t,o){if(t.target?.closest(".resize-handle"))return;const n=gt(o.querySelector(".cell[data-row]"));if(n<0)return;const r=e._rows[n];if(!r)return;if(e._dispatchRowClick?.(t,n,r,o))return;const i=t.target?.closest(".cell[data-col]");if(i){const o=Number(i.getAttribute("data-col"));if(!isNaN(o)){if(e._dispatchCellClick?.(t,n,o,i))return;const r=e._focusRow!==n||e._focusCol!==o;if(e._focusRow=n,e._focusCol=o,i.classList.contains(X.EDITING)){r&&(ft(e._bodyEl??e),i.classList.add("cell-focus"));const o=t.target,n=i.contains(o)&&o.matches(Ct)?o:i.querySelector(Ct);try{n?.focus({preventScroll:!0})}catch{}return}Vt(e)}}}function Mt(e,t){return e&&"object"==typeof e?"__rowCacheKey"in e?e.__rowCacheKey:"rowId"in e&&null!=e.rowId?`id:${e.rowId}`:t?`id:${t(e)}`:e:e}function Lt(e,t,o){const n=Mt(t,o);return"string"==typeof n?e.byKey.get(n):n&&"object"==typeof n?e.byRef.get(n):void 0}function kt(e,t,o){if(t<0||t>=e.length)return;const n=e[t],r=o-n.height;if(0!==r){n.height=o,n.measured=!0;for(let o=t+1;o<e.length;o++)e[o].offset+=r}}function Ot(e,t){if(0===e.length)return-1;if(t<=0)return 0;let o=0,n=e.length-1;for(;o<=n;){const r=Math.floor((o+n)/2),i=e[r],s=i.offset+i.height;if(t<i.offset)n=r-1;else{if(!(t>=s))return r;o=r+1}}return Math.max(0,Math.min(o,e.length-1))}function Dt(e,t){const{positionCache:o,heightCache:n,rows:r,start:i,end:s,getPluginHeight:l,getRowId:a}=e;let c=!1;t.forEach(e=>{const t=e.dataset.rowIndex;if(!t)return;const d=parseInt(t,10);if(d<i||d>=s||d>=r.length)return;const h=r[d],u=l?.(h,d);if(void 0!==u){const e=o[d];return void((!e.measured||Math.abs(e.height-u)>1)&&(kt(o,d,u),c=!0))}const g=e.offsetHeight;if(g>0){const e=o[d];(!e.measured||Math.abs(e.height-g)>1)&&(kt(o,d,g),function(e,t,o,n){const r=Mt(t,n);"string"==typeof r?e.byKey.set(r,o):r&&"object"==typeof r&&e.byRef.set(r,o)}(n,h,g,a),c=!0)}});const d=c?function(e){let t=0;for(const o of e)o.measured&&t++;return t}(o):0,h=c?function(e,t){let o=0,n=0;for(const r of e)r.measured&&(o+=r.height,n++);return n>0?o/n:t}(o,e.defaultHeight):0;return{hasChanges:c,measuredCount:d,averageHeight:h}}Rt.innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const It=335e5;function zt(e,t,o=It){return{rawContentHeight:e,spacerHeight:Math.min(e,o),viewportHeight:t,capped:e>o}}function Nt(e,t){if(!t.capped)return e;const o=t.spacerHeight-t.viewportHeight,n=t.rawContentHeight-t.viewportHeight;if(o<=0||n<=0)return e;const r=e*n/o;return r<0?0:r>n?n:r}function qt(e,t){if(!t.capped)return e;const o=t.spacerHeight-t.viewportHeight,n=t.rawContentHeight-t.viewportHeight;return o<=0||n<=0?e:e*o/n}function Ft(e){const{totalRows:t,viewportHeight:o,scrollTop:n,rowHeight:r,overscan:i,maxSpacerHeight:s=It}=e,l=Math.ceil(o/r),a=t*r,c=zt(a,o,s),d=Nt(n,c);let h=Math.floor(d/r)-i;h<0&&(h=0);let u=h+l+2*i;return u>t&&(u=t),u===t&&h>0&&(h=Math.max(0,u-l-2*i)),{start:h,end:u,offsetY:h*r,totalHeight:c.spacerHeight,rawContentHeight:a}}function $t(e,t){return e<=t}function Wt(e){"function"==typeof e.commitActiveRowEdit&&e.commitActiveRowEdit()}function Bt(e){if(!e)return!1;const t=e.tagName;return"INPUT"===t||"SELECT"===t||"TEXTAREA"===t||!!e.isContentEditable}function Vt(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:o,viewportEl:n,scrollMapping:r}=e._virtualization,i=o,s=n?.clientHeight??i?.clientHeight??0;if(i&&s>0){const o=e._focusRow*t,n=r?Nt(i.scrollTop,r):i.scrollTop;if(o<n)i.scrollTop=r?qt(o,r):o;else if(o+t>n+s){const e=o-s+t;i.scrollTop=r?qt(e,r):e}}}const o=void 0!==e._activeEditRows&&-1!==e._activeEditRows||!!e._isGridEditMode;o||e.refreshVirtualWindow(!1),ft(e._bodyEl),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const n=e._focusRow,r=e._virtualization.start??0,i=e._virtualization.end??e._rows.length;if(n>=r&&n<i){const i=e._bodyEl.querySelectorAll(".data-grid-row")[n-r];let s=i?.children[e._focusCol];if(s&&s.classList?.contains("cell")||(s=i?.querySelector(`.cell[data-col="${e._focusCol}"]`)??i?.querySelector(".cell[data-col]")),s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const n=e.querySelector(".tbw-scroll-area");if(n&&s&&(!o||t?.forceHorizontalScroll))if(t?.forceScrollLeft)n.scrollLeft=0;else if(t?.forceScrollRight)n.scrollLeft=n.scrollWidth-n.clientWidth;else{const t=e._getHorizontalScrollOffsets?.(i??void 0,s)??{left:0,right:0};if(!t.skipScroll){const e=s.getBoundingClientRect(),o=n.getBoundingClientRect(),r=e.left-o.left+n.scrollLeft,i=r+e.width,l=n.scrollLeft+t.left,a=n.scrollLeft+n.clientWidth-t.right;r<l?n.scrollLeft=r-t.left:i>a&&(n.scrollLeft=i-n.clientWidth+t.right)}}if(o&&s.classList.contains(X.EDITING)){const e=s.querySelector(Ct);if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(o&&!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}else if(!o){const t=document.activeElement;t instanceof HTMLElement&&t!==e&&"function"==typeof e.contains&&e.contains(t)&&!t.classList.contains("cell")&&!t.closest(".cell")||t===e||e.focus({preventScroll:!0})}}}}const Ut=/* @__PURE__ */new WeakMap;function Gt(e,t){const o=gt(t),n=function(e){if(!e)return-1;const t=e.getAttribute("data-col");return t?parseInt(t,10):-1}(t);if(o<0||n<0)return;e._focusRow=o,e._focusCol=n,ft(e._bodyEl),t.classList.add("cell-focus"),t.setAttribute("aria-selected","true");const r=t.closest("tbw-grid, [data-tbw-grid]");r&&document.activeElement!==r&&r.focus({preventScroll:!0})}function jt(e,t,o,n){let r=null;const i=o.composedPath?.();if(r=i&&i.length>0?i[0]:o.target,r&&!t.contains(r)){const e=document.elementFromPoint(o.clientX,o.clientY);e&&(r=e)}const s=r?.closest?.("[data-col]"),l=r?.closest?.(".data-grid-row"),a=r?.closest?.(".header-row");let c,d,h,u,g,f;return s&&(c=parseInt(s.getAttribute("data-row")??"-1",10),d=parseInt(s.getAttribute("data-col")??"-1",10),c>=0&&d>=0&&(h=e._rows[c],f=e._visibleColumns[d],u=f?.field,g=h&&u?h[u]:void 0)),{type:n,row:h,rowIndex:void 0!==c&&c>=0?c:void 0,colIndex:void 0!==d&&d>=0?d:void 0,field:u,value:g,column:f,originalEvent:o,cellElement:s??void 0,rowElement:l??void 0,isHeader:!!a,cell:void 0!==c&&void 0!==d&&c>=0&&d>=0?{row:c,col:d}:void 0}}function Yt(e,t,o,n){t.addEventListener("keydown",t=>function(e,t){if(e._dispatchKeyDown?.(t))return;const o=e._rows.length-1,n=e._visibleColumns.length-1,r=void 0!==e._activeEditRows&&-1!==e._activeEditRows,i=e._visibleColumns[e._focusCol],s=i?.type,l=t.composedPath?.()??[],a=l.length?l[0]:t.target;if((!a||a===e||a.closest?.(".rows-body"))&&(!Bt(a)||"Home"!==t.key&&"End"!==t.key)&&!(Bt(a)&&("ArrowUp"===t.key||"ArrowDown"===t.key)&&"INPUT"===a.tagName&&"number"===a.type||Bt(a)&&("ArrowLeft"===t.key||"ArrowRight"===t.key)||Bt(a)&&("Enter"===t.key||"Escape"===t.key)||r&&"select"===s&&("ArrowDown"===t.key||"ArrowUp"===t.key))){switch(t.key){case"Tab":return t.preventDefault(),t.shiftKey?e._focusCol>0?e._focusCol-=1:e._focusRow>0&&(e._activeEditRows===e._focusRow&&Wt(e),e._focusRow-=1,e._focusCol=n):e._focusCol<n?e._focusCol+=1:(Wt(e),e._focusRow<o&&(e._focusRow+=1,e._focusCol=0)),void Vt(e);case"ArrowDown":r&&Wt(e),e._focusRow=Math.min(o,e._focusRow+1),t.preventDefault();break;case"ArrowUp":r&&Wt(e),e._focusRow=Math.max(0,e._focusRow-1),t.preventDefault();break;case"ArrowRight":{const o=wt(e);e._focusCol=o?Math.max(0,e._focusCol-1):Math.min(n,e._focusCol+1),t.preventDefault();break}case"ArrowLeft":{const o=wt(e);e._focusCol=o?Math.min(n,e._focusCol+1):Math.max(0,e._focusCol-1),t.preventDefault();break}case"Home":return t.ctrlKey||t.metaKey?(r&&Wt(e),e._focusRow=0,e._focusCol=0):e._focusCol=0,t.preventDefault(),void Vt(e,{forceScrollLeft:!0});case"End":return t.ctrlKey||t.metaKey?(r&&Wt(e),e._focusRow=o,e._focusCol=n):e._focusCol=n,t.preventDefault(),void Vt(e,{forceScrollRight:!0});case"PageDown":e._focusRow=Math.min(o,e._focusRow+20),t.preventDefault();break;case"PageUp":e._focusRow=Math.max(0,e._focusRow-20),t.preventDefault();break;case"Enter":{const o=e._focusRow,n=e._focusCol,r=e._visibleColumns[n],i=e._rows[o],s=r?.field??"",l=s&&i?i[s]:void 0,a=e.querySelector(`[data-row="${o}"][data-col="${n}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,detail:{rowIndex:o,colIndex:n,column:r,field:s,value:l,row:i,cellEl:a,trigger:"keyboard",originalEvent:t}});if(e.dispatchEvent(c),c.defaultPrevented)return void t.preventDefault();break}default:return}Vt(e)}}(e,t),{signal:n}),o.addEventListener("mousedown",t=>function(e,t,o){const n=jt(e,t,o,"mousedown");e._dispatchCellMouseDown?.(n)&&Ut.set(e,!0)}(e,o,t),{signal:n}),document.addEventListener("mousemove",t=>function(e,t,o){if(!Ut.get(e))return;const n=jt(e,t,o,"mousemove");e._dispatchCellMouseMove?.(n)}(e,o,t),{signal:n}),document.addEventListener("mouseup",t=>function(e,t,o){if(!Ut.get(e))return;const n=jt(e,t,o,"mouseup");e._dispatchCellMouseUp?.(n),Ut.set(e,!1)}(e,o,t),{signal:n})}let Xt;function Kt(e){Xt=e}class Zt{#m;#G=/* @__PURE__ */new Set;#j=/* @__PURE__ */new Map;#Y=null;#X=null;constructor(e){this.#m=e,this.#K()}focusCell(e,t){const o=this.#m,n=o._rows.length-1;if(n<0)return;let r;if("string"==typeof t){if(r=o._visibleColumns.findIndex(e=>e.field===t),r<0)return}else r=t;const i=o._visibleColumns.length-1;i<0||(o._focusRow=Math.max(0,Math.min(e,n)),o._focusCol=Math.max(0,Math.min(r,i)),Vt(o))}get focusedCell(){const e=this.#m;if(0===e._rows.length||0===e._visibleColumns.length)return null;const t=e._visibleColumns[e._focusCol];return{rowIndex:e._focusRow,colIndex:e._focusCol,field:t?.field??""}}scrollToRow(e,t){const o=this.#m._virtualization;if(!o.enabled)return;const n=o.container;if(!n)return;const r=this.#m._rows.length;if(0===r)return;const i=Math.max(0,Math.min(e,r-1)),s=t?.align??"nearest",l=t?.behavior??"instant";let a,c;const d=o.positionCache;o.variableHeights&&d&&d.length>i?(a=d[i].offset,c=d[i].height):(a=i*o.rowHeight,c=o.rowHeight);const h=o.viewportEl?.clientHeight??n.clientHeight??0;if(h<=0)return;const u=n.scrollTop,g=a+c,f=u+h;let p;switch(s){case"start":p=a;break;case"center":p=a-h/2+c/2;break;case"end":p=g-h;break;default:if(a>=u&&g<=f)return;p=a<u?a:g-h}p=Math.max(0,p);const w=qt(p,o.scrollMapping);"smooth"===l?n.scrollTo({top:w,behavior:"smooth"}):n.scrollTop=w}scrollToRowById(e,t){const o=this.#m._getRowEntry(e);o&&this.scrollToRow(o.index,t)}registerExternalFocusContainer(e){if(this.#G.has(e))return;this.#G.add(e);const t=new AbortController,o=t.signal,n=this.#m;e.addEventListener("focusin",e=>{n.dataset.hasFocus="",this.#Z(e.target)},{signal:o}),e.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&this.containsFocus(t)||delete n.dataset.hasFocus,null===t&&this.#Q()},{signal:o}),this.#j.set(e,()=>t.abort())}unregisterExternalFocusContainer(e){this.#G.delete(e);const t=this.#j.get(e);t&&(t(),this.#j.delete(e))}containsFocus(e){const t=e??document.activeElement;return!!t&&(!!this.#m.contains(t)||this.isInExternalFocusContainer(t))}isInExternalFocusContainer(e){for(const t of this.#G)if(t.contains(e))return!0;return!1}#K(){const e=this.#m,t=new AbortController,o=t.signal;e.addEventListener("focusin",e=>this.#Z(e.target),{signal:o,capture:!0}),e.addEventListener("focusout",e=>{null===e.relatedTarget&&this.#Q()},{signal:o}),this.#X=()=>t.abort()}#Z(e){if(!(e instanceof HTMLElement))return;if(e===this.#m)return;const t=e.closest?.(".cell");t&&!t.classList.contains("editing")||this.isInExternalFocusContainer(e)||(this.#Y=e)}#Q(){queueMicrotask(()=>{if(!this.#m.isConnected)return;document.activeElement===document.body&&this.restoreLastFocus()})}restoreLastFocus(){const e=this.#Y;if(!e)return!1;if(!e.isConnected)return this.#Y=null,!1;if(e===document.activeElement)return!0;try{e.focus({preventScroll:!0})}catch{return!1}return document.activeElement===e}get lastFocusedElement(){return this.#Y?.isConnected?this.#Y:null}destroy(){for(const e of this.#j.values())e();this.#j.clear(),this.#G.clear(),this.#X?.(),this.#X=null,this.#Y=null}}const Qt="function"==typeof requestIdleCallback;function Jt(e){Qt?cancelIdleCallback(e):clearTimeout(e)}function eo(e,t){if(t){const o=t({size:e});if("string"==typeof o){const e=document.createElement("div");return e.innerHTML=o,e}return o}return function(e){const t=document.createElement("div");return t.className=`tbw-spinner tbw-spinner--${e}`,t.setAttribute("role","progressbar"),t.setAttribute("aria-label","Loading"),t}(e)}function to(e,t){if(t){if(e.classList.add("tbw-row-loading"),e.setAttribute("aria-busy","true"),!e.querySelector(".tbw-row-loading-overlay")){const t=document.createElement("div");t.className="tbw-row-loading-overlay",t.setAttribute("aria-hidden","true");const o=document.createElement("div");o.className="tbw-row-loading-spinner",t.appendChild(o),e.appendChild(t)}}else e.classList.remove("tbw-row-loading"),e.removeAttribute("aria-busy"),e.querySelector(".tbw-row-loading-overlay")?.remove()}function oo(e){let t=null,o=null,n=null,r=null;const i=n=>{if(!t)return;const r=n.clientX-t.startX,i=Math.max(40,t.startWidth+r),s=e._visibleColumns[t.colIndex];s.width=i,s.__userResized=!0,s.__renderedWidth=i,null==o&&(o=requestAnimationFrame(()=>{o=null,e.updateTemplate?.()})),e.dispatchEvent(new CustomEvent("column-resize",{detail:{field:s.field,width:i}}))};let s=!1;const l=()=>{const o=null!==t;o&&(s=!0,requestAnimationFrame(()=>{s=!1})),window.removeEventListener("mousemove",i),window.removeEventListener("mouseup",l),null!==n&&(document.documentElement.style.cursor=n,n=null),null!==r&&(document.body.style.userSelect=r,r=null),t=null,o&&e.requestStateChange&&e.requestStateChange()};return{get isResizing(){return null!==t||s},start(o,s,a){o.preventDefault();const c=e._headerRowEl??e.findHeaderRow?.();c&&function(t,o){const n=o.querySelectorAll(".cell");for(let r=0;r<e._visibleColumns.length;r++){if(r===t)continue;const o=e._visibleColumns[r];if(null==o.width&&!o.__userResized){const e=n[r],t=e?.getBoundingClientRect().width;t&&(o.width=Math.round(t),o.__userResized=!0,o.__renderedWidth=o.width)}}}(s,c);const d=e._visibleColumns[s],h="number"==typeof d?.width?d.width:void 0,u=d?.__renderedWidth??h??a.getBoundingClientRect().width;t={startX:o.clientX,colIndex:s,startWidth:u},window.addEventListener("mousemove",i),window.addEventListener("mouseup",l),null===n&&(n=document.documentElement.style.cursor),document.documentElement.style.cursor="e-resize",null===r&&(r=document.body.style.userSelect),document.body.style.userSelect="none"},resetColumn(t){const o=e._visibleColumns[t];o&&(o.__userResized=!1,o.__renderedWidth=void 0,o.width=o.__originalWidth,e.updateTemplate?.(),e.requestStateChange?.(),e.dispatchEvent(new CustomEvent("column-resize-reset",{detail:{field:o.field,width:o.width}})))},dispose(){l()}}}const no="data-animating",ro={change:"--tbw-row-change-duration",insert:"--tbw-row-insert-duration",remove:"--tbw-row-remove-duration"},io={change:500,insert:300,remove:200};function so(e,t){const o=ro[t],n=getComputedStyle(e).getPropertyValue(o);if(n){const e=function(e){const t=e.trim().toLowerCase();return t.endsWith("ms")?parseFloat(t):t.endsWith("s")?1e3*parseFloat(t):parseFloat(t)}(n);if(!isNaN(e)&&e>0)return e}return io[t]}function lo(e,t,o){if(t<0)return Promise.resolve(!1);const n=e.findRenderedRowElement?.(t);return n?new Promise(e=>{!function(e,t,o){e.removeAttribute(no),e.offsetWidth,e.setAttribute(no,t);const n=so(e,t);setTimeout(()=>{"remove"!==t&&e.removeAttribute(no),o?.()},n)}(n,o,()=>e(!0))}):Promise.resolve(!1)}function ao(e,t){if(t)return t(e);const o=e;return"id"in o&&null!=o.id?String(o.id):"_id"in o&&null!=o._id?String(o._id):void 0}function co(e,t,o){const n=ao(e,o);return void 0===n&&R("TBW040",'Cannot determine row ID. Configure getRowId in gridConfig or ensure rows have an "id" property.',t),n}class ho{#m;constructor(e){this.#m=e}resolveRowId(e){return co(e,this.#m.id,this.#m.effectiveConfig?.getRowId)}getRow(e){return this.#m._getRowEntry(e)?.row}getRowEntry(e){return this.#m._getRowEntry(e)}updateRow(e,t,n="api"){const r=this.#m,i=r._getRowEntry(e);i||R(o,`Row with ID "${e}" not found. Ensure the row exists and getRowId is correctly configured.`,r.id);const{row:s,index:l}=i,a=[];for(const[o,c]of Object.entries(t)){const e=s[o];e!==c&&(a.push({field:o,oldValue:e,newValue:c}),s[o]=c,qe(s,o))}for(const{field:o,oldValue:c,newValue:d}of a)r.dispatchEvent(new CustomEvent("cell-change",{detail:{row:s,rowId:e,rowIndex:l,field:o,oldValue:c,newValue:d,changes:t,source:n},bubbles:!0,composed:!0}));a.length>0&&(xt(r),r._requestSchedulerPhase(rt.VIRTUALIZATION,"updateRow"),r._emitDataChange())}updateRows(e,t="api"){const n=this.#m;let r=!1;for(const{id:i,changes:s}of e){const e=n._getRowEntry(i);e||R(o,`Row with ID "${i}" not found. Ensure the row exists and getRowId is correctly configured.`,n.id);const{row:l,index:a}=e;for(const[o,c]of Object.entries(s)){const e=l[o];e!==c&&(r=!0,l[o]=c,qe(l,o),n.dispatchEvent(new CustomEvent("cell-change",{detail:{row:l,rowId:i,rowIndex:a,field:o,oldValue:e,newValue:c,changes:s,source:t},bubbles:!0,composed:!0})))}}r&&(xt(n),n._requestSchedulerPhase(rt.VIRTUALIZATION,"updateRows"),n._emitDataChange())}async insertRow(e,t,o=!0){const n=this.#m,r=Math.max(0,Math.min(e,n._rows.length));n.sourceRows=[...n.sourceRows,t];const i=[...n._rows];i.splice(r,0,t),n._rows=i,n._sortState&&(n.__originalOrder=[...n.__originalOrder,t]),xt(n),n._rebuildRowIdMap(),n.__rowRenderEpoch++;for(let s=0;s<n._rowPool.length;s++)n._rowPool[s].__epoch=-1;n.refreshVirtualWindow(!0),n._emitPluginEvent("row-inserted",{row:t,index:r}),n._emitDataChange(),o&&(await new Promise(e=>requestAnimationFrame(()=>e())),await lo(n,r,"insert"))}async removeRow(e,t=!0){const o=this.#m,n=o._rows[e];if(!n)return;t&&await lo(o,e,"remove");const r=o._rows.indexOf(n);if(r<0)return n;const i=[...o._rows];i.splice(r,1),o._rows=i;const s=o.sourceRows.indexOf(n);if(s>=0){const e=[...o.sourceRows];e.splice(s,1),o.sourceRows=e}if(o._sortState){const e=o.__originalOrder.indexOf(n);if(e>=0){const t=[...o.__originalOrder];t.splice(e,1),o.__originalOrder=t}}xt(o),o._rebuildRowIdMap(),o.__rowRenderEpoch++;for(let l=0;l<o._rowPool.length;l++)o._rowPool[l].__epoch=-1;return o.refreshVirtualWindow(!0),o._emitDataChange(),t&&requestAnimationFrame(()=>{const e=o.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),n}async applyTransaction(e,t=!0){const o=this.#m,n={added:[],updated:[],removed:[]};if(e.remove?.length)for(const{id:l}of e.remove){const e=o._getRowEntry(l);if(!e)continue;const{row:r}=e;if(t){const e=o._rows.indexOf(r);e>=0&&await lo(o,e,"remove")}const i=o._rows.indexOf(r);if(i<0){n.removed.push(r);continue}const s=[...o._rows];s.splice(i,1),o._rows=s;const a=o.sourceRows.indexOf(r);if(a>=0){const e=[...o.sourceRows];e.splice(a,1),o.sourceRows=e}if(o._sortState){const e=o.__originalOrder.indexOf(r);if(e>=0){const t=[...o.__originalOrder];t.splice(e,1),o.__originalOrder=t}}n.removed.push(r)}const r=new Set(e.remove?.map(e=>e.id));if(e.update?.length)for(const{id:l,changes:a}of e.update){if(r.has(l))continue;const e=o._getRowEntry(l);if(!e)continue;const{row:t,index:i}=e;let s=!1;for(const[n,r]of Object.entries(a)){const e=t[n];e!==r&&(s=!0,t[n]=r,qe(t,n),o.dispatchEvent(new CustomEvent("cell-change",{detail:{row:t,rowId:l,rowIndex:i,field:n,oldValue:e,newValue:r,changes:a,source:"api"},bubbles:!0,composed:!0})))}s&&n.updated.push(t)}if(e.add?.length)for(const l of e.add){o.sourceRows=[...o.sourceRows,l];const e=[...o._rows];e.push(l),o._rows=e,o._sortState&&(o.__originalOrder=[...o.__originalOrder,l]),n.added.push(l)}const i=n.added.length>0||n.removed.length>0,s=n.updated.length>0;if(i){xt(o),o._rebuildRowIdMap(),o.__rowRenderEpoch++;for(let e=0;e<o._rowPool.length;e++)o._rowPool[e].__epoch=-1;o.refreshVirtualWindow(!0)}else s&&(xt(o),o._requestSchedulerPhase(rt.VIRTUALIZATION,"applyTransaction"));if((i||s)&&o._emitDataChange(),t&&n.added.length>0){await new Promise(e=>requestAnimationFrame(()=>e()));for(const e of n.added){const t=o._rows.indexOf(e);t>=0&&await lo(o,t,"insert")}}if(t&&n.updated.length>0)for(const l of n.updated){const e=o._rows.indexOf(l);e>=0&&await lo(o,e,"change")}return t&&n.removed.length>0&&requestAnimationFrame(()=>{const e=o.querySelectorAll('[data-animating="remove"]');for(let t=0;t<e.length;t++)e[t].removeAttribute("data-animating")}),n}#J=null;#ee=[];#te=null;applyTransactionAsync(e){return this.#J||(this.#J={add:[],update:[],remove:[]}),e.add&&this.#J.add.push(...e.add),e.update&&this.#J.update.push(...e.update),e.remove&&this.#J.remove.push(...e.remove),new Promise(e=>{this.#ee.push(e),null===this.#te&&(this.#te=requestAnimationFrame(()=>{this.#te=null;const e=this.#J,t=this.#ee;this.#J=null,this.#ee=[],this.applyTransaction(e,!1).then(e=>{for(const o of t)o(e)})}))})}}const uo="tbw-grid-styles";let go="";const fo=/* @__PURE__ */new Map;function po(){const e=function(){const e=Ho.activeTag;return e===Ho.tagName?uo:`${uo}-${e}`}();let t=document.getElementById(e);return t||(t=document.createElement("style"),t.id=e,t.setAttribute("data-tbw-grid","true"),document.head.appendChild(t)),t}function wo(e){const t=Ho.activeTag;return t===Ho.tagName?e:e.replace(/(?<![-\w])tbw-grid(?![-\w])/g,t)}function mo(){const e=po(),t=Array.from(fo.values()).join("\n");e.textContent=`${go}\n\n/* Plugin Styles */\n${t}`}async function bo(e){if(go)return;if("string"==typeof e&&e.length>0)return go=wo(e),void mo();await new Promise(e=>setTimeout(e,50));const t=function(){try{for(const e of Array.from(document.styleSheets))try{const t=Array.from(e.cssRules||[]).map(e=>e.cssText).join("\n");if(t.includes(".tbw-grid-root")&&t.includes("tbw-grid"))return t}catch{continue}}catch(e){E("TBW120",`Failed to extract grid.css from document stylesheets: ${e}`)}return null}();t?(go=wo(t),mo()):"undefined"!=typeof process&&"test"===process.env?.NODE_ENV||E("TBW121",`Could not find grid.css in document.styleSheets. Grid styling will not work. Available stylesheets: ${Array.from(document.styleSheets).map(e=>e.href||"(inline)").join(", ")}`)}function vo(e){e.startY=null,e.startX=null,e.lastY=null,e.lastX=null,e.lastTime=null,e.locked=!1}function Co(e){e.momentumRaf&&(cancelAnimationFrame(e.momentumRaf),e.momentumRaf=0)}function yo(e,t){if(null!==e.lastTime){performance.now()-e.lastTime>60&&(e.velocityY=0,e.velocityX=0)}(Math.abs(e.velocityY)>.1||Math.abs(e.velocityX)>.1)&&function(e,t){const o=.95,n=1;let r=performance.now();const i=()=>{const s=performance.now(),l=s-r;r=s;const a=l/16,c=Math.pow(o,a);e.velocityY*=c,e.velocityX*=c;const d=16*e.velocityY,h=16*e.velocityX,u=Math.abs(d)>=n,g=Math.abs(h)>=n;u&&(t.fauxScrollbar.scrollTop+=d),g&&t.scrollArea&&(t.scrollArea.scrollLeft+=h),e.momentumRaf=u||g?requestAnimationFrame(i):0};e.momentumRaf=requestAnimationFrame(i)}(e,t),vo(e)}function _o(e,t,o,n){e.addEventListener("pointerdown",o=>{"touch"===o.pointerType&&null===t.activePointerId&&(t.activePointerId=o.pointerId,e.setPointerCapture(o.pointerId),function(e,t,o){Co(o),o.startY=t,o.startX=e,o.lastY=t,o.lastX=e,o.lastTime=performance.now(),o.velocityY=0,o.velocityX=0,o.locked=!1}(o.clientX,o.clientY,t))},{passive:!0,signal:n}),e.addEventListener("pointermove",e=>{if(e.pointerId!==t.activePointerId)return;const n=function(e,t,o,n){if(null===o.lastY||null===o.lastX)return!1;const r=performance.now(),i=o.lastY-t,s=o.lastX-e;if(null!==o.lastTime){const e=r-o.lastTime;e>0&&(o.velocityY=i/e,o.velocityX=s/e)}if(o.lastY=t,o.lastX=e,o.lastTime=r,o.locked){const{scrollTop:e,scrollHeight:t,clientHeight:o}=n.fauxScrollbar;if(i>0&&e<t-o||i<0&&e>0?n.fauxScrollbar.scrollTop+=i:0!==i&&window.scrollBy(0,i),n.scrollArea){const{scrollLeft:e,scrollWidth:t,clientWidth:o}=n.scrollArea;s>0&&e<t-o||s<0&&e>0?n.scrollArea.scrollLeft+=s:0!==s&&window.scrollBy(s,0)}return!0}const l=null!==o.startY?Math.abs(o.startY-t):0,a=null!==o.startX?Math.abs(o.startX-e):0;if(l<3&&a<3)return!1;const c=l>=a,{scrollHeight:d,clientHeight:h}=n.fauxScrollbar,u=d-h>0;let g=!1;if(n.scrollArea){const{scrollWidth:e,clientWidth:t}=n.scrollArea;g=e-t>0}return!!(c&&u||!c&&g)&&(o.locked=!0,n.fauxScrollbar.scrollTop+=i,n.scrollArea&&(n.scrollArea.scrollLeft+=s),!0)}(e.clientX,e.clientY,t,o);n&&e.preventDefault()},{passive:!1,signal:n}),e.addEventListener("pointerup",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,yo(t,o))},{passive:!0,signal:n}),e.addEventListener("pointercancel",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,vo(t))},{passive:!0,signal:n}),e.addEventListener("lostpointercapture",e=>{e.pointerId===t.activePointerId&&(t.activePointerId=null,vo(t))},{passive:!0,signal:n})}const So=[{property:"editable",pluginName:"editing",level:"column",description:"",isUsed:e=>!0===e||"function"==typeof e},{property:"editor",pluginName:"editing",level:"column",description:""},{property:"editorParams",pluginName:"editing",level:"column",description:""},{property:"group",pluginName:"groupingColumns",level:"column",description:""},{property:"pinned",pluginName:"pinnedColumns",level:"column",description:"",isUsed:e=>"left"===e||"right"===e||"start"===e||"end"===e}],Ro=[{property:"rowEditable",pluginName:"editing",level:"config",description:"",isUsed:e=>"function"==typeof e},{property:"columnGroups",pluginName:"groupingColumns",level:"config",description:"",isUsed:e=>Array.isArray(e)&&e.length>0}];function Eo(e){return`import { ${Po(e)}Plugin } from '@toolbox-web/grid/plugins/${t=e,t.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}';`;var t}function Po(e){return e.charAt(0).toUpperCase()+e.slice(1)}function xo(e,t){return e.some(e=>e.name===t)}class Ao{#m;state;constructor(e,t){this.#m=e,this.state={enabled:!0,rowHeight:28,bypassThreshold:24,start:0,end:0,container:null,viewportEl:null,totalHeightEl:null,positionCache:null,heightCache:{byKey:/* @__PURE__ */new Map,byRef:/* @__PURE__ */new WeakMap},averageHeight:28,measuredCount:0,variableHeights:!1,cachedViewportHeight:0,cachedFauxHeight:0,cachedScrollAreaHeight:0,scrollAreaEl:null,scrollMapping:{rawContentHeight:0,spacerHeight:0,viewportHeight:0,capped:!1},...t}}updateCachedGeometry(){const e=this.state,t=e.container,o=e.viewportEl??t;o&&(e.cachedViewportHeight=o.clientHeight),t&&(e.cachedFauxHeight=t.clientHeight);const n=e.scrollAreaEl;n&&(e.cachedScrollAreaHeight=n.clientHeight)}calculateTotalSpacerHeight(e,t=!1){const o=this.state;let n,r,i;if(t){const e=o.container??this.#m._hostElement,t=o.viewportEl??e,s=o.scrollAreaEl;n=e?.clientHeight??0,r=t?.clientHeight??0,i=s?s.clientHeight:n,o.cachedFauxHeight=n,o.cachedViewportHeight=r,o.cachedScrollAreaHeight=i}else n=o.cachedFauxHeight,r=o.cachedViewportHeight,i=o.cachedScrollAreaHeight||n;const s=i-r,l=Math.max(0,n-i);let a;return a=o.variableHeights&&o.positionCache?function(e){if(0===e.length)return 0;const t=e[e.length-1];return t.offset+t.height}(o.positionCache):e*o.rowHeight,o.scrollMapping=zt(a,r),o.scrollMapping.spacerHeight+s+l}initializePositionCache(){const e=this.state;if(!e.variableHeights)return;const t=this.#m,o=t._rows,n=e.rowHeight||28,r=t.effectiveConfig?.rowHeight,i=t.effectiveConfig?.getRowId,s=i?e=>i(e):void 0;e.positionCache=function(e,t,o,n,r){const i=new Array(e.length);let s=0;for(let l=0;l<e.length;l++){const a=e[l];let c=r?.(a,l),d=void 0!==c;void 0===c&&(c=Lt(t,a,n.rowId),d=void 0!==c),void 0===c&&(c=o,d=!1),i[l]={offset:s,height:c,measured:d},s+=c}return i}(o,e.heightCache,n,{rowId:s},(e,o)=>{const n=t._getPluginRowHeight(e,o);if(void 0!==n)return n;if(r){const t=r(e,o);if(void 0!==t&&t>0)return t}});const l=function(e,t,o,n){let r=0,i=0;for(let s=0;s<e.length;s++){const o=e[s];if(o.measured){const e=n?.(t[s],s);void 0===e&&(i+=o.height,r++)}}return{measuredCount:r,averageHeight:r>0?i/r:o}}(e.positionCache,o,n,(e,o)=>t._getPluginRowHeight(e,o));e.measuredCount=l.measuredCount,l.measuredCount>0&&(e.averageHeight=l.averageHeight)}invalidateRowHeight(e,t){const o=this.state;if(!o.variableHeights)return;if(!o.positionCache)return;const n=this.#m._rows;if(e<0||e>=n.length)return;const r=n[e];let i=t;void 0===i&&(i=this.#m._getPluginRowHeight(r,e)),void 0===i&&(i=o.rowHeight);const s=o.positionCache[e];if(s&&!(Math.abs(s.height-i)<1)&&(kt(o.positionCache,e,i),o.totalHeightEl)){const e=this.calculateTotalSpacerHeight(n.length);o.totalHeightEl.style.height=`${e}px`}}measureRenderedRowHeights(e,t){const o=this.state;if(!o.variableHeights)return;if(!o.positionCache)return;const n=this.#m,r=n._bodyEl;if(!r)return;const i=r.querySelectorAll(".data-grid-row"),s=n.effectiveConfig?.getRowId,l=n._rows,a=Dt({positionCache:o.positionCache,heightCache:o.heightCache,rows:l,defaultHeight:o.rowHeight,start:e,end:t,getPluginHeight:(e,t)=>n._getPluginRowHeight(e,t),getRowId:s?e=>s(e):void 0},i);if(a.hasChanges&&(o.measuredCount=a.measuredCount,o.averageHeight=a.averageHeight,o.totalHeightEl)){const e=this.calculateTotalSpacerHeight(l.length);o.totalHeightEl.style.height=`${e}px`}}refreshVirtualWindow(e=!1,t=!1){const o=this.state,n=this.#m,r=n._bodyEl;if(!r)return!1;const i=n._rows.length;if(!o.enabled)return n._renderVisibleRows(0,i),t||n._afterPluginRender(),!0;if(i<=o.bypassThreshold)return o.start=0,o.end=i,e&&(r.style.transform="translateY(0px)"),n._renderVisibleRows(0,i,n.__rowRenderEpoch),e&&o.variableHeights&&this.initializePositionCache(),e&&o.totalHeightEl&&(o.totalHeightEl.style.height=`${this.calculateTotalSpacerHeight(i,!0)}px`),n._updateAriaCounts(i,n._visibleColumns.length),t||n._afterPluginRender(),!0;const s=o.container,l=o.viewportEl??s,a=e?o.cachedViewportHeight=l.clientHeight:o.cachedViewportHeight||(o.cachedViewportHeight=l.clientHeight),c=o.rowHeight,d=Nt(s.scrollTop,o.scrollMapping);let h;e&&o.variableHeights&&this.initializePositionCache();const u=o.positionCache;o.variableHeights&&u&&u.length>0?(h=Ot(u,d),-1===h&&(h=0)):h=Math.floor(d/c),h-=h%2,h<0&&(h=0),i>0&&h>i-1&&(h=i-1);const g=n._adjustPluginVirtualStart(h,d,c);let f;if(void 0!==g&&g<h&&(h=g,h-=h%2,h<0&&(h=0)),o.variableHeights&&u&&u.length>0){const e=a+3*c;let t=0;for(f=h;f<i&&t<e;)t+=u[f].height,f++;const o=Math.ceil(a/c)+3;f-h<o&&(f=Math.min(h+o,i))}else{f=h+(Math.ceil(a/c)+3)}f>i&&(f=i);const p=o.start,w=o.end;if(!e&&h===p&&f===w)return!1;o.start=h,o.end=f;const m=e?o.cachedFauxHeight=s.clientHeight:o.cachedFauxHeight||(o.cachedFauxHeight=s.clientHeight);if(e){const e=o.scrollAreaEl;e&&(o.cachedScrollAreaHeight=e.clientHeight)}if(0===m&&a>0)return n._requestSchedulerPhase(rt.VIRTUALIZATION,"stale-refs-retry"),!1;if(e&&o.totalHeightEl){const e=this.calculateTotalSpacerHeight(i);o.totalHeightEl.style.height=`${e}px`}let b;b=o.variableHeights&&u&&u[h]?u[h].offset:h*c;const v=-(d-b);return r.style.transform=`translateY(${v}px)`,n._renderVisibleRows(h,f,n.__rowRenderEpoch),e&&o.variableHeights&&this.measureRenderedRowHeights(h,f),n._updateAriaCounts(i,n._visibleColumns.length),e&&!t&&(n._afterPluginRender(),queueMicrotask(()=>{if(!o.totalHeightEl)return;const e=this.calculateTotalSpacerHeight(i);0===o.cachedFauxHeight&&o.cachedViewportHeight>0||(o.totalHeightEl.style.height=`${e}px`)})),!0}}class To{constructor(e){this.grid=e}plugins=[];getPlugins(){return this.plugins}pluginMap=/* @__PURE__ */new Map;cellRenderers=/* @__PURE__ */new Map;headerRenderers=/* @__PURE__ */new Map;cellEditors=/* @__PURE__ */new Map;_hasAfterCellRender=!1;_hasAfterRowRender=!1;_hasProcessRows=!1;_hasRowStructurePlugins=!1;#oe=/* @__PURE__ */new Map;eventListeners=/* @__PURE__ */new Map;queryHandlers=/* @__PURE__ */new Map;attachAll(e){const t=this.#ne(e);for(const o of t)this.attach(o)}#ne(e){if(e.length<2)return e;const t=/* @__PURE__ */new Map,o=/* @__PURE__ */new Map,n=[];for(const r of e){const e=r.constructor,i=t.get(e);if(!i){t.set(e,r),n.push(r);continue}const s=o.get(i)??[];s.push(r),o.set(i,s)}if(0===o.size)return n;for(const[r,i]of o)r.mergeConfigsFrom(i);return n}attach(e){if(function(e,o,n){const r=e.name,i=e.constructor.dependencies??[];for(const s of i){if(s.when&&!s.when(e.resolvedConfig))continue;const i=s.name,l=s.required??!0,a=s.reason;if(o.some(e=>e.name===i))continue;const c=s.severity??(l?"error":void 0);if(!c)continue;const d="error"===c?"requires":"recommends",h=a??`${Po(r)}Plugin ${d} ${Po(i)}Plugin`;if("error"===c){const e=Eo(i);R("TBW020",`Plugin dependency error:\n\n${h}.\n\n → Add the plugin to your gridConfig.plugins array BEFORE ${Po(r)}Plugin:\n ${e}\n plugins: [new ${Po(i)}Plugin(), new ${Po(r)}Plugin()]`,n)}else dt()&&("warn"===c?E(t,`${h}.`,n):P(t,`${h}.`,n))}}(e,this.plugins,this.grid.getAttribute("id")??void 0),this.pluginMap.set(e.constructor,e),this.plugins.push(e),e.cellRenderers)for(const[t,o]of Object.entries(e.cellRenderers))this.cellRenderers.set(t,o);if(e.headerRenderers)for(const[t,o]of Object.entries(e.headerRenderers))this.headerRenderers.set(t,o);if(e.cellEditors)for(const[t,o]of Object.entries(e.cellEditors))this.cellEditors.set(t,o);this.registerQueryHandlers(e),e.attach(this.grid),this.#re();for(const t of this.plugins)t!==e&&t.onPluginAttached&&t.onPluginAttached(e.name,e)}registerQueryHandlers(e){const t=e.constructor.manifest;if(t?.queries)for(const o of t.queries){let t=this.queryHandlers.get(o.type);t||(t=/* @__PURE__ */new Set,this.queryHandlers.set(o.type,t)),t.add(e)}}unregisterQueryHandlers(e){for(const[t,o]of this.queryHandlers)o.delete(e),0===o.size&&this.queryHandlers.delete(t)}detachAll(){for(const e of this.plugins)for(const t of this.plugins)t!==e&&t.onPluginDetached&&t.onPluginDetached(e.name);for(let e=this.plugins.length-1;e>=0;e--){const t=this.plugins[e];this.unsubscribeAll(t),this.unregisterQueryHandlers(t),t.detach()}this.plugins=[],this.pluginMap.clear(),this.cellRenderers.clear(),this.headerRenderers.clear(),this.cellEditors.clear(),this.eventListeners.clear(),this.queryHandlers.clear(),this._hasAfterCellRender=!1,this._hasAfterRowRender=!1,this._hasProcessRows=!1,this.#oe.clear()}getPlugin(e){return this.pluginMap.get(e)}getPluginByName(e){return this.plugins.find(t=>t.name===e||t.aliases?.includes(e))}hasPlugin(e){return this.pluginMap.has(e)}getAll(){return this.plugins}getRegisteredPluginNames(){return this.plugins.map(e=>e.name)}getCellRenderer(e){return this.cellRenderers.get(e)}getHeaderRenderer(e){return this.headerRenderers.get(e)}getCellEditor(e){return this.cellEditors.get(e)}getPluginStyles(){return this.plugins.filter(e=>e.styles).map(e=>({name:e.name,styles:e.styles}))}processRows(e){if(!this._hasProcessRows)return e;let t=e;for(const o of this.#ie("processRows")){const e=o.processRows(t);e!==t&&(t=e)}return t}processColumns(e){let t=[...e];for(const o of this.#ie("processColumns"))t=o.processColumns(t);return t}processConfig(e){for(const t of this.#ie("processConfig"))t.processConfig(e)}beforeRender(){for(const e of this.plugins)e.beforeRender?.()}afterStructuralRender(){for(const e of this.#ie("afterStructuralRender"))e.afterStructuralRender()}afterRender(){for(const e of this.#ie("afterRender"))e.afterRender()}afterCellRender(e){for(const t of this.#ie("afterCellRender"))t.afterCellRender(e)}hasAfterCellRenderHook(){return this._hasAfterCellRender}afterRowRender(e){for(const t of this.#ie("afterRowRender"))t.afterRowRender(e)}hasAfterRowRenderHook(){return this._hasAfterRowRender}#re(){this._hasAfterCellRender=this.plugins.some(e=>"function"==typeof e.afterCellRender),this._hasAfterRowRender=this.plugins.some(e=>"function"==typeof e.afterRowRender),this._hasProcessRows=this.plugins.some(e=>"function"==typeof e.processRows),this._hasRowStructurePlugins=this.plugins.some(e=>!0===e.constructor.manifest?.modifiesRowStructure),this.#oe.clear()}#ie(e){let t=this.#oe.get(e);if(t)return t;t=this.plugins.filter(t=>e in t&&"function"==typeof t[e]);const o=t=>{const o=t.constructor.manifest?.hookPriority;if(!o)return 0;return o[e]??0};return t.some(e=>0!==o(e))&&t.sort((e,t)=>o(e)-o(t)),this.#oe.set(e,t),t}onScrollRender(){for(const e of this.#ie("onScrollRender"))e.onScrollRender()}getRowHeight(e,t){for(const o of this.plugins)if("function"==typeof o.getRowHeight){const n=o.getRowHeight(e,t);if(void 0!==n)return n}}hasRowHeightPlugin(){for(const e of this.plugins)if("function"==typeof e.getRowHeight)return!0;return!1}adjustVirtualStart(e,t,o){let n=e;for(const r of this.plugins)if("function"==typeof r.adjustVirtualStart){const i=r.adjustVirtualStart(e,t,o);i<n&&(n=i)}return n}renderRow(e,t,o){for(const n of this.plugins)if(n.renderRow?.(e,t,o))return!0;return!1}queryPlugins(e){const t=[],o=this.queryHandlers.get(e.type);if(o&&o.size>0){for(const n of o){const o=n.handleQuery?.(e);void 0!==o&&t.push(o)}return t}for(const n of this.plugins){const o=n.handleQuery?.(e);void 0!==o&&t.push(o)}return t}subscribe(e,t,o){let n=this.eventListeners.get(t);n||(n=/* @__PURE__ */new Map,this.eventListeners.set(t,n)),n.set(e,o)}unsubscribe(e,t){const o=this.eventListeners.get(t);o&&(o.delete(e),0===o.size&&this.eventListeners.delete(t))}unsubscribeAll(e){for(const[t,o]of this.eventListeners)o.delete(e),0===o.size&&this.eventListeners.delete(t)}emitPluginEvent(e,t){const o=this.eventListeners.get(e);if(o)for(const r of o.values())try{r(t)}catch(n){x("TBW024",`Error in plugin event handler for "${e}": ${n}`,this.grid.getAttribute("id")??void 0)}}onKeyDown(e){for(const t of this.#ie("onKeyDown"))if(t.onKeyDown(e))return!0;return!1}onCellClick(e){for(const t of this.#ie("onCellClick"))if(t.onCellClick(e))return!0;return!1}onRowClick(e){for(const t of this.#ie("onRowClick"))if(t.onRowClick(e))return!0;return!1}onHeaderClick(e){for(const t of this.#ie("onHeaderClick"))if(t.onHeaderClick(e))return!0;return!1}onScroll(e){for(const t of this.#ie("onScroll"))t.onScroll(e)}onCellMouseDown(e){for(const t of this.#ie("onCellMouseDown"))if(t.onCellMouseDown(e))return!0;return!1}onCellMouseMove(e){for(const t of this.#ie("onCellMouseMove"))if(t.onCellMouseMove(e))return!0;return!1}onCellMouseUp(e){for(const t of this.#ie("onCellMouseUp"))if(t.onCellMouseUp(e))return!0;return!1}getHorizontalScrollOffsets(e,t){let o=0,n=0,r=!1;for(const i of this.plugins){const s=i.getHorizontalScrollOffsets?.(e,t);s&&(o+=s.left,n+=s.right,s.skipScroll&&(r=!0))}return{left:o,right:n,skipScroll:r}}getToolPanels(){const e=[];for(const t of this.plugins){const o=t.getToolPanel?.();o&&e.push({plugin:t,panel:o})}return e.sort((e,t)=>(e.panel.order??0)-(t.panel.order??0))}getHeaderContents(){const e=[];for(const t of this.plugins){const o=t.getHeaderContent?.();o&&e.push({plugin:t,content:o})}return e.sort((e,t)=>(e.content.order??0)-(t.content.order??0))}}class Ho extends HTMLElement{static tagName="tbw-grid";static version="2.16.4";static activeTag="tbw-grid";static#se=0;static adapters=[];static registerAdapter(e){this.adapters.push(e)}static getAdapters(){return this.adapters}static clearAdapters(){this.adapters=[]}static get observedAttributes(){return["rows","columns","grid-config","fit-mode","loading"]}get#le(){return this}#ae=!1;#C;#y;#ce=[];get#k(){return this.#de?.effective??{}}#he=!1;#ue=!1;#ge={rows:!1,columns:!1,gridConfig:!1,fitMode:!1};#fe;#pe=0;#we=null;#me=!1;#be=!1;#ve=0;#Ce;#ye={startY:null,startX:null,lastY:null,lastX:null,lastTime:null,velocityY:0,velocityX:0,momentumRaf:0,locked:!1,activePointerId:null};#_e;#Se;#Re;#Ee;#Pe={scrollTop:0,scrollLeft:0,scrollHeight:0,scrollWidth:0,clientHeight:0,clientWidth:0};#xe;#Ae;#Te;#He;#Me;#Le;get _pluginManager(){return this.#xe}#ke=!1;#Oe;#De;#q;#de;#Ie;#ze=/* @__PURE__ */new Map;#Ne=!1;#qe=/* @__PURE__ */new Set;#Fe=/* @__PURE__ */new Map;#$e;#We={};#Be=/* @__PURE__ */new Map;#Ve=!1;_rows=[];#Ue=[];get _columns(){return this.#k.columns??[]}set _columns(e){this.#k.columns=e,this.#Ge=void 0}#Ge;get _visibleColumns(){return this.#Ge??=this._columns.filter(e=>!e.hidden)}_invalidateVisibleColumnsCache(){this.#Ge=void 0}_headerRowEl;_bodyEl;_rowPool=[];_resizeController;get _virtualization(){return this.#He.state}set _virtualization(e){Object.assign(this.#He.state,e)}_focusRow=0;_focusCol=0;_restoreFocusAfterRender=!1;_sortState=null;_gridTemplate="";__rowRenderEpoch=0;__didInitialAutoSize=!1;get __lightDomColumnsCache(){return this.#de?.lightDomColumnsCache}set __lightDomColumnsCache(e){this.#de&&(this.#de.lightDomColumnsCache=e)}get __originalColumnNodes(){return this.#de?.originalColumnNodes}set __originalColumnNodes(e){this.#de&&(this.#de.originalColumnNodes=e)}__originalOrder=[];__frameworkAdapter;__rowsBodyEl=null;get rows(){return this._rows}set rows(e){const t=Array.isArray(e)?e:[],o=this.#ce;this.#ce=t,o!==t&&this.#je("rows")}get sourceRows(){return this.#ce}set sourceRows(e){this.#ce=Array.isArray(e)?e:[]}get columns(){return[...this._columns]}set columns(e){const t=this.#de?.getColumns();this.#de?.setColumns(e),t!==e&&this.#je("columns")}get gridConfig(){return this.#k}set gridConfig(e){e&&this.__frameworkAdapter?.processConfig&&(e=this.__frameworkAdapter.processConfig(e));const t=this.#de?.getGridConfig();this.#de?.setGridConfig(e),t!==e&&(this.#de.clearLightDomCache(),this.#je("gridConfig"))}get _sourceConfig(){return this.#de?.getGridConfig()}get fitMode(){return this.#k.fitMode??"stretch"}set fitMode(e){const t=this.#de?.getFitMode();this.#de?.setFitMode(e),t!==e&&this.#je("fitMode")}get loading(){return this.#Ne}set loading(e){const t=this.#Ne;this.#Ne=e,t!==e&&(e?(this.setAttribute("loading",""),this.setAttribute("aria-busy","true")):(this.removeAttribute("loading"),this.removeAttribute("aria-busy")),this.#Ye(),this.#Xe())}setRowLoading(e,t){const o=this.#qe.has(e);t?this.#qe.add(e):this.#qe.delete(e),o!==t&&this.#Ke(e,t)}setCellLoading(e,t,o){let n=this.#Fe.get(e);const r=n?.has(t)??!1;o?(n||(n=/* @__PURE__ */new Set,this.#Fe.set(e,n)),n.add(t)):(n?.delete(t),0===n?.size&&this.#Fe.delete(e)),r!==o&&this.#Ze(e,t,o)}isRowLoading(e){return this.#qe.has(e)}isCellLoading(e,t){return this.#Fe.get(e)?.has(t)??!1}clearAllLoading(){this.loading=!1;for(const e of this.#qe)this.#Ke(e,!1);this.#qe.clear();for(const[e,t]of this.#Fe)for(const o of t)this.#Ze(e,o,!1);this.#Fe.clear()}get effectiveConfig(){return this.#k}get disconnectSignal(){return this.#_e||(this.#_e=new AbortController),this.#_e.signal}constructor(){super(),this.#Qe(),this.#C=new Promise(e=>this.#y=e),this.#He=new Ao(this),this.#Me=new Zt(this),this.#Le=new ho(this),this.#fe=new it(this),this.#fe.setInitialReadyResolver(()=>this.#y?.()),this.#de=new st(this)}#Je(){const e=this.#xe?.getPluginByName("shell"),t=e??(this.#Ie??=new Ae);return t.ensureState(this),t}#et=/* @__PURE__ */new Set;#tt(e){this.#et.has(e)||(this.#et.add(e),E("TBW076",`grid.${e} is deprecated. Enable the shell via \`features: { shell }\` and call \`grid.getPluginByName('shell')?.${e}\` instead.`,this.id))}get#ot(){return this.#Je().shellState}async#Qe(){await bo('@layer tbw-base, tbw-plugins, tbw-theme;\n\n@layer tbw-base{tbw-grid{--tbw-base-icon-size: 1em;--tbw-base-radius: .25em;--tbw-font-size: 1em;--tbw-font-size-sm: .9285em;--tbw-font-size-xs: .7857em;--tbw-font-size-2xs: .7142em;--tbw-spacing-xs: .25em;--tbw-spacing-sm: .375em;--tbw-spacing-md: .5em;--tbw-spacing-lg: .75em;--tbw-spacing-xl: 1em;--tbw-icon-size: var(--tbw-base-icon-size);--tbw-icon-size-sm: .875em;--tbw-checkbox-size: var(--tbw-base-icon-size);--tbw-toggle-size: 1.25em;--tbw-border-radius: var(--tbw-base-radius);--tbw-color-bg: transparent;--tbw-color-panel-bg: light-dark(#eeeeee, #222222);--tbw-color-fg: light-dark(#222222, #eeeeee);--tbw-color-fg-muted: light-dark(#555555, #aaaaaa);--tbw-color-accent: light-dark(#3b82f6, #3b82f6);--tbw-color-accent-fg: light-dark(#ffffff, #000000);--tbw-color-success: light-dark(hsl(122, 39%, 40%), hsl(122, 39%, 49%));--tbw-color-warning: light-dark(hsl(38, 92%, 50%), hsl(38, 92%, 50%));--tbw-color-error: light-dark(hsl(0, 65%, 51%), hsl(0, 65%, 55%));--tbw-color-danger: var(--tbw-color-error);--tbw-color-selection: light-dark(#fff7d6, #333333);--tbw-color-row-alt: var(--tbw-color-bg);--tbw-color-row-hover: light-dark(#f0f6ff, #1c1c1c);--tbw-color-header-bg: color-mix(in hsl, var(--tbw-color-panel-bg) 85%, var(--tbw-color-fg));--tbw-color-header-fg: color-mix(in hsl, var(--tbw-color-fg) 75%, var(--tbw-color-panel-bg));--tbw-color-border: light-dark(#d0d0d4, #454545);--tbw-color-border-strong: light-dark(#777777, #666666);--tbw-color-border-cell: var(--tbw-color-border);--tbw-color-border-header: var(--tbw-color-border);--tbw-color-shadow: light-dark(rgba(0, 0, 0, .1), rgba(0, 0, 0, .3));--tbw-font-family: inherit;--tbw-font-size-header: var(--tbw-font-size);--tbw-font-weight-header: bold;--tbw-cell-padding-header: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-cell-padding-v: var(--tbw-spacing-xs);--tbw-cell-padding-h: var(--tbw-spacing-md);--tbw-cell-padding: var(--tbw-cell-padding-v) var(--tbw-cell-padding-h);--tbw-cell-padding-input: var(--tbw-spacing-xs) var(--tbw-spacing-sm);--tbw-row-height: 1.75em;--tbw-header-height: 1.875em;--tbw-cell-white-space: nowrap;--tbw-border-width: 1px;--tbw-border-style: solid;--tbw-border-input: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-strong);--tbw-border-header: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-header);--tbw-row-divider: var(--tbw-border-width) var(--tbw-border-style) var(--tbw-color-border-cell);--tbw-row-hover-outline: 0;--tbw-color-active-row-bg: var(--tbw-color-selection);--tbw-active-row-outline: 0;--tbw-focus-outline-width: 2px;--tbw-focus-outline: var(--tbw-focus-outline-width) var(--tbw-border-style) var(--tbw-color-accent);--tbw-focus-outline-offset: -2px;--tbw-focus-background: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-range-border-color: var(--tbw-color-accent);--tbw-range-selection-bg: rgba(from var(--tbw-range-border-color) r g b / 12%);--tbw-column-selection-bg: rgba(from var(--tbw-color-accent) r g b / 12%);--tbw-resize-handle-width: 2px;--tbw-resize-handle-color: transparent;--tbw-resize-handle-color-hover: var(--tbw-color-accent);--tbw-resize-handle-border-radius: 0;--tbw-resize-indicator-width: 2px;--tbw-resize-indicator-color: var(--tbw-color-accent);--tbw-resize-indicator-opacity: .6;--tbw-transition-duration: .12s;--tbw-transition-ease: ease;--tbw-animation-duration: .2s;--tbw-animation-easing: ease-out;--tbw-animation-enabled: 1;--tbw-row-change-duration: .5s;--tbw-row-insert-duration: .3s;--tbw-row-remove-duration: .2s;--tbw-row-change-color: rgba(from var(--tbw-color-accent) r g b / 25%);--tbw-sort-indicator-color: var(--tbw-color-fg-muted);--tbw-sort-indicator-active-color: var(--tbw-color-accent);--tbw-sort-indicator-display: inline-flex;--tbw-sort-indicator-visibility: visible;--tbw-header-text-transform: none;--tbw-header-letter-spacing: normal;--tbw-color-header-separator: var(--tbw-color-border-cell);--tbw-density-scale: 1;--tbw-shell-header-height: 2.75em;--tbw-shell-header-bg: var(--tbw-color-panel-bg);--tbw-shell-header-border: var(--tbw-color-border);--tbw-shell-title-font-size: var(--tbw-font-size);--tbw-shell-title-font-weight: 600;--tbw-tool-panel-width: 17.5em;--tbw-tool-panel-bg: var(--tbw-color-panel-bg);--tbw-tool-panel-border: var(--tbw-color-border);--tbw-tool-panel-header-height: 2.5em;--tbw-tool-panel-transition: var(--tbw-animation-duration) var(--tbw-animation-easing);--tbw-toolbar-button-size: 2em;--tbw-toolbar-button-gap: var(--tbw-spacing-xs);--tbw-panel-padding: var(--tbw-spacing-lg);--tbw-panel-gap: var(--tbw-spacing-md);--tbw-menu-item-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-menu-item-gap: var(--tbw-spacing-md);--tbw-menu-min-width: 10rem;--tbw-button-padding: var(--tbw-spacing-sm) var(--tbw-spacing-lg);--tbw-button-padding-sm: var(--tbw-spacing-xs) var(--tbw-spacing-md);--tbw-input-height: var(--tbw-row-height);--tbw-input-padding: 0 var(--tbw-spacing-md);--tbw-detail-padding: var(--tbw-spacing-xl);--tbw-detail-max-height: 31.25rem;--tbw-indicator-size: var(--tbw-spacing-sm);--tbw-icon-expand: "▶";--tbw-icon-collapse: "▼";--tbw-icon-sort-asc: "▲";--tbw-icon-sort-desc: "▼";--tbw-icon-sort-none: "⇅";--tbw-icon-submenu-arrow: "▶";--tbw-icon-drag-handle: "⋮⋮";--tbw-icon-tool-panel: "☰";--tbw-icon-filter: "";--tbw-icon-filter-active: "";--tbw-icon-print: "🖨️";--tbw-icon-expand-mask: none;--tbw-icon-collapse-mask: none;--tbw-icon-sort-asc-mask: none;--tbw-icon-sort-desc-mask: none;--tbw-icon-sort-none-mask: none;--tbw-icon-submenu-arrow-mask: none;--tbw-icon-drag-handle-mask: none;--tbw-icon-tool-panel-mask: none;--tbw-icon-filter-mask: url("data:image/svg+xml,%3Csvg viewBox=\'0 0 16 16\' width=\'12\' height=\'12\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cpath fill=\'currentColor\' d=\'M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z\'/%3E%3C/svg%3E");--tbw-icon-filter-active-mask: var(--tbw-icon-filter-mask);--tbw-icon-print-mask: none}}\n@layer tbw-base{tbw-grid{color-scheme:inherit;position:relative;display:block;width:100%;height:100%;min-height:0;contain:content;font-family:var(--tbw-font-family);font-size:var(--tbw-font-size);font-feature-settings:"tnum","lnum";background:var(--tbw-color-bg);color:var(--tbw-color-fg);border:1px solid var(--tbw-color-border);border-radius:var(--tbw-border-radius);overflow:clip;outline:none;&,*{box-sizing:border-box}.tbw-grid-root{position:relative;display:flex;flex-direction:column;height:100%;&.has-shell{display:flex;flex-direction:column;height:100%}&:has(.selected){user-select:none}}.tbw-scroll-area{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow-x:auto;overflow-y:hidden;overflow-anchor:none}.rows-body-wrapper{flex:1;min-height:0;display:flex;flex-direction:row;width:100%;min-width:fit-content}.rows-body{flex:1;min-width:0;min-height:0;display:flex;flex-direction:column;overflow:visible}.rows-container{display:flex;flex-direction:row;flex:1;min-height:0;overflow:visible;position:relative}.rows-viewport{flex:1;min-width:0;position:relative;display:block;overflow:clip;touch-action:none;.rows{position:absolute;top:0;left:0;min-width:100%;will-change:transform;z-index:var(--tbw-z-layer-rows, 1)}}.faux-vscroll{position:sticky;inset-inline-end:0;flex-shrink:0;width:auto;overflow-y:auto;overflow-x:hidden;z-index:var(--tbw-z-layer-header, 30);touch-action:none}.faux-vscroll-spacer{width:1px}.tbw-sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}&[data-has-focus]{.cell-focus,.row-focus{outline:var(--tbw-focus-outline);outline-offset:var(--tbw-focus-outline-offset)}}.sticky-left,.sticky-right{position:sticky;z-index:25}.sticky-left{box-shadow:1px 0 0 var(--tbw-color-border)}.sticky-right{box-shadow:-1px 0 0 var(--tbw-color-border)}}}\n@layer tbw-base{tbw-grid{[data-icon=expand]:empty:before{content:var(--tbw-icon-expand)}[data-icon=collapse]:empty:before{content:var(--tbw-icon-collapse)}[data-icon=sort-asc]:empty:before{content:var(--tbw-icon-sort-asc)}[data-icon=sort-desc]:empty:before{content:var(--tbw-icon-sort-desc)}[data-icon=sort-none]:empty:before{content:var(--tbw-icon-sort-none)}[data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow)}[data-icon=drag-handle]:empty:before{content:var(--tbw-icon-drag-handle)}[data-icon=tool-panel]:empty:before{content:var(--tbw-icon-tool-panel)}[data-icon=print]:empty:before{content:var(--tbw-icon-print)}[data-icon=filter]:empty:before{content:var(--tbw-icon-filter)}[data-icon=filter-active]:empty:before{content:var(--tbw-icon-filter-active)}[data-icon]:empty:before{display:inline-block;vertical-align:middle;-webkit-mask-size:contain;mask-size:contain;-webkit-mask-repeat:no-repeat;mask-repeat:no-repeat;-webkit-mask-position:center;mask-position:center}[data-icon=expand]:empty:before{-webkit-mask-image:var(--tbw-icon-expand-mask);mask-image:var(--tbw-icon-expand-mask)}[data-icon=collapse]:empty:before{-webkit-mask-image:var(--tbw-icon-collapse-mask);mask-image:var(--tbw-icon-collapse-mask)}[data-icon=sort-asc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-asc-mask);mask-image:var(--tbw-icon-sort-asc-mask)}[data-icon=sort-desc]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-desc-mask);mask-image:var(--tbw-icon-sort-desc-mask)}[data-icon=sort-none]:empty:before{-webkit-mask-image:var(--tbw-icon-sort-none-mask);mask-image:var(--tbw-icon-sort-none-mask)}[data-icon=submenu-arrow]:empty:before{-webkit-mask-image:var(--tbw-icon-submenu-arrow-mask);mask-image:var(--tbw-icon-submenu-arrow-mask)}[data-icon=drag-handle]:empty:before{-webkit-mask-image:var(--tbw-icon-drag-handle-mask);mask-image:var(--tbw-icon-drag-handle-mask)}[data-icon=tool-panel]:empty:before{-webkit-mask-image:var(--tbw-icon-tool-panel-mask);mask-image:var(--tbw-icon-tool-panel-mask)}[data-icon=print]:empty:before{-webkit-mask-image:var(--tbw-icon-print-mask);mask-image:var(--tbw-icon-print-mask)}[data-icon=filter]:empty:before,[data-icon=filter-active]:empty:before{width:var(--tbw-icon-size, 1em);height:var(--tbw-icon-size, 1em);background:currentColor}[data-icon=filter]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-mask);mask-image:var(--tbw-icon-filter-mask)}[data-icon=filter-active]:empty:before{-webkit-mask-image:var(--tbw-icon-filter-active-mask);mask-image:var(--tbw-icon-filter-active-mask)}}.tbw-context-menu [data-icon]:empty:before{display:inline-block;width:1em;height:1em;vertical-align:middle}.tbw-context-menu [data-icon=submenu-arrow]:empty:before{content:var(--tbw-icon-submenu-arrow, "▶")}}\n@layer tbw-base{tbw-grid{.header{display:block;flex-shrink:0;z-index:var(--tbw-z-layer-header, 30);background:var(--tbw-color-header-bg);overflow:visible}.header-group-row{display:grid;grid-template-columns:var(--tbw-column-template);background:var(--tbw-color-header-bg);z-index:var(--tbw-z-layer-header, 30)}.header-group-cell{display:flex;align-items:center;justify-content:flex-start;padding:var(--tbw-cell-padding-header, 2px 8px);color:var(--tbw-color-header-group-fg, var(--tbw-color-header-fg));font-weight:var(--tbw-font-weight-header-group, var(--tbw-font-weight-header));justify-content:var(--tbw-align-header-group, var(--tbw-align-header, flex-start));&:not(:last-child){border-right:2px solid var(--tbw-color-border)}}.header-row{display:grid;grid-template-columns:var(--tbw-column-template);color:var(--tbw-color-header-fg);font-size:var(--tbw-font-size-header);min-height:var(--tbw-header-height);border-bottom:var(--tbw-border-header);z-index:var(--tbw-z-layer-header, 30);text-transform:var(--tbw-header-text-transform);letter-spacing:var(--tbw-header-letter-spacing);>.cell{display:flex;align-items:center;gap:4px;padding:var(--tbw-cell-padding-header, 2px 8px);background-color:var(--tbw-color-header-bg);font-weight:var(--tbw-font-weight-header);border-right:1px solid var(--tbw-color-border-cell);overflow:visible;min-width:0;>span:first-child{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-weight:inherit}>span[part~=sort-indicator]{flex-shrink:0;opacity:.6;color:var(--tbw-sort-indicator-color);display:var(--tbw-sort-indicator-display, inline-flex);visibility:var(--tbw-sort-indicator-visibility, visible);transition:opacity .15s,visibility 0s,display 0s allow-discrete;transition-behavior:allow-discrete}&:hover>span[part~=sort-indicator]{display:inline-flex;visibility:visible}&[aria-sort=ascending]>span[part~=sort-indicator],&[aria-sort=descending]>span[part~=sort-indicator]{display:inline-flex;visibility:visible;opacity:1;color:var(--tbw-sort-indicator-active-color)}&:last-child{border-right:0;.resize-handle{right:0;width:calc(var(--tbw-resize-hit-area, 18px) / 2)}}&.grouped.group-end:not(:last-child){border-right:2px solid var(--tbw-color-border)}&.resizable{position:relative}&.sticky-left,&.sticky-right{background:var(--tbw-color-header-bg);z-index:35}}}.header-group-row>.header-group-cell{&.sticky-left,&.sticky-right{background:var(--tbw-color-header-bg);z-index:35}}.sortable{cursor:pointer;user-select:none}.resize-handle{position:absolute;top:0;right:calc(var(--tbw-resize-hit-area, 18px) / -2);width:var(--tbw-resize-hit-area, 18px);height:100%;cursor:e-resize;user-select:none;touch-action:none;z-index:20;background:transparent;&:before{content:"";position:absolute;top:0;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:100%;background:var(--tbw-resize-handle-color);border-radius:var(--tbw-resize-handle-border-radius);transition:background .12s ease}&:after{content:"";position:absolute;top:100%;left:50%;transform:translate(-50%);width:var(--tbw-resize-handle-width);height:0;background:var(--tbw-resize-indicator-color, var(--tbw-color-accent));opacity:0;pointer-events:none;transition:opacity .12s ease,height 0s .12s;z-index:1000}&:hover{&:before{background:var(--tbw-resize-handle-color-hover)}&:after{height:100vh;opacity:var(--tbw-resize-indicator-opacity, .6);transition:opacity .12s ease,height 0s}}}}}\n@layer tbw-base{tbw-grid{.data-grid-row{display:grid;grid-template-columns:var(--tbw-column-template);contain:layout style;&:nth-child(2n){background:var(--tbw-color-row-alt)}@media(hover:hover){&:hover{background:var(--tbw-color-row-hover)}}>.cell{display:block;padding:var(--tbw-cell-padding, 2px 8px);border-bottom:var(--tbw-row-divider);min-height:var(--tbw-row-height);align-content:center;border-right:1px solid var(--tbw-color-border-cell);overflow:hidden;min-width:0;white-space:var(--tbw-cell-white-space, nowrap);text-overflow:ellipsis;>*{overflow:hidden;text-overflow:ellipsis;white-space:inherit;min-width:0}&:last-child{border-right:0}&[data-type=boolean]{text-align:center;input[type=checkbox]{margin:0;width:var(--tbw-checkbox-size);height:var(--tbw-checkbox-size);vertical-align:middle}}&.selected:focus-visible,&:focus-visible:not(.cell-focus){outline:none}&.sticky-left,&.sticky-right{background:var(--tbw-color-panel-bg)}}}.selecting .data-grid-row>.cell{user-select:none}}}\n@layer tbw-base{.tbw-loading-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:1000;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-spinner{--tbw-spinner-size: 48px;--tbw-spinner-border-width: 3px;--tbw-spinner-color: var(--tbw-color-accent);--tbw-spinner-track-color: var(--tbw-color-border);width:var(--tbw-spinner-size);height:var(--tbw-spinner-size);border:var(--tbw-spinner-border-width) solid var(--tbw-spinner-track-color);border-top-color:var(--tbw-spinner-color);border-radius:50%;animation:tbw-spin .8s linear infinite}.tbw-spinner--large{--tbw-spinner-size: min(48px, calc(100% - 16px) )}.tbw-spinner--small{--tbw-spinner-size: calc(var(--tbw-row-height, 28px) * .6);--tbw-spinner-border-width: 2px}.data-grid-row.tbw-row-loading{position:relative;pointer-events:none}.tbw-row-loading-overlay{position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out;pointer-events:none;display:flex;align-items:center}.tbw-row-loading-spinner{--_spinner-size: calc(var(--tbw-row-height, 28px) * .6);margin-left:var(--tbw-spacing-md);width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite}.cell.tbw-cell-loading{position:relative;pointer-events:none;&:before{content:"";position:absolute;inset:0;background:light-dark(rgba(255,255,255,.7),rgba(0,0,0,.5));z-index:26;animation:tbw-fade-in .15s ease-out}&:after{--_spinner-size: calc(var(--tbw-row-height, 28px) * .5);content:"";position:absolute;left:var(--tbw-spacing-sm);top:0;bottom:0;margin:auto 0;width:var(--_spinner-size);height:var(--_spinner-size);border:2px solid var(--tbw-spinner-track-color, var(--tbw-color-border));border-top-color:var(--tbw-spinner-color, var(--tbw-color-accent));border-radius:50%;animation:tbw-spin .8s linear infinite;z-index:27}}}\n@layer tbw-base{.tbw-empty-overlay{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;padding:var(--tbw-spacing-md, 12px);text-align:center;background:light-dark(rgba(255,255,255,.6),rgba(0,0,0,.4));color:var(--tbw-color-text-secondary, var(--tbw-color-text));z-index:999;pointer-events:all;animation:tbw-fade-in .15s ease-out}.tbw-empty-message{font-family:var(--tbw-font-family, inherit);font-size:var(--tbw-font-size-md, 14px);line-height:1.4;max-width:480px;user-select:text}}\n@layer tbw-base{tbw-grid{.tbw-expanding{animation:tbw-expand var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}.tbw-collapsing{animation:tbw-collapse var(--tbw-animation-duration) var(--tbw-animation-easing) forwards;overflow:hidden}&[data-animation-mode=off]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms;.data-grid-row[data-animating]{animation:none}}}tbw-grid .data-grid-row[data-animating=change]{animation:tbw-row-change var(--tbw-row-change-duration) ease-out}tbw-grid .data-grid-row[data-animating=insert]{animation:tbw-row-insert var(--tbw-row-insert-duration) ease-out;will-change:max-height,opacity}tbw-grid .data-grid-row[data-animating=remove]{animation:tbw-row-remove var(--tbw-row-remove-duration) ease-out forwards;will-change:max-height,opacity,transform;pointer-events:none}}@keyframes tbw-expand{0%{opacity:0;max-height:0;transform:translateY(-8px)}to{opacity:1;max-height:500px;transform:translateY(0)}}@keyframes tbw-collapse{0%{opacity:1;max-height:500px;transform:translateY(0)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-row-change{0%{background-color:transparent}20%{background-color:var(--tbw-row-change-color)}to{background-color:transparent}}@keyframes tbw-row-insert{0%{opacity:0;max-height:0;overflow:hidden}to{opacity:1;max-height:var(--tbw-row-height, 28px);overflow:hidden}}@keyframes tbw-row-remove{0%{opacity:1;transform:translateY(0);max-height:var(--tbw-row-height, 28px)}to{opacity:0;max-height:0;transform:translateY(-8px)}}@keyframes tbw-spin{to{transform:rotate(360deg)}}@keyframes tbw-fade-in{0%{opacity:0}to{opacity:1}}\n@layer tbw-base{@media(forced-colors:active){tbw-grid{--tbw-color-border: CanvasText;--tbw-color-border-strong: CanvasText;--tbw-color-border-cell: CanvasText;--tbw-color-border-header: CanvasText;--tbw-color-fg: CanvasText;--tbw-color-bg: Canvas;--tbw-color-panel-bg: Canvas;--tbw-color-header-bg: Canvas;--tbw-color-header-fg: CanvasText;--tbw-color-accent: Highlight;--tbw-color-accent-fg: HighlightText;--tbw-color-selection: Highlight;--tbw-color-row-hover: Highlight;--tbw-focus-outline: 2px solid Highlight;--tbw-range-border-color: Highlight;.cell:focus,.cell.active-cell{outline:2px solid Highlight!important;outline-offset:-2px}.data-grid-row[aria-selected=true]{background:Highlight!important;color:HighlightText!important}}}@media(prefers-reduced-motion:reduce){tbw-grid[data-animation-mode=reduced-motion]{--tbw-animation-enabled: 0;--tbw-animation-duration: 0ms;.data-grid-row[data-animating]{animation:none}}}}\n')}getPlugin(e){return this.#xe?.getPlugin(e)}getPluginByName(e){return this.#xe?.getPluginByName(e)}requestRender(){this.#fe.requestPhase(rt.ROWS,"plugin:requestRender")}requestColumnsRender(){this.#fe.requestPhase(rt.COLUMNS,"plugin:requestColumnsRender")}requestRenderWithFocus(){this._restoreFocusAfterRender=!0,this.#fe.requestPhase(rt.ROWS,"plugin:requestRenderWithFocus")}updateTemplate(){Ie(this)}requestAfterRender(){this.#fe.requestPhase(rt.STYLE,"plugin:requestAfterRender")}requestVirtualRefresh(){this._virtualization.start=-1,this.refreshVirtualWindow(!1)}#nt(){this.#xe=new To(this);const e=this.#k?.plugins,t=Array.isArray(e)?e:[],o=this.#k?.features;let n,r=[];if(o&&Xt){r=Xt(o).map(e=>this.#rt(e))}if(0===r.length)n=t;else if(0===t.length)n=r;else{const e=new Set(t.map(e=>e.name));n=[...r.filter(t=>!e.has(t.name)),...t]}n.some(e=>"shell"===e.name)?this.#Ie=n.find(e=>"shell"===e.name):(this.#Ie??=new Ae,this.#ze.set("shell",this.#Ie),n=[this.#Ie,...n]),this.#xe.attachAll(n)}#rt(e){const t=this.#ze.get(e.name);return t&&t!==e?(t.refreshUserConfigFrom(e),t):(this.#ze.set(e.name,e),e)}#it(){!function(e){let t=!1;for(const{name:o,styles:n}of e)fo.has(o)||(fo.set(o,wo(n)),t=!0);t&&mo()}(this.#xe?.getPluginStyles()??[])}#st(){const e=this.#k?.plugins,t=Array.isArray(e)?e:[],o=this.#k?.features??void 0,n=o!==this.#Te;if((this.#Ae===t||void 0!==this.#Ae&&this.#Ae.length===t.length&&this.#Ae.every((e,o)=>e===t[o]))&&!n)return void(this.#Ae=t);this.#xe&&this.#xe.detachAll();for(const i of this.#ot.toolPanels.keys()){const e=this.#ot.lightDomToolPanelIds.has(i),t=this.#ot.apiToolPanelIds.has(i);if(!e&&!t){const e=this.#ot.panelCleanups.get(i);e&&(e(),this.#ot.panelCleanups.delete(i)),this.#ot.toolPanels.delete(i)}}for(const i of this.#ot.headerContents.keys()){if(this.#ot.apiHeaderContentIds.has(i))continue;const e=this.#ot.headerContentCleanups.get(i);e&&(e(),this.#ot.headerContentCleanups.delete(i)),this.#ot.headerContents.delete(i)}this.#nt(),this.#it(),this.#Ae=t,this.#Te=o,this.#lt(),this.#at();const r=this.#me;if(this.#me=this.#xe?.getAll().some(e=>e.onScroll)??!1,!r&&this.#me){const e=this.#le.querySelector(".tbw-grid-content")??this.#le.querySelector(".tbw-grid-root");this.#ct(e)}}#dt(){this.#xe?.detachAll()}#at(){if(!this.#xe)return;const e=this.#xe.getToolPanels();for(const{panel:o}of e){if(this.#ot.apiToolPanelIds.has(o.id))continue;if(this.#ot.lightDomToolPanelIds.has(o.id)){E(s,`Tool panel "${o.id}" is provided by a plugin; ignoring the matching light-DOM <tbw-grid-tool-panel>.`,this.id);const e=this.#ot.panelCleanups.get(o.id);e&&(e(),this.#ot.panelCleanups.delete(o.id)),this.#ot.lightDomToolPanelIds.delete(o.id),this.#ot.adapterBoundToolPanelIds.delete(o.id)}this.#ot.toolPanels.set(o.id,o)}const t=this.#xe.getHeaderContents();for(const{content:o}of t)if(!this.#ot.apiHeaderContentIds.has(o.id)){if(this.#ot.headerContents.has(o.id)){E(l,`Header content "${o.id}" is provided by a plugin; ignoring the matching light-DOM definition.`,this.id);const e=this.#ot.headerContentCleanups.get(o.id);e&&(e(),this.#ot.headerContentCleanups.delete(o.id))}this.#ot.headerContents.set(o.id,o)}}#ht(){const e=Ho.getAdapters();if(0===e.length&&!this.__frameworkAdapter)return;const t=this.__frameworkAdapter;return o=>{if(t?.createToolPanelRenderer){const e=t.createToolPanelRenderer(o);if(e)return e}for(const t of e)if(t.createToolPanelRenderer){const e=t.createToolPanelRenderer(o);if(e)return e}}}_registerLightDomHandler(e,t){this.#de.registerLightDomHandler(e,t)}_unregisterLightDomHandler(e){this.#de.unregisterLightDomHandler(e)}_requestConfigMerge(){this.#de.markSourcesChanged(),this.#de.merge()}_getToolPanelRendererFactory(){return this.#ht()}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.hasAttribute("version")||this.setAttribute("version",Ho.version),this.hasAttribute("data-tbw-grid")||this.setAttribute("data-tbw-grid",""),this.id||(this.id="tbw-grid-"+ ++Ho.#se),this._rows=Array.isArray(this.#ce)?[...this.#ce]:[],this.#_e&&(this.#_e.abort(),this.#ke=!1),this.#_e=new AbortController,this.#Ee&&(Jt(this.#Ee),this.#Ee=void 0),this.#h(),this.#de.parseLightDomColumns(this),this.#de.merge(),this.#nt();const e=this.#k?.plugins;var t,o;this.#Ae=Array.isArray(e)?e:[],this.#Te=this.#k?.features??void 0,this.#at(),this.#ae||(this.#ut(),this.#it(),this.#ae=!0),this.#gt(),this.#Ee=(t=()=>{this.#ft()},o={timeout:100},Qt?requestIdleCallback(t,o):window.setTimeout(()=>{const e=Date.now();t({didTimeout:!1,timeRemaining:()=>Math.max(0,50-(Date.now()-e))})},1))}disconnectedCallback(){this.#Ee&&(Jt(this.#Ee),this.#Ee=void 0),this.#ve&&(clearTimeout(this.#ve),this.#ve=0),this.#dt();const e=this.#xe?.getPluginByName("shell")??this.#Ie;e?.disposeShellState(),Co(this.#ye),this.#_e&&(this.#_e.abort(),this.#_e=void 0),this.#Oe?.abort(),this.#Oe=void 0,this.#ke=!1,this._resizeController&&this._resizeController.dispose(),this.#Se&&(this.#Se.disconnect(),this.#Se=void 0),this.#Re&&(this.#Re.disconnect(),this.#Re=void 0,this.#pt=!1,this.#wt=0),xt(this),this.#mt.clear(),this._virtualization.heightCache?.byKey.clear(),this.#Ae=void 0,this.#Te=void 0;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].remove();this._rowPool.length=0,this.__rowsBodyEl=null,this.#he=!1}attributeChangedCallback(e,t,o){if("loading"===e){const e=null!==o&&"false"!==o;return void(this.loading!==e&&(this.loading=e))}if(t!==o&&o&&"null"!==o&&"undefined"!==o)if("rows"===e||"columns"===e||"grid-config"===e)try{const t=JSON.parse(o);"rows"===e?this.rows=t:"columns"===e?this.columns=t:"grid-config"===e&&(this.gridConfig=t)}catch{E("TBW130",`Invalid JSON for '${e}' attribute: ${o}`,this.id)}else"fit-mode"===e&&(this.fitMode=o)}#gt(){const e=this.#le.querySelector(".tbw-grid-content")??this.#le.querySelector(".tbw-grid-root");if(this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this.setAttribute("data-upgraded",""),this.#he=!0,this._resizeController=oo(this),this.#bt(),this.#ct(e),this.#ke)return;this.#ke=!0;const t=this.disconnectSignal;Yt(this,this,this.#le,t),this.#lt(),queueMicrotask(()=>this.#vt()),this.#fe.requestPhase(rt.FULL,"afterConnect")}#lt(){const e=this.#k.rowHeight,t=this.#xe.hasRowHeightPlugin();"function"==typeof e||t?this._virtualization.variableHeights||(this._virtualization.variableHeights=!0,this._virtualization.rowHeight="number"==typeof e&&e>0?e:this._virtualization.rowHeight||28,this.#He.initializePositionCache(),"function"!=typeof e&&(this.#be=!0)):!t&&"function"!=typeof e&&this._virtualization.variableHeights?(this._virtualization.variableHeights=!1,this._virtualization.positionCache=null):"number"==typeof e&&e>0?(this._virtualization.rowHeight=e,this._virtualization.variableHeights=!1):requestAnimationFrame(()=>this.#Ct())}#Ct(){if(this.#xe.hasRowHeightPlugin())return;const e=this.#k.rowHeight;if("number"==typeof e&&e>0)return;const t=this._bodyEl?.querySelector(".data-grid-row");if(!t)return;const o=this.#yt(),n=[],r=this._bodyEl?.querySelectorAll(".data-grid-row");for(const u of r??[]){if(u.style.getPropertyValue("--tbw-row-height"))continue;let e=0;u.querySelectorAll(".cell").forEach(t=>{const o=t.offsetHeight;o>e&&(e=o)});const t=Math.max(u.getBoundingClientRect().height,e);t>0&&n.push(t)}if(0===n.length)return;n.sort((e,t)=>e-t);const i=n.length>>1,s=n.length%2==1?n[i]:(n[i-1]+n[i])/2,l=this._virtualization.rowHeight,a=this.#wt,c=o>0&&a>0&&Math.abs(o-a)>1,d=o>0&&0===a,h=s>0&&s-l>1;if(o>0&&(this.#wt=o),c||d||h){const e=c||d?Math.max(o,s):s;Math.abs(e-l)>1&&(this._virtualization.rowHeight=e,this.#fe.requestPhase(rt.VIRTUALIZATION,"measureRowHeight"))}}#yt(){const e=getComputedStyle(this).getPropertyValue("--tbw-row-height").trim();if(!e)return 0;if(e.endsWith("px"))return parseFloat(e)||0;const t=this._bodyEl?.querySelector('.data-grid-row:not([style*="--tbw-row-height"]) > .cell');if(!t)return 0;const o=parseFloat(getComputedStyle(t).minHeight);return o>0?o:0}#_t(){const e=this._bodyEl?.querySelector(".data-grid-row");if(!e)return;const t=e.querySelectorAll(".cell");let o=0;t.forEach(e=>{const t=e.offsetHeight;t>o&&(o=t)});const n=e.getBoundingClientRect(),r=Math.max(n.height,o);if(r>0){if(Math.abs(r-this._virtualization.rowHeight)>1&&(this._virtualization.rowHeight=r),this.#He.initializePositionCache(),this._virtualization.totalHeightEl){const e=this.#He.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`}}}#ct(e){this.#Oe?.abort(),this.#Oe=new AbortController;const t=this.#Oe.signal,o=e?.querySelector(".faux-vscroll"),n=e?.querySelector(".rows");if(this._virtualization.container=o??this,this.#me=this.#xe?.getAll().some(e=>e.onScroll)??!1,o&&n){o.addEventListener("scroll",()=>{if(!this._virtualization.enabled&&!this.#me)return;const e=o.scrollTop,t=Nt(e,this._virtualization.scrollMapping),r=this._virtualization.rowHeight;if(this._rows.length<=this._virtualization.bypassThreshold)n.style.transform=`translateY(${-e}px)`;else{const e=this._virtualization.positionCache;let o,i;if(this._virtualization.variableHeights&&e&&e.length>0){o=Ot(e,t),-1===o&&(o=0);const n=o-o%2;i=e[n]?.offset??n*r}else{o=Math.floor(t/r);i=(o-o%2)*r}const s=-(t-i);n.style.transform=`translateY(${s}px)`}this.#we=e,this.#pe||(this.#pe=requestAnimationFrame(()=>{this.#pe=0,null!==this.#we&&(this.#St(this.#we),this.#we=null)}))},{passive:!0,signal:t});const e=this.#le.querySelector(".tbw-scroll-area");this.#De=e,this._virtualization.scrollAreaEl=e,e&&this.#me&&e.addEventListener("scroll",()=>{const t=this.#Pe;t.scrollTop=o.scrollTop,t.scrollLeft=e.scrollLeft,t.scrollHeight=o.scrollHeight,t.scrollWidth=e.scrollWidth,t.clientHeight=o.clientHeight,t.clientWidth=e.clientWidth,this.#xe?.onScroll(t)},{passive:!0,signal:t});const r=this.#le.querySelector(".tbw-grid-content"),i=this.#De;r&&(r.addEventListener("wheel",e=>{try{if(r.querySelector("select:open"))return}catch{}const t=e.shiftKey||Math.abs(e.deltaX)>Math.abs(e.deltaY);if(t&&i){const t=e.shiftKey?e.deltaY:e.deltaX,{scrollLeft:o,scrollWidth:n,clientWidth:r}=i;(t>0&&o<n-r||t<0&&o>0)&&(e.preventDefault(),i.scrollLeft+=t)}else if(!t){const{scrollTop:t,scrollHeight:n,clientHeight:r}=o;(e.deltaY>0&&t<n-r||e.deltaY<0&&t>0)&&(e.preventDefault(),o.scrollTop+=e.deltaY)}},{passive:!1,signal:t}),_o(r,this.#ye,{fauxScrollbar:o,scrollArea:i},t))}var r,i,s;this._bodyEl&&(r=this,i=this._bodyEl,s=t,i.addEventListener("mousedown",e=>{const t=e.target.closest(".cell[data-col]");if(!t)return;if(t.classList.contains(X.EDITING))return;const o=e.target;o.draggable||o.closest('[draggable="true"]')||e.preventDefault(),Gt(r,t)},{signal:s}),i.addEventListener("click",e=>{const t=e.target.closest(".data-grid-row");if(t&&Ht(r,e,t),!document.activeElement?.closest(`.cell.${X.EDITING}`)){const t=e.target.closest("tbw-grid, [data-tbw-grid]");t&&t.focus({preventScroll:!0})}},{signal:s}),i.addEventListener("dblclick",e=>{const t=e.target.closest(".data-grid-row");t&&Ht(r,e,t)},{signal:s})),this.#Se?.disconnect(),this._virtualization.viewportEl&&(this.#Se=new ResizeObserver(()=>{this.#Rt(),this.#fe.requestPhase(rt.VIRTUALIZATION,"resize-observer")}),this.#Se.observe(this._virtualization.viewportEl)),this.#le.addEventListener("focusin",()=>{this.dataset.hasFocus=""},{signal:t}),this.#le.addEventListener("focusout",e=>{const t=e.relatedTarget;t&&(this.#le.contains(t)||this.#Me.isInExternalFocusContainer(t))||delete this.dataset.hasFocus},{signal:t})}#pt=!1;#wt=0;#Et(){if(this.#pt)return;const e=this._bodyEl?.querySelector(".data-grid-row");e&&(this.#pt=!0,this.#Re?.disconnect(),this.#Re=new ResizeObserver(()=>{this.#Ct()}),this.#Re.observe(e))}addEventListener(e,t,o){super.addEventListener(e,t,o)}removeEventListener(e,t,o){super.removeEventListener(e,t,o)}on(e,t){const o=e=>{t(e.detail,e)};return this.addEventListener(e,o),()=>this.removeEventListener(e,o)}#Pt(e,t){this.#he&&this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_emitDataChange(){this.#Pt("data-change",{rowCount:this._rows.length,sourceRowCount:this.#ce.length}),function(e,t,o){if(o===t.lastAnnouncedSourceCount)return;const n=t.lastAnnouncedSourceCount;t.lastAnnouncedSourceCount=o,0===o&&n<0||Te(e,He(e,"dataLoaded",o))}(this,this.#xt,this.#ce.length)}#vt(){const e=this._bodyEl?.querySelectorAll(".data-grid-row");e?.forEach((e,t)=>{const o=t===this._focusRow;e.setAttribute("aria-selected",String(o)),e.querySelectorAll(".cell").forEach((e,t)=>{e.setAttribute("aria-selected",String(o&&t===this._focusCol))})})}#je(e){this.#ge[e]=!0,this.#ue||(this.#ue=!0,queueMicrotask(()=>this.#At()))}#At(){if(!this.#ue||!this.#he)return void(this.#ue=!1);const e=this.#ge;if(this.#ue=!1,this.#ge={rows:!1,columns:!1,gridConfig:!1,fitMode:!1},e.gridConfig)return this.#Tt(),void(e.rows&&this.#Ht());e.columns&&this.#Mt(),e.rows&&this.#Ht(),e.fitMode&&this.#Lt()}#Ht(){this._rows=Array.isArray(this.#ce)?[...this.#ce]:[],this.#Ve=!0,this.#fe.requestPhase(rt.ROWS,"applyRowsUpdate")}#kt(){this.#Ve&&this._rebuildRowIdMap()}_rebuildRowIdMap(){this.#Ve=!1,this.#Be.clear();const e=this.#k.getRowId;for(let t=0;t<this._rows.length;t++){const o=ao(this._rows[t],e);void 0!==o&&this.#Be.set(o,{row:this._rows[t],index:t})}}#Mt(){xt(this),this.#de.merge(),this.#bt()}#Lt(){this.#de.merge();if("fixed"===this.#k.fitMode)this.__didInitialAutoSize=!1,ke(this);else{for(let e=0;e<this._columns.length;e++){const t=this._columns[e];!t.__userResized&&t.__autoSized&&delete t.width}Ie(this)}}#Tt(){this.#Je()._parseLightDomHeader(this);const e=!!this.#le.querySelector(".has-shell"),t=!!this.#le.querySelector(".tbw-tool-panel"),o=this.#le.querySelectorAll(".tbw-accordion-section").length,n=this.#le.querySelector(".tbw-tool-panel")?.dataset.position??"right",r=this.#le.querySelector(".tbw-shell-body")?.dataset.mode??"overlay";this.#de.parseLightDomColumns(this),this.#de.merge(),this.#st(),this.#lt(),this.#Je()._parseLightDomToolPanels(this),this.#de.markSourcesChanged(),this.#de.merge();const i=this.#de.initialColumnState;if(i){this.#de.initialColumnState=void 0,this.#q=void 0;const e=this.#xe?.getAll()??[];this.#de.applyState(i,e)}const s=this.#Je()._shouldRenderHeader(this.#k?.shell),l=(this.#k?.shell?.toolPanels?.length??0)>0,a=this.#k?.shell?.toolPanels?.length??0,c=this.#k?.shell?.toolPanel?.position??"right",d=this.#k?.shell?.toolPanel?.mode??"overlay";if(e!==s||!t&&l||t&&a!==o||t&&n!==c||t&&r!==d)return this.#Je()._prepareForRerender(),this.#ut(),this.#it(),this.#gt(),void this._rebuildRowIdMap();e&&this.#Ot(),this.#ot.isPanelOpen&&this.#Je()._renderOpenPanelContent(this),this._rebuildRowIdMap(),this.#fe.requestPhase(rt.COLUMNS,"applyGridConfigUpdate")}#Ot(){const e=this.#le.querySelector(".tbw-shell-header");if(!e)return;const t=this.#k.shell?.header?.title??this.#ot.lightDomTitle;let o=e.querySelector(".tbw-shell-title");t?(o||(o=document.createElement("h2"),o.className="tbw-shell-title",o.setAttribute("part","shell-title"),e.insertBefore(o,e.firstChild)),o.textContent=t):o&&o.remove()}#Dt(){if(this.__rowRenderEpoch++,this.#xe){const e=this.#Ue.length>0?this.#Ue:this._columns,t=e.filter(e=>!e.hidden),o=e.filter(e=>e.hidden),n=this.#xe.processColumns([...t]);if(n!==t){const r=new Set(n.map(e=>e.field));!t.some(e=>r.has(e.field))&&n.length>0?this._columns=[...n,...o]:this._columns=this.#It(e,n,o)}else this._columns=[...e]}}#It(e,t,o){if(0===o.length)return t;const n=/* @__PURE__ */new Map;for(const l of t)n.set(l.field,l);const r=new Set(e.map(e=>e.field)),i=[];for(const l of t)r.has(l.field)||i.push(l);const s=[];for(const l of e){const e=n.get(l.field);e?s.push(e):l.hidden&&s.push(l)}return s.push(...i),s}#zt(){xt(this);const e=this.#ce;if(!Array.isArray(e))return this._rows=[],this._rebuildRowIdMap(),this._virtualization.variableHeights&&this.#He.initializePositionCache(),void this._emitDataChange();if(!this._sortState&&this.#k.initialSort){const{field:e,direction:t}=this.#k.initialSort;this._columns.find(t=>t.field===e)&&(this._sortState={field:e,direction:"desc"===t?-1:1})}this._sortState&&(this.__originalOrder=this._rows);const t=function(e,t,o=!1){if(!e._sortState)return t;const n=e.effectiveConfig?.sortHandler??$e;if(n===$e)return o||(e.__originalOrder=t.slice()),Ue(t,e._sortState.field,e._sortState.direction,e._columns),t;o||(e.__originalOrder=t);const r=n(t,e._sortState,e._columns);return r&&"function"==typeof r.then?t:r}(this,this._sortState?[...e]:e,!0),o=this.#xe?.processRows(t)??t;this._rows=o,this.#Ve=!0,this._emitDataChange()}_renderVisibleRows(e,t,o=this.__rowRenderEpoch){if(this.#Ce||(this.#Ce=(e,t,o)=>this.#xe?.renderRow(e,t,o)??!1),function(e,t,o,n,r){const i=Math.max(0,o-t),s=e._bodyEl,l=e._visibleColumns,a=l.length;let c=e.__cachedHeaderRowCount;for(void 0===c&&(c=e.querySelector(".header-group-row")?2:1,e.__cachedHeaderRowCount=c);e._rowPool.length<i;){const t=Pt();e._rowPool.push(t)}if(e._rowPool.length>i){const t=e.__frameworkAdapter,o=t?.releaseCell;t?.beginBatch?.(e);try{for(let n=i;n<e._rowPool.length;n++){const r=e._rowPool[n];if(o){const e=r.children;for(let n=0;n<e.length;n++){const r=e[n];r.firstElementChild&&o.call(t,r)}}r.parentNode===s&&r.remove()}e._rowPool.length=i}finally{t?.endBatch?.(e)}}const d=r&&!1!==e.__hasRenderRowPlugins,h=e._hasAfterRowRenderHook?.()??!1,u=e._virtualization?.variableHeights&&"function"==typeof e.effectiveConfig?.rowHeight?e.effectiveConfig.rowHeight:null;for(let f=0;f<i;f++){const o=t+f,i=e._rows[o],p=e._rowPool[f];if(p.setAttribute("aria-rowindex",String(o+c+1)),d&&r(i,p,o)){p.__epoch=n,p.__rowDataRef=i,p.parentNode!==s&&s.appendChild(p);continue}const w=p.__epoch,m=p.__rowDataRef;let b=p.children.length;b>a&&p.lastElementChild?.classList.contains("tbw-row-loading-overlay")&&b--;const v=w===n&&b===a,C=m!==i,y=!!e._isGridEditMode;let _=!1;if(v&&C)for(let e=0;e<a;e++)if(l[e].externalView&&!p.querySelector(`.cell[data-col="${e}"] [data-external-view]`)){_=!0;break}if(!v||_){const t=yt(p),r=y&&!C||e._activeEditRows===o;t&&!r?(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),_t(p),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i):t&&r?(At(e,p,i,o),p.__rowDataRef=i):(p.__isCustomRow&&(p.className="data-grid-row",p.setAttribute("role","row"),p.__isCustomRow=!1),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i)}else if(C){const t=yt(p),r=e._activeEditRows===o;t&&!r?(_t(p),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i):(At(e,p,i,o),p.__rowDataRef=i)}else{const t=yt(p),r=y||e._activeEditRows===o;t&&!r?(_t(p),Tt(e,p,i,o),p.__epoch=n,p.__rowDataRef=i):At(e,p,i,o)}let S=!1;const R=e._changedRowIdSet;if(R&&R.size>0)try{const t=e.getRowId?.(i);t&&(S=R.has(t))}catch{}S!==p.classList.contains("changed")&&p.classList.toggle("changed",S);const P=e.effectiveConfig?.rowClass;if(P){const t=p.getAttribute("data-dynamic-classes");if(t){const e=t.split(" ");for(let t=0;t<e.length;t++)e[t]&&p.classList.remove(e[t])}try{const e=P(i),t="string"==typeof e?e.split(/\s+/):e;if(t&&t.length>0){let e="";for(let o=0;o<t.length;o++){const n=t[o];n&&"string"==typeof n&&(p.classList.add(n),e+=(e?" ":"")+n)}p.setAttribute("data-dynamic-classes",e)}else p.removeAttribute("data-dynamic-classes")}catch(g){E("TBW060",`rowClass callback error: ${g}`,e.id),p.removeAttribute("data-dynamic-classes")}}if(u){const e=u(i,o);void 0!==e&&e>0?p.style.setProperty("--tbw-row-height",`${e}px`):p.style.removeProperty("--tbw-row-height")}h&&e._afterRowRender?.({row:i,rowIndex:o,rowElement:p}),p.parentNode!==s&&s.appendChild(p)}}(this,e,t,o,this.#Ce),this.#qe.size>0)for(const n of this.#qe)this.#Ke(n,!0)}#xt={rowCount:-1,colCount:-1,ariaLabel:void 0,ariaLabelledBy:void 0,ariaDescribedBy:void 0,ariaRoleDescription:void 0,lastAnnouncedSourceCount:-1};_updateAriaCounts(e,t){!function(e,t,o,n,r){if(n===e.rowCount&&r===e.colCount)return!1;const i=e.rowCount;e.rowCount=n,e.colCount=r,t&&(t.setAttribute("aria-rowcount",String(n)),t.setAttribute("aria-colcount",String(r))),n!==i&&o&&(n>0?o.setAttribute("role","rowgroup"):o.removeAttribute("role"))}(this.#xt,this.__rowsBodyEl,this._bodyEl,e,t)}_requestSchedulerPhase(e,t){this.#fe.requestPhase(e,t)}_getPluginRowHeight(e,t){return this.#xe?.getRowHeight?.(e,t)}_adjustPluginVirtualStart(e,t,o){return this.#xe?.adjustVirtualStart(e,t,o)}_afterPluginRender(){this.#xe?.afterRender()}_emitPluginEvent(e,t){this.#xe?.emitPluginEvent(e,t)}_schedulerMergeConfig(){this.#de.parseLightDomColumns(this),this.#de.merge(),this.#st(),function(e,t,o){const n=So,r=Ro,i=/* @__PURE__ */new Map;function s(e,t,o,n,r=!1){i.has(e)||i.set(e,{description:t,importHint:o,fields:[],isConfigProperty:r});const s=i.get(e);s.fields.includes(n)||s.fields.push(n)}const l=e.features;function a(e){return!!l&&!1===l[e]}for(const d of r){const o=e[d.property];if((d.isUsed?d.isUsed(o):void 0!==o)&&!xo(t,d.pluginName)&&!a(d.pluginName)){const e=d.description||`the "${d.property}" ${d.level} property`;s(d.pluginName,e,Eo(d.pluginName),d.property,!0)}}const c=e.columns;if(c&&c.length>0)for(const d of c)for(const e of n){const o=d[e.property];if((e.isUsed?e.isUsed(o):void 0!==o)&&!xo(t,e.pluginName)&&!a(e.pluginName)){const t=d.field||"<unknown>",o=e.description||`the "${e.property}" ${e.level} property`;s(e.pluginName,o,Eo(e.pluginName),t)}}if(i.size>0){const e=[];for(const[t,{description:o,importHint:n,fields:r,isConfigProperty:s}]of i)if(s)e.push(`Config uses ${o}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${n}\n plugins: [new ${Po(t)}Plugin(), ...]`);else{const i=r.slice(0,3).join(", ")+(r.length>3?`, ... (${r.length} total)`:"");e.push(`Column(s) [${i}] use ${o}, but the required plugin is not loaded.\n → Add the plugin to your gridConfig.plugins array:\n ${n}\n plugins: [new ${Po(t)}Plugin(), ...]`)}R([...i.values()].some(e=>e.isConfigProperty)?"TBW002":"TBW001",`Configuration error:\n\n${e.join("\n\n")}\n\nThis validation helps catch misconfigurations early. The properties listed above require their respective plugins to function.`,o)}}(this.#k,this.#xe?.getPlugins()??[],this.id),function(e,t){const o=[],n=[];for(const r of e){const e=r.constructor.manifest;if(e?.configRules)for(const t of e.configRules){const e=r.config;if(t.check(e)){const e=`[${Po(r.name)}Plugin] Configuration warning: ${t.message}`;"error"===t.severity?o.push(e):n.push(e)}}}if(n.length>0&&dt())for(const r of n)E("TBW004",r,t);o.length>0&&R("TBW003",`Configuration error:\n\n${o.join("\n\n")}`,t)}(this.#xe?.getPlugins()??[],this.id),function(e,t){if(!dt())return;const o=new Set(e.map(e=>e.name)),n=/* @__PURE__ */new Set;for(const r of e){const e=r.constructor.manifest;if(e?.incompatibleWith)for(const i of e.incompatibleWith)if(o.has(i.name)){const e=[r.name,i.name].sort().join("↔");if(n.has(e))continue;n.add(e),E("TBW022",`${Po(r.name)}Plugin and ${Po(i.name)}Plugin are both loaded, but they are currently incompatible.\n\n → ${i.reason}\n\n Consider removing one of these plugins to avoid unexpected behavior.`,t)}}}(this.#xe?.getPlugins()??[],this.id),this.#Nt(),this.#Ue=[...this._columns]}_schedulerProcessColumns(){this.#Dt()}_schedulerProcessRows(){this.#zt()}_schedulerRenderHeader(){ot(this)}_schedulerUpdateTemplate(){Ie(this)}_schedulerAfterRender(){this.#xe?.afterRender(),this.#Xe(),this._virtualization.enabled&&this._virtualization.totalHeightEl&&queueMicrotask(()=>{if(!this._virtualization.totalHeightEl)return;const e=this.#He.calculateTotalSpacerHeight(this._rows.length);this._virtualization.totalHeightEl.style.height=`${e}px`});"fixed"!==this.#k.fitMode||this.__didInitialAutoSize||(this.__didInitialAutoSize=!0,ke(this)),this._restoreFocusAfterRender&&(this._restoreFocusAfterRender=!1,Vt(this)),this._virtualization.enabled&&!this.#pt&&this.#Et(),this.#be&&(this.#be=!1,requestAnimationFrame(()=>{requestAnimationFrame(()=>{this.#_t()})})),this.#Ne&&this.#Ye()}get _schedulerIsConnected(){return this.isConnected&&this.#he}get _hostElement(){return this}get _renderRoot(){return this.#le}_emit(e,t){this.#Pt(e,t)}get _accordionIcons(){return{expand:this.#k?.icons?.expand??G.expand,collapse:this.#k?.icons?.collapse??G.collapse}}get _shellState(){return this.#ot}_clearRowPool(){const e=this.__frameworkAdapter,t=e?.releaseCell;if(t){e?.beginBatch?.(this);try{for(let o=0;o<this._rowPool.length;o++){const n=this._rowPool[o].children;for(let o=0;o<n.length;o++){const r=n[o];r.firstElementChild&&t.call(e,r)}}this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="")}finally{e?.endBatch?.(this)}}else this._rowPool.length=0,this._bodyEl&&(this._bodyEl.innerHTML="");this.__rowRenderEpoch++}_setup(){this.#bt()}_applyAnimationConfig(e){const t={...U,...e.animation},o=t.mode??"reduced-motion";let n=1;!1===o||"off"===o?n=0:!0!==o&&"on"!==o||(n=1),this.style.setProperty("--tbw-animation-duration",`${t.duration}ms`),this.style.setProperty("--tbw-animation-easing",t.easing??"ease-out"),this.style.setProperty("--tbw-animation-enabled",String(n)),this.dataset.animationMode="boolean"==typeof o?o?"on":"off":o}#Nt(){!function(e,t,o){if(!t)return!1;let n=!1;const r=o?.gridAriaLabelledBy,i=r?void 0:function(e){const t=e?.gridAriaLabel;return t||(e?.shell?.header?.title??void 0)}(o);r!==e.ariaLabelledBy&&(e.ariaLabelledBy=r,r?t.setAttribute("aria-labelledby",r):t.removeAttribute("aria-labelledby"),n=!0),i!==e.ariaLabel&&(e.ariaLabel=i,i?t.setAttribute("aria-label",i):t.removeAttribute("aria-label"),n=!0);const s=o?.gridAriaDescribedBy;s!==e.ariaDescribedBy&&(e.ariaDescribedBy=s,s?t.setAttribute("aria-describedby",s):t.removeAttribute("aria-describedby"),n=!0);const l=o?.gridAriaRoleDescription;l!==e.ariaRoleDescription&&(e.ariaRoleDescription=l,l?t.setAttribute("aria-roledescription",l):t.removeAttribute("aria-roledescription"),n=!0)}(this.#xt,this.__rowsBodyEl,this.#k)}#Ye(){const e=this.querySelector(".tbw-grid-root");var t;e&&(this.#Ne?(this.#$e||(this.#$e=function(e){const t=document.createElement("div");return t.className="tbw-loading-overlay",t.setAttribute("role","status"),t.setAttribute("aria-live","polite"),t.appendChild(eo("large",e)),t}(this.#k?.loadingRenderer)),function(e,t){e.appendChild(t)}(e,this.#$e)):(t=this.#$e,t?.remove()))}#Xe(){!function(e,t,o,n,r,i,s){if(!e)return;if(!function(e,t,o){return!(e||t>0||null===o)}(t,o,r))return ct(s.el),s.el=void 0,s.renderer=void 0,s.target=void 0,s.sourceRows=void 0,void(s.filteredOut=void 0);const l=n.length,a=l>0&&0===o;if(s.el&&s.renderer===r&&s.target===i&&s.sourceRows===n&&s.filteredOut===a)return;const c="grid"===i?e:e.querySelector(".rows-container")??e;ct(s.el),s.el=at({sourceRowCount:l,filteredOut:a},r??void 0,i),function(e,t){e.appendChild(t)}(c,s.el),s.renderer=r,s.target=i,s.sourceRows=n,s.filteredOut=a}(this.querySelector(".tbw-grid-root"),this.#Ne,this._rows.length,this.#ce,this.#k?.emptyRenderer,this.#k?.emptyOverlay??"rows",this.#We)}#Ke(e,t){this.#kt();const o=this.#Be.get(e);if(!o)return;const n=this.findRenderedRowElement?.(o.index);n&&to(n,t)}#Ze(e,t,o){this.#kt();const n=this.#Be.get(e);if(!n)return;const r=this.findRenderedRowElement?.(n.index);if(!r)return;const i=this._visibleColumns.findIndex(e=>e.field===t);if(i<0)return;const s=r.children[i];s&&function(e,t){t?(e.classList.add("tbw-cell-loading"),e.setAttribute("aria-busy","true")):(e.classList.remove("tbw-cell-loading"),e.removeAttribute("aria-busy"))}(s,o)}#bt(){if(this.isConnected&&this._headerRowEl&&this._bodyEl){if(this.#de.parseLightDomColumns(this),this.#q){const e=this.#q;this.#q=void 0,this.#de.merge();const t=this.#xe?.getAll()??[];this.#de.applyState(e,t)}this._bodyEl&&(this._bodyEl.style.display="",this._bodyEl.style.gridTemplateColumns=""),this.#fe.requestPhase(rt.FULL,"setup")}}#St(e){const t=this._virtualization.container,o=this.#De,n=o?.scrollLeft??0,r=t?.scrollHeight??0,i=o?.scrollWidth??0,s=t?.clientHeight??0,l=o?.clientWidth??0;if(this.refreshVirtualWindow(!1)&&this.#xe?.onScrollRender(),this._virtualization.variableHeights&&(this.#ve&&clearTimeout(this.#ve),this.#ve=window.setTimeout(()=>{this.#ve=0,this.#He.measureRenderedRowHeights(this._virtualization.start,this._virtualization.end)},100)),this.#me){const t=this.#Pe;t.scrollTop=e,t.scrollLeft=n,t.scrollHeight=r,t.scrollWidth=i,t.clientHeight=s,t.clientWidth=l,this.#xe?.onScroll(t)}this.#Pt("tbw-scroll",{scrollTop:e,scrollHeight:r,clientHeight:s,direction:"vertical"})}findHeaderRow(){return this.#le.querySelector(".header-row")}findRenderedRowElement(e){const t=this._virtualization,o=e-t.start;return o>=0&&o<this._rowPool.length&&o<t.end-t.start?this._rowPool[o]:null}_dispatchCellClick(e,t,o,n){const r=this._rows[t],i=this._visibleColumns[o];if(!r||!i)return!1;const s=i.field,l=r[s],a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,composed:!0,detail:{rowIndex:t,colIndex:o,column:i,field:s,value:l,row:r,cellEl:n,trigger:"pointer",originalEvent:e}});if(this.dispatchEvent(a),a.defaultPrevented)return!0;const c={row:r,rowIndex:t,colIndex:o,column:i,field:s,value:l,cellEl:n,originalEvent:e},d=this.#xe?.onCellClick(c)??!1;return this.#Pt("cell-click",c),d}_dispatchRowClick(e,t,o,n){if(!o)return!1;const r={rowIndex:t,row:o,rowEl:n,originalEvent:e},i=this.#xe?.onRowClick(r)??!1;return this.#Pt("row-click",r),i}_dispatchHeaderClick(e,t,o){if(!t)return!1;const n={colIndex:this._columns.indexOf(t),field:t.field,column:t,headerEl:o,originalEvent:e};return this.#xe?.onHeaderClick(n)??!1}_dispatchKeyDown(e){return this.#xe?.onKeyDown(e)??!1}_getHorizontalScrollOffsets(e,t){return this.#xe?.getHorizontalScrollOffsets(e,t)??{left:0,right:0}}query(e,t){return this.#xe?.queryPlugins({type:e,context:t})??[]}_dispatchCellMouseDown(e){return this.#xe?.onCellMouseDown(e)??!1}_dispatchCellMouseMove(e){this.#xe?.onCellMouseMove(e)}_dispatchCellMouseUp(e){this.#xe?.onCellMouseUp(e)}_afterCellRender(e){this.#xe?.afterCellRender(e)}_hasAfterCellRenderHook(){return this.#xe?.hasAfterCellRenderHook()??!1}_afterRowRender(e){this.#xe?.afterRowRender(e)}_hasAfterRowRenderHook(){return this.#xe?.hasAfterRowRenderHook()??!1}async ready(){return this.#C}async forceLayout(){return 0===this.#fe.pendingPhase&&this.#fe.requestPhase(rt.FULL,"forceLayout"),this.#fe.whenReady()}async getConfig(){return Object.freeze({...this.#k||{}})}getRowId(e){return co(e,this.id,this.#k.getRowId)}getRow(e){return this.#Le.getRow(e)}_getRowEntry(e){return this.#kt(),this.#Be.get(e)}updateRow(e,t,o="api"){this.#Le.updateRow(e,t,o)}updateRows(e,t="api"){this.#Le.updateRows(e,t)}animateRow(e,t){return lo(this,e,t)}animateRows(e,t){return function(e,t,o){return Promise.all(t.map(t=>lo(e,t,o))).then(e=>e.filter(Boolean).length)}(this,e,t)}animateRowById(e,t){return function(e,t,o){const n=e._rows??[],r=e.getRowId;if(!r)return Promise.resolve(!1);const i=n.findIndex(e=>{if(null==e)return!1;try{return r(e)===t}catch{return!1}});return i<0?Promise.resolve(!1):lo(e,i,o)}(this,e,t)}async insertRow(e,t,o=!0){return this.#Le.insertRow(e,t,o)}async removeRow(e,t=!0){return this.#Le.removeRow(e,t)}async applyTransaction(e,t=!0){return this.#Le.applyTransaction(e,t)}applyTransactionAsync(e){return this.#Le.applyTransactionAsync(e)}focusCell(e,t){this.#Me.focusCell(e,t)}get focusedCell(){return this.#Me.focusedCell}scrollToRow(e,t){this.#Me.scrollToRow(e,t)}scrollToRowById(e,t){this.#Me.scrollToRowById(e,t)}setColumnVisible(e,t){const o=this.#de.setColumnVisible(e,t);return o&&this.requestStateChange(),o}toggleColumnVisibility(e){const t=this.#de.toggleColumnVisibility(e);return t&&this.requestStateChange(),t}isColumnVisible(e){return this.#de.isColumnVisible(e)}showAllColumns(){this.#de.showAllColumns(),this.requestStateChange()}getAllColumns(){return this.#de.getAllColumns()}setColumnOrder(e){this.#de.setColumnOrder(e),this.requestStateChange()}getColumnOrder(){return this.#de.getColumnOrder()}getColumnState(){const e=this.#xe?.getAll()??[];return this.#de.collectState(e)}get columnState(){return this.getColumnState()}applyColumnState(e){e&&(this.#ae?this.#qt(e):(this.#q=e,this.#de.initialColumnState=e))}#qt(e){const t=this._columns,o=this._sortState,n=this.#xe?.getAll()??[];this.#de.applyState(e,n);if(!e.columns.some(e=>void 0!==e.sort)&&this.#Ft(t,o))return this.#Ge=void 0,Ie(this),void this.#fe.requestPhase(rt.STYLE,"column-width");this.#bt()}#Ft(e,t){const o=this._columns,n=this._sortState;if(t?.field!==n?.field||t?.direction!==n?.direction)return!1;if(e.length!==o.length)return!1;for(let r=0;r<e.length;r++){const t=e[r],n=o[r];if(t.field!==n.field)return!1;if(!!t.hidden!=!!n.hidden)return!1}return!0}get sortModel(){return this._sortState?{field:this._sortState.field,direction:1===this._sortState.direction?"asc":"desc"}:null}sort(e,t){if(null===e){if(!this._sortState)return;const e=this._sortState.field;this._sortState=null,this.__rowRenderEpoch++;for(let t=0;t<this._rowPool.length;t++)this._rowPool[t].__epoch=-1;return this._rows=this.__originalOrder.slice(),this.__originalOrder=[],ot(this),this.refreshVirtualWindow(!0),this.dispatchEvent(new CustomEvent("sort-change",{detail:{field:e,direction:0}})),this._pluginManager?.emitPluginEvent?.("sort-change",{field:e,direction:0}),void this.requestStateChange?.()}const o=this._columns.find(t=>t.field===e);o&&(t?(this._sortState||(this.__originalOrder=this._rows.slice()),Ke(this,o,"desc"===t?-1:1)):Xe(this,o))}requestStateChange(){const e=this.#xe?.getAll()??[];this.#de.requestStateChange(e)}resetColumnState(){this.#q=void 0,this.__originalOrder=[];const e=this.#xe?.getAll()??[];this.#de.resetState(e),this.#de.merge(),this.#bt()}get isToolPanelOpen(){return this.#tt("isToolPanelOpen"),this.#Je().isToolPanelOpen}get defaultRowHeight(){return this._virtualization.rowHeight}get expandedToolPanelSections(){return this.#tt("expandedToolPanelSections"),this.#Je().expandedToolPanelSections}openToolPanel(e){this.#tt("openToolPanel()"),this.#Je().openToolPanel(e)}closeToolPanel(){this.#tt("closeToolPanel()"),this.#Je().closeToolPanel()}toggleToolPanel(){this.#tt("toggleToolPanel()"),this.#Je().toggleToolPanel()}toggleToolPanelSection(e){this.#tt("toggleToolPanelSection()"),this.#Je().toggleToolPanelSection(e)}getToolPanels(){return this.#tt("getToolPanels()"),this.#Je().getToolPanels()}registerToolPanel(e){this.#tt("registerToolPanel()"),this.#Je().registerToolPanel(e)}unregisterToolPanel(e){this.#tt("unregisterToolPanel()"),this.#Je().unregisterToolPanel(e)}getHeaderContents(){return this.#tt("getHeaderContents()"),this.#Je().getHeaderContents()}registerHeaderContent(e){this.#tt("registerHeaderContent()"),this.#Je().registerHeaderContent(e)}unregisterHeaderContent(e){this.#tt("unregisterHeaderContent()"),this.#Je().unregisterHeaderContent(e)}getToolbarContents(){return this.#tt("getToolbarContents()"),this.#Je().getToolbarContents()}registerToolbarContent(e){this.#tt("registerToolbarContent()"),this.#Je().registerToolbarContent(e)}unregisterToolbarContent(e){this.#tt("unregisterToolbarContent()"),this.#Je().unregisterToolbarContent(e)}#$t=!1;refreshShellHeader(){this.#$t||(this.#$t=!0,queueMicrotask(()=>{this.#$t=!1,this.isConnected&&(this.#h(),this.#de.markSourcesChanged(),this.#de.merge(),this.#Je()._prepareForRerender(),this.#xe?.afterStructuralRender(),this.#Wt())}))}#Wt(){const e=this.#le.querySelector(".tbw-grid-content")??this.#le.querySelector(".tbw-grid-root");this._headerRowEl=e?.querySelector(".header-row"),this._virtualization.totalHeightEl=e?.querySelector(".faux-vscroll-spacer"),this._virtualization.viewportEl=e?.querySelector(".rows-viewport"),this._bodyEl=e?.querySelector(".rows"),this.__rowsBodyEl=e?.querySelector(".rows-body"),this._resizeController=oo(this),this.#ct(e),this.#fe.requestPhase(rt.COLUMNS,"shellRefresh")}#mt=/* @__PURE__ */new Map;registerStyles(e,t){let o=this.#mt.get(e);o||(o=new CSSStyleSheet,this.#mt.set(e,o)),o.replaceSync(t),this.#Bt()}unregisterStyles(e){this.#mt.delete(e)&&this.#Bt()}getRegisteredStyles(){return Array.from(this.#mt.keys())}#Bt(){const e=Array.from(this.#mt.values()),t=document.adoptedStyleSheets.filter(e=>!Array.from(this.#mt.values()).includes(e));document.adoptedStyleSheets=[...t,...e]}registerExternalFocusContainer(e){this.#Me.registerExternalFocusContainer(e)}unregisterExternalFocusContainer(e){this.#Me.unregisterExternalFocusContainer(e)}containsFocus(e){return this.#Me.containsFocus(e)}get lastFocusedElement(){return this.#Me.lastFocusedElement}restoreLastFocus(){return this.#Me.restoreLastFocus()}#h(){this.#Je()._parseLightDomAll(this)}#Vt(){this.#le.querySelector(".tbw-shell-header")&&(this.#Je()._prepareForRerender(),this.#xe?.afterStructuralRender())}#ft(){const e=()=>{this.__lightDomColumnsCache=void 0,this.#bt()};this.#de.registerLightDomHandler("tbw-grid-column",e),this.#de.registerLightDomHandler("tbw-grid-detail",e),this.#de.observeLightDOM(this)}refreshColumns(){this.__lightDomColumnsCache=void 0,xt(this),this.#de.parseLightDomColumns(this);const e=this.#ot.lightDomTitle,t=this.#ot.hasToolButtonsContainer;this.#h();const o=this.#ot.lightDomTitle,n=this.#ot.hasToolButtonsContainer;(o&&!e||n&&!t)&&(this.#de.markSourcesChanged(),this.#de.merge(),this.#Vt()),this.#fe.requestPhase(rt.COLUMNS,"refreshColumns")}#Rt(){this.#He.updateCachedGeometry()}refreshVirtualWindow(e=!1,t=!1){return this.#He.refreshVirtualWindow(e,t)}invalidateRowHeight(e,t){this.#He.invalidateRowHeight(e,t)}#ut(){this.#h(),this.#de.markSourcesChanged(),this.#de.merge(),function(e){const t=[];for(let o=e.firstChild;o;o=o.nextSibling)1===o.nodeType&&o.classList.contains(X.ROOT)||t.push(o);e.replaceChildren();for(const o of t)e.appendChild(o);e.appendChild(ie({hasShell:!1}))}(this.#le),this.#xe?.afterStructuralRender()}}!function(){const e=Ho.tagName,t=customElements.get(e);if(!t)return customElements.define(e,Ho),void(Ho.activeTag=e);if(t.version===Ho.version)return void(Ho.activeTag=e);const o=`${e}-v${Ho.version.replace(/[^a-zA-Z0-9]+/g,"-").toLowerCase()}`;customElements.get(o)||customElements.define(o,Ho),Ho.activeTag=o}(),globalThis.DataGridElement||(globalThis.DataGridElement=Ho);const Mo=["canHandle","createRenderer","createEditor","processConfig","getTypeDefault","createToolPanelRenderer","parseDetailElement","parseResponsiveCardElement","releaseCell","unmount","beginBatch","endBatch"];function Lo(e){const t=document.createElement(Ho.activeTag);return e&&(t.gridConfig=e),t}function ko(e,t,o){let n=document,r=!1;return"boolean"==typeof t?r=t:t&&(n=t,r=!!o),r?customElements.whenDefined(Ho.activeTag).then(()=>n.querySelector(e)):n.querySelector(e)}const Oo={CELL_CHANGE:"cell-change",CELL_COMMIT:"cell-commit",ROW_COMMIT:"row-commit",EDIT_OPEN:"edit-open",EDIT_CLOSE:"edit-close",CHANGED_ROWS_RESET:"changed-rows-reset",MOUNT_EXTERNAL_VIEW:"mount-external-view",MOUNT_EXTERNAL_EDITOR:"mount-external-editor",SORT_CHANGE:"sort-change",COLUMN_RESIZE:"column-resize",CELL_ACTIVATE:"cell-activate",GROUP_TOGGLE:"group-toggle",COLUMN_STATE_CHANGE:"column-state-change",DATA_CHANGE:"data-change",TBW_SCROLL:"tbw-scroll"},Do={SELECTION_CHANGE:"selection-change",TREE_EXPAND:"tree-expand",TREE_LOAD_START:"tree-load-start",TREE_LOAD_END:"tree-load-end",TREE_LOAD_ERROR:"tree-load-error",FILTER_CHANGE:"filter-change",SORT_MODEL_CHANGE:"sort-model-change",EXPORT_START:"export-start",EXPORT_COMPLETE:"export-complete",CLIPBOARD_COPY:"clipboard-copy",CLIPBOARD_PASTE:"clipboard-paste",CONTEXT_MENU_OPEN:"context-menu-open",CONTEXT_MENU_CLOSE:"context-menu-close",HISTORY_CHANGE:"history-change",SERVER_LOADING:"server-loading",SERVER_ERROR:"server-error",COLUMN_VISIBILITY_CHANGE:"column-visibility-change",COLUMN_REORDER:"column-reorder",DETAIL_EXPAND:"detail-expand",GROUP_EXPAND:"group-expand"};function Io(e,t,o){return o?.valueAccessor?Ne(e,o):e?.[t]}function zo(e){return null==e||""===e||"number"==typeof e&&isNaN(e)}const No={sum:(e,t,o)=>{let n=0;for(let r=0;r<e.length;r++){const i=Io(e[r],t,o);if(zo(i))continue;const s=Number(i);isNaN(s)||(n+=s)}return n},avg:(e,t,o)=>{if(!e.length)return 0;let n=0,r=0;for(let i=0;i<e.length;i++){const s=Io(e[i],t,o);if(zo(s))continue;const l=Number(s);isNaN(l)||(n+=l,r++)}return r>0?n/r:0},count:e=>e.length,min:(e,t,o)=>{if(!e.length)return 0;let n=1/0;for(let r=0;r<e.length;r++){const i=Io(e[r],t,o);if(zo(i))continue;const s=Number(i);isNaN(s)||s<n&&(n=s)}return n===1/0?0:n},max:(e,t,o)=>{if(!e.length)return 0;let n=-1/0;for(let r=0;r<e.length;r++){const i=Io(e[r],t,o);if(zo(i))continue;const s=Number(i);isNaN(s)||s>n&&(n=s)}return n===-1/0?0:n},first:(e,t,o)=>e[0]?Io(e[0],t,o):void 0,last:(e,t,o)=>e.length?Io(e[e.length-1],t,o):void 0},qo=/* @__PURE__ */new Map,Fo={register(e,t){qo.set(e,t)},unregister(e){qo.delete(e)},get(e){if(void 0!==e)return"function"==typeof e?e:qo.get(e)??No[e]},run(e,t,o,n){const r=this.get(e);return r?r(t,o,n):void 0},has:e=>qo.has(e)||e in No,list:()=>[...Object.keys(No),...qo.keys()]},$o={sum:e=>{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t},avg:e=>{if(!e.length)return 0;let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length},count:e=>e.length,min:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]<t&&(t=e[o]);return t},max:e=>{if(!e.length)return 0;let t=e[0];for(let o=1;o<e.length;o++)e[o]>t&&(t=e[o]);return t},first:e=>e[0]??0,last:e=>e[e.length-1]??0};function Wo(e){return $o[e]??$o.sum}function Bo(e,t){return Wo(e)(t)}export{Y as BaseGridPlugin,g as C,Mo as CORE_CONSUMED_ADAPTER_METHODS,v as D,V as DEFAULT_A11Y_MESSAGES,U as DEFAULT_ANIMATION_CONFIG,G as DEFAULT_GRID_ICONS,Oo as DGEvents,Ho as DataGridElement,a as E,Ct as F,B as FitModeEnum,Q as GridCSSVars,X as GridClasses,K as GridDataAttrs,Ho as GridElement,Z as GridSelectors,f as M,It as MAX_ELEMENT_HEIGHT_PX,w as N,u as P,Do as PluginEvents,To as PluginManager,rt as RenderPhase,p as T,Te as a,Fo as aggregatorRegistry,$t as b,$e as builtInSort,Ft as c,zt as computeScrollMapping,Lo as createGrid,R as d,Fe as defaultComparator,Vt as e,ut as f,qt as fromVirtualScrollTop,He as g,Wo as getValueAggregator,m as h,b as i,qe as invalidateAccessorCache,to as j,q as k,pt as l,c as m,d as n,x as o,h as p,gt as q,ko as queryGrid,mt as r,Ne as resolveCellValue,Bo as runValueAggregator,z as s,Kt as setFeatureResolver,j as t,Nt as toVirtualScrollTop,ft as u,P as v,E as w,y as x,C as y,_ as z};//# sourceMappingURL=index.js.map