Skip to content

Commit ce22a34

Browse files
authored
feat: added Blur model (#129)
1 parent fcb880c commit ce22a34

File tree

7 files changed

+76
-1
lines changed

7 files changed

+76
-1
lines changed

models/Blur/Blur.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
class Blur {
2+
static get Model() {
3+
return {
4+
_class: 'blur',
5+
center: '{0.5, 0.5}',
6+
isEnabled: true,
7+
motionAngle: 0,
8+
radius: 0,
9+
saturation: 1,
10+
type: Blur.Type.Gaussian,
11+
};
12+
}
13+
14+
static get Type() {
15+
return {
16+
Gaussian: 0,
17+
Motion: 1,
18+
Zoom: 2,
19+
Background: 3,
20+
};
21+
}
22+
23+
/**
24+
* @param {Blur.Model} args
25+
* @param {Blur.Model} json
26+
*/
27+
constructor(args, json) {
28+
if (json) Object.assign(this, json);
29+
if (args) Object.assign(this, Blur.Model, args);
30+
}
31+
32+
/**
33+
* @param {Blur.Model} json
34+
* @returns {Blur}
35+
*/
36+
static fromJSON(json) {
37+
return new Blur(null, json);
38+
}
39+
}
40+
41+
module.exports = Blur;

models/Blur/index.d.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
declare enum BlurType {
2+
Gaussian = 0,
3+
Motion = 1,
4+
Zoom = 2,
5+
Background = 3,
6+
}
7+
8+
declare class Blur {
9+
_class: 'blur';
10+
center: string;
11+
isEnabled: boolean;
12+
motionAngle: number;
13+
radius: number;
14+
saturation: number;
15+
type: BlurType;
16+
17+
static readonly Type: BlurType;
18+
static fromJSON(json: Blur): Blur;
19+
20+
constructor(args: Partial<Blur>)
21+
constructor(args: any)
22+
constructor(args: null | undefined, json: Blur)
23+
}
24+
25+
export = Blur;

models/Blur/index.js

Whitespace-only changes.

models/Style/Style.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
const uuid = require('uuid-v4');
1515
const TextStyle = require('../TextStyle');
1616
const Fill = require('../Fill');
17+
const Blur = require('../Blur');
1718
const Border = require('../Border');
1819
const Shadow = require('../Shadow');
1920
const GraphicsContextSettings = require('../GraphicsContextSettings');
@@ -70,6 +71,8 @@ class Style {
7071
* @param {Object[]} args.fills Sent to {@link Fill}
7172
* @param {Object[]} args.borders Sent to {@link Border}
7273
* @param {Object[]} args.shadows Sent to {@link Shadow}
74+
* @param {Object} args.textStyle Sent to {@link TextStyle}
75+
* @param {Blur} args.blur Sent to {@link Blur}
7376
* @param {Style.Model} json
7477
*/
7578
constructor(args = {}, json) {
@@ -79,14 +82,16 @@ class Style {
7982
if (this.fills) this.fills = this.fills.map((fill) => new Fill(null, fill));
8083
if (this.borders) this.borders = this.borders.map((border) => new Border(null, border));
8184
if (this.shadows) this.shadows = this.shadows.map((shadow) => new Shadow(null, shadow));
85+
if (this.blur) this.blur = new Blur(this.blur);
8286
} else {
8387
const id = args.id || uuid().toUpperCase();
8488
Object.assign(this, Style.Model, {
8589
do_objectID: id,
8690
borders: (args.borders || []).map((border) => new Border(border)),
8791
fills: (args.fills || []).map((fill) => new Fill(fill)),
8892
shadows: (args.shadows || []).map((shadow) => new Shadow(shadow)),
89-
textStyle: args.textStyle ? new TextStyle(args.textStyle) : undefined,
93+
...(args.textStyle ? { textStyle: new TextStyle(args.textStyle) } : {}),
94+
...(args.blur ? { blur: new Blur(args.blur) } : {}),
9095
});
9196
}
9297
}

models/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Artboard from './Artboard';
22
import AttributedString from './AttributedString';
33
import Group from './Group';
44
import Bitmap from './Bitmap';
5+
import Blur from './Blur';
56
import Border from './Border';
67
import BorderOptions from './BorderOptions';
78
import Color from './Color';
@@ -42,6 +43,7 @@ export {
4243
AttributedString,
4344
Group,
4445
Bitmap,
46+
Blur,
4547
Border,
4648
BorderOptions,
4749
Color,

models/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = {
1717
AttributedString: require('./AttributedString'),
1818
Group: require('./Group'),
1919
Bitmap: require('./Bitmap'),
20+
Blur: require('./Blur'),
2021
Border: require('./Border'),
2122
BorderOptions: require('./BorderOptions'),
2223
Color: require('./Color'),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"type": "commonjs",
77
"types": "index.d.ts",
8+
"typings": "index.d.ts",
89
"files": [
910
"models",
1011
"utils",

0 commit comments

Comments
 (0)