customized-fabric 1.1.3 → 1.1.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/lib/TextInputObject/index.js +2 -2
- package/lib/utils/index.d.ts +1 -2
- package/lib/utils/index.js +2 -30
- package/package.json +1 -6
@@ -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.4",
|
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
|
}
|