From c87a917e6f5561a434b3fdc5ad383b60ce324e8a Mon Sep 17 00:00:00 2001 From: Kevin Goedecke Date: Fri, 6 Sep 2019 01:32:22 +0200 Subject: [PATCH] feat: Add GraphicsContextSettings (#46) --- .../GraphicsContextSettings.js | 45 +++++++++++++++++++ .../GraphicsContextSettings.test.js | 22 +++++++++ .../__GraphicsContextSettings.json | 5 +++ models/GraphicsContextSettings/index.d.ts | 8 ++++ models/GraphicsContextSettings/index.js | 14 ++++++ models/Shadow/Shadow.js | 7 +-- models/Shadow/index.d.ts | 7 +-- models/Style/Style.js | 7 +-- models/Style/index.d.ts | 7 +-- models/index.d.ts | 2 + models/index.js | 1 + 11 files changed, 105 insertions(+), 20 deletions(-) create mode 100644 models/GraphicsContextSettings/GraphicsContextSettings.js create mode 100644 models/GraphicsContextSettings/GraphicsContextSettings.test.js create mode 100644 models/GraphicsContextSettings/__GraphicsContextSettings.json create mode 100644 models/GraphicsContextSettings/index.d.ts create mode 100644 models/GraphicsContextSettings/index.js diff --git a/models/GraphicsContextSettings/GraphicsContextSettings.js b/models/GraphicsContextSettings/GraphicsContextSettings.js new file mode 100644 index 0000000..0249604 --- /dev/null +++ b/models/GraphicsContextSettings/GraphicsContextSettings.js @@ -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; diff --git a/models/GraphicsContextSettings/GraphicsContextSettings.test.js b/models/GraphicsContextSettings/GraphicsContextSettings.test.js new file mode 100644 index 0000000..f6c1e95 --- /dev/null +++ b/models/GraphicsContextSettings/GraphicsContextSettings.test.js @@ -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)); + }); +}); diff --git a/models/GraphicsContextSettings/__GraphicsContextSettings.json b/models/GraphicsContextSettings/__GraphicsContextSettings.json new file mode 100644 index 0000000..ce5d8e2 --- /dev/null +++ b/models/GraphicsContextSettings/__GraphicsContextSettings.json @@ -0,0 +1,5 @@ +{ + "_class": "graphicsContextSettings", + "blendMode": 0, + "opacity": 1 +} \ No newline at end of file diff --git a/models/GraphicsContextSettings/index.d.ts b/models/GraphicsContextSettings/index.d.ts new file mode 100644 index 0000000..1e28d27 --- /dev/null +++ b/models/GraphicsContextSettings/index.d.ts @@ -0,0 +1,8 @@ +declare class GraphicsContextSettings { + _class: 'graphicsContextSettings'; + blendMode: number; + opacity: number; + constructor(args?: any, json?: any); +} + +export = GraphicsContextSettings; diff --git a/models/GraphicsContextSettings/index.js b/models/GraphicsContextSettings/index.js new file mode 100644 index 0000000..cb61d8e --- /dev/null +++ b/models/GraphicsContextSettings/index.js @@ -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'); diff --git a/models/Shadow/Shadow.js b/models/Shadow/Shadow.js index 8dbb1d0..cb01bd6 100644 --- a/models/Shadow/Shadow.js +++ b/models/Shadow/Shadow.js @@ -12,6 +12,7 @@ */ const Color = require('../Color'); +const GraphicsContextSettings = require('../GraphicsContextSettings'); class Shadow { static get Model() { @@ -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, diff --git a/models/Shadow/index.d.ts b/models/Shadow/index.d.ts index 23e3cc6..2b752f8 100644 --- a/models/Shadow/index.d.ts +++ b/models/Shadow/index.d.ts @@ -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; diff --git a/models/Style/Style.js b/models/Style/Style.js index 32b576f..57a3d1e 100644 --- a/models/Style/Style.js +++ b/models/Style/Style.js @@ -16,6 +16,7 @@ const TextStyle = require('../TextStyle'); const Fill = require('../Fill'); const Border = require('../Border'); const Shadow = require('../Shadow'); +const GraphicsContextSettings = require('../GraphicsContextSettings'); /** * @@ -42,11 +43,7 @@ class Style { fills: [], shadows: [], textStyle: {}, - contextSettings: { - _class: 'graphicsContextSettings', - blendMode: Style.BlendMode.Normal, - opacity: 1, - }, + contextSettings: GraphicsContextSettings.Model, }; } diff --git a/models/Style/index.d.ts b/models/Style/index.d.ts index 7727285..c199a34 100644 --- a/models/Style/index.d.ts +++ b/models/Style/index.d.ts @@ -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: { @@ -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); } diff --git a/models/index.d.ts b/models/index.d.ts index a9f6595..f495a68 100644 --- a/models/index.d.ts +++ b/models/index.d.ts @@ -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'; @@ -38,6 +39,7 @@ export { ExportFormat, ExportOptions, Fill, + GraphicsContextSettings, Gradient, Meta, Oval, diff --git a/models/index.js b/models/index.js index c5387d8..c3f5f69 100644 --- a/models/index.js +++ b/models/index.js @@ -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'),