@hprint/plugins 0.0.1-alpha.2 → 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 +20 -20
- package/dist/index.mjs +2258 -2239
- package/dist/src/plugins/AlignGuidLinePlugin.d.ts +7 -2
- package/dist/src/plugins/AlignGuidLinePlugin.d.ts.map +1 -1
- package/dist/src/plugins/CreateElementPlugin.d.ts +4 -0
- 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 +5 -0
- package/dist/src/plugins/QrCodePlugin.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/plugins/AlignGuidLinePlugin.ts +195 -184
- package/src/plugins/BarCodePlugin.ts +2 -2
- package/src/plugins/CreateElementPlugin.ts +23 -2
- package/src/plugins/GroupAlignPlugin.ts +2 -2
- package/src/plugins/LockPlugin.ts +3 -1
- package/src/plugins/QrCodePlugin.ts +322 -329
- package/src/utils/ruler/ruler.ts +13 -1
|
@@ -48,8 +48,8 @@ class BarCodePlugin implements IPluginTempl {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
async hookTransformObjectEnd({ originObject, fabricObject }: { originObject: any, fabricObject: any }) {
|
|
51
|
-
if (originObject.extensionType === '
|
|
52
|
-
this.
|
|
51
|
+
if (originObject.extensionType === 'barcode') {
|
|
52
|
+
this._bindBarcodeEvents(fabricObject);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -54,7 +54,11 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
54
54
|
public editor: IEditor
|
|
55
55
|
) { }
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
async hookTransformObjectEnd({ originObject, fabricObject }: { originObject: any, fabricObject: any }) {
|
|
58
|
+
if (fabricObject) {
|
|
59
|
+
this.addSetAndSyncByUnit(fabricObject);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
58
62
|
|
|
59
63
|
private _processPoints(points: Array<{ x: number; y: number }>, dpi?: number): { processed: Array<{ x: number; y: number }>; originByUnit: Record<string, Record<string, any>> } {
|
|
60
64
|
const hasCfg = CreateElementPlugin.lengthFieldConfigs.some(
|
|
@@ -101,6 +105,12 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
101
105
|
if (value !== undefined) {
|
|
102
106
|
const processedVal = convertSingle(value, unit, dpi);
|
|
103
107
|
mergeOrigin(this, unit, { [field]: value });
|
|
108
|
+
if (this.type === 'image' && (field === 'width' || field === 'height')) {
|
|
109
|
+
if (field === 'width') {
|
|
110
|
+
return originalSet('scaleX', processedVal / (this.width || 1));
|
|
111
|
+
}
|
|
112
|
+
return originalSet('scaleY', processedVal / (this.height || 1));
|
|
113
|
+
}
|
|
104
114
|
return originalSet(field, processedVal);
|
|
105
115
|
}
|
|
106
116
|
}
|
|
@@ -136,7 +146,18 @@ class CreateElementPlugin implements IPluginTempl {
|
|
|
136
146
|
const { processed, originByUnit } = processOptions(opts, unit, dpi, singleFields);
|
|
137
147
|
const originUnit = originByUnit[unit] || {};
|
|
138
148
|
if (Object.keys(originUnit).length) mergeOrigin(this, unit, originUnit);
|
|
139
|
-
|
|
149
|
+
const finalProps = { ...opts, ...processed };
|
|
150
|
+
if (this.type === 'image') {
|
|
151
|
+
if (finalProps.width !== undefined) {
|
|
152
|
+
finalProps.scaleX = finalProps.width / (this.width || 1);
|
|
153
|
+
delete finalProps.width;
|
|
154
|
+
}
|
|
155
|
+
if (finalProps.height !== undefined) {
|
|
156
|
+
finalProps.scaleY = finalProps.height / (this.height || 1);
|
|
157
|
+
delete finalProps.height;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return originalSet(finalProps);
|
|
140
161
|
}
|
|
141
162
|
return originalSet(key, value);
|
|
142
163
|
};
|
|
@@ -15,7 +15,7 @@ type IPlugin = Pick<
|
|
|
15
15
|
|
|
16
16
|
declare module '@hprint/core' {
|
|
17
17
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
18
|
-
interface IEditor extends IPlugin {}
|
|
18
|
+
interface IEditor extends IPlugin { }
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
class GroupAlignPlugin implements IPluginTempl {
|
|
@@ -34,7 +34,7 @@ class GroupAlignPlugin implements IPluginTempl {
|
|
|
34
34
|
constructor(
|
|
35
35
|
public canvas: fabric.Canvas,
|
|
36
36
|
public editor: IEditor
|
|
37
|
-
) {}
|
|
37
|
+
) { }
|
|
38
38
|
|
|
39
39
|
left() {
|
|
40
40
|
const { canvas } = this;
|
|
@@ -9,7 +9,7 @@ type IPlugin = Pick<LockPlugin, 'lock' | 'unLock'>;
|
|
|
9
9
|
|
|
10
10
|
declare module '@hprint/core' {
|
|
11
11
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
12
|
-
interface IEditor extends IPlugin {}
|
|
12
|
+
interface IEditor extends IPlugin { }
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
enum ItypeKey {
|
|
@@ -181,6 +181,8 @@ export default class LockPlugin implements IPluginTempl {
|
|
|
181
181
|
|
|
182
182
|
hookImportAfter() {
|
|
183
183
|
this.canvas.forEachObject((obj: fabric.Object) => {
|
|
184
|
+
// 避免导入JSON后选中画布
|
|
185
|
+
if (obj.id === 'workspace') return;
|
|
184
186
|
if (obj.hasControls === false && obj.selectable === false) {
|
|
185
187
|
this.canvas.setActiveObject(obj);
|
|
186
188
|
this.lock();
|