modern-canvas 0.4.37 → 0.4.39

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.mjs CHANGED
@@ -2490,25 +2490,23 @@ class Transform2D extends Matrix3 {
2490
2490
  return t2d.multiply(this, this);
2491
2491
  }
2492
2492
  skewX(x) {
2493
- return this.skew(x, 1);
2493
+ return this.skew(x, 0);
2494
2494
  }
2495
2495
  skewY(y) {
2496
- return this.skew(1, y);
2496
+ return this.skew(0, y);
2497
2497
  }
2498
2498
  skew(x, y) {
2499
2499
  return this.premultiply(Transform2D._t2d.makeSkew(x, y));
2500
2500
  }
2501
2501
  makeSkew(x, y) {
2502
- const cx = Math.cos(y);
2503
- const sx = Math.sin(y);
2504
- const cy = -Math.sin(-x);
2505
- const sy = Math.cos(-x);
2502
+ const tanX = Math.tan(x);
2503
+ const tanY = Math.tan(y);
2506
2504
  this.set([
2507
- cx,
2508
- cy,
2505
+ 1,
2506
+ tanY,
2509
2507
  0,
2510
- sx,
2511
- sy,
2508
+ tanX,
2509
+ 1,
2512
2510
  0,
2513
2511
  0,
2514
2512
  0,
@@ -2557,7 +2555,7 @@ class Transform2D extends Matrix3 {
2557
2555
  scale(x, y, z = 1) {
2558
2556
  return this.premultiply(Transform2D._t2d.makeScale(x, y, z));
2559
2557
  }
2560
- makeScale(x, y, z = 1) {
2558
+ makeScale(x, y, _z = 1) {
2561
2559
  this.set([
2562
2560
  x,
2563
2561
  0,
@@ -2567,7 +2565,7 @@ class Transform2D extends Matrix3 {
2567
2565
  0,
2568
2566
  0,
2569
2567
  0,
2570
- z
2568
+ 1
2571
2569
  ]);
2572
2570
  return this;
2573
2571
  }
@@ -6447,15 +6445,27 @@ let Node = class extends CoreObject {
6447
6445
  if (this.is(node) || node.hasParent()) {
6448
6446
  return node;
6449
6447
  }
6448
+ let index = -1;
6450
6449
  switch (internalMode) {
6451
6450
  case "default":
6451
+ index = this._children.findLastIndex((node2) => node2.internalMode === "default");
6452
+ if (index > -1) {
6453
+ index += 1;
6454
+ } else {
6455
+ index = this._children.findIndex((node2) => node2.internalMode === "back");
6456
+ }
6457
+ break;
6452
6458
  case "front": {
6453
- const targetMode = internalMode === "default" ? "back" : "front";
6454
- const index = this._children.findIndex((node2) => node2.internalMode === targetMode);
6459
+ index = this._children.findLastIndex((node2) => node2.internalMode === "front");
6455
6460
  if (index > -1) {
6456
- this._children.splice(index, 0, node);
6461
+ index += 1;
6457
6462
  } else {
6458
- this._children.push(node);
6463
+ index = this._children.findIndex((node2) => node2.internalMode === "default");
6464
+ }
6465
+ if (index > -1) {
6466
+ index += 1;
6467
+ } else {
6468
+ index = this._children.findIndex((node2) => node2.internalMode === "back");
6459
6469
  }
6460
6470
  break;
6461
6471
  }
@@ -6463,6 +6473,11 @@ let Node = class extends CoreObject {
6463
6473
  this._children.push(node);
6464
6474
  break;
6465
6475
  }
6476
+ if (index > -1) {
6477
+ this._children.splice(index, 0, node);
6478
+ } else {
6479
+ this._children.push(node);
6480
+ }
6466
6481
  node.internalMode = internalMode;
6467
6482
  node.setParent(this);
6468
6483
  this.emit("appendChild", node);
@@ -10201,7 +10216,7 @@ let BaseElement2D = class extends Node2D {
10201
10216
  const offsetY = originY * height;
10202
10217
  this.transform.identity().translate(-offsetX, -offsetY).scale(this.scale.x, this.scale.y).skew(this.skew.x, this.skew.y).rotate(this.rotation);
10203
10218
  parseCSSTransform(this.style.transform, width, height, this.transform);
10204
- this.transform.translate(offsetX + this.position.x, offsetY + this.position.y);
10219
+ this.transform.translate(this.position.x, this.position.y).translate(offsetX, offsetY);
10205
10220
  }
10206
10221
  _updateGlobalTransform() {
10207
10222
  super._updateGlobalTransform();
@@ -11225,22 +11240,23 @@ let Text2D = class extends TextureRect2D {
11225
11240
  this._subTextsCount = 0;
11226
11241
  }
11227
11242
  if (this.split) {
11228
- this.measureResult?.paragraphs.forEach((p) => {
11243
+ this.measure().paragraphs.forEach((p) => {
11229
11244
  p.fragments.forEach((f) => {
11230
11245
  f.characters.forEach((c) => {
11231
- this.appendChild(
11246
+ this.append(
11232
11247
  new Text2D({
11233
- content: c.content,
11248
+ internalMode: "front",
11234
11249
  style: {
11235
11250
  ...c.computedStyle,
11236
11251
  left: c.inlineBox.x,
11237
11252
  top: c.inlineBox.y,
11238
11253
  width: 0,
11239
- height: 0,
11240
- effects: this.effects
11241
- }
11242
- }),
11243
- "front"
11254
+ height: 0
11255
+ },
11256
+ content: c.content,
11257
+ effects: this.effects,
11258
+ fonts: this.fonts
11259
+ })
11244
11260
  );
11245
11261
  this._subTextsCount++;
11246
11262
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.4.37",
4
+ "version": "0.4.39",
5
5
  "packageManager": "pnpm@9.15.1",
6
6
  "description": "A JavaScript WebGL rendering engine.",
7
7
  "author": "wxm",