@idraw/core 0.4.0-beta.4 → 0.4.0-beta.40
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/board/index.d.ts +46 -0
- package/dist/esm/board/index.js +371 -0
- package/dist/esm/board/sharer.d.ts +21 -0
- package/dist/esm/board/sharer.js +101 -0
- package/dist/esm/board/viewer.d.ts +32 -0
- package/dist/esm/board/viewer.js +165 -0
- package/dist/esm/board/watcher.d.ts +15 -0
- package/dist/esm/board/watcher.js +218 -0
- package/dist/esm/config.d.ts +28 -0
- package/dist/esm/config.js +34 -0
- package/dist/esm/index.d.ts +23 -9
- package/dist/esm/index.js +36 -12
- 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 +137 -112
- package/dist/esm/middleware/dragger/index.d.ts +2 -2
- package/dist/esm/middleware/dragger/index.js +5 -3
- package/dist/esm/middleware/info/config.d.ts +5 -0
- package/dist/esm/middleware/info/config.js +9 -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 +9 -0
- package/dist/esm/middleware/info/index.js +131 -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 +11 -0
- package/dist/esm/middleware/layout-selector/config.js +12 -0
- package/dist/esm/middleware/layout-selector/index.d.ts +5 -0
- package/dist/esm/middleware/layout-selector/index.js +349 -0
- package/dist/esm/middleware/layout-selector/types.d.ts +17 -0
- package/dist/esm/middleware/layout-selector/types.js +2 -0
- package/dist/esm/middleware/layout-selector/util.d.ts +9 -0
- package/dist/esm/middleware/layout-selector/util.js +63 -0
- package/dist/esm/middleware/pointer/index.d.ts +3 -0
- package/dist/esm/middleware/pointer/index.js +43 -0
- package/dist/esm/middleware/pointer/types.d.ts +3 -0
- package/dist/esm/middleware/pointer/types.js +1 -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 -3
- package/dist/esm/middleware/ruler/index.js +33 -14
- 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 +97 -25
- package/dist/esm/middleware/scaler/index.d.ts +2 -3
- package/dist/esm/middleware/scaler/index.js +3 -2
- 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 +48 -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 -43
- package/dist/esm/middleware/selector/config.d.ts +9 -1
- package/dist/esm/middleware/selector/config.js +17 -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-debug.d.ts +5 -0
- package/dist/esm/middleware/selector/draw-debug.js +30 -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 -1
- package/dist/esm/middleware/selector/draw-wrapper.js +57 -35
- package/dist/esm/middleware/selector/index.d.ts +11 -4
- package/dist/esm/middleware/selector/index.js +420 -70
- package/dist/esm/middleware/selector/pattern/icon-rotate.d.ts +4 -0
- package/dist/esm/middleware/selector/pattern/icon-rotate.js +88 -0
- package/dist/esm/middleware/selector/pattern/index.d.ts +8 -0
- package/dist/esm/middleware/selector/pattern/index.js +38 -0
- 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 +10 -4
- package/dist/esm/middleware/selector/types.js +2 -1
- package/dist/esm/middleware/selector/util.d.ts +14 -7
- package/dist/esm/middleware/selector/util.js +45 -43
- package/dist/esm/middleware/text-editor/index.d.ts +20 -3
- package/dist/esm/middleware/text-editor/index.js +96 -19
- package/dist/index.global.js +4765 -1466
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -6
|
@@ -0,0 +1,131 @@
|
|
|
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, MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE } from './config';
|
|
5
|
+
export { MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE };
|
|
6
|
+
const infoFontSize = 10;
|
|
7
|
+
const infoLineHeight = 16;
|
|
8
|
+
export const MiddlewareInfo = (opts, config) => {
|
|
9
|
+
const { boardContent, calculator, eventHub } = opts;
|
|
10
|
+
const { overlayContext } = boardContent;
|
|
11
|
+
let innerConfig = Object.assign(Object.assign({}, defaltStyle), config);
|
|
12
|
+
let showAngleInfo = true;
|
|
13
|
+
const showInfoAngleCallback = ({ show }) => {
|
|
14
|
+
showAngleInfo = show;
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
name: '@middleware/info',
|
|
18
|
+
use() {
|
|
19
|
+
eventHub.on(MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE, showInfoAngleCallback);
|
|
20
|
+
},
|
|
21
|
+
disuse() {
|
|
22
|
+
eventHub.off(MIDDLEWARE_INTERNAL_EVENT_SHOW_INFO_ANGLE, showInfoAngleCallback);
|
|
23
|
+
},
|
|
24
|
+
resetConfig(config) {
|
|
25
|
+
innerConfig = Object.assign(Object.assign({}, innerConfig), config);
|
|
26
|
+
},
|
|
27
|
+
beforeDrawFrame({ snapshot }) {
|
|
28
|
+
var _a;
|
|
29
|
+
const { textBackground, textColor } = innerConfig;
|
|
30
|
+
const style = {
|
|
31
|
+
textBackground,
|
|
32
|
+
textColor
|
|
33
|
+
};
|
|
34
|
+
const { sharedStore } = snapshot;
|
|
35
|
+
const selectedElementList = sharedStore[keySelectedElementList];
|
|
36
|
+
const actionType = sharedStore[keyActionType];
|
|
37
|
+
const groupQueue = sharedStore[keyGroupQueue] || [];
|
|
38
|
+
if (selectedElementList.length === 1) {
|
|
39
|
+
const elem = selectedElementList[0];
|
|
40
|
+
if (elem && ['select', 'drag', 'resize'].includes(actionType)) {
|
|
41
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
42
|
+
const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
|
|
43
|
+
const { x, y, w, h, angle } = elem;
|
|
44
|
+
const totalGroupQueue = [
|
|
45
|
+
...groupQueue,
|
|
46
|
+
...[
|
|
47
|
+
{
|
|
48
|
+
uuid: createUUID(),
|
|
49
|
+
x,
|
|
50
|
+
y,
|
|
51
|
+
w,
|
|
52
|
+
h,
|
|
53
|
+
angle,
|
|
54
|
+
type: 'group',
|
|
55
|
+
detail: { children: [] }
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
];
|
|
59
|
+
const calcOpts = { viewScaleInfo, viewSizeInfo };
|
|
60
|
+
const rangeRectInfo = calculator.calcViewRectInfoFromOrigin(elem.uuid, calcOpts);
|
|
61
|
+
let totalAngle = 0;
|
|
62
|
+
totalGroupQueue.forEach((group) => {
|
|
63
|
+
totalAngle += group.angle || 0;
|
|
64
|
+
});
|
|
65
|
+
const totalRadian = parseAngleToRadian(limitAngle(0 - totalAngle));
|
|
66
|
+
if (rangeRectInfo) {
|
|
67
|
+
const elemCenter = rangeRectInfo === null || rangeRectInfo === void 0 ? void 0 : rangeRectInfo.center;
|
|
68
|
+
const rectInfo = {
|
|
69
|
+
topLeft: rotatePoint(elemCenter, rangeRectInfo.topLeft, totalRadian),
|
|
70
|
+
topRight: rotatePoint(elemCenter, rangeRectInfo.topRight, totalRadian),
|
|
71
|
+
bottomRight: rotatePoint(elemCenter, rangeRectInfo.bottomRight, totalRadian),
|
|
72
|
+
bottomLeft: rotatePoint(elemCenter, rangeRectInfo.bottomLeft, totalRadian),
|
|
73
|
+
center: rotatePoint(elemCenter, rangeRectInfo.center, totalRadian),
|
|
74
|
+
top: rotatePoint(elemCenter, rangeRectInfo.top, totalRadian),
|
|
75
|
+
right: rotatePoint(elemCenter, rangeRectInfo.right, totalRadian),
|
|
76
|
+
bottom: rotatePoint(elemCenter, rangeRectInfo.bottom, totalRadian),
|
|
77
|
+
left: rotatePoint(elemCenter, rangeRectInfo.left, totalRadian)
|
|
78
|
+
};
|
|
79
|
+
const x = formatNumber(elem.x, { decimalPlaces: 2 });
|
|
80
|
+
const y = formatNumber(elem.y, { decimalPlaces: 2 });
|
|
81
|
+
const w = formatNumber(elem.w, { decimalPlaces: 2 });
|
|
82
|
+
const h = formatNumber(elem.h, { decimalPlaces: 2 });
|
|
83
|
+
const xyText = `${formatNumber(x, { decimalPlaces: 0 })},${formatNumber(y, { decimalPlaces: 0 })}`;
|
|
84
|
+
const whText = `${formatNumber(w, { decimalPlaces: 0 })}x${formatNumber(h, { decimalPlaces: 0 })}`;
|
|
85
|
+
const angleText = `${formatNumber(elem.angle || 0, { decimalPlaces: 0 })}°`;
|
|
86
|
+
drawSizeInfoText(overlayContext, {
|
|
87
|
+
point: {
|
|
88
|
+
x: rectInfo.bottom.x,
|
|
89
|
+
y: rectInfo.bottom.y + infoFontSize
|
|
90
|
+
},
|
|
91
|
+
rotateCenter: rectInfo.center,
|
|
92
|
+
angle: totalAngle,
|
|
93
|
+
text: whText,
|
|
94
|
+
fontSize: infoFontSize,
|
|
95
|
+
lineHeight: infoLineHeight,
|
|
96
|
+
style
|
|
97
|
+
});
|
|
98
|
+
drawPositionInfoText(overlayContext, {
|
|
99
|
+
point: {
|
|
100
|
+
x: rectInfo.topLeft.x,
|
|
101
|
+
y: rectInfo.topLeft.y - infoFontSize * 2
|
|
102
|
+
},
|
|
103
|
+
rotateCenter: rectInfo.center,
|
|
104
|
+
angle: totalAngle,
|
|
105
|
+
text: xyText,
|
|
106
|
+
fontSize: infoFontSize,
|
|
107
|
+
lineHeight: infoLineHeight,
|
|
108
|
+
style
|
|
109
|
+
});
|
|
110
|
+
if (showAngleInfo) {
|
|
111
|
+
if (((_a = elem.operations) === null || _a === void 0 ? void 0 : _a.rotatable) !== false) {
|
|
112
|
+
drawAngleInfoText(overlayContext, {
|
|
113
|
+
point: {
|
|
114
|
+
x: rectInfo.top.x + infoFontSize + 4,
|
|
115
|
+
y: rectInfo.top.y - infoFontSize * 2 - 18
|
|
116
|
+
},
|
|
117
|
+
rotateCenter: rectInfo.center,
|
|
118
|
+
angle: totalAngle,
|
|
119
|
+
text: angleText,
|
|
120
|
+
fontSize: infoFontSize,
|
|
121
|
+
lineHeight: infoLineHeight,
|
|
122
|
+
style
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { keySelectedElementList, keyHoverElement, keyActionType, keyGroupQueue } from '../selector';
|
|
2
|
+
import type { DeepSelectorSharedStorage } from '../selector';
|
|
3
|
+
export type DeepInfoSharedStorage = Pick<DeepSelectorSharedStorage, typeof keySelectedElementList | typeof keyHoverElement | typeof keyActionType | typeof keyGroupQueue>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { MiddlewareLayoutSelectorStyle } from '@idraw/types';
|
|
2
|
+
export declare const key = "LAYOUT_SELECT";
|
|
3
|
+
export declare const keyLayoutActionType: unique symbol;
|
|
4
|
+
export declare const keyLayoutControlType: unique symbol;
|
|
5
|
+
export declare const keyLayoutController: unique symbol;
|
|
6
|
+
export declare const keyLayoutIsHoverContent: unique symbol;
|
|
7
|
+
export declare const keyLayoutIsHoverController: unique symbol;
|
|
8
|
+
export declare const keyLayoutIsSelected: unique symbol;
|
|
9
|
+
export declare const keyLayoutIsBusyMoving: unique symbol;
|
|
10
|
+
export declare const controllerSize = 10;
|
|
11
|
+
export declare const defaultStyle: MiddlewareLayoutSelectorStyle;
|
|
@@ -0,0 +1,12 @@
|
|
|
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 keyLayoutIsHoverContent = Symbol(`${key}_layoutIsHoverContent`);
|
|
6
|
+
export const keyLayoutIsHoverController = Symbol(`${key}_layoutIsHoverController`);
|
|
7
|
+
export const keyLayoutIsSelected = Symbol(`${key}_layoutIsSelected`);
|
|
8
|
+
export const keyLayoutIsBusyMoving = Symbol(`${key}_layoutIsSelected`);
|
|
9
|
+
export const controllerSize = 10;
|
|
10
|
+
export const defaultStyle = {
|
|
11
|
+
activeColor: '#b331c9'
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BoardMiddleware, MiddlewareLayoutSelectorConfig, CoreEventMap } from '@idraw/types';
|
|
2
|
+
import type { LayoutSelectorSharedStorage } from './types';
|
|
3
|
+
import { keyLayoutIsSelected, keyLayoutIsBusyMoving } from './config';
|
|
4
|
+
export { keyLayoutIsSelected, keyLayoutIsBusyMoving };
|
|
5
|
+
export declare const MiddlewareLayoutSelector: BoardMiddleware<LayoutSelectorSharedStorage, CoreEventMap, MiddlewareLayoutSelectorConfig>;
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { calcLayoutSizeController, isViewPointInVertexes, getViewScaleInfoFromSnapshot, isViewPointInElementSize, calcViewElementSize } from '@idraw/util';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutController, keyLayoutControlType, keyLayoutIsHoverContent, keyLayoutIsHoverController, keyLayoutIsSelected, keyLayoutIsBusyMoving, controllerSize, defaultStyle } from './config';
|
|
3
|
+
import { keyActionType as keyElementActionType } from '../selector';
|
|
4
|
+
import { drawLayoutController, drawLayoutHover } from './util';
|
|
5
|
+
import { coreEventKeys } from '../../config';
|
|
6
|
+
export { keyLayoutIsSelected, keyLayoutIsBusyMoving };
|
|
7
|
+
export const MiddlewareLayoutSelector = (opts, config) => {
|
|
8
|
+
const { sharer, boardContent, calculator, viewer, eventHub } = opts;
|
|
9
|
+
const { overlayContext } = boardContent;
|
|
10
|
+
let innerConfig = Object.assign(Object.assign({}, defaultStyle), config);
|
|
11
|
+
let prevPoint = null;
|
|
12
|
+
let prevIsHoverContent = null;
|
|
13
|
+
let prevIsSelected = 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(keyLayoutIsHoverContent, null);
|
|
20
|
+
sharer.setSharedStorage(keyLayoutIsHoverController, null);
|
|
21
|
+
sharer.setSharedStorage(keyLayoutIsSelected, null);
|
|
22
|
+
sharer.setSharedStorage(keyLayoutIsBusyMoving, null);
|
|
23
|
+
prevIsHoverContent = null;
|
|
24
|
+
prevIsSelected = null;
|
|
25
|
+
};
|
|
26
|
+
const isInElementAction = () => {
|
|
27
|
+
const elementActionType = sharer.getSharedStorage(keyElementActionType);
|
|
28
|
+
if (elementActionType && elementActionType !== 'area') {
|
|
29
|
+
clear();
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
const getLayoutSize = () => {
|
|
35
|
+
const data = sharer.getActiveStorage('data');
|
|
36
|
+
if (data === null || data === void 0 ? void 0 : data.layout) {
|
|
37
|
+
const { x, y, w, h } = data.layout;
|
|
38
|
+
return { x, y, w, h };
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
42
|
+
const isInLayout = (p) => {
|
|
43
|
+
const size = getLayoutSize();
|
|
44
|
+
if (size) {
|
|
45
|
+
const { x, y, w, h } = size;
|
|
46
|
+
const viewScaleInfo = sharer.getActiveViewScaleInfo();
|
|
47
|
+
const viewSize = calcViewElementSize({
|
|
48
|
+
x: x - controllerSize / 2,
|
|
49
|
+
y: y - controllerSize / 2,
|
|
50
|
+
w: w + controllerSize,
|
|
51
|
+
h: h + controllerSize
|
|
52
|
+
}, { viewScaleInfo });
|
|
53
|
+
return isViewPointInElementSize(p, viewSize);
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
};
|
|
57
|
+
const resetController = () => {
|
|
58
|
+
const viewScaleInfo = sharer.getActiveViewScaleInfo();
|
|
59
|
+
const size = getLayoutSize();
|
|
60
|
+
if (size) {
|
|
61
|
+
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
|
|
62
|
+
sharer.setSharedStorage(keyLayoutController, controller);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
sharer.setSharedStorage(keyLayoutController, null);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const resetControlType = (e) => {
|
|
69
|
+
const data = sharer.getActiveStorage('data');
|
|
70
|
+
const controller = sharer.getSharedStorage(keyLayoutController);
|
|
71
|
+
let controllerType = null;
|
|
72
|
+
if (controller && (data === null || data === void 0 ? void 0 : data.layout) && (e === null || e === void 0 ? void 0 : e.point)) {
|
|
73
|
+
let layoutControlType = null;
|
|
74
|
+
if (controller) {
|
|
75
|
+
const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = controller;
|
|
76
|
+
const list = [topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left];
|
|
77
|
+
for (let i = 0; i < list.length; i++) {
|
|
78
|
+
const item = list[i];
|
|
79
|
+
if (isViewPointInVertexes(e.point, item.vertexes)) {
|
|
80
|
+
layoutControlType = `${item.type}`;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (layoutControlType) {
|
|
85
|
+
sharer.setSharedStorage(keyLayoutControlType, layoutControlType);
|
|
86
|
+
eventHub.trigger(coreEventKeys.CLEAR_SELECT);
|
|
87
|
+
controllerType = layoutControlType;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (controllerType) {
|
|
92
|
+
sharer.setSharedStorage(keyLayoutIsHoverController, true);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
sharer.setSharedStorage(keyLayoutIsHoverController, false);
|
|
96
|
+
}
|
|
97
|
+
return controllerType;
|
|
98
|
+
};
|
|
99
|
+
const updateCursor = (controlType) => {
|
|
100
|
+
if (sharer.getSharedStorage(keyLayoutIsBusyMoving) === true) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
eventHub.trigger(coreEventKeys.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
|
+
resetConfig(config) {
|
|
116
|
+
innerConfig = Object.assign(Object.assign({}, innerConfig), config);
|
|
117
|
+
},
|
|
118
|
+
hover: (e) => {
|
|
119
|
+
if (sharer.getSharedStorage(keyLayoutIsBusyMoving) === true) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (isInElementAction()) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (isInLayout(e.point)) {
|
|
126
|
+
sharer.setSharedStorage(keyLayoutIsHoverContent, true);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
sharer.setSharedStorage(keyLayoutIsHoverContent, false);
|
|
130
|
+
if (prevIsHoverContent === true) {
|
|
131
|
+
viewer.drawFrame();
|
|
132
|
+
prevIsHoverContent = 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
|
+
if (sharer.getSharedStorage(keyLayoutIsHoverController) === true) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
if (sharer.getSharedStorage(keyLayoutIsHoverContent) && !prevIsHoverContent) {
|
|
161
|
+
viewer.drawFrame();
|
|
162
|
+
}
|
|
163
|
+
prevIsHoverContent = sharer.getSharedStorage(keyLayoutIsHoverContent);
|
|
164
|
+
if (sharer.getSharedStorage(keyLayoutIsHoverController) === true) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
pointStart: (e) => {
|
|
169
|
+
if (isInElementAction()) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (isInLayout(e.point)) {
|
|
173
|
+
sharer.setSharedStorage(keyLayoutIsSelected, true);
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
if (prevIsSelected === true) {
|
|
177
|
+
clear();
|
|
178
|
+
viewer.drawFrame();
|
|
179
|
+
}
|
|
180
|
+
sharer.setSharedStorage(keyLayoutIsSelected, false);
|
|
181
|
+
}
|
|
182
|
+
resetController();
|
|
183
|
+
const layoutControlType = resetControlType(e);
|
|
184
|
+
prevPoint = e.point;
|
|
185
|
+
if (layoutControlType) {
|
|
186
|
+
sharer.setSharedStorage(keyLayoutActionType, 'resize');
|
|
187
|
+
}
|
|
188
|
+
if (sharer.getSharedStorage(keyLayoutIsSelected) === true && !prevIsSelected) {
|
|
189
|
+
viewer.drawFrame();
|
|
190
|
+
eventHub.trigger(coreEventKeys.SELECT_LAYOUT);
|
|
191
|
+
}
|
|
192
|
+
prevIsSelected = sharer.getSharedStorage(keyLayoutIsSelected);
|
|
193
|
+
if (sharer.getSharedStorage(keyLayoutIsHoverController) === true) {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
pointMove: (e) => {
|
|
198
|
+
if (!sharer.getSharedStorage(keyLayoutIsSelected)) {
|
|
199
|
+
if (isInElementAction()) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
204
|
+
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
205
|
+
const data = sharer.getActiveStorage('data');
|
|
206
|
+
if (layoutActionType === 'resize' && layoutControlType && (data === null || data === void 0 ? void 0 : data.layout)) {
|
|
207
|
+
if (prevPoint) {
|
|
208
|
+
sharer.setSharedStorage(keyLayoutIsBusyMoving, true);
|
|
209
|
+
const scale = sharer.getActiveStorage('scale');
|
|
210
|
+
const viewMoveX = e.point.x - prevPoint.x;
|
|
211
|
+
const viewMoveY = e.point.y - prevPoint.y;
|
|
212
|
+
const moveX = viewMoveX / scale;
|
|
213
|
+
const moveY = viewMoveY / scale;
|
|
214
|
+
const { x, y, w, h, operations = {} } = data.layout;
|
|
215
|
+
const { position = 'absolute' } = operations;
|
|
216
|
+
if (layoutControlType === 'top') {
|
|
217
|
+
if (position === 'relative') {
|
|
218
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
219
|
+
viewer.scroll({ moveY: viewMoveY });
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
223
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (layoutControlType === 'right') {
|
|
227
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
228
|
+
}
|
|
229
|
+
else if (layoutControlType === 'bottom') {
|
|
230
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
231
|
+
}
|
|
232
|
+
else if (layoutControlType === 'left') {
|
|
233
|
+
if (position === 'relative') {
|
|
234
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
235
|
+
viewer.scroll({ moveX: viewMoveX });
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
239
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
else if (layoutControlType === 'top-left') {
|
|
243
|
+
if (position === 'relative') {
|
|
244
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
245
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
246
|
+
viewer.scroll({ moveX: viewMoveX, moveY: viewMoveY });
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
250
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
251
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
252
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
else if (layoutControlType === 'top-right') {
|
|
256
|
+
if (position === 'relative') {
|
|
257
|
+
viewer.scroll({
|
|
258
|
+
moveY: viewMoveY
|
|
259
|
+
});
|
|
260
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
261
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
265
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
266
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
else if (layoutControlType === 'bottom-right') {
|
|
270
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
271
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
272
|
+
}
|
|
273
|
+
else if (layoutControlType === 'bottom-left') {
|
|
274
|
+
if (position === 'relative') {
|
|
275
|
+
viewer.scroll({
|
|
276
|
+
moveX: viewMoveX
|
|
277
|
+
});
|
|
278
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
279
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
283
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
284
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
prevPoint = e.point;
|
|
289
|
+
resetController();
|
|
290
|
+
viewer.drawFrame();
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
if (['resize'].includes(layoutActionType)) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
pointEnd: () => {
|
|
298
|
+
sharer.setSharedStorage(keyLayoutIsBusyMoving, false);
|
|
299
|
+
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
300
|
+
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
301
|
+
const data = sharer.getActiveStorage('data');
|
|
302
|
+
if (data && layoutActionType === 'resize' && layoutControlType) {
|
|
303
|
+
eventHub.trigger(coreEventKeys.CHANGE, {
|
|
304
|
+
type: 'dragLayout',
|
|
305
|
+
data
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
309
|
+
sharer.setSharedStorage(keyLayoutControlType, null);
|
|
310
|
+
if (sharer.getSharedStorage(keyLayoutIsHoverController) === true) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
beforeDrawFrame: ({ snapshot }) => {
|
|
315
|
+
var _a;
|
|
316
|
+
if (isInElementAction()) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
const { activeColor } = innerConfig;
|
|
320
|
+
const style = { activeColor };
|
|
321
|
+
const { sharedStore, activeStore } = snapshot;
|
|
322
|
+
const layoutActionType = sharedStore[keyLayoutActionType];
|
|
323
|
+
const layoutIsHover = sharedStore[keyLayoutIsHoverContent];
|
|
324
|
+
const layoutIsSelected = sharedStore[keyLayoutIsSelected];
|
|
325
|
+
if ((_a = activeStore.data) === null || _a === void 0 ? void 0 : _a.layout) {
|
|
326
|
+
const { x, y, w, h } = activeStore.data.layout;
|
|
327
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
328
|
+
const size = { x, y, w, h };
|
|
329
|
+
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize });
|
|
330
|
+
if (layoutIsHover === true) {
|
|
331
|
+
const viewSize = calcViewElementSize(size, { viewScaleInfo });
|
|
332
|
+
drawLayoutHover(overlayContext, { layoutSize: viewSize, style });
|
|
333
|
+
}
|
|
334
|
+
if ((layoutActionType && ['resize'].includes(layoutActionType)) || layoutIsSelected === true) {
|
|
335
|
+
drawLayoutController(overlayContext, { controller, style });
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
scrollX: () => {
|
|
340
|
+
clear();
|
|
341
|
+
},
|
|
342
|
+
scrollY: () => {
|
|
343
|
+
clear();
|
|
344
|
+
},
|
|
345
|
+
wheelScale: () => {
|
|
346
|
+
clear();
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { LayoutSizeController, Element } from '@idraw/types';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHoverContent, keyLayoutIsHoverController, keyLayoutIsSelected, keyLayoutIsBusyMoving } 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
|
+
[keyLayoutIsHoverContent]: boolean | null;
|
|
14
|
+
[keyLayoutIsHoverController]: boolean | null;
|
|
15
|
+
[keyLayoutIsSelected]: boolean | null;
|
|
16
|
+
[keyLayoutIsBusyMoving]: boolean | null;
|
|
17
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ViewContext2D, LayoutSizeController, ElementSize, MiddlewareLayoutSelectorStyle } from '@idraw/types';
|
|
2
|
+
export declare function drawLayoutController(ctx: ViewContext2D, opts: {
|
|
3
|
+
controller: LayoutSizeController;
|
|
4
|
+
style: MiddlewareLayoutSelectorStyle;
|
|
5
|
+
}): void;
|
|
6
|
+
export declare function drawLayoutHover(ctx: ViewContext2D, opts: {
|
|
7
|
+
layoutSize: ElementSize;
|
|
8
|
+
style: MiddlewareLayoutSelectorStyle;
|
|
9
|
+
}): void;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function drawControllerBox(ctx, boxVertexes, style) {
|
|
2
|
+
const { activeColor } = style;
|
|
3
|
+
ctx.setLineDash([]);
|
|
4
|
+
ctx.fillStyle = '#FFFFFF';
|
|
5
|
+
ctx.beginPath();
|
|
6
|
+
ctx.moveTo(boxVertexes[0].x, boxVertexes[0].y);
|
|
7
|
+
ctx.lineTo(boxVertexes[1].x, boxVertexes[1].y);
|
|
8
|
+
ctx.lineTo(boxVertexes[2].x, boxVertexes[2].y);
|
|
9
|
+
ctx.lineTo(boxVertexes[3].x, boxVertexes[3].y);
|
|
10
|
+
ctx.closePath();
|
|
11
|
+
ctx.fill();
|
|
12
|
+
ctx.strokeStyle = activeColor;
|
|
13
|
+
ctx.lineWidth = 2;
|
|
14
|
+
ctx.beginPath();
|
|
15
|
+
ctx.moveTo(boxVertexes[0].x, boxVertexes[0].y);
|
|
16
|
+
ctx.lineTo(boxVertexes[1].x, boxVertexes[1].y);
|
|
17
|
+
ctx.lineTo(boxVertexes[2].x, boxVertexes[2].y);
|
|
18
|
+
ctx.lineTo(boxVertexes[3].x, boxVertexes[3].y);
|
|
19
|
+
ctx.closePath();
|
|
20
|
+
ctx.stroke();
|
|
21
|
+
}
|
|
22
|
+
function drawControllerLine(ctx, opts) {
|
|
23
|
+
const { start, end, style } = opts;
|
|
24
|
+
const { activeColor } = style;
|
|
25
|
+
const lineWidth = 2;
|
|
26
|
+
const strokeStyle = activeColor;
|
|
27
|
+
ctx.setLineDash([]);
|
|
28
|
+
ctx.strokeStyle = strokeStyle;
|
|
29
|
+
ctx.lineWidth = lineWidth;
|
|
30
|
+
ctx.beginPath();
|
|
31
|
+
ctx.moveTo(start.x, start.y);
|
|
32
|
+
ctx.lineTo(end.x, end.y);
|
|
33
|
+
ctx.closePath();
|
|
34
|
+
ctx.stroke();
|
|
35
|
+
}
|
|
36
|
+
export function drawLayoutController(ctx, opts) {
|
|
37
|
+
const { controller, style } = opts;
|
|
38
|
+
const { topLeft, topRight, bottomLeft, bottomRight, topMiddle, rightMiddle, bottomMiddle, leftMiddle } = controller;
|
|
39
|
+
drawControllerLine(ctx, { start: topLeft.center, end: topRight.center, centerVertexes: topMiddle.vertexes, style });
|
|
40
|
+
drawControllerLine(ctx, { start: topRight.center, end: bottomRight.center, centerVertexes: rightMiddle.vertexes, style });
|
|
41
|
+
drawControllerLine(ctx, { start: bottomRight.center, end: bottomLeft.center, centerVertexes: bottomMiddle.vertexes, style });
|
|
42
|
+
drawControllerLine(ctx, { start: bottomLeft.center, end: topLeft.center, centerVertexes: leftMiddle.vertexes, style });
|
|
43
|
+
drawControllerBox(ctx, topLeft.vertexes, style);
|
|
44
|
+
drawControllerBox(ctx, topRight.vertexes, style);
|
|
45
|
+
drawControllerBox(ctx, bottomRight.vertexes, style);
|
|
46
|
+
drawControllerBox(ctx, bottomLeft.vertexes, style);
|
|
47
|
+
}
|
|
48
|
+
export function drawLayoutHover(ctx, opts) {
|
|
49
|
+
const { layoutSize, style } = opts;
|
|
50
|
+
const { activeColor } = style;
|
|
51
|
+
const { x, y, w, h } = layoutSize;
|
|
52
|
+
ctx.setLineDash([]);
|
|
53
|
+
ctx.strokeStyle = activeColor;
|
|
54
|
+
ctx.lineWidth = 1;
|
|
55
|
+
ctx.beginPath();
|
|
56
|
+
ctx.moveTo(x, y);
|
|
57
|
+
ctx.lineTo(x + w, y);
|
|
58
|
+
ctx.lineTo(x + w, y + h);
|
|
59
|
+
ctx.lineTo(x, y + h);
|
|
60
|
+
ctx.lineTo(x, y);
|
|
61
|
+
ctx.closePath();
|
|
62
|
+
ctx.stroke();
|
|
63
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { keySelectedElementList } from '../selector';
|
|
2
|
+
import { coreEventKeys } from '../../config';
|
|
3
|
+
export const MiddlewarePointer = (opts) => {
|
|
4
|
+
const { boardContent, eventHub, sharer } = opts;
|
|
5
|
+
const canvas = boardContent.boardContext.canvas;
|
|
6
|
+
const container = opts.container || document.body;
|
|
7
|
+
const id = `idraw-middleware-pointer-${Math.random().toString(26).substring(2)}`;
|
|
8
|
+
const getCanvasRect = () => {
|
|
9
|
+
const clientRect = canvas.getBoundingClientRect();
|
|
10
|
+
const { left, top, width, height } = clientRect;
|
|
11
|
+
return { left, top, width, height };
|
|
12
|
+
};
|
|
13
|
+
const contextMenuPointer = document.createElement('div');
|
|
14
|
+
contextMenuPointer.setAttribute('id', id);
|
|
15
|
+
contextMenuPointer.style.position = 'fixed';
|
|
16
|
+
contextMenuPointer.style.top = '0';
|
|
17
|
+
contextMenuPointer.style.bottom = 'unset';
|
|
18
|
+
contextMenuPointer.style.left = '0';
|
|
19
|
+
contextMenuPointer.style.right = 'unset';
|
|
20
|
+
container.appendChild(contextMenuPointer);
|
|
21
|
+
return {
|
|
22
|
+
name: '@middleware/pointer',
|
|
23
|
+
use() {
|
|
24
|
+
},
|
|
25
|
+
disuse() {
|
|
26
|
+
},
|
|
27
|
+
pointStart(e) {
|
|
28
|
+
},
|
|
29
|
+
pointEnd() {
|
|
30
|
+
},
|
|
31
|
+
contextMenu(e) {
|
|
32
|
+
const { point } = e;
|
|
33
|
+
const { left, top } = getCanvasRect();
|
|
34
|
+
contextMenuPointer.style.left = `${left + point.x}px`;
|
|
35
|
+
contextMenuPointer.style.top = `${top + point.y}px`;
|
|
36
|
+
const selectedElements = sharer.getSharedStorage(keySelectedElementList);
|
|
37
|
+
eventHub.trigger(coreEventKeys.CONTEXT_MENU, {
|
|
38
|
+
pointerContainer: contextMenuPointer,
|
|
39
|
+
selectedElements: selectedElements || []
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
};
|