Leichen-Suche: tote Dateien/Funktionen entfernt, revokeMaterial-Bug behoben
ts-prune + cargo check über alle Crates durchsucht, jeder Fund per grep gegengeprüft. Gelöscht: ResourcesPanel.tsx (abgelöstes Alt-Panel), RibbonBar.tsx (Ribbon-Phase-1-Überbleibsel), sowie diverse Funktionen ohne jeden Aufrufer (sampleTerrainColors, docToSvgText/tspanToSvg, isEmpty/deserialize/fromJson, findAccentSwatch, unregisterPanel, removeFromDockLayout, TOOL_ORDER). revokeMaterial (materials/ambientcg.ts) existierte, wurde aber nie aufgerufen — jeder Material-Wechsel/-Upload liess Blob-URLs leaken. Jetzt über revokeMaterialUrls() in ComponentsTab.tsx beim Ersetzen/Löschen/ Bauteil-Löschen verdrahtet. tsc -b / vitest run (891/891) / npm run build grün.
This commit is contained in:
1 parent
cbdc3d5d76
commit
003fde4320
13 files changed
+38
-448
No files matched your search
+1
-36
@@ -152,7 +152,7 @@ export interface SvgTextOptions {
|
||||
/**
|
||||
* Zerlegt das Dokument in Zeilen/Tspans mit bereits in Benutzereinheiten
|
||||
* umgerechneten Grössen. Der Aufrufer positioniert die Zeilen selbst (Baseline
|
||||
* der Zeile i = `y + Σ lineHeight[0..i-1]`, s. `docToSvgText`).
|
||||
* der Zeile i = `y + Σ lineHeight[0..i-1]`).
|
||||
*/
|
||||
export function docToLines(doc: RichTextDoc, opts: SvgTextOptions): SvgLine[] {
|
||||
const basePt = opts.basePt ?? 12;
|
||||
@@ -262,38 +262,3 @@ function runToTspan(run: TextRun, basePt: number, unitPerPt: number, color: stri
|
||||
return tspan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Baut ein komplettes `<text>`-SVG-Element als String. Jede Zeile ist ein
|
||||
* `<tspan x=… dy=…>`, darin ein `<tspan>` je Run. `text-anchor` folgt der
|
||||
* Absatz-Ausrichtung (left→start, center→middle, right→end).
|
||||
*/
|
||||
export function docToSvgText(doc: RichTextDoc, opts: SvgTextOptions): string {
|
||||
const lines = docToLines(doc, opts);
|
||||
const parts: string[] = [];
|
||||
lines.forEach((line, i) => {
|
||||
const dy = i === 0 ? 0 : line.lineHeight;
|
||||
const anchor = line.align === "center" ? "middle" : line.align === "right" ? "end" : "start";
|
||||
const runSpans = line.tspans.map((t) => tspanToSvg(t)).join("");
|
||||
// Leere Zeile: ein Zero-Width-Space, damit dy dennoch wirkt.
|
||||
const content = runSpans || "​";
|
||||
parts.push(
|
||||
`<tspan x="${round(opts.x)}" dy="${round(dy)}" text-anchor="${anchor}">${content}</tspan>`,
|
||||
);
|
||||
});
|
||||
return `<text x="${round(opts.x)}" y="${round(opts.y)}">${parts.join("")}</text>`;
|
||||
}
|
||||
|
||||
function tspanToSvg(t: SvgTspan): string {
|
||||
const attrs: string[] = [`font-size="${t.fontSize}"`, `fill="${escapeAttr(t.fill)}"`];
|
||||
if (t.fontWeight) attrs.push(`font-weight="${t.fontWeight}"`);
|
||||
if (t.fontStyle) attrs.push(`font-style="${t.fontStyle}"`);
|
||||
if (t.fontFamily) attrs.push(`font-family="${escapeAttr(t.fontFamily)}"`);
|
||||
if (t.textDecoration) attrs.push(`text-decoration="${t.textDecoration}"`);
|
||||
if (t.baselineShift) attrs.push(`dy="${-t.baselineShift}"`);
|
||||
const body = escapeText(t.text);
|
||||
// Bei baseline-shift den dy nach dem Run zurücksetzen, damit die Grundlinie hält.
|
||||
if (t.baselineShift) {
|
||||
return `<tspan ${attrs.join(" ")}>${body}</tspan><tspan dy="${t.baselineShift}">​</tspan>`;
|
||||
}
|
||||
return `<tspan ${attrs.join(" ")}>${body}</tspan>`;
|
||||
}
|
||||
@@ -103,11 +103,6 @@ export function plainText(doc: RichTextDoc): string {
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
/** Ist das Dokument (nach Reintext) leer? */
|
||||
export function isEmpty(doc: RichTextDoc): boolean {
|
||||
return plainText(doc).length === 0;
|
||||
}
|
||||
|
||||
/** Gesamtlänge in Zeichen (inkl. Absatzumbrüche als je 1 Zeichen). */
|
||||
export function docLength(doc: RichTextDoc): number {
|
||||
return plainText(doc).length;
|
||||
@@ -376,41 +371,6 @@ export function serialize(doc: RichTextDoc): string {
|
||||
return JSON.stringify({ version: 1, paragraphs });
|
||||
}
|
||||
|
||||
/**
|
||||
* Liest ein Dokument aus JSON. Robust gegenüber fehlenden Feldern; unbekannter
|
||||
* Input ergibt ein leeres Dokument statt eines Fehlers.
|
||||
*/
|
||||
export function deserialize(json: string): RichTextDoc {
|
||||
try {
|
||||
const raw = JSON.parse(json) as unknown;
|
||||
return fromJson(raw);
|
||||
} catch {
|
||||
return emptyDoc();
|
||||
}
|
||||
}
|
||||
|
||||
/** Wandelt ein bereits geparstes Objekt in ein valides Dokument. */
|
||||
export function fromJson(raw: unknown): RichTextDoc {
|
||||
if (!raw || typeof raw !== "object") return emptyDoc();
|
||||
const obj = raw as { paragraphs?: unknown };
|
||||
if (!Array.isArray(obj.paragraphs)) return emptyDoc();
|
||||
const paragraphs: Paragraph[] = obj.paragraphs.map((p) => {
|
||||
const pp = (p ?? {}) as { runs?: unknown; align?: unknown };
|
||||
const runs: TextRun[] = Array.isArray(pp.runs)
|
||||
? pp.runs.map((r) => {
|
||||
const rr = (r ?? {}) as { text?: unknown; marks?: unknown };
|
||||
const text = typeof rr.text === "string" ? rr.text : "";
|
||||
const marks = normalizeMarks((rr.marks ?? {}) as Marks);
|
||||
return { text, marks };
|
||||
})
|
||||
: [];
|
||||
const para: Paragraph = { runs };
|
||||
if (pp.align === "center" || pp.align === "right") para.align = pp.align;
|
||||
return para;
|
||||
});
|
||||
return normalizeDoc({ version: 1, paragraphs });
|
||||
}
|
||||
|
||||
// ── Style-Presets ──────────────────────────────────────────────────────────
|
||||
|
||||
/** Ein benannter Stil (Marks-Vorlage), z. B. „Titel". */
|
||||
|
||||
Reference in new issue
Block a user