customized-fabric 1.0.0 → 1.0.2
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/{ClipartObject → customizedFabric/ClipartObject}/index.js +1 -1
- package/lib/{ImagePlaceholderObject → customizedFabric/ImagePlaceholderObject}/index.js +1 -1
- package/lib/{TextInputObject → customizedFabric/TextInputObject}/constants.js +1 -0
- package/lib/{TextInputObject → customizedFabric/TextInputObject}/index.js +1 -1
- package/lib/customizedFabric/index.js +54 -0
- package/lib/index.js +1 -36
- package/package.json +4 -1
- package/src/ClipartObject/constants.ts +0 -9
- package/src/ClipartObject/index.ts +0 -156
- package/src/ClipartObject/interfaces.ts +0 -29
- package/src/ImagePlaceholderObject/constants.ts +0 -9
- package/src/ImagePlaceholderObject/index.ts +0 -155
- package/src/ImagePlaceholderObject/interfaces.ts +0 -21
- package/src/TextInputObject/constants.ts +0 -11
- package/src/TextInputObject/index.ts +0 -205
- package/src/TextInputObject/interfaces.ts +0 -40
- package/src/constants.ts +0 -10
- package/src/index.ts +0 -62
- package/src/interfaces.ts +0 -3
- package/src/objectId/bson_value.ts +0 -18
- package/src/objectId/constants.ts +0 -141
- package/src/objectId/error.ts +0 -85
- package/src/objectId/index.ts +0 -354
- package/src/objectId/parser/utils.ts +0 -29
- package/src/objectId/utils/byte_utils.ts +0 -72
- package/src/objectId/utils/node_byte_utils.ts +0 -173
- package/src/objectId/utils/web_byte_utils.ts +0 -212
- package/src/utils.ts +0 -93
- package/tsconfig.json +0 -110
- /package/lib/{ClipartObject → customizedFabric/ClipartObject}/constants.js +0 -0
- /package/lib/{ClipartObject → customizedFabric/ClipartObject}/interfaces.js +0 -0
- /package/lib/{ImagePlaceholderObject → customizedFabric/ImagePlaceholderObject}/constants.js +0 -0
- /package/lib/{ImagePlaceholderObject → customizedFabric/ImagePlaceholderObject}/interfaces.js +0 -0
- /package/lib/{TextInputObject → customizedFabric/TextInputObject}/interfaces.js +0 -0
- /package/lib/{constants.js → customizedFabric/constants.js} +0 -0
- /package/lib/{interfaces.js → customizedFabric/interfaces.js} +0 -0
- /package/lib/{utils.js → customizedFabric/utils.js} +0 -0
- /package/lib/{objectId → utils/objectId}/bson_value.js +0 -0
- /package/lib/{objectId → utils/objectId}/constants.js +0 -0
- /package/lib/{objectId → utils/objectId}/error.js +0 -0
- /package/lib/{objectId → utils/objectId}/index.js +0 -0
- /package/lib/{objectId → utils/objectId}/parser/utils.js +0 -0
- /package/lib/{objectId → utils/objectId}/utils/byte_utils.js +0 -0
- /package/lib/{objectId → utils/objectId}/utils/node_byte_utils.js +0 -0
- /package/lib/{objectId → utils/objectId}/utils/web_byte_utils.js +0 -0
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Clipart = exports.toClipartObject = void 0;
|
4
4
|
const fabric_1 = require("fabric");
|
5
5
|
const constants_1 = require("./constants");
|
6
|
+
const objectId_1 = require("@/utils/objectId");
|
6
7
|
const utils_1 = require("../utils");
|
7
|
-
const objectId_1 = require("../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({
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImagePlaceholder = exports.toImagePlaceholderObject = void 0;
|
4
4
|
const fabric_1 = require("fabric");
|
5
5
|
const constants_1 = require("./constants");
|
6
|
+
const objectId_1 = require("@/utils/objectId");
|
6
7
|
const utils_1 = require("../utils");
|
7
|
-
const objectId_1 = require("../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({
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TextInput = exports.toTextInputObject = void 0;
|
4
4
|
const fabric_1 = require("fabric");
|
5
5
|
const constants_1 = require("./constants");
|
6
|
+
const objectId_1 = require("@/utils/objectId");
|
6
7
|
const utils_1 = require("../utils");
|
7
|
-
const objectId_1 = require("../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 ?? {};
|
@@ -0,0 +1,54 @@
|
|
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;
|
package/lib/index.js
CHANGED
@@ -14,39 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
|
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("./interfaces"), exports);
|
52
|
-
exports.default = fabric_1.fabric;
|
17
|
+
__exportStar(require("./customizedFabric"), exports);
|
package/package.json
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "customized-fabric",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"description": "Customized fabric",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"types": "lib/index.d.ts",
|
7
|
+
"files": [
|
8
|
+
"lib"
|
9
|
+
],
|
7
10
|
"scripts": {
|
8
11
|
"test": "echo \"Error: no test specified\" && exit 1",
|
9
12
|
"build": "tsc",
|
@@ -1,156 +0,0 @@
|
|
1
|
-
import { fabric } from "fabric";
|
2
|
-
import { CLIPART_OBJECT_ATTRIBUTES } from "./constants";
|
3
|
-
import { loadImageFromFile } from "../utils";
|
4
|
-
import { ClipartObject, IClipartOptions } from "./interfaces";
|
5
|
-
import { ObjectId } from "../objectId";
|
6
|
-
|
7
|
-
const ClipartClass = fabric.util.createClass(fabric.Group, {
|
8
|
-
initialize: function (options?: IClipartOptions) {
|
9
|
-
this.rectObject = new fabric.Rect({
|
10
|
-
width: options?.width,
|
11
|
-
height: options?.height,
|
12
|
-
fill: undefined,
|
13
|
-
originX: "center",
|
14
|
-
originY: "center",
|
15
|
-
objectCaching: false,
|
16
|
-
...CLIPART_OBJECT_ATTRIBUTES.stroke,
|
17
|
-
});
|
18
|
-
|
19
|
-
const imageObject = new fabric.Image("");
|
20
|
-
imageObject.set({
|
21
|
-
width: options?.width,
|
22
|
-
height: options?.height,
|
23
|
-
});
|
24
|
-
this.imageObject = imageObject;
|
25
|
-
|
26
|
-
const group = new fabric.Group([this.rectObject, this.imageObject]);
|
27
|
-
group.setControlsVisibility({
|
28
|
-
mt: false,
|
29
|
-
mr: false,
|
30
|
-
mb: false,
|
31
|
-
ml: false,
|
32
|
-
});
|
33
|
-
this.set(group);
|
34
|
-
this.on("scaling", () => {
|
35
|
-
let width = this.width * this.scaleX;
|
36
|
-
let height = this.height * this.scaleY;
|
37
|
-
const imageScaleX = width / this.imageObject.width;
|
38
|
-
const imageScaleY = height / this.imageObject.height;
|
39
|
-
this.imageObject.set({ scaleX: imageScaleX, scaleY: imageScaleY });
|
40
|
-
this.fitImage(this.imageObject);
|
41
|
-
this.canvas?.renderAll?.();
|
42
|
-
});
|
43
|
-
this.set({
|
44
|
-
_id: new ObjectId().toString(),
|
45
|
-
name: CLIPART_OBJECT_ATTRIBUTES.name,
|
46
|
-
type: CLIPART_OBJECT_ATTRIBUTES.type,
|
47
|
-
...options,
|
48
|
-
layerId: options?.personalizeId ?? options?.layerId,
|
49
|
-
objectCaching: false,
|
50
|
-
});
|
51
|
-
|
52
|
-
if (options?.clipartUrl) {
|
53
|
-
this.loadImageFromUrl(options.clipartUrl);
|
54
|
-
}
|
55
|
-
if (options?.clipartFile) {
|
56
|
-
this.loadImageFromFile(options.clipartFile);
|
57
|
-
}
|
58
|
-
if (options?.hideStroke) {
|
59
|
-
this.rectObject.set({ strokeWidth: 0 });
|
60
|
-
}
|
61
|
-
},
|
62
|
-
|
63
|
-
loadImageFromUrl: async function (url: string) {
|
64
|
-
fabric.Image.fromURL(
|
65
|
-
url,
|
66
|
-
(loadedImage) => {
|
67
|
-
this.loadImage(loadedImage);
|
68
|
-
},
|
69
|
-
{
|
70
|
-
crossOrigin: "anonymous",
|
71
|
-
}
|
72
|
-
);
|
73
|
-
},
|
74
|
-
|
75
|
-
loadImageFromFile: async function (imageFile: File) {
|
76
|
-
const loadedImage = await loadImageFromFile(imageFile);
|
77
|
-
this.loadImage(loadedImage);
|
78
|
-
},
|
79
|
-
|
80
|
-
loadImage: function (image: fabric.Image) {
|
81
|
-
if (image.width && image.height) {
|
82
|
-
image.set({
|
83
|
-
originX: "center",
|
84
|
-
originY: "center",
|
85
|
-
});
|
86
|
-
image.scaleToWidth(this.width);
|
87
|
-
this.remove(this.imageObject);
|
88
|
-
this.imageObject = image;
|
89
|
-
this.add(this.imageObject);
|
90
|
-
this.fitImage(this.imageObject);
|
91
|
-
} else {
|
92
|
-
this.remove(this.imageObject);
|
93
|
-
const imageObject = new fabric.Image("");
|
94
|
-
imageObject.set({
|
95
|
-
width: this.width,
|
96
|
-
height: this.height,
|
97
|
-
});
|
98
|
-
this.imageObject = imageObject;
|
99
|
-
this.add(this.imageObject);
|
100
|
-
this.fitImage(this.imageObject);
|
101
|
-
}
|
102
|
-
this.canvas?.renderAll();
|
103
|
-
},
|
104
|
-
|
105
|
-
getSettings: function (attribute: string) {
|
106
|
-
return this.get(attribute);
|
107
|
-
},
|
108
|
-
|
109
|
-
setSizes: function (options: { width?: number; height?: number }) {
|
110
|
-
const { width, height } = options;
|
111
|
-
if (width) {
|
112
|
-
const scaleX = width / (this?.imageObject?.width ?? this.width);
|
113
|
-
this.imageObject.set({ scaleX, scaleY: scaleX });
|
114
|
-
}
|
115
|
-
if (height) {
|
116
|
-
const scaleY = height / (this?.imageObject?.height ?? this.height);
|
117
|
-
this.imageObject.set({ scaleX: scaleY, scaleY });
|
118
|
-
}
|
119
|
-
this.fitImage(this.imageObject);
|
120
|
-
this.canvas?.renderAll?.();
|
121
|
-
},
|
122
|
-
|
123
|
-
fitImage: function (image: fabric.Image) {
|
124
|
-
const attributes = {
|
125
|
-
scaleX: 1,
|
126
|
-
scaleY: 1,
|
127
|
-
width: (image.width ?? 0) * (image.scaleX ?? 1),
|
128
|
-
height: (image.height ?? 0) * (image.scaleY ?? 1),
|
129
|
-
};
|
130
|
-
this.set(attributes);
|
131
|
-
this.rectObject.set(attributes);
|
132
|
-
},
|
133
|
-
});
|
134
|
-
|
135
|
-
export const toClipartObject = (clipartObject: ClipartObject) => {
|
136
|
-
return {
|
137
|
-
id: clipartObject._id,
|
138
|
-
personalizeId: clipartObject.layerId,
|
139
|
-
layerId: clipartObject.layerId,
|
140
|
-
name: clipartObject.name,
|
141
|
-
locked: clipartObject.locked,
|
142
|
-
isAdditional: clipartObject?.isAdditional,
|
143
|
-
clipartUrl: clipartObject?.clipartUrl,
|
144
|
-
clipartFile: clipartObject?.clipartFile,
|
145
|
-
clipartRootCategoryId: clipartObject?.clipartRootCategoryId,
|
146
|
-
clipartCategoryId: clipartObject?.clipartCategoryId,
|
147
|
-
clipartOptionId: clipartObject?.clipartOptionId,
|
148
|
-
};
|
149
|
-
};
|
150
|
-
|
151
|
-
export class Clipart extends fabric.Group {
|
152
|
-
constructor(options?: IClipartOptions) {
|
153
|
-
super();
|
154
|
-
return new ClipartClass(options);
|
155
|
-
}
|
156
|
-
}
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { ObjectId } from "../objectId";
|
2
|
-
|
3
|
-
export interface ClipartObject extends fabric.Group {
|
4
|
-
_id: ObjectId;
|
5
|
-
layerId?: number;
|
6
|
-
locked?: boolean;
|
7
|
-
isAdditional?: boolean;
|
8
|
-
clipartFile?: File;
|
9
|
-
clipartRootCategoryId?: string;
|
10
|
-
clipartRootCategoryName?: string;
|
11
|
-
clipartCategoryId?: string;
|
12
|
-
clipartCategoryName?: string;
|
13
|
-
clipartOptionId?: number;
|
14
|
-
imageObject?: fabric.Image;
|
15
|
-
clipartUrl?: string;
|
16
|
-
loadImageFromFile: (imageFile: File) => void;
|
17
|
-
loadImageFromUrl: (imageUrl: string) => void;
|
18
|
-
getSettings: (attribute: string) => any;
|
19
|
-
setSizes: (options: { width?: number; height?: number }) => void;
|
20
|
-
}
|
21
|
-
|
22
|
-
export interface IClipartOptions extends fabric.IGroupOptions {
|
23
|
-
_id?: string;
|
24
|
-
personalizeId?: number;
|
25
|
-
layerId: number;
|
26
|
-
clipartUrl?: string;
|
27
|
-
clipartFile?: File;
|
28
|
-
hideStroke?: boolean;
|
29
|
-
}
|
@@ -1,155 +0,0 @@
|
|
1
|
-
import { fabric } from "fabric";
|
2
|
-
import { IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES } from "./constants";
|
3
|
-
import { IImagePlaceholderOptions, ImagePlaceholderObject } from "./interfaces";
|
4
|
-
import { loadImageFromFile } from "../utils";
|
5
|
-
import { ObjectId } from "../objectId";
|
6
|
-
|
7
|
-
const ImagePlaceholderClass = fabric.util.createClass(fabric.Group, {
|
8
|
-
initialize: function (options?: IImagePlaceholderOptions) {
|
9
|
-
this.rectObject = new fabric.Rect({
|
10
|
-
width: options?.width,
|
11
|
-
height: options?.height,
|
12
|
-
fill: undefined,
|
13
|
-
originX: "center",
|
14
|
-
originY: "center",
|
15
|
-
objectCaching: false,
|
16
|
-
...IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.stroke,
|
17
|
-
});
|
18
|
-
|
19
|
-
this.imageObject = new fabric.Image("");
|
20
|
-
|
21
|
-
const group = new fabric.Group([this.rectObject, this.imageObject]);
|
22
|
-
this.set(group);
|
23
|
-
this.on("scaling", () => {
|
24
|
-
let width = this.width * this.scaleX;
|
25
|
-
let height = this.height * this.scaleY;
|
26
|
-
this.setSizes({ width, height });
|
27
|
-
this.canvas?.renderAll();
|
28
|
-
});
|
29
|
-
this.set({
|
30
|
-
_id: new ObjectId().toString(),
|
31
|
-
name: IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.name,
|
32
|
-
type: IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.type,
|
33
|
-
...options,
|
34
|
-
layerId: options?.personalizeId ?? options?.layerId,
|
35
|
-
objectCaching: false,
|
36
|
-
});
|
37
|
-
|
38
|
-
if (options?.imageFile) {
|
39
|
-
this.loadImageFromFile(options?.imageFile);
|
40
|
-
}
|
41
|
-
if (options?.hideStroke) {
|
42
|
-
this.rectObject.set({ strokeWidth: 0 });
|
43
|
-
}
|
44
|
-
},
|
45
|
-
|
46
|
-
loadImageFromUrl: async function (url: string) {
|
47
|
-
fabric.Image.fromURL(
|
48
|
-
url,
|
49
|
-
(loadedImage) => {
|
50
|
-
this.loadImage(loadedImage);
|
51
|
-
},
|
52
|
-
{
|
53
|
-
crossOrigin: "anonymous",
|
54
|
-
}
|
55
|
-
);
|
56
|
-
},
|
57
|
-
|
58
|
-
loadImageFromFile: async function (imageFile: File) {
|
59
|
-
const loadedImage = await loadImageFromFile(imageFile);
|
60
|
-
this.loadImage(loadedImage);
|
61
|
-
},
|
62
|
-
|
63
|
-
loadImage: function (image: fabric.Image) {
|
64
|
-
if (image.width && image.height) {
|
65
|
-
image.set({
|
66
|
-
originX: "center",
|
67
|
-
originY: "center",
|
68
|
-
});
|
69
|
-
this.remove(this.imageObject);
|
70
|
-
this.imageObject = image;
|
71
|
-
this.add(this.imageObject);
|
72
|
-
this.fitImage(this.imageObject);
|
73
|
-
} else {
|
74
|
-
this.remove(this.imageObject);
|
75
|
-
this.imageObject = new fabric.Image("");
|
76
|
-
this.add(this.imageObject);
|
77
|
-
this.fitImage(this.imageObject);
|
78
|
-
}
|
79
|
-
this.canvas?.renderAll();
|
80
|
-
},
|
81
|
-
|
82
|
-
setSizes: function (options: { width?: number; height?: number }) {
|
83
|
-
const { width, height } = options;
|
84
|
-
const attributes: any = {
|
85
|
-
scaleX: 1,
|
86
|
-
scaleY: 1,
|
87
|
-
};
|
88
|
-
if (width) {
|
89
|
-
attributes.width = width;
|
90
|
-
}
|
91
|
-
if (height) {
|
92
|
-
attributes.height = height;
|
93
|
-
}
|
94
|
-
this.set(attributes);
|
95
|
-
this.rectObject.set(attributes);
|
96
|
-
this.fitImage(this.imageObject);
|
97
|
-
this.canvas?.renderAll?.();
|
98
|
-
},
|
99
|
-
|
100
|
-
fitImage: function (image: fabric.Image) {
|
101
|
-
const imageScaleX = this.width / (image?.width ?? 1);
|
102
|
-
const imageScaleY = this.height / (image?.height ?? 1);
|
103
|
-
imageScaleX > imageScaleY
|
104
|
-
? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
|
105
|
-
: image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
|
106
|
-
},
|
107
|
-
|
108
|
-
getSettings: function (attribute: string) {
|
109
|
-
return this.get(attribute);
|
110
|
-
},
|
111
|
-
|
112
|
-
loadUploadedImage: function (imageFile: File) {
|
113
|
-
loadImageFromFile(imageFile).then((loadedImage) => {
|
114
|
-
const clipPath = new fabric.Rect({
|
115
|
-
width: this.width,
|
116
|
-
height: this.height,
|
117
|
-
top: this.top,
|
118
|
-
left: this.left,
|
119
|
-
absolutePositioned: true,
|
120
|
-
});
|
121
|
-
loadedImage.set({ top: this.top, left: this.left, clipPath: clipPath });
|
122
|
-
this.fitImage(loadedImage);
|
123
|
-
this.uploadedImage = loadedImage;
|
124
|
-
const canvas = this?.canvas;
|
125
|
-
canvas?.add(this.uploadedImage);
|
126
|
-
canvas?.renderAll();
|
127
|
-
});
|
128
|
-
},
|
129
|
-
|
130
|
-
removeUploadedImage: function () {
|
131
|
-
const canvas = this?.canvas;
|
132
|
-
canvas?.remove(this.uploadedImage);
|
133
|
-
canvas?.renderAll();
|
134
|
-
},
|
135
|
-
});
|
136
|
-
|
137
|
-
export const toImagePlaceholderObject = (
|
138
|
-
imagePlaceholderObject: ImagePlaceholderObject
|
139
|
-
) => {
|
140
|
-
return {
|
141
|
-
id: imagePlaceholderObject._id,
|
142
|
-
personalizeId: imagePlaceholderObject.layerId,
|
143
|
-
layerId: imagePlaceholderObject.layerId,
|
144
|
-
name: imagePlaceholderObject.name,
|
145
|
-
locked: imagePlaceholderObject.locked,
|
146
|
-
isAdditional: imagePlaceholderObject?.isAdditional,
|
147
|
-
};
|
148
|
-
};
|
149
|
-
|
150
|
-
export class ImagePlaceholder extends fabric.Group {
|
151
|
-
constructor(options?: IImagePlaceholderOptions) {
|
152
|
-
super();
|
153
|
-
return new ImagePlaceholderClass(options);
|
154
|
-
}
|
155
|
-
}
|
@@ -1,21 +0,0 @@
|
|
1
|
-
import { ObjectId } from "../objectId";
|
2
|
-
|
3
|
-
export interface ImagePlaceholderObject extends fabric.Group {
|
4
|
-
_id: ObjectId;
|
5
|
-
layerId: number;
|
6
|
-
locked: boolean;
|
7
|
-
imageFile?: File;
|
8
|
-
isAdditional: boolean;
|
9
|
-
loadImageFromFile: (imageFile: File) => void;
|
10
|
-
loadImageFromUrl: (imageUrl: string) => void;
|
11
|
-
getSettings: (attribute: string) => any;
|
12
|
-
setSizes: (options: { width?: number; height?: number }) => void;
|
13
|
-
}
|
14
|
-
|
15
|
-
export interface IImagePlaceholderOptions extends fabric.IGroupOptions {
|
16
|
-
_id?: string;
|
17
|
-
personalizeId?: number;
|
18
|
-
layerId: number;
|
19
|
-
imageFile?: File;
|
20
|
-
hideStroke?: boolean;
|
21
|
-
}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
export const TEXT_INPUT_OBJECT_ATTRIBUTES = {
|
2
|
-
name: "Text input",
|
3
|
-
type: "TEXT_INPUT",
|
4
|
-
stroke: {
|
5
|
-
stroke: "#000000",
|
6
|
-
strokeDashArray: [5, 5],
|
7
|
-
strokeWidth: 2,
|
8
|
-
},
|
9
|
-
};
|
10
|
-
|
11
|
-
export const PARENT_ATTRIBUTES = ["top", "left", "width", "height", "angle"];
|