modern-canvas 0.8.3 → 0.8.5

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
@@ -9739,7 +9739,7 @@ class BaseElement2DShape extends CoreObject {
9739
9739
  }
9740
9740
  if (!viewBox) {
9741
9741
  const bbox = this._path2DSet.getBoundingBox();
9742
- viewBox = bbox ? [bbox.x, bbox.y, bbox.width, bbox.height] : [0, 0, 1, 1];
9742
+ viewBox = bbox ? [bbox.x, bbox.y, bbox.width || 1, bbox.height || 1] : [0, 0, 1, 1];
9743
9743
  }
9744
9744
  const [x, y, w, h] = viewBox;
9745
9745
  this._path2DSet.paths.forEach((path) => {
@@ -9889,6 +9889,15 @@ class BaseElement2DText extends CoreObject {
9889
9889
  this.enabled && !/^\s*$/.test(this.base.toString())
9890
9890
  );
9891
9891
  }
9892
+ _getVertTransform() {
9893
+ const parent = this.parent;
9894
+ if (parent.scale.x > 0 && parent.scale.y > 0) {
9895
+ return void 0;
9896
+ }
9897
+ const scale = parent.scale.x * parent.scale.y;
9898
+ const origin = parent.getTransformOrigin();
9899
+ return new Transform2D().translate(-origin.x, -origin.y).scale(scale > 0 ? 1 : -1, 1).translate(origin.x, origin.y);
9900
+ }
9892
9901
  draw() {
9893
9902
  const ctx = this.parent.context;
9894
9903
  this.base.update();
@@ -9906,11 +9915,13 @@ class BaseElement2DText extends CoreObject {
9906
9915
  ctx.strokeStyle = this._textures[0] ?? outline.color;
9907
9916
  ctx.lineCap = outline.lineCap;
9908
9917
  ctx.lineJoin = outline.lineJoin;
9918
+ ctx.vertTransform = this._getVertTransform();
9909
9919
  ctx.stroke({ disableWrapMode });
9910
9920
  }
9911
9921
  } else {
9912
9922
  ctx.addPath(path);
9913
9923
  ctx.style = { ...path.style };
9924
+ ctx.vertTransform = this._getVertTransform();
9914
9925
  ctx.stroke();
9915
9926
  }
9916
9927
  }
@@ -9923,13 +9934,13 @@ class BaseElement2DText extends CoreObject {
9923
9934
  ctx.style = { ...path.style };
9924
9935
  ctx.uvTransform = uvTransform;
9925
9936
  ctx.fillStyle = this._textures[1] ?? fill.color;
9926
- ctx.fill({
9927
- disableWrapMode
9928
- });
9937
+ ctx.vertTransform = this._getVertTransform();
9938
+ ctx.fill({ disableWrapMode });
9929
9939
  }
9930
9940
  } else {
9931
9941
  ctx.addPath(path);
9932
9942
  ctx.style = { ...path.style };
9943
+ ctx.vertTransform = this._getVertTransform();
9933
9944
  ctx.fill();
9934
9945
  }
9935
9946
  }
@@ -10064,16 +10075,22 @@ exports.BaseElement2D = class BaseElement2D extends exports.Node2D {
10064
10075
  }
10065
10076
  return this;
10066
10077
  }
10067
- _updateStyleProperty(key, value, _oldValue, _declaration) {
10078
+ _updateStyleProperty(key, value, oldValue, _declaration) {
10068
10079
  switch (key) {
10069
10080
  case "rotate":
10070
10081
  this.rotation = this.style.rotate * DEG_TO_RAD;
10071
10082
  break;
10072
10083
  case "scaleX":
10073
10084
  this.scale.x = this.style.scaleX;
10085
+ if (this.text.canDraw() && (value ^ oldValue) < 0) {
10086
+ this.requestRedraw();
10087
+ }
10074
10088
  break;
10075
10089
  case "scaleY":
10076
10090
  this.scale.y = this.style.scaleY;
10091
+ if (this.text.canDraw() && (value ^ oldValue) < 0) {
10092
+ this.requestRedraw();
10093
+ }
10077
10094
  break;
10078
10095
  case "skewX":
10079
10096
  this.skew.x = this.style.skewX;
package/dist/index.d.cts CHANGED
@@ -2104,6 +2104,7 @@ declare class BaseElement2DText extends CoreObject {
2104
2104
  measure(): MeasureResult;
2105
2105
  updateMeasure(): this;
2106
2106
  canDraw(): boolean;
2107
+ protected _getVertTransform(): Transform2D | undefined;
2107
2108
  draw(): void;
2108
2109
  }
2109
2110
 
@@ -2156,7 +2157,7 @@ declare class BaseElement2D extends Node2D implements Rectangulable {
2156
2157
  set shadow(value: Shadow);
2157
2158
  constructor(properties?: Partial<BaseElement2DProperties>, nodes?: Node[]);
2158
2159
  setProperties(properties?: Record<string, any>): this;
2159
- protected _updateStyleProperty(key: string, value: any, _oldValue: any, _declaration?: PropertyDeclaration): void;
2160
+ protected _updateStyleProperty(key: string, value: any, oldValue: any, _declaration?: PropertyDeclaration): void;
2160
2161
  protected _updateMaskImage(): void;
2161
2162
  getTransformOrigin(): Vector2;
2162
2163
  updateTransform(cb?: (transform: Transform2D) => void): void;
package/dist/index.d.mts CHANGED
@@ -2104,6 +2104,7 @@ declare class BaseElement2DText extends CoreObject {
2104
2104
  measure(): MeasureResult;
2105
2105
  updateMeasure(): this;
2106
2106
  canDraw(): boolean;
2107
+ protected _getVertTransform(): Transform2D | undefined;
2107
2108
  draw(): void;
2108
2109
  }
2109
2110
 
@@ -2156,7 +2157,7 @@ declare class BaseElement2D extends Node2D implements Rectangulable {
2156
2157
  set shadow(value: Shadow);
2157
2158
  constructor(properties?: Partial<BaseElement2DProperties>, nodes?: Node[]);
2158
2159
  setProperties(properties?: Record<string, any>): this;
2159
- protected _updateStyleProperty(key: string, value: any, _oldValue: any, _declaration?: PropertyDeclaration): void;
2160
+ protected _updateStyleProperty(key: string, value: any, oldValue: any, _declaration?: PropertyDeclaration): void;
2160
2161
  protected _updateMaskImage(): void;
2161
2162
  getTransformOrigin(): Vector2;
2162
2163
  updateTransform(cb?: (transform: Transform2D) => void): void;
package/dist/index.d.ts CHANGED
@@ -2104,6 +2104,7 @@ declare class BaseElement2DText extends CoreObject {
2104
2104
  measure(): MeasureResult;
2105
2105
  updateMeasure(): this;
2106
2106
  canDraw(): boolean;
2107
+ protected _getVertTransform(): Transform2D | undefined;
2107
2108
  draw(): void;
2108
2109
  }
2109
2110
 
@@ -2156,7 +2157,7 @@ declare class BaseElement2D extends Node2D implements Rectangulable {
2156
2157
  set shadow(value: Shadow);
2157
2158
  constructor(properties?: Partial<BaseElement2DProperties>, nodes?: Node[]);
2158
2159
  setProperties(properties?: Record<string, any>): this;
2159
- protected _updateStyleProperty(key: string, value: any, _oldValue: any, _declaration?: PropertyDeclaration): void;
2160
+ protected _updateStyleProperty(key: string, value: any, oldValue: any, _declaration?: PropertyDeclaration): void;
2160
2161
  protected _updateMaskImage(): void;
2161
2162
  getTransformOrigin(): Vector2;
2162
2163
  updateTransform(cb?: (transform: Transform2D) => void): void;