modern-canvas 0.6.11 → 0.6.13
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 +64 -16
- package/dist/index.d.cts +11 -6
- package/dist/index.d.mts +11 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +49 -43
- package/dist/index.mjs +65 -17
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineProperty, EventEmitter, getDeclarations, parseColor, property, RawWeakMap as RawWeakMap$1, isGradient, clearUndef, idGenerator, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
|
|
1
|
+
import { defineProperty, EventEmitter, getDeclarations, parseColor, property, RawWeakMap as RawWeakMap$1, isGradient, clearUndef, idGenerator, isColorFillObject, normalizeFill, isNone, normalizeBackground, normalizeForeground, normalizeOutline, normalizeShadow, normalizeShape, getDefaultStyle, normalizeText } from 'modern-idoc';
|
|
2
2
|
import { extend } from 'colord';
|
|
3
3
|
import namesPlugin from 'colord/plugins/names';
|
|
4
4
|
import { Path2D, Path2DSet, svgToDom, svgToPath2DSet, Matrix3 as Matrix3$1 } from 'modern-path2d';
|
|
@@ -955,6 +955,8 @@ class CoreObject extends EventEmitter {
|
|
|
955
955
|
if (value && typeof value === "object") {
|
|
956
956
|
if ("toJSON" in value && typeof value.toJSON === "function") {
|
|
957
957
|
json[key] = value.toJSON();
|
|
958
|
+
} else if (Array.isArray(value)) {
|
|
959
|
+
json[key] = [...value];
|
|
958
960
|
} else {
|
|
959
961
|
json[key] = { ...value };
|
|
960
962
|
}
|
|
@@ -2439,7 +2441,7 @@ attribute vec4 aColorMatrixOffset;
|
|
|
2439
2441
|
attribute vec4 aDisableWrapMode;
|
|
2440
2442
|
|
|
2441
2443
|
uniform mat3 projectionMatrix;
|
|
2442
|
-
uniform mat3
|
|
2444
|
+
uniform mat3 worldTransformMatrix;
|
|
2443
2445
|
uniform vec4 modulate;
|
|
2444
2446
|
|
|
2445
2447
|
varying float vTextureId;
|
|
@@ -2451,8 +2453,14 @@ varying vec4 vColorMatrixOffset;
|
|
|
2451
2453
|
varying vec4 vDisableWrapMode;
|
|
2452
2454
|
|
|
2453
2455
|
void main(void) {
|
|
2456
|
+
mat3 modelMatrix = mat3(
|
|
2457
|
+
1.0, 0.0, 0.0,
|
|
2458
|
+
0.0, 1.0, 0.0,
|
|
2459
|
+
0.0, 0.0, 1.0
|
|
2460
|
+
);
|
|
2454
2461
|
vTextureId = aTextureId;
|
|
2455
|
-
|
|
2462
|
+
mat3 modelViewProjectionMatrix = projectionMatrix * worldTransformMatrix * modelMatrix;
|
|
2463
|
+
gl_Position = vec4((modelViewProjectionMatrix * vec3(aPosition, 1.0)).xy, 0.0, 1.0);
|
|
2456
2464
|
vUv = aUv;
|
|
2457
2465
|
vModulate = aModulate * modulate;
|
|
2458
2466
|
vBackgroundColor = aBackgroundColor;
|
|
@@ -2543,7 +2551,6 @@ void main(void) {
|
|
|
2543
2551
|
renderer2.program.updateUniforms(program, {
|
|
2544
2552
|
samplers,
|
|
2545
2553
|
modulate: [1, 1, 1, 1],
|
|
2546
|
-
translationMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
2547
2554
|
...renderer2.program.uniforms
|
|
2548
2555
|
});
|
|
2549
2556
|
renderer2.vertexArray.bind(vao ?? vertexArray);
|
|
@@ -3198,7 +3205,8 @@ class WebGLProgramModule extends WebGLModule {
|
|
|
3198
3205
|
}
|
|
3199
3206
|
boundProgram = null;
|
|
3200
3207
|
uniforms = {
|
|
3201
|
-
projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
|
3208
|
+
projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
3209
|
+
worldTransformMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
|
3202
3210
|
};
|
|
3203
3211
|
create(options) {
|
|
3204
3212
|
const program = this.gl.createProgram();
|
|
@@ -3400,7 +3408,10 @@ ${gl.getShaderInfoLog(shader)}`);
|
|
|
3400
3408
|
reset() {
|
|
3401
3409
|
super.reset();
|
|
3402
3410
|
this.boundProgram = null;
|
|
3403
|
-
this.uniforms = {
|
|
3411
|
+
this.uniforms = {
|
|
3412
|
+
projectionMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
3413
|
+
worldTransformMatrix: [1, 0, 0, 0, 1, 0, 0, 0, 1]
|
|
3414
|
+
};
|
|
3404
3415
|
}
|
|
3405
3416
|
free() {
|
|
3406
3417
|
super.free();
|
|
@@ -6047,18 +6058,21 @@ let Node = class extends CoreObject {
|
|
|
6047
6058
|
toJSON() {
|
|
6048
6059
|
return clearUndef({
|
|
6049
6060
|
...super.toJSON(),
|
|
6050
|
-
is: this.is,
|
|
6051
6061
|
children: this._children.length ? [...this._children.map((child) => child.toJSON())] : void 0,
|
|
6052
|
-
meta:
|
|
6062
|
+
meta: {
|
|
6063
|
+
...this.meta,
|
|
6064
|
+
inCanvasIs: this.is
|
|
6065
|
+
}
|
|
6053
6066
|
});
|
|
6054
6067
|
}
|
|
6055
6068
|
static parse(value) {
|
|
6056
6069
|
if (Array.isArray(value)) {
|
|
6057
6070
|
return value.map((val) => this.parse(val));
|
|
6058
6071
|
}
|
|
6059
|
-
const {
|
|
6060
|
-
const
|
|
6061
|
-
const
|
|
6072
|
+
const { meta = {}, children, ...props } = value;
|
|
6073
|
+
const { inCanvasIs = "Node" } = meta;
|
|
6074
|
+
const Class = customNodes.get(inCanvasIs) ?? Node;
|
|
6075
|
+
const node = new Class({ ...props, meta });
|
|
6062
6076
|
children?.forEach((child) => node.appendChild(this.parse(child)));
|
|
6063
6077
|
return node;
|
|
6064
6078
|
}
|
|
@@ -7100,7 +7114,19 @@ class CanvasContext extends Path2D {
|
|
|
7100
7114
|
if (!this.curves.length) {
|
|
7101
7115
|
return;
|
|
7102
7116
|
}
|
|
7103
|
-
|
|
7117
|
+
let strokeStyle = this.strokeStyle;
|
|
7118
|
+
if (!strokeStyle && this.style.stroke) {
|
|
7119
|
+
switch (typeof this.style.stroke) {
|
|
7120
|
+
case "string":
|
|
7121
|
+
strokeStyle = this.style.stroke;
|
|
7122
|
+
break;
|
|
7123
|
+
case "object":
|
|
7124
|
+
if (isColorFillObject(this.style.stroke)) {
|
|
7125
|
+
strokeStyle = this.style.stroke.color;
|
|
7126
|
+
}
|
|
7127
|
+
break;
|
|
7128
|
+
}
|
|
7129
|
+
}
|
|
7104
7130
|
this._draws.push({
|
|
7105
7131
|
...options,
|
|
7106
7132
|
type: "stroke",
|
|
@@ -7128,7 +7154,19 @@ class CanvasContext extends Path2D {
|
|
|
7128
7154
|
if (!this.curves.length) {
|
|
7129
7155
|
return;
|
|
7130
7156
|
}
|
|
7131
|
-
|
|
7157
|
+
let fillStyle = this.fillStyle;
|
|
7158
|
+
if (!fillStyle && this.style.fill) {
|
|
7159
|
+
switch (typeof this.style.fill) {
|
|
7160
|
+
case "string":
|
|
7161
|
+
fillStyle = this.style.fill;
|
|
7162
|
+
break;
|
|
7163
|
+
case "object":
|
|
7164
|
+
if (isColorFillObject(this.style.fill)) {
|
|
7165
|
+
fillStyle = this.style.fill.color;
|
|
7166
|
+
}
|
|
7167
|
+
break;
|
|
7168
|
+
}
|
|
7169
|
+
}
|
|
7132
7170
|
this._draws.push({
|
|
7133
7171
|
...options,
|
|
7134
7172
|
type: "fill",
|
|
@@ -9273,6 +9311,8 @@ class BaseElement2DText extends CoreObject {
|
|
|
9273
9311
|
switch (args[0]) {
|
|
9274
9312
|
case "content":
|
|
9275
9313
|
case "effects":
|
|
9314
|
+
case "fill":
|
|
9315
|
+
case "outline":
|
|
9276
9316
|
this.setter(args[0], args[1]);
|
|
9277
9317
|
break;
|
|
9278
9318
|
}
|
|
@@ -9289,12 +9329,14 @@ class BaseElement2DText extends CoreObject {
|
|
|
9289
9329
|
_updateProperty(key, value, oldValue, declaration) {
|
|
9290
9330
|
super._updateProperty(key, value, oldValue, declaration);
|
|
9291
9331
|
switch (key) {
|
|
9332
|
+
case "enabled":
|
|
9292
9333
|
case "content":
|
|
9293
9334
|
case "effects":
|
|
9294
|
-
case "
|
|
9335
|
+
case "measureDom":
|
|
9295
9336
|
case "fonts":
|
|
9337
|
+
case "fill":
|
|
9338
|
+
case "outline":
|
|
9296
9339
|
case "split":
|
|
9297
|
-
case "enabled":
|
|
9298
9340
|
this.parent.requestRedraw();
|
|
9299
9341
|
break;
|
|
9300
9342
|
}
|
|
@@ -9345,8 +9387,14 @@ __decorateClass$o([
|
|
|
9345
9387
|
property({ alias: "base.effects" })
|
|
9346
9388
|
], BaseElement2DText.prototype, "effects");
|
|
9347
9389
|
__decorateClass$o([
|
|
9348
|
-
property({
|
|
9349
|
-
], BaseElement2DText.prototype, "
|
|
9390
|
+
property({ alias: "base.fill" })
|
|
9391
|
+
], BaseElement2DText.prototype, "fill");
|
|
9392
|
+
__decorateClass$o([
|
|
9393
|
+
property({ alias: "base.outline" })
|
|
9394
|
+
], BaseElement2DText.prototype, "outline");
|
|
9395
|
+
__decorateClass$o([
|
|
9396
|
+
property({ protected: true, alias: "base.measureDom" })
|
|
9397
|
+
], BaseElement2DText.prototype, "measureDom");
|
|
9350
9398
|
__decorateClass$o([
|
|
9351
9399
|
property({ protected: true, alias: "base.fonts" })
|
|
9352
9400
|
], BaseElement2DText.prototype, "fonts");
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-canvas",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.13",
|
|
5
5
|
"packageManager": "pnpm@9.15.1",
|
|
6
6
|
"description": "A JavaScript WebGL rendering engine.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -70,15 +70,15 @@
|
|
|
70
70
|
"colord": "^2.9.3",
|
|
71
71
|
"earcut": "^3.0.1",
|
|
72
72
|
"modern-font": "^0.4.1",
|
|
73
|
-
"modern-idoc": "^0.8.
|
|
74
|
-
"modern-path2d": "^1.4.
|
|
75
|
-
"modern-text": "^1.
|
|
73
|
+
"modern-idoc": "^0.8.6",
|
|
74
|
+
"modern-path2d": "^1.4.5",
|
|
75
|
+
"modern-text": "^1.7.1",
|
|
76
76
|
"yoga-layout": "^3.2.1"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@antfu/eslint-config": "^4.16.2",
|
|
80
80
|
"@types/earcut": "^3.0.0",
|
|
81
|
-
"@types/node": "^24.0.
|
|
81
|
+
"@types/node": "^24.0.13",
|
|
82
82
|
"bumpp": "^10.2.0",
|
|
83
83
|
"conventional-changelog-cli": "^5.0.0",
|
|
84
84
|
"eslint": "^9.30.1",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"simple-git-hooks": "^2.13.0",
|
|
89
89
|
"typescript": "^5.8.3",
|
|
90
90
|
"unbuild": "^3.5.0",
|
|
91
|
-
"vite": "^7.0.
|
|
91
|
+
"vite": "^7.0.4",
|
|
92
92
|
"vitest": "^3.2.4"
|
|
93
93
|
},
|
|
94
94
|
"simple-git-hooks": {
|