Skip to content

Commit

Permalink
feat: added Blur model (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
L2jLiga committed Jul 28, 2020
1 parent fcb880c commit ce22a34
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
41 changes: 41 additions & 0 deletions models/Blur/Blur.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class Blur {
static get Model() {
return {
_class: 'blur',
center: '{0.5, 0.5}',
isEnabled: true,
motionAngle: 0,
radius: 0,
saturation: 1,
type: Blur.Type.Gaussian,
};
}

static get Type() {
return {
Gaussian: 0,
Motion: 1,
Zoom: 2,
Background: 3,
};
}

/**
* @param {Blur.Model} args
* @param {Blur.Model} json
*/
constructor(args, json) {
if (json) Object.assign(this, json);
if (args) Object.assign(this, Blur.Model, args);
}

/**
* @param {Blur.Model} json
* @returns {Blur}
*/
static fromJSON(json) {
return new Blur(null, json);
}
}

module.exports = Blur;
25 changes: 25 additions & 0 deletions models/Blur/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
declare enum BlurType {
Gaussian = 0,
Motion = 1,
Zoom = 2,
Background = 3,
}

declare class Blur {
_class: 'blur';
center: string;
isEnabled: boolean;
motionAngle: number;
radius: number;
saturation: number;
type: BlurType;

static readonly Type: BlurType;
static fromJSON(json: Blur): Blur;

constructor(args: Partial<Blur>)
constructor(args: any)
constructor(args: null | undefined, json: Blur)
}

export = Blur;
Empty file added models/Blur/index.js
Empty file.
7 changes: 6 additions & 1 deletion models/Style/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
const uuid = require('uuid-v4');
const TextStyle = require('../TextStyle');
const Fill = require('../Fill');
const Blur = require('../Blur');
const Border = require('../Border');
const Shadow = require('../Shadow');
const GraphicsContextSettings = require('../GraphicsContextSettings');
Expand Down Expand Up @@ -70,6 +71,8 @@ class Style {
* @param {Object[]} args.fills Sent to {@link Fill}
* @param {Object[]} args.borders Sent to {@link Border}
* @param {Object[]} args.shadows Sent to {@link Shadow}
* @param {Object} args.textStyle Sent to {@link TextStyle}
* @param {Blur} args.blur Sent to {@link Blur}
* @param {Style.Model} json
*/
constructor(args = {}, json) {
Expand All @@ -79,14 +82,16 @@ class Style {
if (this.fills) this.fills = this.fills.map((fill) => new Fill(null, fill));
if (this.borders) this.borders = this.borders.map((border) => new Border(null, border));
if (this.shadows) this.shadows = this.shadows.map((shadow) => new Shadow(null, shadow));
if (this.blur) this.blur = new Blur(this.blur);
} else {
const id = args.id || uuid().toUpperCase();
Object.assign(this, Style.Model, {
do_objectID: id,
borders: (args.borders || []).map((border) => new Border(border)),
fills: (args.fills || []).map((fill) => new Fill(fill)),
shadows: (args.shadows || []).map((shadow) => new Shadow(shadow)),
textStyle: args.textStyle ? new TextStyle(args.textStyle) : undefined,
...(args.textStyle ? { textStyle: new TextStyle(args.textStyle) } : {}),
...(args.blur ? { blur: new Blur(args.blur) } : {}),
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions models/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Artboard from './Artboard';
import AttributedString from './AttributedString';
import Group from './Group';
import Bitmap from './Bitmap';
import Blur from './Blur';
import Border from './Border';
import BorderOptions from './BorderOptions';
import Color from './Color';
Expand Down Expand Up @@ -42,6 +43,7 @@ export {
AttributedString,
Group,
Bitmap,
Blur,
Border,
BorderOptions,
Color,
Expand Down
1 change: 1 addition & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
AttributedString: require('./AttributedString'),
Group: require('./Group'),
Bitmap: require('./Bitmap'),
Blur: require('./Blur'),
Border: require('./Border'),
BorderOptions: require('./BorderOptions'),
Color: require('./Color'),
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"type": "commonjs",
"types": "index.d.ts",
"typings": "index.d.ts",
"files": [
"models",
"utils",
Expand Down

0 comments on commit ce22a34

Please sign in to comment.