feat: color a site from its address, and offer a failed web page to the system browser

This commit is contained in:
randogoth 2026-10-11 22:32:44 +03:00
parent 56db479df0
commit 9d9f09ebc7
24 changed files with 597 additions and 25 deletions

View file

@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import '../../mews/document.dart';
import 'site_palette.dart';
/// The client's own presentation, mirroring the palettes of the default
/// stylesheet mews-0.1.css (spec 5.1). Mews clients ignore author CSS and use
@ -23,11 +24,16 @@ class MewsPalette {
final Color preBackground;
}
/// Visited links keep one color across every palette, generated ones
/// included, so the mark of having been somewhere reads the same everywhere.
const visitedLight = Color(0xff5b2a86);
const visitedDark = Color(0xffc9a3f2);
const _plainLight = MewsPalette(
background: Color(0xfffaf8f3),
foreground: Color(0xff1f1f1f),
link: Color(0xff1a4f9c),
visited: Color(0xff5b2a86),
visited: visitedLight,
border: Color(0xffc9c4b8),
preBackground: Color(0xffefece4),
);
@ -36,7 +42,7 @@ const _plainDark = MewsPalette(
background: Color(0xff18191b),
foreground: Color(0xffe3e1dc),
link: Color(0xff8fb8f5),
visited: Color(0xffc9a3f2),
visited: visitedDark,
border: Color(0xff45464a),
preBackground: Color(0xff222326),
);
@ -45,7 +51,7 @@ const _warmLight = MewsPalette(
background: Color(0xfffbf4e8),
foreground: Color(0xff2a2420),
link: Color(0xff8a3d14),
visited: Color(0xff5b2a86),
visited: visitedLight,
border: Color(0xffc9c4b8),
preBackground: Color(0xffefece4),
);
@ -54,7 +60,7 @@ const _warmDark = MewsPalette(
background: Color(0xff1d1916),
foreground: Color(0xffe8dfd3),
link: Color(0xfff0b48a),
visited: Color(0xffc9a3f2),
visited: visitedDark,
border: Color(0xff45464a),
preBackground: Color(0xff222326),
);
@ -63,7 +69,7 @@ const _coolLight = MewsPalette(
background: Color(0xfff3f6fa),
foreground: Color(0xff1c2430),
link: Color(0xff1a4f9c),
visited: Color(0xff5b2a86),
visited: visitedLight,
border: Color(0xffc9c4b8),
preBackground: Color(0xffefece4),
);
@ -72,7 +78,7 @@ const _coolDark = MewsPalette(
background: Color(0xff161a20),
foreground: Color(0xffdde4ee),
link: Color(0xff8fb8f5),
visited: Color(0xffc9a3f2),
visited: visitedDark,
border: Color(0xff45464a),
preBackground: Color(0xff222326),
);
@ -81,7 +87,7 @@ const _greenLight = MewsPalette(
background: Color(0xfff2f6ef),
foreground: Color(0xff1f2a1f),
link: Color(0xff24502a),
visited: Color(0xff5b2a86),
visited: visitedLight,
border: Color(0xffc9c4b8),
preBackground: Color(0xffefece4),
);
@ -90,7 +96,7 @@ const _greenDark = MewsPalette(
background: Color(0xff161b16),
foreground: Color(0xffdbe6d8),
link: Color(0xff9fd39a),
visited: Color(0xffc9a3f2),
visited: visitedDark,
border: Color(0xff45464a),
preBackground: Color(0xff222326),
);
@ -99,7 +105,7 @@ const _monoLight = MewsPalette(
background: Color(0xffe8ebe1),
foreground: Color(0xff1e2219),
link: Color(0xff1e2219),
visited: Color(0xff5b2a86),
visited: visitedLight,
border: Color(0xffc9c4b8),
preBackground: Color(0xffefece4),
);
@ -108,14 +114,27 @@ const _monoDark = MewsPalette(
background: Color(0xff1b1d18),
foreground: Color(0xffc8d0b8),
link: Color(0xffc8d0b8),
visited: Color(0xffc9a3f2),
visited: visitedDark,
border: Color(0xff45464a),
preBackground: Color(0xff222326),
);
/// Resolves the palette: the reader's variant choice overrides the page's own
/// variant unless the choice is "site" (spec 5.3, 8.2).
MewsPalette paletteFor({required MewsVariant pageVariant, required String readerVariant, required bool dark}) {
/// variant unless the choice is "site" (spec 5.3, 8.2). The choice "host"
/// derives the palette from the address instead, and falls back to the plain
/// palette for an address with no host.
MewsPalette paletteFor({
required MewsVariant pageVariant,
required String readerVariant,
required bool dark,
String? url,
}) {
if (readerVariant == 'host' && url != null) {
final derived = sitePalette(url, dark: dark);
if (derived != null) {
return derived;
}
}
final variant = readerVariant == 'site' ? pageVariant : pageVariantFromName(readerVariant);
return switch ((variant, dark)) {
(MewsVariant.warm, false) => _warmLight,