@idraw/core 0.4.0-beta.2 → 0.4.0-beta.20

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.
Files changed (60) hide show
  1. package/dist/esm/config.d.ts +1 -0
  2. package/dist/esm/config.js +1 -0
  3. package/dist/esm/index.d.ts +17 -5
  4. package/dist/esm/index.js +35 -10
  5. package/dist/esm/lib/cursor-image.d.ts +3 -0
  6. package/dist/esm/lib/cursor-image.js +3 -0
  7. package/dist/esm/lib/cursor.d.ts +3 -12
  8. package/dist/esm/lib/cursor.js +138 -106
  9. package/dist/esm/middleware/dragger/index.d.ts +7 -0
  10. package/dist/esm/middleware/dragger/index.js +43 -0
  11. package/dist/esm/middleware/info/draw-info.d.ts +31 -0
  12. package/dist/esm/middleware/info/draw-info.js +110 -0
  13. package/dist/esm/middleware/info/index.d.ts +3 -0
  14. package/dist/esm/middleware/info/index.js +110 -0
  15. package/dist/esm/middleware/info/types.d.ts +3 -0
  16. package/dist/esm/middleware/info/types.js +1 -0
  17. package/dist/esm/middleware/layout-selector/config.d.ts +6 -0
  18. package/dist/esm/middleware/layout-selector/config.js +6 -0
  19. package/dist/esm/middleware/layout-selector/index.d.ts +3 -0
  20. package/dist/esm/middleware/layout-selector/index.js +251 -0
  21. package/dist/esm/middleware/layout-selector/types.d.ts +12 -0
  22. package/dist/esm/middleware/layout-selector/types.js +2 -0
  23. package/dist/esm/middleware/layout-selector/util.d.ts +5 -0
  24. package/dist/esm/middleware/layout-selector/util.js +93 -0
  25. package/dist/esm/middleware/ruler/index.d.ts +3 -2
  26. package/dist/esm/middleware/ruler/index.js +13 -8
  27. package/dist/esm/middleware/ruler/types.d.ts +3 -0
  28. package/dist/esm/middleware/ruler/types.js +1 -0
  29. package/dist/esm/middleware/ruler/util.d.ts +6 -1
  30. package/dist/esm/middleware/ruler/util.js +55 -1
  31. package/dist/esm/middleware/scaler/index.d.ts +2 -2
  32. package/dist/esm/middleware/scaler/index.js +1 -3
  33. package/dist/esm/middleware/scroller/index.d.ts +2 -1
  34. package/dist/esm/middleware/scroller/index.js +5 -5
  35. package/dist/esm/middleware/scroller/types.d.ts +9 -0
  36. package/dist/esm/middleware/scroller/types.js +1 -0
  37. package/dist/esm/middleware/scroller/util.js +1 -1
  38. package/dist/esm/middleware/selector/config.d.ts +12 -0
  39. package/dist/esm/middleware/selector/config.js +12 -0
  40. package/dist/esm/middleware/selector/draw-auxiliary.d.ts +7 -0
  41. package/dist/esm/middleware/selector/draw-auxiliary.js +46 -0
  42. package/dist/esm/middleware/selector/draw-base.d.ts +30 -0
  43. package/dist/esm/middleware/selector/draw-base.js +100 -0
  44. package/dist/esm/middleware/selector/draw-reference.d.ts +5 -0
  45. package/dist/esm/middleware/selector/draw-reference.js +31 -0
  46. package/dist/esm/middleware/selector/draw-wrapper.d.ts +9 -1
  47. package/dist/esm/middleware/selector/draw-wrapper.js +34 -26
  48. package/dist/esm/middleware/selector/index.d.ts +7 -4
  49. package/dist/esm/middleware/selector/index.js +275 -68
  50. package/dist/esm/middleware/selector/reference.d.ts +13 -0
  51. package/dist/esm/middleware/selector/reference.js +273 -0
  52. package/dist/esm/middleware/selector/types.d.ts +8 -4
  53. package/dist/esm/middleware/selector/types.js +1 -1
  54. package/dist/esm/middleware/selector/util.d.ts +11 -2
  55. package/dist/esm/middleware/selector/util.js +36 -14
  56. package/dist/esm/middleware/text-editor/index.d.ts +20 -2
  57. package/dist/esm/middleware/text-editor/index.js +79 -17
  58. package/dist/index.global.js +3477 -1066
  59. package/dist/index.global.min.js +1 -1
  60. package/package.json +5 -5
@@ -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,3 @@
1
+ import type { BoardMiddleware } from '@idraw/types';
2
+ import type { DeepInfoSharedStorage } from './types';
3
+ export declare const MiddlewareInfo: BoardMiddleware<DeepInfoSharedStorage>;
@@ -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,3 @@
1
+ import type { BoardMiddleware } from '@idraw/types';
2
+ import type { LayoutSelectorSharedStorage } from './types';
3
+ export declare const MiddlewareLayoutSelector: BoardMiddleware<LayoutSelectorSharedStorage>;
@@ -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
+ };
@@ -0,0 +1,2 @@
1
+ import { keyLayoutActionType, keyLayoutControlType, keyLayoutController } from './config';
2
+ import { keyActionType as keyElementActionType } from '../selector';
@@ -0,0 +1,5 @@
1
+ import type { ViewContext2D, LayoutSizeController, DataLayout } from '@idraw/types';
2
+ export declare function drawLayoutController(ctx: ViewContext2D, opts: {
3
+ controller: LayoutSizeController;
4
+ operations: DataLayout['operations'];
5
+ }): void;
@@ -0,0 +1,93 @@
1
+ import { selectColor, disableColor } from './config';
2
+ function drawControllerBox(ctx, boxVertexes) {
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 = selectColor;
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 drawControllerCross(ctx, opts) {
23
+ const { vertexes, strokeStyle, lineWidth } = opts;
24
+ ctx.setLineDash([]);
25
+ ctx.strokeStyle = strokeStyle;
26
+ ctx.lineWidth = lineWidth;
27
+ ctx.beginPath();
28
+ ctx.moveTo(vertexes[0].x, vertexes[0].y);
29
+ ctx.lineTo(vertexes[2].x, vertexes[2].y);
30
+ ctx.closePath();
31
+ ctx.stroke();
32
+ ctx.beginPath();
33
+ ctx.moveTo(vertexes[1].x, vertexes[1].y);
34
+ ctx.lineTo(vertexes[3].x, vertexes[3].y);
35
+ ctx.closePath();
36
+ ctx.stroke();
37
+ }
38
+ function drawControllerLine(ctx, opts) {
39
+ const { start, end, centerVertexes, disabled } = opts;
40
+ const lineWidth = disabled === true ? 1 : 2;
41
+ const strokeStyle = disabled === true ? disableColor : selectColor;
42
+ ctx.setLineDash([]);
43
+ ctx.strokeStyle = strokeStyle;
44
+ ctx.lineWidth = lineWidth;
45
+ ctx.beginPath();
46
+ ctx.moveTo(start.x, start.y);
47
+ ctx.lineTo(end.x, end.y);
48
+ ctx.closePath();
49
+ ctx.stroke();
50
+ if (disabled === true) {
51
+ drawControllerCross(ctx, {
52
+ vertexes: centerVertexes,
53
+ lineWidth,
54
+ strokeStyle
55
+ });
56
+ }
57
+ }
58
+ export function drawLayoutController(ctx, opts) {
59
+ const { controller, operations } = opts;
60
+ const { topLeft, topRight, bottomLeft, bottomRight, topMiddle, rightMiddle, bottomMiddle, leftMiddle } = controller;
61
+ drawControllerLine(ctx, { start: topLeft.center, end: topRight.center, centerVertexes: topMiddle.vertexes, disabled: !!(operations === null || operations === void 0 ? void 0 : operations.disableTop) });
62
+ drawControllerLine(ctx, { start: topRight.center, end: bottomRight.center, centerVertexes: rightMiddle.vertexes, disabled: !!(operations === null || operations === void 0 ? void 0 : operations.disableRight) });
63
+ drawControllerLine(ctx, { start: bottomRight.center, end: bottomLeft.center, centerVertexes: bottomMiddle.vertexes, disabled: !!(operations === null || operations === void 0 ? void 0 : operations.disableBottom) });
64
+ drawControllerLine(ctx, { start: bottomLeft.center, end: topLeft.center, centerVertexes: leftMiddle.vertexes, disabled: !!(operations === null || operations === void 0 ? void 0 : operations.disableLeft) });
65
+ const disabledOpts = {
66
+ lineWidth: 1,
67
+ strokeStyle: disableColor
68
+ };
69
+ if ((operations === null || operations === void 0 ? void 0 : operations.disableTopLeft) === true) {
70
+ drawControllerCross(ctx, Object.assign({ vertexes: topLeft.vertexes }, disabledOpts));
71
+ }
72
+ else {
73
+ drawControllerBox(ctx, topLeft.vertexes);
74
+ }
75
+ if ((operations === null || operations === void 0 ? void 0 : operations.disableTopRight) === true) {
76
+ drawControllerCross(ctx, Object.assign({ vertexes: topRight.vertexes }, disabledOpts));
77
+ }
78
+ else {
79
+ drawControllerBox(ctx, topRight.vertexes);
80
+ }
81
+ if ((operations === null || operations === void 0 ? void 0 : operations.disableBottomRight) === true) {
82
+ drawControllerCross(ctx, Object.assign({ vertexes: bottomRight.vertexes }, disabledOpts));
83
+ }
84
+ else {
85
+ drawControllerBox(ctx, bottomRight.vertexes);
86
+ }
87
+ if ((operations === null || operations === void 0 ? void 0 : operations.disableBottomLeft) === true) {
88
+ drawControllerCross(ctx, Object.assign({ vertexes: bottomLeft.vertexes }, disabledOpts));
89
+ }
90
+ else {
91
+ drawControllerBox(ctx, bottomLeft.vertexes);
92
+ }
93
+ }
@@ -1,3 +1,4 @@
1
- import type { BoardMiddleware, CoreEvent } from '@idraw/types';
1
+ import type { BoardMiddleware, CoreEventMap } from '@idraw/types';
2
+ import type { DeepRulerSharedStorage } from './types';
2
3
  export declare const middlewareEventRuler = "@middleware/show-ruler";
3
- export declare const MiddlewareRuler: BoardMiddleware<Record<string, any>, CoreEvent>;
4
+ export declare const MiddlewareRuler: BoardMiddleware<DeepRulerSharedStorage, CoreEventMap>;