modern-canvas 0.23.3 → 0.23.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.js
CHANGED
|
@@ -6720,23 +6720,21 @@ var ki = class extends J {
|
|
|
6720
6720
|
let e = await this._resolveSourceCanvas();
|
|
6721
6721
|
if (!e) return;
|
|
6722
6722
|
let t = e.width, n = e.height, r = Oi(e, this.effects, t, n);
|
|
6723
|
-
this.texture = new
|
|
6723
|
+
this.texture = new R({
|
|
6724
6724
|
source: r,
|
|
6725
6725
|
width: t,
|
|
6726
|
-
height: n
|
|
6726
|
+
height: n,
|
|
6727
|
+
uploadMethodId: "image"
|
|
6727
6728
|
});
|
|
6728
6729
|
}
|
|
6729
6730
|
async _resolveSourceCanvas() {
|
|
6730
|
-
this._sourceImage !== this.image && (this._sourceCanvas = void 0, this._sourceImage = this.image);
|
|
6731
|
-
let e = this.texture?.source;
|
|
6732
|
-
if (e && e.width > 0 && e.height > 0) return this._sourceCanvas = this._snapshot(e);
|
|
6733
|
-
if (this._sourceCanvas) return this._sourceCanvas;
|
|
6731
|
+
if (this._sourceImage !== this.image && (this._sourceCanvas = void 0, this._sourceImage = this.image), this._sourceCanvas) return this._sourceCanvas;
|
|
6734
6732
|
if (d(this.image) || this.image === "viewport") return;
|
|
6735
|
-
let
|
|
6736
|
-
let
|
|
6737
|
-
return Ne &&
|
|
6733
|
+
let e = this.image, t = await $.loadBy(`${e}#mc-foreground-source`, async () => {
|
|
6734
|
+
let t = await $.fetchImageBitmap(e), n = this._snapshot(t);
|
|
6735
|
+
return Ne && t instanceof ImageBitmap && t.close(), n;
|
|
6738
6736
|
});
|
|
6739
|
-
return this._sourceImage === t && (this._sourceCanvas =
|
|
6737
|
+
return this._sourceImage === e && t && (this._sourceCanvas = t), t;
|
|
6740
6738
|
}
|
|
6741
6739
|
_snapshot(e) {
|
|
6742
6740
|
let t = Math.max(1, Math.round(e.width)), n = Math.max(1, Math.round(e.height)), r = S(t, n), i = r?.getContext("2d");
|
|
@@ -11,10 +11,11 @@ export declare class Element2DForeground extends Element2DFill implements Normal
|
|
|
11
11
|
/**
|
|
12
12
|
* 原图的 CPU 副本(HTMLCanvas),供烘焙 effects 使用。
|
|
13
13
|
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* 刻意不读 `this.texture.source`:那张 ImageBitmap 由纹理管线持有,会经 GPU
|
|
15
|
+
* 上传(premultiply)/ 资源 GC 而被消费或 `close()`,其内容与尺寸随运行环境
|
|
16
|
+
* (含 headless / 自定义 canvas factory)漂移——实测过空白、尺寸异常(如
|
|
17
|
+
* 3552×3552 全透明)。这份副本一律由 `_resolveSourceCanvas` 从 image 独立解码,
|
|
18
|
+
* 与 GPU 纹理生命周期彻底解耦。
|
|
18
19
|
*/
|
|
19
20
|
protected _sourceCanvas?: HTMLCanvasElement;
|
|
20
21
|
/** `_sourceCanvas` 对应的图片地址,image 变更时用于失效旧副本 */
|
|
@@ -22,12 +23,12 @@ export declare class Element2DForeground extends Element2DFill implements Normal
|
|
|
22
23
|
setProperties(properties?: Foreground): this;
|
|
23
24
|
protected _updateProperty(key: string, value: any, oldValue: any): void;
|
|
24
25
|
loadTexture(): Promise<void>;
|
|
25
|
-
/** 把原图 + effects
|
|
26
|
+
/** 把原图 + effects 烘焙成一张运行时纹理(gif/无 effects 时跳过) */
|
|
26
27
|
protected _applyEffects(): Promise<void>;
|
|
27
28
|
/**
|
|
28
|
-
* 取得用于烘焙的 CPU
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* 取得用于烘焙的 CPU 副本:始终从 image 独立解码一份(createImageBitmap 保证解码
|
|
30
|
+
* 就绪),快照进 canvas,按 url 在资源层缓存复用。不读 `this.texture.source`——见
|
|
31
|
+
* `_sourceCanvas` 注释。只缓存真正拿到的副本,避免把空/未就绪结果钉死。
|
|
31
32
|
*/
|
|
32
33
|
protected _resolveSourceCanvas(): Promise<HTMLCanvasElement | undefined>;
|
|
33
34
|
/** 把一张存活的图源画进新 canvas(不会被 close,可反复用于烘焙) */
|