杂务:新增声明级注释覆盖率

This commit is contained in:
xiaowang
2026-05-23 18:44:57 +08:00
parent 8f038894e7
commit 844516988b
234 changed files with 8356 additions and 0 deletions
+68
View File
@@ -1,5 +1,13 @@
/**
* Purpose: SHOP_THEME_CHANGED_EVENT supports shop-theme.ts by holding or executing the shop theme changed event page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
export const SHOP_THEME_CHANGED_EVENT = 'yumi-shop-theme-updated'
/**
* Purpose: ShopThemeSource supports shop-theme.ts by holding or executing the shop theme source page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
export interface ShopThemeSource {
themePrimaryColor?: string | null
themeSecondaryColor?: string | null
@@ -9,6 +17,10 @@ export interface ShopThemeSource {
themeBackgroundImageFileId?: string | number | null
}
/**
* Purpose: ResolvedShopTheme supports shop-theme.ts by holding or executing the resolved shop theme page or API role.
* Usage: import, call, read, or update this interface from the owning page/module while preserving the surrounding loading and permission flow.
*/
export interface ResolvedShopTheme {
primaryColor: string
secondaryColor: string
@@ -25,14 +37,26 @@ export interface ResolvedShopTheme {
cssVars: Record<string, string>
}
/**
* Purpose: HEX_COLOR_PATTERN supports shop-theme.ts by holding or executing the hex color pattern page or API role.
* Usage: import, call, read, or update this const from the owning page/module while preserving the surrounding loading and permission flow.
*/
const HEX_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/
export const DEFAULT_SHOP_THEME: ResolvedShopTheme = resolveShopThemeSource()
/**
* Purpose: resolveShopTheme supports shop-theme.ts by holding or executing the resolve shop theme page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
export function resolveShopTheme(source?: ShopThemeSource | null): ResolvedShopTheme {
return resolveShopThemeSource(source)
}
/**
* Purpose: applyShopTheme supports shop-theme.ts by holding or executing the apply shop theme page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
export function applyShopTheme(theme: ResolvedShopTheme, backgroundImageUrl?: string | null) {
if (typeof document === 'undefined') {
return
@@ -44,6 +68,10 @@ export function applyShopTheme(theme: ResolvedShopTheme, backgroundImageUrl?: st
root.style.setProperty('--theme-background-image', backgroundImageUrl ? `url("${backgroundImageUrl}")` : 'none')
}
/**
* Purpose: notifyShopThemeChanged supports shop-theme.ts by holding or executing the notify shop theme changed page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
export function notifyShopThemeChanged() {
if (typeof window === 'undefined') {
return
@@ -51,6 +79,10 @@ export function notifyShopThemeChanged() {
window.dispatchEvent(new Event(SHOP_THEME_CHANGED_EVENT))
}
/**
* Purpose: resolveShopThemeSource supports shop-theme.ts by holding or executing the resolve shop theme source page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function resolveShopThemeSource(source?: ShopThemeSource | null): ResolvedShopTheme {
const normalizedPrimaryColor = normalizeHexColor(source?.themePrimaryColor)
const primaryColor = normalizedPrimaryColor || '#C6597D'
@@ -107,6 +139,10 @@ function resolveShopThemeSource(source?: ShopThemeSource | null): ResolvedShopTh
}
}
/**
* Purpose: normalizeHexColor supports shop-theme.ts by holding or executing the normalize hex color page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function normalizeHexColor(value?: string | null): string | undefined {
if (!value) {
return undefined
@@ -115,6 +151,10 @@ function normalizeHexColor(value?: string | null): string | undefined {
return HEX_COLOR_PATTERN.test(normalized) ? normalized.toUpperCase() : undefined
}
/**
* Purpose: mixColor supports shop-theme.ts by holding or executing the mix color page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function mixColor(foreground: string, background: string, backgroundWeight: number): string {
const fg = hexToRgb(foreground)
const bg = hexToRgb(background)
@@ -126,15 +166,27 @@ function mixColor(foreground: string, background: string, backgroundWeight: numb
})
}
/**
* Purpose: readableTextColor supports shop-theme.ts by holding or executing the readable text color page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function readableTextColor(background: string, preferred: string): string {
return relativeLuminance(hexToRgb(background)) > 0.48 ? preferred : '#FFFFFF'
}
/**
* Purpose: rgba supports shop-theme.ts by holding or executing the rgba page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function rgba(color: string, alpha: number): string {
const rgb = hexToRgb(color)
return `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${clamp(alpha, 0, 1)})`
}
/**
* Purpose: relativeLuminance supports shop-theme.ts by holding or executing the relative luminance page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function relativeLuminance(rgb: { r: number; g: number; b: number }): number {
const toLinearChannel = (value: number) => {
const channel = value / 255
@@ -146,6 +198,10 @@ function relativeLuminance(rgb: { r: number; g: number; b: number }): number {
return 0.2126 * r + 0.7152 * g + 0.0722 * b
}
/**
* Purpose: hexToRgb supports shop-theme.ts by holding or executing the hex to rgb page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function hexToRgb(color: string): { r: number; g: number; b: number } {
const value = color.replace('#', '')
return {
@@ -155,14 +211,26 @@ function hexToRgb(color: string): { r: number; g: number; b: number } {
}
}
/**
* Purpose: rgbToHex supports shop-theme.ts by holding or executing the rgb to hex page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function rgbToHex(rgb: { r: number; g: number; b: number }): string {
return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`
}
/**
* Purpose: toHex supports shop-theme.ts by holding or executing the to hex page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function toHex(value: number): string {
return clamp(value, 0, 255).toString(16).padStart(2, '0').toUpperCase()
}
/**
* Purpose: clamp supports shop-theme.ts by holding or executing the clamp page or API role.
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
*/
function clamp(value: number, min: number, max: number): number {
return Math.min(max, Math.max(min, value))
}