@meta2d/core 1.0.68 → 1.0.70

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.68",
3
+ "version": "1.0.70",
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",
@@ -270,6 +270,7 @@ export declare class Canvas {
270
270
  playingAnimate?: boolean;
271
271
  noChildren?: boolean;
272
272
  }): void;
273
+ initGlobalStyle(): void;
273
274
  render: (patchFlags?: number | boolean) => void;
274
275
  renderPens: () => void;
275
276
  private renderPenContainChild;
@@ -1,5 +1,5 @@
1
1
  import { KeydownType } from '../options';
2
- import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, CanvasLayer, ctxFlip, ctxRotate, setGlobalAlpha, drawImage, setElemPosition, getAllFollowers, calcChildrenInitRect, } from '../pen';
2
+ import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, clearLifeCycle, rotatePen, calcTextAutoWidth, getGradientAnimatePath, CanvasLayer, ctxFlip, ctxRotate, setGlobalAlpha, drawImage, setElemPosition, getAllFollowers, calcChildrenInitRect, } from '../pen';
3
3
  import { calcRotate, distance, getDistance, hitPoint, PointType, PrevNextType, rotatePoint, samePoint, scalePoint, translatePoint, TwoWay, } from '../point';
4
4
  import { calcCenter, calcRightBottom, calcRelativePoint, getRect, getRectOfPoints, pointInRect, pointInSimpleRect, rectInRect, rectToPoints, resizeRect, translateRect, pointInPolygon } from '../rect';
5
5
  import { EditType, globalStore, } from '../store';
@@ -19,6 +19,7 @@ import { Title } from '../title';
19
19
  import { CanvasTemplate } from './canvasTemplate';
20
20
  import { getLinePoints } from '../diagrams/line';
21
21
  import { Popconfirm } from '../popconfirm';
22
+ import { themeKeys } from '../theme';
22
23
  export const movingSuffix = '-moving';
23
24
  export class Canvas {
24
25
  parent;
@@ -4027,6 +4028,27 @@ export class Canvas {
4027
4028
  pen.calculative.gradientTimer = undefined;
4028
4029
  }, 50);
4029
4030
  }
4031
+ initGlobalStyle() {
4032
+ const options = {};
4033
+ const data = {};
4034
+ const theme = {};
4035
+ themeKeys.forEach(key => {
4036
+ if (this.store.options[key] !== undefined) {
4037
+ options[key] = this.store.options[key];
4038
+ }
4039
+ if (this.store.data[key] !== undefined) {
4040
+ data[key] = this.store.data[key];
4041
+ }
4042
+ if (this.store.data.theme) {
4043
+ const value = this.store.theme[this.store.data.theme]?.[key];
4044
+ if (value !== undefined) {
4045
+ theme[key] = value;
4046
+ }
4047
+ }
4048
+ });
4049
+ this.store.styles = {};
4050
+ Object.assign(this.store.styles, options, data, theme);
4051
+ }
4030
4052
  render = (patchFlags) => {
4031
4053
  if (patchFlags) {
4032
4054
  this.opening = false;
@@ -4078,7 +4100,7 @@ export class Canvas {
4078
4100
  };
4079
4101
  renderPens = () => {
4080
4102
  const ctx = this.offscreen.getContext('2d');
4081
- ctx.strokeStyle = getGlobalColor(this.store);
4103
+ ctx.strokeStyle = this.store.styles.color; //getGlobalColor(this.store);
4082
4104
  for (const pen of this.store.data.pens) {
4083
4105
  if (!isFinite(pen.x)) {
4084
4106
  continue;
@@ -4145,7 +4167,7 @@ export class Canvas {
4145
4167
  ctx.rotate((this.activeRect.rotate * Math.PI) / 180);
4146
4168
  ctx.translate(-pivot.x, -pivot.y);
4147
4169
  }
4148
- ctx.strokeStyle = this.store.options.activeColor;
4170
+ ctx.strokeStyle = this.store.styles.activeColor;
4149
4171
  ctx.globalAlpha = this.store.options.activeGlobalAlpha === undefined ? 0.3 : this.store.options.activeGlobalAlpha;
4150
4172
  ctx.beginPath();
4151
4173
  ctx.lineWidth = this.store.options.activeLineWidth || 1;
@@ -4167,7 +4189,7 @@ export class Canvas {
4167
4189
  ctx.stroke();
4168
4190
  // Draw rotate control points.
4169
4191
  ctx.beginPath();
4170
- ctx.strokeStyle = this.store.options.activeColor;
4192
+ ctx.strokeStyle = this.store.styles.activeColor;
4171
4193
  ctx.fillStyle = '#ffffff';
4172
4194
  ctx.arc(this.activeRect.center.x, this.activeRect.y - 30, 5, 0, Math.PI * 2);
4173
4195
  ctx.fill();
@@ -4195,7 +4217,7 @@ export class Canvas {
4195
4217
  }
4196
4218
  if (anchors) {
4197
4219
  ctx.strokeStyle =
4198
- this.store.hover.anchorColor || this.store.options.anchorColor;
4220
+ this.store.hover.anchorColor || this.store.styles.anchorColor;
4199
4221
  ctx.fillStyle =
4200
4222
  this.store.hover.anchorBackground ||
4201
4223
  this.store.options.anchorBackground;
@@ -4251,7 +4273,7 @@ export class Canvas {
4251
4273
  if (this.store.hover.type && this.store.hoverAnchor === anchor) {
4252
4274
  ctx.save();
4253
4275
  ctx.strokeStyle =
4254
- this.store.hover.activeColor || this.store.options.activeColor;
4276
+ this.store.hover.activeColor || this.store.styles.activeColor;
4255
4277
  ctx.fillStyle = ctx.strokeStyle;
4256
4278
  }
4257
4279
  else if (anchor.color || anchor.background) {
@@ -4299,7 +4321,7 @@ export class Canvas {
4299
4321
  if (!getPensLock(this.store.active) &&
4300
4322
  !getPensDisableResize(this.store.active) &&
4301
4323
  !this.store.options.disableSize) {
4302
- ctx.strokeStyle = this.store.options.activeColor;
4324
+ ctx.strokeStyle = this.store.styles.activeColor;
4303
4325
  ctx.fillStyle = '#ffffff';
4304
4326
  this.sizeCPs.forEach((pt, i) => {
4305
4327
  if (this.activeRect.rotate) {
@@ -5796,7 +5818,7 @@ export class Canvas {
5796
5818
  offset && (this.store.clipboard.offset = offset);
5797
5819
  pos && (this.store.clipboard.pos = pos);
5798
5820
  }
5799
- if (!this.keyOptions.F) {
5821
+ if (!this.keyOptions?.F) {
5800
5822
  this.store.clipboard.pens.forEach((pen) => {
5801
5823
  delete pen.copyIndex;
5802
5824
  });
@@ -7074,7 +7096,8 @@ export class Canvas {
7074
7096
  // }
7075
7097
  ctx.textBaseline = 'middle'; // 默认垂直居中
7076
7098
  ctx.scale(scale, scale);
7077
- const background = this.store.data.background || this.store.options.background;
7099
+ const background = this.store.data.background || this.store.styles.background;
7100
+ // this.store.data.background || this.store.options.background;
7078
7101
  if (background && isV) {
7079
7102
  // 绘制背景颜色
7080
7103
  ctx.save();
@@ -7115,7 +7138,11 @@ export class Canvas {
7115
7138
  else {
7116
7139
  // 平移画布,画笔的 worldRect 不变化
7117
7140
  if (isV) {
7118
- ctx.translate(-oldRect.x + p[3] * _scale || 0, -oldRect.y + p[0] * _scale || 0);
7141
+ // ctx.translate(
7142
+ // -oldRect.x + p[3] * _scale || 0,
7143
+ // -oldRect.y + p[0] * _scale || 0
7144
+ // );
7145
+ ctx.translate(-rect.x, -rect.y);
7119
7146
  }
7120
7147
  else {
7121
7148
  ctx.translate((isRight ? storeData.x : -oldRect.x) + p[3] * _scale || 0, (isBottom ? storeData.y : -oldRect.y) + p[0] * _scale || 0);
@@ -7183,7 +7210,8 @@ export class Canvas {
7183
7210
  const ctx = canvas.getContext('2d');
7184
7211
  ctx.textBaseline = 'middle'; // 默认垂直居中
7185
7212
  ctx.scale(scale, scale);
7186
- const background = this.store.data.background || this.store.options.background;
7213
+ const background = this.store.data.background || this.store.styles.background;
7214
+ // this.store.data.background || this.store.options.background;
7187
7215
  if (background) {
7188
7216
  // 绘制背景颜色
7189
7217
  ctx.save();
@@ -7199,6 +7227,9 @@ export class Canvas {
7199
7227
  if (!isShowChild(pen, this.store) || pen.visible == false) {
7200
7228
  continue;
7201
7229
  }
7230
+ if (pen.name === 'combine' && !pen.draw) {
7231
+ continue;
7232
+ }
7202
7233
  const { active } = pen.calculative;
7203
7234
  pen.calculative.active = false;
7204
7235
  if (pen.calculative.img) {