chore(theme): re-vendor cms theme copies for font size steps

Picks up FontSizeStepKeys/DefaultFontSizeSteps/ValidateFontSizeSteps and
the FontSizeSteps field on ThemeTypography, so the preset gate's
DisallowUnknownFields parse accepts presets shipping fontSizeSteps.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Alex Dunmow 2026-08-04 00:54:07 +08:00
parent 6fb2519cfd
commit 08da6a4723
2 changed files with 37 additions and 0 deletions

View File

@ -236,6 +236,7 @@ type ThemeTypography struct {
LineHeightBase string `json:"lineHeightBase"` LineHeightBase string `json:"lineHeightBase"`
FontWeightBase string `json:"fontWeightBase"` FontWeightBase string `json:"fontWeightBase"`
FontSizeOverrides map[string]string `json:"fontSizeOverrides,omitempty"` FontSizeOverrides map[string]string `json:"fontSizeOverrides,omitempty"`
FontSizeSteps map[string]string `json:"fontSizeSteps,omitempty"`
} }
// ThemeSpacing represents spacing settings // ThemeSpacing represents spacing settings

View File

@ -3,6 +3,7 @@ package theme
import ( import (
"fmt" "fmt"
"regexp" "regexp"
"slices"
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
@ -19,6 +20,41 @@ var fontSizeOverrideKeys = map[string]bool{
var fontSizePattern = regexp.MustCompile(`^(\d+(?:\.\d+)?|\.\d+)(rem|px)$`) var fontSizePattern = regexp.MustCompile(`^(\d+(?:\.\d+)?|\.\d+)(rem|px)$`)
var fontSizeStepKeys = []string{"small", "normal", "large", "huge"}
// FontSizeStepKeys returns the canonical step keys in display order.
func FontSizeStepKeys() []string {
return slices.Clone(fontSizeStepKeys)
}
// DefaultFontSizeSteps returns the fallback rem value for each step.
func DefaultFontSizeSteps() map[string]string {
return map[string]string{
"small": "0.875rem",
"normal": "1rem",
"large": "1.125rem",
"huge": "1.25rem",
}
}
// ValidateFontSizeSteps rejects unknown keys and non-rem values. Steps feed the
// base-size UI chips only and are never emitted to CSS; rem-only so chips always
// scale with visitor preferences.
func ValidateFontSizeSteps(steps map[string]string) error {
for k, v := range steps {
if !slices.Contains(fontSizeStepKeys, k) {
return fmt.Errorf("unknown font size step %q (valid: %s)", k, strings.Join(fontSizeStepKeys, ", "))
}
if err := ValidateFontSize(v); err != nil {
return err
}
if !strings.HasSuffix(v, "rem") {
return fmt.Errorf("font size step %q must be a rem value, got %q", k, v)
}
}
return nil
}
// FontSizeOverrideKeys returns the canonical override keys, sorted. // FontSizeOverrideKeys returns the canonical override keys, sorted.
func FontSizeOverrideKeys() []string { func FontSizeOverrideKeys() []string {
keys := make([]string, 0, len(fontSizeOverrideKeys)) keys := make([]string, 0, len(fontSizeOverrideKeys))