@meta2d/core 1.0.3 → 1.0.5

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.3",
3
+ "version": "1.0.5",
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",
@@ -237,10 +237,6 @@ var Canvas = /** @class */ (function () {
237
237
  }
238
238
  e.preventDefault();
239
239
  e.stopPropagation();
240
- if (_this.store.options.scroll && !e.ctrlKey && !e.metaKey && _this.scroll) {
241
- _this.scroll.wheel(e.deltaY < 0);
242
- return;
243
- }
244
240
  if (_this.store.options.disableScale) {
245
241
  return;
246
242
  }
@@ -250,6 +246,29 @@ var Canvas = /** @class */ (function () {
250
246
  return;
251
247
  if (_this.store.data.locked === LockState.DisableMoveScale)
252
248
  return;
249
+ //禁止触摸屏双指缩放操作
250
+ if (_this.store.options.disableTouchPadScale &&
251
+ e.ctrlKey &&
252
+ e.deltaY !== 0) {
253
+ return;
254
+ }
255
+ //window触控板只允许平移 触摸屏一般不超过100
256
+ var isWin = navigator.userAgent.indexOf('Win') !== -1;
257
+ if (isWin && !e.ctrlKey && Math.abs(e.deltaY) < 100) {
258
+ _this.translate(-e.deltaX, -e.deltaY);
259
+ return;
260
+ }
261
+ //mac触控板只允许平移(排除普通鼠标的情况)
262
+ var isMac = /macintosh|mac os x/i.test(navigator.userAgent) ||
263
+ navigator.platform.indexOf('Mac') !== -1;
264
+ if (isMac && !e.ctrlKey && e.wheelDeltaY % 240 !== 0) {
265
+ _this.translate(-e.deltaX, -e.deltaY);
266
+ return;
267
+ }
268
+ if (_this.store.options.scroll && !e.ctrlKey && !e.metaKey && _this.scroll) {
269
+ _this.scroll.wheel(e.deltaY < 0);
270
+ return;
271
+ }
253
272
  // 触摸板平移
254
273
  var isTouchPad = !(!e.deltaX && e.deltaY);
255
274
  var now = performance.now();
@@ -542,6 +561,20 @@ var Canvas = /** @class */ (function () {
542
561
  _this.store.options.disableAnchor = !_this.store.options.disableAnchor;
543
562
  _this.store.emitter.emit('disableAnchor', _this.store.options.disableAnchor);
544
563
  break;
564
+ case '=':
565
+ if (e.ctrlKey || e.metaKey) {
566
+ _this.scale(_this.store.data.scale + 0.1);
567
+ e.preventDefault();
568
+ e.stopPropagation();
569
+ }
570
+ break;
571
+ case '-':
572
+ if (e.ctrlKey || e.metaKey) {
573
+ _this.scale(_this.store.data.scale - 0.1);
574
+ e.preventDefault();
575
+ e.stopPropagation();
576
+ }
577
+ break;
545
578
  }
546
579
  _this.render(false);
547
580
  };
@@ -779,7 +812,7 @@ var Canvas = /** @class */ (function () {
779
812
  }
780
813
  //shift 快捷添加锚点并连线
781
814
  if (!_this.store.options.autoAnchor && !_this.drawingLine) {
782
- if (e.shiftKey) {
815
+ if (e.shiftKey && !e.ctrlKey) {
783
816
  _this.setAnchor(_this.store.pointAt);
784
817
  _this.drawingLineName = _this.store.options.drawingLineName;
785
818
  var anchor = _this.store.activeAnchor;
@@ -2310,21 +2343,26 @@ var Canvas = /** @class */ (function () {
2310
2343
  : pen.textHeight * font_scale) + "px;";
2311
2344
  }
2312
2345
  else {
2313
- var tem = pen.height / scale - (pen.textTop || 0);
2346
+ var tem = pen.calculative.worldRect.height / scale - (pen.textTop || 0);
2314
2347
  if (tem < 0) {
2315
2348
  tem = 0;
2316
2349
  }
2317
2350
  style += "height:" + (pen.fontSize * scale < 12 ? tem * font_scale : tem * scale * font_scale) + "px;";
2318
2351
  }
2352
+ var _textWidth = null;
2319
2353
  if (pen.textWidth) {
2354
+ _textWidth =
2355
+ (pen.textWidth < 1 && pen.textWidth) > -1
2356
+ ? pen.textWidth * pen.calculative.worldRect.width
2357
+ : pen.textWidth;
2320
2358
  if (pen.whiteSpace !== 'pre-line') {
2321
- if (pen.textWidth < pen.fontSize) {
2359
+ if (_textWidth < pen.fontSize) {
2322
2360
  style += "width:" + pen.fontSize * 1.2 * font_scale + "px;";
2323
2361
  }
2324
2362
  else {
2325
2363
  style += "width:" + (scale > 1
2326
- ? pen.textWidth * font_scale * scale
2327
- : pen.textWidth * font_scale) + "px;";
2364
+ ? _textWidth * font_scale * scale
2365
+ : _textWidth * font_scale) + "px;";
2328
2366
  }
2329
2367
  }
2330
2368
  }
@@ -2357,8 +2395,10 @@ var Canvas = /** @class */ (function () {
2357
2395
  }
2358
2396
  if (pen.whiteSpace !== 'nowrap') {
2359
2397
  var textWidth = pen.fontSize * 1.2 * pen.text.length;
2360
- var contentWidth = (pen.textWidth || pen.width / scale) *
2361
- Math.floor(pen.height / scale / (pen.lineHeight * pen.fontSize));
2398
+ var contentWidth = (_textWidth || pen.calculative.worldRect.width / scale) *
2399
+ Math.floor(pen.calculative.worldRect.height /
2400
+ scale /
2401
+ (pen.lineHeight * pen.fontSize));
2362
2402
  if (textWidth > contentWidth) {
2363
2403
  style += 'justify-content: start;';
2364
2404
  }
@@ -3484,13 +3524,11 @@ var Canvas = /** @class */ (function () {
3484
3524
  var _this = this;
3485
3525
  var before = this.store.histories[this.store.historyIndex];
3486
3526
  if (before && before.type === EditType.Add) {
3527
+ var pens_6 = [];
3487
3528
  before.pens.forEach(function (pen) {
3488
- if (!pen.calculative) {
3489
- return;
3490
- }
3491
- pen.calculative.canvas = _this;
3529
+ pens_6.push(_this.store.pens[pen.id]);
3492
3530
  });
3493
- this.active(before.pens);
3531
+ this.active(pens_6);
3494
3532
  }
3495
3533
  };
3496
3534
  Canvas.prototype.doEditAction = function (action, undo) {
@@ -4005,6 +4043,22 @@ var Canvas = /** @class */ (function () {
4005
4043
  });
4006
4044
  }
4007
4045
  pen.type && this.initLineRect(pen);
4046
+ if (pen.calculative.gradientTimer) {
4047
+ clearTimeout(pen.calculative.gradientTimer);
4048
+ }
4049
+ pen.calculative.gradientTimer = setTimeout(function () {
4050
+ if (pen.calculative.lineGradient) {
4051
+ pen.calculative.lineGradient = null;
4052
+ }
4053
+ if (pen.calculative.gradient) {
4054
+ pen.calculative.gradient = null;
4055
+ }
4056
+ if (pen.calculative.radialGradient) {
4057
+ pen.calculative.radialGradient = null;
4058
+ }
4059
+ _this.patchFlags = true;
4060
+ pen.calculative.gradientTimer = undefined;
4061
+ }, 50);
4008
4062
  };
4009
4063
  Canvas.prototype.translate = function (x, y) {
4010
4064
  if (x === void 0) { x = 0; }
@@ -4253,6 +4307,7 @@ var Canvas = /** @class */ (function () {
4253
4307
  }, 200);
4254
4308
  };
4255
4309
  Canvas.prototype.movePens = function (e) {
4310
+ var _a, _b;
4256
4311
  if (!this.activeRect || this.store.data.locked) {
4257
4312
  return;
4258
4313
  }
@@ -4262,9 +4317,8 @@ var Canvas = /** @class */ (function () {
4262
4317
  }
4263
4318
  if (!this.store.options.moveConnectedLine &&
4264
4319
  this.store.active.length === 1 &&
4265
- (this.store.active[0].anchors[0].connectTo ||
4266
- this.store.active[0].anchors[this.store.active[0].anchors.length - 1]
4267
- .connectTo)) {
4320
+ (((_a = this.store.active[0].anchors[0]) === null || _a === void 0 ? void 0 : _a.connectTo) ||
4321
+ ((_b = this.store.active[0].anchors[this.store.active[0].anchors.length - 1]) === null || _b === void 0 ? void 0 : _b.connectTo))) {
4268
4322
  return;
4269
4323
  }
4270
4324
  if (!this.movingPens) {
@@ -4288,7 +4342,7 @@ var Canvas = /** @class */ (function () {
4288
4342
  this.clearDock();
4289
4343
  var moveDock = this.customMoveDock || calcMoveDock;
4290
4344
  this.dock = moveDock(this.store, rect, this.movingPens, offset);
4291
- var _a = this.dock, xDock = _a.xDock, yDock = _a.yDock;
4345
+ var _c = this.dock, xDock = _c.xDock, yDock = _c.yDock;
4292
4346
  var dockPen = void 0;
4293
4347
  if (xDock) {
4294
4348
  offset.x += xDock.step;
@@ -4341,11 +4395,12 @@ var Canvas = /** @class */ (function () {
4341
4395
  */
4342
4396
  Canvas.prototype.initMovingPens = function () {
4343
4397
  var _this = this;
4398
+ var _a, _b;
4344
4399
  if (!this.store.options.moveConnectedLine) {
4345
4400
  for (var i = 0; i < this.store.active.length; i++) {
4346
4401
  var pen = this.store.active[i];
4347
- if (pen.anchors[0].connectTo ||
4348
- pen.anchors[pen.anchors.length - 1].connectTo) {
4402
+ if (((_a = pen.anchors[0]) === null || _a === void 0 ? void 0 : _a.connectTo) ||
4403
+ ((_b = pen.anchors[pen.anchors.length - 1]) === null || _b === void 0 ? void 0 : _b.connectTo)) {
4349
4404
  this.store.active.splice(i, 1);
4350
4405
  pen.calculative.active = undefined;
4351
4406
  --i;
@@ -4377,7 +4432,7 @@ var Canvas = /** @class */ (function () {
4377
4432
  };
4378
4433
  Canvas.prototype.moveLineAnchor = function (pt, keyOptions) {
4379
4434
  var _this = this;
4380
- var _a, _b, _c;
4435
+ var _a, _b, _c, _d;
4381
4436
  if (!this.activeRect || this.store.data.locked) {
4382
4437
  return;
4383
4438
  }
@@ -4389,7 +4444,7 @@ var Canvas = /** @class */ (function () {
4389
4444
  disconnectLine(pen, getAnchor(pen, this.store.activeAnchor.anchorId), this.store.pens[this.store.activeAnchor.penId], this.store.activeAnchor);
4390
4445
  }
4391
4446
  var anchorId = this.store.activeAnchor.id;
4392
- var connectedLine = (_b = this.store.pens[this.store.activeAnchor.penId].connectedLines) === null || _b === void 0 ? void 0 : _b.filter(function (item) { return item.anchor === anchorId; });
4447
+ var connectedLine = (_c = (_b = this.store.pens[this.store.activeAnchor.penId]) === null || _b === void 0 ? void 0 : _b.connectedLines) === null || _c === void 0 ? void 0 : _c.filter(function (item) { return item.anchor === anchorId; });
4393
4448
  if (connectedLine && connectedLine.length > 0) {
4394
4449
  connectedLine.forEach(function (connected) {
4395
4450
  var pen = _this.store.pens[connected.lineId];
@@ -4415,7 +4470,7 @@ var Canvas = /** @class */ (function () {
4415
4470
  to.prev = undefined;
4416
4471
  // 重新自动计算连线
4417
4472
  if (line.lineName !== 'polyline') {
4418
- (_c = this[line.lineName]) === null || _c === void 0 ? void 0 : _c.call(this, this.store, line);
4473
+ (_d = this[line.lineName]) === null || _d === void 0 ? void 0 : _d.call(this, this.store, line);
4419
4474
  }
4420
4475
  }
4421
4476
  }
@@ -4638,7 +4693,7 @@ var Canvas = /** @class */ (function () {
4638
4693
  return;
4639
4694
  }
4640
4695
  var initPens = !doing && deepClone(pens, true);
4641
- translateRect(this.activeRect, x, y);
4696
+ this.activeRect && translateRect(this.activeRect, x, y);
4642
4697
  var containChildPens = this.getAllByPens(pens);
4643
4698
  pens.forEach(function (pen) {
4644
4699
  var _a, _b;
@@ -4677,7 +4732,7 @@ var Canvas = /** @class */ (function () {
4677
4732
  _this.updateLines(pen);
4678
4733
  (_b = pen.onMove) === null || _b === void 0 ? void 0 : _b.call(pen, pen);
4679
4734
  });
4680
- this.getSizeCPs();
4735
+ this.activeRect && this.getSizeCPs();
4681
4736
  this.render();
4682
4737
  this.tooltip.translate(x, y);
4683
4738
  if (!doing) {
@@ -5213,15 +5268,15 @@ var Canvas = /** @class */ (function () {
5213
5268
  var e_20, _a;
5214
5269
  var retPens = [];
5215
5270
  try {
5216
- for (var pens_6 = __values(pens), pens_6_1 = pens_6.next(); !pens_6_1.done; pens_6_1 = pens_6.next()) {
5217
- var pen = pens_6_1.value;
5271
+ for (var pens_7 = __values(pens), pens_7_1 = pens_7.next(); !pens_7_1.done; pens_7_1 = pens_7.next()) {
5272
+ var pen = pens_7_1.value;
5218
5273
  retPens.push.apply(retPens, __spreadArray([], __read(deepClone(getAllChildren(pen, this.store), true)), false));
5219
5274
  }
5220
5275
  }
5221
5276
  catch (e_20_1) { e_20 = { error: e_20_1 }; }
5222
5277
  finally {
5223
5278
  try {
5224
- if (pens_6_1 && !pens_6_1.done && (_a = pens_6.return)) _a.call(pens_6);
5279
+ if (pens_7_1 && !pens_7_1.done && (_a = pens_7.return)) _a.call(pens_7);
5225
5280
  }
5226
5281
  finally { if (e_20) throw e_20.error; }
5227
5282
  }