@idraw/util 0.4.0-beta.9 → 0.4.0
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/index.d.ts +46 -31
- package/dist/esm/index.js +46 -31
- package/dist/esm/{lib → tool}/color.js +9 -6
- package/dist/esm/{lib → tool}/event.d.ts +1 -0
- package/dist/esm/{lib → tool}/event.js +3 -0
- package/dist/esm/tool/flat-object.d.ts +6 -0
- package/dist/esm/tool/flat-object.js +28 -0
- package/dist/esm/tool/get-set-del.d.ts +4 -0
- package/dist/esm/tool/get-set-del.js +65 -0
- package/dist/esm/{lib → tool}/html.d.ts +1 -1
- package/dist/esm/{lib → tool}/html.js +6 -2
- package/dist/esm/{lib → tool}/istype.d.ts +1 -0
- package/dist/esm/{lib → tool}/istype.js +3 -0
- package/dist/esm/tool/merge.d.ts +1 -0
- package/dist/esm/tool/merge.js +17 -0
- package/dist/esm/tool/omit.d.ts +1 -0
- package/dist/esm/tool/omit.js +7 -0
- package/dist/esm/tool/store.d.ts +16 -0
- package/dist/esm/{lib → tool}/store.js +17 -5
- package/dist/esm/tool/unflat-object.d.ts +3 -0
- package/dist/esm/tool/unflat-object.js +91 -0
- package/dist/esm/{lib → tool}/uuid.d.ts +1 -1
- package/dist/esm/tool/uuid.js +39 -0
- package/dist/esm/view/box.d.ts +2 -0
- package/dist/esm/view/box.js +173 -0
- package/dist/esm/{lib → view}/canvas.d.ts +0 -1
- package/dist/esm/view/canvas.js +57 -0
- package/dist/esm/{lib → view}/check.js +14 -14
- package/dist/esm/{lib → view}/config.js +2 -2
- package/dist/esm/{lib → view}/context2d.d.ts +4 -0
- package/dist/esm/{lib → view}/context2d.js +20 -0
- package/dist/esm/view/controller.d.ts +12 -0
- package/dist/esm/view/controller.js +321 -0
- package/dist/esm/{lib → view}/data.d.ts +1 -0
- package/dist/esm/{lib → view}/data.js +43 -22
- package/dist/esm/{lib → view}/element.d.ts +5 -0
- package/dist/esm/{lib → view}/element.js +66 -5
- package/dist/esm/view/flat.d.ts +2 -0
- package/dist/esm/view/flat.js +133 -0
- package/dist/esm/view/group.d.ts +3 -0
- package/dist/esm/view/group.js +81 -0
- package/dist/esm/{lib → view}/handle-element.d.ts +11 -1
- package/dist/esm/{lib → view}/handle-element.js +102 -51
- package/dist/esm/view/handle-global.d.ts +4 -0
- package/dist/esm/view/handle-global.js +28 -0
- package/dist/esm/view/handle-layout.d.ts +4 -0
- package/dist/esm/view/handle-layout.js +28 -0
- package/dist/esm/{lib → view}/is.d.ts +3 -1
- package/dist/esm/{lib → view}/is.js +22 -6
- package/dist/esm/view/modify-record.d.ts +4 -0
- package/dist/esm/view/modify-record.js +10 -0
- package/dist/esm/view/point-move-element.d.ts +5 -0
- package/dist/esm/view/point-move-element.js +26 -0
- package/dist/esm/view/position.d.ts +15 -0
- package/dist/esm/view/position.js +79 -0
- package/dist/esm/view/rect.js +11 -0
- package/dist/esm/view/resize-element.d.ts +4 -0
- package/dist/esm/view/resize-element.js +255 -0
- package/dist/esm/{lib → view}/rotate.js +8 -13
- package/dist/esm/view/text.d.ts +1 -0
- package/dist/esm/view/text.js +4 -0
- package/dist/esm/{lib → view}/view-box.js +3 -1
- package/dist/esm/{lib → view}/view-calc.d.ts +16 -3
- package/dist/esm/{lib → view}/view-calc.js +127 -3
- package/dist/esm/view/view-content.d.ts +14 -0
- package/dist/esm/view/view-content.js +88 -0
- package/dist/index.global.js +1938 -346
- package/dist/index.global.min.js +1 -1
- package/package.json +2 -2
- package/dist/esm/lib/canvas.js +0 -81
- package/dist/esm/lib/controller.d.ts +0 -6
- package/dist/esm/lib/controller.js +0 -103
- package/dist/esm/lib/rect.js +0 -11
- package/dist/esm/lib/resize-element.d.ts +0 -2
- package/dist/esm/lib/resize-element.js +0 -101
- package/dist/esm/lib/store.d.ts +0 -11
- package/dist/esm/lib/uuid.js +0 -31
- /package/dist/esm/{lib → tool}/color.d.ts +0 -0
- /package/dist/esm/{lib → tool}/file.d.ts +0 -0
- /package/dist/esm/{lib → tool}/file.js +0 -0
- /package/dist/esm/{lib → tool}/image.d.ts +0 -0
- /package/dist/esm/{lib → tool}/image.js +0 -0
- /package/dist/esm/{lib → tool}/number.d.ts +0 -0
- /package/dist/esm/{lib → tool}/number.js +0 -0
- /package/dist/esm/{lib → tool}/time.d.ts +0 -0
- /package/dist/esm/{lib → tool}/time.js +0 -0
- /package/dist/esm/{lib → view}/check.d.ts +0 -0
- /package/dist/esm/{lib → view}/config.d.ts +0 -0
- /package/dist/esm/{lib → view}/load.d.ts +0 -0
- /package/dist/esm/{lib → view}/load.js +0 -0
- /package/dist/esm/{lib → view}/matrix.d.ts +0 -0
- /package/dist/esm/{lib → view}/matrix.js +0 -0
- /package/dist/esm/{lib → view}/middleware.d.ts +0 -0
- /package/dist/esm/{lib → view}/middleware.js +0 -0
- /package/dist/esm/{lib → view}/parser.d.ts +0 -0
- /package/dist/esm/{lib → view}/parser.js +0 -0
- /package/dist/esm/{lib → view}/point.d.ts +0 -0
- /package/dist/esm/{lib → view}/point.js +0 -0
- /package/dist/esm/{lib → view}/rect.d.ts +0 -0
- /package/dist/esm/{lib → view}/rotate.d.ts +0 -0
- /package/dist/esm/{lib → view}/svg-path.d.ts +0 -0
- /package/dist/esm/{lib → view}/svg-path.js +0 -0
- /package/dist/esm/{lib → view}/vertex.d.ts +0 -0
- /package/dist/esm/{lib → view}/vertex.js +0 -0
- /package/dist/esm/{lib → view}/view-box.d.ts +0 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { createUUID } from '../tool/uuid';
|
|
2
|
+
import { getCenterFromTwoPoints } from './point';
|
|
3
|
+
import { calcElementVertexesInGroup, calcElementVertexes } from './vertex';
|
|
4
|
+
import { calcViewElementSize } from './view-calc';
|
|
5
|
+
import { calcElementCenter } from './rotate';
|
|
6
|
+
function createControllerElementSizeFromCenter(center, opts) {
|
|
7
|
+
const { x, y } = center;
|
|
8
|
+
const { size, angle } = opts;
|
|
9
|
+
return {
|
|
10
|
+
x: x - size / 2,
|
|
11
|
+
y: y - size / 2,
|
|
12
|
+
w: size,
|
|
13
|
+
h: size,
|
|
14
|
+
angle
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function calcElementSizeController(elemSize, opts) {
|
|
18
|
+
const { groupQueue, controllerSize, viewScaleInfo, rotateControllerSize, rotateControllerPosition } = opts;
|
|
19
|
+
const ctrlSize = (controllerSize && controllerSize > 0 ? controllerSize : 8) / viewScaleInfo.scale;
|
|
20
|
+
const { x, y, w, h, angle = 0 } = elemSize;
|
|
21
|
+
const rotateCtrlSize = rotateControllerSize;
|
|
22
|
+
const rotateCtrlPos = rotateControllerPosition;
|
|
23
|
+
const ctrlGroupQueue = [
|
|
24
|
+
...[
|
|
25
|
+
{
|
|
26
|
+
uuid: createUUID(),
|
|
27
|
+
x,
|
|
28
|
+
y,
|
|
29
|
+
w,
|
|
30
|
+
h,
|
|
31
|
+
angle,
|
|
32
|
+
type: 'group',
|
|
33
|
+
detail: { children: [] }
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
...groupQueue
|
|
37
|
+
];
|
|
38
|
+
let totalAngle = 0;
|
|
39
|
+
ctrlGroupQueue.forEach(({ angle = 0 }) => {
|
|
40
|
+
totalAngle += angle;
|
|
41
|
+
});
|
|
42
|
+
const vertexes = calcElementVertexesInGroup(elemSize, { groupQueue });
|
|
43
|
+
const rotateElemVertexes = calcElementVertexesInGroup({
|
|
44
|
+
x: x,
|
|
45
|
+
y: y - (rotateCtrlPos + rotateCtrlSize / 2) / viewScaleInfo.scale,
|
|
46
|
+
h: h + (rotateCtrlPos * 2 + rotateCtrlSize) / viewScaleInfo.scale,
|
|
47
|
+
w: w,
|
|
48
|
+
angle
|
|
49
|
+
}, { groupQueue: [...groupQueue] });
|
|
50
|
+
const topCenter = getCenterFromTwoPoints(vertexes[0], vertexes[1]);
|
|
51
|
+
const rightCenter = getCenterFromTwoPoints(vertexes[1], vertexes[2]);
|
|
52
|
+
const bottomCenter = getCenterFromTwoPoints(vertexes[2], vertexes[3]);
|
|
53
|
+
const leftCenter = getCenterFromTwoPoints(vertexes[3], vertexes[0]);
|
|
54
|
+
const topLeftCenter = vertexes[0];
|
|
55
|
+
const topRightCenter = vertexes[1];
|
|
56
|
+
const bottomRightCenter = vertexes[2];
|
|
57
|
+
const bottomLeftCenter = vertexes[3];
|
|
58
|
+
const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: totalAngle });
|
|
59
|
+
const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: totalAngle });
|
|
60
|
+
const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: totalAngle });
|
|
61
|
+
const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: totalAngle });
|
|
62
|
+
const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
63
|
+
const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: totalAngle });
|
|
64
|
+
const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: totalAngle });
|
|
65
|
+
const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, {
|
|
66
|
+
size: ctrlSize,
|
|
67
|
+
angle: totalAngle
|
|
68
|
+
});
|
|
69
|
+
const topLeftVertexes = calcElementVertexes(topLeftSize);
|
|
70
|
+
const topRightVertexes = calcElementVertexes(topRightSize);
|
|
71
|
+
const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
|
|
72
|
+
const bottomRightVertexes = calcElementVertexes(bottomRightSize);
|
|
73
|
+
const topVertexes = [
|
|
74
|
+
topLeftVertexes[1],
|
|
75
|
+
topRightVertexes[0],
|
|
76
|
+
topRightVertexes[3],
|
|
77
|
+
topLeftVertexes[2]
|
|
78
|
+
];
|
|
79
|
+
const rightVertexes = [
|
|
80
|
+
topRightVertexes[3],
|
|
81
|
+
topRightVertexes[2],
|
|
82
|
+
bottomRightVertexes[1],
|
|
83
|
+
bottomRightVertexes[0]
|
|
84
|
+
];
|
|
85
|
+
const bottomVertexes = [
|
|
86
|
+
bottomLeftVertexes[1],
|
|
87
|
+
bottomRightVertexes[0],
|
|
88
|
+
bottomRightVertexes[3],
|
|
89
|
+
bottomLeftVertexes[2]
|
|
90
|
+
];
|
|
91
|
+
const leftVertexes = [
|
|
92
|
+
topLeftVertexes[3],
|
|
93
|
+
topLeftVertexes[2],
|
|
94
|
+
bottomLeftVertexes[1],
|
|
95
|
+
bottomLeftVertexes[0]
|
|
96
|
+
];
|
|
97
|
+
const topMiddleVertexes = calcElementVertexes(topMiddleSize);
|
|
98
|
+
const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
|
|
99
|
+
const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
|
|
100
|
+
const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
|
|
101
|
+
const rotateCenter = getCenterFromTwoPoints(rotateElemVertexes[0], rotateElemVertexes[1]);
|
|
102
|
+
const tempRotateSizeRepairRatio = 1.1;
|
|
103
|
+
const rotateSize = createControllerElementSizeFromCenter(rotateCenter, {
|
|
104
|
+
size: (rotateControllerSize * tempRotateSizeRepairRatio) / viewScaleInfo.scale,
|
|
105
|
+
angle: totalAngle
|
|
106
|
+
});
|
|
107
|
+
const rotateVertexes = calcElementVertexes(rotateSize);
|
|
108
|
+
const sizeController = {
|
|
109
|
+
originalElementCenter: calcElementCenter(elemSize),
|
|
110
|
+
originalElementSize: Object.assign({}, elemSize),
|
|
111
|
+
elementWrapper: vertexes,
|
|
112
|
+
left: {
|
|
113
|
+
type: 'left',
|
|
114
|
+
vertexes: leftVertexes,
|
|
115
|
+
center: leftCenter,
|
|
116
|
+
size: ctrlSize
|
|
117
|
+
},
|
|
118
|
+
right: {
|
|
119
|
+
type: 'right',
|
|
120
|
+
vertexes: rightVertexes,
|
|
121
|
+
center: rightCenter,
|
|
122
|
+
size: ctrlSize
|
|
123
|
+
},
|
|
124
|
+
top: {
|
|
125
|
+
type: 'top',
|
|
126
|
+
vertexes: topVertexes,
|
|
127
|
+
center: topCenter,
|
|
128
|
+
size: ctrlSize
|
|
129
|
+
},
|
|
130
|
+
bottom: {
|
|
131
|
+
type: 'bottom',
|
|
132
|
+
vertexes: bottomVertexes,
|
|
133
|
+
center: bottomCenter,
|
|
134
|
+
size: ctrlSize
|
|
135
|
+
},
|
|
136
|
+
topLeft: {
|
|
137
|
+
type: 'top-left',
|
|
138
|
+
vertexes: topLeftVertexes,
|
|
139
|
+
center: topLeftCenter,
|
|
140
|
+
size: ctrlSize
|
|
141
|
+
},
|
|
142
|
+
topRight: {
|
|
143
|
+
type: 'top-right',
|
|
144
|
+
vertexes: topRightVertexes,
|
|
145
|
+
center: topRightCenter,
|
|
146
|
+
size: ctrlSize
|
|
147
|
+
},
|
|
148
|
+
bottomLeft: {
|
|
149
|
+
type: 'bottom-left',
|
|
150
|
+
vertexes: bottomLeftVertexes,
|
|
151
|
+
center: bottomLeftCenter,
|
|
152
|
+
size: ctrlSize
|
|
153
|
+
},
|
|
154
|
+
bottomRight: {
|
|
155
|
+
type: 'bottom-right',
|
|
156
|
+
vertexes: bottomRightVertexes,
|
|
157
|
+
center: bottomRightCenter,
|
|
158
|
+
size: ctrlSize
|
|
159
|
+
},
|
|
160
|
+
leftMiddle: {
|
|
161
|
+
type: 'left-middle',
|
|
162
|
+
vertexes: leftMiddleVertexes,
|
|
163
|
+
center: leftCenter,
|
|
164
|
+
size: ctrlSize
|
|
165
|
+
},
|
|
166
|
+
rightMiddle: {
|
|
167
|
+
type: 'right-middle',
|
|
168
|
+
vertexes: rightMiddleVertexes,
|
|
169
|
+
center: rightCenter,
|
|
170
|
+
size: ctrlSize
|
|
171
|
+
},
|
|
172
|
+
topMiddle: {
|
|
173
|
+
type: 'top-middle',
|
|
174
|
+
vertexes: topMiddleVertexes,
|
|
175
|
+
center: topCenter,
|
|
176
|
+
size: ctrlSize
|
|
177
|
+
},
|
|
178
|
+
bottomMiddle: {
|
|
179
|
+
type: 'bottom-middle',
|
|
180
|
+
vertexes: bottomMiddleVertexes,
|
|
181
|
+
center: bottomCenter,
|
|
182
|
+
size: ctrlSize
|
|
183
|
+
},
|
|
184
|
+
rotate: {
|
|
185
|
+
type: 'rotate',
|
|
186
|
+
vertexes: rotateVertexes,
|
|
187
|
+
center: rotateCenter,
|
|
188
|
+
size: rotateControllerSize
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
return sizeController;
|
|
192
|
+
}
|
|
193
|
+
export function calcLayoutSizeController(layoutSize, opts) {
|
|
194
|
+
const { controllerSize, viewScaleInfo } = opts;
|
|
195
|
+
const ctrlSize = controllerSize && controllerSize > 0 ? controllerSize : 8;
|
|
196
|
+
const { x, y, w, h } = calcViewElementSize(layoutSize, { viewScaleInfo });
|
|
197
|
+
const center = calcElementCenter({ x, y, w, h });
|
|
198
|
+
const topCenter = { x: center.x, y };
|
|
199
|
+
const rightCenter = { x: x + w, y: center.y };
|
|
200
|
+
const bottomCenter = { x: center.x, y: y + h };
|
|
201
|
+
const leftCenter = { x, y: center.y };
|
|
202
|
+
const topLeftCenter = { x, y };
|
|
203
|
+
const topRightCenter = { x: x + w, y };
|
|
204
|
+
const bottomRightCenter = { x: x + w, y: y + h };
|
|
205
|
+
const bottomLeftCenter = { x, y: y + h };
|
|
206
|
+
const topMiddleSize = createControllerElementSizeFromCenter(topCenter, { size: ctrlSize, angle: 0 });
|
|
207
|
+
const rightMiddleSize = createControllerElementSizeFromCenter(rightCenter, { size: ctrlSize, angle: 0 });
|
|
208
|
+
const bottomMiddleSize = createControllerElementSizeFromCenter(bottomCenter, { size: ctrlSize, angle: 0 });
|
|
209
|
+
const leftMiddleSize = createControllerElementSizeFromCenter(leftCenter, { size: ctrlSize, angle: 0 });
|
|
210
|
+
const topLeftSize = createControllerElementSizeFromCenter(topLeftCenter, { size: ctrlSize, angle: 0 });
|
|
211
|
+
const topRightSize = createControllerElementSizeFromCenter(topRightCenter, { size: ctrlSize, angle: 0 });
|
|
212
|
+
const bottomLeftSize = createControllerElementSizeFromCenter(bottomLeftCenter, { size: ctrlSize, angle: 0 });
|
|
213
|
+
const bottomRightSize = createControllerElementSizeFromCenter(bottomRightCenter, { size: ctrlSize, angle: 0 });
|
|
214
|
+
const topLeftVertexes = calcElementVertexes(topLeftSize);
|
|
215
|
+
const topRightVertexes = calcElementVertexes(topRightSize);
|
|
216
|
+
const bottomLeftVertexes = calcElementVertexes(bottomLeftSize);
|
|
217
|
+
const bottomRightVertexes = calcElementVertexes(bottomRightSize);
|
|
218
|
+
const topVertexes = [
|
|
219
|
+
topLeftVertexes[1],
|
|
220
|
+
topRightVertexes[0],
|
|
221
|
+
topRightVertexes[3],
|
|
222
|
+
topLeftVertexes[2]
|
|
223
|
+
];
|
|
224
|
+
const rightVertexes = [
|
|
225
|
+
topRightVertexes[3],
|
|
226
|
+
topRightVertexes[2],
|
|
227
|
+
bottomRightVertexes[1],
|
|
228
|
+
bottomRightVertexes[0]
|
|
229
|
+
];
|
|
230
|
+
const bottomVertexes = [
|
|
231
|
+
bottomLeftVertexes[1],
|
|
232
|
+
bottomRightVertexes[0],
|
|
233
|
+
bottomRightVertexes[3],
|
|
234
|
+
bottomLeftVertexes[2]
|
|
235
|
+
];
|
|
236
|
+
const leftVertexes = [
|
|
237
|
+
topLeftVertexes[3],
|
|
238
|
+
topLeftVertexes[2],
|
|
239
|
+
bottomLeftVertexes[1],
|
|
240
|
+
bottomLeftVertexes[0]
|
|
241
|
+
];
|
|
242
|
+
const topMiddleVertexes = calcElementVertexes(topMiddleSize);
|
|
243
|
+
const rightMiddleVertexes = calcElementVertexes(rightMiddleSize);
|
|
244
|
+
const bottomMiddleVertexes = calcElementVertexes(bottomMiddleSize);
|
|
245
|
+
const leftMiddleVertexes = calcElementVertexes(leftMiddleSize);
|
|
246
|
+
const sizeController = {
|
|
247
|
+
left: {
|
|
248
|
+
type: 'left',
|
|
249
|
+
vertexes: leftVertexes,
|
|
250
|
+
center: leftCenter,
|
|
251
|
+
size: ctrlSize
|
|
252
|
+
},
|
|
253
|
+
right: {
|
|
254
|
+
type: 'right',
|
|
255
|
+
vertexes: rightVertexes,
|
|
256
|
+
center: rightCenter,
|
|
257
|
+
size: ctrlSize
|
|
258
|
+
},
|
|
259
|
+
top: {
|
|
260
|
+
type: 'top',
|
|
261
|
+
vertexes: topVertexes,
|
|
262
|
+
center: topCenter,
|
|
263
|
+
size: ctrlSize
|
|
264
|
+
},
|
|
265
|
+
bottom: {
|
|
266
|
+
type: 'bottom',
|
|
267
|
+
vertexes: bottomVertexes,
|
|
268
|
+
center: bottomCenter,
|
|
269
|
+
size: ctrlSize
|
|
270
|
+
},
|
|
271
|
+
topLeft: {
|
|
272
|
+
type: 'top-left',
|
|
273
|
+
vertexes: topLeftVertexes,
|
|
274
|
+
center: topLeftCenter,
|
|
275
|
+
size: ctrlSize
|
|
276
|
+
},
|
|
277
|
+
topRight: {
|
|
278
|
+
type: 'top-right',
|
|
279
|
+
vertexes: topRightVertexes,
|
|
280
|
+
center: topRightCenter,
|
|
281
|
+
size: ctrlSize
|
|
282
|
+
},
|
|
283
|
+
bottomLeft: {
|
|
284
|
+
type: 'bottom-left',
|
|
285
|
+
vertexes: bottomLeftVertexes,
|
|
286
|
+
center: bottomLeftCenter,
|
|
287
|
+
size: ctrlSize
|
|
288
|
+
},
|
|
289
|
+
bottomRight: {
|
|
290
|
+
type: 'bottom-right',
|
|
291
|
+
vertexes: bottomRightVertexes,
|
|
292
|
+
center: bottomRightCenter,
|
|
293
|
+
size: ctrlSize
|
|
294
|
+
},
|
|
295
|
+
leftMiddle: {
|
|
296
|
+
type: 'left-middle',
|
|
297
|
+
vertexes: leftMiddleVertexes,
|
|
298
|
+
center: leftCenter,
|
|
299
|
+
size: ctrlSize
|
|
300
|
+
},
|
|
301
|
+
rightMiddle: {
|
|
302
|
+
type: 'right-middle',
|
|
303
|
+
vertexes: rightMiddleVertexes,
|
|
304
|
+
center: rightCenter,
|
|
305
|
+
size: ctrlSize
|
|
306
|
+
},
|
|
307
|
+
topMiddle: {
|
|
308
|
+
type: 'top-middle',
|
|
309
|
+
vertexes: topMiddleVertexes,
|
|
310
|
+
center: topCenter,
|
|
311
|
+
size: ctrlSize
|
|
312
|
+
},
|
|
313
|
+
bottomMiddle: {
|
|
314
|
+
type: 'bottom-middle',
|
|
315
|
+
vertexes: bottomMiddleVertexes,
|
|
316
|
+
center: bottomCenter,
|
|
317
|
+
size: ctrlSize
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
return sizeController;
|
|
321
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Data, Element, LoadItemMap } from '@idraw/types';
|
|
2
2
|
export declare function deepClone<T = any>(target: T): T;
|
|
3
3
|
export declare function deepCloneElement<T extends Element = Element>(element: T): T;
|
|
4
|
+
export declare function deepCloneData(data: Data): Data;
|
|
4
5
|
export declare function sortDataAsserts(data: Data, opts?: {
|
|
5
6
|
clone?: boolean;
|
|
6
7
|
}): Data;
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { createAssetId, createUUID, isAssetId } from '../tool/uuid';
|
|
2
13
|
export function deepClone(target) {
|
|
3
14
|
function _clone(t) {
|
|
4
15
|
const type = is(t);
|
|
@@ -40,11 +51,17 @@ export function deepCloneElement(element) {
|
|
|
40
51
|
_resetUUID(elem);
|
|
41
52
|
return elem;
|
|
42
53
|
}
|
|
54
|
+
export function deepCloneData(data) {
|
|
55
|
+
const { elements } = data, restData = __rest(data, ["elements"]);
|
|
56
|
+
return Object.assign(Object.assign({}, deepClone(restData)), {
|
|
57
|
+
elements: elements.map((elem) => deepCloneElement(elem))
|
|
58
|
+
});
|
|
59
|
+
}
|
|
43
60
|
function is(target) {
|
|
44
|
-
return Object.prototype.toString
|
|
61
|
+
return (Object.prototype.toString
|
|
45
62
|
.call(target)
|
|
46
63
|
.replace(/[\]|\[]{1,1}/gi, '')
|
|
47
|
-
.split(' ')[1];
|
|
64
|
+
.split(' ')[1]);
|
|
48
65
|
}
|
|
49
66
|
export function sortDataAsserts(data, opts) {
|
|
50
67
|
const assets = data.assets || {};
|
|
@@ -56,7 +73,7 @@ export function sortDataAsserts(data, opts) {
|
|
|
56
73
|
elems.forEach((elem) => {
|
|
57
74
|
if (elem.type === 'image' && elem.detail.src) {
|
|
58
75
|
const src = elem.detail.src;
|
|
59
|
-
const assetUUID = createAssetId(src);
|
|
76
|
+
const assetUUID = createAssetId(src, elem.uuid);
|
|
60
77
|
if (!assets[assetUUID]) {
|
|
61
78
|
assets[assetUUID] = {
|
|
62
79
|
type: 'image',
|
|
@@ -67,7 +84,7 @@ export function sortDataAsserts(data, opts) {
|
|
|
67
84
|
}
|
|
68
85
|
else if (elem.type === 'svg') {
|
|
69
86
|
const svg = elem.detail.svg;
|
|
70
|
-
const assetUUID = createAssetId(svg);
|
|
87
|
+
const assetUUID = createAssetId(svg, elem.uuid);
|
|
71
88
|
if (!assets[assetUUID]) {
|
|
72
89
|
assets[assetUUID] = {
|
|
73
90
|
type: 'svg',
|
|
@@ -78,7 +95,7 @@ export function sortDataAsserts(data, opts) {
|
|
|
78
95
|
}
|
|
79
96
|
else if (elem.type === 'html') {
|
|
80
97
|
const html = elem.detail.html;
|
|
81
|
-
const assetUUID = createAssetId(html);
|
|
98
|
+
const assetUUID = createAssetId(html, elem.uuid);
|
|
82
99
|
if (!assets[assetUUID]) {
|
|
83
100
|
assets[assetUUID] = {
|
|
84
101
|
type: 'html',
|
|
@@ -118,8 +135,8 @@ export function filterCompactData(data, opts) {
|
|
|
118
135
|
value: loadItemMap[src].source
|
|
119
136
|
};
|
|
120
137
|
}
|
|
121
|
-
else {
|
|
122
|
-
const assetUUID = createAssetId(src);
|
|
138
|
+
else if (!assets[src]) {
|
|
139
|
+
const assetUUID = createAssetId(src, elem.uuid);
|
|
123
140
|
if (!assets[assetUUID]) {
|
|
124
141
|
assets[assetUUID] = {
|
|
125
142
|
type: 'image',
|
|
@@ -131,37 +148,41 @@ export function filterCompactData(data, opts) {
|
|
|
131
148
|
}
|
|
132
149
|
else if (elem.type === 'svg') {
|
|
133
150
|
const svg = elem.detail.svg;
|
|
134
|
-
const assetUUID = createAssetId(svg);
|
|
135
151
|
if (isAssetId(svg) && !assets[svg] && loadItemMap[svg] && typeof ((_b = loadItemMap[svg]) === null || _b === void 0 ? void 0 : _b.source) === 'string') {
|
|
136
152
|
assets[svg] = {
|
|
137
153
|
type: 'svg',
|
|
138
154
|
value: loadItemMap[svg].source
|
|
139
155
|
};
|
|
140
156
|
}
|
|
141
|
-
else if (!assets[
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
157
|
+
else if (!assets[svg]) {
|
|
158
|
+
const assetUUID = createAssetId(svg, elem.uuid);
|
|
159
|
+
if (!assets[assetUUID]) {
|
|
160
|
+
assets[assetUUID] = {
|
|
161
|
+
type: 'svg',
|
|
162
|
+
value: svg
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
elem.detail.svg = assetUUID;
|
|
146
166
|
}
|
|
147
|
-
elem.detail.svg = assetUUID;
|
|
148
167
|
}
|
|
149
168
|
else if (elem.type === 'html') {
|
|
150
169
|
const html = elem.detail.html;
|
|
151
|
-
const assetUUID = createAssetId(html);
|
|
152
170
|
if (isAssetId(html) && !assets[html] && loadItemMap[html] && typeof ((_c = loadItemMap[html]) === null || _c === void 0 ? void 0 : _c.source) === 'string') {
|
|
153
171
|
assets[html] = {
|
|
154
172
|
type: 'html',
|
|
155
173
|
value: loadItemMap[html].source
|
|
156
174
|
};
|
|
157
175
|
}
|
|
158
|
-
else if (!assets[
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
176
|
+
else if (!assets[html]) {
|
|
177
|
+
const assetUUID = createAssetId(html, elem.uuid);
|
|
178
|
+
if (!assets[assetUUID]) {
|
|
179
|
+
assets[assetUUID] = {
|
|
180
|
+
type: 'html',
|
|
181
|
+
value: html
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
elem.detail.html = assetUUID;
|
|
163
185
|
}
|
|
164
|
-
elem.detail.html = assetUUID;
|
|
165
186
|
}
|
|
166
187
|
else if (elem.type === 'group' && Array.isArray(elem.detail.children)) {
|
|
167
188
|
const groupAssets = elem.detail.assets || {};
|
|
@@ -16,6 +16,7 @@ export declare function getElemenetsAssetIds(elements: Elements): string[];
|
|
|
16
16
|
export declare function findElementFromList(uuid: string, list: Element<ElementType>[]): Element<ElementType> | null;
|
|
17
17
|
export declare function findElementsFromList(uuids: string[], list: Element<ElementType>[]): Element<ElementType>[];
|
|
18
18
|
export declare function getGroupQueueFromList(uuid: string, elements: Element<ElementType>[]): Element<'group'>[];
|
|
19
|
+
export declare function getGroupQueueByElementPosition(elements: Element<ElementType>[], position: ElementPosition): Element<'group'>[] | null;
|
|
19
20
|
export declare function getElementSize(elem: Element): ElementSize;
|
|
20
21
|
export declare function mergeElementAsset<T extends Element<LoadElementType>>(element: T, assets: ElementAssets): T;
|
|
21
22
|
export declare function filterElementAsset<T extends Element<LoadElementType>>(element: T): {
|
|
@@ -28,3 +29,7 @@ export declare function findElementsFromListByPositions(positions: ElementPositi
|
|
|
28
29
|
export declare function findElementFromListByPosition(position: ElementPosition, list: Element[]): Element | null;
|
|
29
30
|
export declare function findElementQueueFromListByPosition(position: ElementPosition, list: Element[]): Element[];
|
|
30
31
|
export declare function getElementPositionFromList(uuid: string, elements: Element<ElementType>[]): ElementPosition;
|
|
32
|
+
export declare function getElementPositionMapFromList(uuids: string[], elements: Element<ElementType>[]): {
|
|
33
|
+
[uuid: string]: ElementPosition;
|
|
34
|
+
};
|
|
35
|
+
export declare function isSameElementSize(elem1: ElementSize, elem2: ElementSize): boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { rotateElementVertexes } from './rotate';
|
|
2
|
-
import { isAssetId, createAssetId } from '
|
|
1
|
+
import { limitAngle, rotateElementVertexes } from './rotate';
|
|
2
|
+
import { isAssetId, createAssetId } from '../tool/uuid';
|
|
3
3
|
function getGroupUUIDs(elements, index) {
|
|
4
4
|
var _a;
|
|
5
5
|
const uuids = [];
|
|
@@ -168,7 +168,11 @@ export function calcElementsContextSize(elements, opts) {
|
|
|
168
168
|
return ctxSize;
|
|
169
169
|
}
|
|
170
170
|
export function calcElementsViewInfo(elements, prevViewSize, options) {
|
|
171
|
-
const contextSize = calcElementsContextSize(elements, {
|
|
171
|
+
const contextSize = calcElementsContextSize(elements, {
|
|
172
|
+
viewWidth: prevViewSize.width,
|
|
173
|
+
viewHeight: prevViewSize.height,
|
|
174
|
+
extend: options === null || options === void 0 ? void 0 : options.extend
|
|
175
|
+
});
|
|
172
176
|
if ((options === null || options === void 0 ? void 0 : options.extend) === true) {
|
|
173
177
|
contextSize.contextWidth = Math.max(contextSize.contextWidth, prevViewSize.contextWidth);
|
|
174
178
|
contextSize.contextHeight = Math.max(contextSize.contextHeight, prevViewSize.contextHeight);
|
|
@@ -260,6 +264,25 @@ export function getGroupQueueFromList(uuid, elements) {
|
|
|
260
264
|
_scan(uuid, elements);
|
|
261
265
|
return groupQueue;
|
|
262
266
|
}
|
|
267
|
+
export function getGroupQueueByElementPosition(elements, position) {
|
|
268
|
+
var _a;
|
|
269
|
+
const groupQueue = [];
|
|
270
|
+
let currentElements = elements;
|
|
271
|
+
if (position.length > 1) {
|
|
272
|
+
for (let i = 0; i < position.length - 1; i++) {
|
|
273
|
+
const index = position[i];
|
|
274
|
+
const group = currentElements[index];
|
|
275
|
+
if ((group === null || group === void 0 ? void 0 : group.type) === 'group' && Array.isArray((_a = group === null || group === void 0 ? void 0 : group.detail) === null || _a === void 0 ? void 0 : _a.children)) {
|
|
276
|
+
groupQueue.push(group);
|
|
277
|
+
currentElements = group.detail.children;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return groupQueue;
|
|
285
|
+
}
|
|
263
286
|
export function getElementSize(elem) {
|
|
264
287
|
const { x, y, w, h, angle } = elem;
|
|
265
288
|
const size = { x, y, w, h, angle };
|
|
@@ -308,7 +331,7 @@ export function filterElementAsset(element) {
|
|
|
308
331
|
resource = element.detail.html;
|
|
309
332
|
}
|
|
310
333
|
if (typeof resource === 'string' && !isAssetId(resource)) {
|
|
311
|
-
assetId = createAssetId(resource);
|
|
334
|
+
assetId = createAssetId(resource, element.uuid);
|
|
312
335
|
assetItem = {
|
|
313
336
|
type: element.type,
|
|
314
337
|
value: resource
|
|
@@ -348,7 +371,7 @@ export function findElementFromListByPosition(position, list) {
|
|
|
348
371
|
for (let i = 0; i < position.length; i++) {
|
|
349
372
|
const pos = position[i];
|
|
350
373
|
const item = tempList[pos];
|
|
351
|
-
if (i < position.length - 1 && item.type === 'group') {
|
|
374
|
+
if (i < position.length - 1 && (item === null || item === void 0 ? void 0 : item.type) === 'group') {
|
|
352
375
|
tempList = item.detail.children;
|
|
353
376
|
}
|
|
354
377
|
else if (i === position.length - 1) {
|
|
@@ -408,3 +431,41 @@ export function getElementPositionFromList(uuid, elements) {
|
|
|
408
431
|
_loop(elements);
|
|
409
432
|
return result;
|
|
410
433
|
}
|
|
434
|
+
export function getElementPositionMapFromList(uuids, elements) {
|
|
435
|
+
const currentPosition = [];
|
|
436
|
+
const positionMap = {};
|
|
437
|
+
let over = false;
|
|
438
|
+
const _loop = (list) => {
|
|
439
|
+
var _a;
|
|
440
|
+
for (let i = 0; i < list.length; i++) {
|
|
441
|
+
if (over === true) {
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
currentPosition.push(i);
|
|
445
|
+
const elem = list[i];
|
|
446
|
+
if (uuids.includes(elem.uuid)) {
|
|
447
|
+
positionMap[elem.uuid] = [...currentPosition];
|
|
448
|
+
if (Object.keys(positionMap).length === uuids.length) {
|
|
449
|
+
over = true;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
else if (elem.type === 'group') {
|
|
454
|
+
_loop(((_a = elem === null || elem === void 0 ? void 0 : elem.detail) === null || _a === void 0 ? void 0 : _a.children) || []);
|
|
455
|
+
}
|
|
456
|
+
if (over) {
|
|
457
|
+
break;
|
|
458
|
+
}
|
|
459
|
+
currentPosition.pop();
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
_loop(elements);
|
|
463
|
+
return positionMap;
|
|
464
|
+
}
|
|
465
|
+
export function isSameElementSize(elem1, elem2) {
|
|
466
|
+
return (elem1.x === elem2.x &&
|
|
467
|
+
elem1.y === elem2.y &&
|
|
468
|
+
elem1.h === elem2.h &&
|
|
469
|
+
elem1.w === elem2.w &&
|
|
470
|
+
limitAngle(elem1.angle || 0) === limitAngle(elem2.angle || 0));
|
|
471
|
+
}
|