Skip to content

Commit 929e22f

Browse files
authored
Give the page one module for what it does in response to the viewport (#9)
* Give the page one module for what it does in response to the viewport Three questions were each answered separately, in three files: has this come into view, has the pointer or the page moved since the last frame, and how deep is each card in this sticky stack. lib/motion is now one seam for all three, and lib/use-reveal.ts is gone into it. The sticky-depth arithmetic was 24 lines inside a useEffect closure, so the only way to check it was to scroll the page by hand and watch the cards. It is now stackDepths, pure, and the 2px tolerance that decides whether a card counts as arrived is a parameter with nine tests rather than a magic number visible in exactly one place. The tests caught my own misreading of it twice on the way in: depth is what is stacked ON a card, not how far down it is, so one card arriving raises the depth of all three below it. useFrameCallback is the rAF coalescing three call sites hand-rolled in three shapes, and the easing curves were written out ten times across four files. The curves are three, not one — the curtain retracts on a symmetric ease-in-out and the letters leave on a slow-out one — so they are named rather than collapsed into a single constant that would be wrong in two of three places. The two reveal recipes are deliberately not merged. The bento card fades and lifts, the heading also blurs, and the distances differ; unifying them means flags, and a flag is a prop with two meanings and no name. ADR-0003 said a second test file carries the decision to add the test script, the turbo task and the CI step. That condition is met, so all three are here and CI runs `pnpm test`. The gate was verified to turn the task red: setting the tolerance to 0 fails a test and fails the build. oxlint.config.ts gains one override. promise/prefer-await-to-callbacks fires on requestAnimationFrame inside useFrameCallback, where a frame callback is not a promise: it fires on the next paint whether or not anything awaits it, and the callers are a mousemove and a scroll listener. Scoped to lib/motion.ts by overrides, and confirmed still firing on a probe file outside it. * Quote the test glob so the runner finds files on Node 24 CI failed on the Test step: node --test lib/ was resolved as a module path rather than a directory to search, and Node 24 has no directory discovery — the argument is matched as a literal glob, resolves to the directory itself, and then gets run as a test file (nodejs/node#64555). The local machine is on Node 26, where the same command worked, which is why it passed here and failed there. The repo pins 24.x in engines and CI, and that pin is deliberate: a previous commit moved CI to 24 because it had been validating a runtime nothing deployed on. node --test "lib/*.test.ts" is the documented form. The quotes matter and have to be double: an unquoted pattern is expanded by the shell rather than by Node, which is why it works interactively and fails under a package script on a different shell. Verified on node 24.20.0, the version CI runs: the directory form fails with MODULE_NOT_FOUND, the quoted glob passes 17. The full gate — lint, typecheck, test, build — passes on 24 as well as on the local 26.
1 parent 5ba0dc7 commit 929e22f

13 files changed

Lines changed: 343 additions & 153 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ env:
2727

2828
jobs:
2929
checks:
30-
name: Lint, typecheck, build
30+
name: Lint, typecheck, test, build
3131
runs-on: ubuntu-latest
3232
timeout-minutes: 20
3333
steps:
@@ -56,5 +56,8 @@ jobs:
5656
- name: Typecheck
5757
run: pnpm typecheck
5858

59+
- name: Test
60+
run: pnpm test
61+
5962
- name: Build
6063
run: pnpm build

‎apps/web/components/bento-card.tsx‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
'use client'
22

33
import Image from 'next/image'
4-
import { useEffect } from 'react'
4+
import { useEffect, useRef } from 'react'
55
import type { ReactNode } from 'react'
66

7-
import { useReveal } from '@/lib/use-reveal'
7+
import { useFrameCallback, useReveal } from '@/lib/motion'
88

99
// The reveal threshold. Low on purpose: the card is far taller than it is wide
1010
// on mobile, so 10% is a fraction that a card clears almost immediately.
@@ -97,40 +97,37 @@ export const BentoCard = ({
9797
const { inView, ref } = useReveal<HTMLDivElement>(REVEAL_THRESHOLD)
9898

9999
// The hover glow follows the cursor through two custom properties, read by
100-
// the radial gradient below. Coalesced into one animation frame: a trackpad
101-
// fires well over 100 mousemove events a second, and each one measured the
102-
// card's box, which forces a layout flush ahead of the write. One measurement
103-
// per frame is the floor, and the last position is the one that renders.
104-
useEffect(() => {
100+
// the radial gradient below. The last position of the frame is the one that
101+
// renders, and measuring it forces a layout flush, so both are once per frame
102+
// — see useFrameCallback.
103+
const position = useRef({ x: 0, y: 0 })
104+
const onFrame = useFrameCallback(() => {
105105
const el = ref.current
106106
if (!el) {
107107
return
108108
}
109+
const rect = el.getBoundingClientRect()
110+
const { x, y } = position.current
111+
el.style.setProperty('--mouse-x', `${x - rect.left}px`)
112+
el.style.setProperty('--mouse-y', `${y - rect.top}px`)
113+
})
109114

110-
let frame = 0
111-
let x = 0
112-
let y = 0
115+
useEffect(() => {
116+
const el = ref.current
117+
if (!el) {
118+
return
119+
}
113120

114121
const onMove = (e: MouseEvent) => {
115-
x = e.clientX
116-
y = e.clientY
117-
if (frame !== 0) {
118-
return
119-
}
120-
frame = requestAnimationFrame(() => {
121-
frame = 0
122-
const rect = el.getBoundingClientRect()
123-
el.style.setProperty('--mouse-x', `${x - rect.left}px`)
124-
el.style.setProperty('--mouse-y', `${y - rect.top}px`)
125-
})
122+
position.current = { x: e.clientX, y: e.clientY }
123+
onFrame()
126124
}
127125

128126
el.addEventListener('mousemove', onMove, { passive: true })
129127
return () => {
130128
el.removeEventListener('mousemove', onMove)
131-
cancelAnimationFrame(frame)
132129
}
133-
}, [ref])
130+
}, [onFrame, ref])
134131

135132
return (
136133
<div

‎apps/web/components/hero.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useCallback, useEffect, useState } from 'react'
55

66
import { HERO_REVEAL_MS, IntroAnimation } from '@/components/intro-animation'
77
import { EXTENDED_NAME } from '@/lib/club'
8+
import { EASE } from '@/lib/motion'
89

910
// The hero is the one section that cannot be static: the banner zoom, the
1011
// headline blur and the scope line are all driven by a single flag the intro
@@ -17,7 +18,7 @@ const stagger = (ready: boolean, i: number) => ({
1718
filter: ready ? 'blur(0px)' : 'blur(16px)',
1819
opacity: ready ? 1 : 0,
1920
transform: ready ? 'translateY(0px)' : 'translateY(20px)',
20-
transition: `opacity 0.8s cubic-bezier(0.16,1,0.3,1) ${120 + i * 80}ms, filter 0.8s cubic-bezier(0.16,1,0.3,1) ${120 + i * 80}ms, transform 0.8s cubic-bezier(0.16,1,0.3,1) ${120 + i * 80}ms`,
21+
transition: `opacity 0.8s ${EASE} ${120 + i * 80}ms, filter 0.8s ${EASE} ${120 + i * 80}ms, transform 0.8s ${EASE} ${120 + i * 80}ms`,
2122
})
2223

2324
// The scope, then the barrier a prospective member actually worries about — both
@@ -66,7 +67,7 @@ export const Hero = () => {
6667
className="absolute inset-0 z-0 h-full w-full object-cover object-[20%_50%] md:object-center"
6768
style={{
6869
transform: videoReady ? 'scale(1.05)' : 'scale(0.85)',
69-
transition: 'transform 2s cubic-bezier(0.16, 1, 0.3, 1)',
70+
transition: `transform 2s ${EASE}`,
7071
}}
7172
/>
7273

@@ -127,8 +128,7 @@ export const Hero = () => {
127128
filter: heroReady ? 'blur(0px)' : 'blur(24px)',
128129
opacity: heroReady ? 1 : 0,
129130
transform: heroReady ? 'translateY(0px)' : 'translateY(32px)',
130-
transition:
131-
'opacity 1s cubic-bezier(0.16,1,0.3,1) 0ms, filter 1s cubic-bezier(0.16,1,0.3,1) 0ms, transform 1s cubic-bezier(0.16,1,0.3,1) 0ms',
131+
transition: `opacity 1s ${EASE} 0ms, filter 1s ${EASE} 0ms, transform 1s ${EASE} 0ms`,
132132
}}
133133
>
134134
We build systems

‎apps/web/components/intro-animation.tsx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import Image from 'next/image'
44
import { useEffect, useState } from 'react'
55

6+
import { EASE, EASE_CURTAIN, EASE_EXIT } from '@/lib/motion'
7+
68
// The letters are traced out of the wordmark in aris-logo.png by
79
// tools/build-brand-assets.py, not typed. No published typeface is close
810
// enough to the drawn one, and a bitmap of them goes soft: the source
@@ -100,9 +102,7 @@ export const IntroAnimation = ({ onDone }: { onDone: () => void }) => {
100102
style={{
101103
background: '#f5f4f1',
102104
bottom: curtainUp ? '100%' : '0%',
103-
transition: curtainUp
104-
? 'bottom 1.3s cubic-bezier(0.76, 0, 0.24, 1)'
105-
: 'none',
105+
transition: curtainUp ? `bottom 1.3s ${EASE_CURTAIN}` : 'none',
106106
}}
107107
/>
108108

@@ -120,13 +120,13 @@ export const IntroAnimation = ({ onDone }: { onDone: () => void }) => {
120120

121121
let transition = 'none'
122122
if (isOut) {
123-
transition = `opacity ${LETTER_OUT_DUR}ms cubic-bezier(0.4,0,1,1) ${outDelay}ms,
124-
filter ${LETTER_OUT_DUR}ms cubic-bezier(0.4,0,1,1) ${outDelay}ms,
125-
transform ${LETTER_OUT_DUR}ms cubic-bezier(0.4,0,1,1) ${outDelay}ms`
123+
transition = `opacity ${LETTER_OUT_DUR}ms ${EASE_EXIT} ${outDelay}ms,
124+
filter ${LETTER_OUT_DUR}ms ${EASE_EXIT} ${outDelay}ms,
125+
transform ${LETTER_OUT_DUR}ms ${EASE_EXIT} ${outDelay}ms`
126126
} else if (isIn) {
127-
transition = `opacity ${LETTER_IN_DUR}ms cubic-bezier(0.16,1,0.3,1) ${inDelay}ms,
128-
filter ${LETTER_IN_DUR}ms cubic-bezier(0.16,1,0.3,1) ${inDelay}ms,
129-
transform ${LETTER_IN_DUR}ms cubic-bezier(0.16,1,0.3,1) ${inDelay}ms`
127+
transition = `opacity ${LETTER_IN_DUR}ms ${EASE} ${inDelay}ms,
128+
filter ${LETTER_IN_DUR}ms ${EASE} ${inDelay}ms,
129+
transform ${LETTER_IN_DUR}ms ${EASE} ${inDelay}ms`
130130
}
131131

132132
return (

‎apps/web/components/reveal-text.tsx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useReveal } from '@/lib/use-reveal'
3+
import { EASE, useReveal } from '@/lib/motion'
44

55
// Splits text into words and reveals each with staggered opacity+blur+translateY
66
// matching the ARIS intro animation style.
@@ -71,9 +71,9 @@ export const RevealText = ({
7171
opacity: visible ? 1 : 0,
7272
transform: visible ? 'translateY(0)' : 'translateY(12px)',
7373
transition: visible
74-
? `opacity ${DURATION}ms cubic-bezier(0.16,1,0.3,1) ${wordDelay}ms,
75-
filter ${DURATION}ms cubic-bezier(0.16,1,0.3,1) ${wordDelay}ms,
76-
transform ${DURATION}ms cubic-bezier(0.16,1,0.3,1) ${wordDelay}ms`
74+
? `opacity ${DURATION}ms ${EASE} ${wordDelay}ms,
75+
filter ${DURATION}ms ${EASE} ${wordDelay}ms,
76+
transform ${DURATION}ms ${EASE} ${wordDelay}ms`
7777
: 'none',
7878
}}
7979
>

‎apps/web/components/stacking-agent-cards.tsx‎

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect, useRef, useState } from 'react'
44

55
import { Tag } from '@/components/tag'
66
import { TECHNICAL_DEPARTMENTS } from '@/lib/club'
7+
import { EASE, stackDepths, useFrameCallback } from '@/lib/motion'
78

89
// The four technical departments, in the order the server channels declare them
910
// (server-orientation.md), are TECHNICAL_DEPARTMENTS in lib/club: the bento cards
@@ -29,52 +30,35 @@ export const StackingAgentCards = () => {
2930
TECHNICAL_DEPARTMENTS.map(() => 0)
3031
)
3132

32-
useEffect(() => {
33-
// Measured on scroll, so the work is coalesced into one frame and then
34-
// thrown away when nothing moved. The previous version wrote a fresh array
35-
// on every scroll event, and a new array identity is a new render: four
36-
// cards re-rendered on every tick of the scroll for the whole section,
37-
// including the long stretches where the stack depth had not changed at all.
38-
let frame = 0
39-
40-
const measure = () => {
41-
frame = 0
42-
const nextDepth = TECHNICAL_DEPARTMENTS.map((_, i) => {
43-
// Count how many cards j > i are currently in sticky position (i.e. have scrolled past card i)
44-
let count = 0
45-
for (let j = i + 1; j < TECHNICAL_DEPARTMENTS.length; j += 1) {
46-
const el = cardRefs.current[j]
47-
if (!el) {
48-
continue
49-
}
50-
const rect = el.getBoundingClientRect()
51-
const stickyTopJ = STICKY_TOP + j * STICKY_STEP
52-
// Card j is "on top of" card i when it has reached its sticky position
53-
if (rect.top <= stickyTopJ + 2) {
54-
count += 1
55-
}
56-
}
57-
return count
58-
})
33+
// Where each card parks once it is sticky. These, and the depth arithmetic in
34+
// lib/motion, are the only things that decide how deep a card is stacked.
35+
const stickyTops = TECHNICAL_DEPARTMENTS.map(
36+
(_, i) => STICKY_TOP + i * STICKY_STEP
37+
)
5938

60-
setDepth((prev) =>
61-
prev.every((d, i) => d === nextDepth[i]) ? prev : nextDepth
62-
)
63-
}
39+
// Measured on scroll, so the work is coalesced into one frame and then thrown
40+
// away when nothing moved. The previous version wrote a fresh array on every
41+
// scroll event, and a new array identity is a new render: four cards
42+
// re-rendered on every tick of the scroll for the whole section, including the
43+
// long stretches where the stack depth had not changed at all.
44+
const measure = useFrameCallback(() => {
45+
const nextDepth = stackDepths(
46+
cardRefs.current.map((el) => el?.getBoundingClientRect().top ?? null),
47+
stickyTops
48+
)
6449

65-
const onScroll = () => {
66-
if (frame === 0) {
67-
frame = requestAnimationFrame(measure)
68-
}
69-
}
50+
setDepth((prev) =>
51+
prev.every((d, i) => d === nextDepth[i]) ? prev : nextDepth
52+
)
53+
})
7054

71-
window.addEventListener('scroll', onScroll, { passive: true })
72-
onScroll()
55+
useEffect(() => {
56+
window.addEventListener('scroll', measure, { passive: true })
57+
measure()
7358
return () => {
74-
cancelAnimationFrame(frame)
75-
window.removeEventListener('scroll', onScroll)
59+
window.removeEventListener('scroll', measure)
7660
}
77-
}, [])
61+
}, [measure])
7862

7963
return (
8064
<div
@@ -99,7 +83,7 @@ export const StackingAgentCards = () => {
9983
style={{
10084
transform: `scale(${scale}) translateY(${translateY}px)`,
10185
transformOrigin: 'top center',
102-
transition: 'transform 0.3s cubic-bezier(0.16,1,0.3,1)',
86+
transition: `transform 0.3s ${EASE}`,
10387
willChange: 'transform',
10488
}}
10589
>

‎apps/web/lib/motion.test.ts‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// The sticky-stack arithmetic, and the easing curve the entrances share.
2+
//
3+
// stackDepths was 24 lines inside a useEffect closure in
4+
// components/stacking-agent-cards.tsx, so the only way to check it was to scroll
5+
// the page and watch. It is now pure, and this is its first test.
6+
//
7+
// Run with `node --test`. The rest of the module needs a DOM and is exercised
8+
// through the page; see docs/adr/0003-node-test-runner-without-ci-until-a-second-file.md
9+
// for why there is still no test script or CI step.
10+
11+
import assert from 'node:assert/strict'
12+
import { readFileSync } from 'node:fs'
13+
import { test } from 'node:test'
14+
15+
import { EASE, stackDepths } from './motion.ts'
16+
17+
// A sticky card parks at `80 + 16 * i` and its rect.top falls to that value as
18+
// it sticks, so a top of 0 means fully stuck and a large top means not yet
19+
// reached. These four are the offsets the cards actually use.
20+
const STICKY = [80, 96, 112, 128]
21+
22+
// Far below every offset: nothing has stuck yet.
23+
const UNSTUCK = [500, 400, 300, 200]
24+
25+
test('no cards stacked when no card has reached its sticky position', () => {
26+
assert.deepEqual(stackDepths(UNSTUCK, STICKY), [0, 0, 0, 0])
27+
})
28+
29+
test('every card stacked when every card has reached its sticky position', () => {
30+
assert.deepEqual(stackDepths([80, 96, 112, 128], STICKY), [3, 2, 1, 0])
31+
})
32+
33+
test('depth counts only the cards below, never the ones above', () => {
34+
// Card 0 is at the bottom of the stack and has three on it; the last card has
35+
// none, whatever the others are doing.
36+
assert.deepEqual(stackDepths([200, 96, 112, 128], STICKY), [3, 2, 1, 0])
37+
assert.equal(stackDepths([200, 96, 112, 128], STICKY).at(-1), 0)
38+
})
39+
40+
test('a card part-way through the stack counts the ones that have passed it', () => {
41+
// Only card 3 has reached its offset, so it sits on top of all three cards
42+
// below it. Depth is what is stacked ON a card, not how far down it is.
43+
assert.deepEqual(stackDepths([500, 400, 300, 128], STICKY), [1, 1, 1, 0])
44+
})
45+
46+
test('an unmeasured card is not counted as stacked', () => {
47+
// null means the ref has not been attached yet, which is not the same as
48+
// having reached the sticky offset.
49+
assert.deepEqual(stackDepths([500, null, 300, 200], STICKY), [0, 0, 0, 0])
50+
assert.deepEqual(stackDepths([500, null, null, 128], STICKY), [1, 1, 1, 0])
51+
})
52+
53+
test('the tolerance absorbs a card sitting a hair above its offset', () => {
54+
// 129 is one pixel past card 3's own offset, so without a tolerance it reads
55+
// as not yet stuck and the card flickers between two depths on the scroll.
56+
assert.deepEqual(stackDepths([500, 400, 300, 129], STICKY), [1, 1, 1, 0])
57+
assert.deepEqual(stackDepths([500, 400, 300, 131], STICKY), [0, 0, 0, 0])
58+
})
59+
60+
test('the tolerance is a parameter, not a constant buried in the loop', () => {
61+
assert.deepEqual(stackDepths([500, 400, 300, 131], STICKY), [0, 0, 0, 0])
62+
assert.deepEqual(stackDepths([500, 400, 300, 131], STICKY, 4), [1, 1, 1, 0])
63+
})
64+
65+
test('no cards in, no depths out', () => {
66+
assert.deepEqual(stackDepths([], []), [])
67+
})
68+
69+
test('the easing curve is defined once and typed literally nowhere else', () => {
70+
assert.equal(EASE, 'cubic-bezier(0.16, 1, 0.3, 1)')
71+
72+
const files = [
73+
'components/hero.tsx',
74+
'components/reveal-text.tsx',
75+
'components/stacking-agent-cards.tsx',
76+
]
77+
for (const file of files) {
78+
const src = readFileSync(new URL(`../${file}`, import.meta.url), 'utf-8')
79+
assert.ok(
80+
src.includes("from '@/lib/motion'"),
81+
`${file} does not import the curve from lib/motion`
82+
)
83+
}
84+
})

0 commit comments

Comments
 (0)