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 +34 -24
- package/dist/index.d.cts +8 -7
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +28 -28
- package/dist/index.mjs +35 -25
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { extend, colord } from 'colord';
|
|
2
2
|
import namesPlugin from 'colord/plugins/names';
|
|
3
|
-
import { Path2D,
|
|
3
|
+
import { Path2D, CurvePath, BoundingBox } from 'modern-path2d';
|
|
4
4
|
import { getDefaultTextStyle, getDefaultTransformStyle } from 'modern-idoc';
|
|
5
5
|
import { textDefaultStyle, Text } from 'modern-text';
|
|
6
6
|
|
|
@@ -3386,8 +3386,8 @@ class CanvasContext extends Path2D {
|
|
|
3386
3386
|
lineWidth;
|
|
3387
3387
|
miterLimit;
|
|
3388
3388
|
_defaultStyle = Texture.EMPTY;
|
|
3389
|
-
|
|
3390
|
-
|
|
3389
|
+
_stroke = [];
|
|
3390
|
+
_fille = [];
|
|
3391
3391
|
stroke() {
|
|
3392
3392
|
let texture = this._defaultStyle;
|
|
3393
3393
|
if (this.strokeStyle) {
|
|
@@ -3398,8 +3398,8 @@ class CanvasContext extends Path2D {
|
|
|
3398
3398
|
}
|
|
3399
3399
|
}
|
|
3400
3400
|
if (this.curves.length) {
|
|
3401
|
-
this.
|
|
3402
|
-
|
|
3401
|
+
this._stroke.push({
|
|
3402
|
+
path: new Path2D(this),
|
|
3403
3403
|
texture,
|
|
3404
3404
|
textureTransform: this.textureTransform,
|
|
3405
3405
|
style: {
|
|
@@ -3410,6 +3410,7 @@ class CanvasContext extends Path2D {
|
|
|
3410
3410
|
miterLimit: this.miterLimit ?? 10
|
|
3411
3411
|
}
|
|
3412
3412
|
});
|
|
3413
|
+
this.currentCurve = new CurvePath();
|
|
3413
3414
|
this.curves = [this.currentCurve];
|
|
3414
3415
|
}
|
|
3415
3416
|
}
|
|
@@ -3428,14 +3429,29 @@ class CanvasContext extends Path2D {
|
|
|
3428
3429
|
texture = new ColorTexture(this.fillStyle);
|
|
3429
3430
|
}
|
|
3430
3431
|
}
|
|
3431
|
-
this.
|
|
3432
|
-
|
|
3432
|
+
this._fille.push({
|
|
3433
|
+
path: new Path2D(this),
|
|
3433
3434
|
texture,
|
|
3434
3435
|
textureTransform: this.textureTransform
|
|
3435
3436
|
});
|
|
3437
|
+
this.currentCurve = new CurvePath();
|
|
3436
3438
|
this.curves = [this.currentCurve];
|
|
3437
3439
|
}
|
|
3440
|
+
copy(source) {
|
|
3441
|
+
super.copy(source);
|
|
3442
|
+
this.strokeStyle = source.strokeStyle;
|
|
3443
|
+
this.fillStyle = source.fillStyle;
|
|
3444
|
+
this.textureTransform = source.textureTransform;
|
|
3445
|
+
this.lineCap = source.lineCap;
|
|
3446
|
+
this.lineJoin = source.lineJoin;
|
|
3447
|
+
this.lineWidth = source.lineWidth;
|
|
3448
|
+
this.miterLimit = source.miterLimit;
|
|
3449
|
+
this._stroke = source._stroke.slice();
|
|
3450
|
+
this._fille = source._fille.slice();
|
|
3451
|
+
return this;
|
|
3452
|
+
}
|
|
3438
3453
|
reset() {
|
|
3454
|
+
super.reset();
|
|
3439
3455
|
this.strokeStyle = void 0;
|
|
3440
3456
|
this.fillStyle = void 0;
|
|
3441
3457
|
this.textureTransform = void 0;
|
|
@@ -3443,9 +3459,9 @@ class CanvasContext extends Path2D {
|
|
|
3443
3459
|
this.lineJoin = void 0;
|
|
3444
3460
|
this.lineWidth = void 0;
|
|
3445
3461
|
this.miterLimit = void 0;
|
|
3446
|
-
this.
|
|
3447
|
-
this.
|
|
3448
|
-
this
|
|
3462
|
+
this._stroke.length = 0;
|
|
3463
|
+
this._fille.length = 0;
|
|
3464
|
+
return this;
|
|
3449
3465
|
}
|
|
3450
3466
|
buildUvs(start, vertices, uvs, texture, textureTransform) {
|
|
3451
3467
|
if (texture) {
|
|
@@ -3483,15 +3499,11 @@ class CanvasContext extends Path2D {
|
|
|
3483
3499
|
uvs = [];
|
|
3484
3500
|
texture = void 0;
|
|
3485
3501
|
};
|
|
3486
|
-
for (let len = this.
|
|
3502
|
+
for (let len = this._stroke.length, i = 0; i < len; i++) {
|
|
3487
3503
|
startUv = vertices.length;
|
|
3488
|
-
const graphics = this.
|
|
3504
|
+
const graphics = this._stroke[i];
|
|
3489
3505
|
texture ??= graphics.texture;
|
|
3490
|
-
|
|
3491
|
-
for (let len2 = graphics.shapes.length, i2 = 0; i2 < len2; i2++) {
|
|
3492
|
-
graphics.shapes[i2].getAdaptivePointArray(points);
|
|
3493
|
-
}
|
|
3494
|
-
strokeTriangulate(points, {
|
|
3506
|
+
graphics.path.strokeTriangulate({
|
|
3495
3507
|
vertices,
|
|
3496
3508
|
indices,
|
|
3497
3509
|
lineStyle: graphics.style,
|
|
@@ -3501,19 +3513,17 @@ class CanvasContext extends Path2D {
|
|
|
3501
3513
|
this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
|
|
3502
3514
|
push("stroke");
|
|
3503
3515
|
}
|
|
3504
|
-
for (let len = this.
|
|
3505
|
-
const graphics = this.
|
|
3516
|
+
for (let len = this._fille.length, i = 0; i < len; i++) {
|
|
3517
|
+
const graphics = this._fille[i];
|
|
3506
3518
|
texture ??= graphics.texture;
|
|
3507
3519
|
if (texture !== graphics.texture) {
|
|
3508
3520
|
push("fill");
|
|
3509
3521
|
}
|
|
3510
3522
|
startUv = vertices.length;
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
});
|
|
3516
|
-
}
|
|
3523
|
+
graphics.path.fillTriangulate({
|
|
3524
|
+
vertices,
|
|
3525
|
+
indices
|
|
3526
|
+
});
|
|
3517
3527
|
this.buildUvs(startUv, vertices, uvs, graphics.texture, graphics.textureTransform);
|
|
3518
3528
|
}
|
|
3519
3529
|
if (vertices.length) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-canvas",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
5
5
|
"packageManager": "pnpm@9.15.1",
|
|
6
6
|
"description": "A JavaScript WebGL rendering engine.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"earcut": "^3.0.1",
|
|
72
72
|
"modern-font": "^0.3.5",
|
|
73
73
|
"modern-idoc": "^0.1.5",
|
|
74
|
-
"modern-path2d": "^1.2.
|
|
74
|
+
"modern-path2d": "^1.2.3",
|
|
75
75
|
"modern-text": "^1.2.0"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|