@opencode/ui 0.0.0-dev-750 → 0.0.0-dev-784

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 (48) hide show
  1. package/dist/components/animated-number-machine.d.ts +95 -0
  2. package/dist/components/popover-machine.d.ts +96 -0
  3. package/dist/components/popover.d.ts +2 -2
  4. package/dist/components/resize-handle-machine.d.ts +71 -0
  5. package/dist/components/scroll-view-machine.d.ts +66 -0
  6. package/dist/components/scroll-view.d.ts +2 -2
  7. package/dist/components/text-field-machine.d.ts +62 -0
  8. package/dist/components/text-reveal-machine.d.ts +90 -0
  9. package/dist/data-display/line-comment/machine.d.ts +157 -0
  10. package/dist/data-display/project-avatar/animation-machine.d.ts +62 -0
  11. package/dist/data-display/project-avatar/animation.d.ts +1 -1
  12. package/dist/feedback/toast/machine.d.ts +57 -0
  13. package/dist/feedback/toast/toast.d.ts +1 -1
  14. package/dist/forms/select/machine.d.ts +45 -0
  15. package/dist/forms/typeahead/machine.d.ts +85 -0
  16. package/dist/navigation/menu/machine.d.ts +49 -0
  17. package/dist/navigation/segmented-control/machine.d.ts +46 -0
  18. package/dist/theme/context.d.ts +20 -9
  19. package/dist/theme/machine.d.ts +174 -0
  20. package/package.json +2 -2
  21. package/src/components/animated-number-machine.ts +214 -0
  22. package/src/components/animated-number.tsx +134 -83
  23. package/src/components/popover-machine.ts +198 -0
  24. package/src/components/popover.tsx +157 -89
  25. package/src/components/resize-handle-machine.ts +174 -0
  26. package/src/components/resize-handle.tsx +113 -83
  27. package/src/components/scroll-view-machine.ts +231 -0
  28. package/src/components/scroll-view.tsx +163 -116
  29. package/src/components/text-field-machine.ts +102 -0
  30. package/src/components/text-field.tsx +78 -24
  31. package/src/components/text-reveal-machine.ts +184 -0
  32. package/src/components/text-reveal.tsx +96 -93
  33. package/src/data-display/line-comment/line-comment.tsx +154 -178
  34. package/src/data-display/line-comment/machine.ts +392 -0
  35. package/src/data-display/project-avatar/animation-machine.ts +182 -0
  36. package/src/data-display/project-avatar/animation.ts +67 -38
  37. package/src/feedback/toast/machine.ts +115 -0
  38. package/src/feedback/toast/toast.tsx +55 -59
  39. package/src/forms/select/machine.ts +81 -0
  40. package/src/forms/select/select.tsx +49 -27
  41. package/src/forms/typeahead/machine.ts +253 -0
  42. package/src/forms/typeahead/typeahead.tsx +70 -62
  43. package/src/navigation/menu/machine.ts +109 -0
  44. package/src/navigation/menu/menu.tsx +118 -20
  45. package/src/navigation/segmented-control/machine.ts +72 -0
  46. package/src/navigation/segmented-control/segmented-control.tsx +46 -46
  47. package/src/theme/context.tsx +134 -240
  48. package/src/theme/machine.ts +508 -0
@@ -1,10 +1,19 @@
1
1
  import { TextField as Kobalte } from "@kobalte/core/text-field"
2
- import { createSignal, Show, splitProps } from "solid-js"
2
+ import { createSignal, onCleanup, Show, splitProps, untrack } from "solid-js"
3
3
  import type { ComponentProps } from "solid-js"
4
4
  import { useI18n } from "../context/i18n"
5
5
  import { IconButton } from "@opencode/ui/icon-button"
6
6
  import { Icon } from "@opencode/ui/icon"
7
7
  import { Tooltip } from "@opencode/ui/tooltip"
8
+ import {
9
+ INITIAL_TEXT_FIELD_COPY_STATE,
10
+ selectTextFieldCopied,
11
+ selectTextFieldCopyIcon,
12
+ selectTextFieldCopyLabelKey,
13
+ transitionTextFieldCopy,
14
+ type TextFieldCopyEffect,
15
+ type TextFieldCopyEvent,
16
+ } from "./text-field-machine"
8
17
 
9
18
  export interface TextFieldProps
10
19
  extends ComponentProps<typeof Kobalte.Input>,
@@ -56,35 +65,49 @@ export function TextField(props: TextFieldProps) {
56
65
  "multiline",
57
66
  ])
58
67
 
59
- const [copied, setCopied] = createSignal(false)
68
+ const [copyState, setCopyState] = createSignal(INITIAL_TEXT_FIELD_COPY_STATE)
69
+ let timer: ReturnType<typeof setTimeout> | undefined
60
70
 
61
- const label = () => {
62
- if (copied()) return i18n.t("ui.textField.copied")
71
+ const dispatch = (event: TextFieldCopyEvent) => {
72
+ const next = transitionTextFieldCopy(untrack(copyState), event)
63
73
 
64
- if (local.copyKind === "link") return i18n.t("ui.textField.copyLink")
65
-
66
- return i18n.t("ui.textField.copyToClipboard")
74
+ if (next.state !== untrack(copyState)) setCopyState(next.state)
75
+ next.effects.forEach(run)
67
76
  }
68
77
 
69
- const icon = () => {
70
- if (copied()) return "check"
78
+ const run = (effect: TextFieldCopyEffect) => {
79
+ if (effect.type === "timer.clear") {
80
+ clearTimeout(timer)
81
+ timer = undefined
71
82
 
72
- if (local.copyKind === "link") return "link"
83
+ return
84
+ }
73
85
 
74
- return "copy"
75
- }
86
+ if (effect.type === "reset.schedule") {
87
+ timer = setTimeout(() => dispatch({ type: "reset.elapsed", attempt: effect.attempt }), effect.delayMs)
76
88
 
77
- async function handleCopy() {
78
- const value = local.value ?? local.defaultValue ?? ""
79
- await navigator.clipboard.writeText(value)
80
- setCopied(true)
81
- setTimeout(() => setCopied(false), 2000)
82
- }
89
+ return
90
+ }
83
91
 
84
- function handleClick() {
85
- if (local.copyable) void handleCopy()
92
+ timer = setTimeout(() => dispatch({ type: "copy.timed-out", attempt: effect.attempt }), effect.timeoutMs)
93
+ void writeClipboard(effect.value).then(
94
+ (written) => dispatch({ type: written ? "copy.succeeded" : "copy.failed", attempt: effect.attempt }),
95
+ () => dispatch({ type: "copy.failed", attempt: effect.attempt }),
96
+ )
86
97
  }
87
98
 
99
+ onCleanup(() => dispatch({ type: "disposed" }))
100
+
101
+ const copied = () => selectTextFieldCopied(copyState())
102
+ const label = () => i18n.t(selectTextFieldCopyLabelKey(copyState(), local.copyKind))
103
+
104
+ const requestCopy = () =>
105
+ dispatch({
106
+ type: "copy.requested",
107
+ value: local.value ?? local.defaultValue ?? "",
108
+ enabled: !!local.copyable && !local.disabled,
109
+ })
110
+
88
111
  return (
89
112
  <Kobalte
90
113
  data-component="input"
@@ -94,7 +117,7 @@ export function TextField(props: TextFieldProps) {
94
117
  value={local.value}
95
118
  onChange={local.onChange}
96
119
  onKeyDown={local.onKeyDown}
97
- onClick={handleClick}
120
+ onClick={requestCopy}
98
121
  required={local.required}
99
122
  disabled={local.disabled}
100
123
  readOnly={local.readOnly}
@@ -118,14 +141,19 @@ export function TextField(props: TextFieldProps) {
118
141
  value={label()}
119
142
  placement="top"
120
143
  gutter={4}
121
- forceOpen={copied() ? true : undefined}
144
+ forceOpen={copied() || undefined}
122
145
  skipDelayDuration={0}
123
146
  >
124
147
  <IconButton
125
148
  type="button"
126
- icon={<Icon name={icon()} />}
149
+ icon={<Icon name={selectTextFieldCopyIcon(copyState(), local.copyKind)} />}
127
150
  variant="ghost"
128
- onClick={handleCopy}
151
+ disabled={local.disabled}
152
+ onClick={(event) => {
153
+ // The field itself copies on click too; one click is one copy.
154
+ event.stopPropagation()
155
+ requestCopy()
156
+ }}
129
157
  tabIndex={-1}
130
158
  data-slot="input-copy-button"
131
159
  aria-label={label()}
@@ -140,3 +168,29 @@ export function TextField(props: TextFieldProps) {
140
168
  </Kobalte>
141
169
  )
142
170
  }
171
+
172
+ // `navigator.clipboard` exists only in secure contexts, so plain-HTTP LAN origins copy through a selected textarea.
173
+ async function writeClipboard(text: string) {
174
+ const written = await navigator.clipboard?.writeText(text).then(
175
+ () => true,
176
+ () => false,
177
+ )
178
+
179
+ if (written) return true
180
+ const active = document.activeElement instanceof HTMLElement ? document.activeElement : undefined
181
+ const textarea = document.createElement("textarea")
182
+ textarea.value = text
183
+ textarea.setAttribute("readonly", "")
184
+ textarea.setAttribute("aria-hidden", "true")
185
+ textarea.tabIndex = -1
186
+ textarea.style.position = "fixed"
187
+ textarea.style.opacity = "0"
188
+ textarea.style.pointerEvents = "none"
189
+ document.body.appendChild(textarea)
190
+ textarea.select()
191
+ const copied = document.execCommand("copy")
192
+ textarea.remove()
193
+ active?.focus({ preventScroll: true })
194
+
195
+ return copied
196
+ }
@@ -0,0 +1,184 @@
1
+ /** Fonts that never settle must not keep the reveal from animating. */
2
+ export const TEXT_REVEAL_READY_TIMEOUT_MS = 1_000
3
+
4
+ /**
5
+ * `measuring` waits for fonts and one painted frame before transitions turn on, so the first text never animates in.
6
+ * It only moves forward, so its results match on the phase. `swapping` holds a replaced text in place for one frame,
7
+ * then the wipe runs. `leaving` is always text that was on screen, so text replaced within one frame never wipes out.
8
+ */
9
+ export type TextRevealState =
10
+ | { readonly status: "measuring"; readonly current: string | undefined; readonly widthPx: number }
11
+ | {
12
+ readonly status: "idle"
13
+ readonly issued: number
14
+ readonly current: string | undefined
15
+ readonly leaving: string | undefined
16
+ readonly widthPx: number
17
+ }
18
+ | {
19
+ readonly status: "swapping"
20
+ readonly attempt: number
21
+ readonly current: string | undefined
22
+ readonly leaving: string | undefined
23
+ readonly widthPx: number
24
+ }
25
+ | { readonly status: "disposed" }
26
+
27
+ type Measured = { readonly widthPx: number; readonly growOnly: boolean }
28
+
29
+ export type TextRevealEvent =
30
+ | { readonly type: "text.changed"; readonly text: string | undefined }
31
+ | ({ readonly type: "width.measured" } & Measured)
32
+ | ({ readonly type: "fonts.settled" } & Measured)
33
+ | ({ readonly type: "ready.settled" } & Measured)
34
+ | ({ readonly type: "ready.timed-out" } & Measured)
35
+ | ({ readonly type: "swap.settled"; readonly attempt: number } & Measured)
36
+ | { readonly type: "disposed" }
37
+
38
+ export type TextRevealEffect =
39
+ | { readonly type: "measure.entering" }
40
+ | { readonly type: "ready.frame" }
41
+ | { readonly type: "swap.frame"; readonly attempt: number }
42
+ | { readonly type: "cancel.frame" }
43
+ | { readonly type: "cancel.ready-timer" }
44
+
45
+ export type TextRevealTransition = {
46
+ readonly state: TextRevealState
47
+ readonly effects: readonly TextRevealEffect[]
48
+ }
49
+
50
+ const NO_EFFECTS: readonly TextRevealEffect[] = Object.freeze([])
51
+
52
+ const MEASURE: TextRevealEffect = Object.freeze({ type: "measure.entering" })
53
+
54
+ const READY_FRAME: TextRevealEffect = Object.freeze({ type: "ready.frame" })
55
+
56
+ const CANCEL_FRAME: TextRevealEffect = Object.freeze({ type: "cancel.frame" })
57
+
58
+ const CANCEL_READY_TIMER: TextRevealEffect = Object.freeze({ type: "cancel.ready-timer" })
59
+
60
+ const DISPOSED: TextRevealState = Object.freeze({ status: "disposed" })
61
+
62
+ export function createTextRevealState(text: string | undefined): TextRevealState {
63
+ return { status: "measuring", current: text, widthPx: 0 }
64
+ }
65
+
66
+ export function transitionTextReveal(state: TextRevealState, event: TextRevealEvent): TextRevealTransition {
67
+ if (state.status === "disposed") return { state, effects: NO_EFFECTS }
68
+
69
+ if (event.type === "disposed") {
70
+ if (state.status === "measuring") return { state: DISPOSED, effects: [CANCEL_FRAME, CANCEL_READY_TIMER] }
71
+
72
+ return { state: DISPOSED, effects: state.status === "swapping" ? [CANCEL_FRAME] : NO_EFFECTS }
73
+ }
74
+
75
+ if (event.type === "text.changed") return changeText(state, event.text)
76
+
77
+ if (state.status === "measuring" && event.type === "fonts.settled") {
78
+ return { state: { ...state, widthPx: widen(state.widthPx, event) }, effects: [READY_FRAME] }
79
+ }
80
+
81
+ // Fonts that settle after the ready timeout still widen the track to the real text.
82
+ if (event.type === "width.measured" || event.type === "fonts.settled") {
83
+ const widthPx = widen(state.widthPx, event)
84
+
85
+ return { state: widthPx === state.widthPx ? state : { ...state, widthPx }, effects: NO_EFFECTS }
86
+ }
87
+
88
+ if (state.status === "measuring" && (event.type === "ready.settled" || event.type === "ready.timed-out")) {
89
+ return {
90
+ state: {
91
+ status: "idle",
92
+ issued: 0,
93
+ current: state.current,
94
+ leaving: undefined,
95
+ widthPx: widen(state.widthPx, event),
96
+ },
97
+ effects: [CANCEL_FRAME, CANCEL_READY_TIMER],
98
+ }
99
+ }
100
+
101
+ if (state.status === "swapping" && event.type === "swap.settled" && event.attempt === state.attempt) {
102
+ return {
103
+ state: {
104
+ status: "idle",
105
+ issued: state.attempt,
106
+ current: state.current,
107
+ leaving: state.leaving,
108
+ widthPx: widen(state.widthPx, event),
109
+ },
110
+ effects: NO_EFFECTS,
111
+ }
112
+ }
113
+
114
+ return { state, effects: NO_EFFECTS }
115
+ }
116
+
117
+ /** Transitions turn on once the first text has painted. */
118
+ export function selectTextRevealReady(state: TextRevealState) {
119
+ return state.status === "idle" || state.status === "swapping"
120
+ }
121
+
122
+ export function selectTextRevealSwapping(state: TextRevealState) {
123
+ return state.status === "swapping"
124
+ }
125
+
126
+ export function selectTextRevealEntering(state: TextRevealState) {
127
+ return (state.status === "disposed" ? undefined : state.current) ?? "\u00A0"
128
+ }
129
+
130
+ export function selectTextRevealLeaving(state: TextRevealState) {
131
+ return (state.status === "idle" || state.status === "swapping" ? state.leaving : undefined) ?? "\u00A0"
132
+ }
133
+
134
+ export function selectTextRevealTrackWidth(state: TextRevealState, truncate: boolean | undefined) {
135
+ if (truncate) return "100%"
136
+
137
+ return state.status !== "disposed" && state.widthPx > 0 ? `${state.widthPx}px` : "auto"
138
+ }
139
+
140
+ function changeText(
141
+ state: Exclude<TextRevealState, { status: "disposed" }>,
142
+ text: string | undefined,
143
+ ): TextRevealTransition {
144
+ if (text === state.current) return { state, effects: NO_EFFECTS }
145
+
146
+ // Before the first paint nothing is on screen to wipe out, so the new text just replaces the old.
147
+ if (state.status === "measuring") return { state: { ...state, current: text }, effects: [MEASURE] }
148
+
149
+ if (state.status === "idle" && state.current !== undefined && text?.startsWith(state.current)) {
150
+ return { state: { ...state, current: text }, effects: [MEASURE] }
151
+ }
152
+
153
+ // Changing back to the text still on screen cancels the swap that never painted.
154
+ if (state.status === "swapping" && text === state.leaving) {
155
+ return {
156
+ state: { status: "idle", issued: state.attempt, current: text, leaving: undefined, widthPx: state.widthPx },
157
+ effects: [CANCEL_FRAME, MEASURE],
158
+ }
159
+ }
160
+
161
+ if (state.status === "swapping") {
162
+ const attempt = state.attempt + 1
163
+
164
+ return {
165
+ state: { ...state, attempt, current: text },
166
+ effects: [CANCEL_FRAME, { type: "swap.frame", attempt }],
167
+ }
168
+ }
169
+
170
+ const attempt = state.issued + 1
171
+
172
+ return {
173
+ state: { status: "swapping", attempt, current: text, leaving: state.current, widthPx: state.widthPx },
174
+ effects: [{ type: "swap.frame", attempt }],
175
+ }
176
+ }
177
+
178
+ function widen(prev: number, measured: Measured) {
179
+ if (measured.widthPx <= 0) return prev
180
+
181
+ if (measured.growOnly && prev > 0 && measured.widthPx <= prev) return prev
182
+
183
+ return measured.widthPx
184
+ }
@@ -1,20 +1,23 @@
1
- import { createEffect, on, onCleanup, onMount } from "solid-js"
2
- import { createStore } from "solid-js/store"
3
-
4
- const px = (value: number | string | undefined, fallback: number) => {
5
- if (typeof value === "number") return `${value}px`
6
-
7
- if (typeof value === "string") return value
8
-
9
- return `${fallback}px`
10
- }
11
-
12
- const ms = (value: number | string | undefined, fallback: number) => {
13
- if (typeof value === "number") return `${value}ms`
14
-
15
- if (typeof value === "string") return value
16
-
17
- return `${fallback}ms`
1
+ import { createEffect, createSignal, onCleanup, onMount, untrack } from "solid-js"
2
+ import {
3
+ createTextRevealState,
4
+ selectTextRevealEntering,
5
+ selectTextRevealLeaving,
6
+ selectTextRevealReady,
7
+ selectTextRevealSwapping,
8
+ selectTextRevealTrackWidth,
9
+ TEXT_REVEAL_READY_TIMEOUT_MS,
10
+ transitionTextReveal,
11
+ type TextRevealEffect,
12
+ type TextRevealEvent,
13
+ } from "./text-reveal-machine"
14
+
15
+ // A number gets the unit; a string is already a CSS value.
16
+ const css = (value: number | string | undefined, fallback: number, unit: "px" | "ms") => {
17
+ if (value === undefined) return `${fallback}${unit}`
18
+
19
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- discriminates this prop's own `number | string` union
20
+ return typeof value === "number" ? `${value}${unit}` : value
18
21
  }
19
22
 
20
23
  const pct = (value: number | undefined, fallback: number) => {
@@ -36,125 +39,125 @@ export function TextReveal(props: {
36
39
  growOnly?: boolean
37
40
  truncate?: boolean
38
41
  }) {
39
- const [state, setState] = createStore({
40
- cur: props.text,
41
- old: undefined as string | undefined,
42
- width: "auto",
43
- ready: false,
44
- swapping: false,
45
- })
46
-
47
- const cur = () => state.cur
48
- const old = () => state.old
49
- const width = () => state.width
50
- const ready = () => state.ready
51
- const swapping = () => state.swapping
42
+ const [machine, setMachine] = createSignal(createTextRevealState(props.text))
52
43
  let inRef: HTMLSpanElement | undefined
53
44
  let outRef: HTMLSpanElement | undefined
54
45
  let rootRef: HTMLSpanElement | undefined
55
46
  let frame: number | undefined
47
+ let readyTimer: ReturnType<typeof setTimeout> | undefined
56
48
 
57
49
  const win = () => inRef?.scrollWidth ?? 0
58
50
  const wout = () => outRef?.scrollWidth ?? 0
51
+ const growOnly = () => props.growOnly ?? true
52
+ // oxlint-disable-next-line anti-slop/no-runtime-typeof -- probing for a browser global; SSR has no frames
53
+ const animates = typeof requestAnimationFrame === "function"
59
54
 
60
- const widen = (next: number) => {
61
- if (next <= 0) return
55
+ const dispatch = (event: TextRevealEvent) => {
56
+ const next = transitionTextReveal(untrack(machine), event)
62
57
 
63
- if (props.growOnly ?? true) {
64
- const prev = Number.parseFloat(width())
58
+ // Commit first: the effects measure the text nodes this state renders.
59
+ if (next.state !== untrack(machine)) setMachine(next.state)
60
+ next.effects.forEach(run)
61
+ }
65
62
 
66
- if (Number.isFinite(prev) && next <= prev) return
67
- }
63
+ const cancelFrame = () => {
64
+ if (frame !== undefined) cancelAnimationFrame(frame)
65
+ frame = undefined
66
+ }
68
67
 
69
- setState("width", `${next}px`)
68
+ const onFrame = (finish: () => void) => {
69
+ cancelFrame()
70
+
71
+ if (!animates) return finish()
72
+ frame = requestAnimationFrame(() => {
73
+ frame = undefined
74
+ finish()
75
+ })
70
76
  }
71
77
 
72
- createEffect(
73
- on(
74
- () => props.text,
75
- (next, prev) => {
76
- if (next === prev) return
77
-
78
- if (typeof next === "string" && typeof prev === "string" && next.startsWith(prev)) {
79
- setState("cur", next)
80
- widen(win())
81
-
82
- return
83
- }
84
-
85
- setState("swapping", true)
86
- setState("old", prev)
87
- setState("cur", next)
88
-
89
- if (typeof requestAnimationFrame !== "function") {
90
- widen(Math.max(win(), wout()))
91
- rootRef?.offsetHeight
92
- setState("swapping", false)
93
-
94
- return
95
- }
96
-
97
- if (frame !== undefined && typeof cancelAnimationFrame === "function") cancelAnimationFrame(frame)
98
- frame = requestAnimationFrame(() => {
99
- widen(Math.max(win(), wout()))
100
- rootRef?.offsetHeight
101
- setState("swapping", false)
102
- frame = undefined
103
- })
104
- },
105
- ),
106
- )
78
+ const run = (effect: TextRevealEffect) => {
79
+ if (effect.type === "measure.entering") {
80
+ dispatch({ type: "width.measured", widthPx: win(), growOnly: growOnly() })
107
81
 
108
- onMount(() => {
109
- widen(win())
110
- const fonts = typeof document !== "undefined" ? document.fonts : undefined
82
+ return
83
+ }
111
84
 
112
- if (typeof requestAnimationFrame !== "function") {
113
- setState("ready", true)
85
+ if (effect.type === "ready.frame") {
86
+ onFrame(() => dispatch({ type: "ready.settled", widthPx: win(), growOnly: growOnly() }))
114
87
 
115
88
  return
116
89
  }
117
90
 
118
- if (!fonts) {
119
- requestAnimationFrame(() => setState("ready", true))
91
+ if (effect.type === "swap.frame") {
92
+ onFrame(() => {
93
+ const widthPx = Math.max(win(), wout())
94
+ rootRef?.offsetHeight
95
+ dispatch({ type: "swap.settled", attempt: effect.attempt, widthPx, growOnly: growOnly() })
96
+ })
120
97
 
121
98
  return
122
99
  }
123
100
 
124
- void fonts.ready.finally(() => {
125
- widen(win())
126
- requestAnimationFrame(() => setState("ready", true))
127
- })
101
+ if (effect.type === "cancel.frame") {
102
+ cancelFrame()
103
+
104
+ return
105
+ }
106
+
107
+ clearTimeout(readyTimer)
108
+ readyTimer = undefined
109
+ }
110
+
111
+ createEffect(() => {
112
+ const text = props.text
113
+ untrack(() => dispatch({ type: "text.changed", text }))
128
114
  })
129
115
 
130
- onCleanup(() => {
131
- if (frame === undefined || typeof cancelAnimationFrame !== "function") return
132
- cancelAnimationFrame(frame)
116
+ onMount(() => {
117
+ dispatch({ type: "width.measured", widthPx: win(), growOnly: growOnly() })
118
+
119
+ if (!animates) {
120
+ dispatch({ type: "ready.settled", widthPx: win(), growOnly: growOnly() })
121
+
122
+ return
123
+ }
124
+
125
+ readyTimer = setTimeout(
126
+ () => dispatch({ type: "ready.timed-out", widthPx: win(), growOnly: growOnly() }),
127
+ TEXT_REVEAL_READY_TIMEOUT_MS,
128
+ )
129
+ const fonts = typeof document !== "undefined" ? document.fonts : undefined
130
+ const settle = () => dispatch({ type: "fonts.settled", widthPx: win(), growOnly: growOnly() })
131
+
132
+ if (!fonts) return settle()
133
+ void fonts.ready.finally(settle)
133
134
  })
134
135
 
136
+ onCleanup(() => dispatch({ type: "disposed" }))
137
+
135
138
  return (
136
139
  <span
137
140
  ref={rootRef}
138
141
  data-component="text-reveal"
139
- data-ready={ready() ? "true" : "false"}
140
- data-swapping={swapping() ? "true" : "false"}
142
+ data-ready={selectTextRevealReady(machine()) ? "true" : "false"}
143
+ data-swapping={selectTextRevealSwapping(machine()) ? "true" : "false"}
141
144
  data-truncate={props.truncate ? "true" : "false"}
142
145
  class={props.class}
143
146
  aria-label={props.text ?? ""}
144
147
  style={{
145
- "--text-reveal-duration": ms(props.duration, 450),
148
+ "--text-reveal-duration": css(props.duration, 450, "ms"),
146
149
  "--text-reveal-edge": pct(props.edge, 17),
147
- "--text-reveal-travel": px(props.travel, 0),
150
+ "--text-reveal-travel": css(props.travel, 0, "px"),
148
151
  "--text-reveal-spring": props.spring ?? "cubic-bezier(0.34, 1.08, 0.64, 1)",
149
152
  "--text-reveal-spring-soft": props.springSoft ?? "cubic-bezier(0.34, 1, 0.64, 1)",
150
153
  }}
151
154
  >
152
- <span data-slot="text-reveal-track" style={{ width: props.truncate ? "100%" : width() }}>
155
+ <span data-slot="text-reveal-track" style={{ width: selectTextRevealTrackWidth(machine(), props.truncate) }}>
153
156
  <span data-slot="text-reveal-entering" ref={inRef}>
154
- {cur() ?? "\u00A0"}
157
+ {selectTextRevealEntering(machine())}
155
158
  </span>
156
159
  <span data-slot="text-reveal-leaving" ref={outRef}>
157
- {old() ?? "\u00A0"}
160
+ {selectTextRevealLeaving(machine())}
158
161
  </span>
159
162
  </span>
160
163
  </span>