@meta2d/core 1.0.57 → 1.0.59
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 +37 -36
- package/src/canvas/canvas.js +48 -8
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +9 -1
- package/src/core.js +124 -26
- package/src/core.js.map +1 -1
- package/src/diagrams/index.d.ts +1 -0
- package/src/diagrams/index.js +2 -1
- package/src/diagrams/index.js.map +1 -1
- package/src/diagrams/line/line.js +6 -1
- package/src/diagrams/line/line.js.map +1 -1
- package/src/diagrams/rectangle.js +1 -0
- package/src/diagrams/rectangle.js.map +1 -1
- package/src/dialog/dialog.js +1 -1
- package/src/dialog/dialog.js.map +1 -1
- package/src/options.d.ts +5 -0
- package/src/options.js.map +1 -1
- package/src/pen/model.d.ts +1 -0
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +36 -36
- package/src/pen/render.js.map +1 -1
- package/src/pen/text.js +2 -4
- package/src/pen/text.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -59,7 +59,7 @@ export declare class Meta2d {
|
|
|
59
59
|
setDatabyOptions(options?: Options): void;
|
|
60
60
|
private init;
|
|
61
61
|
initEventFns(): void;
|
|
62
|
-
navigatorTo(id: string): void
|
|
62
|
+
navigatorTo(id: string): Promise<void>;
|
|
63
63
|
doSendDataEvent(value: any, topics?: string): void;
|
|
64
64
|
sendDataToNetWork(value: any, pen: Pen, e: any): Promise<void>;
|
|
65
65
|
resize(width?: number, height?: number): void;
|
|
@@ -160,6 +160,13 @@ export declare class Meta2d {
|
|
|
160
160
|
combine(pens?: Pen[], showChild?: number): any;
|
|
161
161
|
uncombine(pen?: Pen): void;
|
|
162
162
|
appendChild(pens?: Pen[]): void;
|
|
163
|
+
/***
|
|
164
|
+
* 修改子图元大小,更新整个组合图元
|
|
165
|
+
* @param rect 新的大小 世界坐标
|
|
166
|
+
* @param child 待更新子图元
|
|
167
|
+
* @param parent 父图元
|
|
168
|
+
*/
|
|
169
|
+
updateRectbyChild(rect: Rect, child: Pen, parent: Pen): void;
|
|
163
170
|
isCombine(pen: Pen): boolean;
|
|
164
171
|
active(pens: Pen[], emit?: boolean): void;
|
|
165
172
|
inactive(): void;
|
|
@@ -218,6 +225,7 @@ export declare class Meta2d {
|
|
|
218
225
|
stopDataMock(): void;
|
|
219
226
|
penMock(pen: Pen): void;
|
|
220
227
|
penNetwork(pen: Pen): void;
|
|
228
|
+
getCookie(name: string): string;
|
|
221
229
|
getDynamicParam(key: string): any;
|
|
222
230
|
onNetworkConnect(https: Network[]): void;
|
|
223
231
|
requestHttp(_req: Network): Promise<void>;
|
package/src/core.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { commonAnchors, commonPens, cube } from './diagrams';
|
|
2
2
|
import { Canvas } from './canvas';
|
|
3
|
-
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers, isInteraction } from './pen';
|
|
3
|
+
import { calcInView, calcTextDrawRect, calcTextLines, calcTextRect, facePen, formatAttrs, getAllChildren, getFromAnchor, getParent, getToAnchor, getWords, LockState, PenType, renderPenRaw, setElemPosition, connectLine, nearestAnchor, setChildValue, isAncestor, isShowChild, CanvasLayer, validationPlugin, setLifeCycleFunc, getAllFollowers, isInteraction, calcWorldAnchors } from './pen';
|
|
4
4
|
import { rotatePoint } from './point';
|
|
5
5
|
import { clearStore, EditType, globalStore, register, registerAnchors, registerCanvasDraw, useStore, } from './store';
|
|
6
6
|
import { formatPadding, loadCss, s8, valueInArray, valueInRange, } from './utils';
|
|
7
|
-
import { calcCenter, calcRelativeRect, getRect, rectInRect, } from './rect';
|
|
7
|
+
import { calcCenter, calcRelativeRect, calcRightBottom, getRect, rectInRect, } from './rect';
|
|
8
8
|
import { deepClone } from './utils/clone';
|
|
9
9
|
import { EventAction } from './event';
|
|
10
10
|
import { ViewMap } from './map';
|
|
@@ -144,7 +144,7 @@ export class Meta2d {
|
|
|
144
144
|
this.render();
|
|
145
145
|
}
|
|
146
146
|
setDatabyOptions(options = {}) {
|
|
147
|
-
const { color, activeColor, activeBackground, grid, gridColor, gridSize, fromArrow, toArrow, rule, ruleColor, textColor, } = options;
|
|
147
|
+
const { color, activeColor, activeBackground, grid, gridColor, gridSize, fromArrow, toArrow, rule, ruleColor, textColor, x = 0, y = 0, } = options;
|
|
148
148
|
this.setRule({ rule, ruleColor });
|
|
149
149
|
this.setGrid({
|
|
150
150
|
grid,
|
|
@@ -158,6 +158,8 @@ export class Meta2d {
|
|
|
158
158
|
activeBackground,
|
|
159
159
|
fromArrow,
|
|
160
160
|
toArrow,
|
|
161
|
+
x,
|
|
162
|
+
y
|
|
161
163
|
});
|
|
162
164
|
}
|
|
163
165
|
init(parent) {
|
|
@@ -363,6 +365,12 @@ export class Meta2d {
|
|
|
363
365
|
if (value[key] === undefined || value[key] === '') {
|
|
364
366
|
value[key] = _pen[key];
|
|
365
367
|
}
|
|
368
|
+
else if (typeof value[key] === 'string' && value[key]?.indexOf('${') > -1) {
|
|
369
|
+
let keys = value[key].match(/(?<=\$\{).*?(?=\})/g);
|
|
370
|
+
if (keys?.length) {
|
|
371
|
+
value[key] = _pen[keys[0]];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
366
374
|
}
|
|
367
375
|
// value.id = _pen.id;
|
|
368
376
|
if (_pen.deviceId) {
|
|
@@ -399,20 +407,49 @@ export class Meta2d {
|
|
|
399
407
|
return;
|
|
400
408
|
};
|
|
401
409
|
}
|
|
402
|
-
navigatorTo(id) {
|
|
410
|
+
async navigatorTo(id) {
|
|
403
411
|
if (!id) {
|
|
404
412
|
return;
|
|
405
413
|
}
|
|
406
|
-
let href = window.location.href;
|
|
407
|
-
let arr = href.split('id=');
|
|
408
|
-
if (arr.length > 1) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
414
|
+
// let href = window.location.href;
|
|
415
|
+
// let arr: string[] = href.split('id=');
|
|
416
|
+
// if (arr.length > 1) {
|
|
417
|
+
// let idx = arr[1].indexOf('&');
|
|
418
|
+
// if (idx === -1) {
|
|
419
|
+
// window.location.href = arr[0] + 'id=' + id;
|
|
420
|
+
// } else {
|
|
421
|
+
// window.location.href = arr[0] + 'id=' + id + arr[1].slice(idx);
|
|
422
|
+
// }
|
|
423
|
+
// }
|
|
424
|
+
//路径参数更新
|
|
425
|
+
const url = new URL(window.location);
|
|
426
|
+
url.searchParams.set('id', id);
|
|
427
|
+
history.pushState({}, '', url);
|
|
428
|
+
//图纸更新
|
|
429
|
+
const netWork = this.store.options.navigatorNetWork;
|
|
430
|
+
const collection = (location.href.includes('2d.') || location.href.includes('/2d')) ? '2d' : 'v';
|
|
431
|
+
const res = await fetch((netWork?.url || `/api/data/${collection}/get`) + (netWork?.method === 'GET' ? `?id=${id}` : ''), {
|
|
432
|
+
headers: {
|
|
433
|
+
Authorization: `Bearer ${this.getCookie('token') || localStorage.getItem('token') || new URLSearchParams(location.search).get('token') || ''}`,
|
|
434
|
+
},
|
|
435
|
+
method: netWork?.method || 'POST',
|
|
436
|
+
body: netWork?.method === 'GET' ? undefined : JSON.stringify({ id: id }),
|
|
437
|
+
});
|
|
438
|
+
if (res.ok) {
|
|
439
|
+
let data = await res.text();
|
|
440
|
+
if (data.constructor === Object || data.constructor === Array) {
|
|
441
|
+
data = JSON.parse(JSON.stringify(data));
|
|
412
442
|
}
|
|
413
|
-
else {
|
|
414
|
-
|
|
443
|
+
else if (typeof data === 'string') {
|
|
444
|
+
data = JSON.parse(data);
|
|
415
445
|
}
|
|
446
|
+
if (data.data) {
|
|
447
|
+
data = data.data;
|
|
448
|
+
}
|
|
449
|
+
this.open(data);
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
this.store.emitter.emit('error', { type: 'http', error: res });
|
|
416
453
|
}
|
|
417
454
|
}
|
|
418
455
|
doSendDataEvent(value, topics) {
|
|
@@ -1231,7 +1268,7 @@ export class Meta2d {
|
|
|
1231
1268
|
pen.parentId = parent.id;
|
|
1232
1269
|
const childRect = calcRelativeRect(pen.calculative.worldRect, rect);
|
|
1233
1270
|
Object.assign(pen, childRect);
|
|
1234
|
-
pen.locked = pen.lockedOnCombine ?? LockState.
|
|
1271
|
+
pen.locked = pen.lockedOnCombine ?? LockState.None;
|
|
1235
1272
|
pen.locked = (pen.interaction || isInteraction.includes(pen.name)) ? 0 : pen.locked;
|
|
1236
1273
|
});
|
|
1237
1274
|
//将组合后的父节点置底
|
|
@@ -1328,9 +1365,26 @@ export class Meta2d {
|
|
|
1328
1365
|
const pIdx = pens.findIndex(pen => pen.name === 'combine' && pen.showChild !== undefined);
|
|
1329
1366
|
if (pIdx !== -1) {
|
|
1330
1367
|
let parent = pens[pIdx];
|
|
1331
|
-
this.pushChildren(parent,
|
|
1368
|
+
// this.pushChildren(parent,[...pens.slice(0, pIdx), ...pens.slice(pIdx + 1)]);
|
|
1369
|
+
const rect = getRect(pens);
|
|
1370
|
+
Object.assign(parent, rect);
|
|
1371
|
+
Object.assign(parent.calculative.worldRect, rect);
|
|
1372
|
+
calcWorldAnchors(parent);
|
|
1373
|
+
parent.children.forEach(penId => {
|
|
1374
|
+
const pen = this.store.pens[penId];
|
|
1375
|
+
const childRect = calcRelativeRect(pen.calculative.worldRect, rect);
|
|
1376
|
+
Object.assign(pen, childRect);
|
|
1377
|
+
});
|
|
1332
1378
|
pens.forEach((pen) => {
|
|
1333
|
-
|
|
1379
|
+
if (pen.id !== parent.id) {
|
|
1380
|
+
parent.children.push(pen.id);
|
|
1381
|
+
pen.parentId = parent.id;
|
|
1382
|
+
const childRect = calcRelativeRect(pen.calculative.worldRect, rect);
|
|
1383
|
+
Object.assign(pen, childRect);
|
|
1384
|
+
pen.locked = pen.lockedOnCombine ?? LockState.DisableMove;
|
|
1385
|
+
pen.locked = (pen.interaction || isInteraction.includes(pen.name)) ? 0 : pen.locked;
|
|
1386
|
+
calcInView(pen, true);
|
|
1387
|
+
}
|
|
1334
1388
|
});
|
|
1335
1389
|
this.initImageCanvas(pens);
|
|
1336
1390
|
this.render();
|
|
@@ -1339,6 +1393,49 @@ export class Meta2d {
|
|
|
1339
1393
|
console.warn('Invalid operation!');
|
|
1340
1394
|
}
|
|
1341
1395
|
}
|
|
1396
|
+
/***
|
|
1397
|
+
* 修改子图元大小,更新整个组合图元
|
|
1398
|
+
* @param rect 新的大小 世界坐标
|
|
1399
|
+
* @param child 待更新子图元
|
|
1400
|
+
* @param parent 父图元
|
|
1401
|
+
*/
|
|
1402
|
+
updateRectbyChild(rect, child, parent) {
|
|
1403
|
+
calcRightBottom(rect);
|
|
1404
|
+
calcCenter(rect);
|
|
1405
|
+
child.calculative.worldRect = rect;
|
|
1406
|
+
if (rectInRect(rect, parent.calculative.worldRect, true)) {
|
|
1407
|
+
const childRect = calcRelativeRect(rect, parent.calculative.worldRect);
|
|
1408
|
+
Object.assign(child, childRect);
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
let x = Math.min(rect.x, parent.calculative.worldRect.x);
|
|
1412
|
+
let y = Math.min(rect.y, parent.calculative.worldRect.y);
|
|
1413
|
+
let ex = Math.max(rect.ex, parent.calculative.worldRect.ex);
|
|
1414
|
+
let ey = Math.max(rect.ey, parent.calculative.worldRect.ey);
|
|
1415
|
+
parent.calculative.worldRect = {
|
|
1416
|
+
x: x,
|
|
1417
|
+
y: y,
|
|
1418
|
+
width: ex - x,
|
|
1419
|
+
height: ey - y,
|
|
1420
|
+
ex,
|
|
1421
|
+
ey
|
|
1422
|
+
};
|
|
1423
|
+
if (!parent.parentId) {
|
|
1424
|
+
Object.assign(parent, parent.calculative.worldRect);
|
|
1425
|
+
}
|
|
1426
|
+
calcCenter(parent.calculative.worldRect);
|
|
1427
|
+
parent.children.forEach((cid) => {
|
|
1428
|
+
const cPen = this.store.pens[cid];
|
|
1429
|
+
const childRect = calcRelativeRect(cPen.calculative.worldRect, parent.calculative.worldRect);
|
|
1430
|
+
Object.assign(cPen, childRect);
|
|
1431
|
+
});
|
|
1432
|
+
if (parent.parentId) {
|
|
1433
|
+
this.updateRectbyChild(parent.calculative.worldRect, parent, this.store.pens[parent.parentId]);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
this.canvas.updatePenRect(parent);
|
|
1437
|
+
this.render();
|
|
1438
|
+
}
|
|
1342
1439
|
isCombine(pen) {
|
|
1343
1440
|
if (pen.name === 'combine') {
|
|
1344
1441
|
return true;
|
|
@@ -1944,20 +2041,20 @@ export class Meta2d {
|
|
|
1944
2041
|
delete this.store.pensNetwork[pen.id];
|
|
1945
2042
|
}
|
|
1946
2043
|
}
|
|
2044
|
+
getCookie(name) {
|
|
2045
|
+
let arr;
|
|
2046
|
+
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
|
|
2047
|
+
if ((arr = document.cookie.match(reg))) {
|
|
2048
|
+
return decodeURIComponent(arr[2]);
|
|
2049
|
+
}
|
|
2050
|
+
else {
|
|
2051
|
+
return '';
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
1947
2054
|
//获取动态参数
|
|
1948
2055
|
getDynamicParam(key) {
|
|
1949
|
-
function getCookie(name) {
|
|
1950
|
-
let arr;
|
|
1951
|
-
const reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
|
|
1952
|
-
if ((arr = document.cookie.match(reg))) {
|
|
1953
|
-
return decodeURIComponent(arr[2]);
|
|
1954
|
-
}
|
|
1955
|
-
else {
|
|
1956
|
-
return '';
|
|
1957
|
-
}
|
|
1958
|
-
}
|
|
1959
2056
|
let params = queryURLParams();
|
|
1960
|
-
let value = params[key] || localStorage[key] || getCookie(key) || '';
|
|
2057
|
+
let value = params[key] || localStorage[key] || this.getCookie(key) || '';
|
|
1961
2058
|
return value;
|
|
1962
2059
|
}
|
|
1963
2060
|
onNetworkConnect(https) {
|
|
@@ -4570,6 +4667,7 @@ export class Meta2d {
|
|
|
4570
4667
|
setLifeCycleFunc = setLifeCycleFunc;
|
|
4571
4668
|
destroy(onlyData) {
|
|
4572
4669
|
this.clear(false);
|
|
4670
|
+
this.stopDataMock();
|
|
4573
4671
|
this.closeSocket();
|
|
4574
4672
|
this.closeNetwork();
|
|
4575
4673
|
this.store.emitter.all.clear(); // 内存释放
|