@hprint/plugins 0.0.1-alpha.1 → 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.
- package/dist/index.js +122 -117
- package/dist/index.mjs +41257 -21115
- package/dist/src/plugins/AlignGuidLinePlugin.d.ts +7 -2
- package/dist/src/plugins/AlignGuidLinePlugin.d.ts.map +1 -1
- package/dist/src/plugins/BarCodePlugin.d.ts +4 -0
- package/dist/src/plugins/BarCodePlugin.d.ts.map +1 -1
- package/dist/src/plugins/CreateElementPlugin.d.ts +3 -9
- package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -1
- package/dist/src/plugins/GroupAlignPlugin.d.ts.map +1 -1
- package/dist/src/plugins/LockPlugin.d.ts.map +1 -1
- package/dist/src/plugins/QrCodePlugin.d.ts +19 -97
- package/dist/src/plugins/QrCodePlugin.d.ts.map +1 -1
- package/dist/src/plugins/ResizePlugin.d.ts.map +1 -1
- package/dist/src/plugins/UnitPlugin.d.ts.map +1 -1
- package/dist/src/plugins/WorkspacePlugin.d.ts.map +1 -1
- package/dist/src/utils/units.d.ts.map +1 -1
- package/package.json +5 -4
- 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/AlignGuidLinePlugin.ts +1152 -1141
- package/src/plugins/BarCodePlugin.ts +33 -27
- package/src/plugins/ControlsPlugin.ts +251 -251
- package/src/plugins/ControlsRotatePlugin.ts +111 -111
- package/src/plugins/CopyPlugin.ts +255 -255
- package/src/plugins/CreateElementPlugin.ts +14 -10
- 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/GroupAlignPlugin.ts +365 -365
- 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/LockPlugin.ts +242 -240
- 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 +322 -393
- package/src/plugins/ResizePlugin.ts +278 -274
- package/src/plugins/RulerPlugin.ts +78 -78
- package/src/plugins/SimpleClipImagePlugin.ts +244 -244
- package/src/plugins/UnitPlugin.ts +326 -327
- package/src/plugins/WaterMarkPlugin.ts +257 -257
- package/src/plugins/WorkspacePlugin.ts +10 -6
- 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/ruler.ts +924 -924
- package/src/utils/ruler/utils.ts +162 -162
- package/src/utils/units.ts +4 -2
- package/tsconfig.json +10 -10
- package/vite.config.ts +29 -29
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
3
|
-
import { SelectMode } from '../types/eventType';
|
|
4
|
-
|
|
5
|
-
type IPlugin = Pick<FlipPlugin, 'flip'>;
|
|
6
|
-
|
|
7
|
-
declare module '@hprint/core' {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
9
|
-
interface IEditor extends IPlugin {}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// import event from '@/utils/event/notifier';
|
|
13
|
-
|
|
14
|
-
export default class FlipPlugin implements IPluginTempl {
|
|
15
|
-
static pluginName = 'FlipPlugin';
|
|
16
|
-
static apis = ['flip'];
|
|
17
|
-
constructor(
|
|
18
|
-
public canvas: fabric.Canvas,
|
|
19
|
-
public editor: IEditor
|
|
20
|
-
) {}
|
|
21
|
-
|
|
22
|
-
flip(type: 'X' | 'Y') {
|
|
23
|
-
const activeObject = this.canvas.getActiveObject();
|
|
24
|
-
if (activeObject) {
|
|
25
|
-
activeObject
|
|
26
|
-
.set(`flip${type}`, !activeObject[`flip${type}`])
|
|
27
|
-
.setCoords();
|
|
28
|
-
this.canvas.requestRenderAll();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
contextMenu() {
|
|
33
|
-
const selectedMode = this.editor.getSelectMode();
|
|
34
|
-
if (selectedMode === SelectMode.ONE) {
|
|
35
|
-
return [
|
|
36
|
-
{
|
|
37
|
-
text: '翻转',
|
|
38
|
-
hotkey: '❯',
|
|
39
|
-
subitems: [
|
|
40
|
-
{
|
|
41
|
-
text: '水平翻转',
|
|
42
|
-
hotkey: '|',
|
|
43
|
-
onclick: () => this.flip('X'),
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
text: '垂直翻转',
|
|
47
|
-
hotkey: '-',
|
|
48
|
-
onclick: () => this.flip('Y'),
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
destroy() {
|
|
57
|
-
console.log('pluginDestroy');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
3
|
+
import { SelectMode } from '../types/eventType';
|
|
4
|
+
|
|
5
|
+
type IPlugin = Pick<FlipPlugin, 'flip'>;
|
|
6
|
+
|
|
7
|
+
declare module '@hprint/core' {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
9
|
+
interface IEditor extends IPlugin {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// import event from '@/utils/event/notifier';
|
|
13
|
+
|
|
14
|
+
export default class FlipPlugin implements IPluginTempl {
|
|
15
|
+
static pluginName = 'FlipPlugin';
|
|
16
|
+
static apis = ['flip'];
|
|
17
|
+
constructor(
|
|
18
|
+
public canvas: fabric.Canvas,
|
|
19
|
+
public editor: IEditor
|
|
20
|
+
) {}
|
|
21
|
+
|
|
22
|
+
flip(type: 'X' | 'Y') {
|
|
23
|
+
const activeObject = this.canvas.getActiveObject();
|
|
24
|
+
if (activeObject) {
|
|
25
|
+
activeObject
|
|
26
|
+
.set(`flip${type}`, !activeObject[`flip${type}`])
|
|
27
|
+
.setCoords();
|
|
28
|
+
this.canvas.requestRenderAll();
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
contextMenu() {
|
|
33
|
+
const selectedMode = this.editor.getSelectMode();
|
|
34
|
+
if (selectedMode === SelectMode.ONE) {
|
|
35
|
+
return [
|
|
36
|
+
{
|
|
37
|
+
text: '翻转',
|
|
38
|
+
hotkey: '❯',
|
|
39
|
+
subitems: [
|
|
40
|
+
{
|
|
41
|
+
text: '水平翻转',
|
|
42
|
+
hotkey: '|',
|
|
43
|
+
onclick: () => this.flip('X'),
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
text: '垂直翻转',
|
|
47
|
+
hotkey: '-',
|
|
48
|
+
onclick: () => this.flip('Y'),
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
destroy() {
|
|
57
|
+
console.log('pluginDestroy');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,165 +1,165 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
import FontFaceObserver from 'fontfaceobserver';
|
|
3
|
-
import axios from 'axios';
|
|
4
|
-
import { utils } from '@hprint/shared';
|
|
5
|
-
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
6
|
-
|
|
7
|
-
type IPlugin = Pick<
|
|
8
|
-
FontPlugin,
|
|
9
|
-
'getFontList' | 'loadFont' | 'getFontJson' | 'downFontByJSON'
|
|
10
|
-
>;
|
|
11
|
-
|
|
12
|
-
declare module '@hprint/core' {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
14
|
-
interface IEditor extends IPlugin {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface Font {
|
|
18
|
-
type: string;
|
|
19
|
-
fontFamily: string;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface FontSource {
|
|
23
|
-
name: string;
|
|
24
|
-
type: string;
|
|
25
|
-
file: string;
|
|
26
|
-
img: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
class FontPlugin implements IPluginTempl {
|
|
30
|
-
private tempPromise: Promise<FontSource[]> | null;
|
|
31
|
-
static pluginName = 'FontPlugin';
|
|
32
|
-
static apis = ['getFontList', 'loadFont', 'getFontJson', 'downFontByJSON'];
|
|
33
|
-
repoSrc: string;
|
|
34
|
-
cacheList: FontSource[];
|
|
35
|
-
constructor(
|
|
36
|
-
public canvas: fabric.Canvas,
|
|
37
|
-
public editor: IEditor,
|
|
38
|
-
config: { repoSrc: string }
|
|
39
|
-
) {
|
|
40
|
-
this.repoSrc = config.repoSrc;
|
|
41
|
-
this.cacheList = [];
|
|
42
|
-
this.tempPromise = null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
hookImportBefore(json: string) {
|
|
46
|
-
return this.downFontByJSON(json);
|
|
47
|
-
}
|
|
48
|
-
getFontList() {
|
|
49
|
-
// 返回暂存字体
|
|
50
|
-
if (this.cacheList.length) {
|
|
51
|
-
return Promise.resolve(this.cacheList);
|
|
52
|
-
}
|
|
53
|
-
if (this.tempPromise) return this.tempPromise;
|
|
54
|
-
this.tempPromise = axios
|
|
55
|
-
.get(
|
|
56
|
-
`${this.repoSrc}/api/fonts?populate=*&pagination[pageSize]=100`
|
|
57
|
-
)
|
|
58
|
-
.then((res) => {
|
|
59
|
-
const list = res.data.data.map((item: any) => {
|
|
60
|
-
return {
|
|
61
|
-
name: item.attributes.name,
|
|
62
|
-
type: item.attributes.type,
|
|
63
|
-
file:
|
|
64
|
-
this.repoSrc +
|
|
65
|
-
item.attributes.file.data.attributes.url,
|
|
66
|
-
img:
|
|
67
|
-
this.repoSrc +
|
|
68
|
-
item.attributes.img.data.attributes.url,
|
|
69
|
-
};
|
|
70
|
-
});
|
|
71
|
-
this.cacheList = list;
|
|
72
|
-
this.createFontCSS(list);
|
|
73
|
-
return list;
|
|
74
|
-
});
|
|
75
|
-
return this.tempPromise;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
downFontByJSON(str: string) {
|
|
79
|
-
const object = JSON.parse(str);
|
|
80
|
-
let fontFamilies: string[] = [];
|
|
81
|
-
const skipFonts = ['arial'];
|
|
82
|
-
if (object.objects) {
|
|
83
|
-
fontFamilies = JSON.parse(str)
|
|
84
|
-
.objects.filter((item: Font) => {
|
|
85
|
-
const hasFontFile = this.cacheList.find(
|
|
86
|
-
(font) => font.name === item.fontFamily
|
|
87
|
-
);
|
|
88
|
-
return (
|
|
89
|
-
item.type.includes('text') &&
|
|
90
|
-
!skipFonts.includes(item.fontFamily) &&
|
|
91
|
-
hasFontFile
|
|
92
|
-
);
|
|
93
|
-
})
|
|
94
|
-
.map((item: Font) => item.fontFamily);
|
|
95
|
-
} else {
|
|
96
|
-
fontFamilies = skipFonts.includes(object.fontFamily)
|
|
97
|
-
? []
|
|
98
|
-
: [object.fontFamily];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const fontFamiliesAll = fontFamilies.map((fontName) => {
|
|
102
|
-
const font = new FontFaceObserver(fontName);
|
|
103
|
-
return font.load(null, 150000);
|
|
104
|
-
});
|
|
105
|
-
return Promise.all(fontFamiliesAll);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// 获取字体数据 新增字体样式使用
|
|
109
|
-
getFontJson() {
|
|
110
|
-
const activeObject = this.canvas.getActiveObject();
|
|
111
|
-
if (activeObject) {
|
|
112
|
-
const json = activeObject.toJSON([
|
|
113
|
-
'id',
|
|
114
|
-
'gradientAngle',
|
|
115
|
-
'selectable',
|
|
116
|
-
'hasControls',
|
|
117
|
-
]);
|
|
118
|
-
const fileStr = `data:text/json;charset=utf-8,${encodeURIComponent(
|
|
119
|
-
JSON.stringify(json, null, '\t')
|
|
120
|
-
)}`;
|
|
121
|
-
const dataUrl = activeObject.toDataURL({});
|
|
122
|
-
utils.downFile(fileStr, 'font.json');
|
|
123
|
-
utils.downFile(dataUrl, 'font.png');
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
loadFont(fontName: string) {
|
|
128
|
-
const font = new FontFaceObserver(fontName);
|
|
129
|
-
return font.load(null, 150000).then(() => {
|
|
130
|
-
const activeObject = this.canvas.getActiveObjects()[0];
|
|
131
|
-
if (activeObject) {
|
|
132
|
-
activeObject.set('fontFamily', fontName);
|
|
133
|
-
this.canvas.renderAll();
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
createFontCSS(arr: any[]) {
|
|
139
|
-
let code = '';
|
|
140
|
-
arr.forEach((item) => {
|
|
141
|
-
code =
|
|
142
|
-
code +
|
|
143
|
-
`
|
|
144
|
-
@font-face {
|
|
145
|
-
font-family: ${item.name};
|
|
146
|
-
src: url('${item.file}');
|
|
147
|
-
}
|
|
148
|
-
`;
|
|
149
|
-
});
|
|
150
|
-
const style = document.createElement('style');
|
|
151
|
-
try {
|
|
152
|
-
style.appendChild(document.createTextNode(code));
|
|
153
|
-
} catch (error) {
|
|
154
|
-
// style.styleSheet.cssText = code;
|
|
155
|
-
}
|
|
156
|
-
const head = document.getElementsByTagName('head')[0];
|
|
157
|
-
head.appendChild(style);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
destroy() {
|
|
161
|
-
console.log('pluginDestroy');
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
export default FontPlugin;
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
import FontFaceObserver from 'fontfaceobserver';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import { utils } from '@hprint/shared';
|
|
5
|
+
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
6
|
+
|
|
7
|
+
type IPlugin = Pick<
|
|
8
|
+
FontPlugin,
|
|
9
|
+
'getFontList' | 'loadFont' | 'getFontJson' | 'downFontByJSON'
|
|
10
|
+
>;
|
|
11
|
+
|
|
12
|
+
declare module '@hprint/core' {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
14
|
+
interface IEditor extends IPlugin {}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Font {
|
|
18
|
+
type: string;
|
|
19
|
+
fontFamily: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface FontSource {
|
|
23
|
+
name: string;
|
|
24
|
+
type: string;
|
|
25
|
+
file: string;
|
|
26
|
+
img: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
class FontPlugin implements IPluginTempl {
|
|
30
|
+
private tempPromise: Promise<FontSource[]> | null;
|
|
31
|
+
static pluginName = 'FontPlugin';
|
|
32
|
+
static apis = ['getFontList', 'loadFont', 'getFontJson', 'downFontByJSON'];
|
|
33
|
+
repoSrc: string;
|
|
34
|
+
cacheList: FontSource[];
|
|
35
|
+
constructor(
|
|
36
|
+
public canvas: fabric.Canvas,
|
|
37
|
+
public editor: IEditor,
|
|
38
|
+
config: { repoSrc: string }
|
|
39
|
+
) {
|
|
40
|
+
this.repoSrc = config.repoSrc;
|
|
41
|
+
this.cacheList = [];
|
|
42
|
+
this.tempPromise = null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
hookImportBefore(json: string) {
|
|
46
|
+
return this.downFontByJSON(json);
|
|
47
|
+
}
|
|
48
|
+
getFontList() {
|
|
49
|
+
// 返回暂存字体
|
|
50
|
+
if (this.cacheList.length) {
|
|
51
|
+
return Promise.resolve(this.cacheList);
|
|
52
|
+
}
|
|
53
|
+
if (this.tempPromise) return this.tempPromise;
|
|
54
|
+
this.tempPromise = axios
|
|
55
|
+
.get(
|
|
56
|
+
`${this.repoSrc}/api/fonts?populate=*&pagination[pageSize]=100`
|
|
57
|
+
)
|
|
58
|
+
.then((res) => {
|
|
59
|
+
const list = res.data.data.map((item: any) => {
|
|
60
|
+
return {
|
|
61
|
+
name: item.attributes.name,
|
|
62
|
+
type: item.attributes.type,
|
|
63
|
+
file:
|
|
64
|
+
this.repoSrc +
|
|
65
|
+
item.attributes.file.data.attributes.url,
|
|
66
|
+
img:
|
|
67
|
+
this.repoSrc +
|
|
68
|
+
item.attributes.img.data.attributes.url,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
this.cacheList = list;
|
|
72
|
+
this.createFontCSS(list);
|
|
73
|
+
return list;
|
|
74
|
+
});
|
|
75
|
+
return this.tempPromise;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
downFontByJSON(str: string) {
|
|
79
|
+
const object = JSON.parse(str);
|
|
80
|
+
let fontFamilies: string[] = [];
|
|
81
|
+
const skipFonts = ['arial'];
|
|
82
|
+
if (object.objects) {
|
|
83
|
+
fontFamilies = JSON.parse(str)
|
|
84
|
+
.objects.filter((item: Font) => {
|
|
85
|
+
const hasFontFile = this.cacheList.find(
|
|
86
|
+
(font) => font.name === item.fontFamily
|
|
87
|
+
);
|
|
88
|
+
return (
|
|
89
|
+
item.type.includes('text') &&
|
|
90
|
+
!skipFonts.includes(item.fontFamily) &&
|
|
91
|
+
hasFontFile
|
|
92
|
+
);
|
|
93
|
+
})
|
|
94
|
+
.map((item: Font) => item.fontFamily);
|
|
95
|
+
} else {
|
|
96
|
+
fontFamilies = skipFonts.includes(object.fontFamily)
|
|
97
|
+
? []
|
|
98
|
+
: [object.fontFamily];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const fontFamiliesAll = fontFamilies.map((fontName) => {
|
|
102
|
+
const font = new FontFaceObserver(fontName);
|
|
103
|
+
return font.load(null, 150000);
|
|
104
|
+
});
|
|
105
|
+
return Promise.all(fontFamiliesAll);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 获取字体数据 新增字体样式使用
|
|
109
|
+
getFontJson() {
|
|
110
|
+
const activeObject = this.canvas.getActiveObject();
|
|
111
|
+
if (activeObject) {
|
|
112
|
+
const json = activeObject.toJSON([
|
|
113
|
+
'id',
|
|
114
|
+
'gradientAngle',
|
|
115
|
+
'selectable',
|
|
116
|
+
'hasControls',
|
|
117
|
+
]);
|
|
118
|
+
const fileStr = `data:text/json;charset=utf-8,${encodeURIComponent(
|
|
119
|
+
JSON.stringify(json, null, '\t')
|
|
120
|
+
)}`;
|
|
121
|
+
const dataUrl = activeObject.toDataURL({});
|
|
122
|
+
utils.downFile(fileStr, 'font.json');
|
|
123
|
+
utils.downFile(dataUrl, 'font.png');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
loadFont(fontName: string) {
|
|
128
|
+
const font = new FontFaceObserver(fontName);
|
|
129
|
+
return font.load(null, 150000).then(() => {
|
|
130
|
+
const activeObject = this.canvas.getActiveObjects()[0];
|
|
131
|
+
if (activeObject) {
|
|
132
|
+
activeObject.set('fontFamily', fontName);
|
|
133
|
+
this.canvas.renderAll();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
createFontCSS(arr: any[]) {
|
|
139
|
+
let code = '';
|
|
140
|
+
arr.forEach((item) => {
|
|
141
|
+
code =
|
|
142
|
+
code +
|
|
143
|
+
`
|
|
144
|
+
@font-face {
|
|
145
|
+
font-family: ${item.name};
|
|
146
|
+
src: url('${item.file}');
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
});
|
|
150
|
+
const style = document.createElement('style');
|
|
151
|
+
try {
|
|
152
|
+
style.appendChild(document.createTextNode(code));
|
|
153
|
+
} catch (error) {
|
|
154
|
+
// style.styleSheet.cssText = code;
|
|
155
|
+
}
|
|
156
|
+
const head = document.getElementsByTagName('head')[0];
|
|
157
|
+
head.appendChild(style);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
destroy() {
|
|
161
|
+
console.log('pluginDestroy');
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export default FontPlugin;
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
import { v4 as uuid } from 'uuid';
|
|
3
|
-
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
4
|
-
|
|
5
|
-
type IPlugin = Pick<FreeDrawPlugin, 'startDraw' | 'endDraw'>;
|
|
6
|
-
|
|
7
|
-
declare module '@hprint/core' {
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
9
|
-
interface IEditor extends IPlugin {}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
type DrawOptions = {
|
|
13
|
-
width: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default class FreeDrawPlugin implements IPluginTempl {
|
|
17
|
-
static pluginName = 'FreeDrawPlugin';
|
|
18
|
-
static apis = ['startDraw', 'endDraw'];
|
|
19
|
-
constructor(
|
|
20
|
-
public canvas: fabric.Canvas,
|
|
21
|
-
public editor: IEditor
|
|
22
|
-
) {}
|
|
23
|
-
|
|
24
|
-
_bindEvent() {
|
|
25
|
-
this.canvas.on('path:created', this._createdHandler);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
_unbindEvent() {
|
|
29
|
-
this.canvas.off('path:created', this._createdHandler);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
_createdHandler = (opt: any) => {
|
|
33
|
-
opt.path.set('id', uuid());
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
startDraw(options: DrawOptions) {
|
|
37
|
-
this.canvas.isDrawingMode = true;
|
|
38
|
-
this.canvas.freeDrawingBrush = new fabric.PencilBrush(this.canvas);
|
|
39
|
-
this.canvas.freeDrawingBrush.width = options.width;
|
|
40
|
-
this._bindEvent();
|
|
41
|
-
}
|
|
42
|
-
endDraw() {
|
|
43
|
-
if (this.canvas.isDrawingMode) {
|
|
44
|
-
this.canvas.isDrawingMode = false;
|
|
45
|
-
this._unbindEvent();
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
import { v4 as uuid } from 'uuid';
|
|
3
|
+
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
4
|
+
|
|
5
|
+
type IPlugin = Pick<FreeDrawPlugin, 'startDraw' | 'endDraw'>;
|
|
6
|
+
|
|
7
|
+
declare module '@hprint/core' {
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
9
|
+
interface IEditor extends IPlugin {}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type DrawOptions = {
|
|
13
|
+
width: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default class FreeDrawPlugin implements IPluginTempl {
|
|
17
|
+
static pluginName = 'FreeDrawPlugin';
|
|
18
|
+
static apis = ['startDraw', 'endDraw'];
|
|
19
|
+
constructor(
|
|
20
|
+
public canvas: fabric.Canvas,
|
|
21
|
+
public editor: IEditor
|
|
22
|
+
) {}
|
|
23
|
+
|
|
24
|
+
_bindEvent() {
|
|
25
|
+
this.canvas.on('path:created', this._createdHandler);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
_unbindEvent() {
|
|
29
|
+
this.canvas.off('path:created', this._createdHandler);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_createdHandler = (opt: any) => {
|
|
33
|
+
opt.path.set('id', uuid());
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
startDraw(options: DrawOptions) {
|
|
37
|
+
this.canvas.isDrawingMode = true;
|
|
38
|
+
this.canvas.freeDrawingBrush = new fabric.PencilBrush(this.canvas);
|
|
39
|
+
this.canvas.freeDrawingBrush.width = options.width;
|
|
40
|
+
this._bindEvent();
|
|
41
|
+
}
|
|
42
|
+
endDraw() {
|
|
43
|
+
if (this.canvas.isDrawingMode) {
|
|
44
|
+
this.canvas.isDrawingMode = false;
|
|
45
|
+
this._unbindEvent();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|