@hprint/plugins 0.0.7 → 0.0.8

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 (37) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.mjs +1 -1
  3. package/package.json +3 -3
  4. package/src/assets/style/resizePlugin.css +27 -27
  5. package/src/objects/Arrow.js +47 -47
  6. package/src/objects/ThinTailArrow.js +50 -50
  7. package/src/plugins/ControlsPlugin.ts +413 -413
  8. package/src/plugins/ControlsRotatePlugin.ts +111 -111
  9. package/src/plugins/CopyPlugin.ts +261 -261
  10. package/src/plugins/DeleteHotKeyPlugin.ts +57 -57
  11. package/src/plugins/DrawLinePlugin.ts +162 -162
  12. package/src/plugins/DrawPolygonPlugin.ts +205 -205
  13. package/src/plugins/DringPlugin.ts +125 -125
  14. package/src/plugins/FlipPlugin.ts +59 -59
  15. package/src/plugins/FontPlugin.ts +165 -165
  16. package/src/plugins/FreeDrawPlugin.ts +49 -49
  17. package/src/plugins/GroupPlugin.ts +82 -82
  18. package/src/plugins/GroupTextEditorPlugin.ts +198 -198
  19. package/src/plugins/HistoryPlugin.ts +181 -181
  20. package/src/plugins/ImageStroke.ts +121 -121
  21. package/src/plugins/LayerPlugin.ts +108 -108
  22. package/src/plugins/MaskPlugin.ts +155 -155
  23. package/src/plugins/MaterialPlugin.ts +224 -224
  24. package/src/plugins/MiddleMousePlugin.ts +45 -45
  25. package/src/plugins/MoveHotKeyPlugin.ts +46 -46
  26. package/src/plugins/PathTextPlugin.ts +89 -89
  27. package/src/plugins/PolygonModifyPlugin.ts +224 -224
  28. package/src/plugins/PrintPlugin.ts +81 -81
  29. package/src/plugins/PsdPlugin.ts +52 -52
  30. package/src/plugins/SimpleClipImagePlugin.ts +244 -244
  31. package/src/types/eventType.ts +11 -11
  32. package/src/utils/psd.js +432 -432
  33. package/src/utils/ruler/guideline.ts +145 -145
  34. package/src/utils/ruler/index.ts +91 -91
  35. package/src/utils/ruler/utils.ts +162 -162
  36. package/tsconfig.json +10 -10
  37. package/vite.config.ts +29 -29
@@ -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;