Skip to content

Commit

Permalink
feat: Add rounded corners shape
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasaglia committed Oct 11, 2021
1 parent 35360d6 commit 589fb43
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/shapes/index.ts
Expand Up @@ -10,3 +10,4 @@ export * from './trim-shape';
export * from './gradient-stroke-shape';
export * from './repeater-shape';
export * from './star-shape';
export * from './rounded-corners-shape';
59 changes: 59 additions & 0 deletions src/shapes/rounded-corners-shape.ts
@@ -0,0 +1,59 @@
import { PropertyType, ShapeType } from '../constants';
import { Property } from '../properties';
import { Shape } from './shape';

/**
* Rounded Corners shape type.
*/
export class RoundedCornersShape extends Shape {
/**
* RoundedCorners shape type: rp
*/
public readonly type = ShapeType.ROUNDED_CORNERS;

public roundness: Property = new Property(this, PropertyType.NUMBER);

/**
* Convert the Lottie JSON object to class instance.
*
* @param json JSON object
* @returns GroupShape instance
*/
public fromJSON(json: Record<string, any>): RoundedCornersShape {
// Base shape
this.classNames = json.cl;
this.id = json.ln;
this.isHidden = json.hd;
this.matchName = json.mn;
this.name = json.nm;

// This shape
this.roundness.fromJSON(json.r);

return this;
}

/**
* Convert the class instance to Lottie JSON object.
*
* Called by Javascript when serializing object with JSON.stringify()
*
* @returns JSON object
*/
public toJSON(): Record<string, any> {

return {
ty: this.type,

// Base shape
cl: this.classNames,
hd: this.isHidden,
ln: this.id,
mn: this.matchName,
nm: this.name,

// This shape
r: this.roundness,
};
}
}

0 comments on commit 589fb43

Please sign in to comment.