modern-canvas 0.23.0 → 0.23.2

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.
@@ -1,4 +1,4 @@
1
- import type { Background, Chart, Connection, Display, Fill, Foreground, Outline, Shadow, Shape, Table, Text } from 'modern-idoc';
1
+ import type { Background, Chart, Connection, Display, Fill, Foreground, NormalizedFilter, Outline, Shadow, Shape, Table, Text } from 'modern-idoc';
2
2
  import type { Path2D, Vector2Like } from 'modern-path2d';
3
3
  import type { InputEvent, InputEventKey } from '../../../core';
4
4
  import type { Node, Rectangulable, RectangulableEvents, SceneTree, Viewport } from '../../main';
@@ -41,6 +41,8 @@ export interface Element2DProperties extends Node2DProperties {
41
41
  connection: Connection;
42
42
  table: Table;
43
43
  chart: Chart;
44
+ /** 元素级结构化滤镜(Effect.filter),转成 CSS filter 后与 style.filter 合并 */
45
+ filter: NormalizedFilter;
44
46
  }
45
47
  export declare class Element2D extends Node2D implements Rectangulable {
46
48
  readonly flexbox: Flexbox;
@@ -109,7 +111,12 @@ export declare class Element2D extends Node2D implements Rectangulable {
109
111
  protected _updateConnection(): void;
110
112
  protected _cullsRender(): boolean;
111
113
  protected _intersectsViewport(viewport: Viewport): boolean;
114
+ protected _styleFilter?: string;
115
+ protected _elementFilter?: string;
112
116
  protected _updateStyleFilter(value?: string): void;
117
+ /** 元素级结构化滤镜 Effect.filter → CSS filter,与 style.filter 合并 */
118
+ protected _updateElementFilter(filter?: NormalizedFilter): void;
119
+ protected _applyColorFilter(): void;
113
120
  protected _updateStyleMaskImage(value?: string): void;
114
121
  protected _getPointArray(): Vector2Like[];
115
122
  getRect(): Aabb2D;
@@ -1,7 +1,19 @@
1
- import type { Foreground, NormalizedForeground } from 'modern-idoc';
1
+ import type { Foreground, NormalizedEffect, NormalizedForeground } from 'modern-idoc';
2
2
  import { Element2DFill } from './Element2DFill';
3
3
  export declare class Element2DForeground extends Element2DFill implements NormalizedForeground {
4
4
  fillWithShape: NormalizedForeground['fillWithShape'];
5
+ /** 图片效果叠层(filling/strokes/offset...);加载后烘焙到运行时 canvas,不持久化 */
6
+ effects?: NormalizedEffect[];
7
+ /**
8
+ * 原图的 CPU 副本(HTMLCanvas),在纹理刚加载、source 仍存活时拍下。
9
+ * 用于烘焙 effects:纹理的 ImageBitmap source 上传 GPU 后可能被
10
+ * `close()`(detached,width/height 归零),此时直接 drawImage 会抛
11
+ * InvalidStateError,故始终从这份不会失效的副本烘焙。
12
+ */
13
+ protected _sourceCanvas?: HTMLCanvasElement;
5
14
  setProperties(properties?: Foreground): this;
6
15
  protected _updateProperty(key: string, value: any, oldValue: any): void;
16
+ loadTexture(): Promise<void>;
17
+ /** 把原纹理 + effects 烘焙成一张运行时 canvas,包成 CanvasTexture(gif/无 effects 时跳过) */
18
+ protected _applyEffects(): void;
7
19
  }
@@ -0,0 +1,13 @@
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
+ * 注意:图案填充(fill.image)需异步预加载,未在 patterns 中提供则跳过该填充。
11
+ */
12
+ export declare function bakeImageEffects(source: Drawable, effects: NormalizedEffect[], width: number, height: number, patterns?: Record<string, Drawable>): HTMLCanvasElement;
13
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.23.0",
4
+ "version": "0.23.2",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",
@@ -54,7 +54,7 @@
54
54
  "dev": "vite playground",
55
55
  "lint": "eslint src playground test",
56
56
  "version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
57
- "release": "pnpm typecheck && pnpm lint && pnpm test --run && bumpp package.json --commit \"release: v%s\" --push --all --tag",
57
+ "release": "pnpm typecheck && pnpm lint && pnpm vitest run && bumpp package.json --commit \"release: v%s\" --push --all --tag",
58
58
  "start": "esno src/index.ts",
59
59
  "test": "vitest",
60
60
  "typecheck": "tsc --noEmit"
@@ -63,7 +63,7 @@
63
63
  "colord": "^2.9.3",
64
64
  "earcut": "^3.0.2",
65
65
  "modern-font": "^0.6.0",
66
- "modern-idoc": "^0.11.8",
66
+ "modern-idoc": "^0.11.9",
67
67
  "modern-path2d": "^1.8.5",
68
68
  "modern-text": "^2.0.3"
69
69
  },