@meta2d/core 1.0.11 → 1.0.13

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.11",
3
+ "version": "1.0.13",
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",
@@ -198,6 +198,7 @@ export declare class Canvas {
198
198
  inactive(drawing?: boolean): void;
199
199
  active(pens: Pen[], emit?: boolean): void;
200
200
  getSizeCPs(): void;
201
+ getSpecialAngle(to: Point, last: Point): void;
201
202
  onResize: () => void;
202
203
  onScroll: () => void;
203
204
  calibrateMouse: (pt: Point) => Point;
@@ -360,6 +361,7 @@ export declare class Canvas {
360
361
  private ondblclick;
361
362
  showInput: (pen: Pen, rect?: Rect, background?: string) => void;
362
363
  setInputStyle: (pen: Pen) => void;
364
+ convertSpecialCharacter(str: any): any;
363
365
  hideInput: () => void;
364
366
  private createInput;
365
367
  clearDropdownList(): void;
@@ -930,6 +930,19 @@ var Canvas = /** @class */ (function () {
930
930
  _this.hoverType = HoverType.None;
931
931
  }
932
932
  }
933
+ else if (_this.hoverType === HoverType.NodeAnchor) {
934
+ //钢笔模式下 可以连节点锚点
935
+ _this.drawingLineName = _this.store.options.drawingLineName;
936
+ var pt = {
937
+ id: s8(),
938
+ x: _this.store.hoverAnchor.x,
939
+ y: _this.store.hoverAnchor.y,
940
+ };
941
+ _this.drawingLine = _this.createDrawingLine(pt);
942
+ _this.drawingLine.calculative.activeAnchor = pt;
943
+ connectLine(_this.store.hover, _this.store.hoverAnchor, _this.drawingLine, pt);
944
+ // this.drawline();
945
+ }
933
946
  else if (!_this.drawingLine && _this.drawingLineName !== 'curve') {
934
947
  _this.inactive(true);
935
948
  var pt = { id: s8(), x: e.x, y: e.y };
@@ -1232,58 +1245,8 @@ var Canvas = /** @class */ (function () {
1232
1245
  _this.drawingLine.calculative.worldAnchors[_this.drawingLine.calculative.worldAnchors.length - 2].y;
1233
1246
  }
1234
1247
  else if (e.shiftKey && e.ctrlKey) {
1235
- //快捷定位到特殊角度
1236
1248
  var last = _this.drawingLine.calculative.worldAnchors[_this.drawingLine.calculative.worldAnchors.length - 2];
1237
- var angle = 0;
1238
- var angleArr = [0, 30, 45, 60, 90, 120, 150, 135, 180];
1239
- //获取实际角度
1240
- if (to.x - last.x !== 0) {
1241
- angle =
1242
- (Math.atan((last.y - to.y) / (to.x - last.x)) * 180) / Math.PI;
1243
- if (to.x < last.x) {
1244
- if (angle > 0) {
1245
- angle -= 180;
1246
- }
1247
- else {
1248
- angle += 180;
1249
- }
1250
- }
1251
- }
1252
- else {
1253
- if (last.y > to.y) {
1254
- angle = 90;
1255
- }
1256
- else if (last.y < to.y) {
1257
- angle = -90;
1258
- }
1259
- }
1260
- //取最近角度
1261
- var _min = 999;
1262
- var index = -1;
1263
- for (var i = 0; i < angleArr.length; i++) {
1264
- if (angle < 0) {
1265
- if (Math.abs(angle + angleArr[i]) < _min) {
1266
- index = i;
1267
- _min = Math.abs(angle + angleArr[i]);
1268
- }
1269
- }
1270
- else {
1271
- if (Math.abs(angle - angleArr[i]) < _min) {
1272
- index = i;
1273
- _min = Math.abs(angle - angleArr[i]);
1274
- }
1275
- }
1276
- }
1277
- if (angle < 0) {
1278
- angle = -angleArr[index];
1279
- }
1280
- else {
1281
- angle = angleArr[index];
1282
- }
1283
- var length_1 = Math.sqrt((last.x - to.x) * (last.x - to.x) +
1284
- (last.y - to.y) * (last.y - to.y));
1285
- to.x = last.x + Math.cos((angle / 180) * Math.PI) * length_1;
1286
- to.y = last.y - Math.sin((angle / 180) * Math.PI) * length_1;
1249
+ _this.getSpecialAngle(to, last);
1287
1250
  }
1288
1251
  }
1289
1252
  _this.drawline();
@@ -2429,6 +2392,7 @@ var Canvas = /** @class */ (function () {
2429
2392
  .replace(/\<br\>/g, '')
2430
2393
  .replace(/&nbsp;/g, ' ')
2431
2394
  .replace(/(<([^>]+)>)/gi, '');
2395
+ _this.inputDiv.dataset.value = _this.convertSpecialCharacter(_this.inputDiv.dataset.value);
2432
2396
  if (pen.onInput) {
2433
2397
  pen.onInput(pen, _this.inputDiv.dataset.value);
2434
2398
  }
@@ -3210,6 +3174,7 @@ var Canvas = /** @class */ (function () {
3210
3174
  setChildrenActive(pen);
3211
3175
  });
3212
3176
  (_b = this.store.active).push.apply(_b, __spreadArray([], __read(pens), false));
3177
+ this.activeRect = undefined;
3213
3178
  this.calcActiveRect();
3214
3179
  this.patchFlags = true;
3215
3180
  emit && this.store.emitter.emit('active', this.store.active);
@@ -3234,6 +3199,57 @@ var Canvas = /** @class */ (function () {
3234
3199
  _this.sizeCPs.push(p);
3235
3200
  });
3236
3201
  };
3202
+ Canvas.prototype.getSpecialAngle = function (to, last) {
3203
+ //快捷定位到特殊角度
3204
+ var angle = 0;
3205
+ var angleArr = [0, 30, 45, 60, 90, 120, 150, 135, 180];
3206
+ //获取实际角度
3207
+ if (to.x - last.x !== 0) {
3208
+ angle = (Math.atan((last.y - to.y) / (to.x - last.x)) * 180) / Math.PI;
3209
+ if (to.x < last.x) {
3210
+ if (angle > 0) {
3211
+ angle -= 180;
3212
+ }
3213
+ else {
3214
+ angle += 180;
3215
+ }
3216
+ }
3217
+ }
3218
+ else {
3219
+ if (last.y > to.y) {
3220
+ angle = 90;
3221
+ }
3222
+ else if (last.y < to.y) {
3223
+ angle = -90;
3224
+ }
3225
+ }
3226
+ //取最近角度
3227
+ var _min = 999;
3228
+ var index = -1;
3229
+ for (var i = 0; i < angleArr.length; i++) {
3230
+ if (angle < 0) {
3231
+ if (Math.abs(angle + angleArr[i]) < _min) {
3232
+ index = i;
3233
+ _min = Math.abs(angle + angleArr[i]);
3234
+ }
3235
+ }
3236
+ else {
3237
+ if (Math.abs(angle - angleArr[i]) < _min) {
3238
+ index = i;
3239
+ _min = Math.abs(angle - angleArr[i]);
3240
+ }
3241
+ }
3242
+ }
3243
+ if (angle < 0) {
3244
+ angle = -angleArr[index];
3245
+ }
3246
+ else {
3247
+ angle = angleArr[index];
3248
+ }
3249
+ var length = Math.sqrt((last.x - to.x) * (last.x - to.x) + (last.y - to.y) * (last.y - to.y));
3250
+ to.x = last.x + Math.cos((angle / 180) * Math.PI) * length;
3251
+ to.y = last.y - Math.sin((angle / 180) * Math.PI) * length;
3252
+ };
3237
3253
  Canvas.prototype.clearHover = function () {
3238
3254
  this.hoverType = HoverType.None;
3239
3255
  this.store.hover = null;
@@ -3246,7 +3262,9 @@ var Canvas = /** @class */ (function () {
3246
3262
  if (!anchor || anchor.locked > LockState.DisableEdit) {
3247
3263
  return HoverType.None;
3248
3264
  }
3249
- if (this.store.options.disableAnchor || pen.disableAnchor) {
3265
+ if ((!(pen.type && pen.calculative.active) &&
3266
+ this.store.options.disableAnchor) ||
3267
+ pen.disableAnchor) {
3250
3268
  return HoverType.None;
3251
3269
  }
3252
3270
  if ((this.mouseDown || this.drawingLine) &&
@@ -3551,6 +3569,9 @@ var Canvas = /** @class */ (function () {
3551
3569
  if (i > -1) {
3552
3570
  _this.store.data.pens.splice(i, 1);
3553
3571
  _this.store.pens[pen.id] = undefined;
3572
+ if (!pen.calculative) {
3573
+ pen.calculative = {};
3574
+ }
3554
3575
  pen.calculative.canvas = _this;
3555
3576
  _this.store.animates.delete(pen);
3556
3577
  _this.store.animateMap.delete(pen);
@@ -3592,8 +3613,12 @@ var Canvas = /** @class */ (function () {
3592
3613
  break;
3593
3614
  case EditType.Delete:
3594
3615
  action.pens.forEach(function (aPen) {
3616
+ var _a;
3595
3617
  var pen = deepClone(aPen, true);
3596
- _this.store.data.pens.splice(pen.calculative.layer, 0, pen);
3618
+ if (!pen.calculative) {
3619
+ pen.calculative = {};
3620
+ }
3621
+ _this.store.data.pens.splice((_a = pen.calculative) === null || _a === void 0 ? void 0 : _a.layer, 0, pen);
3597
3622
  // 先放进去,pens 可能是子节点在前,而父节点在后
3598
3623
  _this.store.pens[pen.id] = pen;
3599
3624
  pen.calculative.canvas = _this;
@@ -4165,6 +4190,7 @@ var Canvas = /** @class */ (function () {
4165
4190
  return;
4166
4191
  }
4167
4192
  scalePen(pen, s, center);
4193
+ pen.onScale && pen.onScale(pen);
4168
4194
  if (pen.isRuleLine) {
4169
4195
  // 扩大线的比例,若是放大,即不缩小,若是缩小,会放大
4170
4196
  var lineScale = s > 1 ? 1 : 1 / s / s;
@@ -4483,8 +4509,41 @@ var Canvas = /** @class */ (function () {
4483
4509
  translatePolylineAnchor(line, this.store.activeAnchor, pt);
4484
4510
  }
4485
4511
  else {
4486
- var offsetX = pt.x - this.store.activeAnchor.x;
4487
- var offsetY = pt.y - this.store.activeAnchor.y;
4512
+ var offsetX = 0;
4513
+ var offsetY = 0;
4514
+ if (line.lineName === 'line' &&
4515
+ line.calculative.worldAnchors[line.calculative.worldAnchors.length - 1] === this.store.activeAnchor) {
4516
+ if (keyOptions.ctrlKey && keyOptions.shiftKey) {
4517
+ var _pt = deepClone(pt);
4518
+ this.getSpecialAngle(_pt, line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2]);
4519
+ offsetX = _pt.x - this.store.activeAnchor.x;
4520
+ offsetY = _pt.y - this.store.activeAnchor.y;
4521
+ }
4522
+ else if (!keyOptions.ctrlKey && keyOptions.shiftKey) {
4523
+ var _pt = {
4524
+ x: pt.x,
4525
+ y: line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2].y,
4526
+ };
4527
+ offsetX = _pt.x - this.store.activeAnchor.x;
4528
+ offsetY = _pt.y - this.store.activeAnchor.y;
4529
+ }
4530
+ else if (keyOptions.ctrlKey && !keyOptions.shiftKey) {
4531
+ var _pt = {
4532
+ x: line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2].x,
4533
+ y: pt.y,
4534
+ };
4535
+ offsetX = _pt.x - this.store.activeAnchor.x;
4536
+ offsetY = _pt.y - this.store.activeAnchor.y;
4537
+ }
4538
+ else {
4539
+ offsetX = pt.x - this.store.activeAnchor.x;
4540
+ offsetY = pt.y - this.store.activeAnchor.y;
4541
+ }
4542
+ }
4543
+ else {
4544
+ offsetX = pt.x - this.store.activeAnchor.x;
4545
+ offsetY = pt.y - this.store.activeAnchor.y;
4546
+ }
4488
4547
  translatePoint(this.store.activeAnchor, offsetX, offsetY);
4489
4548
  if (this.store.hover &&
4490
4549
  this.store.hoverAnchor &&
@@ -4810,7 +4869,7 @@ var Canvas = /** @class */ (function () {
4810
4869
  k !== 'height' &&
4811
4870
  k !== 'initRect' &&
4812
4871
  (typeof pen[k] !== 'object' || k === 'lineDash')) {
4813
- if (k === 'fontSize') {
4872
+ if (k === 'fontSize' || k === 'lineWidth') {
4814
4873
  pen[k] =
4815
4874
  pen.calculative[k] / pen.calculative.canvas.store.data.scale;
4816
4875
  }
@@ -5582,6 +5641,12 @@ var Canvas = /** @class */ (function () {
5582
5641
  }
5583
5642
  });
5584
5643
  };
5644
+ Canvas.prototype.convertSpecialCharacter = function (str) {
5645
+ var arrEntities = { lt: '<', gt: '>', nbsp: ' ', amp: '&', quot: '"' };
5646
+ return str.replace(/&(lt|gt|nbsp|amp|quot);/gi, function (all, t) {
5647
+ return arrEntities[t];
5648
+ });
5649
+ };
5585
5650
  Canvas.prototype.createInput = function () {
5586
5651
  var _this = this;
5587
5652
  this.inputParent.classList.add('meta2d-input');
@@ -5828,6 +5893,10 @@ var Canvas = /** @class */ (function () {
5828
5893
  pen.calculative.gradient = undefined;
5829
5894
  pen.calculative.radialGradient = undefined;
5830
5895
  }
5896
+ if (data.gradientRadius) {
5897
+ pen.calculative.gradient = undefined;
5898
+ pen.calculative.radialGradient = undefined;
5899
+ }
5831
5900
  if (data.animateLineWidth) {
5832
5901
  pen.calculative.gradientAnimatePath = undefined;
5833
5902
  }