chore(appliedFontsStore): move the FontLoadRequestConfig type and other types from appliedFontsStore into types directory
This commit is contained in:
@@ -8,6 +8,8 @@ export type {
|
|||||||
FontFeatures,
|
FontFeatures,
|
||||||
FontFiles,
|
FontFiles,
|
||||||
FontItem,
|
FontItem,
|
||||||
|
FontLoadRequestConfig,
|
||||||
|
FontLoadStatus,
|
||||||
FontMetadata,
|
FontMetadata,
|
||||||
FontProvider,
|
FontProvider,
|
||||||
// Fontshare API types
|
// Fontshare API types
|
||||||
@@ -37,7 +39,6 @@ export type {
|
|||||||
export {
|
export {
|
||||||
appliedFontsManager,
|
appliedFontsManager,
|
||||||
createUnifiedFontStore,
|
createUnifiedFontStore,
|
||||||
type FontConfigRequest,
|
|
||||||
type UnifiedFontStore,
|
type UnifiedFontStore,
|
||||||
unifiedFontStore,
|
unifiedFontStore,
|
||||||
} from './store';
|
} from './store';
|
||||||
|
|||||||
@@ -1,36 +1,13 @@
|
|||||||
import { SvelteMap } from 'svelte/reactivity';
|
import { SvelteMap } from 'svelte/reactivity';
|
||||||
|
import type {
|
||||||
|
FontLoadRequestConfig,
|
||||||
|
FontLoadStatus,
|
||||||
|
} from '../../types';
|
||||||
import {
|
import {
|
||||||
getEffectiveConcurrency,
|
getEffectiveConcurrency,
|
||||||
yieldToMainThread,
|
yieldToMainThread,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
/** Loading state of a font. Failed loads may be retried up to MAX_RETRIES. */
|
|
||||||
export type FontStatus = 'loading' | 'loaded' | 'error';
|
|
||||||
|
|
||||||
/** Configuration for a font load request. */
|
|
||||||
export interface FontConfigRequest {
|
|
||||||
/**
|
|
||||||
* Unique identifier for the font (e.g., "lato", "roboto").
|
|
||||||
*/
|
|
||||||
id: string;
|
|
||||||
/**
|
|
||||||
* Actual font family name recognized by the browser (e.g., "Lato", "Roboto").
|
|
||||||
*/
|
|
||||||
name: string;
|
|
||||||
/**
|
|
||||||
* URL pointing to the font file (typically .ttf or .woff2).
|
|
||||||
*/
|
|
||||||
url: string;
|
|
||||||
/**
|
|
||||||
* Numeric weight (100-900). Variable fonts load once per ID regardless of weight.
|
|
||||||
*/
|
|
||||||
weight: number;
|
|
||||||
/**
|
|
||||||
* Variable fonts load once per ID; static fonts load per weight.
|
|
||||||
*/
|
|
||||||
isVariable?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages web font loading with caching, adaptive concurrency, and automatic cleanup.
|
* Manages web font loading with caching, adaptive concurrency, and automatic cleanup.
|
||||||
*
|
*
|
||||||
@@ -62,7 +39,7 @@ export class AppliedFontsManager {
|
|||||||
#usageTracker = new Map<string, number>();
|
#usageTracker = new Map<string, number>();
|
||||||
|
|
||||||
// Fonts queued for loading by `touch()`, processed by `#processQueue()`
|
// Fonts queued for loading by `touch()`, processed by `#processQueue()`
|
||||||
#queue = new Map<string, FontConfigRequest>();
|
#queue = new Map<string, FontLoadRequestConfig>();
|
||||||
|
|
||||||
// Handle for scheduled queue processing (requestIdleCallback or setTimeout)
|
// Handle for scheduled queue processing (requestIdleCallback or setTimeout)
|
||||||
#timeoutId: ReturnType<typeof setTimeout> | null = null;
|
#timeoutId: ReturnType<typeof setTimeout> | null = null;
|
||||||
@@ -94,7 +71,7 @@ export class AppliedFontsManager {
|
|||||||
readonly #CACHE_NAME = 'font-cache-v1'; // Versioned for future invalidation
|
readonly #CACHE_NAME = 'font-cache-v1'; // Versioned for future invalidation
|
||||||
|
|
||||||
// Reactive status map for Svelte components to track font states
|
// Reactive status map for Svelte components to track font states
|
||||||
statuses = new SvelteMap<string, FontStatus>();
|
statuses = new SvelteMap<string, FontLoadStatus>();
|
||||||
|
|
||||||
// Starts periodic cleanup timer (browser-only).
|
// Starts periodic cleanup timer (browser-only).
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -114,7 +91,7 @@ export class AppliedFontsManager {
|
|||||||
* Retry behavior: 'loaded' and 'loading' fonts are skipped; 'error' fonts retry if count < MAX_RETRIES.
|
* Retry behavior: 'loaded' and 'loading' fonts are skipped; 'error' fonts retry if count < MAX_RETRIES.
|
||||||
* Scheduling: Prefers requestIdleCallback (150ms timeout), falls back to setTimeout(16ms).
|
* Scheduling: Prefers requestIdleCallback (150ms timeout), falls back to setTimeout(16ms).
|
||||||
*/
|
*/
|
||||||
touch(configs: FontConfigRequest[]) {
|
touch(configs: FontLoadRequestConfig[]) {
|
||||||
if (this.#abortController.signal.aborted) return;
|
if (this.#abortController.signal.aborted) return;
|
||||||
|
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|||||||
@@ -14,7 +14,4 @@ export {
|
|||||||
} from './unifiedFontStore.svelte';
|
} from './unifiedFontStore.svelte';
|
||||||
|
|
||||||
// Applied fonts manager (CSS loading - unchanged)
|
// Applied fonts manager (CSS loading - unchanged)
|
||||||
export {
|
export { appliedFontsManager } from './appliedFontsStore/appliedFontsStore.svelte';
|
||||||
appliedFontsManager,
|
|
||||||
type FontConfigRequest,
|
|
||||||
} from './appliedFontsStore/appliedFontsStore.svelte';
|
|
||||||
|
|||||||
@@ -56,3 +56,5 @@ export type {
|
|||||||
FontCollectionSort,
|
FontCollectionSort,
|
||||||
FontCollectionState,
|
FontCollectionState,
|
||||||
} from './store';
|
} from './store';
|
||||||
|
|
||||||
|
export * from './store/appliedFonts';
|
||||||
|
|||||||
30
src/entities/Font/model/types/store/appliedFonts.ts
Normal file
30
src/entities/Font/model/types/store/appliedFonts.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/**
|
||||||
|
* Configuration for a font load request.
|
||||||
|
*/
|
||||||
|
export interface FontLoadRequestConfig {
|
||||||
|
/**
|
||||||
|
* Unique identifier for the font (e.g., "lato", "roboto").
|
||||||
|
*/
|
||||||
|
id: string;
|
||||||
|
/**
|
||||||
|
* Actual font family name recognized by the browser (e.g., "Lato", "Roboto").
|
||||||
|
*/
|
||||||
|
name: string;
|
||||||
|
/**
|
||||||
|
* URL pointing to the font file (typically .ttf or .woff2).
|
||||||
|
*/
|
||||||
|
url: string;
|
||||||
|
/**
|
||||||
|
* Numeric weight (100-900). Variable fonts load once per ID regardless of weight.
|
||||||
|
*/
|
||||||
|
weight: number;
|
||||||
|
/**
|
||||||
|
* Variable fonts load once per ID; static fonts load per weight.
|
||||||
|
*/
|
||||||
|
isVariable?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loading state of a font.
|
||||||
|
*/
|
||||||
|
export type FontLoadStatus = 'loading' | 'loaded' | 'error';
|
||||||
@@ -15,7 +15,7 @@ import type {
|
|||||||
import { fade } from 'svelte/transition';
|
import { fade } from 'svelte/transition';
|
||||||
import { getFontUrl } from '../../lib';
|
import { getFontUrl } from '../../lib';
|
||||||
import {
|
import {
|
||||||
type FontConfigRequest,
|
type FontLoadRequestConfig,
|
||||||
type UnifiedFont,
|
type UnifiedFont,
|
||||||
appliedFontsManager,
|
appliedFontsManager,
|
||||||
unifiedFontStore,
|
unifiedFontStore,
|
||||||
@@ -54,7 +54,7 @@ const isLoading = $derived(
|
|||||||
);
|
);
|
||||||
|
|
||||||
function handleInternalVisibleChange(visibleItems: UnifiedFont[]) {
|
function handleInternalVisibleChange(visibleItems: UnifiedFont[]) {
|
||||||
const configs: FontConfigRequest[] = [];
|
const configs: FontLoadRequestConfig[] = [];
|
||||||
|
|
||||||
visibleItems.forEach(item => {
|
visibleItems.forEach(item => {
|
||||||
const url = getFontUrl(item, weight);
|
const url = getFontUrl(item, weight);
|
||||||
|
|||||||
Reference in New Issue
Block a user