@idraw/core 0.3.0-alpha.4 → 0.3.0-alpha.7
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/constant/element.d.ts +2 -0
- package/dist/esm/constant/element.js +10 -0
- package/dist/esm/constant/static.d.ts +11 -0
- package/dist/esm/constant/static.js +13 -0
- package/dist/esm/index.d.ts +59 -0
- package/{esm → dist/esm}/index.js +10 -10
- package/dist/esm/lib/calculate.d.ts +5 -0
- package/dist/esm/lib/calculate.js +64 -0
- package/dist/esm/lib/check.d.ts +28 -0
- package/dist/esm/lib/check.js +115 -0
- package/dist/esm/lib/config.d.ts +3 -0
- package/dist/esm/lib/config.js +20 -0
- package/dist/esm/lib/core-event.d.ts +49 -0
- package/dist/esm/lib/core-event.js +50 -0
- package/dist/esm/lib/diff.d.ts +6 -0
- package/dist/esm/lib/diff.js +80 -0
- package/dist/esm/lib/draw/base.d.ts +5 -0
- package/dist/esm/lib/draw/base.js +90 -0
- package/dist/esm/lib/draw/wrapper.d.ts +4 -0
- package/dist/esm/lib/draw/wrapper.js +144 -0
- package/dist/esm/lib/element/element-base.d.ts +3 -0
- package/dist/esm/lib/element/element-base.js +5 -0
- package/dist/esm/lib/element/element-controller.d.ts +3 -0
- package/dist/esm/lib/element/element-controller.js +3 -0
- package/dist/esm/lib/element/element-hub.d.ts +9 -0
- package/dist/esm/lib/element/element-hub.js +16 -0
- package/dist/esm/lib/element.d.ts +15 -0
- package/dist/esm/lib/element.js +380 -0
- package/dist/esm/lib/engine-temp.d.ts +22 -0
- package/dist/esm/lib/engine-temp.js +29 -0
- package/dist/esm/lib/engine.d.ts +47 -0
- package/dist/esm/lib/engine.js +323 -0
- package/dist/esm/lib/helper.d.ts +30 -0
- package/dist/esm/lib/helper.js +363 -0
- package/dist/esm/lib/index.d.ts +13 -0
- package/dist/esm/lib/index.js +13 -0
- package/dist/esm/lib/is.d.ts +26 -0
- package/dist/esm/lib/is.js +100 -0
- package/dist/esm/lib/mapper.d.ts +26 -0
- package/dist/esm/lib/mapper.js +89 -0
- package/dist/esm/lib/parse.d.ts +2 -0
- package/dist/esm/lib/parse.js +29 -0
- package/dist/esm/lib/temp.d.ts +11 -0
- package/dist/esm/lib/temp.js +19 -0
- package/dist/esm/lib/transform.d.ts +4 -0
- package/dist/esm/lib/transform.js +20 -0
- package/dist/esm/lib/value.d.ts +2 -0
- package/dist/esm/lib/value.js +7 -0
- package/dist/esm/mixins/element.d.ts +20 -0
- package/dist/esm/mixins/element.js +156 -0
- package/{esm → dist/esm}/names.d.ts +0 -0
- package/{esm → dist/esm}/names.js +0 -0
- package/dist/esm/plugins/helper.d.ts +12 -0
- package/dist/esm/plugins/helper.js +21 -0
- package/dist/esm/util/filter.d.ts +1 -0
- package/dist/esm/util/filter.js +3 -0
- package/dist/index.global.js +4431 -5923
- package/dist/index.global.min.js +1 -1
- package/package.json +11 -16
- package/dist/index.cjs.js +0 -5995
- package/dist/index.d.ts +0 -163
- package/dist/index.esm.js +0 -5993
- package/esm/default.d.ts +0 -1
- package/esm/default.js +0 -2
- package/esm/esm.d.ts +0 -2
- package/esm/esm.js +0 -3
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import { deepClone } from '@idraw/util';
|
|
2
|
+
import { parseAngleToRadian, calcElementCenter } from './calculate';
|
|
3
|
+
import { rotateContext, rotateElement } from './transform';
|
|
4
|
+
import { LIMIT_QBLIQUE_ANGLE } from './../constant/element';
|
|
5
|
+
const limitQbliqueAngle = LIMIT_QBLIQUE_ANGLE;
|
|
6
|
+
export class Helper {
|
|
7
|
+
constructor(board, config) {
|
|
8
|
+
this._areaStart = { x: 0, y: 0 };
|
|
9
|
+
this._areaEnd = { x: 0, y: 0 };
|
|
10
|
+
this._board = board;
|
|
11
|
+
this._ctx = this._board.getContext();
|
|
12
|
+
this._coreConfig = config;
|
|
13
|
+
this._helperConfig = {
|
|
14
|
+
elementIndexMap: {}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
updateConfig(data, opts) {
|
|
18
|
+
this._updateElementIndex(data);
|
|
19
|
+
this._updateSelectedElementWrapper(data, opts);
|
|
20
|
+
this._updateSelectedElementListWrapper(data, opts);
|
|
21
|
+
}
|
|
22
|
+
getConfig() {
|
|
23
|
+
return deepClone(this._helperConfig);
|
|
24
|
+
}
|
|
25
|
+
getElementIndexByUUID(uuid) {
|
|
26
|
+
const index = this._helperConfig.elementIndexMap[uuid];
|
|
27
|
+
if (index >= 0) {
|
|
28
|
+
return index;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
isPointInElementWrapperController(p, data) {
|
|
33
|
+
var _a, _b;
|
|
34
|
+
const ctx = this._ctx;
|
|
35
|
+
const uuid = ((_b = (_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementWrapper) === null || _b === void 0 ? void 0 : _b.uuid) || null;
|
|
36
|
+
let directIndex = null;
|
|
37
|
+
let selectedControllerDirection = null;
|
|
38
|
+
let hoverControllerDirection = null;
|
|
39
|
+
if (!this._helperConfig.selectedElementWrapper) {
|
|
40
|
+
return {
|
|
41
|
+
uuid,
|
|
42
|
+
selectedControllerDirection,
|
|
43
|
+
directIndex,
|
|
44
|
+
hoverControllerDirection
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const wrapper = this._helperConfig.selectedElementWrapper;
|
|
48
|
+
const controllers = [
|
|
49
|
+
wrapper.controllers.right,
|
|
50
|
+
wrapper.controllers.topRight,
|
|
51
|
+
wrapper.controllers.top,
|
|
52
|
+
wrapper.controllers.topLeft,
|
|
53
|
+
wrapper.controllers.left,
|
|
54
|
+
wrapper.controllers.bottomLeft,
|
|
55
|
+
wrapper.controllers.bottom,
|
|
56
|
+
wrapper.controllers.bottomRight
|
|
57
|
+
];
|
|
58
|
+
let directionNames = [
|
|
59
|
+
'right',
|
|
60
|
+
'top-right',
|
|
61
|
+
'top',
|
|
62
|
+
'top-left',
|
|
63
|
+
'left',
|
|
64
|
+
'bottom-left',
|
|
65
|
+
'bottom',
|
|
66
|
+
'bottom-right'
|
|
67
|
+
];
|
|
68
|
+
let hoverDirectionNames = deepClone(directionNames);
|
|
69
|
+
let angleMoveNum = 0;
|
|
70
|
+
if (data && uuid) {
|
|
71
|
+
const elemIdx = this.getElementIndexByUUID(uuid);
|
|
72
|
+
if (elemIdx !== null && elemIdx >= 0) {
|
|
73
|
+
const elem = data.elements[elemIdx];
|
|
74
|
+
let angle = elem.angle;
|
|
75
|
+
if (angle < 0) {
|
|
76
|
+
angle += 360;
|
|
77
|
+
}
|
|
78
|
+
if (angle < 45) {
|
|
79
|
+
angleMoveNum = 0;
|
|
80
|
+
}
|
|
81
|
+
else if (angle < 90) {
|
|
82
|
+
angleMoveNum = 1;
|
|
83
|
+
}
|
|
84
|
+
else if (angle < 135) {
|
|
85
|
+
angleMoveNum = 2;
|
|
86
|
+
}
|
|
87
|
+
else if (angle < 180) {
|
|
88
|
+
angleMoveNum = 3;
|
|
89
|
+
}
|
|
90
|
+
else if (angle < 225) {
|
|
91
|
+
angleMoveNum = 4;
|
|
92
|
+
}
|
|
93
|
+
else if (angle < 270) {
|
|
94
|
+
angleMoveNum = 5;
|
|
95
|
+
}
|
|
96
|
+
else if (angle < 315) {
|
|
97
|
+
angleMoveNum = 6;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (angleMoveNum > 0) {
|
|
102
|
+
hoverDirectionNames = hoverDirectionNames
|
|
103
|
+
.slice(-angleMoveNum)
|
|
104
|
+
.concat(hoverDirectionNames.slice(0, -angleMoveNum));
|
|
105
|
+
}
|
|
106
|
+
rotateContext(ctx, wrapper.translate, wrapper.radian || 0, () => {
|
|
107
|
+
for (let i = 0; i < controllers.length; i++) {
|
|
108
|
+
const controller = controllers[i];
|
|
109
|
+
if (controller.invisible === true) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
ctx.beginPath();
|
|
113
|
+
ctx.arc(controller.x, controller.y, wrapper.controllerSize, 0, Math.PI * 2);
|
|
114
|
+
ctx.closePath();
|
|
115
|
+
if (ctx.isPointInPath(p.x, p.y)) {
|
|
116
|
+
selectedControllerDirection = directionNames[i];
|
|
117
|
+
hoverControllerDirection = hoverDirectionNames[i];
|
|
118
|
+
}
|
|
119
|
+
if (selectedControllerDirection) {
|
|
120
|
+
directIndex = i;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
if (selectedControllerDirection === null) {
|
|
126
|
+
const controller = wrapper.controllers.rotate;
|
|
127
|
+
if (controller.invisible !== true) {
|
|
128
|
+
rotateContext(ctx, wrapper.translate, wrapper.radian || 0, () => {
|
|
129
|
+
ctx.beginPath();
|
|
130
|
+
ctx.arc(controller.x, controller.y, wrapper.controllerSize, 0, Math.PI * 2);
|
|
131
|
+
ctx.closePath();
|
|
132
|
+
if (ctx.isPointInPath(p.x, p.y)) {
|
|
133
|
+
selectedControllerDirection = 'rotate';
|
|
134
|
+
hoverControllerDirection = 'rotate';
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
uuid,
|
|
141
|
+
selectedControllerDirection,
|
|
142
|
+
hoverControllerDirection,
|
|
143
|
+
directIndex
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
isPointInElementList(p, data) {
|
|
147
|
+
var _a, _b, _c;
|
|
148
|
+
const ctx = this._ctx;
|
|
149
|
+
let idx = -1;
|
|
150
|
+
let uuid = null;
|
|
151
|
+
const wrapperList = ((_a = this._helperConfig) === null || _a === void 0 ? void 0 : _a.selectedElementListWrappers) || [];
|
|
152
|
+
for (let i = 0; i < wrapperList.length; i++) {
|
|
153
|
+
const wrapper = wrapperList[i];
|
|
154
|
+
const elemIdx = this._helperConfig.elementIndexMap[wrapper.uuid];
|
|
155
|
+
const ele = data.elements[elemIdx];
|
|
156
|
+
if (!ele)
|
|
157
|
+
continue;
|
|
158
|
+
if (((_b = ele.operation) === null || _b === void 0 ? void 0 : _b.invisible) === true)
|
|
159
|
+
continue;
|
|
160
|
+
let bw = 0;
|
|
161
|
+
if (((_c = ele.desc) === null || _c === void 0 ? void 0 : _c.borderWidth) > 0) {
|
|
162
|
+
bw = ele.desc.borderWidth;
|
|
163
|
+
}
|
|
164
|
+
rotateElement(ctx, ele, () => {
|
|
165
|
+
ctx.beginPath();
|
|
166
|
+
ctx.moveTo(ele.x - bw, ele.y - bw);
|
|
167
|
+
ctx.lineTo(ele.x + ele.w + bw, ele.y - bw);
|
|
168
|
+
ctx.lineTo(ele.x + ele.w + bw, ele.y + ele.h + bw);
|
|
169
|
+
ctx.lineTo(ele.x - bw, ele.y + ele.h + bw);
|
|
170
|
+
ctx.lineTo(ele.x - bw, ele.y - bw);
|
|
171
|
+
ctx.closePath();
|
|
172
|
+
if (ctx.isPointInPath(p.x, p.y)) {
|
|
173
|
+
idx = i;
|
|
174
|
+
uuid = ele.uuid;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
if (idx >= 0) {
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (uuid && idx >= 0) {
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
startSelectArea(p) {
|
|
189
|
+
this._areaStart = p;
|
|
190
|
+
this._areaEnd = p;
|
|
191
|
+
}
|
|
192
|
+
changeSelectArea(p) {
|
|
193
|
+
this._areaEnd = p;
|
|
194
|
+
this._calcSelectedArea();
|
|
195
|
+
}
|
|
196
|
+
clearSelectedArea() {
|
|
197
|
+
this._areaStart = { x: 0, y: 0 };
|
|
198
|
+
this._areaEnd = { x: 0, y: 0 };
|
|
199
|
+
this._calcSelectedArea();
|
|
200
|
+
}
|
|
201
|
+
calcSelectedElements(data) {
|
|
202
|
+
const transform = this._ctx.getTransform();
|
|
203
|
+
const { scale = 1, scrollX = 0, scrollY = 0 } = transform;
|
|
204
|
+
const start = this._areaStart;
|
|
205
|
+
const end = this._areaEnd;
|
|
206
|
+
const x = (Math.min(start.x, end.x) - scrollX) / scale;
|
|
207
|
+
const y = (Math.min(start.y, end.y) - scrollY) / scale;
|
|
208
|
+
const w = Math.abs(end.x - start.x) / scale;
|
|
209
|
+
const h = Math.abs(end.y - start.y) / scale;
|
|
210
|
+
const uuids = [];
|
|
211
|
+
const ctx = this._ctx;
|
|
212
|
+
ctx.beginPath();
|
|
213
|
+
ctx.moveTo(x, y);
|
|
214
|
+
ctx.lineTo(x + w, y);
|
|
215
|
+
ctx.lineTo(x + w, y + h);
|
|
216
|
+
ctx.lineTo(x, y + h);
|
|
217
|
+
ctx.lineTo(x, y);
|
|
218
|
+
ctx.closePath();
|
|
219
|
+
data.elements.forEach((elem) => {
|
|
220
|
+
var _a;
|
|
221
|
+
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.invisible) !== true) {
|
|
222
|
+
const centerX = elem.x + elem.w / 2;
|
|
223
|
+
const centerY = elem.y + elem.h / 2;
|
|
224
|
+
if (ctx.isPointInPathWithoutScroll(centerX, centerY)) {
|
|
225
|
+
uuids.push(elem.uuid);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
return uuids;
|
|
230
|
+
}
|
|
231
|
+
_calcSelectedArea() {
|
|
232
|
+
const start = this._areaStart;
|
|
233
|
+
const end = this._areaEnd;
|
|
234
|
+
const transform = this._ctx.getTransform();
|
|
235
|
+
const { scale = 1, scrollX = 0, scrollY = 0 } = transform;
|
|
236
|
+
const elemWrapper = this._coreConfig.elementWrapper;
|
|
237
|
+
const lineWidth = elemWrapper.lineWidth / scale;
|
|
238
|
+
const lineDash = elemWrapper.lineDash.map((n) => n / scale);
|
|
239
|
+
this._helperConfig.selectedAreaWrapper = {
|
|
240
|
+
x: (Math.min(start.x, end.x) - scrollX) / scale,
|
|
241
|
+
y: (Math.min(start.y, end.y) - scrollY) / scale,
|
|
242
|
+
w: Math.abs(end.x - start.x) / scale,
|
|
243
|
+
h: Math.abs(end.y - start.y) / scale,
|
|
244
|
+
startPoint: { x: start.x, y: start.y },
|
|
245
|
+
endPoint: { x: end.x, y: end.y },
|
|
246
|
+
lineWidth: lineWidth,
|
|
247
|
+
lineDash: lineDash,
|
|
248
|
+
color: elemWrapper.color
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
_updateElementIndex(data) {
|
|
252
|
+
this._helperConfig.elementIndexMap = {};
|
|
253
|
+
data.elements.forEach((elem, i) => {
|
|
254
|
+
this._helperConfig.elementIndexMap[elem.uuid] = i;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
_updateSelectedElementWrapper(data, opts) {
|
|
258
|
+
var _a;
|
|
259
|
+
const { selectedUUID: uuid } = opts;
|
|
260
|
+
if (!(typeof uuid === 'string' &&
|
|
261
|
+
this._helperConfig.elementIndexMap[uuid] >= 0)) {
|
|
262
|
+
delete this._helperConfig.selectedElementWrapper;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
const index = this._helperConfig.elementIndexMap[uuid];
|
|
266
|
+
const elem = data.elements[index];
|
|
267
|
+
if (((_a = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _a === void 0 ? void 0 : _a.invisible) === true) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const wrapper = this._createSelectedElementWrapper(elem, opts);
|
|
271
|
+
this._helperConfig.selectedElementWrapper = wrapper;
|
|
272
|
+
}
|
|
273
|
+
_updateSelectedElementListWrapper(data, opts) {
|
|
274
|
+
const { selectedUUIDList } = opts;
|
|
275
|
+
const wrapperList = [];
|
|
276
|
+
data.elements.forEach((elem, i) => {
|
|
277
|
+
if (selectedUUIDList === null || selectedUUIDList === void 0 ? void 0 : selectedUUIDList.includes(elem.uuid)) {
|
|
278
|
+
const wrapper = this._createSelectedElementWrapper(elem, opts);
|
|
279
|
+
wrapperList.push(wrapper);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
this._helperConfig.selectedElementListWrappers = wrapperList;
|
|
283
|
+
}
|
|
284
|
+
_createSelectedElementWrapper(elem, opts) {
|
|
285
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
286
|
+
const { scale } = opts;
|
|
287
|
+
const elemWrapper = this._coreConfig.elementWrapper;
|
|
288
|
+
const controllerSize = elemWrapper.controllerSize / scale;
|
|
289
|
+
const lineWidth = elemWrapper.lineWidth / scale;
|
|
290
|
+
const lineDash = elemWrapper.lineDash.map((n) => n / scale);
|
|
291
|
+
const rotateLimit = 12;
|
|
292
|
+
const bw = ((_a = elem.desc) === null || _a === void 0 ? void 0 : _a.borderWidth) || 0;
|
|
293
|
+
let hideObliqueDirection = false;
|
|
294
|
+
if (typeof elem.angle === 'number' &&
|
|
295
|
+
Math.abs(elem.angle) > limitQbliqueAngle) {
|
|
296
|
+
hideObliqueDirection = true;
|
|
297
|
+
}
|
|
298
|
+
const controllerOffset = lineWidth;
|
|
299
|
+
const wrapper = {
|
|
300
|
+
uuid: elem.uuid,
|
|
301
|
+
controllerSize: controllerSize,
|
|
302
|
+
controllerOffset: controllerOffset,
|
|
303
|
+
lock: ((_b = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _b === void 0 ? void 0 : _b.lock) === true,
|
|
304
|
+
controllers: {
|
|
305
|
+
topLeft: {
|
|
306
|
+
x: elem.x - controllerOffset - bw,
|
|
307
|
+
y: elem.y - controllerOffset - bw,
|
|
308
|
+
invisible: hideObliqueDirection || ((_c = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _c === void 0 ? void 0 : _c.disableScale) === true
|
|
309
|
+
},
|
|
310
|
+
top: {
|
|
311
|
+
x: elem.x + elem.w / 2,
|
|
312
|
+
y: elem.y - controllerOffset - bw,
|
|
313
|
+
invisible: ((_d = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _d === void 0 ? void 0 : _d.disableScale) === true
|
|
314
|
+
},
|
|
315
|
+
topRight: {
|
|
316
|
+
x: elem.x + elem.w + controllerOffset + bw,
|
|
317
|
+
y: elem.y - controllerOffset - bw,
|
|
318
|
+
invisible: hideObliqueDirection || ((_e = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _e === void 0 ? void 0 : _e.disableScale) === true
|
|
319
|
+
},
|
|
320
|
+
right: {
|
|
321
|
+
x: elem.x + elem.w + controllerOffset + bw,
|
|
322
|
+
y: elem.y + elem.h / 2,
|
|
323
|
+
invisible: ((_f = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _f === void 0 ? void 0 : _f.disableScale) === true
|
|
324
|
+
},
|
|
325
|
+
bottomRight: {
|
|
326
|
+
x: elem.x + elem.w + controllerOffset + bw,
|
|
327
|
+
y: elem.y + elem.h + controllerOffset + bw,
|
|
328
|
+
invisible: hideObliqueDirection || ((_g = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _g === void 0 ? void 0 : _g.disableScale) === true
|
|
329
|
+
},
|
|
330
|
+
bottom: {
|
|
331
|
+
x: elem.x + elem.w / 2,
|
|
332
|
+
y: elem.y + elem.h + controllerOffset + bw,
|
|
333
|
+
invisible: ((_h = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _h === void 0 ? void 0 : _h.disableScale) === true
|
|
334
|
+
},
|
|
335
|
+
bottomLeft: {
|
|
336
|
+
x: elem.x - controllerOffset - bw,
|
|
337
|
+
y: elem.y + elem.h + controllerOffset + bw,
|
|
338
|
+
invisible: hideObliqueDirection || ((_j = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _j === void 0 ? void 0 : _j.disableScale) === true
|
|
339
|
+
},
|
|
340
|
+
left: {
|
|
341
|
+
x: elem.x - controllerOffset - bw,
|
|
342
|
+
y: elem.y + elem.h / 2,
|
|
343
|
+
invisible: ((_k = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _k === void 0 ? void 0 : _k.disableScale) === true
|
|
344
|
+
},
|
|
345
|
+
rotate: {
|
|
346
|
+
x: elem.x + elem.w / 2,
|
|
347
|
+
y: elem.y - controllerSize - (controllerSize * 2 + rotateLimit) - bw,
|
|
348
|
+
invisible: ((_l = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _l === void 0 ? void 0 : _l.disbaleRotate) === true
|
|
349
|
+
}
|
|
350
|
+
},
|
|
351
|
+
lineWidth: lineWidth,
|
|
352
|
+
lineDash: lineDash,
|
|
353
|
+
color: ((_m = elem === null || elem === void 0 ? void 0 : elem.operation) === null || _m === void 0 ? void 0 : _m.lock) === true
|
|
354
|
+
? elemWrapper.lockColor
|
|
355
|
+
: elemWrapper.color
|
|
356
|
+
};
|
|
357
|
+
if (typeof elem.angle === 'number' && (elem.angle > 0 || elem.angle < 0)) {
|
|
358
|
+
wrapper.radian = parseAngleToRadian(elem.angle);
|
|
359
|
+
wrapper.translate = calcElementCenter(elem);
|
|
360
|
+
}
|
|
361
|
+
return wrapper;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './calculate';
|
|
2
|
+
export * from './check';
|
|
3
|
+
export * from './config';
|
|
4
|
+
export * from './core-event';
|
|
5
|
+
export * from './diff';
|
|
6
|
+
export * from './element';
|
|
7
|
+
export * from './helper';
|
|
8
|
+
export * from './is';
|
|
9
|
+
export * from './mapper';
|
|
10
|
+
export * from './parse';
|
|
11
|
+
export * from './temp';
|
|
12
|
+
export * from './transform';
|
|
13
|
+
export * from './value';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from './calculate';
|
|
2
|
+
export * from './check';
|
|
3
|
+
export * from './config';
|
|
4
|
+
export * from './core-event';
|
|
5
|
+
export * from './diff';
|
|
6
|
+
export * from './element';
|
|
7
|
+
export * from './helper';
|
|
8
|
+
export * from './is';
|
|
9
|
+
export * from './mapper';
|
|
10
|
+
export * from './parse';
|
|
11
|
+
export * from './temp';
|
|
12
|
+
export * from './transform';
|
|
13
|
+
export * from './value';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
declare const is: TypeIs;
|
|
2
|
+
type TypeIs = {
|
|
3
|
+
x: (value: any) => boolean;
|
|
4
|
+
y: (value: any) => boolean;
|
|
5
|
+
w: (value: any) => boolean;
|
|
6
|
+
h: (value: any) => boolean;
|
|
7
|
+
angle: (value: any) => boolean;
|
|
8
|
+
number: (value: any) => boolean;
|
|
9
|
+
borderWidth: (value: any) => boolean;
|
|
10
|
+
borderRadius: (value: any) => boolean;
|
|
11
|
+
color: (value: any) => boolean;
|
|
12
|
+
imageSrc: (value: any) => boolean;
|
|
13
|
+
imageURL: (value: any) => boolean;
|
|
14
|
+
imageBase64: (value: any) => boolean;
|
|
15
|
+
svg: (value: any) => boolean;
|
|
16
|
+
html: (value: any) => boolean;
|
|
17
|
+
text: (value: any) => boolean;
|
|
18
|
+
fontSize: (value: any) => boolean;
|
|
19
|
+
fontWeight: (value: any) => boolean;
|
|
20
|
+
lineHeight: (value: any) => boolean;
|
|
21
|
+
textAlign: (value: any) => boolean;
|
|
22
|
+
fontFamily: (value: any) => boolean;
|
|
23
|
+
strokeWidth: (value: any) => boolean;
|
|
24
|
+
};
|
|
25
|
+
export default is;
|
|
26
|
+
export { TypeIs };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { isColorStr } from '@idraw/util';
|
|
2
|
+
function number(value) {
|
|
3
|
+
return typeof value === 'number' && (value > 0 || value <= 0);
|
|
4
|
+
}
|
|
5
|
+
function x(value) {
|
|
6
|
+
return number(value);
|
|
7
|
+
}
|
|
8
|
+
function y(value) {
|
|
9
|
+
return number(value);
|
|
10
|
+
}
|
|
11
|
+
function w(value) {
|
|
12
|
+
return typeof value === 'number' && value >= 0;
|
|
13
|
+
}
|
|
14
|
+
function h(value) {
|
|
15
|
+
return typeof value === 'number' && value >= 0;
|
|
16
|
+
}
|
|
17
|
+
function angle(value) {
|
|
18
|
+
return typeof value === 'number' && value >= -360 && value <= 360;
|
|
19
|
+
}
|
|
20
|
+
function borderWidth(value) {
|
|
21
|
+
return w(value);
|
|
22
|
+
}
|
|
23
|
+
function borderRadius(value) {
|
|
24
|
+
return number(value) && value >= 0;
|
|
25
|
+
}
|
|
26
|
+
function color(value) {
|
|
27
|
+
return isColorStr(value);
|
|
28
|
+
}
|
|
29
|
+
function imageURL(value) {
|
|
30
|
+
return (typeof value === 'string' &&
|
|
31
|
+
/^(http:\/\/|https:\/\/|\.\/|\/)/.test(`${value}`));
|
|
32
|
+
}
|
|
33
|
+
function imageBase64(value) {
|
|
34
|
+
return typeof value === 'string' && /^(data:image\/)/.test(`${value}`);
|
|
35
|
+
}
|
|
36
|
+
function imageSrc(value) {
|
|
37
|
+
return imageBase64(value) || imageURL(value);
|
|
38
|
+
}
|
|
39
|
+
function svg(value) {
|
|
40
|
+
return (typeof value === 'string' &&
|
|
41
|
+
/^(<svg[\s]{1,}|<svg>)/i.test(`${value}`.trim()) &&
|
|
42
|
+
/<\/[\s]{0,}svg>$/i.test(`${value}`.trim()));
|
|
43
|
+
}
|
|
44
|
+
function html(value) {
|
|
45
|
+
let result = false;
|
|
46
|
+
if (typeof value === 'string') {
|
|
47
|
+
let div = document.createElement('div');
|
|
48
|
+
div.innerHTML = value;
|
|
49
|
+
if (div.children.length > 0) {
|
|
50
|
+
result = true;
|
|
51
|
+
}
|
|
52
|
+
div = null;
|
|
53
|
+
}
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
function text(value) {
|
|
57
|
+
return typeof value === 'string';
|
|
58
|
+
}
|
|
59
|
+
function fontSize(value) {
|
|
60
|
+
return number(value) && value > 0;
|
|
61
|
+
}
|
|
62
|
+
function lineHeight(value) {
|
|
63
|
+
return number(value) && value > 0;
|
|
64
|
+
}
|
|
65
|
+
function strokeWidth(value) {
|
|
66
|
+
return number(value) && value > 0;
|
|
67
|
+
}
|
|
68
|
+
function textAlign(value) {
|
|
69
|
+
return ['center', 'left', 'right'].includes(value);
|
|
70
|
+
}
|
|
71
|
+
function fontFamily(value) {
|
|
72
|
+
return typeof value === 'string' && value.length > 0;
|
|
73
|
+
}
|
|
74
|
+
function fontWeight(value) {
|
|
75
|
+
return ['bold'].includes(value);
|
|
76
|
+
}
|
|
77
|
+
const is = {
|
|
78
|
+
x,
|
|
79
|
+
y,
|
|
80
|
+
w,
|
|
81
|
+
h,
|
|
82
|
+
angle,
|
|
83
|
+
number,
|
|
84
|
+
borderWidth,
|
|
85
|
+
borderRadius,
|
|
86
|
+
color,
|
|
87
|
+
imageSrc,
|
|
88
|
+
imageURL,
|
|
89
|
+
imageBase64,
|
|
90
|
+
svg,
|
|
91
|
+
html,
|
|
92
|
+
text,
|
|
93
|
+
fontSize,
|
|
94
|
+
lineHeight,
|
|
95
|
+
textAlign,
|
|
96
|
+
fontFamily,
|
|
97
|
+
fontWeight,
|
|
98
|
+
strokeWidth
|
|
99
|
+
};
|
|
100
|
+
export default is;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { TypeData, TypePoint, TypePointCursor } from '@idraw/types';
|
|
2
|
+
import Board from '@idraw/board';
|
|
3
|
+
import { Helper } from './helper';
|
|
4
|
+
import { Element } from './element';
|
|
5
|
+
declare const _board: unique symbol;
|
|
6
|
+
declare const _helper: unique symbol;
|
|
7
|
+
declare const _element: unique symbol;
|
|
8
|
+
declare const _opts: unique symbol;
|
|
9
|
+
type Options = {
|
|
10
|
+
board: Board;
|
|
11
|
+
element: Element;
|
|
12
|
+
helper: Helper;
|
|
13
|
+
};
|
|
14
|
+
export declare class Mapper {
|
|
15
|
+
private [_opts];
|
|
16
|
+
private [_board];
|
|
17
|
+
private [_helper];
|
|
18
|
+
private [_element];
|
|
19
|
+
constructor(opts: Options);
|
|
20
|
+
isEffectivePoint(p: TypePoint): boolean;
|
|
21
|
+
judgePointCursor(p: TypePoint, data: TypeData): {
|
|
22
|
+
cursor: TypePointCursor;
|
|
23
|
+
elementUUID: string | null;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const _board = Symbol('_displayCtx');
|
|
2
|
+
const _helper = Symbol('_helper');
|
|
3
|
+
const _element = Symbol('_element');
|
|
4
|
+
const _opts = Symbol('_opts');
|
|
5
|
+
export class Mapper {
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
this[_opts] = opts;
|
|
8
|
+
this[_board] = this[_opts].board;
|
|
9
|
+
this[_element] = this[_opts].element;
|
|
10
|
+
this[_helper] = this[_opts].helper;
|
|
11
|
+
}
|
|
12
|
+
isEffectivePoint(p) {
|
|
13
|
+
const scrollLineWidth = this[_board].getScrollLineWidth();
|
|
14
|
+
const screenInfo = this[_board].getScreenInfo();
|
|
15
|
+
if (p.x <= screenInfo.width - scrollLineWidth &&
|
|
16
|
+
p.y <= screenInfo.height - scrollLineWidth) {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
judgePointCursor(p, data) {
|
|
22
|
+
let cursor = 'auto';
|
|
23
|
+
let elementUUID = null;
|
|
24
|
+
if (!this.isEffectivePoint(p)) {
|
|
25
|
+
return { cursor, elementUUID };
|
|
26
|
+
}
|
|
27
|
+
const { uuid, hoverControllerDirection } = this[_helper].isPointInElementWrapperController(p, data);
|
|
28
|
+
const direction = hoverControllerDirection;
|
|
29
|
+
if (uuid && direction) {
|
|
30
|
+
switch (direction) {
|
|
31
|
+
case 'top-right': {
|
|
32
|
+
cursor = 'ne-resize';
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'top-left': {
|
|
36
|
+
cursor = 'nw-resize';
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
case 'top': {
|
|
40
|
+
cursor = 'n-resize';
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case 'right': {
|
|
44
|
+
cursor = 'e-resize';
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case 'bottom-right': {
|
|
48
|
+
cursor = 'se-resize';
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
case 'bottom': {
|
|
52
|
+
cursor = 's-resize';
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
case 'bottom-left': {
|
|
56
|
+
cursor = 'sw-resize';
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
case 'left': {
|
|
60
|
+
cursor = 'w-resize';
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'rotate': {
|
|
64
|
+
cursor = 'grab';
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
default: {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (uuid) {
|
|
72
|
+
elementUUID = uuid;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
const [index, uuid] = this[_element].isPointInElement(p, data);
|
|
77
|
+
if (index >= 0) {
|
|
78
|
+
cursor = 'move';
|
|
79
|
+
}
|
|
80
|
+
if (uuid) {
|
|
81
|
+
elementUUID = uuid;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
cursor,
|
|
86
|
+
elementUUID
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { elementNames } from './../constant/element';
|
|
2
|
+
export function parseData(data) {
|
|
3
|
+
const result = {
|
|
4
|
+
elements: [],
|
|
5
|
+
};
|
|
6
|
+
if (Array.isArray(data === null || data === void 0 ? void 0 : data.elements)) {
|
|
7
|
+
data === null || data === void 0 ? void 0 : data.elements.forEach((elem = {}) => {
|
|
8
|
+
if (isElement(elem)) {
|
|
9
|
+
result.elements.push(elem);
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
if (typeof data.bgColor === 'string') {
|
|
14
|
+
result.bgColor = data.bgColor;
|
|
15
|
+
}
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
function isElement(elem) {
|
|
19
|
+
if (!(isNumber(elem.x) && isNumber(elem.y) && isNumber(elem.w) && isNumber(elem.h))) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (!(typeof elem.type === 'string' && elementNames.includes(elem.type))) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
function isNumber(num) {
|
|
28
|
+
return (num >= 0 || num < 0);
|
|
29
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type TempDataDesc = {
|
|
2
|
+
hasInited: boolean;
|
|
3
|
+
};
|
|
4
|
+
export declare class TempData {
|
|
5
|
+
private _temp;
|
|
6
|
+
constructor();
|
|
7
|
+
set<T extends keyof TempDataDesc>(name: T, value: TempDataDesc[T]): void;
|
|
8
|
+
get<T extends keyof TempDataDesc>(name: T): TempDataDesc[T];
|
|
9
|
+
clear(): void;
|
|
10
|
+
}
|
|
11
|
+
export {};
|