@idraw/core 0.3.0-alpha.6 → 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,90 @@
|
|
|
1
|
+
import { istype, isColorStr } from '@idraw/util';
|
|
2
|
+
import { rotateElement } from './../transform';
|
|
3
|
+
import is from './../is';
|
|
4
|
+
export function clearContext(ctx) {
|
|
5
|
+
ctx.setFillStyle('#000000');
|
|
6
|
+
ctx.setStrokeStyle('#000000');
|
|
7
|
+
ctx.setLineDash([]);
|
|
8
|
+
ctx.setGlobalAlpha(1);
|
|
9
|
+
ctx.setShadowColor('#00000000');
|
|
10
|
+
ctx.setShadowOffsetX(0);
|
|
11
|
+
ctx.setShadowOffsetY(0);
|
|
12
|
+
ctx.setShadowBlur(0);
|
|
13
|
+
}
|
|
14
|
+
export function drawBgColor(ctx, color) {
|
|
15
|
+
const size = ctx.getSize();
|
|
16
|
+
ctx.setFillStyle(color);
|
|
17
|
+
ctx.fillRect(0, 0, size.contextWidth, size.contextHeight);
|
|
18
|
+
}
|
|
19
|
+
export function drawBox(ctx, elem, pattern) {
|
|
20
|
+
clearContext(ctx);
|
|
21
|
+
drawBoxBorder(ctx, elem);
|
|
22
|
+
clearContext(ctx);
|
|
23
|
+
rotateElement(ctx, elem, () => {
|
|
24
|
+
const { x, y, w, h } = elem;
|
|
25
|
+
let r = elem.desc.borderRadius || 0;
|
|
26
|
+
r = Math.min(r, w / 2, h / 2);
|
|
27
|
+
if (w < r * 2 || h < r * 2) {
|
|
28
|
+
r = 0;
|
|
29
|
+
}
|
|
30
|
+
ctx.beginPath();
|
|
31
|
+
ctx.moveTo(x + r, y);
|
|
32
|
+
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
33
|
+
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
34
|
+
ctx.arcTo(x, y + h, x, y, r);
|
|
35
|
+
ctx.arcTo(x, y, x + w, y, r);
|
|
36
|
+
ctx.closePath();
|
|
37
|
+
if (typeof pattern === 'string') {
|
|
38
|
+
ctx.setFillStyle(pattern);
|
|
39
|
+
}
|
|
40
|
+
else if (['CanvasPattern'].includes(istype.type(pattern))) {
|
|
41
|
+
ctx.setFillStyle(pattern);
|
|
42
|
+
}
|
|
43
|
+
ctx.fill();
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function drawBoxBorder(ctx, elem) {
|
|
47
|
+
clearContext(ctx);
|
|
48
|
+
rotateElement(ctx, elem, () => {
|
|
49
|
+
if (!(elem.desc.borderWidth && elem.desc.borderWidth > 0)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const bw = elem.desc.borderWidth;
|
|
53
|
+
let borderColor = '#000000';
|
|
54
|
+
if (isColorStr(elem.desc.borderColor) === true) {
|
|
55
|
+
borderColor = elem.desc.borderColor;
|
|
56
|
+
}
|
|
57
|
+
const x = elem.x - bw / 2;
|
|
58
|
+
const y = elem.y - bw / 2;
|
|
59
|
+
const w = elem.w + bw;
|
|
60
|
+
const h = elem.h + bw;
|
|
61
|
+
let r = elem.desc.borderRadius || 0;
|
|
62
|
+
r = Math.min(r, w / 2, h / 2);
|
|
63
|
+
if (r < w / 2 && r < h / 2) {
|
|
64
|
+
r = r + bw / 2;
|
|
65
|
+
}
|
|
66
|
+
const { desc } = elem;
|
|
67
|
+
if (desc.shadowColor !== undefined && isColorStr(desc.shadowColor)) {
|
|
68
|
+
ctx.setShadowColor(desc.shadowColor);
|
|
69
|
+
}
|
|
70
|
+
if (desc.shadowOffsetX !== undefined && is.number(desc.shadowOffsetX)) {
|
|
71
|
+
ctx.setShadowOffsetX(desc.shadowOffsetX);
|
|
72
|
+
}
|
|
73
|
+
if (desc.shadowOffsetY !== undefined && is.number(desc.shadowOffsetY)) {
|
|
74
|
+
ctx.setShadowOffsetY(desc.shadowOffsetY);
|
|
75
|
+
}
|
|
76
|
+
if (desc.shadowBlur !== undefined && is.number(desc.shadowBlur)) {
|
|
77
|
+
ctx.setShadowBlur(desc.shadowBlur);
|
|
78
|
+
}
|
|
79
|
+
ctx.beginPath();
|
|
80
|
+
ctx.setLineWidth(bw);
|
|
81
|
+
ctx.setStrokeStyle(borderColor);
|
|
82
|
+
ctx.moveTo(x + r, y);
|
|
83
|
+
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
84
|
+
ctx.arcTo(x + w, y + h, x, y + h, r);
|
|
85
|
+
ctx.arcTo(x, y + h, x, y, r);
|
|
86
|
+
ctx.arcTo(x, y, x + w, y, r);
|
|
87
|
+
ctx.closePath();
|
|
88
|
+
ctx.stroke();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TypeContext, TypeHelperConfig } from '@idraw/types';
|
|
2
|
+
export declare function drawElementWrapper(ctx: TypeContext, config: TypeHelperConfig): void;
|
|
3
|
+
export declare function drawAreaWrapper(ctx: TypeContext, config: TypeHelperConfig): void;
|
|
4
|
+
export declare function drawElementListWrappers(ctx: TypeContext, config: TypeHelperConfig): void;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { rotateContext } from './../transform';
|
|
2
|
+
import { clearContext } from './base';
|
|
3
|
+
export function drawElementWrapper(ctx, config) {
|
|
4
|
+
if (!(config === null || config === void 0 ? void 0 : config.selectedElementWrapper)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const wrapper = config.selectedElementWrapper;
|
|
8
|
+
clearContext(ctx);
|
|
9
|
+
rotateContext(ctx, wrapper.translate, wrapper.radian || 0, () => {
|
|
10
|
+
ctx.beginPath();
|
|
11
|
+
ctx.setLineDash(wrapper.lineDash);
|
|
12
|
+
ctx.setLineWidth(wrapper.lineWidth);
|
|
13
|
+
ctx.setStrokeStyle(wrapper.color);
|
|
14
|
+
ctx.moveTo(wrapper.controllers.topLeft.x, wrapper.controllers.topLeft.y);
|
|
15
|
+
ctx.lineTo(wrapper.controllers.topRight.x, wrapper.controllers.topRight.y);
|
|
16
|
+
ctx.lineTo(wrapper.controllers.bottomRight.x, wrapper.controllers.bottomRight.y);
|
|
17
|
+
ctx.lineTo(wrapper.controllers.bottomLeft.x, wrapper.controllers.bottomLeft.y);
|
|
18
|
+
ctx.lineTo(wrapper.controllers.topLeft.x, wrapper.controllers.topLeft.y - wrapper.lineWidth / 2);
|
|
19
|
+
ctx.stroke();
|
|
20
|
+
ctx.closePath();
|
|
21
|
+
if (wrapper.lock !== true) {
|
|
22
|
+
if (wrapper.controllers.rotate.invisible !== true) {
|
|
23
|
+
ctx.beginPath();
|
|
24
|
+
ctx.moveTo(wrapper.controllers.top.x, wrapper.controllers.top.y);
|
|
25
|
+
ctx.lineTo(wrapper.controllers.rotate.x, wrapper.controllers.rotate.y + wrapper.controllerSize);
|
|
26
|
+
ctx.stroke();
|
|
27
|
+
ctx.closePath();
|
|
28
|
+
ctx.beginPath();
|
|
29
|
+
ctx.setLineDash([]);
|
|
30
|
+
ctx.setLineWidth(wrapper.controllerSize / 2);
|
|
31
|
+
ctx.arc(wrapper.controllers.rotate.x, wrapper.controllers.rotate.y, wrapper.controllerSize * 0.8, Math.PI / 6, Math.PI * 2);
|
|
32
|
+
ctx.stroke();
|
|
33
|
+
ctx.closePath();
|
|
34
|
+
}
|
|
35
|
+
ctx.setFillStyle(wrapper.color);
|
|
36
|
+
[
|
|
37
|
+
wrapper.controllers.topLeft,
|
|
38
|
+
wrapper.controllers.top,
|
|
39
|
+
wrapper.controllers.topRight,
|
|
40
|
+
wrapper.controllers.right,
|
|
41
|
+
wrapper.controllers.bottomRight,
|
|
42
|
+
wrapper.controllers.bottom,
|
|
43
|
+
wrapper.controllers.bottomLeft,
|
|
44
|
+
wrapper.controllers.left,
|
|
45
|
+
].forEach((controller) => {
|
|
46
|
+
if (controller.invisible !== true) {
|
|
47
|
+
ctx.beginPath();
|
|
48
|
+
ctx.arc(controller.x, controller.y, wrapper.controllerSize, 0, Math.PI * 2);
|
|
49
|
+
ctx.fill();
|
|
50
|
+
ctx.closePath();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
clearContext(ctx);
|
|
56
|
+
ctx.setStrokeStyle(wrapper.color);
|
|
57
|
+
[
|
|
58
|
+
wrapper.controllers.topLeft, wrapper.controllers.top, wrapper.controllers.topRight, wrapper.controllers.right,
|
|
59
|
+
wrapper.controllers.bottomRight, wrapper.controllers.bottom, wrapper.controllers.bottomLeft, wrapper.controllers.left,
|
|
60
|
+
].forEach((controller) => {
|
|
61
|
+
ctx.beginPath();
|
|
62
|
+
ctx.moveTo(controller.x - wrapper.controllerSize / 2, controller.y - wrapper.controllerSize / 2);
|
|
63
|
+
ctx.lineTo(controller.x + wrapper.controllerSize / 2, controller.y + wrapper.controllerSize / 2);
|
|
64
|
+
ctx.stroke();
|
|
65
|
+
ctx.closePath();
|
|
66
|
+
ctx.beginPath();
|
|
67
|
+
ctx.moveTo(controller.x + wrapper.controllerSize / 2, controller.y - wrapper.controllerSize / 2);
|
|
68
|
+
ctx.lineTo(controller.x - wrapper.controllerSize / 2, controller.y + wrapper.controllerSize / 2);
|
|
69
|
+
ctx.stroke();
|
|
70
|
+
ctx.closePath();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export function drawAreaWrapper(ctx, config) {
|
|
76
|
+
if (!(config === null || config === void 0 ? void 0 : config.selectedAreaWrapper)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const wrapper = config.selectedAreaWrapper;
|
|
80
|
+
if (wrapper && wrapper.w > 0 && wrapper.h > 0) {
|
|
81
|
+
clearContext(ctx);
|
|
82
|
+
ctx.setGlobalAlpha(0.3);
|
|
83
|
+
ctx.setFillStyle(wrapper.color);
|
|
84
|
+
ctx.fillRect(wrapper.x, wrapper.y, wrapper.w, wrapper.h);
|
|
85
|
+
clearContext(ctx);
|
|
86
|
+
ctx.beginPath();
|
|
87
|
+
ctx.setLineDash(wrapper.lineDash);
|
|
88
|
+
ctx.setLineWidth(wrapper.lineWidth);
|
|
89
|
+
ctx.setStrokeStyle(wrapper.color);
|
|
90
|
+
ctx.moveTo(wrapper.x, wrapper.y);
|
|
91
|
+
ctx.lineTo(wrapper.x + wrapper.w, wrapper.y);
|
|
92
|
+
ctx.lineTo(wrapper.x + wrapper.w, wrapper.y + wrapper.h);
|
|
93
|
+
ctx.lineTo(wrapper.x, wrapper.y + wrapper.h);
|
|
94
|
+
ctx.lineTo(wrapper.x, wrapper.y);
|
|
95
|
+
ctx.stroke();
|
|
96
|
+
ctx.closePath();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
export function drawElementListWrappers(ctx, config) {
|
|
100
|
+
if (!Array.isArray(config === null || config === void 0 ? void 0 : config.selectedElementListWrappers)) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
const wrapperList = config.selectedElementListWrappers;
|
|
104
|
+
wrapperList === null || wrapperList === void 0 ? void 0 : wrapperList.forEach((wrapper) => {
|
|
105
|
+
clearContext(ctx);
|
|
106
|
+
rotateContext(ctx, wrapper.translate, wrapper.radian || 0, () => {
|
|
107
|
+
clearContext(ctx);
|
|
108
|
+
ctx.setGlobalAlpha(0.05);
|
|
109
|
+
ctx.setFillStyle(wrapper.color);
|
|
110
|
+
ctx.fillRect(wrapper.controllers.topLeft.x, wrapper.controllers.topLeft.y, wrapper.controllers.bottomRight.x - wrapper.controllers.topLeft.x, wrapper.controllers.bottomRight.y - wrapper.controllers.topLeft.y);
|
|
111
|
+
clearContext(ctx);
|
|
112
|
+
ctx.beginPath();
|
|
113
|
+
ctx.setLineDash(wrapper.lineDash);
|
|
114
|
+
ctx.setLineWidth(wrapper.lineWidth);
|
|
115
|
+
ctx.setStrokeStyle(wrapper.color);
|
|
116
|
+
ctx.moveTo(wrapper.controllers.topLeft.x, wrapper.controllers.topLeft.y);
|
|
117
|
+
ctx.lineTo(wrapper.controllers.topRight.x, wrapper.controllers.topRight.y);
|
|
118
|
+
ctx.lineTo(wrapper.controllers.bottomRight.x, wrapper.controllers.bottomRight.y);
|
|
119
|
+
ctx.lineTo(wrapper.controllers.bottomLeft.x, wrapper.controllers.bottomLeft.y);
|
|
120
|
+
ctx.lineTo(wrapper.controllers.topLeft.x, wrapper.controllers.topLeft.y - wrapper.lineWidth / 2);
|
|
121
|
+
ctx.stroke();
|
|
122
|
+
ctx.closePath();
|
|
123
|
+
if (wrapper.lock === true) {
|
|
124
|
+
clearContext(ctx);
|
|
125
|
+
ctx.setStrokeStyle(wrapper.color);
|
|
126
|
+
[
|
|
127
|
+
wrapper.controllers.topLeft, wrapper.controllers.top, wrapper.controllers.topRight, wrapper.controllers.right,
|
|
128
|
+
wrapper.controllers.bottomRight, wrapper.controllers.bottom, wrapper.controllers.bottomLeft, wrapper.controllers.left,
|
|
129
|
+
].forEach((controller) => {
|
|
130
|
+
ctx.beginPath();
|
|
131
|
+
ctx.moveTo(controller.x - wrapper.controllerSize / 2, controller.y - wrapper.controllerSize / 2);
|
|
132
|
+
ctx.lineTo(controller.x + wrapper.controllerSize / 2, controller.y + wrapper.controllerSize / 2);
|
|
133
|
+
ctx.stroke();
|
|
134
|
+
ctx.closePath();
|
|
135
|
+
ctx.beginPath();
|
|
136
|
+
ctx.moveTo(controller.x + wrapper.controllerSize / 2, controller.y - wrapper.controllerSize / 2);
|
|
137
|
+
ctx.lineTo(controller.x - wrapper.controllerSize / 2, controller.y + wrapper.controllerSize / 2);
|
|
138
|
+
ctx.stroke();
|
|
139
|
+
ctx.closePath();
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ElementController from './element-controller';
|
|
2
|
+
declare class ElementHub {
|
|
3
|
+
private _controllerMap;
|
|
4
|
+
constructor();
|
|
5
|
+
register(type: string, controller: ElementController): void;
|
|
6
|
+
clear(): void;
|
|
7
|
+
getDrawActions(): void;
|
|
8
|
+
}
|
|
9
|
+
export default ElementHub;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class ElementHub {
|
|
2
|
+
constructor() {
|
|
3
|
+
this._controllerMap = new Map();
|
|
4
|
+
}
|
|
5
|
+
register(type, controller) {
|
|
6
|
+
if (this._controllerMap.has(type) !== true) {
|
|
7
|
+
this._controllerMap.set(type, controller);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
clear() {
|
|
11
|
+
this._controllerMap.clear();
|
|
12
|
+
}
|
|
13
|
+
getDrawActions() {
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default ElementHub;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TypeContext, TypePoint, TypeData, TypeHelperWrapperControllerDirection, TypeElement, TypeElemDesc } from '@idraw/types';
|
|
2
|
+
export declare class Element {
|
|
3
|
+
private _ctx;
|
|
4
|
+
constructor(ctx: TypeContext);
|
|
5
|
+
initData(data: TypeData): TypeData;
|
|
6
|
+
isPointInElement(p: TypePoint, data: TypeData): [number, string | null];
|
|
7
|
+
dragElement(data: TypeData, uuid: string, point: TypePoint, prevPoint: TypePoint, scale: number): void;
|
|
8
|
+
transformElement(data: TypeData, uuid: string, point: TypePoint, prevPoint: TypePoint, scale: number, direction: TypeHelperWrapperControllerDirection): null | {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
angle: number;
|
|
12
|
+
};
|
|
13
|
+
getElementIndex(data: TypeData, uuid: string): number;
|
|
14
|
+
limitElementAttrs(elem: TypeElement<keyof TypeElemDesc>): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { createUUID } from '@idraw/util';
|
|
2
|
+
import { rotateElement } from './transform';
|
|
3
|
+
import { calcRadian, calcElementCenter, parseRadianToAngle } from './calculate';
|
|
4
|
+
import { limitAngle, limitNum } from './value';
|
|
5
|
+
import { LIMIT_QBLIQUE_ANGLE } from './../constant/element';
|
|
6
|
+
const limitQbliqueAngle = LIMIT_QBLIQUE_ANGLE;
|
|
7
|
+
export class Element {
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this._ctx = ctx;
|
|
10
|
+
}
|
|
11
|
+
initData(data) {
|
|
12
|
+
data.elements.forEach((elem) => {
|
|
13
|
+
if (!(elem.uuid && typeof elem.uuid === 'string')) {
|
|
14
|
+
elem.uuid = createUUID();
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
isPointInElement(p, data) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
const ctx = this._ctx;
|
|
22
|
+
let idx = -1;
|
|
23
|
+
let uuid = null;
|
|
24
|
+
for (let i = data.elements.length - 1; i >= 0; i--) {
|
|
25
|
+
const ele = data.elements[i];
|
|
26
|
+
if (((_a = ele.operation) === null || _a === void 0 ? void 0 : _a.invisible) === true)
|
|
27
|
+
continue;
|
|
28
|
+
let bw = 0;
|
|
29
|
+
if (((_b = ele.desc) === null || _b === void 0 ? void 0 : _b.borderWidth) > 0) {
|
|
30
|
+
bw = ele.desc.borderWidth;
|
|
31
|
+
}
|
|
32
|
+
rotateElement(ctx, ele, () => {
|
|
33
|
+
ctx.beginPath();
|
|
34
|
+
ctx.moveTo(ele.x - bw, ele.y - bw);
|
|
35
|
+
ctx.lineTo(ele.x + ele.w + bw, ele.y - bw);
|
|
36
|
+
ctx.lineTo(ele.x + ele.w + bw, ele.y + ele.h + bw);
|
|
37
|
+
ctx.lineTo(ele.x - bw, ele.y + ele.h + bw);
|
|
38
|
+
ctx.lineTo(ele.x - bw, ele.y - bw);
|
|
39
|
+
ctx.closePath();
|
|
40
|
+
if (ctx.isPointInPath(p.x, p.y)) {
|
|
41
|
+
idx = i;
|
|
42
|
+
uuid = ele.uuid;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (idx >= 0) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [idx, uuid];
|
|
50
|
+
}
|
|
51
|
+
dragElement(data, uuid, point, prevPoint, scale) {
|
|
52
|
+
const index = this.getElementIndex(data, uuid);
|
|
53
|
+
if (!data.elements[index]) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const moveX = point.x - prevPoint.x;
|
|
57
|
+
const moveY = point.y - prevPoint.y;
|
|
58
|
+
data.elements[index].x += (moveX / scale);
|
|
59
|
+
data.elements[index].y += (moveY / scale);
|
|
60
|
+
this.limitElementAttrs(data.elements[index]);
|
|
61
|
+
}
|
|
62
|
+
transformElement(data, uuid, point, prevPoint, scale, direction) {
|
|
63
|
+
var _a, _b;
|
|
64
|
+
const index = this.getElementIndex(data, uuid);
|
|
65
|
+
if (!data.elements[index]) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
if (((_b = (_a = data.elements[index]) === null || _a === void 0 ? void 0 : _a.operation) === null || _b === void 0 ? void 0 : _b.lock) === true) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
let moveX = (point.x - prevPoint.x) / scale;
|
|
72
|
+
let moveY = (point.y - prevPoint.y) / scale;
|
|
73
|
+
const elem = data.elements[index];
|
|
74
|
+
if ([
|
|
75
|
+
'top-left', 'top', 'top-right', 'right',
|
|
76
|
+
'bottom-right', 'bottom', 'bottom-left', 'left'
|
|
77
|
+
].includes(direction)) {
|
|
78
|
+
const p = calcuScaleElemPosition(elem, moveX, moveY, direction, scale);
|
|
79
|
+
elem.x = p.x;
|
|
80
|
+
elem.y = p.y;
|
|
81
|
+
elem.w = p.w;
|
|
82
|
+
elem.h = p.h;
|
|
83
|
+
}
|
|
84
|
+
else if (direction === 'rotate') {
|
|
85
|
+
const center = calcElementCenter(elem);
|
|
86
|
+
const radian = calcRadian(center, prevPoint, point);
|
|
87
|
+
elem.angle = (elem.angle || 0) + parseRadianToAngle(radian);
|
|
88
|
+
}
|
|
89
|
+
this.limitElementAttrs(elem);
|
|
90
|
+
return {
|
|
91
|
+
width: limitNum(elem.w),
|
|
92
|
+
height: limitNum(elem.h),
|
|
93
|
+
angle: limitAngle(elem.angle || 0),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
getElementIndex(data, uuid) {
|
|
97
|
+
let idx = -1;
|
|
98
|
+
for (let i = 0; i < data.elements.length; i++) {
|
|
99
|
+
if (data.elements[i].uuid === uuid) {
|
|
100
|
+
idx = i;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return idx;
|
|
105
|
+
}
|
|
106
|
+
limitElementAttrs(elem) {
|
|
107
|
+
elem.x = limitNum(elem.x);
|
|
108
|
+
elem.y = limitNum(elem.y);
|
|
109
|
+
elem.w = limitNum(elem.w);
|
|
110
|
+
elem.h = limitNum(elem.h);
|
|
111
|
+
elem.angle = limitAngle(elem.angle || 0);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function calcuScaleElemPosition(elem, moveX, moveY, direction, scale) {
|
|
115
|
+
const p = { x: elem.x, y: elem.y, w: elem.w, h: elem.h };
|
|
116
|
+
let angle = elem.angle;
|
|
117
|
+
if (angle < 0) {
|
|
118
|
+
angle = Math.max(0, 360 + angle);
|
|
119
|
+
}
|
|
120
|
+
switch (direction) {
|
|
121
|
+
case 'top-left': {
|
|
122
|
+
if (elem.w - moveX > 0 && elem.h - moveY > 0) {
|
|
123
|
+
p.x += moveX;
|
|
124
|
+
p.y += moveY;
|
|
125
|
+
p.w -= moveX;
|
|
126
|
+
p.h -= moveY;
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
case 'top': {
|
|
131
|
+
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
132
|
+
if (p.h - moveY > 0) {
|
|
133
|
+
p.y += moveY;
|
|
134
|
+
p.h -= moveY;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (elem.angle > 0 || elem.angle < 0) {
|
|
138
|
+
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
139
|
+
let moveDist = calcMoveDist(moveX, moveY);
|
|
140
|
+
let centerX = p.x + elem.w / 2;
|
|
141
|
+
let centerY = p.y + elem.h / 2;
|
|
142
|
+
if (angle < 90) {
|
|
143
|
+
moveDist = 0 - changeMoveDistDirect(moveDist, moveY);
|
|
144
|
+
const radian = parseRadian(angle);
|
|
145
|
+
const centerMoveDist = moveDist / 2;
|
|
146
|
+
centerX = centerX + centerMoveDist * Math.sin(radian);
|
|
147
|
+
centerY = centerY - centerMoveDist * Math.cos(radian);
|
|
148
|
+
}
|
|
149
|
+
else if (angle < 180) {
|
|
150
|
+
moveDist = changeMoveDistDirect(moveDist, moveX);
|
|
151
|
+
const radian = parseRadian(angle - 90);
|
|
152
|
+
const centerMoveDist = moveDist / 2;
|
|
153
|
+
centerX = centerX + centerMoveDist * Math.cos(radian);
|
|
154
|
+
centerY = centerY + centerMoveDist * Math.sin(radian);
|
|
155
|
+
}
|
|
156
|
+
else if (angle < 270) {
|
|
157
|
+
moveDist = changeMoveDistDirect(moveDist, moveY);
|
|
158
|
+
const radian = parseRadian(angle - 180);
|
|
159
|
+
const centerMoveDist = moveDist / 2;
|
|
160
|
+
centerX = centerX - centerMoveDist * Math.sin(radian);
|
|
161
|
+
centerY = centerY + centerMoveDist * Math.cos(radian);
|
|
162
|
+
}
|
|
163
|
+
else if (angle < 360) {
|
|
164
|
+
moveDist = 0 - changeMoveDistDirect(moveDist, moveX);
|
|
165
|
+
const radian = parseRadian(angle - 270);
|
|
166
|
+
const centerMoveDist = moveDist / 2;
|
|
167
|
+
centerX = centerX - centerMoveDist * Math.cos(radian);
|
|
168
|
+
centerY = centerY - centerMoveDist * Math.sin(radian);
|
|
169
|
+
}
|
|
170
|
+
if (p.h + moveDist > 0) {
|
|
171
|
+
p.h = p.h + moveDist;
|
|
172
|
+
p.x = centerX - p.w / 2;
|
|
173
|
+
p.y = centerY - p.h / 2;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
if (p.h - moveY > 0) {
|
|
178
|
+
p.y += moveY;
|
|
179
|
+
p.h -= moveY;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case 'top-right': {
|
|
185
|
+
if (p.h - moveY > 0 && p.w + moveX > 0) {
|
|
186
|
+
p.y += moveY;
|
|
187
|
+
p.w += moveX;
|
|
188
|
+
p.h -= moveY;
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case 'right': {
|
|
193
|
+
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
194
|
+
if (elem.w + moveX > 0) {
|
|
195
|
+
p.w += moveX;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
else if (elem.angle > 0 || elem.angle < 0) {
|
|
199
|
+
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
200
|
+
let moveDist = calcMoveDist(moveX, moveY);
|
|
201
|
+
let centerX = p.x + elem.w / 2;
|
|
202
|
+
let centerY = p.y + elem.h / 2;
|
|
203
|
+
if (angle < 90) {
|
|
204
|
+
moveDist = changeMoveDistDirect(moveDist, moveY);
|
|
205
|
+
const radian = parseRadian(angle);
|
|
206
|
+
const centerMoveDist = moveDist / 2;
|
|
207
|
+
centerX = centerX + centerMoveDist * Math.cos(radian);
|
|
208
|
+
centerY = centerY + centerMoveDist * Math.sin(radian);
|
|
209
|
+
}
|
|
210
|
+
else if (angle < 180) {
|
|
211
|
+
moveDist = changeMoveDistDirect(moveDist, moveY);
|
|
212
|
+
const radian = parseRadian(angle - 90);
|
|
213
|
+
const centerMoveDist = moveDist / 2;
|
|
214
|
+
centerX = centerX - centerMoveDist * Math.sin(radian);
|
|
215
|
+
centerY = centerY + centerMoveDist * Math.cos(radian);
|
|
216
|
+
}
|
|
217
|
+
else if (angle < 270) {
|
|
218
|
+
moveDist = changeMoveDistDirect(moveDist, moveY);
|
|
219
|
+
const radian = parseRadian(angle - 180);
|
|
220
|
+
const centerMoveDist = moveDist / 2;
|
|
221
|
+
centerX = centerX + centerMoveDist * Math.cos(radian);
|
|
222
|
+
centerY = centerY + centerMoveDist * Math.sin(radian);
|
|
223
|
+
moveDist = 0 - moveDist;
|
|
224
|
+
}
|
|
225
|
+
else if (angle < 360) {
|
|
226
|
+
moveDist = changeMoveDistDirect(moveDist, moveX);
|
|
227
|
+
const radian = parseRadian(angle - 270);
|
|
228
|
+
const centerMoveDist = moveDist / 2;
|
|
229
|
+
centerX = centerX + centerMoveDist * Math.sin(radian);
|
|
230
|
+
centerY = centerY - centerMoveDist * Math.cos(radian);
|
|
231
|
+
}
|
|
232
|
+
if (p.w + moveDist > 0) {
|
|
233
|
+
p.w = p.w + moveDist;
|
|
234
|
+
p.x = centerX - p.w / 2;
|
|
235
|
+
p.y = centerY - p.h / 2;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
if (elem.w + moveX > 0) {
|
|
240
|
+
p.w += moveX;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
break;
|
|
244
|
+
}
|
|
245
|
+
case 'bottom-right': {
|
|
246
|
+
if (elem.w + moveX > 0 && elem.h + moveY > 0) {
|
|
247
|
+
p.w += moveX;
|
|
248
|
+
p.h += moveY;
|
|
249
|
+
}
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
case 'bottom': {
|
|
253
|
+
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
254
|
+
if (elem.h + moveY > 0) {
|
|
255
|
+
p.h += moveY;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
else if (elem.angle > 0 || elem.angle < 0) {
|
|
259
|
+
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
260
|
+
let moveDist = calcMoveDist(moveX, moveY);
|
|
261
|
+
let centerX = p.x + elem.w / 2;
|
|
262
|
+
let centerY = p.y + elem.h / 2;
|
|
263
|
+
if (angle < 90) {
|
|
264
|
+
moveDist = changeMoveDistDirect(moveDist, moveY);
|
|
265
|
+
const radian = parseRadian(angle);
|
|
266
|
+
const centerMoveDist = moveDist / 2;
|
|
267
|
+
centerX = centerX - centerMoveDist * Math.sin(radian);
|
|
268
|
+
centerY = centerY + centerMoveDist * Math.cos(radian);
|
|
269
|
+
}
|
|
270
|
+
else if (angle < 180) {
|
|
271
|
+
moveDist = 0 - changeMoveDistDirect(moveDist, moveX);
|
|
272
|
+
const radian = parseRadian(angle - 90);
|
|
273
|
+
const centerMoveDist = moveDist / 2;
|
|
274
|
+
centerX = centerX - centerMoveDist * Math.cos(radian);
|
|
275
|
+
centerY = centerY - centerMoveDist * Math.sin(radian);
|
|
276
|
+
}
|
|
277
|
+
else if (angle < 270) {
|
|
278
|
+
moveDist = changeMoveDistDirect(moveDist, moveX);
|
|
279
|
+
const radian = parseRadian(angle - 180);
|
|
280
|
+
const centerMoveDist = moveDist / 2;
|
|
281
|
+
centerX = centerX + centerMoveDist * Math.sin(radian);
|
|
282
|
+
centerY = centerY - centerMoveDist * Math.cos(radian);
|
|
283
|
+
}
|
|
284
|
+
else if (angle < 360) {
|
|
285
|
+
moveDist = changeMoveDistDirect(moveDist, moveX);
|
|
286
|
+
const radian = parseRadian(angle - 270);
|
|
287
|
+
const centerMoveDist = moveDist / 2;
|
|
288
|
+
centerX = centerX + centerMoveDist * Math.cos(radian);
|
|
289
|
+
centerY = centerY + centerMoveDist * Math.sin(radian);
|
|
290
|
+
}
|
|
291
|
+
if (p.h + moveDist > 0) {
|
|
292
|
+
p.h = p.h + moveDist;
|
|
293
|
+
p.x = centerX - p.w / 2;
|
|
294
|
+
p.y = centerY - p.h / 2;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
if (elem.h + moveY > 0) {
|
|
299
|
+
p.h += moveY;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
case 'bottom-left': {
|
|
305
|
+
if (elem.w - moveX > 0 && elem.h + moveY > 0) {
|
|
306
|
+
p.x += moveX;
|
|
307
|
+
p.w -= moveX;
|
|
308
|
+
p.h += moveY;
|
|
309
|
+
}
|
|
310
|
+
break;
|
|
311
|
+
}
|
|
312
|
+
case 'left': {
|
|
313
|
+
if (elem.angle === 0 || Math.abs(elem.angle) < limitQbliqueAngle) {
|
|
314
|
+
if (elem.w - moveX > 0) {
|
|
315
|
+
p.x += moveX;
|
|
316
|
+
p.w -= moveX;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
else if (elem.angle > 0 || elem.angle < 0) {
|
|
320
|
+
const angle = elem.angle > 0 ? elem.angle : Math.max(0, elem.angle + 360);
|
|
321
|
+
let moveDist = calcMoveDist(moveX, moveY);
|
|
322
|
+
let centerX = p.x + elem.w / 2;
|
|
323
|
+
let centerY = p.y + elem.h / 2;
|
|
324
|
+
if (angle < 90) {
|
|
325
|
+
moveDist = 0 - changeMoveDistDirect(moveDist, moveX);
|
|
326
|
+
const radian = parseRadian(angle);
|
|
327
|
+
const centerMoveDist = moveDist / 2;
|
|
328
|
+
centerX = centerX - centerMoveDist * Math.cos(radian);
|
|
329
|
+
centerY = centerY - centerMoveDist * Math.sin(radian);
|
|
330
|
+
}
|
|
331
|
+
else if (angle < 180) {
|
|
332
|
+
moveDist = changeMoveDistDirect(moveDist, moveX);
|
|
333
|
+
const radian = parseRadian(angle - 90);
|
|
334
|
+
const centerMoveDist = moveDist / 2;
|
|
335
|
+
centerX = centerX + centerMoveDist * Math.sin(radian);
|
|
336
|
+
centerY = centerY - centerMoveDist * Math.cos(radian);
|
|
337
|
+
}
|
|
338
|
+
else if (angle < 270) {
|
|
339
|
+
moveDist = changeMoveDistDirect(moveDist, moveY);
|
|
340
|
+
const radian = parseRadian(angle - 180);
|
|
341
|
+
const centerMoveDist = moveDist / 2;
|
|
342
|
+
centerX = centerX + centerMoveDist * Math.cos(radian);
|
|
343
|
+
centerY = centerY + centerMoveDist * Math.sin(radian);
|
|
344
|
+
}
|
|
345
|
+
else if (angle < 360) {
|
|
346
|
+
moveDist = changeMoveDistDirect(moveDist, moveY);
|
|
347
|
+
const radian = parseRadian(angle - 270);
|
|
348
|
+
const centerMoveDist = moveDist / 2;
|
|
349
|
+
centerX = centerX - centerMoveDist * Math.sin(radian);
|
|
350
|
+
centerY = centerY + centerMoveDist * Math.cos(radian);
|
|
351
|
+
}
|
|
352
|
+
if (p.w + moveDist > 0) {
|
|
353
|
+
p.w = p.w + moveDist;
|
|
354
|
+
p.x = centerX - p.w / 2;
|
|
355
|
+
p.y = centerY - p.h / 2;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
if (elem.w - moveX > 0) {
|
|
360
|
+
p.x += moveX;
|
|
361
|
+
p.w -= moveX;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
default: {
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return p;
|
|
371
|
+
}
|
|
372
|
+
function parseRadian(angle) {
|
|
373
|
+
return angle * Math.PI / 180;
|
|
374
|
+
}
|
|
375
|
+
function calcMoveDist(moveX, moveY) {
|
|
376
|
+
return Math.sqrt(moveX * moveX + moveY * moveY);
|
|
377
|
+
}
|
|
378
|
+
function changeMoveDistDirect(moveDist, moveDirect) {
|
|
379
|
+
return moveDirect > 0 ? Math.abs(moveDist) : 0 - Math.abs(moveDist);
|
|
380
|
+
}
|