@hprint/plugins 0.0.2 → 0.0.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/package.json +3 -3
- package/src/plugins/AlignGuidLinePlugin.ts +1152 -1152
- package/src/plugins/GroupAlignPlugin.ts +365 -365
- package/src/plugins/LockPlugin.ts +242 -242
- package/src/plugins/ResizePlugin.ts +278 -278
- package/src/plugins/RulerPlugin.ts +78 -78
- package/src/plugins/UnitPlugin.ts +348 -348
- package/src/plugins/WaterMarkPlugin.ts +257 -257
- package/src/utils/ruler/ruler.ts +936 -936
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { fabric } from '@hprint/core';
|
|
2
|
-
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
3
|
-
|
|
4
|
-
type IPlugin = Pick<
|
|
5
|
-
RulerPlugin,
|
|
6
|
-
'hideGuideline' | 'showGuideline' | 'rulerEnable' | 'rulerDisable'
|
|
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
|
-
import initRuler from '../utils/ruler';
|
|
15
|
-
|
|
16
|
-
class RulerPlugin implements IPluginTempl {
|
|
17
|
-
static pluginName = 'RulerPlugin';
|
|
18
|
-
// static events = ['sizeChange'];
|
|
19
|
-
static apis = [
|
|
20
|
-
'hideGuideline',
|
|
21
|
-
'showGuideline',
|
|
22
|
-
'rulerEnable',
|
|
23
|
-
'rulerDisable',
|
|
24
|
-
];
|
|
25
|
-
ruler: any;
|
|
26
|
-
constructor(
|
|
27
|
-
public canvas: fabric.Canvas,
|
|
28
|
-
public editor: IEditor
|
|
29
|
-
) {
|
|
30
|
-
this.init();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
hookSaveBefore() {
|
|
34
|
-
return new Promise((resolve) => {
|
|
35
|
-
this.hideGuideline();
|
|
36
|
-
resolve(true);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
hookSaveAfter() {
|
|
41
|
-
return new Promise((resolve) => {
|
|
42
|
-
this.showGuideline();
|
|
43
|
-
resolve(true);
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
init() {
|
|
48
|
-
this.ruler = initRuler(this.canvas, this.editor, {
|
|
49
|
-
unit: (this.editor.getUnit?.() as 'px' | 'mm') || 'px',
|
|
50
|
-
});
|
|
51
|
-
// 监听全局单位变化,更新标尺展示
|
|
52
|
-
this.editor.on?.('unitChange', (unit: 'px' | 'mm') => {
|
|
53
|
-
this.ruler?.setUnit?.(unit);
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
hideGuideline() {
|
|
58
|
-
this.ruler.hideGuideline();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
showGuideline() {
|
|
62
|
-
this.ruler.showGuideline();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
rulerEnable() {
|
|
66
|
-
this.ruler.enable();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
rulerDisable() {
|
|
70
|
-
this.ruler.disable();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
destroy() {
|
|
74
|
-
console.log('pluginDestroy');
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default RulerPlugin;
|
|
1
|
+
import { fabric } from '@hprint/core';
|
|
2
|
+
import type { IEditor, IPluginTempl } from '@hprint/core';
|
|
3
|
+
|
|
4
|
+
type IPlugin = Pick<
|
|
5
|
+
RulerPlugin,
|
|
6
|
+
'hideGuideline' | 'showGuideline' | 'rulerEnable' | 'rulerDisable'
|
|
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
|
+
import initRuler from '../utils/ruler';
|
|
15
|
+
|
|
16
|
+
class RulerPlugin implements IPluginTempl {
|
|
17
|
+
static pluginName = 'RulerPlugin';
|
|
18
|
+
// static events = ['sizeChange'];
|
|
19
|
+
static apis = [
|
|
20
|
+
'hideGuideline',
|
|
21
|
+
'showGuideline',
|
|
22
|
+
'rulerEnable',
|
|
23
|
+
'rulerDisable',
|
|
24
|
+
];
|
|
25
|
+
ruler: any;
|
|
26
|
+
constructor(
|
|
27
|
+
public canvas: fabric.Canvas,
|
|
28
|
+
public editor: IEditor
|
|
29
|
+
) {
|
|
30
|
+
this.init();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
hookSaveBefore() {
|
|
34
|
+
return new Promise((resolve) => {
|
|
35
|
+
this.hideGuideline();
|
|
36
|
+
resolve(true);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
hookSaveAfter() {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
this.showGuideline();
|
|
43
|
+
resolve(true);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
init() {
|
|
48
|
+
this.ruler = initRuler(this.canvas, this.editor, {
|
|
49
|
+
unit: (this.editor.getUnit?.() as 'px' | 'mm') || 'px',
|
|
50
|
+
});
|
|
51
|
+
// 监听全局单位变化,更新标尺展示
|
|
52
|
+
this.editor.on?.('unitChange', (unit: 'px' | 'mm') => {
|
|
53
|
+
this.ruler?.setUnit?.(unit);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
hideGuideline() {
|
|
58
|
+
this.ruler.hideGuideline();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
showGuideline() {
|
|
62
|
+
this.ruler.showGuideline();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
rulerEnable() {
|
|
66
|
+
this.ruler.enable();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
rulerDisable() {
|
|
70
|
+
this.ruler.disable();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
destroy() {
|
|
74
|
+
console.log('pluginDestroy');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default RulerPlugin;
|