@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,134 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import {
|
|
3
|
+
AVATAR_DISPOSED,
|
|
4
|
+
AVATAR_POINTER_LEFT,
|
|
5
|
+
AVATAR_REFRESH,
|
|
6
|
+
AVATAR_REST_MS,
|
|
7
|
+
createAvatarClock,
|
|
8
|
+
INITIAL_AVATAR_ANIMATION_STATE,
|
|
9
|
+
selectAvatarPaintTime,
|
|
10
|
+
selectAvatarRunning,
|
|
11
|
+
transitionAvatarAnimation,
|
|
12
|
+
type AvatarAnimationEvent,
|
|
13
|
+
type AvatarAnimationState,
|
|
14
|
+
type AvatarAnimationTransition,
|
|
15
|
+
type AvatarClock,
|
|
16
|
+
} from "./animation-machine"
|
|
17
|
+
|
|
18
|
+
const enter = (now: number, reduced = false): AvatarAnimationEvent => ({ type: "pointer.entered", now, reduced })
|
|
19
|
+
|
|
20
|
+
const frame = (now: number): AvatarAnimationEvent => ({ type: "frame", now })
|
|
21
|
+
|
|
22
|
+
const motion = (reduced: boolean): AvatarAnimationEvent => ({ type: "motion.changed", reduced })
|
|
23
|
+
|
|
24
|
+
function run(clock: AvatarClock, state: AvatarAnimationState, ...events: AvatarAnimationEvent[]) {
|
|
25
|
+
return events.reduce<AvatarAnimationTransition>(
|
|
26
|
+
(result, event) => transitionAvatarAnimation(result.state, clock, event),
|
|
27
|
+
{ state, effect: "none" },
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const animating = (clock: AvatarClock) =>
|
|
32
|
+
run(clock, INITIAL_AVATAR_ANIMATION_STATE, enter(0), frame(AVATAR_REST_MS + 10)).state
|
|
33
|
+
|
|
34
|
+
describe("transitionAvatarAnimation", () => {
|
|
35
|
+
test("waits out the rest delay, then animates", () => {
|
|
36
|
+
const clock = createAvatarClock()
|
|
37
|
+
const resting = run(clock, INITIAL_AVATAR_ANIMATION_STATE, enter(0), frame(80))
|
|
38
|
+
|
|
39
|
+
expect(resting.state.status).toBe("resting")
|
|
40
|
+
expect(resting.effect).toBe("none")
|
|
41
|
+
expect(selectAvatarRunning(resting.state)).toBe(true)
|
|
42
|
+
|
|
43
|
+
const first = run(clock, resting.state, frame(AVATAR_REST_MS + 10))
|
|
44
|
+
|
|
45
|
+
expect(first).toMatchObject({ state: { status: "animating" }, effect: "paint-frame" })
|
|
46
|
+
expect(selectAvatarPaintTime(first.state, clock)).toBeCloseTo(0.08)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test("passing over a row stops at once without painting", () => {
|
|
50
|
+
const clock = createAvatarClock()
|
|
51
|
+
const result = run(clock, INITIAL_AVATAR_ANIMATION_STATE, enter(0), frame(30), AVATAR_POINTER_LEFT)
|
|
52
|
+
|
|
53
|
+
expect(result).toMatchObject({ state: INITIAL_AVATAR_ANIMATION_STATE, effect: "none" })
|
|
54
|
+
expect(selectAvatarRunning(result.state)).toBe(false)
|
|
55
|
+
expect(clock).toEqual(createAvatarClock())
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test("a refresh repaints the static frame while resting, not while animating", () => {
|
|
59
|
+
const clock = createAvatarClock()
|
|
60
|
+
const resting = run(clock, INITIAL_AVATAR_ANIMATION_STATE, enter(0)).state
|
|
61
|
+
|
|
62
|
+
expect(run(clock, INITIAL_AVATAR_ANIMATION_STATE, AVATAR_REFRESH).effect).toBe("paint-static")
|
|
63
|
+
expect(run(clock, resting, AVATAR_REFRESH)).toMatchObject({ state: resting, effect: "paint-static" })
|
|
64
|
+
expect(run(clock, animating(clock), AVATAR_REFRESH).effect).toBe("none")
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
test("reduced motion blocks the hover and stops a running animation", () => {
|
|
68
|
+
const clock = createAvatarClock()
|
|
69
|
+
|
|
70
|
+
expect(run(clock, INITIAL_AVATAR_ANIMATION_STATE, enter(0, true)).state).toBe(INITIAL_AVATAR_ANIMATION_STATE)
|
|
71
|
+
|
|
72
|
+
const resting = run(clock, INITIAL_AVATAR_ANIMATION_STATE, enter(0)).state
|
|
73
|
+
|
|
74
|
+
expect(run(clock, resting, motion(true))).toMatchObject({ state: INITIAL_AVATAR_ANIMATION_STATE, effect: "none" })
|
|
75
|
+
|
|
76
|
+
const stopped = run(clock, animating(clock), motion(true))
|
|
77
|
+
|
|
78
|
+
expect(stopped).toMatchObject({ state: INITIAL_AVATAR_ANIMATION_STATE, effect: "paint-static" })
|
|
79
|
+
expect(clock).toEqual(createAvatarClock())
|
|
80
|
+
expect(run(clock, animating(clock), motion(false)).state.status).toBe("animating")
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
test("eases back after the pointer leaves, resumes without a rest delay, and settles", () => {
|
|
84
|
+
const clock = createAvatarClock()
|
|
85
|
+
const easing = run(clock, animating(clock), AVATAR_POINTER_LEFT)
|
|
86
|
+
|
|
87
|
+
expect(easing).toMatchObject({ state: { status: "easing" }, effect: "none" })
|
|
88
|
+
expect(run(clock, easing.state, enter(170, true)).state).toBe(easing.state)
|
|
89
|
+
|
|
90
|
+
const resumed = run(clock, easing.state, enter(170), frame(186))
|
|
91
|
+
|
|
92
|
+
expect(resumed).toMatchObject({ state: { status: "animating" }, effect: "paint-frame" })
|
|
93
|
+
|
|
94
|
+
const eased = run(clock, resumed.state, AVATAR_POINTER_LEFT, frame(286))
|
|
95
|
+
|
|
96
|
+
expect(eased).toMatchObject({ state: { status: "easing" }, effect: "paint-frame" })
|
|
97
|
+
expect(clock.time).toBeLessThan(0.116)
|
|
98
|
+
|
|
99
|
+
const settled = run(clock, eased.state, frame(386), frame(486), frame(586))
|
|
100
|
+
|
|
101
|
+
expect(settled).toMatchObject({ state: INITIAL_AVATAR_ANIMATION_STATE, effect: "paint-static" })
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
test("a frame step never runs backwards or past the cap", () => {
|
|
105
|
+
const clock = createAvatarClock()
|
|
106
|
+
const state = animating(clock)
|
|
107
|
+
const time = clock.time
|
|
108
|
+
|
|
109
|
+
run(clock, state, frame(0))
|
|
110
|
+
expect(clock.time).toBe(time)
|
|
111
|
+
run(clock, state, frame(10_000))
|
|
112
|
+
expect(clock.time).toBeCloseTo(time + 0.1)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
test("frames reuse the same frozen transition", () => {
|
|
116
|
+
const clock = createAvatarClock()
|
|
117
|
+
const state = animating(clock)
|
|
118
|
+
const first = transitionAvatarAnimation(state, clock, frame(200))
|
|
119
|
+
|
|
120
|
+
expect(transitionAvatarAnimation(state, clock, frame(216))).toBe(first)
|
|
121
|
+
expect(Object.isFrozen(first)).toBe(true)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test("disposing ignores later events", () => {
|
|
125
|
+
const clock = createAvatarClock()
|
|
126
|
+
const disposed = run(clock, animating(clock), AVATAR_DISPOSED).state
|
|
127
|
+
|
|
128
|
+
expect(selectAvatarRunning(disposed)).toBe(false)
|
|
129
|
+
expect(run(clock, disposed, enter(0), frame(500), AVATAR_REFRESH)).toMatchObject({
|
|
130
|
+
state: disposed,
|
|
131
|
+
effect: "none",
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from "crypto"
|
|
2
|
+
import { describe, expect, test } from "bun:test"
|
|
3
|
+
import { generateProjectIcon, getProjectAvatarGenerated } from "./project-avatar"
|
|
4
|
+
|
|
5
|
+
describe("generateProjectIcon", () => {
|
|
6
|
+
test("derives the same icon from the same key", () => {
|
|
7
|
+
expect(generateProjectIcon("project-a")).toEqual(generateProjectIcon("project-a"))
|
|
8
|
+
expect(generateProjectIcon("project-a")).not.toEqual(generateProjectIcon("project-b"))
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// Projects without a stored icon fall back to this output, so it must not drift between releases.
|
|
12
|
+
test("resolves the seed, palette and every drawing parameter", () => {
|
|
13
|
+
expect(generateProjectIcon("9f1c2a7e01")).toEqual({
|
|
14
|
+
style: "mesh",
|
|
15
|
+
version: 1,
|
|
16
|
+
params: {
|
|
17
|
+
scale: 0.95,
|
|
18
|
+
fold: 0.4,
|
|
19
|
+
light: 1,
|
|
20
|
+
tilt: -0.02,
|
|
21
|
+
speed: 0.9,
|
|
22
|
+
grain: 0.14,
|
|
23
|
+
grainSize: 16,
|
|
24
|
+
seedX: 39.46408212184906,
|
|
25
|
+
seedY: 35.76026787981391,
|
|
26
|
+
grainX: 60,
|
|
27
|
+
grainY: 31,
|
|
28
|
+
color0: 0x10451d,
|
|
29
|
+
color1: 0x4c956c,
|
|
30
|
+
color2: 0xd68c45,
|
|
31
|
+
color3: 0xf2e8cf,
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
describe("getProjectAvatarGenerated", () => {
|
|
38
|
+
test("keeps chosen and discovered icons", () => {
|
|
39
|
+
expect(getProjectAvatarGenerated({ id: "abc", icon: { override: "data:custom" } })).toBeUndefined()
|
|
40
|
+
expect(getProjectAvatarGenerated({ id: "abc", icon: { url: "data:auto" } })).toBeUndefined()
|
|
41
|
+
expect(getProjectAvatarGenerated({ id: "abc", icon: { color: "blue" } })).toBeUndefined()
|
|
42
|
+
const opencode = createHash("sha1").update("git-remote:github.com/anomalyco/opencode").digest("hex")
|
|
43
|
+
expect(getProjectAvatarGenerated({ id: opencode, worktree: "/repo" })).toBeUndefined()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
test("seeds by project ID or, for unidentified projects, by directory", () => {
|
|
47
|
+
expect(getProjectAvatarGenerated({ id: "abc", worktree: "/repo" })).toBe("abc")
|
|
48
|
+
expect(getProjectAvatarGenerated({ id: "global", worktree: "/scratch" })).toBe("/scratch")
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { PROJECT_ICON_STYLES } from "./procedural"
|
|
3
|
+
|
|
4
|
+
describe("procedural project icon styles", () => {
|
|
5
|
+
test.each(PROJECT_ICON_STYLES.map((style) => [style.id, style] as const))(
|
|
6
|
+
"%s resolves the same finite params from the same key",
|
|
7
|
+
(id, style) => {
|
|
8
|
+
const icon = style.generate("harbor-api")
|
|
9
|
+
|
|
10
|
+
expect(style.generate("harbor-api")).toEqual(icon)
|
|
11
|
+
expect(style.generate("basalt")).not.toEqual(icon)
|
|
12
|
+
expect(icon.style).toBe(id)
|
|
13
|
+
expect(Object.values(icon.params).every(Number.isFinite)).toBe(true)
|
|
14
|
+
},
|
|
15
|
+
)
|
|
16
|
+
})
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { For } from "solid-js"
|
|
2
|
+
import image from "../../assets/favicon/apple-touch-icon.png"
|
|
3
|
+
import { ProjectAvatar, PROJECT_AVATAR_VARIANTS, type ProjectAvatarProps } from "./project-avatar"
|
|
4
|
+
|
|
5
|
+
const docs = `### Overview
|
|
6
|
+
Saturated 16px project avatar with color variants and optional unread dot.
|
|
7
|
+
|
|
8
|
+
### API
|
|
9
|
+
- Required: \`fallback\` string.
|
|
10
|
+
- Optional: \`src\`, \`variant\`, \`unread\`, \`label\` and \`generated\` (a project seed).
|
|
11
|
+
|
|
12
|
+
### Variants
|
|
13
|
+
- Color: orange, yellow, cyan, green, red, pink, blue, purple, gray.
|
|
14
|
+
- Outline: neutral, muted style for de-emphasized projects (e.g. recently closed).
|
|
15
|
+
- Image vs initial content state.
|
|
16
|
+
- Unread dot with corner mask when \`unread\` is set.
|
|
17
|
+
- Switch the Avatars style to Generated in the panel to use the seed. An image or outline takes precedence.
|
|
18
|
+
|
|
19
|
+
### Theming
|
|
20
|
+
- Uses \`--v2-avatar-bg-*\` and \`--v2-avatar-border-*\` tokens with inset box-shadow borders.
|
|
21
|
+
`
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
title: "UI/ProjectAvatar",
|
|
25
|
+
id: "ui-project-avatar",
|
|
26
|
+
component: ProjectAvatar,
|
|
27
|
+
tags: ["autodocs"],
|
|
28
|
+
parameters: {
|
|
29
|
+
motion: ["projectAvatar.style"],
|
|
30
|
+
docs: {
|
|
31
|
+
description: {
|
|
32
|
+
component: docs,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
argTypes: {
|
|
37
|
+
variant: {
|
|
38
|
+
control: "select",
|
|
39
|
+
options: [...PROJECT_AVATAR_VARIANTS, "outline"],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
args: {
|
|
43
|
+
fallback: "O",
|
|
44
|
+
variant: "orange",
|
|
45
|
+
src: "",
|
|
46
|
+
generated: "opencode",
|
|
47
|
+
label: "",
|
|
48
|
+
unread: false,
|
|
49
|
+
} satisfies ProjectAvatarProps,
|
|
50
|
+
render: Preview,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function Preview(args: ProjectAvatarProps) {
|
|
54
|
+
return (
|
|
55
|
+
<ProjectAvatar
|
|
56
|
+
{...args}
|
|
57
|
+
classList={{
|
|
58
|
+
"[&_[data-slot=project-avatar-label]]:visible! [&_[data-slot=project-avatar-initial]]:invisible": !!args.label,
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export const Basic = {}
|
|
65
|
+
|
|
66
|
+
export const WithImage = {
|
|
67
|
+
args: {
|
|
68
|
+
src: image,
|
|
69
|
+
fallback: "O",
|
|
70
|
+
variant: "blue",
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const AllVariants = {
|
|
75
|
+
render: (args: ProjectAvatarProps) => (
|
|
76
|
+
<div style={{ display: "flex", gap: "16px", "align-items": "center" }}>
|
|
77
|
+
<For each={PROJECT_AVATAR_VARIANTS}>
|
|
78
|
+
{(variant) => <Preview {...args} fallback={variant[0].toUpperCase()} variant={variant} />}
|
|
79
|
+
</For>
|
|
80
|
+
</div>
|
|
81
|
+
),
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const Outline = {
|
|
85
|
+
args: {
|
|
86
|
+
fallback: "O",
|
|
87
|
+
variant: "outline",
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const Unread = {
|
|
92
|
+
args: {
|
|
93
|
+
fallback: "O",
|
|
94
|
+
variant: "orange",
|
|
95
|
+
unread: true,
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export const AllVariantsUnread = {
|
|
100
|
+
args: { unread: true },
|
|
101
|
+
render: AllVariants.render,
|
|
102
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createHash } from "crypto"
|
|
2
|
+
import { describe, expect, test } from "bun:test"
|
|
3
|
+
import { getProjectAvatarSource } from "./project-avatar"
|
|
4
|
+
|
|
5
|
+
describe("getProjectAvatarSource", () => {
|
|
6
|
+
test("prefers a chosen image, then a chosen color, then the automatic icon", () => {
|
|
7
|
+
expect(getProjectAvatarSource("abc", { override: "data:image/png;base64,AA==", url: "data:auto" })).toBe(
|
|
8
|
+
"data:image/png;base64,AA==",
|
|
9
|
+
)
|
|
10
|
+
expect(getProjectAvatarSource("abc", { color: "blue", url: "data:auto" })).toBeUndefined()
|
|
11
|
+
expect(getProjectAvatarSource("abc", { url: "data:auto" })).toBe("data:auto")
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test("recognizes the OpenCode repository by its remote-derived project ID", () => {
|
|
15
|
+
const id = createHash("sha1").update("git-remote:github.com/anomalyco/opencode").digest("hex")
|
|
16
|
+
|
|
17
|
+
expect(getProjectAvatarSource(id)).toBe("https://opencode.ai/favicon.svg")
|
|
18
|
+
expect(getProjectAvatarSource(id, { override: "data:custom" })).toBe("data:custom")
|
|
19
|
+
expect(getProjectAvatarSource(id, { color: "blue" })).toBeUndefined()
|
|
20
|
+
})
|
|
21
|
+
})
|