Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | 6x 6x 89x 89x 89x 6x 6x 6x 89x 1x 1x 89x 1x 1x 89x 1x 1x 89x 1x 1x 89x 1x 1x 89x 1x 1x 89x 5x 5x 89x 1x 1x 89x 1x 1x 89x 1x 1x 89x 1x 1x 89x 1x 1x | import { EditorAPI, Id } from '../types/CommonTypes'; import { ColorUsage } from '../types/ColorStyleTypes'; import { CornerRadiusUpdateModel, ShapeProperties } from '../types/ShapeTypes'; import { getEditorResponseData } from '../utils/EditorResponseData'; /** * The ShapeController is responsible for all communication regarding Shapes. * Methods inside this controller can be called by `window.SDK.shape.{method-name}` */ export class ShapeController { /** * @ignore */ #editorAPI: EditorAPI; /** * @ignore */ constructor(editorAPI: EditorAPI) { this.#editorAPI = editorAPI; } /** * This method updates properties of the shape * @param id the id of the shapeFrame that needs to get updated. * @param properties A property to update * @returns */ private setShapeProperties = async (id: Id, properties: ShapeProperties) => { const res = await this.#editorAPI; return res .setShapeProperties(id, JSON.stringify(properties)) .then((result) => getEditorResponseData<null>(result)); }; /** * This method will set the visibility of the shape fill. * @param id the id of the shapeFrame that needs to get updated. * @param enableFill Whether the shape fill is visible. * @returns */ setEnableFill = async (id: Id, enableFill: boolean) => { const properties: ShapeProperties = { enableFill: enableFill }; return this.setShapeProperties(id, properties); }; /** * This method will set the shape fill color of a specified shape frame. * @param id the id of the shapeFrame that needs to get updated. * @param fillColor the new shape fill color that you want to set to the shapeFrame. * @returns */ setFillColor = async (id: Id, fillColor: ColorUsage) => { const properties: ShapeProperties = { fillColor: fillColor }; return this.setShapeProperties(id, properties); }; /** * This method will set the visibility of the shape stroke. * @param id the id of the shapeFrame that needs to get updated. * @param enableStroke Whether the shape stroke is visible. * @returns */ setEnableStroke = async (id: Id, enableStroke: boolean) => { const properties: ShapeProperties = { enableStroke: enableStroke }; return this.setShapeProperties(id, properties); }; /** * This method will set the shape stroke color of a specified shape frame. * @param id the id of the shapeFrame that needs to get updated. * @param strokeColor the new shape stroke color that you want to set to the shapeFrame. * @returns */ setStrokeColor = async (id: Id, strokeColor: ColorUsage) => { const properties: ShapeProperties = { strokeColor: strokeColor }; return this.setShapeProperties(id, properties); }; /** * This method will set the shape stroke weight of a specified shape frame. * @param id the id of the shapeFrame that needs to get updated. * @param strokeWeight the new shape stroke weight that you want to set to the shapeFrame. * @returns */ setStrokeWeight = async (id: Id, strokeWeight: number) => { const properties: ShapeProperties = { strokeWeight: strokeWeight }; return this.setShapeProperties(id, properties); }; /** * This method will set the flag to change the way the rectangle shape corners will be changed: all at once or separately. * @param id the id of the shapeFrame that needs to get updated. * @param allCornersSame the new flag that you want to set to the shapeFrame. * @returns */ setFlagAllCornersSame = async (id: Id, allCornersSame: boolean) => { const properties: ShapeProperties = { allCornersSame: allCornersSame }; return this.setShapeProperties(id, properties); }; /** * This method updates radii of the rectangle and polygon shapes * @param id the id of the shapeFrame that needs to get updated. * @param radius A radius object to update a desired corner; * @returns */ private setShapeCorners = async (id: Id, radius: CornerRadiusUpdateModel) => { const res = await this.#editorAPI; return res.setShapeCorners(id, JSON.stringify(radius)).then((result) => getEditorResponseData<null>(result)); }; /** * This method will set the radius for all corners of the rectangle and polygon shapes * @param id the id of the shapeFrame that needs to get updated. * @param radius A radius to update all corners at once; * @returns */ setRadiusAll = async (id: Id, radius: number) => { const cornerRadius: CornerRadiusUpdateModel = { radiusAll: radius }; return this.setShapeCorners(id, cornerRadius); }; /** * This method will set the radius for the top left corner of the rectangle shape * @param id the id of the shapeFrame that needs to get updated. * @param radius A radius to update the top left corner; * @returns */ setRadiusTopLeft = async (id: Id, radius: number) => { const cornerRadius: CornerRadiusUpdateModel = { topLeft: radius }; return this.setShapeCorners(id, cornerRadius); }; /** * This method will set the radius for the bottom left corner of the rectangle shape * @param id the id of the shapeFrame that needs to get updated. * @param radius A radius to update the bottom left corner; * @returns */ setRadiusBottomLeft = async (id: Id, radius: number) => { const cornerRadius: CornerRadiusUpdateModel = { bottomLeft: radius }; return this.setShapeCorners(id, cornerRadius); }; /** * This method will set the radius for the top right corner of the rectangle shape * @param id the id of the shapeFrame that needs to get updated. * @param radius A radius to update the top right corner; * @returns */ setRadiusTopRight = async (id: Id, radius: number) => { const cornerRadius: CornerRadiusUpdateModel = { topRight: radius }; return this.setShapeCorners(id, cornerRadius); }; /** * This method will set the radius for the bottom right corner of the rectangle shape * @param id the id of the shapeFrame that needs to get updated. * @param radius A radius to update the bottom right corner; * @returns */ setRadiusBottomRight = async (id: Id, radius: number) => { const cornerRadius: CornerRadiusUpdateModel = { bottomRight: radius }; return this.setShapeCorners(id, cornerRadius); }; } |