modern-canvas 0.23.5 → 0.23.6
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/index.js +22 -12
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3644,19 +3644,29 @@ var $n = class extends w {
|
|
|
3644
3644
|
return u(e);
|
|
3645
3645
|
}
|
|
3646
3646
|
static linearGradient(e, t, n) {
|
|
3647
|
-
t
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
i.fillStyle =
|
|
3655
|
-
|
|
3647
|
+
let r = Number.isFinite(t) && t > 0, i = Number.isFinite(n) && n > 0, a = Number.isFinite(e.angle);
|
|
3648
|
+
t = r ? t : 1, n = i ? n : 1;
|
|
3649
|
+
let o = S(t, n);
|
|
3650
|
+
if (!o) throw Error("GradientTexture requires a canvas; call setCanvasFactory() in non-browser environments.");
|
|
3651
|
+
let s = o.getContext("2d");
|
|
3652
|
+
if (!s) throw Error("Failed to parse linear gradient, get canvas context is null.");
|
|
3653
|
+
let { stops: c } = e, l = t, u = n;
|
|
3654
|
+
if (!r || !i || !a) s.fillStyle = c?.find((e) => e?.color)?.color ?? "transparent", s.fillRect(0, 0, l, u);
|
|
3655
|
+
else {
|
|
3656
|
+
let t = e.angle, n = l / 2, r = u / 2, i = (t + 90) * Math.PI / 180, a = Math.sin(i), o = -Math.cos(i), d = Math.abs(l * Math.sin(i)) + Math.abs(u * Math.cos(i)), f = s.createLinearGradient(n - d / 2 * a, r - d / 2 * o, n + d / 2 * a, r + d / 2 * o);
|
|
3657
|
+
for (let e of c) {
|
|
3658
|
+
let t = Number.isFinite(e.offset) ? Math.min(1, Math.max(0, e.offset)) : 0;
|
|
3659
|
+
try {
|
|
3660
|
+
f.addColorStop(t, e.color);
|
|
3661
|
+
} catch {}
|
|
3662
|
+
}
|
|
3663
|
+
s.fillStyle = f, s.fillRect(0, 0, l, u);
|
|
3664
|
+
}
|
|
3665
|
+
let d = s.getImageData(0, 0, o.width, o.height);
|
|
3656
3666
|
return {
|
|
3657
|
-
width:
|
|
3658
|
-
height:
|
|
3659
|
-
source: new Uint8Array(
|
|
3667
|
+
width: d.width,
|
|
3668
|
+
height: d.height,
|
|
3669
|
+
source: new Uint8Array(d.data.buffer),
|
|
3660
3670
|
uploadMethodId: "buffer"
|
|
3661
3671
|
};
|
|
3662
3672
|
}
|