@meta2d/core 1.0.46 → 1.0.47

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.46",
3
+ "version": "1.0.47",
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",
@@ -195,6 +195,8 @@ export declare class Canvas {
195
195
  button?: number;
196
196
  }) => void;
197
197
  private addRuleLine;
198
+ clearRuleLines(): void;
199
+ get ruleLines(): Pen[];
198
200
  /**
199
201
  * @description 调整pen的坐标,让pen按照网格自动对齐
200
202
  * @author Joseph Ho
@@ -428,6 +430,7 @@ export declare class Canvas {
428
430
  };
429
431
  toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
430
432
  activeToPng(padding?: Padding): string;
433
+ pensToPng(pens?: Pen[], padding?: Padding): string;
431
434
  toggleAnchorMode(): void;
432
435
  addAnchorHand(): void;
433
436
  removeAnchorHand(): void;
@@ -100,6 +100,7 @@ import { Dialog } from '../dialog';
100
100
  import { setter } from '../utils/object';
101
101
  import { Title } from '../title';
102
102
  import { CanvasTemplate } from './canvasTemplate';
103
+ import { getLinePoints } from '../diagrams/line';
103
104
  export var movingSuffix = '-moving';
104
105
  var Canvas = /** @class */ (function () {
105
106
  function Canvas(parent, parentElement, store) {
@@ -639,9 +640,16 @@ var Canvas = /** @class */ (function () {
639
640
  _this.store.active.forEach(function (pen) {
640
641
  if (pen.type) {
641
642
  pen.close = !pen.close;
643
+ if (pen.close) {
644
+ getLinePoints(pen);
645
+ }
642
646
  _this.store.path2dMap.set(pen, globalStore.path2dDraws.line(pen));
643
647
  getLineLength(pen);
644
648
  }
649
+ else {
650
+ //图元进入编辑模式
651
+ pen.calculative.focus = !pen.calculative.focus;
652
+ }
645
653
  });
646
654
  _this.render();
647
655
  }
@@ -1343,9 +1351,13 @@ var Canvas = /** @class */ (function () {
1343
1351
  }
1344
1352
  if (_this.store.active.length === 1) {
1345
1353
  var activePen = _this.store.active[0];
1346
- if (activePen.locked < LockState.DisableMove) {
1354
+ if (activePen.locked === undefined || activePen.locked < LockState.DisableMove) {
1347
1355
  (_e = activePen === null || activePen === void 0 ? void 0 : activePen.onMouseMove) === null || _e === void 0 ? void 0 : _e.call(activePen, activePen, _this.mousePos);
1348
1356
  }
1357
+ if (activePen.calculative.focus) {
1358
+ //执行图元的操作
1359
+ return;
1360
+ }
1349
1361
  }
1350
1362
  _this.movePens(e);
1351
1363
  return;
@@ -1446,11 +1458,17 @@ var Canvas = /** @class */ (function () {
1446
1458
  return;
1447
1459
  }
1448
1460
  if (_this.mouseRight === MouseRight.Down) {
1449
- _this.store.emitter.emit('contextmenu', {
1450
- e: e,
1451
- clientRect: _this.clientRect,
1452
- pen: _this.store.hover,
1453
- });
1461
+ if (_this.store.hover && _this.store.hover.calculative.focus) {
1462
+ _this.store.hover.onContextmenu &&
1463
+ _this.store.hover.onContextmenu(_this.store.hover, e);
1464
+ }
1465
+ else {
1466
+ _this.store.emitter.emit('contextmenu', {
1467
+ e: e,
1468
+ clientRect: _this.clientRect,
1469
+ pen: _this.store.hover,
1470
+ });
1471
+ }
1454
1472
  }
1455
1473
  _this.mouseRight = MouseRight.None;
1456
1474
  _this.calibrateMouse(e);
@@ -2489,7 +2507,7 @@ var Canvas = /** @class */ (function () {
2489
2507
  }
2490
2508
  var textRect = rect || pen.calculative.worldTextRect;
2491
2509
  //value和innerText问题
2492
- var preInputText = pen.calculative.tempText || pen.text + '' || '';
2510
+ var preInputText = pen.calculative.tempText === undefined ? (pen.text + '' || '') : pen.calculative.tempText;
2493
2511
  var textArr = preInputText.replace(/\x20/g, '&nbsp;').split(/[\s\n]/);
2494
2512
  var finalText = (textArr.join('</div><div>') + "</div>")
2495
2513
  .replace('</div>', '')
@@ -3471,6 +3489,16 @@ var Canvas = /** @class */ (function () {
3471
3489
  ],
3472
3490
  });
3473
3491
  };
3492
+ Canvas.prototype.clearRuleLines = function () {
3493
+ this.delete(this.ruleLines);
3494
+ };
3495
+ Object.defineProperty(Canvas.prototype, "ruleLines", {
3496
+ get: function () {
3497
+ return this.store.data.pens.filter(function (p) { return p.isRuleLine; });
3498
+ },
3499
+ enumerable: false,
3500
+ configurable: true
3501
+ });
3474
3502
  /**
3475
3503
  * @description 调整pen的坐标,让pen按照网格自动对齐
3476
3504
  * @author Joseph Ho
@@ -4078,7 +4106,7 @@ var Canvas = /** @class */ (function () {
4078
4106
  this.doEditAction(action_1, true);
4079
4107
  step--;
4080
4108
  }
4081
- if (action.type == EditType.Add || action.type == EditType.Delete) {
4109
+ if (action.type == EditType.Add || action.type == EditType.Delete || action.type == EditType.Update) {
4082
4110
  this.activeHistory();
4083
4111
  }
4084
4112
  };
@@ -4096,19 +4124,27 @@ var Canvas = /** @class */ (function () {
4096
4124
  this.doEditAction(action_2, false);
4097
4125
  step--;
4098
4126
  }
4099
- if (action.type == EditType.Add || action.type == EditType.Delete) {
4127
+ if (action.type == EditType.Add || action.type == EditType.Delete || action.type == EditType.Update) {
4100
4128
  this.activeHistory();
4101
4129
  }
4102
4130
  };
4103
4131
  Canvas.prototype.activeHistory = function () {
4104
4132
  var _this = this;
4133
+ var now = this.store.histories[this.store.historyIndex + 1];
4134
+ var pens = [];
4135
+ if (now && (now.type === EditType.Update)) {
4136
+ now.pens.forEach(function (pen) {
4137
+ pens.push(_this.store.pens[pen.id]);
4138
+ });
4139
+ this.active(pens);
4140
+ return;
4141
+ }
4105
4142
  var before = this.store.histories[this.store.historyIndex];
4106
- if (before && before.type === EditType.Add) {
4107
- var pens_8 = [];
4143
+ if (before && (before.type === EditType.Add || before.type === EditType.Delete)) {
4108
4144
  before.pens.forEach(function (pen) {
4109
- pens_8.push(_this.store.pens[pen.id]);
4145
+ pens.push(_this.store.pens[pen.id]);
4110
4146
  });
4111
- this.active(pens_8);
4147
+ this.active(pens);
4112
4148
  }
4113
4149
  };
4114
4150
  Canvas.prototype.doEditAction = function (action, undo) {
@@ -4206,7 +4242,7 @@ var Canvas = /** @class */ (function () {
4206
4242
  break;
4207
4243
  case EditType.Replace: {
4208
4244
  // undo pens则为新的pen
4209
- var pens_9 = undo ? action.initPens : action.pens;
4245
+ var pens_8 = undo ? action.initPens : action.pens;
4210
4246
  var unPens_2 = undo ? action.pens : action.initPens;
4211
4247
  // 删除旧的
4212
4248
  unPens_2.forEach(function (aPen) {
@@ -4227,7 +4263,7 @@ var Canvas = /** @class */ (function () {
4227
4263
  }
4228
4264
  });
4229
4265
  // 放置新的
4230
- pens_9.reverse().forEach(function (aPen) {
4266
+ pens_8.reverse().forEach(function (aPen) {
4231
4267
  var _a, _b;
4232
4268
  var pen = deepClone(aPen, true);
4233
4269
  if (!pen.calculative) {
@@ -4245,7 +4281,7 @@ var Canvas = /** @class */ (function () {
4245
4281
  }
4246
4282
  pen.calculative.canvas = _this;
4247
4283
  });
4248
- pens_9.reverse().forEach(function (aPen) {
4284
+ pens_8.reverse().forEach(function (aPen) {
4249
4285
  var pen = _this.store.data.pens.find(function (i) { return i.id === aPen.id; });
4250
4286
  var rect = _this.getPenRect(pen, action.origin, action.scale);
4251
4287
  _this.setPenRect(pen, rect, false);
@@ -5397,8 +5433,18 @@ var Canvas = /** @class */ (function () {
5397
5433
  }
5398
5434
  }
5399
5435
  else {
5400
- offsetX = pt.x - this.store.activeAnchor.x;
5401
- offsetY = pt.y - this.store.activeAnchor.y;
5436
+ if (!keyOptions.ctrlKey && keyOptions.shiftKey) {
5437
+ offsetX = pt.x - this.store.activeAnchor.x;
5438
+ offsetY = 0;
5439
+ }
5440
+ else if (keyOptions.ctrlKey && !keyOptions.shiftKey) {
5441
+ offsetX = 0;
5442
+ offsetY = pt.y - this.store.activeAnchor.y;
5443
+ }
5444
+ else {
5445
+ offsetX = pt.x - this.store.activeAnchor.x;
5446
+ offsetY = pt.y - this.store.activeAnchor.y;
5447
+ }
5402
5448
  }
5403
5449
  translatePoint(this.store.activeAnchor, offsetX, offsetY);
5404
5450
  if (this.store.hover &&
@@ -6369,15 +6415,15 @@ var Canvas = /** @class */ (function () {
6369
6415
  var e_21, _a;
6370
6416
  var retPens = [];
6371
6417
  try {
6372
- for (var pens_10 = __values(pens), pens_10_1 = pens_10.next(); !pens_10_1.done; pens_10_1 = pens_10.next()) {
6373
- var pen = pens_10_1.value;
6418
+ for (var pens_9 = __values(pens), pens_9_1 = pens_9.next(); !pens_9_1.done; pens_9_1 = pens_9.next()) {
6419
+ var pen = pens_9_1.value;
6374
6420
  retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
6375
6421
  }
6376
6422
  }
6377
6423
  catch (e_21_1) { e_21 = { error: e_21_1 }; }
6378
6424
  finally {
6379
6425
  try {
6380
- if (pens_10_1 && !pens_10_1.done && (_a = pens_10.return)) _a.call(pens_10);
6426
+ if (pens_9_1 && !pens_9_1.done && (_a = pens_9.return)) _a.call(pens_9);
6381
6427
  }
6382
6428
  finally { if (e_21) throw e_21.error; }
6383
6429
  }
@@ -7217,9 +7263,17 @@ var Canvas = /** @class */ (function () {
7217
7263
  return canvas.toDataURL();
7218
7264
  };
7219
7265
  Canvas.prototype.activeToPng = function (padding) {
7266
+ if (padding === void 0) { padding = 2; }
7267
+ return this.pensToPng(this.store.active, padding);
7268
+ };
7269
+ Canvas.prototype.pensToPng = function (pens, padding) {
7220
7270
  var e_24, _a;
7271
+ if (pens === void 0) { pens = this.store.active; }
7221
7272
  if (padding === void 0) { padding = 2; }
7222
- var allPens = this.getAllByPens(this.store.active);
7273
+ if (pens.length === 0) {
7274
+ return;
7275
+ }
7276
+ var allPens = this.getAllByPens(pens);
7223
7277
  var ids = allPens.map(function (pen) { return pen.id; });
7224
7278
  var rect = getRect(allPens);
7225
7279
  if (!isFinite(rect.width)) {