@hprint/plugins 0.0.6 → 0.0.8
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.
- package/dist/index.js +15 -15
- package/dist/index.mjs +1864 -1862
- package/dist/src/plugins/BarCodePlugin.d.ts +2 -2
- package/dist/src/plugins/BarCodePlugin.d.ts.map +1 -1
- package/dist/src/plugins/CopyPlugin.d.ts.map +1 -1
- package/dist/src/plugins/CreateElementPlugin.d.ts +2 -2
- package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -1
- package/dist/src/plugins/QrCodePlugin.d.ts +2 -2
- package/dist/src/plugins/QrCodePlugin.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/assets/style/resizePlugin.css +27 -27
- package/src/objects/Arrow.js +47 -47
- package/src/objects/ThinTailArrow.js +50 -50
- package/src/plugins/BarCodePlugin.ts +7 -7
- package/src/plugins/ControlsPlugin.ts +413 -413
- package/src/plugins/ControlsRotatePlugin.ts +111 -111
- package/src/plugins/CopyPlugin.ts +261 -255
- package/src/plugins/CreateElementPlugin.ts +3 -1
- package/src/plugins/DeleteHotKeyPlugin.ts +57 -57
- package/src/plugins/DrawLinePlugin.ts +162 -162
- package/src/plugins/DrawPolygonPlugin.ts +205 -205
- package/src/plugins/DringPlugin.ts +125 -125
- package/src/plugins/FlipPlugin.ts +59 -59
- package/src/plugins/FontPlugin.ts +165 -165
- package/src/plugins/FreeDrawPlugin.ts +49 -49
- package/src/plugins/GroupPlugin.ts +82 -82
- package/src/plugins/GroupTextEditorPlugin.ts +198 -198
- package/src/plugins/HistoryPlugin.ts +181 -181
- package/src/plugins/ImageStroke.ts +121 -121
- package/src/plugins/LayerPlugin.ts +108 -108
- package/src/plugins/MaskPlugin.ts +155 -155
- package/src/plugins/MaterialPlugin.ts +224 -224
- package/src/plugins/MiddleMousePlugin.ts +45 -45
- package/src/plugins/MoveHotKeyPlugin.ts +46 -46
- package/src/plugins/PathTextPlugin.ts +89 -89
- package/src/plugins/PolygonModifyPlugin.ts +224 -224
- package/src/plugins/PrintPlugin.ts +81 -81
- package/src/plugins/PsdPlugin.ts +52 -52
- package/src/plugins/QrCodePlugin.ts +6 -6
- package/src/plugins/SimpleClipImagePlugin.ts +244 -244
- package/src/types/eventType.ts +11 -11
- package/src/utils/psd.js +432 -432
- package/src/utils/ruler/guideline.ts +145 -145
- package/src/utils/ruler/index.ts +91 -91
- package/src/utils/ruler/utils.ts +162 -162
- package/tsconfig.json +10 -10
- package/vite.config.ts +29 -29
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
3
|
-
import { io } from 'socket.io-client';
|
|
4
|
-
|
|
5
|
-
type IPlugin = Pick<PrintPlugin, 'printPDF' | 'getPrinterList'>;
|
|
6
|
-
|
|
7
|
-
export interface Option {
|
|
8
|
-
'printer-location': string;
|
|
9
|
-
'printer-make-and-model': string;
|
|
10
|
-
system_driverinfo: string;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface IPrinterItem {
|
|
14
|
-
name: string;
|
|
15
|
-
displayName: string;
|
|
16
|
-
description: string;
|
|
17
|
-
status: number;
|
|
18
|
-
isDefault: boolean;
|
|
19
|
-
options: Option;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IPrintPDFOption {
|
|
23
|
-
width: number;
|
|
24
|
-
height: number;
|
|
25
|
-
base64: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
declare module '@hprint/core' {
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
30
|
-
interface IEditor extends IPlugin {}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export default class PrintPlugin implements IPluginTempl {
|
|
34
|
-
static pluginName = 'PrintPlugin';
|
|
35
|
-
static apis = ['printPDF', 'getPrinterList'];
|
|
36
|
-
|
|
37
|
-
socket?: any;
|
|
38
|
-
isConnect = false;
|
|
39
|
-
printerList: IPrinterItem[] = [];
|
|
40
|
-
|
|
41
|
-
constructor(
|
|
42
|
-
public canvas: fabric.Canvas,
|
|
43
|
-
public editor: IEditor
|
|
44
|
-
) {
|
|
45
|
-
this.editor = editor;
|
|
46
|
-
this.canvas = canvas;
|
|
47
|
-
|
|
48
|
-
this.socket = io('http://localhost:17521', {
|
|
49
|
-
transports: ['websocket'],
|
|
50
|
-
auth: {
|
|
51
|
-
token: 'vue-plugin-hiprint',
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
this.socket.on('connect', () => {
|
|
56
|
-
this.isConnect = true;
|
|
57
|
-
// globalThis.connect = true;
|
|
58
|
-
// TODO: Do something for your project
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
this.socket.on('printerList', (printerList: IPrinterItem[]) => {
|
|
62
|
-
console.log('printerList', printerList);
|
|
63
|
-
this.printerList = printerList;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
printPDF(options: IPrintPDFOption) {
|
|
68
|
-
this.socket.emit('printPDF', {
|
|
69
|
-
...options,
|
|
70
|
-
unit: 'mm',
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
getPrinterList() {
|
|
75
|
-
return this.printerList;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
destroy() {
|
|
79
|
-
console.log('pluginDestroy');
|
|
80
|
-
}
|
|
81
|
-
}
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
3
|
+
import { io } from 'socket.io-client';
|
|
4
|
+
|
|
5
|
+
type IPlugin = Pick<PrintPlugin, 'printPDF' | 'getPrinterList'>;
|
|
6
|
+
|
|
7
|
+
export interface Option {
|
|
8
|
+
'printer-location': string;
|
|
9
|
+
'printer-make-and-model': string;
|
|
10
|
+
system_driverinfo: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IPrinterItem {
|
|
14
|
+
name: string;
|
|
15
|
+
displayName: string;
|
|
16
|
+
description: string;
|
|
17
|
+
status: number;
|
|
18
|
+
isDefault: boolean;
|
|
19
|
+
options: Option;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IPrintPDFOption {
|
|
23
|
+
width: number;
|
|
24
|
+
height: number;
|
|
25
|
+
base64: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare module '@hprint/core' {
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
30
|
+
interface IEditor extends IPlugin {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default class PrintPlugin implements IPluginTempl {
|
|
34
|
+
static pluginName = 'PrintPlugin';
|
|
35
|
+
static apis = ['printPDF', 'getPrinterList'];
|
|
36
|
+
|
|
37
|
+
socket?: any;
|
|
38
|
+
isConnect = false;
|
|
39
|
+
printerList: IPrinterItem[] = [];
|
|
40
|
+
|
|
41
|
+
constructor(
|
|
42
|
+
public canvas: fabric.Canvas,
|
|
43
|
+
public editor: IEditor
|
|
44
|
+
) {
|
|
45
|
+
this.editor = editor;
|
|
46
|
+
this.canvas = canvas;
|
|
47
|
+
|
|
48
|
+
this.socket = io('http://localhost:17521', {
|
|
49
|
+
transports: ['websocket'],
|
|
50
|
+
auth: {
|
|
51
|
+
token: 'vue-plugin-hiprint',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
this.socket.on('connect', () => {
|
|
56
|
+
this.isConnect = true;
|
|
57
|
+
// globalThis.connect = true;
|
|
58
|
+
// TODO: Do something for your project
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
this.socket.on('printerList', (printerList: IPrinterItem[]) => {
|
|
62
|
+
console.log('printerList', printerList);
|
|
63
|
+
this.printerList = printerList;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
printPDF(options: IPrintPDFOption) {
|
|
68
|
+
this.socket.emit('printPDF', {
|
|
69
|
+
...options,
|
|
70
|
+
unit: 'mm',
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getPrinterList() {
|
|
75
|
+
return this.printerList;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
destroy() {
|
|
79
|
+
console.log('pluginDestroy');
|
|
80
|
+
}
|
|
81
|
+
}
|
package/src/plugins/PsdPlugin.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
import { utils } from '@hprint/shared';
|
|
3
|
-
import psdToJson from '../utils/psd';
|
|
4
|
-
import Psd from '@webtoon/psd';
|
|
5
|
-
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
6
|
-
|
|
7
|
-
type IPlugin = Pick<PsdPlugin, 'insertPSD'>;
|
|
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 PsdPlugin implements IPluginTempl {
|
|
15
|
-
static pluginName = 'PsdPlugin';
|
|
16
|
-
static apis = ['insertPSD'];
|
|
17
|
-
constructor(
|
|
18
|
-
public canvas: fabric.Canvas,
|
|
19
|
-
public editor: IEditor
|
|
20
|
-
) {}
|
|
21
|
-
|
|
22
|
-
insertPSD(callback?: () => void) {
|
|
23
|
-
return new Promise((resolve, reject) => {
|
|
24
|
-
utils
|
|
25
|
-
.selectFiles({ accept: '.psd' })
|
|
26
|
-
.then((files) => {
|
|
27
|
-
if (files && files.length > 0) {
|
|
28
|
-
const file = files[0];
|
|
29
|
-
const reader = new FileReader();
|
|
30
|
-
reader.readAsText(file, 'UTF-8');
|
|
31
|
-
reader.onload = async () => {
|
|
32
|
-
const result = await file.arrayBuffer();
|
|
33
|
-
// 解析PSD文件
|
|
34
|
-
const psdFile = Psd.parse(result as ArrayBuffer);
|
|
35
|
-
console.log(psdFile, '11111');
|
|
36
|
-
const json = await psdToJson(psdFile);
|
|
37
|
-
// 加载json
|
|
38
|
-
this.loadJSON(json, callback);
|
|
39
|
-
resolve('');
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
})
|
|
43
|
-
.catch(reject);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
loadJSON(json: string, callback?: () => void) {
|
|
48
|
-
this.editor.loadJSON(json, callback);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default PsdPlugin;
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
import { utils } from '@hprint/shared';
|
|
3
|
+
import psdToJson from '../utils/psd';
|
|
4
|
+
import Psd from '@webtoon/psd';
|
|
5
|
+
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
6
|
+
|
|
7
|
+
type IPlugin = Pick<PsdPlugin, 'insertPSD'>;
|
|
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 PsdPlugin implements IPluginTempl {
|
|
15
|
+
static pluginName = 'PsdPlugin';
|
|
16
|
+
static apis = ['insertPSD'];
|
|
17
|
+
constructor(
|
|
18
|
+
public canvas: fabric.Canvas,
|
|
19
|
+
public editor: IEditor
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
insertPSD(callback?: () => void) {
|
|
23
|
+
return new Promise((resolve, reject) => {
|
|
24
|
+
utils
|
|
25
|
+
.selectFiles({ accept: '.psd' })
|
|
26
|
+
.then((files) => {
|
|
27
|
+
if (files && files.length > 0) {
|
|
28
|
+
const file = files[0];
|
|
29
|
+
const reader = new FileReader();
|
|
30
|
+
reader.readAsText(file, 'UTF-8');
|
|
31
|
+
reader.onload = async () => {
|
|
32
|
+
const result = await file.arrayBuffer();
|
|
33
|
+
// 解析PSD文件
|
|
34
|
+
const psdFile = Psd.parse(result as ArrayBuffer);
|
|
35
|
+
console.log(psdFile, '11111');
|
|
36
|
+
const json = await psdToJson(psdFile);
|
|
37
|
+
// 加载json
|
|
38
|
+
this.loadJSON(json, callback);
|
|
39
|
+
resolve('');
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
.catch(reject);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
loadJSON(json: string, callback?: () => void) {
|
|
48
|
+
this.editor.loadJSON(json, callback);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export default PsdPlugin;
|
|
@@ -4,7 +4,7 @@ import { utils } from '@hprint/shared';
|
|
|
4
4
|
import { getUnit, processOptions, formatOriginValues } from '../utils/units';
|
|
5
5
|
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
6
6
|
|
|
7
|
-
type IPlugin = Pick<QrCodePlugin, 'addQrCode' | 'setQrCode'>;
|
|
7
|
+
type IPlugin = Pick<QrCodePlugin, 'addQrCode' | 'setQrCode' | 'initQrcodeEvents'>;
|
|
8
8
|
|
|
9
9
|
declare module '@hprint/core' {
|
|
10
10
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
@@ -13,7 +13,7 @@ declare module '@hprint/core' {
|
|
|
13
13
|
|
|
14
14
|
class QrCodePlugin implements IPluginTempl {
|
|
15
15
|
static pluginName = 'QrCodePlugin';
|
|
16
|
-
static apis = ['addQrCode', 'setQrCode'];
|
|
16
|
+
static apis = ['addQrCode', 'setQrCode', 'initQrcodeEvents'];
|
|
17
17
|
constructor(
|
|
18
18
|
public canvas: fabric.Canvas,
|
|
19
19
|
public editor: IEditor
|
|
@@ -47,7 +47,7 @@ class QrCodePlugin implements IPluginTempl {
|
|
|
47
47
|
|
|
48
48
|
async hookTransformObjectEnd({ originObject, fabricObject }: { originObject: any, fabricObject: any }) {
|
|
49
49
|
if (originObject.extensionType === 'qrcode') {
|
|
50
|
-
this.
|
|
50
|
+
this.initQrcodeEvents(fabricObject);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -180,7 +180,7 @@ class QrCodePlugin implements IPluginTempl {
|
|
|
180
180
|
/**
|
|
181
181
|
* 绑定二维码相关事件与方法
|
|
182
182
|
*/
|
|
183
|
-
|
|
183
|
+
initQrcodeEvents(imgEl: fabric.Image) {
|
|
184
184
|
(imgEl as any).setExtension = async (fields: Record<string, any>) => {
|
|
185
185
|
const currentExt = (imgEl.get('extension') as any) || {};
|
|
186
186
|
const merged = { ...currentExt, ...(fields || {}) };
|
|
@@ -279,7 +279,7 @@ class QrCodePlugin implements IPluginTempl {
|
|
|
279
279
|
originMapped.height = originMapped.width;
|
|
280
280
|
}
|
|
281
281
|
(imgEl as any)._originSize = { [unit]: originMapped };
|
|
282
|
-
this.
|
|
282
|
+
this.initQrcodeEvents(imgEl);
|
|
283
283
|
resolve(imgEl);
|
|
284
284
|
},
|
|
285
285
|
{ crossOrigin: 'anonymous' }
|
|
@@ -302,7 +302,7 @@ class QrCodePlugin implements IPluginTempl {
|
|
|
302
302
|
extension: { ...option },
|
|
303
303
|
});
|
|
304
304
|
imgEl.scaleToWidth(activeObject.getScaledWidth());
|
|
305
|
-
this.
|
|
305
|
+
this.initQrcodeEvents(imgEl);
|
|
306
306
|
this.editor.del();
|
|
307
307
|
this.canvas.add(imgEl);
|
|
308
308
|
this.canvas.setActiveObject(imgEl);
|