@koeroesi86/canvas-grid 26.11.8 → 26.11.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/build/types/types.d.ts +64 -0
- package/build/types/utils/cell-editors.d.ts +5 -0
- package/build/types/utils/data-store.d.ts +5 -0
- package/build/types/utils/edit-value.d.ts +18 -0
- package/build/types/utils/selection-navigation.d.ts +5 -0
- package/build/types/web-component.d.ts +49 -2
- package/build/web-component.js +2 -2
- package/build/web-component.js.map +1 -1
- package/build/web-component.mjs +420 -127
- package/build/web-component.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ Live demo and feature overview: https://koeroesi86.github.io/canvas-grid/
|
|
|
17
17
|
- [API reference](docs/api.md): data model, methods, properties
|
|
18
18
|
- [Sorting](docs/sorting.md)
|
|
19
19
|
- [Selection](docs/selection.md)
|
|
20
|
+
- [Editing](docs/editing.md)
|
|
20
21
|
- [Theming](docs/theming.md): CSS custom properties, light and dark
|
|
21
22
|
- [Custom renderers and layers](docs/renderers.md)
|
|
22
23
|
- [AG Grid-style adapter](docs/ag-grid-adapter.md)
|
package/build/types/types.d.ts
CHANGED
|
@@ -153,3 +153,67 @@ export interface CellRenderer {
|
|
|
153
153
|
}
|
|
154
154
|
/** A renderer, or the name it was registered under. */
|
|
155
155
|
export type RendererRef = string | CellRenderer;
|
|
156
|
+
/** A cell by the ids of its row and column, with the value stored in it. */
|
|
157
|
+
export interface CellEditContext {
|
|
158
|
+
rowId: RowId;
|
|
159
|
+
rowIndex: number;
|
|
160
|
+
columnId: Key;
|
|
161
|
+
columnIndex: number;
|
|
162
|
+
/** The raw value stored in the cell. */
|
|
163
|
+
value: unknown;
|
|
164
|
+
}
|
|
165
|
+
/** Whether a column's cells can be edited: for all of them, or decided per cell. */
|
|
166
|
+
export type CellEditable = boolean | ((cell: CellEditContext) => boolean);
|
|
167
|
+
export interface SelectOption {
|
|
168
|
+
value: unknown;
|
|
169
|
+
/** Text shown for the option; defaults to the value as text. */
|
|
170
|
+
label?: string;
|
|
171
|
+
}
|
|
172
|
+
/** The built-in editors: `'text'`, `'number'`, a `'checkbox'` for booleans, or a `select` among `options`. */
|
|
173
|
+
export type BuiltInCellEditor = 'text' | 'number' | 'checkbox' | {
|
|
174
|
+
type: 'select';
|
|
175
|
+
options: readonly (string | number | SelectOption)[];
|
|
176
|
+
};
|
|
177
|
+
/** What a custom editor is built from. */
|
|
178
|
+
export interface CellEditorContext extends CellEditContext {
|
|
179
|
+
/** The key that started editing by typing; the editor starts with this text instead of the value. Undefined otherwise. */
|
|
180
|
+
initialText: string | undefined;
|
|
181
|
+
/** Ends editing with the editor's current value, as Enter does. */
|
|
182
|
+
commit(): void;
|
|
183
|
+
/** Ends editing and keeps the old value, as Escape does. */
|
|
184
|
+
cancel(): void;
|
|
185
|
+
}
|
|
186
|
+
/** A custom editor: the grid puts `element` over the cell, focuses it, and asks `getValue` when the user commits. */
|
|
187
|
+
export interface CellEditorInstance {
|
|
188
|
+
element: HTMLElement;
|
|
189
|
+
/** The edited value. Strings from the built-in text and number editors go through the column's `valueParser`; a custom editor's value is used as it is. */
|
|
190
|
+
getValue(): unknown;
|
|
191
|
+
/** Called instead of focusing `element`. */
|
|
192
|
+
focus?(): void;
|
|
193
|
+
/** Called each time the grid moved the editor (scrolling, resizing), and with `false` while it is clipped out of sight; for parts that sit outside `element`, such as a popup. */
|
|
194
|
+
place?(visible: boolean): void;
|
|
195
|
+
/** Called when editing ended, to clean up. */
|
|
196
|
+
destroy?(): void;
|
|
197
|
+
}
|
|
198
|
+
export type CustomCellEditor = (context: CellEditorContext) => CellEditorInstance;
|
|
199
|
+
export type CellEditor = BuiltInCellEditor | CustomCellEditor;
|
|
200
|
+
/** A change about to be written: what `valueSetter` and `validator` get. */
|
|
201
|
+
export interface CellValueChange extends CellEditContext {
|
|
202
|
+
/** The value the cell holds now (`value` is the same). */
|
|
203
|
+
oldValue: unknown;
|
|
204
|
+
newValue: unknown;
|
|
205
|
+
}
|
|
206
|
+
export interface CellEditStartDetail extends CellEditContext {
|
|
207
|
+
}
|
|
208
|
+
export interface CellEditEndDetail extends CellEditContext {
|
|
209
|
+
/** Editing was cancelled; the cell keeps its value. */
|
|
210
|
+
cancelled: boolean;
|
|
211
|
+
/** The committed value; undefined when cancelled. */
|
|
212
|
+
newValue: unknown;
|
|
213
|
+
}
|
|
214
|
+
export interface CellValueChangedDetail extends CellEditContext {
|
|
215
|
+
oldValue: unknown;
|
|
216
|
+
newValue: unknown;
|
|
217
|
+
}
|
|
218
|
+
/** What an edit does when its cell scrolls out of view: write the value, drop it, or keep the editor (hidden) until the cell is back. */
|
|
219
|
+
export type EditOutOfView = 'commit' | 'cancel' | 'keep';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CellEditor, CellEditorContext, CellEditorInstance } from '../types';
|
|
2
|
+
/** Builds the editor a column asks for; a column without one edits text. */
|
|
3
|
+
export declare const createEditor: (editor: CellEditor | undefined, context: CellEditorContext) => CellEditorInstance;
|
|
4
|
+
/** Whether typing a character on the cell can start this editor. */
|
|
5
|
+
export declare const startsByTyping: (editor: CellEditor | undefined) => editor is "number" | "text" | import("../types").CustomCellEditor | undefined;
|
|
@@ -34,6 +34,11 @@ declare class DataStore {
|
|
|
34
34
|
/** Value of a cell, `undefined` when the row has none. */
|
|
35
35
|
getValue(rowId: RowId, columnKey: Key): unknown;
|
|
36
36
|
getUpdatedAt(rowId: RowId, columnKey: Key): number | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Writes one cell right away, skipping the queue, and re-sorts when it is the sort key.
|
|
39
|
+
* Returns whether rows changed position; false too when the row does not exist.
|
|
40
|
+
*/
|
|
41
|
+
setValue(rowId: RowId, columnKey: Key, value: unknown, now?: number): boolean;
|
|
37
42
|
queueUpdate(row: RowInput): void;
|
|
38
43
|
queueRemove(row: RowInput): void;
|
|
39
44
|
clear(): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BuiltInCellEditor, CellEditor, CellValueChange } from '../types';
|
|
2
|
+
export type EditResult = {
|
|
3
|
+
ok: true;
|
|
4
|
+
value: unknown;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
message: string;
|
|
8
|
+
};
|
|
9
|
+
export interface ValueRules {
|
|
10
|
+
parse?: (text: string, change: CellValueChange) => unknown;
|
|
11
|
+
validate?: (value: unknown, change: CellValueChange) => boolean | string;
|
|
12
|
+
}
|
|
13
|
+
/** The text of a number editor as a number; empty text is no value. */
|
|
14
|
+
export declare const parseNumber: (text: string) => number | undefined;
|
|
15
|
+
/** The editor type a column uses when it names none. */
|
|
16
|
+
export declare const editorKind: (editor: CellEditor | undefined) => BuiltInCellEditor | 'custom';
|
|
17
|
+
/** Turns what an editor holds into the value to store: strings of text editors are parsed, then everything is validated. */
|
|
18
|
+
export declare const resolveEdit: (raw: unknown, editor: CellEditor | undefined, rules: ValueRules, change: Omit<CellValueChange, 'newValue'>) => EditResult;
|
|
@@ -22,3 +22,8 @@ export declare const stepWithin: (bounds: Bounds, from: CellPosition, axis: Axis
|
|
|
22
22
|
* unchanged when it is already visible, and the span's start wins when it is larger than the viewport.
|
|
23
23
|
*/
|
|
24
24
|
export declare const revealOffset: (start: number, end: number, scroll: number, size: number) => number;
|
|
25
|
+
/**
|
|
26
|
+
* Where the selection goes after an edit ends on `from`: Enter (`axis` `'row'`) moves down, Tab (`'column'`) right, one back with `backwards`.
|
|
27
|
+
* Tab continues on the next row past the last column; at the edge of the grid the cell stays.
|
|
28
|
+
*/
|
|
29
|
+
export declare const stepAfterEdit: (from: CellPosition, axis: Axis, backwards: boolean, { rowCount, columnCount }: GridSize) => CellPosition;
|
|
@@ -9,7 +9,7 @@ import HeaderRenderer from './header';
|
|
|
9
9
|
import CellValueRenderer from './cell-value';
|
|
10
10
|
import type { TextStyle } from './text';
|
|
11
11
|
import type { LayerOptions } from './utils/layer';
|
|
12
|
-
import type { CellContext, CellFocusDetail, CellPosition, CellRange, CellRenderer, CellState, ContextMenuDetail, ContextMenuItem, GridSelection, Key, RendererRef, RowId, RowInput, SelectionChangeDetail, SelectionCopyDetail, SelectionMode, SortDirection, SortKey } from './types';
|
|
12
|
+
import type { BuiltInCellEditor, CellContext, CellEditable, CellEditContext, CellEditEndDetail, CellEditor, CellEditorContext, CellEditorInstance, CellEditStartDetail, CellFocusDetail, CellPosition, CellRange, CellRenderer, CellState, CellValueChange, CellValueChangedDetail, ContextMenuDetail, ContextMenuItem, CustomCellEditor, EditOutOfView, GridSelection, Key, RendererRef, RowId, RowInput, SelectionChangeDetail, SelectionCopyDetail, SelectionMode, SelectOption, SortDirection, SortKey } from './types';
|
|
13
13
|
import type { RowIdGetter } from './utils/data-store';
|
|
14
14
|
/** What the grid remembers about a cell between frames. */
|
|
15
15
|
interface CellEntry {
|
|
@@ -39,6 +39,16 @@ export interface ColumnHeader {
|
|
|
39
39
|
headerFont?: string;
|
|
40
40
|
/** Renderer drawing the header of this column. */
|
|
41
41
|
headerRenderer: RendererRef;
|
|
42
|
+
/** Whether the user can edit this column's cells: `true`, or a function asked per cell. Defaults to `false`. `startEditing` follows it too. */
|
|
43
|
+
editable?: CellEditable;
|
|
44
|
+
/** Editor over the cell: `'text'` (default), `'number'`, `'checkbox'`, `{ type: 'select', options }`, or a function building a custom one. */
|
|
45
|
+
cellEditor?: CellEditor;
|
|
46
|
+
/** Turns the text of the text and number editors into the value to store; throw to mark the text invalid. Defaults to the text, or a number for `'number'`. */
|
|
47
|
+
valueParser?: (text: string, change: CellValueChange) => unknown;
|
|
48
|
+
/** Says whether a parsed value may be stored: `true`, or `false` / a message for an invalid-state editor that cannot be committed. */
|
|
49
|
+
validator?: (value: unknown, change: CellValueChange) => boolean | string;
|
|
50
|
+
/** Applies a committed edit instead of the grid storing it. Return `false` to reject the edit and keep the editor open. */
|
|
51
|
+
valueSetter?: (change: CellValueChange) => boolean | void;
|
|
42
52
|
}
|
|
43
53
|
/** What `getColumnState` returns and `setColumnState` takes: enough to restore the column widths later. */
|
|
44
54
|
export interface ColumnState {
|
|
@@ -66,7 +76,7 @@ interface AgApi {
|
|
|
66
76
|
setColumnDefs: (columns: ColumnDefinition[]) => void;
|
|
67
77
|
getRowNodeId: RowIdGetter;
|
|
68
78
|
}
|
|
69
|
-
export type { CellContext, CellFocusDetail, CellPosition, CellRange, CellRenderer, CellState, ContextMenuDetail, ContextMenuItem, GridSelection, LayerOptions, RendererRef, SelectionChangeDetail, SelectionCopyDetail, SelectionMode, SortDirection, SortKey, };
|
|
79
|
+
export type { BuiltInCellEditor, CellContext, CellEditable, CellEditContext, CellEditEndDetail, CellEditor, CellEditorContext, CellEditorInstance, CellEditStartDetail, CellFocusDetail, CellPosition, CellRange, CellRenderer, CellState, CellValueChange, CellValueChangedDetail, ContextMenuDetail, ContextMenuItem, CustomCellEditor, EditOutOfView, GridSelection, LayerOptions, RendererRef, SelectionChangeDetail, SelectionCopyDetail, SelectionMode, SelectOption, SortDirection, SortKey, };
|
|
70
80
|
export interface RowResizeDetail {
|
|
71
81
|
rowId: RowId;
|
|
72
82
|
height: number;
|
|
@@ -87,6 +97,9 @@ declare global {
|
|
|
87
97
|
cellfocus: CustomEvent<CellFocusDetail>;
|
|
88
98
|
selectioncopy: CustomEvent<SelectionCopyDetail>;
|
|
89
99
|
gridcontextmenu: CustomEvent<ContextMenuDetail>;
|
|
100
|
+
celleditstart: CustomEvent<CellEditStartDetail>;
|
|
101
|
+
celleditend: CustomEvent<CellEditEndDetail>;
|
|
102
|
+
cellvaluechanged: CustomEvent<CellValueChangedDetail>;
|
|
90
103
|
}
|
|
91
104
|
}
|
|
92
105
|
declare class CanvasGridComponent extends HTMLElement {
|
|
@@ -461,6 +474,40 @@ declare class CanvasGridComponent extends HTMLElement {
|
|
|
461
474
|
private menuAnchor;
|
|
462
475
|
/** Opens the context menu on a right click, a long press or the menu key, once `gridcontextmenu` let it. */
|
|
463
476
|
private readonly onContextMenu;
|
|
477
|
+
/** What happens to an edit when its cell scrolls out of view: `'cancel'` (default) drops it, `'commit'` writes it, `'keep'` hides the editor until the cell is back. */
|
|
478
|
+
editOutOfView: EditOutOfView;
|
|
479
|
+
private edit;
|
|
480
|
+
private cellOf;
|
|
481
|
+
private canEdit;
|
|
482
|
+
/**
|
|
483
|
+
* Puts an editor over a cell, committing the edit in progress first. Returns whether one opened: the cell has to exist and be `editable`,
|
|
484
|
+
* and a cancelled `celleditstart` or an edit that cannot be committed stop it. The cell is scrolled into view.
|
|
485
|
+
*/
|
|
486
|
+
startEditing(rowId: RowId, columnId: Key): boolean;
|
|
487
|
+
/** Ends the edit in progress: commits it, or drops it with `cancel`. Returns false when there was none, or the value is invalid or rejected, which keeps the editor open. */
|
|
488
|
+
stopEditing(cancel?: boolean): boolean;
|
|
489
|
+
private openEditor;
|
|
490
|
+
private finishEditIfOpen;
|
|
491
|
+
/** The editor's value parsed and validated against the value the cell holds now. */
|
|
492
|
+
private checkEdit;
|
|
493
|
+
private showValidity;
|
|
494
|
+
/** Writes a committed value, through the column's `valueSetter` when it has one. Returns false when that rejected it. */
|
|
495
|
+
private applyEdit;
|
|
496
|
+
private finishEdit;
|
|
497
|
+
private closeEditor;
|
|
498
|
+
/** Keeps the editor on its cell as the grid scrolls, resizes or re-sorts; applies `editOutOfView` once the cell is gone from the view. */
|
|
499
|
+
private positionEditor;
|
|
500
|
+
/** Enter and Tab commit and move the selection on, Escape drops the edit; the keys stay inside the editor, which the grid would otherwise act on. */
|
|
501
|
+
private readonly onEditorKeyDown;
|
|
502
|
+
/** Leaving the editor commits it, or drops it when its value is invalid. Switching windows leaves it be. */
|
|
503
|
+
private readonly onEditorFocusOut;
|
|
504
|
+
/** The cell at a displayed row and column, when both exist. */
|
|
505
|
+
private cellAt;
|
|
506
|
+
private canEditAt;
|
|
507
|
+
private editAt;
|
|
508
|
+
private readonly onEditDoubleClick;
|
|
509
|
+
/** Starts editing the active cell for F2, Enter (with a single cell selected) or a typed character, which begins the text. */
|
|
510
|
+
private handleEditKey;
|
|
464
511
|
get totalHeight(): number;
|
|
465
512
|
refreshScrollbar(): void;
|
|
466
513
|
queueUpdate(row: RowInput): void;
|
package/build/web-component.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.CanvasGrid=t())})(this,function(){var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n)),l=o(((e,t)=>{var n=`Expected a function`,r=NaN,i=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,s=/^0o[0-7]+$/i,c=parseInt,l=typeof global==`object`&&global&&global.Object===Object&&global,u=typeof self==`object`&&self&&self.Object===Object&&self,d=l||u||Function(`return this`)(),f=Object.prototype.toString,p=Math.max,m=Math.min,h=function(){return d.Date.now()};function g(e,t,r){var i,a,o,s,c,l,u=0,d=!1,f=!1,g=!0;if(typeof e!=`function`)throw TypeError(n);t=x(t)||0,v(r)&&(d=!!r.leading,f=`maxWait`in r,o=f?p(x(r.maxWait)||0,t):o,g=`trailing`in r?!!r.trailing:g);function _(t){var n=i,r=a;return i=a=void 0,u=t,s=e.apply(r,n),s}function y(e){return u=e,c=setTimeout(C,t),d?_(e):s}function b(e){var n=e-l,r=e-u,i=t-n;return f?m(i,o-r):i}function S(e){var n=e-l,r=e-u;return l===void 0||n>=t||n<0||f&&r>=o}function C(){var e=h();if(S(e))return w(e);c=setTimeout(C,b(e))}function w(e){return c=void 0,g&&i?_(e):(i=a=void 0,s)}function T(){c!==void 0&&clearTimeout(c),u=0,i=l=a=c=void 0}function E(){return c===void 0?s:w(h())}function D(){var e=h(),n=S(e);if(i=arguments,a=this,l=e,n){if(c===void 0)return y(l);if(f)return c=setTimeout(C,t),_(l)}return c===void 0&&(c=setTimeout(C,t)),s}return D.cancel=T,D.flush=E,D}function _(e,t,r){var i=!0,a=!0;if(typeof e!=`function`)throw TypeError(n);return v(r)&&(i=`leading`in r?!!r.leading:i,a=`trailing`in r?!!r.trailing:a),g(e,t,{leading:i,maxWait:t,trailing:a})}function v(e){var t=typeof e;return!!e&&(t==`object`||t==`function`)}function y(e){return!!e&&typeof e==`object`}function b(e){return typeof e==`symbol`||y(e)&&f.call(e)==`[object Symbol]`}function x(e){if(typeof e==`number`)return e;if(b(e))return r;if(v(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=v(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=e.replace(i,``);var n=o.test(e);return n||s.test(e)?c(e.slice(2),n?2:8):a.test(e)?r:+e}t.exports=_})),u=o(((e,t)=>{var n=NaN,r=/^\s+|\s+$/g,i=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,o=/^0o[0-7]+$/i,s=parseInt,c=typeof global==`object`&&global&&global.Object===Object&&global,l=typeof self==`object`&&self&&self.Object===Object&&self,u=c||l||Function(`return this`)(),d=Object.prototype.toString,f=Math.max,p=Math.min,m=function(){return u.Date.now()};function h(e,t,n){var r,i,a,o,s,c,l=0,u=!1,d=!1,h=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=y(t)||0,g(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?f(y(n.maxWait)||0,t):a,h=`trailing`in n?!!n.trailing:h);function _(t){var n=r,a=i;return r=i=void 0,l=t,o=e.apply(a,n),o}function v(e){return l=e,s=setTimeout(S,t),u?_(e):o}function b(e){var n=e-c,r=e-l,i=t-n;return d?p(i,a-r):i}function x(e){var n=e-c,r=e-l;return c===void 0||n>=t||n<0||d&&r>=a}function S(){var e=m();if(x(e))return C(e);s=setTimeout(S,b(e))}function C(e){return s=void 0,h&&r?_(e):(r=i=void 0,o)}function w(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function T(){return s===void 0?o:C(m())}function E(){var e=m(),n=x(e);if(r=arguments,i=this,c=e,n){if(s===void 0)return v(c);if(d)return s=setTimeout(S,t),_(c)}return s===void 0&&(s=setTimeout(S,t)),o}return E.cancel=w,E.flush=T,E}function g(e){var t=typeof e;return!!e&&(t==`object`||t==`function`)}function _(e){return!!e&&typeof e==`object`}function v(e){return typeof e==`symbol`||_(e)&&d.call(e)==`[object Symbol]`}function y(e){if(typeof e==`number`)return e;if(v(e))return n;if(g(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=g(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=e.replace(r,``);var c=a.test(e);return c||o.test(e)?s(e.slice(2),c?2:8):i.test(e)?n:+e}t.exports=h})),d=c(l()),f=c(u()),p=class{entries=new Map;constructor(){this.get=this.get.bind(this),this.set=this.set.bind(this),this.clear=this.clear.bind(this),this.forEach=this.forEach.bind(this)}get keys(){return Array.from(this.entries.values(),e=>e.key)}get(e){return this.entries.get(String(e))?.value}set(e,t){let n=this.entries.get(String(e));n?n.value=t:this.entries.set(String(e),{key:e,value:t})}add(e){this.set(this.entries.size,e)}delete(e){this.entries.delete(String(e))}clear(e){typeof e==`function`?this.entries.forEach(({key:t,value:n},r)=>{e(n,t)&&this.entries.delete(r)}):this.entries.clear()}forEach(e){this.entries.forEach(({key:t,value:n})=>e(n,t))}get length(){return this.entries.size}},m=class{values;version=0;updatedAt=void 0;constructor(e=0){this.values=Array(e).fill(void 0)}get(e){return this.values[e]}getUpdatedAt(e){return this.updatedAt?.[e]||void 0}set(e,t,n){for(this.version++;this.values.length<e;)this.values.push(void 0);if(this.values[e]=t,n!==void 0||this.updatedAt!==void 0){for(this.updatedAt??=Array(this.values.length).fill(0);this.updatedAt.length<this.values.length;)this.updatedAt.push(0);this.updatedAt[e]=n??0}}clearSlots(e){this.version++,e.forEach(e=>{e<this.values.length&&(this.values[e]=void 0),this.updatedAt&&e<this.updatedAt.length&&(this.updatedAt[e]=0)})}compact(e){this.version++,this.values=Array.from(e,e=>this.values[e]);let{updatedAt:t}=this;t&&(this.updatedAt=Array.from(e,e=>t[e]??0))}},h=1024,g=class{items=[];byId=new Map;tops=[];end=0;nextSlot=0;get length(){return this.items.length}get totalHeight(){return this.end}get slotCount(){return this.nextSlot}get keys(){return this.items.map(e=>e.id)}get(e){return this.byId.get(String(e))}at(e){return this.items[e]}topOf(e){return this.tops[e]??this.end}indexAt(e){if(e<=0)return 0;if(e>=this.end)return this.length;let t=0,n=this.items.length-1;for(;t<n;){let r=Math.ceil((t+n)/2);this.tops[r]<=e?t=r:n=r-1}return t}set(e){let t=String(e.id),n=this.byId.get(t);if(n){let r={id:e.id,height:e.height,index:n.index,slot:n.slot};return this.items[n.index]=r,this.byId.set(t,r),this.reindexFrom(n.index),r}let r=this.items.length,i={id:e.id,height:e.height,index:r,slot:this.nextSlot++};return this.items.push(i),this.byId.set(t,i),this.tops.push(this.end),this.end+=Math.round(e.height),i}setHeight(e,t){let n=this.get(e);return!n||n.height===t?!1:(n.height=t,this.reindexFrom(n.index),!0)}setHeights(e){this.items.forEach(t=>{t.height=e(t.id)}),this.reindexFrom(0)}borderAt(e,t){if(this.items.length===0)return-1;let n=this.indexAt(e),r=n<this.items.length?Math.abs(this.topOf(n+1)-e):1/0,i=n>0?Math.abs(this.topOf(n)-e):1/0;return Math.min(i,r)>t?-1:i<r?n-1:n}removeMany(e){let t=new Set;if(e.forEach(e=>{let n=this.get(e);n&&t.add(n)}),t.size===0)return[];t.forEach(e=>this.byId.delete(String(e.id)));let n=Array.from(t,e=>e.index).sort((e,t)=>e-t);return this.closeGaps(n),this.reindexFrom(n[0]),Array.from(t,e=>e.slot).sort((e,t)=>e-t)}compactSlots(){let e=this.nextSlot-this.items.length;if(e<h||e<=this.items.length)return;let t=Int32Array.from(this.items,e=>e.slot).sort(),n=new Int32Array(this.nextSlot);return t.forEach((e,t)=>{n[e]=t}),this.items.forEach(e=>{e.slot=n[e.slot]}),this.nextSlot=this.items.length,t}sort(e){this.items.sort(e),this.reindexFrom(0)}resort(e,t){let n=new Set;for(let t of e){let e=this.get(t);e&&n.add(e)}if(n.size===0)return;let r=Array.from(n,e=>e.index).sort((e,t)=>e-t);this.closeGaps(r);let i=Array.from(n).sort(t),a=i.map(e=>this.lowerBound(this.items,e,t)),o=this.items.length;i.forEach(e=>this.items.push(e));let{items:s}=this,c=o;for(let e=i.length-1;e>=0;e--){for(let t=c-1;t>=a[e];t--)s[t+e+1]=s[t];s[a[e]+e]=i[e],c=a[e]}this.reindexFrom(Math.min(r[0],a[0]))}clear(){this.items=[],this.byId.clear(),this.tops=[],this.end=0,this.nextSlot=0}closeGaps(e){let{items:t}=this,n=e[0];e.forEach((r,i)=>{let a=e[i+1]??t.length;for(let e=r+1;e<a;e++)t[n++]=t[e]}),t.length=n}lowerBound(e,t,n){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;n(e[a],t)<0?r=a+1:i=a}return r}reindexFrom(e){this.tops.length=this.items.length;let t=e===0?0:this.tops[e-1]+Math.round(this.items[e-1].height);for(let n=e;n<this.items.length;n++){let e=this.items[n];e.index=n,this.tops[n]=t,t+=Math.round(e.height)}this.end=t}},_=()=>new Date().valueOf(),v=(e,t)=>e.id,y=new Intl.Collator,b=8,x=e=>e==null?3:typeof e==`number`||typeof e==`bigint`?0:typeof e==`string`?1:2,S=(e,t)=>{let n=x(e)-x(t);return n===0?x(e)===3?0:x(e)===0?Number(e)-Number(t):y.compare(String(e),String(t)):n},C=e=>{let t=new Uint8Array(e.length),n=new Float64Array(e.length),r=new Int32Array(e.length),i=new Map;for(let a=0;a<e.length;a++){let o=e[a],s=x(o);if(t[a]=s,s===0){n[a]=Number(o);continue}if(s!==1&&s!==2)continue;let c=String(o),l=i.get(c);l===void 0&&(l=i.size,i.set(c,l)),r[a]=l}let a=new Float64Array(i.size),o=Array.from(i.keys()).sort(y.compare),s=0;o.forEach((e,t)=>{t>0&&y.compare(o[t-1],e)!==0&&s++,a[i.get(e)??0]=s});for(let i=0;i<e.length;i++)(t[i]===1||t[i]===2)&&(n[i]=a[r[i]]);return{ranks:t,keys:n}},w=class{rows=new g;columns=new Map;pending=[];sortModel=[];sortDirty=!1;sortChanged=new Set;defaultKeys=new WeakMap;environment;constructor(e){this.environment=e}get hasPending(){return this.pending.length>0}getSortModel(){return this.sortModel}setSortModel(e){this.sortModel=[...e],this.sort()}getValue(e,t){let n=this.rows.get(e);return n?this.columns.get(String(t))?.get(n.slot):void 0}getUpdatedAt(e,t){let n=this.rows.get(e);return n?this.columns.get(String(t))?.getUpdatedAt(n.slot):void 0}queueUpdate(e){this.pending.push({type:`update`,row:e})}queueRemove(e){this.pending.push({type:`remove`,row:e})}clear(){this.rows.clear(),this.columns.clear()}setRows(e){this.pending=[],this.clear(),this.sortChanged.clear(),Object.keys(e[0]??{}).forEach(t=>this.columns.set(t,new m(e.length))),e.forEach((e,t)=>this.addRow(this.environment.getRowId(e,t),e,void 0)),this.sortModel.length>0&&this.sort()}flush(e=_()){let t=this.pending;this.pending=[];let n=[],r=!1,i=()=>{r=this.removeRows(n)||r,n.length=0};return t.forEach(({type:t,row:r})=>{t===`remove`?n.push(this.environment.getRowId(r)):(i(),this.applyUpdate(r,e))}),i(),this.sortDirty?(this.sortChanges(),!0):r}column(e){let t=this.columns.get(e);return t||(t=new m(this.rows.slotCount),this.columns.set(e,t)),t}addRow(e,t,n){let{slot:r}=this.rows.set({id:e,height:this.environment.getCellHeight()}),i=Object.keys(t);for(let e of i)this.column(e).set(r,t[e],n);this.markSortDirty(e,i);let a=this.environment.getRowHeight?.(e);a!==void 0&&this.rows.setHeight(e,a)}removeRows(e){if(e.length===0)return!1;let t=this.rows.removeMany(e);this.columns.forEach(e=>e.clearSlots(t));let n=this.rows.compactSlots();return n&&this.columns.forEach(e=>e.compact(n)),t.length>0}applyUpdate(e,t){let n=this.environment.getRowId(e),r=this.rows.get(n);r?Object.keys(e).forEach(n=>this.applyValue(r.id,r.slot,n,e[n],t)):this.addRow(n,e,t)}applyValue(e,t,n,r,i){let a=this.column(n),o=a.get(t);o!==r&&(a.set(t,r,o===void 0?void 0:i),this.markSortDirty(e,[n]))}markSortDirty(e,t){this.sortModel.some(({columnId:e})=>t.includes(String(e)))&&(this.sortDirty=!0,this.sortChanged.add(String(e)))}defaultKeyOf(e){let t=this.defaultKeys.get(e);if(t&&t.version===e.version)return t.key;let n=C(e.values);return this.defaultKeys.set(e,{version:e.version,key:n}),n}createComparator(e){let[t,...n]=this.sortModel,r=t&&!t.compare&&e&&n.length===0?this.columns.get(String(t.columnId)):void 0;if(r){let{ranks:e,keys:n}=this.defaultKeyOf(r),i=t.direction===`desc`?-1:1;return(t,r)=>{let a=e[t.slot]-e[r.slot]||n[t.slot]-n[r.slot]||0;return a===0?t.slot-r.slot:a*i}}let i=this.sortModel.map(({columnId:t,direction:n=`asc`,compare:r})=>{let i=this.columns.get(String(t)),a=i?.values,o=n===`desc`?-1:1;if(!i||!a)return{order:()=>0,sign:o};if(r)return{order:(e,t)=>r(a[e.slot],a[t.slot]),sign:o};if(!e)return{order:(e,t)=>S(a[e.slot],a[t.slot]),sign:o};let{ranks:s,keys:c}=this.defaultKeyOf(i);return{order:(e,t)=>s[e.slot]-s[t.slot]||c[e.slot]-c[t.slot]||0,sign:o}});return(e,t)=>{for(let{order:n,sign:r}of i){let i=n(e,t);if(i!==0)return i*r}return e.slot-t.slot}}sort(){this.sortDirty=!1,this.sortChanged.clear(),this.rows.sort(this.createComparator(!0))}sortChanges(){let e=this.sortChanged;e.size*b>=this.rows.length?this.sort():(this.sortDirty=!1,this.sortChanged=new Set,this.rows.resort(e,this.createComparator(!1)))}},T=class{entries=new Map;limit;constructor(e){this.limit=e}get(e){let t=this.entries.get(e);if(t!==void 0)return this.entries.delete(e),this.entries.set(e,t),t}set(e,t){this.entries.delete(e),this.entries.set(e,t);let[n]=this.entries.keys();this.entries.size>this.limit&&n!==void 0&&this.entries.delete(n)}clear(){this.entries.clear()}get size(){return this.entries.size}},E=`canvas-grid{isolation:isolate;display:block;position:relative}canvas-grid,canvas-grid *{box-sizing:border-box;margin:0;padding:0}canvas-grid:focus:not(:focus-visible){outline:none}canvas-grid .drawingLayer{contain:strict;width:100%;height:100%;position:absolute;top:0;left:0}canvas-grid .scrollArea{scrollbar-width:thin;scrollbar-color:var(--cg-scrollbar-color,#555) transparent;z-index:10;backface-visibility:hidden;will-change:transform;width:100%;height:100%;position:absolute;top:0;left:0;overflow:auto}canvas-grid .scrollArea>div{will-change:scroll-position, transform}canvas-grid .resizeGuide{pointer-events:none;z-index:11;background:#4a90d9;width:1px;height:100%;display:none;position:absolute;top:0;left:0}canvas-grid .resizeGuide.horizontal{width:100%;height:1px}canvas-grid[theme=light] .scrollArea{scrollbar-color:var(--cg-scrollbar-color,#b4bac2) transparent}@media (prefers-color-scheme:light){canvas-grid:not([theme=dark]) .scrollArea{scrollbar-color:var(--cg-scrollbar-color,#b4bac2) transparent}}canvas-grid .contextMenu{border:1px solid var(--canvas-grid-menu-border,#3d4650);background:var(--canvas-grid-menu-background,#1f262d);min-width:160px;color:var(--canvas-grid-menu-color,#e6edf3);border-radius:6px;margin:0;padding:4px;font:13px system-ui,sans-serif;position:fixed;inset:auto;box-shadow:0 6px 20px #0006}canvas-grid .contextMenu button{width:100%;color:inherit;font:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:4px;padding:6px 10px;display:block}canvas-grid .contextMenu button:hover:not(:disabled),canvas-grid .contextMenu button:focus-visible{background:var(--canvas-grid-menu-hover,#2f3d4a);outline:none}canvas-grid .contextMenu button:disabled{opacity:.5;cursor:default}`,D=e=>!!e,O=e=>t=>({draw:(n,r,i)=>e(n,t,r,i)}),ee=({x:e=0,y:t=0,children:n})=>({draw:(r,i,a)=>[n].flat(2).filter(D).forEach(n=>n.draw(r,i+e,a+t))}),k={createElement(e,t,...n){return e(Object.assign({},t,{children:n}))}},A=class{options;constructor(e){this.options={...e}}update(e){let t={...this.options};Object.assign(this.options,e),this.optionsUpdated(t)}optionsUpdated(e){}clearCache(){}},j=(e,t)=>{let n=e.getContext(`2d`,t);if(!n)throw Error(`2D canvas context is not available`);return n},te=class extends A{ctx;offCanvas=document.createElement(`canvas`);offCtx;rotation=Math.PI/180*270;speed=6;count=75;constructor(e){super(e),this.ctx=this.options.ctx,this.offCanvas.width=250,this.offCanvas.height=250,this.offCtx=j(this.offCanvas),this.offCtx.lineWidth=.5,this.setColor(`rgba(255, 255, 255, 0.75)`)}setColor(e){this.offCtx.strokeStyle=e}updateLoader(){this.rotation+=this.speed/100}renderLoader(){this.offCtx.save(),this.offCtx.globalCompositeOperation=`source-over`,this.offCtx.translate(125,125),this.offCtx.rotate(this.rotation);let e=this.count;for(;e--;)this.offCtx.beginPath(),this.offCtx.arc(0,0,e+Math.random()*35,Math.random(),Math.PI/3+Math.random()/12,!1),this.offCtx.stroke();this.offCtx.restore()}render(){this.offCtx.globalCompositeOperation=`destination-out`,this.offCtx.fillStyle=`rgba(255, 255, 255, 0.03)`,this.offCtx.fillRect(0,0,250,250),this.updateLoader(),this.renderLoader();let e=Math.round((this.ctx.canvas.width-this.offCanvas.width)/2),t=Math.round((this.ctx.canvas.height-this.offCanvas.height)/2);return this.ctx.clearRect(e,t,250,250),this.ctx.drawImage(this.offCanvas,e,t),this.offCanvas}},ne=class{name;canvas=document.createElement(`canvas`);ctx;constructor(e,{alpha:t=!0,desynchronized:n=!1}={}){this.name=e,this.canvas.className=`drawingLayer ${e}`,this.ctx=j(this.canvas,{alpha:t,desynchronized:n})}width=0;height=0;pixelRatio=1;resize(e,t,n=1){return e===this.width&&t===this.height&&n===this.pixelRatio?!1:(this.width=e,this.height=t,this.pixelRatio=n,this.canvas.width=Math.round(e*n),this.canvas.height=Math.round(t*n),this.ctx.setTransform(n,0,0,n,0,0),!0)}clear(){this.ctx.clearRect(0,0,this.width,this.height)}},re=class{renderers=new Map;warned=new Set;register(e,t){this.renderers.set(e,t),this.warned.delete(e)}unregister(e){this.renderers.delete(e)}get(e){return this.renderers.get(e)}resolve(e){if(typeof e!=`string`)return e;let t=this.renderers.get(e);return!t&&!this.warned.has(e)&&(this.warned.add(e),console.warn(`canvas-grid: no renderer registered as "${e}"`)),t}clearCaches(){this.renderers.forEach(e=>e.clearCache?.())}},M=O((e,{x:t=0,y:n=0,width:r,height:i,color:a,alpha:o=1},s,c)=>{let l=Math.trunc(r),u=Math.trunc(i);!a||l<=0||u<=0||o<=0||(e.fillStyle=a,o>=1?e.fillRect(s+t,c+n,l,u):(e.globalAlpha=o,e.fillRect(s+t,c+n,l,u),e.globalAlpha=1))}),ie=120,ae=.5,oe=typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(prefers-reduced-motion: reduce)`):void 0,se=e=>e*e*(3-2*e),ce=class e extends A{static defaultOptions={layer:`background`,enableFlashing:!0,background:`#333`,flashInDuration:200,flashOutDuration:400,flashColor:`rgb(214, 144, 13)`,zebraColor:`rgba(255, 255, 255, 0.025)`,hoverColor:`rgba(255, 255, 255, 0.06)`,borderRightWidth:0,borderRightColor:`#fff`,borderBottomWidth:0,borderBottomColor:`#fff`};constructor(t={}){super({...e.defaultOptions,...t})}hoveredRowIndex=void 0;hoverFades=new Map;get hoverDuration(){return oe?.matches?0:ie}hover(e,t=Date.now()){e!==this.hoveredRowIndex&&(this.hoveredRowIndex!==void 0&&this.startFade(this.hoveredRowIndex,0,t),e!==void 0&&this.startFade(e,1,t),this.hoveredRowIndex=e)}startFade(e,t,n){this.hoverFades.set(e,{from:this.getHoverFraction(e,n),to:t,start:n})}getHoverFraction(e,t){let n=this.hoverFades.get(e);if(!n)return 0;let r=this.hoverDuration,i=r<=0?1:Math.min(1,Math.max(0,(t-n.start)/r));i>=1&&n.to===0&&this.hoverFades.delete(e);let a=1-(1-i)*(1-i);return n.from+(n.to-n.from)*a}get layer(){return this.options.layer}isAnimating({age:e,row:t,now:n}){let r=t===void 0?void 0:this.hoverFades.get(t.index);return r&&n-r.start<this.hoverDuration?!0:this.options.enableFlashing&&e<=this.options.flashInDuration+this.options.flashOutDuration}getFlashAlpha(e){if(!this.options.enableFlashing)return 0;let{flashInDuration:t,flashOutDuration:n}=this.options;if(e>t+n)return 0;if(oe?.matches)return ae;let r=Math.max(0,(t+n-e)/n),i=e<t?se(e/t):r*r;return Math.round(i*1e3)/1e3}draw({ctx:e,x:t,y:n,width:r,height:i,age:a,row:o,now:s}){let{background:c,flashColor:l,zebraColor:u,hoverColor:d,borderRightWidth:f,borderRightColor:p,borderBottomWidth:m,borderBottomColor:h}=this.options,g=this.getFlashAlpha(a),_=o===void 0?0:this.getHoverFraction(o.index,s);k.createElement(ee,null,k.createElement(M,{width:r,height:i,color:c}),o!==void 0&&o.index%2==1&&k.createElement(M,{width:r,height:i,color:u}),_>0&&k.createElement(M,{width:r,height:i,color:d,alpha:_}),g>0&&k.createElement(M,{width:r,height:i,color:l,alpha:g}),f>0&&k.createElement(M,{x:r-f,width:f,height:i,color:p}),m>0&&k.createElement(M,{y:i-m,width:r,height:m,color:h})).draw(e,t,n)}},le=/[\p{M}ᄀ-ᇿꥠ-ힰ-\u{10000}-\u{10ffff}]/u,ue=768,de=new Intl.Segmenter,fe=e=>Array.from(de.segment(e),({segment:e})=>e),pe=e=>le.test(e)?fe(e):e,me=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>=ue)return!0;return!1},N=(e,t,n,r)=>{let i=0,a=0;for(;a<e.length;){let n=r(e[a]);if(i+n>t)break;i+=n,a++}if(a===e.length)return a;let o=r(n);for(;a>0&&i+o>t;)a--,i-=r(e[a]);return i+o>t?-1:a},he=(e,t)=>{let n=0;for(let r=0;r<e.length;r++)n+=t(e[r]);return n},ge=4096,_e=(e,t,n,r)=>{if(!e)return r;let i=e.get(t);return i?(i.available=n,i.text=r,r):(e.size>=ge&&e.clear(),e.set(t,{available:n,text:r}),r)},ve=(e,t,n,r,i)=>{let{measure:a,cache:o}=i,s=o?.get(e);if(s?.available===t)return s.text;let c=pe(e);if(N(c,t,n,r)===c.length)return e;let l=a(e);if(l<=t)return _e(o,e,t,e);let u=l/he(c,r),d=N(c,t,n,e=>r(e)*u),f=e=>typeof c==`string`?c.slice(0,e):c.slice(0,e).join(``);for(;d>0&&a(f(d)+n)>t;)d--;return _e(o,e,t,d<0||d===0&&a(n)>t?``:f(d)+n)},ye=(e,t,n,r,i)=>{let a=r(n),o=n.charAt(0),s=0,c=0;for(;c<e.length;){let n=s+r(e.charAt(c))+(c===0?0:i(e.charAt(c-1),e.charAt(c)));if(n>t)break;s=n,c++}if(c===e.length)return e;for(;c>0&&s+i(e.charAt(c-1),o)+a>t;)c--,s-=r(e.charAt(c))+(c===0?0:i(e.charAt(c-1),e.charAt(c)));return c>0||a<=t?e.slice(0,c)+n:``},be=(e,t,n,r,i={measure:e=>he(pe(e),r),sumIsExact:!0})=>{let a=N(e,t,n,r);return a===e.length?e:i.sumIsExact&&!me(e)?a<0?``:e.slice(0,a)+n:i.kerning&&!me(e)?ye(e,t,n,r,i.kerning):ve(e,t,n,r,i)},P={textRendering:`auto`,fontKerning:`auto`,letterSpacing:`0px`,direction:`ltr`,textOverflow:`clip`},xe=768,Se=/^[^\p{L}]*(?=[-ࣿיִ-﷿ﹰ-ﻼ])\p{L}/u,F=class e extends A{static defaultOptions={...P,ellipsis:`…`,cellPadding:{top:3,right:3,bottom:3,left:3},font:`12px sans-serif`,color:`#fff`,isEllipsisRight:!0};fonts=new Map;measureContext=j(document.createElement(`canvas`));measuredState=``;styled=!1;constructor(t={}){super({...e.defaultOptions,...t}),this.styled=this.differsFromDefault()}differsFromDefault(){return Object.keys(P).some(e=>e!==`textOverflow`&&this.options[e]!==P[e])}set font(e){this.options.font!==e&&(this.options.font=e,this.clearCache())}get font(){return this.options.font}set color(e){this.options.color=e}get color(){return this.options.color}setStyle(e){Object.keys(e).some(t=>e[t]!==this.options[t])&&(this.update(e),this.styled=this.styled||this.differsFromDefault(),this.clearCache())}pixelRatio=1;clearCache(){this.fonts.clear(),this.lastMeasures=void 0,this.measuredState=``}measuresOf(e){let t=this.fonts.get(e);if(t)return t;let n=new Map,r={font:e,widths:new Map,pairs:new Map,fitted:n,probed:!1,widthOf:e=>this.measureCharacter(r,e),exactFit:{measure:e=>this.measureString(r,e),cache:n,sumIsExact:!0,kerning:(e,t)=>this.measureKerning(r,e,t)}};return this.fonts.set(e,r),r}prepareMeasuring(e){let{textRendering:t,fontKerning:n,letterSpacing:r}=this.options,i=`${e.font}|${t}|${n}|${r}`;this.measuredState!==i&&(this.measureContext.font=e.font,this.measureContext.textRendering=t,this.measureContext.fontKerning=n,this.measureContext.letterSpacing=r,this.measuredState=i),e.probed||(e.probed=!0,e.exactFit.sumIsExact=Math.abs(this.measureContext.measureText(`i`).width-this.measureContext.measureText(`W`).width)<.01)}measureCharacter(e,t){let n=e.widths.get(t);if(n!==void 0)return n;this.prepareMeasuring(e);let r=this.measureContext.measureText(t).width;return e.widths.set(t,r),r}measureKerning(e,t,n){let r=t.charCodeAt(0)*65536+n.charCodeAt(0),i=e.pairs.get(r);if(i!==void 0)return i;let a=this.measureString(e,t+n)-this.measureCharacter(e,t)-this.measureCharacter(e,n);return e.pairs.set(r,a),a}measureString(e,t){return this.prepareMeasuring(e),this.measureContext.measureText(t).width}getTextWidth(e){let{widthOf:t}=this.measuresOf(this.options.font),n=0;for(let r=0;r<e.length;r++)n+=t(e.charAt(r));return n}fitsBySum(e,t,n){let r=0;for(let i=0;i<e.length;i++)if(e.charCodeAt(i)>=xe||(r+=n(e.charAt(i)),r>t))return!1;return!0}lastMeasures=void 0;isRightToLeft(e){let{direction:t}=this.options;return t===`auto`?Se.test(e):t===`rtl`}paint(e,{value:t=``,x:n=0,y:r=0,width:i=0,height:a=0,font:o=this.options.font},s,c){let{cellPadding:l}=this.options,u=i-l.left-l.right,d=this.lastMeasures?.font===o?this.lastMeasures:this.measuresOf(o);this.lastMeasures=d;let f=this.options.textOverflow===`clip`&&!this.fitsBySum(t,u,d.widthOf),p=this.options.textOverflow===`clip`?t:be(t,u,this.options.ellipsis,d.widthOf,d.exactFit);if(p===``||a-l.top-l.bottom<=0)return;f&&(e.save(),e.beginPath(),e.rect(s+n+l.left,c+r,Math.max(0,u),a),e.clip());let m=this.styled&&this.isRightToLeft(p);this.styled&&(e.textRendering=this.options.textRendering,e.fontKerning=this.options.fontKerning,e.letterSpacing=this.options.letterSpacing,e.direction=m?`rtl`:`ltr`),e.font=o,e.fillStyle=this.options.color,e.textAlign=m?`right`:`left`,e.textBaseline=`middle`;let{pixelRatio:h}=this,g=m?s+n+i-l.right:s+n+l.left;e.fillText(p,Math.round(g*h)/h,Math.round((c+r+l.top+(a-l.top-l.bottom)/2)*h)/h),f&&e.restore()}element=O((e,t,n,r)=>this.paint(e,t,n,r))},Ce=8,I=5,we=.75,Te=O((e,{width:t,height:n,direction:r,color:i},a,o)=>{let s=Math.round(a+t-13),c=Math.round(o+(n-I)/2),l=r===`asc`;e.beginPath(),e.moveTo(s,l?c+I:c),e.lineTo(s+Ce,l?c+I:c),e.lineTo(s+Ce/2,l?c:c+I),e.closePath(),e.fillStyle=i,e.globalAlpha=we,e.fill(),e.globalAlpha=1}),Ee=class e extends A{static defaultOptions={layer:`header`,background:`#333`,selectedBackground:`#2f3d4a`,fullySelectedBackground:`#3a5a7c`,font:`13px sans-serif`,color:`#fff`,borderRightWidth:1,borderRightColor:`#fff`,borderBottomWidth:1,borderBottomColor:`#fff`};textRenderer;sortDirections=new Map;setSortModel(e){this.sortDirections.clear(),e.forEach(({columnId:e,direction:t=`asc`})=>this.sortDirections.set(String(e),t))}constructor(t={}){super({...e.defaultOptions,...t}),this.textRenderer=new F({font:this.options.font,color:this.options.color})}get layer(){return this.options.layer}set font(e){this.options.font=e,this.textRenderer.font=e}get font(){return this.textRenderer.font}set pixelRatio(e){this.textRenderer.pixelRatio=e}get pixelRatio(){return this.textRenderer.pixelRatio}setTextStyle(e){this.textRenderer.setStyle(e)}optionsUpdated(){this.textRenderer.color=this.options.color}clearCache(){this.textRenderer.clearCache()}backgroundFor(e){return e===`full`?this.options.fullySelectedBackground:e===`partial`?this.options.selectedBackground:this.options.background}draw({ctx:e,x:t,y:n,width:r,height:i,column:a,formatted:o,selected:s}){if(r===0||i===0)return;let c=a===void 0?void 0:this.sortDirections.get(String(a.id)),{borderRightWidth:l,borderRightColor:u,borderBottomWidth:d,borderBottomColor:f}=this.options,p=this.backgroundFor(s);k.createElement(ee,null,k.createElement(M,{width:r,height:i,color:p}),l>0&&k.createElement(M,{x:r-l,width:l,height:i,color:u}),d>0&&k.createElement(M,{y:i-d,width:r,height:d,color:f}),k.createElement(this.textRenderer.element,{value:o,font:a?.headerFont,width:c?r-18:r,height:i}),c&&k.createElement(Te,{width:r,height:i,direction:c,color:this.options.color})).draw(e,t,n)}},De=class e extends A{static defaultOptions={layer:`content`,font:`12px sans-serif`,color:`#fff`};renderer;constructor(t={}){super({...e.defaultOptions,...t}),this.renderer=new F({font:this.options.font,color:this.options.color})}get layer(){return this.options.layer}set font(e){this.options.font=e,this.renderer.font=e}get font(){return this.options.font}set color(e){this.options.color=e,this.renderer.color=e}get color(){return this.options.color}set pixelRatio(e){this.renderer.pixelRatio=e}get pixelRatio(){return this.renderer.pixelRatio}setTextStyle(e){this.renderer.setStyle(e)}clearCache(){this.renderer.clearCache()}draw({ctx:e,x:t,y:n,width:r,height:i,column:a,formatted:o,valueChanged:s,forced:c}){(s||c)&&(e.clearRect(t,n,r,i),k.createElement(this.renderer.element,{value:o,font:a?.font,width:r,height:i}).draw(e,t,n))}},L=(e,t,n)=>e===`inherit`?!t.fontSize||!t.fontFamily?n:[t.fontStyle,t.fontWeight,t.fontSize,t.fontFamily].filter(Boolean).join(` `):e,R={background:`--cg-background`,text:`--cg-text-color`,font:`--cg-font`,rowHeight:`--cg-row-height`,border:`--cg-border-color`,headerBackground:`--cg-header-background`,headerText:`--cg-header-text-color`,headerFont:`--cg-header-font`,headerHeight:`--cg-header-height`,headerBorder:`--cg-header-border-color`,headerBottomBorder:`--cg-header-bottom-border-color`,headerSelected:`--cg-header-selected-background`,headerFullySelected:`--cg-header-fully-selected-background`,zebra:`--cg-zebra-color`,hover:`--cg-hover-color`,flash:`--cg-flash-color`,selection:`--cg-selection-color`,selectionBorder:`--cg-selection-border-color`},Oe={font:`12px sans-serif`,rowHeight:20,headerFont:`13px sans-serif`,headerHeight:30,flash:`rgb(214, 144, 13)`},ke={dark:{...Oe,background:`#333`,text:`#efefef`,border:`#3b3b3b`,headerBackground:`#262626`,headerText:`#efefef`,headerBorder:`#333`,headerBottomBorder:`#4a4a4a`,headerSelected:`#2f3d4a`,headerFullySelected:`#3a5a7c`,zebra:`rgba(255, 255, 255, 0.025)`,hover:`rgba(255, 255, 255, 0.06)`,selection:`rgba(74, 144, 217, 0.25)`,selectionBorder:`#4a90d9`},light:{...Oe,background:`#fff`,text:`#1f2328`,border:`#e4e7eb`,headerBackground:`#f3f4f6`,headerText:`#1f2328`,headerBorder:`#e4e7eb`,headerBottomBorder:`#c9ced6`,headerSelected:`#dbe8f6`,headerFullySelected:`#b9d3ee`,zebra:`rgba(0, 0, 0, 0.025)`,hover:`rgba(0, 0, 0, 0.05)`,selection:`rgba(74, 144, 217, 0.2)`,selectionBorder:`#2f6fb5`}},Ae=[`rowHeight`,`headerHeight`],je=[`font`,`headerFont`],Me=e=>{let t=/^\d+(\.\d+)?(px)?$/.test(e)?parseFloat(e):NaN;return t>0?t:void 0},Ne=(e,{read:t,isColor:n,isFont:r})=>{let i=ke[e],a=(e,t)=>{if(t)return Ae.includes(e)?Me(t):je.includes(e)?r(t)?t:void 0:n(t)?t:void 0};return Object.fromEntries(Object.keys(R).map(e=>[e,a(e,t(R[e]).trim())??i[e]]))},Pe=(e,t)=>Object.keys(R).every(n=>e[n]===t[n]),Fe=e=>t=>{e.fillStyle=`#000000`,e.fillStyle=t;let n=e.fillStyle;return e.fillStyle=`#ffffff`,e.fillStyle=t,n===e.fillStyle},Ie=e=>typeof CSS>`u`||CSS.supports(`font`,e),Le=(e,t=20,n=1/0)=>Math.round(Math.max(t,Math.min(n,e))),Re=e=>{let t=Array(e.length+1);return t[0]=0,e.forEach((e,n)=>{t[n+1]=t[n]+Math.round(e)}),t},z=(e,t)=>{let n=e.length-2;if(n<0)return-1;let r=0,i=n;for(;r<i;){let n=r+i+1>>1;e[n]<=t?r=n:i=n-1}return r},ze=(e,t,n)=>{let r=z(e,t+n);if(r<0)return-1;let i=r>0&&Math.abs(e[r]-t)<=n?r-1:-1,a=Math.abs(e[r+1]-t)<=n?r:-1;return i>=0?i:a},B=(e,t)=>e<=t?[e,t]:[t,e],V=(e,t)=>({...e&&{rows:e},...t&&{columns:t}}),Be=(e,t)=>V(B(e.row,t.row),B(e.column,t.column)),H=(e,t,n)=>e===`range`?Be(t,n):e===`row`?V(B(t.row,n.row),void 0):e===`column`?V(void 0,B(t.column,n.column)):Be(n,n),U=e=>B(Math.max(0,Math.floor(e[0])),Math.max(0,Math.floor(e[1]))),W=e=>V(e.rows&&U(e.rows),e.columns&&U(e.columns)),Ve=e=>e&&[e[0],e[1]],He=e=>V(Ve(e.rows),Ve(e.columns)),G=(e,t,n)=>{let r=Math.max(0,e.rows?.[0]??0),i=Math.min(t-1,e.rows?.[1]??t-1),a=Math.max(0,e.columns?.[0]??0),o=Math.min(n-1,e.columns?.[1]??n-1);return r>i||a>o?void 0:{top:r,bottom:i,left:a,right:o}},K=(e,t)=>t===void 0||e>=t[0]&&e<=t[1],Ue=(e,t)=>e===void 0||e[0]<=0&&e[1]>=t-1,We=(e,t,n)=>K(t,e.rows)&&K(n,e.columns),Ge=(e,t,n)=>{let r=`none`;for(let i of e)if(K(t,i.columns)){if(Ue(i.rows,n))return`full`;r=`partial`}return r},Ke=(e,t,n)=>{let r=`none`;for(let i of e)if(K(t,i.rows)){if(Ue(i.columns,n))return`full`;r=`partial`}return r},qe=e=>e.rows===void 0&&e.columns===void 0?`all`:e.rows===void 0?`column`:e.columns===void 0?`row`:`block`,q=(e,t,n)=>e===`column`?V(void 0,B(t,n)):V(B(t,n),void 0),J=(e,t,n)=>e===`column`?{row:n,column:t}:{row:t,column:n},Y=(e,t)=>e===`column`?t.column:t.row,X=(e,t)=>e===`column`?t.row:t.column,Je=(e,t)=>e?.[0]===t?.[0]&&e?.[1]===t?.[1],Ye=(e,t)=>Je(e.rows,t.rows)&&Je(e.columns,t.columns),Xe=(e,t)=>e?.row===t?.row&&e?.column===t?.column,Ze=(e,t)=>e&&[e[0],Math.min(e[1],t-1)],Qe=(e,t,n)=>e&&{row:Math.min(e.row,t-1),column:Math.min(e.column,n-1)},$e=class{ranges=[];active=void 0;focus=void 0;assign(e,t,n){let r=e.length!==this.ranges.length||e.some((e,t)=>!Ye(e,this.ranges[t]))||!Xe(t,this.active);return this.ranges=e,this.active=t&&{row:t.row,column:t.column},this.focus=n&&{row:n.row,column:n.column},r}set(e,t,n=t){return this.assign([W(e)],t,n)}add(e,t){return this.assign([...this.ranges,W(e)],t,t)}extend(e,t){return this.ranges.length===0||this.active===void 0?this.set(e,t):this.assign([...this.ranges.slice(0,-1),W(e)],this.active,t)}clear(){return this.assign([],void 0,void 0)}activate(e){return this.assign(this.ranges,e,e)}replace(e,t){let n=e.map(W),r=n[n.length-1];if(r===void 0)return this.clear();let i=t??{row:r.rows?.[0]??0,column:r.columns?.[0]??0};return this.assign(n,i,i)}clamp(e,t){if(e===0||t===0)return this.clear();let n=this.ranges.filter(n=>G(n,e,t)!==void 0).map(n=>V(Ze(n.rows,e),Ze(n.columns,t)));return n.length===0?this.clear():this.assign(n,Qe(this.active,e,t),Qe(this.focus,e,t))}snapshot(){return{ranges:this.ranges.map(He),active:this.active&&{...this.active}}}},et=(e,t,n)=>e<t?-Math.min(30,Math.max(2,(t-e)/4)):e>n?Math.min(30,Math.max(2,(e-n)/4)):0,tt=(e,t)=>Math.max(0,Math.min(t,e)),nt=(e,t,n,{rowCount:r,columnCount:i,pageRows:a})=>{let o=r-1,s=i-1,c=(e,t)=>({row:tt(e,o),column:tt(t,s)});switch(t){case`ArrowUp`:return c(n?0:e.row-1,e.column);case`ArrowDown`:return c(n?o:e.row+1,e.column);case`ArrowLeft`:return c(e.row,n?0:e.column-1);case`ArrowRight`:return c(e.row,n?s:e.column+1);case`Home`:return c(n?0:e.row,0);case`End`:return c(n?o:e.row,s);case`PageUp`:return c(e.row-a,e.column);case`PageDown`:return c(e.row+a,e.column);default:return}},rt=(e,t,n,r)=>{let i=r?-1:1,[a,o,s,c]=n===`row`?[e.top,e.bottom,e.left,e.right]:[e.left,e.right,e.top,e.bottom],l=Y(n,t)+i;if(l>=a&&l<=o)return J(n,l,X(n,t));let u=c-s+1,d=s+((X(n,t)+i-s)%u+u)%u;return J(n,i>0?a:o,d)},it=(e,t,n,r)=>Math.min(e,Math.max(n,t-r)),at=1e6,ot=e=>/[\t\r\n"]/.test(e)?`"${e.replaceAll(`"`,`""`)}"`:e,st=(e,t,n=at)=>{let r=e.right-e.left+1,i=e.bottom-e.top+1,a=Math.min(i,Math.max(1,Math.floor(n/r)));return{text:Array.from({length:a},(n,i)=>Array.from({length:r},(n,r)=>ot(t(e.top+i,e.left+r))).join(` `)).join(`\r
|
|
2
|
-
`),truncated:a<i}},ct=class{element;host;onPick;constructor(e,t){this.host=e,this.onPick=t}get isOpen(){return this.element?.matches(`:popover-open`)??!1}open(e,t,n){this.close();let r=this.element??this.create();r.replaceChildren(...n.map(e=>this.createItem(e))),r.style.left=`${e}px`,r.style.top=`${t}px`,r.showPopover();let{width:i,height:a}=r.getBoundingClientRect();r.style.left=`${Math.max(0,Math.min(e,document.documentElement.clientWidth-i))}px`,r.style.top=`${Math.max(0,Math.min(t,document.documentElement.clientHeight-a))}px`,this.items().find(e=>!e.disabled)?.focus({preventScroll:!0})}close(){this.isOpen&&this.element?.hidePopover()}items(){return Array.from(this.element?.querySelectorAll(`[role="menuitem"]`)??[])}create(){let e=document.createElement(`div`);return e.className=`contextMenu`,e.role=`menu`,e.popover=`auto`,e.addEventListener(`keydown`,this.onKeyDown),e.addEventListener(`toggle`,t=>{t.newState===`closed`&&e.contains(document.activeElement)&&this.host.focus({preventScroll:!0})}),this.host.append(e),this.element=e,e}createItem({id:e,label:t,disabled:n}){let r=document.createElement(`button`);return r.type=`button`,r.role=`menuitem`,r.textContent=t,r.disabled=n,r.addEventListener(`click`,()=>{this.close(),this.onPick(e)}),r}onKeyDown=e=>{e.stopPropagation();let t=this.items().filter(e=>!e.disabled),n=t.indexOf(document.activeElement),r=e=>t[(e+t.length)%t.length]?.focus();if(e.key===`ArrowDown`)r(n+1);else if(e.key===`ArrowUp`)r(n<0?-1:n-1);else if(e.key===`Home`)r(0);else if(e.key===`End`)r(-1);else if(e.key===`Tab`)this.close();else return;e.preventDefault()}},Z={scrollArea:`scrollArea`,resizeGuide:`resizeGuide`,horizontalGuide:`horizontal`},Q={mouse:4,touch:12},lt=50,ut=500,dt=8,$={background:`background`,content:`content`,selection:`selection`,header:`header`,backgroundRenderer:`background`,valueRenderer:`value`,headerRenderer:`header`},ft=[$.background,$.content,$.selection,$.header],pt=`canvas-grid-styles`,mt=()=>{if(document.getElementById(pt))return;let e=document.createElement(`style`);e.id=pt,e.textContent=E,document.head.appendChild(e)},ht=e=>{let t=e.getRootNode();return e.parentElement??(t instanceof ShadowRoot?t.host:null)},gt=e=>{let t=[];for(let n=e;n;n=ht(n))t.push(n);return t},_t=2,vt=`12px sans-serif`,yt=`13px sans-serif`,bt=class e extends HTMLElement{fps=60;theme=ke.dark;_font=void 0;_headerFont=void 0;_headerHeight=void 0;_cellHeight=void 0;cellPadding={top:3,right:3,bottom:3,left:3};showRowNumbers=!0;showHeaders=!0;rowNumbersWidth=30;ellipsis=`…`;_backgroundColor=void 0;_headerBackgroundColor=void 0;_textColor=void 0;selectionColor=void 0;selectionBorderColor=void 0;get backgroundColor(){return this._backgroundColor??this.theme.background}set backgroundColor(e){this._backgroundColor=e,this.applyTheme()}get headerBackgroundColor(){return this._headerBackgroundColor??this.theme.headerBackground}set headerBackgroundColor(e){this._headerBackgroundColor=e,this.applyTheme()}get textColor(){return this._textColor??this.theme.text}set textColor(e){this._textColor=e,this.applyTheme()}get headerHeight(){return this._headerHeight??this.theme.headerHeight}set headerHeight(e){this._headerHeight=e}get cellHeight(){return this._cellHeight??this.theme.rowHeight}set cellHeight(e){this._cellHeight=e}dataStore=new w({getRowId:(e,t)=>this.getRowId(e,t),getCellHeight:()=>this.cellHeight,getRowHeight:e=>this.newRowHeight(e)});_dataCollection=this.dataStore.rows;cellEntries=new T(2048);getRowId=v;headers=new p;animationFrame=void 0;scrollYOffset=0;prevScrollYOffset=0;scrollXOffset=0;prevScrollXOffset=0;lastRender=new Date().valueOf();lastDraw=this.lastRender;isScrolling=!1;scrollHelper=document.createElement(`div`);scrollArea=this.createScrollArea();layers=[];layersByName=new Map;warnedLayers=new Set;renderers=new re;cellRenderers=[$.backgroundRenderer,$.valueRenderer];cellBackgroundRenderer=new ce({layer:$.background,background:this.theme.background,enableFlashing:!0,flashInDuration:200,flashOutDuration:400,flashColor:this.theme.flash,zebraColor:this.theme.zebra,hoverColor:this.theme.hover,borderRightWidth:1,borderRightColor:this.theme.border,borderBottomWidth:1,borderBottomColor:this.theme.border});cellValueRenderer=new De({layer:$.content,font:this.theme.font,color:this.theme.text});headerCellRenderer=new Ee({layer:$.header,font:this.theme.headerFont,color:this.theme.headerText,background:this.theme.headerBackground,selectedBackground:this.theme.headerSelected,fullySelectedBackground:this.theme.headerFullySelected,borderRightWidth:1,borderRightColor:this.theme.headerBorder,borderBottomWidth:1,borderBottomColor:this.theme.headerBottomBorder});loadingIndicator;cell;placeholderState={};throttleTransation=(0,d.default)(()=>{let e=this.totalHeight,t=this.dataStore.flush();e!==this.totalHeight&&this.refreshScrollbar(),this.refitSelection(),t&&this.forceDraw(),this.requestRender()},50);agApi;constructor(){super(),this.resize=this.resize.bind(this),this.setValues=this.setValues.bind(this),this.setColumns=this.setColumns.bind(this),this.clearValues=this.clearValues.bind(this),this.updateLastRender=this.updateLastRender.bind(this),this.transaction=this.transaction.bind(this),this.queueUpdate=this.queueUpdate.bind(this),this.addLayer($.background,{alpha:!1}),this.addLayer($.content),this.addLayer($.header),this.registerRenderer($.backgroundRenderer,this.cellBackgroundRenderer),this.registerRenderer($.valueRenderer,this.cellValueRenderer),this.registerRenderer($.headerRenderer,this.headerCellRenderer),this.loadingIndicator=new te({ctx:this.requireLayer($.header).ctx}),this.cell={ctx:this.requireLayer($.content).ctx,x:0,y:0,width:0,height:0,row:void 0,column:void 0,value:void 0,formatted:``,updatedAt:void 0,age:1/0,now:0,dt:0,valueChanged:!1,forced:!1,isScrolling:!1,selected:`none`,state:{}};let e=this;this.agApi={setRowData:this.setValues,updateRowData:this.transaction,setColumnDefs:this.setColumns,get getRowNodeId(){return e.getRowId},set getRowNodeId(t){typeof t==`function`&&(e.getRowId=t)}}}get canvas(){return this.requireLayer($.content).canvas}get flashInDuration(){return this.cellBackgroundRenderer.options.flashInDuration}set flashInDuration(e){this.cellBackgroundRenderer.update({flashInDuration:e})}get flashOutDuration(){return this.cellBackgroundRenderer.options.flashOutDuration}set flashOutDuration(e){this.cellBackgroundRenderer.update({flashOutDuration:e})}getLayer(e){return this.layersByName.get(e)}requireLayer(e){let t=this.getLayer(e);if(!t)throw Error(`canvas-grid: no layer named "${e}"`);return t}addLayer(e,{alpha:t=!0,desynchronized:n=!1,before:r}={}){if(this.getLayer(e))throw Error(`canvas-grid: layer "${e}" already exists`);let i=new ne(e,{alpha:t,desynchronized:n}),a=r===void 0?void 0:this.requireLayer(r);return this.layers.splice(a?this.layers.indexOf(a):this.layers.length,0,i),this.layersByName.set(e,i),this.scrollArea.parentElement===this&&(this.insertBefore(i.canvas,a?.canvas??this.scrollArea),i.resize(this.clientWidth,this.clientHeight,this.pixelRatio),this.forceDraw()),i}removeLayer(e){let t=this.requireLayer(e);this.layers=this.layers.filter(e=>e!==t),this.layersByName.delete(e),t.canvas.remove()}registerRenderer(e,t){this.renderers.register(e,t)}unregisterRenderer(e){this.renderers.unregister(e)}createScrollArea(){let e=document.createElement(`div`);return e.className=Z.scrollArea,e.appendChild(this.scrollHelper),e}set font(e){this._font!==e&&(this._font=e,this.cellValueRenderer.font=L(e,getComputedStyle(this),vt))}get font(){return this._font??this.theme.font}set headerFont(e){this._headerFont!==e&&(this._headerFont=e,this.headerCellRenderer.font=L(e,getComputedStyle(this),yt))}get headerFont(){return this._headerFont??this.theme.headerFont}textStyle={...P};setTextStyle(e){this.textStyle={...this.textStyle,...e},this.cellValueRenderer.setTextStyle(this.textStyle),this.headerCellRenderer.setTextStyle(this.textStyle),this.forceDraw()}set textRendering(e){this.setTextStyle({textRendering:e})}get textRendering(){return this.textStyle.textRendering}set fontKerning(e){this.setTextStyle({fontKerning:e})}get fontKerning(){return this.textStyle.fontKerning}set letterSpacing(e){this.setTextStyle({letterSpacing:e})}get letterSpacing(){return this.textStyle.letterSpacing}set textOverflow(e){this.setTextStyle({textOverflow:e})}get textOverflow(){return this.textStyle.textOverflow}set direction(e){this.setTextStyle({direction:e})}get direction(){return this.textStyle.direction}connectedCallback(){this.layers.forEach(e=>this.appendChild(e.canvas)),this.appendChild(this.scrollArea),this.appendChild(this.resizeGuide),this.updateLastRender(),this.refreshTheme(),this.refreshFonts(),this.watchTheme(),this.headers.length===0&&this.setColumns(Array(50).fill(1).map((e,t)=>t)),document.addEventListener(`visibilitychange`,this.onVisibilityChange),this.observeSize(),this.pixelRatioQuery=window.matchMedia(`(resolution: ${this.pixelRatio}dppx)`),this.pixelRatioQuery.addEventListener(`change`,this.watchPixelRatio,{once:!0}),document.fonts?document.fonts.addEventListener(`loadingdone`,this.onFontsLoaded):this.fontsTimeout=setTimeout(this.onFontsLoaded,2e3);let e=(0,f.default)(()=>{this.isScrolling=!1},200);this.scrollArea.addEventListener(`pointermove`,this.onPointerMove),this.scrollArea.addEventListener(`pointerleave`,this.onPointerLeave),this.scrollArea.addEventListener(`pointerdown`,this.onResizePointerDown),this.scrollArea.addEventListener(`pointermove`,this.onResizePointerMove),this.scrollArea.addEventListener(`pointerup`,this.onResizePointerEnd),this.scrollArea.addEventListener(`pointercancel`,this.onResizePointerEnd),this.scrollArea.addEventListener(`dblclick`,this.onResizeDoubleClick),this.scrollArea.addEventListener(`touchstart`,this.onResizeTouchStart,{passive:!1}),this.scrollArea.addEventListener(`pointerdown`,this.onSelectPointerDown),this.scrollArea.addEventListener(`pointermove`,this.onSelectPointerMove),this.scrollArea.addEventListener(`pointerup`,this.onSelectPointerEnd),this.scrollArea.addEventListener(`pointercancel`,this.onSelectPointerEnd),this.addEventListener(`keydown`,this.onKeyDown),this.addEventListener(`copy`,this.onCopy),this.addEventListener(`contextmenu`,this.onContextMenu),this.scrollArea.addEventListener(`scroll`,()=>{this.contextMenu?.close(),this.isScrolling=!0,this.updateHoveredRow(),e(),this.requestRender()})}hoverDirty=[];setHoveredRow(e){let t=this.cellBackgroundRenderer.hoveredRowIndex;t!==e&&(this.cellBackgroundRenderer.hover(e),this.hoverDirty.push(t,e),this.requestRender())}pointerY=void 0;updateHoveredRow(){if(this.pointerY===void 0)return;let e=this.pointerY-(this.showHeaders?this.headerHeight:0),t=this._dataCollection.indexAt(e+this.scrollArea.scrollTop);this.setHoveredRow(e<0||t>=this._dataCollection.length?void 0:t)}onPointerMove=e=>{this.pointerY=e.clientY-this.getBoundingClientRect().top,this.updateHoveredRow()};onPointerLeave=()=>{this.pointerY=void 0,this.setHoveredRow(void 0)};fontsTimeout=void 0;onVisibilityChange=()=>{document.visibilityState===`hidden`?this.cancelRender():this.resize()};refreshFonts(){this.cellValueRenderer.font=L(this.font,getComputedStyle(this),vt),this.headerCellRenderer.font=L(this.headerFont,getComputedStyle(this),yt),this.renderers.clearCaches(),this.resize()}onFontsLoaded=()=>this.refreshFonts();themeQuery=void 0;themeObserver=void 0;colorCheck=void 0;get themeName(){let e=this.getAttribute(`theme`);return e===`light`||e===`dark`?e:window.matchMedia(`(prefers-color-scheme: light)`).matches?`light`:`dark`}refreshTheme(){let e=getComputedStyle(this);this.colorCheck??=Fe(document.createElement(`canvas`).getContext(`2d`)??{fillStyle:``});let t=Ne(this.themeName,{read:t=>e.getPropertyValue(t),isColor:this.colorCheck,isFont:Ie});if(Pe(t,this.theme))return;let n=t.rowHeight!==this.theme.rowHeight||t.headerHeight!==this.theme.headerHeight;this.theme=t,n&&this.syncThemeHeights(),this.applyTheme()}applyTheme(){let{theme:e}=this;this.cellBackgroundRenderer.update({background:this.backgroundColor,borderRightColor:e.border,borderBottomColor:e.border,zebraColor:e.zebra,hoverColor:e.hover,flashColor:e.flash}),this.headerCellRenderer.update({background:this.headerBackgroundColor,color:this._textColor??e.headerText,selectedBackground:e.headerSelected,fullySelectedBackground:e.headerFullySelected,borderRightColor:e.headerBorder,borderBottomColor:e.headerBottomBorder}),this.cellValueRenderer.color=this.textColor,this.loadingIndicator.setColor(this.textColor),this.refreshFonts()}syncThemeHeights(){this._cellHeight===void 0&&this.rowHeightOf===void 0&&this._dataCollection.setHeights(e=>this.heightOfRow(e)),this.refreshRowHeights(),this.refreshScrollbar()}onThemeChange=()=>this.refreshTheme();watchTheme(){this.themeQuery=window.matchMedia(`(prefers-color-scheme: light)`),this.themeQuery.addEventListener(`change`,this.onThemeChange),this.themeObserver=new MutationObserver(this.onThemeChange),gt(this).forEach(e=>this.themeObserver?.observe(e,{attributes:!0,attributeFilter:[`class`,`style`,`theme`,`data-theme`]}))}unwatchTheme(){this.themeQuery?.removeEventListener(`change`,this.onThemeChange),this.themeObserver?.disconnect()}cancelRender(){this.animationFrame!==void 0&&cancelAnimationFrame(this.animationFrame),this.animationFrame=void 0}requestRender(){this.animationFrame??=requestAnimationFrame(()=>this.render())}updateLastRender(){this.lastRender=new Date().valueOf()}render(){if(this.animationFrame=void 0,this.readScrollOffsets(),this.relayoutPending){this.relayoutPending=!1,this.forceDraw(),this.updateLastRender();return}let e=new Date().valueOf()-this.lastRender;!this.isScrolling&&e<1e3/this.fps-_t?this.requestRender():(this.draw(),this.updateLastRender())}readScrollOffsets(){this.scrollXOffset=Math.round(this.scrollArea.scrollLeft),this.scrollYOffset=Math.round(this.scrollArea.scrollTop)}hasScrolled(){return this.hasXScrolled()||this.hasYScrolled()}hasYScrolled(){return this.prevScrollYOffset!==this.scrollYOffset}hasXScrolled(){return this.prevScrollXOffset!==this.scrollXOffset}isInViewport(e=0,t=0,n=0,r=0){return!(e>this.viewportWidth||t>this.viewportHeight||e+n<0||t+r<0)}describe(e,t,n,r,i){return Object.assign(this.cell,{x:e,y:t,width:n,height:r,row:void 0,column:void 0,value:void 0,formatted:``,updatedAt:void 0,age:1/0,valueChanged:!0,forced:!0,selected:`none`,state:this.placeholderState},i)}paint(e){let t=this.renderers.resolve(e),n=t&&this.layersByName.get(t.layer);t&&!n&&!this.warnedLayers.has(t.layer)&&(this.warnedLayers.add(t.layer),console.warn(`canvas-grid: renderer draws on missing layer "${t.layer}"`)),t&&n&&(this.cell.ctx=n.ctx,t.draw(this.cell))}paintAll(e){e.forEach(e=>this.paint(e))}isAnimating(e){return e.some(e=>this.renderers.resolve(e)?.isAnimating?.(this.cell)===!0)}draw(e=!1){let t=new Date().valueOf(),n=e||this.hasScrolled();this.cell.now=t,this.cell.dt=t-this.lastDraw,this.cell.isScrolling=this.isScrolling,this.lastDraw=t,!e&&this.hasScrolled()&&this.clearCustomLayers();let r=this._dataCollection.length===0;if((e||this.hasXScrolled()||this.headersDirty)&&this.showHeaders&&this.renderHeaders(),e&&this.showRowNumbers&&this._dataCollection.length===0)for(let e=0;e<=200;e++)this.renderRowNumber({index:e},e*this.cellHeight+(this.showHeaders?this.headerHeight:0)-this.scrollYOffset);if(this._dataCollection.length===0){this.loadingIndicator.render();for(let e=0;e<=200;e++)this.headers.forEach(t=>{this.describe(Math.round(this.columnOffsets[t.index]+(this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset),Math.round(e*this.cellHeight+(this.showHeaders?this.headerHeight:0)-this.scrollYOffset),t.width,this.cellHeight,{column:t,valueChanged:!1}),this.paintAll(t.renderers??this.cellRenderers)})}let i=Math.round((this.showHeaders?this.headerHeight:0)-this.scrollYOffset),a=Math.round((this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset),o=this._dataCollection.indexAt(-i),s=this.getVisibleColumns(a);for(let a=o;a<this._dataCollection.length;a++){let o=this._dataCollection.at(a),c=i+this._dataCollection.topOf(a);if(!o||c>=this.viewportHeight)break;let{id:l,slot:u}=o;if((e||this.hasYScrolled()||this.headersDirty)&&this.showRowNumbers&&this.renderRowNumber(o,c),o.height+c>0){let e=this.cellEntries.get(String(l));e||(e={},this.cellEntries.set(String(l),e));let i={id:l,index:o.index};for(let{header:l,id:d,x:f,store:p}of s){let s=p?.get(u);if(s===void 0)continue;let m=e[d]??={value:void 0,formatted:void 0,animating:!1,state:{}},h=m.formatted!==void 0&&m.value===s?m.formatted:l.valueFormatter(s),g=m.formatted!==h,_=p?.getUpdatedAt(u),{cell:v}=this;v.x=f,v.y=c,v.width=Math.round(l.width),v.height=o.height,v.row=i,v.column=l,v.value=s,v.formatted=h,v.updatedAt=_,v.age=_===void 0?1/0:t-_,v.valueChanged=g,v.forced=n,v.selected=`none`,v.state=m.state;let y=l.renderers??this.cellRenderers,b=this.isAnimating(y);(n||g||b||m.animating||this.hoverDirty.includes(a))&&this.paintAll(y),m.animating=b,m.value=s,m.formatted=h,r||=b}}}(n||this.selectionDirty)&&this.renderSelection(),(this.scrollYOffset>0||this.scrollXOffset>0)&&this.renderBrick(),this.hoverDirty=[],this.selectionDirty=!1,this.headersDirty=!1,this.prevScrollYOffset=this.scrollYOffset,this.prevScrollXOffset=this.scrollXOffset,r&&this.requestRender()}getVisibleColumns(e){let t=[],{columnList:n,columnOffsets:r}=this;for(let i=Math.max(0,z(r,-e));i<n.length;i++){let a=e+r[i];if(a>this.viewportWidth)break;let o=n[i];t.push({header:o,id:String(o.id),x:a,store:this.dataStore.columns.get(String(o.id))})}return t}columnList=[];columnOffsets=[0];updateColumnLayout(){this.columnList=[],this.headers.forEach(e=>this.columnList.push(e)),this.columnOffsets=Re(this.columnList.map(e=>e.width))}selectionDirty=!1;headersDirty=!1;columnSelection(e){let{ranges:t}=this.selectionModel;return t.length===0?`none`:Ge(t,e,this._dataCollection.length)}rowSelection(e){let{ranges:t}=this.selectionModel;return t.length===0?`none`:Ke(t,e,this.columnList.length)}selectionDrawn=!1;renderSelection(){let{ranges:e,active:t}=this.selectionModel;if(e.length===0&&!this.selectionDrawn)return;let n=this.getLayer($.selection);if(!n)return;let{ctx:r}=n;if(n.clear(),this.selectionDrawn=e.length>0,!this.selectionDrawn)return;let i=this.showRowNumbers?this.rowNumbersWidth:0,a=this.showHeaders?this.headerHeight:0,o=i-this.scrollXOffset,s=a-this.scrollYOffset,{_dataCollection:c,columnOffsets:l}=this,u=e=>{let t=G(e,c.length,this.columnList.length);if(!t)return;let n=o+l[t.left],r=s+c.topOf(t.top);return{x:n,y:r,width:o+l[t.right+1]-n,height:s+c.topOf(t.bottom+1)-r}};r.save(),r.beginPath(),r.rect(i,a,this.viewportWidth-i,this.viewportHeight-a),r.clip(),r.fillStyle=this.selectionColor??this.theme.selection,r.strokeStyle=this.selectionBorderColor??this.theme.selectionBorder,r.lineWidth=1,e.map(u).forEach(e=>{e&&(r.fillRect(e.x,e.y,e.width,e.height),r.strokeRect(e.x+.5,e.y+.5,e.width-1,e.height-1))});let d=t&&u({rows:[t.row,t.row],columns:[t.column,t.column]});d&&(r.clearRect(d.x,d.y,d.width,d.height),r.lineWidth=2,r.strokeRect(d.x+1,d.y+1,d.width-2,d.height-2)),r.restore()}renderRowNumber(e,t){this.isInViewport(0,t,this.rowNumbersWidth,e.height)&&(this.describe(0,Math.ceil(t),this.rowNumbersWidth,e.height??0,{row:{id:e.index,index:e.index},formatted:`${e.index+1}`,selected:this.rowSelection(e.index)}),this.paint($.headerRenderer))}clearCustomLayers(){this.layers.filter(e=>!ft.includes(e.name)).forEach(e=>e.clear())}forceDraw(){this.layers.forEach(e=>e.clear()),this.draw(!0)}viewportWidth=0;viewportHeight=0;get pixelRatio(){return window.devicePixelRatio||1}resize(){this.cancelRender();let{pixelRatio:e}=this;this.viewportWidth=this.clientWidth,this.viewportHeight=this.clientHeight,this.layers.forEach(t=>t.resize(this.clientWidth,this.clientHeight,e)),this.cellValueRenderer.pixelRatio!==e&&this.renderers.clearCaches(),this.cellValueRenderer.pixelRatio=e,this.headerCellRenderer.pixelRatio=e,this.forceDraw()}observeSize(){this.resizeObserver??=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this)}watchPixelRatio=()=>{this.pixelRatioQuery?.removeEventListener(`change`,this.watchPixelRatio),this.pixelRatioQuery=window.matchMedia(`(resolution: ${this.pixelRatio}dppx)`),this.pixelRatioQuery.addEventListener(`change`,this.watchPixelRatio,{once:!0}),this.resize()};resizeObserver=void 0;pixelRatioQuery=void 0;getRowData(e){let t=this._dataCollection.get(e);if(!t)return;let n={};return this.dataStore.columns.forEach((e,r)=>{let i=e.get(t.slot);i!==void 0&&(n[r]=i)}),{id:t.id,index:t.index,height:t.height,values:n}}setSortModel(e){this.dataStore.setSortModel(e),this.headerCellRenderer.setSortModel(e),this.forceDraw()}getSortModel(){return this.dataStore.getSortModel()}renderBrick(){this.showHeaders&&this.showRowNumbers&&this.headerBackgroundColor&&(this.describe(0,0,this.rowNumbersWidth,this.headerHeight,{}),this.paint($.headerRenderer))}renderHeaders(){let e=(this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset;this.getVisibleColumns(e).forEach(({header:e,x:t})=>{this.describe(t,0,Math.round(e.width),this.headerHeight,{column:e,formatted:e.displayName??``,selected:this.columnSelection(e.index)}),this.paint(e.headerRenderer)}),this.scrollXOffset+this.rowNumbersWidth>0&&this.renderBrick()}getColumnHeader(e){return this.headers.get(e)}requestRelayout(){this.relayoutPending=!0,this.requestRender()}relayoutPending=!1;emitResized(e,t,n){this.dispatchEvent(new CustomEvent(e,{detail:{columnId:t.id,width:t.width,source:n}}))}applyColumnWidths(e){let t=Array.from(e).map(([e,t])=>({column:this.headers.get(e),width:t})).filter(({column:e,width:t})=>e!==void 0&&Le(t,e.minWidth,e.maxWidth)!==Math.round(e.width)).flatMap(({column:e,width:t})=>e===void 0?[]:[{column:e,width:Le(t,e.minWidth,e.maxWidth)}]).map(({column:e,width:t})=>Object.assign(e,{width:t}));return t.length===0||(this.updateColumnLayout(),this.refreshScrollbar(),this.requestRelayout()),t}setColumnWidth(e,t){this.applyColumnWidths([[e,t]]).forEach(e=>this.emitResized(`columnresized`,e,`api`))}getColumnState(){return this.columnList.map(({id:e,width:t})=>({id:e,width:Math.round(t)}))}setColumnState(e){this.applyColumnWidths(e.map(({id:e,width:t})=>[e,t])).forEach(e=>this.emitResized(`columnresized`,e,`api`))}measureContext=void 0;autoSizeColumns(e){this.measureContext??=document.createElement(`canvas`).getContext(`2d`);let t=this.measureContext;if(!t)return;let{scrollTop:n}=this.scrollArea,r=[];for(let e=this._dataCollection.indexAt(n);e<this._dataCollection.length&&r.length<ut;e++){let t=this._dataCollection.at(e);if(!t||this._dataCollection.topOf(e)>n+this.viewportHeight)break;r.push(t)}let i=this.cellPadding.left+this.cellPadding.right+1,a=(e,n)=>(t.font=e,Math.max(0,...Array.from(n,e=>t.measureText(e).width))),o=(e??this.columnList.map(({id:e})=>e)).flatMap(e=>this.headers.get(e)??[]).map(e=>{let t=this.dataStore.columns.get(String(e.id)),n=r.flatMap(({slot:e})=>t?.get(e)??[]).map(t=>e.valueFormatter(t)),o=a(e.headerFont??this.headerCellRenderer.font,[e.displayName??``])+i+18,s=a(e.font??this.cellValueRenderer.font,n)+i;return[e.id,Math.ceil(Math.max(o,s))]});this.applyColumnWidths(o).forEach(e=>this.emitResized(`columnresized`,e,`auto`))}static MIN_ROW_HEIGHT=8;rowHeightOverrides=new Map;rowHeightOf=void 0;heightOfRow(t){let n=this.rowHeightOverrides.get(String(t))??this.rowHeightOf?.(t)??this.cellHeight;return Math.max(e.MIN_ROW_HEIGHT,Math.round(n))}newRowHeight=e=>this.rowHeightOverrides.size===0&&this.rowHeightOf===void 0?void 0:this.heightOfRow(e);refreshRowHeights(){this.refreshScrollbar(),this.requestRelayout()}emitRowResized(e,t,n){let r=this._dataCollection.get(t)?.height;r!==void 0&&this.dispatchEvent(new CustomEvent(e,{detail:{rowId:t,height:r,source:n}}))}setRowHeight(e){this.rowHeightOverrides.clear(),typeof e==`function`?this.rowHeightOf=e:(this.rowHeightOf=void 0,this._cellHeight=e),this._dataCollection.setHeights(e=>this.heightOfRow(e)),this.refreshRowHeights()}setRowHeightById(t,n){this.rowHeightOverrides.set(String(t),Math.max(e.MIN_ROW_HEIGHT,Math.round(n))),this._dataCollection.setHeight(t,this.heightOfRow(t))&&(this.refreshRowHeights(),this.emitRowResized(`rowresized`,t,`api`))}resizeDrag=void 0;findResizeTarget(e,t,n){let r=this.getBoundingClientRect(),i=e-r.left,a=t-r.top,o=n===`touch`?Q.touch:Q.mouse;if(i<0||a<0||i>this.scrollArea.clientWidth)return;let s=this.showRowNumbers?this.rowNumbersWidth:0,c=this.showHeaders?this.headerHeight:0;if(this.showHeaders&&a<=c)return this.findColumnBorder(i-s,o);if(this.showRowNumbers&&i<s)return this.findRowBorder(a-c,o)}findColumnBorder(e,t){if(e<0)return;let n=this.columnList[ze(this.columnOffsets,e+this.scrollArea.scrollLeft,t)];return n===void 0||n.resizable===!1?void 0:{axis:`column`,column:n}}findRowBorder(e,t){let n=this._dataCollection.at(this._dataCollection.borderAt(e+this.scrollArea.scrollTop,t));return n===void 0?void 0:{axis:`row`,row:n}}moveResizeGuide(){let{resizeDrag:e,resizeGuide:t}=this;if(t.style.display=e?`block`:`none`,!e)return;let n=e.axis===`row`;t.classList.toggle(Z.horizontalGuide,n);let r=this.showRowNumbers?this.rowNumbersWidth:0,i=this.showHeaders?this.headerHeight:0;t.style.transform=e.axis===`row`?`translateY(${i+this._dataCollection.topOf(e.row.index)+e.row.height-this.scrollArea.scrollTop}px)`:`translateX(${r+(this.columnOffsets[e.column.index+1]??0)-this.scrollArea.scrollLeft}px)`}resizeGuide=Object.assign(document.createElement(`div`),{className:Z.resizeGuide});onResizePointerDown=e=>{let t=e.button===0?this.findResizeTarget(e.clientX,e.clientY,e.pointerType):void 0;t&&(e.preventDefault(),this.scrollArea.setPointerCapture(e.pointerId),this.resizeDrag=t.axis===`row`?{...t,start:e.clientY,startSize:t.row.height,lastEvent:0}:{...t,start:e.clientX,startSize:t.column.width,lastEvent:0},this.moveResizeGuide())};onResizePointerMove=e=>{let{resizeDrag:t}=this;if(t)t.axis===`row`?this.dragRow(t,e.clientY-t.start):this.dragColumn(t,e.clientX-t.start),this.moveResizeGuide();else{let t=this.findResizeTarget(e.clientX,e.clientY,e.pointerType);this.scrollArea.style.cursor=t===void 0?``:`${t.axis===`row`?`row`:`col`}-resize`}};dragColumn(e,t){let{column:n}=e;this.applyColumnWidths([[n.id,e.startSize+t]]),this.dueForLiveEvent(e)&&this.emitResized(`columnresizing`,n,`drag`)}dragRow(t,n){let{id:r}=t.row;this.rowHeightOverrides.set(String(r),Math.max(e.MIN_ROW_HEIGHT,Math.round(t.startSize+n))),this._dataCollection.setHeight(r,this.heightOfRow(r))&&this.refreshRowHeights(),this.dueForLiveEvent(t)&&this.emitRowResized(`rowresizing`,r,`drag`)}dueForLiveEvent(e){let t=performance.now();return t-e.lastEvent<lt?!1:(e.lastEvent=t,!0)}onResizePointerEnd=e=>{let{resizeDrag:t}=this;t&&(this.resizeDrag=void 0,this.scrollArea.releasePointerCapture(e.pointerId),this.moveResizeGuide(),t.axis===`row`&&t.row.height!==t.startSize&&this.emitRowResized(`rowresized`,t.row.id,`drag`),t.axis===`column`&&t.column.width!==t.startSize&&this.emitResized(`columnresized`,t.column,`drag`))};onResizeDoubleClick=e=>{let t=this.findResizeTarget(e.clientX,e.clientY,`mouse`);if(t?.axis!==`column`)return;let{column:n}=t;n===this.columnList[this.columnList.length-1]&&this.fillRemainingSpace(n)||this.autoSizeColumns([n.id])};fillRemainingSpace(e){let t=this.scrollArea.clientWidth-(this.showRowNumbers?this.rowNumbersWidth:0)-this.columnOffsets[this.columnOffsets.length-1];return t<=0?!1:(this.applyColumnWidths([[e.id,e.width+t]]).forEach(e=>this.emitResized(`columnresized`,e,`auto`)),!0)}onResizeTouchStart=e=>{let[t]=Array.from(e.touches);e.touches.length===1&&this.findResizeTarget(t.clientX,t.clientY,`touch`)&&e.preventDefault()};selectionModel=new $e;mode=`none`;set selectionMode(e){e!==this.mode&&(this.mode=e,this.updateTabIndex(),e===`none`&&this.clearSelection())}ownsTabIndex=!1;updateTabIndex(){this.mode!==`none`&&!this.hasAttribute(`tabindex`)&&(this.tabIndex=0,this.ownsTabIndex=!0),this.mode===`none`&&this.ownsTabIndex&&(this.removeAttribute(`tabindex`),this.ownsTabIndex=!1)}get selectionMode(){return this.mode}getSelection(){return this.selectionModel.snapshot()}setSelection(e,t){this.changeSelection(()=>this.selectionModel.replace(e,t),!1)}clearSelection(){this.changeSelection(()=>this.selectionModel.clear(),!1)}emitSelectionChange(e){this.dispatchEvent(new CustomEvent(`selectionchange`,{detail:{...this.selectionModel.snapshot(),selecting:e}}))}emitCellFocus(){let{active:e}=this.selectionModel,t=e&&this._dataCollection.at(e.row),n=e&&this.columnList[e.column];e&&t&&n&&this.dispatchEvent(new CustomEvent(`cellfocus`,{detail:{rowId:t.id,rowIndex:e.row,columnId:n.id,columnIndex:e.column}}))}changeSelection(e,t){let n=this.selectionModel.active&&{...this.selectionModel.active};if(!e())return!1;this.selectionModel.ranges.length>0&&!this.getLayer($.selection)&&this.addLayer($.selection,{before:$.header}),this.selectionDirty=!0,this.headersDirty=!0,this.requestRender(),this.emitSelectionChange(t);let{active:r}=this.selectionModel;return r&&(r.row!==n?.row||r.column!==n.column)&&this.emitCellFocus(),!0}refitSelection(){this.selectionModel.ranges.length!==0&&(this.changeSelection(()=>this.selectionModel.clamp(this._dataCollection.length,this.columnList.length),!1),this.selectionDirty=!0)}selectDrag=void 0;touchTap=void 0;offsetsOf(e,t){let n=this.getBoundingClientRect(),r=this.showRowNumbers?this.rowNumbersWidth:0,i=this.showHeaders?this.headerHeight:0;return{x:e-n.left,y:t-n.top,left:r,top:i}}columnIndexAt(e){let t=z(this.columnOffsets,e);return t<0||e>=this.columnOffsets[this.columnOffsets.length-1]?void 0:t}rowIndexAt(e){let t=this._dataCollection.indexAt(e);return t>=this._dataCollection.length?void 0:t}hitAt(e,t){let{x:n,y:r,left:i,top:a}=this.offsetsOf(e,t);if(n<0||r<0||n>this.scrollArea.clientWidth||r>this.scrollArea.clientHeight)return;let o=r<a,s=n<i,c=this.columnIndexAt(n-i+this.scrollArea.scrollLeft),l=this.rowIndexAt(r-a+this.scrollArea.scrollTop);return o&&s?{zone:`all`}:o?c===void 0?void 0:{zone:`column`,column:c}:s?l===void 0?void 0:{zone:`row`,row:l}:c===void 0||l===void 0?void 0:{zone:`cell`,row:l,column:c}}nearestCell(e,t){let n=this._dataCollection.length;if(n===0||this.columnList.length===0)return;let{x:r,y:i,left:a,top:o}=this.offsetsOf(e,t);return{row:Math.min(n-1,this._dataCollection.indexAt(Math.max(0,i-o)+this.scrollArea.scrollTop)),column:z(this.columnOffsets,Math.max(0,r-a)+this.scrollArea.scrollLeft)}}firstVisible(e){return e===`column`?this._dataCollection.indexAt(this.scrollArea.scrollTop):Math.max(0,z(this.columnOffsets,this.scrollArea.scrollLeft))}pressCell(e,{extend:t,additive:n},r){let{selectionModel:i,mode:a}=this,{active:o}=i;if(t&&o&&a!==`cell`){let t=H(a,o,e);return this.changeSelection(()=>n?i.extend(t,e):i.set(t,o,e),r),{...o}}let s=H(a,e,e);return this.changeSelection(()=>n&&a!==`cell`?i.add(s,e):i.set(s,e),r),e}pressLine(e,t,{extend:n,additive:r},i){let{selectionModel:a}=this,{active:o}=a;if(n&&o){let n=q(e,Y(e,o),t),s=J(e,t,X(e,o));return this.changeSelection(()=>r?a.extend(n,s):a.set(n,o,s),i),{...o}}let s=J(e,t,this.firstVisible(e)),c=q(e,t,t);return this.changeSelection(()=>r?a.add(c,s):a.set(c,s),i),s}selectEverything(e){let t=this.selectionModel.active??{row:this.firstVisible(`column`),column:this.firstVisible(`row`)};this.changeSelection(()=>this.selectionModel.set({},t),e)}static ZONE_MODES={cell:[`cell`,`range`,`row`,`column`],column:[`range`,`column`],row:[`range`,`row`],all:[`range`,`row`,`column`]};press(t,n,r){if(e.ZONE_MODES[t.zone].includes(this.mode)){if(t.zone===`all`)this.selectEverything(r);else return t.zone===`column`?{anchor:this.pressLine(`column`,t.column,n,r),axis:`column`}:t.zone===`row`?{anchor:this.pressLine(`row`,t.row,n,r),axis:`row`}:{anchor:this.pressCell({row:t.row,column:t.column},n,r),axis:void 0}}}dragSelectTo({x:e,y:t,anchor:n,axis:r}){let i=this.nearestCell(e,t);if(!i)return;if(r){let e=J(r,Y(r,i),X(r,n));this.changeSelection(()=>this.selectionModel.extend(q(r,Y(r,n),Y(r,i)),e),!0);return}if(this.mode===`cell`)return;let a=H(this.mode,n,i);this.changeSelection(()=>this.selectionModel.extend(a,i),!0)}onSelectPointerDown=e=>{if(this.mode===`none`||e.button!==0||this.resizeDrag)return;let t=this.hitAt(e.clientX,e.clientY);if(!t)return;let n={extend:e.shiftKey,additive:e.ctrlKey||e.metaKey};if(e.pointerType===`touch`){this.touchTap={pointerId:e.pointerId,x:e.clientX,y:e.clientY,hit:t,modifiers:n};return}e.preventDefault(),this.focus({preventScroll:!0});let r=this.press(t,n,!0);r&&(this.scrollArea.setPointerCapture(e.pointerId),this.selectDrag={...r,pointerId:e.pointerId,x:e.clientX,y:e.clientY,frame:void 0})};onSelectPointerMove=e=>{let{touchTap:t,selectDrag:n}=this;t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>dt&&(this.touchTap=void 0),n&&n.pointerId===e.pointerId&&(n.x=e.clientX,n.y=e.clientY,this.dragSelectTo(n),n.frame??=requestAnimationFrame(this.scrollWhileDragging))};scrollWhileDragging=()=>{let e=this.selectDrag;if(!e)return;e.frame=void 0;let{x:t,y:n,left:r,top:i}=this.offsetsOf(e.x,e.y),a=e.axis===`row`?0:et(t,r,this.scrollArea.clientWidth),o=e.axis===`column`?0:et(n,i,this.scrollArea.clientHeight);(a!==0||o!==0)&&(this.scrollArea.scrollBy(a,o),this.dragSelectTo(e),e.frame=requestAnimationFrame(this.scrollWhileDragging))};onSelectPointerEnd=e=>{let{touchTap:t,selectDrag:n}=this;t?.pointerId===e.pointerId?(this.touchTap=void 0,e.type===`pointerup`&&(this.focus({preventScroll:!0}),this.press(t.hit,t.modifiers,!1))):n&&n.pointerId===e.pointerId&&(this.endSelectDrag(),this.scrollArea.hasPointerCapture(e.pointerId)&&this.scrollArea.releasePointerCapture(e.pointerId),this.emitSelectionChange(!1))};endSelectDrag(){this.selectDrag?.frame!==void 0&&cancelAnimationFrame(this.selectDrag.frame),this.selectDrag=void 0}revealCell({row:e,column:t}){let{scrollArea:n,_dataCollection:r,columnOffsets:i}=this,{left:a,top:o}=this.offsetsOf(0,0),s=it(r.topOf(e),r.topOf(e+1),n.scrollTop,n.clientHeight-o),c=it(i[t],i[t+1],n.scrollLeft,n.clientWidth-a);s!==n.scrollTop&&(n.scrollTop=s),c!==n.scrollLeft&&(n.scrollLeft=c)}get gridSize(){let{top:e}=this.offsetsOf(0,0);return{rowCount:this._dataCollection.length,columnCount:this.columnList.length,pageRows:Math.max(1,Math.floor((this.scrollArea.clientHeight-e)/this.cellHeight))}}moveTo(e){let t=H(this.mode,e,e);this.changeSelection(()=>this.selectionModel.set(t,e),!1),this.revealCell(e)}extendTo(e){let{selectionModel:t,mode:n}=this,{active:r,focus:i}=t,a=t.ranges[t.ranges.length-1];if(!r||!i||!a)return;let o=qe(a);if(o===`all`)return;if(o===`block`){let i=H(n,r,e);this.changeSelection(()=>t.extend(i,e),!1),this.revealCell(e);return}let s=o,c=q(s,Y(s,r),Y(s,e)),l=J(s,Y(s,e),X(s,i));this.changeSelection(()=>t.extend(c,l),!1),this.revealCell(l)}stepActive(e,t){let{selectionModel:n}=this,{active:r}=n,i=n.ranges[n.ranges.length-1],a=i&&G(i,this._dataCollection.length,this.columnList.length);if(!r)return!1;if(a&&(a.top!==a.bottom||a.left!==a.right)){let i=rt(a,r,e,t);return this.changeSelection(()=>n.activate(i),!1),this.revealCell(i),!0}if(e===`column`)return!1;let o=nt(r,t?`ArrowUp`:`ArrowDown`,!1,this.gridSize);return o&&this.moveTo(o),!0}selectLineOfActive(t){let{active:n}=this.selectionModel;if(!n||!e.ZONE_MODES[t].includes(this.mode))return!1;let r=q(t,Y(t,n),Y(t,n));return this.changeSelection(()=>this.selectionModel.set(r,n),!1),!0}collapseSelection(){let{active:e}=this.selectionModel;if(!e)return!1;let t=H(this.mode,e,e);return this.changeSelection(()=>this.selectionModel.set(t,e),!1)}navigate(e,t){let{active:n,focus:r}=this.selectionModel,i=this.gridSize;if(i.rowCount===0||i.columnCount===0)return!1;let a={row:this.firstVisible(`column`),column:this.firstVisible(`row`)},o=e.shiftKey&&this.mode!==`cell`,s=nt(n?o&&r||n:a,e.key,t,i);return s?(n?o?this.extendTo(s):this.moveTo(s):this.moveTo(a),!0):!1}handleSelectionKey(t){let n=t.ctrlKey||t.metaKey,{key:r,shiftKey:i}=t;return n&&r.toLowerCase()===`a`?e.ZONE_MODES.all.includes(this.mode)?(this.selectEverything(!1),!0):!1:r===` `&&n?this.selectLineOfActive(`column`):r===` `&&i?this.selectLineOfActive(`row`):r===`Enter`?this.stepActive(`row`,i):r===`Tab`?this.stepActive(`column`,i):r===`Escape`?this.collapseSelection():this.navigate(t,n)}onKeyDown=e=>{this.mode===`none`||e.defaultPrevented||e.altKey||!this.handleSelectionKey(e)||e.preventDefault()};copiedSelection(){let{ranges:e}=this.selectionModel,t=e[e.length-1],n=t&&G(t,this._dataCollection.length,this.columnList.length);if(!t||!n)return;let r=this.columnList.slice(n.left,n.right+1).map(e=>({header:e,store:this.dataStore.columns.get(String(e.id))})),{text:i,truncated:a}=st(n,(e,t)=>{let{header:i,store:a}=r[t-n.left],o=a?.get(this._dataCollection.at(e)?.slot??-1);return o===void 0?``:i.valueFormatter(o)});return{text:i,range:{...t},truncated:a}}requestCopy(){let e=this.mode===`none`?void 0:this.copiedSelection();if(e)return this.dispatchEvent(new CustomEvent(`selectioncopy`,{detail:e,cancelable:!0}))?e:void 0}onCopy=e=>{let t=e.clipboardData&&this.requestCopy();t&&e.clipboardData&&(e.clipboardData.setData(`text/plain`,t.text),e.preventDefault())};async copySelection(){let e=this.requestCopy();return e?(await navigator.clipboard.writeText(e.text),!0):!1}contextMenuItems=[{id:`copy`,label:`Copy`,disabled:()=>this.selectionModel.ranges.length===0,run:()=>void this.copySelection()}];contextMenu;menuDetail;isSelected(e){let{ranges:t}=this.selectionModel;return e.zone===`cell`?t.some(t=>We(t,e.row,e.column)):e.zone===`column`?Ge(t,e.column,this._dataCollection.length)===`full`:e.zone===`row`?Ke(t,e.row,this.columnList.length)===`full`:t.some(e=>qe(e)===`all`)}menuAnchor(){let{x:e,y:t,left:n,top:r}=this.offsetsOf(0,0),{active:i}=this.selectionModel;return i?{x:n-e+this.columnOffsets[i.column]-this.scrollArea.scrollLeft,y:r-t+this._dataCollection.topOf(i.row+1)-this.scrollArea.scrollTop}:{x:n-e,y:r-t}}onContextMenu=e=>{if(this.mode===`none`||this.contextMenuItems.length===0||e.defaultPrevented)return;let t=e.button===2,n=t?this.hitAt(e.clientX,e.clientY):void 0;if(t&&!n)return;e.preventDefault(),this.focus({preventScroll:!0}),n&&!this.isSelected(n)&&this.press(n,{extend:!1,additive:!1},!1);let r=t?{x:e.clientX,y:e.clientY}:this.menuAnchor(),i=this.selectionModel.active,a={...this.selectionModel.snapshot(),...r,row:n?n.zone===`cell`||n.zone===`row`?n.row:void 0:i?.row,column:n?n.zone===`cell`||n.zone===`column`?n.column:void 0:i?.column,items:[...this.contextMenuItems]};this.dispatchEvent(new CustomEvent(`gridcontextmenu`,{detail:a,cancelable:!0}))&&a.items.length!==0&&(this.menuDetail=a,this.contextMenu??=new ct(this,e=>this.menuDetail?.items.find(t=>t.id===e)?.run(this.menuDetail)),this.contextMenu.open(a.x,a.y,a.items.map(({id:e,label:t,disabled:n})=>({id:e,label:t,disabled:typeof n==`function`?n(a):n??!1}))))};get totalHeight(){return this._dataCollection.totalHeight}refreshScrollbar(){let e=this.totalHeight+this.headerHeight;this.scrollHelper.style.height=`${e}px`;let t=this.columnOffsets[this.columnOffsets.length-1];this.scrollHelper.style.width=`${t}px`}queueUpdate(e){this.dataStore.queueUpdate(e),this.throttleTransation()}queueRemove(e){this.dataStore.queueRemove(e),this.throttleTransation()}transaction({add:e=[],remove:t=[],update:n=[]}){Array.isArray(e)&&e.forEach(e=>this.queueUpdate(e)),Array.isArray(n)&&n.forEach(e=>this.queueUpdate(e)),Array.isArray(t)&&t.forEach(e=>this.queueRemove(e))}clearValues(){this.dataStore.clear(),this.cellEntries.clear()}formatValue(e,t){return this.headers.get(e)?.valueFormatter(t)??String(t)}setValues(e){this.throttleTransation.cancel(),this.clearValues(),Array.isArray(e)&&(this.dataStore.setRows(e),this.refreshScrollbar(),this.refitSelection(),this.forceDraw())}setColumns(e){if(Array.isArray(e)){this.headers.clear(),this.cellEntries.clear();let t={width:100,valueFormatter:e=>String(e),headerRenderer:$.headerRenderer};e.forEach((e,n)=>{if(typeof e==`string`||typeof e==`number`){let r=e+``;this.headers.set(r,{...t,index:n,id:e,displayName:r})}typeof e==`object`&&this.headers.set(e.id+``,{...t,index:n,...e})}),this.updateColumnLayout(),this.refreshScrollbar(),this.refitSelection(),this.forceDraw()}}disconnectedCallback(){this.cancelRender(),this.endSelectDrag(),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.resizeObserver?.disconnect(),this.pixelRatioQuery?.removeEventListener(`change`,this.watchPixelRatio),this.unwatchTheme(),document.fonts?.removeEventListener(`loadingdone`,this.onFontsLoaded),clearTimeout(this.fontsTimeout)}};return window&&window.customElements&&(mt(),customElements.define(`canvas-grid`,bt)),bt});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.CanvasGrid=t())})(this,function(){var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n)),l=o(((e,t)=>{var n=`Expected a function`,r=NaN,i=/^\s+|\s+$/g,a=/^[-+]0x[0-9a-f]+$/i,o=/^0b[01]+$/i,s=/^0o[0-7]+$/i,c=parseInt,l=typeof global==`object`&&global&&global.Object===Object&&global,u=typeof self==`object`&&self&&self.Object===Object&&self,d=l||u||Function(`return this`)(),f=Object.prototype.toString,p=Math.max,m=Math.min,h=function(){return d.Date.now()};function g(e,t,r){var i,a,o,s,c,l,u=0,d=!1,f=!1,g=!0;if(typeof e!=`function`)throw TypeError(n);t=x(t)||0,v(r)&&(d=!!r.leading,f=`maxWait`in r,o=f?p(x(r.maxWait)||0,t):o,g=`trailing`in r?!!r.trailing:g);function _(t){var n=i,r=a;return i=a=void 0,u=t,s=e.apply(r,n),s}function y(e){return u=e,c=setTimeout(C,t),d?_(e):s}function b(e){var n=e-l,r=e-u,i=t-n;return f?m(i,o-r):i}function S(e){var n=e-l,r=e-u;return l===void 0||n>=t||n<0||f&&r>=o}function C(){var e=h();if(S(e))return w(e);c=setTimeout(C,b(e))}function w(e){return c=void 0,g&&i?_(e):(i=a=void 0,s)}function T(){c!==void 0&&clearTimeout(c),u=0,i=l=a=c=void 0}function E(){return c===void 0?s:w(h())}function D(){var e=h(),n=S(e);if(i=arguments,a=this,l=e,n){if(c===void 0)return y(l);if(f)return c=setTimeout(C,t),_(l)}return c===void 0&&(c=setTimeout(C,t)),s}return D.cancel=T,D.flush=E,D}function _(e,t,r){var i=!0,a=!0;if(typeof e!=`function`)throw TypeError(n);return v(r)&&(i=`leading`in r?!!r.leading:i,a=`trailing`in r?!!r.trailing:a),g(e,t,{leading:i,maxWait:t,trailing:a})}function v(e){var t=typeof e;return!!e&&(t==`object`||t==`function`)}function y(e){return!!e&&typeof e==`object`}function b(e){return typeof e==`symbol`||y(e)&&f.call(e)==`[object Symbol]`}function x(e){if(typeof e==`number`)return e;if(b(e))return r;if(v(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=v(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=e.replace(i,``);var n=o.test(e);return n||s.test(e)?c(e.slice(2),n?2:8):a.test(e)?r:+e}t.exports=_})),u=o(((e,t)=>{var n=NaN,r=/^\s+|\s+$/g,i=/^[-+]0x[0-9a-f]+$/i,a=/^0b[01]+$/i,o=/^0o[0-7]+$/i,s=parseInt,c=typeof global==`object`&&global&&global.Object===Object&&global,l=typeof self==`object`&&self&&self.Object===Object&&self,u=c||l||Function(`return this`)(),d=Object.prototype.toString,f=Math.max,p=Math.min,m=function(){return u.Date.now()};function h(e,t,n){var r,i,a,o,s,c,l=0,u=!1,d=!1,h=!0;if(typeof e!=`function`)throw TypeError(`Expected a function`);t=y(t)||0,g(n)&&(u=!!n.leading,d=`maxWait`in n,a=d?f(y(n.maxWait)||0,t):a,h=`trailing`in n?!!n.trailing:h);function _(t){var n=r,a=i;return r=i=void 0,l=t,o=e.apply(a,n),o}function v(e){return l=e,s=setTimeout(S,t),u?_(e):o}function b(e){var n=e-c,r=e-l,i=t-n;return d?p(i,a-r):i}function x(e){var n=e-c,r=e-l;return c===void 0||n>=t||n<0||d&&r>=a}function S(){var e=m();if(x(e))return C(e);s=setTimeout(S,b(e))}function C(e){return s=void 0,h&&r?_(e):(r=i=void 0,o)}function w(){s!==void 0&&clearTimeout(s),l=0,r=c=i=s=void 0}function T(){return s===void 0?o:C(m())}function E(){var e=m(),n=x(e);if(r=arguments,i=this,c=e,n){if(s===void 0)return v(c);if(d)return s=setTimeout(S,t),_(c)}return s===void 0&&(s=setTimeout(S,t)),o}return E.cancel=w,E.flush=T,E}function g(e){var t=typeof e;return!!e&&(t==`object`||t==`function`)}function _(e){return!!e&&typeof e==`object`}function v(e){return typeof e==`symbol`||_(e)&&d.call(e)==`[object Symbol]`}function y(e){if(typeof e==`number`)return e;if(v(e))return n;if(g(e)){var t=typeof e.valueOf==`function`?e.valueOf():e;e=g(t)?t+``:t}if(typeof e!=`string`)return e===0?e:+e;e=e.replace(r,``);var c=a.test(e);return c||o.test(e)?s(e.slice(2),c?2:8):i.test(e)?n:+e}t.exports=h})),d=c(l()),f=c(u()),p=class{entries=new Map;constructor(){this.get=this.get.bind(this),this.set=this.set.bind(this),this.clear=this.clear.bind(this),this.forEach=this.forEach.bind(this)}get keys(){return Array.from(this.entries.values(),e=>e.key)}get(e){return this.entries.get(String(e))?.value}set(e,t){let n=this.entries.get(String(e));n?n.value=t:this.entries.set(String(e),{key:e,value:t})}add(e){this.set(this.entries.size,e)}delete(e){this.entries.delete(String(e))}clear(e){typeof e==`function`?this.entries.forEach(({key:t,value:n},r)=>{e(n,t)&&this.entries.delete(r)}):this.entries.clear()}forEach(e){this.entries.forEach(({key:t,value:n})=>e(n,t))}get length(){return this.entries.size}},m=class{values;version=0;updatedAt=void 0;constructor(e=0){this.values=Array(e).fill(void 0)}get(e){return this.values[e]}getUpdatedAt(e){return this.updatedAt?.[e]||void 0}set(e,t,n){for(this.version++;this.values.length<e;)this.values.push(void 0);if(this.values[e]=t,n!==void 0||this.updatedAt!==void 0){for(this.updatedAt??=Array(this.values.length).fill(0);this.updatedAt.length<this.values.length;)this.updatedAt.push(0);this.updatedAt[e]=n??0}}clearSlots(e){this.version++,e.forEach(e=>{e<this.values.length&&(this.values[e]=void 0),this.updatedAt&&e<this.updatedAt.length&&(this.updatedAt[e]=0)})}compact(e){this.version++,this.values=Array.from(e,e=>this.values[e]);let{updatedAt:t}=this;t&&(this.updatedAt=Array.from(e,e=>t[e]??0))}},h=1024,g=class{items=[];byId=new Map;tops=[];end=0;nextSlot=0;get length(){return this.items.length}get totalHeight(){return this.end}get slotCount(){return this.nextSlot}get keys(){return this.items.map(e=>e.id)}get(e){return this.byId.get(String(e))}at(e){return this.items[e]}topOf(e){return this.tops[e]??this.end}indexAt(e){if(e<=0)return 0;if(e>=this.end)return this.length;let t=0,n=this.items.length-1;for(;t<n;){let r=Math.ceil((t+n)/2);this.tops[r]<=e?t=r:n=r-1}return t}set(e){let t=String(e.id),n=this.byId.get(t);if(n){let r={id:e.id,height:e.height,index:n.index,slot:n.slot};return this.items[n.index]=r,this.byId.set(t,r),this.reindexFrom(n.index),r}let r=this.items.length,i={id:e.id,height:e.height,index:r,slot:this.nextSlot++};return this.items.push(i),this.byId.set(t,i),this.tops.push(this.end),this.end+=Math.round(e.height),i}setHeight(e,t){let n=this.get(e);return!n||n.height===t?!1:(n.height=t,this.reindexFrom(n.index),!0)}setHeights(e){this.items.forEach(t=>{t.height=e(t.id)}),this.reindexFrom(0)}borderAt(e,t){if(this.items.length===0)return-1;let n=this.indexAt(e),r=n<this.items.length?Math.abs(this.topOf(n+1)-e):1/0,i=n>0?Math.abs(this.topOf(n)-e):1/0;return Math.min(i,r)>t?-1:i<r?n-1:n}removeMany(e){let t=new Set;if(e.forEach(e=>{let n=this.get(e);n&&t.add(n)}),t.size===0)return[];t.forEach(e=>this.byId.delete(String(e.id)));let n=Array.from(t,e=>e.index).sort((e,t)=>e-t);return this.closeGaps(n),this.reindexFrom(n[0]),Array.from(t,e=>e.slot).sort((e,t)=>e-t)}compactSlots(){let e=this.nextSlot-this.items.length;if(e<h||e<=this.items.length)return;let t=Int32Array.from(this.items,e=>e.slot).sort(),n=new Int32Array(this.nextSlot);return t.forEach((e,t)=>{n[e]=t}),this.items.forEach(e=>{e.slot=n[e.slot]}),this.nextSlot=this.items.length,t}sort(e){this.items.sort(e),this.reindexFrom(0)}resort(e,t){let n=new Set;for(let t of e){let e=this.get(t);e&&n.add(e)}if(n.size===0)return;let r=Array.from(n,e=>e.index).sort((e,t)=>e-t);this.closeGaps(r);let i=Array.from(n).sort(t),a=i.map(e=>this.lowerBound(this.items,e,t)),o=this.items.length;i.forEach(e=>this.items.push(e));let{items:s}=this,c=o;for(let e=i.length-1;e>=0;e--){for(let t=c-1;t>=a[e];t--)s[t+e+1]=s[t];s[a[e]+e]=i[e],c=a[e]}this.reindexFrom(Math.min(r[0],a[0]))}clear(){this.items=[],this.byId.clear(),this.tops=[],this.end=0,this.nextSlot=0}closeGaps(e){let{items:t}=this,n=e[0];e.forEach((r,i)=>{let a=e[i+1]??t.length;for(let e=r+1;e<a;e++)t[n++]=t[e]}),t.length=n}lowerBound(e,t,n){let r=0,i=e.length;for(;r<i;){let a=r+i>>>1;n(e[a],t)<0?r=a+1:i=a}return r}reindexFrom(e){this.tops.length=this.items.length;let t=e===0?0:this.tops[e-1]+Math.round(this.items[e-1].height);for(let n=e;n<this.items.length;n++){let e=this.items[n];e.index=n,this.tops[n]=t,t+=Math.round(e.height)}this.end=t}},_=()=>new Date().valueOf(),v=(e,t)=>e.id,y=new Intl.Collator,b=8,x=e=>e==null?3:typeof e==`number`||typeof e==`bigint`?0:typeof e==`string`?1:2,S=(e,t)=>{let n=x(e)-x(t);return n===0?x(e)===3?0:x(e)===0?Number(e)-Number(t):y.compare(String(e),String(t)):n},C=e=>{let t=new Uint8Array(e.length),n=new Float64Array(e.length),r=new Int32Array(e.length),i=new Map;for(let a=0;a<e.length;a++){let o=e[a],s=x(o);if(t[a]=s,s===0){n[a]=Number(o);continue}if(s!==1&&s!==2)continue;let c=String(o),l=i.get(c);l===void 0&&(l=i.size,i.set(c,l)),r[a]=l}let a=new Float64Array(i.size),o=Array.from(i.keys()).sort(y.compare),s=0;o.forEach((e,t)=>{t>0&&y.compare(o[t-1],e)!==0&&s++,a[i.get(e)??0]=s});for(let i=0;i<e.length;i++)(t[i]===1||t[i]===2)&&(n[i]=a[r[i]]);return{ranks:t,keys:n}},w=class{rows=new g;columns=new Map;pending=[];sortModel=[];sortDirty=!1;sortChanged=new Set;defaultKeys=new WeakMap;environment;constructor(e){this.environment=e}get hasPending(){return this.pending.length>0}getSortModel(){return this.sortModel}setSortModel(e){this.sortModel=[...e],this.sort()}getValue(e,t){let n=this.rows.get(e);return n?this.columns.get(String(t))?.get(n.slot):void 0}getUpdatedAt(e,t){let n=this.rows.get(e);return n?this.columns.get(String(t))?.getUpdatedAt(n.slot):void 0}setValue(e,t,n,r=_()){let i=this.rows.get(e);return!i||(this.applyValue(e,i.slot,String(t),n,r),!this.sortDirty)?!1:(this.sortChanges(),!0)}queueUpdate(e){this.pending.push({type:`update`,row:e})}queueRemove(e){this.pending.push({type:`remove`,row:e})}clear(){this.rows.clear(),this.columns.clear()}setRows(e){this.pending=[],this.clear(),this.sortChanged.clear(),Object.keys(e[0]??{}).forEach(t=>this.columns.set(t,new m(e.length))),e.forEach((e,t)=>this.addRow(this.environment.getRowId(e,t),e,void 0)),this.sortModel.length>0&&this.sort()}flush(e=_()){let t=this.pending;this.pending=[];let n=[],r=!1,i=()=>{r=this.removeRows(n)||r,n.length=0};return t.forEach(({type:t,row:r})=>{t===`remove`?n.push(this.environment.getRowId(r)):(i(),this.applyUpdate(r,e))}),i(),this.sortDirty?(this.sortChanges(),!0):r}column(e){let t=this.columns.get(e);return t||(t=new m(this.rows.slotCount),this.columns.set(e,t)),t}addRow(e,t,n){let{slot:r}=this.rows.set({id:e,height:this.environment.getCellHeight()}),i=Object.keys(t);for(let e of i)this.column(e).set(r,t[e],n);this.markSortDirty(e,i);let a=this.environment.getRowHeight?.(e);a!==void 0&&this.rows.setHeight(e,a)}removeRows(e){if(e.length===0)return!1;let t=this.rows.removeMany(e);this.columns.forEach(e=>e.clearSlots(t));let n=this.rows.compactSlots();return n&&this.columns.forEach(e=>e.compact(n)),t.length>0}applyUpdate(e,t){let n=this.environment.getRowId(e),r=this.rows.get(n);r?Object.keys(e).forEach(n=>this.applyValue(r.id,r.slot,n,e[n],t)):this.addRow(n,e,t)}applyValue(e,t,n,r,i){let a=this.column(n),o=a.get(t);o!==r&&(a.set(t,r,o===void 0?void 0:i),this.markSortDirty(e,[n]))}markSortDirty(e,t){this.sortModel.some(({columnId:e})=>t.includes(String(e)))&&(this.sortDirty=!0,this.sortChanged.add(String(e)))}defaultKeyOf(e){let t=this.defaultKeys.get(e);if(t&&t.version===e.version)return t.key;let n=C(e.values);return this.defaultKeys.set(e,{version:e.version,key:n}),n}createComparator(e){let[t,...n]=this.sortModel,r=t&&!t.compare&&e&&n.length===0?this.columns.get(String(t.columnId)):void 0;if(r){let{ranks:e,keys:n}=this.defaultKeyOf(r),i=t.direction===`desc`?-1:1;return(t,r)=>{let a=e[t.slot]-e[r.slot]||n[t.slot]-n[r.slot]||0;return a===0?t.slot-r.slot:a*i}}let i=this.sortModel.map(({columnId:t,direction:n=`asc`,compare:r})=>{let i=this.columns.get(String(t)),a=i?.values,o=n===`desc`?-1:1;if(!i||!a)return{order:()=>0,sign:o};if(r)return{order:(e,t)=>r(a[e.slot],a[t.slot]),sign:o};if(!e)return{order:(e,t)=>S(a[e.slot],a[t.slot]),sign:o};let{ranks:s,keys:c}=this.defaultKeyOf(i);return{order:(e,t)=>s[e.slot]-s[t.slot]||c[e.slot]-c[t.slot]||0,sign:o}});return(e,t)=>{for(let{order:n,sign:r}of i){let i=n(e,t);if(i!==0)return i*r}return e.slot-t.slot}}sort(){this.sortDirty=!1,this.sortChanged.clear(),this.rows.sort(this.createComparator(!0))}sortChanges(){let e=this.sortChanged;e.size*b>=this.rows.length?this.sort():(this.sortDirty=!1,this.sortChanged=new Set,this.rows.resort(e,this.createComparator(!1)))}},T=class{entries=new Map;limit;constructor(e){this.limit=e}get(e){let t=this.entries.get(e);if(t!==void 0)return this.entries.delete(e),this.entries.set(e,t),t}set(e,t){this.entries.delete(e),this.entries.set(e,t);let[n]=this.entries.keys();this.entries.size>this.limit&&n!==void 0&&this.entries.delete(n)}clear(){this.entries.clear()}get size(){return this.entries.size}},E=`canvas-grid{isolation:isolate;display:block;position:relative}canvas-grid,canvas-grid *{box-sizing:border-box;margin:0;padding:0}canvas-grid:focus:not(:focus-visible){outline:none}canvas-grid .drawingLayer{contain:strict;width:100%;height:100%;position:absolute;top:0;left:0}canvas-grid .scrollArea{scrollbar-width:thin;scrollbar-color:var(--cg-scrollbar-color,#555) transparent;z-index:10;backface-visibility:hidden;will-change:transform;width:100%;height:100%;position:absolute;top:0;left:0;overflow:auto}canvas-grid .scrollArea>div{will-change:scroll-position, transform}canvas-grid .cellEditor{z-index:12;background:var(--cg-background,#333);color:var(--cg-text-color,#efefef);outline:2px solid var(--cg-selection-border-color,#4a90d9);outline-offset:-2px;display:flex;position:absolute}canvas-grid .cellEditor.invalid{outline-color:var(--cg-invalid-color,#d9534f)!important}canvas-grid .cellEditor>input:not([type=checkbox]){min-width:0;height:100%;color:inherit;font:inherit;padding:0 var(--cg-editor-padding-right,3px) 0 var(--cg-editor-padding-left,3px);background:0 0;border:0;outline:0;flex:1;line-height:normal}canvas-grid .cellEditor>input.number{font-variant-numeric:tabular-nums}canvas-grid .cellEditor>.cellSelect{min-width:0;padding:0 var(--cg-editor-padding-right,3px) 0 var(--cg-editor-padding-left,3px);cursor:pointer;outline:0;flex:1;align-items:center;display:flex;position:relative}canvas-grid .cellEditor>.cellSelect:after{content:"";border:4px solid #0000;border-top-color:currentColor;border-bottom-width:0;flex:none;margin-left:auto}canvas-grid .cellEditor>.cellSelect>.cellSelectLabel{white-space:nowrap;text-overflow:ellipsis;flex:1;min-width:0;overflow:hidden}canvas-grid .cellEditor>input[type=checkbox]{margin:auto 0 auto var(--cg-editor-padding-left,3px)}canvas-grid .resizeGuide{pointer-events:none;z-index:11;background:#4a90d9;width:1px;height:100%;display:none;position:absolute;top:0;left:0}canvas-grid .resizeGuide.horizontal{width:100%;height:1px}canvas-grid[theme=light] .scrollArea{scrollbar-color:var(--cg-scrollbar-color,#b4bac2) transparent}@media (prefers-color-scheme:light){canvas-grid:not([theme=dark]) .scrollArea{scrollbar-color:var(--cg-scrollbar-color,#b4bac2) transparent}}canvas-grid .contextMenu{border:1px solid var(--canvas-grid-menu-border,#3d4650);background:var(--canvas-grid-menu-background,#1f262d);min-width:160px;color:var(--canvas-grid-menu-color,#e6edf3);border-radius:6px;margin:0;padding:4px;font:13px system-ui,sans-serif;position:fixed;inset:auto;box-shadow:0 6px 20px #0006}canvas-grid .contextMenu button{width:100%;color:inherit;font:inherit;text-align:left;cursor:pointer;background:0 0;border:0;border-radius:4px;padding:6px 10px;display:block}canvas-grid .contextMenu button:hover:not(:disabled),canvas-grid .contextMenu button:focus-visible{background:var(--canvas-grid-menu-hover,#2f3d4a);outline:none}canvas-grid .contextMenu button:disabled{opacity:.5;cursor:default}.cellSelectList{box-sizing:border-box;background:var(--cg-editor-background,#333);color:var(--cg-editor-text,#efefef);font:inherit;border:1px solid var(--cg-editor-border,#555);outline:1px solid var(--cg-editor-accent,#4a90d9);outline-offset:-1px;scrollbar-width:thin;margin:0;padding:2px 0;position:fixed;inset:auto;overflow-y:auto;box-shadow:0 4px 12px #0000004d}.cellSelectList>[role=option]{white-space:nowrap;cursor:pointer;padding:3px 8px}.cellSelectList>[role=option]:hover{background:var(--cg-editor-highlight,#4a90d940)}.cellSelectList>[role=option].active{background:var(--cg-editor-accent,#4a90d9);color:var(--cg-editor-background,#333)}`,D=e=>!!e,O=e=>t=>({draw:(n,r,i)=>e(n,t,r,i)}),ee=({x:e=0,y:t=0,children:n})=>({draw:(r,i,a)=>[n].flat(2).filter(D).forEach(n=>n.draw(r,i+e,a+t))}),k={createElement(e,t,...n){return e(Object.assign({},t,{children:n}))}},A=class{options;constructor(e){this.options={...e}}update(e){let t={...this.options};Object.assign(this.options,e),this.optionsUpdated(t)}optionsUpdated(e){}clearCache(){}},j=(e,t)=>{let n=e.getContext(`2d`,t);if(!n)throw Error(`2D canvas context is not available`);return n},te=class extends A{ctx;offCanvas=document.createElement(`canvas`);offCtx;rotation=Math.PI/180*270;speed=6;count=75;constructor(e){super(e),this.ctx=this.options.ctx,this.offCanvas.width=250,this.offCanvas.height=250,this.offCtx=j(this.offCanvas),this.offCtx.lineWidth=.5,this.setColor(`rgba(255, 255, 255, 0.75)`)}setColor(e){this.offCtx.strokeStyle=e}updateLoader(){this.rotation+=this.speed/100}renderLoader(){this.offCtx.save(),this.offCtx.globalCompositeOperation=`source-over`,this.offCtx.translate(125,125),this.offCtx.rotate(this.rotation);let e=this.count;for(;e--;)this.offCtx.beginPath(),this.offCtx.arc(0,0,e+Math.random()*35,Math.random(),Math.PI/3+Math.random()/12,!1),this.offCtx.stroke();this.offCtx.restore()}render(){this.offCtx.globalCompositeOperation=`destination-out`,this.offCtx.fillStyle=`rgba(255, 255, 255, 0.03)`,this.offCtx.fillRect(0,0,250,250),this.updateLoader(),this.renderLoader();let e=Math.round((this.ctx.canvas.width-this.offCanvas.width)/2),t=Math.round((this.ctx.canvas.height-this.offCanvas.height)/2);return this.ctx.clearRect(e,t,250,250),this.ctx.drawImage(this.offCanvas,e,t),this.offCanvas}},ne=class{name;canvas=document.createElement(`canvas`);ctx;constructor(e,{alpha:t=!0,desynchronized:n=!1}={}){this.name=e,this.canvas.className=`drawingLayer ${e}`,this.ctx=j(this.canvas,{alpha:t,desynchronized:n})}width=0;height=0;pixelRatio=1;resize(e,t,n=1){return e===this.width&&t===this.height&&n===this.pixelRatio?!1:(this.width=e,this.height=t,this.pixelRatio=n,this.canvas.width=Math.round(e*n),this.canvas.height=Math.round(t*n),this.ctx.setTransform(n,0,0,n,0,0),!0)}clear(){this.ctx.clearRect(0,0,this.width,this.height)}},re=class{renderers=new Map;warned=new Set;register(e,t){this.renderers.set(e,t),this.warned.delete(e)}unregister(e){this.renderers.delete(e)}get(e){return this.renderers.get(e)}resolve(e){if(typeof e!=`string`)return e;let t=this.renderers.get(e);return!t&&!this.warned.has(e)&&(this.warned.add(e),console.warn(`canvas-grid: no renderer registered as "${e}"`)),t}clearCaches(){this.renderers.forEach(e=>e.clearCache?.())}},M=O((e,{x:t=0,y:n=0,width:r,height:i,color:a,alpha:o=1},s,c)=>{let l=Math.trunc(r),u=Math.trunc(i);!a||l<=0||u<=0||o<=0||(e.fillStyle=a,o>=1?e.fillRect(s+t,c+n,l,u):(e.globalAlpha=o,e.fillRect(s+t,c+n,l,u),e.globalAlpha=1))}),ie=120,ae=.5,oe=typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(prefers-reduced-motion: reduce)`):void 0,se=e=>e*e*(3-2*e),ce=class e extends A{static defaultOptions={layer:`background`,enableFlashing:!0,background:`#333`,flashInDuration:200,flashOutDuration:400,flashColor:`rgb(214, 144, 13)`,zebraColor:`rgba(255, 255, 255, 0.025)`,hoverColor:`rgba(255, 255, 255, 0.06)`,borderRightWidth:0,borderRightColor:`#fff`,borderBottomWidth:0,borderBottomColor:`#fff`};constructor(t={}){super({...e.defaultOptions,...t})}hoveredRowIndex=void 0;hoverFades=new Map;get hoverDuration(){return oe?.matches?0:ie}hover(e,t=Date.now()){e!==this.hoveredRowIndex&&(this.hoveredRowIndex!==void 0&&this.startFade(this.hoveredRowIndex,0,t),e!==void 0&&this.startFade(e,1,t),this.hoveredRowIndex=e)}startFade(e,t,n){this.hoverFades.set(e,{from:this.getHoverFraction(e,n),to:t,start:n})}getHoverFraction(e,t){let n=this.hoverFades.get(e);if(!n)return 0;let r=this.hoverDuration,i=r<=0?1:Math.min(1,Math.max(0,(t-n.start)/r));i>=1&&n.to===0&&this.hoverFades.delete(e);let a=1-(1-i)*(1-i);return n.from+(n.to-n.from)*a}get layer(){return this.options.layer}isAnimating({age:e,row:t,now:n}){let r=t===void 0?void 0:this.hoverFades.get(t.index);return r&&n-r.start<this.hoverDuration?!0:this.options.enableFlashing&&e<=this.options.flashInDuration+this.options.flashOutDuration}getFlashAlpha(e){if(!this.options.enableFlashing)return 0;let{flashInDuration:t,flashOutDuration:n}=this.options;if(e>t+n)return 0;if(oe?.matches)return ae;let r=Math.max(0,(t+n-e)/n),i=e<t?se(e/t):r*r;return Math.round(i*1e3)/1e3}draw({ctx:e,x:t,y:n,width:r,height:i,age:a,row:o,now:s}){let{background:c,flashColor:l,zebraColor:u,hoverColor:d,borderRightWidth:f,borderRightColor:p,borderBottomWidth:m,borderBottomColor:h}=this.options,g=this.getFlashAlpha(a),_=o===void 0?0:this.getHoverFraction(o.index,s);k.createElement(ee,null,k.createElement(M,{width:r,height:i,color:c}),o!==void 0&&o.index%2==1&&k.createElement(M,{width:r,height:i,color:u}),_>0&&k.createElement(M,{width:r,height:i,color:d,alpha:_}),g>0&&k.createElement(M,{width:r,height:i,color:l,alpha:g}),f>0&&k.createElement(M,{x:r-f,width:f,height:i,color:p}),m>0&&k.createElement(M,{y:i-m,width:r,height:m,color:h})).draw(e,t,n)}},le=/[\p{M}ᄀ-ᇿꥠ-ힰ-\u{10000}-\u{10ffff}]/u,ue=768,de=new Intl.Segmenter,fe=e=>Array.from(de.segment(e),({segment:e})=>e),pe=e=>le.test(e)?fe(e):e,me=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>=ue)return!0;return!1},N=(e,t,n,r)=>{let i=0,a=0;for(;a<e.length;){let n=r(e[a]);if(i+n>t)break;i+=n,a++}if(a===e.length)return a;let o=r(n);for(;a>0&&i+o>t;)a--,i-=r(e[a]);return i+o>t?-1:a},he=(e,t)=>{let n=0;for(let r=0;r<e.length;r++)n+=t(e[r]);return n},ge=4096,_e=(e,t,n,r)=>{if(!e)return r;let i=e.get(t);return i?(i.available=n,i.text=r,r):(e.size>=ge&&e.clear(),e.set(t,{available:n,text:r}),r)},ve=(e,t,n,r,i)=>{let{measure:a,cache:o}=i,s=o?.get(e);if(s?.available===t)return s.text;let c=pe(e);if(N(c,t,n,r)===c.length)return e;let l=a(e);if(l<=t)return _e(o,e,t,e);let u=l/he(c,r),d=N(c,t,n,e=>r(e)*u),f=e=>typeof c==`string`?c.slice(0,e):c.slice(0,e).join(``);for(;d>0&&a(f(d)+n)>t;)d--;return _e(o,e,t,d<0||d===0&&a(n)>t?``:f(d)+n)},ye=(e,t,n,r,i)=>{let a=r(n),o=n.charAt(0),s=0,c=0;for(;c<e.length;){let n=s+r(e.charAt(c))+(c===0?0:i(e.charAt(c-1),e.charAt(c)));if(n>t)break;s=n,c++}if(c===e.length)return e;for(;c>0&&s+i(e.charAt(c-1),o)+a>t;)c--,s-=r(e.charAt(c))+(c===0?0:i(e.charAt(c-1),e.charAt(c)));return c>0||a<=t?e.slice(0,c)+n:``},be=(e,t,n,r,i={measure:e=>he(pe(e),r),sumIsExact:!0})=>{let a=N(e,t,n,r);return a===e.length?e:i.sumIsExact&&!me(e)?a<0?``:e.slice(0,a)+n:i.kerning&&!me(e)?ye(e,t,n,r,i.kerning):ve(e,t,n,r,i)},P={textRendering:`auto`,fontKerning:`auto`,letterSpacing:`0px`,direction:`ltr`,textOverflow:`clip`},xe=768,Se=/^[^\p{L}]*(?=[-ࣿיִ-﷿ﹰ-ﻼ])\p{L}/u,Ce=class e extends A{static defaultOptions={...P,ellipsis:`…`,cellPadding:{top:3,right:3,bottom:3,left:3},font:`12px sans-serif`,color:`#fff`,isEllipsisRight:!0};fonts=new Map;measureContext=j(document.createElement(`canvas`));measuredState=``;styled=!1;constructor(t={}){super({...e.defaultOptions,...t}),this.styled=this.differsFromDefault()}differsFromDefault(){return Object.keys(P).some(e=>e!==`textOverflow`&&this.options[e]!==P[e])}set font(e){this.options.font!==e&&(this.options.font=e,this.clearCache())}get font(){return this.options.font}set color(e){this.options.color=e}get color(){return this.options.color}setStyle(e){Object.keys(e).some(t=>e[t]!==this.options[t])&&(this.update(e),this.styled=this.styled||this.differsFromDefault(),this.clearCache())}pixelRatio=1;clearCache(){this.fonts.clear(),this.lastMeasures=void 0,this.measuredState=``}measuresOf(e){let t=this.fonts.get(e);if(t)return t;let n=new Map,r={font:e,widths:new Map,pairs:new Map,fitted:n,probed:!1,widthOf:e=>this.measureCharacter(r,e),exactFit:{measure:e=>this.measureString(r,e),cache:n,sumIsExact:!0,kerning:(e,t)=>this.measureKerning(r,e,t)}};return this.fonts.set(e,r),r}prepareMeasuring(e){let{textRendering:t,fontKerning:n,letterSpacing:r}=this.options,i=`${e.font}|${t}|${n}|${r}`;this.measuredState!==i&&(this.measureContext.font=e.font,this.measureContext.textRendering=t,this.measureContext.fontKerning=n,this.measureContext.letterSpacing=r,this.measuredState=i),e.probed||(e.probed=!0,e.exactFit.sumIsExact=Math.abs(this.measureContext.measureText(`i`).width-this.measureContext.measureText(`W`).width)<.01)}measureCharacter(e,t){let n=e.widths.get(t);if(n!==void 0)return n;this.prepareMeasuring(e);let r=this.measureContext.measureText(t).width;return e.widths.set(t,r),r}measureKerning(e,t,n){let r=t.charCodeAt(0)*65536+n.charCodeAt(0),i=e.pairs.get(r);if(i!==void 0)return i;let a=this.measureString(e,t+n)-this.measureCharacter(e,t)-this.measureCharacter(e,n);return e.pairs.set(r,a),a}measureString(e,t){return this.prepareMeasuring(e),this.measureContext.measureText(t).width}getTextWidth(e){let{widthOf:t}=this.measuresOf(this.options.font),n=0;for(let r=0;r<e.length;r++)n+=t(e.charAt(r));return n}fitsBySum(e,t,n){let r=0;for(let i=0;i<e.length;i++)if(e.charCodeAt(i)>=xe||(r+=n(e.charAt(i)),r>t))return!1;return!0}lastMeasures=void 0;isRightToLeft(e){let{direction:t}=this.options;return t===`auto`?Se.test(e):t===`rtl`}paint(e,{value:t=``,x:n=0,y:r=0,width:i=0,height:a=0,font:o=this.options.font},s,c){let{cellPadding:l}=this.options,u=i-l.left-l.right,d=this.lastMeasures?.font===o?this.lastMeasures:this.measuresOf(o);this.lastMeasures=d;let f=this.options.textOverflow===`clip`&&!this.fitsBySum(t,u,d.widthOf),p=this.options.textOverflow===`clip`?t:be(t,u,this.options.ellipsis,d.widthOf,d.exactFit);if(p===``||a-l.top-l.bottom<=0)return;f&&(e.save(),e.beginPath(),e.rect(s+n+l.left,c+r,Math.max(0,u),a),e.clip());let m=this.styled&&this.isRightToLeft(p);this.styled&&(e.textRendering=this.options.textRendering,e.fontKerning=this.options.fontKerning,e.letterSpacing=this.options.letterSpacing,e.direction=m?`rtl`:`ltr`),e.font=o,e.fillStyle=this.options.color,e.textAlign=m?`right`:`left`,e.textBaseline=`middle`;let{pixelRatio:h}=this,g=m?s+n+i-l.right:s+n+l.left;e.fillText(p,Math.round(g*h)/h,Math.round((c+r+l.top+(a-l.top-l.bottom)/2)*h)/h),f&&e.restore()}element=O((e,t,n,r)=>this.paint(e,t,n,r))},we=8,F=5,Te=.75,Ee=O((e,{width:t,height:n,direction:r,color:i},a,o)=>{let s=Math.round(a+t-13),c=Math.round(o+(n-F)/2),l=r===`asc`;e.beginPath(),e.moveTo(s,l?c+F:c),e.lineTo(s+we,l?c+F:c),e.lineTo(s+we/2,l?c:c+F),e.closePath(),e.fillStyle=i,e.globalAlpha=Te,e.fill(),e.globalAlpha=1}),De=class e extends A{static defaultOptions={layer:`header`,background:`#333`,selectedBackground:`#2f3d4a`,fullySelectedBackground:`#3a5a7c`,font:`13px sans-serif`,color:`#fff`,borderRightWidth:1,borderRightColor:`#fff`,borderBottomWidth:1,borderBottomColor:`#fff`};textRenderer;sortDirections=new Map;setSortModel(e){this.sortDirections.clear(),e.forEach(({columnId:e,direction:t=`asc`})=>this.sortDirections.set(String(e),t))}constructor(t={}){super({...e.defaultOptions,...t}),this.textRenderer=new Ce({font:this.options.font,color:this.options.color})}get layer(){return this.options.layer}set font(e){this.options.font=e,this.textRenderer.font=e}get font(){return this.textRenderer.font}set pixelRatio(e){this.textRenderer.pixelRatio=e}get pixelRatio(){return this.textRenderer.pixelRatio}setTextStyle(e){this.textRenderer.setStyle(e)}optionsUpdated(){this.textRenderer.color=this.options.color}clearCache(){this.textRenderer.clearCache()}backgroundFor(e){return e===`full`?this.options.fullySelectedBackground:e===`partial`?this.options.selectedBackground:this.options.background}draw({ctx:e,x:t,y:n,width:r,height:i,column:a,formatted:o,selected:s}){if(r===0||i===0)return;let c=a===void 0?void 0:this.sortDirections.get(String(a.id)),{borderRightWidth:l,borderRightColor:u,borderBottomWidth:d,borderBottomColor:f}=this.options,p=this.backgroundFor(s);k.createElement(ee,null,k.createElement(M,{width:r,height:i,color:p}),l>0&&k.createElement(M,{x:r-l,width:l,height:i,color:u}),d>0&&k.createElement(M,{y:i-d,width:r,height:d,color:f}),k.createElement(this.textRenderer.element,{value:o,font:a?.headerFont,width:c?r-18:r,height:i}),c&&k.createElement(Ee,{width:r,height:i,direction:c,color:this.options.color})).draw(e,t,n)}},Oe=class e extends A{static defaultOptions={layer:`content`,font:`12px sans-serif`,color:`#fff`};renderer;constructor(t={}){super({...e.defaultOptions,...t}),this.renderer=new Ce({font:this.options.font,color:this.options.color})}get layer(){return this.options.layer}set font(e){this.options.font=e,this.renderer.font=e}get font(){return this.options.font}set color(e){this.options.color=e,this.renderer.color=e}get color(){return this.options.color}set pixelRatio(e){this.renderer.pixelRatio=e}get pixelRatio(){return this.renderer.pixelRatio}setTextStyle(e){this.renderer.setStyle(e)}clearCache(){this.renderer.clearCache()}draw({ctx:e,x:t,y:n,width:r,height:i,column:a,formatted:o,valueChanged:s,forced:c}){(s||c)&&(e.clearRect(t,n,r,i),k.createElement(this.renderer.element,{value:o,font:a?.font,width:r,height:i}).draw(e,t,n))}},I=(e,t,n)=>e===`inherit`?!t.fontSize||!t.fontFamily?n:[t.fontStyle,t.fontWeight,t.fontSize,t.fontFamily].filter(Boolean).join(` `):e,L={background:`--cg-background`,text:`--cg-text-color`,font:`--cg-font`,rowHeight:`--cg-row-height`,border:`--cg-border-color`,headerBackground:`--cg-header-background`,headerText:`--cg-header-text-color`,headerFont:`--cg-header-font`,headerHeight:`--cg-header-height`,headerBorder:`--cg-header-border-color`,headerBottomBorder:`--cg-header-bottom-border-color`,headerSelected:`--cg-header-selected-background`,headerFullySelected:`--cg-header-fully-selected-background`,zebra:`--cg-zebra-color`,hover:`--cg-hover-color`,flash:`--cg-flash-color`,selection:`--cg-selection-color`,selectionBorder:`--cg-selection-border-color`},ke={font:`12px sans-serif`,rowHeight:20,headerFont:`13px sans-serif`,headerHeight:30,flash:`rgb(214, 144, 13)`},Ae={dark:{...ke,background:`#333`,text:`#efefef`,border:`#3b3b3b`,headerBackground:`#262626`,headerText:`#efefef`,headerBorder:`#333`,headerBottomBorder:`#4a4a4a`,headerSelected:`#2f3d4a`,headerFullySelected:`#3a5a7c`,zebra:`rgba(255, 255, 255, 0.025)`,hover:`rgba(255, 255, 255, 0.06)`,selection:`rgba(74, 144, 217, 0.25)`,selectionBorder:`#4a90d9`},light:{...ke,background:`#fff`,text:`#1f2328`,border:`#e4e7eb`,headerBackground:`#f3f4f6`,headerText:`#1f2328`,headerBorder:`#e4e7eb`,headerBottomBorder:`#c9ced6`,headerSelected:`#dbe8f6`,headerFullySelected:`#b9d3ee`,zebra:`rgba(0, 0, 0, 0.025)`,hover:`rgba(0, 0, 0, 0.05)`,selection:`rgba(74, 144, 217, 0.2)`,selectionBorder:`#2f6fb5`}},je=[`rowHeight`,`headerHeight`],Me=[`font`,`headerFont`],Ne=e=>{let t=/^\d+(\.\d+)?(px)?$/.test(e)?parseFloat(e):NaN;return t>0?t:void 0},Pe=(e,{read:t,isColor:n,isFont:r})=>{let i=Ae[e],a=(e,t)=>{if(t)return je.includes(e)?Ne(t):Me.includes(e)?r(t)?t:void 0:n(t)?t:void 0};return Object.fromEntries(Object.keys(L).map(e=>[e,a(e,t(L[e]).trim())??i[e]]))},Fe=(e,t)=>Object.keys(L).every(n=>e[n]===t[n]),Ie=e=>t=>{e.fillStyle=`#000000`,e.fillStyle=t;let n=e.fillStyle;return e.fillStyle=`#ffffff`,e.fillStyle=t,n===e.fillStyle},Le=e=>typeof CSS>`u`||CSS.supports(`font`,e),Re=(e,t=20,n=1/0)=>Math.round(Math.max(t,Math.min(n,e))),ze=e=>{let t=Array(e.length+1);return t[0]=0,e.forEach((e,n)=>{t[n+1]=t[n]+Math.round(e)}),t},R=(e,t)=>{let n=e.length-2;if(n<0)return-1;let r=0,i=n;for(;r<i;){let n=r+i+1>>1;e[n]<=t?r=n:i=n-1}return r},Be=(e,t,n)=>{let r=R(e,t+n);if(r<0)return-1;let i=r>0&&Math.abs(e[r]-t)<=n?r-1:-1,a=Math.abs(e[r+1]-t)<=n?r:-1;return i>=0?i:a},z=(e,t)=>e<=t?[e,t]:[t,e],B=(e,t)=>({...e&&{rows:e},...t&&{columns:t}}),Ve=(e,t)=>B(z(e.row,t.row),z(e.column,t.column)),V=(e,t,n)=>e===`range`?Ve(t,n):e===`row`?B(z(t.row,n.row),void 0):e===`column`?B(void 0,z(t.column,n.column)):Ve(n,n),He=e=>z(Math.max(0,Math.floor(e[0])),Math.max(0,Math.floor(e[1]))),H=e=>B(e.rows&&He(e.rows),e.columns&&He(e.columns)),U=e=>e&&[e[0],e[1]],Ue=e=>B(U(e.rows),U(e.columns)),W=(e,t,n)=>{let r=Math.max(0,e.rows?.[0]??0),i=Math.min(t-1,e.rows?.[1]??t-1),a=Math.max(0,e.columns?.[0]??0),o=Math.min(n-1,e.columns?.[1]??n-1);return r>i||a>o?void 0:{top:r,bottom:i,left:a,right:o}},G=(e,t)=>t===void 0||e>=t[0]&&e<=t[1],We=(e,t)=>e===void 0||e[0]<=0&&e[1]>=t-1,Ge=(e,t,n)=>G(t,e.rows)&&G(n,e.columns),Ke=(e,t,n)=>{let r=`none`;for(let i of e)if(G(t,i.columns)){if(We(i.rows,n))return`full`;r=`partial`}return r},qe=(e,t,n)=>{let r=`none`;for(let i of e)if(G(t,i.rows)){if(We(i.columns,n))return`full`;r=`partial`}return r},Je=e=>e.rows===void 0&&e.columns===void 0?`all`:e.rows===void 0?`column`:e.columns===void 0?`row`:`block`,K=(e,t,n)=>e===`column`?B(void 0,z(t,n)):B(z(t,n),void 0),q=(e,t,n)=>e===`column`?{row:n,column:t}:{row:t,column:n},J=(e,t)=>e===`column`?t.column:t.row,Y=(e,t)=>e===`column`?t.row:t.column,Ye=(e,t)=>e?.[0]===t?.[0]&&e?.[1]===t?.[1],Xe=(e,t)=>Ye(e.rows,t.rows)&&Ye(e.columns,t.columns),Ze=(e,t)=>e?.row===t?.row&&e?.column===t?.column,Qe=(e,t)=>e&&[e[0],Math.min(e[1],t-1)],$e=(e,t,n)=>e&&{row:Math.min(e.row,t-1),column:Math.min(e.column,n-1)},et=class{ranges=[];active=void 0;focus=void 0;assign(e,t,n){let r=e.length!==this.ranges.length||e.some((e,t)=>!Xe(e,this.ranges[t]))||!Ze(t,this.active);return this.ranges=e,this.active=t&&{row:t.row,column:t.column},this.focus=n&&{row:n.row,column:n.column},r}set(e,t,n=t){return this.assign([H(e)],t,n)}add(e,t){return this.assign([...this.ranges,H(e)],t,t)}extend(e,t){return this.ranges.length===0||this.active===void 0?this.set(e,t):this.assign([...this.ranges.slice(0,-1),H(e)],this.active,t)}clear(){return this.assign([],void 0,void 0)}activate(e){return this.assign(this.ranges,e,e)}replace(e,t){let n=e.map(H),r=n[n.length-1];if(r===void 0)return this.clear();let i=t??{row:r.rows?.[0]??0,column:r.columns?.[0]??0};return this.assign(n,i,i)}clamp(e,t){if(e===0||t===0)return this.clear();let n=this.ranges.filter(n=>W(n,e,t)!==void 0).map(n=>B(Qe(n.rows,e),Qe(n.columns,t)));return n.length===0?this.clear():this.assign(n,$e(this.active,e,t),$e(this.focus,e,t))}snapshot(){return{ranges:this.ranges.map(Ue),active:this.active&&{...this.active}}}},tt=(e,t,n)=>e<t?-Math.min(30,Math.max(2,(t-e)/4)):e>n?Math.min(30,Math.max(2,(e-n)/4)):0,nt=(e,t)=>Math.max(0,Math.min(t,e)),rt=(e,t,n,{rowCount:r,columnCount:i,pageRows:a})=>{let o=r-1,s=i-1,c=(e,t)=>({row:nt(e,o),column:nt(t,s)});switch(t){case`ArrowUp`:return c(n?0:e.row-1,e.column);case`ArrowDown`:return c(n?o:e.row+1,e.column);case`ArrowLeft`:return c(e.row,n?0:e.column-1);case`ArrowRight`:return c(e.row,n?s:e.column+1);case`Home`:return c(n?0:e.row,0);case`End`:return c(n?o:e.row,s);case`PageUp`:return c(e.row-a,e.column);case`PageDown`:return c(e.row+a,e.column);default:return}},it=(e,t,n,r)=>{let i=r?-1:1,[a,o,s,c]=n===`row`?[e.top,e.bottom,e.left,e.right]:[e.left,e.right,e.top,e.bottom],l=J(n,t)+i;if(l>=a&&l<=o)return q(n,l,Y(n,t));let u=c-s+1,d=s+((Y(n,t)+i-s)%u+u)%u;return q(n,i>0?a:o,d)},at=(e,t,n,r)=>Math.min(e,Math.max(n,t-r)),ot=(e,t,n,{rowCount:r,columnCount:i})=>{let a=n?-1:1,o=(e,t)=>e>=0&&e<r&&t>=0&&t<i;if(t===`row`)return o(e.row+a,e.column)?{row:e.row+a,column:e.column}:e;if(o(e.row,e.column+a))return{row:e.row,column:e.column+a};let s=e.row+a;return o(s,0)?{row:s,column:n?i-1:0}:e},st=1e6,ct=e=>/[\t\r\n"]/.test(e)?`"${e.replaceAll(`"`,`""`)}"`:e,lt=(e,t,n=st)=>{let r=e.right-e.left+1,i=e.bottom-e.top+1,a=Math.min(i,Math.max(1,Math.floor(n/r)));return{text:Array.from({length:a},(n,i)=>Array.from({length:r},(n,r)=>ct(t(e.top+i,e.left+r))).join(` `)).join(`\r
|
|
2
|
+
`),truncated:a<i}},ut=class{element;host;onPick;constructor(e,t){this.host=e,this.onPick=t}get isOpen(){return this.element?.matches(`:popover-open`)??!1}open(e,t,n){this.close();let r=this.element??this.create();r.replaceChildren(...n.map(e=>this.createItem(e))),r.style.left=`${e}px`,r.style.top=`${t}px`,r.showPopover();let{width:i,height:a}=r.getBoundingClientRect();r.style.left=`${Math.max(0,Math.min(e,document.documentElement.clientWidth-i))}px`,r.style.top=`${Math.max(0,Math.min(t,document.documentElement.clientHeight-a))}px`,this.items().find(e=>!e.disabled)?.focus({preventScroll:!0})}close(){this.isOpen&&this.element?.hidePopover()}items(){return Array.from(this.element?.querySelectorAll(`[role="menuitem"]`)??[])}create(){let e=document.createElement(`div`);return e.className=`contextMenu`,e.role=`menu`,e.popover=`auto`,e.addEventListener(`keydown`,this.onKeyDown),e.addEventListener(`toggle`,t=>{t.newState===`closed`&&e.contains(document.activeElement)&&this.host.focus({preventScroll:!0})}),this.host.append(e),this.element=e,e}createItem({id:e,label:t,disabled:n}){let r=document.createElement(`button`);return r.type=`button`,r.role=`menuitem`,r.textContent=t,r.disabled=n,r.addEventListener(`click`,()=>{this.close(),this.onPick(e)}),r}onKeyDown=e=>{e.stopPropagation();let t=this.items().filter(e=>!e.disabled),n=t.indexOf(document.activeElement),r=e=>t[(e+t.length)%t.length]?.focus();if(e.key===`ArrowDown`)r(n+1);else if(e.key===`ArrowUp`)r(n<0?-1:n-1);else if(e.key===`Home`)r(0);else if(e.key===`End`)r(-1);else if(e.key===`Tab`)this.close();else return;e.preventDefault()}},X=e=>e==null?``:String(e),Z=e=>{let t=document.createElement(`input`);return t.type=e,t},dt=(e,t)=>{e.focus({preventScroll:!0}),t?e.setSelectionRange(e.value.length,e.value.length):e.select()},ft=({value:e,initialText:t})=>{let n=Z(`text`);return n.value=t??X(e),{element:n,getValue:()=>n.value,focus:()=>dt(n,t!==void 0)}},pt=({value:e,initialText:t})=>{let n=Z(`text`);return n.inputMode=`decimal`,n.autocomplete=`off`,n.classList.add(`number`),n.value=t??X(e),{element:n,getValue:()=>n.value,focus:()=>dt(n,t!==void 0)}},mt=({value:e})=>{let t=Z(`checkbox`);return t.checked=e===!0,{element:t,getValue:()=>t.checked,focus:()=>t.focus({preventScroll:!0})}},ht=e=>typeof e==`object`?e:{value:e},gt=240,_t=8,vt=(e,{value:t,commit:n})=>{let r=e.map(ht),i=r.some(e=>e.value===t)?r:[{value:t,label:X(t)},...r],a=e=>e.label??X(e.value),o=Math.max(0,i.findIndex(e=>e.value===t)),s=!1,c=document.createElement(`div`);c.className=`cellSelect`,c.tabIndex=0,c.role=`combobox`,c.ariaHasPopup=`listbox`;let l=document.createElement(`span`);l.className=`cellSelectLabel`;let u=document.createElement(`div`);u.className=`cellSelectList`,u.role=`listbox`,u.popover=`manual`,c.append(l,u);let d=i.map((e,t)=>{let r=document.createElement(`div`);return r.role=`option`,r.textContent=a(e),r.addEventListener(`pointerdown`,e=>e.preventDefault()),r.addEventListener(`click`,()=>{f(t),n()}),r});u.append(...d);function f(e){o=e,l.textContent=a(i[e]),d.forEach((t,n)=>{t.classList.toggle(`active`,n===e),t.ariaSelected=String(n===e)}),d[e]?.scrollIntoView({block:`nearest`})}let p=e=>{let t=s&&e;if(c.ariaExpanded=String(s),t!==u.matches(`:popover-open`)&&(t?u.showPopover():u.hidePopover()),!t)return;let n=c.getBoundingClientRect(),r=Math.min(u.scrollHeight,gt),i=window.innerHeight-n.bottom-_t,a=n.top-_t,l=r>i&&a>i;u.style.maxHeight=`${Math.min(gt,l?a:i)}px`,u.style.minWidth=`${n.width}px`,u.style.left=`${n.left}px`,u.style.top=`${l?n.top-Math.min(r,a):n.bottom}px`,d[o]?.scrollIntoView({block:`nearest`})},m=e=>{let t=e.toLowerCase(),n=[...i.keys()].map((e,t)=>(o+1+t)%i.length).find(e=>a(i[e]).toLowerCase().startsWith(t));n!==void 0&&f(n)};return c.addEventListener(`pointerdown`,e=>{e.target instanceof Node&&u.contains(e.target)||(e.preventDefault(),c.focus({preventScroll:!0}),s=!s,p(!0))}),c.addEventListener(`keydown`,e=>{let t={ArrowDown:1,ArrowUp:-1}[e.key],n=e.key.length===1&&!e.ctrlKey&&!e.metaKey&&!e.altKey;(t!==void 0||n)&&(e.preventDefault(),s=!0,t===void 0?m(e.key):f(Math.max(0,Math.min(i.length-1,o+t))),p(!0))}),f(o),{element:c,getValue:()=>i[o]?.value,focus(){c.focus({preventScroll:!0}),s=!0,p(!0)},place:p,destroy(){s=!1,p(!1)}}},yt=(e,t)=>e===`checkbox`?mt(t):typeof e==`object`?vt(e.options,t):e===`number`?pt(t):ft(t),bt=(e,t)=>typeof e==`function`?e(t):yt(e??`text`,t),xt=e=>e===void 0||typeof e==`function`||e===`text`||e===`number`,St=`Invalid value`,Ct=e=>{if(e.trim()===``)return;let t=Number(e);if(Number.isNaN(t))throw Error(`Not a number`);return t},wt=e=>e===void 0?`text`:typeof e==`function`?`custom`:e,Tt=(e,t,n,r)=>{let i=wt(t),a=i===`text`||i===`number`,o=n.parse??(i===`number`?Ct:void 0),s={...r,newValue:e};try{let t=a&&typeof e==`string`&&o?o(e,s):e,r=n.validate?.(t,{...s,newValue:t})??!0;return r===!0?{ok:!0,value:t}:{ok:!1,message:typeof r==`string`?r:St}}catch(e){return{ok:!1,message:e instanceof Error&&e.message?e.message:St}}},Q={scrollArea:`scrollArea`,resizeGuide:`resizeGuide`,horizontalGuide:`horizontal`},Et={mouse:4,touch:12},Dt=50,Ot=500,kt=8,$={background:`background`,content:`content`,selection:`selection`,header:`header`,backgroundRenderer:`background`,valueRenderer:`value`,headerRenderer:`header`},At=[$.background,$.content,$.selection,$.header],jt=`canvas-grid-styles`,Mt=()=>{if(document.getElementById(jt))return;let e=document.createElement(`style`);e.id=jt,e.textContent=E,document.head.appendChild(e)},Nt=e=>{let t=e.getRootNode();return e.parentElement??(t instanceof ShadowRoot?t.host:null)},Pt=e=>{let t=[];for(let n=e;n;n=Nt(n))t.push(n);return t},Ft=2,It=`12px sans-serif`,Lt=`13px sans-serif`,Rt=class e extends HTMLElement{fps=60;theme=Ae.dark;_font=void 0;_headerFont=void 0;_headerHeight=void 0;_cellHeight=void 0;cellPadding={top:3,right:3,bottom:3,left:3};showRowNumbers=!0;showHeaders=!0;rowNumbersWidth=30;ellipsis=`…`;_backgroundColor=void 0;_headerBackgroundColor=void 0;_textColor=void 0;selectionColor=void 0;selectionBorderColor=void 0;get backgroundColor(){return this._backgroundColor??this.theme.background}set backgroundColor(e){this._backgroundColor=e,this.applyTheme()}get headerBackgroundColor(){return this._headerBackgroundColor??this.theme.headerBackground}set headerBackgroundColor(e){this._headerBackgroundColor=e,this.applyTheme()}get textColor(){return this._textColor??this.theme.text}set textColor(e){this._textColor=e,this.applyTheme()}get headerHeight(){return this._headerHeight??this.theme.headerHeight}set headerHeight(e){this._headerHeight=e}get cellHeight(){return this._cellHeight??this.theme.rowHeight}set cellHeight(e){this._cellHeight=e}dataStore=new w({getRowId:(e,t)=>this.getRowId(e,t),getCellHeight:()=>this.cellHeight,getRowHeight:e=>this.newRowHeight(e)});_dataCollection=this.dataStore.rows;cellEntries=new T(2048);getRowId=v;headers=new p;animationFrame=void 0;scrollYOffset=0;prevScrollYOffset=0;scrollXOffset=0;prevScrollXOffset=0;lastRender=new Date().valueOf();lastDraw=this.lastRender;isScrolling=!1;scrollHelper=document.createElement(`div`);scrollArea=this.createScrollArea();layers=[];layersByName=new Map;warnedLayers=new Set;renderers=new re;cellRenderers=[$.backgroundRenderer,$.valueRenderer];cellBackgroundRenderer=new ce({layer:$.background,background:this.theme.background,enableFlashing:!0,flashInDuration:200,flashOutDuration:400,flashColor:this.theme.flash,zebraColor:this.theme.zebra,hoverColor:this.theme.hover,borderRightWidth:1,borderRightColor:this.theme.border,borderBottomWidth:1,borderBottomColor:this.theme.border});cellValueRenderer=new Oe({layer:$.content,font:this.theme.font,color:this.theme.text});headerCellRenderer=new De({layer:$.header,font:this.theme.headerFont,color:this.theme.headerText,background:this.theme.headerBackground,selectedBackground:this.theme.headerSelected,fullySelectedBackground:this.theme.headerFullySelected,borderRightWidth:1,borderRightColor:this.theme.headerBorder,borderBottomWidth:1,borderBottomColor:this.theme.headerBottomBorder});loadingIndicator;cell;placeholderState={};throttleTransation=(0,d.default)(()=>{let e=this.totalHeight,t=this.dataStore.flush();e!==this.totalHeight&&this.refreshScrollbar(),this.refitSelection(),t&&this.forceDraw(),this.requestRender()},50);agApi;constructor(){super(),this.resize=this.resize.bind(this),this.setValues=this.setValues.bind(this),this.setColumns=this.setColumns.bind(this),this.clearValues=this.clearValues.bind(this),this.updateLastRender=this.updateLastRender.bind(this),this.transaction=this.transaction.bind(this),this.queueUpdate=this.queueUpdate.bind(this),this.addLayer($.background,{alpha:!1}),this.addLayer($.content),this.addLayer($.header),this.registerRenderer($.backgroundRenderer,this.cellBackgroundRenderer),this.registerRenderer($.valueRenderer,this.cellValueRenderer),this.registerRenderer($.headerRenderer,this.headerCellRenderer),this.loadingIndicator=new te({ctx:this.requireLayer($.header).ctx}),this.cell={ctx:this.requireLayer($.content).ctx,x:0,y:0,width:0,height:0,row:void 0,column:void 0,value:void 0,formatted:``,updatedAt:void 0,age:1/0,now:0,dt:0,valueChanged:!1,forced:!1,isScrolling:!1,selected:`none`,state:{}};let e=this;this.agApi={setRowData:this.setValues,updateRowData:this.transaction,setColumnDefs:this.setColumns,get getRowNodeId(){return e.getRowId},set getRowNodeId(t){typeof t==`function`&&(e.getRowId=t)}}}get canvas(){return this.requireLayer($.content).canvas}get flashInDuration(){return this.cellBackgroundRenderer.options.flashInDuration}set flashInDuration(e){this.cellBackgroundRenderer.update({flashInDuration:e})}get flashOutDuration(){return this.cellBackgroundRenderer.options.flashOutDuration}set flashOutDuration(e){this.cellBackgroundRenderer.update({flashOutDuration:e})}getLayer(e){return this.layersByName.get(e)}requireLayer(e){let t=this.getLayer(e);if(!t)throw Error(`canvas-grid: no layer named "${e}"`);return t}addLayer(e,{alpha:t=!0,desynchronized:n=!1,before:r}={}){if(this.getLayer(e))throw Error(`canvas-grid: layer "${e}" already exists`);let i=new ne(e,{alpha:t,desynchronized:n}),a=r===void 0?void 0:this.requireLayer(r);return this.layers.splice(a?this.layers.indexOf(a):this.layers.length,0,i),this.layersByName.set(e,i),this.scrollArea.parentElement===this&&(this.insertBefore(i.canvas,a?.canvas??this.scrollArea),i.resize(this.clientWidth,this.clientHeight,this.pixelRatio),this.forceDraw()),i}removeLayer(e){let t=this.requireLayer(e);this.layers=this.layers.filter(e=>e!==t),this.layersByName.delete(e),t.canvas.remove()}registerRenderer(e,t){this.renderers.register(e,t)}unregisterRenderer(e){this.renderers.unregister(e)}createScrollArea(){let e=document.createElement(`div`);return e.className=Q.scrollArea,e.appendChild(this.scrollHelper),e}set font(e){this._font!==e&&(this._font=e,this.cellValueRenderer.font=I(e,getComputedStyle(this),It))}get font(){return this._font??this.theme.font}set headerFont(e){this._headerFont!==e&&(this._headerFont=e,this.headerCellRenderer.font=I(e,getComputedStyle(this),Lt))}get headerFont(){return this._headerFont??this.theme.headerFont}textStyle={...P};setTextStyle(e){this.textStyle={...this.textStyle,...e},this.cellValueRenderer.setTextStyle(this.textStyle),this.headerCellRenderer.setTextStyle(this.textStyle),this.forceDraw()}set textRendering(e){this.setTextStyle({textRendering:e})}get textRendering(){return this.textStyle.textRendering}set fontKerning(e){this.setTextStyle({fontKerning:e})}get fontKerning(){return this.textStyle.fontKerning}set letterSpacing(e){this.setTextStyle({letterSpacing:e})}get letterSpacing(){return this.textStyle.letterSpacing}set textOverflow(e){this.setTextStyle({textOverflow:e})}get textOverflow(){return this.textStyle.textOverflow}set direction(e){this.setTextStyle({direction:e})}get direction(){return this.textStyle.direction}connectedCallback(){this.layers.forEach(e=>this.appendChild(e.canvas)),this.appendChild(this.scrollArea),this.appendChild(this.resizeGuide),this.updateLastRender(),this.refreshTheme(),this.refreshFonts(),this.watchTheme(),this.headers.length===0&&this.setColumns(Array(50).fill(1).map((e,t)=>t)),document.addEventListener(`visibilitychange`,this.onVisibilityChange),this.observeSize(),this.pixelRatioQuery=window.matchMedia(`(resolution: ${this.pixelRatio}dppx)`),this.pixelRatioQuery.addEventListener(`change`,this.watchPixelRatio,{once:!0}),document.fonts?document.fonts.addEventListener(`loadingdone`,this.onFontsLoaded):this.fontsTimeout=setTimeout(this.onFontsLoaded,2e3);let e=(0,f.default)(()=>{this.isScrolling=!1},200);this.scrollArea.addEventListener(`pointermove`,this.onPointerMove),this.scrollArea.addEventListener(`pointerleave`,this.onPointerLeave),this.scrollArea.addEventListener(`pointerdown`,this.onResizePointerDown),this.scrollArea.addEventListener(`pointermove`,this.onResizePointerMove),this.scrollArea.addEventListener(`pointerup`,this.onResizePointerEnd),this.scrollArea.addEventListener(`pointercancel`,this.onResizePointerEnd),this.scrollArea.addEventListener(`dblclick`,this.onResizeDoubleClick),this.scrollArea.addEventListener(`touchstart`,this.onResizeTouchStart,{passive:!1}),this.scrollArea.addEventListener(`pointerdown`,this.onSelectPointerDown),this.scrollArea.addEventListener(`pointermove`,this.onSelectPointerMove),this.scrollArea.addEventListener(`pointerup`,this.onSelectPointerEnd),this.scrollArea.addEventListener(`pointercancel`,this.onSelectPointerEnd),this.scrollArea.addEventListener(`dblclick`,this.onEditDoubleClick),this.addEventListener(`keydown`,this.onKeyDown),this.addEventListener(`copy`,this.onCopy),this.addEventListener(`contextmenu`,this.onContextMenu),this.scrollArea.addEventListener(`scroll`,()=>{this.contextMenu?.close(),this.isScrolling=!0,this.updateHoveredRow(),e(),this.requestRender()})}hoverDirty=[];setHoveredRow(e){let t=this.cellBackgroundRenderer.hoveredRowIndex;t!==e&&(this.cellBackgroundRenderer.hover(e),this.hoverDirty.push(t,e),this.requestRender())}pointerY=void 0;updateHoveredRow(){if(this.pointerY===void 0)return;let e=this.pointerY-(this.showHeaders?this.headerHeight:0),t=this._dataCollection.indexAt(e+this.scrollArea.scrollTop);this.setHoveredRow(e<0||t>=this._dataCollection.length?void 0:t)}onPointerMove=e=>{this.pointerY=e.clientY-this.getBoundingClientRect().top,this.updateHoveredRow()};onPointerLeave=()=>{this.pointerY=void 0,this.setHoveredRow(void 0)};fontsTimeout=void 0;onVisibilityChange=()=>{document.visibilityState===`hidden`?this.cancelRender():this.resize()};refreshFonts(){this.cellValueRenderer.font=I(this.font,getComputedStyle(this),It),this.headerCellRenderer.font=I(this.headerFont,getComputedStyle(this),Lt),this.renderers.clearCaches(),this.resize()}onFontsLoaded=()=>this.refreshFonts();themeQuery=void 0;themeObserver=void 0;colorCheck=void 0;get themeName(){let e=this.getAttribute(`theme`);return e===`light`||e===`dark`?e:window.matchMedia(`(prefers-color-scheme: light)`).matches?`light`:`dark`}refreshTheme(){let e=getComputedStyle(this);this.colorCheck??=Ie(document.createElement(`canvas`).getContext(`2d`)??{fillStyle:``});let t=Pe(this.themeName,{read:t=>e.getPropertyValue(t),isColor:this.colorCheck,isFont:Le});if(Fe(t,this.theme))return;let n=t.rowHeight!==this.theme.rowHeight||t.headerHeight!==this.theme.headerHeight;this.theme=t,n&&this.syncThemeHeights(),this.applyTheme()}applyTheme(){let{theme:e}=this;this.cellBackgroundRenderer.update({background:this.backgroundColor,borderRightColor:e.border,borderBottomColor:e.border,zebraColor:e.zebra,hoverColor:e.hover,flashColor:e.flash}),this.headerCellRenderer.update({background:this.headerBackgroundColor,color:this._textColor??e.headerText,selectedBackground:e.headerSelected,fullySelectedBackground:e.headerFullySelected,borderRightColor:e.headerBorder,borderBottomColor:e.headerBottomBorder}),this.cellValueRenderer.color=this.textColor,this.loadingIndicator.setColor(this.textColor),this.refreshFonts()}syncThemeHeights(){this._cellHeight===void 0&&this.rowHeightOf===void 0&&this._dataCollection.setHeights(e=>this.heightOfRow(e)),this.refreshRowHeights(),this.refreshScrollbar()}onThemeChange=()=>this.refreshTheme();watchTheme(){this.themeQuery=window.matchMedia(`(prefers-color-scheme: light)`),this.themeQuery.addEventListener(`change`,this.onThemeChange),this.themeObserver=new MutationObserver(this.onThemeChange),Pt(this).forEach(e=>this.themeObserver?.observe(e,{attributes:!0,attributeFilter:[`class`,`style`,`theme`,`data-theme`]}))}unwatchTheme(){this.themeQuery?.removeEventListener(`change`,this.onThemeChange),this.themeObserver?.disconnect()}cancelRender(){this.animationFrame!==void 0&&cancelAnimationFrame(this.animationFrame),this.animationFrame=void 0}requestRender(){this.animationFrame??=requestAnimationFrame(()=>this.render())}updateLastRender(){this.lastRender=new Date().valueOf()}render(){if(this.animationFrame=void 0,this.readScrollOffsets(),this.relayoutPending){this.relayoutPending=!1,this.forceDraw(),this.updateLastRender();return}let e=new Date().valueOf()-this.lastRender;!this.isScrolling&&e<1e3/this.fps-Ft?this.requestRender():(this.draw(),this.updateLastRender())}readScrollOffsets(){this.scrollXOffset=Math.round(this.scrollArea.scrollLeft),this.scrollYOffset=Math.round(this.scrollArea.scrollTop)}hasScrolled(){return this.hasXScrolled()||this.hasYScrolled()}hasYScrolled(){return this.prevScrollYOffset!==this.scrollYOffset}hasXScrolled(){return this.prevScrollXOffset!==this.scrollXOffset}isInViewport(e=0,t=0,n=0,r=0){return!(e>this.viewportWidth||t>this.viewportHeight||e+n<0||t+r<0)}describe(e,t,n,r,i){return Object.assign(this.cell,{x:e,y:t,width:n,height:r,row:void 0,column:void 0,value:void 0,formatted:``,updatedAt:void 0,age:1/0,valueChanged:!0,forced:!0,selected:`none`,state:this.placeholderState},i)}paint(e){let t=this.renderers.resolve(e),n=t&&this.layersByName.get(t.layer);t&&!n&&!this.warnedLayers.has(t.layer)&&(this.warnedLayers.add(t.layer),console.warn(`canvas-grid: renderer draws on missing layer "${t.layer}"`)),t&&n&&(this.cell.ctx=n.ctx,t.draw(this.cell))}paintAll(e){e.forEach(e=>this.paint(e))}isAnimating(e){return e.some(e=>this.renderers.resolve(e)?.isAnimating?.(this.cell)===!0)}draw(e=!1){this.edit&&this.positionEditor();let t=new Date().valueOf(),n=e||this.hasScrolled();this.cell.now=t,this.cell.dt=t-this.lastDraw,this.cell.isScrolling=this.isScrolling,this.lastDraw=t,!e&&this.hasScrolled()&&this.clearCustomLayers();let r=this._dataCollection.length===0;if((e||this.hasXScrolled()||this.headersDirty)&&this.showHeaders&&this.renderHeaders(),e&&this.showRowNumbers&&this._dataCollection.length===0)for(let e=0;e<=200;e++)this.renderRowNumber({index:e},e*this.cellHeight+(this.showHeaders?this.headerHeight:0)-this.scrollYOffset);if(this._dataCollection.length===0){this.loadingIndicator.render();for(let e=0;e<=200;e++)this.headers.forEach(t=>{this.describe(Math.round(this.columnOffsets[t.index]+(this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset),Math.round(e*this.cellHeight+(this.showHeaders?this.headerHeight:0)-this.scrollYOffset),t.width,this.cellHeight,{column:t,valueChanged:!1}),this.paintAll(t.renderers??this.cellRenderers)})}let i=Math.round((this.showHeaders?this.headerHeight:0)-this.scrollYOffset),a=Math.round((this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset),o=this._dataCollection.indexAt(-i),s=this.getVisibleColumns(a);for(let a=o;a<this._dataCollection.length;a++){let o=this._dataCollection.at(a),c=i+this._dataCollection.topOf(a);if(!o||c>=this.viewportHeight)break;let{id:l,slot:u}=o;if((e||this.hasYScrolled()||this.headersDirty)&&this.showRowNumbers&&this.renderRowNumber(o,c),o.height+c>0){let e=this.cellEntries.get(String(l));e||(e={},this.cellEntries.set(String(l),e));let i={id:l,index:o.index};for(let{header:l,id:d,x:f,store:p}of s){let s=p?.get(u);if(s===void 0)continue;let m=e[d]??={value:void 0,formatted:void 0,animating:!1,state:{}},h=m.formatted!==void 0&&m.value===s?m.formatted:l.valueFormatter(s),g=m.formatted!==h,_=p?.getUpdatedAt(u),{cell:v}=this;v.x=f,v.y=c,v.width=Math.round(l.width),v.height=o.height,v.row=i,v.column=l,v.value=s,v.formatted=h,v.updatedAt=_,v.age=_===void 0?1/0:t-_,v.valueChanged=g,v.forced=n,v.selected=`none`,v.state=m.state;let y=l.renderers??this.cellRenderers,b=this.isAnimating(y);(n||g||b||m.animating||this.hoverDirty.includes(a))&&this.paintAll(y),m.animating=b,m.value=s,m.formatted=h,r||=b}}}(n||this.selectionDirty)&&this.renderSelection(),(this.scrollYOffset>0||this.scrollXOffset>0)&&this.renderBrick(),this.hoverDirty=[],this.selectionDirty=!1,this.headersDirty=!1,this.prevScrollYOffset=this.scrollYOffset,this.prevScrollXOffset=this.scrollXOffset,r&&this.requestRender()}getVisibleColumns(e){let t=[],{columnList:n,columnOffsets:r}=this;for(let i=Math.max(0,R(r,-e));i<n.length;i++){let a=e+r[i];if(a>this.viewportWidth)break;let o=n[i];t.push({header:o,id:String(o.id),x:a,store:this.dataStore.columns.get(String(o.id))})}return t}columnList=[];columnOffsets=[0];updateColumnLayout(){this.columnList=[],this.headers.forEach(e=>this.columnList.push(e)),this.columnOffsets=ze(this.columnList.map(e=>e.width))}selectionDirty=!1;headersDirty=!1;columnSelection(e){let{ranges:t}=this.selectionModel;return t.length===0?`none`:Ke(t,e,this._dataCollection.length)}rowSelection(e){let{ranges:t}=this.selectionModel;return t.length===0?`none`:qe(t,e,this.columnList.length)}selectionDrawn=!1;renderSelection(){let{ranges:e,active:t}=this.selectionModel;if(e.length===0&&!this.selectionDrawn)return;let n=this.getLayer($.selection);if(!n)return;let{ctx:r}=n;if(n.clear(),this.selectionDrawn=e.length>0,!this.selectionDrawn)return;let i=this.showRowNumbers?this.rowNumbersWidth:0,a=this.showHeaders?this.headerHeight:0,o=i-this.scrollXOffset,s=a-this.scrollYOffset,{_dataCollection:c,columnOffsets:l}=this,u=e=>{let t=W(e,c.length,this.columnList.length);if(!t)return;let n=o+l[t.left],r=s+c.topOf(t.top);return{x:n,y:r,width:o+l[t.right+1]-n,height:s+c.topOf(t.bottom+1)-r}};r.save(),r.beginPath(),r.rect(i,a,this.viewportWidth-i,this.viewportHeight-a),r.clip(),r.fillStyle=this.selectionColor??this.theme.selection,r.strokeStyle=this.selectionBorderColor??this.theme.selectionBorder,r.lineWidth=1,e.map(u).forEach(e=>{e&&(r.fillRect(e.x,e.y,e.width,e.height),r.strokeRect(e.x+.5,e.y+.5,e.width-1,e.height-1))});let d=t&&u({rows:[t.row,t.row],columns:[t.column,t.column]});d&&(r.clearRect(d.x,d.y,d.width,d.height),r.lineWidth=2,r.strokeRect(d.x+1,d.y+1,d.width-2,d.height-2)),r.restore()}renderRowNumber(e,t){this.isInViewport(0,t,this.rowNumbersWidth,e.height)&&(this.describe(0,Math.ceil(t),this.rowNumbersWidth,e.height??0,{row:{id:e.index,index:e.index},formatted:`${e.index+1}`,selected:this.rowSelection(e.index)}),this.paint($.headerRenderer))}clearCustomLayers(){this.layers.filter(e=>!At.includes(e.name)).forEach(e=>e.clear())}forceDraw(){this.layers.forEach(e=>e.clear()),this.draw(!0)}viewportWidth=0;viewportHeight=0;get pixelRatio(){return window.devicePixelRatio||1}resize(){this.cancelRender();let{pixelRatio:e}=this;this.viewportWidth=this.clientWidth,this.viewportHeight=this.clientHeight,this.layers.forEach(t=>t.resize(this.clientWidth,this.clientHeight,e)),this.cellValueRenderer.pixelRatio!==e&&this.renderers.clearCaches(),this.cellValueRenderer.pixelRatio=e,this.headerCellRenderer.pixelRatio=e,this.forceDraw()}observeSize(){this.resizeObserver??=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this)}watchPixelRatio=()=>{this.pixelRatioQuery?.removeEventListener(`change`,this.watchPixelRatio),this.pixelRatioQuery=window.matchMedia(`(resolution: ${this.pixelRatio}dppx)`),this.pixelRatioQuery.addEventListener(`change`,this.watchPixelRatio,{once:!0}),this.resize()};resizeObserver=void 0;pixelRatioQuery=void 0;getRowData(e){let t=this._dataCollection.get(e);if(!t)return;let n={};return this.dataStore.columns.forEach((e,r)=>{let i=e.get(t.slot);i!==void 0&&(n[r]=i)}),{id:t.id,index:t.index,height:t.height,values:n}}setSortModel(e){this.dataStore.setSortModel(e),this.headerCellRenderer.setSortModel(e),this.forceDraw()}getSortModel(){return this.dataStore.getSortModel()}renderBrick(){this.showHeaders&&this.showRowNumbers&&this.headerBackgroundColor&&(this.describe(0,0,this.rowNumbersWidth,this.headerHeight,{}),this.paint($.headerRenderer))}renderHeaders(){let e=(this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset;this.getVisibleColumns(e).forEach(({header:e,x:t})=>{this.describe(t,0,Math.round(e.width),this.headerHeight,{column:e,formatted:e.displayName??``,selected:this.columnSelection(e.index)}),this.paint(e.headerRenderer)}),this.scrollXOffset+this.rowNumbersWidth>0&&this.renderBrick()}getColumnHeader(e){return this.headers.get(e)}requestRelayout(){this.relayoutPending=!0,this.requestRender()}relayoutPending=!1;emitResized(e,t,n){this.dispatchEvent(new CustomEvent(e,{detail:{columnId:t.id,width:t.width,source:n}}))}applyColumnWidths(e){let t=Array.from(e).map(([e,t])=>({column:this.headers.get(e),width:t})).filter(({column:e,width:t})=>e!==void 0&&Re(t,e.minWidth,e.maxWidth)!==Math.round(e.width)).flatMap(({column:e,width:t})=>e===void 0?[]:[{column:e,width:Re(t,e.minWidth,e.maxWidth)}]).map(({column:e,width:t})=>Object.assign(e,{width:t}));return t.length===0||(this.updateColumnLayout(),this.refreshScrollbar(),this.requestRelayout()),t}setColumnWidth(e,t){this.applyColumnWidths([[e,t]]).forEach(e=>this.emitResized(`columnresized`,e,`api`))}getColumnState(){return this.columnList.map(({id:e,width:t})=>({id:e,width:Math.round(t)}))}setColumnState(e){this.applyColumnWidths(e.map(({id:e,width:t})=>[e,t])).forEach(e=>this.emitResized(`columnresized`,e,`api`))}measureContext=void 0;autoSizeColumns(e){this.measureContext??=document.createElement(`canvas`).getContext(`2d`);let t=this.measureContext;if(!t)return;let{scrollTop:n}=this.scrollArea,r=[];for(let e=this._dataCollection.indexAt(n);e<this._dataCollection.length&&r.length<Ot;e++){let t=this._dataCollection.at(e);if(!t||this._dataCollection.topOf(e)>n+this.viewportHeight)break;r.push(t)}let i=this.cellPadding.left+this.cellPadding.right+1,a=(e,n)=>(t.font=e,Math.max(0,...Array.from(n,e=>t.measureText(e).width))),o=(e??this.columnList.map(({id:e})=>e)).flatMap(e=>this.headers.get(e)??[]).map(e=>{let t=this.dataStore.columns.get(String(e.id)),n=r.flatMap(({slot:e})=>t?.get(e)??[]).map(t=>e.valueFormatter(t)),o=a(e.headerFont??this.headerCellRenderer.font,[e.displayName??``])+i+18,s=a(e.font??this.cellValueRenderer.font,n)+i;return[e.id,Math.ceil(Math.max(o,s))]});this.applyColumnWidths(o).forEach(e=>this.emitResized(`columnresized`,e,`auto`))}static MIN_ROW_HEIGHT=8;rowHeightOverrides=new Map;rowHeightOf=void 0;heightOfRow(t){let n=this.rowHeightOverrides.get(String(t))??this.rowHeightOf?.(t)??this.cellHeight;return Math.max(e.MIN_ROW_HEIGHT,Math.round(n))}newRowHeight=e=>this.rowHeightOverrides.size===0&&this.rowHeightOf===void 0?void 0:this.heightOfRow(e);refreshRowHeights(){this.refreshScrollbar(),this.requestRelayout()}emitRowResized(e,t,n){let r=this._dataCollection.get(t)?.height;r!==void 0&&this.dispatchEvent(new CustomEvent(e,{detail:{rowId:t,height:r,source:n}}))}setRowHeight(e){this.rowHeightOverrides.clear(),typeof e==`function`?this.rowHeightOf=e:(this.rowHeightOf=void 0,this._cellHeight=e),this._dataCollection.setHeights(e=>this.heightOfRow(e)),this.refreshRowHeights()}setRowHeightById(t,n){this.rowHeightOverrides.set(String(t),Math.max(e.MIN_ROW_HEIGHT,Math.round(n))),this._dataCollection.setHeight(t,this.heightOfRow(t))&&(this.refreshRowHeights(),this.emitRowResized(`rowresized`,t,`api`))}resizeDrag=void 0;findResizeTarget(e,t,n){let r=this.getBoundingClientRect(),i=e-r.left,a=t-r.top,o=n===`touch`?Et.touch:Et.mouse;if(i<0||a<0||i>this.scrollArea.clientWidth)return;let s=this.showRowNumbers?this.rowNumbersWidth:0,c=this.showHeaders?this.headerHeight:0;if(this.showHeaders&&a<=c)return this.findColumnBorder(i-s,o);if(this.showRowNumbers&&i<s)return this.findRowBorder(a-c,o)}findColumnBorder(e,t){if(e<0)return;let n=this.columnList[Be(this.columnOffsets,e+this.scrollArea.scrollLeft,t)];return n===void 0||n.resizable===!1?void 0:{axis:`column`,column:n}}findRowBorder(e,t){let n=this._dataCollection.at(this._dataCollection.borderAt(e+this.scrollArea.scrollTop,t));return n===void 0?void 0:{axis:`row`,row:n}}moveResizeGuide(){let{resizeDrag:e,resizeGuide:t}=this;if(t.style.display=e?`block`:`none`,!e)return;let n=e.axis===`row`;t.classList.toggle(Q.horizontalGuide,n);let r=this.showRowNumbers?this.rowNumbersWidth:0,i=this.showHeaders?this.headerHeight:0;t.style.transform=e.axis===`row`?`translateY(${i+this._dataCollection.topOf(e.row.index)+e.row.height-this.scrollArea.scrollTop}px)`:`translateX(${r+(this.columnOffsets[e.column.index+1]??0)-this.scrollArea.scrollLeft}px)`}resizeGuide=Object.assign(document.createElement(`div`),{className:Q.resizeGuide});onResizePointerDown=e=>{let t=e.button===0?this.findResizeTarget(e.clientX,e.clientY,e.pointerType):void 0;t&&(e.preventDefault(),this.scrollArea.setPointerCapture(e.pointerId),this.resizeDrag=t.axis===`row`?{...t,start:e.clientY,startSize:t.row.height,lastEvent:0}:{...t,start:e.clientX,startSize:t.column.width,lastEvent:0},this.moveResizeGuide())};onResizePointerMove=e=>{let{resizeDrag:t}=this;if(t)t.axis===`row`?this.dragRow(t,e.clientY-t.start):this.dragColumn(t,e.clientX-t.start),this.moveResizeGuide();else{let t=this.findResizeTarget(e.clientX,e.clientY,e.pointerType);this.scrollArea.style.cursor=t===void 0?``:`${t.axis===`row`?`row`:`col`}-resize`}};dragColumn(e,t){let{column:n}=e;this.applyColumnWidths([[n.id,e.startSize+t]]),this.dueForLiveEvent(e)&&this.emitResized(`columnresizing`,n,`drag`)}dragRow(t,n){let{id:r}=t.row;this.rowHeightOverrides.set(String(r),Math.max(e.MIN_ROW_HEIGHT,Math.round(t.startSize+n))),this._dataCollection.setHeight(r,this.heightOfRow(r))&&this.refreshRowHeights(),this.dueForLiveEvent(t)&&this.emitRowResized(`rowresizing`,r,`drag`)}dueForLiveEvent(e){let t=performance.now();return t-e.lastEvent<Dt?!1:(e.lastEvent=t,!0)}onResizePointerEnd=e=>{let{resizeDrag:t}=this;t&&(this.resizeDrag=void 0,this.scrollArea.releasePointerCapture(e.pointerId),this.moveResizeGuide(),t.axis===`row`&&t.row.height!==t.startSize&&this.emitRowResized(`rowresized`,t.row.id,`drag`),t.axis===`column`&&t.column.width!==t.startSize&&this.emitResized(`columnresized`,t.column,`drag`))};onResizeDoubleClick=e=>{let t=this.findResizeTarget(e.clientX,e.clientY,`mouse`);if(t?.axis!==`column`)return;let{column:n}=t;n===this.columnList[this.columnList.length-1]&&this.fillRemainingSpace(n)||this.autoSizeColumns([n.id])};fillRemainingSpace(e){let t=this.scrollArea.clientWidth-(this.showRowNumbers?this.rowNumbersWidth:0)-this.columnOffsets[this.columnOffsets.length-1];return t<=0?!1:(this.applyColumnWidths([[e.id,e.width+t]]).forEach(e=>this.emitResized(`columnresized`,e,`auto`)),!0)}onResizeTouchStart=e=>{let[t]=Array.from(e.touches);e.touches.length===1&&this.findResizeTarget(t.clientX,t.clientY,`touch`)&&e.preventDefault()};selectionModel=new et;mode=`none`;set selectionMode(e){e!==this.mode&&(this.mode=e,this.updateTabIndex(),e===`none`&&this.clearSelection())}ownsTabIndex=!1;updateTabIndex(){this.mode!==`none`&&!this.hasAttribute(`tabindex`)&&(this.tabIndex=0,this.ownsTabIndex=!0),this.mode===`none`&&this.ownsTabIndex&&(this.removeAttribute(`tabindex`),this.ownsTabIndex=!1)}get selectionMode(){return this.mode}getSelection(){return this.selectionModel.snapshot()}setSelection(e,t){this.changeSelection(()=>this.selectionModel.replace(e,t),!1)}clearSelection(){this.changeSelection(()=>this.selectionModel.clear(),!1)}emitSelectionChange(e){this.dispatchEvent(new CustomEvent(`selectionchange`,{detail:{...this.selectionModel.snapshot(),selecting:e}}))}emitCellFocus(){let{active:e}=this.selectionModel,t=e&&this._dataCollection.at(e.row),n=e&&this.columnList[e.column];e&&t&&n&&this.dispatchEvent(new CustomEvent(`cellfocus`,{detail:{rowId:t.id,rowIndex:e.row,columnId:n.id,columnIndex:e.column}}))}changeSelection(e,t){let n=this.selectionModel.active&&{...this.selectionModel.active};if(!e())return!1;this.selectionModel.ranges.length>0&&!this.getLayer($.selection)&&this.addLayer($.selection,{before:$.header}),this.selectionDirty=!0,this.headersDirty=!0,this.requestRender(),this.emitSelectionChange(t);let{active:r}=this.selectionModel;return r&&(r.row!==n?.row||r.column!==n.column)&&this.emitCellFocus(),!0}refitSelection(){this.selectionModel.ranges.length!==0&&(this.changeSelection(()=>this.selectionModel.clamp(this._dataCollection.length,this.columnList.length),!1),this.selectionDirty=!0)}selectDrag=void 0;touchTap=void 0;offsetsOf(e,t){let n=this.getBoundingClientRect(),r=this.showRowNumbers?this.rowNumbersWidth:0,i=this.showHeaders?this.headerHeight:0;return{x:e-n.left,y:t-n.top,left:r,top:i}}columnIndexAt(e){let t=R(this.columnOffsets,e);return t<0||e>=this.columnOffsets[this.columnOffsets.length-1]?void 0:t}rowIndexAt(e){let t=this._dataCollection.indexAt(e);return t>=this._dataCollection.length?void 0:t}hitAt(e,t){let{x:n,y:r,left:i,top:a}=this.offsetsOf(e,t);if(n<0||r<0||n>this.scrollArea.clientWidth||r>this.scrollArea.clientHeight)return;let o=r<a,s=n<i,c=this.columnIndexAt(n-i+this.scrollArea.scrollLeft),l=this.rowIndexAt(r-a+this.scrollArea.scrollTop);return o&&s?{zone:`all`}:o?c===void 0?void 0:{zone:`column`,column:c}:s?l===void 0?void 0:{zone:`row`,row:l}:c===void 0||l===void 0?void 0:{zone:`cell`,row:l,column:c}}nearestCell(e,t){let n=this._dataCollection.length;if(n===0||this.columnList.length===0)return;let{x:r,y:i,left:a,top:o}=this.offsetsOf(e,t);return{row:Math.min(n-1,this._dataCollection.indexAt(Math.max(0,i-o)+this.scrollArea.scrollTop)),column:R(this.columnOffsets,Math.max(0,r-a)+this.scrollArea.scrollLeft)}}firstVisible(e){return e===`column`?this._dataCollection.indexAt(this.scrollArea.scrollTop):Math.max(0,R(this.columnOffsets,this.scrollArea.scrollLeft))}pressCell(e,{extend:t,additive:n},r){let{selectionModel:i,mode:a}=this,{active:o}=i;if(t&&o&&a!==`cell`){let t=V(a,o,e);return this.changeSelection(()=>n?i.extend(t,e):i.set(t,o,e),r),{...o}}let s=V(a,e,e);return this.changeSelection(()=>n&&a!==`cell`?i.add(s,e):i.set(s,e),r),e}pressLine(e,t,{extend:n,additive:r},i){let{selectionModel:a}=this,{active:o}=a;if(n&&o){let n=K(e,J(e,o),t),s=q(e,t,Y(e,o));return this.changeSelection(()=>r?a.extend(n,s):a.set(n,o,s),i),{...o}}let s=q(e,t,this.firstVisible(e)),c=K(e,t,t);return this.changeSelection(()=>r?a.add(c,s):a.set(c,s),i),s}selectEverything(e){let t=this.selectionModel.active??{row:this.firstVisible(`column`),column:this.firstVisible(`row`)};this.changeSelection(()=>this.selectionModel.set({},t),e)}static ZONE_MODES={cell:[`cell`,`range`,`row`,`column`],column:[`range`,`column`],row:[`range`,`row`],all:[`range`,`row`,`column`]};press(t,n,r){if(e.ZONE_MODES[t.zone].includes(this.mode)){if(t.zone===`all`)this.selectEverything(r);else return t.zone===`column`?{anchor:this.pressLine(`column`,t.column,n,r),axis:`column`}:t.zone===`row`?{anchor:this.pressLine(`row`,t.row,n,r),axis:`row`}:{anchor:this.pressCell({row:t.row,column:t.column},n,r),axis:void 0}}}dragSelectTo({x:e,y:t,anchor:n,axis:r}){let i=this.nearestCell(e,t);if(!i)return;if(r){let e=q(r,J(r,i),Y(r,n));this.changeSelection(()=>this.selectionModel.extend(K(r,J(r,n),J(r,i)),e),!0);return}if(this.mode===`cell`)return;let a=V(this.mode,n,i);this.changeSelection(()=>this.selectionModel.extend(a,i),!0)}onSelectPointerDown=e=>{if(this.mode===`none`||e.button!==0||this.resizeDrag)return;let t=this.hitAt(e.clientX,e.clientY);if(!t)return;let n={extend:e.shiftKey,additive:e.ctrlKey||e.metaKey};if(e.pointerType===`touch`){this.touchTap={pointerId:e.pointerId,x:e.clientX,y:e.clientY,hit:t,modifiers:n};return}e.preventDefault(),this.focus({preventScroll:!0});let r=this.press(t,n,!0);r&&(this.scrollArea.setPointerCapture(e.pointerId),this.selectDrag={...r,pointerId:e.pointerId,x:e.clientX,y:e.clientY,frame:void 0})};onSelectPointerMove=e=>{let{touchTap:t,selectDrag:n}=this;t&&Math.hypot(e.clientX-t.x,e.clientY-t.y)>kt&&(this.touchTap=void 0),n&&n.pointerId===e.pointerId&&(n.x=e.clientX,n.y=e.clientY,this.dragSelectTo(n),n.frame??=requestAnimationFrame(this.scrollWhileDragging))};scrollWhileDragging=()=>{let e=this.selectDrag;if(!e)return;e.frame=void 0;let{x:t,y:n,left:r,top:i}=this.offsetsOf(e.x,e.y),a=e.axis===`row`?0:tt(t,r,this.scrollArea.clientWidth),o=e.axis===`column`?0:tt(n,i,this.scrollArea.clientHeight);(a!==0||o!==0)&&(this.scrollArea.scrollBy(a,o),this.dragSelectTo(e),e.frame=requestAnimationFrame(this.scrollWhileDragging))};onSelectPointerEnd=e=>{let{touchTap:t,selectDrag:n}=this;t?.pointerId===e.pointerId?(this.touchTap=void 0,e.type===`pointerup`&&(this.focus({preventScroll:!0}),this.press(t.hit,t.modifiers,!1))):n&&n.pointerId===e.pointerId&&(this.endSelectDrag(),this.scrollArea.hasPointerCapture(e.pointerId)&&this.scrollArea.releasePointerCapture(e.pointerId),this.emitSelectionChange(!1))};endSelectDrag(){this.selectDrag?.frame!==void 0&&cancelAnimationFrame(this.selectDrag.frame),this.selectDrag=void 0}revealCell({row:e,column:t}){let{scrollArea:n,_dataCollection:r,columnOffsets:i}=this,{left:a,top:o}=this.offsetsOf(0,0),s=at(r.topOf(e),r.topOf(e+1),n.scrollTop,n.clientHeight-o),c=at(i[t],i[t+1],n.scrollLeft,n.clientWidth-a);s!==n.scrollTop&&(n.scrollTop=s),c!==n.scrollLeft&&(n.scrollLeft=c)}get gridSize(){let{top:e}=this.offsetsOf(0,0);return{rowCount:this._dataCollection.length,columnCount:this.columnList.length,pageRows:Math.max(1,Math.floor((this.scrollArea.clientHeight-e)/this.cellHeight))}}moveTo(e){let t=V(this.mode,e,e);this.changeSelection(()=>this.selectionModel.set(t,e),!1),this.revealCell(e)}extendTo(e){let{selectionModel:t,mode:n}=this,{active:r,focus:i}=t,a=t.ranges[t.ranges.length-1];if(!r||!i||!a)return;let o=Je(a);if(o===`all`)return;if(o===`block`){let i=V(n,r,e);this.changeSelection(()=>t.extend(i,e),!1),this.revealCell(e);return}let s=o,c=K(s,J(s,r),J(s,e)),l=q(s,J(s,e),Y(s,i));this.changeSelection(()=>t.extend(c,l),!1),this.revealCell(l)}stepActive(e,t){let{selectionModel:n}=this,{active:r}=n,i=n.ranges[n.ranges.length-1],a=i&&W(i,this._dataCollection.length,this.columnList.length);if(!r)return!1;if(a&&(a.top!==a.bottom||a.left!==a.right)){let i=it(a,r,e,t);return this.changeSelection(()=>n.activate(i),!1),this.revealCell(i),!0}if(e===`column`)return!1;let o=rt(r,t?`ArrowUp`:`ArrowDown`,!1,this.gridSize);return o&&this.moveTo(o),!0}selectLineOfActive(t){let{active:n}=this.selectionModel;if(!n||!e.ZONE_MODES[t].includes(this.mode))return!1;let r=K(t,J(t,n),J(t,n));return this.changeSelection(()=>this.selectionModel.set(r,n),!1),!0}collapseSelection(){let{active:e}=this.selectionModel;if(!e)return!1;let t=V(this.mode,e,e);return this.changeSelection(()=>this.selectionModel.set(t,e),!1)}navigate(e,t){let{active:n,focus:r}=this.selectionModel,i=this.gridSize;if(i.rowCount===0||i.columnCount===0)return!1;let a={row:this.firstVisible(`column`),column:this.firstVisible(`row`)},o=e.shiftKey&&this.mode!==`cell`,s=rt(n?o&&r||n:a,e.key,t,i);return s?(n?o?this.extendTo(s):this.moveTo(s):this.moveTo(a),!0):!1}handleSelectionKey(t){let n=t.ctrlKey||t.metaKey,{key:r,shiftKey:i}=t;return n&&r.toLowerCase()===`a`?e.ZONE_MODES.all.includes(this.mode)?(this.selectEverything(!1),!0):!1:r===` `&&n?this.selectLineOfActive(`column`):r===` `&&i?this.selectLineOfActive(`row`):r===`Enter`?this.stepActive(`row`,i):r===`Tab`?this.stepActive(`column`,i):r===`Escape`?this.collapseSelection():this.navigate(t,n)}onKeyDown=e=>{this.mode===`none`||e.defaultPrevented||e.altKey||(this.handleEditKey(e)||this.handleSelectionKey(e))&&e.preventDefault()};copiedSelection(){let{ranges:e}=this.selectionModel,t=e[e.length-1],n=t&&W(t,this._dataCollection.length,this.columnList.length);if(!t||!n)return;let r=this.columnList.slice(n.left,n.right+1).map(e=>({header:e,store:this.dataStore.columns.get(String(e.id))})),{text:i,truncated:a}=lt(n,(e,t)=>{let{header:i,store:a}=r[t-n.left],o=a?.get(this._dataCollection.at(e)?.slot??-1);return o===void 0?``:i.valueFormatter(o)});return{text:i,range:{...t},truncated:a}}requestCopy(){let e=this.mode===`none`?void 0:this.copiedSelection();if(e)return this.dispatchEvent(new CustomEvent(`selectioncopy`,{detail:e,cancelable:!0}))?e:void 0}onCopy=e=>{let t=e.clipboardData&&this.requestCopy();t&&e.clipboardData&&(e.clipboardData.setData(`text/plain`,t.text),e.preventDefault())};async copySelection(){let e=this.requestCopy();return e?(await navigator.clipboard.writeText(e.text),!0):!1}contextMenuItems=[{id:`edit`,label:`Edit`,disabled:({row:e,column:t})=>!this.canEditAt(e,t),run:({row:e,column:t})=>void this.editAt(e,t)},{id:`copy`,label:`Copy`,disabled:()=>this.selectionModel.ranges.length===0,run:()=>void this.copySelection()}];contextMenu;menuDetail;isSelected(e){let{ranges:t}=this.selectionModel;return e.zone===`cell`?t.some(t=>Ge(t,e.row,e.column)):e.zone===`column`?Ke(t,e.column,this._dataCollection.length)===`full`:e.zone===`row`?qe(t,e.row,this.columnList.length)===`full`:t.some(e=>Je(e)===`all`)}menuAnchor(){let{x:e,y:t,left:n,top:r}=this.offsetsOf(0,0),{active:i}=this.selectionModel;return i?{x:n-e+this.columnOffsets[i.column]-this.scrollArea.scrollLeft,y:r-t+this._dataCollection.topOf(i.row+1)-this.scrollArea.scrollTop}:{x:n-e,y:r-t}}onContextMenu=e=>{if(this.mode===`none`||this.contextMenuItems.length===0||e.defaultPrevented)return;let t=e.button===2,n=t?this.hitAt(e.clientX,e.clientY):void 0;if(t&&!n)return;e.preventDefault(),this.focus({preventScroll:!0}),n&&!this.isSelected(n)&&this.press(n,{extend:!1,additive:!1},!1);let r=t?{x:e.clientX,y:e.clientY}:this.menuAnchor(),i=this.selectionModel.active,a={...this.selectionModel.snapshot(),...r,row:n?n.zone===`cell`||n.zone===`row`?n.row:void 0:i?.row,column:n?n.zone===`cell`||n.zone===`column`?n.column:void 0:i?.column,items:[...this.contextMenuItems]};this.dispatchEvent(new CustomEvent(`gridcontextmenu`,{detail:a,cancelable:!0}))&&a.items.length!==0&&(this.menuDetail=a,this.contextMenu??=new ut(this,e=>this.menuDetail?.items.find(t=>t.id===e)?.run(this.menuDetail)),this.contextMenu.open(a.x,a.y,a.items.map(({id:e,label:t,disabled:n})=>({id:e,label:t,disabled:typeof n==`function`?n(a):n??!1}))))};editOutOfView=`cancel`;edit;cellOf(e,t){let n=this._dataCollection.get(e),r=this.headers.get(t);if(n&&r)return{rowId:n.id,rowIndex:n.index,columnId:r.id,columnIndex:r.index,value:this.dataStore.getValue(n.id,r.id)}}canEdit(e){let t=this.headers.get(e.columnId)?.editable;return typeof t==`function`?t(e):t===!0}startEditing(e,t){return this.openEditor(e,t,void 0)}stopEditing(e=!1){return this.finishEdit(e)}openEditor(e,t,n){let r=this.cellOf(e,t);if(!r||!this.canEdit(r)||!this.finishEditIfOpen()||!this.dispatchEvent(new CustomEvent(`celleditstart`,{detail:r,cancelable:!0})))return!1;this.revealCell({row:r.rowIndex,column:r.columnIndex});let i=bt(this.headers.get(t)?.cellEditor,{...r,initialText:n,commit:()=>void this.finishEdit(!1),cancel:()=>void this.finishEdit(!0)}),a=document.createElement(`div`);return a.className=`cellEditor`,a.style.colorScheme=this.themeName,a.style.background=this.backgroundColor,a.style.color=this.textColor,a.style.outlineColor=this.theme.selectionBorder,a.style.setProperty(`--cg-editor-background`,this.backgroundColor),a.style.setProperty(`--cg-editor-text`,this.textColor),a.style.setProperty(`--cg-editor-border`,this.theme.border),a.style.setProperty(`--cg-editor-accent`,this.theme.selectionBorder),a.style.setProperty(`--cg-editor-highlight`,this.theme.selection),a.style.setProperty(`--cg-editor-padding-left`,`${this.cellPadding.left}px`),a.style.setProperty(`--cg-editor-padding-right`,`${this.cellPadding.right}px`),a.style.font=this.headers.get(t)?.font??this.font,a.append(i.element),a.addEventListener(`keydown`,this.onEditorKeyDown),a.addEventListener(`focusout`,this.onEditorFocusOut),a.addEventListener(`input`,()=>this.showValidity()),a.addEventListener(`change`,()=>this.showValidity()),this.append(a),this.edit={cell:r,instance:i,wrapper:a},this.positionEditor(),i.focus?i.focus():i.element.focus({preventScroll:!0}),!0}finishEditIfOpen(){return!this.edit||this.finishEdit(!1)}checkEdit(e){let t=this.headers.get(e.cell.columnId),n=this.dataStore.getValue(e.cell.rowId,e.cell.columnId);return Tt(e.instance.getValue(),t?.cellEditor,{parse:t?.valueParser,validate:t?.validator},{...e.cell,value:n,oldValue:n})}showValidity(e){let{edit:t}=this;if(!t)return;let{ok:n,message:r}={message:void 0,...e??this.checkEdit(t)};t.wrapper.classList.toggle(`invalid`,!n),t.wrapper.title=r??``,t.instance.element.setAttribute(`aria-invalid`,String(!n))}applyEdit(e,t){let{cell:n}=e,r=this.dataStore.getValue(n.rowId,n.columnId);if(t===n.value)return!0;let i=this.headers.get(n.columnId)?.valueSetter;return i&&i({...n,value:r,oldValue:r,newValue:t})===!1?!1:(!i&&this.dataStore.setValue(n.rowId,n.columnId,t)&&this.forceDraw(),i||this.requestRender(),this.dispatchEvent(new CustomEvent(`cellvaluechanged`,{detail:{...n,value:t,oldValue:r,newValue:t}})),!0)}finishEdit(e){let{edit:t}=this;if(!t)return!1;let n=e?void 0:this.checkEdit(t);if(n&&!n.ok)return this.showValidity(n),!1;let r=n?.ok?n.value:void 0;return n&&!this.applyEdit(t,r)?(this.showValidity({ok:!1,message:`Rejected`}),!1):(this.closeEditor(t),this.dispatchEvent(new CustomEvent(`celleditend`,{detail:{...t.cell,cancelled:e,newValue:r}})),!0)}closeEditor({wrapper:e,instance:t}){let n=e.contains(document.activeElement);this.edit=void 0,t.destroy?.(),e.remove(),n&&this.focus({preventScroll:!0})}positionEditor(){let{edit:e,scrollArea:t,columnOffsets:n}=this;if(!e)return;let r=this.cellOf(e.cell.rowId,e.cell.columnId);if(!r){this.finishEdit(!0);return}e.cell.rowIndex=r.rowIndex,e.cell.columnIndex=r.columnIndex;let{left:i,top:a}=this.offsetsOf(0,0),o=this._dataCollection,s=i+n[r.columnIndex]-Math.round(t.scrollLeft),c=a+o.topOf(r.rowIndex)-Math.round(t.scrollTop),l=n[r.columnIndex+1]-n[r.columnIndex],u=o.topOf(r.rowIndex+1)-o.topOf(r.rowIndex),d={top:Math.max(0,a-c),right:Math.max(0,s+l-t.clientWidth),bottom:Math.max(0,c+u-t.clientHeight),left:Math.max(0,i-s)},f=d.top>=u||d.bottom>=u||d.left>=l||d.right>=l;if(f&&this.editOutOfView!==`keep`&&this.finishEdit(this.editOutOfView===`cancel`))return;let{style:p}=e.wrapper;p.left=`${s}px`,p.top=`${c}px`,p.width=`${l}px`,p.height=`${u}px`,p.clipPath=f?`inset(100%)`:`inset(${d.top}px ${d.right}px ${d.bottom}px ${d.left}px)`,p.pointerEvents=f?`none`:``,e.instance.place?.(!f)}onEditorKeyDown=e=>{e.stopPropagation();let{edit:t}=this,{key:n,shiftKey:r}=e;if(!t||e.isComposing||![`Escape`,`Enter`,`Tab`].includes(n))return;e.preventDefault();let{rowIndex:i,columnIndex:a}=t.cell;if(!this.finishEdit(n===`Escape`)||n===`Escape`||this.mode===`none`)return;let o=ot({row:i,column:a},n===`Enter`?`row`:`column`,r,this.gridSize);this.moveTo(o)};onEditorFocusOut=e=>{let{edit:t}=this;!t||!document.hasFocus()||e.relatedTarget instanceof Node&&t.wrapper.contains(e.relatedTarget)||this.finishEdit(!1)||this.finishEdit(!0)};cellAt(e,t){let n=e===void 0?void 0:this._dataCollection.at(e),r=t===void 0?void 0:this.columnList[t];return n&&r?this.cellOf(n.id,r.id):void 0}canEditAt(e,t){let n=this.cellAt(e,t);return n!==void 0&&this.canEdit(n)}editAt(e,t){let n=this.cellAt(e,t);return n!==void 0&&this.openEditor(n.rowId,n.columnId,void 0)}onEditDoubleClick=e=>{let t=this.hitAt(e.clientX,e.clientY);t?.zone===`cell`&&this.editAt(t.row,t.column)};handleEditKey(e){let{active:t,ranges:n}=this.selectionModel,r=t&&this._dataCollection.at(t.row),i=t&&this.columnList[t.column];if(!r||!i)return!1;let{key:a,shiftKey:o}=e,s=n.length===1?W(n[0],this._dataCollection.length,this.columnList.length):void 0,c=s!==void 0&&s.top===s.bottom&&s.left===s.right,l=a.length===1&&!e.ctrlKey&&!e.metaKey&&!(a===` `&&o);return a===`F2`||a===`Enter`&&!o&&c?this.openEditor(r.id,i.id,void 0):l&&xt(i.cellEditor)&&this.openEditor(r.id,i.id,a)}get totalHeight(){return this._dataCollection.totalHeight}refreshScrollbar(){let e=this.totalHeight+this.headerHeight;this.scrollHelper.style.height=`${e}px`;let t=this.columnOffsets[this.columnOffsets.length-1];this.scrollHelper.style.width=`${t}px`}queueUpdate(e){this.dataStore.queueUpdate(e),this.throttleTransation()}queueRemove(e){this.dataStore.queueRemove(e),this.throttleTransation()}transaction({add:e=[],remove:t=[],update:n=[]}){Array.isArray(e)&&e.forEach(e=>this.queueUpdate(e)),Array.isArray(n)&&n.forEach(e=>this.queueUpdate(e)),Array.isArray(t)&&t.forEach(e=>this.queueRemove(e))}clearValues(){this.dataStore.clear(),this.cellEntries.clear()}formatValue(e,t){return this.headers.get(e)?.valueFormatter(t)??String(t)}setValues(e){this.throttleTransation.cancel(),this.clearValues(),Array.isArray(e)&&(this.dataStore.setRows(e),this.refreshScrollbar(),this.refitSelection(),this.forceDraw())}setColumns(e){if(Array.isArray(e)){this.headers.clear(),this.cellEntries.clear();let t={width:100,valueFormatter:e=>String(e),headerRenderer:$.headerRenderer};e.forEach((e,n)=>{if(typeof e==`string`||typeof e==`number`){let r=e+``;this.headers.set(r,{...t,index:n,id:e,displayName:r})}typeof e==`object`&&this.headers.set(e.id+``,{...t,index:n,...e})}),this.updateColumnLayout(),this.refreshScrollbar(),this.refitSelection(),this.forceDraw()}}disconnectedCallback(){this.finishEdit(!0),this.cancelRender(),this.endSelectDrag(),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.resizeObserver?.disconnect(),this.pixelRatioQuery?.removeEventListener(`change`,this.watchPixelRatio),this.unwatchTheme(),document.fonts?.removeEventListener(`loadingdone`,this.onFontsLoaded),clearTimeout(this.fontsTimeout)}};return window&&window.customElements&&(Mt(),customElements.define(`canvas-grid`,Rt)),Rt});
|
|
3
3
|
//# sourceMappingURL=web-component.js.map
|