cbvirtua 1.0.50 → 1.0.52

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 (139) hide show
  1. package/canvas-demo-master/canvas-demo-master/README.md +7 -0
  2. package/canvas-demo-master/canvas-demo-master/countShowBall/README.md +7 -0
  3. package/canvas-demo-master/canvas-demo-master/countShowBall/countdown.js +227 -0
  4. package/canvas-demo-master/canvas-demo-master/countShowBall/digit.js +135 -0
  5. package/canvas-demo-master/canvas-demo-master/countShowBall/index.html +23 -0
  6. package/canvas-demo-master/canvas-demo-master/write/README.md +17 -0
  7. package/canvas-demo-master/canvas-demo-master/write/css/write.css +40 -0
  8. package/canvas-demo-master/canvas-demo-master/write/index.html +26 -0
  9. package/canvas-demo-master/canvas-demo-master/write/js/controller.js +43 -0
  10. package/canvas-demo-master/canvas-demo-master/write/js/index.js +10 -0
  11. package/canvas-demo-master/canvas-demo-master/write/js/paper.js +63 -0
  12. package/canvas-demo-master/canvas-demo-master/write/js/require.js +36 -0
  13. package/canvas-demo-master/canvas-demo-master/write/js/write.js +143 -0
  14. package/canvas-demo-master/canvas-demo-master/writeRxJS/README.md +17 -0
  15. package/canvas-demo-master/canvas-demo-master/writeRxJS/css/write.css +40 -0
  16. package/canvas-demo-master/canvas-demo-master/writeRxJS/index.html +27 -0
  17. package/canvas-demo-master/canvas-demo-master/writeRxJS/js/controller.js +43 -0
  18. package/canvas-demo-master/canvas-demo-master/writeRxJS/js/index.js +10 -0
  19. package/canvas-demo-master/canvas-demo-master/writeRxJS/js/paper.js +65 -0
  20. package/canvas-demo-master/canvas-demo-master/writeRxJS/js/require.js +36 -0
  21. package/canvas-demo-master/canvas-demo-master/writeRxJS/js/write.js +107 -0
  22. package/drawingBoard-main/drawingBoard-main/README.md +32 -0
  23. package/drawingBoard-main/drawingBoard-main/index.html +13 -0
  24. package/drawingBoard-main/drawingBoard-main/package.json +31 -0
  25. package/drawingBoard-main/drawingBoard-main/pnpm-lock.yaml +2378 -0
  26. package/drawingBoard-main/drawingBoard-main/public/vite.svg +1 -0
  27. package/drawingBoard-main/drawingBoard-main/src/App.vue +64 -0
  28. package/drawingBoard-main/drawingBoard-main/src/assets/huabi.svg +1 -0
  29. package/drawingBoard-main/drawingBoard-main/src/assets/huabigongju-juxing.svg +1 -0
  30. package/drawingBoard-main/drawingBoard-main/src/assets/huabigongju-tuoyuan.svg +1 -0
  31. package/drawingBoard-main/drawingBoard-main/src/assets/huabigongju-wenben.svg +1 -0
  32. package/drawingBoard-main/drawingBoard-main/src/assets/jiantougongju-hover.svg +1 -0
  33. package/drawingBoard-main/drawingBoard-main/src/assets/layer.svg +1 -0
  34. package/drawingBoard-main/drawingBoard-main/src/assets/layer_1.svg +1 -0
  35. package/drawingBoard-main/drawingBoard-main/src/assets/tuceng.svg +1 -0
  36. package/drawingBoard-main/drawingBoard-main/src/assets/tuceng_1.svg +1 -0
  37. package/drawingBoard-main/drawingBoard-main/src/assets/wujiaoxing.svg +1 -0
  38. package/drawingBoard-main/drawingBoard-main/src/assets/xiangpigongju.svg +1 -0
  39. package/drawingBoard-main/drawingBoard-main/src/assets/xuanzegongju.svg +1 -0
  40. package/drawingBoard-main/drawingBoard-main/src/assets/zhixiangongju.svg +1 -0
  41. package/drawingBoard-main/drawingBoard-main/src/components/plugins/LayerOptions.tsx +67 -0
  42. package/drawingBoard-main/drawingBoard-main/src/components/plugins/LineSegmentBackgroundColorPlugin.tsx +25 -0
  43. package/drawingBoard-main/drawingBoard-main/src/components/plugins/LineSegmentColorPlugin.tsx +25 -0
  44. package/drawingBoard-main/drawingBoard-main/src/components/plugins/LineSegmentSizePlugin.tsx +26 -0
  45. package/drawingBoard-main/drawingBoard-main/src/components/plugins/TextColor.tsx +25 -0
  46. package/drawingBoard-main/drawingBoard-main/src/components/plugins/TextSize.tsx +27 -0
  47. package/drawingBoard-main/drawingBoard-main/src/components/tools/Menu.scss +10 -0
  48. package/drawingBoard-main/drawingBoard-main/src/components/tools/Menu.tsx +33 -0
  49. package/drawingBoard-main/drawingBoard-main/src/components/tools/Tips.scss +16 -0
  50. package/drawingBoard-main/drawingBoard-main/src/components/tools/Tips.tsx +5 -0
  51. package/drawingBoard-main/drawingBoard-main/src/components/tools/Toolbar.scss +26 -0
  52. package/drawingBoard-main/drawingBoard-main/src/components/tools/Toolbar.tsx +39 -0
  53. package/drawingBoard-main/drawingBoard-main/src/components/tools/ToolbarMenu.scss +45 -0
  54. package/drawingBoard-main/drawingBoard-main/src/components/tools/ToolbarMenu.tsx +61 -0
  55. package/drawingBoard-main/drawingBoard-main/src/components/tools/index.tsx +22 -0
  56. package/drawingBoard-main/drawingBoard-main/src/main.scss +4 -0
  57. package/drawingBoard-main/drawingBoard-main/src/main.ts +11 -0
  58. package/drawingBoard-main/drawingBoard-main/src/shims-vue.d.ts +5 -0
  59. package/drawingBoard-main/drawingBoard-main/src/utils/App.ts +24 -0
  60. package/drawingBoard-main/drawingBoard-main/src/utils/DrawingBoard.ts +213 -0
  61. package/drawingBoard-main/drawingBoard-main/src/utils/History.ts +70 -0
  62. package/drawingBoard-main/drawingBoard-main/src/utils/Tools.ts +241 -0
  63. package/drawingBoard-main/drawingBoard-main/src/utils/types.ts +55 -0
  64. package/drawingBoard-main/drawingBoard-main/src/vite-env.d.ts +1 -0
  65. package/drawingBoard-main/drawingBoard-main/tsconfig.app.json +36 -0
  66. package/drawingBoard-main/drawingBoard-main/tsconfig.json +7 -0
  67. package/drawingBoard-main/drawingBoard-main/tsconfig.node.json +23 -0
  68. package/drawingBoard-main/drawingBoard-main/vite.config.ts +16 -0
  69. package/hidpi-canvas-polyfill-master.zip +0 -0
  70. package/package.json +1 -1
  71. package//346/226/260/345/273/272 /346/226/207/346/234/254/346/226/207/346/241/243.txt" +53 -0
  72. package/canvas-example-main.zip +0 -0
  73. package/hanzi-writer/.prettierrc.json +0 -7
  74. package/hanzi-writer/COPYING.md +0 -11
  75. package/hanzi-writer/LICENSE +0 -20
  76. package/hanzi-writer/README.md +0 -37
  77. package/hanzi-writer/babel.config.js +0 -14
  78. package/hanzi-writer/dist/types/HanziWriter.d.ts +0 -108
  79. package/hanzi-writer/dist/types/LoadingManager.d.ts +0 -20
  80. package/hanzi-writer/dist/types/Positioner.d.ts +0 -22
  81. package/hanzi-writer/dist/types/Quiz.d.ts +0 -40
  82. package/hanzi-writer/dist/types/RenderState.d.ts +0 -74
  83. package/hanzi-writer/dist/types/__tests__/HanziWriter-test.d.ts +0 -1
  84. package/hanzi-writer/dist/types/__tests__/LoadingManager-test.d.ts +0 -1
  85. package/hanzi-writer/dist/types/__tests__/Mutation-test.d.ts +0 -1
  86. package/hanzi-writer/dist/types/__tests__/Positioner-test.d.ts +0 -1
  87. package/hanzi-writer/dist/types/__tests__/Quiz-test.d.ts +0 -1
  88. package/hanzi-writer/dist/types/__tests__/RenderState-test.d.ts +0 -1
  89. package/hanzi-writer/dist/types/__tests__/defaultCharDataLoader-test.d.ts +0 -1
  90. package/hanzi-writer/dist/types/__tests__/geometry-test.d.ts +0 -1
  91. package/hanzi-writer/dist/types/__tests__/parseCharData-test.d.ts +0 -1
  92. package/hanzi-writer/dist/types/__tests__/strokeMatches-test.d.ts +0 -1
  93. package/hanzi-writer/dist/types/__tests__/utils-test.d.ts +0 -1
  94. package/hanzi-writer/dist/types/characterActions.d.ts +0 -18
  95. package/hanzi-writer/dist/types/defaultCharDataLoader.d.ts +0 -3
  96. package/hanzi-writer/dist/types/defaultOptions.d.ts +0 -3
  97. package/hanzi-writer/dist/types/geometry.d.ts +0 -38
  98. package/hanzi-writer/dist/types/models/Character.d.ts +0 -6
  99. package/hanzi-writer/dist/types/models/Stroke.d.ts +0 -17
  100. package/hanzi-writer/dist/types/models/UserStroke.d.ts +0 -8
  101. package/hanzi-writer/dist/types/parseCharData.d.ts +0 -3
  102. package/hanzi-writer/dist/types/quizActions.d.ts +0 -10
  103. package/hanzi-writer/dist/types/renderers/HanziWriterRendererBase.d.ts +0 -14
  104. package/hanzi-writer/dist/types/renderers/RenderTargetBase.d.ts +0 -22
  105. package/hanzi-writer/dist/types/renderers/StrokeRendererBase.d.ts +0 -13
  106. package/hanzi-writer/dist/types/renderers/canvas/CharacterRenderer.d.ts +0 -14
  107. package/hanzi-writer/dist/types/renderers/canvas/HanziWriterRenderer.d.ts +0 -19
  108. package/hanzi-writer/dist/types/renderers/canvas/RenderTarget.d.ts +0 -6
  109. package/hanzi-writer/dist/types/renderers/canvas/StrokeRenderer.d.ts +0 -16
  110. package/hanzi-writer/dist/types/renderers/canvas/__tests__/CharacterRenderer-test.d.ts +0 -1
  111. package/hanzi-writer/dist/types/renderers/canvas/__tests__/HanziWriterRenderer-test.d.ts +0 -1
  112. package/hanzi-writer/dist/types/renderers/canvas/__tests__/RenderTarget-test.d.ts +0 -1
  113. package/hanzi-writer/dist/types/renderers/canvas/__tests__/StrokeRenderer-test.d.ts +0 -1
  114. package/hanzi-writer/dist/types/renderers/canvas/__tests__/canvasUtils-test.d.ts +0 -1
  115. package/hanzi-writer/dist/types/renderers/canvas/__tests__/renderUserStroke-test.d.ts +0 -1
  116. package/hanzi-writer/dist/types/renderers/canvas/canvasUtils.d.ts +0 -9
  117. package/hanzi-writer/dist/types/renderers/canvas/index.d.ts +0 -7
  118. package/hanzi-writer/dist/types/renderers/canvas/renderUserStroke.d.ts +0 -7
  119. package/hanzi-writer/dist/types/renderers/svg/CharacterRenderer.d.ts +0 -20
  120. package/hanzi-writer/dist/types/renderers/svg/HanziWriterRenderer.d.ts +0 -20
  121. package/hanzi-writer/dist/types/renderers/svg/RenderTarget.d.ts +0 -11
  122. package/hanzi-writer/dist/types/renderers/svg/StrokeRenderer.d.ts +0 -21
  123. package/hanzi-writer/dist/types/renderers/svg/UserStrokeRenderer.d.ts +0 -15
  124. package/hanzi-writer/dist/types/renderers/svg/__tests__/CharacterRenderer-test.d.ts +0 -1
  125. package/hanzi-writer/dist/types/renderers/svg/__tests__/HanziWriterRenderer-test.d.ts +0 -1
  126. package/hanzi-writer/dist/types/renderers/svg/__tests__/StrokeRenderer-test.d.ts +0 -1
  127. package/hanzi-writer/dist/types/renderers/svg/__tests__/svgUtils-test.d.ts +0 -1
  128. package/hanzi-writer/dist/types/renderers/svg/index.d.ts +0 -7
  129. package/hanzi-writer/dist/types/renderers/svg/svgUtils.d.ts +0 -5
  130. package/hanzi-writer/dist/types/strokeMatches.d.ts +0 -14
  131. package/hanzi-writer/dist/types/testUtils.d.ts +0 -1
  132. package/hanzi-writer/dist/types/typings/types.d.ts +0 -121
  133. package/hanzi-writer/dist/types/utils.d.ts +0 -26
  134. package/hanzi-writer/jest-jsdom-env.js +0 -20
  135. package/hanzi-writer/package.json +0 -66
  136. package/hanzi-writer/rollup.config.js +0 -58
  137. package/hanzi-writer/tsconfig.json +0 -79
  138. package/progress-master.zip +0 -0
  139. package/xbossdebug-wechat-master.zip +0 -0
@@ -0,0 +1,213 @@
1
+ import "@leafer-in/editor";
2
+ import "@leafer-in/text-editor";
3
+ import Tools, { INITIAL_HEIGHT, INITIAL_WIDTH } from "./Tools";
4
+
5
+ import {
6
+ App,
7
+ DragEvent,
8
+ ICursorType,
9
+ ILeaf,
10
+ IUIJSONData,
11
+ Text,
12
+ } from "leafer-ui";
13
+ import { Ref, ref, toRef, watch } from "vue";
14
+ import { EditorEvent } from "@leafer-in/editor";
15
+ import History from "./History";
16
+ import { IAppProps } from "./types";
17
+
18
+ class DrawingBoard {
19
+ private leaferInstance: null | App = null;
20
+ private rootDom: null | HTMLElement = null;
21
+ private isSelect = false;
22
+ private onChange: (json: IUIJSONData) => void = () => {};
23
+ private history: null | History = null;
24
+
25
+ public tools: null | Tools = null;
26
+ public selectedGraphics: Ref<null | any> = ref(null);
27
+ public clearGraphicsQueue = new Map<ILeaf, ILeaf>();
28
+ public readonly leaferInstanceReadonly: null | App = null;
29
+
30
+ constructor({ domId, onChange, config }: IAppProps) {
31
+ this.rootDom = document.getElementById(domId);
32
+
33
+ if (!this.rootDom) {
34
+ console.warn("未找到挂载元素!");
35
+ return;
36
+ }
37
+
38
+ if (onChange) this.onChange = onChange;
39
+
40
+ this.leaferInstance = this.initApp(this.rootDom);
41
+ this.leaferInstanceReadonly = this.leaferInstance;
42
+ this.tools = new Tools(config);
43
+ this.history = new History(this.leaferInstance);
44
+ this.initEvent(this.leaferInstance);
45
+
46
+ watch(
47
+ () => this.tools.toolbarActiveIndex.value,
48
+ (newValue) => {
49
+ this.setEditorState(!newValue);
50
+ this.setCursor();
51
+ }
52
+ );
53
+ }
54
+
55
+ private initApp = (view: HTMLElement) => {
56
+ const app = new App({
57
+ view,
58
+ editor: {},
59
+ });
60
+
61
+ return app;
62
+ };
63
+
64
+ private initEvent = (app: App) => {
65
+ app.on(DragEvent.DOWN, this.mousedown);
66
+ app.on(DragEvent.DRAG, this.mousemove);
67
+ app.on(DragEvent.UP, this.mouseup);
68
+ app.editor.on(EditorEvent.SELECT, this.graphicSelected);
69
+ document.body.addEventListener("keydown", this.onKeyDownEvent);
70
+ };
71
+
72
+ public destroy() {
73
+ this.leaferInstance.off(DragEvent.DOWN, this.mousedown);
74
+ this.leaferInstance.off(DragEvent.DRAG, this.mousemove);
75
+ this.leaferInstance.off(DragEvent.UP, this.mouseup);
76
+ this.leaferInstance.editor.off(EditorEvent.SELECT, this.graphicSelected);
77
+ document.body.removeEventListener("keydown", this.onKeyDownEvent);
78
+ }
79
+
80
+ onKeyDownEvent = (event: KeyboardEvent) => {
81
+ // 快捷键撤销
82
+ if (event.ctrlKey && event.key === "z") this.historyBack();
83
+
84
+ // 快捷键取消撤销
85
+ if (event.ctrlKey && event.key === "y") this.historyUnBack();
86
+ };
87
+
88
+ private mousedown = (e: DragEvent) =>
89
+ this.aop(null, () => {
90
+ const { x, y } = e.getPage();
91
+
92
+ const graphics = this.tools.getActiveGraphics();
93
+
94
+ const graph = graphics.createdFactory!(
95
+ x - INITIAL_WIDTH,
96
+ y - INITIAL_HEIGHT
97
+ );
98
+
99
+ this.selectedGraphics.value = graph;
100
+ this.leaferInstance.tree.add(graph);
101
+ });
102
+
103
+ private mousemove = (e: DragEvent) =>
104
+ this.aop(null, () => {
105
+ if (!this.selectedGraphics.value) return;
106
+
107
+ const graphics = this.tools.getActiveGraphics();
108
+
109
+ // 不需要移动
110
+ if (graphics.notMove) return;
111
+
112
+ const { x, y } = this.selectedGraphics.value;
113
+
114
+ if (!x || !y) return;
115
+
116
+ const { x: offsetX, y: offsetY } = e.getPage();
117
+ const [width, height] = [offsetX - x, offsetY - y];
118
+
119
+ if(graphics.onMousemove) {
120
+ graphics.onMousemove(e, this, { width, height })
121
+ } else {
122
+ const scaleX = width < 0 ? -1 : 1,
123
+ scaleY = height < 0 ? -1 : 1;
124
+
125
+ this.selectedGraphics.value.scaleX = scaleX;
126
+ this.selectedGraphics.value.scaleY = scaleY;
127
+ this.selectedGraphics.value.width = Math.abs(width);
128
+ this.selectedGraphics.value.height = Math.abs(height);
129
+ }
130
+ });
131
+
132
+ private mouseup = () => {
133
+ if (this.isSelect) return;
134
+
135
+ if (this.tools.getActiveGraphics().isAfterRemove) {
136
+ this.selectedGraphics.value.remove();
137
+ }
138
+
139
+ this.clearGraphicsQueue.forEach((graphics) => {
140
+ graphics.remove();
141
+ this.clearGraphicsQueue.delete(graphics);
142
+ });
143
+
144
+ this.tools.toolbarActiveIndex.value = 0;
145
+ this.selectedGraphics.value = null;
146
+
147
+ const isSave = this.history.save(this.leaferInstance.tree.toJSON());
148
+ isSave && this.onChange(this.leaferInstance.tree.toJSON());
149
+ };
150
+
151
+ private aop = (beforeHandler, afterHandler) => {
152
+ beforeHandler && beforeHandler();
153
+
154
+ if (!this.tools.toolbarActiveIndex.value) return;
155
+
156
+ afterHandler && afterHandler();
157
+ };
158
+
159
+ public setEditorState = (state: boolean) => {
160
+ this.leaferInstance.editor.cancel();
161
+ this.leaferInstance.editor.hittable = state;
162
+ this.leaferInstance.editor.visible = state;
163
+ };
164
+
165
+ private graphicSelected = ({ value }: any) => {
166
+ if (!value || !value?.tag) {
167
+ this.selectedGraphics.value = null;
168
+ this.isSelect = false;
169
+ return;
170
+ }
171
+
172
+ this.isSelect = true;
173
+
174
+ if (value.tag === "Pen") {
175
+ value.children[0].name = value.name;
176
+ this.selectedGraphics.value = value.children[0];
177
+ } else {
178
+ this.selectedGraphics.value = value;
179
+ }
180
+ };
181
+
182
+ public setCursor = () => {
183
+ const cursor = (this.tools.getActiveGraphics().cursor ||
184
+ "crosshair") as ICursorType;
185
+ this.leaferInstance.cursor = this.tools.toolbarActiveIndex.value
186
+ ? cursor
187
+ : "auto";
188
+ };
189
+
190
+ public getSelectedGraphics = () => {
191
+ return toRef(
192
+ this.selectedGraphics.value
193
+ ? this.selectedGraphics.value
194
+ : this.tools.getActiveGraphics()
195
+ );
196
+ };
197
+
198
+ setJson = (json: IUIJSONData | null) => {
199
+ if (!json) return;
200
+ this.leaferInstance.tree.set({ children: json.children });
201
+ this.onChange(json);
202
+ };
203
+
204
+ historyBack = () => {
205
+ this.setJson(this.history.getBackJson());
206
+ };
207
+
208
+ historyUnBack = () => {
209
+ this.setJson(this.history.getUnBackJson());
210
+ };
211
+ }
212
+
213
+ export default DrawingBoard;
@@ -0,0 +1,70 @@
1
+ import { App, IUIJSONData } from "leafer-ui";
2
+ import { Ref, ref } from "vue";
3
+
4
+ export const clearAppJson = (_: IUIJSONData) => {
5
+ _.children = _.children?.filter(({ tag }) => tag !== "SimulateElement")
6
+
7
+ return _;
8
+ }
9
+
10
+ class History {
11
+ queue: Ref<IUIJSONData[]> = ref([]);
12
+ activeIndex = this.queue.value.length
13
+
14
+ // // 撤销 || 取消撤销
15
+ // operate: IOperate = ''
16
+ // preOperate: IOperate = ''
17
+
18
+ constructor(app: App) {
19
+ this.save(app.tree.toJSON())
20
+ }
21
+
22
+ save(json: IUIJSONData) {
23
+ if (!json) return false;
24
+
25
+ json = clearAppJson(json);
26
+
27
+ const newJson = JSON.stringify(json);
28
+ const oldJson = JSON.stringify(this.queue.value[this.activeIndex - 1] || '');
29
+
30
+ // 可优化,简单对比
31
+ if (newJson === oldJson) return false;
32
+
33
+ if (this.queue.value.length >= 20) {
34
+ this.queue.value.shift();
35
+ }
36
+
37
+ this.queue.value.push(json);
38
+ this.activeIndex = this.queue.value.length;
39
+
40
+ return true;
41
+ }
42
+
43
+ getBackJson() {
44
+ // 上一次
45
+ const _json = this.queue.value[this.activeIndex - 2];
46
+
47
+ if (this.activeIndex < -1 || !_json) {
48
+ console.warn('已无更多可撤销数据');
49
+ return null;
50
+ };
51
+
52
+ this.activeIndex--;
53
+
54
+ return _json;
55
+ }
56
+
57
+ getUnBackJson() {
58
+ if (this.activeIndex >= this.queue.value.length || !this.queue.value[this.activeIndex]) {
59
+ console.warn('已无更多可恢复数据');
60
+ return null
61
+ }
62
+
63
+ const _json = this.queue.value[this.activeIndex]
64
+ this.activeIndex++;
65
+
66
+ return _json;
67
+ }
68
+ }
69
+
70
+ export default History
@@ -0,0 +1,241 @@
1
+ import { Ellipse, Line, Pen, Rect, Text } from "leafer-ui";
2
+ import Index from "../components/tools/index";
3
+ import { render, h, ref, Ref, nextTick } from "vue";
4
+ import { Arrow } from "@leafer-in/arrow";
5
+
6
+ import SELECT_TOOl_ICON from "../assets/xuanzegongju.svg";
7
+ import BRUSH_TOOl_ICON from "../assets/huabi.svg";
8
+ import ERASER_TOOl_ICON from "../assets/xiangpigongju.svg";
9
+ import RECT_TOOl_ICON from "../assets/huabigongju-juxing.svg";
10
+ import ELLIPSE_TOOl_ICON from "../assets/huabigongju-tuoyuan.svg";
11
+ import TEXT_TOOl_ICON from "../assets/huabigongju-wenben.svg";
12
+ import LINE_TOOl_ICON from "../assets/zhixiangongju.svg";
13
+ import ARROW_TOOl_ICON from "../assets/jiantougongju-hover.svg";
14
+
15
+ import LineSegmentSizePlugin from "../components/plugins/LineSegmentSizePlugin";
16
+ import LineSegmentColorPlugin from "../components/plugins/LineSegmentColorPlugin";
17
+ import LineSegmentBackgroundColorPlugin from "../components/plugins/LineSegmentBackgroundColorPlugin";
18
+ import { IAppProps, IToolBarItem } from "./types";
19
+ import TextColor from "../components/plugins/TextColor";
20
+ import TextSize from "../components/plugins/TextSize";
21
+
22
+ export const INITIAL_WIDTH = 0;
23
+ export const INITIAL_HEIGHT = 0;
24
+
25
+ export const toolBarOptions: IToolBarItem[] = [
26
+ {
27
+ icon: SELECT_TOOl_ICON,
28
+ name: "selectTool",
29
+ title: "选择",
30
+ },
31
+ {
32
+ icon: BRUSH_TOOl_ICON,
33
+ name: "brushTool",
34
+ title: "画笔",
35
+ strokeWidth: 3,
36
+ stroke: "rgba(0, 0, 0, 1)",
37
+ createdFactory(x: number, y: number) {
38
+ const pen: Pen = new Pen({
39
+ name: "brushTool",
40
+ x,
41
+ y,
42
+ editable: true,
43
+ });
44
+
45
+ pen.setStyle({
46
+ stroke: this.stroke,
47
+ strokeWidth: this.strokeWidth,
48
+ strokeCap: "round",
49
+ strokeJoin: "round",
50
+ });
51
+ return pen;
52
+ },
53
+ onMousemove(e, drawingBoard, point) {
54
+ drawingBoard.selectedGraphics.value.lineTo(point.width, point.height);
55
+ },
56
+ menuPlugins: [LineSegmentSizePlugin, LineSegmentColorPlugin],
57
+ },
58
+ {
59
+ icon: RECT_TOOl_ICON,
60
+ name: "rectTool",
61
+ title: "矩形",
62
+ strokeWidth: 2,
63
+ stroke: "rgba(0, 0, 0, 1)",
64
+ fill: "#fff",
65
+ createdFactory(x: number, y: number) {
66
+ return new Rect({
67
+ name: "rectTool",
68
+ x,
69
+ y,
70
+ width: INITIAL_WIDTH,
71
+ height: INITIAL_HEIGHT,
72
+ strokeWidth: this.strokeWidth,
73
+ stroke: this.stroke,
74
+ fill: this.fill,
75
+ editable: true,
76
+ });
77
+ },
78
+ menuPlugins: [
79
+ LineSegmentSizePlugin,
80
+ LineSegmentColorPlugin,
81
+ LineSegmentBackgroundColorPlugin,
82
+ ],
83
+ },
84
+ {
85
+ icon: ELLIPSE_TOOl_ICON,
86
+ name: "ellipseTool",
87
+ title: "椭圆",
88
+ strokeWidth: 2,
89
+ stroke: "rgba(0, 0, 0, 1)",
90
+ fill: "#fff",
91
+ createdFactory(x: number, y: number) {
92
+ return new Ellipse({
93
+ name: "ellipseTool",
94
+ x,
95
+ y,
96
+ width: INITIAL_WIDTH,
97
+ height: INITIAL_HEIGHT,
98
+ innerRadius: 1,
99
+ editable: true,
100
+ strokeWidth: this.strokeWidth,
101
+ stroke: this.stroke,
102
+ fill: this.fill,
103
+ });
104
+ },
105
+
106
+ menuPlugins: [
107
+ LineSegmentSizePlugin,
108
+ LineSegmentColorPlugin,
109
+ LineSegmentBackgroundColorPlugin,
110
+ ],
111
+ },
112
+ {
113
+ icon: LINE_TOOl_ICON,
114
+ name: "lineTool",
115
+ title: "线条",
116
+ strokeWidth: 3,
117
+ stroke: "rgba(0, 0, 0, 1)",
118
+ createdFactory(x: number, y: number) {
119
+ return new Line({
120
+ name: "lineTool",
121
+ x,
122
+ y,
123
+ toPoint: { x: 0, y: 0 },
124
+ strokeWidth: this.strokeWidth,
125
+ stroke: this.stroke,
126
+ editable: true,
127
+ });
128
+ },
129
+ onMousemove(e, drawingBoard, point) {
130
+ drawingBoard.selectedGraphics.value.toPoint = { x: point.width, y: point.height };
131
+ },
132
+ menuPlugins: [LineSegmentSizePlugin, LineSegmentColorPlugin],
133
+ },
134
+ {
135
+ icon: ARROW_TOOl_ICON,
136
+ name: "arrowTool",
137
+ title: "箭头",
138
+ strokeWidth: 3,
139
+ stroke: "rgba(0, 0, 0, 1)",
140
+ createdFactory(x: number, y: number) {
141
+ return new Arrow({
142
+ name: "arrowTool",
143
+ x,
144
+ y,
145
+ toPoint: { x: 0, y: 0 },
146
+ strokeWidth: this.strokeWidth,
147
+ stroke: this.stroke,
148
+ editable: true,
149
+ });
150
+ },
151
+ onMousemove(e, drawingBoard, point) {
152
+ drawingBoard.selectedGraphics.value.toPoint = { x: point.width, y: point.height };
153
+ },
154
+ menuPlugins: [LineSegmentSizePlugin, LineSegmentColorPlugin],
155
+ },
156
+ {
157
+ icon: TEXT_TOOl_ICON,
158
+ name: "textTool",
159
+ title: "文本",
160
+ notMove: true,
161
+ cursor: "text",
162
+ fontSize: 24,
163
+ fill: "rgba(0, 0, 0, 1)",
164
+ createdFactory(x: number, y: number) {
165
+ return new Text({
166
+ name: "textTool",
167
+ x: x - 5,
168
+ width: 200,
169
+ height: 35,
170
+ y: y - 10,
171
+ text: "请双击编辑内容",
172
+ fontSize: this.fontSize,
173
+ fill: this.fill,
174
+ editable: true,
175
+ });
176
+ },
177
+ menuPlugins: [TextSize, TextColor],
178
+ },
179
+ {
180
+ icon: ERASER_TOOl_ICON,
181
+ name: "eraserTool",
182
+ title: "橡皮擦",
183
+ cursor: "grabbing",
184
+ isAfterRemove: true,
185
+ createdFactory: (x: number, y: number) =>
186
+ new Line({
187
+ x,
188
+ y,
189
+ toPoint: { x: 0, y: 0 },
190
+ strokeWidth: 3,
191
+ stroke: "rgba(0, 0, 0, 1)",
192
+ editable: true,
193
+ }),
194
+
195
+ onMousemove(e, drawingBoard) {
196
+ const { target } = drawingBoard.leaferInstanceReadonly.pick(
197
+ { x: e.x, y: e.y },
198
+ {
199
+ hitRadius: 2,
200
+ }
201
+ )!;
202
+
203
+ if (!target) return;
204
+
205
+ const has = drawingBoard.clearGraphicsQueue.has(target);
206
+
207
+ if (has) return;
208
+
209
+ drawingBoard.clearGraphicsQueue.set(target, target);
210
+ target.opacity = 0.5;
211
+ },
212
+ },
213
+ ];
214
+
215
+ class Tools {
216
+ public toolbarActiveIndex: Ref<number> = ref(0);
217
+ constructor(config: IAppProps["config"]) {
218
+ this.init(config);
219
+ }
220
+
221
+ private init(config: IAppProps["config"]) {
222
+ if (config.toolbar && config.toolbar.length) {
223
+ config.toolbar.forEach((item) => {
224
+ if (item.index) {
225
+ toolBarOptions.splice(item.index, 0, item);
226
+ }
227
+ });
228
+ }
229
+
230
+ const div = document.createElement("div");
231
+ document.getElementById("app").append(div);
232
+
233
+ nextTick(() => render(h(Index), div));
234
+ }
235
+
236
+ public getActiveGraphics() {
237
+ return toolBarOptions[this.toolbarActiveIndex.value];
238
+ }
239
+ }
240
+
241
+ export default Tools;
@@ -0,0 +1,55 @@
1
+ import { App, IUIJSONData, DragEvent, IUI } from "leafer-ui";
2
+ import DrawingBoard from "./DrawingBoard";
3
+ import { Ref } from "vue";
4
+
5
+ export interface IPluginProps {
6
+ drawingBoard: DrawingBoard;
7
+ }
8
+
9
+ export interface IToolBarItem {
10
+ icon: string;
11
+ name: string;
12
+ title: string;
13
+
14
+ // 组件工具栏位置
15
+ index?: number;
16
+
17
+ // 禁止移动
18
+ notMove?: boolean;
19
+
20
+ // 手势图标
21
+ cursor?: string;
22
+
23
+ // 是否能够移除
24
+ isAfterRemove?: boolean;
25
+
26
+ // 创建图形工厂函数
27
+ createdFactory?: (x: number, y: number) => IUI;
28
+
29
+ // 自定义鼠标移动函数
30
+ onMousemove?: (
31
+ e: DragEvent,
32
+ drawingBoard: DrawingBoard,
33
+ point: {
34
+ width: number;
35
+ height: number;
36
+ }
37
+ ) => void;
38
+
39
+ // 菜单插件
40
+ menuPlugins?: Array<any>;
41
+ strokeWidth?: number;
42
+ stroke?: string;
43
+ fill?: string;
44
+ fontSize?: number;
45
+ [key: string]: any;
46
+ }
47
+
48
+ export interface IAppProps {
49
+ domId: string;
50
+ onChange?: (json: IUIJSONData) => void;
51
+ config?: {
52
+ // 增加自定义工具栏
53
+ toolbar?: Array<IToolBarItem>;
54
+ };
55
+ }
@@ -0,0 +1 @@
1
+ /// <reference types="vite/client" />
@@ -0,0 +1,36 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "esnext",
4
+ "useDefineForClassFields": true,
5
+ "module": "esnext",
6
+ "moduleResolution": "node",
7
+ "strict": false,
8
+ "jsx": "preserve",
9
+ // "jsxImportSource": "vue",
10
+ "sourceMap": true,
11
+ "resolveJsonModule": true,
12
+ "esModuleInterop": true,
13
+ "lib": [
14
+ "esnext",
15
+ "dom"
16
+ ],
17
+ "types": [
18
+ "element-plus/global",
19
+ "vite/client",
20
+ ],
21
+ "baseUrl": "./",
22
+ // "paths": {
23
+ // "@/*": [
24
+ // "src/*"
25
+ // ],
26
+ // },
27
+ "isolatedModules": true,
28
+ "skipLibCheck": true
29
+ },
30
+ "include": [
31
+ "src/**/*.ts",
32
+ "src/**/*.d.ts",
33
+ "src/**/*.tsx",
34
+ "src/**/*.vue",
35
+ ]
36
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "files": [],
3
+ "references": [
4
+ { "path": "./tsconfig.app.json" },
5
+ { "path": "./tsconfig.node.json" }
6
+ ]
7
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "lib": ["ES2023"],
5
+ "module": "ESNext",
6
+ "skipLibCheck": true,
7
+
8
+ /* Bundler mode */
9
+ "moduleResolution": "Bundler",
10
+ "allowImportingTsExtensions": true,
11
+ "isolatedModules": true,
12
+ "moduleDetection": "force",
13
+ "noEmit": true,
14
+
15
+ /* Linting */
16
+ "strict": true,
17
+ "noUnusedLocals": true,
18
+ "noUnusedParameters": true,
19
+ "noFallthroughCasesInSwitch": true,
20
+ "noUncheckedSideEffectImports": true
21
+ },
22
+ "include": ["vite.config.ts"]
23
+ }
@@ -0,0 +1,16 @@
1
+ import { defineConfig } from "vite";
2
+ import vue from "@vitejs/plugin-vue";
3
+ import vueJsx from "@vitejs/plugin-vue-jsx";
4
+ import svgLoader from 'vite-svg-loader'
5
+
6
+ // https://vite.dev/config/
7
+ export default defineConfig({
8
+ plugins: [vue(), vueJsx(), svgLoader()],
9
+ css: {
10
+ preprocessorOptions: {
11
+ scss: {
12
+ api: "modern-compiler", // or "modern"
13
+ },
14
+ },
15
+ },
16
+ });
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbvirtua",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {