Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ea25bc

Browse files
committed
Update build-custom-theme to handle keyframes properly
Fixes node-red#2636 Also adds a header to the generated CSS identifing the version of NR and date/time it was generated.
1 parent f5e46a6 commit 8ea25bc

3 files changed

Lines changed: 33 additions & 46 deletions

File tree

packages/node_modules/@node-red/editor-client/src/sass/flow.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,10 @@ g.red-ui-flow-link-unknown path.red-ui-flow-link-line {
342342
stroke-dasharray: 10, 4;
343343
}
344344

345-
@keyframes red-ui-flow-port-tooltip-fadeIn { from { opacity:0; } to { opacity:1; } }
345+
// @keyframes *must* be on multiple lines so build-custom-theme can filter them out
346+
@keyframes red-ui-flow-port-tooltip-fadeIn {
347+
from { opacity:0; } to { opacity:1; }
348+
}
346349

347350
.red-ui-flow-port-tooltip {
348351
opacity:0;

packages/node_modules/@node-red/editor-client/src/sass/notifications.scss

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -71,38 +71,9 @@
7171
}
7272

7373
.red-ui-notification-shake-horizontal {
74-
-webkit-animation: red-ui-notification-shake-horizontal 0.3s steps(2, end) both;
75-
animation: red-ui-notification-shake-horizontal 0.3s steps(2, end) both;
76-
}
77-
78-
@-webkit-keyframes red-ui-notification-shake-horizontal {
79-
0%,
80-
100% {
81-
-webkit-transform: translateX(0);
82-
transform: translateX(0);
83-
}
84-
10%,
85-
30%,
86-
50%,
87-
70% {
88-
-webkit-transform: translateX(-1px);
89-
transform: translateX(-1px);
90-
}
91-
20%,
92-
40%,
93-
60% {
94-
-webkit-transform: translateX(1px);
95-
transform: translateX(1px);
96-
}
97-
// 80% {
98-
// -webkit-transform: translateX(1px);
99-
// transform: translateX(1px);
100-
// }
101-
// 90% {
102-
// -webkit-transform: translateX(-1px);
103-
// transform: translateX(-1px);
104-
// }
74+
animation: red-ui-notification-shake-horizontal 0.3s steps(2, end) both;
10575
}
76+
// @keyframes *must* be on multiple lines so build-custom-theme can filter them out
10677
@keyframes red-ui-notification-shake-horizontal {
10778
0%,
10879
100% {
@@ -122,12 +93,4 @@
12293
-webkit-transform: translateX(1px);
12394
transform: translateX(1px);
12495
}
125-
// 80% {
126-
// -webkit-transform: translateX(1px);
127-
// transform: translateX(1px);
128-
// }
129-
// 90% {
130-
// -webkit-transform: translateX(-1px);
131-
// transform: translateX(-1px);
132-
// }
13396
}

scripts/build-custom-theme.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const sass = require("node-sass");
2929

3030
const knownOpts = {
3131
"help": Boolean,
32+
"long": Boolean,
3233
"in": [path],
3334
"out": [path]
3435
};
@@ -45,7 +46,8 @@ if (parsedArgs.help) {
4546
console.log("Options:");
4647
console.log(" --in FILE Custom colors sass file");
4748
console.log(" --out FILE Where you write the result");
48-
console.log(" -?, --help show this help");
49+
console.log(" --long Do not compress the output");
50+
console.log(" -?, --help Show this help");
4951
console.log("");
5052
process.exit();
5153
}
@@ -64,7 +66,6 @@ if (parsedArgs.in && fs.existsSync(parsedArgs.in)) {
6466
}
6567

6668
// Load base colours
67-
6869
let colorsFile = fs.readFileSync(path.join(__dirname,"../packages/node_modules/@node-red/editor-client/src/sass/colors.scss"),"utf-8")
6970
let updatedColors = [];
7071

@@ -81,7 +82,7 @@ const result = sass.renderSync({
8182
contents: updatedColors.join("\n")
8283
}
8384
}
84-
return {file:"../packages/node_modules/@node-red/editor-client/src/sass/"+url+".scss"}
85+
return {file:path.join(__dirname,"../packages/node_modules/@node-red/editor-client/src/sass/"+url+".scss")}
8586
}
8687
});
8788

@@ -90,8 +91,18 @@ const lines = css.split("\n");
9091
const colorCSS = []
9192
const nonColorCSS = [];
9293

94+
let inKeyFrameBlock = false;
95+
9396
lines.forEach(l => {
94-
if (!/^ /.test(l)) {
97+
if (inKeyFrameBlock) {
98+
nonColorCSS.push(l);
99+
if (/^}/.test(l)) {
100+
inKeyFrameBlock = false;
101+
}
102+
} else if (/^@keyframes/.test(l)) {
103+
nonColorCSS.push(l);
104+
inKeyFrameBlock = true;
105+
} else if (!/^ /.test(l)) {
95106
colorCSS.push(l);
96107
nonColorCSS.push(l);
97108
} else if (/color|border|background|fill|stroke|outline|box-shadow/.test(l)) {
@@ -101,9 +112,19 @@ lines.forEach(l => {
101112
}
102113
});
103114

104-
var output = sass.renderSync({outputStyle: "compressed",data:colorCSS.join("\n")});
115+
116+
const nrPkg = require("../package.json");
117+
const now = new Date().toISOString();
118+
119+
const header = `/*
120+
* Theme generated with Node-RED ${nrPkg.version} on ${now}
121+
*/`;
122+
123+
var output = sass.renderSync({outputStyle: parsedArgs.long?"expanded":"compressed",data:colorCSS.join("\n")});
105124
if (parsedArgs.out) {
106-
fs.writeFileSync(parsedArgs.out,output.css);
125+
126+
fs.writeFileSync(parsedArgs.out,header+"\n"+output.css);
107127
} else {
128+
console.log(header);
108129
console.log(output.css.toString());
109130
}

0 commit comments

Comments
 (0)