@meta2d/core 1.0.13 → 1.0.15
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 +20 -2
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +4 -1
- package/src/core.js +95 -13
- package/src/core.js.map +1 -1
- package/src/diagrams/gif.js +2 -4
- package/src/diagrams/gif.js.map +1 -1
- package/src/diagrams/iframe.js +1 -1
- package/src/diagrams/iframe.js.map +1 -1
- package/src/diagrams/video.js +1 -1
- package/src/diagrams/video.js.map +1 -1
- package/src/pen/model.d.ts +1 -0
- package/src/pen/model.js +1 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +49 -10
- package/src/pen/render.js.map +1 -1
- package/src/scroll/scroll.d.ts +3 -0
- package/src/scroll/scroll.js +24 -0
- package/src/scroll/scroll.js.map +1 -1
- package/src/store/store.d.ts +18 -0
- package/src/store/store.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export declare class Meta2d {
|
|
|
14
14
|
canvas: Canvas;
|
|
15
15
|
websocket: WebSocket;
|
|
16
16
|
mqttClient: MqttClient;
|
|
17
|
+
websockets: WebSocket[];
|
|
18
|
+
mqttClients: MqttClient[];
|
|
17
19
|
socketFn: (e: string, topic: string) => boolean;
|
|
18
20
|
events: Record<number, (pen: Pen, e: Event) => void>;
|
|
19
21
|
map: ViewMap;
|
|
@@ -224,7 +226,8 @@ export declare class Meta2d {
|
|
|
224
226
|
* 宽度放大到屏幕尺寸,并滚动到最顶部
|
|
225
227
|
*
|
|
226
228
|
*/
|
|
227
|
-
scrollView(viewPadding?: Padding): void;
|
|
229
|
+
scrollView(viewPadding?: Padding, pageMode?: boolean): void;
|
|
230
|
+
screenView(viewPadding?: Padding, WorH?: boolean): void;
|
|
228
231
|
topView(paddingTop?: number): void;
|
|
229
232
|
centerView(): void;
|
|
230
233
|
/**
|
package/src/core.js
CHANGED
|
@@ -94,6 +94,7 @@ import { ViewMap } from './map';
|
|
|
94
94
|
import * as mqtt from 'mqtt/dist/mqtt.min.js';
|
|
95
95
|
import pkg from '../package.json';
|
|
96
96
|
import { lockedError } from './utils/error';
|
|
97
|
+
import { Scroll } from './scroll';
|
|
97
98
|
var Meta2d = /** @class */ (function () {
|
|
98
99
|
function Meta2d(parent, opts) {
|
|
99
100
|
var _this = this;
|
|
@@ -307,13 +308,22 @@ var Meta2d = /** @class */ (function () {
|
|
|
307
308
|
Meta2d.prototype.setOptions = function (opts) {
|
|
308
309
|
if (opts === void 0) { opts = {}; }
|
|
309
310
|
this.store.options = Object.assign(this.store.options, opts);
|
|
311
|
+
if (this.canvas && opts.scroll !== undefined) {
|
|
312
|
+
if (opts.scroll) {
|
|
313
|
+
!this.canvas.scroll && (this.canvas.scroll = new Scroll(this.canvas));
|
|
314
|
+
this.canvas.scroll.show();
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
this.canvas.scroll.hide();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
310
320
|
};
|
|
311
321
|
Meta2d.prototype.getOptions = function () {
|
|
312
322
|
return this.store.options;
|
|
313
323
|
};
|
|
314
324
|
Meta2d.prototype.setDatabyOptions = function (options) {
|
|
315
325
|
if (options === void 0) { options = {}; }
|
|
316
|
-
var color = options.color, activeColor = options.activeColor, activeBackground = options.activeBackground, grid = options.grid, gridColor = options.gridColor, gridSize = options.gridSize, fromArrow = options.fromArrow, toArrow = options.toArrow, rule = options.rule, ruleColor = options.ruleColor;
|
|
326
|
+
var color = options.color, activeColor = options.activeColor, activeBackground = options.activeBackground, grid = options.grid, gridColor = options.gridColor, gridSize = options.gridSize, fromArrow = options.fromArrow, toArrow = options.toArrow, rule = options.rule, ruleColor = options.ruleColor, textColor = options.textColor;
|
|
317
327
|
this.setRule({ rule: rule, ruleColor: ruleColor });
|
|
318
328
|
this.setGrid({
|
|
319
329
|
grid: grid,
|
|
@@ -321,6 +331,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
321
331
|
gridSize: gridSize,
|
|
322
332
|
});
|
|
323
333
|
this.store.data = Object.assign(this.store.data, {
|
|
334
|
+
textColor: textColor,
|
|
324
335
|
color: color,
|
|
325
336
|
activeColor: activeColor,
|
|
326
337
|
activeBackground: activeBackground,
|
|
@@ -724,14 +735,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
724
735
|
this.finishDrawLine(true);
|
|
725
736
|
this.canvas.drawingLineName = '';
|
|
726
737
|
this.stopPencil();
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
});
|
|
734
|
-
}
|
|
738
|
+
//恢复可选状态
|
|
739
|
+
this.store.data.pens.forEach(function (pen) {
|
|
740
|
+
if (pen.externElement === true) {
|
|
741
|
+
pen.onMove && pen.onMove(pen);
|
|
742
|
+
}
|
|
743
|
+
});
|
|
735
744
|
};
|
|
736
745
|
// end - 当前鼠标位置,是否作为终点
|
|
737
746
|
Meta2d.prototype.finishDrawLine = function (end) {
|
|
@@ -922,6 +931,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
922
931
|
pen.animations.length > index) {
|
|
923
932
|
var animate = deepClone(pen.animations[index]);
|
|
924
933
|
delete animate.name;
|
|
934
|
+
animate.currentAnimation = index;
|
|
925
935
|
if (!pen.type && animate.frames) {
|
|
926
936
|
animate.showDuration = _this.calcAnimateDuration(animate);
|
|
927
937
|
}
|
|
@@ -975,6 +985,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
975
985
|
pens = idOrTagOrPens;
|
|
976
986
|
}
|
|
977
987
|
pens.forEach(function (pen) {
|
|
988
|
+
pen.currentAnimation = undefined;
|
|
978
989
|
pen.calculative.pause = undefined;
|
|
979
990
|
pen.calculative.start = undefined;
|
|
980
991
|
pen.calculative.duration = undefined;
|
|
@@ -1060,6 +1071,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1060
1071
|
* @param showChild 组合后展示第几个孩子
|
|
1061
1072
|
*/
|
|
1062
1073
|
Meta2d.prototype.combine = function (pens, showChild) {
|
|
1074
|
+
var _this = this;
|
|
1063
1075
|
if (pens === void 0) { pens = this.store.active; }
|
|
1064
1076
|
if (!pens || !pens.length) {
|
|
1065
1077
|
return;
|
|
@@ -1094,8 +1106,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
1094
1106
|
this.canvas.makePen(parent);
|
|
1095
1107
|
// }
|
|
1096
1108
|
var initParent = deepClone(parent);
|
|
1109
|
+
var minIndex = Infinity;
|
|
1097
1110
|
pens.forEach(function (pen) {
|
|
1098
1111
|
var _a;
|
|
1112
|
+
var index = _this.store.data.pens.findIndex(function (_pen) { return _pen.id === pen.id; });
|
|
1113
|
+
if (index < minIndex) {
|
|
1114
|
+
minIndex = index;
|
|
1115
|
+
}
|
|
1099
1116
|
if (pen === parent || pen.parentId === parent.id) {
|
|
1100
1117
|
return;
|
|
1101
1118
|
}
|
|
@@ -1106,6 +1123,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
1106
1123
|
Object.assign(pen, childRect);
|
|
1107
1124
|
pen.locked = (_a = pen.lockedOnCombine) !== null && _a !== void 0 ? _a : LockState.DisableMove;
|
|
1108
1125
|
});
|
|
1126
|
+
//将组合后的父节点置底
|
|
1127
|
+
this.store.data.pens.splice(minIndex, 0, parent);
|
|
1128
|
+
this.store.data.pens.pop();
|
|
1109
1129
|
this.canvas.active([parent]);
|
|
1110
1130
|
var step = 1;
|
|
1111
1131
|
// if (!oneIsParent) {
|
|
@@ -1284,8 +1304,21 @@ var Meta2d = /** @class */ (function () {
|
|
|
1284
1304
|
if (websocket) {
|
|
1285
1305
|
this.store.data.websocket = websocket;
|
|
1286
1306
|
}
|
|
1287
|
-
if (this.store.data.
|
|
1288
|
-
this.
|
|
1307
|
+
if (this.store.data.websockets) {
|
|
1308
|
+
this.websockets = [];
|
|
1309
|
+
this.store.data.websockets.forEach(function (websocket, index) {
|
|
1310
|
+
_this.websockets[index] = new WebSocket(websocket.url, websocket.protocols);
|
|
1311
|
+
_this.websockets[index].onmessage = function (e) {
|
|
1312
|
+
_this.socketCallback(e.data);
|
|
1313
|
+
};
|
|
1314
|
+
_this.websockets[index].onclose = function () {
|
|
1315
|
+
console.info('Canvas websocket closed and reconneting...');
|
|
1316
|
+
_this.connectWebsocket();
|
|
1317
|
+
};
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
else if (this.store.data.websocket) {
|
|
1321
|
+
this.websocket = new WebSocket(this.store.data.websocket, this.store.data.websocketProtocols);
|
|
1289
1322
|
this.websocket.onmessage = function (e) {
|
|
1290
1323
|
_this.socketCallback(e.data);
|
|
1291
1324
|
};
|
|
@@ -1301,6 +1334,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
1301
1334
|
this.websocket.close();
|
|
1302
1335
|
this.websocket = undefined;
|
|
1303
1336
|
}
|
|
1337
|
+
if (this.websockets) {
|
|
1338
|
+
this.websockets.forEach(function (websocket) {
|
|
1339
|
+
websocket.onclose = undefined;
|
|
1340
|
+
websocket.close();
|
|
1341
|
+
websocket = undefined;
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1304
1344
|
};
|
|
1305
1345
|
Meta2d.prototype.connectMqtt = function (params) {
|
|
1306
1346
|
var _this = this;
|
|
@@ -1310,7 +1350,22 @@ var Meta2d = /** @class */ (function () {
|
|
|
1310
1350
|
this.store.data.mqttTopics = params.mqttTopics;
|
|
1311
1351
|
this.store.data.mqttOptions = params.mqttOptions;
|
|
1312
1352
|
}
|
|
1313
|
-
if (this.store.data.
|
|
1353
|
+
if (this.store.data.mqtts) {
|
|
1354
|
+
this.mqttClients = [];
|
|
1355
|
+
this.store.data.mqtts.forEach(function (_mqtt, index) {
|
|
1356
|
+
if (_mqtt.options.clientId && !_mqtt.options.customClientId) {
|
|
1357
|
+
_mqtt.options.clientId = s8();
|
|
1358
|
+
}
|
|
1359
|
+
_this.mqttClients[index] = mqtt.connect(_mqtt.url, _mqtt.options);
|
|
1360
|
+
_this.mqttClients[index].on('message', function (topic, message) {
|
|
1361
|
+
_this.socketCallback(message.toString(), topic);
|
|
1362
|
+
});
|
|
1363
|
+
if (_mqtt.topics) {
|
|
1364
|
+
_this.mqttClients[index].subscribe(_mqtt.topics.split(','));
|
|
1365
|
+
}
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
else if (this.store.data.mqtt) {
|
|
1314
1369
|
if (this.store.data.mqttOptions.clientId &&
|
|
1315
1370
|
!this.store.data.mqttOptions.customClientId) {
|
|
1316
1371
|
this.store.data.mqttOptions.clientId = s8();
|
|
@@ -1327,6 +1382,10 @@ var Meta2d = /** @class */ (function () {
|
|
|
1327
1382
|
Meta2d.prototype.closeMqtt = function () {
|
|
1328
1383
|
var _a;
|
|
1329
1384
|
(_a = this.mqttClient) === null || _a === void 0 ? void 0 : _a.end();
|
|
1385
|
+
this.mqttClients &&
|
|
1386
|
+
this.mqttClients.forEach(function (mqttClient) {
|
|
1387
|
+
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.end();
|
|
1388
|
+
});
|
|
1330
1389
|
};
|
|
1331
1390
|
Meta2d.prototype.connectHttp = function () {
|
|
1332
1391
|
var _this = this;
|
|
@@ -1795,8 +1854,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
1795
1854
|
* 宽度放大到屏幕尺寸,并滚动到最顶部
|
|
1796
1855
|
*
|
|
1797
1856
|
*/
|
|
1798
|
-
Meta2d.prototype.scrollView = function (viewPadding) {
|
|
1857
|
+
Meta2d.prototype.scrollView = function (viewPadding, pageMode) {
|
|
1799
1858
|
if (viewPadding === void 0) { viewPadding = 10; }
|
|
1859
|
+
if (pageMode === void 0) { pageMode = false; }
|
|
1800
1860
|
if (!this.hasView())
|
|
1801
1861
|
return;
|
|
1802
1862
|
//滚动状态下
|
|
@@ -1811,6 +1871,28 @@ var Meta2d = /** @class */ (function () {
|
|
|
1811
1871
|
var ratio = (width - padding[1] - padding[3]) / rect.width;
|
|
1812
1872
|
this.scale(ratio * this.store.data.scale);
|
|
1813
1873
|
this.topView(padding[0]);
|
|
1874
|
+
if (pageMode) {
|
|
1875
|
+
this.canvas.scroll.changeMode();
|
|
1876
|
+
}
|
|
1877
|
+
};
|
|
1878
|
+
Meta2d.prototype.screenView = function (viewPadding, WorH) {
|
|
1879
|
+
if (viewPadding === void 0) { viewPadding = 10; }
|
|
1880
|
+
if (WorH === void 0) { WorH = true; }
|
|
1881
|
+
if (!this.hasView())
|
|
1882
|
+
return;
|
|
1883
|
+
var canvas = this.canvas.canvas;
|
|
1884
|
+
var width = canvas.offsetWidth, height = canvas.offsetHeight;
|
|
1885
|
+
this.resize(width, height);
|
|
1886
|
+
var padding = formatPadding(viewPadding);
|
|
1887
|
+
var rect = this.getRect();
|
|
1888
|
+
//默认宽度充满
|
|
1889
|
+
var ratio = (width - padding[1] - padding[3]) / rect.width;
|
|
1890
|
+
if (!WorH) {
|
|
1891
|
+
ratio = (height - padding[0] - padding[2]) / rect.height;
|
|
1892
|
+
}
|
|
1893
|
+
this.scale(ratio * this.store.data.scale);
|
|
1894
|
+
//height充满时是居中
|
|
1895
|
+
this.topView(padding[0]);
|
|
1814
1896
|
};
|
|
1815
1897
|
Meta2d.prototype.topView = function (paddingTop) {
|
|
1816
1898
|
if (paddingTop === void 0) { paddingTop = 10; }
|