Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(ui): remove getComputedStyle from theming system (#7350)

Seamus0ca2c9663642
diff --git a/apps/web/src/components/app/GlobalHotkeys.tsx b/apps/web/src/components/app/GlobalHotkeys.tsx
index 3ff905d376..37929b9596 100644
--- a/apps/web/src/components/app/GlobalHotkeys.tsx
+++ b/apps/web/src/components/app/GlobalHotkeys.tsx
@@ -59,9 +59,9 @@ import type { ThemeV3 } from '@theme/types/themeTypes';
import {
applySystemTheme,
applyTheme,
- clearThemePreview,
previewTheme,
resolveActiveThemeId,
+ scheduleThemePreviewEnd,
} from '@theme/utils/themeUtils';
import { type Component, onCleanup, Show } from 'solid-js';
import { useSplitLayout } from './split-layout/layout';
@@ -446,7 +446,7 @@ export default function GlobalShortcuts() {
const theme = systemResolvedTheme();
if (theme) previewTheme(theme.id);
},
- onHighlightEnd: clearThemePreview,
+ onHighlightEnd: scheduleThemePreviewEnd,
});
themes().forEach((theme) => {
@@ -464,7 +464,7 @@ export default function GlobalShortcuts() {
runWithInputFocused: true,
displayComponent: () => <ThemeDisplay theme={theme} />,
onHighlight: () => previewTheme(theme.id),
- onHighlightEnd: clearThemePreview,
+ onHighlightEnd: scheduleThemePreviewEnd,
});
});
@@ -490,7 +490,7 @@ export default function GlobalShortcuts() {
runWithInputFocused: true,
displayComponent: () => <ThemeDisplay theme={theme} />,
onHighlight: () => previewTheme(theme.id),
- onHighlightEnd: clearThemePreview,
+ onHighlightEnd: scheduleThemePreviewEnd,
});
});
@@ -516,7 +516,7 @@ export default function GlobalShortcuts() {
runWithInputFocused: true,
displayComponent: () => <ThemeDisplay theme={theme} />,
onHighlight: () => previewTheme(theme.id),
- onHighlightEnd: clearThemePreview,
+ onHighlightEnd: scheduleThemePreviewEnd,
});
});
diff --git a/apps/web/src/components/app/ReactiveFavicon.tsx b/apps/web/src/components/app/ReactiveFavicon.tsx
index bb801a68f8..a573db6645 100644
--- a/apps/web/src/components/app/ReactiveFavicon.tsx
+++ b/apps/web/src/components/app/ReactiveFavicon.tsx
@@ -1,6 +1,6 @@
import { updateFavicon } from '@app/util/favicon';
import { createCrossTabBus } from '@core/cross-tab/cross-tab-bus';
-import { useReactiveColorString } from '@theme/signals/themeReactive';
+import { committedThemeAccent } from '@theme/signals/themeSignals';
import { createEffect, createSignal, onCleanup, onMount } from 'solid-js';
import { match, P } from 'ts-pattern';
import { useGlobalNotificationSource } from './GlobalAppState';
@@ -30,9 +30,6 @@ export function ReactiveFavicon() {
const globalNotifications = useGlobalNotificationSource();
- const accentColor = useReactiveColorString('a0');
- const badgeColor = useReactiveColorString('a0');
-
const postBadgeMessage = (hasBadge: boolean) => {
badgeBus.publish({ hasBadge, sentAt: Date.now() });
};
@@ -70,7 +67,11 @@ export function ReactiveFavicon() {
});
createEffect(() => {
- updateFavicon(accentColor(), badgeColor(), showNotificationBadge());
+ updateFavicon(
+ committedThemeAccent(),
+ committedThemeAccent(),
+ showNotificationBadge()
+ );
});
return null;
diff --git a/apps/web/src/components/ui/components/LogoProgress.tsx b/apps/web/src/components/ui/components/LogoProgress.tsx
index bae3c558b7..bdb59582bc 100644
--- a/apps/web/src/components/ui/components/LogoProgress.tsx
+++ b/apps/web/src/components/ui/components/LogoProgress.tsx
@@ -17,10 +17,10 @@ export function LogoProgress(props: LogoProgressProps) {
class={props.class}
display="block"
>
- <path d={LOGO_PATH} fill="var(--b4)" />
+ <path d={LOGO_PATH} fill="var(--color-edge)" />
<path
d={LOGO_PATH}
- fill="var(--a0)"
+ fill="var(--color-accent)"
style={{
'clip-path': `inset(0 ${clipRight()} 0 0)`,
transition: 'clip-path 0.3s ease',
diff --git a/apps/web/src/components/ui/components/Scroll.tsx b/apps/web/src/components/ui/components/Scroll.tsx
index 640deee4fd..8e0b55e968 100644
--- a/apps/web/src/components/ui/components/Scroll.tsx
+++ b/apps/web/src/components/ui/components/Scroll.tsx
@@ -142,7 +142,7 @@ export function Scroll(props: ScrollProps) {
transform: `translateY(${translateY()}px)`,
transition: 'opacity 150ms ease-in-out',
'border-radius': `${THUMB_WIDTH * 0.5}px`,
- 'background-color': 'var(--c4)',
+ 'background-color': 'var(--color-content-4)',
height: `${thumbHeight()}px`,
opacity: visible() ? 1 : 0,
right: `${THUMB_INSET}px`,
diff --git a/apps/web/src/components/ui/utils/monochromeIcons.ts b/apps/web/src/components/ui/utils/monochromeIcons.ts
index 77faeab60c..1e5b46a1ab 100644
--- a/apps/web/src/components/ui/utils/monochromeIcons.ts
+++ b/apps/web/src/components/ui/utils/monochromeIcons.ts
@@ -7,39 +7,60 @@ export function initMonochromeIcons() {
if (monochromeIcons()) {
document.documentElement.style.setProperty(
'--color-calendar',
- 'var(--c0)'
+ 'var(--color-content-0)'
);
document.documentElement.style.setProperty(
'--color-contact',
- 'var(--c0)'
+ 'var(--color-content-0)'
);
document.documentElement.style.setProperty(
'--color-canvas',
- 'var(--c0)'
+ 'var(--color-content-0)'
);
document.documentElement.style.setProperty(
'--color-folder',
- 'var(--c0)'
+ 'var(--color-content-0)'
);
document.documentElement.style.setProperty(
'--color-image',
- 'var(--c0)'
+ 'var(--color-content-0)'
);
document.documentElement.style.setProperty(
'--color-video',
- 'var(--c0)'
+ 'var(--color-content-0)'
);
document.documentElement.style.setProperty(
'--color-write',
- 'var(--c0)'
- );
- document.documentElement.style.setProperty('--color-code', 'var(--c0)');
- document.documentElement.style.setProperty('--color-chat', 'var(--c0)');
- document.documentElement.style.setProperty('--color-html', 'var(--c0)');
- document.documentElement.style.setProperty('--color-note', 'var(--c0)');
- document.documentElement.style.setProperty('--color-task', 'var(--c0)');
- document.documentElement.style.setProperty('--color-pdf', 'var(--c0)');
- document.documentElement.style.setProperty('--color-rss', 'var(--c0)');
+ 'var(--color-content-0)'
+ );
+ document.documentElement.style.setProperty(
+ '--color-code',
+ 'var(--color-content-0)'
+ );
+ document.documentElement.style.setProperty(
+ '--color-chat',
+ 'var(--color-content-0)'
+ );
+ document.documentElement.style.setProperty(
+ '--color-html',
+ 'var(--color-content-0)'
+ );
+ document.documentElement.style.setProperty(
+ '--color-note',
+ 'var(--color-content-0)'
+ );
+ document.documentElement.style.setProperty(
+ '--color-task',
+ 'var(--color-content-0)'
+ );
+ document.documentElement.style.setProperty(
+ '--color-pdf',
+ 'var(--color-content-0)'
+ );
+ document.documentElement.style.setProperty(
+ '--color-rss',
+ 'var(--color-content-0)'
+ );
} else {
document.documentElement.style.removeProperty('--color-calendar');
document.documentElement.style.removeProperty('--color-contact');
diff --git a/apps/web/src/features/block-agent/ui/PierreDiff.tsx b/apps/web/src/features/block-agent/ui/PierreDiff.tsx
index b67819937c..ff1cc7e9a0 100644
--- a/apps/web/src/features/block-agent/ui/PierreDiff.tsx
+++ b/apps/web/src/features/block-agent/ui/PierreDiff.tsx
@@ -14,7 +14,7 @@
* bounds diff calculation and DOM work, which still run on the main thread.
* - Theme: pierre's built-in `pierre-light`/`pierre-dark` pair (its
* default). Macro flags dark mode via `html[data-theme-light="false"]`
- * (see features/theme/signals/themeReactive.ts), so we watch that
+ * (see features/theme/utils/themeUtils.ts), so we watch that
* attribute and drive `setThemeType('light' | 'dark')` explicitly
* instead of pierre's OS-preference "system" mode.
*/
diff --git a/apps/web/src/features/block-pdf/component/placeables/Signature.tsx b/apps/web/src/features/block-pdf/component/placeables/Signature.tsx
index 9ee0a2c21f..bc37d7eee2 100644
--- a/apps/web/src/features/block-pdf/component/placeables/Signature.tsx
+++ b/apps/web/src/features/block-pdf/component/placeables/Signature.tsx
@@ -13,7 +13,7 @@ import {
onMount,
Show,
} from 'solid-js';
-import { themeReactive } from '../../../theme/signals/themeReactive';
+import { resolvedThemeColors } from '../../../theme/signals/themeSignals';
import { usePdfDocument } from '../../context/pdf-document-context';
import { usePdfViewer } from '../../context/pdf-viewer-context';
import { useDeletePlaceable, useModifyPayload } from '../../store/placeables';
@@ -141,7 +141,10 @@ function SignatureEditor(props: SignatureEditorProps) {
ref={canvasRef}
// SCUFFED THEMING TODO: this filter is janky af, checks if it's a "darkish" or "lightish" theme, we should handle this better
style={{
- filter: themeReactive.b0.l[0]() < 0.5 ? 'invert(1)' : 'none',
+ filter:
+ resolvedThemeColors()['surface-0'].l < 0.5
+ ? 'invert(1)'
+ : 'none',
}}
/>
<div class="flex flex-row w-full justify-center items-center border-t border-edge">
diff --git a/apps/web/src/features/channel/Call/callkit-drawer-theme.ts b/apps/web/src/features/channel/Call/callkit-drawer-theme.ts
index b7f5d9ba9f..a72e930cb3 100644
--- a/apps/web/src/features/channel/Call/callkit-drawer-theme.ts
+++ b/apps/web/src/features/channel/Call/callkit-drawer-theme.ts
@@ -1,9 +1,10 @@
import { ENABLE_CALLKIT } from '@core/constant/featureFlags';
import { isPlatform, isTauri } from '@core/util/platform';
+import { createLazyMemo } from '@solid-primitives/memo';
import { invoke } from '@tauri-apps/api/core';
-import { themeReactive } from '@theme/signals/themeReactive';
+import { resolvedThemeColors } from '@theme/signals/themeSignals';
import Color from 'colorjs.io';
-import { type Accessor, createMemo } from 'solid-js';
+import type { Accessor } from 'solid-js';
export type RgbaColor = {
red: number;
@@ -26,8 +27,12 @@ export type CallKitDrawerTheme = {
};
export function createCallKitDrawerTheme(): Accessor<CallKitDrawerTheme> {
- return createMemo(currentCallKitTheme, undefined, {
- equals: (a, b) => callKitDrawerThemeKey(a) === callKitDrawerThemeKey(b),
+ return createLazyMemo<CallKitDrawerTheme>((previous) => {
+ const next = currentCallKitTheme();
+ return previous &&
+ callKitDrawerThemeKey(previous) === callKitDrawerThemeKey(next)
+ ? previous
+ : next;
});
}
@@ -52,13 +57,14 @@ export async function setNativeCallKitDrawerTheme(
}
function currentCallKitTheme(): CallKitDrawerTheme {
- const b0 = currentThemeToken('b0');
- const c0 = currentThemeToken('c0');
- const b1 = currentThemeToken('b1');
- const b2 = currentThemeToken('b2');
- const b3 = currentThemeToken('b3');
- const b4 = currentThemeToken('b4');
- const c1 = currentThemeToken('c1');
+ const colors = resolvedThemeColors();
+ const b0 = colors['surface-0'];
+ const c0 = colors['content-0'];
+ const b1 = colors['surface-1'];
+ const b2 = colors['surface-2'];
+ const b3 = colors['edge-muted'];
+ const b4 = colors['edge'];
+ const c1 = colors['content-1'];
const message = {
l: (b1.l + b2.l) / 2,
c: (b1.c + b2.c) / 2,
@@ -128,16 +134,6 @@ function currentCallKitTheme(): CallKitDrawerTheme {
};
}
-function currentThemeToken(
- token: 'b0' | 'b1' | 'b2' | 'b3' | 'b4' | 'c0' | 'c1'
-) {
- return {
- l: themeReactive[token].l[0](),
- c: themeReactive[token].c[0](),
- h: themeReactive[token].h[0](),
- };
-}
-
function oklchToRgba(
token: { l: number; c: number; h: number },
fallback: RgbaColor,
diff --git a/apps/web/src/features/channel/Call/use-callkit-theme-sync.ts b/apps/web/src/features/channel/Call/use-callkit-theme-sync.ts
index 70deae0582..4a4c8f7d06 100644
--- a/apps/web/src/features/channel/Call/use-callkit-theme-sync.ts
+++ b/apps/web/src/features/channel/Call/use-callkit-theme-sync.ts
@@ -1,14 +1,26 @@
-import { createEffect } from 'solid-js';
+import { ENABLE_CALLKIT } from '@core/constant/featureFlags';
+import { isPlatform, isTauri } from '@core/util/platform';
+import { createEffect, createMemo } from 'solid-js';
import { setNativeCallKitDrawerTheme } from './callkit-drawer-theme';
import { useNativeCallState } from './native-call-state';
+async function syncDrawerTheme(
+ theme: Parameters<typeof setNativeCallKitDrawerTheme>[0]
+) {
+ try {
+ await setNativeCallKitDrawerTheme(theme);
+ } catch (err) {
+ console.error('[callkit] failed to sync native drawer theme', err);
+ }
+}
+
export function useCallKitThemeSync() {
const nativeCall = useNativeCallState();
+ if (!ENABLE_CALLKIT || !isTauri() || !isPlatform('ios')) return null;
+ const theme = createMemo(nativeCall.drawerTheme);
createEffect(() => {
- setNativeCallKitDrawerTheme(nativeCall.drawerTheme()).catch((err) =>
- console.error('[callkit] failed to sync native drawer theme', err)
- );
+ void syncDrawerTheme(theme());
});
return null;
diff --git a/apps/web/src/features/channel/Participants/ParticipantsListItem.tsx b/apps/web/src/features/channel/Participants/ParticipantsListItem.tsx
index 2e14d9eaba..78255508f2 100644
--- a/apps/web/src/features/channel/Participants/ParticipantsListItem.tsx
+++ b/apps/web/src/features/channel/Participants/ParticipantsListItem.tsx
@@ -31,7 +31,7 @@ export function ParticipantsListItem(props: {
<div
class="flex items-center justify-between gap-2 py-2 px-6 text-sm w-full bg-surface hover:bg-hover"
classList={{ 'border-b': !props.isLast }}
- style={{ 'border-color': 'var(--b3)' }}
+ style={{ 'border-color': 'var(--color-edge-muted)' }}
>
<button
{...navigationHandlers}
diff --git a/apps/web/src/features/email-message/rendering-adapter.ts b/apps/web/src/features/email-message/rendering-adapter.ts
index 34391920f1..d1849fbeab 100644
--- a/apps/web/src/features/email-message/rendering-adapter.ts
+++ b/apps/web/src/features/email-message/rendering-adapter.ts
@@ -1,25 +1,12 @@
import { ENABLE_PROXY_EMAIL_IMAGES } from '@core/constant/featureFlags';
import { SERVER_HOSTS } from '@core/constant/servers';
import { interceptMailtoLinks } from '@core/util/interceptMailtoLinks';
-import { createMemo } from 'solid-js';
-import { themeReactive } from '../theme/signals/themeReactive';
-import { themeUpdate } from '../theme/signals/themeSignals';
import type { EmailRenderingContextValue } from './context/email-rendering-context';
import { fetchImagesViaPlatform, resolveCidImages } from './image-adapter';
+import { createEmailTheme } from './theme';
export function createEmailRenderingContext(): EmailRenderingContextValue {
- const theme = createMemo(() => {
- themeUpdate();
- return {
- inkL: themeReactive.c0.l[0](),
- inkC: themeReactive.c0.c[0](),
- inkH: themeReactive.c0.h[0](),
- panelL: themeReactive.b1.l[0](),
- accentL: themeReactive.a0.l[0](),
- accentC: themeReactive.a0.c[0](),
- accentH: themeReactive.a0.h[0](),
- };
- });
+ const theme = createEmailTheme();
return {
theme,
images: {
diff --git a/apps/web/src/features/email-message/theme.ts b/apps/web/src/features/email-message/theme.ts
new file mode 100644
index 0000000000..9abbf947c2
--- /dev/null
+++ b/apps/web/src/features/email-message/theme.ts
@@ -0,0 +1,34 @@
+import type { ThemeColorParams } from '@macro-inc/email-renderer/browser';
+import { resolvedThemeColors } from '@theme/signals/themeSignals';
+import { createMemo } from 'solid-js';
+
+/** Only recolor email HTML when a color used by its contrast algorithm changes. */
+export function createEmailTheme() {
+ return createMemo<ThemeColorParams, undefined>(
+ () => {
+ const colors = resolvedThemeColors();
+ const ink = colors['content-0'];
+ const accent = colors.accent;
+ return {
+ inkL: ink.l,
+ inkC: ink.c,
+ inkH: ink.h,
+ panelL: colors['surface-1'].l,
+ accentL: accent.l,
+ accentC: accent.c,
+ accentH: accent.h,
+ };
+ },
+ undefined,
+ {
+ equals: (a, b) =>
+ a.inkL === b.inkL &&
+ a.inkC === b.inkC &&
+ a.inkH === b.inkH &&
+ a.panelL === b.panelL &&
+ a.accentL === b.accentL &&
+ a.accentC === b.accentC &&
+ a.accentH === b.accentH,
+ }
+ );
+}
diff --git a/apps/web/src/features/notifications/notification-platform.ts b/apps/web/src/features/notifications/notification-platform.ts
index aedfd0c049..7ab5c67026 100644
--- a/apps/web/src/features/notifications/notification-platform.ts
+++ b/apps/web/src/features/notifications/notification-platform.ts
@@ -1,7 +1,7 @@
import { getFaviconUrl } from '@app/util/favicon';
import type { SplitManager } from '@components/app/split-layout/layoutManager';
import { markdownToPlainText } from '@macro-inc/lexical-core';
-import { themeReactive } from '../theme/signals/themeReactive';
+import { committedThemeAccent } from '../theme/signals/themeSignals';
import type { PlatformNotificationState } from './components/PlatformNotificationProvider';
import { isEntityDiscussionEvent } from './entity-discussion';
import { GITHUB_EVENT_TYPES } from './github-event-types';
@@ -35,11 +35,6 @@ export interface PlatformNotificationData {
const USER_NAME_FALLBACK = 'Someone';
const DOCUMENT_NAME_FALLBACK = 'Something';
-function getAccentColorForIcon(): string {
- const { l, c, h } = themeReactive.a0;
- return `oklch(${l[0]()} ${c[0]()} ${h[0]()}deg)`;
-}
-
/**
* Who the notification reads as being from. Agent notifications have no user
* sender - a bot is not a user - so the bot (or, for a mention, the author)
@@ -74,7 +69,7 @@ export async function toPlatformNotificationData(
resolveUserName: UserNameResolver,
resolveDocumentName: DocumentNameResolver
): Promise<PlatformNotificationData | null> {
- const accentColor = getAccentColorForIcon();
+ const accentColor = committedThemeAccent();
const icon = getFaviconUrl(accentColor);
const metadata = notification.notification_metadata;
diff --git a/apps/web/src/features/notifications/tests/notification-platform.test.ts b/apps/web/src/features/notifications/tests/notification-platform.test.ts
index f6d442253d..455746de32 100644
--- a/apps/web/src/features/notifications/tests/notification-platform.test.ts
+++ b/apps/web/src/features/notifications/tests/notification-platform.test.ts
@@ -12,14 +12,8 @@ vi.mock('@macro-inc/lexical-core', () => ({
markdownToPlainText: (content: string) => content,
}));
-vi.mock('../../theme/signals/themeReactive', () => ({
- themeReactive: {
- a0: {
- l: [() => '0.8'],
- c: [() => '0.1'],
- h: [() => '100'],
- },
- },
+vi.mock('../../theme/signals/themeSignals', () => ({
+ committedThemeAccent: () => 'oklch(0.8 0.1 100deg)',
}));
vi.mock('../notification-navigation', () => ({
diff --git a/apps/web/src/features/settings/Appearance.tsx b/apps/web/src/features/settings/Appearance.tsx
index a3602a89dd..3c18b35a47 100644
--- a/apps/web/src/features/settings/Appearance.tsx
+++ b/apps/web/src/features/settings/Appearance.tsx
@@ -648,8 +648,7 @@ function ActiveThemeRow() {
export function Appearance() {
return (
- // Soften any stray `b4` edge in the theme editor to the muted `b3` tone.
- <div class="h-full" style={{ '--b4l': 'var(--b3l)' }}>
+ <div class="h-full">
<SettingsPage title="Appearance">
<SettingsSection title="Color Theme">
{/* Establish a container so the rows can stack (label/description over
diff --git a/apps/web/src/features/settings/Shortcuts.tsx b/apps/web/src/features/settings/Shortcuts.tsx
index e0871fbab2..56ac9c049a 100644
--- a/apps/web/src/features/settings/Shortcuts.tsx
+++ b/apps/web/src/features/settings/Shortcuts.tsx
@@ -822,11 +822,12 @@ const KEYS: KeyDef[] = [
];
function KeyRect(props: { def: KeyDef; active: boolean }) {
- const stroke = () => (props.active ? 'var(--a0)' : 'var(--b4)');
+ const stroke = () =>
+ props.active ? 'var(--color-accent)' : 'var(--color-edge)';
const fill = () =>
props.active
- ? 'oklch(from var(--a0) l c h / 0.1)'
- : 'oklch(from var(--b2) l c h / 0.1)';
+ ? 'oklch(from var(--color-accent) l c h / 0.1)'
+ : 'oklch(from var(--color-surface-2) l c h / 0.1)';
return (
<>
diff --git a/apps/web/src/features/setup/Module.tsx b/apps/web/src/features/setup/Module.tsx
index 6c96f1f2e8..72bb2e9569 100644
--- a/apps/web/src/features/setup/Module.tsx
+++ b/apps/web/src/features/setup/Module.tsx
@@ -1,4 +1,3 @@
-import { useReactiveColorString } from '@theme/signals/themeReactive';
import {
createEffect,
createUniqueId,
@@ -347,8 +346,6 @@ export function Module(props: {
state?: ModuleState;
class?: string;
}) {
- const accentColor = useReactiveColorString('a0');
- const inkColor = useReactiveColorString('c0');
let root: SVGGElement | undefined;
let logoGroup: SVGGElement | undefined;
let ventsGroup: SVGGElement | undefined;
@@ -408,7 +405,7 @@ export function Module(props: {
if (!root || prefersReducedMotion()) return;
for (const animation of clickAnimations) animation.cancel();
clickAnimations = [];
- const accent = accentColor();
+ const accent = 'var(--color-accent)';
const dur = { duration: ACCELERATION.durationMs } as const;
const add = {
duration: ACCELERATION.durationMs,
@@ -436,7 +433,8 @@ export function Module(props: {
)) {
// Flash from the state-specific resting stroke so linked-module vents
// don't jump from accent back to ink.
- const resting = props.state === 'linked' ? accentColor() : inkColor();
+ const resting =
+ props.state === 'linked' ? 'var(--color-accent)' : 'var(--color-ink)';
clickAnimations.push(
vent.animate(
[
diff --git a/apps/web/src/features/setup/SetupGraphic.tsx b/apps/web/src/features/setup/SetupGraphic.tsx
index f99035104b..80ea56a111 100644
--- a/apps/web/src/features/setup/SetupGraphic.tsx
+++ b/apps/web/src/features/setup/SetupGraphic.tsx
@@ -1,4 +1,3 @@
-import { useReactiveColorString } from '@theme/signals/themeReactive';
import { createEffect, For, on, onCleanup, onMount, Show } from 'solid-js';
import { Module, type ModuleLogo, type ModuleState } from './Module';
import { MODULE_LOGOS } from './moduleLogos';
@@ -280,8 +279,6 @@ export function SetupGraphic(props: {
* module's `linked` state. */
poweredUp?: boolean;
}) {
- const accentColor = useReactiveColorString('a0');
- const inkColor = useReactiveColorString('c0');
const modules = () => props.modules ?? DEFAULT_MODULES;
// Connectors follow their modules: one per shown module whose connector
// isn't disabled and isn't in the `linked` state (which hides it), carrying
@@ -333,8 +330,8 @@ export function SetupGraphic(props: {
// the onset.
const illuminateLeds = () => {
darkenLeds();
- const accent = accentColor();
- const ink = inkColor();
+ const accent = 'var(--color-accent)';
+ const ink = 'var(--color-ink)';
const lit = `drop-shadow(0 0 1.5px ${accent})`;
const bright = `drop-shadow(0 0 4px ${accent})`;
const motion = !reducedMotion();
diff --git a/apps/web/src/features/theme/components/ColorSwatch.tsx b/apps/web/src/features/theme/components/ColorSwatch.tsx
index 359a3b43c2..0a91f8077c 100644
--- a/apps/web/src/features/theme/components/ColorSwatch.tsx
+++ b/apps/web/src/features/theme/components/ColorSwatch.tsx
@@ -3,7 +3,6 @@ export function ColorSwatch(props: { width: string; color: string }) {
<div
class="theme-color-swatch"
style="
- transition: border-color var(--transition);
border: 1px solid var(--color-edge-muted);
border-radius: 2px;
padding: 3px;
diff --git a/apps/web/src/features/theme/signals/themeReactive.ts b/apps/web/src/features/theme/signals/themeReactive.ts
deleted file mode 100644
index 4e1fa07672..0000000000
--- a/apps/web/src/features/theme/signals/themeReactive.ts
+++ /dev/null
@@ -1,528 +0,0 @@
-import { createEffect, createSignal, on } from 'solid-js';
-import type { ThemePrevious, ThemeReactive } from '../types/themeTypes';
-import { setThemeUpdate } from './themeSignals';
-
-export const themeReactive: ThemeReactive = {
- a0: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'accent color',
- },
- a1: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'accent color +40°',
- },
- a2: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'accent color +80°',
- },
- a3: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'accent color +120°',
- },
- a4: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'accent color +160°',
- },
- b0: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'background',
- },
- b1: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'background active',
- },
- b2: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'background hover',
- },
- b3: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'muted edge',
- },
- b4: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'edge',
- },
- c0: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'text',
- },
- c1: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'text muted',
- },
- c2: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'text extra muted',
- },
- c3: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'text disabled',
- },
- c4: {
- l: createSignal(0),
- c: createSignal(0),
- h: createSignal(0),
- description: 'text placeholder',
- },
-} as const;
-
-const previousTheme: ThemePrevious = {
- a0: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- a1: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- a2: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- a3: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- a4: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- b0: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- b1: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- b2: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- b3: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- b4: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- c0: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- c1: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- c2: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- c3: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
- c4: { l: Number.NaN, c: Number.NaN, h: Number.NaN },
-};
-
-let transitionState = false;
-function jamTransition(): void {
- if (!transitionState) {
- transitionState = true;
- document.documentElement.style.setProperty('--transition', '0s');
-
- setTimeout(() => {
- document.documentElement.style.setProperty('--transition', '0.0s');
- // document.documentElement.style.setProperty('--transition', '0.15s');
- transitionState = false;
- }, 100);
- }
-}
-const ALL_THEME_SIGNALS = [
- themeReactive.a0.l[0],
- themeReactive.a0.c[0],
- themeReactive.a0.h[0],
- themeReactive.a1.l[0],
- themeReactive.a1.c[0],
- themeReactive.a1.h[0],
- themeReactive.a2.l[0],
- themeReactive.a2.c[0],
- themeReactive.a2.h[0],
- themeReactive.a3.l[0],
- themeReactive.a3.c[0],
- themeReactive.a3.h[0],
- themeReactive.a4.l[0],
- themeReactive.a4.c[0],
- themeReactive.a4.h[0],
- themeReactive.b0.l[0],
- themeReactive.b0.c[0],
- themeReactive.b0.h[0],
- themeReactive.b1.l[0],
- themeReactive.b1.c[0],
- themeReactive.b1.h[0],
- themeReactive.b2.l[0],
- themeReactive.b2.c[0],
- themeReactive.b2.h[0],
- themeReactive.b3.l[0],
- themeReactive.b3.c[0],
- themeReactive.b3.h[0],
- themeReactive.b4.l[0],
- themeReactive.b4.c[0],
- themeReactive.b4.h[0],
- themeReactive.c0.l[0],
- themeReactive.c0.h[0],
- themeReactive.c0.c[0],
- themeReactive.c1.l[0],
- themeReactive.c1.c[0],
- themeReactive.c1.h[0],
- themeReactive.c2.l[0],
- themeReactive.c2.c[0],
- themeReactive.c2.h[0],
- themeReactive.c3.l[0],
- themeReactive.c3.c[0],
- themeReactive.c3.h[0],
- themeReactive.c4.l[0],
- themeReactive.c4.c[0],
- themeReactive.c4.h[0],
-];
-
-function syncThemeLightAttribute(): void {
- document.documentElement.dataset.themeLight =
- themeReactive.b0.l[0]() > themeReactive.c0.l[0]() ? 'true' : 'false';
-}
-
-createEffect(
- on(
- ALL_THEME_SIGNALS,
- () => {
- jamTransition();
-
- if (themeReactive.a0.l[0]() !== previousTheme.a0.l) {
- const accentContrastLightness =
- themeReactive.a0.l[0]() < 0.72 ? 0.97 : 0.2;
- document.documentElement.style.setProperty(
- '--a0l',
- `${themeReactive.a0.l[0]()}`
- );
- document.documentElement.style.setProperty(
- '--accent-contrast-l',
- `${accentContrastLightness}`
- );
- previousTheme.a0.l = themeReactive.a0.l[0]();
- }
- if (themeReactive.a0.c[0]() !== previousTheme.a0.c) {
- document.documentElement.style.setProperty(
- '--a0c',
- `${themeReactive.a0.c[0]()}`
- );
- previousTheme.a0.c = themeReactive.a0.c[0]();
- }
- if (themeReactive.a0.h[0]() !== previousTheme.a0.h) {
- document.documentElement.style.setProperty(
- '--a0h',
- `${themeReactive.a0.h[0]()}deg`
- );
- previousTheme.a0.h = themeReactive.a0.h[0]();
- }
- if (themeReactive.a1.l[0]() !== previousTheme.a1.l) {
- document.documentElement.style.setProperty(
- '--a1l',
- `${themeReactive.a1.l[0]()}`
- );
- previousTheme.a1.l = themeReactive.a1.l[0]();
- }
- if (themeReactive.a1.c[0]() !== previousTheme.a1.c) {
- document.documentElement.style.setProperty(
- '--a1c',
- `${themeReactive.a1.c[0]()}`
- );
- previousTheme.a1.c = themeReactive.a1.c[0]();
- }
- if (themeReactive.a1.h[0]() !== previousTheme.a1.h) {
- document.documentElement.style.setProperty(
- '--a1h',
- `${themeReactive.a1.h[0]()}deg`
- );
- previousTheme.a1.h = themeReactive.a1.h[0]();
- }
- if (themeReactive.a2.l[0]() !== previousTheme.a2.l) {
- document.documentElement.style.setProperty(
- '--a2l',
- `${themeReactive.a2.l[0]()}`
- );
- previousTheme.a2.l = themeReactive.a2.l[0]();
- }
- if (themeReactive.a2.c[0]() !== previousTheme.a2.c) {
- document.documentElement.style.setProperty(
- '--a2c',
- `${themeReactive.a2.c[0]()}`
- );
- previousTheme.a2.c = themeReactive.a2.c[0]();
- }
- if (themeReactive.a2.h[0]() !== previousTheme.a2.h) {
- document.documentElement.style.setProperty(
- '--a2h',
- `${themeReactive.a2.h[0]()}deg`
- );
- previousTheme.a2.h = themeReactive.a2.h[0]();
- }
- if (themeReactive.a3.l[0]() !== previousTheme.a3.l) {
- document.documentElement.style.setProperty(
- '--a3l',
- `${themeReactive.a3.l[0]()}`
- );
- previousTheme.a3.l = themeReactive.a3.l[0]();
- }
- if (themeReactive.a3.c[0]() !== previousTheme.a3.c) {
- document.documentElement.style.setProperty(
- '--a3c',
- `${themeReactive.a3.c[0]()}`
- );
- previousTheme.a3.c = themeReactive.a3.c[0]();
- }
- if (themeReactive.a3.h[0]() !== previousTheme.a3.h) {
- document.documentElement.style.setProperty(
- '--a3h',
- `${themeReactive.a3.h[0]()}deg`
- );
- previousTheme.a3.h = themeReactive.a3.h[0]();
- }
- if (themeReactive.a4.l[0]() !== previousTheme.a4.l) {
- document.documentElement.style.setProperty(
- '--a4l',
- `${themeReactive.a4.l[0]()}`
- );
- previousTheme.a4.l = themeReactive.a4.l[0]();
- }
- if (themeReactive.a4.c[0]() !== previousTheme.a4.c) {
- document.documentElement.style.setProperty(
- '--a4c',
- `${themeReactive.a4.c[0]()}`
- );
- previousTheme.a4.c = themeReactive.a4.c[0]();
- }
- if (themeReactive.a4.h[0]() !== previousTheme.a4.h) {
- document.documentElement.style.setProperty(
- '--a4h',
- `${themeReactive.a4.h[0]()}deg`
- );
- previousTheme.a4.h = themeReactive.a4.h[0]();
- }
- if (themeReactive.b0.l[0]() !== previousTheme.b0.l) {
- document.documentElement.style.setProperty(
- '--b0l',
- `${themeReactive.b0.l[0]()}`
- );
- previousTheme.b0.l = themeReactive.b0.l[0]();
- }
- if (themeReactive.b0.c[0]() !== previousTheme.b0.c) {
- document.documentElement.style.setProperty(
- '--b0c',
- `${themeReactive.b0.c[0]()}`
- );
- previousTheme.b0.c = themeReactive.b0.c[0]();
- }
- if (themeReactive.b0.h[0]() !== previousTheme.b0.h) {
- document.documentElement.style.setProperty(
- '--b0h',
- `${themeReactive.b0.h[0]()}deg`
- );
- previousTheme.b0.h = themeReactive.b0.h[0]();
- }
- if (themeReactive.b1.l[0]() !== previousTheme.b1.l) {
- document.documentElement.style.setProperty(
- '--b1l',
- `${themeReactive.b1.l[0]()}`
- );
- previousTheme.b1.l = themeReactive.b1.l[0]();
- }
- if (themeReactive.b1.c[0]() !== previousTheme.b1.c) {
- document.documentElement.style.setProperty(
- '--b1c',
- `${themeReactive.b1.c[0]()}`
- );
- previousTheme.b1.c = themeReactive.b1.c[0]();
- }
- if (themeReactive.b1.h[0]() !== previousTheme.b1.h) {
- document.documentElement.style.setProperty(
- '--b1h',
- `${themeReactive.b1.h[0]()}deg`
- );
- previousTheme.b1.h = themeReactive.b1.h[0]();
- }
- if (themeReactive.b2.l[0]() !== previousTheme.b2.l) {
- document.documentElement.style.setProperty(
- '--b2l',
- `${themeReactive.b2.l[0]()}`
- );
- previousTheme.b2.l = themeReactive.b2.l[0]();
- }
- if (themeReactive.b2.c[0]() !== previousTheme.b2.c) {
- document.documentElement.style.setProperty(
- '--b2c',
- `${themeReactive.b2.c[0]()}`
- );
- previousTheme.b2.c = themeReactive.b2.c[0]();
- }
- if (themeReactive.b2.h[0]() !== previousTheme.b2.h) {
- document.documentElement.style.setProperty(
- '--b2h',
- `${themeReactive.b2.h[0]()}deg`
- );
- previousTheme.b2.h = themeReactive.b2.h[0]();
- }
- if (themeReactive.b3.l[0]() !== previousTheme.b3.l) {
- document.documentElement.style.setProperty(
- '--b3l',
- `${themeReactive.b3.l[0]()}`
- );
- previousTheme.b3.l = themeReactive.b3.l[0]();
- }
- if (themeReactive.b3.c[0]() !== previousTheme.b3.c) {
- document.documentElement.style.setProperty(
- '--b3c',
- `${themeReactive.b3.c[0]()}`
- );
- previousTheme.b3.c = themeReactive.b3.c[0]();
- }
- if (themeReactive.b3.h[0]() !== previousTheme.b3.h) {
- document.documentElement.style.setProperty(
- '--b3h',
- `${themeReactive.b3.h[0]()}deg`
- );
- previousTheme.b3.h = themeReactive.b3.h[0]();
- }
- if (themeReactive.b4.l[0]() !== previousTheme.b4.l) {
- document.documentElement.style.setProperty(
- '--b4l',
- `${themeReactive.b4.l[0]()}`
- );
- previousTheme.b4.l = themeReactive.b4.l[0]();
- }
- if (themeReactive.b4.c[0]() !== previousTheme.b4.c) {
- document.documentElement.style.setProperty(
- '--b4c',
- `${themeReactive.b4.c[0]()}`
- );
- previousTheme.b4.c = themeReactive.b4.c[0]();
- }
- if (themeReactive.b4.h[0]() !== previousTheme.b4.h) {
- document.documentElement.style.setProperty(
- '--b4h',
- `${themeReactive.b4.h[0]()}deg`
- );
- previousTheme.b4.h = themeReactive.b4.h[0]();
- }
- if (themeReactive.c0.l[0]() !== previousTheme.c0.l) {
- document.documentElement.style.setProperty(
- '--c0l',
- `${themeReactive.c0.l[0]()}`
- );
- previousTheme.c0.l = themeReactive.c0.l[0]();
- }
- if (themeReactive.c0.c[0]() !== previousTheme.c0.c) {
- document.documentElement.style.setProperty(
- '--c0c',
- `${themeReactive.c0.c[0]()}`
- );
- previousTheme.c0.c = themeReactive.c0.c[0]();
- }
- if (themeReactive.c0.h[0]() !== previousTheme.c0.h) {
- document.documentElement.style.setProperty(
- '--c0h',
- `${themeReactive.c0.h[0]()}deg`
- );
- previousTheme.c0.h = themeReactive.c0.h[0]();
- }
- if (themeReactive.c1.l[0]() !== previousTheme.c1.l) {
- document.documentElement.style.setProperty(
- '--c1l',
- `${themeReactive.c1.l[0]()}`
- );
- previousTheme.c1.l = themeReactive.c1.l[0]();
- }
- if (themeReactive.c1.c[0]() !== previousTheme.c1.c) {
- document.documentElement.style.setProperty(
- '--c1c',
- `${themeReactive.c1.c[0]()}`
- );
- previousTheme.c1.c = themeReactive.c1.c[0]();
- }
- if (themeReactive.c1.h[0]() !== previousTheme.c1.h) {
- document.documentElement.style.setProperty(
- '--c1h',
- `${themeReactive.c1.h[0]()}deg`
- );
- previousTheme.c1.h = themeReactive.c1.h[0]();
- }
- if (themeReactive.c2.l[0]() !== previousTheme.c2.l) {
- document.documentElement.style.setProperty(
- '--c2l',
- `${themeReactive.c2.l[0]()}`
- );
- previousTheme.c2.l = themeReactive.c2.l[0]();
- }
- if (themeReactive.c2.c[0]() !== previousTheme.c2.c) {
- document.documentElement.style.setProperty(
- '--c2c',
- `${themeReactive.c2.c[0]()}`
- );
- previousTheme.c2.c = themeReactive.c2.c[0]();
- }
- if (themeReactive.c2.h[0]() !== previousTheme.c2.h) {
- document.documentElement.style.setProperty(
- '--c2h',
- `${themeReactive.c2.h[0]()}deg`
- );
- previousTheme.c2.h = themeReactive.c2.h[0]();
- }
- if (themeReactive.c3.l[0]() !== previousTheme.c3.l) {
- document.documentElement.style.setProperty(
- '--c3l',
- `${themeReactive.c3.l[0]()}`
- );
- previousTheme.c3.l = themeReactive.c3.l[0]();
- }
- if (themeReactive.c3.c[0]() !== previousTheme.c3.c) {
- document.documentElement.style.setProperty(
- '--c3c',
- `${themeReactive.c3.c[0]()}`
- );
- previousTheme.c3.c = themeReactive.c3.c[0]();
- }
- if (themeReactive.c3.h[0]() !== previousTheme.c3.h) {
- document.documentElement.style.setProperty(
- '--c3h',
- `${themeReactive.c3.h[0]()}deg`
- );
- previousTheme.c3.h = themeReactive.c3.h[0]();
- }
- if (themeReactive.c4.l[0]() !== previousTheme.c4.l) {
- document.documentElement.style.setProperty(
- '--c4l',
- `${themeReactive.c4.l[0]()}`
- );
- previousTheme.c4.l = themeReactive.c4.l[0]();
- }
- if (themeReactive.c4.c[0]() !== previousTheme.c4.c) {
- document.documentElement.style.setProperty(
- '--c4c',
- `${themeReactive.c4.c[0]()}`
- );
- previousTheme.c4.c = themeReactive.c4.c[0]();
- }
- if (themeReactive.c4.h[0]() !== previousTheme.c4.h) {
- document.documentElement.style.setProperty(
- '--c4h',
- `${themeReactive.c4.h[0]()}deg`
- );
- previousTheme.c4.h = themeReactive.c4.h[0]();
- }
-
- syncThemeLightAttribute();
- setThemeUpdate();
- },
- { defer: true }
- )
-);
-
-function _createThemeEffect(cb: () => void) {
- return createEffect(on(ALL_THEME_SIGNALS, cb));
-}
-
-export function useReactiveColorString(colorKey: keyof ThemeReactive) {
- const [l, c, h] = [
- themeReactive[colorKey].l[0],
- themeReactive[colorKey].c[0],
- themeReactive[colorKey].h[0],
- ];
- return () => `oklch(${l()} ${c()} ${h()}deg)`;
-}
diff --git a/apps/web/src/features/theme/signals/themeSignals.ts b/apps/web/src/features/theme/signals/themeSignals.ts
index 97c49ae2df..309ebd4b7a 100644
--- a/apps/web/src/features/theme/signals/themeSignals.ts
+++ b/apps/web/src/features/theme/signals/themeSignals.ts
@@ -11,6 +11,7 @@ import type {
ThemeV1,
ThemeV3,
} from '../types/themeTypes';
+import { resolveThemeColors } from '../utils/resolvedThemeColors';
import { normalizeThemeColorTokens } from '../utils/themeColorTokens';
import {
convertThemev0v1,
@@ -21,11 +22,6 @@ import { isThemeV2, isThemeV3 } from '../utils/themeValidation';
export const [isThemeSaved, setIsThemeSaved] = createSignal<boolean>(true);
-export const [themeUpdate, setThemeUpdate] = createSignal<undefined>(
- undefined,
- { equals: () => false }
-);
-
export const [htmlColor, setHtmlColor] = makePersisted(
createSignal({ color: '' }),
{ name: 'html-color-theme' }
@@ -80,6 +76,16 @@ export const [liveThemeMode, setLiveThemeMode] = createSignal<'light' | 'dark'>(
'dark'
);
+/** Shared concrete colors for integrations which cannot inherit CSS tokens. */
+export const resolvedThemeColors = createMemo(() =>
+ resolveThemeColors(themeColorTokens(), liveThemeMode())
+);
+
+/** Icons outside the app follow committed colors, not transient previews. */
+export const [committedThemeAccent, setCommittedThemeAccent] = createSignal(
+ 'oklch(0.7 0.12 250deg)'
+);
+
// Per-mode theme preferences, persisted to localStorage. The active one is
// applied by systemThemeEffect / resolveActiveThemeId (themeUtils.ts): the light
// theme when themeMode is 'light' (or 'system' + OS light), the dark theme when
diff --git a/apps/web/src/features/theme/types/themeTypes.ts b/apps/web/src/features/theme/types/themeTypes.ts
index 6d2f1ed4a5..609f499819 100644
--- a/apps/web/src/features/theme/types/themeTypes.ts
+++ b/apps/web/src/features/theme/types/themeTypes.ts
@@ -1,50 +1,3 @@
-import type { Signal } from 'solid-js';
-
-type ThemeReactiveToken = {
- l: Signal<number>;
- c: Signal<number>;
- h: Signal<number>;
- description: string;
-};
-
-export type ThemeReactive = {
- a0: ThemeReactiveToken;
- a1: ThemeReactiveToken;
- a2: ThemeReactiveToken;
- a3: ThemeReactiveToken;
- a4: ThemeReactiveToken;
- b0: ThemeReactiveToken;
- b1: ThemeReactiveToken;
- b2: ThemeReactiveToken;
- b3: ThemeReactiveToken;
- b4: ThemeReactiveToken;
- c0: ThemeReactiveToken;
- c1: ThemeReactiveToken;
- c2: ThemeReactiveToken;
- c3: ThemeReactiveToken;
- c4: ThemeReactiveToken;
-};
-
-export type ThemeReactiveColor = ThemeReactive[keyof ThemeReactive];
-
-export type ThemePrevious = {
- a0: { l: number; c: number; h: number };
- a1: { l: number; c: number; h: number };
- a2: { l: number; c: number; h: number };
- a3: { l: number; c: number; h: number };
- a4: { l: number; c: number; h: number };
- b0: { l: number; c: number; h: number };
- b1: { l: number; c: number; h: number };
- b2: { l: number; c: number; h: number };
- b3: { l: number; c: number; h: number };
- b4: { l: number; c: number; h: number };
- c0: { l: number; c: number; h: number };
- c1: { l: number; c: number; h: number };
- c2: { l: number; c: number; h: number };
- c3: { l: number; c: number; h: number };
- c4: { l: number; c: number; h: number };
-};
-
export const surfaceTokens = [
'surface-0',
'surface-1',
diff --git a/apps/web/src/features/theme/utils/__tests__/resolvedThemeColors.test.ts b/apps/web/src/features/theme/utils/__tests__/resolvedThemeColors.test.ts
new file mode 100644
index 0000000000..a22c1efcb6
--- /dev/null
+++ b/apps/web/src/features/theme/utils/__tests__/resolvedThemeColors.test.ts
@@ -0,0 +1,84 @@
+// @vitest-environment node
+import { describe, expect, it } from 'vitest';
+import { resolveThemeColors } from '../resolvedThemeColors';
+
+describe('resolved theme colors', () => {
+ it('normalizes valid hue angles without clamping their color', () => {
+ const colors = resolveThemeColors(
+ {
+ accent: 'oklch(0.6 0.2 -30)',
+ 'content-0': 'oklch(0.7 0.1 810)',
+ },
+ 'dark'
+ );
+ expect(colors.accent.h).toBe(330);
+ expect(colors['content-0'].h).toBe(90);
+ });
+
+ it('falls back for invalid mix percentages', () => {
+ const colors = resolveThemeColors(
+ {
+ accent:
+ 'color-mix(in oklch, var(--color-content-0) 150%, var(--color-surface-0))',
+ },
+ 'dark'
+ );
+ expect(colors.accent).toEqual(resolveThemeColors({}, 'dark').accent);
+ });
+
+ it('resolves linked and mixed colors from their dependencies', () => {
+ const tokens = {
+ accent: 'var(--color-source)',
+ source: 'oklch(0.6 0.2 30)',
+ 'surface-1':
+ 'color-mix(in oklch, var(--color-source) 25%, var(--color-other))',
+ other: 'oklch(0.2 0.1 70)',
+ };
+ const first = resolveThemeColors(tokens, 'dark');
+ expect(first.accent.l).toBeCloseTo(0.6);
+ expect(first['surface-1'].l).toBeCloseTo(0.3);
+ const edited = resolveThemeColors(
+ { ...tokens, source: 'oklch(0.8 0.2 30)' },
+ 'dark'
+ );
+ expect(edited.accent.l).toBeCloseTo(0.8);
+ expect(edited['surface-1'].l).toBeCloseTo(0.35);
+ expect(first.accent.l).toBeCloseTo(0.6);
+ });
+
+ it('mixes alpha without premultiplying hue and preserves linked transparency', () => {
+ const colors = resolveThemeColors(
+ {
+ a: 'oklch(0.8 0.2 350 / 0.5)',
+ b: 'oklch(0.2 0.1 10)',
+ accent: 'color-mix(in oklch, var(--color-a) 50%, var(--color-b))',
+ 'content-0': 'color-mix(in oklch, var(--color-a) 20%, transparent)',
+ },
+ 'dark'
+ );
+ expect(colors.accent).toMatchObject({ alpha: 0.75, h: 0 });
+ expect(colors.accent.l).toBeCloseTo(0.4);
+ expect(colors['content-0'].alpha).toBeCloseTo(0.1);
+ });
+
+ it('ignores powerless hue in neutral endpoints', () => {
+ const colors = resolveThemeColors(
+ {
+ a: 'oklch(0.2 0 0)',
+ b: 'oklch(0.8 0.2 100)',
+ accent: 'color-mix(in oklch, var(--color-a) 50%, var(--color-b))',
+ },
+ 'dark'
+ );
+ expect(colors.accent.h).toBeCloseTo(100);
+ expect(colors.accent.c).toBeCloseTo(0.1);
+ });
+
+ it('terminates cyclic references and falls back to the default color', () => {
+ const colors = resolveThemeColors(
+ { accent: 'var(--color-loop)', loop: 'var(--color-accent)' },
+ 'dark'
+ );
+ expect(colors.accent).toEqual(resolveThemeColors({}, 'dark').accent);
+ });
+});
diff --git a/apps/web/src/features/theme/utils/resolvedThemeColors.ts b/apps/web/src/features/theme/utils/resolvedThemeColors.ts
new file mode 100644
index 0000000000..0f02ec4933
--- /dev/null
+++ b/apps/web/src/features/theme/utils/resolvedThemeColors.ts
@@ -0,0 +1,203 @@
+import Color from 'colorjs.io';
+import { match } from 'ts-pattern';
+import { macroDarkTheme } from '../themes/macro-dark';
+import { macroLightTheme } from '../themes/macro-light';
+import type { ThemeColorMode, ThemeColorTokens } from '../types/themeTypes';
+import { type OklchColor, sanitizeOklch } from './colorUtil';
+import { parseThemeAssignment } from './themeAssignments';
+
+const resolvedTokens = [
+ 'accent',
+ 'surface-0',
+ 'surface-1',
+ 'surface-2',
+ 'edge',
+ 'edge-muted',
+ 'content-0',
+ 'content-1',
+] as const;
+
+export type ResolvedThemeColors = Readonly<
+ Record<(typeof resolvedTokens)[number], Readonly<OklchColor>>
+>;
+
+// Bounded by content, not theme ID: editing a linked input must invalidate every
+// dependent result, while revisiting a preview should require no DOM reads.
+const cache = new Map<string, ResolvedThemeColors>();
+const CACHE_SIZE = 32;
+
+function toOklch(color: Color): OklchColor {
+ const converted = color.to('oklch');
+ return sanitizeOklch({
+ l: converted.coords[0],
+ c: converted.coords[1],
+ h: ((converted.coords[2] % 360) + 360) % 360,
+ alpha: converted.alpha,
+ });
+}
+
+// CSS color-mix premultiplies rectangular coordinates, but not hue. Color.js
+// 0.5's mix() gamut-maps endpoints and premultiplies hue too, so use its color
+// conversion with CSS interpolation here instead.
+function mixColors(
+ a: Color,
+ b: Color,
+ amount: number,
+ space: 'oklch' | 'srgb'
+): Color {
+ const first = a.to(space);
+ const second = b.to(space);
+ if (space === 'oklch') {
+ if (first.coords[1] < 0.000004) first.coords[2] = Number.NaN;
+ if (second.coords[1] < 0.000004) second.coords[2] = Number.NaN;
+ }
+ const alpha = first.alpha * amount + second.alpha * (1 - amount);
+ const coords = first.coords.map((start, index) => {
+ let end = second.coords[index];
+ if (Number.isNaN(start)) start = end;
+ if (Number.isNaN(end)) end = start;
+ if (space === 'oklch' && index === 2) {
+ start = ((start % 360) + 360) % 360;
+ end = ((end % 360) + 360) % 360;
+ const delta = end - start;
+ if (delta > 180) start += 360;
+ else if (delta < -180) end += 360;
+ return (((start * amount + end * (1 - amount)) % 360) + 360) % 360;
+ }
+ return alpha === 0
+ ? 0
+ : (start * first.alpha * amount + end * second.alpha * (1 - amount)) /
+ alpha;
+ }) as [number, number, number];
+ return new Color(space, coords, alpha);
+}
+
+/** Resolve authored expressions without involving the application's DOM. */
+function resolveGraph(tokens: ThemeColorTokens) {
+ const colors = new Map<string, Color | null>();
+ const visiting = new Set<string>();
+ const resolve = (token: string): Color | null => {
+ if (colors.has(token)) return colors.get(token) ?? null;
+ if (visiting.has(token)) return null;
+ const value = tokens[token];
+ if (!value) return null;
+ visiting.add(token);
+ let color: Color | null = null;
+ try {
+ color = match(parseThemeAssignment(value))
+ .with({ kind: 'custom' }, ({ value }) => new Color(value))
+ .with({ kind: 'linked' }, ({ token, alpha }) => {
+ if (!Number.isFinite(alpha) || alpha < 0 || alpha > 1) return null;
+ const source = resolve(token);
+ if (!source) return null;
+ const result = source.clone();
+ result.alpha *= alpha;
+ return result;
+ })
+ .with({ kind: 'mixed' }, ({ first, second, mix, alpha, space }) => {
+ if (
+ !Number.isFinite(mix) ||
+ mix < 0 ||
+ mix > 1 ||
+ !Number.isFinite(alpha) ||
+ alpha < 0 ||
+ alpha > 1
+ )
+ return null;
+ const a = resolve(first);
+ const b = resolve(second);
+ if (!a || !b) return null;
+ const result = mixColors(a, b, mix, space ?? 'oklch');
+ result.alpha *= alpha;
+ return result;
+ })
+ .exhaustive();
+ } catch {
+ // Arbitrary CSS syntax is resolved by the browser fallback below.
+ }
+ visiting.delete(token);
+ colors.set(token, color);
+ return color;
+ };
+ return resolve;
+}
+
+/** Browser-only escape hatch for custom CSS (relative colors, calc, etc.).
+ * All probes are written before reading; styles belong to a tiny independent
+ * document, never to the document containing the channel or spreadsheet. */
+function resolveCustomColors(
+ tokens: ThemeColorTokens,
+ names: readonly string[],
+ mode: ThemeColorMode
+): Map<string, Color> {
+ const colors = new Map<string, Color>();
+ if (!names.length || typeof document === 'undefined' || !document.body)
+ return colors;
+ const frame = document.createElement('iframe');
+ frame.title = 'Theme color resolution';
+ frame.setAttribute('aria-hidden', 'true');
+ frame.tabIndex = -1;
+ frame.style.cssText =
+ 'position:fixed;width:0;height:0;border:0;visibility:hidden;pointer-events:none;contain:strict';
+ document.body.append(frame);
+ try {
+ const doc = frame.contentDocument;
+ const view = frame.contentWindow;
+ if (!doc || !view) return colors;
+ const root = doc.documentElement;
+ root.style.colorScheme = mode;
+ root.style.setProperty('--layer-surface', 'var(--color-surface-0)');
+ root.style.setProperty('--layer-inset', 'var(--color-surface-0)');
+ for (const [token, value] of Object.entries(tokens)) {
+ root.style.setProperty(`--color-${token}`, value);
+ }
+ const probes = names.map((token) => {
+ const probe = doc.createElement('span');
+ probe.style.color = `var(--color-${token})`;
+ doc.body.append(probe);
+ return { token, probe };
+ });
+ for (const { token, probe } of probes) {
+ const style = view.getComputedStyle(probe);
+ const value = style.getPropertyValue(`--color-${token}`).trim();
+ if (!value || typeof CSS === 'undefined' || !CSS.supports('color', value))
+ continue;
+ try {
+ colors.set(token, new Color(style.color));
+ } catch {
+ // Invalid custom colors retain the default for this theme mode.
+ }
+ }
+ return colors;
+ } finally {
+ frame.remove();
+ }
+}
+
+/** Concrete colors needed by non-CSS consumers. Resolve before writing live CSS. */
+export function resolveThemeColors(
+ authored: ThemeColorTokens,
+ mode: ThemeColorMode
+): ResolvedThemeColors {
+ const defaults = mode === 'dark' ? macroDarkTheme : macroLightTheme;
+ const tokens = { ...defaults.colorTokens, ...authored };
+ const key = JSON.stringify([
+ mode,
+ Object.entries(tokens).sort(([a], [b]) => a.localeCompare(b)),
+ ]);
+ const cached = cache.get(key);
+ if (cached) return cached;
+ const resolve = resolveGraph(tokens);
+ const missing = resolvedTokens.filter((token) => !resolve(token));
+ const custom = resolveCustomColors(tokens, missing, mode);
+ const fallback = resolveGraph(defaults.colorTokens);
+ const result = Object.fromEntries(
+ resolvedTokens.map((token) => [
+ token,
+ toOklch(resolve(token) ?? custom.get(token) ?? fallback(token)!),
+ ])
+ ) as ResolvedThemeColors;
+ if (cache.size >= CACHE_SIZE) cache.delete(cache.keys().next().value!);
+ cache.set(key, result);
+ return result;
+}
diff --git a/apps/web/src/features/theme/utils/themeUtils.ts b/apps/web/src/features/theme/utils/themeUtils.ts
index c244cb5715..8d54d603b4 100644
--- a/apps/web/src/features/theme/utils/themeUtils.ts
+++ b/apps/web/src/features/theme/utils/themeUtils.ts
@@ -1,12 +1,13 @@
import { toast } from '@core/component/Toast/Toast';
import { batch, createEffect, on } from 'solid-js';
import { DEFAULT_DARK_THEME, DEFAULT_LIGHT_THEME } from '../constants';
-import { themeReactive } from '../signals/themeReactive';
import {
currentThemeId,
darkModeTheme,
lightModeTheme,
liveThemeMode,
+ resolvedThemeColors,
+ setCommittedThemeAccent,
setCurrentThemeId,
setDarkModeTheme,
setHtmlColor,
@@ -22,12 +23,9 @@ import {
themes,
userThemes,
} from '../signals/themeSignals';
-import type {
- ThemeColorTokens,
- ThemeV2Tokens,
- ThemeV3,
-} from '../types/themeTypes';
-import { getOklch } from './colorUtil';
+import type { ThemeColorTokens, ThemeV3 } from '../types/themeTypes';
+import { formatOklch } from './colorUtil';
+import { resolveThemeColors } from './resolvedThemeColors';
import {
isStructuralThemeToken,
normalizeThemeColorTokens,
@@ -76,66 +74,6 @@ async function _importTheme(): Promise<void> {
let renderedColorTokenKeys = new Set<string>();
-/** Old non-CSS integrations still consume a/b/c numeric signals. V3 does not
- * store those values; this bridge derives them from the rendered token graph. */
-const LEGACY_TOKEN_MAP = {
- a0: 'accent',
- a1: 'orange',
- a2: 'lime',
- a3: 'teal',
- a4: 'blue',
- b0: 'surface-0',
- b1: 'surface-1',
- b2: 'surface-2',
- b3: 'edge-muted',
- b4: 'edge',
- c0: 'content-0',
- c1: 'content-1',
- c2: 'content-2',
- c3: 'content-3',
- c4: 'content-4',
-} as const satisfies Record<keyof ThemeV2Tokens, string>;
-
-function resolvedTokenOklch(
- token: string
-): { l: number; c: number; h: number } | null {
- const authored = themeColorTokens()[token];
- if (authored) {
- try {
- return getOklch(authored);
- } catch {
- // var() and color-mix() values need the browser to resolve the graph.
- }
- }
- if (typeof document === 'undefined') return null;
-
- const probe = document.createElement('span');
- probe.style.cssText = 'position:fixed;visibility:hidden;pointer-events:none';
- probe.style.color = `var(--color-${token})`;
- document.documentElement.append(probe);
- const resolved = getComputedStyle(probe).color;
- probe.remove();
-
- try {
- return getOklch(resolved);
- } catch {
- return null;
- }
-}
-
-function syncLegacyCompatibilityTokens(): void {
- batch(() => {
- for (const [legacyToken, colorToken] of Object.entries(LEGACY_TOKEN_MAP)) {
- const color = resolvedTokenOklch(colorToken);
- if (!color) continue;
- const target = themeReactive[legacyToken as keyof ThemeV2Tokens];
- target.l[1](color.l);
- target.c[1](color.c);
- target.h[1](color.h);
- }
- });
-}
-
function renderThemeColorToken(token: string, value: string): void {
const mapped = themeTokenCssVar(token, value);
@@ -158,6 +96,8 @@ export function previewLiveThemeColorToken(token: string, value: string): void {
/** Writes all VNext authored tokens to the root and updates editor state. */
export function setLiveThemeColorTokens(tokens: ThemeColorTokens): void {
const normalizedTokens = normalizeThemeColorTokens(tokens, liveThemeMode());
+ // Compute before invalidating styles on the live document.
+ const colors = resolveThemeColors(normalizedTokens, liveThemeMode());
for (const key of renderedColorTokenKeys) {
if (!(key in normalizedTokens)) {
document.documentElement.style.removeProperty(`--color-${key}`);
@@ -168,17 +108,30 @@ export function setLiveThemeColorTokens(tokens: ThemeColorTokens): void {
renderThemeColorToken(key, value);
}
renderedColorTokenKeys = new Set(Object.keys(normalizedTokens));
+ const root = document.documentElement;
+ root.dataset.themeLight = String(
+ colors['surface-0'].l > colors['content-0'].l
+ );
+ if (!normalizedTokens['accent-contrast']) {
+ root.style.setProperty(
+ '--color-accent-contrast',
+ formatOklch({
+ ...colors['content-0'],
+ l: colors.accent.l < 0.72 ? 0.97 : 0.2,
+ })
+ );
+ }
+ root.style.setProperty(
+ '--theme-comment-ink-lightness',
+ String(colors['content-1'].l)
+ );
setThemeColorTokens(normalizedTokens);
- syncLegacyCompatibilityTokens();
}
/** Updates one authored token immediately; persistence still happens on save. */
export function updateLiveThemeColorToken(token: string, value: string): void {
const next = { ...themeColorTokens(), [token]: value };
- renderThemeColorToken(token, value);
- renderedColorTokenKeys.add(token);
- setThemeColorTokens(next);
- syncLegacyCompatibilityTokens();
+ setLiveThemeColorTokens(next);
setIsThemeSaved(false);
}
@@ -188,6 +141,7 @@ let previewSnapshot: {
colorTokens: ThemeColorTokens;
mode: 'light' | 'dark';
} | null = null;
+let previewEndVersion = 0;
export function applyTheme(id: string): void {
let theme = themes().find((t) => t.id === id);
@@ -200,13 +154,12 @@ export function applyTheme(id: string): void {
// clearThemePreview doesn't revert the commit.
previewSnapshot = null;
- setLiveThemeMode(theme.mode);
- setLiveThemeColorTokens(theme.colorTokens);
- queueMicrotask(() => {
- /* scuffed af */
- setIsThemeSaved(true);
- syncHtmlColor();
+ batch(() => {
+ setLiveThemeMode(theme.mode);
+ setLiveThemeColorTokens(theme.colorTokens);
});
+ setIsThemeSaved(true);
+ syncCommittedColors();
}
/** Temporarily shows a theme (e.g. while it's hovered/highlighted in a picker)
@@ -219,6 +172,7 @@ export function previewTheme(id: string): void {
if (!theme) {
return;
}
+ previewEndVersion++;
if (!previewSnapshot) {
// Snapshot the live tokens (not the selected theme id) so ending the
// preview restores unsaved in-editor edits too.
@@ -227,19 +181,34 @@ export function previewTheme(id: string): void {
mode: liveThemeMode(),
};
}
- setLiveThemeMode(theme.mode);
- setLiveThemeColorTokens(theme.colorTokens);
+ batch(() => {
+ setLiveThemeMode(theme.mode);
+ setLiveThemeColorTokens(theme.colorTokens);
+ });
+}
+
+/** A highlight handoff ends the old row before starting the next. Defer only
+ * the rollback so a new preview in the same turn retains the original snapshot. */
+export function scheduleThemePreviewEnd(): void {
+ const version = ++previewEndVersion;
+ queueMicrotask(() => {
+ if (version === previewEndVersion) clearThemePreview();
+ });
}
/** Ends an active theme preview, restoring the pre-preview tokens. No-op when
* nothing is being previewed. */
export function clearThemePreview(): void {
+ previewEndVersion++;
if (!previewSnapshot) {
return;
}
- setLiveThemeMode(previewSnapshot.mode);
- setLiveThemeColorTokens(previewSnapshot.colorTokens);
+ const snapshot = previewSnapshot;
previewSnapshot = null;
+ batch(() => {
+ setLiveThemeMode(snapshot.mode);
+ setLiveThemeColorTokens(snapshot.colorTokens);
+ });
}
/** Resolves the theme id that should be live for the current "Active theme"
@@ -263,11 +232,11 @@ export function systemThemeEffect(): void {
);
}
-/** Persists the live background color, used for the pre-hydration first paint. */
-function syncHtmlColor(): void {
- const color = resolvedTokenOklch('surface-0');
- if (!color) return;
- setHtmlColor({ color: `oklch(${color.l} ${color.c} ${color.h}deg)` });
+/** Only committed colors affect browser/notification icons and first paint. */
+function syncCommittedColors(): void {
+ const colors = resolvedThemeColors();
+ setHtmlColor({ color: formatOklch(colors['surface-0']) });
+ setCommittedThemeAccent(formatOklch(colors.accent));
}
export function saveTheme(name: string): void {
@@ -282,6 +251,7 @@ export function saveTheme(name: string): void {
setUserThemes([...userThemes(), newTheme]);
setCurrentThemeId(id);
setIsThemeSaved(true);
+ syncCommittedColors();
}
/** Save the live V3 registry back onto an existing custom theme. */
@@ -300,6 +270,7 @@ export function updateTheme(id: string, name: string): void {
);
setCurrentThemeId(id);
setIsThemeSaved(true);
+ syncCommittedColors();
}
export function deleteTheme(id: string): void {
@@ -360,11 +331,9 @@ export function applySystemTheme(): void {
/** Checks if the theme contrast is too low, and if so, applies a readable theme. This is to prevent malicious actors sending "Theme Viruses" which make a user's theme unusable. */
export function ensureMinimalThemeContrast() {
- const surface = resolvedTokenOklch('surface-0');
- const content = resolvedTokenOklch('content-0');
- if (!surface || !content) {
- return;
- }
+ const colors = resolvedThemeColors();
+ const surface = colors['surface-0'];
+ const content = colors['content-0'];
const lowContrastTheme = Math.abs(content.l - surface.l) < 0.2;
if (lowContrastTheme) {
applyTheme(DEFAULT_DARK_THEME);
diff --git a/apps/web/src/index.css b/apps/web/src/index.css
index 3af9b4bea0..76c072bfb4 100644
--- a/apps/web/src/index.css
+++ b/apps/web/src/index.css
@@ -5,57 +5,6 @@
@source './lib/core/component/LexicalMarkdown/theme.ts';
@source '../**/*.tsx';
-@property --a0l { syntax: "<number>"; inherits: true; initial-value: 0.88; }
-@property --a0c { syntax: "<number>"; inherits: true; initial-value: 0.20; }
-@property --a0h { syntax: "<angle>"; inherits: true; initial-value: 145deg; }
-@property --a1l { syntax: "<number>"; inherits: true; initial-value: 0.61; }
-@property --a1c { syntax: "<number>"; inherits: true; initial-value: 0.37; }
-@property --a1h { syntax: "<angle>"; inherits: true; initial-value: 54deg; }
-@property --a2l { syntax: "<number>"; inherits: true; initial-value: 0.61; }
-@property --a2c { syntax: "<number>"; inherits: true; initial-value: 0.37; }
-@property --a2h { syntax: "<angle>"; inherits: true; initial-value: 94deg; }
-@property --a3l { syntax: "<number>"; inherits: true; initial-value: 0.61; }
-@property --a3c { syntax: "<number>"; inherits: true; initial-value: 0.37; }
-@property --a3h { syntax: "<angle>"; inherits: true; initial-value: 144deg; }
-@property --a4l { syntax: "<number>"; inherits: true; initial-value: 0.61; }
-@property --a4c { syntax: "<number>"; inherits: true; initial-value: 0.37; }
-@property --a4h { syntax: "<angle>"; inherits: true; initial-value: 194deg; }
-
-@property --b0l { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --b0c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --b0h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --b1l { syntax: "<number>"; inherits: true; initial-value: 0.15; }
-@property --b1c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --b1h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --b2l { syntax: "<number>"; inherits: true; initial-value: 0.16; }
-@property --b2c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --b2h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --b3l { syntax: "<number>"; inherits: true; initial-value: 0.18; }
-@property --b3c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --b3h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --b4l { syntax: "<number>"; inherits: true; initial-value: 0.36; }
-@property --b4c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --b4h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-
-@property --c0l { syntax: "<number>"; inherits: true; initial-value: 1; }
-@property --c0c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --c0h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --c1l { syntax: "<number>"; inherits: true; initial-value: 0.90; }
-@property --c1c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --c1h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --c2l { syntax: "<number>"; inherits: true; initial-value: 0.80; }
-@property --c2c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --c2h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --c3l { syntax: "<number>"; inherits: true; initial-value: 0.70; }
-@property --c3c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --c3h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-@property --c4l { syntax: "<number>"; inherits: true; initial-value: 0.60; }
-@property --c4c { syntax: "<number>"; inherits: true; initial-value: 0; }
-@property --c4h { syntax: "<angle>"; inherits: true; initial-value: 14deg; }
-
-/* Foreground lightness selected for readable content on the active accent. */
-@property --accent-contrast-l { syntax: "<number>"; inherits: true; initial-value: 0.2; }
-
@property --safe-bottom { syntax: "<length>"; inherits: true; initial-value: 0px; }
@property --safe-right { syntax: "<length>"; inherits: true; initial-value: 0px; }
@property --safe-left { syntax: "<length>"; inherits: true; initial-value: 0px; }
@@ -120,30 +69,6 @@
--left-of-channel-rail: calc(var(--left-of-connector) - var(--channel-rail-width) / 2);
--channel-rail-center: calc(var(--left-of-channel-rail) + var(--channel-rail-width) / 2);
- /* accent - active, hover states, high chroma */
- --a0: oklch(var(--a0l) var(--a0c) var(--a0h));
- --a1: oklch(var(--a1l) var(--a1c) var(--a1h));
- --a2: oklch(var(--a2l) var(--a2c) var(--a2h));
- --a3: oklch(var(--a3l) var(--a3c) var(--a3h));
- --a4: oklch(var(--a4l) var(--a4c) var(--a4h));
-
- /* base - background colors, borders */
- --b0: oklch(var(--b0l) var(--b0c) var(--b0h));
- --b1: oklch(var(--b1l) var(--b1c) var(--b1h));
- --b2: oklch(var(--b2l) var(--b2c) var(--b2h));
- --b3: oklch(var(--b3l) var(--b3c) var(--b3h));
- --b4: oklch(var(--b4l) var(--b4c) var(--b4h));
-
- /* contrast, body & paragraph text, icon stroke & fill */
- --c0: oklch(var(--c0l) var(--c0c) var(--c0h));
- --c1: oklch(var(--c1l) var(--c1c) var(--c1h));
- --c2: oklch(var(--c2l) var(--c2c) var(--c2h));
- --c3: oklch(var(--c3l) var(--c3c) var(--c3h));
- --c4: oklch(var(--c4l) var(--c4c) var(--c4h));
-
- /* scuffed: defualt 0.15, used for transition jamming, currently disabled */
- --transition: 0s;
-
/* Glass chrome, ported from the marketing site's hero CTA ring
(solid-site `.home-hero-cta-bar`). The look is four things layered on a
translucent surface: a backdrop blur, a bright inner top edge, a dark
@@ -453,21 +378,21 @@ body.tauri-ios {
--default-ring-width: var(--app-ring-width);
/* Input tokens: the only raw colors stored by a VNext theme. */
- --color-surface-0: var(--b0);
- --color-surface-1: var(--b1);
- --color-surface-2: var(--b2);
- --color-surface-3: var(--b3);
- --color-surface-4: var(--b4);
- --color-content-0: var(--c0);
- --color-content-1: var(--c1);
- --color-content-2: var(--c2);
- --color-content-3: var(--c3);
- --color-content-4: var(--c4);
+ --color-surface-0: oklch(0.17 0 0);
+ --color-surface-1: oklch(0.1949 0 0);
+ --color-surface-2: oklch(0.2115 0 0);
+ --color-surface-3: oklch(0.2281 0 0);
+ --color-surface-4: oklch(0.2447 0 0);
+ --color-content-0: oklch(1 0 0);
+ --color-content-1: oklch(0.83 0 0);
+ --color-content-2: oklch(0.75 0 0);
+ --color-content-3: oklch(0.63 0 0);
+ --color-content-4: oklch(0.55 0 0);
--color-edge: var(--color-surface-4);
--color-edge-muted: var(--color-surface-3);
- --color-accent: var(--a0);
- --color-accent-contrast: oklch(var(--accent-contrast-l) var(--c0c) var(--c0h));
- --color-accent-contrast-muted: oklch(var(--accent-contrast-l) var(--c0c) var(--c0h) / 0.7);
+ --color-accent: oklch(0.7 0.12 250);
+ --color-accent-contrast: oklch(0.97 0 0);
+ --color-accent-contrast-muted: oklch(from var(--color-accent-contrast) l c h / 0.7);
--color-red: oklch(63.7% 0.237 25.331);
--color-orange: oklch(70.5% 0.213 47.604);
--color-amber: oklch(76.9% 0.188 70.08);
@@ -605,7 +530,7 @@ body.tauri-ios {
/* Entity colors are aliases of the authored named palette. */
--color-comment: var(--color-yellow);
--color-comment-bg: oklch(from var(--color-comment) l c h / 0.15);
- --color-comment-ink: oklch(from var(--color-comment) var(--c1l) c h); /* scuffed */
+ --color-comment-ink: oklch(from var(--color-comment) var(--theme-comment-ink-lightness, 0.83) c h); /* scuffed */
--color-calendar: var(--color-yellow);
--color-contact: var(--color-yellow);
@@ -1481,12 +1406,12 @@ a {
}
@utility hover-transition-bg {
- transition: background-color var(--transition);
+ transition: none;
&:hover { transition: none; }
}
@utility hover-transition-border {
- transition: border-color var(--transition);
+ transition: none;
&:hover { transition: none; }
}
diff --git a/apps/web/src/lib/core/component/CustomScrollbar.tsx b/apps/web/src/lib/core/component/CustomScrollbar.tsx
index b2055e1438..17e486f105 100644
--- a/apps/web/src/lib/core/component/CustomScrollbar.tsx
+++ b/apps/web/src/lib/core/component/CustomScrollbar.tsx
@@ -290,7 +290,7 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
height: `${THUMB_THICKNESS}px`,
bottom: `${EDGE_INSET}px`,
left: '0',
- 'background-color': 'var(--c4)',
+ 'background-color': 'var(--color-content-4)',
'border-radius': '2px',
'pointer-events': 'none',
opacity: isDragging() || isScrolling() || isHovered() ? 1 : 0,
@@ -302,7 +302,7 @@ function InnerCustomScrollbar(props: CustomScrollbarProps) {
width: `${THUMB_THICKNESS}px`,
right: `${EDGE_INSET}px`,
top: '0',
- 'background-color': 'var(--c4)',
+ 'background-color': 'var(--color-content-4)',
'border-radius': '2px',
'pointer-events': 'none',
opacity: isDragging() || isScrolling() || isHovered() ? 1 : 0,
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/HtmlRender.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/HtmlRender.tsx
index 757739beeb..09832d8125 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/HtmlRender.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/HtmlRender.tsx
@@ -1,12 +1,6 @@
-import {
- processEmailColors,
- stripColorSchemeMediaQueries,
- type ThemeColorParams,
-} from '@core/email';
+import { processEmailColors, stripColorSchemeMediaQueries } from '@core/email';
import { interceptMailtoLinks } from '@core/util/interceptMailtoLinks';
import type { HtmlRenderDecoratorProps } from '@macro-inc/lexical-core/nodes/HtmlRenderNode';
-import { themeReactive } from '@theme/signals/themeReactive';
-import { themeUpdate } from '@theme/signals/themeSignals';
import {
type Component,
createEffect,
@@ -15,8 +9,10 @@ import {
untrack,
} from 'solid-js';
import { Portal } from 'solid-js/web';
+import { createEmailTheme } from '../../../../../../features/email-message/theme';
export const HtmlRender: Component<HtmlRenderDecoratorProps> = (props) => {
+ const theme = createEmailTheme();
let marker: HTMLDivElement | undefined;
const [shadowContainer, setShadowContainer] = createSignal<HTMLElement>();
const [content, setContent] = createSignal<HTMLDivElement>();
@@ -54,7 +50,7 @@ export const HtmlRender: Component<HtmlRenderDecoratorProps> = (props) => {
// text colors to the theme (or force a white panel for table-layout emails).
// Display-only — the node's raw html is what exportDOM sends.
createEffect(() => {
- themeUpdate();
+ const colors = theme();
const el = content();
if (!el) return;
// Reset to the raw html so recoloring never compounds
@@ -73,16 +69,7 @@ export const HtmlRender: Component<HtmlRenderDecoratorProps> = (props) => {
if (adapt) {
el.style.removeProperty('background-color');
el.style.removeProperty('color');
- const theme: ThemeColorParams = {
- inkL: themeReactive.c0.l[0](),
- inkC: themeReactive.c0.c[0](),
- inkH: themeReactive.c0.h[0](),
- panelL: themeReactive.b1.l[0](),
- accentL: themeReactive.a0.l[0](),
- accentC: themeReactive.a0.c[0](),
- accentH: themeReactive.a0.h[0](),
- };
- processEmailColors(el, theme);
+ processEmailColors(el, colors);
} else {
el.style.setProperty('background-color', 'white', 'important');
// Some emails don't set a color, so force black for readability
diff --git a/apps/web/src/lib/utils/favicon.ts b/apps/web/src/lib/utils/favicon.ts
index 5d467df27e..fa221bfe76 100644
--- a/apps/web/src/lib/utils/favicon.ts
+++ b/apps/web/src/lib/utils/favicon.ts
@@ -4,6 +4,21 @@ import FaviconBadgeSvg from '@icon/macro-logo-badge.svg?raw';
const FAVICON_SIZE = 48;
let currentFaviconLink: HTMLLinkElement | null = null;
+let requestedIcon = '';
+const renderedIcons = new Map<string, string>();
+
+function setFavicon(url: string): void {
+ if (!currentFaviconLink?.isConnected) {
+ document
+ .querySelectorAll('link[rel*="icon"]')
+ .forEach((link) => link.remove());
+ currentFaviconLink = document.createElement('link');
+ currentFaviconLink.rel = 'icon';
+ currentFaviconLink.type = 'image/png';
+ document.head.appendChild(currentFaviconLink);
+ }
+ currentFaviconLink.href = url;
+}
/** escapes a color value for use in SVG */
function escapeColorForSvg(color: string): string {
@@ -31,9 +46,13 @@ export function updateFavicon(
badgeColor?: string,
hasBadge?: boolean
): void {
- if (currentFaviconLink?.parentNode) {
- currentFaviconLink.parentNode.removeChild(currentFaviconLink);
- currentFaviconLink = null;
+ const key = JSON.stringify([faviconColor, badgeColor, !!hasBadge]);
+ if (key === requestedIcon && currentFaviconLink?.isConnected) return;
+ requestedIcon = key;
+ const cached = renderedIcons.get(key);
+ if (cached) {
+ setFavicon(cached);
+ return;
}
const canvas = document.createElement('canvas');
@@ -47,6 +66,7 @@ export function updateFavicon(
img.src = processSvg(hasBadge ? FaviconBadgeSvg : FaviconSvg, faviconColor);
img.onload = () => {
+ if (requestedIcon !== key) return;
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
if (hasBadge) {
@@ -65,29 +85,9 @@ export function updateFavicon(
const faviconUrl = canvas.toDataURL();
- if (currentFaviconLink?.parentNode) {
- currentFaviconLink.parentNode.removeChild(currentFaviconLink);
- }
-
- const existingLinks = document.querySelectorAll('link[rel*="icon"]');
- existingLinks.forEach((link) => {
- link.remove();
- });
-
- // create and add new favicon
- const link = document.createElement('link');
- link.rel = 'icon';
- link.type = 'image/png';
- link.href = faviconUrl;
- document.head.appendChild(link);
- currentFaviconLink = link;
-
- // update existing shortcut icon if present
- const existingShortcutIcon = document.querySelector(
- 'link[rel="shortcut icon"]'
- ) as HTMLLinkElement;
- if (existingShortcutIcon) {
- existingShortcutIcon.href = faviconUrl;
- }
+ if (renderedIcons.size >= 32)
+ renderedIcons.delete(renderedIcons.keys().next().value!);
+ renderedIcons.set(key, faviconUrl);
+ setFavicon(faviconUrl);
};
}
diff --git a/docs/AGENT_GUIDE/navigation.md b/docs/AGENT_GUIDE/navigation.md
index 9d4399ea58..0f09b7fcb9 100644
--- a/docs/AGENT_GUIDE/navigation.md
+++ b/docs/AGENT_GUIDE/navigation.md
@@ -522,6 +522,12 @@ Opens a dialog with a focused `Search...` textbox and bubble-style category radi
the top hit. Also exposes commands: `Create`, `Change theme`, `MCP setup`. Keys: Tab cycles
category, Esc closes. The category strip and footer have transparent backgrounds.
+In `Change theme`, Up/Down previews the highlighted palette across the open app,
+including channels and spreadsheets. Moving between rows preserves the original
+palette for cancellation without briefly restoring it between previews. Esc
+restores that palette (including unsaved edits); Enter commits the highlighted
+theme. Browser and notification icons change only when a theme is committed.
+
With the local GraphQL cache enabled, Cmd+K and document/channel `@` mentions
search cached entities without waiting for a server search. Background hydration
updates an already-open menu only when a bucket it uses changes. Email/body/tag-only