Skip to content

Commit

Permalink
feat: Add GraphicsContextSettings (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Goedecke authored and dbanksdesign committed Sep 5, 2019
1 parent 84293db commit c87a917
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 20 deletions.
45 changes: 45 additions & 0 deletions models/GraphicsContextSettings/GraphicsContextSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

/**
* Options for exporting an artboard
*/
class GraphicsContextSettings {
/**
* @property {integer} blendMode
* @property {float} opacity
*/
static get Model() {
return {
_class: 'graphicsContextSettings',
blendMode: 0,
opacity: 1,
};
}

/**
*
* @param {GraphicsContextSettings.Model} args
* @param {GraphicsContextSettings.Model} json
*/
constructor(args = {}, json) {
if (json) {
Object.assign(this, json);
} else {
Object.assign(this, GraphicsContextSettings.Model, args);
}
return this;
}
}

module.exports = GraphicsContextSettings;
22 changes: 22 additions & 0 deletions models/GraphicsContextSettings/GraphicsContextSettings.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

const GraphicsContextSettings = require('./index');
const json = require('./__GraphicsContextSettings.json');

describe('GraphicsContextSettings', () => {
it('should work from raw JSON', () => {
const graphicsContextSettings = new GraphicsContextSettings(null, json);
expect(JSON.stringify(json, null, 2)).toEqual(JSON.stringify(graphicsContextSettings, null, 2));
});
});
5 changes: 5 additions & 0 deletions models/GraphicsContextSettings/__GraphicsContextSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"_class": "graphicsContextSettings",
"blendMode": 0,
"opacity": 1
}
8 changes: 8 additions & 0 deletions models/GraphicsContextSettings/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare class GraphicsContextSettings {
_class: 'graphicsContextSettings';
blendMode: number;
opacity: number;
constructor(args?: any, json?: any);
}

export = GraphicsContextSettings;
14 changes: 14 additions & 0 deletions models/GraphicsContextSettings/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/

module.exports = require('./GraphicsContextSettings');
7 changes: 2 additions & 5 deletions models/Shadow/Shadow.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

const Color = require('../Color');
const GraphicsContextSettings = require('../GraphicsContextSettings');

class Shadow {
static get Model() {
Expand All @@ -20,11 +21,7 @@ class Shadow {
isEnabled: true,
blurRadius: 4,
color: Color.Model,
contextSettings: {
_class: 'graphicsContextSettings',
blendMode: 0,
opacity: 1,
},
contextSettings: GraphicsContextSettings.Model,
offsetX: 0,
offsetY: 2,
spread: 0,
Expand Down
7 changes: 2 additions & 5 deletions models/Shadow/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import Color from '../Color';
import GraphicsContextSettings from '../GraphicsContextSettings';

declare class Shadow {
_class: 'shadow';
isEnabled: boolean;
blurRadius: number;
color: Color;
contextSettings: {
_class: 'graphicsContextSettings';
blendMode: number;
opacity: number;
};
contextSettings: GraphicsContextSettings;
offsetX: number;
offsetY: number;
spread: number;
Expand Down
7 changes: 2 additions & 5 deletions models/Style/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const TextStyle = require('../TextStyle');
const Fill = require('../Fill');
const Border = require('../Border');
const Shadow = require('../Shadow');
const GraphicsContextSettings = require('../GraphicsContextSettings');

/**
*
Expand All @@ -42,11 +43,7 @@ class Style {
fills: [],
shadows: [],
textStyle: {},
contextSettings: {
_class: 'graphicsContextSettings',
blendMode: Style.BlendMode.Normal,
opacity: 1,
},
contextSettings: GraphicsContextSettings.Model,
};
}

Expand Down
7 changes: 2 additions & 5 deletions models/Style/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import TextStyle from '../TextStyle';
import Fill from '../Fill';
import Border from '../Border';
import Shadow from '../Shadow';
import GraphicsContextSettings from '../GraphicsContextSettings';

declare class Style {
static MarkerType: {
Expand Down Expand Up @@ -50,11 +51,7 @@ declare class Style {
fills: Fill[];
shadows: Shadow[];
textStyle: TextStyle;
contextSettings: {
_class: 'graphicsContextSettings';
blendMode: number;
opacity: number;
};
contextSettings: GraphicsContextSettings;

constructor(args?: any, json?: any);
}
Expand Down
2 changes: 2 additions & 0 deletions models/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Document from './Document';
import ExportFormat from './ExportFormat';
import ExportOptions from './ExportOptions';
import Fill from './Fill';
import GraphicsContextSettings from './GraphicsContextSettings';
import Gradient from './Gradient';
import Meta from './Meta';
import Oval from './Oval';
Expand Down Expand Up @@ -38,6 +39,7 @@ export {
ExportFormat,
ExportOptions,
Fill,
GraphicsContextSettings,
Gradient,
Meta,
Oval,
Expand Down
1 change: 1 addition & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module.exports = {
ExportFormat: require('./ExportFormat'),
ExportOptions: require('./ExportOptions'),
Fill: require('./Fill'),
GraphicsContextSettings: require('./GraphicsContextSettings'),
Gradient: require('./Gradient'),
Meta: require('./Meta'),
Oval: require('./Oval'),
Expand Down

0 comments on commit c87a917

Please sign in to comment.