diff --git a/index.css b/index.css
index 9cc261c..54a6398 100644
--- a/index.css
+++ b/index.css
@@ -15,3 +15,7 @@ body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-weight: 500;
}
+
+#output_error {
+ color: red;
+}
diff --git a/index.html b/index.html
index cdf6de0..0aa6ce5 100644
--- a/index.html
+++ b/index.html
@@ -16,6 +16,7 @@
This is a preview of your gradient.
+
Gradient type
@@ -25,10 +26,11 @@
-
-
-
+
+
+
+
Linear
diff --git a/index.js b/index.js
index d9d3190..20cd5aa 100644
--- a/index.js
+++ b/index.js
@@ -38,6 +38,23 @@ function updateUi() {
button3.onclick = () => removeColor(i);
list.appendChild(button3);
+ // Dynamic distance scaling between color nodes, too much effort to implement rn
+ /*
+ let sliderValue = document.createElement('span');
+ sliderValue.innerText = '50%';
+
+ let slider = document.createElement('input');
+ slider.type = 'range';
+ slider.min = 0;
+ slider.max = 100;
+ slider.value = 50;
+ slider.autocomplete = 'off';
+ slider.oninput = (e) => sliderValue.innerText = `${e.currentTarget.value}%`;
+
+ list.appendChild(slider);
+ list.appendChild(sliderValue);
+ */
+
list.appendChild(document.createElement('br'));
}
}
@@ -48,6 +65,11 @@ function updateUi() {
if (css) {
document.getElementById('preview').style.backgroundImage = css;
document.getElementById('output').value = css;
+
+ if (css.length > 128) {
+ document.getElementById('output_error').innerText = `Warning: The generated CSS is ${css.length} characters long, which exceeds Revolt's limit of 128 characters. You will not be able to use this gradient on Revolt.`;
+ }
+ else document.getElementById('output_error').innerText = '';
}
}
@@ -81,6 +103,23 @@ function moveDown(index) {
updateUi();
}
+/**
+ * @returns {string}
+ */
+function generateColorList() {
+ const noTransition = document.getElementById('no_transition').checked;
+ if (noTransition) {
+ const distance = 100 / colors.length;
+ const colorCodes = [];
+ for (let i = 0; i < colors.length; i++) {
+ colorCodes.push(i == 0 ? colors[i] : `${colors[i]} ${Math.round(distance * i * 10) / 10}%`);
+ colorCodes.push(i == colors.length - 1 ? colors[i] : `${colors[i]} ${Math.round(distance * (i+1) * 10) / 10}%`);
+ }
+ return colorCodes.join(',');
+ }
+ else return colors.join(',');
+}
+
/**
* @returns {string}
*/
@@ -97,7 +136,7 @@ function generateCss() {
*/
function generateCssLinear() {
const rotation = document.getElementById('rotation').value;
- return `linear-gradient(${rotation}deg,${colors.join(',')})`;
+ return `linear-gradient(${rotation}deg,${generateColorList()})`;
}
/**
* @returns {string}
@@ -107,7 +146,7 @@ function generateCssRadial() {
const mode = Array.from(radios).find(r => r.checked).value ?? 'circle';
radios = document.getElementsByName('radial_pos');
const pos = Array.from(radios).find(r => r.checked).value ?? 'center';
- return `radial-gradient(${mode} at ${pos}, ${colors.join(',')})`;
+ return `radial-gradient(${mode} at ${pos}, ${generateColorList()})`;
}
/**
* @returns {string}
@@ -117,7 +156,7 @@ function generateCssConic() {
const showCustomPos = document.getElementById('conic_custom_position').checked;
const x = document.getElementById('conic_x').value;
const y = document.getElementById('conic_y').value;
- return `conic-gradient(from ${rotation}deg${showCustomPos ? ` at ${x}% ${y}%` : ''}, ${colors.join(',')})`;
+ return `conic-gradient(from ${rotation}deg${showCustomPos ? ` at ${x}% ${y}%` : ''}, ${generateColorList()})`;
}
// Initial update