@idraw/core 0.4.3 → 1.0.0-alpha.1

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 (149) hide show
  1. package/dist/esm/board/index.d.ts +2 -2
  2. package/dist/esm/board/index.js +23 -12
  3. package/dist/esm/board/sharer.d.ts +3 -3
  4. package/dist/esm/board/sharer.js +10 -10
  5. package/dist/esm/board/viewer.d.ts +3 -3
  6. package/dist/esm/board/viewer.js +14 -14
  7. package/dist/esm/board/watcher.d.ts +3 -3
  8. package/dist/esm/board/watcher.js +68 -43
  9. package/dist/esm/core.d.ts +52 -0
  10. package/dist/esm/core.js +393 -0
  11. package/dist/esm/cursor/cursor-image.d.ts +2 -0
  12. package/dist/esm/cursor/cursor-image.js +2 -0
  13. package/dist/esm/cursor/cursor.js +60 -24
  14. package/dist/esm/index.d.ts +12 -61
  15. package/dist/esm/index.js +11 -389
  16. package/dist/esm/middlewares/common.d.ts +4 -0
  17. package/dist/esm/middlewares/common.js +13 -0
  18. package/dist/esm/middlewares/creator/dom.d.ts +11 -0
  19. package/dist/esm/middlewares/creator/dom.js +52 -0
  20. package/dist/esm/middlewares/creator/index.d.ts +5 -0
  21. package/dist/esm/middlewares/creator/index.js +136 -0
  22. package/dist/esm/middlewares/creator/static.d.ts +14 -0
  23. package/dist/esm/middlewares/creator/static.js +19 -0
  24. package/dist/esm/middlewares/creator/styles.d.ts +4 -0
  25. package/dist/esm/middlewares/creator/styles.js +32 -0
  26. package/dist/esm/middlewares/creator/types.d.ts +7 -0
  27. package/dist/esm/middlewares/creator/types.js +1 -0
  28. package/dist/esm/middlewares/creator/util.d.ts +10 -0
  29. package/dist/esm/middlewares/creator/util.js +52 -0
  30. package/dist/esm/middlewares/dragger/index.js +5 -5
  31. package/dist/esm/middlewares/info/draw-info.d.ts +11 -11
  32. package/dist/esm/middlewares/info/draw-info.js +18 -18
  33. package/dist/esm/middlewares/info/index.d.ts +2 -1
  34. package/dist/esm/middlewares/info/index.js +48 -51
  35. package/dist/esm/middlewares/info/static.d.ts +6 -0
  36. package/dist/esm/middlewares/info/{config.js → static.js} +6 -1
  37. package/dist/esm/middlewares/info/types.d.ts +2 -2
  38. package/dist/esm/middlewares/layout-selector/dom.d.ts +10 -0
  39. package/dist/esm/middlewares/layout-selector/dom.js +108 -0
  40. package/dist/esm/middlewares/layout-selector/index.d.ts +1 -1
  41. package/dist/esm/middlewares/layout-selector/index.js +89 -141
  42. package/dist/esm/middlewares/layout-selector/static.d.ts +32 -0
  43. package/dist/esm/middlewares/layout-selector/static.js +39 -0
  44. package/dist/esm/middlewares/layout-selector/styles.d.ts +4 -0
  45. package/dist/esm/middlewares/layout-selector/styles.js +127 -0
  46. package/dist/esm/middlewares/layout-selector/types.d.ts +6 -6
  47. package/dist/esm/middlewares/layout-selector/types.js +2 -2
  48. package/dist/esm/middlewares/layout-selector/util.d.ts +4 -4
  49. package/dist/esm/middlewares/layout-selector/util.js +19 -19
  50. package/dist/esm/middlewares/path-creator/dom.d.ts +29 -0
  51. package/dist/esm/middlewares/path-creator/dom.js +145 -0
  52. package/dist/esm/middlewares/path-creator/index.d.ts +5 -0
  53. package/dist/esm/middlewares/path-creator/index.js +203 -0
  54. package/dist/esm/middlewares/path-creator/static.d.ts +23 -0
  55. package/dist/esm/middlewares/path-creator/static.js +49 -0
  56. package/dist/esm/middlewares/path-creator/types.d.ts +1 -0
  57. package/dist/esm/middlewares/path-editor/calc.d.ts +6 -0
  58. package/dist/esm/middlewares/path-editor/calc.js +51 -0
  59. package/dist/esm/middlewares/path-editor/dom.d.ts +32 -0
  60. package/dist/esm/middlewares/path-editor/dom.js +575 -0
  61. package/dist/esm/middlewares/path-editor/draw.d.ts +7 -0
  62. package/dist/esm/middlewares/path-editor/draw.js +113 -0
  63. package/dist/esm/middlewares/path-editor/index.d.ts +5 -0
  64. package/dist/esm/middlewares/path-editor/index.js +312 -0
  65. package/dist/esm/middlewares/path-editor/parse.d.ts +5 -0
  66. package/dist/esm/middlewares/path-editor/parse.js +37 -0
  67. package/dist/esm/middlewares/path-editor/static.d.ts +34 -0
  68. package/dist/esm/middlewares/path-editor/static.js +82 -0
  69. package/dist/esm/middlewares/path-editor/types.d.ts +26 -0
  70. package/dist/esm/middlewares/path-editor/types.js +1 -0
  71. package/dist/esm/middlewares/path-editor/util.d.ts +5 -0
  72. package/dist/esm/middlewares/path-editor/util.js +21 -0
  73. package/dist/esm/middlewares/pointer/index.js +5 -5
  74. package/dist/esm/middlewares/pointer/types.d.ts +2 -2
  75. package/dist/esm/middlewares/ruler/index.d.ts +2 -0
  76. package/dist/esm/middlewares/ruler/index.js +12 -19
  77. package/dist/esm/middlewares/ruler/static.d.ts +8 -0
  78. package/dist/esm/middlewares/ruler/{config.js → static.js} +16 -3
  79. package/dist/esm/middlewares/ruler/types.d.ts +2 -2
  80. package/dist/esm/middlewares/ruler/util.d.ts +6 -6
  81. package/dist/esm/middlewares/ruler/util.js +31 -31
  82. package/dist/esm/middlewares/scaler/index.js +2 -2
  83. package/dist/esm/middlewares/scroller/dom.d.ts +14 -0
  84. package/dist/esm/middlewares/scroller/dom.js +53 -0
  85. package/dist/esm/middlewares/scroller/index.d.ts +2 -0
  86. package/dist/esm/middlewares/scroller/index.js +111 -46
  87. package/dist/esm/middlewares/scroller/static.d.ts +21 -0
  88. package/dist/esm/middlewares/scroller/static.js +29 -0
  89. package/dist/esm/middlewares/scroller/styles.d.ts +4 -0
  90. package/dist/esm/middlewares/scroller/styles.js +73 -0
  91. package/dist/esm/middlewares/scroller/types.d.ts +8 -6
  92. package/dist/esm/middlewares/scroller/types.js +1 -1
  93. package/dist/esm/middlewares/scroller/util.d.ts +6 -13
  94. package/dist/esm/middlewares/scroller/util.js +15 -144
  95. package/dist/esm/middlewares/selector/dom.d.ts +21 -0
  96. package/dist/esm/middlewares/selector/dom.js +395 -0
  97. package/dist/esm/middlewares/selector/draw-base.d.ts +9 -21
  98. package/dist/esm/middlewares/selector/draw-base.js +19 -43
  99. package/dist/esm/middlewares/selector/draw-reference.d.ts +4 -5
  100. package/dist/esm/middlewares/selector/draw-reference.js +5 -5
  101. package/dist/esm/middlewares/selector/index.d.ts +4 -2
  102. package/dist/esm/middlewares/selector/index.js +315 -439
  103. package/dist/esm/middlewares/selector/reference.d.ts +5 -5
  104. package/dist/esm/middlewares/selector/reference.js +36 -30
  105. package/dist/esm/middlewares/selector/render-frame.d.ts +11 -0
  106. package/dist/esm/middlewares/selector/render-frame.js +107 -0
  107. package/dist/esm/middlewares/selector/resize.d.ts +7 -0
  108. package/dist/esm/middlewares/selector/resize.js +27 -0
  109. package/dist/esm/middlewares/selector/static.d.ts +67 -0
  110. package/dist/esm/middlewares/selector/static.js +92 -0
  111. package/dist/esm/middlewares/selector/styles.d.ts +4 -0
  112. package/dist/esm/middlewares/selector/styles.js +153 -0
  113. package/dist/esm/middlewares/selector/types.d.ts +27 -27
  114. package/dist/esm/middlewares/selector/types.js +1 -1
  115. package/dist/esm/middlewares/selector/util.d.ts +22 -32
  116. package/dist/esm/middlewares/selector/util.js +226 -243
  117. package/dist/esm/middlewares/text-editor/dom.d.ts +5 -0
  118. package/dist/esm/middlewares/text-editor/dom.js +135 -0
  119. package/dist/esm/middlewares/text-editor/index.d.ts +5 -20
  120. package/dist/esm/middlewares/text-editor/index.js +201 -208
  121. package/dist/esm/middlewares/text-editor/static.d.ts +10 -0
  122. package/dist/esm/middlewares/text-editor/static.js +17 -0
  123. package/dist/esm/middlewares/text-editor/types.d.ts +21 -0
  124. package/dist/esm/middlewares/text-editor/types.js +1 -0
  125. package/dist/esm/record.d.ts +5 -5
  126. package/dist/esm/record.js +14 -14
  127. package/dist/esm/{config.d.ts → static.d.ts} +16 -0
  128. package/dist/esm/{config.js → static.js} +18 -2
  129. package/dist/index.global.js +8934 -5647
  130. package/dist/index.global.min.js +1 -1
  131. package/package.json +4 -4
  132. package/dist/esm/middlewares/info/config.d.ts +0 -5
  133. package/dist/esm/middlewares/layout-selector/config.d.ts +0 -11
  134. package/dist/esm/middlewares/layout-selector/config.js +0 -12
  135. package/dist/esm/middlewares/ruler/config.d.ts +0 -7
  136. package/dist/esm/middlewares/scroller/config.d.ts +0 -10
  137. package/dist/esm/middlewares/scroller/config.js +0 -16
  138. package/dist/esm/middlewares/selector/config.d.ts +0 -30
  139. package/dist/esm/middlewares/selector/config.js +0 -38
  140. package/dist/esm/middlewares/selector/draw-auxiliary.js +0 -12
  141. package/dist/esm/middlewares/selector/draw-debug.d.ts +0 -5
  142. package/dist/esm/middlewares/selector/draw-debug.js +0 -30
  143. package/dist/esm/middlewares/selector/draw-wrapper.d.ts +0 -37
  144. package/dist/esm/middlewares/selector/draw-wrapper.js +0 -139
  145. package/dist/esm/middlewares/selector/pattern/icon-rotate.d.ts +0 -4
  146. package/dist/esm/middlewares/selector/pattern/icon-rotate.js +0 -88
  147. package/dist/esm/middlewares/selector/pattern/index.d.ts +0 -8
  148. package/dist/esm/middlewares/selector/pattern/index.js +0 -38
  149. /package/dist/esm/middlewares/{selector/draw-auxiliary.d.ts → path-creator/types.js} +0 -0
@@ -0,0 +1,127 @@
1
+ import { injectStyles, removeStyles, getMiddlewareValidStyles } from '@idraw/util';
2
+ import { classNameMap, cornerHandlerBorderWidth, cornerHandlerSize, edgeHandlerSize, hoverBoxBorderWidth, selectedBoxBorderWidth, } from './static';
3
+ export function initStyles(rootClassName, styles) {
4
+ const cls = (str) => `.${str}`;
5
+ const stylesProps = {
6
+ zIndex: styles.zIndex,
7
+ position: 'absolute',
8
+ background: 'transparent',
9
+ [`&${cls(classNameMap.hover)}`]: {
10
+ [`&${cls(classNameMap.cornerHandler)}`]: {
11
+ display: 'none',
12
+ },
13
+ [`&${cls(classNameMap.edgeHandler)}`]: {
14
+ width: `${hoverBoxBorderWidth}px`,
15
+ height: `${hoverBoxBorderWidth}px`,
16
+ [`&${cls(classNameMap.edgeLeftHandler)}`]: {
17
+ width: `${hoverBoxBorderWidth}px`,
18
+ },
19
+ [`&${cls(classNameMap.edgeRightHandler)}`]: {
20
+ width: `${hoverBoxBorderWidth}px`,
21
+ },
22
+ [`&${cls(classNameMap.edgeTopHandler)}`]: {
23
+ height: `${hoverBoxBorderWidth}px`,
24
+ },
25
+ [`&${cls(classNameMap.edgeBottomHandler)}`]: {
26
+ height: `${hoverBoxBorderWidth}px`,
27
+ },
28
+ },
29
+ },
30
+ [`&${cls(classNameMap.cornerHandler)}`]: {
31
+ outline: `${cornerHandlerBorderWidth}px solid ${styles.handlerBorderColor}`,
32
+ background: styles.handlerBackground,
33
+ width: `${cornerHandlerSize}px`,
34
+ height: `${cornerHandlerSize}px`,
35
+ top: 'unset',
36
+ bottom: 'unset',
37
+ left: 'unset',
38
+ right: 'unset',
39
+ ['&:hover']: {
40
+ background: styles.handlerHoverBackground,
41
+ },
42
+ ['&:active']: {
43
+ background: styles.handlerActiveBackground,
44
+ },
45
+ [`&${cls(classNameMap.cornerTopLeftHandler)}`]: {
46
+ transform: 'translate(-50%, -50%)',
47
+ },
48
+ [`&${cls(classNameMap.cornerTopRightHandler)}`]: {
49
+ transform: 'translate(-50%, -50%)',
50
+ },
51
+ [`&${cls(classNameMap.cornerBottomLeftHandler)}`]: {
52
+ transform: 'translate(-50%, -50%)',
53
+ },
54
+ [`&${cls(classNameMap.cornerBottomRightHandler)}`]: {
55
+ transform: 'translate(-50%, -50%)',
56
+ },
57
+ },
58
+ [`&${cls(classNameMap.edgeHandler)}`]: {
59
+ width: `${cornerHandlerSize}px`,
60
+ height: `${cornerHandlerSize}px`,
61
+ ['&:after']: {
62
+ position: 'absolute',
63
+ content: '""',
64
+ background: styles.handlerBorderColor,
65
+ },
66
+ [`&${cls(classNameMap.edgeLeftHandler)}`]: {
67
+ width: `${edgeHandlerSize}px`,
68
+ transform: 'translateX(-50%)',
69
+ ['&:after']: {
70
+ top: 0,
71
+ bottom: 0,
72
+ left: '50%',
73
+ right: 'unset',
74
+ width: selectedBoxBorderWidth,
75
+ },
76
+ },
77
+ [`&${cls(classNameMap.edgeRightHandler)}`]: {
78
+ width: `${edgeHandlerSize}px`,
79
+ transform: 'translateX(-50%)',
80
+ ['&:after']: {
81
+ top: 0,
82
+ bottom: 0,
83
+ left: '50%',
84
+ right: 'unset',
85
+ width: selectedBoxBorderWidth,
86
+ },
87
+ },
88
+ [`&${cls(classNameMap.edgeTopHandler)}`]: {
89
+ height: `${edgeHandlerSize}px`,
90
+ transform: 'translateY(-50%)',
91
+ ['&:after']: {
92
+ left: 0,
93
+ right: 0,
94
+ top: '50%',
95
+ bottom: 'unset',
96
+ height: selectedBoxBorderWidth,
97
+ },
98
+ },
99
+ [`&${cls(classNameMap.edgeBottomHandler)}`]: {
100
+ height: `${edgeHandlerSize}px`,
101
+ transform: 'translateY(-50%)',
102
+ ['&:after']: {
103
+ left: 0,
104
+ right: 0,
105
+ top: '50%',
106
+ bottom: 'unset',
107
+ height: selectedBoxBorderWidth,
108
+ },
109
+ },
110
+ },
111
+ };
112
+ injectStyles({ styles: stylesProps, rootClassName, type: 'element' });
113
+ }
114
+ export function destroyStyles(rootClassName) {
115
+ removeStyles({ rootClassName, type: 'element' });
116
+ }
117
+ export function getMiddlewareLayoutSelectorStyles(config) {
118
+ const styles = getMiddlewareValidStyles(config, [
119
+ 'zIndex',
120
+ 'activeColor',
121
+ 'handlerBorderColor',
122
+ 'handlerBackground',
123
+ 'handlerHoverBackground',
124
+ 'handlerActiveBackground',
125
+ ]);
126
+ return styles;
127
+ }
@@ -1,15 +1,15 @@
1
- import type { LayoutSizeController, Element } from '@idraw/types';
2
- import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHoverContent, keyLayoutIsHoverController, keyLayoutIsSelected, keyLayoutIsBusyMoving } from './config';
3
- import { keyActionType as keyElementActionType, keyHoverElement } from '../selector';
4
- import type { ActionType as ElementActionType } from '../selector';
1
+ import type { LayoutSizeController, Material } from '@idraw/types';
2
+ import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHoverContent, keyLayoutIsHoverController, keyLayoutIsSelected, keyLayoutIsBusyMoving } from './static';
3
+ import { keyActionType as keyMaterialActionType, keyHoverMaterial } from '../selector';
4
+ import type { ActionType as MaterialActionType } from '../selector';
5
5
  export type ActionType = 'resize' | null;
6
6
  export type ControlType = 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
7
7
  export type LayoutSelectorSharedStorage = {
8
8
  [keyLayoutActionType]: ActionType | null;
9
9
  [keyLayoutControlType]: ControlType | null;
10
10
  [keyLayoutController]: LayoutSizeController | null;
11
- [keyElementActionType]: ElementActionType | null;
12
- [keyHoverElement]: Element | null;
11
+ [keyMaterialActionType]: MaterialActionType | null;
12
+ [keyHoverMaterial]: Material | null;
13
13
  [keyLayoutIsHoverContent]: boolean | null;
14
14
  [keyLayoutIsHoverController]: boolean | null;
15
15
  [keyLayoutIsSelected]: boolean | null;
@@ -1,2 +1,2 @@
1
- import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHoverContent, keyLayoutIsHoverController, keyLayoutIsSelected, keyLayoutIsBusyMoving } from './config';
2
- import { keyActionType as keyElementActionType, keyHoverElement } from '../selector';
1
+ import { keyLayoutActionType, keyLayoutControlType, keyLayoutController, keyLayoutIsHoverContent, keyLayoutIsHoverController, keyLayoutIsSelected, keyLayoutIsBusyMoving, } from './static';
2
+ import { keyActionType as keyMaterialActionType, keyHoverMaterial } from '../selector';
@@ -1,9 +1,9 @@
1
- import type { ViewContext2D, LayoutSizeController, ElementSize, MiddlewareLayoutSelectorStyle } from '@idraw/types';
1
+ import type { ViewContext2D, LayoutSizeController, MaterialSize, MiddlewareLayoutSelectorStyles } from '@idraw/types';
2
2
  export declare function drawLayoutController(ctx: ViewContext2D, opts: {
3
3
  controller: LayoutSizeController;
4
- style: MiddlewareLayoutSelectorStyle;
4
+ styles: MiddlewareLayoutSelectorStyles;
5
5
  }): void;
6
6
  export declare function drawLayoutHover(ctx: ViewContext2D, opts: {
7
- layoutSize: ElementSize;
8
- style: MiddlewareLayoutSelectorStyle;
7
+ layoutSize: MaterialSize;
8
+ styles: MiddlewareLayoutSelectorStyles;
9
9
  }): void;
@@ -1,5 +1,5 @@
1
- function drawControllerBox(ctx, boxVertexes, style) {
2
- const { activeColor } = style;
1
+ function drawControllerBox(ctx, boxVertexes, styles) {
2
+ const { activeColor } = styles;
3
3
  ctx.setLineDash([]);
4
4
  ctx.fillStyle = '#FFFFFF';
5
5
  ctx.beginPath();
@@ -20,8 +20,8 @@ function drawControllerBox(ctx, boxVertexes, style) {
20
20
  ctx.stroke();
21
21
  }
22
22
  function drawControllerLine(ctx, opts) {
23
- const { start, end, style } = opts;
24
- const { activeColor } = style;
23
+ const { start, end, styles } = opts;
24
+ const { activeColor } = styles;
25
25
  const lineWidth = 2;
26
26
  const strokeStyle = activeColor;
27
27
  ctx.setLineDash([]);
@@ -34,44 +34,44 @@ function drawControllerLine(ctx, opts) {
34
34
  ctx.stroke();
35
35
  }
36
36
  export function drawLayoutController(ctx, opts) {
37
- const { controller, style } = opts;
37
+ const { controller, styles } = opts;
38
38
  const { topLeft, topRight, bottomLeft, bottomRight, topMiddle, rightMiddle, bottomMiddle, leftMiddle } = controller;
39
- drawControllerLine(ctx, { start: topLeft.center, end: topRight.center, centerVertexes: topMiddle.vertexes, style });
39
+ drawControllerLine(ctx, { start: topLeft.center, end: topRight.center, centerVertexes: topMiddle.vertexes, styles });
40
40
  drawControllerLine(ctx, {
41
41
  start: topRight.center,
42
42
  end: bottomRight.center,
43
43
  centerVertexes: rightMiddle.vertexes,
44
- style
44
+ styles,
45
45
  });
46
46
  drawControllerLine(ctx, {
47
47
  start: bottomRight.center,
48
48
  end: bottomLeft.center,
49
49
  centerVertexes: bottomMiddle.vertexes,
50
- style
50
+ styles,
51
51
  });
52
52
  drawControllerLine(ctx, {
53
53
  start: bottomLeft.center,
54
54
  end: topLeft.center,
55
55
  centerVertexes: leftMiddle.vertexes,
56
- style
56
+ styles,
57
57
  });
58
- drawControllerBox(ctx, topLeft.vertexes, style);
59
- drawControllerBox(ctx, topRight.vertexes, style);
60
- drawControllerBox(ctx, bottomRight.vertexes, style);
61
- drawControllerBox(ctx, bottomLeft.vertexes, style);
58
+ drawControllerBox(ctx, topLeft.vertexes, styles);
59
+ drawControllerBox(ctx, topRight.vertexes, styles);
60
+ drawControllerBox(ctx, bottomRight.vertexes, styles);
61
+ drawControllerBox(ctx, bottomLeft.vertexes, styles);
62
62
  }
63
63
  export function drawLayoutHover(ctx, opts) {
64
- const { layoutSize, style } = opts;
65
- const { activeColor } = style;
66
- const { x, y, w, h } = layoutSize;
64
+ const { layoutSize, styles } = opts;
65
+ const { activeColor } = styles;
66
+ const { x, y, width, height } = layoutSize;
67
67
  ctx.setLineDash([]);
68
68
  ctx.strokeStyle = activeColor;
69
69
  ctx.lineWidth = 1;
70
70
  ctx.beginPath();
71
71
  ctx.moveTo(x, y);
72
- ctx.lineTo(x + w, y);
73
- ctx.lineTo(x + w, y + h);
74
- ctx.lineTo(x, y + h);
72
+ ctx.lineTo(x + width, y);
73
+ ctx.lineTo(x + width, y + height);
74
+ ctx.lineTo(x, y + height);
75
75
  ctx.lineTo(x, y);
76
76
  ctx.closePath();
77
77
  ctx.stroke();
@@ -0,0 +1,29 @@
1
+ import type { Point, ViewScaleInfo, MiddlewarePathCreatorStyles } from '@idraw/types';
2
+ export declare function initStyles(rootClassName: string, styles: MiddlewarePathCreatorStyles): void;
3
+ export declare function destroyStyles(rootClassName: string): void;
4
+ export declare function initRoot(container: HTMLElement, opts: {
5
+ id: string;
6
+ rootClassName: string;
7
+ }): HTMLDivElement | undefined;
8
+ export declare function createAnchorElement(opts: {
9
+ id: string;
10
+ index: number;
11
+ point: Point;
12
+ commandType: string;
13
+ viewScaleInfo: ViewScaleInfo;
14
+ styles: MiddlewarePathCreatorStyles;
15
+ }): HTMLElement;
16
+ export declare function appendAnchorElement(root: HTMLElement, opts: {
17
+ point: Point;
18
+ viewScaleInfo: ViewScaleInfo;
19
+ styles: MiddlewarePathCreatorStyles;
20
+ }): {
21
+ id: string;
22
+ };
23
+ export declare function updateAnchorsStyle(root: HTMLDivElement, opts: {
24
+ viewScaleInfo: ViewScaleInfo;
25
+ styles: MiddlewarePathCreatorStyles;
26
+ }): void;
27
+ export declare function isAnchorElement(elem: HTMLElement): boolean;
28
+ export declare function getIndexFromAnchorElement(elem: HTMLElement): number | null;
29
+ export declare function clearRoot(root: HTMLElement | null): void;
@@ -0,0 +1,145 @@
1
+ import { injectStyles, removeStyles, createHTMLElement, setHTMLCSSProps, createId, calcViewPoint, ATTR_VALID_WATCH, } from '@idraw/util';
2
+ import { ATTR_X, ATTR_Y, ATTR_AHCHOR_CMD_TYPE, ATTR_AHCHOR_INDEX, ATTR_AHCHOR_ID, ATTR_HELPER_TYPE, HELPER_ANCHOR, classNameMap, } from './static';
3
+ export function initStyles(rootClassName, styles) {
4
+ const stylesProps = {
5
+ display: 'flex',
6
+ position: 'absolute',
7
+ top: 0,
8
+ left: 0,
9
+ right: 0,
10
+ bottom: 0,
11
+ overflow: 'hidden',
12
+ justifyContent: 'center',
13
+ alignItems: 'center',
14
+ [`.${classNameMap.anchor}`]: {
15
+ position: 'absolute',
16
+ width: styles.anchorSize,
17
+ height: styles.anchorSize,
18
+ background: styles.anchorBackground,
19
+ border: `${styles.anchorBorderWidth}px solid ${styles.anchorBorderColor}`,
20
+ borderRadius: '50%',
21
+ overflow: 'hidden',
22
+ ['&:hover']: {
23
+ borderColor: styles.anchorHoverBorderColor,
24
+ background: styles.anchorHoverBackground,
25
+ },
26
+ ['&:active']: {
27
+ borderColor: styles.anchorActiveBorderColor,
28
+ background: styles.anchorActiveBackground,
29
+ },
30
+ [`&.${classNameMap.selected}`]: {
31
+ borderColor: styles.anchorActiveBorderColor,
32
+ background: styles.anchorActiveBackground,
33
+ },
34
+ },
35
+ };
36
+ injectStyles({
37
+ styles: stylesProps,
38
+ rootClassName,
39
+ type: 'element',
40
+ });
41
+ }
42
+ export function destroyStyles(rootClassName) {
43
+ removeStyles({ rootClassName, type: 'element' });
44
+ }
45
+ export function initRoot(container, opts) {
46
+ const { id, rootClassName } = opts;
47
+ if (!container) {
48
+ return;
49
+ }
50
+ const root = createHTMLElement('div', {
51
+ id,
52
+ className: [classNameMap.hide, rootClassName].join(' '),
53
+ [ATTR_VALID_WATCH]: 'true',
54
+ });
55
+ if (!container.contains(root)) {
56
+ container.appendChild(root);
57
+ }
58
+ return root;
59
+ }
60
+ const getAnchorPosition = (opts) => {
61
+ const { x, y, size, borderWidth } = opts;
62
+ return {
63
+ left: x - size / 2 - borderWidth,
64
+ top: y - size / 2 - borderWidth,
65
+ };
66
+ };
67
+ export function createAnchorElement(opts) {
68
+ const { id, index, point, commandType, viewScaleInfo, styles } = opts;
69
+ const viewPoint = calcViewPoint(point, { viewScaleInfo });
70
+ const $anchor = createHTMLElement('div', {
71
+ [ATTR_HELPER_TYPE]: HELPER_ANCHOR,
72
+ [ATTR_AHCHOR_CMD_TYPE]: commandType,
73
+ [ATTR_AHCHOR_INDEX]: index,
74
+ [ATTR_AHCHOR_ID]: id,
75
+ [ATTR_VALID_WATCH]: 'true',
76
+ [ATTR_X]: point.x,
77
+ [ATTR_Y]: point.y,
78
+ className: classNameMap.anchor,
79
+ style: Object.assign(Object.assign({}, getAnchorPosition({
80
+ x: viewPoint.x,
81
+ y: viewPoint.y,
82
+ size: styles.anchorSize,
83
+ borderWidth: styles.anchorBorderWidth,
84
+ })), { display: 'block' }),
85
+ });
86
+ return $anchor;
87
+ }
88
+ export function appendAnchorElement(root, opts) {
89
+ const { point, viewScaleInfo, styles } = opts;
90
+ const $existedAnchors = Array.from(root.querySelectorAll(`[${ATTR_HELPER_TYPE}="${HELPER_ANCHOR}"]`));
91
+ const index = $existedAnchors.length;
92
+ const id = createId();
93
+ const $anchor = createAnchorElement({
94
+ index,
95
+ id,
96
+ point,
97
+ styles,
98
+ viewScaleInfo,
99
+ commandType: index === 0 ? 'M' : 'C',
100
+ });
101
+ if (index === 0) {
102
+ root.appendChild($anchor);
103
+ }
104
+ else {
105
+ const $lastAnchor = $existedAnchors[$existedAnchors.length - 1];
106
+ $lastAnchor.after($anchor);
107
+ }
108
+ return { id };
109
+ }
110
+ const getAnchorElementInfo = (elem) => {
111
+ const id = elem.getAttribute(ATTR_AHCHOR_ID) || '';
112
+ const type = elem.getAttribute(ATTR_HELPER_TYPE) || '';
113
+ const x = parseFloat(elem.getAttribute(ATTR_X) || '0');
114
+ const y = parseFloat(elem.getAttribute(ATTR_Y) || '0');
115
+ const info = { id, type, x, y };
116
+ return info;
117
+ };
118
+ export function updateAnchorsStyle(root, opts) {
119
+ const { viewScaleInfo, styles } = opts;
120
+ const $anchors = Array.from(root.querySelectorAll(`[${ATTR_HELPER_TYPE}="${HELPER_ANCHOR}"]`));
121
+ $anchors.forEach(($anchor) => {
122
+ const info = getAnchorElementInfo($anchor);
123
+ const viewPoint = calcViewPoint({ x: info.x, y: info.y }, { viewScaleInfo });
124
+ setHTMLCSSProps($anchor, getAnchorPosition(Object.assign(Object.assign({}, viewPoint), { size: styles.anchorSize, borderWidth: styles.anchorBorderWidth })));
125
+ });
126
+ }
127
+ export function isAnchorElement(elem) {
128
+ return elem.getAttribute(ATTR_HELPER_TYPE) === HELPER_ANCHOR;
129
+ }
130
+ export function getIndexFromAnchorElement(elem) {
131
+ const index = elem.getAttribute(ATTR_AHCHOR_INDEX);
132
+ if (typeof index === 'string') {
133
+ return parseInt(index);
134
+ }
135
+ return index;
136
+ }
137
+ export function clearRoot(root) {
138
+ if (!root) {
139
+ return;
140
+ }
141
+ const children = Array.from(root.children);
142
+ children.forEach((child) => {
143
+ child.remove();
144
+ });
145
+ }
@@ -0,0 +1,5 @@
1
+ import type { Middleware, CoreEventMap, MiddlewarePathCreatorConfig } from '@idraw/types';
2
+ import type { PathSharedStorage } from './types';
3
+ import { getMiddlewarePathCreatorStyles } from './static';
4
+ export { getMiddlewarePathCreatorStyles };
5
+ export declare const MiddlewarePathCreator: Middleware<PathSharedStorage, CoreEventMap, MiddlewarePathCreatorConfig>;
@@ -0,0 +1,203 @@
1
+ import { createId, getHTMLElementRectInPage, calcPointFromView, createUUID, convertLineToExactCurveCommand, updateMaterialInList, refinePathMaterial, deepClone, } from '@idraw/util';
2
+ import { coreEventKeys } from '../../static';
3
+ import { initRoot, clearRoot, appendAnchorElement, updateAnchorsStyle, isAnchorElement, getIndexFromAnchorElement, initStyles, destroyStyles, } from './dom';
4
+ import { defaultConfig, getRootClassName, getMiddlewarePathCreatorStyles } from './static';
5
+ import { triggerChangeEvent } from '../common';
6
+ export { getMiddlewarePathCreatorStyles };
7
+ export const MiddlewarePathCreator = (opts, config) => {
8
+ const innerConfig = Object.assign(Object.assign({}, defaultConfig), config);
9
+ const { defaultStrokeWidth, defaultStroke } = innerConfig;
10
+ const styles = getMiddlewarePathCreatorStyles(innerConfig);
11
+ const rootClassName = getRootClassName();
12
+ const { viewer, eventHub, sharer, calculator } = opts;
13
+ const container = opts.container;
14
+ const id = rootClassName;
15
+ let root = null;
16
+ let pathCommandIndex = -1;
17
+ let createdPathMaterial = null;
18
+ let prevPoint = null;
19
+ const clearData = () => {
20
+ clearRoot(root);
21
+ prevPoint = null;
22
+ createdPathMaterial = null;
23
+ pathCommandIndex = -1;
24
+ };
25
+ const refineData = () => {
26
+ if (!createdPathMaterial) {
27
+ return;
28
+ }
29
+ createdPathMaterial = refinePathMaterial(createdPathMaterial);
30
+ const data = sharer.getActiveStorage('data');
31
+ updateMaterialInList(createdPathMaterial.id, {
32
+ x: createdPathMaterial.x,
33
+ y: createdPathMaterial.y,
34
+ width: createdPathMaterial.width,
35
+ height: createdPathMaterial.height,
36
+ commands: createdPathMaterial.commands,
37
+ }, data.materials);
38
+ calculator.modifyVirtualAttributes(createdPathMaterial, {
39
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
40
+ viewSizeInfo: sharer.getActiveViewSizeInfo(),
41
+ groupQueue: [],
42
+ });
43
+ calculator.forceVisiable(createdPathMaterial.id);
44
+ viewer.drawFrame();
45
+ };
46
+ const refreshMaterials = () => {
47
+ var _a;
48
+ if (!createdPathMaterial) {
49
+ return;
50
+ }
51
+ const data = sharer.getActiveStorage('data');
52
+ if (pathCommandIndex > 0) {
53
+ updateMaterialInList(createdPathMaterial.id, {
54
+ x: createdPathMaterial.x,
55
+ y: createdPathMaterial.y,
56
+ width: createdPathMaterial.width,
57
+ height: createdPathMaterial.height,
58
+ commands: createdPathMaterial.commands,
59
+ }, data.materials);
60
+ }
61
+ else {
62
+ data.materials.push(createdPathMaterial);
63
+ const modifyRecord = {
64
+ type: 'addMaterial',
65
+ time: Date.now(),
66
+ content: {
67
+ method: 'addMaterial',
68
+ id: createdPathMaterial.id,
69
+ position: [(_a = data.materials) === null || _a === void 0 ? void 0 : _a.length],
70
+ material: deepClone(createdPathMaterial),
71
+ },
72
+ };
73
+ triggerChangeEvent(eventHub, { data, type: 'addMaterial', modifyRecord });
74
+ }
75
+ calculator.modifyVirtualAttributes(createdPathMaterial, {
76
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
77
+ viewSizeInfo: sharer.getActiveViewSizeInfo(),
78
+ groupQueue: [],
79
+ });
80
+ calculator.forceVisiable(createdPathMaterial.id);
81
+ viewer.drawFrame();
82
+ };
83
+ const mouseDownEvent = (e) => {
84
+ const $target = e.target;
85
+ if (isAnchorElement($target)) {
86
+ const index = getIndexFromAnchorElement($target);
87
+ if (index === 0 && pathCommandIndex > 1 && createdPathMaterial) {
88
+ createdPathMaterial.commands.push({
89
+ id: createId(),
90
+ type: 'Z',
91
+ params: [],
92
+ });
93
+ refineData();
94
+ clearData();
95
+ }
96
+ return;
97
+ }
98
+ const rootRect = getHTMLElementRectInPage(root);
99
+ const viewPoint = {
100
+ x: e.pageX - rootRect.pageX,
101
+ y: e.pageY - rootRect.pageY,
102
+ };
103
+ const viewScaleInfo = sharer.getActiveViewScaleInfo();
104
+ const viewSizeInfo = sharer.getActiveViewSizeInfo();
105
+ const point = calcPointFromView(viewPoint, {
106
+ viewScaleInfo,
107
+ });
108
+ const { id } = appendAnchorElement(root, { point, viewScaleInfo, styles });
109
+ if (pathCommandIndex < 0 || !createdPathMaterial) {
110
+ pathCommandIndex = 0;
111
+ createdPathMaterial = {
112
+ id: createUUID(),
113
+ type: 'path',
114
+ x: 0,
115
+ y: 0,
116
+ width: viewSizeInfo.width,
117
+ height: viewSizeInfo.height,
118
+ strokeWidth: defaultStrokeWidth,
119
+ stroke: defaultStroke,
120
+ commands: [{ id, type: 'M', params: [point.x, point.y] }],
121
+ };
122
+ }
123
+ else {
124
+ pathCommandIndex++;
125
+ createdPathMaterial.commands.push(Object.assign(Object.assign({}, convertLineToExactCurveCommand(prevPoint, point)), { id }));
126
+ }
127
+ prevPoint = point;
128
+ refreshMaterials();
129
+ };
130
+ const mouseMoveEvent = () => {
131
+ };
132
+ const mouseUpEvent = () => {
133
+ window.removeEventListener('mousemove', mouseMoveEvent);
134
+ };
135
+ const mouseLeaveEvent = () => {
136
+ window.removeEventListener('mousemove', mouseMoveEvent);
137
+ };
138
+ const onEvents = () => {
139
+ root === null || root === void 0 ? void 0 : root.addEventListener('mousedown', mouseDownEvent);
140
+ window.addEventListener('mouseup', mouseUpEvent);
141
+ window.addEventListener('mouseleave', mouseLeaveEvent);
142
+ };
143
+ const offEvents = () => {
144
+ root === null || root === void 0 ? void 0 : root.removeEventListener('mousedown', mouseDownEvent);
145
+ window.removeEventListener('mouseup', mouseUpEvent);
146
+ window.removeEventListener('mouseleave', mouseLeaveEvent);
147
+ };
148
+ const init = () => {
149
+ if (!container) {
150
+ return;
151
+ }
152
+ root = initRoot(container, { id, rootClassName });
153
+ if (!container.contains(root)) {
154
+ container.appendChild(root);
155
+ }
156
+ };
157
+ const destroy = () => {
158
+ offEvents();
159
+ root === null || root === void 0 ? void 0 : root.remove();
160
+ root = null;
161
+ };
162
+ const pathCreateCallback = () => {
163
+ onEvents();
164
+ viewer.drawFrame();
165
+ };
166
+ const clearPathCreateCallback = () => {
167
+ refineData();
168
+ offEvents();
169
+ clearData();
170
+ };
171
+ const clear = () => {
172
+ clearData();
173
+ viewer.drawFrame();
174
+ };
175
+ return {
176
+ name: '@middleware/pen-create',
177
+ use() {
178
+ initStyles(rootClassName, styles);
179
+ eventHub.on(coreEventKeys.PATH_CREATE, pathCreateCallback);
180
+ eventHub.on(coreEventKeys.CLEAR_PATH_CREATE, clearPathCreateCallback);
181
+ init();
182
+ },
183
+ disuse() {
184
+ destroyStyles(rootClassName);
185
+ eventHub.off(coreEventKeys.PATH_CREATE, pathCreateCallback);
186
+ eventHub.off(coreEventKeys.CLEAR_PATH_CREATE, clearPathCreateCallback);
187
+ clear();
188
+ destroy();
189
+ },
190
+ beforeDrawFrame() {
191
+ updateAnchorsStyle(root, {
192
+ viewScaleInfo: sharer.getActiveViewScaleInfo(),
193
+ styles,
194
+ });
195
+ },
196
+ hover() {
197
+ eventHub.trigger(coreEventKeys.CURSOR, {
198
+ type: 'pen',
199
+ });
200
+ return false;
201
+ },
202
+ };
203
+ };
@@ -0,0 +1,23 @@
1
+ import type { MiddlewarePathCreatorConfig, MiddlewarePathCreatorStyles } from '@idraw/types';
2
+ export declare const key = "PATH-CREATOR";
3
+ export declare const getRootClassName: () => string;
4
+ export declare const classNameMap: {
5
+ hide: string;
6
+ anchor: string;
7
+ director: string;
8
+ directorLines: string;
9
+ pathLine: string;
10
+ selected: string;
11
+ };
12
+ export declare const ATTR_X = "data-x";
13
+ export declare const ATTR_Y = "data-y";
14
+ export declare const ATTR_ANGLE = "data-angle";
15
+ export declare const ATTR_TYPE = "data-type";
16
+ export declare const ATTR_HELPER_TYPE = "data-helper-type";
17
+ export declare const ATTR_AHCHOR_CMD_TYPE = "data-anchor-cmd-type";
18
+ export declare const ATTR_AHCHOR_INDEX = "data-anchor-index";
19
+ export declare const ATTR_AHCHOR_ID = "data-anchor-id";
20
+ export declare const HELPER_ROOT = "root";
21
+ export declare const HELPER_ANCHOR = "anchor";
22
+ export declare const defaultConfig: MiddlewarePathCreatorConfig;
23
+ export declare function getMiddlewarePathCreatorStyles<C = MiddlewarePathCreatorConfig, S = MiddlewarePathCreatorStyles>(config: C): S;