@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.
Files changed (67) 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 -7
  4. package/dist/esm/index.js +31 -10
  5. package/dist/esm/lib/cursor-image.d.ts +1 -0
  6. package/dist/esm/lib/cursor-image.js +1 -0
  7. package/dist/esm/lib/cursor.d.ts +3 -12
  8. package/dist/esm/lib/cursor.js +136 -112
  9. package/dist/esm/middleware/dragger/index.d.ts +2 -2
  10. package/dist/esm/middleware/dragger/index.js +1 -0
  11. package/dist/esm/middleware/info/config.d.ts +4 -0
  12. package/dist/esm/middleware/info/config.js +8 -0
  13. package/dist/esm/middleware/info/draw-info.d.ts +29 -0
  14. package/dist/esm/middleware/info/draw-info.js +113 -0
  15. package/dist/esm/middleware/info/index.d.ts +3 -0
  16. package/dist/esm/middleware/info/index.js +112 -0
  17. package/dist/esm/middleware/info/types.d.ts +3 -0
  18. package/dist/esm/middleware/info/types.js +1 -0
  19. package/dist/esm/middleware/layout-selector/config.d.ts +9 -0
  20. package/dist/esm/middleware/layout-selector/config.js +9 -0
  21. package/dist/esm/middleware/layout-selector/index.d.ts +5 -0
  22. package/dist/esm/middleware/layout-selector/index.js +332 -0
  23. package/dist/esm/middleware/layout-selector/types.d.ts +15 -0
  24. package/dist/esm/middleware/layout-selector/types.js +2 -0
  25. package/dist/esm/middleware/layout-selector/util.d.ts +8 -0
  26. package/dist/esm/middleware/layout-selector/util.js +108 -0
  27. package/dist/esm/middleware/ruler/config.d.ts +7 -0
  28. package/dist/esm/middleware/ruler/config.js +21 -0
  29. package/dist/esm/middleware/ruler/index.d.ts +3 -2
  30. package/dist/esm/middleware/ruler/index.js +27 -11
  31. package/dist/esm/middleware/ruler/types.d.ts +3 -0
  32. package/dist/esm/middleware/ruler/types.js +1 -0
  33. package/dist/esm/middleware/ruler/util.d.ts +20 -4
  34. package/dist/esm/middleware/ruler/util.js +92 -21
  35. package/dist/esm/middleware/scaler/index.d.ts +2 -2
  36. package/dist/esm/middleware/scaler/index.js +1 -0
  37. package/dist/esm/middleware/scroller/config.d.ts +4 -0
  38. package/dist/esm/middleware/scroller/config.js +10 -0
  39. package/dist/esm/middleware/scroller/index.d.ts +3 -2
  40. package/dist/esm/middleware/scroller/index.js +44 -6
  41. package/dist/esm/middleware/scroller/types.d.ts +11 -0
  42. package/dist/esm/middleware/scroller/types.js +1 -0
  43. package/dist/esm/middleware/scroller/util.d.ts +3 -2
  44. package/dist/esm/middleware/scroller/util.js +32 -44
  45. package/dist/esm/middleware/selector/config.d.ts +11 -1
  46. package/dist/esm/middleware/selector/config.js +19 -1
  47. package/dist/esm/middleware/selector/draw-auxiliary.d.ts +1 -0
  48. package/dist/esm/middleware/selector/draw-auxiliary.js +12 -0
  49. package/dist/esm/middleware/selector/draw-base.d.ts +30 -0
  50. package/dist/esm/middleware/selector/draw-base.js +100 -0
  51. package/dist/esm/middleware/selector/draw-reference.d.ts +7 -0
  52. package/dist/esm/middleware/selector/draw-reference.js +31 -0
  53. package/dist/esm/middleware/selector/draw-wrapper.d.ts +16 -2
  54. package/dist/esm/middleware/selector/draw-wrapper.js +52 -35
  55. package/dist/esm/middleware/selector/index.d.ts +7 -4
  56. package/dist/esm/middleware/selector/index.js +287 -47
  57. package/dist/esm/middleware/selector/reference.d.ts +13 -0
  58. package/dist/esm/middleware/selector/reference.js +267 -0
  59. package/dist/esm/middleware/selector/types.d.ts +9 -4
  60. package/dist/esm/middleware/selector/types.js +2 -1
  61. package/dist/esm/middleware/selector/util.d.ts +11 -2
  62. package/dist/esm/middleware/selector/util.js +36 -14
  63. package/dist/esm/middleware/text-editor/index.d.ts +20 -2
  64. package/dist/esm/middleware/text-editor/index.js +92 -16
  65. package/dist/index.global.js +3827 -1006
  66. package/dist/index.global.min.js +1 -1
  67. package/package.json +5 -5
@@ -0,0 +1,108 @@
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.disabledTop) });
62
+ drawControllerLine(ctx, { start: topRight.center, end: bottomRight.center, centerVertexes: rightMiddle.vertexes, disabled: !!(operations === null || operations === void 0 ? void 0 : operations.disabledRight) });
63
+ drawControllerLine(ctx, { start: bottomRight.center, end: bottomLeft.center, centerVertexes: bottomMiddle.vertexes, disabled: !!(operations === null || operations === void 0 ? void 0 : operations.disabledBottom) });
64
+ drawControllerLine(ctx, { start: bottomLeft.center, end: topLeft.center, centerVertexes: leftMiddle.vertexes, disabled: !!(operations === null || operations === void 0 ? void 0 : operations.disabledLeft) });
65
+ const disabledOpts = {
66
+ lineWidth: 1,
67
+ strokeStyle: disableColor
68
+ };
69
+ if ((operations === null || operations === void 0 ? void 0 : operations.disabledTopLeft) === 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.disabledTopRight) === 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.disabledBottomRight) === 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.disabledBottomLeft) === true) {
88
+ drawControllerCross(ctx, Object.assign({ vertexes: bottomLeft.vertexes }, disabledOpts));
89
+ }
90
+ else {
91
+ drawControllerBox(ctx, bottomLeft.vertexes);
92
+ }
93
+ }
94
+ export function drawLayoutHover(ctx, opts) {
95
+ const { layoutSize } = opts;
96
+ const { x, y, w, h } = layoutSize;
97
+ ctx.setLineDash([]);
98
+ ctx.strokeStyle = selectColor;
99
+ ctx.lineWidth = 1;
100
+ ctx.beginPath();
101
+ ctx.moveTo(x, y);
102
+ ctx.lineTo(x + w, y);
103
+ ctx.lineTo(x + w, y + h);
104
+ ctx.lineTo(x, y + h);
105
+ ctx.lineTo(x, y);
106
+ ctx.closePath();
107
+ ctx.stroke();
108
+ }
@@ -0,0 +1,7 @@
1
+ import type { MiddlewareRulerStyle } from '@idraw/types';
2
+ export declare const rulerSize = 16;
3
+ export declare const fontSize = 10;
4
+ export declare const fontWeight = 100;
5
+ export declare const lineSize = 1;
6
+ export declare const fontFamily = "monospace";
7
+ export declare const defaultStyle: MiddlewareRulerStyle;
@@ -0,0 +1,21 @@
1
+ export const rulerSize = 16;
2
+ export const fontSize = 10;
3
+ export const fontWeight = 100;
4
+ export const lineSize = 1;
5
+ export const fontFamily = 'monospace';
6
+ const background = '#FFFFFFA8';
7
+ const borderColor = '#00000080';
8
+ const scaleColor = '#000000';
9
+ const textColor = '#00000080';
10
+ const gridColor = '#AAAAAA20';
11
+ const gridPrimaryColor = '#AAAAAA40';
12
+ const selectedAreaColor = '#196097';
13
+ export const defaultStyle = {
14
+ background,
15
+ borderColor,
16
+ scaleColor,
17
+ textColor,
18
+ gridColor,
19
+ gridPrimaryColor,
20
+ selectedAreaColor
21
+ };
@@ -1,3 +1,4 @@
1
- import type { BoardMiddleware, CoreEvent } from '@idraw/types';
1
+ import type { BoardMiddleware, CoreEventMap, MiddlewareRulerConfig } 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, MiddlewareRulerConfig>;
@@ -1,9 +1,21 @@
1
1
  import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
2
- import { drawRulerBackground, drawXRuler, drawYRuler, calcXRulerScaleList, calcYRulerScaleList, drawUnderGrid } from './util';
2
+ import { drawRulerBackground, drawXRuler, drawYRuler, calcXRulerScaleList, calcYRulerScaleList, drawGrid, drawScrollerSelectedArea } from './util';
3
+ import { defaultStyle } from './config';
3
4
  export const middlewareEventRuler = '@middleware/show-ruler';
4
- export const MiddlewareRuler = (opts) => {
5
- const { boardContent, viewer, eventHub } = opts;
6
- const { helperContext, underContext } = boardContent;
5
+ export const MiddlewareRuler = (opts, config) => {
6
+ const { boardContent, viewer, eventHub, calculator } = opts;
7
+ const { overlayContext, underlayContext } = boardContent;
8
+ const innerConfig = Object.assign(Object.assign({}, defaultStyle), config);
9
+ const { background, borderColor, scaleColor, textColor, gridColor, gridPrimaryColor, selectedAreaColor } = innerConfig;
10
+ const style = {
11
+ background,
12
+ borderColor,
13
+ scaleColor,
14
+ textColor,
15
+ gridColor,
16
+ gridPrimaryColor,
17
+ selectedAreaColor
18
+ };
7
19
  let show = true;
8
20
  let showGrid = true;
9
21
  const rulerCallback = (e) => {
@@ -18,6 +30,7 @@ export const MiddlewareRuler = (opts) => {
18
30
  }
19
31
  };
20
32
  return {
33
+ name: '@middleware/ruler',
21
34
  use() {
22
35
  eventHub.on(middlewareEventRuler, rulerCallback);
23
36
  },
@@ -28,17 +41,20 @@ export const MiddlewareRuler = (opts) => {
28
41
  if (show === true) {
29
42
  const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
30
43
  const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
31
- drawRulerBackground(helperContext, { viewScaleInfo, viewSizeInfo });
32
- const xList = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
33
- drawXRuler(helperContext, { scaleList: xList });
34
- const yList = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
35
- drawYRuler(helperContext, { scaleList: yList });
44
+ drawScrollerSelectedArea(overlayContext, { snapshot, calculator, style });
45
+ drawRulerBackground(overlayContext, { viewScaleInfo, viewSizeInfo, style });
46
+ const { list: xList, rulerUnit } = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
47
+ drawXRuler(overlayContext, { scaleList: xList, style });
48
+ const { list: yList } = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
49
+ drawYRuler(overlayContext, { scaleList: yList, style });
36
50
  if (showGrid === true) {
37
- drawUnderGrid(underContext, {
51
+ const ctx = rulerUnit === 1 ? overlayContext : underlayContext;
52
+ drawGrid(ctx, {
38
53
  xList,
39
54
  yList,
40
55
  viewScaleInfo,
41
- viewSizeInfo
56
+ viewSizeInfo,
57
+ style
42
58
  });
43
59
  }
44
60
  }
@@ -0,0 +1,3 @@
1
+ import { keySelectedElementList, keyActionType } from '../selector';
2
+ import type { DeepSelectorSharedStorage } from '../selector';
3
+ export type DeepRulerSharedStorage = Pick<DeepSelectorSharedStorage, typeof keySelectedElementList | typeof keyActionType>;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
- import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D } from '@idraw/types';
1
+ import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D, BoardViewerFrameSnapshot, ViewCalculator } from '@idraw/types';
2
+ import type { DeepRulerSharedStorage, MiddlewareRulerStyle } from './types';
2
3
  interface RulerScale {
3
4
  num: number;
4
5
  showNum: boolean;
@@ -9,25 +10,40 @@ interface RulerScale {
9
10
  export declare function calcXRulerScaleList(opts: {
10
11
  viewScaleInfo: ViewScaleInfo;
11
12
  viewSizeInfo: ViewSizeInfo;
12
- }): RulerScale[];
13
+ }): {
14
+ list: RulerScale[];
15
+ rulerUnit: number;
16
+ };
13
17
  export declare function calcYRulerScaleList(opts: {
14
18
  viewScaleInfo: ViewScaleInfo;
15
19
  viewSizeInfo: ViewSizeInfo;
16
- }): RulerScale[];
20
+ }): {
21
+ list: RulerScale[];
22
+ rulerUnit: number;
23
+ };
17
24
  export declare function drawXRuler(ctx: ViewContext2D, opts: {
18
25
  scaleList: RulerScale[];
26
+ style: MiddlewareRulerStyle;
19
27
  }): void;
20
28
  export declare function drawYRuler(ctx: ViewContext2D, opts: {
21
29
  scaleList: RulerScale[];
30
+ style: MiddlewareRulerStyle;
22
31
  }): void;
23
32
  export declare function drawRulerBackground(ctx: ViewContext2D, opts: {
24
33
  viewScaleInfo: ViewScaleInfo;
25
34
  viewSizeInfo: ViewSizeInfo;
35
+ style: MiddlewareRulerStyle;
26
36
  }): void;
27
- export declare function drawUnderGrid(ctx: ViewContext2D, opts: {
37
+ export declare function drawGrid(ctx: ViewContext2D, opts: {
28
38
  xList: RulerScale[];
29
39
  yList: RulerScale[];
30
40
  viewScaleInfo: ViewScaleInfo;
31
41
  viewSizeInfo: ViewSizeInfo;
42
+ style: MiddlewareRulerStyle;
43
+ }): void;
44
+ export declare function drawScrollerSelectedArea(ctx: ViewContext2D, opts: {
45
+ snapshot: BoardViewerFrameSnapshot<DeepRulerSharedStorage>;
46
+ calculator: ViewCalculator;
47
+ style: MiddlewareRulerStyle;
32
48
  }): void;
33
49
  export {};
@@ -1,21 +1,35 @@
1
- import { formatNumber, rotateByCenter } from '@idraw/util';
2
- const rulerSize = 16;
3
- const background = '#FFFFFFA8';
4
- const borderColor = '#00000080';
5
- const scaleColor = '#000000';
6
- const textColor = '#00000080';
7
- const fontFamily = 'monospace';
8
- const fontSize = 10;
9
- const fontWeight = 100;
10
- const gridColor = '#AAAAAA20';
11
- const gridKeyColor = '#AAAAAA40';
12
- const lineSize = 1;
1
+ import { formatNumber, rotateByCenter, getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
2
+ import { keySelectedElementList, keyActionType } from '../selector';
3
+ import { rulerSize, fontSize, fontWeight, lineSize, fontFamily } from './config';
4
+ const limitRulerUnitList = [1, 2, 5, 10, 20, 50, 100, 200, 500];
5
+ function limitRulerUnit(unit) {
6
+ unit = Math.max(limitRulerUnitList[0], Math.min(unit, limitRulerUnitList[limitRulerUnitList.length - 1]));
7
+ for (let i = 0; i < limitRulerUnitList.length - 1; i++) {
8
+ const thisUnit = limitRulerUnitList[i];
9
+ const nextUnit = limitRulerUnitList[i + 1];
10
+ if (unit > nextUnit) {
11
+ continue;
12
+ }
13
+ if (unit === thisUnit) {
14
+ return unit;
15
+ }
16
+ if (unit === nextUnit) {
17
+ return unit;
18
+ }
19
+ const mid = (thisUnit + nextUnit) / 2;
20
+ if (unit <= mid) {
21
+ return thisUnit;
22
+ }
23
+ return nextUnit;
24
+ }
25
+ return unit;
26
+ }
13
27
  function calcRulerScaleList(opts) {
14
28
  const { scale, viewLength, viewOffset } = opts;
15
29
  const list = [];
16
30
  let rulerUnit = 10;
17
31
  rulerUnit = formatNumber(rulerUnit / scale, { decimalPlaces: 0 });
18
- rulerUnit = Math.max(10, Math.min(rulerUnit, 1000));
32
+ rulerUnit = limitRulerUnit(rulerUnit);
19
33
  const rulerKeyUnit = rulerUnit * 10;
20
34
  const rulerSubKeyUnit = rulerUnit * 5;
21
35
  let index = 0;
@@ -38,7 +52,7 @@ function calcRulerScaleList(opts) {
38
52
  list.push(rulerScale);
39
53
  index++;
40
54
  }
41
- return list;
55
+ return { list, rulerUnit };
42
56
  }
43
57
  export function calcXRulerScaleList(opts) {
44
58
  const { viewScaleInfo, viewSizeInfo } = opts;
@@ -63,7 +77,8 @@ export function calcYRulerScaleList(opts) {
63
77
  });
64
78
  }
65
79
  export function drawXRuler(ctx, opts) {
66
- const { scaleList } = opts;
80
+ const { scaleList, style } = opts;
81
+ const { scaleColor, textColor } = style;
67
82
  const scaleDrawStart = rulerSize;
68
83
  const scaleDrawEnd = (rulerSize * 4) / 5;
69
84
  const subKeyScaleDrawEnd = (rulerSize * 2) / 5;
@@ -95,7 +110,8 @@ export function drawXRuler(ctx, opts) {
95
110
  }
96
111
  }
97
112
  export function drawYRuler(ctx, opts) {
98
- const { scaleList } = opts;
113
+ const { scaleList, style } = opts;
114
+ const { scaleColor, textColor } = style;
99
115
  const scaleDrawStart = rulerSize;
100
116
  const scaleDrawEnd = (rulerSize * 4) / 5;
101
117
  const subKeyScaleDrawEnd = (rulerSize * 2) / 5;
@@ -132,8 +148,9 @@ export function drawYRuler(ctx, opts) {
132
148
  }
133
149
  }
134
150
  export function drawRulerBackground(ctx, opts) {
135
- const { viewSizeInfo } = opts;
151
+ const { viewSizeInfo, style } = opts;
136
152
  const { width, height } = viewSizeInfo;
153
+ const { background, borderColor } = style;
137
154
  ctx.beginPath();
138
155
  ctx.moveTo(0, 0);
139
156
  ctx.lineTo(width + 1, 0);
@@ -150,16 +167,17 @@ export function drawRulerBackground(ctx, opts) {
150
167
  ctx.strokeStyle = borderColor;
151
168
  ctx.stroke();
152
169
  }
153
- export function drawUnderGrid(ctx, opts) {
154
- const { xList, yList, viewSizeInfo } = opts;
170
+ export function drawGrid(ctx, opts) {
171
+ const { xList, yList, viewSizeInfo, style } = opts;
155
172
  const { width, height } = viewSizeInfo;
173
+ const { gridColor, gridPrimaryColor } = style;
156
174
  for (let i = 0; i < xList.length; i++) {
157
175
  const item = xList[i];
158
176
  ctx.beginPath();
159
177
  ctx.moveTo(item.position, 0);
160
178
  ctx.lineTo(item.position, height);
161
179
  if (item.isKeyNum === true || item.isSubKeyNum === true) {
162
- ctx.strokeStyle = gridKeyColor;
180
+ ctx.strokeStyle = gridPrimaryColor;
163
181
  }
164
182
  else {
165
183
  ctx.strokeStyle = gridColor;
@@ -175,7 +193,7 @@ export function drawUnderGrid(ctx, opts) {
175
193
  ctx.moveTo(0, item.position);
176
194
  ctx.lineTo(width, item.position);
177
195
  if (item.isKeyNum === true || item.isSubKeyNum === true) {
178
- ctx.strokeStyle = gridKeyColor;
196
+ ctx.strokeStyle = gridPrimaryColor;
179
197
  }
180
198
  else {
181
199
  ctx.strokeStyle = gridColor;
@@ -185,3 +203,56 @@ export function drawUnderGrid(ctx, opts) {
185
203
  ctx.stroke();
186
204
  }
187
205
  }
206
+ export function drawScrollerSelectedArea(ctx, opts) {
207
+ const { snapshot, calculator, style } = opts;
208
+ const { sharedStore } = snapshot;
209
+ const { selectedAreaColor } = style;
210
+ const selectedElementList = sharedStore[keySelectedElementList];
211
+ const actionType = sharedStore[keyActionType];
212
+ if (['select', 'drag', 'drag-list', 'drag-list-end'].includes(actionType) && selectedElementList.length > 0) {
213
+ const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
214
+ const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
215
+ const rangeRectInfoList = [];
216
+ const xAreaStartList = [];
217
+ const xAreaEndList = [];
218
+ const yAreaStartList = [];
219
+ const yAreaEndList = [];
220
+ selectedElementList.forEach((elem) => {
221
+ const rectInfo = calculator.calcViewRectInfoFromRange(elem.uuid, {
222
+ viewScaleInfo,
223
+ viewSizeInfo
224
+ });
225
+ if (rectInfo) {
226
+ rangeRectInfoList.push(rectInfo);
227
+ xAreaStartList.push(rectInfo.left.x);
228
+ xAreaEndList.push(rectInfo.right.x);
229
+ yAreaStartList.push(rectInfo.top.y);
230
+ yAreaEndList.push(rectInfo.bottom.y);
231
+ }
232
+ });
233
+ if (!(rangeRectInfoList.length > 0)) {
234
+ return;
235
+ }
236
+ const xAreaStart = Math.min(...xAreaStartList);
237
+ const xAreaEnd = Math.max(...xAreaEndList);
238
+ const yAreaStart = Math.min(...yAreaStartList);
239
+ const yAreaEnd = Math.max(...yAreaEndList);
240
+ ctx.globalAlpha = 1;
241
+ ctx.beginPath();
242
+ ctx.moveTo(xAreaStart, 0);
243
+ ctx.lineTo(xAreaEnd, 0);
244
+ ctx.lineTo(xAreaEnd, rulerSize);
245
+ ctx.lineTo(xAreaStart, rulerSize);
246
+ ctx.fillStyle = selectedAreaColor;
247
+ ctx.closePath();
248
+ ctx.fill();
249
+ ctx.beginPath();
250
+ ctx.moveTo(0, yAreaStart);
251
+ ctx.lineTo(rulerSize, yAreaStart);
252
+ ctx.lineTo(rulerSize, yAreaEnd);
253
+ ctx.lineTo(0, yAreaEnd);
254
+ ctx.fillStyle = selectedAreaColor;
255
+ ctx.closePath();
256
+ ctx.fill();
257
+ }
258
+ }
@@ -1,3 +1,3 @@
1
- import type { BoardMiddleware, CoreEvent } from '@idraw/types';
1
+ import type { BoardMiddleware, CoreEventMap } from '@idraw/types';
2
2
  export declare const middlewareEventScale = "@middleware/scale";
3
- export declare const MiddlewareScaler: BoardMiddleware<Record<string, any>, CoreEvent>;
3
+ export declare const MiddlewareScaler: BoardMiddleware<Record<string, any>, CoreEventMap>;
@@ -5,6 +5,7 @@ export const MiddlewareScaler = (opts) => {
5
5
  const maxScale = 50;
6
6
  const minScale = 0.05;
7
7
  return {
8
+ name: '@middleware/scaler',
8
9
  wheelScale(e) {
9
10
  const { deltaY, point } = e;
10
11
  const { scale } = sharer.getActiveViewScaleInfo();
@@ -1,6 +1,10 @@
1
+ import type { MiddlewareScrollerStyle } from '@idraw/types';
1
2
  export declare const key = "SCROLL";
2
3
  export declare const keyXThumbRect: unique symbol;
3
4
  export declare const keyYThumbRect: unique symbol;
5
+ export declare const keyHoverXThumbRect: unique symbol;
6
+ export declare const keyHoverYThumbRect: unique symbol;
4
7
  export declare const keyPrevPoint: unique symbol;
5
8
  export declare const keyActivePoint: unique symbol;
6
9
  export declare const keyActiveThumbType: unique symbol;
10
+ export declare const defaultStyle: MiddlewareScrollerStyle;
@@ -1,6 +1,16 @@
1
1
  export const key = 'SCROLL';
2
2
  export const keyXThumbRect = Symbol(`${key}_xThumbRect`);
3
3
  export const keyYThumbRect = Symbol(`${key}_yThumbRect`);
4
+ export const keyHoverXThumbRect = Symbol(`${key}_hoverXThumbRect`);
5
+ export const keyHoverYThumbRect = Symbol(`${key}_hoverYThumbRect`);
4
6
  export const keyPrevPoint = Symbol(`${key}_prevPoint`);
5
7
  export const keyActivePoint = Symbol(`${key}_activePoint`);
6
8
  export const keyActiveThumbType = Symbol(`${key}_activeThumbType`);
9
+ export const defaultStyle = {
10
+ thumbBackground: '#0000003A',
11
+ thumbBorderColor: '#0000008A',
12
+ hoverThumbBackground: '#0000005F',
13
+ hoverThumbBorderColor: '#000000EE',
14
+ activeThumbBackground: '#0000005E',
15
+ activeThumbBorderColor: '#000000F0'
16
+ };
@@ -1,2 +1,3 @@
1
- import type { BoardMiddleware } from '@idraw/types';
2
- export declare const MiddlewareScroller: BoardMiddleware;
1
+ import type { BoardMiddleware, MiddlewareScrollerConfig } from '@idraw/types';
2
+ import type { DeepScrollerSharedStorage } from './types';
3
+ export declare const MiddlewareScroller: BoardMiddleware<DeepScrollerSharedStorage, any, MiddlewareScrollerConfig>;
@@ -1,14 +1,28 @@
1
1
  import { drawScroller, isPointInScrollThumb } from './util';
2
- import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType } from './config';
3
- export const MiddlewareScroller = (opts) => {
4
- const { viewer, boardContent, sharer } = opts;
5
- const { helperContext } = boardContent;
2
+ import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect, defaultStyle } from './config';
3
+ export const MiddlewareScroller = (opts, config) => {
4
+ const { viewer, boardContent, sharer, eventHub } = opts;
5
+ const { overlayContext } = boardContent;
6
6
  sharer.setSharedStorage(keyXThumbRect, null);
7
7
  sharer.setSharedStorage(keyYThumbRect, null);
8
+ let isBusy = false;
9
+ const innerConfig = Object.assign(Object.assign({}, defaultStyle), config);
10
+ const { thumbBackground, thumbBorderColor, hoverThumbBackground, hoverThumbBorderColor, activeThumbBackground, activeThumbBorderColor } = innerConfig;
11
+ const style = {
12
+ thumbBackground,
13
+ thumbBorderColor,
14
+ hoverThumbBackground,
15
+ hoverThumbBorderColor,
16
+ activeThumbBackground,
17
+ activeThumbBorderColor
18
+ };
8
19
  const clear = () => {
9
20
  sharer.setSharedStorage(keyPrevPoint, null);
10
21
  sharer.setSharedStorage(keyActivePoint, null);
11
22
  sharer.setSharedStorage(keyActiveThumbType, null);
23
+ sharer.setSharedStorage(keyHoverXThumbRect, null);
24
+ sharer.setSharedStorage(keyHoverYThumbRect, null);
25
+ isBusy = false;
12
26
  };
13
27
  clear();
14
28
  const scrollX = (p) => {
@@ -36,12 +50,13 @@ export const MiddlewareScroller = (opts) => {
36
50
  }
37
51
  };
38
52
  const getThumbType = (p) => {
39
- return isPointInScrollThumb(helperContext, p, {
53
+ return isPointInScrollThumb(overlayContext, p, {
40
54
  xThumbRect: sharer.getSharedStorage(keyXThumbRect),
41
55
  yThumbRect: sharer.getSharedStorage(keyYThumbRect)
42
56
  });
43
57
  };
44
58
  return {
59
+ name: '@middleware/scroller',
45
60
  wheel: (e) => {
46
61
  viewer.scroll({
47
62
  moveX: 0 - e.deltaX,
@@ -49,10 +64,32 @@ export const MiddlewareScroller = (opts) => {
49
64
  });
50
65
  viewer.drawFrame();
51
66
  },
67
+ hover: (e) => {
68
+ if (isBusy === true) {
69
+ return false;
70
+ }
71
+ const { point } = e;
72
+ const thumbType = getThumbType(point);
73
+ if (thumbType === 'X' || thumbType === 'Y') {
74
+ if (thumbType === 'X') {
75
+ sharer.setSharedStorage(keyHoverXThumbRect, true);
76
+ sharer.setSharedStorage(keyHoverYThumbRect, false);
77
+ }
78
+ else {
79
+ sharer.setSharedStorage(keyHoverXThumbRect, false);
80
+ sharer.setSharedStorage(keyHoverYThumbRect, true);
81
+ }
82
+ eventHub.trigger('cursor', { type: 'default' });
83
+ return false;
84
+ }
85
+ sharer.setSharedStorage(keyHoverXThumbRect, false);
86
+ sharer.setSharedStorage(keyHoverYThumbRect, false);
87
+ },
52
88
  pointStart: (e) => {
53
89
  const { point } = e;
54
90
  const thumbType = getThumbType(point);
55
91
  if (thumbType === 'X' || thumbType === 'Y') {
92
+ isBusy = true;
56
93
  sharer.setSharedStorage(keyActiveThumbType, thumbType);
57
94
  sharer.setSharedStorage(keyPrevPoint, point);
58
95
  return false;
@@ -74,6 +111,7 @@ export const MiddlewareScroller = (opts) => {
74
111
  }
75
112
  },
76
113
  pointEnd: () => {
114
+ isBusy = false;
77
115
  const activeThumbType = sharer.getSharedStorage(keyActiveThumbType);
78
116
  clear();
79
117
  if (activeThumbType === 'X' || activeThumbType === 'Y') {
@@ -83,7 +121,7 @@ export const MiddlewareScroller = (opts) => {
83
121
  }
84
122
  },
85
123
  beforeDrawFrame({ snapshot }) {
86
- const { xThumbRect, yThumbRect } = drawScroller(helperContext, { snapshot });
124
+ const { xThumbRect, yThumbRect } = drawScroller(overlayContext, { snapshot, style });
87
125
  sharer.setSharedStorage(keyXThumbRect, xThumbRect);
88
126
  sharer.setSharedStorage(keyYThumbRect, yThumbRect);
89
127
  }
@@ -0,0 +1,11 @@
1
+ import type { Point, ElementSize } from '@idraw/types';
2
+ import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
3
+ export type DeepScrollerSharedStorage = {
4
+ [keyXThumbRect]: null | ElementSize;
5
+ [keyYThumbRect]: null | ElementSize;
6
+ [keyHoverXThumbRect]: boolean | null;
7
+ [keyHoverYThumbRect]: boolean | null;
8
+ [keyPrevPoint]: null | Point;
9
+ [keyActivePoint]: null | Point;
10
+ [keyActiveThumbType]: null | 'X' | 'Y';
11
+ };
@@ -0,0 +1 @@
1
+ import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
@@ -1,11 +1,12 @@
1
- import type { Point, BoardViewerFrameSnapshot, ViewContext2D, ElementSize } from '@idraw/types';
1
+ import type { Point, BoardViewerFrameSnapshot, ViewContext2D, ElementSize, MiddlewareScrollerStyle } from '@idraw/types';
2
2
  export type ScrollbarThumbType = 'X' | 'Y';
3
- export declare function isPointInScrollThumb(helperContext: ViewContext2D, p: Point, opts: {
3
+ export declare function isPointInScrollThumb(overlayContext: ViewContext2D, p: Point, opts: {
4
4
  xThumbRect?: ElementSize | null;
5
5
  yThumbRect?: ElementSize | null;
6
6
  }): ScrollbarThumbType | null;
7
7
  export declare function drawScroller(ctx: ViewContext2D, opts: {
8
8
  snapshot: BoardViewerFrameSnapshot;
9
+ style: MiddlewareScrollerStyle;
9
10
  }): {
10
11
  xThumbRect: ElementSize;
11
12
  yThumbRect: ElementSize;