Reported by Juest: fix dark flip/roll buttons in yomirc
The dice feature's buttons styled themselves with var(--panel) and var(--green-soft), neither of which exists: --panel was never a token and --green-soft got renamed to --accent-soft. So the buttons had no fill and the bare <button> picked up the OS dark UA chrome (the sandbox iframe declared color-scheme: light dark, following the visitor's OS, not the app). On a dark desktop the flip/roll buttons came out dark in a light theme. Use the real, mirrored tokens (--accent-soft fill, --accent hover) so the buttons always carry the theme's own accent, and pin the sandbox iframe's color-scheme to the app theme (from its --bg) so no plugin's native controls track the OS instead of the skin. Drop the dead --panel from the mirror list.
This commit is contained in:
parent
cd00b1d94c
commit
f999661b68
3 changed files with 22 additions and 4 deletions
|
|
@ -26,10 +26,28 @@
|
|||
var listeners = {}; // event name -> [fn]
|
||||
var pending = new Map(), rpcId = 0; // in-flight RPCs
|
||||
|
||||
// Is this background colour a dark one? Rough luminance on a #rgb/#rrggbb or
|
||||
// rgb(...) string; anything unparseable counts as light.
|
||||
function isDark(c) {
|
||||
if (!c) return false;
|
||||
var m = String(c).trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i), r, g, b;
|
||||
if (m) {
|
||||
var h = m[1]; if (h.length === 3) h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
|
||||
r = parseInt(h.slice(0, 2), 16); g = parseInt(h.slice(2, 4), 16); b = parseInt(h.slice(4, 6), 16);
|
||||
} else {
|
||||
var n = String(c).match(/(\d+)\D+(\d+)\D+(\d+)/); if (!n) return false;
|
||||
r = +n[1]; g = +n[2]; b = +n[3];
|
||||
}
|
||||
return (0.2126 * r + 0.7152 * g + 0.0722 * b) < 128;
|
||||
}
|
||||
|
||||
// Mirror the app's theme CSS vars onto our root so plugin UI can use var(--accent) etc.
|
||||
// Also pin color-scheme to the APP theme (from its background), not the visitor's OS,
|
||||
// so native controls don't render dark chrome under a light theme or vice-versa.
|
||||
function applyTheme(vars) {
|
||||
if (!vars) return;
|
||||
for (var k in vars) { try { document.documentElement.style.setProperty(k, vars[k]); } catch (e) {} }
|
||||
if (vars['--bg']) document.documentElement.style.colorScheme = isDark(vars['--bg']) ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function rpc(method) {
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ Orbit.plugin('dice', function (orbit, log) {
|
|||
b.style.cssText =
|
||||
'font:600 13px system-ui,sans-serif;cursor:pointer;line-height:1;' +
|
||||
'padding:.3rem .5rem;border-radius:9px;white-space:nowrap;' +
|
||||
'border:1px solid var(--border,#8884);background:var(--panel,transparent);color:var(--ink,inherit)';
|
||||
b.onmouseenter = function () { b.style.background = 'var(--green-soft,rgba(127,127,127,.14))'; };
|
||||
b.onmouseleave = function () { b.style.background = 'var(--panel,transparent)'; };
|
||||
'border:1px solid var(--border,#8884);background:var(--accent-soft,rgba(127,127,127,.14));color:var(--ink,inherit)';
|
||||
b.onmouseenter = function () { b.style.background = 'var(--accent,#3a7)'; b.style.color = 'var(--bg,#fff)'; };
|
||||
b.onmouseleave = function () { b.style.background = 'var(--accent-soft,rgba(127,127,127,.14))'; b.style.color = 'var(--ink,inherit)'; };
|
||||
return b;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ export interface ThemeMsg { type: 'theme'; theme: Record<string, string>; }
|
|||
export interface RpcReplyMsg { type: 'rpc:reply'; id: number; result?: unknown; error?: string; }
|
||||
|
||||
// App CSS variables mirrored into the sandbox so plugins can `var(--accent)` etc.
|
||||
export const THEME_VARS = ['--bg', '--ink', '--accent', '--muted', '--border', '--panel', '--accent-soft'] as const;
|
||||
export const THEME_VARS = ['--bg', '--ink', '--accent', '--muted', '--border', '--accent-soft'] as const;
|
||||
|
||||
// guest -> host
|
||||
export interface RpcMsg { type: 'rpc'; id: number; method: string; args: unknown[]; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue