@idraw/core 0.4.0-beta.3 → 0.4.0-beta.30
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 +15 -5
- package/dist/esm/index.js +29 -8
- 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/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 +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/index.d.ts +3 -2
- package/dist/esm/middleware/ruler/index.js +12 -9
- 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 +15 -4
- package/dist/esm/middleware/ruler/util.js +81 -4
- 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 +2 -0
- package/dist/esm/middleware/scroller/config.js +2 -0
- package/dist/esm/middleware/scroller/index.d.ts +2 -1
- package/dist/esm/middleware/scroller/index.js +33 -5
- 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 +1 -1
- package/dist/esm/middleware/scroller/util.js +22 -17
- 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 +280 -45
- 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 +3685 -953
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
|
@@ -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;
|
|
@@ -9,11 +10,17 @@ interface RulerScale {
|
|
|
9
10
|
export declare function calcXRulerScaleList(opts: {
|
|
10
11
|
viewScaleInfo: ViewScaleInfo;
|
|
11
12
|
viewSizeInfo: ViewSizeInfo;
|
|
12
|
-
}):
|
|
13
|
+
}): {
|
|
14
|
+
list: RulerScale[];
|
|
15
|
+
rulerUnit: number;
|
|
16
|
+
};
|
|
13
17
|
export declare function calcYRulerScaleList(opts: {
|
|
14
18
|
viewScaleInfo: ViewScaleInfo;
|
|
15
19
|
viewSizeInfo: ViewSizeInfo;
|
|
16
|
-
}):
|
|
20
|
+
}): {
|
|
21
|
+
list: RulerScale[];
|
|
22
|
+
rulerUnit: number;
|
|
23
|
+
};
|
|
17
24
|
export declare function drawXRuler(ctx: ViewContext2D, opts: {
|
|
18
25
|
scaleList: RulerScale[];
|
|
19
26
|
}): void;
|
|
@@ -24,10 +31,14 @@ export declare function drawRulerBackground(ctx: ViewContext2D, opts: {
|
|
|
24
31
|
viewScaleInfo: ViewScaleInfo;
|
|
25
32
|
viewSizeInfo: ViewSizeInfo;
|
|
26
33
|
}): void;
|
|
27
|
-
export declare function
|
|
34
|
+
export declare function drawGrid(ctx: ViewContext2D, opts: {
|
|
28
35
|
xList: RulerScale[];
|
|
29
36
|
yList: RulerScale[];
|
|
30
37
|
viewScaleInfo: ViewScaleInfo;
|
|
31
38
|
viewSizeInfo: ViewSizeInfo;
|
|
32
39
|
}): void;
|
|
40
|
+
export declare function drawScrollerSelectedArea(ctx: ViewContext2D, opts: {
|
|
41
|
+
snapshot: BoardViewerFrameSnapshot<DeepRulerSharedStorage>;
|
|
42
|
+
calculator: ViewCalculator;
|
|
43
|
+
}): void;
|
|
33
44
|
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,12 +11,36 @@ const fontWeight = 100;
|
|
|
10
11
|
const gridColor = '#AAAAAA20';
|
|
11
12
|
const gridKeyColor = '#AAAAAA40';
|
|
12
13
|
const lineSize = 1;
|
|
14
|
+
const selectedAreaColor = '#196097';
|
|
15
|
+
const limitRulerUnitList = [1, 2, 5, 10, 20, 50, 100, 200, 500];
|
|
16
|
+
function limitRulerUnit(unit) {
|
|
17
|
+
unit = Math.max(limitRulerUnitList[0], Math.min(unit, limitRulerUnitList[limitRulerUnitList.length - 1]));
|
|
18
|
+
for (let i = 0; i < limitRulerUnitList.length - 1; i++) {
|
|
19
|
+
const thisUnit = limitRulerUnitList[i];
|
|
20
|
+
const nextUnit = limitRulerUnitList[i + 1];
|
|
21
|
+
if (unit > nextUnit) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
if (unit === thisUnit) {
|
|
25
|
+
return unit;
|
|
26
|
+
}
|
|
27
|
+
if (unit === nextUnit) {
|
|
28
|
+
return unit;
|
|
29
|
+
}
|
|
30
|
+
const mid = (thisUnit + nextUnit) / 2;
|
|
31
|
+
if (unit <= mid) {
|
|
32
|
+
return thisUnit;
|
|
33
|
+
}
|
|
34
|
+
return nextUnit;
|
|
35
|
+
}
|
|
36
|
+
return unit;
|
|
37
|
+
}
|
|
13
38
|
function calcRulerScaleList(opts) {
|
|
14
39
|
const { scale, viewLength, viewOffset } = opts;
|
|
15
40
|
const list = [];
|
|
16
41
|
let rulerUnit = 10;
|
|
17
42
|
rulerUnit = formatNumber(rulerUnit / scale, { decimalPlaces: 0 });
|
|
18
|
-
rulerUnit =
|
|
43
|
+
rulerUnit = limitRulerUnit(rulerUnit);
|
|
19
44
|
const rulerKeyUnit = rulerUnit * 10;
|
|
20
45
|
const rulerSubKeyUnit = rulerUnit * 5;
|
|
21
46
|
let index = 0;
|
|
@@ -38,7 +63,7 @@ function calcRulerScaleList(opts) {
|
|
|
38
63
|
list.push(rulerScale);
|
|
39
64
|
index++;
|
|
40
65
|
}
|
|
41
|
-
return list;
|
|
66
|
+
return { list, rulerUnit };
|
|
42
67
|
}
|
|
43
68
|
export function calcXRulerScaleList(opts) {
|
|
44
69
|
const { viewScaleInfo, viewSizeInfo } = opts;
|
|
@@ -150,7 +175,7 @@ export function drawRulerBackground(ctx, opts) {
|
|
|
150
175
|
ctx.strokeStyle = borderColor;
|
|
151
176
|
ctx.stroke();
|
|
152
177
|
}
|
|
153
|
-
export function
|
|
178
|
+
export function drawGrid(ctx, opts) {
|
|
154
179
|
const { xList, yList, viewSizeInfo } = opts;
|
|
155
180
|
const { width, height } = viewSizeInfo;
|
|
156
181
|
for (let i = 0; i < xList.length; i++) {
|
|
@@ -185,3 +210,55 @@ export function drawUnderGrid(ctx, opts) {
|
|
|
185
210
|
ctx.stroke();
|
|
186
211
|
}
|
|
187
212
|
}
|
|
213
|
+
export function drawScrollerSelectedArea(ctx, opts) {
|
|
214
|
+
const { snapshot, calculator } = opts;
|
|
215
|
+
const { sharedStore } = snapshot;
|
|
216
|
+
const selectedElementList = sharedStore[keySelectedElementList];
|
|
217
|
+
const actionType = sharedStore[keyActionType];
|
|
218
|
+
if (['select', 'drag', 'drag-list', 'drag-list-end'].includes(actionType) && selectedElementList.length > 0) {
|
|
219
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
220
|
+
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
221
|
+
const rangeRectInfoList = [];
|
|
222
|
+
const xAreaStartList = [];
|
|
223
|
+
const xAreaEndList = [];
|
|
224
|
+
const yAreaStartList = [];
|
|
225
|
+
const yAreaEndList = [];
|
|
226
|
+
selectedElementList.forEach((elem) => {
|
|
227
|
+
const rectInfo = calculator.calcViewRectInfoFromRange(elem.uuid, {
|
|
228
|
+
viewScaleInfo,
|
|
229
|
+
viewSizeInfo
|
|
230
|
+
});
|
|
231
|
+
if (rectInfo) {
|
|
232
|
+
rangeRectInfoList.push(rectInfo);
|
|
233
|
+
xAreaStartList.push(rectInfo.left.x);
|
|
234
|
+
xAreaEndList.push(rectInfo.right.x);
|
|
235
|
+
yAreaStartList.push(rectInfo.top.y);
|
|
236
|
+
yAreaEndList.push(rectInfo.bottom.y);
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
if (!(rangeRectInfoList.length > 0)) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
const xAreaStart = Math.min(...xAreaStartList);
|
|
243
|
+
const xAreaEnd = Math.max(...xAreaEndList);
|
|
244
|
+
const yAreaStart = Math.min(...yAreaStartList);
|
|
245
|
+
const yAreaEnd = Math.max(...yAreaEndList);
|
|
246
|
+
ctx.globalAlpha = 1;
|
|
247
|
+
ctx.beginPath();
|
|
248
|
+
ctx.moveTo(xAreaStart, 0);
|
|
249
|
+
ctx.lineTo(xAreaEnd, 0);
|
|
250
|
+
ctx.lineTo(xAreaEnd, rulerSize);
|
|
251
|
+
ctx.lineTo(xAreaStart, rulerSize);
|
|
252
|
+
ctx.fillStyle = selectedAreaColor;
|
|
253
|
+
ctx.closePath();
|
|
254
|
+
ctx.fill();
|
|
255
|
+
ctx.beginPath();
|
|
256
|
+
ctx.moveTo(0, yAreaStart);
|
|
257
|
+
ctx.lineTo(rulerSize, yAreaStart);
|
|
258
|
+
ctx.lineTo(rulerSize, yAreaEnd);
|
|
259
|
+
ctx.lineTo(0, yAreaEnd);
|
|
260
|
+
ctx.fillStyle = selectedAreaColor;
|
|
261
|
+
ctx.closePath();
|
|
262
|
+
ctx.fill();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -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,6 +1,8 @@
|
|
|
1
1
|
export declare const key = "SCROLL";
|
|
2
2
|
export declare const keyXThumbRect: unique symbol;
|
|
3
3
|
export declare const keyYThumbRect: unique symbol;
|
|
4
|
+
export declare const keyHoverXThumbRect: unique symbol;
|
|
5
|
+
export declare const keyHoverYThumbRect: unique symbol;
|
|
4
6
|
export declare const keyPrevPoint: unique symbol;
|
|
5
7
|
export declare const keyActivePoint: unique symbol;
|
|
6
8
|
export declare const keyActiveThumbType: unique symbol;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export const key = 'SCROLL';
|
|
2
2
|
export const keyXThumbRect = Symbol(`${key}_xThumbRect`);
|
|
3
3
|
export const keyYThumbRect = Symbol(`${key}_yThumbRect`);
|
|
4
|
+
export const keyHoverXThumbRect = Symbol(`${key}_hoverXThumbRect`);
|
|
5
|
+
export const keyHoverYThumbRect = Symbol(`${key}_hoverYThumbRect`);
|
|
4
6
|
export const keyPrevPoint = Symbol(`${key}_prevPoint`);
|
|
5
7
|
export const keyActivePoint = Symbol(`${key}_activePoint`);
|
|
6
8
|
export const keyActiveThumbType = Symbol(`${key}_activeThumbType`);
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { drawScroller, isPointInScrollThumb } from './util';
|
|
2
|
-
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
|
|
2
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
3
3
|
export const MiddlewareScroller = (opts) => {
|
|
4
|
-
const { viewer, boardContent, sharer } = opts;
|
|
5
|
-
const {
|
|
4
|
+
const { viewer, boardContent, sharer, eventHub } = opts;
|
|
5
|
+
const { overlayContext } = boardContent;
|
|
6
6
|
sharer.setSharedStorage(keyXThumbRect, null);
|
|
7
7
|
sharer.setSharedStorage(keyYThumbRect, null);
|
|
8
|
+
let isBusy = false;
|
|
8
9
|
const clear = () => {
|
|
9
10
|
sharer.setSharedStorage(keyPrevPoint, null);
|
|
10
11
|
sharer.setSharedStorage(keyActivePoint, null);
|
|
11
12
|
sharer.setSharedStorage(keyActiveThumbType, null);
|
|
13
|
+
sharer.setSharedStorage(keyHoverXThumbRect, null);
|
|
14
|
+
sharer.setSharedStorage(keyHoverYThumbRect, null);
|
|
15
|
+
isBusy = false;
|
|
12
16
|
};
|
|
13
17
|
clear();
|
|
14
18
|
const scrollX = (p) => {
|
|
@@ -36,12 +40,13 @@ export const MiddlewareScroller = (opts) => {
|
|
|
36
40
|
}
|
|
37
41
|
};
|
|
38
42
|
const getThumbType = (p) => {
|
|
39
|
-
return isPointInScrollThumb(
|
|
43
|
+
return isPointInScrollThumb(overlayContext, p, {
|
|
40
44
|
xThumbRect: sharer.getSharedStorage(keyXThumbRect),
|
|
41
45
|
yThumbRect: sharer.getSharedStorage(keyYThumbRect)
|
|
42
46
|
});
|
|
43
47
|
};
|
|
44
48
|
return {
|
|
49
|
+
name: '@middleware/scroller',
|
|
45
50
|
wheel: (e) => {
|
|
46
51
|
viewer.scroll({
|
|
47
52
|
moveX: 0 - e.deltaX,
|
|
@@ -49,10 +54,32 @@ export const MiddlewareScroller = (opts) => {
|
|
|
49
54
|
});
|
|
50
55
|
viewer.drawFrame();
|
|
51
56
|
},
|
|
57
|
+
hover: (e) => {
|
|
58
|
+
if (isBusy === true) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
const { point } = e;
|
|
62
|
+
const thumbType = getThumbType(point);
|
|
63
|
+
if (thumbType === 'X' || thumbType === 'Y') {
|
|
64
|
+
if (thumbType === 'X') {
|
|
65
|
+
sharer.setSharedStorage(keyHoverXThumbRect, true);
|
|
66
|
+
sharer.setSharedStorage(keyHoverYThumbRect, false);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
sharer.setSharedStorage(keyHoverXThumbRect, false);
|
|
70
|
+
sharer.setSharedStorage(keyHoverYThumbRect, true);
|
|
71
|
+
}
|
|
72
|
+
eventHub.trigger('cursor', { type: 'default' });
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
sharer.setSharedStorage(keyHoverXThumbRect, false);
|
|
76
|
+
sharer.setSharedStorage(keyHoverYThumbRect, false);
|
|
77
|
+
},
|
|
52
78
|
pointStart: (e) => {
|
|
53
79
|
const { point } = e;
|
|
54
80
|
const thumbType = getThumbType(point);
|
|
55
81
|
if (thumbType === 'X' || thumbType === 'Y') {
|
|
82
|
+
isBusy = true;
|
|
56
83
|
sharer.setSharedStorage(keyActiveThumbType, thumbType);
|
|
57
84
|
sharer.setSharedStorage(keyPrevPoint, point);
|
|
58
85
|
return false;
|
|
@@ -74,6 +101,7 @@ export const MiddlewareScroller = (opts) => {
|
|
|
74
101
|
}
|
|
75
102
|
},
|
|
76
103
|
pointEnd: () => {
|
|
104
|
+
isBusy = false;
|
|
77
105
|
const activeThumbType = sharer.getSharedStorage(keyActiveThumbType);
|
|
78
106
|
clear();
|
|
79
107
|
if (activeThumbType === 'X' || activeThumbType === 'Y') {
|
|
@@ -83,7 +111,7 @@ export const MiddlewareScroller = (opts) => {
|
|
|
83
111
|
}
|
|
84
112
|
},
|
|
85
113
|
beforeDrawFrame({ snapshot }) {
|
|
86
|
-
const { xThumbRect, yThumbRect } = drawScroller(
|
|
114
|
+
const { xThumbRect, yThumbRect } = drawScroller(overlayContext, { snapshot });
|
|
87
115
|
sharer.setSharedStorage(keyXThumbRect, xThumbRect);
|
|
88
116
|
sharer.setSharedStorage(keyYThumbRect, yThumbRect);
|
|
89
117
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Point, ElementSize } from '@idraw/types';
|
|
2
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
3
|
+
export type DeepScrollerSharedStorage = {
|
|
4
|
+
[keyXThumbRect]: null | ElementSize;
|
|
5
|
+
[keyYThumbRect]: null | ElementSize;
|
|
6
|
+
[keyHoverXThumbRect]: boolean | null;
|
|
7
|
+
[keyHoverYThumbRect]: boolean | null;
|
|
8
|
+
[keyPrevPoint]: null | Point;
|
|
9
|
+
[keyActivePoint]: null | Point;
|
|
10
|
+
[keyActiveThumbType]: null | 'X' | 'Y';
|
|
11
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Point, BoardViewerFrameSnapshot, ViewContext2D, ElementSize } from '@idraw/types';
|
|
2
2
|
export type ScrollbarThumbType = 'X' | 'Y';
|
|
3
|
-
export declare function isPointInScrollThumb(
|
|
3
|
+
export declare function isPointInScrollThumb(overlayContext: ViewContext2D, p: Point, opts: {
|
|
4
4
|
xThumbRect?: ElementSize | null;
|
|
5
5
|
yThumbRect?: ElementSize | null;
|
|
6
6
|
}): ScrollbarThumbType | null;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
|
|
2
|
-
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect } from './config';
|
|
2
|
+
import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect, keyHoverXThumbRect, keyHoverYThumbRect } 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
|
-
thumbColor: '#
|
|
8
|
+
thumbColor: '#0000008A',
|
|
9
|
+
thumbHoverColor: '#000000EE',
|
|
9
10
|
scrollBarColor: '#FFFFFF60',
|
|
10
11
|
showScrollBar: false
|
|
11
12
|
};
|
|
12
|
-
function isPointAtRect(
|
|
13
|
-
const ctx =
|
|
13
|
+
function isPointAtRect(overlayContext, p, rect) {
|
|
14
|
+
const ctx = overlayContext;
|
|
14
15
|
const { x, y, w, h } = rect;
|
|
15
16
|
ctx.beginPath();
|
|
16
17
|
ctx.rect(x, y, w, h);
|
|
@@ -20,13 +21,13 @@ function isPointAtRect(helperContext, p, rect) {
|
|
|
20
21
|
}
|
|
21
22
|
return false;
|
|
22
23
|
}
|
|
23
|
-
export function isPointInScrollThumb(
|
|
24
|
+
export function isPointInScrollThumb(overlayContext, p, opts) {
|
|
24
25
|
let thumbType = null;
|
|
25
26
|
const { xThumbRect, yThumbRect } = opts;
|
|
26
|
-
if (xThumbRect && isPointAtRect(
|
|
27
|
+
if (xThumbRect && isPointAtRect(overlayContext, p, xThumbRect)) {
|
|
27
28
|
thumbType = 'X';
|
|
28
29
|
}
|
|
29
|
-
else if (yThumbRect && isPointAtRect(
|
|
30
|
+
else if (yThumbRect && isPointAtRect(overlayContext, p, yThumbRect)) {
|
|
30
31
|
thumbType = 'Y';
|
|
31
32
|
}
|
|
32
33
|
return thumbType;
|
|
@@ -38,11 +39,14 @@ function getScrollInfoFromSnapshot(snapshot) {
|
|
|
38
39
|
prevPoint: sharedStore[keyPrevPoint] || null,
|
|
39
40
|
activeThumbType: sharedStore[keyActiveThumbType] || null,
|
|
40
41
|
xThumbRect: sharedStore[keyXThumbRect] || null,
|
|
41
|
-
yThumbRect: sharedStore[keyYThumbRect] || null
|
|
42
|
+
yThumbRect: sharedStore[keyYThumbRect] || null,
|
|
43
|
+
hoverXThumb: sharedStore[keyHoverXThumbRect],
|
|
44
|
+
hoverYThumb: sharedStore[keyHoverYThumbRect]
|
|
42
45
|
};
|
|
43
46
|
return info;
|
|
44
47
|
}
|
|
45
|
-
function calcScrollerInfo(
|
|
48
|
+
function calcScrollerInfo(opts) {
|
|
49
|
+
const { viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb } = opts;
|
|
46
50
|
const { width, height } = viewSizeInfo;
|
|
47
51
|
const { offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo;
|
|
48
52
|
const sliderMinSize = scrollerLineWidth * 2.5;
|
|
@@ -101,7 +105,8 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
|
|
|
101
105
|
ySize,
|
|
102
106
|
translateY,
|
|
103
107
|
translateX,
|
|
104
|
-
|
|
108
|
+
xThumbColor: hoverXThumb ? scrollConfig.thumbHoverColor : scrollConfig.thumbColor,
|
|
109
|
+
yThumbColor: hoverYThumb ? scrollConfig.thumbHoverColor : scrollConfig.thumbColor,
|
|
105
110
|
scrollBarColor: scrollConfig.scrollBarColor,
|
|
106
111
|
xThumbRect,
|
|
107
112
|
yThumbRect
|
|
@@ -155,12 +160,12 @@ function drawScrollerThumb(ctx, opts) {
|
|
|
155
160
|
}
|
|
156
161
|
ctx.restore();
|
|
157
162
|
}
|
|
158
|
-
function drawScrollerInfo(
|
|
159
|
-
const ctx =
|
|
163
|
+
function drawScrollerInfo(overlayContext, opts) {
|
|
164
|
+
const ctx = overlayContext;
|
|
160
165
|
const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
|
|
161
|
-
const { activeThumbType, prevPoint, activePoint } = scrollInfo;
|
|
166
|
+
const { activeThumbType, prevPoint, activePoint, hoverXThumb, hoverYThumb } = scrollInfo;
|
|
162
167
|
const { width, height } = viewSizeInfo;
|
|
163
|
-
const wrapper = calcScrollerInfo(viewScaleInfo, viewSizeInfo);
|
|
168
|
+
const wrapper = calcScrollerInfo({ viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb });
|
|
164
169
|
let xThumbRect = Object.assign({}, wrapper.xThumbRect);
|
|
165
170
|
let yThumbRect = Object.assign({}, wrapper.yThumbRect);
|
|
166
171
|
if (activeThumbType && prevPoint && activePoint) {
|
|
@@ -177,12 +182,12 @@ function drawScrollerInfo(helperContext, opts) {
|
|
|
177
182
|
ctx.fillStyle = wrapper.scrollBarColor;
|
|
178
183
|
ctx.fillRect(0, height - wrapper.lineSize, width, wrapper.lineSize);
|
|
179
184
|
}
|
|
180
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.
|
|
185
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.xThumbColor }));
|
|
181
186
|
if (scrollConfig.showScrollBar === true) {
|
|
182
187
|
ctx.fillStyle = wrapper.scrollBarColor;
|
|
183
188
|
ctx.fillRect(width - wrapper.lineSize, 0, wrapper.lineSize, height);
|
|
184
189
|
}
|
|
185
|
-
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.
|
|
190
|
+
drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.yThumbColor }));
|
|
186
191
|
ctx.globalAlpha = 1;
|
|
187
192
|
return {
|
|
188
193
|
xThumbRect,
|
|
@@ -8,8 +8,12 @@ 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;
|
|
11
12
|
export declare const keyGroupQueue: unique symbol;
|
|
12
13
|
export declare const keyGroupQueueVertexesList: unique symbol;
|
|
14
|
+
export declare const keyIsMoving: unique symbol;
|
|
15
|
+
export declare const keyEnableSelectInGroup: unique symbol;
|
|
16
|
+
export declare const keyEnableSnapToGrid: unique symbol;
|
|
13
17
|
export declare const keyDebugElemCenter: unique symbol;
|
|
14
18
|
export declare const keyDebugStartVertical: unique symbol;
|
|
15
19
|
export declare const keyDebugEndVertical: unique symbol;
|
|
@@ -20,3 +24,11 @@ export declare const selectWrapperBorderWidth = 2;
|
|
|
20
24
|
export declare const resizeControllerBorderWidth = 4;
|
|
21
25
|
export declare const areaBorderWidth = 1;
|
|
22
26
|
export declare const wrapperColor = "#1973ba";
|
|
27
|
+
export declare const lockColor = "#5b5959b5";
|
|
28
|
+
export declare const controllerSize = 10;
|
|
29
|
+
export declare const auxiliaryColor = "#f7276e";
|
|
30
|
+
export declare const referenceColor = "#f7276e";
|
|
31
|
+
export declare const middlewareEventSelect: string;
|
|
32
|
+
export declare const middlewareEventSelectClear: string;
|
|
33
|
+
export declare const middlewareEventSelectInGroup: string;
|
|
34
|
+
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`);
|
|
@@ -20,3 +24,11 @@ export const selectWrapperBorderWidth = 2;
|
|
|
20
24
|
export const resizeControllerBorderWidth = 4;
|
|
21
25
|
export const areaBorderWidth = 1;
|
|
22
26
|
export const wrapperColor = '#1973ba';
|
|
27
|
+
export const lockColor = '#5b5959b5';
|
|
28
|
+
export const controllerSize = 10;
|
|
29
|
+
export const auxiliaryColor = '#f7276e';
|
|
30
|
+
export const referenceColor = '#f7276e';
|
|
31
|
+
export const middlewareEventSelect = '@middleware/select';
|
|
32
|
+
export const middlewareEventSelectClear = '@middleware/select-clear';
|
|
33
|
+
export const middlewareEventSelectInGroup = '@middleware/select-in-group';
|
|
34
|
+
export const middlewareEventSnapToGrid = '@middleware/snap-to-grid';
|
|
@@ -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
|
+
}
|