@hprint/plugins 0.0.1-alpha.2 → 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 (53) hide show
  1. package/dist/index.js +17 -17
  2. package/dist/index.mjs +1071 -1057
  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/GroupAlignPlugin.d.ts.map +1 -1
  6. package/dist/src/plugins/LockPlugin.d.ts.map +1 -1
  7. package/dist/src/plugins/QrCodePlugin.d.ts +5 -0
  8. package/dist/src/plugins/QrCodePlugin.d.ts.map +1 -1
  9. package/package.json +3 -3
  10. package/src/assets/style/resizePlugin.css +27 -27
  11. package/src/objects/Arrow.js +47 -47
  12. package/src/objects/ThinTailArrow.js +50 -50
  13. package/src/plugins/AlignGuidLinePlugin.ts +1152 -1141
  14. package/src/plugins/BarCodePlugin.ts +2 -2
  15. package/src/plugins/ControlsPlugin.ts +251 -251
  16. package/src/plugins/ControlsRotatePlugin.ts +111 -111
  17. package/src/plugins/CopyPlugin.ts +255 -255
  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/GroupAlignPlugin.ts +365 -365
  26. package/src/plugins/GroupPlugin.ts +82 -82
  27. package/src/plugins/GroupTextEditorPlugin.ts +198 -198
  28. package/src/plugins/HistoryPlugin.ts +181 -181
  29. package/src/plugins/ImageStroke.ts +121 -121
  30. package/src/plugins/LayerPlugin.ts +108 -108
  31. package/src/plugins/LockPlugin.ts +242 -240
  32. package/src/plugins/MaskPlugin.ts +155 -155
  33. package/src/plugins/MaterialPlugin.ts +224 -224
  34. package/src/plugins/MiddleMousePlugin.ts +45 -45
  35. package/src/plugins/MoveHotKeyPlugin.ts +46 -46
  36. package/src/plugins/PathTextPlugin.ts +89 -89
  37. package/src/plugins/PolygonModifyPlugin.ts +224 -224
  38. package/src/plugins/PrintPlugin.ts +81 -81
  39. package/src/plugins/PsdPlugin.ts +52 -52
  40. package/src/plugins/QrCodePlugin.ts +322 -329
  41. package/src/plugins/ResizePlugin.ts +278 -278
  42. package/src/plugins/RulerPlugin.ts +78 -78
  43. package/src/plugins/SimpleClipImagePlugin.ts +244 -244
  44. package/src/plugins/UnitPlugin.ts +326 -326
  45. package/src/plugins/WaterMarkPlugin.ts +257 -257
  46. package/src/types/eventType.ts +11 -11
  47. package/src/utils/psd.js +432 -432
  48. package/src/utils/ruler/guideline.ts +145 -145
  49. package/src/utils/ruler/index.ts +91 -91
  50. package/src/utils/ruler/ruler.ts +924 -924
  51. package/src/utils/ruler/utils.ts +162 -162
  52. package/tsconfig.json +10 -10
  53. package/vite.config.ts +29 -29
@@ -1,111 +1,111 @@
1
- import { fabric } from '@hprint/core';
2
- import type { IEditor, IPluginTempl } from '@hprint/core';
3
-
4
- // 定义旋转光标样式,根据转动角度设定光标旋转
5
- function rotateIcon(angle: number) {
6
- return `url("data:image/svg+xml,%3Csvg height='18' width='18' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: black;'%3E%3Cg fill='none' transform='rotate(${angle} 16 16)'%3E%3Cpath d='M22.4484 0L32 9.57891L22.4484 19.1478V13.1032C17.6121 13.8563 13.7935 17.6618 13.0479 22.4914H19.2141L9.60201 32.01L0 22.4813H6.54912C7.36524 14.1073 14.0453 7.44023 22.4484 6.61688V0Z' fill='white'/%3E%3Cpath d='M24.0605 3.89587L29.7229 9.57896L24.0605 15.252V11.3562C17.0479 11.4365 11.3753 17.0895 11.3048 24.0879H15.3048L9.60201 29.7308L3.90932 24.0879H8.0806C8.14106 15.3223 15.2645 8.22345 24.0605 8.14313V3.89587Z' fill='black'/%3E%3C/g%3E%3C/svg%3E ") 12 12,crosshair`;
7
- }
8
-
9
- class ControlsRotatePlugin implements IPluginTempl {
10
- static pluginName = 'ControlsRotatePlugin';
11
- constructor(
12
- public canvas: fabric.Canvas,
13
- public editor: IEditor
14
- ) {
15
- this.init();
16
- }
17
- init() {
18
- const { canvas } = this;
19
- // 添加旋转控制响应区域
20
- fabric.Object.prototype.controls.mtr = new fabric.Control({
21
- x: -0.5,
22
- y: -0.5,
23
- offsetY: -10,
24
- offsetX: -10,
25
- rotate: 20,
26
- actionName: 'rotate',
27
- actionHandler: fabric.controlsUtils.rotationWithSnapping,
28
- render: () => '',
29
- });
30
- // ↖左上
31
- fabric.Object.prototype.controls.mtr2 = new fabric.Control({
32
- x: 0.5,
33
- y: -0.5,
34
- offsetY: -10,
35
- offsetX: 10,
36
- rotate: 20,
37
- actionName: 'rotate',
38
- actionHandler: fabric.controlsUtils.rotationWithSnapping,
39
- render: () => '',
40
- }); // ↗右上
41
- fabric.Object.prototype.controls.mtr3 = new fabric.Control({
42
- x: 0.5,
43
- y: 0.5,
44
- offsetY: 10,
45
- offsetX: 10,
46
- rotate: 20,
47
- actionName: 'rotate',
48
- actionHandler: fabric.controlsUtils.rotationWithSnapping,
49
- render: () => '',
50
- }); // ↘右下
51
- fabric.Object.prototype.controls.mtr4 = new fabric.Control({
52
- x: -0.5,
53
- y: 0.5,
54
- offsetY: 10,
55
- offsetX: -10,
56
- rotate: 20,
57
- actionName: 'rotate',
58
- actionHandler: fabric.controlsUtils.rotationWithSnapping,
59
- render: () => '',
60
- }); // ↙左下
61
-
62
- // 渲染时,执行
63
- canvas.on('after:render', () => {
64
- const activeObj = canvas.getActiveObject();
65
- const angle = activeObj?.angle?.toFixed(2);
66
- if (angle !== undefined) {
67
- fabric.Object.prototype.controls.mtr.cursorStyle = rotateIcon(
68
- Number(angle)
69
- );
70
- fabric.Object.prototype.controls.mtr2.cursorStyle = rotateIcon(
71
- Number(angle) + 90
72
- );
73
- fabric.Object.prototype.controls.mtr3.cursorStyle = rotateIcon(
74
- Number(angle) + 180
75
- );
76
- fabric.Object.prototype.controls.mtr4.cursorStyle = rotateIcon(
77
- Number(angle) + 270
78
- );
79
- }
80
- });
81
-
82
- // 旋转时,实时更新旋转控制图标
83
- canvas.on('object:rotating', (event) => {
84
- const body = canvas.lowerCanvasEl.nextSibling as HTMLElement;
85
- const angle = canvas.getActiveObject()?.angle?.toFixed(2);
86
- if (angle === undefined) return;
87
- switch (event.transform?.corner) {
88
- case 'mtr':
89
- body.style.cursor = rotateIcon(Number(angle));
90
- break;
91
- case 'mtr2':
92
- body.style.cursor = rotateIcon(Number(angle) + 90);
93
- break;
94
- case 'mtr3':
95
- body.style.cursor = rotateIcon(Number(angle) + 180);
96
- break;
97
- case 'mtr4':
98
- body.style.cursor = rotateIcon(Number(angle) + 270);
99
- break;
100
- default:
101
- break;
102
- } // 设置四角旋转光标
103
- });
104
- }
105
-
106
- destroy() {
107
- console.log('pluginDestroy');
108
- }
109
- }
110
-
111
- export default ControlsRotatePlugin;
1
+ import { fabric } from '@hprint/core';
2
+ import type { IEditor, IPluginTempl } from '@hprint/core';
3
+
4
+ // 定义旋转光标样式,根据转动角度设定光标旋转
5
+ function rotateIcon(angle: number) {
6
+ return `url("data:image/svg+xml,%3Csvg height='18' width='18' viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg' style='color: black;'%3E%3Cg fill='none' transform='rotate(${angle} 16 16)'%3E%3Cpath d='M22.4484 0L32 9.57891L22.4484 19.1478V13.1032C17.6121 13.8563 13.7935 17.6618 13.0479 22.4914H19.2141L9.60201 32.01L0 22.4813H6.54912C7.36524 14.1073 14.0453 7.44023 22.4484 6.61688V0Z' fill='white'/%3E%3Cpath d='M24.0605 3.89587L29.7229 9.57896L24.0605 15.252V11.3562C17.0479 11.4365 11.3753 17.0895 11.3048 24.0879H15.3048L9.60201 29.7308L3.90932 24.0879H8.0806C8.14106 15.3223 15.2645 8.22345 24.0605 8.14313V3.89587Z' fill='black'/%3E%3C/g%3E%3C/svg%3E ") 12 12,crosshair`;
7
+ }
8
+
9
+ class ControlsRotatePlugin implements IPluginTempl {
10
+ static pluginName = 'ControlsRotatePlugin';
11
+ constructor(
12
+ public canvas: fabric.Canvas,
13
+ public editor: IEditor
14
+ ) {
15
+ this.init();
16
+ }
17
+ init() {
18
+ const { canvas } = this;
19
+ // 添加旋转控制响应区域
20
+ fabric.Object.prototype.controls.mtr = new fabric.Control({
21
+ x: -0.5,
22
+ y: -0.5,
23
+ offsetY: -10,
24
+ offsetX: -10,
25
+ rotate: 20,
26
+ actionName: 'rotate',
27
+ actionHandler: fabric.controlsUtils.rotationWithSnapping,
28
+ render: () => '',
29
+ });
30
+ // ↖左上
31
+ fabric.Object.prototype.controls.mtr2 = new fabric.Control({
32
+ x: 0.5,
33
+ y: -0.5,
34
+ offsetY: -10,
35
+ offsetX: 10,
36
+ rotate: 20,
37
+ actionName: 'rotate',
38
+ actionHandler: fabric.controlsUtils.rotationWithSnapping,
39
+ render: () => '',
40
+ }); // ↗右上
41
+ fabric.Object.prototype.controls.mtr3 = new fabric.Control({
42
+ x: 0.5,
43
+ y: 0.5,
44
+ offsetY: 10,
45
+ offsetX: 10,
46
+ rotate: 20,
47
+ actionName: 'rotate',
48
+ actionHandler: fabric.controlsUtils.rotationWithSnapping,
49
+ render: () => '',
50
+ }); // ↘右下
51
+ fabric.Object.prototype.controls.mtr4 = new fabric.Control({
52
+ x: -0.5,
53
+ y: 0.5,
54
+ offsetY: 10,
55
+ offsetX: -10,
56
+ rotate: 20,
57
+ actionName: 'rotate',
58
+ actionHandler: fabric.controlsUtils.rotationWithSnapping,
59
+ render: () => '',
60
+ }); // ↙左下
61
+
62
+ // 渲染时,执行
63
+ canvas.on('after:render', () => {
64
+ const activeObj = canvas.getActiveObject();
65
+ const angle = activeObj?.angle?.toFixed(2);
66
+ if (angle !== undefined) {
67
+ fabric.Object.prototype.controls.mtr.cursorStyle = rotateIcon(
68
+ Number(angle)
69
+ );
70
+ fabric.Object.prototype.controls.mtr2.cursorStyle = rotateIcon(
71
+ Number(angle) + 90
72
+ );
73
+ fabric.Object.prototype.controls.mtr3.cursorStyle = rotateIcon(
74
+ Number(angle) + 180
75
+ );
76
+ fabric.Object.prototype.controls.mtr4.cursorStyle = rotateIcon(
77
+ Number(angle) + 270
78
+ );
79
+ }
80
+ });
81
+
82
+ // 旋转时,实时更新旋转控制图标
83
+ canvas.on('object:rotating', (event) => {
84
+ const body = canvas.lowerCanvasEl.nextSibling as HTMLElement;
85
+ const angle = canvas.getActiveObject()?.angle?.toFixed(2);
86
+ if (angle === undefined) return;
87
+ switch (event.transform?.corner) {
88
+ case 'mtr':
89
+ body.style.cursor = rotateIcon(Number(angle));
90
+ break;
91
+ case 'mtr2':
92
+ body.style.cursor = rotateIcon(Number(angle) + 90);
93
+ break;
94
+ case 'mtr3':
95
+ body.style.cursor = rotateIcon(Number(angle) + 180);
96
+ break;
97
+ case 'mtr4':
98
+ body.style.cursor = rotateIcon(Number(angle) + 270);
99
+ break;
100
+ default:
101
+ break;
102
+ } // 设置四角旋转光标
103
+ });
104
+ }
105
+
106
+ destroy() {
107
+ console.log('pluginDestroy');
108
+ }
109
+ }
110
+
111
+ export default ControlsRotatePlugin;