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
125 changes: 123 additions & 2 deletions TODO.md

Large diffs are not rendered by default.

302 changes: 291 additions & 11 deletions docs/DESIGN.md

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions src/components/deadpan/ask-record.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { CornerDownLeft } from 'lucide-react'
import { type CSSProperties, type FormEvent, useRef, useState } from 'react'
import { useTranslation } from 'react-i18next'

import { Redacted } from '@/components/motion/redacted'
import { TypedText } from '@/components/motion/typed-text'
import { cn } from '@/lib/utils'

type Entry = { id: number; text: string; time: string }

const MAX_ENTRIES = 5

/** 页面设计单位(一页 512 宽)换算成容器宽度的比例,与 book-pages 的坐标一一对应。 */
const u = (value: number) => `calc(var(--u) * ${value})`

function Row({ entry, index }: { entry: Entry; index: number }) {
const { t } = useTranslation()
const [peek, setPeek] = useState(false)
return (
<li
className='grid animate-in grid-cols-[auto_1fr] fade-in slide-in-from-bottom-2 duration-500'
style={{ columnGap: u(10), paddingBlock: u(6), minHeight: u(60), fontSize: u(15) }}
>
<span className='font-serif-sc font-bold text-[#842219]'>{t('dp.ask.q')}</span>
<p className='font-serif-sc leading-[1.45] text-[#17120d]'>
<TypedText text={entry.text} />
<span className='ml-2 font-mono tracking-[.14em] text-[#17120d]/45' style={{ fontSize: u(8) }}>
N°{String(index + 1).padStart(2, '0')} · {entry.time}
</span>
</p>
<span className='font-serif-sc font-bold text-[#17120d]/60'>{t('dp.ask.a')}</span>
<button
type='button'
onPointerEnter={() => setPeek(true)}
onPointerLeave={() => setPeek(false)}
onFocus={() => setPeek(true)}
onBlur={() => setPeek(false)}
className='w-fit text-left text-[#17120d]/75'
style={{ fontSize: u(13) }}
>
<Redacted revealed={peek} barClassName='bg-[#17120d]'>
{t('dp.ask.pending')}
</Redacted>
</button>
</li>
)
}

/**
* 讯问笔录:叠在书的右页上,访客写下的问题被誊写进笔录,回答栏盖着机密条。
* 容器宽度就是一页宽;内部尺寸按页面设计单位(512 宽)换算。active 为假时整块不可聚焦。
*/
export function AskRecord({ active }: { active: boolean }) {
const { t } = useTranslation()
const [entries, setEntries] = useState<Entry[]>([])
const [draft, setDraft] = useState('')
const counter = useRef(0)

const submit = (event: FormEvent) => {
event.preventDefault()
const text = draft.trim().slice(0, 80)
if (!text) return
const time = new Date().toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', hour12: false })
counter.current++
setEntries((list) => [...list, { id: counter.current, text, time }].slice(-MAX_ENTRIES))
setDraft('')
}

return (
<div
inert={!active}
className={cn(
'@container absolute inset-0 transition-opacity duration-500',
active ? 'opacity-100' : 'opacity-0',
)}
>
<div className='relative size-full text-[#17120d]' style={{ '--u': 'calc(100cqw / 512)' } as CSSProperties}>
<div className='absolute overflow-hidden' style={{ left: u(66), top: u(66), width: u(402), height: u(528) }}>
{entries.length === 0 ? (
<p
className='flex size-full items-center justify-center text-center font-serif-sc text-[#17120d]/45'
style={{ fontSize: u(16) }}
>
{t('dp.ask.empty')}
</p>
) : (
<ol aria-live='polite'>
{entries.map((entry) => (
<Row key={entry.id} entry={entry} index={entry.id - 1} />
))}
</ol>
)}
</div>
<form
onSubmit={submit}
className='absolute flex items-end'
style={{ left: u(66), top: u(618), width: u(402), gap: u(10) }}
>
<label className='flex flex-1 flex-col' style={{ gap: u(4) }}>
<span className='font-mono tracking-[.2em] text-[#17120d]/60 uppercase' style={{ fontSize: u(8) }}>
{t('dp.ask.label')}
</span>
<input
value={draft}
onChange={(event) => setDraft(event.target.value)}
maxLength={80}
placeholder={t('dp.ask.placeholder')}
className='w-full border-b border-[#17120d]/60 bg-transparent font-serif-sc text-[#17120d] outline-none placeholder:text-[#17120d]/35 focus:border-[#842219]'
style={{ fontSize: u(16), paddingBlock: u(4) }}
/>
</label>
<button
type='submit'
disabled={!draft.trim()}
className='flex items-center bg-[#17120d] font-semibold tracking-[.14em] text-[#ecdcbc] uppercase transition-colors hover:bg-[#842219] disabled:opacity-40'
style={{ height: u(32), paddingInline: u(12), gap: u(6), fontSize: u(10) }}
>
{t('dp.ask.submit')} <CornerDownLeft aria-hidden style={{ width: u(11), height: u(11) }} />
</button>
</form>
</div>
</div>
)
}
78 changes: 78 additions & 0 deletions src/components/deadpan/book-nav.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { getLenis } from '@/lib/smooth-scroll'

/**
* 书页进度 q:第 i 次翻页占 q ∈ [i+0.1, i+0.7],其余为停留;
* 翻完最后一张后(q ≥ 6.2)整本书合上,各页自上而下错开 0.03 依次落回右侧,约在 6.85 合拢。
*/
export const LEAVES = 7
export const TURNS = LEAVES - 1
export const CLOSE_AT = TURNS + 0.2
export const Q_MAX = TURNS + 1.4
/** 每单位 q 占多少屏高的滚动距离。 */
export const SCREENS_PER_Q = 0.85
/**
* 跨页:0 合上、1 开卷目录 + 总目序页、2 总目第 1、2 页、3 总目第 3 页 + 推理卷首、
* 4 线索墙、5 盘问、6 见报、7 书合上,镜头拉远回到全景(收尾)。
*/
export const SPREADS = LEAVES + 1
export const BOARD_SPREAD = 4
export const ASK_SPREAD = 5
export const PAPER_SPREAD = 6
export const END_SPREAD = 7

/**
* 取景:书在世界里大小固定,用整体缩放来推拉镜头。
* 线索墙与盘问正对(缩放恰为 1,叠层与书页对齐);见报时拉升到 paper。
*/
export const SHOT = { wide: 0.9, close: 1.06, flat: 1, paper: 1.1 }

export const SECTION_HEIGHT_SVH = (1 + Q_MAX * SCREENS_PER_Q) * 100

/** 纸的宽高比(A 系列)。 */
export const PAGE_ASPECT = 724 / 512

const clamp = (value: number, min = 0, max = 1) => Math.min(max, Math.max(min, value))

/** 第 i 张纸的翻动进度 0..1。 */
export function turnFraction(q: number, index: number) {
const x = clamp((q - index - 0.1) / 0.6)
return x * x * (3 - 2 * x)
}

/** 第 i 张纸合上的进度 0..1:上面的纸先落,封面最后。 */
export function closeFraction(q: number, index: number) {
const x = clamp((q - (CLOSE_AT + 0.03 * (TURNS - 1 - index))) / 0.5)
return x * x * (3 - 2 * x)
}

/** 当前最接近的跨页(翻过一半算翻过;合上过半算收尾)。 */
export function spreadAt(q: number) {
if (closeFraction(q, 2) >= 0.5) return END_SPREAD
let spread = 0
for (let i = 0; i < TURNS; i++) if (turnFraction(q, i) >= 0.5) spread++
return spread
}

/** 停在某个跨页时的 q。 */
export const spreadQ = (spread: number) => (spread === 0 ? 0.02 : spread === END_SPREAD ? Q_MAX - 0.3 : spread - 0.1)

/** 一页(不含封面的大小差)在舞台里的尺寸,书与线索墙叠层共用。 */
export function pageSize(stageWidth: number, stageHeight: number) {
const width = Math.min(stageWidth * 0.45, (stageHeight * 0.72) / PAGE_ASPECT)
return { width, height: width * PAGE_ASPECT }
}

/** 某个跨页对应的滚动位置。 */
export function spreadScrollTop(section: HTMLElement, spread: number) {
const top = section.getBoundingClientRect().top + window.scrollY
const travel = Math.max(0, section.offsetHeight - window.innerHeight)
return top + (spreadQ(spread) / Q_MAX) * travel
}

/** 滚动到某个跨页;immediate 用于章节跳转时转场幕已盖住画面。 */
export function scrollToSpread(section: HTMLElement, spread: number, immediate = false) {
const target = spreadScrollTop(section, clamp(spread, 0, END_SPREAD))
const lenis = getLenis()
if (lenis) lenis.scrollTo(target, immediate ? { immediate: true, force: true } : { duration: 1.3 })
else window.scrollTo({ top: target, behavior: immediate ? 'instant' : 'smooth' })
}
Loading
Loading