@meta2d/core 1.0.25 → 1.0.27
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.js +113 -100
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +1 -0
- package/src/core.js +104 -39
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.js +27 -4
- package/src/diagrams/iframe.js.map +1 -1
- package/src/event/event.d.ts +3 -1
- package/src/event/event.js +2 -0
- package/src/event/event.js.map +1 -1
- package/src/options.d.ts +6 -0
- package/src/options.js +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +7 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +66 -4
- package/src/pen/render.js.map +1 -1
- package/src/pen/text.js +17 -1
- package/src/pen/text.js.map +1 -1
- package/src/store/store.d.ts +2 -0
- package/src/store/store.js.map +1 -1
- package/src/title/title.js +9 -9
- package/src/title/title.js.map +1 -1
- package/src/utils/clone.d.ts +1 -1
- package/src/utils/clone.js +14 -4
- package/src/utils/clone.js.map +1 -1
- package/src/utils/url.d.ts +3 -0
- package/src/utils/url.js +7 -0
- package/src/utils/url.js.map +1 -0
package/src/core.d.ts
CHANGED
|
@@ -282,6 +282,7 @@ export declare class Meta2d {
|
|
|
282
282
|
formatPainter(): void;
|
|
283
283
|
clearFormatPainter(): void;
|
|
284
284
|
alignNodes(align: string, pens?: Pen[], rect?: Rect): void;
|
|
285
|
+
alignNodesV(align: string, pens?: Pen[]): void;
|
|
285
286
|
/**
|
|
286
287
|
* 对齐画笔,基于第一个画笔
|
|
287
288
|
* @param align 左对齐,右对齐,上对齐,下对齐,居中对齐
|
package/src/core.js
CHANGED
|
@@ -96,6 +96,7 @@ import pkg from '../package.json';
|
|
|
96
96
|
import { lockedError } from './utils/error';
|
|
97
97
|
import { Scroll } from './scroll';
|
|
98
98
|
import { getter } from './utils/object';
|
|
99
|
+
import { queryURLParams } from './utils/url';
|
|
99
100
|
var Meta2d = /** @class */ (function () {
|
|
100
101
|
function Meta2d(parent, opts) {
|
|
101
102
|
var _this = this;
|
|
@@ -569,6 +570,31 @@ var Meta2d = /** @class */ (function () {
|
|
|
569
570
|
}
|
|
570
571
|
}
|
|
571
572
|
};
|
|
573
|
+
this.events[EventAction.PostMessage] = function (pen, e) {
|
|
574
|
+
if (typeof e.value !== 'string') {
|
|
575
|
+
console.warn('[meta2d] Emit value must be a string');
|
|
576
|
+
return;
|
|
577
|
+
}
|
|
578
|
+
var _pen = e.params ? _this.findOne(e.params) : pen;
|
|
579
|
+
if (_pen.name !== 'iframe' || !_pen.iframe) {
|
|
580
|
+
console.warn('不是嵌入页面');
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
var params = queryURLParams(_pen.iframe.split('?')[1]);
|
|
584
|
+
_pen.calculative.singleton.div.children[0].contentWindow.postMessage(JSON.stringify({
|
|
585
|
+
name: e.value,
|
|
586
|
+
id: params.id,
|
|
587
|
+
}), '*');
|
|
588
|
+
return;
|
|
589
|
+
};
|
|
590
|
+
this.events[EventAction.PostMessageToParent] = function (pen, e) {
|
|
591
|
+
if (typeof e.value !== 'string') {
|
|
592
|
+
console.warn('[meta2d] Emit value must be a string');
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
window.parent.postMessage(JSON.stringify(e.value), '*');
|
|
596
|
+
return;
|
|
597
|
+
};
|
|
572
598
|
};
|
|
573
599
|
Meta2d.prototype.navigatorTo = function (id) {
|
|
574
600
|
if (!id) {
|
|
@@ -1205,9 +1231,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
1205
1231
|
var _this = this;
|
|
1206
1232
|
this.stopAnimate(idOrTagOrPens);
|
|
1207
1233
|
var pens;
|
|
1234
|
+
// 没有参数 则播放有自动播放属性的动画
|
|
1208
1235
|
if (!idOrTagOrPens) {
|
|
1209
1236
|
pens = this.store.data.pens.filter(function (pen) {
|
|
1210
|
-
return (pen.type || pen.frames) && pen.autoPlay
|
|
1237
|
+
return (((pen.type || pen.frames) && pen.autoPlay) ||
|
|
1238
|
+
(pen.animations && pen.autoPlay));
|
|
1211
1239
|
});
|
|
1212
1240
|
}
|
|
1213
1241
|
else if (typeof idOrTagOrPens === 'string') {
|
|
@@ -1217,6 +1245,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1217
1245
|
pens = idOrTagOrPens;
|
|
1218
1246
|
}
|
|
1219
1247
|
pens.forEach(function (pen) {
|
|
1248
|
+
var _a;
|
|
1220
1249
|
if (pen.calculative.pause) {
|
|
1221
1250
|
var d = Date.now() - pen.calculative.pause;
|
|
1222
1251
|
pen.calculative.pause = undefined;
|
|
@@ -1224,8 +1253,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
1224
1253
|
pen.calculative.frameEnd += d;
|
|
1225
1254
|
}
|
|
1226
1255
|
else {
|
|
1256
|
+
var index = -1;
|
|
1227
1257
|
if (params !== undefined && pen.animations) {
|
|
1228
|
-
var index = -1;
|
|
1229
1258
|
if (typeof params === 'string') {
|
|
1230
1259
|
index = pen.animations.findIndex(function (animation) { return animation.name === params; });
|
|
1231
1260
|
if (index === -1) {
|
|
@@ -1240,6 +1269,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
1240
1269
|
return;
|
|
1241
1270
|
}
|
|
1242
1271
|
}
|
|
1272
|
+
}
|
|
1273
|
+
else if (params === undefined) {
|
|
1274
|
+
index = ((_a = pen.animations) === null || _a === void 0 ? void 0 : _a.findIndex(function (i) { return i.autoPlay; })) || -1;
|
|
1275
|
+
}
|
|
1276
|
+
if (index !== -1) {
|
|
1243
1277
|
var animate = deepClone(pen.animations[index]);
|
|
1244
1278
|
delete animate.name;
|
|
1245
1279
|
animate.currentAnimation = index;
|
|
@@ -1308,7 +1342,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
1308
1342
|
});
|
|
1309
1343
|
this.initImageCanvas(pens);
|
|
1310
1344
|
setTimeout(function () {
|
|
1311
|
-
|
|
1345
|
+
var _a;
|
|
1346
|
+
(_a = _this.canvas) === null || _a === void 0 ? void 0 : _a.calcActiveRect();
|
|
1312
1347
|
_this.render();
|
|
1313
1348
|
}, 20);
|
|
1314
1349
|
};
|
|
@@ -1972,12 +2007,6 @@ var Meta2d = /** @class */ (function () {
|
|
|
1972
2007
|
};
|
|
1973
2008
|
//获取动态参数
|
|
1974
2009
|
Meta2d.prototype.getDynamicParam = function (key) {
|
|
1975
|
-
function queryURLParams() {
|
|
1976
|
-
var url = window.location.href.split('?')[1];
|
|
1977
|
-
var urlSearchParams = new URLSearchParams(url);
|
|
1978
|
-
var params = Object.fromEntries(urlSearchParams.entries());
|
|
1979
|
-
return params;
|
|
1980
|
-
}
|
|
1981
2010
|
function getCookie(name) {
|
|
1982
2011
|
var arr;
|
|
1983
2012
|
var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
|
|
@@ -2869,6 +2898,38 @@ var Meta2d = /** @class */ (function () {
|
|
|
2869
2898
|
pens: pens,
|
|
2870
2899
|
});
|
|
2871
2900
|
};
|
|
2901
|
+
//对齐大屏
|
|
2902
|
+
Meta2d.prototype.alignNodesV = function (align, pens) {
|
|
2903
|
+
var e_9, _a;
|
|
2904
|
+
if (pens === void 0) { pens = this.store.data.pens; }
|
|
2905
|
+
var width = this.store.data.width || this.store.options.width;
|
|
2906
|
+
var height = this.store.data.height || this.store.options.height;
|
|
2907
|
+
var rect = {
|
|
2908
|
+
x: 0,
|
|
2909
|
+
y: 0,
|
|
2910
|
+
width: width,
|
|
2911
|
+
height: height,
|
|
2912
|
+
};
|
|
2913
|
+
var initPens = deepClone(pens); // 原 pens ,深拷贝一下
|
|
2914
|
+
try {
|
|
2915
|
+
for (var pens_2 = __values(pens), pens_2_1 = pens_2.next(); !pens_2_1.done; pens_2_1 = pens_2.next()) {
|
|
2916
|
+
var item = pens_2_1.value;
|
|
2917
|
+
this.alignPen(align, item, rect);
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
catch (e_9_1) { e_9 = { error: e_9_1 }; }
|
|
2921
|
+
finally {
|
|
2922
|
+
try {
|
|
2923
|
+
if (pens_2_1 && !pens_2_1.done && (_a = pens_2.return)) _a.call(pens_2);
|
|
2924
|
+
}
|
|
2925
|
+
finally { if (e_9) throw e_9.error; }
|
|
2926
|
+
}
|
|
2927
|
+
this.pushHistory({
|
|
2928
|
+
type: EditType.Update,
|
|
2929
|
+
initPens: initPens,
|
|
2930
|
+
pens: pens,
|
|
2931
|
+
});
|
|
2932
|
+
};
|
|
2872
2933
|
/**
|
|
2873
2934
|
* 对齐画笔,基于第一个画笔
|
|
2874
2935
|
* @param align 左对齐,右对齐,上对齐,下对齐,居中对齐
|
|
@@ -2949,7 +3010,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2949
3010
|
* @param distance 总的宽 or 高
|
|
2950
3011
|
*/
|
|
2951
3012
|
Meta2d.prototype.spaceBetweenByDirection = function (direction, pens, distance) {
|
|
2952
|
-
var
|
|
3013
|
+
var e_10, _a;
|
|
2953
3014
|
var _this = this;
|
|
2954
3015
|
if (pens === void 0) { pens = this.store.data.pens; }
|
|
2955
3016
|
!distance && (distance = this.getPenRect(this.getRect(pens))[direction]);
|
|
@@ -2975,20 +3036,20 @@ var Meta2d = /** @class */ (function () {
|
|
|
2975
3036
|
var pen0Rect = this.getPenRect(pens[0]);
|
|
2976
3037
|
var left = direction === 'width' ? pen0Rect.x : pen0Rect.y;
|
|
2977
3038
|
try {
|
|
2978
|
-
for (var
|
|
2979
|
-
var pen =
|
|
3039
|
+
for (var pens_3 = __values(pens), pens_3_1 = pens_3.next(); !pens_3_1.done; pens_3_1 = pens_3.next()) {
|
|
3040
|
+
var pen = pens_3_1.value;
|
|
2980
3041
|
var penRect = this.getPenRect(pen);
|
|
2981
3042
|
direction === 'width' ? (penRect.x = left) : (penRect.y = left);
|
|
2982
3043
|
left += penRect[direction] + space;
|
|
2983
3044
|
this.setValue(__assign({ id: pen.id }, penRect), { render: false, doEvent: false });
|
|
2984
3045
|
}
|
|
2985
3046
|
}
|
|
2986
|
-
catch (
|
|
3047
|
+
catch (e_10_1) { e_10 = { error: e_10_1 }; }
|
|
2987
3048
|
finally {
|
|
2988
3049
|
try {
|
|
2989
|
-
if (
|
|
3050
|
+
if (pens_3_1 && !pens_3_1.done && (_a = pens_3.return)) _a.call(pens_3);
|
|
2990
3051
|
}
|
|
2991
|
-
finally { if (
|
|
3052
|
+
finally { if (e_10) throw e_10.error; }
|
|
2992
3053
|
}
|
|
2993
3054
|
this.render();
|
|
2994
3055
|
this.pushHistory({
|
|
@@ -3105,7 +3166,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3105
3166
|
* @param pens pen 置顶的画笔
|
|
3106
3167
|
*/
|
|
3107
3168
|
Meta2d.prototype.top = function (pens) {
|
|
3108
|
-
var
|
|
3169
|
+
var e_11, _a;
|
|
3109
3170
|
var _this = this;
|
|
3110
3171
|
if (!pens)
|
|
3111
3172
|
pens = this.store.active;
|
|
@@ -3133,12 +3194,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3133
3194
|
_loop_3(pen);
|
|
3134
3195
|
}
|
|
3135
3196
|
}
|
|
3136
|
-
catch (
|
|
3197
|
+
catch (e_11_1) { e_11 = { error: e_11_1 }; }
|
|
3137
3198
|
finally {
|
|
3138
3199
|
try {
|
|
3139
3200
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3140
3201
|
}
|
|
3141
|
-
finally { if (
|
|
3202
|
+
finally { if (e_11) throw e_11.error; }
|
|
3142
3203
|
}
|
|
3143
3204
|
};
|
|
3144
3205
|
/**
|
|
@@ -3154,7 +3215,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3154
3215
|
* @param pens 画笔们,注意 pen 必须在该数组内才有效
|
|
3155
3216
|
*/
|
|
3156
3217
|
Meta2d.prototype.bottom = function (pens) {
|
|
3157
|
-
var
|
|
3218
|
+
var e_12, _a;
|
|
3158
3219
|
if (!pens)
|
|
3159
3220
|
pens = this.store.active;
|
|
3160
3221
|
if (!Array.isArray(pens))
|
|
@@ -3185,12 +3246,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3185
3246
|
_loop_4(pen);
|
|
3186
3247
|
}
|
|
3187
3248
|
}
|
|
3188
|
-
catch (
|
|
3249
|
+
catch (e_12_1) { e_12 = { error: e_12_1 }; }
|
|
3189
3250
|
finally {
|
|
3190
3251
|
try {
|
|
3191
3252
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3192
3253
|
}
|
|
3193
|
-
finally { if (
|
|
3254
|
+
finally { if (e_12) throw e_12.error; }
|
|
3194
3255
|
}
|
|
3195
3256
|
};
|
|
3196
3257
|
/**
|
|
@@ -3199,7 +3260,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3199
3260
|
* @param pen 画笔
|
|
3200
3261
|
*/
|
|
3201
3262
|
Meta2d.prototype.upByArea = function (pen) {
|
|
3202
|
-
var _a,
|
|
3263
|
+
var _a, e_13, _b;
|
|
3203
3264
|
var _this = this;
|
|
3204
3265
|
var index = this.store.data.pens.findIndex(function (p) { return p.id === pen.id; });
|
|
3205
3266
|
if (index === -1) {
|
|
@@ -3249,12 +3310,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3249
3310
|
_loop_6(pen_2);
|
|
3250
3311
|
}
|
|
3251
3312
|
}
|
|
3252
|
-
catch (
|
|
3313
|
+
catch (e_13_1) { e_13 = { error: e_13_1 }; }
|
|
3253
3314
|
finally {
|
|
3254
3315
|
try {
|
|
3255
3316
|
if (allPens_1_1 && !allPens_1_1.done && (_b = allPens_1.return)) _b.call(allPens_1);
|
|
3256
3317
|
}
|
|
3257
|
-
finally { if (
|
|
3318
|
+
finally { if (e_13) throw e_13.error; }
|
|
3258
3319
|
}
|
|
3259
3320
|
this.initImageCanvas([pen]);
|
|
3260
3321
|
};
|
|
@@ -3295,7 +3356,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3295
3356
|
* @param pens 画笔
|
|
3296
3357
|
*/
|
|
3297
3358
|
Meta2d.prototype.up = function (pens) {
|
|
3298
|
-
var
|
|
3359
|
+
var e_14, _a;
|
|
3299
3360
|
var _this = this;
|
|
3300
3361
|
if (!pens)
|
|
3301
3362
|
pens = this.store.active;
|
|
@@ -3348,12 +3409,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3348
3409
|
_loop_7(pen);
|
|
3349
3410
|
}
|
|
3350
3411
|
}
|
|
3351
|
-
catch (
|
|
3412
|
+
catch (e_14_1) { e_14 = { error: e_14_1 }; }
|
|
3352
3413
|
finally {
|
|
3353
3414
|
try {
|
|
3354
3415
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3355
3416
|
}
|
|
3356
|
-
finally { if (
|
|
3417
|
+
finally { if (e_14) throw e_14.error; }
|
|
3357
3418
|
}
|
|
3358
3419
|
};
|
|
3359
3420
|
/**
|
|
@@ -3361,7 +3422,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3361
3422
|
* @param pen 画笔
|
|
3362
3423
|
*/
|
|
3363
3424
|
Meta2d.prototype.down = function (pens) {
|
|
3364
|
-
var
|
|
3425
|
+
var e_15, _a;
|
|
3365
3426
|
var _this = this;
|
|
3366
3427
|
if (!pens)
|
|
3367
3428
|
pens = this.store.active;
|
|
@@ -3416,12 +3477,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3416
3477
|
_loop_9(pen);
|
|
3417
3478
|
}
|
|
3418
3479
|
}
|
|
3419
|
-
catch (
|
|
3480
|
+
catch (e_15_1) { e_15 = { error: e_15_1 }; }
|
|
3420
3481
|
finally {
|
|
3421
3482
|
try {
|
|
3422
3483
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3423
3484
|
}
|
|
3424
|
-
finally { if (
|
|
3485
|
+
finally { if (e_15) throw e_15.error; }
|
|
3425
3486
|
}
|
|
3426
3487
|
};
|
|
3427
3488
|
Meta2d.prototype.setLayer = function (pen, toIndex, pens) {
|
|
@@ -3463,6 +3524,10 @@ var Meta2d = /** @class */ (function () {
|
|
|
3463
3524
|
console.warn(node, 'node contain a error connectedLine');
|
|
3464
3525
|
return;
|
|
3465
3526
|
}
|
|
3527
|
+
if (lines.find(function (_line) { return _line.id === line.id; })) {
|
|
3528
|
+
//去重
|
|
3529
|
+
return;
|
|
3530
|
+
}
|
|
3466
3531
|
switch (type) {
|
|
3467
3532
|
case 'all':
|
|
3468
3533
|
lines.push(line);
|
|
@@ -3496,7 +3561,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3496
3561
|
var nextNodes_1 = [];
|
|
3497
3562
|
// 2. 遍历出线的 nextNode
|
|
3498
3563
|
lines.forEach(function (line) {
|
|
3499
|
-
var
|
|
3564
|
+
var e_16, _a;
|
|
3500
3565
|
var lineNextNode = _this.nextNode(line);
|
|
3501
3566
|
var _loop_11 = function (node) {
|
|
3502
3567
|
var have = nextNodes_1.find(function (next) { return next.id === node.id; });
|
|
@@ -3509,12 +3574,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3509
3574
|
_loop_11(node);
|
|
3510
3575
|
}
|
|
3511
3576
|
}
|
|
3512
|
-
catch (
|
|
3577
|
+
catch (e_16_1) { e_16 = { error: e_16_1 }; }
|
|
3513
3578
|
finally {
|
|
3514
3579
|
try {
|
|
3515
3580
|
if (lineNextNode_1_1 && !lineNextNode_1_1.done && (_a = lineNextNode_1.return)) _a.call(lineNextNode_1);
|
|
3516
3581
|
}
|
|
3517
|
-
finally { if (
|
|
3582
|
+
finally { if (e_16) throw e_16.error; }
|
|
3518
3583
|
}
|
|
3519
3584
|
});
|
|
3520
3585
|
return nextNodes_1;
|
|
@@ -3537,7 +3602,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3537
3602
|
var preNodes_1 = [];
|
|
3538
3603
|
// 2. 遍历入线的 preNode
|
|
3539
3604
|
lines.forEach(function (line) {
|
|
3540
|
-
var
|
|
3605
|
+
var e_17, _a;
|
|
3541
3606
|
var linePreNode = _this.previousNode(line);
|
|
3542
3607
|
var _loop_12 = function (node) {
|
|
3543
3608
|
var have = preNodes_1.find(function (pre) { return pre.id === node.id; });
|
|
@@ -3550,12 +3615,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3550
3615
|
_loop_12(node);
|
|
3551
3616
|
}
|
|
3552
3617
|
}
|
|
3553
|
-
catch (
|
|
3618
|
+
catch (e_17_1) { e_17 = { error: e_17_1 }; }
|
|
3554
3619
|
finally {
|
|
3555
3620
|
try {
|
|
3556
3621
|
if (linePreNode_1_1 && !linePreNode_1_1.done && (_a = linePreNode_1.return)) _a.call(linePreNode_1);
|
|
3557
3622
|
}
|
|
3558
|
-
finally { if (
|
|
3623
|
+
finally { if (e_17) throw e_17.error; }
|
|
3559
3624
|
}
|
|
3560
3625
|
});
|
|
3561
3626
|
return preNodes_1;
|
|
@@ -3831,7 +3896,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3831
3896
|
: deepClone(__spreadArray([parent], __read(components), false));
|
|
3832
3897
|
};
|
|
3833
3898
|
Meta2d.prototype.setVisible = function (pen, visible, render) {
|
|
3834
|
-
var
|
|
3899
|
+
var e_18, _a;
|
|
3835
3900
|
if (render === void 0) { render = true; }
|
|
3836
3901
|
this.onSizeUpdate();
|
|
3837
3902
|
this.setValue({ id: pen.id, visible: visible }, { render: false, doEvent: false });
|
|
@@ -3843,12 +3908,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
3843
3908
|
child && this.setVisible(child, visible, false);
|
|
3844
3909
|
}
|
|
3845
3910
|
}
|
|
3846
|
-
catch (
|
|
3911
|
+
catch (e_18_1) { e_18 = { error: e_18_1 }; }
|
|
3847
3912
|
finally {
|
|
3848
3913
|
try {
|
|
3849
3914
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
3850
3915
|
}
|
|
3851
|
-
finally { if (
|
|
3916
|
+
finally { if (e_18) throw e_18.error; }
|
|
3852
3917
|
}
|
|
3853
3918
|
}
|
|
3854
3919
|
render && this.render();
|