@idraw/core 0.4.0-beta.30 → 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 (33) hide show
  1. package/dist/esm/index.d.ts +2 -2
  2. package/dist/esm/index.js +2 -2
  3. package/dist/esm/middleware/info/config.d.ts +4 -0
  4. package/dist/esm/middleware/info/config.js +8 -0
  5. package/dist/esm/middleware/info/draw-info.d.ts +4 -6
  6. package/dist/esm/middleware/info/draw-info.js +12 -9
  7. package/dist/esm/middleware/info/index.d.ts +2 -2
  8. package/dist/esm/middleware/info/index.js +11 -9
  9. package/dist/esm/middleware/ruler/config.d.ts +7 -0
  10. package/dist/esm/middleware/ruler/config.js +21 -0
  11. package/dist/esm/middleware/ruler/index.d.ts +2 -2
  12. package/dist/esm/middleware/ruler/index.js +19 -6
  13. package/dist/esm/middleware/ruler/util.d.ts +6 -1
  14. package/dist/esm/middleware/ruler/util.js +13 -19
  15. package/dist/esm/middleware/scroller/config.d.ts +2 -0
  16. package/dist/esm/middleware/scroller/config.js +8 -0
  17. package/dist/esm/middleware/scroller/index.d.ts +2 -2
  18. package/dist/esm/middleware/scroller/index.js +13 -3
  19. package/dist/esm/middleware/scroller/util.d.ts +2 -1
  20. package/dist/esm/middleware/scroller/util.js +19 -36
  21. package/dist/esm/middleware/selector/config.d.ts +2 -4
  22. package/dist/esm/middleware/selector/config.js +10 -4
  23. package/dist/esm/middleware/selector/draw-auxiliary.d.ts +1 -7
  24. package/dist/esm/middleware/selector/draw-auxiliary.js +1 -35
  25. package/dist/esm/middleware/selector/draw-reference.d.ts +2 -0
  26. package/dist/esm/middleware/selector/draw-reference.js +2 -2
  27. package/dist/esm/middleware/selector/draw-wrapper.d.ts +7 -1
  28. package/dist/esm/middleware/selector/draw-wrapper.js +22 -13
  29. package/dist/esm/middleware/selector/index.d.ts +2 -2
  30. package/dist/esm/middleware/selector/index.js +16 -11
  31. package/dist/index.global.js +193 -104
  32. package/dist/index.global.min.js +1 -1
  33. package/package.json +5 -5
@@ -13,8 +13,8 @@ export declare class Core<E extends CoreEventMap = CoreEventMap> {
13
13
  constructor(container: HTMLDivElement, opts: CoreOptions);
14
14
  isDestroyed(): boolean;
15
15
  destroy(): void;
16
- use(middleware: BoardMiddleware<any, any>): void;
17
- disuse(middleware: BoardMiddleware<any, any>): void;
16
+ use<C extends any = any>(middleware: BoardMiddleware<any, any, any>, config?: C): void;
17
+ disuse(middleware: BoardMiddleware<any, any, any>): void;
18
18
  setData(data: Data, opts?: {
19
19
  modifiedOptions?: ModifyOptions;
20
20
  }): void;
package/dist/esm/index.js CHANGED
@@ -58,8 +58,8 @@ export class Core {
58
58
  __classPrivateFieldGet(this, _Core_board, "f").destroy();
59
59
  __classPrivateFieldGet(this, _Core_canvas, "f").remove();
60
60
  }
61
- use(middleware) {
62
- __classPrivateFieldGet(this, _Core_board, "f").use(middleware);
61
+ use(middleware, config) {
62
+ __classPrivateFieldGet(this, _Core_board, "f").use(middleware, config);
63
63
  }
64
64
  disuse(middleware) {
65
65
  __classPrivateFieldGet(this, _Core_board, "f").disuse(middleware);
@@ -0,0 +1,4 @@
1
+ import type { MiddlewareInfoStyle } from '@idraw/types';
2
+ export declare const infoFontSize = 10;
3
+ export declare const infoLineHeight = 16;
4
+ export declare const defaltStyle: MiddlewareInfoStyle;
@@ -0,0 +1,8 @@
1
+ const infoBackground = '#1973bac6';
2
+ const infoTextColor = '#ffffff';
3
+ export const infoFontSize = 10;
4
+ export const infoLineHeight = 16;
5
+ export const defaltStyle = {
6
+ textBackground: infoBackground,
7
+ textColor: infoTextColor
8
+ };
@@ -1,4 +1,5 @@
1
1
  import type { PointSize, ViewContext2D } from '@idraw/types';
2
+ import type { MiddlewareInfoStyle } from './types';
2
3
  export declare function drawSizeInfoText(ctx: ViewContext2D, opts: {
3
4
  point: PointSize;
4
5
  rotateCenter: PointSize;
@@ -6,8 +7,7 @@ export declare function drawSizeInfoText(ctx: ViewContext2D, opts: {
6
7
  text: string;
7
8
  fontSize: number;
8
9
  lineHeight: number;
9
- color: string;
10
- background: string;
10
+ style: MiddlewareInfoStyle;
11
11
  }): void;
12
12
  export declare function drawPositionInfoText(ctx: ViewContext2D, opts: {
13
13
  point: PointSize;
@@ -16,8 +16,7 @@ export declare function drawPositionInfoText(ctx: ViewContext2D, opts: {
16
16
  text: string;
17
17
  fontSize: number;
18
18
  lineHeight: number;
19
- color: string;
20
- background: string;
19
+ style: MiddlewareInfoStyle;
21
20
  }): void;
22
21
  export declare function drawAngleInfoText(ctx: ViewContext2D, opts: {
23
22
  point: PointSize;
@@ -26,6 +25,5 @@ export declare function drawAngleInfoText(ctx: ViewContext2D, opts: {
26
25
  text: string;
27
26
  fontSize: number;
28
27
  lineHeight: number;
29
- color: string;
30
- background: string;
28
+ style: MiddlewareInfoStyle;
31
29
  }): void;
@@ -1,7 +1,8 @@
1
1
  import { rotateByCenter } from '@idraw/util';
2
2
  const fontFamily = 'monospace';
3
3
  export function drawSizeInfoText(ctx, opts) {
4
- const { point, rotateCenter, angle, text, color, background, fontSize, lineHeight } = opts;
4
+ const { point, rotateCenter, angle, text, style, fontSize, lineHeight } = opts;
5
+ const { textColor, textBackground } = style;
5
6
  rotateByCenter(ctx, angle, rotateCenter, () => {
6
7
  ctx.$setFont({
7
8
  fontWeight: '300',
@@ -23,7 +24,7 @@ export function drawSizeInfoText(ctx, opts) {
23
24
  y: point.y
24
25
  };
25
26
  ctx.setLineDash([]);
26
- ctx.fillStyle = background;
27
+ ctx.fillStyle = textBackground;
27
28
  ctx.beginPath();
28
29
  ctx.moveTo(bgStart.x, bgStart.y);
29
30
  ctx.lineTo(bgEnd.x, bgStart.y);
@@ -31,13 +32,14 @@ export function drawSizeInfoText(ctx, opts) {
31
32
  ctx.lineTo(bgStart.x, bgEnd.y);
32
33
  ctx.closePath();
33
34
  ctx.fill();
34
- ctx.fillStyle = color;
35
+ ctx.fillStyle = textColor;
35
36
  ctx.textBaseline = 'top';
36
37
  ctx.fillText(text, textStart.x, textStart.y + padding);
37
38
  });
38
39
  }
39
40
  export function drawPositionInfoText(ctx, opts) {
40
- const { point, rotateCenter, angle, text, color, background, fontSize, lineHeight } = opts;
41
+ const { point, rotateCenter, angle, text, style, fontSize, lineHeight } = opts;
42
+ const { textBackground, textColor } = style;
41
43
  rotateByCenter(ctx, angle, rotateCenter, () => {
42
44
  ctx.$setFont({
43
45
  fontWeight: '300',
@@ -59,7 +61,7 @@ export function drawPositionInfoText(ctx, opts) {
59
61
  y: point.y
60
62
  };
61
63
  ctx.setLineDash([]);
62
- ctx.fillStyle = background;
64
+ ctx.fillStyle = textBackground;
63
65
  ctx.beginPath();
64
66
  ctx.moveTo(bgStart.x, bgStart.y);
65
67
  ctx.lineTo(bgEnd.x, bgStart.y);
@@ -67,13 +69,14 @@ export function drawPositionInfoText(ctx, opts) {
67
69
  ctx.lineTo(bgStart.x, bgEnd.y);
68
70
  ctx.closePath();
69
71
  ctx.fill();
70
- ctx.fillStyle = color;
72
+ ctx.fillStyle = textColor;
71
73
  ctx.textBaseline = 'top';
72
74
  ctx.fillText(text, textStart.x, textStart.y + padding);
73
75
  });
74
76
  }
75
77
  export function drawAngleInfoText(ctx, opts) {
76
- const { point, rotateCenter, angle, text, color, background, fontSize, lineHeight } = opts;
78
+ const { point, rotateCenter, angle, text, style, fontSize, lineHeight } = opts;
79
+ const { textBackground, textColor } = style;
77
80
  rotateByCenter(ctx, angle, rotateCenter, () => {
78
81
  ctx.$setFont({
79
82
  fontWeight: '300',
@@ -95,7 +98,7 @@ export function drawAngleInfoText(ctx, opts) {
95
98
  y: point.y
96
99
  };
97
100
  ctx.setLineDash([]);
98
- ctx.fillStyle = background;
101
+ ctx.fillStyle = textBackground;
99
102
  ctx.beginPath();
100
103
  ctx.moveTo(bgStart.x, bgStart.y);
101
104
  ctx.lineTo(bgEnd.x, bgStart.y);
@@ -103,7 +106,7 @@ export function drawAngleInfoText(ctx, opts) {
103
106
  ctx.lineTo(bgStart.x, bgEnd.y);
104
107
  ctx.closePath();
105
108
  ctx.fill();
106
- ctx.fillStyle = color;
109
+ ctx.fillStyle = textColor;
107
110
  ctx.textBaseline = 'top';
108
111
  ctx.fillText(text, textStart.x, textStart.y + padding);
109
112
  });
@@ -1,3 +1,3 @@
1
- import type { BoardMiddleware } from '@idraw/types';
1
+ import type { BoardMiddleware, MiddlewareInfoConfig } from '@idraw/types';
2
2
  import type { DeepInfoSharedStorage } from './types';
3
- export declare const MiddlewareInfo: BoardMiddleware<DeepInfoSharedStorage>;
3
+ export declare const MiddlewareInfo: BoardMiddleware<DeepInfoSharedStorage, any, MiddlewareInfoConfig>;
@@ -1,13 +1,18 @@
1
1
  import { formatNumber, getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot, createUUID, limitAngle, rotatePoint, parseAngleToRadian } from '@idraw/util';
2
2
  import { keySelectedElementList, keyActionType, keyGroupQueue } from '../selector';
3
3
  import { drawSizeInfoText, drawPositionInfoText, drawAngleInfoText } from './draw-info';
4
- const infoBackground = '#1973bac6';
5
- const infoTextColor = '#ffffff';
4
+ import { defaltStyle } from './config';
6
5
  const infoFontSize = 10;
7
6
  const infoLineHeight = 16;
8
- export const MiddlewareInfo = (opts) => {
7
+ export const MiddlewareInfo = (opts, config) => {
9
8
  const { boardContent, calculator } = opts;
10
9
  const { overlayContext } = boardContent;
10
+ const innerConfig = Object.assign(Object.assign({}, defaltStyle), config);
11
+ const { textBackground, textColor } = innerConfig;
12
+ const style = {
13
+ textBackground,
14
+ textColor
15
+ };
11
16
  return {
12
17
  name: '@middleware/info',
13
18
  beforeDrawFrame({ snapshot }) {
@@ -73,8 +78,7 @@ export const MiddlewareInfo = (opts) => {
73
78
  text: whText,
74
79
  fontSize: infoFontSize,
75
80
  lineHeight: infoLineHeight,
76
- color: infoTextColor,
77
- background: infoBackground
81
+ style
78
82
  });
79
83
  drawPositionInfoText(overlayContext, {
80
84
  point: {
@@ -86,8 +90,7 @@ export const MiddlewareInfo = (opts) => {
86
90
  text: xyText,
87
91
  fontSize: infoFontSize,
88
92
  lineHeight: infoLineHeight,
89
- color: infoTextColor,
90
- background: infoBackground
93
+ style
91
94
  });
92
95
  drawAngleInfoText(overlayContext, {
93
96
  point: {
@@ -99,8 +102,7 @@ export const MiddlewareInfo = (opts) => {
99
102
  text: angleText,
100
103
  fontSize: infoFontSize,
101
104
  lineHeight: infoLineHeight,
102
- color: infoTextColor,
103
- background: infoBackground
105
+ style
104
106
  });
105
107
  }
106
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,4 +1,4 @@
1
- import type { BoardMiddleware, CoreEventMap } from '@idraw/types';
1
+ import type { BoardMiddleware, CoreEventMap, MiddlewareRulerConfig } from '@idraw/types';
2
2
  import type { DeepRulerSharedStorage } from './types';
3
3
  export declare const middlewareEventRuler = "@middleware/show-ruler";
4
- export declare const MiddlewareRuler: BoardMiddleware<DeepRulerSharedStorage, CoreEventMap>;
4
+ export declare const MiddlewareRuler: BoardMiddleware<DeepRulerSharedStorage, CoreEventMap, MiddlewareRulerConfig>;
@@ -1,9 +1,21 @@
1
1
  import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
2
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
+ export const MiddlewareRuler = (opts, config) => {
5
6
  const { boardContent, viewer, eventHub, calculator } = opts;
6
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) => {
@@ -29,19 +41,20 @@ export const MiddlewareRuler = (opts) => {
29
41
  if (show === true) {
30
42
  const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
31
43
  const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
32
- drawScrollerSelectedArea(overlayContext, { snapshot, calculator });
33
- drawRulerBackground(overlayContext, { viewScaleInfo, viewSizeInfo });
44
+ drawScrollerSelectedArea(overlayContext, { snapshot, calculator, style });
45
+ drawRulerBackground(overlayContext, { viewScaleInfo, viewSizeInfo, style });
34
46
  const { list: xList, rulerUnit } = calcXRulerScaleList({ viewScaleInfo, viewSizeInfo });
35
- drawXRuler(overlayContext, { scaleList: xList });
47
+ drawXRuler(overlayContext, { scaleList: xList, style });
36
48
  const { list: yList } = calcYRulerScaleList({ viewScaleInfo, viewSizeInfo });
37
- drawYRuler(overlayContext, { scaleList: yList });
49
+ drawYRuler(overlayContext, { scaleList: yList, style });
38
50
  if (showGrid === true) {
39
51
  const ctx = rulerUnit === 1 ? overlayContext : underlayContext;
40
52
  drawGrid(ctx, {
41
53
  xList,
42
54
  yList,
43
55
  viewScaleInfo,
44
- viewSizeInfo
56
+ viewSizeInfo,
57
+ style
45
58
  });
46
59
  }
47
60
  }
@@ -1,5 +1,5 @@
1
1
  import type { ViewScaleInfo, ViewSizeInfo, ViewContext2D, BoardViewerFrameSnapshot, ViewCalculator } from '@idraw/types';
2
- import type { DeepRulerSharedStorage } from './types';
2
+ import type { DeepRulerSharedStorage, MiddlewareRulerStyle } from './types';
3
3
  interface RulerScale {
4
4
  num: number;
5
5
  showNum: boolean;
@@ -23,22 +23,27 @@ export declare function calcYRulerScaleList(opts: {
23
23
  };
24
24
  export declare function drawXRuler(ctx: ViewContext2D, opts: {
25
25
  scaleList: RulerScale[];
26
+ style: MiddlewareRulerStyle;
26
27
  }): void;
27
28
  export declare function drawYRuler(ctx: ViewContext2D, opts: {
28
29
  scaleList: RulerScale[];
30
+ style: MiddlewareRulerStyle;
29
31
  }): void;
30
32
  export declare function drawRulerBackground(ctx: ViewContext2D, opts: {
31
33
  viewScaleInfo: ViewScaleInfo;
32
34
  viewSizeInfo: ViewSizeInfo;
35
+ style: MiddlewareRulerStyle;
33
36
  }): void;
34
37
  export declare function drawGrid(ctx: ViewContext2D, opts: {
35
38
  xList: RulerScale[];
36
39
  yList: RulerScale[];
37
40
  viewScaleInfo: ViewScaleInfo;
38
41
  viewSizeInfo: ViewSizeInfo;
42
+ style: MiddlewareRulerStyle;
39
43
  }): void;
40
44
  export declare function drawScrollerSelectedArea(ctx: ViewContext2D, opts: {
41
45
  snapshot: BoardViewerFrameSnapshot<DeepRulerSharedStorage>;
42
46
  calculator: ViewCalculator;
47
+ style: MiddlewareRulerStyle;
43
48
  }): void;
44
49
  export {};
@@ -1,17 +1,6 @@
1
1
  import { formatNumber, rotateByCenter, getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
2
2
  import { keySelectedElementList, keyActionType } from '../selector';
3
- const rulerSize = 16;
4
- const background = '#FFFFFFA8';
5
- const borderColor = '#00000080';
6
- const scaleColor = '#000000';
7
- const textColor = '#00000080';
8
- const fontFamily = 'monospace';
9
- const fontSize = 10;
10
- const fontWeight = 100;
11
- const gridColor = '#AAAAAA20';
12
- const gridKeyColor = '#AAAAAA40';
13
- const lineSize = 1;
14
- const selectedAreaColor = '#196097';
3
+ import { rulerSize, fontSize, fontWeight, lineSize, fontFamily } from './config';
15
4
  const limitRulerUnitList = [1, 2, 5, 10, 20, 50, 100, 200, 500];
16
5
  function limitRulerUnit(unit) {
17
6
  unit = Math.max(limitRulerUnitList[0], Math.min(unit, limitRulerUnitList[limitRulerUnitList.length - 1]));
@@ -88,7 +77,8 @@ export function calcYRulerScaleList(opts) {
88
77
  });
89
78
  }
90
79
  export function drawXRuler(ctx, opts) {
91
- const { scaleList } = opts;
80
+ const { scaleList, style } = opts;
81
+ const { scaleColor, textColor } = style;
92
82
  const scaleDrawStart = rulerSize;
93
83
  const scaleDrawEnd = (rulerSize * 4) / 5;
94
84
  const subKeyScaleDrawEnd = (rulerSize * 2) / 5;
@@ -120,7 +110,8 @@ export function drawXRuler(ctx, opts) {
120
110
  }
121
111
  }
122
112
  export function drawYRuler(ctx, opts) {
123
- const { scaleList } = opts;
113
+ const { scaleList, style } = opts;
114
+ const { scaleColor, textColor } = style;
124
115
  const scaleDrawStart = rulerSize;
125
116
  const scaleDrawEnd = (rulerSize * 4) / 5;
126
117
  const subKeyScaleDrawEnd = (rulerSize * 2) / 5;
@@ -157,8 +148,9 @@ export function drawYRuler(ctx, opts) {
157
148
  }
158
149
  }
159
150
  export function drawRulerBackground(ctx, opts) {
160
- const { viewSizeInfo } = opts;
151
+ const { viewSizeInfo, style } = opts;
161
152
  const { width, height } = viewSizeInfo;
153
+ const { background, borderColor } = style;
162
154
  ctx.beginPath();
163
155
  ctx.moveTo(0, 0);
164
156
  ctx.lineTo(width + 1, 0);
@@ -176,15 +168,16 @@ export function drawRulerBackground(ctx, opts) {
176
168
  ctx.stroke();
177
169
  }
178
170
  export function drawGrid(ctx, opts) {
179
- const { xList, yList, viewSizeInfo } = opts;
171
+ const { xList, yList, viewSizeInfo, style } = opts;
180
172
  const { width, height } = viewSizeInfo;
173
+ const { gridColor, gridPrimaryColor } = style;
181
174
  for (let i = 0; i < xList.length; i++) {
182
175
  const item = xList[i];
183
176
  ctx.beginPath();
184
177
  ctx.moveTo(item.position, 0);
185
178
  ctx.lineTo(item.position, height);
186
179
  if (item.isKeyNum === true || item.isSubKeyNum === true) {
187
- ctx.strokeStyle = gridKeyColor;
180
+ ctx.strokeStyle = gridPrimaryColor;
188
181
  }
189
182
  else {
190
183
  ctx.strokeStyle = gridColor;
@@ -200,7 +193,7 @@ export function drawGrid(ctx, opts) {
200
193
  ctx.moveTo(0, item.position);
201
194
  ctx.lineTo(width, item.position);
202
195
  if (item.isKeyNum === true || item.isSubKeyNum === true) {
203
- ctx.strokeStyle = gridKeyColor;
196
+ ctx.strokeStyle = gridPrimaryColor;
204
197
  }
205
198
  else {
206
199
  ctx.strokeStyle = gridColor;
@@ -211,8 +204,9 @@ export function drawGrid(ctx, opts) {
211
204
  }
212
205
  }
213
206
  export function drawScrollerSelectedArea(ctx, opts) {
214
- const { snapshot, calculator } = opts;
207
+ const { snapshot, calculator, style } = opts;
215
208
  const { sharedStore } = snapshot;
209
+ const { selectedAreaColor } = style;
216
210
  const selectedElementList = sharedStore[keySelectedElementList];
217
211
  const actionType = sharedStore[keyActionType];
218
212
  if (['select', 'drag', 'drag-list', 'drag-list-end'].includes(actionType) && selectedElementList.length > 0) {
@@ -1,3 +1,4 @@
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;
@@ -6,3 +7,4 @@ export declare const keyHoverYThumbRect: unique symbol;
6
7
  export declare const keyPrevPoint: unique symbol;
7
8
  export declare const keyActivePoint: unique symbol;
8
9
  export declare const keyActiveThumbType: unique symbol;
10
+ export declare const defaultStyle: MiddlewareScrollerStyle;
@@ -6,3 +6,11 @@ export const keyHoverYThumbRect = Symbol(`${key}_hoverYThumbRect`);
6
6
  export const keyPrevPoint = Symbol(`${key}_prevPoint`);
7
7
  export const keyActivePoint = Symbol(`${key}_activePoint`);
8
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,3 +1,3 @@
1
- import type { BoardMiddleware } from '@idraw/types';
1
+ import type { BoardMiddleware, MiddlewareScrollerConfig } from '@idraw/types';
2
2
  import type { DeepScrollerSharedStorage } from './types';
3
- export declare const MiddlewareScroller: BoardMiddleware<DeepScrollerSharedStorage>;
3
+ export declare const MiddlewareScroller: BoardMiddleware<DeepScrollerSharedStorage, any, MiddlewareScrollerConfig>;
@@ -1,11 +1,21 @@
1
1
  import { drawScroller, isPointInScrollThumb } from './util';
2
- import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
3
- export const MiddlewareScroller = (opts) => {
2
+ import { keyXThumbRect, keyYThumbRect, keyPrevPoint, keyActivePoint, keyActiveThumbType, keyHoverXThumbRect, keyHoverYThumbRect, defaultStyle } from './config';
3
+ export const MiddlewareScroller = (opts, config) => {
4
4
  const { viewer, boardContent, sharer, eventHub } = opts;
5
5
  const { overlayContext } = boardContent;
6
6
  sharer.setSharedStorage(keyXThumbRect, null);
7
7
  sharer.setSharedStorage(keyYThumbRect, null);
8
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
+ };
9
19
  const clear = () => {
10
20
  sharer.setSharedStorage(keyPrevPoint, null);
11
21
  sharer.setSharedStorage(keyActivePoint, null);
@@ -111,7 +121,7 @@ export const MiddlewareScroller = (opts) => {
111
121
  }
112
122
  },
113
123
  beforeDrawFrame({ snapshot }) {
114
- const { xThumbRect, yThumbRect } = drawScroller(overlayContext, { snapshot });
124
+ const { xThumbRect, yThumbRect } = drawScroller(overlayContext, { snapshot, style });
115
125
  sharer.setSharedStorage(keyXThumbRect, xThumbRect);
116
126
  sharer.setSharedStorage(keyYThumbRect, yThumbRect);
117
127
  }
@@ -1,4 +1,4 @@
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
3
  export declare function isPointInScrollThumb(overlayContext: ViewContext2D, p: Point, opts: {
4
4
  xThumbRect?: ElementSize | null;
@@ -6,6 +6,7 @@ export declare function isPointInScrollThumb(overlayContext: ViewContext2D, p: P
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,15 +1,7 @@
1
1
  import { getViewScaleInfoFromSnapshot, getViewSizeInfoFromSnapshot } from '@idraw/util';
2
2
  import { keyActivePoint, keyActiveThumbType, keyPrevPoint, keyXThumbRect, keyYThumbRect, keyHoverXThumbRect, keyHoverYThumbRect } from './config';
3
- const minScrollerWidth = 12;
4
3
  const scrollerLineWidth = 16;
5
- const scrollerThumbAlpha = 0.3;
6
- const scrollConfig = {
7
- width: minScrollerWidth,
8
- thumbColor: '#0000008A',
9
- thumbHoverColor: '#000000EE',
10
- scrollBarColor: '#FFFFFF60',
11
- showScrollBar: false
12
- };
4
+ const minThumbLength = scrollerLineWidth * 2.5;
13
5
  function isPointAtRect(overlayContext, p, rect) {
14
6
  const ctx = overlayContext;
15
7
  const { x, y, w, h } = rect;
@@ -46,11 +38,12 @@ function getScrollInfoFromSnapshot(snapshot) {
46
38
  return info;
47
39
  }
48
40
  function calcScrollerInfo(opts) {
49
- const { viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb } = opts;
41
+ const { viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb, style } = opts;
50
42
  const { width, height } = viewSizeInfo;
51
43
  const { offsetTop, offsetBottom, offsetLeft, offsetRight } = viewScaleInfo;
52
- const sliderMinSize = scrollerLineWidth * 2.5;
44
+ const sliderMinSize = minThumbLength;
53
45
  const lineSize = scrollerLineWidth;
46
+ const { thumbBackground, thumbBorderColor, hoverThumbBackground, hoverThumbBorderColor } = style;
54
47
  let xSize = 0;
55
48
  let ySize = 0;
56
49
  xSize = Math.max(sliderMinSize, width - lineSize * 2 - (Math.abs(offsetLeft) + Math.abs(offsetRight)));
@@ -105,23 +98,24 @@ function calcScrollerInfo(opts) {
105
98
  ySize,
106
99
  translateY,
107
100
  translateX,
108
- xThumbColor: hoverXThumb ? scrollConfig.thumbHoverColor : scrollConfig.thumbColor,
109
- yThumbColor: hoverYThumb ? scrollConfig.thumbHoverColor : scrollConfig.thumbColor,
110
- scrollBarColor: scrollConfig.scrollBarColor,
101
+ xThumbBackground: hoverXThumb ? hoverThumbBackground : thumbBackground,
102
+ yThumbBackground: hoverYThumb ? hoverThumbBackground : thumbBackground,
103
+ xThumbBorderColor: hoverXThumb ? hoverThumbBorderColor : thumbBorderColor,
104
+ yThumbBorderColor: hoverYThumb ? hoverThumbBorderColor : thumbBorderColor,
111
105
  xThumbRect,
112
106
  yThumbRect
113
107
  };
114
108
  return scrollWrapper;
115
109
  }
116
110
  function drawScrollerThumb(ctx, opts) {
117
- let { x, y, h, w } = opts;
111
+ let { x, y, h, w, background, borderColor } = opts;
118
112
  ctx.save();
119
113
  ctx.shadowColor = '#FFFFFF';
120
114
  ctx.shadowOffsetX = 0;
121
115
  ctx.shadowOffsetY = 0;
122
116
  ctx.shadowBlur = 1;
123
117
  {
124
- const { color, axis } = opts;
118
+ const { axis } = opts;
125
119
  if (axis === 'X') {
126
120
  y = y + h / 4 + 0;
127
121
  h = h / 2;
@@ -135,7 +129,7 @@ function drawScrollerThumb(ctx, opts) {
135
129
  if (w < r * 2 || h < r * 2) {
136
130
  r = 0;
137
131
  }
138
- ctx.globalAlpha = scrollerThumbAlpha;
132
+ ctx.globalAlpha = 1;
139
133
  ctx.beginPath();
140
134
  ctx.moveTo(x + r, y);
141
135
  ctx.arcTo(x + w, y, x + w, y + h, r);
@@ -143,12 +137,11 @@ function drawScrollerThumb(ctx, opts) {
143
137
  ctx.arcTo(x, y + h, x, y, r);
144
138
  ctx.arcTo(x, y, x + w, y, r);
145
139
  ctx.closePath();
146
- ctx.fillStyle = color;
140
+ ctx.fillStyle = background;
147
141
  ctx.fill();
148
- ctx.globalAlpha = 1;
149
142
  ctx.beginPath();
150
143
  ctx.lineWidth = 1;
151
- ctx.strokeStyle = color;
144
+ ctx.strokeStyle = borderColor;
152
145
  ctx.setLineDash([]);
153
146
  ctx.moveTo(x + r, y);
154
147
  ctx.arcTo(x + w, y, x + w, y + h, r);
@@ -162,10 +155,9 @@ function drawScrollerThumb(ctx, opts) {
162
155
  }
163
156
  function drawScrollerInfo(overlayContext, opts) {
164
157
  const ctx = overlayContext;
165
- const { viewScaleInfo, viewSizeInfo, scrollInfo } = opts;
158
+ const { viewScaleInfo, viewSizeInfo, scrollInfo, style } = opts;
166
159
  const { activeThumbType, prevPoint, activePoint, hoverXThumb, hoverYThumb } = scrollInfo;
167
- const { width, height } = viewSizeInfo;
168
- const wrapper = calcScrollerInfo({ viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb });
160
+ const wrapper = calcScrollerInfo({ viewScaleInfo, viewSizeInfo, hoverXThumb, hoverYThumb, style });
169
161
  let xThumbRect = Object.assign({}, wrapper.xThumbRect);
170
162
  let yThumbRect = Object.assign({}, wrapper.yThumbRect);
171
163
  if (activeThumbType && prevPoint && activePoint) {
@@ -178,27 +170,18 @@ function drawScrollerInfo(overlayContext, opts) {
178
170
  yThumbRect.y = yThumbRect.y + (activePoint.y - prevPoint.y);
179
171
  }
180
172
  }
181
- if (scrollConfig.showScrollBar === true) {
182
- ctx.fillStyle = wrapper.scrollBarColor;
183
- ctx.fillRect(0, height - wrapper.lineSize, width, wrapper.lineSize);
184
- }
185
- drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, color: wrapper.xThumbColor }));
186
- if (scrollConfig.showScrollBar === true) {
187
- ctx.fillStyle = wrapper.scrollBarColor;
188
- ctx.fillRect(width - wrapper.lineSize, 0, wrapper.lineSize, height);
189
- }
190
- drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, color: wrapper.yThumbColor }));
191
- ctx.globalAlpha = 1;
173
+ drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'X' }, xThumbRect), { r: wrapper.lineSize / 2, background: wrapper.xThumbBackground, borderColor: wrapper.xThumbBorderColor }));
174
+ drawScrollerThumb(ctx, Object.assign(Object.assign({ axis: 'Y' }, yThumbRect), { r: wrapper.lineSize / 2, background: wrapper.yThumbBackground, borderColor: wrapper.yThumbBorderColor }));
192
175
  return {
193
176
  xThumbRect,
194
177
  yThumbRect
195
178
  };
196
179
  }
197
180
  export function drawScroller(ctx, opts) {
198
- const { snapshot } = opts;
181
+ const { snapshot, style } = opts;
199
182
  const viewSizeInfo = getViewSizeInfoFromSnapshot(snapshot);
200
183
  const viewScaleInfo = getViewScaleInfoFromSnapshot(snapshot);
201
184
  const scrollInfo = getScrollInfoFromSnapshot(snapshot);
202
- const { xThumbRect, yThumbRect } = drawScrollerInfo(ctx, { viewSizeInfo, viewScaleInfo, scrollInfo });
185
+ const { xThumbRect, yThumbRect } = drawScrollerInfo(ctx, { viewSizeInfo, viewScaleInfo, scrollInfo, style });
203
186
  return { xThumbRect, yThumbRect };
204
187
  }
@@ -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;
@@ -23,11 +24,8 @@ export declare const keyDebugEnd0: unique symbol;
23
24
  export declare const selectWrapperBorderWidth = 2;
24
25
  export declare const resizeControllerBorderWidth = 4;
25
26
  export declare const areaBorderWidth = 1;
26
- export declare const wrapperColor = "#1973ba";
27
- export declare const lockColor = "#5b5959b5";
28
27
  export declare const controllerSize = 10;
29
- export declare const auxiliaryColor = "#f7276e";
30
- export declare const referenceColor = "#f7276e";
28
+ export declare const defaultStyle: MiddlewareSelectorStyle;
31
29
  export declare const middlewareEventSelect: string;
32
30
  export declare const middlewareEventSelectClear: string;
33
31
  export declare const middlewareEventSelectInGroup: string;