@zyro-sec/ui 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +29 -0
- package/bunfig.toml +2 -0
- package/package.json +21 -40
- package/perf/motion.bench.ts +14 -0
- package/perf/motion.ts +16 -0
- package/script/build-oc2-v2-overrides.ts +38 -0
- package/script/colors.txt +288 -0
- package/script/generate-spinner.ts +121 -0
- package/script/pack.ts +5 -0
- package/script/tailwind.ts +24 -0
- package/src/actions/button/button.stories.tsx +158 -0
- package/src/actions/icon-button/icon-button.stories.tsx +122 -0
- package/src/actions/split-button/split-button.stories.tsx +59 -0
- package/src/assets/favicon/apple-touch-icon-v3.png +0 -0
- package/src/assets/favicon/apple-touch-icon.png +0 -0
- package/src/assets/favicon/favicon-96x96-v3.png +0 -0
- package/src/assets/favicon/favicon-96x96.png +0 -0
- package/src/assets/favicon/favicon-v3.ico +0 -0
- package/src/assets/favicon/favicon-v3.svg +7 -0
- package/src/assets/favicon/favicon.ico +0 -0
- package/src/assets/favicon/favicon.svg +7 -0
- package/src/assets/favicon/site.webmanifest +24 -0
- package/src/assets/favicon/web-app-manifest-192x192.png +0 -0
- package/src/assets/favicon/web-app-manifest-512x512.png +0 -0
- package/src/assets/icons/provider/302ai.svg +7 -0
- package/src/assets/icons/provider/abacus.svg +14 -0
- package/src/assets/icons/provider/aihubmix.svg +3 -0
- package/src/assets/icons/provider/alibaba-cn.svg +3 -0
- package/src/assets/icons/provider/alibaba-coding-plan-cn.svg +3 -0
- package/src/assets/icons/provider/alibaba-coding-plan.svg +3 -0
- package/src/assets/icons/provider/alibaba.svg +3 -0
- package/src/assets/icons/provider/amazon-bedrock.svg +3 -0
- package/src/assets/icons/provider/anthropic.svg +3 -0
- package/src/assets/icons/provider/azure-cognitive-services.svg +24 -0
- package/src/assets/icons/provider/azure.svg +3 -0
- package/src/assets/icons/provider/bailing.svg +3 -0
- package/src/assets/icons/provider/baseten.svg +3 -0
- package/src/assets/icons/provider/berget.svg +3 -0
- package/src/assets/icons/provider/cerebras.svg +4 -0
- package/src/assets/icons/provider/chutes.svg +24 -0
- package/src/assets/icons/provider/clarifai.svg +24 -0
- package/src/assets/icons/provider/claude-agent.svg +3 -0
- package/src/assets/icons/provider/cloudferro-sherlock.svg +5 -0
- package/src/assets/icons/provider/cloudflare-ai-gateway.svg +4 -0
- package/src/assets/icons/provider/cloudflare-workers-ai.svg +4 -0
- package/src/assets/icons/provider/cohere.svg +5 -0
- package/src/assets/icons/provider/cortecs.svg +24 -0
- package/src/assets/icons/provider/deepinfra.svg +4 -0
- package/src/assets/icons/provider/deepseek.svg +3 -0
- package/src/assets/icons/provider/digitalocean.svg +6 -0
- package/src/assets/icons/provider/dinference.svg +1 -0
- package/src/assets/icons/provider/drun.svg +8 -0
- package/src/assets/icons/provider/evroc.svg +3 -0
- package/src/assets/icons/provider/fastrouter.svg +3 -0
- package/src/assets/icons/provider/fireworks-ai.svg +3 -0
- package/src/assets/icons/provider/firmware.svg +18 -0
- package/src/assets/icons/provider/friendli.svg +3 -0
- package/src/assets/icons/provider/github-copilot.svg +3 -0
- package/src/assets/icons/provider/github-models.svg +3 -0
- package/src/assets/icons/provider/gitlab.svg +3 -0
- package/src/assets/icons/provider/google-vertex-anthropic.svg +24 -0
- package/src/assets/icons/provider/google-vertex.svg +10 -0
- package/src/assets/icons/provider/google.svg +3 -0
- package/src/assets/icons/provider/groq.svg +3 -0
- package/src/assets/icons/provider/helicone.svg +6 -0
- package/src/assets/icons/provider/huggingface.svg +3 -0
- package/src/assets/icons/provider/iflowcn.svg +3 -0
- package/src/assets/icons/provider/inception.svg +4 -0
- package/src/assets/icons/provider/inference.svg +3 -0
- package/src/assets/icons/provider/io-net.svg +5 -0
- package/src/assets/icons/provider/jiekou.svg +4 -0
- package/src/assets/icons/provider/kilo.svg +4 -0
- package/src/assets/icons/provider/kimi-for-coding.svg +3 -0
- package/src/assets/icons/provider/kuae-cloud-coding-plan.svg +3 -0
- package/src/assets/icons/provider/llama.svg +3 -0
- package/src/assets/icons/provider/lmstudio.svg +24 -0
- package/src/assets/icons/provider/lucidquery.svg +3 -0
- package/src/assets/icons/provider/meganova.svg +3 -0
- package/src/assets/icons/provider/meituan.svg +6 -0
- package/src/assets/icons/provider/meta.svg +3 -0
- package/src/assets/icons/provider/minimax-cn-coding-plan.svg +24 -0
- package/src/assets/icons/provider/minimax-cn.svg +3 -0
- package/src/assets/icons/provider/minimax-coding-plan.svg +24 -0
- package/src/assets/icons/provider/minimax.svg +3 -0
- package/src/assets/icons/provider/mistral.svg +3 -0
- package/src/assets/icons/provider/moark.svg +3 -0
- package/src/assets/icons/provider/modelscope.svg +5 -0
- package/src/assets/icons/provider/moonshotai-cn.svg +3 -0
- package/src/assets/icons/provider/moonshotai.svg +3 -0
- package/src/assets/icons/provider/morph.svg +24 -0
- package/src/assets/icons/provider/nano-gpt.svg +3 -0
- package/src/assets/icons/provider/nebius.svg +4 -0
- package/src/assets/icons/provider/nova.svg +3 -0
- package/src/assets/icons/provider/novita-ai.svg +10 -0
- package/src/assets/icons/provider/nvidia.svg +3 -0
- package/src/assets/icons/provider/ollama-cloud.svg +7 -0
- package/src/assets/icons/provider/openai.svg +3 -0
- package/src/assets/icons/provider/opencode-go.svg +3 -0
- package/src/assets/icons/provider/opencode.svg +3 -0
- package/src/assets/icons/provider/openrouter.svg +3 -0
- package/src/assets/icons/provider/ovhcloud.svg +3 -0
- package/src/assets/icons/provider/perplexity-agent.svg +3 -0
- package/src/assets/icons/provider/perplexity.svg +3 -0
- package/src/assets/icons/provider/poe.svg +7 -0
- package/src/assets/icons/provider/privatemode-ai.svg +5 -0
- package/src/assets/icons/provider/qihang-ai.svg +9 -0
- package/src/assets/icons/provider/qiniu-ai.svg +7 -0
- package/src/assets/icons/provider/reflection.svg +3 -0
- package/src/assets/icons/provider/requesty.svg +24 -0
- package/src/assets/icons/provider/sap-ai-core.svg +24 -0
- package/src/assets/icons/provider/scaleway.svg +5 -0
- package/src/assets/icons/provider/siliconflow-cn.svg +3 -0
- package/src/assets/icons/provider/siliconflow.svg +3 -0
- package/src/assets/icons/provider/stackit.svg +4 -0
- package/src/assets/icons/provider/stepfun.svg +16 -0
- package/src/assets/icons/provider/submodel.svg +3 -0
- package/src/assets/icons/provider/synthetic.svg +24 -0
- package/src/assets/icons/provider/tencent-coding-plan.svg +5 -0
- package/src/assets/icons/provider/tencent.svg +3 -0
- package/src/assets/icons/provider/thinkingmachines.svg +3 -0
- package/src/assets/icons/provider/togetherai.svg +4 -0
- package/src/assets/icons/provider/upstage.svg +24 -0
- package/src/assets/icons/provider/v0.svg +3 -0
- package/src/assets/icons/provider/venice.svg +4 -0
- package/src/assets/icons/provider/vercel.svg +3 -0
- package/src/assets/icons/provider/vivgrid.svg +4 -0
- package/src/assets/icons/provider/vultr.svg +6 -0
- package/src/assets/icons/provider/wandb.svg +24 -0
- package/src/assets/icons/provider/xai.svg +3 -0
- package/src/assets/icons/provider/xiaomi.svg +3 -0
- package/src/assets/icons/provider/zai-coding-plan.svg +3 -0
- package/src/assets/icons/provider/zai.svg +3 -0
- package/src/assets/icons/provider/zenmux.svg +4 -0
- package/src/assets/icons/provider/zhipuai-coding-plan.svg +3 -0
- package/src/assets/icons/provider/zhipuai.svg +3 -0
- package/src/assets/images/social-share-black.png +0 -0
- package/src/assets/images/social-share-zen.png +0 -0
- package/src/assets/images/social-share.png +0 -0
- package/src/components/animated-number-machine.test.ts +140 -0
- package/src/components/animated-number.stories.tsx +35 -0
- package/src/components/app-icon.stories.tsx +73 -0
- package/src/components/card.stories.tsx +101 -0
- package/src/components/collapsible.stories.tsx +76 -0
- package/src/components/context-menu.stories.tsx +150 -0
- package/src/components/diagram-preview.stories.tsx +62 -0
- package/src/components/dock-surface.stories.tsx +26 -0
- package/src/components/document-surface.stories.tsx +42 -0
- package/src/components/error-details.stories.tsx +72 -0
- package/src/components/favicon.stories.tsx +49 -0
- package/src/components/file-icon-machine.test.ts +52 -0
- package/src/components/file-icon.stories.tsx +93 -0
- package/src/components/file-icons/sprite.svg +11707 -0
- package/src/components/font.stories.tsx +48 -0
- package/src/components/hover-card.stories.tsx +79 -0
- package/src/components/image-flight-machine.test.ts +184 -0
- package/src/components/image-flight.test.ts +173 -0
- package/src/components/image-preview.stories.tsx +392 -0
- package/src/components/image-zoom-machine.test.ts +154 -0
- package/src/components/image-zoom.test.ts +96 -0
- package/src/components/list.stories.tsx +221 -0
- package/src/components/logo.stories.tsx +62 -0
- package/src/components/menu-scroll.stories.tsx +73 -0
- package/src/components/popover-machine.test.ts +150 -0
- package/src/components/popover.stories.tsx +84 -0
- package/src/components/preview-controls.stories.tsx +40 -0
- package/src/components/progress.stories.tsx +69 -0
- package/src/components/provider-icon.stories.tsx +75 -0
- package/src/components/resize-handle-machine.test.ts +164 -0
- package/src/components/resize-handle.stories.tsx +81 -0
- package/src/components/rolling-number.stories.tsx +23 -0
- package/src/components/scroll-view-machine.test.ts +141 -0
- package/src/components/scroll-view.stories.tsx +68 -0
- package/src/components/scroll-view.test.ts +114 -0
- package/src/components/spinner-radar.test.ts +61 -0
- package/src/components/spinner.stories.tsx +40 -0
- package/src/components/sticky-accordion-header.stories.tsx +64 -0
- package/src/components/text-field-machine.test.ts +99 -0
- package/src/components/text-field.stories.tsx +132 -0
- package/src/components/text-reveal-machine.test.ts +157 -0
- package/src/components/text-reveal.stories.tsx +363 -0
- package/src/components/text-strikethrough.stories.tsx +296 -0
- package/src/components/thinking-heading.stories.tsx +900 -0
- package/src/components/truncated-text.stories.tsx +37 -0
- package/src/components/typewriter-machine.test.ts +177 -0
- package/src/components/typewriter.stories.tsx +51 -0
- package/src/context/dialog-machine.test.ts +295 -0
- package/src/context/i18n.test.ts +89 -0
- package/src/context/marked-base.test.ts +75 -0
- package/src/context/marked-parser.test.ts +167 -0
- package/src/context/marked-regression.test.ts +12 -0
- package/src/data-display/accordion/accordion.stories.tsx +76 -0
- package/src/data-display/avatar/avatar.stories.tsx +48 -0
- package/src/data-display/badge/badge.stories.tsx +75 -0
- package/src/data-display/diff-changes/diff-changes.stories.tsx +63 -0
- package/src/data-display/keybind/keybind.stories.tsx +77 -0
- package/src/data-display/line-comment/line-comment.stories.tsx +288 -0
- package/src/data-display/line-comment/machine.test.ts +385 -0
- package/src/data-display/project-avatar/animation-machine.test.ts +134 -0
- package/src/data-display/project-avatar/generated.test.ts +50 -0
- package/src/data-display/project-avatar/procedural.test.ts +16 -0
- package/src/data-display/project-avatar/project-avatar.stories.tsx +102 -0
- package/src/data-display/project-avatar/project-avatar.test.ts +21 -0
- package/src/data-display/project-avatar/project-icon-styles.stories.tsx +772 -0
- package/src/feedback/activity-ring/activity-ring.stories.tsx +20 -0
- package/src/feedback/loader/loader.stories.tsx +44 -0
- package/src/feedback/progress-circle/progress-circle.stories.tsx +56 -0
- package/src/feedback/toast/description.test.ts +20 -0
- package/src/feedback/toast/machine.test.ts +106 -0
- package/src/feedback/toast/toast.stories.tsx +186 -0
- package/src/forms/checkbox/checkbox.stories.tsx +104 -0
- package/src/forms/field/field.stories.tsx +129 -0
- package/src/forms/inline-input/inline-input.stories.tsx +37 -0
- package/src/forms/radio/radio.stories.tsx +145 -0
- package/src/forms/redirect-paste/redirect-paste.stories.tsx +101 -0
- package/src/forms/search-list/navigation.test.ts +40 -0
- package/src/forms/search-list/search-list.stories.tsx +108 -0
- package/src/forms/select/machine.test.ts +105 -0
- package/src/forms/select/select.stories.tsx +208 -0
- package/src/forms/switch/switch.stories.tsx +97 -0
- package/src/forms/text-input/text-input.stories.tsx +220 -0
- package/src/forms/textarea/textarea.stories.tsx +137 -0
- package/src/forms/typeahead/machine.test.ts +143 -0
- package/src/forms/typeahead/typeahead.stories.tsx +113 -0
- package/src/hooks/auto-scroll-machine.test.ts +212 -0
- package/src/hooks/list-machine.test.ts +263 -0
- package/src/hooks/spin-phase.test.ts +32 -0
- package/src/hooks/use-filtered-list.test.ts +41 -0
- package/src/icons/icon/icon.stories.tsx +131 -0
- package/src/layout/divider/divider.stories.tsx +38 -0
- package/src/motion/README.md +113 -0
- package/src/motion/core.test.ts +328 -0
- package/src/motion-tuning-features.test.ts +129 -0
- package/src/motion-tuning.test.ts +68 -0
- package/src/navigation/menu/machine.test.ts +85 -0
- package/src/navigation/menu/menu.stories.tsx +328 -0
- package/src/navigation/menu/submenu-machine.test.ts +71 -0
- package/src/navigation/segmented-control/segmented-control.stories.tsx +115 -0
- package/src/navigation/segmented-control/segmented-control.test.ts +123 -0
- package/src/navigation/tab-state-indicator.stories.tsx +24 -0
- package/src/navigation/tabs/tabs.stories.tsx +193 -0
- package/src/overlays/dialog/dialog.stories.tsx +365 -0
- package/src/overlays/mcp-sign-in/machine.test.ts +215 -0
- package/src/overlays/tooltip/machine.test.ts +214 -0
- package/src/overlays/tooltip/tooltip.stories.tsx +155 -0
- package/src/styles/blue-tokens.stories.tsx +215 -0
- package/src/theme/desktop-theme.schema.json +168 -0
- package/src/theme/machine.test.ts +498 -0
- package/src/theme/v2/resolve.test.ts +120 -0
- package/src/typography/slash/slash.stories.tsx +26 -0
- package/src/typography/text-shimmer/machine.test.ts +117 -0
- package/src/typography/text-shimmer/text-shimmer.stories.tsx +64 -0
- package/src/typography/wordmark/wordmark.stories.tsx +19 -0
- package/test/solid-jsx.ts +20 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +23 -0
- package/vite.config.ts +61 -0
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import {
|
|
3
|
+
createThemeState,
|
|
4
|
+
selectColorScheme,
|
|
5
|
+
selectMode,
|
|
6
|
+
selectThemeId,
|
|
7
|
+
selectThemesLoading,
|
|
8
|
+
THEME_LOAD_TIMEOUT_MS,
|
|
9
|
+
transitionTheme,
|
|
10
|
+
type ColorScheme,
|
|
11
|
+
type ResolvedMode,
|
|
12
|
+
type ThemeEffect,
|
|
13
|
+
type ThemeEvent,
|
|
14
|
+
type ThemeMachineState,
|
|
15
|
+
} from "./machine"
|
|
16
|
+
import type { DesktopTheme } from "./types"
|
|
17
|
+
|
|
18
|
+
const bundled = new Set(["oc-2", "dracula", "nord", "tokyonight"])
|
|
19
|
+
|
|
20
|
+
function theme(id: string): DesktopTheme {
|
|
21
|
+
const variant = {
|
|
22
|
+
palette: {
|
|
23
|
+
neutral: "#101418",
|
|
24
|
+
ink: "#e6edf3",
|
|
25
|
+
primary: "#009fff",
|
|
26
|
+
success: "#3fb950",
|
|
27
|
+
warning: "#d29922",
|
|
28
|
+
error: "#f85149",
|
|
29
|
+
info: "#a371f7",
|
|
30
|
+
},
|
|
31
|
+
} as const
|
|
32
|
+
|
|
33
|
+
return { name: id, id, light: variant, dark: variant }
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const oc2 = theme("oc-2")
|
|
37
|
+
|
|
38
|
+
const dracula = theme("dracula")
|
|
39
|
+
|
|
40
|
+
const nord = theme("nord")
|
|
41
|
+
|
|
42
|
+
const tokyonight = theme("tokyonight")
|
|
43
|
+
|
|
44
|
+
const midnight = theme("acme:midnight")
|
|
45
|
+
|
|
46
|
+
function start(input: { themeId?: string; scheme?: ColorScheme; systemMode?: ResolvedMode } = {}) {
|
|
47
|
+
return createThemeState({
|
|
48
|
+
themeId: input.themeId ?? "oc-2",
|
|
49
|
+
scheme: input.scheme ?? "dark",
|
|
50
|
+
systemMode: input.systemMode ?? "dark",
|
|
51
|
+
defaultTheme: oc2,
|
|
52
|
+
bundled,
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function run(state: ThemeMachineState, ...events: ThemeEvent[]) {
|
|
57
|
+
return events.reduce<{ state: ThemeMachineState; effects: ThemeEffect[] }>(
|
|
58
|
+
(result, event) => {
|
|
59
|
+
const next = transitionTheme(result.state, event, bundled)
|
|
60
|
+
|
|
61
|
+
return { state: next.state, effects: [...result.effects, ...next.effects] }
|
|
62
|
+
},
|
|
63
|
+
{ state, effects: [] },
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function applied(effects: readonly ThemeEffect[]) {
|
|
68
|
+
return effects.flatMap((effect) =>
|
|
69
|
+
effect.type === "apply-theme" ? [{ id: effect.id, mode: effect.mode, scheme: effect.scheme }] : [],
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function storage(effects: readonly ThemeEffect[]) {
|
|
74
|
+
return effects.filter(
|
|
75
|
+
(effect) =>
|
|
76
|
+
effect.type === "persist-theme" ||
|
|
77
|
+
effect.type === "persist-scheme" ||
|
|
78
|
+
effect.type === "cache-theme" ||
|
|
79
|
+
effect.type === "clear-cache",
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
test("a system light/dark flip keeps a previewed scheme until the preview follows the system", () => {
|
|
84
|
+
const previewed = run(start({ scheme: "system", systemMode: "dark" }).state, {
|
|
85
|
+
type: "preview.scheme",
|
|
86
|
+
scheme: "light",
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
expect(applied(previewed.effects)).toEqual([{ id: "oc-2", mode: "light", scheme: "light" }])
|
|
90
|
+
|
|
91
|
+
const flipped = run(
|
|
92
|
+
previewed.state,
|
|
93
|
+
{ type: "system.mode.changed", mode: "light" },
|
|
94
|
+
{ type: "system.mode.changed", mode: "dark" },
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
expect(flipped.effects).toEqual([])
|
|
98
|
+
expect(selectMode(flipped.state)).toBe("light")
|
|
99
|
+
expect(flipped.state.status).toBe("previewing")
|
|
100
|
+
|
|
101
|
+
const system = run(flipped.state, { type: "preview.scheme", scheme: "system" })
|
|
102
|
+
|
|
103
|
+
expect(applied(system.effects)).toEqual([{ id: "oc-2", mode: "dark", scheme: "system" }])
|
|
104
|
+
expect(applied(run(system.state, { type: "system.mode.changed", mode: "light" }).effects)).toEqual([
|
|
105
|
+
{ id: "oc-2", mode: "light", scheme: "system" },
|
|
106
|
+
])
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test("a previewed system scheme follows the system even when the saved scheme is fixed", () => {
|
|
110
|
+
const result = run(
|
|
111
|
+
start({ scheme: "dark", systemMode: "dark" }).state,
|
|
112
|
+
{ type: "preview.scheme", scheme: "system" },
|
|
113
|
+
{ type: "system.mode.changed", mode: "light" },
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
expect(applied(result.effects)).toEqual([
|
|
117
|
+
{ id: "oc-2", mode: "dark", scheme: "system" },
|
|
118
|
+
{ id: "oc-2", mode: "light", scheme: "system" },
|
|
119
|
+
])
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test("registrations, settling and a finished load keep a preview on screen", () => {
|
|
123
|
+
const initial = start({ themeId: "tokyonight" })
|
|
124
|
+
|
|
125
|
+
expect(initial.effects).toEqual([
|
|
126
|
+
{ type: "load-theme", id: "tokyonight", attempt: 1, timeoutMs: THEME_LOAD_TIMEOUT_MS },
|
|
127
|
+
])
|
|
128
|
+
|
|
129
|
+
const previewed = run(
|
|
130
|
+
initial.state,
|
|
131
|
+
{ type: "preview.theme", id: "oc-2" },
|
|
132
|
+
{ type: "preview.scheme", scheme: "light" },
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
const background = run(
|
|
136
|
+
previewed.state,
|
|
137
|
+
{ type: "theme.registered", theme: midnight },
|
|
138
|
+
{ type: "settled" },
|
|
139
|
+
{ type: "theme.loaded", id: "tokyonight", attempt: 1, theme: tokyonight },
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
expect(applied(background.effects)).toEqual([])
|
|
143
|
+
expect(storage(background.effects)).toEqual([{ type: "cache-theme", id: "tokyonight", theme: tokyonight }])
|
|
144
|
+
|
|
145
|
+
const cancelled = run(background.state, { type: "preview.cancelled" })
|
|
146
|
+
|
|
147
|
+
expect(applied(cancelled.effects)).toEqual([{ id: "tokyonight", mode: "dark", scheme: "dark" }])
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
test("another tab's theme choice becomes the saved theme behind a preview", () => {
|
|
151
|
+
const previewed = run(
|
|
152
|
+
start().state,
|
|
153
|
+
{ type: "preview.theme", id: "dracula" },
|
|
154
|
+
{ type: "theme.loaded", id: "dracula", attempt: 1, theme: dracula },
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
const changed = run(
|
|
158
|
+
previewed.state,
|
|
159
|
+
{ type: "storage.theme.changed", id: "nord" },
|
|
160
|
+
{ type: "theme.loaded", id: "nord", attempt: 2, theme: nord },
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
expect(applied(changed.effects)).toEqual([])
|
|
164
|
+
expect(selectThemeId(changed.state, bundled)).toBe("dracula")
|
|
165
|
+
expect(applied(run(changed.state, { type: "preview.cancelled" }).effects)).toEqual([
|
|
166
|
+
{ id: "nord", mode: "dark", scheme: "dark" },
|
|
167
|
+
])
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test("a saved theme that finishes loading after cancel and a new preview stays behind the new preview", () => {
|
|
171
|
+
const result = run(
|
|
172
|
+
start({ themeId: "nord" }).state,
|
|
173
|
+
{ type: "preview.theme", id: "oc-2" },
|
|
174
|
+
{ type: "preview.cancelled" },
|
|
175
|
+
{ type: "preview.theme", id: "oc-2" },
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
const loaded = run(result.state, { type: "theme.loaded", id: "nord", attempt: 1, theme: nord })
|
|
179
|
+
|
|
180
|
+
expect(applied(result.effects)).toEqual([{ id: "oc-2", mode: "dark", scheme: "dark" }])
|
|
181
|
+
expect(applied(loaded.effects)).toEqual([])
|
|
182
|
+
expect(selectThemeId(loaded.state, bundled)).toBe("oc-2")
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test("selecting a theme ends its preview, and the previewed theme's late load does not paint", () => {
|
|
186
|
+
const selected = run(
|
|
187
|
+
start({ themeId: "nord" }).state,
|
|
188
|
+
{ type: "theme.loaded", id: "nord", attempt: 1, theme: nord },
|
|
189
|
+
{ type: "preview.theme", id: "dracula" },
|
|
190
|
+
{ type: "theme.selected", id: "oc-2" },
|
|
191
|
+
)
|
|
192
|
+
|
|
193
|
+
expect(selected.state.status).toBe("committed")
|
|
194
|
+
expect(applied(selected.effects).at(-1)).toEqual({ id: "oc-2", mode: "dark", scheme: "dark" })
|
|
195
|
+
|
|
196
|
+
const late = run(selected.state, { type: "theme.loaded", id: "dracula", attempt: 2, theme: dracula })
|
|
197
|
+
|
|
198
|
+
expect(late.effects).toEqual([{ type: "cancel-load-timer", attempt: 2 }])
|
|
199
|
+
expect(run(late.state, { type: "preview.committed" }).effects).toEqual([])
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test("selecting a theme keeps a previewed scheme", () => {
|
|
203
|
+
const result = run(
|
|
204
|
+
start().state,
|
|
205
|
+
{ type: "preview.theme", id: "dracula" },
|
|
206
|
+
{ type: "preview.scheme", scheme: "light" },
|
|
207
|
+
{ type: "theme.selected", id: "oc-2" },
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
expect(result.state.status === "previewing" && result.state.preview).toEqual({ scheme: "light" })
|
|
211
|
+
expect(applied(result.effects)).toEqual([{ id: "oc-2", mode: "light", scheme: "light" }])
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
test("previews never touch storage; committing saves both axes without painting again", () => {
|
|
215
|
+
const previewed = run(
|
|
216
|
+
start({ themeId: "nord" }).state,
|
|
217
|
+
{ type: "theme.loaded", id: "nord", attempt: 1, theme: nord },
|
|
218
|
+
{ type: "preview.theme", id: "dracula" },
|
|
219
|
+
{ type: "theme.loaded", id: "dracula", attempt: 2, theme: dracula },
|
|
220
|
+
{ type: "preview.scheme", scheme: "light" },
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
const cancelled = run(previewed.state, { type: "preview.cancelled" })
|
|
224
|
+
|
|
225
|
+
expect(storage(previewed.effects)).toEqual([{ type: "cache-theme", id: "nord", theme: nord }])
|
|
226
|
+
expect(storage(cancelled.effects)).toEqual([])
|
|
227
|
+
|
|
228
|
+
const committed = run(previewed.state, { type: "preview.committed" })
|
|
229
|
+
|
|
230
|
+
expect(storage(committed.effects)).toEqual([
|
|
231
|
+
{ type: "persist-theme", id: "dracula" },
|
|
232
|
+
{ type: "persist-scheme", scheme: "light" },
|
|
233
|
+
{ type: "cache-theme", id: "dracula", theme: dracula },
|
|
234
|
+
])
|
|
235
|
+
expect(applied(committed.effects)).toEqual([])
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
test("a plugin theme withdrawn and registered again caches both variants again", () => {
|
|
239
|
+
const selected = run(
|
|
240
|
+
start().state,
|
|
241
|
+
{ type: "theme.registered", theme: midnight },
|
|
242
|
+
{ type: "settled" },
|
|
243
|
+
{ type: "theme.selected", id: "acme:midnight" },
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
const withdrawn = run(selected.state, { type: "theme.unregistered", theme: midnight })
|
|
247
|
+
|
|
248
|
+
expect(withdrawn.effects).toEqual([
|
|
249
|
+
{ type: "clear-cache" },
|
|
250
|
+
expect.objectContaining({ type: "apply-theme", id: "oc-2" }),
|
|
251
|
+
])
|
|
252
|
+
|
|
253
|
+
const restored = run(withdrawn.state, { type: "theme.registered", theme: midnight })
|
|
254
|
+
|
|
255
|
+
expect(restored.effects).toEqual([
|
|
256
|
+
{ type: "cache-theme", id: "acme:midnight", theme: midnight },
|
|
257
|
+
expect.objectContaining({ type: "apply-theme", id: "acme:midnight" }),
|
|
258
|
+
])
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
test("mode and theme id follow a preview and return on cancel; the saved scheme does not", () => {
|
|
262
|
+
const state = start({ themeId: "oc-2", scheme: "dark" }).state
|
|
263
|
+
const previewed = run(state, { type: "preview.scheme", scheme: "light" }, { type: "preview.theme", id: "dracula" })
|
|
264
|
+
|
|
265
|
+
expect([
|
|
266
|
+
selectMode(previewed.state),
|
|
267
|
+
selectThemeId(previewed.state, bundled),
|
|
268
|
+
selectColorScheme(previewed.state),
|
|
269
|
+
]).toEqual(["light", "dracula", "dark"])
|
|
270
|
+
|
|
271
|
+
const cancelled = run(previewed.state, { type: "preview.cancelled" }).state
|
|
272
|
+
|
|
273
|
+
expect([selectMode(cancelled), selectThemeId(cancelled, bundled), selectColorScheme(cancelled)]).toEqual([
|
|
274
|
+
"dark",
|
|
275
|
+
"oc-2",
|
|
276
|
+
"dark",
|
|
277
|
+
])
|
|
278
|
+
|
|
279
|
+
const committed = run(previewed.state, { type: "preview.committed" }).state
|
|
280
|
+
|
|
281
|
+
expect([selectMode(committed), selectThemeId(committed, bundled), selectColorScheme(committed)]).toEqual([
|
|
282
|
+
"light",
|
|
283
|
+
"dracula",
|
|
284
|
+
"light",
|
|
285
|
+
])
|
|
286
|
+
})
|
|
287
|
+
|
|
288
|
+
test("a slow import shows the default theme, keeps the cached colors, and still applies and caches when it arrives", () => {
|
|
289
|
+
const slow = run(start({ themeId: "tokyonight" }).state, {
|
|
290
|
+
type: "theme.load.timed-out",
|
|
291
|
+
id: "tokyonight",
|
|
292
|
+
attempt: 1,
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
expect(selectThemeId(slow.state, bundled)).toBe("oc-2")
|
|
296
|
+
expect(slow.effects).toEqual([expect.objectContaining({ type: "apply-theme", id: "oc-2" })])
|
|
297
|
+
expect(selectThemesLoading(slow.state)).toBe(false)
|
|
298
|
+
|
|
299
|
+
const late = run(slow.state, { type: "theme.loaded", id: "tokyonight", attempt: 1, theme: tokyonight })
|
|
300
|
+
|
|
301
|
+
expect(selectThemeId(late.state, bundled)).toBe("tokyonight")
|
|
302
|
+
expect(late.effects).toEqual([
|
|
303
|
+
{ type: "cancel-load-timer", attempt: 1 },
|
|
304
|
+
{ type: "cache-theme", id: "tokyonight", theme: tokyonight },
|
|
305
|
+
expect.objectContaining({ type: "apply-theme", id: "tokyonight" }),
|
|
306
|
+
])
|
|
307
|
+
})
|
|
308
|
+
|
|
309
|
+
test("a failed import shows the default theme, keeps the cached colors, and loads again when selected", () => {
|
|
310
|
+
const failed = run(start({ themeId: "tokyonight" }).state, {
|
|
311
|
+
type: "theme.load.failed",
|
|
312
|
+
id: "tokyonight",
|
|
313
|
+
attempt: 1,
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
expect(selectThemeId(failed.state, bundled)).toBe("oc-2")
|
|
317
|
+
expect(failed.effects).toEqual([
|
|
318
|
+
{ type: "cancel-load-timer", attempt: 1 },
|
|
319
|
+
expect.objectContaining({ type: "apply-theme", id: "oc-2" }),
|
|
320
|
+
])
|
|
321
|
+
|
|
322
|
+
const late = run(failed.state, { type: "theme.loaded", id: "tokyonight", attempt: 1, theme: tokyonight })
|
|
323
|
+
|
|
324
|
+
expect(late.state).toBe(failed.state)
|
|
325
|
+
expect(late.effects).toEqual([])
|
|
326
|
+
|
|
327
|
+
const retried = run(failed.state, { type: "theme.selected", id: "tokyonight" })
|
|
328
|
+
|
|
329
|
+
expect(retried.effects).toEqual([
|
|
330
|
+
{ type: "persist-theme", id: "tokyonight" },
|
|
331
|
+
{ type: "load-theme", id: "tokyonight", attempt: 2, timeoutMs: THEME_LOAD_TIMEOUT_MS },
|
|
332
|
+
])
|
|
333
|
+
|
|
334
|
+
const loaded = run(retried.state, { type: "theme.loaded", id: "tokyonight", attempt: 2, theme: tokyonight })
|
|
335
|
+
|
|
336
|
+
expect(applied(loaded.effects)).toEqual([{ id: "tokyonight", mode: "dark", scheme: "dark" }])
|
|
337
|
+
})
|
|
338
|
+
|
|
339
|
+
test("selecting a slow theme again starts a fresh attempt with its own timeout", () => {
|
|
340
|
+
const slow = run(start({ themeId: "tokyonight" }).state, {
|
|
341
|
+
type: "theme.load.timed-out",
|
|
342
|
+
id: "tokyonight",
|
|
343
|
+
attempt: 1,
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
const retried = run(slow.state, { type: "theme.selected", id: "tokyonight" })
|
|
347
|
+
|
|
348
|
+
expect(retried.effects).toEqual([
|
|
349
|
+
{ type: "persist-theme", id: "tokyonight" },
|
|
350
|
+
{ type: "load-theme", id: "tokyonight", attempt: 2, timeoutMs: THEME_LOAD_TIMEOUT_MS },
|
|
351
|
+
])
|
|
352
|
+
expect(selectThemesLoading(retried.state)).toBe(true)
|
|
353
|
+
|
|
354
|
+
const stale = run(retried.state, { type: "theme.loaded", id: "tokyonight", attempt: 1, theme: tokyonight })
|
|
355
|
+
|
|
356
|
+
expect(stale.state).toBe(retried.state)
|
|
357
|
+
expect(
|
|
358
|
+
applied(run(retried.state, { type: "theme.loaded", id: "tokyonight", attempt: 2, theme: tokyonight }).effects),
|
|
359
|
+
).toEqual([{ id: "tokyonight", mode: "dark", scheme: "dark" }])
|
|
360
|
+
})
|
|
361
|
+
|
|
362
|
+
test("a slow or failed import never clears the cached colors of the selected bundled theme", () => {
|
|
363
|
+
const cached = run(
|
|
364
|
+
start({ themeId: "nord" }).state,
|
|
365
|
+
{ type: "theme.loaded", id: "nord", attempt: 1, theme: nord },
|
|
366
|
+
{ type: "theme.selected", id: "tokyonight" },
|
|
367
|
+
)
|
|
368
|
+
|
|
369
|
+
// Another theme's colors go: the next start must not paint them under the new choice.
|
|
370
|
+
expect(storage(cached.effects).at(-1)).toEqual({ type: "clear-cache" })
|
|
371
|
+
|
|
372
|
+
const unknown = start({ themeId: "tokyonight" }).state
|
|
373
|
+
|
|
374
|
+
const outcomes = [
|
|
375
|
+
run(unknown, { type: "theme.load.timed-out", id: "tokyonight", attempt: 1 }),
|
|
376
|
+
run(unknown, { type: "theme.load.failed", id: "tokyonight", attempt: 1 }),
|
|
377
|
+
run(
|
|
378
|
+
unknown,
|
|
379
|
+
{ type: "theme.load.timed-out", id: "tokyonight", attempt: 1 },
|
|
380
|
+
{ type: "theme.load.failed", id: "tokyonight", attempt: 1 },
|
|
381
|
+
),
|
|
382
|
+
]
|
|
383
|
+
|
|
384
|
+
outcomes.forEach((outcome) => {
|
|
385
|
+
expect(storage(outcome.effects)).toEqual([])
|
|
386
|
+
expect(outcome.state.cached).toEqual({ status: "unknown" })
|
|
387
|
+
})
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
test("withdrawing a previewed plugin theme ends the preview; a replaced theme ignores the old withdrawal", () => {
|
|
391
|
+
const previewed = run(
|
|
392
|
+
start().state,
|
|
393
|
+
{ type: "theme.registered", theme: midnight },
|
|
394
|
+
{ type: "preview.theme", id: "acme:midnight" },
|
|
395
|
+
)
|
|
396
|
+
|
|
397
|
+
const withdrawn = run(previewed.state, { type: "theme.unregistered", theme: midnight })
|
|
398
|
+
|
|
399
|
+
expect(withdrawn.state.status).toBe("committed")
|
|
400
|
+
expect(applied(withdrawn.effects)).toEqual([{ id: "oc-2", mode: "dark", scheme: "dark" }])
|
|
401
|
+
|
|
402
|
+
const replacement = theme("acme:midnight")
|
|
403
|
+
const replaced = run(previewed.state, { type: "theme.registered", theme: replacement })
|
|
404
|
+
const stale = run(replaced.state, { type: "theme.unregistered", theme: midnight })
|
|
405
|
+
|
|
406
|
+
expect(stale.state).toBe(replaced.state)
|
|
407
|
+
expect(selectThemeId(stale.state, bundled)).toBe("acme:midnight")
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
test("a saved plugin theme keeps the cached colors until plugins settle without it", () => {
|
|
411
|
+
const initial = start({ themeId: "gone:midnight" })
|
|
412
|
+
|
|
413
|
+
expect(initial.effects).toEqual([{ type: "notify-applied", mode: "dark", scheme: "dark" }])
|
|
414
|
+
expect(selectThemeId(initial.state, bundled)).toBe("gone:midnight")
|
|
415
|
+
|
|
416
|
+
const settled = run(initial.state, { type: "settled" })
|
|
417
|
+
|
|
418
|
+
expect(selectThemeId(settled.state, bundled)).toBe("oc-2")
|
|
419
|
+
expect(settled.effects).toEqual([
|
|
420
|
+
{ type: "clear-cache" },
|
|
421
|
+
expect.objectContaining({ type: "apply-theme", id: "oc-2" }),
|
|
422
|
+
])
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
test("preloading skips loaded and loading themes and retries failed ones", () => {
|
|
426
|
+
const failed = run(
|
|
427
|
+
start({ themeId: "nord" }).state,
|
|
428
|
+
{ type: "theme.load.failed", id: "nord", attempt: 1 },
|
|
429
|
+
{ type: "preview.theme", id: "dracula" },
|
|
430
|
+
)
|
|
431
|
+
|
|
432
|
+
const preloaded = run(failed.state, { type: "themes.preload" })
|
|
433
|
+
|
|
434
|
+
expect(preloaded.effects).toEqual([
|
|
435
|
+
{ type: "load-theme", id: "nord", attempt: 3, timeoutMs: THEME_LOAD_TIMEOUT_MS },
|
|
436
|
+
{ type: "load-theme", id: "tokyonight", attempt: 4, timeoutMs: THEME_LOAD_TIMEOUT_MS },
|
|
437
|
+
])
|
|
438
|
+
expect(selectThemesLoading(preloaded.state)).toBe(true)
|
|
439
|
+
|
|
440
|
+
const again = run(preloaded.state, { type: "themes.preload" })
|
|
441
|
+
|
|
442
|
+
expect(again.state).toBe(preloaded.state)
|
|
443
|
+
expect(again.effects).toEqual([])
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
test("events that change nothing return the same state", () => {
|
|
447
|
+
const state = run(start().state, { type: "theme.registered", theme: midnight }, { type: "settled" }).state
|
|
448
|
+
const previewing = run(state, { type: "preview.scheme", scheme: "light" }).state
|
|
449
|
+
|
|
450
|
+
const unchanged: [ThemeMachineState, ThemeEvent][] = [
|
|
451
|
+
[state, { type: "theme.selected", id: "oc-2" }],
|
|
452
|
+
[state, { type: "scheme.selected", scheme: "dark" }],
|
|
453
|
+
[state, { type: "preview.theme", id: "missing" }],
|
|
454
|
+
[state, { type: "preview.committed" }],
|
|
455
|
+
[state, { type: "preview.cancelled" }],
|
|
456
|
+
[state, { type: "theme.registered", theme: midnight }],
|
|
457
|
+
[state, { type: "theme.unregistered", theme: oc2 }],
|
|
458
|
+
[state, { type: "settled" }],
|
|
459
|
+
[state, { type: "system.mode.changed", mode: "dark" }],
|
|
460
|
+
[state, { type: "storage.theme.changed", id: "oc-2" }],
|
|
461
|
+
[state, { type: "storage.scheme.changed", scheme: "dark" }],
|
|
462
|
+
[state, { type: "theme.loaded", id: "nord", attempt: 9, theme: nord }],
|
|
463
|
+
[state, { type: "theme.load.failed", id: "nord", attempt: 9 }],
|
|
464
|
+
[state, { type: "theme.load.timed-out", id: "nord", attempt: 9 }],
|
|
465
|
+
[previewing, { type: "preview.scheme", scheme: "light" }],
|
|
466
|
+
[previewing, { type: "system.mode.changed", mode: "dark" }],
|
|
467
|
+
[previewing, { type: "preview.theme", id: "missing" }],
|
|
468
|
+
]
|
|
469
|
+
|
|
470
|
+
unchanged.forEach(([current, event]) => {
|
|
471
|
+
const next = transitionTheme(current, event, bundled)
|
|
472
|
+
|
|
473
|
+
expect(next.state).toBe(current)
|
|
474
|
+
expect(next.effects).toEqual([])
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
expect(run(state, { type: "theme.selected", id: "missing" }).effects).toEqual([
|
|
478
|
+
{ type: "warn-missing-theme", id: "missing" },
|
|
479
|
+
])
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
test("disposal cancels imports and ignores every later event", () => {
|
|
483
|
+
const loading = start({ themeId: "nord" }).state
|
|
484
|
+
const disposed = run(loading, { type: "disposed" })
|
|
485
|
+
|
|
486
|
+
expect(disposed.effects).toEqual([{ type: "cancel-all-loads" }])
|
|
487
|
+
expect(selectThemesLoading(disposed.state)).toBe(false)
|
|
488
|
+
|
|
489
|
+
const late = run(
|
|
490
|
+
disposed.state,
|
|
491
|
+
{ type: "theme.loaded", id: "nord", attempt: 1, theme: nord },
|
|
492
|
+
{ type: "theme.selected", id: "dracula" },
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
expect(late.state).toBe(disposed.state)
|
|
496
|
+
expect(late.effects).toEqual([])
|
|
497
|
+
expect(run(start().state, { type: "disposed" }).effects).toEqual([])
|
|
498
|
+
})
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { contrastRatio } from "../color"
|
|
3
|
+
import type { DesktopTheme, HexColor, ResolvedV2Theme } from "../types"
|
|
4
|
+
import { resolveThemeV2, resolveThemeVariantV2, themeV2ToCss } from "./resolve"
|
|
5
|
+
|
|
6
|
+
const theme: DesktopTheme = await Bun.file(new URL("../themes/oc-2.json", import.meta.url)).json()
|
|
7
|
+
|
|
8
|
+
describe("icon emphasis", () => {
|
|
9
|
+
test.each(["light", "dark"] as const)("OC-2 %s icons increase in contrast from faint to base", (mode) => {
|
|
10
|
+
expectIconEmphasis(resolveThemeV2(theme)[mode])
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test.each([false, true])("custom theme fallbacks preserve icon emphasis (dark: %s)", (dark) => {
|
|
14
|
+
expectIconEmphasis(resolveThemeVariantV2({ ...theme[dark ? "dark" : "light"], v2Overrides: undefined }, dark))
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe("focus ring colour", () => {
|
|
19
|
+
test.each([
|
|
20
|
+
{ mode: "light", expected: "var(--v2-blue-500)" },
|
|
21
|
+
{ mode: "dark", expected: "var(--v2-blue-400)" },
|
|
22
|
+
] as const)("$mode uses the same focus token for OpenCode and custom-theme fallbacks", ({ mode, expected }) => {
|
|
23
|
+
expect(resolveThemeV2(theme)[mode]["v2-border-border-focus"]).toBe(expected)
|
|
24
|
+
expect(
|
|
25
|
+
resolveThemeVariantV2({ ...theme[mode], v2Overrides: undefined }, mode === "dark")["v2-border-border-focus"],
|
|
26
|
+
).toBe(expected)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test("a custom theme can override the focus ring colour", () => {
|
|
30
|
+
const tokens = resolveThemeVariantV2(
|
|
31
|
+
{ ...theme.dark, v2Overrides: { "v2-border-border-focus": "var(--v2-green-500)" } },
|
|
32
|
+
true,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
expect(tokens["v2-border-border-focus"]).toBe("var(--v2-green-500)")
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
describe("contrast icon-button tokens", () => {
|
|
40
|
+
test("OC-2 dark mode uses a light background and an inverse icon matching the base surface", () => {
|
|
41
|
+
const tokens = resolveThemeV2(theme).dark
|
|
42
|
+
expect(tokens["v2-background-bg-icon-button-contrast"]).toBe("var(--v2-grey-400)")
|
|
43
|
+
expect(tokens["v2-grey-400"]).toBe("#dbdbdbff")
|
|
44
|
+
expect(tokens["v2-icon-icon-inverse"]).toBe(tokens["v2-background-bg-base"])
|
|
45
|
+
expect(tokens["v2-grey-1100"]).toBe("#161616ff")
|
|
46
|
+
expect(tokens["v2-background-bg-contrast"]).toBe("var(--v2-grey-700)")
|
|
47
|
+
expect(tokens["v2-text-text-contrast"]).toBe("var(--v2-grey-50)")
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test("OC-2 light mode retains the existing contrast background and foreground", () => {
|
|
51
|
+
const tokens = resolveThemeV2(theme).light
|
|
52
|
+
expect(tokens["v2-background-bg-icon-button-contrast"]).toBe("var(--v2-background-bg-contrast)")
|
|
53
|
+
expect(tokens["v2-background-bg-contrast"]).toBe("var(--v2-grey-1000)")
|
|
54
|
+
expect(tokens["v2-text-text-contrast"]).toBe("var(--v2-grey-50)")
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
test.each([false, true])("custom themes without the new token receive a fallback (dark: %s)", (dark) => {
|
|
58
|
+
const tokens = resolveThemeVariantV2({ ...theme.dark, v2Overrides: undefined }, dark)
|
|
59
|
+
expect(tokens["v2-background-bg-icon-button-contrast"]).toBe(
|
|
60
|
+
dark ? "var(--v2-grey-400)" : "var(--v2-background-bg-contrast)",
|
|
61
|
+
)
|
|
62
|
+
expect(themeV2ToCss(tokens)).toContain(
|
|
63
|
+
`--v2-background-bg-icon-button-contrast: ${tokens["v2-background-bg-icon-button-contrast"]};`,
|
|
64
|
+
)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test("custom themes can override the icon-button background independently", () => {
|
|
68
|
+
const tokens = resolveThemeVariantV2(
|
|
69
|
+
{
|
|
70
|
+
...theme.dark,
|
|
71
|
+
v2Overrides: { ...theme.dark.v2Overrides, "v2-background-bg-icon-button-contrast": "#dddddd" },
|
|
72
|
+
},
|
|
73
|
+
true,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
expect(tokens["v2-background-bg-icon-button-contrast"]).toBe("#dddddd")
|
|
77
|
+
expect(tokens["v2-background-bg-contrast"]).toBe("var(--v2-grey-700)")
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
describe("input elevation", () => {
|
|
82
|
+
test.each([
|
|
83
|
+
{
|
|
84
|
+
mode: "light",
|
|
85
|
+
input:
|
|
86
|
+
"0px 0px 0px 0px var(--v2-alpha-dark-0), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 1px 1.5px 0px var(--v2-alpha-dark-10)",
|
|
87
|
+
button:
|
|
88
|
+
"0px 0px 0px 0px var(--v2-alpha-dark-0), 0px 0px 0px 0.5px var(--v2-alpha-dark-14), 0px 1px 1.5px 0px var(--v2-alpha-dark-10)",
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
mode: "dark",
|
|
92
|
+
input:
|
|
93
|
+
"0px -0.5px 0px 0px var(--v2-alpha-light-6), 0px 0px 0px 0.5px var(--v2-alpha-light-16), 0px 1px 2px 0px var(--v2-alpha-dark-0)",
|
|
94
|
+
button:
|
|
95
|
+
"0px -0.5px 0px 0px var(--v2-alpha-light-10), 0px 0px 0px 0.5px var(--v2-alpha-light-20), 0px 1px 2px 0px var(--v2-alpha-dark-40)",
|
|
96
|
+
},
|
|
97
|
+
] as const)(
|
|
98
|
+
"$mode matches Figma in OC-2 and custom-theme fallbacks without changing buttons",
|
|
99
|
+
({ mode, input, button }) => {
|
|
100
|
+
for (const tokens of [
|
|
101
|
+
resolveThemeV2(theme)[mode],
|
|
102
|
+
resolveThemeVariantV2({ ...theme[mode], v2Overrides: undefined }, mode === "dark"),
|
|
103
|
+
]) {
|
|
104
|
+
expect(tokens["v2-elevation-input"]).toBe(input)
|
|
105
|
+
expect(tokens["v2-elevation-button-neutral"]).toBe(button)
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
function expectIconEmphasis(tokens: ResolvedV2Theme) {
|
|
112
|
+
// SAFETY: these resolved background/icon color tokens are hex colors or references to other hex color tokens.
|
|
113
|
+
const resolve = (value: string): HexColor =>
|
|
114
|
+
value.startsWith("var(--") ? resolve(tokens[value.slice(6, -1)]) : (value as HexColor)
|
|
115
|
+
|
|
116
|
+
const background = resolve(tokens["v2-background-bg-base"])
|
|
117
|
+
const contrast = (role: string) => contrastRatio(resolve(tokens[`v2-icon-icon-${role}`]), background)
|
|
118
|
+
expect(contrast("faint")).toBeLessThan(contrast("muted"))
|
|
119
|
+
expect(contrast("muted")).toBeLessThan(contrast("base"))
|
|
120
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Slash } from "./slash"
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: "UI/Slash",
|
|
5
|
+
id: "ui-slash",
|
|
6
|
+
component: Slash,
|
|
7
|
+
args: { gap: 8 },
|
|
8
|
+
argTypes: { gap: { control: { type: "range", min: 0, max: 24, step: 1 } } },
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const Paths = {
|
|
12
|
+
render: (args: { gap: number }) => (
|
|
13
|
+
<div class="flex flex-col items-start gap-4 p-6 text-[13px] leading-4 text-v2-text-text-muted">
|
|
14
|
+
<span class="flex items-center">
|
|
15
|
+
<span>home</span>
|
|
16
|
+
<Slash gap={args.gap} />
|
|
17
|
+
<span class="text-v2-text-text-base">HOME</span>
|
|
18
|
+
</span>
|
|
19
|
+
<span class="flex items-center">
|
|
20
|
+
<span class="text-v2-text-text-faint">Anthropic</span>
|
|
21
|
+
<Slash />
|
|
22
|
+
<span>Claude Opus 5.5 Fast</span>
|
|
23
|
+
</span>
|
|
24
|
+
</div>
|
|
25
|
+
),
|
|
26
|
+
}
|