Git Komut Rehberi & Terminal Asistanı
Sıfırdan Yeni Bir Depo Başlatın:
Mevcut Bir Git Deposu veya Klasörü Gönderin:
Hataları Geri Alma, İptal & Temizlik:
Son commit'i geri al (yapılan değişiklikleri korur):
git reset --soft HEAD~1
Yapılan yerel değişiklikleri iptal et (çalışma ağacını temizler):
git restore .
Takip edilmeyen gereksiz dosyaları sil:
git clean -fd
Değişiklikleri geçici sakla ve geri getir (stash):
git stash git stash pop
Dal (Branch) ve Sürüm Etiketleri:
Yeni dal aç ve geçiş yap:
git checkout -b yeni-ozellik git push -u origin yeni-ozellik
Sürüm etiketi (tag) oluştur ve gönder:
git tag -a v1.0.0 -m "Sürüm 1.0.0" git push origin --tags
149 lines
4.7 KiB
TypeScript
149 lines
4.7 KiB
TypeScript
import { z } from "zod";
|
|||
|
|
import { sceneShape } from "@/lib/shapeCatalog";
|
||
|
|
import { fallbackSolidColor } from "@/lib/workplaneShapes";
|
||
|
|
import type { ShapeKind, WorkplaneShape } from "@/types/sketchforge";
|
||
|
|
|
||
|
|
// The ShapeKind union is the validation source of truth (CLAUDE.md). The type is
|
||
|
|
// compile-time only, so we mirror it here as a runtime list for the zod enum, with a
|
||
|
|
// two-way compile-time guard so the list can never silently drift from the union.
|
||
|
|
export const SHAPE_KINDS = [
|
||
|
|
"box",
|
||
|
|
"cylinder",
|
||
|
|
"sphere",
|
||
|
|
"sketch",
|
||
|
|
"scribble",
|
||
|
|
"cone",
|
||
|
|
"pyramid",
|
||
|
|
"roof",
|
||
|
|
"text",
|
||
|
|
"roundRoof",
|
||
|
|
"halfSphere",
|
||
|
|
"torus",
|
||
|
|
"tube",
|
||
|
|
"ring",
|
||
|
|
"wedge",
|
||
|
|
"polygon",
|
||
|
|
"icosahedron",
|
||
|
|
"mesh",
|
||
|
|
] as const;
|
||
|
|
|
||
|
|
type MissingFromList = Exclude<ShapeKind, (typeof SHAPE_KINDS)[number]>;
|
||
|
|
type ExtraInList = Exclude<(typeof SHAPE_KINDS)[number], ShapeKind>;
|
||
|
|
// If either of these errors, SHAPE_KINDS and the ShapeKind union have drifted — fix the list.
|
||
|
|
const _assertNoneMissing: MissingFromList extends never ? true : false = true;
|
||
|
|
const _assertNoneExtra: ExtraInList extends never ? true : false = true;
|
||
|
|
void _assertNoneMissing;
|
||
|
|
void _assertNoneExtra;
|
||
|
|
|
||
|
|
// Structural input contract for a model-authored shape. We require only the base
|
||
|
|
// numerics every kind needs (width/depth/height) plus a valid kind; everything else is
|
||
|
|
// optional and gets filled + canonicalised by the app's own sceneShape(). We deliberately
|
||
|
|
// do NOT encode parameter ranges here — the app's canonicaliser owns that.
|
||
|
|
export interface ShapeInput {
|
||
|
|
id?: string;
|
||
|
|
name?: string;
|
||
|
|
kind: ShapeKind;
|
||
|
|
color?: string;
|
||
|
|
hole?: boolean;
|
||
|
|
x?: number;
|
||
|
|
z?: number;
|
||
|
|
elevation?: number;
|
||
|
|
width: number;
|
||
|
|
depth: number;
|
||
|
|
height: number;
|
||
|
|
size?: number;
|
||
|
|
rotation?: number;
|
||
|
|
rotationX?: number;
|
||
|
|
rotationZ?: number;
|
||
|
|
mirrorX?: boolean;
|
||
|
|
mirrorY?: boolean;
|
||
|
|
mirrorZ?: boolean;
|
||
|
|
radius?: number;
|
||
|
|
steps?: number;
|
||
|
|
sides?: number;
|
||
|
|
bevel?: number;
|
||
|
|
segments?: number;
|
||
|
|
topRadius?: number;
|
||
|
|
baseRadius?: number;
|
||
|
|
text?: string;
|
||
|
|
font?: string;
|
||
|
|
importedMesh?: unknown;
|
||
|
|
imagePlate?: unknown;
|
||
|
|
groupedShapes?: ShapeInput[];
|
||
|
|
groupedBaseWidth?: number;
|
||
|
|
groupedBaseDepth?: number;
|
||
|
|
groupedBaseHeight?: number;
|
||
|
|
locked?: boolean;
|
||
|
|
hidden?: boolean;
|
||
|
|
}
|
||
|
|
|
||
|
|
const finiteNumber = z.number().finite();
|
||
|
|
|
||
|
|
// z.lazy for the groupedShapes recursion (a boolean result carries its parts).
|
||
|
|
export const shapeInputSchema: z.ZodType<ShapeInput> = z.lazy(() =>
|
||
|
|
z.object({
|
||
|
|
id: z.string().optional(),
|
||
|
|
name: z.string().optional(),
|
||
|
|
kind: z.enum(SHAPE_KINDS),
|
||
|
|
color: z.string().optional(),
|
||
|
|
hole: z.boolean().optional(),
|
||
|
|
x: finiteNumber.optional(),
|
||
|
|
z: finiteNumber.optional(),
|
||
|
|
elevation: finiteNumber.optional(),
|
||
|
|
width: finiteNumber,
|
||
|
|
depth: finiteNumber,
|
||
|
|
height: finiteNumber,
|
||
|
|
size: finiteNumber.optional(),
|
||
|
|
rotation: finiteNumber.optional(),
|
||
|
|
rotationX: finiteNumber.optional(),
|
||
|
|
rotationZ: finiteNumber.optional(),
|
||
|
|
mirrorX: z.boolean().optional(),
|
||
|
|
mirrorY: z.boolean().optional(),
|
||
|
|
mirrorZ: z.boolean().optional(),
|
||
|
|
radius: finiteNumber.optional(),
|
||
|
|
steps: finiteNumber.optional(),
|
||
|
|
sides: finiteNumber.optional(),
|
||
|
|
bevel: finiteNumber.optional(),
|
||
|
|
segments: finiteNumber.optional(),
|
||
|
|
topRadius: finiteNumber.optional(),
|
||
|
|
baseRadius: finiteNumber.optional(),
|
||
|
|
text: z.string().optional(),
|
||
|
|
font: z.string().optional(),
|
||
|
|
importedMesh: z.unknown().optional(),
|
||
|
|
imagePlate: z.unknown().optional(),
|
||
|
|
groupedShapes: z.array(shapeInputSchema).optional(),
|
||
|
|
groupedBaseWidth: finiteNumber.optional(),
|
||
|
|
groupedBaseDepth: finiteNumber.optional(),
|
||
|
|
groupedBaseHeight: finiteNumber.optional(),
|
||
|
|
locked: z.boolean().optional(),
|
||
|
|
hidden: z.boolean().optional(),
|
||
|
|
}),
|
||
|
|
);
|
||
|
|
|
||
|
|
export const shapesArraySchema = z.array(shapeInputSchema);
|
||
|
|
|
||
|
|
function prettifyKind(kind: ShapeKind) {
|
||
|
|
const spaced = kind.replace(/([a-z])([A-Z])/g, "$1 $2");
|
||
|
|
return spaced.charAt(0).toUpperCase() + spaced.slice(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Validate-then-defaults pipeline: the zod layer only rejects structurally broken shapes;
|
||
|
|
// sceneShape() (which calls canonicalizeShape) is the single source of truth for defaults
|
||
|
|
// + canonicalisation. Grouped parts are normalised depth-first so children get defaults too.
|
||
|
|
export function toWorkplaneShape(input: ShapeInput): WorkplaneShape {
|
||
|
|
const kind = input.kind;
|
||
|
|
const color = input.color ?? fallbackSolidColor({ kind } as WorkplaneShape);
|
||
|
|
const name = input.name ?? prettifyKind(kind);
|
||
|
|
const groupedShapes = input.groupedShapes?.map(toWorkplaneShape);
|
||
|
|
return sceneShape({
|
||
|
|
...(input as Partial<WorkplaneShape>),
|
||
|
|
name,
|
||
|
|
kind,
|
||
|
|
color,
|
||
|
|
groupedShapes,
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function toWorkplaneShapes(inputs: ShapeInput[]): WorkplaneShape[] {
|
||
|
|
return inputs.map(toWorkplaneShape);
|
||
|
|
}
|