@hprint/plugins 0.0.7 → 0.0.9-alpha.0

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