chore: ARTEX 初始化

ARTEX — AI 自主渗透测试系统(Go 后端 + Next.js 前端,单二进制内嵌)。

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
Autumn-27andClaude Opus 4.8 committed 2026-07-26 04:27:45 -04:00
commit 0ef8561411
287 files changed
+70178

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
export function applyContentLayout(value: "centered" | "full-width") {
const root = document.documentElement;
root.setAttribute("data-content-layout", value);
}
export function applyNavbarStyle(value: "sticky" | "scroll") {
const root = document.documentElement;
root.setAttribute("data-navbar-style", value);
}
export function applySidebarVariant(value: string) {
const root = document.documentElement;
root.setAttribute("data-sidebar-variant", value);
}
export function applySidebarCollapsible(value: string) {
const root = document.documentElement;
root.setAttribute("data-sidebar-collapsible", value);
}
export function applyFont(value: string) {
const root = document.documentElement;
root.setAttribute("data-font", value);
}
+32
View File
@@ -0,0 +1,32 @@
// Sidebar Variant
export const SIDEBAR_VARIANT_OPTIONS = [
{ label: "Sidebar", value: "sidebar" },
{ label: "Inset", value: "inset" },
{ label: "Floating", value: "floating" },
] as const;
export const SIDEBAR_VARIANT_VALUES = SIDEBAR_VARIANT_OPTIONS.map((v) => v.value);
export type SidebarVariant = (typeof SIDEBAR_VARIANT_VALUES)[number];
// Sidebar Collapsible
export const SIDEBAR_COLLAPSIBLE_OPTIONS = [
{ label: "Icon", value: "icon" },
{ label: "Offcanvas", value: "offcanvas" },
] as const;
export const SIDEBAR_COLLAPSIBLE_VALUES = SIDEBAR_COLLAPSIBLE_OPTIONS.map((v) => v.value);
export type SidebarCollapsible = (typeof SIDEBAR_COLLAPSIBLE_VALUES)[number];
// Content Layout
export const CONTENT_LAYOUT_OPTIONS = [
{ label: "Centered", value: "centered" },
{ label: "Full Width", value: "full-width" },
] as const;
export const CONTENT_LAYOUT_VALUES = CONTENT_LAYOUT_OPTIONS.map((v) => v.value);
export type ContentLayout = (typeof CONTENT_LAYOUT_VALUES)[number];
// Navbar Style
export const NAVBAR_STYLE_OPTIONS = [
{ label: "Sticky", value: "sticky" },
{ label: "Scroll", value: "scroll" },
] as const;
export const NAVBAR_STYLE_VALUES = NAVBAR_STYLE_OPTIONS.map((v) => v.value);
export type NavbarStyle = (typeof NAVBAR_STYLE_VALUES)[number];
@@ -0,0 +1,90 @@
/**
* How each preference should be saved.
*
* "client-cookie" → write cookie on the browser only.
* "server-cookie" → write cookie through a Server Action.
* "localStorage" → save only on the client (non-layout stuff).
* "none" → no saving, resets on reload.
*
* Layout-critical prefs (sidebar_variant / sidebar_collapsible)
* must stay consistent during SSR → so they can’t use localStorage.
* Others are flexible and can use any persistence.
*/
import type { FontKey } from "@/lib/fonts/registry";
import type { ContentLayout, NavbarStyle, SidebarCollapsible, SidebarVariant } from "./layout";
import type { ThemeMode, ThemePreset } from "./theme";
export type PreferencePersistence = "none" | "client-cookie" | "server-cookie" | "localStorage";
/**
* All available preference keys and their value types.
*/
export type PreferenceValueMap = {
theme_mode: ThemeMode;
theme_preset: ThemePreset;
font: FontKey;
content_layout: ContentLayout;
navbar_style: NavbarStyle;
sidebar_variant: SidebarVariant;
sidebar_collapsible: SidebarCollapsible;
};
export type PreferenceKey = keyof PreferenceValueMap;
/**
* Layout-critical keys → these affect SSR UI (sidebar shape)
* so they must be accessible on the server.
*/
export const LAYOUT_CRITICAL_KEYS = ["sidebar_variant", "sidebar_collapsible"] as const;
export type LayoutCriticalKey = (typeof LAYOUT_CRITICAL_KEYS)[number];
/**
* Everything else is non-critical and can be read from the client.
*/
export type NonCriticalKey = Exclude<PreferenceKey, LayoutCriticalKey>;
/**
* Layout-critical cannot use "localStorage" because SSR needs the value.
* So remove it from allowed persistence types for those keys.
*/
type LayoutCriticalPersistence = Exclude<PreferencePersistence, "localStorage">;
/**
* Final config:
* - layout-critical keys → restricted persistence
* - non-critical keys → can use any persistence
*/
type PreferencePersistenceConfig = {
[K in LayoutCriticalKey]: LayoutCriticalPersistence;
} & {
[K in NonCriticalKey]: PreferencePersistence;
};
/**
* Default preference values on first load.
*/
export const PREFERENCE_DEFAULTS: PreferenceValueMap = {
theme_mode: "light",
theme_preset: "default",
font: "geist",
content_layout: "centered",
navbar_style: "sticky",
sidebar_variant: "inset",
sidebar_collapsible: "icon",
};
/**
* How each preference is persisted.
* You can change these per-key.
*/
export const PREFERENCE_PERSISTENCE: PreferencePersistenceConfig = {
theme_mode: "client-cookie",
theme_preset: "client-cookie",
font: "client-cookie",
content_layout: "client-cookie",
navbar_style: "client-cookie",
sidebar_variant: "client-cookie", // layout-critical → cannot be "localStorage"
sidebar_collapsible: "client-cookie", // layout-critical → cannot be "localStorage"
};
@@ -0,0 +1,27 @@
"use client";
import { setClientCookie } from "../cookie.client";
import { setLocalStorageValue } from "../local-storage.client";
import { PREFERENCE_PERSISTENCE, type PreferenceKey } from "./preferences-config";
export async function persistPreference(key: PreferenceKey, value: string) {
const mode = PREFERENCE_PERSISTENCE[key];
switch (mode) {
case "none":
return;
// 静态导出无 Node 服务端,server-cookie 退化为浏览器 cookie(写入语义等价)。
case "server-cookie":
case "client-cookie":
setClientCookie(key, value);
return;
case "localStorage":
setLocalStorageValue(key, value);
return;
default:
return;
}
}
+42
View File
@@ -0,0 +1,42 @@
import type { ResolvedThemeMode, ThemeMode } from "./theme";
export function resolveThemeMode(mode: ThemeMode): ResolvedThemeMode {
if (mode === "system") {
const prefersDark = window.matchMedia?.("(prefers-color-scheme: dark)")?.matches;
return prefersDark ? "dark" : "light";
}
return mode === "dark" ? "dark" : "light";
}
export function applyThemeMode(mode: ThemeMode): ResolvedThemeMode {
const resolved = resolveThemeMode(mode);
const doc = document.documentElement;
doc.setAttribute("data-theme-mode", mode);
doc.classList.add("disable-transitions");
doc.classList.toggle("dark", resolved === "dark");
doc.style.colorScheme = resolved;
requestAnimationFrame(() => {
doc.classList.remove("disable-transitions");
});
return resolved;
}
export function applyThemePreset(value: string) {
document.documentElement.setAttribute("data-theme-preset", value);
}
export function subscribeToSystemTheme(onChange: (mode: ResolvedThemeMode) => void): () => void {
if (typeof window === "undefined") return () => undefined;
const media = window.matchMedia?.("(prefers-color-scheme: dark)");
if (!media) return () => undefined;
const listener = (event: MediaQueryListEvent) => {
onChange(event.matches ? "dark" : "light");
};
media.addEventListener("change", listener);
return () => {
media.removeEventListener("change", listener);
};
}
+52
View File
@@ -0,0 +1,52 @@
export const THEME_MODE_OPTIONS = [
{ label: "Light", value: "light" },
{ label: "Dark", value: "dark" },
{ label: "System", value: "system" },
] as const;
export const THEME_MODE_VALUES = THEME_MODE_OPTIONS.map((o) => o.value);
export type ThemeMode = (typeof THEME_MODE_VALUES)[number];
export type ResolvedThemeMode = "light" | "dark";
// --- generated:themePresets:start ---
export const THEME_PRESET_OPTIONS = [
{
label: "Default",
value: "default",
primary: {
light: "oklch(0.205 0 0)",
dark: "oklch(0.922 0 0)",
},
},
{
label: "Brutalist",
value: "brutalist",
primary: {
light: "oklch(0.6489 0.237 26.9728)",
dark: "oklch(0.7044 0.1872 23.1858)",
},
},
{
label: "Soft Pop",
value: "soft-pop",
primary: {
light: "oklch(0.5106 0.2301 276.9656)",
dark: "oklch(0.6801 0.1583 276.9349)",
},
},
{
label: "Tangerine",
value: "tangerine",
primary: {
light: "oklch(0.64 0.17 36.44)",
dark: "oklch(0.64 0.17 36.44)",
},
},
] as const;
export const THEME_PRESET_VALUES = THEME_PRESET_OPTIONS.map((p) => p.value);
export type ThemePreset = (typeof THEME_PRESET_OPTIONS)[number]["value"];
// --- generated:themePresets:end ---