feature/fetch-fonts #14

Merged
ilia merged 76 commits from feature/fetch-fonts into main 2026-01-14 11:01:44 +00:00
6 changed files with 82 additions and 24 deletions
Showing only changes of commit db814f0b93 - Show all commits

View File

@@ -30,10 +30,3 @@ export {
normalizeGoogleFont,
normalizeGoogleFonts,
} from './normalize/normalize';
export type {
FontFeatures,
FontMetadata,
FontStyleUrls,
UnifiedFont,
UnifiedFontVariant,
} from './normalize/normalize';

View File

@@ -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<string, string>
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;
}
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -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';

View File

@@ -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
*/