diff --git a/src/core/cache.ts b/src/core/cache.ts index 0379711..81d81f1 100644 --- a/src/core/cache.ts +++ b/src/core/cache.ts @@ -24,6 +24,7 @@ export const overlayCache = new LRUCache(500); export const imageDecodeCache = new LRUCache(64); export const paletteDetectionCache = new LRUCache(200); export const baseMinifyCache = new LRUCache(100); +export const colorCaches = new LRUCache>(500); export const tooLargeOverlays = new Set(); export function clearOverlayCache() { @@ -31,5 +32,6 @@ export function clearOverlayCache() { imageDecodeCache.clear(); paletteDetectionCache.clear(); baseMinifyCache.clear(); + colorCaches.clear(); tooLargeOverlays.clear(); } \ No newline at end of file diff --git a/src/ui/ccModal.ts b/src/ui/ccModal.ts index bf7ba3b..1b23d63 100644 --- a/src/ui/ccModal.ts +++ b/src/ui/ccModal.ts @@ -1,7 +1,8 @@ /// import { WPLACE_FREE, WPLACE_PAID, WPLACE_NAMES, DEFAULT_FREE_KEYS } from '../core/palette'; import { createCanvas } from '../core/canvas'; -import { config, saveConfig } from '../core/store'; +import { colorCaches } from '../core/cache'; +import { config, saveConfig, type OverlayItem } from '../core/store'; import { MAX_OVERLAY_DIM } from '../core/constants'; import { ensureHook } from '../core/hook'; import { clearOverlayCache, paletteDetectionCache } from '../core/cache'; @@ -38,7 +39,7 @@ type CCState = { selectedPaid: Set; realtime: boolean; - overlay: any | null; + overlay: OverlayItem | null; lastColorCounts: Record; isStale: boolean; }; @@ -191,7 +192,7 @@ export function buildCCModal() { renderPaletteGrid(); } -export function openCCModal(overlay: any) { +export function openCCModal(overlay: OverlayItem) { if (!cc) return; cc.overlay = overlay; @@ -266,7 +267,12 @@ function processImage() { const palette = getActivePalette(); const counts: Record = {}; - const colorCache: Map = new Map(); + const id = cc.overlay.id; + let colorCache = colorCaches.get(id); + if (!colorCache) { + colorCache = new Map(); + colorCaches.set(id, colorCache); + } for (let i = 0; i < src.length; i += 4) { const r = src[i], g = src[i+1], b = src[i+2], a = src[i+3];