refactor/code-splitting #31
@@ -1,7 +1,7 @@
|
||||
/** @vitest-environment jsdom */
|
||||
import { AppliedFontsManager } from './appliedFontsStore.svelte';
|
||||
import { FontFetchError } from './errors';
|
||||
import { FontEvictionPolicy } from './fontEvictionPolicy/FontEvictionPolicy';
|
||||
import { FontEvictionPolicy } from './utils/fontEvictionPolicy/FontEvictionPolicy';
|
||||
|
||||
// ── Fake collaborators ────────────────────────────────────────────────────────
|
||||
|
||||
|
||||
@@ -7,15 +7,15 @@ import {
|
||||
FontFetchError,
|
||||
FontParseError,
|
||||
} from './errors';
|
||||
import { FontBufferCache } from './fontBufferCache/FontBufferCache';
|
||||
import { FontEvictionPolicy } from './fontEvictionPolicy/FontEvictionPolicy';
|
||||
import { FontLoadQueue } from './fontLoadQueue/FontLoadQueue';
|
||||
import {
|
||||
generateFontKey,
|
||||
getEffectiveConcurrency,
|
||||
loadFont,
|
||||
yieldToMainThread,
|
||||
} from './utils';
|
||||
import { FontBufferCache } from './utils/fontBufferCache/FontBufferCache';
|
||||
import { FontEvictionPolicy } from './utils/fontEvictionPolicy/FontEvictionPolicy';
|
||||
import { FontLoadQueue } from './utils/fontLoadQueue/FontLoadQueue';
|
||||
|
||||
interface AppliedFontsManagerDeps {
|
||||
cache?: FontBufferCache;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/** @vitest-environment jsdom */
|
||||
import { FontFetchError } from '../errors';
|
||||
import { FontFetchError } from '../../errors';
|
||||
import { FontBufferCache } from './FontBufferCache';
|
||||
|
||||
const makeBuffer = () => new ArrayBuffer(8);
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FontFetchError } from '../errors';
|
||||
import { FontFetchError } from '../../errors';
|
||||
|
||||
type Fetcher = (url: string, init?: RequestInit) => Promise<Response>;
|
||||
|
||||
@@ -40,7 +40,9 @@ export class FontBufferCache {
|
||||
async get(url: string, signal?: AbortSignal): Promise<ArrayBuffer> {
|
||||
// Tier 1: in-memory (fastest, no I/O)
|
||||
const inMemory = this.#buffersByUrl.get(url);
|
||||
if (inMemory) return inMemory;
|
||||
if (inMemory) {
|
||||
return inMemory;
|
||||
}
|
||||
|
||||
// Tier 2: Cache API
|
||||
try {
|
||||
@@ -48,8 +48,12 @@ export class FontEvictionPolicy {
|
||||
*/
|
||||
shouldEvict(key: string, now: number): boolean {
|
||||
const lastUsed = this.#usageTracker.get(key);
|
||||
if (lastUsed === undefined) return false;
|
||||
if (this.#pinnedFonts.has(key)) return false;
|
||||
if (lastUsed === undefined) {
|
||||
return false;
|
||||
}
|
||||
if (this.#pinnedFonts.has(key)) {
|
||||
return false;
|
||||
}
|
||||
return now - lastUsed >= this.#TTL;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { FontLoadRequestConfig } from '../../../types';
|
||||
import type { FontLoadRequestConfig } from '../../../../types';
|
||||
import { FontLoadQueue } from './FontLoadQueue';
|
||||
|
||||
const config = (id: string): FontLoadRequestConfig => ({
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { FontLoadRequestConfig } from '../../../types';
|
||||
import type { FontLoadRequestConfig } from '../../../../types';
|
||||
|
||||
/**
|
||||
* Manages the font load queue and per-font retry counts.
|
||||
@@ -17,7 +17,9 @@ export class FontLoadQueue {
|
||||
* @returns `true` if the key was newly enqueued, `false` if it was already present.
|
||||
*/
|
||||
enqueue(key: string, config: FontLoadRequestConfig): boolean {
|
||||
if (this.#queue.has(key)) return false;
|
||||
if (this.#queue.has(key)) {
|
||||
return false;
|
||||
}
|
||||
this.#queue.set(key, config);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user