From 850d35c23bb5289521d8bfc2d6b3e5f28b6de393 Mon Sep 17 00:00:00 2001 From: Andrey Chalkin Date: Sat, 18 Jul 2020 14:23:07 +0700 Subject: [PATCH] feat: added Star shape --- models/Star/Star.js | 32 ++++++++++++++++++++++++++++++++ models/Star/index.d.ts | 9 +++++++++ models/Star/index.js | 1 + models/index.d.ts | 2 ++ models/index.js | 1 + 5 files changed, 45 insertions(+) create mode 100644 models/Star/Star.js create mode 100644 models/Star/index.d.ts create mode 100644 models/Star/index.js diff --git a/models/Star/Star.js b/models/Star/Star.js new file mode 100644 index 0000000..3fb5e53 --- /dev/null +++ b/models/Star/Star.js @@ -0,0 +1,32 @@ +const uuid = require('uuid-v4'); +const Layer = require('../Layer'); +const Rect = require('../Rect'); +const Style = require('../Style'); + +class Star extends Layer { + static get Model() { + return { + ...super.Model, + _class: 'star', + numberOfPoints: 5, + radius: 0, + }; + } + + constructor(args, json) { + super(args, json); + if (!json) { + const id = args.id || uuid().toUpperCase(); + Object.assign(this, Star.Model, { + do_objectID: id, + name: args.name || id, + style: args.style ? Style.LayerStyle(args.style) : null, + frame: new Rect(args.frame), + }); + if (args.numberOfPoints) this.numberOfPoints = args.numberOfPoints; + if (args.radius) this.radius = args.radius; + } + } +} + +module.exports = Star; diff --git a/models/Star/index.d.ts b/models/Star/index.d.ts new file mode 100644 index 0000000..4450a06 --- /dev/null +++ b/models/Star/index.d.ts @@ -0,0 +1,9 @@ +import Layer from '../Layer'; + +declare class Star extends Layer { + _class: 'star'; + numberOfPoints: number; + radius: number; +} + +export = Star; diff --git a/models/Star/index.js b/models/Star/index.js new file mode 100644 index 0000000..c11ff89 --- /dev/null +++ b/models/Star/index.js @@ -0,0 +1 @@ +module.exports = require('./Star'); diff --git a/models/index.d.ts b/models/index.d.ts index a2b7474..7acbcc3 100644 --- a/models/index.d.ts +++ b/models/index.d.ts @@ -26,6 +26,7 @@ import ShapePath from './ShapePath'; import SharedStyle from './SharedStyle'; import Sketch from './Sketch'; import Slice from './Slice'; +import Star from './Star'; import StringAttribute from './StringAttribute'; import Style from './Style'; import SymbolInstance from './SymbolInstance'; @@ -66,6 +67,7 @@ export { SharedStyle, Sketch, Slice, + Star, StringAttribute, Style, SymbolInstance, diff --git a/models/index.js b/models/index.js index 4f19f23..735a43d 100644 --- a/models/index.js +++ b/models/index.js @@ -40,6 +40,7 @@ module.exports = { SharedStyle: require('./SharedStyle'), Sketch: require('./Sketch'), Slice: require('./Slice'), + Star: require('./Star'), StringAttribute: require('./StringAttribute'), Style: require('./Style'), SymbolInstance: require('./SymbolInstance'),