customized-fabric 1.6.8 → 1.6.9
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/lib/ClipartObject/index.d.ts +0 -1
- package/lib/ClipartObject/index.js +30 -38
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -4
- package/package.json +1 -1
@@ -23,19 +23,16 @@ const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
23
23
|
});
|
24
24
|
this.imageObject = imageObject;
|
25
25
|
const group = new fabric_1.fabric.Group([this.rectObject, this.imageObject]);
|
26
|
-
group.setControlsVisibility({
|
27
|
-
mt: false,
|
28
|
-
mr: false,
|
29
|
-
mb: false,
|
30
|
-
ml: false,
|
31
|
-
});
|
32
26
|
this.set(group);
|
33
27
|
this.on("scaling", () => {
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
const attributes = {
|
29
|
+
width: this.width * this.scaleX,
|
30
|
+
height: this.height * this.scaleY,
|
31
|
+
scaleX: 1,
|
32
|
+
scaleY: 1,
|
33
|
+
};
|
34
|
+
this.set(attributes);
|
35
|
+
this.rectObject?.set(attributes);
|
39
36
|
this.fitImage(this.imageObject);
|
40
37
|
this.canvas?.renderAll?.();
|
41
38
|
});
|
@@ -66,7 +63,6 @@ const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
66
63
|
originX: "center",
|
67
64
|
originY: "center",
|
68
65
|
});
|
69
|
-
image.scaleToWidth(this.width);
|
70
66
|
this.remove(this.imageObject);
|
71
67
|
this.imageObject = image;
|
72
68
|
this.add(this.imageObject);
|
@@ -90,39 +86,35 @@ const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
90
86
|
},
|
91
87
|
setSizes: function (options) {
|
92
88
|
const { width, height } = options;
|
89
|
+
const attributes = {
|
90
|
+
scaleX: 1,
|
91
|
+
scaleY: 1,
|
92
|
+
};
|
93
93
|
if (width) {
|
94
|
-
|
95
|
-
this.imageObject.set({ scaleX, scaleY: scaleX });
|
94
|
+
attributes.width = width;
|
96
95
|
}
|
97
96
|
if (height) {
|
98
|
-
|
99
|
-
this.imageObject.set({ scaleX: scaleY, scaleY });
|
97
|
+
attributes.height = height;
|
100
98
|
}
|
99
|
+
this.set(attributes);
|
100
|
+
this.rectObject?.set(attributes);
|
101
101
|
this.fitImage(this.imageObject);
|
102
102
|
this.canvas?.renderAll?.();
|
103
103
|
},
|
104
|
-
fitImage: function (image) {
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
image.set({
|
119
|
-
originX: "center",
|
120
|
-
originY: "center",
|
121
|
-
top: this.top,
|
122
|
-
left: this.left,
|
123
|
-
angle: this.angle,
|
124
|
-
});
|
125
|
-
return image;
|
104
|
+
fitImage: function (image, cover = false) {
|
105
|
+
if (image) {
|
106
|
+
const imageScaleX = this.width / (image?.width ?? 1);
|
107
|
+
const imageScaleY = this.height / (image?.height ?? 1);
|
108
|
+
if (cover) {
|
109
|
+
imageScaleX < imageScaleY
|
110
|
+
? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
|
111
|
+
: image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
|
112
|
+
}
|
113
|
+
else {
|
114
|
+
imageScaleX > imageScaleY
|
115
|
+
? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
|
116
|
+
: image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
|
117
|
+
}
|
126
118
|
}
|
127
119
|
},
|
128
120
|
});
|
package/lib/utils/index.d.ts
CHANGED
@@ -20,5 +20,5 @@ export declare const getObject: (object: any, options?: {
|
|
20
20
|
}) => Clipart | ImagePlaceholder | CurvedText | TextInput | undefined;
|
21
21
|
export declare const asyncGetObject: (object: any, options?: {
|
22
22
|
isOriginal?: boolean;
|
23
|
-
}) => Promise<
|
23
|
+
}) => Promise<Clipart | ImagePlaceholder | CurvedText | TextInput | undefined>;
|
24
24
|
export default fabric;
|
package/lib/utils/index.js
CHANGED
@@ -176,10 +176,7 @@ const asyncGetObject = async (object, options) => {
|
|
176
176
|
isOriginal: options?.isOriginal,
|
177
177
|
});
|
178
178
|
if (object?.clipartUrl) {
|
179
|
-
|
180
|
-
if (clipart) {
|
181
|
-
return clipart;
|
182
|
-
}
|
179
|
+
await clipartObject?.loadImage?.(object?.clipartUrl);
|
183
180
|
}
|
184
181
|
return clipartObject;
|
185
182
|
}
|