Coverage for fastblocks / adapters / fonts / _base.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-01-02 20:00 -0800

1"""Base classes and protocols for font adapters.""" 

2 

3from contextlib import suppress 

4from typing import Protocol 

5from uuid import UUID 

6 

7# Oneiric imports 

8from oneiric.core.config import OneiricSettings 

9from oneiric.core.resolution import Resolver 

10 

11# Oneiric resolver for dependency injection 

12depends = Resolver() 

13 

14 

15class FontsBaseSettings(OneiricSettings): 

16 """Base settings for font adapters using OneiricSettings.""" 

17 

18 primary_font: str = "Arial, sans-serif" 

19 secondary_font: str = "Georgia, serif" 

20 cdn_url: str | None = None 

21 font_weights: list[str] = ["400", "700"] 

22 

23 def __init__(self, **data: dict) -> None: 

24 super().__init__(**data) 

25 

26 

27class FontsProtocol(Protocol): 

28 """Protocol for font adapter implementations.""" 

29 

30 async def get_font_import(self) -> str: ... 

31 def get_font_family(self, font_type: str) -> str: ... 

32 

33 

34class FontsBase: 

35 """Base class for font adapters using Oneiric patterns.""" 

36 

37 # Oneiric-compatible metadata 

38 MODULE_ID: UUID = UUID("01937d86-4f2a-7b3c-8d9e-f3b4d3c2b1a4") # Static UUID7 

39 MODULE_STATUS = "stable" 

40 

41 def __init__(self) -> None: 

42 """Initialize font adapter.""" 

43 # Register with Oneiric resolver (fail gracefully if not supported) 

44 with suppress(Exception): 

45 depends.set(self) 

46 

47 async def get_font_import(self) -> str: 

48 """Generate font import statements.""" 

49 raise NotImplementedError() 

50 

51 def get_font_family(self, font_type: str) -> str: 

52 """Get font family CSS values.""" 

53 raise NotImplementedError()