Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions quartz/components/HomeAbout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { QuartzComponent, QuartzComponentConstructor } from "./types"
import { DocTitle, localizedAttrs, SiteLang, T } from "./localized"
import style from "./styles/homeAbout.scss"
// @ts-ignore
import tiltScript from "./scripts/tilt.inline"
import tiltStyle from "./styles/tilt.scss"
import { concatenateResources } from "../util/resources"

const aboutTitle: Record<SiteLang, string> = {
en: "About",
Expand All @@ -17,21 +21,25 @@ const HomeAbout: QuartzComponent = () => (
<DocTitle text={aboutTitle} />

<div class="home-about-layout">
<figure class="home-about-portrait">
<img
src="/static/portrait-bookstore.webp"
{...localizedAttrs({
alt: {
en: "Portrait of Thiago Komeno",
ja: "米野ティアゴの写真",
zh: "米野雅各的肖像",
pt: "Retrato de Thiago Komeno",
},
})}
loading="eager"
decoding="async"
fetchPriority="high"
/>
<figure class="home-about-portrait" data-tilt>
<span class="tilt-shadow" aria-hidden="true"></span>
<div class="home-about-portrait-card tilt-card">
<img
src="/static/portrait-bookstore.webp"
{...localizedAttrs({
alt: {
en: "Portrait of Thiago Komeno",
ja: "米野ティアゴの写真",
zh: "米野雅各的肖像",
pt: "Retrato de Thiago Komeno",
},
})}
loading="eager"
decoding="async"
fetchPriority="high"
/>
<span class="tilt-glare" aria-hidden="true"></span>
</div>
</figure>

<div class="home-about-copy">
Expand Down Expand Up @@ -75,6 +83,7 @@ const HomeAbout: QuartzComponent = () => (
</section>
)

HomeAbout.css = style
HomeAbout.css = concatenateResources(style, tiltStyle)
HomeAbout.afterDOMLoaded = tiltScript

export default (() => HomeAbout) satisfies QuartzComponentConstructor
15 changes: 11 additions & 4 deletions quartz/components/HomeArticles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import { QuartzPluginData } from "../plugins/vfile"
import { concatenateResources } from "../util/resources"
import style from "./styles/homeArticles.scss"
import archiveStyle from "./styles/archiveGate.scss"
import tiltStyle from "./styles/tilt.scss"
import { VIEWBOX, WORD, WORD_SLANT, WORD_VIEWBOX, drawGate } from "./archiveGateDrawing"
// @ts-ignore
import script from "./scripts/homeArticles.inline"
// @ts-ignore
import archiveScript from "./scripts/archiveGate.inline"
// @ts-ignore
import tiltScript from "./scripts/tilt.inline"

const featuredArticleSlug = "Swift-Student-Challenge-2026"
// Everything written before this article is kept behind the archive gate, on its own page.
Expand Down Expand Up @@ -398,8 +401,12 @@ export default (() => {
{featuredArticle && (
<article class="article-featured">
{featuredArticle.firstImage && (
<figure class="article-featured-image" aria-hidden="true">
<img src={featuredArticle.firstImage} alt="" loading="eager" decoding="async" />
<figure class="article-featured-image" aria-hidden="true" data-tilt>
<span class="tilt-shadow"></span>
<div class="article-featured-image-card tilt-card">
<img src={featuredArticle.firstImage} alt="" loading="eager" decoding="async" />
<span class="tilt-glare"></span>
</div>
</figure>
)}
<div class="article-featured-copy">
Expand Down Expand Up @@ -437,7 +444,7 @@ export default (() => {
)
}

HomeArticles.css = concatenateResources(style, archiveStyle)
HomeArticles.afterDOMLoaded = concatenateResources(script, archiveScript)
HomeArticles.css = concatenateResources(style, archiveStyle, tiltStyle)
HomeArticles.afterDOMLoaded = concatenateResources(script, archiveScript, tiltScript)
return HomeArticles
}) satisfies QuartzComponentConstructor
143 changes: 143 additions & 0 deletions quartz/components/scripts/tilt.inline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
// Tilts a photo toward the pointer, like a card held in the hand (the About portrait and
// the featured article on the Articles page). Markup: a [data-tilt] root holding a
// .tilt-card (what moves) and a .tilt-shadow; styles live in styles/tilt.scss. It
// leans in 3D, lifts slightly, a soft highlight follows the pointer across the glass,
// and the shadow underneath slides opposite the tilt. Motion runs on springs (after the
// HoloCard component on reactbits.dev) so it eases in and settles instead of snapping.
//
// Touch screens have no hover, so there the card follows a finger while it's pressed
// and lets go on release; a vertical swipe still scrolls the page (touch-action: pan-y).

const PERSPECTIVE = 1100 // px
const TILT_MAX = 12 // deg at the card's edge
const HOVER_SCALE = 1.04
const SHADOW_SHIFT = 0.7 // px of shadow travel per degree of tilt

const clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v))

// One semi-implicit Euler step of a damped spring pulling `value` toward `target`.
const spring = (
value: number,
velocity: number,
target: number,
stiffness: number,
damping: number,
dt: number,
): [number, number] => {
const next = velocity + ((target - value) * stiffness - velocity * damping) * dt
return [value + next * dt, next]
}

function setupTilt(root: HTMLElement) {
const card = root.querySelector<HTMLElement>(".tilt-card")
const shadow = root.querySelector<HTMLElement>(".tilt-shadow")
if (!card || !shadow) return

const pointer = { x: 0.5, y: 0.5, inside: false }
const s = {
tiltX: 0,
tiltVX: 0,
tiltY: 0,
tiltVY: 0,
lift: 1,
liftV: 0,
gx: 0.5,
gxV: 0,
gy: 0.5,
gyV: 0,
}
let raf = 0
let last = 0
let calm = 0

const tick = (now: number) => {
raf = 0
const dt = Math.min(1 / 30, Math.max(1 / 240, (now - last) / 1000))
last = now

const targetX = pointer.inside ? (0.5 - pointer.y) * 2 * TILT_MAX : 0
const targetY = pointer.inside ? (pointer.x - 0.5) * 2 * TILT_MAX : 0
const targetLift = pointer.inside ? HOVER_SCALE : 1

// Sub-step at 240Hz so the springs stay stable on slow frames.
const steps = Math.ceil(dt / (1 / 240))
const h = dt / steps
for (let i = 0; i < steps; i++) {
;[s.tiltX, s.tiltVX] = spring(s.tiltX, s.tiltVX, targetX, 150, 16, h)
;[s.tiltY, s.tiltVY] = spring(s.tiltY, s.tiltVY, targetY, 150, 16, h)
;[s.lift, s.liftV] = spring(s.lift, s.liftV, targetLift, 320, 30, h)
;[s.gx, s.gxV] = spring(s.gx, s.gxV, pointer.x, 220, 30, h)
;[s.gy, s.gyV] = spring(s.gy, s.gyV, pointer.y, 220, 30, h)
}

// 0 at rest, 1 fully lifted: fades the glare and shadow in and out with the hover.
const raised = clamp((s.lift - 1) / (HOVER_SCALE - 1), 0, 1)
card.style.transform = `perspective(${PERSPECTIVE}px) scale(${s.lift}) rotateX(${s.tiltX}deg) rotateY(${s.tiltY}deg)`
card.style.setProperty("--glare-x", `${s.gx * 100}%`)
card.style.setProperty("--glare-y", `${s.gy * 100}%`)
card.style.setProperty("--raised", `${raised}`)
shadow.style.transform = `translate(${-s.tiltY * SHADOW_SHIFT}px, ${s.tiltX * SHADOW_SHIFT}px) scale(${0.9 + (s.lift - 1) * 1.5})`
shadow.style.opacity = `${raised}`

const motion =
Math.abs(s.tiltVX) +
Math.abs(s.tiltVY) +
Math.abs(s.liftV) * 40 +
Math.abs(s.tiltX - targetX) +
Math.abs(s.tiltY - targetY) +
Math.abs(s.lift - targetLift) * 40
calm = motion > 0.02 ? 0 : calm + dt
// Sleep once the card has settled and nobody is touching it.
if (!pointer.inside && calm > 0.3) {
card.style.transform = ""
return
}
raf = requestAnimationFrame(tick)
}

const wake = () => {
if (raf) return
calm = 0
last = performance.now()
raf = requestAnimationFrame(tick)
}

const track = (e: PointerEvent) => {
// A finger only steers while it's pressed; otherwise a stray move would stick.
if (e.pointerType === "touch" && e.type === "pointermove" && !e.buttons) return
const rect = root.getBoundingClientRect()
pointer.x = clamp((e.clientX - rect.left) / rect.width, 0, 1)
pointer.y = clamp((e.clientY - rect.top) / rect.height, 0, 1)
pointer.inside = true
wake()
}

const leave = (e: PointerEvent) => {
// A mouse button release keeps hovering; only a lifted finger lets go.
if (e.type === "pointerup" && e.pointerType !== "touch") return
pointer.inside = false
wake()
}

root.addEventListener("pointerenter", track)
root.addEventListener("pointermove", track)
root.addEventListener("pointerdown", track)
root.addEventListener("pointerleave", leave)
root.addEventListener("pointerup", leave)
root.addEventListener("pointercancel", leave)

window.addCleanup(() => {
cancelAnimationFrame(raf)
root.removeEventListener("pointerenter", track)
root.removeEventListener("pointermove", track)
root.removeEventListener("pointerdown", track)
root.removeEventListener("pointerleave", leave)
root.removeEventListener("pointerup", leave)
root.removeEventListener("pointercancel", leave)
})
}

document.addEventListener("nav", () => {
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return
document.querySelectorAll<HTMLElement>("[data-tilt]").forEach(setupTilt)
})
8 changes: 5 additions & 3 deletions quartz/components/styles/homeAbout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
gap: 2rem;
}

// Tilts toward the pointer; the shared layers are in tilt.scss.
.home-about-portrait {
position: relative;
--tilt-radius: 16px;
aspect-ratio: 4 / 5;
overflow: hidden;
margin: 0;
}

.home-about-portrait-card {
// A plain 8px arc reads as a clipped corner at this size. A larger radius with
// continuous curvature (where supported) eases into the edge like iOS corners.
border-radius: 16px;
corner-shape: superellipse(1.5);

// Hairline inner edge: softens the dark photo against the light page so the
Expand Down
9 changes: 5 additions & 4 deletions quartz/components/styles/homeArticles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,15 @@
margin-bottom: 3.5rem;
}
// The photo spans the copy column from the meta line to the end of the summary;
// it is taken out of flow so the text alone sets the row height.
// it is taken out of flow so the text alone sets the row height. It tilts toward the
// pointer; the shared layers are in tilt.scss.
.article-featured-image {
position: relative;
--tilt-radius: 8px;
display: block;
min-height: 14rem;
margin: 0;
overflow: hidden;
border-radius: 8px;
}
.article-featured-image-card {
background: var(--lightgray);
// Override the global img margin, which pushed the photo down inside its frame.
& img {
Expand Down
50 changes: 50 additions & 0 deletions quartz/components/styles/tilt.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Shared layers for photos that tilt toward the pointer (scripts/tilt.inline.ts).
// The root keeps the layout box and catches the pointer without clipping, so the
// shadow can spill past the photo; the card inside is what tilts and clips the image.
// Each root sets --tilt-radius to its corner radius.
[data-tilt] {
position: relative;
// Horizontal drags tilt the photo on touch screens; vertical ones still scroll.
touch-action: pan-y;
-webkit-tap-highlight-color: transparent;
}

// Hidden at rest; fades in and slides opposite the tilt while the card is lifted.
.tilt-shadow {
position: absolute;
inset: 10% 7% -4%;
border-radius: var(--tilt-radius, 8px);
background: rgba(0, 0, 0, 0.35);
filter: blur(26px);
opacity: 0;
pointer-events: none;
will-change: transform, opacity;
}

.tilt-card {
position: absolute;
inset: 0;
overflow: hidden;
border-radius: var(--tilt-radius, 8px);
will-change: transform;

& img {
pointer-events: none;
-webkit-user-drag: none;
user-select: none;
}
}

// A soft gloss that follows the pointer, like light catching a glossy print.
.tilt-glare {
position: absolute;
inset: 0;
background: radial-gradient(
circle at var(--glare-x, 50%) var(--glare-y, 50%),
rgba(255, 255, 255, 0.35),
rgba(255, 255, 255, 0) 60%
);
mix-blend-mode: soft-light;
opacity: var(--raised, 0);
pointer-events: none;
}