@koeroesi86/canvas-grid 26.11.6 → 26.11.7
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/build/types/cell-background/index.d.ts +13 -3
- package/build/types/header/index.d.ts +8 -1
- package/build/types/sort-indicator/index.d.ts +13 -0
- package/build/types/text/index.d.ts +12 -0
- package/build/types/utils/fit-text.d.ts +5 -0
- package/build/types/web-component.d.ts +16 -0
- package/build/web-component.js +1 -1
- package/build/web-component.js.map +1 -1
- package/build/web-component.mjs +207 -108
- package/build/web-component.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -15,11 +15,21 @@ export interface CellBackgroundOptions {
|
|
|
15
15
|
declare class CellBackground extends Renderer<CellBackgroundOptions> implements CellRenderer {
|
|
16
16
|
static readonly defaultOptions: CellBackgroundOptions;
|
|
17
17
|
constructor(options?: Partial<CellBackgroundOptions>);
|
|
18
|
+
/** Index of the row under the pointer, set by the grid through `hover`. */
|
|
19
|
+
hoveredRowIndex: number | undefined;
|
|
20
|
+
/** Rows whose highlight is fading in or out, or fully on. */
|
|
21
|
+
private readonly hoverFades;
|
|
22
|
+
private get hoverDuration();
|
|
23
|
+
/** Moves the highlight to the given row (or none); the rows involved fade from where they are. */
|
|
24
|
+
hover(index: number | undefined, now?: number): void;
|
|
25
|
+
private startFade;
|
|
26
|
+
/** How much of the highlight a row shows, from 0 to 1; finished fade-outs are forgotten. */
|
|
27
|
+
private getHoverFraction;
|
|
18
28
|
get layer(): string;
|
|
19
29
|
/** Cells flash after their value changed, until the flash has faded out. */
|
|
20
|
-
isAnimating({ age }: Readonly<CellContext>): boolean;
|
|
21
|
-
/** Flash opacity for a cell updated `age` ms ago:
|
|
30
|
+
isAnimating({ age, row, now }: Readonly<CellContext>): boolean;
|
|
31
|
+
/** Flash opacity for a cell updated `age` ms ago: eases in, eases out, then 0. A steady highlight with reduced motion. */
|
|
22
32
|
private getFlashAlpha;
|
|
23
|
-
draw({ ctx, x, y, width, height, age }: Readonly<CellContext>): void;
|
|
33
|
+
draw({ ctx, x, y, width, height, age, row, now }: Readonly<CellContext>): void;
|
|
24
34
|
}
|
|
25
35
|
export default CellBackground;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Renderer from '../utils/renderer';
|
|
2
2
|
import type { TextStyle } from '../text';
|
|
3
|
-
import type { CellContext, CellRenderer } from '../types';
|
|
3
|
+
import type { CellContext, CellRenderer, SortDirection } from '../types';
|
|
4
4
|
export interface HeaderOptions {
|
|
5
5
|
layer: string;
|
|
6
6
|
background: string;
|
|
@@ -14,6 +14,13 @@ export interface HeaderOptions {
|
|
|
14
14
|
declare class HeaderRenderer extends Renderer<HeaderOptions> implements CellRenderer {
|
|
15
15
|
static readonly defaultOptions: HeaderOptions;
|
|
16
16
|
private readonly textRenderer;
|
|
17
|
+
/** Sort direction by column id, set by the grid; sorted headers show an arrow. */
|
|
18
|
+
private readonly sortDirections;
|
|
19
|
+
/** Shows the arrows of the columns in the sort model; the grid redraws the headers afterwards. */
|
|
20
|
+
setSortModel(model: readonly {
|
|
21
|
+
columnId: string | number;
|
|
22
|
+
direction?: SortDirection;
|
|
23
|
+
}[]): void;
|
|
17
24
|
constructor(options?: Partial<HeaderOptions>);
|
|
18
25
|
get layer(): string;
|
|
19
26
|
set font(font: string);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { SortDirection } from '../types';
|
|
2
|
+
export interface SortIndicatorProps {
|
|
3
|
+
/** Width and height of the area the arrow is centred in, relative to the draw origin. */
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
direction: SortDirection;
|
|
7
|
+
color: string;
|
|
8
|
+
}
|
|
9
|
+
/** Width of the arrow's area, for the header to keep its text clear of it. */
|
|
10
|
+
export declare const SORT_INDICATOR_AREA = 18;
|
|
11
|
+
/** Small filled triangle at the right end of a header: pointing up for ascending, down for descending. */
|
|
12
|
+
declare const SortIndicator: import("../utils/jsx").Component<SortIndicatorProps>;
|
|
13
|
+
export default SortIndicator;
|
|
@@ -12,6 +12,11 @@ export interface TextStyle {
|
|
|
12
12
|
* so mixed data works. Right-to-left text is aligned to the right of the cell.
|
|
13
13
|
*/
|
|
14
14
|
direction: 'ltr' | 'rtl' | 'auto';
|
|
15
|
+
/**
|
|
16
|
+
* What happens to text wider than its cell. `'clip'` cuts it off at the cell edge, which needs no measuring.
|
|
17
|
+
* `'ellipsis'` shortens it and ends it with the ellipsis, which means measuring the text.
|
|
18
|
+
*/
|
|
19
|
+
textOverflow: 'clip' | 'ellipsis';
|
|
15
20
|
}
|
|
16
21
|
export interface TextOptions extends TextStyle {
|
|
17
22
|
ellipsis: string;
|
|
@@ -51,10 +56,17 @@ declare class TextRenderer extends Renderer<TextOptions> {
|
|
|
51
56
|
private prepareMeasuring;
|
|
52
57
|
/** Width of one character in a font, measured once. */
|
|
53
58
|
private measureCharacter;
|
|
59
|
+
/** What a pair of characters is wider than the two alone, measured once per pair: negative for kerned pairs such as "AV". */
|
|
60
|
+
private measureKerning;
|
|
54
61
|
/** Width of a string as the browser lays it out: includes kerning, ligatures and joined scripts. */
|
|
55
62
|
private measureString;
|
|
56
63
|
/** Sum of the character widths in the renderer's font: exact for monospace fonts, a close upper bound for most others. */
|
|
57
64
|
getTextWidth(text: string): number;
|
|
65
|
+
/**
|
|
66
|
+
* Whether simple text surely fits: the cached character widths add up to at most `available`. Kerning only narrows
|
|
67
|
+
* text, so a fit by the sum is a fit. Anything past Latin (joined scripts, emoji) is not trusted and gets clipped.
|
|
68
|
+
*/
|
|
69
|
+
private fitsBySum;
|
|
58
70
|
/** The font of the cell drawn last: columns mostly share one, so the lookup by font name is skipped. */
|
|
59
71
|
private lastMeasures;
|
|
60
72
|
private isRightToLeft;
|
|
@@ -11,6 +11,11 @@ export interface ExactFit {
|
|
|
11
11
|
cache?: FitCache;
|
|
12
12
|
/** The character widths add up to the real width, as for a monospace font: Latin text then needs no measuring. */
|
|
13
13
|
sumIsExact: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* How much wider (negative: narrower) two neighbouring characters are laid out than their own widths add up to:
|
|
16
|
+
* kerning and ligatures. With it, simple Latin text is cut by arithmetic instead of by measuring.
|
|
17
|
+
*/
|
|
18
|
+
kerning?: (left: string, right: string) => number;
|
|
14
19
|
}
|
|
15
20
|
/**
|
|
16
21
|
* Cuts `text` to fit `available` pixels, ending in `ellipsis` when something was cut.
|
|
@@ -55,6 +55,7 @@ declare global {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
declare class CanvasGridComponent extends HTMLElement {
|
|
58
|
+
/** Maximum redraw rate. */
|
|
58
59
|
fps: number;
|
|
59
60
|
_font: string;
|
|
60
61
|
_headerFont: string;
|
|
@@ -136,10 +137,24 @@ declare class CanvasGridComponent extends HTMLElement {
|
|
|
136
137
|
/** Extra space after each character as a CSS length, `'0px'` by default. */
|
|
137
138
|
set letterSpacing(letterSpacing: string);
|
|
138
139
|
get letterSpacing(): string;
|
|
140
|
+
/**
|
|
141
|
+
* What happens to text wider than its cell: `'clip'` (default) cuts it off at the cell edge and measures nothing,
|
|
142
|
+
* `'ellipsis'` shortens it and ends it with an ellipsis, which means measuring the text.
|
|
143
|
+
*/
|
|
144
|
+
set textOverflow(textOverflow: TextStyle['textOverflow']);
|
|
145
|
+
get textOverflow(): TextStyle['textOverflow'];
|
|
139
146
|
/** `'ltr'` (default), `'rtl'`, or `'auto'` to pick the direction per cell from its first letter. */
|
|
140
147
|
set direction(direction: TextStyle['direction']);
|
|
141
148
|
get direction(): TextStyle['direction'];
|
|
142
149
|
connectedCallback(): void;
|
|
150
|
+
/** Rows whose cells must be redrawn because the hover highlight moved off or onto them. */
|
|
151
|
+
private hoverDirty;
|
|
152
|
+
private setHoveredRow;
|
|
153
|
+
/** Pointer position relative to the grid, kept to find the hovered row again after scrolling. */
|
|
154
|
+
private pointerY;
|
|
155
|
+
private updateHoveredRow;
|
|
156
|
+
private readonly onPointerMove;
|
|
157
|
+
private readonly onPointerLeave;
|
|
143
158
|
private fontsTimeout;
|
|
144
159
|
private readonly onVisibilityChange;
|
|
145
160
|
/**
|
|
@@ -156,6 +171,7 @@ declare class CanvasGridComponent extends HTMLElement {
|
|
|
156
171
|
requestRender(): void;
|
|
157
172
|
updateLastRender(): void;
|
|
158
173
|
render(): void;
|
|
174
|
+
private readScrollOffsets;
|
|
159
175
|
hasScrolled(): boolean;
|
|
160
176
|
hasYScrolled(): boolean;
|
|
161
177
|
hasXScrolled(): boolean;
|
package/build/web-component.js
CHANGED
|
@@ -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;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`,$)),$});
|
|
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{scrollbar-width:thin;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}`,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},ee=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}},te=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)}},ne=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?.())}},N=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))}),P=`#fff`,re=.025,ie=.06,ae=120,oe=.5,F=typeof window<`u`&&typeof window.matchMedia==`function`?window.matchMedia(`(prefers-reduced-motion: reduce)`):void 0,se=e=>e*e*(3-2*e),I=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})}hoveredRowIndex=void 0;hoverFades=new Map;get hoverDuration(){return F?.matches?0:ae}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(F?.matches)return oe;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,flashRGB:l,borderRightWidth:u,borderRightColor:d,borderBottomWidth:f,borderBottomColor:p}=this.options,m=this.getFlashAlpha(a),h=o===void 0?0:this.getHoverFraction(o.index,s)*ie;A.createElement(k,null,A.createElement(N,{width:r,height:i,color:c}),o!==void 0&&o.index%2==1&&A.createElement(N,{width:r,height:i,color:P,alpha:re}),h>0&&A.createElement(N,{width:r,height:i,color:P,alpha:h}),m>0&&A.createElement(N,{width:r,height:i,color:`rgb(${l})`,alpha:m}),u>0&&A.createElement(N,{x:r-u,width:u,height:i,color:d}),f>0&&A.createElement(N,{y:i-f,width:r,height:f,color:p})).draw(e,t,n)}},ce=/[\p{M}ᄀ-ᇿꥠ-ힰ-\u{10000}-\u{10ffff}]/u,le=768,ue=new Intl.Segmenter,de=e=>Array.from(ue.segment(e),({segment:e})=>e),L=e=>ce.test(e)?de(e):e,R=e=>{for(let t=0;t<e.length;t++)if(e.charCodeAt(t)>=le)return!0;return!1},z=(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},B=(e,t)=>{let n=0;for(let r=0;r<e.length;r++)n+=t(e[r]);return n},V=4096,H=(e,t,n,r)=>{if(!e)return r;let i=e.get(t);return i?(i.available=n,i.text=r,r):(e.size>=V&&e.clear(),e.set(t,{available:n,text:r}),r)},fe=(e,t,n,r,i)=>{let{measure:a,cache:o}=i,s=o?.get(e);if(s?.available===t)return s.text;let c=L(e);if(z(c,t,n,r)===c.length)return e;let l=a(e);if(l<=t)return H(o,e,t,e);let u=l/B(c,r),d=z(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 H(o,e,t,d<0||d===0&&a(n)>t?``:f(d)+n)},pe=(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:``},U=(e,t,n,r,i={measure:e=>B(L(e),r),sumIsExact:!0})=>{let a=z(e,t,n,r);return a===e.length?e:i.sumIsExact&&!R(e)?a<0?``:e.slice(0,a)+n:i.kerning&&!R(e)?pe(e,t,n,r,i.kerning):fe(e,t,n,r,i)},W={textRendering:`auto`,fontKerning:`auto`,letterSpacing:`0px`,direction:`ltr`,textOverflow:`clip`},me=768,he=/^[^\p{L}]*(?=[-ࣿיִ-﷿ﹰ-ﻼ])\p{L}/u,G=class e extends j{static defaultOptions={...W,ellipsis:`…`,cellPadding:{top:3,right:3,bottom:3,left:3},font:`12px sans-serif`,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(W).some(e=>e!==`textOverflow`&&this.options[e]!==W[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)>=me||(r+=n(e.charAt(i)),r>t))return!1;return!0}lastMeasures=void 0;isRightToLeft(e){let{direction:t}=this.options;return t===`auto`?he.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:U(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))},K=8,q=5,ge=.75,_e=O((e,{width:t,height:n,direction:r,color:i},a,o)=>{let s=Math.round(a+t-13),c=Math.round(o+(n-q)/2),l=r===`asc`;e.beginPath(),e.moveTo(s,l?c+q:c),e.lineTo(s+K,l?c+q:c),e.lineTo(s+K/2,l?c:c+q),e.closePath(),e.fillStyle=i,e.globalAlpha=ge,e.fill(),e.globalAlpha=1}),ve=class e extends j{static defaultOptions={layer:`header`,background:`#333`,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 G({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 s=a===void 0?void 0:this.sortDirections.get(String(a.id)),{background:c,borderRightWidth:l,borderRightColor:u,borderBottomWidth:d,borderBottomColor:f}=this.options;A.createElement(k,null,A.createElement(N,{width:r,height:i,color:c}),l>0&&A.createElement(N,{x:r-l,width:l,height:i,color:u}),d>0&&A.createElement(N,{y:i-d,width:r,height:d,color:f}),A.createElement(this.textRenderer.element,{value:o,font:a?.headerFont,width:s?r-18:r,height:i}),s&&A.createElement(_e,{width:r,height:i,direction:s,color:this.options.color})).draw(e,t,n)}},ye=class e extends j{static defaultOptions={layer:`content`,font:`12px sans-serif`,color:`#fff`};renderer;constructor(t={}){super({...e.defaultOptions,...t}),this.renderer=new G({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,be={scrollArea:`scrollArea`},Y={background:`background`,content:`content`,header:`header`,backgroundRenderer:`background`,valueRenderer:`value`,headerRenderer:`header`},X=`canvas-grid-styles`,xe=()=>{if(document.getElementById(X))return;let e=document.createElement(`style`);e.id=X,e.textContent=E,document.head.appendChild(e)},Se=2,Z=`12px sans-serif`,Q=`13px sans-serif`,$=class extends HTMLElement{fps=60;_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=`#262626`;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 ne;cellRenderers=[Y.backgroundRenderer,Y.valueRenderer];cellBackgroundRenderer=new I({layer:Y.background,background:this._backgroundColor,enableFlashing:!0,flashInDuration:200,flashOutDuration:400,flashRGB:`214, 144, 13`,borderRightWidth:1,borderRightColor:`#3b3b3b`,borderBottomWidth:1,borderBottomColor:`#3b3b3b`});cellValueRenderer=new ye({layer:Y.content,font:this._font,color:this.textColor});headerCellRenderer=new ve({layer:Y.header,font:this._headerFont,color:this.textColor,background:`#262626`,borderRightWidth:1,borderRightColor:`#333`,borderBottomWidth:1,borderBottomColor:`#4a4a4a`});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 ee({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 te(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=be.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={...W};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.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);this.scrollArea.addEventListener(`pointermove`,this.onPointerMove),this.scrollArea.addEventListener(`pointerleave`,this.onPointerLeave),this.scrollArea.addEventListener(`scroll`,()=>{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=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,this.readScrollOffsets();let e=new Date().valueOf()-this.lastRender;!this.isScrolling&&e<1e3/this.fps-Se?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,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: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=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.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}}}(this.scrollYOffset>0||this.scrollXOffset>0)&&this.renderBrick(),this.hoverDirty=[],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.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(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&&(xe(),customElements.define(`canvas-grid`,$)),$});
|
|
2
2
|
//# sourceMappingURL=web-component.js.map
|