Skip to content

CanvasAnvil is an open source AI diagram maker and flowchart generator - an infinite-canvas diagram editor and self-hosted drawio alternative that writes editable .drawio files. Text to diagram, then fix nodes, layout and labels in place. Also AI presentations, interior design CAD/BOM, posters and infographics.

build: turn on TypeScript strict mode, split the bundle, drop the BOMs

codingFeng101816ef9188e51
diff --git a/api/routes/chat.ts b/api/routes/chat.ts
index 0cefd6e..cd95ac6 100644
--- a/api/routes/chat.ts
+++ b/api/routes/chat.ts
@@ -1,2 +1,2 @@
-export { POST } from "../../src/server/routes/chat"
+export { POST } from "../../src/server/routes/chat"
diff --git a/api/routes/config.ts b/api/routes/config.ts
index 07d59a3..7da4a86 100644
--- a/api/routes/config.ts
+++ b/api/routes/config.ts
@@ -1,2 +1,2 @@
-export { GET } from "../../src/server/routes/config"
+export { GET } from "../../src/server/routes/config"
diff --git a/api/routes/log-feedback.ts b/api/routes/log-feedback.ts
index 8342c51..ccf7953 100644
--- a/api/routes/log-feedback.ts
+++ b/api/routes/log-feedback.ts
@@ -1,2 +1,2 @@
-export { POST } from "../../src/server/routes/log-feedback"
+export { POST } from "../../src/server/routes/log-feedback"
diff --git a/api/routes/log-file-parser.ts b/api/routes/log-file-parser.ts
index a616cd9..fc0f524 100644
--- a/api/routes/log-file-parser.ts
+++ b/api/routes/log-file-parser.ts
@@ -1,3 +1,3 @@
-export { POST } from "../../src/server/routes/log-file-parser"
+export { POST } from "../../src/server/routes/log-file-parser"
diff --git a/api/routes/log-save.ts b/api/routes/log-save.ts
index a86809e..6c7635c 100644
--- a/api/routes/log-save.ts
+++ b/api/routes/log-save.ts
@@ -1,2 +1,2 @@
-export { POST } from "../../src/server/routes/log-save"
+export { POST } from "../../src/server/routes/log-save"
diff --git a/api/routes/third-party-parser.ts b/api/routes/third-party-parser.ts
index f8232e1..510a30c 100644
--- a/api/routes/third-party-parser.ts
+++ b/api/routes/third-party-parser.ts
@@ -1,3 +1,3 @@
-export { POST } from "../../src/server/routes/third-party-parser"
+export { POST } from "../../src/server/routes/third-party-parser"
diff --git a/api/routes/verify-access-code.ts b/api/routes/verify-access-code.ts
index b79e825..a3e2991 100644
--- a/api/routes/verify-access-code.ts
+++ b/api/routes/verify-access-code.ts
@@ -1,2 +1,2 @@
-export { POST } from "../../src/server/routes/verify-access-code"
+export { POST } from "../../src/server/routes/verify-access-code"
diff --git a/src/App.tsx b/src/App.tsx
deleted file mode 100644
index 15d67ea..0000000
--- a/src/App.tsx
+++ /dev/null
@@ -1,177 +0,0 @@
-import React, { useState } from "react";
-import { Toaster } from "sonner";
-import { FileCode, Layers, Presentation } from "lucide-react";
-import { Button } from "@/shared/ui/button";
-import { SettingsDialog } from "@/components/SettingsDialog";
-import { LandingPage } from "@/pages/LandingPage";
-import { cn } from "@/shared/lib/utils";
-import { getUiLanguage, t, useUiLanguage, type UiLanguage } from "@/shared/i18n";
-import { FlowWorkspaceShell } from "@/workspaces/flow/FlowWorkspaceShell";
-import { CadWorkspaceShell } from "@/workspaces/cad/CadWorkspaceShell";
-import { PptWorkspaceShell } from "@/workspaces/ppt/PptWorkspaceShell";
-import type { PortalWorkspace } from "@/pages/portal/data";
-
-type WorkspaceType = "flow" | "cad" | "ppt";
-const APP_VIEW_STORAGE_KEY = "CanvasAnvil-app-view-v1";
-const APP_WORKSPACE_STORAGE_KEY = "CanvasAnvil-active-workspace-v1";
-
-function BrandIcon({ className }: { className?: string }) {
- return (
- <span className={cn("inline-flex h-10 w-10 shrink-0 items-center justify-center", className)}>
- <svg viewBox="0 0 48 48" role="img" aria-label="CanvasAnvil" className="h-full w-full drop-shadow-[0_8px_18px_rgba(35,108,255,0.22)]">
- <path d="M24 3.8 42 12.8 24 21.8 6 12.8 24 3.8Z" fill="#236CFF" />
- <path d="M24 8.6 32.4 12.8 24 17 15.6 12.8 24 8.6Z" fill="#8EC1FF" />
- <path d="M8.8 17.5 24 25.1l15.2-7.6v5.7L24 30.8 8.8 23.2v-5.7Z" fill="#0B77F4" />
- <path d="M16.5 29.3h15l-2.7 4.4h-9.6l-2.7-4.4Z" fill="#053EA8" />
- <path d="M13.3 36.6h21.4v4.2H13.3v-4.2Z" fill="#236CFF" />
- <path d="M10 41.4h28v3.4H10v-3.4Z" fill="#053EA8" />
- </svg>
- </span>
- );
-}
-
-class ErrorBoundary extends React.Component<{ children: React.ReactNode }, { error: Error | null }> {
- state: { error: Error | null } = { error: null };
-
- static getDerivedStateFromError(error: Error) {
- return { error };
- }
-
- componentDidCatch(error: Error) {
- console.error("UI crashed", error);
- }
-
- render() {
- if (this.state.error) {
- const uiLang: UiLanguage = getUiLanguage();
- return (
- <div className="w-full h-full flex items-center justify-center p-6">
- <div className="max-w-[720px] w-full rounded-xl border border-border/60 bg-background p-5">
- <div className="text-base font-medium mb-2">UI Error</div>
- <div className="text-sm text-muted-foreground whitespace-pre-wrap break-words mb-4">
- {String(this.state.error?.message || "Unknown error")}
- </div>
- <div className="flex items-center gap-2">
- <Button variant="default" onClick={() => window.location.reload()}>
- {t(uiLang, "app.refresh")}
- </Button>
- <Button variant="outline" onClick={() => this.setState({ error: null })}>
- {t(uiLang, "app.tryContinue")}
- </Button>
- </div>
- </div>
- </div>
- );
- }
- return this.props.children as any;
- }
-}
-
-function App() {
- const uiLang = useUiLanguage();
- const [showLanding, setShowLanding] = useState(() => {
- if (typeof window === "undefined") return true;
- const saved = localStorage.getItem(APP_VIEW_STORAGE_KEY);
- if (saved === "workspace") return false;
- if (saved === "landing") return true;
- return true;
- });
- const [activeWorkspace, setActiveWorkspace] = useState<WorkspaceType>(() => {
- if (typeof window === "undefined") return "flow";
- const saved = localStorage.getItem(APP_WORKSPACE_STORAGE_KEY);
- return saved === "cad" || saved === "ppt" || saved === "flow" ? saved : "flow";
- });
-
- React.useEffect(() => {
- if (typeof window === "undefined") return;
- localStorage.setItem(APP_VIEW_STORAGE_KEY, showLanding ? "landing" : "workspace");
- }, [showLanding]);
-
- React.useEffect(() => {
- if (typeof window === "undefined") return;
- localStorage.setItem(APP_WORKSPACE_STORAGE_KEY, activeWorkspace);
- }, [activeWorkspace]);
-
- if (showLanding) {
- return (
- <LandingPage
- onStart={(workspace?: PortalWorkspace) => {
- if (workspace) setActiveWorkspace(workspace);
- setShowLanding(false);
- }}
- />
- );
- }
-
- return (
- <div className="h-screen w-screen flex flex-col bg-background overflow-hidden font-sans">
- <Toaster position="top-center" richColors />
-
- <header className="h-16 border-b border-border/40 grid grid-cols-[1fr_auto_1fr] items-center gap-4 px-6 bg-background/80 backdrop-blur-md supports-[backdrop-filter]:bg-background/60 z-50 shadow-sm">
- <div
- className="flex items-center gap-2.5 font-semibold text-lg tracking-tight text-foreground/90 cursor-pointer justify-self-start"
- onClick={() => setShowLanding(true)}
- >
- <BrandIcon className="h-10 w-10" />
- <span>CanvasAnvil</span>
- </div>
-
- <div className="justify-self-center max-w-full overflow-x-auto">
- <div className="flex min-w-max items-center bg-muted/50 p-1 rounded-xl border border-border/50 shadow-inner">
- <button
- onClick={() => setActiveWorkspace("flow")}
- className={cn(
- "flex items-center gap-2 px-4 py-1.5 rounded-lg text-sm font-medium transition-all duration-300 ease-out",
- activeWorkspace === "flow"
- ? "bg-background text-foreground shadow-sm ring-1 ring-border/50 scale-100"
- : "text-muted-foreground hover:text-foreground hover:bg-background/50",
- )}
- >
- <Layers className="w-4 h-4" />
- {t(uiLang, "nav.flow")}
- </button>
- <button
- onClick={() => setActiveWorkspace("cad")}
- className={cn(
- "flex items-center gap-2 px-4 py-1.5 rounded-lg text-sm font-medium transition-all duration-300 ease-out",
- activeWorkspace === "cad"
- ? "bg-background text-foreground shadow-sm ring-1 ring-border/50 scale-100"
- : "text-muted-foreground hover:text-foreground hover:bg-background/50",
- )}
- >
- <FileCode className="w-4 h-4" />
- {t(uiLang, "nav.cad")}
- </button>
- <button
- onClick={() => setActiveWorkspace("ppt")}
- className={cn(
- "flex items-center gap-2 px-4 py-1.5 rounded-lg text-sm font-medium transition-all duration-300 ease-out",
- activeWorkspace === "ppt"
- ? "bg-background text-foreground shadow-sm ring-1 ring-border/50 scale-100"
- : "text-muted-foreground hover:text-foreground hover:bg-background/50",
- )}
- >
- <Presentation className="w-4 h-4" />
- {t(uiLang, "nav.ppt")}
- </button>
- </div>
- </div>
-
- <div className="w-48 flex justify-end justify-self-end">
- <SettingsDialog />
- </div>
- </header>
-
- <div className="flex-1 overflow-hidden relative">
- <ErrorBoundary>
- {activeWorkspace === "flow" && <FlowWorkspaceShell />}
- {activeWorkspace === "cad" && <CadWorkspaceShell />}
- {activeWorkspace === "ppt" && <PptWorkspaceShell />}
- </ErrorBoundary>
- </div>
- </div>
- );
-}
-
-export default App;
-
diff --git a/src/app/App.tsx b/src/app/App.tsx
new file mode 100644
index 0000000..e3692c8
--- /dev/null
+++ b/src/app/App.tsx
@@ -0,0 +1,108 @@
+import { Suspense, useEffect, useState } from "react";
+import { Loader2 } from "lucide-react";
+import { Toaster } from "sonner";
+import { BrandIcon } from "@/app/BrandIcon";
+import { ErrorBoundary } from "@/app/ErrorBoundary";
+import { DEFAULT_WORKSPACE, WORKSPACES, isWorkspaceId, type WorkspaceId } from "@/app/workspaces";
+import { SettingsDialog } from "@/components/SettingsDialog";
+import { LandingPage } from "@/pages/LandingPage";
+import { cn } from "@/shared/lib/utils";
+import { t, useUiLanguage } from "@/shared/i18n";
+
+const APP_VIEW_STORAGE_KEY = "CanvasAnvil-app-view-v1";
+const APP_WORKSPACE_STORAGE_KEY = "CanvasAnvil-active-workspace-v1";
+
+function readStoredWorkspace(): WorkspaceId {
+ if (typeof window === "undefined") return DEFAULT_WORKSPACE;
+ const saved = localStorage.getItem(APP_WORKSPACE_STORAGE_KEY);
+ return isWorkspaceId(saved) ? saved : DEFAULT_WORKSPACE;
+}
+
+function WorkspaceFallback() {
+ return (
+ <div className="h-full w-full flex items-center justify-center">
+ <Loader2 className="h-6 w-6 animate-spin text-muted-foreground" />
+ </div>
+ );
+}
+
+export default function App() {
+ const uiLang = useUiLanguage();
+ const [showLanding, setShowLanding] = useState(() => {
+ if (typeof window === "undefined") return true;
+ return localStorage.getItem(APP_VIEW_STORAGE_KEY) !== "workspace";
+ });
+ const [activeWorkspace, setActiveWorkspace] = useState<WorkspaceId>(readStoredWorkspace);
+
+ useEffect(() => {
+ localStorage.setItem(APP_VIEW_STORAGE_KEY, showLanding ? "landing" : "workspace");
+ }, [showLanding]);
+
+ useEffect(() => {
+ localStorage.setItem(APP_WORKSPACE_STORAGE_KEY, activeWorkspace);
+ }, [activeWorkspace]);
+
+ if (showLanding) {
+ return (
+ <LandingPage
+ onStart={(workspace) => {
+ if (workspace) setActiveWorkspace(workspace);
+ setShowLanding(false);
+ }}
+ />
+ );
+ }
+
+ const active = WORKSPACES.find((workspace) => workspace.id === activeWorkspace) ?? WORKSPACES[0];
+ const ActiveWorkspace = active.Component;
+
+ return (
+ <div className="h-screen w-screen flex flex-col bg-background overflow-hidden font-sans">
+ <Toaster position="top-center" richColors />
+
+ <header className="h-16 border-b border-border/40 grid grid-cols-[1fr_auto_1fr] items-center gap-4 px-6 bg-background/80 backdrop-blur-md supports-[backdrop-filter]:bg-background/60 z-50 shadow-sm">
+ <div
+ className="flex items-center gap-2.5 font-semibold text-lg tracking-tight text-foreground/90 cursor-pointer justify-self-start"
+ onClick={() => setShowLanding(true)}
+ >
+ <BrandIcon className="h-10 w-10" />
+ <span>CanvasAnvil</span>
+ </div>
+
+ <div className="justify-self-center max-w-full overflow-x-auto">
+ <div className="flex min-w-max items-center bg-muted/50 p-1 rounded-xl border border-border/50 shadow-inner">
+ {WORKSPACES.map(({ id, labelKey, icon: Icon }) => (
+ <button
+ key={id}
+ onClick={() => setActiveWorkspace(id)}
+ className={cn(
+ "flex items-center gap-2 px-4 py-1.5 rounded-lg text-sm font-medium transition-all duration-300 ease-out",
+ activeWorkspace === id
+ ? "bg-background text-foreground shadow-sm ring-1 ring-border/50 scale-100"
+ : "text-muted-foreground hover:text-foreground hover:bg-background/50",
+ )}
+ >
+ <Icon className="w-4 h-4" />
+ {t(uiLang, labelKey)}
+ </button>
+ ))}
+ </div>
+ </div>
+
+ <div className="w-48 flex justify-end justify-self-end">
+ <SettingsDialog />
+ </div>
+ </header>
+
+ <div className="flex-1 overflow-hidden relative">
+ <ErrorBoundary>
+ {/* Keyed so switching canvases unmounts the previous one rather than
+ reusing its state under a different workspace. */}
+ <Suspense fallback={<WorkspaceFallback />}>
+ <ActiveWorkspace key={active.id} />
+ </Suspense>
+ </ErrorBoundary>
+ </div>
+ </div>
+ );
+}
diff --git a/src/app/BrandIcon.tsx b/src/app/BrandIcon.tsx
new file mode 100644
index 0000000..937b47b
--- /dev/null
+++ b/src/app/BrandIcon.tsx
@@ -0,0 +1,21 @@
+import { cn } from "@/shared/lib/utils";
+
+export function BrandIcon({ className }: { className?: string }) {
+ return (
+ <span className={cn("inline-flex h-10 w-10 shrink-0 items-center justify-center", className)}>
+ <svg
+ viewBox="0 0 48 48"
+ role="img"
+ aria-label="CanvasAnvil"
+ className="h-full w-full drop-shadow-[0_8px_18px_rgba(35,108,255,0.22)]"
+ >
+ <path d="M24 3.8 42 12.8 24 21.8 6 12.8 24 3.8Z" fill="#236CFF" />
+ <path d="M24 8.6 32.4 12.8 24 17 15.6 12.8 24 8.6Z" fill="#8EC1FF" />
+ <path d="M8.8 17.5 24 25.1l15.2-7.6v5.7L24 30.8 8.8 23.2v-5.7Z" fill="#0B77F4" />
+ <path d="M16.5 29.3h15l-2.7 4.4h-9.6l-2.7-4.4Z" fill="#053EA8" />
+ <path d="M13.3 36.6h21.4v4.2H13.3v-4.2Z" fill="#236CFF" />
+ <path d="M10 41.4h28v3.4H10v-3.4Z" fill="#053EA8" />
+ </svg>
+ </span>
+ );
+}
diff --git a/src/app/ErrorBoundary.tsx b/src/app/ErrorBoundary.tsx
new file mode 100644
index 0000000..3c979e4
--- /dev/null
+++ b/src/app/ErrorBoundary.tsx
@@ -0,0 +1,49 @@
+import React from "react";
+import { Button } from "@/shared/ui/button";
+import { getUiLanguage, t } from "@/shared/i18n";
+
+/**
+ * Catches a render crash in a workspace so the rest of the shell — the header,
+ * the settings dialog, the other canvases — stays usable, and offers a retry
+ * that does not throw away the page.
+ */
+export class ErrorBoundary extends React.Component<
+ { children: React.ReactNode },
+ { error: Error | null }
+> {
+ state: { error: Error | null } = { error: null };
+
+ static getDerivedStateFromError(error: Error) {
+ return { error };
+ }
+
+ componentDidCatch(error: Error) {
+ console.error("UI crashed", error);
+ }
+
+ render() {
+ if (!this.state.error) return this.props.children;
+
+ // Read the language directly: a hook is not available in a class, and this
+ // path renders once, after a crash.
+ const uiLang = getUiLanguage();
+ return (
+ <div className="w-full h-full flex items-center justify-center p-6">
+ <div className="max-w-[720px] w-full rounded-xl border border-border/60 bg-background p-5">
+ <div className="text-base font-medium mb-2">UI Error</div>
+ <div className="text-sm text-muted-foreground whitespace-pre-wrap break-words mb-4">
+ {String(this.state.error?.message || "Unknown error")}
+ </div>
+ <div className="flex items-center gap-2">
+ <Button variant="default" onClick={() => window.location.reload()}>
+ {t(uiLang, "app.refresh")}
+ </Button>
+ <Button variant="outline" onClick={() => this.setState({ error: null })}>
+ {t(uiLang, "app.tryContinue")}
+ </Button>
+ </div>
+ </div>
+ </div>
+ );
+ }
+}
diff --git a/src/app/workspaces.ts b/src/app/workspaces.ts
new file mode 100644
index 0000000..e61765e
--- /dev/null
+++ b/src/app/workspaces.ts
@@ -0,0 +1,58 @@
+import { lazy, type ComponentType, type LazyExoticComponent } from "react";
+import { FileCode, Layers, Presentation, type LucideIcon } from "lucide-react";
+import type { MessageKey } from "@/shared/i18n";
+
+/**
+ * The canvases the app offers.
+ *
+ * Adding or removing one is a change to this array and nothing else — the
+ * header tabs, the persisted selection and the rendered workspace all read
+ * from here.
+ *
+ * Each shell is loaded lazily: a session normally uses one canvas, and the
+ * other two together account for most of the bundle.
+ */
+
+export type WorkspaceId = "flow" | "cad" | "ppt";
+
+export interface WorkspaceDescriptor {
+ id: WorkspaceId;
+ /** Key into the shared message dictionary. */
+ labelKey: MessageKey;
+ icon: LucideIcon;
+ Component: LazyExoticComponent<ComponentType>;
+}
+
+export const WORKSPACES: WorkspaceDescriptor[] = [
+ {
+ id: "flow",
+ labelKey: "nav.flow",
+ icon: Layers,
+ Component: lazy(() =>
+ import("@/workspaces/flow/FlowWorkspaceShell").then((m) => ({ default: m.FlowWorkspaceShell })),
+ ),
+ },
+ {
+ id: "cad",
+ labelKey: "nav.cad",
+ icon: FileCode,
+ Component: lazy(() =>
+ import("@/workspaces/cad/CadWorkspaceShell").then((m) => ({ default: m.CadWorkspaceShell })),
+ ),
+ },
+ {
+ id: "ppt",
+ labelKey: "nav.ppt",
+ icon: Presentation,
+ Component: lazy(() =>
+ import("@/workspaces/ppt/PptWorkspaceShell").then((m) => ({ default: m.PptWorkspaceShell })),
+ ),
+ },
+];
+
+export const DEFAULT_WORKSPACE: WorkspaceId = "flow";
+
+/** Guards the value read back from localStorage, which may predate a removal. */
+export function isWorkspaceId(value: unknown): value is WorkspaceId {
+ return WORKSPACES.some((workspace) => workspace.id === value);
+}
diff --git a/src/features/ppt-editor/adapters/fromCanvasAnvil.ts b/src/features/ppt-editor/adapters/fromCanvasAnvil.ts
index cb0d553..752c653 100644
--- a/src/features/ppt-editor/adapters/fromCanvasAnvil.ts
+++ b/src/features/ppt-editor/adapters/fromCanvasAnvil.ts
@@ -2,6 +2,7 @@ import {
pptElementsToTextBlocks,
textBlocksToPptElements,
type PptElement,
+ type PptTextBlock,
} from "@/lib/ppt-service";
import type {
CanvasAnvilRenderLayerLike,
@@ -18,7 +19,7 @@ import type {
EditorVideoElement,
} from "@/features/ppt-editor/types";
-const toEditorElements = (elements?: PptElement[], textBlocksFallback = []): EditorElement[] => {
+const toEditorElements = (elements?: PptElement[], textBlocksFallback: PptTextBlock[] = []): EditorElement[] => {
const source = Array.isArray(elements) && elements.length > 0 ? elements : textBlocksToPptElements(textBlocksFallback);
return source
.map((element): EditorElement | null => {
@@ -162,7 +163,7 @@ export const canvasAnvilToEditorSlide = (
}
): EditorSlide => {
const layer = options?.renderLayer || undefined;
- const textBlocks = Array.isArray(layer?.textBlocks) ? layer!.textBlocks! : [];
+ const textBlocks: PptTextBlock[] = Array.isArray(layer?.textBlocks) ? layer.textBlocks : [];
const elements = toEditorElements(layer?.elements, textBlocks);
return {
diff --git a/src/features/ppt-editor/components/PptReviewBridge.tsx b/src/features/ppt-editor/components/PptReviewBridge.tsx
index 1e006a1..98307ac 100644
--- a/src/features/ppt-editor/components/PptReviewBridge.tsx
+++ b/src/features/ppt-editor/components/PptReviewBridge.tsx
@@ -1,4 +1,4 @@
-import type React from "react";
+import type React from "react";
import { FileSearch, FileText, Loader2, Play, Trash2 } from "lucide-react";
import { Button } from "@/shared/ui/button";
import { Textarea } from "@/shared/ui/textarea";
@@ -52,12 +52,10 @@ export function PptReviewSidebar(props: {
reviewPhase,
extractionSummary,
reviewDrawMode,
- confirmLabel,
tr,
onPanelResizeStart,
onExtract,
onStartEditing,
- onExport,
onToggleDrawMode,
onSelectBlock,
onDeleteBlock,
diff --git a/src/lib/ppt-service.ts b/src/lib/ppt-service.ts
index 0d9b7ea..e004a93 100644
--- a/src/lib/ppt-service.ts
+++ b/src/lib/ppt-service.ts
@@ -1,5 +1,3 @@
-import PptxGenJS from "pptxgenjs"
-import { PDFDocument } from "pdf-lib"
import { generateChatMessage, generateImage, generateVisionChatMessage } from "@/ai/client"
import { buildRisenPrompt } from "./risen-prompt"
import pptOutlineSystem from "../../agent/ppt/outline.md?raw"
@@ -1146,11 +1144,13 @@ export const pptService = {
? normalizedAdditional.map((x) => String(x?.url || "")).filter(Boolean)
: [];
- return await generateImage({
+ const imageUrl = await generateImage({
prompt,
- referenceImageUrl: templateImageUrl,
+ referenceImageUrl: templateImageUrl || undefined,
additionalReferenceImageUrls,
});
+ if (!imageUrl) throw new Error("Slide image generation returned no image.");
+ return imageUrl;
},
extractSlideTextBlocks: async (
@@ -1215,10 +1215,12 @@ export const pptService = {
? `基于原图生成同一页 PPT 的无字底图。只移除下面这些文本框内的文字本身,且只允许修改已给出文本框范围内、被文字笔画实际占据的像素;如果某个文本框里没有文字,就不要做任何修改。文本框外任何像素都绝对不能改动。不要改版式、不要改图片、不要改图标、不要改图表、不要改装饰、不要扩大修改范围。禁止生成任何矩形补丁、纯色块、模糊块、修复块、遮罩边界、文本框痕迹或重新设计的背景。处理后的区域必须与周围原始背景连续一致,看起来像原图里从来没有放过文字。\n\n要删除的文字:\n${textList || "(none)"}\n\n文字位置:\n${textRegions}\n\n严格边界要求:\n${backgroundHints.join("\n") || "(none)"}`
: `Create a textless background for this same slide. Remove only the text inside the listed text boxes, and modify only the pixels actually occupied by text glyphs inside those boxes. If a listed text box contains no text, do not change anything in that box. Absolutely do not modify any pixel outside the listed text boxes. Do not alter layout, images, icons, charts, decorations, or the surrounding background. Do not expand the edited area. Do not create any rectangular patch, flat color block, blur patch, inpaint patch, mask edge, textbox residue, or redesigned background. The cleaned area must blend seamlessly with the original nearby background so it looks like the text was never placed there.\n\nText to remove:\n${textList || "(none)"}\n\nText regions:\n${textRegions}\n\nHard boundaries:\n${backgroundHints.join("\n") || "(none)"}`;
- return await generateImage({
+ const imageUrl = await generateImage({
prompt,
- referenceImageUrl: slideImageUrl,
+ referenceImageUrl: slideImageUrl || undefined,
});
+ if (!imageUrl) throw new Error("Textless background generation returned no image.");
+ return imageUrl;
},
reviewSlideTextBlocks: async (
@@ -1381,6 +1383,7 @@ export const pptService = {
},
exportPptx: async (pages: PptPage[], images: Record<string, string>, filename: string) => {
+ const { default: PptxGenJS } = await import("pptxgenjs");
const pptx = new PptxGenJS();
pptx.layout = "LAYOUT_WIDE";
@@ -1587,6 +1590,7 @@ export const pptService = {
},
exportPdf: async (pages: PptPage[], images: Record<string, string>, filename: string) => {
+ const { PDFDocument } = await import("pdf-lib");
const pdfDoc = await PDFDocument.create();
const pageWidth = 960;
const pageHeight = 540;
diff --git a/src/main.tsx b/src/main.tsx
index fab1219..e01727f 100644
--- a/src/main.tsx
+++ b/src/main.tsx
@@ -1,6 +1,6 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
-import App from './App'
+import App from '@/app/App'
import './index.css'
createRoot(document.getElementById('root')!).render(
diff --git a/src/server/routes/config.ts b/src/server/routes/config.ts
index 9db6f4a..3183fa2 100644
--- a/src/server/routes/config.ts
+++ b/src/server/routes/config.ts
@@ -1,4 +1,4 @@
-export async function GET() {
+export async function GET() {
return Response.json({
accessCodeRequired: !!process.env.ACCESS_CODE_LIST,
dailyRequestLimit: Number(process.env.DAILY_REQUEST_LIMIT) || 0,
diff --git a/src/server/routes/log-feedback.ts b/src/server/routes/log-feedback.ts
index 826680c..ed0189f 100644
--- a/src/server/routes/log-feedback.ts
+++ b/src/server/routes/log-feedback.ts
@@ -1,4 +1,4 @@
-import { randomUUID } from "crypto"
+import { randomUUID } from "crypto"
import { z } from "zod"
import { getLangfuseClient } from "../telemetry/langfuse"
diff --git a/src/server/routes/log-save.ts b/src/server/routes/log-save.ts
index cd67f03..d145229 100644
--- a/src/server/routes/log-save.ts
+++ b/src/server/routes/log-save.ts
@@ -1,4 +1,4 @@
-import { randomUUID } from "crypto"
+import { randomUUID } from "crypto"
import { z } from "zod"
import { getLangfuseClient } from "../telemetry/langfuse"
diff --git a/src/server/routes/verify-access-code.ts b/src/server/routes/verify-access-code.ts
index eb2dc80..5c4098d 100644
--- a/src/server/routes/verify-access-code.ts
+++ b/src/server/routes/verify-access-code.ts
@@ -1,4 +1,4 @@
-export async function POST(req: Request) {
+export async function POST(req: Request) {
const accessCodes =
process.env.ACCESS_CODE_LIST?.split(",")
.map((code) => code.trim())
diff --git a/src/server/telemetry/langfuse.ts b/src/server/telemetry/langfuse.ts
index 241e256..08d0ae3 100644
--- a/src/server/telemetry/langfuse.ts
+++ b/src/server/telemetry/langfuse.ts
@@ -1,4 +1,4 @@
-import { LangfuseClient } from "@langfuse/client"
+import { LangfuseClient } from "@langfuse/client"
import { observe, updateActiveTrace } from "@langfuse/tracing"
import * as api from "@opentelemetry/api"
@@ -82,14 +82,17 @@ export function getTelemetryConfig(params: {
}) {
if (!isLangfuseEnabled()) return undefined
+ // OpenTelemetry attributes cannot be undefined, so omit the keys we lack
+ // rather than sending them as undefined.
+ const metadata: Record<string, string> = {}
+ if (params.sessionId) metadata.sessionId = params.sessionId
+ if (params.userId) metadata.userId = params.userId
+
return {
isEnabled: true,
recordInputs: true,
recordOutputs: true,
- metadata: {
- sessionId: params.sessionId,
- userId: params.userId,
- },
+ metadata,
}
}
diff --git a/src/shared/chat/history-dialog.tsx b/src/shared/chat/history-dialog.tsx
index c6f83c2..7da8100 100644
--- a/src/shared/chat/history-dialog.tsx
+++ b/src/shared/chat/history-dialog.tsx
@@ -1,4 +1,3 @@
-import React from 'react';
import {
Dialog,
DialogContent,
diff --git a/src/shared/i18n/messages.ts b/src/shared/i18n/messages.ts
index a14415d..63f178d 100644
--- a/src/shared/i18n/messages.ts
+++ b/src/shared/i18n/messages.ts
@@ -59,4 +59,7 @@ const messages = {
"error.missingApiKey": { zh: "请先在设置中配置 API Key", en: "Please configure an API key in Settings first." },
} satisfies Dict;
+/** Every key the app-shell dictionary defines. */
+export type MessageKey = keyof typeof messages;
+
export const { t, translate: tAuto, useT } = createTranslator(messages);
diff --git a/src/shared/storage/indexed-db-store.ts b/src/shared/storage/indexed-db-store.ts
index 52c923f..b2bd61e 100644
--- a/src/shared/storage/indexed-db-store.ts
+++ b/src/shared/storage/indexed-db-store.ts
@@ -37,7 +37,7 @@ export function createWorkspaceStore(databaseName: string): WorkspaceStore {
/** Runs one transaction and closes the connection, whatever the outcome. */
async function transact<T>(
mode: IDBTransactionMode,
- run: (store: IDBObjectStore, resolve: (value: T) => void) => void,
+ run: (store: IDBObjectStore, resolve: (value: T | null) => void) => void,
): Promise<T | null> {
const db = await open();
if (!db) return null;
diff --git a/src/workspaces/cad/CadWorkspaceShell.tsx b/src/workspaces/cad/CadWorkspaceShell.tsx
index 7e1e818..8942f82 100644
--- a/src/workspaces/cad/CadWorkspaceShell.tsx
+++ b/src/workspaces/cad/CadWorkspaceShell.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useRef, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { cn } from "@/shared/lib/utils";
import { t, useUiLanguage } from "@/shared/i18n";
@@ -30,6 +30,9 @@ const CAD_RENDERS_STORAGE_KEY = "CanvasAnvil-cad-renders-v1";
const CAD_ANALYSIS_IMAGES_STORAGE_KEY = "CanvasAnvil-cad-analysis-images-v1";
const CAD_CHAT_STORAGE_KEY = "chat_history_v2_cad";
+/** What the model returns for a CAD image request; every field is unverified. */
+type CadImagePrompt = { title?: unknown; prompt?: unknown };
+
const tryParseJson = (text: string) => {
try {
return JSON.parse(text);
@@ -644,7 +647,7 @@ export function CadWorkspaceShell() {
}
if (parsedType === "cad_analysis_images") {
- const prompts = Array.isArray(parsed.prompts) ? parsed.prompts : [];
+ const prompts: CadImagePrompt[] = Array.isArray(parsed.prompts) ? parsed.prompts : [];
const defaultTitles = [
uiLang === "zh" ? "整体方案图" : "Overall Scheme",
uiLang === "zh" ? "重点策略图" : "Key Strategy",
@@ -743,7 +746,7 @@ export function CadWorkspaceShell() {
}
if (parsedType === "cad_images") {
- const prompts = Array.isArray(parsed.prompts) ? parsed.prompts : [];
+ const prompts: CadImagePrompt[] = Array.isArray(parsed.prompts) ? parsed.prompts : [];
const previousStableRenders = normalizeCadRenderItems(cadImages, { allowBlob: false, max: 30 });
const items = prompts
.map((p: any) => ({
diff --git a/src/workspaces/cad/chat/ChatPanel.tsx b/src/workspaces/cad/chat/ChatPanel.tsx
index a656db0..ba2d44f 100644
--- a/src/workspaces/cad/chat/ChatPanel.tsx
+++ b/src/workspaces/cad/chat/ChatPanel.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useRef, useEffect } from 'react';
+import { useState, useRef, useEffect } from 'react';
import { PanelRightClose, PanelRightOpen } from 'lucide-react';
import { cn } from '@/shared/lib/utils';
import { streamChatMessage, generateChatMessage, ChatMessage, getAIConfig } from '@/ai/client';
diff --git a/src/workspaces/cad/chat/code-block.tsx b/src/workspaces/cad/chat/code-block.tsx
index 1d98f2c..05f32b2 100644
--- a/src/workspaces/cad/chat/code-block.tsx
+++ b/src/workspaces/cad/chat/code-block.tsx
@@ -1,4 +1,4 @@
-import React, { useMemo, useState } from "react";
+import { useMemo, useState } from "react";
import { Check, ChevronDown, ChevronUp, Copy, Cpu, Play, X } from "lucide-react";
import { Highlight, themes, type Language } from "prism-react-renderer";
import { useUiLanguage } from "@/shared/i18n";
diff --git a/src/workspaces/cad/workspace/CadWorkspace.tsx b/src/workspaces/cad/workspace/CadWorkspace.tsx
index 0b55783..5011419 100644
--- a/src/workspaces/cad/workspace/CadWorkspace.tsx
+++ b/src/workspaces/cad/workspace/CadWorkspace.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useMemo, useRef, useState } from 'react';
+import { useEffect, useMemo, useRef, useState } from 'react';
import { Loader2, MessageSquarePlus, Box, Image as ImageIcon, Table2, Download } from 'lucide-react';
import {
ContextMenu,
@@ -8,7 +8,6 @@ import {
} from "@/shared/ui/context-menu";
import { Button } from "@/shared/ui/button";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/shared/ui/dialog";
-import { PDFDocument } from "pdf-lib";
import { useUiLanguage } from "@/shared/i18n";
import { toast } from "sonner";
import { getCadRenderSlotTitles } from "@/lib/cad-render-titles";
@@ -551,6 +550,7 @@ export function CadWorkspace({
if (downloadable.length === 0 || isExporting) return;
setIsExporting(true);
try {
+ const { PDFDocument } = await import("pdf-lib");
const pdfDoc = await PDFDocument.create();
for (const it of downloadable) {
const res = await fetch(it.url);
diff --git a/src/workspaces/flow/FlowWorkspaceShell.tsx b/src/workspaces/flow/FlowWorkspaceShell.tsx
index b840800..220b385 100644
--- a/src/workspaces/flow/FlowWorkspaceShell.tsx
+++ b/src/workspaces/flow/FlowWorkspaceShell.tsx
@@ -1,4 +1,3 @@
-import React from "react";
import { NextFlowWorkspace } from "@/workspaces/flow/next/NextFlowWorkspace";
export function FlowWorkspaceShell() {
diff --git a/src/workspaces/flow/next/components/chat-input.tsx b/src/workspaces/flow/next/components/chat-input.tsx
index 1be1ac8..ee68b3d 100644
--- a/src/workspaces/flow/next/components/chat-input.tsx
+++ b/src/workspaces/flow/next/components/chat-input.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import {
Brain,
diff --git a/src/workspaces/flow/next/components/chat-message-display.tsx b/src/workspaces/flow/next/components/chat-message-display.tsx
index d554cd5..cd721bc 100644
--- a/src/workspaces/flow/next/components/chat-message-display.tsx
+++ b/src/workspaces/flow/next/components/chat-message-display.tsx
@@ -1,6 +1,22 @@
-"use client"
+"use client"
-type UIMessage = any
+/**
+ * A message as the chat hook hands it over. `parts` is deliberately loose:
+ * the AI SDK streams tool calls, files and reasoning blocks whose shapes vary
+ * by provider, and this component narrows each part where it reads it.
+ */
+interface UIMessagePart {
+ type: string
+ [key: string]: any
+}
+
+type UIMessage = {
+ id: string
+ role: "user" | "assistant" | "system"
+ /** A plain string, or the multimodal part array the model was sent. */
+ content?: string | UIMessagePart[]
+ parts?: UIMessagePart[]
+}
import {
Check,
@@ -132,7 +148,7 @@ const getMessageTextContent = (message: UIMessage): string => {
if (message.parts && message.parts.length > 0) {
return message.parts
.filter((part) => part.type === "text")
- .map((part) => (part as { text: string }).text)
+ .map((part) => String(part.text ?? ""))
.join("\n")
}
if (Array.isArray(message.content)) {
@@ -705,7 +721,7 @@ export function ChatMessageDisplay({
)
) {
parts = message.content
- .map((item: any) => {
+ .map((item: any): UIMessagePart | null => {
if (
item?.type ===
"text"
@@ -756,7 +772,10 @@ export function ChatMessageDisplay({
}
return null
})
- .filter(Boolean)
+ .filter(
+ (part): part is UIMessagePart =>
+ part !== null,
+ )
}
}
@@ -1079,13 +1098,9 @@ export function ChatMessageDisplay({
part.type ===
"text"
) {
- const textContent =
- (
- part as {
- text: string
- }
- )
- .text
+ const textContent = String(
+ part.text ?? "",
+ )
const sections = splitTextIntoFileSections(
textContent,
).filter(
diff --git a/src/workspaces/flow/next/components/chat-panel.tsx b/src/workspaces/flow/next/components/chat-panel.tsx
index 10537b7..7c8b638 100644
--- a/src/workspaces/flow/next/components/chat-panel.tsx
+++ b/src/workspaces/flow/next/components/chat-panel.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import { useChat } from "@ai-sdk/react"
import {
@@ -229,7 +229,7 @@ export default function ChatPanel({
const chat: any = (useChat as any)({
api: "/api/chat",
- onError: (error) => {
+ onError: (error: unknown) => {
setIsParsingFiles(false)
console.error('[ChatPanel] useChat error:', error)
const rawDetail =
@@ -250,7 +250,7 @@ export default function ChatPanel({
toast.error(`发送失败:${detail}`)
},
- async onToolCall({ toolCall }) {
+ async onToolCall({ toolCall }: { toolCall: any }) {
if (DEBUG) {
console.log(
`[onToolCall] Tool: ${toolCall.toolName}, CallId: ${toolCall.toolCallId}`,
@@ -528,7 +528,7 @@ Please fix the XML issues. Ensure cell_id values exist in the current XML and th
}
}
},
- sendAutomaticallyWhen: ({ messages }) => {
+ sendAutomaticallyWhen: ({ messages }: { messages: any[] }) => {
const shouldRetry = hasToolErrors(
messages as unknown as ChatMessage[],
)
@@ -998,7 +998,10 @@ Please fix the XML issues. Ensure cell_id values exist in the current XML and th
}
return null
})
- .filter((x: any) => x?.url && String(x.url).startsWith("data:image/"))
+ .filter(
+ (x): x is { url: string; contentType: string } =>
+ !!x?.url && String(x.url).startsWith("data:image/"),
+ )
const messageContent: any[] = []
for (const attachment of imageAttachments) {
diff --git a/src/workspaces/flow/next/components/error-toast.tsx b/src/workspaces/flow/next/components/error-toast.tsx
index c4872dd..5b8622b 100644
--- a/src/workspaces/flow/next/components/error-toast.tsx
+++ b/src/workspaces/flow/next/components/error-toast.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import type React from "react"
diff --git a/src/workspaces/flow/next/components/history-dialog.tsx b/src/workspaces/flow/next/components/history-dialog.tsx
index 36b3e73..23e8405 100644
--- a/src/workspaces/flow/next/components/history-dialog.tsx
+++ b/src/workspaces/flow/next/components/history-dialog.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import Image from "@/workspaces/flow/next/shims/next-image"
import { useState } from "react"
diff --git a/src/workspaces/flow/next/components/quota-limit-toast.tsx b/src/workspaces/flow/next/components/quota-limit-toast.tsx
index c72dd05..1b9b75c 100644
--- a/src/workspaces/flow/next/components/quota-limit-toast.tsx
+++ b/src/workspaces/flow/next/components/quota-limit-toast.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import { FaCoffee } from "react-icons/fa"
import { useFlowT } from "@/workspaces/flow/next/lib/translations"
diff --git a/src/workspaces/flow/next/components/save-dialog.tsx b/src/workspaces/flow/next/components/save-dialog.tsx
index 4e17ebe..3e9697d 100644
--- a/src/workspaces/flow/next/components/save-dialog.tsx
+++ b/src/workspaces/flow/next/components/save-dialog.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import { useEffect, useState } from "react"
import { Button } from "@/shared/ui/button"
diff --git a/src/workspaces/flow/next/contexts/diagram-context.tsx b/src/workspaces/flow/next/contexts/diagram-context.tsx
index 51f8c02..9acb2d0 100644
--- a/src/workspaces/flow/next/contexts/diagram-context.tsx
+++ b/src/workspaces/flow/next/contexts/diagram-context.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import type React from "react"
import { createContext, useContext, useRef, useState } from "react"
diff --git a/src/workspaces/flow/next/lib/storage.ts b/src/workspaces/flow/next/lib/storage.ts
index 797495c..f717718 100644
--- a/src/workspaces/flow/next/lib/storage.ts
+++ b/src/workspaces/flow/next/lib/storage.ts
@@ -1,4 +1,4 @@
-// Centralized localStorage keys
+// Centralized localStorage keys
// Consolidates all storage keys from chat-panel.tsx and settings-dialog.tsx
export const STORAGE_KEYS = {
diff --git a/src/workspaces/flow/next/lib/use-quota-manager.tsx b/src/workspaces/flow/next/lib/use-quota-manager.tsx
index b4f29ad..823892c 100644
--- a/src/workspaces/flow/next/lib/use-quota-manager.tsx
+++ b/src/workspaces/flow/next/lib/use-quota-manager.tsx
@@ -1,4 +1,4 @@
-"use client"
+"use client"
import { useCallback, useMemo } from "react"
import { toast } from "sonner"
diff --git a/src/workspaces/flow/next/shims/next-image.tsx b/src/workspaces/flow/next/shims/next-image.tsx
index 0b8f642..e9fc4d9 100644
--- a/src/workspaces/flow/next/shims/next-image.tsx
+++ b/src/workspaces/flow/next/shims/next-image.tsx
@@ -1,4 +1,4 @@
-import React from "react";
+import React from "react";
type ImageProps = React.ImgHTMLAttributes<HTMLImageElement> & {
src: string;
diff --git a/src/workspaces/ppt/PptWorkspaceShell.tsx b/src/workspaces/ppt/PptWorkspaceShell.tsx
index d021120..8fdec31 100644
--- a/src/workspaces/ppt/PptWorkspaceShell.tsx
+++ b/src/workspaces/ppt/PptWorkspaceShell.tsx
@@ -1,4 +1,4 @@
-import React, { useEffect, useRef, useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { cn } from "@/shared/lib/utils";
import { t, useUiLanguage } from "@/shared/i18n";
import {
diff --git a/src/workspaces/ppt/chat/ChatMessageDisplay.tsx b/src/workspaces/ppt/chat/ChatMessageDisplay.tsx
index 7da793a..981d890 100644
--- a/src/workspaces/ppt/chat/ChatMessageDisplay.tsx
+++ b/src/workspaces/ppt/chat/ChatMessageDisplay.tsx
@@ -1,4 +1,4 @@
-import React, { useRef, useEffect, useState, useCallback } from 'react';
+import React, { useRef, useEffect, useState, useCallback } from 'react';
import { Check, ChevronDown, ChevronUp, Copy, FileCode, FileText, Loader2, Pencil, RotateCcw } from "lucide-react";
import ReactMarkdown from "react-markdown";
import remarkGfm from 'remark-gfm';
diff --git a/src/workspaces/ppt/chat/ChatPanel.tsx b/src/workspaces/ppt/chat/ChatPanel.tsx
index c53621a..c40af67 100644
--- a/src/workspaces/ppt/chat/ChatPanel.tsx
+++ b/src/workspaces/ppt/chat/ChatPanel.tsx
@@ -1,4 +1,4 @@
-import React, { useState, useRef, useEffect } from 'react';
+import { useState, useRef, useEffect } from 'react';
import { PanelRightClose, PanelRightOpen } from 'lucide-react';
import { cn } from '@/shared/lib/utils';
import { streamChatMessage, generateChatMessage, generatePptProxyChatMessage, ChatMessage, getAIConfig } from '@/ai/client';
diff --git a/src/workspaces/ppt/chat/code-block.tsx b/src/workspaces/ppt/chat/code-block.tsx
index 82c957f..98b05d7 100644
--- a/src/workspaces/ppt/chat/code-block.tsx
+++ b/src/workspaces/ppt/chat/code-block.tsx
@@ -1,4 +1,4 @@
-import React, { useMemo, useRef, useState } from 'react';
+import { useMemo, useRef, useState } from 'react';
import { Highlight, themes, type Language } from "prism-react-renderer";
import { ChevronRight, Loader2 } from 'lucide-react';
import { cn } from '@/shared/lib/utils';
diff --git a/src/workspaces/ppt/workspace/PptWorkspace.tsx b/src/workspaces/ppt/workspace/PptWorkspace.tsx
index e8d0cbc..3d22cc3 100644
--- a/src/workspaces/ppt/workspace/PptWorkspace.tsx
+++ b/src/workspaces/ppt/workspace/PptWorkspace.tsx
@@ -379,7 +379,7 @@ export function PptWorkspace({
startY: number;
}>(null);
const reviewPanelResizeRef = useRef<null | { startClientX: number; startWidth: number }>(null);
- const reviewLayerPromiseRef = useRef<Record<string, Promise<{ versionId: string; imageUrl: string; layer: SlideRenderLayer } | null>>>({});
+ const reviewLayerPromiseRef = useRef<Record<string, Promise<{ versionId: string; imageUrl: string; layer: SlideRenderLayer } | null> | undefined>>({});
const [materialPreview, setMaterialPreview] = useState<{ open: boolean; slideTitle: string; item: SlideMaterialImage | null }>({
open: false,
slideTitle: "",
@@ -3644,7 +3644,7 @@ export function PptWorkspace({
status: "completed",
};
if (!versionId || !imageUrl) return basePage;
- let layer = renderLayers[slide.id]?.[versionId];
+ let layer: SlideRenderLayer | undefined = renderLayers[slide.id]?.[versionId];
if (!hasRenderableTextBlocks(layer)) {
layer = (await ensureEditableReviewLayer(slide))?.layer;
}
diff --git a/tsconfig.json b/tsconfig.json
index 3ef2d3f..3042cb5 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -16,8 +16,8 @@
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
- "strict": false,
- "noUnusedLocals": false,
+ "strict": true,
+ "noUnusedLocals": true,
"noUnusedParameters": false,
"noFallthroughCasesInSwitch": false,
"noUncheckedSideEffectImports": false,
diff --git a/vite.config.ts b/vite.config.ts
index 03563a2..648ccc1 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -130,10 +130,42 @@ export default defineConfig({
},
build: {
sourcemap: 'hidden',
+ rollupOptions: {
+ output: {
+ // Split by package rather than by named entry point: the object
+ // form of manualChunks makes each listed package a chunk entry, which
+ // let Vite's own preload helper get hoisted into a vendor chunk and
+ // pulled into the initial load. Returning undefined leaves placement
+ // to Rollup, which keeps the helper with the entry.
+ manualChunks(id: string) {
+ // Vite's dynamic-import preload helper is a virtual module every
+ // lazy chunk needs. Left to Rollup it landed in the PowerPoint
+ // chunk, which made the entry preload 800 kB to reach it.
+ if (id.includes("vite/preload-helper")) return "vendor-react"
+ if (!id.includes("node_modules")) return
+ const match = /node_modules[\\\/](?:(@[^\\\/]+)[\\\/])?([^\\\/]+)/.exec(id)
+ const pkg = match ? `${match[1] ? `${match[1]}/` : ""}${match[2]}` : ""
+ if (pkg === "react" || pkg === "react-dom" || pkg === "scheduler") return "vendor-react"
+ if (pkg === "pptxgenjs" || pkg === "pdf-lib") return "vendor-office"
+ if (pkg === "jszip" || pkg === "pako") return "vendor-zip"
+ if (pkg === "mammoth") return "vendor-docs"
+ if (pkg === "react-markdown" || pkg === "remark-gfm" || pkg === "prism-react-renderer") {
+ return "vendor-markdown"
+ }
+ if (pkg === "react-drawio") return "vendor-drawio"
+ if (pkg === "ai" || pkg.startsWith("@ai-sdk/") || pkg === "openai") return "vendor-ai"
+ if (pkg === "lucide-react" || pkg === "motion" || pkg === "framer-motion" || pkg === "sonner") {
+ return "vendor-ui"
+ }
+ if (pkg.startsWith("@radix-ui/")) return "vendor-radix"
+ return
+ },
+ },
+ },
},
plugins: [
createLocalApiPlugin(),
react(),
- tsconfigPaths()
+ tsconfigPaths({ projects: ['./tsconfig.json'] })
],
})