modern-canvas 0.7.14 → 0.7.15
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 +51 -46
- package/dist/index.d.cts +13 -12
- package/dist/index.d.mts +13 -12
- package/dist/index.d.ts +13 -12
- package/dist/index.js +15 -15
- package/dist/index.mjs +51 -46
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1740,7 +1740,7 @@ class Matrix3 extends Matrix {
|
|
|
1740
1740
|
constructor(array) {
|
|
1741
1741
|
super(3, 3, array);
|
|
1742
1742
|
}
|
|
1743
|
-
|
|
1743
|
+
affineInvert() {
|
|
1744
1744
|
const [
|
|
1745
1745
|
n11,
|
|
1746
1746
|
n21,
|
|
@@ -2192,10 +2192,10 @@ class Transform2D extends Matrix3 {
|
|
|
2192
2192
|
newPos.y = b * x + d * y + ty;
|
|
2193
2193
|
return newPos;
|
|
2194
2194
|
}
|
|
2195
|
-
|
|
2196
|
-
return this.clone().
|
|
2195
|
+
affineInverse() {
|
|
2196
|
+
return this.clone().affineInvert();
|
|
2197
2197
|
}
|
|
2198
|
-
|
|
2198
|
+
applyAffineInverse(pos, newPos) {
|
|
2199
2199
|
newPos = newPos || new Vector2();
|
|
2200
2200
|
const { a, b, c, d, tx, ty } = this.toObject();
|
|
2201
2201
|
const id = 1 / (a * d + c * -b);
|
|
@@ -2574,7 +2574,7 @@ attribute vec4 aBackgroundColor;
|
|
|
2574
2574
|
attribute vec4 aDisableWrapMode;
|
|
2575
2575
|
|
|
2576
2576
|
uniform mat3 projectionMatrix;
|
|
2577
|
-
uniform mat3
|
|
2577
|
+
uniform mat3 viewMatrix;
|
|
2578
2578
|
uniform vec4 modulate;
|
|
2579
2579
|
|
|
2580
2580
|
varying float vTextureId;
|
|
@@ -2590,7 +2590,7 @@ void main(void) {
|
|
|
2590
2590
|
0.0, 0.0, 1.0
|
|
2591
2591
|
);
|
|
2592
2592
|
vTextureId = aTextureId;
|
|
2593
|
-
mat3 modelViewProjectionMatrix = projectionMatrix *
|
|
2593
|
+
mat3 modelViewProjectionMatrix = projectionMatrix * viewMatrix * modelMatrix;
|
|
2594
2594
|
gl_Position = vec4((modelViewProjectionMatrix * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
|
|
2595
2595
|
vUv = aUv;
|
|
2596
2596
|
vModulate = aModulate * modulate;
|
|
@@ -3321,7 +3321,7 @@ class WebGLProgramModule extends WebGLModule {
|
|
|
3321
3321
|
boundProgram = null;
|
|
3322
3322
|
uniforms = {
|
|
3323
3323
|
projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
3324
|
-
|
|
3324
|
+
viewMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
|
3325
3325
|
};
|
|
3326
3326
|
create(options) {
|
|
3327
3327
|
const program = this.gl.createProgram();
|
|
@@ -3525,7 +3525,7 @@ ${gl.getShaderInfoLog(shader)}`);
|
|
|
3525
3525
|
this.boundProgram = null;
|
|
3526
3526
|
this.uniforms = {
|
|
3527
3527
|
projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
3528
|
-
|
|
3528
|
+
viewMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
|
3529
3529
|
};
|
|
3530
3530
|
}
|
|
3531
3531
|
free() {
|
|
@@ -3619,8 +3619,8 @@ class WebGLScissorModule extends WebGLModule {
|
|
|
3619
3619
|
use() {
|
|
3620
3620
|
const renderer = this._renderer;
|
|
3621
3621
|
const { pixelRatio, mask, viewport, screen, gl, program } = renderer;
|
|
3622
|
-
const {
|
|
3623
|
-
const rect = transformRectToAABB(
|
|
3622
|
+
const { viewMatrix } = program.uniforms;
|
|
3623
|
+
const rect = transformRectToAABB(viewMatrix, mask.last.mask);
|
|
3624
3624
|
const { x, y, width, height } = rect;
|
|
3625
3625
|
let scissorY;
|
|
3626
3626
|
if (viewport.boundViewport) {
|
|
@@ -6559,7 +6559,7 @@ let Viewport = class extends Node {
|
|
|
6559
6559
|
this.projection.flipY(flipY);
|
|
6560
6560
|
}
|
|
6561
6561
|
projection = new Projection2D();
|
|
6562
|
-
|
|
6562
|
+
canvasTransform = new Transform2D();
|
|
6563
6563
|
_framebufferIndex = 0;
|
|
6564
6564
|
_framebuffers = [
|
|
6565
6565
|
{ texture: new ViewportTexture(), needsUpload: false },
|
|
@@ -6674,7 +6674,7 @@ let Viewport = class extends Node {
|
|
|
6674
6674
|
render(renderer, next) {
|
|
6675
6675
|
const oldViewport = this._tree?.getCurrentViewport();
|
|
6676
6676
|
renderer.program.uniforms.projectionMatrix = this.projection.toArray(true);
|
|
6677
|
-
renderer.program.uniforms.
|
|
6677
|
+
renderer.program.uniforms.viewMatrix = this.canvasTransform.toArray(true);
|
|
6678
6678
|
this.activate(renderer);
|
|
6679
6679
|
renderer.clear();
|
|
6680
6680
|
super.render(renderer, next);
|
|
@@ -6689,11 +6689,11 @@ let Viewport = class extends Node {
|
|
|
6689
6689
|
getRect() {
|
|
6690
6690
|
return new Rect2(this.x, this.y, this.width, this.height);
|
|
6691
6691
|
}
|
|
6692
|
-
|
|
6693
|
-
return this.
|
|
6692
|
+
toCanvasGlobal(screenPos, newPos) {
|
|
6693
|
+
return this.canvasTransform.applyAffineInverse(screenPos, newPos);
|
|
6694
6694
|
}
|
|
6695
|
-
|
|
6696
|
-
return this.
|
|
6695
|
+
toCanvasScreen(globalPos, newPos) {
|
|
6696
|
+
return this.canvasTransform.apply(globalPos, newPos);
|
|
6697
6697
|
}
|
|
6698
6698
|
};
|
|
6699
6699
|
__decorateClass$P([
|
|
@@ -7231,35 +7231,28 @@ let Node2D = class extends CanvasItem {
|
|
|
7231
7231
|
getTransformOrigin() {
|
|
7232
7232
|
return new Vector2(0, 0);
|
|
7233
7233
|
}
|
|
7234
|
-
|
|
7234
|
+
updateTransform(cb) {
|
|
7235
7235
|
const origin = this.getTransformOrigin();
|
|
7236
|
-
const transform =
|
|
7237
|
-
transform.translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
|
|
7236
|
+
const transform = this.transform.identity().translate(-origin.x, -origin.y).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
|
|
7238
7237
|
cb?.(transform);
|
|
7239
7238
|
transform.translate(this.position.x, this.position.y).translate(origin.x, origin.y);
|
|
7240
|
-
return transform;
|
|
7241
|
-
}
|
|
7242
|
-
updateTransform() {
|
|
7243
|
-
this.transform.copy(this.getTransform());
|
|
7244
7239
|
}
|
|
7245
7240
|
updateGlobalTransform() {
|
|
7246
7241
|
this.updateTransform();
|
|
7247
7242
|
const parent = this.getParent();
|
|
7248
7243
|
if (parent?.globalTransform) {
|
|
7249
|
-
|
|
7250
|
-
|
|
7251
|
-
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
7255
|
-
|
|
7256
|
-
|
|
7257
|
-
);
|
|
7258
|
-
this.
|
|
7259
|
-
|
|
7260
|
-
|
|
7261
|
-
);
|
|
7262
|
-
this.globalRotation = parent.globalRotation + this.rotation;
|
|
7244
|
+
const {
|
|
7245
|
+
globalPosition,
|
|
7246
|
+
globalScale,
|
|
7247
|
+
globalSkew,
|
|
7248
|
+
globalTransform,
|
|
7249
|
+
globalRotation
|
|
7250
|
+
} = parent;
|
|
7251
|
+
this._parentTransformDirtyId = globalTransform.dirtyId;
|
|
7252
|
+
this.globalPosition.set(globalPosition.x + this.position.x, globalPosition.y + this.position.y);
|
|
7253
|
+
this.globalScale.set(globalScale.x * this.scale.x, globalScale.y * this.scale.y);
|
|
7254
|
+
this.globalSkew.set(globalSkew.x * this.skew.x, globalSkew.y * this.skew.y);
|
|
7255
|
+
this.globalRotation = globalRotation + this.rotation;
|
|
7263
7256
|
parent.globalTransform.multiply(this.transform, this.globalTransform);
|
|
7264
7257
|
} else {
|
|
7265
7258
|
this.globalPosition.copy(this.position);
|
|
@@ -7308,7 +7301,7 @@ let Node2D = class extends CanvasItem {
|
|
|
7308
7301
|
}
|
|
7309
7302
|
}
|
|
7310
7303
|
toLocal(globalPos, newPos) {
|
|
7311
|
-
return this.globalTransform.
|
|
7304
|
+
return this.globalTransform.applyAffineInverse(globalPos, newPos);
|
|
7312
7305
|
}
|
|
7313
7306
|
toGlobal(localPos, newPos) {
|
|
7314
7307
|
return this.globalTransform.apply(localPos, newPos);
|
|
@@ -7335,7 +7328,7 @@ var __decorateClass$I = (decorators, target, key, kind) => {
|
|
|
7335
7328
|
return result;
|
|
7336
7329
|
};
|
|
7337
7330
|
let Camera2D = class extends Node2D {
|
|
7338
|
-
zoom = new Vector2(1, 1).on("update", () => this.
|
|
7331
|
+
zoom = new Vector2(1, 1).on("update", () => this.updateCanvasTransform());
|
|
7339
7332
|
maxZoom = new Vector2(6, 6);
|
|
7340
7333
|
minZoom = new Vector2(0.1, 0.1);
|
|
7341
7334
|
_screenOffset = { x: 0, y: 0 };
|
|
@@ -7422,14 +7415,26 @@ let Camera2D = class extends Node2D {
|
|
|
7422
7415
|
}
|
|
7423
7416
|
updateTransform() {
|
|
7424
7417
|
super.updateTransform();
|
|
7425
|
-
this.
|
|
7418
|
+
this.updateCanvasTransform();
|
|
7426
7419
|
}
|
|
7427
|
-
|
|
7420
|
+
updateCanvasTransform() {
|
|
7428
7421
|
const viewport = this.getViewport();
|
|
7429
7422
|
if (!viewport)
|
|
7430
7423
|
return;
|
|
7431
|
-
viewport.
|
|
7432
|
-
this.emit("
|
|
7424
|
+
viewport.canvasTransform.identity().scale(this.zoom.x, this.zoom.y).translate(this.position.x, this.position.y);
|
|
7425
|
+
this.emit("updateCanvasTransform");
|
|
7426
|
+
}
|
|
7427
|
+
toGlobal(screenPos, newPos) {
|
|
7428
|
+
const viewport = this.getViewport();
|
|
7429
|
+
if (!viewport)
|
|
7430
|
+
throw new Error("Failed to toGlobal, viewport is empty");
|
|
7431
|
+
return viewport.toCanvasGlobal(screenPos, newPos);
|
|
7432
|
+
}
|
|
7433
|
+
toScreen(globalPos, newPos) {
|
|
7434
|
+
const viewport = this.getViewport();
|
|
7435
|
+
if (!viewport)
|
|
7436
|
+
throw new Error("Failed to toScreen, viewport is empty");
|
|
7437
|
+
return viewport.toCanvasScreen(globalPos, newPos);
|
|
7433
7438
|
}
|
|
7434
7439
|
};
|
|
7435
7440
|
__decorateClass$I([
|
|
@@ -10032,9 +10037,9 @@ let BaseElement2D = class extends Node2D {
|
|
|
10032
10037
|
const [originX, originY] = parseCSSTransformOrigin(this.style.transformOrigin);
|
|
10033
10038
|
return new Vector2(originX * width, originY * height);
|
|
10034
10039
|
}
|
|
10035
|
-
|
|
10040
|
+
updateTransform(cb) {
|
|
10036
10041
|
const { width, height } = this.size;
|
|
10037
|
-
|
|
10042
|
+
super.updateTransform((transform) => {
|
|
10038
10043
|
parseCSSTransform(this.style.transform ?? "", width, height, transform);
|
|
10039
10044
|
cb?.(transform);
|
|
10040
10045
|
});
|
|
@@ -10223,7 +10228,7 @@ let BaseElement2D = class extends Node2D {
|
|
|
10223
10228
|
const pos = new Vector2(screenX, screenY);
|
|
10224
10229
|
const viewport = this.getViewport();
|
|
10225
10230
|
if (viewport) {
|
|
10226
|
-
viewport.
|
|
10231
|
+
viewport.toCanvasGlobal(pos, pos);
|
|
10227
10232
|
}
|
|
10228
10233
|
this.toLocal(pos, pos);
|
|
10229
10234
|
if (this._positionInput(pos, key)) {
|