@hprint/plugins 0.0.1-alpha.3 → 0.0.1

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,224 +1,224 @@
1
- import { fabric } from '@hprint/core';
2
- import axios from 'axios';
3
- import qs from 'qs';
4
- import type { IEditor, IPluginTempl } from '@hprint/core';
5
-
6
- type IPlugin = Pick<
7
- MaterialPlugin,
8
- | 'getTemplTypeList'
9
- | 'getTemplList'
10
- | 'getMaterialTypeList'
11
- | 'getMaterialList'
12
- | 'getSizeList'
13
- >;
14
-
15
- declare module '@hprint/core' {
16
- // eslint-disable-next-line @typescript-eslint/no-empty-interface
17
- interface IEditor extends IPlugin {}
18
- }
19
-
20
- class MaterialPlugin implements IPluginTempl {
21
- static pluginName = 'MaterialPlugin';
22
- static apis = [
23
- 'getTemplTypeList',
24
- 'getTemplList',
25
- 'getMaterialTypeList',
26
- 'getMaterialList',
27
- 'getSizeList',
28
- ];
29
- apiMapUrl: { [propName: string]: string };
30
- repoSrc: string;
31
- constructor(
32
- public canvas: fabric.Canvas,
33
- public editor: IEditor,
34
- config: { repoSrc: string }
35
- ) {
36
- this.repoSrc = config.repoSrc;
37
- this.apiMapUrl = {
38
- template: config.repoSrc + '/template/type.json',
39
- svg: config.repoSrc + '/svg/type.json',
40
- };
41
- }
42
- // 获取模板分类
43
- getTemplTypeList() {
44
- return axios
45
- .get(`${this.repoSrc}/api/templ-types?pagination[pageSize]=100`)
46
- .then((res) => {
47
- const list = res.data.data.map((item: any) => {
48
- return {
49
- value: item.id,
50
- label: item.attributes.name,
51
- };
52
- });
53
- return list;
54
- });
55
- }
56
- // 分页获取模板列表
57
- getTemplList(templType = '', index = 1, searchKeyword = '') {
58
- const query = {
59
- fields: '*',
60
- populate: {
61
- img: '*',
62
- },
63
- filters: {},
64
- pagination: {
65
- page: index,
66
- pageSize: 10,
67
- },
68
- };
69
-
70
- const queryParams = this._getQueryParams(query, [
71
- {
72
- key: 'templ_type',
73
- value: templType,
74
- type: '$eq',
75
- },
76
- {
77
- key: 'name',
78
- value: searchKeyword,
79
- type: '$contains',
80
- },
81
- ]);
82
-
83
- return axios
84
- .get(`${this.repoSrc}/api/templs?${queryParams}`)
85
- .then((res: any) => {
86
- const list = res.data.data.map((item: any) => {
87
- return {
88
- name: item.attributes.name,
89
- desc: item.attributes.desc,
90
- src: this._getMaterialPreviewUrl(item.attributes.img),
91
- json: item.attributes.json,
92
- };
93
- });
94
- return { list, pagination: res?.data?.meta?.pagination };
95
- });
96
- }
97
-
98
- /**
99
- * @description: 获取素材分类
100
- * @return {Promise<any>}
101
- */
102
- getMaterialTypeList() {
103
- return axios
104
- .get(`${this.repoSrc}/api/material-types?pagination[pageSize]=100`)
105
- .then((res) => {
106
- const list = res.data.data.map((item: any) => {
107
- return {
108
- value: item.id,
109
- label: item.attributes.name,
110
- };
111
- });
112
- return list;
113
- });
114
- }
115
-
116
- /**
117
- * @description: 获取素材列表
118
- * @returns Promise<Array>
119
- */
120
- getMaterialList(materialType = '', index = 1, searchKeyword = '') {
121
- const query = {
122
- populate: {
123
- img: '*',
124
- },
125
- // fields: ['materialType'],
126
- filters: {},
127
- pagination: {
128
- page: index,
129
- pageSize: 50,
130
- },
131
- };
132
-
133
- const queryParams = this._getQueryParams(query, [
134
- {
135
- key: 'material_type',
136
- value: materialType,
137
- type: '$eq',
138
- },
139
- {
140
- key: 'name',
141
- value: searchKeyword,
142
- type: '$contains',
143
- },
144
- ]);
145
-
146
- return axios
147
- .get(`${this.repoSrc}/api/materials?${queryParams}`)
148
- .then((res: any) => {
149
- const list = res.data.data.map((item: any) => {
150
- return {
151
- name: item.attributes.name,
152
- desc: item.attributes.desc,
153
- src: this._getMaterialInfoUrl(item.attributes.img),
154
- previewSrc: this._getMaterialPreviewUrl(
155
- item.attributes.img
156
- ),
157
- };
158
- });
159
- return { list, pagination: res?.data?.meta?.pagination };
160
- });
161
- }
162
-
163
- getSizeList() {
164
- return axios
165
- .get(`${this.repoSrc}/api/sizes?pagination[pageSize]=100`)
166
- .then((res) => {
167
- const list = res.data.data.map((item: any) => {
168
- return {
169
- value: item.id,
170
- name: item.attributes.name,
171
- width: Number(item.attributes.width),
172
- height: Number(item.attributes.height),
173
- unit: item.attributes.unit,
174
- };
175
- });
176
- return list;
177
- });
178
- }
179
- getFontList() {
180
- return axios
181
- .get(`${this.repoSrc}/api/fonts?pagination[pageSize]=100`)
182
- .then((res) => {
183
- const list = res.data.data.map((item: any) => {
184
- return {
185
- value: item.id,
186
- label: item.attributes.name,
187
- };
188
- });
189
- return list;
190
- });
191
- }
192
-
193
- _getMaterialInfoUrl(info: any) {
194
- const imgUrl = info?.data?.attributes?.url || '';
195
- return this.repoSrc + imgUrl;
196
- }
197
-
198
- _getMaterialPreviewUrl(info: any) {
199
- const imgUrl =
200
- info?.data?.attributes?.formats?.small?.url ||
201
- info?.data?.attributes?.url ||
202
- '';
203
- return this.repoSrc + imgUrl;
204
- }
205
-
206
- // 拼接查询条件参数
207
- _getQueryParams(option: any, filters: any) {
208
- filters.forEach((item: any) => {
209
- const { key, value, type } = item;
210
- if (value) {
211
- option.filters[key] = { [type]: value };
212
- }
213
- });
214
- return qs.stringify(option);
215
- }
216
-
217
- async getMaterialInfo(typeId: string) {
218
- const url = this.apiMapUrl[typeId];
219
- const res = await axios.get(url, { params: { typeId } });
220
- return res.data.data;
221
- }
222
- }
223
-
224
- export default MaterialPlugin;
1
+ import { fabric } from '@hprint/core';
2
+ import axios from 'axios';
3
+ import qs from 'qs';
4
+ import type { IEditor, IPluginTempl } from '@hprint/core';
5
+
6
+ type IPlugin = Pick<
7
+ MaterialPlugin,
8
+ | 'getTemplTypeList'
9
+ | 'getTemplList'
10
+ | 'getMaterialTypeList'
11
+ | 'getMaterialList'
12
+ | 'getSizeList'
13
+ >;
14
+
15
+ declare module '@hprint/core' {
16
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
17
+ interface IEditor extends IPlugin {}
18
+ }
19
+
20
+ class MaterialPlugin implements IPluginTempl {
21
+ static pluginName = 'MaterialPlugin';
22
+ static apis = [
23
+ 'getTemplTypeList',
24
+ 'getTemplList',
25
+ 'getMaterialTypeList',
26
+ 'getMaterialList',
27
+ 'getSizeList',
28
+ ];
29
+ apiMapUrl: { [propName: string]: string };
30
+ repoSrc: string;
31
+ constructor(
32
+ public canvas: fabric.Canvas,
33
+ public editor: IEditor,
34
+ config: { repoSrc: string }
35
+ ) {
36
+ this.repoSrc = config.repoSrc;
37
+ this.apiMapUrl = {
38
+ template: config.repoSrc + '/template/type.json',
39
+ svg: config.repoSrc + '/svg/type.json',
40
+ };
41
+ }
42
+ // 获取模板分类
43
+ getTemplTypeList() {
44
+ return axios
45
+ .get(`${this.repoSrc}/api/templ-types?pagination[pageSize]=100`)
46
+ .then((res) => {
47
+ const list = res.data.data.map((item: any) => {
48
+ return {
49
+ value: item.id,
50
+ label: item.attributes.name,
51
+ };
52
+ });
53
+ return list;
54
+ });
55
+ }
56
+ // 分页获取模板列表
57
+ getTemplList(templType = '', index = 1, searchKeyword = '') {
58
+ const query = {
59
+ fields: '*',
60
+ populate: {
61
+ img: '*',
62
+ },
63
+ filters: {},
64
+ pagination: {
65
+ page: index,
66
+ pageSize: 10,
67
+ },
68
+ };
69
+
70
+ const queryParams = this._getQueryParams(query, [
71
+ {
72
+ key: 'templ_type',
73
+ value: templType,
74
+ type: '$eq',
75
+ },
76
+ {
77
+ key: 'name',
78
+ value: searchKeyword,
79
+ type: '$contains',
80
+ },
81
+ ]);
82
+
83
+ return axios
84
+ .get(`${this.repoSrc}/api/templs?${queryParams}`)
85
+ .then((res: any) => {
86
+ const list = res.data.data.map((item: any) => {
87
+ return {
88
+ name: item.attributes.name,
89
+ desc: item.attributes.desc,
90
+ src: this._getMaterialPreviewUrl(item.attributes.img),
91
+ json: item.attributes.json,
92
+ };
93
+ });
94
+ return { list, pagination: res?.data?.meta?.pagination };
95
+ });
96
+ }
97
+
98
+ /**
99
+ * @description: 获取素材分类
100
+ * @return {Promise<any>}
101
+ */
102
+ getMaterialTypeList() {
103
+ return axios
104
+ .get(`${this.repoSrc}/api/material-types?pagination[pageSize]=100`)
105
+ .then((res) => {
106
+ const list = res.data.data.map((item: any) => {
107
+ return {
108
+ value: item.id,
109
+ label: item.attributes.name,
110
+ };
111
+ });
112
+ return list;
113
+ });
114
+ }
115
+
116
+ /**
117
+ * @description: 获取素材列表
118
+ * @returns Promise<Array>
119
+ */
120
+ getMaterialList(materialType = '', index = 1, searchKeyword = '') {
121
+ const query = {
122
+ populate: {
123
+ img: '*',
124
+ },
125
+ // fields: ['materialType'],
126
+ filters: {},
127
+ pagination: {
128
+ page: index,
129
+ pageSize: 50,
130
+ },
131
+ };
132
+
133
+ const queryParams = this._getQueryParams(query, [
134
+ {
135
+ key: 'material_type',
136
+ value: materialType,
137
+ type: '$eq',
138
+ },
139
+ {
140
+ key: 'name',
141
+ value: searchKeyword,
142
+ type: '$contains',
143
+ },
144
+ ]);
145
+
146
+ return axios
147
+ .get(`${this.repoSrc}/api/materials?${queryParams}`)
148
+ .then((res: any) => {
149
+ const list = res.data.data.map((item: any) => {
150
+ return {
151
+ name: item.attributes.name,
152
+ desc: item.attributes.desc,
153
+ src: this._getMaterialInfoUrl(item.attributes.img),
154
+ previewSrc: this._getMaterialPreviewUrl(
155
+ item.attributes.img
156
+ ),
157
+ };
158
+ });
159
+ return { list, pagination: res?.data?.meta?.pagination };
160
+ });
161
+ }
162
+
163
+ getSizeList() {
164
+ return axios
165
+ .get(`${this.repoSrc}/api/sizes?pagination[pageSize]=100`)
166
+ .then((res) => {
167
+ const list = res.data.data.map((item: any) => {
168
+ return {
169
+ value: item.id,
170
+ name: item.attributes.name,
171
+ width: Number(item.attributes.width),
172
+ height: Number(item.attributes.height),
173
+ unit: item.attributes.unit,
174
+ };
175
+ });
176
+ return list;
177
+ });
178
+ }
179
+ getFontList() {
180
+ return axios
181
+ .get(`${this.repoSrc}/api/fonts?pagination[pageSize]=100`)
182
+ .then((res) => {
183
+ const list = res.data.data.map((item: any) => {
184
+ return {
185
+ value: item.id,
186
+ label: item.attributes.name,
187
+ };
188
+ });
189
+ return list;
190
+ });
191
+ }
192
+
193
+ _getMaterialInfoUrl(info: any) {
194
+ const imgUrl = info?.data?.attributes?.url || '';
195
+ return this.repoSrc + imgUrl;
196
+ }
197
+
198
+ _getMaterialPreviewUrl(info: any) {
199
+ const imgUrl =
200
+ info?.data?.attributes?.formats?.small?.url ||
201
+ info?.data?.attributes?.url ||
202
+ '';
203
+ return this.repoSrc + imgUrl;
204
+ }
205
+
206
+ // 拼接查询条件参数
207
+ _getQueryParams(option: any, filters: any) {
208
+ filters.forEach((item: any) => {
209
+ const { key, value, type } = item;
210
+ if (value) {
211
+ option.filters[key] = { [type]: value };
212
+ }
213
+ });
214
+ return qs.stringify(option);
215
+ }
216
+
217
+ async getMaterialInfo(typeId: string) {
218
+ const url = this.apiMapUrl[typeId];
219
+ const res = await axios.get(url, { params: { typeId } });
220
+ return res.data.data;
221
+ }
222
+ }
223
+
224
+ export default MaterialPlugin;
@@ -1,45 +1,45 @@
1
- import { fabric } from '@hprint/core';
2
- import type { IEditor, IPluginTempl } from '@hprint/core';
3
-
4
- class MiddleMousePlugin implements IPluginTempl {
5
- static pluginName = 'MiddleMousePlugin';
6
- workspaceEl!: HTMLElement;
7
-
8
- constructor(
9
- public canvas: fabric.Canvas,
10
- public editor: IEditor
11
- ) {
12
- this.init();
13
- }
14
-
15
- private init() {
16
- const workspaceEl = document.querySelector('#workspace') as HTMLElement;
17
- if (!workspaceEl) {
18
- throw new Error('element #workspace is missing, plz check!');
19
- }
20
- this.workspaceEl = workspaceEl;
21
- this.initListener();
22
- }
23
-
24
- private handleMouseUp = (e: MouseEvent) =>
25
- e.button === 1 && this.canvas.fire('mouse:up', { e });
26
-
27
- private handleMouseDown = (e: MouseEvent) =>
28
- e.button === 1 && this.canvas.fire('mouse:down', { e });
29
-
30
- /**
31
- * @desc 初始化鼠标中键监听事件
32
- */
33
- private initListener() {
34
- this.workspaceEl.addEventListener('mouseup', this.handleMouseUp);
35
- this.workspaceEl.addEventListener('mousedown', this.handleMouseDown);
36
- }
37
-
38
- destroy() {
39
- this.workspaceEl.removeEventListener('mouseup', this.handleMouseUp);
40
- this.workspaceEl.removeEventListener('mousedown', this.handleMouseDown);
41
- console.log('pluginDestroy');
42
- }
43
- }
44
-
45
- export default MiddleMousePlugin;
1
+ import { fabric } from '@hprint/core';
2
+ import type { IEditor, IPluginTempl } from '@hprint/core';
3
+
4
+ class MiddleMousePlugin implements IPluginTempl {
5
+ static pluginName = 'MiddleMousePlugin';
6
+ workspaceEl!: HTMLElement;
7
+
8
+ constructor(
9
+ public canvas: fabric.Canvas,
10
+ public editor: IEditor
11
+ ) {
12
+ this.init();
13
+ }
14
+
15
+ private init() {
16
+ const workspaceEl = document.querySelector('#workspace') as HTMLElement;
17
+ if (!workspaceEl) {
18
+ throw new Error('element #workspace is missing, plz check!');
19
+ }
20
+ this.workspaceEl = workspaceEl;
21
+ this.initListener();
22
+ }
23
+
24
+ private handleMouseUp = (e: MouseEvent) =>
25
+ e.button === 1 && this.canvas.fire('mouse:up', { e });
26
+
27
+ private handleMouseDown = (e: MouseEvent) =>
28
+ e.button === 1 && this.canvas.fire('mouse:down', { e });
29
+
30
+ /**
31
+ * @desc 初始化鼠标中键监听事件
32
+ */
33
+ private initListener() {
34
+ this.workspaceEl.addEventListener('mouseup', this.handleMouseUp);
35
+ this.workspaceEl.addEventListener('mousedown', this.handleMouseDown);
36
+ }
37
+
38
+ destroy() {
39
+ this.workspaceEl.removeEventListener('mouseup', this.handleMouseUp);
40
+ this.workspaceEl.removeEventListener('mousedown', this.handleMouseDown);
41
+ console.log('pluginDestroy');
42
+ }
43
+ }
44
+
45
+ export default MiddleMousePlugin;
@@ -1,46 +1,46 @@
1
- import { fabric } from '@hprint/core';
2
- import type { IEditor, IPluginTempl } from '@hprint/core';
3
-
4
- class MoveHotKeyPlugin implements IPluginTempl {
5
- static pluginName = 'MoveHotKeyPlugin';
6
- hotkeys: string[] = ['left', 'right', 'down', 'up'];
7
- constructor(
8
- public canvas: fabric.Canvas,
9
- public editor: IEditor
10
- ) {}
11
-
12
- // 快捷键扩展回调
13
- hotkeyEvent(eventName: string, e: KeyboardEvent) {
14
- if (e.type === 'keydown') {
15
- const { canvas } = this;
16
- const activeObject = canvas.getActiveObject();
17
- if (!activeObject) return;
18
- switch (eventName) {
19
- case 'left':
20
- if (activeObject.left === undefined) return;
21
- activeObject.set('left', activeObject.left - 1);
22
- break;
23
- case 'right':
24
- if (activeObject.left === undefined) return;
25
- activeObject.set('left', activeObject.left + 1);
26
- break;
27
- case 'down':
28
- if (activeObject.top === undefined) return;
29
- activeObject.set('top', activeObject.top + 1);
30
- break;
31
- case 'up':
32
- if (activeObject.top === undefined) return;
33
- activeObject.set('top', activeObject.top - 1);
34
- break;
35
- default:
36
- }
37
- canvas.renderAll();
38
- }
39
- }
40
-
41
- destroy() {
42
- console.log('pluginDestroy');
43
- }
44
- }
45
-
46
- export default MoveHotKeyPlugin;
1
+ import { fabric } from '@hprint/core';
2
+ import type { IEditor, IPluginTempl } from '@hprint/core';
3
+
4
+ class MoveHotKeyPlugin implements IPluginTempl {
5
+ static pluginName = 'MoveHotKeyPlugin';
6
+ hotkeys: string[] = ['left', 'right', 'down', 'up'];
7
+ constructor(
8
+ public canvas: fabric.Canvas,
9
+ public editor: IEditor
10
+ ) {}
11
+
12
+ // 快捷键扩展回调
13
+ hotkeyEvent(eventName: string, e: KeyboardEvent) {
14
+ if (e.type === 'keydown') {
15
+ const { canvas } = this;
16
+ const activeObject = canvas.getActiveObject();
17
+ if (!activeObject) return;
18
+ switch (eventName) {
19
+ case 'left':
20
+ if (activeObject.left === undefined) return;
21
+ activeObject.set('left', activeObject.left - 1);
22
+ break;
23
+ case 'right':
24
+ if (activeObject.left === undefined) return;
25
+ activeObject.set('left', activeObject.left + 1);
26
+ break;
27
+ case 'down':
28
+ if (activeObject.top === undefined) return;
29
+ activeObject.set('top', activeObject.top + 1);
30
+ break;
31
+ case 'up':
32
+ if (activeObject.top === undefined) return;
33
+ activeObject.set('top', activeObject.top - 1);
34
+ break;
35
+ default:
36
+ }
37
+ canvas.renderAll();
38
+ }
39
+ }
40
+
41
+ destroy() {
42
+ console.log('pluginDestroy');
43
+ }
44
+ }
45
+
46
+ export default MoveHotKeyPlugin;