customized-fabric 1.0.0
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/constants.js +12 -0
- package/lib/ClipartObject/index.js +145 -0
- package/lib/ClipartObject/interfaces.js +2 -0
- package/lib/ImagePlaceholderObject/constants.js +12 -0
- package/lib/ImagePlaceholderObject/index.js +140 -0
- package/lib/ImagePlaceholderObject/interfaces.js +2 -0
- package/lib/TextInputObject/constants.js +13 -0
- package/lib/TextInputObject/index.js +188 -0
- package/lib/TextInputObject/interfaces.js +2 -0
- package/lib/constants.js +12 -0
- package/lib/index.js +52 -0
- package/lib/interfaces.js +19 -0
- package/lib/objectId/bson_value.js +12 -0
- package/lib/objectId/constants.js +107 -0
- package/lib/objectId/error.js +79 -0
- package/lib/objectId/index.js +281 -0
- package/lib/objectId/parser/utils.js +31 -0
- package/lib/objectId/utils/byte_utils.js +28 -0
- package/lib/objectId/utils/node_byte_utils.js +98 -0
- package/lib/objectId/utils/web_byte_utils.js +124 -0
- package/lib/utils.js +90 -0
- package/package.json +21 -0
- package/src/ClipartObject/constants.ts +9 -0
- package/src/ClipartObject/index.ts +156 -0
- package/src/ClipartObject/interfaces.ts +29 -0
- package/src/ImagePlaceholderObject/constants.ts +9 -0
- package/src/ImagePlaceholderObject/index.ts +155 -0
- package/src/ImagePlaceholderObject/interfaces.ts +21 -0
- package/src/TextInputObject/constants.ts +11 -0
- package/src/TextInputObject/index.ts +205 -0
- package/src/TextInputObject/interfaces.ts +40 -0
- package/src/constants.ts +10 -0
- package/src/index.ts +62 -0
- package/src/interfaces.ts +3 -0
- package/src/objectId/bson_value.ts +18 -0
- package/src/objectId/constants.ts +141 -0
- package/src/objectId/error.ts +85 -0
- package/src/objectId/index.ts +354 -0
- package/src/objectId/parser/utils.ts +29 -0
- package/src/objectId/utils/byte_utils.ts +72 -0
- package/src/objectId/utils/node_byte_utils.ts +173 -0
- package/src/objectId/utils/web_byte_utils.ts +212 -0
- package/src/utils.ts +93 -0
- package/tsconfig.json +110 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CLIPART_OBJECT_ATTRIBUTES = void 0;
|
|
4
|
+
exports.CLIPART_OBJECT_ATTRIBUTES = {
|
|
5
|
+
name: "Clipart",
|
|
6
|
+
type: "CLIP_ART",
|
|
7
|
+
stroke: {
|
|
8
|
+
stroke: "#000000",
|
|
9
|
+
strokeDashArray: [5, 5],
|
|
10
|
+
strokeWidth: 2,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Clipart = exports.toClipartObject = void 0;
|
|
4
|
+
const fabric_1 = require("fabric");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const objectId_1 = require("../objectId");
|
|
8
|
+
const ClipartClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
9
|
+
initialize: function (options) {
|
|
10
|
+
this.rectObject = new fabric_1.fabric.Rect({
|
|
11
|
+
width: options?.width,
|
|
12
|
+
height: options?.height,
|
|
13
|
+
fill: undefined,
|
|
14
|
+
originX: "center",
|
|
15
|
+
originY: "center",
|
|
16
|
+
objectCaching: false,
|
|
17
|
+
...constants_1.CLIPART_OBJECT_ATTRIBUTES.stroke,
|
|
18
|
+
});
|
|
19
|
+
const imageObject = new fabric_1.fabric.Image("");
|
|
20
|
+
imageObject.set({
|
|
21
|
+
width: options?.width,
|
|
22
|
+
height: options?.height,
|
|
23
|
+
});
|
|
24
|
+
this.imageObject = imageObject;
|
|
25
|
+
const group = new fabric_1.fabric.Group([this.rectObject, this.imageObject]);
|
|
26
|
+
group.setControlsVisibility({
|
|
27
|
+
mt: false,
|
|
28
|
+
mr: false,
|
|
29
|
+
mb: false,
|
|
30
|
+
ml: false,
|
|
31
|
+
});
|
|
32
|
+
this.set(group);
|
|
33
|
+
this.on("scaling", () => {
|
|
34
|
+
let width = this.width * this.scaleX;
|
|
35
|
+
let height = this.height * this.scaleY;
|
|
36
|
+
const imageScaleX = width / this.imageObject.width;
|
|
37
|
+
const imageScaleY = height / this.imageObject.height;
|
|
38
|
+
this.imageObject.set({ scaleX: imageScaleX, scaleY: imageScaleY });
|
|
39
|
+
this.fitImage(this.imageObject);
|
|
40
|
+
this.canvas?.renderAll?.();
|
|
41
|
+
});
|
|
42
|
+
this.set({
|
|
43
|
+
_id: new objectId_1.ObjectId().toString(),
|
|
44
|
+
name: constants_1.CLIPART_OBJECT_ATTRIBUTES.name,
|
|
45
|
+
type: constants_1.CLIPART_OBJECT_ATTRIBUTES.type,
|
|
46
|
+
...options,
|
|
47
|
+
layerId: options?.personalizeId ?? options?.layerId,
|
|
48
|
+
objectCaching: false,
|
|
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) {
|
|
57
|
+
this.rectObject.set({ strokeWidth: 0 });
|
|
58
|
+
}
|
|
59
|
+
},
|
|
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) {
|
|
72
|
+
if (image.width && image.height) {
|
|
73
|
+
image.set({
|
|
74
|
+
originX: "center",
|
|
75
|
+
originY: "center",
|
|
76
|
+
});
|
|
77
|
+
image.scaleToWidth(this.width);
|
|
78
|
+
this.remove(this.imageObject);
|
|
79
|
+
this.imageObject = image;
|
|
80
|
+
this.add(this.imageObject);
|
|
81
|
+
this.fitImage(this.imageObject);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.remove(this.imageObject);
|
|
85
|
+
const imageObject = new fabric_1.fabric.Image("");
|
|
86
|
+
imageObject.set({
|
|
87
|
+
width: this.width,
|
|
88
|
+
height: this.height,
|
|
89
|
+
});
|
|
90
|
+
this.imageObject = imageObject;
|
|
91
|
+
this.add(this.imageObject);
|
|
92
|
+
this.fitImage(this.imageObject);
|
|
93
|
+
}
|
|
94
|
+
this.canvas?.renderAll();
|
|
95
|
+
},
|
|
96
|
+
getSettings: function (attribute) {
|
|
97
|
+
return this.get(attribute);
|
|
98
|
+
},
|
|
99
|
+
setSizes: function (options) {
|
|
100
|
+
const { width, height } = options;
|
|
101
|
+
if (width) {
|
|
102
|
+
const scaleX = width / (this?.imageObject?.width ?? this.width);
|
|
103
|
+
this.imageObject.set({ scaleX, scaleY: scaleX });
|
|
104
|
+
}
|
|
105
|
+
if (height) {
|
|
106
|
+
const scaleY = height / (this?.imageObject?.height ?? this.height);
|
|
107
|
+
this.imageObject.set({ scaleX: scaleY, scaleY });
|
|
108
|
+
}
|
|
109
|
+
this.fitImage(this.imageObject);
|
|
110
|
+
this.canvas?.renderAll?.();
|
|
111
|
+
},
|
|
112
|
+
fitImage: function (image) {
|
|
113
|
+
const attributes = {
|
|
114
|
+
scaleX: 1,
|
|
115
|
+
scaleY: 1,
|
|
116
|
+
width: (image.width ?? 0) * (image.scaleX ?? 1),
|
|
117
|
+
height: (image.height ?? 0) * (image.scaleY ?? 1),
|
|
118
|
+
};
|
|
119
|
+
this.set(attributes);
|
|
120
|
+
this.rectObject.set(attributes);
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const toClipartObject = (clipartObject) => {
|
|
124
|
+
return {
|
|
125
|
+
id: clipartObject._id,
|
|
126
|
+
personalizeId: clipartObject.layerId,
|
|
127
|
+
layerId: clipartObject.layerId,
|
|
128
|
+
name: clipartObject.name,
|
|
129
|
+
locked: clipartObject.locked,
|
|
130
|
+
isAdditional: clipartObject?.isAdditional,
|
|
131
|
+
clipartUrl: clipartObject?.clipartUrl,
|
|
132
|
+
clipartFile: clipartObject?.clipartFile,
|
|
133
|
+
clipartRootCategoryId: clipartObject?.clipartRootCategoryId,
|
|
134
|
+
clipartCategoryId: clipartObject?.clipartCategoryId,
|
|
135
|
+
clipartOptionId: clipartObject?.clipartOptionId,
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
exports.toClipartObject = toClipartObject;
|
|
139
|
+
class Clipart extends fabric_1.fabric.Group {
|
|
140
|
+
constructor(options) {
|
|
141
|
+
super();
|
|
142
|
+
return new ClipartClass(options);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.Clipart = Clipart;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES = void 0;
|
|
4
|
+
exports.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES = {
|
|
5
|
+
name: "Image placeholder",
|
|
6
|
+
type: "IMAGE_PLACEHOLDER",
|
|
7
|
+
stroke: {
|
|
8
|
+
stroke: "#000000",
|
|
9
|
+
strokeDashArray: [5, 5],
|
|
10
|
+
strokeWidth: 2,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImagePlaceholder = exports.toImagePlaceholderObject = void 0;
|
|
4
|
+
const fabric_1 = require("fabric");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const objectId_1 = require("../objectId");
|
|
8
|
+
const ImagePlaceholderClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
9
|
+
initialize: function (options) {
|
|
10
|
+
this.rectObject = new fabric_1.fabric.Rect({
|
|
11
|
+
width: options?.width,
|
|
12
|
+
height: options?.height,
|
|
13
|
+
fill: undefined,
|
|
14
|
+
originX: "center",
|
|
15
|
+
originY: "center",
|
|
16
|
+
objectCaching: false,
|
|
17
|
+
...constants_1.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.stroke,
|
|
18
|
+
});
|
|
19
|
+
this.imageObject = new fabric_1.fabric.Image("");
|
|
20
|
+
const group = new fabric_1.fabric.Group([this.rectObject, this.imageObject]);
|
|
21
|
+
this.set(group);
|
|
22
|
+
this.on("scaling", () => {
|
|
23
|
+
let width = this.width * this.scaleX;
|
|
24
|
+
let height = this.height * this.scaleY;
|
|
25
|
+
this.setSizes({ width, height });
|
|
26
|
+
this.canvas?.renderAll();
|
|
27
|
+
});
|
|
28
|
+
this.set({
|
|
29
|
+
_id: new objectId_1.ObjectId().toString(),
|
|
30
|
+
name: constants_1.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.name,
|
|
31
|
+
type: constants_1.IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.type,
|
|
32
|
+
...options,
|
|
33
|
+
layerId: options?.personalizeId ?? options?.layerId,
|
|
34
|
+
objectCaching: false,
|
|
35
|
+
});
|
|
36
|
+
if (options?.imageFile) {
|
|
37
|
+
this.loadImageFromFile(options?.imageFile);
|
|
38
|
+
}
|
|
39
|
+
if (options?.hideStroke) {
|
|
40
|
+
this.rectObject.set({ strokeWidth: 0 });
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
loadImageFromUrl: async function (url) {
|
|
44
|
+
fabric_1.fabric.Image.fromURL(url, (loadedImage) => {
|
|
45
|
+
this.loadImage(loadedImage);
|
|
46
|
+
}, {
|
|
47
|
+
crossOrigin: "anonymous",
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
loadImageFromFile: async function (imageFile) {
|
|
51
|
+
const loadedImage = await (0, utils_1.loadImageFromFile)(imageFile);
|
|
52
|
+
this.loadImage(loadedImage);
|
|
53
|
+
},
|
|
54
|
+
loadImage: function (image) {
|
|
55
|
+
if (image.width && image.height) {
|
|
56
|
+
image.set({
|
|
57
|
+
originX: "center",
|
|
58
|
+
originY: "center",
|
|
59
|
+
});
|
|
60
|
+
this.remove(this.imageObject);
|
|
61
|
+
this.imageObject = image;
|
|
62
|
+
this.add(this.imageObject);
|
|
63
|
+
this.fitImage(this.imageObject);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
this.remove(this.imageObject);
|
|
67
|
+
this.imageObject = new fabric_1.fabric.Image("");
|
|
68
|
+
this.add(this.imageObject);
|
|
69
|
+
this.fitImage(this.imageObject);
|
|
70
|
+
}
|
|
71
|
+
this.canvas?.renderAll();
|
|
72
|
+
},
|
|
73
|
+
setSizes: function (options) {
|
|
74
|
+
const { width, height } = options;
|
|
75
|
+
const attributes = {
|
|
76
|
+
scaleX: 1,
|
|
77
|
+
scaleY: 1,
|
|
78
|
+
};
|
|
79
|
+
if (width) {
|
|
80
|
+
attributes.width = width;
|
|
81
|
+
}
|
|
82
|
+
if (height) {
|
|
83
|
+
attributes.height = height;
|
|
84
|
+
}
|
|
85
|
+
this.set(attributes);
|
|
86
|
+
this.rectObject.set(attributes);
|
|
87
|
+
this.fitImage(this.imageObject);
|
|
88
|
+
this.canvas?.renderAll?.();
|
|
89
|
+
},
|
|
90
|
+
fitImage: function (image) {
|
|
91
|
+
const imageScaleX = this.width / (image?.width ?? 1);
|
|
92
|
+
const imageScaleY = this.height / (image?.height ?? 1);
|
|
93
|
+
imageScaleX > imageScaleY
|
|
94
|
+
? image.set({ scaleX: imageScaleY, scaleY: imageScaleY })
|
|
95
|
+
: image.set({ scaleX: imageScaleX, scaleY: imageScaleX });
|
|
96
|
+
},
|
|
97
|
+
getSettings: function (attribute) {
|
|
98
|
+
return this.get(attribute);
|
|
99
|
+
},
|
|
100
|
+
loadUploadedImage: function (imageFile) {
|
|
101
|
+
(0, utils_1.loadImageFromFile)(imageFile).then((loadedImage) => {
|
|
102
|
+
const clipPath = new fabric_1.fabric.Rect({
|
|
103
|
+
width: this.width,
|
|
104
|
+
height: this.height,
|
|
105
|
+
top: this.top,
|
|
106
|
+
left: this.left,
|
|
107
|
+
absolutePositioned: true,
|
|
108
|
+
});
|
|
109
|
+
loadedImage.set({ top: this.top, left: this.left, clipPath: clipPath });
|
|
110
|
+
this.fitImage(loadedImage);
|
|
111
|
+
this.uploadedImage = loadedImage;
|
|
112
|
+
const canvas = this?.canvas;
|
|
113
|
+
canvas?.add(this.uploadedImage);
|
|
114
|
+
canvas?.renderAll();
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
removeUploadedImage: function () {
|
|
118
|
+
const canvas = this?.canvas;
|
|
119
|
+
canvas?.remove(this.uploadedImage);
|
|
120
|
+
canvas?.renderAll();
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
const toImagePlaceholderObject = (imagePlaceholderObject) => {
|
|
124
|
+
return {
|
|
125
|
+
id: imagePlaceholderObject._id,
|
|
126
|
+
personalizeId: imagePlaceholderObject.layerId,
|
|
127
|
+
layerId: imagePlaceholderObject.layerId,
|
|
128
|
+
name: imagePlaceholderObject.name,
|
|
129
|
+
locked: imagePlaceholderObject.locked,
|
|
130
|
+
isAdditional: imagePlaceholderObject?.isAdditional,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
exports.toImagePlaceholderObject = toImagePlaceholderObject;
|
|
134
|
+
class ImagePlaceholder extends fabric_1.fabric.Group {
|
|
135
|
+
constructor(options) {
|
|
136
|
+
super();
|
|
137
|
+
return new ImagePlaceholderClass(options);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.ImagePlaceholder = ImagePlaceholder;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PARENT_ATTRIBUTES = exports.TEXT_INPUT_OBJECT_ATTRIBUTES = void 0;
|
|
4
|
+
exports.TEXT_INPUT_OBJECT_ATTRIBUTES = {
|
|
5
|
+
name: "Text input",
|
|
6
|
+
type: "TEXT_INPUT",
|
|
7
|
+
stroke: {
|
|
8
|
+
stroke: "#000000",
|
|
9
|
+
strokeDashArray: [5, 5],
|
|
10
|
+
strokeWidth: 2,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
exports.PARENT_ATTRIBUTES = ["top", "left", "width", "height", "angle"];
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextInput = exports.toTextInputObject = void 0;
|
|
4
|
+
const fabric_1 = require("fabric");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const utils_1 = require("../utils");
|
|
7
|
+
const objectId_1 = require("../objectId");
|
|
8
|
+
const TextInputClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, {
|
|
9
|
+
initialize: function (options) {
|
|
10
|
+
const { text, ...rest } = options ?? {};
|
|
11
|
+
this.rectObject = new fabric_1.fabric.Rect({
|
|
12
|
+
width: options?.width,
|
|
13
|
+
height: options?.height,
|
|
14
|
+
fill: undefined,
|
|
15
|
+
originX: "center",
|
|
16
|
+
originY: "center",
|
|
17
|
+
objectCaching: false,
|
|
18
|
+
...constants_1.TEXT_INPUT_OBJECT_ATTRIBUTES.stroke,
|
|
19
|
+
});
|
|
20
|
+
this.textObject = new fabric_1.fabric.IText("", {
|
|
21
|
+
originX: "top",
|
|
22
|
+
originY: "left",
|
|
23
|
+
textAlign: "center",
|
|
24
|
+
objectCaching: false,
|
|
25
|
+
...text,
|
|
26
|
+
});
|
|
27
|
+
const group = new fabric_1.fabric.Group([this.rectObject, this.textObject]);
|
|
28
|
+
this.set(group);
|
|
29
|
+
this.on("scaling", () => {
|
|
30
|
+
let width = this.width * this.scaleX;
|
|
31
|
+
let height = this.height * this.scaleY;
|
|
32
|
+
const attributes = {
|
|
33
|
+
scaleX: 1,
|
|
34
|
+
scaleY: 1,
|
|
35
|
+
width,
|
|
36
|
+
height,
|
|
37
|
+
};
|
|
38
|
+
this.set(attributes);
|
|
39
|
+
this.rectObject.set(attributes);
|
|
40
|
+
this.autoChangeFontSize(0.1);
|
|
41
|
+
this.textObject.set({
|
|
42
|
+
width: width,
|
|
43
|
+
});
|
|
44
|
+
this.canvas?.renderAll?.();
|
|
45
|
+
});
|
|
46
|
+
this.set({
|
|
47
|
+
_id: new objectId_1.ObjectId().toString(),
|
|
48
|
+
name: constants_1.TEXT_INPUT_OBJECT_ATTRIBUTES.name,
|
|
49
|
+
type: constants_1.TEXT_INPUT_OBJECT_ATTRIBUTES.type,
|
|
50
|
+
...rest,
|
|
51
|
+
layerId: options?.personalizeId ?? options?.layerId,
|
|
52
|
+
objectCaching: false,
|
|
53
|
+
});
|
|
54
|
+
this.autoChangeFontSize(0.1);
|
|
55
|
+
this.textObject.set({
|
|
56
|
+
width: this.width,
|
|
57
|
+
});
|
|
58
|
+
if (options?.fontUrl) {
|
|
59
|
+
(0, utils_1.loadFontFromUrl)(text?.fontFamily ?? "", options?.fontUrl).then(() => {
|
|
60
|
+
this.canvas?.renderAll?.();
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
if (options?.hideStroke) {
|
|
64
|
+
this.rectObject.set({ strokeWidth: 0 });
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
autoChangeFontSize: function (changeSpeed) {
|
|
68
|
+
if (this.width <= this.textObject.__lineWidths ||
|
|
69
|
+
this.height <= this.textObject.height) {
|
|
70
|
+
while (this.width <= this.textObject.__lineWidths ||
|
|
71
|
+
this.height <= this.textObject.height) {
|
|
72
|
+
this.textObject.set({
|
|
73
|
+
fontSize: this.textObject.fontSize - changeSpeed,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
while (this.textObject.maxFontSize > this.textObject.fontSize &&
|
|
79
|
+
this.width > this.textObject.__lineWidths &&
|
|
80
|
+
this.height > this.textObject.height) {
|
|
81
|
+
this.textObject.set({
|
|
82
|
+
fontSize: this.textObject.fontSize + changeSpeed,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
setText: function (text) {
|
|
88
|
+
this.textObject.set({
|
|
89
|
+
text,
|
|
90
|
+
});
|
|
91
|
+
this.autoChangeFontSize(0.1);
|
|
92
|
+
this.textObject.set({
|
|
93
|
+
width: this.width,
|
|
94
|
+
});
|
|
95
|
+
this.canvas?.renderAll?.();
|
|
96
|
+
},
|
|
97
|
+
setMaxFontSize: function (fontSize) {
|
|
98
|
+
this.textObject.set({
|
|
99
|
+
fontSize,
|
|
100
|
+
});
|
|
101
|
+
if (this.textObject.__lineWidths < this.width &&
|
|
102
|
+
this.textObject.height < this.height) {
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this.autoChangeFontSize(1);
|
|
106
|
+
}
|
|
107
|
+
this.textObject.set({
|
|
108
|
+
width: this.width,
|
|
109
|
+
});
|
|
110
|
+
this.textObject.set({
|
|
111
|
+
maxFontSize: fontSize,
|
|
112
|
+
});
|
|
113
|
+
this.canvas?.renderAll?.();
|
|
114
|
+
},
|
|
115
|
+
setFontFamily: async function (fontName, fontUrl) {
|
|
116
|
+
if (!(0, utils_1.isFontLoaded)(fontName)) {
|
|
117
|
+
await (0, utils_1.loadFontFromUrl)(fontName, fontUrl ?? "");
|
|
118
|
+
}
|
|
119
|
+
this.textObject.set({ fontFamily: fontName });
|
|
120
|
+
this.autoChangeFontSize(0.1);
|
|
121
|
+
this.textObject.set({
|
|
122
|
+
width: this.width,
|
|
123
|
+
});
|
|
124
|
+
this.canvas?.renderAll?.();
|
|
125
|
+
},
|
|
126
|
+
setSizes: function (options) {
|
|
127
|
+
const { width, height } = options;
|
|
128
|
+
if (width && width > this.textObject.__lineWidths) {
|
|
129
|
+
this.set({ width });
|
|
130
|
+
this.textObject.set({ width });
|
|
131
|
+
}
|
|
132
|
+
if (height && height > this.textObject.height) {
|
|
133
|
+
this.set({ height });
|
|
134
|
+
}
|
|
135
|
+
this.canvas?.renderAll?.();
|
|
136
|
+
},
|
|
137
|
+
setTextAttributes: function (options) {
|
|
138
|
+
this.textObject.set(options);
|
|
139
|
+
this.textObject.set({
|
|
140
|
+
width: this.width,
|
|
141
|
+
});
|
|
142
|
+
this.canvas?.renderAll?.();
|
|
143
|
+
},
|
|
144
|
+
getTextAttribute: function (attribute) {
|
|
145
|
+
return this.textObject.get(attribute);
|
|
146
|
+
},
|
|
147
|
+
getSettings: function (attribute) {
|
|
148
|
+
if (constants_1.PARENT_ATTRIBUTES.includes(attribute)) {
|
|
149
|
+
return this.get(attribute);
|
|
150
|
+
}
|
|
151
|
+
return this.textObject.get(attribute);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
const toTextInputObject = (textInputObject) => {
|
|
155
|
+
const textObject = textInputObject.textObject;
|
|
156
|
+
return {
|
|
157
|
+
id: textInputObject?._id,
|
|
158
|
+
personalizeId: textInputObject?.layerId,
|
|
159
|
+
layerId: textInputObject?.layerId,
|
|
160
|
+
name: textInputObject?.name,
|
|
161
|
+
locked: textInputObject?.locked,
|
|
162
|
+
fontId: textInputObject?.fontId,
|
|
163
|
+
fontCategoryId: textInputObject?.fontCategoryId,
|
|
164
|
+
fontUrl: textInputObject?.fontUrl,
|
|
165
|
+
isAdditional: textInputObject?.isAdditional,
|
|
166
|
+
text: {
|
|
167
|
+
fontWeight: textObject?.fontWeight,
|
|
168
|
+
fontSize: textObject?.fontSize,
|
|
169
|
+
textAlign: textObject?.textAlign,
|
|
170
|
+
text: textObject?.text,
|
|
171
|
+
fill: textObject?.fill,
|
|
172
|
+
width: textObject?.width,
|
|
173
|
+
height: textObject?.height,
|
|
174
|
+
fontFamily: textObject?.fontFamily,
|
|
175
|
+
maxFontSize: textObject?.maxFontSize,
|
|
176
|
+
stroke: textObject?.stroke,
|
|
177
|
+
strokeWidth: textObject?.strokeWidth,
|
|
178
|
+
},
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
exports.toTextInputObject = toTextInputObject;
|
|
182
|
+
class TextInput extends fabric_1.fabric.Group {
|
|
183
|
+
constructor(options) {
|
|
184
|
+
super();
|
|
185
|
+
return new TextInputClass(options);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
exports.TextInput = TextInput;
|
package/lib/constants.js
ADDED
|
@@ -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.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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("./interfaces"), exports);
|
|
52
|
+
exports.default = fabric_1.fabric;
|
|
@@ -0,0 +1,19 @@
|
|
|
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);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BSONValue = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
/** @public */
|
|
6
|
+
class BSONValue {
|
|
7
|
+
/** @internal */
|
|
8
|
+
get [Symbol.for("@@mdb.bson.version")]() {
|
|
9
|
+
return constants_1.BSON_MAJOR_VERSION;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.BSONValue = BSONValue;
|