@opencode/ui 2.2.5 → 2.2.6

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.
Files changed (117) hide show
  1. package/dist/actions/button/button.d.ts +2 -2
  2. package/dist/actions/icon-button/icon-button.d.ts +1 -1
  3. package/dist/components/animated-number-machine.d.ts +95 -0
  4. package/dist/components/file-icon-machine.d.ts +40 -0
  5. package/dist/components/file-icon.d.ts +0 -2
  6. package/dist/components/file-icons/choose-icon-name.d.ts +2 -0
  7. package/dist/components/image-flight-machine.d.ts +135 -0
  8. package/dist/components/image-zoom-machine.d.ts +95 -0
  9. package/dist/components/image-zoom.d.ts +6 -3
  10. package/dist/components/list.d.ts +2 -6
  11. package/dist/components/menu-scroll.d.ts +9 -3
  12. package/dist/components/popover-machine.d.ts +96 -0
  13. package/dist/components/popover.d.ts +2 -2
  14. package/dist/components/resize-handle-machine.d.ts +71 -0
  15. package/dist/components/resize-handle.d.ts +2 -0
  16. package/dist/components/scroll-view-machine.d.ts +68 -0
  17. package/dist/components/scroll-view.d.ts +2 -2
  18. package/dist/components/spinner.d.ts +11 -3
  19. package/dist/components/text-field-machine.d.ts +62 -0
  20. package/dist/components/text-reveal-machine.d.ts +90 -0
  21. package/dist/components/typewriter-machine.d.ts +62 -0
  22. package/dist/context/dialog-machine.d.ts +125 -0
  23. package/dist/context/dialog.d.ts +17 -16
  24. package/dist/data-display/line-comment/machine.d.ts +157 -0
  25. package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
  26. package/dist/data-display/project-avatar/animation.d.ts +1 -1
  27. package/dist/feedback/activity-ring/activity-ring.d.ts +2 -1
  28. package/dist/feedback/toast/machine.d.ts +57 -0
  29. package/dist/feedback/toast/toast.d.ts +1 -1
  30. package/dist/forms/checkbox/checkbox.d.ts +6 -1
  31. package/dist/forms/select/machine.d.ts +45 -0
  32. package/dist/forms/select/select.d.ts +4 -0
  33. package/dist/forms/typeahead/machine.d.ts +85 -0
  34. package/dist/hooks/auto-scroll-machine.d.ts +89 -0
  35. package/dist/hooks/create-auto-scroll.d.ts +1 -1
  36. package/dist/hooks/list-machine.d.ts +150 -0
  37. package/dist/hooks/use-filtered-list.d.ts +21 -35
  38. package/dist/i18n/en.d.ts +5 -0
  39. package/dist/icons/catalog.d.ts +8 -0
  40. package/dist/navigation/menu/machine.d.ts +49 -0
  41. package/dist/navigation/menu/menu.d.ts +5 -3
  42. package/dist/navigation/segmented-control/machine.d.ts +46 -0
  43. package/dist/overlays/mcp-sign-in/machine.d.ts +184 -0
  44. package/dist/overlays/mcp-sign-in/mcp-sign-in.d.ts +40 -0
  45. package/dist/overlays/tooltip/machine.d.ts +146 -0
  46. package/dist/theme/context.d.ts +38 -14
  47. package/dist/theme/machine.d.ts +174 -0
  48. package/dist/typography/text-shimmer/machine.d.ts +48 -0
  49. package/package.json +19 -3
  50. package/src/actions/button/button.tsx +11 -6
  51. package/src/actions/icon-button/icon-button.tsx +17 -4
  52. package/src/components/animated-number-machine.ts +214 -0
  53. package/src/components/animated-number.tsx +134 -83
  54. package/src/components/file-icon-machine.ts +78 -0
  55. package/src/components/file-icon.tsx +96 -579
  56. package/src/components/file-icons/choose-icon-name.ts +574 -0
  57. package/src/components/image-flight-machine.ts +247 -0
  58. package/src/components/image-preview.css +5 -2
  59. package/src/components/image-preview.tsx +390 -252
  60. package/src/components/image-zoom-machine.ts +191 -0
  61. package/src/components/image-zoom.ts +22 -14
  62. package/src/components/list.tsx +46 -137
  63. package/src/components/menu-scroll.css +19 -8
  64. package/src/components/menu-scroll.tsx +111 -34
  65. package/src/components/popover-machine.ts +198 -0
  66. package/src/components/popover.tsx +157 -89
  67. package/src/components/resize-handle-machine.ts +174 -0
  68. package/src/components/resize-handle.tsx +116 -67
  69. package/src/components/scroll-view-machine.ts +244 -0
  70. package/src/components/scroll-view.tsx +163 -116
  71. package/src/components/spinner.css +18 -5
  72. package/src/components/spinner.tsx +28 -14
  73. package/src/components/text-field-machine.ts +102 -0
  74. package/src/components/text-field.tsx +78 -24
  75. package/src/components/text-reveal-machine.ts +184 -0
  76. package/src/components/text-reveal.tsx +96 -93
  77. package/src/components/typewriter-machine.ts +134 -0
  78. package/src/components/typewriter.tsx +50 -39
  79. package/src/context/dialog-machine.ts +280 -0
  80. package/src/context/dialog.tsx +168 -177
  81. package/src/data-display/line-comment/line-comment.tsx +157 -178
  82. package/src/data-display/line-comment/machine.ts +391 -0
  83. package/src/data-display/project-avatar/animation-machine.ts +182 -0
  84. package/src/data-display/project-avatar/animation.ts +67 -38
  85. package/src/feedback/activity-ring/activity-ring.tsx +1 -1
  86. package/src/feedback/toast/machine.ts +115 -0
  87. package/src/feedback/toast/toast.tsx +55 -59
  88. package/src/forms/checkbox/checkbox-compact.css +169 -0
  89. package/src/forms/checkbox/checkbox.tsx +93 -31
  90. package/src/forms/search-list/search-list.css +5 -1
  91. package/src/forms/search-list/search-list.tsx +4 -4
  92. package/src/forms/select/machine.ts +81 -0
  93. package/src/forms/select/select.css +59 -17
  94. package/src/forms/select/select.tsx +67 -31
  95. package/src/forms/typeahead/machine.ts +253 -0
  96. package/src/forms/typeahead/typeahead.tsx +70 -62
  97. package/src/hooks/auto-scroll-machine.ts +261 -0
  98. package/src/hooks/create-auto-scroll.tsx +110 -205
  99. package/src/hooks/list-machine.ts +359 -0
  100. package/src/hooks/use-filtered-list.tsx +101 -112
  101. package/src/i18n/en.ts +6 -1
  102. package/src/icons/catalog.ts +8 -0
  103. package/src/navigation/menu/machine.ts +109 -0
  104. package/src/navigation/menu/menu.tsx +130 -22
  105. package/src/navigation/segmented-control/machine.ts +72 -0
  106. package/src/navigation/segmented-control/segmented-control.tsx +46 -46
  107. package/src/overlays/dialog/dialog.tsx +7 -1
  108. package/src/overlays/mcp-sign-in/machine.ts +343 -0
  109. package/src/overlays/mcp-sign-in/mcp-sign-in.ts +159 -0
  110. package/src/overlays/tooltip/machine.ts +303 -0
  111. package/src/overlays/tooltip/tooltip.tsx +157 -92
  112. package/src/styles/theme.css +10 -2
  113. package/src/theme/context.tsx +192 -269
  114. package/src/theme/machine.ts +508 -0
  115. package/src/typography/text-shimmer/machine.ts +90 -0
  116. package/src/typography/text-shimmer/text-shimmer.css +71 -39
  117. package/src/typography/text-shimmer/text-shimmer.tsx +41 -24
@@ -1,70 +1,73 @@
1
- import { For, createEffect, createMemo, on } from "solid-js"
2
- import { createStore } from "solid-js/store"
3
-
4
- const TRACK = Array.from({ length: 30 }, (_, index) => index % 10)
1
+ import { For, createEffect, createMemo, createSignal, on, onCleanup, untrack } from "solid-js"
2
+ import { prefersReducedMotion } from "../motion/reduced"
3
+ import {
4
+ ANIMATED_NUMBER_FALLBACK_PAD_MS,
5
+ ANIMATED_NUMBER_TRACK_LENGTH,
6
+ createAnimatedDigitState,
7
+ createAnimatedNumberState,
8
+ selectAnimatedDigitRolling,
9
+ selectAnimatedDigitStep,
10
+ selectAnimatedNumberDirection,
11
+ selectAnimatedNumberPlaces,
12
+ selectAnimatedNumberResizing,
13
+ selectAnimatedNumberValue,
14
+ transitionAnimatedDigit,
15
+ transitionAnimatedNumber,
16
+ type AnimatedDigitEvent,
17
+ type AnimatedNumberEffect,
18
+ type AnimatedNumberEvent,
19
+ } from "./animated-number-machine"
20
+
21
+ const TRACK = Array.from({ length: ANIMATED_NUMBER_TRACK_LENGTH }, (_, index) => index % 10)
5
22
 
6
23
  const DURATION = 600
7
24
 
8
- function normalize(value: number) {
9
- return ((value % 10) + 10) % 10
10
- }
25
+ const ROLL_ENDED: AnimatedDigitEvent = { type: "roll.ended" }
11
26
 
12
- function spin(from: number, to: number, direction: 1 | -1) {
13
- if (from === to) return 0
27
+ const RESIZE_ENDED: AnimatedNumberEvent = { type: "resize.ended" }
14
28
 
15
- if (direction > 0) return (to - from + 10) % 10
29
+ function Digit(props: { value: number; direction: 1 | -1 }) {
30
+ const [digit, setDigit] = createSignal(createAnimatedDigitState(props.value))
31
+ let strip: HTMLSpanElement | undefined
16
32
 
17
- return -((from - to + 10) % 10)
18
- }
33
+ const fallback = createFallback(
34
+ () => strip,
35
+ (attempt) => dispatch({ type: "roll.timed-out", attempt }),
36
+ )
19
37
 
20
- function Digit(props: { value: number; direction: 1 | -1 }) {
21
- const [state, setState] = createStore({
22
- step: props.value + 10,
23
- animating: false,
24
- })
38
+ const dispatch = (event: AnimatedDigitEvent) => {
39
+ const prev = untrack(digit)
40
+ const next = transitionAnimatedDigit(prev, event)
25
41
 
26
- const step = () => state.step
27
- const animating = () => state.animating
28
- let last = props.value
29
- let strip: HTMLSpanElement | undefined
42
+ if (next.state !== prev) setDigit(next.state)
43
+ next.effects.forEach(fallback)
44
+ }
30
45
 
31
46
  createEffect(
32
47
  on(
33
48
  () => props.value,
34
- (next) => {
35
- const delta = spin(last, next, props.direction)
36
- last = next
37
-
38
- // An unchanged digit keeps any roll it is in the middle of.
39
- if (!delta) return
40
-
41
- const target = step() + delta
42
-
43
- // A detached digit never finishes a roll, and rapid changes can run off the track, so both settle at once.
44
- if (!strip?.isConnected || target < 0 || target >= TRACK.length) {
45
- setState({ animating: false, step: next + 10 })
46
-
47
- return
48
- }
49
-
50
- setState({ animating: true, step: target })
51
- },
49
+ (value) =>
50
+ dispatch({ type: "digit.changed", digit: value, direction: props.direction, canAnimate: canAnimate(strip) }),
52
51
  { defer: true },
53
52
  ),
54
53
  )
55
54
 
55
+ onCleanup(() => dispatch({ type: "disposed" }))
56
+
57
+ const ended = (event: TransitionEvent) => {
58
+ if (transitionEnded(event, strip, "top")) dispatch(ROLL_ENDED)
59
+ }
60
+
56
61
  return (
57
- <span data-slot="animated-number-digit" data-animating={animating() ? "true" : "false"}>
62
+ <span data-slot="animated-number-digit" data-animating={selectAnimatedDigitRolling(digit()) ? "true" : "false"}>
58
63
  <span data-slot="animated-number-static" data-digit={props.value} />
59
64
  <span
60
65
  ref={strip}
61
66
  data-slot="animated-number-strip"
62
- onTransitionEnd={() => {
63
- setState("animating", false)
64
- setState("step", (value) => normalize(value) + 10)
65
- }}
67
+ onTransitionEnd={ended}
68
+ onTransitionCancel={ended}
66
69
  style={{
67
- "--animated-number-offset": `${step()}`,
70
+ "--animated-number-offset": `${selectAnimatedDigitStep(digit())}`,
68
71
  "--animated-number-duration": `var(--tool-motion-odometer-ms, ${DURATION}ms)`,
69
72
  }}
70
73
  >
@@ -83,50 +86,39 @@ export function AnimatedNumber(props: { value: number; class?: string }) {
83
86
 
84
87
  // A spare leading zero waits outside the clipped width to roll in. A digit that leaves stays until the width has
85
88
  // shrunk past it, so it rolls to zero instead of vanishing.
86
- const [state, setState] = createStore<{ value: number; direction: 1 | -1; places: number; resizing: boolean }>({
87
- value: target(),
88
- direction: 1,
89
- places: String(target()).length + 1,
90
- resizing: false,
91
- })
92
-
93
- const value = () => state.value
94
- const direction = () => state.direction
89
+ const [number, setNumber] = createSignal(createAnimatedNumberState(target()))
95
90
  let box: HTMLSpanElement | undefined
96
91
 
97
- createEffect(
98
- on(
99
- target,
100
- (next) => {
101
- const current = value()
102
-
103
- if (next === current) return
104
-
105
- const digits = String(next).length
92
+ const fallback = createFallback(
93
+ () => box,
94
+ (attempt) => dispatch({ type: "resize.timed-out", attempt }),
95
+ )
106
96
 
107
- // A detached number cannot ease its width and would never hear it end, so it settles at once.
108
- if (!box?.isConnected) {
109
- setState({ direction: next > current ? 1 : -1, value: next, places: digits + 1, resizing: false })
97
+ const dispatch = (event: AnimatedNumberEvent) => {
98
+ const prev = untrack(number)
99
+ const next = transitionAnimatedNumber(prev, event)
110
100
 
111
- return
112
- }
101
+ if (next.state !== prev) setNumber(next.state)
102
+ next.effects.forEach(fallback)
103
+ }
113
104
 
114
- // Only a change to the digit count eases the width, so a late font swap or zoom never animates it.
115
- setState({
116
- direction: next > current ? 1 : -1,
117
- value: next,
118
- places: Math.max(state.places, digits + 1),
119
- resizing: state.resizing || digits !== String(current).length,
120
- })
121
- },
122
- { defer: true },
123
- ),
105
+ createEffect(
106
+ on(target, (value) => dispatch({ type: "value.changed", value, canAnimate: canAnimate(box) }), { defer: true }),
124
107
  )
125
108
 
109
+ onCleanup(() => dispatch({ type: "disposed" }))
110
+
111
+ const value = () => selectAnimatedNumberValue(number())
112
+ const direction = () => selectAnimatedNumberDirection(number())
126
113
  const label = createMemo(() => value().toString())
114
+ const count = createMemo(() => selectAnimatedNumberPlaces(number()))
127
115
 
128
116
  // Place values, most significant first. Keying by place keeps each digit rolling as digits appear and leave.
129
- const places = createMemo(() => Array.from({ length: state.places }, (_, index) => state.places - 1 - index))
117
+ const places = createMemo(() => Array.from({ length: count() }, (_, index) => count() - 1 - index))
118
+
119
+ const ended = (event: TransitionEvent) => {
120
+ if (transitionEnded(event, box, "width")) dispatch(RESIZE_ENDED)
121
+ }
130
122
 
131
123
  return (
132
124
  <span data-component="animated-number" class={props.class}>
@@ -135,12 +127,11 @@ export function AnimatedNumber(props: { value: number; class?: string }) {
135
127
  <span
136
128
  ref={box}
137
129
  data-slot="animated-number-value"
138
- data-resizing={state.resizing ? "true" : "false"}
130
+ data-resizing={selectAnimatedNumberResizing(number()) ? "true" : "false"}
139
131
  aria-hidden="true"
140
132
  style={{ "--animated-number-width": `${label().length}ch` }}
141
- onTransitionEnd={(event) => {
142
- if (event.target === event.currentTarget) setState({ places: label().length + 1, resizing: false })
143
- }}
133
+ onTransitionEnd={ended}
134
+ onTransitionCancel={ended}
144
135
  >
145
136
  <For each={places()}>
146
137
  {(place) => <Digit value={Math.floor(value() / 10 ** place) % 10} direction={direction()} />}
@@ -149,3 +140,63 @@ export function AnimatedNumber(props: { value: number; class?: string }) {
149
140
  </span>
150
141
  )
151
142
  }
143
+
144
+ // A detached element never runs a transition, and reduced motion runs them in 0 ms, which reports no end.
145
+ function canAnimate(element: HTMLElement | undefined) {
146
+ return element?.isConnected === true && !prefersReducedMotion()
147
+ }
148
+
149
+ // A change that retargets a running transition cancels the old one while the new one keeps going; only a transition
150
+ // with nothing left running on the property has ended.
151
+ function transitionEnded(event: TransitionEvent, element: HTMLElement | undefined, property: string) {
152
+ if (!element || event.target !== element || event.propertyName !== property) return false
153
+
154
+ if (event.type !== "transitioncancel") return true
155
+
156
+ return !element
157
+ .getAnimations()
158
+ .some(
159
+ (animation) =>
160
+ animation instanceof CSSTransition &&
161
+ animation.transitionProperty === property &&
162
+ animation.playState === "running",
163
+ )
164
+ }
165
+
166
+ /** Settles an eased change whose end event never arrives, a little after its transition should have finished. */
167
+ function createFallback(element: () => HTMLElement | undefined, timeout: (attempt: number) => void) {
168
+ let timer: ReturnType<typeof setTimeout> | undefined
169
+
170
+ return (effect: AnimatedNumberEffect) => {
171
+ clearTimeout(timer)
172
+ timer = undefined
173
+
174
+ if (effect.type === "clear") return
175
+ // The change's transition styles apply when Solid flushes this update, so measure after it.
176
+ queueMicrotask(() => {
177
+ clearTimeout(timer)
178
+ timer = setTimeout(() => timeout(effect.attempt), transitionMs(element()) + ANIMATED_NUMBER_FALLBACK_PAD_MS)
179
+ })
180
+ }
181
+ }
182
+
183
+ function transitionMs(element: HTMLElement | undefined) {
184
+ if (!element?.isConnected) return 0
185
+ const style = getComputedStyle(element)
186
+ const delays = style.transitionDelay.split(",")
187
+
188
+ return Math.max(
189
+ 0,
190
+ ...style.transitionDuration
191
+ .split(",")
192
+ .map((duration, index) => milliseconds(duration) + milliseconds(delays[index % delays.length])),
193
+ )
194
+ }
195
+
196
+ function milliseconds(value: string) {
197
+ const time = Number.parseFloat(value)
198
+
199
+ if (!Number.isFinite(time)) return 0
200
+
201
+ return value.trim().endsWith("ms") ? time : time * 1000
202
+ }
@@ -0,0 +1,78 @@
1
+ import type { IconName } from "./file-icons/types"
2
+
3
+ export const FILE_ICON_LOAD_TIMEOUT_MS = 10_000
4
+
5
+ /** Bundled with the component, so they are always in the sprite and stand in for an icon that failed to load. */
6
+ export type FallbackIconName = "Document" | "Folder" | "FolderOpen"
7
+
8
+ /**
9
+ * Lifecycle of one lazy `<symbol>` in the in-document sprite, shared by every mounted icon with that name. It only
10
+ * moves forward: Chromium keeps a failed dynamic import failed for the page's lifetime, so a retry cannot succeed.
11
+ */
12
+ export type FileIconSymbolState = { readonly status: "unrequested" | "loading" | "failed" | "ready" }
13
+
14
+ export type FileIconSymbolEvent =
15
+ | { readonly type: "requested" }
16
+ | { readonly type: "load.succeeded"; readonly svg: string }
17
+ | { readonly type: "load.failed" }
18
+ | { readonly type: "load.timed-out" }
19
+
20
+ export type FileIconSymbolEffect =
21
+ | { readonly type: "load" }
22
+ | { readonly type: "insert-symbol"; readonly svg: string }
23
+ | { readonly type: "cancel-timeout" }
24
+
25
+ export type FileIconSymbolTransition = {
26
+ readonly state: FileIconSymbolState
27
+ readonly effects: readonly FileIconSymbolEffect[]
28
+ }
29
+
30
+ const UNREQUESTED: FileIconSymbolState = Object.freeze({ status: "unrequested" })
31
+
32
+ const LOADING: FileIconSymbolState = Object.freeze({ status: "loading" })
33
+
34
+ const FAILED: FileIconSymbolState = Object.freeze({ status: "failed" })
35
+
36
+ const READY: FileIconSymbolState = Object.freeze({ status: "ready" })
37
+
38
+ export const INITIAL_FILE_ICON_SYMBOL_STATE = UNREQUESTED
39
+
40
+ export const READY_FILE_ICON_SYMBOL_STATE = READY
41
+
42
+ export const FILE_ICON_REQUESTED: FileIconSymbolEvent = Object.freeze({ type: "requested" })
43
+
44
+ const NONE: readonly FileIconSymbolEffect[] = Object.freeze([])
45
+
46
+ const LOAD: readonly FileIconSymbolEffect[] = Object.freeze([{ type: "load" }])
47
+
48
+ const CANCEL: readonly FileIconSymbolEffect[] = Object.freeze([{ type: "cancel-timeout" }])
49
+
50
+ export function transitionFileIconSymbol(
51
+ state: FileIconSymbolState,
52
+ event: FileIconSymbolEvent,
53
+ ): FileIconSymbolTransition {
54
+ if (state.status === "unrequested" && event.type === "requested") return { state: LOADING, effects: LOAD }
55
+
56
+ // A symbol that arrives after its timeout still upgrades the icons showing the fallback.
57
+ if ((state.status === "loading" || state.status === "failed") && event.type === "load.succeeded")
58
+ return {
59
+ state: READY,
60
+ effects: [...(state.status === "loading" ? CANCEL : NONE), { type: "insert-symbol", svg: event.svg }],
61
+ }
62
+
63
+ if (state.status === "loading" && (event.type === "load.failed" || event.type === "load.timed-out"))
64
+ return { state: FAILED, effects: CANCEL }
65
+
66
+ return { state, effects: NONE }
67
+ }
68
+
69
+ export function chooseFallbackIconName(type: "directory" | "file", expanded: boolean): FallbackIconName {
70
+ if (type === "file") return "Document"
71
+
72
+ return expanded ? "FolderOpen" : "Folder"
73
+ }
74
+
75
+ /** The symbol a mounted icon shows: its own unless it failed to load. */
76
+ export function selectFileIconSymbol(state: FileIconSymbolState, name: IconName, fallback: FallbackIconName): IconName {
77
+ return state.status === "failed" ? fallback : name
78
+ }