Skip to content

Commit

Permalink
feat: support for blend mode arg in human readable format (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Goedecke authored and dbanksdesign committed Nov 7, 2019
1 parent a5eff43 commit c945f56
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
6 changes: 5 additions & 1 deletion models/GraphicsContextSettings/GraphicsContextSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* and limitations under the License.
*/

const { blendModeMap } = require('../../utils/maps');

/**
* Options for exporting an artboard
*/
Expand All @@ -36,7 +38,9 @@ class GraphicsContextSettings {
if (json) {
Object.assign(this, json);
} else {
Object.assign(this, GraphicsContextSettings.Model, args);
Object.assign(this, GraphicsContextSettings.Model, args, {
blendMode: blendModeMap[args.blendMode || 'normal'],
});
}
return this;
}
Expand Down
19 changes: 19 additions & 0 deletions utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@ declare const maps: {
bottom: 1,
center: 2,
};
blendModeMap: {
normal: 0,
darken: 1,
multiply: 2,
colorBurn: 3,
lighten: 4,
screen: 5,
colorDodge: 6,
overlay: 7,
softLight: 8,
hardLight: 9,
difference: 10,
exclusion: 11,
hue: 12,
saturation: 13,
luminosity: 14,
plusDarker: 15,
plusLighter: 16,
};
};
declare const stackLayers: (layers: Layer[], gutter?: number) => Layer[];

Expand Down
30 changes: 30 additions & 0 deletions utils/maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,39 @@ Object.keys(verticalAlignmentMap).forEach(key => {
verticalAlignmentMap[verticalAlignmentMap[key]] = key;
});

/**
* Maps blend modes int enums to human-readable strings
* @example
* blendModeMap.multiply // => 2
*/
const blendModeMap = {
normal: 0,
darken: 1,
multiply: 2,
colorBurn: 3,
lighten: 4,
screen: 5,
colorDodge: 6,
overlay: 7,
softLight: 8,
hardLight: 9,
difference: 10,
exclusion: 11,
hue: 12,
saturation: 13,
luminosity: 14,
plusDarker: 15,
plusLighter: 16,
};

Object.keys(blendModeMap).forEach(key => {
blendModeMap[blendModeMap[key]] = key;
});

module.exports = {
textAlignmentMap,
verticalAlignmentMap,
textTransformMap,
textBehaviourMap,
blendModeMap,
};

0 comments on commit c945f56

Please sign in to comment.