mirror of
https://github.com/wled/WLED.git
synced 2025-07-14 14:26:33 +00:00
Remove legacy CSS gradient code from liveview.htm
Reduce file size by removing legacy CSS gradient code and moving drawing operations to a separate function
This commit is contained in:
parent
1333c41811
commit
0a1d82de2a
@ -6,28 +6,32 @@
|
||||
<meta name="theme-color" content="#222222">
|
||||
<title>WLED Live Preview</title>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
#canv {
|
||||
background: black;
|
||||
filter: brightness(175%);
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
}
|
||||
#canvas {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
#canv {
|
||||
background: black;
|
||||
filter: brightness(175%);
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
var d = document;
|
||||
var ws;
|
||||
var tmout = null;
|
||||
function update() // via HTTP (/json/live)
|
||||
{
|
||||
var c;
|
||||
var ctx;
|
||||
function draw(start, skip, leds, fill) {
|
||||
c.width = d.documentElement.clientWidth;
|
||||
w = c.width / (leds.length - start);
|
||||
for (i = start; i < leds.length; i += skip) {
|
||||
ctx.fillStyle = fill(leds,i);
|
||||
ctx.fillRect((i - start) * w, 0, 4 * w, c.height);
|
||||
}
|
||||
}
|
||||
function update() { // via HTTP (/json/live)
|
||||
if (d.hidden) {
|
||||
clearTimeout(tmout);
|
||||
tmout = setTimeout(update, 250);
|
||||
@ -42,25 +46,7 @@
|
||||
return res.json();
|
||||
})
|
||||
.then(json => {
|
||||
var leddata = (data) => "#" + ((data.length > 6) ? data.substring(2) : data);
|
||||
var len = json.leds.length;
|
||||
try { //canvas support
|
||||
var c = d.getElementById('canvas');
|
||||
var ctx = c.getContext('2d');
|
||||
c.width = d.documentElement.clientWidth;
|
||||
ctx.clearRect(0, 0, c.width, c.height);
|
||||
for (i = 0; i < len; i++) {
|
||||
ctx.fillStyle = leddata(json.leds[i]);
|
||||
ctx.fillRect(i * c.width / len, 0, c.width, c.height);
|
||||
}
|
||||
} catch (e) { //fallback to gradient method
|
||||
var str = "linear-gradient(90deg,";
|
||||
for (i = 0; i < len; i++) {
|
||||
str += leddata(json.leds[i]) + ((i < len -1) ? "," : "");
|
||||
}
|
||||
str += ")";
|
||||
d.getElementById("canv").style.background = str;
|
||||
}
|
||||
draw(0, 1, json.leds, (a,i) => "#" + ((a[i].length > 6) ? a[i].substring(2) : a[i]));
|
||||
clearTimeout(tmout);
|
||||
tmout = setTimeout(update, 40);
|
||||
})
|
||||
@ -71,8 +57,9 @@
|
||||
})
|
||||
}
|
||||
function S() { // Startup function (onload)
|
||||
let wsOn = (window.location.href.indexOf("?ws") > 0);
|
||||
if (!wsOn) {update(); return;}
|
||||
c = d.getElementById('canv');
|
||||
ctx = c.getContext('2d');
|
||||
if (window.location.href.indexOf("?ws") == -1) {update(); return;}
|
||||
|
||||
// Initialize WebSocket connection
|
||||
try {
|
||||
@ -102,26 +89,8 @@
|
||||
if (toString.call(e.data) === '[object ArrayBuffer]') {
|
||||
let leds = new Uint8Array(event.data);
|
||||
if (leds[0] != 76) return; //'L'
|
||||
let len = leds.length;
|
||||
let start = leds[1]==2 ? 4 : 2; // 1 = 1D, 2 = 1D/2D (leds[2]=w, leds[3]=h)
|
||||
let rgb = (i) => `rgb(${leds[i]},${leds[i+1]},${leds[i+2]})`;
|
||||
try { //canvas support
|
||||
var c = d.getElementById('canvas');
|
||||
var ctx = c.getContext('2d');
|
||||
c.width = d.documentElement.clientWidth;
|
||||
ctx.clearRect(0, 0, c.width, c.height);
|
||||
for (i = start; i < len; i+=3) {
|
||||
ctx.fillStyle = rgb(i);
|
||||
ctx.fillRect((i - start) * c.width / (len - start), 0, c.width, c.height);
|
||||
}
|
||||
} catch (e) { //fallback to gradient method
|
||||
let str = "linear-gradient(90deg,";
|
||||
for (i = start; i < len; i+=3) {
|
||||
str += rgb(i) + ((i < len -3) ? "," : "");
|
||||
}
|
||||
str += ")";
|
||||
d.getElementById("canv").style.background = str;
|
||||
}
|
||||
// leds[1] = 1: 1D; leds[1] = 2: 1D/2D (leds[2]=w, leds[3]=h)
|
||||
draw(leds[1]==2 ? 4 : 2, 3, leds, (a,i) => `rgb(${a[i]},${a[i+1]},${a[i+2]})`);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Peek WS error:",err);
|
||||
@ -131,6 +100,6 @@
|
||||
</script>
|
||||
</head>
|
||||
<body onload="S()">
|
||||
<div id="canv"><canvas id="canvas"></canvas></div>
|
||||
<canvas id="canv"></canvas>
|
||||
</body>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user