arc-ui 0.4.0

Physics-first native Rust desktop UI component library & charts for GPUI (120+ interactive components ported from Arc).
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
//! Ported from Arc (MIT) © 2026 Elia Kuratli
//! Source: `Arc源码/arc-library/registry/components/countdown/countdown.tsx` & `countdown.module.css`
//!
//! A fixed-moment countdown (`countdown`) for launches, live events, and deadlines:
//! - Splits remaining seconds across the requested units (`Days`, `Hours`, `Minutes`, `Seconds`),
//!   sorted largest-first so the leading unit absorbs overflow (`countdown_split_units`).
//! - Shortest-path digit wheels (`countdown_wheel_shortest_target`) with column-specific modular
//!   bases (`countdown_wheel_bases`: `3` for hours tens, `6` for minutes/seconds tens, `10` for ones
//!   and largest-unit columns) so `00 -> 59` or `00 -> 23` wraps in a single step.
//! - Supports `Large` (display typography with unit labels and colons) and `Compact` (`32px` pill
//!   with inline `d / h / m / s` letters) variants.
//! - Morphs into `complete_label` with a pulsing green live indicator dot (`2.0s` cycle) and fires
//!   `on_complete` once when reaching zero.

use std::{cell::RefCell, rc::Rc};

use arc_motion::{arc_spring, is_reduced_motion, motion_now};
use arc_tokens::{
    ActiveArcLocale as _, ActiveArcTheme as _, Locale, Radii, Spacing, Typography, oklab_mix,
};
use gpui_kit::{
    AnyElement, App, Bounds, Corners, Edges, ElementId, IntoElement, ParentElement, RenderOnce,
    Role, SharedString, Styled, Window, base::StyledExt as _, canvas, div, point, prelude::*, px,
    quad,
};

type CompleteCallback = Rc<dyn Fn(&(), &mut Window, &mut App)>;

/// Time unit displayed in [`Countdown`].
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
pub enum CountdownUnit {
    Days,
    Hours,
    Minutes,
    Seconds,
}

impl CountdownUnit {
    pub const DEFAULT_ALL: [CountdownUnit; 4] = [
        CountdownUnit::Days,
        CountdownUnit::Hours,
        CountdownUnit::Minutes,
        CountdownUnit::Seconds,
    ];

    #[inline]
    pub const fn seconds_per_unit(self) -> u64 {
        match self {
            Self::Days => 86_400,
            Self::Hours => 3_600,
            Self::Minutes => 60,
            Self::Seconds => 1,
        }
    }

    #[inline]
    pub const fn wrap_limit(self) -> Option<u64> {
        match self {
            Self::Days => None,
            Self::Hours => Some(24),
            Self::Minutes | Self::Seconds => Some(60),
        }
    }

    #[inline]
    pub const fn label_large(self, locale: Locale) -> &'static str {
        match self {
            Self::Days => locale.text("天", "Days"),
            Self::Hours => locale.text("时", "Hours"),
            Self::Minutes => locale.text("分", "Minutes"),
            Self::Seconds => locale.text("秒", "Seconds"),
        }
    }

    #[inline]
    pub const fn label_compact(self) -> &'static str {
        match self {
            Self::Days => "d",
            Self::Hours => "h",
            Self::Minutes => "m",
            Self::Seconds => "s",
        }
    }
}

/// Visual size / layout variant of [`Countdown`].
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Hash)]
pub enum CountdownVariant {
    #[default]
    Large,
    Compact,
}

/// Splits `total_seconds` across `units` (automatically sorted largest-first and deduplicated).
///
/// The largest unit absorbs all remaining whole units without modulo wrapping, so if `Days` is
/// omitted, `Hours` can exceed `24`.
pub fn countdown_split_units(
    total_seconds: u64,
    units: &[CountdownUnit],
) -> Vec<(CountdownUnit, u64)> {
    let mut sorted: Vec<CountdownUnit> = if units.is_empty() {
        CountdownUnit::DEFAULT_ALL.to_vec()
    } else {
        units.to_vec()
    };
    sorted.sort_by_key(|u| std::cmp::Reverse(u.seconds_per_unit()));
    sorted.dedup();

    sorted
        .into_iter()
        .enumerate()
        .map(|(index, unit)| {
            let divisor = unit.seconds_per_unit();
            let raw = total_seconds / divisor;
            let val = if index == 0 {
                raw
            } else if let Some(limit) = unit.wrap_limit() {
                raw % limit
            } else {
                raw
            };
            (unit, val)
        })
        .collect()
}

/// Returns the modular wheel base for each digit column of `unit`.
///
/// Mirrors `basesFor(unit, largest, length)` in `countdown.tsx`:
/// - For non-largest two-digit groups, the tens column uses base `3` for `Hours` (`0..=2`) and
///   base `6` for `Minutes`/`Seconds` (`0..=5`), so `00 -> 59` wraps in a single step.
/// - All other columns use base `10`.
pub fn countdown_wheel_bases(
    unit: CountdownUnit,
    is_largest: bool,
    digit_count: usize,
) -> Vec<u32> {
    (0..digit_count)
        .map(|index| {
            let is_tens = digit_count == 2 && index == 0 && !is_largest;
            if is_tens {
                match unit {
                    CountdownUnit::Hours => 3,
                    _ => 6,
                }
            } else {
                10
            }
        })
        .collect()
}

/// Computes the next cumulative wheel target position taking the shortest path around a modular
/// wheel of size `base` from `prev_digit` to `next_digit`.
#[inline]
pub fn countdown_wheel_shortest_target(
    prev_target: f32,
    prev_digit: u32,
    next_digit: u32,
    base: u32,
) -> f32 {
    let base = base.max(1);
    if prev_digit == next_digit {
        return prev_target;
    }
    let up = (next_digit + base - (prev_digit % base)) % base;
    let down = base - up;
    let delta = if down <= up {
        -(down as f32)
    } else {
        up as f32
    };
    prev_target + delta
}

/// Computes the signed circular offset (`-base/2 .. +base/2`) of `digit` relative to continuous
/// wheel position `wheel_pos` on a wheel of size `base`.
#[inline]
pub fn countdown_wheel_digit_offset(wheel_pos: f32, digit: u32, base: u32) -> f32 {
    let b = (base.max(1)) as f32;

    ((digit as f32 - wheel_pos) % b + b * 1.5) % b - b * 0.5
}

#[derive(Clone)]
struct CountdownInternalState {
    anchor_now: f64,
    last_initial_secs: u64,
    last_reset_nonce: u64,
    fired_complete: bool,
    wheel_targets: Vec<(u32, f32)>,
}

/// Fixed-moment / duration countdown component (`countdown`).
#[derive(IntoElement)]
pub struct Countdown {
    id: ElementId,
    /// Remaining seconds from mount (or from the latest `reset_nonce` / `initial_seconds` change)
    /// when running in self-ticking mode.
    initial_seconds: u64,
    /// Optional controlled remaining seconds override.
    remaining_seconds: Option<u64>,
    /// Monotonic nonce allowing callers to restart the countdown to `initial_seconds`.
    reset_nonce: u64,
    paused: bool,
    units: Vec<CountdownUnit>,
    variant: CountdownVariant,
    complete_label: Option<SharedString>,
    label: SharedString,
    on_complete: Option<CompleteCallback>,
}

impl Countdown {
    pub fn new(id: impl Into<ElementId>, initial_seconds: u64) -> Self {
        Self {
            id: id.into(),
            initial_seconds,
            remaining_seconds: None,
            reset_nonce: 0,
            paused: false,
            units: CountdownUnit::DEFAULT_ALL.to_vec(),
            variant: CountdownVariant::Large,
            complete_label: None,
            label: SharedString::from("Time remaining"),
            on_complete: None,
        }
    }

    /// Overrides the countdown with an explicit controlled remaining seconds value.
    pub fn remaining_seconds(mut self, seconds: u64) -> Self {
        self.remaining_seconds = Some(seconds);
        self
    }

    /// Bumping `nonce` restarts the internal countdown clock back to `initial_seconds`.
    pub fn reset_nonce(mut self, nonce: u64) -> Self {
        self.reset_nonce = nonce;
        self
    }

    pub fn paused(mut self, paused: bool) -> Self {
        self.paused = paused;
        self
    }

    pub fn units(mut self, units: impl IntoIterator<Item = CountdownUnit>) -> Self {
        self.units = units.into_iter().collect();
        self
    }

    pub fn variant(mut self, variant: CountdownVariant) -> Self {
        self.variant = variant;
        self
    }

    pub fn complete_label(mut self, label: impl Into<SharedString>) -> Self {
        self.complete_label = Some(label.into());
        self
    }

    pub fn label(mut self, label: impl Into<SharedString>) -> Self {
        self.label = label.into();
        self
    }

    pub fn on_complete(mut self, callback: impl Fn(&(), &mut Window, &mut App) + 'static) -> Self {
        self.on_complete = Some(Rc::new(callback));
        self
    }
}

impl RenderOnce for Countdown {
    fn render(self, window: &mut Window, cx: &mut App) -> impl IntoElement {
        let theme = cx.arc_theme();
        let colors = theme.colors;
        let motion = theme.motion;
        let locale = cx.arc_locale();
        let reduced = is_reduced_motion(cx);
        let now = motion_now(cx);

        let state_cell = window
            .use_keyed_state(
                ElementId::NamedChild(
                    self.id.clone().into(),
                    SharedString::from("countdown-state"),
                ),
                cx,
                |_, _| {
                    Rc::new(RefCell::new(CountdownInternalState {
                        anchor_now: now,
                        last_initial_secs: self.initial_seconds,
                        last_reset_nonce: self.reset_nonce,
                        fired_complete: false,
                        wheel_targets: Vec::new(),
                    }))
                },
            )
            .read(cx)
            .clone();

        let (seconds_left, should_fire_complete) = {
            let mut st = state_cell.borrow_mut();
            if st.last_initial_secs != self.initial_seconds
                || st.last_reset_nonce != self.reset_nonce
            {
                st.anchor_now = now;
                st.last_initial_secs = self.initial_seconds;
                st.last_reset_nonce = self.reset_nonce;
                st.fired_complete = false;
            }

            let left = if let Some(explicit) = self.remaining_seconds {
                explicit
            } else if self.paused {
                // Keep anchor sliding while paused so remaining time freezes
                let elapsed = (now - st.anchor_now).max(0.0);
                let frozen_left = (self.initial_seconds as f64 - elapsed).ceil().max(0.0) as u64;
                st.anchor_now = now - (self.initial_seconds.saturating_sub(frozen_left)) as f64;
                frozen_left
            } else {
                let elapsed = (now - st.anchor_now).max(0.0);
                (self.initial_seconds as f64 - elapsed).ceil().max(0.0) as u64
            };

            let fire = if left == 0 && !st.fired_complete && self.initial_seconds > 0 {
                st.fired_complete = true;
                true
            } else {
                false
            };
            (left, fire)
        };

        if should_fire_complete && let Some(cb) = self.on_complete.clone() {
            window.defer(cx, move |window, cx| {
                cb(&(), window, cx);
            });
        }

        let is_complete = seconds_left == 0;
        let is_compact = self.variant == CountdownVariant::Compact;
        let mut needs_anim_frame = !self.paused && !is_complete && self.remaining_seconds.is_none();

        let complete_text = self
            .complete_label
            .unwrap_or_else(|| SharedString::from(locale.text("已开始 Live now", "Live now")));

        let parts = countdown_split_units(seconds_left, &self.units);

        // Flatten all digit columns across groups to maintain stable wheel targets
        let mut flat_columns: Vec<(CountdownUnit, usize, usize, u32, u32)> = Vec::new();
        for (group_idx, (unit, value)) in parts.iter().enumerate() {
            let text = format!("{value:02}");
            let bases = countdown_wheel_bases(*unit, group_idx == 0, text.len());
            for (col_idx, ch) in text.chars().enumerate() {
                let digit = ch.to_digit(10).unwrap_or(0);
                let base = bases.get(col_idx).copied().unwrap_or(10);
                flat_columns.push((*unit, group_idx, col_idx, digit, base));
            }
        }

        // Update shortest-path cumulative wheel targets
        let column_targets: Vec<f32> = {
            let mut st = state_cell.borrow_mut();
            if st.wheel_targets.len() != flat_columns.len() {
                st.wheel_targets = flat_columns
                    .iter()
                    .map(|(_, _, _, digit, _)| (*digit, *digit as f32))
                    .collect();
            }
            let mut out = Vec::with_capacity(flat_columns.len());
            for (i, (_, _, _, digit, base)) in flat_columns.iter().enumerate() {
                let (prev_digit, prev_target) = st.wheel_targets[i];
                let next_target =
                    countdown_wheel_shortest_target(prev_target, prev_digit, *digit, *base);
                st.wheel_targets[i] = (*digit, next_target);
                out.push(next_target);
            }
            out
        };

        let body_el: AnyElement = if is_complete {
            // Complete badge with pulsing green live dot
            let pulse_phase = if reduced {
                0.0
            } else {
                needs_anim_frame = true;
                ((now * 0.5).fract()) as f32
            };
            let dot_size = if is_compact { 8.0 } else { 11.0 };
            let success_color = colors.success;

            let live_dot = div()
                .relative()
                .size(px(dot_size * 2.4))
                .flex_none()
                .flex()
                .items_center()
                .justify_center()
                .child(
                    canvas(
                        move |bounds, _window, _cx| bounds,
                        move |bounds: Bounds<gpui_kit::Pixels>, _, window, _cx| {
                            let cx_pt = bounds.origin.x + bounds.size.width * 0.5;
                            let cy_pt = bounds.origin.y + bounds.size.height * 0.5;

                            // Expanding ripple ring (`0..0.7` of the 2s cycle)
                            if !reduced && pulse_phase < 0.75 {
                                let t = (pulse_phase / 0.75).clamp(0.0, 1.0);
                                let ring_scale = 1.0 + 1.6 * t;
                                let ring_alpha = 0.48 * (1.0 - t);
                                let ring_d = dot_size * ring_scale;
                                let mut c = success_color;
                                c.a *= ring_alpha;
                                window.paint_quad(quad(
                                    Bounds::new(
                                        point(cx_pt - px(ring_d * 0.5), cy_pt - px(ring_d * 0.5)),
                                        gpui_kit::size(px(ring_d), px(ring_d)),
                                    ),
                                    Corners::all(px(ring_d)),
                                    c,
                                    Edges::all(px(0.0)),
                                    gpui_kit::transparent_black(),
                                    gpui_kit::BorderStyle::default(),
                                ));
                            }

                            // Solid center dot
                            window.paint_quad(quad(
                                Bounds::new(
                                    point(cx_pt - px(dot_size * 0.5), cy_pt - px(dot_size * 0.5)),
                                    gpui_kit::size(px(dot_size), px(dot_size)),
                                ),
                                Corners::all(px(dot_size)),
                                success_color,
                                Edges::all(px(0.0)),
                                gpui_kit::transparent_black(),
                                gpui_kit::BorderStyle::default(),
                            ));
                        },
                    )
                    .size_full(),
                );

            div()
                .flex()
                .flex_row()
                .items_center()
                .gap(if is_compact { px(4.0) } else { px(8.0) })
                .child(live_dot)
                .child(
                    div()
                        .text_size(if is_compact {
                            Typography::TEXT_SM
                        } else {
                            px(28.0)
                        })
                        .font_medium()
                        .text_color(if is_compact {
                            colors.success
                        } else {
                            colors.foreground
                        })
                        .child(complete_text),
                )
                .into_any_element()
        } else {
            // Render unit groups and rolling digit wheels
            let digit_h = if is_compact { 20.0 } else { 44.0 };
            let digit_w = if is_compact { 9.5 } else { 24.0 };
            let digit_font = if is_compact {
                Typography::TEXT_SM
            } else {
                px(36.0)
            };

            let mut flat_cursor = 0usize;
            let mut group_els: Vec<AnyElement> = Vec::with_capacity(parts.len());

            for (group_idx, (unit, value)) in parts.iter().enumerate() {
                let text = format!("{value:02}");
                let col_count = text.chars().count();
                let mut wheel_els: Vec<AnyElement> = Vec::with_capacity(col_count);

                for col_idx in 0..col_count {
                    let (_, _, _, digit, base) = flat_columns[flat_cursor];
                    let target_pos = column_targets[flat_cursor];
                    flat_cursor += 1;

                    let wheel_pos = if reduced {
                        target_pos
                    } else {
                        let s = arc_spring(
                            ElementId::NamedChild(
                                self.id.clone().into(),
                                SharedString::from(format!("wheel-{group_idx}-{col_idx}")),
                            ),
                            target_pos,
                            motion.spring.snappy,
                            window,
                            cx,
                        );
                        if (s - target_pos).abs() > 0.002 {
                            needs_anim_frame = true;
                        }
                        s
                    };

                    // Render visible digits on the modular wheel (`|offset| < 1.0`)
                    let mut wheel_box = div()
                        .relative()
                        .w(px(digit_w))
                        .h(px(digit_h))
                        .overflow_hidden();

                    for candidate in 0..base {
                        let offset = countdown_wheel_digit_offset(wheel_pos, candidate, base);
                        if offset.abs() < 0.98 {
                            let opacity = (1.0 - offset.abs()).clamp(0.0, 1.0);
                            let y_px = offset * digit_h;
                            let mut fg = colors.foreground;
                            fg.a *= opacity;

                            wheel_box = wheel_box.child(
                                div()
                                    .absolute()
                                    .left_0()
                                    .top(px(y_px))
                                    .w(px(digit_w))
                                    .h(px(digit_h))
                                    .flex()
                                    .items_center()
                                    .justify_center()
                                    .text_size(digit_font)
                                    .font_medium()
                                    .text_color(fg)
                                    .child(SharedString::from(format!("{candidate}"))),
                            );
                        } else if reduced && candidate == digit {
                            wheel_box = wheel_box.child(
                                div()
                                    .size_full()
                                    .flex()
                                    .items_center()
                                    .justify_center()
                                    .text_size(digit_font)
                                    .font_medium()
                                    .text_color(colors.foreground)
                                    .child(SharedString::from(format!("{candidate}"))),
                            );
                        }
                    }

                    wheel_els.push(wheel_box.into_any_element());
                }

                let group_node = if is_compact {
                    div()
                        .flex()
                        .flex_row()
                        .items_baseline()
                        .gap(px(1.0))
                        .child(div().flex().flex_row().items_center().children(wheel_els))
                        .child(
                            div()
                                .text_size(Typography::TEXT_SM)
                                .text_color(colors.text_muted)
                                .child(unit.label_compact()),
                        )
                        .into_any_element()
                } else {
                    div()
                        .flex()
                        .flex_row()
                        .items_start()
                        .when(group_idx > 0, |this| {
                            let mut colon_c = colors.text_muted;
                            colon_c.a *= 0.6;
                            this.child(
                                div()
                                    .h(px(digit_h))
                                    .px(px(6.0))
                                    .flex()
                                    .items_center()
                                    .justify_center()
                                    .text_size(px(32.0))
                                    .font_medium()
                                    .text_color(colon_c)
                                    .child(":"),
                            )
                        })
                        .child(
                            div()
                                .min_w(px(58.0))
                                .flex()
                                .flex_col()
                                .items_center()
                                .gap(px(6.0))
                                .child(div().flex().flex_row().items_center().children(wheel_els))
                                .child(
                                    div()
                                        .text_size(Typography::TEXT_XS)
                                        .text_color(colors.text_muted)
                                        .child(unit.label_large(locale)),
                                ),
                        )
                        .into_any_element()
                };

                group_els.push(group_node);
            }

            div()
                .flex()
                .flex_row()
                .items_center()
                .gap(if is_compact { px(6.0) } else { px(0.0) })
                .children(group_els)
                .into_any_element()
        };

        if needs_anim_frame {
            window.request_animation_frame();
        }

        if is_compact {
            let (border_c, bg_c) = if is_complete {
                (
                    oklab_mix(colors.success, colors.border, 0.35),
                    oklab_mix(colors.success, colors.surface, 0.09),
                )
            } else {
                (colors.border, colors.surface)
            };

            div()
                .id(self.id)
                .role(Role::Group)
                .min_h(px(32.0))
                .px(Spacing::S3)
                .rounded(Radii::PILL)
                .border_1()
                .border_color(border_c)
                .bg(bg_c)
                .flex()
                .flex_row()
                .items_center()
                .justify_center()
                .child(body_el)
        } else {
            div()
                .id(self.id)
                .role(Role::Group)
                .w_full()
                .flex()
                .flex_row()
                .items_center()
                .justify_center()
                .child(body_el)
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn countdown_split_units_lets_largest_unit_absorb_overflow() {
        // 1 day (86400) + 5 hours (18000) + 12 minutes (720) + 9 seconds = 105_129s
        let all = countdown_split_units(105_129, &CountdownUnit::DEFAULT_ALL);
        assert_eq!(
            all,
            vec![
                (CountdownUnit::Days, 1),
                (CountdownUnit::Hours, 5),
                (CountdownUnit::Minutes, 12),
                (CountdownUnit::Seconds, 9),
            ]
        );

        // Without Days, Hours absorbs the full 29 hours
        let hms = countdown_split_units(
            105_129,
            &[
                CountdownUnit::Hours,
                CountdownUnit::Minutes,
                CountdownUnit::Seconds,
            ],
        );
        assert_eq!(
            hms,
            vec![
                (CountdownUnit::Hours, 29),
                (CountdownUnit::Minutes, 12),
                (CountdownUnit::Seconds, 9),
            ]
        );
    }

    #[test]
    fn countdown_wheel_bases_and_shortest_path_wrap_00_to_59_in_one_step() {
        // Minutes (not largest): tens column has base 6, ones column has base 10
        assert_eq!(
            countdown_wheel_bases(CountdownUnit::Minutes, false, 2),
            vec![6, 10]
        );
        // Hours (not largest): tens column has base 3, ones column has base 10
        assert_eq!(
            countdown_wheel_bases(CountdownUnit::Hours, false, 2),
            vec![3, 10]
        );
        // Largest unit: all columns use base 10
        assert_eq!(
            countdown_wheel_bases(CountdownUnit::Hours, true, 2),
            vec![10, 10]
        );

        // Wrapping 0 -> 5 on a base-6 tens wheel moves by -1 step (downward), not +5
        let t1 = countdown_wheel_shortest_target(0.0, 0, 5, 6);
        assert!((t1 - (-1.0)).abs() < 1e-6);

        // Wrapping 0 -> 9 on a base-10 ones wheel moves by -1 step
        let t2 = countdown_wheel_shortest_target(0.0, 0, 9, 10);
        assert!((t2 - (-1.0)).abs() < 1e-6);
    }
}