@@ -378,10 +378,28 @@ function Read-DreamSkinTheme {
378378 Directory = $directory
379379 ThemePath = $themePath
380380 ImagePath = $imagePath
381- Theme = $theme
381+ Theme = Normalize - DreamSkinThemeContract - Theme $theme
382382 }
383383}
384384
385+ function Normalize-DreamSkinThemeContract {
386+ param ([Parameter (Mandatory = $true )][object ]$Theme )
387+ if ($null -eq $Theme -or $Theme -is [string ] -or $Theme -is [array ]) {
388+ throw ' Theme contract must be a JSON object.'
389+ }
390+ if (-not $Theme.PSObject.Properties [' id' ] -or -not $Theme.PSObject.Properties [' id' ].Value) {
391+ $Theme | Add-Member - NotePropertyName id - NotePropertyValue ' custom' - Force
392+ }
393+ if (-not $Theme.PSObject.Properties [' appearance' ] -or -not $Theme.PSObject.Properties [' appearance' ].Value) {
394+ $Theme | Add-Member - NotePropertyName appearance - NotePropertyValue ' auto' - Force
395+ }
396+ if (-not $Theme.PSObject.Properties [' art' ] -or -not $Theme.PSObject.Properties [' art' ].Value) {
397+ $Theme | Add-Member - NotePropertyName art - NotePropertyValue `
398+ ([pscustomobject ]@ { focusX = $null ; focusY = $null ; safeArea = ' auto' ; taskMode = ' auto' }) - Force
399+ }
400+ return $Theme
401+ }
402+
385403function Write-DreamSkinTheme {
386404 param (
387405 [Parameter (Mandatory = $true )][string ]$ThemeDirectory ,
@@ -390,6 +408,7 @@ function Write-DreamSkinTheme {
390408 Assert-DreamSkinNoReparseComponents - Path $ThemeDirectory
391409 New-Item - ItemType Directory - Force - Path $ThemeDirectory | Out-Null
392410 Assert-DreamSkinNoReparseComponents - Path $ThemeDirectory
411+ $Theme = Normalize- DreamSkinThemeContract - Theme $Theme
393412 $json = $Theme | ConvertTo-Json - Depth 8
394413 $themePath = Join-Path $ThemeDirectory ' theme.json'
395414 Assert-DreamSkinNoReparseComponents - Path $themePath
@@ -538,7 +557,6 @@ function Set-DreamSkinActiveTheme {
538557 name = ' 自定义主题'
539558 appearance = ' auto'
540559 art = [pscustomobject ]@ { focusX = $null ; focusY = $null ; safeArea = ' auto' ; taskMode = ' auto' }
541- palette = [pscustomobject ]@ {}
542560 }
543561 }
544562 $imageName = New-DreamSkinThemeImageName - Extension $extension
@@ -564,15 +582,7 @@ function Set-DreamSkinActiveTheme {
564582 Assert-DreamSkinImageFile - Path $target
565583 $Theme | Add-Member - NotePropertyName image - NotePropertyValue $imageName - Force
566584 if ($Name ) { $Theme | Add-Member - NotePropertyName name - NotePropertyValue $Name - Force }
567- if (-not $Theme.id ) { $Theme | Add-Member - NotePropertyName id - NotePropertyValue ' custom' - Force }
568- if (-not $Theme.appearance ) { $Theme | Add-Member - NotePropertyName appearance - NotePropertyValue ' auto' - Force }
569- if (-not $Theme.art ) {
570- $Theme | Add-Member - NotePropertyName art - NotePropertyValue `
571- ([pscustomobject ]@ { focusX = $null ; focusY = $null ; safeArea = ' auto' ; taskMode = ' auto' }) - Force
572- }
573- if (-not $Theme.palette ) {
574- $Theme | Add-Member - NotePropertyName palette - NotePropertyValue ([pscustomobject ]@ {}) - Force
575- }
585+ $Theme = Normalize- DreamSkinThemeContract - Theme $Theme
576586 $activeCss = Join-Path $paths.Active ' theme.css'
577587 Assert-DreamSkinNoReparseComponents - Path $activeCss
578588 if ($temporaryCss ) {
@@ -715,19 +725,7 @@ function Get-DreamSkinThemeRuntimeContentFingerprint {
715725 $loaded = Read-DreamSkinTheme - ThemeDirectory $ThemeDirectory - SkipImageMetadata
716726 $runtimeTheme = $loaded.Theme | ConvertTo-Json - Depth 8 | ConvertFrom-Json
717727 $runtimeTheme.image = ' <runtime-image>'
718- if (-not $runtimeTheme.id ) {
719- $runtimeTheme | Add-Member - NotePropertyName id - NotePropertyValue ' custom' - Force
720- }
721- if (-not $runtimeTheme.appearance ) {
722- $runtimeTheme | Add-Member - NotePropertyName appearance - NotePropertyValue ' auto' - Force
723- }
724- if (-not $runtimeTheme.art ) {
725- $runtimeTheme | Add-Member - NotePropertyName art - NotePropertyValue `
726- ([pscustomobject ]@ { focusX = $null ; focusY = $null ; safeArea = ' auto' ; taskMode = ' auto' }) - Force
727- }
728- if (-not $runtimeTheme.palette ) {
729- $runtimeTheme | Add-Member - NotePropertyName palette - NotePropertyValue ([pscustomobject ]@ {}) - Force
730- }
728+ $runtimeTheme = Normalize- DreamSkinThemeContract - Theme $runtimeTheme
731729 $canonicalTheme = ConvertTo-DreamSkinCanonicalJsonValue - Value $runtimeTheme
732730 $themeBytes = [System.Text.Encoding ]::UTF8.GetBytes(
733731 ($canonicalTheme | ConvertTo-Json - Depth 8 - Compress)
0 commit comments