@koeroesi86/canvas-grid 26.11.3 → 26.11.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  import Renderer from '../utils/renderer';
2
+ import type { TextStyle } from '../text';
2
3
  import type { CellContext, CellRenderer } from '../types';
3
4
  export interface CellValueOptions {
4
5
  layer: string;
@@ -16,6 +17,7 @@ export default class CellValueRenderer extends Renderer<CellValueOptions> implem
16
17
  get color(): string;
17
18
  set pixelRatio(pixelRatio: number);
18
19
  get pixelRatio(): number;
20
+ setTextStyle(style: Partial<TextStyle>): void;
19
21
  clearCache(): void;
20
- draw({ ctx, x, y, width, height, formatted, valueChanged, forced }: Readonly<CellContext>): void;
22
+ draw({ ctx, x, y, width, height, column, formatted, valueChanged, forced }: Readonly<CellContext>): void;
21
23
  }
@@ -1,4 +1,5 @@
1
1
  import Renderer from '../utils/renderer';
2
+ import type { TextStyle } from '../text';
2
3
  import type { CellContext, CellRenderer } from '../types';
3
4
  export interface HeaderOptions {
4
5
  layer: string;
@@ -19,7 +20,8 @@ declare class HeaderRenderer extends Renderer<HeaderOptions> implements CellRend
19
20
  get font(): string;
20
21
  set pixelRatio(pixelRatio: number);
21
22
  get pixelRatio(): number;
23
+ setTextStyle(style: Partial<TextStyle>): void;
22
24
  clearCache(): void;
23
- draw({ ctx, x, y, width, height, formatted }: Readonly<CellContext>): void;
25
+ draw({ ctx, x, y, width, height, column, formatted }: Readonly<CellContext>): void;
24
26
  }
25
27
  export default HeaderRenderer;
@@ -1,6 +1,19 @@
1
1
  import Renderer from '../utils/renderer';
2
2
  import type { RenderProps } from '../types';
3
- export interface TextOptions {
3
+ export interface TextStyle {
4
+ /** Canvas `textRendering`: trade speed for legibility or exact geometry. Browser default is `'auto'`. */
5
+ textRendering: CanvasTextRendering;
6
+ /** Canvas `fontKerning`. Browser default is `'auto'`. */
7
+ fontKerning: CanvasFontKerning;
8
+ /** Extra space after each character, a CSS length such as `'0.5px'`. */
9
+ letterSpacing: string;
10
+ /**
11
+ * `'ltr'` and `'rtl'` set the direction of every cell; `'auto'` picks it per cell from the first letter,
12
+ * so mixed data works. Right-to-left text is aligned to the right of the cell.
13
+ */
14
+ direction: 'ltr' | 'rtl' | 'auto';
15
+ }
16
+ export interface TextOptions extends TextStyle {
4
17
  ellipsis: string;
5
18
  cellPadding: {
6
19
  top: number;
@@ -12,20 +25,45 @@ export interface TextOptions {
12
25
  color: string;
13
26
  isEllipsisRight: boolean;
14
27
  }
28
+ export declare const defaultTextStyle: Readonly<TextStyle>;
15
29
  declare class TextRenderer extends Renderer<TextOptions> {
16
30
  static readonly defaultOptions: TextOptions;
17
- private readonly characterRenderer;
31
+ /** Measurements per font, so columns with their own font do not mix up widths. Cleared when anything affecting widths changes. */
32
+ private readonly fonts;
33
+ private readonly measureContext;
34
+ private measuredState;
35
+ /** Set once a style option differs from the default, so grids that never touch them set nothing extra per cell. */
36
+ private styled;
18
37
  constructor(options?: Partial<TextOptions>);
38
+ private differsFromDefault;
19
39
  set font(font: string);
20
40
  get font(): string;
21
41
  set color(color: string);
22
42
  get color(): string;
23
- set pixelRatio(pixelRatio: number);
24
- get pixelRatio(): number;
43
+ /** Changes the text style; widths are measured again when something changed. */
44
+ setStyle(style: Partial<TextStyle>): void;
45
+ /** Text is drawn straight into the layer, whose transform already scales it to the device pixel ratio. */
46
+ pixelRatio: number;
25
47
  clearCache(): void;
48
+ /** The measurements of a font, created on first use. */
49
+ private measuresOf;
50
+ /** Gives the measuring context the font and style the text is drawn with. */
51
+ private prepareMeasuring;
52
+ /** Width of one character in a font, measured once. */
53
+ private measureCharacter;
54
+ /** Width of a string as the browser lays it out: includes kerning, ligatures and joined scripts. */
55
+ private measureString;
56
+ /** Sum of the character widths in the renderer's font: exact for monospace fonts, a close upper bound for most others. */
26
57
  getTextWidth(text: string): number;
27
- /** Draws the text clipped with an ellipsis; `(x, y)` is the offset of the text box from `(originX, originY)`. */
28
- paint(ctx: CanvasRenderingContext2D, { value, x, y, width, height }: RenderProps, originX: number, originY: number): void;
58
+ /** The font of the cell drawn last: columns mostly share one, so the lookup by font name is skipped. */
59
+ private lastMeasures;
60
+ private isRightToLeft;
61
+ /**
62
+ * Draws the text clipped with an ellipsis; `(x, y)` is the offset of the text box from `(originX, originY)`.
63
+ * The whole string is drawn with one `fillText`: recording one command per cell is much cheaper than
64
+ * one `drawImage` per character, and the browser keeps its own glyph cache.
65
+ */
66
+ paint(ctx: CanvasRenderingContext2D, { value, x, y, width, height, font }: RenderProps, originX: number, originY: number): void;
29
67
  readonly element: import("../utils/jsx").Component<RenderProps>;
30
68
  }
31
69
  export default TextRenderer;
@@ -23,6 +23,8 @@ export interface SortKey {
23
23
  /** Props of a drawable element (see utils/jsx); positions are relative to the draw origin. */
24
24
  export interface RenderProps {
25
25
  value?: string;
26
+ /** CSS font of the text; defaults to the renderer's own. */
27
+ font?: string;
26
28
  x?: number;
27
29
  y?: number;
28
30
  width?: number;
@@ -38,6 +40,10 @@ export interface CellColumn {
38
40
  id: Key;
39
41
  index: number;
40
42
  displayName?: string;
43
+ /** Font of this column's cells, when it has its own. */
44
+ font?: string;
45
+ /** Font of this column's header, when it has its own. */
46
+ headerFont?: string;
41
47
  }
42
48
  /**
43
49
  * Everything a renderer needs to draw one cell, header or row number.
@@ -4,6 +4,8 @@
4
4
  */
5
5
  declare class ColumnStore {
6
6
  values: unknown[];
7
+ /** Changes whenever a value is set, cleared or moved, so results computed from the values can be reused while it stays the same. */
8
+ version: number;
7
9
  /** When each value last changed, 0 when unknown; only allocated once a value changes after loading. */
8
10
  private updatedAt;
9
11
  constructor(length?: number);
@@ -21,6 +21,8 @@ declare class DataStore {
21
21
  private sortDirty;
22
22
  /** Ids of the rows changed since the last sort; only those have to move when few changed. */
23
23
  private sortChanged;
24
+ /** Sort keys per column, reused until the column's values change (e.g. when only the direction flips). */
25
+ private defaultKeys;
24
26
  private environment;
25
27
  constructor(environment: DataStoreEnvironment);
26
28
  get hasPending(): boolean;
@@ -46,6 +48,7 @@ declare class DataStore {
46
48
  private applyUpdate;
47
49
  private applyValue;
48
50
  private markSortDirty;
51
+ private defaultKeyOf;
49
52
  /** Orders two rows by the sort model, ties by slot so the order is total. */
50
53
  private createComparator;
51
54
  private sort;
@@ -0,0 +1,24 @@
1
+ /** The text that was cut to `available` pixels, remembered per text so a cell that is drawn again costs one lookup. */
2
+ export interface FittedText {
3
+ available: number;
4
+ text: string;
5
+ }
6
+ export type FitCache = Map<string, FittedText>;
7
+ export interface ExactFit {
8
+ /** Width of a string as the browser lays it out, with kerning, ligatures and joined scripts. */
9
+ measure: (text: string) => number;
10
+ /** Cuts already made, so a text that is drawn again is not measured again. */
11
+ cache?: FitCache;
12
+ /** The character widths add up to the real width, as for a monospace font: Latin text then needs no measuring. */
13
+ sumIsExact: boolean;
14
+ }
15
+ /**
16
+ * Cuts `text` to fit `available` pixels, ending in `ellipsis` when something was cut.
17
+ * `widthOf` gives the width of one character, and the text width is the sum of those: cheap, and exact for a
18
+ * monospace font. That is all that runs for text that fits, which is nearly every cell. A cell that does not fit
19
+ * is measured again with `exact.measure` when the sum cannot be trusted, which is for proportional fonts (kerning
20
+ * makes the sum overshoot) and for text with joined scripts such as Arabic (it overshoots by 40%).
21
+ * Characters that form one glyph (emoji, letters with combining accents) are kept or cut together.
22
+ */
23
+ declare const fitText: (text: string, available: number, ellipsis: string, widthOf: (character: string) => number, exact?: ExactFit) => string;
24
+ export default fitText;
@@ -0,0 +1,8 @@
1
+ export declare const INHERIT_FONT = "inherit";
2
+ type FontStyle = Pick<CSSStyleDeclaration, 'fontStyle' | 'fontWeight' | 'fontSize' | 'fontFamily'>;
3
+ /**
4
+ * The element's computed font as a canvas font string, or `fallback` when it has none (not attached yet).
5
+ * Built from the longhands, because `getComputedStyle(...).font` is empty in some browsers.
6
+ */
7
+ export declare const resolveFont: (font: string, style: FontStyle, fallback: string) => string;
8
+ export {};
@@ -7,6 +7,7 @@ import RendererRegistry from './utils/renderer-registry';
7
7
  import CellBackground from './cell-background';
8
8
  import HeaderRenderer from './header';
9
9
  import CellValueRenderer from './cell-value';
10
+ import type { TextStyle } from './text';
10
11
  import type { LayerOptions } from './utils/layer';
11
12
  import type { CellContext, CellRenderer, CellState, Key, RendererRef, RowId, RowInput, SortDirection, SortKey } from './types';
12
13
  import type { RowIdGetter } from './utils/data-store';
@@ -26,6 +27,10 @@ export interface ColumnHeader {
26
27
  /** Renderers drawing a cell of this column, in order. Defaults to the grid's `cellRenderers`. */
27
28
  renderers?: RendererRef[];
28
29
  valueFormatter: (value: unknown) => string;
30
+ /** CSS font of this column's cells, instead of the grid's `font`. Not `'inherit'`: that is the grid's. */
31
+ font?: string;
32
+ /** CSS font of this column's header, instead of the grid's `headerFont`. */
33
+ headerFont?: string;
29
34
  /** Renderer drawing the header of this column. */
30
35
  headerRenderer: RendererRef;
31
36
  }
@@ -120,9 +125,28 @@ declare class CanvasGridComponent extends HTMLElement {
120
125
  get font(): string;
121
126
  set headerFont(font: string);
122
127
  get headerFont(): string;
128
+ private textStyle;
129
+ private setTextStyle;
130
+ /** Canvas `textRendering` for cells and headers: `'auto'` (default), `'optimizeSpeed'`, `'optimizeLegibility'` or `'geometricPrecision'`. */
131
+ set textRendering(textRendering: TextStyle['textRendering']);
132
+ get textRendering(): TextStyle['textRendering'];
133
+ /** Canvas `fontKerning` for cells and headers: `'auto'` (default), `'normal'` or `'none'`. */
134
+ set fontKerning(fontKerning: TextStyle['fontKerning']);
135
+ get fontKerning(): TextStyle['fontKerning'];
136
+ /** Extra space after each character as a CSS length, `'0px'` by default. */
137
+ set letterSpacing(letterSpacing: string);
138
+ get letterSpacing(): string;
139
+ /** `'ltr'` (default), `'rtl'`, or `'auto'` to pick the direction per cell from its first letter. */
140
+ set direction(direction: TextStyle['direction']);
141
+ get direction(): TextStyle['direction'];
123
142
  connectedCallback(): void;
124
143
  private fontsTimeout;
125
144
  private readonly onVisibilityChange;
145
+ /**
146
+ * Re-reads the fonts and redraws. Call it after changing the CSS font of the grid or its ancestors
147
+ * while `font` / `headerFont` are `'inherit'`. Web fonts finishing to load trigger it too.
148
+ */
149
+ refreshFonts(): void;
126
150
  private readonly onFontsLoaded;
127
151
  cancelRender(): void;
128
152
  /**
@@ -1,2 +1,2 @@
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;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.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){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.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}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 Map;e.forEach((e,i)=>{t[i]=x(e),t[i]===0&&(n[i]=Number(e)),(t[i]===1||t[i]===2)&&r.set(String(e),0)});let i=0,a=Array.from(r.keys()).sort(y.compare);return a.forEach((e,t)=>{t>0&&y.compare(a[t-1],e)!==0&&i++,r.set(e,i)}),e.forEach((e,i)=>{(t[i]===1||t[i]===2)&&(n[i]=r.get(String(e))??0)}),{ranks:t,keys:n}},w=class{rows=new g;columns=new Map;pending=[];sortModel=[];sortDirty=!1;sortChanged=new Set;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)}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)))}createComparator(e){let t=this.sortModel.map(({columnId:t,direction:n=`asc`,compare:r})=>{let i=this.columns.get(String(t))?.values,a=n===`desc`?-1:1;if(!i)return{order:()=>0,sign:a};if(r)return{order:(e,t)=>r(i[e.slot],i[t.slot]),sign:a};if(!e)return{order:(e,t)=>S(i[e.slot],i[t.slot]),sign:a};let{ranks:o,keys:s}=C(i);return{order:(e,t)=>o[e.slot]-o[t.slot]||(o[e.slot]===3?0:s[e.slot]-s[t.slot])||0,sign:a}});return(e,n)=>{for(let{order:r,sign:i}of t){let t=r(e,n);if(t!==0)return t*i}return e.slot-n.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 .drawingLayer{contain:strict;width:100%;height:100%;position:absolute;top:0;left:0}canvas-grid .scrollArea{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}`,D=e=>!!e,O=e=>t=>({draw:(n,r,i)=>e(n,t,r,i)}),k=({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))}),A={createElement(e,t,...n){return e(Object.assign({},t,{children:n}))}},j=class{options;constructor(e){this.options={...e}}update(e){let t={...this.options};Object.assign(this.options,e),this.optionsUpdated(t)}optionsUpdated(e){}clearCache(){}},M=class extends j{bitmaps=new T(4096);cacheKey(e){}pixelRatio=1;clearCache(){this.bitmaps.clear()}paint(e,t,n,r){let i=this.cacheKey(t),a=(i===void 0?void 0:this.bitmaps.get(i))??this.renderBitmap(t,i);a.width<=0||a.height<=0||e.drawImage(a,n+(t.x??0),r+(t.y??0),a.width/this.pixelRatio,a.height/this.pixelRatio)}element=O((e,t,n,r)=>this.paint(e,t,n,r));renderBitmap(e,t){let n=this.render(e);if(t===void 0||n.width<=0||n.height<=0)return n;let r=document.createElement(`canvas`);return r.width=n.width,r.height=n.height,r.getContext(`2d`)?.drawImage(n,0,0),this.bitmaps.set(t,r),r}},N=(e,t)=>{let n=e.getContext(`2d`,t);if(!n)throw Error(`2D canvas context is not available`);return n},P=class extends j{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=N(this.offCanvas),this.offCtx.lineWidth=.5,this.offCtx.strokeStyle=`rgba(255, 255, 255, 0.75)`}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}},F=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=N(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)}},I=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?.())}},L=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))}),R=class e extends j{static defaultOptions={layer:`background`,enableFlashing:!0,background:`#333`,flashInDuration:200,flashOutDuration:400,flashRGB:`214, 144, 13`,borderRightWidth:0,borderRightColor:`#fff`,borderBottomWidth:0,borderBottomColor:`#fff`};constructor(t={}){super({...e.defaultOptions,...t})}get layer(){return this.options.layer}isAnimating({age:e}){return 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,r=e<t?e/t:(t+n-e)/n;return Math.max(0,Math.round(r*1e3)/1e3)}draw({ctx:e,x:t,y:n,width:r,height:i,age:a}){let{background:o,flashRGB:s,borderRightWidth:c,borderRightColor:l,borderBottomWidth:u,borderBottomColor:d}=this.options,f=this.getFlashAlpha(a);A.createElement(k,null,A.createElement(L,{width:r,height:i,color:o}),f>0&&A.createElement(L,{width:r,height:i,color:`rgb(${s})`,alpha:f}),c>0&&A.createElement(L,{x:r-c,width:c,height:i,color:l}),u>0&&A.createElement(L,{y:i-u,width:r,height:u,color:d})).draw(e,t,n)}},z=class e extends M{static defaultOptions={font:`12px monospace`,color:`#fff`,alpha:!0,clearBeforeRender:!0};charWidthCache=new p;canvas=document.createElement(`canvas`);ctx;constructor(t={}){super({...e.defaultOptions,...t}),this.ctx=N(this.canvas,{alpha:this.options.alpha}),this.ctx.textAlign=`left`,this.ctx.textBaseline=`top`}set font(e){this.options.font!==e&&(this.options.font=e)}set color(e){this.options.color=e}clearCache(){super.clearCache(),this.charWidthCache.clear()}cacheKey({value:e=``,height:t=0}){return`${this.options.font}|${this.options.color}|${this.pixelRatio}|${t}|${e}`}getCharacterWidth(e=``){let t=this.charWidthCache.get(e);if(t)return t;this.ctx.font!==this.options.font&&(this.ctx.font=this.options.font,this.ctx.textAlign=`left`,this.ctx.textBaseline=`top`);let n=Math.ceil(this.ctx.measureText(e).width);return this.charWidthCache.set(e,n),n}render({value:e=``,height:t=0}){let{pixelRatio:n}=this;return this.canvas.width=Math.round(this.getCharacterWidth(e)*n),this.canvas.height=Math.round(t*n),this.ctx.setTransform(n,0,0,n,0,0),this.ctx.font=this.options.font,this.ctx.textAlign=`left`,this.ctx.textBaseline=`top`,this.ctx.fillStyle!==this.options.color&&(this.ctx.fillStyle=this.options.color),this.ctx.fillText(e,0,0),this.canvas}},B=class e extends j{static defaultOptions={ellipsis:`…`,cellPadding:{top:3,right:3,bottom:3,left:3},font:`12px monospace`,color:`#fff`,isEllipsisRight:!0};characterRenderer;constructor(t={}){super({...e.defaultOptions,...t}),this.characterRenderer=new z({font:this.options.font,color:this.options.color})}set font(e){this.options.font!==e&&(this.options.font=e,this.characterRenderer.font=e,this.clearCache())}get font(){return this.options.font}set color(e){this.options.color=e,this.characterRenderer.color=e}get color(){return this.options.color}set pixelRatio(e){this.characterRenderer.pixelRatio=e}get pixelRatio(){return this.characterRenderer.pixelRatio}clearCache(){this.characterRenderer.clearCache()}getTextWidth(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charAt(n);t+=this.characterRenderer.getCharacterWidth(r)}return t}paint(e,{value:t=``,x:n=0,y:r=0,width:i=0,height:a=0},o,s){let c=this.characterRenderer.getCharacterWidth(this.options.ellipsis),l=this.options.cellPadding.left+this.options.cellPadding.right,u=i-c-l,d=o+n,f=s+r+this.options.cellPadding.top,p=a-this.options.cellPadding.top-this.options.cellPadding.bottom,m=this.options.cellPadding.left,h=0;for(let n=0;n<t.length;n++){let r=t.charAt(n),i=Math.round(this.characterRenderer.getCharacterWidth(r));if(Math.ceil(h+i)>=u){this.characterRenderer.paint(e,{value:this.options.ellipsis,height:p},d+m,f);break}this.characterRenderer.paint(e,{value:r,height:p},d+m,f),h+=i,m+=i}}element=O((e,t,n,r)=>this.paint(e,t,n,r))},V=class e extends j{static defaultOptions={layer:`header`,background:`#333`,font:`13px monospace`,color:`#fff`,borderRightWidth:1,borderRightColor:`#fff`,borderBottomWidth:1,borderBottomColor:`#fff`};textRenderer;constructor(t={}){super({...e.defaultOptions,...t}),this.textRenderer=new B({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}clearCache(){this.textRenderer.clearCache()}draw({ctx:e,x:t,y:n,width:r,height:i,formatted:a}){if(r===0||i===0)return;let{background:o,borderRightWidth:s,borderRightColor:c,borderBottomWidth:l,borderBottomColor:u}=this.options;A.createElement(k,null,A.createElement(L,{width:r,height:i,color:o}),s>0&&A.createElement(L,{x:r-s,width:s,height:i,color:c}),l>0&&A.createElement(L,{y:i-l,width:r,height:l,color:u}),A.createElement(this.textRenderer.element,{value:a,width:r,height:i})).draw(e,t,n)}},H=class e extends j{static defaultOptions={layer:`content`,font:`12px monospace`,color:`#fff`};renderer;constructor(t={}){super({...e.defaultOptions,...t}),this.renderer=new B({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}clearCache(){this.renderer.clearCache()}draw({ctx:e,x:t,y:n,width:r,height:i,formatted:a,valueChanged:o,forced:s}){(o||s)&&(e.clearRect(t,n,r,i),A.createElement(this.renderer.element,{value:a,width:r,height:i}).draw(e,t,n))}},U={scrollArea:`scrollArea`},W={background:`background`,content:`content`,header:`header`,backgroundRenderer:`background`,valueRenderer:`value`,headerRenderer:`header`},G=`canvas-grid-styles`,K=()=>{if(document.getElementById(G))return;let e=document.createElement(`style`);e.id=G,e.textContent=E,document.head.appendChild(e)},q=class extends HTMLElement{fps=30;_font=`12px monospace`;_headerFont=`13px monospace`;headerHeight=30;cellHeight=20;cellPadding={top:3,right:3,bottom:3,left:3};showRowNumbers=!0;showHeaders=!0;rowNumbersWidth=30;ellipsis=`…`;_backgroundColor=`#333`;_headerBackgroundColor=`#222`;textColor=`#efefef`;dataStore=new w({getRowId:(e,t)=>this.getRowId(e,t),getCellHeight:()=>this.cellHeight});_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 I;cellRenderers=[W.backgroundRenderer,W.valueRenderer];cellBackgroundRenderer=new R({layer:W.background,background:this._backgroundColor,enableFlashing:!0,flashInDuration:200,flashOutDuration:400,flashRGB:`214, 144, 13`,borderRightWidth:1,borderRightColor:`#3f3f3f`,borderBottomWidth:1,borderBottomColor:`#3f3f3f`});cellValueRenderer=new H({layer:W.content,font:this._font,color:this.textColor});headerCellRenderer=new V({layer:W.header,font:this._headerFont,color:this.textColor,background:`#222`,borderRightWidth:1,borderRightColor:`#2f2f2f`,borderBottomWidth:1,borderBottomColor:`#2f2f2f`});loadingIndicator;cell;placeholderState={};throttleTransation=(0,d.default)(()=>{let e=this.totalHeight,t=this.dataStore.flush();e!==this.totalHeight&&this.refreshScrollbar(),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(W.background,{alpha:!1}),this.addLayer(W.content),this.addLayer(W.header),this.registerRenderer(W.backgroundRenderer,this.cellBackgroundRenderer),this.registerRenderer(W.valueRenderer,this.cellValueRenderer),this.registerRenderer(W.headerRenderer,this.headerCellRenderer),this.loadingIndicator=new P({ctx:this.requireLayer(W.header).ctx}),this.cell={ctx:this.requireLayer(W.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,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(W.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 F(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=U.scrollArea,e.appendChild(this.scrollHelper),e}set font(e){this._font!==e&&(this._font=e,this.cellValueRenderer.font=e)}get font(){return this._font}set headerFont(e){this._headerFont!==e&&(this._headerFont=e,this.headerCellRenderer.font=e)}get headerFont(){return this._headerFont}connectedCallback(){this.layers.forEach(e=>this.appendChild(e.canvas)),this.appendChild(this.scrollArea),this.updateLastRender(),this.resize(),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),t=(0,d.default)((t,n)=>{this.scrollXOffset=Math.round(n),this.scrollYOffset=Math.round(t),e(),this.requestRender()},10);this.scrollArea.addEventListener(`scroll`,()=>{let{scrollTop:e,scrollLeft:n}=this.scrollArea;this.isScrolling=!0,t(e,n)})}fontsTimeout=void 0;onVisibilityChange=()=>{document.visibilityState===`hidden`?this.cancelRender():this.resize()};onFontsLoaded=()=>{this.renderers.clearCaches(),this.resize()};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(){this.animationFrame=void 0,new Date().valueOf()-this.lastRender<1e3/this.fps?this.requestRender():(this.draw(),this.updateLastRender())}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,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;let r=this._dataCollection.length===0;if((e||this.hasXScrolled())&&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(t.index*t.width+(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.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:a,id:l,x:d,store:f}of s){let s=f?.get(u);if(s===void 0)continue;let p=e[l]??={value:void 0,formatted:void 0,animating:!1,state:{}},m=p.formatted!==void 0&&p.value===s?p.formatted:a.valueFormatter(s),h=p.formatted!==m,g=f?.getUpdatedAt(u),{cell:_}=this;_.x=d,_.y=c,_.width=a.width,_.height=o.height,_.row=i,_.column=a,_.value=s,_.formatted=m,_.updatedAt=g,_.age=g===void 0?1/0:t-g,_.valueChanged=h,_.forced=n,_.state=p.state;let v=a.renderers??this.cellRenderers,y=this.isAnimating(v);(n||h||y||p.animating)&&this.paintAll(v),p.animating=y,p.value=s,p.formatted=m,r||=y}}}(this.scrollYOffset>0||this.scrollXOffset>0)&&this.renderBrick(),this.prevScrollYOffset=this.scrollYOffset,this.prevScrollXOffset=this.scrollXOffset,r&&this.requestRender()}getVisibleColumns(e){let t=[],n=e;return this.headers.forEach((e,r)=>{this.isInViewport(n,0,e.width,0)&&t.push({header:e,id:String(r),x:n,store:this.dataStore.columns.get(String(r))}),n+=Math.round(e.width)}),t}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}`}),this.paint(W.headerRenderer))}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.forceDraw()}getSortModel(){return this.dataStore.getSortModel()}renderBrick(){this.showHeaders&&this.showRowNumbers&&this._headerBackgroundColor&&(this.describe(0,0,this.rowNumbersWidth,this.headerHeight,{}),this.paint(W.headerRenderer))}renderHeaders(){let e=(this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset;this.headers.forEach(t=>{this.isInViewport(e,0,t.width,this.headerHeight)&&(this.describe(e,0,t.width,this.headerHeight,{column:t,formatted:t.displayName??``}),this.paint(t.headerRenderer)),e+=t.width}),this.scrollXOffset+this.rowNumbersWidth>0&&this.renderBrick()}getColumnHeader(e){return this.headers.get(e)}get totalHeight(){return this._dataCollection.totalHeight}refreshScrollbar(){let e=this.totalHeight+this.headerHeight;this.scrollHelper.style.height=`${e}px`;let t=0;this.headers.forEach(e=>{t+=Math.round(e.width)}),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.forceDraw())}setColumns(e){if(Array.isArray(e)){this.headers.clear(),this.cellEntries.clear();let t={width:100,valueFormatter:e=>String(e),headerRenderer:W.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.refreshScrollbar(),this.forceDraw()}}disconnectedCallback(){this.cancelRender(),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.resizeObserver?.disconnect(),this.pixelRatioQuery?.removeEventListener(`change`,this.watchPixelRatio),document.fonts?.removeEventListener(`loadingdone`,this.onFontsLoaded),clearTimeout(this.fontsTimeout)}};return window&&window.customElements&&(K(),customElements.define(`canvas-grid`,q)),q});
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}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)}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 .drawingLayer{contain:strict;width:100%;height:100%;position:absolute;top:0;left:0}canvas-grid .scrollArea{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}`,D=e=>!!e,O=e=>t=>({draw:(n,r,i)=>e(n,t,r,i)}),k=({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))}),A={createElement(e,t,...n){return e(Object.assign({},t,{children:n}))}},j=class{options;constructor(e){this.options={...e}}update(e){let t={...this.options};Object.assign(this.options,e),this.optionsUpdated(t)}optionsUpdated(e){}clearCache(){}},M=(e,t)=>{let n=e.getContext(`2d`,t);if(!n)throw Error(`2D canvas context is not available`);return n},N=class extends j{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=M(this.offCanvas),this.offCtx.lineWidth=.5,this.offCtx.strokeStyle=`rgba(255, 255, 255, 0.75)`}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}},ee=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=M(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)}},te=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?.())}},P=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))}),ne=class e extends j{static defaultOptions={layer:`background`,enableFlashing:!0,background:`#333`,flashInDuration:200,flashOutDuration:400,flashRGB:`214, 144, 13`,borderRightWidth:0,borderRightColor:`#fff`,borderBottomWidth:0,borderBottomColor:`#fff`};constructor(t={}){super({...e.defaultOptions,...t})}get layer(){return this.options.layer}isAnimating({age:e}){return 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,r=e<t?e/t:(t+n-e)/n;return Math.max(0,Math.round(r*1e3)/1e3)}draw({ctx:e,x:t,y:n,width:r,height:i,age:a}){let{background:o,flashRGB:s,borderRightWidth:c,borderRightColor:l,borderBottomWidth:u,borderBottomColor:d}=this.options,f=this.getFlashAlpha(a);A.createElement(k,null,A.createElement(P,{width:r,height:i,color:o}),f>0&&A.createElement(P,{width:r,height:i,color:`rgb(${s})`,alpha:f}),c>0&&A.createElement(P,{x:r-c,width:c,height:i,color:l}),u>0&&A.createElement(P,{y:i-u,width:r,height:u,color:d})).draw(e,t,n)}},re=/[\p{M}ᄀ-ᇿꥠ-꥿ힰ-퟿‌‍\u{10000}-\u{10ffff}]/u,F=768,I=new Intl.Segmenter,L=e=>Array.from(I.segment(e),({segment:e})=>e),R=e=>re.test(e)?L(e):e,z=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>=F)return!0;return!1},B=(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},V=(e,t)=>{let n=0;for(let r=0;r<e.length;r++)n+=t(e[r]);return n},H=4096,U=(e,t,n,r)=>{if(!e)return r;let i=e.get(t);return i?(i.available=n,i.text=r,r):(e.size>=H&&e.clear(),e.set(t,{available:n,text:r}),r)},W=(e,t,n,r,i)=>{let{measure:a,cache:o}=i,s=o?.get(e);if(s?.available===t)return s.text;let c=R(e);if(B(c,t,n,r)===c.length)return e;let l=a(e);if(l<=t)return U(o,e,t,e);let u=l/V(c,r),d=B(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 U(o,e,t,d<0||d===0&&a(n)>t?``:f(d)+n)},G=(e,t,n,r,i={measure:e=>V(R(e),r),sumIsExact:!0})=>{let a=B(e,t,n,r);return a===e.length?e:i.sumIsExact&&!z(e)?a<0?``:e.slice(0,a)+n:W(e,t,n,r,i)},K={textRendering:`auto`,fontKerning:`auto`,letterSpacing:`0px`,direction:`ltr`},ie=/^[^\p{L}]*(?=[֐-ࣿיִ-﷿ﹰ-ﻼ])\p{L}/u,q=class e extends j{static defaultOptions={...K,ellipsis:`…`,cellPadding:{top:3,right:3,bottom:3,left:3},font:`12px monospace`,color:`#fff`,isEllipsisRight:!0};fonts=new Map;measureContext=M(document.createElement(`canvas`));measuredState=``;styled=!1;constructor(t={}){super({...e.defaultOptions,...t}),this.styled=this.differsFromDefault()}differsFromDefault(){return Object.keys(K).some(e=>this.options[e]!==K[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,fitted:n,probed:!1,widthOf:e=>this.measureCharacter(r,e),exactFit:{measure:e=>this.measureString(r,e),cache:n,sumIsExact:!0}};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}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}lastMeasures=void 0;isRightToLeft(e){let{direction:t}=this.options;return t===`auto`?ie.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=G(t,u,this.options.ellipsis,d.widthOf,d.exactFit);if(f===``||a-l.top-l.bottom<=0)return;let p=this.styled&&this.isRightToLeft(f);this.styled&&(e.textRendering=this.options.textRendering,e.fontKerning=this.options.fontKerning,e.letterSpacing=this.options.letterSpacing,e.direction=p?`rtl`:`ltr`),e.font=o,e.fillStyle=this.options.color,e.textAlign=p?`right`:`left`,e.textBaseline=`middle`;let{pixelRatio:m}=this,h=p?s+n+i-l.right:s+n+l.left;e.fillText(f,Math.round(h*m)/m,Math.round((c+r+l.top+(a-l.top-l.bottom)/2)*m)/m)}element=O((e,t,n,r)=>this.paint(e,t,n,r))},ae=class e extends j{static defaultOptions={layer:`header`,background:`#333`,font:`13px monospace`,color:`#fff`,borderRightWidth:1,borderRightColor:`#fff`,borderBottomWidth:1,borderBottomColor:`#fff`};textRenderer;constructor(t={}){super({...e.defaultOptions,...t}),this.textRenderer=new q({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)}clearCache(){this.textRenderer.clearCache()}draw({ctx:e,x:t,y:n,width:r,height:i,column:a,formatted:o}){if(r===0||i===0)return;let{background:s,borderRightWidth:c,borderRightColor:l,borderBottomWidth:u,borderBottomColor:d}=this.options;A.createElement(k,null,A.createElement(P,{width:r,height:i,color:s}),c>0&&A.createElement(P,{x:r-c,width:c,height:i,color:l}),u>0&&A.createElement(P,{y:i-u,width:r,height:u,color:d}),A.createElement(this.textRenderer.element,{value:o,font:a?.headerFont,width:r,height:i})).draw(e,t,n)}},oe=class e extends j{static defaultOptions={layer:`content`,font:`12px monospace`,color:`#fff`};renderer;constructor(t={}){super({...e.defaultOptions,...t}),this.renderer=new q({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),A.createElement(this.renderer.element,{value:o,font:a?.font,width:r,height:i}).draw(e,t,n))}},J=(e,t,n)=>e===`inherit`?!t.fontSize||!t.fontFamily?n:[t.fontStyle,t.fontWeight,t.fontSize,t.fontFamily].filter(Boolean).join(` `):e,se={scrollArea:`scrollArea`},Y={background:`background`,content:`content`,header:`header`,backgroundRenderer:`background`,valueRenderer:`value`,headerRenderer:`header`},X=`canvas-grid-styles`,ce=()=>{if(document.getElementById(X))return;let e=document.createElement(`style`);e.id=X,e.textContent=E,document.head.appendChild(e)},Z=`12px monospace`,Q=`13px monospace`,$=class extends HTMLElement{fps=30;_font=Z;_headerFont=Q;headerHeight=30;cellHeight=20;cellPadding={top:3,right:3,bottom:3,left:3};showRowNumbers=!0;showHeaders=!0;rowNumbersWidth=30;ellipsis=`…`;_backgroundColor=`#333`;_headerBackgroundColor=`#222`;textColor=`#efefef`;dataStore=new w({getRowId:(e,t)=>this.getRowId(e,t),getCellHeight:()=>this.cellHeight});_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 te;cellRenderers=[Y.backgroundRenderer,Y.valueRenderer];cellBackgroundRenderer=new ne({layer:Y.background,background:this._backgroundColor,enableFlashing:!0,flashInDuration:200,flashOutDuration:400,flashRGB:`214, 144, 13`,borderRightWidth:1,borderRightColor:`#3f3f3f`,borderBottomWidth:1,borderBottomColor:`#3f3f3f`});cellValueRenderer=new oe({layer:Y.content,font:this._font,color:this.textColor});headerCellRenderer=new ae({layer:Y.header,font:this._headerFont,color:this.textColor,background:`#222`,borderRightWidth:1,borderRightColor:`#2f2f2f`,borderBottomWidth:1,borderBottomColor:`#2f2f2f`});loadingIndicator;cell;placeholderState={};throttleTransation=(0,d.default)(()=>{let e=this.totalHeight,t=this.dataStore.flush();e!==this.totalHeight&&this.refreshScrollbar(),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(Y.background,{alpha:!1}),this.addLayer(Y.content),this.addLayer(Y.header),this.registerRenderer(Y.backgroundRenderer,this.cellBackgroundRenderer),this.registerRenderer(Y.valueRenderer,this.cellValueRenderer),this.registerRenderer(Y.headerRenderer,this.headerCellRenderer),this.loadingIndicator=new N({ctx:this.requireLayer(Y.header).ctx}),this.cell={ctx:this.requireLayer(Y.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,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(Y.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 ee(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=se.scrollArea,e.appendChild(this.scrollHelper),e}set font(e){this._font!==e&&(this._font=e,this.cellValueRenderer.font=J(e,getComputedStyle(this),Z))}get font(){return this._font}set headerFont(e){this._headerFont!==e&&(this._headerFont=e,this.headerCellRenderer.font=J(e,getComputedStyle(this),Q))}get headerFont(){return this._headerFont}textStyle={...K};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 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.updateLastRender(),this.refreshFonts(),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),t=(0,d.default)((t,n)=>{this.scrollXOffset=Math.round(n),this.scrollYOffset=Math.round(t),e(),this.requestRender()},10);this.scrollArea.addEventListener(`scroll`,()=>{let{scrollTop:e,scrollLeft:n}=this.scrollArea;this.isScrolling=!0,t(e,n)})}fontsTimeout=void 0;onVisibilityChange=()=>{document.visibilityState===`hidden`?this.cancelRender():this.resize()};refreshFonts(){this.cellValueRenderer.font=J(this._font,getComputedStyle(this),Z),this.headerCellRenderer.font=J(this._headerFont,getComputedStyle(this),Q),this.renderers.clearCaches(),this.resize()}onFontsLoaded=()=>this.refreshFonts();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(){this.animationFrame=void 0,new Date().valueOf()-this.lastRender<1e3/this.fps?this.requestRender():(this.draw(),this.updateLastRender())}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,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;let r=this._dataCollection.length===0;if((e||this.hasXScrolled())&&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(t.index*t.width+(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.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:a,id:l,x:d,store:f}of s){let s=f?.get(u);if(s===void 0)continue;let p=e[l]??={value:void 0,formatted:void 0,animating:!1,state:{}},m=p.formatted!==void 0&&p.value===s?p.formatted:a.valueFormatter(s),h=p.formatted!==m,g=f?.getUpdatedAt(u),{cell:_}=this;_.x=d,_.y=c,_.width=a.width,_.height=o.height,_.row=i,_.column=a,_.value=s,_.formatted=m,_.updatedAt=g,_.age=g===void 0?1/0:t-g,_.valueChanged=h,_.forced=n,_.state=p.state;let v=a.renderers??this.cellRenderers,y=this.isAnimating(v);(n||h||y||p.animating)&&this.paintAll(v),p.animating=y,p.value=s,p.formatted=m,r||=y}}}(this.scrollYOffset>0||this.scrollXOffset>0)&&this.renderBrick(),this.prevScrollYOffset=this.scrollYOffset,this.prevScrollXOffset=this.scrollXOffset,r&&this.requestRender()}getVisibleColumns(e){let t=[],n=e;return this.headers.forEach((e,r)=>{this.isInViewport(n,0,e.width,0)&&t.push({header:e,id:String(r),x:n,store:this.dataStore.columns.get(String(r))}),n+=Math.round(e.width)}),t}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}`}),this.paint(Y.headerRenderer))}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.forceDraw()}getSortModel(){return this.dataStore.getSortModel()}renderBrick(){this.showHeaders&&this.showRowNumbers&&this._headerBackgroundColor&&(this.describe(0,0,this.rowNumbersWidth,this.headerHeight,{}),this.paint(Y.headerRenderer))}renderHeaders(){let e=(this.showRowNumbers?this.rowNumbersWidth:0)-this.scrollXOffset;this.headers.forEach(t=>{this.isInViewport(e,0,t.width,this.headerHeight)&&(this.describe(e,0,t.width,this.headerHeight,{column:t,formatted:t.displayName??``}),this.paint(t.headerRenderer)),e+=t.width}),this.scrollXOffset+this.rowNumbersWidth>0&&this.renderBrick()}getColumnHeader(e){return this.headers.get(e)}get totalHeight(){return this._dataCollection.totalHeight}refreshScrollbar(){let e=this.totalHeight+this.headerHeight;this.scrollHelper.style.height=`${e}px`;let t=0;this.headers.forEach(e=>{t+=Math.round(e.width)}),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.forceDraw())}setColumns(e){if(Array.isArray(e)){this.headers.clear(),this.cellEntries.clear();let t={width:100,valueFormatter:e=>String(e),headerRenderer:Y.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.refreshScrollbar(),this.forceDraw()}}disconnectedCallback(){this.cancelRender(),document.removeEventListener(`visibilitychange`,this.onVisibilityChange),this.resizeObserver?.disconnect(),this.pixelRatioQuery?.removeEventListener(`change`,this.watchPixelRatio),document.fonts?.removeEventListener(`loadingdone`,this.onFontsLoaded),clearTimeout(this.fontsTimeout)}};return window&&window.customElements&&(ce(),customElements.define(`canvas-grid`,$)),$});
2
2
  //# sourceMappingURL=web-component.js.map