@koeroesi86/canvas-grid 26.11.3 → 26.11.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/types/text/index.d.ts +12 -4
- package/build/types/utils/column-store.d.ts +2 -0
- package/build/types/utils/data-store.d.ts +3 -0
- package/build/types/utils/fit-text.d.ts +6 -0
- package/build/web-component.js +1 -1
- package/build/web-component.js.map +1 -1
- package/build/web-component.mjs +125 -160
- package/build/web-component.mjs.map +1 -1
- package/package.json +2 -5
- package/build/types/character/index.d.ts +0 -21
|
@@ -14,17 +14,25 @@ export interface TextOptions {
|
|
|
14
14
|
}
|
|
15
15
|
declare class TextRenderer extends Renderer<TextOptions> {
|
|
16
16
|
static readonly defaultOptions: TextOptions;
|
|
17
|
-
private readonly
|
|
17
|
+
private readonly characterWidths;
|
|
18
|
+
private readonly measureContext;
|
|
19
|
+
private measuredFont;
|
|
18
20
|
constructor(options?: Partial<TextOptions>);
|
|
19
21
|
set font(font: string);
|
|
20
22
|
get font(): string;
|
|
21
23
|
set color(color: string);
|
|
22
24
|
get color(): string;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
+
/** Text is drawn straight into the layer, whose transform already scales it to the device pixel ratio. */
|
|
26
|
+
pixelRatio: number;
|
|
25
27
|
clearCache(): void;
|
|
28
|
+
/** Width of one character in the current font, measured once. */
|
|
29
|
+
private measureCharacter;
|
|
26
30
|
getTextWidth(text: string): number;
|
|
27
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Draws the text clipped with an ellipsis; `(x, y)` is the offset of the text box from `(originX, originY)`.
|
|
33
|
+
* The whole string is drawn with one `fillText`: recording one command per cell is much cheaper than
|
|
34
|
+
* one `drawImage` per character, and the browser keeps its own glyph cache.
|
|
35
|
+
*/
|
|
28
36
|
paint(ctx: CanvasRenderingContext2D, { value, x, y, width, height }: RenderProps, originX: number, originY: number): void;
|
|
29
37
|
readonly element: import("../utils/jsx").Component<RenderProps>;
|
|
30
38
|
}
|
|
@@ -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,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cuts `text` to fit `available` pixels, ending in `ellipsis` when something was cut.
|
|
3
|
+
* `widthOf` gives the width of one character; the width of the text is the sum of its characters.
|
|
4
|
+
*/
|
|
5
|
+
declare const fitText: (text: string, available: number, ellipsis: string, widthOf: (character: string) => number) => string;
|
|
6
|
+
export default fitText;
|
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;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}},P=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)}},F=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?.())}},I=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))}),L=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(I,{width:r,height:i,color:o}),f>0&&A.createElement(I,{width:r,height:i,color:`rgb(${s})`,alpha:f}),c>0&&A.createElement(I,{x:r-c,width:c,height:i,color:l}),u>0&&A.createElement(I,{y:i-u,width:r,height:u,color:d})).draw(e,t,n)}},R=(e,t,n,r)=>{let i=0,a=0;for(;a<e.length;){let n=r(e.charAt(a));if(i+n>t)break;i+=n,a++}if(a===e.length)return e;let o=r(n);for(;a>0&&i+o>t;)a--,i-=r(e.charAt(a));return i+o>t?``:e.slice(0,a)+n},z=class e extends j{static defaultOptions={ellipsis:`…`,cellPadding:{top:3,right:3,bottom:3,left:3},font:`12px monospace`,color:`#fff`,isEllipsisRight:!0};characterWidths=new Map;measureContext=M(document.createElement(`canvas`));measuredFont=``;constructor(t={}){super({...e.defaultOptions,...t})}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}pixelRatio=1;clearCache(){this.characterWidths.clear(),this.measuredFont=``}measureCharacter(e){let t=this.characterWidths.get(e);if(t!==void 0)return t;this.measuredFont!==this.options.font&&(this.measureContext.font=this.options.font,this.measuredFont=this.options.font);let n=this.measureContext.measureText(e).width;return this.characterWidths.set(e,n),n}getTextWidth(e){let t=0;for(let n=0;n<e.length;n++)t+=this.measureCharacter(e.charAt(n));return t}paint(e,{value:t=``,x:n=0,y:r=0,width:i=0,height:a=0},o,s){let{cellPadding:c}=this.options,l=R(t,i-c.left-c.right,this.options.ellipsis,e=>this.measureCharacter(e));l===``||a-c.top-c.bottom<=0||(e.font=this.options.font,e.fillStyle=this.options.color,e.textAlign=`left`,e.textBaseline=`top`,e.fillText(l,o+n+c.left,s+r+c.top))}element=O((e,t,n,r)=>this.paint(e,t,n,r))},B=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 z({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(I,{width:r,height:i,color:o}),s>0&&A.createElement(I,{x:r-s,width:s,height:i,color:c}),l>0&&A.createElement(I,{y:i-l,width:r,height:l,color:u}),A.createElement(this.textRenderer.element,{value:a,width:r,height:i})).draw(e,t,n)}},V=class e extends j{static defaultOptions={layer:`content`,font:`12px monospace`,color:`#fff`};renderer;constructor(t={}){super({...e.defaultOptions,...t}),this.renderer=new z({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))}},H={scrollArea:`scrollArea`},U={background:`background`,content:`content`,header:`header`,backgroundRenderer:`background`,valueRenderer:`value`,headerRenderer:`header`},W=`canvas-grid-styles`,G=()=>{if(document.getElementById(W))return;let e=document.createElement(`style`);e.id=W,e.textContent=E,document.head.appendChild(e)},K=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 F;cellRenderers=[U.backgroundRenderer,U.valueRenderer];cellBackgroundRenderer=new L({layer:U.background,background:this._backgroundColor,enableFlashing:!0,flashInDuration:200,flashOutDuration:400,flashRGB:`214, 144, 13`,borderRightWidth:1,borderRightColor:`#3f3f3f`,borderBottomWidth:1,borderBottomColor:`#3f3f3f`});cellValueRenderer=new V({layer:U.content,font:this._font,color:this.textColor});headerCellRenderer=new B({layer:U.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(U.background,{alpha:!1}),this.addLayer(U.content),this.addLayer(U.header),this.registerRenderer(U.backgroundRenderer,this.cellBackgroundRenderer),this.registerRenderer(U.valueRenderer,this.cellValueRenderer),this.registerRenderer(U.headerRenderer,this.headerCellRenderer),this.loadingIndicator=new N({ctx:this.requireLayer(U.header).ctx}),this.cell={ctx:this.requireLayer(U.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(U.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 P(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=H.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(U.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(U.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:U.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&&(G(),customElements.define(`canvas-grid`,K)),K});
|
|
2
2
|
//# sourceMappingURL=web-component.js.map
|