AI-native design editor. Open-source Figma alternative.
fix(fig): use Cover pages for thumbnails
Victor Wads6da2f2654b68
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fb7e0f81f..63d5fdd09 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -61,6 +61,7 @@### Fixed+- Generate and cache 512×512 recent-file previews from the conventional `Cover` page after opening a `.fig`, without modifying the source file.- Keep text-editing carets, hit testing, and selection highlights aligned with vertically centered or bottom-aligned text. (#539)- Match AI chat code-block syntax colors and backgrounds to the active light or dark theme. (#537)- Let desktop users select and copy AI chat text without replacing it with the selected canvas layers. (#538)diff --git a/packages/core/src/io/formats/fig/export.ts b/packages/core/src/io/formats/fig/export.tsindex ca5d0b6cd..66806aa18 100644--- a/packages/core/src/io/formats/fig/export.ts+++ b/packages/core/src/io/formats/fig/export.ts@@ -14,6 +14,7 @@ import { decodeBase64 } from '#core/bytes'import type { SkiaRenderer } from '#core/canvas'import { CANVAS_BG_COLOR, IS_BROWSER, IS_TAURI } from '#core/constants'import { applyEnabledLibrariesPluginData } from '#core/io/formats/fig/library-metadata'+import { findFigThumbnailPageId } from '#core/io/formats/fig/thumbnail-page'import { renderThumbnail } from '#core/io/formats/raster'import { populateAllLazyFigImportRoots } from '#core/kiwi/fig/lazy-import'import {@@ -80,8 +81,8 @@ function collectImageEntries(graph: SceneGraph): Array<{ name: string; data: Uinreturn entries}-const THUMBNAIL_WIDTH = 400-const THUMBNAIL_HEIGHT = 225+const THUMBNAIL_WIDTH = 512+const THUMBNAIL_HEIGHT = 512async function renderFigThumbnail(graph: SceneGraph,@@ -534,7 +535,7 @@ export async function exportFigFile(const kiwiData = compiled.encodeMessage(msg)- const currentPageId = pageId ?? pages[0]?.id+ const currentPageId = pageId ?? findFigThumbnailPageId(pages)const thumbnailPNG = await renderFigThumbnail(graph,currentPageId,diff --git a/packages/core/src/io/formats/fig/index.ts b/packages/core/src/io/formats/fig/index.tsindex 07bb38a73..1cc42e1ff 100644--- a/packages/core/src/io/formats/fig/index.ts+++ b/packages/core/src/io/formats/fig/index.ts@@ -1,2 +1,3 @@export { readFigFile, parseFigFile, type ParseFigFileOptions } from './read'export { exportFigFile, compressFigData, compressFigDataSync } from './write'+export { findFigThumbnailPageId } from './thumbnail-page'diff --git a/packages/core/src/io/formats/fig/thumbnail-page.ts b/packages/core/src/io/formats/fig/thumbnail-page.tsnew file mode 100644index 000000000..4dedd240d--- /dev/null+++ b/packages/core/src/io/formats/fig/thumbnail-page.ts@@ -0,0 +1,18 @@+type ThumbnailPage = {+ id: string+ name: string+}++const COVER_PAGE_NAME = 'cover'++/** Resolve the conventional Figma cover page without falling back to unrelated content. */+export function findFigThumbnailPageId(pages: readonly ThumbnailPage[]): string | undefined {+ const normalizedNames = pages.map((page) => ({+ page,+ name: page.name.trim().toLocaleLowerCase()+ }))+ return (+ normalizedNames.find(({ name }) => name === COVER_PAGE_NAME)?.page.id ??+ normalizedNames.find(({ name }) => name.includes(COVER_PAGE_NAME))?.page.id+ )+}diff --git a/packages/core/src/io/formats/raster/render.ts b/packages/core/src/io/formats/raster/render.tsindex 7e5a77521..a2bb298fb 100644--- a/packages/core/src/io/formats/raster/render.ts+++ b/packages/core/src/io/formats/raster/render.ts@@ -341,13 +341,13 @@ export function renderThumbnail(const contentH = bounds.maxY - bounds.minYif (contentW <= 0 || contentH <= 0) return null- const scale = Math.min(width / contentW, height / contentH, 2)+ const scale = Math.min(width / contentW, height / contentH)+ const pixelW = Math.max(1, Math.round(contentW * scale))+ const pixelH = Math.max(1, Math.round(contentH * scale))- return renderToSurface(ck, renderer, graph, pageId, width, height, 'PNG', 100, (canvas) => {+ return renderToSurface(ck, renderer, graph, pageId, pixelW, pixelH, 'PNG', 100, (canvas) => {canvas.clear(ck.Color4f(renderer.pageColor.r, renderer.pageColor.g, renderer.pageColor.b, 1))- const offsetX = (width - contentW * scale) / 2 - bounds.minX * scale- const offsetY = (height - contentH * scale) / 2 - bounds.minY * scale- canvas.translate(offsetX, offsetY)+ canvas.translate(-bounds.minX * scale, -bounds.minY * scale)canvas.scale(scale, scale)})}diff --git a/packages/docs/reference/file-format.md b/packages/docs/reference/file-format.mdindex 3c6ee72fa..264c45056 100644--- a/packages/docs/reference/file-format.md+++ b/packages/docs/reference/file-format.md@@ -35,7 +35,7 @@ SceneGraph → NodeChange[] → Kiwi encode → compress (Zstd/deflate)→ write .fig file```-Export uses <kbd>⌘</kbd><kbd>S</kbd> (Save) and <kbd>⇧</kbd><kbd>⌘</kbd><kbd>S</kbd> (Save As) with native OS dialogs on the desktop app. The exported file includes a `thumbnail.png` required by Figma for file preview.+Export uses <kbd>⌘</kbd><kbd>S</kbd> (Save) and <kbd>⇧</kbd><kbd>⌘</kbd><kbd>S</kbd> (Save As) with native OS dialogs on the desktop app. The exported file includes a `thumbnail.png` required by Figma for file preview. OpenPencil uses the first page named exactly `Cover` (case-insensitive), then the first page whose name contains `Cover`. The desktop app also caches this Cover after opening a file so Recent Files can prefer the generated preview without modifying the source `.fig`.Compression uses Zstd via Tauri Rust command on desktop, with deflate fallback in the browser.diff --git a/packages/fig/src/thumbnail.ts b/packages/fig/src/thumbnail.tsindex ac1e77562..bb764c5cd 100644--- a/packages/fig/src/thumbnail.ts+++ b/packages/fig/src/thumbnail.ts@@ -49,6 +49,12 @@ function hasPNGSignature(bytes: Uint8Array): boolean {return PNG_SIGNATURE.every((byte, index) => bytes[index] === byte)}+function hasUsablePNGDimensions(bytes: Uint8Array): boolean {+ if (bytes.byteLength < 24 || !hasPNGSignature(bytes)) return false+ const data = view(bytes)+ return data.getUint32(16) > 1 && data.getUint32(20) > 1+}+function findThumbnailEntry(central: Uint8Array,maxCompressed: number,@@ -97,7 +103,7 @@ async function readEntryPayload(if (dataStart + entry.compressedSize > reader.size) return nullconst compressed = await reader.read(dataStart, dataStart + entry.compressedSize)if (entry.method === 0) {- return compressed.byteLength === entry.outputSize && hasPNGSignature(compressed)+ return compressed.byteLength === entry.outputSize && hasUsablePNGDimensions(compressed)? compressed: null}@@ -109,7 +115,7 @@ async function readEntryPayload(return null}})()- return output?.byteLength === entry.outputSize && hasPNGSignature(output) ? output : null+ return output?.byteLength === entry.outputSize && hasUsablePNGDimensions(output) ? output : null}/**diff --git a/src/app/cache/index.ts b/src/app/cache/index.tsindex 66b50a7da..47a9884c0 100644--- a/src/app/cache/index.ts+++ b/src/app/cache/index.ts@@ -18,10 +18,25 @@ function cachePath(key: string) {return `${APP_CACHE_DIR}/${key.split('/').map(encodeURIComponent).join('/')}`}+function cacheDirectoryPath(key: string) {+ const segments = key.split('/').slice(0, -1)+ return segments.length > 0+ ? `${APP_CACHE_DIR}/${segments.map(encodeURIComponent).join('/')}`+ : APP_CACHE_DIR+}+function storageKey(key: string) {return `${STORAGE_PREFIX}${key}`}+function removeStorageEntriesWithPrefix(prefix: string): void {+ if (!isStorageAvailable()) return+ for (let i = window.localStorage.length - 1; i >= 0; i--) {+ const key = window.localStorage.key(i)+ if (key?.startsWith(storageKey(prefix))) window.localStorage.removeItem(key)+ }+}+export async function readCacheText(key: string): Promise<string | null> {if (isTauriRuntime()) {try {@@ -41,7 +56,7 @@ export async function readCacheText(key: string): Promise<string | null> {export async function writeCacheText(key: string, value: string): Promise<void> {if (isTauriRuntime()) {const { BaseDirectory, mkdir, writeFile } = await import('@tauri-apps/plugin-fs')- await mkdir(APP_CACHE_DIR, { baseDir: BaseDirectory.AppLocalData, recursive: true })+ await mkdir(cacheDirectoryPath(key), { baseDir: BaseDirectory.AppLocalData, recursive: true })await writeFile(cachePath(key), textEncoder.encode(value), {baseDir: BaseDirectory.AppLocalData})@@ -83,7 +98,7 @@ export async function writeCacheBytes(key: string, value: ArrayBuffer): Promise<if (!isTauriRuntime()) returnconst { BaseDirectory, mkdir, writeFile } = await import('@tauri-apps/plugin-fs')- await mkdir(APP_CACHE_DIR, { baseDir: BaseDirectory.AppLocalData, recursive: true })+ await mkdir(cacheDirectoryPath(key), { baseDir: BaseDirectory.AppLocalData, recursive: true })await writeFile(cachePath(key), new Uint8Array(value), { baseDir: BaseDirectory.AppLocalData })}@@ -98,11 +113,26 @@ export async function removeCachePrefix(prefix: string): Promise<void> {return}- if (!isStorageAvailable()) return- for (let i = window.localStorage.length - 1; i >= 0; i--) {- const key = window.localStorage.key(i)- if (key?.startsWith(storageKey(prefix))) window.localStorage.removeItem(key)+ removeStorageEntriesWithPrefix(prefix)+}++export async function removeCacheEntriesWithPrefix(prefix: string): Promise<void> {+ if (isTauriRuntime()) {+ try {+ const { BaseDirectory, readDir, remove } = await import('@tauri-apps/plugin-fs')+ const entries = await readDir(APP_CACHE_DIR, { baseDir: BaseDirectory.AppLocalData })+ await Promise.all(+ entries+ .filter((entry) => entry.isFile && entry.name.startsWith(prefix))+ .map((entry) => remove(cachePath(entry.name), { baseDir: BaseDirectory.AppLocalData }))+ )+ } catch (error) {+ console.warn(`Cache entry cleanup skipped for "${prefix}":`, error)+ }+ return}++ removeStorageEntriesWithPrefix(prefix)}type JSONCacheEnvelope<T> = {diff --git a/src/app/document/io/source.ts b/src/app/document/io/source.tsindex f271ba0b0..058f3e198 100644--- a/src/app/document/io/source.ts+++ b/src/app/document/io/source.ts@@ -48,7 +48,8 @@ export function createDocumentSourceActions({getRenderer}: DocumentSourceOptions) {function buildFigFile() {- return exportFigFile(editor.graph, undefined, getRenderer() ?? undefined, state.currentPageId)+ const renderer = getRenderer()+ return exportFigFile(editor.graph, renderer?.ck, renderer ?? undefined)}function buildRecoveryFigFile() {diff --git a/src/app/shell/menu/editor.ts b/src/app/shell/menu/editor.tsindex d9fef1e58..1197cb68c 100644--- a/src/app/shell/menu/editor.ts+++ b/src/app/shell/menu/editor.ts@@ -73,7 +73,7 @@ export function useEditorMenu() {useNativeMenuEvents((id) => {if (id === 'clear-recent-files') {- clearRecentFiles()+ void clearRecentFiles()return}if (id.startsWith(OPEN_RECENT_EVENT_PREFIX)) {diff --git a/src/app/shell/menu/recent-files.ts b/src/app/shell/menu/recent-files.tsindex 35427178a..66a1afcd7 100644--- a/src/app/shell/menu/recent-files.ts+++ b/src/app/shell/menu/recent-files.ts@@ -3,11 +3,19 @@ import { computed } from 'vue'import { extractFigThumbnailFromReader } from '@open-pencil/fig'+import {+ readCacheBytes,+ removeCacheEntriesWithPrefix,+ removeCachePrefix,+ writeCacheBytes+} from '@/app/cache'import { isTauri } from '@/app/tauri/env'const MAX_RECENT_FILES = 10const RECENT_FILES_STORAGE_KEY = 'open-pencil:recent-files'const RECENT_FILE_OPENED_AT_STORAGE_KEY = 'open-pencil:recent-file-opened-at'+const RECENT_FILE_THUMBNAIL_CACHE_DIR = 'recent-file-thumbnails/v2'+const LEGACY_RECENT_FILE_THUMBNAIL_CACHE_PREFIX = 'recent-file-thumbnail-v2-'export type RecentFile = {id: string@@ -70,17 +78,51 @@ export function forgetRecentFile(path: string): void {updateRecentFiles(normalizedRecentFiles().filter((recent) => recent !== path))}-export function clearRecentFiles(): void {+export async function clearRecentFiles(): Promise<void> {recentFileOpenedAt.value = {}updateRecentFiles([])+ await Promise.all([+ removeCachePrefix(RECENT_FILE_THUMBNAIL_CACHE_DIR),+ removeCacheEntriesWithPrefix(LEGACY_RECENT_FILE_THUMBNAIL_CACHE_PREFIX)+ ])}export function recentFileAt(index: number): string | null {return normalizedRecentFiles()[index] ?? null}+async function recentFileThumbnailCacheKey(path: string): Promise<string> {+ let fingerprint = path+ try {+ const { stat } = await import('@tauri-apps/plugin-fs')+ const info = await stat(path)+ fingerprint = `${path}\0${info.size}\0${info.mtime?.getTime() ?? 0}`+ } catch (error) {+ // A path-only key still permits a preview when metadata is unavailable.+ console.warn('[Recent files] Could not stat the file for thumbnail caching', error)+ }+ const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(fingerprint))+ const hash = [...new Uint8Array(digest)]+ .map((byte) => byte.toString(16).padStart(2, '0'))+ .join('')+ return `${RECENT_FILE_THUMBNAIL_CACHE_DIR}/${hash}.png`+}++export async function loadCachedRecentFileThumbnail(path: string): Promise<Uint8Array | null> {+ if (!isTauri()) return null+ const bytes = await readCacheBytes(await recentFileThumbnailCacheKey(path))+ return bytes ? new Uint8Array(bytes) : null+}++export async function cacheRecentFileThumbnail(path: string, bytes: Uint8Array): Promise<void> {+ if (!isTauri()) return+ await writeCacheBytes(await recentFileThumbnailCacheKey(path), Uint8Array.from(bytes).buffer)+}+export async function loadRecentFileThumbnail(path: string): Promise<Uint8Array | null> {if (!isTauri() || !path.toLowerCase().endsWith('.fig')) return null+ const cached = await loadCachedRecentFileThumbnail(path)+ if (cached) return cachedconst { readFile } = await import('@tauri-apps/plugin-fs')const bytes = await readFile(path)return extractFigThumbnailFromReader({diff --git a/src/app/tabs/index.ts b/src/app/tabs/index.tsindex 2122aea04..15b9e7e33 100644--- a/src/app/tabs/index.ts+++ b/src/app/tabs/index.ts@@ -1,6 +1,10 @@+import { promiseTimeout } from '@vueuse/core'import { shallowRef, computed, triggerRef } from 'vue'import { BUILTIN_IO_FORMATS, IORegistry } from '@open-pencil/core/io'+import { findFigThumbnailPageId } from '@open-pencil/core/io/formats/fig'+import { renderThumbnail } from '@open-pencil/core/io/formats/raster'+import { populateLazyFigImportRoots } from '@open-pencil/core/kiwi'import { computeAllLayouts } from '@open-pencil/core/layout'import type { SceneGraph } from '@open-pencil/scene-graph'@@ -16,6 +20,10 @@ import {createActiveStorageAdapter,type StorageDocument} from '@/app/integrations/storage'+import {+ cacheRecentFileThumbnail,+ loadCachedRecentFileThumbnail+} from '@/app/shell/menu/recent-files'import { getLocalCanvasStore } from '@/app/storage/local-store'import { seedStorageCanvasFromRemote } from '@/app/storage/sync/persist'import { createFileOpenCoordinator } from '@/app/tabs/open/coordinator'@@ -29,6 +37,8 @@ export interface Tab {const io = new IORegistry(BUILTIN_IO_FORMATS)const fileOpenCoordinator = createFileOpenCoordinator()+const RECENT_FILE_THUMBNAIL_SIZE = 512+const coverThumbnailListeners = new WeakMap<EditorStore, () => void>()let nextTabId = 1@@ -88,6 +98,15 @@ export function leaveHome(tabId: string): void {tabsRef.value = tabsRef.value.with(tabIndex, { ...tab, showHome: false })}+export function showRecentFiles(): void {+ const homeTab = tabsRef.value.find((tab) => tab.showHome)+ if (homeTab) {+ switchTab(homeTab.id)+ return+ }+ createTab(undefined, undefined, true)+}+function activateTab(tab: Tab) {activeTabId.value = tab.idsetActiveEditorStore(tab.store)@@ -106,7 +125,10 @@ export async function closeTab(tabId: string): Promise<void> {if (idx === -1) returnconst closingTab = tabsRef.value[idx]+ if (closingTab.showHome) returnconst wasActive = activeTabId.value === tabId+ coverThumbnailListeners.get(closingTab.store)?.()+ coverThumbnailListeners.delete(closingTab.store)await closingTab.store.persistRecoveryNow()closingTab.store.dispose()tabsRef.value = tabsRef.value.filter((t) => t.id !== tabId)@@ -134,6 +156,7 @@ function isDOMImportFile(file: File): boolean {function reusableTabStore(): EditorStore {const current = activeTab.value+ if (current?.showHome) return createTab().storeconst isUntouched =current?.store.state.documentName === 'Untitled' && !current.store.undo.canUndoif (isUntouched) {@@ -147,9 +170,56 @@ async function readFigForTab(file: File, store: EditorStore): Promise<SceneGraphconst imported = await readFigFileProgressively(file, store)const firstPageId = imported.getPages()[0]?.idif (firstPageId) computeAllLayouts(imported, firstPageId)+ const coverPageId = findFigThumbnailPageId(imported.getPages())+ if (coverPageId && coverPageId !== firstPageId) {+ populateLazyFigImportRoots(imported, [coverPageId])+ computeAllLayouts(imported, coverPageId)+ }return imported}+async function cacheOpenedFigCover(path: string, store: EditorStore): Promise<void> {+ if (await loadCachedRecentFileThumbnail(path)) return+ const coverPageId = findFigThumbnailPageId(store.graph.getPages())+ if (!coverPageId) return+ for (let attempt = 0; attempt < 240 && !store.renderer; attempt++) {+ await promiseTimeout(250)+ }+ const renderer = store.renderer+ if (!renderer) {+ console.warn('[Recent files] Cover thumbnail skipped because the renderer was unavailable')+ return+ }+ const bytes = renderThumbnail(+ renderer.ck,+ renderer,+ store.graph,+ coverPageId,+ RECENT_FILE_THUMBNAIL_SIZE,+ RECENT_FILE_THUMBNAIL_SIZE+ )+ if (!bytes) {+ console.warn('[Recent files] Cover thumbnail skipped because the Cover page was empty')+ return+ }+ await cacheRecentFileThumbnail(path, bytes)+}++function watchOpenedFigCover(path: string, store: EditorStore): void {+ coverThumbnailListeners.get(store)?.()+ const coverPageId = findFigThumbnailPageId(store.graph.getPages())+ if (!coverPageId) return+ coverThumbnailListeners.set(+ store,+ store.onEditorEvent('page:changed', (pageId) => {+ if (pageId !== coverPageId) return+ void cacheOpenedFigCover(path, store).catch((error) => {+ console.warn('[Recent files] Failed to cache the Cover thumbnail', error)+ })+ })+ )+}+function findStorageTab(providerId: string, documentId: string): Tab | undefined {return tabsRef.value.find((tab) => {const binding = tab.store.getStorageBinding()@@ -227,6 +297,12 @@ export async function openFileInNewTab(const existing = await findTabByFileIdentity(tabsRef.value, identity)if (existing) {switchTab(existing.id)+ if (path?.toLowerCase().endsWith('.fig')) {+ watchOpenedFigCover(path, existing.store)+ void cacheOpenedFigCover(path, existing.store).catch((error) => {+ console.warn('[Recent files] Failed to cache the Cover thumbnail', error)+ })+ }return { kind: 'existing' as const }}@@ -273,10 +349,16 @@ export async function openFileInNewTab(store.replaceGraph(imported)store.undo.clear()store.setDocumentSource(file.name, sourceFormat, handle, path)+ if (isFig && path) watchOpenedFigCover(path, store)store.clearSelection()const pageId = store.graph.getPages()[0]?.id ?? store.graph.rootIdawait store.switchPage(pageId)await store.fitCurrentPageToViewport()+ if (isFig && path) {+ void cacheOpenedFigCover(path, store).catch((error) => {+ console.warn('[Recent files] Failed to cache the Cover thumbnail', error)+ })+ }completion.resolve(undefined)} catch (error) {completion.reject(error)diff --git a/src/components/TabBar.vue b/src/components/TabBar.vueindex bea5b7a64..469cae256 100644--- a/src/components/TabBar.vue+++ b/src/components/TabBar.vue@@ -5,7 +5,7 @@ import { tv } from 'tailwind-variants'import Tip from '@/components/ui/Tip.vue'import tabBarTheme from '@/theme/tab-bar'-import { useTabsStore, createTab } from '@/app/tabs'+import { useTabsStore, showRecentFiles } from '@/app/tabs'import { useI18n } from '@open-pencil/vue'const { dialogs } = useI18n()@@ -19,12 +19,8 @@ const modelValue = computed({set: (id: string) => switchTab(id)})-function openRecentFilesTab() {- createTab(undefined, undefined, true)-}--function onMiddleClick(e: MouseEvent, tabId: string) {- if (e.button === 1) {+function onMiddleClick(e: MouseEvent, tabId: string, isHome: boolean) {+ if (e.button === 1 && !isHome) {e.preventDefault()void closeTab(tabId)}@@ -51,17 +47,17 @@ function onClose(e: MouseEvent, tabId: string) {data-test-id="tabbar-tab":class="tabBarStyles({ active: tab.isActive }).trigger()":data-active="tab.isActive || undefined"- @mousedown="onMiddleClick($event, tab.id)"+ @mousedown="onMiddleClick($event, tab.id, tab.isHome)"><icon-lucide-house v-if="tab.isHome" :class="baseStyles.icon()" /><icon-lucide-file v-else :class="baseStyles.icon()" /><span :class="baseStyles.label()">{{ tab.isHome ? dialogs.recentFiles : tab.name }}</span>- <Tip :label="dialogs.closeTab({ name: tab.isHome ? dialogs.recentFiles : tab.name })">+ <Tip v-if="!tab.isHome" :label="dialogs.closeTab({ name: tab.name })"><buttondata-test-id="tabbar-close":class="tabBarStyles({ active: tab.isActive }).close()":data-active="tab.isActive || undefined"- :aria-label="dialogs.closeTab({ name: tab.isHome ? dialogs.recentFiles : tab.name })"+ :aria-label="dialogs.closeTab({ name: tab.name })"tabindex="-1"@click="onClose($event, tab.id)">@@ -75,7 +71,7 @@ function onClose(e: MouseEvent, tabId: string) {data-test-id="tabbar-new":class="baseStyles.newAction()":aria-label="dialogs.newTab"- @click="openRecentFilesTab"+ @click="showRecentFiles"><icon-lucide-plus :class="baseStyles.newIcon()" /></button>diff --git a/src/components/recent-files/RecentFilesHome.vue b/src/components/recent-files/RecentFilesHome.vueindex e27e9e52b..1d3126946 100644--- a/src/components/recent-files/RecentFilesHome.vue+++ b/src/components/recent-files/RecentFilesHome.vue@@ -5,6 +5,7 @@ import { useLocalStorage } from '@vueuse/core'import { useDocumentWorkspace, useI18n } from '@open-pencil/vue'import {+ clearRecentFiles,forgetRecentFile,loadRecentFileThumbnail,recentFiles,@@ -89,6 +90,15 @@ function formattedDate(updatedAt: string): string {<p class="mt-1 text-xs text-muted">{{ dialogs.recentFilesDescription }}</p></div><div v-if="hasRecentFiles" class="ml-auto flex rounded border border-border p-0.5">+ <button+ type="button"+ class="flex size-7 items-center justify-center rounded-sm text-muted hover:text-surface"+ :aria-label="dialogs.clear"+ data-test-id="recent-files-clear"+ @click="clearRecentFiles"+ >+ <icon-lucide-trash-2 class="size-3.5" />+ </button><buttontype="button"class="flex size-7 items-center justify-center rounded-sm text-muted hover:text-surface"@@ -125,7 +135,7 @@ function formattedDate(updatedAt: string): string {><divv-workspace-preview="document.path"- class="flex aspect-[4/3] items-center justify-center overflow-hidden bg-panel-field"+ class="flex aspect-video items-center justify-center overflow-hidden bg-panel-field"><imgv-if="previewURL(document.path)"diff --git a/src/views/EditorView.vue b/src/views/EditorView.vueindex 52a4252b3..2db3413a8 100644--- a/src/views/EditorView.vue+++ b/src/views/EditorView.vue@@ -18,7 +18,7 @@ import { isTauri } from '@/app/tauri/env'import { appMenuShortcut } from '@/app/shell/menu/shortcut'import { createDemoShapes } from '@/app/demo/document'import { useEditorStore } from '@/app/editor/active-store'-import { createTab, activeTab, getActiveStore, leaveHome, tabCount } from '@/app/tabs'+import { createTab, activeTab, getActiveStore, tabCount } from '@/app/tabs'import CollabPanel from '@/components/CollabPanel/CollabPanel.vue'import EditorCanvas from '@/components/EditorCanvas.vue'@@ -126,8 +126,8 @@ onUnmounted(() => {<SafariBanner /><FontStatusBanner /><RenameSelectionDialog />- <RecentFilesHome v-if="showingHome" @new-document="activeTab && leaveHome(activeTab.id)" /><TabBar />+ <RecentFilesHome v-if="showingHome" @new-document="createTab" /><!-- Desktop layout --><SplitterGroupdiff --git a/tests/e2e/app/recent-files.spec.ts b/tests/e2e/app/recent-files.spec.tsindex beddbf029..6d43f1d82 100644--- a/tests/e2e/app/recent-files.spec.ts+++ b/tests/e2e/app/recent-files.spec.ts@@ -5,21 +5,24 @@ test('opens to the recent-files home and starts a new document', async ({ page }await expect(page.getByTestId('recent-files-home')).toBeVisible()await expect(page.getByText('No recent files yet')).toBeVisible()+ await expect(page.getByTestId('tabbar-tab')).toHaveCount(1)await page.getByTestId('home-new-document').click()await expect(page.getByTestId('recent-files-home')).toBeHidden()const tab = page.getByTestId('tabbar-tab')- await expect(tab).toBeVisible()+ await expect(tab).toHaveCount(2)await page.getByTestId('tabbar-new').click()await expect(page.getByTestId('recent-files-home')).toBeVisible()await expect(page.getByTestId('tabbar-tab')).toHaveCount(2)- await expect(page.getByTestId('tabbar-tab').last()).toContainText('Recent files')+ await expect(page.getByTestId('tabbar-tab').first()).toContainText('Recent files')+ await expect(page.getByTestId('tabbar-close')).toHaveCount(1)+ await page.getByTestId('tabbar-tab').last().click()await page.getByTestId('tabbar-tab').last().hover()await page.getByTestId('tabbar-tab').last().getByTestId('tabbar-close').click()- await expect(page.getByTestId('recent-files-home')).toBeHidden()+ await expect(page.getByTestId('recent-files-home')).toBeVisible()})diff --git a/tests/engine/app/cache.test.ts b/tests/engine/app/cache.test.tsindex 53c49c853..92e54fffd 100644--- a/tests/engine/app/cache.test.ts+++ b/tests/engine/app/cache.test.ts@@ -56,4 +56,20 @@ describe('app cache', () => {await expect(readCacheText('openrouter/other')).resolves.toBeNull()await expect(readCacheText('fonts/manifest')).resolves.toBe('fonts')})++ test('removes web cache entries sharing a file-name prefix', async () => {+ installLocalStorage()+ const { readCacheText, removeCacheEntriesWithPrefix, writeCacheText } =+ await import('@/app/cache')++ await writeCacheText('recent-file-thumbnail-v2-one.png', 'one')+ await writeCacheText('recent-file-thumbnail-v2-two.png', 'two')+ await writeCacheText('font-cache/v1/manifest', 'fonts')++ await removeCacheEntriesWithPrefix('recent-file-thumbnail-v2-')++ await expect(readCacheText('recent-file-thumbnail-v2-one.png')).resolves.toBeNull()+ await expect(readCacheText('recent-file-thumbnail-v2-two.png')).resolves.toBeNull()+ await expect(readCacheText('font-cache/v1/manifest')).resolves.toBe('fonts')+ })})diff --git a/tests/engine/app/tabs/open-file-dedup.test.ts b/tests/engine/app/tabs/open-file-dedup.test.tsindex c39bae377..ed26c93db 100644--- a/tests/engine/app/tabs/open-file-dedup.test.ts+++ b/tests/engine/app/tabs/open-file-dedup.test.ts@@ -6,7 +6,14 @@ import { SceneGraph } from '@open-pencil/scene-graph'import { resolveBrowserFileURL } from '@/app/document/io/browser'import type { DocumentSourceIdentity } from '@/app/document/io/types'-import { createTab, getActiveStore, openFileInNewTab, tabCount } from '@/app/tabs'+import {+ createTab,+ getActiveStore,+ getTabsSnapshot,+ openFileInNewTab,+ showRecentFiles,+ tabCount+} from '@/app/tabs'import { fileIdentitiesMatch, findTabByFileIdentity } from '@/app/tabs/open/identity'function setupGlobals() {@@ -115,6 +122,17 @@ describe('openFileInNewTab deduplication', () => {expect(resolveBrowserFileURL('/design.fig#selection').href).toBe('http://localhost/design.fig')})+ test('keeps one permanent Recent Files tab', () => {+ const initialCount = tabCount()+ const initialHomeCount = getTabsSnapshot().filter((tab) => tab.showHome).length++ showRecentFiles()+ showRecentFiles()++ expect(tabCount()).toBe(initialCount + (initialHomeCount === 0 ? 1 : 0))+ expect(getTabsSnapshot().filter((tab) => tab.showHome)).toHaveLength(1)+ })+test('activates the existing tab when the same path is opened again', async () => {const initialCount = tabCount()const file = new File([], 'design.fig')diff --git a/tests/engine/io/fig/thumbnail-page.test.ts b/tests/engine/io/fig/thumbnail-page.test.tsnew file mode 100644index 000000000..00d330f6d--- /dev/null+++ b/tests/engine/io/fig/thumbnail-page.test.ts@@ -0,0 +1,29 @@+import { describe, expect, test } from 'bun:test'++import { findFigThumbnailPageId } from '#core/io/formats/fig/thumbnail-page'++describe('FIG thumbnail page selection', () => {+ test('prefers an exact Cover page case-insensitively', () => {+ expect(+ findFigThumbnailPageId([+ { id: 'first', name: 'Cover archive' },+ { id: 'exact', name: ' COVER ' },+ { id: 'last', name: 'Cover v2' }+ ])+ ).toBe('exact')+ })++ test('uses the first page containing Cover when no exact match exists', () => {+ expect(+ findFigThumbnailPageId([+ { id: 'unrelated', name: 'Homepage' },+ { id: 'first-cover', name: '✨ Project cover' },+ { id: 'second-cover', name: 'Cover archive' }+ ])+ ).toBe('first-cover')+ })++ test('does not fall back to an unrelated page', () => {+ expect(findFigThumbnailPageId([{ id: 'first', name: 'Homepage' }])).toBeUndefined()+ })+})diff --git a/tests/engine/io/fig/thumbnail-range.test.ts b/tests/engine/io/fig/thumbnail-range.test.tsindex ff527920c..4ce9121f6 100644--- a/tests/engine/io/fig/thumbnail-range.test.ts+++ b/tests/engine/io/fig/thumbnail-range.test.ts@@ -41,6 +41,17 @@ describe('fig ranged thumbnail extraction', () => {expect(await extractFigThumbnailFromReader(memoryReader(bytes, []))).toBeNull()})+ test('rejects the 1x1 no-cover placeholder', async () => {+ const png = new Uint8Array(24)+ png.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a])+ const dimensions = new DataView(png.buffer)+ dimensions.setUint32(16, 1)+ dimensions.setUint32(20, 1)++ const bytes = zipSync({ 'thumbnail.png': png }, { level: 0 })+ expect(await extractFigThumbnailFromReader(memoryReader(bytes, []))).toBeNull()+ })+test('returns null when deflated thumbnail data is corrupt', async () => {const png = new Uint8Array([0x89,