Skip to content

Commit d72e95d

Browse files
committed
build(package): 拆分SDK文件
1 parent d3c74f0 commit d72e95d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+4352
-9
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
"@vueuse/core": "^10.1.0",
1919
"axios": "^1.3.4",
2020
"color-gradient-picker-vue3": "^2.0.7",
21-
"events": "^3.3.0",
22-
"fabric": "^5.2.1",
23-
"fabric-history": "^1.6.0",
2421
"fontfaceobserver": "^2.1.0",
25-
"hotkeys-js": "^3.8.8",
2622
"lodash-es": "^4.17.21",
2723
"number-precision": "^1.6.0",
28-
"tapable": "^2.2.1",
2924
"uuid": "^8.3.2",
3025
"view-ui-plus": "^1.3.7",
26+
"fabric": "^5.2.1",
3127
"vue": "^3.2.25",
3228
"vue-i18n": "9.0.0",
3329
"vue-router": "^4.0.16",
34-
"vue3-lazyload": "^0.3.6"
30+
"vue3-lazyload": "^0.3.6",
31+
"@kuaitu/core": "workspace:^"
3532
},
33+
"workspaces": [
34+
"packages/*"
35+
],
3636
"devDependencies": {
3737
"@commitlint/cli": "^17.4.2",
3838
"@commitlint/config-conventional": "^17.4.2",
@@ -69,4 +69,4 @@
6969
"prettier --write"
7070
]
7171
}
72-
}
72+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

packages/core/package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@kuaitu/core",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.ts",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"dependencies": {
10+
"events": "^3.3.0",
11+
"fabric-history": "^1.6.0",
12+
"fontfaceobserver": "^2.1.0",
13+
"hotkeys-js": "^3.8.8",
14+
"tapable": "^2.2.1",
15+
"uuid": "^8.3.2"
16+
},
17+
"keywords": [],
18+
"author": "",
19+
"license": "ISC"
20+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* @Author: 秦少卫
3+
* @Date: 2023-06-21 22:09:36
4+
* @LastEditors: 秦少卫
5+
* @LastEditTime: 2023-06-22 16:07:52
6+
* @Description: file content
7+
*/
8+
9+
import { v4 as uuid } from 'uuid';
10+
import { fabric } from 'fabric';
11+
import Arrow from '@/core12122/objects/Arrow';
12+
import Editor from '../core';
13+
type IEditor = Editor;
14+
15+
class DrawLinePlugin {
16+
public canvas: fabric.Canvas;
17+
public editor: IEditor;
18+
static pluginName = 'DrawLinePlugin';
19+
static apis = ['setArrow', 'setMode'];
20+
isDrawingLineMode: boolean;
21+
isArrow: boolean;
22+
lineToDraw: any;
23+
pointer: any;
24+
pointerPoints: any;
25+
isDrawingLine: boolean;
26+
constructor(canvas: fabric.Canvas, editor: IEditor) {
27+
this.canvas = canvas;
28+
this.editor = editor;
29+
30+
this.isDrawingLine = false;
31+
this.isDrawingLineMode = false;
32+
this.isArrow = false;
33+
this.lineToDraw = null;
34+
this.pointer = null;
35+
this.pointerPoints = null;
36+
this.init();
37+
}
38+
39+
init() {
40+
const { canvas } = this;
41+
canvas.on('mouse:down', (o) => {
42+
if (!this.isDrawingLineMode) return;
43+
canvas.discardActiveObject();
44+
canvas.getObjects().forEach((obj) => {
45+
obj.selectable = false;
46+
obj.hasControls = false;
47+
});
48+
canvas.requestRenderAll();
49+
this.isDrawingLine = true;
50+
this.pointer = canvas.getPointer(o.e);
51+
this.pointerPoints = [this.pointer.x, this.pointer.y, this.pointer.x, this.pointer.y];
52+
53+
const NodeHandler = this.isArrow ? Arrow : fabric.Line;
54+
this.lineToDraw = new NodeHandler(this.pointerPoints, {
55+
strokeWidth: 2,
56+
stroke: '#000000',
57+
id: uuid(),
58+
});
59+
60+
this.lineToDraw.selectable = false;
61+
this.lineToDraw.evented = false;
62+
this.lineToDraw.strokeUniform = true;
63+
canvas.add(this.lineToDraw);
64+
});
65+
66+
canvas.on('mouse:move', (o) => {
67+
if (!this.isDrawingLine) return;
68+
canvas.discardActiveObject();
69+
const activeObject = canvas.getActiveObject();
70+
if (activeObject) return;
71+
this.pointer = canvas.getPointer(o.e);
72+
73+
if (o.e.shiftKey) {
74+
// calc angle
75+
const startX = this.pointerPoints[0];
76+
const startY = this.pointerPoints[1];
77+
const x2 = this.pointer.x - startX;
78+
const y2 = this.pointer.y - startY;
79+
const r = Math.sqrt(x2 * x2 + y2 * y2);
80+
let angle = (Math.atan2(y2, x2) / Math.PI) * 180;
81+
angle = parseInt(((angle + 7.5) % 360) / 15) * 15;
82+
83+
const cosx = r * Math.cos((angle * Math.PI) / 180);
84+
const sinx = r * Math.sin((angle * Math.PI) / 180);
85+
86+
this.lineToDraw.set({
87+
x2: cosx + startX,
88+
y2: sinx + startY,
89+
});
90+
} else {
91+
this.lineToDraw.set({
92+
x2: this.pointer.x,
93+
y2: this.pointer.y,
94+
});
95+
}
96+
97+
canvas.renderAll();
98+
});
99+
100+
canvas.on('mouse:up', () => {
101+
if (!this.isDrawingLine) return;
102+
this.lineToDraw.setCoords();
103+
this.isDrawingLine = false;
104+
canvas.discardActiveObject();
105+
});
106+
}
107+
108+
setArrow(params: any) {
109+
this.isArrow = params;
110+
}
111+
112+
setMode(params: any) {
113+
this.isDrawingLineMode = params;
114+
if (!this.isDrawingLineMode) {
115+
this.endRest();
116+
}
117+
}
118+
119+
endRest() {
120+
this.canvas.getObjects().forEach((obj) => {
121+
if (obj.id !== 'workspace') {
122+
obj.selectable = true;
123+
obj.hasControls = true;
124+
}
125+
});
126+
}
127+
128+
destroy() {
129+
console.log('pluginDestroy');
130+
}
131+
}
132+
133+
export default DrawLinePlugin;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/core/plugin/RulerPlugin.ts packages/core/plugin/RulerPlugin.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Editor from '../core';
1111
// import { throttle } from 'lodash-es';
1212
type IEditor = Editor;
1313

14-
import initRuler from '@/core/ruler';
14+
import initRuler from '@/core12122/ruler';
1515

1616
class RulerPlugin {
1717
public canvas: fabric.Canvas;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pnpm-workspace.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages:
2+
- 'packages/*'

0 commit comments

Comments
 (0)