@genome-spy/app 0.85.0 → 0.87.0

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 (58) hide show
  1. package/README.md +28 -0
  2. package/dist/{agentApi-Cz0hCnVp.js → agentApi-BZ1JCo1N.js} +7174 -8484
  3. package/dist/agentApi.es.js +3312 -3575
  4. package/dist/agentShared.es.js +14 -13
  5. package/dist/canvas2d-B_PnIof-.js +620 -0
  6. package/dist/canvas2d-Cafq5v-N.js +620 -0
  7. package/dist/{arrayUtils-LJpQOu-U.js → clipOptions-D6eh9T-_.js} +1060 -634
  8. package/dist/{paramUtils-BYI4rwyL.js → clipOptions-H68pJyEZ.js} +940 -514
  9. package/dist/{debug-CgDtmspT.js → debug-BGzgZmyk.js} +8 -8
  10. package/dist/{debug-BvCZWumf.js → debug-UYKZLNh4.js} +8 -8
  11. package/dist/index.es.js +2983 -2916
  12. package/dist/index.js +2006 -1997
  13. package/dist/indexer-Di57GyxX.js +72 -0
  14. package/dist/indexer-o6Hpg4nN.js +72 -0
  15. package/dist/layoutResult-D50MSHXR.js +97 -0
  16. package/dist/nativeText-D9SoxpaD.js +934 -0
  17. package/dist/nativeText-DAjvkrzc.js +934 -0
  18. package/dist/performanceProfiler-CPLEjApa.js +20 -0
  19. package/dist/rasterExport-DzldLv6E.js +44 -0
  20. package/dist/rasterExport-IAbJwi8F.js +44 -0
  21. package/dist/rasterImage-B4rPLaW9.js +18 -0
  22. package/dist/rasterization-CFogVB3B.js +50 -0
  23. package/dist/rectangle-DKnrAmKs.js +142 -0
  24. package/dist/renderCanvas2D-BJ93Ptqj.js +277 -0
  25. package/dist/renderCanvas2D-yJ1IrDcX.js +277 -0
  26. package/dist/schema.json +11685 -4428
  27. package/dist/{svg-yFj875aX.js → svg-BRpl2Xub.js} +412 -449
  28. package/dist/{svg-CCu8kYy2.js → svg-DJuqHIyc.js} +399 -436
  29. package/dist/svgRasterizer-CGZQ5njV.js +40 -0
  30. package/dist/svgRasterizer-PAoqLn1j.js +40 -0
  31. package/dist/vega-scale-BGC53c22.js +2403 -0
  32. package/dist/vega-scale-DdW2NzQ3.js +2403 -0
  33. package/dist/viewError-BiR9VCgL.js +29 -0
  34. package/dist/{viewIdentityRegistry-BUdkK9zT.js → viewIdentityRegistry-D4p067HU.js} +1 -1
  35. package/dist/{viewIdentityRegistry-D3oPbN4O.js → viewIdentityRegistry-Dc2hXYsO.js} +1 -1
  36. package/dist/viewSelectors-DNXnGwEW.js +2015 -0
  37. package/dist/viewSelectors-DYYlOt91.js +2015 -0
  38. package/dist/viewUtils-EdhZTPrJ.js +6448 -0
  39. package/dist/webgl-C53DwzVT.js +4127 -0
  40. package/dist/webgl-CdgNFlJk.js +4127 -0
  41. package/package.json +7 -6
  42. package/dist/bmFontMetrics-CuNB-kNN.js +0 -31
  43. package/dist/canvas2d-DoAXEiF9.js +0 -309
  44. package/dist/canvas2d-f5jl4A5D.js +0 -310
  45. package/dist/clipOptions-gqdb3fvW.js +0 -43
  46. package/dist/color-W5zffv-z.js +0 -335
  47. package/dist/framebufferReadback-CCLOjStu.js +0 -148
  48. package/dist/framebufferReadback-THWwFqs8.js +0 -1994
  49. package/dist/nativeText-DMO8gLt7.js +0 -806
  50. package/dist/nativeText-m5AUINMq.js +0 -806
  51. package/dist/twgl-full.module-DB2UdP1k.js +0 -1849
  52. package/dist/viewRenderingContext-HtpqwS_x.js +0 -120
  53. package/dist/viewSelectors-DGCspRN3.js +0 -4198
  54. package/dist/viewSelectors-U5oLCLHV.js +0 -4195
  55. package/dist/viewUtils-Dg4RA40Q.js +0 -7503
  56. package/dist/warning-DRGdb6BF.js +0 -59
  57. package/dist/webgl-Ci6ZhCCf.js +0 -54
  58. package/dist/webgl-Dpz8a3TI.js +0 -53
@@ -0,0 +1,620 @@
1
+ import { X as e, an as t, o as n, rt as r, s as i } from "./clipOptions-H68pJyEZ.js";
2
+ import { v as a } from "./vega-scale-BGC53c22.js";
3
+ import { t as o } from "./rectangle-DKnrAmKs.js";
4
+ import { t as s } from "./warning-CpIIpk8e.js";
5
+ import { n as c, r as l, t as u } from "./performanceProfiler-CPLEjApa.js";
6
+ import { n as d, t as f } from "./layoutResult-D50MSHXR.js";
7
+ import { D as p, M as m, O as h, S as g, T as _, _ as v, a as y, c as b, d as x, f as S, g as C, i as w, j as T, k as E, l as D, m as O, o as ee, p as te, s as ne, v as re, x as ie, y as k } from "./nativeText-DAjvkrzc.js";
8
+ import { n as A, t as j } from "./renderCanvas2D-BJ93Ptqj.js";
9
+ import { t as M } from "./canvasSizeHelper-7h_8rOcx.js";
10
+ import { exportCanvas as N, exportRaster as P } from "./rasterExport-IAbJwi8F.js";
11
+ import { createCanvas2DSvgRasterizer as F } from "./svgRasterizer-PAoqLn1j.js";
12
+ //#region ../core/src/rendering/canvas2d/picking/softwarePickingRasterizer.js
13
+ var I = 12, L = .5, R = class {
14
+ #e = [];
15
+ #t = [];
16
+ #n = [
17
+ 0,
18
+ 0,
19
+ 0,
20
+ 0
21
+ ];
22
+ #r = 0;
23
+ #i = 0;
24
+ #a = 0;
25
+ #o = 0;
26
+ #s = 0;
27
+ #c = 0;
28
+ #l = 0;
29
+ #u = 0;
30
+ #d = 0;
31
+ #f = 0;
32
+ constructor(e) {
33
+ this.buffer = e, this.resetClip();
34
+ }
35
+ resetClip() {
36
+ this.#r = 0, this.#i = 0, this.#a = this.buffer.width, this.#o = this.buffer.height;
37
+ }
38
+ resetStatistics() {
39
+ this.#s = 0, this.#c = 0, this.#l = 0, this.#u = 0, this.#d = 0, this.#f = 0;
40
+ }
41
+ getStatistics() {
42
+ return {
43
+ rectangles: this.#s,
44
+ squares: this.#c,
45
+ polygons: this.#l,
46
+ segments: this.#u,
47
+ cubics: this.#d,
48
+ spans: this.#f
49
+ };
50
+ }
51
+ setClip(e, t, n, r) {
52
+ if (!Number.isFinite(e) || !Number.isFinite(t) || !Number.isFinite(n) || !Number.isFinite(r)) throw RangeError("Software picking clip must be finite.");
53
+ this.#r = H(Math.floor(Math.min(e, n)), 0, this.buffer.width), this.#i = H(Math.floor(Math.min(t, r)), 0, this.buffer.height), this.#a = H(Math.ceil(Math.max(e, n)), this.#r, this.buffer.width), this.#o = H(Math.ceil(Math.max(t, r)), this.#i, this.buffer.height);
54
+ }
55
+ fillRect(e, t, n, r, i) {
56
+ this.#s++, this.#p(e, t, n, r, i);
57
+ }
58
+ #p(e, t, n, r, i) {
59
+ let a = t + r, o = n + i;
60
+ if (!Number.isFinite(a) || !Number.isFinite(o) || r == 0 || i == 0) return;
61
+ let s = Math.max(this.#r, Math.floor(Math.min(t, a))), c = Math.max(this.#i, Math.floor(Math.min(n, o))), l = Math.min(this.#a, Math.ceil(Math.max(t, a))), u = Math.min(this.#o, Math.ceil(Math.max(n, o)));
62
+ if (!(s >= l || c >= u)) for (let t = c; t < u; t++) this.#m(e, t, s, l);
63
+ }
64
+ fillSquare(e, t, n, r) {
65
+ !Number.isFinite(t) || !Number.isFinite(n) || !(r > 0) || !Number.isFinite(r) || (this.#c++, this.#h(e, t, n, r));
66
+ }
67
+ fillConvexPolygon(e, t) {
68
+ if (t.length < 6 || t.length % 2 != 0) throw Error("A convex picking polygon requires at least three x/y pairs.");
69
+ this.#l++;
70
+ let n = Infinity, r = -Infinity;
71
+ for (let e = 1; e < t.length; e += 2) {
72
+ let i = t[e];
73
+ if (!Number.isFinite(t[e - 1]) || !Number.isFinite(i)) return;
74
+ n = Math.min(n, i), r = Math.max(r, i);
75
+ }
76
+ let i = Math.max(this.#i, Math.floor(n)), a = Math.min(this.#o, Math.ceil(r)), o = this.#t;
77
+ for (let n = i; n < a; n++) {
78
+ let r = n + .5;
79
+ o.length = 0;
80
+ let i = t.length - 2;
81
+ for (let e = 0; e < t.length; e += 2) {
82
+ let n = t[i], a = t[i + 1], s = t[e], c = t[e + 1];
83
+ (a <= r && r < c || c <= r && r < a) && o.push(n + (r - a) * (s - n) / (c - a)), i = e;
84
+ }
85
+ o.sort((e, t) => e - t);
86
+ for (let t = 0; t + 1 < o.length; t += 2) {
87
+ let r = Math.max(this.#r, Math.floor(o[t])), i = Math.min(this.#a, Math.ceil(o[t + 1]));
88
+ r < i && this.#m(e, n, r, i);
89
+ }
90
+ }
91
+ let s = t.length - 2;
92
+ for (let n = 0; n < t.length; n += 2) this.strokeSegment(e, t[s], t[s + 1], t[n], t[n + 1], 1), s = n;
93
+ }
94
+ strokeSegment(e, t, n, r, i, a, o) {
95
+ if (!(a > 0) || !Number.isFinite(a)) return;
96
+ this.#u++;
97
+ let s = a / 2, c = this.#n;
98
+ if (!z(t, n, r, i, this.#r - s, this.#i - s, this.#a + s, this.#o + s, c)) return;
99
+ let l = c[2] - c[0], u = c[3] - c[1], d = Math.ceil(Math.max(Math.abs(l), Math.abs(u)));
100
+ if (d == 0) {
101
+ this.#h(e, c[0], c[1], s, o);
102
+ return;
103
+ }
104
+ for (let t = 0; t <= d; t++) {
105
+ let n = t / d;
106
+ this.#h(e, c[0] + l * n, c[1] + u * n, s, o);
107
+ }
108
+ }
109
+ strokeCubic(e, t, n, r, i, a, o, s, c, l, u = L, d) {
110
+ if (!(l > 0) || !Number.isFinite(l) || !(u > 0) || !Number.isFinite(u) || !Number.isFinite(t) || !Number.isFinite(n) || !Number.isFinite(r) || !Number.isFinite(i) || !Number.isFinite(a) || !Number.isFinite(o) || !Number.isFinite(s) || !Number.isFinite(c)) return;
111
+ this.#d++;
112
+ let f = this.#e;
113
+ for (f.length = 0, f.push(t, n, r, i, a, o, s, c, 0); f.length;) {
114
+ let t = f.pop(), n = f.pop(), r = f.pop(), i = f.pop(), a = f.pop(), o = f.pop(), s = f.pop(), c = f.pop(), p = f.pop();
115
+ if (t >= I || B(p, c, s, o, a, i, r, n, u)) {
116
+ this.strokeSegment(e, p, c, r, n, l, d);
117
+ continue;
118
+ }
119
+ let m = (p + s) / 2, h = (c + o) / 2, g = (s + a) / 2, _ = (o + i) / 2, v = (a + r) / 2, y = (i + n) / 2, b = (m + g) / 2, x = (h + _) / 2, S = (g + v) / 2, C = (_ + y) / 2, w = (b + S) / 2, T = (x + C) / 2, E = t + 1;
120
+ f.push(w, T, S, C, v, y, r, n, E, p, c, m, h, b, x, w, T, E);
121
+ }
122
+ }
123
+ #m(e, t, n, r) {
124
+ this.#f++;
125
+ let i = t * this.buffer.width;
126
+ this.buffer.ids.fill(e >>> 0, i + n, i + r);
127
+ }
128
+ #h(e, t, n, r, i) {
129
+ let a = Math.max(this.#r, Math.floor(t - r)), o = Math.max(this.#i, Math.floor(n - r)), s = Math.min(this.#a, Math.ceil(t + r)), c = Math.min(this.#o, Math.ceil(n + r));
130
+ if (a >= s || o >= c) return;
131
+ let l = e >>> 0, u = this.buffer.ids, d = this.buffer.width, f = s - a;
132
+ for (let e = o; e < c; e++) {
133
+ this.#f++;
134
+ let t = e * d + a, n = t + f;
135
+ if (i) for (let t = a; t < s; t++) i(t + .5, e + .5) && (u[e * d + t] = l);
136
+ else if (f > 16) u.fill(l, t, n);
137
+ else for (let e = t; e < n; e++) u[e] = l;
138
+ }
139
+ }
140
+ };
141
+ function z(e, t, n, r, i, a, o, s, c) {
142
+ if (!Number.isFinite(e) || !Number.isFinite(t) || !Number.isFinite(n) || !Number.isFinite(r)) return !1;
143
+ let l = n - e, u = r - t, d = 0, f = 1;
144
+ if (l == 0) {
145
+ if (e < i || e > o) return !1;
146
+ } else {
147
+ let t = (i - e) / l, n = (o - e) / l;
148
+ d = Math.max(d, Math.min(t, n)), f = Math.min(f, Math.max(t, n));
149
+ }
150
+ if (u == 0) {
151
+ if (t < a || t > s) return !1;
152
+ } else {
153
+ let e = (a - t) / u, n = (s - t) / u;
154
+ d = Math.max(d, Math.min(e, n)), f = Math.min(f, Math.max(e, n));
155
+ }
156
+ return d > f ? !1 : (c[0] = e + d * l, c[1] = t + d * u, c[2] = e + f * l, c[3] = t + f * u, !0);
157
+ }
158
+ function B(e, t, n, r, i, a, o, s, c) {
159
+ let l = o - e, u = s - t, d = l * l + u * u, f = c * c;
160
+ if (d == 0) {
161
+ let o = V(e, t, n, r), s = V(e, t, i, a);
162
+ return Math.max(o, s) <= f;
163
+ }
164
+ let p = u * (n - e) - l * (r - t), m = u * (i - e) - l * (a - t);
165
+ return Math.max(p * p, m * m) <= f * d;
166
+ }
167
+ function V(e, t, n, r) {
168
+ let i = n - e, a = r - t;
169
+ return i * i + a * a;
170
+ }
171
+ function H(e, t, n) {
172
+ return Math.max(t, Math.min(n, e));
173
+ }
174
+ //#endregion
175
+ //#region ../core/src/rendering/canvas2d/picking/renderers/index.js
176
+ var U = 1;
177
+ function W(e, t) {
178
+ let n = e.getType();
179
+ return n == "arrow" ? K(e, t) : n == "rect" ? q(e, t) : n == "point" ? J(e, t) : n == "rule" || n == "tick" ? ae(e, t) : n == "link" ? oe(e, t) : n == "text" ? se(e, t) : 0;
180
+ }
181
+ function G(e) {
182
+ let t = e.getType();
183
+ return t == "rect" || t == "arrow" || t == "point" || t == "rule" || t == "tick" || t == "link" || t == "text";
184
+ }
185
+ function K(e, t) {
186
+ let n = e, r = re(n), i = Array(8).fill(0);
187
+ return ie(n, r, t, (e) => {
188
+ let a = Y(n, e.datum), o = e.strokeWidth / 2;
189
+ r.stem && t.rasterizer.strokeSegment(a, e.tail.x, e.tail.y, e.tip.x, e.tip.y, e.stemHalfWidth * 2 + e.strokeWidth), k(e, (n, r) => {
190
+ let s = e.headHalfWidth + o, c = n + e.tangent.x * o, l = r + e.tangent.y * o, u = e.headRepeatFootprint + o, d = n - e.tangent.x * u, f = r - e.tangent.y * u;
191
+ ce(i, c, l, d, f, e.normal.x, e.normal.y, s), t.rasterizer.fillConvexPolygon(a, i);
192
+ });
193
+ });
194
+ }
195
+ function q(e, t) {
196
+ let n = e;
197
+ return D(n, b(n), t, (e) => t.rasterizer.fillRect(Y(n, e.datum), e.x, e.y, e.width, e.height));
198
+ }
199
+ function J(e, t) {
200
+ let n = e, r = _(n, n.properties.minPickingSize);
201
+ return S(n, x(n), t, (e) => t.rasterizer.fillSquare(Y(n, e.datum), e.x, e.y, Math.max(e.boundsRadius, r / 2)));
202
+ }
203
+ function ae(e, t) {
204
+ let n = e;
205
+ return ne(n, ee(n), t, (e) => t.rasterizer.strokeSegment(Y(n, e.datum), e.x1, e.y1, e.x2, e.y2, Math.max(e.strokeWidth, U)));
206
+ }
207
+ function oe(e, t) {
208
+ let n = e, r = _(n, n.properties.minPickingSize), i = te(n), a = C(n, i.shape);
209
+ return O(n, i, t, (e) => {
210
+ let [i, o, s, c] = e.points, l = a(e.datum), u = l && v(i, c, l);
211
+ t.rasterizer.strokeCubic(Y(n, e.datum), i[0], i[1], o[0], o[1], s[0], s[1], c[0], c[1], Math.max(e.strokeWidth, r), void 0, u ? (e, t) => Math.abs(u.normalX * e + u.normalY * t - u.offset) < u.end : void 0);
212
+ });
213
+ }
214
+ function se(e, t) {
215
+ let n = e;
216
+ return y(n, w(n), t, (e) => t.rasterizer.fillConvexPolygon(Y(n, e.datum), e.boundsQuad));
217
+ }
218
+ function ce(e, t, n, r, i, a, o, s) {
219
+ let c = a * s, l = o * s;
220
+ e[0] = t + c, e[1] = n + l, e[2] = r + c, e[3] = i + l, e[4] = r - c, e[5] = i - l, e[6] = t - c, e[7] = n - l;
221
+ }
222
+ function Y(e, t) {
223
+ let n = e.encoders;
224
+ return g(n.uniqueId, t);
225
+ }
226
+ //#endregion
227
+ //#region ../core/src/rendering/canvas2d/picking/softwarePickingViewRenderingContext.js
228
+ var le = class extends d {
229
+ #e = [];
230
+ #t = /* @__PURE__ */ new Set();
231
+ #n;
232
+ #r = new T();
233
+ #i;
234
+ #a = [0, 0];
235
+ constructor(e) {
236
+ super({ picking: !0 }), this.width = e.width, this.height = e.height, this.devicePixelRatio = e.devicePixelRatio, this.getRasterizer = e.getRasterizer, this.#n = c(), this.#i = e.xIndexManager;
237
+ }
238
+ getDevicePixelRatio() {
239
+ return this.devicePixelRatio;
240
+ }
241
+ pushView(e, t) {
242
+ this.#t.has(e) || (e.onBeforeRender(), this.#t.add(e)), this.#e.push({
243
+ view: e,
244
+ coords: t
245
+ });
246
+ }
247
+ popView(e) {
248
+ if (this.#e.pop()?.view !== e) throw Error("Unbalanced software picking view rendering context stack.");
249
+ }
250
+ renderMark(e, t) {
251
+ if (!e.isPickingParticipant() || !G(e)) return;
252
+ let r = t.sampleFacetRenderingOptions;
253
+ if (r && !e.encoders.facetIndex && (this.#n?.addCount("canvasSampleFacetOccurrences"), !A(r))) {
254
+ this.#n?.addCount("canvasCulledSampleFacetOccurrences");
255
+ return;
256
+ }
257
+ let a = e.unitView.getEffectiveOpacity();
258
+ if (a <= 0) return;
259
+ let o = this.currentCoords, c = n(t), l = i(c, e.properties.clip, o), u = h(this.width, this.height, l);
260
+ if (!E(u)) return;
261
+ let d = p(o, c, e.properties.cullByVisibleRange), f = this.#i?.prepare(e) ?? !1;
262
+ m(e, t, o, this.#r, (t, n) => {
263
+ if (n.length == 0) return;
264
+ let r = 0, i = n.length;
265
+ if (f && this.#i.query(n, this.#a) && (r = this.#a[0], i = this.#a[1], r === i)) return;
266
+ let o = this.getRasterizer();
267
+ o.setClip(u.x1, u.y1, u.x2, u.y2), W(e, {
268
+ rasterizer: o,
269
+ coords: t,
270
+ data: n,
271
+ start: r,
272
+ end: i,
273
+ visibleBounds: u,
274
+ anchorCullBounds: d,
275
+ viewOpacity: a
276
+ });
277
+ }, (t) => s(`Canvas2D picking could not resolve sample facet index ${t}. View: ${e.unitView.getPathString()}`));
278
+ }
279
+ get currentCoords() {
280
+ let e = t(this.#e);
281
+ if (!e) throw Error("No current view in software picking rendering context.");
282
+ return e.coords;
283
+ }
284
+ }, X = 2 ** 31 - 1, ue = -(2 ** 31);
285
+ function de(t, n, r, i = r) {
286
+ let a = Array(t);
287
+ a.fill(X);
288
+ let o = ue, s = -Infinity, c = !1, l = Array(t);
289
+ l.fill(0);
290
+ let u = n[0], d = (n[1] - n[0]) / t, f = (n, r) => {
291
+ let i = (n - u) / d, a = Math.floor(i);
292
+ return e(r && a == i ? a - 1 : a, 0, t - 1);
293
+ };
294
+ function p(e, t, n) {
295
+ if (c) return;
296
+ if (t > o) o = t;
297
+ else {
298
+ c = !0;
299
+ return;
300
+ }
301
+ let i = r(e);
302
+ if (!Number.isFinite(i) || i < s) {
303
+ c = !0;
304
+ return;
305
+ }
306
+ s = i;
307
+ let u = f(i, !1);
308
+ a[u] > t && (a[u] = t), l[u] < n && (l[u] = n);
309
+ }
310
+ function m(e, t, n) {
311
+ if (c) return;
312
+ if (t > o) o = t;
313
+ else {
314
+ c = !0, console.debug("Items (vertices) are not ordered properly. Disabling binned index.");
315
+ return;
316
+ }
317
+ let u = r(e), d = i(e);
318
+ if (!Number.isFinite(u) || !Number.isFinite(d)) {
319
+ c = !0;
320
+ return;
321
+ } else if (u < s) {
322
+ c = !0;
323
+ return;
324
+ } else if (d < u) {
325
+ c = !0;
326
+ return;
327
+ }
328
+ s = u;
329
+ let p = f(u, !1), m = u === d ? p : f(d, !0);
330
+ for (let e = p; e <= m; e++) a[e] > t && (a[e] = t), l[e] < n && (l[e] = n);
331
+ }
332
+ let h = (e, t, n = [0, 0]) => {
333
+ let r = f(e, !1), i = f(t, !0), o = a[r], s = Math.max(l[i], o);
334
+ return n[0] = o, n[1] = s, n;
335
+ }, g = () => {
336
+ if (c) return;
337
+ for (let e = 1; e < l.length; e++) l[e] < l[e - 1] && (l[e] = l[e - 1]);
338
+ let e = !0;
339
+ for (let t = a.length - 1; t > 0; t--) e && a[t] == X ? (a[t] = l[t], e = !1) : a[t - 1] > a[t] && (a[t - 1] = a[t]);
340
+ return h;
341
+ };
342
+ return p.getIndex = g, m.getIndex = g, r == i ? p : m;
343
+ }
344
+ //#endregion
345
+ //#region ../core/src/rendering/xIndex/markXIndex.js
346
+ function fe(e, t, n = 0) {
347
+ if (!t.length) return;
348
+ let r = de(Math.min(256, Math.ceil(Math.sqrt(t.length))), e.indexDomain, e.xAccessor, e.x2Accessor);
349
+ return t.forEach((e, t) => r(e, n + t, n + t + 1)), r.getIndex();
350
+ }
351
+ function pe(e) {
352
+ let t = e.encoders?.x, n = e.encoders?.x2;
353
+ if (!t?.channelDef || !("buildIndex" in t.channelDef) || !t.channelDef.buildIndex || !t.scale || !a(t.scale.type) && !["index", "locus"].includes(t.scale.type) || t.branches.length !== 1) return;
354
+ let i = e.getType();
355
+ if (i !== "point" && i !== "rect") return;
356
+ let o = r(t)?.asNumberAccessor();
357
+ if (!o) return;
358
+ let s;
359
+ if (n && (n.scale !== t.scale || n.branches.length !== 1 || (s = r(n)?.asNumberAccessor(), !s))) return;
360
+ let c = e.unitView.getScaleResolution("x"), l = c?.zoomExtent;
361
+ if (!(!c || !l || !Number.isFinite(l[0]) || !Number.isFinite(l[1]) || l[1] <= l[0])) return {
362
+ xAccessor: o,
363
+ x2Accessor: s,
364
+ scaleResolution: c,
365
+ indexDomain: [l[0], l[1]],
366
+ domainStartOffset: ["index", "locus"].includes(t.scale.type) ? -1 : 0
367
+ };
368
+ }
369
+ function me(e, t) {
370
+ let n = e.scaleResolution.getScale().domain();
371
+ if (n.length !== 2 || !Number.isFinite(n[0]) || !Number.isFinite(n[1]) || n[1] <= n[0]) return !1;
372
+ let r = n[1] - n[0];
373
+ return t[0] = n[0] + e.domainStartOffset - r, t[1] = n[1] + r, !0;
374
+ }
375
+ //#endregion
376
+ //#region ../core/src/rendering/canvas2d/canvasXIndexManager.js
377
+ var he = class {
378
+ #e = /* @__PURE__ */ new WeakMap();
379
+ #t = [0, 0];
380
+ #n;
381
+ prepare(e) {
382
+ if (this.#n = void 0, e.encoders.facetIndex) return this.#r();
383
+ let t = e.unitView.getCollector(), n = e.unitView.getScaleResolution("x"), r = n?.zoomExtent, i = this.#e.get(e);
384
+ if (!i || i.collector !== t || i.dataRevision !== t.dataRevision || i.xEncoder !== e.encoders.x || i.x2Encoder !== e.encoders.x2 || i.xScaleResolution !== n || i.xIndexDomainStart !== r?.[0] || i.xIndexDomainEnd !== r?.[1]) {
385
+ let a = pe(e);
386
+ i = {
387
+ collector: t,
388
+ dataRevision: t.dataRevision,
389
+ xEncoder: e.encoders.x,
390
+ x2Encoder: e.encoders.x2,
391
+ xScaleResolution: n,
392
+ xIndexDomainStart: r?.[0],
393
+ xIndexDomainEnd: r?.[1],
394
+ spec: a,
395
+ batches: /* @__PURE__ */ new WeakMap()
396
+ }, this.#e.set(e, i);
397
+ }
398
+ let a = i.spec;
399
+ return !a || !me(a, this.#t) ? this.#r() : (this.#n = i, !0);
400
+ }
401
+ query(e, t) {
402
+ let n = this.#n;
403
+ if (!n?.spec) throw Error("Canvas x-index query was not prepared.");
404
+ u("canvasXIndexNativeItems", e.length);
405
+ let r = n.batches.get(e);
406
+ return r === void 0 && (r = fe(n.spec, e) ?? null, n.batches.set(e, r), u("canvasXIndexBuilds"), r || u("canvasXIndexRejectedBuilds")), r ? (r(this.#t[0], this.#t[1], t), u("canvasXIndexQueries"), u("canvasXIndexCandidateItems", t[1] - t[0]), t[0] === t[1] && u("canvasXIndexEmptyRanges"), !0) : this.#r();
407
+ }
408
+ #r() {
409
+ return u("canvasXIndexFallbackQueries"), !1;
410
+ }
411
+ }, Z = class {
412
+ constructor(e) {
413
+ this.viewRoot = e.viewRoot, this.context = e.context, this.surface = e.surface, this.getBackground = e.getBackground, this.broadcast = e.broadcast, this.onLayoutComputed = e.onLayoutComputed, this.layoutResult = void 0, this.pickingRasterizer = void 0, this.dirtyPickingBuffer = !0, this.xIndexManager = new he(), this.opacityLayers = [];
414
+ }
415
+ computeLayout() {
416
+ this.broadcast("layout"), this.surface.invalidateSize();
417
+ let e = 5;
418
+ for (;;) {
419
+ let t = this.#e();
420
+ if (!t) return;
421
+ if (!this.surface.invalidateSize()) {
422
+ this.layoutResult = t, this.dirtyPickingBuffer = !0, this.onLayoutComputed(), this.broadcast("layoutComputed");
423
+ return;
424
+ }
425
+ if (e--, e == 0) throw Error("Layout did not settle: canvas size kept changing.");
426
+ }
427
+ }
428
+ renderAll() {
429
+ let e = this.layoutResult;
430
+ if (!e) return;
431
+ let t = this.surface.getLogicalCanvasSize();
432
+ if (isNaN(t.width) || isNaN(t.height)) return;
433
+ let n = c();
434
+ n?.beginFrame("canvas");
435
+ try {
436
+ l("render", () => j({
437
+ layoutResult: e,
438
+ context: this.context,
439
+ width: t.width,
440
+ height: t.height,
441
+ devicePixelRatio: this.surface.getDevicePixelRatio(),
442
+ background: this.getBackground(),
443
+ paint: !0,
444
+ xIndexManager: this.xIndexManager,
445
+ opacityLayers: this.opacityLayers
446
+ })), this.dirtyPickingBuffer = !0;
447
+ } finally {
448
+ n?.endFrame();
449
+ }
450
+ }
451
+ renderPickingFramebuffer() {
452
+ let e = this.layoutResult;
453
+ if (!this.dirtyPickingBuffer || !e) return;
454
+ let t = this.surface.getLogicalCanvasSize();
455
+ if (isNaN(t.width) || isNaN(t.height)) return;
456
+ this.surface.clearPickingBuffer();
457
+ let n = this.pickingRasterizer, r = !1, i = new le({
458
+ width: t.width,
459
+ height: t.height,
460
+ devicePixelRatio: this.surface.getDevicePixelRatio(),
461
+ getRasterizer: () => (n || (n = new R(this.surface.getPickingBuffer()), this.pickingRasterizer = n), r ||= (n.resetClip(), n.resetStatistics(), !0), n),
462
+ xIndexManager: this.xIndexManager
463
+ }), a = c();
464
+ a?.beginFrame("canvas", "picking");
465
+ try {
466
+ l("picking", () => e.collectRenderCommands(i)), this.dirtyPickingBuffer = !1, r && ge(n, a);
467
+ } finally {
468
+ a?.endFrame();
469
+ }
470
+ }
471
+ createPickingBufferVisualization() {
472
+ return this.dirtyPickingBuffer = !0, this.renderPickingFramebuffer(), this.surface.createPickingBufferVisualization();
473
+ }
474
+ #e() {
475
+ let e = this.surface.getLogicalCanvasSize();
476
+ if (!(isNaN(e.width) || isNaN(e.height))) return f(this.viewRoot, o.create(0, 0, e.width, e.height), {
477
+ devicePixelRatio: this.surface.getDevicePixelRatio(),
478
+ renderingOptions: { firstFacet: !0 }
479
+ });
480
+ }
481
+ };
482
+ function ge(e, t) {
483
+ if (!t) return;
484
+ let n = e.getStatistics();
485
+ t.addCount("pickingRectangles", n.rectangles), t.addCount("pickingSquares", n.squares), t.addCount("pickingPolygons", n.polygons), t.addCount("pickingSegments", n.segments), t.addCount("pickingCubics", n.cubics), t.addCount("pickingSpans", n.spans);
486
+ }
487
+ //#endregion
488
+ //#region ../core/src/rendering/canvas2d/picking/softwarePickingBuffer.js
489
+ var Q = /* @__PURE__ */ new Uint32Array(), _e = class {
490
+ #e = Q;
491
+ width = 0;
492
+ height = 0;
493
+ constructor(e = 0, t = 0) {
494
+ this.resize(e, t);
495
+ }
496
+ get ids() {
497
+ return this.#e;
498
+ }
499
+ resize(e, t) {
500
+ let n = $(e, "width"), r = $(t, "height");
501
+ if (n == this.width && r == this.height) return !1;
502
+ let i = n * r;
503
+ if (!Number.isSafeInteger(i)) throw RangeError("Software picking buffer is too large.");
504
+ return this.width = n, this.height = r, this.#e = i ? new Uint32Array(i) : Q, !0;
505
+ }
506
+ clear() {
507
+ this.#e.fill(0);
508
+ }
509
+ read(e, t) {
510
+ if (!Number.isFinite(e) || !Number.isFinite(t)) return 0;
511
+ let n = Math.floor(e), r = Math.floor(t);
512
+ return n < 0 || r < 0 || n >= this.width || r >= this.height ? 0 : this.#e[r * this.width + n];
513
+ }
514
+ dispose() {
515
+ this.width = 0, this.height = 0, this.#e = Q;
516
+ }
517
+ };
518
+ function $(e, t) {
519
+ if (!Number.isFinite(e) || e < 0) throw RangeError(`Software picking buffer ${t} must be a finite nonnegative number.`);
520
+ return Math.floor(e);
521
+ }
522
+ //#endregion
523
+ //#region ../core/src/rendering/canvas2d/canvas2DSurface.js
524
+ var ve = class {
525
+ #e;
526
+ #t;
527
+ #n;
528
+ #r = !1;
529
+ constructor(e) {
530
+ let t = document.createElement("canvas"), n = t.getContext("2d");
531
+ if (!n) throw Error("Unable to initialize a Canvas2D rendering context.");
532
+ this.canvas = t, this.context = n, e.container.appendChild(t);
533
+ try {
534
+ this.#e = new M(e.container, t, e.sizeSource, () => {
535
+ this.#i() && e.onCanvasResize();
536
+ }), this.#i();
537
+ } catch (e) {
538
+ throw this.#e?.finalize(), t.remove(), e;
539
+ }
540
+ }
541
+ invalidateSize() {
542
+ return this.#e.invalidate(), this.#i();
543
+ }
544
+ #i() {
545
+ let e = this.getLogicalCanvasSize(), t = this.#e.getPhysicalCanvasSize(e);
546
+ return this.#t?.logicalWidth == e.width && this.#t.logicalHeight == e.height && this.#t.physicalWidth == t.width && this.#t.physicalHeight == t.height ? !1 : (this.canvas.style.width = `${e.width}px`, this.canvas.style.height = `${e.height}px`, this.canvas.width = t.width, this.canvas.height = t.height, this.#t = {
547
+ logicalWidth: e.width,
548
+ logicalHeight: e.height,
549
+ physicalWidth: t.width,
550
+ physicalHeight: t.height
551
+ }, this.#n?.resize(e.width, e.height), !0);
552
+ }
553
+ getLogicalCanvasSize() {
554
+ return this.#e.getLogicalCanvasSize();
555
+ }
556
+ getDevicePixelRatio() {
557
+ return this.#e.getDevicePixelRatio();
558
+ }
559
+ getPickingBuffer() {
560
+ if (this.#r) throw Error("Canvas2D surface has been finalized.");
561
+ let e = this.getLogicalCanvasSize();
562
+ return this.#n ??= new _e(e.width, e.height), this.#n;
563
+ }
564
+ clearPickingBuffer() {
565
+ this.#n?.clear();
566
+ }
567
+ readPickingId(e, t) {
568
+ return this.#r ? 0 : this.#n?.read(e, t) ?? 0;
569
+ }
570
+ createPickingBufferVisualization() {
571
+ if (this.#r) return;
572
+ let e = this.getPickingBuffer(), t = document.createElement("canvas");
573
+ t.width = e.width, t.height = e.height;
574
+ let n = t.getContext("2d");
575
+ if (!n) throw Error("Unable to initialize a Canvas2D picking visualization context.");
576
+ if (e.width > 0 && e.height > 0) {
577
+ let t = n.createImageData(e.width, e.height);
578
+ for (let n = 0; n < e.ids.length; n++) {
579
+ let r = e.ids[n], i = n * 4;
580
+ if (r != 0) {
581
+ let e = Math.imul(r ^ r >>> 16, 73244475);
582
+ t.data[i] = 64 + (e & 127), t.data[i + 1] = 64 + (e >>> 8 & 127), t.data[i + 2] = 64 + (e >>> 16 & 127);
583
+ }
584
+ t.data[i + 3] = 255;
585
+ }
586
+ n.putImageData(t, 0, 0);
587
+ }
588
+ return t;
589
+ }
590
+ finalize() {
591
+ this.#r || (this.#r = !0, this.#n?.dispose(), this.#n = void 0, this.#e.finalize(), this.canvas.remove());
592
+ }
593
+ };
594
+ //#endregion
595
+ //#region ../core/src/rendering/canvas2d/index.js
596
+ function ye(e) {
597
+ let t = new ve(e);
598
+ return {
599
+ surface: t,
600
+ createRenderCoordinator: (e) => new Z({
601
+ ...e,
602
+ surface: t,
603
+ context: t.context
604
+ }),
605
+ exportCanvas: (e) => N({
606
+ ...e,
607
+ liveSize: t.getLogicalCanvasSize(),
608
+ liveDevicePixelRatio: t.getDevicePixelRatio()
609
+ }),
610
+ exportRaster: (e) => P({
611
+ ...e,
612
+ liveSize: t.getLogicalCanvasSize(),
613
+ liveDevicePixelRatio: t.getDevicePixelRatio()
614
+ }),
615
+ rasterizeSvgRuns: (e) => F()(e),
616
+ readPickingId: (e, n) => t.readPickingId(e, n)
617
+ };
618
+ }
619
+ //#endregion
620
+ export { ye as createCanvas2DRenderingBackend };