task(D12): block attributes - BlockAttrDef type, attrDefs on definitions, instance attrValues rendering as text primitives, properties panel attribute form

This commit is contained in:
Agent Zero
2026-08-29 03:35:36 +02:00
parent 7b207d8e39
commit 9ca86d67dd
4 changed files with 171 additions and 2 deletions
+23 -1
View File
@@ -42,7 +42,7 @@ function fillOrNull(raw: unknown): string | null {
* Gibt ein leeres Array zurück für unbekannte Typen bzw. Elemente,
* die nichts Sichtbares beitragen (z.B. leerer Text).
*/
export function elementToPrimitives(el: CADElement): ShapePrimitive[] {
export function elementToPrimitives(el: CADElement, attrDefs?: Array<{ tag: string; prompt: string; defaultValue?: string }>): ShapePrimitive[] {
const props = (el.properties ?? {}) as Record<string, unknown>;
const stroke = (props.stroke as string | undefined) ?? FALLBACK_STROKE;
const sw = (props.strokeWidth as number | undefined) ?? 1;
@@ -296,6 +296,28 @@ export function elementToPrimitives(el: CADElement): ShapePrimitive[] {
return out;
}
case 'block_instance': {
// Task D12: Attr-Texte der Instanz zeichnen (tag=Wert, default-Fallback).
const attrValues = (props.attrValues as Record<string, string> | undefined) ?? {};
if (!attrDefs || attrDefs.length === 0) return [];
const out: ShapePrimitive[] = [];
const fontSize = 9;
const lineH = 16;
let i = 0;
for (const def of attrDefs) {
const value = attrValues[def.tag] ?? def.defaultValue ?? '—';
out.push({
kind: 'text',
at: { x: el.x, y: el.y - 8 - i * lineH },
text: `${def.tag}=${value}`,
fontSize,
color: stroke,
});
i++;
}
return out;
}
default:
return [];
}