LCOV - code coverage report
Current view: top level - src/platform/theme - themeStore.ts Coverage Total Hit
Test: ComfyUI E2E Coverage Lines: 75.0 % 20 15
Test Date: 2026-11-17 04:17:53

            Line data    Source code
       1              : import { defineStore } from 'pinia'
       2              : import { computed, ref } from 'vue'
       3              : 
       4              : import {
       5              :   BUILT_IN_THEME_PRESETS,
       6              :   DEFAULT_THEME_PRESET
       7              : } from '@comfyorg/theme-core/builtInThemePresets'
       8              : import { resolveTheme } from '@comfyorg/theme-core/resolveTheme'
       9              : import type {
      10              :   ThemePreset,
      11              :   ThemePresets
      12              : } from '@comfyorg/theme-core/themePresetSchema'
      13              : 
      14         2356 : export const useThemeStore = defineStore('theme', () => {
      15         2355 :   const customPresets = ref<ThemePresets>({})
      16         2355 :   const activePresetId = ref<string>(DEFAULT_THEME_PRESET.id)
      17         2355 :   const presetsLookup = computed<Partial<ThemePresets>>(() => ({
      18              :     ...BUILT_IN_THEME_PRESETS,
      19              :     ...customPresets.value
      20              :   }))
      21         2355 :   const presets = computed(() =>
      22              :     Object.values(presetsLookup.value).filter(
      23              :       (preset): preset is ThemePreset => preset !== undefined
      24              :     )
      25              :   )
      26         2355 :   const activeTheme = computed(() =>
      27              :     resolveTheme(
      28              :       presetsLookup.value[activePresetId.value] ?? DEFAULT_THEME_PRESET
      29              :     )
      30              :   )
      31         2355 :   const colorScheme = computed(() => activeTheme.value.colorScheme)
      32              : 
      33            1 :   function addCustomPreset(preset: ThemePreset) {
      34            1 :     if (preset.id in presetsLookup.value) return false
      35            1 :     customPresets.value[preset.id] = preset
      36            1 :     activePresetId.value = preset.id
      37            1 :     return true
      38              :   }
      39              : 
      40            0 :   function deleteCustomPreset(id: string) {
      41            0 :     if (!(id in customPresets.value)) return false
      42            0 :     delete customPresets.value[id]
      43            0 :     activePresetId.value = BUILT_IN_THEME_PRESETS.dark.id
      44            0 :     return true
      45              :   }
      46              : 
      47            7 :   function isCustomPreset(id: string) {
      48            7 :     return id in customPresets.value
      49              :   }
      50              : 
      51         2355 :   return {
      52              :     customPresets,
      53              :     activePresetId,
      54              :     presetsLookup,
      55              :     presets,
      56              :     activeTheme,
      57              :     colorScheme,
      58              :     isCustomPreset,
      59              :     addCustomPreset,
      60              :     deleteCustomPreset
      61              :   }
      62              : })
        

Generated by: LCOV version 2.0-1