modern-canvas 0.12.22 → 0.13.0

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 Ht, Observable as de, Reactivable as Ir, parseColor as Ls, property as u, RawWeakMap as Br, isGradient as Fs, isColorFillObject as mr, clearUndef as Nr, idGenerator as zr, normalizeFill as $s, isNone as L, normalizeBackground as Vs, normalizeForeground as Gs, normalizeOutline as js, normalizeShadow as Ws, normalizeShape as qs, getDefaultStyle as Xs, normalizeText as Hs, normalizeTextContent as Ys, getDefaultTextStyle as Ks, getDefaultLayoutStyle as Zs } from "modern-idoc";
1
+ import { defineProperty as Ht, Observable as de, Reactivable as Ir, parseColor as zs, property as u, RawWeakMap as Br, isGradient as Fs, isColorFillObject as mr, clearUndef as Nr, idGenerator as Lr, normalizeFill as $s, isNone as z, normalizeBackground as Vs, normalizeForeground as Gs, normalizeOutline as js, normalizeShadow as Ws, normalizeShape as qs, getDefaultStyle as Xs, normalizeText as Hs, normalizeTextContent as Ys, getDefaultTextStyle as Ks, getDefaultLayoutStyle as Zs } from "modern-idoc";
2
2
  import { fonts as Js } from "modern-font";
3
3
  import { extend as Qs } from "colord";
4
4
  import ei from "colord/plugins/names";
@@ -81,7 +81,7 @@ class k {
81
81
  }
82
82
  }
83
83
  k.start();
84
- async function Lr(r) {
84
+ async function zr(r) {
85
85
  return new Promise((e) => {
86
86
  k.on(
87
87
  () => {
@@ -545,7 +545,7 @@ class pe extends Ir {
545
545
  this.setProperties(e);
546
546
  }
547
547
  _nextTick() {
548
- return Lr();
548
+ return zr();
549
549
  }
550
550
  equal(e) {
551
551
  return !!(e && this.instanceId === e.instanceId);
@@ -563,7 +563,7 @@ class Z {
563
563
  return this._value;
564
564
  }
565
565
  set value(e) {
566
- this._colord = Ls(e ?? "none");
566
+ this._colord = zs(e ?? "none");
567
567
  }
568
568
  get r8() {
569
569
  return this._colord.rgba.r;
@@ -1352,8 +1352,8 @@ class ge {
1352
1352
  };
1353
1353
  }
1354
1354
  }
1355
- class O extends Kr {
1356
- static _t2d = /* @__PURE__ */ new O();
1355
+ class M extends Kr {
1356
+ static _t2d = /* @__PURE__ */ new M();
1357
1357
  premultiply(e) {
1358
1358
  return e.multiply(this, this);
1359
1359
  }
@@ -1364,7 +1364,7 @@ class O extends Kr {
1364
1364
  return this.skew(0, e);
1365
1365
  }
1366
1366
  skew(e, t) {
1367
- return this.premultiply(O._t2d.makeSkew(e, t));
1367
+ return this.premultiply(M._t2d.makeSkew(e, t));
1368
1368
  }
1369
1369
  makeSkew(e, t) {
1370
1370
  const s = Math.tan(e), i = Math.tan(t);
@@ -1393,7 +1393,7 @@ class O extends Kr {
1393
1393
  return this.translate(e, t, s);
1394
1394
  }
1395
1395
  translate(e, t, s = 0) {
1396
- return this.premultiply(O._t2d.makeTranslation(e, t, s));
1396
+ return this.premultiply(M._t2d.makeTranslation(e, t, s));
1397
1397
  }
1398
1398
  makeTranslation(e, t, s = 0) {
1399
1399
  return this.set([
@@ -1418,7 +1418,7 @@ class O extends Kr {
1418
1418
  return this.scale(e, t, s);
1419
1419
  }
1420
1420
  scale(e, t, s = 1) {
1421
- return this.premultiply(O._t2d.makeScale(e, t, s));
1421
+ return this.premultiply(M._t2d.makeScale(e, t, s));
1422
1422
  }
1423
1423
  makeScale(e, t, s = 1) {
1424
1424
  return this.set([
@@ -1443,7 +1443,7 @@ class O extends Kr {
1443
1443
  return this.rotate(e);
1444
1444
  }
1445
1445
  rotate(e) {
1446
- return this.premultiply(O._t2d.makeRotation(e));
1446
+ return this.premultiply(M._t2d.makeRotation(e));
1447
1447
  }
1448
1448
  rotate3d(e, t, s, i) {
1449
1449
  const [o, a, n] = this._rotate3d(e, t, s, i);
@@ -1600,7 +1600,7 @@ Jr([
1600
1600
  u({ internal: !0 })
1601
1601
  ], Jt.prototype, "view");
1602
1602
  var Ye = /* @__PURE__ */ ((r) => (r.NORMAL = "normal", r.ADD = "add", r.MULTIPLY = "multiply", r.SCREEN = "screen", r.NONE = "none", r.NORMAL_NPM = "normal_npm", r.ADD_NPM = "add_npm", r.SCREEN_NPM = "screen_npm", r.SRC_IN = "src_in", r.SRC_OUT = "src_out", r.SRC_ATOP = "src_atop", r.DST_OVER = "dst_over", r.DST_IN = "dst_in", r.DST_OUT = "dst_out", r.DST_ATOP = "dst_atop", r.XOR = "xor", r.SUBTRACT = "subtract", r))(Ye || {});
1603
- function zi(r) {
1603
+ function Li(r) {
1604
1604
  return {
1605
1605
  normal: [r.ONE, r.ONE_MINUS_SRC_ALPHA],
1606
1606
  add: [r.ONE, r.ONE],
@@ -1689,7 +1689,7 @@ class Re {
1689
1689
  }
1690
1690
  }
1691
1691
  Re._init();
1692
- class Li extends X {
1692
+ class zi extends X {
1693
1693
  install(e) {
1694
1694
  super.install(e), e.state = this;
1695
1695
  }
@@ -1700,7 +1700,7 @@ class Li extends X {
1700
1700
  blendModes;
1701
1701
  defaultState = new Re({ blend: !0 });
1702
1702
  onUpdateContext() {
1703
- super.onUpdateContext(), this.blendModes = zi(this._renderer.gl);
1703
+ super.onUpdateContext(), this.blendModes = Li(this._renderer.gl);
1704
1704
  }
1705
1705
  toggle(e, t) {
1706
1706
  this._renderer.gl[t ? "enable" : "disable"](e);
@@ -1917,18 +1917,18 @@ void main(void) {
1917
1917
  let l = 0, c = 0;
1918
1918
  const d = [];
1919
1919
  for (let _ = s.length, f = { id: ++this._drawCallUid }, m = [], g = /* @__PURE__ */ new Map(), w = 0, P = 0, R = 0; R < _; R++) {
1920
- const A = s[R].texture, z = R === _ - 1;
1920
+ const A = s[R].texture, L = R === _ - 1;
1921
1921
  if (!A || g.has(A)) {
1922
- if (!z)
1922
+ if (!L)
1923
1923
  continue;
1924
1924
  } else
1925
1925
  m.push(A), g.set(A, w++);
1926
- if (z || w >= i) {
1926
+ if (L || w >= i) {
1927
1927
  f.textures = m, f.textureLocationMap = g, w = 0, f.first = c;
1928
1928
  for (let V = P; V <= R; V++) {
1929
1929
  const {
1930
1930
  indices: ur,
1931
- vertices: zt,
1931
+ vertices: Lt,
1932
1932
  uvs: dr = new Float32Array(0),
1933
1933
  size: pr = new Float32Array(0),
1934
1934
  texture: fr,
@@ -1938,9 +1938,9 @@ void main(void) {
1938
1938
  disableWrapMode: Us = !1
1939
1939
  } = s[V], Ds = pr[0] || 0, Is = pr[1] || 0;
1940
1940
  P < V && f.blendMode !== _r && (f.count = c - f.first, d.push(f), P = V, f = { id: ++this._drawCallUid }, f.textures = m, f.first = c);
1941
- const Bs = l / this._vertexSize, Ns = (fr ? g.get(fr) : -1) ?? -1, zs = Us ? 1 : 0;
1942
- for (let Lt = zt.length, Y = 0; Y < Lt; Y += 2) {
1943
- if (a[l++] = Ns, a[l++] = zt[Y], a[l++] = zt[Y + 1], a[l++] = Ds, a[l++] = Is, a[l++] = dr[Y], a[l++] = dr[Y + 1], je) {
1941
+ const Bs = l / this._vertexSize, Ns = (fr ? g.get(fr) : -1) ?? -1, Ls = Us ? 1 : 0;
1942
+ for (let zt = Lt.length, Y = 0; Y < zt; Y += 2) {
1943
+ if (a[l++] = Ns, a[l++] = Lt[Y], a[l++] = Lt[Y + 1], a[l++] = Ds, a[l++] = Is, a[l++] = dr[Y], a[l++] = dr[Y + 1], je) {
1944
1944
  const te = l * 4;
1945
1945
  n[te] = je[0], n[te + 1] = je[1], n[te + 2] = je[2], n[te + 3] = je[3];
1946
1946
  }
@@ -1948,9 +1948,9 @@ void main(void) {
1948
1948
  const te = l * 4;
1949
1949
  n[te] = We[0], n[te + 1] = We[1], n[te + 2] = We[2], n[te + 3] = We[3];
1950
1950
  }
1951
- l++, a[l++] = zs;
1951
+ l++, a[l++] = Ls;
1952
1952
  }
1953
- for (let Lt = ur.length, Y = 0; Y < Lt; Y++)
1953
+ for (let zt = ur.length, Y = 0; Y < zt; Y++)
1954
1954
  h[c++] = Bs + ur[Y];
1955
1955
  f.blendMode = _r;
1956
1956
  }
@@ -1962,11 +1962,11 @@ void main(void) {
1962
1962
  for (let _ = d.length, f = 0; f < _; f++) {
1963
1963
  const m = d[f], { first: g = 0, textures: w, textureLocationMap: P } = m;
1964
1964
  for (let R = w.length, A = 0; A < R; A++) {
1965
- const z = w[A], V = P.get(z);
1965
+ const L = w[A], V = P.get(L);
1966
1966
  V !== void 0 && this._renderer.texture.bind({
1967
1967
  target: "texture_2d",
1968
1968
  location: V,
1969
- value: z
1969
+ value: L
1970
1970
  });
1971
1971
  }
1972
1972
  this._state.blendMode = m.blendMode, this._renderer.state.bind(this._state), p.draw({
@@ -2874,7 +2874,7 @@ class Qi extends Jt {
2874
2874
  new ji(),
2875
2875
  new Zi(),
2876
2876
  new Ji(),
2877
- new Li(),
2877
+ new zi(),
2878
2878
  new Gi(),
2879
2879
  new Xi(),
2880
2880
  new Hi(),
@@ -3629,11 +3629,11 @@ class Ot extends T {
3629
3629
  const { angle: a = 0, stops: n } = e, h = t, l = s, c = h / 2, d = l / 2, p = (a + 90) * Math.PI / 180, _ = Math.sin(p), f = -Math.cos(p), m = Math.abs(h * Math.sin(p)) + Math.abs(l * Math.cos(p)), g = c - _ * (m / 2), w = d - f * (m / 2), P = c + _ * (m / 2), R = d + f * (m / 2), A = o.createLinearGradient(g, w, P, R);
3630
3630
  for (const V of n) A.addColorStop(V.offset, V.color);
3631
3631
  o.fillStyle = A, o.fillRect(0, 0, h, l);
3632
- const z = o.getImageData(0, 0, i.width, i.height);
3632
+ const L = o.getImageData(0, 0, i.width, i.height);
3633
3633
  return {
3634
- width: z.width,
3635
- height: z.height,
3636
- pixels: new Uint8Array(z.data.buffer)
3634
+ width: L.width,
3635
+ height: L.height,
3636
+ pixels: new Uint8Array(L.data.buffer)
3637
3637
  };
3638
3638
  }
3639
3639
  constructor(e, t, s) {
@@ -4069,7 +4069,7 @@ function yo(r) {
4069
4069
  let e = Pr[r] ?? 0;
4070
4070
  return e++, Pr[r] = e, e;
4071
4071
  }
4072
- let M = class extends pe {
4072
+ let O = class extends pe {
4073
4073
  _meta = new go(this);
4074
4074
  get meta() {
4075
4075
  return this._meta;
@@ -4265,7 +4265,7 @@ let M = class extends pe {
4265
4265
  const n = e.renderStack.push(this);
4266
4266
  a = e.renderStack.currentCall, e.renderStack.currentCall = n;
4267
4267
  }
4268
- if (this.mask instanceof M)
4268
+ if (this.mask instanceof O)
4269
4269
  this.getNode("__$mask") || (this.mask.processMode = "disabled", this.appendChild(this.mask, "front"));
4270
4270
  else {
4271
4271
  const n = this.getNode("__$mask");
@@ -4429,43 +4429,43 @@ let M = class extends pe {
4429
4429
  static parse(r) {
4430
4430
  if (Array.isArray(r))
4431
4431
  return r.map((n) => this.parse(n));
4432
- const { meta: e = {}, children: t, ...s } = r, { inCanvasIs: i = "Node" } = e, o = Yt.get(i) ?? M, a = new o({ ...s, meta: e });
4432
+ const { meta: e = {}, children: t, ...s } = r, { inCanvasIs: i = "Node" } = e, o = Yt.get(i) ?? O, a = new o({ ...s, meta: e });
4433
4433
  return t?.forEach((n) => a.appendChild(this.parse(n))), a;
4434
4434
  }
4435
4435
  };
4436
4436
  ae([
4437
- u({ fallback: zr() })
4438
- ], M.prototype, "id", 2);
4437
+ u({ fallback: Lr() })
4438
+ ], O.prototype, "id", 2);
4439
4439
  ae([
4440
- u({ fallback: zr() })
4441
- ], M.prototype, "name", 2);
4440
+ u({ fallback: Lr() })
4441
+ ], O.prototype, "name", 2);
4442
4442
  ae([
4443
4443
  u({ internal: !0, fallback: "inherit" })
4444
- ], M.prototype, "processMode", 2);
4444
+ ], O.prototype, "processMode", 2);
4445
4445
  ae([
4446
4446
  u({ internal: !0, fallback: "default" })
4447
- ], M.prototype, "processSortMode", 2);
4447
+ ], O.prototype, "processSortMode", 2);
4448
4448
  ae([
4449
4449
  u({ internal: !0, fallback: "inherit" })
4450
- ], M.prototype, "renderMode", 2);
4450
+ ], O.prototype, "renderMode", 2);
4451
4451
  ae([
4452
4452
  u({ internal: !0, fallback: "inherit" })
4453
- ], M.prototype, "inputMode", 2);
4453
+ ], O.prototype, "inputMode", 2);
4454
4454
  ae([
4455
4455
  u({ internal: !0, fallback: "default" })
4456
- ], M.prototype, "internalMode", 2);
4456
+ ], O.prototype, "internalMode", 2);
4457
4457
  ae([
4458
4458
  u({ internal: !0 })
4459
- ], M.prototype, "mask", 2);
4460
- M = ae([
4459
+ ], O.prototype, "mask", 2);
4460
+ O = ae([
4461
4461
  v("Node")
4462
- ], M);
4462
+ ], O);
4463
4463
  var xo = Object.defineProperty, wo = Object.getOwnPropertyDescriptor, Be = (r, e, t, s) => {
4464
4464
  for (var i = s > 1 ? void 0 : s ? wo(e, t) : e, o = r.length - 1, a; o >= 0; o--)
4465
4465
  (a = r[o]) && (i = (s ? a(e, t, i) : a(i)) || i);
4466
4466
  return s && i && xo(e, t, i), i;
4467
4467
  };
4468
- let G = class extends M {
4468
+ let G = class extends O {
4469
4469
  constructor(r, e = []) {
4470
4470
  super(), this.setProperties(r).append(e);
4471
4471
  }
@@ -4662,12 +4662,12 @@ var Eo = Object.defineProperty, Co = Object.getOwnPropertyDescriptor, Ne = (r, e
4662
4662
  (a = r[o]) && (i = (s ? a(e, t, i) : a(i)) || i);
4663
4663
  return s && i && Eo(e, t, i), i;
4664
4664
  };
4665
- let j = class extends M {
4665
+ let j = class extends O {
4666
4666
  constructor(r = !1) {
4667
4667
  super(), this.flipY = r, this.projection.flipY(r);
4668
4668
  }
4669
4669
  projection = new Ii();
4670
- canvasTransform = new O();
4670
+ canvasTransform = new M();
4671
4671
  _framebufferIndex = 0;
4672
4672
  _framebuffers = [
4673
4673
  { texture: new wr(), needsUpload: !1 },
@@ -4982,12 +4982,12 @@ class Ro {
4982
4982
  }), this.calls = [];
4983
4983
  }
4984
4984
  }
4985
- var Mo = Object.defineProperty, Oo = Object.getOwnPropertyDescriptor, ze = (r, e, t, s) => {
4985
+ var Mo = Object.defineProperty, Oo = Object.getOwnPropertyDescriptor, Le = (r, e, t, s) => {
4986
4986
  for (var i = s > 1 ? void 0 : s ? Oo(e, t) : e, o = r.length - 1, a; o >= 0; o--)
4987
4987
  (a = r[o]) && (i = (s ? a(e, t, i) : a(i)) || i);
4988
4988
  return s && i && Mo(e, t, i), i;
4989
4989
  };
4990
- let ie = class extends M {
4990
+ let ie = class extends O {
4991
4991
  static from(r, e = !1) {
4992
4992
  const [t, s] = r ? Array.isArray(r) ? r : [0, r] : [];
4993
4993
  return new ie({
@@ -5018,22 +5018,22 @@ let ie = class extends M {
5018
5018
  super._process(r), this.paused || this.addTime(r);
5019
5019
  }
5020
5020
  };
5021
- ze([
5021
+ Le([
5022
5022
  u({ fallback: 0 })
5023
5023
  ], ie.prototype, "startTime", 2);
5024
- ze([
5024
+ Le([
5025
5025
  u({ fallback: 0 })
5026
5026
  ], ie.prototype, "currentTime", 2);
5027
- ze([
5027
+ Le([
5028
5028
  u({ fallback: Number.MAX_SAFE_INTEGER })
5029
5029
  ], ie.prototype, "endTime", 2);
5030
- ze([
5030
+ Le([
5031
5031
  u({ fallback: !1 })
5032
5032
  ], ie.prototype, "loop", 2);
5033
- ze([
5033
+ Le([
5034
5034
  u({ fallback: !1 })
5035
5035
  ], ie.prototype, "paused", 2);
5036
- ie = ze([
5036
+ ie = Le([
5037
5037
  v("Timeline")
5038
5038
  ], ie);
5039
5039
  var ko = Object.defineProperty, Uo = Object.getOwnPropertyDescriptor, is = (r, e, t, s) => {
@@ -5054,7 +5054,7 @@ var Do = Object.defineProperty, ht = (r, e, t, s) => {
5054
5054
  (a = r[o]) && (i = a(e, t, i) || i);
5055
5055
  return i && Do(e, t, i), i;
5056
5056
  };
5057
- class Le extends Zt {
5057
+ class ze extends Zt {
5058
5058
  input = new Ri();
5059
5059
  renderStack = new Ro();
5060
5060
  root = new wt(!0).setTree(this);
@@ -5106,19 +5106,19 @@ class Le extends Zt {
5106
5106
  }
5107
5107
  ht([
5108
5108
  u()
5109
- ], Le.prototype, "backgroundColor");
5109
+ ], ze.prototype, "backgroundColor");
5110
5110
  ht([
5111
5111
  u({ internal: !0, fallback: !1 })
5112
- ], Le.prototype, "debug");
5112
+ ], ze.prototype, "debug");
5113
5113
  ht([
5114
5114
  u({ internal: !0, fallback: !1 })
5115
- ], Le.prototype, "processPaused");
5115
+ ], ze.prototype, "processPaused");
5116
5116
  ht([
5117
5117
  u({ internal: !0, default: () => Js })
5118
- ], Le.prototype, "fonts");
5118
+ ], ze.prototype, "fonts");
5119
5119
  ht([
5120
5120
  u({ internal: !0, default: () => new ie() })
5121
- ], Le.prototype, "timeline");
5121
+ ], ze.prototype, "timeline");
5122
5122
  var Io = Object.getOwnPropertyDescriptor, Bo = (r, e, t, s) => {
5123
5123
  for (var i = s > 1 ? void 0 : s ? Io(e, t) : e, o = r.length - 1, a; o >= 0; o--)
5124
5124
  (a = r[o]) && (i = a(i) || i);
@@ -5136,8 +5136,8 @@ Me = Bo([
5136
5136
  duration: 2e3
5137
5137
  })
5138
5138
  ], Me);
5139
- var No = Object.defineProperty, zo = Object.getOwnPropertyDescriptor, rr = (r, e, t, s) => {
5140
- for (var i = s > 1 ? void 0 : s ? zo(e, t) : e, o = r.length - 1, a; o >= 0; o--)
5139
+ var No = Object.defineProperty, Lo = Object.getOwnPropertyDescriptor, rr = (r, e, t, s) => {
5140
+ for (var i = s > 1 ? void 0 : s ? Lo(e, t) : e, o = r.length - 1, a; o >= 0; o--)
5141
5141
  (a = r[o]) && (i = (s ? a(e, t, i) : a(i)) || i);
5142
5142
  return s && i && No(e, t, i), i;
5143
5143
  };
@@ -5146,12 +5146,12 @@ let xe = class extends ye {
5146
5146
  scale = new S(1, 1).on("update", () => this.updateGlobalTransform());
5147
5147
  skew = new S().on("update", () => this.updateGlobalTransform());
5148
5148
  pivot = new S().on("update", () => this.updateGlobalTransform());
5149
- extraTransform = new O();
5150
- transform = new O();
5149
+ extraTransform = new M();
5150
+ transform = new M();
5151
5151
  globalPosition = new S();
5152
5152
  globalScale = new S();
5153
5153
  globalSkew = new S();
5154
- globalTransform = new O();
5154
+ globalTransform = new M();
5155
5155
  _parentTransformDirtyId;
5156
5156
  constructor(r, e = []) {
5157
5157
  super(), this.setProperties(r).append(e);
@@ -5223,14 +5223,15 @@ rr([
5223
5223
  xe = rr([
5224
5224
  v("Node2D")
5225
5225
  ], xe);
5226
- var Lo = Object.defineProperty, Fo = Object.getOwnPropertyDescriptor, kt = (r, e, t, s) => {
5226
+ var zo = Object.defineProperty, Fo = Object.getOwnPropertyDescriptor, kt = (r, e, t, s) => {
5227
5227
  for (var i = s > 1 ? void 0 : s ? Fo(e, t) : e, o = r.length - 1, a; o >= 0; o--)
5228
5228
  (a = r[o]) && (i = (s ? a(e, t, i) : a(i)) || i);
5229
- return s && i && Lo(e, t, i), i;
5229
+ return s && i && zo(e, t, i), i;
5230
5230
  };
5231
5231
  let Ke = class extends xe {
5232
+ canvasTransform = new M();
5232
5233
  _screenOffset = { x: 0, y: 0 };
5233
- _zoom = new S(1, 1).on("update", () => this.updateCanvasTransform());
5234
+ _zoom = new S(1, 1).on("update", () => this.updateTransform());
5234
5235
  get zoom() {
5235
5236
  return this._zoom;
5236
5237
  }
@@ -5291,8 +5292,8 @@ let Ke = class extends xe {
5291
5292
  } else if (e === "pointermove") {
5292
5293
  const t = r;
5293
5294
  this.grabbing && (this.position.add(
5294
- -(this._screenOffset.x - t.screenX),
5295
- -(this._screenOffset.y - t.screenY)
5295
+ this._screenOffset.x - t.screenX,
5296
+ this._screenOffset.y - t.screenY
5296
5297
  ), this._screenOffset = { x: t.screenX, y: t.screenY });
5297
5298
  } else if (e === "pointerup") {
5298
5299
  const t = r;
@@ -5303,16 +5304,16 @@ let Ke = class extends xe {
5303
5304
  if (r.ctrlKey) {
5304
5305
  if (!(r.wheelDeltaY ? Math.abs(Math.abs(r.wheelDeltaY) - Math.abs(3 * r.deltaY)) < 3 : r.deltaMode === 0)) {
5305
5306
  r.preventDefault();
5306
- const t = this._zoom.x;
5307
+ const t = { x: r.screenX, y: r.screenY }, s = this.toGlobal(t);
5307
5308
  this.zoomWithWheel(r.deltaY);
5308
- const s = 1 - this._zoom.x / t;
5309
+ const i = this.toScreen(s);
5309
5310
  this.position.add(
5310
- (r.screenX - this.position.x) * s,
5311
- (r.screenY - this.position.y) * s
5311
+ i.x - t.x,
5312
+ i.y - t.y
5312
5313
  );
5313
5314
  }
5314
5315
  } else
5315
- r.preventDefault(), this.position.add(-r.deltaX, -r.deltaY);
5316
+ r.preventDefault(), this.position.add(r.deltaX, r.deltaY);
5316
5317
  }
5317
5318
  zoomWithWheel(r) {
5318
5319
  const e = Math.log(this._zoom.x), t = -r * this.wheelSensitivity, s = e + t;
@@ -5322,20 +5323,13 @@ let Ke = class extends xe {
5322
5323
  super.updateTransform(), this.updateCanvasTransform();
5323
5324
  }
5324
5325
  updateCanvasTransform() {
5325
- const r = this.getViewport();
5326
- r && (r.canvasTransform.identity().scale(this._zoom.x, this._zoom.y).translate(this.position.x, this.position.y), this.emit("updateCanvasTransform"));
5326
+ this.canvasTransform.identity().scale(this._zoom.x, this._zoom.y).premultiply(this.transform.affineInverse()), this.getViewport()?.canvasTransform.copy(this.canvasTransform), this.emit("updateCanvasTransform");
5327
5327
  }
5328
5328
  toGlobal(r, e) {
5329
- const t = this.getViewport();
5330
- if (!t)
5331
- throw new Error("Failed to toGlobal, viewport is empty");
5332
- return t.toCanvasGlobal(r, e);
5329
+ return this.canvasTransform.applyAffineInverse(r, e);
5333
5330
  }
5334
5331
  toScreen(r, e) {
5335
- const t = this.getViewport();
5336
- if (!t)
5337
- throw new Error("Failed to toScreen, viewport is empty");
5338
- return t.toCanvasScreen(r, e);
5332
+ return this.canvasTransform.apply(r, e);
5339
5333
  }
5340
5334
  toJSON() {
5341
5335
  return {
@@ -5410,7 +5404,7 @@ function Al(r) {
5410
5404
  }
5411
5405
  return e;
5412
5406
  }
5413
- function $o(r, e, t, s = new O()) {
5407
+ function $o(r, e, t, s = new M()) {
5414
5408
  return r = !r || r === "none" ? "" : r, At(r, { width: e, height: t }).reverse().forEach(({ name: i, args: o }) => {
5415
5409
  const a = o.map((n) => n.normalizedIntValue);
5416
5410
  switch (i) {
@@ -7110,7 +7104,7 @@ ue = ct([
7110
7104
  ], ue);
7111
7105
  function Pt(r, e) {
7112
7106
  let t = !1;
7113
- const { left: s = 0, top: i = 0, width: o, height: a } = e, n = new O().translate(-s, -i).scale(1 / o, 1 / a);
7107
+ const { left: s = 0, top: i = 0, width: o, height: a } = e, n = new M().translate(-s, -i).scale(1 / o, 1 / a);
7114
7108
  if (r.cropRect) {
7115
7109
  const {
7116
7110
  left: h = 0,
@@ -7147,10 +7141,10 @@ function Pt(r, e) {
7147
7141
  }
7148
7142
  return { disableWrapMode: t, uvTransform: n };
7149
7143
  }
7150
- var za = Object.defineProperty, H = (r, e, t, s) => {
7144
+ var La = Object.defineProperty, H = (r, e, t, s) => {
7151
7145
  for (var i = void 0, o = r.length - 1, a; o >= 0; o--)
7152
7146
  (a = r[o]) && (i = a(e, t, i) || i);
7153
- return i && za(e, t, i), i;
7147
+ return i && La(e, t, i), i;
7154
7148
  };
7155
7149
  class D extends pe {
7156
7150
  constructor(e) {
@@ -7163,7 +7157,7 @@ class D extends pe {
7163
7157
  }
7164
7158
  setProperties(e) {
7165
7159
  return this._setProperties(
7166
- L(e) ? void 0 : $s(e)
7160
+ z(e) ? void 0 : $s(e)
7167
7161
  );
7168
7162
  }
7169
7163
  _updateProperty(e, t, s) {
@@ -7190,7 +7184,7 @@ class D extends pe {
7190
7184
  this.linearGradient ?? this.radialGradient,
7191
7185
  this.parent.size.width,
7192
7186
  this.parent.size.height
7193
- ) : L(this.image) || (this.parent.tree?.log(`load image ${this.image}`), this.image.split("?")[0].endsWith(".gif") ? this.animatedTexture = await q.gif.load(this.image) : this.texture = await q.texture.load(this.image));
7187
+ ) : z(this.image) || (this.parent.tree?.log(`load image ${this.image}`), this.image.split("?")[0].endsWith(".gif") ? this.animatedTexture = await q.gif.load(this.image) : this.texture = await q.texture.load(this.image));
7194
7188
  }
7195
7189
  async _updateTexture() {
7196
7190
  await this.loadTexture(), this.parent.requestRedraw();
@@ -7264,15 +7258,15 @@ H([
7264
7258
  H([
7265
7259
  u()
7266
7260
  ], D.prototype, "opacity");
7267
- var La = Object.defineProperty, Fa = (r, e, t, s) => {
7261
+ var za = Object.defineProperty, Fa = (r, e, t, s) => {
7268
7262
  for (var i = void 0, o = r.length - 1, a; o >= 0; o--)
7269
7263
  (a = r[o]) && (i = a(e, t, i) || i);
7270
- return i && La(e, t, i), i;
7264
+ return i && za(e, t, i), i;
7271
7265
  };
7272
7266
  class Cs extends D {
7273
7267
  setProperties(e) {
7274
7268
  return super._setProperties(
7275
- L(e) ? void 0 : Vs(e)
7269
+ z(e) ? void 0 : Vs(e)
7276
7270
  );
7277
7271
  }
7278
7272
  _updateProperty(e, t, s) {
@@ -7294,7 +7288,7 @@ var $a = Object.defineProperty, Va = (r, e, t, s) => {
7294
7288
  class Ss extends D {
7295
7289
  setProperties(e) {
7296
7290
  return super._setProperties(
7297
- L(e) ? void 0 : Gs(e)
7291
+ z(e) ? void 0 : Gs(e)
7298
7292
  );
7299
7293
  }
7300
7294
  _updateProperty(e, t, s) {
@@ -7316,7 +7310,7 @@ var Ga = Object.defineProperty, ut = (r, e, t, s) => {
7316
7310
  class $e extends D {
7317
7311
  setProperties(e) {
7318
7312
  return super._setProperties(
7319
- L(e) ? void 0 : js(e)
7313
+ z(e) ? void 0 : js(e)
7320
7314
  );
7321
7315
  }
7322
7316
  _updateProperty(e, t, s) {
@@ -7373,7 +7367,7 @@ class Ve extends pe {
7373
7367
  }
7374
7368
  setProperties(e) {
7375
7369
  return super.setProperties(
7376
- L(e) ? void 0 : Ws(e)
7370
+ z(e) ? void 0 : Ws(e)
7377
7371
  );
7378
7372
  }
7379
7373
  _updateProperty(e, t, s) {
@@ -7419,7 +7413,7 @@ class Ge extends pe {
7419
7413
  _path2DSet = new ti();
7420
7414
  setProperties(e) {
7421
7415
  return super.setProperties(
7422
- L(e) ? void 0 : qs(e)
7416
+ z(e) ? void 0 : qs(e)
7423
7417
  );
7424
7418
  }
7425
7419
  _updateProperty(e, t, s) {
@@ -7504,7 +7498,7 @@ class ee extends pe {
7504
7498
  _textureMap = /* @__PURE__ */ new Map();
7505
7499
  setProperties(e) {
7506
7500
  return super.setProperties(
7507
- L(e) ? void 0 : Hs(e)
7501
+ z(e) ? void 0 : Hs(e)
7508
7502
  );
7509
7503
  }
7510
7504
  _updateProperty(e, t, s) {
@@ -7562,7 +7556,7 @@ class ee extends pe {
7562
7556
  e.linearGradient ?? e.radialGradient,
7563
7557
  t.width,
7564
7558
  t.height
7565
- ) : L(e.image) ? void 0 : (this.parent.tree?.log(`load image ${e.image}`), await q.texture.load(e.image));
7559
+ ) : z(e.image) ? void 0 : (this.parent.tree?.log(`load image ${e.image}`), await q.texture.load(e.image));
7566
7560
  }
7567
7561
  setContent(e) {
7568
7562
  this.content = Ys(e);
@@ -7578,7 +7572,7 @@ class ee extends pe {
7578
7572
  if (e.scale.x > 0 && e.scale.y > 0)
7579
7573
  return;
7580
7574
  const t = e.scale.x * e.scale.y, s = e.pivot;
7581
- return new O().translate(-s.x, -s.y).scale(t > 0 ? 1 : -1, 1).translate(s.x, s.y);
7575
+ return new M().translate(-s.x, -s.y).scale(t > 0 ? 1 : -1, 1).translate(s.x, s.y);
7582
7576
  }
7583
7577
  useTextureDraw() {
7584
7578
  let e = this.drawMode;
@@ -7590,7 +7584,7 @@ class ee extends pe {
7590
7584
  const i = s.getMeta();
7591
7585
  if (i instanceof oi) {
7592
7586
  const o = i.parent.index, a = i.parent.parent.index;
7593
- if (s.style.fill && !L(s.style.fill))
7587
+ if (s.style.fill && !z(s.style.fill))
7594
7588
  if (typeof s.style.fill == "object") {
7595
7589
  const n = s.style.fill, h = this._textureMap.get(`${a}.${o}.fill`) ?? this._textureMap.get(`${a}.fill`) ?? this._textureMap.get("fill");
7596
7590
  if (n.enabled !== !1 && (h || n.color)) {
@@ -7611,7 +7605,7 @@ class ee extends pe {
7611
7605
  e.addPath(s), e.style = { ...s.style }, e.fill({
7612
7606
  vertTransform: this._createVertTransform()
7613
7607
  });
7614
- if (s.style.stroke && !L(s.style.stroke))
7608
+ if (s.style.stroke && !z(s.style.stroke))
7615
7609
  if (typeof s.style.stroke == "object") {
7616
7610
  const n = s.style.stroke, h = this._textureMap.get(`${a}.${o}.outline`) ?? this._textureMap.get(`${a}.outline`) ?? this._textureMap.get("outline");
7617
7611
  if (n.enabled !== !1 && (h || n.color) && (n.width === void 0 || n.width)) {
@@ -7642,7 +7636,7 @@ class ee extends pe {
7642
7636
  _textureDraw(e) {
7643
7637
  const { left: t = 0, top: s = 0, width: i, height: o } = this.base.boundingBox;
7644
7638
  e.fillStyle = this._texture, e.rect(t, s, i, o), e.fill({
7645
- uvTransform: new O().translate(-t, -s).scale(1 / i, 1 / o),
7639
+ uvTransform: new M().translate(-t, -s).scale(1 / i, 1 / o),
7646
7640
  vertTransform: this._createVertTransform()
7647
7641
  });
7648
7642
  }
@@ -7841,7 +7835,7 @@ let rt = class extends xe {
7841
7835
  this._overflowHidden = e === "hidden";
7842
7836
  break;
7843
7837
  case "pointerEvents":
7844
- this._allowPointerEvents = !L(e);
7838
+ this._allowPointerEvents = !z(e);
7845
7839
  break;
7846
7840
  case "borderRadius":
7847
7841
  default:
@@ -8508,7 +8502,7 @@ let De = class extends Te {
8508
8502
  const { left: e = 0, top: t = 0, right: s = 0, bottom: i = 0 } = this.srcRect ?? {}, { width: o, height: a } = this.size;
8509
8503
  this.context.fillStyle = r;
8510
8504
  const n = Math.abs(1 + (e + s)) * o, h = Math.abs(1 + (t + i)) * a, l = 1 / n, c = 1 / h, d = e * o * l, p = t * a * c;
8511
- this.context.uvTransform = new O().scale(l, c).translate(d, p), this.shape.draw(), this.context.fill();
8505
+ this.context.uvTransform = new M().scale(l, c).translate(d, p), this.shape.draw(), this.context.fill();
8512
8506
  }
8513
8507
  }
8514
8508
  _repaint(r) {
@@ -8670,7 +8664,7 @@ function _t(r, e, t, s) {
8670
8664
  const o = 3 * r - 3 * t + 1, a = 3 * t - 6 * r, n = 3 * r, h = 3 * e - 3 * s + 1, l = 3 * s - 6 * e, c = 3 * e, d = (m) => (3 * o * m + 2 * a) * m + n, p = (m) => ((o * m + a) * m + n) * m, _ = (m) => ((h * m + l) * m + c) * m;
8671
8665
  function f(m) {
8672
8666
  let g = m, w, P;
8673
- for (let z = 0; z < 8; z++) {
8667
+ for (let L = 0; L < 8; L++) {
8674
8668
  if (P = p(g) - m, Math.abs(P) < 1e-6)
8675
8669
  return g;
8676
8670
  if (w = d(g), Math.abs(w) < 1e-6)
@@ -9667,7 +9661,7 @@ let it = class extends Te {
9667
9661
  }
9668
9662
  _drawSrc() {
9669
9663
  const r = this._src;
9670
- r?.isValid() && (this.context.fillStyle = r, this.context.uvTransform = new O().scale(
9664
+ r?.isValid() && (this.context.fillStyle = r, this.context.uvTransform = new M().scale(
9671
9665
  1 / this.style.width,
9672
9666
  1 / this.style.height
9673
9667
  ));
@@ -9750,11 +9744,11 @@ void main(void) {
9750
9744
  Et = In([
9751
9745
  v("KawaseTransition")
9752
9746
  ], Et);
9753
- var Nn = Object.defineProperty, zn = Object.getOwnPropertyDescriptor, Ln = (r, e, t) => e in r ? Nn(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Fn = (r, e, t, s) => {
9754
- for (var i = s > 1 ? void 0 : s ? zn(e, t) : e, o = r.length - 1, a; o >= 0; o--)
9747
+ var Nn = Object.defineProperty, Ln = Object.getOwnPropertyDescriptor, zn = (r, e, t) => e in r ? Nn(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Fn = (r, e, t, s) => {
9748
+ for (var i = s > 1 ? void 0 : s ? Ln(e, t) : e, o = r.length - 1, a; o >= 0; o--)
9755
9749
  (a = r[o]) && (i = a(i) || i);
9756
9750
  return i;
9757
- }, $n = (r, e, t) => Ln(r, e + "", t);
9751
+ }, $n = (r, e, t) => zn(r, e + "", t);
9758
9752
  let Ct = class extends Me {
9759
9753
  apply(r) {
9760
9754
  b.draw(r, Ct.material, {
@@ -10001,9 +9995,12 @@ class el extends Ee {
10001
9995
  },
10002
9996
  loop: !1,
10003
9997
  autoplay: !1,
10004
- animationData: await e.fetch(s).then((a) => a.json())
9998
+ animationData: await e.loadBy(
9999
+ s,
10000
+ () => e.fetch(s).then((a) => a.json())
10001
+ )
10005
10002
  });
10006
- return this.load = (s, i) => e.loadBy(s, () => t(s, i)), [
10003
+ return this.load = (s, i) => t(s, i), [
10007
10004
  "lottie"
10008
10005
  ].forEach((s) => {
10009
10006
  e.register(s, t);
@@ -10238,7 +10235,7 @@ const Ae = {
10238
10235
  preserveDrawingBuffer: !1,
10239
10236
  powerPreference: "default"
10240
10237
  };
10241
- class Nt extends Le {
10238
+ class Nt extends ze {
10242
10239
  renderer;
10243
10240
  get view() {
10244
10241
  return this.renderer.view;
@@ -10319,7 +10316,7 @@ class Nt extends Le {
10319
10316
  return this.renderer.resize(e, t, s), this.root.width = e, this.root.height = t, this.root.requestUpload(), this.render(), this;
10320
10317
  }
10321
10318
  nextTick() {
10322
- return Lr();
10319
+ return zr();
10323
10320
  }
10324
10321
  async waitUntilLoad() {
10325
10322
  await q.waitUntilLoad(), await this.nextTick();
@@ -10406,7 +10403,7 @@ async function cl(r) {
10406
10403
  data: o,
10407
10404
  keyframes: a = [],
10408
10405
  onBefore: n,
10409
- onFrame: h
10406
+ onKeyframe: h
10410
10407
  } = r;
10411
10408
  return I ??= new Nt({
10412
10409
  pixelRatio: 1,
@@ -10414,8 +10411,8 @@ async function cl(r) {
10414
10411
  height: 1,
10415
10412
  preserveDrawingBuffer: !0
10416
10413
  }), I.debug = e, I.fonts = t, I.timeline.currentTime = 0, I.root.removeChildren(), I.resize(s, i, !0), (Array.isArray(o) ? o : [o]).forEach((l) => {
10417
- l instanceof M ? (l.parent = void 0, I.root.appendChild(l)) : I.root.appendChild(M.parse(l));
10418
- }), await n?.(I), await I.waitAndRender(), await new Promise((l) => {
10414
+ l instanceof O ? (l.parent = void 0, I.root.appendChild(l)) : I.root.appendChild(O.parse(l));
10415
+ }), await n?.(I), await I.waitAndRender(), a.length && await new Promise((l) => {
10419
10416
  let c = 0;
10420
10417
  const d = a.length, p = a[d - 1];
10421
10418
  async function _() {
@@ -10425,7 +10422,7 @@ async function cl(r) {
10425
10422
  I.timeline.currentTime = f, I.render(), await h?.(I.toPixels(), {
10426
10423
  currentTime: f,
10427
10424
  duration: g,
10428
- progress: f / p
10425
+ progress: p !== 0 ? f / p : 1
10429
10426
  }), requestAnimationFrame(_);
10430
10427
  }
10431
10428
  _();
@@ -10513,7 +10510,7 @@ export {
10513
10510
  ki as Matrix4,
10514
10511
  go as Meta,
10515
10512
  Hr as MouseInputEvent,
10516
- M as Node,
10513
+ O as Node,
10517
10514
  xe as Node2D,
10518
10515
  U as OutlineEffect,
10519
10516
  Kt as PI,
@@ -10544,7 +10541,7 @@ export {
10544
10541
  gi as SUPPORTS_WEBKIT_OFFLINE_AUDIO_CONTEXT,
10545
10542
  vi as SUPPORTS_WEB_AUDIO,
10546
10543
  _i as SUPPORTS_WHEEL_EVENTS,
10547
- Le as SceneTree,
10544
+ ze as SceneTree,
10548
10545
  tl as TextLoader,
10549
10546
  T as Texture2D,
10550
10547
  rl as TextureLoader,
@@ -10553,7 +10550,7 @@ export {
10553
10550
  ot as TiltShiftTransition,
10554
10551
  ie as Timeline,
10555
10552
  G as TimelineNode,
10556
- O as Transform2D,
10553
+ M as Transform2D,
10557
10554
  cn as TransformRect2D,
10558
10555
  Me as Transition,
10559
10556
  St as TwistTransition,
@@ -10582,7 +10579,7 @@ export {
10582
10579
  Qi as WebGLRenderer,
10583
10580
  Xi as WebGLScissorModule,
10584
10581
  Re as WebGLState,
10585
- Li as WebGLStateModule,
10582
+ zi as WebGLStateModule,
10586
10583
  Hi as WebGLStencilModule,
10587
10584
  Ki as WebGLTextureModule,
10588
10585
  Zi as WebGLVertexArrayModule,
@@ -10627,9 +10624,9 @@ export {
10627
10624
  C as lerp,
10628
10625
  _n as linear,
10629
10626
  xr as log2,
10630
- zi as mapWebGLBlendModes,
10627
+ Li as mapWebGLBlendModes,
10631
10628
  yr as nextPow2,
10632
- Lr as nextTick,
10629
+ zr as nextTick,
10633
10630
  Or as overflowMap,
10634
10631
  Al as parseCSSFilter,
10635
10632
  $o as parseCSSTransform,
package/dist/render.d.ts CHANGED
@@ -9,7 +9,7 @@ export interface RenderOptions {
9
9
  fonts?: Fonts;
10
10
  keyframes?: number[];
11
11
  onBefore?: (engine: Engine) => void | Promise<void>;
12
- onFrame?: (frame: Uint8ClampedArray<ArrayBuffer>, ctx: {
12
+ onKeyframe?: (frame: Uint8ClampedArray<ArrayBuffer>, ctx: {
13
13
  currentTime: number;
14
14
  duration: number;
15
15
  progress: number;
@@ -1,7 +1,7 @@
1
1
  import type { InputEvent, InputEventKey, Vector2Data, WheelInputEvent } from '../../core';
2
2
  import type { Node } from '../main';
3
3
  import type { Node2DEvents, Node2DProperties } from './Node2D';
4
- import { Vector2 } from '../../core';
4
+ import { Transform2D, Vector2 } from '../../core';
5
5
  import { Node2D } from './Node2D';
6
6
  export interface Camera2DProperties extends Node2DProperties {
7
7
  zoom?: Vector2Data;
@@ -22,6 +22,7 @@ export declare class Camera2D extends Node2D {
22
22
  wheelSensitivity: number;
23
23
  spaceKey: boolean;
24
24
  grabbing: boolean;
25
+ readonly canvasTransform: Transform2D;
25
26
  protected _screenOffset: {
26
27
  x: number;
27
28
  y: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.12.22",
4
+ "version": "0.13.0",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",
@@ -97,8 +97,8 @@
97
97
  "simple-git-hooks": "^2.13.1",
98
98
  "typescript": "^5.9.3",
99
99
  "unbuild": "^3.6.1",
100
- "vite": "^7.1.12",
101
- "vitest": "^4.0.6",
100
+ "vite": "^7.2.1",
101
+ "vitest": "^4.0.7",
102
102
  "yoga-layout": "^3.2.1"
103
103
  },
104
104
  "simple-git-hooks": {