customized-fabric 1.1.3 → 1.1.5
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.
@@ -17,10 +17,12 @@ export default class ImagePlaceholder extends fabric.Group {
|
|
17
17
|
isAdditional?: boolean;
|
18
18
|
loadImageFromFile?: (imageFile: File) => void;
|
19
19
|
loadImageFromUrl?: (imageUrl: string) => void;
|
20
|
+
loadUploadedImage?: (imageFile: File) => Promise<fabric.Image>;
|
20
21
|
getSettings?: (attribute: string) => any;
|
21
22
|
setSizes?: (options: {
|
22
23
|
width?: number;
|
23
24
|
height?: number;
|
24
25
|
}) => void;
|
26
|
+
toImageObject?: () => void;
|
25
27
|
constructor(options?: IImagePlaceholderOptions);
|
26
28
|
}
|
@@ -97,28 +97,59 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
|
|
97
97
|
getSettings: function (attribute) {
|
98
98
|
return this.get(attribute);
|
99
99
|
},
|
100
|
-
loadUploadedImage: function (imageFile) {
|
101
|
-
(0, utils_1.loadImageFromFile)(imageFile)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
100
|
+
loadUploadedImage: async function (imageFile) {
|
101
|
+
const loadedImage = await (0, utils_1.loadImageFromFile)(imageFile);
|
102
|
+
const clipPath = new fabric_1.fabric.Rect({
|
103
|
+
width: this.width,
|
104
|
+
height: this.height,
|
105
|
+
top: this.top,
|
106
|
+
left: this.left,
|
107
|
+
absolutePositioned: true,
|
108
|
+
});
|
109
|
+
loadedImage.set({
|
110
|
+
originX: "left",
|
111
|
+
originY: "top",
|
112
|
+
top: this.top,
|
113
|
+
left: this.left,
|
114
|
+
clipPath: clipPath,
|
115
115
|
});
|
116
|
+
this.fitImage(loadedImage);
|
117
|
+
this.uploadedImage = loadedImage;
|
118
|
+
const canvas = this?.canvas;
|
119
|
+
canvas?.add(this.uploadedImage);
|
120
|
+
canvas?.renderAll();
|
121
|
+
return this.uploadedImage;
|
116
122
|
},
|
117
123
|
removeUploadedImage: function () {
|
118
124
|
const canvas = this?.canvas;
|
119
125
|
canvas?.remove(this.uploadedImage);
|
126
|
+
this.uploadedImage = undefined;
|
120
127
|
canvas?.renderAll();
|
121
128
|
},
|
129
|
+
toImageObject: function () {
|
130
|
+
if (this.uploadedImage) {
|
131
|
+
const { originX, originY, left = 0, top = 0, width, height, scaleX, scaleY, angle, flipX, flipY, skewX, skewY, opacity, } = this.uploadedImage;
|
132
|
+
return {
|
133
|
+
originX,
|
134
|
+
originY,
|
135
|
+
left: left - this.left,
|
136
|
+
top: top - this.top,
|
137
|
+
width,
|
138
|
+
height,
|
139
|
+
scaleX,
|
140
|
+
scaleY,
|
141
|
+
angle,
|
142
|
+
flipX,
|
143
|
+
flipY,
|
144
|
+
skewX,
|
145
|
+
skewY,
|
146
|
+
opacity,
|
147
|
+
};
|
148
|
+
}
|
149
|
+
else {
|
150
|
+
return {};
|
151
|
+
}
|
152
|
+
},
|
122
153
|
});
|
123
154
|
const toImagePlaceholderObject = (imagePlaceholderObject) => {
|
124
155
|
return {
|
@@ -56,7 +56,7 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
56
56
|
width: this.width,
|
57
57
|
});
|
58
58
|
if (options?.fontUrl) {
|
59
|
-
(0, utils_1.loadFontFromUrl)(text?.fontFamily ?? ""
|
59
|
+
(0, utils_1.loadFontFromUrl)(options?.fontUrl, text?.fontFamily ?? "").then(() => {
|
60
60
|
this.canvas?.renderAll?.();
|
61
61
|
});
|
62
62
|
}
|
@@ -114,7 +114,7 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
114
114
|
},
|
115
115
|
setFontFamily: async function (fontName, fontUrl) {
|
116
116
|
if (!(0, utils_1.isFontLoaded)(fontName)) {
|
117
|
-
await (0, utils_1.loadFontFromUrl)(
|
117
|
+
await (0, utils_1.loadFontFromUrl)(fontUrl ?? "", fontName);
|
118
118
|
}
|
119
119
|
this.textObject.set({ fontFamily: fontName });
|
120
120
|
this.autoChangeFontSize(0.1);
|
package/lib/utils/index.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { fabric } from "fabric";
|
|
2
2
|
import Clipart from "../ClipartObject";
|
3
3
|
import ImagePlaceholder from "../ImagePlaceholderObject";
|
4
4
|
import TextInput from "../TextInputObject";
|
5
|
-
export declare const loadFontFromUrl: (
|
5
|
+
export declare const loadFontFromUrl: (url: string, name: string) => Promise<void>;
|
6
6
|
export declare const isFontLoaded: (name: string) => boolean;
|
7
7
|
export declare const loadImageFromFile: (image: File) => Promise<fabric.Image>;
|
8
8
|
export declare const loadImageFromUrl: (url: string) => Promise<fabric.Image>;
|
@@ -11,5 +11,4 @@ export declare const lockAllObjects: (canvas: fabric.Canvas, locked: boolean) =>
|
|
11
11
|
export declare const getObject: (object: any, options?: {
|
12
12
|
isOriginal?: boolean;
|
13
13
|
}) => Clipart | ImagePlaceholder | TextInput | undefined;
|
14
|
-
export declare const downloadFileFromUrl: (url: string, filePath: string, fileName: string) => Promise<string>;
|
15
14
|
export default fabric;
|
package/lib/utils/index.js
CHANGED
@@ -22,23 +22,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
22
|
__setModuleDefault(result, mod);
|
23
23
|
return result;
|
24
24
|
};
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
-
};
|
28
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.
|
26
|
+
exports.getObject = exports.lockAllObjects = exports.lockObject = exports.loadImageFromUrl = exports.loadImageFromFile = exports.isFontLoaded = exports.loadFontFromUrl = void 0;
|
30
27
|
const fabric_1 = require("fabric");
|
31
28
|
const constants_1 = require("../constants");
|
32
29
|
const ClipartObject_1 = __importStar(require("../ClipartObject"));
|
33
30
|
const ImagePlaceholderObject_1 = __importStar(require("../ImagePlaceholderObject"));
|
34
31
|
const TextInputObject_1 = __importStar(require("../TextInputObject"));
|
35
|
-
const
|
36
|
-
const fs_1 = require("fs");
|
37
|
-
const loadFontFromUrl = async (name, url) => {
|
32
|
+
const loadFontFromUrl = async (url, name) => {
|
38
33
|
if (!name || !url)
|
39
34
|
return;
|
40
|
-
const fontFilePath = await (0, exports.downloadFileFromUrl)(url, "fonts", `${name}.ttf`);
|
41
|
-
fabric_1.fabric.nodeCanvas.registerFont(fontFilePath, { family: name });
|
42
35
|
if (typeof window === "undefined") {
|
43
36
|
}
|
44
37
|
else {
|
@@ -156,25 +149,4 @@ fabric_1.fabric.Object.prototype.toObject = (function (toObject) {
|
|
156
149
|
}
|
157
150
|
};
|
158
151
|
})(fabric_1.fabric.Object.prototype.toObject);
|
159
|
-
const downloadFileFromUrl = async (url, filePath, fileName) => {
|
160
|
-
return new Promise((resolve, reject) => {
|
161
|
-
https_1.default
|
162
|
-
.get(url, (res) => {
|
163
|
-
if (!(0, fs_1.existsSync)(`${"."}/${filePath}`)) {
|
164
|
-
(0, fs_1.mkdirSync)(`${"."}/${filePath}`);
|
165
|
-
}
|
166
|
-
const path = `${"."}/${filePath}/${fileName}`;
|
167
|
-
const fileWriter = (0, fs_1.createWriteStream)(path);
|
168
|
-
res.pipe(fileWriter);
|
169
|
-
fileWriter.on("finish", () => {
|
170
|
-
fileWriter.close();
|
171
|
-
resolve(path);
|
172
|
-
});
|
173
|
-
})
|
174
|
-
.on("error", (error) => {
|
175
|
-
reject(error);
|
176
|
-
});
|
177
|
-
});
|
178
|
-
};
|
179
|
-
exports.downloadFileFromUrl = downloadFileFromUrl;
|
180
152
|
exports.default = fabric_1.fabric;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "customized-fabric",
|
3
|
-
"version": "1.1.
|
3
|
+
"version": "1.1.5",
|
4
4
|
"description": "Customized fabric",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
@@ -21,10 +21,5 @@
|
|
21
21
|
"devDependencies": {
|
22
22
|
"@types/fabric": "^5.3.3",
|
23
23
|
"typescript": "^5.2.2"
|
24
|
-
},
|
25
|
-
"browser": {
|
26
|
-
"fs": false,
|
27
|
-
"path": false,
|
28
|
-
"os": false
|
29
24
|
}
|
30
25
|
}
|