modern-canvas 0.1.4 → 0.1.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
@@ -3392,8 +3392,8 @@ class CanvasContext extends modernPath2d.Path2D {
3392
3392
  lineWidth;
3393
3393
  miterLimit;
3394
3394
  _defaultStyle = Texture.EMPTY;
3395
- _stroked = [];
3396
- _filled = [];
3395
+ _stroke = [];
3396
+ _fille = [];
3397
3397
  stroke() {
3398
3398
  let texture = this._defaultStyle;
3399
3399
  if (this.strokeStyle) {
@@ -3404,8 +3404,8 @@ class CanvasContext extends modernPath2d.Path2D {
3404
3404
  }
3405
3405
  }
3406
3406
  if (this.curves.length) {
3407
- this._stroked.push({
3408
- shapes: this.curves.slice(),
3407
+ this._stroke.push({
3408
+ path: new modernPath2d.Path2D(this),
3409
3409
  texture,
3410
3410
  textureTransform: this.textureTransform,
3411
3411
  style: {
@@ -3416,6 +3416,7 @@ class CanvasContext extends modernPath2d.Path2D {
3416
3416
  miterLimit: this.miterLimit ?? 10
3417
3417
  }
3418
3418
  });
3419
+ this.currentCurve = new modernPath2d.CurvePath();
3419
3420
  this.curves = [this.currentCurve];
3420
3421
  }
3421
3422
  }
@@ -3434,14 +3435,29 @@ class CanvasContext extends modernPath2d.Path2D {
3434
3435
  texture = new ColorTexture(this.fillStyle);
3435
3436
  }
3436
3437
  }
3437
- this._filled.push({
3438
- shapes: this.curves.slice(),
3438
+ this._fille.push({
3439
+ path: new modernPath2d.Path2D(this),
3439
3440
  texture,
3440
3441
  textureTransform: this.textureTransform
3441
3442
  });
3443
+ this.currentCurve = new modernPath2d.CurvePath();
3442
3444
  this.curves = [this.currentCurve];
3443
3445
  }
3446
+ copy(source) {
3447
+ super.copy(source);
3448
+ this.strokeStyle = source.strokeStyle;
3449
+ this.fillStyle = source.fillStyle;
3450
+ this.textureTransform = source.textureTransform;
3451
+ this.lineCap = source.lineCap;
3452
+ this.lineJoin = source.lineJoin;
3453
+ this.lineWidth = source.lineWidth;
3454
+ this.miterLimit = source.miterLimit;
3455
+ this._stroke = source._stroke.slice();
3456
+ this._fille = source._fille.slice();
3457
+ return this;
3458
+ }
3444
3459
  reset() {
3460
+ super.reset();
3445
3461
  this.strokeStyle = void 0;
3446
3462
  this.fillStyle = void 0;
3447
3463
  this.textureTransform = void 0;
@@ -3449,9 +3465,9 @@ class CanvasContext extends modernPath2d.Path2D {
3449
3465
  this.lineJoin = void 0;
3450
3466
  this.lineWidth = void 0;
3451
3467
  this.miterLimit = void 0;
3452
- this.curves = [this.currentCurve];
3453
- this._stroked.length = 0;
3454
- this._filled.length = 0;
3468
+ this._stroke.length = 0;
3469
+ this._fille.length = 0;
3470
+ return this;
3455
3471
  }
3456
3472
  buildUvs(start, vertices, uvs, texture, textureTransform) {
3457
3473
  if (texture) {
@@ -3489,15 +3505,11 @@ class CanvasContext extends modernPath2d.Path2D {
3489
3505
  uvs = [];
3490
3506
  texture = void 0;
3491
3507
  };
3492
- for (let len = this._stroked.length, i = 0; i < len; i++) {
3508
+ for (let len = this._stroke.length, i = 0; i < len; i++) {
3493
3509
  startUv = vertices.length;
3494
- const graphics = this._stroked[i];
3510
+ const graphics = this._stroke[i];
3495
3511
  texture ??= graphics.texture;
3496
- const points = [];
3497
- for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
3498
- graphics.shapes[i2].getAdaptivePointArray(points);
3499
- }
3500
- modernPath2d.strokeTriangulate(points, {
3512
+ graphics.path.strokeTriangulate({
3501
3513
  vertices,
3502
3514
  indices,
3503
3515
  lineStyle: graphics.style,
@@ -3507,19 +3519,17 @@ class CanvasContext extends modernPath2d.Path2D {
3507
3519
  this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
3508
3520
  push("stroke");
3509
3521
  }
3510
- for (let len = this._filled.length, i = 0; i < len; i++) {
3511
- const graphics = this._filled[i];
3522
+ for (let len = this._fille.length, i = 0; i < len; i++) {
3523
+ const graphics = this._fille[i];
3512
3524
  texture ??= graphics.texture;
3513
3525
  if (texture !== graphics.texture) {
3514
3526
  push("fill");
3515
3527
  }
3516
3528
  startUv = vertices.length;
3517
- for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
3518
- graphics.shapes[i2].fillTriangulate({
3519
- vertices,
3520
- indices
3521
- });
3522
- }
3529
+ graphics.path.fillTriangulate({
3530
+ vertices,
3531
+ indices
3532
+ });
3523
3533
  this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
3524
3534
  }
3525
3535
  if (vertices.length) {
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Visibility, Overflow, IDOCTextStyleDeclaration, IDOCTransformStyleDeclaration } from 'modern-idoc';
2
- import { CurvePath, LineStyle, Path2D, LineCap, LineJoin, BoundingBox } from 'modern-path2d';
2
+ import { Path2D, LineStyle, LineCap, LineJoin, BoundingBox } from 'modern-path2d';
3
3
  import { AnyColor, Colord } from 'colord';
4
4
  import { AnimationItem } from 'lottie-web';
5
5
  import { TextOptions, Text, MeasureResult } from 'modern-text';
@@ -1488,13 +1488,13 @@ interface CanvasBatchable extends Batchable2D {
1488
1488
  texture?: Texture;
1489
1489
  }
1490
1490
  interface StrokedGraphics {
1491
- shapes: CurvePath[];
1491
+ path: Path2D;
1492
1492
  texture?: Texture;
1493
1493
  textureTransform?: Transform2D;
1494
1494
  style: LineStyle;
1495
1495
  }
1496
1496
  interface FilledGraphics {
1497
- shapes: CurvePath[];
1497
+ path: Path2D;
1498
1498
  texture?: Texture;
1499
1499
  textureTransform?: Transform2D;
1500
1500
  }
@@ -1506,14 +1506,15 @@ declare class CanvasContext extends Path2D {
1506
1506
  lineJoin?: LineJoin;
1507
1507
  lineWidth?: number;
1508
1508
  miterLimit?: number;
1509
- protected _defaultStyle: Texture<TextureSource>;
1510
- protected _stroked: StrokedGraphics[];
1511
- protected _filled: FilledGraphics[];
1509
+ _defaultStyle: Texture<TextureSource>;
1510
+ _stroke: StrokedGraphics[];
1511
+ _fille: FilledGraphics[];
1512
1512
  stroke(): void;
1513
1513
  fillRect(x: number, y: number, width: number, height: number): void;
1514
1514
  strokeRect(x: number, y: number, width: number, height: number): void;
1515
1515
  fill(): void;
1516
- reset(): void;
1516
+ copy(source: CanvasContext): this;
1517
+ reset(): this;
1517
1518
  buildUvs(start: number, vertices: number[], uvs: number[], texture?: Texture, textureTransform?: Transform2D): void;
1518
1519
  toBatchables(): CanvasBatchable[];
1519
1520
  }
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Visibility, Overflow, IDOCTextStyleDeclaration, IDOCTransformStyleDeclaration } from 'modern-idoc';
2
- import { CurvePath, LineStyle, Path2D, LineCap, LineJoin, BoundingBox } from 'modern-path2d';
2
+ import { Path2D, LineStyle, LineCap, LineJoin, BoundingBox } from 'modern-path2d';
3
3
  import { AnyColor, Colord } from 'colord';
4
4
  import { AnimationItem } from 'lottie-web';
5
5
  import { TextOptions, Text, MeasureResult } from 'modern-text';
@@ -1488,13 +1488,13 @@ interface CanvasBatchable extends Batchable2D {
1488
1488
  texture?: Texture;
1489
1489
  }
1490
1490
  interface StrokedGraphics {
1491
- shapes: CurvePath[];
1491
+ path: Path2D;
1492
1492
  texture?: Texture;
1493
1493
  textureTransform?: Transform2D;
1494
1494
  style: LineStyle;
1495
1495
  }
1496
1496
  interface FilledGraphics {
1497
- shapes: CurvePath[];
1497
+ path: Path2D;
1498
1498
  texture?: Texture;
1499
1499
  textureTransform?: Transform2D;
1500
1500
  }
@@ -1506,14 +1506,15 @@ declare class CanvasContext extends Path2D {
1506
1506
  lineJoin?: LineJoin;
1507
1507
  lineWidth?: number;
1508
1508
  miterLimit?: number;
1509
- protected _defaultStyle: Texture<TextureSource>;
1510
- protected _stroked: StrokedGraphics[];
1511
- protected _filled: FilledGraphics[];
1509
+ _defaultStyle: Texture<TextureSource>;
1510
+ _stroke: StrokedGraphics[];
1511
+ _fille: FilledGraphics[];
1512
1512
  stroke(): void;
1513
1513
  fillRect(x: number, y: number, width: number, height: number): void;
1514
1514
  strokeRect(x: number, y: number, width: number, height: number): void;
1515
1515
  fill(): void;
1516
- reset(): void;
1516
+ copy(source: CanvasContext): this;
1517
+ reset(): this;
1517
1518
  buildUvs(start: number, vertices: number[], uvs: number[], texture?: Texture, textureTransform?: Transform2D): void;
1518
1519
  toBatchables(): CanvasBatchable[];
1519
1520
  }
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Visibility, Overflow, IDOCTextStyleDeclaration, IDOCTransformStyleDeclaration } from 'modern-idoc';
2
- import { CurvePath, LineStyle, Path2D, LineCap, LineJoin, BoundingBox } from 'modern-path2d';
2
+ import { Path2D, LineStyle, LineCap, LineJoin, BoundingBox } from 'modern-path2d';
3
3
  import { AnyColor, Colord } from 'colord';
4
4
  import { AnimationItem } from 'lottie-web';
5
5
  import { TextOptions, Text, MeasureResult } from 'modern-text';
@@ -1488,13 +1488,13 @@ interface CanvasBatchable extends Batchable2D {
1488
1488
  texture?: Texture;
1489
1489
  }
1490
1490
  interface StrokedGraphics {
1491
- shapes: CurvePath[];
1491
+ path: Path2D;
1492
1492
  texture?: Texture;
1493
1493
  textureTransform?: Transform2D;
1494
1494
  style: LineStyle;
1495
1495
  }
1496
1496
  interface FilledGraphics {
1497
- shapes: CurvePath[];
1497
+ path: Path2D;
1498
1498
  texture?: Texture;
1499
1499
  textureTransform?: Transform2D;
1500
1500
  }
@@ -1506,14 +1506,15 @@ declare class CanvasContext extends Path2D {
1506
1506
  lineJoin?: LineJoin;
1507
1507
  lineWidth?: number;
1508
1508
  miterLimit?: number;
1509
- protected _defaultStyle: Texture<TextureSource>;
1510
- protected _stroked: StrokedGraphics[];
1511
- protected _filled: FilledGraphics[];
1509
+ _defaultStyle: Texture<TextureSource>;
1510
+ _stroke: StrokedGraphics[];
1511
+ _fille: FilledGraphics[];
1512
1512
  stroke(): void;
1513
1513
  fillRect(x: number, y: number, width: number, height: number): void;
1514
1514
  strokeRect(x: number, y: number, width: number, height: number): void;
1515
1515
  fill(): void;
1516
- reset(): void;
1516
+ copy(source: CanvasContext): this;
1517
+ reset(): this;
1517
1518
  buildUvs(start: number, vertices: number[], uvs: number[], texture?: Texture, textureTransform?: Transform2D): void;
1518
1519
  toBatchables(): CanvasBatchable[];
1519
1520
  }