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, normalizeGoogleFont,
normalizeGoogleFonts, normalizeGoogleFonts,
} from './normalize/normalize'; } from './normalize/normalize';
export type {
FontFeatures,
FontMetadata,
FontStyleUrls,
UnifiedFont,
UnifiedFontVariant,
} from './normalize/normalize';

View File

@@ -15,7 +15,6 @@ import type {
FontshareFont, FontshareFont,
GoogleFontItem, GoogleFontItem,
UnifiedFont, UnifiedFont,
UnifiedFontVariant,
} from '../../model/types'; } from '../../model/types';
/** /**
@@ -128,14 +127,15 @@ export function normalizeGoogleFont(apiFont: GoogleFontItem): UnifiedFont {
// Map variant files to style URLs // Map variant files to style URLs
const styles: FontStyleUrls = {}; const styles: FontStyleUrls = {};
for (const [variant, url] of Object.entries(apiFont.files)) { 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') { if (variant === 'regular' || variant === '400') {
styles.regular = url; styles.regular = urlString;
} else if (variant === 'italic' || variant === '400italic') { } else if (variant === 'italic' || variant === '400italic') {
styles.italic = url; styles.italic = urlString;
} else if (variant === 'bold' || variant === '700') { } else if (variant === 'bold' || variant === '700') {
styles.bold = url; styles.bold = urlString;
} else if (variant === 'bolditalic' || variant === '700italic') { } else if (variant === 'bolditalic' || variant === '700italic') {
styles.boldItalic = url; styles.boldItalic = urlString;
} }
} }

View File

@@ -2,20 +2,20 @@ export {
fetchAllFontshareFonts, fetchAllFontshareFonts,
fetchFontshareFontBySlug, fetchFontshareFontBySlug,
fetchFontshareFonts, fetchFontshareFonts,
} from './api/fontshare'; } from './api/fontshare/fontshare';
export type { export type {
FontshareParams, FontshareParams,
FontshareResponse, FontshareResponse,
} from './api/fontshare'; } from './api/fontshare/fontshare';
export { export {
fetchGoogleFontFamily, fetchGoogleFontFamily,
fetchGoogleFonts, fetchGoogleFonts,
} from './api/googleFonts'; } from './api/google/googleFonts';
export type { export type {
GoogleFontItem, GoogleFontItem,
GoogleFontsParams, GoogleFontsParams,
GoogleFontsResponse, GoogleFontsResponse,
} from './api/googleFonts'; } from './api/google/googleFonts';
export { export {
normalizeFontshareFont, normalizeFontshareFont,
normalizeFontshareFonts, normalizeFontshareFonts,

View File

@@ -18,10 +18,7 @@ import type {
UnifiedFont, UnifiedFont,
} from '$entities/Font'; } from '$entities/Font';
import { createCollectionCache } from '$shared/fetch/collectionCache'; import { createCollectionCache } from '$shared/fetch/collectionCache';
import type { import type { Writable } from 'svelte/store';
Readable,
Writable,
} from 'svelte/store';
import { import {
derived, derived,
get, get,

View File

@@ -4,10 +4,10 @@
* Exports font collection store types and factory function * Exports font collection store types and factory function
*/ */
export { createFontCollectionStore } from './fontCollectionStore';
export type { export type {
FontCollectionFilters, FontCollectionFilters,
FontCollectionSort, FontCollectionSort,
FontCollectionState, FontCollectionState,
FontCollectionStore, 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 * GOOGLE FONTS API TYPES
* ============================================================================ * ============================================================================ */
*/
/** /**
* Model of google fonts api response * Model of google fonts api response
@@ -99,6 +98,75 @@ export interface FontItem {
menu: string; 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 * Standard font weights that can appear in Google Fonts API
*/ */