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.mjs CHANGED
@@ -5125,20 +5125,17 @@ class GradientTexture extends Texture2D {
5125
5125
  const h = height;
5126
5126
  const cx = w / 2;
5127
5127
  const cy = h / 2;
5128
- const canAng = angle * Math.PI / 180;
5129
- const hypt = cy / Math.cos(canAng);
5130
- const fromTopRight = cx - Math.sqrt(hypt * hypt - cy * cy);
5131
- const diag = Math.sin(canAng) * fromTopRight;
5132
- const len = hypt + diag;
5133
- const x0 = cx + Math.cos(-Math.PI / 2 + canAng) * len;
5134
- const y0 = cy + Math.sin(-Math.PI / 2 + canAng) * len;
5135
- const x1 = cx + Math.cos(Math.PI / 2 + canAng) * len;
5136
- const y1 = cy + Math.sin(Math.PI / 2 + canAng) * len;
5137
- const gradient = ctx.createLinearGradient(x0, y0, x1, y1);
5138
- stops.forEach((stop) => {
5139
- gradient.addColorStop(stop.offset, stop.color);
5140
- });
5141
- ctx.fillStyle = gradient;
5128
+ const A = (angle + 90) * Math.PI / 180;
5129
+ const dx = Math.sin(A);
5130
+ const dy = -Math.cos(A);
5131
+ const L = Math.abs(w * Math.sin(A)) + Math.abs(h * Math.cos(A));
5132
+ const x0 = cx - dx * (L / 2);
5133
+ const y0 = cy - dy * (L / 2);
5134
+ const x1 = cx + dx * (L / 2);
5135
+ const y1 = cy + dy * (L / 2);
5136
+ const g = ctx.createLinearGradient(x0, y0, x1, y1);
5137
+ for (const s of stops) g.addColorStop(s.offset, s.color);
5138
+ ctx.fillStyle = g;
5142
5139
  ctx.fillRect(0, 0, w, h);
5143
5140
  const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
5144
5141
  return {
@@ -14425,21 +14422,31 @@ class Engine extends SceneTree {
14425
14422
  const canvas1 = document.createElement("canvas");
14426
14423
  canvas1.width = imageData.width;
14427
14424
  canvas1.height = imageData.height;
14428
- canvas1.getContext("2d")?.putImageData(imageData, 0, 0);
14425
+ const ctx1 = canvas1.getContext("2d");
14426
+ if (ctx1) {
14427
+ ctx1.fillStyle = "rgba(0, 0, 0, 0)";
14428
+ ctx1.clearRect(0, 0, canvas1.width, canvas1.height);
14429
+ ctx1.putImageData(imageData, 0, 0);
14430
+ }
14429
14431
  const canvas2 = document.createElement("canvas");
14430
14432
  canvas2.width = this.width;
14431
14433
  canvas2.height = this.height;
14432
- canvas2.getContext("2d")?.drawImage(
14433
- canvas1,
14434
- 0,
14435
- 0,
14436
- canvas1.width,
14437
- canvas1.height,
14438
- 0,
14439
- 0,
14440
- canvas2.width,
14441
- canvas2.height
14442
- );
14434
+ const ctx2 = canvas2.getContext("2d");
14435
+ if (ctx2) {
14436
+ ctx2.fillStyle = "rgba(0, 0, 0, 0)";
14437
+ ctx2.clearRect(0, 0, canvas2.width, canvas2.height);
14438
+ ctx2.drawImage(
14439
+ canvas1,
14440
+ 0,
14441
+ 0,
14442
+ canvas1.width,
14443
+ canvas1.height,
14444
+ 0,
14445
+ 0,
14446
+ canvas2.width,
14447
+ canvas2.height
14448
+ );
14449
+ }
14443
14450
  return canvas2;
14444
14451
  }
14445
14452
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.8.6",
4
+ "version": "0.8.8",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",