Add warning and transitionless gradient
This commit is contained in:
parent
75eef390ff
commit
300cde1217
|
@ -15,3 +15,7 @@ body {
|
||||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#output_error {
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
<p id="preview">This is a preview of your gradient.</p>
|
<p id="preview">This is a preview of your gradient.</p>
|
||||||
<input type="text" id="output" style="width: calc(100% - 8px)" value="Adjust the options, the output will appear here :3" readonly autocomplete="off" />
|
<input type="text" id="output" style="width: calc(100% - 8px)" value="Adjust the options, the output will appear here :3" readonly autocomplete="off" />
|
||||||
|
<p id="output_error"></p>
|
||||||
|
|
||||||
<h3>Gradient type</h3>
|
<h3>Gradient type</h3>
|
||||||
<input type="radio" id="gradient_linear" value="gradient_linear" name="gradient_type" onchange="updateUi()" autocomplete="off" />
|
<input type="radio" id="gradient_linear" value="gradient_linear" name="gradient_type" onchange="updateUi()" autocomplete="off" />
|
||||||
|
@ -25,10 +26,11 @@
|
||||||
<input type="radio" id="gradient_conic" value="gradient_conic" name="gradient_type" onchange="updateUi()" autocomplete="off" />
|
<input type="radio" id="gradient_conic" value="gradient_conic" name="gradient_type" onchange="updateUi()" autocomplete="off" />
|
||||||
<label for="gradient_conic">Conic Gradient</label><br />
|
<label for="gradient_conic">Conic Gradient</label><br />
|
||||||
|
|
||||||
<div id="color-list">
|
<div id="color-list"></div>
|
||||||
|
|
||||||
</div>
|
|
||||||
<button onclick="appendColor()">Add Color</button>
|
<button onclick="appendColor()">Add Color</button>
|
||||||
|
<br />
|
||||||
|
<input id="no_transition" type="checkbox" autocomplete="off" onchange="updateUi()">
|
||||||
|
<label for="no_transition">No transitions</label>
|
||||||
|
|
||||||
<div id="config_linear" style="display: none;">
|
<div id="config_linear" style="display: none;">
|
||||||
<h4>Linear</h4>
|
<h4>Linear</h4>
|
||||||
|
|
45
index.js
45
index.js
|
@ -38,6 +38,23 @@ function updateUi() {
|
||||||
button3.onclick = () => removeColor(i);
|
button3.onclick = () => removeColor(i);
|
||||||
list.appendChild(button3);
|
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'));
|
list.appendChild(document.createElement('br'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +65,11 @@ function updateUi() {
|
||||||
if (css) {
|
if (css) {
|
||||||
document.getElementById('preview').style.backgroundImage = css;
|
document.getElementById('preview').style.backgroundImage = css;
|
||||||
document.getElementById('output').value = 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();
|
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}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
|
@ -97,7 +136,7 @@ function generateCss() {
|
||||||
*/
|
*/
|
||||||
function generateCssLinear() {
|
function generateCssLinear() {
|
||||||
const rotation = document.getElementById('rotation').value;
|
const rotation = document.getElementById('rotation').value;
|
||||||
return `linear-gradient(${rotation}deg,${colors.join(',')})`;
|
return `linear-gradient(${rotation}deg,${generateColorList()})`;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
|
@ -107,7 +146,7 @@ function generateCssRadial() {
|
||||||
const mode = Array.from(radios).find(r => r.checked).value ?? 'circle';
|
const mode = Array.from(radios).find(r => r.checked).value ?? 'circle';
|
||||||
radios = document.getElementsByName('radial_pos');
|
radios = document.getElementsByName('radial_pos');
|
||||||
const pos = Array.from(radios).find(r => r.checked).value ?? 'center';
|
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}
|
* @returns {string}
|
||||||
|
@ -117,7 +156,7 @@ function generateCssConic() {
|
||||||
const showCustomPos = document.getElementById('conic_custom_position').checked;
|
const showCustomPos = document.getElementById('conic_custom_position').checked;
|
||||||
const x = document.getElementById('conic_x').value;
|
const x = document.getElementById('conic_x').value;
|
||||||
const y = document.getElementById('conic_y').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
|
// Initial update
|
||||||
|
|
Loading…
Reference in a new issue