@meta2d/core 1.0.88 → 1.0.89
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 +48 -27
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +1 -0
- package/src/core.js +87 -19
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.js +13 -4
- package/src/diagrams/iframe.js.map +1 -1
- package/src/pen/model.d.ts +1 -1
- package/src/pen/render.js +47 -20
- package/src/pen/render.js.map +1 -1
- package/src/pen/text.js +36 -25
- package/src/pen/text.js.map +1 -1
- package/src/scroll/scroll.d.ts +4 -1
- package/src/scroll/scroll.js +81 -8
- package/src/scroll/scroll.js.map +1 -1
- package/src/utils/time.js +2 -1
- package/src/utils/time.js.map +1 -1
- package/src/utils/tool.d.ts +1 -0
- package/src/utils/tool.js +4 -0
- package/src/utils/tool.js.map +1 -0
- package/src/utils/url.d.ts +1 -1
- package/src/utils/url.js +36 -4
- package/src/utils/url.js.map +1 -1
package/src/core.d.ts
CHANGED
package/src/core.js
CHANGED
|
@@ -18,6 +18,7 @@ import { HotkeyType } from './data';
|
|
|
18
18
|
import { Message, messageList } from './message';
|
|
19
19
|
import { closeJetLinks, connectJetLinks, getSendData, sendJetLinksData } from './utils/jetLinks';
|
|
20
20
|
import { le5leTheme } from './theme';
|
|
21
|
+
const echartReg = /^echarts/;
|
|
21
22
|
export class Meta2d {
|
|
22
23
|
store;
|
|
23
24
|
canvas;
|
|
@@ -555,7 +556,7 @@ export class Meta2d {
|
|
|
555
556
|
if (item.prop) {
|
|
556
557
|
if (item.id && item.id !== '固定值') {
|
|
557
558
|
const pen = this.findOne(item.id);
|
|
558
|
-
value[item.prop] = pen[item.key];
|
|
559
|
+
value[item.prop] = getter(pen, item.key); // pen[item.key];
|
|
559
560
|
}
|
|
560
561
|
else {
|
|
561
562
|
if (typeof item.value === 'string' && item.value.includes('${')) {
|
|
@@ -666,6 +667,7 @@ export class Meta2d {
|
|
|
666
667
|
else {
|
|
667
668
|
this.fitView(true, 10);
|
|
668
669
|
}
|
|
670
|
+
document.title = data.name + "-" + window.name;
|
|
669
671
|
}
|
|
670
672
|
}
|
|
671
673
|
doSendDataEvent(value, topics) {
|
|
@@ -1281,8 +1283,9 @@ export class Meta2d {
|
|
|
1281
1283
|
const initJs = this.store.data.initJs;
|
|
1282
1284
|
if (initJs && initJs.trim()) {
|
|
1283
1285
|
try {
|
|
1284
|
-
|
|
1286
|
+
let fn = new Function('context', initJs);
|
|
1285
1287
|
fn({ meta2d: this });
|
|
1288
|
+
fn = null;
|
|
1286
1289
|
}
|
|
1287
1290
|
catch (e) {
|
|
1288
1291
|
console.warn('initJs error', e);
|
|
@@ -1617,10 +1620,12 @@ export class Meta2d {
|
|
|
1617
1620
|
this.store.animateMap.delete(pen);
|
|
1618
1621
|
});
|
|
1619
1622
|
this.initImageCanvas(pens);
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1623
|
+
if (this.store.data.locked === LockState.None) {
|
|
1624
|
+
setTimeout(() => {
|
|
1625
|
+
this.canvas?.calcActiveRect();
|
|
1626
|
+
this.render();
|
|
1627
|
+
}, 20);
|
|
1628
|
+
}
|
|
1624
1629
|
}
|
|
1625
1630
|
startVideo(idOrTagOrPens) {
|
|
1626
1631
|
let pens;
|
|
@@ -2506,6 +2511,19 @@ export class Meta2d {
|
|
|
2506
2511
|
});
|
|
2507
2512
|
}
|
|
2508
2513
|
}
|
|
2514
|
+
// 稳定连接配置
|
|
2515
|
+
if (!options.hasOwnProperty("keepalive")) {
|
|
2516
|
+
Object.assign(options, { keepallive: 30 });
|
|
2517
|
+
}
|
|
2518
|
+
if (!options.hasOwnProperty("clean")) {
|
|
2519
|
+
Object.assign(options, { clean: false });
|
|
2520
|
+
}
|
|
2521
|
+
if (!options.hasOwnProperty("reconnectPeriod")) {
|
|
2522
|
+
Object.assign(options, { reconnectPeriod: 0 });
|
|
2523
|
+
}
|
|
2524
|
+
if (!options.hasOwnProperty("connectTimeout")) {
|
|
2525
|
+
Object.assign(options, { connectTimeout: 10 * 1000 });
|
|
2526
|
+
}
|
|
2509
2527
|
this.mqttClients[net.index] = mqtt.connect(url, options);
|
|
2510
2528
|
this.mqttClients[net.index].on('message', (topic, message) => {
|
|
2511
2529
|
this.socketCallback(message.toString(), {
|
|
@@ -2519,6 +2537,7 @@ export class Meta2d {
|
|
|
2519
2537
|
this.mqttClients[net.index].on('error', (error) => {
|
|
2520
2538
|
this.store.emitter.emit('error', { type: 'mqtt', error });
|
|
2521
2539
|
});
|
|
2540
|
+
let reconnectDelay = 1000;
|
|
2522
2541
|
this.mqttClients[net.index].on('close', () => {
|
|
2523
2542
|
if (this.store.options.reconnetTimes) {
|
|
2524
2543
|
net.times++;
|
|
@@ -2526,20 +2545,39 @@ export class Meta2d {
|
|
|
2526
2545
|
net.times = 0;
|
|
2527
2546
|
this.mqttClients && this.mqttClients[net.index]?.end();
|
|
2528
2547
|
}
|
|
2548
|
+
setTimeout(() => {
|
|
2549
|
+
if (net.times < this.store.options.reconnetTimes) {
|
|
2550
|
+
this.mqttClients[net.index].reconnect(options);
|
|
2551
|
+
reconnectDelay = Math.min(reconnectDelay * 2, 10 * 1000);
|
|
2552
|
+
}
|
|
2553
|
+
}, reconnectDelay);
|
|
2529
2554
|
}
|
|
2530
2555
|
});
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
if (
|
|
2534
|
-
|
|
2535
|
-
if (
|
|
2536
|
-
|
|
2537
|
-
|
|
2556
|
+
this.mqttClients[net.index].on('connect', (connack) => {
|
|
2557
|
+
reconnectDelay = 1000;
|
|
2558
|
+
if (!connack.sessionPresent) {
|
|
2559
|
+
// 创建了新会话或没有找到旧会话,需要重新订阅主题
|
|
2560
|
+
if (net.topics) {
|
|
2561
|
+
let topics = net.topics;
|
|
2562
|
+
if (topics.indexOf('${') > -1) {
|
|
2563
|
+
let keys = topics.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2564
|
+
if (keys) {
|
|
2565
|
+
keys.forEach((key) => {
|
|
2566
|
+
topics = topics.replace(`\${${key}}`, this.getDynamicParam(key));
|
|
2567
|
+
});
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
// QoS=1 是 MQTT 中最常用的级别,它能在保证大部分消息可靠传递
|
|
2571
|
+
this.mqttClients[net.index].subscribe(topics.split(','), { qos: 1 }, (err) => {
|
|
2572
|
+
if (err)
|
|
2573
|
+
console.error("订阅失败:", err);
|
|
2538
2574
|
});
|
|
2539
2575
|
}
|
|
2540
2576
|
}
|
|
2541
|
-
|
|
2542
|
-
|
|
2577
|
+
else {
|
|
2578
|
+
//已恢复之前的会话,可以接收离线消息,不需要重新订阅,之前的订阅已恢复
|
|
2579
|
+
}
|
|
2580
|
+
});
|
|
2543
2581
|
}
|
|
2544
2582
|
connectNetWebSocket(net) {
|
|
2545
2583
|
if (this.websockets[net.index]) {
|
|
@@ -3022,7 +3060,7 @@ export class Meta2d {
|
|
|
3022
3060
|
if (res.ok) {
|
|
3023
3061
|
const data = await res.text();
|
|
3024
3062
|
const net = this.store.data.networks.filter(item => item.protocol === 'http')[req.index];
|
|
3025
|
-
this.socketCallback(data, { type: 'http', url: req.url, name: req.name, net });
|
|
3063
|
+
this.socketCallback(data, { type: 'http', method: req.method, url: req.url, name: req.name, net });
|
|
3026
3064
|
}
|
|
3027
3065
|
else {
|
|
3028
3066
|
_req.times++;
|
|
@@ -3102,6 +3140,7 @@ export class Meta2d {
|
|
|
3102
3140
|
topic: context.topic,
|
|
3103
3141
|
url: context.url,
|
|
3104
3142
|
method: context.method,
|
|
3143
|
+
net: context.net
|
|
3105
3144
|
});
|
|
3106
3145
|
if (!_message) {
|
|
3107
3146
|
return;
|
|
@@ -3293,6 +3332,11 @@ export class Meta2d {
|
|
|
3293
3332
|
initPens = deepClone(pens);
|
|
3294
3333
|
}
|
|
3295
3334
|
pens.forEach((pen) => {
|
|
3335
|
+
if (pen.name === 'echarts' && !pen.onBeforeValue) {
|
|
3336
|
+
const hasEchartsStartKey = Object.keys(data).some(key => echartReg.test(key));
|
|
3337
|
+
if (hasEchartsStartKey)
|
|
3338
|
+
return;
|
|
3339
|
+
}
|
|
3296
3340
|
const afterData = pen.onBeforeValue
|
|
3297
3341
|
? pen.onBeforeValue(pen, data)
|
|
3298
3342
|
: data;
|
|
@@ -4592,12 +4636,23 @@ export class Meta2d {
|
|
|
4592
4636
|
const { offsetWidth: width, offsetHeight: height } = canvas;
|
|
4593
4637
|
this.resize(width, height);
|
|
4594
4638
|
const padding = formatPadding(viewPadding);
|
|
4595
|
-
|
|
4639
|
+
let rect = null;
|
|
4640
|
+
const w = this.store.data.width || this.store.options.width;
|
|
4641
|
+
const h = this.store.data.height || this.store.options.height;
|
|
4642
|
+
if (w && h) {
|
|
4643
|
+
rect = {
|
|
4644
|
+
width: w * this.store.data.scale,
|
|
4645
|
+
height: h * this.store.data.scale,
|
|
4646
|
+
};
|
|
4647
|
+
}
|
|
4648
|
+
else {
|
|
4649
|
+
rect = this.getRect();
|
|
4650
|
+
}
|
|
4596
4651
|
const ratio = (width - padding[1] - padding[3]) / rect.width;
|
|
4597
4652
|
this.scale(ratio * this.store.data.scale);
|
|
4598
4653
|
this.topView(padding[0]);
|
|
4599
4654
|
if (pageMode) {
|
|
4600
|
-
this.canvas.scroll.changeMode();
|
|
4655
|
+
this.canvas.scroll.changeMode(padding[0]);
|
|
4601
4656
|
}
|
|
4602
4657
|
}
|
|
4603
4658
|
screenView(viewPadding = 10, WorH = true) {
|
|
@@ -4622,7 +4677,20 @@ export class Meta2d {
|
|
|
4622
4677
|
return;
|
|
4623
4678
|
const rect = this.getRect();
|
|
4624
4679
|
const viewCenter = this.getViewCenter();
|
|
4625
|
-
const
|
|
4680
|
+
const w = this.store.data.width || this.store.options.width;
|
|
4681
|
+
const h = this.store.data.height || this.store.options.height;
|
|
4682
|
+
let pensRect = null;
|
|
4683
|
+
if (w && h) {
|
|
4684
|
+
pensRect = {
|
|
4685
|
+
x: 0,
|
|
4686
|
+
y: 0,
|
|
4687
|
+
width: w,
|
|
4688
|
+
height: h,
|
|
4689
|
+
};
|
|
4690
|
+
}
|
|
4691
|
+
else {
|
|
4692
|
+
pensRect = this.getPenRect(rect);
|
|
4693
|
+
}
|
|
4626
4694
|
calcCenter(pensRect);
|
|
4627
4695
|
const { center } = pensRect;
|
|
4628
4696
|
const { scale, origin, x: dataX, y: dataY } = this.store.data;
|