@meta2d/core 1.0.24 → 1.0.25
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 -0
- package/src/canvas/canvas.js +98 -6
- package/src/canvas/canvas.js.map +1 -1
- package/src/canvas/canvasImage.js +7 -8
- package/src/canvas/canvasImage.js.map +1 -1
- package/src/core.d.ts +5 -1
- package/src/core.js +191 -45
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.d.ts +0 -3
- package/src/diagrams/iframe.js +181 -21
- package/src/diagrams/iframe.js.map +1 -1
- package/src/event/event.d.ts +2 -1
- package/src/event/event.js.map +1 -1
- package/src/pen/model.d.ts +3 -0
- package/src/pen/model.js +1 -1
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +1 -1
- package/src/pen/render.js.map +1 -1
- package/src/rect/rect.js +15 -2
- package/src/rect/rect.js.map +1 -1
- package/src/store/store.d.ts +7 -0
- package/src/store/store.js +1 -0
- package/src/store/store.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.25",
|
|
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
|
@@ -396,6 +396,7 @@ export declare class Canvas {
|
|
|
396
396
|
height: number;
|
|
397
397
|
};
|
|
398
398
|
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean): string;
|
|
399
|
+
activeToPng(padding?: Padding): string;
|
|
399
400
|
toggleAnchorMode(): void;
|
|
400
401
|
addAnchorHand(): void;
|
|
401
402
|
removeAnchorHand(): void;
|
package/src/canvas/canvas.js
CHANGED
|
@@ -242,6 +242,12 @@ var Canvas = /** @class */ (function () {
|
|
|
242
242
|
if (_this.pencil) {
|
|
243
243
|
return;
|
|
244
244
|
}
|
|
245
|
+
if (_this.store.hover) {
|
|
246
|
+
if (_this.store.hover.onWheel) {
|
|
247
|
+
_this.store.hover.onWheel(_this.store.hover, e);
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
245
251
|
if (_this.store.options.disableScale) {
|
|
246
252
|
return;
|
|
247
253
|
}
|
|
@@ -381,12 +387,12 @@ var Canvas = /** @class */ (function () {
|
|
|
381
387
|
_this.translateAnchor(-1, 0);
|
|
382
388
|
break;
|
|
383
389
|
}
|
|
384
|
-
x = -
|
|
390
|
+
x = -1;
|
|
385
391
|
if (e.shiftKey) {
|
|
386
392
|
x = -5;
|
|
387
393
|
}
|
|
388
394
|
if (e.ctrlKey || e.metaKey) {
|
|
389
|
-
x = -
|
|
395
|
+
x = -10;
|
|
390
396
|
}
|
|
391
397
|
_this.translatePens(_this.store.active, x, 0);
|
|
392
398
|
break;
|
|
@@ -395,12 +401,12 @@ var Canvas = /** @class */ (function () {
|
|
|
395
401
|
_this.translateAnchor(0, -1);
|
|
396
402
|
break;
|
|
397
403
|
}
|
|
398
|
-
y = -
|
|
404
|
+
y = -1;
|
|
399
405
|
if (e.shiftKey) {
|
|
400
406
|
y = -5;
|
|
401
407
|
}
|
|
402
408
|
if (e.ctrlKey || e.metaKey) {
|
|
403
|
-
y = -
|
|
409
|
+
y = -10;
|
|
404
410
|
}
|
|
405
411
|
_this.translatePens(_this.store.active, 0, y);
|
|
406
412
|
break;
|
|
@@ -409,11 +415,12 @@ var Canvas = /** @class */ (function () {
|
|
|
409
415
|
_this.translateAnchor(1, 0);
|
|
410
416
|
break;
|
|
411
417
|
}
|
|
418
|
+
x = 1;
|
|
412
419
|
if (e.shiftKey) {
|
|
413
420
|
x = 5;
|
|
414
421
|
}
|
|
415
422
|
if (e.ctrlKey || e.metaKey) {
|
|
416
|
-
x =
|
|
423
|
+
x = 10;
|
|
417
424
|
}
|
|
418
425
|
_this.translatePens(_this.store.active, x, 0);
|
|
419
426
|
break;
|
|
@@ -422,11 +429,12 @@ var Canvas = /** @class */ (function () {
|
|
|
422
429
|
_this.translateAnchor(0, 1);
|
|
423
430
|
break;
|
|
424
431
|
}
|
|
432
|
+
y = 1;
|
|
425
433
|
if (e.shiftKey) {
|
|
426
434
|
y = 5;
|
|
427
435
|
}
|
|
428
436
|
if (e.ctrlKey || e.metaKey) {
|
|
429
|
-
y =
|
|
437
|
+
y = 10;
|
|
430
438
|
}
|
|
431
439
|
_this.translatePens(_this.store.active, 0, y);
|
|
432
440
|
break;
|
|
@@ -1424,6 +1432,16 @@ var Canvas = /** @class */ (function () {
|
|
|
1424
1432
|
// Add pen
|
|
1425
1433
|
if (_this.addCaches && _this.addCaches.length) {
|
|
1426
1434
|
if (!_this.store.data.locked) {
|
|
1435
|
+
if (_this.dragRect) {
|
|
1436
|
+
// 只存在一个缓存图元
|
|
1437
|
+
if (_this.addCaches.length === 1) {
|
|
1438
|
+
var target = _this.addCaches[0];
|
|
1439
|
+
target.width = _this.dragRect.width;
|
|
1440
|
+
target.height = _this.dragRect.height;
|
|
1441
|
+
e.x = (_this.dragRect.x + _this.dragRect.ex) / 2;
|
|
1442
|
+
e.y = (_this.dragRect.y + _this.dragRect.ey) / 2;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1427
1445
|
_this.dropPens(_this.addCaches, e);
|
|
1428
1446
|
}
|
|
1429
1447
|
_this.addCaches = undefined;
|
|
@@ -2723,6 +2741,17 @@ var Canvas = /** @class */ (function () {
|
|
|
2723
2741
|
});
|
|
2724
2742
|
};
|
|
2725
2743
|
this.externalElements.onmouseleave = function (e) {
|
|
2744
|
+
//离开画布取消所有选中
|
|
2745
|
+
_this.store.data.pens.forEach(function (pen) {
|
|
2746
|
+
if (pen.calculative.hover) {
|
|
2747
|
+
pen.calculative.hover = false;
|
|
2748
|
+
}
|
|
2749
|
+
});
|
|
2750
|
+
if (_this.store.hover) {
|
|
2751
|
+
_this.store.hover.calculative.hover = false;
|
|
2752
|
+
_this.store.hover = undefined;
|
|
2753
|
+
}
|
|
2754
|
+
_this.render();
|
|
2726
2755
|
if (e.toElement !== _this.tooltip.box) {
|
|
2727
2756
|
_this.tooltip.hide();
|
|
2728
2757
|
_this.store.lastHover = undefined;
|
|
@@ -4482,6 +4511,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4482
4511
|
var sign = [1, 3].includes(this.resizeIndex) ? -1 : 1;
|
|
4483
4512
|
offsetY = (sign * (offsetX * h)) / w;
|
|
4484
4513
|
}
|
|
4514
|
+
this.activeRect.ratio = this.initPens[0].ratio;
|
|
4485
4515
|
resizeRect(this.activeRect, offsetX, offsetY, this.resizeIndex);
|
|
4486
4516
|
calcCenter(this.activeRect);
|
|
4487
4517
|
var scaleX = this.activeRect.width / w;
|
|
@@ -4947,6 +4977,8 @@ var Canvas = /** @class */ (function () {
|
|
|
4947
4977
|
Canvas.prototype.translatePens = function (pens, x, y, doing) {
|
|
4948
4978
|
var _this = this;
|
|
4949
4979
|
if (pens === void 0) { pens = this.store.active; }
|
|
4980
|
+
x = x * this.store.data.scale;
|
|
4981
|
+
y = y * this.store.data.scale;
|
|
4950
4982
|
if (!pens || !pens.length) {
|
|
4951
4983
|
return;
|
|
4952
4984
|
}
|
|
@@ -6295,6 +6327,66 @@ var Canvas = /** @class */ (function () {
|
|
|
6295
6327
|
}
|
|
6296
6328
|
return canvas.toDataURL();
|
|
6297
6329
|
};
|
|
6330
|
+
Canvas.prototype.activeToPng = function (padding) {
|
|
6331
|
+
var e_24, _a;
|
|
6332
|
+
if (padding === void 0) { padding = 2; }
|
|
6333
|
+
var allPens = this.getAllByPens(this.store.active);
|
|
6334
|
+
var ids = allPens.map(function (pen) { return pen.id; });
|
|
6335
|
+
var rect = getRect(allPens);
|
|
6336
|
+
if (!isFinite(rect.width)) {
|
|
6337
|
+
throw new Error('can not to png, because width is not finite');
|
|
6338
|
+
}
|
|
6339
|
+
var oldRect = deepClone(rect);
|
|
6340
|
+
var p = formatPadding(padding);
|
|
6341
|
+
rect.x -= p[3];
|
|
6342
|
+
rect.y -= p[0];
|
|
6343
|
+
rect.width += p[3] + p[1];
|
|
6344
|
+
rect.height += p[0] + p[2];
|
|
6345
|
+
calcRightBottom(rect);
|
|
6346
|
+
var canvas = document.createElement('canvas');
|
|
6347
|
+
canvas.width = rect.width;
|
|
6348
|
+
canvas.height = rect.height;
|
|
6349
|
+
if (canvas.width > 32767 ||
|
|
6350
|
+
canvas.height > 32767 ||
|
|
6351
|
+
(!navigator.userAgent.includes('Firefox') &&
|
|
6352
|
+
canvas.height * canvas.width > 268435456) ||
|
|
6353
|
+
(navigator.userAgent.includes('Firefox') &&
|
|
6354
|
+
canvas.height * canvas.width > 472907776)) {
|
|
6355
|
+
throw new Error('can not to png, because the size exceeds the browser limit');
|
|
6356
|
+
}
|
|
6357
|
+
var ctx = canvas.getContext('2d');
|
|
6358
|
+
ctx.textBaseline = 'middle'; // 默认垂直居中
|
|
6359
|
+
// // 平移画布,画笔的 worldRect 不变化
|
|
6360
|
+
ctx.translate(-oldRect.x, -oldRect.y);
|
|
6361
|
+
try {
|
|
6362
|
+
for (var _b = __values(this.store.data.pens), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
6363
|
+
var pen = _c.value;
|
|
6364
|
+
if (ids.includes(pen.id)) {
|
|
6365
|
+
// 不使用 calculative.inView 的原因是,如果 pen 在 view 之外,那么它的 calculative.inView 为 false,但是它的绘制还是需要的
|
|
6366
|
+
if (!isShowChild(pen, this.store) || pen.visible == false) {
|
|
6367
|
+
continue;
|
|
6368
|
+
}
|
|
6369
|
+
var active = pen.calculative.active;
|
|
6370
|
+
pen.calculative.active = false;
|
|
6371
|
+
if (pen.calculative.img) {
|
|
6372
|
+
renderPenRaw(ctx, pen);
|
|
6373
|
+
}
|
|
6374
|
+
else {
|
|
6375
|
+
renderPen(ctx, pen);
|
|
6376
|
+
}
|
|
6377
|
+
pen.calculative.active = active;
|
|
6378
|
+
}
|
|
6379
|
+
}
|
|
6380
|
+
}
|
|
6381
|
+
catch (e_24_1) { e_24 = { error: e_24_1 }; }
|
|
6382
|
+
finally {
|
|
6383
|
+
try {
|
|
6384
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
6385
|
+
}
|
|
6386
|
+
finally { if (e_24) throw e_24.error; }
|
|
6387
|
+
}
|
|
6388
|
+
return canvas.toDataURL();
|
|
6389
|
+
};
|
|
6298
6390
|
Canvas.prototype.toggleAnchorMode = function () {
|
|
6299
6391
|
var _a;
|
|
6300
6392
|
if (!this.hotkeyType) {
|