@meta2d/core 1.0.32 → 1.0.34
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 +2 -2
- package/src/canvas/canvas.js +357 -55
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +4 -2
- package/src/core.js +120 -55
- package/src/core.js.map +1 -1
- package/src/diagrams/iframe.js +10 -7
- package/src/diagrams/iframe.js.map +1 -1
- package/src/event/event.d.ts +4 -1
- package/src/event/event.js.map +1 -1
- package/src/options.d.ts +4 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +9 -0
- package/src/pen/model.js +4 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.d.ts +1 -0
- package/src/pen/render.js +72 -16
- package/src/pen/render.js.map +1 -1
- package/src/store/store.d.ts +9 -1
- package/src/store/store.js +2 -0
- package/src/store/store.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -196,8 +196,10 @@ export declare class Meta2d {
|
|
|
196
196
|
connectNetwork(): void;
|
|
197
197
|
randomString(e: number): string;
|
|
198
198
|
penMock(pen: Pen): void;
|
|
199
|
+
penNetwork(pen: Pen): void;
|
|
199
200
|
getDynamicParam(key: string): any;
|
|
200
201
|
onNetworkConnect(https: Network[]): void;
|
|
202
|
+
requestHttp(_req: Network): Promise<void>;
|
|
201
203
|
closeNetwork(): void;
|
|
202
204
|
socketCallback(message: string, context?: {
|
|
203
205
|
type?: string;
|
|
@@ -232,14 +234,14 @@ export declare class Meta2d {
|
|
|
232
234
|
judgeCondition(pen: Pen, key: string, condition: TriggerCondition): boolean;
|
|
233
235
|
pushChildren(parent: Pen, children: Pen[]): void;
|
|
234
236
|
renderPenRaw: typeof renderPenRaw;
|
|
235
|
-
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean): string;
|
|
237
|
+
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
|
|
236
238
|
activeToPng(padding?: Padding): string;
|
|
237
239
|
/**
|
|
238
240
|
* 下载 png
|
|
239
241
|
* @param name 传入参数自带文件后缀名 例如:'test.png'
|
|
240
242
|
* @param padding 上右下左的内边距
|
|
241
243
|
*/
|
|
242
|
-
downloadPng(name?: string, padding?: Padding): void;
|
|
244
|
+
downloadPng(name?: string, padding?: Padding, maxWidth?: number): void;
|
|
243
245
|
downloadSvg(): void;
|
|
244
246
|
getRect(pens?: Pen[]): Rect;
|
|
245
247
|
hiddenTemplate(): void;
|
package/src/core.js
CHANGED
|
@@ -97,6 +97,7 @@ import { lockedError } from './utils/error';
|
|
|
97
97
|
import { Scroll } from './scroll';
|
|
98
98
|
import { getter } from './utils/object';
|
|
99
99
|
import { queryURLParams } from './utils/url';
|
|
100
|
+
import { HotkeyType } from './data';
|
|
100
101
|
var Meta2d = /** @class */ (function () {
|
|
101
102
|
function Meta2d(parent, opts) {
|
|
102
103
|
var _this = this;
|
|
@@ -143,6 +144,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
143
144
|
e.pen && e.pen.onClick && e.pen.onClick(e.pen, _this.canvas.mousePos);
|
|
144
145
|
_this.store.data.locked && e.pen && _this.doEvent(e.pen, eventName);
|
|
145
146
|
break;
|
|
147
|
+
case 'contextmenu':
|
|
148
|
+
e.pen &&
|
|
149
|
+
e.pen.onContextmenu &&
|
|
150
|
+
e.pen.onContextmenu(e.pen, _this.canvas.mousePos);
|
|
151
|
+
_this.store.data.locked && e.pen && _this.doEvent(e.pen, eventName);
|
|
152
|
+
break;
|
|
146
153
|
case 'mousedown':
|
|
147
154
|
e.pen &&
|
|
148
155
|
e.pen.onMouseDown &&
|
|
@@ -186,11 +193,32 @@ var Meta2d = /** @class */ (function () {
|
|
|
186
193
|
(_a = pen.events) === null || _a === void 0 ? void 0 : _a.forEach(function (event) {
|
|
187
194
|
var _a;
|
|
188
195
|
if (event.actions && event.actions.length) {
|
|
189
|
-
event.
|
|
190
|
-
|
|
191
|
-
|
|
196
|
+
if (event.name === eventName) {
|
|
197
|
+
//条件成立
|
|
198
|
+
var flag = false;
|
|
199
|
+
if (event.conditions && event.conditions.length) {
|
|
200
|
+
if (event.conditionType === 'and') {
|
|
201
|
+
flag = event.conditions.every(function (condition) {
|
|
202
|
+
return _this.judgeCondition(pen, condition.key, condition);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
else if (event.conditionType === 'or') {
|
|
206
|
+
flag = event.conditions.some(function (condition) {
|
|
207
|
+
return _this.judgeCondition(pen, condition.key, condition);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
192
210
|
}
|
|
193
|
-
|
|
211
|
+
else {
|
|
212
|
+
flag = true;
|
|
213
|
+
}
|
|
214
|
+
if (flag) {
|
|
215
|
+
event.actions.forEach(function (action) {
|
|
216
|
+
if (_this.events[action.action]) {
|
|
217
|
+
_this.events[action.action](pen, action);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
194
222
|
}
|
|
195
223
|
else {
|
|
196
224
|
if (_this.events[event.action] && event.name === eventName) {
|
|
@@ -362,6 +390,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
362
390
|
ruleColor: opts.ruleColor,
|
|
363
391
|
});
|
|
364
392
|
}
|
|
393
|
+
if (opts.resizeMode !== undefined) {
|
|
394
|
+
if (!opts.resizeMode) {
|
|
395
|
+
this.canvas.hotkeyType = HotkeyType.None;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
365
398
|
this.store.options = Object.assign(this.store.options, opts);
|
|
366
399
|
if (this.canvas && opts.scroll !== undefined) {
|
|
367
400
|
if (opts.scroll) {
|
|
@@ -623,7 +656,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
623
656
|
window.location.href = arr[0] + 'id=' + id;
|
|
624
657
|
}
|
|
625
658
|
else {
|
|
626
|
-
window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx
|
|
659
|
+
window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx);
|
|
627
660
|
}
|
|
628
661
|
}
|
|
629
662
|
};
|
|
@@ -718,7 +751,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
718
751
|
}
|
|
719
752
|
}
|
|
720
753
|
else {
|
|
721
|
-
websocket_1 = new WebSocket(network.url, network.protocols);
|
|
754
|
+
websocket_1 = new WebSocket(network.url, network.protocols || undefined);
|
|
722
755
|
websocket_1.onopen = function () {
|
|
723
756
|
console.info('websocket连接成功');
|
|
724
757
|
websocket_1.send(value);
|
|
@@ -1268,7 +1301,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
1268
1301
|
if (!idOrTagOrPens) {
|
|
1269
1302
|
pens = this.store.data.pens.filter(function (pen) {
|
|
1270
1303
|
return (((pen.type || pen.frames) && pen.autoPlay) ||
|
|
1271
|
-
(pen.animations &&
|
|
1304
|
+
(pen.animations &&
|
|
1305
|
+
pen.animations.length &&
|
|
1306
|
+
pen.animations.findIndex(function (i) { return i.autoPlay; }) !== -1));
|
|
1272
1307
|
});
|
|
1273
1308
|
}
|
|
1274
1309
|
else if (typeof idOrTagOrPens === 'string') {
|
|
@@ -1304,9 +1339,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
1304
1339
|
}
|
|
1305
1340
|
}
|
|
1306
1341
|
else if (params === undefined) {
|
|
1307
|
-
index = (
|
|
1342
|
+
index = (_a = pen.animations) === null || _a === void 0 ? void 0 : _a.findIndex(function (i) { return i.autoPlay; });
|
|
1308
1343
|
}
|
|
1309
|
-
if (index !== -1) {
|
|
1344
|
+
if (index !== -1 && index !== undefined) {
|
|
1310
1345
|
var animate = deepClone(pen.animations[index]);
|
|
1311
1346
|
delete animate.name;
|
|
1312
1347
|
animate.currentAnimation = index;
|
|
@@ -1688,7 +1723,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1688
1723
|
this.store.data.websocket = websocket;
|
|
1689
1724
|
}
|
|
1690
1725
|
if (this.store.data.websocket) {
|
|
1691
|
-
this.websocket = new WebSocket(this.store.data.websocket, this.store.data.websocketProtocols);
|
|
1726
|
+
this.websocket = new WebSocket(this.store.data.websocket, this.store.data.websocketProtocols || undefined);
|
|
1692
1727
|
this.websocket.onmessage = function (e) {
|
|
1693
1728
|
_this.socketCallback(e.data, {
|
|
1694
1729
|
type: 'websocket',
|
|
@@ -1883,7 +1918,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
1883
1918
|
mqttIndex_1 += 1;
|
|
1884
1919
|
}
|
|
1885
1920
|
else if (net.protocol === 'websocket') {
|
|
1886
|
-
_this.websockets[websocketIndex_1] = new WebSocket(net.url, net.protocols);
|
|
1921
|
+
_this.websockets[websocketIndex_1] = new WebSocket(net.url, net.protocols || undefined);
|
|
1887
1922
|
_this.websockets[websocketIndex_1].onmessage = function (e) {
|
|
1888
1923
|
_this.socketCallback(e.data, { type: 'websocket', url: net.url });
|
|
1889
1924
|
};
|
|
@@ -2038,6 +2073,22 @@ var Meta2d = /** @class */ (function () {
|
|
|
2038
2073
|
}
|
|
2039
2074
|
}
|
|
2040
2075
|
};
|
|
2076
|
+
Meta2d.prototype.penNetwork = function (pen) {
|
|
2077
|
+
var penNetwork = {
|
|
2078
|
+
url: pen.apiUrl,
|
|
2079
|
+
method: pen.apiMethod,
|
|
2080
|
+
headers: pen.apiHeaders,
|
|
2081
|
+
body: pen.apiBody,
|
|
2082
|
+
};
|
|
2083
|
+
//临时请求一次
|
|
2084
|
+
this.requestHttp(penNetwork);
|
|
2085
|
+
if (pen.apiEnable) {
|
|
2086
|
+
if (!this.store.pensNetwork) {
|
|
2087
|
+
this.store.pensNetwork = {};
|
|
2088
|
+
}
|
|
2089
|
+
this.store.pensNetwork[pen.id] = penNetwork;
|
|
2090
|
+
}
|
|
2091
|
+
};
|
|
2041
2092
|
//获取动态参数
|
|
2042
2093
|
Meta2d.prototype.getDynamicParam = function (key) {
|
|
2043
2094
|
function getCookie(name) {
|
|
@@ -2060,6 +2111,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2060
2111
|
if (!(https && https.length) && !enable) {
|
|
2061
2112
|
return;
|
|
2062
2113
|
}
|
|
2114
|
+
if (this.store.pensNetwork) {
|
|
2115
|
+
for (var key in this.store.pensNetwork) {
|
|
2116
|
+
https.push(this.store.pensNetwork[key]);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2063
2119
|
this.updateTimer = setInterval(function () {
|
|
2064
2120
|
//模拟数据
|
|
2065
2121
|
enable &&
|
|
@@ -2067,48 +2123,56 @@ var Meta2d = /** @class */ (function () {
|
|
|
2067
2123
|
_this.penMock(pen);
|
|
2068
2124
|
});
|
|
2069
2125
|
https.forEach(function (_item) { return __awaiter(_this, void 0, void 0, function () {
|
|
2070
|
-
var item, i, keys, i, keys, res, data;
|
|
2071
2126
|
return __generator(this, function (_a) {
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
item = deepClone(_item);
|
|
2075
|
-
if (!item.url) return [3 /*break*/, 3];
|
|
2076
|
-
if (typeof item.headers === 'object') {
|
|
2077
|
-
for (i in item.headers) {
|
|
2078
|
-
keys = item.headers[i].match(/(?<=\$\{).*?(?=\})/g);
|
|
2079
|
-
if (keys) {
|
|
2080
|
-
item.headers[i] = item.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
if (typeof item.body === 'object') {
|
|
2085
|
-
for (i in item.body) {
|
|
2086
|
-
keys = item.body[i].match(/(?<=\$\{).*?(?=\})/g);
|
|
2087
|
-
if (keys) {
|
|
2088
|
-
item.body[i] = item.body[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
return [4 /*yield*/, fetch(item.url, {
|
|
2093
|
-
headers: item.headers,
|
|
2094
|
-
method: item.method,
|
|
2095
|
-
body: item.method === 'GET' ? undefined : JSON.stringify(item.body),
|
|
2096
|
-
})];
|
|
2097
|
-
case 1:
|
|
2098
|
-
res = _a.sent();
|
|
2099
|
-
if (!res.ok) return [3 /*break*/, 3];
|
|
2100
|
-
return [4 /*yield*/, res.text()];
|
|
2101
|
-
case 2:
|
|
2102
|
-
data = _a.sent();
|
|
2103
|
-
this.socketCallback(data, { type: 'http', url: item.url });
|
|
2104
|
-
_a.label = 3;
|
|
2105
|
-
case 3: return [2 /*return*/];
|
|
2106
|
-
}
|
|
2127
|
+
this.requestHttp(_item);
|
|
2128
|
+
return [2 /*return*/];
|
|
2107
2129
|
});
|
|
2108
2130
|
}); });
|
|
2109
2131
|
_this.render();
|
|
2110
2132
|
}, this.store.data.networkInterval || 1000);
|
|
2111
2133
|
};
|
|
2134
|
+
Meta2d.prototype.requestHttp = function (_req) {
|
|
2135
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
2136
|
+
var req, i, keys, i, keys, res, data;
|
|
2137
|
+
return __generator(this, function (_a) {
|
|
2138
|
+
switch (_a.label) {
|
|
2139
|
+
case 0:
|
|
2140
|
+
req = deepClone(_req);
|
|
2141
|
+
if (!req.url) return [3 /*break*/, 3];
|
|
2142
|
+
if (typeof req.headers === 'object') {
|
|
2143
|
+
for (i in req.headers) {
|
|
2144
|
+
keys = req.headers[i].match(/(?<=\$\{).*?(?=\})/g);
|
|
2145
|
+
if (keys) {
|
|
2146
|
+
req.headers[i] = req.headers[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
|
|
2147
|
+
}
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
if (typeof req.body === 'object') {
|
|
2151
|
+
for (i in req.body) {
|
|
2152
|
+
keys = req.body[i].match(/(?<=\$\{).*?(?=\})/g);
|
|
2153
|
+
if (keys) {
|
|
2154
|
+
req.body[i] = req.body[i].replace("${" + keys[0] + "}", this.getDynamicParam(keys[0]));
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
return [4 /*yield*/, fetch(req.url, {
|
|
2159
|
+
headers: req.headers,
|
|
2160
|
+
method: req.method,
|
|
2161
|
+
body: req.method === 'GET' ? undefined : JSON.stringify(req.body),
|
|
2162
|
+
})];
|
|
2163
|
+
case 1:
|
|
2164
|
+
res = _a.sent();
|
|
2165
|
+
if (!res.ok) return [3 /*break*/, 3];
|
|
2166
|
+
return [4 /*yield*/, res.text()];
|
|
2167
|
+
case 2:
|
|
2168
|
+
data = _a.sent();
|
|
2169
|
+
this.socketCallback(data, { type: 'http', url: req.url });
|
|
2170
|
+
_a.label = 3;
|
|
2171
|
+
case 3: return [2 /*return*/];
|
|
2172
|
+
}
|
|
2173
|
+
});
|
|
2174
|
+
});
|
|
2175
|
+
};
|
|
2112
2176
|
Meta2d.prototype.closeNetwork = function () {
|
|
2113
2177
|
this.mqttClients &&
|
|
2114
2178
|
this.mqttClients.forEach(function (mqttClient) {
|
|
@@ -2331,10 +2395,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
2331
2395
|
this.canvas.calcActiveRect();
|
|
2332
2396
|
}
|
|
2333
2397
|
if (history) {
|
|
2398
|
+
var _pens = deepClone(pens);
|
|
2334
2399
|
this.pushHistory({
|
|
2335
2400
|
type: EditType.Update,
|
|
2336
2401
|
initPens: initPens,
|
|
2337
|
-
pens:
|
|
2402
|
+
pens: _pens,
|
|
2338
2403
|
});
|
|
2339
2404
|
}
|
|
2340
2405
|
doEvent &&
|
|
@@ -2495,9 +2560,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
2495
2560
|
step: step,
|
|
2496
2561
|
});
|
|
2497
2562
|
};
|
|
2498
|
-
Meta2d.prototype.toPng = function (padding, callback, containBkImg) {
|
|
2563
|
+
Meta2d.prototype.toPng = function (padding, callback, containBkImg, maxWidth) {
|
|
2499
2564
|
if (containBkImg === void 0) { containBkImg = false; }
|
|
2500
|
-
return this.canvas.toPng(padding, callback, containBkImg);
|
|
2565
|
+
return this.canvas.toPng(padding, callback, containBkImg, maxWidth);
|
|
2501
2566
|
};
|
|
2502
2567
|
Meta2d.prototype.activeToPng = function (padding) {
|
|
2503
2568
|
return this.canvas.activeToPng(padding);
|
|
@@ -2507,7 +2572,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2507
2572
|
* @param name 传入参数自带文件后缀名 例如:'test.png'
|
|
2508
2573
|
* @param padding 上右下左的内边距
|
|
2509
2574
|
*/
|
|
2510
|
-
Meta2d.prototype.downloadPng = function (name, padding) {
|
|
2575
|
+
Meta2d.prototype.downloadPng = function (name, padding, maxWidth) {
|
|
2511
2576
|
var e_6, _a;
|
|
2512
2577
|
var _this = this;
|
|
2513
2578
|
var _b;
|
|
@@ -2530,7 +2595,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2530
2595
|
setTimeout(function () {
|
|
2531
2596
|
var a = document.createElement('a');
|
|
2532
2597
|
a.setAttribute('download', (name || _this.store.data.name || 'le5le.meta2d') + '.png');
|
|
2533
|
-
a.setAttribute('href', _this.toPng(padding, undefined, true));
|
|
2598
|
+
a.setAttribute('href', _this.toPng(padding, undefined, true, maxWidth));
|
|
2534
2599
|
var evt = document.createEvent('MouseEvents');
|
|
2535
2600
|
evt.initEvent('click', true, true);
|
|
2536
2601
|
a.dispatchEvent(evt);
|
|
@@ -3459,7 +3524,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
3459
3524
|
}
|
|
3460
3525
|
//dom
|
|
3461
3526
|
if (pen.externElement || pen.name === 'gif') {
|
|
3462
|
-
var zIndex =
|
|
3527
|
+
var zIndex = 1;
|
|
3463
3528
|
// let zIndex = pen.calculative.zIndex === undefined ? 5 : pen.calculative.zIndex + 1;
|
|
3464
3529
|
if (type === 'top') {
|
|
3465
3530
|
pen.calculative.canvas.maxZindex += 1;
|
|
@@ -3472,8 +3537,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
3472
3537
|
else if (type === 'down') {
|
|
3473
3538
|
zIndex =
|
|
3474
3539
|
pen.calculative.zIndex === undefined ? 3 : pen.calculative.zIndex - 1;
|
|
3475
|
-
if (zIndex <
|
|
3476
|
-
zIndex =
|
|
3540
|
+
if (zIndex < 1) {
|
|
3541
|
+
zIndex = 1;
|
|
3477
3542
|
}
|
|
3478
3543
|
}
|
|
3479
3544
|
this.setValue({ id: pen.id, zIndex: zIndex }, { render: false, doEvent: false, history: false });
|