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

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 (50) hide show
  1. package/dist/index.js +17 -17
  2. package/dist/index.mjs +1282 -1277
  3. package/dist/src/plugins/CreateElementPlugin.d.ts +4 -0
  4. package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -1
  5. package/dist/src/utils/ruler/ruler.d.ts +1 -0
  6. package/dist/src/utils/ruler/ruler.d.ts.map +1 -1
  7. package/package.json +3 -3
  8. package/src/assets/style/resizePlugin.css +27 -27
  9. package/src/objects/Arrow.js +47 -47
  10. package/src/objects/ThinTailArrow.js +50 -50
  11. package/src/plugins/AlignGuidLinePlugin.ts +1152 -1152
  12. package/src/plugins/ControlsPlugin.ts +251 -251
  13. package/src/plugins/ControlsRotatePlugin.ts +111 -111
  14. package/src/plugins/CopyPlugin.ts +255 -255
  15. package/src/plugins/CreateElementPlugin.ts +23 -2
  16. package/src/plugins/DeleteHotKeyPlugin.ts +57 -57
  17. package/src/plugins/DrawLinePlugin.ts +162 -162
  18. package/src/plugins/DrawPolygonPlugin.ts +205 -205
  19. package/src/plugins/DringPlugin.ts +125 -125
  20. package/src/plugins/FlipPlugin.ts +59 -59
  21. package/src/plugins/FontPlugin.ts +165 -165
  22. package/src/plugins/FreeDrawPlugin.ts +49 -49
  23. package/src/plugins/GroupAlignPlugin.ts +365 -365
  24. package/src/plugins/GroupPlugin.ts +82 -82
  25. package/src/plugins/GroupTextEditorPlugin.ts +198 -198
  26. package/src/plugins/HistoryPlugin.ts +181 -181
  27. package/src/plugins/ImageStroke.ts +121 -121
  28. package/src/plugins/LayerPlugin.ts +108 -108
  29. package/src/plugins/LockPlugin.ts +242 -242
  30. package/src/plugins/MaskPlugin.ts +155 -155
  31. package/src/plugins/MaterialPlugin.ts +224 -224
  32. package/src/plugins/MiddleMousePlugin.ts +45 -45
  33. package/src/plugins/MoveHotKeyPlugin.ts +46 -46
  34. package/src/plugins/PathTextPlugin.ts +89 -89
  35. package/src/plugins/PolygonModifyPlugin.ts +224 -224
  36. package/src/plugins/PrintPlugin.ts +81 -81
  37. package/src/plugins/PsdPlugin.ts +52 -52
  38. package/src/plugins/ResizePlugin.ts +278 -278
  39. package/src/plugins/RulerPlugin.ts +78 -78
  40. package/src/plugins/SimpleClipImagePlugin.ts +244 -244
  41. package/src/plugins/UnitPlugin.ts +326 -326
  42. package/src/plugins/WaterMarkPlugin.ts +257 -257
  43. package/src/types/eventType.ts +11 -11
  44. package/src/utils/psd.js +432 -432
  45. package/src/utils/ruler/guideline.ts +145 -145
  46. package/src/utils/ruler/index.ts +91 -91
  47. package/src/utils/ruler/ruler.ts +936 -924
  48. package/src/utils/ruler/utils.ts +162 -162
  49. package/tsconfig.json +10 -10
  50. package/vite.config.ts +29 -29
@@ -1,155 +1,155 @@
1
- import { fabric } from '@hprint/core';
2
- import type { IEditor, IPluginTempl } from '@hprint/core';
3
-
4
- type IPlugin = Pick<
5
- MaskPlugin,
6
- 'setCoverMask' | 'workspaceMaskToggle' | 'getworkspaceMaskStatus'
7
- >;
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 MaskPlugin implements IPluginTempl {
15
- static pluginName = 'MaskPlugin';
16
- static apis = [
17
- 'setCoverMask',
18
- 'workspaceMaskToggle',
19
- 'getworkspaceMaskStatus',
20
- ];
21
- coverMask: null | fabric.Rect = null;
22
- workspace: null | fabric.Rect = null;
23
- workspaceEl!: HTMLElement;
24
- hackFlag = false;
25
- constructor(
26
- public canvas: fabric.Canvas,
27
- public editor: IEditor
28
- ) {
29
- this.init();
30
- }
31
-
32
- private init() {
33
- const workspaceEl = document.querySelector('#workspace') as HTMLElement;
34
- if (!workspaceEl) {
35
- throw new Error('element #workspace is missing, plz check!');
36
- }
37
- this.workspaceEl = workspaceEl;
38
- }
39
-
40
- /**
41
- * @desc 蒙版开关
42
- * @param val Boolean false
43
- */
44
- workspaceMaskToggle() {
45
- const workspaceMask = this.getWorkspaceMask();
46
- if (!workspaceMask) {
47
- this.initMask();
48
- } else {
49
- // 如果有 则删除
50
- workspaceMask && this.canvas.remove(workspaceMask);
51
- this.workspace?.clone((cloned: fabric.Rect) => {
52
- this.canvas.clipPath = cloned;
53
- this.coverMask = null;
54
- this.canvas.requestRenderAll();
55
- });
56
- this.editor.off('loadJson', this.initMask);
57
- }
58
- }
59
- /**
60
- * @desc 获取蒙版开关
61
- */
62
- getworkspaceMaskStatus() {
63
- return this.coverMask !== null;
64
- }
65
-
66
- /**
67
- * @desc 获取蒙版
68
- * @returns Object
69
- */
70
- getWorkspaceMask() {
71
- return this.canvas
72
- .getObjects()
73
- .find((item) => item.id === 'coverMask') as fabric.Rect;
74
- }
75
-
76
- // 返回workspace对象
77
- getWorkspase() {
78
- return this.canvas
79
- .getObjects()
80
- .find((item) => item.id === 'workspace') as fabric.Rect;
81
- }
82
-
83
- setCoverMask(hack = false) {
84
- if (!this.coverMask || !this.workspace) {
85
- return;
86
- }
87
- const center = this.canvas.getCenter();
88
- const zoom = this.canvas.getZoom();
89
- let zoomToPointNumber = zoom;
90
- if (hack) {
91
- // 比较hack的方法,判断为fabric内部的数据更新问题
92
- zoomToPointNumber += 0.0000001 * (this.hackFlag ? 1 : -1);
93
- this.hackFlag = !this.hackFlag;
94
- }
95
-
96
- this.canvas.zoomToPoint(
97
- new fabric.Point(center.left, center.top),
98
- zoomToPointNumber
99
- );
100
- if (zoom) {
101
- const { workspaceEl } = this;
102
- const width = workspaceEl.offsetWidth;
103
- const height = workspaceEl.offsetHeight;
104
- const cWidth = width / zoom;
105
- const cHeight = height / zoom;
106
- this.coverMask.width = cWidth;
107
- this.coverMask.height = cHeight;
108
- this.coverMask.left =
109
- (this.workspace.left || 0) +
110
- (this.workspace.width! - cWidth) / 2;
111
- this.coverMask.top =
112
- (this.workspace.top || 0) +
113
- (this.workspace.height! - cHeight) / 2;
114
- this.workspace.clone((clone: fabric.Rect) => {
115
- clone.left = -clone.width! / 2;
116
- clone.top = -clone.height! / 2;
117
- clone.inverted = true;
118
- this.coverMask!.clipPath = clone;
119
- this.canvas.requestRenderAll();
120
- });
121
- }
122
- }
123
-
124
- initMask(needBindLoadJSON = true) {
125
- this.workspace = this.getWorkspase();
126
- if (!this.workspace) {
127
- throw new Error('MaskPlugin must be used after WorkspacePlugin!');
128
- }
129
- const coverMask = new fabric.Rect({
130
- fill: 'rgba(0,0,0,0.5)',
131
- id: 'coverMask',
132
- strokeWidth: 0,
133
- });
134
- coverMask.set('selectable', false);
135
- coverMask.set('hasControls', false);
136
- coverMask.set('evented', false);
137
- coverMask.hoverCursor = 'default';
138
- this.canvas.on('object:added', () => {
139
- coverMask.bringToFront();
140
- });
141
- this.canvas.clipPath = undefined;
142
- this.canvas.add(coverMask);
143
- this.coverMask = coverMask;
144
- this.setCoverMask();
145
- // 适配模板和psd的loadjson,在加载完成后再入mask
146
- needBindLoadJSON &&
147
- this.editor.on('loadJson', () => this.initMask(false));
148
- }
149
-
150
- destroy() {
151
- console.log('pluginDestroy');
152
- }
153
- }
154
-
155
- export default MaskPlugin;
1
+ import { fabric } from '@hprint/core';
2
+ import type { IEditor, IPluginTempl } from '@hprint/core';
3
+
4
+ type IPlugin = Pick<
5
+ MaskPlugin,
6
+ 'setCoverMask' | 'workspaceMaskToggle' | 'getworkspaceMaskStatus'
7
+ >;
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 MaskPlugin implements IPluginTempl {
15
+ static pluginName = 'MaskPlugin';
16
+ static apis = [
17
+ 'setCoverMask',
18
+ 'workspaceMaskToggle',
19
+ 'getworkspaceMaskStatus',
20
+ ];
21
+ coverMask: null | fabric.Rect = null;
22
+ workspace: null | fabric.Rect = null;
23
+ workspaceEl!: HTMLElement;
24
+ hackFlag = false;
25
+ constructor(
26
+ public canvas: fabric.Canvas,
27
+ public editor: IEditor
28
+ ) {
29
+ this.init();
30
+ }
31
+
32
+ private init() {
33
+ const workspaceEl = document.querySelector('#workspace') as HTMLElement;
34
+ if (!workspaceEl) {
35
+ throw new Error('element #workspace is missing, plz check!');
36
+ }
37
+ this.workspaceEl = workspaceEl;
38
+ }
39
+
40
+ /**
41
+ * @desc 蒙版开关
42
+ * @param val Boolean false
43
+ */
44
+ workspaceMaskToggle() {
45
+ const workspaceMask = this.getWorkspaceMask();
46
+ if (!workspaceMask) {
47
+ this.initMask();
48
+ } else {
49
+ // 如果有 则删除
50
+ workspaceMask && this.canvas.remove(workspaceMask);
51
+ this.workspace?.clone((cloned: fabric.Rect) => {
52
+ this.canvas.clipPath = cloned;
53
+ this.coverMask = null;
54
+ this.canvas.requestRenderAll();
55
+ });
56
+ this.editor.off('loadJson', this.initMask);
57
+ }
58
+ }
59
+ /**
60
+ * @desc 获取蒙版开关
61
+ */
62
+ getworkspaceMaskStatus() {
63
+ return this.coverMask !== null;
64
+ }
65
+
66
+ /**
67
+ * @desc 获取蒙版
68
+ * @returns Object
69
+ */
70
+ getWorkspaceMask() {
71
+ return this.canvas
72
+ .getObjects()
73
+ .find((item) => item.id === 'coverMask') as fabric.Rect;
74
+ }
75
+
76
+ // 返回workspace对象
77
+ getWorkspase() {
78
+ return this.canvas
79
+ .getObjects()
80
+ .find((item) => item.id === 'workspace') as fabric.Rect;
81
+ }
82
+
83
+ setCoverMask(hack = false) {
84
+ if (!this.coverMask || !this.workspace) {
85
+ return;
86
+ }
87
+ const center = this.canvas.getCenter();
88
+ const zoom = this.canvas.getZoom();
89
+ let zoomToPointNumber = zoom;
90
+ if (hack) {
91
+ // 比较hack的方法,判断为fabric内部的数据更新问题
92
+ zoomToPointNumber += 0.0000001 * (this.hackFlag ? 1 : -1);
93
+ this.hackFlag = !this.hackFlag;
94
+ }
95
+
96
+ this.canvas.zoomToPoint(
97
+ new fabric.Point(center.left, center.top),
98
+ zoomToPointNumber
99
+ );
100
+ if (zoom) {
101
+ const { workspaceEl } = this;
102
+ const width = workspaceEl.offsetWidth;
103
+ const height = workspaceEl.offsetHeight;
104
+ const cWidth = width / zoom;
105
+ const cHeight = height / zoom;
106
+ this.coverMask.width = cWidth;
107
+ this.coverMask.height = cHeight;
108
+ this.coverMask.left =
109
+ (this.workspace.left || 0) +
110
+ (this.workspace.width! - cWidth) / 2;
111
+ this.coverMask.top =
112
+ (this.workspace.top || 0) +
113
+ (this.workspace.height! - cHeight) / 2;
114
+ this.workspace.clone((clone: fabric.Rect) => {
115
+ clone.left = -clone.width! / 2;
116
+ clone.top = -clone.height! / 2;
117
+ clone.inverted = true;
118
+ this.coverMask!.clipPath = clone;
119
+ this.canvas.requestRenderAll();
120
+ });
121
+ }
122
+ }
123
+
124
+ initMask(needBindLoadJSON = true) {
125
+ this.workspace = this.getWorkspase();
126
+ if (!this.workspace) {
127
+ throw new Error('MaskPlugin must be used after WorkspacePlugin!');
128
+ }
129
+ const coverMask = new fabric.Rect({
130
+ fill: 'rgba(0,0,0,0.5)',
131
+ id: 'coverMask',
132
+ strokeWidth: 0,
133
+ });
134
+ coverMask.set('selectable', false);
135
+ coverMask.set('hasControls', false);
136
+ coverMask.set('evented', false);
137
+ coverMask.hoverCursor = 'default';
138
+ this.canvas.on('object:added', () => {
139
+ coverMask.bringToFront();
140
+ });
141
+ this.canvas.clipPath = undefined;
142
+ this.canvas.add(coverMask);
143
+ this.coverMask = coverMask;
144
+ this.setCoverMask();
145
+ // 适配模板和psd的loadjson,在加载完成后再入mask
146
+ needBindLoadJSON &&
147
+ this.editor.on('loadJson', () => this.initMask(false));
148
+ }
149
+
150
+ destroy() {
151
+ console.log('pluginDestroy');
152
+ }
153
+ }
154
+
155
+ export default MaskPlugin;