@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,48 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import * as mod from "./font"
|
|
3
|
+
|
|
4
|
+
const docs = `### Overview
|
|
5
|
+
Uses native system font stacks for sans and mono typography.
|
|
6
|
+
|
|
7
|
+
Optional compatibility component. Existing roots can keep rendering it, but it does nothing.
|
|
8
|
+
|
|
9
|
+
### API
|
|
10
|
+
- No props.
|
|
11
|
+
|
|
12
|
+
### Variants and states
|
|
13
|
+
- No variants.
|
|
14
|
+
|
|
15
|
+
### Behavior
|
|
16
|
+
- Compatibility wrapper only. No font assets are injected or preloaded.
|
|
17
|
+
|
|
18
|
+
### Accessibility
|
|
19
|
+
- Not applicable.
|
|
20
|
+
|
|
21
|
+
### Theming/tokens
|
|
22
|
+
- Theme tokens come from CSS variables, not this component.
|
|
23
|
+
|
|
24
|
+
`
|
|
25
|
+
|
|
26
|
+
export default {
|
|
27
|
+
title: "UI/Font",
|
|
28
|
+
id: "components-font",
|
|
29
|
+
component: mod.Font,
|
|
30
|
+
tags: ["autodocs"],
|
|
31
|
+
parameters: {
|
|
32
|
+
docs: {
|
|
33
|
+
description: {
|
|
34
|
+
component: docs,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const Basic = {
|
|
41
|
+
render: () => (
|
|
42
|
+
<div style={{ display: "grid", gap: "8px" }}>
|
|
43
|
+
<mod.Font />
|
|
44
|
+
<div style={{ "font-family": "var(--font-family-sans)" }}>OpenCode Sans Sample</div>
|
|
45
|
+
<div style={{ "font-family": "var(--font-family-mono)" }}>OpenCode Mono Sample</div>
|
|
46
|
+
</div>
|
|
47
|
+
),
|
|
48
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createEffect, createSignal } from "solid-js"
|
|
2
|
+
import { HoverCard, type HoverCardProps } from "./hover-card"
|
|
3
|
+
|
|
4
|
+
const docs = `### Overview
|
|
5
|
+
Hover-triggered card for lightweight previews and metadata.
|
|
6
|
+
|
|
7
|
+
Use for short summaries; avoid dense interactive controls.
|
|
8
|
+
|
|
9
|
+
### API
|
|
10
|
+
- Required: \`trigger\` element.
|
|
11
|
+
- Children render inside the hover card body.
|
|
12
|
+
|
|
13
|
+
### Variants and states
|
|
14
|
+
- None; content and trigger are fully composable.
|
|
15
|
+
|
|
16
|
+
### Behavior
|
|
17
|
+
- Opens on hover/focus over the trigger.
|
|
18
|
+
|
|
19
|
+
### Accessibility
|
|
20
|
+
- TODO: confirm focus and hover intent behavior from Kobalte.
|
|
21
|
+
|
|
22
|
+
### Theming/tokens
|
|
23
|
+
- Uses \`data-component="hover-card-content"\` and slots for styling.
|
|
24
|
+
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
export default {
|
|
28
|
+
title: "UI/HoverCard",
|
|
29
|
+
id: "components-hover-card",
|
|
30
|
+
component: HoverCard,
|
|
31
|
+
args: { open: false, placement: "bottom" },
|
|
32
|
+
argTypes: { placement: { control: "select", options: ["top", "right", "bottom", "left"] } },
|
|
33
|
+
tags: ["autodocs"],
|
|
34
|
+
parameters: {
|
|
35
|
+
docs: {
|
|
36
|
+
description: {
|
|
37
|
+
component: docs,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type CardArgs = Pick<HoverCardProps, "open" | "placement" | "mount"> & { inline?: boolean }
|
|
44
|
+
|
|
45
|
+
function Card(props: CardArgs) {
|
|
46
|
+
const [open, setOpen] = createSignal(props.open)
|
|
47
|
+
createEffect(() => setOpen(props.open))
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<HoverCard
|
|
51
|
+
open={open()}
|
|
52
|
+
onOpenChange={setOpen}
|
|
53
|
+
placement={props.placement}
|
|
54
|
+
mount={props.mount}
|
|
55
|
+
trigger={<span style={{ "text-decoration": "underline", cursor: "default" }}>Hover me</span>}
|
|
56
|
+
>
|
|
57
|
+
<div style={{ display: "grid", gap: "6px" }}>
|
|
58
|
+
<div style={{ "font-weight": 600 }}>{props.inline ? "Mounted inside" : "Preview"}</div>
|
|
59
|
+
<div style={{ color: "var(--text-weak)", "font-size": "12px" }}>
|
|
60
|
+
{props.inline ? "Uses custom mount node." : "Short supporting text."}
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</HoverCard>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const Basic = { render: Card }
|
|
68
|
+
|
|
69
|
+
export const InlineMount = {
|
|
70
|
+
render: (props: CardArgs) => {
|
|
71
|
+
const [mount, setMount] = createSignal<HTMLDivElement | undefined>(undefined)
|
|
72
|
+
|
|
73
|
+
return (
|
|
74
|
+
<div ref={setMount} style={{ padding: "16px", border: "1px dashed var(--border-weak)" }}>
|
|
75
|
+
<Card {...props} inline mount={mount()} />
|
|
76
|
+
</div>
|
|
77
|
+
)
|
|
78
|
+
},
|
|
79
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import type { FlightFrame } from "./image-flight"
|
|
3
|
+
import {
|
|
4
|
+
INITIAL_PREVIEW_FLIGHT_STATE,
|
|
5
|
+
selectFlightInteractive,
|
|
6
|
+
selectFlightStage,
|
|
7
|
+
selectVideoAtRest,
|
|
8
|
+
transitionPreviewFlight,
|
|
9
|
+
type PreviewFlightEffect,
|
|
10
|
+
type PreviewFlightEvent,
|
|
11
|
+
type PreviewFlightStage,
|
|
12
|
+
type PreviewFlightState,
|
|
13
|
+
} from "./image-flight-machine"
|
|
14
|
+
|
|
15
|
+
const box = { x: 10, y: 20, width: 80, height: 60 }
|
|
16
|
+
|
|
17
|
+
const origin: FlightFrame = { image: box, clip: box, radius: 6, surface: box, surfaceRadius: 6, lift: 0 }
|
|
18
|
+
|
|
19
|
+
type Replay = { state: PreviewFlightState; effects: readonly PreviewFlightEffect[]; stages: PreviewFlightStage[] }
|
|
20
|
+
|
|
21
|
+
function replay(events: PreviewFlightEvent[], from = INITIAL_PREVIEW_FLIGHT_STATE) {
|
|
22
|
+
return events.reduce<Replay>(
|
|
23
|
+
(result, event) => {
|
|
24
|
+
const next = transitionPreviewFlight(result.state, event)
|
|
25
|
+
|
|
26
|
+
return { state: next.state, effects: next.effects, stages: [...result.stages, selectFlightStage(next.state)] }
|
|
27
|
+
},
|
|
28
|
+
{ state: from, effects: [], stages: [] },
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const flyingOpen: PreviewFlightEvent[] = [{ type: "image.loaded" }, { type: "decode.ready", attempt: 1, origin }]
|
|
33
|
+
|
|
34
|
+
describe("image preview flight", () => {
|
|
35
|
+
test("opens by flying out of a visible origin and lands at rest", () => {
|
|
36
|
+
const opening = replay(flyingOpen)
|
|
37
|
+
|
|
38
|
+
expect(opening.state).toEqual({ status: "opening", mode: "flight", borrowed: false })
|
|
39
|
+
expect(opening.effects).toEqual([
|
|
40
|
+
{ type: "decode.cancel" },
|
|
41
|
+
{ type: "origin.hide" },
|
|
42
|
+
{ type: "open.flight", from: origin },
|
|
43
|
+
])
|
|
44
|
+
expect(opening.stages).toEqual(["pending", "flying"])
|
|
45
|
+
|
|
46
|
+
const open = transitionPreviewFlight(opening.state, { type: "motion.settled" })
|
|
47
|
+
expect(open.state).toEqual({ status: "open", originHidden: true, borrowed: false })
|
|
48
|
+
expect(selectFlightStage(open.state)).toBe("rest")
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test("opens by fading without an origin, and when the image fails to load", () => {
|
|
52
|
+
expect(replay([{ type: "image.loaded" }, { type: "decode.ready", attempt: 1, origin: undefined }]).effects).toEqual(
|
|
53
|
+
[{ type: "decode.cancel" }, { type: "open.fade" }],
|
|
54
|
+
)
|
|
55
|
+
const failed = replay([{ type: "image.failed" }])
|
|
56
|
+
expect(failed.state).toEqual({ status: "opening", mode: "fade", borrowed: false })
|
|
57
|
+
expect(failed.effects).toEqual([{ type: "open.fade" }])
|
|
58
|
+
expect(selectFlightStage(failed.state)).toBe("rest")
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// Bug: closing mid-flight once the origin scrolled away kept the opening flight running, left the origin hidden,
|
|
62
|
+
// and its landing flipped data-stage back to "rest" in the middle of the close.
|
|
63
|
+
test("a close mid-flight with the origin gone fades out, shows the origin and never returns to rest", () => {
|
|
64
|
+
const opening = replay(flyingOpen).state
|
|
65
|
+
const closing = replay([{ type: "close.started", origin: undefined }, { type: "motion.settled" }], opening)
|
|
66
|
+
|
|
67
|
+
expect(transitionPreviewFlight(opening, { type: "close.started", origin: undefined }).effects).toEqual([
|
|
68
|
+
{ type: "body.closing.acquire" },
|
|
69
|
+
{ type: "zoom.settle" },
|
|
70
|
+
{ type: "origin.show" },
|
|
71
|
+
{ type: "close.fade" },
|
|
72
|
+
])
|
|
73
|
+
expect(closing.stages).toEqual(["closing", "closing"])
|
|
74
|
+
expect(closing.state).toEqual({ status: "closed" })
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
// Bug: a fading close left data-stage at "rest", so a borrowed video kept taking clicks and the window keys and
|
|
78
|
+
// wheel stayed captured for the whole exit.
|
|
79
|
+
test("a fading close of a video stops taking input and hands the video back once it fades", () => {
|
|
80
|
+
const open = replay([{ type: "video.ready", origin }, { type: "motion.settled" }]).state
|
|
81
|
+
const closing = transitionPreviewFlight(open, { type: "close.started", origin: undefined })
|
|
82
|
+
|
|
83
|
+
expect(closing.effects).toEqual([
|
|
84
|
+
{ type: "body.closing.acquire" },
|
|
85
|
+
{ type: "zoom.fit" },
|
|
86
|
+
{ type: "origin.show" },
|
|
87
|
+
{ type: "close.fade" },
|
|
88
|
+
])
|
|
89
|
+
expect(selectFlightStage(closing.state)).toBe("closing")
|
|
90
|
+
expect(selectFlightInteractive(closing.state)).toBe(false)
|
|
91
|
+
expect(selectVideoAtRest(closing.state)).toBe(true)
|
|
92
|
+
expect(transitionPreviewFlight(closing.state, { type: "motion.settled" })).toEqual({
|
|
93
|
+
state: { status: "closed" },
|
|
94
|
+
effects: [{ type: "video.return" }],
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// Bug: reveal awaited decode with no claim, so a decode that settled after the image changed revealed it anyway.
|
|
99
|
+
test("a decode of an image that changed or loaded again is ignored", () => {
|
|
100
|
+
const reloaded = replay([{ type: "image.loaded" }, { type: "src.changed" }, { type: "image.loaded" }])
|
|
101
|
+
|
|
102
|
+
expect(reloaded.state).toEqual({ status: "decoding", attempt: 3 })
|
|
103
|
+
expect(reloaded.effects).toEqual([{ type: "decode.start", attempt: 3 }])
|
|
104
|
+
|
|
105
|
+
const stale = transitionPreviewFlight(reloaded.state, { type: "decode.ready", attempt: 1, origin })
|
|
106
|
+
expect(stale.state).toBe(reloaded.state)
|
|
107
|
+
expect(stale.effects).toEqual([])
|
|
108
|
+
expect(transitionPreviewFlight(reloaded.state, { type: "decode.ready", attempt: 3, origin }).state.status).toBe(
|
|
109
|
+
"opening",
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
const again = transitionPreviewFlight({ status: "decoding", attempt: 1 }, { type: "image.loaded" })
|
|
113
|
+
expect(again.effects).toEqual([{ type: "decode.cancel" }, { type: "decode.start", attempt: 2 }])
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
test("a close before the preview reveals ends it there, and a late decode is ignored", () => {
|
|
117
|
+
const closed = replay([{ type: "image.loaded" }, { type: "close.started", origin }])
|
|
118
|
+
|
|
119
|
+
expect(closed.state).toEqual({ status: "closed" })
|
|
120
|
+
expect(closed.effects).toEqual([{ type: "decode.cancel" }, { type: "body.closing.acquire" }])
|
|
121
|
+
expect(transitionPreviewFlight(closed.state, { type: "decode.ready", attempt: 1, origin }).state).toBe(closed.state)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test("a close mid-flight with the origin in sight turns the flight around, then veils the stand-in", () => {
|
|
125
|
+
const opening = replay(flyingOpen).state
|
|
126
|
+
const turned = transitionPreviewFlight(opening, { type: "close.started", origin })
|
|
127
|
+
|
|
128
|
+
expect(turned.effects).toEqual([
|
|
129
|
+
{ type: "body.closing.acquire" },
|
|
130
|
+
{ type: "zoom.settle" },
|
|
131
|
+
{ type: "close.flight", to: origin, turn: true },
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
const landed = transitionPreviewFlight(turned.state, { type: "motion.settled" })
|
|
135
|
+
expect(landed.state).toEqual({ status: "closing", mode: "veil", borrowed: false })
|
|
136
|
+
expect(landed.effects).toEqual([{ type: "origin.show" }, { type: "close.veil" }])
|
|
137
|
+
expect(selectFlightStage(landed.state)).toBe("flying")
|
|
138
|
+
expect(transitionPreviewFlight(landed.state, { type: "motion.settled" }).state).toEqual({ status: "closed" })
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test("a close from a fade-opened preview hides the origin and flies home from rest", () => {
|
|
142
|
+
const open = replay([{ type: "image.failed" }, { type: "motion.settled" }]).state
|
|
143
|
+
|
|
144
|
+
expect(transitionPreviewFlight(open, { type: "close.started", origin }).effects).toEqual([
|
|
145
|
+
{ type: "body.closing.acquire" },
|
|
146
|
+
{ type: "zoom.settle" },
|
|
147
|
+
{ type: "origin.hide" },
|
|
148
|
+
{ type: "close.flight", to: origin, turn: false },
|
|
149
|
+
])
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test("a video flying home is handed back as it lands", () => {
|
|
153
|
+
const open = replay([{ type: "video.ready", origin }, { type: "motion.settled" }]).state
|
|
154
|
+
const closing = transitionPreviewFlight(open, { type: "close.started", origin })
|
|
155
|
+
|
|
156
|
+
expect(closing.effects.at(-1)).toEqual({ type: "close.flight", to: origin, turn: false })
|
|
157
|
+
expect(transitionPreviewFlight(closing.state, { type: "motion.settled" })).toEqual({
|
|
158
|
+
state: { status: "closed" },
|
|
159
|
+
effects: [{ type: "origin.show" }, { type: "video.return" }],
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
// A throttled frame loop can let the dialog unmount before the close lands.
|
|
164
|
+
test("disposal tears down what each phase holds, once", () => {
|
|
165
|
+
const flying: PreviewFlightState = { status: "closing", mode: "flight", borrowed: true }
|
|
166
|
+
|
|
167
|
+
expect(transitionPreviewFlight(flying, { type: "disposed" }).effects).toEqual([
|
|
168
|
+
{ type: "loop.stop" },
|
|
169
|
+
{ type: "origin.show" },
|
|
170
|
+
{ type: "video.return" },
|
|
171
|
+
{ type: "body.closing.release" },
|
|
172
|
+
])
|
|
173
|
+
expect(transitionPreviewFlight({ status: "closed" }, { type: "disposed" }).effects).toEqual([
|
|
174
|
+
{ type: "body.closing.release" },
|
|
175
|
+
])
|
|
176
|
+
expect(transitionPreviewFlight({ status: "decoding", attempt: 2 }, { type: "disposed" }).effects).toEqual([
|
|
177
|
+
{ type: "decode.cancel" },
|
|
178
|
+
])
|
|
179
|
+
|
|
180
|
+
const disposed = transitionPreviewFlight(flying, { type: "disposed" }).state
|
|
181
|
+
expect(transitionPreviewFlight(disposed, { type: "motion.settled" }).state).toBe(disposed)
|
|
182
|
+
expect(transitionPreviewFlight(disposed, { type: "disposed" }).effects).toEqual([])
|
|
183
|
+
})
|
|
184
|
+
})
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { createFlight, elementFrame, fittedImage, flightStyle, KICK, type FlightFrame } from "./image-flight"
|
|
3
|
+
|
|
4
|
+
// A 1600×900 screenshot.
|
|
5
|
+
const natural = { width: 1600, height: 900 }
|
|
6
|
+
|
|
7
|
+
describe("fittedImage", () => {
|
|
8
|
+
test("covers a box of another shape, overflowing it evenly", () => {
|
|
9
|
+
// A 58×46 thumbnail is taller than 16:9, so the image fills its height and overflows its width.
|
|
10
|
+
expect(fittedImage({ x: 100, y: 200, width: 58, height: 46 }, natural, "cover")).toEqual({
|
|
11
|
+
x: 100 - (46 * (16 / 9) - 58) / 2,
|
|
12
|
+
y: 200,
|
|
13
|
+
width: 46 * (16 / 9),
|
|
14
|
+
height: 46,
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test("contains within a box, letterboxed evenly", () => {
|
|
19
|
+
expect(fittedImage({ x: 0, y: 0, width: 400, height: 400 }, natural, "contain")).toEqual({
|
|
20
|
+
x: 0,
|
|
21
|
+
y: 87.5,
|
|
22
|
+
width: 400,
|
|
23
|
+
height: 225,
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("matches the box when the shapes agree", () => {
|
|
28
|
+
const box = { x: 10, y: 20, width: 320, height: 180 }
|
|
29
|
+
|
|
30
|
+
expect(fittedImage(box, natural, "fill")).toEqual(box)
|
|
31
|
+
expect(fittedImage(box, natural, "contain")).toEqual(box)
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
describe("flightStyle", () => {
|
|
36
|
+
const base = { x: 200, y: 100, width: 800, height: 450 }
|
|
37
|
+
|
|
38
|
+
test("is the identity at the base frame", () => {
|
|
39
|
+
expect(flightStyle(base, { image: base, clip: base, radius: 6 })).toEqual({
|
|
40
|
+
transform: "translate(0px, 0px) scale(1)",
|
|
41
|
+
clipPath: "inset(0px 0px 0px 0px round 6px)",
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test("shrinks uniformly onto an uncropped thumbnail, keeping its on-screen radius", () => {
|
|
46
|
+
const thumbnail = { x: 40, y: 600, width: 320, height: 180 }
|
|
47
|
+
|
|
48
|
+
expect(flightStyle(base, { image: thumbnail, clip: thumbnail, radius: 6 })).toEqual({
|
|
49
|
+
transform: "translate(-160px, 500px) scale(0.4)",
|
|
50
|
+
clipPath: "inset(0px 0px 0px 0px round 15px)",
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test("crops to a cover thumbnail instead of squashing the image", () => {
|
|
55
|
+
const frame = elementFrame({ x: 100, y: 200, width: 40, height: 45 }, natural, "cover", 6)
|
|
56
|
+
const style = flightStyle(base, frame)
|
|
57
|
+
// The image is 80×45 on screen, half the base, and 20px of it hangs past each side of the box.
|
|
58
|
+
expect(frame.image).toEqual({ x: 80, y: 200, width: 80, height: 45 })
|
|
59
|
+
expect(style).toEqual({
|
|
60
|
+
transform: "translate(-120px, 100px) scale(0.1)",
|
|
61
|
+
clipPath: "inset(0px 200px 0px 200px round 60px)",
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test("clips a zoomed image to the viewport it is seen through", () => {
|
|
66
|
+
const image = { x: -200, y: -125, width: 1600, height: 900 }
|
|
67
|
+
const clip = { x: 0, y: 0, width: 1200, height: 650 }
|
|
68
|
+
|
|
69
|
+
expect(flightStyle(base, { image, clip, radius: 0 })).toEqual({
|
|
70
|
+
transform: "translate(-400px, -225px) scale(2)",
|
|
71
|
+
clipPath: "inset(62.5px 100px 62.5px 100px round 0px)",
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe("elementFrame", () => {
|
|
77
|
+
test("starts from the part the page shows, under a sticky bar, with the panel lying flat on it", () => {
|
|
78
|
+
const box = { x: 100, y: 20, width: 640, height: 360 }
|
|
79
|
+
const frame = elementFrame(box, natural, "fill", 4, { x: 0, y: 48, width: 1280, height: 752 })
|
|
80
|
+
|
|
81
|
+
expect(frame.image).toEqual(box)
|
|
82
|
+
expect(frame.clip).toEqual({ x: 100, y: 48, width: 640, height: 332 })
|
|
83
|
+
expect(frame.surface).toEqual(frame.clip)
|
|
84
|
+
expect(frame.surfaceRadius).toBe(4)
|
|
85
|
+
expect(frame.lift).toBe(0)
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
describe("createFlight", () => {
|
|
90
|
+
const box = (x: number, width: number) => ({ x, y: 100, width, height: width * 0.75 })
|
|
91
|
+
|
|
92
|
+
const frame = (x: number, width: number, radius: number, lift: number): FlightFrame => ({
|
|
93
|
+
image: box(x, width),
|
|
94
|
+
clip: box(x, width),
|
|
95
|
+
radius,
|
|
96
|
+
// On the page the panel is the image itself; open, it is a wider panel around it.
|
|
97
|
+
surface: lift ? { x: x - 120, y: 60, width: width + 240, height: width * 0.75 + 96 } : box(x, width),
|
|
98
|
+
surfaceRadius: lift ? 10 : radius,
|
|
99
|
+
lift,
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const thumbnail = frame(495, 285, 8, 0)
|
|
103
|
+
|
|
104
|
+
const preview = frame(314, 651, 6, 1)
|
|
105
|
+
|
|
106
|
+
const progress = (flight: ReturnType<typeof createFlight>) =>
|
|
107
|
+
(flight.frame().image.width - thumbnail.image.width) / (preview.image.width - thumbnail.image.width)
|
|
108
|
+
|
|
109
|
+
test("opens fast and settles without overshoot, like Claude's measured preview", () => {
|
|
110
|
+
const flight = createFlight(thumbnail)
|
|
111
|
+
flight.to(preview, KICK.open, { duration: 0.2, bounce: 0 })
|
|
112
|
+
const path = Array.from({ length: 30 }, () => (flight.step(1 / 60), progress(flight)))
|
|
113
|
+
|
|
114
|
+
// Measured at 0.2 s: 25% after one frame, 61% after three, 91% after seven.
|
|
115
|
+
expect(path[0]).toBeCloseTo(0.25, 1)
|
|
116
|
+
expect(path[2]).toBeCloseTo(0.61, 1)
|
|
117
|
+
expect(path[6]).toBeCloseTo(0.91, 1)
|
|
118
|
+
path.forEach((value) => expect(value).toBeLessThanOrEqual(1))
|
|
119
|
+
expect(flight.frame()).toEqual(preview)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test("grows the panel out of the image on the same flight, lifting it as it lands", () => {
|
|
123
|
+
const flight = createFlight(thumbnail)
|
|
124
|
+
flight.to(preview, KICK.open)
|
|
125
|
+
const path = Array.from({ length: 30 }, () => (flight.step(1 / 60), flight.frame()))
|
|
126
|
+
|
|
127
|
+
path.slice(1).forEach((frame, index) => {
|
|
128
|
+
expect(frame.lift).toBeGreaterThanOrEqual(path[index].lift)
|
|
129
|
+
expect(frame.surface.width).toBeGreaterThanOrEqual(path[index].surface.width)
|
|
130
|
+
})
|
|
131
|
+
// The lift keeps pace with the image's growth, so the shadow rises as the panel does.
|
|
132
|
+
path.forEach((frame) =>
|
|
133
|
+
expect(frame.lift).toBeCloseTo(
|
|
134
|
+
(frame.image.width - thumbnail.image.width) / (preview.image.width - thumbnail.image.width),
|
|
135
|
+
2,
|
|
136
|
+
),
|
|
137
|
+
)
|
|
138
|
+
expect(flight.frame()).toEqual(preview)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
test("keeps its launch shape on a slower spring, stretched in time", () => {
|
|
142
|
+
const snappy = createFlight(thumbnail)
|
|
143
|
+
const calm = createFlight(thumbnail)
|
|
144
|
+
snappy.to(preview, KICK.open)
|
|
145
|
+
calm.to(preview, KICK.open, { duration: 0.6, bounce: 0 })
|
|
146
|
+
snappy.step(1 / 60)
|
|
147
|
+
calm.step(2 / 60)
|
|
148
|
+
|
|
149
|
+
expect(progress(calm)).toBeCloseTo(progress(snappy), 5)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
test("turns around mid-flight from where it is, carrying its velocity", () => {
|
|
153
|
+
const flight = createFlight(thumbnail)
|
|
154
|
+
flight.to(preview, KICK.open)
|
|
155
|
+
Array.from({ length: 4 }, () => flight.step(1 / 60))
|
|
156
|
+
const turn = flight.frame()
|
|
157
|
+
flight.to(thumbnail, KICK.close)
|
|
158
|
+
|
|
159
|
+
expect(flight.frame()).toEqual(turn)
|
|
160
|
+
|
|
161
|
+
// A fresh close launched from the same frame, at rest, moves further on its first frame than the reversed flight,
|
|
162
|
+
// which first has to cancel the outward velocity it still carries.
|
|
163
|
+
const fresh = createFlight(turn)
|
|
164
|
+
fresh.to(thumbnail, KICK.close)
|
|
165
|
+
flight.step(1 / 60)
|
|
166
|
+
fresh.step(1 / 60)
|
|
167
|
+
expect(turn.image.width - flight.frame().image.width).toBeGreaterThan(0)
|
|
168
|
+
expect(turn.image.width - flight.frame().image.width).toBeLessThan(turn.image.width - fresh.frame().image.width)
|
|
169
|
+
|
|
170
|
+
while (flight.step(1 / 60));
|
|
171
|
+
expect(flight.frame()).toEqual(thumbnail)
|
|
172
|
+
})
|
|
173
|
+
})
|