diff --git a/.gitignore b/.gitignore index c6b403a..406f134 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ playwright-report/ # Local workspace state .codex/ +.codex-run/ .codex-remote-attachments/ # OS/editor noise diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index 574c6aa..5f057fe 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -2,7 +2,7 @@ import { Clock3, EllipsisVertical, FileUp, Grid3X3, HomeIcon, List, Pencil, Plus, Search, Settings, SlidersHorizontal, Trash2, X } from "lucide-react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react"; -import { SketchForgeEditor, importedShapeFromStl } from "@/components/SketchForgeEditor"; +import { SketchForgeEditor, importedShapeFromStl, importedShapeFromSvg } from "@/components/SketchForgeEditor"; import { createLocalId } from "@/lib/localIds"; import { importExtensionSupported } from "@/lib/stlImport"; import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE, normalizeSnapGrid, normalizeWorkspaceSettings } from "@/lib/workplaneSettings"; @@ -236,7 +236,7 @@ function newProject(name: string, index: number, shapeCount = 0): DashboardProje } function projectNameFromFileName(fileName: string) { - return fileName.replace(/\.[^.]+$/, "").trim() || "Imported STL design"; + return fileName.replace(/\.[^.]+$/, "").trim() || "Imported design"; } export default function Home() { @@ -255,7 +255,7 @@ export default function Home() { const [dashboardNotice, setDashboardNotice] = useState(""); const [projectShapesById, setProjectShapesById] = useState>({}); const projectsJsonRef = useRef(""); - const dashboardStlInputRef = useRef(null); + const dashboardImportInputRef = useRef(null); const nextProjectRevisionRef = useRef(0); const projectShapeSaveQueuesRef = useRef>>({}); @@ -513,15 +513,18 @@ export default function Home() { openEditor(project.id, { allowMissingFromStorage: true }); }; - const importStlFileFromDashboard = useCallback( + const importFileFromDashboard = useCallback( async (file: File) => { - if (!importExtensionSupported(file.name)) { - setDashboardNotice("Unsupported file type. Use STL."); + const isSvg = /\.svg$/i.test(file.name) || file.type === "image/svg+xml"; + if (!isSvg && !importExtensionSupported(file.name)) { + setDashboardNotice("Unsupported file type. Use STL or SVG."); return; } try { - const shape = importedShapeFromStl(file.name, await file.arrayBuffer()); + const shape = isSvg + ? importedShapeFromSvg(file.name, await file.text()) + : importedShapeFromStl(file.name, await file.arrayBuffer()); const project = newProject(projectNameFromFileName(file.name), projects.length, 1); const revision = project.revision ?? project.updatedAt; await saveProjectShapes(project.id, [shape], revision); @@ -608,14 +611,14 @@ export default function Home() { {JSON.stringify(projectDebugSummary)} { const file = event.currentTarget.files?.[0]; if (file) { - void importStlFileFromDashboard(file); + void importFileFromDashboard(file); } event.currentTarget.value = ""; }} @@ -637,7 +640,7 @@ export default function Home() { onDeleteProject={deleteProject} onDownloadFolderChange={setDownloadFolder} onDownloadModeChange={setDownloadMode} - onImportStl={() => dashboardStlInputRef.current?.click()} + onImportFile={() => dashboardImportInputRef.current?.click()} onChallenges={() => { setDashboardSection("challenges"); setDashboardNotice(""); @@ -688,7 +691,7 @@ function Dashboard({ onDeleteProject, onDownloadFolderChange, onDownloadModeChange, - onImportStl, + onImportFile, onChallenges, onDashboardHome, onOpenProject, @@ -714,7 +717,7 @@ function Dashboard({ onDeleteProject: (projectId: string) => void; onDownloadFolderChange: (value: string) => void; onDownloadModeChange: (value: DownloadMode) => void; - onImportStl: () => void; + onImportFile: () => void; onChallenges: () => void; onDashboardHome: () => void; onOpenProject: (projectId: string) => void; @@ -810,11 +813,11 @@ function Dashboard({ Create new 3D design - diff --git a/apps/web/src/components/WorkplaneViewport.tsx b/apps/web/src/components/WorkplaneViewport.tsx index 2e327ca..edb646d 100644 --- a/apps/web/src/components/WorkplaneViewport.tsx +++ b/apps/web/src/components/WorkplaneViewport.tsx @@ -4437,7 +4437,7 @@ function createShapeObject(shape: WorkplaneShape, showEdges = false, onTextureRe opacity: shape.hole ? (shape.importedMesh ? 0.34 : 0.52) : 1, roughness: shape.hole ? 0.88 : 0.57, metalness: 0.02, - side: shape.importedMesh?.sourceFormat === "json" || mirroredAxisCount(shape) % 2 === 1 ? THREE.DoubleSide : THREE.FrontSide, + side: shape.importedMesh?.sourceFormat === "json" || shape.importedMesh?.sourceFormat === "svg" || mirroredAxisCount(shape) % 2 === 1 ? THREE.DoubleSide : THREE.FrontSide, }); const width = shapeWidth(shape); diff --git a/apps/web/src/lib/stlImport.ts b/apps/web/src/lib/stlImport.ts index 83aa362..9e546b6 100644 --- a/apps/web/src/lib/stlImport.ts +++ b/apps/web/src/lib/stlImport.ts @@ -4,7 +4,7 @@ import { createLocalId } from "@/lib/localIds"; import type { WorkplaneShape } from "@/types/sketchforge"; const stlLoader = new STLLoader(); -const SUPPORTED_IMPORT_EXTENSIONS = new Set(["stl"]); +const SUPPORTED_IMPORT_EXTENSIONS = new Set(["stl", "svg"]); function fileExtension(fileName: string) { return fileName.split(".").pop()?.toLowerCase() ?? ""; diff --git a/tests/unit/importExtensions.test.ts b/tests/unit/importExtensions.test.ts new file mode 100644 index 0000000..627da42 --- /dev/null +++ b/tests/unit/importExtensions.test.ts @@ -0,0 +1,15 @@ +import { describe, expect, it } from "vitest"; +import { importExtensionSupported } from "@/lib/stlImport"; + +describe("importExtensionSupported", () => { + it("accepts STL and SVG imports", () => { + expect(importExtensionSupported("part.stl")).toBe(true); + expect(importExtensionSupported("logo.svg")).toBe(true); + expect(importExtensionSupported("profile.SVG")).toBe(true); + }); + + it("rejects unsupported dashboard import extensions", () => { + expect(importExtensionSupported("drawing.png")).toBe(false); + expect(importExtensionSupported("assembly.step")).toBe(false); + }); +});