From 2486b998c8c1fbcccf97458be0f793b5a6cfa4b7 Mon Sep 17 00:00:00 2001 From: Formsmith746 <214276465+Formsmith746@users.noreply.github.com> Date: Mon, 24 Aug 2026 12:55:20 +0300 Subject: [PATCH] release: SketchForge 1.0.7 --- README.md | 2 +- apps/web/src/app/page.tsx | 4 +++- apps/web/src/lib/skfProject.ts | 23 ++++++++++++++------ docs/CHANGELOG.md | 6 ++++++ docs/SKF_PROJECT_FORMAT.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- tests/unit/skfProject.test.ts | 39 ++++++++++++++++++++++++++++++++++ 8 files changed, 70 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2b1c5a1..9460147 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Star SketchForge on GitHub Sponsor SketchForge on GitHub Local first - Version v1.0.6 + Version v1.0.7

diff --git a/apps/web/src/app/page.tsx b/apps/web/src/app/page.tsx index 8f5b807..98e6b15 100644 --- a/apps/web/src/app/page.tsx +++ b/apps/web/src/app/page.tsx @@ -918,6 +918,9 @@ export default function Home() { )}:${project.placementElevation ?? 0}:${placementWorkplaneFingerprint(normalizePlacementWorkplane(project.placementWorkplane, project.placementElevation))}:${placementWorkplaneFingerprint(normalizePlacementWorkplane(project.sketchPlacementWorkplane))}`; if (currentFingerprint === nextFingerprint) return project; changed = true; + // `revision` tracks the IndexedDB shape snapshot. Advancing it for a + // workspace-only change can make the loader replace newer live shapes + // with an older persisted snapshot while autosave is still pending. return { ...project, workspace, @@ -926,7 +929,6 @@ export default function Home() { placementWorkplane, sketchPlacementWorkplane, updatedAt: version, - revision: version, }; }); if (!changed) return current; diff --git a/apps/web/src/lib/skfProject.ts b/apps/web/src/lib/skfProject.ts index 5d7fe0a..2889e39 100644 --- a/apps/web/src/lib/skfProject.ts +++ b/apps/web/src/lib/skfProject.ts @@ -12,13 +12,13 @@ import type { GridSize, ProjectAsset, ProjectAssetSourceFormat, SketchOperation, export const SKF_SCHEMA_ID = "com.sketchforge.project"; export const SKF_FORMAT_VERSION = 1; export const SKF_MINIMUM_READER_VERSION = 1; -export const SKF_CREATED_WITH_VERSION = "1.0.6"; +export const SKF_CREATED_WITH_VERSION = "1.0.7"; export const SKF_MEDIA_TYPE = "application/vnd.sketchforge.project+zip"; export const SKF_LIMITS = { archiveBytes: 512 * 1024 * 1024, expandedBytes: 1024 * 1024 * 1024, - projectJsonBytes: 32 * 1024 * 1024, + projectJsonBytes: 64 * 1024 * 1024, assetBytes: 256 * 1024 * 1024, entries: 4096, states: 5001, @@ -751,7 +751,11 @@ export async function exportSkfProject(input: SkfProjectExportInput) { sketchPlacementWorkplane, }, }; - builder.files["project.json"] = strToU8(`${JSON.stringify(document, null, 2)}\n`); + const projectJson = strToU8(JSON.stringify(document)); + if (projectJson.byteLength > SKF_LIMITS.projectJsonBytes) { + throw new Error("Project data exceeds the 64 MB .skf limit. Export with fewer history steps or simplify the project."); + } + builder.files["project.json"] = projectJson; return zipAsync(Object.fromEntries(Object.entries(builder.files).sort(([a], [b]) => a.localeCompare(b))), input.compressionLevel); } @@ -1064,6 +1068,7 @@ async function restoreShapeFromNode( files: ArchiveFiles, runtimeAssetByArchiveId: Map, sourceMeshCache: Map>>, + derivedMeshCache: Map>, sourceImporter: SkfSourceImporter, restoring = new Set(), ): Promise { @@ -1106,7 +1111,11 @@ async function restoreShapeFromNode( } else if (node.importedMesh?.meshAssetId) { const meshRecord = assetById.get(node.importedMesh.meshAssetId); if (!meshRecord) throw new Error(`Object '${node.objectId}' is missing its derived mesh`); - const decoded = decodeMeshCache(files[meshRecord.path]); + let decoded = derivedMeshCache.get(meshRecord.id); + if (!decoded) { + decoded = decodeMeshCache(files[meshRecord.path]); + derivedMeshCache.set(meshRecord.id, decoded); + } const brepRecord = node.importedMesh.brepStepAssetId ? assetById.get(node.importedMesh.brepStepAssetId) : undefined; importedMesh = { ...decoded, @@ -1120,14 +1129,14 @@ async function restoreShapeFromNode( } const groupedShapes = node.groupedShapeNodeIds?.length - ? await Promise.all(node.groupedShapeNodeIds.map((childId) => restoreShapeFromNode(childId, nodeById, assetById, files, runtimeAssetByArchiveId, sourceMeshCache, sourceImporter, new Set(restoring)))) + ? await Promise.all(node.groupedShapeNodeIds.map((childId) => restoreShapeFromNode(childId, nodeById, assetById, files, runtimeAssetByArchiveId, sourceMeshCache, derivedMeshCache, sourceImporter, new Set(restoring)))) : undefined; const edgeTreatmentHistory = node.edgeTreatmentHistory?.length ? await Promise.all(node.edgeTreatmentHistory.map(async (entry) => ({ id: entry.id, createdAt: entry.createdAt, feature: entry.feature as NonNullable[number]["feature"], - before: await restoreShapeFromNode(entry.beforeNodeId, nodeById, assetById, files, runtimeAssetByArchiveId, sourceMeshCache, sourceImporter, new Set(restoring)), + before: await restoreShapeFromNode(entry.beforeNodeId, nodeById, assetById, files, runtimeAssetByArchiveId, sourceMeshCache, derivedMeshCache, sourceImporter, new Set(restoring)), ...(entry.appliedFrame ? { appliedFrame: entry.appliedFrame as NonNullable[number]["appliedFrame"] } : {}), }))) : undefined; @@ -1158,6 +1167,7 @@ async function restoreV1(document: SkfProjectDocumentV1, assetById: Map>>(); + const derivedMeshCache = new Map>(); const sourceImporter = options.sourceImporter ?? defaultSourceImporter; const restoredStates = new Map(); for (const state of document.states) { @@ -1169,6 +1179,7 @@ async function restoreV1(document: SkfProjectDocumentV1, assetById: Map { expect(restored.shapes[0].importedMesh?.assetId).toBe(restored.assets[0].id); }); + it("shares decoded derived-mesh arrays across restored history states", async () => { + const importedMesh: NonNullable = { + positions: [0, 0, 0, 1, 0, 0, 0, 1, 0], + normals: [0, 0, 1, 0, 0, 1, 0, 0, 1], + baseWidth: 1, + baseDepth: 1, + baseHeight: 1, + triangleCount: 1, + sourceFormat: "json", + }; + const before = shape("mesh", "derived-history", { importedMesh, x: 0 }); + const after = { ...before, x: 20 }; + const history = [editorHistoryEntry([before], []), editorHistoryEntry([after], [after.id])]; + + const restored = await importSkfProject(await exportSkfProject(input([after], { history, historyIndex: 1 }))); + const firstPositions = restored.history[0].shapes[0].importedMesh?.positions; + const secondPositions = restored.history[1].shapes[0].importedMesh?.positions; + + expect(firstPositions).toBe(secondPositions); + expect(restored.shapes[0].importedMesh?.positions).toBe(secondPositions); + }); + it.each(["svg", "step"] as const)("stores and restores original %s sources", async (sourceFormat) => { const asset = await projectAssetFromBytes(`source.${sourceFormat}`, sourceFormat, strToU8(`${sourceFormat} source`)); const importedMesh: NonNullable = { @@ -429,6 +452,22 @@ describe("SketchForge .skf project packages", () => { } }); + it("writes compact project data that stays compatible with the reader limit", async () => { + const exported = await exportSkfProject(input([shape("box")])); + const { files, document } = packageDocument(exported); + const projectJson = strFromU8(files["project.json"]); + + expect(projectJson).toBe(JSON.stringify(document)); + await expect(importSkfProject(exported)).resolves.toMatchObject({ projectName: "Round trip" }); + }); + + it("refuses to create an .skf package that its reader cannot reopen", async () => { + const oversizedName = "x".repeat(SKF_LIMITS.projectJsonBytes); + + await expect(exportSkfProject(input([shape("box")], { projectName: oversizedName }))) + .rejects.toThrow("Project data exceeds the 64 MB .skf limit"); + }); + it("migrates the documented v0 JSON project without changing IDs", async () => { const box = shape("box", "legacy-box"); const legacy = strToU8(JSON.stringify({