@koeroesi86/canvas-grid 1.0.15 → 26.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.md +27 -0
  2. package/build/types/cell-background/index.d.ts +25 -0
  3. package/build/types/cell-value/index.d.ts +21 -0
  4. package/build/types/character/index.d.ts +21 -0
  5. package/build/types/header/index.d.ts +25 -0
  6. package/build/types/rectangle/index.d.ts +12 -0
  7. package/build/types/text/index.d.ts +31 -0
  8. package/build/types/types.d.ts +87 -0
  9. package/build/types/utils/canvas.d.ts +1 -0
  10. package/build/types/utils/collection.d.ts +18 -0
  11. package/build/types/utils/column-store.d.ts +16 -0
  12. package/build/types/utils/data-store.d.ts +49 -0
  13. package/build/types/utils/jsx.d.ts +40 -0
  14. package/build/types/utils/layer.d.ts +26 -0
  15. package/build/types/utils/loading.d.ts +17 -0
  16. package/build/types/utils/lru-cache.d.ts +11 -0
  17. package/build/types/utils/renderer-registry.d.ts +13 -0
  18. package/build/types/utils/renderer.d.ts +26 -0
  19. package/build/types/utils/row-store.d.ts +37 -0
  20. package/build/types/utils/selectors.d.ts +3 -0
  21. package/build/types/web-component.d.ts +189 -0
  22. package/build/web-component.js +1 -732
  23. package/build/web-component.js.map +1 -1
  24. package/build/web-component.mjs +1226 -0
  25. package/build/web-component.mjs.map +1 -0
  26. package/package.json +32 -32
  27. package/.babelrc +0 -14
  28. package/.eslintrc +0 -7
  29. package/.github/CODEOWNERS +0 -1
  30. package/.github/SECURITY.md +0 -9
  31. package/.github/dependabot.yml +0 -11
  32. package/.github/workflows/ci.yml +0 -32
  33. package/.github/workflows/codeql.yml +0 -26
  34. package/.github/workflows/publish.yml +0 -51
  35. package/components/cellBackground/index.jsx +0 -86
  36. package/components/cellValue/index.jsx +0 -80
  37. package/components/character/index.jsx +0 -82
  38. package/components/component.scss +0 -45
  39. package/components/example.js +0 -56
  40. package/components/header/index.jsx +0 -100
  41. package/components/rectangle/index.jsx +0 -65
  42. package/components/text/index.jsx +0 -131
  43. package/components/utils/collection.js +0 -58
  44. package/components/utils/drawingLayer.js +0 -66
  45. package/components/utils/jsx.js +0 -57
  46. package/components/utils/loading.js +0 -58
  47. package/components/utils/renderer.js +0 -45
  48. package/components/utils/selectors.js +0 -13
  49. package/components/web-component.js +0 -582
  50. package/config/htmlGenerator.js +0 -36
  51. package/nodemon.json +0 -5
  52. package/public/index.html +0 -29
  53. package/scripts/build.js +0 -30
  54. package/scripts/dev.js +0 -64
  55. package/server/example.js +0 -59
  56. package/server/exampleServe.js +0 -3
  57. package/webpack.config.js +0 -151
@@ -0,0 +1,1226 @@
1
+ // \0rolldown/runtime.js
2
+ 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) => {
3
+ 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, {
4
+ get: ((e) => i[e]).bind(null, d),
5
+ enumerable: !(s = n(i, d)) || s.enumerable
6
+ });
7
+ return e;
8
+ }, c = (n, r, o) => (o = n == null ? {} : e(i(n)), s(r || !n || !n.__esModule || !a.call(n, "default") ? t(o, "default", {
9
+ value: n,
10
+ enumerable: !0
11
+ }) : o, n)), l = /* @__PURE__ */ o(((e, t) => {
12
+ 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() {
13
+ return d.Date.now();
14
+ };
15
+ function g(e, t, r) {
16
+ var i, a, o, s, c, l, u = 0, d = !1, f = !1, g = !0;
17
+ if (typeof e != "function") throw TypeError(n);
18
+ 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);
19
+ function _(t) {
20
+ var n = i, r = a;
21
+ return i = a = void 0, u = t, s = e.apply(r, n), s;
22
+ }
23
+ function y(e) {
24
+ return u = e, c = setTimeout(C, t), d ? _(e) : s;
25
+ }
26
+ function b(e) {
27
+ var n = e - l, r = e - u, i = t - n;
28
+ return f ? m(i, o - r) : i;
29
+ }
30
+ function S(e) {
31
+ var n = e - l, r = e - u;
32
+ return l === void 0 || n >= t || n < 0 || f && r >= o;
33
+ }
34
+ function C() {
35
+ var e = h();
36
+ if (S(e)) return w(e);
37
+ c = setTimeout(C, b(e));
38
+ }
39
+ function w(e) {
40
+ return c = void 0, g && i ? _(e) : (i = a = void 0, s);
41
+ }
42
+ function T() {
43
+ c !== void 0 && clearTimeout(c), u = 0, i = l = a = c = void 0;
44
+ }
45
+ function E() {
46
+ return c === void 0 ? s : w(h());
47
+ }
48
+ function D() {
49
+ var e = h(), n = S(e);
50
+ if (i = arguments, a = this, l = e, n) {
51
+ if (c === void 0) return y(l);
52
+ if (f) return c = setTimeout(C, t), _(l);
53
+ }
54
+ return c === void 0 && (c = setTimeout(C, t)), s;
55
+ }
56
+ return D.cancel = T, D.flush = E, D;
57
+ }
58
+ function _(e, t, r) {
59
+ var i = !0, a = !0;
60
+ if (typeof e != "function") throw TypeError(n);
61
+ return v(r) && (i = "leading" in r ? !!r.leading : i, a = "trailing" in r ? !!r.trailing : a), g(e, t, {
62
+ leading: i,
63
+ maxWait: t,
64
+ trailing: a
65
+ });
66
+ }
67
+ function v(e) {
68
+ var t = typeof e;
69
+ return !!e && (t == "object" || t == "function");
70
+ }
71
+ function y(e) {
72
+ return !!e && typeof e == "object";
73
+ }
74
+ function b(e) {
75
+ return typeof e == "symbol" || y(e) && f.call(e) == "[object Symbol]";
76
+ }
77
+ function x(e) {
78
+ if (typeof e == "number") return e;
79
+ if (b(e)) return r;
80
+ if (v(e)) {
81
+ var t = typeof e.valueOf == "function" ? e.valueOf() : e;
82
+ e = v(t) ? t + "" : t;
83
+ }
84
+ if (typeof e != "string") return e === 0 ? e : +e;
85
+ e = e.replace(i, "");
86
+ var n = o.test(e);
87
+ return n || s.test(e) ? c(e.slice(2), n ? 2 : 8) : a.test(e) ? r : +e;
88
+ }
89
+ t.exports = _;
90
+ })), u = /* @__PURE__ */ o(((e, t) => {
91
+ 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() {
92
+ return u.Date.now();
93
+ };
94
+ function h(e, t, n) {
95
+ var r, i, a, o, s, c, l = 0, u = !1, d = !1, h = !0;
96
+ if (typeof e != "function") throw TypeError("Expected a function");
97
+ 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);
98
+ function _(t) {
99
+ var n = r, a = i;
100
+ return r = i = void 0, l = t, o = e.apply(a, n), o;
101
+ }
102
+ function v(e) {
103
+ return l = e, s = setTimeout(S, t), u ? _(e) : o;
104
+ }
105
+ function b(e) {
106
+ var n = e - c, r = e - l, i = t - n;
107
+ return d ? p(i, a - r) : i;
108
+ }
109
+ function x(e) {
110
+ var n = e - c, r = e - l;
111
+ return c === void 0 || n >= t || n < 0 || d && r >= a;
112
+ }
113
+ function S() {
114
+ var e = m();
115
+ if (x(e)) return C(e);
116
+ s = setTimeout(S, b(e));
117
+ }
118
+ function C(e) {
119
+ return s = void 0, h && r ? _(e) : (r = i = void 0, o);
120
+ }
121
+ function w() {
122
+ s !== void 0 && clearTimeout(s), l = 0, r = c = i = s = void 0;
123
+ }
124
+ function T() {
125
+ return s === void 0 ? o : C(m());
126
+ }
127
+ function E() {
128
+ var e = m(), n = x(e);
129
+ if (r = arguments, i = this, c = e, n) {
130
+ if (s === void 0) return v(c);
131
+ if (d) return s = setTimeout(S, t), _(c);
132
+ }
133
+ return s === void 0 && (s = setTimeout(S, t)), o;
134
+ }
135
+ return E.cancel = w, E.flush = T, E;
136
+ }
137
+ function g(e) {
138
+ var t = typeof e;
139
+ return !!e && (t == "object" || t == "function");
140
+ }
141
+ function _(e) {
142
+ return !!e && typeof e == "object";
143
+ }
144
+ function v(e) {
145
+ return typeof e == "symbol" || _(e) && d.call(e) == "[object Symbol]";
146
+ }
147
+ function y(e) {
148
+ if (typeof e == "number") return e;
149
+ if (v(e)) return n;
150
+ if (g(e)) {
151
+ var t = typeof e.valueOf == "function" ? e.valueOf() : e;
152
+ e = g(t) ? t + "" : t;
153
+ }
154
+ if (typeof e != "string") return e === 0 ? e : +e;
155
+ e = e.replace(r, "");
156
+ var c = a.test(e);
157
+ return c || o.test(e) ? s(e.slice(2), c ? 2 : 8) : i.test(e) ? n : +e;
158
+ }
159
+ t.exports = h;
160
+ })), d = /* @__PURE__ */ c(l()), f = /* @__PURE__ */ c(u()), p = class {
161
+ entries = /* @__PURE__ */ new Map();
162
+ constructor() {
163
+ this.get = this.get.bind(this), this.set = this.set.bind(this), this.clear = this.clear.bind(this), this.forEach = this.forEach.bind(this);
164
+ }
165
+ get keys() {
166
+ return Array.from(this.entries.values(), (e) => e.key);
167
+ }
168
+ get(e) {
169
+ return this.entries.get(String(e))?.value;
170
+ }
171
+ set(e, t) {
172
+ let n = this.entries.get(String(e));
173
+ n ? n.value = t : this.entries.set(String(e), {
174
+ key: e,
175
+ value: t
176
+ });
177
+ }
178
+ add(e) {
179
+ this.set(this.entries.size, e);
180
+ }
181
+ delete(e) {
182
+ this.entries.delete(String(e));
183
+ }
184
+ clear(e) {
185
+ typeof e == "function" ? this.entries.forEach(({ key: t, value: n }, r) => {
186
+ e(n, t) && this.entries.delete(r);
187
+ }) : this.entries.clear();
188
+ }
189
+ forEach(e) {
190
+ this.entries.forEach(({ key: t, value: n }) => e(n, t));
191
+ }
192
+ get length() {
193
+ return this.entries.size;
194
+ }
195
+ }, m = class {
196
+ values;
197
+ updatedAt = void 0;
198
+ constructor(e = 0) {
199
+ this.values = Array(e).fill(void 0);
200
+ }
201
+ get(e) {
202
+ return this.values[e];
203
+ }
204
+ getUpdatedAt(e) {
205
+ return this.updatedAt?.[e] || void 0;
206
+ }
207
+ set(e, t, n) {
208
+ for (; this.values.length < e;) this.values.push(void 0);
209
+ if (this.values[e] = t, n !== void 0 || this.updatedAt !== void 0) {
210
+ for (this.updatedAt ??= Array(this.values.length).fill(0); this.updatedAt.length < this.values.length;) this.updatedAt.push(0);
211
+ this.updatedAt[e] = n ?? 0;
212
+ }
213
+ }
214
+ removeSlots(e) {
215
+ if (e.length === 0) return;
216
+ let t = (t) => {
217
+ let n = 0, r = 0;
218
+ for (let i = 0; i < t.length; i++) r < e.length && e[r] === i ? r++ : t[n++] = t[i];
219
+ t.length = n;
220
+ };
221
+ t(this.values), this.updatedAt && t(this.updatedAt);
222
+ }
223
+ }, h = class {
224
+ items = [];
225
+ indexById = /* @__PURE__ */ new Map();
226
+ tops = [];
227
+ end = 0;
228
+ get length() {
229
+ return this.items.length;
230
+ }
231
+ get totalHeight() {
232
+ return this.end;
233
+ }
234
+ get keys() {
235
+ return this.items.map((e) => e.id);
236
+ }
237
+ get(e) {
238
+ let t = this.indexById.get(String(e));
239
+ return t === void 0 ? void 0 : this.items[t];
240
+ }
241
+ at(e) {
242
+ return this.items[e];
243
+ }
244
+ topOf(e) {
245
+ return this.tops[e] ?? this.end;
246
+ }
247
+ indexAt(e) {
248
+ if (e <= 0) return 0;
249
+ if (e >= this.end) return this.length;
250
+ let t = 0, n = this.items.length - 1;
251
+ for (; t < n;) {
252
+ let r = Math.ceil((t + n) / 2);
253
+ this.tops[r] <= e ? t = r : n = r - 1;
254
+ }
255
+ return t;
256
+ }
257
+ set(e) {
258
+ let t = this.indexById.get(String(e.id));
259
+ if (t !== void 0) {
260
+ this.items[t] = {
261
+ ...e,
262
+ index: t,
263
+ slot: this.items[t].slot
264
+ }, this.reindexFrom(t);
265
+ return;
266
+ }
267
+ let n = this.items.length;
268
+ this.items.push({
269
+ ...e,
270
+ index: n,
271
+ slot: n
272
+ }), this.indexById.set(String(e.id), n), this.tops.push(this.end), this.end += Math.round(e.height);
273
+ }
274
+ removeMany(e) {
275
+ let t = /* @__PURE__ */ new Set();
276
+ if (e.forEach((e) => {
277
+ let n = this.get(e);
278
+ n && t.add(n);
279
+ }), t.size === 0) return [];
280
+ let n = Array.from(t, (e) => e.slot).sort((e, t) => e - t), r = Array.from(t).reduce((e, t) => Math.min(e, t.index), Infinity);
281
+ t.forEach((e) => this.indexById.delete(String(e.id))), this.items = this.items.filter((e) => !t.has(e));
282
+ let i = new Int32Array(this.items.length + n.length);
283
+ for (let e = 0, t = 0; e < i.length; e++) n[t] === e && t++, i[e] = t;
284
+ return this.items.forEach((e) => {
285
+ e.slot -= i[e.slot];
286
+ }), this.reindexFrom(r), n;
287
+ }
288
+ sort(e) {
289
+ this.items.sort(e), this.reindexFrom(0);
290
+ }
291
+ clear() {
292
+ this.items = [], this.indexById.clear(), this.tops = [], this.end = 0;
293
+ }
294
+ reindexFrom(e) {
295
+ this.tops.length = this.items.length;
296
+ let t = e === 0 ? 0 : this.tops[e - 1] + Math.round(this.items[e - 1].height);
297
+ for (let n = e; n < this.items.length; n++) {
298
+ let e = this.items[n];
299
+ e.index = n, this.indexById.set(String(e.id), n), this.tops[n] = t, t += Math.round(e.height);
300
+ }
301
+ this.end = t;
302
+ }
303
+ }, g = () => (/* @__PURE__ */ new Date()).valueOf(), _ = (e, t) => e.id, v = new Intl.Collator(), y = (e) => e == null ? 3 : typeof e == "number" || typeof e == "bigint" ? 0 : typeof e == "string" ? 1 : 2, b = (e, t) => {
304
+ let n = y(e) - y(t);
305
+ return n === 0 ? y(e) === 3 ? 0 : y(e) === 0 ? Number(e) - Number(t) : v.compare(String(e), String(t)) : n;
306
+ }, x = class {
307
+ rows = new h();
308
+ columns = /* @__PURE__ */ new Map();
309
+ pending = [];
310
+ sortModel = [];
311
+ sortDirty = !1;
312
+ environment;
313
+ constructor(e) {
314
+ this.environment = e;
315
+ }
316
+ get hasPending() {
317
+ return this.pending.length > 0;
318
+ }
319
+ getSortModel() {
320
+ return this.sortModel;
321
+ }
322
+ setSortModel(e) {
323
+ this.sortModel = [...e], this.sort();
324
+ }
325
+ getValue(e, t) {
326
+ let n = this.rows.get(e);
327
+ return n ? this.columns.get(String(t))?.get(n.slot) : void 0;
328
+ }
329
+ getUpdatedAt(e, t) {
330
+ let n = this.rows.get(e);
331
+ return n ? this.columns.get(String(t))?.getUpdatedAt(n.slot) : void 0;
332
+ }
333
+ queueUpdate(e) {
334
+ this.pending.push({
335
+ type: "update",
336
+ row: e
337
+ });
338
+ }
339
+ queueRemove(e) {
340
+ this.pending.push({
341
+ type: "remove",
342
+ row: e
343
+ });
344
+ }
345
+ clear() {
346
+ this.rows.clear(), this.columns.clear();
347
+ }
348
+ setRows(e) {
349
+ this.pending = [], this.clear(), e.forEach((e, t) => this.addRow(this.environment.getRowId(e, t), e, void 0)), this.sort();
350
+ }
351
+ flush(e = g()) {
352
+ let t = this.pending;
353
+ this.pending = [];
354
+ let n = [], r = !1, i = () => {
355
+ r = this.removeRows(n) || r, n.length = 0;
356
+ };
357
+ return t.forEach(({ type: t, row: r }) => {
358
+ t === "remove" ? n.push(this.environment.getRowId(r)) : (i(), this.applyUpdate(r, e));
359
+ }), i(), this.sortDirty ? (this.sort(), !0) : r;
360
+ }
361
+ column(e) {
362
+ let t = this.columns.get(e);
363
+ return t || (t = new m(this.rows.length), this.columns.set(e, t)), t;
364
+ }
365
+ addRow(e, t, n) {
366
+ this.rows.set({
367
+ id: e,
368
+ height: this.environment.getCellHeight()
369
+ });
370
+ let r = this.rows.get(e)?.slot ?? 0;
371
+ Object.keys(t).forEach((e) => this.column(e).set(r, t[e], n)), this.markSortDirty(Object.keys(t));
372
+ }
373
+ removeRows(e) {
374
+ if (e.length === 0) return !1;
375
+ let t = this.rows.removeMany(e);
376
+ return this.columns.forEach((e) => e.removeSlots(t)), t.length > 0;
377
+ }
378
+ applyUpdate(e, t) {
379
+ let n = this.environment.getRowId(e), r = this.rows.get(n);
380
+ r ? Object.keys(e).forEach((n) => this.applyValue(r.slot, n, e[n], t)) : this.addRow(n, e, t);
381
+ }
382
+ applyValue(e, t, n, r) {
383
+ let i = this.column(t), a = i.get(e);
384
+ a !== n && (i.set(e, n, a === void 0 ? void 0 : r), this.markSortDirty([t]));
385
+ }
386
+ markSortDirty(e) {
387
+ this.sortModel.some(({ columnId: t }) => e.includes(String(t))) && (this.sortDirty = !0);
388
+ }
389
+ sort() {
390
+ this.sortDirty = !1;
391
+ let e = this.sortModel.map(({ columnId: e, direction: t = "asc", compare: n = b }) => ({
392
+ values: this.columns.get(String(e))?.values,
393
+ compare: n,
394
+ sign: t === "desc" ? -1 : 1
395
+ }));
396
+ this.rows.sort((t, n) => {
397
+ for (let { values: r, compare: i, sign: a } of e) {
398
+ let e = r ? i(r[t.slot], r[n.slot]) : 0;
399
+ if (e !== 0) return e * a;
400
+ }
401
+ return t.slot - n.slot;
402
+ });
403
+ }
404
+ }, S = class {
405
+ entries = /* @__PURE__ */ new Map();
406
+ limit;
407
+ constructor(e) {
408
+ this.limit = e;
409
+ }
410
+ get(e) {
411
+ let t = this.entries.get(e);
412
+ if (t !== void 0) return this.entries.delete(e), this.entries.set(e, t), t;
413
+ }
414
+ set(e, t) {
415
+ this.entries.delete(e), this.entries.set(e, t);
416
+ let [n] = this.entries.keys();
417
+ this.entries.size > this.limit && n !== void 0 && this.entries.delete(n);
418
+ }
419
+ clear() {
420
+ this.entries.clear();
421
+ }
422
+ get size() {
423
+ return this.entries.size;
424
+ }
425
+ }, C = "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}", w = (e) => !!e, T = (e) => (t) => ({ draw: (n, r, i) => e(n, t, r, i) }), E = ({ x: e = 0, y: t = 0, children: n }) => ({ draw: (r, i, a) => [n].flat(2).filter(w).forEach((n) => n.draw(r, i + e, a + t)) }), D = { createElement(e, t, ...n) {
426
+ return e(Object.assign({}, t, { children: n }));
427
+ } }, O = class {
428
+ options;
429
+ constructor(e) {
430
+ this.options = { ...e };
431
+ }
432
+ update(e) {
433
+ let t = { ...this.options };
434
+ Object.assign(this.options, e), this.optionsUpdated(t);
435
+ }
436
+ optionsUpdated(e) {}
437
+ clearCache() {}
438
+ }, k = class extends O {
439
+ bitmaps = new S(4096);
440
+ cacheKey(e) {}
441
+ pixelRatio = 1;
442
+ clearCache() {
443
+ this.bitmaps.clear();
444
+ }
445
+ paint(e, t, n, r) {
446
+ let i = this.cacheKey(t), a = (i === void 0 ? void 0 : this.bitmaps.get(i)) ?? this.renderBitmap(t, i);
447
+ 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);
448
+ }
449
+ element = T((e, t, n, r) => this.paint(e, t, n, r));
450
+ renderBitmap(e, t) {
451
+ let n = this.render(e);
452
+ if (t === void 0 || n.width <= 0 || n.height <= 0) return n;
453
+ let r = document.createElement("canvas");
454
+ return r.width = n.width, r.height = n.height, r.getContext("2d")?.drawImage(n, 0, 0), this.bitmaps.set(t, r), r;
455
+ }
456
+ }, A = (e, t) => {
457
+ let n = e.getContext("2d", t);
458
+ if (!n) throw Error("2D canvas context is not available");
459
+ return n;
460
+ }, j = class extends O {
461
+ ctx;
462
+ offCanvas = document.createElement("canvas");
463
+ offCtx;
464
+ rotation = Math.PI / 180 * 270;
465
+ speed = 6;
466
+ count = 75;
467
+ constructor(e) {
468
+ super(e), this.ctx = this.options.ctx, this.offCanvas.width = 250, this.offCanvas.height = 250, this.offCtx = A(this.offCanvas), this.offCtx.lineWidth = .5, this.offCtx.strokeStyle = "rgba(255, 255, 255, 0.75)";
469
+ }
470
+ updateLoader() {
471
+ this.rotation += this.speed / 100;
472
+ }
473
+ renderLoader() {
474
+ this.offCtx.save(), this.offCtx.globalCompositeOperation = "source-over", this.offCtx.translate(125, 125), this.offCtx.rotate(this.rotation);
475
+ let e = this.count;
476
+ 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();
477
+ this.offCtx.restore();
478
+ }
479
+ render() {
480
+ 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();
481
+ let e = Math.round((this.ctx.canvas.width - this.offCanvas.width) / 2), t = Math.round((this.ctx.canvas.height - this.offCanvas.height) / 2);
482
+ return this.ctx.clearRect(e, t, 250, 250), this.ctx.drawImage(this.offCanvas, e, t), this.offCanvas;
483
+ }
484
+ }, M = class {
485
+ name;
486
+ canvas = document.createElement("canvas");
487
+ ctx;
488
+ constructor(e, { alpha: t = !0, desynchronized: n = !1 } = {}) {
489
+ this.name = e, this.canvas.className = `drawingLayer ${e}`, this.ctx = A(this.canvas, {
490
+ alpha: t,
491
+ desynchronized: n
492
+ });
493
+ }
494
+ width = 0;
495
+ height = 0;
496
+ pixelRatio = 1;
497
+ resize(e, t, n = 1) {
498
+ 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);
499
+ }
500
+ clear() {
501
+ this.ctx.clearRect(0, 0, this.width, this.height);
502
+ }
503
+ }, N = class {
504
+ renderers = /* @__PURE__ */ new Map();
505
+ warned = /* @__PURE__ */ new Set();
506
+ register(e, t) {
507
+ this.renderers.set(e, t), this.warned.delete(e);
508
+ }
509
+ unregister(e) {
510
+ this.renderers.delete(e);
511
+ }
512
+ get(e) {
513
+ return this.renderers.get(e);
514
+ }
515
+ resolve(e) {
516
+ if (typeof e != "string") return e;
517
+ let t = this.renderers.get(e);
518
+ return !t && !this.warned.has(e) && (this.warned.add(e), console.warn(`canvas-grid: no renderer registered as "${e}"`)), t;
519
+ }
520
+ clearCaches() {
521
+ this.renderers.forEach((e) => e.clearCache?.());
522
+ }
523
+ }, P = T((e, { x: t = 0, y: n = 0, width: r, height: i, color: a, alpha: o = 1 }, s, c) => {
524
+ let l = Math.trunc(r), u = Math.trunc(i);
525
+ !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));
526
+ }), F = class e extends O {
527
+ static defaultOptions = {
528
+ layer: "background",
529
+ enableFlashing: !0,
530
+ background: "#333",
531
+ flashInDuration: 200,
532
+ flashOutDuration: 400,
533
+ flashRGB: "214, 144, 13",
534
+ borderRightWidth: 0,
535
+ borderRightColor: "#fff",
536
+ borderBottomWidth: 0,
537
+ borderBottomColor: "#fff"
538
+ };
539
+ constructor(t = {}) {
540
+ super({
541
+ ...e.defaultOptions,
542
+ ...t
543
+ });
544
+ }
545
+ get layer() {
546
+ return this.options.layer;
547
+ }
548
+ isAnimating({ age: e }) {
549
+ return this.options.enableFlashing && e <= this.options.flashInDuration + this.options.flashOutDuration;
550
+ }
551
+ getFlashAlpha(e) {
552
+ if (!this.options.enableFlashing) return 0;
553
+ let { flashInDuration: t, flashOutDuration: n } = this.options, r = e < t ? e / t : (t + n - e) / n;
554
+ return Math.max(0, Math.round(r * 1e3) / 1e3);
555
+ }
556
+ draw({ ctx: e, x: t, y: n, width: r, height: i, age: a }) {
557
+ let { background: o, flashRGB: s, borderRightWidth: c, borderRightColor: l, borderBottomWidth: u, borderBottomColor: d } = this.options, f = this.getFlashAlpha(a);
558
+ (/* @__PURE__ */ D.createElement(E, null, /* @__PURE__ */ D.createElement(P, {
559
+ width: r,
560
+ height: i,
561
+ color: o
562
+ }), f > 0 && /* @__PURE__ */ D.createElement(P, {
563
+ width: r,
564
+ height: i,
565
+ color: `rgb(${s})`,
566
+ alpha: f
567
+ }), c > 0 && /* @__PURE__ */ D.createElement(P, {
568
+ x: r - c,
569
+ width: c,
570
+ height: i,
571
+ color: l
572
+ }), u > 0 && /* @__PURE__ */ D.createElement(P, {
573
+ y: i - u,
574
+ width: r,
575
+ height: u,
576
+ color: d
577
+ }))).draw(e, t, n);
578
+ }
579
+ }, I = class e extends k {
580
+ static defaultOptions = {
581
+ font: "12px monospace",
582
+ color: "#fff",
583
+ alpha: !0,
584
+ clearBeforeRender: !0
585
+ };
586
+ charWidthCache = new p();
587
+ canvas = document.createElement("canvas");
588
+ ctx;
589
+ constructor(t = {}) {
590
+ super({
591
+ ...e.defaultOptions,
592
+ ...t
593
+ }), this.ctx = A(this.canvas, { alpha: this.options.alpha }), this.ctx.textAlign = "left", this.ctx.textBaseline = "top";
594
+ }
595
+ set font(e) {
596
+ this.options.font !== e && (this.options.font = e);
597
+ }
598
+ set color(e) {
599
+ this.options.color = e;
600
+ }
601
+ clearCache() {
602
+ super.clearCache(), this.charWidthCache.clear();
603
+ }
604
+ cacheKey({ value: e = "", height: t = 0 }) {
605
+ return `${this.options.font}|${this.options.color}|${this.pixelRatio}|${t}|${e}`;
606
+ }
607
+ getCharacterWidth(e = "") {
608
+ let t = this.charWidthCache.get(e);
609
+ if (t) return t;
610
+ this.ctx.font !== this.options.font && (this.ctx.font = this.options.font, this.ctx.textAlign = "left", this.ctx.textBaseline = "top");
611
+ let n = Math.ceil(this.ctx.measureText(e).width);
612
+ return this.charWidthCache.set(e, n), n;
613
+ }
614
+ render({ value: e = "", height: t = 0 }) {
615
+ let { pixelRatio: n } = this;
616
+ 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;
617
+ }
618
+ }, L = class e extends O {
619
+ static defaultOptions = {
620
+ ellipsis: "…",
621
+ cellPadding: {
622
+ top: 3,
623
+ right: 3,
624
+ bottom: 3,
625
+ left: 3
626
+ },
627
+ font: "12px monospace",
628
+ color: "#fff",
629
+ isEllipsisRight: !0
630
+ };
631
+ characterRenderer;
632
+ constructor(t = {}) {
633
+ super({
634
+ ...e.defaultOptions,
635
+ ...t
636
+ }), this.characterRenderer = new I({
637
+ font: this.options.font,
638
+ color: this.options.color
639
+ });
640
+ }
641
+ set font(e) {
642
+ this.options.font !== e && (this.options.font = e, this.characterRenderer.font = e, this.clearCache());
643
+ }
644
+ get font() {
645
+ return this.options.font;
646
+ }
647
+ set color(e) {
648
+ this.options.color = e, this.characterRenderer.color = e;
649
+ }
650
+ get color() {
651
+ return this.options.color;
652
+ }
653
+ set pixelRatio(e) {
654
+ this.characterRenderer.pixelRatio = e;
655
+ }
656
+ get pixelRatio() {
657
+ return this.characterRenderer.pixelRatio;
658
+ }
659
+ clearCache() {
660
+ this.characterRenderer.clearCache();
661
+ }
662
+ getTextWidth(e) {
663
+ let t = 0;
664
+ for (let n = 0; n < e.length; n++) {
665
+ let r = e.charAt(n);
666
+ t += this.characterRenderer.getCharacterWidth(r);
667
+ }
668
+ return t;
669
+ }
670
+ paint(e, { value: t = "", x: n = 0, y: r = 0, width: i = 0, height: a = 0 }, o, s) {
671
+ 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;
672
+ for (let n = 0; n < t.length; n++) {
673
+ let r = t.charAt(n), i = Math.round(this.characterRenderer.getCharacterWidth(r));
674
+ if (Math.ceil(h + i) >= u) {
675
+ this.characterRenderer.paint(e, {
676
+ value: this.options.ellipsis,
677
+ height: p
678
+ }, d + m, f);
679
+ break;
680
+ }
681
+ this.characterRenderer.paint(e, {
682
+ value: r,
683
+ height: p
684
+ }, d + m, f), h += i, m += i;
685
+ }
686
+ }
687
+ element = T((e, t, n, r) => this.paint(e, t, n, r));
688
+ }, R = class e extends O {
689
+ static defaultOptions = {
690
+ layer: "header",
691
+ background: "#333",
692
+ font: "13px monospace",
693
+ color: "#fff",
694
+ borderRightWidth: 1,
695
+ borderRightColor: "#fff",
696
+ borderBottomWidth: 1,
697
+ borderBottomColor: "#fff"
698
+ };
699
+ textRenderer;
700
+ constructor(t = {}) {
701
+ super({
702
+ ...e.defaultOptions,
703
+ ...t
704
+ }), this.textRenderer = new L({
705
+ font: this.options.font,
706
+ color: this.options.color
707
+ });
708
+ }
709
+ get layer() {
710
+ return this.options.layer;
711
+ }
712
+ set font(e) {
713
+ this.options.font = e, this.textRenderer.font = e;
714
+ }
715
+ get font() {
716
+ return this.textRenderer.font;
717
+ }
718
+ set pixelRatio(e) {
719
+ this.textRenderer.pixelRatio = e;
720
+ }
721
+ get pixelRatio() {
722
+ return this.textRenderer.pixelRatio;
723
+ }
724
+ clearCache() {
725
+ this.textRenderer.clearCache();
726
+ }
727
+ draw({ ctx: e, x: t, y: n, width: r, height: i, formatted: a }) {
728
+ if (r === 0 || i === 0) return;
729
+ let { background: o, borderRightWidth: s, borderRightColor: c, borderBottomWidth: l, borderBottomColor: u } = this.options;
730
+ (/* @__PURE__ */ D.createElement(E, null, /* @__PURE__ */ D.createElement(P, {
731
+ width: r,
732
+ height: i,
733
+ color: o
734
+ }), s > 0 && /* @__PURE__ */ D.createElement(P, {
735
+ x: r - s,
736
+ width: s,
737
+ height: i,
738
+ color: c
739
+ }), l > 0 && /* @__PURE__ */ D.createElement(P, {
740
+ y: i - l,
741
+ width: r,
742
+ height: l,
743
+ color: u
744
+ }), /* @__PURE__ */ D.createElement(this.textRenderer.element, {
745
+ value: a,
746
+ width: r,
747
+ height: i
748
+ }))).draw(e, t, n);
749
+ }
750
+ }, z = class e extends O {
751
+ static defaultOptions = {
752
+ layer: "content",
753
+ font: "12px monospace",
754
+ color: "#fff"
755
+ };
756
+ renderer;
757
+ constructor(t = {}) {
758
+ super({
759
+ ...e.defaultOptions,
760
+ ...t
761
+ }), this.renderer = new L({
762
+ font: this.options.font,
763
+ color: this.options.color
764
+ });
765
+ }
766
+ get layer() {
767
+ return this.options.layer;
768
+ }
769
+ set font(e) {
770
+ this.options.font = e, this.renderer.font = e;
771
+ }
772
+ get font() {
773
+ return this.options.font;
774
+ }
775
+ set color(e) {
776
+ this.options.color = e, this.renderer.color = e;
777
+ }
778
+ get color() {
779
+ return this.options.color;
780
+ }
781
+ set pixelRatio(e) {
782
+ this.renderer.pixelRatio = e;
783
+ }
784
+ get pixelRatio() {
785
+ return this.renderer.pixelRatio;
786
+ }
787
+ clearCache() {
788
+ this.renderer.clearCache();
789
+ }
790
+ draw({ ctx: e, x: t, y: n, width: r, height: i, formatted: a, valueChanged: o, forced: s }) {
791
+ (o || s) && (e.clearRect(t, n, r, i), (/* @__PURE__ */ D.createElement(this.renderer.element, {
792
+ value: a,
793
+ width: r,
794
+ height: i
795
+ })).draw(e, t, n));
796
+ }
797
+ }, B = { scrollArea: "scrollArea" }, V = {
798
+ background: "background",
799
+ content: "content",
800
+ header: "header",
801
+ backgroundRenderer: "background",
802
+ valueRenderer: "value",
803
+ headerRenderer: "header"
804
+ }, H = "canvas-grid-styles", U = () => {
805
+ if (document.getElementById(H)) return;
806
+ let e = document.createElement("style");
807
+ e.id = H, e.textContent = C, document.head.appendChild(e);
808
+ }, W = class extends HTMLElement {
809
+ fps = 30;
810
+ _font = "12px monospace";
811
+ _headerFont = "13px monospace";
812
+ headerHeight = 30;
813
+ cellHeight = 20;
814
+ cellPadding = {
815
+ top: 3,
816
+ right: 3,
817
+ bottom: 3,
818
+ left: 3
819
+ };
820
+ showRowNumbers = !0;
821
+ showHeaders = !0;
822
+ rowNumbersWidth = 30;
823
+ ellipsis = "…";
824
+ _backgroundColor = "#333";
825
+ _headerBackgroundColor = "#222";
826
+ textColor = "#efefef";
827
+ dataStore = new x({
828
+ getRowId: (e, t) => this.getRowId(e, t),
829
+ getCellHeight: () => this.cellHeight
830
+ });
831
+ _dataCollection = this.dataStore.rows;
832
+ cellEntries = new S(2048);
833
+ getRowId = _;
834
+ headers = new p();
835
+ animationFrame = void 0;
836
+ scrollYOffset = 0;
837
+ prevScrollYOffset = 0;
838
+ scrollXOffset = 0;
839
+ prevScrollXOffset = 0;
840
+ lastRender = (/* @__PURE__ */ new Date()).valueOf();
841
+ lastDraw = this.lastRender;
842
+ isScrolling = !1;
843
+ scrollHelper = document.createElement("div");
844
+ scrollArea = this.createScrollArea();
845
+ layers = [];
846
+ layersByName = /* @__PURE__ */ new Map();
847
+ warnedLayers = /* @__PURE__ */ new Set();
848
+ renderers = new N();
849
+ cellRenderers = [V.backgroundRenderer, V.valueRenderer];
850
+ cellBackgroundRenderer = new F({
851
+ layer: V.background,
852
+ background: this._backgroundColor,
853
+ enableFlashing: !0,
854
+ flashInDuration: 200,
855
+ flashOutDuration: 400,
856
+ flashRGB: "214, 144, 13",
857
+ borderRightWidth: 1,
858
+ borderRightColor: "#3f3f3f",
859
+ borderBottomWidth: 1,
860
+ borderBottomColor: "#3f3f3f"
861
+ });
862
+ cellValueRenderer = new z({
863
+ layer: V.content,
864
+ font: this._font,
865
+ color: this.textColor
866
+ });
867
+ headerCellRenderer = new R({
868
+ layer: V.header,
869
+ font: this._headerFont,
870
+ color: this.textColor,
871
+ background: "#222",
872
+ borderRightWidth: 1,
873
+ borderRightColor: "#2f2f2f",
874
+ borderBottomWidth: 1,
875
+ borderBottomColor: "#2f2f2f"
876
+ });
877
+ loadingIndicator;
878
+ cell;
879
+ placeholderState = {};
880
+ throttleTransation = (0, d.default)(() => {
881
+ let e = this.totalHeight, t = this.dataStore.flush();
882
+ e !== this.totalHeight && this.refreshScrollbar(), t && this.forceDraw(), this.requestRender();
883
+ }, 50);
884
+ agApi;
885
+ constructor() {
886
+ 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(V.background, { alpha: !1 }), this.addLayer(V.content), this.addLayer(V.header), this.registerRenderer(V.backgroundRenderer, this.cellBackgroundRenderer), this.registerRenderer(V.valueRenderer, this.cellValueRenderer), this.registerRenderer(V.headerRenderer, this.headerCellRenderer), this.loadingIndicator = new j({ ctx: this.requireLayer(V.header).ctx }), this.cell = {
887
+ ctx: this.requireLayer(V.content).ctx,
888
+ x: 0,
889
+ y: 0,
890
+ width: 0,
891
+ height: 0,
892
+ row: void 0,
893
+ column: void 0,
894
+ value: void 0,
895
+ formatted: "",
896
+ updatedAt: void 0,
897
+ age: Infinity,
898
+ now: 0,
899
+ dt: 0,
900
+ valueChanged: !1,
901
+ forced: !1,
902
+ isScrolling: !1,
903
+ state: {}
904
+ };
905
+ let e = this;
906
+ this.agApi = {
907
+ setRowData: this.setValues,
908
+ updateRowData: this.transaction,
909
+ setColumnDefs: this.setColumns,
910
+ get getRowNodeId() {
911
+ return e.getRowId;
912
+ },
913
+ set getRowNodeId(t) {
914
+ typeof t == "function" && (e.getRowId = t);
915
+ }
916
+ };
917
+ }
918
+ get canvas() {
919
+ return this.requireLayer(V.content).canvas;
920
+ }
921
+ get flashInDuration() {
922
+ return this.cellBackgroundRenderer.options.flashInDuration;
923
+ }
924
+ set flashInDuration(e) {
925
+ this.cellBackgroundRenderer.update({ flashInDuration: e });
926
+ }
927
+ get flashOutDuration() {
928
+ return this.cellBackgroundRenderer.options.flashOutDuration;
929
+ }
930
+ set flashOutDuration(e) {
931
+ this.cellBackgroundRenderer.update({ flashOutDuration: e });
932
+ }
933
+ getLayer(e) {
934
+ return this.layersByName.get(e);
935
+ }
936
+ requireLayer(e) {
937
+ let t = this.getLayer(e);
938
+ if (!t) throw Error(`canvas-grid: no layer named "${e}"`);
939
+ return t;
940
+ }
941
+ addLayer(e, { alpha: t = !0, desynchronized: n = !1, before: r } = {}) {
942
+ if (this.getLayer(e)) throw Error(`canvas-grid: layer "${e}" already exists`);
943
+ let i = new M(e, {
944
+ alpha: t,
945
+ desynchronized: n
946
+ }), a = r === void 0 ? void 0 : this.requireLayer(r);
947
+ 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;
948
+ }
949
+ removeLayer(e) {
950
+ let t = this.requireLayer(e);
951
+ this.layers = this.layers.filter((e) => e !== t), this.layersByName.delete(e), t.canvas.remove();
952
+ }
953
+ registerRenderer(e, t) {
954
+ this.renderers.register(e, t);
955
+ }
956
+ unregisterRenderer(e) {
957
+ this.renderers.unregister(e);
958
+ }
959
+ createScrollArea() {
960
+ let e = document.createElement("div");
961
+ return e.className = B.scrollArea, e.appendChild(this.scrollHelper), e;
962
+ }
963
+ set font(e) {
964
+ this._font !== e && (this._font = e, this.cellValueRenderer.font = e);
965
+ }
966
+ get font() {
967
+ return this._font;
968
+ }
969
+ set headerFont(e) {
970
+ this._headerFont !== e && (this._headerFont = e, this.headerCellRenderer.font = e);
971
+ }
972
+ get headerFont() {
973
+ return this._headerFont;
974
+ }
975
+ connectedCallback() {
976
+ 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);
977
+ let e = (0, f.default)(() => {
978
+ this.isScrolling = !1;
979
+ }, 200), t = (0, d.default)((t, n) => {
980
+ this.scrollXOffset = Math.round(n), this.scrollYOffset = Math.round(t), e(), this.requestRender();
981
+ }, 10);
982
+ this.scrollArea.addEventListener("scroll", () => {
983
+ let { scrollTop: e, scrollLeft: n } = this.scrollArea;
984
+ this.isScrolling = !0, t(e, n);
985
+ });
986
+ }
987
+ fontsTimeout = void 0;
988
+ onVisibilityChange = () => {
989
+ document.visibilityState === "hidden" ? this.cancelRender() : this.resize();
990
+ };
991
+ onFontsLoaded = () => {
992
+ this.renderers.clearCaches(), this.resize();
993
+ };
994
+ cancelRender() {
995
+ this.animationFrame !== void 0 && cancelAnimationFrame(this.animationFrame), this.animationFrame = void 0;
996
+ }
997
+ requestRender() {
998
+ this.animationFrame ??= requestAnimationFrame(() => this.render());
999
+ }
1000
+ updateLastRender() {
1001
+ this.lastRender = (/* @__PURE__ */ new Date()).valueOf();
1002
+ }
1003
+ render() {
1004
+ this.animationFrame = void 0, (/* @__PURE__ */ new Date()).valueOf() - this.lastRender < 1e3 / this.fps ? this.requestRender() : (this.draw(), this.updateLastRender());
1005
+ }
1006
+ hasScrolled() {
1007
+ return this.hasXScrolled() || this.hasYScrolled();
1008
+ }
1009
+ hasYScrolled() {
1010
+ return this.prevScrollYOffset !== this.scrollYOffset;
1011
+ }
1012
+ hasXScrolled() {
1013
+ return this.prevScrollXOffset !== this.scrollXOffset;
1014
+ }
1015
+ isInViewport(e = 0, t = 0, n = 0, r = 0) {
1016
+ return !(e > this.viewportWidth || t > this.viewportHeight || e + n < 0 || t + r < 0);
1017
+ }
1018
+ describe(e, t, n, r, i) {
1019
+ return Object.assign(this.cell, {
1020
+ x: e,
1021
+ y: t,
1022
+ width: n,
1023
+ height: r,
1024
+ row: void 0,
1025
+ column: void 0,
1026
+ value: void 0,
1027
+ formatted: "",
1028
+ updatedAt: void 0,
1029
+ age: Infinity,
1030
+ valueChanged: !0,
1031
+ forced: !0,
1032
+ state: this.placeholderState
1033
+ }, i);
1034
+ }
1035
+ paint(e) {
1036
+ let t = this.renderers.resolve(e), n = t && this.layersByName.get(t.layer);
1037
+ 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));
1038
+ }
1039
+ paintAll(e) {
1040
+ e.forEach((e) => this.paint(e));
1041
+ }
1042
+ isAnimating(e) {
1043
+ return e.some((e) => this.renderers.resolve(e)?.isAnimating?.(this.cell) === !0);
1044
+ }
1045
+ draw(e = !1) {
1046
+ let t = (/* @__PURE__ */ new Date()).valueOf(), n = e || this.hasScrolled();
1047
+ this.cell.now = t, this.cell.dt = t - this.lastDraw, this.cell.isScrolling = this.isScrolling, this.lastDraw = t;
1048
+ let r = this._dataCollection.length === 0;
1049
+ 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);
1050
+ if (this._dataCollection.length === 0) {
1051
+ this.loadingIndicator.render();
1052
+ for (let e = 0; e <= 200; e++) this.headers.forEach((t) => {
1053
+ 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, {
1054
+ column: t,
1055
+ valueChanged: !1
1056
+ }), this.paintAll(t.renderers ?? this.cellRenderers);
1057
+ });
1058
+ }
1059
+ 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);
1060
+ for (let a = o; a < this._dataCollection.length; a++) {
1061
+ let o = this._dataCollection.at(a), c = i + this._dataCollection.topOf(a);
1062
+ if (!o || c >= this.viewportHeight) break;
1063
+ let { id: l, slot: u } = o;
1064
+ if ((e || this.hasYScrolled()) && this.showRowNumbers && this.renderRowNumber(o, c), o.height + c > 0) {
1065
+ let e = this.cellEntries.get(String(l));
1066
+ e || (e = {}, this.cellEntries.set(String(l), e));
1067
+ let i = {
1068
+ id: l,
1069
+ index: o.index
1070
+ };
1071
+ for (let { header: a, id: l, x: d, store: f } of s) {
1072
+ let s = f?.get(u);
1073
+ if (s === void 0) continue;
1074
+ let p = e[l] ??= {
1075
+ value: void 0,
1076
+ formatted: void 0,
1077
+ animating: !1,
1078
+ state: {}
1079
+ }, m = p.formatted !== void 0 && p.value === s ? p.formatted : a.valueFormatter(s), h = p.formatted !== m, g = f?.getUpdatedAt(u), { cell: _ } = this;
1080
+ _.x = d, _.y = c, _.width = a.width, _.height = o.height, _.row = i, _.column = a, _.value = s, _.formatted = m, _.updatedAt = g, _.age = g === void 0 ? Infinity : t - g, _.valueChanged = h, _.forced = n, _.state = p.state;
1081
+ let v = a.renderers ?? this.cellRenderers, y = this.isAnimating(v);
1082
+ (n || h || y || p.animating) && this.paintAll(v), p.animating = y, p.value = s, p.formatted = m, r ||= y;
1083
+ }
1084
+ }
1085
+ }
1086
+ (this.scrollYOffset > 0 || this.scrollXOffset > 0) && this.renderBrick(), this.prevScrollYOffset = this.scrollYOffset, this.prevScrollXOffset = this.scrollXOffset, r && this.requestRender();
1087
+ }
1088
+ getVisibleColumns(e) {
1089
+ let t = [], n = e;
1090
+ return this.headers.forEach((e, r) => {
1091
+ this.isInViewport(n, 0, e.width, 0) && t.push({
1092
+ header: e,
1093
+ id: String(r),
1094
+ x: n,
1095
+ store: this.dataStore.columns.get(String(r))
1096
+ }), n += Math.round(e.width);
1097
+ }), t;
1098
+ }
1099
+ renderRowNumber(e, t) {
1100
+ this.isInViewport(0, t, this.rowNumbersWidth, e.height) && (this.describe(0, Math.ceil(t), this.rowNumbersWidth, e.height ?? 0, {
1101
+ row: {
1102
+ id: e.index,
1103
+ index: e.index
1104
+ },
1105
+ formatted: `${e.index + 1}`
1106
+ }), this.paint(V.headerRenderer));
1107
+ }
1108
+ forceDraw() {
1109
+ this.layers.forEach((e) => e.clear()), this.draw(!0);
1110
+ }
1111
+ viewportWidth = 0;
1112
+ viewportHeight = 0;
1113
+ get pixelRatio() {
1114
+ return window.devicePixelRatio || 1;
1115
+ }
1116
+ resize() {
1117
+ this.cancelRender();
1118
+ let { pixelRatio: e } = this;
1119
+ 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();
1120
+ }
1121
+ observeSize() {
1122
+ this.resizeObserver ??= new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this);
1123
+ }
1124
+ watchPixelRatio = () => {
1125
+ this.pixelRatioQuery?.removeEventListener("change", this.watchPixelRatio), this.pixelRatioQuery = window.matchMedia(`(resolution: ${this.pixelRatio}dppx)`), this.pixelRatioQuery.addEventListener("change", this.watchPixelRatio, { once: !0 }), this.resize();
1126
+ };
1127
+ resizeObserver = void 0;
1128
+ pixelRatioQuery = void 0;
1129
+ getRowData(e) {
1130
+ let t = this._dataCollection.get(e);
1131
+ if (!t) return;
1132
+ let n = {};
1133
+ return this.dataStore.columns.forEach((e, r) => {
1134
+ let i = e.get(t.slot);
1135
+ i !== void 0 && (n[r] = i);
1136
+ }), {
1137
+ id: t.id,
1138
+ index: t.index,
1139
+ height: t.height,
1140
+ values: n
1141
+ };
1142
+ }
1143
+ setSortModel(e) {
1144
+ this.dataStore.setSortModel(e), this.forceDraw();
1145
+ }
1146
+ getSortModel() {
1147
+ return this.dataStore.getSortModel();
1148
+ }
1149
+ renderBrick() {
1150
+ this.showHeaders && this.showRowNumbers && this._headerBackgroundColor && (this.describe(0, 0, this.rowNumbersWidth, this.headerHeight, {}), this.paint(V.headerRenderer));
1151
+ }
1152
+ renderHeaders() {
1153
+ let e = (this.showRowNumbers ? this.rowNumbersWidth : 0) - this.scrollXOffset;
1154
+ this.headers.forEach((t) => {
1155
+ this.isInViewport(e, 0, t.width, this.headerHeight) && (this.describe(e, 0, t.width, this.headerHeight, {
1156
+ column: t,
1157
+ formatted: t.displayName ?? ""
1158
+ }), this.paint(t.headerRenderer)), e += t.width;
1159
+ }), this.scrollXOffset + this.rowNumbersWidth > 0 && this.renderBrick();
1160
+ }
1161
+ getColumnHeader(e) {
1162
+ return this.headers.get(e);
1163
+ }
1164
+ get totalHeight() {
1165
+ return this._dataCollection.totalHeight;
1166
+ }
1167
+ refreshScrollbar() {
1168
+ let e = this.totalHeight + this.headerHeight;
1169
+ this.scrollHelper.style.height = `${e}px`;
1170
+ let t = 0;
1171
+ this.headers.forEach((e) => {
1172
+ t += Math.round(e.width);
1173
+ }), this.scrollHelper.style.width = `${t}px`;
1174
+ }
1175
+ queueUpdate(e) {
1176
+ this.dataStore.queueUpdate(e), this.throttleTransation();
1177
+ }
1178
+ queueRemove(e) {
1179
+ this.dataStore.queueRemove(e), this.throttleTransation();
1180
+ }
1181
+ transaction({ add: e = [], remove: t = [], update: n = [] }) {
1182
+ 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));
1183
+ }
1184
+ clearValues() {
1185
+ this.dataStore.clear(), this.cellEntries.clear();
1186
+ }
1187
+ formatValue(e, t) {
1188
+ return this.headers.get(e)?.valueFormatter(t) ?? String(t);
1189
+ }
1190
+ setValues(e) {
1191
+ this.throttleTransation.cancel(), this.clearValues(), Array.isArray(e) && (this.dataStore.setRows(e), this.refreshScrollbar(), this.forceDraw());
1192
+ }
1193
+ setColumns(e) {
1194
+ if (Array.isArray(e)) {
1195
+ this.headers.clear(), this.cellEntries.clear();
1196
+ let t = {
1197
+ width: 100,
1198
+ valueFormatter: (e) => String(e),
1199
+ headerRenderer: V.headerRenderer
1200
+ };
1201
+ e.forEach((e, n) => {
1202
+ if (typeof e == "string" || typeof e == "number") {
1203
+ let r = e + "";
1204
+ this.headers.set(r, {
1205
+ ...t,
1206
+ index: n,
1207
+ id: e,
1208
+ displayName: r
1209
+ });
1210
+ }
1211
+ typeof e == "object" && this.headers.set(e.id + "", {
1212
+ ...t,
1213
+ index: n,
1214
+ ...e
1215
+ });
1216
+ }), this.refreshScrollbar(), this.forceDraw();
1217
+ }
1218
+ }
1219
+ disconnectedCallback() {
1220
+ 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);
1221
+ }
1222
+ };
1223
+ window && window.customElements && (U(), customElements.define("canvas-grid", W));
1224
+ export { W as default };
1225
+
1226
+ //# sourceMappingURL=web-component.mjs.map