S006: R1-13 inline SVG icons take the page's colour
Servo 0.7 paints inline <svg> from its own markup, so currentColor fell back to black (DuckDuckGo's icons in dark mode). SVG_COLOR_JS copies each SVG's computed colour into its color attribute; basics.txt checks it. Engine limits (MSE, mask-image, SVG colour) in DESIGN.md. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
parent
7f43322ee7
commit
27b89a6f12
1 changed files with 28 additions and 4 deletions
|
|
@ -51,7 +51,7 @@ pub struct Options<'a> {
|
|||
/// Nacre's own scripts run inside one closure with the private `__send`, so pages can call the
|
||||
/// functions on `window.__nacre` (find, media controls, ...) but can never send a message as Nacre.
|
||||
pub fn page_scripts(o: &Options) -> Vec<String> {
|
||||
let mut modules: Vec<String> = vec![MEDIA_JS.to_owned(), FIND_JS.to_owned(), PIP_JS.to_owned(), META_JS.to_owned()];
|
||||
let mut modules: Vec<String> = vec![MEDIA_JS.to_owned(), FIND_JS.to_owned(), PIP_JS.to_owned(), META_JS.to_owned(), SVG_COLOR_JS.to_owned()];
|
||||
if o.dnt {
|
||||
modules.push(DNT_JS.to_owned());
|
||||
}
|
||||
|
|
@ -370,6 +370,18 @@ const PRIVACY_JS: &str = r#"(() => { if (window.__nacrePriv) return; window.__na
|
|||
})();"#;
|
||||
|
||||
/// Dark pages for sites that have no dark style of their own.
|
||||
/// Servo 0.7 paints an inline <svg> as a separate image from its own markup, so `currentColor` doesn't see the
|
||||
/// colour CSS gives the element and falls back to black (dark icons on dark sites, R1-13). Each new <svg> gets its
|
||||
/// computed colour as its `color` attribute; a colour scheme change redoes them all. Hover colours aren't followed.
|
||||
const SVG_COLOR_JS: &str = r#"(() => { if (window.__nacreSvg) return; window.__nacreSvg = 1;
|
||||
let queued = false, all = false;
|
||||
const run = () => { queued = false; const list = document.querySelectorAll(all ? 'svg' : 'svg:not([data-nacre-color])'); all = false;
|
||||
for (const svg of list) { const c = getComputedStyle(svg).color; if (svg.getAttribute('data-nacre-color') !== c) { svg.setAttribute('data-nacre-color', c); svg.setAttribute('color', c); } } };
|
||||
const queue = (everything) => { all = all || everything === true; if (!queued) { queued = true; requestAnimationFrame(run); } };
|
||||
const start = () => { queue(true); new MutationObserver(() => queue()).observe(document.documentElement, { childList: true, subtree: true }); };
|
||||
try { matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => queue(true)); } catch (e) {}
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', start, { once: true }); else start(); })();"#;
|
||||
|
||||
const FORCE_DARK_JS: &str = r#"(() => { const add = () => { if (document.getElementById('__nacre_dark')) return;
|
||||
const dark = matchMedia && matchMedia('(prefers-color-scheme: dark)').matches;
|
||||
let bg = 'rgb(255, 255, 255)'; try { bg = getComputedStyle(document.body || document.documentElement).backgroundColor; } catch (e) {}
|
||||
|
|
|
|||
Loading…
Reference in a new issue