@hprint/plugins 0.0.1-alpha.3 → 0.0.1-alpha.4

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 (50) hide show
  1. package/dist/index.js +17 -17
  2. package/dist/index.mjs +1282 -1277
  3. package/dist/src/plugins/CreateElementPlugin.d.ts +4 -0
  4. package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -1
  5. package/dist/src/utils/ruler/ruler.d.ts +1 -0
  6. package/dist/src/utils/ruler/ruler.d.ts.map +1 -1
  7. package/package.json +3 -3
  8. package/src/assets/style/resizePlugin.css +27 -27
  9. package/src/objects/Arrow.js +47 -47
  10. package/src/objects/ThinTailArrow.js +50 -50
  11. package/src/plugins/AlignGuidLinePlugin.ts +1152 -1152
  12. package/src/plugins/ControlsPlugin.ts +251 -251
  13. package/src/plugins/ControlsRotatePlugin.ts +111 -111
  14. package/src/plugins/CopyPlugin.ts +255 -255
  15. package/src/plugins/CreateElementPlugin.ts +23 -2
  16. package/src/plugins/DeleteHotKeyPlugin.ts +57 -57
  17. package/src/plugins/DrawLinePlugin.ts +162 -162
  18. package/src/plugins/DrawPolygonPlugin.ts +205 -205
  19. package/src/plugins/DringPlugin.ts +125 -125
  20. package/src/plugins/FlipPlugin.ts +59 -59
  21. package/src/plugins/FontPlugin.ts +165 -165
  22. package/src/plugins/FreeDrawPlugin.ts +49 -49
  23. package/src/plugins/GroupAlignPlugin.ts +365 -365
  24. package/src/plugins/GroupPlugin.ts +82 -82
  25. package/src/plugins/GroupTextEditorPlugin.ts +198 -198
  26. package/src/plugins/HistoryPlugin.ts +181 -181
  27. package/src/plugins/ImageStroke.ts +121 -121
  28. package/src/plugins/LayerPlugin.ts +108 -108
  29. package/src/plugins/LockPlugin.ts +242 -242
  30. package/src/plugins/MaskPlugin.ts +155 -155
  31. package/src/plugins/MaterialPlugin.ts +224 -224
  32. package/src/plugins/MiddleMousePlugin.ts +45 -45
  33. package/src/plugins/MoveHotKeyPlugin.ts +46 -46
  34. package/src/plugins/PathTextPlugin.ts +89 -89
  35. package/src/plugins/PolygonModifyPlugin.ts +224 -224
  36. package/src/plugins/PrintPlugin.ts +81 -81
  37. package/src/plugins/PsdPlugin.ts +52 -52
  38. package/src/plugins/ResizePlugin.ts +278 -278
  39. package/src/plugins/RulerPlugin.ts +78 -78
  40. package/src/plugins/SimpleClipImagePlugin.ts +244 -244
  41. package/src/plugins/UnitPlugin.ts +326 -326
  42. package/src/plugins/WaterMarkPlugin.ts +257 -257
  43. package/src/types/eventType.ts +11 -11
  44. package/src/utils/psd.js +432 -432
  45. package/src/utils/ruler/guideline.ts +145 -145
  46. package/src/utils/ruler/index.ts +91 -91
  47. package/src/utils/ruler/ruler.ts +936 -924
  48. package/src/utils/ruler/utils.ts +162 -162
  49. package/tsconfig.json +10 -10
  50. package/vite.config.ts +29 -29
@@ -1,57 +1,57 @@
1
- import { fabric } from '@hprint/core';
2
- import type { IEditor, IPluginTempl } from '@hprint/core';
3
-
4
- type IPlugin = Pick<DeleteHotKeyPlugin, 'del'>;
5
-
6
- declare module '@hprint/core' {
7
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
8
- interface IEditor extends IPlugin {}
9
- }
10
-
11
- class DeleteHotKeyPlugin implements IPluginTempl {
12
- static pluginName = 'DeleteHotKeyPlugin';
13
- static apis = ['del'];
14
- hotkeys: string[] = ['backspace'];
15
- constructor(
16
- public canvas: fabric.Canvas,
17
- public editor: IEditor
18
- ) {}
19
-
20
- // 快捷键扩展回调
21
- hotkeyEvent(eventName: string, e: KeyboardEvent) {
22
- if (e.type === 'keydown' && eventName === 'backspace') {
23
- this.del();
24
- }
25
- }
26
-
27
- del() {
28
- const { canvas } = this;
29
- const activeObject = canvas.getActiveObjects();
30
- if (activeObject) {
31
- activeObject.map((item) => canvas.remove(item));
32
- canvas.requestRenderAll();
33
- canvas.discardActiveObject();
34
- }
35
- }
36
-
37
- contextMenu() {
38
- const activeObject = this.canvas.getActiveObject();
39
- if (activeObject) {
40
- return [
41
- null,
42
- {
43
- text: '删除',
44
- hotkey: 'Backspace',
45
- disabled: false,
46
- onclick: () => this.del(),
47
- },
48
- ];
49
- }
50
- }
51
-
52
- destroy() {
53
- console.log('pluginDestroy');
54
- }
55
- }
56
-
57
- export default DeleteHotKeyPlugin;
1
+ import { fabric } from '@hprint/core';
2
+ import type { IEditor, IPluginTempl } from '@hprint/core';
3
+
4
+ type IPlugin = Pick<DeleteHotKeyPlugin, 'del'>;
5
+
6
+ declare module '@hprint/core' {
7
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
8
+ interface IEditor extends IPlugin {}
9
+ }
10
+
11
+ class DeleteHotKeyPlugin implements IPluginTempl {
12
+ static pluginName = 'DeleteHotKeyPlugin';
13
+ static apis = ['del'];
14
+ hotkeys: string[] = ['backspace'];
15
+ constructor(
16
+ public canvas: fabric.Canvas,
17
+ public editor: IEditor
18
+ ) {}
19
+
20
+ // 快捷键扩展回调
21
+ hotkeyEvent(eventName: string, e: KeyboardEvent) {
22
+ if (e.type === 'keydown' && eventName === 'backspace') {
23
+ this.del();
24
+ }
25
+ }
26
+
27
+ del() {
28
+ const { canvas } = this;
29
+ const activeObject = canvas.getActiveObjects();
30
+ if (activeObject) {
31
+ activeObject.map((item) => canvas.remove(item));
32
+ canvas.requestRenderAll();
33
+ canvas.discardActiveObject();
34
+ }
35
+ }
36
+
37
+ contextMenu() {
38
+ const activeObject = this.canvas.getActiveObject();
39
+ if (activeObject) {
40
+ return [
41
+ null,
42
+ {
43
+ text: '删除',
44
+ hotkey: 'Backspace',
45
+ disabled: false,
46
+ onclick: () => this.del(),
47
+ },
48
+ ];
49
+ }
50
+ }
51
+
52
+ destroy() {
53
+ console.log('pluginDestroy');
54
+ }
55
+ }
56
+
57
+ export default DeleteHotKeyPlugin;
@@ -1,162 +1,162 @@
1
- import { v4 as uuid } from 'uuid';
2
- import { fabric } from '@hprint/core';
3
- import Arrow from '../objects/Arrow';
4
- import ThinTailArrow from '../objects/ThinTailArrow';
5
- import type { IEditor, IPluginTempl } from '@hprint/core';
6
-
7
- type IPlugin = Pick<DrawLinePlugin, 'setLineType' | 'setMode'>;
8
-
9
- declare module '@hprint/core' {
10
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
11
- interface IEditor extends IPlugin {}
12
- }
13
-
14
- class DrawLinePlugin implements IPluginTempl {
15
- static pluginName = 'DrawLinePlugin';
16
- static apis = ['setLineType', 'setMode'];
17
- isDrawingLineMode: boolean;
18
- lineType: string;
19
- lineToDraw: any;
20
- pointer: any;
21
- pointerPoints: any;
22
- isDrawingLine: boolean;
23
- constructor(
24
- public canvas: fabric.Canvas,
25
- public editor: IEditor
26
- ) {
27
- this.isDrawingLine = false;
28
- this.isDrawingLineMode = false;
29
- this.lineType = '';
30
- this.lineToDraw = null;
31
- this.pointer = null;
32
- this.pointerPoints = null;
33
- this.init();
34
- }
35
-
36
- init() {
37
- const { canvas } = this;
38
- canvas.on('mouse:down', (o) => {
39
- if (!this.isDrawingLineMode) return;
40
- canvas.discardActiveObject();
41
- canvas.getObjects().forEach((obj) => {
42
- obj.selectable = false;
43
- obj.hasControls = false;
44
- });
45
- canvas.requestRenderAll();
46
- this.isDrawingLine = true;
47
- this.pointer = canvas.getPointer(o.e);
48
- this.pointerPoints = [
49
- this.pointer.x,
50
- this.pointer.y,
51
- this.pointer.x,
52
- this.pointer.y,
53
- ];
54
- let NodeHandler;
55
- let opts: any = {
56
- strokeWidth: 2,
57
- stroke: '#000000',
58
- id: uuid(),
59
- };
60
- switch (this.lineType) {
61
- case 'line':
62
- NodeHandler = fabric.Line;
63
- break;
64
- case 'arrow':
65
- NodeHandler = Arrow;
66
- break;
67
- case 'thinTailArrow':
68
- NodeHandler = ThinTailArrow;
69
- opts = {
70
- strokeWidth: 2,
71
- stroke: '#ff0000',
72
- fill: '#ff0000',
73
- id: uuid(),
74
- };
75
- break;
76
- default:
77
- break;
78
- }
79
- if (!NodeHandler) throw new Error('Draw failed: invalid lineType.');
80
-
81
- this.lineToDraw = new NodeHandler(this.pointerPoints, opts);
82
-
83
- this.lineToDraw.selectable = false;
84
- this.lineToDraw.evented = false;
85
- this.lineToDraw.strokeUniform = true;
86
- canvas.add(this.lineToDraw);
87
- });
88
-
89
- canvas.on('mouse:move', (o) => {
90
- if (
91
- !this.isDrawingLine ||
92
- !['line', 'arrow', 'thinTailArrow'].includes(this.lineType)
93
- )
94
- return;
95
- canvas.discardActiveObject();
96
- const activeObject = canvas.getActiveObject();
97
- if (activeObject) return;
98
- this.pointer = canvas.getPointer(o.e);
99
-
100
- if (o.e.shiftKey) {
101
- // calc angle
102
- const startX = this.pointerPoints[0];
103
- const startY = this.pointerPoints[1];
104
- const x2 = this.pointer.x - startX;
105
- const y2 = this.pointer.y - startY;
106
- const r = Math.sqrt(x2 * x2 + y2 * y2);
107
- let angle = (Math.atan2(y2, x2) / Math.PI) * 180;
108
- angle = ~~(((angle + 7.5) % 360) / 15) * 15;
109
-
110
- const cosx = r * Math.cos((angle * Math.PI) / 180);
111
- const sinx = r * Math.sin((angle * Math.PI) / 180);
112
-
113
- this.lineToDraw.set({
114
- x2: cosx + startX,
115
- y2: sinx + startY,
116
- });
117
- } else {
118
- this.lineToDraw.set({
119
- x2: this.pointer.x,
120
- y2: this.pointer.y,
121
- });
122
- }
123
-
124
- canvas.renderAll();
125
- });
126
-
127
- canvas.on('mouse:up', () => {
128
- if (!this.isDrawingLine) return;
129
- this.lineToDraw.setCoords();
130
- this.isDrawingLine = false;
131
- canvas.discardActiveObject();
132
- canvas.renderAll();
133
- this.editor.saveState();
134
- });
135
- }
136
-
137
- setLineType(params: any) {
138
- this.lineType = params;
139
- }
140
-
141
- setMode(params: any) {
142
- this.isDrawingLineMode = params;
143
- if (!this.isDrawingLineMode) {
144
- this.endRest();
145
- }
146
- }
147
-
148
- endRest() {
149
- this.canvas.getObjects().forEach((obj) => {
150
- if (obj.id !== 'workspace') {
151
- obj.selectable = true;
152
- obj.hasControls = true;
153
- }
154
- });
155
- }
156
-
157
- destroy() {
158
- console.log('pluginDestroy');
159
- }
160
- }
161
-
162
- export default DrawLinePlugin;
1
+ import { v4 as uuid } from 'uuid';
2
+ import { fabric } from '@hprint/core';
3
+ import Arrow from '../objects/Arrow';
4
+ import ThinTailArrow from '../objects/ThinTailArrow';
5
+ import type { IEditor, IPluginTempl } from '@hprint/core';
6
+
7
+ type IPlugin = Pick<DrawLinePlugin, 'setLineType' | 'setMode'>;
8
+
9
+ declare module '@hprint/core' {
10
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
11
+ interface IEditor extends IPlugin {}
12
+ }
13
+
14
+ class DrawLinePlugin implements IPluginTempl {
15
+ static pluginName = 'DrawLinePlugin';
16
+ static apis = ['setLineType', 'setMode'];
17
+ isDrawingLineMode: boolean;
18
+ lineType: string;
19
+ lineToDraw: any;
20
+ pointer: any;
21
+ pointerPoints: any;
22
+ isDrawingLine: boolean;
23
+ constructor(
24
+ public canvas: fabric.Canvas,
25
+ public editor: IEditor
26
+ ) {
27
+ this.isDrawingLine = false;
28
+ this.isDrawingLineMode = false;
29
+ this.lineType = '';
30
+ this.lineToDraw = null;
31
+ this.pointer = null;
32
+ this.pointerPoints = null;
33
+ this.init();
34
+ }
35
+
36
+ init() {
37
+ const { canvas } = this;
38
+ canvas.on('mouse:down', (o) => {
39
+ if (!this.isDrawingLineMode) return;
40
+ canvas.discardActiveObject();
41
+ canvas.getObjects().forEach((obj) => {
42
+ obj.selectable = false;
43
+ obj.hasControls = false;
44
+ });
45
+ canvas.requestRenderAll();
46
+ this.isDrawingLine = true;
47
+ this.pointer = canvas.getPointer(o.e);
48
+ this.pointerPoints = [
49
+ this.pointer.x,
50
+ this.pointer.y,
51
+ this.pointer.x,
52
+ this.pointer.y,
53
+ ];
54
+ let NodeHandler;
55
+ let opts: any = {
56
+ strokeWidth: 2,
57
+ stroke: '#000000',
58
+ id: uuid(),
59
+ };
60
+ switch (this.lineType) {
61
+ case 'line':
62
+ NodeHandler = fabric.Line;
63
+ break;
64
+ case 'arrow':
65
+ NodeHandler = Arrow;
66
+ break;
67
+ case 'thinTailArrow':
68
+ NodeHandler = ThinTailArrow;
69
+ opts = {
70
+ strokeWidth: 2,
71
+ stroke: '#ff0000',
72
+ fill: '#ff0000',
73
+ id: uuid(),
74
+ };
75
+ break;
76
+ default:
77
+ break;
78
+ }
79
+ if (!NodeHandler) throw new Error('Draw failed: invalid lineType.');
80
+
81
+ this.lineToDraw = new NodeHandler(this.pointerPoints, opts);
82
+
83
+ this.lineToDraw.selectable = false;
84
+ this.lineToDraw.evented = false;
85
+ this.lineToDraw.strokeUniform = true;
86
+ canvas.add(this.lineToDraw);
87
+ });
88
+
89
+ canvas.on('mouse:move', (o) => {
90
+ if (
91
+ !this.isDrawingLine ||
92
+ !['line', 'arrow', 'thinTailArrow'].includes(this.lineType)
93
+ )
94
+ return;
95
+ canvas.discardActiveObject();
96
+ const activeObject = canvas.getActiveObject();
97
+ if (activeObject) return;
98
+ this.pointer = canvas.getPointer(o.e);
99
+
100
+ if (o.e.shiftKey) {
101
+ // calc angle
102
+ const startX = this.pointerPoints[0];
103
+ const startY = this.pointerPoints[1];
104
+ const x2 = this.pointer.x - startX;
105
+ const y2 = this.pointer.y - startY;
106
+ const r = Math.sqrt(x2 * x2 + y2 * y2);
107
+ let angle = (Math.atan2(y2, x2) / Math.PI) * 180;
108
+ angle = ~~(((angle + 7.5) % 360) / 15) * 15;
109
+
110
+ const cosx = r * Math.cos((angle * Math.PI) / 180);
111
+ const sinx = r * Math.sin((angle * Math.PI) / 180);
112
+
113
+ this.lineToDraw.set({
114
+ x2: cosx + startX,
115
+ y2: sinx + startY,
116
+ });
117
+ } else {
118
+ this.lineToDraw.set({
119
+ x2: this.pointer.x,
120
+ y2: this.pointer.y,
121
+ });
122
+ }
123
+
124
+ canvas.renderAll();
125
+ });
126
+
127
+ canvas.on('mouse:up', () => {
128
+ if (!this.isDrawingLine) return;
129
+ this.lineToDraw.setCoords();
130
+ this.isDrawingLine = false;
131
+ canvas.discardActiveObject();
132
+ canvas.renderAll();
133
+ this.editor.saveState();
134
+ });
135
+ }
136
+
137
+ setLineType(params: any) {
138
+ this.lineType = params;
139
+ }
140
+
141
+ setMode(params: any) {
142
+ this.isDrawingLineMode = params;
143
+ if (!this.isDrawingLineMode) {
144
+ this.endRest();
145
+ }
146
+ }
147
+
148
+ endRest() {
149
+ this.canvas.getObjects().forEach((obj) => {
150
+ if (obj.id !== 'workspace') {
151
+ obj.selectable = true;
152
+ obj.hasControls = true;
153
+ }
154
+ });
155
+ }
156
+
157
+ destroy() {
158
+ console.log('pluginDestroy');
159
+ }
160
+ }
161
+
162
+ export default DrawLinePlugin;