Migrate project to pnpm monorepo

Restructure the repository into a pnpm workspace under packages/ (core, webui, runtime). Move source files for core and webui into packages/*, add package manifests for @snowluma/core and @snowluma/runtime, and remove the old launcher package.json. Update root package.json to be a monorepo controller (scripts delegate to pnpm filters, set packageManager and Node engine). Configure build outputs to emit into the repo-root dist/ (vite config changes) so the existing release pipeline continues to work. Add .npmrc with mirrors, expand .gitignore for monorepo layout, add tsconfig base and package-level tsconfigs, and add vitest config for the core package. Adjust injector native search paths and update tests import paths to the new package layout. Small CI/workflow comment added to clarify build behavior and README updated with monorepo structure and common commands.
This commit is contained in:
手瓜一十雪 committed 2026-05-03 14:02:29 +08:00
1 parent 6bba36bba6
commit 39f1672b29
122 files changed
+279 -85

No files matched your search

@@ -0,0 +1,58 @@
import { createContext, useContext, useEffect, useState, type ReactNode } from 'react';
export type ThemeMode = 'light' | 'dark' | 'system';
interface ThemeContextValue {
mode: ThemeMode;
resolved: 'light' | 'dark';
setMode: (mode: ThemeMode) => void;
}
const ThemeContext = createContext<ThemeContextValue | null>(null);
function getSystemTheme(): 'light' | 'dark' {
return window.matchMedia?.('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
export function ThemeProvider({ children }: { children: ReactNode }) {
const [mode, setModeState] = useState<ThemeMode>(() => {
const saved = localStorage.getItem('snowluma_theme') as ThemeMode | null;
if (saved === 'light' || saved === 'dark' || saved === 'system') return saved;
return 'system';
});
const [systemTheme, setSystemTheme] = useState<'light' | 'dark'>(getSystemTheme);
useEffect(() => {
const mq = window.matchMedia('(prefers-color-scheme: dark)');
const handler = (e: MediaQueryListEvent) => setSystemTheme(e.matches ? 'dark' : 'light');
mq.addEventListener('change', handler);
return () => mq.removeEventListener('change', handler);
}, []);
const resolved: 'light' | 'dark' = mode === 'system' ? systemTheme : mode;
useEffect(() => {
const root = document.documentElement;
root.className = resolved;
root.setAttribute('data-theme', resolved);
root.style.colorScheme = resolved;
}, [resolved]);
const setMode = (m: ThemeMode) => {
setModeState(m);
localStorage.setItem('snowluma_theme', m);
};
return (
<ThemeContext value={{ mode, resolved, setMode }}>
{children}
</ThemeContext>
);
}
export function useTheme() {
const ctx = useContext(ThemeContext);
if (!ctx) throw new Error('useTheme must be used within ThemeProvider');
return ctx;
}