modern-canvas 0.8.6 → 0.8.8

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.cjs CHANGED
@@ -5131,20 +5131,17 @@ class GradientTexture extends Texture2D {
5131
5131
  const h = height;
5132
5132
  const cx = w / 2;
5133
5133
  const cy = h / 2;
5134
- const canAng = angle * Math.PI / 180;
5135
- const hypt = cy / Math.cos(canAng);
5136
- const fromTopRight = cx - Math.sqrt(hypt * hypt - cy * cy);
5137
- const diag = Math.sin(canAng) * fromTopRight;
5138
- const len = hypt + diag;
5139
- const x0 = cx + Math.cos(-Math.PI / 2 + canAng) * len;
5140
- const y0 = cy + Math.sin(-Math.PI / 2 + canAng) * len;
5141
- const x1 = cx + Math.cos(Math.PI / 2 + canAng) * len;
5142
- const y1 = cy + Math.sin(Math.PI / 2 + canAng) * len;
5143
- const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
5144
- stops.forEach((stop) => {
5145
- gradient.addColorStop(stop.offset, stop.color);
5146
- });
5147
- ctx.fillStyle = gradient;
5134
+ const A = (angle + 90) * Math.PI / 180;
5135
+ const dx = Math.sin(A);
5136
+ const dy = -Math.cos(A);
5137
+ const L = Math.abs(w * Math.sin(A)) + Math.abs(h * Math.cos(A));
5138
+ const x0 = cx - dx * (L / 2);
5139
+ const y0 = cy - dy * (L / 2);
5140
+ const x1 = cx + dx * (L / 2);
5141
+ const y1 = cy + dy * (L / 2);
5142
+ const g = ctx.createLinearGradient(x0, y0, x1, y1);
5143
+ for (const s of stops) g.addColorStop(s.offset, s.color);
5144
+ ctx.fillStyle = g;
5148
5145
  ctx.fillRect(0, 0, w, h);
5149
5146
  const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
5150
5147
  return {
@@ -14431,21 +14428,31 @@ class Engine extends SceneTree {
14431
14428
  const canvas1 = document.createElement("canvas");
14432
14429
  canvas1.width = imageData.width;
14433
14430
  canvas1.height = imageData.height;
14434
- canvas1.getContext("2d")?.putImageData(imageData, 0, 0);
14431
+ const ctx1 = canvas1.getContext("2d");
14432
+ if (ctx1) {
14433
+ ctx1.fillStyle = "rgba(0, 0, 0, 0)";
14434
+ ctx1.clearRect(0, 0, canvas1.width, canvas1.height);
14435
+ ctx1.putImageData(imageData, 0, 0);
14436
+ }
14435
14437
  const canvas2 = document.createElement("canvas");
14436
14438
  canvas2.width = this.width;
14437
14439
  canvas2.height = this.height;
14438
- canvas2.getContext("2d")?.drawImage(
14439
- canvas1,
14440
- 0,
14441
- 0,
14442
- canvas1.width,
14443
- canvas1.height,
14444
- 0,
14445
- 0,
14446
- canvas2.width,
14447
- canvas2.height
14448
- );
14440
+ const ctx2 = canvas2.getContext("2d");
14441
+ if (ctx2) {
14442
+ ctx2.fillStyle = "rgba(0, 0, 0, 0)";
14443
+ ctx2.clearRect(0, 0, canvas2.width, canvas2.height);
14444
+ ctx2.drawImage(
14445
+ canvas1,
14446
+ 0,
14447
+ 0,
14448
+ canvas1.width,
14449
+ canvas1.height,
14450
+ 0,
14451
+ 0,
14452
+ canvas2.width,
14453
+ canvas2.height
14454
+ );
14455
+ }
14449
14456
  return canvas2;
14450
14457
  }
14451
14458
  }