-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
63 lines (56 loc) · 1.4 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const {Color} = require("scenegraph");
var assets = require("assets");
function invertColor(color) {
var a = color.a;
var r = 255 - color.r;
var b = 255 - color.b;
var g = 255 - color.g;
return new Color({r: r, b: b, g: g, a:a});
}
function invertColorAssets() {
var allColors = assets.colors.get();
allColors.forEach((asset) => {
if(asset.color instanceof Color) {
assets.colors.delete(asset);
}
});
allColors.forEach((asset) => {
if(asset.color instanceof Color) {
asset.color = invertColor(asset.color);
assets.colors.add(asset);
}
});
}
function invertNodeColor(node) {
if(node.fill) {
if(node.fill instanceof Color) {
node.fill = invertColor(node.fill);
}
}
if(node.stroke) {
if(node.stroke instanceof Color) {
node.stroke = invertColor(node.stroke);
}
}
}
function invertNode(node) {
invertNodeColor(node);
node.children.forEach((child) =>{
invertNode(child);
});
}
function invertColorsFunction(selection, documentRoot) {
if(selection.items.length === 0) {
invertNode(documentRoot);
invertColorAssets();
} else {
selection.items.forEach((node) => {
invertNode(node);
});
}
}
module.exports = {
commands: {
invertColors: invertColorsFunction
}
};