@idraw/core 0.4.0-beta.2 → 0.4.0-beta.20
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 -5
- package/dist/esm/index.js +35 -10
- package/dist/esm/lib/cursor-image.d.ts +3 -0
- package/dist/esm/lib/cursor-image.js +3 -0
- package/dist/esm/lib/cursor.d.ts +3 -12
- package/dist/esm/lib/cursor.js +138 -106
- package/dist/esm/middleware/dragger/index.d.ts +7 -0
- package/dist/esm/middleware/dragger/index.js +43 -0
- package/dist/esm/middleware/info/draw-info.d.ts +31 -0
- package/dist/esm/middleware/info/draw-info.js +110 -0
- package/dist/esm/middleware/info/index.d.ts +3 -0
- package/dist/esm/middleware/info/index.js +110 -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 +6 -0
- package/dist/esm/middleware/layout-selector/config.js +6 -0
- package/dist/esm/middleware/layout-selector/index.d.ts +3 -0
- package/dist/esm/middleware/layout-selector/index.js +251 -0
- package/dist/esm/middleware/layout-selector/types.d.ts +12 -0
- package/dist/esm/middleware/layout-selector/types.js +2 -0
- package/dist/esm/middleware/layout-selector/util.d.ts +5 -0
- package/dist/esm/middleware/layout-selector/util.js +93 -0
- package/dist/esm/middleware/ruler/index.d.ts +3 -2
- package/dist/esm/middleware/ruler/index.js +13 -8
- 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 +6 -1
- package/dist/esm/middleware/ruler/util.js +55 -1
- package/dist/esm/middleware/scaler/index.d.ts +2 -2
- package/dist/esm/middleware/scaler/index.js +1 -3
- package/dist/esm/middleware/scroller/index.d.ts +2 -1
- package/dist/esm/middleware/scroller/index.js +5 -5
- package/dist/esm/middleware/scroller/types.d.ts +9 -0
- package/dist/esm/middleware/scroller/types.js +1 -0
- package/dist/esm/middleware/scroller/util.js +1 -1
- package/dist/esm/middleware/selector/config.d.ts +12 -0
- package/dist/esm/middleware/selector/config.js +12 -0
- package/dist/esm/middleware/selector/draw-auxiliary.d.ts +7 -0
- package/dist/esm/middleware/selector/draw-auxiliary.js +46 -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 +5 -0
- package/dist/esm/middleware/selector/draw-reference.js +31 -0
- package/dist/esm/middleware/selector/draw-wrapper.d.ts +9 -1
- package/dist/esm/middleware/selector/draw-wrapper.js +34 -26
- package/dist/esm/middleware/selector/index.d.ts +7 -4
- package/dist/esm/middleware/selector/index.js +275 -68
- package/dist/esm/middleware/selector/reference.d.ts +13 -0
- package/dist/esm/middleware/selector/reference.js +273 -0
- package/dist/esm/middleware/selector/types.d.ts +8 -4
- package/dist/esm/middleware/selector/types.js +1 -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 +79 -17
- package/dist/index.global.js +3477 -1066
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
|
|
2
|
-
import { drawRulerBackground, drawXRuler, drawYRuler, calcXRulerScaleList, calcYRulerScaleList, drawUnderGrid } from './util';
|
|
2
|
+
import { drawRulerBackground, drawXRuler, drawYRuler, calcXRulerScaleList, calcYRulerScaleList, drawUnderGrid, drawScrollerSelectedArea } from './util';
|
|
3
3
|
export const middlewareEventRuler = '@middleware/show-ruler';
|
|
4
4
|
export const MiddlewareRuler = (opts) => {
|
|
5
|
-
const
|
|
6
|
-
const {
|
|
7
|
-
const { helperContext, underContext } = viewContent;
|
|
5
|
+
const { boardContent, viewer, eventHub, calculator } = opts;
|
|
6
|
+
const { helperContext, underContext } = boardContent;
|
|
8
7
|
let show = true;
|
|
9
8
|
let showGrid = true;
|
|
10
|
-
|
|
9
|
+
const rulerCallback = (e) => {
|
|
11
10
|
if (typeof (e === null || e === void 0 ? void 0 : e.show) === 'boolean') {
|
|
12
11
|
show = e.show;
|
|
13
12
|
}
|
|
@@ -17,14 +16,20 @@ export const MiddlewareRuler = (opts) => {
|
|
|
17
16
|
if (typeof (e === null || e === void 0 ? void 0 : e.show) === 'boolean' || typeof (e === null || e === void 0 ? void 0 : e.showGrid) === 'boolean') {
|
|
18
17
|
viewer.drawFrame();
|
|
19
18
|
}
|
|
20
|
-
}
|
|
19
|
+
};
|
|
21
20
|
return {
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
name: '@middleware/ruler',
|
|
22
|
+
use() {
|
|
23
|
+
eventHub.on(middlewareEventRuler, rulerCallback);
|
|
24
|
+
},
|
|
25
|
+
disuse() {
|
|
26
|
+
eventHub.off(middlewareEventRuler, rulerCallback);
|
|
27
|
+
},
|
|
24
28
|
beforeDrawFrame: ({ snapshot }) => {
|
|
25
29
|
if (show === true) {
|
|
26
30
|
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
27
31
|
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
32
|
+
drawScrollerSelectedArea(helperContext, { snapshot, calculator });
|
|
28
33
|
drawRulerBackground(helperContext, { viewScaleInfo, viewSizeInfo });
|
|
29
34
|
const xList = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
30
35
|
drawXRuler(helperContext, { scaleList: xList });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D } from '@idraw/types';
|
|
1
|
+
import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D, BoardViewerFrameSnapshot, ViewCalculator } from '@idraw/types';
|
|
2
|
+
import type { DeepRulerSharedStorage } from './types';
|
|
2
3
|
interface RulerScale {
|
|
3
4
|
num: number;
|
|
4
5
|
showNum: boolean;
|
|
@@ -30,4 +31,8 @@ export declare function drawUnderGrid(ctx: ViewContext2D, opts: {
|
|
|
30
31
|
viewScaleInfo: ViewScaleInfo;
|
|
31
32
|
viewSizeInfo: ViewSizeInfo;
|
|
32
33
|
}): void;
|
|
34
|
+
export declare function drawScrollerSelectedArea(ctx: ViewContext2D, opts: {
|
|
35
|
+
snapshot: BoardViewerFrameSnapshot<DeepRulerSharedStorage>;
|
|
36
|
+
calculator: ViewCalculator;
|
|
37
|
+
}): void;
|
|
33
38
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { formatNumber, rotateByCenter } from '@idraw/util';
|
|
1
|
+
import { formatNumber, rotateByCenter, getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
|
|
2
|
+
import { keySelectedElementList, keyActionType } from '../selector';
|
|
2
3
|
const rulerSize = 16;
|
|
3
4
|
const background = '#FFFFFFA8';
|
|
4
5
|
const borderColor = '#00000080';
|
|
@@ -10,6 +11,7 @@ const fontWeight = 100;
|
|
|
10
11
|
const gridColor = '#AAAAAA20';
|
|
11
12
|
const gridKeyColor = '#AAAAAA40';
|
|
12
13
|
const lineSize = 1;
|
|
14
|
+
const selectedAreaColor = '#196097';
|
|
13
15
|
function calcRulerScaleList(opts) {
|
|
14
16
|
const { scale, viewLength, viewOffset } = opts;
|
|
15
17
|
const list = [];
|
|
@@ -185,3 +187,55 @@ export function drawUnderGrid(ctx, opts) {
|
|
|
185
187
|
ctx.stroke();
|
|
186
188
|
}
|
|
187
189
|
}
|
|
190
|
+
export function drawScrollerSelectedArea(ctx, opts) {
|
|
191
|
+
const { snapshot, calculator } = opts;
|
|
192
|
+
const { sharedStore } = snapshot;
|
|
193
|
+
const selectedElementList = sharedStore[keySelectedElementList];
|
|
194
|
+
const actionType = sharedStore[keyActionType];
|
|
195
|
+
if (['select', 'drag', 'drag-list', 'drag-list-end'].includes(actionType) && selectedElementList.length > 0) {
|
|
196
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
197
|
+
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
198
|
+
const rangeRectInfoList = [];
|
|
199
|
+
const xAreaStartList = [];
|
|
200
|
+
const xAreaEndList = [];
|
|
201
|
+
const yAreaStartList = [];
|
|
202
|
+
const yAreaEndList = [];
|
|
203
|
+
selectedElementList.forEach((elem) => {
|
|
204
|
+
const rectInfo = calculator.calcViewRectInfoFromRange(elem.uuid, {
|
|
205
|
+
viewScaleInfo,
|
|
206
|
+
viewSizeInfo
|
|
207
|
+
});
|
|
208
|
+
if (rectInfo) {
|
|
209
|
+
rangeRectInfoList.push(rectInfo);
|
|
210
|
+
xAreaStartList.push(rectInfo.left.x);
|
|
211
|
+
xAreaEndList.push(rectInfo.right.x);
|
|
212
|
+
yAreaStartList.push(rectInfo.top.y);
|
|
213
|
+
yAreaEndList.push(rectInfo.bottom.y);
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
if (!(rangeRectInfoList.length > 0)) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
const xAreaStart = Math.min(...xAreaStartList);
|
|
220
|
+
const xAreaEnd = Math.max(...xAreaEndList);
|
|
221
|
+
const yAreaStart = Math.min(...yAreaStartList);
|
|
222
|
+
const yAreaEnd = Math.max(...yAreaEndList);
|
|
223
|
+
ctx.globalAlpha = 1;
|
|
224
|
+
ctx.beginPath();
|
|
225
|
+
ctx.moveTo(xAreaStart, 0);
|
|
226
|
+
ctx.lineTo(xAreaEnd, 0);
|
|
227
|
+
ctx.lineTo(xAreaEnd, rulerSize);
|
|
228
|
+
ctx.lineTo(xAreaStart, rulerSize);
|
|
229
|
+
ctx.fillStyle = selectedAreaColor;
|
|
230
|
+
ctx.closePath();
|
|
231
|
+
ctx.fill();
|
|
232
|
+
ctx.beginPath();
|
|
233
|
+
ctx.moveTo(0, yAreaStart);
|
|
234
|
+
ctx.lineTo(rulerSize, yAreaStart);
|
|
235
|
+
ctx.lineTo(rulerSize, yAreaEnd);
|
|
236
|
+
ctx.lineTo(0, yAreaEnd);
|
|
237
|
+
ctx.fillStyle = selectedAreaColor;
|
|
238
|
+
ctx.closePath();
|
|
239
|
+
ctx.fill();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { BoardMiddleware,
|
|
1
|
+
import type { BoardMiddleware, CoreEventMap } from '@idraw/types';
|
|
2
2
|
export declare const middlewareEventScale = "@middleware/scale";
|
|
3
|
-
export declare const MiddlewareScaler: BoardMiddleware<Record<string, any>,
|
|
3
|
+
export declare const MiddlewareScaler: BoardMiddleware<Record<string, any>, CoreEventMap>;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { formatNumber } from '@idraw/util';
|
|
2
2
|
export const middlewareEventScale = '@middleware/scale';
|
|
3
3
|
export const MiddlewareScaler = (opts) => {
|
|
4
|
-
const key = 'SCALE';
|
|
5
4
|
const { viewer, sharer, eventHub } = opts;
|
|
6
5
|
const maxScale = 50;
|
|
7
6
|
const minScale = 0.05;
|
|
8
7
|
return {
|
|
9
|
-
|
|
10
|
-
isDefault: true,
|
|
8
|
+
name: '@middleware/scaler',
|
|
11
9
|
wheelScale(e) {
|
|
12
10
|
const { deltaY, point } = e;
|
|
13
11
|
const { scale } = sharer.getActiveViewScaleInfo();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { drawScroller, isPointInScrollThumb } from './util';
|
|
2
|
-
import {
|
|
2
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
3
3
|
export const MiddlewareScroller = (opts) => {
|
|
4
|
-
const { viewer,
|
|
5
|
-
const { helperContext } =
|
|
4
|
+
const { viewer, boardContent, sharer } = opts;
|
|
5
|
+
const { helperContext } = boardContent;
|
|
6
6
|
sharer.setSharedStorage(keyXThumbRect, null);
|
|
7
7
|
sharer.setSharedStorage(keyYThumbRect, null);
|
|
8
8
|
const clear = () => {
|
|
@@ -42,7 +42,7 @@ export const MiddlewareScroller = (opts) => {
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
return {
|
|
45
|
-
|
|
45
|
+
name: '@middleware/scroller',
|
|
46
46
|
wheel: (e) => {
|
|
47
47
|
viewer.scroll({
|
|
48
48
|
moveX: 0 - e.deltaX,
|
|
@@ -74,7 +74,7 @@ export const MiddlewareScroller = (opts) => {
|
|
|
74
74
|
return false;
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
|
-
pointEnd: (
|
|
77
|
+
pointEnd: () => {
|
|
78
78
|
const activeThumbType = sharer.getSharedStorage(keyActiveThumbType);
|
|
79
79
|
clear();
|
|
80
80
|
if (activeThumbType === 'X' || activeThumbType === 'Y') {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Point, ElementSize } from '@idraw/types';
|
|
2
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
3
|
+
export type DeepScrollerSharedStorage = {
|
|
4
|
+
[keyXThumbRect]: null | ElementSize;
|
|
5
|
+
[keyYThumbRect]: null | ElementSize;
|
|
6
|
+
[keyPrevPoint]: null | Point;
|
|
7
|
+
[keyActivePoint]: null | Point;
|
|
8
|
+
[keyActiveThumbType]: null | 'X' | 'Y';
|
|
9
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
@@ -2,7 +2,7 @@ import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idra
|
|
|
2
2
|
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect } from './config';
|
|
3
3
|
const minScrollerWidth = 12;
|
|
4
4
|
const scrollerLineWidth = 16;
|
|
5
|
-
const scrollerThumbAlpha = 0.
|
|
5
|
+
const scrollerThumbAlpha = 0.3;
|
|
6
6
|
const scrollConfig = {
|
|
7
7
|
width: minScrollerWidth,
|
|
8
8
|
thumbColor: '#000000AA',
|
|
@@ -8,8 +8,13 @@ export declare const keyHoverElementVertexes: unique symbol;
|
|
|
8
8
|
export declare const keySelectedElementList: unique symbol;
|
|
9
9
|
export declare const keySelectedElementListVertexes: unique symbol;
|
|
10
10
|
export declare const keySelectedElementController: unique symbol;
|
|
11
|
+
export declare const keySelectedElementPosition: unique symbol;
|
|
12
|
+
export declare const keySelectedReferenceXLines: unique symbol;
|
|
13
|
+
export declare const keySelectedReferenceYLines: unique symbol;
|
|
11
14
|
export declare const keyGroupQueue: unique symbol;
|
|
12
15
|
export declare const keyGroupQueueVertexesList: unique symbol;
|
|
16
|
+
export declare const keyIsMoving: unique symbol;
|
|
17
|
+
export declare const keyEnableSelectInGroup: 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;
|
|
@@ -20,3 +25,10 @@ export declare const selectWrapperBorderWidth = 2;
|
|
|
20
25
|
export declare const resizeControllerBorderWidth = 4;
|
|
21
26
|
export declare const areaBorderWidth = 1;
|
|
22
27
|
export declare const wrapperColor = "#1973ba";
|
|
28
|
+
export declare const lockColor = "#5b5959b5";
|
|
29
|
+
export declare const controllerSize = 10;
|
|
30
|
+
export declare const auxiliaryColor = "#f7276e";
|
|
31
|
+
export declare const referenceColor = "#f7276e";
|
|
32
|
+
export declare const middlewareEventSelect: string;
|
|
33
|
+
export declare const middlewareEventSelectClear: string;
|
|
34
|
+
export declare const middlewareEventSelectInGroup: string;
|
|
@@ -8,8 +8,13 @@ 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`);
|
|
12
|
+
export const keySelectedReferenceXLines = Symbol(`${key}_selectedReferenceXLines`);
|
|
13
|
+
export const keySelectedReferenceYLines = Symbol(`${key}_selectedReferenceYLines`);
|
|
11
14
|
export const keyGroupQueue = Symbol(`${key}_groupQueue`);
|
|
12
15
|
export const keyGroupQueueVertexesList = Symbol(`${key}_groupQueueVertexesList`);
|
|
16
|
+
export const keyIsMoving = Symbol(`${key}_isMoving`);
|
|
17
|
+
export const keyEnableSelectInGroup = Symbol(`${key}_canSelectInGroup`);
|
|
13
18
|
export const keyDebugElemCenter = Symbol(`${key}_debug_elemCenter`);
|
|
14
19
|
export const keyDebugStartVertical = Symbol(`${key}_debug_startVertical`);
|
|
15
20
|
export const keyDebugEndVertical = Symbol(`${key}_debug_endVertical`);
|
|
@@ -20,3 +25,10 @@ export const selectWrapperBorderWidth = 2;
|
|
|
20
25
|
export const resizeControllerBorderWidth = 4;
|
|
21
26
|
export const areaBorderWidth = 1;
|
|
22
27
|
export const wrapperColor = '#1973ba';
|
|
28
|
+
export const lockColor = '#5b5959b5';
|
|
29
|
+
export const controllerSize = 10;
|
|
30
|
+
export const auxiliaryColor = '#f7276e';
|
|
31
|
+
export const referenceColor = '#f7276e';
|
|
32
|
+
export const middlewareEventSelect = '@middleware/select';
|
|
33
|
+
export const middlewareEventSelectClear = '@middleware/select-clear';
|
|
34
|
+
export const middlewareEventSelectInGroup = '@middleware/select-in-group';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ViewContext2D, Element, ViewScaleInfo, ViewSizeInfo, ViewCalculator } from '@idraw/types';
|
|
2
|
+
export declare function drawAuxiliaryExperimentBox(ctx: ViewContext2D, opts: {
|
|
3
|
+
calculator: ViewCalculator;
|
|
4
|
+
element: Element | null;
|
|
5
|
+
viewScaleInfo: ViewScaleInfo;
|
|
6
|
+
viewSizeInfo: ViewSizeInfo;
|
|
7
|
+
}): void;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { auxiliaryColor } from './config';
|
|
2
|
+
import { drawLine, drawCrossByCenter } from './draw-base';
|
|
3
|
+
function getViewBoxInfo(rectInfo) {
|
|
4
|
+
const boxInfo = {
|
|
5
|
+
minX: rectInfo.topLeft.x,
|
|
6
|
+
minY: rectInfo.topLeft.y,
|
|
7
|
+
maxX: rectInfo.bottomRight.x,
|
|
8
|
+
maxY: rectInfo.bottomRight.y,
|
|
9
|
+
midX: rectInfo.center.x,
|
|
10
|
+
midY: rectInfo.center.y
|
|
11
|
+
};
|
|
12
|
+
return boxInfo;
|
|
13
|
+
}
|
|
14
|
+
export function drawAuxiliaryExperimentBox(ctx, opts) {
|
|
15
|
+
const { element, viewScaleInfo, viewSizeInfo, calculator } = opts;
|
|
16
|
+
if (!element) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const viewRectInfo = calculator.calcViewRectInfoFromRange(element.uuid, { viewScaleInfo, viewSizeInfo });
|
|
20
|
+
if (!viewRectInfo) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
const lineOpts = {
|
|
24
|
+
borderColor: auxiliaryColor,
|
|
25
|
+
borderWidth: 1,
|
|
26
|
+
lineDash: []
|
|
27
|
+
};
|
|
28
|
+
const boxInfo = getViewBoxInfo(viewRectInfo);
|
|
29
|
+
const { width, height } = viewSizeInfo;
|
|
30
|
+
drawLine(ctx, { x: boxInfo.minX, y: 0 }, { x: boxInfo.minX, y: height }, lineOpts);
|
|
31
|
+
drawLine(ctx, { x: boxInfo.midX, y: 0 }, { x: boxInfo.midX, y: height }, lineOpts);
|
|
32
|
+
drawLine(ctx, { x: boxInfo.maxX, y: 0 }, { x: boxInfo.maxX, y: height }, lineOpts);
|
|
33
|
+
drawLine(ctx, { x: 0, y: boxInfo.minY }, { x: width, y: boxInfo.minY }, lineOpts);
|
|
34
|
+
drawLine(ctx, { x: 0, y: boxInfo.midY }, { x: width, y: boxInfo.midY }, lineOpts);
|
|
35
|
+
drawLine(ctx, { x: 0, y: boxInfo.maxY }, { x: width, y: boxInfo.maxY }, lineOpts);
|
|
36
|
+
const crossOpts = Object.assign(Object.assign({}, lineOpts), { size: 6 });
|
|
37
|
+
drawCrossByCenter(ctx, viewRectInfo.center, crossOpts);
|
|
38
|
+
drawCrossByCenter(ctx, viewRectInfo.topLeft, crossOpts);
|
|
39
|
+
drawCrossByCenter(ctx, viewRectInfo.topRight, crossOpts);
|
|
40
|
+
drawCrossByCenter(ctx, viewRectInfo.bottomLeft, crossOpts);
|
|
41
|
+
drawCrossByCenter(ctx, viewRectInfo.bottomRight, crossOpts);
|
|
42
|
+
drawCrossByCenter(ctx, viewRectInfo.top, crossOpts);
|
|
43
|
+
drawCrossByCenter(ctx, viewRectInfo.right, crossOpts);
|
|
44
|
+
drawCrossByCenter(ctx, viewRectInfo.bottom, crossOpts);
|
|
45
|
+
drawCrossByCenter(ctx, viewRectInfo.left, crossOpts);
|
|
46
|
+
}
|
|
@@ -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,31 @@
|
|
|
1
|
+
import { referenceColor } from './config';
|
|
2
|
+
import { drawLine, drawCrossByCenter } from './draw-base';
|
|
3
|
+
export function drawReferenceLines(ctx, opts) {
|
|
4
|
+
const { xLines, yLines } = opts;
|
|
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,12 +1,20 @@
|
|
|
1
|
-
import type { Element, ElementType, PointSize, RendererDrawElementOptions, ViewContext2D, ViewRectVertexes, ViewScaleInfo, ViewSizeInfo, ElementSizeController } from '@idraw/types';
|
|
1
|
+
import type { Element, ElementType, PointSize, RendererDrawElementOptions, ViewContext2D, ViewRectVertexes, ViewScaleInfo, ViewSizeInfo, ElementSizeController, ViewCalculator } from '@idraw/types';
|
|
2
2
|
import type { AreaSize } from './types';
|
|
3
3
|
export declare function drawHoverVertexesWrapper(ctx: ViewContext2D, vertexes: ViewRectVertexes | null, opts: {
|
|
4
4
|
viewScaleInfo: ViewScaleInfo;
|
|
5
5
|
viewSizeInfo: ViewSizeInfo;
|
|
6
6
|
}): void;
|
|
7
|
+
export declare function drawLockVertexesWrapper(ctx: ViewContext2D, vertexes: ViewRectVertexes | null, opts: {
|
|
8
|
+
viewScaleInfo: ViewScaleInfo;
|
|
9
|
+
viewSizeInfo: ViewSizeInfo;
|
|
10
|
+
controller?: ElementSizeController | null;
|
|
11
|
+
}): void;
|
|
7
12
|
export declare function drawSelectedElementControllersVertexes(ctx: ViewContext2D, controller: ElementSizeController | null, opts: {
|
|
13
|
+
hideControllers: boolean;
|
|
8
14
|
viewScaleInfo: ViewScaleInfo;
|
|
9
15
|
viewSizeInfo: ViewSizeInfo;
|
|
16
|
+
element: Element | null;
|
|
17
|
+
calculator: ViewCalculator;
|
|
10
18
|
}): void;
|
|
11
19
|
export declare function drawElementListShadows(ctx: ViewContext2D, elements: Element<ElementType>[], opts?: Omit<RendererDrawElementOptions, 'loader'>): void;
|
|
12
20
|
export declare function drawArea(ctx: ViewContext2D, opts: {
|
|
@@ -1,22 +1,6 @@
|
|
|
1
|
-
import { rotateElementVertexes, calcViewVertexes } from '@idraw/util';
|
|
2
|
-
import { resizeControllerBorderWidth, areaBorderWidth, wrapperColor, selectWrapperBorderWidth } from './config';
|
|
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, wrapperColor, selectWrapperBorderWidth, lockColor, 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;
|
|
@@ -24,26 +8,50 @@ export function drawHoverVertexesWrapper(ctx, vertexes, opts) {
|
|
|
24
8
|
const wrapperOpts = { borderColor: wrapperColor, borderWidth: 1, background: 'transparent', lineDash: [] };
|
|
25
9
|
drawVertexes(ctx, calcViewVertexes(vertexes, opts), wrapperOpts);
|
|
26
10
|
}
|
|
11
|
+
export function drawLockVertexesWrapper(ctx, vertexes, opts) {
|
|
12
|
+
if (!vertexes) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const wrapperOpts = { borderColor: lockColor, borderWidth: 1, background: 'transparent', lineDash: [] };
|
|
16
|
+
drawVertexes(ctx, calcViewVertexes(vertexes, opts), wrapperOpts);
|
|
17
|
+
const { controller } = opts;
|
|
18
|
+
if (controller) {
|
|
19
|
+
const { topLeft, topRight, bottomLeft, bottomRight, topMiddle, bottomMiddle, leftMiddle, rightMiddle } = controller;
|
|
20
|
+
const ctrlOpts = Object.assign(Object.assign({}, wrapperOpts), { borderWidth: 1, background: lockColor });
|
|
21
|
+
drawCrossVertexes(ctx, calcViewVertexes(topMiddle.vertexes, opts), ctrlOpts);
|
|
22
|
+
drawCrossVertexes(ctx, calcViewVertexes(bottomMiddle.vertexes, opts), ctrlOpts);
|
|
23
|
+
drawCrossVertexes(ctx, calcViewVertexes(leftMiddle.vertexes, opts), ctrlOpts);
|
|
24
|
+
drawCrossVertexes(ctx, calcViewVertexes(rightMiddle.vertexes, opts), ctrlOpts);
|
|
25
|
+
drawCrossVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
|
|
26
|
+
drawCrossVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
|
|
27
|
+
drawCrossVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
|
|
28
|
+
drawCrossVertexes(ctx, calcViewVertexes(bottomRight.vertexes, opts), ctrlOpts);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
27
31
|
export function drawSelectedElementControllersVertexes(ctx, controller, opts) {
|
|
28
32
|
if (!controller) {
|
|
29
33
|
return;
|
|
30
34
|
}
|
|
31
|
-
const {
|
|
35
|
+
const { hideControllers } = opts;
|
|
36
|
+
const { elementWrapper, topLeft, topRight, bottomLeft, bottomRight, top, rotate } = controller;
|
|
32
37
|
const wrapperOpts = { borderColor: wrapperColor, borderWidth: selectWrapperBorderWidth, background: 'transparent', lineDash: [] };
|
|
33
38
|
const ctrlOpts = Object.assign(Object.assign({}, wrapperOpts), { borderWidth: resizeControllerBorderWidth, background: '#FFFFFF' });
|
|
34
39
|
drawVertexes(ctx, calcViewVertexes(elementWrapper, opts), wrapperOpts);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
if (!hideControllers) {
|
|
41
|
+
drawLine(ctx, calcViewPointSize(top.center, opts), calcViewPointSize(rotate.center, opts), Object.assign(Object.assign({}, ctrlOpts), { borderWidth: 2 }));
|
|
42
|
+
drawVertexes(ctx, calcViewVertexes(topLeft.vertexes, opts), ctrlOpts);
|
|
43
|
+
drawVertexes(ctx, calcViewVertexes(topRight.vertexes, opts), ctrlOpts);
|
|
44
|
+
drawVertexes(ctx, calcViewVertexes(bottomLeft.vertexes, opts), ctrlOpts);
|
|
45
|
+
drawVertexes(ctx, calcViewVertexes(bottomRight.vertexes, opts), ctrlOpts);
|
|
46
|
+
drawCircleController(ctx, calcViewPointSize(rotate.center, opts), Object.assign(Object.assign({}, ctrlOpts), { size: controllerSize, borderWidth: 2 }));
|
|
47
|
+
}
|
|
39
48
|
}
|
|
40
49
|
export function drawElementListShadows(ctx, elements, opts) {
|
|
41
50
|
elements.forEach((elem) => {
|
|
42
51
|
let { x, y, w, h } = elem;
|
|
43
52
|
const { angle = 0 } = elem;
|
|
44
53
|
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);
|
|
54
|
+
const size = calcViewElementSize({ x, y, w, h }, opts);
|
|
47
55
|
x = size.x;
|
|
48
56
|
y = size.y;
|
|
49
57
|
w = size.w;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { BoardMiddleware, DeepSelectorSharedStorage } from './types';
|
|
3
|
-
|
|
4
|
-
export
|
|
1
|
+
import type { CoreEventMap } from '@idraw/types';
|
|
2
|
+
import type { BoardMiddleware, ActionType, DeepSelectorSharedStorage } from './types';
|
|
3
|
+
import { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup, keyActionType, keyResizeType, keyGroupQueue, keySelectedElementList } from './config';
|
|
4
|
+
export { keySelectedElementList, keyActionType, keyResizeType, keyGroupQueue };
|
|
5
|
+
export type { DeepSelectorSharedStorage, ActionType };
|
|
6
|
+
export { middlewareEventSelect, middlewareEventSelectClear, middlewareEventSelectInGroup };
|
|
7
|
+
export declare const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, CoreEventMap>;
|