customized-fabric 1.0.0 → 1.0.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.
Files changed (45) hide show
  1. package/lib/customizedFabric/ClipartObject/constants.js +12 -0
  2. package/lib/customizedFabric/ClipartObject/index.js +145 -0
  3. package/lib/customizedFabric/ClipartObject/interfaces.js +2 -0
  4. package/lib/customizedFabric/ImagePlaceholderObject/constants.js +12 -0
  5. package/lib/customizedFabric/ImagePlaceholderObject/index.js +140 -0
  6. package/lib/customizedFabric/ImagePlaceholderObject/interfaces.js +2 -0
  7. package/lib/customizedFabric/TextInputObject/constants.js +14 -0
  8. package/lib/customizedFabric/TextInputObject/index.js +188 -0
  9. package/lib/customizedFabric/TextInputObject/interfaces.js +2 -0
  10. package/lib/customizedFabric/constants.js +12 -0
  11. package/lib/customizedFabric/index.js +54 -0
  12. package/lib/customizedFabric/interfaces.js +19 -0
  13. package/lib/customizedFabric/utils.js +90 -0
  14. package/lib/index.js +1 -36
  15. package/lib/utils/objectId/bson_value.js +12 -0
  16. package/lib/utils/objectId/constants.js +107 -0
  17. package/lib/utils/objectId/error.js +79 -0
  18. package/lib/utils/objectId/index.js +281 -0
  19. package/lib/utils/objectId/parser/utils.js +31 -0
  20. package/lib/utils/objectId/utils/byte_utils.js +28 -0
  21. package/lib/utils/objectId/utils/node_byte_utils.js +98 -0
  22. package/lib/utils/objectId/utils/web_byte_utils.js +124 -0
  23. package/package.json +4 -1
  24. package/src/ClipartObject/constants.ts +0 -9
  25. package/src/ClipartObject/index.ts +0 -156
  26. package/src/ClipartObject/interfaces.ts +0 -29
  27. package/src/ImagePlaceholderObject/constants.ts +0 -9
  28. package/src/ImagePlaceholderObject/index.ts +0 -155
  29. package/src/ImagePlaceholderObject/interfaces.ts +0 -21
  30. package/src/TextInputObject/constants.ts +0 -11
  31. package/src/TextInputObject/index.ts +0 -205
  32. package/src/TextInputObject/interfaces.ts +0 -40
  33. package/src/constants.ts +0 -10
  34. package/src/index.ts +0 -62
  35. package/src/interfaces.ts +0 -3
  36. package/src/objectId/bson_value.ts +0 -18
  37. package/src/objectId/constants.ts +0 -141
  38. package/src/objectId/error.ts +0 -85
  39. package/src/objectId/index.ts +0 -354
  40. package/src/objectId/parser/utils.ts +0 -29
  41. package/src/objectId/utils/byte_utils.ts +0 -72
  42. package/src/objectId/utils/node_byte_utils.ts +0 -173
  43. package/src/objectId/utils/web_byte_utils.ts +0 -212
  44. package/src/utils.ts +0 -93
  45. package/tsconfig.json +0 -110
@@ -1,205 +0,0 @@
1
- import { fabric } from "fabric";
2
- import { PARENT_ATTRIBUTES, TEXT_INPUT_OBJECT_ATTRIBUTES } from "./constants";
3
- import { isFontLoaded, loadFontFromUrl } from "../utils";
4
- import { ITextInputOptions, TextInputObject } from "./interfaces";
5
- import { ObjectId } from "../objectId";
6
-
7
- const TextInputClass = fabric.util.createClass(fabric.Group, {
8
- initialize: function (options?: ITextInputOptions) {
9
- const { text, ...rest } = options ?? {};
10
-
11
- this.rectObject = new fabric.Rect({
12
- width: options?.width,
13
- height: options?.height,
14
- fill: undefined,
15
- originX: "center",
16
- originY: "center",
17
- objectCaching: false,
18
- ...TEXT_INPUT_OBJECT_ATTRIBUTES.stroke,
19
- });
20
-
21
- this.textObject = new fabric.IText("", {
22
- originX: "top",
23
- originY: "left",
24
- textAlign: "center",
25
- objectCaching: false,
26
- ...text,
27
- });
28
-
29
- const group = new fabric.Group([this.rectObject, this.textObject]);
30
- this.set(group);
31
- this.on("scaling", () => {
32
- let width = this.width * this.scaleX;
33
- let height = this.height * this.scaleY;
34
- const attributes = {
35
- scaleX: 1,
36
- scaleY: 1,
37
- width,
38
- height,
39
- };
40
- this.set(attributes);
41
- this.rectObject.set(attributes);
42
- this.autoChangeFontSize(0.1);
43
- this.textObject.set({
44
- width: width,
45
- });
46
- this.canvas?.renderAll?.();
47
- });
48
- this.set({
49
- _id: new ObjectId().toString(),
50
- name: TEXT_INPUT_OBJECT_ATTRIBUTES.name,
51
- type: TEXT_INPUT_OBJECT_ATTRIBUTES.type,
52
- ...rest,
53
- layerId: options?.personalizeId ?? options?.layerId,
54
- objectCaching: false,
55
- });
56
- this.autoChangeFontSize(0.1);
57
- this.textObject.set({
58
- width: this.width,
59
- });
60
-
61
- if (options?.fontUrl) {
62
- loadFontFromUrl(text?.fontFamily ?? "", options?.fontUrl).then(() => {
63
- this.canvas?.renderAll?.();
64
- });
65
- }
66
- if (options?.hideStroke) {
67
- this.rectObject.set({ strokeWidth: 0 });
68
- }
69
- },
70
-
71
- autoChangeFontSize: function (changeSpeed: number) {
72
- if (
73
- this.width <= this.textObject.__lineWidths ||
74
- this.height <= this.textObject.height
75
- ) {
76
- while (
77
- this.width <= this.textObject.__lineWidths ||
78
- this.height <= this.textObject.height
79
- ) {
80
- this.textObject.set({
81
- fontSize: this.textObject.fontSize - changeSpeed,
82
- });
83
- }
84
- } else {
85
- while (
86
- this.textObject.maxFontSize > this.textObject.fontSize &&
87
- this.width > this.textObject.__lineWidths &&
88
- this.height > this.textObject.height
89
- ) {
90
- this.textObject.set({
91
- fontSize: this.textObject.fontSize + changeSpeed,
92
- });
93
- }
94
- }
95
- },
96
-
97
- setText: function (text: string) {
98
- this.textObject.set({
99
- text,
100
- });
101
- this.autoChangeFontSize(0.1);
102
- this.textObject.set({
103
- width: this.width,
104
- });
105
- this.canvas?.renderAll?.();
106
- },
107
-
108
- setMaxFontSize: function (fontSize: number) {
109
- this.textObject.set({
110
- fontSize,
111
- });
112
- if (
113
- this.textObject.__lineWidths < this.width &&
114
- this.textObject.height < this.height
115
- ) {
116
- } else {
117
- this.autoChangeFontSize(1);
118
- }
119
- this.textObject.set({
120
- width: this.width,
121
- });
122
- this.textObject.set({
123
- maxFontSize: fontSize,
124
- });
125
- this.canvas?.renderAll?.();
126
- },
127
-
128
- setFontFamily: async function (fontName: string, fontUrl?: string) {
129
- if (!isFontLoaded(fontName)) {
130
- await loadFontFromUrl(fontName, fontUrl ?? "");
131
- }
132
- this.textObject.set({ fontFamily: fontName });
133
- this.autoChangeFontSize(0.1);
134
- this.textObject.set({
135
- width: this.width,
136
- });
137
- this.canvas?.renderAll?.();
138
- },
139
-
140
- setSizes: function (options: { width?: number; height?: number }) {
141
- const { width, height } = options;
142
- if (width && width > this.textObject.__lineWidths) {
143
- this.set({ width });
144
- this.textObject.set({ width });
145
- }
146
- if (height && height > this.textObject.height) {
147
- this.set({ height });
148
- }
149
- this.canvas?.renderAll?.();
150
- },
151
-
152
- setTextAttributes: function (options: fabric.ITextOptions) {
153
- this.textObject.set(options);
154
- this.textObject.set({
155
- width: this.width,
156
- });
157
- this.canvas?.renderAll?.();
158
- },
159
-
160
- getTextAttribute: function (attribute: string) {
161
- return this.textObject.get(attribute);
162
- },
163
-
164
- getSettings: function (attribute: string) {
165
- if (PARENT_ATTRIBUTES.includes(attribute)) {
166
- return this.get(attribute);
167
- }
168
- return this.textObject.get(attribute);
169
- },
170
- });
171
-
172
- export const toTextInputObject = (textInputObject: TextInputObject) => {
173
- const textObject = textInputObject.textObject;
174
- return {
175
- id: textInputObject?._id,
176
- personalizeId: textInputObject?.layerId,
177
- layerId: textInputObject?.layerId,
178
- name: textInputObject?.name,
179
- locked: textInputObject?.locked,
180
- fontId: textInputObject?.fontId,
181
- fontCategoryId: textInputObject?.fontCategoryId,
182
- fontUrl: textInputObject?.fontUrl,
183
- isAdditional: textInputObject?.isAdditional,
184
- text: {
185
- fontWeight: textObject?.fontWeight,
186
- fontSize: textObject?.fontSize,
187
- textAlign: textObject?.textAlign,
188
- text: textObject?.text,
189
- fill: textObject?.fill,
190
- width: textObject?.width,
191
- height: textObject?.height,
192
- fontFamily: textObject?.fontFamily,
193
- maxFontSize: (textObject as any)?.maxFontSize,
194
- stroke: textObject?.stroke,
195
- strokeWidth: textObject?.strokeWidth,
196
- },
197
- };
198
- };
199
-
200
- export class TextInput extends fabric.Group {
201
- constructor(options?: ITextInputOptions) {
202
- super();
203
- return new TextInputClass(options);
204
- }
205
- }
@@ -1,40 +0,0 @@
1
- import { ObjectId } from "../objectId";
2
-
3
- export interface TextInputObject extends fabric.Group {
4
- _id: ObjectId;
5
- layerId: number;
6
- locked: boolean;
7
- textObject: fabric.IText;
8
- fontId: number;
9
- fontCategoryId: string;
10
- fontUrl: string;
11
- isAdditional: boolean;
12
- setText: (text: string) => void;
13
- setMaxFontSize: (fontSize: string) => void;
14
- setFontFamily: (fontName: string, fontUrl?: string) => void;
15
- setTextAttributes: (options: fabric.ITextOptions) => void;
16
- getTextAttribute: (attribute: string) => any;
17
- getSettings: (attribute: string) => any;
18
- setSizes: (options: { width?: number; height?: number }) => void;
19
- }
20
-
21
- export interface ITextInputOptions extends fabric.IGroupOptions {
22
- _id?: ObjectId;
23
- personalizeId?: string;
24
- layerId: number;
25
- text: {
26
- fontSize?: number;
27
- fill?: string;
28
- width?: number;
29
- height?: number;
30
- textAlign?: string;
31
- fontWeight?: string;
32
- text: string;
33
- fontFamily?: string;
34
- maxFontSize: number;
35
- stroke?: string;
36
- strokeWidth?: number;
37
- };
38
- fontUrl?: string;
39
- hideStroke?: boolean;
40
- }
package/src/constants.ts DELETED
@@ -1,10 +0,0 @@
1
- import { CLIPART_OBJECT_ATTRIBUTES } from "./ClipartObject/constants";
2
- import { IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES } from "./ImagePlaceholderObject/constants";
3
- import { TEXT_INPUT_OBJECT_ATTRIBUTES } from "./TextInputObject/constants";
4
-
5
- export const OBJECT_TYPES = {
6
- textInput: TEXT_INPUT_OBJECT_ATTRIBUTES.type,
7
- clipart: CLIPART_OBJECT_ATTRIBUTES.type,
8
- imagePlaceHolder: IMAGE_PLACEHOLDER_OBJECT_ATTRIBUTES.type,
9
- activeSelection: "activeSelection",
10
- };
package/src/index.ts DELETED
@@ -1,62 +0,0 @@
1
- import { fabric } from "fabric";
2
- import { TextInput, toTextInputObject } from "./TextInputObject";
3
- import { Clipart, toClipartObject } from "./ClipartObject";
4
- import {
5
- ImagePlaceholder,
6
- toImagePlaceholderObject,
7
- } from "./ImagePlaceholderObject";
8
- import {
9
- ClipartObject,
10
- TextInputObject,
11
- ImagePlaceholderObject,
12
- } from "./interfaces";
13
- import { OBJECT_TYPES } from "./constants";
14
-
15
- (fabric as any).TextInput = TextInput;
16
- (fabric as any).Clipart = Clipart;
17
- (fabric as any).ImagePlaceholder = ImagePlaceholder;
18
-
19
- fabric.Object.prototype.transparentCorners = false;
20
- fabric.Object.prototype.cornerColor = "black";
21
- fabric.Object.prototype.cornerStyle = "circle";
22
- fabric.Object.prototype.cornerStrokeColor = "black";
23
- fabric.Object.prototype.borderColor = "black";
24
-
25
- fabric.Object.prototype.toObject = (function (toObject) {
26
- return function (this: fabric.Object) {
27
- switch (this.type) {
28
- case OBJECT_TYPES.textInput: {
29
- return fabric.util.object.extend(
30
- toObject.call(this),
31
- toTextInputObject(this as TextInputObject)
32
- );
33
- }
34
-
35
- case OBJECT_TYPES.clipart: {
36
- return fabric.util.object.extend(
37
- toObject.call(this),
38
- toClipartObject(this as ClipartObject)
39
- );
40
- }
41
-
42
- case OBJECT_TYPES.imagePlaceHolder: {
43
- return fabric.util.object.extend(
44
- toObject.call(this),
45
- toImagePlaceholderObject(this as ImagePlaceholderObject)
46
- );
47
- }
48
-
49
- default: {
50
- return {};
51
- }
52
- }
53
- };
54
- })(fabric.Object.prototype.toObject);
55
-
56
- export * from "./TextInputObject";
57
- export * from "./ClipartObject";
58
- export * from "./ImagePlaceholderObject";
59
-
60
- export * from "./interfaces";
61
-
62
- export default fabric;
package/src/interfaces.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./TextInputObject/interfaces";
2
- export * from "./ClipartObject/interfaces";
3
- export * from "./ImagePlaceholderObject/interfaces";
@@ -1,18 +0,0 @@
1
- import { BSON_MAJOR_VERSION } from "./constants";
2
-
3
- /** @public */
4
- export abstract class BSONValue {
5
- /** @public */
6
- public abstract get _bsontype(): string;
7
-
8
- /** @internal */
9
- get [Symbol.for("@@mdb.bson.version")](): typeof BSON_MAJOR_VERSION {
10
- return BSON_MAJOR_VERSION;
11
- }
12
-
13
- /** @public */
14
- public abstract inspect(): string;
15
-
16
- /** @internal */
17
- abstract toExtendedJSON(): unknown;
18
- }
@@ -1,141 +0,0 @@
1
- /** @internal */
2
- export const BSON_MAJOR_VERSION = 5 as const;
3
-
4
- /** @internal */
5
- export const BSON_INT32_MAX = 0x7fffffff;
6
- /** @internal */
7
- export const BSON_INT32_MIN = -0x80000000;
8
- /** @internal */
9
- export const BSON_INT64_MAX = Math.pow(2, 63) - 1;
10
- /** @internal */
11
- export const BSON_INT64_MIN = -Math.pow(2, 63);
12
-
13
- /**
14
- * Any integer up to 2^53 can be precisely represented by a double.
15
- * @internal
16
- */
17
- export const JS_INT_MAX = Math.pow(2, 53);
18
-
19
- /**
20
- * Any integer down to -2^53 can be precisely represented by a double.
21
- * @internal
22
- */
23
- export const JS_INT_MIN = -Math.pow(2, 53);
24
-
25
- /** Number BSON Type @internal */
26
- export const BSON_DATA_NUMBER = 1;
27
-
28
- /** String BSON Type @internal */
29
- export const BSON_DATA_STRING = 2;
30
-
31
- /** Object BSON Type @internal */
32
- export const BSON_DATA_OBJECT = 3;
33
-
34
- /** Array BSON Type @internal */
35
- export const BSON_DATA_ARRAY = 4;
36
-
37
- /** Binary BSON Type @internal */
38
- export const BSON_DATA_BINARY = 5;
39
-
40
- /** Binary BSON Type @internal */
41
- export const BSON_DATA_UNDEFINED = 6;
42
-
43
- /** ObjectId BSON Type @internal */
44
- export const BSON_DATA_OID = 7;
45
-
46
- /** Boolean BSON Type @internal */
47
- export const BSON_DATA_BOOLEAN = 8;
48
-
49
- /** Date BSON Type @internal */
50
- export const BSON_DATA_DATE = 9;
51
-
52
- /** null BSON Type @internal */
53
- export const BSON_DATA_NULL = 10;
54
-
55
- /** RegExp BSON Type @internal */
56
- export const BSON_DATA_REGEXP = 11;
57
-
58
- /** Code BSON Type @internal */
59
- export const BSON_DATA_DBPOINTER = 12;
60
-
61
- /** Code BSON Type @internal */
62
- export const BSON_DATA_CODE = 13;
63
-
64
- /** Symbol BSON Type @internal */
65
- export const BSON_DATA_SYMBOL = 14;
66
-
67
- /** Code with Scope BSON Type @internal */
68
- export const BSON_DATA_CODE_W_SCOPE = 15;
69
-
70
- /** 32 bit Integer BSON Type @internal */
71
- export const BSON_DATA_INT = 16;
72
-
73
- /** Timestamp BSON Type @internal */
74
- export const BSON_DATA_TIMESTAMP = 17;
75
-
76
- /** Long BSON Type @internal */
77
- export const BSON_DATA_LONG = 18;
78
-
79
- /** Decimal128 BSON Type @internal */
80
- export const BSON_DATA_DECIMAL128 = 19;
81
-
82
- /** MinKey BSON Type @internal */
83
- export const BSON_DATA_MIN_KEY = 0xff;
84
-
85
- /** MaxKey BSON Type @internal */
86
- export const BSON_DATA_MAX_KEY = 0x7f;
87
-
88
- /** Binary Default Type @internal */
89
- export const BSON_BINARY_SUBTYPE_DEFAULT = 0;
90
-
91
- /** Binary Function Type @internal */
92
- export const BSON_BINARY_SUBTYPE_FUNCTION = 1;
93
-
94
- /** Binary Byte Array Type @internal */
95
- export const BSON_BINARY_SUBTYPE_BYTE_ARRAY = 2;
96
-
97
- /** Binary Deprecated UUID Type @deprecated Please use BSON_BINARY_SUBTYPE_UUID_NEW @internal */
98
- export const BSON_BINARY_SUBTYPE_UUID = 3;
99
-
100
- /** Binary UUID Type @internal */
101
- export const BSON_BINARY_SUBTYPE_UUID_NEW = 4;
102
-
103
- /** Binary MD5 Type @internal */
104
- export const BSON_BINARY_SUBTYPE_MD5 = 5;
105
-
106
- /** Encrypted BSON type @internal */
107
- export const BSON_BINARY_SUBTYPE_ENCRYPTED = 6;
108
-
109
- /** Column BSON type @internal */
110
- export const BSON_BINARY_SUBTYPE_COLUMN = 7;
111
-
112
- /** Binary User Defined Type @internal */
113
- export const BSON_BINARY_SUBTYPE_USER_DEFINED = 128;
114
-
115
- /** @public */
116
- export const BSONType = Object.freeze({
117
- double: 1,
118
- string: 2,
119
- object: 3,
120
- array: 4,
121
- binData: 5,
122
- undefined: 6,
123
- objectId: 7,
124
- bool: 8,
125
- date: 9,
126
- null: 10,
127
- regex: 11,
128
- dbPointer: 12,
129
- javascript: 13,
130
- symbol: 14,
131
- javascriptWithScope: 15,
132
- int: 16,
133
- timestamp: 17,
134
- long: 18,
135
- decimal: 19,
136
- minKey: -1,
137
- maxKey: 127,
138
- } as const);
139
-
140
- /** @public */
141
- export type BSONType = (typeof BSONType)[keyof typeof BSONType];
@@ -1,85 +0,0 @@
1
- import { BSON_MAJOR_VERSION } from "./constants";
2
-
3
- /**
4
- * @public
5
- * @category Error
6
- *
7
- * `BSONError` objects are thrown when BSON ecounters an error.
8
- *
9
- * This is the parent class for all the other errors thrown by this library.
10
- */
11
- export class BSONError extends Error {
12
- /**
13
- * @internal
14
- * The underlying algorithm for isBSONError may change to improve how strict it is
15
- * about determining if an input is a BSONError. But it must remain backwards compatible
16
- * with previous minors & patches of the current major version.
17
- */
18
- protected get bsonError(): true {
19
- return true;
20
- }
21
-
22
- override get name(): string {
23
- return "BSONError";
24
- }
25
-
26
- constructor(message: string) {
27
- super(message);
28
- }
29
-
30
- /**
31
- * @public
32
- *
33
- * All errors thrown from the BSON library inherit from `BSONError`.
34
- * This method can assist with determining if an error originates from the BSON library
35
- * even if it does not pass an `instanceof` check against this class' constructor.
36
- *
37
- * @param value - any javascript value that needs type checking
38
- */
39
- public static isBSONError(value: unknown): value is BSONError {
40
- return (
41
- value != null &&
42
- typeof value === "object" &&
43
- "bsonError" in value &&
44
- value.bsonError === true &&
45
- // Do not access the following properties, just check existence
46
- "name" in value &&
47
- "message" in value &&
48
- "stack" in value
49
- );
50
- }
51
- }
52
-
53
- /**
54
- * @public
55
- * @category Error
56
- */
57
- export class BSONVersionError extends BSONError {
58
- get name(): "BSONVersionError" {
59
- return "BSONVersionError";
60
- }
61
-
62
- constructor() {
63
- super(
64
- `Unsupported BSON version, bson types must be from bson ${BSON_MAJOR_VERSION}.0 or later`
65
- );
66
- }
67
- }
68
-
69
- /**
70
- * @public
71
- * @category Error
72
- *
73
- * An error generated when BSON functions encounter an unexpected input
74
- * or reaches an unexpected/invalid internal state
75
- *
76
- */
77
- export class BSONRuntimeError extends BSONError {
78
- get name(): "BSONRuntimeError" {
79
- return "BSONRuntimeError";
80
- }
81
-
82
- constructor(message: string) {
83
- super(message);
84
- }
85
- }