@idraw/core 0.4.0-beta.3 → 0.4.0-beta.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/config.d.ts +1 -0
- package/dist/esm/config.js +1 -0
- package/dist/esm/index.d.ts +17 -7
- package/dist/esm/index.js +31 -10
- package/dist/esm/lib/cursor-image.d.ts +1 -0
- package/dist/esm/lib/cursor-image.js +1 -0
- package/dist/esm/lib/cursor.d.ts +3 -12
- package/dist/esm/lib/cursor.js +136 -112
- package/dist/esm/middleware/dragger/index.d.ts +2 -2
- package/dist/esm/middleware/dragger/index.js +1 -0
- package/dist/esm/middleware/info/config.d.ts +4 -0
- package/dist/esm/middleware/info/config.js +8 -0
- package/dist/esm/middleware/info/draw-info.d.ts +29 -0
- package/dist/esm/middleware/info/draw-info.js +113 -0
- package/dist/esm/middleware/info/index.d.ts +3 -0
- package/dist/esm/middleware/info/index.js +112 -0
- package/dist/esm/middleware/info/types.d.ts +3 -0
- package/dist/esm/middleware/info/types.js +1 -0
- package/dist/esm/middleware/layout-selector/config.d.ts +9 -0
- package/dist/esm/middleware/layout-selector/config.js +9 -0
- package/dist/esm/middleware/layout-selector/index.d.ts +5 -0
- package/dist/esm/middleware/layout-selector/index.js +332 -0
- package/dist/esm/middleware/layout-selector/types.d.ts +15 -0
- package/dist/esm/middleware/layout-selector/types.js +2 -0
- package/dist/esm/middleware/layout-selector/util.d.ts +8 -0
- package/dist/esm/middleware/layout-selector/util.js +108 -0
- package/dist/esm/middleware/ruler/config.d.ts +7 -0
- package/dist/esm/middleware/ruler/config.js +21 -0
- package/dist/esm/middleware/ruler/index.d.ts +3 -2
- package/dist/esm/middleware/ruler/index.js +27 -11
- package/dist/esm/middleware/ruler/types.d.ts +3 -0
- package/dist/esm/middleware/ruler/types.js +1 -0
- package/dist/esm/middleware/ruler/util.d.ts +20 -4
- package/dist/esm/middleware/ruler/util.js +92 -21
- package/dist/esm/middleware/scaler/index.d.ts +2 -2
- package/dist/esm/middleware/scaler/index.js +1 -0
- package/dist/esm/middleware/scroller/config.d.ts +4 -0
- package/dist/esm/middleware/scroller/config.js +10 -0
- package/dist/esm/middleware/scroller/index.d.ts +3 -2
- package/dist/esm/middleware/scroller/index.js +44 -6
- package/dist/esm/middleware/scroller/types.d.ts +11 -0
- package/dist/esm/middleware/scroller/types.js +1 -0
- package/dist/esm/middleware/scroller/util.d.ts +3 -2
- package/dist/esm/middleware/scroller/util.js +32 -44
- package/dist/esm/middleware/selector/config.d.ts +11 -1
- package/dist/esm/middleware/selector/config.js +19 -1
- package/dist/esm/middleware/selector/draw-auxiliary.d.ts +1 -0
- package/dist/esm/middleware/selector/draw-auxiliary.js +12 -0
- package/dist/esm/middleware/selector/draw-base.d.ts +30 -0
- package/dist/esm/middleware/selector/draw-base.js +100 -0
- package/dist/esm/middleware/selector/draw-reference.d.ts +7 -0
- package/dist/esm/middleware/selector/draw-reference.js +31 -0
- package/dist/esm/middleware/selector/draw-wrapper.d.ts +16 -2
- package/dist/esm/middleware/selector/draw-wrapper.js +52 -35
- package/dist/esm/middleware/selector/index.d.ts +7 -4
- package/dist/esm/middleware/selector/index.js +287 -47
- package/dist/esm/middleware/selector/reference.d.ts +13 -0
- package/dist/esm/middleware/selector/reference.js +267 -0
- package/dist/esm/middleware/selector/types.d.ts +9 -4
- package/dist/esm/middleware/selector/types.js +2 -1
- package/dist/esm/middleware/selector/util.d.ts +11 -2
- package/dist/esm/middleware/selector/util.js +36 -14
- package/dist/esm/middleware/text-editor/index.d.ts +20 -2
- package/dist/esm/middleware/text-editor/index.js +92 -16
- package/dist/index.global.js +3827 -1006
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { rotateByCenter } from '@idraw/util';
|
|
2
|
+
const fontFamily = 'monospace';
|
|
3
|
+
export function drawSizeInfoText(ctx, opts) {
|
|
4
|
+
const { point, rotateCenter, angle, text, style, fontSize, lineHeight } = opts;
|
|
5
|
+
const { textColor, textBackground } = style;
|
|
6
|
+
rotateByCenter(ctx, angle, rotateCenter, () => {
|
|
7
|
+
ctx.$setFont({
|
|
8
|
+
fontWeight: '300',
|
|
9
|
+
fontSize,
|
|
10
|
+
fontFamily
|
|
11
|
+
});
|
|
12
|
+
const padding = (lineHeight - fontSize) / 2;
|
|
13
|
+
const textWidth = ctx.$undoPixelRatio(ctx.measureText(text).width);
|
|
14
|
+
const bgStart = {
|
|
15
|
+
x: point.x - textWidth / 2 - padding,
|
|
16
|
+
y: point.y
|
|
17
|
+
};
|
|
18
|
+
const bgEnd = {
|
|
19
|
+
x: bgStart.x + textWidth + padding * 2,
|
|
20
|
+
y: bgStart.y + fontSize + padding
|
|
21
|
+
};
|
|
22
|
+
const textStart = {
|
|
23
|
+
x: point.x - textWidth / 2,
|
|
24
|
+
y: point.y
|
|
25
|
+
};
|
|
26
|
+
ctx.setLineDash([]);
|
|
27
|
+
ctx.fillStyle = textBackground;
|
|
28
|
+
ctx.beginPath();
|
|
29
|
+
ctx.moveTo(bgStart.x, bgStart.y);
|
|
30
|
+
ctx.lineTo(bgEnd.x, bgStart.y);
|
|
31
|
+
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
32
|
+
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
33
|
+
ctx.closePath();
|
|
34
|
+
ctx.fill();
|
|
35
|
+
ctx.fillStyle = textColor;
|
|
36
|
+
ctx.textBaseline = 'top';
|
|
37
|
+
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
export function drawPositionInfoText(ctx, opts) {
|
|
41
|
+
const { point, rotateCenter, angle, text, style, fontSize, lineHeight } = opts;
|
|
42
|
+
const { textBackground, textColor } = style;
|
|
43
|
+
rotateByCenter(ctx, angle, rotateCenter, () => {
|
|
44
|
+
ctx.$setFont({
|
|
45
|
+
fontWeight: '300',
|
|
46
|
+
fontSize,
|
|
47
|
+
fontFamily
|
|
48
|
+
});
|
|
49
|
+
const padding = (lineHeight - fontSize) / 2;
|
|
50
|
+
const textWidth = ctx.$undoPixelRatio(ctx.measureText(text).width);
|
|
51
|
+
const bgStart = {
|
|
52
|
+
x: point.x,
|
|
53
|
+
y: point.y
|
|
54
|
+
};
|
|
55
|
+
const bgEnd = {
|
|
56
|
+
x: bgStart.x + textWidth + padding * 2,
|
|
57
|
+
y: bgStart.y + fontSize + padding
|
|
58
|
+
};
|
|
59
|
+
const textStart = {
|
|
60
|
+
x: point.x + padding,
|
|
61
|
+
y: point.y
|
|
62
|
+
};
|
|
63
|
+
ctx.setLineDash([]);
|
|
64
|
+
ctx.fillStyle = textBackground;
|
|
65
|
+
ctx.beginPath();
|
|
66
|
+
ctx.moveTo(bgStart.x, bgStart.y);
|
|
67
|
+
ctx.lineTo(bgEnd.x, bgStart.y);
|
|
68
|
+
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
69
|
+
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
70
|
+
ctx.closePath();
|
|
71
|
+
ctx.fill();
|
|
72
|
+
ctx.fillStyle = textColor;
|
|
73
|
+
ctx.textBaseline = 'top';
|
|
74
|
+
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function drawAngleInfoText(ctx, opts) {
|
|
78
|
+
const { point, rotateCenter, angle, text, style, fontSize, lineHeight } = opts;
|
|
79
|
+
const { textBackground, textColor } = style;
|
|
80
|
+
rotateByCenter(ctx, angle, rotateCenter, () => {
|
|
81
|
+
ctx.$setFont({
|
|
82
|
+
fontWeight: '300',
|
|
83
|
+
fontSize,
|
|
84
|
+
fontFamily
|
|
85
|
+
});
|
|
86
|
+
const padding = (lineHeight - fontSize) / 2;
|
|
87
|
+
const textWidth = ctx.$undoPixelRatio(ctx.measureText(text).width);
|
|
88
|
+
const bgStart = {
|
|
89
|
+
x: point.x,
|
|
90
|
+
y: point.y
|
|
91
|
+
};
|
|
92
|
+
const bgEnd = {
|
|
93
|
+
x: bgStart.x + textWidth + padding * 2,
|
|
94
|
+
y: bgStart.y + fontSize + padding
|
|
95
|
+
};
|
|
96
|
+
const textStart = {
|
|
97
|
+
x: point.x + padding,
|
|
98
|
+
y: point.y
|
|
99
|
+
};
|
|
100
|
+
ctx.setLineDash([]);
|
|
101
|
+
ctx.fillStyle = textBackground;
|
|
102
|
+
ctx.beginPath();
|
|
103
|
+
ctx.moveTo(bgStart.x, bgStart.y);
|
|
104
|
+
ctx.lineTo(bgEnd.x, bgStart.y);
|
|
105
|
+
ctx.lineTo(bgEnd.x, bgEnd.y);
|
|
106
|
+
ctx.lineTo(bgStart.x, bgEnd.y);
|
|
107
|
+
ctx.closePath();
|
|
108
|
+
ctx.fill();
|
|
109
|
+
ctx.fillStyle = textColor;
|
|
110
|
+
ctx.textBaseline = 'top';
|
|
111
|
+
ctx.fillText(text, textStart.x, textStart.y + padding);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
import { defaltStyle } from './config';
|
|
5
|
+
const infoFontSize = 10;
|
|
6
|
+
const infoLineHeight = 16;
|
|
7
|
+
export const MiddlewareInfo = (opts, config) => {
|
|
8
|
+
const { boardContent, calculator } = opts;
|
|
9
|
+
const { overlayContext } = boardContent;
|
|
10
|
+
const innerConfig = Object.assign(Object.assign({}, defaltStyle), config);
|
|
11
|
+
const { textBackground, textColor } = innerConfig;
|
|
12
|
+
const style = {
|
|
13
|
+
textBackground,
|
|
14
|
+
textColor
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
name: '@middleware/info',
|
|
18
|
+
beforeDrawFrame({ snapshot }) {
|
|
19
|
+
const { sharedStore } = snapshot;
|
|
20
|
+
const selectedElementList = sharedStore[keySelectedElementList];
|
|
21
|
+
const actionType = sharedStore[keyActionType];
|
|
22
|
+
const groupQueue = sharedStore[keyGroupQueue] || [];
|
|
23
|
+
if (selectedElementList.length === 1) {
|
|
24
|
+
const elem = selectedElementList[0];
|
|
25
|
+
if (elem && ['select', 'drag', 'resize'].includes(actionType)) {
|
|
26
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
27
|
+
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
28
|
+
const { x, y, w, h, angle } = elem;
|
|
29
|
+
const totalGroupQueue = [
|
|
30
|
+
...groupQueue,
|
|
31
|
+
...[
|
|
32
|
+
{
|
|
33
|
+
uuid: createUUID(),
|
|
34
|
+
x,
|
|
35
|
+
y,
|
|
36
|
+
w,
|
|
37
|
+
h,
|
|
38
|
+
angle,
|
|
39
|
+
type: 'group',
|
|
40
|
+
detail: { children: [] }
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
];
|
|
44
|
+
const calcOpts = { viewScaleInfo, viewSizeInfo };
|
|
45
|
+
const rangeRectInfo = calculator.calcViewRectInfoFromOrigin(elem.uuid, calcOpts);
|
|
46
|
+
let totalAngle = 0;
|
|
47
|
+
totalGroupQueue.forEach((group) => {
|
|
48
|
+
totalAngle += group.angle || 0;
|
|
49
|
+
});
|
|
50
|
+
const totalRadian = parseAngleToRadian(limitAngle(0 - totalAngle));
|
|
51
|
+
if (rangeRectInfo) {
|
|
52
|
+
const elemCenter = rangeRectInfo === null || rangeRectInfo === void 0 ? void 0 : rangeRectInfo.center;
|
|
53
|
+
const rectInfo = {
|
|
54
|
+
topLeft: rotatePoint(elemCenter, rangeRectInfo.topLeft, totalRadian),
|
|
55
|
+
topRight: rotatePoint(elemCenter, rangeRectInfo.topRight, totalRadian),
|
|
56
|
+
bottomRight: rotatePoint(elemCenter, rangeRectInfo.bottomRight, totalRadian),
|
|
57
|
+
bottomLeft: rotatePoint(elemCenter, rangeRectInfo.bottomLeft, totalRadian),
|
|
58
|
+
center: rotatePoint(elemCenter, rangeRectInfo.center, totalRadian),
|
|
59
|
+
top: rotatePoint(elemCenter, rangeRectInfo.top, totalRadian),
|
|
60
|
+
right: rotatePoint(elemCenter, rangeRectInfo.right, totalRadian),
|
|
61
|
+
bottom: rotatePoint(elemCenter, rangeRectInfo.bottom, totalRadian),
|
|
62
|
+
left: rotatePoint(elemCenter, rangeRectInfo.left, totalRadian)
|
|
63
|
+
};
|
|
64
|
+
const x = formatNumber(elem.x, { decimalPlaces: 2 });
|
|
65
|
+
const y = formatNumber(elem.y, { decimalPlaces: 2 });
|
|
66
|
+
const w = formatNumber(elem.w, { decimalPlaces: 2 });
|
|
67
|
+
const h = formatNumber(elem.h, { decimalPlaces: 2 });
|
|
68
|
+
const xyText = `${formatNumber(x, { decimalPlaces: 0 })},${formatNumber(y, { decimalPlaces: 0 })}`;
|
|
69
|
+
const whText = `${formatNumber(w, { decimalPlaces: 0 })}x${formatNumber(h, { decimalPlaces: 0 })}`;
|
|
70
|
+
const angleText = `${formatNumber(elem.angle || 0, { decimalPlaces: 0 })}°`;
|
|
71
|
+
drawSizeInfoText(overlayContext, {
|
|
72
|
+
point: {
|
|
73
|
+
x: rectInfo.bottom.x,
|
|
74
|
+
y: rectInfo.bottom.y + infoFontSize
|
|
75
|
+
},
|
|
76
|
+
rotateCenter: rectInfo.center,
|
|
77
|
+
angle: totalAngle,
|
|
78
|
+
text: whText,
|
|
79
|
+
fontSize: infoFontSize,
|
|
80
|
+
lineHeight: infoLineHeight,
|
|
81
|
+
style
|
|
82
|
+
});
|
|
83
|
+
drawPositionInfoText(overlayContext, {
|
|
84
|
+
point: {
|
|
85
|
+
x: rectInfo.topLeft.x,
|
|
86
|
+
y: rectInfo.topLeft.y - infoFontSize * 2
|
|
87
|
+
},
|
|
88
|
+
rotateCenter: rectInfo.center,
|
|
89
|
+
angle: totalAngle,
|
|
90
|
+
text: xyText,
|
|
91
|
+
fontSize: infoFontSize,
|
|
92
|
+
lineHeight: infoLineHeight,
|
|
93
|
+
style
|
|
94
|
+
});
|
|
95
|
+
drawAngleInfoText(overlayContext, {
|
|
96
|
+
point: {
|
|
97
|
+
x: rectInfo.top.x + infoFontSize,
|
|
98
|
+
y: rectInfo.top.y - infoFontSize * 2
|
|
99
|
+
},
|
|
100
|
+
rotateCenter: rectInfo.center,
|
|
101
|
+
angle: totalAngle,
|
|
102
|
+
text: angleText,
|
|
103
|
+
fontSize: infoFontSize,
|
|
104
|
+
lineHeight: infoLineHeight,
|
|
105
|
+
style
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
@@ -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 {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const key = "LAYOUT_SELECT";
|
|
2
|
+
export declare const keyLayoutActionType: unique symbol;
|
|
3
|
+
export declare const keyLayoutControlType: unique symbol;
|
|
4
|
+
export declare const keyLayoutController: unique symbol;
|
|
5
|
+
export declare const keyLayoutIsHover: unique symbol;
|
|
6
|
+
export declare const keyLayoutIsSelected: unique symbol;
|
|
7
|
+
export declare const selectColor = "#b331c9";
|
|
8
|
+
export declare const disableColor = "#5b5959b5";
|
|
9
|
+
export declare const controllerSize = 10;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const key = 'LAYOUT_SELECT';
|
|
2
|
+
export const keyLayoutActionType = Symbol(`${key}_layoutActionType`);
|
|
3
|
+
export const keyLayoutControlType = Symbol(`${key}_layoutControlType`);
|
|
4
|
+
export const keyLayoutController = Symbol(`${key}_layoutController`);
|
|
5
|
+
export const keyLayoutIsHover = Symbol(`${key}_layoutIsHover`);
|
|
6
|
+
export const keyLayoutIsSelected = Symbol(`${key}_layoutIsSelected`);
|
|
7
|
+
export const selectColor = '#b331c9';
|
|
8
|
+
export const disableColor = '#5b5959b5';
|
|
9
|
+
export const controllerSize = 10;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BoardMiddleware } from '@idraw/types';
|
|
2
|
+
import type { LayoutSelectorSharedStorage } from './types';
|
|
3
|
+
import { keyLayoutIsSelected } from './config';
|
|
4
|
+
export { keyLayoutIsSelected };
|
|
5
|
+
export declare const MiddlewareLayoutSelector: BoardMiddleware<LayoutSelectorSharedStorage>;
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
import { calcLayoutSizeController, isViewPointInVertexes, getViewScaleInfoFromSnapshot, isViewPointInElementSize, calcViewElementSize } from '@idraw/util';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutController, keyLayoutControlType, keyLayoutIsHover, keyLayoutIsSelected, controllerSize } from './config';
|
|
3
|
+
import { keyActionType as keyElementActionType, keyHoverElement, middlewareEventSelectClear } from '../selector';
|
|
4
|
+
import { drawLayoutController, drawLayoutHover } from './util';
|
|
5
|
+
import { eventChange } from '../../config';
|
|
6
|
+
export { keyLayoutIsSelected };
|
|
7
|
+
export const MiddlewareLayoutSelector = (opts) => {
|
|
8
|
+
const { sharer, boardContent, calculator, viewer, eventHub } = opts;
|
|
9
|
+
const { overlayContext } = boardContent;
|
|
10
|
+
let prevPoint = null;
|
|
11
|
+
let prevIsHover = null;
|
|
12
|
+
let prevIsSelected = null;
|
|
13
|
+
let isBusy = null;
|
|
14
|
+
const clear = () => {
|
|
15
|
+
prevPoint = null;
|
|
16
|
+
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
17
|
+
sharer.setSharedStorage(keyLayoutControlType, null);
|
|
18
|
+
sharer.setSharedStorage(keyLayoutController, null);
|
|
19
|
+
sharer.setSharedStorage(keyLayoutIsHover, null);
|
|
20
|
+
sharer.setSharedStorage(keyLayoutIsSelected, null);
|
|
21
|
+
prevIsHover = null;
|
|
22
|
+
prevIsSelected = null;
|
|
23
|
+
isBusy = null;
|
|
24
|
+
};
|
|
25
|
+
const isInElementHover = () => {
|
|
26
|
+
const hoverElement = sharer.getSharedStorage(keyHoverElement);
|
|
27
|
+
if (hoverElement) {
|
|
28
|
+
clear();
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
const isInElementAction = () => {
|
|
34
|
+
const elementActionType = sharer.getSharedStorage(keyElementActionType);
|
|
35
|
+
if (elementActionType && elementActionType !== 'area') {
|
|
36
|
+
clear();
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
};
|
|
41
|
+
const getLayoutSize = () => {
|
|
42
|
+
const data = sharer.getActiveStorage('data');
|
|
43
|
+
if (data === null || data === void 0 ? void 0 : data.layout) {
|
|
44
|
+
const { x, y, w, h } = data.layout;
|
|
45
|
+
return { x, y, w, h };
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
49
|
+
const isInLayout = (p) => {
|
|
50
|
+
const size = getLayoutSize();
|
|
51
|
+
if (size) {
|
|
52
|
+
const { x, y, w, h } = size;
|
|
53
|
+
const viewScaleInfo = sharer.getActiveViewScaleInfo();
|
|
54
|
+
const viewSize = calcViewElementSize({
|
|
55
|
+
x: x - controllerSize / 2,
|
|
56
|
+
y: y - controllerSize / 2,
|
|
57
|
+
w: w + controllerSize,
|
|
58
|
+
h: h + controllerSize
|
|
59
|
+
}, { viewScaleInfo });
|
|
60
|
+
return isViewPointInElementSize(p, viewSize);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
64
|
+
const resetController = () => {
|
|
65
|
+
const viewScaleInfo = sharer.getActiveViewScaleInfo();
|
|
66
|
+
const size = getLayoutSize();
|
|
67
|
+
if (size) {
|
|
68
|
+
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
|
|
69
|
+
sharer.setSharedStorage(keyLayoutController, controller);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
sharer.setSharedStorage(keyLayoutController, null);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const resetControlType = (e) => {
|
|
76
|
+
const data = sharer.getActiveStorage('data');
|
|
77
|
+
const controller = sharer.getSharedStorage(keyLayoutController);
|
|
78
|
+
if (controller && (data === null || data === void 0 ? void 0 : data.layout) && (e === null || e === void 0 ? void 0 : e.point)) {
|
|
79
|
+
let layoutControlType = null;
|
|
80
|
+
if (controller) {
|
|
81
|
+
const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = controller;
|
|
82
|
+
const list = [topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left];
|
|
83
|
+
for (let i = 0; i < list.length; i++) {
|
|
84
|
+
const item = list[i];
|
|
85
|
+
if (isViewPointInVertexes(e.point, item.vertexes)) {
|
|
86
|
+
layoutControlType = `${item.type}`;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (layoutControlType) {
|
|
91
|
+
sharer.setSharedStorage(keyLayoutControlType, layoutControlType);
|
|
92
|
+
eventHub.trigger(middlewareEventSelectClear, {});
|
|
93
|
+
return layoutControlType;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
};
|
|
99
|
+
const updateCursor = (controlType) => {
|
|
100
|
+
if (isBusy === true) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
eventHub.trigger('cursor', {
|
|
104
|
+
type: controlType ? `resize-${controlType}` : controlType,
|
|
105
|
+
groupQueue: [],
|
|
106
|
+
element: getLayoutSize()
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
return {
|
|
110
|
+
name: '@middleware/layout-selector',
|
|
111
|
+
use: () => {
|
|
112
|
+
clear();
|
|
113
|
+
resetController();
|
|
114
|
+
},
|
|
115
|
+
hover: (e) => {
|
|
116
|
+
if (isBusy === true) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (isInElementAction()) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (isInElementHover()) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (isInLayout(e.point)) {
|
|
126
|
+
sharer.setSharedStorage(keyLayoutIsHover, true);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
sharer.setSharedStorage(keyLayoutIsHover, false);
|
|
130
|
+
if (prevIsHover === true) {
|
|
131
|
+
viewer.drawFrame();
|
|
132
|
+
prevIsHover = false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
if (sharer.getSharedStorage(keyLayoutIsSelected) === true) {
|
|
136
|
+
const prevLayoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
137
|
+
const data = sharer.getActiveStorage('data');
|
|
138
|
+
if (data === null || data === void 0 ? void 0 : data.layout) {
|
|
139
|
+
if (prevLayoutActionType !== 'resize') {
|
|
140
|
+
resetController();
|
|
141
|
+
const layoutControlType = resetControlType(e);
|
|
142
|
+
if (layoutControlType) {
|
|
143
|
+
updateCursor(layoutControlType);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
updateCursor();
|
|
147
|
+
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const layoutControlType = resetControlType(e);
|
|
152
|
+
updateCursor(layoutControlType);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (sharer.getSharedStorage(keyLayoutIsHover) && !prevIsHover) {
|
|
158
|
+
viewer.drawFrame();
|
|
159
|
+
}
|
|
160
|
+
prevIsHover = sharer.getSharedStorage(keyLayoutIsHover);
|
|
161
|
+
},
|
|
162
|
+
pointStart: (e) => {
|
|
163
|
+
if (isInElementAction()) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (isInLayout(e.point)) {
|
|
167
|
+
sharer.setSharedStorage(keyLayoutIsSelected, true);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
if (prevIsSelected === true) {
|
|
171
|
+
clear();
|
|
172
|
+
viewer.drawFrame();
|
|
173
|
+
}
|
|
174
|
+
sharer.setSharedStorage(keyLayoutIsSelected, false);
|
|
175
|
+
}
|
|
176
|
+
resetController();
|
|
177
|
+
const layoutControlType = resetControlType(e);
|
|
178
|
+
prevPoint = e.point;
|
|
179
|
+
if (layoutControlType) {
|
|
180
|
+
sharer.setSharedStorage(keyLayoutActionType, 'resize');
|
|
181
|
+
}
|
|
182
|
+
if (sharer.getSharedStorage(keyLayoutIsSelected) === true && !prevIsSelected) {
|
|
183
|
+
viewer.drawFrame();
|
|
184
|
+
}
|
|
185
|
+
prevIsSelected = sharer.getSharedStorage(keyLayoutIsSelected);
|
|
186
|
+
},
|
|
187
|
+
pointMove: (e) => {
|
|
188
|
+
if (!sharer.getSharedStorage(keyLayoutIsSelected)) {
|
|
189
|
+
if (isInElementAction()) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
194
|
+
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
195
|
+
const data = sharer.getActiveStorage('data');
|
|
196
|
+
if (layoutActionType === 'resize' && layoutControlType && (data === null || data === void 0 ? void 0 : data.layout)) {
|
|
197
|
+
if (prevPoint) {
|
|
198
|
+
isBusy = true;
|
|
199
|
+
const scale = sharer.getActiveStorage('scale');
|
|
200
|
+
const viewMoveX = e.point.x - prevPoint.x;
|
|
201
|
+
const viewMoveY = e.point.y - prevPoint.y;
|
|
202
|
+
const moveX = viewMoveX / scale;
|
|
203
|
+
const moveY = viewMoveY / scale;
|
|
204
|
+
const { x, y, w, h, operations = {} } = data.layout;
|
|
205
|
+
const { position = 'absolute' } = operations;
|
|
206
|
+
if (layoutControlType === 'top') {
|
|
207
|
+
if (position === 'relative') {
|
|
208
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
209
|
+
viewer.scroll({ moveY: viewMoveY });
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
213
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
else if (layoutControlType === 'right') {
|
|
217
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
218
|
+
}
|
|
219
|
+
else if (layoutControlType === 'bottom') {
|
|
220
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
221
|
+
}
|
|
222
|
+
else if (layoutControlType === 'left') {
|
|
223
|
+
if (position === 'relative') {
|
|
224
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
225
|
+
viewer.scroll({ moveX: viewMoveX });
|
|
226
|
+
}
|
|
227
|
+
else {
|
|
228
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
229
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
else if (layoutControlType === 'top-left') {
|
|
233
|
+
if (position === 'relative') {
|
|
234
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
235
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
236
|
+
viewer.scroll({ moveX: viewMoveX, moveY: viewMoveY });
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
240
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
241
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
242
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
else if (layoutControlType === 'top-right') {
|
|
246
|
+
if (position === 'relative') {
|
|
247
|
+
viewer.scroll({
|
|
248
|
+
moveY: viewMoveY
|
|
249
|
+
});
|
|
250
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
251
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
255
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
256
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
else if (layoutControlType === 'bottom-right') {
|
|
260
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
261
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
262
|
+
}
|
|
263
|
+
else if (layoutControlType === 'bottom-left') {
|
|
264
|
+
if (position === 'relative') {
|
|
265
|
+
viewer.scroll({
|
|
266
|
+
moveX: viewMoveX
|
|
267
|
+
});
|
|
268
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
269
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
273
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
274
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
prevPoint = e.point;
|
|
279
|
+
resetController();
|
|
280
|
+
viewer.drawFrame();
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
if (['resize'].includes(layoutActionType)) {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
pointEnd: () => {
|
|
288
|
+
isBusy = false;
|
|
289
|
+
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
290
|
+
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
291
|
+
const data = sharer.getActiveStorage('data');
|
|
292
|
+
if (data && layoutActionType === 'resize' && layoutControlType) {
|
|
293
|
+
eventHub.trigger(eventChange, {
|
|
294
|
+
type: 'changeLayout',
|
|
295
|
+
data
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
beforeDrawFrame: ({ snapshot }) => {
|
|
300
|
+
var _a;
|
|
301
|
+
if (isInElementAction()) {
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
304
|
+
const { sharedStore, activeStore } = snapshot;
|
|
305
|
+
const layoutActionType = sharedStore[keyLayoutActionType];
|
|
306
|
+
const layoutIsHover = sharedStore[keyLayoutIsHover];
|
|
307
|
+
const layoutIsSelected = sharedStore[keyLayoutIsSelected];
|
|
308
|
+
if ((_a = activeStore.data) === null || _a === void 0 ? void 0 : _a.layout) {
|
|
309
|
+
const { x, y, w, h } = activeStore.data.layout;
|
|
310
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
311
|
+
const size = { x, y, w, h };
|
|
312
|
+
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize });
|
|
313
|
+
if (layoutIsHover === true) {
|
|
314
|
+
const viewSize = calcViewElementSize(size, { viewScaleInfo });
|
|
315
|
+
drawLayoutHover(overlayContext, { layoutSize: viewSize });
|
|
316
|
+
}
|
|
317
|
+
if ((layoutActionType && ['resize'].includes(layoutActionType)) || layoutIsSelected === true) {
|
|
318
|
+
drawLayoutController(overlayContext, { controller, operations: activeStore.data.layout.operations || {} });
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
},
|
|
322
|
+
scrollX: () => {
|
|
323
|
+
clear();
|
|
324
|
+
},
|
|
325
|
+
scrollY: () => {
|
|
326
|
+
clear();
|
|
327
|
+
},
|
|
328
|
+
wheelScale: () => {
|
|
329
|
+
clear();
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LayoutSizeController, Element } from '@idraw/types';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHover, keyLayoutIsSelected } from './config';
|
|
3
|
+
import { keyActionType as keyElementActionType, keyHoverElement } from '../selector';
|
|
4
|
+
import type { ActionType as ElementActionType } from '../selector';
|
|
5
|
+
export type ActionType = 'resize' | null;
|
|
6
|
+
export type ControlType = 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
7
|
+
export type LayoutSelectorSharedStorage = {
|
|
8
|
+
[keyLayoutActionType]: ActionType | null;
|
|
9
|
+
[keyLayoutControlType]: ControlType | null;
|
|
10
|
+
[keyLayoutController]: LayoutSizeController | null;
|
|
11
|
+
[keyElementActionType]: ElementActionType | null;
|
|
12
|
+
[keyHoverElement]: Element | null;
|
|
13
|
+
[keyLayoutIsHover]: boolean | null;
|
|
14
|
+
[keyLayoutIsSelected]: boolean | null;
|
|
15
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ViewContext2D, LayoutSizeController, DataLayout, ElementSize } from '@idraw/types';
|
|
2
|
+
export declare function drawLayoutController(ctx: ViewContext2D, opts: {
|
|
3
|
+
controller: LayoutSizeController;
|
|
4
|
+
operations: DataLayout['operations'];
|
|
5
|
+
}): void;
|
|
6
|
+
export declare function drawLayoutHover(ctx: ViewContext2D, opts: {
|
|
7
|
+
layoutSize: ElementSize;
|
|
8
|
+
}): void;
|