2019-04-23 15:09:46 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function RenderGradient(stops, max) {
|
|
|
|
let result = {};
|
|
|
|
|
2019-05-09 10:41:35 +00:00
|
|
|
for(let value in stops)
|
2019-04-23 15:09:46 +00:00
|
|
|
result[value / max] = stops[value];
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-05-09 10:41:35 +00:00
|
|
|
/**
|
|
|
|
* Generates a CSS gradient, given the output of RenderGradient().
|
|
|
|
* @param {[string, string]} stops The stops specification to create a css linear-gradient from. Should be the output of RenderGradient().
|
|
|
|
* @returns {string} The rendered CSS linear-gradient.
|
|
|
|
*/
|
|
|
|
function GenerateCSSGradient(stops) {
|
2019-04-23 15:09:46 +00:00
|
|
|
let stops_processed = [];
|
|
|
|
for(let value in stops) {
|
2019-05-09 10:41:35 +00:00
|
|
|
let valueNumber = parseFloat(value);
|
|
|
|
stops_processed.push(`${stops[value]} ${(valueNumber*100).toFixed(3).replace(/\.?[0]+$/, "")}%`);
|
2019-04-23 15:09:46 +00:00
|
|
|
}
|
|
|
|
return `linear-gradient(to bottom, ${stops_processed.join(", ")})`;
|
|
|
|
}
|
|
|
|
|
2019-05-09 10:41:35 +00:00
|
|
|
export { RenderGradient, GenerateCSSGradient };
|