refactor: single source for writing styles + action labels; add theme module

- src/lib/actions.ts: canonical ACTIONS/ACTION_LABELS/WRITING_STYLES;
  context-menu styles derived (WRITING_STYLES minus Default). Replaces
  the three duplicated style arrays in popup, content, and background.
- src/lib/theme.ts: canonical palette. Existing hex literals in the
  entrypoints are swapped wholesale when light/dark theming lands, so
  the color plumbing is only rewritten once.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
john kevin asprec
2026-07-14 21:35:54 +08:00
parent 324cfcc486
commit 47d9152bda
5 changed files with 62 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
import { defineBackground } from 'wxt/utils/define-background';
import nacl from 'tweetnacl';
import type { AnalyzePayload, LexAIConfig, LexAIResponse } from '@lib/types';
import { ACTIONS, ACTION_LABELS, CONTEXT_MENU_STYLES } from '@lib/actions';
// ─── Fetch with timeout ───────────────────────────────────────────────────────
@@ -431,25 +432,15 @@ export default defineBackground(() => {
console.log('LexAI background service worker started');
// ─── Context menus ───────────────────────────────────────────────────────
const CONTEXT_ACTIONS = ['fix', 'rephrase', 'shorten', 'expand', 'explain'] as const;
const CONTEXT_ACTION_LABELS: Record<string, string> = {
fix: 'Fix Grammar',
rephrase: 'Rephrase',
shorten: 'Shorten',
expand: 'Expand',
explain: 'Explain',
};
const CONTEXT_STYLES = ['Formal', 'Casual', 'Academic', 'Creative', 'Concise'];
chrome.runtime.onInstalled.addListener(() => {
chrome.contextMenus.removeAll(() => {
CONTEXT_ACTIONS.forEach(action => {
ACTIONS.forEach(action => {
chrome.contextMenus.create({
id: `lexai-${action}`,
title: `⚡ LexAI: ${CONTEXT_ACTION_LABELS[action]}`,
title: `⚡ LexAI: ${ACTION_LABELS[action]}`,
contexts: ['selection'],
});
CONTEXT_STYLES.forEach(style => {
CONTEXT_MENU_STYLES.forEach(style => {
chrome.contextMenus.create({
id: `lexai-${action}-${style.toLowerCase()}`,
parentId: `lexai-${action}`,