@meta2d/core 1.0.23 → 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 +1 -1
- package/src/canvas/canvas.d.ts +1 -0
- package/src/canvas/canvas.js +118 -13
- 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 +211 -55
- 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/options.d.ts +1 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +5 -0
- package/src/pen/model.js +1 -10
- 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/pen/text.d.ts +1 -0
- package/src/pen/text.js +42 -0
- package/src/pen/text.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/src/title/title.d.ts +2 -1
- package/src/title/title.js +6 -2
- package/src/title/title.js.map +1 -1
package/package.json
CHANGED
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
|
@@ -82,7 +82,7 @@ var __values = (this && this.__values) || function(o) {
|
|
|
82
82
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
83
83
|
};
|
|
84
84
|
import { KeydownType } from '../options';
|
|
85
|
-
import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, } from '../pen';
|
|
85
|
+
import { addLineAnchor, calcIconRect, calcTextRect, calcWorldAnchors, calcWorldRects, LockState, nearestAnchor, PenType, pushPenAnchor, removePenAnchor, renderPen, scalePen, translateLine, deleteTempAnchor, connectLine, disconnectLine, getAnchor, calcAnchorDock, calcMoveDock, calcTextLines, setNodeAnimate, setLineAnimate, calcPenRect, setChildrenActive, getParent, setHover, randomId, getPensLock, getToAnchor, getFromAnchor, calcPadding, getPensDisableRotate, getPensDisableResize, needCalcTextRectProps, calcResizeDock, needPatchFlagsPenRectProps, needCalcIconRectProps, isDomShapes, renderPenRaw, needSetPenProps, getAllChildren, calcInView, isShowChild, getTextColor, getGlobalColor, clearLifeCycle, rotatePen, calcTextAutoWidth, } from '../pen';
|
|
86
86
|
import { calcRotate, distance, getDistance, hitPoint, PointType, PrevNextType, rotatePoint, samePoint, scalePoint, translatePoint, TwoWay, } from '../point';
|
|
87
87
|
import { calcCenter, calcRightBottom, calcRelativePoint, getRect, getRectOfPoints, pointInRect, pointInSimpleRect, rectInRect, rectToPoints, resizeRect, translateRect, } from '../rect';
|
|
88
88
|
import { EditType, globalStore, } from '../store';
|
|
@@ -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
|
}
|
|
@@ -307,6 +313,9 @@ var Canvas = /** @class */ (function () {
|
|
|
307
313
|
e.target.tagName === 'TEXTAREA') {
|
|
308
314
|
return;
|
|
309
315
|
}
|
|
316
|
+
if (_this.store.options.unavailableKeys.includes(e.key)) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
310
319
|
var x = 10;
|
|
311
320
|
var y = 10;
|
|
312
321
|
switch (e.key) {
|
|
@@ -378,12 +387,12 @@ var Canvas = /** @class */ (function () {
|
|
|
378
387
|
_this.translateAnchor(-1, 0);
|
|
379
388
|
break;
|
|
380
389
|
}
|
|
381
|
-
x = -
|
|
390
|
+
x = -1;
|
|
382
391
|
if (e.shiftKey) {
|
|
383
392
|
x = -5;
|
|
384
393
|
}
|
|
385
394
|
if (e.ctrlKey || e.metaKey) {
|
|
386
|
-
x = -
|
|
395
|
+
x = -10;
|
|
387
396
|
}
|
|
388
397
|
_this.translatePens(_this.store.active, x, 0);
|
|
389
398
|
break;
|
|
@@ -392,12 +401,12 @@ var Canvas = /** @class */ (function () {
|
|
|
392
401
|
_this.translateAnchor(0, -1);
|
|
393
402
|
break;
|
|
394
403
|
}
|
|
395
|
-
y = -
|
|
404
|
+
y = -1;
|
|
396
405
|
if (e.shiftKey) {
|
|
397
406
|
y = -5;
|
|
398
407
|
}
|
|
399
408
|
if (e.ctrlKey || e.metaKey) {
|
|
400
|
-
y = -
|
|
409
|
+
y = -10;
|
|
401
410
|
}
|
|
402
411
|
_this.translatePens(_this.store.active, 0, y);
|
|
403
412
|
break;
|
|
@@ -406,11 +415,12 @@ var Canvas = /** @class */ (function () {
|
|
|
406
415
|
_this.translateAnchor(1, 0);
|
|
407
416
|
break;
|
|
408
417
|
}
|
|
418
|
+
x = 1;
|
|
409
419
|
if (e.shiftKey) {
|
|
410
420
|
x = 5;
|
|
411
421
|
}
|
|
412
422
|
if (e.ctrlKey || e.metaKey) {
|
|
413
|
-
x =
|
|
423
|
+
x = 10;
|
|
414
424
|
}
|
|
415
425
|
_this.translatePens(_this.store.active, x, 0);
|
|
416
426
|
break;
|
|
@@ -419,11 +429,12 @@ var Canvas = /** @class */ (function () {
|
|
|
419
429
|
_this.translateAnchor(0, 1);
|
|
420
430
|
break;
|
|
421
431
|
}
|
|
432
|
+
y = 1;
|
|
422
433
|
if (e.shiftKey) {
|
|
423
434
|
y = 5;
|
|
424
435
|
}
|
|
425
436
|
if (e.ctrlKey || e.metaKey) {
|
|
426
|
-
y =
|
|
437
|
+
y = 10;
|
|
427
438
|
}
|
|
428
439
|
_this.translatePens(_this.store.active, 0, y);
|
|
429
440
|
break;
|
|
@@ -989,7 +1000,7 @@ var Canvas = /** @class */ (function () {
|
|
|
989
1000
|
_this.store.data.rule &&
|
|
990
1001
|
!_this.store.options.disableRuleLine &&
|
|
991
1002
|
_this.addRuleLine(e);
|
|
992
|
-
|
|
1003
|
+
_this.inactive();
|
|
993
1004
|
break;
|
|
994
1005
|
case HoverType.Node:
|
|
995
1006
|
case HoverType.Line:
|
|
@@ -1421,6 +1432,16 @@ var Canvas = /** @class */ (function () {
|
|
|
1421
1432
|
// Add pen
|
|
1422
1433
|
if (_this.addCaches && _this.addCaches.length) {
|
|
1423
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
|
+
}
|
|
1424
1445
|
_this.dropPens(_this.addCaches, e);
|
|
1425
1446
|
}
|
|
1426
1447
|
_this.addCaches = undefined;
|
|
@@ -1662,7 +1683,7 @@ var Canvas = /** @class */ (function () {
|
|
|
1662
1683
|
for (var _d = (e_1 = void 0, __values(pen.calculative.worldAnchors)), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
1663
1684
|
var anchor = _e.value;
|
|
1664
1685
|
if (hitPoint(pt, anchor, _this.pointSize, anchor.penId ? _this.store.pens[anchor.penId] : undefined)) {
|
|
1665
|
-
_this.title.show(anchor);
|
|
1686
|
+
_this.title.show(anchor, pen);
|
|
1666
1687
|
if (anchor.title) {
|
|
1667
1688
|
return "break-outer";
|
|
1668
1689
|
}
|
|
@@ -2237,7 +2258,7 @@ var Canvas = /** @class */ (function () {
|
|
|
2237
2258
|
};
|
|
2238
2259
|
this.ondblclick = function (e) {
|
|
2239
2260
|
if (_this.store.hover &&
|
|
2240
|
-
!_this.store.data.locked &&
|
|
2261
|
+
(!_this.store.data.locked || _this.store.hover.dbInput) &&
|
|
2241
2262
|
!_this.store.options.disableInput) {
|
|
2242
2263
|
if (_this.store.hover.onShowInput) {
|
|
2243
2264
|
_this.store.hover.onShowInput(_this.store.hover, e);
|
|
@@ -2273,9 +2294,13 @@ var Canvas = /** @class */ (function () {
|
|
|
2273
2294
|
return;
|
|
2274
2295
|
}
|
|
2275
2296
|
//过滤table2图元
|
|
2276
|
-
if (!rect) {
|
|
2297
|
+
if (!rect && !pen.dbInput) {
|
|
2277
2298
|
_this.setInputStyle(pen);
|
|
2278
2299
|
}
|
|
2300
|
+
else {
|
|
2301
|
+
_this.inputDiv.style.width = '100%';
|
|
2302
|
+
_this.inputDiv.style.height = '100%';
|
|
2303
|
+
}
|
|
2279
2304
|
var textRect = rect || pen.calculative.worldTextRect;
|
|
2280
2305
|
//value和innerText问题
|
|
2281
2306
|
var preInputText = pen.calculative.tempText || pen.text + '' || '';
|
|
@@ -2500,6 +2525,9 @@ var Canvas = /** @class */ (function () {
|
|
|
2500
2525
|
pen.text = _this.inputDiv.dataset.value;
|
|
2501
2526
|
pen.calculative.text = pen.text;
|
|
2502
2527
|
_this.inputDiv.dataset.penId = undefined;
|
|
2528
|
+
if (pen.name === 'text' && pen.textAutoAdjust) {
|
|
2529
|
+
calcTextAutoWidth(pen);
|
|
2530
|
+
}
|
|
2503
2531
|
calcTextRect(pen);
|
|
2504
2532
|
_this.patchFlags = true;
|
|
2505
2533
|
_this.pushHistory({
|
|
@@ -2713,6 +2741,17 @@ var Canvas = /** @class */ (function () {
|
|
|
2713
2741
|
});
|
|
2714
2742
|
};
|
|
2715
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();
|
|
2716
2755
|
if (e.toElement !== _this.tooltip.box) {
|
|
2717
2756
|
_this.tooltip.hide();
|
|
2718
2757
|
_this.store.lastHover = undefined;
|
|
@@ -3148,7 +3187,6 @@ var Canvas = /** @class */ (function () {
|
|
|
3148
3187
|
},
|
|
3149
3188
|
],
|
|
3150
3189
|
});
|
|
3151
|
-
this.inactive();
|
|
3152
3190
|
};
|
|
3153
3191
|
/**
|
|
3154
3192
|
* 拖拽结束,数据更新到 active.pens
|
|
@@ -3189,6 +3227,9 @@ var Canvas = /** @class */ (function () {
|
|
|
3189
3227
|
// active 消息表示拖拽结束
|
|
3190
3228
|
// this.store.emitter.emit('active', this.store.active);
|
|
3191
3229
|
this.initImageCanvas(this.store.active);
|
|
3230
|
+
// 避免选中图元的出错情况,this.dock为undefined
|
|
3231
|
+
if (!this.dock)
|
|
3232
|
+
return;
|
|
3192
3233
|
var _a = this.dock, xDock = _a.xDock, yDock = _a.yDock;
|
|
3193
3234
|
var dockPen;
|
|
3194
3235
|
if (xDock) {
|
|
@@ -4470,6 +4511,7 @@ var Canvas = /** @class */ (function () {
|
|
|
4470
4511
|
var sign = [1, 3].includes(this.resizeIndex) ? -1 : 1;
|
|
4471
4512
|
offsetY = (sign * (offsetX * h)) / w;
|
|
4472
4513
|
}
|
|
4514
|
+
this.activeRect.ratio = this.initPens[0].ratio;
|
|
4473
4515
|
resizeRect(this.activeRect, offsetX, offsetY, this.resizeIndex);
|
|
4474
4516
|
calcCenter(this.activeRect);
|
|
4475
4517
|
var scaleX = this.activeRect.width / w;
|
|
@@ -4625,7 +4667,8 @@ var Canvas = /** @class */ (function () {
|
|
|
4625
4667
|
// 线宽为 0 ,看不到外边框,拖动过程中给个外边框
|
|
4626
4668
|
pen.lineWidth === 0 && (value.lineWidth = 1);
|
|
4627
4669
|
// TODO: 例如 pen.name = 'triangle' 的情况,但有图片,是否还需要变成矩形呢?
|
|
4628
|
-
if (
|
|
4670
|
+
if (pen.name.endsWith('Dom') ||
|
|
4671
|
+
isDomShapes.includes(pen.name) ||
|
|
4629
4672
|
_this.store.options.domShapes.includes(pen.name) ||
|
|
4630
4673
|
pen.image) {
|
|
4631
4674
|
// 修改名称会执行 onDestroy ,清空它
|
|
@@ -4934,6 +4977,8 @@ var Canvas = /** @class */ (function () {
|
|
|
4934
4977
|
Canvas.prototype.translatePens = function (pens, x, y, doing) {
|
|
4935
4978
|
var _this = this;
|
|
4936
4979
|
if (pens === void 0) { pens = this.store.active; }
|
|
4980
|
+
x = x * this.store.data.scale;
|
|
4981
|
+
y = y * this.store.data.scale;
|
|
4937
4982
|
if (!pens || !pens.length) {
|
|
4938
4983
|
return;
|
|
4939
4984
|
}
|
|
@@ -6282,6 +6327,66 @@ var Canvas = /** @class */ (function () {
|
|
|
6282
6327
|
}
|
|
6283
6328
|
return canvas.toDataURL();
|
|
6284
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
|
+
};
|
|
6285
6390
|
Canvas.prototype.toggleAnchorMode = function () {
|
|
6286
6391
|
var _a;
|
|
6287
6392
|
if (!this.hotkeyType) {
|