modern-canvas 0.8.2 → 0.8.3
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 +121 -51
- package/dist/index.d.cts +6 -7
- package/dist/index.d.mts +6 -7
- package/dist/index.d.ts +6 -7
- package/dist/index.js +38 -38
- package/dist/index.mjs +121 -51
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -870,14 +870,14 @@ class Input extends EventEmitter {
|
|
|
870
870
|
let IID = 0;
|
|
871
871
|
class CoreObject extends EventEmitter {
|
|
872
872
|
instanceId = ++IID;
|
|
873
|
-
|
|
873
|
+
_propertyAccessor;
|
|
874
874
|
_properties = /* @__PURE__ */ new Map();
|
|
875
875
|
_updatedProperties = /* @__PURE__ */ new Map();
|
|
876
876
|
_changedProperties = /* @__PURE__ */ new Set();
|
|
877
877
|
_updatingPromise = Promise.resolve();
|
|
878
878
|
_updating = false;
|
|
879
879
|
useCustomPropertyAccessor(accessor) {
|
|
880
|
-
this.
|
|
880
|
+
this._propertyAccessor = accessor;
|
|
881
881
|
this.getPropertyDeclarations().forEach((declaration, key) => {
|
|
882
882
|
const newValue = accessor.get(key, () => void 0);
|
|
883
883
|
const oldValue = this._properties.get(key);
|
|
@@ -901,15 +901,15 @@ class CoreObject extends EventEmitter {
|
|
|
901
901
|
if (context?.declaration.protected) {
|
|
902
902
|
return this[context.internalKey];
|
|
903
903
|
} else {
|
|
904
|
-
return this.
|
|
904
|
+
return this._propertyAccessor ? this._propertyAccessor.get(key, () => this._properties.get(key)) : this._properties.get(key);
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
907
|
setter(key, value, context) {
|
|
908
908
|
if (context?.declaration.protected) {
|
|
909
909
|
this[context.internalKey] = value;
|
|
910
910
|
} else {
|
|
911
|
-
if (this.
|
|
912
|
-
this.
|
|
911
|
+
if (this._propertyAccessor) {
|
|
912
|
+
this._propertyAccessor.set(key, value);
|
|
913
913
|
}
|
|
914
914
|
this._properties.set(key, value);
|
|
915
915
|
}
|
|
@@ -7259,7 +7259,7 @@ let Node2D = class extends CanvasItem {
|
|
|
7259
7259
|
super._updateProperty(key, value, oldValue, declaration);
|
|
7260
7260
|
switch (key) {
|
|
7261
7261
|
case "rotation":
|
|
7262
|
-
this.
|
|
7262
|
+
this.updateGlobalTransform();
|
|
7263
7263
|
break;
|
|
7264
7264
|
}
|
|
7265
7265
|
}
|
|
@@ -9351,6 +9351,45 @@ ZoomBlurEffect = __decorateClass$t([
|
|
|
9351
9351
|
customNode("ZoomBlurEffect")
|
|
9352
9352
|
], ZoomBlurEffect);
|
|
9353
9353
|
|
|
9354
|
+
function getDrawOptions(fill, size) {
|
|
9355
|
+
let disableWrapMode = false;
|
|
9356
|
+
const { width, height } = size;
|
|
9357
|
+
const uvTransform = new Transform2D().scale(1 / width, 1 / height);
|
|
9358
|
+
if (fill.cropRect) {
|
|
9359
|
+
const {
|
|
9360
|
+
left = 0,
|
|
9361
|
+
top = 0,
|
|
9362
|
+
right = 0,
|
|
9363
|
+
bottom = 0
|
|
9364
|
+
} = fill.cropRect;
|
|
9365
|
+
uvTransform.scale(
|
|
9366
|
+
Math.abs(1 - (left + right)),
|
|
9367
|
+
Math.abs(1 - (top + bottom))
|
|
9368
|
+
).translate(left, top);
|
|
9369
|
+
disableWrapMode = true;
|
|
9370
|
+
}
|
|
9371
|
+
if (fill.tile) {
|
|
9372
|
+
const {
|
|
9373
|
+
translateX = 0,
|
|
9374
|
+
translateY = 0,
|
|
9375
|
+
scaleX = 1,
|
|
9376
|
+
scaleY = 1
|
|
9377
|
+
// flip, TODO
|
|
9378
|
+
// alignment, TODO
|
|
9379
|
+
} = fill.tile;
|
|
9380
|
+
uvTransform.translate(-translateX / width, -translateY / height).scale(1 / scaleX, 1 / scaleY);
|
|
9381
|
+
disableWrapMode = true;
|
|
9382
|
+
} else if (fill.stretchRect) {
|
|
9383
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = fill.stretchRect;
|
|
9384
|
+
uvTransform.scale(
|
|
9385
|
+
Math.abs(1 - (-left + -right)),
|
|
9386
|
+
Math.abs(1 - (-top + -bottom))
|
|
9387
|
+
).translate(-left, -top);
|
|
9388
|
+
disableWrapMode = true;
|
|
9389
|
+
}
|
|
9390
|
+
return { disableWrapMode, uvTransform };
|
|
9391
|
+
}
|
|
9392
|
+
|
|
9354
9393
|
var __defProp$l = Object.defineProperty;
|
|
9355
9394
|
var __decorateClass$s = (decorators, target, key, kind) => {
|
|
9356
9395
|
var result = void 0 ;
|
|
@@ -9417,47 +9456,12 @@ class BaseElement2DFill extends CoreObject {
|
|
|
9417
9456
|
this.enabled && (this._texture || this.color)
|
|
9418
9457
|
);
|
|
9419
9458
|
}
|
|
9420
|
-
_getDrawOptions() {
|
|
9421
|
-
let disableWrapMode = false;
|
|
9422
|
-
const { width, height } = this.parent.size;
|
|
9423
|
-
const uvTransform = new Transform2D().scale(1 / width, 1 / height);
|
|
9424
|
-
if (this.cropRect) {
|
|
9425
|
-
const {
|
|
9426
|
-
left = 0,
|
|
9427
|
-
top = 0,
|
|
9428
|
-
right = 0,
|
|
9429
|
-
bottom = 0
|
|
9430
|
-
} = this.cropRect;
|
|
9431
|
-
uvTransform.scale(
|
|
9432
|
-
Math.abs(1 - (left + right)),
|
|
9433
|
-
Math.abs(1 - (top + bottom))
|
|
9434
|
-
).translate(left, top);
|
|
9435
|
-
disableWrapMode = true;
|
|
9436
|
-
}
|
|
9437
|
-
if (this.tile) {
|
|
9438
|
-
const {
|
|
9439
|
-
translateX = 0,
|
|
9440
|
-
translateY = 0,
|
|
9441
|
-
scaleX = 1,
|
|
9442
|
-
scaleY = 1
|
|
9443
|
-
// flip, TODO
|
|
9444
|
-
// alignment, TODO
|
|
9445
|
-
} = this.tile;
|
|
9446
|
-
uvTransform.translate(-translateX / width, -translateY / height).scale(1 / scaleX, 1 / scaleY);
|
|
9447
|
-
disableWrapMode = true;
|
|
9448
|
-
} else if (this.stretchRect) {
|
|
9449
|
-
const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretchRect;
|
|
9450
|
-
uvTransform.scale(
|
|
9451
|
-
Math.abs(1 - (-left + -right)),
|
|
9452
|
-
Math.abs(1 - (-top + -bottom))
|
|
9453
|
-
).translate(-left, -top);
|
|
9454
|
-
disableWrapMode = true;
|
|
9455
|
-
}
|
|
9456
|
-
return { disableWrapMode, uvTransform };
|
|
9457
|
-
}
|
|
9458
9459
|
draw() {
|
|
9459
9460
|
const ctx = this.parent.context;
|
|
9460
|
-
const { uvTransform, disableWrapMode } =
|
|
9461
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(
|
|
9462
|
+
this,
|
|
9463
|
+
this.parent.size
|
|
9464
|
+
);
|
|
9461
9465
|
ctx.uvTransform = uvTransform;
|
|
9462
9466
|
ctx.fillStyle = this._texture ?? this.color;
|
|
9463
9467
|
ctx.fill({
|
|
@@ -9589,7 +9593,10 @@ class BaseElement2DOutline extends BaseElement2DFill {
|
|
|
9589
9593
|
}
|
|
9590
9594
|
draw() {
|
|
9591
9595
|
const ctx = this.parent.context;
|
|
9592
|
-
const { uvTransform, disableWrapMode } =
|
|
9596
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(
|
|
9597
|
+
this,
|
|
9598
|
+
this.parent.size
|
|
9599
|
+
);
|
|
9593
9600
|
ctx.lineWidth = this.width || 1;
|
|
9594
9601
|
ctx.uvTransform = uvTransform;
|
|
9595
9602
|
ctx.strokeStyle = this._texture ?? this.color;
|
|
@@ -9812,6 +9819,7 @@ class BaseElement2DText extends CoreObject {
|
|
|
9812
9819
|
}
|
|
9813
9820
|
base = new Text();
|
|
9814
9821
|
measureResult;
|
|
9822
|
+
_textures = [];
|
|
9815
9823
|
setProperties(properties) {
|
|
9816
9824
|
return super.setProperties(
|
|
9817
9825
|
isNone(properties) ? void 0 : normalizeText(properties)
|
|
@@ -9825,12 +9833,34 @@ class BaseElement2DText extends CoreObject {
|
|
|
9825
9833
|
case "effects":
|
|
9826
9834
|
case "measureDom":
|
|
9827
9835
|
case "fonts":
|
|
9836
|
+
this.parent.requestRedraw();
|
|
9837
|
+
break;
|
|
9828
9838
|
case "fill":
|
|
9839
|
+
this._updateTexture(0, value);
|
|
9840
|
+
break;
|
|
9829
9841
|
case "outline":
|
|
9830
|
-
this.
|
|
9842
|
+
this._updateTexture(1, value);
|
|
9831
9843
|
break;
|
|
9832
9844
|
}
|
|
9833
9845
|
}
|
|
9846
|
+
async _updateTexture(index, fill) {
|
|
9847
|
+
this._textures[index] = await this._loadTexture(fill);
|
|
9848
|
+
this.parent.requestRedraw();
|
|
9849
|
+
}
|
|
9850
|
+
async _loadTexture(fill) {
|
|
9851
|
+
if (fill.linearGradient || fill.radialGradient) {
|
|
9852
|
+
return new GradientTexture(
|
|
9853
|
+
fill.linearGradient ?? fill.radialGradient,
|
|
9854
|
+
this.parent.size.width,
|
|
9855
|
+
this.parent.size.height
|
|
9856
|
+
);
|
|
9857
|
+
} else if (!isNone(fill.image)) {
|
|
9858
|
+
this.parent.tree?.log(`load image ${fill.image}`);
|
|
9859
|
+
return await assets.texture.load(fill.image);
|
|
9860
|
+
} else {
|
|
9861
|
+
return void 0;
|
|
9862
|
+
}
|
|
9863
|
+
}
|
|
9834
9864
|
setContent(content) {
|
|
9835
9865
|
this.content = normalizeTextContent(content);
|
|
9836
9866
|
}
|
|
@@ -9858,9 +9888,45 @@ class BaseElement2DText extends CoreObject {
|
|
|
9858
9888
|
this.base.update();
|
|
9859
9889
|
this.base.pathSets.forEach((pathSet) => {
|
|
9860
9890
|
pathSet.paths.forEach((path) => {
|
|
9861
|
-
|
|
9862
|
-
|
|
9863
|
-
|
|
9891
|
+
if (path.style.stroke && !isNone(path.style.stroke)) {
|
|
9892
|
+
if (typeof path.style.stroke === "object") {
|
|
9893
|
+
const outline = path.style.stroke;
|
|
9894
|
+
if (outline.enabled !== false && (this._textures[0] || outline.color) && (outline.width === void 0 || outline.width)) {
|
|
9895
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(outline, this.parent.size);
|
|
9896
|
+
ctx.addPath(path);
|
|
9897
|
+
ctx.style = { ...path.style };
|
|
9898
|
+
ctx.lineWidth = outline.width || 1;
|
|
9899
|
+
ctx.uvTransform = uvTransform;
|
|
9900
|
+
ctx.strokeStyle = this._textures[0] ?? outline.color;
|
|
9901
|
+
ctx.lineCap = outline.lineCap;
|
|
9902
|
+
ctx.lineJoin = outline.lineJoin;
|
|
9903
|
+
ctx.stroke({ disableWrapMode });
|
|
9904
|
+
}
|
|
9905
|
+
} else {
|
|
9906
|
+
ctx.addPath(path);
|
|
9907
|
+
ctx.style = { ...path.style };
|
|
9908
|
+
ctx.stroke();
|
|
9909
|
+
}
|
|
9910
|
+
}
|
|
9911
|
+
if (path.style.fill && !isNone(path.style.fill)) {
|
|
9912
|
+
if (typeof path.style.fill === "object") {
|
|
9913
|
+
const fill = path.style.fill;
|
|
9914
|
+
if (fill.enabled !== false && (this._textures[1] || fill.color)) {
|
|
9915
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(fill, this.parent.size);
|
|
9916
|
+
ctx.addPath(path);
|
|
9917
|
+
ctx.style = { ...path.style };
|
|
9918
|
+
ctx.uvTransform = uvTransform;
|
|
9919
|
+
ctx.fillStyle = this._textures[1] ?? fill.color;
|
|
9920
|
+
ctx.fill({
|
|
9921
|
+
disableWrapMode
|
|
9922
|
+
});
|
|
9923
|
+
}
|
|
9924
|
+
} else {
|
|
9925
|
+
ctx.addPath(path);
|
|
9926
|
+
ctx.style = { ...path.style };
|
|
9927
|
+
ctx.fill();
|
|
9928
|
+
}
|
|
9929
|
+
}
|
|
9864
9930
|
});
|
|
9865
9931
|
});
|
|
9866
9932
|
}
|
|
@@ -14255,7 +14321,11 @@ class Engine extends SceneTree {
|
|
|
14255
14321
|
return this.renderer.toPixels();
|
|
14256
14322
|
}
|
|
14257
14323
|
toImageData() {
|
|
14258
|
-
return new ImageData(
|
|
14324
|
+
return new ImageData(
|
|
14325
|
+
this.toPixels(),
|
|
14326
|
+
this.gl.drawingBufferWidth,
|
|
14327
|
+
this.gl.drawingBufferHeight
|
|
14328
|
+
);
|
|
14259
14329
|
}
|
|
14260
14330
|
toCanvas2D() {
|
|
14261
14331
|
const imageData = this.toImageData();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-canvas",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.8.
|
|
4
|
+
"version": "0.8.3",
|
|
5
5
|
"packageManager": "pnpm@9.15.1",
|
|
6
6
|
"description": "A JavaScript WebGL rendering engine.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"@types/node": "^24.3.0",
|
|
85
85
|
"bumpp": "^10.2.3",
|
|
86
86
|
"conventional-changelog-cli": "^5.0.0",
|
|
87
|
-
"eslint": "^9.
|
|
87
|
+
"eslint": "^9.34.0",
|
|
88
88
|
"lint-staged": "^16.1.5",
|
|
89
89
|
"lottie-web": "^5.13.0",
|
|
90
90
|
"modern-gif": "^2.0.4",
|