@hprint/plugins 0.0.9-alpha.0 → 0.0.9-alpha.1

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.
@@ -45,11 +45,29 @@ class QrCodePlugin implements IPluginTempl {
45
45
  }
46
46
  }
47
47
 
48
- async hookTransformObjectEnd({ originObject, fabricObject }: { originObject: any, fabricObject: any }) {
49
- if (originObject.extensionType === 'qrcode') {
50
- this.initQrcodeEvents(fabricObject);
51
- }
52
- }
48
+ async hookTransformObjectEnd({ originObject, fabricObject }: { originObject: any, fabricObject: any }) {
49
+ if (originObject.extensionType === 'qrcode') {
50
+ this.initQrcodeEvents(fabricObject);
51
+ }
52
+ }
53
+
54
+ async hookImportAfter() {
55
+ const qrcodeObjects = this.canvas
56
+ .getObjects()
57
+ .filter(
58
+ (obj: any) =>
59
+ obj.type === 'image' && obj.extensionType === 'qrcode'
60
+ ) as fabric.Image[];
61
+
62
+ await Promise.all(
63
+ qrcodeObjects.map(async (imgEl) => {
64
+ this.initQrcodeEvents(imgEl);
65
+ await this._updateQrCodeImage(imgEl, true);
66
+ })
67
+ );
68
+
69
+ this.canvas.renderAll();
70
+ }
53
71
 
54
72
  async _getQrCodeResult(options: any): Promise<{ url: string; width: number; height: number }> {
55
73
  const zoom = this.canvas.getZoom() || 1;
@@ -123,11 +141,11 @@ class QrCodePlugin implements IPluginTempl {
123
141
  return options;
124
142
  }
125
143
 
126
- private async _updateQrCodeImage(imgEl: fabric.Image, immediate = false) {
127
- const extension = imgEl.get('extension');
128
- if (!extension) return;
129
- const updateFn = async () => {
130
- const currentWidth = imgEl.getScaledWidth();
144
+ private async _updateQrCodeImage(imgEl: fabric.Image, immediate = false) {
145
+ const extension = imgEl.get('extension');
146
+ if (!extension) return;
147
+ const updateFn = async () => {
148
+ const currentWidth = imgEl.getScaledWidth();
131
149
  const currentHeight = imgEl.getScaledHeight();
132
150
  const size = Math.max(currentWidth, currentHeight);
133
151
  const options = {
@@ -135,11 +153,11 @@ class QrCodePlugin implements IPluginTempl {
135
153
  width: size,
136
154
  height: size,
137
155
  };
138
- const paramsOption = this._paramsToOption(options);
139
- try {
140
- const url = await this._getBase64Str(paramsOption);
141
- await new Promise<void>((resolve) => {
142
- imgEl.setSrc(url, () => {
156
+ const paramsOption = this._paramsToOption(options);
157
+ try {
158
+ const url = await this._getBase64Str(paramsOption);
159
+ await new Promise<void>((resolve) => {
160
+ imgEl.setSrc(url, () => {
143
161
  this._setImageScale(imgEl, currentWidth, currentHeight);
144
162
  imgEl.set('extension', options);
145
163
  this.canvas.renderAll();