@opencode/ui 0.0.0-dev-21032 → 0.0.0-dev-21034

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencode/ui",
3
- "version": "0.0.0-dev-21032",
3
+ "version": "0.0.0-dev-21034",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -7,17 +7,23 @@
7
7
 
8
8
  [data-slot="animated-number-value"] {
9
9
  display: inline-flex;
10
- flex-direction: row-reverse;
10
+ /* Digits keep numeric order in RTL documents. */
11
+ direction: ltr;
11
12
  align-items: baseline;
12
13
  justify-content: flex-end;
13
14
  line-height: inherit;
14
15
  width: var(--animated-number-width, 1ch);
15
16
  overflow: hidden;
17
+ }
18
+
19
+ [data-slot="animated-number-value"][data-resizing="true"] {
16
20
  transition: width var(--tool-motion-spring-ms, 560ms) var(--tool-motion-ease, cubic-bezier(0.22, 1, 0.36, 1));
17
21
  }
18
22
 
19
23
  [data-slot="animated-number-digit"] {
20
24
  display: inline-grid;
25
+ /* Digits outside the width are clipped at the start edge, not squeezed. */
26
+ flex-shrink: 0;
21
27
  width: 1ch;
22
28
  height: 1em;
23
29
  line-height: 1em;
@@ -56,6 +62,11 @@
56
62
  line-height: 1em;
57
63
  }
58
64
 
65
+ [data-slot="animated-number-static"]::before,
66
+ [data-slot="animated-number-cell"]::before {
67
+ content: attr(data-digit);
68
+ }
69
+
59
70
  [data-slot="animated-number-digit"][data-animating="true"] [data-slot="animated-number-static"] {
60
71
  visibility: hidden;
61
72
  }
@@ -63,8 +74,10 @@
63
74
  [data-slot="animated-number-strip"] {
64
75
  display: inline-flex;
65
76
  flex-direction: column;
66
- margin-top: calc(var(--animated-number-offset, 10) * -1em);
67
- transition-property: margin-top;
77
+ /* Not transform: a composited roll lands on whole pixels, then the digit shifts as it settles. */
78
+ position: relative;
79
+ top: calc(var(--animated-number-offset, 10) * -1em);
80
+ transition-property: top;
68
81
  transition-duration: var(--animated-number-duration, 560ms);
69
82
  transition-timing-function: var(--tool-motion-ease, cubic-bezier(0.22, 1, 0.36, 1));
70
83
  }
@@ -76,7 +89,7 @@
76
89
  }
77
90
 
78
91
  @media (prefers-reduced-motion: reduce) {
79
- [data-component="animated-number"] [data-slot="animated-number-value"] {
92
+ [data-component="animated-number"] [data-slot="animated-number-value"][data-resizing] {
80
93
  transition-duration: 0ms;
81
94
  }
82
95
 
@@ -1,4 +1,4 @@
1
- import { For, Index, createEffect, createMemo, on } from "solid-js"
1
+ import { For, createEffect, createMemo, on } from "solid-js"
2
2
  import { createStore } from "solid-js/store"
3
3
 
4
4
  const TRACK = Array.from({ length: 30 }, (_, index) => index % 10)
@@ -26,6 +26,7 @@ function Digit(props: { value: number; direction: 1 | -1 }) {
26
26
  const step = () => state.step
27
27
  const animating = () => state.animating
28
28
  let last = props.value
29
+ let strip: HTMLSpanElement | undefined
29
30
 
30
31
  createEffect(
31
32
  on(
@@ -34,15 +35,19 @@ function Digit(props: { value: number; direction: 1 | -1 }) {
34
35
  const delta = spin(last, next, props.direction)
35
36
  last = next
36
37
 
37
- if (!delta) {
38
- setState("animating", false)
39
- setState("step", next + 10)
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 })
40
46
 
41
47
  return
42
48
  }
43
49
 
44
- setState("animating", true)
45
- setState("step", (value) => value + delta)
50
+ setState({ animating: true, step: target })
46
51
  },
47
52
  { defer: true },
48
53
  ),
@@ -50,8 +55,9 @@ function Digit(props: { value: number; direction: 1 | -1 }) {
50
55
 
51
56
  return (
52
57
  <span data-slot="animated-number-digit" data-animating={animating() ? "true" : "false"}>
53
- <span data-slot="animated-number-static">{props.value}</span>
58
+ <span data-slot="animated-number-static" data-digit={props.value} />
54
59
  <span
60
+ ref={strip}
55
61
  data-slot="animated-number-strip"
56
62
  onTransitionEnd={() => {
57
63
  setState("animating", false)
@@ -62,7 +68,7 @@ function Digit(props: { value: number; direction: 1 | -1 }) {
62
68
  "--animated-number-duration": `var(--tool-motion-odometer-ms, ${DURATION}ms)`,
63
69
  }}
64
70
  >
65
- <For each={TRACK}>{(value) => <span data-slot="animated-number-cell">{value}</span>}</For>
71
+ <For each={TRACK}>{(value) => <span data-slot="animated-number-cell" data-digit={value} />}</For>
66
72
  </span>
67
73
  </span>
68
74
  )
@@ -75,13 +81,18 @@ export function AnimatedNumber(props: { value: number; class?: string }) {
75
81
  return Math.max(0, Math.round(props.value))
76
82
  })
77
83
 
78
- const [state, setState] = createStore({
84
+ // A spare leading zero waits outside the clipped width to roll in. A digit that leaves stays until the width has
85
+ // 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 }>({
79
87
  value: target(),
80
- direction: 1 as 1 | -1,
88
+ direction: 1,
89
+ places: String(target()).length + 1,
90
+ resizing: false,
81
91
  })
82
92
 
83
93
  const value = () => state.value
84
94
  const direction = () => state.direction
95
+ let box: HTMLSpanElement | undefined
85
96
 
86
97
  createEffect(
87
98
  on(
@@ -91,8 +102,22 @@ export function AnimatedNumber(props: { value: number; class?: string }) {
91
102
 
92
103
  if (next === current) return
93
104
 
94
- setState("direction", next > current ? 1 : -1)
95
- setState("value", next)
105
+ const digits = String(next).length
106
+
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 })
110
+
111
+ return
112
+ }
113
+
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
+ })
96
121
  },
97
122
  { defer: true },
98
123
  ),
@@ -100,22 +125,26 @@ export function AnimatedNumber(props: { value: number; class?: string }) {
100
125
 
101
126
  const label = createMemo(() => value().toString())
102
127
 
103
- const digits = createMemo(() =>
104
- Array.from(label(), (char) => {
105
- const code = char.charCodeAt(0) - 48
106
-
107
- if (code < 0 || code > 9) return 0
108
-
109
- return code
110
- }).reverse(),
111
- )
112
-
113
- const width = createMemo(() => `${digits().length}ch`)
128
+ // 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))
114
130
 
115
131
  return (
116
- <span data-component="animated-number" class={props.class} aria-label={label()}>
117
- <span data-slot="animated-number-value" style={{ "--animated-number-width": width() }}>
118
- <Index each={digits()}>{(digit) => <Digit value={digit()} direction={direction()} />}</Index>
132
+ <span data-component="animated-number" class={props.class}>
133
+ {/* The value is the only text: screen readers and copy read it once, in order. CSS draws the digits. */}
134
+ <span class="sr-only">{label()}</span>
135
+ <span
136
+ ref={box}
137
+ data-slot="animated-number-value"
138
+ data-resizing={state.resizing ? "true" : "false"}
139
+ aria-hidden="true"
140
+ style={{ "--animated-number-width": `${label().length}ch` }}
141
+ onTransitionEnd={(event) => {
142
+ if (event.target === event.currentTarget) setState({ places: label().length + 1, resizing: false })
143
+ }}
144
+ >
145
+ <For each={places()}>
146
+ {(place) => <Digit value={Math.floor(value() / 10 ** place) % 10} direction={direction()} />}
147
+ </For>
119
148
  </span>
120
149
  </span>
121
150
  )