@hprint/plugins 0.0.1-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 (153) hide show
  1. package/dist/index.css +1 -0
  2. package/dist/index.js +478 -0
  3. package/dist/index.mjs +41731 -0
  4. package/dist/src/index.d.ts +8 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/src/objects/Arrow.d.ts +2 -0
  7. package/dist/src/objects/Arrow.d.ts.map +1 -0
  8. package/dist/src/objects/ThinTailArrow.d.ts +2 -0
  9. package/dist/src/objects/ThinTailArrow.d.ts.map +1 -0
  10. package/dist/src/plugins/AddBaseTypePlugin.d.ts +26 -0
  11. package/dist/src/plugins/AddBaseTypePlugin.d.ts.map +1 -0
  12. package/dist/src/plugins/AlignGuidLinePlugin.d.ts +16 -0
  13. package/dist/src/plugins/AlignGuidLinePlugin.d.ts.map +1 -0
  14. package/dist/src/plugins/BarCodePlugin.d.ts +68 -0
  15. package/dist/src/plugins/BarCodePlugin.d.ts.map +1 -0
  16. package/dist/src/plugins/CenterAlignPlugin.d.ts +29 -0
  17. package/dist/src/plugins/CenterAlignPlugin.d.ts.map +1 -0
  18. package/dist/src/plugins/ControlsPlugin.d.ts +11 -0
  19. package/dist/src/plugins/ControlsPlugin.d.ts.map +1 -0
  20. package/dist/src/plugins/ControlsRotatePlugin.d.ts +11 -0
  21. package/dist/src/plugins/ControlsRotatePlugin.d.ts.map +1 -0
  22. package/dist/src/plugins/CopyPlugin.d.ts +30 -0
  23. package/dist/src/plugins/CopyPlugin.d.ts.map +1 -0
  24. package/dist/src/plugins/CreateElementPlugin.d.ts +121 -0
  25. package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -0
  26. package/dist/src/plugins/DeleteHotKeyPlugin.d.ts +25 -0
  27. package/dist/src/plugins/DeleteHotKeyPlugin.d.ts.map +1 -0
  28. package/dist/src/plugins/DrawLinePlugin.d.ts +26 -0
  29. package/dist/src/plugins/DrawLinePlugin.d.ts.map +1 -0
  30. package/dist/src/plugins/DrawPolygonPlugin.d.ts +41 -0
  31. package/dist/src/plugins/DrawPolygonPlugin.d.ts.map +1 -0
  32. package/dist/src/plugins/DringPlugin.d.ts +33 -0
  33. package/dist/src/plugins/DringPlugin.d.ts.map +1 -0
  34. package/dist/src/plugins/FlipPlugin.d.ts +26 -0
  35. package/dist/src/plugins/FlipPlugin.d.ts.map +1 -0
  36. package/dist/src/plugins/FontPlugin.d.ts +33 -0
  37. package/dist/src/plugins/FontPlugin.d.ts.map +1 -0
  38. package/dist/src/plugins/FreeDrawPlugin.d.ts +23 -0
  39. package/dist/src/plugins/FreeDrawPlugin.d.ts.map +1 -0
  40. package/dist/src/plugins/GroupAlignPlugin.d.ts +24 -0
  41. package/dist/src/plugins/GroupAlignPlugin.d.ts.map +1 -0
  42. package/dist/src/plugins/GroupPlugin.d.ts +24 -0
  43. package/dist/src/plugins/GroupPlugin.d.ts.map +1 -0
  44. package/dist/src/plugins/GroupTextEditorPlugin.d.ts +18 -0
  45. package/dist/src/plugins/GroupTextEditorPlugin.d.ts.map +1 -0
  46. package/dist/src/plugins/HistoryPlugin.d.ts +30 -0
  47. package/dist/src/plugins/HistoryPlugin.d.ts.map +1 -0
  48. package/dist/src/plugins/ImageStroke.d.ts +18 -0
  49. package/dist/src/plugins/ImageStroke.d.ts.map +1 -0
  50. package/dist/src/plugins/LayerPlugin.d.ts +31 -0
  51. package/dist/src/plugins/LayerPlugin.d.ts.map +1 -0
  52. package/dist/src/plugins/LockPlugin.d.ts +27 -0
  53. package/dist/src/plugins/LockPlugin.d.ts.map +1 -0
  54. package/dist/src/plugins/MaskPlugin.d.ts +38 -0
  55. package/dist/src/plugins/MaskPlugin.d.ts.map +1 -0
  56. package/dist/src/plugins/MaterialPlugin.d.ts +45 -0
  57. package/dist/src/plugins/MaterialPlugin.d.ts.map +1 -0
  58. package/dist/src/plugins/MiddleMousePlugin.d.ts +18 -0
  59. package/dist/src/plugins/MiddleMousePlugin.d.ts.map +1 -0
  60. package/dist/src/plugins/MoveHotKeyPlugin.d.ts +12 -0
  61. package/dist/src/plugins/MoveHotKeyPlugin.d.ts.map +1 -0
  62. package/dist/src/plugins/PathTextPlugin.d.ts +30 -0
  63. package/dist/src/plugins/PathTextPlugin.d.ts.map +1 -0
  64. package/dist/src/plugins/PolygonModifyPlugin.d.ts +28 -0
  65. package/dist/src/plugins/PolygonModifyPlugin.d.ts.map +1 -0
  66. package/dist/src/plugins/PrintPlugin.d.ts +39 -0
  67. package/dist/src/plugins/PrintPlugin.d.ts.map +1 -0
  68. package/dist/src/plugins/PsdPlugin.d.ts +17 -0
  69. package/dist/src/plugins/PsdPlugin.d.ts.map +1 -0
  70. package/dist/src/plugins/QrCodePlugin.d.ts +137 -0
  71. package/dist/src/plugins/QrCodePlugin.d.ts.map +1 -0
  72. package/dist/src/plugins/ResizePlugin.d.ts +44 -0
  73. package/dist/src/plugins/ResizePlugin.d.ts.map +1 -0
  74. package/dist/src/plugins/RulerPlugin.d.ts +24 -0
  75. package/dist/src/plugins/RulerPlugin.d.ts.map +1 -0
  76. package/dist/src/plugins/SimpleClipImagePlugin.d.ts +18 -0
  77. package/dist/src/plugins/SimpleClipImagePlugin.d.ts.map +1 -0
  78. package/dist/src/plugins/UnitPlugin.d.ts +84 -0
  79. package/dist/src/plugins/UnitPlugin.d.ts.map +1 -0
  80. package/dist/src/plugins/WaterMarkPlugin.d.ts +40 -0
  81. package/dist/src/plugins/WaterMarkPlugin.d.ts.map +1 -0
  82. package/dist/src/plugins/WorkspacePlugin.d.ts +57 -0
  83. package/dist/src/plugins/WorkspacePlugin.d.ts.map +1 -0
  84. package/dist/src/types/eventType.d.ts +11 -0
  85. package/dist/src/types/eventType.d.ts.map +1 -0
  86. package/dist/src/utils/psd.d.ts +3 -0
  87. package/dist/src/utils/psd.d.ts.map +1 -0
  88. package/dist/src/utils/ruler/guideline.d.ts +4 -0
  89. package/dist/src/utils/ruler/guideline.d.ts.map +1 -0
  90. package/dist/src/utils/ruler/index.d.ts +5 -0
  91. package/dist/src/utils/ruler/index.d.ts.map +1 -0
  92. package/dist/src/utils/ruler/ruler.d.ts +147 -0
  93. package/dist/src/utils/ruler/ruler.d.ts.map +1 -0
  94. package/dist/src/utils/ruler/utils.d.ts +50 -0
  95. package/dist/src/utils/ruler/utils.d.ts.map +1 -0
  96. package/dist/src/utils/units.d.ts +22 -0
  97. package/dist/src/utils/units.d.ts.map +1 -0
  98. package/package.json +51 -0
  99. package/src/assets/edgecontrol.svg +17 -0
  100. package/src/assets/lock.svg +7 -0
  101. package/src/assets/middlecontrol.svg +17 -0
  102. package/src/assets/middlecontrolhoz.svg +17 -0
  103. package/src/assets/rotateicon.svg +20 -0
  104. package/src/assets/style/resizePlugin.css +27 -0
  105. package/src/index.ts +121 -0
  106. package/src/objects/Arrow.js +47 -0
  107. package/src/objects/ThinTailArrow.js +50 -0
  108. package/src/plugins/AddBaseTypePlugin.ts +107 -0
  109. package/src/plugins/AlignGuidLinePlugin.ts +1141 -0
  110. package/src/plugins/BarCodePlugin.ts +860 -0
  111. package/src/plugins/CenterAlignPlugin.ts +133 -0
  112. package/src/plugins/ControlsPlugin.ts +251 -0
  113. package/src/plugins/ControlsRotatePlugin.ts +111 -0
  114. package/src/plugins/CopyPlugin.ts +255 -0
  115. package/src/plugins/CreateElementPlugin.ts +548 -0
  116. package/src/plugins/DeleteHotKeyPlugin.ts +57 -0
  117. package/src/plugins/DrawLinePlugin.ts +162 -0
  118. package/src/plugins/DrawPolygonPlugin.ts +205 -0
  119. package/src/plugins/DringPlugin.ts +125 -0
  120. package/src/plugins/FlipPlugin.ts +59 -0
  121. package/src/plugins/FontPlugin.ts +165 -0
  122. package/src/plugins/FreeDrawPlugin.ts +49 -0
  123. package/src/plugins/GroupAlignPlugin.ts +365 -0
  124. package/src/plugins/GroupPlugin.ts +82 -0
  125. package/src/plugins/GroupTextEditorPlugin.ts +198 -0
  126. package/src/plugins/HistoryPlugin.ts +181 -0
  127. package/src/plugins/ImageStroke.ts +121 -0
  128. package/src/plugins/LayerPlugin.ts +108 -0
  129. package/src/plugins/LockPlugin.ts +240 -0
  130. package/src/plugins/MaskPlugin.ts +155 -0
  131. package/src/plugins/MaterialPlugin.ts +224 -0
  132. package/src/plugins/MiddleMousePlugin.ts +45 -0
  133. package/src/plugins/MoveHotKeyPlugin.ts +46 -0
  134. package/src/plugins/PathTextPlugin.ts +89 -0
  135. package/src/plugins/PolygonModifyPlugin.ts +224 -0
  136. package/src/plugins/PrintPlugin.ts +81 -0
  137. package/src/plugins/PsdPlugin.ts +52 -0
  138. package/src/plugins/QrCodePlugin.ts +393 -0
  139. package/src/plugins/ResizePlugin.ts +274 -0
  140. package/src/plugins/RulerPlugin.ts +78 -0
  141. package/src/plugins/SimpleClipImagePlugin.ts +244 -0
  142. package/src/plugins/UnitPlugin.ts +327 -0
  143. package/src/plugins/WaterMarkPlugin.ts +257 -0
  144. package/src/plugins/WorkspacePlugin.ts +307 -0
  145. package/src/types/eventType.ts +11 -0
  146. package/src/utils/psd.js +432 -0
  147. package/src/utils/ruler/guideline.ts +145 -0
  148. package/src/utils/ruler/index.ts +91 -0
  149. package/src/utils/ruler/ruler.ts +924 -0
  150. package/src/utils/ruler/utils.ts +162 -0
  151. package/src/utils/units.ts +133 -0
  152. package/tsconfig.json +10 -0
  153. package/vite.config.ts +29 -0
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
2
+ <svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
3
+ <path d="M12 22C17.5228 22 22 17.5228 22 12C22 6.47715 17.5228 2 12 2C6.47715 2 2 6.47715 2 12C2 17.5228 6.47715 22 12 22Z" stroke="black" fill="white" stroke-opacity="0.3" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
4
+ <path d="M9 11V10C9 8.34 9.5 7 12 7C14.5 7 15 8.34 15 10V11" stroke="#292D32" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
5
+ <path d="M12 14.6C12.3314 14.6 12.6 14.3314 12.6 14C12.6 13.6687 12.3314 13.4 12 13.4C11.6686 13.4 11.4 13.6687 11.4 14C11.4 14.3314 11.6686 14.6 12 14.6Z" stroke="#292D32" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
6
+ <path d="M14.5 17H9.5C7.5 17 7 16.5 7 14.5V13.5C7 11.5 7.5 11 9.5 11H14.5C16.5 11 17 11.5 17 13.5V14.5C17 16.5 16.5 17 14.5 17Z" stroke="#292D32" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
7
+ </svg>
@@ -0,0 +1,17 @@
1
+ <svg width="12" height="24" viewBox="0 0 12 24" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g filter="url(#filter0_d)">
3
+ <rect x="4" y="4" width="4" height="16" rx="2" fill="white"/>
4
+ <rect x="4.25" y="4.25" width="3.5" height="15.5" rx="1.75" stroke="black" stroke-opacity="0.3" stroke-width="0.5"/>
5
+ </g>
6
+ <defs>
7
+ <filter id="filter0_d" x="0" y="0" width="12" height="24" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
8
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
9
+ <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
10
+ <feOffset/>
11
+ <feGaussianBlur stdDeviation="2"/>
12
+ <feColorMatrix type="matrix" values="0 0 0 0 0.137674 0 0 0 0 0.190937 0 0 0 0 0.270833 0 0 0 0.15 0"/>
13
+ <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow"/>
14
+ <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>
15
+ </filter>
16
+ </defs>
17
+ </svg>
@@ -0,0 +1,17 @@
1
+ <svg width="24" height="12" viewBox="0 0 24 12" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g filter="url(#filter0_d)">
3
+ <rect x="20" y="4" width="4" height="16" rx="2" transform="rotate(90 20 4)" fill="white"/>
4
+ <rect x="19.75" y="4.25" width="3.5" height="15.5" rx="1.75" transform="rotate(90 19.75 4.25)" stroke="black" stroke-opacity="0.3" stroke-width="0.5"/>
5
+ </g>
6
+ <defs>
7
+ <filter id="filter0_d" x="0" y="0" width="24" height="12" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
8
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
9
+ <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
10
+ <feOffset/>
11
+ <feGaussianBlur stdDeviation="2"/>
12
+ <feColorMatrix type="matrix" values="0 0 0 0 0.137674 0 0 0 0 0.190937 0 0 0 0 0.270833 0 0 0 0.15 0"/>
13
+ <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow"/>
14
+ <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>
15
+ </filter>
16
+ </defs>
17
+ </svg>
@@ -0,0 +1,20 @@
1
+ <svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
2
+ <g filter="url(#filter0_d)">
3
+ <circle cx="9" cy="9" r="5" fill="white"/>
4
+ <circle cx="9" cy="9" r="4.75" stroke="black" stroke-opacity="0.3" stroke-width="0.5"/>
5
+ </g>
6
+ <path d="M10.8047 11.1242L9.49934 11.1242L9.49934 9.81885" stroke="black" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round"/>
7
+ <path d="M6.94856 6.72607L8.25391 6.72607L8.25391 8.03142" stroke="black" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round"/>
8
+ <path d="M9.69517 6.92267C10.007 7.03301 10.2858 7.22054 10.5055 7.46776C10.7252 7.71497 10.8787 8.01382 10.9517 8.33642C11.0247 8.65902 11.0148 8.99485 10.9229 9.31258C10.831 9.63031 10.6601 9.91958 10.4262 10.1534L9.49701 11.0421M8.25792 6.72607L7.30937 7.73554C7.07543 7.96936 6.90454 8.25863 6.81264 8.57636C6.72073 8.89408 6.71081 9.22992 6.78381 9.55251C6.8568 9.87511 7.01032 10.174 7.23005 10.4212C7.44978 10.6684 7.72855 10.8559 8.04036 10.9663" stroke="black" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round"/>
9
+ <defs>
10
+ <filter id="filter0_d" x="0" y="0" width="18" height="18" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
11
+ <feFlood flood-opacity="0" result="BackgroundImageFix"/>
12
+ <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
13
+ <feOffset/>
14
+ <feGaussianBlur stdDeviation="2"/>
15
+ <feColorMatrix type="matrix" values="0 0 0 0 0.137674 0 0 0 0 0.190937 0 0 0 0 0.270833 0 0 0 0.15 0"/>
16
+ <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow"/>
17
+ <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>
18
+ </filter>
19
+ </defs>
20
+ </svg>
@@ -0,0 +1,27 @@
1
+ .resize-bar {
2
+ border-radius: 3px;
3
+ background-color: rgba(160, 160, 160, 0.6);
4
+ position: absolute;
5
+ }
6
+ .resize-bar:hover {
7
+ background-color: #328cff;
8
+ }
9
+ .resize-bar.horizontal {
10
+ width: 6px;
11
+ height: 30px;
12
+ }
13
+ .resize-bar.vertical {
14
+ width: 30px;
15
+ height: 6px;
16
+ }
17
+ .resize-bar.active {
18
+ background-color: #328cff;
19
+ }
20
+ #resize-left-bar,
21
+ #resize-right-bar {
22
+ cursor: ew-resize;
23
+ }
24
+ #resize-top-bar,
25
+ #resize-bottom-bar {
26
+ cursor: ns-resize;
27
+ }
package/src/index.ts ADDED
@@ -0,0 +1,121 @@
1
+ import { IPluginTempl } from '@hprint/core'
2
+ import { SelectEvent, SelectMode } from './types/eventType';
3
+ // 导入所有插件
4
+ import UnitPlugin from './plugins/UnitPlugin';
5
+ import DringPlugin from './plugins/DringPlugin';
6
+ import AlignGuidLinePlugin from './plugins/AlignGuidLinePlugin';
7
+ import ControlsPlugin from './plugins/ControlsPlugin';
8
+ import ControlsRotatePlugin from './plugins/ControlsRotatePlugin';
9
+ import CenterAlignPlugin from './plugins/CenterAlignPlugin';
10
+ import LayerPlugin from './plugins/LayerPlugin';
11
+ import CopyPlugin from './plugins/CopyPlugin';
12
+ import MoveHotKeyPlugin from './plugins/MoveHotKeyPlugin';
13
+ import DeleteHotKeyPlugin from './plugins/DeleteHotKeyPlugin';
14
+ import GroupPlugin from './plugins/GroupPlugin';
15
+ import DrawLinePlugin from './plugins/DrawLinePlugin';
16
+ import GroupTextEditorPlugin from './plugins/GroupTextEditorPlugin';
17
+ import GroupAlignPlugin from './plugins/GroupAlignPlugin';
18
+ import WorkspacePlugin from './plugins/WorkspacePlugin';
19
+ import MaskPlugin from './plugins/MaskPlugin';
20
+ import HistoryPlugin from './plugins/HistoryPlugin';
21
+ import FlipPlugin from './plugins/FlipPlugin';
22
+ import RulerPlugin from './plugins/RulerPlugin';
23
+ import MaterialPlugin from './plugins/MaterialPlugin';
24
+ import WaterMarkPlugin from './plugins/WaterMarkPlugin';
25
+ import FontPlugin from './plugins/FontPlugin';
26
+ import PolygonModifyPlugin from './plugins/PolygonModifyPlugin';
27
+ import DrawPolygonPlugin from './plugins/DrawPolygonPlugin';
28
+ import FreeDrawPlugin from './plugins/FreeDrawPlugin';
29
+ import PathTextPlugin from './plugins/PathTextPlugin';
30
+ import PsdPlugin from './plugins/PsdPlugin';
31
+ import SimpleClipImagePlugin from './plugins/SimpleClipImagePlugin';
32
+ import BarCodePlugin from './plugins/BarCodePlugin';
33
+ import QrCodePlugin from './plugins/QrCodePlugin';
34
+ import ImageStroke from './plugins/ImageStroke';
35
+ import ResizePlugin from './plugins/ResizePlugin';
36
+ import LockPlugin from './plugins/LockPlugin';
37
+ import AddBaseTypePlugin from './plugins/AddBaseTypePlugin';
38
+ import PrintPlugin from './plugins/PrintPlugin';
39
+ import CreateElementPlugin from './plugins/CreateElementPlugin';
40
+
41
+ // 对象形式导出所有插件
42
+ const pluginsObject: { [key: string]: IPluginTempl } = {
43
+ UnitPlugin,
44
+ DringPlugin,
45
+ AlignGuidLinePlugin,
46
+ ControlsPlugin,
47
+ ControlsRotatePlugin,
48
+ CenterAlignPlugin,
49
+ LayerPlugin,
50
+ CopyPlugin,
51
+ MoveHotKeyPlugin,
52
+ DeleteHotKeyPlugin,
53
+ GroupPlugin,
54
+ DrawLinePlugin,
55
+ GroupTextEditorPlugin,
56
+ GroupAlignPlugin,
57
+ WorkspacePlugin,
58
+ MaskPlugin,
59
+ HistoryPlugin,
60
+ FlipPlugin,
61
+ RulerPlugin,
62
+ MaterialPlugin,
63
+ WaterMarkPlugin,
64
+ FontPlugin,
65
+ PolygonModifyPlugin,
66
+ DrawPolygonPlugin,
67
+ FreeDrawPlugin,
68
+ PathTextPlugin,
69
+ PsdPlugin,
70
+ SimpleClipImagePlugin,
71
+ BarCodePlugin,
72
+ QrCodePlugin,
73
+ ImageStroke,
74
+ ResizePlugin,
75
+ LockPlugin,
76
+ AddBaseTypePlugin,
77
+ PrintPlugin,
78
+ CreateElementPlugin,
79
+ };
80
+
81
+ // 数组形式导出所有插件
82
+ const pluginsList: IPluginTempl[] = [
83
+ UnitPlugin,
84
+ DringPlugin,
85
+ AlignGuidLinePlugin,
86
+ ControlsPlugin,
87
+ ControlsRotatePlugin,
88
+ CenterAlignPlugin,
89
+ LayerPlugin,
90
+ CopyPlugin,
91
+ MoveHotKeyPlugin,
92
+ DeleteHotKeyPlugin,
93
+ GroupPlugin,
94
+ DrawLinePlugin,
95
+ GroupTextEditorPlugin,
96
+ GroupAlignPlugin,
97
+ WorkspacePlugin,
98
+ MaskPlugin,
99
+ HistoryPlugin,
100
+ FlipPlugin,
101
+ RulerPlugin,
102
+ MaterialPlugin,
103
+ WaterMarkPlugin,
104
+ FontPlugin,
105
+ PolygonModifyPlugin,
106
+ DrawPolygonPlugin,
107
+ FreeDrawPlugin,
108
+ PathTextPlugin,
109
+ PsdPlugin,
110
+ SimpleClipImagePlugin,
111
+ BarCodePlugin,
112
+ QrCodePlugin,
113
+ ImageStroke,
114
+ ResizePlugin,
115
+ LockPlugin,
116
+ AddBaseTypePlugin,
117
+ PrintPlugin,
118
+ CreateElementPlugin,
119
+ ];
120
+
121
+ export { pluginsObject, pluginsList, SelectEvent, SelectMode };
@@ -0,0 +1,47 @@
1
+ import { fabric } from '@hprint/core';
2
+
3
+ fabric.Arrow = fabric.util.createClass(fabric.Line, {
4
+ type: 'arrow',
5
+ superType: 'drawing',
6
+ initialize(points, options) {
7
+ if (!points) {
8
+ const { x1, x2, y1, y2 } = options;
9
+ points = [x1, y1, x2, y2];
10
+ }
11
+ options = options || {};
12
+ this.callSuper('initialize', points, options);
13
+ },
14
+ _render(ctx) {
15
+ this.callSuper('_render', ctx);
16
+ ctx.save();
17
+ // 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
18
+ ctx.scale(1 / this.scaleX, 1 / this.scaleY);
19
+ const xDiff = (this.x2 - this.x1) * this.scaleX;
20
+ const yDiff = (this.y2 - this.y1) * this.scaleY;
21
+ const angle = Math.atan2(yDiff, xDiff);
22
+ ctx.translate(
23
+ ((this.x2 - this.x1) / 2) * this.scaleX,
24
+ ((this.y2 - this.y1) / 2) * this.scaleY
25
+ );
26
+ ctx.rotate(angle);
27
+ ctx.beginPath();
28
+ // Move 5px in front of line to start the arrow so it does not have the square line end showing in front (0,0)
29
+ ctx.moveTo(0, 0);
30
+ ctx.lineTo(-10, 5);
31
+ ctx.lineTo(-10, -5);
32
+ ctx.closePath();
33
+ ctx.lineWidth = this.lineWidth;
34
+ ctx.strokeStyle = this.stroke;
35
+ ctx.fillStyle = this.fill;
36
+ ctx.stroke();
37
+ ctx.fill();
38
+ ctx.restore();
39
+ },
40
+ });
41
+
42
+ fabric.Arrow.fromObject = (options, callback) => {
43
+ const { x1, x2, y1, y2 } = options;
44
+ return callback(new fabric.Arrow([x1, y1, x2, y2], options));
45
+ };
46
+
47
+ export default fabric.Arrow;
@@ -0,0 +1,50 @@
1
+ import { fabric } from '@hprint/core';
2
+
3
+ fabric.ThinTailArrow = fabric.util.createClass(fabric.Line, {
4
+ type: 'thinTailArrow',
5
+ superType: 'drawing',
6
+ initialize(points, options) {
7
+ if (!points) {
8
+ const { x1, x2, y1, y2 } = options;
9
+ points = [x1, y1, x2, y2];
10
+ }
11
+ options = options || {};
12
+ this.callSuper('initialize', points, options);
13
+ },
14
+ _render(ctx) {
15
+ ctx.save();
16
+ // 乘或除对应的scaleX(Y),抵消元素放缩造成的影响,使箭头不会变形
17
+ ctx.scale(1 / this.scaleX, 1 / this.scaleY);
18
+ const xDiff = (this.x2 - this.x1) * this.scaleX;
19
+ const yDiff = (this.y2 - this.y1) * this.scaleY;
20
+ ctx.translate(-xDiff / 2, -yDiff / 2);
21
+ // 箭头方位角
22
+ const angle = Math.atan2(yDiff, xDiff);
23
+ ctx.rotate(angle);
24
+ // 箭头总长(最小长度是20)
25
+ let length = Math.hypot(xDiff, yDiff);
26
+ length = length < 20 ? 20 : length;
27
+ // 绘制箭头
28
+ ctx.beginPath();
29
+ ctx.moveTo(0, 0);
30
+ ctx.lineTo(length - 18, -5);
31
+ ctx.lineTo(length - 20, -12);
32
+ ctx.lineTo(length, 0);
33
+ ctx.lineTo(length - 20, 12);
34
+ ctx.lineTo(length - 18, 5);
35
+ ctx.lineTo(0, 0);
36
+ ctx.lineWidth = this.strokeWidth;
37
+ ctx.strokeStyle = this.stroke;
38
+ ctx.fillStyle = this.fill;
39
+ ctx.stroke();
40
+ ctx.fill();
41
+ ctx.restore();
42
+ },
43
+ });
44
+
45
+ fabric.ThinTailArrow.fromObject = (options, callback) => {
46
+ const { x1, x2, y1, y2 } = options;
47
+ return callback(new fabric.ThinTailArrow([x1, y1, x2, y2], options));
48
+ };
49
+
50
+ export default fabric.ThinTailArrow;
@@ -0,0 +1,107 @@
1
+ import { fabric, IEditor, IPluginTempl } from '@hprint/core';
2
+ import { v4 as uuid } from 'uuid';
3
+
4
+ type IPlugin = Pick<AddBaseTypePlugin, 'addObject' | 'createImgByElement'>;
5
+
6
+ declare module '@hprint/core' {
7
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
8
+ interface IEditor extends IPlugin { }
9
+ }
10
+
11
+ export default class AddBaseTypePlugin implements IPluginTempl {
12
+ static pluginName = 'AddBaseTypePlugin';
13
+ static apis = ['addObject', 'createImgByElement'];
14
+ constructor(
15
+ public canvas: fabric.Canvas,
16
+ public editor: IEditor
17
+ ) {
18
+ this.editor = editor;
19
+ this.canvas = canvas;
20
+ }
21
+
22
+ addObject(
23
+ item: fabric.Object,
24
+ optons?: {
25
+ event: DragEvent;
26
+ scale: boolean;
27
+ center: boolean;
28
+ }
29
+ ) {
30
+ const { event = false, scale = false, center = true } = optons || {};
31
+ item.set({
32
+ id: uuid(),
33
+ });
34
+ scale && this._toScale(item);
35
+ event && this._toEvent(item, event);
36
+ this.canvas.add(item);
37
+ if (!event && center) {
38
+ this._toCenter(item);
39
+ }
40
+ item.syncOriginSizeByUnit(['left', 'top']);
41
+ this.canvas.setActiveObject(item);
42
+ this.canvas.renderAll();
43
+ this.editor.saveState();
44
+ }
45
+
46
+ _toEvent(item: fabric.Object, event: DragEvent) {
47
+ const { left, top } = this.canvas
48
+ .getSelectionElement()
49
+ .getBoundingClientRect();
50
+ if (event.x < left || event.y < top || item.width === undefined) return;
51
+ const point = {
52
+ x: event.x - left,
53
+ y: event.y - top,
54
+ };
55
+ const pointerVpt = this.canvas.restorePointerVpt(point);
56
+ item.set({
57
+ left: pointerVpt.x,
58
+ top: pointerVpt.y,
59
+ });
60
+ }
61
+
62
+ _toCenter(item: fabric.Object) {
63
+ // this.canvas.setActiveObject(item);
64
+ this.editor.positionV2(item, 'center');
65
+ }
66
+
67
+ _toScale(item: fabric.Object) {
68
+ const { width } = this.editor.getWorkspase();
69
+ if (width === undefined) return;
70
+ item.scaleToWidth(width / 2);
71
+ }
72
+
73
+ createImgByElement(target: HTMLImageElement) {
74
+ return new Promise((resolve) => {
75
+ const imgType = this.getImageExtension(target.src);
76
+ if (imgType === 'svg') {
77
+ fabric.loadSVGFromURL(target.src, (objects) => {
78
+ const item = fabric.util.groupSVGElements(objects, {
79
+ shadow: '',
80
+ fontFamily: 'arial',
81
+ name: 'svg元素',
82
+ });
83
+ resolve(item);
84
+ });
85
+ } else {
86
+ fabric.Image.fromURL(
87
+ target.src,
88
+ (imgEl) => {
89
+ resolve(imgEl);
90
+ },
91
+ { crossOrigin: 'anonymous' }
92
+ );
93
+ }
94
+ });
95
+ }
96
+
97
+ getImageExtension(imageUrl: string) {
98
+ const pathParts = imageUrl.split('/');
99
+ const filename = pathParts[pathParts.length - 1];
100
+ const fileParts = filename.split('.');
101
+ return fileParts[fileParts.length - 1];
102
+ }
103
+
104
+ destroy() {
105
+ console.log('pluginDestroy');
106
+ }
107
+ }