@idraw/core 0.4.0-beta.3 → 0.4.0-beta.31
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/config.d.ts +1 -0
- package/dist/esm/config.js +1 -0
- package/dist/esm/index.d.ts +17 -7
- package/dist/esm/index.js +31 -10
- package/dist/esm/lib/cursor-image.d.ts +1 -0
- package/dist/esm/lib/cursor-image.js +1 -0
- package/dist/esm/lib/cursor.d.ts +3 -12
- package/dist/esm/lib/cursor.js +136 -112
- package/dist/esm/middleware/dragger/index.d.ts +2 -2
- package/dist/esm/middleware/dragger/index.js +1 -0
- package/dist/esm/middleware/info/config.d.ts +4 -0
- package/dist/esm/middleware/info/config.js +8 -0
- package/dist/esm/middleware/info/draw-info.d.ts +29 -0
- package/dist/esm/middleware/info/draw-info.js +113 -0
- package/dist/esm/middleware/info/index.d.ts +3 -0
- package/dist/esm/middleware/info/index.js +112 -0
- package/dist/esm/middleware/info/types.d.ts +3 -0
- package/dist/esm/middleware/info/types.js +1 -0
- package/dist/esm/middleware/layout-selector/config.d.ts +9 -0
- package/dist/esm/middleware/layout-selector/config.js +9 -0
- package/dist/esm/middleware/layout-selector/index.d.ts +5 -0
- package/dist/esm/middleware/layout-selector/index.js +332 -0
- package/dist/esm/middleware/layout-selector/types.d.ts +15 -0
- package/dist/esm/middleware/layout-selector/types.js +2 -0
- package/dist/esm/middleware/layout-selector/util.d.ts +8 -0
- package/dist/esm/middleware/layout-selector/util.js +108 -0
- package/dist/esm/middleware/ruler/config.d.ts +7 -0
- package/dist/esm/middleware/ruler/config.js +21 -0
- package/dist/esm/middleware/ruler/index.d.ts +3 -2
- package/dist/esm/middleware/ruler/index.js +27 -11
- package/dist/esm/middleware/ruler/types.d.ts +3 -0
- package/dist/esm/middleware/ruler/types.js +1 -0
- package/dist/esm/middleware/ruler/util.d.ts +20 -4
- package/dist/esm/middleware/ruler/util.js +92 -21
- package/dist/esm/middleware/scaler/index.d.ts +2 -2
- package/dist/esm/middleware/scaler/index.js +1 -0
- package/dist/esm/middleware/scroller/config.d.ts +4 -0
- package/dist/esm/middleware/scroller/config.js +10 -0
- package/dist/esm/middleware/scroller/index.d.ts +3 -2
- package/dist/esm/middleware/scroller/index.js +44 -6
- package/dist/esm/middleware/scroller/types.d.ts +11 -0
- package/dist/esm/middleware/scroller/types.js +1 -0
- package/dist/esm/middleware/scroller/util.d.ts +3 -2
- package/dist/esm/middleware/scroller/util.js +32 -44
- package/dist/esm/middleware/selector/config.d.ts +11 -1
- package/dist/esm/middleware/selector/config.js +19 -1
- package/dist/esm/middleware/selector/draw-auxiliary.d.ts +1 -0
- package/dist/esm/middleware/selector/draw-auxiliary.js +12 -0
- package/dist/esm/middleware/selector/draw-base.d.ts +30 -0
- package/dist/esm/middleware/selector/draw-base.js +100 -0
- package/dist/esm/middleware/selector/draw-reference.d.ts +7 -0
- package/dist/esm/middleware/selector/draw-reference.js +31 -0
- package/dist/esm/middleware/selector/draw-wrapper.d.ts +16 -2
- package/dist/esm/middleware/selector/draw-wrapper.js +52 -35
- package/dist/esm/middleware/selector/index.d.ts +7 -4
- package/dist/esm/middleware/selector/index.js +287 -47
- package/dist/esm/middleware/selector/reference.d.ts +13 -0
- package/dist/esm/middleware/selector/reference.js +267 -0
- package/dist/esm/middleware/selector/types.d.ts +9 -4
- package/dist/esm/middleware/selector/types.js +2 -1
- package/dist/esm/middleware/selector/util.d.ts +11 -2
- package/dist/esm/middleware/selector/util.js +36 -14
- package/dist/esm/middleware/text-editor/index.d.ts +20 -2
- package/dist/esm/middleware/text-editor/index.js +92 -16
- package/dist/index.global.js +3827 -1006
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
|
|
2
|
-
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect } from './config';
|
|
3
|
-
const minScrollerWidth = 12;
|
|
2
|
+
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
4
3
|
const scrollerLineWidth = 16;
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
thumbColor: '#000000AA',
|
|
9
|
-
scrollBarColor: '#FFFFFF60',
|
|
10
|
-
showScrollBar: false
|
|
11
|
-
};
|
|
12
|
-
function isPointAtRect(helperContext, p, rect) {
|
|
13
|
-
const ctx = helperContext;
|
|
4
|
+
const minThumbLength = scrollerLineWidth * 2.5;
|
|
5
|
+
function isPointAtRect(overlayContext, p, rect) {
|
|
6
|
+
const ctx = overlayContext;
|
|
14
7
|
const { x, y, w, h } = rect;
|
|
15
8
|
ctx.beginPath();
|
|
16
9
|
ctx.rect(x, y, w, h);
|
|
@@ -20,13 +13,13 @@ function isPointAtRect(helperContext, p, rect) {
|
|
|
20
13
|
}
|
|
21
14
|
return false;
|
|
22
15
|
}
|
|
23
|
-
export function isPointInScrollThumb(
|
|
16
|
+
export function isPointInScrollThumb(overlayContext, p, opts) {
|
|
24
17
|
let thumbType = null;
|
|
25
18
|
const { xThumbRect, yThumbRect } = opts;
|
|
26
|
-
if (xThumbRect && isPointAtRect(
|
|
19
|
+
if (xThumbRect && isPointAtRect(overlayContext, p, xThumbRect)) {
|
|
27
20
|
thumbType = 'X';
|
|
28
21
|
}
|
|
29
|
-
else if (yThumbRect && isPointAtRect(
|
|
22
|
+
else if (yThumbRect && isPointAtRect(overlayContext, p, yThumbRect)) {
|
|
30
23
|
thumbType = 'Y';
|
|
31
24
|
}
|
|
32
25
|
return thumbType;
|
|
@@ -38,15 +31,19 @@ function getScrollInfoFromSnapshot(snapshot) {
|
|
|
38
31
|
prevPoint: sharedStore[keyPrevPoint] || null,
|
|
39
32
|
activeThumbType: sharedStore[keyActiveThumbType] || null,
|
|
40
33
|
xThumbRect: sharedStore[keyXThumbRect] || null,
|
|
41
|
-
yThumbRect: sharedStore[keyYThumbRect] || null
|
|
34
|
+
yThumbRect: sharedStore[keyYThumbRect] || null,
|
|
35
|
+
hoverXThumb: sharedStore[keyHoverXThumbRect],
|
|
36
|
+
hoverYThumb: sharedStore[keyHoverYThumbRect]
|
|
42
37
|
};
|
|
43
38
|
return info;
|
|
44
39
|
}
|
|
45
|
-
function calcScrollerInfo(
|
|
40
|
+
function calcScrollerInfo(opts) {
|
|
41
|
+
const { viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb, style } = opts;
|
|
46
42
|
const { width, height } = viewSizeInfo;
|
|
47
43
|
const { offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo;
|
|
48
|
-
const sliderMinSize =
|
|
44
|
+
const sliderMinSize = minThumbLength;
|
|
49
45
|
const lineSize = scrollerLineWidth;
|
|
46
|
+
const { thumbBackground, thumbBorderColor, hoverThumbBackground, hoverThumbBorderColor } = style;
|
|
50
47
|
let xSize = 0;
|
|
51
48
|
let ySize = 0;
|
|
52
49
|
xSize = Math.max(sliderMinSize, width - lineSize * 2 - (Math.abs(offsetLeft) + Math.abs(offsetRight)));
|
|
@@ -101,22 +98,24 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
101
98
|
ySize,
|
|
102
99
|
translateY,
|
|
103
100
|
translateX,
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
xThumbBackground: hoverXThumb ? hoverThumbBackground : thumbBackground,
|
|
102
|
+
yThumbBackground: hoverYThumb ? hoverThumbBackground : thumbBackground,
|
|
103
|
+
xThumbBorderColor: hoverXThumb ? hoverThumbBorderColor : thumbBorderColor,
|
|
104
|
+
yThumbBorderColor: hoverYThumb ? hoverThumbBorderColor : thumbBorderColor,
|
|
106
105
|
xThumbRect,
|
|
107
106
|
yThumbRect
|
|
108
107
|
};
|
|
109
108
|
return scrollWrapper;
|
|
110
109
|
}
|
|
111
110
|
function drawScrollerThumb(ctx, opts) {
|
|
112
|
-
let { x, y, h, w } = opts;
|
|
111
|
+
let { x, y, h, w, background, borderColor } = opts;
|
|
113
112
|
ctx.save();
|
|
114
113
|
ctx.shadowColor = '#FFFFFF';
|
|
115
114
|
ctx.shadowOffsetX = 0;
|
|
116
115
|
ctx.shadowOffsetY = 0;
|
|
117
116
|
ctx.shadowBlur = 1;
|
|
118
117
|
{
|
|
119
|
-
const {
|
|
118
|
+
const { axis } = opts;
|
|
120
119
|
if (axis === 'X') {
|
|
121
120
|
y = y + h / 4 + 0;
|
|
122
121
|
h = h / 2;
|
|
@@ -130,7 +129,7 @@ function drawScrollerThumb(ctx, opts) {
|
|
|
130
129
|
if (w < r * 2 || h < r * 2) {
|
|
131
130
|
r = 0;
|
|
132
131
|
}
|
|
133
|
-
ctx.globalAlpha =
|
|
132
|
+
ctx.globalAlpha = 1;
|
|
134
133
|
ctx.beginPath();
|
|
135
134
|
ctx.moveTo(x + r, y);
|
|
136
135
|
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
@@ -138,12 +137,11 @@ function drawScrollerThumb(ctx, opts) {
|
|
|
138
137
|
ctx.arcTo(x, y + h, x, y, r);
|
|
139
138
|
ctx.arcTo(x, y, x + w, y, r);
|
|
140
139
|
ctx.closePath();
|
|
141
|
-
ctx.fillStyle =
|
|
140
|
+
ctx.fillStyle = background;
|
|
142
141
|
ctx.fill();
|
|
143
|
-
ctx.globalAlpha = 1;
|
|
144
142
|
ctx.beginPath();
|
|
145
143
|
ctx.lineWidth = 1;
|
|
146
|
-
ctx.strokeStyle =
|
|
144
|
+
ctx.strokeStyle = borderColor;
|
|
147
145
|
ctx.setLineDash([]);
|
|
148
146
|
ctx.moveTo(x + r, y);
|
|
149
147
|
ctx.arcTo(x + w, y, x + w, y + h, r);
|
|
@@ -155,12 +153,11 @@ function drawScrollerThumb(ctx, opts) {
|
|
|
155
153
|
}
|
|
156
154
|
ctx.restore();
|
|
157
155
|
}
|
|
158
|
-
function drawScrollerInfo(
|
|
159
|
-
const ctx =
|
|
160
|
-
const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
|
|
161
|
-
const { activeThumbType, prevPoint, activePoint } = scrollInfo;
|
|
162
|
-
const {
|
|
163
|
-
const wrapper = calcScrollerInfo(viewScaleInfo, viewSizeInfo);
|
|
156
|
+
function drawScrollerInfo(overlayContext, opts) {
|
|
157
|
+
const ctx = overlayContext;
|
|
158
|
+
const { viewScaleInfo, viewSizeInfo, scrollInfo, style } = opts;
|
|
159
|
+
const { activeThumbType, prevPoint, activePoint, hoverXThumb, hoverYThumb } = scrollInfo;
|
|
160
|
+
const wrapper = calcScrollerInfo({ viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb, style });
|
|
164
161
|
let xThumbRect = Object.assign({}, wrapper.xThumbRect);
|
|
165
162
|
let yThumbRect = Object.assign({}, wrapper.yThumbRect);
|
|
166
163
|
if (activeThumbType && prevPoint && activePoint) {
|
|
@@ -173,27 +170,18 @@ function drawScrollerInfo(helperContext, opts) {
|
|
|
173
170
|
yThumbRect.y = yThumbRect.y + (activePoint.y - prevPoint.y);
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
ctx.fillRect(0, height - wrapper.lineSize, width, wrapper.lineSize);
|
|
179
|
-
}
|
|
180
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.thumbColor }));
|
|
181
|
-
if (scrollConfig.showScrollBar === true) {
|
|
182
|
-
ctx.fillStyle = wrapper.scrollBarColor;
|
|
183
|
-
ctx.fillRect(width - wrapper.lineSize, 0, wrapper.lineSize, height);
|
|
184
|
-
}
|
|
185
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.thumbColor }));
|
|
186
|
-
ctx.globalAlpha = 1;
|
|
173
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, background: wrapper.xThumbBackground, borderColor: wrapper.xThumbBorderColor }));
|
|
174
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, background: wrapper.yThumbBackground, borderColor: wrapper.yThumbBorderColor }));
|
|
187
175
|
return {
|
|
188
176
|
xThumbRect,
|
|
189
177
|
yThumbRect
|
|
190
178
|
};
|
|
191
179
|
}
|
|
192
180
|
export function drawScroller(ctx, opts) {
|
|
193
|
-
const { snapshot } = opts;
|
|
181
|
+
const { snapshot, style } = opts;
|
|
194
182
|
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
195
183
|
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
196
184
|
const scrollInfo = getScrollInfoFromSnapshot(snapshot);
|
|
197
|
-
const { xThumbRect, yThumbRect } = drawScrollerInfo(ctx, { viewSizeInfo, viewScaleInfo, scrollInfo });
|
|
185
|
+
const { xThumbRect, yThumbRect } = drawScrollerInfo(ctx, { viewSizeInfo, viewScaleInfo, scrollInfo, style });
|
|
198
186
|
return { xThumbRect, yThumbRect };
|
|
199
187
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MiddlewareSelectorStyle } from '@idraw/types';
|
|
1
2
|
export declare const key = "SELECT";
|
|
2
3
|
export declare const keyActionType: unique symbol;
|
|
3
4
|
export declare const keyResizeType: unique symbol;
|
|
@@ -8,8 +9,12 @@ export declare const keyHoverElementVertexes: unique symbol;
|
|
|
8
9
|
export declare const keySelectedElementList: unique symbol;
|
|
9
10
|
export declare const keySelectedElementListVertexes: unique symbol;
|
|
10
11
|
export declare const keySelectedElementController: unique symbol;
|
|
12
|
+
export declare const keySelectedElementPosition: unique symbol;
|
|
11
13
|
export declare const keyGroupQueue: unique symbol;
|
|
12
14
|
export declare const keyGroupQueueVertexesList: unique symbol;
|
|
15
|
+
export declare const keyIsMoving: unique symbol;
|
|
16
|
+
export declare const keyEnableSelectInGroup: unique symbol;
|
|
17
|
+
export declare const keyEnableSnapToGrid: unique symbol;
|
|
13
18
|
export declare const keyDebugElemCenter: unique symbol;
|
|
14
19
|
export declare const keyDebugStartVertical: unique symbol;
|
|
15
20
|
export declare const keyDebugEndVertical: unique symbol;
|
|
@@ -19,4 +24,9 @@ export declare const keyDebugEnd0: unique symbol;
|
|
|
19
24
|
export declare const selectWrapperBorderWidth = 2;
|
|
20
25
|
export declare const resizeControllerBorderWidth = 4;
|
|
21
26
|
export declare const areaBorderWidth = 1;
|
|
22
|
-
export declare const
|
|
27
|
+
export declare const controllerSize = 10;
|
|
28
|
+
export declare const defaultStyle: MiddlewareSelectorStyle;
|
|
29
|
+
export declare const middlewareEventSelect: string;
|
|
30
|
+
export declare const middlewareEventSelectClear: string;
|
|
31
|
+
export declare const middlewareEventSelectInGroup: string;
|
|
32
|
+
export declare const middlewareEventSnapToGrid: string;
|
|
@@ -8,8 +8,12 @@ export const keyHoverElementVertexes = Symbol(`${key}_hoverElementVertexes`);
|
|
|
8
8
|
export const keySelectedElementList = Symbol(`${key}_selectedElementList`);
|
|
9
9
|
export const keySelectedElementListVertexes = Symbol(`${key}_selectedElementListVertexes`);
|
|
10
10
|
export const keySelectedElementController = Symbol(`${key}_selectedElementController`);
|
|
11
|
+
export const keySelectedElementPosition = Symbol(`${key}_selectedElementPosition`);
|
|
11
12
|
export const keyGroupQueue = Symbol(`${key}_groupQueue`);
|
|
12
13
|
export const keyGroupQueueVertexesList = Symbol(`${key}_groupQueueVertexesList`);
|
|
14
|
+
export const keyIsMoving = Symbol(`${key}_isMoving`);
|
|
15
|
+
export const keyEnableSelectInGroup = Symbol(`${key}_enableSelectInGroup`);
|
|
16
|
+
export const keyEnableSnapToGrid = Symbol(`${key}_enableSnapToGrid`);
|
|
13
17
|
export const keyDebugElemCenter = Symbol(`${key}_debug_elemCenter`);
|
|
14
18
|
export const keyDebugStartVertical = Symbol(`${key}_debug_startVertical`);
|
|
15
19
|
export const keyDebugEndVertical = Symbol(`${key}_debug_endVertical`);
|
|
@@ -19,4 +23,18 @@ export const keyDebugEnd0 = Symbol(`${key}_debug_end0`);
|
|
|
19
23
|
export const selectWrapperBorderWidth = 2;
|
|
20
24
|
export const resizeControllerBorderWidth = 4;
|
|
21
25
|
export const areaBorderWidth = 1;
|
|
22
|
-
export const
|
|
26
|
+
export const controllerSize = 10;
|
|
27
|
+
const activeColor = '#1973ba';
|
|
28
|
+
const activeAreaColor = '#1976d21c';
|
|
29
|
+
const lockedColor = '#5b5959b5';
|
|
30
|
+
const referenceColor = '#f7276e';
|
|
31
|
+
export const defaultStyle = {
|
|
32
|
+
activeColor,
|
|
33
|
+
activeAreaColor,
|
|
34
|
+
lockedColor,
|
|
35
|
+
referenceColor
|
|
36
|
+
};
|
|
37
|
+
export const middlewareEventSelect = '@middleware/select';
|
|
38
|
+
export const middlewareEventSelectClear = '@middleware/select-clear';
|
|
39
|
+
export const middlewareEventSelectInGroup = '@middleware/select-in-group';
|
|
40
|
+
export const middlewareEventSnapToGrid = '@middleware/snap-to-grid';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function getViewBoxInfo(rectInfo) {
|
|
2
|
+
const boxInfo = {
|
|
3
|
+
minX: rectInfo.topLeft.x,
|
|
4
|
+
minY: rectInfo.topLeft.y,
|
|
5
|
+
maxX: rectInfo.bottomRight.x,
|
|
6
|
+
maxY: rectInfo.bottomRight.y,
|
|
7
|
+
midX: rectInfo.center.x,
|
|
8
|
+
midY: rectInfo.center.y
|
|
9
|
+
};
|
|
10
|
+
return boxInfo;
|
|
11
|
+
}
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { PointSize, ViewContext2D, ViewRectVertexes } from '@idraw/types';
|
|
2
|
+
export declare function drawVertexes(ctx: ViewContext2D, vertexes: ViewRectVertexes, opts: {
|
|
3
|
+
borderColor: string;
|
|
4
|
+
borderWidth: number;
|
|
5
|
+
background: string;
|
|
6
|
+
lineDash: number[];
|
|
7
|
+
}): void;
|
|
8
|
+
export declare function drawLine(ctx: ViewContext2D, start: PointSize, end: PointSize, opts: {
|
|
9
|
+
borderColor: string;
|
|
10
|
+
borderWidth: number;
|
|
11
|
+
lineDash: number[];
|
|
12
|
+
}): void;
|
|
13
|
+
export declare function drawCircleController(ctx: ViewContext2D, circleCenter: PointSize, opts: {
|
|
14
|
+
borderColor: string;
|
|
15
|
+
borderWidth: number;
|
|
16
|
+
background: string;
|
|
17
|
+
lineDash: number[];
|
|
18
|
+
size: number;
|
|
19
|
+
}): void;
|
|
20
|
+
export declare function drawCrossVertexes(ctx: ViewContext2D, vertexes: ViewRectVertexes, opts: {
|
|
21
|
+
borderColor: string;
|
|
22
|
+
borderWidth: number;
|
|
23
|
+
lineDash: number[];
|
|
24
|
+
}): void;
|
|
25
|
+
export declare function drawCrossByCenter(ctx: ViewContext2D, center: PointSize, opts: {
|
|
26
|
+
size: number;
|
|
27
|
+
borderColor: string;
|
|
28
|
+
borderWidth: number;
|
|
29
|
+
lineDash: number[];
|
|
30
|
+
}): void;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export function drawVertexes(ctx, vertexes, opts) {
|
|
2
|
+
const { borderColor, borderWidth, background, lineDash } = opts;
|
|
3
|
+
ctx.setLineDash([]);
|
|
4
|
+
ctx.lineWidth = borderWidth;
|
|
5
|
+
ctx.strokeStyle = borderColor;
|
|
6
|
+
ctx.fillStyle = background;
|
|
7
|
+
ctx.setLineDash(lineDash);
|
|
8
|
+
ctx.beginPath();
|
|
9
|
+
ctx.moveTo(vertexes[0].x, vertexes[0].y);
|
|
10
|
+
ctx.lineTo(vertexes[1].x, vertexes[1].y);
|
|
11
|
+
ctx.lineTo(vertexes[2].x, vertexes[2].y);
|
|
12
|
+
ctx.lineTo(vertexes[3].x, vertexes[3].y);
|
|
13
|
+
ctx.lineTo(vertexes[0].x, vertexes[0].y);
|
|
14
|
+
ctx.closePath();
|
|
15
|
+
ctx.stroke();
|
|
16
|
+
ctx.fill();
|
|
17
|
+
}
|
|
18
|
+
export function drawLine(ctx, start, end, opts) {
|
|
19
|
+
const { borderColor, borderWidth, lineDash } = opts;
|
|
20
|
+
ctx.setLineDash([]);
|
|
21
|
+
ctx.lineWidth = borderWidth;
|
|
22
|
+
ctx.strokeStyle = borderColor;
|
|
23
|
+
ctx.setLineDash(lineDash);
|
|
24
|
+
ctx.beginPath();
|
|
25
|
+
ctx.moveTo(start.x, start.y);
|
|
26
|
+
ctx.lineTo(end.x, end.y);
|
|
27
|
+
ctx.closePath();
|
|
28
|
+
ctx.stroke();
|
|
29
|
+
}
|
|
30
|
+
export function drawCircleController(ctx, circleCenter, opts) {
|
|
31
|
+
const { size, borderColor, borderWidth, background } = opts;
|
|
32
|
+
const center = circleCenter;
|
|
33
|
+
const r = size / 2;
|
|
34
|
+
const a = r;
|
|
35
|
+
const b = r;
|
|
36
|
+
if (a >= 0 && b >= 0) {
|
|
37
|
+
if (typeof borderWidth === 'number' && borderWidth > 0) {
|
|
38
|
+
const ba = borderWidth / 2 + a;
|
|
39
|
+
const bb = borderWidth / 2 + b;
|
|
40
|
+
ctx.beginPath();
|
|
41
|
+
ctx.strokeStyle = borderColor;
|
|
42
|
+
ctx.lineWidth = borderWidth;
|
|
43
|
+
ctx.circle(center.x, center.y, ba, bb, 0, 0, 2 * Math.PI);
|
|
44
|
+
ctx.closePath();
|
|
45
|
+
ctx.stroke();
|
|
46
|
+
}
|
|
47
|
+
ctx.beginPath();
|
|
48
|
+
ctx.fillStyle = background;
|
|
49
|
+
ctx.circle(center.x, center.y, a, b, 0, 0, 2 * Math.PI);
|
|
50
|
+
ctx.closePath();
|
|
51
|
+
ctx.fill();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
export function drawCrossVertexes(ctx, vertexes, opts) {
|
|
55
|
+
const { borderColor, borderWidth, lineDash } = opts;
|
|
56
|
+
ctx.setLineDash([]);
|
|
57
|
+
ctx.lineWidth = borderWidth;
|
|
58
|
+
ctx.strokeStyle = borderColor;
|
|
59
|
+
ctx.setLineDash(lineDash);
|
|
60
|
+
ctx.beginPath();
|
|
61
|
+
ctx.moveTo(vertexes[0].x, vertexes[0].y);
|
|
62
|
+
ctx.lineTo(vertexes[2].x, vertexes[2].y);
|
|
63
|
+
ctx.closePath();
|
|
64
|
+
ctx.stroke();
|
|
65
|
+
ctx.beginPath();
|
|
66
|
+
ctx.moveTo(vertexes[1].x, vertexes[1].y);
|
|
67
|
+
ctx.lineTo(vertexes[3].x, vertexes[3].y);
|
|
68
|
+
ctx.closePath();
|
|
69
|
+
ctx.stroke();
|
|
70
|
+
}
|
|
71
|
+
export function drawCrossByCenter(ctx, center, opts) {
|
|
72
|
+
const { size, borderColor, borderWidth, lineDash } = opts;
|
|
73
|
+
const minX = center.x - size / 2;
|
|
74
|
+
const maxX = center.x + size / 2;
|
|
75
|
+
const minY = center.y - size / 2;
|
|
76
|
+
const maxY = center.y + size / 2;
|
|
77
|
+
const vertexes = [
|
|
78
|
+
{
|
|
79
|
+
x: minX,
|
|
80
|
+
y: minY
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
x: maxX,
|
|
84
|
+
y: minY
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
x: maxX,
|
|
88
|
+
y: maxY
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
x: minX,
|
|
92
|
+
y: maxY
|
|
93
|
+
}
|
|
94
|
+
];
|
|
95
|
+
drawCrossVertexes(ctx, vertexes, {
|
|
96
|
+
borderColor,
|
|
97
|
+
borderWidth,
|
|
98
|
+
lineDash
|
|
99
|
+
});
|
|
100
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ViewContext2D, PointSize } from '@idraw/types';
|
|
2
|
+
import { MiddlewareSelectorStyle } from './types';
|
|
3
|
+
export declare function drawReferenceLines(ctx: ViewContext2D, opts: {
|
|
4
|
+
xLines?: Array<PointSize[]>;
|
|
5
|
+
yLines?: Array<PointSize[]>;
|
|
6
|
+
style: MiddlewareSelectorStyle;
|
|
7
|
+
}): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { drawLine, drawCrossByCenter } from './draw-base';
|
|
2
|
+
export function drawReferenceLines(ctx, opts) {
|
|
3
|
+
const { xLines, yLines, style } = opts;
|
|
4
|
+
const { referenceColor } = style;
|
|
5
|
+
const lineOpts = {
|
|
6
|
+
borderColor: referenceColor,
|
|
7
|
+
borderWidth: 1,
|
|
8
|
+
lineDash: []
|
|
9
|
+
};
|
|
10
|
+
const crossOpts = Object.assign(Object.assign({}, lineOpts), { size: 6 });
|
|
11
|
+
if (xLines) {
|
|
12
|
+
xLines.forEach((line) => {
|
|
13
|
+
line.forEach((p, pIdx) => {
|
|
14
|
+
drawCrossByCenter(ctx, p, crossOpts);
|
|
15
|
+
if (line[pIdx + 1]) {
|
|
16
|
+
drawLine(ctx, line[pIdx], line[pIdx + 1], lineOpts);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (yLines) {
|
|
22
|
+
yLines.forEach((line) => {
|
|
23
|
+
line.forEach((p, pIdx) => {
|
|
24
|
+
drawCrossByCenter(ctx, p, crossOpts);
|
|
25
|
+
if (line[pIdx + 1]) {
|
|
26
|
+
drawLine(ctx, line[pIdx], line[pIdx + 1], lineOpts);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -1,22 +1,36 @@
|
|
|
1
|
-
import type { Element, ElementType, PointSize, RendererDrawElementOptions, ViewContext2D, ViewRectVertexes, ViewScaleInfo, ViewSizeInfo, ElementSizeController } from '@idraw/types';
|
|
2
|
-
import type { AreaSize } from './types';
|
|
1
|
+
import type { Element, ElementType, PointSize, RendererDrawElementOptions, ViewContext2D, ViewRectVertexes, ViewScaleInfo, ViewSizeInfo, ElementSizeController, ViewCalculator } from '@idraw/types';
|
|
2
|
+
import type { AreaSize, MiddlewareSelectorStyle } from './types';
|
|
3
3
|
export declare function drawHoverVertexesWrapper(ctx: ViewContext2D, vertexes: ViewRectVertexes | null, opts: {
|
|
4
4
|
viewScaleInfo: ViewScaleInfo;
|
|
5
5
|
viewSizeInfo: ViewSizeInfo;
|
|
6
|
+
style: MiddlewareSelectorStyle;
|
|
7
|
+
}): void;
|
|
8
|
+
export declare function drawLockVertexesWrapper(ctx: ViewContext2D, vertexes: ViewRectVertexes | null, opts: {
|
|
9
|
+
viewScaleInfo: ViewScaleInfo;
|
|
10
|
+
viewSizeInfo: ViewSizeInfo;
|
|
11
|
+
controller?: ElementSizeController | null;
|
|
12
|
+
style: MiddlewareSelectorStyle;
|
|
6
13
|
}): void;
|
|
7
14
|
export declare function drawSelectedElementControllersVertexes(ctx: ViewContext2D, controller: ElementSizeController | null, opts: {
|
|
15
|
+
hideControllers: boolean;
|
|
8
16
|
viewScaleInfo: ViewScaleInfo;
|
|
9
17
|
viewSizeInfo: ViewSizeInfo;
|
|
18
|
+
element: Element | null;
|
|
19
|
+
calculator: ViewCalculator;
|
|
20
|
+
style: MiddlewareSelectorStyle;
|
|
10
21
|
}): void;
|
|
11
22
|
export declare function drawElementListShadows(ctx: ViewContext2D, elements: Element<ElementType>[], opts?: Omit<RendererDrawElementOptions, 'loader'>): void;
|
|
12
23
|
export declare function drawArea(ctx: ViewContext2D, opts: {
|
|
13
24
|
start: PointSize;
|
|
14
25
|
end: PointSize;
|
|
26
|
+
style: MiddlewareSelectorStyle;
|
|
15
27
|
}): void;
|
|
16
28
|
export declare function drawListArea(ctx: ViewContext2D, opts: {
|
|
17
29
|
areaSize: AreaSize;
|
|
30
|
+
style: MiddlewareSelectorStyle;
|
|
18
31
|
}): void;
|
|
19
32
|
export declare function drawGroupQueueVertexesWrappers(ctx: ViewContext2D, vertexesList: ViewRectVertexes[], opts: {
|
|
20
33
|
viewScaleInfo: ViewScaleInfo;
|
|
21
34
|
viewSizeInfo: ViewSizeInfo;
|
|
35
|
+
style: MiddlewareSelectorStyle;
|
|
22
36
|
}): void;
|
|
@@ -1,49 +1,62 @@
|
|
|
1
|
-
import { rotateElementVertexes, calcViewVertexes } from '@idraw/util';
|
|
2
|
-
import { resizeControllerBorderWidth, areaBorderWidth,
|
|
3
|
-
|
|
4
|
-
const { borderColor, borderWidth, background, lineDash } = opts;
|
|
5
|
-
ctx.setLineDash([]);
|
|
6
|
-
ctx.lineWidth = borderWidth;
|
|
7
|
-
ctx.strokeStyle = borderColor;
|
|
8
|
-
ctx.fillStyle = background;
|
|
9
|
-
ctx.setLineDash(lineDash);
|
|
10
|
-
ctx.beginPath();
|
|
11
|
-
ctx.moveTo(vertexes[0].x, vertexes[0].y);
|
|
12
|
-
ctx.lineTo(vertexes[1].x, vertexes[1].y);
|
|
13
|
-
ctx.lineTo(vertexes[2].x, vertexes[2].y);
|
|
14
|
-
ctx.lineTo(vertexes[3].x, vertexes[3].y);
|
|
15
|
-
ctx.lineTo(vertexes[0].x, vertexes[0].y);
|
|
16
|
-
ctx.closePath();
|
|
17
|
-
ctx.stroke();
|
|
18
|
-
ctx.fill();
|
|
19
|
-
}
|
|
1
|
+
import { rotateElementVertexes, calcViewPointSize, calcViewVertexes, calcViewElementSize } from '@idraw/util';
|
|
2
|
+
import { resizeControllerBorderWidth, areaBorderWidth, selectWrapperBorderWidth, controllerSize } from './config';
|
|
3
|
+
import { drawVertexes, drawLine, drawCircleController, drawCrossVertexes } from './draw-base';
|
|
20
4
|
export function drawHoverVertexesWrapper(ctx, vertexes, opts) {
|
|
21
5
|
if (!vertexes) {
|
|
22
6
|
return;
|
|
23
7
|
}
|
|
24
|
-
const
|
|
8
|
+
const { style } = opts;
|
|
9
|
+
const { activeColor } = style;
|
|
10
|
+
const wrapperOpts = { borderColor: activeColor, borderWidth: 1, background: 'transparent', lineDash: [] };
|
|
25
11
|
drawVertexes(ctx, calcViewVertexes(vertexes, opts), wrapperOpts);
|
|
26
12
|
}
|
|
13
|
+
export function drawLockVertexesWrapper(ctx, vertexes, opts) {
|
|
14
|
+
if (!vertexes) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const { style } = opts;
|
|
18
|
+
const { lockedColor } = style;
|
|
19
|
+
const wrapperOpts = { borderColor: lockedColor, borderWidth: 1, background: 'transparent', lineDash: [] };
|
|
20
|
+
drawVertexes(ctx, calcViewVertexes(vertexes, opts), wrapperOpts);
|
|
21
|
+
const { controller } = opts;
|
|
22
|
+
if (controller) {
|
|
23
|
+
const { topLeft, topRight, bottomLeft, bottomRight, topMiddle, bottomMiddle, leftMiddle, rightMiddle } = controller;
|
|
24
|
+
const ctrlOpts = Object.assign(Object.assign({}, wrapperOpts), { borderWidth: 1, background: lockedColor });
|
|
25
|
+
drawCrossVertexes(ctx, calcViewVertexes(topMiddle.vertexes, opts), ctrlOpts);
|
|
26
|
+
drawCrossVertexes(ctx, calcViewVertexes(bottomMiddle.vertexes, opts), ctrlOpts);
|
|
27
|
+
drawCrossVertexes(ctx, calcViewVertexes(leftMiddle.vertexes, opts), ctrlOpts);
|
|
28
|
+
drawCrossVertexes(ctx, calcViewVertexes(rightMiddle.vertexes, opts), ctrlOpts);
|
|
29
|
+
drawCrossVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
|
|
30
|
+
drawCrossVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
|
|
31
|
+
drawCrossVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
|
|
32
|
+
drawCrossVertexes(ctx, calcViewVertexes(bottomRight.vertexes, opts), ctrlOpts);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
27
35
|
export function drawSelectedElementControllersVertexes(ctx, controller, opts) {
|
|
28
36
|
if (!controller) {
|
|
29
37
|
return;
|
|
30
38
|
}
|
|
31
|
-
const {
|
|
32
|
-
const
|
|
39
|
+
const { hideControllers, style } = opts;
|
|
40
|
+
const { activeColor } = style;
|
|
41
|
+
const { elementWrapper, topLeft, topRight, bottomLeft, bottomRight, top, rotate } = controller;
|
|
42
|
+
const wrapperOpts = { borderColor: activeColor, borderWidth: selectWrapperBorderWidth, background: 'transparent', lineDash: [] };
|
|
33
43
|
const ctrlOpts = Object.assign(Object.assign({}, wrapperOpts), { borderWidth: resizeControllerBorderWidth, background: '#FFFFFF' });
|
|
34
44
|
drawVertexes(ctx, calcViewVertexes(elementWrapper, opts), wrapperOpts);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
if (!hideControllers) {
|
|
46
|
+
drawLine(ctx, calcViewPointSize(top.center, opts), calcViewPointSize(rotate.center, opts), Object.assign(Object.assign({}, ctrlOpts), { borderWidth: 2 }));
|
|
47
|
+
drawVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
|
|
48
|
+
drawVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
|
|
49
|
+
drawVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
|
|
50
|
+
drawVertexes(ctx, calcViewVertexes(bottomRight.vertexes, opts), ctrlOpts);
|
|
51
|
+
drawCircleController(ctx, calcViewPointSize(rotate.center, opts), Object.assign(Object.assign({}, ctrlOpts), { size: controllerSize, borderWidth: 2 }));
|
|
52
|
+
}
|
|
39
53
|
}
|
|
40
54
|
export function drawElementListShadows(ctx, elements, opts) {
|
|
41
55
|
elements.forEach((elem) => {
|
|
42
56
|
let { x, y, w, h } = elem;
|
|
43
57
|
const { angle = 0 } = elem;
|
|
44
58
|
if (opts === null || opts === void 0 ? void 0 : opts.calculator) {
|
|
45
|
-
const {
|
|
46
|
-
const size = calculator.elementSize({ x, y, w, h }, opts.viewScaleInfo, opts.viewSizeInfo);
|
|
59
|
+
const size = calcViewElementSize({ x, y, w, h }, opts);
|
|
47
60
|
x = size.x;
|
|
48
61
|
y = size.y;
|
|
49
62
|
w = size.w;
|
|
@@ -68,11 +81,12 @@ export function drawElementListShadows(ctx, elements, opts) {
|
|
|
68
81
|
});
|
|
69
82
|
}
|
|
70
83
|
export function drawArea(ctx, opts) {
|
|
71
|
-
const { start, end } = opts;
|
|
84
|
+
const { start, end, style } = opts;
|
|
85
|
+
const { activeColor, activeAreaColor } = style;
|
|
72
86
|
ctx.setLineDash([]);
|
|
73
87
|
ctx.lineWidth = areaBorderWidth;
|
|
74
|
-
ctx.strokeStyle =
|
|
75
|
-
ctx.fillStyle =
|
|
88
|
+
ctx.strokeStyle = activeColor;
|
|
89
|
+
ctx.fillStyle = activeAreaColor;
|
|
76
90
|
ctx.beginPath();
|
|
77
91
|
ctx.moveTo(start.x, start.y);
|
|
78
92
|
ctx.lineTo(end.x, start.y);
|
|
@@ -83,12 +97,13 @@ export function drawArea(ctx, opts) {
|
|
|
83
97
|
ctx.fill();
|
|
84
98
|
}
|
|
85
99
|
export function drawListArea(ctx, opts) {
|
|
86
|
-
const { areaSize } = opts;
|
|
100
|
+
const { areaSize, style } = opts;
|
|
101
|
+
const { activeColor, activeAreaColor } = style;
|
|
87
102
|
const { x, y, w, h } = areaSize;
|
|
88
103
|
ctx.setLineDash([]);
|
|
89
104
|
ctx.lineWidth = areaBorderWidth;
|
|
90
|
-
ctx.strokeStyle =
|
|
91
|
-
ctx.fillStyle =
|
|
105
|
+
ctx.strokeStyle = activeColor;
|
|
106
|
+
ctx.fillStyle = activeAreaColor;
|
|
92
107
|
ctx.beginPath();
|
|
93
108
|
ctx.moveTo(x, y);
|
|
94
109
|
ctx.lineTo(x + w, y);
|
|
@@ -99,9 +114,11 @@ export function drawListArea(ctx, opts) {
|
|
|
99
114
|
ctx.fill();
|
|
100
115
|
}
|
|
101
116
|
export function drawGroupQueueVertexesWrappers(ctx, vertexesList, opts) {
|
|
117
|
+
const { style } = opts;
|
|
118
|
+
const { activeColor } = style;
|
|
102
119
|
for (let i = 0; i < vertexesList.length; i++) {
|
|
103
120
|
const vertexes = vertexesList[i];
|
|
104
|
-
const wrapperOpts = { borderColor:
|
|
121
|
+
const wrapperOpts = { borderColor: activeColor, borderWidth: selectWrapperBorderWidth, background: 'transparent', lineDash: [4, 4] };
|
|
105
122
|
drawVertexes(ctx, calcViewVertexes(vertexes, opts), wrapperOpts);
|
|
106
123
|
}
|
|
107
124
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BoardMiddleware, DeepSelectorSharedStorage } from './types';
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
import type { CoreEventMap, MiddlewareSelectorConfig } from '@idraw/types';
|
|
2
|
+
import type { BoardMiddleware, ActionType, DeepSelectorSharedStorage } from './types';
|
|
3
|
+
import { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup, middlewareEventSnapToGrid, keyActionType, keyResizeType, keyGroupQueue, keyHoverElement, keySelectedElementList } from './config';
|
|
4
|
+
export { keySelectedElementList, keyHoverElement, keyActionType, keyResizeType, keyGroupQueue };
|
|
5
|
+
export type { DeepSelectorSharedStorage, ActionType };
|
|
6
|
+
export { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup, middlewareEventSnapToGrid };
|
|
7
|
+
export declare const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, CoreEventMap, MiddlewareSelectorConfig>;
|