fix(adom): parity fixes from the runed audit (IsIdle, IsInViewport)

A line-by-line audit of the ports against runed's original source found two
faithfulness regressions in unused F3 utilities:

- IsIdle seeded `lastActive` to 0 (epoch) instead of the construction
  timestamp, so `Date.now() - lastActive` read ~56 years until first activity.
  Now `$state(Date.now())`, matching runed.
- IsInViewport passed `threshold: undefined`, which the IntersectionObserver
  spec coerces to 0 (fires at a single pixel). runed defaults it to 0.1;
  restored (and rootMargin -> '0px').

Guarded IsIdle's baseline in its test. check=59.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
menubar-v4-safe
dev 3 months ago
parent 2fdfbae3c9
commit d56572f156

@ -17,6 +17,8 @@ describe('IsIdle', () => {
flushSync();
});
expect(idle.current).toBe(false);
// lastActive is seeded to the construction time, not the epoch.
expect(idle.lastActive).toBeGreaterThan(0);
await vi.advanceTimersByTimeAsync(1000);
expect(idle.current).toBe(true);

@ -32,7 +32,9 @@ export type IsIdleOptions = {
export class IsIdle {
#current = $state(false);
#lastActive = $state(0);
// Baseline is the construction instant (matching runed), so `lastActive` is a
// plausible timestamp before any activity — not the epoch.
#lastActive = $state(Date.now());
constructor(options: IsIdleOptions = {}) {
const win = options.window ?? (isBrowser ? window : undefined);
@ -44,7 +46,6 @@ export class IsIdle {
const detectVisibilityChanges = $derived(toValue(options.detectVisibilityChanges) ?? false);
const trackLastActive = options.trackLastActive ?? true;
this.#current = options.initialState ?? false;
this.#lastActive = 0;
const debouncedReset = debounce(
() => {

@ -37,7 +37,13 @@ export class IsInViewport {
}
this.#isInViewport = isIntersecting;
},
{ root: options.root, rootMargin: options.rootMargin, threshold: options.threshold }
{
root: options.root,
rootMargin: options.rootMargin ?? '0px',
// Match runed's default (0.1) — an unset threshold otherwise coerces to 0,
// firing at a single pixel instead of once ~10% is in view.
threshold: options.threshold ?? 0.1
}
);
observer.observe(el);
return () => observer.disconnect();

Loading…
Cancel
Save

Powered by TurnKey Linux.