@genome-spy/app 0.84.0 → 0.85.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.
- package/dist/{agentApi-DHXYZVvQ.js → agentApi-Cz0hCnVp.js} +5790 -5190
- package/dist/agentApi.es.js +3117 -2793
- package/dist/agentShared.es.js +8 -8
- package/dist/arrayUtils-LJpQOu-U.js +2175 -0
- package/dist/canvas2d-DoAXEiF9.js +309 -0
- package/dist/canvas2d-f5jl4A5D.js +310 -0
- package/dist/canvasSizeHelper-7h_8rOcx.js +56 -0
- package/dist/clipOptions-gqdb3fvW.js +43 -0
- package/dist/{clipOptions-Dqco1p8b.js → color-W5zffv-z.js} +1 -43
- package/dist/{debug-aHQsa6hU.js → debug-BvCZWumf.js} +2 -2
- package/dist/{debug-D6FqxKEj.js → debug-CgDtmspT.js} +2 -2
- package/dist/{esm-CGLz7idZ.js → esm-BA6yMcc-.js} +438 -434
- package/dist/{esm-D8vvQAP3.js → esm-CcDLRSvC.js} +33 -33
- package/dist/{esm-BeV56E_5.js → esm-CfYZhLHN.js} +33 -33
- package/dist/{esm-DQ3lJSQN.js → esm-JAiZmFIS.js} +1 -1
- package/dist/{framebufferReadback-CC0D6Haw.js → framebufferReadback-CCLOjStu.js} +26 -25
- package/dist/{framebufferReadback-Bje9lHb7.js → framebufferReadback-THWwFqs8.js} +14 -13
- package/dist/index.es.js +541 -538
- package/dist/index.js +560 -554
- package/dist/nativeText-DMO8gLt7.js +806 -0
- package/dist/nativeText-m5AUINMq.js +806 -0
- package/dist/paramUtils-BYI4rwyL.js +2195 -0
- package/dist/schema.json +1488 -88
- package/dist/style.css +1 -1
- package/dist/svg-CCu8kYy2.js +1158 -0
- package/dist/svg-yFj875aX.js +1158 -0
- package/dist/{svgNumber-C6aRPc8Z.js → svgNumber-DNxESJQB.js} +1 -1
- package/dist/{twgl-full.module-BNEMlXRV.js → twgl-full.module-DB2UdP1k.js} +1 -1
- package/dist/{viewIdentityRegistry-AEQpJTDm.js → viewIdentityRegistry-BUdkK9zT.js} +1 -1
- package/dist/{viewIdentityRegistry-Dl7rR4Ay.js → viewIdentityRegistry-D3oPbN4O.js} +1 -1
- package/dist/viewSelectors-DGCspRN3.js +4198 -0
- package/dist/viewSelectors-U5oLCLHV.js +4195 -0
- package/dist/{viewUtils-DMNiWslc.js → viewUtils-Dg4RA40Q.js} +2384 -2109
- package/dist/warning-CpIIpk8e.js +7 -0
- package/dist/warning-DRGdb6BF.js +59 -0
- package/dist/{raster-BofBWXbe.js → webgl-Ci6ZhCCf.js} +4 -4
- package/dist/{raster-9uKYMjHZ.js → webgl-Dpz8a3TI.js} +3 -3
- package/package.json +5 -5
- package/dist/svg-CvsT1Y2V.js +0 -1793
- package/dist/svg-DRgWfcsL.js +0 -1793
- package/dist/viewSelectors-BhW4mTR1.js +0 -6386
- package/dist/viewSelectors-Bwzj10Qz.js +0 -6363
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import { Vt as e } from "./paramUtils-BYI4rwyL.js";
|
|
2
|
+
import { a as t, o as n } from "./clipOptions-gqdb3fvW.js";
|
|
3
|
+
import { n as r, t as i } from "./warning-DRGdb6BF.js";
|
|
4
|
+
import { n as a, t as o } from "./viewRenderingContext-HtpqwS_x.js";
|
|
5
|
+
import { C as s, E as c, S as l, _ as u, a as d, b as f, c as p, d as m, f as h, g, h as _, i as v, l as y, m as b, n as x, o as S, p as C, r as w, s as T, t as E, u as D, w as O, x as k } from "./nativeText-DMO8gLt7.js";
|
|
6
|
+
//#region ../core/src/rendering/canvas2d/renderers/arrow.js
|
|
7
|
+
function A(e, t) {
|
|
8
|
+
let n = e, r = t.context, i = n.encoders, a = _(n);
|
|
9
|
+
r.lineJoin = "miter";
|
|
10
|
+
let o, s;
|
|
11
|
+
return g(n, a, t, (e) => {
|
|
12
|
+
e.headShapeFallback && t.warn(`Canvas2D rendered unsupported arrow headShape "${a.headShape}" as a triangle.`), r.beginPath();
|
|
13
|
+
for (let t of e.boundaryLoops) {
|
|
14
|
+
let e = t[0];
|
|
15
|
+
r.moveTo(e.x, e.y);
|
|
16
|
+
for (let e = 1; e < t.length; e++) r.lineTo(t[e].x, t[e].y);
|
|
17
|
+
r.closePath();
|
|
18
|
+
}
|
|
19
|
+
let n = k(i.fill(e.datum)), c = u(i.fillOpacity, e.datum) * t.viewOpacity;
|
|
20
|
+
n != "none" && c > 0 && (o != n && (r.fillStyle = n, o = n), r.globalAlpha = c, r.fill());
|
|
21
|
+
let l = k(i.stroke(e.datum)), d = u(i.strokeOpacity, e.datum) * t.viewOpacity;
|
|
22
|
+
l != "none" && d > 0 && e.strokeWidth > 0 && (s != l && (r.strokeStyle = l, s = l), r.globalAlpha = d, r.lineWidth = e.strokeWidth, r.stroke());
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ../core/src/rendering/canvas2d/renderers/link.js
|
|
27
|
+
function j(e, t) {
|
|
28
|
+
let n = e, r = t.context, i = n.encoders, a = f(n, n.properties.arcFadingDistance), o = C(n);
|
|
29
|
+
o.shape == "arc" && a !== !1 && a[0] > 0 && a[1] > 0 && t.warn("Canvas2D ignored unsupported link arc fading."), r.lineCap = "butt";
|
|
30
|
+
let s;
|
|
31
|
+
return b(n, o, t, (e) => {
|
|
32
|
+
let n = k(i.color(e.datum)), a = u(i.opacity, e.datum) * t.viewOpacity;
|
|
33
|
+
if (n == "none" || a <= 0 || e.strokeWidth <= 0) return;
|
|
34
|
+
s != n && (r.strokeStyle = n, s = n), r.globalAlpha = a, r.lineWidth = e.strokeWidth;
|
|
35
|
+
let [o, c, l, d] = e.points;
|
|
36
|
+
r.beginPath(), r.moveTo(o[0], o[1]), r.bezierCurveTo(c[0], c[1], l[0], l[1], d[0], d[1]), r.stroke();
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region ../core/src/rendering/canvas2d/renderers/point.js
|
|
41
|
+
function M(e, t) {
|
|
42
|
+
let n = e;
|
|
43
|
+
f(n, n.properties.fillGradientStrength) && t.warn("Canvas2D ignored unsupported point property fillGradientStrength."), n.properties.geometricZoomBound && t.warn("Canvas2D ignored unsupported point property geometricZoomBound.");
|
|
44
|
+
let r = m(n), i = t.context, a = n.encoders, o, s;
|
|
45
|
+
return h(n, r, t, (e) => {
|
|
46
|
+
let n = e.datum, r = e.lineShape, c = k(a.fill(n)), l = u(a.fillOpacity, n) * t.viewOpacity, d = k(a.stroke(n)), f = u(a.strokeOpacity, n) * t.viewOpacity;
|
|
47
|
+
r && (d == "none" || f <= 0) && (d = c, f = l), i.beginPath();
|
|
48
|
+
let p = e.angle != 0 && e.shape != "circle";
|
|
49
|
+
p && (i.save(), i.translate(e.x, e.y), i.rotate(e.angle * Math.PI / 180));
|
|
50
|
+
let m = p ? 0 : e.x, h = p ? 0 : e.y, g = !0;
|
|
51
|
+
if (e.shape == "circle") i.arc(m, h, e.geometryRadius, 0, Math.PI * 2);
|
|
52
|
+
else if (e.shape == "square") {
|
|
53
|
+
let t = e.geometryRadius * 2;
|
|
54
|
+
i.rect(m - e.geometryRadius, h - e.geometryRadius, t, t);
|
|
55
|
+
} else g = D(e.shape, m, h, e.geometryRadius, i);
|
|
56
|
+
p && i.restore(), g || (t.warn(`Canvas2D rendered unsupported point shape "${e.shape}" as a circle.`), i.arc(e.x, e.y, e.geometryRadius, 0, Math.PI * 2)), !r && c != "none" && l > 0 && (o != c && (i.fillStyle = c, o = c), N(i, l), i.fill()), d != "none" && f > 0 && e.strokeWidth > 0 && (r && i.lineCap != "butt" && (i.lineCap = "butt"), s != d && (i.strokeStyle = d, s = d), N(i, f), P(i, e.strokeWidth), i.stroke());
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function N(e, t) {
|
|
60
|
+
e.globalAlpha != t && (e.globalAlpha = t);
|
|
61
|
+
}
|
|
62
|
+
function P(e, t) {
|
|
63
|
+
e.lineWidth != t && (e.lineWidth = t);
|
|
64
|
+
}
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region ../core/src/rendering/canvas2d/renderers/rect.js
|
|
67
|
+
function F(e, t) {
|
|
68
|
+
let n = e, r = p(n);
|
|
69
|
+
r.hatch != "none" && t.warn("Canvas2D ignored unsupported rect hatch."), r.shadow.opacity > 0 && t.warn("Canvas2D ignored unsupported rect shadow.");
|
|
70
|
+
let i = t.context, a = n.encoders, o, s, c = [
|
|
71
|
+
0,
|
|
72
|
+
0,
|
|
73
|
+
0,
|
|
74
|
+
0
|
|
75
|
+
];
|
|
76
|
+
return y(n, r, t, (e) => {
|
|
77
|
+
let n = e.opacityFactor, r = e.fill != "none" && e.fillOpacity > 0, l = k(a.stroke(e.datum)), d = u(a.strokeOpacity, e.datum) * t.viewOpacity * n, f = l != "none" && d > 0 && e.strokeWidth > 0, p = e.radii.topLeft != 0 || e.radii.topRight != 0 || e.radii.bottomRight != 0 || e.radii.bottomLeft != 0;
|
|
78
|
+
p && (r || f) && (c[0] = e.radii.topLeft, c[1] = e.radii.topRight, c[2] = e.radii.bottomRight, c[3] = e.radii.bottomLeft, i.beginPath(), i.roundRect(e.x, e.y, e.width, e.height, c)), r && (o != e.fill && (i.fillStyle = e.fill, o = e.fill), I(i, e.fillOpacity * n), p ? i.fill() : i.fillRect(e.x, e.y, e.width, e.height)), f && (s != l && (i.strokeStyle = l, s = l), I(i, d), L(i, e.strokeWidth), p ? i.stroke() : i.strokeRect(e.x, e.y, e.width, e.height));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
function I(e, t) {
|
|
82
|
+
e.globalAlpha != t && (e.globalAlpha = t);
|
|
83
|
+
}
|
|
84
|
+
function L(e, t) {
|
|
85
|
+
e.lineWidth != t && (e.lineWidth = t);
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region ../core/src/rendering/canvas2d/renderers/rule.js
|
|
89
|
+
function R(e, t) {
|
|
90
|
+
let n = e, r = t.context, i = n.encoders;
|
|
91
|
+
r.lineCap = f(n, n.properties.strokeCap), r.setLineDash(f(n, n.properties.strokeDash) ?? []), r.lineDashOffset = f(n, n.properties.strokeDashOffset);
|
|
92
|
+
let a;
|
|
93
|
+
return T(n, S(n), t, (e) => {
|
|
94
|
+
let n = k(i.color(e.datum)), o = u(i.opacity, e.datum) * t.viewOpacity;
|
|
95
|
+
n == "none" || o <= 0 || e.strokeWidth <= 0 || (a != n && (r.strokeStyle = n, a = n), r.globalAlpha = o, r.lineWidth = e.strokeWidth, r.beginPath(), r.moveTo(e.x1, e.y1), r.lineTo(e.x2, e.y2), r.stroke());
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region ../core/src/rendering/canvas2d/renderers/text.js
|
|
100
|
+
function z(e, t) {
|
|
101
|
+
let n = e, r = n.properties, i = v(n), a = t.context, o = n.encoders, s = E(r.font), c = `${r.fontStyle ?? "normal"} ${w(r.fontWeight ?? "normal")} `, l = i.baseline == "baseline" ? "alphabetic" : i.baseline;
|
|
102
|
+
[
|
|
103
|
+
r.viewportEdgeFadeWidthTop,
|
|
104
|
+
r.viewportEdgeFadeWidthRight,
|
|
105
|
+
r.viewportEdgeFadeWidthBottom,
|
|
106
|
+
r.viewportEdgeFadeWidthLeft
|
|
107
|
+
].some((e) => f(n, e) > 0) && t.warn("Canvas2D ignored unsupported text viewport edge fading.");
|
|
108
|
+
let p, m;
|
|
109
|
+
return i.logoLetters || (a.textAlign = i.align, a.textBaseline = l), d(n, i, t, (e) => {
|
|
110
|
+
e.multiCharacterLogo && t.warn("Canvas2D stretches multi-character logo text as a single glyph cell.");
|
|
111
|
+
let n = k(o.color(e.datum)), r = u(o.opacity, e.datum) * t.viewOpacity * e.fadeOpacity;
|
|
112
|
+
if (!(n == "none" || r <= 0)) if (p != n && (a.fillStyle = n, p = n), a.globalAlpha = r, m != e.size && (a.font = `${c}${e.size}px ${s}`, m = e.size), e.logoScale) {
|
|
113
|
+
a.save(), a.translate(e.x, e.y), a.rotate(e.angle * Math.PI / 180), a.translate(e.dx, e.dy);
|
|
114
|
+
let t = a.measureText(e.text).width;
|
|
115
|
+
a.scale(e.logoScale.width / t, e.logoScale.heightScale), a.textAlign = "center", a.textBaseline = "alphabetic", a.fillText(e.text, 0, x("middle", 1)), a.restore();
|
|
116
|
+
} else e.angle ? (a.save(), a.translate(e.x, e.y), a.rotate(e.angle * Math.PI / 180), a.fillText(e.text, e.dx, e.dy, e.width), a.restore()) : a.fillText(e.text, e.x + e.dx, e.y + e.dy, e.width);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region ../core/src/rendering/canvas2d/renderers/index.js
|
|
121
|
+
function B(e, t) {
|
|
122
|
+
return e.getType() == "arrow" ? A(e, t) : e.getType() == "link" ? j(e, t) : e.getType() == "rect" ? F(e, t) : e.getType() == "point" ? M(e, t) : e.getType() == "rule" || e.getType() == "tick" ? R(e, t) : e.getType() == "text" ? z(e, t) : (t.warn(`Canvas2D rendering is not implemented for mark type "${e.getType()}".`), 0);
|
|
123
|
+
}
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region ../core/src/rendering/canvas2d/canvas2DViewRenderingContext.js
|
|
126
|
+
var V = class extends o {
|
|
127
|
+
#e = [];
|
|
128
|
+
#t = /* @__PURE__ */ new Set();
|
|
129
|
+
constructor(e, t) {
|
|
130
|
+
if (super(e), this.context = t.context, this.width = t.width, this.height = t.height, this.devicePixelRatio = t.devicePixelRatio, this.paint = t.paint, this.paint) {
|
|
131
|
+
let e = this.context;
|
|
132
|
+
e.resetTransform(), e.clearRect(0, 0, e.canvas.width, e.canvas.height), e.setTransform(this.devicePixelRatio, 0, 0, this.devicePixelRatio, 0, 0), e.globalAlpha = 1, e.globalCompositeOperation = "source-over", t.background != null && (e.fillStyle = t.background, e.fillRect(0, 0, this.width, this.height));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
getDevicePixelRatio() {
|
|
136
|
+
return this.devicePixelRatio;
|
|
137
|
+
}
|
|
138
|
+
pushView(e, t) {
|
|
139
|
+
this.paint && !this.#t.has(e) && (e.onBeforeRender(), this.#t.add(e)), this.#e.push({
|
|
140
|
+
view: e,
|
|
141
|
+
coords: t
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
popView(e) {
|
|
145
|
+
if (this.#e.pop()?.view !== e) throw Error("Unbalanced Canvas2D view rendering context stack.");
|
|
146
|
+
}
|
|
147
|
+
renderMark(e, r) {
|
|
148
|
+
if (!this.paint || e.unitView.getEffectiveOpacity() <= 0) return;
|
|
149
|
+
let a = this.currentCoords, o = t(r), u = n(o, e.properties.clip, a), d = s(this.width, this.height, u);
|
|
150
|
+
if (!O(d)) return;
|
|
151
|
+
let f = l(a, o, e.properties.cullByVisibleRange), p = this.context;
|
|
152
|
+
if (p.save(), u) {
|
|
153
|
+
let e = u.rect.flatten(), t = u.clipX ? e.x : 0, n = u.clipY ? e.y : 0, r = u.clipX ? e.width : this.width, i = u.clipY ? e.height : this.height;
|
|
154
|
+
p.beginPath(), p.rect(t, n, r, i), p.clip();
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
c(e, r, a, (t, n) => B(e, {
|
|
158
|
+
context: p,
|
|
159
|
+
coords: t,
|
|
160
|
+
data: n,
|
|
161
|
+
visibleBounds: d,
|
|
162
|
+
anchorCullBounds: f,
|
|
163
|
+
viewOpacity: e.unitView.getEffectiveOpacity(),
|
|
164
|
+
warn: (t) => i(`${t} View: ${e.unitView.getPathString()}`)
|
|
165
|
+
}), (t) => i(`Canvas2D could not resolve sample facet index ${t}. View: ${e.unitView.getPathString()}`));
|
|
166
|
+
} finally {
|
|
167
|
+
p.restore();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
get currentCoords() {
|
|
171
|
+
let t = e(this.#e);
|
|
172
|
+
if (!t) throw Error("No current view in Canvas2D rendering context.");
|
|
173
|
+
return t.coords;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region ../core/src/rendering/canvas2d/renderCanvas2D.js
|
|
178
|
+
function H(e) {
|
|
179
|
+
let t = new V({ picking: !1 }, e);
|
|
180
|
+
e.viewRoot.render(t, a.create(0, 0, e.width, e.height), { firstFacet: !0 });
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region ../core/src/rendering/canvas2d/canvas2DRenderCoordinator.js
|
|
184
|
+
var U = class {
|
|
185
|
+
constructor(e) {
|
|
186
|
+
this.viewRoot = e.viewRoot, this.context = e.context, this.surface = e.surface, this.getBackground = e.getBackground, this.broadcast = e.broadcast, this.onLayoutComputed = e.onLayoutComputed;
|
|
187
|
+
}
|
|
188
|
+
computeLayout() {
|
|
189
|
+
this.broadcast("layout"), this.surface.invalidateSize();
|
|
190
|
+
let e = 5;
|
|
191
|
+
for (;;) {
|
|
192
|
+
if (this.#e(!1), !this.surface.invalidateSize()) {
|
|
193
|
+
this.onLayoutComputed(), this.broadcast("layoutComputed");
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (e--, e == 0) throw Error("Layout did not settle: canvas size kept changing.");
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
renderAll() {
|
|
200
|
+
this.#e(!0);
|
|
201
|
+
}
|
|
202
|
+
#e(e) {
|
|
203
|
+
let t = this.surface.getLogicalCanvasSize();
|
|
204
|
+
isNaN(t.width) || isNaN(t.height) || H({
|
|
205
|
+
viewRoot: this.viewRoot,
|
|
206
|
+
context: this.context,
|
|
207
|
+
width: t.width,
|
|
208
|
+
height: t.height,
|
|
209
|
+
devicePixelRatio: this.surface.getDevicePixelRatio(),
|
|
210
|
+
background: this.getBackground(),
|
|
211
|
+
paint: e
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}, W = class {
|
|
215
|
+
#e;
|
|
216
|
+
#t;
|
|
217
|
+
constructor(e) {
|
|
218
|
+
let t = document.createElement("canvas"), n = t.getContext("2d");
|
|
219
|
+
if (!n) throw Error("Unable to initialize a Canvas2D rendering context.");
|
|
220
|
+
this.canvas = t, this.context = n, e.container.appendChild(t);
|
|
221
|
+
try {
|
|
222
|
+
this.#e = new r(e.container, t, e.sizeSource, () => {
|
|
223
|
+
this.#n() && e.onCanvasResize();
|
|
224
|
+
}), this.#n();
|
|
225
|
+
} catch (e) {
|
|
226
|
+
throw this.#e?.finalize(), t.remove(), e;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
invalidateSize() {
|
|
230
|
+
return this.#e.invalidate(), this.#n();
|
|
231
|
+
}
|
|
232
|
+
#n() {
|
|
233
|
+
let e = this.getLogicalCanvasSize(), t = this.#e.getPhysicalCanvasSize(e);
|
|
234
|
+
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 = {
|
|
235
|
+
logicalWidth: e.width,
|
|
236
|
+
logicalHeight: e.height,
|
|
237
|
+
physicalWidth: t.width,
|
|
238
|
+
physicalHeight: t.height
|
|
239
|
+
}, !0);
|
|
240
|
+
}
|
|
241
|
+
getLogicalCanvasSize() {
|
|
242
|
+
return this.#e.getLogicalCanvasSize();
|
|
243
|
+
}
|
|
244
|
+
getDevicePixelRatio() {
|
|
245
|
+
return this.#e.getDevicePixelRatio();
|
|
246
|
+
}
|
|
247
|
+
finalize() {
|
|
248
|
+
this.#e.finalize(), this.canvas.remove();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region ../core/src/rendering/canvas2d/rasterExport.js
|
|
253
|
+
async function G(e) {
|
|
254
|
+
let t = e.mimeType ?? "image/png";
|
|
255
|
+
if (t != "image/png") throw Error(`Unsupported raster export MIME type: ${t}`);
|
|
256
|
+
let n = q(e);
|
|
257
|
+
return new Promise((e, r) => {
|
|
258
|
+
n.toBlob((t) => {
|
|
259
|
+
t ? e(t) : r(/* @__PURE__ */ Error("Canvas2D could not encode the raster export."));
|
|
260
|
+
}, t);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
function K(e) {
|
|
264
|
+
return q({
|
|
265
|
+
...e,
|
|
266
|
+
pixelRatio: e.devicePixelRatio ?? e.pixelRatio
|
|
267
|
+
}).toDataURL("image/png");
|
|
268
|
+
}
|
|
269
|
+
function q(e) {
|
|
270
|
+
let t = e.logicalWidth ?? e.liveSize.width, n = e.logicalHeight ?? e.liveSize.height, r = e.pixelRatio ?? e.liveDevicePixelRatio, i = document.createElement("canvas");
|
|
271
|
+
i.width = Math.floor(t * r), i.height = Math.floor(n * r);
|
|
272
|
+
let a = i.getContext("2d");
|
|
273
|
+
if (!a) throw Error("Unable to initialize a Canvas2D export context.");
|
|
274
|
+
return H({
|
|
275
|
+
viewRoot: e.viewRoot,
|
|
276
|
+
context: a,
|
|
277
|
+
width: t,
|
|
278
|
+
height: n,
|
|
279
|
+
devicePixelRatio: r,
|
|
280
|
+
background: e.clearColor ?? null,
|
|
281
|
+
paint: !0
|
|
282
|
+
}), i;
|
|
283
|
+
}
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region ../core/src/rendering/canvas2d/index.js
|
|
286
|
+
function J(e) {
|
|
287
|
+
let t = new W(e);
|
|
288
|
+
return {
|
|
289
|
+
surface: t,
|
|
290
|
+
glHelper: void 0,
|
|
291
|
+
createRenderCoordinator: (e) => new U({
|
|
292
|
+
...e,
|
|
293
|
+
surface: t,
|
|
294
|
+
context: t.context
|
|
295
|
+
}),
|
|
296
|
+
exportCanvas: (e) => K({
|
|
297
|
+
...e,
|
|
298
|
+
liveSize: t.getLogicalCanvasSize(),
|
|
299
|
+
liveDevicePixelRatio: t.getDevicePixelRatio()
|
|
300
|
+
}),
|
|
301
|
+
exportRaster: (e) => G({
|
|
302
|
+
...e,
|
|
303
|
+
liveSize: t.getLogicalCanvasSize(),
|
|
304
|
+
liveDevicePixelRatio: t.getDevicePixelRatio()
|
|
305
|
+
})
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
export { J as createCanvas2DRenderingBackend };
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { r as e } from "./arrayUtils-LJpQOu-U.js";
|
|
2
|
+
import { a as t, o as n } from "./clipOptions-gqdb3fvW.js";
|
|
3
|
+
import { t as r } from "./canvasSizeHelper-7h_8rOcx.js";
|
|
4
|
+
import { n as i, t as a } from "./viewRenderingContext-HtpqwS_x.js";
|
|
5
|
+
import { t as o } from "./warning-CpIIpk8e.js";
|
|
6
|
+
import { C as s, E as c, S as l, _ as u, a as d, b as f, c as p, d as m, f as h, g, h as _, i as v, l as y, m as b, n as x, o as S, p as C, r as w, s as T, t as E, u as D, w as O, x as k } from "./nativeText-m5AUINMq.js";
|
|
7
|
+
//#region ../core/src/rendering/canvas2d/renderers/arrow.js
|
|
8
|
+
function A(e, t) {
|
|
9
|
+
let n = e, r = t.context, i = n.encoders, a = _(n);
|
|
10
|
+
r.lineJoin = "miter";
|
|
11
|
+
let o, s;
|
|
12
|
+
return g(n, a, t, (e) => {
|
|
13
|
+
e.headShapeFallback && t.warn(`Canvas2D rendered unsupported arrow headShape "${a.headShape}" as a triangle.`), r.beginPath();
|
|
14
|
+
for (let t of e.boundaryLoops) {
|
|
15
|
+
let e = t[0];
|
|
16
|
+
r.moveTo(e.x, e.y);
|
|
17
|
+
for (let e = 1; e < t.length; e++) r.lineTo(t[e].x, t[e].y);
|
|
18
|
+
r.closePath();
|
|
19
|
+
}
|
|
20
|
+
let n = k(i.fill(e.datum)), c = u(i.fillOpacity, e.datum) * t.viewOpacity;
|
|
21
|
+
n != "none" && c > 0 && (o != n && (r.fillStyle = n, o = n), r.globalAlpha = c, r.fill());
|
|
22
|
+
let l = k(i.stroke(e.datum)), d = u(i.strokeOpacity, e.datum) * t.viewOpacity;
|
|
23
|
+
l != "none" && d > 0 && e.strokeWidth > 0 && (s != l && (r.strokeStyle = l, s = l), r.globalAlpha = d, r.lineWidth = e.strokeWidth, r.stroke());
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region ../core/src/rendering/canvas2d/renderers/link.js
|
|
28
|
+
function j(e, t) {
|
|
29
|
+
let n = e, r = t.context, i = n.encoders, a = f(n, n.properties.arcFadingDistance), o = C(n);
|
|
30
|
+
o.shape == "arc" && a !== !1 && a[0] > 0 && a[1] > 0 && t.warn("Canvas2D ignored unsupported link arc fading."), r.lineCap = "butt";
|
|
31
|
+
let s;
|
|
32
|
+
return b(n, o, t, (e) => {
|
|
33
|
+
let n = k(i.color(e.datum)), a = u(i.opacity, e.datum) * t.viewOpacity;
|
|
34
|
+
if (n == "none" || a <= 0 || e.strokeWidth <= 0) return;
|
|
35
|
+
s != n && (r.strokeStyle = n, s = n), r.globalAlpha = a, r.lineWidth = e.strokeWidth;
|
|
36
|
+
let [o, c, l, d] = e.points;
|
|
37
|
+
r.beginPath(), r.moveTo(o[0], o[1]), r.bezierCurveTo(c[0], c[1], l[0], l[1], d[0], d[1]), r.stroke();
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region ../core/src/rendering/canvas2d/renderers/point.js
|
|
42
|
+
function M(e, t) {
|
|
43
|
+
let n = e;
|
|
44
|
+
f(n, n.properties.fillGradientStrength) && t.warn("Canvas2D ignored unsupported point property fillGradientStrength."), n.properties.geometricZoomBound && t.warn("Canvas2D ignored unsupported point property geometricZoomBound.");
|
|
45
|
+
let r = m(n), i = t.context, a = n.encoders, o, s;
|
|
46
|
+
return h(n, r, t, (e) => {
|
|
47
|
+
let n = e.datum, r = e.lineShape, c = k(a.fill(n)), l = u(a.fillOpacity, n) * t.viewOpacity, d = k(a.stroke(n)), f = u(a.strokeOpacity, n) * t.viewOpacity;
|
|
48
|
+
r && (d == "none" || f <= 0) && (d = c, f = l), i.beginPath();
|
|
49
|
+
let p = e.angle != 0 && e.shape != "circle";
|
|
50
|
+
p && (i.save(), i.translate(e.x, e.y), i.rotate(e.angle * Math.PI / 180));
|
|
51
|
+
let m = p ? 0 : e.x, h = p ? 0 : e.y, g = !0;
|
|
52
|
+
if (e.shape == "circle") i.arc(m, h, e.geometryRadius, 0, Math.PI * 2);
|
|
53
|
+
else if (e.shape == "square") {
|
|
54
|
+
let t = e.geometryRadius * 2;
|
|
55
|
+
i.rect(m - e.geometryRadius, h - e.geometryRadius, t, t);
|
|
56
|
+
} else g = D(e.shape, m, h, e.geometryRadius, i);
|
|
57
|
+
p && i.restore(), g || (t.warn(`Canvas2D rendered unsupported point shape "${e.shape}" as a circle.`), i.arc(e.x, e.y, e.geometryRadius, 0, Math.PI * 2)), !r && c != "none" && l > 0 && (o != c && (i.fillStyle = c, o = c), N(i, l), i.fill()), d != "none" && f > 0 && e.strokeWidth > 0 && (r && i.lineCap != "butt" && (i.lineCap = "butt"), s != d && (i.strokeStyle = d, s = d), N(i, f), P(i, e.strokeWidth), i.stroke());
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
function N(e, t) {
|
|
61
|
+
e.globalAlpha != t && (e.globalAlpha = t);
|
|
62
|
+
}
|
|
63
|
+
function P(e, t) {
|
|
64
|
+
e.lineWidth != t && (e.lineWidth = t);
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region ../core/src/rendering/canvas2d/renderers/rect.js
|
|
68
|
+
function F(e, t) {
|
|
69
|
+
let n = e, r = p(n);
|
|
70
|
+
r.hatch != "none" && t.warn("Canvas2D ignored unsupported rect hatch."), r.shadow.opacity > 0 && t.warn("Canvas2D ignored unsupported rect shadow.");
|
|
71
|
+
let i = t.context, a = n.encoders, o, s, c = [
|
|
72
|
+
0,
|
|
73
|
+
0,
|
|
74
|
+
0,
|
|
75
|
+
0
|
|
76
|
+
];
|
|
77
|
+
return y(n, r, t, (e) => {
|
|
78
|
+
let n = e.opacityFactor, r = e.fill != "none" && e.fillOpacity > 0, l = k(a.stroke(e.datum)), d = u(a.strokeOpacity, e.datum) * t.viewOpacity * n, f = l != "none" && d > 0 && e.strokeWidth > 0, p = e.radii.topLeft != 0 || e.radii.topRight != 0 || e.radii.bottomRight != 0 || e.radii.bottomLeft != 0;
|
|
79
|
+
p && (r || f) && (c[0] = e.radii.topLeft, c[1] = e.radii.topRight, c[2] = e.radii.bottomRight, c[3] = e.radii.bottomLeft, i.beginPath(), i.roundRect(e.x, e.y, e.width, e.height, c)), r && (o != e.fill && (i.fillStyle = e.fill, o = e.fill), I(i, e.fillOpacity * n), p ? i.fill() : i.fillRect(e.x, e.y, e.width, e.height)), f && (s != l && (i.strokeStyle = l, s = l), I(i, d), L(i, e.strokeWidth), p ? i.stroke() : i.strokeRect(e.x, e.y, e.width, e.height));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function I(e, t) {
|
|
83
|
+
e.globalAlpha != t && (e.globalAlpha = t);
|
|
84
|
+
}
|
|
85
|
+
function L(e, t) {
|
|
86
|
+
e.lineWidth != t && (e.lineWidth = t);
|
|
87
|
+
}
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region ../core/src/rendering/canvas2d/renderers/rule.js
|
|
90
|
+
function R(e, t) {
|
|
91
|
+
let n = e, r = t.context, i = n.encoders;
|
|
92
|
+
r.lineCap = f(n, n.properties.strokeCap), r.setLineDash(f(n, n.properties.strokeDash) ?? []), r.lineDashOffset = f(n, n.properties.strokeDashOffset);
|
|
93
|
+
let a;
|
|
94
|
+
return T(n, S(n), t, (e) => {
|
|
95
|
+
let n = k(i.color(e.datum)), o = u(i.opacity, e.datum) * t.viewOpacity;
|
|
96
|
+
n == "none" || o <= 0 || e.strokeWidth <= 0 || (a != n && (r.strokeStyle = n, a = n), r.globalAlpha = o, r.lineWidth = e.strokeWidth, r.beginPath(), r.moveTo(e.x1, e.y1), r.lineTo(e.x2, e.y2), r.stroke());
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region ../core/src/rendering/canvas2d/renderers/text.js
|
|
101
|
+
function z(e, t) {
|
|
102
|
+
let n = e, r = n.properties, i = v(n), a = t.context, o = n.encoders, s = E(r.font), c = `${r.fontStyle ?? "normal"} ${w(r.fontWeight ?? "normal")} `, l = i.baseline == "baseline" ? "alphabetic" : i.baseline;
|
|
103
|
+
[
|
|
104
|
+
r.viewportEdgeFadeWidthTop,
|
|
105
|
+
r.viewportEdgeFadeWidthRight,
|
|
106
|
+
r.viewportEdgeFadeWidthBottom,
|
|
107
|
+
r.viewportEdgeFadeWidthLeft
|
|
108
|
+
].some((e) => f(n, e) > 0) && t.warn("Canvas2D ignored unsupported text viewport edge fading.");
|
|
109
|
+
let p, m;
|
|
110
|
+
return i.logoLetters || (a.textAlign = i.align, a.textBaseline = l), d(n, i, t, (e) => {
|
|
111
|
+
e.multiCharacterLogo && t.warn("Canvas2D stretches multi-character logo text as a single glyph cell.");
|
|
112
|
+
let n = k(o.color(e.datum)), r = u(o.opacity, e.datum) * t.viewOpacity * e.fadeOpacity;
|
|
113
|
+
if (!(n == "none" || r <= 0)) if (p != n && (a.fillStyle = n, p = n), a.globalAlpha = r, m != e.size && (a.font = `${c}${e.size}px ${s}`, m = e.size), e.logoScale) {
|
|
114
|
+
a.save(), a.translate(e.x, e.y), a.rotate(e.angle * Math.PI / 180), a.translate(e.dx, e.dy);
|
|
115
|
+
let t = a.measureText(e.text).width;
|
|
116
|
+
a.scale(e.logoScale.width / t, e.logoScale.heightScale), a.textAlign = "center", a.textBaseline = "alphabetic", a.fillText(e.text, 0, x("middle", 1)), a.restore();
|
|
117
|
+
} else e.angle ? (a.save(), a.translate(e.x, e.y), a.rotate(e.angle * Math.PI / 180), a.fillText(e.text, e.dx, e.dy, e.width), a.restore()) : a.fillText(e.text, e.x + e.dx, e.y + e.dy, e.width);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region ../core/src/rendering/canvas2d/renderers/index.js
|
|
122
|
+
function B(e, t) {
|
|
123
|
+
return e.getType() == "arrow" ? A(e, t) : e.getType() == "link" ? j(e, t) : e.getType() == "rect" ? F(e, t) : e.getType() == "point" ? M(e, t) : e.getType() == "rule" || e.getType() == "tick" ? R(e, t) : e.getType() == "text" ? z(e, t) : (t.warn(`Canvas2D rendering is not implemented for mark type "${e.getType()}".`), 0);
|
|
124
|
+
}
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region ../core/src/rendering/canvas2d/canvas2DViewRenderingContext.js
|
|
127
|
+
var V = class extends a {
|
|
128
|
+
#e = [];
|
|
129
|
+
#t = /* @__PURE__ */ new Set();
|
|
130
|
+
constructor(e, t) {
|
|
131
|
+
if (super(e), this.context = t.context, this.width = t.width, this.height = t.height, this.devicePixelRatio = t.devicePixelRatio, this.paint = t.paint, this.paint) {
|
|
132
|
+
let e = this.context;
|
|
133
|
+
e.resetTransform(), e.clearRect(0, 0, e.canvas.width, e.canvas.height), e.setTransform(this.devicePixelRatio, 0, 0, this.devicePixelRatio, 0, 0), e.globalAlpha = 1, e.globalCompositeOperation = "source-over", t.background != null && (e.fillStyle = t.background, e.fillRect(0, 0, this.width, this.height));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
getDevicePixelRatio() {
|
|
137
|
+
return this.devicePixelRatio;
|
|
138
|
+
}
|
|
139
|
+
pushView(e, t) {
|
|
140
|
+
this.paint && !this.#t.has(e) && (e.onBeforeRender(), this.#t.add(e)), this.#e.push({
|
|
141
|
+
view: e,
|
|
142
|
+
coords: t
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
popView(e) {
|
|
146
|
+
if (this.#e.pop()?.view !== e) throw Error("Unbalanced Canvas2D view rendering context stack.");
|
|
147
|
+
}
|
|
148
|
+
renderMark(e, r) {
|
|
149
|
+
if (!this.paint || e.unitView.getEffectiveOpacity() <= 0) return;
|
|
150
|
+
let i = this.currentCoords, a = t(r), u = n(a, e.properties.clip, i), d = s(this.width, this.height, u);
|
|
151
|
+
if (!O(d)) return;
|
|
152
|
+
let f = l(i, a, e.properties.cullByVisibleRange), p = this.context;
|
|
153
|
+
if (p.save(), u) {
|
|
154
|
+
let e = u.rect.flatten(), t = u.clipX ? e.x : 0, n = u.clipY ? e.y : 0, r = u.clipX ? e.width : this.width, i = u.clipY ? e.height : this.height;
|
|
155
|
+
p.beginPath(), p.rect(t, n, r, i), p.clip();
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
c(e, r, i, (t, n) => B(e, {
|
|
159
|
+
context: p,
|
|
160
|
+
coords: t,
|
|
161
|
+
data: n,
|
|
162
|
+
visibleBounds: d,
|
|
163
|
+
anchorCullBounds: f,
|
|
164
|
+
viewOpacity: e.unitView.getEffectiveOpacity(),
|
|
165
|
+
warn: (t) => o(`${t} View: ${e.unitView.getPathString()}`)
|
|
166
|
+
}), (t) => o(`Canvas2D could not resolve sample facet index ${t}. View: ${e.unitView.getPathString()}`));
|
|
167
|
+
} finally {
|
|
168
|
+
p.restore();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
get currentCoords() {
|
|
172
|
+
let t = e(this.#e);
|
|
173
|
+
if (!t) throw Error("No current view in Canvas2D rendering context.");
|
|
174
|
+
return t.coords;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region ../core/src/rendering/canvas2d/renderCanvas2D.js
|
|
179
|
+
function H(e) {
|
|
180
|
+
let t = new V({ picking: !1 }, e);
|
|
181
|
+
e.viewRoot.render(t, i.create(0, 0, e.width, e.height), { firstFacet: !0 });
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region ../core/src/rendering/canvas2d/canvas2DRenderCoordinator.js
|
|
185
|
+
var U = class {
|
|
186
|
+
constructor(e) {
|
|
187
|
+
this.viewRoot = e.viewRoot, this.context = e.context, this.surface = e.surface, this.getBackground = e.getBackground, this.broadcast = e.broadcast, this.onLayoutComputed = e.onLayoutComputed;
|
|
188
|
+
}
|
|
189
|
+
computeLayout() {
|
|
190
|
+
this.broadcast("layout"), this.surface.invalidateSize();
|
|
191
|
+
let e = 5;
|
|
192
|
+
for (;;) {
|
|
193
|
+
if (this.#e(!1), !this.surface.invalidateSize()) {
|
|
194
|
+
this.onLayoutComputed(), this.broadcast("layoutComputed");
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (e--, e == 0) throw Error("Layout did not settle: canvas size kept changing.");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
renderAll() {
|
|
201
|
+
this.#e(!0);
|
|
202
|
+
}
|
|
203
|
+
#e(e) {
|
|
204
|
+
let t = this.surface.getLogicalCanvasSize();
|
|
205
|
+
isNaN(t.width) || isNaN(t.height) || H({
|
|
206
|
+
viewRoot: this.viewRoot,
|
|
207
|
+
context: this.context,
|
|
208
|
+
width: t.width,
|
|
209
|
+
height: t.height,
|
|
210
|
+
devicePixelRatio: this.surface.getDevicePixelRatio(),
|
|
211
|
+
background: this.getBackground(),
|
|
212
|
+
paint: e
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}, W = class {
|
|
216
|
+
#e;
|
|
217
|
+
#t;
|
|
218
|
+
constructor(e) {
|
|
219
|
+
let t = document.createElement("canvas"), n = t.getContext("2d");
|
|
220
|
+
if (!n) throw Error("Unable to initialize a Canvas2D rendering context.");
|
|
221
|
+
this.canvas = t, this.context = n, e.container.appendChild(t);
|
|
222
|
+
try {
|
|
223
|
+
this.#e = new r(e.container, t, e.sizeSource, () => {
|
|
224
|
+
this.#n() && e.onCanvasResize();
|
|
225
|
+
}), this.#n();
|
|
226
|
+
} catch (e) {
|
|
227
|
+
throw this.#e?.finalize(), t.remove(), e;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
invalidateSize() {
|
|
231
|
+
return this.#e.invalidate(), this.#n();
|
|
232
|
+
}
|
|
233
|
+
#n() {
|
|
234
|
+
let e = this.getLogicalCanvasSize(), t = this.#e.getPhysicalCanvasSize(e);
|
|
235
|
+
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 = {
|
|
236
|
+
logicalWidth: e.width,
|
|
237
|
+
logicalHeight: e.height,
|
|
238
|
+
physicalWidth: t.width,
|
|
239
|
+
physicalHeight: t.height
|
|
240
|
+
}, !0);
|
|
241
|
+
}
|
|
242
|
+
getLogicalCanvasSize() {
|
|
243
|
+
return this.#e.getLogicalCanvasSize();
|
|
244
|
+
}
|
|
245
|
+
getDevicePixelRatio() {
|
|
246
|
+
return this.#e.getDevicePixelRatio();
|
|
247
|
+
}
|
|
248
|
+
finalize() {
|
|
249
|
+
this.#e.finalize(), this.canvas.remove();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region ../core/src/rendering/canvas2d/rasterExport.js
|
|
254
|
+
async function G(e) {
|
|
255
|
+
let t = e.mimeType ?? "image/png";
|
|
256
|
+
if (t != "image/png") throw Error(`Unsupported raster export MIME type: ${t}`);
|
|
257
|
+
let n = q(e);
|
|
258
|
+
return new Promise((e, r) => {
|
|
259
|
+
n.toBlob((t) => {
|
|
260
|
+
t ? e(t) : r(/* @__PURE__ */ Error("Canvas2D could not encode the raster export."));
|
|
261
|
+
}, t);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function K(e) {
|
|
265
|
+
return q({
|
|
266
|
+
...e,
|
|
267
|
+
pixelRatio: e.devicePixelRatio ?? e.pixelRatio
|
|
268
|
+
}).toDataURL("image/png");
|
|
269
|
+
}
|
|
270
|
+
function q(e) {
|
|
271
|
+
let t = e.logicalWidth ?? e.liveSize.width, n = e.logicalHeight ?? e.liveSize.height, r = e.pixelRatio ?? e.liveDevicePixelRatio, i = document.createElement("canvas");
|
|
272
|
+
i.width = Math.floor(t * r), i.height = Math.floor(n * r);
|
|
273
|
+
let a = i.getContext("2d");
|
|
274
|
+
if (!a) throw Error("Unable to initialize a Canvas2D export context.");
|
|
275
|
+
return H({
|
|
276
|
+
viewRoot: e.viewRoot,
|
|
277
|
+
context: a,
|
|
278
|
+
width: t,
|
|
279
|
+
height: n,
|
|
280
|
+
devicePixelRatio: r,
|
|
281
|
+
background: e.clearColor ?? null,
|
|
282
|
+
paint: !0
|
|
283
|
+
}), i;
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region ../core/src/rendering/canvas2d/index.js
|
|
287
|
+
function J(e) {
|
|
288
|
+
let t = new W(e);
|
|
289
|
+
return {
|
|
290
|
+
surface: t,
|
|
291
|
+
glHelper: void 0,
|
|
292
|
+
createRenderCoordinator: (e) => new U({
|
|
293
|
+
...e,
|
|
294
|
+
surface: t,
|
|
295
|
+
context: t.context
|
|
296
|
+
}),
|
|
297
|
+
exportCanvas: (e) => K({
|
|
298
|
+
...e,
|
|
299
|
+
liveSize: t.getLogicalCanvasSize(),
|
|
300
|
+
liveDevicePixelRatio: t.getDevicePixelRatio()
|
|
301
|
+
}),
|
|
302
|
+
exportRaster: (e) => G({
|
|
303
|
+
...e,
|
|
304
|
+
liveSize: t.getLogicalCanvasSize(),
|
|
305
|
+
liveDevicePixelRatio: t.getDevicePixelRatio()
|
|
306
|
+
})
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
//#endregion
|
|
310
|
+
export { J as createCanvas2DRenderingBackend };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
//#region ../core/src/rendering/canvasSizeHelper.js
|
|
2
|
+
var e = class {
|
|
3
|
+
constructor(e, t, n, r) {
|
|
4
|
+
this._container = e, this._canvas = t, this._sizeSource = n, this._onPhysicalSizeChange = r ?? (() => {}), this._logicalCanvasSize = void 0, this._devicePixelContentBoxSize = void 0, this._devicePixelContentBoxObserver = void 0, this._observeDevicePixelContentBox();
|
|
5
|
+
}
|
|
6
|
+
invalidate() {
|
|
7
|
+
this._logicalCanvasSize = void 0, this._devicePixelContentBoxSize = void 0;
|
|
8
|
+
}
|
|
9
|
+
finalize() {
|
|
10
|
+
this._devicePixelContentBoxObserver && this._devicePixelContentBoxObserver.disconnect();
|
|
11
|
+
}
|
|
12
|
+
getPhysicalCanvasSize(e) {
|
|
13
|
+
if (this._devicePixelContentBoxSize) return this._devicePixelContentBoxSize;
|
|
14
|
+
let t = window.devicePixelRatio ?? 1;
|
|
15
|
+
return e ||= this.getLogicalCanvasSize(), {
|
|
16
|
+
width: Math.round(e.width * t),
|
|
17
|
+
height: Math.round(e.height * t)
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
getDevicePixelRatio(e) {
|
|
21
|
+
e ||= this.getLogicalCanvasSize();
|
|
22
|
+
let t = this.getPhysicalCanvasSize(e), n = e.width > 0 ? t.width / e.width : void 0, r = e.height > 0 ? t.height / e.height : void 0;
|
|
23
|
+
return n !== void 0 && r !== void 0 ? (n + r) / 2 : n === void 0 ? r === void 0 ? window.devicePixelRatio ?? 1 : r : n;
|
|
24
|
+
}
|
|
25
|
+
getLogicalCanvasSize() {
|
|
26
|
+
if (this._logicalCanvasSize) return this._logicalCanvasSize;
|
|
27
|
+
let e = this._sizeSource(), t = window.getComputedStyle(this._container, null), n = this._container.getBoundingClientRect(), r = parseFloat(t.paddingLeft), i = parseFloat(t.paddingRight), a = parseFloat(t.paddingTop), o = parseFloat(t.paddingBottom), s = parseFloat(t.borderLeftWidth), c = parseFloat(t.borderRightWidth), l = parseFloat(t.borderTopWidth), u = parseFloat(t.borderBottomWidth), d = e.width ?? n.width - r - i - s - c, f = e.height ?? n.height - a - o - l - u;
|
|
28
|
+
return this._logicalCanvasSize = {
|
|
29
|
+
width: d,
|
|
30
|
+
height: f
|
|
31
|
+
}, this._logicalCanvasSize;
|
|
32
|
+
}
|
|
33
|
+
_observeDevicePixelContentBox() {
|
|
34
|
+
if (typeof ResizeObserver != "function") return;
|
|
35
|
+
let e = new ResizeObserver((e) => {
|
|
36
|
+
let t = e.find((e) => e.target == this._canvas);
|
|
37
|
+
if (!t) return;
|
|
38
|
+
let n = t.devicePixelContentBoxSize;
|
|
39
|
+
if (!n) return;
|
|
40
|
+
let r = Array.isArray(n) ? n[0] : n;
|
|
41
|
+
if (!r) return;
|
|
42
|
+
let i = {
|
|
43
|
+
width: r.inlineSize,
|
|
44
|
+
height: r.blockSize
|
|
45
|
+
};
|
|
46
|
+
this._devicePixelContentBoxSize && this._devicePixelContentBoxSize.width == i.width && this._devicePixelContentBoxSize.height == i.height || (this._devicePixelContentBoxSize = i, this._onPhysicalSizeChange());
|
|
47
|
+
});
|
|
48
|
+
try {
|
|
49
|
+
e.observe(this._canvas, { box: "device-pixel-content-box" }), this._devicePixelContentBoxObserver = e;
|
|
50
|
+
} catch {
|
|
51
|
+
e.disconnect();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
//#endregion
|
|
56
|
+
export { e as t };
|