customized-fabric 2.0.5 → 2.0.6
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.
| @@ -29,9 +29,9 @@ export declare const toCurvedTextObject: (object: CurvedText) => { | |
| 29 29 | 
             
                    prefix: any;
         | 
| 30 30 | 
             
                    infix: any;
         | 
| 31 31 | 
             
                    suffix: any;
         | 
| 32 | 
            -
                     | 
| 32 | 
            +
                    lengthRatio: any;
         | 
| 33 33 | 
             
                    pathSide: any;
         | 
| 34 | 
            -
                     | 
| 34 | 
            +
                    positionAngle: any;
         | 
| 35 35 | 
             
                    isAllCapital: any;
         | 
| 36 36 | 
             
                };
         | 
| 37 37 | 
             
            };
         | 
| @@ -27,7 +27,8 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, | |
| 27 27 | 
             
                        objectCaching: false,
         | 
| 28 28 | 
             
                        fontFamily: "",
         | 
| 29 29 | 
             
                        paintFirst: "stroke",
         | 
| 30 | 
            -
                         | 
| 30 | 
            +
                        lengthRatio: 0.3,
         | 
| 31 | 
            +
                        positionAngle: 0,
         | 
| 31 32 | 
             
                        ...text,
         | 
| 32 33 | 
             
                        text: isAllCapital ? fullText.toUpperCase() : fullText,
         | 
| 33 34 | 
             
                    });
         | 
| @@ -69,12 +70,13 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, | |
| 69 70 | 
             
                    this.fire("scaling");
         | 
| 70 71 | 
             
                },
         | 
| 71 72 | 
             
                autoChangeFontSize: function (changeSpeed = 0.1) {
         | 
| 72 | 
            -
                    let {  | 
| 73 | 
            -
                    const circumference = (0, svg_util_1.getEllipseCircumference)(this.width / 2, this.height / 2);
         | 
| 74 | 
            -
                    const curvedLength = circumference * curvedLengthRatio;
         | 
| 75 | 
            -
                    let maxLineWidth = Math.max(...this.textObject.__lineWidths);
         | 
| 73 | 
            +
                    let { fontSize = 0, lengthRatio = 0.3, maxFontSize } = this.textObject;
         | 
| 76 74 | 
             
                    fontSize = Number(fontSize);
         | 
| 77 | 
            -
                     | 
| 75 | 
            +
                    lengthRatio = Number(lengthRatio);
         | 
| 76 | 
            +
                    maxFontSize = Number(maxFontSize);
         | 
| 77 | 
            +
                    const length = (0, svg_util_1.getEllipseCircumference)(this.width / 2, this.height / 2) * lengthRatio;
         | 
| 78 | 
            +
                    let maxLineWidth = Math.max(...this.textObject.__lineWidths);
         | 
| 79 | 
            +
                    while (length <= maxLineWidth) {
         | 
| 78 80 | 
             
                        fontSize -= changeSpeed;
         | 
| 79 81 | 
             
                        this.textObject.set({
         | 
| 80 82 | 
             
                            fontSize,
         | 
| @@ -82,7 +84,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, | |
| 82 84 | 
             
                        this.canvas?.renderAll?.();
         | 
| 83 85 | 
             
                        maxLineWidth = Math.max(...this.textObject.__lineWidths);
         | 
| 84 86 | 
             
                    }
         | 
| 85 | 
            -
                    while (maxFontSize > fontSize.toFixed(1) &&  | 
| 87 | 
            +
                    while (maxFontSize > fontSize.toFixed(1) && length > maxLineWidth) {
         | 
| 86 88 | 
             
                        fontSize += changeSpeed;
         | 
| 87 89 | 
             
                        this.textObject.set({
         | 
| 88 90 | 
             
                            fontSize,
         | 
| @@ -158,7 +160,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, | |
| 158 160 | 
             
                    return this.textObject.get(attribute);
         | 
| 159 161 | 
             
                },
         | 
| 160 162 | 
             
                calculateTextPath: function (width, height) {
         | 
| 161 | 
            -
                    const { pathSide,  | 
| 163 | 
            +
                    const { pathSide, positionAngle } = this.textObject;
         | 
| 162 164 | 
             
                    const textHeight = 0;
         | 
| 163 165 | 
             
                    const rx = (width - textHeight) / 2;
         | 
| 164 166 | 
             
                    const ry = (height - textHeight) / 2;
         | 
| @@ -173,6 +175,7 @@ const CurvedTextClass = fabric_1.fabric.util.createClass(fabric_1.fabric.Group, | |
| 173 175 | 
             
                    this.pathObject = path;
         | 
| 174 176 | 
             
                    const pathInfo = fabric_1.fabric.util?.getPathSegmentsInfo?.(path.path);
         | 
| 175 177 | 
             
                    const pathLength = pathInfo?.[(pathInfo?.length ?? 0) - 1]?.length;
         | 
| 178 | 
            +
                    const pathStartOffset = ((positionAngle % 360) * pathLength) / 360;
         | 
| 176 179 | 
             
                    this.textObject.set({
         | 
| 177 180 | 
             
                        path,
         | 
| 178 181 | 
             
                        pathLength,
         | 
| @@ -211,9 +214,9 @@ const toCurvedTextObject = (object) => { | |
| 211 214 | 
             
                        prefix: textObject?.prefix,
         | 
| 212 215 | 
             
                        infix: textObject?.infix,
         | 
| 213 216 | 
             
                        suffix: textObject?.suffix,
         | 
| 214 | 
            -
                         | 
| 217 | 
            +
                        lengthRatio: textObject?.lengthRatio,
         | 
| 215 218 | 
             
                        pathSide: textObject?.pathSide,
         | 
| 216 | 
            -
                         | 
| 219 | 
            +
                        positionAngle: textObject?.positionAngle,
         | 
| 217 220 | 
             
                        isAllCapital: textObject?.isAllCapital,
         | 
| 218 221 | 
             
                    },
         | 
| 219 222 | 
             
                };
         |