@meta2d/core 1.0.81 → 1.0.83

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.83",
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() {
@@ -4519,11 +4548,11 @@ export class Canvas {
4519
4548
  }
4520
4549
  scalePoint(this.store.data.origin, s, center);
4521
4550
  this.store.data.pens.forEach((pen) => {
4551
+ pen.onScale && pen.onScale(pen);
4522
4552
  if (pen.parentId) {
4523
4553
  return;
4524
4554
  }
4525
4555
  scalePen(pen, s, center);
4526
- pen.onScale && pen.onScale(pen);
4527
4556
  if (pen.isRuleLine) {
4528
4557
  // 扩大线的比例,若是放大,即不缩小,若是缩小,会放大
4529
4558
  const lineScale = 1 / s; //s > 1 ? 1 : 1 / s / s;
@@ -5844,6 +5873,11 @@ export class Canvas {
5844
5873
  let _y = -this.store.clipboard.initRect.height / this.store.clipboard.scale / 10 / (scale);
5845
5874
  let offsetX = (scale - this.store.clipboard.scale) * this.store.clipboard.initRect.width / 2 + _x;
5846
5875
  let offsetY = (scale - this.store.clipboard.scale) * this.store.clipboard.initRect.height / 2 + _y;
5876
+ if (scale < this.store.clipboard.scale) {
5877
+ // 减小粘贴偏移量
5878
+ offsetX = (scale - this.store.clipboard.scale) / ((this.store.clipboard.scale - scale) * 100) * this.store.clipboard.initRect.width / 2 + _x;
5879
+ offsetY = (scale - this.store.clipboard.scale) / ((this.store.clipboard.scale - scale) * 100) * this.store.clipboard.initRect.height / 2 + _y;
5880
+ }
5847
5881
  if (this.store.clipboard.pens.length > 1) {
5848
5882
  offsetX = (scale - 1) * this.store.clipboard.initRect.width / this.store.clipboard.scale / 2;
5849
5883
  offsetY = (scale - 1) * this.store.clipboard.initRect.height / this.store.clipboard.scale / 2;