mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-16 21:43:33 +08:00
💋 Sync 2026-10-16 23:55:30
This commit is contained in:
1 parent
76f10c2a74
commit
1849cc6156
254 files changed
+25484
-8840
No files matched your search
@@ -0,0 +1,12 @@
|
||||
config global
|
||||
option login_style 'classic'
|
||||
option primary '#5e72e4'
|
||||
option dark_primary '#483d8b'
|
||||
option dark_primary_mode 'auto'
|
||||
option dark_glass_mode 'inherit'
|
||||
option blur '10'
|
||||
option blur_dark '10'
|
||||
option transparency '0.5'
|
||||
option transparency_dark '0.5'
|
||||
option mode 'normal'
|
||||
option online_wallpaper 'none'
|
||||
@@ -1,5 +1,64 @@
|
||||
#!/bin/sh
|
||||
|
||||
# The empty legacy package saves its conffile before releasing file ownership.
|
||||
if [ -f /etc/argon-config-migration/argon ]; then
|
||||
cp -p /etc/argon-config-migration/argon /etc/config/argon || exit 1
|
||||
rm -f /etc/argon-config-migration/argon
|
||||
rmdir /etc/argon-config-migration 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Preserve configured values and migrate the old Bing switch only when needed.
|
||||
[ -e /etc/config/argon ] || touch /etc/config/argon || exit 1
|
||||
if ! uci -q get 'argon.@global[0]' >/dev/null; then
|
||||
uci -q add argon global >/dev/null
|
||||
fi
|
||||
old_bing="$(uci -q get 'argon.@global[0].bing_background')"
|
||||
if [ -n "$old_bing" ]; then
|
||||
if ! uci -q get 'argon.@global[0].online_wallpaper' >/dev/null; then
|
||||
if [ "$old_bing" = 1 ]; then
|
||||
uci set 'argon.@global[0].online_wallpaper=bing'
|
||||
else
|
||||
uci set 'argon.@global[0].online_wallpaper=none'
|
||||
fi
|
||||
fi
|
||||
uci -q delete 'argon.@global[0].bing_background'
|
||||
fi
|
||||
# Missing selectors identify old installations; preserve their separate choices.
|
||||
if ! uci -q get 'argon.@global[0].dark_primary_mode' >/dev/null; then
|
||||
if [ -n "$(uci -q get 'argon.@global[0].dark_primary')" ]; then
|
||||
uci set 'argon.@global[0].dark_primary_mode=custom'
|
||||
else
|
||||
uci set 'argon.@global[0].dark_primary_mode=auto'
|
||||
fi
|
||||
fi
|
||||
if ! uci -q get 'argon.@global[0].dark_glass_mode' >/dev/null; then
|
||||
light_blur="$(uci -q get 'argon.@global[0].blur')"
|
||||
light_opacity="$(uci -q get 'argon.@global[0].transparency')"
|
||||
dark_blur="$(uci -q get 'argon.@global[0].blur_dark')"
|
||||
dark_opacity="$(uci -q get 'argon.@global[0].transparency_dark')"
|
||||
if [ "${dark_blur:-${light_blur:-10}}" != "${light_blur:-10}" ] ||
|
||||
[ "${dark_opacity:-${light_opacity:-0.5}}" != "${light_opacity:-0.5}" ]; then
|
||||
uci set 'argon.@global[0].dark_glass_mode=custom'
|
||||
else
|
||||
uci set 'argon.@global[0].dark_glass_mode=inherit'
|
||||
fi
|
||||
fi
|
||||
while read -r option value; do
|
||||
uci -q get "argon.@global[0].$option" >/dev/null ||
|
||||
uci set "argon.@global[0].$option=$value"
|
||||
done <<'DEFAULTS'
|
||||
login_style classic
|
||||
primary #5e72e4
|
||||
dark_primary #483d8b
|
||||
blur 10
|
||||
blur_dark 10
|
||||
transparency 0.5
|
||||
transparency_dark 0.5
|
||||
mode normal
|
||||
online_wallpaper none
|
||||
DEFAULTS
|
||||
uci commit argon
|
||||
|
||||
if [ "$PKG_UPGRADE" != 1 ]; then
|
||||
uci get luci.themes.Argon >/dev/null 2>&1 || \
|
||||
uci batch <<-EOF
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/www/luci-static/argon/branding/
|
||||
/www/luci-static/argon/background/
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
readonly bg_path="/www/luci-static/argon/background"
|
||||
readonly tmp_path="/tmp/argon_background.tmp"
|
||||
|
||||
valid_filename() {
|
||||
case "$1" in
|
||||
""|"."|".."|*/*|*\\*) return 1 ;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
|
||||
result() {
|
||||
printf '{ "result": %s }\n' "$1"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
"list")
|
||||
json_init
|
||||
json_add_object "avail"
|
||||
json_close_object
|
||||
json_add_object "remove"
|
||||
json_add_string "filename" "filename"
|
||||
json_close_object
|
||||
json_add_object "rename"
|
||||
json_add_string "newname" "filename"
|
||||
json_close_object
|
||||
json_dump
|
||||
json_cleanup
|
||||
;;
|
||||
"call")
|
||||
case "$2" in
|
||||
"avail")
|
||||
json_init
|
||||
json_add_int "avail" "$(df | grep -E '/$' | awk '{print $4}')"
|
||||
json_dump
|
||||
json_cleanup
|
||||
;;
|
||||
"remove")
|
||||
read -r input
|
||||
json_load "$input" || { result 255; exit 0; }
|
||||
json_get_var filename "filename"
|
||||
json_cleanup
|
||||
|
||||
if ! valid_filename "$filename"; then
|
||||
result 255
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [ -d "$bg_path/$filename" ]; then
|
||||
result 255
|
||||
elif rm -f "$bg_path/$filename" 2>/dev/null; then
|
||||
result 0
|
||||
else
|
||||
result 1
|
||||
fi
|
||||
;;
|
||||
"rename")
|
||||
read -r input
|
||||
json_load "$input" || { result 255; exit 0; }
|
||||
json_get_var newname "newname"
|
||||
json_cleanup
|
||||
|
||||
if ! valid_filename "$newname" || [ -L "$bg_path/$newname" ] ||
|
||||
{ [ -e "$bg_path/$newname" ] && [ ! -f "$bg_path/$newname" ]; }; then
|
||||
result 255
|
||||
exit 0
|
||||
fi
|
||||
case "$(printf '%s' "$newname" | tr 'A-Z' 'a-z')" in
|
||||
*.jpg|*.jpeg|*.png|*.gif|*.webp|*.mp4|*.webm) ;;
|
||||
*) result 255; exit 0 ;;
|
||||
esac
|
||||
|
||||
if [ -f "$tmp_path" ] && [ ! -L "$tmp_path" ] &&
|
||||
mkdir -p "$bg_path" && chmod 0644 "$tmp_path" &&
|
||||
mv -f "$tmp_path" "$bg_path/$newname" 2>/dev/null; then
|
||||
result 0
|
||||
else
|
||||
result 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
readonly config_dir='/etc/config'
|
||||
|
||||
status() {
|
||||
printf '{"result":%s,"mode":"%s"}\n' "$1" "${mode:-normal}"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
list)
|
||||
printf '%s\n' '{"get":{},"set":{"mode":""}}'
|
||||
;;
|
||||
call)
|
||||
case "$2" in get|set) ;; *) exit 1 ;; esac
|
||||
if [ "$2" = set ]; then
|
||||
read -r input
|
||||
json_load "$input" || { status 2; exit 0; }
|
||||
json_get_var requested mode
|
||||
case "$requested" in normal|light|dark) ;; *) status 2; exit 0 ;; esac
|
||||
fi
|
||||
# A private delta directory keeps unrelated UCI changes out of this commit.
|
||||
umask 077
|
||||
work="$(mktemp -d /tmp/argon-appearance.XXXXXX)" || { status 1; exit 0; }
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
trap 'exit 1' HUP INT TERM
|
||||
uci -q -c "$config_dir" -t "$work" get 'argon.@global[0]' >/dev/null || { status 1; exit 0; }
|
||||
current="$(uci -q -c "$config_dir" -t "$work" get 'argon.@global[0].mode')"
|
||||
mode="$current"
|
||||
case "$mode" in normal|light|dark) ;; *) mode=normal ;; esac
|
||||
if [ "$2" = set ] && [ "$current" != "$requested" ]; then
|
||||
uci -q -c "$config_dir" -t "$work" set "argon.@global[0].mode=$requested" &&
|
||||
uci -q -c "$config_dir" -t "$work" commit argon || { status 1; exit 0; }
|
||||
mode="$requested"
|
||||
fi
|
||||
status 0
|
||||
;;
|
||||
esac
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
readonly branding_dir='/www/luci-static/argon/branding'
|
||||
readonly lock_dir='/tmp/argon_branding.lock'
|
||||
readonly upload_prefix='/tmp/argon_branding_'
|
||||
|
||||
valid_destination() {
|
||||
[ ! -L "$1" ] && { [ ! -e "$1" ] || [ -f "$1" ]; }
|
||||
}
|
||||
|
||||
valid_asset() {
|
||||
printf '%s\n' "$1" | grep -Eq '^image-[0-9a-f]{64}\.png$' &&
|
||||
[ -f "$branding_dir/$1" ] && [ ! -L "$branding_dir/$1" ]
|
||||
}
|
||||
|
||||
read_state() {
|
||||
favicon=''
|
||||
logo=''
|
||||
[ -d "$branding_dir" ] && [ ! -L "$branding_dir" ] || return 0
|
||||
if [ -f "$branding_dir/current.json" ] && [ ! -L "$branding_dir/current.json" ] &&
|
||||
[ "$(wc -c < "$branding_dir/current.json")" -le 1024 ] &&
|
||||
json_load "$(cat "$branding_dir/current.json")"; then
|
||||
json_get_var favicon favicon
|
||||
json_get_var logo logo
|
||||
fi
|
||||
valid_asset "$favicon" || favicon=''
|
||||
valid_asset "$logo" || logo=''
|
||||
}
|
||||
|
||||
status() {
|
||||
json_init
|
||||
json_add_int result "$1"
|
||||
json_add_string favicon "$favicon"
|
||||
json_add_string logo "$logo"
|
||||
json_dump
|
||||
}
|
||||
|
||||
# Check the PNG header, bounded dimensions, IDAT presence and complete IEND.
|
||||
# Images are served as PNG only, never as user-supplied filenames or SVG/HTML.
|
||||
validate_png() {
|
||||
local size header ending
|
||||
size="$(wc -c < "$1")"
|
||||
[ "$size" -ge 67 ] && [ "$size" -le 1048576 ] || return 1
|
||||
# OpenWrt enables hexdump, but od is absent or lacks -A/-t/-N.
|
||||
header="$(hexdump -v -n 29 -e '1/1 "%u "' "$1")" || return 1
|
||||
set -- $header
|
||||
[ "$#" -eq 29 ] || return 1
|
||||
[ "$1 $2 $3 $4 $5 $6 $7 $8" = '137 80 78 71 13 10 26 10' ] || return 1
|
||||
shift 8
|
||||
[ "$1 $2 $3 $4 $5 $6 $7 $8" = '0 0 0 13 73 72 68 82' ] || return 1
|
||||
shift 8
|
||||
width=$(( $1 * 16777216 + $2 * 65536 + $3 * 256 + $4 ))
|
||||
height=$(( $5 * 16777216 + $6 * 65536 + $7 * 256 + $8 ))
|
||||
[ "$width" -ge 16 ] && [ "$height" -ge 16 ] &&
|
||||
[ "$width" -le 1024 ] && [ "$height" -le 1024 ] || return 1
|
||||
[ "$target" = logo ] || [ "$width" -eq "$height" ] || return 1
|
||||
shift 8
|
||||
case "$1:$2" in 1:0|2:0|4:0|8:0|16:0|8:2|16:2|1:3|2:3|4:3|8:3|8:4|16:4|8:6|16:6) ;; *) return 1 ;; esac
|
||||
[ "$3 $4" = '0 0' ] && [ "$5" -le 1 ] || return 1
|
||||
ending="$(tail -c 12 "$work/image.png" | hexdump -v -e '1/1 "%02x"')" || return 1
|
||||
[ "$ending" = '0000000049454e44ae426082' ] && LC_ALL=C grep -q 'IDAT' "$work/image.png"
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
[ -z "$work" ] || rm -rf "$work"
|
||||
rmdir "$lock_dir" 2>/dev/null
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
list)
|
||||
printf '%s\n' '{"get":{},"set":{"target":"","token":""},"reset":{"target":""}}'
|
||||
;;
|
||||
call)
|
||||
method="$2"
|
||||
case "$method" in
|
||||
get) read_state; status 0; exit 0 ;;
|
||||
set|reset) ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
read -r input
|
||||
json_load "$input" || { status 2; exit 0; }
|
||||
json_get_var target target
|
||||
json_get_var token token
|
||||
case "$target" in favicon|logo|both) ;; *) status 2; exit 0 ;; esac
|
||||
if [ "$method" = set ]; then
|
||||
printf '%s\n' "$token" | grep -Eq '^[0-9a-f]{32}$' || { status 2; exit 0; }
|
||||
upload="${upload_prefix}${token}.png"
|
||||
[ -f "$upload" ] && [ ! -L "$upload" ] || { status 2; exit 0; }
|
||||
fi
|
||||
mkdir "$lock_dir" 2>/dev/null || { status 3; exit 0; }
|
||||
work=''
|
||||
trap cleanup EXIT
|
||||
trap 'exit 1' HUP INT TERM
|
||||
umask 077
|
||||
[ ! -L "$branding_dir" ] && mkdir -p "$branding_dir" && chmod 0755 "$branding_dir" || { status 1; exit 0; }
|
||||
work="$(mktemp -d "$branding_dir/.upload.XXXXXX")" || { status 1; exit 0; }
|
||||
read_state
|
||||
old_favicon="$favicon"
|
||||
old_logo="$logo"
|
||||
if [ "$method" = set ]; then
|
||||
mv "$upload" "$work/image.png" || { status 1; exit 0; }
|
||||
validate_png "$work/image.png" || { status 2; exit 0; }
|
||||
hash="$(sha256sum "$work/image.png")"
|
||||
hash="${hash%% *}"
|
||||
printf '%s\n' "$hash" | grep -Eq '^[0-9a-f]{64}$' || { status 1; exit 0; }
|
||||
asset="image-$hash.png"
|
||||
manifest="image-$hash.webmanifest"
|
||||
valid_destination "$branding_dir/$asset" && valid_destination "$branding_dir/$manifest" || { status 1; exit 0; }
|
||||
printf '{"name":"OpenWrt","display":"standalone","icons":[{"src":"%s","sizes":"%sx%s","type":"image/png"}]}\n' "$asset" "$width" "$height" > "$work/manifest"
|
||||
chmod 0644 "$work/image.png" "$work/manifest" &&
|
||||
mv -f "$work/image.png" "$branding_dir/$asset" &&
|
||||
mv -f "$work/manifest" "$branding_dir/$manifest" || { status 1; exit 0; }
|
||||
else
|
||||
asset=''
|
||||
fi
|
||||
case "$target" in favicon) favicon="$asset" ;; logo) logo="$asset" ;; both) favicon="$asset"; logo="$asset" ;; esac
|
||||
json_init
|
||||
json_add_string favicon "$favicon"
|
||||
json_add_string logo "$logo"
|
||||
json_dump > "$work/current.json"
|
||||
valid_destination "$branding_dir/current.json" && chmod 0644 "$work/current.json" &&
|
||||
mv -f "$work/current.json" "$branding_dir/current.json" || { status 1; exit 0; }
|
||||
# Keep the active images and one previous generation for pages already open.
|
||||
for file in "$branding_dir"/image-*.png; do
|
||||
name="${file##*/}"
|
||||
case "$name" in "$favicon"|"$logo"|"$old_favicon"|"$old_logo") continue ;; esac
|
||||
rm -f "$file" "${file%.png}.webmanifest"
|
||||
done
|
||||
status 0
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1 @@
|
||||
Argon settings are provided by luci-theme-argon.
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"admin/system/argon-config": {
|
||||
"title": "Argon Config",
|
||||
"order": 90,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "argon-config"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-argon-config" ],
|
||||
"uci": { "argon": true }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"luci-app-argon-config": {
|
||||
"description": "Grant UCI access for luci-app-argon-config",
|
||||
"read": {
|
||||
"file": {
|
||||
"/www/luci-static/argon/background/*": [ "list" ]
|
||||
},
|
||||
"ubus": {
|
||||
"luci.argon": [ "avail" ],
|
||||
"luci.argon_appearance": [ "get" ],
|
||||
"luci.argon_branding": [ "get" ]
|
||||
},
|
||||
"uci": [ "argon" ]
|
||||
},
|
||||
"write": {
|
||||
"file": {
|
||||
"/tmp/argon_background.tmp": [ "write" ],
|
||||
"/tmp/argon_branding_*.png": [ "write" ]
|
||||
},
|
||||
"ubus": {
|
||||
"luci.argon": [ "remove", "rename" ],
|
||||
"luci.argon_appearance": [ "set" ],
|
||||
"luci.argon_branding": [ "set", "reset" ]
|
||||
},
|
||||
"uci": [ "argon" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,9 @@
|
||||
"luci-theme-argon": {
|
||||
"description": "Grant UCI access for luci-theme-argon",
|
||||
"read": {
|
||||
"ubus": {
|
||||
"luci.argon_appearance": [ "get" ]
|
||||
},
|
||||
"uci": [ "argon" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
'use strict';
|
||||
|
||||
import { pow } from 'math';
|
||||
|
||||
// The linear-sRGB/Oklab transforms below are ported from Culori 4.0.2.
|
||||
// https://github.com/Evercoder/culori/tree/v4.0.2/src/oklab
|
||||
// MIT License
|
||||
// Copyright (c) 2018 Dan Burzo
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
export function normalize_hex(value) {
|
||||
if (type(value) != 'string' || !match(value, /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/))
|
||||
return null;
|
||||
if (length(value) == 4)
|
||||
value = '#' + substr(value, 1, 1) + substr(value, 1, 1) +
|
||||
substr(value, 2, 1) + substr(value, 2, 1) + substr(value, 3, 1) + substr(value, 3, 1);
|
||||
return lc(value);
|
||||
};
|
||||
|
||||
function linear(value) {
|
||||
return value <= 0.04045 ? value / 12.92 : pow((value + 0.055) / 1.055, 2.4);
|
||||
}
|
||||
|
||||
function rgb(hex) {
|
||||
return map([1, 3, 5], offset => int(substr(hex, offset, 2), 16) / 255.0);
|
||||
}
|
||||
|
||||
function luminance(hex) {
|
||||
let v = map(rgb(hex), linear);
|
||||
return 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2];
|
||||
}
|
||||
|
||||
export function contrast(a, b) {
|
||||
let x = luminance(a), y = luminance(b);
|
||||
return x > y ? (x + 0.05) / (y + 0.05) : (y + 0.05) / (x + 0.05);
|
||||
};
|
||||
|
||||
function oklab(hex) {
|
||||
let v = map(rgb(hex), linear), r = v[0], g = v[1], b = v[2];
|
||||
let l = pow(0.412221469470763 * r + 0.5363325372617348 * g + 0.0514459932675022 * b, 1.0 / 3);
|
||||
let m = pow(0.2119034958178252 * r + 0.6806995506452344 * g + 0.1073969535369406 * b, 1.0 / 3);
|
||||
let s = pow(0.0883024591900564 * r + 0.2817188391361215 * g + 0.6299787016738222 * b, 1.0 / 3);
|
||||
let a = 1.9779985324311684 * l - 2.4285922420485799 * m + 0.450593709617411 * s;
|
||||
let b1 = 0.0259040424655478 * l + 0.7827717124575296 * m - 0.8086757549230774 * s;
|
||||
// Achromatic seeds must not acquire a hue from floating-point noise.
|
||||
if (a * a + b1 * b1 < 0.000000000001)
|
||||
a = b1 = 0;
|
||||
return [0.210454268309314 * l + 0.7936177747023054 * m - 0.0040720430116193 * s, a, b1];
|
||||
}
|
||||
|
||||
function linear_rgb(l, a, b) {
|
||||
let x = pow(l + 0.3963377773761749 * a + 0.2158037573099136 * b, 3);
|
||||
let y = pow(l - 0.1055613458156586 * a - 0.0638541728258133 * b, 3);
|
||||
let z = pow(l - 0.0894841775298119 * a - 1.2914855480194092 * b, 3);
|
||||
return [4.0767416360759574 * x - 3.3077115392580616 * y + 0.2309699031821044 * z,
|
||||
-1.2684379732850317 * x + 2.6097573492876887 * y - 0.3413193760026573 * z,
|
||||
-0.0041960761386756 * x - 0.7034186179359362 * y + 1.7076146940746117 * z];
|
||||
}
|
||||
|
||||
function in_gamut(v) {
|
||||
return v[0] >= 0 && v[0] <= 1 && v[1] >= 0 && v[1] <= 1 && v[2] >= 0 && v[2] <= 1;
|
||||
}
|
||||
|
||||
function encode(v) {
|
||||
let x = v <= 0.0031308 ? v * 12.92 : 1.055 * pow(v, 1.0 / 2.4) - 0.055;
|
||||
return int((x < 0 ? 0 : x > 1 ? 1 : x) * 255 + 0.5);
|
||||
}
|
||||
|
||||
function tone(seed, lightness, scale) {
|
||||
let lo = 0, hi = scale;
|
||||
let v = linear_rgb(lightness, seed[1] * hi, seed[2] * hi);
|
||||
// Preserve OKLCH hue/lightness; reduce chroma rather than clipping channels.
|
||||
if (!in_gamut(v)) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
let mid = (lo + hi) / 2;
|
||||
if (in_gamut(linear_rgb(lightness, seed[1] * mid, seed[2] * mid)))
|
||||
lo = mid;
|
||||
else
|
||||
hi = mid;
|
||||
}
|
||||
v = linear_rgb(lightness, seed[1] * lo, seed[2] * lo);
|
||||
}
|
||||
return sprintf('#%02x%02x%02x', encode(v[0]), encode(v[1]), encode(v[2]));
|
||||
}
|
||||
|
||||
export function dark_palette(color, custom) {
|
||||
color = normalize_hex(color) ?? '#5e72e4';
|
||||
let seed = oklab(color);
|
||||
let fill = color;
|
||||
if (!custom) {
|
||||
for (let l = 0.57; l >= 0.3; l -= 0.01) {
|
||||
fill = tone(seed, l, 0.8);
|
||||
if (contrast('#ffffff', fill) >= 4.6)
|
||||
break;
|
||||
}
|
||||
}
|
||||
let link = tone(seed, 0.82, 0.65);
|
||||
// Field edges keep more chroma than the pale keyboard focus ring.
|
||||
let control_focus = tone(seed, 0.69, 0.95);
|
||||
return {
|
||||
primary: fill,
|
||||
on_primary: contrast('#ffffff', fill) >= contrast('#000000', fill) ? '#ffffff' : '#000000',
|
||||
link: link,
|
||||
focus: tone(seed, 0.90, 0.4),
|
||||
control_focus: control_focus,
|
||||
progress: tone(seed, 0.74, 0.8),
|
||||
control_ring: sprintf('rgba(%d, %d, %d, .18)', int(substr(control_focus, 1, 2), 16), int(substr(control_focus, 3, 2), 16), int(substr(control_focus, 5, 2), 16)),
|
||||
selected: tone(seed, 0.31, 0.35),
|
||||
hover: tone(seed, 0.37, 0.4),
|
||||
shadow: sprintf('rgba(%d, %d, %d, .1)', int(substr(link, 1, 2), 16), int(substr(link, 3, 2), 16), int(substr(link, 5, 2), 16)),
|
||||
ring: sprintf('rgba(%d, %d, %d, .28)', int(substr(link, 1, 2), 16), int(substr(link, 3, 2), 16), int(substr(link, 5, 2), 16))
|
||||
};
|
||||
};
|
||||
|
||||
function valid_number(value, fallback, maximum) {
|
||||
return type(value) == 'string' && match(value, /^(0|[1-9][0-9]*)(\.[0-9]+)?$/) && +value <= maximum ? value : fallback;
|
||||
}
|
||||
|
||||
export function appearance_modes(settings) {
|
||||
let color = settings.dark_primary_mode;
|
||||
if (color != 'auto' && color != 'custom')
|
||||
color = normalize_hex(settings.dark_primary) ? 'custom' : 'auto';
|
||||
let glass = settings.dark_glass_mode;
|
||||
if (glass != 'inherit' && glass != 'custom') {
|
||||
let blur = valid_number(settings.blur, '10', 100);
|
||||
let opacity = valid_number(settings.transparency, '0.5', 1);
|
||||
glass = +valid_number(settings.blur_dark, blur, 100) != +blur ||
|
||||
+valid_number(settings.transparency_dark, opacity, 1) != +opacity ? 'custom' : 'inherit';
|
||||
}
|
||||
return { color, glass };
|
||||
};
|
||||
Reference in new issue
Block a user