modern-canvas 0.4.2 → 0.4.4

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
@@ -7690,7 +7690,8 @@ exports.MaskEffect = class MaskEffect extends exports.Effect {
7690
7690
  QuadUvGeometry.draw(renderer, exports.MaskEffect.material, {
7691
7691
  sampler: 0,
7692
7692
  mask: 1,
7693
- area: context.targetArea
7693
+ area: context.targetArea,
7694
+ rotation: context.target?.globalRotation ?? 0
7694
7695
  });
7695
7696
  renderer.texture.unbind(1);
7696
7697
  });
@@ -7710,6 +7711,20 @@ void main() {
7710
7711
  uniform sampler2D sampler;
7711
7712
  uniform sampler2D mask;
7712
7713
  uniform float area[4];
7714
+ uniform float rotation;
7715
+
7716
+ vec2 rotateUV(vec2 uv, float angle) {
7717
+ uv -= 0.5;
7718
+ float cosAngle = cos(angle);
7719
+ float sinAngle = sin(angle);
7720
+ mat2 rotationMatrix = mat2(
7721
+ cosAngle, -sinAngle,
7722
+ sinAngle, cosAngle
7723
+ );
7724
+ uv = rotationMatrix * uv;
7725
+ uv += 0.5;
7726
+ return uv;
7727
+ }
7713
7728
 
7714
7729
  void main(void) {
7715
7730
  if (
@@ -7723,7 +7738,7 @@ void main(void) {
7723
7738
  (vUv.x - area[0]) / area[2],
7724
7739
  ((1.0 - vUv.y) - area[1]) / area[3]
7725
7740
  );
7726
- vec4 maskColor = texture2D(mask, uv);
7741
+ vec4 maskColor = texture2D(mask, rotateUV(uv, rotation));
7727
7742
  gl_FragColor = mix(vec4(0.), color, maskColor.a);
7728
7743
  } else {
7729
7744
  gl_FragColor = vec4(0.);
@@ -9654,9 +9669,13 @@ exports.Image2D = class Image2D extends exports.Element2D {
9654
9669
  const { left = 0, top = 0, right = 0, bottom = 0 } = this.srcRect ?? {};
9655
9670
  const { width, height } = this.size;
9656
9671
  this.context.fillStyle = texture;
9657
- const sx = 1 / ((1 - left + -right) * width);
9658
- const sy = 1 / ((1 - top + -bottom) * height);
9659
- this.context.textureTransform = new Transform2D().scale(sx, sy).translate(left * width * sx, top * height * sy);
9672
+ const w = Math.abs(1 + (left + right)) * width;
9673
+ const h = Math.abs(1 + (top + bottom)) * height;
9674
+ const sx = 1 / w;
9675
+ const sy = 1 / h;
9676
+ const tx = left * width * sx;
9677
+ const ty = top * height * sy;
9678
+ this.context.textureTransform = new Transform2D().scale(sx, sy).translate(tx, ty);
9660
9679
  super._drawContent();
9661
9680
  }
9662
9681
  }