@meta2d/core 1.0.31 → 1.0.33
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 +2 -2
- package/src/canvas/canvas.d.ts +1 -1
- package/src/canvas/canvas.js +193 -12
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +4 -4
- package/src/core.js +51 -21
- package/src/core.js.map +1 -1
- package/src/event/event.d.ts +3 -0
- 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/render.js +5 -2
- package/src/pen/render.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -54,7 +54,7 @@ export declare class Meta2d {
|
|
|
54
54
|
initEventFns(): void;
|
|
55
55
|
navigatorTo(id: string): void;
|
|
56
56
|
doSendDataEvent(value: any, topics?: string): void;
|
|
57
|
-
sendDataToNetWork(value: any,
|
|
57
|
+
sendDataToNetWork(value: any, _network: Network): Promise<void>;
|
|
58
58
|
resize(width?: number, height?: number): void;
|
|
59
59
|
/**
|
|
60
60
|
*
|
|
@@ -63,7 +63,7 @@ export declare class Meta2d {
|
|
|
63
63
|
addPen(pen: Pen, history?: boolean, emit?: boolean): Promise<Pen>;
|
|
64
64
|
addPens(pens: Pen[], history?: boolean): Promise<Pen[]>;
|
|
65
65
|
render(patchFlags?: boolean | number): void;
|
|
66
|
-
setBackgroundImage(url: string): Promise<void>;
|
|
66
|
+
setBackgroundImage(url: string, data?: any): Promise<void>;
|
|
67
67
|
setBackgroundColor(color?: string): void;
|
|
68
68
|
setGrid({ grid, gridColor, gridSize, gridRotate, }?: {
|
|
69
69
|
grid?: boolean;
|
|
@@ -232,14 +232,14 @@ export declare class Meta2d {
|
|
|
232
232
|
judgeCondition(pen: Pen, key: string, condition: TriggerCondition): boolean;
|
|
233
233
|
pushChildren(parent: Pen, children: Pen[]): void;
|
|
234
234
|
renderPenRaw: typeof renderPenRaw;
|
|
235
|
-
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean): string;
|
|
235
|
+
toPng(padding?: Padding, callback?: BlobCallback, containBkImg?: boolean, maxWidth?: number): string;
|
|
236
236
|
activeToPng(padding?: Padding): string;
|
|
237
237
|
/**
|
|
238
238
|
* 下载 png
|
|
239
239
|
* @param name 传入参数自带文件后缀名 例如:'test.png'
|
|
240
240
|
* @param padding 上右下左的内边距
|
|
241
241
|
*/
|
|
242
|
-
downloadPng(name?: string, padding?: Padding): void;
|
|
242
|
+
downloadPng(name?: string, padding?: Padding, maxWidth?: number): void;
|
|
243
243
|
downloadSvg(): void;
|
|
244
244
|
getRect(pens?: Pen[]): Rect;
|
|
245
245
|
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;
|
|
@@ -186,11 +187,32 @@ var Meta2d = /** @class */ (function () {
|
|
|
186
187
|
(_a = pen.events) === null || _a === void 0 ? void 0 : _a.forEach(function (event) {
|
|
187
188
|
var _a;
|
|
188
189
|
if (event.actions && event.actions.length) {
|
|
189
|
-
event.
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
if (event.name === eventName) {
|
|
191
|
+
//条件成立
|
|
192
|
+
var flag = false;
|
|
193
|
+
if (event.conditions && event.conditions.length) {
|
|
194
|
+
if (event.conditionType === 'and') {
|
|
195
|
+
flag = event.conditions.every(function (condition) {
|
|
196
|
+
return _this.judgeCondition(pen, condition.key, condition);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
else if (event.conditionType === 'or') {
|
|
200
|
+
flag = event.conditions.some(function (condition) {
|
|
201
|
+
return _this.judgeCondition(pen, condition.key, condition);
|
|
202
|
+
});
|
|
203
|
+
}
|
|
192
204
|
}
|
|
193
|
-
|
|
205
|
+
else {
|
|
206
|
+
flag = true;
|
|
207
|
+
}
|
|
208
|
+
if (flag) {
|
|
209
|
+
event.actions.forEach(function (action) {
|
|
210
|
+
if (_this.events[action.action]) {
|
|
211
|
+
_this.events[action.action](pen, action);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
}
|
|
194
216
|
}
|
|
195
217
|
else {
|
|
196
218
|
if (_this.events[event.action] && event.name === eventName) {
|
|
@@ -362,6 +384,11 @@ var Meta2d = /** @class */ (function () {
|
|
|
362
384
|
ruleColor: opts.ruleColor,
|
|
363
385
|
});
|
|
364
386
|
}
|
|
387
|
+
if (opts.resizeMode !== undefined) {
|
|
388
|
+
if (!opts.resizeMode) {
|
|
389
|
+
this.canvas.hotkeyType = HotkeyType.None;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
365
392
|
this.store.options = Object.assign(this.store.options, opts);
|
|
366
393
|
if (this.canvas && opts.scroll !== undefined) {
|
|
367
394
|
if (opts.scroll) {
|
|
@@ -623,7 +650,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
623
650
|
window.location.href = arr[0] + 'id=' + id;
|
|
624
651
|
}
|
|
625
652
|
else {
|
|
626
|
-
window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx
|
|
653
|
+
window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx);
|
|
627
654
|
}
|
|
628
655
|
}
|
|
629
656
|
};
|
|
@@ -651,12 +678,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
651
678
|
}
|
|
652
679
|
this.store.emitter.emit('sendData', data);
|
|
653
680
|
};
|
|
654
|
-
Meta2d.prototype.sendDataToNetWork = function (value,
|
|
681
|
+
Meta2d.prototype.sendDataToNetWork = function (value, _network) {
|
|
655
682
|
return __awaiter(this, void 0, void 0, function () {
|
|
656
|
-
var i, keys, params, res, clients_1, mqttClient_1, websockets, websocket_1;
|
|
683
|
+
var network, i, keys, params, res, clients_1, mqttClient_1, websockets, websocket_1;
|
|
657
684
|
return __generator(this, function (_a) {
|
|
658
685
|
switch (_a.label) {
|
|
659
686
|
case 0:
|
|
687
|
+
network = deepClone(_network);
|
|
660
688
|
if (!network.url) {
|
|
661
689
|
return [2 /*return*/];
|
|
662
690
|
}
|
|
@@ -770,7 +798,8 @@ var Meta2d = /** @class */ (function () {
|
|
|
770
798
|
var _a;
|
|
771
799
|
(_a = this.canvas) === null || _a === void 0 ? void 0 : _a.render(patchFlags);
|
|
772
800
|
};
|
|
773
|
-
Meta2d.prototype.setBackgroundImage = function (url) {
|
|
801
|
+
Meta2d.prototype.setBackgroundImage = function (url, data) {
|
|
802
|
+
var _a, _b, _c, _e;
|
|
774
803
|
return __awaiter(this, void 0, void 0, function () {
|
|
775
804
|
function loadImage(url) {
|
|
776
805
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -793,13 +822,13 @@ var Meta2d = /** @class */ (function () {
|
|
|
793
822
|
});
|
|
794
823
|
}
|
|
795
824
|
var that, width, height, img;
|
|
796
|
-
return __generator(this, function (
|
|
797
|
-
switch (
|
|
825
|
+
return __generator(this, function (_f) {
|
|
826
|
+
switch (_f.label) {
|
|
798
827
|
case 0:
|
|
799
828
|
that = this;
|
|
800
829
|
this.store.data.bkImage = url;
|
|
801
|
-
width = this.store.data.width || this.store.options.width;
|
|
802
|
-
height = this.store.data.height || this.store.options.height;
|
|
830
|
+
width = (data === null || data === void 0 ? void 0 : data.width) || ((_a = this.store.data) === null || _a === void 0 ? void 0 : _a.width) || ((_b = this.store.options) === null || _b === void 0 ? void 0 : _b.width);
|
|
831
|
+
height = (data === null || data === void 0 ? void 0 : data.height) || ((_c = this.store.data) === null || _c === void 0 ? void 0 : _c.height) || ((_e = this.store.options) === null || _e === void 0 ? void 0 : _e.height);
|
|
803
832
|
if (width && height) {
|
|
804
833
|
this.canvas.canvasTemplate.canvas.style.backgroundImage = null;
|
|
805
834
|
this.canvas && (this.canvas.canvasTemplate.bgPatchFlags = true);
|
|
@@ -812,7 +841,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
812
841
|
if (!url) return [3 /*break*/, 2];
|
|
813
842
|
return [4 /*yield*/, loadImage(url)];
|
|
814
843
|
case 1:
|
|
815
|
-
img =
|
|
844
|
+
img = _f.sent();
|
|
816
845
|
// 用作 toPng 的绘制
|
|
817
846
|
this.store.bkImg = img;
|
|
818
847
|
if (width && height) {
|
|
@@ -824,7 +853,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
824
853
|
return [3 /*break*/, 3];
|
|
825
854
|
case 2:
|
|
826
855
|
this.store.bkImg = null;
|
|
827
|
-
|
|
856
|
+
_f.label = 3;
|
|
828
857
|
case 3: return [2 /*return*/];
|
|
829
858
|
}
|
|
830
859
|
});
|
|
@@ -858,7 +887,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
858
887
|
this.clear(false, data.template);
|
|
859
888
|
this.canvas.autoPolylineFlag = true;
|
|
860
889
|
if (data) {
|
|
861
|
-
this.setBackgroundImage(data.bkImage);
|
|
890
|
+
this.setBackgroundImage(data.bkImage, data);
|
|
862
891
|
Object.assign(this.store.data, data);
|
|
863
892
|
this.store.data.pens = [];
|
|
864
893
|
try {
|
|
@@ -2064,11 +2093,12 @@ var Meta2d = /** @class */ (function () {
|
|
|
2064
2093
|
_this.store.data.pens.forEach(function (pen) {
|
|
2065
2094
|
_this.penMock(pen);
|
|
2066
2095
|
});
|
|
2067
|
-
https.forEach(function (
|
|
2068
|
-
var i, keys, i, keys, res, data;
|
|
2096
|
+
https.forEach(function (_item) { return __awaiter(_this, void 0, void 0, function () {
|
|
2097
|
+
var item, i, keys, i, keys, res, data;
|
|
2069
2098
|
return __generator(this, function (_a) {
|
|
2070
2099
|
switch (_a.label) {
|
|
2071
2100
|
case 0:
|
|
2101
|
+
item = deepClone(_item);
|
|
2072
2102
|
if (!item.url) return [3 /*break*/, 3];
|
|
2073
2103
|
if (typeof item.headers === 'object') {
|
|
2074
2104
|
for (i in item.headers) {
|
|
@@ -2492,9 +2522,9 @@ var Meta2d = /** @class */ (function () {
|
|
|
2492
2522
|
step: step,
|
|
2493
2523
|
});
|
|
2494
2524
|
};
|
|
2495
|
-
Meta2d.prototype.toPng = function (padding, callback, containBkImg) {
|
|
2525
|
+
Meta2d.prototype.toPng = function (padding, callback, containBkImg, maxWidth) {
|
|
2496
2526
|
if (containBkImg === void 0) { containBkImg = false; }
|
|
2497
|
-
return this.canvas.toPng(padding, callback, containBkImg);
|
|
2527
|
+
return this.canvas.toPng(padding, callback, containBkImg, maxWidth);
|
|
2498
2528
|
};
|
|
2499
2529
|
Meta2d.prototype.activeToPng = function (padding) {
|
|
2500
2530
|
return this.canvas.activeToPng(padding);
|
|
@@ -2504,7 +2534,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2504
2534
|
* @param name 传入参数自带文件后缀名 例如:'test.png'
|
|
2505
2535
|
* @param padding 上右下左的内边距
|
|
2506
2536
|
*/
|
|
2507
|
-
Meta2d.prototype.downloadPng = function (name, padding) {
|
|
2537
|
+
Meta2d.prototype.downloadPng = function (name, padding, maxWidth) {
|
|
2508
2538
|
var e_6, _a;
|
|
2509
2539
|
var _this = this;
|
|
2510
2540
|
var _b;
|
|
@@ -2527,7 +2557,7 @@ var Meta2d = /** @class */ (function () {
|
|
|
2527
2557
|
setTimeout(function () {
|
|
2528
2558
|
var a = document.createElement('a');
|
|
2529
2559
|
a.setAttribute('download', (name || _this.store.data.name || 'le5le.meta2d') + '.png');
|
|
2530
|
-
a.setAttribute('href', _this.toPng(padding, undefined, true));
|
|
2560
|
+
a.setAttribute('href', _this.toPng(padding, undefined, true, maxWidth));
|
|
2531
2561
|
var evt = document.createEvent('MouseEvents');
|
|
2532
2562
|
evt.initEvent('click', true, true);
|
|
2533
2563
|
a.dispatchEvent(evt);
|