feat: search field of the history panel stands out (recess, focus border, magnifier)
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
44521e478d
commit
02d579c8b8
4 files changed
+87
No files matched your search
@@ -568,3 +568,44 @@ export function isManualResize({ reportedPx, orderedPx, tolerance = 3 }) {
|
||||
if (!Number.isFinite(reportedPx) || !Number.isFinite(orderedPx)) return false;
|
||||
return Math.abs(reportedPx - orderedPx) > tolerance;
|
||||
}
|
||||
|
||||
// --- colors from the theme -----------------------------------------------------
|
||||
|
||||
/**
|
||||
* How light a color is (0 dark .. 1 light), from `#rgb`, `#rrggbb` or
|
||||
* `#rrggbbaa`; nothing for what is not such a color.
|
||||
*
|
||||
* @param {unknown} color
|
||||
* @returns {number|null}
|
||||
*/
|
||||
export function luminance(color) {
|
||||
if (typeof color !== "string") return null;
|
||||
let hex = color.trim();
|
||||
if (!/^#([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(hex)) return null;
|
||||
hex = hex.slice(1);
|
||||
if (hex.length === 3) hex = hex.replace(/./g, "$&$&");
|
||||
const channel = (at) => parseInt(hex.slice(at, at + 2), 16) / 255;
|
||||
return 0.2126 * channel(0) + 0.7152 * channel(2) + 0.0722 * channel(4);
|
||||
}
|
||||
|
||||
/**
|
||||
* The background of an input field set into a panel: the darkest color the
|
||||
* theme names among the usual surfaces, so the field reads as a recess in the
|
||||
* panel whatever the theme. A theme with none to offer leaves the panel's own.
|
||||
*
|
||||
* @param {Record<string,string>} theme - `theme()`
|
||||
* @param {string} panelBackground - the background of the panel
|
||||
* @returns {string}
|
||||
*/
|
||||
export function fieldBackground(theme, panelBackground) {
|
||||
let best = null;
|
||||
let bestLight = Infinity;
|
||||
for (const key of ["background", "canvas", "pane", "surface", "chrome"]) {
|
||||
const light = luminance(theme?.[key]);
|
||||
if (light !== null && light < bestLight) {
|
||||
best = theme[key];
|
||||
bestLight = light;
|
||||
}
|
||||
}
|
||||
return best ?? panelBackground;
|
||||
}
|
||||
Reference in new issue
Block a user