modern-canvas 0.7.11 → 0.7.13

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
@@ -1950,10 +1950,23 @@ class Rect2 {
1950
1950
  switch (args.length) {
1951
1951
  case 0:
1952
1952
  break;
1953
- case 1:
1954
- position.set(args[0].position);
1955
- size.set(args[0].size);
1953
+ case 1: {
1954
+ const arg = args[0];
1955
+ if (arg instanceof Rect2) {
1956
+ position.set(arg.position);
1957
+ size.set(arg.size);
1958
+ } else {
1959
+ const xx = arg.map((p) => p[0]);
1960
+ const yy = arg.map((p) => p[1]);
1961
+ const minX = Math.min(...xx);
1962
+ const maxX = Math.max(...xx);
1963
+ const minY = Math.min(...yy);
1964
+ const maxY = Math.max(...yy);
1965
+ position.set(minX, minY);
1966
+ size.set(maxX - minX, maxY - minY);
1967
+ }
1956
1968
  break;
1969
+ }
1957
1970
  case 2:
1958
1971
  position.set(args[0]);
1959
1972
  size.set(args[1]);
@@ -1975,6 +1988,14 @@ class Rect2 {
1975
1988
  );
1976
1989
  return this;
1977
1990
  }
1991
+ toMinmax() {
1992
+ return {
1993
+ minX: this.position.x,
1994
+ minY: this.position.y,
1995
+ maxX: this.end.x,
1996
+ maxY: this.end.y
1997
+ };
1998
+ }
1978
1999
  toArray() {
1979
2000
  return [this.x, this.y, this.width, this.height];
1980
2001
  }
@@ -2141,6 +2162,30 @@ class Transform2D extends Matrix3 {
2141
2162
  b * x + d * y + ty
2142
2163
  ];
2143
2164
  }
2165
+ decompose(pivot = { x: 0, y: 0 }, output = {
2166
+ position: { x: 0, y: 0 },
2167
+ scale: { x: 0, y: 0 },
2168
+ skew: { x: 0, y: 0 },
2169
+ rotation: 0
2170
+ }) {
2171
+ const { a, b, c, d, tx, ty } = this.toObject();
2172
+ const skewX = -Math.atan2(-c, d);
2173
+ const skewY = Math.atan2(b, a);
2174
+ const delta = Math.abs(skewX + skewY);
2175
+ if (delta < 1e-5 || Math.abs(PI_2 - delta) < 1e-5) {
2176
+ output.rotation = skewY;
2177
+ output.skew.x = output.skew.y = 0;
2178
+ } else {
2179
+ output.rotation = 0;
2180
+ output.skew.x = skewX;
2181
+ output.skew.y = skewY;
2182
+ }
2183
+ output.scale.x = Math.sqrt(a * a + b * b);
2184
+ output.scale.y = Math.sqrt(c * c + d * d);
2185
+ output.position.x = tx + (pivot.x * a + pivot.y * c);
2186
+ output.position.y = ty + (pivot.x * b + pivot.y * d);
2187
+ return output;
2188
+ }
2144
2189
  inverse() {
2145
2190
  return this.clone().invert();
2146
2191
  }
@@ -2149,7 +2194,17 @@ class Transform2D extends Matrix3 {
2149
2194
  return a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0;
2150
2195
  }
2151
2196
  toObject() {
2152
- const [a, c, tx, b, d, ty, , , tz] = this._array;
2197
+ const [
2198
+ a,
2199
+ c,
2200
+ tx,
2201
+ b,
2202
+ d,
2203
+ ty,
2204
+ ,
2205
+ ,
2206
+ tz
2207
+ ] = this._array;
2153
2208
  return { a, c, tx, b, d, ty, tz };
2154
2209
  }
2155
2210
  }
@@ -6891,10 +6946,10 @@ __decorateClass$O([
6891
6946
  modernIdoc.property()
6892
6947
  ], exports.Effect.prototype, "effectMode", 2);
6893
6948
  __decorateClass$O([
6894
- modernIdoc.property()
6949
+ modernIdoc.property({ fallback: "" })
6895
6950
  ], exports.Effect.prototype, "glsl", 2);
6896
6951
  __decorateClass$O([
6897
- modernIdoc.property()
6952
+ modernIdoc.property({ fallback: "" })
6898
6953
  ], exports.Effect.prototype, "glslSrc", 2);
6899
6954
  exports.Effect = __decorateClass$O([
6900
6955
  customNode("Effect")
@@ -7170,25 +7225,27 @@ exports.Node2D = class Node2D extends exports.CanvasItem {
7170
7225
  const parent = this.getParent();
7171
7226
  if (parent?.globalTransform) {
7172
7227
  this._parentTransformDirtyId = parent.globalTransform.dirtyId;
7173
- this.globalScale.set(parent.globalScale.x * this.scale.x, parent.globalScale.y * this.scale.y);
7228
+ this.globalPosition.set(
7229
+ parent.globalPosition.x + this.position.x,
7230
+ parent.globalPosition.y + this.position.y
7231
+ );
7232
+ this.globalScale.set(
7233
+ parent.globalScale.x * this.scale.x,
7234
+ parent.globalScale.y * this.scale.y
7235
+ );
7236
+ this.globalSkew.set(
7237
+ parent.globalSkew.x * this.skew.x,
7238
+ parent.globalSkew.y * this.skew.y
7239
+ );
7174
7240
  this.globalRotation = parent.globalRotation + this.rotation;
7175
7241
  parent.globalTransform.multiply(this.transform, this.globalTransform);
7176
7242
  } else {
7243
+ this.globalPosition.copy(this.position);
7177
7244
  this.globalScale.copy(this.scale);
7245
+ this.globalSkew.copy(this.skew);
7178
7246
  this.globalRotation = this.rotation;
7179
7247
  this.globalTransform.copy(this.transform);
7180
7248
  }
7181
- const [
7182
- a,
7183
- c,
7184
- tx,
7185
- b,
7186
- d,
7187
- ty
7188
- ] = this.globalTransform.toArray();
7189
- this.globalPosition.set(tx, ty);
7190
- this.globalSkew.x = Math.atan2(c, a) - this.globalRotation;
7191
- this.globalSkew.y = Math.atan2(b, d) - this.globalRotation;
7192
7249
  this.requestRelayout();
7193
7250
  }
7194
7251
  _transformVertices(vertices, vertTransform) {
@@ -7289,7 +7346,7 @@ exports.Camera2D = class Camera2D extends exports.Node2D {
7289
7346
  }
7290
7347
  } else if (key === "pointerdown") {
7291
7348
  const e = event;
7292
- if (!this.grabbing && this.spaceKey) {
7349
+ if (!this.grabbing && (this.spaceKey || e.button === 1)) {
7293
7350
  this.grabbing = true;
7294
7351
  e.cursor = "grabbing";
7295
7352
  this._screenOffset = { x: e.screenX, y: e.screenY };
@@ -7307,7 +7364,11 @@ exports.Camera2D = class Camera2D extends exports.Node2D {
7307
7364
  const e = event;
7308
7365
  if (this.grabbing) {
7309
7366
  this.grabbing = false;
7310
- e.cursor = "grab";
7367
+ if (this.spaceKey) {
7368
+ e.cursor = "grab";
7369
+ } else {
7370
+ e.cursor = "default";
7371
+ }
7311
7372
  }
7312
7373
  } else if (key === "wheel") {
7313
7374
  this._onWheel(event);
@@ -7571,28 +7632,28 @@ void main(void) {
7571
7632
  }`
7572
7633
  }));
7573
7634
  __decorateClass$H([
7574
- modernIdoc.property()
7635
+ modernIdoc.property({ fallback: 1 })
7575
7636
  ], exports.ColorAdjustEffect.prototype, "saturation", 2);
7576
7637
  __decorateClass$H([
7577
- modernIdoc.property()
7638
+ modernIdoc.property({ fallback: 1 })
7578
7639
  ], exports.ColorAdjustEffect.prototype, "contrast", 2);
7579
7640
  __decorateClass$H([
7580
- modernIdoc.property()
7641
+ modernIdoc.property({ fallback: 1 })
7581
7642
  ], exports.ColorAdjustEffect.prototype, "brightness", 2);
7582
7643
  __decorateClass$H([
7583
- modernIdoc.property()
7644
+ modernIdoc.property({ fallback: 1 })
7584
7645
  ], exports.ColorAdjustEffect.prototype, "red", 2);
7585
7646
  __decorateClass$H([
7586
- modernIdoc.property()
7647
+ modernIdoc.property({ fallback: 1 })
7587
7648
  ], exports.ColorAdjustEffect.prototype, "green", 2);
7588
7649
  __decorateClass$H([
7589
- modernIdoc.property()
7650
+ modernIdoc.property({ fallback: 1 })
7590
7651
  ], exports.ColorAdjustEffect.prototype, "blue", 2);
7591
7652
  __decorateClass$H([
7592
- modernIdoc.property()
7653
+ modernIdoc.property({ fallback: 1 })
7593
7654
  ], exports.ColorAdjustEffect.prototype, "alpha", 2);
7594
7655
  __decorateClass$H([
7595
- modernIdoc.property()
7656
+ modernIdoc.property({ fallback: 1 })
7596
7657
  ], exports.ColorAdjustEffect.prototype, "gamma", 2);
7597
7658
  exports.ColorAdjustEffect = __decorateClass$H([
7598
7659
  customNode("ColorAdjustEffect")
@@ -7778,10 +7839,10 @@ void main(void) {
7778
7839
  }`
7779
7840
  }));
7780
7841
  __decorateClass$F([
7781
- modernIdoc.property()
7842
+ modernIdoc.property({ default: () => [] })
7782
7843
  ], exports.ColorOverlayEffect.prototype, "colors", 2);
7783
7844
  __decorateClass$F([
7784
- modernIdoc.property()
7845
+ modernIdoc.property({ fallback: 0.5 })
7785
7846
  ], exports.ColorOverlayEffect.prototype, "alpha", 2);
7786
7847
  exports.ColorOverlayEffect = __decorateClass$F([
7787
7848
  customNode("ColorOverlayEffect")
@@ -7863,10 +7924,10 @@ void main(void) {
7863
7924
  }`
7864
7925
  }));
7865
7926
  __decorateClass$E([
7866
- modernIdoc.property()
7927
+ modernIdoc.property({ default: () => [] })
7867
7928
  ], exports.ColorRemoveEffect.prototype, "colors", 2);
7868
7929
  __decorateClass$E([
7869
- modernIdoc.property()
7930
+ modernIdoc.property({ fallback: 0.5 })
7870
7931
  ], exports.ColorRemoveEffect.prototype, "epsilon", 2);
7871
7932
  exports.ColorRemoveEffect = __decorateClass$E([
7872
7933
  customNode("ColorRemoveEffect")
@@ -7970,10 +8031,10 @@ void main(void) {
7970
8031
  }`
7971
8032
  }));
7972
8033
  __decorateClass$D([
7973
- modernIdoc.property()
8034
+ modernIdoc.property({ default: () => [] })
7974
8035
  ], exports.ColorReplaceEffect.prototype, "colors", 2);
7975
8036
  __decorateClass$D([
7976
- modernIdoc.property()
8037
+ modernIdoc.property({ fallback: 0.05 })
7977
8038
  ], exports.ColorReplaceEffect.prototype, "epsilon", 2);
7978
8039
  exports.ColorReplaceEffect = __decorateClass$D([
7979
8040
  customNode("ColorReplaceEffect")
@@ -8094,10 +8155,10 @@ void main(void) {
8094
8155
  frag: frag$2
8095
8156
  }));
8096
8157
  __decorateClass$C([
8097
- modernIdoc.property({ default: 4 })
8158
+ modernIdoc.property({ fallback: 4 })
8098
8159
  ], exports.GaussianBlurEffect.prototype, "strength", 2);
8099
8160
  __decorateClass$C([
8100
- modernIdoc.property({ default: 3 })
8161
+ modernIdoc.property({ fallback: 3 })
8101
8162
  ], exports.GaussianBlurEffect.prototype, "quality", 2);
8102
8163
  exports.GaussianBlurEffect = __decorateClass$C([
8103
8164
  customNode("GaussianBlurEffect")
@@ -8176,19 +8237,19 @@ void main(void) {
8176
8237
  }`
8177
8238
  }));
8178
8239
  __decorateClass$B([
8179
- modernIdoc.property()
8240
+ modernIdoc.property({ fallback: "#000000FF" })
8180
8241
  ], exports.DropShadowEffect.prototype, "color", 2);
8181
8242
  __decorateClass$B([
8182
- modernIdoc.property()
8243
+ modernIdoc.property({ fallback: 4 })
8183
8244
  ], exports.DropShadowEffect.prototype, "blur", 2);
8184
8245
  __decorateClass$B([
8185
- modernIdoc.property()
8246
+ modernIdoc.property({ fallback: 4 })
8186
8247
  ], exports.DropShadowEffect.prototype, "offsetX", 2);
8187
8248
  __decorateClass$B([
8188
- modernIdoc.property()
8249
+ modernIdoc.property({ fallback: 4 })
8189
8250
  ], exports.DropShadowEffect.prototype, "offsetY", 2);
8190
8251
  __decorateClass$B([
8191
- modernIdoc.property()
8252
+ modernIdoc.property({ fallback: false })
8192
8253
  ], exports.DropShadowEffect.prototype, "shadowOnly", 2);
8193
8254
  exports.DropShadowEffect = __decorateClass$B([
8194
8255
  customNode("DropShadowEffect")
@@ -8248,7 +8309,7 @@ void main(void) {
8248
8309
  }`
8249
8310
  }));
8250
8311
  __decorateClass$A([
8251
- modernIdoc.property()
8312
+ modernIdoc.property({ fallback: 5 })
8252
8313
  ], exports.EmbossEffect.prototype, "strength", 2);
8253
8314
  exports.EmbossEffect = __decorateClass$A([
8254
8315
  customNode("EmbossEffect")
@@ -8437,31 +8498,31 @@ void main(void) {
8437
8498
  }`
8438
8499
  }));
8439
8500
  __decorateClass$z([
8440
- modernIdoc.property()
8501
+ modernIdoc.property({ fallback: 10 })
8441
8502
  ], exports.GlitchEffect.prototype, "slices", 2);
8442
8503
  __decorateClass$z([
8443
- modernIdoc.property()
8504
+ modernIdoc.property({ fallback: 512 })
8444
8505
  ], exports.GlitchEffect.prototype, "sampleSize", 2);
8445
8506
  __decorateClass$z([
8446
- modernIdoc.property()
8507
+ modernIdoc.property({ fallback: 100 })
8447
8508
  ], exports.GlitchEffect.prototype, "offset", 2);
8448
8509
  __decorateClass$z([
8449
- modernIdoc.property()
8510
+ modernIdoc.property({ fallback: 0 })
8450
8511
  ], exports.GlitchEffect.prototype, "direction", 2);
8451
8512
  __decorateClass$z([
8452
- modernIdoc.property()
8513
+ modernIdoc.property({ fallback: 2 })
8453
8514
  ], exports.GlitchEffect.prototype, "fillMode", 2);
8454
8515
  __decorateClass$z([
8455
- modernIdoc.property()
8516
+ modernIdoc.property({ fallback: 0 })
8456
8517
  ], exports.GlitchEffect.prototype, "seed", 2);
8457
8518
  __decorateClass$z([
8458
- modernIdoc.property()
8519
+ modernIdoc.property({ default: () => [2, 2] })
8459
8520
  ], exports.GlitchEffect.prototype, "red", 2);
8460
8521
  __decorateClass$z([
8461
- modernIdoc.property()
8522
+ modernIdoc.property({ default: () => [-10, 4] })
8462
8523
  ], exports.GlitchEffect.prototype, "green", 2);
8463
8524
  __decorateClass$z([
8464
- modernIdoc.property()
8525
+ modernIdoc.property({ default: () => [10, -4] })
8465
8526
  ], exports.GlitchEffect.prototype, "blue", 2);
8466
8527
  exports.GlitchEffect = __decorateClass$z([
8467
8528
  customNode("GlitchEffect")
@@ -8654,25 +8715,25 @@ void main(void) {
8654
8715
  }`
8655
8716
  }));
8656
8717
  __decorateClass$y([
8657
- modernIdoc.property()
8718
+ modernIdoc.property({ fallback: 0 })
8658
8719
  ], exports.GodrayEffect.prototype, "time", 2);
8659
8720
  __decorateClass$y([
8660
- modernIdoc.property()
8721
+ modernIdoc.property({ fallback: 30 })
8661
8722
  ], exports.GodrayEffect.prototype, "angle", 2);
8662
8723
  __decorateClass$y([
8663
- modernIdoc.property()
8724
+ modernIdoc.property({ fallback: 0.5 })
8664
8725
  ], exports.GodrayEffect.prototype, "gain", 2);
8665
8726
  __decorateClass$y([
8666
- modernIdoc.property()
8727
+ modernIdoc.property({ fallback: 2.5 })
8667
8728
  ], exports.GodrayEffect.prototype, "lacunarity", 2);
8668
8729
  __decorateClass$y([
8669
- modernIdoc.property()
8730
+ modernIdoc.property({ fallback: true })
8670
8731
  ], exports.GodrayEffect.prototype, "parallel", 2);
8671
8732
  __decorateClass$y([
8672
- modernIdoc.property()
8733
+ modernIdoc.property({ default: () => [0, 0] })
8673
8734
  ], exports.GodrayEffect.prototype, "center", 2);
8674
8735
  __decorateClass$y([
8675
- modernIdoc.property()
8736
+ modernIdoc.property({ fallback: 1 })
8676
8737
  ], exports.GodrayEffect.prototype, "alpha", 2);
8677
8738
  exports.GodrayEffect = __decorateClass$y([
8678
8739
  customNode("GodrayEffect")
@@ -8776,13 +8837,13 @@ void main() {
8776
8837
  }
8777
8838
  };
8778
8839
  __decorateClass$x([
8779
- modernIdoc.property()
8840
+ modernIdoc.property({ fallback: 4 })
8780
8841
  ], exports.KawaseBlurEffect.prototype, "strength", 2);
8781
8842
  __decorateClass$x([
8782
- modernIdoc.property()
8843
+ modernIdoc.property({ fallback: 3 })
8783
8844
  ], exports.KawaseBlurEffect.prototype, "quality", 2);
8784
8845
  __decorateClass$x([
8785
- modernIdoc.property()
8846
+ modernIdoc.property({ default: () => [1, 1] })
8786
8847
  ], exports.KawaseBlurEffect.prototype, "pixelSize", 2);
8787
8848
  exports.KawaseBlurEffect = __decorateClass$x([
8788
8849
  customNode("KawaseBlurEffect")
@@ -8888,7 +8949,7 @@ __decorateClass$w([
8888
8949
  modernIdoc.property({ protected: true })
8889
8950
  ], exports.MaskEffect.prototype, "texture", 2);
8890
8951
  __decorateClass$w([
8891
- modernIdoc.property({ default: "" })
8952
+ modernIdoc.property({ fallback: "" })
8892
8953
  ], exports.MaskEffect.prototype, "src", 2);
8893
8954
  exports.MaskEffect = __decorateClass$w([
8894
8955
  customNode("MaskEffect")
@@ -8990,25 +9051,25 @@ void main() {
8990
9051
  __publicField$7(exports.OutlineEffect, "MIN_SAMPLES", 1);
8991
9052
  __publicField$7(exports.OutlineEffect, "MAX_SAMPLES", 100);
8992
9053
  __decorateClass$v([
8993
- modernIdoc.property()
9054
+ modernIdoc.property({ fallback: "#000000ff" })
8994
9055
  ], exports.OutlineEffect.prototype, "color", 2);
8995
9056
  __decorateClass$v([
8996
- modernIdoc.property()
9057
+ modernIdoc.property({ fallback: 1 })
8997
9058
  ], exports.OutlineEffect.prototype, "width", 2);
8998
9059
  __decorateClass$v([
8999
- modernIdoc.property()
9060
+ modernIdoc.property({ fallback: "solid" })
9000
9061
  ], exports.OutlineEffect.prototype, "style", 2);
9001
9062
  __decorateClass$v([
9002
9063
  modernIdoc.property()
9003
9064
  ], exports.OutlineEffect.prototype, "image", 2);
9004
9065
  __decorateClass$v([
9005
- modernIdoc.property()
9066
+ modernIdoc.property({ fallback: 1 })
9006
9067
  ], exports.OutlineEffect.prototype, "opacity", 2);
9007
9068
  __decorateClass$v([
9008
- modernIdoc.property()
9069
+ modernIdoc.property({ fallback: 0.1 })
9009
9070
  ], exports.OutlineEffect.prototype, "quality", 2);
9010
9071
  __decorateClass$v([
9011
- modernIdoc.property()
9072
+ modernIdoc.property({ fallback: false })
9012
9073
  ], exports.OutlineEffect.prototype, "knockout", 2);
9013
9074
  exports.OutlineEffect = __decorateClass$v([
9014
9075
  customNode("OutlineEffect")
@@ -9079,7 +9140,7 @@ void main(void) {
9079
9140
  }`
9080
9141
  }));
9081
9142
  __decorateClass$u([
9082
- modernIdoc.property()
9143
+ modernIdoc.property({ fallback: 10 })
9083
9144
  ], exports.PixelateEffect.prototype, "strength", 2);
9084
9145
  exports.PixelateEffect = __decorateClass$u([
9085
9146
  customNode("PixelateEffect")
@@ -9210,13 +9271,13 @@ __decorateClass$t([
9210
9271
  modernIdoc.property()
9211
9272
  ], exports.ZoomBlurEffect.prototype, "center", 2);
9212
9273
  __decorateClass$t([
9213
- modernIdoc.property()
9274
+ modernIdoc.property({ fallback: 20 })
9214
9275
  ], exports.ZoomBlurEffect.prototype, "innerRadius", 2);
9215
9276
  __decorateClass$t([
9216
- modernIdoc.property()
9277
+ modernIdoc.property({ fallback: -1 })
9217
9278
  ], exports.ZoomBlurEffect.prototype, "radius", 2);
9218
9279
  __decorateClass$t([
9219
- modernIdoc.property()
9280
+ modernIdoc.property({ fallback: 0.1 })
9220
9281
  ], exports.ZoomBlurEffect.prototype, "strength", 2);
9221
9282
  exports.ZoomBlurEffect = __decorateClass$t([
9222
9283
  customNode("ZoomBlurEffect")
@@ -9958,36 +10019,67 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
9958
10019
  this._updateOverflow();
9959
10020
  }
9960
10021
  getRect() {
9961
- const { width: w, height: h } = this.size;
10022
+ return this.getGlobalAabb();
10023
+ }
10024
+ _getPointArray() {
10025
+ const { width, height } = this.size;
9962
10026
  const x1 = 0;
9963
10027
  const y1 = 0;
9964
- const x2 = x1 + w;
9965
- const y2 = y1 + h;
9966
- const [a, c, tx, b, d, ty] = this.globalTransform.toArray();
9967
- const points = [
10028
+ const x2 = x1 + width;
10029
+ const y2 = y1 + height;
10030
+ return [
9968
10031
  [x1, y1],
9969
10032
  [x1, y2],
9970
10033
  [x2, y1],
9971
10034
  [x2, y2]
9972
- ].map((p) => {
9973
- return [
9974
- a * p[0] + c * p[1] + tx,
9975
- b * p[0] + d * p[1] + ty
9976
- ];
9977
- });
9978
- const xx = points.map((p) => p[0]);
9979
- const yy = points.map((p) => p[1]);
9980
- const minX = Math.min(...xx);
9981
- const maxX = Math.max(...xx);
9982
- const minY = Math.min(...yy);
9983
- const maxY = Math.max(...yy);
10035
+ ];
10036
+ }
10037
+ getAabb() {
9984
10038
  return new Rect2(
9985
- minX,
9986
- minY,
9987
- maxX - minX,
9988
- maxY - minY
10039
+ this._getPointArray().map((p) => {
10040
+ return this.transform.applyToPoint(p[0], p[1]);
10041
+ })
10042
+ );
10043
+ }
10044
+ getGlobalAabb() {
10045
+ return new Rect2(
10046
+ this._getPointArray().map((p) => {
10047
+ return this.globalTransform.applyToPoint(p[0], p[1]);
10048
+ })
9989
10049
  );
9990
10050
  }
10051
+ getObb() {
10052
+ const origin = this.getTransformOrigin();
10053
+ const _origin = this.transform.applyToPoint(origin.x, origin.y);
10054
+ const offset = [_origin[0] - origin.x, _origin[1] - origin.y];
10055
+ return {
10056
+ rect: new Rect2(
10057
+ this._getPointArray().map((p) => {
10058
+ return [
10059
+ p[0] + offset[0],
10060
+ p[1] + offset[1]
10061
+ ];
10062
+ })
10063
+ ),
10064
+ rotation: this.rotation
10065
+ };
10066
+ }
10067
+ getGlobalObb() {
10068
+ const origin = this.getTransformOrigin();
10069
+ const _origin = this.globalTransform.applyToPoint(origin.x, origin.y);
10070
+ const offset = [_origin[0] - origin.x, _origin[1] - origin.y];
10071
+ return {
10072
+ rect: new Rect2(
10073
+ this._getPointArray().map((p) => {
10074
+ return [
10075
+ p[0] + offset[0],
10076
+ p[1] + offset[1]
10077
+ ];
10078
+ })
10079
+ ),
10080
+ rotation: this.globalRotation
10081
+ };
10082
+ }
9991
10083
  // protected _rectsOverlap(r1: any, r2: any): boolean {
9992
10084
  // return (
9993
10085
  // r1.x < r2.x + r2.width
package/dist/index.d.cts CHANGED
@@ -498,9 +498,16 @@ declare class Rect2 {
498
498
  readonly position: Vector2;
499
499
  readonly size: Vector2;
500
500
  constructor(from: Rect2);
501
+ constructor(pointArray: [number, number][]);
501
502
  constructor(position: Vector2, size: Vector2);
502
503
  constructor(x: number, y: number, width: number, height: number);
503
504
  update(): this;
505
+ toMinmax(): {
506
+ minX: number;
507
+ minY: number;
508
+ maxX: number;
509
+ maxY: number;
510
+ };
504
511
  toArray(): number[];
505
512
  toJSON(): {
506
513
  x: number;
@@ -510,7 +517,7 @@ declare class Rect2 {
510
517
  };
511
518
  }
512
519
 
513
- interface Transform2DObject {
520
+ interface TransformObject {
514
521
  a: number;
515
522
  c: number;
516
523
  tx: number;
@@ -519,6 +526,21 @@ interface Transform2DObject {
519
526
  ty: number;
520
527
  tz: number;
521
528
  }
529
+ interface TransformableObject {
530
+ position: {
531
+ x: number;
532
+ y: number;
533
+ };
534
+ scale: {
535
+ x: number;
536
+ y: number;
537
+ };
538
+ skew: {
539
+ x: number;
540
+ y: number;
541
+ };
542
+ rotation: number;
543
+ }
522
544
  /**
523
545
  * Transform
524
546
  *
@@ -552,10 +574,14 @@ declare class Transform2D extends Matrix3 {
552
574
  protected _rotateToScale(rad: number): number;
553
575
  protected _rotate3d(x: number, y: number, z: number, rad: number): number[];
554
576
  makeRotation(theta: number): this;
555
- applyToPoint(x: number, y: number): number[];
577
+ applyToPoint(x: number, y: number): [number, number];
578
+ decompose(pivot?: {
579
+ x: number;
580
+ y: number;
581
+ }, output?: TransformableObject): TransformableObject;
556
582
  inverse(): this;
557
583
  isIdentity(): boolean;
558
- toObject(): Transform2DObject;
584
+ toObject(): TransformObject;
559
585
  }
560
586
 
561
587
  declare const DEG_TO_RAD: number;
@@ -2125,6 +2151,17 @@ declare class BaseElement2D extends Node2D implements Rectangulable {
2125
2151
  getTransform(cb?: (transform: Transform2D) => void): Transform2D;
2126
2152
  updateGlobalTransform(): void;
2127
2153
  getRect(): Rect2;
2154
+ protected _getPointArray(): [number, number][];
2155
+ getAabb(): Rect2;
2156
+ getGlobalAabb(): Rect2;
2157
+ getObb(): {
2158
+ rect: Rect2;
2159
+ rotation: number;
2160
+ };
2161
+ getGlobalObb(): {
2162
+ rect: Rect2;
2163
+ rotation: number;
2164
+ };
2128
2165
  protected _updateOverflow(): void;
2129
2166
  protected _draw(): void;
2130
2167
  protected _drawContent(): void;
@@ -2713,7 +2750,7 @@ interface ColorFilterEffectProperties {
2713
2750
  }
2714
2751
  declare class ColorFilterEffect extends Effect {
2715
2752
  static material: Material;
2716
- filter: string | undefined;
2753
+ filter?: string;
2717
2754
  protected _colorMatrix: ColorMatrix;
2718
2755
  constructor(properties?: Partial<ColorFilterEffectProperties>, children?: Node[]);
2719
2756
  apply(renderer: WebGLRenderer, source: Viewport): void;
@@ -2881,7 +2918,7 @@ interface MaskEffectProperties extends EffectProperties {
2881
2918
  }
2882
2919
  declare class MaskEffect extends Effect {
2883
2920
  static material: Material;
2884
- texture: Texture2D<ImageBitmap> | undefined;
2921
+ texture?: Texture2D<ImageBitmap>;
2885
2922
  src: string;
2886
2923
  constructor(properties?: Partial<MaskEffectProperties>, children?: Node[]);
2887
2924
  load(): Promise<void>;
@@ -2932,7 +2969,7 @@ interface ZoomBlurEffectProperties extends EffectProperties {
2932
2969
  }
2933
2970
  declare class ZoomBlurEffect extends Effect {
2934
2971
  static material: Material;
2935
- center: number[] | undefined;
2972
+ center?: number[];
2936
2973
  innerRadius: number;
2937
2974
  radius: number;
2938
2975
  strength: number;
@@ -3269,4 +3306,4 @@ interface RenderOptions {
3269
3306
  declare function render(options: RenderOptions): Promise<HTMLCanvasElement>;
3270
3307
 
3271
3308
  export { AnimatedTexture, Animation, Assets, Audio, AudioPipeline, AudioProcessor, AudioSpectrum, AudioWaveform, BaseElement2D, BaseElement2DBackground, BaseElement2DFill, BaseElement2DForeground, BaseElement2DOutline, BaseElement2DShadow, BaseElement2DShape, BaseElement2DStyle, BaseElement2DText, Camera2D, CanvasContext, CanvasItem, CanvasItemEditor, CanvasTexture, Color, ColorAdjustEffect, ColorFilterEffect, ColorMatrix, ColorOverlayEffect, ColorRemoveEffect, ColorReplaceEffect, ColorTexture, Control, CoreObject, DEG_TO_RAD, DEVICE_PIXEL_RATIO, DropShadowEffect, Effect, EffectMaterial, Element2D, Element2DStyle, EmbossEffect, Engine, FlexElement2D, FlexElement2DStyle, FlexLayout, FontLoader, GIFLoader, GaussianBlurEffect, Geometry, GlitchEffect, GodrayEffect, GradientTexture, HTMLAudio, HTMLAudioContext, HTMLSound, IN_BROWSER, Image2D, ImageTexture, IndexBuffer, Input, InputEvent, JSONLoader, KawaseBlurEffect, KawaseTransition, KeyboardInputEvent, LeftEraseTransition, Loader, Lottie2D, LottieLoader, MainLoop, MaskEffect, Material, Matrix, Matrix2, Matrix3, Matrix4, MouseInputEvent, Node, Node2D, OutlineEffect, PI, PI_2, PixelateEffect, PixelsTexture, PointerInputEvent, Projection2D, QuadGeometry, QuadUvGeometry, RAD_TO_DEG, Range, RawWeakMap, Rect2, RefCounted, Renderer, Resource, Ruler, SUPPORTS_AUDIO_CONTEXT, SUPPORTS_CLICK_EVENTS, SUPPORTS_CREATE_IMAGE_BITMAP, SUPPORTS_IMAGE_BITMAP, SUPPORTS_MOUSE_EVENTS, SUPPORTS_OFFLINE_AUDIO_CONTEXT, SUPPORTS_POINTER_EVENTS, SUPPORTS_RESIZE_OBSERVER, SUPPORTS_TOUCH_EVENTS, SUPPORTS_WEBGL2, SUPPORTS_WEBKIT_AUDIO_CONTEXT, SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT, SUPPORTS_WEB_AUDIO, SUPPORTS_WHEEL_EVENTS, Scaler, SceneTree, ScrollBar, TextLoader, Texture2D, TextureLoader, TextureRect2D, Ticker, TiltShiftTransition, Timeline, TimelineNode, Transform2D, TransformRect2D, Transition, TwistTransition, UvGeometry, UvMaterial, Vector, Vector2, Vector3, Vector4, VertexAttribute, VertexBuffer, Video2D, VideoLoader, VideoTexture, Viewport, ViewportTexture, WebAudio, WebAudioContext, WebGLBatch2DModule, WebGLBlendMode, WebGLBufferModule, WebGLFramebufferModule, WebGLMaskModule, WebGLModule, WebGLProgramModule, WebGLRenderer, WebGLScissorModule, WebGLState, WebGLStateModule, WebGLStencilModule, WebGLTextureModule, WebGLVertexArrayModule, WebGLViewportModule, WebSound, WheelInputEvent, Window, XScrollBar, YScrollBar, ZoomBlurEffect, assets, clamp, clampFrag, createHTMLCanvas, createNode, crossOrigin, cubicBezier, curves, customNode, customNodes, defaultOptions, determineCrossOrigin, ease, easeIn, easeInOut, easeOut, frag, getDefaultCssPropertyValue, isCanvasElement, isElementNode, isImageElement, isPow2, isVideoElement, isWebgl2, lerp, linear, log2, mapWebGLBlendModes, nextPow2, nextTick, parseCSSFilter, parseCSSTransform, parseCSSTransformOrigin, parseCssFunctions, parseCssProperty, render, timingFunctions, uid };
3272
- export type { AnimationEffectMode, AnimationProperties, AssetHandler, AudioWaveformProperties, BaseElement2DEventMap, BaseElement2DProperties, BaseElement2DStyleProperties, Batchable2D, CSSFilterKey, CSSFilters, Camera2DEventMap, Camera2DProperties, CanvasBatchable, CanvasItemEventMap, CanvasItemProperties, ColorAdjustEffectProperties, ColorFilterEffectProperties, ColorOverlayEffectProperties, ColorRemoveEffectProperties, ColorReplaceEffectProperties, ComputedLayout, ControlEventMap, ControlProperties, CoreObjectEventMap, CssFunction, CssFunctionArg, Cursor, CustomPropertyAccessor, DropShadowEffectProperties, Easing, EffectContext, EffectMode, EffectProperties, Element2DEventMap, Element2DProperties, Element2DStyleProperties, EmbossEffectProperties, EngineOptions, FillDraw, FlexBaseElement2DEventMap, FlexElement2DProperties, FlexElement2DStyleProperties, GaussianBlurEffectProperties, GeometryOptions, GlitchEffectProperties, GodrayEffectProperties, IAudioContext, IAudioNode, IPlayOptions, Image2DProperties, ImageFrame, ImageTextureOptions, IndexBufferOptions, InputEventKey, InputEventMap, InternalMode, KawaseBlurEffectProperties, Keyframe, Lottie2DProperties, MainLoopEventMap, MaskColor, MaskData, MaskEffectProperties, MaskObject, MaskRect, Maskable, MaterialOptions, MatrixLike, MatrixOperateOutput, Node2DEventMap, Node2DProperties, NodeEventMap, NodeProperties, NormalizedKeyframe, OutlineEffectProperties, PixelateEffectProperties, PlatformAudio, PlatformSound, ProcessMode, ProcessSortMode, RangeProperties, Rectangulable, RectangulableEventMap, RefCountedEventMap, RenderMode, RenderOptions, Renderable, ResourceEventMap, RulerProperties, ScalerEventMap, ScalerProperties, SceneTreeEventMap, ScrollBarProperties, StrokeDraw, Texture2DFilterMode, Texture2DPixelsSource, Texture2DSource, Texture2DWrapMode, TextureRect2DProperties, TimelineEventMap, TimelineNodeEventMap, TimelineNodeProperties, TimelineProperties, TimingFunctions, Transform2DObject, TransformRect2DProperties, TransitionProperties, UVTransform, VectorLike, VectorOperateOutput, VertTransform, VertexAttributeOptions, VertexBufferOptions, Video2DProperties, VideoTextureOptions, VideoTextureSource, ViewportEventMap, ViewportFramebuffer, WebGLBufferMeta, WebGLBufferOptions, WebGLBufferTarget, WebGLBufferUsage, WebGLDrawMode, WebGLDrawOptions, WebGLExtensions, WebGLFramebufferMeta, WebGLFramebufferOptions, WebGLProgramMeta, WebGLProgramOptions, WebGLTarget, WebGLTextureFilterMode, WebGLTextureLocation, WebGLTextureMeta, WebGLTextureOptions, WebGLTextureSource, WebGLTextureTarget, WebGLTextureWrapMode, WebGLVertexArrayObjectMeta, WebGLVertexArrayObjectOptions, WebGLVertexAttrib, WebGLVertexAttribType, WebGLViewport, XScrollBarProperties, YScrollBarProperties, ZoomBlurEffectProperties };
3309
+ export type { AnimationEffectMode, AnimationProperties, AssetHandler, AudioWaveformProperties, BaseElement2DEventMap, BaseElement2DProperties, BaseElement2DStyleProperties, Batchable2D, CSSFilterKey, CSSFilters, Camera2DEventMap, Camera2DProperties, CanvasBatchable, CanvasItemEventMap, CanvasItemProperties, ColorAdjustEffectProperties, ColorFilterEffectProperties, ColorOverlayEffectProperties, ColorRemoveEffectProperties, ColorReplaceEffectProperties, ComputedLayout, ControlEventMap, ControlProperties, CoreObjectEventMap, CssFunction, CssFunctionArg, Cursor, CustomPropertyAccessor, DropShadowEffectProperties, Easing, EffectContext, EffectMode, EffectProperties, Element2DEventMap, Element2DProperties, Element2DStyleProperties, EmbossEffectProperties, EngineOptions, FillDraw, FlexBaseElement2DEventMap, FlexElement2DProperties, FlexElement2DStyleProperties, GaussianBlurEffectProperties, GeometryOptions, GlitchEffectProperties, GodrayEffectProperties, IAudioContext, IAudioNode, IPlayOptions, Image2DProperties, ImageFrame, ImageTextureOptions, IndexBufferOptions, InputEventKey, InputEventMap, InternalMode, KawaseBlurEffectProperties, Keyframe, Lottie2DProperties, MainLoopEventMap, MaskColor, MaskData, MaskEffectProperties, MaskObject, MaskRect, Maskable, MaterialOptions, MatrixLike, MatrixOperateOutput, Node2DEventMap, Node2DProperties, NodeEventMap, NodeProperties, NormalizedKeyframe, OutlineEffectProperties, PixelateEffectProperties, PlatformAudio, PlatformSound, ProcessMode, ProcessSortMode, RangeProperties, Rectangulable, RectangulableEventMap, RefCountedEventMap, RenderMode, RenderOptions, Renderable, ResourceEventMap, RulerProperties, ScalerEventMap, ScalerProperties, SceneTreeEventMap, ScrollBarProperties, StrokeDraw, Texture2DFilterMode, Texture2DPixelsSource, Texture2DSource, Texture2DWrapMode, TextureRect2DProperties, TimelineEventMap, TimelineNodeEventMap, TimelineNodeProperties, TimelineProperties, TimingFunctions, TransformObject, TransformRect2DProperties, TransformableObject, TransitionProperties, UVTransform, VectorLike, VectorOperateOutput, VertTransform, VertexAttributeOptions, VertexBufferOptions, Video2DProperties, VideoTextureOptions, VideoTextureSource, ViewportEventMap, ViewportFramebuffer, WebGLBufferMeta, WebGLBufferOptions, WebGLBufferTarget, WebGLBufferUsage, WebGLDrawMode, WebGLDrawOptions, WebGLExtensions, WebGLFramebufferMeta, WebGLFramebufferOptions, WebGLProgramMeta, WebGLProgramOptions, WebGLTarget, WebGLTextureFilterMode, WebGLTextureLocation, WebGLTextureMeta, WebGLTextureOptions, WebGLTextureSource, WebGLTextureTarget, WebGLTextureWrapMode, WebGLVertexArrayObjectMeta, WebGLVertexArrayObjectOptions, WebGLVertexAttrib, WebGLVertexAttribType, WebGLViewport, XScrollBarProperties, YScrollBarProperties, ZoomBlurEffectProperties };