customized-fabric 1.3.0 → 1.3.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.
@@ -28,12 +28,12 @@ export default class Clipart extends fabric.Group {
28
28
  clipartOptionId?: number;
29
29
  clipartUrl?: string;
30
30
  imageObject?: fabric.Image;
31
- loadImageFromFile?: (imageFile: File) => void;
32
- loadImageFromUrl?: (imageUrl: string) => void;
31
+ loadImage?: (imageFile: File | string) => Promise<void>;
33
32
  getSettings?: (attribute: string) => any;
34
33
  setSizes?: (options: {
35
34
  width?: number;
36
35
  height?: number;
37
36
  }) => void;
37
+ loadCustomizedClipart?: (clipartUrl: string) => Promise<fabric.Image>;
38
38
  constructor(options?: IClipartOptions);
39
39
  }
@@ -47,28 +47,17 @@ const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
47
47
  layerId: options?.personalizeId ?? options?.layerId,
48
48
  objectCaching: false,
49
49
  });
50
- if (options?.clipartUrl) {
51
- this.loadImageFromUrl(options.clipartUrl);
52
- }
53
- if (options?.clipartFile) {
54
- this.loadImageFromFile(options.clipartFile);
55
- }
56
- if (options?.hideStroke) {
50
+ if (options?.isOriginal) {
57
51
  this.rectObject.set({ strokeWidth: 0 });
58
52
  }
53
+ else {
54
+ if (options?.clipartFile || options?.clipartUrl) {
55
+ this.loadImage(options?.clipartFile ?? options.clipartUrl);
56
+ }
57
+ }
59
58
  },
60
- loadImageFromUrl: async function (url) {
61
- fabric_1.fabric.Image.fromURL(url, (loadedImage) => {
62
- this.loadImage(loadedImage);
63
- }, {
64
- crossOrigin: "anonymous",
65
- });
66
- },
67
- loadImageFromFile: async function (imageFile) {
68
- const loadedImage = await (0, utils_1.loadImageFromFile)(imageFile);
69
- this.loadImage(loadedImage);
70
- },
71
- loadImage: function (image) {
59
+ loadImage: async function (imageInput) {
60
+ const image = await (0, utils_1.loadImage)(imageInput);
72
61
  if (image.width && image.height) {
73
62
  image.set({
74
63
  originX: "center",
@@ -119,6 +108,20 @@ const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
119
108
  this.set(attributes);
120
109
  this.rectObject.set(attributes);
121
110
  },
111
+ loadCustomizedClipart: async function (clipartUrl) {
112
+ const image = await (0, utils_1.loadImageFromUrl)(clipartUrl);
113
+ if (image.width && image.height) {
114
+ image.scaleToWidth(this.width);
115
+ image.set({
116
+ originX: "center",
117
+ originY: "center",
118
+ top: this.top,
119
+ left: this.left,
120
+ angle: this.angle,
121
+ });
122
+ return image;
123
+ }
124
+ },
122
125
  });
123
126
  const toClipartObject = (clipartObject) => {
124
127
  return {
@@ -5,6 +5,6 @@ export interface IClipartOptions extends fabric.IGroupOptions {
5
5
  layerId: number;
6
6
  clipartUrl?: string;
7
7
  clipartFile?: File;
8
- hideStroke?: boolean;
8
+ isOriginal?: boolean;
9
9
  isAdditional?: boolean;
10
10
  }
@@ -16,6 +16,7 @@ export default class ImagePlaceholder extends fabric.Group {
16
16
  layerId?: number;
17
17
  locked?: boolean;
18
18
  imageFile?: File;
19
+ maskFile?: File;
19
20
  maskUrl?: string;
20
21
  isAdditional?: boolean;
21
22
  getSettings?: (attribute: string) => any;
@@ -35,12 +35,12 @@ const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.G
35
35
  if (options?.imageFile) {
36
36
  this.loadImage(options?.imageFile);
37
37
  }
38
- if (options?.hideStroke) {
38
+ if (options?.isOriginal) {
39
39
  this.rectObject.set({ strokeWidth: 0 });
40
40
  }
41
41
  else {
42
- if (options?.maskUrl) {
43
- this.loadMask(options?.maskUrl);
42
+ if (options?.maskFile || options?.maskUrl) {
43
+ this.loadMask(options?.maskFile ?? options?.maskUrl);
44
44
  }
45
45
  }
46
46
  },
@@ -41,8 +41,9 @@ export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
41
41
  personalizeId?: number;
42
42
  layerId: number;
43
43
  imageFile?: File;
44
- hideStroke?: boolean;
44
+ isOriginal?: boolean;
45
45
  isAdditional?: boolean;
46
46
  image?: IImageOptions;
47
47
  maskUrl?: string;
48
+ maskFile?: File;
48
49
  }
@@ -55,14 +55,16 @@ const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
55
55
  this.textObject.set({
56
56
  width: this.width,
57
57
  });
58
- if (options?.fontUrl) {
59
- (0, utils_1.loadFontFromUrl)(options?.fontUrl, text?.fontFamily ?? "").then(() => {
60
- this.canvas?.renderAll?.();
61
- });
62
- }
63
- if (options?.hideStroke) {
58
+ if (options?.isOriginal) {
64
59
  this.rectObject.set({ strokeWidth: 0 });
65
60
  }
61
+ else {
62
+ if (options?.fontUrl) {
63
+ (0, utils_1.loadFontFromUrl)(options?.fontUrl, text?.fontFamily ?? "").then(() => {
64
+ this.canvas?.renderAll?.();
65
+ });
66
+ }
67
+ }
66
68
  },
67
69
  autoChangeFontSize: function (changeSpeed) {
68
70
  if (this.width <= this.textObject.__lineWidths ||
@@ -20,6 +20,6 @@ export interface ITextInputOptions extends fabric.IGroupOptions {
20
20
  suffix?: string;
21
21
  };
22
22
  fontUrl?: string;
23
- hideStroke?: boolean;
23
+ isOriginal?: boolean;
24
24
  isAdditional?: boolean;
25
25
  }
@@ -14,5 +14,5 @@ export declare const getObject: (object: any, options?: {
14
14
  }) => Clipart | ImagePlaceholder | TextInput | undefined;
15
15
  export declare const asyncGetObject: (object: any, options?: {
16
16
  isOriginal?: boolean;
17
- }) => Promise<Clipart | ImagePlaceholder | TextInput | undefined>;
17
+ }) => Promise<fabric.Image | Clipart | ImagePlaceholder | TextInput | undefined>;
18
18
  export default fabric;
@@ -114,21 +114,21 @@ const getObject = (object, options) => {
114
114
  case constants_1.OBJECT_TYPES.textInput: {
115
115
  const textInputObject = new TextInputObject_1.default({
116
116
  ...object,
117
- hideStroke: options?.isOriginal,
117
+ isOriginal: options?.isOriginal,
118
118
  });
119
119
  return textInputObject;
120
120
  }
121
121
  case constants_1.OBJECT_TYPES.clipart: {
122
122
  const clipartObject = new ClipartObject_1.default({
123
123
  ...object,
124
- hideStroke: options?.isOriginal,
124
+ isOriginal: options?.isOriginal,
125
125
  });
126
126
  return clipartObject;
127
127
  }
128
128
  case constants_1.OBJECT_TYPES.imagePlaceHolder: {
129
129
  const imagePlaceHolderObject = new ImagePlaceholderObject_1.default({
130
130
  ...object,
131
- hideStroke: options?.isOriginal,
131
+ isOriginal: options?.isOriginal,
132
132
  });
133
133
  return imagePlaceHolderObject;
134
134
  }
@@ -142,21 +142,27 @@ const asyncGetObject = async (object, options) => {
142
142
  case constants_1.OBJECT_TYPES.textInput: {
143
143
  const textInputObject = new TextInputObject_1.default({
144
144
  ...object,
145
- hideStroke: options?.isOriginal,
145
+ isOriginal: options?.isOriginal,
146
146
  });
147
147
  return textInputObject;
148
148
  }
149
149
  case constants_1.OBJECT_TYPES.clipart: {
150
150
  const clipartObject = new ClipartObject_1.default({
151
151
  ...object,
152
- hideStroke: options?.isOriginal,
152
+ isOriginal: options?.isOriginal,
153
153
  });
154
+ if (object?.clipartUrl) {
155
+ const clipart = await clipartObject?.loadCustomizedClipart?.(object?.clipartUrl);
156
+ if (clipart) {
157
+ return clipart;
158
+ }
159
+ }
154
160
  return clipartObject;
155
161
  }
156
162
  case constants_1.OBJECT_TYPES.imagePlaceHolder: {
157
163
  const imagePlaceHolderObject = new ImagePlaceholderObject_1.default({
158
164
  ...object,
159
- hideStroke: options?.isOriginal,
165
+ isOriginal: options?.isOriginal,
160
166
  });
161
167
  if (object?.image) {
162
168
  const image = await imagePlaceHolderObject?.loadCustomizedImage?.(object?.image);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "customized-fabric",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Customized fabric",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",