mirror of
https://github.com/arthur-pbty/arthur-os.git
synced 2026-08-03 12:47:50 +02:00
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
function clampBrightness(value) {
|
|
var n = Number(value)
|
|
if (!isFinite(n)) return 1
|
|
return Math.max(1, Math.min(100, Math.round(n)))
|
|
}
|
|
|
|
function normalizeScale(scale) {
|
|
var n = parseFloat(String(scale || ""))
|
|
if (!isFinite(n)) return ""
|
|
return String(Math.round(n * 100) / 100)
|
|
}
|
|
|
|
function brightnessName(percent) {
|
|
var p = Math.round(percent)
|
|
if (p >= 95) return "Sun blast"
|
|
if (p >= 80) return "Solar flare"
|
|
if (p >= 65) return "Golden hour"
|
|
if (p >= 45) return "Even day"
|
|
if (p >= 30) return "Soft glow"
|
|
if (p >= 20) return "Lamp light"
|
|
if (p >= 10) return "Candlelit"
|
|
return "Night owl"
|
|
}
|
|
|
|
function parseDisplays(raw) {
|
|
var displays = []
|
|
try {
|
|
displays = raw ? JSON.parse(String(raw)) : []
|
|
} catch (e) {
|
|
displays = []
|
|
}
|
|
if (!Array.isArray(displays)) displays = []
|
|
|
|
var count = 0
|
|
for (var i = 0; i < displays.length; i++) {
|
|
if (displays[i] && displays[i].enabled) count++
|
|
}
|
|
|
|
return {
|
|
displays: displays,
|
|
enabledDisplayCount: count
|
|
}
|
|
}
|
|
|
|
if (typeof module !== "undefined") {
|
|
module.exports = {
|
|
clampBrightness: clampBrightness,
|
|
normalizeScale: normalizeScale,
|
|
brightnessName: brightnessName,
|
|
parseDisplays: parseDisplays
|
|
}
|
|
}
|