diff --git a/src/entities/Font/api/index.ts b/src/entities/Font/api/index.ts index 6656408..9e9ed8e 100644 --- a/src/entities/Font/api/index.ts +++ b/src/entities/Font/api/index.ts @@ -30,10 +30,3 @@ export { normalizeGoogleFont, normalizeGoogleFonts, } from './normalize/normalize'; -export type { - FontFeatures, - FontMetadata, - FontStyleUrls, - UnifiedFont, - UnifiedFontVariant, -} from './normalize/normalize'; diff --git a/src/entities/Font/api/normalize/normalize.ts b/src/entities/Font/api/normalize/normalize.ts index 2dda371..116d64d 100644 --- a/src/entities/Font/api/normalize/normalize.ts +++ b/src/entities/Font/api/normalize/normalize.ts @@ -15,7 +15,6 @@ import type { FontshareFont, GoogleFontItem, UnifiedFont, - UnifiedFontVariant, } from '../../model/types'; /** @@ -128,14 +127,15 @@ export function normalizeGoogleFont(apiFont: GoogleFontItem): UnifiedFont { // Map variant files to style URLs const styles: FontStyleUrls = {}; for (const [variant, url] of Object.entries(apiFont.files)) { + const urlString = url as string; // Type assertion for Record if (variant === 'regular' || variant === '400') { - styles.regular = url; + styles.regular = urlString; } else if (variant === 'italic' || variant === '400italic') { - styles.italic = url; + styles.italic = urlString; } else if (variant === 'bold' || variant === '700') { - styles.bold = url; + styles.bold = urlString; } else if (variant === 'bolditalic' || variant === '700italic') { - styles.boldItalic = url; + styles.boldItalic = urlString; } } diff --git a/src/entities/Font/index.ts b/src/entities/Font/index.ts index dfd765f..74250a0 100644 --- a/src/entities/Font/index.ts +++ b/src/entities/Font/index.ts @@ -2,20 +2,20 @@ export { fetchAllFontshareFonts, fetchFontshareFontBySlug, fetchFontshareFonts, -} from './api/fontshare'; +} from './api/fontshare/fontshare'; export type { FontshareParams, FontshareResponse, -} from './api/fontshare'; +} from './api/fontshare/fontshare'; export { fetchGoogleFontFamily, fetchGoogleFonts, -} from './api/googleFonts'; +} from './api/google/googleFonts'; export type { GoogleFontItem, GoogleFontsParams, GoogleFontsResponse, -} from './api/googleFonts'; +} from './api/google/googleFonts'; export { normalizeFontshareFont, normalizeFontshareFonts, diff --git a/src/entities/Font/model/stores/fontCollectionStore.ts b/src/entities/Font/model/stores/fontCollectionStore.ts index cff581a..b4cca62 100644 --- a/src/entities/Font/model/stores/fontCollectionStore.ts +++ b/src/entities/Font/model/stores/fontCollectionStore.ts @@ -18,10 +18,7 @@ import type { UnifiedFont, } from '$entities/Font'; import { createCollectionCache } from '$shared/fetch/collectionCache'; -import type { - Readable, - Writable, -} from 'svelte/store'; +import type { Writable } from 'svelte/store'; import { derived, get, diff --git a/src/entities/Font/model/stores/index.ts b/src/entities/Font/model/stores/index.ts index eba84c8..e260461 100644 --- a/src/entities/Font/model/stores/index.ts +++ b/src/entities/Font/model/stores/index.ts @@ -4,10 +4,10 @@ * Exports font collection store types and factory function */ -export { createFontCollectionStore } from './fontCollectionStore'; export type { FontCollectionFilters, FontCollectionSort, FontCollectionState, FontCollectionStore, -} from './fontCollectionStore'; +} from '../types'; +export { createFontCollectionStore } from './fontCollectionStore'; diff --git a/src/entities/Font/model/types.ts b/src/entities/Font/model/types.ts index 9b8093f..2aa6c21 100644 --- a/src/entities/Font/model/types.ts +++ b/src/entities/Font/model/types.ts @@ -22,8 +22,7 @@ export type FontSubset = 'latin' | 'latin-ext' | 'cyrillic' | 'greek' | 'arabic' /** * ============================================================================ * GOOGLE FONTS API TYPES - * ============================================================================ - */ + * ============================================================================ */ /** * Model of google fonts api response @@ -99,6 +98,75 @@ export interface FontItem { menu: string; } +/** + * Type alias for backward compatibility + * Google Fonts API font item + */ +export type GoogleFontItem = FontItem; + +/** + * Individual font from Google Fonts API + */ +export interface FontItem { + /** + * Font family name (e.g., "Roboto", "Open Sans", "Lato") + * This is the name used in CSS font-family declarations + */ + family: string; + + /** + * Font category classification (e.g., "sans-serif", "serif", "display", "handwriting", "monospace") + * Useful for grouping and filtering fonts by style + */ + category: string; + + /** + * Available font variants for this font family + * Array of strings representing available weights and styles + * Examples: ["regular", "italic", "100", "200", "300", "400", "500", "600", "700", "800", "900", "100italic", "900italic"] + * The keys in the `files` object correspond to these variant values + */ + variants: FontVariant[]; + + /** + * Supported character subsets for this font + * Examples: ["latin", "latin-ext", "cyrillic", "greek", "arabic", "devanagari", "vietnamese", "hebrew", "thai", etc.] + * Determines which character sets are included in the font files + */ + subsets: string[]; + + /** + * Font version identifier + * Format: "v" followed by version number (e.g., "v31", "v20", "v1") + * Used to track font updates and cache busting + */ + version: string; + + /** + * Last modification date of the font + * Format: ISO 8601 date string (e.g., "2024-01-15", "2023-12-01") + * Indicates when the font was last updated by the font foundry + */ + lastModified: string; + + /** + * Mapping of font variants to their downloadable URLs + * Keys correspond to values in the `variants` array + * Examples: + * - "regular" → "https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Me4W..." + * - "700" → "https://fonts.gstatic.com/s/roboto/v30/KFOlCnqEu92Fr1MmWUlf..." + * - "700italic" → "https://fonts.gstatic.com/s/roboto/v30/KFOjCnqEu92Fr1Mu51TzA..." + */ + files: FontFiles; + + /** + * URL to the font menu preview image + * Typically a PNG showing the font family name in the font + * Example: "https://fonts.gstatic.com/l/font?kit=KFOmCnqEu92Fr1Me4W...&s=i2" + */ + menu: string; +} + /** * Standard font weights that can appear in Google Fonts API */