From 80ebe9ae8ee4d06377f637bd2730f87df759f030 Mon Sep 17 00:00:00 2001 From: Sarahtonin Date: Mon, 31 Aug 2026 17:07:49 +0200 Subject: [PATCH] Fixed borders around coloured names, and the default colour picker for users. --- Pages/Profile.php | 2 +- Scripts/Garden/Profile.js | 4 +- Scripts/Garden/Users.js | 145 +++++++++++++++++++++++++++++--------- 3 files changed, 115 insertions(+), 36 deletions(-) diff --git a/Pages/Profile.php b/Pages/Profile.php index ac4050c..0b12c5d 100644 --- a/Pages/Profile.php +++ b/Pages/Profile.php @@ -79,7 +79,7 @@ $SubNavbarCurrent = "Player"; id="ProfileColourInput" class="ProfileColourInput" type="color" - value="#cdd6f4" + value="#000000" > { + const Value = + parseInt( + Channel, + 16 + ) / 255; + + return Value <= 0.04045 + ? Value / 12.92 + : Math.pow( + (Value + 0.055) / + 1.055, + 2.4 + ); + } + ); + + return ( + 0.2126 * Channels[0] + + 0.7152 * Channels[1] + + 0.0722 * Channels[2] + ); +} + + +function GetContrastRatio( + FirstLuminance, + SecondLuminance +) { + const Lighter = Math.max( + FirstLuminance, + SecondLuminance + ); + + const Darker = Math.min( + FirstLuminance, + SecondLuminance + ); + + return ( + Lighter + 0.05 + ) / ( + Darker + 0.05 + ); +} + + function GetPlayerColourOutline( Colour ) { - const Red = parseInt( - Colour.slice(1, 3), - 16 + const ColourLuminance = + GetRelativeLuminance( + Colour + ); + + const LightLuminance = + GetRelativeLuminance( + "#cdd6f4" + ); + + const DarkLuminance = + GetRelativeLuminance( + "#11111b" + ); + + const LightContrast = + GetContrastRatio( + ColourLuminance, + LightLuminance + ); + + const DarkContrast = + GetContrastRatio( + ColourLuminance, + DarkLuminance + ); + + return DarkContrast >= + LightContrast + ? "var(--Crust)" + : "var(--Text)"; +} + + +function GetPlayerColourShadow( + Outline +) { + const Shadows = []; + + for (let Y = -2; Y <= 2; Y++) { + for (let X = -2; X <= 2; X++) { + if (X === 0 && Y === 0) { + continue; + } + + Shadows.push( + `${X}px ${Y}px 0 ${Outline}` + ); + } + } + + return Shadows.join( + ", " ); - - const Green = parseInt( - Colour.slice(3, 5), - 16 - ); - - const Blue = parseInt( - Colour.slice(5, 7), - 16 - ); - - const Brightness = - ( - Red * 299 + - Green * 587 + - Blue * 114 - ) / 1000; - - return Brightness < 150 - ? "var(--Text)" - : "var(--Crust)"; } @@ -73,14 +157,9 @@ function ApplyPlayerColour( Colour; Element.style.textShadow = - `-1px -1px 0 ${Outline}, ` + - `0 -1px 0 ${Outline}, ` + - `1px -1px 0 ${Outline}, ` + - `-1px 0 0 ${Outline}, ` + - `1px 0 0 ${Outline}, ` + - `-1px 1px 0 ${Outline}, ` + - `0 1px 0 ${Outline}, ` + - `1px 1px 0 ${Outline}`; + GetPlayerColourShadow( + Outline + ); }