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.
- package/lib/ClipartObject/index.d.ts +2 -2
- package/lib/ClipartObject/index.js +22 -19
- package/lib/ClipartObject/interfaces.d.ts +1 -1
- package/lib/ImagePlaceholderObject/index.d.ts +1 -0
- package/lib/ImagePlaceholderObject/index.js +3 -3
- package/lib/ImagePlaceholderObject/interfaces.d.ts +2 -1
- package/lib/TextInputObject/index.js +8 -6
- package/lib/TextInputObject/interfaces.d.ts +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +12 -6
- package/package.json +1 -1
| @@ -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 | 
            -
                 | 
| 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?. | 
| 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 | 
            -
                 | 
| 61 | 
            -
                     | 
| 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 {
         | 
| @@ -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?. | 
| 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 | 
            -
                 | 
| 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?. | 
| 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 ||
         | 
    
        package/lib/utils/index.d.ts
    CHANGED
    
    | @@ -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;
         | 
    
        package/lib/utils/index.js
    CHANGED
    
    | @@ -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 | 
            -
                             | 
| 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 | 
            -
                             | 
| 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 | 
            -
                             | 
| 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 | 
            -
                             | 
| 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 | 
            -
                             | 
| 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 | 
            -
                             | 
| 165 | 
            +
                            isOriginal: options?.isOriginal,
         | 
| 160 166 | 
             
                        });
         | 
| 161 167 | 
             
                        if (object?.image) {
         | 
| 162 168 | 
             
                            const image = await imagePlaceHolderObject?.loadCustomizedImage?.(object?.image);
         |