@meta2d/core 1.0.12 → 1.0.14

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.12",
3
+ "version": "1.0.14",
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;
@@ -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();
@@ -2550,17 +2513,22 @@ var Canvas = /** @class */ (function () {
2550
2513
  _this.store.emitter.emit('valueUpdate', pen);
2551
2514
  };
2552
2515
  this.canvasImageBottom = new CanvasImage(parentElement, store, true);
2516
+ this.canvasImageBottom.canvas.style.zIndex = '1';
2553
2517
  parentElement.appendChild(this.canvas);
2554
2518
  this.canvas.style.position = 'absolute';
2555
2519
  this.canvas.style.backgroundRepeat = 'no-repeat';
2556
2520
  this.canvas.style.backgroundSize = '100% 100%';
2521
+ this.canvas.style.zIndex = '2';
2557
2522
  this.canvasImage = new CanvasImage(parentElement, store);
2523
+ this.canvasImage.canvas.style.zIndex = '3';
2558
2524
  this.magnifierCanvas = new MagnifierCanvas(this, parentElement, store);
2525
+ this.magnifierCanvas.canvas.style.zIndex = '4';
2559
2526
  this.externalElements.style.position = 'absolute';
2560
2527
  this.externalElements.style.left = '0';
2561
2528
  this.externalElements.style.top = '0';
2562
2529
  this.externalElements.style.outline = 'none';
2563
2530
  this.externalElements.style.background = 'transparent';
2531
+ this.externalElements.style.zIndex = '4';
2564
2532
  parentElement.style.position = 'relative';
2565
2533
  parentElement.appendChild(this.externalElements);
2566
2534
  this.createInput();
@@ -2780,6 +2748,7 @@ var Canvas = /** @class */ (function () {
2780
2748
  img.onerror = function (e) {
2781
2749
  reject(e);
2782
2750
  };
2751
+ img.crossOrigin = 'anonymous';
2783
2752
  img.src = url;
2784
2753
  })];
2785
2754
  }
@@ -3236,6 +3205,57 @@ var Canvas = /** @class */ (function () {
3236
3205
  _this.sizeCPs.push(p);
3237
3206
  });
3238
3207
  };
3208
+ Canvas.prototype.getSpecialAngle = function (to, last) {
3209
+ //快捷定位到特殊角度
3210
+ var angle = 0;
3211
+ var angleArr = [0, 30, 45, 60, 90, 120, 150, 135, 180];
3212
+ //获取实际角度
3213
+ if (to.x - last.x !== 0) {
3214
+ angle = (Math.atan((last.y - to.y) / (to.x - last.x)) * 180) / Math.PI;
3215
+ if (to.x < last.x) {
3216
+ if (angle > 0) {
3217
+ angle -= 180;
3218
+ }
3219
+ else {
3220
+ angle += 180;
3221
+ }
3222
+ }
3223
+ }
3224
+ else {
3225
+ if (last.y > to.y) {
3226
+ angle = 90;
3227
+ }
3228
+ else if (last.y < to.y) {
3229
+ angle = -90;
3230
+ }
3231
+ }
3232
+ //取最近角度
3233
+ var _min = 999;
3234
+ var index = -1;
3235
+ for (var i = 0; i < angleArr.length; i++) {
3236
+ if (angle < 0) {
3237
+ if (Math.abs(angle + angleArr[i]) < _min) {
3238
+ index = i;
3239
+ _min = Math.abs(angle + angleArr[i]);
3240
+ }
3241
+ }
3242
+ else {
3243
+ if (Math.abs(angle - angleArr[i]) < _min) {
3244
+ index = i;
3245
+ _min = Math.abs(angle - angleArr[i]);
3246
+ }
3247
+ }
3248
+ }
3249
+ if (angle < 0) {
3250
+ angle = -angleArr[index];
3251
+ }
3252
+ else {
3253
+ angle = angleArr[index];
3254
+ }
3255
+ var length = Math.sqrt((last.x - to.x) * (last.x - to.x) + (last.y - to.y) * (last.y - to.y));
3256
+ to.x = last.x + Math.cos((angle / 180) * Math.PI) * length;
3257
+ to.y = last.y - Math.sin((angle / 180) * Math.PI) * length;
3258
+ };
3239
3259
  Canvas.prototype.clearHover = function () {
3240
3260
  this.hoverType = HoverType.None;
3241
3261
  this.store.hover = null;
@@ -3248,7 +3268,9 @@ var Canvas = /** @class */ (function () {
3248
3268
  if (!anchor || anchor.locked > LockState.DisableEdit) {
3249
3269
  return HoverType.None;
3250
3270
  }
3251
- if (this.store.options.disableAnchor || pen.disableAnchor) {
3271
+ if ((!(pen.type && pen.calculative.active) &&
3272
+ this.store.options.disableAnchor) ||
3273
+ pen.disableAnchor) {
3252
3274
  return HoverType.None;
3253
3275
  }
3254
3276
  if ((this.mouseDown || this.drawingLine) &&
@@ -4174,6 +4196,7 @@ var Canvas = /** @class */ (function () {
4174
4196
  return;
4175
4197
  }
4176
4198
  scalePen(pen, s, center);
4199
+ pen.onScale && pen.onScale(pen);
4177
4200
  if (pen.isRuleLine) {
4178
4201
  // 扩大线的比例,若是放大,即不缩小,若是缩小,会放大
4179
4202
  var lineScale = s > 1 ? 1 : 1 / s / s;
@@ -4492,8 +4515,41 @@ var Canvas = /** @class */ (function () {
4492
4515
  translatePolylineAnchor(line, this.store.activeAnchor, pt);
4493
4516
  }
4494
4517
  else {
4495
- var offsetX = pt.x - this.store.activeAnchor.x;
4496
- var offsetY = pt.y - this.store.activeAnchor.y;
4518
+ var offsetX = 0;
4519
+ var offsetY = 0;
4520
+ if (line.lineName === 'line' &&
4521
+ line.calculative.worldAnchors[line.calculative.worldAnchors.length - 1] === this.store.activeAnchor) {
4522
+ if (keyOptions.ctrlKey && keyOptions.shiftKey) {
4523
+ var _pt = deepClone(pt);
4524
+ this.getSpecialAngle(_pt, line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2]);
4525
+ offsetX = _pt.x - this.store.activeAnchor.x;
4526
+ offsetY = _pt.y - this.store.activeAnchor.y;
4527
+ }
4528
+ else if (!keyOptions.ctrlKey && keyOptions.shiftKey) {
4529
+ var _pt = {
4530
+ x: pt.x,
4531
+ y: line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2].y,
4532
+ };
4533
+ offsetX = _pt.x - this.store.activeAnchor.x;
4534
+ offsetY = _pt.y - this.store.activeAnchor.y;
4535
+ }
4536
+ else if (keyOptions.ctrlKey && !keyOptions.shiftKey) {
4537
+ var _pt = {
4538
+ x: line.calculative.worldAnchors[line.calculative.worldAnchors.length - 2].x,
4539
+ y: pt.y,
4540
+ };
4541
+ offsetX = _pt.x - this.store.activeAnchor.x;
4542
+ offsetY = _pt.y - this.store.activeAnchor.y;
4543
+ }
4544
+ else {
4545
+ offsetX = pt.x - this.store.activeAnchor.x;
4546
+ offsetY = pt.y - this.store.activeAnchor.y;
4547
+ }
4548
+ }
4549
+ else {
4550
+ offsetX = pt.x - this.store.activeAnchor.x;
4551
+ offsetY = pt.y - this.store.activeAnchor.y;
4552
+ }
4497
4553
  translatePoint(this.store.activeAnchor, offsetX, offsetY);
4498
4554
  if (this.store.hover &&
4499
4555
  this.store.hoverAnchor &&
@@ -4819,7 +4875,7 @@ var Canvas = /** @class */ (function () {
4819
4875
  k !== 'height' &&
4820
4876
  k !== 'initRect' &&
4821
4877
  (typeof pen[k] !== 'object' || k === 'lineDash')) {
4822
- if (k === 'fontSize') {
4878
+ if (k === 'fontSize' || k === 'lineWidth') {
4823
4879
  pen[k] =
4824
4880
  pen.calculative[k] / pen.calculative.canvas.store.data.scale;
4825
4881
  }
@@ -5175,7 +5231,8 @@ var Canvas = /** @class */ (function () {
5175
5231
  });
5176
5232
  Canvas.prototype.copy = function (pens) {
5177
5233
  return __awaiter(this, void 0, void 0, function () {
5178
- var page, _a, origin, scale, clipboard, _b;
5234
+ var page, _a, origin, scale, copyPens, clipboard, _b;
5235
+ var _this = this;
5179
5236
  return __generator(this, function (_c) {
5180
5237
  switch (_c.label) {
5181
5238
  case 0:
@@ -5184,9 +5241,20 @@ var Canvas = /** @class */ (function () {
5184
5241
  this.store.clipboard = undefined;
5185
5242
  localStorage.removeItem(this.clipboardName);
5186
5243
  sessionStorage.setItem('page', page);
5244
+ copyPens = this.getAllByPens(deepClone(pens || this.store.active, true));
5245
+ //根据pens顺序复制
5246
+ copyPens.forEach(function (activePen) {
5247
+ activePen.copyIndex = _this.store.data.pens.findIndex(function (pen) { return pen.id === activePen.id; });
5248
+ });
5249
+ copyPens.sort(function (a, b) {
5250
+ return a.copyIndex - b.copyIndex;
5251
+ });
5252
+ copyPens.forEach(function (activePen) {
5253
+ delete activePen.copyIndex;
5254
+ });
5187
5255
  clipboard = {
5188
5256
  meta2d: true,
5189
- pens: this.getAllByPens(deepClone(pens || this.store.active, true)),
5257
+ pens: copyPens,
5190
5258
  origin: deepClone(origin),
5191
5259
  scale: scale,
5192
5260
  page: page,
@@ -5843,6 +5911,10 @@ var Canvas = /** @class */ (function () {
5843
5911
  pen.calculative.gradient = undefined;
5844
5912
  pen.calculative.radialGradient = undefined;
5845
5913
  }
5914
+ if (data.gradientRadius) {
5915
+ pen.calculative.gradient = undefined;
5916
+ pen.calculative.radialGradient = undefined;
5917
+ }
5846
5918
  if (data.animateLineWidth) {
5847
5919
  pen.calculative.gradientAnimatePath = undefined;
5848
5920
  }