modern-canvas 0.24.10 → 0.24.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/Engine.d.ts +15 -5
- package/dist/index.js +761 -823
- package/dist/scene/2d/element/Element2DFill.d.ts +15 -2
- package/dist/scene/2d/element/Element2DForeground.d.ts +6 -36
- package/dist/scene/2d/element/imagePipeline.d.ts +11 -0
- package/dist/scene/2d/element/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/scene/2d/element/bakeImageEffects.d.ts +0 -17
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Fill, NormalizedFill } from 'modern-idoc';
|
|
2
|
-
import type { AnimatedTexture
|
|
1
|
+
import type { Fill, NormalizedFill, PipelineImage } from 'modern-idoc';
|
|
2
|
+
import type { AnimatedTexture } from '../../resources';
|
|
3
3
|
import type { Element2D } from './Element2D';
|
|
4
4
|
import { CoreObject } from '../../../core';
|
|
5
|
+
import { Texture2D } from '../../resources';
|
|
5
6
|
export interface Element2DFill extends NormalizedFill {
|
|
6
7
|
}
|
|
7
8
|
export declare class Element2DFill extends CoreObject implements NormalizedFill {
|
|
@@ -17,6 +18,8 @@ export declare class Element2DFill extends CoreObject implements NormalizedFill
|
|
|
17
18
|
rotateWithShape?: NormalizedFill['rotateWithShape'];
|
|
18
19
|
tile?: NormalizedFill['tile'];
|
|
19
20
|
opacity?: NormalizedFill['opacity'];
|
|
21
|
+
/** 图片处理管线;图片加载后交由注入的解析器烘焙到运行时纹理,不持久化 */
|
|
22
|
+
pipelines?: NormalizedFill['pipelines'];
|
|
20
23
|
texture?: Texture2D;
|
|
21
24
|
animatedTexture?: AnimatedTexture;
|
|
22
25
|
constructor(_parent: Element2D);
|
|
@@ -24,6 +27,16 @@ export declare class Element2DFill extends CoreObject implements NormalizedFill
|
|
|
24
27
|
setProperties(properties?: Fill): this;
|
|
25
28
|
protected _updateProperty(key: string, value: any, oldValue: any): void;
|
|
26
29
|
loadTexture(): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* 把原图经 `pipelines` 烘焙成一张运行时纹理(无管线 / 无解析器 / gif 时跳过)。
|
|
32
|
+
* 始终从 image 独立解码像素喂给管线,不读 `this.texture.source`(那张 ImageBitmap
|
|
33
|
+
* 由纹理管线持有、会经 premultiply 上传/GC 而被消费)。结果按 `url + 管线` 缓存复用。
|
|
34
|
+
*/
|
|
35
|
+
protected _applyPipelines(url: string): Promise<void>;
|
|
36
|
+
protected _pipelineKey(pipelines: NonNullable<NormalizedFill['pipelines']>): string;
|
|
37
|
+
/** 从 image 独立解码为中立像素结构(不读 GPU 纹理 source) */
|
|
38
|
+
protected _decodePipelineSource(url: string): Promise<PipelineImage | undefined>;
|
|
39
|
+
protected _pipelineImageToCanvas(image: PipelineImage): HTMLCanvasElement | undefined;
|
|
27
40
|
protected _updateTexture(): Promise<void>;
|
|
28
41
|
isValid(): boolean;
|
|
29
42
|
draw(): void;
|
|
@@ -1,42 +1,12 @@
|
|
|
1
|
-
import type { Foreground,
|
|
1
|
+
import type { Foreground, NormalizedForeground } from 'modern-idoc';
|
|
2
2
|
import { Element2DFill } from './Element2DFill';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* 前景 = 带「图片处理管线」的填充。管线(描边/调色/抠图等图片样式)由基类
|
|
5
|
+
* `Element2DFill` 在图片加载时经注入的解析器烘焙到运行时纹理,本类只在 `Fill`
|
|
6
|
+
* 之上补充 `fillWithShape`(前景按形状裁切)。
|
|
7
|
+
*/
|
|
7
8
|
export declare class Element2DForeground extends Element2DFill implements NormalizedForeground {
|
|
8
9
|
fillWithShape: NormalizedForeground['fillWithShape'];
|
|
9
|
-
/** 图片效果叠层(filling/strokes/offset...);加载后烘焙到运行时 canvas,不持久化 */
|
|
10
|
-
effects?: NormalizedEffect[];
|
|
11
|
-
/**
|
|
12
|
-
* 原图的 CPU 副本(HTMLCanvas),供烘焙 effects 使用。
|
|
13
|
-
*
|
|
14
|
-
* 刻意不读 `this.texture.source`:那张 ImageBitmap 由纹理管线持有,会经 GPU
|
|
15
|
-
* 上传(premultiply)/ 资源 GC 而被消费或 `close()`,其内容与尺寸随运行环境
|
|
16
|
-
* (含 headless / 自定义 canvas factory)漂移——实测过空白、尺寸异常(如
|
|
17
|
-
* 3552×3552 全透明)。这份副本一律由 `_resolveSourceCanvas` 从 image 独立解码,
|
|
18
|
-
* 与 GPU 纹理生命周期彻底解耦。
|
|
19
|
-
*/
|
|
20
|
-
protected _sourceCanvas?: HTMLCanvasElement;
|
|
21
|
-
/** `_sourceCanvas` 对应的图片地址,image 变更时用于失效旧副本 */
|
|
22
|
-
protected _sourceImage?: string;
|
|
23
10
|
setProperties(properties?: Foreground): this;
|
|
24
11
|
protected _updateProperty(key: string, value: any, oldValue: any): void;
|
|
25
|
-
loadTexture(): Promise<void>;
|
|
26
|
-
/** 把原图 + effects 烘焙成一张运行时纹理(gif/无 effects 时跳过) */
|
|
27
|
-
protected _applyEffects(): Promise<void>;
|
|
28
|
-
/**
|
|
29
|
-
* 预解码 effects 里 fill.image 用到的图案。烘焙是同步的,图案须先就绪;
|
|
30
|
-
* 按 url 在资源层缓存复用,未提供的图案在烘焙时会被跳过(不重上色)。
|
|
31
|
-
*/
|
|
32
|
-
protected _resolvePatterns(): Promise<Record<string, HTMLCanvasElement>>;
|
|
33
|
-
/**
|
|
34
|
-
* 取得用于烘焙的 CPU 副本:始终从 image 独立解码一份(createImageBitmap 保证解码
|
|
35
|
-
* 就绪),快照进 canvas,按 url 在资源层缓存复用。不读 `this.texture.source`——见
|
|
36
|
-
* `_sourceCanvas` 注释。只缓存真正拿到的副本,避免把空/未就绪结果钉死。
|
|
37
|
-
*/
|
|
38
|
-
protected _resolveSourceCanvas(): Promise<HTMLCanvasElement | undefined>;
|
|
39
|
-
/** 把一张存活的图源画进新 canvas(不会被 close,可反复用于烘焙) */
|
|
40
|
-
protected _snapshot(source: Snapshotable): HTMLCanvasElement | undefined;
|
|
41
12
|
}
|
|
42
|
-
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ImagePipeline, PipelineImage } from 'modern-idoc';
|
|
2
|
+
/**
|
|
3
|
+
* 图片处理管线解析器:给定管线步骤与原图像素,返回处理后的像素。
|
|
4
|
+
*
|
|
5
|
+
* 引擎本身不认识任何具名管线,只在图片填充加载时把 `pipelines + 像素` 交给注入的
|
|
6
|
+
* 解析器烘焙(仿 `setCanvasFactory`)。具体管线(描边/调色/抠图等)由上层
|
|
7
|
+
* (如 mce + @mce/bigesj)注册并实现。返回 `undefined` 表示放弃处理、沿用原图。
|
|
8
|
+
*/
|
|
9
|
+
export type ImagePipelineResolver = (pipelines: ImagePipeline[], image: PipelineImage) => Promise<PipelineImage | undefined>;
|
|
10
|
+
export declare function setImagePipelineResolver(resolver: ImagePipelineResolver | undefined): void;
|
|
11
|
+
export declare function getImagePipelineResolver(): ImagePipelineResolver | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-canvas",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.24.
|
|
4
|
+
"version": "0.24.13",
|
|
5
5
|
"packageManager": "pnpm@10.19.0",
|
|
6
6
|
"description": "A JavaScript WebGL rendering engine. only the ESM.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"colord": "^2.9.3",
|
|
64
64
|
"earcut": "^3.0.2",
|
|
65
65
|
"modern-font": "^0.6.1",
|
|
66
|
-
"modern-idoc": "^0.12.
|
|
66
|
+
"modern-idoc": "^0.12.2",
|
|
67
67
|
"modern-path2d": "^1.8.5",
|
|
68
68
|
"modern-text": "^2.0.9"
|
|
69
69
|
},
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NormalizedEffect } from 'modern-idoc';
|
|
2
|
-
type Drawable = CanvasImageSource & {
|
|
3
|
-
width: number;
|
|
4
|
-
height: number;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* 把 `原图 + effects` 烘焙到一张运行时 canvas(不持久化、不转存图片)。
|
|
8
|
-
* 每层按顺序:fill 重上色 → outline 描边 → 按 transform 位移 / shadow 投影后合成。
|
|
9
|
-
*
|
|
10
|
-
* 合成统一用 destination-over:数组按「前 → 后」堆叠(第 0 层在最上,后续依次落到其后),
|
|
11
|
-
* transform translate 只决定该层落点、不改变堆叠次序。于是「原图层 `{}` 在前 + 位移填充层在后」
|
|
12
|
-
* 即得到「主图在上、彩色副本作为阴影/重影偏移到背后」——与来源编辑器的图片样式一致。
|
|
13
|
-
*
|
|
14
|
-
* 注意:图案填充(fill.image)需异步预加载,未在 patterns 中提供则跳过该填充。
|
|
15
|
-
*/
|
|
16
|
-
export declare function bakeImageEffects(source: Drawable, effects: NormalizedEffect[], width: number, height: number, patterns?: Record<string, Drawable>): HTMLCanvasElement;
|
|
17
|
-
export {};
|