Make the hero Moon image configurable (src/alt), backwards-compatible #20

Merged
whitlocktech merged 2 commits from feature/configurable-moon-image into main 2026-07-03 04:45:26 +00:00
Showing only changes of commit 7e8ffeee6f - Show all commits

View File

@@ -12,6 +12,17 @@ const round2 = (v) => Math.round(v * 100) / 100
const genId = () => (crypto.randomUUID ? crypto.randomUUID() : `el-${Date.now()}-${Math.random()}`)
const hexOf = (v) => (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(v || '') ? v : '#ffffff')
// Soft page-weight warning shown before uploading a large hero image. This is
// only a nudge (hero images render on the public landing page); the server hard-
// limits uploads at 8 MB. Returns true when the caller should abort the upload.
const WARN_UPLOAD_MB = 5
function tooLargeToUpload(size) {
return (
size > WARN_UPLOAD_MB * 1024 * 1024 &&
!confirm(`This image is over ${WARN_UPLOAD_MB} MB and may slow the page. Upload anyway?`)
)
}
function newElement(type, z) {
const base = { id: genId(), type, x: 50, y: 50, z, anchor: 'center' }
if (type === 'text_block') {
@@ -206,7 +217,7 @@ export default function HeroEditor() {
const file = e.target.files?.[0]
e.target.value = ''
if (!file) return
if (file.size > 1024 * 1024 && !confirm('This image is over 1 MB and may slow the page. Upload anyway?')) return
if (tooLargeToUpload(file.size)) return
setUploading(true)
try {
const { url } = await api.admin.upload(file)
@@ -506,7 +517,7 @@ function MoonPanel({ element, onProps }) {
const f = e.target.files?.[0]
e.target.value = ''
if (!f) return
if (f.size > 1024 * 1024 && !confirm('This image is over 1 MB and may slow the page. Upload anyway?')) return
if (tooLargeToUpload(f.size)) return
setUp(true)
try {
const { url } = await api.admin.upload(f)
@@ -583,7 +594,7 @@ function ImagePanel({ element, onProps }) {
const f = e.target.files?.[0]
e.target.value = ''
if (!f) return
if (f.size > 1024 * 1024 && !confirm('This image is over 1 MB and may slow the page. Upload anyway?')) return
if (tooLargeToUpload(f.size)) return
setUp(true)
try {
const { url } = await api.admin.upload(f)