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