@meta2d/core 1.0.85 → 1.0.86
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 +3 -1
- package/src/canvas/canvas.js.map +1 -1
- package/src/core.d.ts +2 -0
- package/src/core.js +122 -36
- 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 +5 -0
- package/src/pen/model.js +12 -1
- package/src/pen/model.js.map +1 -1
- package/src/pen/render.js +3 -1
- package/src/pen/render.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;
|
|
@@ -950,6 +961,53 @@ 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
|
+
}
|
|
992
|
+
if (!width || !height) {
|
|
993
|
+
//2d 偏移量很大
|
|
994
|
+
let outpens = findOutliersByZScore(pens);
|
|
995
|
+
outpens.forEach((item) => {
|
|
996
|
+
let repeat = dirtyPens.filter((_item) => _item.id === item.id);
|
|
997
|
+
if (!repeat.length) {
|
|
998
|
+
dirtyPens.push(item);
|
|
999
|
+
}
|
|
1000
|
+
});
|
|
1001
|
+
}
|
|
1002
|
+
if (active) {
|
|
1003
|
+
this.active(dirtyPens);
|
|
1004
|
+
}
|
|
1005
|
+
return dirtyPens;
|
|
1006
|
+
}
|
|
1007
|
+
clearDirtyData() {
|
|
1008
|
+
let dirtyPens = this.dirtyData();
|
|
1009
|
+
this.delete(dirtyPens, true);
|
|
1010
|
+
}
|
|
953
1011
|
cacheData(id) {
|
|
954
1012
|
if (id && this.store.options.cacheLength) {
|
|
955
1013
|
let index = this.store.cacheDatas.findIndex((item) => item.data && item.data._id === id);
|
|
@@ -1850,27 +1908,33 @@ export class Meta2d {
|
|
|
1850
1908
|
calcRightBottom(rect);
|
|
1851
1909
|
calcCenter(rect);
|
|
1852
1910
|
child.calculative.worldRect = rect;
|
|
1853
|
-
if (rectInRect(rect, parent.calculative.worldRect, true)) {
|
|
1911
|
+
if (parent.container && rectInRect(rect, parent.calculative.worldRect, true)) { //取所有图元的范围
|
|
1854
1912
|
const childRect = calcRelativeRect(rect, parent.calculative.worldRect);
|
|
1855
1913
|
Object.assign(child, childRect);
|
|
1856
1914
|
}
|
|
1857
1915
|
else {
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1916
|
+
if (parent.container) { //容器模式取操作过程中最大范围
|
|
1917
|
+
let x = Math.min(rect.x, parent.calculative.worldRect.x);
|
|
1918
|
+
let y = Math.min(rect.y, parent.calculative.worldRect.y);
|
|
1919
|
+
let ex = Math.max(rect.ex, parent.calculative.worldRect.ex);
|
|
1920
|
+
let ey = Math.max(rect.ey, parent.calculative.worldRect.ey);
|
|
1921
|
+
parent.calculative.worldRect = {
|
|
1922
|
+
x: x,
|
|
1923
|
+
y: y,
|
|
1924
|
+
width: ex - x,
|
|
1925
|
+
height: ey - y,
|
|
1926
|
+
ex,
|
|
1927
|
+
ey,
|
|
1928
|
+
};
|
|
1929
|
+
calcCenter(parent.calculative.worldRect);
|
|
1930
|
+
}
|
|
1931
|
+
else { //取所有图元的范围
|
|
1932
|
+
const pens = parent.children.map((cid) => this.store.pens[cid]);
|
|
1933
|
+
parent.calculative.worldRect = getRect(pens);
|
|
1934
|
+
}
|
|
1870
1935
|
if (!parent.parentId) {
|
|
1871
1936
|
Object.assign(parent, parent.calculative.worldRect);
|
|
1872
1937
|
}
|
|
1873
|
-
calcCenter(parent.calculative.worldRect);
|
|
1874
1938
|
parent.children.forEach((cid) => {
|
|
1875
1939
|
const cPen = this.store.pens[cid];
|
|
1876
1940
|
const childRect = calcRelativeRect(cPen.calculative.worldRect, parent.calculative.worldRect);
|
|
@@ -2895,24 +2959,46 @@ export class Meta2d {
|
|
|
2895
2959
|
}
|
|
2896
2960
|
}
|
|
2897
2961
|
if (typeof req.headers === 'object') {
|
|
2898
|
-
for (let i in req.headers) {
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
}
|
|
2962
|
+
/*for (let i in req.headers) {
|
|
2963
|
+
if (typeof req.headers[i] === 'string') {
|
|
2964
|
+
let keys = req.headers[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2965
|
+
if (keys) {
|
|
2966
|
+
req.headers[i] = req.headers[i].replace(
|
|
2967
|
+
`\${${keys[0]}}`,
|
|
2968
|
+
this.getDynamicParam(keys[0])
|
|
2969
|
+
);
|
|
2970
|
+
}
|
|
2971
|
+
}
|
|
2972
|
+
}*/
|
|
2973
|
+
let headersStr = JSON.stringify(req.headers);
|
|
2974
|
+
let keys = headersStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2975
|
+
if (keys?.length) {
|
|
2976
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2977
|
+
headersStr = headersStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
|
|
2904
2978
|
}
|
|
2905
2979
|
}
|
|
2980
|
+
req.headers = JSON.parse(headersStr);
|
|
2906
2981
|
}
|
|
2907
2982
|
if (typeof req.body === 'object') {
|
|
2908
|
-
for (let i in req.body) {
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
}
|
|
2983
|
+
/*for (let i in req.body) {
|
|
2984
|
+
if (typeof req.body[i] === 'string') {
|
|
2985
|
+
let keys = req.body[i].match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2986
|
+
if (keys) {
|
|
2987
|
+
req.body[i] = req.body[i].replace(
|
|
2988
|
+
`\${${keys[0]}}`,
|
|
2989
|
+
this.getDynamicParam(keys[0])
|
|
2990
|
+
);
|
|
2991
|
+
}
|
|
2992
|
+
}
|
|
2993
|
+
}*/
|
|
2994
|
+
let bodyStr = JSON.stringify(req.body);
|
|
2995
|
+
let keys = bodyStr.match(/\$\{([^}]+)\}/g)?.map(m => m.slice(2, -1));
|
|
2996
|
+
if (keys?.length) {
|
|
2997
|
+
for (let i = 0; i < keys.length; i++) {
|
|
2998
|
+
bodyStr = bodyStr.replace(`\${${keys[i]}}`, this.getDynamicParam(keys[i]));
|
|
2914
2999
|
}
|
|
2915
3000
|
}
|
|
3001
|
+
req.body = JSON.parse(bodyStr);
|
|
2916
3002
|
}
|
|
2917
3003
|
// 默认每一秒请求一次
|
|
2918
3004
|
const res = await fetch(req.url, {
|
|
@@ -4635,7 +4721,7 @@ export class Meta2d {
|
|
|
4635
4721
|
});
|
|
4636
4722
|
for (let i = 1; i < pens.length; i++) {
|
|
4637
4723
|
const pen = pens[i];
|
|
4638
|
-
this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
|
|
4724
|
+
this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
|
|
4639
4725
|
}
|
|
4640
4726
|
this.render();
|
|
4641
4727
|
this.pushHistory({
|
|
@@ -4658,7 +4744,7 @@ export class Meta2d {
|
|
|
4658
4744
|
});
|
|
4659
4745
|
for (let i = 0; i < pens.length - 1; i++) {
|
|
4660
4746
|
const pen = pens[i];
|
|
4661
|
-
this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
|
|
4747
|
+
this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
|
|
4662
4748
|
}
|
|
4663
4749
|
this.render();
|
|
4664
4750
|
this.pushHistory({
|
|
@@ -4700,7 +4786,7 @@ export class Meta2d {
|
|
|
4700
4786
|
const attrs = JSON.parse(localStorage.getItem('meta2d-formatPainter'));
|
|
4701
4787
|
for (let i = 0; i < pens.length; i++) {
|
|
4702
4788
|
const pen = pens[i];
|
|
4703
|
-
this.setValue({ id: pen.id, ...attrs }, { render: false, doEvent: false });
|
|
4789
|
+
this.setValue({ id: pen.id, ...defaultFormat, ...attrs }, { render: false, doEvent: false });
|
|
4704
4790
|
}
|
|
4705
4791
|
this.render();
|
|
4706
4792
|
this.pushHistory({
|