modern-canvas 0.23.7 → 0.23.8

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
@@ -6697,7 +6697,7 @@ function Oi(e, t, n, r, i = {}) {
6697
6697
  let t = e;
6698
6698
  n.fill && (n.fill.color || n.fill.linearGradient || n.fill.image) && (t = Ti(t, a, o, n.fill, i)), n.outline?.width && n.outline.color && (t = Ei(t, a, o, n.outline.width, n.outline.color));
6699
6699
  let { x: r, y: s } = Di(n.transform);
6700
- c.save(), n.shadow && (c.shadowColor = n.shadow.color, c.shadowBlur = n.shadow.blur ?? 0, c.shadowOffsetX = n.shadow.offsetX ?? 0, c.shadowOffsetY = n.shadow.offsetY ?? 0), r || s ? c.drawImage(t, r, s, a, o) : (c.globalCompositeOperation = "destination-over", c.drawImage(t, 0, 0, a, o)), c.restore();
6700
+ c.save(), c.globalCompositeOperation = "destination-over", n.shadow && (c.shadowColor = n.shadow.color, c.shadowBlur = n.shadow.blur ?? 0, c.shadowOffsetX = n.shadow.offsetX ?? 0, c.shadowOffsetY = n.shadow.offsetY ?? 0), c.drawImage(t, r, s, a, o), c.restore();
6701
6701
  }
6702
6702
  return s;
6703
6703
  }
@@ -6729,14 +6729,27 @@ var ki = class extends J {
6729
6729
  }
6730
6730
  let e = await this._resolveSourceCanvas();
6731
6731
  if (!e) return;
6732
- let t = e.width, n = e.height, r = Oi(e, this.effects, t, n);
6732
+ let t = e.width, n = e.height, r = await this._resolvePatterns(), i = Oi(e, this.effects, t, n, r);
6733
6733
  this.texture = new R({
6734
- source: r,
6734
+ source: i,
6735
6735
  width: t,
6736
6736
  height: n,
6737
6737
  uploadMethodId: "image"
6738
6738
  });
6739
6739
  }
6740
+ async _resolvePatterns() {
6741
+ let e = {};
6742
+ for (let t of this.effects ?? []) {
6743
+ let n = t.fill?.image;
6744
+ if (!n || d(n) || e[n]) continue;
6745
+ let r = await $.loadBy(`${n}#mc-foreground-pattern`, async () => {
6746
+ let e = await $.fetchImageBitmap(n), t = this._snapshot(e);
6747
+ return Ne && e instanceof ImageBitmap && e.close(), t;
6748
+ });
6749
+ r && (e[n] = r);
6750
+ }
6751
+ return e;
6752
+ }
6740
6753
  async _resolveSourceCanvas() {
6741
6754
  if (this._sourceImage !== this.image && (this._sourceCanvas = void 0, this._sourceImage = this.image), this._sourceCanvas) return this._sourceCanvas;
6742
6755
  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
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "modern-canvas",
3
3
  "type": "module",
4
- "version": "0.23.7",
4
+ "version": "0.23.8",
5
5
  "packageManager": "pnpm@10.19.0",
6
6
  "description": "A JavaScript WebGL rendering engine. only the ESM.",
7
7
  "author": "wxm",