modern-canvas 0.15.7 → 0.15.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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineProperty as Qr, Observable as Ct, Reactivable as ts, parseColor as ii, property as h, isGradient as ai, isColorFillObject as Fr, clearUndef as es, idGenerator as vr, isNone as I, normalizeFill as rs, normalizeBackground as oi, normalizeForeground as ni, normalizeOutline as li, normalizeShadow as hi, normalizeShape as ci, getDefaultStyle as ui, normalizeText as di, normalizeTextContent as fi, getDefaultTextStyle as pi, getDefaultLayoutStyle as _i, RawWeakMap as mi } from "modern-idoc";
1
+ import { defineProperty as Qr, Observable as Ct, Reactivable as ts, parseColor as ii, property as h, isGradient as ai, isColorFillObject as Fr, clearUndef as es, idGenerator as vr, isNone as M, normalizeFill as rs, normalizeBackground as oi, normalizeForeground as ni, normalizeOutline as li, normalizeShadow as hi, normalizeShape as ci, getDefaultStyle as ui, normalizeText as di, normalizeTextContent as fi, getDefaultTextStyle as pi, getDefaultLayoutStyle as _i, RawWeakMap as mi } from "modern-idoc";
2
2
  import { fonts as gi } from "modern-font";
3
3
  import { extend as vi } from "colord";
4
4
  import bi from "colord/plugins/names";
@@ -179,7 +179,7 @@ function is(r, t, e = {}) {
179
179
  }
180
180
  return l;
181
181
  }
182
- const Ci = "WebGL2RenderingContext" in globalThis, Oi = "ImageBitmap" in globalThis, Di = "ResizeObserver" in globalThis, Kt = "PointerEvent" in globalThis, Ii = "WheelEvent" in globalThis, sh = "MouseEvent" in globalThis, pt = "ontouchstart" in globalThis, Mi = "onclick" in globalThis, ih = "createImageBitmap" in globalThis, as = "AudioContext" in globalThis, os = "webkitAudioContext" in globalThis, ns = "OfflineAudioContext" in globalThis, ki = "webkitOfflineAudioContext" in globalThis, Ni = as || os, xr = typeof window < "u", Ui = typeof navigator < "u" && navigator?.userAgent?.indexOf("Mac") >= 0, ls = globalThis.devicePixelRatio || 1, hs = (r) => r !== null && typeof r == "object" && r.nodeType === 1, Bi = (r) => hs(r) && r.tagName === "VIDEO", ah = (r) => hs(r) && r.tagName === "IMG";
182
+ const Ci = "WebGL2RenderingContext" in globalThis, Oi = "ImageBitmap" in globalThis, Di = "ResizeObserver" in globalThis, Kt = "PointerEvent" in globalThis, Mi = "WheelEvent" in globalThis, sh = "MouseEvent" in globalThis, pt = "ontouchstart" in globalThis, Ii = "onclick" in globalThis, ih = "createImageBitmap" in globalThis, as = "AudioContext" in globalThis, os = "webkitAudioContext" in globalThis, ns = "OfflineAudioContext" in globalThis, ki = "webkitOfflineAudioContext" in globalThis, Ni = as || os, xr = typeof window < "u", Ui = typeof navigator < "u" && navigator?.userAgent?.indexOf("Mac") >= 0, ls = globalThis.devicePixelRatio || 1, hs = (r) => r !== null && typeof r == "object" && r.nodeType === 1, Bi = (r) => hs(r) && r.tagName === "VIDEO", ah = (r) => hs(r) && r.tagName === "IMG";
183
183
  function Li(r) {
184
184
  return typeof r == "object" && r !== null && r.nodeType === 1 && r.tagName === "CANVAS";
185
185
  }
@@ -375,7 +375,7 @@ class ji extends Ct {
375
375
  const a = t.changedTouches[s];
376
376
  typeof a.button > "u" && (a.button = 0), typeof a.buttons > "u" && (a.buttons = 1), typeof a.isPrimary > "u" && (a.isPrimary = t.touches.length === 1 && t.type === "touchstart"), typeof a.width > "u" && (a.width = a.radiusX || 1), typeof a.height > "u" && (a.height = a.radiusY || 1), typeof a.tiltX > "u" && (a.tiltX = 0), typeof a.tiltY > "u" && (a.tiltY = 0), typeof a.pointerType > "u" && (a.pointerType = "touch"), typeof a.pointerId > "u" && (a.pointerId = a.identifier || 0), typeof a.pressure > "u" && (a.pressure = a.force || 0.5), typeof a.twist > "u" && (a.twist = 0), typeof a.tangentialPressure > "u" && (a.tangentialPressure = 0), typeof a.layerX > "u" && (a.layerX = a.offsetX = a.clientX), typeof a.layerY > "u" && (a.layerY = a.offsetY = a.clientY), a.type = t.type, e.push(a);
377
377
  }
378
- else if (Ii && t instanceof globalThis.WheelEvent)
378
+ else if (Mi && t instanceof globalThis.WheelEvent)
379
379
  e.push(t);
380
380
  else if (Kt && t instanceof globalThis.PointerEvent)
381
381
  e.push(t);
@@ -2959,13 +2959,13 @@ const Oa = {
2959
2959
  r.source
2960
2960
  ), t.width = o, t.height = l;
2961
2961
  }
2962
- }, Ia = {
2962
+ }, Ma = {
2963
2963
  buffer: Oa,
2964
2964
  image: Da
2965
2965
  };
2966
- class Ma extends q {
2966
+ class Ia extends q {
2967
2967
  uploaders = {
2968
- ...Ia
2968
+ ...Ma
2969
2969
  };
2970
2970
  textures = /* @__PURE__ */ new Map();
2971
2971
  glTextures = /* @__PURE__ */ new Map();
@@ -3355,7 +3355,7 @@ class Fa extends q {
3355
3355
  class za extends Pr {
3356
3356
  contextLost = !1;
3357
3357
  _systems = [
3358
- new Ma(),
3358
+ new Ia(),
3359
3359
  new ea(),
3360
3360
  new pa(),
3361
3361
  new Ua(),
@@ -3529,7 +3529,7 @@ var $a = Object.defineProperty, Ge = (r, t, e, s) => {
3529
3529
  (o = r[a]) && (i = o(t, e, i) || i);
3530
3530
  return i && $a(t, e, i), i;
3531
3531
  };
3532
- class It extends lt {
3532
+ class Mt extends lt {
3533
3533
  constructor(t = {}) {
3534
3534
  super(), this.setProperties(t);
3535
3535
  }
@@ -3539,16 +3539,16 @@ class It extends lt {
3539
3539
  }
3540
3540
  Ge([
3541
3541
  h({ fallback: "triangle-list" })
3542
- ], It.prototype, "topology");
3542
+ ], Mt.prototype, "topology");
3543
3543
  Ge([
3544
3544
  h({ default: () => ({}) })
3545
- ], It.prototype, "attributes");
3545
+ ], Mt.prototype, "attributes");
3546
3546
  Ge([
3547
3547
  h({ default: () => new Xt() })
3548
- ], It.prototype, "indexBuffer");
3548
+ ], Mt.prototype, "indexBuffer");
3549
3549
  Ge([
3550
3550
  h({ fallback: 1 })
3551
- ], It.prototype, "instanceCount");
3551
+ ], Mt.prototype, "instanceCount");
3552
3552
  var Ha = Object.defineProperty, gs = (r, t, e, s) => {
3553
3553
  for (var i = void 0, a = r.length - 1, o; a >= 0; a--)
3554
3554
  (o = r[a]) && (i = o(t, e, i) || i);
@@ -3565,7 +3565,7 @@ gs([
3565
3565
  gs([
3566
3566
  h({ default: () => new Float32Array() })
3567
3567
  ], gt.prototype, "data");
3568
- var Xa = Object.defineProperty, Mt = (r, t, e, s) => {
3568
+ var Xa = Object.defineProperty, It = (r, t, e, s) => {
3569
3569
  for (var i = void 0, a = r.length - 1, o; a >= 0; a--)
3570
3570
  (o = r[a]) && (i = o(t, e, i) || i);
3571
3571
  return i && Xa(t, e, i), i;
@@ -3575,28 +3575,28 @@ class H extends lt {
3575
3575
  super(), this.setProperties(t);
3576
3576
  }
3577
3577
  }
3578
- Mt([
3578
+ It([
3579
3579
  h({ default: () => new gt() })
3580
3580
  ], H.prototype, "buffer");
3581
- Mt([
3581
+ It([
3582
3582
  h({ fallback: "float32" })
3583
3583
  ], H.prototype, "format");
3584
- Mt([
3584
+ It([
3585
3585
  h()
3586
3586
  ], H.prototype, "instance");
3587
- Mt([
3587
+ It([
3588
3588
  h()
3589
3589
  ], H.prototype, "stride");
3590
- Mt([
3590
+ It([
3591
3591
  h()
3592
3592
  ], H.prototype, "offset");
3593
- Mt([
3593
+ It([
3594
3594
  h()
3595
3595
  ], H.prototype, "start");
3596
- Mt([
3596
+ It([
3597
3597
  h()
3598
3598
  ], H.prototype, "divisor");
3599
- class nh extends It {
3599
+ class nh extends Mt {
3600
3600
  constructor() {
3601
3601
  super({
3602
3602
  topology: "triangle-strip",
@@ -3725,7 +3725,7 @@ void main(void) { gl_FragColor = transition(vUv); }` : ""}`
3725
3725
  });
3726
3726
  }
3727
3727
  }
3728
- class Ie extends E {
3728
+ class Me extends E {
3729
3729
  static _instance;
3730
3730
  static get instance() {
3731
3731
  return this._instance ??= new this();
@@ -3758,12 +3758,12 @@ void main(void) {
3758
3758
  });
3759
3759
  }
3760
3760
  }
3761
- class P extends It {
3761
+ class P extends Mt {
3762
3762
  static _instance;
3763
3763
  static get instance() {
3764
3764
  return this._instance ??= new this();
3765
3765
  }
3766
- static draw(t, e = Ie.instance, s) {
3766
+ static draw(t, e = Me.instance, s) {
3767
3767
  this.instance.draw(t, e, s);
3768
3768
  }
3769
3769
  constructor() {
@@ -3788,7 +3788,7 @@ class P extends It {
3788
3788
  });
3789
3789
  }
3790
3790
  }
3791
- class lh extends It {
3791
+ class lh extends Mt {
3792
3792
  positionBuffer;
3793
3793
  uvBuffer;
3794
3794
  constructor(t) {
@@ -4402,11 +4402,11 @@ function co(r) {
4402
4402
  let t = Kr[r] ?? 0;
4403
4403
  return t++, Kr[r] = t, t;
4404
4404
  }
4405
- let M = class extends xt {
4405
+ let I = class extends xt {
4406
4406
  static parse(r, t = "Node") {
4407
4407
  if (Array.isArray(r))
4408
4408
  return r.map((n) => this.parse(n));
4409
- const { is: e, meta: s = {}, children: i, ...a } = r, o = br.get(e ?? s.inCanvasIs ?? t) ?? M, l = new o({ ...a, meta: s });
4409
+ const { is: e, meta: s = {}, children: i, ...a } = r, o = br.get(e ?? s.inCanvasIs ?? t) ?? I, l = new o({ ...a, meta: s });
4410
4410
  return i?.forEach((n) => l.appendChild(this.parse(n))), l;
4411
4411
  }
4412
4412
  _mask;
@@ -4671,7 +4671,7 @@ let M = class extends xt {
4671
4671
  append(...r) {
4672
4672
  let t;
4673
4673
  Array.isArray(r[0]) ? t = r[0] : t = r, t.forEach((e) => {
4674
- e instanceof M ? this.appendChild(e) : this.appendChild(M.parse(e));
4674
+ e instanceof I ? this.appendChild(e) : this.appendChild(I.parse(e));
4675
4675
  });
4676
4676
  }
4677
4677
  before(...r) {
@@ -4801,37 +4801,37 @@ let M = class extends xt {
4801
4801
  };
4802
4802
  ht([
4803
4803
  h({ default: () => vr() })
4804
- ], M.prototype, "id", 2);
4804
+ ], I.prototype, "id", 2);
4805
4805
  ht([
4806
4806
  h({ default: () => vr() })
4807
- ], M.prototype, "name", 2);
4807
+ ], I.prototype, "name", 2);
4808
4808
  ht([
4809
4809
  h({ fallback: "inherit" })
4810
- ], M.prototype, "processMode", 2);
4810
+ ], I.prototype, "processMode", 2);
4811
4811
  ht([
4812
4812
  h({ fallback: "default" })
4813
- ], M.prototype, "processSortMode", 2);
4813
+ ], I.prototype, "processSortMode", 2);
4814
4814
  ht([
4815
4815
  h({ fallback: "inherit" })
4816
- ], M.prototype, "renderMode", 2);
4816
+ ], I.prototype, "renderMode", 2);
4817
4817
  ht([
4818
4818
  h({ fallback: "inherit" })
4819
- ], M.prototype, "inputMode", 2);
4819
+ ], I.prototype, "inputMode", 2);
4820
4820
  ht([
4821
4821
  h({ fallback: "default" })
4822
- ], M.prototype, "internalMode", 2);
4822
+ ], I.prototype, "internalMode", 2);
4823
4823
  ht([
4824
4824
  h({ internal: !0, default: !0 })
4825
- ], M.prototype, "needsRender", 2);
4826
- M = ht([
4825
+ ], I.prototype, "needsRender", 2);
4826
+ I = ht([
4827
4827
  b("Node")
4828
- ], M);
4828
+ ], I);
4829
4829
  var uo = Object.defineProperty, fo = Object.getOwnPropertyDescriptor, de = (r, t, e, s) => {
4830
4830
  for (var i = s > 1 ? void 0 : s ? fo(t, e) : t, a = r.length - 1, o; a >= 0; a--)
4831
4831
  (o = r[a]) && (i = (s ? o(t, e, i) : o(i)) || i);
4832
4832
  return s && i && uo(t, e, i), i;
4833
4833
  };
4834
- let et = class extends M {
4834
+ let et = class extends I {
4835
4835
  insideTimeRange = !1;
4836
4836
  /** Timeline */
4837
4837
  get _timeline() {
@@ -5094,7 +5094,7 @@ var mo = Object.defineProperty, go = Object.getOwnPropertyDescriptor, kt = (r, t
5094
5094
  (o = r[a]) && (i = (s ? o(t, e, i) : o(i)) || i);
5095
5095
  return s && i && mo(t, e, i), i;
5096
5096
  };
5097
- let X = class extends M {
5097
+ let X = class extends I {
5098
5098
  canvasTransform = new $();
5099
5099
  renderTargetIndex = 0;
5100
5100
  renderTargets = [
@@ -5147,7 +5147,7 @@ let X = class extends M {
5147
5147
  return !1;
5148
5148
  }
5149
5149
  activateWithCopy(r, t) {
5150
- this.resize(t.width, t.height), this.activate(r) && (r.clear(), t.texture.activate(r, 0), P.draw(r, Ie.instance, {
5150
+ this.resize(t.width, t.height), this.activate(r) && (r.clear(), t.texture.activate(r, 0), P.draw(r, Me.instance, {
5151
5151
  sampler: 0
5152
5152
  }));
5153
5153
  }
@@ -5433,7 +5433,7 @@ var xo = Object.defineProperty, wo = Object.getOwnPropertyDescriptor, pe = (r, t
5433
5433
  (o = r[a]) && (i = (s ? o(t, e, i) : o(i)) || i);
5434
5434
  return s && i && xo(t, e, i), i;
5435
5435
  };
5436
- let vt = class extends M {
5436
+ let vt = class extends I {
5437
5437
  currentTime = 0;
5438
5438
  static from(r, t = !1) {
5439
5439
  const [e, s] = r ? Array.isArray(r) ? r : [0, r] : [];
@@ -5670,7 +5670,7 @@ var Oo = Object.defineProperty, Do = Object.getOwnPropertyDescriptor, Rr = (r, t
5670
5670
  (o = r[a]) && (i = (s ? o(t, e, i) : o(i)) || i);
5671
5671
  return s && i && Oo(t, e, i), i;
5672
5672
  };
5673
- let Me = class extends ae {
5673
+ let Ie = class extends ae {
5674
5674
  canvasTransform = new $();
5675
5675
  _screenOffset = { x: 0, y: 0 };
5676
5676
  _zoom = new R(1, 1, () => this._updateTransform());
@@ -5722,6 +5722,34 @@ let Me = class extends ae {
5722
5722
  mt(t, this._minZoom.y, this._maxZoom.y)
5723
5723
  ), this;
5724
5724
  }
5725
+ setZoomAtOrigin(r, t, e) {
5726
+ let s;
5727
+ if (e === "screenCenter") {
5728
+ const o = this._tree?.root;
5729
+ o ? s = { x: o.width / 2, y: o.height / 2 } : s = { x: 0, y: 0 };
5730
+ } else
5731
+ s = e;
5732
+ const i = this.toGlobal(s);
5733
+ this.setZoom(r, t);
5734
+ const a = this.toScreen(i);
5735
+ this.position.add({
5736
+ x: a.x - s.x,
5737
+ y: a.y - s.y
5738
+ });
5739
+ }
5740
+ _zoomStep(r) {
5741
+ return r < 0.15 ? 0.05 : r < 0.5 ? 0.1 : r < 3 ? 0.25 : 1;
5742
+ }
5743
+ zoomIn() {
5744
+ const r = this._zoomStep(this._zoom.x);
5745
+ let t = this._zoom.x + r;
5746
+ t = Math.floor(t / r) * r, this.setZoomAtOrigin(t, t, "screenCenter");
5747
+ }
5748
+ zoomOut() {
5749
+ const r = this._zoomStep(this._zoom.x);
5750
+ let t = this._zoom.x - r;
5751
+ t = Math.ceil(t / r) * r, this.setZoomAtOrigin(t, t, "screenCenter");
5752
+ }
5725
5753
  _input(r, t) {
5726
5754
  if (super._input(r, t), t === "keydown") {
5727
5755
  const e = r;
@@ -5745,22 +5773,17 @@ let Me = class extends ae {
5745
5773
  }
5746
5774
  _onWheel(r) {
5747
5775
  if (r.preventDefault(), r.ctrlKey || r.metaKey) {
5748
- const t = { x: r.screenX, y: r.screenY }, e = this.toGlobal(t), s = r.ctrlKey && Ui ? 10 : 1, i = -r.deltaY * (r.deltaMode === 1 ? 0.05 : r.deltaMode ? 1 : 2e-3) * s;
5749
- this.zoomWithWheel(i);
5750
- const a = this.toScreen(e);
5751
- this.position.add({
5752
- x: a.x - t.x,
5753
- y: a.y - t.y
5754
- });
5776
+ const t = this._getZoomByWheel(r, this._zoom.x);
5777
+ this.setZoomAtOrigin(t, t, { x: r.screenX, y: r.screenY });
5755
5778
  } else
5756
5779
  this.position.add({
5757
5780
  x: Math.round(r.deltaX),
5758
5781
  y: Math.round(r.deltaY)
5759
5782
  });
5760
5783
  }
5761
- zoomWithWheel(r) {
5762
- const e = Math.log(this._zoom.x) + r, s = Math.exp(e);
5763
- this.setZoom(Math.round(s * 1e4) / 1e4);
5784
+ _getZoomByWheel(r, t) {
5785
+ const e = r.ctrlKey && Ui ? 10 : 1, s = -r.deltaY * (r.deltaMode === 1 ? 0.05 : r.deltaMode ? 1 : 2e-3) * e, a = Math.log(t) + s, o = Math.exp(a);
5786
+ return Math.round(o * 1e4) / 1e4;
5764
5787
  }
5765
5788
  _updateTransform() {
5766
5789
  super._updateTransform(), this._updateCanvasTransform();
@@ -5791,16 +5814,16 @@ let Me = class extends ae {
5791
5814
  };
5792
5815
  Rr([
5793
5816
  h({ internal: !0, fallback: !1 })
5794
- ], Me.prototype, "spaceKey", 2);
5817
+ ], Ie.prototype, "spaceKey", 2);
5795
5818
  Rr([
5796
5819
  h({ internal: !0, fallback: !1 })
5797
- ], Me.prototype, "grabbing", 2);
5798
- Me = Rr([
5820
+ ], Ie.prototype, "grabbing", 2);
5821
+ Ie = Rr([
5799
5822
  b("Camera2D", {
5800
5823
  processMode: "disabled",
5801
5824
  renderMode: "disabled"
5802
5825
  })
5803
- ], Me);
5826
+ ], Ie);
5804
5827
  const Zr = {
5805
5828
  brightness: 1,
5806
5829
  contrast: 1,
@@ -5850,7 +5873,7 @@ function hh(r) {
5850
5873
  }
5851
5874
  return t;
5852
5875
  }
5853
- function Io(r, t, e, s = new $()) {
5876
+ function Mo(r, t, e, s = new $()) {
5854
5877
  return r = !r || r === "none" ? "" : r, Fe(r, { width: t, height: e }).reverse().forEach(({ name: i, args: a }) => {
5855
5878
  const o = a.map((l) => l.normalizedIntValue);
5856
5879
  switch (i) {
@@ -5920,7 +5943,7 @@ function Io(r, t, e, s = new $()) {
5920
5943
  }
5921
5944
  }), s;
5922
5945
  }
5923
- function Mo(r) {
5946
+ function Io(r) {
5924
5947
  const [t, e = t] = r.split(" ");
5925
5948
  return [t, e].map((s) => {
5926
5949
  switch (s = s.trim(), s) {
@@ -6738,9 +6761,9 @@ let rt = class extends T {
6738
6761
  uInputSize: [t.width, t.height, 1 / t.width, 1 / t.height]
6739
6762
  });
6740
6763
  }), this.blurEffect.strength = this.blur, this.blurEffect.apply(r, this.viewport3), t.redraw(r, () => {
6741
- this.viewport3.texture.activate(r, 1), P.draw(r, Ie.instance, {
6764
+ this.viewport3.texture.activate(r, 1), P.draw(r, Me.instance, {
6742
6765
  sampler: 1
6743
- }), this.shadowOnly || P.draw(r, Ie.instance, {
6766
+ }), this.shadowOnly || P.draw(r, Me.instance, {
6744
6767
  sampler: 0
6745
6768
  }), r.texture.unbind(1);
6746
6769
  });
@@ -6790,10 +6813,10 @@ Wt([
6790
6813
  rt = Wt([
6791
6814
  b("DropShadowEffect")
6792
6815
  ], rt);
6793
- var Is = Object.defineProperty, an = Object.getOwnPropertyDescriptor, on = (r, t, e) => t in r ? Is(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, Ms = (r, t, e, s) => {
6816
+ var Ms = Object.defineProperty, an = Object.getOwnPropertyDescriptor, on = (r, t, e) => t in r ? Ms(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, Is = (r, t, e, s) => {
6794
6817
  for (var i = s > 1 ? void 0 : s ? an(t, e) : t, a = r.length - 1, o; a >= 0; a--)
6795
6818
  (o = r[a]) && (i = (s ? o(t, e, i) : o(i)) || i);
6796
- return s && i && Is(t, e, i), i;
6819
+ return s && i && Ms(t, e, i), i;
6797
6820
  }, nn = (r, t, e) => on(r, t + "", e);
6798
6821
  let oe = class extends T {
6799
6822
  constructor(r, t = []) {
@@ -6837,10 +6860,10 @@ void main(void) {
6837
6860
  }`
6838
6861
  }
6839
6862
  }));
6840
- Ms([
6863
+ Is([
6841
6864
  h({ fallback: 5 })
6842
6865
  ], oe.prototype, "strength", 2);
6843
- oe = Ms([
6866
+ oe = Is([
6844
6867
  b("EmbossEffect")
6845
6868
  ], oe);
6846
6869
  var ks = Object.defineProperty, ln = Object.getOwnPropertyDescriptor, hn = (r, t, e) => t in r ? ks(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, st = (r, t, e, s) => {
@@ -7734,7 +7757,7 @@ class F extends xt {
7734
7757
  }
7735
7758
  setProperties(t) {
7736
7759
  return this._setProperties(
7737
- I(t) ? void 0 : rs(t)
7760
+ M(t) ? void 0 : rs(t)
7738
7761
  );
7739
7762
  }
7740
7763
  _updateProperty(t, e, s) {
@@ -7763,7 +7786,7 @@ class F extends xt {
7763
7786
  Math.floor(this._parent.size.width),
7764
7787
  Math.floor(this._parent.size.height)
7765
7788
  );
7766
- else if (I(this.image))
7789
+ else if (M(this.image))
7767
7790
  this.animatedTexture = void 0, this.texture = void 0;
7768
7791
  else if (this._parent.tree?.log(`load image ${this.image}`), this.image !== "viewport") {
7769
7792
  let t = this.image.split("?")[0].endsWith(".gif");
@@ -7857,22 +7880,22 @@ Z([
7857
7880
  Z([
7858
7881
  h()
7859
7882
  ], F.prototype, "opacity");
7860
- var In = Object.defineProperty, Mn = (r, t, e, s) => {
7883
+ var Mn = Object.defineProperty, In = (r, t, e, s) => {
7861
7884
  for (var i = void 0, a = r.length - 1, o; a >= 0; a--)
7862
7885
  (o = r[a]) && (i = o(t, e, i) || i);
7863
- return i && In(t, e, i), i;
7886
+ return i && Mn(t, e, i), i;
7864
7887
  };
7865
7888
  class $s extends F {
7866
7889
  setProperties(t) {
7867
7890
  return super._setProperties(
7868
- I(t) ? void 0 : oi(t)
7891
+ M(t) ? void 0 : oi(t)
7869
7892
  );
7870
7893
  }
7871
7894
  _updateProperty(t, e, s) {
7872
7895
  super._updateProperty(t, e, s), t === "fillWithShape" && this._parent.requestDraw();
7873
7896
  }
7874
7897
  }
7875
- Mn([
7898
+ In([
7876
7899
  h()
7877
7900
  ], $s.prototype, "fillWithShape");
7878
7901
  var kn = Object.defineProperty, Nn = (r, t, e, s) => {
@@ -7883,7 +7906,7 @@ var kn = Object.defineProperty, Nn = (r, t, e, s) => {
7883
7906
  class Hs extends F {
7884
7907
  setProperties(t) {
7885
7908
  return super._setProperties(
7886
- I(t) ? void 0 : ni(t)
7909
+ M(t) ? void 0 : ni(t)
7887
7910
  );
7888
7911
  }
7889
7912
  _updateProperty(t, e, s) {
@@ -7901,7 +7924,7 @@ var Un = Object.defineProperty, me = (r, t, e, s) => {
7901
7924
  class qt extends F {
7902
7925
  setProperties(t) {
7903
7926
  return super._setProperties(
7904
- I(t) ? void 0 : li(t)
7927
+ M(t) ? void 0 : li(t)
7905
7928
  );
7906
7929
  }
7907
7930
  _updateProperty(t, e, s) {
@@ -7951,7 +7974,7 @@ class jt extends xt {
7951
7974
  }
7952
7975
  setProperties(t) {
7953
7976
  return super.setProperties(
7954
- I(t) ? void 0 : hi(t)
7977
+ M(t) ? void 0 : hi(t)
7955
7978
  );
7956
7979
  }
7957
7980
  _updateProperty(t, e, s) {
@@ -7997,7 +8020,7 @@ class Yt extends xt {
7997
8020
  _path2DSet = new yi();
7998
8021
  setProperties(t) {
7999
8022
  return super.setProperties(
8000
- I(t) ? void 0 : ci(t)
8023
+ M(t) ? void 0 : ci(t)
8001
8024
  );
8002
8025
  }
8003
8026
  _updateProperty(t, e, s) {
@@ -8100,7 +8123,7 @@ class it extends xt {
8100
8123
  _textureMap = /* @__PURE__ */ new Map();
8101
8124
  setProperties(t) {
8102
8125
  return super.setProperties(
8103
- I(t) ? void 0 : di(t)
8126
+ M(t) ? void 0 : di(t)
8104
8127
  );
8105
8128
  }
8106
8129
  _updateProperty(t, e, s) {
@@ -8169,7 +8192,7 @@ class it extends xt {
8169
8192
  t.linearGradient ?? t.radialGradient,
8170
8193
  e.width,
8171
8194
  e.height
8172
- ) : I(t.image) ? void 0 : (this._parent.tree?.log(`load image ${t.image}`), await G.texture.load(t.image));
8195
+ ) : M(t.image) ? void 0 : (this._parent.tree?.log(`load image ${t.image}`), await G.texture.load(t.image));
8173
8196
  }
8174
8197
  setContent(t) {
8175
8198
  this.content = fi(t);
@@ -8196,7 +8219,7 @@ class it extends xt {
8196
8219
  const a = i.getMeta();
8197
8220
  if (a instanceof Ei) {
8198
8221
  const o = a.parent.index, l = a.parent.parent.index;
8199
- if (i.style.fill && !I(i.style.fill))
8222
+ if (i.style.fill && !M(i.style.fill))
8200
8223
  if (typeof i.style.fill == "object") {
8201
8224
  const n = i.style.fill, c = this._textureMap.get(`${l}.${o}.fill`) ?? this._textureMap.get(`${l}.fill`) ?? this._textureMap.get("fill");
8202
8225
  n.enabled !== !1 && (c || n.color) && (t.addPath(i), t.style = { ...i.style }, t.fillStyle = c?.texture ?? n.color, t.fill({
@@ -8215,7 +8238,7 @@ class it extends xt {
8215
8238
  t.addPath(i), t.style = { ...i.style }, t.fill({
8216
8239
  transformVertex: e
8217
8240
  });
8218
- if (i.style.stroke && !I(i.style.stroke))
8241
+ if (i.style.stroke && !M(i.style.stroke))
8219
8242
  if (typeof i.style.stroke == "object") {
8220
8243
  const n = i.style.stroke, c = this._textureMap.get(`${l}.${o}.outline`) ?? this._textureMap.get(`${l}.outline`) ?? this._textureMap.get("outline");
8221
8244
  n.enabled !== !1 && (c || n.color) && (n.width === void 0 || n.width) && (t.addPath(i), t.style = { ...i.style }, t.lineWidth = n.width || 1, t.strokeStyle = c?.texture ?? n.color, t.lineCap = n.lineCap, t.lineJoin = n.lineJoin, t.stroke({
@@ -8235,9 +8258,9 @@ class it extends xt {
8235
8258
  transformVertex: e
8236
8259
  });
8237
8260
  } else
8238
- t.addPath(i), t.style = { ...i.style }, i.style.fill && !I(i.style.fill) && t.fill({
8261
+ t.addPath(i), t.style = { ...i.style }, i.style.fill && !M(i.style.fill) && t.fill({
8239
8262
  transformVertex: this._createTransformVertex()
8240
- }), i.style.stroke && !I(i.style.stroke) && t.stroke({
8263
+ }), i.style.stroke && !M(i.style.stroke) && t.stroke({
8241
8264
  transformVertex: this._createTransformVertex()
8242
8265
  });
8243
8266
  });
@@ -8397,7 +8420,7 @@ const A = {
8397
8420
  "content-box": 1
8398
8421
  // BoxSizing.ContentBox
8399
8422
  };
8400
- class Ir {
8423
+ class Mr {
8401
8424
  constructor(t) {
8402
8425
  this._parent = t, this._addChild = this._addChild.bind(this), this._removeChild = this._removeChild.bind(this), this._parent.on("addChild", this._addChild), this._parent.on("removeChild", this._removeChild);
8403
8426
  }
@@ -8406,7 +8429,7 @@ class Ir {
8406
8429
  const { loadYoga: t } = await import("yoga-layout/load");
8407
8430
  this._yoga = await t();
8408
8431
  }
8409
- node = Ir._yoga?.Node.create();
8432
+ node = Mr._yoga?.Node.create();
8410
8433
  _addChild(t, e) {
8411
8434
  if (t instanceof yt && t.flexbox.node && this.node) {
8412
8435
  this.node.insertChild(t.flexbox.node, e);
@@ -8594,7 +8617,7 @@ var Gn = Object.getOwnPropertyDescriptor, Vn = (r, t, e, s) => {
8594
8617
  };
8595
8618
  const $n = new Set(Object.keys(_i())), Hn = new Set(Object.keys(pi()));
8596
8619
  let yt = class extends ae {
8597
- flexbox = new Ir(this);
8620
+ flexbox = new Mr(this);
8598
8621
  aabb = new j();
8599
8622
  globalAabb = new j();
8600
8623
  _parentGlobalDisplay;
@@ -8742,7 +8765,7 @@ let yt = class extends ae {
8742
8765
  this.skew.y = t;
8743
8766
  break;
8744
8767
  case "transform":
8745
- this.extraTransform.identity(), this.extraTransform.translate(-this.pivot.x, -this.pivot.y), Io(
8768
+ this.extraTransform.identity(), this.extraTransform.translate(-this.pivot.x, -this.pivot.y), Mo(
8746
8769
  t ?? "",
8747
8770
  this.size.width,
8748
8771
  this.size.height,
@@ -8750,7 +8773,7 @@ let yt = class extends ae {
8750
8773
  ), this.extraTransform.translate(this.pivot.x, this.pivot.y), this.updateGlobalTransform();
8751
8774
  break;
8752
8775
  case "transformOrigin": {
8753
- const s = Mo(t ?? "");
8776
+ const s = Io(t ?? "");
8754
8777
  this.pivot.set(
8755
8778
  s[0] * this.size.width,
8756
8779
  s[1] * this.size.height
@@ -8791,7 +8814,7 @@ let yt = class extends ae {
8791
8814
  this._overflowHidden = t === "hidden", this._updateMask();
8792
8815
  break;
8793
8816
  case "pointerEvents":
8794
- this._allowPointerEvents = !I(t);
8817
+ this._allowPointerEvents = !M(t);
8795
8818
  break;
8796
8819
  case "borderRadius":
8797
8820
  this.requestDraw();
@@ -8824,13 +8847,13 @@ let yt = class extends ae {
8824
8847
  this._parentGlobalDisplay !== t?.globalDisplay && this._updateGlobalDisplay(), this.flexbox.update(), super._process(r);
8825
8848
  }
8826
8849
  _updateStyleFilter(r) {
8827
- I(r) ? (this._colorFilterEffect?.remove(), this._colorFilterEffect = void 0, this.requestRender()) : (this._colorFilterEffect || (this._colorFilterEffect = new zt({
8850
+ M(r) ? (this._colorFilterEffect?.remove(), this._colorFilterEffect = void 0, this.requestRender()) : (this._colorFilterEffect || (this._colorFilterEffect = new zt({
8828
8851
  name: "styleFilter",
8829
8852
  internalMode: "front"
8830
8853
  }), this.append(this._colorFilterEffect)), this._colorFilterEffect.filter = r);
8831
8854
  }
8832
8855
  _updateStyleMaskImage(r) {
8833
- I(r) ? (this._maskEffect?.remove(), this._maskEffect = void 0, this.requestRender()) : (this._maskEffect || (this._maskEffect = new Ht({
8856
+ M(r) ? (this._maskEffect?.remove(), this._maskEffect = void 0, this.requestRender()) : (this._maskEffect || (this._maskEffect = new Ht({
8834
8857
  name: "styleMaskImage",
8835
8858
  internalMode: "back"
8836
8859
  }), this.append(this._maskEffect)), this._maskEffect.image = r);
@@ -9311,10 +9334,10 @@ he = Xe([
9311
9334
  duration: 2e3
9312
9335
  })
9313
9336
  ], he);
9314
- class Mr extends Ct {
9337
+ class Ir extends Ct {
9315
9338
  static _instance;
9316
9339
  static get instance() {
9317
- return this._instance || (this._instance = new Mr()), this._instance;
9340
+ return this._instance || (this._instance = new Ir()), this._instance;
9318
9341
  }
9319
9342
  playbackRate = 1;
9320
9343
  muted = !1;
@@ -9498,7 +9521,7 @@ class al {
9498
9521
  return !!this.source && this.source.readyState === 4;
9499
9522
  }
9500
9523
  get context() {
9501
- return Mr.instance;
9524
+ return Ir.instance;
9502
9525
  }
9503
9526
  async load() {
9504
9527
  return new Promise((t) => {
@@ -9609,7 +9632,7 @@ class Rt extends Ys {
9609
9632
  2,
9610
9633
  ns ? Math.max(8e3, Math.min(96e3, t.sampleRate)) : 44100
9611
9634
  ), s = t.createDynamicsCompressor(), i = t.createAnalyser();
9612
- i.connect(s), s.connect(t.destination), super(i, s), this._context = t, this._offlineContext = e, this._compressor = s, this._analyser = i, this._locked = t.state === "suspended" && (pt || Mi), xr && (this._locked && (this._unlock(), document.addEventListener("mousedown", this._unlock, !0), document.addEventListener("touchstart", this._unlock, !0), document.addEventListener("touchend", this._unlock, !0)), globalThis.addEventListener("focus", this._onFocus), globalThis.addEventListener("blur", this._onBlur));
9635
+ i.connect(s), s.connect(t.destination), super(i, s), this._context = t, this._offlineContext = e, this._compressor = s, this._analyser = i, this._locked = t.state === "suspended" && (pt || Ii), xr && (this._locked && (this._unlock(), document.addEventListener("mousedown", this._unlock, !0), document.addEventListener("touchstart", this._unlock, !0), document.addEventListener("touchend", this._unlock, !0)), globalThis.addEventListener("focus", this._onFocus), globalThis.addEventListener("blur", this._onBlur));
9613
9636
  }
9614
9637
  _onFocus() {
9615
9638
  if (!this.autoPause)
@@ -10289,8 +10312,8 @@ void main(void) {
10289
10312
  ue = Ol([
10290
10313
  b("TiltShiftTransition")
10291
10314
  ], ue);
10292
- var Il = Object.defineProperty, Ml = Object.getOwnPropertyDescriptor, kl = (r, t, e) => t in r ? Il(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, Nl = (r, t, e, s) => {
10293
- for (var i = s > 1 ? void 0 : s ? Ml(t, e) : t, a = r.length - 1, o; a >= 0; a--)
10315
+ var Ml = Object.defineProperty, Il = Object.getOwnPropertyDescriptor, kl = (r, t, e) => t in r ? Ml(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e, Nl = (r, t, e, s) => {
10316
+ for (var i = s > 1 ? void 0 : s ? Il(t, e) : t, a = r.length - 1, o; a >= 0; a--)
10294
10317
  (o = r[a]) && (i = o(i) || i);
10295
10318
  return i;
10296
10319
  }, Ul = (r, t, e) => kl(r, t + "", e);
@@ -10813,7 +10836,7 @@ export {
10813
10836
  uh as AudioSpectrum,
10814
10837
  ce as AudioWaveform,
10815
10838
  _t as BufferUsage,
10816
- Me as Camera2D,
10839
+ Ie as Camera2D,
10817
10840
  ao as CanvasContext,
10818
10841
  Lt as CanvasItem,
10819
10842
  vs as CanvasTexture,
@@ -10843,10 +10866,10 @@ export {
10843
10866
  it as Element2DText,
10844
10867
  oe as EmbossEffect,
10845
10868
  kr as Engine,
10846
- Ir as Flexbox,
10869
+ Mr as Flexbox,
10847
10870
  Ga as FontLoader,
10848
10871
  nt as GaussianBlurEffect,
10849
- It as Geometry,
10872
+ Mt as Geometry,
10850
10873
  Bl as GifLoader,
10851
10874
  ga as GlBatch2DSystem,
10852
10875
  ie as GlBlendMode,
@@ -10867,7 +10890,7 @@ export {
10867
10890
  K as GodrayEffect,
10868
10891
  Ve as GradientTexture,
10869
10892
  al as HTMLAudio,
10870
- Mr as HTMLAudioContext,
10893
+ Ir as HTMLAudioContext,
10871
10894
  Ne as HTMLSound,
10872
10895
  xr as IN_BROWSER,
10873
10896
  Ui as IN_MAC_OS,
@@ -10887,7 +10910,7 @@ export {
10887
10910
  E as Material,
10888
10911
  no as Meta,
10889
10912
  cs as MouseInputEvent,
10890
- M as Node,
10913
+ I as Node,
10891
10914
  ae as Node2D,
10892
10915
  Oe as Obb2D,
10893
10916
  L as OutlineEffect,
@@ -10905,7 +10928,7 @@ export {
10905
10928
  Pr as Renderer,
10906
10929
  lt as Resource,
10907
10930
  as as SUPPORTS_AUDIO_CONTEXT,
10908
- Mi as SUPPORTS_CLICK_EVENTS,
10931
+ Ii as SUPPORTS_CLICK_EVENTS,
10909
10932
  ih as SUPPORTS_CREATE_IMAGE_BITMAP,
10910
10933
  Oi as SUPPORTS_IMAGE_BITMAP,
10911
10934
  sh as SUPPORTS_MOUSE_EVENTS,
@@ -10917,7 +10940,7 @@ export {
10917
10940
  os as SUPPORTS_WEBKIT_AUDIO_CONTEXT,
10918
10941
  ki as SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT,
10919
10942
  Ni as SUPPORTS_WEB_AUDIO,
10920
- Ii as SUPPORTS_WHEEL_EVENTS,
10943
+ Mi as SUPPORTS_WHEEL_EVENTS,
10921
10944
  Pt as SceneTree,
10922
10945
  zl as TextLoader,
10923
10946
  x as Texture2D,
@@ -10932,7 +10955,7 @@ export {
10932
10955
  Ft as Transition,
10933
10956
  Le as TwistTransition,
10934
10957
  lh as UvGeometry,
10935
- Ie as UvMaterial,
10958
+ Me as UvMaterial,
10936
10959
  R as Vector2,
10937
10960
  H as VertexAttribute,
10938
10961
  gt as VertexBuffer,
@@ -10992,8 +11015,8 @@ export {
10992
11015
  hh as parseCssFilter,
10993
11016
  Fe as parseCssFunctions,
10994
11017
  Pe as parseCssProperty,
10995
- Io as parseCssTransform,
10996
- Mo as parseCssTransformOrigin,
11018
+ Mo as parseCssTransform,
11019
+ Io as parseCssTransformOrigin,
10997
11020
  lr as positionTypeMap,
10998
11021
  dh as render,
10999
11022
  Ot as stencilModeMap,
@@ -39,9 +39,13 @@ export declare class Camera2D extends Node2D {
39
39
  setProperties(properties?: Record<string, any>): this;
40
40
  addZoom(x: number, y?: number): this;
41
41
  setZoom(x: number, y?: number): this;
42
+ setZoomAtOrigin(x: number, y: number, origin: Vector2Like | 'screenCenter'): void;
43
+ protected _zoomStep(val: number): number;
44
+ zoomIn(): void;
45
+ zoomOut(): void;
42
46
  protected _input(event: InputEvent, key: InputEventKey): void;
43
47
  protected _onWheel(e: WheelInputEvent): void;
44
- zoomWithWheel(delta: number): void;
48
+ protected _getZoomByWheel(e: WheelInputEvent, val: number): number;
45
49
  _updateTransform(): void;
46
50
  protected _updateCanvasTransform(): void;
47
51
  syncCanvasTransform(): void;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.15.7",
4
+ "version": "0.15.8",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",