@meta2d/core 1.0.36 → 1.0.37

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,8 +1,8 @@
1
1
  {
2
2
  "name": "@meta2d/core",
3
- "version": "1.0.36",
3
+ "version": "1.0.37",
4
4
  "description": "@meta2d/core: Powerful, Beautiful, Simple, Open - Web-Based 2D At Its Best .",
5
- "main": "index.js",
5
+ "main": "index.ts",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
8
  "copy": "shx cp package.build.json ../../dist/core/package.json",
@@ -317,7 +317,8 @@ var Canvas = /** @class */ (function () {
317
317
  var _a, _b, _c;
318
318
  if (_this.store.data.locked >= LockState.DisableEdit &&
319
319
  e.target.tagName !== 'INPUT' &&
320
- e.target.tagName !== 'TEXTAREA') {
320
+ e.target.tagName !== 'TEXTAREA' &&
321
+ !e.target.dataset.meta2dIgnore) {
321
322
  _this.store.active.forEach(function (pen) {
322
323
  var _a;
323
324
  (_a = pen.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(pen, pen, e.key);
@@ -325,7 +326,8 @@ var Canvas = /** @class */ (function () {
325
326
  }
326
327
  if (_this.store.data.locked >= LockState.DisableEdit ||
327
328
  e.target.tagName === 'INPUT' ||
328
- e.target.tagName === 'TEXTAREA') {
329
+ e.target.tagName === 'TEXTAREA' ||
330
+ e.target.dataset.meta2dIgnore) {
329
331
  return;
330
332
  }
331
333
  if (_this.store.options.unavailableKeys.includes(e.key)) {
@@ -3693,28 +3695,27 @@ var Canvas = /** @class */ (function () {
3693
3695
  }
3694
3696
  }
3695
3697
  //取最近角度
3696
- var _min = 999;
3697
- var index = -1;
3698
- for (var i = 0; i < angleArr.length; i++) {
3699
- if (angle < 0) {
3700
- if (Math.abs(angle + angleArr[i]) < _min) {
3701
- index = i;
3702
- _min = Math.abs(angle + angleArr[i]);
3703
- }
3704
- }
3705
- else {
3706
- if (Math.abs(angle - angleArr[i]) < _min) {
3707
- index = i;
3708
- _min = Math.abs(angle - angleArr[i]);
3709
- }
3710
- }
3711
- }
3712
- if (angle < 0) {
3713
- angle = -angleArr[index];
3714
- }
3715
- else {
3716
- angle = angleArr[index];
3717
- }
3698
+ // let _min = 999;
3699
+ // let index = -1;
3700
+ // for (let i = 0; i < angleArr.length; i++) {
3701
+ // if (angle < 0) {
3702
+ // if (Math.abs(angle + angleArr[i]) < _min) {
3703
+ // index = i;
3704
+ // _min = Math.abs(angle + angleArr[i]);
3705
+ // }
3706
+ // } else {
3707
+ // if (Math.abs(angle - angleArr[i]) < _min) {
3708
+ // index = i;
3709
+ // _min = Math.abs(angle - angleArr[i]);
3710
+ // }
3711
+ // }
3712
+ // }
3713
+ // if (angle < 0) {
3714
+ // angle = -angleArr[index];
3715
+ // } else {
3716
+ // angle = angleArr[index];
3717
+ // }
3718
+ angle = Math.round(angle / 15) * 15;
3718
3719
  var length = Math.sqrt((last.x - to.x) * (last.x - to.x) + (last.y - to.y) * (last.y - to.y));
3719
3720
  to.x = last.x + Math.cos((angle / 180) * Math.PI) * length;
3720
3721
  to.y = last.y - Math.sin((angle / 180) * Math.PI) * length;
@@ -4109,6 +4110,59 @@ var Canvas = /** @class */ (function () {
4109
4110
  });
4110
4111
  action.type = EditType.Add;
4111
4112
  break;
4113
+ case EditType.Replace: {
4114
+ // undo pens则为新的pen
4115
+ var pens_9 = undo ? action.initPens : action.pens;
4116
+ var unPens_2 = undo ? action.pens : action.initPens;
4117
+ // 删除旧的
4118
+ unPens_2.forEach(function (aPen) {
4119
+ var _a;
4120
+ var pen = deepClone(aPen, true);
4121
+ var i = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
4122
+ if (i > -1) {
4123
+ (_a = pen.onDestroy) === null || _a === void 0 ? void 0 : _a.call(pen, _this.store.data.pens.find(function (i) { return i.id === pen.id; }));
4124
+ var i_1 = _this.store.data.pens.findIndex(function (item) { return item.id === pen.id; });
4125
+ _this.store.data.pens.splice(i_1, 1);
4126
+ _this.store.pens[pen.id] = undefined;
4127
+ if (!pen.calculative) {
4128
+ pen.calculative = {};
4129
+ }
4130
+ pen.calculative.canvas = _this;
4131
+ _this.store.animates.delete(pen);
4132
+ _this.store.animateMap.delete(pen);
4133
+ }
4134
+ });
4135
+ // 放置新的
4136
+ pens_9.reverse().forEach(function (aPen) {
4137
+ var _a, _b;
4138
+ var pen = deepClone(aPen, true);
4139
+ if (!pen.calculative) {
4140
+ pen.calculative = {};
4141
+ }
4142
+ _this.store.data.pens.splice(((_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.layer) !== -1
4143
+ ? (_b = pen.calculative) === null || _b === void 0 ? void 0 : _b.layer
4144
+ : _this.store.data.pens.length, 0, pen);
4145
+ // 先放进去,pens 可能是子节点在前,而父节点在后
4146
+ _this.store.pens[pen.id] = pen;
4147
+ if (pen.type && pen.lastConnected) {
4148
+ for (var key in pen.lastConnected) {
4149
+ _this.store.pens[key].connectedLines = pen.lastConnected[key];
4150
+ }
4151
+ }
4152
+ pen.calculative.canvas = _this;
4153
+ });
4154
+ pens_9.reverse().forEach(function (aPen) {
4155
+ var pen = _this.store.data.pens.find(function (i) { return i.id === aPen.id; });
4156
+ var rect = _this.getPenRect(pen, action.origin, action.scale);
4157
+ _this.setPenRect(pen, rect, false);
4158
+ pen.calculative.image = undefined;
4159
+ pen.calculative.backgroundImage = undefined;
4160
+ pen.calculative.strokeImage = undefined;
4161
+ _this.loadImage(pen);
4162
+ });
4163
+ action.type = EditType.Replace;
4164
+ break;
4165
+ }
4112
4166
  }
4113
4167
  if (action.type === EditType.Update) {
4114
4168
  var pens = __spreadArray(__spreadArray([], __read(action.pens), false), __read(action.initPens), false);
@@ -5208,25 +5262,29 @@ var Canvas = /** @class */ (function () {
5208
5262
  else {
5209
5263
  var offsetX = 0;
5210
5264
  var offsetY = 0;
5211
- if (line.lineName === 'line' &&
5212
- line.calculative.worldAnchors[line.calculative.worldAnchors.length - 1] === this.store.activeAnchor) {
5265
+ if (line.lineName === 'line') {
5266
+ var index = line.calculative.worldAnchors.findIndex(function (anchor) { return anchor.id === _this.store.activeAnchor.id; });
5267
+ if (index === 0) {
5268
+ index = 2;
5269
+ }
5270
+ var relativePt = line.calculative.worldAnchors[index - 1];
5213
5271
  if (keyOptions.ctrlKey && keyOptions.shiftKey) {
5214
5272
  var _pt = deepClone(pt);
5215
- this.getSpecialAngle(_pt, line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2]);
5273
+ this.getSpecialAngle(_pt, relativePt);
5216
5274
  offsetX = _pt.x - this.store.activeAnchor.x;
5217
5275
  offsetY = _pt.y - this.store.activeAnchor.y;
5218
5276
  }
5219
5277
  else if (!keyOptions.ctrlKey && keyOptions.shiftKey) {
5220
5278
  var _pt = {
5221
5279
  x: pt.x,
5222
- y: line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2].y,
5280
+ y: relativePt.y,
5223
5281
  };
5224
5282
  offsetX = _pt.x - this.store.activeAnchor.x;
5225
5283
  offsetY = _pt.y - this.store.activeAnchor.y;
5226
5284
  }
5227
5285
  else if (keyOptions.ctrlKey && !keyOptions.shiftKey) {
5228
5286
  var _pt = {
5229
- x: line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2].x,
5287
+ x: relativePt.x,
5230
5288
  y: pt.y,
5231
5289
  };
5232
5290
  offsetX = _pt.x - this.store.activeAnchor.x;
@@ -6196,15 +6254,15 @@ var Canvas = /** @class */ (function () {
6196
6254
  var e_21, _a;
6197
6255
  var retPens = [];
6198
6256
  try {
6199
- for (var pens_9 = __values(pens), pens_9_1 = pens_9.next(); !pens_9_1.done; pens_9_1 = pens_9.next()) {
6200
- var pen = pens_9_1.value;
6257
+ for (var pens_10 = __values(pens), pens_10_1 = pens_10.next(); !pens_10_1.done; pens_10_1 = pens_10.next()) {
6258
+ var pen = pens_10_1.value;
6201
6259
  retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
6202
6260
  }
6203
6261
  }
6204
6262
  catch (e_21_1) { e_21 = { error: e_21_1 }; }
6205
6263
  finally {
6206
6264
  try {
6207
- if (pens_9_1 && !pens_9_1.done && (_a = pens_9.return)) _a.call(pens_9);
6265
+ if (pens_10_1 && !pens_10_1.done && (_a = pens_10.return)) _a.call(pens_10);
6208
6266
  }
6209
6267
  finally { if (e_21) throw e_21.error; }
6210
6268
  }
@@ -6330,6 +6388,8 @@ var Canvas = /** @class */ (function () {
6330
6388
  this.render();
6331
6389
  // TODO: 连线的删除 ,连接的 node 的 connectLines 会变化(删除 node ,line 的 anchors 类似),未记历史记录
6332
6390
  if (history) {
6391
+ if (deletePens.length === 0)
6392
+ return [2 /*return*/];
6333
6393
  this.pushHistory({ type: EditType.Delete, pens: deletePens });
6334
6394
  }
6335
6395
  this.store.emitter.emit('delete', pens);