@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,263 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import {
|
|
3
|
+
createListState,
|
|
4
|
+
listActive,
|
|
5
|
+
listScrollTarget,
|
|
6
|
+
selectListEmptyState,
|
|
7
|
+
transitionList,
|
|
8
|
+
type ListEffect,
|
|
9
|
+
type ListEvent,
|
|
10
|
+
type ListKeyDown,
|
|
11
|
+
type ListState,
|
|
12
|
+
} from "./list-machine"
|
|
13
|
+
|
|
14
|
+
const items = ["Alpha", "Beta", "Gamma"]
|
|
15
|
+
|
|
16
|
+
const config = { key: (item: string) => item }
|
|
17
|
+
|
|
18
|
+
function run(state: ListState<string>, ...events: ListEvent<string>[]) {
|
|
19
|
+
return events.reduce<{ state: ListState<string>; effects: ListEffect<string>[]; handled: boolean }>(
|
|
20
|
+
(result, event) => transitionList(result.state, event, config),
|
|
21
|
+
{ state, effects: [], handled: false },
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Answers the load a transition asked for, as the driver does for a synchronous `items` list.
|
|
26
|
+
function settle(result: { state: ListState<string>; effects: ListEffect<string>[] }) {
|
|
27
|
+
const load = result.effects.find((effect) => effect.type === "load")
|
|
28
|
+
|
|
29
|
+
if (!load) return result.state
|
|
30
|
+
const matches = items.filter((item) => item.toLowerCase().includes(load.query.toLowerCase()))
|
|
31
|
+
|
|
32
|
+
return transitionList(result.state, { type: "load.resolved", attempt: load.attempt, items: matches }, config).state
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function loaded(filter?: string) {
|
|
36
|
+
return settle(run(createListState<string>(filter), { type: "items.reload" }))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function key(key: string, input: Partial<Omit<ListKeyDown, "type" | "key">> = {}): ListKeyDown {
|
|
40
|
+
return {
|
|
41
|
+
type: "key.down",
|
|
42
|
+
key,
|
|
43
|
+
ctrl: false,
|
|
44
|
+
alt: false,
|
|
45
|
+
meta: false,
|
|
46
|
+
shift: false,
|
|
47
|
+
composing: false,
|
|
48
|
+
search: false,
|
|
49
|
+
claimed: false,
|
|
50
|
+
...input,
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
test("the clear button shows every row again and tells the parent", () => {
|
|
55
|
+
const typed = settle(run(loaded(), { type: "query.change", value: "al" }))
|
|
56
|
+
expect(typed.rows).toEqual(["Alpha"])
|
|
57
|
+
|
|
58
|
+
const cleared = run(typed, { type: "query.change", value: "" })
|
|
59
|
+
expect(cleared.effects).toEqual([
|
|
60
|
+
{ type: "notify.filter", value: "" },
|
|
61
|
+
{ type: "load", attempt: 3, query: "" },
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
const state = settle(cleared)
|
|
65
|
+
expect(state.filter).toEqual({ type: "uncontrolled", query: "" })
|
|
66
|
+
expect(state.rows).toEqual(items)
|
|
67
|
+
expect(state.highlight.activeKey).toBe("Alpha")
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
test("a controlled list clears when the parent accepts and keeps rows and query together when it does not", () => {
|
|
71
|
+
const start = loaded("al")
|
|
72
|
+
expect(start.rows).toEqual(["Alpha"])
|
|
73
|
+
|
|
74
|
+
const cleared = run(start, { type: "query.change", value: "" })
|
|
75
|
+
expect(cleared.effects).toEqual([{ type: "notify.filter", value: "" }])
|
|
76
|
+
expect(cleared.state).toBe(start)
|
|
77
|
+
|
|
78
|
+
const accepted = run(cleared.state, { type: "filter.controlled", value: "" })
|
|
79
|
+
expect(accepted.effects).toEqual([{ type: "load", attempt: 2, query: "" }])
|
|
80
|
+
expect(settle(accepted).rows).toEqual(items)
|
|
81
|
+
expect(settle(accepted).filter).toEqual({ type: "controlled", query: "" })
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
test("a forced change reloads an unchanged query once", () => {
|
|
85
|
+
const start = loaded()
|
|
86
|
+
|
|
87
|
+
expect(run(start, { type: "query.change", value: "" }).effects).toEqual([])
|
|
88
|
+
expect(run(start, { type: "query.change", value: "", force: true }).effects).toEqual([
|
|
89
|
+
{ type: "notify.filter", value: "" },
|
|
90
|
+
{ type: "load", attempt: 2, query: "" },
|
|
91
|
+
])
|
|
92
|
+
expect(run(loaded("al"), { type: "query.change", value: "al", force: true }).effects).toEqual([
|
|
93
|
+
{ type: "notify.filter", value: "al" },
|
|
94
|
+
{ type: "load", attempt: 2, query: "al" },
|
|
95
|
+
])
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test("switching between controlled and uncontrolled keeps the query and reloads only on a new one", () => {
|
|
99
|
+
const start = loaded()
|
|
100
|
+
const adopted = run(start, { type: "filter.controlled", value: "" })
|
|
101
|
+
expect(adopted.effects).toEqual([])
|
|
102
|
+
expect(adopted.state.filter).toEqual({ type: "controlled", query: "" })
|
|
103
|
+
|
|
104
|
+
expect(run(adopted.state, { type: "filter.uncontrolled" }).state.filter).toEqual({ type: "uncontrolled", query: "" })
|
|
105
|
+
expect(run(start, { type: "filter.controlled", value: "be" }).effects).toEqual([
|
|
106
|
+
{ type: "load", attempt: 2, query: "be" },
|
|
107
|
+
])
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test("a superseded or late load result is ignored", () => {
|
|
111
|
+
const first = run(loaded(), { type: "query.change", value: "a" })
|
|
112
|
+
const second = run(first.state, { type: "query.change", value: "al" })
|
|
113
|
+
const stale = transitionList(second.state, { type: "load.resolved", attempt: 2, items }, config)
|
|
114
|
+
expect(stale.state).toBe(second.state)
|
|
115
|
+
|
|
116
|
+
const ready = transitionList(second.state, { type: "load.resolved", attempt: 3, items }, config).state
|
|
117
|
+
expect(ready).toMatchObject({ status: "ready", epoch: 3, rows: ["Alpha"] })
|
|
118
|
+
expect(transitionList(ready, { type: "load.failed", attempt: 3 }, config).state).toBe(ready)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
test("a rejected load reports a failure, not an empty result, and a reload or new query recovers", () => {
|
|
122
|
+
// `load.failed` used to settle as `ready` with no rows, so the list said "No results" for a server error.
|
|
123
|
+
const loading = run(loaded(), { type: "items.reload" })
|
|
124
|
+
const failed = transitionList(loading.state, { type: "load.failed", attempt: 2 }, config)
|
|
125
|
+
expect(failed.state).toMatchObject({ status: "failed", epoch: 2, rows: [], highlight: { activeKey: null } })
|
|
126
|
+
expect(failed.effects).toEqual([{ type: "cancel.load" }])
|
|
127
|
+
expect(selectListEmptyState(failed.state)).toEqual({ type: "failed" })
|
|
128
|
+
|
|
129
|
+
const empty = transitionList(loading.state, { type: "load.resolved", attempt: 2, items: [] }, config).state
|
|
130
|
+
expect(selectListEmptyState(empty)).toEqual({ type: "empty", query: "" })
|
|
131
|
+
|
|
132
|
+
expect(run(failed.state, { type: "items.reload" }).effects).toEqual([{ type: "load", attempt: 3, query: "" }])
|
|
133
|
+
expect(settle(run(failed.state, { type: "items.reload" }))).toMatchObject({ status: "ready", rows: items })
|
|
134
|
+
expect(settle(run(failed.state, { type: "query.change", value: "be" }))).toMatchObject({
|
|
135
|
+
status: "ready",
|
|
136
|
+
rows: ["Beta"],
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test("a load that never settles times out into a failure", () => {
|
|
141
|
+
const typed = run(loaded(), { type: "query.change", value: "al" })
|
|
142
|
+
expect(selectListEmptyState(typed.state)).toEqual({ type: "loading" })
|
|
143
|
+
|
|
144
|
+
const timedOut = transitionList(typed.state, { type: "load.timed-out", attempt: 2 }, config)
|
|
145
|
+
expect(timedOut.state).toMatchObject({ status: "failed", epoch: 2, rows: [] })
|
|
146
|
+
expect(timedOut.effects).toEqual([{ type: "cancel.load" }])
|
|
147
|
+
|
|
148
|
+
// A superseded attempt's timeout does not fail the attempt that replaced it.
|
|
149
|
+
const retyped = run(typed.state, { type: "query.change", value: "alp" }).state
|
|
150
|
+
expect(transitionList(retyped, { type: "load.timed-out", attempt: 2 }, config).state).toBe(retyped)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
test("a slow search that timed out still shows its results, unless a newer attempt started", () => {
|
|
154
|
+
const timedOut = transitionList(
|
|
155
|
+
run(loaded(), { type: "query.change", value: "al" }).state,
|
|
156
|
+
{ type: "load.timed-out", attempt: 2 },
|
|
157
|
+
config,
|
|
158
|
+
).state
|
|
159
|
+
|
|
160
|
+
const late = transitionList(timedOut, { type: "load.resolved", attempt: 2, items }, config)
|
|
161
|
+
expect(late.state).toMatchObject({ status: "ready", epoch: 2, rows: ["Alpha"], highlight: { activeKey: "Alpha" } })
|
|
162
|
+
expect(late.effects).toEqual([])
|
|
163
|
+
expect(transitionList(timedOut, { type: "load.failed", attempt: 2 }, config).state).toBe(timedOut)
|
|
164
|
+
expect(transitionList(timedOut, { type: "load.resolved", attempt: 1, items }, config).state).toBe(timedOut)
|
|
165
|
+
|
|
166
|
+
const reloading = run(timedOut, { type: "items.reload" }).state
|
|
167
|
+
expect(transitionList(reloading, { type: "load.resolved", attempt: 2, items }, config).state).toBe(reloading)
|
|
168
|
+
|
|
169
|
+
const reloaded = settle(run(timedOut, { type: "items.reload" }))
|
|
170
|
+
expect(transitionList(reloaded, { type: "load.resolved", attempt: 2, items }, config).state).toBe(reloaded)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test("disposing stops an in-flight load and ignores every later event", () => {
|
|
174
|
+
const loading = run(loaded(), { type: "items.reload" }).state
|
|
175
|
+
const disposed = transitionList(loading, { type: "disposed" }, config)
|
|
176
|
+
expect(disposed.state.status).toBe("disposed")
|
|
177
|
+
expect(disposed.effects).toEqual([{ type: "cancel.load" }])
|
|
178
|
+
expect(transitionList(loaded(), { type: "disposed" }, config).effects).toEqual([])
|
|
179
|
+
|
|
180
|
+
for (const event of [
|
|
181
|
+
{ type: "load.resolved", attempt: 2, items },
|
|
182
|
+
{ type: "load.failed", attempt: 2 },
|
|
183
|
+
{ type: "query.change", value: "be" },
|
|
184
|
+
{ type: "items.reload" },
|
|
185
|
+
key("ArrowDown"),
|
|
186
|
+
] satisfies ListEvent<string>[])
|
|
187
|
+
expect(transitionList(disposed.state, event, config)).toMatchObject({ state: disposed.state, effects: [] })
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
test("the pointer takes the highlight without scrolling and any key gives it back", () => {
|
|
191
|
+
const start = loaded()
|
|
192
|
+
expect(run(start, { type: "pointer.move", key: "Beta", moved: false }).state).toBe(start)
|
|
193
|
+
|
|
194
|
+
const hovered = run(start, { type: "pointer.move", key: "Beta", moved: true }).state
|
|
195
|
+
expect(hovered.highlight).toEqual({ mode: "mouse", activeKey: "Beta" })
|
|
196
|
+
expect(listScrollTarget(hovered)).toEqual({ type: "none" })
|
|
197
|
+
|
|
198
|
+
const left = run(hovered, { type: "pointer.leave" }).state
|
|
199
|
+
expect(left.highlight).toEqual({ mode: "mouse", activeKey: null })
|
|
200
|
+
expect(run(start, { type: "pointer.leave" }).state).toBe(start)
|
|
201
|
+
|
|
202
|
+
const typed = run(hovered, key("Escape", { claimed: true }))
|
|
203
|
+
expect(typed.handled).toBe(false)
|
|
204
|
+
expect(typed.state.highlight).toEqual({ mode: "keyboard", activeKey: "Beta" })
|
|
205
|
+
expect(listScrollTarget(typed.state)).toEqual({ type: "item", key: "Beta" })
|
|
206
|
+
})
|
|
207
|
+
|
|
208
|
+
test.each<{ name: string; events: ListKeyDown[]; active: string | null; handled: boolean }>([
|
|
209
|
+
{ name: "ArrowDown moves to the next row", events: [key("ArrowDown")], active: "Beta", handled: true },
|
|
210
|
+
{ name: "ArrowUp wraps to the last row", events: [key("ArrowUp")], active: "Gamma", handled: true },
|
|
211
|
+
{
|
|
212
|
+
name: "Ctrl+N and Ctrl+P move like arrows",
|
|
213
|
+
events: [key("n", { ctrl: true }), key("n", { ctrl: true }), key("p", { ctrl: true })],
|
|
214
|
+
active: "Beta",
|
|
215
|
+
handled: true,
|
|
216
|
+
},
|
|
217
|
+
{ name: "ArrowDown wraps to the first row", events: [key("End"), key("ArrowDown")], active: "Alpha", handled: true },
|
|
218
|
+
{
|
|
219
|
+
name: "Option+Arrow is left to text editing",
|
|
220
|
+
events: [key("ArrowDown", { alt: true })],
|
|
221
|
+
active: "Alpha",
|
|
222
|
+
handled: false,
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
name: "Cmd+Arrow is left to text editing",
|
|
226
|
+
events: [key("ArrowDown", { meta: true })],
|
|
227
|
+
active: "Alpha",
|
|
228
|
+
handled: false,
|
|
229
|
+
},
|
|
230
|
+
{ name: "End jumps to the last row", events: [key("End")], active: "Gamma", handled: true },
|
|
231
|
+
{ name: "a search input keeps End", events: [key("End", { search: true })], active: "Alpha", handled: false },
|
|
232
|
+
{ name: "Tab moves to the next row", events: [key("Tab")], active: "Beta", handled: true },
|
|
233
|
+
{
|
|
234
|
+
name: "Shift+Tab on the first row leaves focus to the browser",
|
|
235
|
+
events: [key("Tab", { shift: true })],
|
|
236
|
+
active: "Alpha",
|
|
237
|
+
handled: false,
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
name: "a claimed key does not move",
|
|
241
|
+
events: [key("ArrowDown", { claimed: true })],
|
|
242
|
+
active: "Alpha",
|
|
243
|
+
handled: false,
|
|
244
|
+
},
|
|
245
|
+
])("$name", (input) => {
|
|
246
|
+
const result = run(loaded(), ...input.events)
|
|
247
|
+
expect(result.state.highlight.activeKey).toBe(input.active)
|
|
248
|
+
expect(result.handled).toBe(input.handled)
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
test("Enter selects the highlighted row and is handled even with none", () => {
|
|
252
|
+
const start = run(loaded(), key("ArrowDown")).state
|
|
253
|
+
expect(listActive(start)).toEqual({ item: "Beta", index: 1 })
|
|
254
|
+
expect(run(start, key("Enter"))).toMatchObject({
|
|
255
|
+
handled: true,
|
|
256
|
+
effects: [{ type: "select", item: "Beta", index: 1 }],
|
|
257
|
+
})
|
|
258
|
+
expect(run(start, key("Enter", { composing: true })).handled).toBe(false)
|
|
259
|
+
|
|
260
|
+
const empty = run(start, { type: "active.set", key: "" })
|
|
261
|
+
expect(empty.state.highlight.activeKey).toBeNull()
|
|
262
|
+
expect(run(empty.state, key("Enter"))).toMatchObject({ handled: true, effects: [] })
|
|
263
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { pinSpinPhase } from "./spin-phase"
|
|
3
|
+
|
|
4
|
+
test("pins only running infinite loops to the timeline origin without touching already-pinned or paused ones", () => {
|
|
5
|
+
let timingCalls = 0
|
|
6
|
+
|
|
7
|
+
const animation = (iterations: number, startTime: number, playState?: AnimationPlayState) => ({
|
|
8
|
+
startTime,
|
|
9
|
+
playState,
|
|
10
|
+
effect: {
|
|
11
|
+
getTiming: () => {
|
|
12
|
+
timingCalls++
|
|
13
|
+
|
|
14
|
+
return { iterations }
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
const loops = [animation(Infinity, 1234, "running"), animation(Infinity, 87, "running")]
|
|
20
|
+
const alreadyPinned = animation(Infinity, 0, "running")
|
|
21
|
+
const paused = animation(Infinity, 500, "paused")
|
|
22
|
+
const fade = animation(1, 1234, "running")
|
|
23
|
+
|
|
24
|
+
pinSpinPhase({ getAnimations: () => [...loops, alreadyPinned, paused, fade] })
|
|
25
|
+
|
|
26
|
+
expect(loops.map((loop) => loop.startTime)).toEqual([0, 0])
|
|
27
|
+
expect(alreadyPinned.startTime).toBe(0)
|
|
28
|
+
expect(paused.startTime).toBe(500)
|
|
29
|
+
expect(fade.startTime).toBe(1234)
|
|
30
|
+
// Already-pinned and paused animations short-circuit before calling getTiming().
|
|
31
|
+
expect(timingCalls).toBe(3)
|
|
32
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { groupItems } from "./use-filtered-list"
|
|
3
|
+
|
|
4
|
+
test("groups under one empty category without a groupBy", () => {
|
|
5
|
+
expect(groupItems(["b", "a"], {})).toEqual([{ category: "", items: ["b", "a"] }])
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
test("keeps item order within a group and first-seen order between groups", () => {
|
|
9
|
+
const items = [
|
|
10
|
+
{ name: "x1", group: "x" },
|
|
11
|
+
{ name: "y1", group: "y" },
|
|
12
|
+
{ name: "x2", group: "x" },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
expect(groupItems(items, { groupBy: (item) => item.group }).map((g) => [g.category, g.items.map((i) => i.name)])).toEqual([
|
|
16
|
+
["x", ["x1", "x2"]],
|
|
17
|
+
["y", ["y1"]],
|
|
18
|
+
])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test("lists numeric-looking categories first, as object keys do", () => {
|
|
22
|
+
expect(groupItems(["b", "10", "a", "2"], { groupBy: (item) => item }).map((g) => g.category)).toEqual([
|
|
23
|
+
"2",
|
|
24
|
+
"10",
|
|
25
|
+
"b",
|
|
26
|
+
"a",
|
|
27
|
+
])
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test("sorts items within groups and then the groups", () => {
|
|
31
|
+
const groups = groupItems([3, 1, 4, 2], {
|
|
32
|
+
groupBy: (n) => (n % 2 ? "odd" : "even"),
|
|
33
|
+
sortBy: (a, b) => a - b,
|
|
34
|
+
sortGroupsBy: (a, b) => a.category.localeCompare(b.category),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
expect(groups).toEqual([
|
|
38
|
+
{ category: "even", items: [2, 4] },
|
|
39
|
+
{ category: "odd", items: [1, 3] },
|
|
40
|
+
])
|
|
41
|
+
})
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { For, onCleanup } from "solid-js"
|
|
2
|
+
import { artworkNames } from "../catalog"
|
|
3
|
+
import { registerIcons } from "../registry"
|
|
4
|
+
import { Icon, type IconProps } from "./icon"
|
|
5
|
+
|
|
6
|
+
const names = artworkNames().sort()
|
|
7
|
+
|
|
8
|
+
const sizes = ["small", "normal", "large"] satisfies IconProps["size"][]
|
|
9
|
+
|
|
10
|
+
type Args = Pick<IconProps, "name" | "size">
|
|
11
|
+
|
|
12
|
+
function Preview(args: Args) {
|
|
13
|
+
return <Icon name={args.name} size={args.size} />
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
title: "UI/Icon",
|
|
18
|
+
id: "ui-icon",
|
|
19
|
+
component: Icon,
|
|
20
|
+
parameters: {
|
|
21
|
+
gridPreview: () => (
|
|
22
|
+
<div class="grid grid-cols-4 gap-4">
|
|
23
|
+
<For each={names.slice(0, 16)}>{(name) => <Icon name={name} />}</For>
|
|
24
|
+
</div>
|
|
25
|
+
),
|
|
26
|
+
},
|
|
27
|
+
tags: ["autodocs"],
|
|
28
|
+
args: {
|
|
29
|
+
name: "check",
|
|
30
|
+
size: "normal",
|
|
31
|
+
},
|
|
32
|
+
argTypes: {
|
|
33
|
+
name: { control: "select", options: names },
|
|
34
|
+
size: { control: "select", options: sizes },
|
|
35
|
+
},
|
|
36
|
+
render: Preview,
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const Gallery = {
|
|
40
|
+
render: (args: Pick<IconProps, "size">) => (
|
|
41
|
+
<div data-scrollable class="max-h-[70dvh] w-full max-w-lg overflow-auto">
|
|
42
|
+
<table class="w-full table-fixed text-start text-v2-text-text-base">
|
|
43
|
+
<caption class="pb-3 text-start font-medium">Desktop icon catalog · {names.length}</caption>
|
|
44
|
+
<tbody>
|
|
45
|
+
<For each={names}>
|
|
46
|
+
{(name) => (
|
|
47
|
+
<tr class="border-b border-v2-border-border-base">
|
|
48
|
+
<th scope="row" class="w-3/4 py-2 text-start font-normal">
|
|
49
|
+
<bdi dir="ltr">{name}</bdi>
|
|
50
|
+
</th>
|
|
51
|
+
<td class="text-center">
|
|
52
|
+
<Icon class="inline-block" name={name} size={args.size} />
|
|
53
|
+
</td>
|
|
54
|
+
</tr>
|
|
55
|
+
)}
|
|
56
|
+
</For>
|
|
57
|
+
</tbody>
|
|
58
|
+
</table>
|
|
59
|
+
</div>
|
|
60
|
+
),
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const Playground = {}
|
|
64
|
+
|
|
65
|
+
export const Sizes = {
|
|
66
|
+
render: (args: Args) => (
|
|
67
|
+
<div style={{ display: "flex", gap: "12px", "align-items": "center" }}>
|
|
68
|
+
<For each={sizes}>{(size) => <Preview {...args} size={size} />}</For>
|
|
69
|
+
</div>
|
|
70
|
+
),
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Artwork outside the catalog, as a plugin declares it: one still drawing, and one that moves from its resting frame.
|
|
74
|
+
const registered = {
|
|
75
|
+
"story:pair": `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
|
|
76
|
+
<path d="M2.5 9V2.5H13.5V3.5M2.5 9L0.5 12.5H7.5M2.5 9H7.5" stroke="currentColor" stroke-linecap="square" stroke-linejoin="round"/>
|
|
77
|
+
<path d="M11.5 12.5H13.5M9.5 5.5V14.5H15.5V5.5H9.5Z" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round"/>
|
|
78
|
+
</svg>`,
|
|
79
|
+
"story:pulse": `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
|
|
80
|
+
<circle cx="8" cy="8" r="6.5" stroke="currentColor"/>
|
|
81
|
+
<circle cx="8" cy="8" r="2" fill="currentColor">
|
|
82
|
+
<animate attributeName="r" values="2;2;5.6;5.6" keyTimes="0;0.167;0.917;1" dur="2.4s" repeatCount="indefinite"/>
|
|
83
|
+
<animate attributeName="opacity" values="1;1;0;0" keyTimes="0;0.167;0.917;1" dur="2.4s" repeatCount="indefinite"/>
|
|
84
|
+
</circle>
|
|
85
|
+
<circle cx="8" cy="8" r="2" fill="currentColor">
|
|
86
|
+
<animate attributeName="r" values="2;2;0;0;2;2" keyTimes="0;0.166;0.167;0.333;0.75;1" dur="2.4s" repeatCount="indefinite"/>
|
|
87
|
+
</circle>
|
|
88
|
+
</svg>`,
|
|
89
|
+
} as const
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Registered artwork draws by name like a catalog icon: in each size, in the text color, and in step where it moves.
|
|
93
|
+
* `story:missing` is not registered, so it draws nothing and keeps its box.
|
|
94
|
+
*/
|
|
95
|
+
export const Registered = {
|
|
96
|
+
render: () => {
|
|
97
|
+
onCleanup(registerIcons(registered))
|
|
98
|
+
|
|
99
|
+
return (
|
|
100
|
+
<div style={{ display: "grid", gap: "12px" }}>
|
|
101
|
+
<For each={["story:pair", "story:pulse", "story:missing"]}>
|
|
102
|
+
{(name) => (
|
|
103
|
+
<div style={{ display: "flex", gap: "12px", "align-items": "center" }}>
|
|
104
|
+
<For each={sizes}>{(size) => <Icon name={name} size={size} />}</For>
|
|
105
|
+
<Icon name={name} class="text-v2-state-fg-success" />
|
|
106
|
+
<Icon name={name} class="text-v2-state-fg-warning" />
|
|
107
|
+
<Icon name={name} style={{ outline: "1px dashed currentColor" }} />
|
|
108
|
+
<bdi dir="ltr">{name}</bdi>
|
|
109
|
+
</div>
|
|
110
|
+
)}
|
|
111
|
+
</For>
|
|
112
|
+
</div>
|
|
113
|
+
)
|
|
114
|
+
},
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export const Directional = {
|
|
118
|
+
args: { name: "arrow-left" },
|
|
119
|
+
render: (args: Args) => (
|
|
120
|
+
<div style={{ display: "grid", gap: "12px" }}>
|
|
121
|
+
<div dir="ltr" style={{ display: "flex", gap: "8px" }}>
|
|
122
|
+
<Preview {...args} />
|
|
123
|
+
<Preview {...args} name="arrow-right" />
|
|
124
|
+
</div>
|
|
125
|
+
<div dir="rtl" style={{ display: "flex", gap: "8px" }}>
|
|
126
|
+
<Preview {...args} />
|
|
127
|
+
<Preview {...args} name="arrow-right" />
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
),
|
|
131
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Divider } from "./divider"
|
|
2
|
+
|
|
3
|
+
const docs = `### Overview
|
|
4
|
+
Horizontal hairline divider for v2 layouts.
|
|
5
|
+
|
|
6
|
+
### API
|
|
7
|
+
- Inherits native div attributes.
|
|
8
|
+
- Stretches to full width of its flex parent.
|
|
9
|
+
|
|
10
|
+
### Theming/tokens
|
|
11
|
+
- Uses \`data-component="divider-v2"\`.
|
|
12
|
+
- Border color: \`--v2-border-border-strong\`.
|
|
13
|
+
`
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
title: "UI/Divider",
|
|
17
|
+
id: "ui-divider",
|
|
18
|
+
component: Divider,
|
|
19
|
+
tags: ["autodocs"],
|
|
20
|
+
parameters: {
|
|
21
|
+
frameWidth: "320px",
|
|
22
|
+
docs: {
|
|
23
|
+
description: {
|
|
24
|
+
component: docs,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const Basic = {
|
|
31
|
+
render: () => (
|
|
32
|
+
<div style={{ display: "flex", "flex-direction": "column", gap: "16px", padding: "16px" }}>
|
|
33
|
+
<span>Above</span>
|
|
34
|
+
<Divider />
|
|
35
|
+
<span>Below</span>
|
|
36
|
+
</div>
|
|
37
|
+
),
|
|
38
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# Motion
|
|
2
|
+
|
|
3
|
+
Springs, a shared frame loop and DOM animation controllers for the UI packages.
|
|
4
|
+
|
|
5
|
+
- `@zyro-sec/ui/motion`: physics and DOM controllers. No Solid imports.
|
|
6
|
+
- `@zyro-sec/ui/motion/solid`: Solid primitives (`springStyle`, `slidingHighlight`, `widthMorph`, `numberTween`).
|
|
7
|
+
|
|
8
|
+
## Provenance
|
|
9
|
+
|
|
10
|
+
Vendored from Kit Langton's `@problems/motion` (`team-board` repo, `packages/motion`, commit `873f5d5`). Behaviour is unchanged. The port applies this repo's formatting and lint rules, removes `else` branches, and moves tests to Bun: pure tests in `core.test.ts`, DOM and Solid tests in `packages/app/test-browser/motion-dom.test.ts` (happy-dom with Solid's browser build). The playground and the SwiftUI comparison script were not carried over. To re-sync, diff the upstream package against `873f5d5` and apply the changes here.
|
|
11
|
+
|
|
12
|
+
Hot paths deliberately use indexed `for` loops, an intrusive linked list with lazy compaction, numeric field initializers (avoiding V8 `undefined` → `Double` field representation transitions), and a `Float64Array`-cached closed-form damped-harmonic transition matrix, so the frame loop and `Spring.step` allocate nothing per frame. In headless Chromium, 1,000 `springStyle` values with a non-allocating paint callback allocate ~0 bytes/frame during rAF steps (~8.5 KB/frame averaged across 250 ms Solid target updates, and ~58 KB/frame when formatting 1,000 CSS `translate3d(...)` strings).
|
|
13
|
+
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// Unit-mass spring, integrated with an exact closed-form damped-harmonic step.
|
|
18
|
+
class Spring {
|
|
19
|
+
constructor(value: number, options?: { omega?: number; zeta?: number }) // defaults omega 26, zeta 0.86
|
|
20
|
+
static fromDuration(value: number, options: { duration: number; bounce: number }): Spring // SwiftUI parameters
|
|
21
|
+
value: number
|
|
22
|
+
target: number
|
|
23
|
+
velocity: number
|
|
24
|
+
set(target: number, options?: { velocity?: number }): this
|
|
25
|
+
snap(value: number): this
|
|
26
|
+
step(dt: number): number // seconds; clamps dt to 0.1; returns value
|
|
27
|
+
readonly resting: boolean
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// One shared requestAnimationFrame loop. A job returns true while it still needs frames.
|
|
31
|
+
const frameLoop: {
|
|
32
|
+
add(job: (dt: number) => boolean): () => void
|
|
33
|
+
addMeasured(read: () => void, write: (dt: number) => boolean): () => void
|
|
34
|
+
}
|
|
35
|
+
function createFrameLoop(scheduler?: { request(callback: (time: number) => void): number; cancel(id: number): void })
|
|
36
|
+
|
|
37
|
+
const prefersReducedMotion: () => boolean // root data-motion, else live matchMedia
|
|
38
|
+
function observeReducedMotion(listener: () => void): () => void
|
|
39
|
+
|
|
40
|
+
class VelocityTracker {
|
|
41
|
+
push(x: number, y: number, t: number): void
|
|
42
|
+
velocity(): { x: number; y: number } // px/s over the last ~90 ms
|
|
43
|
+
reset(): void
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Short WAAPI entrances for elements that genuinely appear; no-ops under reduced motion.
|
|
47
|
+
function enter(el: Element, options?: { x?; y?; scale?; duration?; delay?; easing?; restart? }): void
|
|
48
|
+
// Single-node FLIP from a previous rect to the element's current box.
|
|
49
|
+
function slideFrom(el: HTMLElement, previous: DOMRect, options?: { duration?: number }): void
|
|
50
|
+
const ease: { out: string; pop: string }
|
|
51
|
+
|
|
52
|
+
function sliderStops(spec)
|
|
53
|
+
function sliderValue(spec, value)
|
|
54
|
+
function sliderStep(spec, value, direction, count?)
|
|
55
|
+
function sliderFraction(spec, value)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Springs match SwiftUI's nonnegative bounce mapping
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
const open = Spring.fromDuration(0, { duration: 0.42, bounce: 0.18 })
|
|
62
|
+
const close = Spring.fromDuration(0, { duration: 0.36, bounce: 0.08 })
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For mass `m = 1`, duration `d` in seconds and bounce `b`:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
ω = 2π / d
|
|
69
|
+
ζ = 1 − b
|
|
70
|
+
stiffness k = ω²
|
|
71
|
+
damping c = 2ζω
|
|
72
|
+
acceleration = −k(value − target) − c·velocity
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`step()` advances the exact closed-form damped-harmonic solution for `dt` (reusing a cached 2×2 state transition matrix when `(omega, zeta, dt)` matches the previous step), with a 100 ms frame clamp. Retargeting preserves velocity unless you supply a new velocity. Rest snaps exactly when displacement is below `0.005` and speed is below `0.02` units/s.
|
|
76
|
+
|
|
77
|
+
The mapping was checked against native `SwiftUI.Spring` on macOS. At `d = 0.42, b = 0.18`, SwiftUI returns `k = 223.80055331268386` and `c = 24.534342628034576`; `core.test.ts` pins these values.
|
|
78
|
+
|
|
79
|
+
Apple calls duration an approximate settling duration. It is a pace parameter, not a timeout. A critically damped spring reaches 98% around `0.93d`. Bounce `0.3` corresponds to `ζ = 0.7` and about 4.6% overshoot, not 30%.
|
|
80
|
+
|
|
81
|
+
`fromDuration` accepts `d >= 2π/240` and `0 <= b < 1`. Negative Apple bounce has a different mapping and is unsupported; bounce `1` never settles. The constructor accepts `omega` in `(0, 240]` and `zeta` in `[0, 2]`, and rejects combinations that are unstable for the 480 Hz integrator.
|
|
82
|
+
|
|
83
|
+
## Measure before writing
|
|
84
|
+
|
|
85
|
+
`frameLoop.addMeasured(read, write)` runs every registered read before any write, so layout reads never interleave with style writes. New jobs join the next frame; removing a job during either phase prevents its remaining work. The loop cancels rAF when its last job is removed. The first frame after sleep uses `1/60` s; later frames use clamped elapsed time.
|
|
86
|
+
|
|
87
|
+
`createFrameLoop(scheduler?)` provides the same API with an injectable scheduler for tests. Core springs do not consult accessibility settings; DOM primitives do, and settle when the preference changes, including pending WAAPI exits.
|
|
88
|
+
|
|
89
|
+
## Solid owns targets; motion owns displayed values
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
springStyle(
|
|
93
|
+
() => button,
|
|
94
|
+
() => ({ width: selected() ? 84 : 22 }),
|
|
95
|
+
(el, v) => {
|
|
96
|
+
el.style.width = `${v.width}px`
|
|
97
|
+
},
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Call Solid helpers inside an owner; they release jobs and observers on cleanup. Signals supply targets only. Paint callbacks must write directly to the DOM, not to signals. `springStyle` reuses its value record; do not retain it. New refs and the first target snap; later targets preserve velocity.
|
|
102
|
+
|
|
103
|
+
`slidingHighlight` expects the positioned container to be the selected row's offset parent. The highlight owns `transform` and the active axis's width/height. It measures for 420 ms after changes and observes container and selected-row resizes. `spring(distance)` may choose each trip's curve; `paint(box)` receives each written box.
|
|
104
|
+
|
|
105
|
+
`widthMorph({ ref, content, watch, spring, inset })` clones content once per target change, measures its hidden `max-content` width in the shared read phase, and removes the clone in the write phase. It writes outer width and gives content `width: 100%`. `watch` must include any state that changes natural content width. The default spring is `0.42 / 0.18`, with `inset: 4`. Give the pill `box-sizing: border-box; padding: 4px`, content `display: flex; min-width: 0`, and keep width and opacity on separate nodes.
|
|
106
|
+
|
|
107
|
+
`numberTween({ ref, value, format })` springs a number and updates `textContent` only when the formatted text changes.
|
|
108
|
+
|
|
109
|
+
## Verify
|
|
110
|
+
|
|
111
|
+
- `bun test src/motion` from `packages/ui`
|
|
112
|
+
- `bun test --conditions=browser --isolate --preload ./happydom.ts ./test-browser/motion-dom.test.ts` from `packages/app`
|
|
113
|
+
- `strobe bench packages/ui/perf/motion.bench.ts --base origin/dev --head .`: retargets and steps 1,000 springs for 60 frames, and compares the CPU it costs with an interval
|