modern-canvas 0.23.7 → 0.23.9
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.js
CHANGED
|
@@ -6692,14 +6692,26 @@ function Di(e) {
|
|
|
6692
6692
|
};
|
|
6693
6693
|
}
|
|
6694
6694
|
function Oi(e, t, n, r, i = {}) {
|
|
6695
|
-
let a = Math.max(1, Math.round(n)), o = Math.max(1, Math.round(r)), s =
|
|
6696
|
-
for (let
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
6701
|
-
|
|
6702
|
-
|
|
6695
|
+
let a = Math.max(1, Math.round(n)), o = Math.max(1, Math.round(r)), s = 0;
|
|
6696
|
+
for (let e of t) {
|
|
6697
|
+
e.outline?.width && e.outline.color && (s = Math.max(s, e.outline.width));
|
|
6698
|
+
let t = Di(e.transform);
|
|
6699
|
+
s = Math.max(s, Math.abs(t.x), Math.abs(t.y));
|
|
6700
|
+
}
|
|
6701
|
+
s = Math.min(Math.ceil(s), Math.floor(Math.min(a, o) * .2));
|
|
6702
|
+
let c = e;
|
|
6703
|
+
if (s > 0) {
|
|
6704
|
+
let t = S(a, o);
|
|
6705
|
+
Ci(t).drawImage(e, s, s, Math.max(1, a - s * 2), Math.max(1, o - s * 2)), c = t;
|
|
6706
|
+
}
|
|
6707
|
+
let l = S(a, o), u = Ci(l);
|
|
6708
|
+
for (let e of t) {
|
|
6709
|
+
let t = c;
|
|
6710
|
+
e.fill && (e.fill.color || e.fill.linearGradient || e.fill.image) && (t = Ti(t, a, o, e.fill, i)), e.outline?.width && e.outline.color && (t = Ei(t, a, o, e.outline.width, e.outline.color));
|
|
6711
|
+
let { x: n, y: r } = Di(e.transform);
|
|
6712
|
+
u.save(), u.globalCompositeOperation = "destination-over", e.shadow && (u.shadowColor = e.shadow.color, u.shadowBlur = e.shadow.blur ?? 0, u.shadowOffsetX = e.shadow.offsetX ?? 0, u.shadowOffsetY = e.shadow.offsetY ?? 0), u.drawImage(t, n, r, a, o), u.restore();
|
|
6713
|
+
}
|
|
6714
|
+
return l;
|
|
6703
6715
|
}
|
|
6704
6716
|
//#endregion
|
|
6705
6717
|
//#region src/scene/2d/element/Element2DForeground.ts
|
|
@@ -6729,14 +6741,27 @@ var ki = class extends J {
|
|
|
6729
6741
|
}
|
|
6730
6742
|
let e = await this._resolveSourceCanvas();
|
|
6731
6743
|
if (!e) return;
|
|
6732
|
-
let t = e.width, n = e.height, r = Oi(e, this.effects, t, n);
|
|
6744
|
+
let t = e.width, n = e.height, r = await this._resolvePatterns(), i = Oi(e, this.effects, t, n, r);
|
|
6733
6745
|
this.texture = new R({
|
|
6734
|
-
source:
|
|
6746
|
+
source: i,
|
|
6735
6747
|
width: t,
|
|
6736
6748
|
height: n,
|
|
6737
6749
|
uploadMethodId: "image"
|
|
6738
6750
|
});
|
|
6739
6751
|
}
|
|
6752
|
+
async _resolvePatterns() {
|
|
6753
|
+
let e = {};
|
|
6754
|
+
for (let t of this.effects ?? []) {
|
|
6755
|
+
let n = t.fill?.image;
|
|
6756
|
+
if (!n || d(n) || e[n]) continue;
|
|
6757
|
+
let r = await $.loadBy(`${n}#mc-foreground-pattern`, async () => {
|
|
6758
|
+
let e = await $.fetchImageBitmap(n), t = this._snapshot(e);
|
|
6759
|
+
return Ne && e instanceof ImageBitmap && e.close(), t;
|
|
6760
|
+
});
|
|
6761
|
+
r && (e[n] = r);
|
|
6762
|
+
}
|
|
6763
|
+
return e;
|
|
6764
|
+
}
|
|
6740
6765
|
async _resolveSourceCanvas() {
|
|
6741
6766
|
if (this._sourceImage !== this.image && (this._sourceCanvas = void 0, this._sourceImage = this.image), this._sourceCanvas) return this._sourceCanvas;
|
|
6742
6767
|
if (d(this.image) || this.image === "viewport") return;
|
|
@@ -25,6 +25,11 @@ export declare class Element2DForeground extends Element2DFill implements Normal
|
|
|
25
25
|
loadTexture(): Promise<void>;
|
|
26
26
|
/** 把原图 + effects 烘焙成一张运行时纹理(gif/无 effects 时跳过) */
|
|
27
27
|
protected _applyEffects(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* 预解码 effects 里 fill.image 用到的图案。烘焙是同步的,图案须先就绪;
|
|
30
|
+
* 按 url 在资源层缓存复用,未提供的图案在烘焙时会被跳过(不重上色)。
|
|
31
|
+
*/
|
|
32
|
+
protected _resolvePatterns(): Promise<Record<string, HTMLCanvasElement>>;
|
|
28
33
|
/**
|
|
29
34
|
* 取得用于烘焙的 CPU 副本:始终从 image 独立解码一份(createImageBitmap 保证解码
|
|
30
35
|
* 就绪),快照进 canvas,按 url 在资源层缓存复用。不读 `this.texture.source`——见
|
|
@@ -5,7 +5,11 @@ type Drawable = CanvasImageSource & {
|
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* 把 `原图 + effects` 烘焙到一张运行时 canvas(不持久化、不转存图片)。
|
|
8
|
-
* 每层按顺序:fill 重上色 → outline 描边 → 按 transform 位移 / shadow
|
|
8
|
+
* 每层按顺序:fill 重上色 → outline 描边 → 按 transform 位移 / shadow 投影后合成。
|
|
9
|
+
*
|
|
10
|
+
* 合成统一用 destination-over:数组按「前 → 后」堆叠(第 0 层在最上,后续依次落到其后),
|
|
11
|
+
* transform translate 只决定该层落点、不改变堆叠次序。于是「原图层 `{}` 在前 + 位移填充层在后」
|
|
12
|
+
* 即得到「主图在上、彩色副本作为阴影/重影偏移到背后」——与来源编辑器的图片样式一致。
|
|
9
13
|
*
|
|
10
14
|
* 注意:图案填充(fill.image)需异步预加载,未在 patterns 中提供则跳过该填充。
|
|
11
15
|
*/
|