release: improve rendering architecture and dark mode

This commit is contained in:
Formsmith
2026-07-28 14:52:59 +03:00
parent 33671c1aae
commit edbb11c97d
32 changed files with 3944 additions and 310 deletions
+33
View File
@@ -0,0 +1,33 @@
import { describe, expect, it } from "vitest";
import {
APP_THEME_STORAGE_KEY,
normalizeAppThemePreference,
readStoredAppTheme,
resolveAppTheme,
storeAppTheme,
} from "@/lib/appTheme";
describe("application theme preference", () => {
it("normalizes stored values and resolves the system theme", () => {
expect(normalizeAppThemePreference("light")).toBe("light");
expect(normalizeAppThemePreference("dark")).toBe("dark");
expect(normalizeAppThemePreference("unexpected")).toBe("system");
expect(resolveAppTheme("system", true)).toBe("dark");
expect(resolveAppTheme("system", false)).toBe("light");
expect(resolveAppTheme("light", true)).toBe("light");
});
it("persists the selected preference and safely falls back for invalid storage", () => {
const values = new Map<string, string>();
const storage = {
getItem: (key: string) => values.get(key) ?? null,
setItem: (key: string, value: string) => values.set(key, value),
};
storeAppTheme(storage, "dark");
expect(values.get(APP_THEME_STORAGE_KEY)).toBe("dark");
expect(readStoredAppTheme(storage)).toBe("dark");
values.set(APP_THEME_STORAGE_KEY, "neon");
expect(readStoredAppTheme(storage)).toBe("system");
});
});
+46
View File
@@ -3,9 +3,13 @@ import {
CAD_MODIFIER_MAX_SHARP_ANGLE,
CAD_MODIFIER_REQUEST_TIMEOUT_MS,
CAD_MODIFIER_RUNTIME_BASE,
cadModifierTopologyEdgeIsSelectable,
cadTransformRequiresGeneralTransform,
cadModifierTimeoutMessage,
defaultCadModifierTangentChain,
edgeModifierSelectionStatus,
isCadModifierWasmMemoryFault,
selectableCadModifierEdge,
} from "@/lib/cadModifierRuntime";
describe("CAD modifier runtime state", () => {
@@ -34,5 +38,47 @@ describe("CAD modifier runtime state", () => {
expect(isCadModifierWasmMemoryFault("toBREP: Out of bounds memory access (evaluating 'func(...args)')")).toBe(true);
expect(isCadModifierWasmMemoryFault("Unreachable code reached", "RuntimeError")).toBe(true);
expect(isCadModifierWasmMemoryFault("The selected edges cannot be filleted together", "Error")).toBe(false);
expect(isCadModifierWasmMemoryFault("fillet: [object WebAssembly.Exception]", "OcctError")).toBe(false);
expect(isCadModifierWasmMemoryFault("fillet: wasm exception", "OcctError")).toBe(false);
});
it("routes rotated non-uniform resize transforms through OCCT's general transform", () => {
const angle = Math.PI / 4;
const cosine = Math.cos(angle);
const sine = Math.sin(angle);
const rotatedNonUniformResize = [
2 * cosine, 0, 2 * sine, 12,
0, 1, 0, 4,
-sine, 0, cosine, -8,
];
const rigidRotation = [
cosine, 0, sine, 12,
0, 1, 0, 4,
-sine, 0, cosine, -8,
];
expect(cadTransformRequiresGeneralTransform(rotatedNonUniformResize)).toBe(true);
expect(cadTransformRequiresGeneralTransform(rigidRotation)).toBe(false);
});
it("does not auto-chain newly created edges after an applied edge treatment", () => {
expect(defaultCadModifierTangentChain(0)).toBe(true);
expect(defaultCadModifierTangentChain(1)).toBe(false);
expect(defaultCadModifierTangentChain(2)).toBe(false);
});
it("keeps valid post-treatment edges selectable when normal outline display suppresses them", () => {
const hiddenDetailEdge = {
display: false,
selectable: true,
manifold: true,
boundary: false,
angle: 45,
points: [0, 0, 0, 1, 0, 0],
};
expect(cadModifierTopologyEdgeIsSelectable(hiddenDetailEdge)).toBe(true);
expect(selectableCadModifierEdge(hiddenDetailEdge, 25)).toBe(true);
expect(selectableCadModifierEdge(hiddenDetailEdge, 60)).toBe(false);
});
});
+51 -6
View File
@@ -61,17 +61,52 @@ describe("editor history snapshots", () => {
expect(projectShapesFingerprint([changed])).not.toBe(projectShapesFingerprint([shape]));
});
it("bounds entry count and estimated memory while retaining undo depth", () => {
it("reuses an immutable mesh signature for transform-only history snapshots", () => {
let coordinateReads = 0;
const positions = new Proxy([0, 0, 0, 1, 0, 0, 0, 1, 0], {
get(target, property, receiver) {
if (typeof property === "string" && /^\d+$/.test(property)) coordinateReads += 1;
return Reflect.get(target, property, receiver);
},
});
const shape = box({
kind: "mesh",
importedMesh: {
positions,
baseWidth: 1,
baseDepth: 1,
baseHeight: 1,
triangleCount: 1,
sourceFormat: "stl",
},
});
const baseline = projectShapesFingerprint([shape]);
expect(coordinateReads).toBeGreaterThan(0);
coordinateReads = 0;
expect(projectShapesFingerprint([{ ...shape, x: 25 }])).not.toBe(baseline);
expect(coordinateReads).toBe(0);
expect(projectShapesFingerprint([{
...shape,
importedMesh: { ...shape.importedMesh!, positions: [...positions] },
}])).toBe(baseline);
});
it("keeps unlimited history and applies preset or custom action limits", () => {
const entries = Array.from({ length: 140 }, (_, index) => ({
...editorHistoryEntry([box({ id: `box-${index}`, x: index })], []),
estimatedBytes: 2 * 1024 * 1024,
}));
const bounded = boundedEditorHistory(entries);
const unlimited = boundedEditorHistory(entries);
const lastThirty = boundedEditorHistory(entries, 30);
const custom = boundedEditorHistory(entries, 7);
expect(bounded.length).toBeLessThanOrEqual(100);
expect(bounded.length).toBeGreaterThanOrEqual(2);
expect(bounded.reduce((total, entry) => total + entry.estimatedBytes, 0)).toBeLessThanOrEqual(64 * 1024 * 1024);
expect(bounded.at(-1)?.shapes[0].id).toBe("box-139");
expect(unlimited).toHaveLength(140);
expect(lastThirty).toHaveLength(31);
expect(lastThirty[0].shapes[0].id).toBe("box-109");
expect(custom).toHaveLength(8);
expect(custom.at(-1)?.shapes[0].id).toBe("box-139");
});
it("trims redo only for a real new edit and preserves it for a no-op", () => {
@@ -99,6 +134,16 @@ describe("editor history snapshots", () => {
expect(restored.entries[2].shapes[0].x).toBe(10);
});
it("restores only the configured number of saved actions without losing the active state", () => {
const entries = Array.from({ length: 80 }, (_, x) => editorHistoryEntry([box({ x })], []));
const restored = hydrateEditorHistoryState([box({ x: 60 })], entries, 60, 30);
expect(restored.entries).toHaveLength(31);
expect(restored.index).toBe(30);
expect(restored.entries[0].shapes[0].x).toBe(30);
expect(restored.entries[restored.index].shapes[0].x).toBe(60);
});
it("falls back to the loaded scene when persisted history is stale", () => {
const stale = [editorHistoryEntry([box({ x: 1 })], [])];
const restored = hydrateEditorHistoryState([box({ x: 9 })], stale, 0);
+9 -7
View File
@@ -54,17 +54,17 @@ function groupedShape(): WorkplaneShape {
}
describe("Snap to Grid", () => {
it("translates a group footprint to the visible grid without resizing it or changing child offsets", () => {
it("snaps the nearest footprint corner to the visible grid without resizing or changing child offsets", () => {
const group = groupedShape();
const snapped = snapShapeFootprintToVisibleGrid(
group,
{ minX: -17.3, minZ: -11.4 },
{ minX: -17.3, maxX: 26.2, minZ: -11.4, maxZ: 8.4 },
{ ...DEFAULT_WORKPLANE_WORKSPACE, gridBlockSize: 5 },
);
expect(snapped.x).toBe(5.5);
expect(snapped.x).toBe(2);
expect(snapped.z).toBe(-0.3);
expect(-17.3 + snapped.x - group.x).toBeCloseTo(-15, 6);
expect(26.2 + snapped.x - group.x).toBeCloseTo(25, 6);
expect(-11.4 + snapped.z - group.z).toBeCloseTo(-10, 6);
expect(snapped).toMatchObject({
elevation: 2.4,
@@ -80,11 +80,13 @@ describe("Snap to Grid", () => {
const group = groupedShape();
const snapped = snapShapeFootprintToVisibleGrid(
group,
{ minX: -18, minZ: -13 },
{ minX: -18, maxX: 25.5, minZ: -13, maxZ: 6.8 },
{ ...DEFAULT_WORKPLANE_WORKSPACE, width: 203, depth: 187, gridBlockSize: 10 },
);
expect(-18 + snapped.x - group.x).toBeCloseTo(-21.5, 6);
expect(-13 + snapped.z - group.z).toBeCloseTo(-13.5, 6);
expect(snapped.x).toBeCloseTo(6.2, 6);
expect(snapped.z).toBeCloseTo(-2, 6);
expect(25.5 + snapped.x - group.x).toBeCloseTo(28.5, 6);
expect(6.8 + snapped.z - group.z).toBeCloseTo(6.5, 6);
});
});
@@ -0,0 +1,70 @@
import { describe, expect, it } from "vitest";
import { editorHistoryEntry } from "@/lib/editorHistory";
import { compactProjectShapeState, hydrateProjectShapeState } from "@/lib/projectShapePersistence";
import type { WorkplaneShape } from "@/types/sketchforge";
function importedShape(): WorkplaneShape {
return {
id: "mesh-1",
name: "Imported mesh",
kind: "mesh",
color: "#d41721",
x: 0,
z: 0,
elevation: 0,
size: 10,
width: 10,
depth: 10,
height: 10,
rotation: 0,
importedMesh: {
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: "stl",
},
};
}
describe("project shape persistence resources", () => {
it("stores one immutable mesh resource across current shapes and history", () => {
const mesh = importedShape();
const group: WorkplaneShape = {
...mesh,
id: "group-1",
name: "Group",
importedMesh: undefined,
groupedShapes: [mesh],
groupedBaseWidth: 10,
groupedBaseDepth: 10,
groupedBaseHeight: 10,
groupOperation: "group",
};
const history = [
editorHistoryEntry([{ ...group, x: 0 }], []),
editorHistoryEntry([{ ...group, x: 5 }], [group.id]),
];
const compact = compactProjectShapeState([{ ...group, x: 5 }], history);
const currentStub = compact.shapes[0].groupedShapes?.[0].importedMesh;
const historyStub = compact.history[0].shapes[0].groupedShapes?.[0].importedMesh;
expect(compact.resources.size).toBe(1);
expect(currentStub?.positions).toEqual([]);
expect(currentStub?.normals).toBeUndefined();
expect(currentStub?.storageResourceId).toBeTruthy();
expect(historyStub?.storageResourceId).toBe(currentStub?.storageResourceId);
const hydrated = hydrateProjectShapeState(compact.shapes, compact.history, compact.resources);
const currentMesh = hydrated.shapes[0].groupedShapes?.[0].importedMesh;
const historyMesh = hydrated.history?.[0].shapes[0].groupedShapes?.[0].importedMesh;
expect(currentMesh?.positions).toEqual(mesh.importedMesh?.positions);
expect(currentMesh?.normals).toEqual(mesh.importedMesh?.normals);
expect(currentMesh?.storageResourceId).toBeUndefined();
expect(historyMesh).toBe(currentMesh);
});
});
+177
View File
@@ -0,0 +1,177 @@
import { describe, expect, it } from "vitest";
import * as THREE from "three";
import { bakedBoxSelectionFrame, bakeCadMetadataForShapeTransform } from "@/lib/cadBakeMetadata";
import { exportSkfProject, importSkfProject } from "@/lib/skfProject";
import { DEFAULT_SNAP_GRID, DEFAULT_WORKPLANE_WORKSPACE } from "@/lib/workplaneSettings";
import type { WorkplaneShape } from "@/types/sketchforge";
function cube(): WorkplaneShape {
return {
id: "cube",
name: "Cube",
kind: "box",
color: "#d41721",
x: 0,
z: 0,
elevation: 0,
size: 20,
width: 20,
depth: 20,
height: 20,
rotation: 0,
rotationX: 0,
rotationZ: 0,
};
}
function inverseRotationPatch(shape: Pick<WorkplaneShape, "rotation" | "rotationX" | "rotationZ">) {
const quaternion = new THREE.Quaternion().setFromEuler(new THREE.Euler(
THREE.MathUtils.degToRad(shape.rotationX ?? 0),
THREE.MathUtils.degToRad(shape.rotation),
THREE.MathUtils.degToRad(shape.rotationZ ?? 0),
"XYZ",
));
const inverse = new THREE.Euler().setFromQuaternion(quaternion.invert(), "XYZ");
return {
rotationX: THREE.MathUtils.radToDeg(inverse.x),
rotation: THREE.MathUtils.radToDeg(inverse.y),
rotationZ: THREE.MathUtils.radToDeg(inverse.z),
};
}
const cubeTriangles = [
0, 2, 1, 0, 3, 2,
4, 5, 6, 4, 6, 7,
0, 1, 5, 0, 5, 4,
1, 2, 6, 1, 6, 5,
2, 3, 7, 2, 7, 6,
3, 0, 4, 3, 4, 7,
];
function primitiveCubePositions() {
const vertices = [
[-10, 0, -10], [10, 0, -10], [10, 0, 10], [-10, 0, 10],
[-10, 20, -10], [10, 20, -10], [10, 20, 10], [-10, 20, 10],
];
return cubeTriangles.flatMap((index) => vertices[index]);
}
function bake(shape: WorkplaneShape, rotation: Pick<WorkplaneShape, "rotation" | "rotationX" | "rotationZ">) {
const source = shape.importedMesh?.positions ?? primitiveCubePositions();
const sourceWidth = shape.importedMesh?.baseWidth ?? shape.width;
const sourceDepth = shape.importedMesh?.baseDepth ?? shape.depth;
const sourceHeight = shape.importedMesh?.baseHeight ?? shape.height;
const matrix = new THREE.Matrix4().makeRotationFromEuler(new THREE.Euler(
THREE.MathUtils.degToRad(rotation.rotationX ?? 0),
THREE.MathUtils.degToRad(rotation.rotation),
THREE.MathUtils.degToRad(rotation.rotationZ ?? 0),
"XYZ",
));
const centerY = shape.height / 2;
const world = Array.from({ length: source.length / 3 }, (_, index) => new THREE.Vector3(
source[index * 3] * shape.width / sourceWidth,
source[index * 3 + 1] * shape.height / sourceHeight - centerY,
source[index * 3 + 2] * shape.depth / sourceDepth,
).applyMatrix4(matrix).add(new THREE.Vector3(shape.x, (shape.elevation ?? 0) + centerY, shape.z)));
const bounds = new THREE.Box3().setFromPoints(world);
const center = bounds.getCenter(new THREE.Vector3());
const size = bounds.getSize(new THREE.Vector3());
const positions = world.flatMap((point) => [point.x - center.x, point.y - bounds.min.y, point.z - center.z]);
const cadMetadata = bakeCadMetadataForShapeTransform(
{ ...shape, ...rotation },
{
centerX: center.x,
minY: bounds.min.y,
centerZ: center.z,
width: size.x,
depth: size.z,
height: size.y,
yawDegrees: rotation.rotation,
},
);
return {
...shape,
kind: "mesh" as const,
x: center.x,
z: center.z,
elevation: bounds.min.y,
size: Math.max(size.x, size.z),
width: size.x,
depth: size.z,
height: size.y,
rotation: 0,
rotationX: 0,
rotationZ: 0,
importedMesh: {
positions,
baseWidth: size.x,
baseDepth: size.z,
baseHeight: size.y,
triangleCount: positions.length / 9,
sourceFormat: "json" as const,
},
...cadMetadata,
};
}
function expectAxisAlignedCube(shape: WorkplaneShape) {
const positions = shape.importedMesh?.positions ?? [];
expect(positions.length).toBeGreaterThan(0);
const coordinates = [0, 1, 2].map((axis) =>
[...new Set(Array.from({ length: positions.length / 3 }, (_, index) => Number(positions[index * 3 + axis].toFixed(5))))].sort((a, b) => a - b),
);
coordinates.forEach((axisValues) => expect(axisValues).toHaveLength(2));
}
describe("selection outline after project reopen", () => {
it("restores the exact oriented box frame for a baked cube", async () => {
const rotated = bake(cube(), { rotationX: 31, rotation: 47, rotationZ: 19 });
const bytes = await exportSkfProject({
projectId: "oriented-selection-outline-project",
projectName: "Oriented selection outline",
createdAt: 1_700_000_000_000,
modifiedAt: 1_700_000_000_100,
shapes: [rotated],
assets: [],
workspace: DEFAULT_WORKPLANE_WORKSPACE,
snapGrid: DEFAULT_SNAP_GRID,
placementElevation: 0,
});
const restored = await importSkfProject(bytes);
const frame = bakedBoxSelectionFrame(restored.shapes[0]);
expect(frame).not.toBeNull();
expect(Math.abs(frame?.xAxis.x ?? 1)).toBeLessThan(0.99);
expect(frame?.width).toBeCloseTo(20, 5);
expect(frame?.height).toBeCloseTo(20, 5);
expect(frame?.depth).toBeCloseTo(20, 5);
});
it("keeps a cube axis-aligned after rotating it away and back, then round-tripping the project", async () => {
const firstRotation = { rotationX: 31, rotation: 47, rotationZ: 19 };
const rotated = bake(cube(), firstRotation);
const returned = bake(rotated, inverseRotationPatch(firstRotation));
expectAxisAlignedCube(returned);
const bytes = await exportSkfProject({
projectId: "selection-outline-project",
projectName: "Selection outline",
createdAt: 1_700_000_000_000,
modifiedAt: 1_700_000_000_100,
shapes: [returned],
assets: [],
workspace: DEFAULT_WORKPLANE_WORKSPACE,
snapGrid: DEFAULT_SNAP_GRID,
placementElevation: 0,
});
const restored = await importSkfProject(bytes);
expectAxisAlignedCube(restored.shapes[0]);
const frame = bakedBoxSelectionFrame(restored.shapes[0]);
expect(frame?.xAxis.x).toBeCloseTo(1, 5);
expect(frame?.yAxis.y).toBeCloseTo(1, 5);
expect(frame?.zAxis.z).toBeCloseTo(1, 5);
expect(restored.shapes[0].rotation).toBe(0);
expect(restored.shapes[0].rotationX).toBe(0);
expect(restored.shapes[0].rotationZ).toBe(0);
});
});
+49
View File
@@ -5,6 +5,7 @@ import {
cadModifierPrimitiveForAnalyticBox,
cadModifierPrimitiveForBakedShape,
} from "@/lib/cadBakeMetadata";
import { cadTransformRequiresGeneralTransform } from "@/lib/cadModifierRuntime";
import type { WorkplaneShape } from "@/types/sketchforge";
function expectTransformClose(actual: number[] | undefined, expected: number[]) {
@@ -185,4 +186,52 @@ describe("SketchForge transform baking", () => {
});
expectTransformClose(restoredPrimitive?.transform, directPrimitive?.transform ?? []);
});
it("uses a general CAD transform after resizing a baked rotated box", () => {
const shape = boxShape({
x: 0,
z: 0,
elevation: 0,
width: 20,
depth: 20,
height: 20,
rotation: 45,
rotationX: 0,
rotationZ: 0,
});
const diagonal = Math.sqrt(20 ** 2 + 20 ** 2);
const baked = bakeCadMetadataForShapeTransform(shape, {
centerX: 0,
minY: 0,
centerZ: 0,
width: diagonal,
depth: diagonal,
height: 20,
yawDegrees: 45,
});
const resizedBakedShape: WorkplaneShape = {
...shape,
...baked,
kind: "mesh",
width: diagonal * 1.8,
depth: diagonal * 0.75,
height: 26,
size: diagonal * 1.8,
rotation: 0,
rotationX: 0,
rotationZ: 0,
importedMesh: {
positions: [-10, 0, -10, 10, 0, -10, 10, 20, 10],
baseWidth: diagonal,
baseDepth: diagonal,
baseHeight: 20,
triangleCount: 1,
sourceFormat: "json",
},
};
const restoredPrimitive = cadModifierPrimitiveForBakedShape(resizedBakedShape);
expect(restoredPrimitive?.transform).toBeDefined();
expect(cadTransformRequiresGeneralTransform(restoredPrimitive?.transform ?? [])).toBe(true);
});
});
+27 -2
View File
@@ -104,7 +104,8 @@ describe("SketchForge .skf project packages", () => {
} : undefined,
}));
const exported = await exportSkfProject(input(shapes));
const customWorkspace = { ...DEFAULT_WORKPLANE_WORKSPACE, gridColor: "#a34fd1" };
const exported = await exportSkfProject(input(shapes, { workspace: customWorkspace }));
const { document } = packageDocument(exported);
const summary = await inspectSkfProjectPackage(exported);
const restored = await importSkfProject(exported);
@@ -112,7 +113,7 @@ describe("SketchForge .skf project packages", () => {
expect(restored.projectName).toBe("Round trip");
expect(restored.sourceProjectId).toBe("project-original");
expect(JSON.stringify(restored.shapes)).toBe(JSON.stringify(shapes.map(canonicalizeShape)));
expect(restored.workspace).toEqual(DEFAULT_WORKPLANE_WORKSPACE);
expect(restored.workspace).toEqual(customWorkspace);
expect(restored.snapGrid).toBe(DEFAULT_SNAP_GRID);
expect(restored.placementElevation).toBe(12.5);
expect(summary).toEqual({
@@ -200,6 +201,30 @@ describe("SketchForge .skf project packages", () => {
expect(restored.shapes[0].edgeTreatmentHistory?.[0].before.kind).toBe("box");
});
it("preserves every silently packaged undo and redo action", async () => {
const created = shape("box", "history-box", { width: 20, depth: 20, x: 0 });
const resized = { ...created, width: 30 };
const moved = { ...resized, x: 18 };
const history = [
editorHistoryEntry([created], ["history-box"]),
editorHistoryEntry([resized], ["history-box"]),
editorHistoryEntry([moved], ["history-box"]),
];
const restored = await importSkfProject(await exportSkfProject(input([resized], {
history,
historyIndex: 1,
compressionLevel: 1,
})));
expect(restored.history).toHaveLength(3);
expect(restored.historyIndex).toBe(1);
expect(restored.history[0].shapes[0]).toMatchObject({ width: 20, x: 0 });
expect(restored.history[1].shapes[0]).toMatchObject({ width: 30, x: 0 });
expect(restored.history[2].shapes[0]).toMatchObject({ width: 30, x: 18 });
expect(restored.shapes[0]).toMatchObject({ width: 30, x: 0 });
});
it("stores one original source asset for repeated imported instances and regenerates it once", async () => {
const sourceBytes = strToU8("solid source");
const asset = await projectAssetFromBytes("shared.stl", "stl", sourceBytes);
+23 -1
View File
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
import { interiorWorkplaneGridCoordinates, workplaneGridPalette, WORKPLANE_LINE_ELEVATION, WORKPLANE_MAJOR_GRID_INTERVAL } from "@/lib/workplaneGrid";
import { interiorWorkplaneGridCoordinates, workplaneGridPalette, workplaneThemePalette, WORKPLANE_LINE_ELEVATION, WORKPLANE_MAJOR_GRID_INTERVAL } from "@/lib/workplaneGrid";
describe("workplane grid geometry", () => {
it("excludes both perimeter coordinates when spacing divides the workplane", () => {
@@ -33,4 +33,26 @@ describe("workplane grid geometry", () => {
expect(palette.major.opacity).toBeLessThan(palette.axis.opacity);
expect(palette.minor.color).not.toBe(palette.major.color);
});
it("uses a complete dark viewport palette without changing the configured project background", () => {
const configuredBackground = "#f8fbfc";
const dark = workplaneThemePalette("dark", configuredBackground);
const light = workplaneThemePalette("light", configuredBackground);
expect(dark.sceneBackground).not.toBe(configuredBackground);
expect(dark.surface.color).not.toBe(light.surface.color);
expect(dark.grid.minor.color).not.toBe(light.grid.minor.color);
expect(light.sceneBackground).toBe(configuredBackground);
});
it("applies a custom project grid color while retaining line hierarchy", () => {
const customColor = "#c23b72";
const palette = workplaneGridPalette("light", customColor);
expect(palette.minor.color).toBe(customColor);
expect(palette.major.color).toBe(customColor);
expect(palette.axis.color).toBe(customColor);
expect(palette.minor.opacity).toBeLessThan(palette.major.opacity);
expect(palette.major.opacity).toBeLessThan(palette.axis.opacity);
});
});
+6
View File
@@ -27,6 +27,7 @@ describe("workplane settings helpers", () => {
sizePreset: "",
gridBlockSize: 2.5,
gridBlockPreset: "Custom",
gridColor: "#a34fd1",
background: "#123456",
showShadows: false,
showGrid: false,
@@ -43,6 +44,7 @@ describe("workplane settings helpers", () => {
width: 500,
gridBlockSize: 2.5,
gridBlockPreset: "Custom",
gridColor: "#a34fd1",
background: "#123456",
showShadows: false,
showGrid: false,
@@ -53,6 +55,10 @@ describe("workplane settings helpers", () => {
});
expect(normalizeWorkspaceSettings({ accuracy: 9 }, fallback).accuracy).toBe(fallback.accuracy);
expect(normalizeWorkspaceSettings({ historyLimit: 73 }).historyLimit).toBe(73);
expect(normalizeWorkspaceSettings({ historyLimit: 9000 }).historyLimit).toBe(5000);
expect(normalizeWorkspaceSettings({ historyLimit: "invalid" }).historyLimit).toBe("unlimited");
expect(normalizeWorkspaceSettings({ gridColor: "not-a-color" }).gridColor).toBe(DEFAULT_WORKPLANE_WORKSPACE.gridColor);
});
it("keeps scale options in the selected unit family", () => {