@idraw/util 0.4.2 → 1.0.0-alpha.1
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/dist/esm/converter/data-svg.d.ts +2 -0
- package/dist/esm/converter/data-svg.js +19 -0
- package/dist/esm/converter/material-svg.d.ts +2 -0
- package/dist/esm/converter/material-svg.js +63 -0
- package/dist/esm/converter/svg-material.d.ts +2 -0
- package/dist/esm/converter/svg-material.js +188 -0
- package/dist/esm/index.d.ts +32 -21
- package/dist/esm/index.js +32 -21
- package/dist/esm/static.d.ts +1 -0
- package/dist/esm/static.js +1 -0
- package/dist/esm/tool/file.js +2 -2
- package/dist/esm/tool/html.js +27 -27
- package/dist/esm/tool/id.d.ts +1 -0
- package/dist/esm/tool/id.js +4 -0
- package/dist/esm/tool/image.js +6 -6
- package/dist/esm/tool/path-to-box.d.ts +3 -0
- package/dist/esm/tool/path-to-box.js +353 -0
- package/dist/esm/tool/path-to-command.d.ts +4 -0
- package/dist/esm/tool/path-to-command.js +392 -0
- package/dist/esm/tool/path.d.ts +18 -0
- package/dist/esm/tool/path.js +421 -0
- package/dist/esm/tool/svg-path.d.ts +3 -0
- package/dist/esm/{view → tool}/svg-path.js +4 -16
- package/dist/esm/tool/time.d.ts +2 -2
- package/dist/esm/tool/time.js +4 -4
- package/dist/esm/tool/uuid.d.ts +1 -1
- package/dist/esm/tool/uuid.js +6 -6
- package/dist/esm/view/box.d.ts +0 -2
- package/dist/esm/view/box.js +1 -173
- package/dist/esm/view/canvas.js +3 -3
- package/dist/esm/view/check.d.ts +8 -7
- package/dist/esm/view/check.js +34 -34
- package/dist/esm/view/config.d.ts +0 -9
- package/dist/esm/view/config.js +1 -71
- package/dist/esm/view/context2d.d.ts +10 -3
- package/dist/esm/view/context2d.js +39 -18
- package/dist/esm/view/controller.d.ts +5 -5
- package/dist/esm/view/controller.js +105 -102
- package/dist/esm/view/data.d.ts +2 -2
- package/dist/esm/view/data.js +65 -65
- package/dist/esm/view/dom.d.ts +23 -0
- package/dist/esm/view/dom.js +190 -0
- package/dist/esm/view/flat.d.ts +2 -2
- package/dist/esm/view/flat.js +53 -53
- package/dist/esm/view/group.d.ts +3 -3
- package/dist/esm/view/group.js +25 -28
- package/dist/esm/view/handle-material.d.ts +24 -0
- package/dist/esm/view/{handle-element.js → handle-material.js} +98 -75
- package/dist/esm/view/is.d.ts +10 -12
- package/dist/esm/view/is.js +15 -19
- package/dist/esm/view/load.d.ts +2 -2
- package/dist/esm/view/load.js +7 -7
- package/dist/esm/view/material.d.ts +40 -0
- package/dist/esm/view/material.js +476 -0
- package/dist/esm/view/middleware.d.ts +1 -0
- package/dist/esm/view/middleware.js +14 -2
- package/dist/esm/view/modify-record.d.ts +4 -4
- package/dist/esm/view/modify-record.js +2 -2
- package/dist/esm/view/parser.d.ts +2 -2
- package/dist/esm/view/parser.js +3 -3
- package/dist/esm/view/path.d.ts +2 -0
- package/dist/esm/view/path.js +30 -0
- package/dist/esm/view/point-move-material.d.ts +5 -0
- package/dist/esm/view/{point-move-element.js → point-move-material.js} +6 -6
- package/dist/esm/view/point.d.ts +3 -8
- package/dist/esm/view/point.js +1 -21
- package/dist/esm/view/position.d.ts +9 -9
- package/dist/esm/view/position.js +1 -1
- package/dist/esm/view/rect.d.ts +2 -2
- package/dist/esm/view/rect.js +4 -4
- package/dist/esm/view/resize-material.d.ts +4 -0
- package/dist/esm/view/resize-material.js +266 -0
- package/dist/esm/view/rotate.d.ts +11 -11
- package/dist/esm/view/rotate.js +24 -24
- package/dist/esm/view/static.d.ts +13 -0
- package/dist/esm/view/static.js +89 -0
- package/dist/esm/view/styles.d.ts +11 -0
- package/dist/esm/view/styles.js +78 -0
- package/dist/esm/view/vertex.d.ts +8 -8
- package/dist/esm/view/vertex.js +28 -28
- package/dist/esm/view/view-box.d.ts +2 -6
- package/dist/esm/view/view-box.js +8 -64
- package/dist/esm/view/view-calc.d.ts +23 -20
- package/dist/esm/view/view-calc.js +104 -93
- package/dist/esm/view/view-content.d.ts +2 -2
- package/dist/esm/view/view-content.js +34 -34
- package/dist/index.global.js +3144 -1548
- package/dist/index.global.min.js +1 -1
- package/package.json +1 -1
- package/dist/esm/view/element.d.ts +0 -35
- package/dist/esm/view/element.js +0 -471
- package/dist/esm/view/handle-element.d.ts +0 -24
- package/dist/esm/view/point-move-element.d.ts +0 -5
- package/dist/esm/view/resize-element.d.ts +0 -4
- package/dist/esm/view/resize-element.js +0 -255
- package/dist/esm/view/svg-path.d.ts +0 -10
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
import { createUUID } from '../tool/uuid';
|
|
2
2
|
import { getCenterFromTwoPoints } from './point';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
function
|
|
3
|
+
import { calcMaterialVertexesInGroup, calcMaterialVertexes } from './vertex';
|
|
4
|
+
import { calcViewMaterialSize } from './view-calc';
|
|
5
|
+
import { calcMaterialCenter } from './rotate';
|
|
6
|
+
function createControllerMaterialSizeFromCenter(center, opts) {
|
|
7
7
|
const { x, y } = center;
|
|
8
8
|
const { size, angle } = opts;
|
|
9
9
|
return {
|
|
10
10
|
x: x - size / 2,
|
|
11
11
|
y: y - size / 2,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
angle
|
|
12
|
+
width: size,
|
|
13
|
+
height: size,
|
|
14
|
+
angle,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
export function
|
|
17
|
+
export function calcMaterialSizeController(mtrlSize, opts) {
|
|
18
18
|
const { groupQueue, controllerSize, viewScaleInfo, rotateControllerSize, rotateControllerPosition } = opts;
|
|
19
19
|
const ctrlSize = (controllerSize && controllerSize > 0 ? controllerSize : 8) / viewScaleInfo.scale;
|
|
20
|
-
const { x, y,
|
|
20
|
+
const { x, y, width, height, angle = 0 } = mtrlSize;
|
|
21
21
|
const rotateCtrlSize = rotateControllerSize;
|
|
22
22
|
const rotateCtrlPos = rotateControllerPosition;
|
|
23
23
|
const ctrlGroupQueue = [
|
|
24
24
|
...[
|
|
25
25
|
{
|
|
26
|
-
|
|
26
|
+
id: createUUID(),
|
|
27
27
|
x,
|
|
28
28
|
y,
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
width,
|
|
30
|
+
height,
|
|
31
31
|
angle,
|
|
32
32
|
type: 'group',
|
|
33
|
-
|
|
34
|
-
}
|
|
33
|
+
children: [],
|
|
34
|
+
},
|
|
35
35
|
],
|
|
36
|
-
...groupQueue
|
|
36
|
+
...groupQueue,
|
|
37
37
|
];
|
|
38
38
|
let totalAngle = 0;
|
|
39
39
|
ctrlGroupQueue.forEach(({ angle = 0 }) => {
|
|
40
40
|
totalAngle += angle;
|
|
41
41
|
});
|
|
42
|
-
const vertexes =
|
|
43
|
-
const
|
|
42
|
+
const vertexes = calcMaterialVertexesInGroup(mtrlSize, { groupQueue });
|
|
43
|
+
const rotateMaterialVertexes = calcMaterialVertexesInGroup({
|
|
44
44
|
x: x,
|
|
45
45
|
y: y - (rotateCtrlPos + rotateCtrlSize / 2) / viewScaleInfo.scale,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
angle
|
|
46
|
+
height: height + (rotateCtrlPos * 2 + rotateCtrlSize) / viewScaleInfo.scale,
|
|
47
|
+
width,
|
|
48
|
+
angle,
|
|
49
49
|
}, { groupQueue: [...groupQueue] });
|
|
50
50
|
const topCenter = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
|
51
51
|
const rightCenter = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
|
@@ -55,267 +55,270 @@ export function calcElementSizeController(elemSize, opts) {
|
|
|
55
55
|
const topRightCenter = vertexes[1];
|
|
56
56
|
const bottomRightCenter = vertexes[2];
|
|
57
57
|
const bottomLeftCenter = vertexes[3];
|
|
58
|
-
const topMiddleSize =
|
|
59
|
-
const rightMiddleSize =
|
|
60
|
-
const bottomMiddleSize =
|
|
61
|
-
const leftMiddleSize =
|
|
62
|
-
const topLeftSize =
|
|
63
|
-
const topRightSize =
|
|
64
|
-
const bottomLeftSize =
|
|
65
|
-
const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, {
|
|
58
|
+
const topMiddleSize = createControllerMaterialSizeFromCenter(topCenter, { size: ctrlSize, angle: totalAngle });
|
|
59
|
+
const rightMiddleSize = createControllerMaterialSizeFromCenter(rightCenter, { size: ctrlSize, angle: totalAngle });
|
|
60
|
+
const bottomMiddleSize = createControllerMaterialSizeFromCenter(bottomCenter, { size: ctrlSize, angle: totalAngle });
|
|
61
|
+
const leftMiddleSize = createControllerMaterialSizeFromCenter(leftCenter, { size: ctrlSize, angle: totalAngle });
|
|
62
|
+
const topLeftSize = createControllerMaterialSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
63
|
+
const topRightSize = createControllerMaterialSizeFromCenter(topRightCenter, { size: ctrlSize, angle: totalAngle });
|
|
64
|
+
const bottomLeftSize = createControllerMaterialSizeFromCenter(bottomLeftCenter, {
|
|
66
65
|
size: ctrlSize,
|
|
67
|
-
angle: totalAngle
|
|
66
|
+
angle: totalAngle,
|
|
68
67
|
});
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
const bottomRightSize = createControllerMaterialSizeFromCenter(bottomRightCenter, {
|
|
69
|
+
size: ctrlSize,
|
|
70
|
+
angle: totalAngle,
|
|
71
|
+
});
|
|
72
|
+
const topLeftVertexes = calcMaterialVertexes(topLeftSize);
|
|
73
|
+
const topRightVertexes = calcMaterialVertexes(topRightSize);
|
|
74
|
+
const bottomLeftVertexes = calcMaterialVertexes(bottomLeftSize);
|
|
75
|
+
const bottomRightVertexes = calcMaterialVertexes(bottomRightSize);
|
|
73
76
|
const topVertexes = [
|
|
74
77
|
topLeftVertexes[1],
|
|
75
78
|
topRightVertexes[0],
|
|
76
79
|
topRightVertexes[3],
|
|
77
|
-
topLeftVertexes[2]
|
|
80
|
+
topLeftVertexes[2],
|
|
78
81
|
];
|
|
79
82
|
const rightVertexes = [
|
|
80
83
|
topRightVertexes[3],
|
|
81
84
|
topRightVertexes[2],
|
|
82
85
|
bottomRightVertexes[1],
|
|
83
|
-
bottomRightVertexes[0]
|
|
86
|
+
bottomRightVertexes[0],
|
|
84
87
|
];
|
|
85
88
|
const bottomVertexes = [
|
|
86
89
|
bottomLeftVertexes[1],
|
|
87
90
|
bottomRightVertexes[0],
|
|
88
91
|
bottomRightVertexes[3],
|
|
89
|
-
bottomLeftVertexes[2]
|
|
92
|
+
bottomLeftVertexes[2],
|
|
90
93
|
];
|
|
91
94
|
const leftVertexes = [
|
|
92
95
|
topLeftVertexes[3],
|
|
93
96
|
topLeftVertexes[2],
|
|
94
97
|
bottomLeftVertexes[1],
|
|
95
|
-
bottomLeftVertexes[0]
|
|
98
|
+
bottomLeftVertexes[0],
|
|
96
99
|
];
|
|
97
|
-
const topMiddleVertexes =
|
|
98
|
-
const rightMiddleVertexes =
|
|
99
|
-
const bottomMiddleVertexes =
|
|
100
|
-
const leftMiddleVertexes =
|
|
101
|
-
const rotateCenter = getCenterFromTwoPoints(
|
|
100
|
+
const topMiddleVertexes = calcMaterialVertexes(topMiddleSize);
|
|
101
|
+
const rightMiddleVertexes = calcMaterialVertexes(rightMiddleSize);
|
|
102
|
+
const bottomMiddleVertexes = calcMaterialVertexes(bottomMiddleSize);
|
|
103
|
+
const leftMiddleVertexes = calcMaterialVertexes(leftMiddleSize);
|
|
104
|
+
const rotateCenter = getCenterFromTwoPoints(rotateMaterialVertexes[0], rotateMaterialVertexes[1]);
|
|
102
105
|
const tempRotateSizeRepairRatio = 1.1;
|
|
103
|
-
const rotateSize =
|
|
106
|
+
const rotateSize = createControllerMaterialSizeFromCenter(rotateCenter, {
|
|
104
107
|
size: (rotateControllerSize * tempRotateSizeRepairRatio) / viewScaleInfo.scale,
|
|
105
|
-
angle: totalAngle
|
|
108
|
+
angle: totalAngle,
|
|
106
109
|
});
|
|
107
|
-
const rotateVertexes =
|
|
110
|
+
const rotateVertexes = calcMaterialVertexes(rotateSize);
|
|
108
111
|
const sizeController = {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
originalMaterialCenter: calcMaterialCenter(mtrlSize),
|
|
113
|
+
originalMaterialSize: Object.assign({}, mtrlSize),
|
|
114
|
+
materialWrapper: vertexes,
|
|
112
115
|
left: {
|
|
113
116
|
type: 'left',
|
|
114
117
|
vertexes: leftVertexes,
|
|
115
118
|
center: leftCenter,
|
|
116
|
-
size: ctrlSize
|
|
119
|
+
size: ctrlSize,
|
|
117
120
|
},
|
|
118
121
|
right: {
|
|
119
122
|
type: 'right',
|
|
120
123
|
vertexes: rightVertexes,
|
|
121
124
|
center: rightCenter,
|
|
122
|
-
size: ctrlSize
|
|
125
|
+
size: ctrlSize,
|
|
123
126
|
},
|
|
124
127
|
top: {
|
|
125
128
|
type: 'top',
|
|
126
129
|
vertexes: topVertexes,
|
|
127
130
|
center: topCenter,
|
|
128
|
-
size: ctrlSize
|
|
131
|
+
size: ctrlSize,
|
|
129
132
|
},
|
|
130
133
|
bottom: {
|
|
131
134
|
type: 'bottom',
|
|
132
135
|
vertexes: bottomVertexes,
|
|
133
136
|
center: bottomCenter,
|
|
134
|
-
size: ctrlSize
|
|
137
|
+
size: ctrlSize,
|
|
135
138
|
},
|
|
136
139
|
topLeft: {
|
|
137
140
|
type: 'top-left',
|
|
138
141
|
vertexes: topLeftVertexes,
|
|
139
142
|
center: topLeftCenter,
|
|
140
|
-
size: ctrlSize
|
|
143
|
+
size: ctrlSize,
|
|
141
144
|
},
|
|
142
145
|
topRight: {
|
|
143
146
|
type: 'top-right',
|
|
144
147
|
vertexes: topRightVertexes,
|
|
145
148
|
center: topRightCenter,
|
|
146
|
-
size: ctrlSize
|
|
149
|
+
size: ctrlSize,
|
|
147
150
|
},
|
|
148
151
|
bottomLeft: {
|
|
149
152
|
type: 'bottom-left',
|
|
150
153
|
vertexes: bottomLeftVertexes,
|
|
151
154
|
center: bottomLeftCenter,
|
|
152
|
-
size: ctrlSize
|
|
155
|
+
size: ctrlSize,
|
|
153
156
|
},
|
|
154
157
|
bottomRight: {
|
|
155
158
|
type: 'bottom-right',
|
|
156
159
|
vertexes: bottomRightVertexes,
|
|
157
160
|
center: bottomRightCenter,
|
|
158
|
-
size: ctrlSize
|
|
161
|
+
size: ctrlSize,
|
|
159
162
|
},
|
|
160
163
|
leftMiddle: {
|
|
161
164
|
type: 'left-middle',
|
|
162
165
|
vertexes: leftMiddleVertexes,
|
|
163
166
|
center: leftCenter,
|
|
164
|
-
size: ctrlSize
|
|
167
|
+
size: ctrlSize,
|
|
165
168
|
},
|
|
166
169
|
rightMiddle: {
|
|
167
170
|
type: 'right-middle',
|
|
168
171
|
vertexes: rightMiddleVertexes,
|
|
169
172
|
center: rightCenter,
|
|
170
|
-
size: ctrlSize
|
|
173
|
+
size: ctrlSize,
|
|
171
174
|
},
|
|
172
175
|
topMiddle: {
|
|
173
176
|
type: 'top-middle',
|
|
174
177
|
vertexes: topMiddleVertexes,
|
|
175
178
|
center: topCenter,
|
|
176
|
-
size: ctrlSize
|
|
179
|
+
size: ctrlSize,
|
|
177
180
|
},
|
|
178
181
|
bottomMiddle: {
|
|
179
182
|
type: 'bottom-middle',
|
|
180
183
|
vertexes: bottomMiddleVertexes,
|
|
181
184
|
center: bottomCenter,
|
|
182
|
-
size: ctrlSize
|
|
185
|
+
size: ctrlSize,
|
|
183
186
|
},
|
|
184
187
|
rotate: {
|
|
185
188
|
type: 'rotate',
|
|
186
189
|
vertexes: rotateVertexes,
|
|
187
190
|
center: rotateCenter,
|
|
188
|
-
size: rotateControllerSize
|
|
189
|
-
}
|
|
191
|
+
size: rotateControllerSize,
|
|
192
|
+
},
|
|
190
193
|
};
|
|
191
194
|
return sizeController;
|
|
192
195
|
}
|
|
193
196
|
export function calcLayoutSizeController(layoutSize, opts) {
|
|
194
197
|
const { controllerSize, viewScaleInfo } = opts;
|
|
195
198
|
const ctrlSize = controllerSize && controllerSize > 0 ? controllerSize : 8;
|
|
196
|
-
const { x, y,
|
|
197
|
-
const center =
|
|
199
|
+
const { x, y, width, height } = calcViewMaterialSize(layoutSize, { viewScaleInfo });
|
|
200
|
+
const center = calcMaterialCenter({ x, y, width, height });
|
|
198
201
|
const topCenter = { x: center.x, y };
|
|
199
|
-
const rightCenter = { x: x +
|
|
200
|
-
const bottomCenter = { x: center.x, y: y +
|
|
202
|
+
const rightCenter = { x: x + width, y: center.y };
|
|
203
|
+
const bottomCenter = { x: center.x, y: y + height };
|
|
201
204
|
const leftCenter = { x, y: center.y };
|
|
202
205
|
const topLeftCenter = { x, y };
|
|
203
|
-
const topRightCenter = { x: x +
|
|
204
|
-
const bottomRightCenter = { x: x +
|
|
205
|
-
const bottomLeftCenter = { x, y: y +
|
|
206
|
-
const topMiddleSize =
|
|
207
|
-
const rightMiddleSize =
|
|
208
|
-
const bottomMiddleSize =
|
|
209
|
-
const leftMiddleSize =
|
|
210
|
-
const topLeftSize =
|
|
211
|
-
const topRightSize =
|
|
212
|
-
const bottomLeftSize =
|
|
213
|
-
const bottomRightSize =
|
|
214
|
-
const topLeftVertexes =
|
|
215
|
-
const topRightVertexes =
|
|
216
|
-
const bottomLeftVertexes =
|
|
217
|
-
const bottomRightVertexes =
|
|
206
|
+
const topRightCenter = { x: x + width, y };
|
|
207
|
+
const bottomRightCenter = { x: x + width, y: y + height };
|
|
208
|
+
const bottomLeftCenter = { x, y: y + height };
|
|
209
|
+
const topMiddleSize = createControllerMaterialSizeFromCenter(topCenter, { size: ctrlSize, angle: 0 });
|
|
210
|
+
const rightMiddleSize = createControllerMaterialSizeFromCenter(rightCenter, { size: ctrlSize, angle: 0 });
|
|
211
|
+
const bottomMiddleSize = createControllerMaterialSizeFromCenter(bottomCenter, { size: ctrlSize, angle: 0 });
|
|
212
|
+
const leftMiddleSize = createControllerMaterialSizeFromCenter(leftCenter, { size: ctrlSize, angle: 0 });
|
|
213
|
+
const topLeftSize = createControllerMaterialSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: 0 });
|
|
214
|
+
const topRightSize = createControllerMaterialSizeFromCenter(topRightCenter, { size: ctrlSize, angle: 0 });
|
|
215
|
+
const bottomLeftSize = createControllerMaterialSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: 0 });
|
|
216
|
+
const bottomRightSize = createControllerMaterialSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: 0 });
|
|
217
|
+
const topLeftVertexes = calcMaterialVertexes(topLeftSize);
|
|
218
|
+
const topRightVertexes = calcMaterialVertexes(topRightSize);
|
|
219
|
+
const bottomLeftVertexes = calcMaterialVertexes(bottomLeftSize);
|
|
220
|
+
const bottomRightVertexes = calcMaterialVertexes(bottomRightSize);
|
|
218
221
|
const topVertexes = [
|
|
219
222
|
topLeftVertexes[1],
|
|
220
223
|
topRightVertexes[0],
|
|
221
224
|
topRightVertexes[3],
|
|
222
|
-
topLeftVertexes[2]
|
|
225
|
+
topLeftVertexes[2],
|
|
223
226
|
];
|
|
224
227
|
const rightVertexes = [
|
|
225
228
|
topRightVertexes[3],
|
|
226
229
|
topRightVertexes[2],
|
|
227
230
|
bottomRightVertexes[1],
|
|
228
|
-
bottomRightVertexes[0]
|
|
231
|
+
bottomRightVertexes[0],
|
|
229
232
|
];
|
|
230
233
|
const bottomVertexes = [
|
|
231
234
|
bottomLeftVertexes[1],
|
|
232
235
|
bottomRightVertexes[0],
|
|
233
236
|
bottomRightVertexes[3],
|
|
234
|
-
bottomLeftVertexes[2]
|
|
237
|
+
bottomLeftVertexes[2],
|
|
235
238
|
];
|
|
236
239
|
const leftVertexes = [
|
|
237
240
|
topLeftVertexes[3],
|
|
238
241
|
topLeftVertexes[2],
|
|
239
242
|
bottomLeftVertexes[1],
|
|
240
|
-
bottomLeftVertexes[0]
|
|
243
|
+
bottomLeftVertexes[0],
|
|
241
244
|
];
|
|
242
|
-
const topMiddleVertexes =
|
|
243
|
-
const rightMiddleVertexes =
|
|
244
|
-
const bottomMiddleVertexes =
|
|
245
|
-
const leftMiddleVertexes =
|
|
245
|
+
const topMiddleVertexes = calcMaterialVertexes(topMiddleSize);
|
|
246
|
+
const rightMiddleVertexes = calcMaterialVertexes(rightMiddleSize);
|
|
247
|
+
const bottomMiddleVertexes = calcMaterialVertexes(bottomMiddleSize);
|
|
248
|
+
const leftMiddleVertexes = calcMaterialVertexes(leftMiddleSize);
|
|
246
249
|
const sizeController = {
|
|
247
250
|
left: {
|
|
248
251
|
type: 'left',
|
|
249
252
|
vertexes: leftVertexes,
|
|
250
253
|
center: leftCenter,
|
|
251
|
-
size: ctrlSize
|
|
254
|
+
size: ctrlSize,
|
|
252
255
|
},
|
|
253
256
|
right: {
|
|
254
257
|
type: 'right',
|
|
255
258
|
vertexes: rightVertexes,
|
|
256
259
|
center: rightCenter,
|
|
257
|
-
size: ctrlSize
|
|
260
|
+
size: ctrlSize,
|
|
258
261
|
},
|
|
259
262
|
top: {
|
|
260
263
|
type: 'top',
|
|
261
264
|
vertexes: topVertexes,
|
|
262
265
|
center: topCenter,
|
|
263
|
-
size: ctrlSize
|
|
266
|
+
size: ctrlSize,
|
|
264
267
|
},
|
|
265
268
|
bottom: {
|
|
266
269
|
type: 'bottom',
|
|
267
270
|
vertexes: bottomVertexes,
|
|
268
271
|
center: bottomCenter,
|
|
269
|
-
size: ctrlSize
|
|
272
|
+
size: ctrlSize,
|
|
270
273
|
},
|
|
271
274
|
topLeft: {
|
|
272
275
|
type: 'top-left',
|
|
273
276
|
vertexes: topLeftVertexes,
|
|
274
277
|
center: topLeftCenter,
|
|
275
|
-
size: ctrlSize
|
|
278
|
+
size: ctrlSize,
|
|
276
279
|
},
|
|
277
280
|
topRight: {
|
|
278
281
|
type: 'top-right',
|
|
279
282
|
vertexes: topRightVertexes,
|
|
280
283
|
center: topRightCenter,
|
|
281
|
-
size: ctrlSize
|
|
284
|
+
size: ctrlSize,
|
|
282
285
|
},
|
|
283
286
|
bottomLeft: {
|
|
284
287
|
type: 'bottom-left',
|
|
285
288
|
vertexes: bottomLeftVertexes,
|
|
286
289
|
center: bottomLeftCenter,
|
|
287
|
-
size: ctrlSize
|
|
290
|
+
size: ctrlSize,
|
|
288
291
|
},
|
|
289
292
|
bottomRight: {
|
|
290
293
|
type: 'bottom-right',
|
|
291
294
|
vertexes: bottomRightVertexes,
|
|
292
295
|
center: bottomRightCenter,
|
|
293
|
-
size: ctrlSize
|
|
296
|
+
size: ctrlSize,
|
|
294
297
|
},
|
|
295
298
|
leftMiddle: {
|
|
296
299
|
type: 'left-middle',
|
|
297
300
|
vertexes: leftMiddleVertexes,
|
|
298
301
|
center: leftCenter,
|
|
299
|
-
size: ctrlSize
|
|
302
|
+
size: ctrlSize,
|
|
300
303
|
},
|
|
301
304
|
rightMiddle: {
|
|
302
305
|
type: 'right-middle',
|
|
303
306
|
vertexes: rightMiddleVertexes,
|
|
304
307
|
center: rightCenter,
|
|
305
|
-
size: ctrlSize
|
|
308
|
+
size: ctrlSize,
|
|
306
309
|
},
|
|
307
310
|
topMiddle: {
|
|
308
311
|
type: 'top-middle',
|
|
309
312
|
vertexes: topMiddleVertexes,
|
|
310
313
|
center: topCenter,
|
|
311
|
-
size: ctrlSize
|
|
314
|
+
size: ctrlSize,
|
|
312
315
|
},
|
|
313
316
|
bottomMiddle: {
|
|
314
317
|
type: 'bottom-middle',
|
|
315
318
|
vertexes: bottomMiddleVertexes,
|
|
316
319
|
center: bottomCenter,
|
|
317
|
-
size: ctrlSize
|
|
318
|
-
}
|
|
320
|
+
size: ctrlSize,
|
|
321
|
+
},
|
|
319
322
|
};
|
|
320
323
|
return sizeController;
|
|
321
324
|
}
|
package/dist/esm/view/data.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Data,
|
|
1
|
+
import type { Data, StrictMaterial, LoadItemMap } from '@idraw/types';
|
|
2
2
|
export declare function deepClone<T = any>(target: T): T;
|
|
3
|
-
export declare function
|
|
3
|
+
export declare function deepCloneMaterial<T extends StrictMaterial = StrictMaterial>(material: T): T;
|
|
4
4
|
export declare function deepCloneData(data: Data): Data;
|
|
5
5
|
export declare function sortDataAsserts(data: Data, opts?: {
|
|
6
6
|
clone?: boolean;
|
package/dist/esm/view/data.js
CHANGED
|
@@ -38,23 +38,23 @@ export function deepClone(target) {
|
|
|
38
38
|
}
|
|
39
39
|
return _clone(target);
|
|
40
40
|
}
|
|
41
|
-
export function
|
|
42
|
-
const
|
|
41
|
+
export function deepCloneMaterial(material) {
|
|
42
|
+
const mtrl = deepClone(material);
|
|
43
43
|
const _resetUUID = (e) => {
|
|
44
|
-
e.
|
|
45
|
-
if (e.type === 'group' && e.
|
|
46
|
-
e.
|
|
44
|
+
e.id = createUUID();
|
|
45
|
+
if (e.type === 'group' && e.children) {
|
|
46
|
+
e.children.forEach((child) => {
|
|
47
47
|
_resetUUID(child);
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
_resetUUID(
|
|
52
|
-
return
|
|
51
|
+
_resetUUID(mtrl);
|
|
52
|
+
return mtrl;
|
|
53
53
|
}
|
|
54
54
|
export function deepCloneData(data) {
|
|
55
|
-
const {
|
|
55
|
+
const { materials } = data, restData = __rest(data, ["materials"]);
|
|
56
56
|
return Object.assign(Object.assign({}, deepClone(restData)), {
|
|
57
|
-
|
|
57
|
+
materials: materials.map((mtrl) => deepCloneMaterial(mtrl)),
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
function is(target) {
|
|
@@ -69,54 +69,54 @@ export function sortDataAsserts(data, opts) {
|
|
|
69
69
|
if ((opts === null || opts === void 0 ? void 0 : opts.clone) === true) {
|
|
70
70
|
sortedData = deepClone(data);
|
|
71
71
|
}
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
const
|
|
76
|
-
const assetUUID = createAssetId(
|
|
72
|
+
const _scanMaterials = (mtrls) => {
|
|
73
|
+
mtrls.forEach((mtrl) => {
|
|
74
|
+
if (mtrl.type === 'image' && mtrl.href) {
|
|
75
|
+
const href = mtrl.href;
|
|
76
|
+
const assetUUID = createAssetId(href, mtrl.id);
|
|
77
77
|
if (!assets[assetUUID]) {
|
|
78
78
|
assets[assetUUID] = {
|
|
79
79
|
type: 'image',
|
|
80
|
-
value:
|
|
80
|
+
value: href,
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
-
|
|
83
|
+
mtrl.href = assetUUID;
|
|
84
84
|
}
|
|
85
|
-
else if (
|
|
86
|
-
const svg =
|
|
87
|
-
const assetUUID = createAssetId(svg,
|
|
85
|
+
else if (mtrl.type === 'svgCode') {
|
|
86
|
+
const svg = mtrl.code;
|
|
87
|
+
const assetUUID = createAssetId(svg, mtrl.id);
|
|
88
88
|
if (!assets[assetUUID]) {
|
|
89
89
|
assets[assetUUID] = {
|
|
90
|
-
type: '
|
|
91
|
-
value: svg
|
|
90
|
+
type: 'svgCode',
|
|
91
|
+
value: svg,
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
mtrl.code = assetUUID;
|
|
95
95
|
}
|
|
96
|
-
else if (
|
|
97
|
-
const html =
|
|
98
|
-
const assetUUID = createAssetId(html,
|
|
96
|
+
else if (mtrl.type === 'foreignObject') {
|
|
97
|
+
const html = mtrl.content;
|
|
98
|
+
const assetUUID = createAssetId(html, mtrl.id);
|
|
99
99
|
if (!assets[assetUUID]) {
|
|
100
100
|
assets[assetUUID] = {
|
|
101
|
-
type: '
|
|
102
|
-
value: html
|
|
101
|
+
type: 'foreignObject',
|
|
102
|
+
value: html,
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
|
|
105
|
+
mtrl.content = assetUUID;
|
|
106
106
|
}
|
|
107
|
-
else if (
|
|
108
|
-
const groupAssets =
|
|
107
|
+
else if (mtrl.type === 'group' && Array.isArray(mtrl.children)) {
|
|
108
|
+
const groupAssets = mtrl.assets || {};
|
|
109
109
|
Object.keys(groupAssets).forEach((assetId) => {
|
|
110
110
|
if (!assets[assetId]) {
|
|
111
111
|
assets[assetId] = groupAssets[assetId];
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
|
-
delete
|
|
115
|
-
|
|
114
|
+
delete mtrl.assets;
|
|
115
|
+
_scanMaterials(mtrl.children);
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
};
|
|
119
|
-
|
|
119
|
+
_scanMaterials(sortedData.materials);
|
|
120
120
|
sortedData.assets = assets;
|
|
121
121
|
return sortedData;
|
|
122
122
|
}
|
|
@@ -124,79 +124,79 @@ export function filterCompactData(data, opts) {
|
|
|
124
124
|
const assets = data.assets || {};
|
|
125
125
|
const sortedData = deepClone(data);
|
|
126
126
|
const loadItemMap = (opts === null || opts === void 0 ? void 0 : opts.loadItemMap) || {};
|
|
127
|
-
const
|
|
128
|
-
|
|
127
|
+
const _scanMaterials = (mtrls) => {
|
|
128
|
+
mtrls.forEach((mtrl) => {
|
|
129
129
|
var _a, _b, _c;
|
|
130
|
-
if (
|
|
131
|
-
const
|
|
132
|
-
if (isAssetId(
|
|
133
|
-
assets[
|
|
130
|
+
if (mtrl.type === 'image' && mtrl.href) {
|
|
131
|
+
const href = mtrl.href;
|
|
132
|
+
if (isAssetId(href) && !assets[href] && loadItemMap[href] && typeof ((_a = loadItemMap[href]) === null || _a === void 0 ? void 0 : _a.source) === 'string') {
|
|
133
|
+
assets[href] = {
|
|
134
134
|
type: 'image',
|
|
135
|
-
value: loadItemMap[
|
|
135
|
+
value: loadItemMap[href].source,
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
|
-
else if (!assets[
|
|
139
|
-
const assetUUID = createAssetId(
|
|
138
|
+
else if (!assets[href]) {
|
|
139
|
+
const assetUUID = createAssetId(href, mtrl.id);
|
|
140
140
|
if (!assets[assetUUID]) {
|
|
141
141
|
assets[assetUUID] = {
|
|
142
142
|
type: 'image',
|
|
143
|
-
value:
|
|
143
|
+
value: href,
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
-
|
|
146
|
+
mtrl.href = assetUUID;
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
else if (
|
|
150
|
-
const svg =
|
|
149
|
+
else if (mtrl.type === 'svgCode') {
|
|
150
|
+
const svg = mtrl.code;
|
|
151
151
|
if (isAssetId(svg) && !assets[svg] && loadItemMap[svg] && typeof ((_b = loadItemMap[svg]) === null || _b === void 0 ? void 0 : _b.source) === 'string') {
|
|
152
152
|
assets[svg] = {
|
|
153
|
-
type: '
|
|
154
|
-
value: loadItemMap[svg].source
|
|
153
|
+
type: 'svgCode',
|
|
154
|
+
value: loadItemMap[svg].source,
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
else if (!assets[svg]) {
|
|
158
|
-
const assetUUID = createAssetId(svg,
|
|
158
|
+
const assetUUID = createAssetId(svg, mtrl.id);
|
|
159
159
|
if (!assets[assetUUID]) {
|
|
160
160
|
assets[assetUUID] = {
|
|
161
|
-
type: '
|
|
162
|
-
value: svg
|
|
161
|
+
type: 'svgCode',
|
|
162
|
+
value: svg,
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
mtrl.code = assetUUID;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
|
-
else if (
|
|
169
|
-
const html =
|
|
168
|
+
else if (mtrl.type === 'foreignObject') {
|
|
169
|
+
const html = mtrl.content;
|
|
170
170
|
if (isAssetId(html) && !assets[html] && loadItemMap[html] && typeof ((_c = loadItemMap[html]) === null || _c === void 0 ? void 0 : _c.source) === 'string') {
|
|
171
171
|
assets[html] = {
|
|
172
|
-
type: '
|
|
173
|
-
value: loadItemMap[html].source
|
|
172
|
+
type: 'foreignObject',
|
|
173
|
+
value: loadItemMap[html].source,
|
|
174
174
|
};
|
|
175
175
|
}
|
|
176
176
|
else if (!assets[html]) {
|
|
177
|
-
const assetUUID = createAssetId(html,
|
|
177
|
+
const assetUUID = createAssetId(html, mtrl.id);
|
|
178
178
|
if (!assets[assetUUID]) {
|
|
179
179
|
assets[assetUUID] = {
|
|
180
|
-
type: '
|
|
181
|
-
value: html
|
|
180
|
+
type: 'foreignObject',
|
|
181
|
+
value: html,
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
|
-
|
|
184
|
+
mtrl.content = assetUUID;
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
else if (
|
|
188
|
-
const groupAssets =
|
|
187
|
+
else if (mtrl.type === 'group' && Array.isArray(mtrl.children)) {
|
|
188
|
+
const groupAssets = mtrl.assets || {};
|
|
189
189
|
Object.keys(groupAssets).forEach((assetId) => {
|
|
190
190
|
if (!assets[assetId]) {
|
|
191
191
|
assets[assetId] = groupAssets[assetId];
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
|
-
delete
|
|
195
|
-
|
|
194
|
+
delete mtrl.assets;
|
|
195
|
+
_scanMaterials(mtrl.children);
|
|
196
196
|
}
|
|
197
197
|
});
|
|
198
198
|
};
|
|
199
|
-
|
|
199
|
+
_scanMaterials(sortedData.materials);
|
|
200
200
|
sortedData.assets = assets;
|
|
201
201
|
return sortedData;
|
|
202
202
|
}
|