@meta2d/core 1.0.87 → 1.0.89

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.87",
3
+ "version": "1.0.89",
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",
@@ -15,6 +15,7 @@ import { MagnifierCanvas } from './magnifierCanvas';
15
15
  import { lockedError } from '../utils/error';
16
16
  import { Dialog } from '../dialog';
17
17
  import { setter } from '../utils/object';
18
+ import { isNumber } from '../utils/tool';
18
19
  import { Title } from '../title';
19
20
  import { CanvasTemplate } from './canvasTemplate';
20
21
  import { getLinePoints } from '../diagrams/line';
@@ -369,6 +370,12 @@ export class Canvas {
369
370
  }
370
371
  let data = JSON.parse(e.data);
371
372
  if (typeof data === 'object') {
373
+ if (data.name === 'onload') {
374
+ this.dialog.iframe.contentWindow.postMessage(JSON.stringify({
375
+ name: 'dialog',
376
+ data: this.dialog.data
377
+ }), '*');
378
+ }
372
379
  this.parent.doMessageEvent(data.name, JSON.stringify(data.data));
373
380
  }
374
381
  else {
@@ -2631,15 +2638,16 @@ export class Canvas {
2631
2638
  pen.calculative.hover = false;
2632
2639
  setChildrenActive(pen, false);
2633
2640
  });
2634
- !drawing && this.store.emitter.emit('inactive', this.store.active);
2641
+ const activePens = [...this.store.active];
2635
2642
  this.store.active = [];
2636
2643
  this.activeRect = undefined;
2637
2644
  this.sizeCPs = undefined;
2638
2645
  this.store.activeAnchor = undefined;
2639
2646
  this.patchFlags = true;
2647
+ !drawing && this.store.emitter.emit('inactive', activePens);
2640
2648
  }
2641
2649
  active(pens, emit = true) {
2642
- if (this.store.active) {
2650
+ if (this.store.active && this.store.active.length) {
2643
2651
  emit && this.store.emitter.emit('inactive', this.store.active);
2644
2652
  for (const pen of this.store.active) {
2645
2653
  pen.calculative.active = undefined;
@@ -4030,31 +4038,51 @@ export class Canvas {
4030
4038
  pen.calculative.fontSize =
4031
4039
  pen.fontSize * pen.calculative.worldRect.height;
4032
4040
  }
4033
- pen.calculative.iconSize = pen.iconSize * scale;
4034
- pen.calculative.iconWidth = pen.iconWidth * scale;
4035
- pen.calculative.iconHeight = pen.iconHeight * scale;
4036
- pen.calculative.iconLeft =
4037
- pen.iconLeft < 1 && pen.iconLeft > -1
4038
- ? pen.iconLeft
4039
- : pen.iconLeft * scale;
4040
- pen.calculative.iconTop =
4041
- pen.iconTop < 1 && pen.iconTop > -1 ? pen.iconTop : pen.iconTop * scale;
4042
- pen.calculative.textWidth =
4043
- pen.textWidth < 1 && pen.textWidth > -1
4044
- ? pen.textWidth
4045
- : pen.textWidth * scale;
4046
- pen.calculative.textHeight =
4047
- pen.textHeight < 1 && pen.textHeight > -1
4048
- ? pen.textHeight
4049
- : pen.textHeight * scale;
4050
- pen.calculative.textLeft =
4051
- pen.textLeft < 1 && pen.textLeft > -1
4052
- ? pen.textLeft * pen.calculative.worldRect.width
4053
- : pen.textLeft * scale;
4054
- pen.calculative.textTop =
4055
- pen.textTop < 1 && pen.textTop > -1 ? pen.textTop * pen.calculative.worldRect.height : pen.textTop * scale;
4056
- if (pen.type === PenType.Line && pen.borderWidth) {
4057
- pen.calculative.borderWidth = pen.borderWidth * scale;
4041
+ if (isNumber(pen.iconSize)) {
4042
+ pen.calculative.iconSize = pen.iconSize * scale;
4043
+ }
4044
+ if (isNumber(pen.iconWidth)) {
4045
+ pen.calculative.iconWidth = pen.iconWidth * scale;
4046
+ }
4047
+ if (isNumber(pen.iconHeight)) {
4048
+ pen.calculative.iconHeight = pen.iconHeight * scale;
4049
+ }
4050
+ if (isNumber(pen.iconLeft)) {
4051
+ pen.calculative.iconLeft =
4052
+ pen.iconLeft < 1 && pen.iconLeft > -1
4053
+ ? pen.iconLeft
4054
+ : pen.iconLeft * scale;
4055
+ }
4056
+ if (isNumber(pen.iconTop)) {
4057
+ pen.calculative.iconTop =
4058
+ pen.iconTop < 1 && pen.iconTop > -1 ? pen.iconTop : pen.iconTop * scale;
4059
+ }
4060
+ if (isNumber(pen.textWidth)) {
4061
+ pen.calculative.textWidth =
4062
+ pen.textWidth < 1 && pen.textWidth > -1
4063
+ ? pen.textWidth
4064
+ : pen.textWidth * scale;
4065
+ }
4066
+ if (isNumber(pen.textHeight)) {
4067
+ pen.calculative.textHeight =
4068
+ pen.textHeight < 1 && pen.textHeight > -1
4069
+ ? pen.textHeight
4070
+ : pen.textHeight * scale;
4071
+ }
4072
+ if (isNumber(pen.textLeft)) {
4073
+ pen.calculative.textLeft =
4074
+ pen.textLeft < 1 && pen.textLeft > -1
4075
+ ? pen.textLeft * pen.calculative.worldRect.width
4076
+ : pen.textLeft * scale;
4077
+ }
4078
+ if (isNumber(pen.textTop)) {
4079
+ pen.calculative.textTop =
4080
+ pen.textTop < 1 && pen.textTop > -1 ? pen.textTop * pen.calculative.worldRect.height : pen.textTop * scale;
4081
+ }
4082
+ if (isNumber(pen.borderWidth)) {
4083
+ if (pen.type === PenType.Line && pen.borderWidth) {
4084
+ pen.calculative.borderWidth = pen.borderWidth * scale;
4085
+ }
4058
4086
  }
4059
4087
  }
4060
4088
  updatePenRect(pen, { worldRectIsReady, playingAnimate, } = {}) {
@@ -4082,22 +4110,24 @@ export class Canvas {
4082
4110
  });
4083
4111
  }
4084
4112
  pen.type && this.initLineRect(pen);
4085
- if (pen.calculative.gradientTimer) {
4086
- clearTimeout(pen.calculative.gradientTimer);
4087
- }
4088
- pen.calculative.gradientTimer = setTimeout(() => {
4089
- if (pen.calculative.lineGradient) {
4090
- pen.calculative.lineGradient = null;
4113
+ if (pen.gradientColors || pen.lineGradientColors) {
4114
+ if (pen.calculative.gradientTimer) {
4115
+ clearTimeout(pen.calculative.gradientTimer);
4091
4116
  }
4092
- if (pen.calculative.gradient) {
4093
- pen.calculative.gradient = null;
4094
- }
4095
- if (pen.calculative.radialGradient) {
4096
- pen.calculative.radialGradient = null;
4097
- }
4098
- this.patchFlags = true;
4099
- pen.calculative.gradientTimer = undefined;
4100
- }, 50);
4117
+ pen.calculative.gradientTimer = setTimeout(() => {
4118
+ if (pen.calculative.lineGradient) {
4119
+ pen.calculative.lineGradient = null;
4120
+ }
4121
+ if (pen.calculative.gradient) {
4122
+ pen.calculative.gradient = null;
4123
+ }
4124
+ if (pen.calculative.radialGradient) {
4125
+ pen.calculative.radialGradient = null;
4126
+ }
4127
+ this.patchFlags = true;
4128
+ pen.calculative.gradientTimer = undefined;
4129
+ }, 50);
4130
+ }
4101
4131
  }
4102
4132
  initGlobalStyle() {
4103
4133
  if (this.store.options.themeOnlyCanvas || this.store.data.themeOnlyCanvas) {
@@ -4107,15 +4137,16 @@ export class Canvas {
4107
4137
  const data = {};
4108
4138
  const theme = {};
4109
4139
  themeKeys.forEach(key => {
4110
- if (this.store.options[key] !== undefined) {
4140
+ // 过滤调 null undefined ''
4141
+ if (this.store.options[key] != null && this.store.options[key] !== '') {
4111
4142
  options[key] = this.store.options[key];
4112
4143
  }
4113
- if (this.store.data[key] !== undefined) {
4144
+ if (this.store.data[key] != null && this.store.data[key] !== '') {
4114
4145
  data[key] = this.store.data[key];
4115
4146
  }
4116
4147
  if (this.store.data.theme) {
4117
4148
  const value = this.store.theme[this.store.data.theme]?.[key];
4118
- if (value !== undefined) {
4149
+ if (value != null && value !== '') {
4119
4150
  theme[key] = value;
4120
4151
  }
4121
4152
  }
@@ -4196,7 +4227,7 @@ export class Canvas {
4196
4227
  pen.calculative.img) {
4197
4228
  ctx.save();
4198
4229
  ctxFlip(ctx, pen);
4199
- if (pen.calculative.rotate) {
4230
+ if (pen.rotateByRoot || pen.calculative.rotate) {
4200
4231
  ctxRotate(ctx, pen);
4201
4232
  }
4202
4233
  setGlobalAlpha(ctx, pen);
@@ -5555,7 +5586,10 @@ export class Canvas {
5555
5586
  * @param angle 本次的旋转值,加到 pen.calculative.rotate 上
5556
5587
  */
5557
5588
  rotatePen(pen, angle, rect) {
5558
- if (pen.type) {
5589
+ if (pen.rotateByRoot) {
5590
+ return;
5591
+ }
5592
+ if (pen.name === 'line') {
5559
5593
  pen.calculative.worldAnchors.forEach((anchor) => {
5560
5594
  rotatePoint(anchor, angle, rect.center);
5561
5595
  });
@@ -6583,7 +6617,7 @@ export class Canvas {
6583
6617
  this.store.emitter.emit('change', pen);
6584
6618
  this.store.emitter.emit('valueUpdate', pen);
6585
6619
  }
6586
- else if (pen.text === this.inputDiv.dataset.value && pen.calculative.textLines.length == 0) {
6620
+ else if (pen.text === this.inputDiv.dataset.value && pen.calculative.textLines && pen.calculative.textLines.length == 0) {
6587
6621
  calcTextRect(pen);
6588
6622
  }
6589
6623
  this.initTemplateCanvas([pen]);
@@ -7005,7 +7039,7 @@ export class Canvas {
7005
7039
  this.updatePenRect(pen);
7006
7040
  }
7007
7041
  else {
7008
- willCalcTextRect && calcTextRect(pen);
7042
+ !pen.hiddenText && willCalcTextRect && calcTextRect(pen);
7009
7043
  willCalcIconRect && calcIconRect(this.store.pens, pen);
7010
7044
  if (willUpdatePath) {
7011
7045
  globalStore.path2dDraws[pen.name] &&