modern-canvas 0.8.1 → 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 +175 -78
- package/dist/index.d.cts +19 -17
- package/dist/index.d.mts +19 -17
- package/dist/index.d.ts +19 -17
- package/dist/index.js +42 -41
- package/dist/index.mjs +175 -78
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -876,14 +876,14 @@ class Input extends modernIdoc.EventEmitter {
|
|
|
876
876
|
let IID = 0;
|
|
877
877
|
class CoreObject extends modernIdoc.EventEmitter {
|
|
878
878
|
instanceId = ++IID;
|
|
879
|
-
|
|
879
|
+
_propertyAccessor;
|
|
880
880
|
_properties = /* @__PURE__ */ new Map();
|
|
881
881
|
_updatedProperties = /* @__PURE__ */ new Map();
|
|
882
882
|
_changedProperties = /* @__PURE__ */ new Set();
|
|
883
883
|
_updatingPromise = Promise.resolve();
|
|
884
884
|
_updating = false;
|
|
885
885
|
useCustomPropertyAccessor(accessor) {
|
|
886
|
-
this.
|
|
886
|
+
this._propertyAccessor = accessor;
|
|
887
887
|
this.getPropertyDeclarations().forEach((declaration, key) => {
|
|
888
888
|
const newValue = accessor.get(key, () => void 0);
|
|
889
889
|
const oldValue = this._properties.get(key);
|
|
@@ -907,15 +907,15 @@ class CoreObject extends modernIdoc.EventEmitter {
|
|
|
907
907
|
if (context?.declaration.protected) {
|
|
908
908
|
return this[context.internalKey];
|
|
909
909
|
} else {
|
|
910
|
-
return this.
|
|
910
|
+
return this._propertyAccessor ? this._propertyAccessor.get(key, () => this._properties.get(key)) : this._properties.get(key);
|
|
911
911
|
}
|
|
912
912
|
}
|
|
913
913
|
setter(key, value, context) {
|
|
914
914
|
if (context?.declaration.protected) {
|
|
915
915
|
this[context.internalKey] = value;
|
|
916
916
|
} else {
|
|
917
|
-
if (this.
|
|
918
|
-
this.
|
|
917
|
+
if (this._propertyAccessor) {
|
|
918
|
+
this._propertyAccessor.set(key, value);
|
|
919
919
|
}
|
|
920
920
|
this._properties.set(key, value);
|
|
921
921
|
}
|
|
@@ -1124,6 +1124,9 @@ class Color {
|
|
|
1124
1124
|
}
|
|
1125
1125
|
return (alpha * 255 << 24) + (r << 16) + (g << 8) + b;
|
|
1126
1126
|
}
|
|
1127
|
+
toInt8Array() {
|
|
1128
|
+
return [this.r8, this.g8, this.b8, this.a8];
|
|
1129
|
+
}
|
|
1127
1130
|
toArray() {
|
|
1128
1131
|
return [this.r, this.g, this.b, this.a];
|
|
1129
1132
|
}
|
|
@@ -2537,8 +2540,8 @@ class WebGLBatch2DModule extends WebGLModule {
|
|
|
2537
2540
|
_state = WebGLState.for2D();
|
|
2538
2541
|
_batchSize = 4096 * 4;
|
|
2539
2542
|
_drawCallUid = 0;
|
|
2540
|
-
_defaultModulate =
|
|
2541
|
-
_defaultBackgroundColor = 0;
|
|
2543
|
+
_defaultModulate = [255, 255, 255, 255];
|
|
2544
|
+
_defaultBackgroundColor = [0, 0, 0, 0];
|
|
2542
2545
|
_batchables = [];
|
|
2543
2546
|
_vertexCount = 0;
|
|
2544
2547
|
_indexCount = 0;
|
|
@@ -2556,7 +2559,7 @@ class WebGLBatch2DModule extends WebGLModule {
|
|
|
2556
2559
|
// 1
|
|
2557
2560
|
aBackgroundColor: { size: 4, normalized: true, type: "unsigned_byte" },
|
|
2558
2561
|
// 1
|
|
2559
|
-
aDisableWrapMode: { size:
|
|
2562
|
+
aDisableWrapMode: { size: 1, normalized: true, type: "float" }
|
|
2560
2563
|
// 1
|
|
2561
2564
|
};
|
|
2562
2565
|
_vertexSize = 1 + 2 + 2 + 1 + 1 + 1;
|
|
@@ -2576,7 +2579,7 @@ attribute vec2 aPosition;
|
|
|
2576
2579
|
attribute vec2 aUv;
|
|
2577
2580
|
attribute vec4 aModulate;
|
|
2578
2581
|
attribute vec4 aBackgroundColor;
|
|
2579
|
-
attribute
|
|
2582
|
+
attribute float aDisableWrapMode;
|
|
2580
2583
|
|
|
2581
2584
|
uniform mat3 projectionMatrix;
|
|
2582
2585
|
uniform mat3 viewMatrix;
|
|
@@ -2588,7 +2591,7 @@ varying float vTextureId;
|
|
|
2588
2591
|
varying vec2 vUv;
|
|
2589
2592
|
varying vec4 vModulate;
|
|
2590
2593
|
varying vec4 vBackgroundColor;
|
|
2591
|
-
varying
|
|
2594
|
+
varying float vDisableWrapMode;
|
|
2592
2595
|
|
|
2593
2596
|
vec2 roundPixels(vec2 position, vec2 targetSize) {
|
|
2594
2597
|
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
@@ -2603,6 +2606,7 @@ void main(void) {
|
|
|
2603
2606
|
vTextureId = aTextureId;
|
|
2604
2607
|
vec3 pos = projectionMatrix * viewMatrix * modelMatrix * vec3(aPosition, 1.0);
|
|
2605
2608
|
gl_Position = vec4(roundPixels(pos.xy, vec2(canvasWidth, canvasHeight)), 0.0, 1.0);
|
|
2609
|
+
// gl_Position = vec4(pos.xy, 0.0, 1.0);
|
|
2606
2610
|
|
|
2607
2611
|
vUv = aUv;
|
|
2608
2612
|
vModulate = aModulate * modulate;
|
|
@@ -2614,20 +2618,20 @@ varying float vTextureId;
|
|
|
2614
2618
|
varying vec2 vUv;
|
|
2615
2619
|
varying vec4 vModulate;
|
|
2616
2620
|
varying vec4 vBackgroundColor;
|
|
2617
|
-
varying
|
|
2621
|
+
varying float vDisableWrapMode;
|
|
2618
2622
|
|
|
2619
2623
|
uniform sampler2D samplers[${maxTextureUnits}];
|
|
2620
2624
|
|
|
2621
2625
|
void main(void) {
|
|
2622
|
-
vec4 color;
|
|
2623
|
-
if (vDisableWrapMode
|
|
2626
|
+
vec4 color = vec4(0.0, 0.0, 0.0, 0.0);
|
|
2627
|
+
if (vDisableWrapMode > 0.0 && (vUv.x < 0.0 || vUv.y < 0.0 || vUv.x > 1.0 || vUv.y > 1.0))
|
|
2624
2628
|
{
|
|
2625
|
-
|
|
2629
|
+
//
|
|
2626
2630
|
}
|
|
2627
2631
|
else
|
|
2628
2632
|
if (vTextureId < 0.0)
|
|
2629
2633
|
{
|
|
2630
|
-
|
|
2634
|
+
//
|
|
2631
2635
|
}${Array.from({ length: maxTextureUnits }, (_, i) => {
|
|
2632
2636
|
let text = " ";
|
|
2633
2637
|
if (i >= 0) {
|
|
@@ -2721,7 +2725,7 @@ void main(void) {
|
|
|
2721
2725
|
const textureMaxUnits = this._renderer.texture.maxUnits;
|
|
2722
2726
|
const attributeBuffer = this._getAttributeBuffer(vertexCount);
|
|
2723
2727
|
const float32View = new Float32Array(attributeBuffer);
|
|
2724
|
-
const
|
|
2728
|
+
const uint8View = new Uint8Array(attributeBuffer);
|
|
2725
2729
|
const indexBuffer = this._getIndexBuffer(indexCount);
|
|
2726
2730
|
let aIndex = 0;
|
|
2727
2731
|
let iIndex = 0;
|
|
@@ -2762,7 +2766,7 @@ void main(void) {
|
|
|
2762
2766
|
drawCall.first = iIndex;
|
|
2763
2767
|
}
|
|
2764
2768
|
const iIndexStart = aIndex / this._vertexSize;
|
|
2765
|
-
const textureLocation = (texture2 ? textureLocationMap.get(texture2) :
|
|
2769
|
+
const textureLocation = (texture2 ? textureLocationMap.get(texture2) : -1) ?? -1;
|
|
2766
2770
|
const disableWrapModeInt = disableWrapMode ? 1 : 0;
|
|
2767
2771
|
for (let len2 = vertices.length, i2 = 0; i2 < len2; i2 += 2) {
|
|
2768
2772
|
float32View[aIndex++] = textureLocation;
|
|
@@ -2770,9 +2774,23 @@ void main(void) {
|
|
|
2770
2774
|
float32View[aIndex++] = vertices[i2 + 1];
|
|
2771
2775
|
float32View[aIndex++] = uvs[i2];
|
|
2772
2776
|
float32View[aIndex++] = uvs[i2 + 1];
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2777
|
+
if (modulate) {
|
|
2778
|
+
const aU8Index = aIndex * 4;
|
|
2779
|
+
uint8View[aU8Index] = modulate[0];
|
|
2780
|
+
uint8View[aU8Index + 1] = modulate[1];
|
|
2781
|
+
uint8View[aU8Index + 2] = modulate[2];
|
|
2782
|
+
uint8View[aU8Index + 3] = modulate[3];
|
|
2783
|
+
}
|
|
2784
|
+
aIndex++;
|
|
2785
|
+
if (backgroundColor) {
|
|
2786
|
+
const aU8Index = aIndex * 4;
|
|
2787
|
+
uint8View[aU8Index] = backgroundColor[0];
|
|
2788
|
+
uint8View[aU8Index + 1] = backgroundColor[1];
|
|
2789
|
+
uint8View[aU8Index + 2] = backgroundColor[2];
|
|
2790
|
+
uint8View[aU8Index + 3] = backgroundColor[3];
|
|
2791
|
+
}
|
|
2792
|
+
aIndex++;
|
|
2793
|
+
float32View[aIndex++] = disableWrapModeInt;
|
|
2776
2794
|
}
|
|
2777
2795
|
for (let len2 = indices.length, i2 = 0; i2 < len2; i2++) {
|
|
2778
2796
|
indexBuffer[iIndex++] = iIndexStart + indices[i2];
|
|
@@ -5557,14 +5575,20 @@ class CanvasContext extends modernPath2d.Path2D {
|
|
|
5557
5575
|
// custom
|
|
5558
5576
|
uvTransform;
|
|
5559
5577
|
vertTransform;
|
|
5560
|
-
_defaultStyle = Texture2D.EMPTY;
|
|
5561
5578
|
_draws = [];
|
|
5562
|
-
|
|
5563
|
-
if (source
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
|
|
5579
|
+
_parseDrawStyle(source) {
|
|
5580
|
+
if (source) {
|
|
5581
|
+
if (source instanceof Texture2D) {
|
|
5582
|
+
return {
|
|
5583
|
+
texture: source
|
|
5584
|
+
};
|
|
5585
|
+
} else {
|
|
5586
|
+
return {
|
|
5587
|
+
backgroundColor: new Color(source).toInt8Array()
|
|
5588
|
+
};
|
|
5589
|
+
}
|
|
5567
5590
|
}
|
|
5591
|
+
return {};
|
|
5568
5592
|
}
|
|
5569
5593
|
stroke(options) {
|
|
5570
5594
|
if (!this.curves.length) {
|
|
@@ -5585,12 +5609,12 @@ class CanvasContext extends modernPath2d.Path2D {
|
|
|
5585
5609
|
}
|
|
5586
5610
|
this._draws.push({
|
|
5587
5611
|
...options,
|
|
5612
|
+
...this._parseDrawStyle(strokeStyle),
|
|
5588
5613
|
type: "stroke",
|
|
5589
5614
|
path: new modernPath2d.Path2D(this),
|
|
5590
|
-
texture: strokeStyle ? this._toTexture(strokeStyle) : this._defaultStyle,
|
|
5591
5615
|
uvTransform: this.uvTransform,
|
|
5592
5616
|
vertTransform: this.vertTransform,
|
|
5593
|
-
|
|
5617
|
+
lineStyle: {
|
|
5594
5618
|
alignment: this.strokeAlignment ?? 0.5,
|
|
5595
5619
|
cap: this.lineCap ?? "butt",
|
|
5596
5620
|
join: this.lineJoin ?? "miter",
|
|
@@ -5625,9 +5649,9 @@ class CanvasContext extends modernPath2d.Path2D {
|
|
|
5625
5649
|
}
|
|
5626
5650
|
this._draws.push({
|
|
5627
5651
|
...options,
|
|
5652
|
+
...this._parseDrawStyle(fillStyle),
|
|
5628
5653
|
type: "fill",
|
|
5629
5654
|
path: new modernPath2d.Path2D(this),
|
|
5630
|
-
texture: fillStyle ? this._toTexture(fillStyle) : this._defaultStyle,
|
|
5631
5655
|
uvTransform: this.uvTransform,
|
|
5632
5656
|
vertTransform: this.vertTransform
|
|
5633
5657
|
});
|
|
@@ -5703,17 +5727,20 @@ class CanvasContext extends modernPath2d.Path2D {
|
|
|
5703
5727
|
current.path.strokeTriangulate({
|
|
5704
5728
|
vertices,
|
|
5705
5729
|
indices,
|
|
5706
|
-
lineStyle: current.
|
|
5730
|
+
lineStyle: current.lineStyle,
|
|
5707
5731
|
flipAlignment: false,
|
|
5708
5732
|
closed: true
|
|
5709
5733
|
});
|
|
5710
5734
|
}
|
|
5711
|
-
|
|
5735
|
+
if (current.texture) {
|
|
5736
|
+
this.buildUvs(0, vertices, uvs, current.texture, current.uvTransform);
|
|
5737
|
+
}
|
|
5712
5738
|
batchables.push({
|
|
5713
5739
|
vertices: new Float32Array(vertices),
|
|
5714
5740
|
indices: new Float32Array(indices),
|
|
5715
5741
|
uvs: new Float32Array(uvs),
|
|
5716
5742
|
texture: current.texture,
|
|
5743
|
+
backgroundColor: current.backgroundColor,
|
|
5717
5744
|
type: current.type,
|
|
5718
5745
|
disableWrapMode: current.disableWrapMode,
|
|
5719
5746
|
vertTransform: current.vertTransform
|
|
@@ -6485,7 +6512,7 @@ exports.CanvasItem = class CanvasItem extends exports.TimelineNode {
|
|
|
6485
6512
|
return batchables.map((batchable) => {
|
|
6486
6513
|
return {
|
|
6487
6514
|
...batchable,
|
|
6488
|
-
modulate: this._modulate.
|
|
6515
|
+
modulate: this._modulate.toInt8Array(),
|
|
6489
6516
|
blendMode: this.blendMode
|
|
6490
6517
|
};
|
|
6491
6518
|
});
|
|
@@ -7238,7 +7265,7 @@ exports.Node2D = class Node2D extends exports.CanvasItem {
|
|
|
7238
7265
|
super._updateProperty(key, value, oldValue, declaration);
|
|
7239
7266
|
switch (key) {
|
|
7240
7267
|
case "rotation":
|
|
7241
|
-
this.
|
|
7268
|
+
this.updateGlobalTransform();
|
|
7242
7269
|
break;
|
|
7243
7270
|
}
|
|
7244
7271
|
}
|
|
@@ -9330,6 +9357,45 @@ exports.ZoomBlurEffect = __decorateClass$t([
|
|
|
9330
9357
|
customNode("ZoomBlurEffect")
|
|
9331
9358
|
], exports.ZoomBlurEffect);
|
|
9332
9359
|
|
|
9360
|
+
function getDrawOptions(fill, size) {
|
|
9361
|
+
let disableWrapMode = false;
|
|
9362
|
+
const { width, height } = size;
|
|
9363
|
+
const uvTransform = new Transform2D().scale(1 / width, 1 / height);
|
|
9364
|
+
if (fill.cropRect) {
|
|
9365
|
+
const {
|
|
9366
|
+
left = 0,
|
|
9367
|
+
top = 0,
|
|
9368
|
+
right = 0,
|
|
9369
|
+
bottom = 0
|
|
9370
|
+
} = fill.cropRect;
|
|
9371
|
+
uvTransform.scale(
|
|
9372
|
+
Math.abs(1 - (left + right)),
|
|
9373
|
+
Math.abs(1 - (top + bottom))
|
|
9374
|
+
).translate(left, top);
|
|
9375
|
+
disableWrapMode = true;
|
|
9376
|
+
}
|
|
9377
|
+
if (fill.tile) {
|
|
9378
|
+
const {
|
|
9379
|
+
translateX = 0,
|
|
9380
|
+
translateY = 0,
|
|
9381
|
+
scaleX = 1,
|
|
9382
|
+
scaleY = 1
|
|
9383
|
+
// flip, TODO
|
|
9384
|
+
// alignment, TODO
|
|
9385
|
+
} = fill.tile;
|
|
9386
|
+
uvTransform.translate(-translateX / width, -translateY / height).scale(1 / scaleX, 1 / scaleY);
|
|
9387
|
+
disableWrapMode = true;
|
|
9388
|
+
} else if (fill.stretchRect) {
|
|
9389
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = fill.stretchRect;
|
|
9390
|
+
uvTransform.scale(
|
|
9391
|
+
Math.abs(1 - (-left + -right)),
|
|
9392
|
+
Math.abs(1 - (-top + -bottom))
|
|
9393
|
+
).translate(-left, -top);
|
|
9394
|
+
disableWrapMode = true;
|
|
9395
|
+
}
|
|
9396
|
+
return { disableWrapMode, uvTransform };
|
|
9397
|
+
}
|
|
9398
|
+
|
|
9333
9399
|
var __defProp$l = Object.defineProperty;
|
|
9334
9400
|
var __decorateClass$s = (decorators, target, key, kind) => {
|
|
9335
9401
|
var result = void 0 ;
|
|
@@ -9396,47 +9462,12 @@ class BaseElement2DFill extends CoreObject {
|
|
|
9396
9462
|
this.enabled && (this._texture || this.color)
|
|
9397
9463
|
);
|
|
9398
9464
|
}
|
|
9399
|
-
_getDrawOptions() {
|
|
9400
|
-
let disableWrapMode = false;
|
|
9401
|
-
const { width, height } = this.parent.size;
|
|
9402
|
-
const uvTransform = new Transform2D().scale(1 / width, 1 / height);
|
|
9403
|
-
if (this.cropRect) {
|
|
9404
|
-
const {
|
|
9405
|
-
left = 0,
|
|
9406
|
-
top = 0,
|
|
9407
|
-
right = 0,
|
|
9408
|
-
bottom = 0
|
|
9409
|
-
} = this.cropRect;
|
|
9410
|
-
uvTransform.scale(
|
|
9411
|
-
Math.abs(1 - (left + right)),
|
|
9412
|
-
Math.abs(1 - (top + bottom))
|
|
9413
|
-
).translate(left, top);
|
|
9414
|
-
disableWrapMode = true;
|
|
9415
|
-
}
|
|
9416
|
-
if (this.tile) {
|
|
9417
|
-
const {
|
|
9418
|
-
translateX = 0,
|
|
9419
|
-
translateY = 0,
|
|
9420
|
-
scaleX = 1,
|
|
9421
|
-
scaleY = 1
|
|
9422
|
-
// flip, TODO
|
|
9423
|
-
// alignment, TODO
|
|
9424
|
-
} = this.tile;
|
|
9425
|
-
uvTransform.translate(-translateX / width, -translateY / height).scale(1 / scaleX, 1 / scaleY);
|
|
9426
|
-
disableWrapMode = true;
|
|
9427
|
-
} else if (this.stretchRect) {
|
|
9428
|
-
const { left = 0, top = 0, right = 0, bottom = 0 } = this.stretchRect;
|
|
9429
|
-
uvTransform.scale(
|
|
9430
|
-
Math.abs(1 - (-left + -right)),
|
|
9431
|
-
Math.abs(1 - (-top + -bottom))
|
|
9432
|
-
).translate(-left, -top);
|
|
9433
|
-
disableWrapMode = true;
|
|
9434
|
-
}
|
|
9435
|
-
return { disableWrapMode, uvTransform };
|
|
9436
|
-
}
|
|
9437
9465
|
draw() {
|
|
9438
9466
|
const ctx = this.parent.context;
|
|
9439
|
-
const { uvTransform, disableWrapMode } =
|
|
9467
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(
|
|
9468
|
+
this,
|
|
9469
|
+
this.parent.size
|
|
9470
|
+
);
|
|
9440
9471
|
ctx.uvTransform = uvTransform;
|
|
9441
9472
|
ctx.fillStyle = this._texture ?? this.color;
|
|
9442
9473
|
ctx.fill({
|
|
@@ -9568,7 +9599,10 @@ class BaseElement2DOutline extends BaseElement2DFill {
|
|
|
9568
9599
|
}
|
|
9569
9600
|
draw() {
|
|
9570
9601
|
const ctx = this.parent.context;
|
|
9571
|
-
const { uvTransform, disableWrapMode } =
|
|
9602
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(
|
|
9603
|
+
this,
|
|
9604
|
+
this.parent.size
|
|
9605
|
+
);
|
|
9572
9606
|
ctx.lineWidth = this.width || 1;
|
|
9573
9607
|
ctx.uvTransform = uvTransform;
|
|
9574
9608
|
ctx.strokeStyle = this._texture ?? this.color;
|
|
@@ -9791,6 +9825,7 @@ class BaseElement2DText extends CoreObject {
|
|
|
9791
9825
|
}
|
|
9792
9826
|
base = new modernText.Text();
|
|
9793
9827
|
measureResult;
|
|
9828
|
+
_textures = [];
|
|
9794
9829
|
setProperties(properties) {
|
|
9795
9830
|
return super.setProperties(
|
|
9796
9831
|
modernIdoc.isNone(properties) ? void 0 : modernIdoc.normalizeText(properties)
|
|
@@ -9804,12 +9839,34 @@ class BaseElement2DText extends CoreObject {
|
|
|
9804
9839
|
case "effects":
|
|
9805
9840
|
case "measureDom":
|
|
9806
9841
|
case "fonts":
|
|
9842
|
+
this.parent.requestRedraw();
|
|
9843
|
+
break;
|
|
9807
9844
|
case "fill":
|
|
9845
|
+
this._updateTexture(0, value);
|
|
9846
|
+
break;
|
|
9808
9847
|
case "outline":
|
|
9809
|
-
this.
|
|
9848
|
+
this._updateTexture(1, value);
|
|
9810
9849
|
break;
|
|
9811
9850
|
}
|
|
9812
9851
|
}
|
|
9852
|
+
async _updateTexture(index, fill) {
|
|
9853
|
+
this._textures[index] = await this._loadTexture(fill);
|
|
9854
|
+
this.parent.requestRedraw();
|
|
9855
|
+
}
|
|
9856
|
+
async _loadTexture(fill) {
|
|
9857
|
+
if (fill.linearGradient || fill.radialGradient) {
|
|
9858
|
+
return new GradientTexture(
|
|
9859
|
+
fill.linearGradient ?? fill.radialGradient,
|
|
9860
|
+
this.parent.size.width,
|
|
9861
|
+
this.parent.size.height
|
|
9862
|
+
);
|
|
9863
|
+
} else if (!modernIdoc.isNone(fill.image)) {
|
|
9864
|
+
this.parent.tree?.log(`load image ${fill.image}`);
|
|
9865
|
+
return await assets.texture.load(fill.image);
|
|
9866
|
+
} else {
|
|
9867
|
+
return void 0;
|
|
9868
|
+
}
|
|
9869
|
+
}
|
|
9813
9870
|
setContent(content) {
|
|
9814
9871
|
this.content = modernIdoc.normalizeTextContent(content);
|
|
9815
9872
|
}
|
|
@@ -9837,9 +9894,45 @@ class BaseElement2DText extends CoreObject {
|
|
|
9837
9894
|
this.base.update();
|
|
9838
9895
|
this.base.pathSets.forEach((pathSet) => {
|
|
9839
9896
|
pathSet.paths.forEach((path) => {
|
|
9840
|
-
|
|
9841
|
-
|
|
9842
|
-
|
|
9897
|
+
if (path.style.stroke && !modernIdoc.isNone(path.style.stroke)) {
|
|
9898
|
+
if (typeof path.style.stroke === "object") {
|
|
9899
|
+
const outline = path.style.stroke;
|
|
9900
|
+
if (outline.enabled !== false && (this._textures[0] || outline.color) && (outline.width === void 0 || outline.width)) {
|
|
9901
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(outline, this.parent.size);
|
|
9902
|
+
ctx.addPath(path);
|
|
9903
|
+
ctx.style = { ...path.style };
|
|
9904
|
+
ctx.lineWidth = outline.width || 1;
|
|
9905
|
+
ctx.uvTransform = uvTransform;
|
|
9906
|
+
ctx.strokeStyle = this._textures[0] ?? outline.color;
|
|
9907
|
+
ctx.lineCap = outline.lineCap;
|
|
9908
|
+
ctx.lineJoin = outline.lineJoin;
|
|
9909
|
+
ctx.stroke({ disableWrapMode });
|
|
9910
|
+
}
|
|
9911
|
+
} else {
|
|
9912
|
+
ctx.addPath(path);
|
|
9913
|
+
ctx.style = { ...path.style };
|
|
9914
|
+
ctx.stroke();
|
|
9915
|
+
}
|
|
9916
|
+
}
|
|
9917
|
+
if (path.style.fill && !modernIdoc.isNone(path.style.fill)) {
|
|
9918
|
+
if (typeof path.style.fill === "object") {
|
|
9919
|
+
const fill = path.style.fill;
|
|
9920
|
+
if (fill.enabled !== false && (this._textures[1] || fill.color)) {
|
|
9921
|
+
const { uvTransform, disableWrapMode } = getDrawOptions(fill, this.parent.size);
|
|
9922
|
+
ctx.addPath(path);
|
|
9923
|
+
ctx.style = { ...path.style };
|
|
9924
|
+
ctx.uvTransform = uvTransform;
|
|
9925
|
+
ctx.fillStyle = this._textures[1] ?? fill.color;
|
|
9926
|
+
ctx.fill({
|
|
9927
|
+
disableWrapMode
|
|
9928
|
+
});
|
|
9929
|
+
}
|
|
9930
|
+
} else {
|
|
9931
|
+
ctx.addPath(path);
|
|
9932
|
+
ctx.style = { ...path.style };
|
|
9933
|
+
ctx.fill();
|
|
9934
|
+
}
|
|
9935
|
+
}
|
|
9843
9936
|
});
|
|
9844
9937
|
});
|
|
9845
9938
|
}
|
|
@@ -14234,7 +14327,11 @@ class Engine extends SceneTree {
|
|
|
14234
14327
|
return this.renderer.toPixels();
|
|
14235
14328
|
}
|
|
14236
14329
|
toImageData() {
|
|
14237
|
-
return new ImageData(
|
|
14330
|
+
return new ImageData(
|
|
14331
|
+
this.toPixels(),
|
|
14332
|
+
this.gl.drawingBufferWidth,
|
|
14333
|
+
this.gl.drawingBufferHeight
|
|
14334
|
+
);
|
|
14238
14335
|
}
|
|
14239
14336
|
toCanvas2D() {
|
|
14240
14337
|
const imageData = this.toImageData();
|
package/dist/index.d.cts
CHANGED
|
@@ -260,7 +260,7 @@ interface CoreObject {
|
|
|
260
260
|
}
|
|
261
261
|
declare class CoreObject extends EventEmitter implements Required<ReactiveObject> {
|
|
262
262
|
readonly instanceId: number;
|
|
263
|
-
protected
|
|
263
|
+
protected _propertyAccessor?: CustomPropertyAccessor;
|
|
264
264
|
protected _properties: Map<string, unknown>;
|
|
265
265
|
protected _updatedProperties: Map<string, unknown>;
|
|
266
266
|
protected _changedProperties: Set<string>;
|
|
@@ -335,6 +335,7 @@ declare class Color {
|
|
|
335
335
|
toHslString(): string;
|
|
336
336
|
toHsv(): HsvaColor;
|
|
337
337
|
toArgb(alpha?: number, applyToRGB?: boolean): number;
|
|
338
|
+
toInt8Array(): [number, number, number, number];
|
|
338
339
|
toArray(): [number, number, number, number];
|
|
339
340
|
}
|
|
340
341
|
|
|
@@ -893,7 +894,7 @@ declare class WebGLRenderer extends Renderer {
|
|
|
893
894
|
reset(): void;
|
|
894
895
|
flush(): void;
|
|
895
896
|
free(): void;
|
|
896
|
-
toPixels(x?: number, y?: number, width?: number, height?: number): Uint8ClampedArray
|
|
897
|
+
toPixels(x?: number, y?: number, width?: number, height?: number): Uint8ClampedArray<ArrayBuffer>;
|
|
897
898
|
}
|
|
898
899
|
|
|
899
900
|
interface Renderable {
|
|
@@ -979,13 +980,13 @@ interface Batchable2D {
|
|
|
979
980
|
indices: Float32Array;
|
|
980
981
|
uvs?: Float32Array;
|
|
981
982
|
texture?: WebGLTexture;
|
|
982
|
-
backgroundColor?: number;
|
|
983
|
-
modulate?: number;
|
|
983
|
+
backgroundColor?: number[];
|
|
984
|
+
modulate?: number[];
|
|
984
985
|
blendMode?: WebGLBlendMode;
|
|
985
986
|
disableWrapMode?: boolean;
|
|
986
987
|
}
|
|
987
988
|
interface Shader {
|
|
988
|
-
update: (attributeBuffer: ArrayBuffer, indexBuffer: Uint16Array) => void;
|
|
989
|
+
update: (attributeBuffer: ArrayBuffer, indexBuffer: Uint16Array<ArrayBuffer>) => void;
|
|
989
990
|
draw: (options?: WebGLDrawOptions) => void;
|
|
990
991
|
}
|
|
991
992
|
declare class WebGLBatch2DModule extends WebGLModule {
|
|
@@ -993,13 +994,13 @@ declare class WebGLBatch2DModule extends WebGLModule {
|
|
|
993
994
|
protected _state: WebGLState;
|
|
994
995
|
protected _batchSize: number;
|
|
995
996
|
protected _drawCallUid: number;
|
|
996
|
-
protected _defaultModulate: number;
|
|
997
|
-
protected _defaultBackgroundColor: number;
|
|
997
|
+
protected _defaultModulate: number[];
|
|
998
|
+
protected _defaultBackgroundColor: number[];
|
|
998
999
|
protected _batchables: Batchable2D[];
|
|
999
1000
|
protected _vertexCount: number;
|
|
1000
1001
|
protected _indexCount: number;
|
|
1001
1002
|
protected _attributeBuffer: ArrayBuffer[];
|
|
1002
|
-
protected _indexBuffers: Uint16Array[];
|
|
1003
|
+
protected _indexBuffers: Uint16Array<ArrayBuffer>[];
|
|
1003
1004
|
protected _shaders: Map<number, Shader>;
|
|
1004
1005
|
protected _attributes: Record<string, Partial<WebGLVertexAttrib>>;
|
|
1005
1006
|
protected _vertexSize: number;
|
|
@@ -1019,7 +1020,7 @@ declare class WebGLBatch2DModule extends WebGLModule {
|
|
|
1019
1020
|
* @param size - minimum required capacity
|
|
1020
1021
|
* @returns - buffer that can fit `size` indices.
|
|
1021
1022
|
*/
|
|
1022
|
-
protected _getIndexBuffer(size: number): Uint16Array
|
|
1023
|
+
protected _getIndexBuffer(size: number): Uint16Array<ArrayBuffer>;
|
|
1023
1024
|
}
|
|
1024
1025
|
/**
|
|
1025
1026
|
* Rounds to next power of two.
|
|
@@ -1472,7 +1473,7 @@ interface CanvasBatchable extends Batchable2D {
|
|
|
1472
1473
|
interface StrokeDraw extends Partial<CanvasBatchable> {
|
|
1473
1474
|
type: 'stroke';
|
|
1474
1475
|
path: Path2D;
|
|
1475
|
-
|
|
1476
|
+
lineStyle: LineStyle;
|
|
1476
1477
|
uvTransform?: UvTransform;
|
|
1477
1478
|
}
|
|
1478
1479
|
interface FillDraw extends Partial<CanvasBatchable> {
|
|
@@ -1490,9 +1491,11 @@ declare class CanvasContext extends Path2D {
|
|
|
1490
1491
|
miterLimit?: number;
|
|
1491
1492
|
uvTransform?: UvTransform;
|
|
1492
1493
|
vertTransform?: VertTransform;
|
|
1493
|
-
protected _defaultStyle: Texture2D<Texture2DSource>;
|
|
1494
1494
|
protected _draws: (StrokeDraw | FillDraw)[];
|
|
1495
|
-
protected
|
|
1495
|
+
protected _parseDrawStyle(source?: Color$1 | Texture2D): {
|
|
1496
|
+
texture?: Texture2D;
|
|
1497
|
+
backgroundColor?: number[];
|
|
1498
|
+
};
|
|
1496
1499
|
stroke(options?: Partial<StrokeDraw>): void;
|
|
1497
1500
|
fillRect(x: number, y: number, width: number, height: number): void;
|
|
1498
1501
|
strokeRect(x: number, y: number, width: number, height: number): void;
|
|
@@ -2012,10 +2015,6 @@ declare class BaseElement2DFill extends CoreObject {
|
|
|
2012
2015
|
loadTexture(): Promise<Texture2D | undefined>;
|
|
2013
2016
|
protected _updateTexture(): Promise<void>;
|
|
2014
2017
|
canDraw(): boolean;
|
|
2015
|
-
protected _getDrawOptions(): {
|
|
2016
|
-
disableWrapMode: boolean;
|
|
2017
|
-
uvTransform: Transform2D;
|
|
2018
|
-
};
|
|
2019
2018
|
draw(): void;
|
|
2020
2019
|
}
|
|
2021
2020
|
|
|
@@ -2095,9 +2094,12 @@ declare class BaseElement2DText extends CoreObject {
|
|
|
2095
2094
|
fonts: Text['fonts'];
|
|
2096
2095
|
readonly base: Text;
|
|
2097
2096
|
measureResult?: MeasureResult;
|
|
2097
|
+
protected _textures: (Texture2D | undefined)[];
|
|
2098
2098
|
constructor(parent: BaseElement2D);
|
|
2099
2099
|
setProperties(properties?: Text$1): this;
|
|
2100
2100
|
protected _updateProperty(key: string, value: any, oldValue: any, declaration?: PropertyDeclaration): void;
|
|
2101
|
+
protected _updateTexture(index: number, fill: NormalizedFill): Promise<void>;
|
|
2102
|
+
protected _loadTexture(fill: NormalizedFill): Promise<Texture2D | undefined>;
|
|
2101
2103
|
setContent(content: TextContent): void;
|
|
2102
2104
|
measure(): MeasureResult;
|
|
2103
2105
|
updateMeasure(): this;
|
|
@@ -3366,7 +3368,7 @@ declare class Engine extends SceneTree {
|
|
|
3366
3368
|
render(delta?: number): void;
|
|
3367
3369
|
start(): Promise<void>;
|
|
3368
3370
|
free(): void;
|
|
3369
|
-
toPixels(): Uint8ClampedArray
|
|
3371
|
+
toPixels(): Uint8ClampedArray<ArrayBuffer>;
|
|
3370
3372
|
toImageData(): ImageData;
|
|
3371
3373
|
toCanvas2D(): HTMLCanvasElement;
|
|
3372
3374
|
}
|