wandertable 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +505 -0
  3. package/dist/style.css +1 -0
  4. package/dist/types/WanderTable.d.ts +112 -0
  5. package/dist/types/WanderTable.d.ts.map +1 -0
  6. package/dist/types/__tests__/ColumnModel.test.d.ts +2 -0
  7. package/dist/types/__tests__/ColumnModel.test.d.ts.map +1 -0
  8. package/dist/types/__tests__/CommandBus.test.d.ts +2 -0
  9. package/dist/types/__tests__/CommandBus.test.d.ts.map +1 -0
  10. package/dist/types/__tests__/DataModel.test.d.ts +2 -0
  11. package/dist/types/__tests__/DataModel.test.d.ts.map +1 -0
  12. package/dist/types/__tests__/Export.test.d.ts +2 -0
  13. package/dist/types/__tests__/Export.test.d.ts.map +1 -0
  14. package/dist/types/__tests__/GroupedHeaders.test.d.ts +2 -0
  15. package/dist/types/__tests__/GroupedHeaders.test.d.ts.map +1 -0
  16. package/dist/types/__tests__/MergeModel.test.d.ts +2 -0
  17. package/dist/types/__tests__/MergeModel.test.d.ts.map +1 -0
  18. package/dist/types/__tests__/SelectionModel.test.d.ts +2 -0
  19. package/dist/types/__tests__/SelectionModel.test.d.ts.map +1 -0
  20. package/dist/types/__tests__/ViewMapping.test.d.ts +2 -0
  21. package/dist/types/__tests__/ViewMapping.test.d.ts.map +1 -0
  22. package/dist/types/columns/ColumnModel.d.ts +25 -0
  23. package/dist/types/columns/ColumnModel.d.ts.map +1 -0
  24. package/dist/types/columns/GroupedHeaders.d.ts +20 -0
  25. package/dist/types/columns/GroupedHeaders.d.ts.map +1 -0
  26. package/dist/types/core/CommandBus.d.ts +63 -0
  27. package/dist/types/core/CommandBus.d.ts.map +1 -0
  28. package/dist/types/core/DataModel.d.ts +27 -0
  29. package/dist/types/core/DataModel.d.ts.map +1 -0
  30. package/dist/types/core/EventEmitter.d.ts +10 -0
  31. package/dist/types/core/EventEmitter.d.ts.map +1 -0
  32. package/dist/types/core/MergeModel.d.ts +35 -0
  33. package/dist/types/core/MergeModel.d.ts.map +1 -0
  34. package/dist/types/core/PaginationModel.d.ts +24 -0
  35. package/dist/types/core/PaginationModel.d.ts.map +1 -0
  36. package/dist/types/core/RowGroupModel.d.ts +36 -0
  37. package/dist/types/core/RowGroupModel.d.ts.map +1 -0
  38. package/dist/types/core/SelectionModel.d.ts +47 -0
  39. package/dist/types/core/SelectionModel.d.ts.map +1 -0
  40. package/dist/types/core/ViewMapping.d.ts +37 -0
  41. package/dist/types/core/ViewMapping.d.ts.map +1 -0
  42. package/dist/types/core/ViewportModel.d.ts +9 -0
  43. package/dist/types/core/ViewportModel.d.ts.map +1 -0
  44. package/dist/types/editors/BlankEditor.d.ts +20 -0
  45. package/dist/types/editors/BlankEditor.d.ts.map +1 -0
  46. package/dist/types/editors/DropdownEditor.d.ts +23 -0
  47. package/dist/types/editors/DropdownEditor.d.ts.map +1 -0
  48. package/dist/types/editors/EditorManager.d.ts +22 -0
  49. package/dist/types/editors/EditorManager.d.ts.map +1 -0
  50. package/dist/types/index.d.ts +35 -0
  51. package/dist/types/index.d.ts.map +1 -0
  52. package/dist/types/interaction/ClipboardManager.d.ts +19 -0
  53. package/dist/types/interaction/ClipboardManager.d.ts.map +1 -0
  54. package/dist/types/interaction/ColumnReorder.d.ts +20 -0
  55. package/dist/types/interaction/ColumnReorder.d.ts.map +1 -0
  56. package/dist/types/interaction/ColumnResize.d.ts +15 -0
  57. package/dist/types/interaction/ColumnResize.d.ts.map +1 -0
  58. package/dist/types/interaction/FillHandle.d.ts +39 -0
  59. package/dist/types/interaction/FillHandle.d.ts.map +1 -0
  60. package/dist/types/interaction/KeyboardNav.d.ts +19 -0
  61. package/dist/types/interaction/KeyboardNav.d.ts.map +1 -0
  62. package/dist/types/interaction/RowResize.d.ts +15 -0
  63. package/dist/types/interaction/RowResize.d.ts.map +1 -0
  64. package/dist/types/plugins/ContextMenu.d.ts +44 -0
  65. package/dist/types/plugins/ContextMenu.d.ts.map +1 -0
  66. package/dist/types/plugins/Export.d.ts +16 -0
  67. package/dist/types/plugins/Export.d.ts.map +1 -0
  68. package/dist/types/render/AutoFit.d.ts +23 -0
  69. package/dist/types/render/AutoFit.d.ts.map +1 -0
  70. package/dist/types/render/DOMRenderer.d.ts +91 -0
  71. package/dist/types/render/DOMRenderer.d.ts.map +1 -0
  72. package/dist/types/render/LoadingOverlay.d.ts +9 -0
  73. package/dist/types/render/LoadingOverlay.d.ts.map +1 -0
  74. package/dist/types/render/PaginationBar.d.ts +20 -0
  75. package/dist/types/render/PaginationBar.d.ts.map +1 -0
  76. package/dist/types/renderers/BadgeRenderer.d.ts +5 -0
  77. package/dist/types/renderers/BadgeRenderer.d.ts.map +1 -0
  78. package/dist/types/renderers/BlankRenderer.d.ts +9 -0
  79. package/dist/types/renderers/BlankRenderer.d.ts.map +1 -0
  80. package/dist/types/renderers/CheckboxRenderer.d.ts +5 -0
  81. package/dist/types/renderers/CheckboxRenderer.d.ts.map +1 -0
  82. package/dist/types/renderers/NumberRenderer.d.ts +7 -0
  83. package/dist/types/renderers/NumberRenderer.d.ts.map +1 -0
  84. package/dist/types/renderers/ProgressRenderer.d.ts +5 -0
  85. package/dist/types/renderers/ProgressRenderer.d.ts.map +1 -0
  86. package/dist/types/renderers/RendererRegistry.d.ts +10 -0
  87. package/dist/types/renderers/RendererRegistry.d.ts.map +1 -0
  88. package/dist/types/renderers/TextRenderer.d.ts +5 -0
  89. package/dist/types/renderers/TextRenderer.d.ts.map +1 -0
  90. package/dist/types/rows/RowModel.d.ts +20 -0
  91. package/dist/types/rows/RowModel.d.ts.map +1 -0
  92. package/dist/types/themes.d.ts +5 -0
  93. package/dist/types/themes.d.ts.map +1 -0
  94. package/dist/types/types/index.d.ts +348 -0
  95. package/dist/types/types/index.d.ts.map +1 -0
  96. package/dist/wandertable.cjs +14 -0
  97. package/dist/wandertable.cjs.map +1 -0
  98. package/dist/wandertable.global.js +14 -0
  99. package/dist/wandertable.global.js.map +1 -0
  100. package/dist/wandertable.js +2757 -0
  101. package/dist/wandertable.js.map +1 -0
  102. package/dist/wandertable.umd.js +14 -0
  103. package/dist/wandertable.umd.js.map +1 -0
  104. package/package.json +36 -0
@@ -0,0 +1,348 @@
1
+ export type CellKey = `${number}:${number}`;
2
+ export interface CellStyle {
3
+ bgColor?: string;
4
+ textColor?: string;
5
+ fontWeight?: 'normal' | 'bold';
6
+ fontStyle?: 'normal' | 'italic';
7
+ textAlign?: 'left' | 'center' | 'right';
8
+ borderLeft?: string;
9
+ borderRight?: string;
10
+ borderTop?: string;
11
+ borderBottom?: string;
12
+ padding?: number;
13
+ }
14
+ export interface CellData {
15
+ value: unknown;
16
+ meta?: Record<string, unknown>;
17
+ type?: string;
18
+ readOnly?: boolean;
19
+ className?: string;
20
+ style?: CellStyle;
21
+ }
22
+ export interface CellPatch {
23
+ row: number;
24
+ col: number;
25
+ data: Partial<CellData>;
26
+ }
27
+ export interface CellState {
28
+ selected: boolean;
29
+ focused: boolean;
30
+ editing: boolean;
31
+ hover: boolean;
32
+ }
33
+ export interface CellBounds {
34
+ x: number;
35
+ y: number;
36
+ width: number;
37
+ height: number;
38
+ }
39
+ export interface SelectionRange {
40
+ startRow: number;
41
+ startCol: number;
42
+ endRow: number;
43
+ endCol: number;
44
+ }
45
+ export interface CellAddress {
46
+ row: number;
47
+ col: number;
48
+ }
49
+ export interface SelectionInfo {
50
+ /** Currently focused cell */
51
+ focus: CellAddress | null;
52
+ /** All selection ranges */
53
+ ranges: SelectionRange[];
54
+ /** Normalized bounding box (min/max) across all ranges */
55
+ bounds: {
56
+ startRow: number;
57
+ startCol: number;
58
+ endRow: number;
59
+ endCol: number;
60
+ } | null;
61
+ /** Total number of cells in the selection */
62
+ cellCount: number;
63
+ /** Number of ranges (1 = single range, >1 = multi-select with Ctrl) */
64
+ rangeCount: number;
65
+ /** Whether more than one cell is selected */
66
+ isMultiCell: boolean;
67
+ /** Whether the selection spans an entire row (all columns) */
68
+ isFullRow: boolean;
69
+ /** Whether the selection spans an entire column (all rows) */
70
+ isFullCol: boolean;
71
+ /** Whether everything is selected */
72
+ isAll: boolean;
73
+ /** Whether nothing is selected */
74
+ isEmpty: boolean;
75
+ /** Number of rows spanned */
76
+ rowSpan: number;
77
+ /** Number of columns spanned */
78
+ colSpan: number;
79
+ }
80
+ export interface DropdownOption {
81
+ value: unknown;
82
+ label: string;
83
+ icon?: string;
84
+ disabled?: boolean;
85
+ group?: string;
86
+ }
87
+ export interface DropdownConfig {
88
+ options?: DropdownOption[];
89
+ source?: (query: string, row: number, col: number) => Promise<DropdownOption[]>;
90
+ multiple?: boolean;
91
+ searchable?: boolean;
92
+ placeholder?: string;
93
+ renderOption?: (option: DropdownOption, el: HTMLElement) => void;
94
+ }
95
+ export interface ColumnConfig {
96
+ key?: string;
97
+ label?: string;
98
+ width?: number;
99
+ minWidth?: number;
100
+ maxWidth?: number;
101
+ type?: string;
102
+ editor?: string;
103
+ readOnly?: boolean;
104
+ sortable?: boolean;
105
+ filterable?: boolean;
106
+ dropdown?: DropdownConfig;
107
+ align?: 'left' | 'center' | 'right';
108
+ frozen?: boolean;
109
+ /** Grouped/nested columns (table mode). Creates a multi-level header. */
110
+ children?: ColumnConfig[];
111
+ }
112
+ export interface RowConfig {
113
+ height?: number;
114
+ readOnly?: boolean;
115
+ className?: string;
116
+ }
117
+ export interface Viewport {
118
+ startRow: number;
119
+ endRow: number;
120
+ startCol: number;
121
+ endCol: number;
122
+ scrollX: number;
123
+ scrollY: number;
124
+ }
125
+ export interface ThemeConfig {
126
+ bgColor?: string;
127
+ cellBgColor?: string;
128
+ cellTextColor?: string;
129
+ headerBgColor?: string;
130
+ headerTextColor?: string;
131
+ gridLineColor?: string;
132
+ selectionBgColor?: string;
133
+ selectionBorderColor?: string;
134
+ focusBorderColor?: string;
135
+ fontFamily?: string;
136
+ fontSize?: number;
137
+ headerFontSize?: number;
138
+ cellPadding?: number;
139
+ headerHeight?: number;
140
+ rowHeaderWidth?: number;
141
+ }
142
+ export interface CellRenderer {
143
+ render(cell: HTMLElement, data: CellData | undefined, state: CellState): void;
144
+ cleanup?(cell: HTMLElement): void;
145
+ }
146
+ export interface CellEditor {
147
+ createElement(container: HTMLElement): HTMLElement;
148
+ open(value: unknown, bounds: CellBounds, cellData: CellData | undefined): void;
149
+ getValue(): unknown;
150
+ close(): void;
151
+ validate?(value: unknown): boolean | string;
152
+ }
153
+ export interface CommandChangeEvent {
154
+ row: number;
155
+ col: number;
156
+ oldValue: unknown;
157
+ newValue: unknown;
158
+ }
159
+ export interface WanderTableEvents {
160
+ 'cell:change': {
161
+ row: number;
162
+ col: number;
163
+ oldValue: unknown;
164
+ newValue: unknown;
165
+ };
166
+ 'cell:click': {
167
+ row: number;
168
+ col: number;
169
+ event: MouseEvent;
170
+ };
171
+ 'cell:dblclick': {
172
+ row: number;
173
+ col: number;
174
+ event: MouseEvent;
175
+ };
176
+ 'cell:contextmenu': {
177
+ row: number;
178
+ col: number;
179
+ event: MouseEvent;
180
+ };
181
+ 'selection:change': {
182
+ ranges: SelectionRange[];
183
+ };
184
+ 'editor:open': {
185
+ row: number;
186
+ col: number;
187
+ };
188
+ 'editor:close': {
189
+ row: number;
190
+ col: number;
191
+ value: unknown;
192
+ cancelled: boolean;
193
+ };
194
+ 'scroll': {
195
+ viewport: Viewport;
196
+ };
197
+ 'column:resize': {
198
+ col: number;
199
+ width: number;
200
+ };
201
+ 'row:resize': {
202
+ row: number;
203
+ height: number;
204
+ };
205
+ 'data:patch': {
206
+ patches: CellPatch[];
207
+ };
208
+ /** Fired after any command executes (edit, paste, delete, etc.) */
209
+ 'command:execute': {
210
+ changes: CommandChangeEvent[];
211
+ };
212
+ /** Fired after an undo - changes show what was RESTORED (old -> new is the undo direction) */
213
+ 'command:undo': {
214
+ changes: CommandChangeEvent[];
215
+ };
216
+ /** Fired after a redo - changes show what was RE-APPLIED */
217
+ 'command:redo': {
218
+ changes: CommandChangeEvent[];
219
+ };
220
+ }
221
+ export interface PaginationConfig {
222
+ /** Enable pagination */
223
+ enabled: boolean;
224
+ /** Rows per page */
225
+ pageSize: number;
226
+ /** Current page (0-based) */
227
+ page?: number;
228
+ /** Total rows (for server-side pagination - if set, overrides data.rowCount) */
229
+ totalRows?: number;
230
+ }
231
+ export interface PaginationState {
232
+ page: number;
233
+ pageSize: number;
234
+ totalRows: number;
235
+ totalPages: number;
236
+ startRow: number;
237
+ endRow: number;
238
+ }
239
+ export interface WanderTableOptions {
240
+ /** 'spreadsheet' = independent cells (default), 'table' = column-driven rows */
241
+ mode?: 'spreadsheet' | 'table';
242
+ data?: CellPatch[];
243
+ /** Table mode: array of row objects keyed by column.key */
244
+ tableData?: Record<string, unknown>[];
245
+ columns?: ColumnConfig[];
246
+ rowCount?: number;
247
+ colCount?: number;
248
+ defaultRowHeight?: number;
249
+ defaultColWidth?: number;
250
+ readOnly?: boolean;
251
+ showRowHeaders?: boolean;
252
+ showColHeaders?: boolean;
253
+ frozenRows?: number;
254
+ frozenCols?: number;
255
+ /** Allow column resize by dragging header edge. Default: true */
256
+ allowColResize?: boolean;
257
+ /** Allow row resize by dragging row header edge. Default: true */
258
+ allowRowResize?: boolean;
259
+ /** Allow multi-cell selection. Default: true */
260
+ allowRangeSelection?: boolean;
261
+ /** Allow editing cells (double click / typing). Default: true */
262
+ allowEditing?: boolean;
263
+ /** Allow clipboard operations (copy/paste/cut). Default: true */
264
+ allowClipboard?: boolean;
265
+ /** Allow context menu on right-click. Default: true */
266
+ allowContextMenu?: boolean;
267
+ /** Allow keyboard navigation. Default: true */
268
+ allowKeyboardNav?: boolean;
269
+ /** Allow cell selection at all. Default: true */
270
+ allowSelection?: boolean;
271
+ /** Enable undo/redo. Default: true */
272
+ allowUndoRedo?: boolean;
273
+ /** Show fill handle on selection for drag-to-fill. Default: true */
274
+ allowFillHandle?: boolean;
275
+ /** Allow column reorder by dragging headers. Default: false */
276
+ allowColReorder?: boolean;
277
+ /** Initial row groups for expand/collapse */
278
+ rowGroups?: {
279
+ startRow: number;
280
+ count: number;
281
+ label?: string;
282
+ expanded?: boolean;
283
+ depth?: number;
284
+ }[];
285
+ /** Called when scroll reaches near the end - for lazy loading more data */
286
+ onLoadMore?: (direction: 'down' | 'right') => void;
287
+ /** Automatically fit row height to cell content after render. Default: false */
288
+ autoRowHeight?: boolean;
289
+ /** Show grid lines between cells. Default: true */
290
+ showGridLines?: boolean;
291
+ /** Show border around the grid. Default: true */
292
+ showBorder?: boolean;
293
+ /** Auto-expand grid when navigating/editing beyond current bounds. Default: false */
294
+ infinite?: boolean;
295
+ /**
296
+ * 'scroll' (default): fixed height container with internal scroll + virtualization.
297
+ * 'auto': grid grows to fit all content, scroll is on the page. No virtualization.
298
+ */
299
+ layout?: 'scroll' | 'auto';
300
+ undoLimit?: number;
301
+ /** Renderer used for cells without data or without a type. Default: 'text' */
302
+ defaultCellType?: string;
303
+ /** Initial merged cell ranges */
304
+ merges?: {
305
+ row: number;
306
+ col: number;
307
+ rowSpan: number;
308
+ colSpan: number;
309
+ }[];
310
+ /** Initial sort */
311
+ sort?: {
312
+ col: number;
313
+ direction: 'asc' | 'desc';
314
+ };
315
+ /** Initial filters: key is column index */
316
+ filters?: Record<number, (row: number, data: any) => boolean>;
317
+ /** Pagination config */
318
+ pagination?: PaginationConfig;
319
+ /** Loading state - shows overlay */
320
+ loading?: boolean;
321
+ theme?: Partial<ThemeConfig>;
322
+ onCellChange?: (row: number, col: number, oldValue: unknown, newValue: unknown) => void;
323
+ onSelectionChange?: (ranges: SelectionRange[]) => void;
324
+ onScroll?: (viewport: Viewport) => void;
325
+ onContextMenu?: (row: number, col: number, event: MouseEvent) => void;
326
+ /**
327
+ * External sort callback. If set, sorting is NOT done internally -
328
+ * the callback is responsible for re-supplying data in the correct order.
329
+ * Return true to indicate the sort was handled externally.
330
+ */
331
+ onSort?: (col: number, direction: 'asc' | 'desc' | null, key?: string) => boolean | void;
332
+ /**
333
+ * External filter callback. If set, filtering is NOT done internally.
334
+ * Return true to indicate the filter was handled externally.
335
+ */
336
+ onFilter?: (col: number, key: string | undefined, active: boolean) => boolean | void;
337
+ /**
338
+ * Fill handle callback. Called when user drags the fill handle.
339
+ * Receives the source range (what was selected) and the fill range (where it's being filled).
340
+ * Return a CellPatch[] to apply custom values, or true to cancel default fill behavior.
341
+ * Return void/false to use default fill (repeat pattern).
342
+ */
343
+ onFill?: (source: SelectionRange, fill: SelectionRange, direction: 'down' | 'up' | 'right' | 'left' | 'diagonal') => CellPatch[] | boolean | void;
344
+ /** Called when page changes (pagination) */
345
+ onPageChange?: (page: number, pageSize: number) => void;
346
+ }
347
+ export declare const DEFAULT_THEME: ThemeConfig;
348
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,OAAO,GAAG,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IAC/B,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO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t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const pe={bgColor:"#ffffff",cellBgColor:"#ffffff",cellTextColor:"#1e293b",headerBgColor:"#f8fafc",headerTextColor:"#475569",gridLineColor:"#e2e8f0",selectionBgColor:"rgba(59, 130, 246, 0.08)",selectionBorderColor:"#3b82f6",focusBorderColor:"#3b82f6",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:13,headerFontSize:12,cellPadding:8,headerHeight:28,rowHeaderWidth:50};class O{constructor(t,e){n(this,"cells",new Map);n(this,"_rowCount");n(this,"_colCount");n(this,"_inTransaction",!1);n(this,"_dirtyKeys",new Set);n(this,"onChange",null);this._rowCount=t,this._colCount=e}get rowCount(){return this._rowCount}set rowCount(t){this._rowCount=t}get colCount(){return this._colCount}set colCount(t){this._colCount=t}key(t,e){return`${t}:${e}`}getCell(t,e){return this.cells.get(this.key(t,e))}setCell(t,e,s){const i=this.key(t,e);this.cells.set(i,s),this.markDirty(i)}setCellValue(t,e,s){const i=this.key(t,e),o=this.cells.get(i);o?o.value=s:this.cells.set(i,{value:s}),this.markDirty(i)}deleteCell(t,e){const s=this.key(t,e);this.cells.delete(s),this.markDirty(s)}hasCell(t,e){return this.cells.has(this.key(t,e))}applyPatch(t){this.transaction(()=>{for(const e of t){const s=this.key(e.row,e.col),i=this.cells.get(s);i?Object.assign(i,e.data):this.cells.set(s,{value:void 0,...e.data}),this._dirtyKeys.add(s)}})}transaction(t){var e;if(this._inTransaction){t();return}this._inTransaction=!0,this._dirtyKeys.clear();try{t()}finally{this._inTransaction=!1,this._dirtyKeys.size>0&&((e=this.onChange)==null||e.call(this,new Set(this._dirtyKeys)),this._dirtyKeys.clear())}}markDirty(t){var e;this._inTransaction?this._dirtyKeys.add(t):(e=this.onChange)==null||e.call(this,new Set([t]))}clear(){var t;this.cells.clear(),(t=this.onChange)==null||t.call(this,new Set)}forEach(t){for(const[e,s]of this.cells){const[i,o]=e.split(":").map(Number);t(i,o,s)}}}class V{constructor(){n(this,"listeners",new Map)}on(t,e){return this.listeners.has(t)||this.listeners.set(t,new Set),this.listeners.get(t).add(e),()=>this.off(t,e)}off(t,e){var s;(s=this.listeners.get(t))==null||s.delete(e)}emit(t,e){var s;(s=this.listeners.get(t))==null||s.forEach(i=>{try{i(e)}catch(o){console.error(`[WanderTable] Error in "${String(t)}" handler:`,o)}})}removeAllListeners(){this.listeners.clear()}}class U{constructor(t,e){n(this,"_focus",null);n(this,"_ranges",[]);n(this,"_rowCount");n(this,"_colCount");n(this,"onChange",null);n(this,"infinite",!1);this._rowCount=t,this._colCount=e}get focus(){return this._focus}get ranges(){return this._ranges}setDimensions(t,e){this._rowCount=t,this._colCount=e}focusCell(t,e){var s;t=this.clampRow(t),e=this.clampCol(e),this._focus={row:t,col:e},this._ranges=[{startRow:t,startCol:e,endRow:t,endCol:e}],(s=this.onChange)==null||s.call(this)}extendTo(t,e){var s;this._focus&&(t=this.clampRow(t),e=this.clampCol(e),this._ranges=[{startRow:this._focus.row,startCol:this._focus.col,endRow:t,endCol:e}],(s=this.onChange)==null||s.call(this))}addRange(t){var e;this._ranges.push(t),this._focus={row:t.startRow,col:t.startCol},(e=this.onChange)==null||e.call(this)}selectColumn(t){var e;this._focus={row:0,col:t},this._ranges=[{startRow:0,startCol:t,endRow:1/0,endCol:t}],(e=this.onChange)==null||e.call(this)}selectRow(t){var e;this._focus={row:t,col:0},this._ranges=[{startRow:t,startCol:0,endRow:t,endCol:1/0}],(e=this.onChange)==null||e.call(this)}selectAll(){var t;this._focus={row:0,col:0},this._ranges=[{startRow:0,startCol:0,endRow:1/0,endCol:1/0}],(t=this.onChange)==null||t.call(this)}isSelected(t,e){return this._ranges.some(s=>this.inRange(t,e,s))}isFocused(t,e){var s,i;return((s=this._focus)==null?void 0:s.row)===t&&((i=this._focus)==null?void 0:i.col)===e}forEachSelected(t){for(const e of this._ranges){const s=Math.min(e.startRow,e.endRow),i=Math.min(Math.max(e.startRow,e.endRow),this._rowCount-1),o=Math.min(e.startCol,e.endCol),l=Math.min(Math.max(e.startCol,e.endCol),this._colCount-1);for(let r=s;r<=i;r++)for(let c=o;c<=l;c++)t(r,c)}}getBounds(){if(this._ranges.length===0)return null;let t=1/0,e=1/0,s=-1/0,i=-1/0;for(const o of this._ranges)t=Math.min(t,o.startRow,o.endRow),e=Math.min(e,o.startCol,o.endCol),s=Math.max(s,o.startRow,o.endRow),i=Math.max(i,o.startCol,o.endCol);return s=Math.min(s,this._rowCount-1),i=Math.min(i,this._colCount-1),{r1:t,c1:e,r2:s,c2:i}}getInfo(){const t=this.getBounds();let e=0;this.forEachSelected(()=>{e++});const s=(t==null?void 0:t.r1)??0,i=(t==null?void 0:t.c1)??0,o=(t==null?void 0:t.r2)??0,l=(t==null?void 0:t.c2)??0,r=this._ranges.some(a=>a.endRow===1/0||a.startRow===1/0),c=this._ranges.some(a=>a.endCol===1/0||a.startCol===1/0),h=t!==null&&(c||i===0&&l===this._colCount-1),d=t!==null&&(r||s===0&&o===this._rowCount-1);return{focus:this._focus?{...this._focus}:null,ranges:this._ranges.map(a=>({...a})),bounds:t?{startRow:s,startCol:i,endRow:o,endCol:l}:null,cellCount:e,rangeCount:this._ranges.length,isMultiCell:e>1,isFullRow:h,isFullCol:d,isAll:h&&d,isEmpty:this._ranges.length===0,rowSpan:t?o-s+1:0,colSpan:t?l-i+1:0}}clear(){var t;this._focus=null,this._ranges=[],(t=this.onChange)==null||t.call(this)}move(t,e,s){if(!this._focus){this.focusCell(0,0);return}const i=this.clampRow(this._focus.row+t),o=this.clampCol(this._focus.col+e);s?this.extendTo(i,o):this.focusCell(i,o)}inRange(t,e,s){const i=Math.min(s.startRow,s.endRow),o=Math.max(s.startRow,s.endRow),l=Math.min(s.startCol,s.endCol),r=Math.max(s.startCol,s.endCol);return t>=i&&t<=o&&e>=l&&e<=r}clampRow(t){return this.infinite?Math.max(0,t):Math.max(0,Math.min(this._rowCount-1,t))}clampCol(t){return this.infinite?Math.max(0,t):Math.max(0,Math.min(this._colCount-1,t))}}class X{constructor(t=100){n(this,"undoStack",[]);n(this,"redoStack",[]);n(this,"limit");n(this,"onChange",null);this.limit=t}execute(t){var e;t.execute(),this.undoStack.push(t),this.undoStack.length>this.limit&&this.undoStack.shift(),this.redoStack.length=0,(e=this.onChange)==null||e.call(this)}undo(){var e;const t=this.undoStack.pop();return t?(t.undo(),this.redoStack.push(t),(e=this.onChange)==null||e.call(this),t):null}redo(){var e;const t=this.redoStack.pop();return t?(t.execute(),this.undoStack.push(t),(e=this.onChange)==null||e.call(this),t):null}get canUndo(){return this.undoStack.length>0}get canRedo(){return this.redoStack.length>0}clear(){this.undoStack.length=0,this.redoStack.length=0}}class A{constructor(t,e,s,i){n(this,"oldValue");var o;this.data=t,this.row=e,this.col=s,this.newValue=i,this.oldValue=(o=t.getCell(e,s))==null?void 0:o.value}execute(){this.data.setCellValue(this.row,this.col,this.newValue)}undo(){this.oldValue===void 0?this.data.deleteCell(this.row,this.col):this.data.setCellValue(this.row,this.col,this.oldValue)}getChanges(){return[{row:this.row,col:this.col,oldValue:this.oldValue,newValue:this.newValue}]}}class F{constructor(t,e){n(this,"snapshots");this.data=t,this.patches=e,this.snapshots=e.map(s=>({row:s.row,col:s.col,old:t.getCell(s.row,s.col)?{...t.getCell(s.row,s.col)}:void 0}))}execute(){this.data.applyPatch(this.patches)}undo(){this.data.transaction(()=>{for(const t of this.snapshots)t.old===void 0?this.data.deleteCell(t.row,t.col):this.data.setCell(t.row,t.col,t.old)})}getChanges(){return this.snapshots.map((t,e)=>{var s,i,o;return{row:t.row,col:t.col,oldValue:(s=t.old)==null?void 0:s.value,newValue:(o=(i=this.patches[e])==null?void 0:i.data)==null?void 0:o.value}})}}class Y{constructor(t,e){n(this,"snapshots",[]);this.data=t,this.cells=e;for(const{row:s,col:i}of e){const o=t.getCell(s,i);o&&this.snapshots.push({row:s,col:i,old:{...o}})}}execute(){this.data.transaction(()=>{for(const{row:t,col:e}of this.cells)this.data.deleteCell(t,e)})}undo(){this.data.transaction(()=>{for(const t of this.snapshots)this.data.setCell(t.row,t.col,t.old)})}getChanges(){return this.snapshots.map(t=>({row:t.row,col:t.col,oldValue:t.old.value,newValue:void 0}))}}class z{constructor(t,e,s){n(this,"configs");n(this,"widths");n(this,"prefixSums");n(this,"defaultWidth");var i;this.defaultWidth=e,this.configs=s??[],this.widths=new Array(t);for(let o=0;o<t;o++)this.widths[o]=((i=this.configs[o])==null?void 0:i.width)??e;this.prefixSums=this.buildPrefixSums()}buildPrefixSums(){const t=new Array(this.widths.length+1);t[0]=0;for(let e=0;e<this.widths.length;e++)t[e+1]=t[e]+this.widths[e];return t}get count(){return this.widths.length}getWidth(t){return this.widths[t]??this.defaultWidth}setWidth(t,e){const s=this.configs[t],i=(s==null?void 0:s.minWidth)??30,o=(s==null?void 0:s.maxWidth)??1/0;this.widths[t]=Math.max(i,Math.min(o,e)),this.prefixSums=this.buildPrefixSums()}getX(t){return this.prefixSums[t]??0}getTotalWidth(){return this.prefixSums[this.widths.length]??0}getConfig(t){return this.configs[t]}setCount(t){for(;this.widths.length<t;)this.widths.push(this.defaultWidth);this.widths.length=t,this.prefixSums=this.buildPrefixSums()}getColAtX(t){let e=0,s=this.widths.length-1;for(;e<=s;){const i=e+s>>>1;if(this.prefixSums[i+1]<=t)e=i+1;else if(this.prefixSums[i]>t)s=i-1;else return i}return Math.max(0,Math.min(e,this.widths.length-1))}static columnLabel(t){return P(t)}}function P(u){let t="",e=u;for(;e>=0;)t=String.fromCharCode(65+e%26)+t,e=Math.floor(e/26)-1;return t}class G{constructor(t,e){n(this,"heights");n(this,"prefixSums");n(this,"defaultHeight");n(this,"configs",new Map);this.defaultHeight=e,this.heights=new Array(t).fill(e),this.prefixSums=this.buildPrefixSums()}buildPrefixSums(){const t=new Array(this.heights.length+1);t[0]=0;for(let e=0;e<this.heights.length;e++)t[e+1]=t[e]+this.heights[e];return t}get count(){return this.heights.length}getHeight(t){return this.heights[t]??this.defaultHeight}setHeight(t,e){this.heights[t]=Math.max(20,e),this.prefixSums=this.buildPrefixSums()}getY(t){return this.prefixSums[t]??0}getTotalHeight(){return this.prefixSums[this.heights.length]??0}getConfig(t){return this.configs.get(t)}setConfig(t,e){this.configs.set(t,e),e.height!=null&&this.setHeight(t,e.height)}setCount(t){for(;this.heights.length<t;)this.heights.push(this.defaultHeight);this.heights.length=t,this.prefixSums=this.buildPrefixSums()}getRowAtY(t){let e=0,s=this.heights.length-1;for(;e<=s;){const i=e+s>>>1;if(this.prefixSums[i+1]<=t)e=i+1;else if(this.prefixSums[i]>t)s=i-1;else return i}return Math.max(0,Math.min(e,this.heights.length-1))}}class fe{constructor(t){n(this,"container");n(this,"scrollContainer");n(this,"scrollSentinel");n(this,"viewportEl");n(this,"colHeaderEl");n(this,"rowHeaderEl");n(this,"cornerEl");n(this,"rowPool",[]);n(this,"activeRows",new Map);n(this,"viewport",{startRow:0,endRow:0,startCol:0,endCol:0,scrollX:0,scrollY:0});n(this,"ctx");n(this,"rafId",0);n(this,"needsRender",!1);n(this,"onScroll",null);n(this,"onCellClick",null);n(this,"onCellDblClick",null);n(this,"onCellContextMenu",null);n(this,"onHeaderClick",null);n(this,"onColumnResizeStart",null);n(this,"onHeaderContextMenu",null);n(this,"handleScroll",()=>{this.scheduleRender()});n(this,"handleMouseDown",t=>{var s;const e=this.getCellFromEvent(t);e&&((s=this.onCellClick)==null||s.call(this,e.row,e.col,t))});n(this,"handleDblClick",t=>{var s;const e=this.getCellFromEvent(t);e&&((s=this.onCellDblClick)==null||s.call(this,e.row,e.col,t))});n(this,"handleContextMenu",t=>{var s;const e=this.getCellFromEvent(t);e&&((s=this.onCellContextMenu)==null||s.call(this,e.row,e.col,t))});n(this,"handleColHeaderMouse",t=>{var o,l;const e=t.target.closest(".wt-col-header-cell");if(!e)return;const s=parseInt(e.dataset.col??"",10);if(isNaN(s))return;const i=e.getBoundingClientRect();if(t.clientX>i.right-5){(o=this.onColumnResizeStart)==null||o.call(this,s,t.clientX);return}(l=this.onHeaderClick)==null||l.call(this,"col",s,t)});n(this,"handleRowHeaderMouse",t=>{var i;const e=t.target.closest(".wt-row-header-cell");if(!e)return;const s=parseInt(e.dataset.row??"",10);isNaN(s)||(i=this.onHeaderClick)==null||i.call(this,"row",s,t)});n(this,"handleCornerMouse",t=>{var e;(e=this.onHeaderClick)==null||e.call(this,"corner",-1,t)});n(this,"handleColHeaderContextMenu",t=>{var i;t.preventDefault();const e=t.target.closest(".wt-col-header-cell");if(!e)return;const s=parseInt(e.dataset.col??"",10);isNaN(s)||(i=this.onHeaderContextMenu)==null||i.call(this,"col",s,t)});n(this,"handleRowHeaderContextMenu",t=>{var i;t.preventDefault();const e=t.target.closest(".wt-row-header-cell");if(!e)return;const s=parseInt(e.dataset.row??"",10);isNaN(s)||(i=this.onHeaderContextMenu)==null||i.call(this,"row",s,t)});this.container=t,this.container.classList.add("wt-root"),this.container.setAttribute("tabindex","0"),this.cornerEl=document.createElement("div"),this.cornerEl.className="wt-corner",this.colHeaderEl=document.createElement("div"),this.colHeaderEl.className="wt-col-headers",this.rowHeaderEl=document.createElement("div"),this.rowHeaderEl.className="wt-row-headers",this.scrollContainer=document.createElement("div"),this.scrollContainer.className="wt-scroll-container",this.scrollSentinel=document.createElement("div"),this.scrollSentinel.className="wt-scroll-sentinel",this.viewportEl=document.createElement("div"),this.viewportEl.className="wt-viewport",this.scrollContainer.appendChild(this.scrollSentinel),this.scrollContainer.appendChild(this.viewportEl),this.container.appendChild(this.cornerEl),this.container.appendChild(this.colHeaderEl),this.container.appendChild(this.rowHeaderEl),this.container.appendChild(this.scrollContainer),this.scrollContainer.addEventListener("scroll",this.handleScroll,{passive:!0}),this.viewportEl.addEventListener("mousedown",this.handleMouseDown),this.viewportEl.addEventListener("dblclick",this.handleDblClick),this.viewportEl.addEventListener("contextmenu",this.handleContextMenu),this.colHeaderEl.addEventListener("mousedown",this.handleColHeaderMouse),this.colHeaderEl.addEventListener("contextmenu",this.handleColHeaderContextMenu),this.rowHeaderEl.addEventListener("mousedown",this.handleRowHeaderMouse),this.rowHeaderEl.addEventListener("contextmenu",this.handleRowHeaderContextMenu),this.cornerEl.addEventListener("mousedown",this.handleCornerMouse)}init(t){this.ctx=t,this.container.classList.toggle("wt-root--no-gridlines",!t.showGridLines),this.container.classList.toggle("wt-root--no-border",!t.showBorder),t.layout==="auto"&&(this.container.classList.add("wt-root--auto"),this.scrollContainer.classList.add("wt-scroll-container--auto")),this.applyTheme(),this.updateLayout(),this.scheduleRender()}applyTheme(){const t=this.ctx.theme,e=this.container.style;e.setProperty("--wt-bg",t.bgColor),e.setProperty("--wt-cell-bg",t.cellBgColor),e.setProperty("--wt-cell-text",t.cellTextColor),e.setProperty("--wt-header-bg",t.headerBgColor),e.setProperty("--wt-header-text",t.headerTextColor),e.setProperty("--wt-grid-line",t.gridLineColor),e.setProperty("--wt-sel-bg",t.selectionBgColor),e.setProperty("--wt-sel-border",t.selectionBorderColor),e.setProperty("--wt-focus-border",t.focusBorderColor),e.setProperty("--wt-font",t.fontFamily),e.setProperty("--wt-font-size",`${t.fontSize}px`),e.setProperty("--wt-header-font-size",`${t.headerFontSize}px`),e.setProperty("--wt-cell-padding",`${t.cellPadding}px`),e.setProperty("--wt-header-height",`${t.headerHeight}px`),e.setProperty("--wt-row-header-width",`${t.rowHeaderWidth}px`)}updateLayout(){const{columns:t,rows:e,viewMapping:s,showColHeaders:i,showRowHeaders:o,theme:l}=this.ctx,r=t.getTotalWidth(),c=s.visibleRowCount,h=c===e.count?e.getTotalHeight():e.getY(c),d=this.ctx.headerRows?this.ctx.headerRows.length:1,a=i?l.headerHeight*d:0,g=o?l.rowHeaderWidth:0;if(this.ctx.layout==="auto"){if(this.container.style.display="grid",this.container.style.gridTemplateColumns=`${g}px ${r}px`,this.container.style.gridTemplateRows=`${a}px auto`,this.container.style.width=`${g+r}px`,this.container.style.minWidth="100%",this.cornerEl.style.display=i&&o?"":"none",this.cornerEl.style.position="static",this.cornerEl.style.width="",this.cornerEl.style.height="",this.colHeaderEl.style.display=i?"":"none",this.colHeaderEl.style.position="static",this.colHeaderEl.style.left="",this.colHeaderEl.style.right="",this.colHeaderEl.style.height=`${a}px`,this.colHeaderEl.style.overflow="visible",this.rowHeaderEl.style.display=o?"":"none",this.rowHeaderEl.style.position="static",this.rowHeaderEl.style.top="",this.rowHeaderEl.style.bottom="",this.rowHeaderEl.style.width=`${g}px`,this.rowHeaderEl.style.overflow="visible",this.scrollContainer.style.position="static",this.scrollContainer.style.top="",this.scrollContainer.style.left="",this.scrollContainer.style.right="",this.scrollContainer.style.bottom="",this.scrollContainer.style.overflow="visible",this.scrollContainer.style.gridColumn=o?"2":"1 / -1",this.scrollSentinel.style.width=`${r}px`,this.scrollSentinel.style.height="0",this.viewportEl.style.position="relative",this.viewportEl.style.height=`${h}px`,this.viewportEl.style.width=`${r}px`,o){const p=this.rowHeaderEl.querySelector(".wt-row-headers-inner");p&&(p.style.height=`${h}px`),this.rowHeaderEl.style.height=`${h}px`,this.rowHeaderEl.style.gridRow="2",this.rowHeaderEl.style.gridColumn="1"}}else this.scrollSentinel.style.width=`${r}px`,this.scrollSentinel.style.height=`${h}px`,this.cornerEl.style.display=i&&o?"":"none",this.cornerEl.style.width=`${g}px`,this.cornerEl.style.height=`${a}px`,this.colHeaderEl.style.display=i?"":"none",this.colHeaderEl.style.left=`${g}px`,this.colHeaderEl.style.height=`${a}px`,this.colHeaderEl.style.right="0",this.rowHeaderEl.style.display=o?"":"none",this.rowHeaderEl.style.top=`${a}px`,this.rowHeaderEl.style.width=`${g}px`,this.rowHeaderEl.style.bottom="0",this.scrollContainer.style.top=`${a}px`,this.scrollContainer.style.left=`${g}px`,this.scrollContainer.style.right="0",this.scrollContainer.style.bottom="0"}scheduleRender(){this.needsRender||(this.needsRender=!0,this.rafId=requestAnimationFrame(()=>{this.needsRender=!1,this.render()}))}render(){var S;const{columns:t,rows:e,viewMapping:s,showColHeaders:i,showRowHeaders:o}=this.ctx,l=this.scrollContainer,r=l.clientWidth,c=l.clientHeight,h=l.scrollLeft,d=l.scrollTop,a=s.visibleRowCount,g=this.ctx.layout==="auto",p=3;let w,C,E,b;if(g)w=0,C=a-1,E=0,b=t.count-1;else{const m=e.getRowAtY(d),f=e.getRowAtY(d+c),x=t.getColAtX(h),H=t.getColAtX(h+r);w=Math.max(0,m-p),C=Math.min(a-1,f+p),E=Math.max(0,x-p),b=Math.min(t.count-1,H+p)}const v={startRow:w,endRow:C,startCol:E,endCol:b,scrollX:h,scrollY:d};this.viewport=v;const _=this.ctx.frozenRows,T=this.ctx.frozenCols,k=new Set;for(let m=0;m<_&&m<a;m++)k.add(m);for(let m=v.startRow;m<=v.endRow;m++)k.add(m);for(const[m,f]of this.activeRows)k.has(m)||(f.el.style.display="none",this.rowPool.push(f),this.activeRows.delete(m));for(const m of k)this.renderRow(m,v,h,d,_,T);if(this.ctx.autoRowHeight){let m=!1;for(const f of k){const x=this.activeRows.get(f);if(!x)continue;let H=20;for(const M of x.cells){if(M.style.display==="none")continue;const L=M.scrollHeight;L>H&&(H=L)}const I=e.getHeight(f);Math.abs(H-I)>1&&(e.setHeight(f,H),m=!0)}if(m){this.updateLayout();for(const f of k){const x=this.activeRows.get(f);if(!x)continue;const I=f<_?e.getY(f)+d:e.getY(f),M=e.getHeight(f);x.el.style.transform=`translateY(${I}px)`,x.el.style.height=`${M}px`;for(const L of x.cells)L.style.display!=="none"&&(L.style.height=`${M}px`)}}}i&&this.renderColHeaders(v,h),o&&this.renderRowHeaders(v,d),(S=this.onScroll)==null||S.call(this,v)}renderRow(t,e,s,i,o,l){var k;const{columns:r,rows:c,data:h,selection:d,viewMapping:a}=this.ctx,g=a.toDataRow(t);let p=this.activeRows.get(t);const w=c.getY(t),C=c.getHeight(t),E=e.endCol-e.startCol+1,b=t<o;p||(p=this.acquireRow(E),p.rowIndex=t,this.activeRows.set(t,p));const v=p.el;v.style.display="";const _=b?w+i:w;v.style.transform=`translateY(${_}px)`,v.style.height=`${C}px`,v.style.zIndex=b?"2":"",v.dataset.row=String(g),this.ensureCells(p,E);const{merges:T}=this.ctx;for(let S=0;S<E;S++){const m=e.startCol+S,f=p.cells[S];if(T.isHidden(g,m)){f.style.display="none";continue}const x=r.getX(m);let H=r.getWidth(m),I=C;const M=T.getMerge(g,m);if(M&&M.row===g&&M.col===m){for(let y=1;y<M.colSpan;y++)H+=r.getWidth(m+y);for(let y=1;y<M.rowSpan;y++)I+=c.getHeight(t+y);f.style.zIndex="1"}else f.style.zIndex="";const L=m<l,ce=L?x+s:x;f.style.transform=`translateX(${ce}px)`,f.style.width=`${H}px`,f.style.height=`${I}px`,f.style.display="",(L||b)&&(f.style.zIndex=L&&b?"4":"3"),f.dataset.row=String(g),f.dataset.col=String(m);const R=h.getCell(g,m),B={selected:d.isSelected(g,m),focused:d.isFocused(g,m),editing:!1,hover:!1};if(f.classList.toggle("wt-cell--selected",B.selected),f.classList.toggle("wt-cell--focused",B.focused),R!=null&&R.style){const y=R.style;y.bgColor?f.style.backgroundColor=y.bgColor:f.style.backgroundColor="",y.textColor?f.style.color=y.textColor:f.style.color="",y.textAlign?f.style.textAlign=y.textAlign:f.style.textAlign="",y.borderLeft?f.style.borderLeft=y.borderLeft:f.style.borderLeft="",y.borderRight?f.style.borderRight=y.borderRight:f.style.borderRight="",y.borderTop?f.style.borderTop=y.borderTop:f.style.borderTop="",y.borderBottom?f.style.borderBottom=y.borderBottom:f.style.borderBottom=""}else f.style.backgroundColor="",f.style.color="",f.style.textAlign="",f.style.borderLeft="",f.style.borderRight="",f.style.borderTop="",f.style.borderBottom="";R!=null&&R.className&&(f.className=`wt-cell ${R.className}`,B.selected&&f.classList.add("wt-cell--selected"),B.focused&&f.classList.add("wt-cell--focused"));const de=(R==null?void 0:R.type)??((k=this.ctx.columns.getConfig(m))==null?void 0:k.type)??this.ctx.defaultCellType;(this.ctx.renderers.get(de)??this.ctx.defaultRenderer).render(f,R,B)}for(let S=E;S<p.cells.length;S++)p.cells[S].style.display="none"}renderColHeaders(t,e){var r;const{columns:s,theme:i}=this.ctx,o=this.ctx.headerRows;this.colHeaderEl.scrollLeft=e;const l=this.colHeaderEl.querySelector(".wt-col-headers-inner")??this.createColHeadersInner();if(l.style.width=`${s.getTotalWidth()}px`,o&&o.length>1){const c=i.headerHeight,h=c*o.length;this.colHeaderEl.style.height=`${h}px`,l.style.height=`${h}px`,l.innerHTML="";for(let d=0;d<o.length;d++)for(const a of o[d]){const g=document.createElement("div");g.className=a.colSpan>1?"wt-header-cell wt-col-header-group":"wt-header-cell wt-col-header-cell";const p=s.getX(a.col);let w=0;for(let C=0;C<a.colSpan;C++)w+=s.getWidth(a.col+C);g.style.transform=`translate(${p}px, ${d*c}px)`,g.style.width=`${w}px`,g.style.height=`${c*a.rowSpan}px`,g.textContent=a.label,a.colSpan===1&&(g.dataset.col=String(a.col)),l.appendChild(g)}}else{const c=t.endCol-t.startCol+1;for(;l.children.length<c;){const h=document.createElement("div");h.className="wt-header-cell wt-col-header-cell",l.appendChild(h)}for(let h=0;h<c;h++){const d=t.startCol+h,a=l.children[h];a.style.display="",a.style.transform=`translateX(${s.getX(d)}px)`,a.style.width=`${s.getWidth(d)}px`,a.style.height=`${i.headerHeight}px`,a.textContent=((r=this.ctx.columns.getConfig(d))==null?void 0:r.label)??z.columnLabel(d),a.dataset.col=String(d)}for(let h=c;h<l.children.length;h++)l.children[h].style.display="none"}}createColHeadersInner(){const t=document.createElement("div");return t.className="wt-col-headers-inner",this.colHeaderEl.appendChild(t),t}renderRowHeaders(t,e){const{rows:s,theme:i}=this.ctx;this.rowHeaderEl.scrollTop=e;let o=this.rowHeaderEl.querySelector(".wt-row-headers-inner");o||(o=document.createElement("div"),o.className="wt-row-headers-inner",this.rowHeaderEl.appendChild(o)),o.style.height=`${s.getTotalHeight()}px`;const l=t.endRow-t.startRow+1;for(;o.children.length<l;){const r=document.createElement("div");r.className="wt-header-cell wt-row-header-cell",o.appendChild(r)}for(let r=0;r<l;r++){const c=t.startRow+r,h=o.children[r];h.style.display="",h.style.transform=`translateY(${s.getY(c)}px)`,h.style.height=`${s.getHeight(c)}px`,h.style.width=`${i.rowHeaderWidth}px`,h.textContent=String(c+1),h.dataset.row=String(c)}for(let r=l;r<o.children.length;r++)o.children[r].style.display="none"}acquireRow(t){let e=this.rowPool.pop();if(!e){const s=document.createElement("div");s.className="wt-row",this.viewportEl.appendChild(s),e={el:s,cells:[],rowIndex:-1}}return this.ensureCells(e,t),e}ensureCells(t,e){for(;t.cells.length<e;){const s=document.createElement("div");s.className="wt-cell",t.el.appendChild(s),t.cells.push(s)}}getCellFromEvent(t){const e=t.target.closest(".wt-cell");if(!e)return null;const s=parseInt(e.dataset.row??"",10),i=parseInt(e.dataset.col??"",10);return isNaN(s)||isNaN(i)?null:{row:s,col:i}}getViewport(){return this.viewport}scrollToCell(t,e){const{columns:s,rows:i}=this.ctx,o=s.getX(e),l=i.getY(t),r=s.getWidth(e),c=i.getHeight(t),h=this.scrollContainer,d=h.clientWidth,a=h.clientHeight;o<h.scrollLeft?h.scrollLeft=o:o+r>h.scrollLeft+d&&(h.scrollLeft=o+r-d),l<h.scrollTop?h.scrollTop=l:l+c>h.scrollTop+a&&(h.scrollTop=l+c-a)}getCellBounds(t,e){const{columns:s,rows:i}=this.ctx;return{x:s.getX(e)-this.scrollContainer.scrollLeft,y:i.getY(t)-this.scrollContainer.scrollTop,width:s.getWidth(e),height:i.getHeight(t)}}getScrollContainer(){return this.scrollContainer}getViewportEl(){return this.viewportEl}getContainer(){return this.container}destroy(){cancelAnimationFrame(this.rafId),this.scrollContainer.removeEventListener("scroll",this.handleScroll),this.viewportEl.removeEventListener("mousedown",this.handleMouseDown),this.viewportEl.removeEventListener("dblclick",this.handleDblClick),this.viewportEl.removeEventListener("contextmenu",this.handleContextMenu),this.colHeaderEl.removeEventListener("mousedown",this.handleColHeaderMouse),this.colHeaderEl.removeEventListener("contextmenu",this.handleColHeaderContextMenu),this.rowHeaderEl.removeEventListener("mousedown",this.handleRowHeaderMouse),this.rowHeaderEl.removeEventListener("contextmenu",this.handleRowHeaderContextMenu),this.cornerEl.removeEventListener("mousedown",this.handleCornerMouse),this.container.innerHTML=""}}const we={selected:!1,focused:!1,editing:!1,hover:!1};class me{constructor(t,e,s,i,o,l){n(this,"measureEl");n(this,"data");n(this,"columns");n(this,"renderers");n(this,"defaultRenderer");this.data=e,this.columns=s,this.renderers=o,this.defaultRenderer=l,this.measureEl=document.createElement("div"),this.measureEl.className="wt-cell",this.measureEl.style.position="absolute",this.measureEl.style.visibility="hidden",this.measureEl.style.left="-9999px",this.measureEl.style.top="-9999px",this.measureEl.style.whiteSpace="nowrap",this.measureEl.style.height="auto",this.measureEl.style.width="auto",t.appendChild(this.measureEl)}measureCell(t,e){var c;const s=this.data.getCell(t,e),i=(s==null?void 0:s.type)??((c=this.columns.getConfig(e))==null?void 0:c.type)??"text";(this.renderers.get(i)??this.defaultRenderer).render(this.measureEl,s,we);const l=this.measureEl.scrollWidth+1,r=this.measureEl.scrollHeight+1;return this.measureEl.textContent="",this.measureEl.innerHTML="",{width:l,height:r}}autoFitColumn(t,e=500){var a;let i=40;const o=((a=this.columns.getConfig(t))==null?void 0:a.label)??P(t);this.measureEl.textContent=o,this.measureEl.style.fontWeight="500",i=Math.max(i,this.measureEl.scrollWidth+16),this.measureEl.style.fontWeight="";const l=this.data.rowCount,r=l>e?Math.floor(l/e):1;for(let g=0;g<l;g+=r){if(!this.data.hasCell(g,t))continue;const{width:p}=this.measureCell(g,t);i=Math.max(i,p+16)}const c=this.columns.getConfig(t),h=(c==null?void 0:c.minWidth)??30,d=(c==null?void 0:c.maxWidth)??600;return Math.max(h,Math.min(d,i))}autoFitRow(t){let e=20;for(let s=0;s<this.columns.count;s++){if(!this.data.hasCell(t,s))continue;this.measureEl.style.width=`${this.columns.getWidth(s)}px`,this.measureEl.style.whiteSpace="normal";const{height:i}=this.measureCell(t,s);e=Math.max(e,i),this.measureEl.style.width="auto",this.measureEl.style.whiteSpace="nowrap"}return e}destroy(){this.measureEl.remove()}}class K{render(t,e,s){const i=e==null?void 0:e.value;if(i==null||i===""){t.textContent="";return}t.textContent=String(i)}}class j{render(t,e,s){const i=!!(e!=null&&e.value);t.innerHTML=`<label class="wt-checkbox">
2
+ <span class="wt-checkbox-box${i?" wt-checkbox-box--checked":""}">
3
+ ${i?'<svg width="12" height="12" viewBox="0 0 12 12" fill="none"><path d="M2.5 6L5 8.5L9.5 3.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/></svg>':""}
4
+ </span>
5
+ </label>`}}const N={active:{bg:"#dcfce7",text:"#166534"},success:{bg:"#dcfce7",text:"#166534"},inactive:{bg:"#fef2f2",text:"#991b1b"},error:{bg:"#fef2f2",text:"#991b1b"},pending:{bg:"#fef9c3",text:"#854d0e"},warning:{bg:"#fef9c3",text:"#854d0e"},info:{bg:"#dbeafe",text:"#1e40af"},default:{bg:"#f1f5f9",text:"#475569"}};class q{render(t,e,s){var h,d;if((e==null?void 0:e.value)==null||e.value===""){t.textContent="";return}const i=String(e.value),o=i.toLowerCase(),l=N[o]??N.default,r=(h=e.meta)==null?void 0:h.badgeBg,c=(d=e.meta)==null?void 0:d.badgeText;t.innerHTML=`<span class="wt-badge" style="background:${r??l.bg};color:${c??l.text}">${i}</span>`}}class J{constructor(t,e){n(this,"formatter");this.formatter=new Intl.NumberFormat(t,e)}render(t,e,s){if((e==null?void 0:e.value)==null||e.value===""){t.textContent="";return}const i=Number(e.value);if(isNaN(i)){t.textContent=String(e.value);return}t.textContent=this.formatter.format(i),t.style.textAlign="right"}}class Z{render(t,e,s){if((e==null?void 0:e.value)==null){t.textContent="";return}const i=Math.max(0,Math.min(100,Number(e.value)));if(isNaN(i)){t.textContent="";return}const o=i>=80?"#22c55e":i>=50?"#f59e0b":i>=25?"#f97316":"#ef4444";t.innerHTML=`<div class="wt-progress">
6
+ <div class="wt-progress-bar" style="width:${i}%;background:${o}"></div>
7
+ <span class="wt-progress-label">${Math.round(i)}%</span>
8
+ </div>`}}class Q{render(t,e,s){t.textContent=""}}class ee{constructor(){n(this,"renderers",new Map);n(this,"defaultRenderer");this.defaultRenderer=new K,this.renderers.set("text",this.defaultRenderer),this.renderers.set("blank",new Q),this.renderers.set("checkbox",new j),this.renderers.set("badge",new q),this.renderers.set("number",new J),this.renderers.set("progress",new Z)}register(t,e){this.renderers.set(t,e)}get(t){return this.renderers.get(t)}getAll(){return this.renderers}}class Ce{constructor(t){n(this,"editors",new Map);n(this,"activeEditor",null);n(this,"activeEditorEl",null);n(this,"activeRow",-1);n(this,"activeCol",-1);n(this,"overlayEl");n(this,"onClose",null);n(this,"handleEditorKey",t=>{switch(t.key){case"Enter":t.shiftKey||(t.preventDefault(),t.stopPropagation(),this.close(!0));break;case"Escape":t.preventDefault(),t.stopPropagation(),this.close(!1);break;case"Tab":t.preventDefault(),t.stopPropagation(),this.close(!0);break}});this.overlayEl=document.createElement("div"),this.overlayEl.className="wt-editor-overlay",this.overlayEl.style.display="none",t.appendChild(this.overlayEl),this.register("text",()=>new ye),this.register("blank",()=>new ve)}register(t,e){this.editors.set(t,e)}get isEditing(){return this.activeEditor!==null}get editingCell(){return this.activeEditor?{row:this.activeRow,col:this.activeCol}:null}open(t,e,s,i,o,l,r){this.close(!1);const c=this.editors.get(s);if(!c)return;this.activeRow=t,this.activeCol=e,this.activeEditor=c(),this.overlayEl.style.display="",this.overlayEl.style.left=`${o.x}px`,this.overlayEl.style.top=`${o.y}px`,this.overlayEl.style.width=`${o.width}px`,this.overlayEl.style.height=`${o.height}px`,this.activeEditorEl=this.activeEditor.createElement(this.overlayEl);const h=r!==void 0?r:i;this.activeEditor.open(h,o,l),this.activeEditorEl.addEventListener("keydown",this.handleEditorKey)}close(t){var l;if(!this.activeEditor)return;const e=this.activeEditor,s=this.activeRow,i=this.activeCol;let o;t&&(o=e.getValue(),e.validate&&e.validate(o)!==!0)||(this.activeEditorEl&&(this.activeEditorEl.removeEventListener("keydown",this.handleEditorKey),this.activeEditorEl=null),e.close(),this.overlayEl.innerHTML="",this.overlayEl.style.display="none",this.activeEditor=null,this.activeRow=-1,this.activeCol=-1,(l=this.onClose)==null||l.call(this,s,i,t?o:void 0,!t))}destroy(){this.close(!1),this.overlayEl.remove()}}class ye{constructor(){n(this,"input")}createElement(t){return this.input=document.createElement("input"),this.input.type="text",this.input.className="wt-editor-input",t.appendChild(this.input),this.input}open(t,e,s){this.input.value=t!=null?String(t):"",requestAnimationFrame(()=>{this.input.focus(),this.input.select()})}getValue(){return this.input.value}close(){this.input.remove()}}class ve{constructor(){n(this,"el")}createElement(t){return this.el=document.createElement("div"),t.appendChild(this.el),this.el}open(){}getValue(){}close(){var t;(t=this.el)==null||t.remove()}}class Ee{constructor(t,e){n(this,"selection");n(this,"callbacks");this.selection=t,this.callbacks=e}handleKeyDown(t){const e=t.ctrlKey||t.metaKey,s=t.shiftKey,i=this.selection.focus;switch(t.key){case"ArrowUp":t.preventDefault(),this.selection.move(-1,0,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"ArrowDown":t.preventDefault(),this.selection.move(1,0,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"ArrowLeft":t.preventDefault(),this.selection.move(0,-1,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"ArrowRight":t.preventDefault(),this.selection.move(0,1,s),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"Tab":t.preventDefault(),this.selection.move(0,s?-1:1,!1),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"Enter":t.preventDefault(),i&&this.callbacks.onStartEdit(i.row,i.col);break;case"F2":t.preventDefault(),i&&this.callbacks.onStartEdit(i.row,i.col);break;case"Delete":case"Backspace":t.preventDefault(),this.callbacks.onDelete();break;case"Escape":t.preventDefault(),this.selection.clear();break;case"Home":t.preventDefault(),e?this.selection.focusCell(0,0):i&&this.selection.focusCell(i.row,0),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"End":t.preventDefault(),this.selection.focus&&this.callbacks.onScrollTo(this.selection.focus.row,this.selection.focus.col);break;case"a":e?(t.preventDefault(),this.selection.selectAll()):this.handleCharInput(t);break;case"c":e?(t.preventDefault(),this.callbacks.onCopy()):this.handleCharInput(t);break;case"v":e?(t.preventDefault(),this.callbacks.onPaste()):this.handleCharInput(t);break;case"x":e?(t.preventDefault(),this.callbacks.onCut()):this.handleCharInput(t);break;case"z":e?(t.preventDefault(),s?this.callbacks.onRedo():this.callbacks.onUndo()):this.handleCharInput(t);break;case"y":e?(t.preventDefault(),this.callbacks.onRedo()):this.handleCharInput(t);break;default:!e&&!t.altKey&&t.key.length===1&&this.handleCharInput(t);break}}handleCharInput(t){if(t.ctrlKey||t.metaKey||t.altKey)return;const e=this.selection.focus;e&&(t.preventDefault(),this.callbacks.onStartEdit(e.row,e.col,t.key))}}class be{constructor(t,e){n(this,"data");n(this,"selection");n(this,"onChange",null);this.data=t,this.selection=e}async copy(){const t=this.selectionToTSV();if(t)try{await navigator.clipboard.writeText(t)}catch{this.fallbackCopy(t)}}async cut(){await this.copy(),this.deleteSelected()}async paste(){var l;const t=this.selection.focus;if(!t)return;let e;try{e=await navigator.clipboard.readText()}catch{return}const s=this.parseTSV(e);if(s.length===0)return;const i=s.length===1&&s[0].length===1,o=[];if(i&&!this.isFullRowOrColSelected()){const r=s[0][0];this.selection.forEachSelected((c,h)=>{c<this.data.rowCount&&h<this.data.colCount&&o.push({row:c,col:h,data:{value:r}})})}else for(let r=0;r<s.length;r++)for(let c=0;c<s[r].length;c++){const h=t.row+r,d=t.col+c;h>=this.data.rowCount||d>=this.data.colCount||o.push({row:h,col:d,data:{value:s[r][c]}})}o.length>0&&(this.data.applyPatch(o),(l=this.onChange)==null||l.call(this,o))}isFullRowOrColSelected(){const t=this.selection.getBounds();if(!t)return!1;const e=t.c1===0&&t.c2===this.data.colCount-1,s=t.r1===0&&t.r2===this.data.rowCount-1;return e||s}deleteSelected(){var e;const t=[];this.selection.forEachSelected((s,i)=>{this.data.hasCell(s,i)&&t.push({row:s,col:i,data:{value:void 0}})}),t.length>0&&(this.data.applyPatch(t),(e=this.onChange)==null||e.call(this,t))}selectionToTSV(){const t=this.selection.getBounds();if(!t)return null;const e=[];for(let s=t.r1;s<=t.r2;s++){const i=[];for(let o=t.c1;o<=t.c2;o++){const l=this.data.getCell(s,o),r=l==null?void 0:l.value;i.push(r!=null?String(r):"")}e.push(i.join(" "))}return e.join(`
9
+ `)}parseTSV(t){return t.split(`
10
+ `).map(e=>e.split(" "))}fallbackCopy(t){const e=document.createElement("textarea");e.value=t,e.style.position="fixed",e.style.left="-9999px",document.body.appendChild(e),e.select(),document.execCommand("copy"),e.remove()}}class xe{constructor(t){n(this,"columns");n(this,"resizing",!1);n(this,"resizeCol",-1);n(this,"startX",0);n(this,"startWidth",0);n(this,"onResize",null);n(this,"handleMove",t=>{var i;if(!this.resizing)return;const e=t.clientX-this.startX,s=Math.max(30,this.startWidth+e);this.columns.setWidth(this.resizeCol,s),(i=this.onResize)==null||i.call(this,this.resizeCol,s)});n(this,"handleUp",()=>{this.resizing=!1,document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp),document.body.style.cursor="",document.body.style.userSelect=""});this.columns=t}start(t,e){t<0||t>=this.columns.count||(this.resizing=!0,this.resizeCol=t,this.startX=e,this.startWidth=this.columns.getWidth(t),document.addEventListener("mousemove",this.handleMove),document.addEventListener("mouseup",this.handleUp),document.body.style.cursor="col-resize",document.body.style.userSelect="none")}destroy(){document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp)}}class Re{constructor(t){n(this,"rows");n(this,"resizing",!1);n(this,"resizeRow",-1);n(this,"startY",0);n(this,"startHeight",0);n(this,"onResize",null);n(this,"handleMove",t=>{var i;if(!this.resizing)return;const e=t.clientY-this.startY,s=Math.max(20,this.startHeight+e);this.rows.setHeight(this.resizeRow,s),(i=this.onResize)==null||i.call(this,this.resizeRow,s)});n(this,"handleUp",()=>{this.resizing=!1,document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp),document.body.style.cursor="",document.body.style.userSelect=""});this.rows=t}start(t,e){this.resizing=!0,this.resizeRow=t,this.startY=e,this.startHeight=this.rows.getHeight(t),document.addEventListener("mousemove",this.handleMove),document.addEventListener("mouseup",this.handleUp),document.body.style.cursor="row-resize",document.body.style.userSelect="none"}destroy(){document.removeEventListener("mousemove",this.handleMove),document.removeEventListener("mouseup",this.handleUp)}}class te{constructor(){n(this,"el",null);n(this,"closeHandler",t=>{this.el&&!this.el.contains(t.target)&&this.close()});n(this,"keyHandler",t=>{t.key==="Escape"&&this.close()})}open(t,e,s,i){this.close(),this.el=document.createElement("div"),this.el.className="wt-context-menu";for(const l of s){if(!(typeof l.visible=="function"?l.visible(i):l.visible??!0))continue;if(l.separator){const a=document.createElement("div");a.className="wt-context-menu-separator",this.el.appendChild(a);continue}const c=typeof l.disabled=="function"?l.disabled(i):l.disabled??!1,h=document.createElement("div");h.className="wt-context-menu-item",c&&h.classList.add("wt-context-menu-item--disabled");const d=document.createElement("span");if(d.textContent=l.label,h.appendChild(d),l.shortcut){const a=document.createElement("span");a.className="wt-context-menu-shortcut",a.textContent=l.shortcut,h.appendChild(a)}if(!c&&l.action){const a=l.action;h.addEventListener("click",g=>{g.stopPropagation(),this.close(),a(i)})}this.el.appendChild(h)}document.body.appendChild(this.el);const o=this.el.getBoundingClientRect();t+o.width>window.innerWidth&&(t=window.innerWidth-o.width-4),e+o.height>window.innerHeight&&(e=window.innerHeight-o.height-4),this.el.style.left=`${Math.max(0,t)}px`,this.el.style.top=`${Math.max(0,e)}px`,requestAnimationFrame(()=>{document.addEventListener("mousedown",this.closeHandler),document.addEventListener("keydown",this.keyHandler)})}close(){this.el&&(this.el.remove(),this.el=null),document.removeEventListener("mousedown",this.closeHandler),document.removeEventListener("keydown",this.keyHandler)}get isOpen(){return this.el!==null}destroy(){this.close()}}class Se{constructor(t,e,s,i,o){n(this,"handleEl");n(this,"shadowEl");n(this,"dragging",!1);n(this,"currentRow",-1);n(this,"currentCol",-1);n(this,"data");n(this,"selection");n(this,"getCellAtPoint",null);n(this,"getCellBounds",null);n(this,"onFill",null);n(this,"onFillCallback",null);n(this,"enabled",!0);n(this,"onMouseDown",t=>{t.preventDefault(),t.stopPropagation();const e=this.selection.getBounds();e&&(this.dragging=!0,this.currentRow=e.r2,this.currentCol=e.c2,document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp),document.body.style.cursor="crosshair",document.body.style.userSelect="none")});n(this,"onMouseMove",t=>{if(!this.dragging||!this.getCellAtPoint)return;const e=this.getCellAtPoint(t.clientX,t.clientY);e&&(this.currentRow=e.row,this.currentCol=e.col,this.updateShadow())});n(this,"onMouseUp",()=>{this.dragging&&(this.dragging=!1,document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.body.style.cursor="",document.body.style.userSelect="",this.shadowEl.style.display="none",this.executeFill(),this.updatePosition())});this.data=e,this.selection=s,this.handleEl=document.createElement("div"),this.handleEl.className="wt-fill-handle",this.handleEl.style.display="none",t.appendChild(this.handleEl),this.shadowEl=document.createElement("div"),this.shadowEl.className="wt-fill-shadow",this.shadowEl.style.display="none",t.appendChild(this.shadowEl),this.handleEl.addEventListener("mousedown",this.onMouseDown)}updatePosition(){const t=this.selection.getBounds();if(!this.enabled||!t||!this.getCellBounds){this.handleEl.style.display="none";return}const e=this.getCellBounds(t.r2,t.c2);this.handleEl.style.display="",this.handleEl.style.left=`${e.x+e.width-4}px`,this.handleEl.style.top=`${e.y+e.height-4}px`}updateShadow(){const t=this.selection.getBounds();if(!t||!this.getCellBounds){this.shadowEl.style.display="none";return}const{r1:e,c1:s,r2:i,c2:o}=t,l=this.currentRow,r=this.currentCol;if(l>=e&&l<=i&&r>=s&&r<=o){this.shadowEl.style.display="none",this.updatePosition();return}const c=Math.min(e,l),h=Math.max(i,l),d=Math.min(s,r),a=Math.max(o,r),g=this.getCellBounds(c,d),p=this.getCellBounds(h,a),w=g.x,C=g.y,E=p.x+p.width-w,b=p.y+p.height-C;this.shadowEl.style.display="",this.shadowEl.style.left=`${w}px`,this.shadowEl.style.top=`${C}px`,this.shadowEl.style.width=`${E}px`,this.shadowEl.style.height=`${b}px`;const v=this.getCellBounds(l,r);this.handleEl.style.left=`${v.x+v.width-4}px`,this.handleEl.style.top=`${v.y+v.height-4}px`}executeFill(){var w,C;const t=this.selection.getBounds();if(!t)return;const{r1:e,c1:s,r2:i,c2:o}=t,l=this.currentRow,r=this.currentCol;if(l>=e&&l<=i&&r>=s&&r<=o)return;const c=l>i?l-i:l<e?e-l:0,h=r>o?r-o:r<s?s-r:0;let d,a;c>0&&h>0?(d="diagonal",a={startRow:Math.min(e,l),startCol:Math.min(s,r),endRow:Math.max(i,l),endCol:Math.max(o,r)}):c>0&&h===0?l>i?(d="down",a={startRow:i+1,startCol:s,endRow:l,endCol:o}):(d="up",a={startRow:l,startCol:s,endRow:e-1,endCol:o}):h>0&&c===0?r>o?(d="right",a={startRow:e,startCol:o+1,endRow:i,endCol:r}):(d="left",a={startRow:e,startCol:r,endRow:i,endCol:s-1}):(d="diagonal",a={startRow:Math.min(e,l),startCol:Math.min(s,r),endRow:Math.max(i,l),endCol:Math.max(o,r)});const g={startRow:e,startCol:s,endRow:i,endCol:o};if(this.onFillCallback){const E=this.onFillCallback(g,a,d);if(E===!0)return;if(Array.isArray(E)){(w=this.onFill)==null||w.call(this,E,g,a,d);return}}const p=this.defaultFill(g,a,d);(C=this.onFill)==null||C.call(this,p,g,a,d)}defaultFill(t,e,s){const i=[],o=t.endRow-t.startRow+1,l=t.endCol-t.startCol+1;for(let r=e.startRow;r<=e.endRow;r++)for(let c=e.startCol;c<=e.endCol;c++){if(r>=t.startRow&&r<=t.endRow&&c>=t.startCol&&c<=t.endCol)continue;const h=t.startRow+((r-t.startRow)%o+o)%o,d=t.startCol+((c-t.startCol)%l+l)%l,a=this.data.getCell(h,d);i.push({row:r,col:c,data:{value:a==null?void 0:a.value}})}return i}destroy(){this.handleEl.remove(),this.shadowEl.remove(),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class Me{constructor(t){n(this,"columns");n(this,"dragging",!1);n(this,"sourceCol",-1);n(this,"targetCol",-1);n(this,"ghostEl",null);n(this,"indicatorEl",null);n(this,"onReorder",null);n(this,"getColAtX",null);n(this,"getColLabel",null);n(this,"onMouseMove",t=>{if(this.dragging&&(this.ghostEl&&(this.ghostEl.style.left=`${t.clientX}px`,this.ghostEl.style.top=`${t.clientY-14}px`),this.getColAtX&&(this.targetCol=this.getColAtX(t.clientX)),this.indicatorEl&&this.targetCol>=0)){const e=this.columns.getX(this.targetCol);this.indicatorEl.style.display="",this.indicatorEl.style.left=`${e}px`}});n(this,"onMouseUp",()=>{var t,e,s;this.dragging&&(this.dragging=!1,document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp),document.body.style.cursor="",document.body.style.userSelect="",(t=this.ghostEl)==null||t.remove(),this.ghostEl=null,(e=this.indicatorEl)==null||e.remove(),this.indicatorEl=null,this.sourceCol!==this.targetCol&&this.targetCol>=0&&((s=this.onReorder)==null||s.call(this,this.sourceCol,this.targetCol)))});this.columns=t}start(t,e,s){var i;this.dragging=!0,this.sourceCol=t,this.targetCol=t,this.ghostEl=document.createElement("div"),this.ghostEl.className="wt-reorder-ghost",this.ghostEl.textContent=((i=this.getColLabel)==null?void 0:i.call(this,t))??String(t),this.ghostEl.style.left=`${e.clientX}px`,this.ghostEl.style.top=`${e.clientY-14}px`,document.body.appendChild(this.ghostEl),this.indicatorEl=document.createElement("div"),this.indicatorEl.className="wt-reorder-indicator",this.indicatorEl.style.display="none",s.appendChild(this.indicatorEl),document.addEventListener("mousemove",this.onMouseMove),document.addEventListener("mouseup",this.onMouseUp),document.body.style.cursor="grabbing",document.body.style.userSelect="none"}destroy(){var t,e;(t=this.ghostEl)==null||t.remove(),(e=this.indicatorEl)==null||e.remove(),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("mouseup",this.onMouseUp)}}class se{constructor(t){n(this,"groups",[]);n(this,"hiddenRows",new Set);n(this,"onChange",null);t&&(this.groups=t.map(e=>({...e})),this.rebuildHidden())}addGroup(t){var e;this.groups.push({...t}),this.rebuildHidden(),(e=this.onChange)==null||e.call(this)}removeGroup(t){var e;this.groups=this.groups.filter(s=>s.startRow!==t),this.rebuildHidden(),(e=this.onChange)==null||e.call(this)}toggleGroup(t){var s;const e=this.groups.find(i=>i.startRow===t);e&&(e.expanded=!e.expanded,this.rebuildHidden(),(s=this.onChange)==null||s.call(this))}expandAll(){var t;for(const e of this.groups)e.expanded=!0;this.rebuildHidden(),(t=this.onChange)==null||t.call(this)}collapseAll(){var t;for(const e of this.groups)e.expanded=!1;this.rebuildHidden(),(t=this.onChange)==null||t.call(this)}isGroupHeader(t){return this.groups.find(e=>e.startRow===t)??null}isHidden(t){return this.hiddenRows.has(t)}getGroups(){return[...this.groups]}rebuildHidden(){this.hiddenRows.clear();for(const t of this.groups)if(!t.expanded)for(let e=1;e<=t.count;e++)this.hiddenRows.add(t.startRow+e)}getFilter(){return t=>!this.hiddenRows.has(t)}clear(){var t;this.groups=[],this.hiddenRows.clear(),(t=this.onChange)==null||t.call(this)}}class ie{constructor(t){n(this,"mapping",[]);n(this,"identity",!0);n(this,"sortState",null);n(this,"filters",new Map);n(this,"data");n(this,"onChange",null);this.data=t,this.rebuild()}get visibleRowCount(){return this.identity?this.data.rowCount:this.mapping.length}toDataRow(t){return this.identity?t:this.mapping[t]??t}toVisualRow(t){return this.identity?t:this.mapping.indexOf(t)}sort(t,e,s){var i;e===null?this.sortState=null:this.sortState={col:t,direction:e,compareFn:s},this.rebuild(),(i=this.onChange)==null||i.call(this)}getSortState(){return this.sortState}clearSort(){var t;this.sortState=null,this.rebuild(),(t=this.onChange)==null||t.call(this)}setFilter(t,e){var s;this.filters.set(t,e),this.rebuild(),(s=this.onChange)==null||s.call(this)}removeFilter(t){var e;this.filters.delete(t),this.rebuild(),(e=this.onChange)==null||e.call(this)}clearFilters(){var t;this.filters.clear(),this.rebuild(),(t=this.onChange)==null||t.call(this)}getActiveFilters(){return Array.from(this.filters.keys())}rebuild(){const t=this.sortState!==null,e=this.filters.size>0;if(!t&&!e){this.identity=!0,this.mapping=[];return}this.identity=!1;let s=[];for(let i=0;i<this.data.rowCount;i++)s.push(i);if(e&&(s=s.filter(i=>{for(const o of this.filters.values())if(!o(i,this.data))return!1;return!0})),t&&this.sortState){const{col:i,direction:o,compareFn:l}=this.sortState,r=o==="desc"?-1:1;s.sort((c,h)=>{var g,p;const d=(g=this.data.getCell(c,i))==null?void 0:g.value,a=(p=this.data.getCell(h,i))==null?void 0:p.value;return l?l(d,a)*r:He(d,a)*r})}this.mapping=s}}function He(u,t){return u==null&&t==null?0:u==null?1:t==null?-1:typeof u=="number"&&typeof t=="number"?u-t:typeof u=="boolean"&&typeof t=="boolean"?u===t?0:u?-1:1:String(u).localeCompare(String(t),void 0,{numeric:!0,sensitivity:"base"})}class oe{constructor(t){n(this,"merges",[]);n(this,"coverMap",new Map);n(this,"onChange",null);if(t)for(const e of t)this.addMerge(e,!1)}key(t,e){return`${t}:${e}`}addMerge(t,e=!0){var s;if(!(t.rowSpan<1||t.colSpan<1)&&!(t.rowSpan===1&&t.colSpan===1)){for(let i=t.row;i<t.row+t.rowSpan;i++)for(let o=t.col;o<t.col+t.colSpan;o++)if(this.coverMap.has(this.key(i,o))){const l=this.coverMap.get(this.key(i,o));this.removeMerge(l.row,l.col,!1)}this.merges.push(t);for(let i=t.row;i<t.row+t.rowSpan;i++)for(let o=t.col;o<t.col+t.colSpan;o++)this.coverMap.set(this.key(i,o),t);e&&((s=this.onChange)==null||s.call(this))}}removeMerge(t,e,s=!0){var l;const i=this.merges.findIndex(r=>r.row===t&&r.col===e);if(i===-1)return!1;const o=this.merges[i];this.merges.splice(i,1);for(let r=o.row;r<o.row+o.rowSpan;r++)for(let c=o.col;c<o.col+o.colSpan;c++)this.coverMap.delete(this.key(r,c));return s&&((l=this.onChange)==null||l.call(this)),!0}getMerge(t,e){return this.coverMap.get(this.key(t,e))??null}isAnchor(t,e){const s=this.coverMap.get(this.key(t,e));return s!==void 0&&s.row===t&&s.col===e}isHidden(t,e){const s=this.coverMap.get(this.key(t,e));return s!==void 0&&(s.row!==t||s.col!==e)}getAll(){return[...this.merges]}clear(){var t;this.merges.length=0,this.coverMap.clear(),(t=this.onChange)==null||t.call(this)}}class ne{constructor(t){n(this,"_page");n(this,"_pageSize");n(this,"_totalRows");n(this,"enabled");n(this,"onChange",null);this.enabled=(t==null?void 0:t.enabled)??!1,this._pageSize=(t==null?void 0:t.pageSize)??50,this._page=(t==null?void 0:t.page)??0,this._totalRows=(t==null?void 0:t.totalRows)??0}get page(){return this._page}get pageSize(){return this._pageSize}get totalRows(){return this._totalRows}get totalPages(){return this._totalRows===0?0:Math.ceil(this._totalRows/this._pageSize)}get startRow(){return this._page*this._pageSize}get endRow(){return Math.min(this.startRow+this._pageSize,this._totalRows)}getState(){return{page:this._page,pageSize:this._pageSize,totalRows:this._totalRows,totalPages:this.totalPages,startRow:this.startRow,endRow:this.endRow}}setPage(t){var s;const e=Math.max(0,Math.min(t,this.totalPages-1));e!==this._page&&(this._page=e,(s=this.onChange)==null||s.call(this,this.getState()))}setPageSize(t){var e;this._pageSize=Math.max(1,t),this._page=Math.min(this._page,this.totalPages-1),this._page<0&&(this._page=0),(e=this.onChange)==null||e.call(this,this.getState())}setTotalRows(t){var e;this._totalRows=t,this._page>=this.totalPages&&(this._page=Math.max(0,this.totalPages-1)),(e=this.onChange)==null||e.call(this,this.getState())}nextPage(){this.setPage(this._page+1)}prevPage(){this.setPage(this._page-1)}firstPage(){this.setPage(0)}lastPage(){this.setPage(this.totalPages-1)}}function $(u){const t=[],e=le(u),s=[];for(let i=0;i<e;i++)s.push([]);return re(u,0,t,s,e),{flatColumns:t,headerRows:s,maxDepth:e}}function le(u){let t=1;for(const e of u)e.children&&e.children.length>0&&(t=Math.max(t,1+le(e.children)));return t}function re(u,t,e,s,i){for(const o of u)if(o.children&&o.children.length>0){const l=e.length;re(o.children,t+1,e,s,i);const r=e.length-l;s[t].push({label:o.label??"",colSpan:r,rowSpan:1,col:l,level:t,config:o})}else{const l=e.length;e.push(o);const r=i-t;s[t].push({label:o.label??"",colSpan:1,rowSpan:r,col:l,level:t,config:o})}}class ke{constructor(t){n(this,"el");n(this,"infoEl");n(this,"prevBtn");n(this,"nextBtn");n(this,"firstBtn");n(this,"lastBtn");n(this,"pageInput");n(this,"clickHandler");n(this,"changeHandler");n(this,"onPageChange",null);this.el=document.createElement("div"),this.el.className="wt-pagination",this.infoEl=document.createElement("span"),this.infoEl.className="wt-pagination-info",this.firstBtn=this.createBtn("first","«"),this.prevBtn=this.createBtn("prev","‹"),this.pageInput=document.createElement("input"),this.pageInput.type="number",this.pageInput.className="wt-pagination-input",this.pageInput.min="1",this.nextBtn=this.createBtn("next","›"),this.lastBtn=this.createBtn("last","»"),this.el.appendChild(this.infoEl),this.el.appendChild(this.firstBtn),this.el.appendChild(this.prevBtn),this.el.appendChild(this.pageInput),this.el.appendChild(this.nextBtn),this.el.appendChild(this.lastBtn),this.clickHandler=e=>{var o,l,r,c;const s=e.target.closest(".wt-pagination-btn");if(!s)return;const i=s.dataset.action;i==="first"?(o=this.onPageChange)==null||o.call(this,0):i==="prev"?(l=this.onPageChange)==null||l.call(this,-1):i==="next"?(r=this.onPageChange)==null||r.call(this,-2):i==="last"&&((c=this.onPageChange)==null||c.call(this,-3))},this.el.addEventListener("click",this.clickHandler),this.changeHandler=()=>{var s;const e=parseInt(this.pageInput.value,10)-1;isNaN(e)||(s=this.onPageChange)==null||s.call(this,e)},this.pageInput.addEventListener("change",this.changeHandler),t.appendChild(this.el)}update(t){this.infoEl.textContent=`${t.startRow+1}-${t.endRow} of ${t.totalRows}`,this.pageInput.value=String(t.page+1),this.pageInput.max=String(t.totalPages),this.prevBtn.disabled=t.page<=0,this.firstBtn.disabled=t.page<=0,this.nextBtn.disabled=t.page>=t.totalPages-1,this.lastBtn.disabled=t.page>=t.totalPages-1}show(){this.el.style.display=""}hide(){this.el.style.display="none"}destroy(){this.el.removeEventListener("click",this.clickHandler),this.pageInput.removeEventListener("change",this.changeHandler),this.el.remove()}createBtn(t,e){const s=document.createElement("button");return s.className="wt-pagination-btn",s.dataset.action=t,s.textContent=e,s}}class Le{constructor(t){n(this,"el");this.el=document.createElement("div"),this.el.className="wt-loading-overlay",this.el.innerHTML='<div class="wt-loading-spinner"></div>',this.el.style.display="none",t.appendChild(this.el)}show(){this.el.style.display=""}hide(){this.el.style.display="none"}get isVisible(){return this.el.style.display!=="none"}destroy(){this.el.remove()}}function ae(u,t,e={}){const{visibleOnly:s=!0,columns:i,includeHeaders:o=!0,headers:l}=e,r=i??Array.from({length:u.colCount},(d,a)=>a),c=[];if(o){const d=r.map((a,g)=>{const p=(l==null?void 0:l[g])??P(a);return W(p)});c.push(d.join(","))}const h=s?t.visibleRowCount:u.rowCount;for(let d=0;d<h;d++){const a=s?t.toDataRow(d):d,g=r.map(p=>{const w=u.getCell(a,p),C=w==null?void 0:w.value;return W(C!=null?String(C):"")});c.push(g.join(","))}return c.join(`
11
+ `)}function he(u,t,e={}){const{visibleOnly:s=!0,columns:i,headers:o}=e,l=i??Array.from({length:u.colCount},(h,d)=>d),r=s?t.visibleRowCount:u.rowCount,c=[];for(let h=0;h<r;h++){const d=s?t.toDataRow(h):h,a={};for(let g=0;g<l.length;g++){const p=l[g],w=(o==null?void 0:o[g])??P(p),C=u.getCell(d,p);a[w]=(C==null?void 0:C.value)??null}c.push(a)}return c}function D(u,t,e){const s=new Blob([u],{type:e}),i=URL.createObjectURL(s),o=document.createElement("a");o.href=i,o.download=t,o.click(),URL.revokeObjectURL(i)}function W(u){return u.includes(",")||u.includes('"')||u.includes(`
12
+ `)?`"${u.replace(/"/g,'""')}"`:u}class _e extends V{constructor(e,s={}){var h,d;super();n(this,"data");n(this,"selection");n(this,"columns");n(this,"rows");n(this,"commands");n(this,"viewMapping");n(this,"merges");n(this,"pagination");n(this,"rowGroups");n(this,"renderer");n(this,"rendererRegistry");n(this,"editorManager");n(this,"keyboard");n(this,"clipboard");n(this,"columnResize");n(this,"rowResize");n(this,"contextMenu");n(this,"autoFit");n(this,"paginationBar",null);n(this,"loadingOverlay");n(this,"fillHandle");n(this,"columnReorder");n(this,"headerRows",[]);n(this,"theme");n(this,"options");n(this,"isDragging",!1);n(this,"_infiniteScrollHandler",null);n(this,"_lazyLoadHandler",null);n(this,"_keydownHandler",null);n(this,"contextMenuItems",[{label:"Copy",shortcut:"Ctrl+C",visible:e=>e.target==="cell",action:()=>this.clipboard.copy()},{label:"Paste",shortcut:"Ctrl+V",visible:e=>e.target==="cell",disabled:e=>e.readOnly,action:()=>this.pasteWithUndo()},{label:"Cut",shortcut:"Ctrl+X",visible:e=>e.target==="cell",disabled:e=>e.readOnly,action:()=>this.cutWithUndo()},{label:"",separator:!0,visible:e=>e.target==="cell"},{label:"Delete content",shortcut:"Del",visible:e=>e.target==="cell"&&e.selectedCount>0,disabled:e=>e.readOnly,action:()=>this.deleteSelected()},{label:"",separator:!0,visible:e=>e.target==="cell"},{label:"Insert row above",visible:e=>e.target==="cell"||e.target==="row-header",disabled:e=>e.readOnly,action:e=>this.insertRow(e.row)},{label:"Insert row below",visible:e=>e.target==="cell"||e.target==="row-header",disabled:e=>e.readOnly,action:e=>this.insertRow(e.row+1)},{label:"Insert column left",visible:e=>e.target==="cell"&&!e.isMultiSelect||e.target==="column-header",disabled:e=>e.readOnly,action:e=>this.insertColumn(e.col)},{label:"Insert column right",visible:e=>e.target==="cell"&&!e.isMultiSelect||e.target==="column-header",disabled:e=>e.readOnly,action:e=>this.insertColumn(e.col+1)},{label:"",separator:!0,visible:e=>e.target==="column-header"},{label:"Sort ascending",visible:e=>e.target==="column-header",action:e=>this.sort(e.col,"asc")},{label:"Sort descending",visible:e=>e.target==="column-header",action:e=>this.sort(e.col,"desc")},{label:"Clear sort",visible:e=>e.target==="column-header"&&this.viewMapping.getSortState()!==null,action:()=>this.clearSort()},{label:"",separator:!0,visible:e=>e.target==="column-header"},{label:"Auto-fit column width",visible:e=>e.target==="column-header"||e.target==="cell",action:e=>this.autoFitColumn(e.col>=0?e.col:0)},{label:"",separator:!0,visible:e=>e.target==="row-header"},{label:"Select row",visible:e=>e.target==="row-header",action:e=>this.selection.selectRow(e.row)},{label:"",separator:!0},{label:"Undo",shortcut:"Ctrl+Z",disabled:e=>!e.canUndo,action:()=>this.undo()},{label:"Redo",shortcut:"Ctrl+Y",disabled:e=>!e.canRedo,action:()=>this.redo()}]);this.options=s;const i=s.defaultRowHeight??28,o=s.defaultColWidth??100;let l=s.columns??[];if(l.some(a=>a.children&&a.children.length>0)){const a=$(l);l=a.flatColumns,this.headerRows=a.headerRows}const r=s.colCount??(l.length||26);let c;if(s.mode==="table"&&s.tableData?c=s.tableData.length:c=s.rowCount??100,this.theme={...pe,...s.theme},this.data=new O(c,r),this.selection=new U(c,r),s.infinite&&(this.selection.infinite=!0),this.columns=new z(r,o,l),this.rows=new G(c,i),this.commands=new X(s.undoLimit??100),this.viewMapping=new ie(this.data),this.merges=new oe,this.pagination=new ne(s.pagination),this.rowGroups=new se((h=s.rowGroups)==null?void 0:h.map(a=>({...a,expanded:a.expanded??!0,depth:a.depth??0}))),this.rendererRegistry=new ee,this.renderer=new fe(e),this.editorManager=new Ce(this.renderer.getScrollContainer()),this.columnResize=new xe(this.columns),this.columnReorder=new Me(this.columns),this.rowResize=new Re(this.rows),this.contextMenu=new te,this.clipboard=new be(this.data,this.selection),this.fillHandle=new Se(this.renderer.getViewportEl(),this.data,this.selection,this.columns,this.rows),this.keyboard=new Ee(this.selection,{onStartEdit:(a,g,p)=>{this.options.allowEditing!==!1&&this.startEditing(a,g,p)},onDelete:()=>this.deleteSelected(),onCopy:()=>{this.options.allowClipboard!==!1&&this.clipboard.copy()},onPaste:()=>{this.options.allowClipboard!==!1&&this.pasteWithUndo()},onCut:()=>{this.options.allowClipboard!==!1&&this.cutWithUndo()},onUndo:()=>{this.options.allowUndoRedo!==!1&&this.undo()},onRedo:()=>{this.options.allowUndoRedo!==!1&&this.redo()},onScrollTo:(a,g)=>this.renderer.scrollToCell(a,g)}),this.wireCallbacks(),this.renderer.init({data:this.data,columns:this.columns,rows:this.rows,selection:this.selection,viewMapping:this.viewMapping,merges:this.merges,theme:this.theme,renderers:this.rendererRegistry.getAll(),defaultRenderer:this.rendererRegistry.defaultRenderer,defaultCellType:s.defaultCellType??"text",showRowHeaders:s.showRowHeaders??!0,showColHeaders:s.showColHeaders??!0,frozenRows:s.frozenRows??0,frozenCols:s.frozenCols??0,autoRowHeight:s.autoRowHeight??!1,showGridLines:s.showGridLines??!0,showBorder:s.showBorder??!0,layout:s.layout??"scroll",headerRows:this.headerRows.length>0?this.headerRows:void 0}),this.autoFit=new me(e,this.data,this.columns,this.rows,this.rendererRegistry.getAll(),this.rendererRegistry.defaultRenderer),this.fillHandle.getCellBounds=(a,g)=>({x:this.columns.getX(g),y:this.rows.getY(a),width:this.columns.getWidth(g),height:this.rows.getHeight(a)}),this.fillHandle.getCellAtPoint=(a,g)=>{const p=this.renderer.getScrollContainer(),w=p.getBoundingClientRect(),C=p.scrollLeft,E=p.scrollTop,b=a-w.left+C,v=g-w.top+E,_=this.rows.getRowAtY(v),T=this.columns.getColAtX(b);return _>=0&&T>=0?{row:_,col:T}:null},this.fillHandle.enabled=s.allowFillHandle!==!1,this.fillHandle.onFillCallback=s.onFill??null,this.fillHandle.onFill=(a,g,p)=>{if(a.length>0){const w=new F(this.data,a);this.execCommand(w),this.emit("data:patch",{patches:a})}this.selection.extendTo(p.endRow,p.endCol)},this.loadingOverlay=new Le(e),s.loading&&this.loadingOverlay.show(),(d=s.pagination)!=null&&d.enabled&&(this.paginationBar=new ke(e),this.pagination.setTotalRows(s.pagination.totalRows??c),this.paginationBar.update(this.pagination.getState()),this.paginationBar.onPageChange=a=>{a===-1?this.pagination.prevPage():a===-2?this.pagination.nextPage():a===-3?this.pagination.lastPage():this.pagination.setPage(a)},this.pagination.onChange=a=>{var g,p,w;(g=this.paginationBar)==null||g.update(a),(w=(p=this.options).onPageChange)==null||w.call(p,a.page,a.pageSize),this.renderer.scheduleRender()}),s.mode==="table"&&s.tableData?this.loadTableData(s.tableData,l):s.data&&this.data.applyPatch(s.data),s.merges)for(const a of s.merges)this.merges.addMerge(a,!1);if(s.sort&&this.viewMapping.sort(s.sort.col,s.sort.direction),s.filters)for(const[a,g]of Object.entries(s.filters))this.viewMapping.setFilter(Number(a),g);if(this.merges.onChange=()=>{this.renderer.scheduleRender()},this.viewMapping.onChange=()=>{this.renderer.updateLayout(),this.renderer.scheduleRender()},s.infinite)if(s.layout==="auto")this._infiniteScrollHandler=()=>{let p=!1;const w=document.documentElement.scrollHeight,C=document.documentElement.scrollWidth,E=window.scrollY+window.innerHeight,b=window.scrollX+window.innerWidth;w-E<200&&(this.data.rowCount+=20,this.rows.setCount(this.data.rowCount),this.viewMapping.rebuild(),p=!0),C-b<200&&(this.data.colCount+=20,this.columns.setCount(this.data.colCount),p=!0),p&&(this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.refresh())},window.addEventListener("scroll",this._infiniteScrollHandler,{passive:!0});else{const p=this.renderer.getScrollContainer();this._infiniteScrollHandler=()=>{p.scrollTop+p.clientHeight>=p.scrollHeight-200&&(this.data.rowCount+=20,this.rows.setCount(this.data.rowCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.viewMapping.rebuild(),this.refresh()),p.scrollLeft+p.clientWidth>=p.scrollWidth-200&&(this.data.colCount+=20,this.columns.setCount(this.data.colCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.refresh())},p.addEventListener("scroll",this._infiniteScrollHandler,{passive:!0})}this.renderer.getContainer().focus()}wireCallbacks(){if(this.data.onChange=()=>{this.renderer.scheduleRender()},this.selection.onChange=()=>{var e,s;this.options.infinite&&this.selection.focus&&this.expandIfNeeded(this.selection.focus.row,this.selection.focus.col),this.renderer.scheduleRender(),this.fillHandle.updatePosition(),this.emit("selection:change",{ranges:this.selection.ranges}),(s=(e=this.options).onSelectionChange)==null||s.call(e,this.selection.ranges)},this.renderer.onCellClick=(e,s,i)=>{this.contextMenu.isOpen&&this.contextMenu.close(),this.editorManager.isEditing&&this.editorManager.close(!0);const o=this.data.getCell(e,s),l=this.columns.getConfig(s),r=this.options.defaultCellType??"text";if(((o==null?void 0:o.type)??(l==null?void 0:l.type)??r)==="checkbox"&&!this.options.readOnly&&this.options.allowEditing!==!1&&!(l!=null&&l.readOnly)&&!(o!=null&&o.readOnly)){const h=!!(o!=null&&o.value);this.setCellValue(e,s,!h),this.options.allowSelection!==!1&&this.selection.focusCell(e,s),this.emit("cell:click",{row:e,col:s,event:i});return}if(this.options.allowSelection!==!1&&(i.shiftKey&&this.options.allowRangeSelection!==!1?this.selection.extendTo(e,s):(i.ctrlKey||i.metaKey)&&this.options.allowRangeSelection!==!1?this.selection.addRange({startRow:e,startCol:s,endRow:e,endCol:s}):this.selection.focusCell(e,s)),this.emit("cell:click",{row:e,col:s,event:i}),this.options.allowRangeSelection!==!1&&this.options.allowSelection!==!1){this.isDragging=!0;const h=a=>{if(!this.isDragging)return;const g=this.renderer.getCellFromEvent(a);g&&this.selection.extendTo(g.row,g.col)},d=()=>{this.isDragging=!1,document.removeEventListener("mousemove",h),document.removeEventListener("mouseup",d)};document.addEventListener("mousemove",h),document.addEventListener("mouseup",d)}},this.renderer.onCellDblClick=(e,s,i)=>{this.emit("cell:dblclick",{row:e,col:s,event:i}),!this.options.readOnly&&this.options.allowEditing!==!1&&this.startEditing(e,s)},this.renderer.onCellContextMenu=(e,s,i)=>{i.preventDefault(),this.emit("cell:contextmenu",{row:e,col:s,event:i}),this.options.allowContextMenu!==!1&&(this.options.allowSelection!==!1&&!this.selection.isSelected(e,s)&&this.selection.focusCell(e,s),this.openContextMenu(i.clientX,i.clientY,e,s))},this.renderer.onHeaderClick=(e,s,i)=>{if(e==="col")this.options.allowColReorder?this.columnReorder.start(s,i,this.renderer.getContainer()):this.selection.selectColumn(s);else if(e==="row"){const o=i.target.closest(".wt-row-header-cell");if(o){const l=o.getBoundingClientRect();if(i.clientY>l.bottom-4&&this.options.allowRowResize!==!1){this.rowResize.start(s,i.clientY);return}}this.selection.selectRow(s)}else e==="corner"&&this.selection.selectAll()},this.renderer.onColumnResizeStart=(e,s)=>{this.options.allowColResize!==!1&&this.columnResize.start(e,s)},this.columnResize.onResize=(e,s)=>{this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("column:resize",{col:e,width:s})},this.rowResize.onResize=(e,s)=>{this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("row:resize",{row:e,height:s})},this.renderer.onScroll=e=>{var s,i;this.emit("scroll",{viewport:e}),(i=(s=this.options).onScroll)==null||i.call(s,e)},this.editorManager.onClose=(e,s,i,o)=>{var l,r,c;if(!o&&i!==void 0){const h=(l=this.data.getCell(e,s))==null?void 0:l.value,d=new A(this.data,e,s,i);this.execCommand(d),this.emit("cell:change",{row:e,col:s,oldValue:h,newValue:i}),(c=(r=this.options).onCellChange)==null||c.call(r,e,s,h,i)}this.emit("editor:close",{row:e,col:s,value:i,cancelled:o}),this.renderer.getContainer().focus()},this._keydownHandler=e=>{this.options.allowKeyboardNav!==!1&&(this.editorManager.isEditing||this.keyboard.handleKeyDown(e))},this.renderer.getContainer().addEventListener("keydown",this._keydownHandler),this.renderer.onHeaderContextMenu=(e,s,i)=>{const o=e==="col"?"column-header":"row-header",l=e==="row"?s:-1,r=e==="col"?s:-1,c=this.buildMenuContext(l,r,o);this.contextMenu.open(i.clientX,i.clientY,this.contextMenuItems,c)},this.clipboard.onChange=e=>{this.emit("data:patch",{patches:e})},this.columnReorder.getColAtX=e=>{const s=this.renderer.getScrollContainer(),i=s.getBoundingClientRect();return this.columns.getColAtX(e-i.left+s.scrollLeft)},this.columnReorder.getColLabel=e=>{var s;return((s=this.columns.getConfig(e))==null?void 0:s.label)??z.columnLabel(e)},this.columnReorder.onReorder=(e,s)=>{this.reorderColumn(e,s)},this.rowGroups.onChange=()=>{const e=this.rowGroups.getFilter();this.viewMapping.setFilter(-1,s=>e(s))},this.options.rowGroups&&this.options.rowGroups.length>0){const e=this.rowGroups.getFilter();this.viewMapping.setFilter(-1,s=>e(s))}if(this.options.onLoadMore){const e=this.options.onLoadMore,s=200;if(this.options.layout==="auto")this._lazyLoadHandler=()=>{const i=document.documentElement.scrollHeight,o=window.scrollY+window.innerHeight;i-o<s&&e("down")},window.addEventListener("scroll",this._lazyLoadHandler,{passive:!0});else{const i=this.renderer.getScrollContainer();this._lazyLoadHandler=()=>{i.scrollTop+i.clientHeight>=i.scrollHeight-s&&e("down"),i.scrollLeft+i.clientWidth>=i.scrollWidth-s&&e("right")},i.addEventListener("scroll",this._lazyLoadHandler,{passive:!0})}}}buildMenuContext(e,s,i="cell"){const o=this.selection.getBounds();let l=0;return this.selection.forEachSelected(()=>{l++}),{target:i,row:e,col:s,selectedCount:l,isMultiSelect:l>1,isFullRow:o?o.c1===0&&o.c2===this.data.colCount-1:!1,isFullCol:o?o.r1===0&&o.r2===this.data.rowCount-1:!1,readOnly:!!this.options.readOnly,canUndo:this.commands.canUndo,canRedo:this.commands.canRedo}}openContextMenu(e,s,i,o){const l=this.buildMenuContext(i,o);this.contextMenu.open(e,s,this.contextMenuItems,l)}setCell(e,s,i){this.data.setCell(e,s,i)}getCell(e,s){return this.data.getCell(e,s)}setCellValue(e,s,i){var r;const o=(r=this.data.getCell(e,s))==null?void 0:r.value,l=new A(this.data,e,s,i);this.execCommand(l),this.emit("cell:change",{row:e,col:s,oldValue:o,newValue:i})}deleteCell(e,s){this.data.deleteCell(e,s)}applyPatch(e){const s=new F(this.data,e);this.execCommand(s),this.emit("data:patch",{patches:e})}transaction(e){this.data.transaction(e)}undo(){const e=this.commands.undo();if(e){const s=e.getChanges().map(i=>({row:i.row,col:i.col,oldValue:i.newValue,newValue:i.oldValue}));this.emit("command:undo",{changes:s})}}redo(){const e=this.commands.redo();e&&this.emit("command:redo",{changes:e.getChanges()})}getSelection(){return[...this.selection.ranges]}getSelectionInfo(){return this.selection.getInfo()}setSelection(e){if(e.length>0){this.selection.focusCell(e[0].startRow,e[0].startCol);for(let s=1;s<e.length;s++)this.selection.addRange(e[s])}}scrollTo(e,s){this.renderer.scrollToCell(e,s)}registerRenderer(e,s){this.rendererRegistry.register(e,s)}registerEditor(e,s){this.editorManager.register(e,s)}setColumnWidth(e,s){this.columns.setWidth(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender()}setRowHeight(e,s){this.rows.setHeight(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender()}autoFitColumn(e){const s=this.autoFit.autoFitColumn(e);this.columns.setWidth(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("column:resize",{col:e,width:s})}autoFitRow(e){const s=this.autoFit.autoFitRow(e);this.rows.setHeight(e,s),this.renderer.updateLayout(),this.renderer.scheduleRender(),this.emit("row:resize",{row:e,height:s})}insertRow(e){this.data.rowCount+=1,this.rows.setCount(this.data.rowCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.data.transaction(()=>{for(let s=this.data.rowCount-1;s>e;s--)for(let i=0;i<this.data.colCount;i++){const o=this.data.getCell(s-1,i);o?this.data.setCell(s,i,{...o}):this.data.deleteCell(s,i)}for(let s=0;s<this.data.colCount;s++)this.data.deleteCell(e,s)}),this.renderer.updateLayout(),this.renderer.scheduleRender()}insertColumn(e){this.data.colCount+=1,this.columns.setCount(this.data.colCount),this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.data.transaction(()=>{for(let s=0;s<this.data.rowCount;s++){for(let i=this.data.colCount-1;i>e;i--){const o=this.data.getCell(s,i-1);o?this.data.setCell(s,i,{...o}):this.data.deleteCell(s,i)}this.data.deleteCell(s,e)}}),this.renderer.updateLayout(),this.renderer.scheduleRender()}sort(e,s,i){var o;if(this.options.onSort){const l=(o=this.columns.getConfig(e))==null?void 0:o.key;if(this.options.onSort(e,s,l)===!0)return}this.viewMapping.sort(e,s,i)}clearSort(){this.options.onSort&&this.options.onSort(-1,null)===!0||this.viewMapping.clearSort()}getSortState(){return this.viewMapping.getSortState()}setFilter(e,s){var i;if(this.options.onFilter){const o=(i=this.columns.getConfig(e))==null?void 0:i.key;if(this.options.onFilter(e,o,!0)===!0)return}this.viewMapping.setFilter(e,s)}removeFilter(e){var s;if(this.options.onFilter){const i=(s=this.columns.getConfig(e))==null?void 0:s.key;if(this.options.onFilter(e,i,!1)===!0)return}this.viewMapping.removeFilter(e)}clearFilters(){this.viewMapping.clearFilters()}getActiveFilters(){return this.viewMapping.getActiveFilters()}mergeCells(e,s,i,o){this.merges.addMerge({row:e,col:s,rowSpan:i,colSpan:o}),this.renderer.scheduleRender()}unmergeCells(e,s){this.merges.removeMerge(e,s),this.renderer.scheduleRender()}getMerge(e,s){return this.merges.getMerge(e,s)}clearMerges(){this.merges.clear(),this.renderer.scheduleRender()}addRowGroup(e,s,i,o=!0){this.rowGroups.addGroup({startRow:e,count:s,label:i,expanded:o,depth:0})}removeRowGroup(e){this.rowGroups.removeGroup(e)}toggleRowGroup(e){this.rowGroups.toggleGroup(e)}expandAllGroups(){this.rowGroups.expandAll()}collapseAllGroups(){this.rowGroups.collapseAll()}exportCSV(e){return ae(this.data,this.viewMapping,e)}exportJSON(e){return he(this.data,this.viewMapping,e)}downloadCSV(e="export.csv",s){const i=this.exportCSV(s);D(i,e,"text/csv;charset=utf-8")}downloadJSON(e="export.json",s){const i=JSON.stringify(this.exportJSON(s),null,2);D(i,e,"application/json")}getViewport(){return this.renderer.getViewport()}refresh(){this.renderer.updateLayout(),this.renderer.scheduleRender()}destroy(){var e;this._keydownHandler&&this.renderer.getContainer().removeEventListener("keydown",this._keydownHandler),this._infiniteScrollHandler&&(window.removeEventListener("scroll",this._infiniteScrollHandler),this.renderer.getScrollContainer().removeEventListener("scroll",this._infiniteScrollHandler)),this._lazyLoadHandler&&(window.removeEventListener("scroll",this._lazyLoadHandler),this.renderer.getScrollContainer().removeEventListener("scroll",this._lazyLoadHandler)),this.fillHandle.destroy(),this.columnReorder.destroy(),this.editorManager.destroy(),this.columnResize.destroy(),this.rowResize.destroy(),this.contextMenu.destroy(),this.autoFit.destroy(),this.loadingOverlay.destroy(),(e=this.paginationBar)==null||e.destroy(),this.renderer.destroy(),this.removeAllListeners()}startEditing(e,s,i){if(this.options.readOnly)return;const o=this.columns.getConfig(s),l=this.data.getCell(e,s);if(o!=null&&o.readOnly||l!=null&&l.readOnly)return;const r=this.options.defaultCellType??"text",c=(l==null?void 0:l.type)??(o==null?void 0:o.type)??r,h=(o==null?void 0:o.editor)??c;if(h==="blank"){this.emit("editor:open",{row:e,col:s}),this.emit("editor:close",{row:e,col:s,value:void 0,cancelled:!0});return}const d=this.renderer.getCellBounds(e,s),a=l==null?void 0:l.value;this.emit("editor:open",{row:e,col:s}),this.editorManager.open(e,s,h,a,d,l,i)}deleteSelected(){if(this.options.readOnly)return;const e=[];if(this.selection.forEachSelected((s,i)=>{this.data.hasCell(s,i)&&e.push({row:s,col:i})}),e.length>0){const s=new Y(this.data,e);this.execCommand(s)}}async pasteWithUndo(){const e=this.selection.focus;if(!e)return;let s;try{s=await navigator.clipboard.readText()}catch{return}const i=s.split(`
13
+ `).map(r=>r.split(" "));if(i.length===0)return;const o=i.length===1&&i[0].length===1,l=[];if(o&&!this.isFullRowOrColSelected()){const r=i[0][0];this.selection.forEachSelected((c,h)=>{c<this.data.rowCount&&h<this.data.colCount&&l.push({row:c,col:h,data:{value:r}})})}else for(let r=0;r<i.length;r++)for(let c=0;c<i[r].length;c++){const h=e.row+r,d=e.col+c;h>=this.data.rowCount||d>=this.data.colCount||l.push({row:h,col:d,data:{value:i[r][c]}})}if(l.length>0){const r=new F(this.data,l);this.execCommand(r),this.emit("data:patch",{patches:l})}}async cutWithUndo(){await this.clipboard.copy(),this.deleteSelected()}execCommand(e){this.commands.execute(e),this.emit("command:execute",{changes:e.getChanges()})}reorderColumn(e,s){if(e===s)return;this.data.transaction(()=>{for(let l=0;l<this.data.rowCount;l++){const r=[];for(let h=0;h<this.data.colCount;h++)r.push(this.data.getCell(l,h));const c=r.splice(e,1)[0];r.splice(s,0,c);for(let h=0;h<r.length;h++)r[h]?this.data.setCell(l,h,r[h]):this.data.deleteCell(l,h)}});const i=[];for(let l=0;l<this.columns.count;l++)i.push(this.columns.getWidth(l));const o=i.splice(e,1)[0];i.splice(s,0,o);for(let l=0;l<i.length;l++)this.columns.setWidth(l,i[l]);this.refresh()}expandIfNeeded(e,s){let i=!1;if(e>=this.data.rowCount){const o=e+2;this.data.rowCount=o,this.rows.setCount(o),this.viewMapping.rebuild(),i=!0}if(s>=this.data.colCount){const o=s+2;this.data.colCount=o,this.columns.setCount(o),i=!0}i&&(this.selection.setDimensions(this.data.rowCount,this.data.colCount),this.refresh())}isFullRowOrColSelected(){const e=this.selection.getBounds();return e?e.c1===0&&e.c2===this.data.colCount-1||e.r1===0&&e.r2===this.data.rowCount-1:!1}loadTableData(e,s){const i=new Map;s.forEach((o,l)=>{o.key&&i.set(o.key,l)}),this.data.transaction(()=>{for(let o=0;o<e.length;o++){const l=e[o];for(const[r,c]of Object.entries(l)){const h=i.get(r);h!==void 0&&this.data.setCell(o,h,{value:c})}}})}setTableData(e){const s=this.options.columns??[];let i=s;s.some(o=>o.children&&o.children.length>0)&&(i=$(s).flatColumns),this.data.clear(),this.data.rowCount=e.length,this.rows.setCount(e.length),this.selection.setDimensions(e.length,this.data.colCount),this.loadTableData(e,i),this.pagination.enabled&&this.pagination.setTotalRows(e.length),this.viewMapping.rebuild(),this.refresh()}setLoading(e){e?this.loadingOverlay.show():this.loadingOverlay.hide()}get isLoading(){return this.loadingOverlay.isVisible}setPage(e){this.pagination.setPage(e)}setPageSize(e){this.pagination.setPageSize(e)}getPaginationState(){return this.pagination.getState()}}class Te{constructor(t){n(this,"config");n(this,"container");n(this,"listEl");n(this,"searchInput",null);n(this,"selected",new Set);n(this,"options",[]);n(this,"highlightIndex",-1);n(this,"searchInputHandler",null);n(this,"handleItemClick",t=>{const e=t.target.closest(".wt-dropdown-item");if(!e)return;t.stopPropagation();const s=parseInt(e.dataset.index??"",10);if(isNaN(s)||s<0||s>=this.options.length)return;const i=this.options[s];i.disabled||this.selectOption(i)});n(this,"handleKey",t=>{const e=this.listEl.children;switch(t.key){case"ArrowDown":t.preventDefault(),this.highlightIndex=Math.min(this.highlightIndex+1,e.length-1),this.updateHighlight();break;case"ArrowUp":t.preventDefault(),this.highlightIndex=Math.max(this.highlightIndex-1,0),this.updateHighlight();break;case"Enter":t.preventDefault(),this.highlightIndex>=0&&this.highlightIndex<this.options.length&&this.selectOption(this.options[this.highlightIndex]);break}});this.config=t}createElement(t){return this.container=document.createElement("div"),this.container.className="wt-dropdown",this.config.searchable&&(this.searchInput=document.createElement("input"),this.searchInput.type="text",this.searchInput.className="wt-dropdown-search",this.searchInput.placeholder=this.config.placeholder??"Search...",this.container.appendChild(this.searchInput),this.searchInputHandler=()=>{this.loadOptions(this.searchInput.value)},this.searchInput.addEventListener("input",this.searchInputHandler)),this.listEl=document.createElement("div"),this.listEl.className="wt-dropdown-list",this.container.appendChild(this.listEl),this.listEl.addEventListener("click",this.handleItemClick),t.appendChild(this.container),this.container.addEventListener("keydown",this.handleKey),this.container}open(t,e,s){this.config.multiple&&Array.isArray(t)?this.selected=new Set(t):t!=null&&(this.selected=new Set([t])),this.loadOptions(""),requestAnimationFrame(()=>{this.searchInput?this.searchInput.focus():this.container.focus()})}getValue(){return this.config.multiple?Array.from(this.selected):this.selected.size>0?this.selected.values().next().value:null}close(){this.searchInput&&this.searchInputHandler&&this.searchInput.removeEventListener("input",this.searchInputHandler),this.listEl.removeEventListener("click",this.handleItemClick),this.container.removeEventListener("keydown",this.handleKey),this.container.remove()}async loadOptions(t){if(this.config.source)this.options=await this.config.source(t,0,0);else if(this.config.options){const e=t.toLowerCase();this.options=e?this.config.options.filter(s=>s.label.toLowerCase().includes(e)):this.config.options}this.renderOptions()}renderOptions(){this.listEl.innerHTML="",this.highlightIndex=-1;for(let t=0;t<this.options.length;t++){const e=this.options[t],s=document.createElement("div");if(s.className="wt-dropdown-item",s.dataset.index=String(t),this.selected.has(e.value)&&s.classList.add("wt-dropdown-item--selected"),e.disabled&&s.classList.add("wt-dropdown-item--disabled"),this.config.renderOption)this.config.renderOption(e,s);else if(s.textContent=e.label,e.icon){const i=document.createElement("span");i.className="wt-dropdown-icon",i.textContent=e.icon,s.prepend(i)}this.listEl.appendChild(s)}}selectOption(t){this.config.multiple?(this.selected.has(t.value)?this.selected.delete(t.value):this.selected.add(t.value),this.renderOptions()):(this.selected.clear(),this.selected.add(t.value))}updateHighlight(){var e;const t=this.listEl.children;for(let s=0;s<t.length;s++)t[s].classList.toggle("wt-dropdown-item--highlight",s===this.highlightIndex);(e=t[this.highlightIndex])==null||e.scrollIntoView({block:"nearest"})}}class Ie{constructor(t){n(this,"el");n(this,"onAttempt");n(this,"row",-1);n(this,"col",-1);this.onAttempt=t??null}createElement(t){return this.el=document.createElement("div"),t.appendChild(this.el),this.el}open(t,e,s){this.onAttempt&&this.onAttempt(this.row,this.col)}setPosition(t,e){this.row=t,this.col=e}getValue(){}close(){var t;(t=this.el)==null||t.remove()}}const Be={bgColor:"#ffffff",cellBgColor:"#ffffff",cellTextColor:"#1e293b",headerBgColor:"#f8fafc",headerTextColor:"#475569",gridLineColor:"#e2e8f0",selectionBgColor:"rgba(59, 130, 246, 0.08)",selectionBorderColor:"#3b82f6",focusBorderColor:"#3b82f6",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:13,headerFontSize:12,cellPadding:8,headerHeight:28,rowHeaderWidth:50},Pe={bgColor:"#0f172a",cellBgColor:"#1e293b",cellTextColor:"#e2e8f0",headerBgColor:"#0f172a",headerTextColor:"#94a3b8",gridLineColor:"#334155",selectionBgColor:"rgba(59, 130, 246, 0.15)",selectionBorderColor:"#3b82f6",focusBorderColor:"#60a5fa",fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',fontSize:13,headerFontSize:12,cellPadding:8,headerHeight:28,rowHeaderWidth:50},Fe={bgColor:"#ffffff",cellBgColor:"#ffffff",cellTextColor:"#111827",headerBgColor:"#ffffff",headerTextColor:"#9ca3af",gridLineColor:"#f3f4f6",selectionBgColor:"rgba(99, 102, 241, 0.06)",selectionBorderColor:"#6366f1",focusBorderColor:"#6366f1",fontFamily:'"Inter", -apple-system, BlinkMacSystemFont, sans-serif',fontSize:13,headerFontSize:11,cellPadding:10,headerHeight:32,rowHeaderWidth:44};exports.BadgeRenderer=q;exports.BlankEditor=Ie;exports.BlankRenderer=Q;exports.CheckboxRenderer=j;exports.ColumnModel=z;exports.CommandBus=X;exports.ContextMenu=te;exports.DataModel=O;exports.DeleteCellsCommand=Y;exports.DropdownEditor=Te;exports.EventEmitter=V;exports.MergeModel=oe;exports.NumberRenderer=J;exports.PaginationModel=ne;exports.PatchCommand=F;exports.ProgressRenderer=Z;exports.RendererRegistry=ee;exports.RowGroupModel=se;exports.RowModel=G;exports.SelectionModel=U;exports.SetCellValueCommand=A;exports.THEME_DARK=Pe;exports.THEME_LIGHT=Be;exports.THEME_MINIMAL=Fe;exports.TextRenderer=K;exports.ViewMapping=ie;exports.WanderTable=_e;exports.columnLabel=P;exports.downloadFile=D;exports.exportCSV=ae;exports.exportJSON=he;exports.flattenColumns=$;
14
+ //# sourceMappingURL=wandertable.cjs.map