@idraw/core 0.4.0-beta.4 → 0.4.0-beta.41

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 (87) hide show
  1. package/dist/esm/board/index.d.ts +44 -0
  2. package/dist/esm/board/index.js +358 -0
  3. package/dist/esm/board/sharer.d.ts +21 -0
  4. package/dist/esm/board/sharer.js +101 -0
  5. package/dist/esm/board/viewer.d.ts +32 -0
  6. package/dist/esm/board/viewer.js +165 -0
  7. package/dist/esm/board/watcher.d.ts +15 -0
  8. package/dist/esm/board/watcher.js +218 -0
  9. package/dist/esm/config.d.ts +28 -0
  10. package/dist/esm/config.js +34 -0
  11. package/dist/esm/index.d.ts +37 -8
  12. package/dist/esm/index.js +265 -10
  13. package/dist/esm/lib/cursor-image.d.ts +1 -0
  14. package/dist/esm/lib/cursor-image.js +1 -0
  15. package/dist/esm/lib/cursor.d.ts +3 -12
  16. package/dist/esm/lib/cursor.js +137 -112
  17. package/dist/esm/middleware/dragger/index.d.ts +2 -2
  18. package/dist/esm/middleware/dragger/index.js +5 -3
  19. package/dist/esm/middleware/info/config.d.ts +5 -0
  20. package/dist/esm/middleware/info/config.js +9 -0
  21. package/dist/esm/middleware/info/draw-info.d.ts +29 -0
  22. package/dist/esm/middleware/info/draw-info.js +113 -0
  23. package/dist/esm/middleware/info/index.d.ts +9 -0
  24. package/dist/esm/middleware/info/index.js +131 -0
  25. package/dist/esm/middleware/info/types.d.ts +3 -0
  26. package/dist/esm/middleware/info/types.js +1 -0
  27. package/dist/esm/middleware/layout-selector/config.d.ts +11 -0
  28. package/dist/esm/middleware/layout-selector/config.js +12 -0
  29. package/dist/esm/middleware/layout-selector/index.d.ts +5 -0
  30. package/dist/esm/middleware/layout-selector/index.js +371 -0
  31. package/dist/esm/middleware/layout-selector/types.d.ts +17 -0
  32. package/dist/esm/middleware/layout-selector/types.js +2 -0
  33. package/dist/esm/middleware/layout-selector/util.d.ts +9 -0
  34. package/dist/esm/middleware/layout-selector/util.js +78 -0
  35. package/dist/esm/middleware/pointer/index.d.ts +3 -0
  36. package/dist/esm/middleware/pointer/index.js +42 -0
  37. package/dist/esm/middleware/pointer/types.d.ts +3 -0
  38. package/dist/esm/middleware/pointer/types.js +1 -0
  39. package/dist/esm/middleware/ruler/config.d.ts +7 -0
  40. package/dist/esm/middleware/ruler/config.js +21 -0
  41. package/dist/esm/middleware/ruler/index.d.ts +3 -3
  42. package/dist/esm/middleware/ruler/index.js +33 -14
  43. package/dist/esm/middleware/ruler/types.d.ts +3 -0
  44. package/dist/esm/middleware/ruler/types.js +1 -0
  45. package/dist/esm/middleware/ruler/util.d.ts +20 -4
  46. package/dist/esm/middleware/ruler/util.js +99 -26
  47. package/dist/esm/middleware/scaler/index.d.ts +2 -3
  48. package/dist/esm/middleware/scaler/index.js +3 -2
  49. package/dist/esm/middleware/scroller/config.d.ts +4 -0
  50. package/dist/esm/middleware/scroller/config.js +10 -0
  51. package/dist/esm/middleware/scroller/index.d.ts +3 -2
  52. package/dist/esm/middleware/scroller/index.js +48 -6
  53. package/dist/esm/middleware/scroller/types.d.ts +11 -0
  54. package/dist/esm/middleware/scroller/types.js +1 -0
  55. package/dist/esm/middleware/scroller/util.d.ts +3 -2
  56. package/dist/esm/middleware/scroller/util.js +33 -44
  57. package/dist/esm/middleware/selector/config.d.ts +9 -1
  58. package/dist/esm/middleware/selector/config.js +17 -1
  59. package/dist/esm/middleware/selector/draw-auxiliary.d.ts +1 -0
  60. package/dist/esm/middleware/selector/draw-auxiliary.js +12 -0
  61. package/dist/esm/middleware/selector/draw-base.d.ts +30 -0
  62. package/dist/esm/middleware/selector/draw-base.js +100 -0
  63. package/dist/esm/middleware/selector/draw-debug.d.ts +5 -0
  64. package/dist/esm/middleware/selector/draw-debug.js +30 -0
  65. package/dist/esm/middleware/selector/draw-reference.d.ts +7 -0
  66. package/dist/esm/middleware/selector/draw-reference.js +31 -0
  67. package/dist/esm/middleware/selector/draw-wrapper.d.ts +16 -1
  68. package/dist/esm/middleware/selector/draw-wrapper.js +70 -38
  69. package/dist/esm/middleware/selector/index.d.ts +11 -4
  70. package/dist/esm/middleware/selector/index.js +450 -70
  71. package/dist/esm/middleware/selector/pattern/icon-rotate.d.ts +4 -0
  72. package/dist/esm/middleware/selector/pattern/icon-rotate.js +88 -0
  73. package/dist/esm/middleware/selector/pattern/index.d.ts +8 -0
  74. package/dist/esm/middleware/selector/pattern/index.js +38 -0
  75. package/dist/esm/middleware/selector/reference.d.ts +13 -0
  76. package/dist/esm/middleware/selector/reference.js +267 -0
  77. package/dist/esm/middleware/selector/types.d.ts +11 -5
  78. package/dist/esm/middleware/selector/types.js +2 -1
  79. package/dist/esm/middleware/selector/util.d.ts +14 -7
  80. package/dist/esm/middleware/selector/util.js +45 -43
  81. package/dist/esm/middleware/text-editor/index.d.ts +20 -3
  82. package/dist/esm/middleware/text-editor/index.js +168 -28
  83. package/dist/esm/record.d.ts +5 -0
  84. package/dist/esm/record.js +38 -0
  85. package/dist/index.global.js +5729 -1519
  86. package/dist/index.global.min.js +1 -1
  87. package/package.json +5 -6
@@ -1,4 +1,5 @@
1
- import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D } from '@idraw/types';
1
+ import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D, BoardViewerFrameSnapshot, ViewCalculator, MiddlewareRulerStyle } from '@idraw/types';
2
+ import type { DeepRulerSharedStorage } 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,34 +148,37 @@ 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
- ctx.moveTo(0, 0);
139
- ctx.lineTo(width + 1, 0);
155
+ const basePosition = -1;
156
+ ctx.moveTo(basePosition, basePosition);
157
+ ctx.lineTo(width + 1, basePosition);
140
158
  ctx.lineTo(width + 1, rulerSize);
141
159
  ctx.lineTo(rulerSize, rulerSize);
142
160
  ctx.lineTo(rulerSize, height + 1);
143
- ctx.lineTo(0, height + 1);
144
- ctx.lineTo(0, 0);
161
+ ctx.lineTo(basePosition, height + 1);
162
+ ctx.lineTo(basePosition, basePosition);
145
163
  ctx.closePath();
146
164
  ctx.fillStyle = background;
147
- ctx.fill();
165
+ ctx.fill('nonzero');
148
166
  ctx.lineWidth = lineSize;
149
167
  ctx.setLineDash([]);
150
168
  ctx.strokeStyle = borderColor;
151
169
  ctx.stroke();
152
170
  }
153
- export function drawUnderGrid(ctx, opts) {
154
- const { xList, yList, viewSizeInfo } = opts;
171
+ export function drawGrid(ctx, opts) {
172
+ const { xList, yList, viewSizeInfo, style } = opts;
155
173
  const { width, height } = viewSizeInfo;
174
+ const { gridColor, gridPrimaryColor } = style;
156
175
  for (let i = 0; i < xList.length; i++) {
157
176
  const item = xList[i];
158
177
  ctx.beginPath();
159
178
  ctx.moveTo(item.position, 0);
160
179
  ctx.lineTo(item.position, height);
161
180
  if (item.isKeyNum === true || item.isSubKeyNum === true) {
162
- ctx.strokeStyle = gridKeyColor;
181
+ ctx.strokeStyle = gridPrimaryColor;
163
182
  }
164
183
  else {
165
184
  ctx.strokeStyle = gridColor;
@@ -175,7 +194,7 @@ export function drawUnderGrid(ctx, opts) {
175
194
  ctx.moveTo(0, item.position);
176
195
  ctx.lineTo(width, item.position);
177
196
  if (item.isKeyNum === true || item.isSubKeyNum === true) {
178
- ctx.strokeStyle = gridKeyColor;
197
+ ctx.strokeStyle = gridPrimaryColor;
179
198
  }
180
199
  else {
181
200
  ctx.strokeStyle = gridColor;
@@ -185,3 +204,57 @@ export function drawUnderGrid(ctx, opts) {
185
204
  ctx.stroke();
186
205
  }
187
206
  }
207
+ export function drawScrollerSelectedArea(ctx, opts) {
208
+ const { snapshot, calculator, style } = opts;
209
+ const { sharedStore } = snapshot;
210
+ const { selectedAreaColor } = style;
211
+ const selectedElementList = sharedStore[keySelectedElementList];
212
+ const actionType = sharedStore[keyActionType];
213
+ if (['select', 'drag', 'drag-list', 'drag-list-end'].includes(actionType) &&
214
+ selectedElementList.length > 0) {
215
+ const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
216
+ const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
217
+ const rangeRectInfoList = [];
218
+ const xAreaStartList = [];
219
+ const xAreaEndList = [];
220
+ const yAreaStartList = [];
221
+ const yAreaEndList = [];
222
+ selectedElementList.forEach((elem) => {
223
+ const rectInfo = calculator.calcViewRectInfoFromRange(elem.uuid, {
224
+ viewScaleInfo,
225
+ viewSizeInfo
226
+ });
227
+ if (rectInfo) {
228
+ rangeRectInfoList.push(rectInfo);
229
+ xAreaStartList.push(rectInfo.left.x);
230
+ xAreaEndList.push(rectInfo.right.x);
231
+ yAreaStartList.push(rectInfo.top.y);
232
+ yAreaEndList.push(rectInfo.bottom.y);
233
+ }
234
+ });
235
+ if (!(rangeRectInfoList.length > 0)) {
236
+ return;
237
+ }
238
+ const xAreaStart = Math.min(...xAreaStartList);
239
+ const xAreaEnd = Math.max(...xAreaEndList);
240
+ const yAreaStart = Math.min(...yAreaStartList);
241
+ const yAreaEnd = Math.max(...yAreaEndList);
242
+ ctx.globalAlpha = 1;
243
+ ctx.beginPath();
244
+ ctx.moveTo(xAreaStart, 0);
245
+ ctx.lineTo(xAreaEnd, 0);
246
+ ctx.lineTo(xAreaEnd, rulerSize);
247
+ ctx.lineTo(xAreaStart, rulerSize);
248
+ ctx.fillStyle = selectedAreaColor;
249
+ ctx.closePath();
250
+ ctx.fill('nonzero');
251
+ ctx.beginPath();
252
+ ctx.moveTo(0, yAreaStart);
253
+ ctx.lineTo(rulerSize, yAreaStart);
254
+ ctx.lineTo(rulerSize, yAreaEnd);
255
+ ctx.lineTo(0, yAreaEnd);
256
+ ctx.fillStyle = selectedAreaColor;
257
+ ctx.closePath();
258
+ ctx.fill('nonzero');
259
+ }
260
+ }
@@ -1,3 +1,2 @@
1
- import type { BoardMiddleware, CoreEvent } from '@idraw/types';
2
- export declare const middlewareEventScale = "@middleware/scale";
3
- export declare const MiddlewareScaler: BoardMiddleware<Record<string, any>, CoreEvent>;
1
+ import type { Middleware, CoreEventMap } from '@idraw/types';
2
+ export declare const MiddlewareScaler: Middleware<Record<string, any>, CoreEventMap>;
@@ -1,10 +1,11 @@
1
1
  import { formatNumber } from '@idraw/util';
2
- export const middlewareEventScale = '@middleware/scale';
2
+ import { coreEventKeys } from '../../config';
3
3
  export const MiddlewareScaler = (opts) => {
4
4
  const { viewer, sharer, eventHub } = 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();
@@ -22,7 +23,7 @@ export const MiddlewareScaler = (opts) => {
22
23
  viewer.scroll({ moveX, moveY });
23
24
  viewer.drawFrame();
24
25
  const scaleNum = formatNumber(scale);
25
- eventHub.trigger(middlewareEventScale, { scale: scaleNum });
26
+ eventHub.trigger(coreEventKeys.SCALE, { scale: scaleNum });
26
27
  }
27
28
  };
28
29
  };
@@ -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 { Middleware, MiddlewareScrollerConfig } from '@idraw/types';
2
+ import type { DeepScrollerSharedStorage } from './types';
3
+ export declare const MiddlewareScroller: Middleware<DeepScrollerSharedStorage, any, MiddlewareScrollerConfig>;
@@ -1,14 +1,20 @@
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
+ import { coreEventKeys } from '../../config';
4
+ export const MiddlewareScroller = (opts, config) => {
5
+ const { viewer, boardContent, sharer, eventHub } = opts;
6
+ const { overlayContext } = boardContent;
6
7
  sharer.setSharedStorage(keyXThumbRect, null);
7
8
  sharer.setSharedStorage(keyYThumbRect, null);
9
+ let isBusy = false;
10
+ let innerConfig = Object.assign(Object.assign({}, defaultStyle), config);
8
11
  const clear = () => {
9
12
  sharer.setSharedStorage(keyPrevPoint, null);
10
13
  sharer.setSharedStorage(keyActivePoint, null);
11
14
  sharer.setSharedStorage(keyActiveThumbType, null);
15
+ sharer.setSharedStorage(keyHoverXThumbRect, null);
16
+ sharer.setSharedStorage(keyHoverYThumbRect, null);
17
+ isBusy = false;
12
18
  };
13
19
  clear();
14
20
  const scrollX = (p) => {
@@ -36,12 +42,16 @@ export const MiddlewareScroller = (opts) => {
36
42
  }
37
43
  };
38
44
  const getThumbType = (p) => {
39
- return isPointInScrollThumb(helperContext, p, {
45
+ return isPointInScrollThumb(overlayContext, p, {
40
46
  xThumbRect: sharer.getSharedStorage(keyXThumbRect),
41
47
  yThumbRect: sharer.getSharedStorage(keyYThumbRect)
42
48
  });
43
49
  };
44
50
  return {
51
+ name: '@middleware/scroller',
52
+ resetConfig(config) {
53
+ innerConfig = Object.assign(Object.assign({}, innerConfig), config);
54
+ },
45
55
  wheel: (e) => {
46
56
  viewer.scroll({
47
57
  moveX: 0 - e.deltaX,
@@ -49,10 +59,32 @@ export const MiddlewareScroller = (opts) => {
49
59
  });
50
60
  viewer.drawFrame();
51
61
  },
62
+ hover: (e) => {
63
+ if (isBusy === true) {
64
+ return false;
65
+ }
66
+ const { point } = e;
67
+ const thumbType = getThumbType(point);
68
+ if (thumbType === 'X' || thumbType === 'Y') {
69
+ if (thumbType === 'X') {
70
+ sharer.setSharedStorage(keyHoverXThumbRect, true);
71
+ sharer.setSharedStorage(keyHoverYThumbRect, false);
72
+ }
73
+ else {
74
+ sharer.setSharedStorage(keyHoverXThumbRect, false);
75
+ sharer.setSharedStorage(keyHoverYThumbRect, true);
76
+ }
77
+ eventHub.trigger(coreEventKeys.CURSOR, { type: 'default' });
78
+ return false;
79
+ }
80
+ sharer.setSharedStorage(keyHoverXThumbRect, false);
81
+ sharer.setSharedStorage(keyHoverYThumbRect, false);
82
+ },
52
83
  pointStart: (e) => {
53
84
  const { point } = e;
54
85
  const thumbType = getThumbType(point);
55
86
  if (thumbType === 'X' || thumbType === 'Y') {
87
+ isBusy = true;
56
88
  sharer.setSharedStorage(keyActiveThumbType, thumbType);
57
89
  sharer.setSharedStorage(keyPrevPoint, point);
58
90
  return false;
@@ -74,6 +106,7 @@ export const MiddlewareScroller = (opts) => {
74
106
  }
75
107
  },
76
108
  pointEnd: () => {
109
+ isBusy = false;
77
110
  const activeThumbType = sharer.getSharedStorage(keyActiveThumbType);
78
111
  clear();
79
112
  if (activeThumbType === 'X' || activeThumbType === 'Y') {
@@ -83,7 +116,16 @@ export const MiddlewareScroller = (opts) => {
83
116
  }
84
117
  },
85
118
  beforeDrawFrame({ snapshot }) {
86
- const { xThumbRect, yThumbRect } = drawScroller(helperContext, { snapshot });
119
+ const { thumbBackground, thumbBorderColor, hoverThumbBackground, hoverThumbBorderColor, activeThumbBackground, activeThumbBorderColor } = innerConfig;
120
+ const style = {
121
+ thumbBackground,
122
+ thumbBorderColor,
123
+ hoverThumbBackground,
124
+ hoverThumbBorderColor,
125
+ activeThumbBackground,
126
+ activeThumbBorderColor
127
+ };
128
+ const { xThumbRect, yThumbRect } = drawScroller(overlayContext, { snapshot, style });
87
129
  sharer.setSharedStorage(keyXThumbRect, xThumbRect);
88
130
  sharer.setSharedStorage(keyYThumbRect, yThumbRect);
89
131
  }
@@ -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;
@@ -1,16 +1,9 @@
1
1
  import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
2
- import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect } from './config';
3
- const minScrollerWidth = 12;
2
+ import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
4
3
  const scrollerLineWidth = 16;
5
- const scrollerThumbAlpha = 0.36;
6
- const scrollConfig = {
7
- width: minScrollerWidth,
8
- thumbColor: '#000000AA',
9
- scrollBarColor: '#FFFFFF60',
10
- showScrollBar: false
11
- };
12
- function isPointAtRect(helperContext, p, rect) {
13
- const ctx = helperContext;
4
+ const minThumbLength = scrollerLineWidth * 2.5;
5
+ function isPointAtRect(overlayContext, p, rect) {
6
+ const ctx = overlayContext;
14
7
  const { x, y, w, h } = rect;
15
8
  ctx.beginPath();
16
9
  ctx.rect(x, y, w, h);
@@ -20,13 +13,13 @@ function isPointAtRect(helperContext, p, rect) {
20
13
  }
21
14
  return false;
22
15
  }
23
- export function isPointInScrollThumb(helperContext, p, opts) {
16
+ export function isPointInScrollThumb(overlayContext, p, opts) {
24
17
  let thumbType = null;
25
18
  const { xThumbRect, yThumbRect } = opts;
26
- if (xThumbRect && isPointAtRect(helperContext, p, xThumbRect)) {
19
+ if (xThumbRect && isPointAtRect(overlayContext, p, xThumbRect)) {
27
20
  thumbType = 'X';
28
21
  }
29
- else if (yThumbRect && isPointAtRect(helperContext, p, yThumbRect)) {
22
+ else if (yThumbRect && isPointAtRect(overlayContext, p, yThumbRect)) {
30
23
  thumbType = 'Y';
31
24
  }
32
25
  return thumbType;
@@ -38,15 +31,19 @@ function getScrollInfoFromSnapshot(snapshot) {
38
31
  prevPoint: sharedStore[keyPrevPoint] || null,
39
32
  activeThumbType: sharedStore[keyActiveThumbType] || null,
40
33
  xThumbRect: sharedStore[keyXThumbRect] || null,
41
- yThumbRect: sharedStore[keyYThumbRect] || null
34
+ yThumbRect: sharedStore[keyYThumbRect] || null,
35
+ hoverXThumb: sharedStore[keyHoverXThumbRect],
36
+ hoverYThumb: sharedStore[keyHoverYThumbRect]
42
37
  };
43
38
  return info;
44
39
  }
45
- function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
40
+ function calcScrollerInfo(opts) {
41
+ const { viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb, style } = opts;
46
42
  const { width, height } = viewSizeInfo;
47
43
  const { offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo;
48
- const sliderMinSize = scrollerLineWidth * 2.5;
44
+ const sliderMinSize = minThumbLength;
49
45
  const lineSize = scrollerLineWidth;
46
+ const { thumbBackground, thumbBorderColor, hoverThumbBackground, hoverThumbBorderColor } = style;
50
47
  let xSize = 0;
51
48
  let ySize = 0;
52
49
  xSize = Math.max(sliderMinSize, width - lineSize * 2 - (Math.abs(offsetLeft) + Math.abs(offsetRight)));
@@ -101,8 +98,10 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
101
98
  ySize,
102
99
  translateY,
103
100
  translateX,
104
- thumbColor: scrollConfig.thumbColor,
105
- scrollBarColor: scrollConfig.scrollBarColor,
101
+ xThumbBackground: hoverXThumb ? hoverThumbBackground : thumbBackground,
102
+ yThumbBackground: hoverYThumb ? hoverThumbBackground : thumbBackground,
103
+ xThumbBorderColor: hoverXThumb ? hoverThumbBorderColor : thumbBorderColor,
104
+ yThumbBorderColor: hoverYThumb ? hoverThumbBorderColor : thumbBorderColor,
106
105
  xThumbRect,
107
106
  yThumbRect
108
107
  };
@@ -110,13 +109,14 @@ function calcScrollerInfo(viewScaleInfo, viewSizeInfo) {
110
109
  }
111
110
  function drawScrollerThumb(ctx, opts) {
112
111
  let { x, y, h, w } = opts;
112
+ const { background, borderColor } = opts;
113
113
  ctx.save();
114
114
  ctx.shadowColor = '#FFFFFF';
115
115
  ctx.shadowOffsetX = 0;
116
116
  ctx.shadowOffsetY = 0;
117
117
  ctx.shadowBlur = 1;
118
118
  {
119
- const { color, axis } = opts;
119
+ const { axis } = opts;
120
120
  if (axis === 'X') {
121
121
  y = y + h / 4 + 0;
122
122
  h = h / 2;
@@ -130,7 +130,7 @@ function drawScrollerThumb(ctx, opts) {
130
130
  if (w < r * 2 || h < r * 2) {
131
131
  r = 0;
132
132
  }
133
- ctx.globalAlpha = scrollerThumbAlpha;
133
+ ctx.globalAlpha = 1;
134
134
  ctx.beginPath();
135
135
  ctx.moveTo(x + r, y);
136
136
  ctx.arcTo(x + w, y, x + w, y + h, r);
@@ -138,12 +138,11 @@ function drawScrollerThumb(ctx, opts) {
138
138
  ctx.arcTo(x, y + h, x, y, r);
139
139
  ctx.arcTo(x, y, x + w, y, r);
140
140
  ctx.closePath();
141
- ctx.fillStyle = color;
142
- ctx.fill();
143
- ctx.globalAlpha = 1;
141
+ ctx.fillStyle = background;
142
+ ctx.fill('nonzero');
144
143
  ctx.beginPath();
145
144
  ctx.lineWidth = 1;
146
- ctx.strokeStyle = color;
145
+ ctx.strokeStyle = borderColor;
147
146
  ctx.setLineDash([]);
148
147
  ctx.moveTo(x + r, y);
149
148
  ctx.arcTo(x + w, y, x + w, y + h, r);
@@ -155,12 +154,11 @@ function drawScrollerThumb(ctx, opts) {
155
154
  }
156
155
  ctx.restore();
157
156
  }
158
- function drawScrollerInfo(helperContext, opts) {
159
- const ctx = helperContext;
160
- const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
161
- const { activeThumbType, prevPoint, activePoint } = scrollInfo;
162
- const { width, height } = viewSizeInfo;
163
- const wrapper = calcScrollerInfo(viewScaleInfo, viewSizeInfo);
157
+ function drawScrollerInfo(overlayContext, opts) {
158
+ const ctx = overlayContext;
159
+ const { viewScaleInfo, viewSizeInfo, scrollInfo, style } = opts;
160
+ const { activeThumbType, prevPoint, activePoint, hoverXThumb, hoverYThumb } = scrollInfo;
161
+ const wrapper = calcScrollerInfo({ viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb, style });
164
162
  let xThumbRect = Object.assign({}, wrapper.xThumbRect);
165
163
  let yThumbRect = Object.assign({}, wrapper.yThumbRect);
166
164
  if (activeThumbType && prevPoint && activePoint) {
@@ -173,27 +171,18 @@ function drawScrollerInfo(helperContext, opts) {
173
171
  yThumbRect.y = yThumbRect.y + (activePoint.y - prevPoint.y);
174
172
  }
175
173
  }
176
- if (scrollConfig.showScrollBar === true) {
177
- ctx.fillStyle = wrapper.scrollBarColor;
178
- ctx.fillRect(0, height - wrapper.lineSize, width, wrapper.lineSize);
179
- }
180
- drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.thumbColor }));
181
- if (scrollConfig.showScrollBar === true) {
182
- ctx.fillStyle = wrapper.scrollBarColor;
183
- ctx.fillRect(width - wrapper.lineSize, 0, wrapper.lineSize, height);
184
- }
185
- drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.thumbColor }));
186
- ctx.globalAlpha = 1;
174
+ drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, background: wrapper.xThumbBackground, borderColor: wrapper.xThumbBorderColor }));
175
+ drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, background: wrapper.yThumbBackground, borderColor: wrapper.yThumbBorderColor }));
187
176
  return {
188
177
  xThumbRect,
189
178
  yThumbRect
190
179
  };
191
180
  }
192
181
  export function drawScroller(ctx, opts) {
193
- const { snapshot } = opts;
182
+ const { snapshot, style } = opts;
194
183
  const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
195
184
  const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
196
185
  const scrollInfo = getScrollInfoFromSnapshot(snapshot);
197
- const { xThumbRect, yThumbRect } = drawScrollerInfo(ctx, { viewSizeInfo, viewScaleInfo, scrollInfo });
186
+ const { xThumbRect, yThumbRect } = drawScrollerInfo(ctx, { viewSizeInfo, viewScaleInfo, scrollInfo, style });
198
187
  return { xThumbRect, yThumbRect };
199
188
  }
@@ -1,3 +1,4 @@
1
+ import type { MiddlewareSelectorStyle } from '@idraw/types';
1
2
  export declare const key = "SELECT";
2
3
  export declare const keyActionType: unique symbol;
3
4
  export declare const keyResizeType: unique symbol;
@@ -8,8 +9,12 @@ export declare const keyHoverElementVertexes: unique symbol;
8
9
  export declare const keySelectedElementList: unique symbol;
9
10
  export declare const keySelectedElementListVertexes: unique symbol;
10
11
  export declare const keySelectedElementController: unique symbol;
12
+ export declare const keySelectedElementPosition: unique symbol;
11
13
  export declare const keyGroupQueue: unique symbol;
12
14
  export declare const keyGroupQueueVertexesList: unique symbol;
15
+ export declare const keyIsMoving: unique symbol;
16
+ export declare const keyEnableSelectInGroup: unique symbol;
17
+ export declare const keyEnableSnapToGrid: unique symbol;
13
18
  export declare const keyDebugElemCenter: unique symbol;
14
19
  export declare const keyDebugStartVertical: unique symbol;
15
20
  export declare const keyDebugEndVertical: unique symbol;
@@ -19,4 +24,7 @@ export declare const keyDebugEnd0: unique symbol;
19
24
  export declare const selectWrapperBorderWidth = 2;
20
25
  export declare const resizeControllerBorderWidth = 4;
21
26
  export declare const areaBorderWidth = 1;
22
- export declare const wrapperColor = "#1973ba";
27
+ export declare const controllerSize = 10;
28
+ export declare const rotateControllerSize = 20;
29
+ export declare const rotateControllerPosition = 22;
30
+ export declare const defaultStyle: MiddlewareSelectorStyle;
@@ -8,8 +8,12 @@ export const keyHoverElementVertexes = Symbol(`${key}_hoverElementVertexes`);
8
8
  export const keySelectedElementList = Symbol(`${key}_selectedElementList`);
9
9
  export const keySelectedElementListVertexes = Symbol(`${key}_selectedElementListVertexes`);
10
10
  export const keySelectedElementController = Symbol(`${key}_selectedElementController`);
11
+ export const keySelectedElementPosition = Symbol(`${key}_selectedElementPosition`);
11
12
  export const keyGroupQueue = Symbol(`${key}_groupQueue`);
12
13
  export const keyGroupQueueVertexesList = Symbol(`${key}_groupQueueVertexesList`);
14
+ export const keyIsMoving = Symbol(`${key}_isMoving`);
15
+ export const keyEnableSelectInGroup = Symbol(`${key}_enableSelectInGroup`);
16
+ export const keyEnableSnapToGrid = Symbol(`${key}_enableSnapToGrid`);
13
17
  export const keyDebugElemCenter = Symbol(`${key}_debug_elemCenter`);
14
18
  export const keyDebugStartVertical = Symbol(`${key}_debug_startVertical`);
15
19
  export const keyDebugEndVertical = Symbol(`${key}_debug_endVertical`);
@@ -19,4 +23,16 @@ export const keyDebugEnd0 = Symbol(`${key}_debug_end0`);
19
23
  export const selectWrapperBorderWidth = 2;
20
24
  export const resizeControllerBorderWidth = 4;
21
25
  export const areaBorderWidth = 1;
22
- export const wrapperColor = '#1973ba';
26
+ export const controllerSize = 10;
27
+ export const rotateControllerSize = 20;
28
+ export const rotateControllerPosition = 22;
29
+ const activeColor = '#1973ba';
30
+ const activeAreaColor = '#1976d21c';
31
+ const lockedColor = '#5b5959b5';
32
+ const referenceColor = '#f7276e';
33
+ export const defaultStyle = {
34
+ activeColor,
35
+ activeAreaColor,
36
+ lockedColor,
37
+ referenceColor
38
+ };
@@ -0,0 +1 @@
1
+ export {};