Skip to content

Commit 9e8e965

Browse files
KTibowclaude
andcommitted
default --source to the OS accent, and drop the all-literal case
A stylesheet where every role is literal is a static theme, which the theme page already emits -- so the branch that dropped --u and --source for it was carrying a case this file should not serve. Per-role literals stay: shadow, scrim and the fixed 2021 error hue are a third of all roles and cost nothing to emit exactly. --source now defaults to AccentColor rather than a hardcoded purple, so an import with no configuration already themes to the user. Verified in both engines that it resolves as a relative-colour origin through a custom property with maths on the channels -- CSS.supports() cannot answer that, since a value containing var() is always accepted at parse time and only fails at computed-value time. AccentColor also predates relative colour syntax in every engine, so anything that can parse this file has it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 1b8729a commit 9e8e965

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

scripts/generate-livetheme.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,10 @@ const hoistPass = (decls: string[]) => {
648648

649649
// --- emit --------------------------------------------------------------------
650650
const usedKeys = new Set(entries.filter((e) => !e.literal).map((e) => e.key));
651-
const allLiteral = usedKeys.size === 0;
652651
const CE = hoistable("max(hypot(a,b),.00001)");
653652
const pd: string[] = [];
654-
if (!allLiteral)
655-
// --u carries: L = source lightness, (a,b) = unit hue vector, alpha = source chroma
656-
pd.push(`--u:oklab(from var(--source) l calc(a/${CE}) calc(b/${CE}) / calc(${CE}))`);
653+
// --u carries: L = source lightness, (a,b) = unit hue vector, alpha = source chroma
654+
pd.push(`--u:oklab(from var(--source) l calc(a/${CE}) calc(b/${CE}) / calc(${CE}))`);
657655
for (const [key, palette] of palInfo) {
658656
if (!usedKeys.has(key)) continue;
659657
let base = "var(--u)";
@@ -709,21 +707,23 @@ const rd = Object.entries(byRole).map(([rn, m]: [string, any]) => {
709707
return `--m3c-${rn}:${l === d ? l : `light-dark(${l},${d})`}`;
710708
});
711709

712-
// Standalone on purpose: one @import and a --source is the whole API. The defaults
713-
// on :root make it render before anything is overridden, and .m3-theme lets a subtree
714-
// carry its own --source -- the custom properties are re-evaluated per element, so a
715-
// nested theme just works.
710+
// Standalone on purpose: one @import is the whole API. --source defaults to the OS
711+
// accent so an unconfigured import already themes to the user, and .m3-theme lets a
712+
// subtree carry its own --source -- the custom properties are re-evaluated per
713+
// element, so a nested theme just works.
716714
const css =
717715
`/* ${variant} -- Material colour roles computed live from --source, in CSS.\n` +
718716
` * Generated by scripts/generate-livetheme.ts; do not edit.\n` +
719717
` *\n` +
720718
` * @import "m3-svelte/etc/livetheme/${variant}.css";\n` +
719+
` *\n` +
720+
` * --source defaults to the OS accent colour. To pin one instead:\n` +
721721
` * :root { --source: #0b57d0; }\n` +
722722
` *\n` +
723-
` * Any subtree can override it instead:\n` +
723+
` * Any subtree can override it:\n` +
724724
` * <div class="m3-theme" style="--source: #b33b15">\n` +
725725
` */\n` +
726-
`:root{${allLiteral ? "" : "--source:#6750a4;"}color-scheme:light dark}\n` +
726+
`:root{--source:AccentColor;color-scheme:light dark}\n` +
727727
`:root,.m3-theme{\n${hoistPass([...pd, ...rd])}\n}\n`;
728728
// Alongside the library's other stylesheets, so svelte-package ships it and it is
729729
// imported the same way they are. scripts/generate-tailwind.ts writes into the same

0 commit comments

Comments
 (0)