@idraw/core 0.4.0-beta.16 → 0.4.0-beta.18
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/index.d.ts +5 -2
- package/dist/esm/index.js +3 -2
- 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/ruler/index.d.ts +2 -1
- package/dist/esm/middleware/ruler/index.js +3 -2
- 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/scroller/index.d.ts +2 -1
- 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 +4 -0
- package/dist/esm/middleware/selector/config.js +4 -0
- package/dist/esm/middleware/selector/draw-auxiliary.d.ts +4 -4
- package/dist/esm/middleware/selector/draw-auxiliary.js +26 -11
- 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 +2 -2
- package/dist/esm/middleware/selector/draw-wrapper.js +2 -3
- package/dist/esm/middleware/selector/index.d.ts +3 -0
- package/dist/esm/middleware/selector/index.js +104 -16
- 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 +5 -3
- package/dist/esm/middleware/selector/types.js +1 -1
- package/dist/esm/middleware/selector/util.js +12 -13
- package/dist/index.global.js +1120 -124
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
- package/dist/esm/middleware/selector/auxiliary.d.ts +0 -5
- package/dist/esm/middleware/selector/auxiliary.js +0 -10
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { Data, PointSize, CoreOptions, BoardMiddleware, ViewSizeInfo, CoreEventMap, ViewScaleInfo, LoadItemMap } from '@idraw/types';
|
|
1
|
+
import type { Data, PointSize, CoreOptions, BoardMiddleware, ViewSizeInfo, CoreEventMap, ViewScaleInfo, LoadItemMap, ModifyOptions } from '@idraw/types';
|
|
2
2
|
export { MiddlewareSelector, middlewareEventSelect, middlewareEventSelectClear } from './middleware/selector';
|
|
3
3
|
export { MiddlewareScroller } from './middleware/scroller';
|
|
4
4
|
export { MiddlewareScaler, middlewareEventScale } from './middleware/scaler';
|
|
5
5
|
export { MiddlewareRuler, middlewareEventRuler } from './middleware/ruler';
|
|
6
6
|
export { MiddlewareTextEditor, middlewareEventTextEdit, middlewareEventTextChange } from './middleware/text-editor';
|
|
7
7
|
export { MiddlewareDragger } from './middleware/dragger';
|
|
8
|
+
export { MiddlewareInfo } from './middleware/info';
|
|
8
9
|
export declare class Core<E extends CoreEventMap = CoreEventMap> {
|
|
9
10
|
#private;
|
|
10
11
|
constructor(container: HTMLDivElement, opts: CoreOptions);
|
|
@@ -12,7 +13,9 @@ export declare class Core<E extends CoreEventMap = CoreEventMap> {
|
|
|
12
13
|
destroy(): void;
|
|
13
14
|
use(middleware: BoardMiddleware<any, any>): void;
|
|
14
15
|
disuse(middleware: BoardMiddleware<any, any>): void;
|
|
15
|
-
setData(data: Data
|
|
16
|
+
setData(data: Data, opts?: {
|
|
17
|
+
modifiedOptions?: ModifyOptions;
|
|
18
|
+
}): void;
|
|
16
19
|
getData(): Data | null;
|
|
17
20
|
scale(opts: {
|
|
18
21
|
scale: number;
|
package/dist/esm/index.js
CHANGED
|
@@ -19,6 +19,7 @@ export { MiddlewareScaler, middlewareEventScale } from './middleware/scaler';
|
|
|
19
19
|
export { MiddlewareRuler, middlewareEventRuler } from './middleware/ruler';
|
|
20
20
|
export { MiddlewareTextEditor, middlewareEventTextEdit, middlewareEventTextChange } from './middleware/text-editor';
|
|
21
21
|
export { MiddlewareDragger } from './middleware/dragger';
|
|
22
|
+
export { MiddlewareInfo } from './middleware/info';
|
|
22
23
|
export class Core {
|
|
23
24
|
constructor(container, opts) {
|
|
24
25
|
_Core_instances.add(this);
|
|
@@ -61,9 +62,9 @@ export class Core {
|
|
|
61
62
|
disuse(middleware) {
|
|
62
63
|
__classPrivateFieldGet(this, _Core_board, "f").disuse(middleware);
|
|
63
64
|
}
|
|
64
|
-
setData(data) {
|
|
65
|
+
setData(data, opts) {
|
|
65
66
|
validateElements((data === null || data === void 0 ? void 0 : data.elements) || []);
|
|
66
|
-
__classPrivateFieldGet(this, _Core_board, "f").setData(data);
|
|
67
|
+
__classPrivateFieldGet(this, _Core_board, "f").setData(data, opts);
|
|
67
68
|
}
|
|
68
69
|
getData() {
|
|
69
70
|
return __classPrivateFieldGet(this, _Core_board, "f").getData();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PointSize, ViewContext2D } from '@idraw/types';
|
|
2
|
+
export declare function drawSizeInfoText(ctx: ViewContext2D, opts: {
|
|
3
|
+
point: PointSize;
|
|
4
|
+
rotateCenter: PointSize;
|
|
5
|
+
angle: number;
|
|
6
|
+
text: string;
|
|
7
|
+
fontSize: number;
|
|
8
|
+
lineHeight: number;
|
|
9
|
+
color: string;
|
|
10
|
+
background: string;
|
|
11
|
+
}): void;
|
|
12
|
+
export declare function drawPositionInfoText(ctx: ViewContext2D, opts: {
|
|
13
|
+
point: PointSize;
|
|
14
|
+
rotateCenter: PointSize;
|
|
15
|
+
angle: number;
|
|
16
|
+
text: string;
|
|
17
|
+
fontSize: number;
|
|
18
|
+
lineHeight: number;
|
|
19
|
+
color: string;
|
|
20
|
+
background: string;
|
|
21
|
+
}): void;
|
|
22
|
+
export declare function drawAngleInfoText(ctx: ViewContext2D, opts: {
|
|
23
|
+
point: PointSize;
|
|
24
|
+
rotateCenter: PointSize;
|
|
25
|
+
angle: number;
|
|
26
|
+
text: string;
|
|
27
|
+
fontSize: number;
|
|
28
|
+
lineHeight: number;
|
|
29
|
+
color: string;
|
|
30
|
+
background: string;
|
|
31
|
+
}): void;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { rotateByCenter } from '@idraw/util';
|
|
2
|
+
const fontFamily = 'monospace';
|
|
3
|
+
export function drawSizeInfoText(ctx, opts) {
|
|
4
|
+
const { point, rotateCenter, angle, text, color, background, fontSize, lineHeight } = opts;
|
|
5
|
+
rotateByCenter(ctx, angle, rotateCenter, () => {
|
|
6
|
+
ctx.$setFont({
|
|
7
|
+
fontWeight: '300',
|
|
8
|
+
fontSize,
|
|
9
|
+
fontFamily
|
|
10
|
+
});
|
|
11
|
+
const padding = (lineHeight - fontSize) / 2;
|
|
12
|
+
const textWidth = ctx.$undoPixelRatio(ctx.measureText(text).width);
|
|
13
|
+
const bgStart = {
|
|
14
|
+
x: point.x - textWidth / 2 - padding,
|
|
15
|
+
y: point.y
|
|
16
|
+
};
|
|
17
|
+
const bgEnd = {
|
|
18
|
+
x: bgStart.x + textWidth + padding * 2,
|
|
19
|
+
y: bgStart.y + fontSize + padding
|
|
20
|
+
};
|
|
21
|
+
const textStart = {
|
|
22
|
+
x: point.x - textWidth / 2,
|
|
23
|
+
y: point.y
|
|
24
|
+
};
|
|
25
|
+
ctx.setLineDash([]);
|
|
26
|
+
ctx.fillStyle = background;
|
|
27
|
+
ctx.beginPath();
|
|
28
|
+
ctx.moveTo(bgStart.x, bgStart.y);
|
|
29
|
+
ctx.lineTo(bgEnd.x, bgStart.y);
|
|
30
|
+
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
31
|
+
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
32
|
+
ctx.closePath();
|
|
33
|
+
ctx.fill();
|
|
34
|
+
ctx.fillStyle = color;
|
|
35
|
+
ctx.textBaseline = 'top';
|
|
36
|
+
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
export function drawPositionInfoText(ctx, opts) {
|
|
40
|
+
const { point, rotateCenter, angle, text, color, background, fontSize, lineHeight } = opts;
|
|
41
|
+
rotateByCenter(ctx, angle, rotateCenter, () => {
|
|
42
|
+
ctx.$setFont({
|
|
43
|
+
fontWeight: '300',
|
|
44
|
+
fontSize,
|
|
45
|
+
fontFamily
|
|
46
|
+
});
|
|
47
|
+
const padding = (lineHeight - fontSize) / 2;
|
|
48
|
+
const textWidth = ctx.$undoPixelRatio(ctx.measureText(text).width);
|
|
49
|
+
const bgStart = {
|
|
50
|
+
x: point.x,
|
|
51
|
+
y: point.y
|
|
52
|
+
};
|
|
53
|
+
const bgEnd = {
|
|
54
|
+
x: bgStart.x + textWidth + padding * 2,
|
|
55
|
+
y: bgStart.y + fontSize + padding
|
|
56
|
+
};
|
|
57
|
+
const textStart = {
|
|
58
|
+
x: point.x + padding,
|
|
59
|
+
y: point.y
|
|
60
|
+
};
|
|
61
|
+
ctx.setLineDash([]);
|
|
62
|
+
ctx.fillStyle = background;
|
|
63
|
+
ctx.beginPath();
|
|
64
|
+
ctx.moveTo(bgStart.x, bgStart.y);
|
|
65
|
+
ctx.lineTo(bgEnd.x, bgStart.y);
|
|
66
|
+
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
67
|
+
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
68
|
+
ctx.closePath();
|
|
69
|
+
ctx.fill();
|
|
70
|
+
ctx.fillStyle = color;
|
|
71
|
+
ctx.textBaseline = 'top';
|
|
72
|
+
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
export function drawAngleInfoText(ctx, opts) {
|
|
76
|
+
const { point, rotateCenter, angle, text, color, background, fontSize, lineHeight } = opts;
|
|
77
|
+
rotateByCenter(ctx, angle, rotateCenter, () => {
|
|
78
|
+
ctx.$setFont({
|
|
79
|
+
fontWeight: '300',
|
|
80
|
+
fontSize,
|
|
81
|
+
fontFamily
|
|
82
|
+
});
|
|
83
|
+
const padding = (lineHeight - fontSize) / 2;
|
|
84
|
+
const textWidth = ctx.$undoPixelRatio(ctx.measureText(text).width);
|
|
85
|
+
const bgStart = {
|
|
86
|
+
x: point.x,
|
|
87
|
+
y: point.y
|
|
88
|
+
};
|
|
89
|
+
const bgEnd = {
|
|
90
|
+
x: bgStart.x + textWidth + padding * 2,
|
|
91
|
+
y: bgStart.y + fontSize + padding
|
|
92
|
+
};
|
|
93
|
+
const textStart = {
|
|
94
|
+
x: point.x + padding,
|
|
95
|
+
y: point.y
|
|
96
|
+
};
|
|
97
|
+
ctx.setLineDash([]);
|
|
98
|
+
ctx.fillStyle = background;
|
|
99
|
+
ctx.beginPath();
|
|
100
|
+
ctx.moveTo(bgStart.x, bgStart.y);
|
|
101
|
+
ctx.lineTo(bgEnd.x, bgStart.y);
|
|
102
|
+
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
103
|
+
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
104
|
+
ctx.closePath();
|
|
105
|
+
ctx.fill();
|
|
106
|
+
ctx.fillStyle = color;
|
|
107
|
+
ctx.textBaseline = 'top';
|
|
108
|
+
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { formatNumber, getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot, createUUID, limitAngle, rotatePoint, parseAngleToRadian } from '@idraw/util';
|
|
2
|
+
import { keySelectedElementList, keyActionType, keyGroupQueue } from '../selector';
|
|
3
|
+
import { drawSizeInfoText, drawPositionInfoText, drawAngleInfoText } from './draw-info';
|
|
4
|
+
const infoBackground = '#1973bac6';
|
|
5
|
+
const infoTextColor = '#ffffff';
|
|
6
|
+
const infoFontSize = 10;
|
|
7
|
+
const infoLineHeight = 16;
|
|
8
|
+
export const MiddlewareInfo = (opts) => {
|
|
9
|
+
const { boardContent, calculator } = opts;
|
|
10
|
+
const { helperContext } = boardContent;
|
|
11
|
+
return {
|
|
12
|
+
name: '@middleware/info',
|
|
13
|
+
beforeDrawFrame({ snapshot }) {
|
|
14
|
+
const { sharedStore } = snapshot;
|
|
15
|
+
const selectedElementList = sharedStore[keySelectedElementList];
|
|
16
|
+
const actionType = sharedStore[keyActionType];
|
|
17
|
+
const groupQueue = sharedStore[keyGroupQueue] || [];
|
|
18
|
+
if (selectedElementList.length === 1) {
|
|
19
|
+
const elem = selectedElementList[0];
|
|
20
|
+
if (elem && ['select', 'drag', 'resize'].includes(actionType)) {
|
|
21
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
22
|
+
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
23
|
+
const { x, y, w, h, angle } = elem;
|
|
24
|
+
const totalGroupQueue = [
|
|
25
|
+
...groupQueue,
|
|
26
|
+
...[
|
|
27
|
+
{
|
|
28
|
+
uuid: createUUID(),
|
|
29
|
+
x,
|
|
30
|
+
y,
|
|
31
|
+
w,
|
|
32
|
+
h,
|
|
33
|
+
angle,
|
|
34
|
+
type: 'group',
|
|
35
|
+
detail: { children: [] }
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
];
|
|
39
|
+
const calcOpts = { viewScaleInfo, viewSizeInfo };
|
|
40
|
+
const rangeRectInfo = calculator.calcViewRectInfoFromOrigin(elem.uuid, calcOpts);
|
|
41
|
+
let totalAngle = 0;
|
|
42
|
+
totalGroupQueue.forEach((group) => {
|
|
43
|
+
totalAngle += group.angle || 0;
|
|
44
|
+
});
|
|
45
|
+
const totalRadian = parseAngleToRadian(limitAngle(0 - totalAngle));
|
|
46
|
+
if (rangeRectInfo) {
|
|
47
|
+
const elemCenter = rangeRectInfo === null || rangeRectInfo === void 0 ? void 0 : rangeRectInfo.center;
|
|
48
|
+
const rectInfo = {
|
|
49
|
+
topLeft: rotatePoint(elemCenter, rangeRectInfo.topLeft, totalRadian),
|
|
50
|
+
topRight: rotatePoint(elemCenter, rangeRectInfo.topRight, totalRadian),
|
|
51
|
+
bottomRight: rotatePoint(elemCenter, rangeRectInfo.bottomRight, totalRadian),
|
|
52
|
+
bottomLeft: rotatePoint(elemCenter, rangeRectInfo.bottomLeft, totalRadian),
|
|
53
|
+
center: rotatePoint(elemCenter, rangeRectInfo.center, totalRadian),
|
|
54
|
+
top: rotatePoint(elemCenter, rangeRectInfo.top, totalRadian),
|
|
55
|
+
right: rotatePoint(elemCenter, rangeRectInfo.right, totalRadian),
|
|
56
|
+
bottom: rotatePoint(elemCenter, rangeRectInfo.bottom, totalRadian),
|
|
57
|
+
left: rotatePoint(elemCenter, rangeRectInfo.left, totalRadian)
|
|
58
|
+
};
|
|
59
|
+
const x = formatNumber(elem.x, { decimalPlaces: 2 });
|
|
60
|
+
const y = formatNumber(elem.y, { decimalPlaces: 2 });
|
|
61
|
+
const w = formatNumber(elem.w, { decimalPlaces: 2 });
|
|
62
|
+
const h = formatNumber(elem.h, { decimalPlaces: 2 });
|
|
63
|
+
const xyText = `${formatNumber(x, { decimalPlaces: 0 })},${formatNumber(y, { decimalPlaces: 0 })}`;
|
|
64
|
+
const whText = `${formatNumber(w, { decimalPlaces: 0 })}x${formatNumber(h, { decimalPlaces: 0 })}`;
|
|
65
|
+
const angleText = `${formatNumber(elem.angle || 0, { decimalPlaces: 0 })}°`;
|
|
66
|
+
drawSizeInfoText(helperContext, {
|
|
67
|
+
point: {
|
|
68
|
+
x: rectInfo.bottom.x,
|
|
69
|
+
y: rectInfo.bottom.y + infoFontSize
|
|
70
|
+
},
|
|
71
|
+
rotateCenter: rectInfo.center,
|
|
72
|
+
angle: totalAngle,
|
|
73
|
+
text: whText,
|
|
74
|
+
fontSize: infoFontSize,
|
|
75
|
+
lineHeight: infoLineHeight,
|
|
76
|
+
color: infoTextColor,
|
|
77
|
+
background: infoBackground
|
|
78
|
+
});
|
|
79
|
+
drawPositionInfoText(helperContext, {
|
|
80
|
+
point: {
|
|
81
|
+
x: rectInfo.topLeft.x,
|
|
82
|
+
y: rectInfo.topLeft.y - infoFontSize * 2
|
|
83
|
+
},
|
|
84
|
+
rotateCenter: rectInfo.center,
|
|
85
|
+
angle: totalAngle,
|
|
86
|
+
text: xyText,
|
|
87
|
+
fontSize: infoFontSize,
|
|
88
|
+
lineHeight: infoLineHeight,
|
|
89
|
+
color: infoTextColor,
|
|
90
|
+
background: infoBackground
|
|
91
|
+
});
|
|
92
|
+
drawAngleInfoText(helperContext, {
|
|
93
|
+
point: {
|
|
94
|
+
x: rectInfo.top.x + infoFontSize,
|
|
95
|
+
y: rectInfo.top.y - infoFontSize * 2
|
|
96
|
+
},
|
|
97
|
+
rotateCenter: rectInfo.center,
|
|
98
|
+
angle: totalAngle,
|
|
99
|
+
text: angleText,
|
|
100
|
+
fontSize: infoFontSize,
|
|
101
|
+
lineHeight: infoLineHeight,
|
|
102
|
+
color: infoTextColor,
|
|
103
|
+
background: infoBackground
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { keySelectedElementList, keyActionType, keyGroupQueue } from '../selector';
|
|
2
|
+
import type { DeepSelectorSharedStorage } from '../selector';
|
|
3
|
+
export type DeepInfoSharedStorage = Pick<DeepSelectorSharedStorage, typeof keySelectedElementList | typeof keyActionType | typeof keyGroupQueue>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { BoardMiddleware, CoreEventMap } from '@idraw/types';
|
|
2
|
+
import type { DeepRulerSharedStorage } from './types';
|
|
2
3
|
export declare const middlewareEventRuler = "@middleware/show-ruler";
|
|
3
|
-
export declare const MiddlewareRuler: BoardMiddleware<
|
|
4
|
+
export declare const MiddlewareRuler: BoardMiddleware<DeepRulerSharedStorage, CoreEventMap>;
|
|
@@ -1,8 +1,8 @@
|
|
|
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 { boardContent, viewer, eventHub } = opts;
|
|
5
|
+
const { boardContent, viewer, eventHub, calculator } = opts;
|
|
6
6
|
const { helperContext, underContext } = boardContent;
|
|
7
7
|
let show = true;
|
|
8
8
|
let showGrid = true;
|
|
@@ -29,6 +29,7 @@ export const MiddlewareRuler = (opts) => {
|
|
|
29
29
|
if (show === true) {
|
|
30
30
|
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
31
31
|
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
32
|
+
drawScrollerSelectedArea(helperContext, { snapshot, calculator });
|
|
32
33
|
drawRulerBackground(helperContext, { viewScaleInfo, viewSizeInfo });
|
|
33
34
|
const xList = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
|
|
34
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
|
+
}
|
|
@@ -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,6 +8,9 @@ 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;
|
|
13
16
|
export declare const keyIsMoving: unique symbol;
|
|
@@ -24,3 +27,4 @@ export declare const wrapperColor = "#1973ba";
|
|
|
24
27
|
export declare const lockColor = "#5b5959b5";
|
|
25
28
|
export declare const controllerSize = 10;
|
|
26
29
|
export declare const auxiliaryColor = "#f7276e";
|
|
30
|
+
export declare const referenceColor = "#f7276e";
|
|
@@ -8,6 +8,9 @@ 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`);
|
|
13
16
|
export const keyIsMoving = Symbol(`${key}_isMoving`);
|
|
@@ -24,3 +27,4 @@ export const wrapperColor = '#1973ba';
|
|
|
24
27
|
export const lockColor = '#5b5959b5';
|
|
25
28
|
export const controllerSize = 10;
|
|
26
29
|
export const auxiliaryColor = '#f7276e';
|
|
30
|
+
export const referenceColor = '#f7276e';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ViewContext2D,
|
|
2
|
-
export declare function
|
|
3
|
-
|
|
1
|
+
import type { ViewContext2D, Element, ViewScaleInfo, ViewSizeInfo, ViewCalculator } from '@idraw/types';
|
|
2
|
+
export declare function drawAuxiliaryExperimentBox(ctx: ViewContext2D, opts: {
|
|
3
|
+
calculator: ViewCalculator;
|
|
4
4
|
element: Element | null;
|
|
5
|
-
groupQueue: Element<'group'>[];
|
|
6
5
|
viewScaleInfo: ViewScaleInfo;
|
|
6
|
+
viewSizeInfo: ViewSizeInfo;
|
|
7
7
|
}): void;
|
|
@@ -1,25 +1,40 @@
|
|
|
1
|
-
import { getElementViewRectInfo } from './auxiliary';
|
|
2
1
|
import { auxiliaryColor } from './config';
|
|
3
2
|
import { drawLine, drawCrossByCenter } from './draw-base';
|
|
4
|
-
|
|
5
|
-
const
|
|
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;
|
|
6
16
|
if (!element) {
|
|
7
17
|
return;
|
|
8
18
|
}
|
|
9
|
-
const viewRectInfo =
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
19
|
+
const viewRectInfo = calculator.calcViewRectInfoFromRange(element.uuid, { viewScaleInfo, viewSizeInfo });
|
|
20
|
+
if (!viewRectInfo) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
13
23
|
const lineOpts = {
|
|
14
24
|
borderColor: auxiliaryColor,
|
|
15
25
|
borderWidth: 1,
|
|
16
26
|
lineDash: []
|
|
17
27
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
drawLine(ctx,
|
|
21
|
-
drawLine(ctx,
|
|
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);
|
|
22
36
|
const crossOpts = Object.assign(Object.assign({}, lineOpts), { size: 6 });
|
|
37
|
+
drawCrossByCenter(ctx, viewRectInfo.center, crossOpts);
|
|
23
38
|
drawCrossByCenter(ctx, viewRectInfo.topLeft, crossOpts);
|
|
24
39
|
drawCrossByCenter(ctx, viewRectInfo.topRight, crossOpts);
|
|
25
40
|
drawCrossByCenter(ctx, viewRectInfo.bottomLeft, crossOpts);
|
|
@@ -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,4 +1,4 @@
|
|
|
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;
|
|
@@ -14,7 +14,7 @@ export declare function drawSelectedElementControllersVertexes(ctx: ViewContext2
|
|
|
14
14
|
viewScaleInfo: ViewScaleInfo;
|
|
15
15
|
viewSizeInfo: ViewSizeInfo;
|
|
16
16
|
element: Element | null;
|
|
17
|
-
|
|
17
|
+
calculator: ViewCalculator;
|
|
18
18
|
}): void;
|
|
19
19
|
export declare function drawElementListShadows(ctx: ViewContext2D, elements: Element<ElementType>[], opts?: Omit<RendererDrawElementOptions, 'loader'>): void;
|
|
20
20
|
export declare function drawArea(ctx: ViewContext2D, opts: {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rotateElementVertexes, calcViewPointSize, calcViewVertexes } from '@idraw/util';
|
|
1
|
+
import { rotateElementVertexes, calcViewPointSize, calcViewVertexes, calcViewElementSize } from '@idraw/util';
|
|
2
2
|
import { resizeControllerBorderWidth, areaBorderWidth, wrapperColor, selectWrapperBorderWidth, lockColor, controllerSize } from './config';
|
|
3
3
|
import { drawVertexes, drawLine, drawCircleController, drawCrossVertexes } from './draw-base';
|
|
4
4
|
export function drawHoverVertexesWrapper(ctx, vertexes, opts) {
|
|
@@ -51,8 +51,7 @@ export function drawElementListShadows(ctx, elements, opts) {
|
|
|
51
51
|
let { x, y, w, h } = elem;
|
|
52
52
|
const { angle = 0 } = elem;
|
|
53
53
|
if (opts === null || opts === void 0 ? void 0 : opts.calculator) {
|
|
54
|
-
const {
|
|
55
|
-
const size = calculator.elementSize({ x, y, w, h }, opts.viewScaleInfo, opts.viewSizeInfo);
|
|
54
|
+
const size = calcViewElementSize({ x, y, w, h }, opts);
|
|
56
55
|
x = size.x;
|
|
57
56
|
y = size.y;
|
|
58
57
|
w = size.w;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { CoreEventMap } from '@idraw/types';
|
|
2
2
|
import type { BoardMiddleware, DeepSelectorSharedStorage } from './types';
|
|
3
|
+
import { keyActionType, keyResizeType, keyGroupQueue, keySelectedElementList } from './config';
|
|
4
|
+
export { keySelectedElementList, keyActionType, keyResizeType, keyGroupQueue };
|
|
5
|
+
export type { DeepSelectorSharedStorage };
|
|
3
6
|
export declare const middlewareEventSelect: string;
|
|
4
7
|
export declare const middlewareEventSelectClear: string;
|
|
5
8
|
export declare const MiddlewareSelector: BoardMiddleware<DeepSelectorSharedStorage, CoreEventMap>;
|