modern-canvas 0.7.12 → 0.7.14

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
@@ -1763,7 +1763,17 @@ class Matrix3 extends Matrix {
1763
1763
  const t13 = n23 * n12 - n22 * n13;
1764
1764
  const det = n11 * t11 + n21 * t12 + n31 * t13;
1765
1765
  if (det === 0) {
1766
- return this.set([0, 0, 0, 0, 0, 0, 0, 0, 0]);
1766
+ return this.set([
1767
+ 0,
1768
+ 0,
1769
+ 0,
1770
+ 0,
1771
+ 0,
1772
+ 0,
1773
+ 0,
1774
+ 0,
1775
+ 0
1776
+ ]);
1767
1777
  }
1768
1778
  const detInv = 1 / det;
1769
1779
  return this.set([
@@ -1950,10 +1960,23 @@ class Rect2 {
1950
1960
  switch (args.length) {
1951
1961
  case 0:
1952
1962
  break;
1953
- case 1:
1954
- position.set(args[0].position);
1955
- size.set(args[0].size);
1963
+ case 1: {
1964
+ const arg = args[0];
1965
+ if (arg instanceof Rect2) {
1966
+ position.set(arg.position);
1967
+ size.set(arg.size);
1968
+ } else {
1969
+ const xx = arg.map((p) => p.x);
1970
+ const yy = arg.map((p) => p.y);
1971
+ const minX = Math.min(...xx);
1972
+ const maxX = Math.max(...xx);
1973
+ const minY = Math.min(...yy);
1974
+ const maxY = Math.max(...yy);
1975
+ position.set(minX, minY);
1976
+ size.set(maxX - minX, maxY - minY);
1977
+ }
1956
1978
  break;
1979
+ }
1957
1980
  case 2:
1958
1981
  position.set(args[0]);
1959
1982
  size.set(args[1]);
@@ -1975,6 +1998,14 @@ class Rect2 {
1975
1998
  );
1976
1999
  return this;
1977
2000
  }
2001
+ toMinmax() {
2002
+ return {
2003
+ minX: this.position.x,
2004
+ minY: this.position.y,
2005
+ maxX: this.end.x,
2006
+ maxY: this.end.y
2007
+ };
2008
+ }
1978
2009
  toArray() {
1979
2010
  return [this.x, this.y, this.width, this.height];
1980
2011
  }
@@ -2134,22 +2165,68 @@ class Transform2D extends Matrix3 {
2134
2165
  ]);
2135
2166
  return this;
2136
2167
  }
2137
- applyToPoint(x, y) {
2168
+ decompose(pivot = { x: 0, y: 0 }, output = {
2169
+ position: { x: 0, y: 0 },
2170
+ scale: { x: 0, y: 0 },
2171
+ skew: { x: 0, y: 0 },
2172
+ rotation: 0
2173
+ }) {
2174
+ const { a, b, c, d, tx, ty } = this.toObject();
2175
+ const skewX = -Math.atan2(-c, d);
2176
+ const skewY = Math.atan2(b, a);
2177
+ const delta = Math.abs(skewX + skewY);
2178
+ if (delta < 1e-5 || Math.abs(PI_2 - delta) < 1e-5) {
2179
+ output.rotation = skewY;
2180
+ output.skew.x = output.skew.y = 0;
2181
+ } else {
2182
+ output.rotation = 0;
2183
+ output.skew.x = skewX;
2184
+ output.skew.y = skewY;
2185
+ }
2186
+ output.scale.x = Math.sqrt(a * a + b * b);
2187
+ output.scale.y = Math.sqrt(c * c + d * d);
2188
+ output.position.x = tx + (pivot.x * a + pivot.y * c);
2189
+ output.position.y = ty + (pivot.x * b + pivot.y * d);
2190
+ return output;
2191
+ }
2192
+ apply(pos, newPos) {
2193
+ newPos = newPos || new Vector2();
2138
2194
  const { a, c, tx, b, d, ty } = this.toObject();
2139
- return [
2140
- a * x + c * y + tx,
2141
- b * x + d * y + ty
2142
- ];
2195
+ const x = pos.x;
2196
+ const y = pos.y;
2197
+ newPos.x = a * x + c * y + tx;
2198
+ newPos.y = b * x + d * y + ty;
2199
+ return newPos;
2143
2200
  }
2144
2201
  inverse() {
2145
2202
  return this.clone().invert();
2146
2203
  }
2204
+ applyInverse(pos, newPos) {
2205
+ newPos = newPos || new Vector2();
2206
+ const { a, b, c, d, tx, ty } = this.toObject();
2207
+ const id = 1 / (a * d + c * -b);
2208
+ const x = pos.x;
2209
+ const y = pos.y;
2210
+ newPos.x = d * id * x + -c * id * y + (ty * c - tx * d) * id;
2211
+ newPos.y = a * id * y + -b * id * x + (-ty * a + tx * b) * id;
2212
+ return newPos;
2213
+ }
2147
2214
  isIdentity() {
2148
2215
  const { a, b, c, d, tx, ty } = this.toObject();
2149
2216
  return a === 1 && b === 0 && c === 0 && d === 1 && tx === 0 && ty === 0;
2150
2217
  }
2151
2218
  toObject() {
2152
- const [a, c, tx, b, d, ty, , , tz] = this._array;
2219
+ const [
2220
+ a,
2221
+ c,
2222
+ tx,
2223
+ b,
2224
+ d,
2225
+ ty,
2226
+ ,
2227
+ ,
2228
+ tz
2229
+ ] = this._array;
2153
2230
  return { a, c, tx, b, d, ty, tz };
2154
2231
  }
2155
2232
  }
@@ -5581,7 +5658,7 @@ class CanvasContext extends modernPath2d.Path2D {
5581
5658
  }
5582
5659
  buildUvs(start, vertices, uvs, texture, uvTransform) {
5583
5660
  if (texture) {
5584
- const _uvTransform = uvTransform ? typeof uvTransform === "function" ? uvTransform : (x, y) => uvTransform.applyToPoint(x, y) : uvTransform;
5661
+ const _uvTransform = uvTransform ? typeof uvTransform === "function" ? uvTransform : (x, y) => uvTransform.apply({ x, y }).toArray() : uvTransform;
5585
5662
  const w = texture.width;
5586
5663
  const h = texture.height;
5587
5664
  for (let len = vertices.length, i = start; i < len; i += 2) {
@@ -6488,7 +6565,7 @@ exports.Viewport = class Viewport extends exports.Node {
6488
6565
  this.projection.flipY(flipY);
6489
6566
  }
6490
6567
  projection = new Projection2D();
6491
- canvasTransform = new Transform2D();
6568
+ worldTransform = new Transform2D();
6492
6569
  _framebufferIndex = 0;
6493
6570
  _framebuffers = [
6494
6571
  { texture: new ViewportTexture(), needsUpload: false },
@@ -6603,7 +6680,7 @@ exports.Viewport = class Viewport extends exports.Node {
6603
6680
  render(renderer, next) {
6604
6681
  const oldViewport = this._tree?.getCurrentViewport();
6605
6682
  renderer.program.uniforms.projectionMatrix = this.projection.toArray(true);
6606
- renderer.program.uniforms.worldTransformMatrix = this.canvasTransform.toArray(true);
6683
+ renderer.program.uniforms.worldTransformMatrix = this.worldTransform.toArray(true);
6607
6684
  this.activate(renderer);
6608
6685
  renderer.clear();
6609
6686
  super.render(renderer, next);
@@ -6618,6 +6695,12 @@ exports.Viewport = class Viewport extends exports.Node {
6618
6695
  getRect() {
6619
6696
  return new Rect2(this.x, this.y, this.width, this.height);
6620
6697
  }
6698
+ toGlobal(worldPos, newPos) {
6699
+ return this.worldTransform.applyInverse(worldPos, newPos);
6700
+ }
6701
+ toWorld(globalPos, newPos) {
6702
+ return this.worldTransform.apply(globalPos, newPos);
6703
+ }
6621
6704
  };
6622
6705
  __decorateClass$P([
6623
6706
  modernIdoc.property({ fallback: 0 })
@@ -6891,10 +6974,10 @@ __decorateClass$O([
6891
6974
  modernIdoc.property()
6892
6975
  ], exports.Effect.prototype, "effectMode", 2);
6893
6976
  __decorateClass$O([
6894
- modernIdoc.property()
6977
+ modernIdoc.property({ fallback: "" })
6895
6978
  ], exports.Effect.prototype, "glsl", 2);
6896
6979
  __decorateClass$O([
6897
- modernIdoc.property()
6980
+ modernIdoc.property({ fallback: "" })
6898
6981
  ], exports.Effect.prototype, "glslSrc", 2);
6899
6982
  exports.Effect = __decorateClass$O([
6900
6983
  customNode("Effect")
@@ -7170,25 +7253,27 @@ exports.Node2D = class Node2D extends exports.CanvasItem {
7170
7253
  const parent = this.getParent();
7171
7254
  if (parent?.globalTransform) {
7172
7255
  this._parentTransformDirtyId = parent.globalTransform.dirtyId;
7173
- this.globalScale.set(parent.globalScale.x * this.scale.x, parent.globalScale.y * this.scale.y);
7256
+ this.globalPosition.set(
7257
+ parent.globalPosition.x + this.position.x,
7258
+ parent.globalPosition.y + this.position.y
7259
+ );
7260
+ this.globalScale.set(
7261
+ parent.globalScale.x * this.scale.x,
7262
+ parent.globalScale.y * this.scale.y
7263
+ );
7264
+ this.globalSkew.set(
7265
+ parent.globalSkew.x * this.skew.x,
7266
+ parent.globalSkew.y * this.skew.y
7267
+ );
7174
7268
  this.globalRotation = parent.globalRotation + this.rotation;
7175
7269
  parent.globalTransform.multiply(this.transform, this.globalTransform);
7176
7270
  } else {
7271
+ this.globalPosition.copy(this.position);
7177
7272
  this.globalScale.copy(this.scale);
7273
+ this.globalSkew.copy(this.skew);
7178
7274
  this.globalRotation = this.rotation;
7179
7275
  this.globalTransform.copy(this.transform);
7180
7276
  }
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
7277
  this.requestRelayout();
7193
7278
  }
7194
7279
  _transformVertices(vertices, vertTransform) {
@@ -7228,6 +7313,12 @@ exports.Node2D = class Node2D extends exports.CanvasItem {
7228
7313
  this.requestRelayout();
7229
7314
  }
7230
7315
  }
7316
+ toLocal(globalPos, newPos) {
7317
+ return this.globalTransform.applyInverse(globalPos, newPos);
7318
+ }
7319
+ toGlobal(localPos, newPos) {
7320
+ return this.globalTransform.apply(localPos, newPos);
7321
+ }
7231
7322
  };
7232
7323
  __decorateClass$J([
7233
7324
  modernIdoc.property({ protected: true, fallback: 0 })
@@ -7250,7 +7341,7 @@ var __decorateClass$I = (decorators, target, key, kind) => {
7250
7341
  return result;
7251
7342
  };
7252
7343
  exports.Camera2D = class Camera2D extends exports.Node2D {
7253
- zoom = new Vector2(1, 1).on("update", () => this.updateCanvasTransform());
7344
+ zoom = new Vector2(1, 1).on("update", () => this.updateWorldTransform());
7254
7345
  maxZoom = new Vector2(6, 6);
7255
7346
  minZoom = new Vector2(0.1, 0.1);
7256
7347
  _screenOffset = { x: 0, y: 0 };
@@ -7337,14 +7428,14 @@ exports.Camera2D = class Camera2D extends exports.Node2D {
7337
7428
  }
7338
7429
  updateTransform() {
7339
7430
  super.updateTransform();
7340
- this.updateCanvasTransform();
7431
+ this.updateWorldTransform();
7341
7432
  }
7342
- updateCanvasTransform() {
7433
+ updateWorldTransform() {
7343
7434
  const viewport = this.getViewport();
7344
7435
  if (!viewport)
7345
7436
  return;
7346
- viewport.canvasTransform.identity().scale(this.zoom.x, this.zoom.y).translate(this.position.x, this.position.y);
7347
- this.emit("updateCanvasTransform");
7437
+ viewport.worldTransform.identity().scale(this.zoom.x, this.zoom.y).translate(this.position.x, this.position.y);
7438
+ this.emit("updateWorldTransform");
7348
7439
  }
7349
7440
  };
7350
7441
  __decorateClass$I([
@@ -7575,28 +7666,28 @@ void main(void) {
7575
7666
  }`
7576
7667
  }));
7577
7668
  __decorateClass$H([
7578
- modernIdoc.property()
7669
+ modernIdoc.property({ fallback: 1 })
7579
7670
  ], exports.ColorAdjustEffect.prototype, "saturation", 2);
7580
7671
  __decorateClass$H([
7581
- modernIdoc.property()
7672
+ modernIdoc.property({ fallback: 1 })
7582
7673
  ], exports.ColorAdjustEffect.prototype, "contrast", 2);
7583
7674
  __decorateClass$H([
7584
- modernIdoc.property()
7675
+ modernIdoc.property({ fallback: 1 })
7585
7676
  ], exports.ColorAdjustEffect.prototype, "brightness", 2);
7586
7677
  __decorateClass$H([
7587
- modernIdoc.property()
7678
+ modernIdoc.property({ fallback: 1 })
7588
7679
  ], exports.ColorAdjustEffect.prototype, "red", 2);
7589
7680
  __decorateClass$H([
7590
- modernIdoc.property()
7681
+ modernIdoc.property({ fallback: 1 })
7591
7682
  ], exports.ColorAdjustEffect.prototype, "green", 2);
7592
7683
  __decorateClass$H([
7593
- modernIdoc.property()
7684
+ modernIdoc.property({ fallback: 1 })
7594
7685
  ], exports.ColorAdjustEffect.prototype, "blue", 2);
7595
7686
  __decorateClass$H([
7596
- modernIdoc.property()
7687
+ modernIdoc.property({ fallback: 1 })
7597
7688
  ], exports.ColorAdjustEffect.prototype, "alpha", 2);
7598
7689
  __decorateClass$H([
7599
- modernIdoc.property()
7690
+ modernIdoc.property({ fallback: 1 })
7600
7691
  ], exports.ColorAdjustEffect.prototype, "gamma", 2);
7601
7692
  exports.ColorAdjustEffect = __decorateClass$H([
7602
7693
  customNode("ColorAdjustEffect")
@@ -7782,10 +7873,10 @@ void main(void) {
7782
7873
  }`
7783
7874
  }));
7784
7875
  __decorateClass$F([
7785
- modernIdoc.property()
7876
+ modernIdoc.property({ default: () => [] })
7786
7877
  ], exports.ColorOverlayEffect.prototype, "colors", 2);
7787
7878
  __decorateClass$F([
7788
- modernIdoc.property()
7879
+ modernIdoc.property({ fallback: 0.5 })
7789
7880
  ], exports.ColorOverlayEffect.prototype, "alpha", 2);
7790
7881
  exports.ColorOverlayEffect = __decorateClass$F([
7791
7882
  customNode("ColorOverlayEffect")
@@ -7867,10 +7958,10 @@ void main(void) {
7867
7958
  }`
7868
7959
  }));
7869
7960
  __decorateClass$E([
7870
- modernIdoc.property()
7961
+ modernIdoc.property({ default: () => [] })
7871
7962
  ], exports.ColorRemoveEffect.prototype, "colors", 2);
7872
7963
  __decorateClass$E([
7873
- modernIdoc.property()
7964
+ modernIdoc.property({ fallback: 0.5 })
7874
7965
  ], exports.ColorRemoveEffect.prototype, "epsilon", 2);
7875
7966
  exports.ColorRemoveEffect = __decorateClass$E([
7876
7967
  customNode("ColorRemoveEffect")
@@ -7974,10 +8065,10 @@ void main(void) {
7974
8065
  }`
7975
8066
  }));
7976
8067
  __decorateClass$D([
7977
- modernIdoc.property()
8068
+ modernIdoc.property({ default: () => [] })
7978
8069
  ], exports.ColorReplaceEffect.prototype, "colors", 2);
7979
8070
  __decorateClass$D([
7980
- modernIdoc.property()
8071
+ modernIdoc.property({ fallback: 0.05 })
7981
8072
  ], exports.ColorReplaceEffect.prototype, "epsilon", 2);
7982
8073
  exports.ColorReplaceEffect = __decorateClass$D([
7983
8074
  customNode("ColorReplaceEffect")
@@ -8098,10 +8189,10 @@ void main(void) {
8098
8189
  frag: frag$2
8099
8190
  }));
8100
8191
  __decorateClass$C([
8101
- modernIdoc.property({ default: 4 })
8192
+ modernIdoc.property({ fallback: 4 })
8102
8193
  ], exports.GaussianBlurEffect.prototype, "strength", 2);
8103
8194
  __decorateClass$C([
8104
- modernIdoc.property({ default: 3 })
8195
+ modernIdoc.property({ fallback: 3 })
8105
8196
  ], exports.GaussianBlurEffect.prototype, "quality", 2);
8106
8197
  exports.GaussianBlurEffect = __decorateClass$C([
8107
8198
  customNode("GaussianBlurEffect")
@@ -8180,19 +8271,19 @@ void main(void) {
8180
8271
  }`
8181
8272
  }));
8182
8273
  __decorateClass$B([
8183
- modernIdoc.property()
8274
+ modernIdoc.property({ fallback: "#000000FF" })
8184
8275
  ], exports.DropShadowEffect.prototype, "color", 2);
8185
8276
  __decorateClass$B([
8186
- modernIdoc.property()
8277
+ modernIdoc.property({ fallback: 4 })
8187
8278
  ], exports.DropShadowEffect.prototype, "blur", 2);
8188
8279
  __decorateClass$B([
8189
- modernIdoc.property()
8280
+ modernIdoc.property({ fallback: 4 })
8190
8281
  ], exports.DropShadowEffect.prototype, "offsetX", 2);
8191
8282
  __decorateClass$B([
8192
- modernIdoc.property()
8283
+ modernIdoc.property({ fallback: 4 })
8193
8284
  ], exports.DropShadowEffect.prototype, "offsetY", 2);
8194
8285
  __decorateClass$B([
8195
- modernIdoc.property()
8286
+ modernIdoc.property({ fallback: false })
8196
8287
  ], exports.DropShadowEffect.prototype, "shadowOnly", 2);
8197
8288
  exports.DropShadowEffect = __decorateClass$B([
8198
8289
  customNode("DropShadowEffect")
@@ -8252,7 +8343,7 @@ void main(void) {
8252
8343
  }`
8253
8344
  }));
8254
8345
  __decorateClass$A([
8255
- modernIdoc.property()
8346
+ modernIdoc.property({ fallback: 5 })
8256
8347
  ], exports.EmbossEffect.prototype, "strength", 2);
8257
8348
  exports.EmbossEffect = __decorateClass$A([
8258
8349
  customNode("EmbossEffect")
@@ -8441,31 +8532,31 @@ void main(void) {
8441
8532
  }`
8442
8533
  }));
8443
8534
  __decorateClass$z([
8444
- modernIdoc.property()
8535
+ modernIdoc.property({ fallback: 10 })
8445
8536
  ], exports.GlitchEffect.prototype, "slices", 2);
8446
8537
  __decorateClass$z([
8447
- modernIdoc.property()
8538
+ modernIdoc.property({ fallback: 512 })
8448
8539
  ], exports.GlitchEffect.prototype, "sampleSize", 2);
8449
8540
  __decorateClass$z([
8450
- modernIdoc.property()
8541
+ modernIdoc.property({ fallback: 100 })
8451
8542
  ], exports.GlitchEffect.prototype, "offset", 2);
8452
8543
  __decorateClass$z([
8453
- modernIdoc.property()
8544
+ modernIdoc.property({ fallback: 0 })
8454
8545
  ], exports.GlitchEffect.prototype, "direction", 2);
8455
8546
  __decorateClass$z([
8456
- modernIdoc.property()
8547
+ modernIdoc.property({ fallback: 2 })
8457
8548
  ], exports.GlitchEffect.prototype, "fillMode", 2);
8458
8549
  __decorateClass$z([
8459
- modernIdoc.property()
8550
+ modernIdoc.property({ fallback: 0 })
8460
8551
  ], exports.GlitchEffect.prototype, "seed", 2);
8461
8552
  __decorateClass$z([
8462
- modernIdoc.property()
8553
+ modernIdoc.property({ default: () => [2, 2] })
8463
8554
  ], exports.GlitchEffect.prototype, "red", 2);
8464
8555
  __decorateClass$z([
8465
- modernIdoc.property()
8556
+ modernIdoc.property({ default: () => [-10, 4] })
8466
8557
  ], exports.GlitchEffect.prototype, "green", 2);
8467
8558
  __decorateClass$z([
8468
- modernIdoc.property()
8559
+ modernIdoc.property({ default: () => [10, -4] })
8469
8560
  ], exports.GlitchEffect.prototype, "blue", 2);
8470
8561
  exports.GlitchEffect = __decorateClass$z([
8471
8562
  customNode("GlitchEffect")
@@ -8658,25 +8749,25 @@ void main(void) {
8658
8749
  }`
8659
8750
  }));
8660
8751
  __decorateClass$y([
8661
- modernIdoc.property()
8752
+ modernIdoc.property({ fallback: 0 })
8662
8753
  ], exports.GodrayEffect.prototype, "time", 2);
8663
8754
  __decorateClass$y([
8664
- modernIdoc.property()
8755
+ modernIdoc.property({ fallback: 30 })
8665
8756
  ], exports.GodrayEffect.prototype, "angle", 2);
8666
8757
  __decorateClass$y([
8667
- modernIdoc.property()
8758
+ modernIdoc.property({ fallback: 0.5 })
8668
8759
  ], exports.GodrayEffect.prototype, "gain", 2);
8669
8760
  __decorateClass$y([
8670
- modernIdoc.property()
8761
+ modernIdoc.property({ fallback: 2.5 })
8671
8762
  ], exports.GodrayEffect.prototype, "lacunarity", 2);
8672
8763
  __decorateClass$y([
8673
- modernIdoc.property()
8764
+ modernIdoc.property({ fallback: true })
8674
8765
  ], exports.GodrayEffect.prototype, "parallel", 2);
8675
8766
  __decorateClass$y([
8676
- modernIdoc.property()
8767
+ modernIdoc.property({ default: () => [0, 0] })
8677
8768
  ], exports.GodrayEffect.prototype, "center", 2);
8678
8769
  __decorateClass$y([
8679
- modernIdoc.property()
8770
+ modernIdoc.property({ fallback: 1 })
8680
8771
  ], exports.GodrayEffect.prototype, "alpha", 2);
8681
8772
  exports.GodrayEffect = __decorateClass$y([
8682
8773
  customNode("GodrayEffect")
@@ -8780,13 +8871,13 @@ void main() {
8780
8871
  }
8781
8872
  };
8782
8873
  __decorateClass$x([
8783
- modernIdoc.property()
8874
+ modernIdoc.property({ fallback: 4 })
8784
8875
  ], exports.KawaseBlurEffect.prototype, "strength", 2);
8785
8876
  __decorateClass$x([
8786
- modernIdoc.property()
8877
+ modernIdoc.property({ fallback: 3 })
8787
8878
  ], exports.KawaseBlurEffect.prototype, "quality", 2);
8788
8879
  __decorateClass$x([
8789
- modernIdoc.property()
8880
+ modernIdoc.property({ default: () => [1, 1] })
8790
8881
  ], exports.KawaseBlurEffect.prototype, "pixelSize", 2);
8791
8882
  exports.KawaseBlurEffect = __decorateClass$x([
8792
8883
  customNode("KawaseBlurEffect")
@@ -8892,7 +8983,7 @@ __decorateClass$w([
8892
8983
  modernIdoc.property({ protected: true })
8893
8984
  ], exports.MaskEffect.prototype, "texture", 2);
8894
8985
  __decorateClass$w([
8895
- modernIdoc.property({ default: "" })
8986
+ modernIdoc.property({ fallback: "" })
8896
8987
  ], exports.MaskEffect.prototype, "src", 2);
8897
8988
  exports.MaskEffect = __decorateClass$w([
8898
8989
  customNode("MaskEffect")
@@ -8994,25 +9085,25 @@ void main() {
8994
9085
  __publicField$7(exports.OutlineEffect, "MIN_SAMPLES", 1);
8995
9086
  __publicField$7(exports.OutlineEffect, "MAX_SAMPLES", 100);
8996
9087
  __decorateClass$v([
8997
- modernIdoc.property()
9088
+ modernIdoc.property({ fallback: "#000000ff" })
8998
9089
  ], exports.OutlineEffect.prototype, "color", 2);
8999
9090
  __decorateClass$v([
9000
- modernIdoc.property()
9091
+ modernIdoc.property({ fallback: 1 })
9001
9092
  ], exports.OutlineEffect.prototype, "width", 2);
9002
9093
  __decorateClass$v([
9003
- modernIdoc.property()
9094
+ modernIdoc.property({ fallback: "solid" })
9004
9095
  ], exports.OutlineEffect.prototype, "style", 2);
9005
9096
  __decorateClass$v([
9006
9097
  modernIdoc.property()
9007
9098
  ], exports.OutlineEffect.prototype, "image", 2);
9008
9099
  __decorateClass$v([
9009
- modernIdoc.property()
9100
+ modernIdoc.property({ fallback: 1 })
9010
9101
  ], exports.OutlineEffect.prototype, "opacity", 2);
9011
9102
  __decorateClass$v([
9012
- modernIdoc.property()
9103
+ modernIdoc.property({ fallback: 0.1 })
9013
9104
  ], exports.OutlineEffect.prototype, "quality", 2);
9014
9105
  __decorateClass$v([
9015
- modernIdoc.property()
9106
+ modernIdoc.property({ fallback: false })
9016
9107
  ], exports.OutlineEffect.prototype, "knockout", 2);
9017
9108
  exports.OutlineEffect = __decorateClass$v([
9018
9109
  customNode("OutlineEffect")
@@ -9083,7 +9174,7 @@ void main(void) {
9083
9174
  }`
9084
9175
  }));
9085
9176
  __decorateClass$u([
9086
- modernIdoc.property()
9177
+ modernIdoc.property({ fallback: 10 })
9087
9178
  ], exports.PixelateEffect.prototype, "strength", 2);
9088
9179
  exports.PixelateEffect = __decorateClass$u([
9089
9180
  customNode("PixelateEffect")
@@ -9214,13 +9305,13 @@ __decorateClass$t([
9214
9305
  modernIdoc.property()
9215
9306
  ], exports.ZoomBlurEffect.prototype, "center", 2);
9216
9307
  __decorateClass$t([
9217
- modernIdoc.property()
9308
+ modernIdoc.property({ fallback: 20 })
9218
9309
  ], exports.ZoomBlurEffect.prototype, "innerRadius", 2);
9219
9310
  __decorateClass$t([
9220
- modernIdoc.property()
9311
+ modernIdoc.property({ fallback: -1 })
9221
9312
  ], exports.ZoomBlurEffect.prototype, "radius", 2);
9222
9313
  __decorateClass$t([
9223
- modernIdoc.property()
9314
+ modernIdoc.property({ fallback: 0.1 })
9224
9315
  ], exports.ZoomBlurEffect.prototype, "strength", 2);
9225
9316
  exports.ZoomBlurEffect = __decorateClass$t([
9226
9317
  customNode("ZoomBlurEffect")
@@ -9706,7 +9797,10 @@ class BaseElement2DText extends CoreObject {
9706
9797
  break;
9707
9798
  }
9708
9799
  }
9709
- _updateText() {
9800
+ setContent(content) {
9801
+ this.content = modernIdoc.normalizeTextContent(content);
9802
+ }
9803
+ measure() {
9710
9804
  this.base.style = {
9711
9805
  justifyContent: "center",
9712
9806
  alignItems: "center",
@@ -9714,12 +9808,6 @@ class BaseElement2DText extends CoreObject {
9714
9808
  ...this.parent.style.toJSON()
9715
9809
  };
9716
9810
  this.base.requestUpdate();
9717
- }
9718
- setContent(content) {
9719
- this.content = modernIdoc.normalizeTextContent(content);
9720
- }
9721
- measure() {
9722
- this._updateText();
9723
9811
  return this.base.measure();
9724
9812
  }
9725
9813
  updateMeasure() {
@@ -9962,36 +10050,63 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
9962
10050
  this._updateOverflow();
9963
10051
  }
9964
10052
  getRect() {
9965
- const { width: w, height: h } = this.size;
10053
+ return this.getGlobalAabb();
10054
+ }
10055
+ _getPointArray() {
10056
+ const { width, height } = this.size;
9966
10057
  const x1 = 0;
9967
10058
  const y1 = 0;
9968
- const x2 = x1 + w;
9969
- const y2 = y1 + h;
9970
- const [a, c, tx, b, d, ty] = this.globalTransform.toArray();
9971
- const points = [
9972
- [x1, y1],
9973
- [x1, y2],
9974
- [x2, y1],
9975
- [x2, y2]
9976
- ].map((p) => {
9977
- return [
9978
- a * p[0] + c * p[1] + tx,
9979
- b * p[0] + d * p[1] + ty
9980
- ];
9981
- });
9982
- const xx = points.map((p) => p[0]);
9983
- const yy = points.map((p) => p[1]);
9984
- const minX = Math.min(...xx);
9985
- const maxX = Math.max(...xx);
9986
- const minY = Math.min(...yy);
9987
- const maxY = Math.max(...yy);
10059
+ const x2 = x1 + width;
10060
+ const y2 = y1 + height;
10061
+ return [
10062
+ { x: x1, y: y1 },
10063
+ { x: x1, y: y2 },
10064
+ { x: x2, y: y1 },
10065
+ { x: x2, y: y2 }
10066
+ ];
10067
+ }
10068
+ getAabb() {
9988
10069
  return new Rect2(
9989
- minX,
9990
- minY,
9991
- maxX - minX,
9992
- maxY - minY
10070
+ this._getPointArray().map((p) => {
10071
+ return this.transform.apply(p);
10072
+ })
10073
+ );
10074
+ }
10075
+ getGlobalAabb() {
10076
+ return new Rect2(
10077
+ this._getPointArray().map((p) => {
10078
+ return this.globalTransform.apply(p);
10079
+ })
9993
10080
  );
9994
10081
  }
10082
+ getObb() {
10083
+ const origin = this.getTransformOrigin();
10084
+ const _origin = this.transform.apply(origin).sub(origin);
10085
+ return {
10086
+ rect: new Rect2(
10087
+ this._getPointArray().map((p) => {
10088
+ p.x += _origin.x;
10089
+ p.y += _origin.y;
10090
+ return p;
10091
+ })
10092
+ ),
10093
+ rotation: this.rotation
10094
+ };
10095
+ }
10096
+ getGlobalObb() {
10097
+ const origin = this.getTransformOrigin();
10098
+ const _origin = this.globalTransform.apply(origin).sub(origin);
10099
+ return {
10100
+ rect: new Rect2(
10101
+ this._getPointArray().map((p) => {
10102
+ p.x += _origin.x;
10103
+ p.y += _origin.y;
10104
+ return p;
10105
+ })
10106
+ ),
10107
+ rotation: this.globalRotation
10108
+ };
10109
+ }
9995
10110
  // protected _rectsOverlap(r1: any, r2: any): boolean {
9996
10111
  // return (
9997
10112
  // r1.x < r2.x + r2.width
@@ -10004,12 +10119,12 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10004
10119
  // override isVisibleInTree(): boolean {
10005
10120
  // if (this._tree) {
10006
10121
  // const root = this._tree.root
10007
- // const camera = root.canvasTransform.inverse()
10122
+ // const camera = root.worldTransform.inverse()
10008
10123
  // const { x, y, width, height } = root
10009
- // const p1 = camera.applyToPoint(x, y)
10010
- // const p2 = camera.applyToPoint(x + width, y)
10011
- // const p3 = camera.applyToPoint(x + width, y + height)
10012
- // const p4 = camera.applyToPoint(x, y + height)
10124
+ // const p1 = camera.apply(x, y)
10125
+ // const p2 = camera.apply(x + width, y)
10126
+ // const p3 = camera.apply(x + width, y + height)
10127
+ // const p4 = camera.apply(x, y + height)
10013
10128
  // const pts = [p1, p2, p3, p4]
10014
10129
  // const xs = pts.map(p => p[0])
10015
10130
  // const ys = pts.map(p => p[1])
@@ -10099,9 +10214,9 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10099
10214
  }
10100
10215
  }
10101
10216
  // eslint-disable-next-line unused-imports/no-unused-vars
10102
- _pointerInput(point, key) {
10217
+ _positionInput(localPos, key) {
10103
10218
  const { width, height } = this.size;
10104
- return point.x >= 0 && point.x < width && point.y >= 0 && point.y < height;
10219
+ return localPos.x >= 0 && localPos.x < width && localPos.y >= 0 && localPos.y < height;
10105
10220
  }
10106
10221
  _input(event, key) {
10107
10222
  switch (key) {
@@ -10109,14 +10224,15 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10109
10224
  case "pointermove":
10110
10225
  case "pointerup": {
10111
10226
  if (this.canPointerEvents()) {
10112
- let { screenX, screenY } = event;
10227
+ const { screenX, screenY } = event;
10113
10228
  if (screenX && screenY) {
10229
+ const pos = new Vector2(screenX, screenY);
10114
10230
  const viewport = this.getViewport();
10115
10231
  if (viewport) {
10116
- [screenX, screenY] = viewport.canvasTransform.inverse().applyToPoint(screenX, screenY);
10232
+ viewport.toGlobal(pos, pos);
10117
10233
  }
10118
- [screenX, screenY] = this.globalTransform.inverse().applyToPoint(screenX, screenY);
10119
- if (this._pointerInput({ x: screenX, y: screenY }, key)) {
10234
+ this.toLocal(pos, pos);
10235
+ if (this._positionInput(pos, key)) {
10120
10236
  if (!event.target) {
10121
10237
  event.target = this;
10122
10238
  }