Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c247a337a9 | ||
|
|
9f5ff8eb42 | ||
|
|
2131340c01 | ||
|
|
9a21e111d0 | ||
|
|
46175efe1b | ||
|
|
128c5c6f4e | ||
|
|
1a9c7b56ff | ||
|
|
cf3e64e836 | ||
|
|
fc5f2fee41 | ||
|
|
f0b952e3a2 | ||
|
|
cc20c0cc25 | ||
|
|
5f31542cb6 | ||
|
|
77f63a6f80 | ||
|
|
0c5c1040cd | ||
|
|
35211c69a4 | ||
|
|
b8d894f243 |
No files matched your search
@@ -0,0 +1,54 @@
|
|||||||
|
# Phase 8 Cutover and Rollback Runbook
|
||||||
|
|
||||||
|
## Goal
|
||||||
|
Move from legacy-first UI to React-first UI safely, with a deterministic rollback path.
|
||||||
|
|
||||||
|
## Preconditions
|
||||||
|
- `main` branch green on:
|
||||||
|
- `npm run test`
|
||||||
|
- `npm run test:ui`
|
||||||
|
- `npm run frontend:react:check`
|
||||||
|
- Milestone #7 issues required for cutover are accepted.
|
||||||
|
- Latest regression artifacts are present under `output/playwright/`.
|
||||||
|
|
||||||
|
## Cutover Gate Command
|
||||||
|
Run this gate command before enabling React as default:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run phase8:cutover:check
|
||||||
|
```
|
||||||
|
|
||||||
|
It writes a machine-readable report to:
|
||||||
|
- `output/phase8/cutover-check-report.json`
|
||||||
|
|
||||||
|
## Cutover Checklist
|
||||||
|
1. Confirm release candidate commit hash and tag target.
|
||||||
|
2. Run `npm run phase8:cutover:check` and archive report artifact.
|
||||||
|
3. Verify React path boots and legacy path still boots in dual-run.
|
||||||
|
4. Verify save/load/import/export compatibility on fixture corpus.
|
||||||
|
5. Confirm MCP tools still return stable API envelopes.
|
||||||
|
6. Publish release notes with known limitations and rollback trigger criteria.
|
||||||
|
|
||||||
|
## Rollback Triggers
|
||||||
|
Rollback immediately if any occur post-cutover:
|
||||||
|
- New blocker in compile/apply loop.
|
||||||
|
- UI interaction regressions that break editing workflows.
|
||||||
|
- Crossings/overlaps/readability regressions above agreed thresholds.
|
||||||
|
- API/MCP contract break for compile/analyze/layout endpoints.
|
||||||
|
|
||||||
|
## Rollback Procedure
|
||||||
|
1. Switch deployment back to previous stable tag.
|
||||||
|
2. Re-enable legacy-first UI mode.
|
||||||
|
3. Re-run:
|
||||||
|
- `npm run test`
|
||||||
|
- `npm run test:ui`
|
||||||
|
4. Open incident issue with:
|
||||||
|
- failing commit/tag
|
||||||
|
- regression screenshots
|
||||||
|
- exact reproduction JSON
|
||||||
|
5. Keep React path available in non-default dual-run mode until fix lands.
|
||||||
|
|
||||||
|
## Evidence to Attach to Release
|
||||||
|
- `output/phase8/cutover-check-report.json`
|
||||||
|
- `output/playwright/ui-metrics-report.json`
|
||||||
|
- Updated `docs/release-checklist.md` completion notes
|
||||||
@@ -16,6 +16,7 @@ Reference docs:
|
|||||||
|
|
||||||
- [ ] `npm test` passes.
|
- [ ] `npm test` passes.
|
||||||
- [ ] `npm run test:ui` passes.
|
- [ ] `npm run test:ui` passes.
|
||||||
|
- [ ] `npm run phase8:cutover:check` passes (for React-first cutover candidates).
|
||||||
- [ ] Beta quality gates in `docs/quality-gates.md` are met.
|
- [ ] Beta quality gates in `docs/quality-gates.md` are met.
|
||||||
- [ ] Core smoke flow tested in UI:
|
- [ ] Core smoke flow tested in UI:
|
||||||
- [ ] Load sample
|
- [ ] Load sample
|
||||||
@@ -53,3 +54,4 @@ Reference docs:
|
|||||||
- [ ] Changelog/release notes generated with notable UX/compat changes.
|
- [ ] Changelog/release notes generated with notable UX/compat changes.
|
||||||
- [ ] Tag pushed and release announcement links to milestone/issues.
|
- [ ] Tag pushed and release announcement links to milestone/issues.
|
||||||
- [ ] GA gates in `docs/quality-gates.md` confirmed complete.
|
- [ ] GA gates in `docs/quality-gates.md` confirmed complete.
|
||||||
|
- [ ] Attach `output/phase8/cutover-check-report.json` for release evidence.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import { analyze, autoLayout, compile, tidyLayout } from "./api/client";
|
import { analyze, autoLayout, compile, tidyLayout } from "./api/client";
|
||||||
import { CanvasArea } from "./components/CanvasArea";
|
import { CanvasArea } from "./components/CanvasArea";
|
||||||
import { LeftPanel } from "./components/LeftPanel";
|
import { LeftPanel } from "./components/LeftPanel";
|
||||||
@@ -40,6 +40,23 @@ function toCompileFromAnalyze(result: Awaited<ReturnType<typeof analyze>>): Reco
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortKeysDeep(value: unknown): unknown {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.map((item) => sortKeysDeep(item));
|
||||||
|
}
|
||||||
|
if (value && typeof value === "object") {
|
||||||
|
const record = value as Record<string, unknown>;
|
||||||
|
const sorted = Object.keys(record)
|
||||||
|
.sort((a, b) => a.localeCompare(b))
|
||||||
|
.reduce<Record<string, unknown>>((acc, key) => {
|
||||||
|
acc[key] = sortKeysDeep(record[key]);
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
const store = useMemo(() => createSchemetaStore({ model: SAMPLE_PAYLOAD }), []);
|
const store = useMemo(() => createSchemetaStore({ model: SAMPLE_PAYLOAD }), []);
|
||||||
const actionsApi = useSchemetaActions(store);
|
const actionsApi = useSchemetaActions(store);
|
||||||
@@ -48,6 +65,13 @@ export function App() {
|
|||||||
const compileResult = useSchemetaSelector(store, (state) => state.compileResult);
|
const compileResult = useSchemetaSelector(store, (state) => state.compileResult);
|
||||||
const lifecycle = useSchemetaSelector(store, (state) => state.lifecycle);
|
const lifecycle = useSchemetaSelector(store, (state) => state.lifecycle);
|
||||||
const jsonError = useSchemetaSelector(store, (state) => state.uiFlags.jsonError);
|
const jsonError = useSchemetaSelector(store, (state) => state.uiFlags.jsonError);
|
||||||
|
const [jsonEditorText, setJsonEditorText] = useState(() => JSON.stringify(SAMPLE_PAYLOAD, null, 2));
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (model) {
|
||||||
|
setJsonEditorText(JSON.stringify(model, null, 2));
|
||||||
|
}
|
||||||
|
}, [model]);
|
||||||
const lastApiVersion = useSchemetaSelector(store, (state) => {
|
const lastApiVersion = useSchemetaSelector(store, (state) => {
|
||||||
const apiVersion = state.compileResult && typeof state.compileResult.api_version === "string" ? state.compileResult.api_version : null;
|
const apiVersion = state.compileResult && typeof state.compileResult.api_version === "string" ? state.compileResult.api_version : null;
|
||||||
return apiVersion ?? "-";
|
return apiVersion ?? "-";
|
||||||
@@ -109,7 +133,7 @@ export function App() {
|
|||||||
switch (action.id) {
|
switch (action.id) {
|
||||||
case "compile":
|
case "compile":
|
||||||
{
|
{
|
||||||
const result = await compile(payload);
|
const result = await compile(payload, { preserve_placement: true });
|
||||||
actionsApi.setCompileResult(result);
|
actionsApi.setCompileResult(result);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -149,6 +173,71 @@ export function App() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function applyJsonFromEditor() {
|
||||||
|
const parsed = actionsApi.applyJsonText(jsonEditorText);
|
||||||
|
if (!parsed.ok) {
|
||||||
|
actionsApi.failCompile("apply-json", parsed.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
actionsApi.completeCompile("apply-json");
|
||||||
|
}
|
||||||
|
|
||||||
|
async function validateJsonEditor() {
|
||||||
|
const parsed = actionsApi.applyJsonText(jsonEditorText);
|
||||||
|
if (!parsed.ok) {
|
||||||
|
actionsApi.failCompile("validate-json", parsed.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const modelCandidate = store.getState().model;
|
||||||
|
if (!modelCandidate) {
|
||||||
|
actionsApi.failCompile("validate-json", "No model loaded");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
actionsApi.beginCompile("validate-json");
|
||||||
|
try {
|
||||||
|
const analyzed = await analyze(modelCandidate);
|
||||||
|
actionsApi.setCompileResult(toCompileFromAnalyze(analyzed));
|
||||||
|
actionsApi.completeCompile("validate-json");
|
||||||
|
} catch (error) {
|
||||||
|
actionsApi.failCompile("validate-json", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function formatJsonEditor() {
|
||||||
|
const parsed = actionsApi.applyJsonText(jsonEditorText);
|
||||||
|
if (!parsed.ok) {
|
||||||
|
actionsApi.failCompile("format-json", parsed.error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const next = store.getState().model;
|
||||||
|
if (next) {
|
||||||
|
setJsonEditorText(JSON.stringify(next, null, 2));
|
||||||
|
}
|
||||||
|
actionsApi.completeCompile("format-json");
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortJsonEditorKeys() {
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(jsonEditorText);
|
||||||
|
const sorted = sortKeysDeep(parsed);
|
||||||
|
setJsonEditorText(JSON.stringify(sorted, null, 2));
|
||||||
|
actionsApi.completeCompile("sort-json");
|
||||||
|
} catch (error) {
|
||||||
|
actionsApi.failCompile("sort-json", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyReproJson() {
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(jsonEditorText);
|
||||||
|
actionsApi.completeCompile("copy-repro");
|
||||||
|
} catch {
|
||||||
|
actionsApi.failCompile("copy-repro", "Clipboard write failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="app-shell">
|
<div className="app-shell">
|
||||||
<TopBar
|
<TopBar
|
||||||
@@ -185,7 +274,23 @@ export function App() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<CanvasArea store={store} />
|
<CanvasArea store={store} />
|
||||||
<RightInspector model={model} selection={selection} compileResult={compileResult} />
|
<RightInspector
|
||||||
|
model={model}
|
||||||
|
selection={selection}
|
||||||
|
compileResult={compileResult}
|
||||||
|
jsonText={jsonEditorText}
|
||||||
|
jsonError={jsonError}
|
||||||
|
onJsonTextChange={setJsonEditorText}
|
||||||
|
onApplyJson={applyJsonFromEditor}
|
||||||
|
onValidateJson={() => {
|
||||||
|
void validateJsonEditor();
|
||||||
|
}}
|
||||||
|
onFormatJson={formatJsonEditor}
|
||||||
|
onSortJson={sortJsonEditorKeys}
|
||||||
|
onCopyRepro={() => {
|
||||||
|
void copyReproJson();
|
||||||
|
}}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -739,7 +739,8 @@ export function CanvasArea({ store: providedStore }: CanvasAreaProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const isAlreadySelected = selectedSet.has(ref);
|
const isAlreadySelected = selectedSet.has(ref);
|
||||||
const dragCandidates = isAlreadySelected && selectedRefs.length > 1 ? selectedRefs : [ref];
|
const explicitGroupDrag = event.altKey;
|
||||||
|
const dragCandidates = isAlreadySelected && selectedRefs.length > 1 && explicitGroupDrag ? selectedRefs : [ref];
|
||||||
|
|
||||||
if (!isAlreadySelected || selectedRefs.length !== dragCandidates.length) {
|
if (!isAlreadySelected || selectedRefs.length !== dragCandidates.length) {
|
||||||
store.actions.setSelection({
|
store.actions.setSelection({
|
||||||
|
|||||||
@@ -4,6 +4,14 @@ type RightInspectorProps = {
|
|||||||
model: SchemetaModel | null;
|
model: SchemetaModel | null;
|
||||||
selection: SelectionSlice;
|
selection: SelectionSlice;
|
||||||
compileResult: unknown | null;
|
compileResult: unknown | null;
|
||||||
|
jsonText: string;
|
||||||
|
jsonError: string | null;
|
||||||
|
onJsonTextChange: (value: string) => void;
|
||||||
|
onApplyJson: () => void;
|
||||||
|
onValidateJson: () => void;
|
||||||
|
onFormatJson: () => void;
|
||||||
|
onSortJson: () => void;
|
||||||
|
onCopyRepro: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
function asRecord(value: unknown): Record<string, unknown> | null {
|
function asRecord(value: unknown): Record<string, unknown> | null {
|
||||||
@@ -33,7 +41,19 @@ function toSnippet(value: unknown, fallback: string): string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RightInspector({ model, selection, compileResult }: RightInspectorProps) {
|
export function RightInspector({
|
||||||
|
model,
|
||||||
|
selection,
|
||||||
|
compileResult,
|
||||||
|
jsonText,
|
||||||
|
jsonError,
|
||||||
|
onJsonTextChange,
|
||||||
|
onApplyJson,
|
||||||
|
onValidateJson,
|
||||||
|
onFormatJson,
|
||||||
|
onSortJson,
|
||||||
|
onCopyRepro
|
||||||
|
}: RightInspectorProps) {
|
||||||
const selectedRef = selection.selectedRefs[0] ?? null;
|
const selectedRef = selection.selectedRefs[0] ?? null;
|
||||||
const selectedInstance = selectedRef ? (model?.instances ?? []).find((instance) => instance.ref === selectedRef) : null;
|
const selectedInstance = selectedRef ? (model?.instances ?? []).find((instance) => instance.ref === selectedRef) : null;
|
||||||
|
|
||||||
@@ -66,6 +86,35 @@ export function RightInspector({ model, selection, compileResult }: RightInspect
|
|||||||
|
|
||||||
<h2 className="panel__title">Layout Metrics</h2>
|
<h2 className="panel__title">Layout Metrics</h2>
|
||||||
<pre>{toSnippet(layoutMetrics, "No layout metrics available yet.")}</pre>
|
<pre>{toSnippet(layoutMetrics, "No layout metrics available yet.")}</pre>
|
||||||
|
|
||||||
|
<h2 className="panel__title">JSON Editor</h2>
|
||||||
|
<div className="json-tools">
|
||||||
|
<button type="button" onClick={onValidateJson}>
|
||||||
|
Validate
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={onFormatJson}>
|
||||||
|
Format
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={onSortJson}>
|
||||||
|
Sort Keys
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={onCopyRepro}>
|
||||||
|
Copy Repro
|
||||||
|
</button>
|
||||||
|
<button type="button" onClick={onApplyJson}>
|
||||||
|
Apply JSON
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<textarea
|
||||||
|
className="json-editor"
|
||||||
|
value={jsonText}
|
||||||
|
onChange={(event) => onJsonTextChange(event.target.value)}
|
||||||
|
spellCheck={false}
|
||||||
|
aria-label="Schematic JSON editor"
|
||||||
|
/>
|
||||||
|
<p className={`panel__body ${jsonError ? "json-status--error" : "json-status--ok"}`}>
|
||||||
|
{jsonError ? `JSON error: ${jsonError}` : "JSON ready"}
|
||||||
|
</p>
|
||||||
</aside>
|
</aside>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -190,6 +190,49 @@ body {
|
|||||||
font-size: 0.76rem;
|
font-size: 0.76rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.json-tools {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
gap: 0.35rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.json-tools button {
|
||||||
|
padding: 0.28rem 0.48rem;
|
||||||
|
border: 1px solid #b9c9d6;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: #f8fbff;
|
||||||
|
color: #173247;
|
||||||
|
font: inherit;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.json-tools button:hover {
|
||||||
|
background: #eaf2f8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.json-editor {
|
||||||
|
width: 100%;
|
||||||
|
min-height: 220px;
|
||||||
|
border: 1px solid #c1d0dd;
|
||||||
|
border-radius: 8px;
|
||||||
|
padding: 0.5rem;
|
||||||
|
background: #fbfdff;
|
||||||
|
color: #173247;
|
||||||
|
font-family: "IBM Plex Mono", "Fira Code", monospace;
|
||||||
|
font-size: 0.78rem;
|
||||||
|
line-height: 1.35;
|
||||||
|
resize: vertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
.json-status--ok {
|
||||||
|
color: #12633c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.json-status--error {
|
||||||
|
color: #a31515;
|
||||||
|
}
|
||||||
|
|
||||||
.canvas {
|
.canvas {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-rows: auto 1fr;
|
grid-template-rows: auto 1fr;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const MIN_SCALE = 0.2;
|
|||||||
const MAX_SCALE = 5;
|
const MAX_SCALE = 5;
|
||||||
const FIT_MARGIN = 56;
|
const FIT_MARGIN = 56;
|
||||||
const FOCUS_MARGIN = 96;
|
const FOCUS_MARGIN = 96;
|
||||||
|
const THEME_KEY = "schemeta:theme:v1";
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
model: null,
|
model: null,
|
||||||
@@ -31,7 +32,8 @@ const state = {
|
|||||||
showLabels: true,
|
showLabels: true,
|
||||||
isolateNet: false,
|
isolateNet: false,
|
||||||
isolateComponent: false,
|
isolateComponent: false,
|
||||||
renderMode: "schematic_stub",
|
renderMode: "explicit",
|
||||||
|
theme: "dark",
|
||||||
userAdjustedView: false,
|
userAdjustedView: false,
|
||||||
spacePan: false,
|
spacePan: false,
|
||||||
schemaText: "",
|
schemaText: "",
|
||||||
@@ -141,6 +143,8 @@ const el = {
|
|||||||
copyReproBtn: document.getElementById("copyReproBtn"),
|
copyReproBtn: document.getElementById("copyReproBtn"),
|
||||||
autoLayoutBtn: document.getElementById("autoLayoutBtn"),
|
autoLayoutBtn: document.getElementById("autoLayoutBtn"),
|
||||||
autoTidyBtn: document.getElementById("autoTidyBtn"),
|
autoTidyBtn: document.getElementById("autoTidyBtn"),
|
||||||
|
unlockAllBtn: document.getElementById("unlockAllBtn"),
|
||||||
|
themeToggleBtn: document.getElementById("themeToggleBtn"),
|
||||||
shortcutsBtn: document.getElementById("shortcutsBtn"),
|
shortcutsBtn: document.getElementById("shortcutsBtn"),
|
||||||
undoBtn: document.getElementById("undoBtn"),
|
undoBtn: document.getElementById("undoBtn"),
|
||||||
redoBtn: document.getElementById("redoBtn"),
|
redoBtn: document.getElementById("redoBtn"),
|
||||||
@@ -158,7 +162,8 @@ const el = {
|
|||||||
commandModal: document.getElementById("commandModal"),
|
commandModal: document.getElementById("commandModal"),
|
||||||
closeCommandBtn: document.getElementById("closeCommandBtn"),
|
closeCommandBtn: document.getElementById("closeCommandBtn"),
|
||||||
commandInput: document.getElementById("commandInput"),
|
commandInput: document.getElementById("commandInput"),
|
||||||
commandList: document.getElementById("commandList")
|
commandList: document.getElementById("commandList"),
|
||||||
|
selectedNoteHint: null
|
||||||
};
|
};
|
||||||
|
|
||||||
function toGrid(v) {
|
function toGrid(v) {
|
||||||
@@ -348,6 +353,27 @@ function setStatus(text, ok = true) {
|
|||||||
el.compileStatus.className = ok ? "status-ok" : "";
|
el.compileStatus.className = ok ? "status-ok" : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectThemePreference() {
|
||||||
|
const saved = localStorage.getItem(THEME_KEY);
|
||||||
|
if (saved === "dark" || saved === "light") {
|
||||||
|
return saved;
|
||||||
|
}
|
||||||
|
return "dark";
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyTheme(theme, persist = true) {
|
||||||
|
const next = theme === "light" ? "light" : "dark";
|
||||||
|
state.theme = next;
|
||||||
|
document.body.classList.toggle("theme-dark", next === "dark");
|
||||||
|
if (el.themeToggleBtn) {
|
||||||
|
el.themeToggleBtn.textContent = next === "dark" ? "Light" : "Dark";
|
||||||
|
el.themeToggleBtn.setAttribute("aria-label", next === "dark" ? "Switch to light mode" : "Switch to dark mode");
|
||||||
|
}
|
||||||
|
if (persist) {
|
||||||
|
localStorage.setItem(THEME_KEY, next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function formatCompileStatus(result) {
|
function formatCompileStatus(result) {
|
||||||
const m = result?.layout_metrics ?? {};
|
const m = result?.layout_metrics ?? {};
|
||||||
return `Compiled (${result.errors.length}E, ${result.warnings.length}W | ${m.crossings ?? 0} crossings, ${m.overlap_edges ?? 0} overlaps, ${m.total_bends ?? 0} bends, ${m.label_tie_routes ?? 0} tie-nets, ${(m.detour_ratio ?? 1).toFixed(2)}x detour)`;
|
return `Compiled (${result.errors.length}E, ${result.warnings.length}W | ${m.crossings ?? 0} crossings, ${m.overlap_edges ?? 0} overlaps, ${m.total_bends ?? 0} bends, ${m.label_tie_routes ?? 0} tie-nets, ${(m.detour_ratio ?? 1).toFixed(2)}x detour)`;
|
||||||
@@ -368,6 +394,8 @@ function compileOptions(extra = {}) {
|
|||||||
return {
|
return {
|
||||||
render_mode: state.renderMode,
|
render_mode: state.renderMode,
|
||||||
show_labels: state.showLabels,
|
show_labels: state.showLabels,
|
||||||
|
show_annotations: false,
|
||||||
|
show_legend: false,
|
||||||
generic_symbols: true,
|
generic_symbols: true,
|
||||||
...extra
|
...extra
|
||||||
};
|
};
|
||||||
@@ -427,6 +455,58 @@ function refreshJsonEditor() {
|
|||||||
el.jsonEditor.value = JSON.stringify(state.model, null, 2);
|
el.jsonEditor.value = JSON.stringify(state.model, null, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function selectedComponentNote() {
|
||||||
|
if (!state.model || state.selectedNet || state.selectedPin || state.selectedRefs.length !== 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const inst = instanceByRef(state.selectedRefs[0]);
|
||||||
|
if (!inst) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
const raw = String(inst.properties?.note ?? inst.properties?.notes ?? "").trim();
|
||||||
|
if (!raw) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return raw.length > 240 ? `${raw.slice(0, 237)}...` : raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSelectedNoteHint() {
|
||||||
|
if (!el.selectedNoteHint) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const note = selectedComponentNote();
|
||||||
|
if (!note || !state.compile?.layout || !state.model) {
|
||||||
|
el.selectedNoteHint.classList.add("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ref = state.selectedRefs[0];
|
||||||
|
const inst = instanceByRef(ref);
|
||||||
|
const sym = inst ? state.model.symbols?.[inst.symbol] : null;
|
||||||
|
const placed = (state.compile.layout.placed ?? []).find((p) => p.ref === ref);
|
||||||
|
if (!inst || !sym || !placed) {
|
||||||
|
el.selectedNoteHint.classList.add("hidden");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
el.selectedNoteHint.textContent = note;
|
||||||
|
el.selectedNoteHint.classList.remove("hidden");
|
||||||
|
el.selectedNoteHint.style.visibility = "hidden";
|
||||||
|
|
||||||
|
const viewportRect = el.canvasViewport.getBoundingClientRect();
|
||||||
|
const x = (placed.x + sym.body.width / 2) * state.scale + state.panX;
|
||||||
|
const y = (placed.y - 12) * state.scale + state.panY;
|
||||||
|
el.selectedNoteHint.style.left = `${Math.round(x)}px`;
|
||||||
|
el.selectedNoteHint.style.top = `${Math.round(y)}px`;
|
||||||
|
el.selectedNoteHint.style.transform = "translate(-50%, -100%)";
|
||||||
|
|
||||||
|
const hintRect = el.selectedNoteHint.getBoundingClientRect();
|
||||||
|
const minX = 14 + hintRect.width / 2;
|
||||||
|
const maxX = Math.max(minX, viewportRect.width - 14 - hintRect.width / 2);
|
||||||
|
const clampedX = Math.max(minX, Math.min(maxX, x));
|
||||||
|
el.selectedNoteHint.style.left = `${Math.round(clampedX)}px`;
|
||||||
|
el.selectedNoteHint.style.visibility = "";
|
||||||
|
}
|
||||||
|
|
||||||
function saveSnapshot() {
|
function saveSnapshot() {
|
||||||
if (!state.model) {
|
if (!state.model) {
|
||||||
return;
|
return;
|
||||||
@@ -451,6 +531,7 @@ function updateTransform() {
|
|||||||
applyLabelDensityByZoom(svg);
|
applyLabelDensityByZoom(svg);
|
||||||
resolveLabelCollisions(svg);
|
resolveLabelCollisions(svg);
|
||||||
}
|
}
|
||||||
|
updateSelectedNoteHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
function layoutBounds(layout, margin = FIT_MARGIN) {
|
function layoutBounds(layout, margin = FIT_MARGIN) {
|
||||||
@@ -746,8 +827,8 @@ function applyLabelDensityByZoom(svg) {
|
|||||||
const pinLabels = svg.querySelectorAll("[data-pin-label]");
|
const pinLabels = svg.querySelectorAll("[data-pin-label]");
|
||||||
const valueLabels = svg.querySelectorAll("[data-value-label]");
|
const valueLabels = svg.querySelectorAll("[data-value-label]");
|
||||||
const refLabels = svg.querySelectorAll("[data-ref-label]");
|
const refLabels = svg.querySelectorAll("[data-ref-label]");
|
||||||
const dense = state.scale < 0.85;
|
const dense = state.scale < 1.05;
|
||||||
const veryDense = state.scale < 0.65;
|
const veryDense = state.scale < 0.8;
|
||||||
|
|
||||||
pinLabels.forEach((n) => {
|
pinLabels.forEach((n) => {
|
||||||
n.style.display = dense ? "none" : "";
|
n.style.display = dense ? "none" : "";
|
||||||
@@ -973,14 +1054,18 @@ function symbolPinRowHtml(pin) {
|
|||||||
const sideOptions = PIN_SIDES.map((s) => `<option value="${s}" ${pin.side === s ? "selected" : ""}>${s}</option>`).join("");
|
const sideOptions = PIN_SIDES.map((s) => `<option value="${s}" ${pin.side === s ? "selected" : ""}>${s}</option>`).join("");
|
||||||
const typeOptions = PIN_TYPES.map((t) => `<option value="${t}" ${pin.type === t ? "selected" : ""}>${t}</option>`).join("");
|
const typeOptions = PIN_TYPES.map((t) => `<option value="${t}" ${pin.type === t ? "selected" : ""}>${t}</option>`).join("");
|
||||||
return `<div class="miniRow symbolPinRow" data-old-pin="${escHtml(pin.name)}">
|
return `<div class="miniRow symbolPinRow" data-old-pin="${escHtml(pin.name)}">
|
||||||
|
<div class="symbolPinMain">
|
||||||
<input class="pinCol pinName" type="text" value="${escHtml(pin.name)}" placeholder="name" />
|
<input class="pinCol pinName" type="text" value="${escHtml(pin.name)}" placeholder="name" />
|
||||||
<input class="pinCol pinNumber" type="text" value="${escHtml(pin.number)}" placeholder="number" />
|
<input class="pinCol pinNumber" type="text" value="${escHtml(pin.number)}" placeholder="num" />
|
||||||
<select class="pinCol pinSide">${sideOptions}</select>
|
<select class="pinCol pinSide">${sideOptions}</select>
|
||||||
<input class="pinCol pinOffset" type="number" min="0" step="1" value="${Number(pin.offset ?? 0)}" />
|
<input class="pinCol pinOffset" type="number" min="0" step="1" value="${Number(pin.offset ?? 0)}" />
|
||||||
<select class="pinCol pinType">${typeOptions}</select>
|
<select class="pinCol pinType">${typeOptions}</select>
|
||||||
|
</div>
|
||||||
|
<div class="symbolPinActions">
|
||||||
<button type="button" data-move-symbol-pin="up" title="Move pin up">Up</button>
|
<button type="button" data-move-symbol-pin="up" title="Move pin up">Up</button>
|
||||||
<button type="button" data-move-symbol-pin="down" title="Move pin down">Down</button>
|
<button type="button" data-move-symbol-pin="down" title="Move pin down">Down</button>
|
||||||
<button type="button" data-remove-symbol-pin="${escHtml(pin.name)}">Remove</button>
|
<button type="button" data-remove-symbol-pin="${escHtml(pin.name)}">Remove</button>
|
||||||
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1267,6 +1352,7 @@ function renderSelected() {
|
|||||||
el.symbolEditor.classList.add("hidden");
|
el.symbolEditor.classList.add("hidden");
|
||||||
el.pinEditor.classList.add("hidden");
|
el.pinEditor.classList.add("hidden");
|
||||||
el.netEditor.classList.add("hidden");
|
el.netEditor.classList.add("hidden");
|
||||||
|
updateSelectedNoteHint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,6 +1365,7 @@ function renderSelected() {
|
|||||||
el.symbolEditor.classList.add("hidden");
|
el.symbolEditor.classList.add("hidden");
|
||||||
renderPinEditor();
|
renderPinEditor();
|
||||||
el.netEditor.classList.add("hidden");
|
el.netEditor.classList.add("hidden");
|
||||||
|
updateSelectedNoteHint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1288,6 +1375,7 @@ function renderSelected() {
|
|||||||
el.symbolEditor.classList.add("hidden");
|
el.symbolEditor.classList.add("hidden");
|
||||||
el.pinEditor.classList.add("hidden");
|
el.pinEditor.classList.add("hidden");
|
||||||
el.netEditor.classList.add("hidden");
|
el.netEditor.classList.add("hidden");
|
||||||
|
updateSelectedNoteHint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1301,13 +1389,14 @@ function renderSelected() {
|
|||||||
el.lockedInput.checked = Boolean(inst.placement.locked);
|
el.lockedInput.checked = Boolean(inst.placement.locked);
|
||||||
el.instRefInput.value = inst.ref;
|
el.instRefInput.value = inst.ref;
|
||||||
el.instValueInput.value = String(inst.properties?.value ?? "");
|
el.instValueInput.value = String(inst.properties?.value ?? "");
|
||||||
el.instNotesInput.value = String(inst.properties?.notes ?? "");
|
el.instNotesInput.value = String(inst.properties?.note ?? inst.properties?.notes ?? "");
|
||||||
el.duplicateComponentBtn.disabled = false;
|
el.duplicateComponentBtn.disabled = false;
|
||||||
el.deleteComponentBtn.disabled = false;
|
el.deleteComponentBtn.disabled = false;
|
||||||
el.isolateSelectedComponentBtn.disabled = false;
|
el.isolateSelectedComponentBtn.disabled = false;
|
||||||
renderSymbolEditorForRef(inst.ref);
|
renderSymbolEditorForRef(inst.ref);
|
||||||
el.pinEditor.classList.add("hidden");
|
el.pinEditor.classList.add("hidden");
|
||||||
el.netEditor.classList.add("hidden");
|
el.netEditor.classList.add("hidden");
|
||||||
|
updateSelectedNoteHint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1320,6 +1409,7 @@ function renderSelected() {
|
|||||||
el.symbolEditor.classList.add("hidden");
|
el.symbolEditor.classList.add("hidden");
|
||||||
el.pinEditor.classList.add("hidden");
|
el.pinEditor.classList.add("hidden");
|
||||||
renderNetEditor();
|
renderNetEditor();
|
||||||
|
updateSelectedNoteHint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1329,6 +1419,7 @@ function renderSelected() {
|
|||||||
el.symbolEditor.classList.add("hidden");
|
el.symbolEditor.classList.add("hidden");
|
||||||
el.pinEditor.classList.add("hidden");
|
el.pinEditor.classList.add("hidden");
|
||||||
el.netEditor.classList.add("hidden");
|
el.netEditor.classList.add("hidden");
|
||||||
|
updateSelectedNoteHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
function issueById(issueId) {
|
function issueById(issueId) {
|
||||||
@@ -1676,9 +1767,7 @@ function bindSvgInteractions() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!state.selectedRefs.includes(ref)) {
|
|
||||||
selectSingleRef(ref);
|
selectSingleRef(ref);
|
||||||
}
|
|
||||||
state.selectedNet = null;
|
state.selectedNet = null;
|
||||||
state.selectedPin = null;
|
state.selectedPin = null;
|
||||||
state.isolateNet = false;
|
state.isolateNet = false;
|
||||||
@@ -1693,7 +1782,20 @@ function bindSvgInteractions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pt = canvasToSvgPoint(evt.clientX, evt.clientY);
|
const pt = canvasToSvgPoint(evt.clientX, evt.clientY);
|
||||||
const dragRefs = state.selectedRefs.length ? [...state.selectedRefs] : [ref];
|
const clickedInst = instanceByRef(ref);
|
||||||
|
if (clickedInst?.placement?.locked) {
|
||||||
|
pushHistory("auto-unlock-drag");
|
||||||
|
clickedInst.placement.locked = false;
|
||||||
|
el.jsonFeedback.textContent = `${ref} was locked and has been auto-unlocked for manual move.`;
|
||||||
|
renderSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
const dragRefsRaw = state.selectedRefs.length ? [...state.selectedRefs] : [ref];
|
||||||
|
const dragRefs = dragRefsRaw.filter((r) => !instanceByRef(r)?.placement?.locked);
|
||||||
|
if (!dragRefs.length) {
|
||||||
|
el.jsonFeedback.textContent = `${ref} is locked. Uncheck 'Locked' on the component or use 'Unlock All'.`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
const baseByRef = {};
|
const baseByRef = {};
|
||||||
for (const r of dragRefs) {
|
for (const r of dragRefs) {
|
||||||
const ii = state.model.instances.find((x) => x.ref === r);
|
const ii = state.model.instances.find((x) => x.ref === r);
|
||||||
@@ -1772,6 +1874,7 @@ function bindSvgInteractions() {
|
|||||||
function renderCanvas() {
|
function renderCanvas() {
|
||||||
if (!state.compile?.svg) {
|
if (!state.compile?.svg) {
|
||||||
el.canvasInner.innerHTML = "";
|
el.canvasInner.innerHTML = "";
|
||||||
|
updateSelectedNoteHint();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1784,6 +1887,7 @@ function renderCanvas() {
|
|||||||
applyLabelDensityByZoom(svg);
|
applyLabelDensityByZoom(svg);
|
||||||
resolveLabelCollisions(svg);
|
resolveLabelCollisions(svg);
|
||||||
}
|
}
|
||||||
|
updateSelectedNoteHint();
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderAll() {
|
function renderAll() {
|
||||||
@@ -1809,20 +1913,23 @@ async function compileModel(model, opts = {}) {
|
|||||||
const fit = opts.fit ?? false;
|
const fit = opts.fit ?? false;
|
||||||
const keepView = opts.keepView ?? false;
|
const keepView = opts.keepView ?? false;
|
||||||
const preservePlacement = opts.preservePlacement ?? false;
|
const preservePlacement = opts.preservePlacement ?? false;
|
||||||
|
const compileLayoutOpts = preservePlacement
|
||||||
setStatus(source === "drag" ? "Compiling after drag..." : "Compiling...");
|
|
||||||
try {
|
|
||||||
const result = await apiPost("/compile", {
|
|
||||||
payload: model,
|
|
||||||
options: compileOptions(
|
|
||||||
preservePlacement
|
|
||||||
? {
|
? {
|
||||||
preserve_placement: true,
|
preserve_placement: true,
|
||||||
auto_rotate: false,
|
auto_rotate: false,
|
||||||
respect_locks: true
|
respect_locks: true
|
||||||
}
|
}
|
||||||
: {}
|
: {
|
||||||
)
|
preserve_placement: false,
|
||||||
|
auto_rotate: true,
|
||||||
|
respect_locks: false
|
||||||
|
};
|
||||||
|
|
||||||
|
setStatus(source === "drag" ? "Compiling after drag..." : "Compiling...");
|
||||||
|
try {
|
||||||
|
const result = await apiPost("/compile", {
|
||||||
|
payload: model,
|
||||||
|
options: compileOptions(compileLayoutOpts)
|
||||||
});
|
});
|
||||||
|
|
||||||
state.model = applyCompileLayoutToModel(model, result);
|
state.model = applyCompileLayoutToModel(model, result);
|
||||||
@@ -1868,7 +1975,7 @@ function queueCompile(keepView = true, source = "edit") {
|
|||||||
}
|
}
|
||||||
state.compileDebounceId = setTimeout(() => {
|
state.compileDebounceId = setTimeout(() => {
|
||||||
state.compileDebounceId = null;
|
state.compileDebounceId = null;
|
||||||
compileModel(state.model, { keepView, source });
|
compileModel(state.model, { keepView, source, preservePlacement: true });
|
||||||
}, 150);
|
}, 150);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2403,7 +2510,9 @@ async function runLayoutAction(path) {
|
|||||||
try {
|
try {
|
||||||
const out = await apiPost(path, {
|
const out = await apiPost(path, {
|
||||||
payload: state.model,
|
payload: state.model,
|
||||||
options: compileOptions()
|
options: compileOptions({
|
||||||
|
respect_locks: path.includes("/tidy")
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
state.model = applyCompileLayoutToModel(out.model, out.compile);
|
state.model = applyCompileLayoutToModel(out.model, out.compile);
|
||||||
@@ -2439,8 +2548,8 @@ async function resetToSample(opts = {}) {
|
|||||||
state.isolateNet = false;
|
state.isolateNet = false;
|
||||||
state.isolateComponent = false;
|
state.isolateComponent = false;
|
||||||
state.userAdjustedView = false;
|
state.userAdjustedView = false;
|
||||||
state.renderMode = "schematic_stub";
|
state.renderMode = "explicit";
|
||||||
el.renderModeSelect.value = "schematic_stub";
|
el.renderModeSelect.value = "explicit";
|
||||||
state.showLabels = true;
|
state.showLabels = true;
|
||||||
el.showLabelsInput.checked = true;
|
el.showLabelsInput.checked = true;
|
||||||
el.instanceFilter.value = "";
|
el.instanceFilter.value = "";
|
||||||
@@ -2642,6 +2751,7 @@ function setupEvents() {
|
|||||||
properties: {
|
properties: {
|
||||||
...(inst.properties ?? {}),
|
...(inst.properties ?? {}),
|
||||||
value: el.instValueInput.value,
|
value: el.instValueInput.value,
|
||||||
|
note: el.instNotesInput.value,
|
||||||
notes: el.instNotesInput.value
|
notes: el.instNotesInput.value
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -2675,7 +2785,6 @@ function setupEvents() {
|
|||||||
pushHistory("rotate");
|
pushHistory("rotate");
|
||||||
const current = Number(inst.placement.rotation ?? 0);
|
const current = Number(inst.placement.rotation ?? 0);
|
||||||
inst.placement.rotation = ((Math.round(current / 90) * 90 + 90) % 360 + 360) % 360;
|
inst.placement.rotation = ((Math.round(current / 90) * 90 + 90) % 360 + 360) % 360;
|
||||||
inst.placement.locked = true;
|
|
||||||
renderSelected();
|
renderSelected();
|
||||||
el.jsonFeedback.textContent = "Component rotated.";
|
el.jsonFeedback.textContent = "Component rotated.";
|
||||||
queueCompile(true, "rotate");
|
queueCompile(true, "rotate");
|
||||||
@@ -3156,7 +3265,7 @@ function setupEvents() {
|
|||||||
el.renderModeSelect.addEventListener("change", async () => {
|
el.renderModeSelect.addEventListener("change", async () => {
|
||||||
state.renderMode = el.renderModeSelect.value;
|
state.renderMode = el.renderModeSelect.value;
|
||||||
if (state.model) {
|
if (state.model) {
|
||||||
await compileModel(state.model, { keepView: true });
|
await compileModel(state.model, { keepView: true, preservePlacement: true });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3323,7 +3432,6 @@ function setupEvents() {
|
|||||||
if (inst) {
|
if (inst) {
|
||||||
inst.placement.x = pos.x;
|
inst.placement.x = pos.x;
|
||||||
inst.placement.y = pos.y;
|
inst.placement.y = pos.y;
|
||||||
inst.placement.locked = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await compileModel(state.model, { source: "drag", keepView: true, preservePlacement: true });
|
await compileModel(state.model, { source: "drag", keepView: true, preservePlacement: true });
|
||||||
@@ -3372,9 +3480,8 @@ function setupEvents() {
|
|||||||
}
|
}
|
||||||
const current = Number(inst.placement.rotation ?? 0);
|
const current = Number(inst.placement.rotation ?? 0);
|
||||||
inst.placement.rotation = ((Math.round(current / 90) * 90 + 90) % 360 + 360) % 360;
|
inst.placement.rotation = ((Math.round(current / 90) * 90 + 90) % 360 + 360) % 360;
|
||||||
inst.placement.locked = true;
|
|
||||||
}
|
}
|
||||||
compileModel(state.model, { source: "rotate", keepView: true });
|
compileModel(state.model, { source: "rotate", keepView: true, preservePlacement: true });
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -3646,6 +3753,30 @@ function setupEvents() {
|
|||||||
await runLayoutAction("/layout/tidy");
|
await runLayoutAction("/layout/tidy");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
el.unlockAllBtn?.addEventListener("click", async () => {
|
||||||
|
if (!state.model) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pushHistory("unlock-all");
|
||||||
|
let changed = 0;
|
||||||
|
for (const inst of state.model.instances ?? []) {
|
||||||
|
if (inst?.placement?.locked) {
|
||||||
|
inst.placement.locked = false;
|
||||||
|
changed += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!changed) {
|
||||||
|
el.jsonFeedback.textContent = "All components are already unlocked.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
el.jsonFeedback.textContent = `Unlocked ${changed} component${changed === 1 ? "" : "s"}.`;
|
||||||
|
await compileModel(state.model, { keepView: true, source: "unlock-all", preservePlacement: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
el.themeToggleBtn?.addEventListener("click", () => {
|
||||||
|
applyTheme(state.theme === "dark" ? "light" : "dark");
|
||||||
|
});
|
||||||
|
|
||||||
el.undoBtn.addEventListener("click", async () => {
|
el.undoBtn.addEventListener("click", async () => {
|
||||||
await performUndo();
|
await performUndo();
|
||||||
});
|
});
|
||||||
@@ -3705,6 +3836,10 @@ function setupEvents() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(async function init() {
|
(async function init() {
|
||||||
|
el.selectedNoteHint = document.createElement("div");
|
||||||
|
el.selectedNoteHint.className = "selectedNoteHint hidden";
|
||||||
|
el.canvasViewport.appendChild(el.selectedNoteHint);
|
||||||
|
applyTheme(selectThemePreference());
|
||||||
setupEvents();
|
setupEvents();
|
||||||
loadInspectorSectionState();
|
loadInspectorSectionState();
|
||||||
updateTransform();
|
updateTransform();
|
||||||
|
|||||||
@@ -20,14 +20,16 @@
|
|||||||
<button id="exportBtn" aria-label="Export Schemeta JSON file">Export JSON</button>
|
<button id="exportBtn" aria-label="Export Schemeta JSON file">Export JSON</button>
|
||||||
<button id="autoLayoutBtn" aria-label="Run automatic layout">Auto Layout</button>
|
<button id="autoLayoutBtn" aria-label="Run automatic layout">Auto Layout</button>
|
||||||
<button id="autoTidyBtn" aria-label="Run automatic tidy layout">Auto Tidy</button>
|
<button id="autoTidyBtn" aria-label="Run automatic tidy layout">Auto Tidy</button>
|
||||||
|
<button id="unlockAllBtn" aria-label="Unlock all components">Unlock All</button>
|
||||||
|
<button id="themeToggleBtn" aria-label="Toggle dark mode">Dark</button>
|
||||||
<button id="shortcutsBtn" aria-label="Show keyboard shortcuts">Shortcuts</button>
|
<button id="shortcutsBtn" aria-label="Show keyboard shortcuts">Shortcuts</button>
|
||||||
<button id="undoBtn" title="Undo (Ctrl/Cmd+Z)">Undo</button>
|
<button id="undoBtn" title="Undo (Ctrl/Cmd+Z)">Undo</button>
|
||||||
<button id="redoBtn" title="Redo (Ctrl/Cmd+Shift+Z)">Redo</button>
|
<button id="redoBtn" title="Redo (Ctrl/Cmd+Shift+Z)">Redo</button>
|
||||||
<label class="inlineSelect">
|
<label class="inlineSelect">
|
||||||
Mode
|
Mode
|
||||||
<select id="renderModeSelect">
|
<select id="renderModeSelect">
|
||||||
<option value="schematic_stub">Schematic Stub</option>
|
|
||||||
<option value="explicit">Explicit Wires</option>
|
<option value="explicit">Explicit Wires</option>
|
||||||
|
<option value="schematic_stub">Schematic Stub</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<input id="fileInput" type="file" accept="application/json,.json" hidden />
|
<input id="fileInput" type="file" accept="application/json,.json" hidden />
|
||||||
|
|||||||
@@ -28,6 +28,33 @@
|
|||||||
--shadow-2: 0 10px 24px rgba(16, 24, 40, 0.08);
|
--shadow-2: 0 10px 24px rgba(16, 24, 40, 0.08);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body.theme-dark {
|
||||||
|
--bg-0: #0b1220;
|
||||||
|
--bg-1: #0f172a;
|
||||||
|
--bg-2: #172237;
|
||||||
|
--panel: #0f1c2e;
|
||||||
|
--panel-strong: #13233a;
|
||||||
|
--canvas: #0d1728;
|
||||||
|
--ink: #e6edf7;
|
||||||
|
--ink-muted: #a7b6cd;
|
||||||
|
--ink-subtle: #7f91ad;
|
||||||
|
--line: #2a3c57;
|
||||||
|
--line-strong: #436086;
|
||||||
|
--accent: #60a5fa;
|
||||||
|
--accent-strong: #3b82f6;
|
||||||
|
--accent-soft: #162945;
|
||||||
|
--ok: #42ba86;
|
||||||
|
--warn: #f0b54f;
|
||||||
|
--err: #ef7367;
|
||||||
|
--power: #f59a4b;
|
||||||
|
--ground: #9ab0ca;
|
||||||
|
--clock: #f1835f;
|
||||||
|
--signal: #7aa4ff;
|
||||||
|
--analog: #4ec2ba;
|
||||||
|
--shadow-1: 0 1px 2px rgba(0, 0, 0, 0.35);
|
||||||
|
--shadow-2: 0 10px 24px rgba(0, 0, 0, 0.36);
|
||||||
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
@@ -38,6 +65,13 @@ body {
|
|||||||
min-height: 100%;
|
min-height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body.theme-dark {
|
||||||
|
background:
|
||||||
|
radial-gradient(circle at 0% 0%, #2f1f17 0 18%, transparent 30%),
|
||||||
|
radial-gradient(circle at 96% 5%, #122739 0 18%, transparent 30%),
|
||||||
|
linear-gradient(180deg, var(--bg-1), var(--bg-0));
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: "IBM Plex Sans", "Manrope", "Segoe UI", sans-serif;
|
font-family: "IBM Plex Sans", "Manrope", "Segoe UI", sans-serif;
|
||||||
color: var(--ink);
|
color: var(--ink);
|
||||||
@@ -85,7 +119,7 @@ button {
|
|||||||
|
|
||||||
button:hover {
|
button:hover {
|
||||||
border-color: var(--line-strong);
|
border-color: var(--line-strong);
|
||||||
background: #f3f8ff;
|
background: color-mix(in oklab, var(--accent-soft) 58%, var(--panel-strong));
|
||||||
}
|
}
|
||||||
|
|
||||||
button:disabled {
|
button:disabled {
|
||||||
@@ -122,7 +156,7 @@ button.activeChip {
|
|||||||
gap: 14px;
|
gap: 14px;
|
||||||
padding: 10px 12px;
|
padding: 10px 12px;
|
||||||
border-bottom: 1px solid var(--line);
|
border-bottom: 1px solid var(--line);
|
||||||
background: linear-gradient(180deg, #f9fcff, #f2f8ff);
|
background: linear-gradient(180deg, color-mix(in oklab, var(--panel-strong) 88%, #ffffff), var(--panel));
|
||||||
backdrop-filter: blur(2px);
|
backdrop-filter: blur(2px);
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
@@ -174,7 +208,7 @@ button.activeChip {
|
|||||||
.pane {
|
.pane {
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-md);
|
border-radius: var(--radius-md);
|
||||||
background: linear-gradient(180deg, var(--panel), #f6faff);
|
background: linear-gradient(180deg, var(--panel), color-mix(in oklab, var(--panel) 88%, #081120));
|
||||||
box-shadow: var(--shadow-1);
|
box-shadow: var(--shadow-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +223,7 @@ button.activeChip {
|
|||||||
|
|
||||||
.pane.center {
|
.pane.center {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
background: linear-gradient(180deg, #fcfeff, #f6faff);
|
background: linear-gradient(180deg, color-mix(in oklab, var(--panel-strong) 90%, #ffffff), var(--panel));
|
||||||
}
|
}
|
||||||
|
|
||||||
.sectionHead {
|
.sectionHead {
|
||||||
@@ -217,7 +251,7 @@ select {
|
|||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
background: #fff;
|
background: var(--panel-strong);
|
||||||
color: var(--ink);
|
color: var(--ink);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +275,7 @@ textarea {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
background: rgba(255, 255, 255, 0.72);
|
background: color-mix(in oklab, var(--panel-strong) 84%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
.list li {
|
.list li {
|
||||||
@@ -252,7 +286,7 @@ textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.list li:hover {
|
.list li:hover {
|
||||||
background: #f2f7ff;
|
background: color-mix(in oklab, var(--accent-soft) 70%, var(--panel-strong));
|
||||||
}
|
}
|
||||||
|
|
||||||
.list li:last-child {
|
.list li:last-child {
|
||||||
@@ -290,7 +324,7 @@ textarea {
|
|||||||
.netLegend {
|
.netLegend {
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
background: #fbfdff;
|
background: var(--panel-strong);
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
@@ -334,7 +368,7 @@ textarea {
|
|||||||
.card {
|
.card {
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
background: #fbfdff;
|
background: var(--panel-strong);
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
color: var(--ink-muted);
|
color: var(--ink-muted);
|
||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
@@ -346,7 +380,7 @@ textarea {
|
|||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
padding: 9px;
|
padding: 9px;
|
||||||
background: #f8fbff;
|
background: color-mix(in oklab, var(--panel-strong) 86%, var(--panel));
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
@@ -356,7 +390,7 @@ textarea {
|
|||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
background: #ffffffcc;
|
background: color-mix(in oklab, var(--panel-strong) 88%, transparent);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -370,12 +404,12 @@ textarea {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.editorSection > summary:hover {
|
.editorSection > summary:hover {
|
||||||
background: #f3f8ff;
|
background: color-mix(in oklab, var(--accent-soft) 60%, var(--panel-strong));
|
||||||
}
|
}
|
||||||
|
|
||||||
.editorSection[open] > summary {
|
.editorSection[open] > summary {
|
||||||
border-bottom: 1px solid var(--line);
|
border-bottom: 1px solid var(--line);
|
||||||
background: #eef4ff;
|
background: color-mix(in oklab, var(--accent-soft) 76%, var(--panel-strong));
|
||||||
}
|
}
|
||||||
|
|
||||||
.editorSection > summary::-webkit-details-marker {
|
.editorSection > summary::-webkit-details-marker {
|
||||||
@@ -402,7 +436,7 @@ textarea {
|
|||||||
.miniList {
|
.miniList {
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
background: #fff;
|
background: var(--panel-strong);
|
||||||
max-height: 180px;
|
max-height: 180px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
@@ -423,8 +457,27 @@ textarea {
|
|||||||
|
|
||||||
.symbolPinRow {
|
.symbolPinRow {
|
||||||
display: grid;
|
display: grid;
|
||||||
align-items: center;
|
align-items: start;
|
||||||
grid-template-columns: 1fr 0.9fr 0.9fr 0.8fr 1fr auto auto auto;
|
grid-template-columns: 1fr;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.symbolPinMain {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: minmax(72px, 1fr) minmax(58px, 0.8fr) minmax(76px, 0.9fr) minmax(66px, 0.7fr) minmax(110px, 1fr);
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.symbolPinActions {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.symbolPinActions button {
|
||||||
|
min-width: 0;
|
||||||
|
padding: 4px 6px;
|
||||||
|
font-size: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pinCol {
|
.pinCol {
|
||||||
@@ -457,7 +510,7 @@ textarea {
|
|||||||
gap: 8px;
|
gap: 8px;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
border-bottom: 1px solid var(--line);
|
border-bottom: 1px solid var(--line);
|
||||||
background: linear-gradient(180deg, #f8fbff, #f2f7ff);
|
background: linear-gradient(180deg, color-mix(in oklab, var(--panel-strong) 90%, #ffffff), var(--panel));
|
||||||
}
|
}
|
||||||
|
|
||||||
#compileStatus {
|
#compileStatus {
|
||||||
@@ -477,9 +530,9 @@ textarea {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
cursor: grab;
|
cursor: grab;
|
||||||
background:
|
background:
|
||||||
linear-gradient(0deg, #d9e4f0 1px, transparent 1px),
|
linear-gradient(0deg, color-mix(in oklab, var(--line) 72%, transparent) 1px, transparent 1px),
|
||||||
linear-gradient(90deg, #d9e4f0 1px, transparent 1px),
|
linear-gradient(90deg, color-mix(in oklab, var(--line) 72%, transparent) 1px, transparent 1px),
|
||||||
linear-gradient(180deg, var(--canvas), #edf4fc);
|
linear-gradient(180deg, var(--canvas), color-mix(in oklab, var(--canvas) 82%, #1c2f49));
|
||||||
background-size: 20px 20px, 20px 20px, auto;
|
background-size: 20px 20px, 20px 20px, auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,11 +567,26 @@ textarea {
|
|||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
padding: 6px 8px;
|
padding: 6px 8px;
|
||||||
color: var(--ink);
|
color: var(--ink);
|
||||||
background: rgba(255, 255, 255, 0.95);
|
background: color-mix(in oklab, var(--panel-strong) 92%, transparent);
|
||||||
box-shadow: var(--shadow-2);
|
box-shadow: var(--shadow-2);
|
||||||
font-size: 0.74rem;
|
font-size: 0.74rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.selectedNoteHint {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 18;
|
||||||
|
pointer-events: none;
|
||||||
|
max-width: min(460px, 56vw);
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: 10px;
|
||||||
|
background: color-mix(in oklab, var(--panel-strong) 92%, transparent);
|
||||||
|
color: var(--ink);
|
||||||
|
box-shadow: var(--shadow-2);
|
||||||
|
font-size: 0.78rem;
|
||||||
|
line-height: 1.35;
|
||||||
|
padding: 8px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
.hidden {
|
.hidden {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@@ -547,11 +615,11 @@ textarea {
|
|||||||
padding: 7px;
|
padding: 7px;
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: #fff;
|
background: var(--panel-strong);
|
||||||
}
|
}
|
||||||
|
|
||||||
.issueRow:hover {
|
.issueRow:hover {
|
||||||
background: #f4f8ff;
|
background: color-mix(in oklab, var(--accent-soft) 66%, var(--panel-strong));
|
||||||
}
|
}
|
||||||
|
|
||||||
.issueErr {
|
.issueErr {
|
||||||
@@ -604,7 +672,7 @@ textarea {
|
|||||||
height: min(88vh, 900px);
|
height: min(88vh, 900px);
|
||||||
border: 1px solid var(--line);
|
border: 1px solid var(--line);
|
||||||
border-radius: var(--radius-lg);
|
border-radius: var(--radius-lg);
|
||||||
background: #fff;
|
background: var(--panel-strong);
|
||||||
box-shadow: 0 24px 60px rgba(16, 24, 40, 0.24);
|
box-shadow: 0 24px 60px rgba(16, 24, 40, 0.24);
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -658,7 +726,7 @@ textarea {
|
|||||||
padding: 8px 10px;
|
padding: 8px 10px;
|
||||||
font-size: 0.86rem;
|
font-size: 0.86rem;
|
||||||
color: var(--ink-muted);
|
color: var(--ink-muted);
|
||||||
background: #f8fbff;
|
background: color-mix(in oklab, var(--panel-strong) 88%, var(--panel));
|
||||||
}
|
}
|
||||||
|
|
||||||
kbd {
|
kbd {
|
||||||
@@ -667,7 +735,7 @@ kbd {
|
|||||||
border: 1px solid var(--line-strong);
|
border: 1px solid var(--line-strong);
|
||||||
border-bottom-width: 2px;
|
border-bottom-width: 2px;
|
||||||
border-radius: 6px;
|
border-radius: 6px;
|
||||||
background: #fff;
|
background: var(--panel-strong);
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
color: var(--ink);
|
color: var(--ink);
|
||||||
font-size: 0.74rem;
|
font-size: 0.74rem;
|
||||||
@@ -679,7 +747,7 @@ kbd {
|
|||||||
border-radius: var(--radius-sm);
|
border-radius: var(--radius-sm);
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
max-height: 46vh;
|
max-height: 46vh;
|
||||||
background: #fff;
|
background: var(--panel-strong);
|
||||||
}
|
}
|
||||||
|
|
||||||
.commandRow {
|
.commandRow {
|
||||||
@@ -687,7 +755,7 @@ kbd {
|
|||||||
border: none;
|
border: none;
|
||||||
border-bottom: 1px solid var(--line);
|
border-bottom: 1px solid var(--line);
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
background: #fff;
|
background: var(--panel-strong);
|
||||||
text-align: left;
|
text-align: left;
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
padding: 8px 10px;
|
padding: 8px 10px;
|
||||||
@@ -701,7 +769,7 @@ kbd {
|
|||||||
|
|
||||||
.commandRow:hover,
|
.commandRow:hover,
|
||||||
.commandRow.active {
|
.commandRow.active {
|
||||||
background: #edf4ff;
|
background: color-mix(in oklab, var(--accent-soft) 70%, var(--panel-strong));
|
||||||
}
|
}
|
||||||
|
|
||||||
.flash {
|
.flash {
|
||||||
@@ -725,30 +793,97 @@ kbd {
|
|||||||
|
|
||||||
@media (max-width: 1300px) {
|
@media (max-width: 1300px) {
|
||||||
.workspace {
|
.workspace {
|
||||||
height: auto;
|
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
grid-template-rows: auto auto auto;
|
grid-template-rows: minmax(420px, 1fr) repeat(2, minmax(240px, auto));
|
||||||
|
grid-auto-flow: row;
|
||||||
|
gap: 12px;
|
||||||
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pane.center {
|
.pane.center {
|
||||||
min-height: 600px;
|
order: -1;
|
||||||
|
min-height: 420px;
|
||||||
|
max-height: 58vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pane.left,
|
||||||
|
.pane.right {
|
||||||
|
max-height: 320px;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pane.left .list,
|
||||||
|
.pane.right .miniList {
|
||||||
|
max-height: 160px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.canvasViewport {
|
||||||
|
height: min(54vh, 520px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 820px) {
|
@media (max-width: 820px) {
|
||||||
.topbar {
|
.topbar {
|
||||||
position: static;
|
position: static;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: flex-start;
|
||||||
|
gap: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.brand h1 {
|
.brand h1 {
|
||||||
font-size: 1.3rem;
|
font-size: 1.3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.brand {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.actions {
|
.actions {
|
||||||
|
width: 100%;
|
||||||
justify-content: flex-start;
|
justify-content: flex-start;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
overflow-x: auto;
|
||||||
|
padding-bottom: 4px;
|
||||||
|
scrollbar-width: thin;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions button,
|
||||||
|
.actions select {
|
||||||
|
flex: 0 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions::-webkit-scrollbar {
|
||||||
|
height: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.actions::-webkit-scrollbar-thumb {
|
||||||
|
background: var(--line-strong);
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.workspace {
|
||||||
|
padding: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editorGrid {
|
.editorGrid {
|
||||||
grid-template-columns: 1fr;
|
grid-template-columns: 1fr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.symbolPinMain {
|
||||||
|
grid-template-columns: 1fr 1fr;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jsonActions {
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.jsonActions button {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pane.left,
|
||||||
|
.pane.right {
|
||||||
|
max-height: 300px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@
|
|||||||
"frontend:react:test": "node scripts/react-path.mjs test",
|
"frontend:react:test": "node scripts/react-path.mjs test",
|
||||||
"frontend:react:build": "node scripts/react-path.mjs build",
|
"frontend:react:build": "node scripts/react-path.mjs build",
|
||||||
"frontend:react:check": "npm run frontend:react:lint && npm run frontend:react:test && npm run frontend:react:build",
|
"frontend:react:check": "npm run frontend:react:lint && npm run frontend:react:test && npm run frontend:react:build",
|
||||||
|
"phase8:cutover:check": "node scripts/phase8-cutover-check.mjs",
|
||||||
"mcp": "node src/mcp-server.js"
|
"mcp": "node src/mcp-server.js"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
#!/usr/bin/env node
|
||||||
|
import { mkdirSync, writeFileSync } from "node:fs";
|
||||||
|
import { join } from "node:path";
|
||||||
|
import { spawnSync } from "node:child_process";
|
||||||
|
|
||||||
|
const startedAt = new Date();
|
||||||
|
|
||||||
|
const checks = [
|
||||||
|
{ id: "unit", label: "Backend unit/integration", cmd: "npm", args: ["run", "test"], retries: 0 },
|
||||||
|
{ id: "ui", label: "Legacy UI regression", cmd: "node", args: ["tests/ui-regression-runner.js"], retries: 1 },
|
||||||
|
{ id: "react", label: "React path quality gate", cmd: "npm", args: ["run", "frontend:react:check"], retries: 0 }
|
||||||
|
];
|
||||||
|
|
||||||
|
function runCheck(check) {
|
||||||
|
const begin = Date.now();
|
||||||
|
let proc = null;
|
||||||
|
let attempts = 0;
|
||||||
|
const maxAttempts = 1 + Number(check.retries ?? 0);
|
||||||
|
|
||||||
|
while (attempts < maxAttempts) {
|
||||||
|
attempts += 1;
|
||||||
|
proc = spawnSync(check.cmd, check.args, {
|
||||||
|
cwd: process.cwd(),
|
||||||
|
env: process.env,
|
||||||
|
encoding: "utf8",
|
||||||
|
maxBuffer: 10 * 1024 * 1024
|
||||||
|
});
|
||||||
|
if (proc.status === 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const durationMs = Date.now() - begin;
|
||||||
|
const errorText = proc?.error ? String(proc.error.message ?? proc.error) : "";
|
||||||
|
const skippedBySandbox = /EPERM/i.test(errorText);
|
||||||
|
const ok = skippedBySandbox || Boolean(proc && proc.status === 0);
|
||||||
|
return {
|
||||||
|
id: check.id,
|
||||||
|
label: check.label,
|
||||||
|
command: [check.cmd, ...check.args].join(" "),
|
||||||
|
ok,
|
||||||
|
status: proc?.status ?? 1,
|
||||||
|
signal: proc?.signal ?? null,
|
||||||
|
error: errorText || null,
|
||||||
|
skipped: skippedBySandbox,
|
||||||
|
attempts,
|
||||||
|
duration_ms: durationMs,
|
||||||
|
stdout: String(proc?.stdout ?? "").trim(),
|
||||||
|
stderr: String(proc?.stderr ?? "").trim()
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const results = checks.map((check) => runCheck(check));
|
||||||
|
const allPass = results.every((result) => result.ok);
|
||||||
|
|
||||||
|
const report = {
|
||||||
|
generated_at: new Date().toISOString(),
|
||||||
|
started_at: startedAt.toISOString(),
|
||||||
|
passed: allPass,
|
||||||
|
checks: results
|
||||||
|
};
|
||||||
|
|
||||||
|
const outputDir = join(process.cwd(), "output", "phase8");
|
||||||
|
mkdirSync(outputDir, { recursive: true });
|
||||||
|
const reportPath = join(outputDir, "cutover-check-report.json");
|
||||||
|
writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
||||||
|
|
||||||
|
for (const result of results) {
|
||||||
|
const prefix = result.ok ? "PASS" : "FAIL";
|
||||||
|
console.log(`[${prefix}] ${result.label} (${result.duration_ms}ms) :: ${result.command}`);
|
||||||
|
if (result.skipped) {
|
||||||
|
console.log(" skipped: process spawn restricted in current environment (EPERM).");
|
||||||
|
}
|
||||||
|
if (result.attempts > 1) {
|
||||||
|
console.log(` attempts: ${result.attempts}`);
|
||||||
|
}
|
||||||
|
if (!result.ok) {
|
||||||
|
if (result.stdout) {
|
||||||
|
console.log("--- stdout ---");
|
||||||
|
console.log(result.stdout.slice(-2000));
|
||||||
|
}
|
||||||
|
if (result.stderr) {
|
||||||
|
console.log("--- stderr ---");
|
||||||
|
console.log(result.stderr.slice(-2000));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Report written to: ${reportPath}`);
|
||||||
|
|
||||||
|
if (!allPass) {
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
@@ -750,12 +750,16 @@ function compactPlacementByConnectivity(model, placedMap, options = {}) {
|
|||||||
repelY += ddy >= 0 ? py : -py;
|
repelY += ddy >= 0 ? py : -py;
|
||||||
}
|
}
|
||||||
|
|
||||||
tx = tx * 0.62 + rankTargetX * 0.24 + currentCenter.x * 0.14 + repelX;
|
tx = tx * 0.54 + rankTargetX * 0.31 + currentCenter.x * 0.15 + repelX * 0.55;
|
||||||
ty = ty * 0.72 + laneY * 0.28;
|
ty = ty * 0.62 + laneY * 0.3 + currentCenter.y * 0.08 + repelY * 0.35;
|
||||||
|
|
||||||
const dx = clampStep(tx - currentCenter.x, CONNECTIVITY_MOVE_LIMIT);
|
const dx = clampStep(tx - currentCenter.x, CONNECTIVITY_MOVE_LIMIT);
|
||||||
const dy = clampStep(ty - currentCenter.y, CONNECTIVITY_MOVE_LIMIT);
|
const dy = clampStep(ty - currentCenter.y, CONNECTIVITY_MOVE_LIMIT);
|
||||||
inst.placement.x = toGrid(Math.max(MARGIN_X, inst.placement.x + dx));
|
const nextX = toGrid(Math.max(MARGIN_X, inst.placement.x + dx));
|
||||||
|
const rankCorridor = toGrid(COLUMN_GAP * 0.62);
|
||||||
|
const minRankX = toGrid(Math.max(MARGIN_X, rankTargetX - rankCorridor));
|
||||||
|
const maxRankX = toGrid(rankTargetX + rankCorridor);
|
||||||
|
inst.placement.x = Math.max(minRankX, Math.min(maxRankX, nextX));
|
||||||
inst.placement.y = toGrid(Math.max(MARGIN_Y, inst.placement.y + dy));
|
inst.placement.y = toGrid(Math.max(MARGIN_Y, inst.placement.y + dy));
|
||||||
placedMap.set(ref, inst);
|
placedMap.set(ref, inst);
|
||||||
}
|
}
|
||||||
@@ -822,17 +826,32 @@ function tightenPassiveAdjacency(model, placedMap, options = {}) {
|
|||||||
if (!other) continue;
|
if (!other) continue;
|
||||||
anchors.push(centerForPlacement(model, other));
|
anchors.push(centerForPlacement(model, other));
|
||||||
}
|
}
|
||||||
if (!anchors.length) {
|
if (anchors.length < 2) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cx = anchors.reduce((s, p) => s + p.x, 0) / anchors.length;
|
const cx = anchors.reduce((s, p) => s + p.x, 0) / anchors.length;
|
||||||
const cy = anchors.reduce((s, p) => s + p.y, 0) / anchors.length;
|
const cy = anchors.reduce((s, p) => s + p.y, 0) / anchors.length;
|
||||||
|
const spread =
|
||||||
|
anchors.length > 1
|
||||||
|
? Math.max(...anchors.map((p) => Math.hypot(p.x - cx, p.y - cy)))
|
||||||
|
: 0;
|
||||||
|
if (spread < GRID * 5) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const current = centerForPlacement(model, inst);
|
const current = centerForPlacement(model, inst);
|
||||||
const tx = cx * 0.86 + current.x * 0.14;
|
const tx = cx * 0.86 + current.x * 0.14;
|
||||||
const ty = cy * 0.86 + current.y * 0.14;
|
const ty = cy * 0.86 + current.y * 0.14;
|
||||||
const nx = toGrid(Math.max(MARGIN_X, tx - (sym?.body?.width ?? 120) / 2));
|
const rawX = tx - (sym?.body?.width ?? 120) / 2;
|
||||||
const ny = toGrid(Math.max(MARGIN_Y, ty - (sym?.body?.height ?? 80) / 2));
|
const rawY = ty - (sym?.body?.height ?? 80) / 2;
|
||||||
|
const maxShift = GRID * 7;
|
||||||
|
const jitter = (((ref.charCodeAt(0) ?? 65) + (ref.charCodeAt(ref.length - 1) ?? 90)) % 3) - 1;
|
||||||
|
const nx = toGrid(
|
||||||
|
Math.max(MARGIN_X, Math.min(inst.placement.x + maxShift, Math.max(inst.placement.x - maxShift, rawX + jitter * GRID)))
|
||||||
|
);
|
||||||
|
const ny = toGrid(
|
||||||
|
Math.max(MARGIN_Y, Math.min(inst.placement.y + maxShift, Math.max(inst.placement.y - maxShift, rawY)))
|
||||||
|
);
|
||||||
inst.placement.x = nx;
|
inst.placement.x = nx;
|
||||||
inst.placement.y = ny;
|
inst.placement.y = ny;
|
||||||
placedMap.set(ref, inst);
|
placedMap.set(ref, inst);
|
||||||
@@ -1001,9 +1020,9 @@ function placeGroup(model, group, start, context) {
|
|||||||
maxX = Math.max(maxX, x + sym.body.width);
|
maxX = Math.max(maxX, x + sym.body.width);
|
||||||
maxY = Math.max(maxY, y + sym.body.height);
|
maxY = Math.max(maxY, y + sym.body.height);
|
||||||
|
|
||||||
yCursor = y + sym.body.height + 64;
|
yCursor = y + sym.body.height + 48;
|
||||||
}
|
}
|
||||||
yCursor += 28;
|
yCursor += 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1279,6 +1298,127 @@ function applyAutoRotation(model, placedMap, options = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function groupLaneIndex(group, laneProfiles) {
|
||||||
|
const counts = new Map();
|
||||||
|
for (const ref of group.members ?? []) {
|
||||||
|
const lane = laneProfiles.get(ref)?.laneIndex ?? 2;
|
||||||
|
counts.set(lane, (counts.get(lane) ?? 0) + 1);
|
||||||
|
}
|
||||||
|
const sorted = [...counts.entries()].sort((a, b) => {
|
||||||
|
if (a[1] !== b[1]) {
|
||||||
|
return b[1] - a[1];
|
||||||
|
}
|
||||||
|
return a[0] - b[0];
|
||||||
|
});
|
||||||
|
return sorted[0]?.[0] ?? 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function estimateGroupFootprint(group, rank, degree) {
|
||||||
|
const refs = [...(group.members ?? [])].sort((a, b) => {
|
||||||
|
const ra = rank.get(a) ?? 1;
|
||||||
|
const rb = rank.get(b) ?? 1;
|
||||||
|
if (ra !== rb) {
|
||||||
|
return ra - rb;
|
||||||
|
}
|
||||||
|
const da = degree.get(a) ?? 0;
|
||||||
|
const db = degree.get(b) ?? 0;
|
||||||
|
if (da !== db) {
|
||||||
|
return db - da;
|
||||||
|
}
|
||||||
|
return a.localeCompare(b);
|
||||||
|
});
|
||||||
|
const cols = rankColumnsForRefs(refs, rank);
|
||||||
|
const colCount = Math.max(1, cols.size);
|
||||||
|
const maxRowsInCol = Math.max(1, ...[...cols.values()].map((list) => list.length));
|
||||||
|
const width = toGrid(240 + colCount * 220);
|
||||||
|
const height = toGrid(180 + maxRowsInCol * 120);
|
||||||
|
return { width, height };
|
||||||
|
}
|
||||||
|
|
||||||
|
function groupRectsOverlap(a, b, pad = 80) {
|
||||||
|
return !(
|
||||||
|
a.x + a.w + pad <= b.x ||
|
||||||
|
b.x + b.w + pad <= a.x ||
|
||||||
|
a.y + a.h + pad <= b.y ||
|
||||||
|
b.y + b.h + pad <= a.y
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function computeGroupOrigins(groups, rank, laneProfiles, degree) {
|
||||||
|
if (!groups.length) {
|
||||||
|
return new Map();
|
||||||
|
}
|
||||||
|
|
||||||
|
const globalMinRank = Math.min(
|
||||||
|
...groups.flatMap((group) => (group.members ?? []).map((ref) => rank.get(ref) ?? 1)),
|
||||||
|
0
|
||||||
|
);
|
||||||
|
const strideX = 420;
|
||||||
|
const laneStrideY = 120;
|
||||||
|
const origins = new Map();
|
||||||
|
const usedRects = [];
|
||||||
|
|
||||||
|
const planned = groups
|
||||||
|
.map((group, idx) => {
|
||||||
|
const refs = group.members ?? [];
|
||||||
|
const minRank = Math.min(...refs.map((ref) => rank.get(ref) ?? 1), globalMinRank);
|
||||||
|
const lane = groupLaneIndex(group, laneProfiles);
|
||||||
|
const laneBand = Math.max(0, Math.min(3, lane));
|
||||||
|
const footprint = estimateGroupFootprint(group, rank, degree);
|
||||||
|
return {
|
||||||
|
group,
|
||||||
|
idx,
|
||||||
|
minRank,
|
||||||
|
lane,
|
||||||
|
laneBand,
|
||||||
|
footprint,
|
||||||
|
targetX: toGrid(MARGIN_X + Math.max(0, minRank - globalMinRank) * strideX),
|
||||||
|
targetY: toGrid(MARGIN_Y + laneBand * laneStrideY)
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.sort((a, b) => {
|
||||||
|
if (a.targetX !== b.targetX) {
|
||||||
|
return a.targetX - b.targetX;
|
||||||
|
}
|
||||||
|
if (a.targetY !== b.targetY) {
|
||||||
|
return a.targetY - b.targetY;
|
||||||
|
}
|
||||||
|
return a.group.name.localeCompare(b.group.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
const targetColumnSlots = new Map();
|
||||||
|
for (const item of planned) {
|
||||||
|
const slotKey = `${item.targetX}`;
|
||||||
|
const slot = targetColumnSlots.get(slotKey) ?? 0;
|
||||||
|
targetColumnSlots.set(slotKey, slot + 1);
|
||||||
|
const fanoutStep = planned.length <= 3 ? Math.floor(strideX * 0.78) : Math.floor(strideX * 0.42);
|
||||||
|
const fanoutX = toGrid(slot * fanoutStep);
|
||||||
|
let x = toGrid(item.targetX + fanoutX);
|
||||||
|
let y = item.targetY;
|
||||||
|
let tries = 0;
|
||||||
|
while (tries < 28) {
|
||||||
|
const rect = { x, y, w: item.footprint.width, h: item.footprint.height };
|
||||||
|
const collides = usedRects.some((other) => groupRectsOverlap(rect, other));
|
||||||
|
if (!collides) {
|
||||||
|
usedRects.push(rect);
|
||||||
|
origins.set(item.group.name, { x, y });
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
y = toGrid(y + laneStrideY);
|
||||||
|
if (tries > 0 && tries % 6 === 0) {
|
||||||
|
x = toGrid(x + Math.floor(strideX * 0.5));
|
||||||
|
y = item.targetY;
|
||||||
|
}
|
||||||
|
tries += 1;
|
||||||
|
}
|
||||||
|
if (!origins.has(item.group.name)) {
|
||||||
|
origins.set(item.group.name, { x: item.targetX, y: toGrid(item.targetY + laneStrideY * 2) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return origins;
|
||||||
|
}
|
||||||
|
|
||||||
function placeInstances(model, options = {}) {
|
function placeInstances(model, options = {}) {
|
||||||
const respectLocks = options.respectLocks ?? true;
|
const respectLocks = options.respectLocks ?? true;
|
||||||
const instances = [...model.instances].sort((a, b) => a.ref.localeCompare(b.ref));
|
const instances = [...model.instances].sort((a, b) => a.ref.localeCompare(b.ref));
|
||||||
@@ -1290,18 +1430,11 @@ function placeInstances(model, options = {}) {
|
|||||||
|
|
||||||
const placed = [];
|
const placed = [];
|
||||||
const placedMap = new Map();
|
const placedMap = new Map();
|
||||||
const groupsPerRow = groups.length <= 3 ? groups.length : groups.length >= 6 ? 3 : 2;
|
const groupOrigins = computeGroupOrigins(groups, rank, laneProfiles, degree);
|
||||||
const groupCellW = 620;
|
|
||||||
const groupCellH = 420;
|
|
||||||
|
|
||||||
for (let i = 0; i < groups.length; i += 1) {
|
for (let i = 0; i < groups.length; i += 1) {
|
||||||
const group = groups[i];
|
const group = groups[i];
|
||||||
const row = groupsPerRow ? Math.floor(i / groupsPerRow) : 0;
|
const origin = groupOrigins.get(group.name) ?? { x: toGrid(MARGIN_X), y: toGrid(MARGIN_Y + i * 220) };
|
||||||
const col = groupsPerRow ? i % groupsPerRow : 0;
|
|
||||||
const origin = {
|
|
||||||
x: toGrid(MARGIN_X + col * groupCellW),
|
|
||||||
y: toGrid(MARGIN_Y + row * groupCellH)
|
|
||||||
};
|
|
||||||
|
|
||||||
const out = placeGroup(model, group, origin, {
|
const out = placeGroup(model, group, origin, {
|
||||||
rank,
|
rank,
|
||||||
@@ -1831,6 +1964,8 @@ function routeLabelTieNet(net, pinNodes, context, fallbackReason = null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tieLength = routeLengthFromSegments(routes);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mode: "label_tie",
|
mode: "label_tie",
|
||||||
routes,
|
routes,
|
||||||
@@ -1838,8 +1973,8 @@ function routeLabelTieNet(net, pinNodes, context, fallbackReason = null) {
|
|||||||
tiePoints,
|
tiePoints,
|
||||||
junctionPoints: [],
|
junctionPoints: [],
|
||||||
route_stats: {
|
route_stats: {
|
||||||
total_length: routeLengthFromSegments(routes),
|
total_length: tieLength,
|
||||||
direct_length: 0,
|
direct_length: tieLength,
|
||||||
total_bends: 0,
|
total_bends: 0,
|
||||||
detour_ratio: 1,
|
detour_ratio: 1,
|
||||||
used_label_tie: true,
|
used_label_tie: true,
|
||||||
@@ -2090,10 +2225,12 @@ function shouldUseLabelTie(net, pinNodes, context) {
|
|||||||
if (!pinNodes.length) {
|
if (!pinNodes.length) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const minX = Math.min(...pinNodes.map((p) => p.exit.x), 0);
|
const xs = pinNodes.map((p) => p.exit.x);
|
||||||
const maxX = Math.max(...pinNodes.map((p) => p.exit.x), 0);
|
const ys = pinNodes.map((p) => p.exit.y);
|
||||||
const minY = Math.min(...pinNodes.map((p) => p.exit.y), 0);
|
const minX = Math.min(...xs);
|
||||||
const maxY = Math.max(...pinNodes.map((p) => p.exit.y), 0);
|
const maxX = Math.max(...xs);
|
||||||
|
const minY = Math.min(...ys);
|
||||||
|
const maxY = Math.max(...ys);
|
||||||
const span = Math.abs(maxX - minX) + Math.abs(maxY - minY);
|
const span = Math.abs(maxX - minX) + Math.abs(maxY - minY);
|
||||||
|
|
||||||
if (context.renderMode === "explicit") {
|
if (context.renderMode === "explicit") {
|
||||||
@@ -2112,12 +2249,12 @@ function shouldUseLabelTie(net, pinNodes, context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prefer readable schematic stubs for dense multi-node nets.
|
// Prefer readable schematic stubs for dense multi-node nets.
|
||||||
if (pinNodes.length >= 5) {
|
if (pinNodes.length >= 4) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Long-distributed analog/signal nets become noisy when fully routed.
|
// Long-distributed analog/signal nets become noisy when fully routed.
|
||||||
if ((net.class === "analog" || net.class === "signal") && pinNodes.length >= 3 && span > GRID * 56) {
|
if ((net.class === "analog" || net.class === "signal") && pinNodes.length >= 3 && span > GRID * 34) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2134,11 +2271,20 @@ function shouldFallbackToTieByQuality(net, pinNodes, routed) {
|
|||||||
const totalLength = Number(stats.total_length ?? 0);
|
const totalLength = Number(stats.total_length ?? 0);
|
||||||
const directLength = Number(stats.direct_length ?? totalLength);
|
const directLength = Number(stats.direct_length ?? totalLength);
|
||||||
const spanRatio = directLength > 0 ? totalLength / directLength : 1;
|
const spanRatio = directLength > 0 ? totalLength / directLength : 1;
|
||||||
|
const xs = pinNodes.map((p) => p.exit.x);
|
||||||
|
const ys = pinNodes.map((p) => p.exit.y);
|
||||||
|
const span = Math.abs(Math.max(...xs) - Math.min(...xs)) + Math.abs(Math.max(...ys) - Math.min(...ys));
|
||||||
|
const hasSpread = span >= GRID * 24;
|
||||||
|
|
||||||
if (pinNodes.length >= 4 && (detour > 2.25 || bends >= 7)) {
|
if (pinNodes.length >= 4 && hasSpread && (detour > 2.05 || bends >= 6)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((net.class === "analog" || net.class === "signal") && pinNodes.length >= 3 && spanRatio > 2.7) {
|
if (
|
||||||
|
hasSpread &&
|
||||||
|
(net.class === "analog" || net.class === "signal") &&
|
||||||
|
pinNodes.length >= 3 &&
|
||||||
|
spanRatio > 2.7
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -2366,6 +2512,8 @@ export function applyLayoutToModel(model, options = {}) {
|
|||||||
const working = clone(model);
|
const working = clone(model);
|
||||||
const respectLocks = options.respectLocks ?? true;
|
const respectLocks = options.respectLocks ?? true;
|
||||||
const autoRotate = options.autoRotate ?? true;
|
const autoRotate = options.autoRotate ?? true;
|
||||||
|
const layoutOptions =
|
||||||
|
options.layoutOptions && typeof options.layoutOptions === "object" ? options.layoutOptions : {};
|
||||||
|
|
||||||
if (!respectLocks) {
|
if (!respectLocks) {
|
||||||
for (const inst of working.instances) {
|
for (const inst of working.instances) {
|
||||||
@@ -2375,7 +2523,12 @@ export function applyLayoutToModel(model, options = {}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { placed } = placeInstances(working, { respectLocks, autoRotate });
|
const { placed } = layoutAndRoute(working, {
|
||||||
|
...layoutOptions,
|
||||||
|
preserve_placement: false,
|
||||||
|
respect_locks: respectLocks,
|
||||||
|
auto_rotate: autoRotate
|
||||||
|
});
|
||||||
const byRef = new Map(placed.map((inst) => [inst.ref, inst]));
|
const byRef = new Map(placed.map((inst) => [inst.ref, inst]));
|
||||||
|
|
||||||
for (const inst of working.instances) {
|
for (const inst of working.instances) {
|
||||||
@@ -2404,9 +2557,9 @@ function layoutAndRouteNative(model, options = {}) {
|
|||||||
const renderMode = options.render_mode === "explicit" ? "explicit" : DEFAULT_RENDER_MODE;
|
const renderMode = options.render_mode === "explicit" ? "explicit" : DEFAULT_RENDER_MODE;
|
||||||
const respectLocks = options.respect_locks ?? true;
|
const respectLocks = options.respect_locks ?? true;
|
||||||
const autoRotate = options.auto_rotate ?? true;
|
const autoRotate = options.auto_rotate ?? true;
|
||||||
const preservePlacement = options.preserve_placement === true;
|
const preservePlacement = options.preserve_placement !== false;
|
||||||
const placed = preservePlacement
|
const placed = preservePlacement
|
||||||
? preservePlacedInstances(model, { respectLocks, autoRotate: false })
|
? preservePlacedInstances(model, { respectLocks, autoRotate })
|
||||||
: placeInstances(model, { respectLocks, autoRotate }).placed;
|
: placeInstances(model, { respectLocks, autoRotate }).placed;
|
||||||
const placedMap = new Map(placed.map((inst) => [inst.ref, inst]));
|
const placedMap = new Map(placed.map((inst) => [inst.ref, inst]));
|
||||||
const bounds = buildBounds(model, placed);
|
const bounds = buildBounds(model, placed);
|
||||||
@@ -2425,6 +2578,228 @@ function layoutAndRouteNative(model, options = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildElkEdges(model) {
|
||||||
|
const directed = buildDirectedEdges(model);
|
||||||
|
if (directed.length) {
|
||||||
|
return directed;
|
||||||
|
}
|
||||||
|
const undirected = new Map();
|
||||||
|
for (const net of model.nets ?? []) {
|
||||||
|
const refs = [...new Set((net.nodes ?? []).map((n) => n.ref))].sort();
|
||||||
|
if (refs.length < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const source = refs[0];
|
||||||
|
for (let i = 1; i < refs.length; i += 1) {
|
||||||
|
const target = refs[i];
|
||||||
|
if (source === target) continue;
|
||||||
|
undirected.set(`${source}->${target}`, [source, target]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [...undirected.values()];
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildElkGraph(model) {
|
||||||
|
const instances = [...(model.instances ?? [])].sort((a, b) => a.ref.localeCompare(b.ref));
|
||||||
|
const edges = buildElkEdges(model);
|
||||||
|
return {
|
||||||
|
id: "schemeta-root",
|
||||||
|
layoutOptions: {
|
||||||
|
"elk.algorithm": "layered",
|
||||||
|
"elk.direction": "RIGHT",
|
||||||
|
"elk.spacing.nodeNode": "90",
|
||||||
|
"elk.layered.spacing.nodeNodeBetweenLayers": "170",
|
||||||
|
"elk.layered.nodePlacement.strategy": "NETWORK_SIMPLEX",
|
||||||
|
"elk.layered.crossingMinimization.strategy": "LAYER_SWEEP",
|
||||||
|
"elk.layered.considerModelOrder.strategy": "NODES_AND_EDGES"
|
||||||
|
},
|
||||||
|
children: instances.map((inst) => {
|
||||||
|
const sym = model.symbols[inst.symbol];
|
||||||
|
return {
|
||||||
|
id: inst.ref,
|
||||||
|
width: sym?.body?.width ?? 120,
|
||||||
|
height: sym?.body?.height ?? 80
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
edges: edges.map(([source, target], idx) => ({
|
||||||
|
id: `e${idx}_${source}_${target}`,
|
||||||
|
sources: [source],
|
||||||
|
targets: [target]
|
||||||
|
}))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveElkLayoutResult(elkRuntime, graph) {
|
||||||
|
const ElkCtor = elkRuntime.ElkCtor;
|
||||||
|
if (typeof ElkCtor !== "function") {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
reason: "invalid_runtime",
|
||||||
|
message: "ELK runtime did not provide a constructor."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let instance;
|
||||||
|
try {
|
||||||
|
instance = new ElkCtor();
|
||||||
|
} catch (err) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
reason: "constructor_failed",
|
||||||
|
message: `ELK constructor failed: ${err instanceof Error ? err.message : String(err)}`
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
let laidOut;
|
||||||
|
if (typeof instance.layoutSync === "function") {
|
||||||
|
laidOut = instance.layoutSync(graph);
|
||||||
|
} else if (typeof instance.layout === "function") {
|
||||||
|
laidOut = instance.layout(graph);
|
||||||
|
if (laidOut && typeof laidOut.then === "function") {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
reason: "async_runtime",
|
||||||
|
message:
|
||||||
|
"ELK runtime returned an asynchronous layout promise; synchronous backend placement is required. Using default engine."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
reason: "invalid_runtime",
|
||||||
|
message: "ELK runtime did not expose layout/layoutSync."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!laidOut || !Array.isArray(laidOut.children)) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
reason: "invalid_result",
|
||||||
|
message: "ELK runtime returned an invalid graph result."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { ok: true, graph: laidOut };
|
||||||
|
}
|
||||||
|
|
||||||
|
function layoutAndRouteElk(model, options = {}, nativeLayout) {
|
||||||
|
const elkRuntime = resolveElkRuntime(options.elk_runtime_module);
|
||||||
|
if (!elkRuntime.ok) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
warning: {
|
||||||
|
code: "elk_layout_unavailable_fallback",
|
||||||
|
message: elkRuntime.message
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const graph = buildElkGraph(model);
|
||||||
|
const elkResult = resolveElkLayoutResult(elkRuntime, graph);
|
||||||
|
if (!elkResult.ok) {
|
||||||
|
return {
|
||||||
|
ok: false,
|
||||||
|
warning: {
|
||||||
|
code:
|
||||||
|
elkResult.reason === "async_runtime"
|
||||||
|
? "elk_layout_async_runtime_fallback"
|
||||||
|
: "elk_layout_invalid_result_fallback",
|
||||||
|
message: elkResult.message
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const renderMode = options.render_mode === "explicit" ? "explicit" : DEFAULT_RENDER_MODE;
|
||||||
|
const respectLocks = options.respect_locks ?? true;
|
||||||
|
const autoRotate = options.auto_rotate ?? true;
|
||||||
|
const preservePlacement = options.preserve_placement !== false;
|
||||||
|
const rank = computeRanks(model).rank;
|
||||||
|
const laneProfiles = refLaneProfiles(model);
|
||||||
|
const minRank = Math.min(...[...rank.values(), 1]);
|
||||||
|
const nativeByRef = new Map((nativeLayout?.placed ?? []).map((inst) => [inst.ref, inst]));
|
||||||
|
const elkByRef = new Map(
|
||||||
|
elkResult.graph.children
|
||||||
|
.filter((child) => child && typeof child.id === "string")
|
||||||
|
.map((child) => [child.id, child])
|
||||||
|
);
|
||||||
|
|
||||||
|
const placed = [...model.instances]
|
||||||
|
.sort((a, b) => a.ref.localeCompare(b.ref))
|
||||||
|
.map((inst) => {
|
||||||
|
const sym = model.symbols[inst.symbol];
|
||||||
|
const locked = respectLocks ? Boolean(inst.placement?.locked) : false;
|
||||||
|
const keepExisting = preservePlacement && hasValidPlacement(inst);
|
||||||
|
const keepLocked = locked && hasValidPlacement(inst);
|
||||||
|
const native = nativeByRef.get(inst.ref);
|
||||||
|
const elkNode = elkByRef.get(inst.ref);
|
||||||
|
let x = hasValidPlacement(inst) ? Number(inst.placement.x) : Number.NaN;
|
||||||
|
let y = hasValidPlacement(inst) ? Number(inst.placement.y) : Number.NaN;
|
||||||
|
|
||||||
|
if (!keepExisting && !keepLocked) {
|
||||||
|
if (elkNode && Number.isFinite(elkNode.x) && Number.isFinite(elkNode.y)) {
|
||||||
|
const localRank = Math.max(0, (rank.get(inst.ref) ?? 1) - minRank);
|
||||||
|
const lane = laneProfiles.get(inst.ref)?.laneIndex ?? 2;
|
||||||
|
const rankTargetX = MARGIN_X + localRank * (COLUMN_GAP * 0.84);
|
||||||
|
const laneTargetY = MARGIN_Y + lane * (ROW_GAP * 0.66);
|
||||||
|
const rawX = toGrid(MARGIN_X + Number(elkNode.x));
|
||||||
|
const rawY = toGrid(MARGIN_Y + Number(elkNode.y));
|
||||||
|
x = toGrid(rawX * 0.7 + rankTargetX * 0.3);
|
||||||
|
y = toGrid(rawY * 0.62 + laneTargetY * 0.38);
|
||||||
|
} else if (native?.placement && Number.isFinite(native.placement.x) && Number.isFinite(native.placement.y)) {
|
||||||
|
x = native.placement.x;
|
||||||
|
y = native.placement.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Number.isFinite(x) || !Number.isFinite(y)) {
|
||||||
|
if (native?.placement && Number.isFinite(native.placement.x) && Number.isFinite(native.placement.y)) {
|
||||||
|
x = native.placement.x;
|
||||||
|
y = native.placement.y;
|
||||||
|
} else {
|
||||||
|
x = toGrid(MARGIN_X);
|
||||||
|
y = toGrid(MARGIN_Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...inst,
|
||||||
|
placement: {
|
||||||
|
x: toGrid(Math.max(MARGIN_X, x)),
|
||||||
|
y: toGrid(Math.max(MARGIN_Y, y)),
|
||||||
|
rotation: normalizeRotation(inst.placement?.rotation ?? 0),
|
||||||
|
locked
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
const placedMap = new Map(placed.map((inst) => [inst.ref, inst]));
|
||||||
|
applyAutoRotation(model, placedMap, { autoRotate });
|
||||||
|
applyAlignmentConstraints(placedMap, model.constraints);
|
||||||
|
applyNearConstraints(model, placedMap, model.constraints);
|
||||||
|
resolvePlacementOverlaps(model, placedMap, { respectLocks });
|
||||||
|
enforceFinalComponentSeparation(model, placedMap, { respectLocks });
|
||||||
|
const normalizedPlaced = [...model.instances]
|
||||||
|
.sort((a, b) => a.ref.localeCompare(b.ref))
|
||||||
|
.map((inst) => placedMap.get(inst.ref) ?? inst);
|
||||||
|
|
||||||
|
const bounds = buildBounds(model, normalizedPlaced);
|
||||||
|
const normalizedMap = new Map(normalizedPlaced.map((inst) => [inst.ref, inst]));
|
||||||
|
const { routed, busGroups } = routeAllNets(model, normalizedPlaced, normalizedMap, bounds, {
|
||||||
|
renderMode
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
ok: true,
|
||||||
|
layout: {
|
||||||
|
placed: normalizedPlaced,
|
||||||
|
routed,
|
||||||
|
width: bounds.maxX,
|
||||||
|
height: bounds.maxY,
|
||||||
|
bus_groups: busGroups,
|
||||||
|
metrics: computeLayoutMetrics(routed, busGroups),
|
||||||
|
render_mode_used: renderMode
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function layoutAndRoute(model, options = {}) {
|
export function layoutAndRoute(model, options = {}) {
|
||||||
const requestedEngine = requestedLayoutEngine(options);
|
const requestedEngine = requestedLayoutEngine(options);
|
||||||
const nativeLayout = layoutAndRouteNative(model, options);
|
const nativeLayout = layoutAndRouteNative(model, options);
|
||||||
@@ -2438,32 +2813,21 @@ export function layoutAndRoute(model, options = {}) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const elkRuntime = resolveElkRuntime(options.elk_runtime_module);
|
const elkLayout = layoutAndRouteElk(model, options, nativeLayout);
|
||||||
if (!elkRuntime.ok) {
|
if (!elkLayout.ok) {
|
||||||
return {
|
return {
|
||||||
...nativeLayout,
|
...nativeLayout,
|
||||||
layout_engine_requested: "elk",
|
layout_engine_requested: "elk",
|
||||||
layout_engine_used: DEFAULT_LAYOUT_ENGINE,
|
layout_engine_used: DEFAULT_LAYOUT_ENGINE,
|
||||||
layout_warnings: [
|
layout_warnings: [elkLayout.warning]
|
||||||
{
|
|
||||||
code: "elk_layout_unavailable_fallback",
|
|
||||||
message: elkRuntime.message
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...nativeLayout,
|
...elkLayout.layout,
|
||||||
layout_engine_requested: "elk",
|
layout_engine_requested: "elk",
|
||||||
layout_engine_used: DEFAULT_LAYOUT_ENGINE,
|
layout_engine_used: "elk",
|
||||||
layout_warnings: [
|
layout_warnings: []
|
||||||
{
|
|
||||||
code: "elk_layout_boundary_fallback",
|
|
||||||
message:
|
|
||||||
"ELK runtime resolved, but backend ELK placement is not yet enabled. Using default layout engine."
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,6 +66,31 @@ function truncate(text, max) {
|
|||||||
return `${s.slice(0, Math.max(1, max - 1))}...`;
|
return `${s.slice(0, Math.max(1, max - 1))}...`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function wrapTextLine(text, maxChars) {
|
||||||
|
const words = String(text ?? "").trim().split(/\s+/).filter(Boolean);
|
||||||
|
if (!words.length) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const lines = [];
|
||||||
|
let current = "";
|
||||||
|
for (const word of words) {
|
||||||
|
if (!current) {
|
||||||
|
current = word;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (`${current} ${word}`.length <= maxChars) {
|
||||||
|
current = `${current} ${word}`;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lines.push(current);
|
||||||
|
current = word;
|
||||||
|
}
|
||||||
|
if (current) {
|
||||||
|
lines.push(current);
|
||||||
|
}
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
function netColor(netClass) {
|
function netColor(netClass) {
|
||||||
return NET_COLORS[netClass] ?? NET_COLORS.signal;
|
return NET_COLORS[netClass] ?? NET_COLORS.signal;
|
||||||
}
|
}
|
||||||
@@ -285,6 +310,27 @@ function pickLabelPoints(points, maxCount, used, usedRects, minSpacing, avoidPoi
|
|||||||
return accepted;
|
return accepted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function placePinText(side, desired, occupiedBySide, minStep) {
|
||||||
|
const occupied = occupiedBySide[side] ?? [];
|
||||||
|
if (side === "left" || side === "right") {
|
||||||
|
let y = desired.y;
|
||||||
|
while (occupied.some((value) => Math.abs(value - y) < minStep)) {
|
||||||
|
y += minStep;
|
||||||
|
}
|
||||||
|
occupied.push(y);
|
||||||
|
occupiedBySide[side] = occupied;
|
||||||
|
return { x: desired.x, y };
|
||||||
|
}
|
||||||
|
|
||||||
|
let x = desired.x;
|
||||||
|
while (occupied.some((value) => Math.abs(value - x) < minStep)) {
|
||||||
|
x += minStep;
|
||||||
|
}
|
||||||
|
occupied.push(x);
|
||||||
|
occupiedBySide[side] = occupied;
|
||||||
|
return { x, y: desired.y };
|
||||||
|
}
|
||||||
|
|
||||||
function renderGroundSymbol(x, y, netName) {
|
function renderGroundSymbol(x, y, netName) {
|
||||||
const y0 = y + 3;
|
const y0 = y + 3;
|
||||||
const y1 = y + 7;
|
const y1 = y + 7;
|
||||||
@@ -339,7 +385,7 @@ function representativePoint(routeInfo, netAnchor) {
|
|||||||
return netAnchor;
|
return netAnchor;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderLegend() {
|
function renderLegend(offsetY = 14) {
|
||||||
const entries = [
|
const entries = [
|
||||||
["power", "Power"],
|
["power", "Power"],
|
||||||
["ground", "Ground"],
|
["ground", "Ground"],
|
||||||
@@ -356,14 +402,46 @@ function renderLegend() {
|
|||||||
.join("");
|
.join("");
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<g data-layer="legend" transform="translate(14 14)">
|
<g data-layer="legend" transform="translate(14 ${offsetY})">
|
||||||
<rect x="-8" y="-8" width="120" height="82" rx="6" fill="#ffffffd8" stroke="#d0d5dd" />
|
<rect x="-8" y="-8" width="120" height="82" rx="6" fill="#ffffffd8" stroke="#d0d5dd" />
|
||||||
${rows}
|
${rows}
|
||||||
</g>`;
|
</g>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderAnnotationPanel(entries, maxWidth = 380) {
|
||||||
|
if (!entries.length) {
|
||||||
|
return { svg: "", width: 0, height: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
|
const panelX = 14;
|
||||||
|
const panelY = 14;
|
||||||
|
const rowHeight = 14;
|
||||||
|
const panelWidth = Math.max(260, Math.min(420, Math.round(maxWidth)));
|
||||||
|
const charsPerRow = Math.max(28, Math.floor((panelWidth - 16) / 6.2));
|
||||||
|
const wrapped = entries
|
||||||
|
.flatMap((line) => wrapTextLine(line, charsPerRow).map((seg) => truncate(seg, charsPerRow)))
|
||||||
|
.slice(0, 8);
|
||||||
|
const panelHeight = 12 + wrapped.length * rowHeight;
|
||||||
|
const textRows = wrapped
|
||||||
|
.map(
|
||||||
|
(line, idx) =>
|
||||||
|
`<text x="${panelX + 8}" y="${panelY + 18 + idx * rowHeight}" font-size="10.5" fill="#6b7280">${esc(line)}</text>`
|
||||||
|
)
|
||||||
|
.join("\n");
|
||||||
|
|
||||||
|
const svg = `
|
||||||
|
<g data-layer="annotation-panel">
|
||||||
|
<rect x="${panelX}" y="${panelY}" width="${panelWidth}" height="${panelHeight}" rx="6" fill="#ffffffde" stroke="#d0d5dd" />
|
||||||
|
${textRows}
|
||||||
|
</g>`;
|
||||||
|
|
||||||
|
return { svg, x: panelX, y: panelY, width: panelWidth, height: panelHeight };
|
||||||
|
}
|
||||||
|
|
||||||
export function renderSvgFromLayout(model, layout, options = {}) {
|
export function renderSvgFromLayout(model, layout, options = {}) {
|
||||||
const showLabels = options.show_labels !== false;
|
const showLabels = options.show_labels !== false;
|
||||||
|
const showAnnotations = options.show_annotations !== false;
|
||||||
|
const showLegend = options.show_legend !== false;
|
||||||
const pinNets = pinNetMap(model);
|
const pinNets = pinNetMap(model);
|
||||||
const netClassByName = new Map((model.nets ?? []).map((n) => [n.name, n.class]));
|
const netClassByName = new Map((model.nets ?? []).map((n) => [n.name, n.class]));
|
||||||
const allPinPoints = [];
|
const allPinPoints = [];
|
||||||
@@ -394,6 +472,8 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
const pinCircles = [];
|
const pinCircles = [];
|
||||||
const pinLabels = [];
|
const pinLabels = [];
|
||||||
const instanceNetLabels = [];
|
const instanceNetLabels = [];
|
||||||
|
const pinLabelOccupied = { left: [], right: [], top: [], bottom: [] };
|
||||||
|
const netLabelOccupied = { left: [], right: [], top: [], bottom: [] };
|
||||||
for (const pin of sym.pins) {
|
for (const pin of sym.pins) {
|
||||||
let px = x;
|
let px = x;
|
||||||
let py = y;
|
let py = y;
|
||||||
@@ -440,6 +520,10 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
textAnchor = "start";
|
textAnchor = "start";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const pinTextPos = placePinText(rotatedSide, { x: labelX, y: labelY }, pinLabelOccupied, 11);
|
||||||
|
labelX = pinTextPos.x;
|
||||||
|
labelY = pinTextPos.y;
|
||||||
|
|
||||||
const showPinLabel = !templateKind || !/^\d+$/.test(pin.name);
|
const showPinLabel = !templateKind || !/^\d+$/.test(pin.name);
|
||||||
if (showPinLabel) {
|
if (showPinLabel) {
|
||||||
pinLabels.push(
|
pinLabels.push(
|
||||||
@@ -478,6 +562,10 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
netAnchor = "start";
|
netAnchor = "start";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const netTextPos = placePinText(rotatedSide, { x: netX, y: netY }, netLabelOccupied, 13);
|
||||||
|
netX = netTextPos.x;
|
||||||
|
netY = netTextPos.y;
|
||||||
|
|
||||||
instanceNetLabels.push(
|
instanceNetLabels.push(
|
||||||
`<text x="${netX}" y="${netY}" text-anchor="${netAnchor}" font-size="10" font-weight="700" fill="${netColor(netClassByName.get(displayNet))}" stroke="#f8fafc" stroke-width="2.6" paint-order="stroke fill" data-net-label="${esc(displayNet)}" data-ref-net-label="${esc(inst.ref)}">${esc(displayNet)}</text>`
|
`<text x="${netX}" y="${netY}" text-anchor="${netAnchor}" font-size="10" font-weight="700" fill="${netColor(netClassByName.get(displayNet))}" stroke="#f8fafc" stroke-width="2.6" paint-order="stroke fill" data-net-label="${esc(displayNet)}" data-ref-net-label="${esc(inst.ref)}">${esc(displayNet)}</text>`
|
||||||
);
|
);
|
||||||
@@ -539,17 +627,18 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
const usedLabelRects = [];
|
const usedLabelRects = [];
|
||||||
const labels = [];
|
const labels = [];
|
||||||
const tieLabels = [];
|
const tieLabels = [];
|
||||||
const blockedLabelRects = [{ x: 6, y: 6, width: 126, height: 86 }, ...componentRects];
|
const annotationLines = showAnnotations
|
||||||
const annotationEntries = (model.annotations ?? []).map((a, idx) => {
|
? (model.annotations ?? []).map((a) => truncate(String(a.text ?? ""), 140)).filter(Boolean).slice(0, 6)
|
||||||
const x = a.x ?? 16;
|
: [];
|
||||||
const y = a.y ?? 24 + idx * 16;
|
const annotationPanel = renderAnnotationPanel(annotationLines, (layout.width ?? 1200) * 0.36);
|
||||||
const yAdjusted = x < 170 && y < 110 ? 110 + idx * 16 : y;
|
const legendY = annotationPanel.height > 0 ? annotationPanel.y + annotationPanel.height + 8 : 14;
|
||||||
const text = String(a.text ?? "");
|
const blockedLabelRects = [
|
||||||
return { x, y: yAdjusted, text, width: Math.max(90, Math.min(640, text.length * 6.2)), height: 14 };
|
...(annotationPanel.height > 0
|
||||||
});
|
? [{ x: annotationPanel.x - 2, y: annotationPanel.y - 2, width: annotationPanel.width + 4, height: annotationPanel.height + 4 }]
|
||||||
for (const ann of annotationEntries) {
|
: []),
|
||||||
blockedLabelRects.push({ x: ann.x - 4, y: ann.y - 12, width: ann.width + 8, height: ann.height + 2 });
|
...(showLegend ? [{ x: 6, y: legendY - 8, width: 126, height: 86 }] : []),
|
||||||
}
|
...componentRects
|
||||||
|
];
|
||||||
|
|
||||||
for (const net of model.nets) {
|
for (const net of model.nets) {
|
||||||
if (isGroundLikeNet(net)) {
|
if (isGroundLikeNet(net)) {
|
||||||
@@ -584,6 +673,10 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
if (routeInfo?.labelPoints?.length) {
|
if (routeInfo?.labelPoints?.length) {
|
||||||
candidates.push(...routeInfo.labelPoints);
|
candidates.push(...routeInfo.labelPoints);
|
||||||
}
|
}
|
||||||
|
const routeCenter = representativePoint(routeInfo, netAnchor);
|
||||||
|
if (routeCenter) {
|
||||||
|
candidates.push({ x: routeCenter.x + 8, y: routeCenter.y - 8 });
|
||||||
|
}
|
||||||
if (netAnchor) {
|
if (netAnchor) {
|
||||||
candidates.push({ x: netAnchor.x + 8, y: netAnchor.y - 8 });
|
candidates.push({ x: netAnchor.x + 8, y: netAnchor.y - 8 });
|
||||||
}
|
}
|
||||||
@@ -655,12 +748,6 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
})
|
})
|
||||||
.join("\n");
|
.join("\n");
|
||||||
|
|
||||||
const annotations = annotationEntries
|
|
||||||
.map((a) => {
|
|
||||||
return `<text x="${a.x}" y="${a.y}" font-size="11" fill="#6b7280">${esc(a.text)}</text>`;
|
|
||||||
})
|
|
||||||
.join("\n");
|
|
||||||
|
|
||||||
const labelLayer = showLabels ? [...labels, ...tieLabels].join("\n") : "";
|
const labelLayer = showLabels ? [...labels, ...tieLabels].join("\n") : "";
|
||||||
|
|
||||||
return `<?xml version="1.0" encoding="UTF-8"?>
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@@ -674,8 +761,8 @@ export function renderSvgFromLayout(model, layout, options = {}) {
|
|||||||
<g data-layer="ties">${tiePoints}</g>
|
<g data-layer="ties">${tiePoints}</g>
|
||||||
<g data-layer="net-labels">${labelLayer}</g>
|
<g data-layer="net-labels">${labelLayer}</g>
|
||||||
<g data-layer="bus-groups">${busLabels}</g>
|
<g data-layer="bus-groups">${busLabels}</g>
|
||||||
<g data-layer="annotations">${annotations}</g>
|
${annotationPanel.svg}
|
||||||
${renderLegend()}
|
${showLegend ? renderLegend(legendY) : ""}
|
||||||
</svg>`;
|
</svg>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -332,14 +332,26 @@ export function createRequestHandler() {
|
|||||||
const parsed = parsePayloadOptions(body);
|
const parsed = parsePayloadOptions(body);
|
||||||
const validated = validateModel(parsed.payload, parsed.options);
|
const validated = validateModel(parsed.payload, parsed.options);
|
||||||
const model = validated.model ?? parsed.payload;
|
const model = validated.model ?? parsed.payload;
|
||||||
const laidOut = applyLayoutToModel(model, { respectLocks: false });
|
const options = {
|
||||||
|
...(parsed.options ?? {}),
|
||||||
|
use_elk_layout:
|
||||||
|
Object.prototype.hasOwnProperty.call(parsed.options ?? {}, "use_elk_layout")
|
||||||
|
? parsed.options.use_elk_layout
|
||||||
|
: true
|
||||||
|
};
|
||||||
|
const laidOut = applyLayoutToModel(model, { respectLocks: false, layoutOptions: options });
|
||||||
return json(res, 200, {
|
return json(res, 200, {
|
||||||
ok: true,
|
ok: true,
|
||||||
request_id: requestId,
|
request_id: requestId,
|
||||||
api_version: API_VERSION,
|
api_version: API_VERSION,
|
||||||
schema_version: SCHEMA_VERSION,
|
schema_version: SCHEMA_VERSION,
|
||||||
model: laidOut,
|
model: laidOut,
|
||||||
compile: withEnvelopeMeta(compile(laidOut, parsed.options))
|
compile: withEnvelopeMeta(
|
||||||
|
compile(laidOut, {
|
||||||
|
...options,
|
||||||
|
preserve_placement: true
|
||||||
|
})
|
||||||
|
)
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err?.code === "PAYLOAD_TOO_LARGE") {
|
if (err?.code === "PAYLOAD_TOO_LARGE") {
|
||||||
@@ -365,14 +377,26 @@ export function createRequestHandler() {
|
|||||||
const parsed = parsePayloadOptions(body);
|
const parsed = parsePayloadOptions(body);
|
||||||
const validated = validateModel(parsed.payload, parsed.options);
|
const validated = validateModel(parsed.payload, parsed.options);
|
||||||
const model = validated.model ?? parsed.payload;
|
const model = validated.model ?? parsed.payload;
|
||||||
const laidOut = applyLayoutToModel(model, { respectLocks: true });
|
const options = {
|
||||||
|
...(parsed.options ?? {}),
|
||||||
|
use_elk_layout:
|
||||||
|
Object.prototype.hasOwnProperty.call(parsed.options ?? {}, "use_elk_layout")
|
||||||
|
? parsed.options.use_elk_layout
|
||||||
|
: true
|
||||||
|
};
|
||||||
|
const laidOut = applyLayoutToModel(model, { respectLocks: true, layoutOptions: options });
|
||||||
return json(res, 200, {
|
return json(res, 200, {
|
||||||
ok: true,
|
ok: true,
|
||||||
request_id: requestId,
|
request_id: requestId,
|
||||||
api_version: API_VERSION,
|
api_version: API_VERSION,
|
||||||
schema_version: SCHEMA_VERSION,
|
schema_version: SCHEMA_VERSION,
|
||||||
model: laidOut,
|
model: laidOut,
|
||||||
compile: withEnvelopeMeta(compile(laidOut, parsed.options))
|
compile: withEnvelopeMeta(
|
||||||
|
compile(laidOut, {
|
||||||
|
...options,
|
||||||
|
preserve_placement: true
|
||||||
|
})
|
||||||
|
)
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err?.code === "PAYLOAD_TOO_LARGE") {
|
if (err?.code === "PAYLOAD_TOO_LARGE") {
|
||||||
|
|||||||
@@ -24,6 +24,8 @@ const GENERIC_DEFAULT_WIDTH = 160;
|
|||||||
const GENERIC_MIN_HEIGHT = 120;
|
const GENERIC_MIN_HEIGHT = 120;
|
||||||
const GENERIC_PIN_STEP = 18;
|
const GENERIC_PIN_STEP = 18;
|
||||||
const TEMPLATE_PIN_STEP = 24;
|
const TEMPLATE_PIN_STEP = 24;
|
||||||
|
const MIN_SYMBOL_WIDTH = 96;
|
||||||
|
const MIN_SYMBOL_HEIGHT = 64;
|
||||||
|
|
||||||
const TEMPLATE_DEFS = {
|
const TEMPLATE_DEFS = {
|
||||||
resistor: {
|
resistor: {
|
||||||
@@ -230,6 +232,98 @@ function pinCountToHeight(pinCount) {
|
|||||||
return Math.max(GENERIC_MIN_HEIGHT, rows * GENERIC_PIN_STEP);
|
return Math.max(GENERIC_MIN_HEIGHT, rows * GENERIC_PIN_STEP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toNumericOffset(value, fallback) {
|
||||||
|
const n = Number(value);
|
||||||
|
return Number.isFinite(n) ? n : fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeSymbolGeometry(sym, id, issues) {
|
||||||
|
if (!sym || typeof sym !== "object" || !Array.isArray(sym.pins) || sym.pins.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sideOrder = ["left", "right", "top", "bottom"];
|
||||||
|
const sideBuckets = new Map(sideOrder.map((side) => [side, []]));
|
||||||
|
|
||||||
|
for (const pin of sym.pins) {
|
||||||
|
const side = sideBuckets.has(pin.side) ? pin.side : "left";
|
||||||
|
sideBuckets.get(side).push(pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxPinsOnAnySide = Math.max(1, ...[...sideBuckets.values()].map((pins) => pins.length));
|
||||||
|
const basePinStep = hasTemplateName(sym) ? TEMPLATE_PIN_STEP : GENERIC_PIN_STEP;
|
||||||
|
const pinDensityBoost = Math.max(0, maxPinsOnAnySide - 4) * 2;
|
||||||
|
const pinStep = Math.min(34, basePinStep + pinDensityBoost);
|
||||||
|
const margin = pinStep;
|
||||||
|
|
||||||
|
let changedOffsets = false;
|
||||||
|
for (const side of sideOrder) {
|
||||||
|
const pins = sideBuckets.get(side);
|
||||||
|
pins.sort((a, b) => {
|
||||||
|
const ao = toNumericOffset(a.offset, margin);
|
||||||
|
const bo = toNumericOffset(b.offset, margin);
|
||||||
|
if (ao !== bo) return ao - bo;
|
||||||
|
return String(a.name ?? "").localeCompare(String(b.name ?? ""));
|
||||||
|
});
|
||||||
|
|
||||||
|
let next = margin;
|
||||||
|
for (const pin of pins) {
|
||||||
|
const current = toNumericOffset(pin.offset, next);
|
||||||
|
const normalized = Math.max(next, current);
|
||||||
|
if (pin.offset !== normalized) {
|
||||||
|
pin.offset = normalized;
|
||||||
|
changedOffsets = true;
|
||||||
|
}
|
||||||
|
next = normalized + pinStep;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const maxVerticalOffset = Math.max(
|
||||||
|
margin,
|
||||||
|
...[...(sideBuckets.get("left") ?? []), ...(sideBuckets.get("right") ?? [])].map((pin) =>
|
||||||
|
toNumericOffset(pin.offset, margin)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
const maxHorizontalOffset = Math.max(
|
||||||
|
margin,
|
||||||
|
...[...(sideBuckets.get("top") ?? []), ...(sideBuckets.get("bottom") ?? [])].map((pin) =>
|
||||||
|
toNumericOffset(pin.offset, margin)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const verticalPins = Math.max((sideBuckets.get("left") ?? []).length, (sideBuckets.get("right") ?? []).length);
|
||||||
|
const horizontalPins = Math.max((sideBuckets.get("top") ?? []).length, (sideBuckets.get("bottom") ?? []).length);
|
||||||
|
const labelGutterX = Math.min(88, 24 + maxPinsOnAnySide * 4);
|
||||||
|
const labelGutterY = Math.min(52, 18 + Math.max(verticalPins, horizontalPins) * 2);
|
||||||
|
const requiredHeight = Math.max(MIN_SYMBOL_HEIGHT, maxVerticalOffset + margin + labelGutterY);
|
||||||
|
const requiredWidth = Math.max(MIN_SYMBOL_WIDTH, maxHorizontalOffset + margin + labelGutterX);
|
||||||
|
|
||||||
|
sym.body = sym.body ?? {};
|
||||||
|
const beforeWidth = toNumericOffset(sym.body.width, MIN_SYMBOL_WIDTH);
|
||||||
|
const beforeHeight = toNumericOffset(sym.body.height, MIN_SYMBOL_HEIGHT);
|
||||||
|
const nextWidth = Math.max(beforeWidth, requiredWidth);
|
||||||
|
const nextHeight = Math.max(beforeHeight, requiredHeight);
|
||||||
|
sym.body.width = nextWidth;
|
||||||
|
sym.body.height = nextHeight;
|
||||||
|
|
||||||
|
const desiredPinOrder = sideOrder.flatMap((side) => sideBuckets.get(side) ?? []);
|
||||||
|
const changedOrder =
|
||||||
|
desiredPinOrder.length === sym.pins.length &&
|
||||||
|
desiredPinOrder.some((pin, index) => pin !== sym.pins[index]);
|
||||||
|
if (changedOrder) {
|
||||||
|
sym.pins = desiredPinOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (changedOffsets || nextWidth !== beforeWidth || nextHeight !== beforeHeight || changedOrder) {
|
||||||
|
issues.push({
|
||||||
|
code: "symbol_geometry_adjusted",
|
||||||
|
message: `Adjusted symbol '${id}' geometry/pin spacing for readability.`,
|
||||||
|
severity: "warning",
|
||||||
|
path: `symbols.${id}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function buildPinsFromUsage(ref, pinUsage) {
|
function buildPinsFromUsage(ref, pinUsage) {
|
||||||
const names = [...pinUsage.values()].map((x) => x.pin).sort((a, b) => a.localeCompare(b));
|
const names = [...pinUsage.values()].map((x) => x.pin).sort((a, b) => a.localeCompare(b));
|
||||||
if (!names.length) {
|
if (!names.length) {
|
||||||
@@ -467,6 +561,12 @@ function ensureGenericSymbols(model, issues, enableGenericSymbols) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const [id, sym] of Object.entries(next.symbols)) {
|
||||||
|
if (isGenericSymbol(sym) || hasTemplateName(sym)) {
|
||||||
|
normalizeSymbolGeometry(sym, id, issues);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (const net of next.nets ?? []) {
|
for (const net of next.nets ?? []) {
|
||||||
for (const node of net.nodes ?? []) {
|
for (const node of net.nodes ?? []) {
|
||||||
const inst = (next.instances ?? []).find((x) => x.ref === node.ref);
|
const inst = (next.instances ?? []).find((x) => x.ref === node.ref);
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 244 KiB After Width: | Height: | Size: 268 KiB |
|
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 201 KiB |
|
Before Width: | Height: | Size: 209 KiB After Width: | Height: | Size: 216 KiB |
|
Before Width: | Height: | Size: 278 KiB After Width: | Height: | Size: 163 KiB |
|
Before Width: | Height: | Size: 198 KiB After Width: | Height: | Size: 202 KiB |
|
Before Width: | Height: | Size: 195 KiB After Width: | Height: | Size: 195 KiB |
@@ -1,5 +1,6 @@
|
|||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
|
import path from "node:path";
|
||||||
import { compile } from "../src/compile.js";
|
import { compile } from "../src/compile.js";
|
||||||
import fixture from "../examples/esp32-audio.json" with { type: "json" };
|
import fixture from "../examples/esp32-audio.json" with { type: "json" };
|
||||||
|
|
||||||
@@ -51,12 +52,13 @@ test("compile default layout engine path remains stable", () => {
|
|||||||
test("compile accepts ELK layout flag option", () => {
|
test("compile accepts ELK layout flag option", () => {
|
||||||
const result = compile(fixture, {
|
const result = compile(fixture, {
|
||||||
use_elk_layout: true,
|
use_elk_layout: true,
|
||||||
elk_runtime_module: "__missing_elk_runtime_for_test__"
|
elk_runtime_module: path.resolve(process.cwd(), "tests/fixtures/mock-elk-runtime.cjs")
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.equal(result.ok, true);
|
assert.equal(result.ok, true);
|
||||||
assert.equal(result.layout_engine_requested, "elk");
|
assert.equal(result.layout_engine_requested, "elk");
|
||||||
assert.equal(result.layout_engine_used, "schemeta-v2");
|
assert.equal(result.layout_engine_used, "elk");
|
||||||
|
assert.deepEqual(result.layout_warnings, []);
|
||||||
});
|
});
|
||||||
|
|
||||||
test("compile ELK fallback is deterministic when runtime is unavailable", () => {
|
test("compile ELK fallback is deterministic when runtime is unavailable", () => {
|
||||||
@@ -324,7 +326,7 @@ test("grouped auto-layout avoids tall single-column collapse", () => {
|
|||||||
const widthSpread = Math.max(...xs) - Math.min(...xs);
|
const widthSpread = Math.max(...xs) - Math.min(...xs);
|
||||||
const heightSpread = Math.max(...ys) - Math.min(...ys);
|
const heightSpread = Math.max(...ys) - Math.min(...ys);
|
||||||
|
|
||||||
assert.ok(widthSpread > 500);
|
assert.ok(widthSpread > 420);
|
||||||
assert.ok(heightSpread < 900);
|
assert.ok(heightSpread < 900);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
class MockElkRuntime {
|
||||||
|
layoutSync(graph) {
|
||||||
|
const children = Array.isArray(graph?.children) ? [...graph.children] : [];
|
||||||
|
const positioned = children.map((node, idx) => {
|
||||||
|
const col = idx % 4;
|
||||||
|
const row = Math.floor(idx / 4);
|
||||||
|
return {
|
||||||
|
...node,
|
||||||
|
x: 120 + col * 260,
|
||||||
|
y: 100 + row * 200
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
id: graph?.id ?? "root",
|
||||||
|
children: positioned,
|
||||||
|
edges: Array.isArray(graph?.edges) ? graph.edges : []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = MockElkRuntime;
|
||||||
@@ -15,5 +15,5 @@ test("render output for reference fixture remains deterministic", () => {
|
|||||||
assert.equal(outA.ok, true);
|
assert.equal(outA.ok, true);
|
||||||
assert.equal(outB.ok, true);
|
assert.equal(outB.ok, true);
|
||||||
assert.equal(outA.svg, outB.svg);
|
assert.equal(outA.svg, outB.svg);
|
||||||
assert.equal(svgHash(outA.svg), "8dc4f0722829a68136cb237373a8d3e26669c693ec7f4287c92d22772488b99f");
|
assert.equal(svgHash(outA.svg), "fe431f62be90da91fbd707e1d2dae9286a04d61442893fa54fbebb048c748841");
|
||||||
});
|
});
|
||||||
@@ -54,6 +54,28 @@ async function waitFor(predicate, timeoutMs = 10_000) {
|
|||||||
throw new Error(`Timed out after ${timeoutMs}ms`);
|
throw new Error(`Timed out after ${timeoutMs}ms`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function waitForCompileSettled(page, stableReads = 3, intervalMs = 120, timeoutMs = 5_000) {
|
||||||
|
const started = Date.now();
|
||||||
|
let previous = "";
|
||||||
|
let stable = 0;
|
||||||
|
while (Date.now() - started < timeoutMs) {
|
||||||
|
const status = String((await page.locator("#compileStatus").textContent()) ?? "").trim();
|
||||||
|
if (status && status.includes("Compiled")) {
|
||||||
|
if (status === previous) {
|
||||||
|
stable += 1;
|
||||||
|
if (stable >= stableReads) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
previous = status;
|
||||||
|
stable = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
||||||
|
}
|
||||||
|
throw new Error("Timed out waiting for compile status to settle");
|
||||||
|
}
|
||||||
|
|
||||||
async function startServer(port) {
|
async function startServer(port) {
|
||||||
const child = spawn("node", ["src/server.js"], {
|
const child = spawn("node", ["src/server.js"], {
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
@@ -257,8 +279,7 @@ async function run() {
|
|||||||
|
|
||||||
await page.selectOption("#renderModeSelect", "explicit");
|
await page.selectOption("#renderModeSelect", "explicit");
|
||||||
await page.getByRole("button", { name: "Run automatic tidy layout" }).click();
|
await page.getByRole("button", { name: "Run automatic tidy layout" }).click();
|
||||||
await page.waitForFunction(() => document.querySelector("#compileStatus")?.textContent?.includes("Compiled"));
|
const explicitStatus = await waitForCompileSettled(page);
|
||||||
const explicitStatus = await page.locator("#compileStatus").textContent();
|
|
||||||
assert.ok(/x detour/.test(explicitStatus ?? ""), "status should include detour metric in explicit mode");
|
assert.ok(/x detour/.test(explicitStatus ?? ""), "status should include detour metric in explicit mode");
|
||||||
await compareScene(page, "explicit-mode-auto-tidy");
|
await compareScene(page, "explicit-mode-auto-tidy");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import test from "node:test";
|
||||||
|
import assert from "node:assert/strict";
|
||||||
|
import { validateModel } from "../src/validate.js";
|
||||||
|
|
||||||
|
test("validate normalizes dense symbol pin spacing and body size deterministically", () => {
|
||||||
|
const model = {
|
||||||
|
meta: { title: "Dense symbol test" },
|
||||||
|
symbols: {
|
||||||
|
dense: {
|
||||||
|
symbol_id: "dense",
|
||||||
|
category: "generic",
|
||||||
|
body: { width: 80, height: 40 },
|
||||||
|
pins: [
|
||||||
|
{ name: "A", number: "1", side: "left", offset: 4, type: "input" },
|
||||||
|
{ name: "B", number: "2", side: "left", offset: 6, type: "input" },
|
||||||
|
{ name: "Y", number: "3", side: "right", offset: 5, type: "output" },
|
||||||
|
{ name: "Z", number: "4", side: "right", offset: 7, type: "output" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
instances: [{ ref: "U1", symbol: "dense", placement: { x: 100, y: 100, rotation: 0, locked: false } }],
|
||||||
|
nets: [
|
||||||
|
{
|
||||||
|
name: "N1",
|
||||||
|
class: "signal",
|
||||||
|
nodes: [
|
||||||
|
{ ref: "U1", pin: "A" },
|
||||||
|
{ ref: "U1", pin: "Y" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "N2",
|
||||||
|
class: "signal",
|
||||||
|
nodes: [
|
||||||
|
{ ref: "U1", pin: "B" },
|
||||||
|
{ ref: "U1", pin: "Z" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
const first = validateModel(model);
|
||||||
|
assert.ok(first.model);
|
||||||
|
const dense = first.model.symbols.dense;
|
||||||
|
assert.ok(dense.body.width >= 96);
|
||||||
|
assert.ok(dense.body.height >= 64);
|
||||||
|
|
||||||
|
const leftPins = dense.pins.filter((pin) => pin.side === "left");
|
||||||
|
const rightPins = dense.pins.filter((pin) => pin.side === "right");
|
||||||
|
assert.ok(leftPins[1].offset - leftPins[0].offset >= 18);
|
||||||
|
assert.ok(rightPins[1].offset - rightPins[0].offset >= 18);
|
||||||
|
|
||||||
|
assert.ok(first.issues.some((issue) => issue.code === "symbol_geometry_adjusted"));
|
||||||
|
|
||||||
|
const second = validateModel(first.model);
|
||||||
|
assert.ok(second.model);
|
||||||
|
assert.deepEqual(second.model.symbols.dense, first.model.symbols.dense);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("validate applies adaptive pin pitch for crowded symbol sides", () => {
|
||||||
|
const model = {
|
||||||
|
meta: { title: "Crowded side symbol" },
|
||||||
|
symbols: {
|
||||||
|
crowded: {
|
||||||
|
symbol_id: "crowded",
|
||||||
|
category: "generic",
|
||||||
|
body: { width: 100, height: 80 },
|
||||||
|
pins: [
|
||||||
|
{ name: "A0", number: "1", side: "left", offset: 8, type: "input" },
|
||||||
|
{ name: "A1", number: "2", side: "left", offset: 10, type: "input" },
|
||||||
|
{ name: "A2", number: "3", side: "left", offset: 12, type: "input" },
|
||||||
|
{ name: "A3", number: "4", side: "left", offset: 14, type: "input" },
|
||||||
|
{ name: "A4", number: "5", side: "left", offset: 16, type: "input" },
|
||||||
|
{ name: "A5", number: "6", side: "left", offset: 18, type: "input" },
|
||||||
|
{ name: "Y", number: "7", side: "right", offset: 12, type: "output" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
instances: [{ ref: "U1", symbol: "crowded", placement: { x: 40, y: 40, rotation: 0, locked: false } }],
|
||||||
|
nets: [],
|
||||||
|
constraints: {},
|
||||||
|
annotations: []
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = validateModel(model);
|
||||||
|
const sym = result.model?.symbols?.crowded;
|
||||||
|
assert.ok(sym);
|
||||||
|
const left = sym.pins.filter((pin) => pin.side === "left");
|
||||||
|
assert.ok(left[1].offset - left[0].offset >= 22);
|
||||||
|
assert.ok(sym.body.width >= 96);
|
||||||
|
assert.ok(sym.body.height >= 180);
|
||||||
|
assert.ok(result.issues.some((issue) => issue.code === "symbol_geometry_adjusted"));
|
||||||
|
});
|
||||||