File size: 6,203 Bytes
7b4250a
 
 
 
 
 
 
 
 
 
ab14380
7b4250a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ab14380
7b4250a
 
 
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
import { useEffect, useState } from 'react'
import { BookOpen, Clapperboard, Image as ImageIcon, Send } from 'lucide-react'
import './quanxue/quanxue.css'
import { Player, type Orient } from './quanxue/ui/Player'
import { ExportPanel } from './quanxue/ui/ExportPanel'
import { CoverPanel } from './quanxue/ui/CoverPanel'
import { PublishPanel } from './quanxue/ui/PublishPanel'
import { Transcript } from './quanxue/ui/Transcript'
import { DURATION, TL } from './quanxue/timeline'
import { fmtTime } from './quanxue/ui/store'
import { Ascii, ExportTest, MusicDump, Still } from './quanxue/dev'

const isPhonePortrait = () => typeof window !== 'undefined' && window.matchMedia('(max-width: 820px) and (orientation: portrait)').matches

function Section({ id, icon, title, sub, children }: { id: string; icon: React.ReactNode; title: string; sub: string; children: React.ReactNode }) {
  return (
    <section id={id} className="scroll-mt-20 rounded-2xl border border-[#cfa961]/12 bg-gradient-to-b from-white/[0.035] to-white/[0.01] p-5 sm:p-7">
      <header className="flex items-end gap-3 mb-6">
        <span className="text-[#cfa961]">{icon}</span>
        <h2 className="qx-song text-xl sm:text-2xl font-semibold tracking-[0.15em] text-[#efe6d2]">{title}</h2>
        <span className="text-xs text-[#9d927f] tracking-wider pb-1 hidden sm:inline">{sub}</span>
      </header>
      {children}
    </section>
  )
}

function Main() {
  const [orient, setOrientState] = useState<Orient>(() => (isPhonePortrait() ? 'portrait' : 'landscape'))
  const [manual, setManual] = useState(false)
  const [seekReq, setSeekReq] = useState({ t: 0, n: 0 })
  const setOrient = (o: Orient) => { setManual(true); setOrientState(o) }
  // 手机旋转时自动切换横竖屏(除非用户手动选择过)
  useEffect(() => {
    const mq = window.matchMedia('(max-width: 820px) and (orientation: portrait)')
    const mq2 = window.matchMedia('(max-height: 520px) and (orientation: landscape)')
    const f = () => { if (manual) return; if (mq.matches) setOrientState('portrait'); else if (mq2.matches) setOrientState('landscape') }
    mq.addEventListener('change', f); mq2.addEventListener('change', f)
    return () => { mq.removeEventListener('change', f); mq2.removeEventListener('change', f) }
  }, [manual])
  const seek = (t: number) => { setSeekReq((s) => ({ t, n: s.n + 1 })); window.scrollTo({ top: 0, behavior: 'smooth' }) }

  const nav = [['watch', '观看'], ['script', '文稿'], ['export', '导出'], ['cover', '封面'], ['publish', '发布']]
  return (
    <div className="qx-root min-h-screen text-[#efe6d2]">
      <nav className="sticky top-0 z-40 backdrop-blur-md bg-[#0b0a08]/75 border-b border-white/5">
        <div className="max-w-6xl mx-auto px-4 h-14 flex items-center gap-3">
          <span className="qx-seal">荀</span>
          <span className="qx-brush text-2xl tracking-[0.25em]">劝学</span>
          <span className="hidden md:inline text-xs text-[#9d927f] tracking-[0.25em]">课文精讲 · 网页实时渲染</span>
          <div className="flex-1" />
          {nav.map(([id, t]) => <a key={id} href={`#${id}`} className="text-sm px-2 sm:px-3 py-1.5 text-[#c9bfa9] hover:text-[#cfa961] tracking-widest">{t}</a>)}
        </div>
      </nav>

      <main className="max-w-6xl mx-auto px-3 sm:px-4 pb-24">
        <div id="watch" className="pt-6 sm:pt-10 scroll-mt-20">
          <div className="flex flex-col sm:flex-row sm:items-end gap-1 sm:gap-4 mb-5 px-1">
            <h1 className="qx-brush text-4xl sm:text-5xl tracking-[0.2em]">劝学<span className="text-[#9d927f] text-2xl sm:text-3xl tracking-[0.1em] ml-3">· 荀子</span></h1>
            <p className="text-sm text-[#9d927f] tracking-wider sm:pb-2">从“性恶论”到“化性起伪”,读懂学习的本质 · 时长 {fmtTime(DURATION)}</p>
          </div>
          <Player orient={orient} setOrient={setOrient} seekReq={seekReq} />
          <div className="mt-4 flex gap-2 overflow-x-auto pb-1 qx-noscroll">
            {TL.chapters.map((c) => (
              <button key={c.id} onClick={() => setSeekReq((s) => ({ t: c.start + 0.01, n: s.n + 1 }))} className="shrink-0 flex items-center gap-2 px-3 py-2 rounded-lg border border-white/10 hover:border-[#cfa961]/50 bg-white/[0.02] transition">
                <span className="qx-brush text-lg text-[#b8392b]">{c.no}</span>
                <span className="text-sm text-[#e2d6bd] whitespace-nowrap">{c.title.replace(/\s/g, '')}</span>
                <span className="text-[11px] text-[#7d7363] tabular-nums">{fmtTime(c.start)}</span>
              </button>
            ))}
          </div>
        </div>

        <div className="mt-10 flex flex-col gap-8">
          <Section id="script" icon={<BookOpen size={22} />} title="解说文稿" sub="点击任意一句跳转播放">
            <Transcript onSeek={seek} />
          </Section>
          <Section id="export" icon={<Clapperboard size={22} />} title="导出 MP4" sub="浏览器本地渲染 · 不上传任何数据">
            <ExportPanel defaultPortrait={orient === 'portrait'} />
          </Section>
          <Section id="cover" icon={<ImageIcon size={22} />} title="封面生成" sub="4:3 · 3:4 · 16:9 多选 · 每个比例多套设计">
            <CoverPanel />
          </Section>
          <Section id="publish" icon={<Send size={22} />} title="发布文案" sub="小红书 · 抖音 · 视频号 · 哔哩哔哩">
            <PublishPanel />
          </Section>
        </div>
        <footer className="mt-14 text-center text-xs text-[#6f6656] tracking-[0.2em] leading-loose">
          原文据《荀子·劝学》(统编版高中语文必修上册)<br />解说文案原创 · AI 配音 · 画面 / 古琴配乐 / 音效 均为程序化实时生成
        </footer>
      </main>
    </div>
  )
}

export default function App() {
  if (typeof location !== 'undefined') {
    if (location.search.includes('still=')) return <Still />
    if (location.search.includes('musicdump')) return <MusicDump />
    if (location.search.includes('exporttest')) return <ExportTest />
    if (location.search.includes('ascii=')) return <Ascii />
  }
  return <Main />
}