@meta2d/core 1.0.85 → 1.0.87
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 +7 -1
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +2 -0
- package/src/core.js +137 -44
- package/src/core.js.map +1 -1
- package/src/options.d.ts +1 -0
- package/src/options.js.map +1 -1
- package/src/pen/math.d.ts +1 -0
- package/src/pen/math.js +21 -0
- package/src/pen/math.js.map +1 -1
- package/src/pen/model.d.ts +7 -0
- package/src/pen/model.js +13 -1
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +25 -3
- package/src/pen/render.js.map +1 -1
- package/src/pen/text.js +1 -1
- package/src/pen/text.js.map +1 -1
package/src/core.d.ts
CHANGED
|
@@ -101,6 +101,8 @@ export declare class Meta2d {
|
|
|
101
101
|
ruleColor?: string;
|
|
102
102
|
}): void;
|
|
103
103
|
open(data?: Meta2dData, render?: boolean): void;
|
|
104
|
+
dirtyData(active?: boolean): any[];
|
|
105
|
+
clearDirtyData(): void;
|
|
104
106
|
cacheData(id: string): void;
|
|
105
107
|
loadCacheData(id: string): void;
|
|
106
108
|
loadLineAnimateDraws(): void;
|
package/src/core.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { commonAnchors, commonPens, cube, reset, updateFormData } 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, calcWorldAnchors, isDomShapes, } 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, isDomShapes, defaultFormat, findOutliersByZScore, } 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';
|
|
@@ -698,14 +698,25 @@ export class Meta2d {
|
|
|
698
698
|
}
|
|
699
699
|
if (network.protocol === 'http') {
|
|
700
700
|
if (typeof network.headers === 'object') {
|
|
701
|
-
for (let i in network.headers) {
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
}
|
|
701
|
+
/*for (let i in network.headers) {
|
|
702
|
+
if (typeof network.headers[i] === 'string') {
|
|
703
|
+
let keys = network.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
704
|
+
if (keys) {
|
|
705
|
+
network.headers[i] = network.headers[i].replace(
|
|
706
|
+
`\${${keys[0]}}`,
|
|
707
|
+
this.getDynamicParam(keys[0])
|
|
708
|
+
);
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
}*/
|
|
712
|
+
let headersStr = JSON.stringify(network.headers);
|
|
713
|
+
let keys = headersStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
714
|
+
if (keys?.length) {
|
|
715
|
+
for (let i = 0; i < keys.length; i++) {
|
|
716
|
+
headersStr = headersStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
|
|
707
717
|
}
|
|
708
718
|
}
|
|
719
|
+
network.headers = JSON.parse(headersStr);
|
|
709
720
|
}
|
|
710
721
|
let params = undefined;
|
|
711
722
|
let url = network.url;
|
|
@@ -716,16 +727,16 @@ export class Meta2d {
|
|
|
716
727
|
.map((key) => key + '=' + value[key])
|
|
717
728
|
.join('&');
|
|
718
729
|
}
|
|
719
|
-
if (network.method === 'POST') {
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
}
|
|
730
|
+
// if (network.method === 'POST') {
|
|
731
|
+
if (url.indexOf('${') > -1) {
|
|
732
|
+
let keys = url.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
733
|
+
if (keys) {
|
|
734
|
+
keys.forEach((key) => {
|
|
735
|
+
url = url.replace(`\${${key}}`, getter(pen, key) || this.getDynamicParam(key));
|
|
736
|
+
});
|
|
727
737
|
}
|
|
728
738
|
}
|
|
739
|
+
// }
|
|
729
740
|
const res = await fetch(url + (params ? params : ''), {
|
|
730
741
|
headers: network.headers || {},
|
|
731
742
|
method: network.method,
|
|
@@ -950,6 +961,58 @@ export class Meta2d {
|
|
|
950
961
|
this.canvas.scroll.init();
|
|
951
962
|
}
|
|
952
963
|
}
|
|
964
|
+
dirtyData(active) {
|
|
965
|
+
//获取画布脏数据
|
|
966
|
+
const pens = this.store.data.pens;
|
|
967
|
+
const width = this.store.data.width || this.store.options.width;
|
|
968
|
+
const height = this.store.data.height || this.store.options.height;
|
|
969
|
+
const dirtyPens = [];
|
|
970
|
+
for (let i = pens.length - 1; i >= 0; i--) {
|
|
971
|
+
let pen = pens[i];
|
|
972
|
+
if (pen.parentId) {
|
|
973
|
+
const parent = this.store.pens[pen.parentId];
|
|
974
|
+
if (pen.x > 10 || pen.y > 10 || pen.width > 10 || pen.height > 10) {
|
|
975
|
+
// 子图元坐标值很大
|
|
976
|
+
dirtyPens.push(pen);
|
|
977
|
+
}
|
|
978
|
+
else if (!parent.children || !parent.children.includes(pen.id)) {
|
|
979
|
+
//已经解组但子图元还有父图元id
|
|
980
|
+
dirtyPens.push(pen);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
if (width && height) {
|
|
984
|
+
//大屏区域外
|
|
985
|
+
let rect = this.getPenRect(pen);
|
|
986
|
+
if (rect.x < -10 || rect.y < -10 || rect.x + rect.width > width || rect.y + rect.height > height) {
|
|
987
|
+
dirtyPens.push(pen);
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
//无效连线 单个锚点连线
|
|
991
|
+
if (pen.name === 'line') {
|
|
992
|
+
if (pen.anchors.length < 2) {
|
|
993
|
+
dirtyPens.push(pen);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
if (!width || !height) {
|
|
998
|
+
//2d 偏移量很大
|
|
999
|
+
let outpens = findOutliersByZScore(pens);
|
|
1000
|
+
outpens.forEach((item) => {
|
|
1001
|
+
let repeat = dirtyPens.filter((_item) => _item.id === item.id);
|
|
1002
|
+
if (!repeat.length) {
|
|
1003
|
+
dirtyPens.push(item);
|
|
1004
|
+
}
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
if (active) {
|
|
1008
|
+
this.active(dirtyPens);
|
|
1009
|
+
}
|
|
1010
|
+
return dirtyPens;
|
|
1011
|
+
}
|
|
1012
|
+
clearDirtyData() {
|
|
1013
|
+
let dirtyPens = this.dirtyData();
|
|
1014
|
+
this.delete(dirtyPens, true);
|
|
1015
|
+
}
|
|
953
1016
|
cacheData(id) {
|
|
954
1017
|
if (id && this.store.options.cacheLength) {
|
|
955
1018
|
let index = this.store.cacheDatas.findIndex((item) => item.data && item.data._id === id);
|
|
@@ -1850,27 +1913,33 @@ export class Meta2d {
|
|
|
1850
1913
|
calcRightBottom(rect);
|
|
1851
1914
|
calcCenter(rect);
|
|
1852
1915
|
child.calculative.worldRect = rect;
|
|
1853
|
-
if (rectInRect(rect, parent.calculative.worldRect, true)) {
|
|
1916
|
+
if (parent.container && rectInRect(rect, parent.calculative.worldRect, true)) { //取所有图元的范围
|
|
1854
1917
|
const childRect = calcRelativeRect(rect, parent.calculative.worldRect);
|
|
1855
1918
|
Object.assign(child, childRect);
|
|
1856
1919
|
}
|
|
1857
1920
|
else {
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1921
|
+
if (parent.container) { //容器模式取操作过程中最大范围
|
|
1922
|
+
let x = Math.min(rect.x, parent.calculative.worldRect.x);
|
|
1923
|
+
let y = Math.min(rect.y, parent.calculative.worldRect.y);
|
|
1924
|
+
let ex = Math.max(rect.ex, parent.calculative.worldRect.ex);
|
|
1925
|
+
let ey = Math.max(rect.ey, parent.calculative.worldRect.ey);
|
|
1926
|
+
parent.calculative.worldRect = {
|
|
1927
|
+
x: x,
|
|
1928
|
+
y: y,
|
|
1929
|
+
width: ex - x,
|
|
1930
|
+
height: ey - y,
|
|
1931
|
+
ex,
|
|
1932
|
+
ey,
|
|
1933
|
+
};
|
|
1934
|
+
calcCenter(parent.calculative.worldRect);
|
|
1935
|
+
}
|
|
1936
|
+
else { //取所有图元的范围
|
|
1937
|
+
const pens = parent.children.map((cid) => this.store.pens[cid]);
|
|
1938
|
+
parent.calculative.worldRect = getRect(pens);
|
|
1939
|
+
}
|
|
1870
1940
|
if (!parent.parentId) {
|
|
1871
1941
|
Object.assign(parent, parent.calculative.worldRect);
|
|
1872
1942
|
}
|
|
1873
|
-
calcCenter(parent.calculative.worldRect);
|
|
1874
1943
|
parent.children.forEach((cid) => {
|
|
1875
1944
|
const cPen = this.store.pens[cid];
|
|
1876
1945
|
const childRect = calcRelativeRect(cPen.calculative.worldRect, parent.calculative.worldRect);
|
|
@@ -2895,24 +2964,46 @@ export class Meta2d {
|
|
|
2895
2964
|
}
|
|
2896
2965
|
}
|
|
2897
2966
|
if (typeof req.headers === 'object') {
|
|
2898
|
-
for (let i in req.headers) {
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
}
|
|
2967
|
+
/*for (let i in req.headers) {
|
|
2968
|
+
if (typeof req.headers[i] === 'string') {
|
|
2969
|
+
let keys = req.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2970
|
+
if (keys) {
|
|
2971
|
+
req.headers[i] = req.headers[i].replace(
|
|
2972
|
+
`\${${keys[0]}}`,
|
|
2973
|
+
this.getDynamicParam(keys[0])
|
|
2974
|
+
);
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
}*/
|
|
2978
|
+
let headersStr = JSON.stringify(req.headers);
|
|
2979
|
+
let keys = headersStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2980
|
+
if (keys?.length) {
|
|
2981
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2982
|
+
headersStr = headersStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
|
|
2904
2983
|
}
|
|
2905
2984
|
}
|
|
2985
|
+
req.headers = JSON.parse(headersStr);
|
|
2906
2986
|
}
|
|
2907
2987
|
if (typeof req.body === 'object') {
|
|
2908
|
-
for (let i in req.body) {
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
}
|
|
2988
|
+
/*for (let i in req.body) {
|
|
2989
|
+
if (typeof req.body[i] === 'string') {
|
|
2990
|
+
let keys = req.body[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2991
|
+
if (keys) {
|
|
2992
|
+
req.body[i] = req.body[i].replace(
|
|
2993
|
+
`\${${keys[0]}}`,
|
|
2994
|
+
this.getDynamicParam(keys[0])
|
|
2995
|
+
);
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
}*/
|
|
2999
|
+
let bodyStr = JSON.stringify(req.body);
|
|
3000
|
+
let keys = bodyStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
3001
|
+
if (keys?.length) {
|
|
3002
|
+
for (let i = 0; i < keys.length; i++) {
|
|
3003
|
+
bodyStr = bodyStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
|
|
2914
3004
|
}
|
|
2915
3005
|
}
|
|
3006
|
+
req.body = JSON.parse(bodyStr);
|
|
2916
3007
|
}
|
|
2917
3008
|
// 默认每一秒请求一次
|
|
2918
3009
|
const res = await fetch(req.url, {
|
|
@@ -4635,7 +4726,7 @@ export class Meta2d {
|
|
|
4635
4726
|
});
|
|
4636
4727
|
for (let i = 1; i < pens.length; i++) {
|
|
4637
4728
|
const pen = pens[i];
|
|
4638
|
-
this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
|
|
4729
|
+
this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
|
|
4639
4730
|
}
|
|
4640
4731
|
this.render();
|
|
4641
4732
|
this.pushHistory({
|
|
@@ -4658,7 +4749,7 @@ export class Meta2d {
|
|
|
4658
4749
|
});
|
|
4659
4750
|
for (let i = 0; i < pens.length - 1; i++) {
|
|
4660
4751
|
const pen = pens[i];
|
|
4661
|
-
this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
|
|
4752
|
+
this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
|
|
4662
4753
|
}
|
|
4663
4754
|
this.render();
|
|
4664
4755
|
this.pushHistory({
|
|
@@ -4700,7 +4791,7 @@ export class Meta2d {
|
|
|
4700
4791
|
const attrs = JSON.parse(localStorage.getItem('meta2d-formatPainter'));
|
|
4701
4792
|
for (let i = 0; i < pens.length; i++) {
|
|
4702
4793
|
const pen = pens[i];
|
|
4703
|
-
this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
|
|
4794
|
+
this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
|
|
4704
4795
|
}
|
|
4705
4796
|
this.render();
|
|
4706
4797
|
this.pushHistory({
|
|
@@ -5321,6 +5412,8 @@ export class Meta2d {
|
|
|
5321
5412
|
pens.splice(index, 1);
|
|
5322
5413
|
}
|
|
5323
5414
|
}
|
|
5415
|
+
this.initTemplateCanvas([pen]);
|
|
5416
|
+
this.initImageCanvas([pen]);
|
|
5324
5417
|
}
|
|
5325
5418
|
changePenId(oldId, newId) {
|
|
5326
5419
|
this.canvas.changePenId(oldId, newId);
|