@idraw/core 0.4.0-beta.17 → 0.4.0-beta.19
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 +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/middleware/info/draw-info.d.ts +31 -0
- package/dist/esm/middleware/info/draw-info.js +110 -0
- package/dist/esm/middleware/info/index.d.ts +3 -0
- package/dist/esm/middleware/info/index.js +110 -0
- package/dist/esm/middleware/info/types.d.ts +3 -0
- package/dist/esm/middleware/info/types.js +1 -0
- package/dist/esm/middleware/layout-selector/config.d.ts +6 -0
- package/dist/esm/middleware/layout-selector/config.js +6 -0
- package/dist/esm/middleware/layout-selector/index.d.ts +3 -0
- package/dist/esm/middleware/layout-selector/index.js +251 -0
- package/dist/esm/middleware/layout-selector/types.d.ts +12 -0
- package/dist/esm/middleware/layout-selector/types.js +2 -0
- package/dist/esm/middleware/layout-selector/util.d.ts +5 -0
- package/dist/esm/middleware/layout-selector/util.js +93 -0
- package/dist/esm/middleware/ruler/index.d.ts +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/index.d.ts +4 -1
- package/dist/esm/middleware/selector/index.js +17 -9
- package/dist/index.global.js +825 -99
- package/dist/index.global.min.js +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const eventChange = "change";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const eventChange = 'change';
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { Data, PointSize, CoreOptions, BoardMiddleware, ViewSizeInfo, CoreEventMap, ViewScaleInfo, LoadItemMap, ModifyOptions } from '@idraw/types';
|
|
2
|
+
export { eventChange } from './config';
|
|
2
3
|
export { MiddlewareSelector, middlewareEventSelect, middlewareEventSelectClear } from './middleware/selector';
|
|
3
4
|
export { MiddlewareScroller } from './middleware/scroller';
|
|
4
5
|
export { MiddlewareScaler, middlewareEventScale } from './middleware/scaler';
|
|
5
6
|
export { MiddlewareRuler, middlewareEventRuler } from './middleware/ruler';
|
|
6
7
|
export { MiddlewareTextEditor, middlewareEventTextEdit, middlewareEventTextChange } from './middleware/text-editor';
|
|
7
8
|
export { MiddlewareDragger } from './middleware/dragger';
|
|
9
|
+
export { MiddlewareInfo } from './middleware/info';
|
|
10
|
+
export { MiddlewareLayoutSelector } from './middleware/layout-selector';
|
|
8
11
|
export declare class Core<E extends CoreEventMap = CoreEventMap> {
|
|
9
12
|
#private;
|
|
10
13
|
constructor(container: HTMLDivElement, opts: CoreOptions);
|
package/dist/esm/index.js
CHANGED
|
@@ -13,12 +13,15 @@ var _Core_instances, _Core_board, _Core_canvas, _Core_container, _Core_initConta
|
|
|
13
13
|
import { Board } from '@idraw/board';
|
|
14
14
|
import { createBoardContent, validateElements } from '@idraw/util';
|
|
15
15
|
import { Cursor } from './lib/cursor';
|
|
16
|
+
export { eventChange } from './config';
|
|
16
17
|
export { MiddlewareSelector, middlewareEventSelect, middlewareEventSelectClear } from './middleware/selector';
|
|
17
18
|
export { MiddlewareScroller } from './middleware/scroller';
|
|
18
19
|
export { MiddlewareScaler, middlewareEventScale } from './middleware/scaler';
|
|
19
20
|
export { MiddlewareRuler, middlewareEventRuler } from './middleware/ruler';
|
|
20
21
|
export { MiddlewareTextEditor, middlewareEventTextEdit, middlewareEventTextChange } from './middleware/text-editor';
|
|
21
22
|
export { MiddlewareDragger } from './middleware/dragger';
|
|
23
|
+
export { MiddlewareInfo } from './middleware/info';
|
|
24
|
+
export { MiddlewareLayoutSelector } from './middleware/layout-selector';
|
|
22
25
|
export class Core {
|
|
23
26
|
constructor(container, opts) {
|
|
24
27
|
_Core_instances.add(this);
|
|
@@ -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 {};
|
|
@@ -0,0 +1,6 @@
|
|
|
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 selectColor = "#1973ba";
|
|
6
|
+
export declare const disableColor = "#5b5959b5";
|
|
@@ -0,0 +1,6 @@
|
|
|
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 selectColor = '#1973ba';
|
|
6
|
+
export const disableColor = '#5b5959b5';
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { calcLayoutSizeController, isViewPointInVertexes, getViewScaleInfoFromSnapshot } from '@idraw/util';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutController, keyLayoutControlType } from './config';
|
|
3
|
+
import { keyActionType as keyElementActionType, middlewareEventSelectClear } from '../selector';
|
|
4
|
+
import { drawLayoutController } from './util';
|
|
5
|
+
import { eventChange } from '../../config';
|
|
6
|
+
export const MiddlewareLayoutSelector = (opts) => {
|
|
7
|
+
const { sharer, boardContent, calculator, viewer, eventHub } = opts;
|
|
8
|
+
const { helperContext } = boardContent;
|
|
9
|
+
let prevPoint = null;
|
|
10
|
+
const clear = () => {
|
|
11
|
+
prevPoint = null;
|
|
12
|
+
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
13
|
+
sharer.setSharedStorage(keyLayoutControlType, null);
|
|
14
|
+
sharer.setSharedStorage(keyLayoutController, null);
|
|
15
|
+
};
|
|
16
|
+
const isInElementAction = () => {
|
|
17
|
+
const elementType = sharer.getSharedStorage(keyElementActionType);
|
|
18
|
+
if (elementType) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
return false;
|
|
22
|
+
};
|
|
23
|
+
const isDisbaledControl = (controlType) => {
|
|
24
|
+
var _a;
|
|
25
|
+
const data = sharer.getActiveStorage('data');
|
|
26
|
+
if ((_a = data === null || data === void 0 ? void 0 : data.layout) === null || _a === void 0 ? void 0 : _a.operations) {
|
|
27
|
+
const operations = data.layout.operations;
|
|
28
|
+
if (controlType === 'left' && operations.disableLeft === true) {
|
|
29
|
+
return true;
|
|
30
|
+
}
|
|
31
|
+
if (controlType === 'top' && operations.disableTop === true) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
if (controlType === 'right' && operations.disableRight === true) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (controlType === 'bottom' && operations.disableBottom === true) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (controlType === 'top-left' && operations.disableTopLeft === true) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
if (controlType === 'top-right' && operations.disableTopRight === true) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
if (controlType === 'bottom-left' && operations.disableBottomLeft === true) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (controlType === 'bottom-right' && operations.disableBottomRight === true) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
const getLayoutSize = () => {
|
|
56
|
+
const data = sharer.getActiveStorage('data');
|
|
57
|
+
if (data === null || data === void 0 ? void 0 : data.layout) {
|
|
58
|
+
const { x, y, w, h } = data.layout;
|
|
59
|
+
return { x, y, w, h };
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
};
|
|
63
|
+
const resetController = () => {
|
|
64
|
+
const viewScaleInfo = sharer.getActiveViewScaleInfo();
|
|
65
|
+
const size = getLayoutSize();
|
|
66
|
+
if (size) {
|
|
67
|
+
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
|
|
68
|
+
sharer.setSharedStorage(keyLayoutController, controller);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
sharer.setSharedStorage(keyLayoutController, null);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const resetControlType = (e) => {
|
|
75
|
+
const data = sharer.getActiveStorage('data');
|
|
76
|
+
const controller = sharer.getSharedStorage(keyLayoutController);
|
|
77
|
+
if (controller && (data === null || data === void 0 ? void 0 : data.layout) && (e === null || e === void 0 ? void 0 : e.point)) {
|
|
78
|
+
let layoutControlType = null;
|
|
79
|
+
if (controller) {
|
|
80
|
+
const { topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left } = controller;
|
|
81
|
+
const list = [topLeft, top, topRight, right, bottomRight, bottom, bottomLeft, left];
|
|
82
|
+
for (let i = 0; i < list.length; i++) {
|
|
83
|
+
const item = list[i];
|
|
84
|
+
if (isViewPointInVertexes(e.point, item.vertexes)) {
|
|
85
|
+
layoutControlType = `${item.type}`;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (layoutControlType) {
|
|
90
|
+
sharer.setSharedStorage(keyLayoutControlType, layoutControlType);
|
|
91
|
+
eventHub.trigger(middlewareEventSelectClear, {});
|
|
92
|
+
return layoutControlType;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
name: '@middleware/layout-selector',
|
|
100
|
+
use: () => {
|
|
101
|
+
clear();
|
|
102
|
+
resetController();
|
|
103
|
+
},
|
|
104
|
+
hover: (e) => {
|
|
105
|
+
if (isInElementAction()) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const prevLayoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
109
|
+
const data = sharer.getActiveStorage('data');
|
|
110
|
+
if ((data === null || data === void 0 ? void 0 : data.layout) && prevLayoutActionType !== 'resize') {
|
|
111
|
+
resetController();
|
|
112
|
+
const layoutControlType = resetControlType(e);
|
|
113
|
+
if (layoutControlType) {
|
|
114
|
+
sharer.setSharedStorage(keyLayoutActionType, 'hover');
|
|
115
|
+
if (!isDisbaledControl(layoutControlType)) {
|
|
116
|
+
eventHub.trigger('cursor', {
|
|
117
|
+
type: `resize-${layoutControlType}`,
|
|
118
|
+
groupQueue: [],
|
|
119
|
+
element: getLayoutSize()
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
viewer.drawFrame();
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
sharer.setSharedStorage(keyLayoutActionType, null);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (['hover', 'resize'].includes(sharer.getSharedStorage(keyLayoutActionType))) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
if (prevLayoutActionType === 'hover' && !sharer.getSharedStorage(keyLayoutActionType)) {
|
|
132
|
+
viewer.drawFrame();
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
pointStart: (e) => {
|
|
136
|
+
if (isInElementAction()) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
resetController();
|
|
140
|
+
const layoutControlType = resetControlType(e);
|
|
141
|
+
prevPoint = e.point;
|
|
142
|
+
if (layoutControlType) {
|
|
143
|
+
if (isDisbaledControl(layoutControlType)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
sharer.setSharedStorage(keyLayoutActionType, 'resize');
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
150
|
+
if (['hover', 'resize'].includes(layoutActionType)) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
pointMove: (e) => {
|
|
155
|
+
if (isInElementAction()) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
159
|
+
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
160
|
+
const data = sharer.getActiveStorage('data');
|
|
161
|
+
if (layoutControlType && isDisbaledControl(layoutControlType)) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (layoutActionType === 'resize' && layoutControlType && (data === null || data === void 0 ? void 0 : data.layout)) {
|
|
165
|
+
if (prevPoint) {
|
|
166
|
+
const scale = sharer.getActiveStorage('scale');
|
|
167
|
+
const moveX = (e.point.x - prevPoint.x) / scale;
|
|
168
|
+
const moveY = (e.point.y - prevPoint.y) / scale;
|
|
169
|
+
const { x, y, w, h } = data.layout;
|
|
170
|
+
if (layoutControlType === 'top') {
|
|
171
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
172
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
173
|
+
}
|
|
174
|
+
else if (layoutControlType === 'right') {
|
|
175
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
176
|
+
}
|
|
177
|
+
else if (layoutControlType === 'bottom') {
|
|
178
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
179
|
+
}
|
|
180
|
+
else if (layoutControlType === 'left') {
|
|
181
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
182
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
183
|
+
}
|
|
184
|
+
else if (layoutControlType === 'top-left') {
|
|
185
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
186
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
187
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
188
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
189
|
+
}
|
|
190
|
+
else if (layoutControlType === 'top-right') {
|
|
191
|
+
data.layout.y = calculator.toGridNum(y + moveY);
|
|
192
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
193
|
+
data.layout.h = calculator.toGridNum(h - moveY);
|
|
194
|
+
}
|
|
195
|
+
else if (layoutControlType === 'bottom-right') {
|
|
196
|
+
data.layout.w = calculator.toGridNum(w + moveX);
|
|
197
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
198
|
+
}
|
|
199
|
+
else if (layoutControlType === 'bottom-left') {
|
|
200
|
+
data.layout.x = calculator.toGridNum(x + moveX);
|
|
201
|
+
data.layout.w = calculator.toGridNum(w - moveX);
|
|
202
|
+
data.layout.h = calculator.toGridNum(h + moveY);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
prevPoint = e.point;
|
|
206
|
+
resetController();
|
|
207
|
+
viewer.drawFrame();
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
if (['hover', 'resize'].includes(layoutActionType)) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
pointEnd: () => {
|
|
215
|
+
const layoutActionType = sharer.getSharedStorage(keyLayoutActionType);
|
|
216
|
+
const layoutControlType = sharer.getSharedStorage(keyLayoutControlType);
|
|
217
|
+
const data = sharer.getActiveStorage('data');
|
|
218
|
+
if (data && layoutActionType === 'resize' && layoutControlType && !isDisbaledControl(layoutControlType)) {
|
|
219
|
+
eventHub.trigger(eventChange, {
|
|
220
|
+
type: 'changeLayout',
|
|
221
|
+
data
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
clear();
|
|
225
|
+
},
|
|
226
|
+
beforeDrawFrame: ({ snapshot }) => {
|
|
227
|
+
var _a;
|
|
228
|
+
const { sharedStore, activeStore } = snapshot;
|
|
229
|
+
const layoutActionType = sharedStore[keyLayoutActionType];
|
|
230
|
+
const layoutControlType = sharedStore[keyLayoutControlType];
|
|
231
|
+
if (((_a = activeStore.data) === null || _a === void 0 ? void 0 : _a.layout) && layoutActionType && layoutControlType) {
|
|
232
|
+
if (['hover', 'resize'].includes(layoutActionType)) {
|
|
233
|
+
const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
|
|
234
|
+
const { x, y, w, h } = activeStore.data.layout;
|
|
235
|
+
const size = { x, y, w, h };
|
|
236
|
+
const controller = calcLayoutSizeController(size, { viewScaleInfo, controllerSize: 10 });
|
|
237
|
+
drawLayoutController(helperContext, { controller, operations: activeStore.data.layout.operations || {} });
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
scrollX: () => {
|
|
242
|
+
clear();
|
|
243
|
+
},
|
|
244
|
+
scrollY: () => {
|
|
245
|
+
clear();
|
|
246
|
+
},
|
|
247
|
+
wheelScale: () => {
|
|
248
|
+
clear();
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { LayoutSizeController } from '@idraw/types';
|
|
2
|
+
import { keyLayoutActionType, keyLayoutControlType, keyLayoutController } from './config';
|
|
3
|
+
import { keyActionType as keyElementActionType } from '../selector';
|
|
4
|
+
import type { ActionType as ElementActionType } from '../selector';
|
|
5
|
+
export type ActionType = 'hover' | '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
|
+
};
|