Hero Phase 1: layout data path + portal renderer

First phase of the hero canvas editor (see HERO_EDITOR.md).

- settings.model: add hero_layout to PUBLIC_KEYS so the portal receives it
  (corrects the design doc — public settings is a whitelist, not getAll();
  hero_layout_draft stays admin-only)
- new HeroElement.jsx: renders one layout element by type (text_block,
  buttons, moon, badge, image); absolute % positioning with anchor; shared
  by the portal now and the editor canvas later
- MoonDot: optional color override for the hero moon element
- Portal.jsx: parse hero_layout (version-checked, try/catch), render elements
  sorted by z; fall back to a DEFAULT_LAYOUT built from the current hero so the
  page is byte-for-byte unchanged until staff publish their own

No schema change. Verified: default render matches the old hero; publishing a
hero_layout re-renders the portal; the draft key is not exposed publicly; client
builds; no console errors.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-28 02:18:09 -05:00
parent 30c2a30c80
commit 578bffc51f
4 changed files with 234 additions and 38 deletions

View File

@@ -1,9 +1,66 @@
import { useMemo } from 'react'
import { Link } from 'react-router-dom'
import PublicLayout from '../../components/PublicLayout.jsx'
import HeroElement from '../../components/HeroElement.jsx'
import { useSite } from '../../contexts/SiteContext.jsx'
const DEFAULT_HERO_IMAGE = '/assets/img/uomysticmoon-main-hero.png'
const HERO_BG =
"linear-gradient(90deg,rgba(11,15,20,0.34) 0%,rgba(11,15,20,0.5) 36%,rgba(11,15,20,0.78) 62%,rgba(11,15,20,0.66) 100%),linear-gradient(180deg,rgba(11,15,20,0.08) 0%,rgba(11,15,20,0.72) 100%),url('/assets/img/uomysticmoon-main-hero.png')"
"linear-gradient(90deg,rgba(11,15,20,0.34) 0%,rgba(11,15,20,0.5) 36%,rgba(11,15,20,0.78) 62%,rgba(11,15,20,0.66) 100%),linear-gradient(180deg,rgba(11,15,20,0.08) 0%,rgba(11,15,20,0.72) 100%),url('" +
DEFAULT_HERO_IMAGE +
"')"
// Single-stop dark overlay driven by the editor's opacity slider.
function buildOverlay(opacity) {
return `linear-gradient(180deg,rgba(11,15,20,${opacity * 0.15}) 0%,rgba(11,15,20,${opacity}) 100%)`
}
// The current hardcoded hero, expressed as a HeroLayout so the page is unchanged
// until staff publish their own. Font sizes use the existing clamp() strings so
// the default stays responsive (editor-created text uses px).
function defaultLayout(teaser) {
return {
version: 1,
background: { image_url: null, position_x: 'left', position_y: 'center', size: 'cover' },
overlay: { opacity: 0.72 },
elements: [
{
id: 'default-text',
type: 'text_block',
x: 50,
y: 42,
z: 1,
anchor: 'center',
props: {
align: 'center',
width: 760,
lines: [
{ text: 'Private shard project', tag: 'span', fontSize: '0.74rem', color: '#c2d2e6', weight: 700, letterSpacing: '0.22em', transform: 'uppercase', font: 'sans' },
{ text: 'UOMysticmoon', tag: 'h1', fontSize: 'clamp(3rem,8.5vw,5.75rem)', color: 'var(--head)', weight: 600, letterSpacing: '0.02em', lineHeight: 1, font: 'display', marginTop: 14 },
{ text: 'A private Ultima Online world in progress', tag: 'p', fontSize: '1.32rem', color: '#dbe2ea', italic: true, marginTop: 22 },
{ text: teaser, tag: 'p', fontSize: '1.06rem', color: '#c4cdd8', maxWidth: 600, marginTop: 22 },
],
},
},
{
id: 'default-buttons',
type: 'buttons',
x: 50,
y: 72,
z: 2,
anchor: 'center',
props: {
align: 'center',
gap: 12,
items: [
{ label: 'Enter the Website', to: '/site', variant: 'primary' },
{ label: 'Open the Wiki', to: '/wiki', variant: 'ghost' },
],
},
},
],
}
}
const QUICK = [
{ label: 'News', to: '/site/news' },
@@ -34,47 +91,47 @@ export default function Portal() {
settings.homepage_teaser ||
'Mysticmoon is still being shaped beneath a midnight sky — a quiet preview for the news, screenshots, guides, and community notes to come as the world wakes.'
// Parse the published layout; fall back to the pre-populated default if missing,
// malformed, the wrong version, or empty — so the hero is never blank.
const parsed = useMemo(() => {
try {
const l = settings.hero_layout ? JSON.parse(settings.hero_layout) : null
return l && l.version === 1 && Array.isArray(l.elements) && l.elements.length ? l : null
} catch {
return null
}
}, [settings.hero_layout])
const layout = parsed || defaultLayout(teaser)
const isDefault = !parsed
const bg = layout.background || {}
// Keep the exact multi-gradient look for the untouched default; otherwise build
// from the editor's overlay opacity over the chosen (or default) image.
const backgroundImage =
isDefault && !bg.image_url
? HERO_BG
: `${buildOverlay(layout.overlay?.opacity ?? 0.72)}, url('${bg.image_url || DEFAULT_HERO_IMAGE}')`
const elements = [...layout.elements].sort((a, b) => (a.z || 0) - (b.z || 0))
return (
<PublicLayout header={false}>
<main style={{ minHeight: '100vh', display: 'flex', flexDirection: 'column' }}>
<section
style={{
position: 'relative',
display: 'grid',
alignContent: 'center',
minHeight: 'clamp(600px,72vh,860px)',
padding: '96px max(18px,calc((100% - 1080px)/2)) 96px',
overflow: 'hidden',
textAlign: 'center',
backgroundColor: 'var(--bg-deep)',
backgroundImage: HERO_BG,
backgroundPosition: 'left center',
backgroundImage,
backgroundPosition: `${bg.position_x || 'left'} ${bg.position_y || 'center'}`,
backgroundRepeat: 'no-repeat',
backgroundSize: 'cover',
backgroundSize: bg.size || 'cover',
}}
>
<div style={{ maxWidth: 760, margin: '0 auto', textShadow: '0 2px 22px rgba(0,0,0,0.82)' }}>
<p className="eyebrow" style={{ color: '#c2d2e6', letterSpacing: '0.22em' }}>
Private shard project
</p>
<h1
className="display"
style={{ margin: 0, fontSize: 'clamp(3rem,8.5vw,5.75rem)', lineHeight: 1, letterSpacing: '0.02em' }}
>
UOMysticmoon
</h1>
<p style={{ margin: '22px auto 0', color: '#dbe2ea', fontSize: '1.32rem', fontStyle: 'italic' }}>
A private Ultima Online world in progress
</p>
<p style={{ maxWidth: 600, margin: '22px auto 0', color: '#c4cdd8', fontSize: '1.06rem' }}>{teaser}</p>
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, justifyContent: 'center', marginTop: 34 }}>
<Link to="/site" className="btn btn-primary">
Enter the Website
</Link>
<Link to="/wiki" className="btn btn-ghost">
Open the Wiki
</Link>
</div>
<div style={{ position: 'absolute', inset: 0, padding: '0 max(18px,calc((100% - 1080px)/2))' }}>
{elements.map((el) => (
<HeroElement key={el.id} element={el} />
))}
</div>
</section>