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

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 (64) hide show
  1. package/dist/index.js +122 -117
  2. package/dist/index.mjs +41257 -21115
  3. package/dist/src/plugins/AlignGuidLinePlugin.d.ts +7 -2
  4. package/dist/src/plugins/AlignGuidLinePlugin.d.ts.map +1 -1
  5. package/dist/src/plugins/BarCodePlugin.d.ts +4 -0
  6. package/dist/src/plugins/BarCodePlugin.d.ts.map +1 -1
  7. package/dist/src/plugins/CreateElementPlugin.d.ts +3 -9
  8. package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -1
  9. package/dist/src/plugins/GroupAlignPlugin.d.ts.map +1 -1
  10. package/dist/src/plugins/LockPlugin.d.ts.map +1 -1
  11. package/dist/src/plugins/QrCodePlugin.d.ts +19 -97
  12. package/dist/src/plugins/QrCodePlugin.d.ts.map +1 -1
  13. package/dist/src/plugins/ResizePlugin.d.ts.map +1 -1
  14. package/dist/src/plugins/UnitPlugin.d.ts.map +1 -1
  15. package/dist/src/plugins/WorkspacePlugin.d.ts.map +1 -1
  16. package/dist/src/utils/units.d.ts.map +1 -1
  17. package/package.json +5 -4
  18. package/src/assets/style/resizePlugin.css +27 -27
  19. package/src/objects/Arrow.js +47 -47
  20. package/src/objects/ThinTailArrow.js +50 -50
  21. package/src/plugins/AlignGuidLinePlugin.ts +1152 -1141
  22. package/src/plugins/BarCodePlugin.ts +33 -27
  23. package/src/plugins/ControlsPlugin.ts +251 -251
  24. package/src/plugins/ControlsRotatePlugin.ts +111 -111
  25. package/src/plugins/CopyPlugin.ts +255 -255
  26. package/src/plugins/CreateElementPlugin.ts +14 -10
  27. package/src/plugins/DeleteHotKeyPlugin.ts +57 -57
  28. package/src/plugins/DrawLinePlugin.ts +162 -162
  29. package/src/plugins/DrawPolygonPlugin.ts +205 -205
  30. package/src/plugins/DringPlugin.ts +125 -125
  31. package/src/plugins/FlipPlugin.ts +59 -59
  32. package/src/plugins/FontPlugin.ts +165 -165
  33. package/src/plugins/FreeDrawPlugin.ts +49 -49
  34. package/src/plugins/GroupAlignPlugin.ts +365 -365
  35. package/src/plugins/GroupPlugin.ts +82 -82
  36. package/src/plugins/GroupTextEditorPlugin.ts +198 -198
  37. package/src/plugins/HistoryPlugin.ts +181 -181
  38. package/src/plugins/ImageStroke.ts +121 -121
  39. package/src/plugins/LayerPlugin.ts +108 -108
  40. package/src/plugins/LockPlugin.ts +242 -240
  41. package/src/plugins/MaskPlugin.ts +155 -155
  42. package/src/plugins/MaterialPlugin.ts +224 -224
  43. package/src/plugins/MiddleMousePlugin.ts +45 -45
  44. package/src/plugins/MoveHotKeyPlugin.ts +46 -46
  45. package/src/plugins/PathTextPlugin.ts +89 -89
  46. package/src/plugins/PolygonModifyPlugin.ts +224 -224
  47. package/src/plugins/PrintPlugin.ts +81 -81
  48. package/src/plugins/PsdPlugin.ts +52 -52
  49. package/src/plugins/QrCodePlugin.ts +322 -393
  50. package/src/plugins/ResizePlugin.ts +278 -274
  51. package/src/plugins/RulerPlugin.ts +78 -78
  52. package/src/plugins/SimpleClipImagePlugin.ts +244 -244
  53. package/src/plugins/UnitPlugin.ts +326 -327
  54. package/src/plugins/WaterMarkPlugin.ts +257 -257
  55. package/src/plugins/WorkspacePlugin.ts +10 -6
  56. package/src/types/eventType.ts +11 -11
  57. package/src/utils/psd.js +432 -432
  58. package/src/utils/ruler/guideline.ts +145 -145
  59. package/src/utils/ruler/index.ts +91 -91
  60. package/src/utils/ruler/ruler.ts +924 -924
  61. package/src/utils/ruler/utils.ts +162 -162
  62. package/src/utils/units.ts +4 -2
  63. package/tsconfig.json +10 -10
  64. 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;