@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.
- package/dist/index.js +17 -17
- package/dist/index.mjs +1282 -1277
- package/dist/src/plugins/CreateElementPlugin.d.ts +4 -0
- package/dist/src/plugins/CreateElementPlugin.d.ts.map +1 -1
- package/dist/src/utils/ruler/ruler.d.ts +1 -0
- package/dist/src/utils/ruler/ruler.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/AlignGuidLinePlugin.ts +1152 -1152
- 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 +23 -2
- 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 -242
- 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/ResizePlugin.ts +278 -278
- package/src/plugins/RulerPlugin.ts +78 -78
- package/src/plugins/SimpleClipImagePlugin.ts +244 -244
- package/src/plugins/UnitPlugin.ts +326 -326
- package/src/plugins/WaterMarkPlugin.ts +257 -257
- 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 +936 -924
- package/src/utils/ruler/utils.ts +162 -162
- package/tsconfig.json +10 -10
- 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;
|