@meta2d/core 1.0.81 → 1.0.82

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meta2d/core",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
4
4
  "description": "@meta2d/core: Powerful, Beautiful, Simple, Open - Web-Based 2D At Its Best .",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -260,6 +260,7 @@ export declare class Canvas {
260
260
  */
261
261
  private firefoxLoadSvg;
262
262
  loadImage(pen: Pen): void;
263
+ __loadImage(src: string): Promise<unknown>;
263
264
  private imageTimer;
264
265
  imageLoaded(): void;
265
266
  private templateImageTimer;
@@ -3646,6 +3646,12 @@ export class Canvas {
3646
3646
  });
3647
3647
  }
3648
3648
  !pen.rotate && (pen.rotate = 0);
3649
+ pen.lineAnimateImages ??= [];
3650
+ if (pen.lineAnimateImages) {
3651
+ pen.lineAnimateImages.forEach((src) => {
3652
+ this.__loadImage(src);
3653
+ });
3654
+ }
3649
3655
  this.loadImage(pen);
3650
3656
  this.parent.penNetwork(pen);
3651
3657
  }
@@ -3966,6 +3972,29 @@ export class Canvas {
3966
3972
  pen.calculative.strokeImage = pen.strokeImage;
3967
3973
  }
3968
3974
  }
3975
+ // 加载图片到全局缓存
3976
+ __loadImage(src) {
3977
+ return new Promise(resolve => {
3978
+ if (!globalStore.htmlElements[src]) {
3979
+ const img = new Image();
3980
+ img.crossOrigin = 'anonymous';
3981
+ img.src = src;
3982
+ if (this.store.options.cdn &&
3983
+ !(src.startsWith('http') ||
3984
+ src.startsWith('//') ||
3985
+ src.startsWith('data:image'))) {
3986
+ img.src = this.store.options.cdn + src;
3987
+ }
3988
+ img.onload = () => {
3989
+ globalStore.htmlElements[src] = img;
3990
+ resolve(img);
3991
+ };
3992
+ }
3993
+ else {
3994
+ resolve(globalStore.htmlElements[src]);
3995
+ }
3996
+ });
3997
+ }
3969
3998
  imageTimer;
3970
3999
  // 避免初始化图片加载重复调用 render,此处防抖
3971
4000
  imageLoaded() {