customized-fabric 1.0.5 → 1.0.7

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.
Files changed (38) hide show
  1. package/lib/{customizedFabric/ClipartObject → ClipartObject}/constants.js +1 -1
  2. package/lib/ClipartObject/index.d.ts +31 -0
  3. package/lib/{customizedFabric/ClipartObject → ClipartObject}/index.js +3 -3
  4. package/lib/ClipartObject/interfaces.d.ts +9 -0
  5. package/lib/ImagePlaceholderObject/index.d.ts +26 -0
  6. package/lib/{customizedFabric/ImagePlaceholderObject → ImagePlaceholderObject}/index.js +3 -3
  7. package/lib/ImagePlaceholderObject/interfaces.d.ts +8 -0
  8. package/lib/TextInputObject/index.d.ts +48 -0
  9. package/lib/{customizedFabric/TextInputObject → TextInputObject}/index.js +3 -3
  10. package/lib/TextInputObject/interfaces.d.ts +21 -0
  11. package/lib/constants/index.d.ts +6 -0
  12. package/lib/constants/index.js +12 -0
  13. package/lib/index.d.ts +6 -1
  14. package/lib/index.js +30 -3
  15. package/lib/{customizedFabric/utils.d.ts → utils/index.d.ts} +6 -3
  16. package/lib/utils/index.js +148 -0
  17. package/package.json +1 -1
  18. package/lib/customizedFabric/ClipartObject/index.d.ts +0 -19
  19. package/lib/customizedFabric/ClipartObject/interfaces.d.ts +0 -30
  20. package/lib/customizedFabric/ImagePlaceholderObject/index.d.ts +0 -14
  21. package/lib/customizedFabric/ImagePlaceholderObject/interfaces.d.ts +0 -22
  22. package/lib/customizedFabric/TextInputObject/index.d.ts +0 -30
  23. package/lib/customizedFabric/TextInputObject/interfaces.d.ts +0 -41
  24. package/lib/customizedFabric/index.d.ts +0 -8
  25. package/lib/customizedFabric/index.js +0 -54
  26. package/lib/customizedFabric/interfaces.d.ts +0 -3
  27. package/lib/customizedFabric/interfaces.js +0 -19
  28. package/lib/customizedFabric/utils.js +0 -90
  29. /package/lib/{customizedFabric/ClipartObject → ClipartObject}/constants.d.ts +0 -0
  30. /package/lib/{customizedFabric/ClipartObject → ClipartObject}/interfaces.js +0 -0
  31. /package/lib/{customizedFabric/ImagePlaceholderObject → ImagePlaceholderObject}/constants.d.ts +0 -0
  32. /package/lib/{customizedFabric/ImagePlaceholderObject → ImagePlaceholderObject}/constants.js +0 -0
  33. /package/lib/{customizedFabric/ImagePlaceholderObject → ImagePlaceholderObject}/interfaces.js +0 -0
  34. /package/lib/{customizedFabric/TextInputObject → TextInputObject}/constants.d.ts +0 -0
  35. /package/lib/{customizedFabric/TextInputObject → TextInputObject}/constants.js +0 -0
  36. /package/lib/{customizedFabric/TextInputObject → TextInputObject}/interfaces.js +0 -0
  37. /package/lib/{customizedFabric/constants.d.ts → constants.d.ts} +0 -0
  38. /package/lib/{customizedFabric/constants.js → constants.js} +0 -0
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CLIPART_OBJECT_ATTRIBUTES = void 0;
4
4
  exports.CLIPART_OBJECT_ATTRIBUTES = {
5
5
  name: "Clipart",
6
- type: "CLIP_ART",
6
+ type: "CLIPART",
7
7
  stroke: {
8
8
  stroke: "#000000",
9
9
  strokeDashArray: [5, 5],
@@ -0,0 +1,31 @@
1
+ import { fabric } from "fabric";
2
+ import { IClipartOptions } from "./interfaces";
3
+ import { ObjectId } from "../utils/objectId";
4
+ export declare const toClipartObject: (clipartObject: Clipart) => {
5
+ id: ObjectId | undefined;
6
+ personalizeId: number | undefined;
7
+ layerId: number | undefined;
8
+ name: string | undefined;
9
+ locked: boolean | undefined;
10
+ isAdditional: boolean | undefined;
11
+ clipartUrl: string | undefined;
12
+ clipartFile: File | undefined;
13
+ clipartRootCategoryId: string | undefined;
14
+ clipartCategoryId: string | undefined;
15
+ clipartOptionId: number | undefined;
16
+ };
17
+ export default class Clipart extends fabric.Group {
18
+ _id?: ObjectId;
19
+ layerId?: number;
20
+ locked?: boolean;
21
+ isAdditional?: boolean;
22
+ clipartFile?: File;
23
+ clipartRootCategoryId?: string;
24
+ clipartRootCategoryName?: string;
25
+ clipartCategoryId?: string;
26
+ clipartCategoryName?: string;
27
+ clipartOptionId?: number;
28
+ clipartUrl?: string;
29
+ imageObject?: fabric.Image;
30
+ constructor(options?: IClipartOptions);
31
+ }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Clipart = exports.toClipartObject = void 0;
3
+ exports.toClipartObject = void 0;
4
4
  const fabric_1 = require("fabric");
5
5
  const constants_1 = require("./constants");
6
6
  const utils_1 = require("../utils");
7
- const objectId_1 = require("../../utils/objectId");
7
+ const objectId_1 = require("../utils/objectId");
8
8
  const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
9
9
  initialize: function (options) {
10
10
  this.rectObject = new fabric_1.fabric.Rect({
@@ -142,4 +142,4 @@ class Clipart extends fabric_1.fabric.Group {
142
142
  return new ClipartClass(options);
143
143
  }
144
144
  }
145
- exports.Clipart = Clipart;
145
+ exports.default = Clipart;
@@ -0,0 +1,9 @@
1
+ import { ObjectId } from "../utils/objectId";
2
+ export interface IClipartOptions extends fabric.IGroupOptions {
3
+ _id?: ObjectId;
4
+ personalizeId?: number;
5
+ layerId: number;
6
+ clipartUrl?: string;
7
+ clipartFile?: File;
8
+ hideStroke?: boolean;
9
+ }
@@ -0,0 +1,26 @@
1
+ import { fabric } from "fabric";
2
+ import { IImagePlaceholderOptions } from "./interfaces";
3
+ import { ObjectId } from "../utils/objectId";
4
+ export declare const toImagePlaceholderObject: (imagePlaceholderObject: ImagePlaceholder) => {
5
+ id: ObjectId | undefined;
6
+ personalizeId: number | undefined;
7
+ layerId: number | undefined;
8
+ name: string | undefined;
9
+ locked: boolean | undefined;
10
+ isAdditional: boolean | undefined;
11
+ };
12
+ export default class ImagePlaceholder extends fabric.Group {
13
+ _id?: ObjectId;
14
+ layerId?: number;
15
+ locked?: boolean;
16
+ imageFile?: File;
17
+ isAdditional?: boolean;
18
+ loadImageFromFile?: (imageFile: File) => void;
19
+ loadImageFromUrl?: (imageUrl: string) => void;
20
+ getSettings?: (attribute: string) => any;
21
+ setSizes?: (options: {
22
+ width?: number;
23
+ height?: number;
24
+ }) => void;
25
+ constructor(options?: IImagePlaceholderOptions);
26
+ }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImagePlaceholder = exports.toImagePlaceholderObject = void 0;
3
+ exports.toImagePlaceholderObject = void 0;
4
4
  const fabric_1 = require("fabric");
5
5
  const constants_1 = require("./constants");
6
6
  const utils_1 = require("../utils");
7
- const objectId_1 = require("../../utils/objectId");
7
+ const objectId_1 = require("../utils/objectId");
8
8
  const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
9
9
  initialize: function (options) {
10
10
  this.rectObject = new fabric_1.fabric.Rect({
@@ -137,4 +137,4 @@ class ImagePlaceholder extends fabric_1.fabric.Group {
137
137
  return new ImagePlaceholderClass(options);
138
138
  }
139
139
  }
140
- exports.ImagePlaceholder = ImagePlaceholder;
140
+ exports.default = ImagePlaceholder;
@@ -0,0 +1,8 @@
1
+ import { ObjectId } from "../utils/objectId";
2
+ export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
3
+ _id?: ObjectId;
4
+ personalizeId?: number;
5
+ layerId: number;
6
+ imageFile?: File;
7
+ hideStroke?: boolean;
8
+ }
@@ -0,0 +1,48 @@
1
+ import { fabric } from "fabric";
2
+ import { ITextInputOptions } from "./interfaces";
3
+ import { ObjectId } from "../utils/objectId";
4
+ export declare const toTextInputObject: (textInputObject: TextInput) => {
5
+ id: ObjectId | undefined;
6
+ personalizeId: number | undefined;
7
+ layerId: number | undefined;
8
+ name: string | undefined;
9
+ locked: boolean | undefined;
10
+ fontId: number | undefined;
11
+ fontCategoryId: string | undefined;
12
+ fontUrl: string | undefined;
13
+ isAdditional: boolean | undefined;
14
+ text: {
15
+ fontWeight: string | number | undefined;
16
+ fontSize: number | undefined;
17
+ textAlign: string | undefined;
18
+ text: string | undefined;
19
+ fill: string | fabric.Gradient | fabric.Pattern | undefined;
20
+ width: number | undefined;
21
+ height: number | undefined;
22
+ fontFamily: string | undefined;
23
+ maxFontSize: any;
24
+ stroke: string | undefined;
25
+ strokeWidth: number | undefined;
26
+ };
27
+ };
28
+ export default class TextInput extends fabric.Group {
29
+ _id?: ObjectId;
30
+ layerId?: number;
31
+ locked?: boolean;
32
+ textObject?: fabric.IText;
33
+ fontId?: number;
34
+ fontCategoryId?: string;
35
+ fontUrl?: string;
36
+ isAdditional?: boolean;
37
+ setText?: (text: string) => void;
38
+ setMaxFontSize?: (fontSize: string) => void;
39
+ setFontFamily?: (fontName: string, fontUrl?: string) => void;
40
+ setTextAttributes?: (options: fabric.ITextOptions) => void;
41
+ getTextAttribute?: (attribute: string) => any;
42
+ getSettings?: (attribute: string) => any;
43
+ setSizes?: (options: {
44
+ width?: number;
45
+ height?: number;
46
+ }) => void;
47
+ constructor(options?: ITextInputOptions);
48
+ }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TextInput = exports.toTextInputObject = void 0;
3
+ exports.toTextInputObject = void 0;
4
4
  const fabric_1 = require("fabric");
5
5
  const constants_1 = require("./constants");
6
6
  const utils_1 = require("../utils");
7
- const objectId_1 = require("../../utils/objectId");
7
+ const objectId_1 = require("../utils/objectId");
8
8
  const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
9
9
  initialize: function (options) {
10
10
  const { text, ...rest } = options ?? {};
@@ -185,4 +185,4 @@ class TextInput extends fabric_1.fabric.Group {
185
185
  return new TextInputClass(options);
186
186
  }
187
187
  }
188
- exports.TextInput = TextInput;
188
+ exports.default = TextInput;
@@ -0,0 +1,21 @@
1
+ import { ObjectId } from "../utils/objectId";
2
+ export interface ITextInputOptions extends fabric.IGroupOptions {
3
+ _id?: ObjectId;
4
+ personalizeId?: string;
5
+ layerId: number;
6
+ text: {
7
+ fontSize?: number;
8
+ fill?: string;
9
+ width?: number;
10
+ height?: number;
11
+ textAlign?: string;
12
+ fontWeight?: string;
13
+ text: string;
14
+ fontFamily?: string;
15
+ maxFontSize: number;
16
+ stroke?: string;
17
+ strokeWidth?: number;
18
+ };
19
+ fontUrl?: string;
20
+ hideStroke?: boolean;
21
+ }
@@ -0,0 +1,6 @@
1
+ export declare const OBJECT_TYPES: {
2
+ textInput: string;
3
+ clipart: string;
4
+ imagePlaceHolder: string;
5
+ activeSelection: string;
6
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OBJECT_TYPES = void 0;
4
+ const constants_1 = require("../ClipartObject/constants");
5
+ const constants_2 = require("../ImagePlaceholderObject/constants");
6
+ const constants_3 = require("../TextInputObject/constants");
7
+ exports.OBJECT_TYPES = {
8
+ textInput: constants_3.TEXT_INPUT_OBJECT_ATTRIBUTES.type,
9
+ clipart: constants_1.CLIPART_OBJECT_ATTRIBUTES.type,
10
+ imagePlaceHolder: constants_2.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.type,
11
+ activeSelection: "activeSelection",
12
+ };
package/lib/index.d.ts CHANGED
@@ -1 +1,6 @@
1
- export * from "./customizedFabric";
1
+ import TextInput from "./TextInputObject";
2
+ import Clipart from "./ClipartObject";
3
+ import ImagePlaceholder from "./ImagePlaceholderObject";
4
+ import fabric, { lockObject, lockAllObjects, loadImageFromFile, loadImageFromUrl, getObject } from "./utils";
5
+ import { OBJECT_TYPES } from "./constants";
6
+ export { fabric, TextInput, Clipart, ImagePlaceholder, lockObject, lockAllObjects, loadImageFromFile, loadImageFromUrl, getObject, OBJECT_TYPES, };
package/lib/index.js CHANGED
@@ -10,8 +10,35 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
27
  };
16
28
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./customizedFabric"), exports);
29
+ exports.OBJECT_TYPES = exports.getObject = exports.loadImageFromUrl = exports.loadImageFromFile = exports.lockAllObjects = exports.lockObject = exports.ImagePlaceholder = exports.Clipart = exports.TextInput = exports.fabric = void 0;
30
+ const TextInputObject_1 = __importDefault(require("./TextInputObject"));
31
+ exports.TextInput = TextInputObject_1.default;
32
+ const ClipartObject_1 = __importDefault(require("./ClipartObject"));
33
+ exports.Clipart = ClipartObject_1.default;
34
+ const ImagePlaceholderObject_1 = __importDefault(require("./ImagePlaceholderObject"));
35
+ exports.ImagePlaceholder = ImagePlaceholderObject_1.default;
36
+ const utils_1 = __importStar(require("./utils"));
37
+ exports.fabric = utils_1.default;
38
+ Object.defineProperty(exports, "lockObject", { enumerable: true, get: function () { return utils_1.lockObject; } });
39
+ Object.defineProperty(exports, "lockAllObjects", { enumerable: true, get: function () { return utils_1.lockAllObjects; } });
40
+ Object.defineProperty(exports, "loadImageFromFile", { enumerable: true, get: function () { return utils_1.loadImageFromFile; } });
41
+ Object.defineProperty(exports, "loadImageFromUrl", { enumerable: true, get: function () { return utils_1.loadImageFromUrl; } });
42
+ Object.defineProperty(exports, "getObject", { enumerable: true, get: function () { return utils_1.getObject; } });
43
+ const constants_1 = require("./constants");
44
+ Object.defineProperty(exports, "OBJECT_TYPES", { enumerable: true, get: function () { return constants_1.OBJECT_TYPES; } });
@@ -1,11 +1,14 @@
1
1
  import { fabric } from "fabric";
2
- import { Clipart, TextInput } from ".";
3
- import { ImagePlaceholder } from "./ImagePlaceholderObject";
2
+ import Clipart from "../ClipartObject";
3
+ import ImagePlaceholder from "../ImagePlaceholderObject";
4
+ import TextInput from "../TextInputObject";
4
5
  export declare const loadFontFromUrl: (name: string, url: string) => Promise<void>;
5
6
  export declare const isFontLoaded: (name: string) => boolean;
6
7
  export declare const loadImageFromFile: (image: File) => Promise<fabric.Image>;
8
+ export declare const loadImageFromUrl: (url: string) => Promise<fabric.Image>;
7
9
  export declare const lockObject: (object: fabric.Object | any, locked: boolean, selectable?: boolean) => void;
8
10
  export declare const lockAllObjects: (canvas: fabric.Canvas, locked: boolean) => void;
9
11
  export declare const getObject: (object: any, options?: {
10
12
  isOriginal?: boolean;
11
- }) => ImagePlaceholder | TextInput | Clipart | undefined;
13
+ }) => Clipart | ImagePlaceholder | TextInput | undefined;
14
+ export default fabric;
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getObject = exports.lockAllObjects = exports.lockObject = exports.loadImageFromUrl = exports.loadImageFromFile = exports.isFontLoaded = exports.loadFontFromUrl = void 0;
27
+ const fabric_1 = require("fabric");
28
+ const constants_1 = require("../constants");
29
+ const ClipartObject_1 = __importStar(require("../ClipartObject"));
30
+ const ImagePlaceholderObject_1 = __importStar(require("../ImagePlaceholderObject"));
31
+ const TextInputObject_1 = __importStar(require("../TextInputObject"));
32
+ const loadFontFromUrl = async (name, url) => {
33
+ if (!name || !url)
34
+ return;
35
+ const font = new FontFace(name, `url(${url})`);
36
+ await font.load();
37
+ document.fonts.add(font);
38
+ };
39
+ exports.loadFontFromUrl = loadFontFromUrl;
40
+ const isFontLoaded = (name) => {
41
+ let isLoaded = false;
42
+ document.fonts.forEach((font) => {
43
+ if (name == font.family) {
44
+ isLoaded = true;
45
+ }
46
+ });
47
+ return isLoaded;
48
+ };
49
+ exports.isFontLoaded = isFontLoaded;
50
+ const loadImageFromFile = (image) => {
51
+ return new Promise((resolve) => {
52
+ const reader = new FileReader();
53
+ reader.onload = function (event) {
54
+ const image = new Image();
55
+ image.src = event?.target?.result;
56
+ image.onload = function () {
57
+ resolve(new fabric_1.fabric.Image(image));
58
+ };
59
+ };
60
+ reader.readAsDataURL(image);
61
+ });
62
+ };
63
+ exports.loadImageFromFile = loadImageFromFile;
64
+ const loadImageFromUrl = (url) => {
65
+ return new Promise((resolve) => {
66
+ fabric_1.fabric.Image.fromURL(url, (loadedImage) => {
67
+ resolve(loadedImage);
68
+ }, {
69
+ crossOrigin: "anonymous",
70
+ });
71
+ });
72
+ };
73
+ exports.loadImageFromUrl = loadImageFromUrl;
74
+ const lockObject = (object, locked, selectable) => {
75
+ object.set({
76
+ hasControls: !locked,
77
+ lockMovementX: locked,
78
+ lockMovementY: locked,
79
+ lockRotation: locked,
80
+ lockScalingX: locked,
81
+ lockScalingY: locked,
82
+ lockUniScaling: locked,
83
+ lockSkewingX: locked,
84
+ lockSkewingY: locked,
85
+ lockScalingFlip: locked,
86
+ locked: locked,
87
+ selectable: selectable ?? !locked,
88
+ });
89
+ };
90
+ exports.lockObject = lockObject;
91
+ const lockAllObjects = (canvas, locked) => {
92
+ canvas._objects.map((object) => {
93
+ (0, exports.lockObject)(object, locked);
94
+ });
95
+ };
96
+ exports.lockAllObjects = lockAllObjects;
97
+ const getObject = (object, options) => {
98
+ switch (object.type) {
99
+ case constants_1.OBJECT_TYPES.textInput: {
100
+ const textInputObject = new TextInputObject_1.default({
101
+ ...object,
102
+ hideStroke: options?.isOriginal,
103
+ });
104
+ return textInputObject;
105
+ }
106
+ case constants_1.OBJECT_TYPES.clipart: {
107
+ const clipartObject = new ClipartObject_1.default({
108
+ ...object,
109
+ hideStroke: options?.isOriginal,
110
+ });
111
+ return clipartObject;
112
+ }
113
+ case constants_1.OBJECT_TYPES.imagePlaceHolder: {
114
+ const imagePlaceHolderObject = new ImagePlaceholderObject_1.default({
115
+ ...object,
116
+ hideStroke: options?.isOriginal,
117
+ });
118
+ return imagePlaceHolderObject;
119
+ }
120
+ default:
121
+ return;
122
+ }
123
+ };
124
+ exports.getObject = getObject;
125
+ fabric_1.fabric.Object.prototype.transparentCorners = false;
126
+ fabric_1.fabric.Object.prototype.cornerColor = "black";
127
+ fabric_1.fabric.Object.prototype.cornerStyle = "circle";
128
+ fabric_1.fabric.Object.prototype.cornerStrokeColor = "black";
129
+ fabric_1.fabric.Object.prototype.borderColor = "black";
130
+ fabric_1.fabric.Object.prototype.toObject = (function (toObject) {
131
+ return function () {
132
+ switch (this.type) {
133
+ case constants_1.OBJECT_TYPES.textInput: {
134
+ return fabric_1.fabric.util.object.extend(toObject.call(this), (0, TextInputObject_1.toTextInputObject)(this));
135
+ }
136
+ case constants_1.OBJECT_TYPES.clipart: {
137
+ return fabric_1.fabric.util.object.extend(toObject.call(this), (0, ClipartObject_1.toClipartObject)(this));
138
+ }
139
+ case constants_1.OBJECT_TYPES.imagePlaceHolder: {
140
+ return fabric_1.fabric.util.object.extend(toObject.call(this), (0, ImagePlaceholderObject_1.toImagePlaceholderObject)(this));
141
+ }
142
+ default: {
143
+ return {};
144
+ }
145
+ }
146
+ };
147
+ })(fabric_1.fabric.Object.prototype.toObject);
148
+ exports.default = fabric_1.fabric;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -1,19 +0,0 @@
1
- import { fabric } from "fabric";
2
- import { ClipartObject, IClipartOptions } from "./interfaces";
3
- import { ObjectId } from "../../utils/objectId";
4
- export declare const toClipartObject: (clipartObject: ClipartObject) => {
5
- id: ObjectId;
6
- personalizeId: number | undefined;
7
- layerId: number | undefined;
8
- name: string | undefined;
9
- locked: boolean | undefined;
10
- isAdditional: boolean | undefined;
11
- clipartUrl: string | undefined;
12
- clipartFile: File | undefined;
13
- clipartRootCategoryId: string | undefined;
14
- clipartCategoryId: string | undefined;
15
- clipartOptionId: number | undefined;
16
- };
17
- export declare class Clipart extends fabric.Group {
18
- constructor(options?: IClipartOptions);
19
- }
@@ -1,30 +0,0 @@
1
- import { ObjectId } from "../../utils/objectId";
2
- export interface ClipartObject extends fabric.Group {
3
- _id: ObjectId;
4
- layerId?: number;
5
- locked?: boolean;
6
- isAdditional?: boolean;
7
- clipartFile?: File;
8
- clipartRootCategoryId?: string;
9
- clipartRootCategoryName?: string;
10
- clipartCategoryId?: string;
11
- clipartCategoryName?: string;
12
- clipartOptionId?: number;
13
- imageObject?: fabric.Image;
14
- clipartUrl?: string;
15
- loadImageFromFile: (imageFile: File) => void;
16
- loadImageFromUrl: (imageUrl: string) => void;
17
- getSettings: (attribute: string) => any;
18
- setSizes: (options: {
19
- width?: number;
20
- height?: number;
21
- }) => void;
22
- }
23
- export interface IClipartOptions extends fabric.IGroupOptions {
24
- _id?: string;
25
- personalizeId?: number;
26
- layerId: number;
27
- clipartUrl?: string;
28
- clipartFile?: File;
29
- hideStroke?: boolean;
30
- }
@@ -1,14 +0,0 @@
1
- import { fabric } from "fabric";
2
- import { IImagePlaceholderOptions, ImagePlaceholderObject } from "./interfaces";
3
- import { ObjectId } from "../../utils/objectId";
4
- export declare const toImagePlaceholderObject: (imagePlaceholderObject: ImagePlaceholderObject) => {
5
- id: ObjectId;
6
- personalizeId: number;
7
- layerId: number;
8
- name: string | undefined;
9
- locked: boolean;
10
- isAdditional: boolean;
11
- };
12
- export declare class ImagePlaceholder extends fabric.Group {
13
- constructor(options?: IImagePlaceholderOptions);
14
- }
@@ -1,22 +0,0 @@
1
- import { ObjectId } from "../../utils/objectId";
2
- export interface ImagePlaceholderObject extends fabric.Group {
3
- _id: ObjectId;
4
- layerId: number;
5
- locked: boolean;
6
- imageFile?: File;
7
- isAdditional: boolean;
8
- loadImageFromFile: (imageFile: File) => void;
9
- loadImageFromUrl: (imageUrl: string) => void;
10
- getSettings: (attribute: string) => any;
11
- setSizes: (options: {
12
- width?: number;
13
- height?: number;
14
- }) => void;
15
- }
16
- export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
17
- _id?: string;
18
- personalizeId?: number;
19
- layerId: number;
20
- imageFile?: File;
21
- hideStroke?: boolean;
22
- }
@@ -1,30 +0,0 @@
1
- import { fabric } from "fabric";
2
- import { ITextInputOptions, TextInputObject } from "./interfaces";
3
- import { ObjectId } from "../../utils/objectId";
4
- export declare const toTextInputObject: (textInputObject: TextInputObject) => {
5
- id: ObjectId;
6
- personalizeId: number;
7
- layerId: number;
8
- name: string | undefined;
9
- locked: boolean;
10
- fontId: number;
11
- fontCategoryId: string;
12
- fontUrl: string;
13
- isAdditional: boolean;
14
- text: {
15
- fontWeight: string | number | undefined;
16
- fontSize: number | undefined;
17
- textAlign: string | undefined;
18
- text: string | undefined;
19
- fill: string | fabric.Gradient | fabric.Pattern | undefined;
20
- width: number | undefined;
21
- height: number | undefined;
22
- fontFamily: string | undefined;
23
- maxFontSize: any;
24
- stroke: string | undefined;
25
- strokeWidth: number | undefined;
26
- };
27
- };
28
- export declare class TextInput extends fabric.Group {
29
- constructor(options?: ITextInputOptions);
30
- }
@@ -1,41 +0,0 @@
1
- import { ObjectId } from "../../utils/objectId";
2
- export interface TextInputObject extends fabric.Group {
3
- _id: ObjectId;
4
- layerId: number;
5
- locked: boolean;
6
- textObject: fabric.IText;
7
- fontId: number;
8
- fontCategoryId: string;
9
- fontUrl: string;
10
- isAdditional: boolean;
11
- setText: (text: string) => void;
12
- setMaxFontSize: (fontSize: string) => void;
13
- setFontFamily: (fontName: string, fontUrl?: string) => void;
14
- setTextAttributes: (options: fabric.ITextOptions) => void;
15
- getTextAttribute: (attribute: string) => any;
16
- getSettings: (attribute: string) => any;
17
- setSizes: (options: {
18
- width?: number;
19
- height?: number;
20
- }) => void;
21
- }
22
- export interface ITextInputOptions extends fabric.IGroupOptions {
23
- _id?: ObjectId;
24
- personalizeId?: string;
25
- layerId: number;
26
- text: {
27
- fontSize?: number;
28
- fill?: string;
29
- width?: number;
30
- height?: number;
31
- textAlign?: string;
32
- fontWeight?: string;
33
- text: string;
34
- fontFamily?: string;
35
- maxFontSize: number;
36
- stroke?: string;
37
- strokeWidth?: number;
38
- };
39
- fontUrl?: string;
40
- hideStroke?: boolean;
41
- }
@@ -1,8 +0,0 @@
1
- import { fabric } from "fabric";
2
- export * from "./TextInputObject";
3
- export * from "./ClipartObject";
4
- export * from "./ImagePlaceholderObject";
5
- export * from "./constants";
6
- export * from "./interfaces";
7
- export * from "./utils";
8
- export default fabric;
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const fabric_1 = require("fabric");
18
- const TextInputObject_1 = require("./TextInputObject");
19
- const ClipartObject_1 = require("./ClipartObject");
20
- const ImagePlaceholderObject_1 = require("./ImagePlaceholderObject");
21
- const constants_1 = require("./constants");
22
- fabric_1.fabric.TextInput = TextInputObject_1.TextInput;
23
- fabric_1.fabric.Clipart = ClipartObject_1.Clipart;
24
- fabric_1.fabric.ImagePlaceholder = ImagePlaceholderObject_1.ImagePlaceholder;
25
- fabric_1.fabric.Object.prototype.transparentCorners = false;
26
- fabric_1.fabric.Object.prototype.cornerColor = "black";
27
- fabric_1.fabric.Object.prototype.cornerStyle = "circle";
28
- fabric_1.fabric.Object.prototype.cornerStrokeColor = "black";
29
- fabric_1.fabric.Object.prototype.borderColor = "black";
30
- fabric_1.fabric.Object.prototype.toObject = (function (toObject) {
31
- return function () {
32
- switch (this.type) {
33
- case constants_1.OBJECT_TYPES.textInput: {
34
- return fabric_1.fabric.util.object.extend(toObject.call(this), (0, TextInputObject_1.toTextInputObject)(this));
35
- }
36
- case constants_1.OBJECT_TYPES.clipart: {
37
- return fabric_1.fabric.util.object.extend(toObject.call(this), (0, ClipartObject_1.toClipartObject)(this));
38
- }
39
- case constants_1.OBJECT_TYPES.imagePlaceHolder: {
40
- return fabric_1.fabric.util.object.extend(toObject.call(this), (0, ImagePlaceholderObject_1.toImagePlaceholderObject)(this));
41
- }
42
- default: {
43
- return {};
44
- }
45
- }
46
- };
47
- })(fabric_1.fabric.Object.prototype.toObject);
48
- __exportStar(require("./TextInputObject"), exports);
49
- __exportStar(require("./ClipartObject"), exports);
50
- __exportStar(require("./ImagePlaceholderObject"), exports);
51
- __exportStar(require("./constants"), exports);
52
- __exportStar(require("./interfaces"), exports);
53
- __exportStar(require("./utils"), exports);
54
- exports.default = fabric_1.fabric;
@@ -1,3 +0,0 @@
1
- export * from "./TextInputObject/interfaces";
2
- export * from "./ClipartObject/interfaces";
3
- export * from "./ImagePlaceholderObject/interfaces";
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./TextInputObject/interfaces"), exports);
18
- __exportStar(require("./ClipartObject/interfaces"), exports);
19
- __exportStar(require("./ImagePlaceholderObject/interfaces"), exports);
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getObject = exports.lockAllObjects = exports.lockObject = exports.loadImageFromFile = exports.isFontLoaded = exports.loadFontFromUrl = void 0;
4
- const fabric_1 = require("fabric");
5
- const constants_1 = require("./constants");
6
- const _1 = require(".");
7
- const ImagePlaceholderObject_1 = require("./ImagePlaceholderObject");
8
- const loadFontFromUrl = async (name, url) => {
9
- if (!name || !url)
10
- return;
11
- const font = new FontFace(name, `url(${url})`);
12
- await font.load();
13
- document.fonts.add(font);
14
- };
15
- exports.loadFontFromUrl = loadFontFromUrl;
16
- const isFontLoaded = (name) => {
17
- let isLoaded = false;
18
- document.fonts.forEach((font) => {
19
- if (name == font.family) {
20
- isLoaded = true;
21
- }
22
- });
23
- return isLoaded;
24
- };
25
- exports.isFontLoaded = isFontLoaded;
26
- const loadImageFromFile = (image) => {
27
- return new Promise((resolve) => {
28
- const reader = new FileReader();
29
- reader.onload = function (event) {
30
- const image = new Image();
31
- image.src = event?.target?.result;
32
- image.onload = function () {
33
- resolve(new fabric_1.fabric.Image(image));
34
- };
35
- };
36
- reader.readAsDataURL(image);
37
- });
38
- };
39
- exports.loadImageFromFile = loadImageFromFile;
40
- const lockObject = (object, locked, selectable) => {
41
- object.set({
42
- hasControls: !locked,
43
- lockMovementX: locked,
44
- lockMovementY: locked,
45
- lockRotation: locked,
46
- lockScalingX: locked,
47
- lockScalingY: locked,
48
- lockUniScaling: locked,
49
- lockSkewingX: locked,
50
- lockSkewingY: locked,
51
- lockScalingFlip: locked,
52
- locked: locked,
53
- selectable: selectable ?? !locked,
54
- });
55
- };
56
- exports.lockObject = lockObject;
57
- const lockAllObjects = (canvas, locked) => {
58
- canvas._objects.map((object) => {
59
- (0, exports.lockObject)(object, locked);
60
- });
61
- };
62
- exports.lockAllObjects = lockAllObjects;
63
- const getObject = (object, options) => {
64
- switch (object.type) {
65
- case constants_1.OBJECT_TYPES.textInput: {
66
- const textInputObject = new _1.TextInput({
67
- ...object,
68
- hideStroke: options?.isOriginal,
69
- });
70
- return textInputObject;
71
- }
72
- case constants_1.OBJECT_TYPES.clipart: {
73
- const clipartObject = new _1.Clipart({
74
- ...object,
75
- hideStroke: options?.isOriginal,
76
- });
77
- return clipartObject;
78
- }
79
- case constants_1.OBJECT_TYPES.imagePlaceHolder: {
80
- const imagePlaceHolderObject = new ImagePlaceholderObject_1.ImagePlaceholder({
81
- ...object,
82
- hideStroke: options?.isOriginal,
83
- });
84
- return imagePlaceHolderObject;
85
- }
86
- default:
87
- return;
88
- }
89
- };
90
- exports.getObject = getObject;