@meta2d/core 1.0.31 → 1.0.33
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 +2 -2
- package/src/canvas/canvas.d.ts +1 -1
- package/src/canvas/canvas.js +193 -12
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +4 -4
- package/src/core.js +51 -21
- package/src/core.js.map +1 -1
- package/src/event/event.d.ts +3 -0
- package/src/event/event.js.map +1 -1
- package/src/options.d.ts +4 -0
- package/src/options.js.map +1 -1
- package/src/pen/render.js +5 -2
- package/src/pen/render.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meta2d/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
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",
|
|
@@ -36,4 +36,4 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"gitHead": "78f2a53ca1839c89b56e2e498d17ba4eb987ad14"
|
|
39
|
-
}
|
|
39
|
+
}
|
package/src/canvas/canvas.d.ts
CHANGED
|
@@ -412,7 +412,7 @@ export declare class Canvas {
|
|
|
412
412
|
width: number;
|
|
413
413
|
height: number;
|
|
414
414
|
};
|
|
415
|
-
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean): string;
|
|
415
|
+
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
|
|
416
416
|
activeToPng(padding?: Padding): string;
|
|
417
417
|
toggleAnchorMode(): void;
|
|
418
418
|
addAnchorHand(): void;
|
package/src/canvas/canvas.js
CHANGED
|
@@ -265,12 +265,15 @@ var Canvas = /** @class */ (function () {
|
|
|
265
265
|
if (_this.store.data.locked === LockState.DisableMoveScale)
|
|
266
266
|
return;
|
|
267
267
|
// e.ctrlKey: false - 平移; true - 缩放。老windows触摸板不支持
|
|
268
|
-
if (!e.ctrlKey &&
|
|
268
|
+
if (!e.ctrlKey &&
|
|
269
|
+
Math.abs(e.wheelDelta) < 100 &&
|
|
270
|
+
e.deltaY.toString().indexOf('.') === -1) {
|
|
269
271
|
if (_this.store.options.scroll && !e.metaKey && _this.scroll) {
|
|
270
272
|
_this.scroll.wheel(e.deltaY < 0);
|
|
271
273
|
return;
|
|
272
274
|
}
|
|
273
|
-
_this.
|
|
275
|
+
var scale = _this.store.data.scale || 1;
|
|
276
|
+
_this.translate(-e.deltaX / scale, -e.deltaY / scale);
|
|
274
277
|
return;
|
|
275
278
|
}
|
|
276
279
|
if (Math.abs(e.wheelDelta) > 100) {
|
|
@@ -296,10 +299,10 @@ var Canvas = /** @class */ (function () {
|
|
|
296
299
|
}
|
|
297
300
|
else {
|
|
298
301
|
if (e.deltaY > 0) {
|
|
299
|
-
scaleOff = -0.
|
|
302
|
+
scaleOff = -0.05;
|
|
300
303
|
}
|
|
301
304
|
else {
|
|
302
|
-
scaleOff = 0.
|
|
305
|
+
scaleOff = 0.05;
|
|
303
306
|
}
|
|
304
307
|
}
|
|
305
308
|
var x = e.offsetX, y = e.offsetY;
|
|
@@ -326,6 +329,19 @@ var Canvas = /** @class */ (function () {
|
|
|
326
329
|
}
|
|
327
330
|
var x = 10;
|
|
328
331
|
var y = 10;
|
|
332
|
+
var vRect = null;
|
|
333
|
+
if (_this.store.options.strictScope) {
|
|
334
|
+
var width = _this.store.data.width || _this.store.options.width;
|
|
335
|
+
var height = _this.store.data.height || _this.store.options.height;
|
|
336
|
+
if (width && height) {
|
|
337
|
+
vRect = {
|
|
338
|
+
x: _this.store.data.origin.x,
|
|
339
|
+
y: _this.store.data.origin.y,
|
|
340
|
+
width: width * _this.store.data.scale,
|
|
341
|
+
height: height * _this.store.data.scale,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
}
|
|
329
345
|
switch (e.key) {
|
|
330
346
|
case ' ':
|
|
331
347
|
_this.hotkeyType = HotkeyType.Translate;
|
|
@@ -350,7 +366,9 @@ var Canvas = /** @class */ (function () {
|
|
|
350
366
|
}
|
|
351
367
|
else if (!_this.hotkeyType) {
|
|
352
368
|
_this.patchFlags = true;
|
|
353
|
-
_this.
|
|
369
|
+
if (!_this.store.options.resizeMode) {
|
|
370
|
+
_this.hotkeyType = HotkeyType.Resize;
|
|
371
|
+
}
|
|
354
372
|
}
|
|
355
373
|
break;
|
|
356
374
|
case 'Alt':
|
|
@@ -403,6 +421,9 @@ var Canvas = /** @class */ (function () {
|
|
|
403
421
|
x = -10;
|
|
404
422
|
}
|
|
405
423
|
x = x * _this.store.data.scale;
|
|
424
|
+
if (vRect && _this.activeRect.x + x < vRect.x) {
|
|
425
|
+
x = vRect.x - _this.activeRect.x;
|
|
426
|
+
}
|
|
406
427
|
_this.translatePens(_this.store.active, x, 0);
|
|
407
428
|
break;
|
|
408
429
|
case 'ArrowUp':
|
|
@@ -418,6 +439,9 @@ var Canvas = /** @class */ (function () {
|
|
|
418
439
|
y = -10;
|
|
419
440
|
}
|
|
420
441
|
y = y * _this.store.data.scale;
|
|
442
|
+
if (vRect && _this.activeRect.y + y < vRect.y) {
|
|
443
|
+
y = vRect.y - _this.activeRect.y;
|
|
444
|
+
}
|
|
421
445
|
_this.translatePens(_this.store.active, 0, y);
|
|
422
446
|
break;
|
|
423
447
|
case 'ArrowRight':
|
|
@@ -433,6 +457,11 @@ var Canvas = /** @class */ (function () {
|
|
|
433
457
|
x = 10;
|
|
434
458
|
}
|
|
435
459
|
x = x * _this.store.data.scale;
|
|
460
|
+
if (vRect &&
|
|
461
|
+
_this.activeRect.x + _this.activeRect.width + x > vRect.x + vRect.width) {
|
|
462
|
+
x =
|
|
463
|
+
vRect.x + vRect.width - (_this.activeRect.x + _this.activeRect.width);
|
|
464
|
+
}
|
|
436
465
|
_this.translatePens(_this.store.active, x, 0);
|
|
437
466
|
break;
|
|
438
467
|
case 'ArrowDown':
|
|
@@ -448,6 +477,14 @@ var Canvas = /** @class */ (function () {
|
|
|
448
477
|
y = 10;
|
|
449
478
|
}
|
|
450
479
|
y = y * _this.store.data.scale;
|
|
480
|
+
if (vRect &&
|
|
481
|
+
_this.activeRect.y + _this.activeRect.height + y >
|
|
482
|
+
vRect.y + vRect.height) {
|
|
483
|
+
y =
|
|
484
|
+
vRect.y +
|
|
485
|
+
vRect.height -
|
|
486
|
+
(_this.activeRect.y + _this.activeRect.height);
|
|
487
|
+
}
|
|
451
488
|
_this.translatePens(_this.store.active, 0, y);
|
|
452
489
|
break;
|
|
453
490
|
case 'd':
|
|
@@ -1014,6 +1051,9 @@ var Canvas = /** @class */ (function () {
|
|
|
1014
1051
|
_this.store.data.rule &&
|
|
1015
1052
|
!_this.store.options.disableRuleLine &&
|
|
1016
1053
|
_this.addRuleLine(e);
|
|
1054
|
+
if (_this.store.options.resizeMode) {
|
|
1055
|
+
_this.hotkeyType = HotkeyType.None;
|
|
1056
|
+
}
|
|
1017
1057
|
_this.inactive();
|
|
1018
1058
|
break;
|
|
1019
1059
|
case HoverType.Node:
|
|
@@ -1038,6 +1078,9 @@ var Canvas = /** @class */ (function () {
|
|
|
1038
1078
|
else {
|
|
1039
1079
|
if (!pen.calculative.active) {
|
|
1040
1080
|
_this.active([pen]);
|
|
1081
|
+
if (_this.store.options.resizeMode) {
|
|
1082
|
+
_this.hotkeyType = HotkeyType.Resize;
|
|
1083
|
+
}
|
|
1041
1084
|
}
|
|
1042
1085
|
}
|
|
1043
1086
|
_this.calcActiveRect();
|
|
@@ -3020,6 +3063,21 @@ var Canvas = /** @class */ (function () {
|
|
|
3020
3063
|
pen.height === rect_1.height) ||
|
|
3021
3064
|
points.some(function (point) { return pointInRect(point, rect_1); })) {
|
|
3022
3065
|
flag = false;
|
|
3066
|
+
//严格范围模式下对齐大屏边界
|
|
3067
|
+
if (this.store.options.strictScope) {
|
|
3068
|
+
if (pen.x < rect_1.x) {
|
|
3069
|
+
pen.x = rect_1.x;
|
|
3070
|
+
}
|
|
3071
|
+
if (pen.y < rect_1.y) {
|
|
3072
|
+
pen.y = rect_1.y;
|
|
3073
|
+
}
|
|
3074
|
+
if (pen.x + pen.width > rect_1.x + rect_1.width) {
|
|
3075
|
+
pen.x = rect_1.x + rect_1.width - pen.width;
|
|
3076
|
+
}
|
|
3077
|
+
if (pen.y + pen.height > rect_1.y + rect_1.height) {
|
|
3078
|
+
pen.y = rect_1.y + rect_1.height - pen.height;
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
3023
3081
|
break;
|
|
3024
3082
|
}
|
|
3025
3083
|
}
|
|
@@ -4391,6 +4449,43 @@ var Canvas = /** @class */ (function () {
|
|
|
4391
4449
|
this.store.data.y += y * this.store.data.scale;
|
|
4392
4450
|
this.store.data.x = Math.round(this.store.data.x);
|
|
4393
4451
|
this.store.data.y = Math.round(this.store.data.y);
|
|
4452
|
+
if (this.store.options.padding) {
|
|
4453
|
+
var p = formatPadding(this.store.options.padding);
|
|
4454
|
+
var width = this.store.data.width || this.store.options.width;
|
|
4455
|
+
var height = this.store.data.height || this.store.options.height;
|
|
4456
|
+
if (this.width < (width + p[1] + p[3]) * this.store.data.scale) {
|
|
4457
|
+
if (this.store.data.x + this.store.data.origin.x >
|
|
4458
|
+
p[3] * this.store.data.scale) {
|
|
4459
|
+
this.store.data.x =
|
|
4460
|
+
p[3] * this.store.data.scale - this.store.data.origin.x;
|
|
4461
|
+
}
|
|
4462
|
+
if (this.store.data.x +
|
|
4463
|
+
this.store.data.origin.x +
|
|
4464
|
+
width * this.store.data.scale <
|
|
4465
|
+
this.width - p[1] * this.store.data.scale) {
|
|
4466
|
+
this.store.data.x =
|
|
4467
|
+
this.width -
|
|
4468
|
+
p[1] * this.store.data.scale -
|
|
4469
|
+
(this.store.data.origin.x + width * this.store.data.scale);
|
|
4470
|
+
}
|
|
4471
|
+
}
|
|
4472
|
+
if (this.height < (height + p[0] + p[2]) * this.store.data.scale) {
|
|
4473
|
+
if (this.store.data.y + this.store.data.origin.y >
|
|
4474
|
+
p[0] * this.store.data.scale) {
|
|
4475
|
+
this.store.data.y =
|
|
4476
|
+
p[0] * this.store.data.scale - this.store.data.origin.y;
|
|
4477
|
+
}
|
|
4478
|
+
if (this.store.data.y +
|
|
4479
|
+
this.store.data.origin.y +
|
|
4480
|
+
height * this.store.data.scale <
|
|
4481
|
+
this.height - p[2] * this.store.data.scale) {
|
|
4482
|
+
this.store.data.y =
|
|
4483
|
+
this.height -
|
|
4484
|
+
p[2] * this.store.data.scale -
|
|
4485
|
+
(this.store.data.origin.y + height * this.store.data.scale);
|
|
4486
|
+
}
|
|
4487
|
+
}
|
|
4488
|
+
}
|
|
4394
4489
|
setTimeout(function () {
|
|
4395
4490
|
_this.canvasTemplate.init();
|
|
4396
4491
|
_this.canvasImage.init();
|
|
@@ -4638,6 +4733,48 @@ var Canvas = /** @class */ (function () {
|
|
|
4638
4733
|
}
|
|
4639
4734
|
this.activeRect.ratio = this.initPens[0].ratio;
|
|
4640
4735
|
resizeRect(this.activeRect, offsetX, offsetY, this.resizeIndex);
|
|
4736
|
+
//大屏区域
|
|
4737
|
+
if (this.store.options.strictScope) {
|
|
4738
|
+
var width = this.store.data.width || this.store.options.width;
|
|
4739
|
+
var height = this.store.data.height || this.store.options.height;
|
|
4740
|
+
if (width && height) {
|
|
4741
|
+
var vRect = {
|
|
4742
|
+
x: this.store.data.origin.x,
|
|
4743
|
+
y: this.store.data.origin.y,
|
|
4744
|
+
width: width * this.store.data.scale,
|
|
4745
|
+
height: height * this.store.data.scale,
|
|
4746
|
+
};
|
|
4747
|
+
if (this.activeRect.x < vRect.x) {
|
|
4748
|
+
this.activeRect.width =
|
|
4749
|
+
this.activeRect.width - (vRect.x - this.activeRect.x);
|
|
4750
|
+
this.activeRect.x = vRect.x;
|
|
4751
|
+
}
|
|
4752
|
+
if (this.activeRect.y < vRect.y) {
|
|
4753
|
+
this.activeRect.height =
|
|
4754
|
+
this.activeRect.height - (vRect.y - this.activeRect.y);
|
|
4755
|
+
this.activeRect.y = vRect.y;
|
|
4756
|
+
}
|
|
4757
|
+
if (this.activeRect.x + this.activeRect.width > vRect.x + vRect.width) {
|
|
4758
|
+
this.activeRect.width =
|
|
4759
|
+
this.activeRect.width -
|
|
4760
|
+
(this.activeRect.x +
|
|
4761
|
+
this.activeRect.width -
|
|
4762
|
+
(vRect.x + vRect.width));
|
|
4763
|
+
this.activeRect.x = vRect.x + vRect.width - this.activeRect.width;
|
|
4764
|
+
this.activeRect.ex = this.activeRect.x + this.activeRect.width;
|
|
4765
|
+
}
|
|
4766
|
+
if (this.activeRect.y + this.activeRect.height >
|
|
4767
|
+
vRect.y + vRect.height) {
|
|
4768
|
+
this.activeRect.height =
|
|
4769
|
+
this.activeRect.height -
|
|
4770
|
+
(this.activeRect.y +
|
|
4771
|
+
this.activeRect.height -
|
|
4772
|
+
(vRect.y + vRect.height));
|
|
4773
|
+
this.activeRect.y = vRect.y + vRect.height - this.activeRect.height;
|
|
4774
|
+
this.activeRect.ey = this.activeRect.y + this.activeRect.height;
|
|
4775
|
+
}
|
|
4776
|
+
}
|
|
4777
|
+
}
|
|
4641
4778
|
calcCenter(this.activeRect);
|
|
4642
4779
|
var scaleX = this.activeRect.width / w;
|
|
4643
4780
|
var scaleY = this.activeRect.height / h;
|
|
@@ -4706,11 +4843,40 @@ var Canvas = /** @class */ (function () {
|
|
|
4706
4843
|
e.ctrlKey && (x = 0);
|
|
4707
4844
|
var rect = deepClone(this.initActiveRect);
|
|
4708
4845
|
translateRect(rect, x, y);
|
|
4846
|
+
var vFlag = false;
|
|
4847
|
+
if (this.store.options.strictScope) {
|
|
4848
|
+
var width = this.store.data.width || this.store.options.width;
|
|
4849
|
+
var height = this.store.data.height || this.store.options.height;
|
|
4850
|
+
if (width && height) {
|
|
4851
|
+
var vRect = {
|
|
4852
|
+
x: this.store.data.origin.x,
|
|
4853
|
+
y: this.store.data.origin.y,
|
|
4854
|
+
width: width * this.store.data.scale,
|
|
4855
|
+
height: height * this.store.data.scale,
|
|
4856
|
+
};
|
|
4857
|
+
if (rect.x < vRect.x) {
|
|
4858
|
+
rect.x = vRect.x;
|
|
4859
|
+
vFlag = true;
|
|
4860
|
+
}
|
|
4861
|
+
if (rect.y < vRect.y) {
|
|
4862
|
+
rect.y = vRect.y;
|
|
4863
|
+
vFlag = true;
|
|
4864
|
+
}
|
|
4865
|
+
if (rect.x + rect.width > vRect.x + vRect.width) {
|
|
4866
|
+
rect.x = vRect.x + vRect.width - rect.width;
|
|
4867
|
+
vFlag = true;
|
|
4868
|
+
}
|
|
4869
|
+
if (rect.y + rect.height > vRect.y + vRect.height) {
|
|
4870
|
+
rect.y = vRect.y + vRect.height - rect.height;
|
|
4871
|
+
vFlag = true;
|
|
4872
|
+
}
|
|
4873
|
+
}
|
|
4874
|
+
}
|
|
4709
4875
|
var offset = {
|
|
4710
4876
|
x: rect.x - this.activeRect.x,
|
|
4711
4877
|
y: rect.y - this.activeRect.y,
|
|
4712
4878
|
};
|
|
4713
|
-
if (!this.store.options.disableDock) {
|
|
4879
|
+
if (!this.store.options.disableDock && !vFlag) {
|
|
4714
4880
|
this.clearDock();
|
|
4715
4881
|
var moveDock = this.customMoveDock || calcMoveDock;
|
|
4716
4882
|
this.dock = moveDock(this.store, rect, this.movingPens, offset);
|
|
@@ -6398,11 +6564,12 @@ var Canvas = /** @class */ (function () {
|
|
|
6398
6564
|
height: pen.height / scale,
|
|
6399
6565
|
};
|
|
6400
6566
|
};
|
|
6401
|
-
Canvas.prototype.toPng = function (padding, callback, containBkImg) {
|
|
6567
|
+
Canvas.prototype.toPng = function (padding, callback, containBkImg, maxWidth) {
|
|
6402
6568
|
var e_22, _a;
|
|
6403
6569
|
if (padding === void 0) { padding = 2; }
|
|
6404
6570
|
if (containBkImg === void 0) { containBkImg = false; }
|
|
6405
6571
|
var rect = getRect(this.store.data.pens);
|
|
6572
|
+
var _scale = this.store.data.scale;
|
|
6406
6573
|
if (!isFinite(rect.width)) {
|
|
6407
6574
|
throw new Error('can not to png, because width is not finite');
|
|
6408
6575
|
}
|
|
@@ -6430,10 +6597,16 @@ var Canvas = /** @class */ (function () {
|
|
|
6430
6597
|
}
|
|
6431
6598
|
// 有背景图,也添加 padding
|
|
6432
6599
|
var p = formatPadding(padding);
|
|
6433
|
-
rect.x -= p[3];
|
|
6434
|
-
rect.y -= p[0];
|
|
6435
|
-
rect.width += p[3] + p[1];
|
|
6436
|
-
rect.height += p[0] + p[2];
|
|
6600
|
+
rect.x -= p[3] * _scale;
|
|
6601
|
+
rect.y -= p[0] * _scale;
|
|
6602
|
+
rect.width += (p[3] + p[1]) * _scale;
|
|
6603
|
+
rect.height += (p[0] + p[2]) * _scale;
|
|
6604
|
+
// 扩大图
|
|
6605
|
+
// const scale =
|
|
6606
|
+
// rect.width > rect.height ? longSide / rect.width : longSide / rect.height;
|
|
6607
|
+
var scale = (maxWidth || 1920) / rect.width;
|
|
6608
|
+
rect.width *= scale;
|
|
6609
|
+
rect.height *= scale;
|
|
6437
6610
|
calcRightBottom(rect);
|
|
6438
6611
|
var canvas = document.createElement('canvas');
|
|
6439
6612
|
canvas.width = rect.width;
|
|
@@ -6447,7 +6620,15 @@ var Canvas = /** @class */ (function () {
|
|
|
6447
6620
|
throw new Error('can not to png, because the size exceeds the browser limit');
|
|
6448
6621
|
}
|
|
6449
6622
|
var ctx = canvas.getContext('2d');
|
|
6623
|
+
// if (window.devicePixelRatio > 1) {
|
|
6624
|
+
// canvas.width *= window.devicePixelRatio;
|
|
6625
|
+
// canvas.height *= window.devicePixelRatio;
|
|
6626
|
+
// canvas.style.width = `${canvas.width / window.devicePixelRatio}`;
|
|
6627
|
+
// canvas.style.height = `${canvas.height / window.devicePixelRatio}`;
|
|
6628
|
+
// ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
|
|
6629
|
+
// }
|
|
6450
6630
|
ctx.textBaseline = 'middle'; // 默认垂直居中
|
|
6631
|
+
ctx.scale(scale, scale);
|
|
6451
6632
|
if (isDrawBkImg) {
|
|
6452
6633
|
var x = rect.x < 0 ? -rect.x : 0;
|
|
6453
6634
|
var y = rect.y < 0 ? -rect.y : 0;
|
|
@@ -6458,7 +6639,7 @@ var Canvas = /** @class */ (function () {
|
|
|
6458
6639
|
// 绘制背景颜色
|
|
6459
6640
|
ctx.save();
|
|
6460
6641
|
ctx.fillStyle = background;
|
|
6461
|
-
ctx.fillRect(0, 0,
|
|
6642
|
+
ctx.fillRect(0, 0, oldRect.width + (p[3] + p[1]) * _scale, oldRect.height + (p[0] + p[2]) * _scale);
|
|
6462
6643
|
ctx.restore();
|
|
6463
6644
|
}
|
|
6464
6645
|
if (!isDrawBkImg) {
|