customized-fabric 1.0.9 → 1.1.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.
@@ -2,7 +2,7 @@ import { fabric } from "fabric";
2
2
  import { IClipartOptions } from "./interfaces";
3
3
  import { ObjectId } from "../utils/objectId";
4
4
  export declare const toClipartObject: (clipartObject: Clipart) => {
5
- id: ObjectId | undefined;
5
+ _id: ObjectId | undefined;
6
6
  personalizeId: number | undefined;
7
7
  layerId: number | undefined;
8
8
  name: string | undefined;
@@ -122,7 +122,7 @@ const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
122
122
  });
123
123
  const toClipartObject = (clipartObject) => {
124
124
  return {
125
- id: clipartObject._id,
125
+ _id: clipartObject._id,
126
126
  personalizeId: clipartObject.layerId,
127
127
  layerId: clipartObject.layerId,
128
128
  name: clipartObject.name,
@@ -11,4 +11,5 @@ 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>;
14
15
  export default fabric;
@@ -22,19 +22,30 @@ 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
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getObject = exports.lockAllObjects = exports.lockObject = exports.loadImageFromUrl = exports.loadImageFromFile = exports.isFontLoaded = exports.loadFontFromUrl = void 0;
29
+ exports.downloadFileFromUrl = exports.getObject = exports.lockAllObjects = exports.lockObject = exports.loadImageFromUrl = exports.loadImageFromFile = exports.isFontLoaded = exports.loadFontFromUrl = void 0;
27
30
  const fabric_1 = require("fabric");
28
31
  const constants_1 = require("../constants");
29
32
  const ClipartObject_1 = __importStar(require("../ClipartObject"));
30
33
  const ImagePlaceholderObject_1 = __importStar(require("../ImagePlaceholderObject"));
31
34
  const TextInputObject_1 = __importStar(require("../TextInputObject"));
35
+ const https_1 = __importDefault(require("https"));
36
+ const fs_1 = require("fs");
32
37
  const loadFontFromUrl = async (name, url) => {
33
38
  if (!name || !url)
34
39
  return;
35
- const font = new FontFace(name, `url(${url})`);
36
- await font.load();
37
- document.fonts.add(font);
40
+ const fontFilePath = await (0, exports.downloadFileFromUrl)(url, "fonts", `${name}.ttf`);
41
+ fabric_1.fabric.nodeCanvas.registerFont(fontFilePath, { family: name });
42
+ if (typeof window === "undefined") {
43
+ }
44
+ else {
45
+ const font = new FontFace(name, `url(${url})`);
46
+ await font.load();
47
+ document.fonts.add(font);
48
+ }
38
49
  };
39
50
  exports.loadFontFromUrl = loadFontFromUrl;
40
51
  const isFontLoaded = (name) => {
@@ -145,4 +156,25 @@ fabric_1.fabric.Object.prototype.toObject = (function (toObject) {
145
156
  }
146
157
  };
147
158
  })(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;
148
180
  exports.default = fabric_1.fabric;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -10,12 +10,12 @@
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "build": "tsc",
13
- "prepare" : "npm run build"
13
+ "prepare": "npm run build"
14
14
  },
15
15
  "author": "",
16
16
  "license": "ISC",
17
17
  "dependencies": {
18
- "@types/node": "^18.15.11",
18
+ "@types/node": "^20.6.0",
19
19
  "fabric": "^5.3.0"
20
20
  },
21
21
  "devDependencies": {