|
| 1 | +import type { SiteLogoConfig } from '@purestack/ts-common' |
| 2 | +import { pickSemanticTone } from '@purestack/ts-style' |
| 3 | +import type { DeepPartial } from '@purestack/ts-util' |
| 4 | +import { |
| 5 | + resolveConfigUrl, |
| 6 | + resolveOptionalString, |
| 7 | + resolveString, |
| 8 | +} from '@purestack/ts-util' |
| 9 | + |
| 10 | +export function resolveSiteLogoConfig( |
| 11 | + input?: DeepPartial<SiteLogoConfig>, |
| 12 | + file?: DeepPartial<SiteLogoConfig>, |
| 13 | +): SiteLogoConfig { |
| 14 | + const href = input?.href !== undefined ? input.href : file?.href |
| 15 | + return { |
| 16 | + brand: resolveString(input?.brand, file?.brand, 'Pure Stack'), |
| 17 | + letterColors: resolveOptionalString( |
| 18 | + input?.letterColors ?? file?.letterColors, |
| 19 | + ), |
| 20 | + subtitleLetterColors: resolveOptionalString( |
| 21 | + input?.subtitleLetterColors ?? file?.subtitleLetterColors, |
| 22 | + ), |
| 23 | + brandSizeSm: resolveOptionalString(input?.brandSizeSm ?? file?.brandSizeSm), |
| 24 | + brandSizeMd: resolveOptionalString(input?.brandSizeMd ?? file?.brandSizeMd), |
| 25 | + brandSizeLg: resolveOptionalString(input?.brandSizeLg ?? file?.brandSizeLg), |
| 26 | + brandSizeXl: resolveOptionalString(input?.brandSizeXl ?? file?.brandSizeXl), |
| 27 | + subtitleSizeSm: resolveOptionalString( |
| 28 | + input?.subtitleSizeSm ?? file?.subtitleSizeSm, |
| 29 | + ), |
| 30 | + subtitleSizeMd: resolveOptionalString( |
| 31 | + input?.subtitleSizeMd ?? file?.subtitleSizeMd, |
| 32 | + ), |
| 33 | + subtitleSizeLg: resolveOptionalString( |
| 34 | + input?.subtitleSizeLg ?? file?.subtitleSizeLg, |
| 35 | + ), |
| 36 | + subtitleSizeXl: resolveOptionalString( |
| 37 | + input?.subtitleSizeXl ?? file?.subtitleSizeXl, |
| 38 | + ), |
| 39 | + iconSize: resolveOptionalString(input?.iconSize ?? file?.iconSize), |
| 40 | + iconSizeSm: resolveOptionalString(input?.iconSizeSm ?? file?.iconSizeSm), |
| 41 | + iconSizeMd: resolveOptionalString(input?.iconSizeMd ?? file?.iconSizeMd), |
| 42 | + iconSizeLg: resolveOptionalString(input?.iconSizeLg ?? file?.iconSizeLg), |
| 43 | + iconSizeXl: resolveOptionalString(input?.iconSizeXl ?? file?.iconSizeXl), |
| 44 | + subtitleInset: resolveOptionalString( |
| 45 | + input?.subtitleInset ?? file?.subtitleInset, |
| 46 | + ), |
| 47 | + subtitleInsetSm: resolveOptionalString( |
| 48 | + input?.subtitleInsetSm ?? file?.subtitleInsetSm, |
| 49 | + ), |
| 50 | + subtitleInsetMd: resolveOptionalString( |
| 51 | + input?.subtitleInsetMd ?? file?.subtitleInsetMd, |
| 52 | + ), |
| 53 | + subtitleInsetLg: resolveOptionalString( |
| 54 | + input?.subtitleInsetLg ?? file?.subtitleInsetLg, |
| 55 | + ), |
| 56 | + subtitleInsetXl: resolveOptionalString( |
| 57 | + input?.subtitleInsetXl ?? file?.subtitleInsetXl, |
| 58 | + ), |
| 59 | + component: resolveOptionalString(input?.component ?? file?.component), |
| 60 | + colors: (input?.colors ?? file?.colors)?.filter( |
| 61 | + (color): color is string => typeof color === 'string', |
| 62 | + ), |
| 63 | + logoBackground: input?.logoBackground ?? file?.logoBackground, |
| 64 | + logoForeground: input?.logoForeground ?? file?.logoForeground, |
| 65 | + href: |
| 66 | + href === null || href === '' |
| 67 | + ? href |
| 68 | + : resolveConfigUrl(resolveString(href, '/')), |
| 69 | + subtitle: resolveOptionalString(input?.subtitle ?? file?.subtitle), |
| 70 | + suffix: resolveOptionalString(input?.suffix ?? file?.suffix), |
| 71 | + ariaLabel: resolveOptionalString(input?.ariaLabel ?? file?.ariaLabel), |
| 72 | + icon: resolveOptionalString(input?.icon ?? file?.icon), |
| 73 | + imageSrc: resolveConfigUrl( |
| 74 | + resolveOptionalString(input?.imageSrc ?? file?.imageSrc), |
| 75 | + ), |
| 76 | + imageSrcDark: resolveConfigUrl( |
| 77 | + resolveOptionalString(input?.imageSrcDark ?? file?.imageSrcDark), |
| 78 | + ), |
| 79 | + monogram: resolveOptionalString(input?.monogram ?? file?.monogram), |
| 80 | + brandColor: resolveOptionalString(input?.brandColor ?? file?.brandColor), |
| 81 | + accentColor: resolveOptionalString(input?.accentColor ?? file?.accentColor), |
| 82 | + markBackground: resolveOptionalString( |
| 83 | + input?.markBackground ?? file?.markBackground, |
| 84 | + ), |
| 85 | + markColor: resolveOptionalString(input?.markColor ?? file?.markColor), |
| 86 | + brandSize: resolveOptionalString(input?.brandSize ?? file?.brandSize), |
| 87 | + subtitleSize: resolveOptionalString( |
| 88 | + input?.subtitleSize ?? file?.subtitleSize, |
| 89 | + ), |
| 90 | + markSize: resolveOptionalString(input?.markSize ?? file?.markSize), |
| 91 | + gap: resolveOptionalString(input?.gap ?? file?.gap), |
| 92 | + layout: resolveLogoChoice(input?.layout ?? file?.layout, [ |
| 93 | + 'horizontal', |
| 94 | + 'stacked', |
| 95 | + 'wordmark', |
| 96 | + 'mark', |
| 97 | + ] as const), |
| 98 | + size: resolveLogoChoice(input?.size ?? file?.size, [ |
| 99 | + 'sm', |
| 100 | + 'md', |
| 101 | + 'lg', |
| 102 | + 'xl', |
| 103 | + ] as const), |
| 104 | + appearance: resolveLogoChoice(input?.appearance ?? file?.appearance, [ |
| 105 | + 'plain', |
| 106 | + 'badge', |
| 107 | + 'outline', |
| 108 | + ] as const), |
| 109 | + markStyle: resolveLogoChoice(input?.markStyle ?? file?.markStyle, [ |
| 110 | + 'plain', |
| 111 | + 'soft', |
| 112 | + 'solid', |
| 113 | + 'outline', |
| 114 | + ] as const), |
| 115 | + wordmarkStyle: resolveLogoChoice( |
| 116 | + input?.wordmarkStyle ?? file?.wordmarkStyle, |
| 117 | + ['plain', 'accent', 'gradient'] as const, |
| 118 | + ), |
| 119 | + shape: resolveLogoChoice(input?.shape ?? file?.shape, [ |
| 120 | + 'rounded', |
| 121 | + 'square', |
| 122 | + 'circle', |
| 123 | + ] as const), |
| 124 | + tone: pickSemanticTone(input?.tone, file?.tone), |
| 125 | + } |
| 126 | +} |
| 127 | + |
| 128 | +function resolveLogoChoice<T extends string>( |
| 129 | + value: unknown, |
| 130 | + choices: readonly T[], |
| 131 | +): T | undefined { |
| 132 | + return typeof value === 'string' && choices.includes(value as T) |
| 133 | + ? (value as T) |
| 134 | + : undefined |
| 135 | +} |
0 commit comments